SageMath_package_template/elliptic_curve_demo.py
Eloi Torrents 4d7c1a1d12 init
2025-09-21 14:46:51 +02:00

35 lines
827 B
Python

#!/usr/bin/env sage -python
from sage.all import EllipticCurve
from demo_package import greet
def describe_curve() -> None:
"""Construct an elliptic curve and print basic arithmetic information."""
E = EllipticCurve([0, 0, 0, -1, 1]) # y^2 = x^3 - x + 1
print(f"Elliptic curve E: {E}")
print(f"Discriminant: {E.discriminant()}")
print(f"j-invariant: {E.j_invariant()}")
rank = E.rank()
print(f"Rank: {rank}")
generators = E.gens()
if generators:
P = generators[0]
print(f"Generator: {P}")
for n in range(1, 6):
multiple = n * P
print(f"{n} * P = {multiple}")
else:
print("Curve has no generators over Q.")
def main() -> None:
print(greet("Sage enthusiast"))
describe_curve()
if __name__ == "__main__":
main()