Skip to content

Infinite loop in conversion of p-adics #28555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xcaruso opened this issue Oct 4, 2019 · 3 comments · Fixed by #39583
Closed

Infinite loop in conversion of p-adics #28555

xcaruso opened this issue Oct 4, 2019 · 3 comments · Fixed by #39583

Comments

@xcaruso
Copy link
Contributor

xcaruso commented Oct 4, 2019

Here is the bug:

sage: A.<a> = Qq(5^2)
sage: a in A.base_ring()
Traceback (most recent call last):
...
RecursionError: maximum recursion depth exceeded in comparison

CC: @roed314

Component: padics

Issue created by migration from https://trac.sagemath.org/ticket/28555

@xcaruso xcaruso added this to the sage-9.0 milestone Oct 4, 2019
@embray
Copy link
Contributor

embray commented Jan 6, 2020

comment:1

Ticket retargeted after milestone closed

@embray embray modified the milestones: sage-9.0, sage-9.1 Jan 6, 2020
@mkoeppe
Copy link
Contributor

mkoeppe commented May 1, 2020

comment:2

Moving tickets to milestone sage-9.2 based on a review of last modification date, branch status, and severity.

@mkoeppe mkoeppe modified the milestones: sage-9.1, sage-9.2 May 1, 2020
@mkoeppe mkoeppe modified the milestones: sage-9.2, sage-9.3 Oct 24, 2020
@mkoeppe
Copy link
Contributor

mkoeppe commented May 10, 2021

comment:4

Moving to 9.4, as 9.3 has been released.

@mkoeppe mkoeppe modified the milestones: sage-9.3, sage-9.4 May 10, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Aug 22, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 18, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 May 3, 2022
@mkoeppe mkoeppe modified the milestones: sage-9.7, sage-9.8 Sep 19, 2022
@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
vbraun pushed a commit to vbraun/sage that referenced this issue May 11, 2025
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
vbraun pushed a commit to vbraun/sage that referenced this issue May 17, 2025
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
@vbraun vbraun closed this as completed in 6560925 May 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy