Ask Your Question
1

symbolic ring comparisons return strange results

asked 7 years ago

DrNick gravatar image

Greetings,

bool(abs(-1+sqrt(2)) != abs(1-sqrt(2)))

erroneously returns True (I'm running SageMath-8.0 on a mac laptop, for what it's worth).

Is this a bug?

Thanks

Preview: (hide)

Comments

it looks like a bug to me, and also why it does this:

sage: x = SR.var('x')
sage: bool(abs(1-x) == abs(x-1))
True
sage: bool(abs(1-x) != abs(x-1))
True
mforets gravatar imagemforets ( 7 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 7 years ago

dan_fulea gravatar image

In order to establish if two expressions are equal, sage performs a "default wash machine program" and in case there is a proof for the True value, it returns this True. Else it returns False.

In such cases, one should help sage to find the truth.

In our case:

sage: expression = abs(-1+sqrt(2)) != abs(1-sqrt(2))
sage: bool(expression)
True
sage: bool(expression.simplify_full())
False

Just tell sage to perfom a simplification of the expression!

Note: One can find many "bugs" like the posted one, just try for instance:

sage: bool( abs(-1+sqrt(2)) != abs(1-sqrt(2)) )
True
sage: bool( abs(-1+sqrt(2)) == abs(1-sqrt(2)) )
True
Preview: (hide)
link

Comments

1

Yeah, I sort of understood the issue of returning False in case it can't really verify truth. But this is returning True when the statement is in fact False.

DrNick gravatar imageDrNick ( 7 years ago )

Most probably this is because a != b is first converted to not (a == b) before evaluation.

eric_g gravatar imageeric_g ( 7 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 7 years ago

Seen: 297 times

Last updated: Oct 04 '17