// Note: see -
        // http://logic.stanford.edu/classes/cs157/2008/lectures/lecture15.pdf
        // slide 16,17, and 18 for where this test example was taken from.
        public static FOLKnowledgeBase createABCDEqualityAndSubstitutionKnowledgeBase(
            InferenceProcedure infp, bool includeEqualityAxioms)
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addConstant("D");
            domain.addPredicate("P");
            domain.addFunction("F");

            FOLKnowledgeBase kb = new FOLKnowledgeBase(domain, infp);

            kb.tell("F(A) = B");
            kb.tell("F(B) = A");
            kb.tell("C = D");
            kb.tell("P(A)");
            kb.tell("P(C)");

            if (includeEqualityAxioms)
            {
                // Reflexivity Axiom
                kb.tell("x = x");
                // Symmetry Axiom
                kb.tell("(x = y => y = x)");
                // Transitivity Axiom
                kb.tell("((x = y AND y = z) => x = z)");
                // Function F Substitution Axiom
                kb.tell("((x = y AND F(y) = z) => F(x) = z)");
                // Predicate P Substitution Axiom
                kb.tell("((x = y AND P(y)) => P(x))");
            }
            return(kb);
        }
Exemplo n.º 2
0
        public void testSimpleClauseNonExample()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addPredicate("P");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            ICollection <Literal> lits = CollectionFactory.CreateQueue <Literal>();
            Predicate             p1   = (Predicate)parser.parse("P(y, F(A,y))");

            lits.Add(new Literal(p1));

            Clause clExpression = new Clause(lits);

            TermEquality assertion = (TermEquality)parser.parse("F(x,B) = C");

            Clause altClExpression = demodulation.apply(assertion, clExpression);

            Assert.IsNull(altClExpression);
        }
Exemplo n.º 3
0
        static void fOL_Demodulation()
        {
            System.Console.WriteLine("-----------------");
            System.Console.WriteLine("Demodulation Demo");
            System.Console.WriteLine("-----------------");
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addConstant("D");
            domain.addConstant("E");
            domain.addPredicate("P");
            domain.addFunction("F");
            domain.addFunction("G");
            domain.addFunction("H");
            domain.addFunction("J");

            FOLParser parser = new FOLParser(domain);

            Predicate    expression = (Predicate)parser.parse("P(A,F(B,G(A,H(B)),C),D)");
            TermEquality assertion  = (TermEquality)parser.parse("B = E");

            Demodulation demodulation  = new Demodulation();
            Predicate    altExpression = (Predicate)demodulation.apply(assertion, expression);

            System.Console.WriteLine("Demodulate '" + expression + "' with '" + assertion + "' to give");
            System.Console.WriteLine(altExpression.ToString());
            System.Console.WriteLine("and again to give");
            System.Console.WriteLine(demodulation.apply(assertion, altExpression).ToString());
            System.Console.WriteLine("");
        }
Exemplo n.º 4
0
        public void testCascadedOccursCheck()
        {
            FOLDomain domain = new FOLDomain();

            domain.addPredicate("P");
            domain.addFunction("F");
            domain.addFunction("SF0");
            domain.addFunction("SF1");
            FOLParser parser = new FOLParser(domain);

            Sentence s1 = parser.parse("P(SF1(v2),v2)");
            Sentence s2 = parser.parse("P(v3,SF0(v3))");
            IMap <Variable, Term> result = unifier.unify(s1, s2);

            Assert.IsNull(result);

            s1     = parser.parse("P(v1,SF0(v1),SF0(v1),SF0(v1),SF0(v1))");
            s2     = parser.parse("P(v2,SF0(v2),v2,     v3,     v2)");
            result = unifier.unify(s1, s2);

            Assert.IsNull(result);

            s1 = parser
                 .parse("P(v1,   F(v2),F(v2),F(v2),v1,      F(F(v1)),F(F(F(v1))),v2)");
            s2 = parser
                 .parse("P(F(v3),v4,   v5,   v6,   F(F(v5)),v4,      F(v3),      F(F(v5)))");
            result = unifier.unify(s1, s2);

            Assert.IsNull(result);
        }
