Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jack4818
GitHub Repository: jack4818/Castryck-Decru-SageMath
Path: blob/main/dead-code/FromProdToJac.sage
323 views
1
def FromProdToJac(C, E, P_c, Q_c, P, Q, a):
2
Fp2 = C.base()
3
R.<x> = PolynomialRing(Fp2)
4
5
P_c2 = 2^(a-1)*P_c
6
Q_c2 = 2^(a-1)*Q_c
7
P2 = 2^(a-1)*P
8
Q2 = 2^(a-1)*Q
9
10
alp1 = P_c2[0]
11
alp2 = Q_c2[0]
12
alp3 = (P_c2 + Q_c2)[0]
13
bet1 = P2[0]
14
bet2 = Q2[0]
15
bet3 = (P2 + Q2)[0]
16
a1 = (alp3 - alp2)^2/(bet3 - bet2) + (alp2 - alp1)^2/(bet2 - bet1) + (alp1 - alp3)^2/(bet1 - bet3)
17
b1 = (bet3 - bet2)^2/(alp3 - alp2) + (bet2 - bet1)^2/(alp2 - alp1) + (bet1 - bet3)^2/(alp1 - alp3)
18
a2 = alp1*(bet3 - bet2) + alp2*(bet1 - bet3) + alp3*(bet2 - bet1)
19
b2 = bet1*(alp3 - alp2) + bet2*(alp1 - alp3) + bet3*(alp2 - alp1)
20
Deltalp = (alp1 - alp2)^2*(alp1 - alp3)^2*(alp2 - alp3)^2
21
Deltbet = (bet1 - bet2)^2*(bet1 - bet3)^2*(bet2 - bet3)^2
22
23
A = Deltbet*a1/a2
24
B = Deltalp*b1/b2
25
26
h = - (A*(alp2 - alp1)*(alp1 - alp3)*x^2 + B*(bet2 - bet1)*(bet1 - bet3))
27
h *= (A*(alp3 - alp2)*(alp2 - alp1)*x^2 + B*(bet3 - bet2)*(bet2 - bet1))
28
h *= (A*(alp1 - alp3)*(alp3 - alp2)*x^2 + B*(bet1 - bet3)*(bet3 - bet2))
29
30
t1 = -(A/B)*b2/b1
31
t2 = (bet1*(bet3 - bet2)^2/(alp3 - alp2) + bet2*(bet1 - bet3)^2/(alp1 - alp3) + bet3*(bet2 - bet1)^2/(alp2 - alp1))/b1
32
s1 = -(B/A)*a2/a1
33
s2 = (alp1*(alp3 - alp2)^2/(bet3 - bet2) + alp2*(alp1 - alp3)^2/(bet1 - bet3) + alp3*(alp2 - alp1)^2/(bet2 - bet1))/a1
34
35
"""
36
We cannot do multivariate function fields,
37
so I followed
38
39
https://ask.sagemath.org/question/37584/multivariate-rational-function-field-of-rank-3-over-rational-field/
40
41
To create a rational function field from a polynomial ring
42
"""
43
Uff_poly.<u0, u1, v0, v1> = PolynomialRing(Fp2, 4)
44
Uff = Uff_poly.fraction_field()
45
Uff.inject_variables()
46
47
A4.<U0, U1, V0, V1> = AffineSpace(Fp2, 4)
48
# U.<U0, U1, V0, V1> = PolynomialRing(Fp2, 4)
49
U = U0.parent()
50
51
u0tilde = 1/u0
52
u1tilde = u1/u0
53
v0tilde = (u1*v0 - u0*v1)/u0^2
54
v1tilde = (u1^2*v0 - u0*v0 - u0*u1*v1)/u0^2
55
56
lamb1 = - ((Deltbet/A^3)*v1tilde)/(s1*u1tilde)
57
lamb2 = - ((Deltalp/B^3)*v1)/(t1*u1)
58
59
x1 = lamb1^2 + alp1 + alp2 + alp3 - s1*(u1tilde^2 - 2*u0tilde) - 2*s2
60
y1 = -lamb1*(x1 - s2 + (u0tilde*v1tilde - u1tilde*v0tilde)*s1/v1tilde)
61
62
x2 = lamb2^2 + bet1 + bet2 + bet3 - t1*(u1^2 - 2*u0) - 2*t2
63
y2 = -lamb2*(x2 - t2 + (u0*v1 - u1*v0)*t1/v1)
64
65
eq1 = U((x1 - P_c[0]).numerator())
66
eq2 = U((y1 - P_c[1]).numerator())
67
eq3 = U((x2 - P[0]).numerator())
68
eq4 = U((y2 - P[1]).numerator())
69
70
eq5 = 2*V0^2 - 2*V0*V1*U1 + V1^2*(U1^2 - 2*U0)
71
eq5 -= 2*Coefficient(h, 0)
72
eq5 -= (-U1)*Coefficient(h, 1)
73
eq5 -= (U1^2 - 2*U0)*Coefficient(h, 2)
74
eq5 -= (-U1^3 + 3*U0*U1)*Coefficient(h, 3)
75
eq5 -= (U1^4 - 4*U1^2*U0 + 2*U0^2)*Coefficient(h, 4)
76
eq5 -= (-U1^5 + 5*U1^3*U0 - 5*U1*U0^2)*Coefficient(h, 5)
77
eq5 -= (U1^6 - 6*U1^4*U0 + 9*U1^2*U0^2 - 2*U0^3)*Coefficient(h, 6)
78
79
# UP TO HERE
80
# Find a way to quickly find solutions!!
81
82
V = A4.subscheme([eq1, eq2, eq3, eq4, eq5])
83
84
# # point with zero coordinates probably correspond to "extra" solutions, we should be left with 4 sols
85
# # (code may fail over small fields)
86
87
# from sage.matrix.matrix2 import Matrix
88
# def resultant(f1, f2, var):
89
# return Matrix.determinant(f1.sylvester_matrix(f2, var))
90
91
# tmp1 = resultant(eq3, eq4, U0)
92
# print(tmp1)
93
# tmp2 = resultant(tmp1, eq5, V0)
94
# print(tmp2)
95
# tmp3 = resultant(tmp2, eq1, V0)
96
# print(tmp3)
97
# tmp4 = resultant(tmp3, eq2, V1)
98
# print(tmp4)
99
100
realsols = []
101
for D in V.rational_points():
102
print(D)
103
Dseq = list(D)
104
if not 0 in Dseq:
105
realsols.append(Dseq)
106
107
print(f"Number of inverse images found: {len(realsols)} (hopefully 4)")
108
109
return False, False, False, False, False
110
# TODO below (similar to above)
111
112
J = Jacobian(HyperellipticCurve(h))
113
sol = choice(realsols)
114
D = J(x^2 + sol[1]*x + sol[0], sol[3]*x + sol[2])
115
imPcP = 2*D
116
117
# now for (Q_c, Q)
118
119
eq1 = U(Numerator(x1 - Q_c[0]))
120
eq2 = U(Numerator(y1 - Q_c[1]))
121
eq3 = U(Numerator(x2 - Q[0]))
122
eq4 = U(Numerator(y2 - Q[1]))
123
124
V = A4.subscheme([eq1, eq2, eq3, eq4, eq5])
125
realsols = []
126
for D in V.rational_points():
127
print(D)
128
Dseq = list(D)
129
if not 0 in Dseq:
130
realsols.append(Dseq)
131
132
print(f"Number of inverse images found: {len(realsols)} (hopefully 4)")
133
sol = choice(realsols)
134
D = J(x^2 + sol[1]*x + sol[0], sol[3]*x + sol[2])
135
imQcQ = 2*D
136
137
return h, imPcP[0], imPcP[1], imQcQ[0], imQcQ[1]
138