Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获得基本判别式_Python_Sage - Fatal编程技术网

Python 获得基本判别式

Python 获得基本判别式,python,sage,Python,Sage,Sage中是否有函数返回与给定判别式相关的基本判别式 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{

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

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

这是我编写的函数,没有找到现有函数:

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

我不知道这个函数是否用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.")

基本判别法有什么问题

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

谢谢我还编写了一个自己的实现,因为我在最初的几个小时里没有得到答案。我将把它添加到我的问题中。a//b是否表示楼层(a/b)?@主要理想域——确切地说:在Python中,
a//b
是“商和余数”除法中的商,
a%b
是余数。在Sage中,一个人可以同时用
quo_-rem
,例如
23。quo_-rem(7)
给出
(3,2)
,实际上
23=3*7+2
。我认为没有问题。谢谢你提到这个方法。