Exemplo n.º 5
0
        public void testBypassReflexivityAxiom()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addPredicate("P");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            List <Literal> lits = new List <Literal>();
            AtomicSentence a1   = (AtomicSentence)parser.parse("P(y, F(A,y))");

            lits.Add(new Literal(a1));

            Clause c1 = new Clause(lits);

            lits.Clear();
            a1 = (AtomicSentence)parser.parse("x = x");
            lits.Add(new Literal(a1));

            Clause c2 = new Clause(lits);

            List <Clause> paras = paramodulation.apply(c1, c2);

            Assert.AreEqual(0, paras.Count);
        }
Exemplo n.º 6
0
        public void setUp()
        {
            FOLDomain domain = DomainFactory.crusadesDomain();

            lexer  = new FOLLexer(domain);
            parser = new FOLParser(lexer);
        }
Exemplo n.º 7
0
        public void testBypassReflexivityAxiom()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addPredicate("P");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            List <Literal> lits = new List <Literal>();
            Predicate      p1   = (Predicate)parser.parse("P(y, F(A,y))");

            lits.Add(new Literal(p1));

            Clause clExpression = new Clause(lits);

            TermEquality assertion = (TermEquality)parser.parse("x = x");

            Clause altClExpression = demodulation.apply(assertion, clExpression);

            Assert.IsNull(altClExpression);
        }
Exemplo n.º 8
0
        public void testSimpleAtomicNonExample()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addConstant("D");
            domain.addConstant("E");
            domain.addPredicate("P");
            domain.addFunction("F");
            domain.addFunction("G");
            domain.addFunction("H");
            domain.addFunction("J");

            FOLParser parser = new FOLParser(domain);

            Predicate    expression = (Predicate)parser.parse("P(A,G(x,B),C)");
            TermEquality assertion  = (TermEquality)parser.parse("G(A,y) = J(y)");

            Predicate altExpression = (Predicate)demodulation.apply(assertion,
                                                                    expression);

            Assert.IsNull(altExpression);
        }
        public void testDefaultClauseSimplifier()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("ZERO");
            domain.addConstant("ONE");
            domain.addPredicate("P");
            domain.addFunction("Plus");
            domain.addFunction("Power");

            FOLParser parser = new FOLParser(domain);

            ICollection <TermEquality> rewrites = CollectionFactory.CreateQueue <TermEquality>();

            rewrites.Add((TermEquality)parser.parse("Plus(x, ZERO) = x"));
            rewrites.Add((TermEquality)parser.parse("Plus(ZERO, x) = x"));
            rewrites.Add((TermEquality)parser.parse("Power(x, ONE) = x"));
            rewrites.Add((TermEquality)parser.parse("Power(x, ZERO) = ONE"));
            DefaultClauseSimplifier simplifier = new DefaultClauseSimplifier(rewrites);

            Sentence s1 = parser.parse("((P(Plus(y,ZERO),Plus(ZERO,y)) OR P(Power(y, ONE),Power(y,ZERO))) OR P(Power(y,ZERO),Plus(y,ZERO)))");

            CNFConverter cnfConverter = new CNFConverter(parser);

            CNF cnf = cnfConverter.convertToCNF(s1);

            Assert.AreEqual(1, cnf.getNumberOfClauses());

            Clause simplified = simplifier.simplify(cnf.getConjunctionOfClauses().Get(0));

            Assert.AreEqual("[P(y,y), P(y,ONE), P(ONE,y)]", simplified.ToString());
        }
