private void make_DNF_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_DNF(); 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"; } }
public formula make_DNF() { formula dnf = new formula(); if (is_DNF) { dnf = this; } else if (top_operation is dis) { dnf = first_operand.make_DNF() | second_operand.make_DNF(); } else if (top_operation is kon) { //дистрибутивность справа: if (!second_operand.is_some_atom_exp && second_operand.top_operation is dis) { formula new_second = new formula(); if (!second_operand.is_DNF) { new_second = second_operand.make_DNF(); } else { new_second = second_operand; } dnf = (((first_operand.make_DNF() & new_second.first_operand.make_DNF())).make_DNF() | ((first_operand.make_DNF() & new_second.second_operand.make_DNF()))).make_DNF(); } else if (!second_operand.is_some_atom_exp && second_operand.top_operation is kon) { formula new_second = new formula(); if (!second_operand.is_DNF) { new_second = second_operand.make_DNF(); } dnf = (first_operand.make_DNF() & new_second).make_DNF(); } 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 dis) { formula new_first = new formula(); if (!first_operand.is_DNF) { new_first = first_operand.make_DNF(); } else { new_first = first_operand; } dnf = ((new_first.first_operand.make_DNF() & second_operand.make_DNF())).make_DNF() | ((new_first.second_operand.make_DNF() & second_operand.make_DNF())).make_DNF(); } else if (!first_operand.is_some_atom_exp && first_operand.top_operation is kon) { formula new_first = new formula(); if (!first_operand.is_DNF) { new_first = first_operand.make_DNF(); } dnf = (new_first.make_DNF() & second_operand.make_DNF()).make_DNF(); } else if (first_operand.is_some_atom_exp) { throw new Exception("Невозможно привести данное выражение к КНФ"); } } } return(dnf); }