Esempio n. 1
0
        public static int SortOrder(this Negation f)
        {
            WFF i = f.inner;

            if (i is AtomicWFF)
            {
                return(0);
            }
            else if (i is Biconditional)
            {
                return(2);
            }
            else if (i is Conditional)
            {
                return(1);
            }
            else if (i is Conjunction)
            {
                return(((Conjunction)i).arity);
            }
            else if (i is Disjunction)
            {
                return(1);
            }
            else if (i is Negation)
            {
                return(1);
            }
            else if (i is Quantifier)
            {
                return(1);
            }

            throw new NotImplementedException(f.GetType().ToString());
        }
Esempio n. 2
0
        public static bool Decomposable(this Negation f)
        {
            WFF i = f.inner;

            if (i is AtomicWFF)
            {
                return(false);
            }
            else if (i is Biconditional)
            {
                return(true);
            }
            else if (i is Conditional)
            {
                return(true);
            }
            else if (i is Conjunction)
            {
                return(true);
            }
            else if (i is Disjunction)
            {
                return(true);
            }
            else if (i is Negation)
            {
                return(true);
            }
            else if (i is Quantifier)
            {
                return(true);
            }

            throw new NotImplementedException(f.GetType().ToString());
        }
Esempio n. 3
0
        public override Proof Find(WFF f)
        {
            Proof a = assumptions.Find(pl => { return(pl.line.Equals(f)); });

            if (a != null)
            {
                return(a);
            }

            foreach (Proof p in steps)
            {
                if (p is Subproof)
                {
                    continue;
                }

                a = p.Find(f);
                if (a != null)
                {
                    return(a);
                }
            }

            if (parent == null)
            {
                return(null);
            }

            return(parent.Find(f));
        }
Esempio n. 4
0
        public override Proof Find(WFF f)
        {
            if (line.Equals(f))
            {
                return(this);
            }

            return(null);
        }
Esempio n. 5
0
        public MainForm()
        {
            InitializeComponent();

            Icon = TruthTree2.Properties.Resources.Icon;

            WFF inn  = new Negation(new Predicate("A"));
            WFF tmp1 = new Negation(inn);
            WFF tmp2 = inn.GetNegation();

            Console.WriteLine("{0}\t{1}", tmp1, tmp2);
        }
Esempio n. 6
0
        public static bool Decomposable(this WFF f)
        {
            if (f is AtomicWFF)
            {
                return(Decomposable((AtomicWFF)f));
            }
            else if (f is ComplexWFF)
            {
                return(Decomposable((ComplexWFF)f));
            }

            throw new NotImplementedException(f.GetType().ToString());
        }
Esempio n. 7
0
        public static int SortOrder(this WFF f)
        {
            if (f is AtomicWFF)
            {
                return(SortOrder((AtomicWFF)f));
            }
            else if (f is ComplexWFF)
            {
                return(SortOrder((ComplexWFF)f));
            }

            throw new NotImplementedException(f.GetType().ToString());
        }
Esempio n. 8
0
        private List <WFF> IdentityDecompose(Identity i, WFF f)
        {
            if (f is AtomicWFF)
            {
                return(IdentityDecompose(i, (AtomicWFF)f));
            }
            else if (f is ComplexWFF)
            {
                return(IdentityDecompose(i, (ComplexWFF)f));
            }

            throw new NotImplementedException(f.GetType().ToString());
        }
Esempio n. 9
0
        private Decomposition DecomposeWFF(WFF f)
        {
            if (f is AtomicWFF)
            {
                return(DecomposeWFF((AtomicWFF)f));
            }
            else if (f is ComplexWFF)
            {
                return(DecomposeWFF((ComplexWFF)f));
            }

            throw new NotImplementedException(f.GetType().ToString());
        }