Exemplo n.º 10
0
        public void testNegativeTermEquality()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addPredicate("P");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            ICollection <Literal> lits = CollectionFactory.CreateQueue <Literal>();
            AtomicSentence        a1   = (AtomicSentence)parser.parse("P(y, F(A,y))");

            lits.Add(new Literal(a1));

            Clause c1 = new Clause(lits);

            lits.Clear();
            a1 = (AtomicSentence)parser.parse("F(x,B) = x");
            lits.Add(new Literal(a1, true));

            Clause c2 = new Clause(lits);

            ISet <Clause> paras = paramodulation.apply(c1, c2);

            Assert.AreEqual(0, paras.Size());
        }
        // Note: see -
        // http://logic.stanford.edu/classes/cs157/2008/lectures/lecture15.pdf
        // slide 12 for where this test example was taken from.
        public static FOLKnowledgeBase createABCEqualityKnowledgeBase(
            InferenceProcedure infp, bool includeEqualityAxioms)
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");

            FOLKnowledgeBase kb = new FOLKnowledgeBase(domain, infp);

            kb.tell("B = A");
            kb.tell("B = C");

            if (includeEqualityAxioms)
            {
                // Reflexivity Axiom
                kb.tell("x = x");
                // Symmetry Axiom
                kb.tell("(x = y => y = x)");
                // Transitivity Axiom
                kb.tell("((x = y AND y = z) => x = z)");
            }
            return(kb);
        }
Exemplo n.º 12
0
        public void testAdditionalVariableMixtures()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addFunction("F");
            domain.addFunction("G");
            domain.addFunction("H");
            domain.addPredicate("P");

            FOLParser parser = new FOLParser(domain);

            // Test Cascade Substitutions handled correctly
            Sentence s1 = parser.parse("P(z, x)");
            Sentence s2 = parser.parse("P(x, a)");
            IMap <Variable, Term> result = unifier.unify(s1, s2);

            Assert.AreEqual("[[z, a], [x, a]]", result.ToString());

            s1     = parser.parse("P(x, z)");
            s2     = parser.parse("P(a, x)");
            result = unifier.unify(s1, s2);

            Assert.AreEqual("[[x, a], [z, a]]", result.ToString());

            s1     = parser.parse("P(w, w, w)");
            s2     = parser.parse("P(x, y, z)");
            result = unifier.unify(s1, s2);

            Assert.AreEqual("[[w, z], [x, z], [y, z]]", result.ToString());

            s1     = parser.parse("P(x, y, z)");
            s2     = parser.parse("P(w, w, w)");
            result = unifier.unify(s1, s2);

            Assert.AreEqual("[[x, w], [y, w], [z, w]]", result.ToString());

            s1     = parser.parse("P(x, B, F(y))");
            s2     = parser.parse("P(A, y, F(z))");
            result = unifier.unify(s1, s2);

            Assert.AreEqual("[[x, A], [y, B], [z, B]]", result.ToString());

            s1     = parser.parse("P(F(x,B), G(y),         F(z,A))");
            s2     = parser.parse("P(y,      G(F(G(w),w)), F(w,z))");
            result = unifier.unify(s1, s2);

            Assert.IsNull(result);

            s1     = parser.parse("P(F(G(A)), x,    F(H(z,z)), H(y,    G(w)))");
            s2     = parser.parse("P(y,       G(z), F(v     ), H(F(w), x   ))");
            result = unifier.unify(s1, s2);

            Assert.AreEqual(
                "[[y, F(G(A))], [x, G(G(A))], [v, H(G(A),G(A))], [w, G(A)], [z, G(A)]]",
                result.ToString());
        }
