问题描述
Sage中是否有一个函数可以返回与给定判别式相关的基本判别式?
参见
这是我编写的函数,没有找到现有的函数:
def getFund(D):
if D % 4 == 2 or D % 4 == 3:
raise ValueError("Not a discriminant.")
if D == 0:
raise ValueError("There is no fundamental associated to 0.")
P = sign(D)
for p in factor(D):
if p[1] % 2 == 1:
P *= p[0]
if P % 4 == 2 or P % 4 == 3:
P *= 4
return P
1楼
basic_discriminant有什么问题?
sage: fundamental_discriminant(1)
1
sage: fundamental_discriminant(3)
12
sage: fundamental_discriminant?
Signature: fundamental_discriminant(D)
Docstring:
Return the discriminant of the quadratic extension K=Q(sqrt{D}),
i.e. an integer d congruent to either 0 or 1, mod 4, and such that,
at most, the only square dividing it is 4.
INPUT:
* "D" - an integer
OUTPUT:
* an integer, the fundamental discriminant
2楼
我不知道该功能是否在SageMath中实现。
但是,如果我正确理解了定义,则可以按以下方式定义函数:
def fundamental_discriminant(d):
if d % 4 == 1:
return d.squarefree_part()
if d % 4 == 0:
k = d.valuation(4)
dd = d // 4^k
if dd % 4 == 1:
return dd.squarefree_part()
if dd % 4 == 2:
return 4 * dd.squarefree_part()
if dd % 4 == 3:
return 4 * dd.squarefree_part()
raise ValueError("Not a discriminant.")