Esempio n. 1
0
        public IAtomicSentence Apply(TermEquality assertion,
                                     IAtomicSentence expression)
        {
            IAtomicSentence altExpression = null;

            IdentifyCandidateMatchingTerm icm = this.GetMatchingSubstitution(assertion
                                                                             .Term1, expression);

            if (null != icm)
            {
                ITerm replaceWith = substVisitor.Subst(
                    icm.GetMatchingSubstitution(), assertion.Term2);
                // 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);
        }
            public IAtomicSentence Replace(IAtomicSentence expression,
                                           ITerm toReplace, ITerm replaceWith)
            {
                this.toReplace   = toReplace;
                this.replaceWith = replaceWith;

                return((IAtomicSentence)expression.Accept(this, null));
            }
            public IdentifyCandidateMatchingTerm(ITerm toMatch,
                                                 IAtomicSentence expression, AbstractModulation p)
            {
                this.toMatch          = toMatch;
                this.toMatchVariables = p.variableCollector
                                        .CollectAllVariables(toMatch);
                this.parent = p;

                expression.Accept(this, null);
            }
        protected IdentifyCandidateMatchingTerm GetMatchingSubstitution(
            ITerm toMatch, IAtomicSentence expression)
        {
            IdentifyCandidateMatchingTerm icm = new IdentifyCandidateMatchingTerm(toMatch, expression, this);

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

            // indicates no match
            return(null);
        }
Esempio n. 5
0
        public Clause Apply(TermEquality assertion, Clause clExpression)
        {
            Clause altClExpression = null;

            foreach (Literal l1 in clExpression.GetLiterals())
            {
                IAtomicSentence altExpression = Apply(assertion, l1.AtomicSentence);
                if (null != altExpression)
                {
                    // I have an alternative, create a new clause
                    // with the alternative and return
                    IList <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.Immutable)
                    {
                        altClExpression.Immutable = true;
                    }
                    if (!clExpression.IsStandardizedApartCheckRequired())
                    {
                        altClExpression.SetStandardizedApartCheckNotRequired();
                    }
                    break;
                }
            }

            return(altClExpression);
        }
        // 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())
                        {
                            IDictionary <Variable, ITerm> subst = unifier.Unify(head
                                                                                .AtomicSentence, l.AtomicSentence);
                            if (null != subst)
                            {
                                // I have a cancellation
                                // Need to apply subst to all of the
                                // literals in the cancellation
                                IList <Literal> cancLits = new List <Literal>();
                                foreach (Literal lfc in c.GetTail())
                                {
                                    IAtomicSentence a = (IAtomicSentence)substVisitor
                                                        .Subst(subst, lfc.AtomicSentence);
                                    cancLits.Add(lfc.NewInstance(a));
                                }
                                Chain cancellation = new Chain(cancLits);
                                cancellation
                                .SetProofStep(new ProofStepChainCancellation(
                                                  cancellation, c, subst));
                                return(cancellation);
                            }
                        }
                    }
                }
            }
            return(c);
        }
Esempio n. 7
0
 public virtual Literal NewInstance(IAtomicSentence atomSentence)
 {
     return(new Literal(atomSentence, this.negativeLiteral));
 }
Esempio n. 8
0
 public Literal(IAtomicSentence atomicSentence, bool negated)
 {
     this.AtomicSentence  = atomicSentence;
     this.negativeLiteral = negated;
 }
Esempio n. 9
0
 public Literal(IAtomicSentence atomicSentence)
 {
     this.AtomicSentence = atomicSentence;
 }
