Пример #1
0
        public AtomicSentence apply(TermEquality assertion,
                AtomicSentence expression)
        {
            AtomicSentence altExpression = null;

            IdentifyCandidateMatchingTerm icm = getMatchingSubstitution(assertion
                    .getTerm1(), expression);

            if (null != icm)
            {
                Term replaceWith = substVisitor.subst(
                        icm.getMatchingSubstitution(), assertion.getTerm2());
                // Want to ignore reflexivity axiom situation, i.e. x = x
                if (!icm.getMatchingTerm().Equals(replaceWith))
                {
                    ReplaceMatchingTerm rmt = new ReplaceMatchingTerm();

                    // Only apply demodulation at most once on each call.
                    altExpression = rmt.replace(expression, icm.getMatchingTerm(),
                            replaceWith);
                }
            }

            return altExpression;
        }
Пример #2
0
            public AtomicSentence replace(AtomicSentence expression, Term toReplace, Term replaceWith)
            {
                this.toReplace   = toReplace;
                this.replaceWith = replaceWith;

                return((AtomicSentence)expression.accept(this, null));
            }
Пример #3
0
        public void testNegativeTermEquality()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addPredicate("P");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            ICollection <Literal> lits = CollectionFactory.CreateQueue <Literal>();
            AtomicSentence        a1   = (AtomicSentence)parser.parse("P(y, F(A,y))");

            lits.Add(new Literal(a1));

            Clause c1 = new Clause(lits);

            lits.Clear();
            a1 = (AtomicSentence)parser.parse("F(x,B) = x");
            lits.Add(new Literal(a1, true));

            Clause c2 = new Clause(lits);

            ISet <Clause> paras = paramodulation.apply(c1, c2);

            Assert.AreEqual(0, paras.Size());
        }
Пример #4
0
        public AtomicSentence apply(TermEquality assertion,
                                    AtomicSentence expression)
        {
            AtomicSentence altExpression = null;

            IdentifyCandidateMatchingTerm icm = getMatchingSubstitution(assertion
                                                                        .getTerm1(), expression);

            if (null != icm)
            {
                Term replaceWith = substVisitor.subst(
                    icm.getMatchingSubstitution(), assertion.getTerm2());
                // Want to ignore reflexivity axiom situation, i.e. x = x
                if (!icm.getMatchingTerm().Equals(replaceWith))
                {
                    ReplaceMatchingTerm rmt = new ReplaceMatchingTerm();

                    // Only apply demodulation at most once on each call.
                    altExpression = rmt.replace(expression, icm.getMatchingTerm(),
                                                replaceWith);
                }
            }

            return(altExpression);
        }
Пример #5
0
        public void testBypassReflexivityAxiom()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addPredicate("P");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            List <Literal> lits = new List <Literal>();
            AtomicSentence a1   = (AtomicSentence)parser.parse("P(y, F(A,y))");

            lits.Add(new Literal(a1));

            Clause c1 = new Clause(lits);

            lits.Clear();
            a1 = (AtomicSentence)parser.parse("x = x");
            lits.Add(new Literal(a1));

            Clause c2 = new Clause(lits);

            List <Clause> paras = paramodulation.apply(c1, c2);

            Assert.AreEqual(0, paras.Count);
        }
Пример #6
0
        public void testAtomicSentenceTrueParse()
        {
            AtomicSentence sen = (AtomicSentence)parser.parse("true");

            Assert.AreEqual(typeof(TrueSentence), sen.GetType());
            sen = (AtomicSentence)parser.parse("(true)");
            Assert.AreEqual(typeof(TrueSentence), sen.GetType());
            sen = (AtomicSentence)parser.parse("((true))");
            Assert.AreEqual(typeof(TrueSentence), sen.GetType());
        }
Пример #7
0
            public IdentifyCandidateMatchingTerm(Term toMatch,
                    AtomicSentence expression,AbstractModulation abstractModulation)
            {
                this.abstractModulation = abstractModulation;
                this.toMatch = toMatch;
                this.toMatchVariables = abstractModulation.variableCollector
                        .collectAllVariables(toMatch);

                expression.accept(this, null);
            }
