sagemath/sage

sage_input is unreliable for elements of ComplexField

Closed this issue · 4 comments

sage: fld = ComplexField(200)
sage: a = fld('0.85425665148473689034386458431097348561089439860408577398333', '20')
sage: sage_input(a, verify=True)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
...
AssertionError: Expected 0.85425665148473689034386458431097348561089439860408577398333 + 20.000000000000000000000000000000000000000000000000000000000*I == 0.85425665148473689034386458431097348561089439860408577398333 + 20.000000000000000000000000000000000000000000000000000000000*I

Apparently, the last bits that are usually not printed get lost.

sage: b = sage_eval(sage_input(a, verify=False))
sage: a == b  # should be True
False
sage: a.str(truncate=False)
0.85425665148473689034386458431097348561089439860408577398333000 + 20.000000000000000000000000000000000000000000000000000000000000*I
sage: b.str(truncate=False)
0.85425665148473689034386458431097348561089439860408577398333374 + 20.000000000000000000000000000000000000000000000000000000000000*I

This was found by

sage -t --long --random-seed=3159 src/sage/rings/complex_mpfr.pyx

The corresponding real version works:

sage: sage_input(a.real(), verify=True)
# Verified
RealField(200)(0.85425665148473689034386458431097348561089439860408577398333)

In #29979, a doctest was marked not tested because of this.

Component: numerical

Reviewer: Markus Wageringel

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

Description changed:

--- 
+++ 
@@ -35,3 +35,4 @@
 RealField(200)(0.85425665148473689034386458431097348561089439860408577398333)
 ```
 
+In #29979, a doctest was marked `not tested` because of this.
comment:5

dup of #30977?

Reviewer: Markus Wageringel

comment:6

Yes, it looks like it. Let us merge them.