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

comparison of symbolic functions #18259

Open
dkrenn opened this issue Apr 20, 2015 · 4 comments
Open

comparison of symbolic functions #18259

dkrenn opened this issue Apr 20, 2015 · 4 comments

Comments

@dkrenn
Copy link
Contributor

dkrenn commented Apr 20, 2015

We have the following strange (wrong) behavior:

sage: f(x) = 2*x
sage: bool(f == 2*x)
True

On the other hand we have

sage: f(x) = 2*x
sage: g(y) = 2*y
sage: bool(f == g)
False

CC: @rwst @videlec

Component: symbolics

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

@dkrenn dkrenn added this to the sage-6.7 milestone Apr 20, 2015
@dkrenn
Copy link
Contributor Author

dkrenn commented Apr 20, 2015

comment:1

This came up in #18092.

@nbruin
Copy link
Contributor

nbruin commented Apr 21, 2015

comment:2

This is a consequence of how coercion and comparison are implemented:

sage: var('y')
y
sage: f(x)=x*y
sage: A=x*y
sage: cSR=parent(f)
sage: cSR.coerce_map_from(SR)
Conversion map:
  From: Symbolic Ring
  To:   Callable function ring with arguments (x,)
sage: SR.coerce_map_from(cSR) is None
True

So, A coerces into the parent of f (and not the other way around): That means that for equality testing, A is coerced into the parent of f and then the comparison is done: comparison testing in sage is defined to be "equal up to coercion" (which probably necessarily breaks in all kinds of particular cases).

If you do not want these things to compare equal then you should break the coercion. That might be reasonable. Conversion can still exist. Currently you can do:

sage: f+y^2
x |--> x*y + y^2

without coercion but with conversion, this would need to be:

sage: f+cSR(y^2)
x |--> x*y + y^2

which does not seem unreasonable to me.

@videlec
Copy link
Contributor

videlec commented Apr 21, 2015

comment:3

Replying to @nbruin:
Hi Niles,

Why not modifying the comparison codes for Callable function ring?

If you do not want these things to compare equal then you should break the coercion. That might be reasonable. Conversion can still exist. Currently you can do:

sage: f+y^2
x |--> x*y + y^2

without coercion but with conversion, this would need to be:

sage: f+cSR(y^2)
x |--> x*y + y^2

which does not seem unreasonable to me.

I definitely would like to be able to do f+1 without an error!

Vincent

@nbruin
Copy link
Contributor

nbruin commented Apr 21, 2015

comment:4

Replying to @videlec:

Why not modifying the comparison codes for Callable function ring?

[...]

I definitely would like to be able to do f+1 without an error!

The second would probably still work if the integers still coerce into cSR (and since cSR inherits from SR it would be a lot of work to break that). But it's a direct consequence that if f+1 works then bool( cSR(1) == 1) will be true, basically because cSR(1)-1 is then 0 (instead of an error), which is what happens in the example in the ticket too.

If you're going to change the comparison for the callable function ring you'd be letting cSR behave completely different from other sage parents. It would also be a lot of work because currently comparison on cSR is just inherited from SR.

The implementation of comparison tests on SR only comes into play after the coercion framework has had its way with the arguments.

@mkoeppe mkoeppe removed this from the sage-6.7 milestone Dec 29, 2022
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