Esempio n. 10
0
        public Tree(List <WFF> s, Tree p = null, WFF d = null, bool rdup = true)
        {
            sentences  = new List <WFF>();
            parent     = p;
            decomposed = d;
            children   = null;

            if (parent == null)
            {
                sentences.AddRange(s);
                terms = new HashSet <Term>();
                foreach (WFF f in sentences)
                {
                    if (f == null)
                    {
                        continue;
                    }

                    terms.UnionWith(f.GetTerms());
                }
            }
            else
            {
                List <WFF> all = getAllSentences();
                foreach (WFF f in s)
                {
                    if (f == null)
                    {
                        continue;
                    }

                    if (rdup)
                    {
                        if (!all.Contains(f))
                        {
                            sentences.Add(f);
                            all.Add(f);
                        }
                    }
                    else
                    {
                        sentences.Add(f);
                    }
                }

                terms = new HashSet <Term>(parent.terms);
            }
        }
Esempio n. 11
0
        public bool Decompose()
        {
            checkForCompletion();
            if (State != TreeState.Incomplete)
            {
                return(false);
            }

            List <WFF> unsatisfied = getAllUnsatisfied();

            unsatisfied.Sort((a, b) => { return(a.SortOrder().CompareTo(b.SortOrder())); });
            if (unsatisfied.Count < 1)
            {
                throw new Exception("How did this even happen?");
            }

            for (int a = 0; a < unsatisfied.Count; a++)
            {
                Decomposition dec = DecomposeWFF(unsatisfied[a]);
                if (dec == null)
                {
                    continue;
                }

                children = dec.getTrees(this);
                if (children == null)
                {
                    continue;
                }

                decomposed = dec.decomposed;
                return(true);
            }

            return(false);
        }
