Beispiel #1
0
        public ATP(IEnumerable <CNFProposition> premisses, CNFProposition theorem = null)
        {
            this.Premisses = new Dictionary <string, CNFProposition>();
            foreach (CNFProposition premisse in premisses)
            {
                AddPremisse(premisse);
            }

            if (theorem != null)
            {
                this.Theorem = theorem;
            }
        }
Beispiel #2
0
        public bool ProveIt(ReportDelegate report)
        {
            // Negates the theorem.
            AST negated = CNF.Convert(Theorem.Ast.Negation());

            m_theoremNegation = new CNFProposition(negated);
            report(string.Format(
                       "Teorema: {0}\nTeorema negado: {1}\nTeorema negado em FNC: {2}\n",
                       CNF.Convert(Theorem.Ast).ToString(),
                       negated.ToString(),
                       m_theoremNegation.ToString()
                       ));

            // Join all premisses and sort them.
            List <MultipleDisjunction> clauses = new List <MultipleDisjunction>();

            foreach (CNFProposition premisse in Premisses.Values)
            {
                clauses.AddRange(premisse.Props);
            }
            clauses.AddRange(m_theoremNegation.Props);
            clauses.Sort();
            string premissesStr  = "Cláusulas (premissas + negação do teorema):";
            int    premisseCount = 0;

            foreach (MultipleDisjunction premisse in clauses)
            {
                premissesStr += string.Format("\n({0}) {1}", ++premisseCount, premisse);
            }
            report(premissesStr + "\n");

            // Evaluate Resolutions.
            report("\n=====================\nTentando provar...\n------------------\n\n");
            List <TestedPair> tested = new List <TestedPair>();
            bool solved = false;

            for (int i = 0; i < clauses.Count; i++)
            {
                for (int j = 0; j < clauses.Count; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    TestedPair pair = new TestedPair(i, j);
                    if (tested.Contains(pair))
                    {
                        continue;
                    }
                    else
                    {
                        tested.Add(pair);
                    }

                    MultipleDisjunction resolvent = clauses[i].ApplyResolution(clauses[j]);
                    if (resolvent == null)
                    {
                        continue;                    // complementaries not found.
                    }
                    solved = resolvent.ISNullClause;
                    if (solved)
                    {
                        report(string.Format(
                                   "Cláusula nula encontrada da aplicação de {0} em {1}.\n",
                                   j + 1, i + 1
                                   ));
                        break;
                    }
                    if (clauses.Contains(resolvent))
                    {
                        continue;
                    }
                    clauses.Add(resolvent);
                    report(string.Format(
                               "({0}) {1} :: De {2} em {3}.\n",
                               clauses.Count,
                               resolvent.ToString(),
                               j + 1, i + 1
                               ));
                    i = j = 0;
                }
                if (solved)
                {
                    break;
                }
            }

            report("\n\n==================\n");
            report(solved ? "TEOREMA PROVADO!" : "NÃO FOI POSSÍVEL PROVAR A TEORIA!");
            report("\n==================\n\n");

            return(solved);
        }
Beispiel #3
0
 public void AddPremisse(CNFProposition premisse)
 {
     this.Premisses.Add(premisse.Ast.ToString(), premisse);
     m_premisses.AddRange(premisse.Props);
 }