Пример #1
0
        /// <summary>
        /// Evaluates a math expression of 2 time spans.
        /// </summary>
        /// <param name="node">The AST node the evaluation is a part of.</param>
        /// <param name="lhs">The time on the left hand side</param>
        /// <param name="rhs">The time on the right hand side</param>
        /// <param name="op">The math operator.</param>
        /// <returns></returns>
        public static LBool CompareBools(AstNode node, LBool lhs, LBool rhs, Operator op)
        {
            var left   = Convert.ToInt32(lhs.Value);
            var right  = Convert.ToInt32(rhs.Value);
            var result = false;

            if (op == Operator.LessThan)
            {
                result = left < right;
            }
            else if (op == Operator.LessThanEqual)
            {
                result = left <= right;
            }
            else if (op == Operator.MoreThan)
            {
                result = left > right;
            }
            else if (op == Operator.MoreThanEqual)
            {
                result = left >= right;
            }
            else if (op == Operator.EqualEqual)
            {
                result = left == right;
            }
            else if (op == Operator.NotEqual)
            {
                result = left != right;
            }
            return(new LBool(result));
        }
Пример #2
0
        private void Prove(TypeSafeContext z3, TermAst p)
        {
            Console.WriteLine("To PROVE: {0}", z3.ToString(z3.MkNot(p)));
            z3.AssertCnstr(z3.MkNot(p));
            z3.Display(System.Console.Out);
            TypeSafeModel model  = null;
            LBool         result = z3.CheckAndGetModel(ref model);

            switch (result)
            {
            case LBool.True:
                Console.WriteLine("false");
                model.Display(System.Console.Out);
                model.Dispose();
                break;

            case LBool.False:
                Console.WriteLine("true");
                break;

            case LBool.Undef:
                Console.WriteLine("unknown");
                break;
            }
        }
Пример #3
0
        public ProverInterface.Outcome CheckAssumptions(List <VCExpr> assumptions, LineariserOptions linOptions,
                                                        out List <Z3ErrorModelAndLabels> boogieErrors,
                                                        out List <int> unsatCore)
        {
            Microsoft.Boogie.Helpers.ExtraTraceInformation("Sending data to the theorem prover");
            boogieErrors = new List <Z3ErrorModelAndLabels>();
            unsatCore    = new List <int>();
            LBool outcome = LBool.Undef;

            Z3Model z3Model;
            Term    proof;

            Term[] core;
            Term[] assumption_terms = new Term[assumptions.Count];
            var    logstring        = "";

            for (int i = 0; i < assumptions.Count; i++)
            {
                Z3apiExprLineariser visitor = new Z3apiExprLineariser(this, namer);
                Term z3ast = (Term)assumptions[i].Accept(visitor, linOptions);
                assumption_terms[i] = z3ast;
                logstring          += string.Format("({0}) ", assumption_terms[i]);
            }

            log("(get-core {0})", logstring);
            outcome = z3.CheckAssumptions(out z3Model, assumption_terms, out proof, out core);

            if (outcome != LBool.False)
            {
                Debug.Assert(z3Model != null);
                LabeledLiterals labels = z3.GetRelevantLabels();
                Debug.Assert(labels != null);

                List <string> labelStrings = new List <string>();
                uint          numLabels    = labels.GetNumLabels();
                for (uint i = 0; i < numLabels; ++i)
                {
                    Symbol sym       = labels.GetLabel(i);
                    string labelName = z3.GetSymbolString(sym);
                    if (!labelName.StartsWith("@"))
                    {
                        labels.Disable(i);
                    }
                    labelStrings.Add(labelName);
                }

                var sw = new StringWriter();
                sw.WriteLine("*** MODEL");
                z3Model.Display(sw);
                sw.WriteLine("*** END_MODEL");
                var sr     = new StringReader(sw.ToString());
                var models = Microsoft.Boogie.Model.ParseModels(sr);
                Z3ErrorModelAndLabels e = new Z3ErrorModelAndLabels(models[0], new List <string>(labelStrings));
                boogieErrors.Add(e);

                labels.Dispose();
                z3Model.Dispose();
            }

            if (boogieErrors.Count > 0)
            {
                return(ProverInterface.Outcome.Invalid);
            }
            else if (outcome == LBool.False)
            {
                foreach (Term t in core)
                {
                    for (int i = 0; i < assumption_terms.Length; i++)
                    {
                        if (t.Equals(assumption_terms[i]))
                        {
                            unsatCore.Add(i);
                        }
                    }
                }
                return(ProverInterface.Outcome.Valid);
            }
            else
            {
                Debug.Assert(outcome == LBool.Undef);
                return(ProverInterface.Outcome.Undetermined);
            }
        }
Пример #4
0
        public ProverInterface.Outcome Check(out List <Z3ErrorModelAndLabels> boogieErrors)
        {
            Microsoft.Boogie.Helpers.ExtraTraceInformation("Sending data to the theorem prover");
            boogieErrors = new List <Z3ErrorModelAndLabels>();
            LBool outcome = LBool.Undef;

            Debug.Assert(0 < this.counterexamples);
            while (true)
            {
                Z3Model z3Model;
                outcome = z3.CheckAndGetModel(out z3Model);

                log("(check-sat)");
                if (outcome == LBool.False)
                {
                    break;
                }

                if (outcome == LBool.Undef && z3Model == null)
                {
                    // Blame this on timeout
                    return(ProverInterface.Outcome.TimeOut);
                }

                Debug.Assert(z3Model != null);
                LabeledLiterals labels = z3.GetRelevantLabels();
                Debug.Assert(labels != null);

                List <string> labelStrings = new List <string>();
                uint          numLabels    = labels.GetNumLabels();
                for (uint i = 0; i < numLabels; ++i)
                {
                    Symbol sym       = labels.GetLabel(i);
                    string labelName = z3.GetSymbolString(sym);
                    if (!labelName.StartsWith("@"))
                    {
                        labels.Disable(i);
                    }
                    labelStrings.Add(labelName);
                }

                var sw = new StringWriter();
                sw.WriteLine("*** MODEL");
                z3Model.Display(sw);
                sw.WriteLine("*** END_MODEL");
                var sr     = new StringReader(sw.ToString());
                var models = Microsoft.Boogie.Model.ParseModels(sr);
                Z3ErrorModelAndLabels e = new Z3ErrorModelAndLabels(models[0], new List <string>(labelStrings));
                boogieErrors.Add(e);

                if (boogieErrors.Count < this.counterexamples)
                {
                    z3.BlockLiterals(labels);
                    log("block-literals {0}", labels);
                }

                labels.Dispose();
                z3Model.Dispose();
                if (boogieErrors.Count == this.counterexamples)
                {
                    break;
                }
            }

            if (boogieErrors.Count > 0)
            {
                return(ProverInterface.Outcome.Invalid);
            }
            else if (outcome == LBool.False)
            {
                return(ProverInterface.Outcome.Valid);
            }
            else
            {
                Debug.Assert(outcome == LBool.Undef);
                return(ProverInterface.Outcome.Undetermined);
            }
        }