Skip to content

Commit

Permalink
Wrap fmpq_mpoly
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Apr 21, 2018
1 parent 46654d0 commit 47abe8b
Show file tree
Hide file tree
Showing 6 changed files with 1,462 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deps/build.jl
Expand Up @@ -5,7 +5,7 @@ oldwdir = pwd()
@show MPIR_VERSION = "3.0.0"
@show MPFR_VERSION = "4.0.0"
@show ANTIC_VERSION = "0063a41b6a75db801fddf562fa4a329c12ce0584"
@show FLINT_VERSION = "84ee095d0cdb66ca228cf3ff67f0f3a206184971"
@show FLINT_VERSION = "adf1583c6bd92a454f3f92a18adf9063d14637a0"
@show ARB_VERSION = "232135f35eeebb74afcea5dd7be436142bee9227"

pkgdir = dirname(dirname(@__FILE__))
Expand Down
2 changes: 2 additions & 0 deletions src/Rings.jl
Expand Up @@ -59,6 +59,8 @@ include("Fields.jl")

include("flint/fmpq_poly.jl")

include("flint/fmpq_mpoly.jl")

include("flint/padic.jl")

include("flint/fmpq_rel_series.jl")
Expand Down
168 changes: 168 additions & 0 deletions src/flint/FlintTypes.jl
Expand Up @@ -794,6 +794,174 @@ function _fmpz_mpoly_ctx_clear_fn(a::FmpzMPolyRing)
(Ref{FmpzMPolyRing},), a)
end

###############################################################################
#
# FmpqMPolyRing / fmpq_mpoly
#
###############################################################################

const flint_orderings = [:lex, :deglex, :degrevlex]

# S is a Symbol which can take the values:
# :lex
# :deglex
# :degrevlex

mutable struct FmpqMPolyRing <: MPolyRing{fmpq}
nvars::Int
nfields::Cint
ord::Int
deg::Cint
rev::Cint
base_ring::FlintRationalField
S::Array{Symbol, 1}

function FmpqMPolyRing(s::Array{Symbol, 1}, S::Symbol, cached::Bool = true)
if cached && haskey(FmpqMPolyID, (s, S))
return FmpqMPolyID[s, S]
else
if S == :lex
ord = 0
elseif S == :deglex
ord = 1
elseif S == :degrevlex
ord = 2
else
error("$S is not a valid ordering")
end

z = new()
ccall((:fmpq_mpoly_ctx_init, :libflint), Void,
(Ref{FmpqMPolyRing}, Int, Int),
z, length(s), ord)
z.base_ring = FlintQQ
z.S = s
finalizer(z, _fmpq_mpoly_ctx_clear_fn)
if cached
FmpqMPolyID[s, S] = z
end
return z
end
end
end

function _fmpq_mpoly_ctx_clear_fn(a::FmpqMPolyRing)
ccall((:fmpq_mpoly_ctx_clear, :libflint), Void,
(Ref{FmpqMPolyRing},), a)
end

const FmpqMPolyID = Dict{Tuple{Array{Symbol, 1}, Symbol}, FmpqMPolyRing}()

mutable struct fmpq_mpoly <: MPolyElem{fmpq}
content_num::Ptr{Void}
content_den::Ptr{Void}
coeffs::Ptr{Void}
exps::Ptr{Void}
alloc::Int
length::Int
bits::Int

parent::FmpqMPolyRing

function fmpq_mpoly(ctx::FmpqMPolyRing)
z = new()
ccall((:fmpq_mpoly_init, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing},), z, ctx)
z.parent = ctx
finalizer(z, _fmpq_mpoly_clear_fn)
return z
end

function fmpq_mpoly(ctx::FmpqMPolyRing, a::Vector{fmpq}, b::Vector{Vector{UInt}})
z = new()
ccall((:fmpq_mpoly_init, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing},), z, ctx)
z.parent = ctx
finalizer(z, _fmpq_mpoly_clear_fn)

for i in 1:length(a)
ccall((:fmpq_mpoly_pushterm_fmpq_ui, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{fmpq}, Ptr{UInt}, Ref{FmpqMPolyRing}),
z, a[i], b[i], ctx)
end

ccall((:fmpq_mpoly_sort, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing}), z, ctx)
ccall((:fmpq_mpoly_combine_like_terms, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing}), z, ctx)
return z
end

function fmpq_mpoly(ctx::FmpqMPolyRing, a::Vector{fmpq}, b::Vector{Vector{fmpz}})
z = new()
ccall((:fmpq_mpoly_init, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing},), z, ctx)
z.parent = ctx
finalizer(z, _fmpq_mpoly_clear_fn)

for i in 1:length(a)
ccall((:fmpq_mpoly_pushterm_fmpq_fmpz, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{fmpq}, Ptr{Ref{fmpz}}, Ref{FmpqMPolyRing}),
z, a[i], b[i], ctx)
end

ccall((:fmpq_mpoly_sort, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing}), z, ctx)
ccall((:fmpq_mpoly_combine_like_terms, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing}), z, ctx)
return z
end

function fmpq_mpoly(ctx::FmpqMPolyRing, a::fmpz)
z = new()
ccall((:fmpq_mpoly_init, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing},), z, ctx)
ccall((:fmpq_mpoly_set_fmpz, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{fmpz}, Ref{FmpqMPolyRing}), z, a, ctx)
z.parent = ctx
finalizer(z, _fmpq_mpoly_clear_fn)
return z
end

function fmpq_mpoly(ctx::FmpqMPolyRing, a::fmpq)
z = new()
ccall((:fmpq_mpoly_init, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing},), z, ctx)
ccall((:fmpq_mpoly_set_fmpq, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{fmpq}, Ref{FmpqMPolyRing}), z, a, ctx)
z.parent = ctx
finalizer(z, _fmpq_mpoly_clear_fn)
return z
end

function fmpq_mpoly(ctx::FmpqMPolyRing, a::Int)
z = new()
ccall((:fmpq_mpoly_init, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing},), z, ctx)
ccall((:fmpq_mpoly_set_si, :libflint), Void,
(Ref{fmpq_mpoly}, Int, Ref{FmpqMPolyRing}), z, a, ctx)
z.parent = ctx
finalizer(z, _fmpq_mpoly_clear_fn)
return z
end

function fmpq_mpoly(ctx::FmpqMPolyRing, a::UInt)
z = new()
ccall((:fmpq_mpoly_init, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing},), z, ctx)
ccall((:fmpq_mpoly_set_ui, :libflint), Void,
(Ref{fmpq_mpoly}, UInt, Ref{FmpqMPolyRing}), z, a, ctx)
z.parent = ctx
finalizer(z, _fmpq_mpoly_clear_fn)
return z
end
end

function _fmpq_mpoly_clear_fn(a::fmpq_mpoly)
ccall((:fmpq_mpoly_clear, :libflint), Void,
(Ref{fmpq_mpoly}, Ref{FmpqMPolyRing}), a, a.parent)
end

###############################################################################
#
# FqNmodFiniteField / fq_nmod
Expand Down

0 comments on commit 47abe8b

Please sign in to comment.