Exemplo n.º 1
0
        /// <summary>
        /// Create a quantified expression either forall or exists
        /// </summary>
        /// <param name="is_forall"></param>
        /// <param name="sorts"></param>
        /// <param name="names"></param>
        /// <param name="body"></param>
        /// <param name="weight"></param>
        /// <param name="patterns"></param>
        /// <param name="noPatterns"></param>
        /// <param name="quantifierID"></param>
        /// <param name="skolemID"></param>
        /// <returns></returns>
        private Z3_ast MkQuantifier(bool is_forall, Z3_sort[] sorts, Z3_symbol[] names, Z3_ast body, uint weight, Z3_ast[] patterns, Z3_ast[] noPatterns, Symbol quantifierID, Symbol skolemID)
        {
            Debug.Assert(sorts != null);
            Debug.Assert(names != null);
            Debug.Assert(body != null);
            Debug.Assert(sorts.Length == names.Length);
            Debug.Assert(sorts.All(s => s != IntPtr.Zero));
            Debug.Assert(names.All(n => n != IntPtr.Zero));
            Debug.Assert(patterns == null || patterns.All(p => p != IntPtr.Zero));
            Debug.Assert(noPatterns == null || noPatterns.All(np => np != IntPtr.Zero));

            if (noPatterns == null && quantifierID == null && skolemID == null)
            {
                return(Native.Z3_mk_quantifier(nCtx, (byte)(is_forall ? 1 : 0), weight,
                                               (uint)(patterns?.Length ?? 0), patterns,
                                               (uint)(sorts?.Length ?? 0), sorts,
                                               names,
                                               body));
            }
            else
            {
                return(Native.Z3_mk_quantifier_ex(nCtx, (byte)(is_forall ? 1 : 0), weight,
                                                  AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID),
                                                  (uint)(patterns?.Length ?? 0), patterns,
                                                  (uint)(noPatterns?.Length ?? 0), noPatterns,
                                                  (uint)(sorts?.Length ?? 0), sorts,
                                                  names,
                                                  body));
            }
        }
Exemplo n.º 2
0
        [ContractVerification(false)] // F: Clousot ForAll decompilation gets confused below. Setting verification off until I fixed the bug
        internal Quantifier(Context ctx, bool isForall, Expr[] bound, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null)
            : base(ctx, IntPtr.Zero)
        {
            Contract.Requires(ctx != null);
            Contract.Requires(body != null);

            Contract.Requires(patterns == null || Contract.ForAll(patterns, p => p != null));
            Contract.Requires(noPatterns == null || Contract.ForAll(noPatterns, np => np != null));
            Contract.Requires(bound == null || Contract.ForAll(bound, n => n != null));

            Context.CheckContextMatch <Expr>(noPatterns);
            Context.CheckContextMatch <Pattern>(patterns);
            //Context.CheckContextMatch(bound);
            Context.CheckContextMatch(body);

            if (noPatterns == null && quantifierID == null && skolemID == null)
            {
                NativeObject = Native.Z3_mk_quantifier_const(ctx.nCtx, (isForall) ? 1 : 0, weight,
                                                             AST.ArrayLength(bound), AST.ArrayToNative(bound),
                                                             AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                             body.NativeObject);
            }
            else
            {
                NativeObject = Native.Z3_mk_quantifier_const_ex(ctx.nCtx, (isForall) ? 1 : 0, weight,
                                                                AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID),
                                                                AST.ArrayLength(bound), AST.ArrayToNative(bound),
                                                                AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                                AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns),
                                                                body.NativeObject);
            }
        }
Exemplo n.º 3
0
        internal Quantifier(Context ctx, bool isForall, Expr[] bound, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null)
            : base(ctx, IntPtr.Zero)
        {
            Debug.Assert(ctx != null);
            Debug.Assert(body != null);

            Debug.Assert(patterns == null || patterns.All(p => p != null));
            Debug.Assert(noPatterns == null || noPatterns.All(np => np != null));
            Debug.Assert(bound == null || bound.All(n => n != null));

            Context.CheckContextMatch <Expr>(noPatterns);
            Context.CheckContextMatch <Pattern>(patterns);
            //Context.CheckContextMatch(bound);
            Context.CheckContextMatch(body);

            if (noPatterns == null && quantifierID == null && skolemID == null)
            {
                NativeObject = Native.Z3_mk_quantifier_const(ctx.nCtx, (byte)(isForall ? 1 : 0), weight,
                                                             AST.ArrayLength(bound), AST.ArrayToNative(bound),
                                                             AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                             body.NativeObject);
            }
            else
            {
                NativeObject = Native.Z3_mk_quantifier_const_ex(ctx.nCtx, (byte)(isForall ? 1 : 0), weight,
                                                                AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID),
                                                                AST.ArrayLength(bound), AST.ArrayToNative(bound),
                                                                AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                                AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns),
                                                                body.NativeObject);
            }
        }
