private void button9_Click(object sender, EventArgs e)
        {
            formula a = new formula();

            if (Expression_checkbox.Checked)
            {
                a = string_helper.Parser_Expressions(richTextBox1.Text); //Строим по строке формулу
            }
            else //if (Predicate_checkbox.Checked)
            {
                a = string_helper.Parser_Predicates(richTextBox1.Text); //Строим по строке формулу
            }
            a = a.get_basic();                                          //приведем формулу к нормальному виду
            a = a.make_KNF();
            richTextBox1.Text = a.ToString();                           //выводим ее назад
            if (a.is_DNF)
            {
                formula_is_DNF.Text = "true";
            }
            else
            {
                formula_is_DNF.Text = "false";
            }
            if (a.is_KNF)
            {
                formula_is_KNF.Text = "true";
            }
            else
            {
                formula_is_KNF.Text = "false";
            }
        }
Exemple #2
0
        public formula make_KNF()
        {
            formula knf = new formula();

            if (is_KNF)
            {
                knf = this;
            }
            else if (top_operation is kon)
            {
                knf = first_operand.make_KNF() & second_operand.make_KNF();
            }
            else if (top_operation is dis)
            {
                //дистрибутивность справа:
                if (!second_operand.is_some_atom_exp && second_operand.top_operation is kon)
                {
                    formula new_second = new formula();
                    if (!second_operand.is_KNF)
                    {
                        new_second = second_operand.make_KNF();
                    }
                    else
                    {
                        new_second = second_operand;
                    }

                    knf = (((first_operand.make_KNF() | new_second.first_operand.make_KNF())).make_KNF() & ((first_operand.make_KNF() | new_second.second_operand.make_KNF()))).make_KNF();
                }
                else if (!second_operand.is_some_atom_exp && second_operand.top_operation is dis)
                {
                    formula new_second = new formula();
                    if (!second_operand.is_KNF)
                    {
                        new_second = second_operand.make_KNF();
                    }
                    knf = (first_operand.make_KNF() | new_second).make_KNF();
                }
                else if (second_operand.is_some_atom_exp || second_operand.top_operation is quantifier)
                {
                    //дистрибутивность слева:
                    if (!first_operand.is_some_atom_exp && first_operand.top_operation is kon)
                    {
                        formula new_first = new formula();
                        if (!first_operand.is_KNF)
                        {
                            new_first = first_operand.make_KNF();
                        }
                        else
                        {
                            new_first = first_operand;
                        }

                        knf = ((new_first.first_operand.make_KNF() | second_operand.make_KNF())).make_KNF() & ((new_first.second_operand.make_KNF() | second_operand.make_KNF())).make_KNF();
                    }
                    else if (!first_operand.is_some_atom_exp && first_operand.top_operation is dis)
                    {
                        formula new_first = new formula();
                        if (!first_operand.is_KNF)
                        {
                            new_first = first_operand.make_KNF();
                        }
                        knf = (new_first.make_KNF() | second_operand.make_KNF()).make_KNF();
                    }
                    else if (first_operand.is_some_atom_exp)
                    {
                        throw new Exception("Невозможно привести данное выражение к КНФ");
                    }
                }
            }

            return(knf);
        }