Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Simon's constructor for elliptic curves. #1190

Merged
merged 4 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/EllCrv/EllCrv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,44 @@
return elliptic_curve(QQFieldElem[QQ(z) for z in x], check = check)
end

# A constructor to create an elliptic curve from a bivariate polynomial.
# One can specify how to interpret the polynomial via the second and the
# third argument.
@doc raw"""
elliptic_curve(f::MPolyRingElem, x::MPolyRingElem, y::MPolyRingElem) -> EllCrv

Construct an elliptic curve from a bivariate polynomial `f` in long Weierstrass form.
The second and third argument specify variables of the `parent` of `f` so that
``f = c ⋅ (-y² + x³ - a₁ ⋅ xy + a₂ ⋅ x² - a₃ ⋅ y + a₄ ⋅ x + a₆)``.
"""
function elliptic_curve(f::MPolyRingElem, x::MPolyRingElem, y::MPolyRingElem)
R = parent(f)
@assert ngens(R) == 2 "polynomial must be bivariate"
@assert x in gens(R) && y in gens(R) "second and third argument must be ring variables"
k = coefficient_ring(f)
kf = k
if !(k isa Field)
kf = fraction_field(k)

Check warning on line 256 in src/EllCrv/EllCrv.jl

View check run for this annotation

Codecov / codecov/patch

src/EllCrv/EllCrv.jl#L256

Added line #L256 was not covered by tests
end
# coeff returns a polynomial in parent(f); we pick out the constant coefficient.
my_const = t->(iszero(t) ? zero(coefficient_ring(parent(t))) : first(coefficients(t)))
c = my_const(coeff(f, [x, y], [3, 0])::MPolyRingElem)
@assert parent(c)===k
f = inv(c)*f
@assert coeff(f, [x,y], [0,2]) == -1 "coefficient of y^2 must be -1"
a6 = coeff(f, [x,y], [0,0])
a4 = coeff(f, [x,y], [1,0])
a2 = coeff(f, [x,y], [2,0])
a3 = -coeff(f, [x,y], [0,1])
a1 = -coeff(f, [x,y], [1,1])
a_invars = [my_const(i) for i in [a1,a2,a3,a4,a6]]
(a1,a2,a3,a4,a6) = a_invars
@assert f == (-(y^2 + a1*x*y + a3*y) + (x^3 + a2*x^2 + a4*x + a6))
E = EllipticCurve(kf, kf.([a1,a2,a3,a4,a6]))
return E
end


@doc raw"""
elliptic_curve(f::PolyElem, [h::PolyElem,] check::Bool = true) -> EllCrv

Expand Down
12 changes: 12 additions & 0 deletions test/EllCrv/EllCrv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,15 @@
@test_throws ErrorException P1//5
end
end

@testset "additional constructors" begin
R, (x, y) = polynomial_ring(QQ, [:x, :y])
f = y^2 - x^3 - 3*x^2 + 7*x - 4
elliptic_curve(f, x, y)

pt, t = polynomial_ring(QQ, :t)
kt = fraction_field(pt)
R, (x, y) = polynomial_ring(kt, [:x, :y])
f = y^2 - x^3 - 3*t*x^2 + 7*x - 4*t^2 - 3
elliptic_curve(f, x, y)
end
Loading