获得基本的判别力

问题描述 投票:1回答:2

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
python sage
2个回答
1
投票

基本判别有什么问题?

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

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.")
© www.soinside.com 2019 - 2024. All rights reserved.