Exemplo n.º 13
0
        public void testAdditionalVariableMixtures()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addFunction("F");
            domain.addFunction("G");
            domain.addFunction("H");
            domain.addPredicate("P");

            FOLParser parser = new FOLParser(domain);

            // Test Cascade Substitutions handled correctly
            Sentence s1 = parser.parse("P(z, x)");
            Sentence s2 = parser.parse("P(x, a)");
            Dictionary <Variable, Term> result = unifier.unify(s1, s2);

            Assert.AreEqual("{z=a, x=a}", result.ToString());

            s1     = parser.parse("P(x, z)");
            s2     = parser.parse("P(a, x)");
            result = unifier.unify(s1, s2);

            Assert.AreEqual("{x=a, z=a}", result.ToString());

            s1     = parser.parse("P(w, w, w)");
            s2     = parser.parse("P(x, y, z)");
            result = unifier.unify(s1, s2);

            Assert.AreEqual("{w=z, x=z, y=z}", result.ToString());

            s1     = parser.parse("P(x, y, z)");
            s2     = parser.parse("P(w, w, w)");
            result = unifier.unify(s1, s2);

            Assert.AreEqual("{x=w, y=w, z=w}", result.ToString());

            s1     = parser.parse("P(x, B, F(y))");
            s2     = parser.parse("P(A, y, F(z))");
            result = unifier.unify(s1, s2);

            Assert.AreEqual("{x=A, y=B, z=B}", result.ToString());

            s1     = parser.parse("P(F(x,B), G(y),         F(z,A))");
            s2     = parser.parse("P(y,      G(F(G(w),w)), F(w,z))");
            result = unifier.unify(s1, s2);

            Assert.IsNull(result);

            s1     = parser.parse("P(F(G(A)), x,    F(H(z,z)), H(y,    G(w)))");
            s2     = parser.parse("P(y,       G(z), F(v     ), H(F(w), x   ))");
            result = unifier.unify(s1, s2);

            Assert.AreEqual(
                "{y=F(G(A)), x=G(G(A)), v=H(G(A),G(A)), w=G(A), z=G(A)}",
                result.ToString());
        }
Exemplo n.º 14
0
        public void testImplicationsAndExtendedAndsOrs()
        {
            FOLDomain domain = new FOLDomain();

            domain.addPredicate("Cheat");
            domain.addPredicate("Extra");
            domain.addPredicate("Knows");
            domain.addPredicate("Diff");
            domain.addPredicate("F");
            domain.addPredicate("A");
            domain.addPredicate("Probation");
            domain.addPredicate("Award");

            FOLParser    parser  = new FOLParser(domain);
            CNFConverter cnfConv = new CNFConverter(parser);

            // cheat(x,y) => f(x,y)
            Sentence def1    = parser.parse("(Cheat(x,y) => F(x,y))");
            CNF      cnfDef1 = cnfConv.convertToCNF(def1);

            Assert.AreEqual("[~Cheat(x,y), F(x,y)]", cnfDef1.ToString());

            // extra(x,y) | knows(x) => a(x,y)
            Sentence def2    = parser.parse("((Extra(x,y) OR Knows(x)) => A(x,y))");
            CNF      cnfDef2 = cnfConv.convertToCNF(def2);

            Assert.AreEqual("[~Extra(x,y), A(x,y)],[~Knows(x), A(x,y)]",
                            cnfDef2.ToString());

            // f(x,y) & f(x,z) & diff(y,z) <=> probation(x)
            Sentence def3 = parser
                            .parse("(((NOT(((F(x,y) AND F(x,z)) AND Diff(y,z)))) OR Probation(x)) AND (((F(x,y) AND F(x,z)) AND Diff(y,z)) OR NOT(Probation(x))))");
            CNF cnfDef3 = cnfConv.convertToCNF(def3);

            Assert
            .AreEqual(
                "[~Diff(y,z), ~F(x,y), ~F(x,z), Probation(x)],[~Probation(x), F(x,y)],[~Probation(x), F(x,z)],[~Probation(x), Diff(y,z)]",
                cnfDef3.ToString());

            // a(x,y) & a(x,z) & diff(y,z) <=> award(x)
            Sentence def4 = parser
                            .parse("(((NOT(((A(x,y) AND A(x,z)) AND Diff(y,z)))) OR Award(x)) AND (((A(x,y) AND A(x,z)) AND Diff(y,z)) OR NOT(Award(x))))");
            CNF cnfDef4 = cnfConv.convertToCNF(def4);

            Assert
            .AreEqual(
                "[~A(x,y), ~A(x,z), ~Diff(y,z), Award(x)],[~Award(x), A(x,y)],[~Award(x), A(x,z)],[~Award(x), Diff(y,z)]",
                cnfDef4.ToString());

            // f(x,y) <=> ~a(x,y)
            Sentence def5 = parser
                            .parse("( ( NOT(F(x,y)) OR NOT(A(x,y))) AND ( F(x,y) OR NOT(NOT(A(x,y))) ) )");
            CNF cnfDef5 = cnfConv.convertToCNF(def5);

            Assert.AreEqual("[~A(x,y), ~F(x,y)],[A(x,y), F(x,y)]", cnfDef5
                            .ToString());
        }
