Exemple #1
0
        /// <summary>
        /// Applies the Resolution technic.
        /// </summary>
        /// <param name="other">other disjunction to apply.</param>
        /// <returns>the resoluted disjunction if found</returns>
        public MultipleDisjunction ApplyResolution(MultipleDisjunction other)
        {
            List <Proposition> result = new List <Proposition>(m_props);

            result.AddRange(other.m_props);

            foreach (Proposition p in m_props)
            {
                foreach (Proposition q in other.m_props)
                {
                    if (p.Negated().Equals(q) || q.Negated().Equals(p))
                    {
                        result.Remove(p);
                        result.Remove(q);
                        MultipleDisjunction md = new MultipleDisjunction(result);
                        md.Simplify();
                        return(md);
                    }
                }
            }

            return(null); // A resolution wasn't found.
        }
Exemple #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);
        }