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

Pretty printing for elliptic curves and their points #1677

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions docs/src/manual/elliptic_curves/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ by setting `check = false`.
julia> E = elliptic_curve(QQ, [1, 2]);

julia> E([1, -2])
Point (1 : -2 : 1) of Elliptic curve with equation
y^2 = x^3 + x + 2
(1 : -2 : 1)

julia> E([2, -4, 2])
Point (1 : -2 : 1) of Elliptic curve with equation
y^2 = x^3 + x + 2
(1 : -2 : 1)
```

```@docs
Expand Down
3 changes: 1 addition & 2 deletions docs/src/manual/elliptic_curves/finite_fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ Return a random point on the elliptic curve $E$ defined over a finite field.
julia> E = elliptic_curve(GF(3), [1, 2]);

julia> rand(E)
Point (2 : 0 : 1) of Elliptic curve with equation
y^2 = x^3 + x + 2
(0 : 1 : 0)
```

## Cardinality and orders
Expand Down
19 changes: 17 additions & 2 deletions src/EllCrv/EllCrv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,21 @@ end
#
################################################################################

function show(io::IO, ::MIME"text/plain", E::EllipticCurve)
io = pretty(io)
println(io, "Elliptic curve with equation")
print(io, Indent())
_print_equation(io, E)
print(io, Dedent())
end

function show(io::IO, E::EllipticCurve)
print(io, "Elliptic curve with equation\n")
io = pretty(io)
print(io, "Elliptic curve with equation ")
_print_equation(io, E)
end

function _print_equation(io::IO, E::EllipticCurve)
a1, a2, a3, a4, a6 = a_invariants(E)
sum = Expr(:call, :+)
push!(sum.args, Expr(:call, :^, :y, 2))
Expand Down Expand Up @@ -831,8 +844,10 @@ function show(io::IO, E::EllipticCurve)
print(io, AbstractAlgebra.expr_to_string(AbstractAlgebra.canonicalize(sum)))
end


function show(io::IO, P::EllipticCurvePoint)
print(io, "Point ($(P[1]) : $(P[2]) : $(P[3])) of $(P.parent)")
io = pretty(io)
print(io, "($(P[1]) : $(P[2]) : $(P[3]))")
end


Expand Down
13 changes: 7 additions & 6 deletions src/EllCrv/Isomorphisms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -615,15 +615,16 @@ end
#
################################################################################


function show(io::IO, f::EllCrvIso)
function show(io::IO, ::MIME"text/plain", f::EllCrvIso)
io = pretty(io)
E1 = domain(f)
E2 = codomain(f)
fx, fy, fz = rational_maps(f)
print(io, "Isomorphism from
$(E1) to \n
$(E2) given by \n
(x : y : 1) -> ($(fx) : $(fy) : $(fz) )")
println(io, "Isomorphism")
println(io, Indent(), "from ", E1)
println(io, "to ", E2)
print(io,"given by ")
print(io, "(x : y : 1) -> ($(fx) : $(fy) : $(fz) )")
end

################################################################################
Expand Down
Loading