#14989: Conversion failure from `ZZ[i]` to `CC`
----------------------------------------------+----------------------------
       Reporter:  mmezzarobba                 |         Owner:
           Type:  defect                      |        Status:
       Priority:  major                       |  needs_review
      Component:  misc                        |     Milestone:  sage-5.12
       Keywords:                              |    Resolution:
        Authors:                              |     Merged in:
Report Upstream:  N/A                         |     Reviewers:
         Branch:  u/mmezzarobba/ticket/14989  |   Work issues:
       Stopgaps:                              |  Dependencies:
----------------------------------------------+----------------------------
Changes (by mmezzarobba):

 * status:  new => needs_review
 * branch:   => u/mmezzarobba/ticket/14989


Old description:

> `ComplexField_class._element_constructor_` calls
> `x.parent().polynomial()` when `isinstance(x,
> NumberFieldElement_quadratic)`, but not all objects of class
> `NumberFieldElement_quadratic` have a number field as a parent. As a
> consequence, the following conversion (that I guess really should work,
> since it is suggested by `pushout()`) fails.
>
> {{{
> sage: QQi.<i> = NumberField(x^2+1, embedding=1.*I)
> sage: O = QQi.order(i)
> sage: from sage.categories.pushout import pushout
> sage: pushout(O, CC)
> Complex Field with 53 bits of precision
> sage: CC(O.gen(1))
> ---------------------------------------------------------------------------
> AttributeError                            Traceback (most recent call
> last)
> <ipython-input-23-dbf70e6b573a> in <module>()
> ----> 1 CC(O.gen(Integer(1)))
>
> /home/marc/co/sage/local/lib/python2.7/site-
> packages/sage/rings/complex_field.pyc in __call__(self, x, im)
>     345         if im is not None:
>     346             x = x, im
> --> 347         return Parent.__call__(self, x)
>     348
>     349     def _element_constructor_(self, x):
>
> /home/marc/co/sage/local/lib/python2.7/site-
> packages/sage/structure/parent.so in
> sage.structure.parent.Parent.__call__ (sage/structure/parent.c:8134)()
>
> /home/marc/co/sage/local/lib/python2.7/site-
> packages/sage/structure/coerce_maps.so in
> sage.structure.coerce_maps.DefaultConvertMap_unique._call_
> (sage/structure/coerce_maps.c:3856)()
>
> /home/marc/co/sage/local/lib/python2.7/site-
> packages/sage/structure/coerce_maps.so in
> sage.structure.coerce_maps.DefaultConvertMap_unique._call_
> (sage/structure/coerce_maps.c:3757)()
>
> /home/marc/co/sage/local/lib/python2.7/site-
> packages/sage/rings/complex_field.pyc in _element_constructor_(self, x)
>     366
>     367             late_import()
> --> 368             if isinstance(x, NumberFieldElement_quadratic) and
> list(x.parent().polynomial()) == [1, 0, 1]:
>     369                 (re, im) = list(x)
>     370                 return complex_number.ComplexNumber(self, re, im)
>
> /home/marc/co/sage/local/lib/python2.7/site-
> packages/sage/structure/parent.so in
> sage.structure.parent.Parent.__getattr__ (sage/structure/parent.c:6662)()
>
> /home/marc/co/sage/local/lib/python2.7/site-
> packages/sage/structure/misc.so in
> sage.structure.misc.getattr_from_other_class
> (sage/structure/misc.c:1606)()
>
> AttributeError: 'AbsoluteOrder_with_category' object has no attribute
> 'polynomial'
> }}}

New description:

 `ComplexField_class._element_constructor_` calls `x.parent().polynomial()`
 when `isinstance(x, NumberFieldElement_quadratic)`, but not all objects of
 class `NumberFieldElement_quadratic` have a number field as a parent. As a
 consequence, the following conversion (that I guess really should work,
 since it is suggested by `pushout()`) fails.

 {{{
 sage: QQi.<i> = NumberField(x^2+1, embedding=CC(0,1))
 sage: O = QQi.order(i)
 sage: from sage.categories.pushout import pushout
 sage: pushout(O, CC)
 Complex Field with 53 bits of precision
 sage: CC(O.gen(1))
 ---------------------------------------------------------------------------
 AttributeError                            Traceback (most recent call
 last)
 <ipython-input-10-dbf70e6b573a> in <module>()
 ----> 1 CC(O.gen(Integer(1)))

 /home/marc/co/sage/local/lib/python2.7/site-
 packages/sage/rings/complex_field.pyc in __call__(self, x, im)
     345         if im is not None:
     346             x = x, im
 --> 347         return Parent.__call__(self, x)
     348
     349     def _element_constructor_(self, x):

 /home/marc/co/sage/local/lib/python2.7/site-
 packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__
 (sage/structure/parent.c:8134)()

 /home/marc/co/sage/local/lib/python2.7/site-
 packages/sage/structure/coerce_maps.so in
 sage.structure.coerce_maps.DefaultConvertMap_unique._call_
 (sage/structure/coerce_maps.c:3856)()

 /home/marc/co/sage/local/lib/python2.7/site-
 packages/sage/structure/coerce_maps.so in
 sage.structure.coerce_maps.DefaultConvertMap_unique._call_
 (sage/structure/coerce_maps.c:3757)()

 /home/marc/co/sage/local/lib/python2.7/site-
 packages/sage/rings/complex_field.pyc in _element_constructor_(self, x)
     366
     367             late_import()
 --> 368             if isinstance(x, NumberFieldElement_quadratic) and
 list(x.parent().polynomial()) == [1, 0, 1]:
     369                 (re, im) = list(x)
     370                 return complex_number.ComplexNumber(self, re, im)

 /home/marc/co/sage/local/lib/python2.7/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent.__getattr__ (sage/structure/parent.c:6662)()

 /home/marc/co/sage/local/lib/python2.7/site-
 packages/sage/structure/misc.so in
 sage.structure.misc.getattr_from_other_class
 (sage/structure/misc.c:1606)()

 AttributeError: 'AbsoluteOrder_with_category' object has no attribute
 'polynomial'
 }}}

--

Comment:

 Hmm, the example I gave in the original ticket is not correct, since it
 sets up an embedding into `SR`. But the same issue occurs with an
 embedding into `CC`. I updated the description to reflect that.

 I ''think'' the linked patches solve the problem, but I have no idea if
 the "spirit" of the fix is right. So it would be great if someone who
 understands the coercion system could have a look!

--
Ticket URL: <http://trac.sagemath.org/ticket/14989#comment:1>
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/groups/opt_out.


Reply via email to