What is the best (in terms of simplicity of use and performance) C++/C++11 library which can simplify formulas like the following?
(a < 0 && b > 0) || (a < 0 && c > 0) || (a < 0 && c > 1)
to (e.g.)
a < 0 && (b > 0 || c > 0)
I think it is very important to explain one thing (because I see this question is misunderstood).
I do not want to simplify C / C++ expressions - I know, the compiler can make it.
I'm making a graph processing tool. On the edges of the graph, there are some conditions about its vertices (lets say the vertices are a
, b
, c
and these conditions are like a<b
, b>0
etc - Please note, that these conditions are not expressed as "strings", they can be any function or library call). During processing, I'm collecting the expressions together and before further graph processing I want to simplify them.
The conditions and expressions will be created during runtime.
I want to be able to input some expressions to that library, like:
[...]
a = new Variable();
b = new Variable();
expr1 = lib.addExpr(a,0, lib.LESS);
expr2 = lib.addExpr(b,0, lib.MORE);
expr3 = lib.addExpr(expr1, expr2, lib.AND);
[...]
cout << lib.solve(exprn).getConditionsOf(a);
Of course this library will probably have a lot more beautiful API. I have written it as method calls only to show what I expect to be the underlying mechanism - to emphasize, that I do not need a source to source compiler or that this question is not related to source compilation optimization.
(x<y)||(y<1)
. This is notthe point of this question. We are looking for a solution, which will simplify expressions because we NEED the simplified form as an input to our algorithm – Tetratomic