Skip to content

Commit cfa1019

Browse files
committed
add comment & test for addition formulas
1 parent bc38798 commit cfa1019

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/sage/schemes/elliptic_curves/addition_formulas_ring.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ def add(E, P, Q):
44
Addition formulas for elliptic curves over general rings
55
with trivial Picard group.
66
7+
This function returns a generator which yields tuples of projective
8+
coordinates. Some linear combination of those coordinate tuples is
9+
guaranteed to form a valid projective point.
10+
11+
.. NOTE::
12+
13+
This function is for internal use. To add two elliptic-curve
14+
points, users should simply use the `+` operator.
15+
716
REFERENCES:
817
918
These formulas were derived by Bosma and Lenstra [BL1995]_,
@@ -25,6 +34,20 @@ def add(E, P, Q):
2534
(582, 2347, 1028)
2635
sage: E(PQ1) == E(PQ2)
2736
True
37+
38+
TESTS:
39+
40+
We ensure that these formulas return the same result as the ones over a field::
41+
42+
sage: from sage.schemes.elliptic_curves.addition_formulas_ring import add
43+
sage: F = GF(2^127-1)
44+
sage: E = EllipticCurve(j=F.random_element())
45+
sage: E = choice(E.twists())
46+
sage: P = E.random_point()
47+
sage: Q = E.random_point()
48+
sage: PQ1, PQ2 = add(E, P, Q)
49+
sage: assert E(*PQ1) == P + Q
50+
sage: assert E(*PQ2) == P + Q
2851
"""
2952
a1, a2, a3, a4, a6 = E.a_invariants()
3053
b2, b4, b6, b8 = E.b_invariants()

0 commit comments

Comments
 (0)