Пример #8
0
            public IdentifyCandidateMatchingTerm(Term toMatch,
                                                 AtomicSentence expression,
                                                 AbstractModulation abstractModulation)
            {
                this.abstractModulation = abstractModulation;
                this.toMatch            = toMatch;
                this.toMatchVariables   = abstractModulation.variableCollector.collectAllVariables(toMatch);

                expression.accept(this, null);
            }
Пример #9
0
        protected IdentifyCandidateMatchingTerm getMatchingSubstitution(
            Term toMatch, AtomicSentence expression)
        {
            IdentifyCandidateMatchingTerm icm = new IdentifyCandidateMatchingTerm(
                toMatch, expression, this);

            if (icm.isMatch())
            {
                return(icm);
            }
            // indicates no match
            return(null);
        }
Пример #10
0
        protected IdentifyCandidateMatchingTerm getMatchingSubstitution(
                Term toMatch, AtomicSentence expression)
        {

            IdentifyCandidateMatchingTerm icm = new IdentifyCandidateMatchingTerm(
                    toMatch, expression, this);

            if (icm.isMatch())
            {
                return icm;
            }

            // indicates no match
            return null;
        }
Пример #11
0
        public override string ToString()
        {
            if (this.strRep == null)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("[");
                if (IsNegativeLiteral())
                {
                    sb.Append("~");
                }
                sb.Append(AtomicSentence.ToString());
                sb.Append("]");
                strRep = sb.ToString();
            }

            return(strRep);
        }
Пример #12
0
        public Clause apply(TermEquality assertion, Clause clExpression)
        {
            Clause altClExpression = null;

            foreach (Literal l1 in clExpression.getLiterals())
            {
                AtomicSentence altExpression = apply(assertion, l1
                                                     .getAtomicSentence());
                if (null != altExpression)
                {
                    // I have an alternative, create a new clause
                    // with the alternative and return
                    List <Literal> newLits = new List <Literal>();
                    foreach (Literal l2 in clExpression.getLiterals())
                    {
                        if (l1.Equals(l2))
                        {
                            newLits.Add(l1.newInstance(altExpression));
                        }
                        else
                        {
                            newLits.Add(l2);
                        }
                    }
                    // Only apply demodulation at most once on
                    // each call.
                    altClExpression = new Clause(newLits);
                    altClExpression.setProofStep(new ProofStepClauseDemodulation(
                                                     altClExpression, clExpression, assertion));
                    if (clExpression.isImmutable())
                    {
                        altClExpression.setImmutable();
                    }
                    if (!clExpression.isStandardizedApartCheckRequired())
                    {
                        altClExpression.setStandardizedApartCheckNotRequired();
                    }
                    break;
                }
            }

            return(altClExpression);
        }
Пример #13
0
        static void fOL_Paramodulation()
        {
            System.Console.WriteLine("-------------------");
            System.Console.WriteLine("Paramodulation Demo");
            System.Console.WriteLine("-------------------");

            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addPredicate("P");
            domain.addPredicate("Q");
            domain.addPredicate("R");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            ICollection <Literal> lits = CollectionFactory.CreateQueue <Literal>();
            AtomicSentence        a1   = (AtomicSentence)parser.parse("P(F(x,B),x)");
            AtomicSentence        a2   = (AtomicSentence)parser.parse("Q(x)");

            lits.Add(new Literal(a1));
            lits.Add(new Literal(a2));

            Clause c1 = new Clause(lits);

            lits.Clear();
            a1 = (AtomicSentence)parser.parse("F(A,y) = y");
            a2 = (AtomicSentence)parser.parse("R(y)");
            lits.Add(new Literal(a1));
            lits.Add(new Literal(a2));

            Clause c2 = new Clause(lits);

            Paramodulation paramodulation = new Paramodulation();
            ISet <Clause>  paras          = paramodulation.apply(c1, c2);

            System.Console.WriteLine("Paramodulate '" + c1 + "' with '" + c2 + "' to give");
            System.Console.WriteLine(paras.ToString());
            System.Console.WriteLine("");
        }
