AIMA.Test.Core.Unit.Logic.FOL.CNFConverterTest.testNestedExistsAndOrs C# (CSharp) Method

testNestedExistsAndOrs() private method

private testNestedExistsAndOrs ( ) : void
return void
        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());
        }