Skip to content

Commit

Permalink
Add many @req !is_trivial checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Oct 11, 2024
1 parent 9ebc781 commit e26b4c9
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/src/constructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ AbstractAlgebra.jl and explain what mathematical domains they represent.
| $S = K((x))$ (to precision $n$) | `S, x = laurent_series_field(K, n, :x)` |
| $S = R((x, y))$ (to precision $n$) | `S, (x, y) = laurent_polynomial_ring(R, n, [:x, :y])` |
| Puiseux series ring to precision $n$ | `S, x = puiseux_series_ring(R, n, :x)` |
| Puiseux series field to precision $n$| `S, x = puiseux_series_field(R, n, :x)` |
| Puiseux series field to precision $n$| `S, x = puiseux_series_field(K, n, :x)` |
| $S = K(x)(y)/(f)$ | `S, y = function_field(f, :y)` with $f\in K(x)[t]$ |
| $S = \mathrm{Frac}_R$ | `S = fraction_field(R)` |
| $S = R/(f)$ | `S, = residue_ring(R, f)` |
Expand Down
1 change: 1 addition & 0 deletions src/Fraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ that it will always be returned by a call to the constructor when the same
base ring $R$ is supplied.
"""
function fraction_field(R::Ring; cached::Bool=true)
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
return Generic.fraction_field(R; cached=cached)
end

Expand Down
1 change: 1 addition & 0 deletions src/FreeAssociativeAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ function free_associative_algebra(
s::Vector{Symbol};
cached::Bool = true,
)
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
parent_obj = Generic.FreeAssociativeAlgebra{elem_type(R)}(R, s, cached)
return (parent_obj, gens(parent_obj))
end
Expand Down
6 changes: 4 additions & 2 deletions src/LaurentPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ julia> rand(R, -3:3, -9:9)
-3*x^2 - 8*x + 4 + 3*x^-1 - 6*x^-2 + 9*x^-3
```
"""
laurent_polynomial_ring(R::Ring, s::VarName; cached::Bool = true) =
Generic.laurent_polynomial_ring(R, Symbol(s); cached)
function laurent_polynomial_ring(R::Ring, s::VarName; cached::Bool = true)
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
return Generic.laurent_polynomial_ring(R, Symbol(s); cached)
end
6 changes: 4 additions & 2 deletions src/LaurentSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ object `S` will be cached so that supplying the same base ring, string and
precision in future will return the same parent object and generator. If
caching of the parent object is not required, `cached` can be set to `false`.
"""
laurent_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true) =
Generic.laurent_series_ring(R, prec, Symbol(s); cached)
function laurent_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true)
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
return Generic.laurent_series_ring(R, prec, Symbol(s); cached)
end

@doc raw"""
laurent_series_field(R::Field, prec::Int, s::VarName; cached::Bool=true)
Expand Down
6 changes: 4 additions & 2 deletions src/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1508,5 +1508,7 @@ 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}; internal_ordering::Symbol=:lex, cached::Bool=true) where T<:Ring =
mpoly_ring_type(T)(R, s, internal_ordering, cached)
function polynomial_ring_only(R::T, s::Vector{Symbol}; internal_ordering::Symbol=:lex, cached::Bool=true) where T<:Ring
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
return mpoly_ring_type(T)(R, s, internal_ordering, cached)
end
3 changes: 2 additions & 1 deletion src/MatRing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -441,5 +441,6 @@ Return parent object corresponding to the ring of $n\times n$ matrices over
the ring $R$.
"""
function matrix_ring(R::NCRing, n::Int)
Generic.matrix_ring(R, n)
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
return Generic.matrix_ring(R, n)
end
4 changes: 4 additions & 0 deletions src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6633,6 +6633,7 @@ randmat_with_rank(S::MatSpace{T}, rank::Int, v...) where {T <: RingElement} =
Constructs the matrix over $R$ with entries as in `arr`.
"""
function matrix(R::NCRing, arr::AbstractMatrix{T}) where {T}
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
if elem_type(R) === T && all(e -> parent(e) === R, arr)
z = Generic.MatSpaceElem{elem_type(R)}(R, arr)
return z
Expand All @@ -6643,6 +6644,7 @@ function matrix(R::NCRing, arr::AbstractMatrix{T}) where {T}
end

function matrix(R::NCRing, arr::MatElem)
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
return map_entries(R, arr)
end

Expand Down Expand Up @@ -6681,6 +6683,7 @@ Constructs the $r \times c$ matrix over $R$, where the entries are taken
row-wise from `arr`.
"""
function matrix(R::NCRing, r::Int, c::Int, arr::AbstractVecOrMat{T}) where T
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
_check_dim(r, c, arr)
ndims(arr) == 2 && return matrix(R, arr)
if elem_type(R) === T && all(e -> parent(e) === R, arr)
Expand Down Expand Up @@ -7062,6 +7065,7 @@ the ring $R$.
function matrix_space(R::NCRing, r::Int, c::Int; cached::Bool = true)
# TODO: the 'cached' argument is ignored and mainly here for backwards compatibility
# (and perhaps future compatibility, in case we need it again)
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
(r < 0 || c < 0) && error("Dimensions must be non-negative")
T = elem_type(R)
return MatSpace{T}(R, r, c)
Expand Down
6 changes: 4 additions & 2 deletions src/NCPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,10 @@ end
Like [`polynomial_ring(R::NCRing, s::Symbol)`](@ref) but return only the
polynomial ring.
"""
polynomial_ring_only(R::T, s::Symbol; cached::Bool=true) where T<:NCRing =
dense_poly_ring_type(T)(R, s, cached)
function polynomial_ring_only(R::T, s::Symbol; cached::Bool=true) where T<:NCRing
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
return dense_poly_ring_type(T)(R, s, cached)
end