Пример #14
0
        public Chain standardizeApart(Chain chain,
                                      StandardizeApartIndexical standardizeApartIndexical)
        {
            List <Variable>             toRename           = variableCollector.collectAllVariables(chain);
            Dictionary <Variable, Term> renameSubstitution = new Dictionary <Variable, Term>();

            foreach (Variable var in toRename)
            {
                Variable v = null;
                do
                {
                    v = new Variable(standardizeApartIndexical.getPrefix()
                                     + standardizeApartIndexical.getNextIndex());
                    // Ensure the new variable name is not already
                    // accidentally used in the sentence
                } while (toRename.Contains(v));

                renameSubstitution.Add(var, v);
            }

            if (renameSubstitution.Count > 0)
            {
                List <Literal> lits = new List <Literal>();

                foreach (Literal l in chain.getLiterals())
                {
                    AtomicSentence atom = (AtomicSentence)substVisitor.subst(
                        renameSubstitution, l.getAtomicSentence());
                    lits.Add(l.newInstance(atom));
                }

                Chain renamed = new Chain(lits);

                renamed.setProofStep(new ProofStepRenaming(renamed, chain
                                                           .getProofStep()));

                return(renamed);
            }

            return(chain);
        }
Пример #15
0
        public void testSimpleExample()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addPredicate("P");
            domain.addPredicate("Q");
            domain.addPredicate("R");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            List <Literal> lits = new List <Literal>();
            AtomicSentence a1   = (AtomicSentence)parser.parse("P(F(x,B),x)");
            AtomicSentence a2   = (AtomicSentence)parser.parse("Q(x)");

            lits.Add(new Literal(a1));
            lits.Add(new Literal(a2));

            Clause c1 = new Clause(lits);

            lits.Clear();
            a1 = (AtomicSentence)parser.parse("F(A,y) = y");
            a2 = (AtomicSentence)parser.parse("R(y)");
            lits.Add(new Literal(a1));
            lits.Add(new Literal(a2));

            Clause c2 = new Clause(lits);

            List <Clause> paras = paramodulation.apply(c1, c2);

            Assert.AreEqual(2, paras.Count);

            foreach (Clause c in paras)
            {
                Assert.AreEqual("[P(B,A), Q(A), R(B)]", c.ToString());
                Assert.AreEqual("[P(F(A,F(x,B)),x), Q(x), R(F(x,B))]", c
                                .ToString());
            }
        }
Пример #16
0
        // Returns c if no cancellation occurred
        private Chain tryCancellation(Chain c)
        {
            Literal head = c.getHead();

            if (null != head && !(head is ReducedLiteral))
            {
                foreach (Literal l in c.getTail())
                {
                    if (l is ReducedLiteral)
                    {
                        // if they can be resolved
                        if (head.isNegativeLiteral() != l.isNegativeLiteral())
                        {
                            IMap <Variable, Term> subst = unifier
                                                          .unify(head.getAtomicSentence(),
                                                                 l.getAtomicSentence());
                            if (null != subst)
                            {
                                // I have a cancellation
                                // Need to apply subst to all of the
                                // literals in the cancellation
                                ICollection <Literal> cancLits = CollectionFactory.CreateQueue <Literal>();
                                foreach (Literal lfc in c.getTail())
                                {
                                    AtomicSentence a = (AtomicSentence)substVisitor
                                                       .subst(subst, lfc.getAtomicSentence());
                                    cancLits.Add(lfc.newInstance(a));
                                }
                                Chain cancellation = new Chain(cancLits);
                                cancellation
                                .setProofStep(new ProofStepChainCancellation(
                                                  cancellation, c, subst));
                                return(cancellation);
                            }
                        }
                    }
                }
            }
            return(c);
        }
