Example #1
0
        /// <summary>
        /// Extract the CNF formulas.
        /// </summary>
        /// <returns>An enumerable of formulas in CNF form.</returns>
        private void ExtractCNFs(TreeNode rootNode, ref List <MultipleDisjunction> data, bool andProve = false)
        {
            string expr = textBoxInput.Text;    // expression input.

            tabControl1.SelectedIndex = 2;

            // Creates a new analyzer for the expression.
            Analyzer asl = new Analyzer(expr);

            // Tokenization phase.
            if (!Tokenize(asl))
            {
                return;
            }
            // Parsing phase.
            AST            ast = CNF.Convert(asl.Parse());
            CNFProposition cnf = new CNFProposition(ast);
            string         fnc = ast.ToString();

            if (andProve)
            {
                atp.Theorem = cnf;
                bool           proved = atp.ProveIt(new ATP.ReportDelegate(Report));
                string         msg    = proved ? "TEOREMA PROVADO!" : "NÃO CONSEGUI PROVAR A TEORIA";
                MessageBoxIcon icon   = proved ? MessageBoxIcon.Asterisk : MessageBoxIcon.Warning;
                MessageBox.Show(msg, "Resultado", MessageBoxButtons.OK, icon);
            }
            else
            {
                atp.AddPremisse(cnf);
            }

            //IEnumerable<CnfOr> orClauses = CNF.Separate(ast, true);
            IEnumerable <MultipleDisjunction> orClauses = cnf.Props;

            // Add the formula to the node and data.
            data.AddRange(orClauses);
            foreach (var clause in orClauses)
            {
                TreeNode node = new TreeNode(clause.ToString());
                rootNode.Nodes.Add(node);
            }
            rootNode.ExpandAll();
        }
Example #2
0
        // Convert the formula to Conjunctive Normal Form.
        private void buttonFNC_Click(object sender, EventArgs e)
        {
            string expr = textBoxInput.Text;    // expression input.

            tabControl1.SelectedIndex = 1;

            // Creates a new analyzer for the expression.
            Analyzer asl = new Analyzer(expr);

            // Tokenization phase.
            if (!Tokenize(asl))
            {
                return;
            }
            // Parsing phase.
            AST            ast = CNF.Convert(asl.Parse());
            string         fnc = ASTFormat.Format(ast, ASTFormat.FormatType.PLAIN);
            CNFProposition cnf = new CNFProposition(ast);
            //IEnumerable<CnfOr> orClauses = CNF.Separate(ast, true);

            // Add this formula to the FNC list.
            RichTextTool rtt = new RichTextTool(ref richTextBoxCNF);

            rtt.AppendText(expr + " - ");
            richTextBoxCNF.SelectionBackColor = Color.Aquamarine;
            rtt.ToggleBold();
            rtt.AppendText(fnc);
            richTextBoxCNF.SelectionBackColor = Color.White;
            rtt.ToggleBold(); rtt.AppendText(" - "); rtt.ToggleBold();
            richTextBoxCNF.SelectionBackColor = Color.LawnGreen;
            rtt.AppendText(cnf.ToString());
            rtt.Eol();

            // Add the tree to the image.

            /*
             * if (m_treeFiller == null) m_treeFiller = new TreeFiller(pictureBoxTree);
             * m_treeFiller.Draw(ast);
             */
        }