# Simplified constructor

Expand Down
11 changes: 7 additions & 4 deletions src/PuiseuxSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ object `S` will be cached so that supplying the same base ring, string and
precision in future will return the same parent object and generator. If
caching of the parent object is not required, `cached` can be set to `false`.
"""
puiseux_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true) =
Generic.PuiseuxSeriesRing(R, prec, Symbol(s); cached)
function puiseux_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true)
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
return Generic.PuiseuxSeriesRing(R, prec, Symbol(s); cached)
end

puiseux_series_field(R::Field, prec::Int, s::VarName; cached::Bool=true) =
Generic.PuiseuxSeriesField(R, prec, Symbol(s); cached)
function puiseux_series_field(R::Field, prec::Int, s::VarName; cached::Bool=true)
return Generic.PuiseuxSeriesField(R, prec, Symbol(s); cached)
end
6 changes: 4 additions & 2 deletions src/RelSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1473,8 +1473,10 @@ object `S` will be cached so that supplying the same base ring, string and
precision in future will return the same parent object and generator. If
caching of the parent object is not required, `cached` can be set to `false`.
"""
power_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true, model::Symbol=:capped_relative) =
Generic.power_series_ring(R, prec, Symbol(s); cached, model)
function power_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true, model::Symbol=:capped_relative)
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
return Generic.power_series_ring(R, prec, Symbol(s); cached, model)
end

function AbsPowerSeriesRing(R::Ring, prec::Int)
T = elem_type(R)
Expand Down
2 changes: 2 additions & 0 deletions src/Residue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ to the constructor with the same base ring $R$ and element $a$. A modulus
of zero is not supported and throws an exception.
"""
function residue_ring(R::Ring, a::RingElement; cached::Bool = true)
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
# Modulus of zero cannot be supported. E.g. A C library could not be expected to
# do matrices over Z/0 using a Z/nZ type. The former is multiprecision, the latter not.
iszero(a) && throw(DomainError(a, "Modulus must be nonzero"))
Expand All @@ -459,6 +460,7 @@ function residue_ring(R::Ring, a::RingElement; cached::Bool = true)
end

function residue_ring(R::PolyRing, a::RingElement; cached::Bool = true)
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
iszero(a) && throw(DomainError(a, "Modulus must be nonzero"))
!is_unit(leading_coefficient(a)) && throw(DomainError(a, "Non-invertible leading coefficient"))
T = elem_type(R)
Expand Down
1 change: 1 addition & 0 deletions src/ResidueField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ residue ring parent object is cached and returned for any subsequent calls
to the constructor with the same base ring $R$ and element $a$.
"""
function residue_field(R::Ring, a::RingElement; cached::Bool = true)
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
iszero(a) && throw(DivideError())
T = elem_type(R)
S = EuclideanRingResidueField{T}(R(a), cached)
Expand Down
4 changes: 4 additions & 0 deletions src/generic/AbsMSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ end

function power_series_ring(R::AbstractAlgebra.Ring, prec::Vector{Int},
s::Vector{Symbol}; cached::Bool=true, model=:capped_absolute)

@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
U = elem_type(R)

S, _ = AbstractAlgebra.polynomial_ring(R, s)
Expand All @@ -724,6 +726,8 @@ end
function power_series_ring(R::AbstractAlgebra.Ring, prec::Int,
s::Vector{Symbol}; weights::Union{Vector{Int}, Nothing}=nothing,
cached::Bool=true, model=:capped_absolute)

@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
U = elem_type(R)

S, _ = AbstractAlgebra.polynomial_ring(R, s)
Expand Down
1 change: 1 addition & 0 deletions src/generic/LaurentMPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ end
###############################################################################

function laurent_polynomial_ring(R::AbstractAlgebra.Ring, s::Vector{Symbol}; cached::Bool = true)
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
P, x = AbstractAlgebra.polynomial_ring(R, s, cached = cached)
R = LaurentMPolyWrapRing(P, cached)
R, map(p -> LaurentMPolyWrap(R, p), x)
Expand Down
1 change: 1 addition & 0 deletions src/generic/LaurentPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ end
###############################################################################

function laurent_polynomial_ring(R::AbstractAlgebra.Ring, s::Symbol; cached::Bool = true)
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
P, x = AbstractAlgebra.polynomial_ring(R, s, cached = cached)
R = LaurentPolyWrapRing(P, cached)
R, LaurentPolyWrap(R, x)
Expand Down
1 change: 1 addition & 0 deletions src/generic/RelSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ end
###############################################################################

function power_series_ring(R::AbstractAlgebra.Ring, prec::Int, s::VarName; cached::Bool=true, model::Symbol=:capped_relative)
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
T = elem_type(R)

if model == :capped_relative
Expand Down
1 change: 1 addition & 0 deletions src/generic/UnivPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,7 @@ x*y - z
```
"""
function universal_polynomial_ring(R::Ring; cached::Bool=true, internal_ordering::Symbol=:lex)
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
T = elem_type(R)
U = mpoly_type(R)

Expand Down

0 comments on commit e26b4c9

Please sign in to comment.