Beispiel #1
0
        private void calculateFactors(List <Clause> parentFactors)
        {
            nonTrivialFactors = new List <Clause>();

            Dictionary <Variable, Term> theta = new Dictionary <Variable, Term>();
            List <Literal> lits = new List <Literal>();

            for (int i = 0; i < 2; i++)
            {
                lits.Clear();
                if (i == 0)
                {
                    // Look at the positive literals
                    lits.AddRange(positiveLiterals);
                }
                else
                {
                    // Look at the negative literals
                    lits.AddRange(negativeLiterals);
                }
                for (int x = 0; x < lits.Count; x++)
                {
                    for (int y = x + 1; y < lits.Count; y++)
                    {
                        Literal litX = lits[x];
                        Literal litY = lits[y];

                        theta.Clear();
                        Dictionary <Variable, Term> substitution = _unifier.unify(litX
                                                                                  .getAtomicSentence(), litY.getAtomicSentence(),
                                                                                  theta);
                        if (null != substitution)
                        {
                            List <Literal> posLits = new List <Literal>();
                            List <Literal> negLits = new List <Literal>();
                            if (i == 0)
                            {
                                posLits
                                .Add(_substVisitor
                                     .subst(substitution, litX));
                            }
                            else
                            {
                                negLits
                                .Add(_substVisitor
                                     .subst(substitution, litX));
                            }
                            foreach (Literal pl in positiveLiterals)
                            {
                                if (pl == litX || pl == litY)
                                {
                                    continue;
                                }
                                posLits.Add(_substVisitor.subst(substitution, pl));
                            }
                            foreach (Literal nl in negativeLiterals)
                            {
                                if (nl == litX || nl == litY)
                                {
                                    continue;
                                }
                                negLits.Add(_substVisitor.subst(substitution, nl));
                            }
                            // Ensure the non trivial factor is standardized apart
                            _standardizeApart.standardizeApart(posLits, negLits,
                                                               _saIndexical);
                            Clause c = new Clause(posLits, negLits);
                            c.setProofStep(new ProofStepClauseFactor(c, this, null, null, null, null));
                            if (isImmutable())
                            {
                                c.setImmutable();
                            }
                            if (!isStandardizedApartCheckRequired())
                            {
                                c.setStandardizedApartCheckNotRequired();
                            }
                            if (null == parentFactors)
                            {
                                c.calculateFactors(nonTrivialFactors);
                                nonTrivialFactors.AddRange(c.getFactors());
                            }
                            else
                            {
                                if (!parentFactors.Contains(c))
                                {
                                    c.calculateFactors(nonTrivialFactors);
                                    nonTrivialFactors.AddRange(c.getFactors());
                                }
                            }
                        }
                    }
                }
            }

            factors = new List <Clause>();
            // Need to add self, even though a non-trivial
            // factor. See: slide 30
            // http://logic.stanford.edu/classes/cs157/2008/lectures/lecture10.pdf
            // for example of incompleteness when
            // trivial factor not included.
            factors.Add(this);
            factors.AddRange(nonTrivialFactors);
        }
Beispiel #2
0
        // Note: Applies binary resolution rule and factoring
        // Note: returns a set with an empty clause if both clauses
        // are empty, otherwise returns a set of binary resolvents.
        public List <Clause> binaryResolvents(Clause othC)
        {
            List <Clause> resolvents = new List <Clause>();

            // Resolving two empty clauses
            // gives you an empty clause
            if (isEmpty() && othC.isEmpty())
            {
                resolvents.Add(new Clause());
                return(resolvents);
            }

            // Ensure Standardized Apart
            // Before attempting binary resolution
            othC = saIfRequired(othC);

            List <Literal> allPosLits = new List <Literal>();
            List <Literal> allNegLits = new List <Literal>();

            allPosLits.AddRange(this.positiveLiterals);
            allPosLits.AddRange(othC.positiveLiterals);
            allNegLits.AddRange(this.negativeLiterals);
            allNegLits.AddRange(othC.negativeLiterals);

            List <Literal> trPosLits    = new List <Literal>();
            List <Literal> trNegLits    = new List <Literal>();
            List <Literal> copyRPosLits = new List <Literal>();
            List <Literal> copyRNegLits = new List <Literal>();

            for (int i = 0; i < 2; i++)
            {
                trPosLits.Clear();
                trNegLits.Clear();

                if (i == 0)
                {
                    // See if this clauses positives
                    // unify with the other clauses
                    // negatives
                    trPosLits.AddRange(this.positiveLiterals);
                    trNegLits.AddRange(othC.negativeLiterals);
                }
                else
                {
                    // Try the other way round now
                    trPosLits.AddRange(othC.positiveLiterals);
                    trNegLits.AddRange(this.negativeLiterals);
                }

                // Now check to see if they resolve
                Dictionary <Variable, Term> copyRBindings = new Dictionary <Variable, Term>();
                foreach (Literal pl in trPosLits)
                {
                    foreach (Literal nl in trNegLits)
                    {
                        copyRBindings.Clear();
                        if (null != _unifier.unify(pl.getAtomicSentence(), nl
                                                   .getAtomicSentence(), copyRBindings))
                        {
                            copyRPosLits.Clear();
                            copyRNegLits.Clear();
                            bool found = false;
                            foreach (Literal l in allPosLits)
                            {
                                if (!found && pl.Equals(l))
                                {
                                    found = true;
                                    continue;
                                }
                                copyRPosLits.Add(_substVisitor.subst(copyRBindings,
                                                                     l));
                            }
                            found = false;
                            foreach (Literal l in allNegLits)
                            {
                                if (!found && nl.Equals(l))
                                {
                                    found = true;
                                    continue;
                                }
                                copyRNegLits.Add(_substVisitor.subst(copyRBindings,
                                                                     l));
                            }
                            // Ensure the resolvents are standardized apart
                            Dictionary <Variable, Term> renameSubstitituon = _standardizeApart
                                                                             .standardizeApart(copyRPosLits, copyRNegLits,
                                                                                               _saIndexical);
                            Clause c = new Clause(copyRPosLits, copyRNegLits);
                            c.setProofStep(new ProofStepClauseBinaryResolvent(c,
                                                                              this, othC, copyRBindings, renameSubstitituon));
                            if (isImmutable())
                            {
                                c.setImmutable();
                            }
                            if (!isStandardizedApartCheckRequired())
                            {
                                c.setStandardizedApartCheckNotRequired();
                            }
                            resolvents.Add(c);
                        }
                    }
                }
            }
            return(resolvents);
        }