Skip to content

Commit d28b2ec

Browse files
author
Release Manager
committed
sagemathgh-39583: Handle various extension degrees in pAdicGenericElement initialisation I have looked into bug sagemath#28555. I have been able to reproduce it with version 10.6.beta7. It turns out the infinite loop can be reproduced with: ``` sage: A.<a> = Qq(5^2) sage: A.base_ring()(a) ``` But the following also triggers the bug: `A.base_ring()(A(1))`. This is bug sagemath#33527. The culprit is in the file `src/sage/rings/padics/padic_template_element.pxi`. Calling `A.base_ring()(a)` will call `pAdicTemplateElement.__init__` which will call `A.base_ring()(a)` again on line 140. To fix it, I added a check for when the degree of the polynomial (over the base ring $\mathbb Z_p$ or $\mathbb Q_p$) defining the element is greater than one. If we were trying to convert to the base ring, I raise a `TypeError` exception. Else, I raise a `NotImplementedError` exception (this is the case when one tries to convert between two extensions, it should be implemented later, but here I only fix the bug). Finally, I change line 140 from `x = self.base_ring()(x)` to `x = self.base_ring()(x.polynomial().constant_coefficient())` to avoid the infinite loop. NOTE: this is my "hello world" PR, I may have broken something with this, please be kind. Please do not hesitate to tell me how to do better. Fixes sagemath#28555. Fixes sagemath#33527. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> None URL: sagemath#39583 Reported by: Rubén Muñoz--Bertrand Reviewer(s): Julian Rüth, roed314, Rubén Muñoz--Bertrand
2 parents 94baf41 + 9694163 commit d28b2ec

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/sage/rings/padics/padic_template_element.pxi

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,23 @@ cdef class pAdicTemplateElement(pAdicGenericElement):
116116
Traceback (most recent call last):
117117
...
118118
TypeError: no conversion between padics when prime numbers differ
119+
120+
Check that bug :issue:`28555` is fixed::
121+
122+
sage: A.<a> = Qq(5^2)
123+
sage: A.base_ring()(A(1))
124+
1 + O(5^20)
125+
sage: A.base_ring()(a)
126+
Traceback (most recent call last):
127+
...
128+
TypeError: element in a proper extension
129+
130+
Check that bug :issue:`33527` is fixed::
131+
132+
sage: K = Qq(25, names='a')
133+
sage: K0 = K.base_ring()
134+
sage: K0(K(1))
135+
1 + O(5^20)
119136
"""
120137
self.prime_pow = <PowComputer_?>parent.prime_pow
121138
pAdicGenericElement.__init__(self, parent)
@@ -137,7 +154,11 @@ cdef class pAdicTemplateElement(pAdicGenericElement):
137154
if x.parent().modulus().change_ring(self.base_ring()) == self.parent().modulus():
138155
x = x.polynomial().change_ring(self.base_ring()).list()
139156
else:
140-
x = self.base_ring()(x)
157+
if x.polynomial().degree() >= 1:
158+
if self.parent() is x.parent().base_ring():
159+
raise TypeError("element in a proper extension")
160+
raise NotImplementedError("conversion between different p-adic extensions not implemented")
161+
x = self.base_ring()(x.polynomial().constant_coefficient())
141162
if x.is_zero():
142163
absprec = min(absprec, x.precision_absolute()*self.prime_pow.e)
143164
x = []

0 commit comments

Comments
 (0)