def volcano_schoof(E, volcano_2=True): q = E.base_field().order() residues = [] moduli = [] l = 2 while prod(moduli) <= 4 * sqrt(q): if q % l == 0: l = next_prime(l) res = finding_t_modln(E, l, volcano_2=volcano_2) residues.append(res[0]) moduli.append(res[1]) l = next_prime(l) t = CRT_list(residues, moduli) if t > 2 * sqrt(q): t = t - prod(moduli) return t
def schoof(E, info=False): q = E.base_field().order() residues = [trace_of_frobenius_mod_2(E)] moduli = [2] l = 3 while prod(moduli) <= 4 * sqrt(q): if q % l == 0: l = next_prime(l) residues.append(trace_of_frobenius_mod(E, l)) moduli.append(l) l = next_prime(l) t = CRT_list(residues, moduli) if t > 2 * sqrt(q): t = t - prod(moduli) if info: return t, moduli return t
def project_onto_eigenspace(gamma, ord_basis, hord, weight=2, level=1, epstwist=None, derivative_order=1): ell = 1 level = ZZ(level) R = hord.parent().base_ring() while True: ell = next_prime(ell) if level % ell == 0: continue verbose('Using ell = %s' % ell) T = hecke_matrix_on_ord(ell, ord_basis, weight, level, epstwist) aell = gamma[ell] / gamma[1] verbose('a_ell = %s' % aell) pp = T.charpoly().change_ring(hord.parent().base_ring()) verbose('deg charpoly(T_ell) = %s' % pp.degree()) x = pp.parent().gen() this_is_zero = pp.subs({x: R(aell)}) if this_is_zero.valuation() < 8: # DEBUG this value is arbitrary... verbose( '!!! Should we skip ell = %s (because %s != 0 (val = %s))?????' % (ell, this_is_zero, this_is_zero.valuation())) if pp.derivative(derivative_order).subs({ x: R(aell) }).valuation() >= 8: # DEBUG this value is arbitrary... verbose('pp.derivative(derivative_order).subs({x:R(aell)}) = %s' % pp.derivative().subs({x: R(aell)})) verbose( '... Skipping ell = %s because polynomial has repeated roots' % ell) continue qq = pp.quo_rem((x - R(aell))**ZZ(derivative_order))[0] break qqT = qq(T).apply_map(lambda x: x.lift()) qq_aell = R(qq.subs({x: R(aell)})) ord_basis_small = ord_basis.submatrix(0, 0, ncols=len(hord)) try: ord_basis_small = ord_basis_small.apply_map(lambda x: x.lift()) except AttributeError: pass hord_in_katz = solve_xAb_echelon(ord_basis_small, hord) qT_hord_in_katz = hord_in_katz * qqT qT_hord = qT_hord_in_katz * ord_basis return ell, (qq_aell.lift()**-1 * qT_hord.apply_map(lambda x: x.lift())).change_ring(R)
The authors can be reached at: [email protected] and [email protected]. ==================================================================== """ from sage.all import QQ, prime_range from sage.arith.misc import next_prime, gcd from sage.rings.number_field.number_field import NumberField from sage.rings.polynomial.polynomial_ring import polygen x = polygen(QQ) K = NumberField(x**2 - 11 * 17 * 9011 * 23629, "b") test_cases_true = [(K, int(q), q, False) for q in prime_range(1000)] test_cases_false = [(K, int(q), next_prime(q), True) for q in prime_range(1000)] def test_warmup(): for K, q, p, result in test_cases_true + test_cases_false: qq = (q * K).factor()[0][0] assert qq.is_coprime(p) == (not qq.divides(p)) == result def test_is_coprime(): for K, q, p, result in test_cases_true + test_cases_false: qq = (q * K).factor()[0][0] is_coprime = qq.is_coprime(p) assert is_coprime == result
def Lpvalue(f, g, h, p, prec, N=None, modformsring=False, weightbound=6, eps=None, orthogonal_form=None, magma_args=None, force_computation=False, algorithm='twostage'): if magma_args is None: magma_args = {} if algorithm not in ['twostage', 'threestage']: raise ValueError( 'Algorithm should be one of "twostage" (default) or "threestage"') from sage.interfaces.magma import Magma magma = Magma(**magma_args) ll, mm = g.weight(), h.weight() t = 0 # Assume t = 0 here kk = ll + mm - 2 * (1 + t) # Is this correct? p = ZZ(p) if N is None: N = LCM([ZZ(f.level()), ZZ(g.level()), ZZ(h.level())]) N = N.prime_to_m_part(p) print("Tame level N = %s, prime p = %s" % (N, p)) prec = ZZ(prec) print("Step 1: Compute the Up matrix") computation_name = '%s_%s_%s_%s_%s_%s' % ( p, N, kk, prec, 'triv' if eps is None else 'char', algorithm) tmp_filename = '/tmp/magma_mtx_%s.tmp' % computation_name import os.path from sage.misc.persist import db, db_save try: if force_computation: raise IOError V = db('Lpvalue_Apow_ordbasis_eimat_%s' % computation_name) ord_basis, eimat, zetapm, elldash, mdash = V[:5] Apow_data = V[5:] except IOError: if force_computation or not os.path.exists(tmp_filename): if eps is not None: eps_magma = sage_character_to_magma(eps, magma=magma) Am, zetapm, eimatm, elldash, mdash = magma.UpOperatorData( p, eps_magma, kk, prec, nvals=5) else: Am, zetapm, eimatm, elldash, mdash = magma.UpOperatorData( p, N, kk, prec, nvals=5) print(" ..Converting to Sage...") Amodulus = Am[1, 1].Parent().Modulus().sage() Arows = Am.NumberOfRows().sage() Acols = Am.NumberOfColumns().sage() Emodulus = eimatm[1, 1].Parent().Modulus().sage() Erows = eimatm.NumberOfRows().sage() Ecols = eimatm.NumberOfColumns().sage() magma.eval('F := Open("%s", "w");' % tmp_filename) magma.eval('fprintf F, "Matrix(Zmod(%s),%s, %s, "' % (Amodulus, Arows, Acols)) magma.eval('fprintf F, "%%o", ElementToSequence(%s)' % Am.name()) magma.eval('fprintf F, ") \\n"') magma.eval('fprintf F, "Matrix(Zmod(%s),%s, %s, "' % (Emodulus, Erows, Ecols)) magma.eval('fprintf F, "%%o", ElementToSequence(%s)' % eimatm.name()) magma.eval('fprintf F, ") \\n"') magma.eval('fprintf F, "%%o\\n", %s' % zetapm.name()) magma.eval('fprintf F, "%%o\\n", %s' % elldash.name()) magma.eval('fprintf F, "%%o\\n", %s' % mdash.name()) magma.eval('delete F;') magma.quit() # Read A and eimat from file from sage.structure.sage_object import load from sage.misc.sage_eval import sage_eval with open(tmp_filename, 'r') as fmagma: A = sage_eval(fmagma.readline(), preparse=False) eimat = sage_eval(fmagma.readline(), preparse=False) zetapm = sage_eval(fmagma.readline()) elldash = sage_eval(fmagma.readline()) mdash = sage_eval(fmagma.readline()) print("Step 3b: Apply Up^(r-1) to H") if algorithm == 'twostage': V0 = list(find_Apow_and_ord(A, eimat, p, prec)) else: V0 = list(find_Apow_and_ord_three_stage(A, eimat, p, prec)) ord_basis = V0[0] Apow_data = V0[1:] V = [ord_basis] V.extend([eimat, zetapm, elldash, mdash]) V.extend(Apow_data) db_save(V, 'Lpvalue_Apow_ordbasis_eimat_%s' % computation_name) from posix import remove remove(tmp_filename) print("Step 2: p-depletion, Coleman primitive, and multiply") H = depletion_coleman_multiply(g, h, p, p * elldash, t=0) print("Step 3a: Compute Up(H)") UpH = vector([H(p * n) for n in range(elldash)]) if len(Apow_data) == 1: Hord = compute_ordinary_projection_two_stage(UpH, Apow_data, eimat, elldash) else: Hord = compute_ordinary_projection_three_stage(UpH, [ord_basis] + Apow_data, eimat, elldash) Hord = Hord.change_ring(Apow_data[0].parent().base_ring()) print("Step 4: Project onto f-component") R = Qp(p, prec) if orthogonal_form is None: ell, piHord = project_onto_eigenspace(f, ord_basis, Hord.change_ring(R), kk, N * p, eps) n = 1 while f[n] == 0: n += 1 Lpa = R(piHord[n]) / R(f[n]) else: ell, piHord = project_onto_eigenspace(f, ord_basis, Hord.change_ring(R), kk, N * p, eps, derivative_order=2) gplus, gminus = f, orthogonal_form l1 = 2 while N * p * ell % l1 == 0 or gplus[l1] == 0: l1 = next_prime(l1) proj_mat = matrix([[gplus[l1], gplus[p]], [gminus[l1], gminus[p]]]) Lpalist = (matrix([piHord[l1], piHord[p]]) * proj_mat**-1).list() Lpa = Lpalist[0] if Lpa.valuation() > prec / 2: # this is quite arbitrary! Lpa = Lpalist[1] n = 1 while f[n] == 0: n += 1 Lpa = Lpa / f[n] return Lpa, ell