Skip to content

Commit

Permalink
Fix and use setcoeff! for arb poly rings (#1916)
Browse files Browse the repository at this point in the history
* Fix and use `setcoeff!` for `AcbPolyRingElem`
* Fix and use `setcoeff!` for `ComplexPolyRingElem`
* Fix and use `setcoeff!` for `ArbPolyRingElem`
* Fix and use `setcoeff!` for `RealPolyRingElem`
  • Loading branch information
lgoettgens authored Oct 28, 2024
1 parent a834677 commit 9df1993
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 52 deletions.
32 changes: 12 additions & 20 deletions src/arb/ArbTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,16 +467,14 @@ mutable struct RealPolyRingElem <: PolyRingElem{RealFieldElem}

function RealPolyRingElem(x::RealFieldElem, p::Int)
z = RealPolyRingElem()
ccall((:arb_poly_set_coeff_arb, libflint), Nothing,
(Ref{RealPolyRingElem}, Int, Ref{RealFieldElem}), z, 0, x)
setcoeff!(z, 0, x)
return z
end

function RealPolyRingElem(x::Vector{RealFieldElem}, p::Int)
z = RealPolyRingElem()
for i = 1:length(x)
ccall((:arb_poly_set_coeff_arb, libflint), Nothing,
(Ref{RealPolyRingElem}, Int, Ref{RealFieldElem}), z, i - 1, x[i])
for i in 1:length(x)
setcoeff!(z, i - 1, x[i])
end
return z
end
Expand Down Expand Up @@ -549,16 +547,14 @@ mutable struct ArbPolyRingElem <: PolyRingElem{ArbFieldElem}

function ArbPolyRingElem(x::ArbFieldElem, p::Int)
z = ArbPolyRingElem()
ccall((:arb_poly_set_coeff_arb, libflint), Nothing,
(Ref{ArbPolyRingElem}, Int, Ref{ArbFieldElem}), z, 0, x)
setcoeff!(z, 0, x)
return z
end

function ArbPolyRingElem(x::Vector{ArbFieldElem}, p::Int)
z = ArbPolyRingElem()
for i = 1:length(x)
ccall((:arb_poly_set_coeff_arb, libflint), Nothing,
(Ref{ArbPolyRingElem}, Int, Ref{ArbFieldElem}), z, i - 1, x[i])
for i in 1:length(x)
setcoeff!(z, i - 1, x[i])
end
return z
end
Expand Down Expand Up @@ -636,16 +632,14 @@ mutable struct ComplexPolyRingElem <: PolyRingElem{ComplexFieldElem}

function ComplexPolyRingElem(x::ComplexFieldElem, p::Int)
z = ComplexPolyRingElem()
ccall((:acb_poly_set_coeff_acb, libflint), Nothing,
(Ref{ComplexPolyRingElem}, Int, Ref{ComplexFieldElem}), z, 0, x)
setcoeff!(z, 0, x)
return z
end

function ComplexPolyRingElem(x::Vector{ComplexFieldElem}, p::Int)
z = ComplexPolyRingElem()
for i = 1:length(x)
ccall((:acb_poly_set_coeff_acb, libflint), Nothing,
(Ref{ComplexPolyRingElem}, Int, Ref{ComplexFieldElem}), z, i - 1, x[i])
for i in 1:length(x)
setcoeff!(z, i - 1, x[i])
end
return z
end
Expand Down Expand Up @@ -727,16 +721,14 @@ mutable struct AcbPolyRingElem <: PolyRingElem{AcbFieldElem}

function AcbPolyRingElem(x::AcbFieldElem, p::Int)
z = AcbPolyRingElem()
ccall((:acb_poly_set_coeff_acb, libflint), Nothing,
(Ref{AcbPolyRingElem}, Int, Ref{AcbFieldElem}), z, 0, x)
setcoeff!(z, 0, x)
return z
end

function AcbPolyRingElem(x::Vector{AcbFieldElem}, p::Int)
z = AcbPolyRingElem()
for i = 1:length(x)
ccall((:acb_poly_set_coeff_acb, libflint), Nothing,
(Ref{AcbPolyRingElem}, Int, Ref{AcbFieldElem}), z, i - 1, x[i])
for i in 1:length(x)
setcoeff!(z, i - 1, x[i])
end
return z
end
Expand Down
21 changes: 13 additions & 8 deletions src/arb/ComplexPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ one(a::ComplexPolyRing) = one!(a())

function gen(a::ComplexPolyRing)
z = ComplexPolyRingElem()
ccall((:acb_poly_set_coeff_si, libflint), Nothing,
(Ref{ComplexPolyRingElem}, Int, Int), z, 1, 1)
setcoeff!(z, 1, 1)
z.parent = a
return z
end
Expand Down Expand Up @@ -705,18 +704,24 @@ function fit!(z::ComplexPolyRingElem, n::Int)
return nothing
end

function setcoeff!(z::ComplexPolyRingElem, n::Int, x::ZZRingElem)
ccall((:acb_poly_set_coeff_fmpz, libflint), Nothing,
(Ref{ComplexPolyRingElem}, Int, Ref{ZZRingElem}), z, n, x)
return z
end

function setcoeff!(z::ComplexPolyRingElem, n::Int, x::ComplexFieldElem)
ccall((:acb_poly_set_coeff_acb, libflint), Nothing,
(Ref{ComplexPolyRingElem}, Int, Ref{ComplexFieldElem}), z, n, x)
return z
end

function setcoeff!(z::ComplexPolyRingElem, n::Int, x::Int)
ccall((:acb_poly_set_coeff_si, libflint), Nothing,
(Ref{ComplexPolyRingElem}, Int, Int), z, n, x)
return z
end

function setcoeff!(z::ComplexPolyRingElem, n::Int, x::ZZRingElem)
return setcoeff!(z, n, base_ring(z)(x))
end

setcoeff!(z::ComplexPolyRingElem, n::Int, x::Integer) = setcoeff!(z, n, flintify(x))

#

function add!(z::ComplexPolyRingElem, x::ComplexPolyRingElem, y::ComplexPolyRingElem)
Expand Down
21 changes: 13 additions & 8 deletions src/arb/RealPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ one(a::RealPolyRing) = one!(a())

function gen(a::RealPolyRing)
z = RealPolyRingElem()
ccall((:arb_poly_set_coeff_si, libflint), Nothing,
(Ref{RealPolyRingElem}, Int, Int), z, 1, 1)
setcoeff!(z, 1, 1)
z.parent = a
return z
end
Expand Down Expand Up @@ -608,18 +607,24 @@ function fit!(z::RealPolyRingElem, n::Int)
return nothing
end

function setcoeff!(z::RealPolyRingElem, n::Int, x::ZZRingElem)
ccall((:arb_poly_set_coeff_fmpz, libflint), Nothing,
(Ref{RealPolyRingElem}, Int, Ref{ZZRingElem}), z, n, x)
return z
end

function setcoeff!(z::RealPolyRingElem, n::Int, x::RealFieldElem)
ccall((:arb_poly_set_coeff_arb, libflint), Nothing,
(Ref{RealPolyRingElem}, Int, Ref{RealFieldElem}), z, n, x)
return z
end

function setcoeff!(z::RealPolyRingElem, n::Int, x::Int)
ccall((:arb_poly_set_coeff_si, libflint), Nothing,
(Ref{RealPolyRingElem}, Int, Int), z, n, x)
return z
end

function setcoeff!(z::RealPolyRingElem, n::Int, x::ZZRingElem)
return setcoeff!(z, n, base_ring(z)(x))
end

setcoeff!(z::RealPolyRingElem, n::Int, x::Integer) = setcoeff!(z, n, flintify(x))

#

function add!(z::RealPolyRingElem, x::RealPolyRingElem, y::RealPolyRingElem)
Expand Down
21 changes: 13 additions & 8 deletions src/arb/acb_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ one(a::AcbPolyRing) = one!(a())

function gen(a::AcbPolyRing)
z = AcbPolyRingElem()
ccall((:acb_poly_set_coeff_si, libflint), Nothing,
(Ref{AcbPolyRingElem}, Int, Int), z, 1, 1)
setcoeff!(z, 1, 1)
z.parent = a
return z
end
Expand Down Expand Up @@ -701,18 +700,24 @@ function fit!(z::AcbPolyRingElem, n::Int)
return nothing
end

function setcoeff!(z::AcbPolyRingElem, n::Int, x::ZZRingElem)
ccall((:acb_poly_set_coeff_fmpz, libflint), Nothing,
(Ref{AcbPolyRingElem}, Int, Ref{ZZRingElem}), z, n, x)
return z
end

function setcoeff!(z::AcbPolyRingElem, n::Int, x::AcbFieldElem)
ccall((:acb_poly_set_coeff_acb, libflint), Nothing,
(Ref{AcbPolyRingElem}, Int, Ref{AcbFieldElem}), z, n, x)
return z
end

function setcoeff!(z::AcbPolyRingElem, n::Int, x::Int)
ccall((:acb_poly_set_coeff_si, libflint), Nothing,
(Ref{AcbPolyRingElem}, Int, Int), z, n, x)
return z
end

function setcoeff!(z::AcbPolyRingElem, n::Int, x::ZZRingElem)
return setcoeff!(z, n, base_ring(z)(x))
end

setcoeff!(z::AcbPolyRingElem, n::Int, x::Integer) = setcoeff!(z, n, flintify(x))

#

function add!(z::AcbPolyRingElem, x::AcbPolyRingElem, y::AcbPolyRingElem)
Expand Down
21 changes: 13 additions & 8 deletions src/arb/arb_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ one(a::ArbPolyRing) = one!(a())

function gen(a::ArbPolyRing)
z = ArbPolyRingElem()
ccall((:arb_poly_set_coeff_si, libflint), Nothing,
(Ref{ArbPolyRingElem}, Int, Int), z, 1, 1)
setcoeff!(z, 1, 1)
z.parent = a
return z
end
Expand Down Expand Up @@ -608,18 +607,24 @@ function fit!(z::ArbPolyRingElem, n::Int)
return nothing
end

function setcoeff!(z::ArbPolyRingElem, n::Int, x::ZZRingElem)
ccall((:arb_poly_set_coeff_fmpz, libflint), Nothing,
(Ref{ArbPolyRingElem}, Int, Ref{ZZRingElem}), z, n, x)
return z
end

function setcoeff!(z::ArbPolyRingElem, n::Int, x::ArbFieldElem)
ccall((:arb_poly_set_coeff_arb, libflint), Nothing,
(Ref{ArbPolyRingElem}, Int, Ref{ArbFieldElem}), z, n, x)
return z
end

function setcoeff!(z::ArbPolyRingElem, n::Int, x::Int)
ccall((:arb_poly_set_coeff_si, libflint), Nothing,
(Ref{ArbPolyRingElem}, Int, Int), z, n, x)
return z
end

function setcoeff!(z::ArbPolyRingElem, n::Int, x::ZZRingElem)
return setcoeff!(z, n, base_ring(z)(x))
end

setcoeff!(z::ArbPolyRingElem, n::Int, x::Integer) = setcoeff!(z, n, flintify(x))

#

function add!(z::ArbPolyRingElem, x::ArbPolyRingElem, y::ArbPolyRingElem)
Expand Down

0 comments on commit 9df1993

Please sign in to comment.