Bug (?) while making a number field

33 views
Skip to first unread message

kcrisman

unread,
Mar 17, 2015, 10:55:14 PM3/17/15
to sage-s...@googlegroups.com
I fully accept the following is probably user error due to having not picked an embedding of the field.

sage: GaussianIntegers = NumberField(x^2+1, 'I').ring_of_integers()
sage: A = GaussianIntegers([2,1])
sage: print A
I + 2
sage: print A.n()
<lots of junk>
RuntimeError: maximum recursion depth exceeded while calling a Python object

Still, this seems like not the most helpful error message; shouldn't it tell me to do (something like) this?

sage: GaussianIntegers = NumberField(x^2+1, 'I', embedding=CC.gen()).ring_of_integers()
sage: A = GaussianIntegers([2,1])
sage: print A.n()
2.00000000000000 + 1.00000000000000*I

- kcrisman

William Stein

unread,
Mar 17, 2015, 11:06:07 PM3/17/15
to sage-support
On Tue, Mar 17, 2015 at 7:55 PM, kcrisman <kcri...@gmail.com> wrote:
> I fully accept the following is probably user error due to having not picked
> an embedding of the field.
>
> sage: GaussianIntegers = NumberField(x^2+1, 'I').ring_of_integers()
> sage: A = GaussianIntegers([2,1])
> sage: print A
> I + 2
> sage: print A.n()
> <lots of junk>
> RuntimeError: maximum recursion depth exceeded while calling a Python object
>
> Still, this seems like not the most helpful error message; shouldn't it tell
> me to do (something like) this?

Yes! Definitely a bug...

>
> sage: GaussianIntegers = NumberField(x^2+1, 'I',
> embedding=CC.gen()).ring_of_integers()
> sage: A = GaussianIntegers([2,1])
> sage: print A.n()
> 2.00000000000000 + 1.00000000000000*I
>
> - kcrisman
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.