Exemplo n.º 15
0
        public void testNestedExistsAndOrs()
        {
            FOLDomain domain = new FOLDomain();

            domain.addPredicate("P");
            domain.addPredicate("R");
            domain.addPredicate("Q");

            FOLParser parser = new FOLParser(domain);

            Sentence origSentence = parser
                                    .parse("EXISTS w (FORALL x ( (EXISTS z (Q(w, z))) => (EXISTS y (NOT(P(x, y)) AND R(y))) ) )");

            CNFConverter cnfConv = new CNFConverter(parser);

            CNF cnf = cnfConv.convertToCNF(origSentence);

            Assert.AreEqual("[~P(x,SF0(x)), ~Q(SC0,z)],[~Q(SC0,z), R(SF0(x))]",
                            cnf.ToString());

            // Ax.Ay.(p(x,y) => Ez.(q(x,y,z)))
            origSentence = parser
                           .parse("FORALL x1 (FORALL y1 (P(x1, y1) => EXISTS z1 (Q(x1, y1, z1))))");

            cnf = cnfConv.convertToCNF(origSentence);

            Assert.AreEqual("[~P(x1,y1), Q(x1,y1,SF1(x1,y1))]", cnf.ToString());

            // Ex.Ay.Az.(r(y,z) <=> q(x,y,z))
            origSentence = parser
                           .parse("EXISTS x2 (FORALL y2 (FORALL z2 (R(y2, z2) <=> Q(x2, y2, z2))))");

            cnf = cnfConv.convertToCNF(origSentence);

            Assert.AreEqual(
                "[~R(y2,z2), Q(SC1,y2,z2)],[~Q(SC1,y2,z2), R(y2,z2)]", cnf
                .ToString());

            // Ax.Ey.(~p(x,y) => Az.(q(x,y,z)))
            origSentence = parser
                           .parse("FORALL x3 (EXISTS y3 (NOT(P(x3, y3)) => FORALL z3 (Q(x3, y3, z3))))");

            cnf = cnfConv.convertToCNF(origSentence);

            Assert
            .AreEqual("[P(x3,SF2(x3)), Q(x3,SF2(x3),z3)]", cnf
                      .ToString());

            // Ew.Ex.Ey.Ez.(r(x,y) & q(x,w,z))
            origSentence = parser
                           .parse("NOT(EXISTS w4 (EXISTS x4 (EXISTS y4 ( EXISTS z4 (R(x4, y4) AND Q(x4, w4, z4))))))");

            cnf = cnfConv.convertToCNF(origSentence);

            Assert.AreEqual("[~Q(x4,w4,z4), ~R(x4,y4)]", cnf.ToString());
        }
Exemplo n.º 16
0
        public static FOLDomain kingsDomain()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("John");
            domain.addConstant("Richard");
            domain.addPredicate("King");
            domain.addPredicate("Greedy");
            domain.addPredicate("Evil");
            return(domain);
        }
