{{{id=1| %python @cached_function def Cartier_matrix(E): r""" INPUT: - ``E`` -- Hyperelliptic Curve of the form $y^2 = f(x)$, defined over $F_q$, where q is a prime power OUTPUT: - ``Cartier-Manin matrix`` -- The matrix with entries $M_{ij} = (c_{pi-j}), f(x)^{(p-1)/2} = \sum c_{i x^i}$ """ #check primality of p - function not valid for p=2 try: p.is_prime(): except ValueError: print "p must be prime"; try: p == 2: except ValueError: return "in this implementation, the characteristic p must be odd"; Fq=FiniteField(p**b,name='a'); g = E.genus() #change elliptic curve to be defined over Fq Fq = FiniteField(p**b,name='a') C = E.change_ring(Fq) g = C.genus() f,h = C.hyperelliptic_polynomials() if h != 0: return 'E must be of the form y^2 = f(x)' #check degree d = f.degree() if d%2 == 0: return 'error: the degree of f is even' #check smoothness df = f.derivative() R = df.resultant(f) if R == 0: return 'error: f(x) is not smooth' F = f**((p-1)/2) #coeff: creates a list of the coefficients of F: a_0, ... , a_n #where F = a_n x^n + ... + a_0 coeff = F.list() #inserting zeros when necessary-- that is, when deg(F) < p*g-1, #which is the highest powered coefficient needed for our matrix zeros = [0 for i in range(p*g-len(coeff))] coeff = coeff + zeros M = []; for i in range(1,g+1): H = [(coeff[j]) for j in range( p*i-1, p*i-g-1, -1)] M.append(H); return M /// }}} {{{id=17| %python def Hasse_Witt(E,p,b): r""" INPUT: - 'E' - Hyperelliptic Curve of the form y^2 = f(x), defined over Q[x] - 'p' - a prime number, q = p^b; E will be redefined over the finite field of order q - 'b' - q = p^b OUTPUT: - 'Hasse-Witt matrix' - """ #check primality and form of elliptic curve if not p.is_prime(): return 'p must be prime' if p == 2: return 'p must be odd' #change elliptic curve to be defined over Fq Fq = FiniteField(p**b,name='a') C = E.change_ring(Fq) g = C.genus() f,h = C.hyperelliptic_polynomials() if h != 0: return 'E must be of the form y^2 = f(x)' #check degree d = f.degree() if d%2 == 0: return 'error: the degree of f is even' #check smoothness df = f.derivative() R = df.resultant(f) if R == 0: return 'error: f(x) is not smooth' F = f**((p-1)/2) #coeff: creates a list of the coefficients of F: a_0, ... , a_n #where F = a_n x^n + ... + a_0 coeff = F.list() #inserting zeros when necessary-- that is, when deg(F) < p*g-1, #which is the highest powered coefficient needed for our matrix zeros = [0 for i in range(p*g-len(coeff))] coeff = coeff + zeros Mall = [] for k in range(g): Mk = []; a = p**k for i in range(1,g+1): H = [(coeff[j])**a for j in range( p*i-1, p*i-g-1, -1)] Mk.append(H); Mall.append(matrix(Fq,Mk)); #multiply all of the Mk matrices together to get the matrix N N = identity_matrix(Fq,g) for l in Mall: N = N*l; return N /// }}} {{{id=2| P.=QQ[]; E = HyperellipticCurve(x^11+x+1,0); E2 = HyperellipticCurve(x^23-x,0); E3 = HyperellipticCurve(x^51-x,0); /// }}} {{{id=24| %python @cached_function def Cartier_matrix_Aly(E,p,b): r""" INPUT: - 'E' - Hyperelliptic Curve of the form y^2 = f(x) - 'p' - a prime number - 'b' - q=p^b OUTPUT: - 'M' The matrix M = (c_(pi-j)), f(x)^((p-1)/2) = \sum c_i x^i """ #checks if not p.is_prime(): return 'p must be prime' Fq=FiniteField(p**b,name='a'); g = E.genus() if p < 2*g-1: return 'that weird error' C=E.change_ring(Fq) f,h = C.hyperelliptic_polynomials() if h != 0: return 'E must be of the form y^2 = f(x)' d = f.degree() if d%2 == 0: return 'the degree of f is even' df=f.derivative() R=df.resultant(f) if R == 0: return 'so curve is not smooth' F = f**((p-1)/2) #coefficients returns a_0, ... , a_n where f(x) = a_n x^n + ... + a_0 Coeff = F.list() M=[]; for j in range(1,g+1): H=[Coeff[i] for i in range((p*j-g), (p*j))] H.reverse() M.append(H); return matrix(Fq,M), Coeff, g /// }}} {{{id=16| %hide %python def Hasse_Vitt(E,p,b): r""" INPUT: - 'M'- Cartier matrix. - 'g' -genus - 'p' -over the field of char p - 'b' - power of p, Fq, OUTPUT: - 'N' - The matrix N = M M^(p)...M^(p^(g-1)) where M = (c_(pi-j)), f(x)^((p-1)/2) = \sum c_i x^i """ #Call the Cartier_matrix command to compute M coeff,M = Cartier_matrix(E,p,b) print coeff print M g = E.genus(); from sage.matrix.constructor import matrix Fq = FiniteField(p**b,name='c'); def frob_mat(Coeffs, k): a = p**k mat = [] Coeffs_pow = [c**a for c in Coeffs] for i in range(1,g+1): H = [(Coeffs_pow[j]) for j in range(p*i-1, p*i-g-1, -1)] mat.append(H); return matrix(Fq,mat) Mall = [M] + [frob_mat(coeff,k) for k in range(1,g)] #multiply to create the identity matrix N = identity_matrix(Fq,g) for l in Mall: N = N*l; return N /// }}} {{{id=23| Cartier_matrix_Aly(E,13,1) /// ( [ 4 6 0 0 0] [ 8 12 8 2 0] [ 0 0 7 8 8] [ 0 0 0 0 0] [ 0 0 0 0 0], [1, 6, 2, 7, 2, 6, 1, 0, 0, 0, 0, 6, 4, 8, 8, 4, 6, 0, 0, 0, 0, 0, 2, 8, 12, 8, 2, 0, 0, 0, 0, 0, 0, 7, 8, 8, 7, 0, 0, 0, 0, 0, 0, 0, 2, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 5 ) }}} {{{id=26| timeit('Cartier_matrix_Aly(E2,7,1)') /// 625 loops, best of 3: 840 µs per loop }}} {{{id=27| timeit('Cartier_matrix(E2,7,1)') /// 125 loops, best of 3: 2.95 ms per loop }}} {{{id=28| E32 = HyperellipticCurve(x^51-x,0) /// }}} {{{id=29| Cartier_matrix(E2,7,1) /// [[0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]] }}} {{{id=30| timeit('Cartier_matrix_Aly(E3,7,1)') timeit('Cartier_matrix(E32,7,1)') /// 625 loops, best of 3: 897 µs per loop 625 loops, best of 3: 894 µs per loop }}} {{{id=31| Fq = FiniteField(3^2,name='a') /// }}} {{{id=32| Fq.base_ring /// }}} {{{id=33| E6 = HyperellipticCurve(a^11+a-1,0) /// Traceback (most recent call last): File "", line 1, in File "_sage_input_6.py", line 10, in exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("RTYgPSBIeXBlcmVsbGlwdGljQ3VydmUoYV4xMSthLTEsMCk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in File "/tmp/tmpPzovvG/___code___.py", line 3, in exec compile(u'E6 = HyperellipticCurve(a**_sage_const_11 +a-_sage_const_1 ,_sage_const_0 )' + '\n', '', 'single') File "", line 1, in NameError: name 'a' is not defined }}} {{{id=34| /// }}}