Beispiel #1
0
 public TPTPOpLineariser(TPTPExprLineariser ExprLineariser, TextWriter wr)
 {
     Contract.Requires(ExprLineariser != null);
     Contract.Requires(wr != null);
     this.ExprLineariser = ExprLineariser;
     this.wr             = wr;
 }
Beispiel #2
0
        protected string VCExpr2String(VCExpr expr, int polarity)
        {
            Contract.Requires(expr != null);
            Contract.Ensures(Contract.Result <string>() != null);

            DateTime start = DateTime.UtcNow;

            if (CommandLineOptions.Clo.Trace)
            {
                Console.Write("Linearising ... ");
            }

            // handle the types in the VCExpr
            TypeEraser eraser;

            switch (CommandLineOptions.Clo.TypeEncodingMethod)
            {
            case CommandLineOptions.TypeEncoding.Arguments:
                eraser = new TypeEraserArguments((TypeAxiomBuilderArguments)AxBuilder, gen);
                break;

            case CommandLineOptions.TypeEncoding.Monomorphic:
                eraser = null;
                break;

            default:
                eraser = new TypeEraserPremisses((TypeAxiomBuilderPremisses)AxBuilder, gen);
                break;
            }
            VCExpr exprWithoutTypes = eraser == null ? expr : eraser.Erase(expr, polarity);

            Contract.Assert(exprWithoutTypes != null);

            var letImplier     = new Let2ImpliesMutator(Gen);
            var flattener      = new TermFormulaFlattener(Gen);
            var exprWithLet    = flattener.Flatten(exprWithoutTypes);
            var exprWithoutLet = letImplier.Mutate(exprWithLet);

            var axiomsWithLet    = flattener.Flatten(AxBuilder.GetNewAxioms());
            var axiomsWithoutLet = letImplier.Mutate(axiomsWithLet);

            DeclCollector.Collect(axiomsWithoutLet);
            DeclCollector.Collect(exprWithoutLet);
            FeedTypeDeclsToProver();

            AddAxiom(TPTPExprLineariser.ToString(axiomsWithoutLet, Namer, Options));
            string res = TPTPExprLineariser.ToString(exprWithoutLet, Namer, Options);

            Contract.Assert(res != null);

            if (CommandLineOptions.Clo.Trace)
            {
                DateTime end     = DateTime.UtcNow;
                TimeSpan elapsed = end - start;
                Console.WriteLine("finished   [{0} s]", elapsed.TotalSeconds);
            }
            return(res);
        }
        ///////////////////////////////////////////////////////////////////////////


        public override bool Visit(VCExprNAry node, bool arg)
        {
            Contract.Requires(node != null);

            if (node.Op is VCExprStoreOp)
            {
                string name = TPTPExprLineariser.Lowercase(SimplifyLikeExprLineariser.StoreOpName(node));
                if (!KnownStoreFunctions.Contains(name))
                {
                    var id = KnownStoreFunctions.Count;

                    if (CommandLineOptions.Clo.MonomorphicArrays)
                    {
                        var sel = TPTPExprLineariser.Lowercase(SimplifyLikeExprLineariser.SelectOpName(node));

                        var eq = "=";
                        if (node[node.Arity - 1].Type.IsBool)
                        {
                            eq = "<=>";
                        }

                        string xS = "", yS = "";
                        string dist = "";

                        for (int i = 0; i < node.Arity - 2; i++)
                        {
                            if (i != 0)
                            {
                                dist += " | ";
                                xS   += ",";
                                yS   += ",";
                            }
                            var x = "X" + i;
                            var y = "Y" + i;
                            xS   += x;
                            yS   += y;
                            dist += string.Format("({0} != {1})", x, y);
                        }

                        string ax1 = "fof(selectEq" + id + ", axiom, ! [M,V," + xS + "] : (" +
                                     string.Format("{0}({1}(M,{2},V),{2}) {3} V", sel, name, xS, eq) + ")).";
                        string ax2 = "fof(selectNeq" + id + ", axiom, ! [M,V," + xS + "," + yS + "] : (" +
                                     string.Format("( {0} ) => ", dist) +
                                     string.Format("{0}({1}(M,{2},V),{3}) {4} {0}(M,{3})", sel, name, xS, yS, eq) + ")).";

                        AddDeclaration(ax1);
                        AddDeclaration(ax2);
                    }

                    KnownStoreFunctions.Add(name);
                }
                //
            }

            return(base.Visit(node, arg));
        }
Beispiel #4
0
        public static string ToString(VCExpr e, UniqueNamer namer, TPTPProverOptions opts)
        {
            Contract.Requires(e != null);
            Contract.Requires(namer != null);
            Contract.Ensures(Contract.Result <string>() != null);

            StringWriter       sw  = new StringWriter();
            TPTPExprLineariser lin = new TPTPExprLineariser(sw, namer, opts);

            Contract.Assert(lin != null);
            lin.Linearise(e, LineariserOptions.Default);
            return(cce.NonNull(sw.ToString()));
        }