public void testExamplesPg299AIMA2e() { FOLDomain domain = DomainFactory.lovesAnimalDomain(); FOLParser parser = new FOLParser(domain); // FOL A. 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); // CNF A1. and A2. Assert.AreEqual( "[Animal(SF0(x)), Loves(SF1(x),x)],[~Loves(x,SF0(x)), Loves(SF1(x),x)]", cnf.ToString()); // FOL B. origSentence = parser .parse("FORALL x (EXISTS y (Animal(y) AND Kills(x, y)) => FORALL z NOT(Loves(z, x)))"); cnf = cnfConv.convertToCNF(origSentence); // CNF B. Assert.AreEqual("[~Animal(y), ~Kills(x,y), ~Loves(z,x)]", cnf.ToString()); // FOL C. origSentence = parser.parse("FORALL x (Animal(x) => Loves(Jack, x))"); cnf = cnfConv.convertToCNF(origSentence); // CNF C. Assert.AreEqual("[~Animal(x), Loves(Jack,x)]", cnf.ToString()); // FOL D. origSentence = parser .parse("(Kills(Jack, Tuna) OR Kills(Curiosity, Tuna))"); cnf = cnfConv.convertToCNF(origSentence); // CNF D. Assert.AreEqual("[Kills(Curiosity,Tuna), Kills(Jack,Tuna)]", cnf.ToString()); // FOL E. origSentence = parser.parse("Cat(Tuna)"); cnf = cnfConv.convertToCNF(origSentence); // CNF E. Assert.AreEqual("[Cat(Tuna)]", cnf.ToString()); // FOL F. origSentence = parser.parse("FORALL x (Cat(x) => Animal(x))"); cnf = cnfConv.convertToCNF(origSentence); // CNF F. Assert.AreEqual("[~Cat(x), Animal(x)]", cnf.ToString()); // FOL G. origSentence = parser.parse("NOT(Kills(Curiosity, Tuna))"); cnf = cnfConv.convertToCNF(origSentence); // CNF G. Assert.AreEqual("[~Kills(Curiosity,Tuna)]", cnf.ToString()); }
public void testTermEquality() { FOLDomain domain = new FOLDomain(); domain.addPredicate("P"); domain.addPredicate("Q"); domain.addPredicate("R"); domain.addConstant("A"); domain.addConstant("B"); domain.addConstant("C"); domain.addConstant("D"); domain.addFunction("Plus"); domain.addConstant("ONE"); domain.addConstant("ZERO"); FOLParser parser = new FOLParser(domain); CNFConverter cnfConv = new CNFConverter(parser); // x=y Sentence sent = parser.parse("x = y"); CNF cnf = cnfConv.convertToCNF(sent); Assert.AreEqual("[x = y]", cnf.ToString()); // x!=y sent = parser.parse("NOT(x = y)"); cnf = cnfConv.convertToCNF(sent); Assert.AreEqual("[~x = y]", cnf.ToString()); // A=B sent = parser.parse("A = B"); cnf = cnfConv.convertToCNF(sent); Assert.AreEqual("[A = B]", cnf.ToString()); // A!=B sent = parser.parse("NOT(A = B)"); cnf = cnfConv.convertToCNF(sent); Assert.AreEqual("[~A = B]", cnf.ToString()); // ~(((~A=B or ~D=C) => ~(A=B or D=C)) => A=D) sent = parser .parse("NOT(((((NOT(A = B) OR NOT(D = C))) => NOT((A = B OR D = C))) => A = D))"); cnf = cnfConv.convertToCNF(sent); Assert.AreEqual( "[~A = B, A = B],[~A = B, D = C],[~D = C, A = B],[~D = C, D = C],[~A = D]", cnf.ToString()); // // Induction Axiom Schema using Term Equality // Base Case: sent = parser .parse("NOT(FORALL x (FORALL y (Plus(Plus(x,y),ZERO) = Plus(x,Plus(y,ZERO)))))"); cnf = cnfConv.convertToCNF(sent); Assert.AreEqual( "[~Plus(Plus(SC0,SC1),ZERO) = Plus(SC0,Plus(SC1,ZERO))]", cnf.ToString()); // Instance of Induction Axion Scmema sent = parser.parse("((" + "Plus(Plus(A,B),ZERO) = Plus(A,Plus(B,ZERO))" + " AND " + "(FORALL x (FORALL y (FORALL z(" + "Plus(Plus(x,y),z) = Plus(x,Plus(y,z))" + " => " + "Plus(Plus(x,y),Plus(z,ONE)) = Plus(x,Plus(y,Plus(z,ONE)))" + "))))" + ")" + " => " + "FORALL x (FORALL y (FORALL z(" + "Plus(Plus(x,y),z) = Plus(x,Plus(y,z))" + "))))"); cnf = cnfConv.convertToCNF(sent); Assert.AreEqual( "[~Plus(Plus(A,B),ZERO) = Plus(A,Plus(B,ZERO)), Plus(Plus(q0,q1),q2) = Plus(q0,Plus(q1,q2)), Plus(Plus(SC2,SC3),SC4) = Plus(SC2,Plus(SC3,SC4))],[~Plus(Plus(A,B),ZERO) = Plus(A,Plus(B,ZERO)), ~Plus(Plus(SC2,SC3),Plus(SC4,ONE)) = Plus(SC2,Plus(SC3,Plus(SC4,ONE))), Plus(Plus(q0,q1),q2) = Plus(q0,Plus(q1,q2))]", cnf.ToString()); // Goal sent = parser .parse("NOT(FORALL x (FORALL y (FORALL z (Plus(Plus(x,y),z) = Plus(x,Plus(y,z))))))"); cnf = cnfConv.convertToCNF(sent); Assert.AreEqual( "[~Plus(Plus(SC5,SC6),SC7) = Plus(SC5,Plus(SC6,SC7))]", cnf.ToString()); }