Exemplo n.º 17
0
 public FOLKnowledgeBase(FOLDomain domain, InferenceProcedure inferenceProcedure, Unifier unifier)
 {
     this.parser             = new FOLParser(new FOLDomain(domain));
     this.inferenceProcedure = inferenceProcedure;
     this.unifier            = unifier;
     //
     this.substVisitor      = new SubstVisitor();
     this.variableCollector = new VariableCollector();
     this._standardizeApart = new StandardizeApart(variableCollector, substVisitor);
     this.cnfConverter      = new CNFConverter(parser);
 }
Exemplo n.º 18
0
        public static FOLDomain knowsDomain()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("John");
            domain.addConstant("Jane");
            domain.addConstant("Bill");
            domain.addConstant("Elizabeth");
            domain.addFunction("Mother");
            domain.addPredicate("Knows");
            return(domain);
        }
        public void testExhaustsSearchSpace()
        {
            // Taken from AIMA pg 679
            FOLDomain domain = new FOLDomain();

            domain.addPredicate("alternate");
            domain.addPredicate("bar");
            domain.addPredicate("fri_sat");
            domain.addPredicate("hungry");
            domain.addPredicate("patrons");
            domain.addPredicate("price");
            domain.addPredicate("raining");
            domain.addPredicate("reservation");
            domain.addPredicate("type");
            domain.addPredicate("wait_estimate");
            domain.addPredicate("will_wait");
            domain.addConstant("Some");
            domain.addConstant("Full");
            domain.addConstant("French");
            domain.addConstant("Thai");
            domain.addConstant("Burger");
            domain.addConstant("$");
            domain.addConstant("_30_60");
            domain.addConstant("X0");
            FOLParser parser = new FOLParser(domain);

            // The hypothesis
            String c1 = "patrons(v,Some)";
            String c2 = "patrons(v,Full) AND (hungry(v) AND type(v,French))";
            String c3 = "patrons(v,Full) AND (hungry(v) AND (type(v,Thai) AND fri_sat(v)))";
            String c4 = "patrons(v,Full) AND (hungry(v) AND type(v,Burger))";
            String sh = "FORALL v (will_wait(v) <=> (" + c1 + " OR (" + c2
                        + " OR (" + c3 + " OR (" + c4 + ")))))";

            Sentence hypothesis = parser.parse(sh);
            Sentence desc       = parser
                                  .parse("(((((((((alternate(X0) AND NOT(bar(X0))) AND NOT(fri_sat(X0))) AND hungry(X0)) AND patrons(X0,Full)) AND price(X0,$)) AND NOT(raining(X0))) AND NOT(reservation(X0))) AND type(X0,Thai)) AND wait_estimate(X0,_30_60))");
            Sentence classification = parser.parse("will_wait(X0)");

            FOLKnowledgeBase kb = new FOLKnowledgeBase(domain,
                                                       new FOLOTTERLikeTheoremProver(false));

            kb.tell(hypothesis);
            kb.tell(desc);

            InferenceResult ir = kb.ask(classification);

            Assert.IsFalse(ir.isTrue());
            Assert.IsTrue(ir.isPossiblyFalse());
            Assert.IsFalse(ir.isUnknownDueToTimeout());
            Assert.IsFalse(ir.isPartialResultDueToTimeout());
            Assert.AreEqual(0, ir.getProofs().Count);
        }
Exemplo n.º 20
0
        public static FOLDomain lovesAnimalDomain()
        {
            FOLDomain domain = new FOLDomain();

            domain.addPredicate("Animal");
            domain.addPredicate("Loves");
            domain.addPredicate("Kills");
            domain.addPredicate("Cat");
            domain.addConstant("Jack");
            domain.addConstant("Tuna");
            domain.addConstant("Curiosity");
            return(domain);
        }
