Beispiel #1
0
        public NaiveResolvent(Clause clause1, Term term1, Clause clause2, Term term2)
        {
            Clause1 = (Clause)clause1.Clone();
            Term1 = (Term)term1.Clone();
            Clause2 = (Clause)clause2.Clone();
            Term2 = (Term)term2.Clone();

            var atoms = new List<Term>();
            atoms.AddRange(clause1.Terms);
            atoms.AddRange(clause2.Terms);

            foreach (var term in atoms.Snapshot())
            {
                if (term.Equals(term1) || term.Counters(term1))
                {
                    atoms.Remove(term);
                }
            }

            Terms = atoms;
            EliminateDuplicateAtoms();

            // This is bullshit, since resolvents should be able to participate
            // in solving process later on.
//            Terms = new List<Term>(Terms).AsReadOnly();
        }
Beispiel #2
0
        public override void Visit(TermNode node)
        {
            Term term;
            IAstTreeNode clauseRoot;

            if (node.Parent is NegationNode)
            {
                term = new Term(node, false);
                clauseRoot = node.Parent.Parent;
            }
            else if (node.Parent is OrNode || node.Parent is L1Expression)
            {
                term = new Term(node, true);
                clauseRoot = node.Parent;
            }
            else if (node.Parent is AndNode)
            {
                term = new Term(node, true);
                clauseRoot = node;
            }
            else
            {
                throw new NotSupportedException(String.Format(
                    "Not a CNF or fatal error: '{0}", node.Parent));
            }

            if (!_clauses.ContainsKey(clauseRoot)) _clauses[clauseRoot] = new Clause();
            _clauses[clauseRoot].Terms.Add(term);
        }
Beispiel #3
0
        // v 0.55
        // Post L0-release. It appears that two clauses can happen to have more than 1 resolvent.
        // What a retard I am because of not thinking of this before :O

        // v 0.57
        // Actually there occurred a lucky shizzle. Back then I wondered whether I should just remove
        // useless calculations of resolvent for equal clauses. Well, actually if you take into account
        // previous comment, you'll see that same two clauses can have an existing resolvent (!), e.g.
        // clause [p(x), ~p(c)] has two unifiable atoms and after an xform of [x => c], there exists
        // a self+self resolvent (so-called "glued clause").

        public static IEnumerable<NaiveResolvent> NaiveResolvents(Clause clause1, Clause clause2)
        {
            // TODO. Snapshots here are absolutely unnecessary
            // TODO. Remove this shitfix asap

            foreach (var sourceTerm1 in clause1.Terms.Snapshot())
            {
                foreach (var sourceTerm2 in clause2.Terms.Snapshot())
                {
                    var gcu = Unifier.NaiveUnifier(sourceTerm1, sourceTerm2).ToXformClause();

                    if (gcu != null)
                    {
                        var uclause1 = gcu(clause1);
                        var uclause2 = gcu(clause2);

                        foreach (var uterm1 in uclause1.Terms)
                        {
                            foreach (var uterm2 in uclause2.Terms)
                            {
                                if (uterm2.Counters(uterm1))
                                {
                                    yield return new NaiveResolvent(
                                        uclause1, uterm1, uclause2, uterm2);
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
 public object Clone()
 {
     var clone = new Clause();
     Terms.ForEach(term => clone.Terms.Add((Term)term.Clone()));
     return clone;
 }