Skip to content

Commit

Permalink
proper expressify for n_transExt (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
tthsqe12 committed Mar 20, 2021
1 parent f38f01e commit 6b922bd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/number/NumberTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ mutable struct N_FField <: Field
ptr::libSingular.coeffs_ptr
base_ring::Field
refcount::Int
S::Array{Symbol, 1}

function N_FField(F::Field, S::Array{Symbol, 1}, cached::Bool = true)
if cached && haskey(N_FFieldID, (F, S))
Expand All @@ -317,7 +318,7 @@ mutable struct N_FField <: Field
v = [pointer(Base.Vector{UInt8}(string(str)*"\0")) for str in S]
cf = libSingular.nCopyCoeff(F.ptr)
ptr = libSingular.transExt_helper(cf, v)
d = new(ptr, F, 1)
d = new(ptr, F, 1, S)
finalizer(_Ring_finalizer, d)
if cached
N_FFieldID[F, S] = d
Expand Down
30 changes: 14 additions & 16 deletions src/number/n_transExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ function characteristic(R::N_FField)
return ZZ(libSingular.n_GetChar(R.ptr))
end

function symbols(R::N_FField)
return R.S
end

function deepcopy_internal(a::n_transExt, dict::IdDict)
return parent(a)(libSingular.n_Copy(a.ptr, parent(a).ptr))
end
Expand Down Expand Up @@ -101,9 +105,9 @@ Return `true` if $n$ is a unit in the field, i.e. nonzero.
"""
isunit(n::n_transExt) = !iszero(n)

function _tExt_to_poly(R, cached)
function _tExt_to_poly(R::N_FField, cached)
n = transcendence_degree(R)
P, = PolynomialRing(base_ring(R), ["a$i" for i in 1:n], cached = cached)
P, = PolynomialRing(base_ring(R), map(string, symbols(R)), cached = cached)
return P
end

Expand Down Expand Up @@ -151,21 +155,15 @@ function show(io::IO, F::N_FField)
print(io, "Function Field over ", base_ring(F), " with transcendence basis ", transcendence_basis(F))
end

function AbstractAlgebra.expressify(n::n_transExt; context = nothing)::Any
# TODO this easy method might not be the best
libSingular.StringSetS("")
libSingular.n_Write(n.ptr, parent(n).ptr, false)
s = libSingular.StringEndS()
e = Meta.parse(s)
if !isa(e, Expr)
return e
elseif e.head == :incomplete
return s
elseif e.head == :call && length(e.args) == 3 && e.args[1] == :/
e.args[1] = ://
return e
function AbstractAlgebra.expressify(a::n_transExt; context = nothing)::Any
n = numerator(a)
n = AbstractAlgebra.expressify(n_transExt_to_spoly(n), context = context)
d = denominator(a)
if isone(d)
return n
else
return e
d = AbstractAlgebra.expressify(n_transExt_to_spoly(d), context = context)
return Expr(:call, ://, n, d)
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/number/n_transExt-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ end

@test sprint(show, "text/plain", q) == "(a*c + b)//c*x^2"
@test string(q) == "(a*c + b)//c*x^2"

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

@test sprint(show, "text/plain", R(big(3)^80)) == string(big(3)^80)
@test string(R(big(3)^80)) == string(big(3)^80)
end

@testset "n_transExt.manipulation" begin
Expand Down

0 comments on commit 6b922bd

Please sign in to comment.