Example #1
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));
        }
Example #2
0
        /// <summary>
        /// Using resolution rule: A V B, C V !B |- A V C.
        /// </summary>
        /// <param name="z"></param>
        private static void Modificator(ITypizedDecorArray <MultipleOr, SkolemPredicateNode, MultipleOr, SkolemPredicateNode> z)
        {
            var rules = UnificationService.GetUnificationRules(z.B.Node, z.D.Node);

            UnificationService.Unificate(z.A.Node, rules);
            UnificationService.Unificate(z.C.Node, rules);
            var aChildren = z.A.Node.Children.ToList();
            var cChildren = z.C.Node.Children.ToList();

            aChildren.Remove(z.B.Node);
            cChildren.Remove(z.D.Node);
            z.A.Replace(new MultipleOr(aChildren.ToArray()));
            z.C.Replace(new MultipleOr(cChildren.ToArray()));
        }
Example #3
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());
        }
Example #4
0
        public void UnificationTest()
        {
            // P(f(x), z)
            var A = new SkolemPredicateNode("P", false, new FunctionNode("f", VariableNode.Make <bool>(0, "x")),
                                            VariableNode.Make <bool>(2, "z"));
            // P(y,a)
            var B = new SkolemPredicateNode("P", false, VariableNode.Make <bool>(1, "y"), new FunctionNode("a"));

            Assert.AreEqual(true, UnificationService.CanUnificate(A, B));
            var rules = UnificationService.GetUnificationRules(A, B);

            Assert.AreEqual(2, rules.Count);
            UnificationService.Unificate(A, rules);
            UnificationService.Unificate(B, rules);
            Assert.AreEqual("P(f(x),a)", A.ToString());
            Assert.AreEqual(A.ToString(), B.ToString());
        }
Example #5
0
        public static IEnumerable <IRule> Get()
        {
            yield return(Rule
                         .New("&&0", StdTags.Inductive, StdTags.Logic, StdTags.SafeResection, StdTags.Simplification)
                         .Select(AnyA[ChildB, ChildC])
                         .Where <And, Constant <bool>, INode>(z => !z.B.Value)
                         .Mod(z => z.A.Replace(z.B.Node)));

            yield return(Rule
                         .New("||1", StdTags.Inductive, StdTags.Logic, StdTags.SafeResection, StdTags.Simplification)
                         .Select(AnyA[ChildB, ChildC])
                         .Where <Or, Constant <bool>, INode>(z => z.B.Value)
                         .Mod(z => z.A.Replace(z.B.Node)));

            yield return(Rule
                         .New("&&1", StdTags.Inductive, StdTags.Logic, StdTags.SafeResection, StdTags.Simplification)
                         .Select(AnyA[ChildB, ChildC])
                         .Where <And, Constant <bool>, INode>(z => z.B.Value)
                         .Mod(z => z.A.Replace(z.C.Node)));

            yield return(Rule
                         .New("||0", StdTags.Inductive, StdTags.Logic, StdTags.SafeResection, StdTags.Simplification)
                         .Select(AnyA[ChildB, ChildC])
                         .Where <Or, Constant <bool>, INode>(z => !z.B.Value)
                         .Mod(z => z.A.Replace(z.C.Node)));

            yield return(Rule
                         .New("!!", StdTags.Deductive, StdTags.Logic, StdTags.SafeResection, StdTags.Simplification)
                         .Select(AnyA[B[C]])
                         .Where <Not, Not, INode>()
                         .Mod(z => z.A.Replace(z.C.Node)));

            yield return(Rule
                         .New("x V x", StdTags.Inductive, StdTags.Logic, StdTags.SafeResection, StdTags.Simplification)
                         .Select(A[ChildB, ChildC])
                         .Where <Or, INode, INode>(z => UnificationService.IsSame(z.B, z.C, true))
                         .Mod(z => z.A.Replace(z.B.Node)));

            yield return(Rule
                         .New("!x V x", StdTags.Inductive, StdTags.Logic, StdTags.SafeResection, StdTags.Simplification)
                         .Select(A[ChildB[ChildC], ChildD])
                         .Where <Or, Not, INode, INode>(z => UnificationService.IsSame(z.C, z.D, true))
                         .Mod(z => z.A.Replace(new Constant <bool>(true))));
        }
Example #6
0
        public void ComplexUnificationTest()
        {
            // !P(x,b,z,s) V ANS(f(g(z,b,h(x,z,s))))
            var A = new MultipleOr(
                new SkolemPredicateNode("P", true, VariableNode.Make <bool>(0, "x"), new FunctionNode("b"), VariableNode.Make <bool>(2, "z"), VariableNode.Make <bool>(3, "s")),
                new SkolemPredicateNode("ANS", false,
                                        new FunctionNode("f",
                                                         new FunctionNode("g", VariableNode.Make <bool>(2, "z"), new FunctionNode("b"),
                                                                          new FunctionNode("h", VariableNode.Make <bool>(0, "x"), VariableNode.Make <bool>(2, "z"), VariableNode.Make <bool>(3, "s"))))));

            // P(a,b,c,s0)
            var B = new SkolemPredicateNode("P", false, new FunctionNode("a"), new FunctionNode("b"), new FunctionNode("c"), new FunctionNode("s0"));

            Assert.AreEqual(true, UnificationService.CanUnificate((SkolemPredicateNode)A.Children[0], B));
            var rules = UnificationService.GetUnificationRules((SkolemPredicateNode)A.Children[0], B);

            Assert.AreEqual(3, rules.Count);
            UnificationService.Unificate(A, rules);
            Assert.AreEqual("!P(a,b,c,s0) ∨ ANS(f(g(c,b,h(a,c,s0))))", A.ToString());
        }
Example #7
0
 public static IRule Get()
 {
     return(Rule
            .New("Resolve", StdTags.Inductive, StdTags.Logic, StdTags.SafeResection)
            .Select(A[ChildB], C[ChildD])
            .Where <MultipleOr, SkolemPredicateNode, MultipleOr, SkolemPredicateNode>(z =>
                                                                                      UnificationService.CanUnificate(z.B, z.D) && (z.B.IsNegate || z.D.IsNegate))
            .Mod(Modificator));
 }