Skip to content

Commit

Permalink
expressify n_Z, n_Q , n_Zn, n_Zp
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Dec 30, 2020
1 parent b64e3f1 commit 05fb06f
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/number/n_Q.jl
Expand Up @@ -106,6 +106,10 @@ function show(io::IO, c::Rationals)
print(io, "Rational Field")
end

function AbstractAlgebra.expressify(n::n_Q; context = nothing)::Any
return AbstractAlgebra.expressify(Rational{BigInt}(n), context = context)
end

function show(io::IO, n::n_Q)
libSingular.StringSetS("")

Expand Down
4 changes: 4 additions & 0 deletions src/number/n_Z.jl
Expand Up @@ -102,6 +102,10 @@ function show(io::IO, c::Integers)
print(io, "Integer Ring")
end

function AbstractAlgebra.expressify(n::n_Z; context = nothing)::Any
return AbstractAlgebra.expressify(BigInt(n), context = context)
end

function show(io::IO, n::n_Z)
libSingular.StringSetS("")

Expand Down
8 changes: 8 additions & 0 deletions src/number/n_Zn.jl
Expand Up @@ -89,6 +89,14 @@ function show(io::IO, c::N_ZnRing)
print(io, "Residue Ring of Integer Ring modulo ", characteristic(c))
end

function AbstractAlgebra.expressify(n::n_Zn; context = nothing)::Any
x = BigInt()
GC.@preserve n begin
ccall((:__gmpz_set, :libgmp), Cvoid, (Ref{BigInt}, Ptr{Any}), x, n.ptr.cpp_object)
end
return AbstractAlgebra.expressify(x, context = context)
end

function show(io::IO, n::n_Zn)
libSingular.StringSetS("")
libSingular.n_Write(n.ptr, parent(n).ptr, false)
Expand Down
5 changes: 5 additions & 0 deletions src/number/n_Zp.jl
Expand Up @@ -80,6 +80,11 @@ function show(io::IO, c::N_ZpField)
print(io, "Finite Field of Characteristic ", characteristic(c))
end

function AbstractAlgebra.expressify(n::n_Zp; context = nothing)::Any
nn = rem(Int(n), characteristic(parent(x)), RoundNearest)
return AbstractAlgebra.expressify(nn, context = context)
end

function show(io::IO, n::n_Zp)
libSingular.StringSetS("")
libSingular.n_Write(n.ptr, parent(n).ptr, false)
Expand Down
6 changes: 6 additions & 0 deletions src/poly/poly.jl
Expand Up @@ -362,6 +362,12 @@ function show(io::IO, a::spoly)
print(io, s)
end

# TODO: Remove this once we can properly expressify elements of type n_GF
function show(io::IO, ::MIME"text/plain", a::spoly{n_GF})
s = libSingular.p_String(a.ptr, parent(a).ptr)
print(io, s)
end

show_minus_one(::Type{spoly{T}}) where T <: Nemo.RingElem = show_minus_one(T)

needs_parentheses(x::spoly) = length(x) > 1
Expand Down
1 change: 1 addition & 0 deletions test/number/n_Q-test.jl
Expand Up @@ -65,6 +65,7 @@ end

@testset "n_Q.printing..." begin
@test string(QQ(123)) == "123"
@test sprint(show, "text/plain", (QQ(123))) == "123"
end

@testset "n_Q.manipulation..." begin
Expand Down
1 change: 1 addition & 0 deletions test/number/n_Z-test.jl
Expand Up @@ -37,6 +37,7 @@ end

@testset "n_Z.printing..." begin
@test string(ZZ(123)) == "123"
@test sprint(show, "text/plain", (ZZ(123))) == "123"
end

@testset "n_Z.manipulation..." begin
Expand Down
2 changes: 2 additions & 0 deletions test/number/n_Zn-test.jl
Expand Up @@ -40,6 +40,8 @@ end
R = ResidueRing(ZZ, 5)

@test string(R(3)) == "3"

@test sprint(show, "text/plain", (R(3))) == "3"
end

@testset "n_Zn.manipulation..." begin
Expand Down
2 changes: 2 additions & 0 deletions test/number/n_Zp-test.jl
Expand Up @@ -40,6 +40,8 @@ end
R = Fp(5)

@test string(R(3)) == "-2"

@test sprint(show, "text/plain", (R(3))) == "-2"
end

@testset "n_Zp.manipulation..." begin
Expand Down

0 comments on commit 05fb06f

Please sign in to comment.