Exemple #1
0
        public void ResolveRuleMultipleTest()
        {
            Expression <Del1> node1 = (x) => P(x) | !Q(x) | R(x);
            Expression <Del1> node2 = (x) => !P(x) | Q(x) | !R(x);
            var result = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(node1), Expressions2LogicTree.Parse(node2));

            Assert.AreEqual(3, result.Count());
        }
Exemple #2
0
        public void ResolveWithUnificateTest()
        {
            Expression <Del1> root      = (x) => P(x) | Q(f(x));
            Expression <Del1> gypotesis = (z) => !P(g(z));
            var result = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(root), Expressions2LogicTree.Parse(gypotesis)).ToList();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("Q(f(g(z)))", result[0].ToString());
        }
Exemple #3
0
        public void PredicateAndNegatePredicate()
        {
            Expression <Del1> root      = (x) => P(x);
            Expression <Del1> gypotesis = (x) => !P(x);

            var result =
                ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(root), Expressions2LogicTree.Parse(gypotesis)).ToList();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("", result[0].ToString());
        }
Exemple #4
0
        public void ErrorUnificationTest()
        {
            // Q(f(a),g(x))
            Expression <Del1> A = (x) => Q(f(a), g(x));
            // Q(y,y)
            Expression <Del1> B = (y) => Q(y, y);
            var node1           = (SkolemPredicateNode)Expressions2LogicTree.Parse(A).Children[0];
            var node2           = (SkolemPredicateNode)Expressions2LogicTree.Parse(B).Children[0];

            Assert.AreEqual(false, UnificationService.CanUnificate(node1, node2));
        }
Exemple #5
0
        public void ResolveRuleTest()
        {
            // P(x) V Q(f(y))
            Expression <Del2> root = (x, y) => P(x) | Q(f(y));
            // !P(x)
            Expression <Del1> gypotesis = (x) => !P(x);
            var result = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(root), Expressions2LogicTree.Parse(gypotesis)).ToList();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("Q(f(y))", result[0].ToString());
            result = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(gypotesis), Expressions2LogicTree.Parse(root)).ToList();
            Assert.AreEqual("Q(f(y))", result[0].ToString());
        }
Exemple #6
0
        public void ResolutionOnResultOfResolution()
        {
            Expression <Del1> f1 = (x) => P(x) | Q(x);
            Expression <Del1> f2 = (x) => !Q(x);
            Expression <Del1> f3 = (x) => !P(x);

            //P(x)
            var result = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(f1), Expressions2LogicTree.Parse(f2)).Single();
            //{} ?
            var result2 = ComputerAlgebra.Resolve(Expressions2LogicTree.Parse(f3), result).ToList();

            Assert.AreEqual(1, result2.Count);
            Assert.AreEqual("", result2[0].ToString());
        }
Exemple #7
0
        static void Main()
        {
            //Type two clauses in SNF without quantifiers
            Expression <Func <int, int, int, int, BooleanGroup> > exp       = (x, y, z, u) => !P(x, y) | Q(z, g(u)) | R(z, f(u));
            Expression <Func <int, int, BooleanGroup> >           gypotesis = (x, u) => !R(x, f(u)) | P(b, h(a));

            var expNode       = Expressions2LogicTree.Parse(exp);
            var gypotesisNode = Expressions2LogicTree.Parse(gypotesis);

            Console.WriteLine("First clause: {0}", expNode);
            Console.WriteLine("Second clause: {0}", gypotesisNode);
            var result = ComputerAlgebra.Resolve(expNode, gypotesisNode).ToList();

            Console.WriteLine("Possible resolvents: [{0}]", string.Join(" ; ", result));
        }
Exemple #8
0
        public void HardUnificationTest()
        {
            // P(a,x,f(g(y))
            Expression <Del2> A = (x, y) => P(a, x, f(g(y)));
            // P(z,f(z),f(u))
            Expression <Del2> B = (z, u) => P(z, f(z), f(u));
            var node1           = (SkolemPredicateNode)Expressions2LogicTree.Parse(A).Children[0];
            var node2           = (SkolemPredicateNode)Expressions2LogicTree.Parse(B).Children[0];

            Assert.AreEqual(true, UnificationService.CanUnificate(node1, node2));
            var rules = UnificationService.GetUnificationRules(node1, node2);

            Assert.AreEqual(3, rules.Count);
            UnificationService.Unificate(node1, node2);
            Assert.AreEqual(node1.ToString(), node2.ToString());
        }
Exemple #9
0
        public void ParseTest()
        {
            Expression <Del1> e    = (x) => !P(f(x)) | P(x);
            INode             node = Expressions2LogicTree.Parse(e);

            Assert.AreEqual(new MultipleOr(new SkolemPredicateNode("P", true, new FunctionNode("f", VariableNode.Make <bool>(0, "x"))),
                                           new SkolemPredicateNode("P", false, VariableNode.Make <bool>(0, "x"))).ToString(),
                            node.ToString());
            Expression <Del3> e3 = (x, y, z) => P(f(x, y)) | !P(y) | P(x, y, z);

            node = Expressions2LogicTree.Parse(e3);
            Assert.AreEqual(new MultipleOr(new SkolemPredicateNode("P", false, new FunctionNode("f", VariableNode.Make <bool>(0, "x"), VariableNode.Make <bool>(1, "y"))),
                                           new SkolemPredicateNode("P", true, VariableNode.Make <bool>(1, "y")),
                                           new SkolemPredicateNode("P", false, VariableNode.Make <bool>(0, "x"), VariableNode.Make <bool>(1, "y"), VariableNode.Make <bool>(2, "z"))).ToString(),
                            node.ToString());
            Expression <Del1> e2 = (x) => P(f(x), a);

            node = Expressions2LogicTree.Parse(e2);
            Assert.AreEqual(new MultipleOr(new SkolemPredicateNode("P", false,
                                                                   new FunctionNode("f", VariableNode.Make <bool>(0, "x")),
                                                                   new FunctionNode("a"))).ToString(),
                            node.ToString());
        }