diff --git a/src/generic/GenericTypes.jl b/src/generic/GenericTypes.jl index 339103a81b..9f33da6f7e 100644 --- a/src/generic/GenericTypes.jl +++ b/src/generic/GenericTypes.jl @@ -464,7 +464,7 @@ end ############################################################################### @attributes mutable struct UniversalPolyRing{T <: RingElement} <: AbstractAlgebra.UniversalPolyRing{T} - mpoly_ring::AbstractAlgebra.MPolyRing{T} + base_ring::AbstractAlgebra.MPolyRing{T} function UniversalPolyRing{T}( R::Ring, s::Vector{Symbol}, internal_ordering::Symbol, cached::Bool=true diff --git a/src/generic/UnivPoly.jl b/src/generic/UnivPoly.jl index f5f0e3e23b..d12c049e4a 100644 --- a/src/generic/UnivPoly.jl +++ b/src/generic/UnivPoly.jl @@ -10,11 +10,11 @@ # ############################################################################### -base_ring_type(::Type{<:UniversalPolyRing{T}}) where T = parent_type(T) -base_ring(S::UniversalPolyRing) = base_ring(mpoly_ring(S))::base_ring_type(S) +base_ring_type(::Type{<:UniversalPolyRing{T}}) where T = mpoly_ring_type(T) +base_ring(S::UniversalPolyRing) = S.base_ring::base_ring_type(S) -coefficient_ring_type(T::Type{<:UniversalPolyRing}) = base_ring_type(T) -coefficient_ring(S::UniversalPolyRing) = base_ring(S) +coefficient_ring_type(::Type{<:UniversalPolyRing{T}}) where T = parent_type(T) +coefficient_ring(S::UniversalPolyRing) = coefficient_ring(base_ring(S))::coefficient_ring_type(S) function is_domain_type(::Type{<:UnivPoly{S}}) where {S <: RingElement} return is_domain_type(S) @@ -30,17 +30,13 @@ elem_type(::Type{UniversalPolyRing{T}}) where {T<:RingElement} = UnivPoly{T} parent_type(::Type{UnivPoly{T}}) where {T<:RingElement} = UniversalPolyRing{T} -function mpoly_ring(S::UniversalPolyRing{T}) where {T<:RingElement} - return S.mpoly_ring::mpoly_ring_type(T) -end - -number_of_variables(S::UniversalPolyRing) = number_of_variables(mpoly_ring(S)) +number_of_variables(S::UniversalPolyRing) = number_of_variables(base_ring(S)) -number_of_generators(S::UniversalPolyRing) = number_of_generators(mpoly_ring(S)) +number_of_generators(S::UniversalPolyRing) = number_of_generators(base_ring(S)) -symbols(S::UniversalPolyRing) = symbols(mpoly_ring(S)) +symbols(S::UniversalPolyRing) = symbols(base_ring(S)) -internal_ordering(p::UniversalPolyRing) = internal_ordering(mpoly_ring(p)) +internal_ordering(p::UniversalPolyRing) = internal_ordering(base_ring(p)) data(p::UnivPoly{T}) where {T<:RingElement} = p.p::mpoly_type(T) @@ -76,7 +72,7 @@ function coeff(p::UnivPoly, exps::Vector{Int}) n = nvars(parent(data(p))) if len > n if !iszero(exps[n + 1:len]) - return base_ring(S)() + return coefficient_ring(S)() end return coeff(data(p), exps[1:n]) end @@ -88,7 +84,7 @@ function coeff(p::UnivPoly, exps::Vector{Int}) end function setcoeff!(p::UnivPoly, exps::Vector{Int}, c::T) where T <: RingElement - c = base_ring(data(p))(c) + c = coefficient_ring(data(p))(c) S = parent(p) len = length(exps) upgrade!(p) @@ -110,9 +106,9 @@ end # ############################################################################### -zero(R::UniversalPolyRing{T}) where {T} = UnivPoly{T}(zero(mpoly_ring(R)), R) +zero(R::UniversalPolyRing{T}) where {T} = UnivPoly{T}(zero(base_ring(R)), R) -one(R::UniversalPolyRing{T}) where {T} = UnivPoly{T}(one(mpoly_ring(R)), R) +one(R::UniversalPolyRing{T}) where {T} = UnivPoly{T}(one(base_ring(R)), R) iszero(p::UnivPoly) = iszero(data(p)) @@ -231,7 +227,7 @@ function _ensure_variables(S::UniversalPolyRing, v::Vector{<:VarName}) end if !isempty(added_symbols) new_symbols = vcat(current_symbols, added_symbols) - S.mpoly_ring = AbstractAlgebra.polynomial_ring_only(base_ring(S), new_symbols; internal_ordering=internal_ordering(S), cached=false) + S.base_ring = AbstractAlgebra.polynomial_ring_only(coefficient_ring(S), new_symbols; internal_ordering=internal_ordering(S), cached=false) end return idx end @@ -242,14 +238,14 @@ function gen(S::UniversalPolyRing, s::VarName) new_symbols = copy(symbols(S)) push!(new_symbols, Symbol(s)) i = length(new_symbols) - S.mpoly_ring = AbstractAlgebra.polynomial_ring_only(base_ring(S), new_symbols; internal_ordering=internal_ordering(S), cached=false) + S.base_ring = AbstractAlgebra.polynomial_ring_only(coefficient_ring(S), new_symbols; internal_ordering=internal_ordering(S), cached=false) end return @inbounds gen(S, i) end function gen(S::UniversalPolyRing{T}, i::Int) where {T} @boundscheck 1 <= i <= nvars(S) || throw(ArgumentError("generator index out of range")) - return UnivPoly{T}(gen(mpoly_ring(S), i), S) + return UnivPoly{T}(gen(base_ring(S), i), S) end function gens(S::UniversalPolyRing{T}) where {T} @@ -263,7 +259,7 @@ function _univ_poly_gens(S::UniversalPolyRing{T}, vars::Vector{Symbol}) where {T idx = _ensure_variables(S, vars) # TRICK: @varnames_interface expects two return values, but we only care # for the second; so just return literally nothing for the first - return nothing, [UnivPoly{T}(gen(mpoly_ring(S), i), S) for i in idx] + return nothing, [UnivPoly{T}(gen(base_ring(S), i), S) for i in idx] end AbstractAlgebra.@varnames_interface _univ_poly_gens(R::UniversalPolyRing{T}, s) where {T} @@ -286,7 +282,7 @@ end canonical_unit(p::UnivPoly) = canonical_unit(data(p)) -characteristic(R::UniversalPolyRing) = characteristic(base_ring(R)) +characteristic(R::UniversalPolyRing) = characteristic(coefficient_ring(R)) function Base.hash(p::UnivPoly, h::UInt) b = 0xcf418d4529109236%UInt @@ -349,7 +345,7 @@ function show(io::IO, R::UniversalPolyRing) @show_name(io, R) @show_special(io, R) print(io, "Universal Polynomial Ring over ") - show(io, base_ring(R)) + show(io, coefficient_ring(R)) end function expressify(a::UnivPoly, x = symbols(parent(a)); context = nothing) @@ -828,7 +824,7 @@ is_univariate(p::UnivPoly) = is_univariate(data(p)) is_univariate_with_data(p::UnivPoly) = is_univariate_with_data(data(p)) -is_univariate(R::UniversalPolyRing) = is_univariate(mpoly_ring(R)) +is_univariate(R::UniversalPolyRing) = is_univariate(base_ring(R)) function coefficients_of_univariate(p::UnivPoly, check_univariate::Bool=true) return coefficients_of_univariate(data(p), check_univariate) @@ -844,7 +840,7 @@ _change_univ_poly_ring(R, Rx, cached::Bool) = universal_polynomial_ring(R, symbo function change_base_ring(R::Ring, p::UnivPoly{T}; cached::Bool=true, parent::UniversalPolyRing = _change_univ_poly_ring(R, parent(p), cached)) where {T <: RingElement} upgrade!(p) - return UnivPoly(change_base_ring(R, data(p); parent = mpoly_ring(parent)), parent) + return UnivPoly(change_base_ring(R, data(p); parent = base_ring(parent)), parent) end function change_coefficient_ring(R::Ring, p::UnivPoly{T}; cached::Bool=true, parent::UniversalPolyRing = _change_univ_poly_ring(R, parent(p), cached)) where {T <: RingElement} @@ -857,9 +853,9 @@ end # ################################################################################ -function map_coefficients(f::T, p::UnivPoly; cached::Bool=true, parent::UniversalPolyRing = _change_univ_poly_ring(parent(f(zero(base_ring(p)))), parent(p), cached)) where T +function map_coefficients(f::T, p::UnivPoly; cached::Bool=true, parent::UniversalPolyRing = _change_univ_poly_ring(parent(f(zero(coefficient_ring(p)))), parent(p), cached)) where T upgrade!(p) - return UnivPoly(map_coefficients(f, data(p); parent = mpoly_ring(parent)), parent) + return UnivPoly(map_coefficients(f, data(p); parent = base_ring(parent)), parent) end ############################################################################### @@ -888,7 +884,7 @@ RandomExtensions.maketype(S::AbstractAlgebra.UniversalPolyRing, _, _, _) = elem_ function RandomExtensions.make(S::AbstractAlgebra.UniversalPolyRing, term_range::AbstractUnitRange{Int}, exp_bound::AbstractUnitRange{Int}, vs...) - R = base_ring(S) + R = coefficient_ring(S) if length(vs) == 1 && elem_type(R) == Random.gentype(vs[1]) Make(S, term_range, exp_bound, vs[1]) else @@ -901,7 +897,7 @@ function rand(rng::AbstractRNG, sp::SamplerTrivial{<:Make4{ S, term_range, exp_bound, v = sp[][1:end] f = S() g = gens(S) - R = base_ring(S) + R = coefficient_ring(S) for i = 1:rand(rng, term_range) term = S(1) for j = 1:length(g) @@ -1049,7 +1045,7 @@ end function upgrade(S::UniversalPolyRing{T}, pp::MPolyRingElem{T}) where {T} n = nvars(S) - nvars(parent(pp)) if n > 0 - ctx = MPolyBuildCtx(mpoly_ring(S)) + ctx = MPolyBuildCtx(base_ring(S)) v0 = zeros(Int, n) for (c, v) in zip(coefficients(pp), exponent_vectors(pp)) push_term!(ctx, c, vcat(v, v0)) @@ -1066,19 +1062,19 @@ function upgrade!(p::UnivPoly) end function (a::UniversalPolyRing{T})(b::RingElement) where {T <: RingElement} - return a(base_ring(a)(b)) + return a(coefficient_ring(a)(b)) end function (a::UniversalPolyRing{T})() where {T <: RingElement} - return UnivPoly{T}(mpoly_ring(a)(), a) + return UnivPoly{T}(base_ring(a)(), a) end function (a::UniversalPolyRing{T})(b::JuliaRingElement) where {T <: RingElement} - return UnivPoly{T}(mpoly_ring(a)(b), a) + return UnivPoly{T}(base_ring(a)(b), a) end function (a::UniversalPolyRing{T})(b::T) where {T <: RingElem} - return UnivPoly{T}(mpoly_ring(a)(b), a) + return UnivPoly{T}(base_ring(a)(b), a) end function (S::UniversalPolyRing{T})(p::UnivPoly{T}) where {T <: RingElement} @@ -1089,12 +1085,12 @@ end function (a::UniversalPolyRing{T})(b::Vector{T}, m::Vector{Vector{Int}}) where {T <: RingElement} if length(m) != 0 len = length(m[1]) - num = nvars(mpoly_ring(a)) + num = nvars(base_ring(a)) if len != num for i = 1:length(m) m[i] = vcat(m[i], zeros(Int, num - len)) end end end - return UnivPoly{T}(mpoly_ring(a)(b, m), a) + return UnivPoly{T}(base_ring(a)(b, m), a) end diff --git a/test/generic/UnivPoly-test.jl b/test/generic/UnivPoly-test.jl index 1b9324365b..9c4249741d 100644 --- a/test/generic/UnivPoly-test.jl +++ b/test/generic/UnivPoly-test.jl @@ -29,7 +29,7 @@ @test elem_type(Generic.UniversalPolyRing{elem_type(R)}) == Generic.UnivPoly{elem_type(R)} @test parent_type(Generic.UnivPoly{elem_type(R)}) == Generic.UniversalPolyRing{elem_type(R)} - @test base_ring(S) === R + @test coefficient_ring(S) === R @test coefficient_ring(S) === R @test coefficient_ring_type(S) === typeof(R) @@ -137,10 +137,10 @@ end @test parent(f2) === S @test parent(f3) === S - @test base_ring(S) === R - @test base_ring(f1) === R - @test base_ring(f2) === R - @test base_ring(f3) === R + @test coefficient_ring(S) === R + @test coefficient_ring(f1) === R + @test coefficient_ring(f2) === R + @test coefficient_ring(f3) === R @test nvars(S) == 3 @@ -1119,9 +1119,9 @@ end @test length(g) == length(g1) @test length(h) == length(h1) - @test base_ring(f1) === U - @test base_ring(g1) === U - @test base_ring(h1) === U + @test coefficient_ring(f1) === U + @test coefficient_ring(g1) === U + @test coefficient_ring(h1) === U f2 = map_coefficients(x->x^2, f) g2 = map_coefficients(x->x^2, g)