--
William (http://wstein.org)

John Cremona

unread,
Mar 18, 2015, 3:02:55 AM3/18/15
to SAGE support
That has been fixed in 6.6.beta1, you did not say which version you were using.

John

Volker Braun

unread,
Mar 18, 2015, 5:09:40 AM3/18/15
to sage-s...@googlegroups.com
On Wednesday, March 18, 2015 at 8:02:55 AM UTC+1, John Cremona wrote:
That has been fixed in 6.6.beta1, you did not say which version you were using.

Still happens with beta5. Do you want to open a ticket?

┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 6.6.beta5, Release Date: 2015-03-13                   │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: GaussianIntegers = NumberField(x^2+1, 'I').ring_of_integers()
sage: A = GaussianIntegers([2,1])
sage: A.n()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-3-f924bd0d29c9> in <module>()
----> 1 A.n()

/mnt/disk/home/release/Sage/src/sage/structure/element.pyx in sage.structure.element.Element.numerical_approx (build/cythonized/sage/structure/element.c:7435)()
    743         """
    744         from sage.misc.functional import numerical_approx
--> 745         return numerical_approx(self, prec=prec, digits=digits,
    746                                 algorithm=algorithm)
    747     n = numerical_approx

/mnt/disk/home/release/Sage/local/lib/python2.7/site-packages/sage/misc/functional.pyc in numerical_approx(x, prec, digits, algorithm)
   1333     # The issue is not precision, try conversion instead
   1334     try:
-> 1335         return RR(x)
   1336     except (TypeError, ValueError):
   1337         pass

/mnt/disk/home/release/Sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9602)()
   1092         if mor is not None:
   1093             if no_extra_args:
-> 1094                 return mor._call_(x)
   1095             else:
   1096                 return mor._call_with_args(x, args, kwds)

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.NamedConvertMap._call_ (build/cythonized/sage/structure/coerce_maps.c:5819)()
    236             raise TypeError("Cannot coerce {} to {}".format(x, C))
    237         cdef Map m
--> 238         cdef Element e = method(C)
    239         if e is None:
    240             raise RuntimeError("BUG in coercion model: {} method of {} returned None".format(self.method_name, type(x)))

/mnt/disk/home/release/Sage/src/sage/rings/number_field/number_field_element.pyx in sage.rings.number_field.number_field_element.NumberFieldElement._mpfr_ (build/cythonized/sage/rings/number_field/number_field_element.cpp:15017)()
   1383             return R(self.base_ring()(self))
   1384         else:
-> 1385             return R(R.complex_field()(self))
   1386 
   1387     def __float__(self):

/mnt/disk/home/release/Sage/local/lib/python2.7/site-packages/sage/rings/complex_field.pyc in __call__(self, x, im)
    349         if im is not None:
    350             x = x, im
--> 351         return Parent.__call__(self, x)
    352 
    353     def _element_constructor_(self, x):

/mnt/disk/home/release/Sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9602)()
   1092         if mor is not None:
   1093             if no_extra_args:
-> 1094                 return mor._call_(x)
   1095             else:
   1096                 return mor._call_with_args(x, args, kwds)

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4496)()
    108                 print type(C), C
    109                 print type(C._element_constructor), C._element_constructor
--> 110             raise
    111 
    112     cpdef Element _call_with_args(self, x, args=(), kwds={}):

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4403)()
    103         cdef Parent C = self._codomain
    104         try:
--> 105             return C._element_constructor(x)
    106         except Exception:
    107             if print_warnings:

/mnt/disk/home/release/Sage/local/lib/python2.7/site-packages/sage/rings/complex_field.pyc in _element_constructor_(self, x)
    391             except AttributeError:
    392                 pass
--> 393         return complex_number.ComplexNumber(self, x)
    394 
    395     def _coerce_map_from_(self, S):

/mnt/disk/home/release/Sage/src/sage/rings/complex_number.pyx in sage.rings.complex_number.ComplexNumber.__init__ (build/cythonized/sage/rings/complex_number.c:4167)()
    182         try:
    183             R = parent._real_field()
--> 184             rr = R(real)
    185             ii = R(imag)
    186             mpfr_set(self.__re, rr.value, rnd)

/mnt/disk/home/release/Sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9602)()
   1092         if mor is not None:
   1093             if no_extra_args:
-> 1094                 return mor._call_(x)
   1095             else:
   1096                 return mor._call_with_args(x, args, kwds)

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.NamedConvertMap._call_ (build/cythonized/sage/structure/coerce_maps.c:5819)()
    236             raise TypeError("Cannot coerce {} to {}".format(x, C))
    237         cdef Map m
--> 238         cdef Element e = method(C)
    239         if e is None:
    240             raise RuntimeError("BUG in coercion model: {} method of {} returned None".format(self.method_name, type(x)))

/mnt/disk/home/release/Sage/src/sage/rings/number_field/number_field_element.pyx in sage.rings.number_field.number_field_element.NumberFieldElement._mpfr_ (build/cythonized/sage/rings/number_field/number_field_element.cpp:15017)()
   1383             return R(self.base_ring()(self))
   1384         else:
-> 1385             return R(R.complex_field()(self))
   1386 
   1387     def __float__(self):

/mnt/disk/home/release/Sage/local/lib/python2.7/site-packages/sage/rings/complex_field.pyc in __call__(self, x, im)
    349         if im is not None:
    350             x = x, im
--> 351         return Parent.__call__(self, x)
    352 
    353     def _element_constructor_(self, x):

/mnt/disk/home/release/Sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9602)()
   1092         if mor is not None:
   1093             if no_extra_args:
-> 1094                 return mor._call_(x)
   1095             else:
   1096                 return mor._call_with_args(x, args, kwds)

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4496)()
    108                 print type(C), C
    109                 print type(C._element_constructor), C._element_constructor
--> 110             raise
    111 
    112     cpdef Element _call_with_args(self, x, args=(), kwds={}):

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4403)()
    103         cdef Parent C = self._codomain
    104         try:
--> 105             return C._element_constructor(x)
    106         except Exception:
    107             if print_warnings:

/mnt/disk/home/release/Sage/local/lib/python2.7/site-packages/sage/rings/complex_field.pyc in _element_constructor_(self, x)
    391             except AttributeError:
    392                 pass
--> 393         return complex_number.ComplexNumber(self, x)
    394 
    395     def _coerce_map_from_(self, S):

/mnt/disk/home/release/Sage/src/sage/rings/complex_number.pyx in sage.rings.complex_number.ComplexNumber.__init__ (build/cythonized/sage/rings/complex_number.c:4167)()
    182         try:
    183             R = parent._real_field()
--> 184             rr = R(real)
    185             ii = R(imag)
    186             mpfr_set(self.__re, rr.value, rnd)

/mnt/disk/home/release/Sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9602)()
   1092         if mor is not None:
   1093             if no_extra_args:
-> 1094                 return mor._call_(x)
   1095             else:
   1096                 return mor._call_with_args(x, args, kwds)

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.NamedConvertMap._call_ (build/cythonized/sage/structure/coerce_maps.c:5819)()
    236             raise TypeError("Cannot coerce {} to {}".format(x, C))
    237         cdef Map m
--> 238         cdef Element e = method(C)
    239         if e is None:
    240             raise RuntimeError("BUG in coercion model: {} method of {} returned None".format(self.method_name, type(x)))

/mnt/disk/home/release/Sage/src/sage/rings/number_field/number_field_element.pyx in sage.rings.number_field.number_field_element.NumberFieldElement._mpfr_ (build/cythonized/sage/rings/number_field/number_field_element.cpp:15017)()
   1383             return R(self.base_ring()(self))
   1384         else:
-> 1385             return R(R.complex_field()(self))
   1386 
   1387     def __float__(self):

/mnt/disk/home/release/Sage/local/lib/python2.7/site-packages/sage/rings/complex_field.pyc in __call__(self, x, im)
    349         if im is not None:
    350             x = x, im
--> 351         return Parent.__call__(self, x)
    352 
    353     def _element_constructor_(self, x):

/mnt/disk/home/release/Sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9602)()
   1092         if mor is not None:
   1093             if no_extra_args:
-> 1094                 return mor._call_(x)
   1095             else:
   1096                 return mor._call_with_args(x, args, kwds)

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4496)()
    108                 print type(C), C
    109                 print type(C._element_constructor), C._element_constructor
--> 110             raise
    111 
    112     cpdef Element _call_with_args(self, x, args=(), kwds={}):

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4403)()
    103         cdef Parent C = self._codomain
    104         try:
--> 105             return C._element_constructor(x)
    106         except Exception:
    107             if print_warnings:

/mnt/disk/home/release/Sage/local/lib/python2.7/site-packages/sage/rings/complex_field.pyc in _element_constructor_(self, x)
    391             except AttributeError:
    392                 pass
--> 393         return complex_number.ComplexNumber(self, x)
    394 
    395     def _coerce_map_from_(self, S):

/mnt/disk/home/release/Sage/src/sage/rings/complex_number.pyx in sage.rings.complex_number.ComplexNumber.__init__ (build/cythonized/sage/rings/complex_number.c:4167)()
    182         try:
    183             R = parent._real_field()
--> 184             rr = R(real)
    185             ii = R(imag)
    186             mpfr_set(self.__re, rr.value, rnd)

/mnt/disk/home/release/Sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9602)()
   1092         if mor is not None:
   1093             if no_extra_args:
-> 1094                 return mor._call_(x)
   1095             else:
   1096                 return mor._call_with_args(x, args, kwds)

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.NamedConvertMap._call_ (build/cythonized/sage/structure/coerce_maps.c:5819)()
    236             raise TypeError("Cannot coerce {} to {}".format(x, C))
    237         cdef Map m
--> 238         cdef Element e = method(C)
    239         if e is None:
    240             raise RuntimeError("BUG in coercion model: {} method of {} returned None".format(self.method_name, type(x)))

/mnt/disk/home/release/Sage/src/sage/rings/number_field/number_field_element.pyx in sage.rings.number_field.number_field_element.NumberFieldElement._mpfr_ (build/cythonized/sage/rings/number_field/number_field_element.cpp:15017)()
   1383             return R(self.base_ring()(self))
   1384         else:
-> 1385             return R(R.complex_field()(self))
   1386 
   1387     def __float__(self):

/mnt/disk/home/release/Sage/local/lib/python2.7/site-packages/sage/rings/complex_field.pyc in __call__(self, x, im)
    349         if im is not None:
    350             x = x, im
--> 351         return Parent.__call__(self, x)
    352 
    353     def _element_constructor_(self, x):

/mnt/disk/home/release/Sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9602)()
   1092         if mor is not None:
   1093             if no_extra_args:
-> 1094                 return mor._call_(x)
   1095             else:
   1096                 return mor._call_with_args(x, args, kwds)

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4496)()
    108                 print type(C), C
    109                 print type(C._element_constructor), C._element_constructor
--> 110             raise
    111 
    112     cpdef Element _call_with_args(self, x, args=(), kwds={}):

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (build/cythonized/sage/structure/coerce_maps.c:4403)()
    103         cdef Parent C = self._codomain
    104         try:
--> 105             return C._element_constructor(x)
    106         except Exception:
    107             if print_warnings:

/mnt/disk/home/release/Sage/local/lib/python2.7/site-packages/sage/rings/complex_field.pyc in _element_constructor_(self, x)
    391             except AttributeError:
    392                 pass
--> 393         return complex_number.ComplexNumber(self, x)
    394 
    395     def _coerce_map_from_(self, S):

/mnt/disk/home/release/Sage/src/sage/rings/complex_number.pyx in sage.rings.complex_number.ComplexNumber.__init__ (build/cythonized/sage/rings/complex_number.c:4167)()
    182         try:
    183             R = parent._real_field()
--> 184             rr = R(real)
    185             ii = R(imag)
    186             mpfr_set(self.__re, rr.value, rnd)

/mnt/disk/home/release/Sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9602)()
   1092         if mor is not None:
   1093             if no_extra_args:
-> 1094                 return mor._call_(x)
   1095             else:
   1096                 return mor._call_with_args(x, args, kwds)

/mnt/disk/home/release/Sage/src/sage/structure/coerce_maps.pyx in sage.structure.coerce_maps.NamedConvertMap._call_ (build/cythonized/sage/structure/coerce_maps.c:5819)()
    236             raise TypeError("Cannot coerce {} to {}".format(x, C))
    237         cdef Map m
--> 238         cdef Element e = method(C)
    239         if e is None:
    240             raise RuntimeError("BUG in coercion model: {} method of {} returned None".format(self.method_name, type(x)))

/mnt/disk/home/release/Sage/src/sage/rings/number_field/number_field_element.pyx in sage.rings.number_field.number_field_element.NumberFieldElement._mpfr_ (build/cythonized/sage/rings/number_field/number_field_element.cpp:15017)()
   1383             return R(self.base_ring()(self))
   1384         else:
-> 1385             return R(R.complex_field()(self))
   1386 
   1387     def __float__(self):

/mnt/disk/home/release/Sage/local/lib/python2.7/site-packages/sage/rings/complex_field.pyc in __call__(self, x, im)
    349         if im is not None:
    350             x = x, im
--> 351         return Parent.__call__(self, x)
    352 
    353     def _element_constructor_(self, x):

/mnt/disk/home/release/Sage/src/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9602)()
   1092         if mor is not None:
   1093             if no_extra_args:
-> 1094                 return mor._call_(x)
   1095             else:
   1096                 return mor._call_with_args(x, args, kwds)

...


/mnt/disk/home/release/Sage/src/sage/misc/cachefunc.pyx in sage.misc.cachefunc.WeakCachedFunction.__call__ (build/cythonized/sage/misc/cachefunc.c:7801)()
   1280             if self._argument_fixer is None:
   1281                 self.argfix_init()
-> 1282             k = self._fix_to_pos(*args, **kwds)
   1283         else:
   1284             if self._default_key is not None:

RuntimeError: maximum recursion depth exceeded while calling a Python object
sage:  


kcrisman

unread,
Mar 18, 2015, 10:34:54 AM3/18/15
to sage-s...@googlegroups.com
Still happens with beta5. Do you want to open a ticket?


John Cremona

unread,
Mar 18, 2015, 5:16:29 PM3/18/15
to SAGE support
OK, so it is not the same as the other Pari recursion bug which was
fixed. I saw the ticket. I have never used the .n() method on
anything, and when I want to embed a number field K into RR or CC I
use K.embeddings(). Otherwise I might have noticed this before.

I note that A.?? does *not* show the source code, which is not in the
file shown as the source of the A.n() function.

Volker Braun

unread,
Mar 18, 2015, 6:41:35 PM3/18/15
to sage-s...@googlegroups.com
I made http://trac.sagemath.org/ticket/17996 for the missing A.n?? source.
Reply all
Reply to author
Forward
0 new messages