February 3, 2022
We will use SageMath, but if you don’t have SageMath, you can do this 1st tutorial with Python, just skip Exercises 1 and 2 and jump directly to exercise 3.
Create a folder on your disk for this course.
Do not use white spaces, dashes or non-ASCII characters (' ', '-' etc) in folder names or file names, instead you can use an underscore _.
Create a new file tutorial1.py where you will write your functions.
c and an initial integer-valued solution to a Bachet equation of the form y^2 - x^3 = c, computes the next solution with Bachet’s replication formula:def bachet_replication_rational(c, x, y):
"""
returns the next solution to the equation y^2 - x^3 = c
INPUT:
- `c`: integer
- `x`: rational number
- `y`: rational number
satisfying y^2 - x^3 = c
RETURN: (X, Y)
"""
# TODO below write your function with a return statementc=-2, a solution is (3,5). Check that your function outputs a valid solution from these inputs.def test_bachet_replication_rational():
"""
Test bachet_replication function with c=-2
Check that the next three solutions to y^2 - x^3 = -2 are
correct, starting at (3,5)
RETURN: True or False
"""
# TODO below write your test with a return statementSageMath in the prompt (the interpreter) converts automatically an expression x/y with integer x, y into a fraction, while Python performs an Euclidean division to get an integer. To obtain an exact rational number in a .py file (outside SageMath interpreter), one needs to tell explicitly SageMath to do so with
t = QQ(a/b)
where QQ (or Q) stands for the field of rationals QQ. Use
import_statements(QQ)
in SageMath prompt to find which library to import in your .py file. Hint: you want to write something like
from sage.xxx import QQ
x and y change to xn, xd for the numerator and the denominator of x, and yn, yd for the numerator and denominator of y. You will need to be careful while handling the coefficients in the formula.def bachet_replication_fraction(c, xn, yn, xd, yd):
"""
returns the next solution to the equation Y^2 - X^3 = c
INPUT:
- `c`: integer
- `xn`: integer, numerator of x
- `yn`: integer, numerator of y
- `xd`: integer, denominator of x
- `yd`: integer, denominator of y
satisfying (yn/yd)^2 - (xn/xd)^3 = c
RETURN: (Xn, Yn, Xd, Yd)
"""
# TODO below write your function with a return statementdef test_bachet_replication_fraction():
"""
Test bachet_replication_rational function with c=-2
Check that the next three solutions to y^2 - x^3 = -2 are
correct, starting at (3,5)
RETURN: True or False
"""
# TODO below write your test with a return statement How can you give a default value to xd and yd so that the header is compatible with integers x,y like in exercise 1?
Using from math import gcd, simplify the fractions. Check again with your test function.
With c=1, a solution is (2, 3). With c=-432, a solution is (12,36). What happens with these solutions? Print the next three solutions.
Later we will see that such points (x,y) on a Bachet elliptic curve y^2 = x^3 + c are torsion points.
If you succeeded in installing Sage, you can check with:
If you are done, you can then do the following optional exercises from Washington’s book. The numbers refer to the exercise numbers at the end of chapter 2 p. 71-76.
y^2 + a1*xy + a3*y = ... it can be done with SageMathy^2 = x^3-432 and Fermat’s equation with n=3, this is Section 2.5.2 pages 36-37.