Пример #17
0
        public void testSimpleExample()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addPredicate("P");
            domain.addPredicate("Q");
            domain.addPredicate("R");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            ICollection <Literal> lits = CollectionFactory.CreateQueue <Literal>();
            AtomicSentence        a1   = (AtomicSentence)parser.parse("P(F(x,B),x)");
            AtomicSentence        a2   = (AtomicSentence)parser.parse("Q(x)");

            lits.Add(new Literal(a1));
            lits.Add(new Literal(a2));

            Clause c1 = new Clause(lits);

            lits.Clear();
            a1 = (AtomicSentence)parser.parse("F(A,y) = y");
            a2 = (AtomicSentence)parser.parse("R(y)");
            lits.Add(new Literal(a1));
            lits.Add(new Literal(a2));

            Clause c2 = new Clause(lits);

            ISet <Clause> paras = paramodulation.apply(c1, c2);

            Assert.AreEqual(2, paras.Size());

            Assert.AreEqual("[P(B,A), Q(A), R(B)]", Util.first(paras).ToString());
            paras.Remove(Util.first(paras));
            Assert.AreEqual("[P(F(A,F(x,B)),x), Q(x), R(F(x,B))]", Util.first(paras).ToString());
        }
Пример #18
0
 public void addNegativeLiteral(AtomicSentence atom)
 {
     addLiteral(new Literal(atom, true));
 }
Пример #19
0
 public ReducedLiteral(AtomicSentence atom, bool negated) : base(atom, negated)
 {
    
 }
Пример #20
0
 public override Literal newInstance(AtomicSentence atom)
 {
     return(new ReducedLiteral(atom, isNegativeLiteral()));
 }
Пример #21
0
 public void addPositiveLiteral(AtomicSentence atom)
 {
     addLiteral(new Literal(atom));
 }
Пример #22
0
        public Chain attemptReduction(Chain nearParent, int farParentIndex)
        {
            Chain nnpc = null;

            Literal nearLiteral = nearParent.getHead();

            IMap <string, ICollection <Chain> > candidateHeads = null;

            if (nearLiteral.isPositiveLiteral())
            {
                candidateHeads = negHeads;
            }
            else
            {
                candidateHeads = posHeads;
            }

            AtomicSentence      nearAtom   = nearLiteral.getAtomicSentence();
            string              nearestKey = nearAtom.getSymbolicName();
            ICollection <Chain> farParents = candidateHeads.Get(nearestKey);

            if (null != farParents)
            {
                Chain farParent = farParents.Get(farParentIndex);
                standardizeApart(farParent);
                Literal               farLiteral = farParent.getHead();
                AtomicSentence        farAtom    = farLiteral.getAtomicSentence();
                IMap <Variable, Term> subst      = unifier.unify(nearAtom, farAtom);

                // If I was able to unify with one
                // of the far heads
                if (null != subst)
                {
                    // Want to always apply reduction uniformly
                    Chain   topChain = farParent;
                    Literal botLit   = nearLiteral;
                    Chain   botChain = nearParent;

                    // Need to apply subst to all of the
                    // literals in the reduction
                    ICollection <Literal> reduction = CollectionFactory.CreateQueue <Literal>();
                    foreach (Literal l in topChain.getTail())
                    {
                        AtomicSentence atom = (AtomicSentence)substVisitor.subst(
                            subst, l.getAtomicSentence());
                        reduction.Add(l.newInstance(atom));
                    }
                    reduction.Add(new ReducedLiteral((AtomicSentence)substVisitor
                                                     .subst(subst, botLit.getAtomicSentence()), botLit
                                                     .isNegativeLiteral()));
                    foreach (Literal l in botChain.getTail())
                    {
                        AtomicSentence atom = (AtomicSentence)substVisitor.subst(subst, l.getAtomicSentence());
                        reduction.Add(l.newInstance(atom));
                    }

                    nnpc = new Chain(reduction);
                    nnpc.setProofStep(new ProofStepChainReduction(nnpc, nearParent,
                                                                  farParent, subst));
                }
            }

            return(nnpc);
        }