Esempio n. 12
0
        internal static void AddTree(this Subproof p, Tree t)
        {
            if (t == null)
            {
                throw new ArgumentNullException();
            }
            if (t.State != TreeState.Closed)
            {
                throw new InvalidOperationException();
            }

            if (t.decomposed == null)
            {
                // Something got a contradiction here, find out what
                List <WFF> all = t.getAllSentences();
                WFF        c1  = null;
                WFF        c2  = null;
                for (int a = 0; a < all.Count; a++)
                {
                    if (all[a] is Negation)
                    {
                        Negation n = (Negation)all[a];
                        if (n.inner is Identity)
                        {
                            Identity i = (Identity)n.inner;
                            if (i.left.Equals(i.right))
                            {
                                c1 = all[a];
                                break;
                            }
                        }
                    }
                    else if (all[a] is Contradiction)
                    {
                        c1 = all[a];
                        break;
                    }

                    bool found = false;
                    for (int b = a + 1; b < all.Count; b++)
                    {
                        if (all[a].Equals(all[b].GetNegation()) || all[b].Equals(all[a].GetNegation()))
                        {
                            c1    = all[a];
                            c2    = all[b];
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        break;
                    }
                }

                Proof p1 = p.Find(c1);
                if (p1 == null)
                {
                    throw new InvalidOperationException("p1");
                }

                if (c2 == null)
                {
                    p.steps.Add(new ProofLine(new Contradiction(), Rule.ContradictionIntro, p1));
                }
                else
                {
                    Proof p2 = p.Find(c2);
                    if (p2 == null)
                    {
                        throw new InvalidOperationException("p2");
                    }

                    p.steps.Add(new ProofLine(new Contradiction(), Rule.ContradictionIntro, p1, p2));
                }

                return;
            }

            Proof d = p.Find(t.decomposed);

            if (t.decomposed is Biconditional)
            {
                // Add the steps for Equiv
                Biconditional b   = (Biconditional)t.decomposed;
                Disjunction   equ = new Disjunction(
                    new Conjunction(b.left, b.right),
                    new Conjunction(b.left.GetNegation(), b.right.GetNegation()));
                ProofLine equp = new ProofLine(equ, Rule.Equivalence, d);
                p.steps.Add(equp);

                ProofLine plleft = new ProofLine(equ.disjuncts[0], Rule.Assumption);
                Subproof  left   = new Subproof();
                left.parent = p;
                left.assumptions.Add(plleft);
                left.steps.Add(new ProofLine(b.left, Rule.AndElim, plleft));
                left.steps.Add(new ProofLine(b.right, Rule.AndElim, plleft));
                AddTree(left, t.children[0]);
                p.steps.Add(left);

                ProofLine plright = new ProofLine(equ.disjuncts[1], Rule.Assumption);
                Subproof  right   = new Subproof();
                right.parent = p;
                right.assumptions.Add(plright);
                right.steps.Add(new ProofLine(b.left.GetNegation(), Rule.AndElim, plright));
                right.steps.Add(new ProofLine(b.right.GetNegation(), Rule.AndElim, plright));
                AddTree(right, t.children[1]);
                p.steps.Add(right);

                p.steps.Add(new ProofLine(new Contradiction(), Rule.OrElim, equp, left, right));
            }
            else if (t.decomposed is Conditional)
            {
                // Add the steps for Impl
                Conditional c    = (Conditional)t.decomposed;
                Disjunction imp  = new Disjunction(c.antecedent.GetNegation(), c.consequent);
                ProofLine   impp = new ProofLine(imp, Rule.Implication, d);
                p.steps.Add(impp);

                Proof[] steps = new Proof[t.children.Length + 1];
                steps[0] = impp;
                for (int a = 0; a < t.children.Length; a++)
                {
                    steps[a + 1] = new Subproof();
                    Subproof s = (Subproof)steps[a + 1];
                    s.parent = p;
                    s.assumptions.Add(new ProofLine(t.children[a].sentences[0], Rule.Assumption));
                    AddTree(s, t.children[a]);
                    p.steps.Add(s);
                }
                p.steps.Add(new ProofLine(new Contradiction(), Rule.OrElim, steps));
            }
            else if (t.decomposed is Conjunction)
            {
                foreach (WFF f in t.children[0].sentences)
                {
                    p.steps.Add(new ProofLine(f, Rule.AndElim, d));
                }
                AddTree(p, t.children[0]);
            }
            else if (t.decomposed is Disjunction)
            {
                Proof[] steps = new Proof[t.children.Length + 1];
                steps[0] = d;
                for (int a = 0; a < t.children.Length; a++)
                {
                    steps[a + 1] = new Subproof();
                    Subproof s = (Subproof)steps[a + 1];
                    s.parent = p;
                    s.assumptions.Add(new ProofLine(t.children[a].sentences[0], Rule.Assumption));
                    AddTree(s, t.children[a]);
                    p.steps.Add(s);
                }
                p.steps.Add(new ProofLine(new Contradiction(), Rule.OrElim, steps));
            }
            else if (t.decomposed is Existential)
            {
                Subproof sub = new Subproof();
                sub.parent = p;
                sub.assumptions.Add(new ProofLine(t.children[0].sentences[0], Rule.Assumption));
                AddTree(sub, t.children[0]);
                p.steps.Add(sub);
                p.steps.Add(new ProofLine(new Contradiction(), Rule.ExistentialElim, d, sub));
            }
            else if (t.decomposed is Identity)
            {
                // Need to add some way to find the other source
                foreach (WFF f in t.children[0].sentences)
                {
                    p.steps.Add(new ProofLine(f, Rule.EqualsElim, d));
                }
                AddTree(p, t.children[0]);
            }
            else if (t.decomposed is Negation)
            {
                Negation n = (Negation)t.decomposed;
                if (n.inner is Biconditional)
                {
                    // I really hope there is a better way for this one
                    // Add the steps for DeM and Equiv
                    Biconditional b   = (Biconditional)n.inner;
                    ProofLine     equ = new ProofLine(new Negation(new Conjunction(new Disjunction(b.left.GetNegation(), b.right), new Disjunction(b.left, b.right.GetNegation()))), Rule.Equivalence, d);
                    p.steps.Add(equ);

                    ProofLine dem = new ProofLine(new Disjunction(new Negation(new Disjunction(b.left.GetNegation(), b.right)), new Negation(new Disjunction(b.left, b.right.GetNegation()))), Rule.DeMorgans, equ);
                    p.steps.Add(dem);

                    Subproof left = new Subproof();
                    left.parent = p;
                    ProofLine plleft = new ProofLine(new Negation(new Disjunction(b.left.GetNegation(), b.right)), Rule.Assumption);
                    left.assumptions.Add(plleft);
                    ProofLine demleft = new ProofLine(new Conjunction(b.left, b.right.GetNegation()), Rule.DeMorgans, plleft);
                    left.steps.Add(demleft);
                    left.steps.Add(new ProofLine(b.left, Rule.AndElim, demleft));
                    left.steps.Add(new ProofLine(b.right.GetNegation(), Rule.AndElim, demleft));
                    AddTree(left, t.children[1]);
                    p.steps.Add(left);

                    Subproof right = new Subproof();
                    right.parent = p;
                    ProofLine plright = new ProofLine(new Negation(new Disjunction(b.left, b.right.GetNegation())), Rule.Assumption);
                    right.assumptions.Add(plright);
                    ProofLine demright = new ProofLine(new Conjunction(b.left.GetNegation(), b.right), Rule.DeMorgans, plright);
                    right.steps.Add(demright);
                    right.steps.Add(new ProofLine(b.left.GetNegation(), Rule.AndElim, demright));
                    right.steps.Add(new ProofLine(b.right, Rule.AndElim, demright));
                    AddTree(right, t.children[0]);
                    p.steps.Add(right);

                    p.steps.Add(new ProofLine(new Contradiction(), Rule.OrElim, dem, left, right));
                }
                else if (n.inner is Conditional)
                {
                    // Add the steps for DeM and Impl
                    Conditional c   = (Conditional)n.inner;
                    ProofLine   imp = new ProofLine(new Negation(new Disjunction(c.antecedent.GetNegation(), c.consequent)), Rule.Implication, d);
                    p.steps.Add(imp);

                    ProofLine dem = new ProofLine(new Conjunction(c.antecedent, c.consequent.GetNegation()), Rule.DeMorgans, imp);
                    p.steps.Add(dem);

                    p.steps.Add(new ProofLine(c.antecedent, Rule.AndElim, dem));
                    p.steps.Add(new ProofLine(c.consequent.GetNegation(), Rule.AndElim, dem));

                    AddTree(p, t.children[0]);
                }
                else if (n.inner is Conjunction)
                {
                    // Add the steps for DeM
                    Conjunction i   = (Conjunction)n.inner;
                    List <WFF>  neg = new List <WFF>();
                    foreach (WFF f in i.conjuncts)
                    {
                        neg.Add(f.GetNegation());
                    }
                    Disjunction dem  = new Disjunction(neg.ToArray());
                    ProofLine   demp = new ProofLine(dem, Rule.DeMorgans, d);
                    p.steps.Add(demp);

                    Proof[] steps = new Proof[t.children.Length + 1];
                    steps[0] = demp;
                    for (int a = 0; a < t.children.Length; a++)
                    {
                        steps[a + 1] = new Subproof();
                        Subproof s = (Subproof)steps[a + 1];
                        s.parent = p;
                        s.assumptions.Add(new ProofLine(t.children[a].sentences[0], Rule.Assumption));
                        AddTree(s, t.children[a]);
                        p.steps.Add(s);
                    }
                    p.steps.Add(new ProofLine(new Contradiction(), Rule.OrElim, steps));
                }
                else if (n.inner is Disjunction)
                {
                    // Add the steps for DeM
                    Disjunction i   = (Disjunction)n.inner;
                    List <WFF>  neg = new List <WFF>();
                    foreach (WFF f in i.disjuncts)
                    {
                        neg.Add(f.GetNegation());
                    }
                    Conjunction dem = new Conjunction(neg.ToArray());

                    ProofLine demp = new ProofLine(dem, Rule.DeMorgans, d);
                    p.steps.Add(demp);

                    foreach (WFF f in t.children[0].sentences)
                    {
                        p.steps.Add(new ProofLine(f, Rule.AndElim, demp));
                    }
                    AddTree(p, t.children[0]);
                }
                else if (n.inner is Existential)
                {
                    // Add the steps for DeM
                    p.steps.Add(new ProofLine(t.children[0].sentences[0], Rule.DeMorgans, d));
                    AddTree(p, t.children[0]);
                }
                else if (n.inner is Negation)
                {
                    p.steps.Add(new ProofLine(t.children[0].sentences[0], Rule.NotElim, d));
                    AddTree(p, t.children[0]);
                }
                else if (n.inner is Universal)
                {
                    // Add the steps for DeM
                    p.steps.Add(new ProofLine(t.children[0].sentences[0], Rule.DeMorgans, d));
                    AddTree(p, t.children[0]);
                }
            }
            else if (t.decomposed is Universal)
            {
                foreach (WFF f in t.children[0].sentences)
                {
                    p.steps.Add(new ProofLine(f, Rule.UniversalElim, d));
                }
                AddTree(p, t.children[0]);
            }
        }
Esempio n. 13
0
 public Universal(Variable v, WFF s)
 {
     variable = v;
     scope    = s;
 }
Esempio n. 14
0
 public Existential(Variable v, WFF s)
 {
     variable = v;
     scope    = s;
 }
Esempio n. 15
0
 internal Decomposition(WFF d, params List <WFF>[] c)
 {
     decomposed    = d;
     decomposition = c;
 }
Esempio n. 16
0
 public ProofLine(WFF l, Rule r, params Proof[] s)
 {
     line    = l;
     rule    = r;
     reasons = new List <Proof>(s);
 }
Esempio n. 17
0
        private void bParse_Click(object sender, EventArgs e)
        {
            premises            = new List <WFF>();
            rtbPremisesOut.Text = "";
            foreach (string l in rtbPremisesIn.Text.Trim().Split('\n'))
            {
                if (l.Length < 1)
                {
                    continue;
                }

                WFF f = Parser.parseString(l.Trim());
                if (f != null)
                {
                    premises.Add(f);
                    rtbPremisesOut.AppendText(f + "\n");
                }
                else
                {
                    MessageBox.Show(string.Format("Error parsing premise {{{0}}}", l.Trim()));
                    rtbPremisesOut.Text = "";
                    return;
                }
            }

            conclusion = Parser.parseString(rtbConclusionIn.Text);
            if (conclusion == null)
            {
                MessageBox.Show(string.Format("Error parsing conclusion {{{0}}}", rtbConclusionIn.Text));
                rtbPremisesOut.Text = "";
                return;
            }
            rtbConclusionOut.Text = String.Format("{0}", conclusion);

            List <WFF> sentences = new List <WFF>(premises);

            sentences.Add(conclusion.GetNegation());

            worker = new Worker <Tree>(
                () =>
            {
                Tree t = new Tree(sentences);
                t.Satisfy();

                return(t);
            });
            worker.WorkFinished += workComplete;

            tree  = null;
            proof = null;

            setStatus("Initialized");

            setEnabled(bParse, true);
            setEnabled(bSatisfy, true);
            setEnabled(bStop, false);
            setEnabled(bShowTree, false);
            setEnabled(bShowProof, false);
            setEnabled(bSaveTree, false);
            setEnabled(bSaveProof, false);

            setTab(1);
        }
Esempio n. 18
0
 public abstract Proof Find(WFF f);