-
-
Notifications
You must be signed in to change notification settings - Fork 50
Description
Environment information
Any version of the ZX library.
Description
The arithmetic for PiExpressions in the ZX package seems to be quite buggy in certain aspects.
For example
const auto beta = zx::PiRational(1, 2);
std::cout << beta * 2 << "\n";
std::cout << beta * 2. << "\n";
const auto betaExpr = zx::PiExpression{beta};
std::cout << betaExpr * 2. << "\n";
// std::cout << betaExpr * 2 << "\n"; // does not compile due to missing overloadyields
1/1
1/1
159154943/500000000The last entry is completely unexpected.
So that's the one thing. This also means something like betaExpr / 2. will result in complete garbage.
Now, #482 adds support for divisions by integers (which allows to write the above as betaExpr / 2).
However, that revealed quite a problem in the way arithmetic expressions are handled.
Namely, that
const auto beta = zx::PiRational(-1, 2);
std::cout << (beta + beta) / 2 << "\n"; // and, if the above is fixed most likely also `(beta+beta)/2.` which currently returns garbageprints
1/2instead of the desired result of -1/2.
The reason for that is beta+beta evaluating to -1 which is 1 mod pi.
Expected behavior
I would expect division and multiplication by floating point numbers for PiExpression to work exactly as they do for PiRational.
Furthermore, I would expect moderately complex arithmetic expressions to produce the correct result.
How to Reproduce
Run the examples from above