Пример #23
0
 public ReducedLiteral(AtomicSentence atom, bool negated)
     : base(atom, negated)
 {
 }
Пример #24
0
 public Literal(AtomicSentence atom, bool negated)
 {
     this.atom       = atom;
     negativeLiteral = negated;
 }
Пример #25
0
        public void testMultipleTermEqualitiesInBothClausesExample()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addConstant("D");
            domain.addPredicate("P");
            domain.addPredicate("Q");
            domain.addPredicate("R");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            List <Literal> lits = new List <Literal>();
            AtomicSentence a1   = (AtomicSentence)parser.parse("F(C,x) = D");
            AtomicSentence a2   = (AtomicSentence)parser.parse("A = D");
            AtomicSentence a3   = (AtomicSentence)parser.parse("P(F(x,B),x)");
            AtomicSentence a4   = (AtomicSentence)parser.parse("Q(x)");
            AtomicSentence a5   = (AtomicSentence)parser.parse("R(C)");

            lits.Add(new Literal(a1));
            lits.Add(new Literal(a2));
            lits.Add(new Literal(a3));
            lits.Add(new Literal(a4));
            lits.Add(new Literal(a5));

            Clause c1 = new Clause(lits);

            lits.Clear();
            a1 = (AtomicSentence)parser.parse("F(A,y) = y");
            a2 = (AtomicSentence)parser.parse("F(B,y) = C");
            a3 = (AtomicSentence)parser.parse("R(y)");
            a4 = (AtomicSentence)parser.parse("R(A)");
            lits.Add(new Literal(a1));
            lits.Add(new Literal(a2));
            lits.Add(new Literal(a3));
            lits.Add(new Literal(a4));

            Clause c2 = new Clause(lits);

            List <Clause> paras = paramodulation.apply(c1, c2);

            Assert.AreEqual(5, paras.Count);

            List <Clause> .Enumerator it = paras.GetEnumerator();
            it.MoveNext();
            Assert
            .AreEqual(
                "[F(B,B) = C, F(C,A) = D, A = D, P(B,A), Q(A), R(A), R(B), R(C)]",
                it.Current.ToString());
            it.MoveNext();
            Assert
            .AreEqual(
                "[F(A,F(C,x)) = D, F(B,F(C,x)) = C, A = D, P(F(x,B),x), Q(x), R(F(C,x)), R(A), R(C)]",
                it.Current.ToString());
            it.MoveNext();
            Assert
            .AreEqual(
                "[F(A,B) = B, F(C,B) = D, A = D, P(C,B), Q(B), R(A), R(B), R(C)]",
                it.Current.ToString());
            it.MoveNext();
            Assert
            .AreEqual(
                "[F(F(B,y),x) = D, F(A,y) = y, A = D, P(F(x,B),x), Q(x), R(y), R(A), R(C)]",
                it.Current.ToString());
            it.MoveNext();
            Assert
            .AreEqual(
                "[F(B,y) = C, F(C,x) = D, F(D,y) = y, P(F(x,B),x), Q(x), R(y), R(A), R(C)]",
                it.Current.ToString());
        }
Пример #26
0
 public virtual Literal newInstance(AtomicSentence atom)
 {
     return new Literal(atom, negativeLiteral);
 }
Пример #27
0
 public override Literal newInstance(AtomicSentence atom)
 {
     return new ReducedLiteral(atom, isNegativeLiteral());
 }
Пример #28
0
 public Literal(AtomicSentence atom, bool negated)
 {
     this.atom = atom;
     this.negativeLiteral = negated;
 }
Пример #29
0
 public Literal(AtomicSentence atom)
 {
     this.atom = atom;
 }
Пример #30
0
        public void testAtomicSentenceFalseParse()
        {
            AtomicSentence sen = (AtomicSentence)parser.parse("faLse");

            Assert.AreEqual(typeof(FalseSentence), sen.GetType());
        }
