Skip to content

Commit e26b4c9

Browse files
committed
Add many @req !is_trivial checks
1 parent 9ebc781 commit e26b4c9

18 files changed

+47
-16
lines changed

docs/src/constructors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ AbstractAlgebra.jl and explain what mathematical domains they represent.
7474
| $S = K((x))$ (to precision $n$) | `S, x = laurent_series_field(K, n, :x)` |
7575
| $S = R((x, y))$ (to precision $n$) | `S, (x, y) = laurent_polynomial_ring(R, n, [:x, :y])` |
7676
| Puiseux series ring to precision $n$ | `S, x = puiseux_series_ring(R, n, :x)` |
77-
| Puiseux series field to precision $n$| `S, x = puiseux_series_field(R, n, :x)` |
77+
| Puiseux series field to precision $n$| `S, x = puiseux_series_field(K, n, :x)` |
7878
| $S = K(x)(y)/(f)$ | `S, y = function_field(f, :y)` with $f\in K(x)[t]$ |
7979
| $S = \mathrm{Frac}_R$ | `S = fraction_field(R)` |
8080
| $S = R/(f)$ | `S, = residue_ring(R, f)` |

src/Fraction.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ that it will always be returned by a call to the constructor when the same
823823
base ring $R$ is supplied.
824824
"""
825825
function fraction_field(R::Ring; cached::Bool=true)
826+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
826827
return Generic.fraction_field(R; cached=cached)
827828
end
828829

src/FreeAssociativeAlgebra.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ function free_associative_algebra(
270270
s::Vector{Symbol};
271271
cached::Bool = true,
272272
)
273+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
273274
parent_obj = Generic.FreeAssociativeAlgebra{elem_type(R)}(R, s, cached)
274275
return (parent_obj, gens(parent_obj))
275276
end

src/LaurentPoly.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ julia> rand(R, -3:3, -9:9)
3939
-3*x^2 - 8*x + 4 + 3*x^-1 - 6*x^-2 + 9*x^-3
4040
```
4141
"""
42-
laurent_polynomial_ring(R::Ring, s::VarName; cached::Bool = true) =
43-
Generic.laurent_polynomial_ring(R, Symbol(s); cached)
42+
function laurent_polynomial_ring(R::Ring, s::VarName; cached::Bool = true)
43+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
44+
return Generic.laurent_polynomial_ring(R, Symbol(s); cached)
45+
end

src/LaurentSeries.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ object `S` will be cached so that supplying the same base ring, string and
2424
precision in future will return the same parent object and generator. If
2525
caching of the parent object is not required, `cached` can be set to `false`.
2626
"""
27-
laurent_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true) =
28-
Generic.laurent_series_ring(R, prec, Symbol(s); cached)
27+
function laurent_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true)
28+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
29+
return Generic.laurent_series_ring(R, prec, Symbol(s); cached)
30+
end
2931

3032
@doc raw"""
3133
laurent_series_field(R::Field, prec::Int, s::VarName; cached::Bool=true)

src/MPoly.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,5 +1508,7 @@ true
15081508
Like [`polynomial_ring(R::Ring, s::Vector{Symbol})`](@ref) but return only the
15091509
multivariate polynomial ring.
15101510
"""
1511-
polynomial_ring_only(R::T, s::Vector{Symbol}; internal_ordering::Symbol=:lex, cached::Bool=true) where T<:Ring =
1512-
mpoly_ring_type(T)(R, s, internal_ordering, cached)
1511+
function polynomial_ring_only(R::T, s::Vector{Symbol}; internal_ordering::Symbol=:lex, cached::Bool=true) where T<:Ring
1512+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
1513+
return mpoly_ring_type(T)(R, s, internal_ordering, cached)
1514+
end

src/MatRing.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,5 +441,6 @@ Return parent object corresponding to the ring of $n\times n$ matrices over
441441
the ring $R$.
442442
"""
443443
function matrix_ring(R::NCRing, n::Int)
444-
Generic.matrix_ring(R, n)
444+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
445+
return Generic.matrix_ring(R, n)
445446
end

src/Matrix.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6633,6 +6633,7 @@ randmat_with_rank(S::MatSpace{T}, rank::Int, v...) where {T <: RingElement} =
66336633
Constructs the matrix over $R$ with entries as in `arr`.
66346634
"""
66356635
function matrix(R::NCRing, arr::AbstractMatrix{T}) where {T}
6636+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
66366637
if elem_type(R) === T && all(e -> parent(e) === R, arr)
66376638
z = Generic.MatSpaceElem{elem_type(R)}(R, arr)
66386639
return z
@@ -6643,6 +6644,7 @@ function matrix(R::NCRing, arr::AbstractMatrix{T}) where {T}
66436644
end
66446645

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

@@ -6681,6 +6683,7 @@ Constructs the $r \times c$ matrix over $R$, where the entries are taken
66816683
row-wise from `arr`.
66826684
"""
66836685
function matrix(R::NCRing, r::Int, c::Int, arr::AbstractVecOrMat{T}) where T
6686+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
66846687
_check_dim(r, c, arr)
66856688
ndims(arr) == 2 && return matrix(R, arr)
66866689
if elem_type(R) === T && all(e -> parent(e) === R, arr)
@@ -7062,6 +7065,7 @@ the ring $R$.
70627065
function matrix_space(R::NCRing, r::Int, c::Int; cached::Bool = true)
70637066
# TODO: the 'cached' argument is ignored and mainly here for backwards compatibility
70647067
# (and perhaps future compatibility, in case we need it again)
7068+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
70657069
(r < 0 || c < 0) && error("Dimensions must be non-negative")
70667070
T = elem_type(R)
70677071
return MatSpace{T}(R, r, c)

src/NCPoly.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,10 @@ end
764764
Like [`polynomial_ring(R::NCRing, s::Symbol)`](@ref) but return only the
765765
polynomial ring.
766766
"""
767-
polynomial_ring_only(R::T, s::Symbol; cached::Bool=true) where T<:NCRing =
768-
dense_poly_ring_type(T)(R, s, cached)
767+
function polynomial_ring_only(R::T, s::Symbol; cached::Bool=true) where T<:NCRing
768+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
769+
return dense_poly_ring_type(T)(R, s, cached)
770+
end
769771

770772
# Simplified constructor
771773

src/PuiseuxSeries.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ object `S` will be cached so that supplying the same base ring, string and
2424
precision in future will return the same parent object and generator. If
2525
caching of the parent object is not required, `cached` can be set to `false`.
2626
"""
27-
puiseux_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true) =
28-
Generic.PuiseuxSeriesRing(R, prec, Symbol(s); cached)
27+
function puiseux_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true)
28+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
29+
return Generic.PuiseuxSeriesRing(R, prec, Symbol(s); cached)
30+
end
2931

30-
puiseux_series_field(R::Field, prec::Int, s::VarName; cached::Bool=true) =
31-
Generic.PuiseuxSeriesField(R, prec, Symbol(s); cached)
32+
function puiseux_series_field(R::Field, prec::Int, s::VarName; cached::Bool=true)
33+
return Generic.PuiseuxSeriesField(R, prec, Symbol(s); cached)
34+
end

src/RelSeries.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,8 +1473,10 @@ object `S` will be cached so that supplying the same base ring, string and
14731473
precision in future will return the same parent object and generator. If
14741474
caching of the parent object is not required, `cached` can be set to `false`.
14751475
"""
1476-
power_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true, model::Symbol=:capped_relative) =
1477-
Generic.power_series_ring(R, prec, Symbol(s); cached, model)
1476+
function power_series_ring(R::Ring, prec::Int, s::VarName; cached::Bool=true, model::Symbol=:capped_relative)
1477+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
1478+
return Generic.power_series_ring(R, prec, Symbol(s); cached, model)
1479+
end
14781480

14791481
function AbsPowerSeriesRing(R::Ring, prec::Int)
14801482
T = elem_type(R)

src/Residue.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ to the constructor with the same base ring $R$ and element $a$. A modulus
450450
of zero is not supported and throws an exception.
451451
"""
452452
function residue_ring(R::Ring, a::RingElement; cached::Bool = true)
453+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
453454
# Modulus of zero cannot be supported. E.g. A C library could not be expected to
454455
# do matrices over Z/0 using a Z/nZ type. The former is multiprecision, the latter not.
455456
iszero(a) && throw(DomainError(a, "Modulus must be nonzero"))
@@ -459,6 +460,7 @@ function residue_ring(R::Ring, a::RingElement; cached::Bool = true)
459460
end
460461

461462
function residue_ring(R::PolyRing, a::RingElement; cached::Bool = true)
463+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
462464
iszero(a) && throw(DomainError(a, "Modulus must be nonzero"))
463465
!is_unit(leading_coefficient(a)) && throw(DomainError(a, "Non-invertible leading coefficient"))
464466
T = elem_type(R)

src/ResidueField.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ residue ring parent object is cached and returned for any subsequent calls
490490
to the constructor with the same base ring $R$ and element $a$.
491491
"""
492492
function residue_field(R::Ring, a::RingElement; cached::Bool = true)
493+
@req !is_trivial(R) "Zero rings are currently not supported as base ring."
493494
iszero(a) && throw(DivideError())
494495
T = elem_type(R)
495496
S = EuclideanRingResidueField{T}(R(a), cached)

src/generic/AbsMSeries.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ end
709709

710710
function power_series_ring(R::AbstractAlgebra.Ring, prec::Vector{Int},
711711
s::Vector{Symbol}; cached::Bool=true, model=:capped_absolute)
712+
713+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
712714
U = elem_type(R)
713715

714716
S, _ = AbstractAlgebra.polynomial_ring(R, s)
@@ -724,6 +726,8 @@ end
724726
function power_series_ring(R::AbstractAlgebra.Ring, prec::Int,
725727
s::Vector{Symbol}; weights::Union{Vector{Int}, Nothing}=nothing,
726728
cached::Bool=true, model=:capped_absolute)
729+
730+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
727731
U = elem_type(R)
728732

729733
S, _ = AbstractAlgebra.polynomial_ring(R, s)

src/generic/LaurentMPoly.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ end
635635
###############################################################################
636636

637637
function laurent_polynomial_ring(R::AbstractAlgebra.Ring, s::Vector{Symbol}; cached::Bool = true)
638+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
638639
P, x = AbstractAlgebra.polynomial_ring(R, s, cached = cached)
639640
R = LaurentMPolyWrapRing(P, cached)
640641
R, map(p -> LaurentMPolyWrap(R, p), x)

src/generic/LaurentPoly.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ end
508508
###############################################################################
509509

510510
function laurent_polynomial_ring(R::AbstractAlgebra.Ring, s::Symbol; cached::Bool = true)
511+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
511512
P, x = AbstractAlgebra.polynomial_ring(R, s, cached = cached)
512513
R = LaurentPolyWrapRing(P, cached)
513514
R, LaurentPolyWrap(R, x)

src/generic/RelSeries.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ end
419419
###############################################################################
420420

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

424425
if model == :capped_relative

src/generic/UnivPoly.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,7 @@ x*y - z
11701170
```
11711171
"""
11721172
function universal_polynomial_ring(R::Ring; cached::Bool=true, internal_ordering::Symbol=:lex)
1173+
@req !is_trivial(R) "Zero rings are currently not supported as coefficient ring."
11731174
T = elem_type(R)
11741175
U = mpoly_type(R)
11751176

0 commit comments

Comments
 (0)