coercion of objects embedded in symbolic expressions

67 views
Skip to first unread message

Ralf Stephan

unread,
Feb 22, 2015, 5:02:44 AM2/22/15
to sage-...@googlegroups.com
Hello,
a long standing issue is
sage: bool(pi<Infinity)
False
sage: bool(SR(3)<Infinity) 
False
at which I'm having a naive stab (because it interferes with #14801).
Maybe I can learn something?

In the ticket the problem has been said having to do with Pynac,
but I don't think so. It would all work nicely if, instead of the expression
object, its underlying `pyobject` would be compared. But this does not
happen because there is no coerce map from `SR` to `InfinityRing`.

So, can we somehow have an indirect coercion map that uses not
the parent but the parent of something a member function (like `pyobject`)
returns? The problem of SR having no canonical map to anything
in spite of some expressions being well behaved is the source of
much frustration.

Regards,

Eric Gourgoulhon

unread,
Feb 22, 2015, 5:21:46 AM2/22/15
to sage-...@googlegroups.com
Hi,

Just to tell that no later than two days ago, I had a bug in my code that was caused by
bool(SR(0) < Infinity) returning False.
I was about to post a message to sage-devel, but thanks to your post, I realize this is a known issue.

Best wishes,

Eric.

Volker Braun

unread,
Feb 22, 2015, 6:17:13 AM2/22/15
to sage-...@googlegroups.com, Burcin Erocal
Just to tell you what you already know, the symbolic ring is the parent of last resort if there is nothing more specific. So its to be expected that you don't have any canonical maps elsewhere.

Pynac should probably unwind the comparison of two wrapped (non-symbolic) python objects to the comparison of the underlying python objects. Haven't tried that, though. You have to be careful about infinite recursions, the comparison might again coerce into the symbolic ring.

Burcin Erocal

unread,
Feb 22, 2015, 7:03:54 AM2/22/15
to Volker Braun, sage-...@googlegroups.com
On Sun, 22 Feb 2015 03:17:13 -0800 (PST)
Volker Braun <vbrau...@gmail.com> wrote:

> Just to tell you what you already know, the symbolic ring is the
> parent of last resort if there is nothing more specific. So its to be
> expected that you don't have any canonical maps elsewhere.
>
> Pynac should probably unwind the comparison of two wrapped
> (non-symbolic) python objects to the comparison of the underlying
> python objects. Haven't tried that, though. You have to be careful
> about infinite recursions, the comparison might again coerce into the
> symbolic ring.

Pynac already calls the Python comparison function if both are
pyobjects. In this case, infinity and constants are not pyobjects. They
are a basic class as in mul, add, symbol, etc.

Cheers,
Burcin

P.S. The infinity class was added to pynac by Volker. :)

Ralf Stephan

unread,
Feb 23, 2015, 3:43:36 AM2/23/15
to sage-...@googlegroups.com, vbrau...@gmail.com
On Sunday, February 22, 2015 at 1:03:54 PM UTC+1, Burcin Erocal wrote:
Pynac already calls the Python comparison function if both are
pyobjects. In this case, infinity and constants are not pyobjects. They
are a basic class as in mul, add, symbol, etc.
The code need not be fast so my solution is in Python and utilizes
the InfinityRing.

 
Reply all
Reply to author
Forward
0 new messages