Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determining equality of symbolic expressions #39319

Open
2 tasks done
adasher opened this issue Jan 11, 2025 · 3 comments
Open
2 tasks done

Determining equality of symbolic expressions #39319

adasher opened this issue Jan 11, 2025 · 3 comments

Comments

@adasher
Copy link

adasher commented Jan 11, 2025

Steps To Reproduce

var('x, y, n')
assume(n,'integer')
assume(n >= 0)
bool((x-y)^n==(-1)^n*(y-x)^n)

Expected Behavior

Returns True.

Actual Behavior

Returns False.

Additional Information

https://ask.sagemath.org/question/80970/how-to-determine-equality-of-symbolic-expressions/

Environment

  • OS: Ubuntu 22.04
  • Sage Version: 9.5

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@orlitzky
Copy link
Contributor

There are two issues here:

  1. Calling bool() on symbolic equalities is a longstanding pain point in our user interface. There are three possible return values: True, False, and "I don't know." For compatibility with python (IIRC) we make sure to always return either True or False... but then what happens to "I don't know"? It gets turned in to False! So you never really know whether or not your equation was provably false, or just too hard to decide.
  2. Sage isn't smart enough to apply your assumptions to this equation, so it doesn't know, for example, that n isn't 1/2. It therefore cowardly refuses to simplify what might be a multi-valued square root to the single value that would make this equation true.

To work around the second problem, subtract the left-hand side of your equation from the right-hand side, and call canonicalize_radical() on the result. It should come out to zero.

@maxale
Copy link
Contributor

maxale commented Jan 16, 2025

@orlitzky: An equivalent comparison via ((x-y)^n - (-1)^n*(y-x)^n).is_zero() is not bound to always return True or False, and could tell us "Don't know" (say, in the form of an exception), but it still returns wrong False.

Related: #38586

@orlitzky
Copy link
Contributor

I don't think it would be too terrible to throw an exception in bool(). No one likes the existing behavior and I'm certainly not defending it; the main roadblock is how much work it would be to change it in a consistent way. A few people have started to work on it over the years but no one has made much progress, e.g.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants