DeRhamComputation/superelliptic.ipynb

34 KiB
Raw Blame History

class superelliptic:
    def __init__(self, f, m, p):
        Rx.<x> = PolynomialRing(GF(p))
        self.polynomial = Rx(f)
        self.exponent = m
        self.characteristic = p
        
    def __repr__(self):
        f = self.polynomial
        m = self.exponent
        p = self.characteristic
        return 'Superelliptic curve with the equation y^' + str(m) + ' = ' + str(f)+' over finite field with ' + str(p) + ' elements.'
    
    def genus(self):
        r = self.polynomial.degree()
        m = self.exponent
        delta = GCD(r, m)
        return 1/2*((r-1)*(m-1) - delta + 1)
    
    def basis_holomorphic_differentials(self, j = 'all'):
        f = self.polynomial
        m = self.exponent
        p = self.characteristic
        r = f.degree()
        delta = GCD(r, m)
        Rxy.<x, y> = PolynomialRing(GF(p), 2)
        Fxy = FractionField(Rxy)
        
        basis = {}
        if j == 'all':
            k = 0
            for j in range(1, m):
                for i in range(1, r):
                    if (r*j - m*i >= delta):
                        basis[k] = superelliptic_form(self, Fxy(x^(i-1)/y^j))
                        k = k+1
            return basis
        else:
            k = 0
            for i in range(1, r):
                if (r*j - m*i >= delta):
                    basis[k] = superelliptic_form(self, Fxy(x^(i-1)/y^j))
                    k = k+1
            return basis
     
    def basis_de_rham(self, j = 'all'):
        f = self.polynomial
        m = self.exponent
        p = self.characteristic
        r = f.degree()
        delta = GCD(r, m)
        Rx.<x> = PolynomialRing(GF(p))
        Rxy.<x, y> = PolynomialRing(GF(p), 2)
        Fxy = FractionField(Rxy)
        basis = {}
        if j == 'all':
            for j in range(1, m):
                holo = C.basis_holomorphic_differentials(j)
                for k in range(0, len(holo)):
                    basis[k] = superelliptic_cech(self, holo[k], superelliptic_function(self, Rx(0))) 
                k = len(basis)
    
                for i in range(1, r):
                    if (r*(m-j) - m*i >= delta):
                        s = Rx(m-j)*Rx(x)*Rx(f.derivative()) - Rx(m)*Rx(i)*f
                        psi = Rx(cut(s, i))
                        basis[k] = superelliptic_cech(self, superelliptic_form(self, Fxy(psi/y^j)), superelliptic_function(self, Fxy(m*y^j/x^i)))
                        k = k+1
            return basis
    
def reduction(C, g):
    p = C.characteristic
    Rxy.<x, y> = PolynomialRing(GF(p), 2)
    Fxy = FractionField(Rxy)
    f = C.polynomial
    r = f.degree()
    m = C.exponent
    g = Fxy(g)
    g1 = g.numerator()
    g2 = g.denominator()
    
    Rx.<x> = PolynomialRing(GF(p))
    Fx = FractionField(Rx)
    FxRy.<y> = PolynomialRing(Fx)    
    (A, B, C) = xgcd(FxRy(g2), FxRy(y^m - f))
    g = FxRy(g1*B/A)
    
    while(g.degree(Rxy(y)) >= m):
        d = g.degree(Rxy(y))
        G = coff(g, d)
        i = floor(d/m)
        g = g - G*y^d + f^i * y^(d%m) *G
    
    return(FxRy(g))

def reduction_form(C, g):
    p = C.characteristic
    Rxy.<x, y> = PolynomialRing(GF(p), 2)
    Fxy = FractionField(Rxy)
    f = C.polynomial
    r = f.degree()
    m = C.exponent
    g = reduction(C, g)

    g1 = RR(0)
    Rx.<x> = PolynomialRing(GF(p))
    Fx = FractionField(Rx)
    FxRy.<y> = PolynomialRing(Fx)
    
    g = FxRy(g)
    for j in range(0, m):
        if j==0:
            G = coff(g, 0)
            g1 += G
        else:
            G = coff(g, j)
            g1 += Fxy(y^(j-m)*f*G)
    return(g1)
        
class superelliptic_function:
    def __init__(self, C, g):
        p = C.characteristic
        Rxy.<x, y> = PolynomialRing(GF(p), 2)
        Fxy = FractionField(Rxy)
        f = C.polynomial
        r = f.degree()
        m = C.exponent
        
        self.curve = C
        g = reduction(C, g)
        self.function = g
        
    def __repr__(self):
        return str(self.function)
    
    def jth_component(self, j):
        g = self.function
        Rxy.<x, y> = PolynomialRing(GF(p), 2)
        g = Rxy(g)
        return g.coefficient(y^j)
    
    def __add__(self, other):
        C = self.curve
        g1 = self.function
        g2 = other.function
        g = reduction(C, g1 + g2)
        return superelliptic_function(C, g)
    
    def __sub__(self, other):
        C = self.curve
        g1 = self.function
        g2 = other.function
        g = reduction(C, g1 - g2)
        return superelliptic_function(C, g)
    
    def __mul__(self, other):
        C = self.curve
        g1 = self.function
        g2 = other.function
        g = reduction(C, g1 * g2)
        return superelliptic_function(C, g)
    
    def __truediv__(self, other):
        C = self.curve
        g1 = self.function
        g2 = other.function
        g = reduction(C, g1 / g2)
        return superelliptic_function(C, g)
    
def diffn(self):
    C = self.curve
    f = C.polynomial
    m = C.exponent
    p = C.characteristic
    g = self.function
    Rxy.<x, y> = PolynomialRing(GF(p), 2)
    Fxy = FractionField(Rxy)
    g = Fxy(g)
    A = g.derivative(x)
    B = g.derivative(y)*f.derivative(x)/(m*y^(m-1))
    return superelliptic_form(C, A+B)
        
class superelliptic_form:
    def __init__(self, C, g):
        p = C.characteristic
        Rxy.<x, y> = PolynomialRing(GF(p), 2)
        Fxy = FractionField(Rxy)
        g = Fxy(reduction_form(C, g))
        self.form = g
        self.curve = C      
        
    def __add__(self, other):
        C = self.curve
        g1 = self.form
        g2 = other.form
        g = reduction(C, g1 + g2)
        return superelliptic_form(C, g)
    
    def __sub__(self, other):
        C = self.curve
        g1 = self.form
        g2 = other.form
        g = reduction(C, g1 - g2)
        return superelliptic_form(C, g)
    
    def __repr__(self):
        g = self.form
        if len(str(g)) == 1:
            return str(g) + ' dx'
        return '('+str(g) + ') dx'
    
    def jth_component(self, j):
        g = self.form
        Rx.<x> = PolynomialRing(GF(p))
        Fx = FractionField(Rx)
        FxRy.<y> = PolynomialRing(Fx)
        Fxy = FractionField(FxRy)
        Ryinv = PolynomialRing(Fx)
        g = Fxy(g)
        g = g(y = 1/y_inv)
        g = Ryinv(g)
        return coff(g, j)
    
    def is_regular_on_U0(self):
        C = self.curve
        p = C.characteristic
        m = C.exponent
        Rx.<x> = PolynomialRing(GF(p))
        for j in range(1, m):
            if self.jth_component(j) not in Rx:
                return 0
        return 1
    
    def is_regular_on_Uinfty(self):
        C = self.curve
        p = C.characteristic
        m = C.exponent
        f = C.polynomial
        r = f.degree()
        delta = GCD(m, r)
        M = m/delta
        R = r/delta
        
        for j in range(1, m):
            A = self.jth_component(j)
            d = degree_of_rational_fctn(A)
            if(-d*M + j*R -(M+1)<0):
                return 0
        return 1
    
    
class superelliptic_cech:
    def __init__(self, C, omega, fct):
        self.omega0 = omega
        self.omega8 = omega - diffn(fct)
        self.f = fct
        self.curve = C
        
    def __add__(self, other):
        C = self.curve
        return superelliptic_cech(C, self.omega0 + other.omega0, self.f + other.f)
    
    def __sub__(self, other):
        C = self.curve
        return superelliptic_cech(C, self.omega0 - other.omega0, self.f - other.f)
    
    def __repr__(self):
        return "(" + str(self.omega0) + ", " + str(self.f) + ", " + str(self.omega8) + ")" 
        
def degree_of_rational_fctn(f):
    Rx.<x> = PolynomialRing(GF(p))
    Fx = FractionField(Rx)
    f = Fx(f)
    f1 = f.numerator()
    f2 = f.denominator()
    d1 = f1.degree()
    d2 = f2.degree()
    return(d1 - d2)

def coff(f, d):
    lista = f.coefficients(sparse = false)
    if len(lista) <= d:
        return 0
    return lista[d]

def cut(f, i):
    R = f.parent()
    coeff = f.coefficients(sparse = false)
    return sum(R(x^(j-i-1)) * coeff[j] for j in range(i+1, f.degree() + 1))
C = superelliptic(x^3 + x + 2, 7, 5)
C.basis_de_rham()
#C.basis_holomorphic_differentials()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-20-d63657cf06e3> in <module>()
      1 C = superelliptic(x**Integer(3) + x + Integer(2), Integer(7), Integer(5))
----> 2 C.basis_de_rham()
      3 #C.basis_holomorphic_differentials()

<ipython-input-19-a65119f7de4f> in basis_de_rham(self, j)
     65                         s = Rx(m-j)*Rx(x)*Rx(f.derivative()) - Rx(m)*Rx(i)*f
     66                         psi = Rx(cut(s, i))
---> 67                         basis[k] = superelliptic_cech(self, superelliptic_form(self, Fxy(psi/y**j)), superelliptic_function(self, Fxy(m*y**j/x**i)))
     68                         k = k+Integer(1)
     69             return basis

