Ask Your Question
1

symbolic ring comparisons return strange results

asked 2017-10-04 16:34:08 +0200

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

edit retag flag offensive close merge delete

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 ( 2017-10-06 05:41:00 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-10-04 19:54:07 +0200

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
edit flag offensive delete link more

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 ( 2017-10-04 22:29:16 +0200 )edit

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

eric_g gravatar imageeric_g ( 2017-10-07 11:19:26 +0200 )edit

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: 2017-10-04 16:34:08 +0200

Seen: 221 times

Last updated: Oct 04 '17