Exemplo n.º 21
0
        public void testInductionAxiomSchema()
        {
            FOLDomain domain = new FOLDomain();

            domain.addPredicate("Equal");
            domain.addFunction("Plus");
            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("N");
            domain.addConstant("ONE");
            domain.addConstant("ZERO");

            FOLParser    parser  = new FOLParser(domain);
            CNFConverter cnfConv = new CNFConverter(parser);

            // Base Case:
            Sentence sent = parser
                            .parse("NOT(FORALL x (FORALL y (Equal(Plus(Plus(x,y),ZERO), Plus(x,Plus(y,ZERO))))))");
            CNF cnf = cnfConv.convertToCNF(sent);

            Assert.AreEqual(
                "[~Equal(Plus(Plus(SC0,SC1),ZERO),Plus(SC0,Plus(SC1,ZERO)))]",
                cnf.ToString());

            // Instance of Induction Axion Scmema
            sent = parser
                   .parse("(("
                          + "Equal(Plus(Plus(A,B),ZERO), Plus(A,Plus(B,ZERO)))"
                          + " AND "
                          + "(FORALL x (FORALL y (FORALL z("
                          + "Equal(Plus(Plus(x,y),z), Plus(x,Plus(y,z)))"
                          + " => "
                          + "Equal(Plus(Plus(x,y),Plus(z,ONE)), Plus(x,Plus(y,Plus(z,ONE))))"
                          + "))))" + ")" + " => "
                          + "FORALL x (FORALL y (FORALL z("
                          + "Equal(Plus(Plus(x,y),z), Plus(x,Plus(y,z)))"
                          + "))))");
            cnf = cnfConv.convertToCNF(sent);
            Assert
            .AreEqual(
                "[~Equal(Plus(Plus(A,B),ZERO),Plus(A,Plus(B,ZERO))), Equal(Plus(Plus(q0,q1),q2),Plus(q0,Plus(q1,q2))), Equal(Plus(Plus(SC2,SC3),SC4),Plus(SC2,Plus(SC3,SC4)))],[~Equal(Plus(Plus(A,B),ZERO),Plus(A,Plus(B,ZERO))), ~Equal(Plus(Plus(SC2,SC3),Plus(SC4,ONE)),Plus(SC2,Plus(SC3,Plus(SC4,ONE)))), Equal(Plus(Plus(q0,q1),q2),Plus(q0,Plus(q1,q2)))]",
                cnf.ToString());

            // Goal
            sent = parser
                   .parse("NOT(FORALL x (FORALL y (FORALL z (Equal(Plus(Plus(x,y),z), Plus(x,Plus(y,z)))))))");
            cnf = cnfConv.convertToCNF(sent);
            Assert.AreEqual(
                "[~Equal(Plus(Plus(SC5,SC6),SC7),Plus(SC5,Plus(SC6,SC7)))]",
                cnf.ToString());
        }
Exemplo n.º 22
0
        public void setUp()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("P");
            domain.addConstant("John");
            domain.addConstant("Saladin");
            domain.addFunction("LeftLeg");
            domain.addFunction("BrotherOf");
            domain.addFunction("EnemyOf");
            domain.addPredicate("HasColor");
            domain.addPredicate("King");
            lexer = new FOLLexer(domain);
        }
Exemplo n.º 23
0
        public FOLLexer(FOLDomain domain)
        {
            this.domain = domain;

            connectors = new HashSet <String>();
            connectors.Add(Connectors.NOT);
            connectors.Add(Connectors.AND);
            connectors.Add(Connectors.OR);
            connectors.Add(Connectors.IMPLIES);
            connectors.Add(Connectors.BICOND);

            quantifiers = new HashSet <String>();
            quantifiers.Add(Quantifiers.FORALL);
            quantifiers.Add(Quantifiers.EXISTS);
        }
Exemplo n.º 24
0
        public FOLLexer(FOLDomain domain)
        {
            this.domain = domain;

            connectors = CollectionFactory.CreateSet <string>();
            connectors.Add(Connectors.NOT);
            connectors.Add(Connectors.AND);
            connectors.Add(Connectors.OR);
            connectors.Add(Connectors.IMPLIES);
            connectors.Add(Connectors.BICOND);

            quantifiers = CollectionFactory.CreateSet <string>();
            quantifiers.Add(Quantifiers.FORALL);
            quantifiers.Add(Quantifiers.EXISTS);
        }