Пример #31
0
 public ReducedLiteral(AtomicSentence atom): base(atom)
 {
     
 }
Пример #32
0
            public AtomicSentence replace(AtomicSentence expression,
                    Term toReplace, Term replaceWith)
            {
                this.toReplace = toReplace;
                this.replaceWith = replaceWith;

                return (AtomicSentence)expression.accept(this, null);
            }
Пример #33
0
 public Literal(AtomicSentence atom)
 {
     this.atom = atom;
 }
Пример #34
0
        public void testAtomicSentenceSymbolParse()
        {
            AtomicSentence sen = (AtomicSentence)parser.parse("AIMA");

            Assert.AreEqual(typeof(Symbol), sen.GetType());
        }
Пример #35
0
 public virtual Literal newInstance(AtomicSentence atom)
 {
     return(new Literal(atom, negativeLiteral));
 }
Пример #36
0
        public void testMultipleTermEqualitiesInBothClausesExample()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addConstant("D");
            domain.addPredicate("P");
            domain.addPredicate("Q");
            domain.addPredicate("R");
            domain.addFunction("F");

            FOLParser parser = new FOLParser(domain);

            ICollection <Literal> lits = CollectionFactory.CreateQueue <Literal>();
            AtomicSentence        a1   = (AtomicSentence)parser.parse("F(C,x) = D");
            AtomicSentence        a2   = (AtomicSentence)parser.parse("A = D");
            AtomicSentence        a3   = (AtomicSentence)parser.parse("P(F(x,B),x)");
            AtomicSentence        a4   = (AtomicSentence)parser.parse("Q(x)");
            AtomicSentence        a5   = (AtomicSentence)parser.parse("R(C)");

            lits.Add(new Literal(a1));
            lits.Add(new Literal(a2));
            lits.Add(new Literal(a3));
            lits.Add(new Literal(a4));
            lits.Add(new Literal(a5));

            Clause c1 = new Clause(lits);

            lits.Clear();
            a1 = (AtomicSentence)parser.parse("F(A,y) = y");
            a2 = (AtomicSentence)parser.parse("F(B,y) = C");
            a3 = (AtomicSentence)parser.parse("R(y)");
            a4 = (AtomicSentence)parser.parse("R(A)");
            lits.Add(new Literal(a1));
            lits.Add(new Literal(a2));
            lits.Add(new Literal(a3));
            lits.Add(new Literal(a4));

            Clause c2 = new Clause(lits);

            ISet <Clause> paras = paramodulation.apply(c1, c2);

            Assert.AreEqual(5, paras.Size());

            Assert.AreEqual(
                "[F(B,B) = C, F(C,A) = D, A = D, P(B,A), Q(A), R(A), R(B), R(C)]",
                Util.first(paras).ToString());
            paras.Remove(Util.first(paras));
            Assert.AreEqual(
                "[F(A,F(C,x)) = D, F(B,F(C,x)) = C, A = D, P(F(x,B),x), Q(x), R(F(C,x)), R(A), R(C)]",
                Util.first(paras).ToString());
            paras.Remove(Util.first(paras));
            Assert.AreEqual(
                "[F(A,B) = B, F(C,B) = D, A = D, P(C,B), Q(B), R(A), R(B), R(C)]",
                Util.first(paras).ToString());
            paras.Remove(Util.first(paras));
            Assert.AreEqual(
                "[F(F(B,y),x) = D, F(A,y) = y, A = D, P(F(x,B),x), Q(x), R(y), R(A), R(C)]",
                Util.first(paras).ToString());
            paras.Remove(Util.first(paras));
            Assert.AreEqual(
                "[F(B,y) = C, F(C,x) = D, F(D,y) = y, P(F(x,B),x), Q(x), R(y), R(A), R(C)]",
                Util.first(paras).ToString());
        }
