Пример #1
0
        // Note: see page 327.
        public StandardizeApartResult standardizeApart(Sentence aSentence,
                StandardizeApartIndexical standardizeApartIndexical)
        {
            List<Variable> toRename = variableCollector
                    .collectAllVariables(aSentence);
            Dictionary<Variable, Term> renameSubstitution = new Dictionary<Variable, Term>();
            Dictionary<Variable, Term> reverseSubstitution = 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);
                reverseSubstitution.Add(v, var);
            }

            Sentence standardized = substVisitor.subst(renameSubstitution,
                    aSentence);

            return new StandardizeApartResult(aSentence, standardized,
                    renameSubstitution, reverseSubstitution);
        }
Пример #2
0
        public Clause standardizeApart(Clause clause,
                StandardizeApartIndexical standardizeApartIndexical)
        {

            List<Variable> toRename = variableCollector.collectAllVariables(clause);
            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));

                if (renameSubstitution.ContainsKey(var))
                {
                    renameSubstitution[var] = v;
                }
                else
                {
                    renameSubstitution.Add(var, v);
                }
            }

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

                foreach (Literal l in clause.getLiterals())
                {
                    literals.Add(substVisitor.subst(renameSubstitution, l));
                }
                Clause renamed = new Clause(literals);
                renamed.setProofStep(new ProofStepRenaming(renamed, clause
                        .getProofStep()));
                return renamed;
            }

            return clause;
        }
Пример #3
0
        public object visitQuantifiedSentence(QuantifiedSentence sentence, object arg)
        {
            ISet <Variable> seenSoFar = (Set <Variable>)arg;

            // Keep track of what I have to subst locally and
            // what my renamed variables will be.
            IMap <Variable, Term>  localSubst    = CollectionFactory.CreateInsertionOrderedMap <Variable, Term>();
            ICollection <Variable> replVariables = CollectionFactory.CreateQueue <Variable>();

            foreach (Variable v in sentence.getVariables())
            {
                // If local variable has be renamed already
                // then I need to come up with own name
                if (seenSoFar.Contains(v))
                {
                    Variable sV = new Variable(quantifiedIndexical.getPrefix() + quantifiedIndexical.getNextIndex());
                    localSubst.Put(v, sV);
                    // Replacement variables should contain new name for variable
                    replVariables.Add(sV);
                }
                else
                {
                    // Not already replaced, this name is good
                    replVariables.Add(v);
                }
            }

            // Apply the local subst
            Sentence subst = substVisitor.subst(localSubst, sentence.getQuantified());

            // Ensure all my existing and replaced variable
            // names are tracked
            seenSoFar.AddAll(replVariables);

            Sentence sQuantified = (Sentence)subst.accept(this, arg);

            return(new QuantifiedSentence(sentence.getQuantifier(), replVariables, sQuantified));
        }
Пример #4
0
        public Chain standardizeApart(Chain chain, StandardizeApartIndexical standardizeApartIndexical)
        {
            ISet <Variable>       toRename           = variableCollector.collectAllVariables(chain);
            IMap <Variable, Term> renameSubstitution = CollectionFactory.CreateInsertionOrderedMap <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.Put(var, v);
            }

            if (renameSubstitution.Size() > 0)
            {
                ICollection <Literal> lits = CollectionFactory.CreateQueue <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);
        }
Пример #5
0
        // Note: see page 327.
        public StandardizeApartResult standardizeApart(Sentence sentence, StandardizeApartIndexical standardizeApartIndexical)
        {
            ISet <Variable>       toRename            = variableCollector.collectAllVariables(sentence);
            IMap <Variable, Term> renameSubstitution  = CollectionFactory.CreateInsertionOrderedMap <Variable, Term>();
            IMap <Variable, Term> reverseSubstitution = CollectionFactory.CreateInsertionOrderedMap <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.Put(var, v);
                reverseSubstitution.Put(v, var);
            }

            Sentence standardized = substVisitor.subst(renameSubstitution, sentence);

            return(new StandardizeApartResult(sentence, standardized, renameSubstitution, reverseSubstitution));
        }
Пример #6
0
        public Dictionary<Variable, Term> standardizeApart(List<Literal> l1Literals,
                List<Literal> l2Literals,
                StandardizeApartIndexical standardizeApartIndexical)
        {
            List<Variable> toRename = new List<Variable>();

            foreach (Literal pl in l1Literals)
            {
                toRename.AddRange(variableCollector.collectAllVariables(pl
                        .getAtomicSentence()));
            }
            foreach (Literal nl in l2Literals)
            {
                toRename.AddRange(variableCollector.collectAllVariables(nl
                        .getAtomicSentence()));
            }

            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));
                if (renameSubstitution.ContainsKey(var))
                {
                    renameSubstitution[var] = v;
                }
                else
                {
                    renameSubstitution.Add(var, v);
                }
            }

            List<Literal> posLits = new List<Literal>();
            List<Literal> negLits = new List<Literal>();

            foreach (Literal pl in l1Literals)
            {
                posLits.Add(substVisitor.subst(renameSubstitution, pl));
            }
            foreach (Literal nl in l2Literals)
            {
                negLits.Add(substVisitor.subst(renameSubstitution, nl));
            }

            l1Literals.Clear();
            l1Literals.AddRange(posLits);
            l2Literals.Clear();
            l2Literals.AddRange(negLits);

            return renameSubstitution;
        }
Пример #7
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;
        }