Skip to content

Commit b7049bf

Browse files
committed
unit group of number field: do not expand product when S is empty
1 parent 0c390a0 commit b7049bf

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/sage/rings/number_field/unit_group.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ def __init__(self, number_field, proof=True, S=None):
305305
sage: tuple(US(K(u)) for u in US.gens()) == US.gens()
306306
True
307307
308+
Bug #36386 (pari stack overflow while expanding units)
309+
sage: d = 12936642
310+
sage: K = QuadraticField(d)
311+
sage: K.unit_group(proof=False)
312+
Unit group with structure C2 x Z of Number Field in a with defining polynomial x^2 - 12936642 with a = 3596.754370262167?
313+
314+
308315
"""
309316
proof = get_flag(proof, "number_field")
310317
K = number_field
@@ -340,20 +347,20 @@ def __init__(self, number_field, proof=True, S=None):
340347
# compute the additional S-unit generators:
341348
if S:
342349
self.__S_unit_data = pK.bnfunits(pS)
350+
# TODO: converting the factored matrix representation of bnfunits into polynomial
351+
# form is a *big* waste of time
352+
su = [pK.nfbasistoalg(pK.nffactorback(z)) for z in self.__S_unit_data[0][0:len(S)]]
353+
su = [K(u, check=False) for u in su]
343354
else:
344-
self.__S_unit_data = pK.bnfunits()
345-
# TODO: converting the factored matrix representation of bnfunits into polynomial
346-
# form is a *big* waste of time
347-
su_fu_tu = [pK.nfbasistoalg(pK.nffactorback(z)) for z in self.__S_unit_data[0]]
348-
349-
self.__nfu = len(pK.bnf_get_fu()) # number of fundamental units
350-
self.__nsu = len(su_fu_tu) - self.__nfu - 1 # number of S-units
351-
self.__ntu = pK.bnf_get_tu()[0] # order of torsion
355+
su = []
356+
357+
self.__nfu = len(fu) # number of fundamental units
358+
self.__nsu = len(su) # number of S-units
359+
self.__ntu = pK.bnf_get_tu()[0] # order of torsion
352360
self.__rank = self.__nfu + self.__nsu
353361

354-
# Move the torsion unit first, then fundamental units then S-units
355-
gens = [K(u, check=False) for u in su_fu_tu]
356-
gens = [gens[-1]] + gens[self.__nsu:-1] + gens[:self.__nsu]
362+
# Put the torsion unit first, then fundamental units then S-units
363+
gens = [K(pK.bnf_get_tu()[1], check=False)] + fu + su
357364

358365
# Construct the abstract group:
359366
gens_orders = tuple([ZZ(self.__ntu)]+[ZZ(0)]*(self.__rank))

0 commit comments

Comments
 (0)