Пример #37
0
        public List <Clause> apply(Clause c1, Clause c2, bool standardizeApart)
        {
            List <Clause> paraExpressions = new List <Clause>();

            for (int i = 0; i < 2; i++)
            {
                Clause topClause, equalityClause;
                if (i == 0)
                {
                    topClause      = c1;
                    equalityClause = c2;
                }
                else
                {
                    topClause      = c2;
                    equalityClause = c1;
                }

                foreach (Literal possEqLit in equalityClause.getLiterals())
                {
                    // Must be a positive term equality to be used
                    // for paramodulation.
                    if (possEqLit.isPositiveLiteral() &&
                        possEqLit.getAtomicSentence() is TermEquality)
                    {
                        TermEquality assertion = (TermEquality)possEqLit
                                                 .getAtomicSentence();

                        // Test matching for both sides of the equality
                        for (int x = 0; x < 2; x++)
                        {
                            Term toMatch, toReplaceWith;
                            if (x == 0)
                            {
                                toMatch       = assertion.getTerm1();
                                toReplaceWith = assertion.getTerm2();
                            }
                            else
                            {
                                toMatch       = assertion.getTerm2();
                                toReplaceWith = assertion.getTerm1();
                            }

                            foreach (Literal l1 in topClause.getLiterals())
                            {
                                IdentifyCandidateMatchingTerm icm = getMatchingSubstitution(
                                    toMatch, l1.getAtomicSentence());

                                if (null != icm)
                                {
                                    Term replaceWith = substVisitor.subst(icm
                                                                          .getMatchingSubstitution(),
                                                                          toReplaceWith);

                                    // Want to ignore reflexivity axiom situation,
                                    // i.e. x = x
                                    if (icm.getMatchingTerm().Equals(replaceWith))
                                    {
                                        continue;
                                    }

                                    ReplaceMatchingTerm rmt = new ReplaceMatchingTerm();

                                    AtomicSentence altExpression = rmt.replace(l1
                                                                               .getAtomicSentence(), icm
                                                                               .getMatchingTerm(), replaceWith);

                                    // I have an alternative, create a new clause
                                    // with the alternative and the substitution
                                    // applied to all the literals before returning
                                    List <Literal> newLits = new List <Literal>();
                                    foreach (Literal l2 in topClause.getLiterals())
                                    {
                                        if (l1.Equals(l2))
                                        {
                                            newLits
                                            .Add(l1
                                                 .newInstance((AtomicSentence)substVisitor
                                                              .subst(
                                                                  icm
                                                                  .getMatchingSubstitution(),
                                                                  altExpression)));
                                        }
                                        else
                                        {
                                            newLits
                                            .Add(substVisitor
                                                 .subst(
                                                     icm
                                                     .getMatchingSubstitution(),
                                                     l2));
                                        }
                                    }
                                    // Assign the equality clause literals,
                                    // excluding
                                    // the term equality used.
                                    foreach (Literal l2 in equalityClause.getLiterals())
                                    {
                                        if (possEqLit.Equals(l2))
                                        {
                                            continue;
                                        }
                                        newLits.Add(substVisitor.subst(icm
                                                                       .getMatchingSubstitution(), l2));
                                    }

                                    // Only apply paramodulation at most once
                                    // for each term equality.
                                    Clause nc = null;
                                    if (standardizeApart)
                                    {
                                        sApart.standardizeApart(newLits,
                                                                _emptyLiteralList, _saIndexical);
                                        nc = new Clause(newLits);
                                    }
                                    else
                                    {
                                        nc = new Clause(newLits);
                                    }
                                    nc
                                    .setProofStep(new ProofStepClauseParamodulation(
                                                      nc, topClause, equalityClause,
                                                      assertion));
                                    if (c1.isImmutable())
                                    {
                                        nc.setImmutable();
                                    }
                                    if (!c1.isStandardizedApartCheckRequired())
                                    {
                                        c1.setStandardizedApartCheckNotRequired();
                                    }
                                    paraExpressions.Add(nc);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return(paraExpressions);
        }
Пример #38
0
 public ReducedLiteral(AtomicSentence atom)
     : base(atom)
 {
 }