Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide ordering a bit #1597

Merged
merged 7 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/ideal.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contain duplicates, zero entries or be empty.
**Examples**

```jldoctest
julia> R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; ordering=:degrevlex)
julia> R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; internal_ordering=:degrevlex)
(Multivariate polynomial ring in 2 variables over integers, AbstractAlgebra.Generic.MPoly{BigInt}[x, y])

julia> V = [3*x^2*y - 3*y^2, 9*x^2*y + 7*x*y]
Expand Down Expand Up @@ -170,7 +170,7 @@ normal_form(::U, ::Generic.Ideal{U}) where {T <: RingElement, U <: Union{PolyRin
**Examples**

```jldoctest
julia> R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; ordering=:degrevlex)
julia> R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; internal_ordering=:degrevlex)
(Multivariate polynomial ring in 2 variables over integers, AbstractAlgebra.Generic.MPoly{BigInt}[x, y])

julia> V = [3*x^2*y - 3*y^2, 9*x^2*y + 7*x*y]
Expand Down
2 changes: 1 addition & 1 deletion docs/src/mpoly_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Return the $i$-th generator (variable) of the given polynomial ring (as a
polynomial).

```julia
ordering(S::MyMPolyRing{T})
internal_ordering(S::MyMPolyRing{T})
```

Return the ordering of the given polynomial ring as a symbol. Supported values currently
Expand Down
10 changes: 5 additions & 5 deletions docs/src/mpolynomial.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ring.
**Examples**

```jldoctest
julia> R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; ordering=:deglex)
julia> R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; internal_ordering=:deglex)
(Multivariate polynomial ring in 2 variables over integers, AbstractAlgebra.Generic.MPoly{BigInt}[x, y])

julia> T, (z, t) = QQ["z", "t"]
Expand Down Expand Up @@ -231,7 +231,7 @@ gen(S::MPolyRing, i::Int)
```

```julia
ordering(S::MPolyRing{T})
internal_ordering(S::MPolyRing{T})
```

Note that the currently supported orderings are `:lex`, `:deglex` and
Expand Down Expand Up @@ -430,7 +430,7 @@ x^3*y
julia> setcoeff!(f, [3, 1], 12)
12*x^3*y + 3*x*y^2 + 1

julia> S, (x, y) = polynomial_ring(QQ, ["x", "y"]; ordering=:deglex)
julia> S, (x, y) = polynomial_ring(QQ, ["x", "y"]; internal_ordering=:deglex)
(Multivariate polynomial ring in 2 variables over rationals, AbstractAlgebra.Generic.MPoly{Rational{BigInt}}[x, y])

julia> V = symbols(S)
Expand All @@ -443,7 +443,7 @@ julia> X = gens(S)
x
y

julia> ord = ordering(S)
julia> ord = internal_ordering(S)
:deglex

julia> S, (x, y) = polynomial_ring(ZZ, ["x", "y"])
Expand Down Expand Up @@ -836,7 +836,7 @@ tail(::MPolyRingElem{T}) where T <: RingElement

```julia
using AbstractAlgebra
R,(x,y) = polynomial_ring(ZZ, ["x", "y"], ordering=:deglex)
R,(x,y) = polynomial_ring(ZZ, ["x", "y"], internal_ordering=:deglex)
p = 2*x*y + 3*y^3 + 1
leading_term(p)
leading_monomial(p)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/univpolynomial.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The universal polynomial ring over a given base ring `R` is constructed with
one of the following constructor functions.

```julia
UniversalPolynomialRing(R::Ring; cached::Bool = true, ordering::Symbol=:lex)
UniversalPolynomialRing(R::Ring; cached::Bool = true, internal_ordering::Symbol=:lex)
```

Given a base ring `R` and an array `S` of strings, return an object representing
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ import .Generic: hash
import .Generic: hooklength
import .Generic: image_fn
import .Generic: image_map
import .Generic: internal_ordering
import .Generic: interreduce!
import .Generic: inv!
import .Generic: inverse_fn
Expand Down Expand Up @@ -637,7 +638,6 @@ import .Generic: normalise
import .Generic: num_coeff
import .Generic: one
import .Generic: order
import .Generic: ordering
import .Generic: parity
import .Generic: partitionseq
import .Generic: perm
Expand Down Expand Up @@ -858,6 +858,7 @@ export image_fn
export image_map
export inflate
export integral
export internal_ordering
export interpolate
export inv!
export invariant_factors
Expand Down Expand Up @@ -988,7 +989,6 @@ export O
export one
export one!
export order
export ordering
export parent_type
export parity
export Partition
Expand Down
25 changes: 13 additions & 12 deletions src/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
biggest = -1
if length(f) != 0
R = parent(f)
if ordering(R) == :lex && i == 1
if internal_ordering(R) == :lex && i == 1

Check warning on line 376 in src/MPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/MPoly.jl#L376

Added line #L376 was not covered by tests
biggest = first(exponent_vectors(f))[1]
else
for v in exponent_vectors(f)
Expand Down Expand Up @@ -402,7 +402,7 @@
"""
function degrees(f::MPolyRingElem{T}) where T <: RingElement
R = parent(f)
if nvars(R) == 1 && ordering(R) == :lex && length(f) > 0
if nvars(R) == 1 && internal_ordering(R) == :lex && length(f) > 0
return first(exponent_vectors(f))
else
biggest = [-1 for i = 1:nvars(R)]
Expand Down Expand Up @@ -1211,7 +1211,7 @@
################################################################################

function _change_mpoly_ring(R, Rx, cached)
P, _ = polynomial_ring(R, map(string, symbols(Rx)), ordering = ordering(Rx), cached = cached)
P, _ = polynomial_ring(R, map(string, symbols(Rx)); internal_ordering = internal_ordering(Rx), cached = cached)
return P
end

Expand Down Expand Up @@ -1346,7 +1346,7 @@
###############################################################################

@doc raw"""
polynomial_ring(R::Ring, varnames::Vector{Symbol}; cached=true, ordering=:lex)
polynomial_ring(R::Ring, varnames::Vector{Symbol}; cached=true, internal_ordering=:lex)

Given a coefficient ring `R` and variable names, say `varnames = [:x1, :x2, ...]`,
return a tuple `S, [x1, x2, ...]` of the polynomial ring $S = R[x1, x2, \dots]$
Expand All @@ -1357,7 +1357,8 @@
(*identical*) ring is returned. Setting `cached` to `false` ensures a distinct
new ring is returned, and will also prevent it from being cached.

The `ordering` of the polynomial ring can be one of `:lex`, `:deglex` or `:degrevlex`.
The monomial ordering used for the internal storage of polynomials in `S` can be
set with `internal_ordering` and must be one of `:lex`, `:deglex` or `:degrevlex`.

See also: [`polynomial_ring(::Ring, ::Vararg)`](@ref), [`@polynomial_ring`](@ref).

Expand All @@ -1374,8 +1375,8 @@
end

"""
polynomial_ring(R::Ring, varnames...; cached=true, ordering=:lex)
polynomial_ring(R::Ring, varnames::Tuple; cached=true, ordering=:lex)
polynomial_ring(R::Ring, varnames...; cached=true, internal_ordering=:lex)
polynomial_ring(R::Ring, varnames::Tuple; cached=true, internal_ordering=:lex)

Like [`polynomial_ring(::Ring, ::Vector{Symbol})`](@ref) with more ways to give
`varnames` as specified in [`variable_names`](@ref).
Expand Down Expand Up @@ -1414,7 +1415,7 @@
polynomial_ring(R::Ring, varnames...)

@doc raw"""
polynomial_ring(R::Ring, n::Int, s::Symbol=:x; cached=true, ordering=:lex)
polynomial_ring(R::Ring, n::Int, s::Symbol=:x; cached=true, internal_ordering=:lex)

Same as [`polynomial_ring(::Ring, ["s$i" for i in 1:n])`](@ref polynomial_ring(::Ring, ::Vector{Symbol})).

Expand All @@ -1428,7 +1429,7 @@
polynomial_ring(R::Ring, n::Int, s::Symbol=:x)

"""
@polynomial_ring(R::Ring, varnames...; cached=true, ordering=:lex)
@polynomial_ring(R::Ring, varnames...; cached=true, internal_ordering=:lex)

Return polynomial ring from [`polynomial_ring(::Ring, ::Vararg)`](@ref) and
introduce the generators into the current scope.
Expand All @@ -1453,13 +1454,13 @@
:(@polynomial_ring)

"""
polynomial_ring_only(R::Ring, s::Vector{Symbol}; ordering::Symbol=:lex, cached::Bool=true)
polynomial_ring_only(R::Ring, s::Vector{Symbol}; internal_ordering::Symbol=:lex, cached::Bool=true)

Like [`polynomial_ring(R::Ring, s::Vector{Symbol})`](@ref) but return only the
multivariate polynomial ring.
"""
polynomial_ring_only(R::T, s::Vector{Symbol}; ordering::Symbol=:lex, cached::Bool=true) where T<:Ring =
mpoly_ring_type(T)(R, s, ordering, cached)
polynomial_ring_only(R::T, s::Vector{Symbol}; internal_ordering::Symbol=:lex, cached::Bool=true) where T<:Ring =
mpoly_ring_type(T)(R, s, internal_ordering, cached)

# Alternative constructors

Expand Down
4 changes: 2 additions & 2 deletions src/UnivPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ end
#
###############################################################################

function UniversalPolynomialRing(R::Ring; ordering=:lex, cached::Bool=true)
return Generic.UniversalPolynomialRing(R; ordering=ordering, cached=cached)
function UniversalPolynomialRing(R::Ring; internal_ordering=:lex, cached::Bool=true)
return Generic.UniversalPolynomialRing(R; internal_ordering=internal_ordering, cached=cached)
end
6 changes: 3 additions & 3 deletions src/generic/GenericTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ end
end
end

function MPolyRing{T}(R::Ring, s::Vector{Symbol}, ordering::Symbol=:lex, cached::Bool=true) where T <: RingElement
function MPolyRing{T}(R::Ring, s::Vector{Symbol}, internal_ordering::Symbol=:lex, cached::Bool=true) where T <: RingElement
@assert T == elem_type(R)
N = length(s)
ordering in (:deglex, :degrevlex) && (N+=1)
return MPolyRing{T}(R, s, ordering, N, cached)
internal_ordering in (:deglex, :degrevlex) && (N+=1)
return MPolyRing{T}(R, s, internal_ordering, N, cached)
end

const MPolyID = CacheDictType{Tuple{Ring, Vector{Symbol}, Symbol, Int}, Ring}()
Expand Down
6 changes: 3 additions & 3 deletions src/generic/Ideal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ function reduce_gens(I::Ideal{U}; complete_reduction::Bool=true) where {T <: Rin
# nothing to be done if only one poly
if length(B) > 1
# make heap
V = ordering(parent(B[1]))
V = internal_ordering(parent(B[1]))
N = nvars(base_ring(I))
heap = Vector{lmnode{U, V, N}}()
for v in B
Expand Down Expand Up @@ -2169,7 +2169,7 @@ function intersect(I::Ideal{T}, J::Ideal{T}) where {U <: RingElement, T <: Abstr
R = base_ring(S) # coefficient ring
# create ring with additional variable "t" with higher precedence
tsym = gensym()
Sup, Supv = AbstractAlgebra.polynomial_ring(R, vcat(tsym, symbols(S)); cached=false, ordering=:degrevlex)
Sup, Supv = AbstractAlgebra.polynomial_ring(R, vcat(tsym, symbols(S)); cached=false, internal_ordering=:degrevlex)
G1 = gens(I)
G2 = gens(J)
ISup = Ideal(Sup, elem_type(Sup)[f(Supv[2:end]...) for f in G1])
Expand All @@ -2192,7 +2192,7 @@ function intersect(I::Ideal{T}, J::Ideal{T}) where {U <: RingElement, T <: Abstr
R = base_ring(S) # coefficient ring
# create ring with additional variable "t" with higher precedence
tsym = gensym()
Sup, Supv = AbstractAlgebra.polynomial_ring(R, vcat(tsym, symbols(S)); cached=false, ordering=ordering(S))
Sup, Supv = AbstractAlgebra.polynomial_ring(R, vcat(tsym, symbols(S)); cached=false, internal_ordering=internal_ordering(S))
G1 = gens(I)
G2 = gens(J)
ISup = Ideal(Sup, elem_type(Sup)[f(Supv[2:end]...) for f in G1])
Expand Down
8 changes: 4 additions & 4 deletions src/generic/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ function vars(p::MPoly{T}) where {T <: RingElement}
end

@doc raw"""
ordering(a::MPolyRing{T}) where {T <: RingElement}
internal_ordering(a::MPolyRing{T}) where {T <: RingElement}

Return the ordering of the given polynomial ring as a symbol. The options are
`:lex`, `:deglex` and `:degrevlex`.
"""
function ordering(a::MPolyRing{T}) where {T <: RingElement}
function internal_ordering(a::MPolyRing{T}) where {T <: RingElement}
return a.ord
end

Expand Down Expand Up @@ -815,7 +815,7 @@ Return the total degree of `f`.
function total_degree(f::MPoly{T}) where {T <: RingElement}
A = f.exps
N = size(A, 1)
ord = ordering(parent(f))
ord = internal_ordering(parent(f))
if ord == :lex
if N == 1
return length(f) == 0 ? -1 : Int(A[1, N])
Expand Down Expand Up @@ -4102,7 +4102,7 @@ function (a::MPolyRing{T})(b::Vector{T}, m::Vector{Vector{Int}}) where {T <: Rin
end

N = a.N
ord = ordering(a)
ord = internal_ordering(a)
Pe = Matrix{UInt}(undef, N, length(m))

if ord == :lex
Expand Down
10 changes: 5 additions & 5 deletions src/generic/UnivPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function vars(p::UnivPoly{T, U}) where {T, U}
return [UnivPoly{T, U}(v, S) for v in V]
end

ordering(p::UniversalPolyRing) = ordering(mpoly_ring(p))
internal_ordering(p::UniversalPolyRing) = internal_ordering(mpoly_ring(p))

function check_parent(a::UnivPoly{T, U}, b::UnivPoly{T, U}, throw::Bool = true) where {T <: RingElement, U <: AbstractAlgebra.MPolyRingElem{T}}
flag = parent(a) != parent(b)
Expand Down Expand Up @@ -904,8 +904,8 @@ end
################################################################################

function _change_univ_poly_ring(R, Rx, cached::Bool)
P, _ = AbstractAlgebra.polynomial_ring(R, map(string, symbols(Rx)), ordering = ordering(Rx), cached = cached)
S = AbstractAlgebra.UniversalPolynomialRing(R; ordering=ordering(Rx), cached=cached)
P, _ = AbstractAlgebra.polynomial_ring(R, map(string, symbols(Rx)), internal_ordering = internal_ordering(Rx), cached = cached)
S = AbstractAlgebra.UniversalPolynomialRing(R; internal_ordering=internal_ordering(Rx), cached=cached)
S.S = deepcopy(symbols(Rx))
S.mpoly_ring = P
return S
Expand Down Expand Up @@ -1120,10 +1120,10 @@ end
#
###############################################################################

function UniversalPolynomialRing(R::Ring; ordering=:lex, cached::Bool=true)
function UniversalPolynomialRing(R::Ring; internal_ordering=:lex, cached::Bool=true)
T = elem_type(R)
U = Generic.MPoly{T}

return UniversalPolyRing{T, U}(R, ordering, cached)
return UniversalPolyRing{T, U}(R, internal_ordering, cached)
end

2 changes: 1 addition & 1 deletion test/algorithms/MPolyEvaluate-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end
end

@testset "MPolyEvaluate.ZZ(QQ)" begin
R, (x, y, z, t) = polynomial_ring(ZZ, ["x", "y", "z", "t"], ordering = :degrevlex)
R, (x, y, z, t) = polynomial_ring(ZZ, ["x", "y", "z", "t"], internal_ordering = :degrevlex)
test_evaluate(zero(R), [QQ(), QQ(), QQ(), QQ()])
test_evaluate(one(R), [QQ(), QQ(), QQ(), QQ()])
for i in 1:100
Expand Down
16 changes: 8 additions & 8 deletions test/generic/Ideal-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ end
end

@testset "Generic.Ideal.ideal_reduction(multivariate)" begin
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; ordering=:degrevlex)
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; internal_ordering=:degrevlex)
for V in example_ideal_gens(x, y)
@test testit(R, V)
end

R, (x, y, z) = polynomial_ring(ZZ, ["x", "y", "z"]; ordering=:degrevlex)
R, (x, y, z) = polynomial_ring(ZZ, ["x", "y", "z"]; internal_ordering=:degrevlex)
for V in example_ideal_gens(x, y, z)
@test testit(R, V)
end
Expand Down Expand Up @@ -262,7 +262,7 @@ end

@testset "Generic.Ideal.comparison" begin
# multivariate
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; ordering=:degrevlex)
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; internal_ordering=:degrevlex)

ex = example_ideal_gens(x, y)
for V in ex[1:28] # 29 and beyond are too slow for some RNG seeds
Expand Down Expand Up @@ -306,7 +306,7 @@ end

@testset "Generic.Ideal.containment" begin
# multivariate
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; ordering=:degrevlex)
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; internal_ordering=:degrevlex)

ex = example_ideal_gens(x, y)
for V in ex[1:15], W in ex[1:15]
Expand Down Expand Up @@ -369,7 +369,7 @@ end

@testset "Generic.Ideal.addition" begin
# multivariate
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; ordering=:degrevlex)
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; internal_ordering=:degrevlex)

ex = example_ideal_gens(x, y)
for V in ex[1:15], W in ex[1:15]
Expand Down Expand Up @@ -431,7 +431,7 @@ end

@testset "Generic.Ideal.multiplication" begin
# multivariate
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; ordering=:degrevlex)
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; internal_ordering=:degrevlex)

ex = example_ideal_gens(x, y)
for V in ex[1:10], W in ex[1:10], X in ex[1:10]
Expand Down Expand Up @@ -499,7 +499,7 @@ end

@testset "Generic.Ideal.adhoc_multiplication" begin
# multivariate
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; ordering=:degrevlex)
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; internal_ordering=:degrevlex)

# random examples
for V in example_ideal_gens(x, y)
Expand Down Expand Up @@ -564,7 +564,7 @@ end

@testset "Generic.Ideal.intersect" begin
# multivariate
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; ordering=:degrevlex)
R, (x, y) = polynomial_ring(ZZ, ["x", "y"]; internal_ordering=:degrevlex)

ex = example_ideal_gens(x, y)
for V in ex[1:10], W in ex[1:10]
Expand Down
Loading
Loading