Example #1
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("");
        }
Example #2
0
        public void testSimpleAtomicExamples()
        {
            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");

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

            Assert.IsFalse(expression.Equals(altExpression));
            Assert
            .AreEqual("P(A,F(E,G(A,H(B)),C),D)", altExpression
                      .ToString());

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

            Assert
            .AreEqual("P(A,F(E,G(A,H(E)),C),D)", altExpression
                      .ToString());

            assertion = (TermEquality)parser.parse("G(x,y) = J(x)");

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

            Assert.AreEqual("P(A,F(B,J(A),C),D)", altExpression.ToString());
        }
Example #3
0
        public Clause simplify(Clause c)
        {
            Clause simplified = c;

            // Apply each of the rewrite rules to the clause
            foreach (TermEquality te in rewrites)
            {
                Clause dc = simplified;
                // Keep applying the rewrite as many times as it
                // can be applied before moving on to the next one.
                while (null != (dc = demodulation.apply(te, dc)))
                {
                    simplified = dc;
                }
            }

            return(simplified);
        }