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

            if (Expression_checkbox.Checked)
            {
                MessageBox.Show("Необходимо выражение ИППП", "Ошибка");
                richTextBox1.Text = "Введите сюда выражение ИППП";
            }
            else //if (Predicate_checkbox.Checked)
            {
                a = string_helper.Parser_Predicates(richTextBox1.Text); //Строим по строке формулу

                a = a.get_basic(); //приведем формулу к нормальному виду
                a = a.make_PNF();
                a = a.make_SSF();
                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";
                }
            }
        }
예제 #2
0
        public formula make_PNF()
        {
            if (this.is_PNF)
            {
                return(this);
            }

            formula pnf = new formula();



            if (top_operation is quantifier)
            {
                quantifier K1 = new quantifier((quantifier)top_operation);
                //bounded_variables.Add(K1.variable);
                pnf = first_operand.make_PNF();
                pnf.logical_exp.Insert(0, top_operation);
                return(pnf);
            }
            else
            {
                //1 правило вноса атомов под квантор
                if (top_operation is dis)
                {
                    if (first_operand.is_free_from_quntifiers && second_operand.is_free_from_quntifiers) //два атома => итак уже пнф
                    {
                        return(first_operand | second_operand);
                    }
                    else if (first_operand.is_free_from_quntifiers && second_operand.is_quantum_expression) //атом и кванторное выражение => записываем атом под квантор
                    {
                        pnf = first_operand | second_operand.first_operand.make_PNF();
                        pnf.logical_exp.Insert(0, second_operand.top_operation);
                        pnf = pnf.make_PNF();
                    }
                    else if (!first_operand.is_free_from_quntifiers && first_operand.top_operation is quantifier) //два кванторных выражения
                    {
                        string variable = get_bounded_variable(first_operand.top_operation);

                        if (second_operand.is_free_from(variable))
                        {
                            pnf = first_operand.first_operand.make_PNF() | second_operand.make_PNF();
                            pnf.logical_exp.Insert(0, first_operand.top_operation);
                            pnf = pnf.make_PNF();
                        }
                    }
                    else if (!second_operand.is_free_from_quntifiers && second_operand.top_operation is quantifier)
                    {
                        string variable = get_bounded_variable(second_operand.top_operation);

                        if (first_operand.is_free_from(variable))
                        {
                            pnf = first_operand.make_PNF() | second_operand.first_operand.make_PNF();
                            pnf.logical_exp.Insert(0, second_operand.top_operation);
                            pnf = pnf.make_PNF();
                        }
                    }
                }
                else if (top_operation is kon)
                {
                    if (first_operand.is_free_from_quntifiers && second_operand.is_free_from_quntifiers) //два атома => итак уже пнф
                    {
                        return(first_operand & second_operand);
                    }
                    else if (first_operand.is_free_from_quntifiers && second_operand.is_quantum_expression) //атом и кванторное выражение => записываем атом под квантор
                    {
                        pnf = first_operand & second_operand.first_operand.make_PNF();
                        pnf.logical_exp.Insert(0, second_operand.top_operation);
                        pnf = pnf.make_PNF();
                    }
                    else if (second_operand.is_free_from_quntifiers && first_operand.is_quantum_expression) //кванторное выражение и атом
                    {
                        pnf = first_operand.first_operand.make_PNF() & second_operand;
                        pnf.logical_exp.Insert(0, first_operand.top_operation);
                        pnf = pnf.make_PNF();
                    }
                    if (first_operand.is_quantum_expression && first_operand.top_operation is quantifier)
                    {
                        string variable = get_bounded_variable(first_operand.top_operation);
                        bounded_variables.Add(variable);

                        if (second_operand.is_free_from(variable))
                        {
                            pnf = first_operand.first_operand.make_PNF() & second_operand.make_PNF();
                            pnf.logical_exp.Insert(0, first_operand.top_operation);
                            pnf = pnf.make_PNF();
                        }
                    }
                    else if (second_operand.is_quantum_expression && second_operand.top_operation is quantifier)
                    {
                        string variable = get_bounded_variable(second_operand.top_operation);
                        //bounded_variables.Add(variable);

                        if (first_operand.is_free_from(variable))
                        {
                            pnf = first_operand.make_PNF() & second_operand.first_operand.make_PNF();
                            pnf.logical_exp.Insert(0, second_operand.top_operation);
                            pnf = pnf.make_PNF();
                        }
                    }
                }

                //2 - правила объединения кванторов
                //2.1 - всеобщность
                if (top_operation is kon)
                {
                    if (first_operand.is_quantum_expression && second_operand.is_quantum_expression)
                    {
                        if (first_operand.top_operation is quantifier && second_operand.top_operation is quantifier)
                        {
                            quantifier K1 = new quantifier((quantifier)first_operand.top_operation);
                            //bounded_variables.Add(K1.variable);
                            quantifier K2 = new quantifier((quantifier)second_operand.top_operation);

                            if (K1.is_universality && K2.is_universality && K1.variable == K2.variable)
                            {
                                pnf = first_operand.first_operand & second_operand.first_operand;
                                pnf.logical_exp.Insert(0, first_operand.top_operation);
                            }
                        }
                    }
                }
                //2.2 - существование
                if (top_operation is dis)
                {
                    if (first_operand.is_quantum_expression && second_operand.is_quantum_expression)
                    {
                        if (first_operand.top_operation is quantifier && second_operand.top_operation is quantifier)
                        {
                            quantifier K1 = new quantifier((quantifier)first_operand.top_operation);
                            //bounded_variables.Add(K1.variable);
                            quantifier K2 = new quantifier((quantifier)second_operand.top_operation);

                            if (K1.is_existance && K2.is_existance && K1.variable == K2.variable)
                            {
                                pnf = first_operand.first_operand | second_operand.first_operand;
                                pnf.logical_exp.Insert(0, first_operand.top_operation);
                            }
                        }
                    }
                }

                //3 - правило выноса квантора за скобки (с переименованием связанных переменных)
                if (top_operation is dis)
                {
                    if (first_operand.is_quantum_expression && second_operand.is_quantum_expression)
                    {
                        quantifier K1 = new quantifier((quantifier)first_operand.top_operation);
                        //bounded_variables.Add(K1.variable);
                        quantifier K2 = new quantifier((quantifier)second_operand.top_operation);

                        if (K1.variable == K2.variable && bounded_variables.Contains(K2.variable))
                        {
                            pnf         = first_operand.first_operand | second_operand.first_operand.rename_variable(K2.variable, K2.variable + "_renamed");
                            K2.variable = K2.variable + "1";
                            pnf.logical_exp.Insert(0, K2);
                            pnf.logical_exp.Insert(0, K1);
                        }
                        else if (!second_operand.is_free_from(K1.variable))
                        {
                            pnf = first_operand.first_operand | second_operand.first_operand.rename_variable(K1.variable, K1.variable + "_renamed");
                            pnf.logical_exp.Insert(0, K2);
                            pnf.logical_exp.Insert(0, K1);
                        }
                        else
                        {
                            pnf = first_operand.first_operand | second_operand.first_operand;
                            pnf.logical_exp.Insert(0, K2);
                            pnf.logical_exp.Insert(0, K1);
                        }
                    }
                }
                else if (top_operation is kon)
                {
                    if (first_operand.is_quantum_expression && second_operand.is_quantum_expression)
                    {
                        quantifier K1 = new quantifier((quantifier)first_operand.top_operation);
                        quantifier K2 = new quantifier((quantifier)second_operand.top_operation);

                        if (K1.variable == K2.variable)
                        {
                            pnf         = first_operand.first_operand & second_operand.first_operand.rename_variable(K2.variable, K2.variable + "_renamed");
                            K2.variable = K2.variable + "1";
                            pnf.logical_exp.Insert(0, K2);
                            pnf.logical_exp.Insert(0, K1);
                        }
                    }
                }



                return(pnf);
            }
        }