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

incorrect test for equality of vectors over SR #33697

Closed
DaveWitteMorris opened this issue Apr 12, 2022 · 8 comments
Closed

incorrect test for equality of vectors over SR #33697

DaveWitteMorris opened this issue Apr 12, 2022 · 8 comments

Comments

@DaveWitteMorris
Copy link
Member

As reported in this sage-devel thread, sage can report that two unequal vectors over the symbolic ring SR are equal:

sage: assume(x > 0)
sage: v = vector(SR, [x])
sage: w = vector(SR, [1])
sage: v == w
True

The problem comes from the fact that if lx != rx: is not the same as if not(lx == rx): when lx and rx are in SR. More precisely, for a symbolic relation such as f(x) == g(x), the docstring of sage.symbolic.expression.__bool__ says bool will return True if the relation is true for all possible values of x, and will return False otherwise. Therefore, it is often the case that bool(f(x) == g(x)) and bool(f(x) != g(x)) are both False.

sage: assume(x > 0)
sage: bool(x == 1)
False
sage: bool(x != 1)
False

The test for equality of vectors uses the comparison if lx != rx: on each component, but it should use if not(lx == rx):. What happens in the example is that there is a value of x for which x is equal to 1. This means that bool(x != 1) is False, so sagemath erroneously concludes that v == w should be true.

Related ticket: #33698. This bug does not arise without assume(x > 0), because inequality of symbolic relations does not follow the docstring's description when there are no assumptions.

Component: symbolics

Author: Dave Morris

Branch/Commit: d7d7bda

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/33697

@DaveWitteMorris
Copy link
Member Author

Branch: public/33697

@DaveWitteMorris

This comment has been minimized.

@DaveWitteMorris
Copy link
Member Author

comment:2

Changed milestone to 9.6, but perhaps should be 9.7 because 9.6 is in release-candidate stage (and perhaps the priority should not be "critical").


New commits:

d7d7bdatrac 33697: equality of SR vectors

@DaveWitteMorris
Copy link
Member Author

Commit: d7d7bda

@tscrim
Copy link
Collaborator

tscrim commented Apr 25, 2022

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Apr 25, 2022

comment:3

LGTM. I also agree on both points.

@DaveWitteMorris
Copy link
Member Author

comment:4

Thanks!

@vbraun
Copy link
Member

vbraun commented May 22, 2022

Changed branch from public/33697 to d7d7bda

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

3 participants