コード例 #1
0
        /// <summary>
        /// Model check an expression to find inputs that lead to it being false.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <returns>
        ///     Assignment to zen arbitrary variables that make the expression false.
        ///     Null if no such assignment exists.
        /// </returns>
        public Dictionary <object, object> ModelCheck(Zen <bool> expression)
        {
            var symbolicEvaluator = new SymbolicEvaluationVisitor <TModel, TVar, TBool, TInt>(solver);
            var env            = new SymbolicEvaluationEnvironment <TModel, TVar, TBool, TInt>();
            var symbolicResult =
                (SymbolicBool <TModel, TVar, TBool, TInt>)expression.Accept(symbolicEvaluator, env);

            // Console.WriteLine($"[time] model checking: {watch.ElapsedMilliseconds}ms");
            // watch.Restart();

            var possibleModel = solver.Satisfiable(symbolicResult.Value);

            // Console.WriteLine($"[time] get sat: {watch.ElapsedMilliseconds}ms");

            if (!possibleModel.HasValue)
            {
                return(null);
            }

            var model = possibleModel.Value;

            // compute the input given the assignment
            var arbitraryAssignment = new Dictionary <object, object>();

            foreach (var kv in symbolicEvaluator.ArbitraryVariables)
            {
                var expr     = kv.Key;
                var variable = kv.Value;
                arbitraryAssignment.Add(expr, this.solver.Get(model, variable));
            }

            return(arbitraryAssignment);
        }
コード例 #2
0
ファイル: Interpreter.cs プロジェクト: maxlevatich/Zen
        private static T Interpret <T>(Zen <T> expression, ImmutableDictionary <string, object> arguments)
        {
            var environment = new ExpressionEvaluatorEnvironment(arguments);
            var interpreter = new ExpressionEvaluator();

            return((T)expression.Accept(interpreter, environment));
        }
コード例 #3
0
        internal static Expression CompileToBlock <T>(
            Zen <T> zenExpression,
            ExpressionConverterEnvironment env,
            ImmutableDictionary <object, Expression> subexpressionCache,
            int currentMatchUnrollingDepth,
            int maxMatchUnrollingDepth)
        {
            var converter = new ExpressionConverter(subexpressionCache, currentMatchUnrollingDepth, maxMatchUnrollingDepth);
            var expr      = zenExpression.Accept(converter, env);

            converter.BlockExpressions.Add(expr);
            return(Expression.Block(converter.Variables, converter.BlockExpressions.ToArray()));
        }
コード例 #4
0
        /// <summary>
        /// Model check an expression to find inputs that lead to it being false.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <returns>
        ///     Assignment to zen arbitrary variables that make the expression false.
        ///     Null if no such assignment exists.
        /// </returns>
        public Dictionary <object, object> ModelCheck(Zen <bool> expression)
        {
            var symbolicEvaluator = new SymbolicEvaluationVisitor <TModel, TVar, TBool, TBitvec, TInt, TString>(solver);
            var env            = new SymbolicEvaluationEnvironment <TModel, TVar, TBool, TBitvec, TInt, TString>();
            var symbolicResult =
                (SymbolicBool <TModel, TVar, TBool, TBitvec, TInt, TString>)expression.Accept(symbolicEvaluator, env);

            var possibleModel = solver.Satisfiable(symbolicResult.Value);

            if (!possibleModel.HasValue)
            {
                return(null);
            }

            var model = possibleModel.Value;

            // compute the input given the assignment
            var arbitraryAssignment = new Dictionary <object, object>();

            foreach (var kv in symbolicEvaluator.ArbitraryVariables)
            {
                var expr     = kv.Key;
                var variable = kv.Value;
                var type     = expr.GetType().GetGenericArguments()[0];
                var obj      = this.solver.Get(model, variable);

                if (ReflectionUtilities.IsFixedIntegerType(type))
                {
                    obj = type.GetConstructor(new Type[] { typeof(byte[]) }).Invoke(new object[] { obj });
                }

                arbitraryAssignment.Add(expr, obj);
            }

            return(arbitraryAssignment);
        }
コード例 #5
0
        public Dictionary <object, ImmutableHashSet <object> > Compute <T>(Zen <T> expr)
        {
            var _ = expr.Accept(this, new Unit());

            return(this.DisjointSets);
        }