Esempio n. 10
0
        public ISet <Clause> Apply(Clause c1, Clause c2, bool standardizeApart)
        {
            ISet <Clause> paraExpressions = new HashedSet <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.AtomicSentence is TermEquality)
                    {
                        var assertion = (TermEquality)possEqLit.AtomicSentence;

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

                            foreach (Literal l1 in topClause.GetLiterals())
                            {
                                var icm = GetMatchingSubstitution(
                                    toMatch, l1.AtomicSentence);

                                if (icm != null)
                                {
                                    ITerm replaceWith = substVisitor.Subst(
                                        icm.GetMatchingSubstitution(), toReplaceWith);

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

                                    var rmt = new ReplaceMatchingTerm();

                                    IAtomicSentence altExpression = rmt.Replace(l1.AtomicSentence,
                                                                                icm.GetMatchingTerm(), replaceWith);

                                    // I have an alternative, create a new clause
                                    // with the alternative and the substitution
                                    // applied to all the literals before returning
                                    var newLits = new List <Literal>();
                                    foreach (Literal l2 in topClause.GetLiterals())
                                    {
                                        if (l1.Equals(l2))
                                        {
                                            newLits.Add(l1.NewInstance((IAtomicSentence)substVisitor
                                                                       .Subst(icm.GetMatchingSubstitution(), altExpression)));
                                        }
                                        else
                                        {
                                            newLits.Add(substVisitor.Subst(icm.GetMatchingSubstitution(), l2));
                                        }
                                    }
                                    // Assign the equality clause literals,
                                    // excluding
                                    // the term equality used.
                                    newLits.AddRange(from l2 in equalityClause.GetLiterals()
                                                     where !possEqLit.Equals(l2)
                                                     select this.substVisitor.Subst(icm.GetMatchingSubstitution(), l2));

                                    // Only apply paramodulation at most once
                                    // for each term equality.
                                    Clause nc;
                                    if (standardizeApart)
                                    {
                                        sApart.GetStandardizeApartResult(newLits, _emptyLiteralList, _saIndexical);
                                        nc = new Clause(newLits);
                                    }
                                    else
                                    {
                                        nc = new Clause(newLits);
                                    }
                                    nc.SetProofStep(new ProofStepClauseParamodulation(nc, topClause, equalityClause, assertion));
                                    if (c1.Immutable)
                                    {
                                        nc.Immutable = true;
                                    }
                                    if (!c1.IsStandardizedApartCheckRequired())
                                    {
                                        c1.SetStandardizedApartCheckNotRequired();
                                    }
                                    paraExpressions.Add(nc);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(paraExpressions);
        }
Esempio n. 11
0
 public void AddNegativeLiteral(IAtomicSentence atom)
 {
     this.AddLiteral(new Literal(atom, true));
 }
Esempio n. 12
0
 public void AddPositiveLiteral(IAtomicSentence atom)
 {
     this.AddLiteral(new Literal(atom));
 }
Esempio n. 13
0
 public override Literal NewInstance(IAtomicSentence atom)
 {
     return(new ReducedLiteral(atom, IsNegativeLiteral()));
 }
Esempio n. 14
0
 public ReducedLiteral(IAtomicSentence atom, bool negated) : base(atom, negated)
 {
 }
Esempio n. 15
0
 public ReducedLiteral(IAtomicSentence atom) : base(atom)
 {
 }
        public Chain AttemptReduction(Chain nearParent, int farParentIndex)
        {
            Chain nnpc = null;

            Literal nearLiteral = nearParent.GetHead();

            IDictionary <string, IList <Chain> > candidateHeads = null;

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

            IAtomicSentence nearAtom   = nearLiteral.AtomicSentence;
            string          nearestKey = nearAtom.GetSymbolicName();
            IList <Chain>   farParents = candidateHeads[nearestKey];

            if (null != farParents)
            {
                Chain farParent = farParents[farParentIndex];
                StandardizeApart(farParent);
                Literal         farLiteral          = farParent.GetHead();
                IAtomicSentence farAtom             = farLiteral.AtomicSentence;
                IDictionary <Variable, ITerm> 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
                    IList <Literal> reduction = new List <Literal>();
                    foreach (Literal l in topChain.GetTail())
                    {
                        IAtomicSentence atom = (IAtomicSentence)substVisitor.Subst(
                            subst, l.AtomicSentence);
                        reduction.Add(l.NewInstance(atom));
                    }
                    reduction.Add(new ReducedLiteral((IAtomicSentence)substVisitor
                                                     .Subst(subst, botLit.AtomicSentence), botLit
                                                     .IsNegativeLiteral()));
                    foreach (Literal l in botChain.GetTail())
                    {
                        IAtomicSentence atom = (IAtomicSentence)substVisitor.Subst(
                            subst, l.AtomicSentence);
                        reduction.Add(l.NewInstance(atom));
                    }

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

            return(nnpc);
        }