MkRealSort() public méthode

Create a real sort.
public MkRealSort ( ) : RealSort
Résultat RealSort
        internal static FuncDecl GetOrAddMemberAccessFunction(Context context, Environment environment, MemberInfo memberInfo)
        {
            FuncDecl memberFunc;
            if (!environment.Members.TryGetValue(memberInfo, out memberFunc))
            {
                Sort memberTypeSort;
                if (!environment.Types.TryGetValue(memberInfo.DeclaringType, out memberTypeSort))
                {
                    throw new KeyNotFoundException(memberInfo.DeclaringType + " could not be found at environment.Types");
                }

                Sort memberReturnTypeEnumSort;
                var propertyType = ((PropertyInfo)memberInfo).PropertyType;
                if (propertyType == typeof(bool))
                    memberReturnTypeEnumSort = context.MkBoolSort();
                else if (propertyType == typeof(int))
                    memberReturnTypeEnumSort = context.MkIntSort();
                else if (propertyType == typeof(long))
                    memberReturnTypeEnumSort = context.MkRealSort();
                else if (propertyType == typeof(string))
                    memberReturnTypeEnumSort = environment.PossibleStringValues;
                else
                {
                    if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
                    {
                        var listItemType = propertyType.GenericTypeArguments[0];

                        var listSort = context.MkSetSort(environment.Types[listItemType]);

                        memberReturnTypeEnumSort = listSort;

                        // TODO: add TryGetValue
                        environment.Types.Add(propertyType, listSort);
                    }
                    else if (propertyType.IsEnum)
                    {
                        EnumSort enumSort = context.MkEnumSort(propertyType.Name, Enum.GetNames(propertyType));

                        memberReturnTypeEnumSort = enumSort;

                        // TODO: add TryGetValue
                        environment.Types.Add(propertyType, enumSort);
                    }
                    else
                    {
                        // TODO throw exception if type is not supported
                        memberReturnTypeEnumSort = environment.Types[propertyType];
                    }
                }

                memberFunc = context.MkFuncDecl(memberInfo.Name, memberTypeSort, memberReturnTypeEnumSort);
                environment.Members.Add(memberInfo, memberFunc);
            }
            return memberFunc;
        }
Exemple #2
0
        static void ModelConverterTest(Context ctx)
        {
            Console.WriteLine("ModelConverterTest");

            ArithExpr xr = (ArithExpr)ctx.MkConst(ctx.MkSymbol("x"), ctx.MkRealSort());
            ArithExpr yr = (ArithExpr)ctx.MkConst(ctx.MkSymbol("y"), ctx.MkRealSort());
            Goal g4 = ctx.MkGoal(true);
            g4.Assert(ctx.MkGt(xr, ctx.MkReal(10, 1)));
            g4.Assert(ctx.MkEq(yr, ctx.MkAdd(xr, ctx.MkReal(1, 1))));
            g4.Assert(ctx.MkGt(yr, ctx.MkReal(1, 1)));

            ApplyResult ar = ApplyTactic(ctx, ctx.MkTactic("simplify"), g4);
            if (ar.NumSubgoals == 1 && (ar.Subgoals[0].IsDecidedSat || ar.Subgoals[0].IsDecidedUnsat))
                throw new TestFailedException();

            ar = ApplyTactic(ctx, ctx.AndThen(ctx.MkTactic("simplify"), ctx.MkTactic("solve-eqs")), g4);
            if (ar.NumSubgoals == 1 && (ar.Subgoals[0].IsDecidedSat || ar.Subgoals[0].IsDecidedUnsat))
                throw new TestFailedException();

            Solver s = ctx.MkSolver();
            foreach (BoolExpr e in ar.Subgoals[0].Formulas)
                s.Assert(e);
            Status q = s.Check();
            Console.WriteLine("Solver says: " + q);
            Console.WriteLine("Model: \n" + s.Model);
            Console.WriteLine("Converted Model: \n" + ar.ConvertModel(0, s.Model));
            if (q != Status.SATISFIABLE)
                throw new TestFailedException();
        }