Exemplo n.º 25
0
        public FOLLexer(FOLDomain domain)
        {
            this.Domain = domain;

            connectors = new HashedSet <string>();
            connectors.Add(Connectors.Not);
            connectors.Add(Connectors.And);
            connectors.Add(Connectors.Or);
            connectors.Add(Connectors.Implies);
            connectors.Add(Connectors.BiCond);

            quantifiers = new HashedSet <string>();
            quantifiers.Add(Quantifiers.ForAll);
            quantifiers.Add(Quantifiers.Exists);
        }
Exemplo n.º 26
0
        public void testExamplePg295AIMA2e()
        {
            FOLDomain domain = DomainFactory.weaponsDomain();
            FOLParser parser = new FOLParser(domain);

            Sentence origSentence = parser
                                    .parse("FORALL x ((((American(x) AND Weapon(y)) AND Sells(x, y, z)) AND Hostile(z)) => Criminal(x))");

            CNFConverter cnfConv = new CNFConverter(parser);

            CNF cnf = cnfConv.convertToCNF(origSentence);

            Assert.AreEqual(
                "[~American(x), ~Hostile(z), ~Sells(x,y,z), ~Weapon(y), Criminal(x)]",
                cnf.ToString());
        }
Exemplo n.º 27
0
        public void testExamplePg296AIMA2e()
        {
            FOLDomain domain = DomainFactory.lovesAnimalDomain();
            FOLParser parser = new FOLParser(domain);

            Sentence origSentence = parser
                                    .parse("FORALL x (FORALL y (Animal(y) => Loves(x, y)) => EXISTS y Loves(y, x))");

            CNFConverter cnfConv = new CNFConverter(parser);

            CNF cnf = cnfConv.convertToCNF(origSentence);

            Assert.AreEqual(
                "[Animal(SF0(x)), Loves(SF1(x),x)],[~Loves(x,SF0(x)), Loves(SF1(x),x)]",
                cnf.ToString());
        }
        public static FOLDomain crusadesDomain()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("John");
            domain.addConstant("Richard");
            domain.addConstant("England");
            domain.addConstant("Saladin");
            domain.addConstant("Crown");

            domain.addFunction("LeftLegOf");
            domain.addFunction("BrotherOf");
            domain.addFunction("EnemyOf");
            domain.addFunction("LegsOf");

            domain.addPredicate("King");
            return(domain);
        }
Exemplo n.º 29
0
        public static FOLDomain ringOfThievesDomain()
        {
            FOLDomain domain = new FOLDomain();

            domain.addPredicate("Parent");
            domain.addPredicate("Caught");
            domain.addPredicate("Friend");
            domain.addPredicate("Skis");
            domain.addConstant("Mike");
            domain.addConstant("Joe");
            domain.addConstant("Janet");
            domain.addConstant("Nancy");
            domain.addConstant("Ernie");
            domain.addConstant("Bert");
            domain.addConstant("Red");
            domain.addConstant("Drew");
            return(domain);
        }
Exemplo n.º 30
0
        static void fOL_CNFConversion()
        {
            System.Console.WriteLine("-------------------------------------------------");
            System.Console.WriteLine("Conjuctive Normal Form for First Order Logic Demo");
            System.Console.WriteLine("-------------------------------------------------");
            FOLDomain domain = DomainFactory.lovesAnimalDomain();
            FOLParser parser = new FOLParser(domain);

            Sentence origSentence = parser.parse("FORALL x (FORALL y (Animal(y) => Loves(x, y)) => EXISTS y Loves(y, x))");

            CNFConverter cnfConv = new CNFConverter(parser);

            CNF cnf = cnfConv.convertToCNF(origSentence);

            System.Console.WriteLine("Convert '" + origSentence + "' to CNF.");
            System.Console.WriteLine("CNF=" + cnf.ToString());
            System.Console.WriteLine("");
        }