获得基本的判别力

时间:2015-10-21 19:50:33

标签: python sage

Sage中是否有一个函数返回与给定判别式相关的基本判别式?

请参阅https://en.wikipedia.org/wiki/Fundamental_discriminant

这是我写的功能,而不是找到现有的功能:

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

我不知道该功能是否在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.")