<ipython-input-19-a65119f7de4f> in __init__(self, C, g)
    186         Rxy = PolynomialRing(GF(p), Integer(2), names=('x', 'y',)); (x, y,) = Rxy._first_ngens(2)
    187         Fxy = FractionField(Rxy)
--> 188         g = Fxy(reduction_form(C, g))
    189         self.form = g
    190         self.curve = C

<ipython-input-19-a65119f7de4f> in reduction_form(C, g)
    112         if j==Integer(0):
    113             G = coff(g, Integer(0))
--> 114             g1 += G
    115         else:
    116             G = coff(g, j)

/opt/sagemath-9.1/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__add__ (build/cythonized/sage/structure/element.c:10839)()
   1232         # Left and right are Sage elements => use coercion model
   1233         if BOTH_ARE_ELEMENT(cl):
-> 1234             return coercion_model.bin_op(left, right, add)
   1235 
   1236         cdef long value

/opt/sagemath-9.1/local/lib/python3.7/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:11180)()
   1253         # We should really include the underlying error.
   1254         # This causes so much headache.
-> 1255         raise bin_op_exception(op, x, y)
   1256 
   1257     cpdef canonical_coercion(self, x, y):

TypeError: unsupported operand parent(s) for +: 'Real Field with 53 bits of precision' and 'Fraction Field of Univariate Polynomial Ring in x over Finite Field of size 5'
licz = 0
m = 2
p = 5
R1.<x> = PolynomialRing(GF(p))
f = R1(x^3 + x + 4)
r = f.degree()
C = superelliptic(f, m, p)
for i in range(0, r):
    for j in range(1, m):
        omega = superelliptic_form(C, x^i/y^j)
        if (omega.is_regular_on_U0() and omega.is_regular_on_Uinfty()):
            print(omega)
            licz += 1
print(licz, C.genus())
print(C.basis_holomorphic_differentials())
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-7-1009561bb01d> in <module>()
      8 for i in range(Integer(0), r):
      9     for j in range(Integer(1), m):
---> 10         omega = superelliptic_form(C, x**i/y**j)
     11         if (omega.is_regular_on_U0() and omega.is_regular_on_Uinfty()):
     12             print(omega)

NameError: name 'y' is not defined
p = 5
R.<x, y> = PolynomialRing(GF(p), 2)
g = x^6*y^2 + y^2
omega = diffn(superelliptic_function(C, y^2))
omega.jth_component(0)
3*x^2 + 1
R.<x, y> = PolynomialRing(GF(p), 2)
g1 = x^3*y^7 + x^2*y^9
g2 = x^2*y + y^6
R1.<x> = PolynomialRing(GF(p))
R2 = FractionField(R1)
R3.<y> = PolynomialRing(R2)

xgcd(R3(g1), R3(g2))[1]*R3(g1) + xgcd(R3(g1), R3(g2))[2]*R3(g2)
y
H = HyperellipticCurve(x^5 - x + 1)
H
Hyperelliptic Curve over Finite Field of size 5 defined by y^2 = x^5 + 4*x + 1
f = x^3 + x + 2
f.derivative(x)
-2*x^2 + 1
p = 5
R1.<x> = PolynomialRing(GF(p))
R2 = FractionField(R1)
R3.<y> = PolynomialRing(R2)
g = y^2/x + y/(x+1)    
g = 1/y+x/y^2
R3.<z> = PolynomialRing(R2)
g(y = 1/z)
x*z^2 + z
f
x^3 + x + 4
f.coefficient()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-62-e054c182ec1a> in <module>()
----> 1 f.coefficient()

/opt/sagemath-9.1/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4614)()
    485             AttributeError: 'LeftZeroSemigroup_with_category.element_class' object has no attribute 'blah_blah'
    486         """
--> 487         return self.getattr_from_category(name)
    488 
    489     cdef getattr_from_category(self, name):

/opt/sagemath-9.1/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/element.c:4723)()
    498         else:
    499             cls = P._abstract_element_class
--> 500         return getattr_from_other_class(self, cls, name)
    501 
    502     def __dir__(self):

/opt/sagemath-9.1/local/lib/python3.7/site-packages/sage/cpython/getattr.pyx in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2614)()
    392         dummy_error_message.cls = type(self)
    393         dummy_error_message.name = name
--> 394         raise AttributeError(dummy_error_message)
    395     attribute = <object>attr
    396     # Check for a descriptor (__get__ in Python)

AttributeError: 'sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint' object has no attribute 'coefficient'
x^3+x+1
x^3 + x + 1
parent(x)
Symbolic Ring
R.<x> = PolynomialRing(GF(5))
R = (x^3+x).parent()
R.<x, y> = PolynomialRing(GF(5))
RR = FractionField(R)
A = RR(1/(x*y))
A.derivative(x)
(-1)/(x^2*y)