Example #1
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);
            }
        }
Example #2
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);
            }
        }