Bug in quadratic_defect

126 views
Skip to first unread message

Przemysław Koprowski

unread,
Mar 23, 2024, 12:05:13 PM3/23/24
to sage-devel

There is a bug in the implementation of quadratic_defect function. It persists over a number of versions of Sage. I have Sage 9.5 and 10.3 beta 4 installed, and the bug is in both versions. Here is a minimal example:

Qx.<x> = QQ[]
K.<t> = NumberField(x^10 - x^8 - 2*x^7 - x^6 + 2*x^5 + 2*x^4 - x^2 + 1)
p = K.prime_factors(2)[0]
pi = K.uniformizer(p)
a = 1 + pi^3
K.quadratic_defect(a,p)

This will throw an exception TypeError: Cannot convert non-integral float to integer

The problem is with the following line in the main loop of this routine:

s = self(q((a - 1) / pi**w)**(1/2))

To make the code work it should be replaced with something like this:

s = self( F.lift((q((a - 1) / pi**w)).sqrt()) )

Best regards,
P.K.

P.S. Besides, if someone decides to correct this function as explained above, I would also suggest to replace the code

# compute uniformizer pi
for g in p.gens():
    if g.valuation(p) == 1:
        pi = g
        break

with just

# compute uniformizer pi
pi = K.uniformizer(p)

Nils Bruin

unread,
Mar 23, 2024, 12:55:50 PM3/23/24
to sage-devel
Thanks! this is now


or


(I'm still a bit murky on what issues are used for)

Dima Pasechnik

unread,
Mar 23, 2024, 2:53:38 PM3/23/24
to sage-...@googlegroups.com
issues are for the cases without an already ready solution, or for something longer term than just one PR

Przemysław Koprowski

unread,
Mar 24, 2024, 7:41:25 AM3/24/24
to sage-devel
Dear Nils,

thanks for preparing the corresponding issue on GitHub. 

Let me just comment on your words "searching the source, this routine isn't actually used elsewhere in sage" (here: https://github.com/sagemath/sage/pull/37657). It is not entirely true, because, as far as I know, the method is_padic_square (in the class of a number field element) internally relies on the quadratic_defect.

BTW, it puzzles me why quadratic_defect is a method of a number field and is_padic_quare of its element. But it is a different story.

Thanks,
P.K.

Nils Bruin

unread,
Mar 24, 2024, 12:02:25 PM3/24/24
to sage-devel
On Sunday 24 March 2024 at 04:41:25 UTC-7 Przemysław Koprowski wrote:
Let me just comment on your words "searching the source, this routine isn't actually used elsewhere in sage" (here: https://github.com/sagemath/sage/pull/37657). It is not entirely true, because, as far as I know, the method is_padic_square (in the class of a number field element) internally relies on the quadratic_defect.

Thanks! I based my assessment on the search result that github returned for `quadratic_defect`. It only returned two hits for me.
Lesson: Don't rely on github search. It's far from exhaustive.

Dima Pasechnik

unread,
Mar 25, 2024, 7:49:50 AM3/25/24
to sage-devel
indeed, entries in src/sage/rings/number_field/number_field.py are just missing in GitHub search. I filed a "feedback".

Reply all
Reply to author
Forward
0 new messages