New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cnf() reorders the variables #10
Comments
Hi, final FormulaFactory f = new FormulaFactory();
final Formula or1 = f.or(f.variable("x"), f.variable("y"));
final Formula or2 = f.or(f.variable("y"), f.variable("x"));
System.out.println(or1); // x | y
System.out.println(or2); // x | y
System.out.println(or1 == or2); // true The second formula Btw. LogicNG even applies some simplifications like absorption, removal of duplicate operands, and some more, when formulas when they are created. For example System.out.println(f.or(f.variable("x"), f.variable("x"), f.falsum())); // x Hope this helps a bit to understand the way LogicNG works. ;) |
If I have more than 2 variables and create a "big conjunctive normal form" the variables in every single clause could have different orderings? And if I'm using Java |
Yes.
If you mean "logical identical" as in syntactically identical, then yes.
If you mean semantically equivalent, then the answer might be false. You would need to call the solver for that question. |
The That means, that formulas like "A & B" and "B & A & A" are considered equals. But it is not a full semantical equivalence check. Like @d-bischoff said: therefore you would have to call a SAT solver. The formula factory in LogicNG is there to minimize heap consumption. Therefore, formulas are not created twice, if they are equal. Therefore if you create a formula "A & B" and afterwards you create a formula "B & A" with the same factory, the second one is not generated again, but the first one is returned. |
So this is only a problem of the Formula#toString() method for easier readability? |
The described phenomenon is not only a property of Formula#toString(). Internally the variables are also re-sorted if you will. However this is not important in any case since the formulas are semantically equivalent. So I don't view this as a problem at all. |
LogicFormula#booleanFunction2Expr() to ensure a canonical form in Symja. See: logic-ng/LogicNG#10
In this JUnit test case the
cnf()
method reorders the variables and the JUnit test fails:See: Symja JUnit tests
The text was updated successfully, but these errors were encountered: