sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.41k stars 474 forks source link

deepcopy() fails for lift_map from residue field of a number field #30499

Open 55f134bc-5e56-491a-9ff0-864540b48904 opened 4 years ago

55f134bc-5e56-491a-9ff0-864540b48904 commented 4 years ago

In sage 9.2 & 9.0 deepcopying the lift_map from a residue field at a prime does not finish because of recursion error

sage: R.<x> = ZZ[]
sage: f = x^2-2
sage: K.<a> = NumberField(f)
sage: P = K(2).factor()[0][0]
sage: F = K.residue_field(P)
sage: m = F.lift_map()
sage: deepcopy(m)

gives

---------------------------------------------------------------------------
RecursionError                            Traceback (most recent call last)
<ipython-input-26-c84bb92e2658> in <module>()
----> 1 deepcopy(m)

/home/sage/sage/local/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
    178                     y = x
    179                 else:
--> 180                     y = _reconstruct(x, memo, *rv)
    181
    182     # If is its own copy, don't memoize.

/home/sage/sage/local/lib/python3.7/copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
    272     if deep and args:
    273         args = (deepcopy(arg, memo) for arg in args)
--> 274     y = func(*args)
    275     if deep:
    276         memo[id(x)] = y

/home/sage/sage/local/lib/python3.7/copy.py in <genexpr>(.0)
    271     deep = memo is not None
    272     if deep and args:
--> 273         args = (deepcopy(arg, memo) for arg in args)
    274     y = func(*args)
    275     if deep:

/home/sage/sage/local/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
    148     copier = _deepcopy_dispatch.get(cls)
    149     if copier:
--> 150         y = copier(x, memo)
    151     else:
    152         try:

/home/sage/sage/local/lib/python3.7/copy.py in _deepcopy_dict(x, memo, deepcopy)
    238     memo[id(x)] = y
    239     for key, value in x.items():
--> 240         y[deepcopy(key, memo)] = deepcopy(value, memo)
    241     return y
    242 d[dict] = _deepcopy_dict

... last 5 frames repeated, from the frame below ...

/home/sage/sage/local/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
    178                     y = x
    179                 else:
--> 180                     y = _reconstruct(x, memo, *rv)
    181
    182     # If is its own copy, don't memoize.

RecursionError: maximum recursion depth exceeded in comparison

and doing the following causes a segfault and crashes Sage

sage: sys.setrecursionlimit(2**30)
sage: deepcopy(m)
{{{

CC: @pjbruin @mjungmath

Component: number theory

Keywords: deepcopy, lift_map

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

mkoeppe commented 4 years ago
comment:1

I don't think the deepcopy protocol is implemented for Sage objects. Most Sage objects are immutable.

mkoeppe commented 3 years ago
comment:4

Moving this ticket to 9.4, as it seems unlikely that it will be merged in 9.3, which is in the release candidate stage

mkoeppe commented 3 years ago

Dependencies: #32478

mkoeppe commented 3 years ago
comment:6

This will be fixed in #32478

mkoeppe commented 3 years ago

Changed dependencies from #32478 to none

mkoeppe commented 3 years ago
comment:7

Replying to @mkoeppe:

This will be fixed in #32478

... actually no