HerpDerpington
HerpDerpington

Reputation: 4453

Does sympy give erroneous simplifications?

I have the following calculation for sympy:

import sympy

q, r = sympy.symbols("q r")
equation = (((-q + r) - (q - r)) <= 0).simplify()
print(equation) # q >= r

equation = ((sympy.sqrt(2) * (-q + r) - sympy.sqrt(2) * (q - r)) <= 0).simplify()
print(equation) # q <= r

I don't see why the results should differ. What am I missing?

Edit

I am using version 1.5.1 of sympy and can see this on Python 3.6.6 and 3.7.7.

Upvotes: 2

Views: 64

Answers (1)

smichr
smichr

Reputation: 19047

A fix for this is given here. It looks like gcd was assumed to behave like igcd (which gives a nonnegative value). But when dealing with non-integers, gcd currently can give a negative result, thus the error. So SymPy will either modify gcd and the simplify code will work or the simplification routine must account for the sign of the extracted gcd.

Upvotes: 1

Related Questions