Ticket #23471: 23471_over_14825.diff
File 23471_over_14825.diff, 11.8 KB (added by , 2 years ago) |
---|
-
src/sage/rings/number_field/number_field.py
diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index d224a344db..4750f84d30 100644
a b class NumberField_generic(WithEqualityById, number_field_base.NumberField): 1362 1362 else: 1363 1363 parent, x = embedding.parent(), embedding 1364 1364 embedding = number_field_morphisms.NumberFieldEmbedding(self, parent, x) 1365 self._populate_coercion_lists_(embedding=embedding )1365 self._populate_coercion_lists_(embedding=embedding, convert_method_name='_number_field_') 1366 1366 1367 1367 def _convert_map_from_(self, other): 1368 1368 r""" -
src/sage/rings/number_field/order.py
diff --git a/src/sage/rings/number_field/order.py b/src/sage/rings/number_field/order.py index 8cd3a8240a..c426e54fd7 100644
a b class AbsoluteOrder(Order): 1091 1091 Quadratic elements have a special optimized type: 1092 1092 1093 1093 """ 1094 Order.__init__(self, K, is_maximal=is_maximal)1095 1096 1094 if K.degree() == 2: 1097 1095 self._element_type = OrderElement_quadratic 1098 1096 # adding the following attribute makes the comparison of elements … … class AbsoluteOrder(Order): 1102 1100 self._element_type = OrderElement_absolute 1103 1101 1104 1102 self._module_rep = module_rep 1105 V, from_v, to_v = self._K.vector_space() 1103 V, from_v, to_v = K.vector_space() 1104 Order.__init__(self, K, is_maximal=is_maximal) 1105 1106 1106 if check: 1107 1107 if not K.is_absolute(): 1108 1108 raise ValueError("AbsoluteOrder must be called with an absolute number field.") … … class RelativeOrder(Order): 1473 1473 sage: loads(dumps(O)) == O 1474 1474 True 1475 1475 """ 1476 Order.__init__(self, K, is_maximal=is_maximal)1477 1476 self._absolute_order = absolute_order 1478 1477 self._module_rep = absolute_order._module_rep 1478 Order.__init__(self, K, is_maximal=is_maximal) 1479 1479 1480 1480 def _element_constructor_(self, x): 1481 1481 """ -
src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx
diff --git a/src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx index 3cef23ab83..aee6f1f813 100644
a b cdef class pAdicZZpXCAElement(pAdicZZpXElement): 1703 1703 """ 1704 1704 R = self.base_ring() 1705 1705 S = R[var] 1706 if self. absprec == 0:1706 if self.is_zero(): 1707 1707 return S([]) 1708 1708 e = self.parent().e() 1709 1709 L = [Integer(c) for c in self._ntl_rep().list()] -
src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx
diff --git a/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx index f3c6f8e1f6..2029b2497e 100644
a b cdef class pAdicZZpXCRElement(pAdicZZpXElement): 2524 2524 """ 2525 2525 R = self.base_ring() 2526 2526 S = R[var] 2527 if self. relprec == 0:2527 if self.is_zero(): 2528 2528 return S([]) 2529 2529 prec = self.relprec + self.ordp 2530 2530 e = self.parent().e() -
src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx
diff --git a/src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx index 5de71b11b1..7fd5b19d84 100644
a b cdef class pAdicZZpXFMElement(pAdicZZpXElement): 1152 1152 """ 1153 1153 R = self.base_ring() 1154 1154 S = R[var] 1155 if self.is_zero(): 1156 return S([]) 1155 1157 return S([Integer(c) for c in self._ntl_rep().list()]) 1156 1158 1157 1159 cdef ZZ_p_c _const_term(self): -
src/sage/rings/padics/padic_extension_generic.py
diff --git a/src/sage/rings/padics/padic_extension_generic.py b/src/sage/rings/padics/padic_extension_generic.py index fa317a30ab..39270fbf75 100644
a b from __future__ import absolute_import 22 22 23 23 from .padic_generic import pAdicGeneric 24 24 from .padic_base_generic import pAdicBaseGeneric 25 from sage.rings.number_field.number_field_base import NumberField 26 from sage.rings.number_field.order import Order 27 from sage.rings.rational_field import QQ 25 28 from sage.structure.richcmp import op_EQ 26 29 from functools import reduce 27 30 from sage.categories.morphism import Morphism 31 from sage.categories.sets_with_partial_maps import SetsWithPartialMaps 32 from sage.categories.integral_domains import IntegralDomains 33 from sage.categories.fields import Fields 34 from sage.categories.homset import Hom 28 35 29 36 class pAdicExtensionGeneric(pAdicGeneric): 30 37 def __init__(self, poly, prec, print_mode, names, element_class): … … class pAdicExtensionGeneric(pAdicGeneric): 62 69 63 70 def _coerce_map_from_(self, R): 64 71 """ 65 Returns True if there is a coercion map from R to self.72 Finds coercion maps from R to this ring. 66 73 67 74 EXAMPLES:: 68 75 … … class pAdicExtensionGeneric(pAdicGeneric): 85 92 from sage.rings.padics.qadic_flint_FP import pAdicCoercion_FP_frac_field as coerce_map 86 93 return coerce_map(R, self) 87 94 95 def _convert_map_from_(self, R): 96 """ 97 Finds conversion maps from R to this ring. 98 99 Currently, a conversion exists if the defining polynomial is the same. 100 101 EXAMPLES:: 102 103 sage: R.<a> = Zq(125) 104 sage: S = R.change(type='capped-abs', prec=40, print_mode='terse', print_pos=False) 105 sage: S(a - 15) 106 -15 + a + O(5^20) 107 108 We get conversions from the exact field:: 109 110 sage: K = R.exact_field(); K 111 Number Field in a with defining polynomial x^3 + 3*x + 3 112 sage: R(K.gen()) 113 a + O(5^20) 114 115 and its maximal order:: 116 117 sage: OK = K.maximal_order() 118 sage: R(OK.gen(1)) 119 a + O(5^20) 120 """ 121 cat = None 122 if self._implementation == 'NTL' and R == QQ: 123 # Want to use DefaultConvertMap 124 return None 125 if isinstance(R, pAdicExtensionGeneric) and R.defining_polynomial(exact=True) == self.defining_polynomial(exact=True): 126 if R.is_field() and not self.is_field(): 127 cat = SetsWithPartialMaps() 128 else: 129 cat = R.category() 130 elif isinstance(R, Order) and R.number_field().defining_polynomial() == self.defining_polynomial(): 131 cat = IntegralDomains() 132 elif isinstance(R, NumberField) and R.defining_polynomial() == self.defining_polynomial(): 133 if self.is_field(): 134 cat = Fields() 135 else: 136 cat = SetsWithPartialMaps() 137 if cat is not None: 138 H = Hom(R, self, cat) 139 return H.__make_element_class__(DefPolyConversion)(H) 140 88 141 def __eq__(self, other): 89 142 """ 90 143 Return ``True`` if ``self == other`` and ``False`` otherwise. … … class pAdicExtensionGeneric(pAdicGeneric): 448 501 #def zeta_order(self): 449 502 # raise NotImplementedError 450 503 504 class DefPolyConversion(Morphism): 505 """ 506 Conversion map between p-adic rings/fields with the same defining polynomial. 507 508 INPUT: 509 510 - ``R`` -- a p-adic extension ring or field. 511 - ``S`` -- a p-adic extension ring or field with the same defining polynomial. 512 513 EXAMPLES:: 514 515 sage: R.<a> = Zq(125, print_mode='terse') 516 sage: S = R.change(prec = 15, type='floating-point') 517 sage: a - 1 518 95367431640624 + a + O(5^20) 519 sage: S(a - 1) 520 30517578124 + a + O(5^15) 521 522 :: 523 524 sage: R.<a> = Zq(125, print_mode='terse') 525 sage: S = R.change(prec = 15, type='floating-point') 526 sage: f = S.convert_map_from(R) 527 sage: TestSuite(f).run() 528 """ 529 def _call_(self, x): 530 """ 531 Use the polynomial associated to the element to do the conversion. 532 533 EXAMPLES:: 534 535 sage: S.<x> = ZZ[] 536 sage: W.<w> = Zp(3).extension(x^4 + 9*x^2 + 3*x - 3) 537 sage: z = W.random_element() 538 sage: repr(W.change(print_mode='digits')(z)) 539 '...20112102111011011200001212210222202220100111100200011222122121202100210120010120' 540 """ 541 S = self.codomain() 542 Sbase = S.base_ring() 543 L = x.polynomial().list() 544 if L and not (len(L) == 1 and L[0].is_zero()): 545 return S([Sbase(c) for c in L]) 546 # Inexact zeros need to be handled separately 547 elif isinstance(x.parent(), pAdicExtensionGeneric): 548 return S(0, x.precision_absolute()) 549 else: 550 return S(0) 551 552 def _call_with_args(self, x, args=(), kwds={}): 553 """ 554 Use the polynomial associated to the element to do the conversion, 555 passing arguments along to the codomain. 556 557 EXAMPLES:: 558 559 sage: S.<x> = ZZ[] 560 sage: W.<w> = Zp(3).extension(x^4 + 9*x^2 + 3*x - 3) 561 sage: z = W.random_element() 562 sage: repr(W.change(print_mode='digits')(z, absprec=8)) 563 '...20010120' 564 """ 565 S = self.codomain() 566 Sbase = S.base_ring() 567 L = x.polynomial().list() 568 if L and not (len(L) == 1 and L[0].is_zero()): 569 return S([Sbase(c) for c in L], *args, **kwds) 570 # Inexact zeros need to be handled separately 571 elif isinstance(x.parent(), pAdicExtensionGeneric): 572 if args: 573 if 'absprec' in kwds: 574 raise TypeError("_call_with_args() got multiple values for keyword argument 'absprec'") 575 absprec = args[0] 576 args = args[1:] 577 else: 578 absprec = kwds.pop('absprec',x.precision_absolute()) 579 absprec = min(absprec, x.precision_absolute()) 580 return S(0, absprec, *args, **kwds) 581 else: 582 return S(0, *args, **kwds) -
src/sage/rings/padics/padic_generic_element.pyx
diff --git a/src/sage/rings/padics/padic_generic_element.pyx b/src/sage/rings/padics/padic_generic_element.pyx index 890a846630..6d59043d50 100644
a b cdef class pAdicGenericElement(LocalGenericElement): 1588 1588 p = self.parent().prime() 1589 1589 return Rational(p**self.valuation() * self.unit_part().lift()) 1590 1590 1591 def _number_field_(self, K): 1592 r""" 1593 Return an element of K approximating this p-adic number. 1594 1595 INPUT: 1596 1597 - ``K`` -- a number field 1598 1599 EXAMPLES:: 1600 1601 sage: R.<a> = Zq(125) 1602 sage: K = R.exact_field() 1603 sage: a._number_field_(K) 1604 a 1605 """ 1606 Kbase = K.base_ring() 1607 if K.defining_polynomial() != self.parent().defining_polynomial(exact=True): 1608 # Might convert to K's base ring. 1609 return Kbase(self) 1610 L = [Kbase(c) for c in self.polynomial().list()] 1611 if len(L) < K.degree(): 1612 L += [Kbase(0)] * (K.degree() - len(L)) 1613 return K(L) 1614 1591 1615 def _log_generic(self, aprec, mina=0): 1592 1616 r""" 1593 1617 Return ``\log(self)`` for ``self`` equal to 1 in the residue field … … cdef class pAdicGenericElement(LocalGenericElement): 2043 2067 2044 2068 sage: R = ZpFM(2, prec=5) 2045 2069 sage: R(180).log(p_branch=0) == R(30).log(p_branch=0) + R(6).log(p_branch=0) 2046 False 2070 False 2047 2071 2048 2072 Check that log is the inverse of exp:: 2049 2073 … … cdef class pAdicGenericElement(LocalGenericElement): 2141 2165 - Julian Rueth (2013-02-14): Added doctests, some changes for 2142 2166 capped-absolute implementations. 2143 2167 2144 - Xavier Caruso (2017-06): Added binary splitting type algorithms 2168 - Xavier Caruso (2017-06): Added binary splitting type algorithms 2145 2169 over Qp 2146 2170 2147 2171 """