Ryan Rueger

ryan@rueg.re / picture / key / home
aboutsummaryrefslogtreecommitdiffhomepage
path: root/theta_lib/isogenies_dim2
diff options
context:
space:
mode:
Diffstat (limited to 'theta_lib/isogenies_dim2')
-rw-r--r--theta_lib/isogenies_dim2/gluing_isogeny_dim2.py292
-rw-r--r--theta_lib/isogenies_dim2/isogeny_chain_dim2.py178
-rw-r--r--theta_lib/isogenies_dim2/isogeny_dim2.py229
3 files changed, 0 insertions, 699 deletions
diff --git a/theta_lib/isogenies_dim2/gluing_isogeny_dim2.py b/theta_lib/isogenies_dim2/gluing_isogeny_dim2.py
deleted file mode 100644
index 2dac387..0000000
--- a/theta_lib/isogenies_dim2/gluing_isogeny_dim2.py
+++ /dev/null
@@ -1,292 +0,0 @@
-"""
-This code is based on a copy of:
-https://github.com/ThetaIsogenies/two-isogenies
-
-MIT License
-
-Copyright (c) 2023 Pierrick Dartois, Luciano Maino, Giacomo Pope and Damien Robert
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-"""
-
-from sage.all import *
-from ..theta_structures.Tuple_point import TuplePoint
-from ..theta_structures.Theta_dim2 import ThetaStructureDim2, ThetaPointDim2
-from ..theta_structures.theta_helpers_dim2 import batch_inversion
-from ..basis_change.base_change_dim2 import montgomery_to_theta_matrix_dim2, apply_base_change_theta_dim2
-from ..theta_structures.montgomery_theta import lift_kummer_montgomery_point
-
-class GluingThetaIsogenyDim2:
- """
- Compute the gluing isogeny from E1 x E2 (Elliptic Product) -> A (Theta Model)
-
- Expected input:
-
- - (K1_8, K2_8) The 8-torsion above the kernel generating the isogeny
- - M (Optional) a base change matrix, if this is not including, it can
- be derived from [2](K1_8, K2_8)
- """
-
- def __init__(self, K1_8, K2_8, Theta12, N):
- # Double points to get four-torsion, we always need one of these, used
- # for the image computations but we'll need both if we wish to derived
- # the base change matrix as well
- K1_4 = 2*K1_8
-
- # Initalise self
- # This is the base change matrix for product Theta coordinates (not used, except in the dual)
- self._base_change_matrix_theta = N
- # Here, base change matrix directly applied to the Montgomery coordinates. null_point_bc is the
- # theta null point obtained after applying the base change to the product Theta-structure.
- self._base_change_matrix, null_point_bc = montgomery_to_theta_matrix_dim2(Theta12.zero().coords(),N, return_null_point = True)
- self._domain_bc = ThetaStructureDim2(null_point_bc)
- self.T_shift = K1_4
- self._precomputation = None
- self._zero_idx = 0
- self._domain_product = Theta12
- self._domain=(K1_8[0].curve(), K1_8[1].curve())
-
- # Map points from elliptic product onto the product theta structure
- # using the base change matrix
- T1_8 = self.base_change(K1_8)
- T2_8 = self.base_change(K2_8)
-
- # Compute the codomain of the gluing isogeny
- self._codomain = self._special_compute_codomain(T1_8, T2_8)
-
- def apply_base_change(self, coords):
- """
- Apply the basis change by acting with matrix multiplication, treating
- the coordinates as a vector
- """
- N = self._base_change_matrix
- x, y, z, t = coords
- X = N[0, 0] * x + N[0, 1] * y + N[0, 2] * z + N[0, 3] * t
- Y = N[1, 0] * x + N[1, 1] * y + N[1, 2] * z + N[1, 3] * t
- Z = N[2, 0] * x + N[2, 1] * y + N[2, 2] * z + N[2, 3] * t
- T = N[3, 0] * x + N[3, 1] * y + N[3, 2] * z + N[3, 3] * t
-
- return (X, Y, Z, T)
-
- def base_change(self, P):
- """
- Compute the basis change on a TuplePoint to recover a ThetaPointDim2 of
- compatible form
- """
- if not isinstance(P, TuplePoint):
- raise TypeError("Function assumes that the input is of type `TuplePoint`")
-
- # extract X,Z coordinates on pairs of points
- P1, P2 = P.points()
- X1, Z1 = P1[0], P1[2]
- X2, Z2 = P2[0], P2[2]
-
- # Correct in the case of (0 : 0)
- if X1 == 0 and Z1 == 0:
- X1 = 1
- Z1 = 0
- if X2 == 0 and Z2 == 0:
- X2 = 1
- Z2 = 0
-
- # Apply the basis transformation on the product
- coords = self.apply_base_change([X1 * X2, X1 * Z2, Z1 * X2, Z1 * Z2])
- return coords
-
- def _special_compute_codomain(self, T1, T2):
- """
- Given twzero_matro isotropic points of 8-torsion T1 and T2, compatible with
- the theta null point, compute the level two theta null point A/K_2
- """
- xAxByCyD = ThetaPointDim2.to_squared_theta(*T1)
- zAtBzYtD = ThetaPointDim2.to_squared_theta(*T2)
-
- # Find the value of the non-zero index
- zero_idx = next((i for i, x in enumerate(xAxByCyD) if x == 0), None)
- self._zero_idx = zero_idx
-
- # Dumb check to make sure everything is OK
- assert xAxByCyD[self._zero_idx] == zAtBzYtD[self._zero_idx] == 0
-
- # Initialize lists
- # The zero index described the permutation
- ABCD = [0 for _ in range(4)]
- precomp = [0 for _ in range(4)]
-
- # Compute non-trivial numerators (Others are either 1 or 0)
- num_1 = zAtBzYtD[1 ^ self._zero_idx]
- num_2 = xAxByCyD[2 ^ self._zero_idx]
- num_3 = zAtBzYtD[3 ^ self._zero_idx]
- num_4 = xAxByCyD[3 ^ self._zero_idx]
-
- # Compute and invert non-trivial denominators
- den_1, den_2, den_3, den_4 = batch_inversion([num_1, num_2, num_3, num_4])
-
- # Compute A, B, C, D
- ABCD[0 ^ self._zero_idx] = 0
- ABCD[1 ^ self._zero_idx] = num_1 * den_3
- ABCD[2 ^ self._zero_idx] = num_2 * den_4
- ABCD[3 ^ self._zero_idx] = 1
-
- # Compute precomputation for isogeny images
- precomp[0 ^ self._zero_idx] = 0
- precomp[1 ^ self._zero_idx] = den_1 * num_3
- precomp[2 ^ self._zero_idx] = den_2 * num_4
- precomp[3 ^ self._zero_idx] = 1
- self._precomputation = precomp
-
- # Final Hadamard of the above coordinates
- a, b, c, d = ThetaPointDim2.to_hadamard(*ABCD)
-
- return ThetaStructureDim2([a, b, c, d])
-
- def special_image(self, P, translate):
- """
- When the domain is a non product theta structure on a product of
- elliptic curves, we will have one of A,B,C,D=0, so the image is more
- difficult. We need to give the coordinates of P but also of
- P+Ti, Ti one of the point of 4-torsion used in the isogeny
- normalisation
- """
- AxByCzDt = ThetaPointDim2.to_squared_theta(*P)
-
- # We are in the case where at most one of A, B, C, D is
- # zero, so we need to account for this
- #
- # To recover values, we use the translated point to get
- AyBxCtDz = ThetaPointDim2.to_squared_theta(*translate)
-
- # Directly compute y,z,t
- y = AxByCzDt[1 ^ self._zero_idx] * self._precomputation[1 ^ self._zero_idx]
- z = AxByCzDt[2 ^ self._zero_idx] * self._precomputation[2 ^ self._zero_idx]
- t = AxByCzDt[3 ^ self._zero_idx]
-
- # We can compute x from the translation
- # First we need a normalisation
- if z != 0:
- zb = AyBxCtDz[3 ^ self._zero_idx]
- lam = z / zb
- else:
- tb = AyBxCtDz[2 ^ self._zero_idx] * self._precomputation[2 ^ self._zero_idx]
- lam = t / tb
-
- # Finally we recover x
- xb = AyBxCtDz[1 ^ self._zero_idx] * self._precomputation[1 ^ self._zero_idx]
- x = xb * lam
-
- xyzt = [0 for _ in range(4)]
- xyzt[0 ^ self._zero_idx] = x
- xyzt[1 ^ self._zero_idx] = y
- xyzt[2 ^ self._zero_idx] = z
- xyzt[3 ^ self._zero_idx] = t
-
- image = ThetaPointDim2.to_hadamard(*xyzt)
- return self._codomain(image)
-
- def __call__(self, P):
- """
- Take into input the theta null point of A/K_2, and return the image
- of the point by the isogeny
- """
- if not isinstance(P, TuplePoint):
- raise TypeError(
- "Isogeny image for the gluing isogeny is defined to act on TuplePoints"
- )
-
- # Compute sum of points on elliptic curve
- P_sum_T = P + self.T_shift
-
- # Push both the point and the translation through the
- # completion
- iso_P = self.base_change(P)
- iso_P_sum_T = self.base_change(P_sum_T)
-
- return self.special_image(iso_P, iso_P_sum_T)
-
- def dual(self):
- domain = self._codomain.hadamard()
- codomain_bc = self._domain_bc.hadamard()
- codomain = self._domain
-
- precomputation = batch_inversion(codomain_bc.null_point_dual())
-
- N_split = self._base_change_matrix.inverse()
-
- return DualGluingThetaIsogenyDim2(domain, codomain_bc, codomain, N_split, precomputation)
-
-
-class DualGluingThetaIsogenyDim2:
- def __init__(self, domain, codomain_bc, codomain, N_split, precomputation):
- self._domain = domain
- self._codomain_bc = codomain_bc # Theta structure
- self._codomain = codomain # Elliptic curves E1 and E2
- self._precomputation = precomputation
- self._splitting_matrix = N_split
-
- def __call__(self,P):
- # Returns a TuplePoint.
- if not isinstance(P, ThetaPointDim2):
- raise TypeError("Isogeny evaluation expects a ThetaPointDim2 as input")
-
- xx, yy, zz, tt = P.squared_theta()
-
- Ai, Bi, Ci, Di = self._precomputation
-
- xx = xx * Ai
- yy = yy * Bi
- zz = zz * Ci
- tt = tt * Di
-
- image_coords = (xx, yy, zz, tt)
-
- X1X2, X1Z2, Z1X2, Z1Z2 = apply_base_change_theta_dim2(self._splitting_matrix, image_coords)
-
- E1, E2 = self._codomain
-
- if Z1Z2!=0:
- #Z1=1, Z2=Z1Z2
-
- Z2_inv=1/Z1Z2
- X2=Z1X2*Z2_inv# Normalize (X2:Z2)=(X2/Z2:1)
-
- X1=X1Z2*Z2_inv
-
- assert X1*Z1X2==X1X2
- P1 = lift_kummer_montgomery_point(E1, X1)
- P2 = lift_kummer_montgomery_point(E2, X2)
- return TuplePoint(P1,P2)
- elif Z1X2==0 and X1Z2!=0:
- # Case (X1:Z1)=0, X1!=0 and (X2:Z2)!=0
-
- X2=X1X2/X1Z2
- P2 = lift_kummer_montgomery_point(E2, X2)
- return TuplePoint(E1(0),P2)
- elif Z1X2!=0 and X1Z2==0:
- # Case (X1:Z1)!=0 and (X2:Z2)=0, X2!=0
-
- X1=X1X2/Z1X2
- P1 = lift_kummer_montgomery_point(E1, X1)
- return TuplePoint(P1,E2(0))
- else:
- return TuplePoint(E1(0),E2(0))
-
-
-
-
-
diff --git a/theta_lib/isogenies_dim2/isogeny_chain_dim2.py b/theta_lib/isogenies_dim2/isogeny_chain_dim2.py
deleted file mode 100644
index 23adb23..0000000
--- a/theta_lib/isogenies_dim2/isogeny_chain_dim2.py
+++ /dev/null
@@ -1,178 +0,0 @@
-"""
-This code is based on a copy of:
-https://github.com/ThetaIsogenies/two-isogenies
-
-MIT License
-
-Copyright (c) 2023 Pierrick Dartois, Luciano Maino, Giacomo Pope and Damien Robert
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-"""
-
-from sage.all import *
-from ..theta_structures.Tuple_point import TuplePoint
-from ..theta_structures.Theta_dim2 import ThetaPointDim2
-from .gluing_isogeny_dim2 import GluingThetaIsogenyDim2
-from .isogeny_dim2 import ThetaIsogenyDim2
-from ..utilities.strategy import optimised_strategy
-
-
-class IsogenyChainDim2:
- r"""
- Given (P1, P2), (Q1, Q2) in (E1 x E2)[2^(n+2)] as the generators of a kernel
- of a (2^n, 2^n)-isogeny
-
- ker(Phi) = <(P1, P2), (Q1, Q2)>
-
- Input:
-
- - kernel = TuplePoint(P1, P2), TuplePoint(Q1, Q2):
- where points are on the elliptic curves E1, E2 of order 2^(n+2)
- - n: the length of the chain
- - strategy: the optimises strategy to compute a walk through the graph of
- images and doublings with a quasli-linear number of steps
- """
-
- def __init__(self, kernel, Theta12, M, n, strategy=None):
- self.n = n
- self.E1, self.E2 = kernel[0].parent_curves()
- assert kernel[1].parent_curves() == [self.E1, self.E2]
-
- self._domain = (self.E1, self.E2)
-
- if strategy is None:
- strategy = self.get_strategy()
- self.strategy = strategy
-
- self._phis = self.isogeny_chain(kernel, Theta12, M)
-
- self._codomain=self._phis[-1]._codomain
-
- def get_strategy(self):
- return optimised_strategy(self.n)
-
- def isogeny_chain(self, kernel, Theta12, M):
- """
- Compute the isogeny chain and store intermediate isogenies for evaluation
- """
- # Extract the CouplePoints from the Kernel
- Tp1, Tp2 = kernel
-
- # Store chain of (2,2)-isogenies
- isogeny_chain = []
-
- # Bookkeeping for optimal strategy
- strat_idx = 0
- level = [0]
- ker = (Tp1, Tp2)
- kernel_elements = [ker]
-
- for k in range(self.n):
- prev = sum(level)
- ker = kernel_elements[-1]
-
- while prev != (self.n - 1 - k):
- level.append(self.strategy[strat_idx])
-
- # Perform the doublings
- Tp1 = ker[0].double_iter(self.strategy[strat_idx])
- Tp2 = ker[1].double_iter(self.strategy[strat_idx])
-
- ker = (Tp1, Tp2)
-
- # Update kernel elements and bookkeeping variables
- kernel_elements.append(ker)
- prev += self.strategy[strat_idx]
- strat_idx += 1
-
- # Compute the codomain from the 8-torsion
- Tp1, Tp2 = ker
- if k == 0:
- phi = GluingThetaIsogenyDim2(Tp1, Tp2, Theta12, M)
- else:
- phi = ThetaIsogenyDim2(Th, Tp1, Tp2)
-
- # Update the chain of isogenies
- Th = phi._codomain
- isogeny_chain.append(phi)
-
- # Remove elements from list
- kernel_elements.pop()
- level.pop()
-
- # Push through points for the next step
- kernel_elements = [(phi(T1), phi(T2)) for T1, T2 in kernel_elements]
-
- return isogeny_chain
-
- def evaluate_isogeny(self, P):
- """
- Given a point P, of type TuplePoint on the domain E1 x E2, computes the
- ThetaPointDim2 on the codomain ThetaStructureDim2.
- """
- if not isinstance(P, TuplePoint):
- raise TypeError(
- "IsogenyChainDim2 isogeny expects as input a TuplePoint on the domain product E1 x E2"
- )
- n=len(self._phis)
- for i in range(n):
- P = self._phis[i](P)
- return P
-
- def __call__(self, P):
- """
- Evaluate a TuplePoint under the action of this isogeny.
- """
- return self.evaluate_isogeny(P)
-
- def dual(self):
- domain = self._codomain
- codomain = self._domain
- n=len(self._phis)
- isogenies=[]
- for i in range(n):
- isogenies.append(self._phis[n-1-i].dual())
- return DualIsogenyChainDim2(domain, codomain, isogenies)
-
-
-class DualIsogenyChainDim2:
- def __init__(self, domain, codomain, isogenies):
- self._domain = domain
- self._codomain = codomain
- self._phis = isogenies
-
- def evaluate_isogeny(self, P):
- """
- Given a ThetaPointDim2 point P on the codomain ThetaStructureDim2,
- computes the image TuplePoint on the codomain E1 x E2.
- """
- if not isinstance(P, ThetaPointDim2):
- raise TypeError(
- "DualIsogenyChainDim2 isogeny expects as input a ThetaPointDim2."
- )
- n=len(self._phis)
- for i in range(n):
- P = self._phis[i](P)
- return P
-
- def __call__(self, P):
- """
- Evaluate a ThetaPointDim2 under the action of this isogeny.
- """
- return self.evaluate_isogeny(P)
diff --git a/theta_lib/isogenies_dim2/isogeny_dim2.py b/theta_lib/isogenies_dim2/isogeny_dim2.py
deleted file mode 100644
index b740ab1..0000000
--- a/theta_lib/isogenies_dim2/isogeny_dim2.py
+++ /dev/null
@@ -1,229 +0,0 @@
-"""
-This code is based on a copy of:
-https://github.com/ThetaIsogenies/two-isogenies
-
-MIT License
-
-Copyright (c) 2023 Pierrick Dartois, Luciano Maino, Giacomo Pope and Damien Robert
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-"""
-
-from sage.all import ZZ
-from ..theta_structures.Theta_dim2 import ThetaStructureDim2, ThetaPointDim2
-from ..theta_structures.theta_helpers_dim2 import batch_inversion
-
-
-class ThetaIsogenyDim2:
- def __init__(self, domain, T1_8, T2_8, hadamard=(False, True)):
- """
- Compute a (2,2)-isogeny in the theta model. Expects as input:
-
- - domain: the ThetaStructureDim2 from which we compute the isogeny
- - (T1_8, T2_8): points of 8-torsion above the kernel generating the isogeny
-
- When the 8-torsion is not available (for example at the end of a long
- (2,2)-isogeny chain), the the helper functions in isogeny_sqrt.py
- must be used.
-
- NOTE: on the hadamard bools:
-
- The optional parameter 'hadamard' controls if we are in standard or dual
- coordinates, and if the codomain is in standard or dual coordinates. By
- default this is (False, True), meaning we use standard coordinates on
- the domain A and the codomain B.
-
- The kernel is then the kernel K_2 where the action is by sign. Other
- possibilities: - (False, False): standard coordinates on A, dual
- coordinates on B - (True, True): start in dual coordinates on A
- (alternatively: standard coordinates on A but quotient by K_1 whose
- action is by permutation), and standard coordinates on B. - (True,
- False): dual coordinates on A and B
-
- These can be composed as follows for A -> B -> C:
-
- - (False, True) -> (False, True) (False, False) -> (True, True):
- - standard coordinates on A and C,
- - standard/resp dual coordinates on B
- - (False, True) -> (False, False) (False, False) -> (True, False):
- - standard coordinates on A,
- - dual coordinates on C,
- - standard/resp dual coordinates on B
- - (True, True) -> (False, True) (True, False) -> (True, True):
- - dual coordinates on A,
- - standard coordinates on C,
- - standard/resp dual coordiantes on B
- - (True, True) -> (False, False) (True, False) -> (True, False):
- - dual coordinates on A and C
- - standard/resp dual coordinates on B
-
- On the other hand, these gives the multiplication by [2] on A:
-
- - (False, False) -> (False, True) (False, True) -> (True, True):
- - doubling in standard coordinates on A
- - going through dual/standard coordinates on B=A/K_2
- - (True, False) -> (False, False) (True, True) -> (True, False):
- - doubling in dual coordinates on A
- - going through dual/standard coordinates on B=A/K_2
- (alternatively: doubling in standard coordinates on A going
- through B'=A/K_1)
- - (False, False) -> (False, False) (False, True) -> (True, False):
- - doubling from standard to dual coordinates on A
- - (True, False) -> (False, True) (True, True) -> (True, True):
- - doubling from dual to standard coordinates on A
- """
- if not isinstance(domain, ThetaStructureDim2):
- raise ValueError
- self._domain = domain
-
- self._hadamard = hadamard
- self._precomputation = None
- self._codomain = self._compute_codomain(T1_8, T2_8)
-
- def _compute_codomain(self, T1, T2):
- """
- Given two isotropic points of 8-torsion T1 and T2, compatible with
- the theta null point, compute the level two theta null point A/K_2
- """
- if self._hadamard[0]:
- xA, xB, _, _ = ThetaPointDim2.to_squared_theta(
- *ThetaPointDim2.to_hadamard(*T1.coords())
- )
- zA, tB, zC, tD = ThetaPointDim2.to_squared_theta(
- *ThetaPointDim2.to_hadamard(*T2.coords())
- )
- else:
- xA, xB, _, _ = T1.squared_theta()
- zA, tB, zC, tD = T2.squared_theta()
-
- if not self._hadamard[0] and self._domain._precomputation:
- # Batch invert denominators
- xA_inv, zA_inv, tB_inv = batch_inversion([xA, zA, tB])
-
- # Compute A, B, C, D
- A = ZZ(1)
- B = xB * xA_inv
- C = zC * zA_inv
- D = tD * tB_inv * B
-
- _, _, _, BBinv, CCinv, DDinv = self._domain._arithmetic_precomputation()
- B_inv = BBinv * B
- C_inv = CCinv * C
- D_inv = DDinv * D
- else:
- # Batch invert denominators
- xA_inv, zA_inv, tB_inv, xB_inv, zC_inv, tD_inv = batch_inversion([xA, zA, tB, xB, zC, tD])
-
- # Compute A, B, C, D
- A = ZZ(1)
- B = xB * xA_inv
- C = zC * zA_inv
- D = tD * tB_inv * B
- B_inv = xB_inv * xA
- C_inv = zC_inv * zA
- D_inv = tD_inv * tB * B_inv
-
- # NOTE: some of the computations we did here could be reused for the
- # arithmetic precomputations of the codomain However, we are always
- # in the mode (False, True) except the very last isogeny, so we do
- # not lose much by not doing this optimisation Just in case we need
- # it later:
- # - for hadamard=(False, True): we can reuse the arithmetic
- # precomputation; we do this already above
- # - for hadamard=(False, False): we can reuse the arithmetic
- # precomputation as above, and furthermore we could reuse B_inv,
- # C_inv, D_inv for the precomputation of the codomain
- # - for hadamard=(True, False): we could reuse B_inv, C_inv, D_inv
- # for the precomputation of the codomain
- # - for hadamard=(True, True): nothing to reuse!
-
- self._precomputation = (B_inv, C_inv, D_inv)
- if self._hadamard[1]:
- a, b, c, d = ThetaPointDim2.to_hadamard(A, B, C, D)
- return ThetaStructureDim2([a, b, c, d], null_point_dual=[A, B, C, D])
- else:
- return ThetaStructureDim2([A, B, C, D])
-
- def __call__(self, P):
- """
- Take into input the theta null point of A/K_2, and return the image
- of the point by the isogeny
- """
- if not isinstance(P, ThetaPointDim2):
- raise TypeError("Isogeny evaluation expects a ThetaPointDim2 as input")
-
- if self._hadamard[0]:
- xx, yy, zz, tt = ThetaPointDim2.to_squared_theta(
- *ThetaPointDim2.to_hadamard(*P.coords())
- )
- else:
- xx, yy, zz, tt = P.squared_theta()
-
- Bi, Ci, Di = self._precomputation
-
- yy = yy * Bi
- zz = zz * Ci
- tt = tt * Di
-
- image_coords = (xx, yy, zz, tt)
- if self._hadamard[1]:
- image_coords = ThetaPointDim2.to_hadamard(*image_coords)
- return self._codomain(image_coords)
-
- def dual(self):
- # Returns the dual isogeny (domain and codomain are inverted).
- # By convention, the new domain and codomain are in standard coordinates.
- if self._hadamard[1]:
- domain=self._codomain.hadamard()
- else:
- domain=self._codomain
- if self._hadamard[0]:
- codomain=self._domain
- else:
- codomain=self._domain.hadamard()
-
- precomputation = batch_inversion(self._domain.null_point().coords())
-
- return DualThetaIsogenyDim2(domain,codomain,precomputation)
-
-class DualThetaIsogenyDim2:
- def __init__(self,domain,codomain,precomputation):
- self._domain=domain
- self._codomain=codomain
- self._precomputation=precomputation
-
- def __call__(self,P):
- if not isinstance(P, ThetaPointDim2):
- raise TypeError("Isogeny evaluation expects a ThetaPointDim2 as input")
-
- xx, yy, zz, tt = P.squared_theta()
-
- Ai, Bi, Ci, Di = self._precomputation
-
- xx = xx * Ai
- yy = yy * Bi
- zz = zz * Ci
- tt = tt * Di
-
- image_coords = (xx, yy, zz, tt)
- image_coords = ThetaPointDim2.to_hadamard(*image_coords)
-
- return self._codomain(image_coords)
-
-