Path: blob/main/dead-code/FromProdToJac.sage
323 views
def FromProdToJac(C, E, P_c, Q_c, P, Q, a):1Fp2 = C.base()2R.<x> = PolynomialRing(Fp2)34P_c2 = 2^(a-1)*P_c5Q_c2 = 2^(a-1)*Q_c6P2 = 2^(a-1)*P7Q2 = 2^(a-1)*Q89alp1 = P_c2[0]10alp2 = Q_c2[0]11alp3 = (P_c2 + Q_c2)[0]12bet1 = P2[0]13bet2 = Q2[0]14bet3 = (P2 + Q2)[0]15a1 = (alp3 - alp2)^2/(bet3 - bet2) + (alp2 - alp1)^2/(bet2 - bet1) + (alp1 - alp3)^2/(bet1 - bet3)16b1 = (bet3 - bet2)^2/(alp3 - alp2) + (bet2 - bet1)^2/(alp2 - alp1) + (bet1 - bet3)^2/(alp1 - alp3)17a2 = alp1*(bet3 - bet2) + alp2*(bet1 - bet3) + alp3*(bet2 - bet1)18b2 = bet1*(alp3 - alp2) + bet2*(alp1 - alp3) + bet3*(alp2 - alp1)19Deltalp = (alp1 - alp2)^2*(alp1 - alp3)^2*(alp2 - alp3)^220Deltbet = (bet1 - bet2)^2*(bet1 - bet3)^2*(bet2 - bet3)^22122A = Deltbet*a1/a223B = Deltalp*b1/b22425h = - (A*(alp2 - alp1)*(alp1 - alp3)*x^2 + B*(bet2 - bet1)*(bet1 - bet3))26h *= (A*(alp3 - alp2)*(alp2 - alp1)*x^2 + B*(bet3 - bet2)*(bet2 - bet1))27h *= (A*(alp1 - alp3)*(alp3 - alp2)*x^2 + B*(bet1 - bet3)*(bet3 - bet2))2829t1 = -(A/B)*b2/b130t2 = (bet1*(bet3 - bet2)^2/(alp3 - alp2) + bet2*(bet1 - bet3)^2/(alp1 - alp3) + bet3*(bet2 - bet1)^2/(alp2 - alp1))/b131s1 = -(B/A)*a2/a132s2 = (alp1*(alp3 - alp2)^2/(bet3 - bet2) + alp2*(alp1 - alp3)^2/(bet1 - bet3) + alp3*(alp2 - alp1)^2/(bet2 - bet1))/a13334"""35We cannot do multivariate function fields,36so I followed3738https://ask.sagemath.org/question/37584/multivariate-rational-function-field-of-rank-3-over-rational-field/3940To create a rational function field from a polynomial ring41"""42Uff_poly.<u0, u1, v0, v1> = PolynomialRing(Fp2, 4)43Uff = Uff_poly.fraction_field()44Uff.inject_variables()4546A4.<U0, U1, V0, V1> = AffineSpace(Fp2, 4)47# U.<U0, U1, V0, V1> = PolynomialRing(Fp2, 4)48U = U0.parent()4950u0tilde = 1/u051u1tilde = u1/u052v0tilde = (u1*v0 - u0*v1)/u0^253v1tilde = (u1^2*v0 - u0*v0 - u0*u1*v1)/u0^25455lamb1 = - ((Deltbet/A^3)*v1tilde)/(s1*u1tilde)56lamb2 = - ((Deltalp/B^3)*v1)/(t1*u1)5758x1 = lamb1^2 + alp1 + alp2 + alp3 - s1*(u1tilde^2 - 2*u0tilde) - 2*s259y1 = -lamb1*(x1 - s2 + (u0tilde*v1tilde - u1tilde*v0tilde)*s1/v1tilde)6061x2 = lamb2^2 + bet1 + bet2 + bet3 - t1*(u1^2 - 2*u0) - 2*t262y2 = -lamb2*(x2 - t2 + (u0*v1 - u1*v0)*t1/v1)6364eq1 = U((x1 - P_c[0]).numerator())65eq2 = U((y1 - P_c[1]).numerator())66eq3 = U((x2 - P[0]).numerator())67eq4 = U((y2 - P[1]).numerator())6869eq5 = 2*V0^2 - 2*V0*V1*U1 + V1^2*(U1^2 - 2*U0)70eq5 -= 2*Coefficient(h, 0)71eq5 -= (-U1)*Coefficient(h, 1)72eq5 -= (U1^2 - 2*U0)*Coefficient(h, 2)73eq5 -= (-U1^3 + 3*U0*U1)*Coefficient(h, 3)74eq5 -= (U1^4 - 4*U1^2*U0 + 2*U0^2)*Coefficient(h, 4)75eq5 -= (-U1^5 + 5*U1^3*U0 - 5*U1*U0^2)*Coefficient(h, 5)76eq5 -= (U1^6 - 6*U1^4*U0 + 9*U1^2*U0^2 - 2*U0^3)*Coefficient(h, 6)7778# UP TO HERE79# Find a way to quickly find solutions!!8081V = A4.subscheme([eq1, eq2, eq3, eq4, eq5])8283# # point with zero coordinates probably correspond to "extra" solutions, we should be left with 4 sols84# # (code may fail over small fields)8586# from sage.matrix.matrix2 import Matrix87# def resultant(f1, f2, var):88# return Matrix.determinant(f1.sylvester_matrix(f2, var))8990# tmp1 = resultant(eq3, eq4, U0)91# print(tmp1)92# tmp2 = resultant(tmp1, eq5, V0)93# print(tmp2)94# tmp3 = resultant(tmp2, eq1, V0)95# print(tmp3)96# tmp4 = resultant(tmp3, eq2, V1)97# print(tmp4)9899realsols = []100for D in V.rational_points():101print(D)102Dseq = list(D)103if not 0 in Dseq:104realsols.append(Dseq)105106print(f"Number of inverse images found: {len(realsols)} (hopefully 4)")107108return False, False, False, False, False109# TODO below (similar to above)110111J = Jacobian(HyperellipticCurve(h))112sol = choice(realsols)113D = J(x^2 + sol[1]*x + sol[0], sol[3]*x + sol[2])114imPcP = 2*D115116# now for (Q_c, Q)117118eq1 = U(Numerator(x1 - Q_c[0]))119eq2 = U(Numerator(y1 - Q_c[1]))120eq3 = U(Numerator(x2 - Q[0]))121eq4 = U(Numerator(y2 - Q[1]))122123V = A4.subscheme([eq1, eq2, eq3, eq4, eq5])124realsols = []125for D in V.rational_points():126print(D)127Dseq = list(D)128if not 0 in Dseq:129realsols.append(Dseq)130131print(f"Number of inverse images found: {len(realsols)} (hopefully 4)")132sol = choice(realsols)133D = J(x^2 + sol[1]*x + sol[0], sol[3]*x + sol[2])134imQcQ = 2*D135136return h, imPcP[0], imPcP[1], imQcQ[0], imQcQ[1]137138