#16127: Fix comparison of PARI objects
-------------------------------------+-------------------------------------
Reporter: pbruin | Owner:
Type: defect | Status: new
Priority: critical | Milestone: sage-6.4
Component: interfaces | Resolution:
Keywords: pari comparison | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/pbruin/16127-gcmp | 9f3f4ea5223abfcedd5aae984129d4f27f68e1d0
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Changes (by pbruin):
* cc: jdemeyer (added)
* priority: minor => critical
* branch: => u/pbruin/16127-gcmp
* commit: => 9f3f4ea5223abfcedd5aae984129d4f27f68e1d0
Old description:
> The following PARI series and ''p''-adics are incorrectly considered to
> be non-zero by `==` and `!=`:
> {{{
> sage: a = pari('O(x)'); a, a.type()
> (O(x), 't_SER')
> sage: b = pari('O(2)'); b, b.type()
> (O(2), 't_PADIC')
> sage: a.gequal(0)
> True
> sage: b.gequal(0)
> True
> sage: a == 0
> False # should be True
> sage: b == 0
> False # should be True
> }}}
> This is due to `__cmp__()` calling the function `gcmp_sage()` in
> `sage/libs/pari/misc.h` (custom replacement for PARI's `gcmp()`), which
> uses string comparison for non-real types. The `gen` type does not
> implement `__eq__()`, `__lt__()` etc.; we either have to implement these,
> or we have to extend `gcmp_sage()` to use `gequal()` before resorting to
> string comparison.
New description:
Comparison of PARI rationals is seriously broken:
{{{
sage: pari(1/2) < pari(1/3)
True
sage: pari(1) < pari(1/2)
True
}}}
Furthermore,the following PARI series and ''p''-adics are incorrectly
considered to be non-zero by `==` and `!=`:
{{{
sage: a = pari('O(x)'); a, a.type()
(O(x), 't_SER')
sage: b = pari('O(2)'); b, b.type()
(O(2), 't_PADIC')
sage: a.gequal(0)
True
sage: b.gequal(0)
True
sage: a == 0
False # should be True
sage: b == 0
False # should be True
}}}
These bugs are caused by `__cmp__()` calling the function `gcmp_sage()` in
`sage/libs/pari/misc.h` (custom replacement for PARI's `gcmp()`), which
uses string comparison for all types other than `t_INT` and `t_REAL`.
A possible solution is to implement `gen._richcmp_c_impl()` and to fix
`gen._cmp_c_impl()` to use the standard PARI `gcmp()` instead of
`gcmp_sage()`. This requires catching PARI "forbidden comparison" errors.
There is actually a non-negligible speed-up if no such error occurs, but a
substantial penalty if an error does occur.
--
Comment:
The attached branch is just a first attempt; it needs documentation, and
we have to time some important comparisons and make sure that there is no
significant speed penalty in realistic use scenarios.
--
Ticket URL: <http://trac.sagemath.org/ticket/16127#comment:3>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.