#4276: [with patch, needs review] move number fields to new coercion, implement
embeddings
----------------------+-----------------------------------------------------
 Reporter:  robertwb  |        Owner:  robertwb  
     Type:  defect    |       Status:  new       
 Priority:  major     |    Milestone:  sage-3.2.2
Component:  coercion  |   Resolution:            
 Keywords:            |  
----------------------+-----------------------------------------------------
Comment (by ncalexan):

 I am trying to referee this, but it's going to take some time.  I'm going
 to put it into my tree and try to move some of my code that does this by
 hand to the embedding architecture.  Email me in a month.

 I have some questions and problems:

 I really need to be able to specify embeddings after creation, because
 *tons* of functions create number fields (composite_fields, for example,
 or subfields) and I really don't want to specify all possible embeddings
 of the results...

 First, why squarefree_part bounded?  This could be a separate patch.

 Second, I can specify non-embeddings that seem to be ignored:

 {{{
 sage: K.<a> = NumberField(x^3+2, embedding=CC(-10).nth_root(3))
 sage: K.coerce_embedding()

 Generic morphism:
   From: Number Field in a with defining polynomial x^3 + 2
   To:   Complex Lazy Field
   Defn: a -> 0.6299605249474365? + 1.091123635971722?*I
 sage: K.gen_embedding()^3
 -2.00000000000000? + 0.?e-14*I
 }}}

 Finally, I am having lots of trouble creating non-default embeddings:

 {{{
 sage: K2.<a> = NumberField(x^2 + 2, 'a', embedding=RR(-sqrt(2)))
 ---------------------------------------------------------------------------
 IndexError                                Traceback (most recent call
 last)

 
/Users/ncalexan/.sage/temp/mero.local/25160/_Users_ncalexan__sage_init_sage_0.py
 in <module>()
 ----> 1
       2
       3
       4
       5

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/number_field/number_field.pyc in
 NumberField(polynomial, name, check, names, cache, embedding)
     369
     370     if polynomial.degree() == 2:
 --> 371         K = NumberField_quadratic(polynomial, name, check,
 embedding)
     372     else:
     373         K = NumberField_absolute(polynomial, name, None, check,
 embedding)

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/number_field/number_field.pyc in __init__(self,
 polynomial, name, check, embedding)
    6470             Number Field in a with defining polynomial x^2 - 4
    6471         """
 -> 6472         NumberField_absolute.__init__(self, polynomial, name=name,
 check=check, embedding=embedding)
    6473         self._element_class =
 number_field_element_quadratic.NumberFieldElement_quadratic
    6474         c, b, a = [rational.Rational(t) for t in
 self.defining_polynomial().list()]

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/number_field/number_field.pyc in __init__(self,
 polynomial, name, latex_name, check, embedding)
    3649         NumberField_generic.__init__(self, polynomial, name,
 latex_name, check, embedding)
    3650         self._element_class =
 number_field_element.NumberFieldElement_absolute
 -> 3651         self._zero_element = self(0)
    3652         self._one_element =  self(1)
    3653

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__
 (sage/structure/parent.c:3665)()
     277
     278
 --> 279
     280
     281

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent.convert_map_from
 (sage/structure/parent.c:8640)()
    1000
    1001
 -> 1002
    1003
    1004

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent.discover_convert_map_from
 (sage/structure/parent.c:8771)()
    1007
    1008
 -> 1009
    1010
    1011

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent.coerce_map_from
 (sage/structure/parent.c:7653)()
     876
     877
 --> 878
     879
     880

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent.discover_coerce_map_from
 (sage/structure/parent.c:7956)()
     921
     922
 --> 923
     924
     925

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/parent_old.so in
 sage.structure.parent_old.Parent._coerce_map_from_
 (sage/structure/parent_old.c:6291)()
     576
     577
 --> 578
     579
     580

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/number_field/number_field.pyc in
 _coerce_map_from_(self, K)
    6497             return
 number_field_element_quadratic.Q_to_quadratic_field_element(self)
    6498         else:
 -> 6499             return NumberField_absolute._coerce_map_from_(self, K)
    6500
    6501

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/number_field/number_field.pyc in
 _coerce_map_from_(self, R)
    1525         """
    1526         if R in [int, long, ZZ, QQ, self.base()]:
 -> 1527             return self._generic_convert_map(R)
    1528         from sage.rings.number_field.order import
 is_NumberFieldOrder
    1529         if is_NumberFieldOrder(R) and
 R.number_field().has_coerce_map_from(self):

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/parent_old.so in
 sage.structure.parent_old.Parent._generic_convert_map
 (sage/structure/parent_old.c:6841)()
     594
     595
 --> 596
     597
     598

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/parent_old.so in
 sage.structure.parent_old.Parent._generic_convert_map
 (sage/structure/parent_old.c:6806)()
     602
     603
 --> 604
     605
     606

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent._generic_convert_map
 (sage/structure/parent.c:6875)()
     747
     748
 --> 749
     750
     751

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/coerce_maps.so in
 sage.structure.coerce_maps.DefaultConvertMap.__init__
 (sage/structure/coerce_maps.c:1931)()
      22
      23
 ---> 24
      25
      26

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/categories/map.so in sage.categories.map.Map.__init__
 (sage/categories/map.c:1768)()
      39
      40
 ---> 41
      42
      43

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/categories/homset.pyc in Hom(X, Y, cat)
     151
     152     ##_cache[key] = weakref.ref(H)
 --> 153     _cache[(X, Y, cat)] = weakref.ref(H)
     154
     155     return H

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/number_field/number_field.pyc in __cmp__(self, other)
    1639         else:
    1640             return cmp(self.coerce_embedding()(self.gen()),
 -> 1641                        other.coerce_embedding()(other.gen()))
    1642
    1643     def _ideal_class_(self):

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/real_lazy.so in
 sage.rings.real_lazy.LazyBinop.__richcmp__ (sage/rings/real_lazy.c:7858)()
     868
     869
 --> 870
     871
     872

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/element.so in
 sage.structure.element.Element._richcmp (sage/structure/element.c:5169)()
     530
     531
 --> 532
     533
     534

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/element.so in
 sage.structure.element.Element._richcmp_c_impl
 (sage/structure/element.c:5400)()
     577
     578
 --> 579
     580
     581

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/real_lazy.so in
 sage.rings.real_lazy.LazyFieldElement._cmp_c_impl
 (sage/rings/real_lazy.c:5445)()
     508
     509
 --> 510
     511
     512

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/real_lazy.so in
 sage.rings.real_lazy.LazyFieldElement.approx
 (sage/rings/real_lazy.c:5880)()
     567
     568
 --> 569
     570
     571

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/real_lazy.so in sage.rings.real_lazy.LazyBinop.eval
 (sage/rings/real_lazy.c:7427)()
     825
     826
 --> 827
     828
     829

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/real_lazy.so in sage.rings.real_lazy.LazyBinop.eval
 (sage/rings/real_lazy.c:7439)()
     826
     827
 --> 828
     829
     830

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/real_lazy.so in
 sage.rings.real_lazy.LazyAlgebraic.eval (sage/rings/real_lazy.c:10310)()
    1278
    1279
 -> 1280
    1281
    1282

 IndexError: list index out of range
 sage:
 }}}


 And even worse, non-embeddings. check the sign of sqrt(2) below)

 {{{
 sage: K1.<a> = NumberField(x^2 + 2, 'a', embedding=RR(sqrt(2)))
 sage: K1.gen_embedding()
 ---------------------------------------------------------------------------
 IndexError                                Traceback (most recent call
 last)

 
/Users/ncalexan/.sage/temp/mero.local/25160/_Users_ncalexan__sage_init_sage_0.py
 in <module>()
 ----> 1
       2
       3
       4
       5

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/IPython/Prompts.pyc in __call__(self, arg)
     549
     550             # and now call a possibly user-defined print mechanism
 --> 551             manipulated_val = self.display(arg)
     552
     553             # user display hooks can change the variable to be
 stored in

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/IPython/Prompts.pyc in _display(self, arg)
     575             return IPython.generics.result_display(arg)
     576         except TryNext:
 --> 577             return self.shell.hooks.result_display(arg)
     578
     579     # Assign the default display method:

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/IPython/hooks.pyc in __call__(self, *args, **kw)
     133             #print "prio",prio,"cmd",cmd #dbg
     134             try:
 --> 135                 ret = cmd(*args, **kw)
     136                 return ret
     137             except ipapi.TryNext, exc:

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/IPython/hooks.pyc in result_display(self, arg)
     163
     164     if self.rc.pprint:
 --> 165         out = pformat(arg)
     166         if '\n' in out:
     167             # So that multi-line strings line up with the left
 column of

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python/pprint.pyc in
 pformat(self, object)
     109     def pformat(self, object):
     110         sio = _StringIO()
 --> 111         self._format(object, sio, 0, 0, {}, 0)
     112         return sio.getvalue()
     113

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python/pprint.pyc in
 _format(self, object, stream, indent, allowance, context, level)
     127             self._readable = False
     128             return
 --> 129         rep = self._repr(object, context, level - 1)
     130         typ = _type(object)
     131         sepLines = _len(rep) > (self._width - 1 - indent -
 allowance)

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python/pprint.pyc in
 _repr(self, object, context, level)
     193     def _repr(self, object, context, level):
     194         repr, readable, recursive = self.format(object,
 context.copy(),
 --> 195                                                 self._depth,
 level)
     196         if not readable:
     197             self._readable = False

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python/pprint.pyc in
 format(self, object, context, maxlevels, level)
     205         and whether the object represents a recursive construct.
     206         """
 --> 207         return _safe_repr(object, context, maxlevels, level)
     208
     209

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python/pprint.pyc in
 _safe_repr(object, context, maxlevels, level)
     290         return format % _commajoin(components), readable,
 recursive
     291
 --> 292     rep = repr(object)
     293     return rep, (rep and not rep.startswith('<')), False
     294

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/structure/sage_object.so in
 sage.structure.sage_object.SageObject.__repr__
 (sage/structure/sage_object.c:1090)()
      90
      91
 ---> 92
      93
      94

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/real_lazy.so in
 sage.rings.real_lazy.LazyFieldElement._repr_
 (sage/rings/real_lazy.c:5833)()
     555
     556
 --> 557
     558
     559

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/real_lazy.so in
 sage.rings.real_lazy.LazyFieldElement.approx
 (sage/rings/real_lazy.c:5880)()
     567
     568
 --> 569
     570
     571

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/real_lazy.so in sage.rings.real_lazy.LazyBinop.eval
 (sage/rings/real_lazy.c:7427)()
     825
     826
 --> 827
     828
     829

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/real_lazy.so in sage.rings.real_lazy.LazyBinop.eval
 (sage/rings/real_lazy.c:7439)()
     826
     827
 --> 828
     829
     830

 /Users/ncalexan/sage-3.2.1.alpha1/local/lib/python2.5/site-
 packages/sage/rings/real_lazy.so in
 sage.rings.real_lazy.LazyAlgebraic.eval (sage/rings/real_lazy.c:10310)()
    1278
    1279
 -> 1280
    1281
    1282

 IndexError: list index out of range
 sage:
 }}}

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/4276#comment:10>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of 
Reinventing the Wheel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to