Skip to content

Commit

Permalink
Remove calls to PolyRing(R)
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jun 12, 2024
1 parent 65f9956 commit 62504fa
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,7 @@ end

function det_df(M::MatrixElem{T}) where {T <: RingElement}
R = base_ring(M)
S = PolyRing(R)
S = polynomial_ring_only(R, :x; cached=false)
n = nrows(M)
p = charpoly(S, M)
d = coeff(p, 0)
Expand Down
11 changes: 8 additions & 3 deletions src/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2936,19 +2936,24 @@ function polynomial_to_power_sums(f::PolyRingElem{T}, n::Int=degree(f)) where T
end

@doc raw"""
power_sums_to_polynomial(P::Vector{T}) where T <: RingElement -> PolyRingElem{T}
power_sums_to_polynomial(P::Vector{T};
parent::PolyRing{T}=PolyRing(parent(P[1])) where T <: RingElement -> PolyRingElem{T}
parent::PolyRing{T} where T <: RingElement -> PolyRingElem{T}
Uses the Newton (or Newton-Girard) identities to obtain the polynomial
with given sums of powers of roots. The list must be nonempty and contain
`degree(f)` entries where $f$ is the polynomial to be recovered. The list
must start with the sum of first powers of the roots.
"""
function power_sums_to_polynomial(P::Vector{T};
parent::PolyRing{T}=PolyRing(parent(P[1]))) where T <: RingElement
function power_sums_to_polynomial(P::Vector{T}; parent::PolyRing{T}) where T <: RingElement

Check warning on line 2948 in src/Poly.jl

View check run for this annotation

Codecov / codecov/patch

src/Poly.jl#L2948

Added line #L2948 was not covered by tests
return power_sums_to_polynomial(P, parent)
end

function power_sums_to_polynomial(P::Vector{T}) where T <: RingElement
R = polynomial_ring_only(parent(P[1]), :x; cached=false)
return power_sums_to_polynomial(P, R)
end

function power_sums_to_polynomial(P::Vector{T}, Rx::PolyRing{T}) where T <: FieldElement
d = length(P)
R = base_ring(Rx)
Expand Down
4 changes: 2 additions & 2 deletions src/generic/Misc/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end
################################################################################

function factor(R::Field, f::PolyRingElem)
Rt = AbstractAlgebra.PolyRing(R)
Rt = AbstractAlgebra.polynomial_ring_only(R, :x; cached=false)

Check warning on line 26 in src/generic/Misc/Poly.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/Misc/Poly.jl#L26

Added line #L26 was not covered by tests
f1 = change_base_ring(R, f; parent = Rt)
return factor(f1)
end
Expand Down Expand Up @@ -70,7 +70,7 @@ end
Returns the roots of the polynomial `f` in the field `R` as an array.
"""
function roots(R::Field, f::PolyRingElem)
Rt = AbstractAlgebra.PolyRing(R)
Rt = AbstractAlgebra.polynomial_ring_only(R, :x; cached=false)

Check warning on line 73 in src/generic/Misc/Poly.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/Misc/Poly.jl#L73

Added line #L73 was not covered by tests
f1 = change_base_ring(R, f, parent = Rt)
return roots(f1)
end
Expand Down
2 changes: 1 addition & 1 deletion src/generic/Misc/Rings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function is_power(a::RingElem, n::Int)
return true, a
end
R = parent(a)
Rt = AbstractAlgebra.PolyRing(R)
Rt = AbstractAlgebra.polynomial_ring_only(R, :x; cached=false)

Check warning on line 15 in src/generic/Misc/Rings.jl

View check run for this annotation

Codecov / codecov/patch

src/generic/Misc/Rings.jl#L15

Added line #L15 was not covered by tests
x = gen(Rt)
r = roots(x^n - a)
if length(r) == 0
Expand Down
2 changes: 1 addition & 1 deletion src/generic/SparsePoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ function gcd(a::SparsePoly{T}, b::SparsePoly{T}, ignore_content::Bool = false) w
# if we are in univariate case, convert to dense, take gcd, convert back
if constant_coeffs
# convert polys to univariate dense
R = AbstractAlgebra.PolyRing(base_ring(base_ring(a)))
R = AbstractAlgebra.polynomial_ring_only(base_ring(base_ring(a)), :x; cached=false)
f = R()
g = R()
fit!(f, reinterpret(Int, a.exps[a.length] + 1))
Expand Down
4 changes: 2 additions & 2 deletions test/generic/Poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
end

@testset "Generic.Poly.constructors" begin
S1 = PolyRing(ZZ)
S2 = PolyRing(ZZ)
S1 = AbstractAlgebra.polynomial_ring_only(ZZ, :x; cached=false)
S2 = AbstractAlgebra.polynomial_ring_only(ZZ, :x; cached=false)

@test S1 !== S2
@test isa(S1, Generic.PolyRing)
Expand Down

0 comments on commit 62504fa

Please sign in to comment.