Exemplo n.º 4
0
        [ContractVerification(false)] // F: Clousot ForAll decompilation gets confused below. Setting verification off until I fixed the bug
        internal Quantifier(Context ctx, bool isForall, Sort[] sorts, Symbol[] names, Expr body,
                            uint weight         = 1, Pattern[] patterns = null, Expr[] noPatterns = null,
                            Symbol quantifierID = null, Symbol skolemID = null
                            )
            : base(ctx)
        {
            Contract.Requires(ctx != null);
            Contract.Requires(sorts != null);
            Contract.Requires(names != null);
            Contract.Requires(body != null);
            Contract.Requires(sorts.Length == names.Length);
            Contract.Requires(Contract.ForAll(sorts, s => s != null));
            Contract.Requires(Contract.ForAll(names, n => n != null));
            Contract.Requires(patterns == null || Contract.ForAll(patterns, p => p != null));
            Contract.Requires(noPatterns == null || Contract.ForAll(noPatterns, np => np != null));

            Context.CheckContextMatch(patterns);
            Context.CheckContextMatch(noPatterns);
            Context.CheckContextMatch(sorts);
            Context.CheckContextMatch(names);
            Context.CheckContextMatch(body);

            if (sorts.Length != names.Length)
            {
                throw new Z3Exception("Number of sorts does not match number of names");
            }

            IntPtr[] _patterns = AST.ArrayToNative(patterns);

            if (noPatterns == null && quantifierID == null && skolemID == null)
            {
                NativeObject = Native.Z3_mk_quantifier(ctx.nCtx, (isForall) ? 1 : 0, weight,
                                                       AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                       AST.ArrayLength(sorts), AST.ArrayToNative(sorts),
                                                       Symbol.ArrayToNative(names),
                                                       body.NativeObject);
            }
            else
            {
                NativeObject = Native.Z3_mk_quantifier_ex(ctx.nCtx, (isForall) ? 1 : 0, weight,
                                                          AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID),
                                                          AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                          AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns),
                                                          AST.ArrayLength(sorts), AST.ArrayToNative(sorts),
                                                          Symbol.ArrayToNative(names),
                                                          body.NativeObject);
            }
        }
Exemplo n.º 5
0
        internal Quantifier(Context ctx, bool isForall, Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null)
            : base(ctx, IntPtr.Zero)
        {
            Debug.Assert(ctx != null);
            Debug.Assert(sorts != null);
            Debug.Assert(names != null);
            Debug.Assert(body != null);
            Debug.Assert(sorts.Length == names.Length);
            Debug.Assert(sorts.All(s => s != null));
            Debug.Assert(names.All(n => n != null));
            Debug.Assert(patterns == null || patterns.All(p => p != null));
            Debug.Assert(noPatterns == null || noPatterns.All(np => np != null));

            Context.CheckContextMatch <Pattern>(patterns);
            Context.CheckContextMatch <Expr>(noPatterns);
            Context.CheckContextMatch <Sort>(sorts);
            Context.CheckContextMatch <Symbol>(names);
            Context.CheckContextMatch(body);

            if (sorts.Length != names.Length)
            {
                throw new Z3Exception("Number of sorts does not match number of names");
            }

            if (noPatterns == null && quantifierID == null && skolemID == null)
            {
                NativeObject = Native.Z3_mk_quantifier(ctx.nCtx, (byte)(isForall ? 1 : 0), weight,
                                                       AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                       AST.ArrayLength(sorts), AST.ArrayToNative(sorts),
                                                       Symbol.ArrayToNative(names),
                                                       body.NativeObject);
            }
            else
            {
                NativeObject = Native.Z3_mk_quantifier_ex(ctx.nCtx, (byte)(isForall ? 1 : 0), weight,
                                                          AST.GetNativeObject(quantifierID), AST.GetNativeObject(skolemID),
                                                          AST.ArrayLength(patterns), AST.ArrayToNative(patterns),
                                                          AST.ArrayLength(noPatterns), AST.ArrayToNative(noPatterns),
                                                          AST.ArrayLength(sorts), AST.ArrayToNative(sorts),
                                                          Symbol.ArrayToNative(names),
                                                          body.NativeObject);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Update named rule into in the fixedpoint solver.
        /// </summary>
        public void UpdateRule(BoolExpr rule, Symbol name)
        {
            Contract.Requires(rule != null);

            Context.CheckContextMatch(rule);
            Native.Z3_fixedpoint_update_rule(Context.nCtx, NativeObject, rule.NativeObject, AST.GetNativeObject(name));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Add rule into the fixedpoint solver.
        /// </summary>
        public void AddRule(BoolExpr rule, Symbol name = null)
        {
            Debug.Assert(rule != null);

            Context.CheckContextMatch(rule);
            Native.Z3_fixedpoint_add_rule(Context.nCtx, NativeObject, rule.NativeObject, AST.GetNativeObject(name));
        }