Computing N for Hyperelliptic curve

533 days ago by wstein

def N(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 Next step - '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 """ #check if not p.is_prime(): return 'p must be prime' f,h = E.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' g=derivative(f(x),x) R=g.resultant(f) if R == 0: return 'f(x) has repeated roots, so it is not smooth' # redefining f, because sage has trouble taking derivative over Fq Fq=GF(p^b,'a'); C=E.change_ring(Fq) f,h = C.hyperelliptic_polynomials() F = f^((p-1)/2) #coefficients returns a_0, ... , a_n where f(x) = a_n x^n + ... + a_0 C = F.list() g = E.genus() Mall=[] for k in range(g): Mk=[]; a=p^k for j in range(1,g+1): H=Sequence([(C[i])^a for i in range((p*j-1-g), (p*j-1))]) H.reverse() Mk.append(H); Mall.append(matrix(Fq,Mk)); MS1= MatrixSpace(Fq,g) N = MS1.identity_matrix() for l in Mall: N=N*l; return N; 
       
P.<x>=QQ[]; E=HyperellipticCurve(x^11+x+1,0) timeit('N(E,13,1)') 
       
5 loops, best of 3: 4.26 ms per loop
5 loops, best of 3: 4.26 ms per loop
N(E,7,3) 
       
[2 0 1 2 2]
[4 5 4 1 1]
[0 0 0 0 0]
[2 0 1 2 2]
[1 0 2 2 2]
[2 0 1 2 2]
[4 5 4 1 1]
[0 0 0 0 0]
[2 0 1 2 2]
[1 0 2 2 2]
P.<x>=GF(7)[] 
       
f = x^3 + x +1 
       
f.derivative() 
       
3*x^2 + 1
3*x^2 + 1
var('x') 
       
x
x
derivative(f, x) 
       
Traceback (click to the left of this block for traceback)
...
ValueError: cannot differentiate with respect to x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_10.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZGVyaXZhdGl2ZShmLCB4KQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpf2qPp6/___code___.py", line 2, in <module>
    exec compile(u'derivative(f, x)
  File "", line 1, in <module>
    
  File "/home/sage/sage_install/sage-4.6/local/lib/python2.6/site-packages/sage/calculus/functional.py", line 130, in derivative
    return f.derivative(*args, **kwds)
  File "polynomial_element.pyx", line 2232, in sage.rings.polynomial.polynomial_element.Polynomial.derivative (sage/rings/polynomial/polynomial_element.c:17755)
  File "derivative.pyx", line 216, in sage.misc.derivative.multi_derivative (sage/misc/derivative.c:2203)
  File "polynomial_template.pxi", line 817, in sage.rings.polynomial.polynomial_zmod_flint.Polynomial_template._derivative (sage/rings/polynomial/polynomial_zmod_flint.c:10343)
ValueError: cannot differentiate with respect to x