当前位置: 代码迷 >> python >> 获得基本的判别
  详细解决方案

获得基本的判别

热度:117   发布时间:2023-06-13 16:54:53.0

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

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

我不知道该功能是否在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.")
  相关解决方案