Ticket #7160: trac_7160-Q_to_quadratic_field_element.patch

File trac_7160-Q_to_quadratic_field_element.patch, 3.8 KB (added by burcin, 9 years ago)
  • sage/rings/number_field/number_field.py

    # HG changeset patch
    # User Burcin Erocal <burcin@erocal.org>
    # Date 1326157690 -3600
    trac 7160: fix element class for result of Q -> quadratic number field morphism
    
    diff --git a/sage/rings/number_field/number_field.py b/sage/rings/number_field/number_field.py
    a b  
    50935093        """
    50945094        NumberField_generic.__init__(self, polynomial, name, latex_name, check, embedding,
    50955095                                     assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes)
    5096         if (element_class is None or
    5097             not issubclass(element_class, number_field_element.NumberFieldElement_absolute)):
     5096        if element_class is None:
    50985097            self._element_class = number_field_element.NumberFieldElement_absolute
     5098        elif not issubclass(element_class, number_field_element.NumberFieldElement_absolute):
     5099            raise ValueError("element class must be a subclass of NumberFieldElement_absolute")
    50995100        else:
    51005101            self._element_class = element_class
    51015102        self._zero_element = self(0)
     
    82418242        NumberField_absolute.__init__(self, polynomial, name=name, check=check,
    82428243                                      embedding=embedding, latex_name=latex_name,
    82438244                                      assume_disc_small=assume_disc_small, maximize_at_primes=maximize_at_primes)
    8244         if (element_class is None or
    8245             not issubclass(element_class, number_field_element_quadratic.NumberFieldElement_quadratic)):
     8245        if element_class is None:
    82468246            self._element_class = number_field_element_quadratic.NumberFieldElement_quadratic
     8247        elif not issubclass(element_class, number_field_element_quadratic.NumberFieldElement_quadratic):
     8248            raise ValueError("element class must be a subclass of NumberFieldElement_quadratic")
    82478249        else:
    82488250            self._element_class = element_class
    82498251       
  • sage/rings/number_field/number_field_element_quadratic.pyx

    diff --git a/sage/rings/number_field/number_field_element_quadratic.pyx b/sage/rings/number_field/number_field_element_quadratic.pyx
    a b  
    16101610            <type 'sage.rings.number_field.number_field_element_quadratic.Q_to_quadratic_field_element'>
    16111611            sage: phi == loads(dumps(phi)) # not implemented
    16121612            True
     1613
     1614        TESTS::
     1615
     1616            sage: from sage.rings.number_field.number_field_element_quadratic import Q_to_quadratic_field_element
     1617            sage: Q_to_quadratic_field_element(I.pyobject().parent())(1/2).__class__
     1618            Q_to_quadratic_field_element(I.pyobject().parent())(1/2).__class__
    16131619        """
    16141620        import sage.categories.homset
    16151621        Morphism.__init__(self, sage.categories.homset.Hom(QQ, K))
    1616         self.zero_element = PY_NEW(NumberFieldElement_quadratic)
     1622        self.zero_element = PY_NEW(K._element_class)
    16171623        self.zero_element._parent = K
    16181624        self.zero_element.D = K._D
    16191625       
     
    16561662    This class is designed primarily to be used by the symbolics
    16571663    system.  Upon comparison, the instances of this class will try to
    16581664    see if they can be embedded as a real number and perform the
    1659     comparision as real numbers.  This fixes bug #6132 where we would
     1665    comparison as real numbers.  This fixes bug #6132 where we would
    16601666    have things like ``bool(I^2) > 0`` returning ``True``.  See
    16611667    :func:`sage.symbolic.pynac.init_pynac_I`.
    16621668    """
     
    17071713        embedding = left.parent().coerce_embedding()
    17081714        if embedding is not None:
    17091715            try:
    1710                 from sage.rings.all import QQbar
    17111716                l = embedding(left)
    17121717                return cmp(l, right)
    17131718            except (TypeError, ValueError), exc: