public void Run() { Dictionary <string, string> cfg = new Dictionary <string, string>() { { "AUTO_CONFIG", "true" }, { "MODEL", "true" } }; using (Context ctx = new Context(cfg)) { Constructor c_leaf = ctx.MkConstructor("leaf", "is_leaf", new string[] { "val" }, new Sort[] { ctx.IntSort }); Constructor c_node = ctx.MkConstructor("node", "is_node", new string[] { "left", "right" }, new Sort[] { null, null }, new uint[] { 1, 1 }); Constructor[] constr_1 = new Constructor[] { c_leaf, c_node }; Constructor c_nil = ctx.MkConstructor("nil", "is_nil"); Constructor c_cons = ctx.MkConstructor("cons", "is_cons", new string[] { "car", "cdr" }, new Sort[] { null, null }, new uint[] { 0, 1 }); Constructor[] constr_2 = new Constructor[] { c_nil, c_cons }; DatatypeSort[] ts = ctx.MkDatatypeSorts(new string[] { "Tree", "TreeList" }, new Constructor[][] { constr_1, constr_2 }); DatatypeSort Tree = ts[0]; DatatypeSort TreeList = ts[1]; FuncDecl leaf = Tree.Constructors[0]; FuncDecl node = Tree.Constructors[1]; FuncDecl val = Tree.Accessors[0][0]; FuncDecl nil = TreeList.Constructors[0]; FuncDecl cons = TreeList.Constructors[1]; Expr t1 = leaf[ctx.MkInt(10)]; Expr tl1 = cons[t1, nil.Apply()]; Expr t2 = node[tl1, nil.Apply()]; Console.WriteLine(t2); Console.WriteLine(val.Apply(t1).Simplify()); t1 = ctx.MkConst("t1", TreeList); t2 = ctx.MkConst("t2", TreeList); Expr t3 = ctx.MkConst("t3", TreeList); Solver s = ctx.MkSolver(); s.Assert(ctx.MkDistinct(t1, t2, t3)); Console.WriteLine(s.Check()); Console.WriteLine(s.Model); } }
public void Run() { Dictionary <string, string> cfg = new Dictionary <string, string>() { { "AUTO_CONFIG", "true" } }; using (Context ctx = new Context(cfg)) { IntExpr x = ctx.MkIntConst("x"); FuncDecl x_d = x.FuncDecl; Console.WriteLine("is_expr(x_d): " + x_d.IsExpr); Console.WriteLine("is_func_decl(x_d): " + x_d.IsFuncDecl); Console.WriteLine("x_d.Name: " + x_d.Name); Console.WriteLine("x_d.Range: " + x_d.Range); Console.WriteLine("x_d.Arity: " + x_d.Arity); Console.WriteLine("x_d() == x: " + (x_d.Apply() == x)); FuncDecl f = ctx.MkFuncDecl("f", new Sort[] { ctx.IntSort, ctx.RealSort }, ctx.BoolSort); Console.WriteLine("f.Name: " + f.Name); Console.WriteLine("f.Range: " + f.Range); Console.WriteLine("f.Arity: " + f.Arity); for (uint i = 0; i < f.Arity; i++) { Console.WriteLine("domain(" + i + "): " + f.Domain[i]); } Console.WriteLine(f[x, ctx.MkInt2Real(x)]); Console.WriteLine(f[x, ctx.MkInt2Real(x)].FuncDecl == f); } }
public TProperty GetValue <TObject, TProperty>(TObject objectToInspect, Expression <Func <TObject, TProperty> > propertyExpression) where TObject : class { try { var memberExpression = (MemberExpression)propertyExpression.Body; FuncDecl member = _environment.Members[memberExpression.Member]; InstanceInfo instance = _environment.Instances.Select(i => i.Value).SingleOrDefault(i => i.ObjectInstance == objectToInspect); Expr objectForMemberAccess = instance.EnumConstant; Sort memberDeclaredObjectSort = member.Domain[0]; if (memberDeclaredObjectSort != objectForMemberAccess.Sort) { objectForMemberAccess = UpcastHelper.Upcast(_context, objectForMemberAccess, memberDeclaredObjectSort); } var memberOfInstance = member.Apply(objectForMemberAccess); var result = _solver.Model.Evaluate(memberOfInstance); if (typeof(TProperty) == typeof(bool)) { if (result.IsBool) { return((TProperty)(object)result.IsTrue); } } if (typeof(TProperty) == typeof(int)) { if (result.IsInt) { return((TProperty)(object)((IntNum)result).Int); } } if (typeof(TProperty) == typeof(string)) { return((TProperty)(object)result.FuncDecl.Name.ToString()); } if (typeof(TProperty).IsEnum) { return((TProperty)Enum.Parse(typeof(TProperty), result.FuncDecl.Name.ToString())); } if (typeof(TProperty).IsGenericType && typeof(TProperty).GetGenericTypeDefinition() == typeof(IEnumerable <>)) { var listInstance = (IList)typeof(List <>) .MakeGenericType(typeof(TProperty).GetGenericArguments()[0]) .GetConstructor(Type.EmptyTypes) .Invoke(null); var storeExpr = result; if (storeExpr.Args.Length == 3) { while (storeExpr.Args.Length == 3) { listInstance.Add(_environment.Instances.Values.Single(i => i.EnumConstant == storeExpr.Args[1]).ObjectInstance); storeExpr = storeExpr.Args[0]; } } else if (storeExpr.Args.Length == 1 && storeExpr.Args[0].IsBool && !storeExpr.Args[0].IsTrue) { // Empty Array } else { var arrayInterpretationFuncDecl = result.FuncDecl.Parameters[0].FuncDecl; var arryItemSort = (DatatypeSort)arrayInterpretationFuncDecl.Domain[0]; foreach (var possibleItem in _environment.Instances.Values .Where(i => i.EnumConstant.Sort == arryItemSort)) { if (_solver.Model.Evaluate(arrayInterpretationFuncDecl.Apply(possibleItem.EnumConstant)).IsTrue) { listInstance.Add(possibleItem.ObjectInstance); } } } return((TProperty)listInstance); } if (typeof(TProperty).IsClass) { return((TProperty)_environment.Instances.Single(i => i.Value.EnumConstant == result).Value.ObjectInstance); } throw new NotSupportedException(typeof(TProperty).Name); } catch (Exception ex) { Trace.WriteLine(ex); throw; } }