From f84179f3bbeac6d820db6ae59d01f178e884197c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 10 Oct 2024 17:45:27 +0200 Subject: [PATCH 1/3] Add many `@req !is_trivial` checks --- src/Fraction.jl | 1 + src/MPoly.jl | 6 ++++-- src/MatRing.jl | 3 ++- src/Matrix.jl | 4 ++++ src/NCPoly.jl | 6 ++++-- src/Residue.jl | 2 ++ src/ResidueField.jl | 1 + 7 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Fraction.jl b/src/Fraction.jl index 05e5a41f5d..8440cc2513 100644 --- a/src/Fraction.jl +++ b/src/Fraction.jl @@ -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 diff --git a/src/MPoly.jl b/src/MPoly.jl index 0af4ced8f7..7942ac86b2 100644 --- a/src/MPoly.jl +++ b/src/MPoly.jl @@ -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 diff --git a/src/MatRing.jl b/src/MatRing.jl index 49d3e48745..7bad1c4575 100644 --- a/src/MatRing.jl +++ b/src/MatRing.jl @@ -446,5 +446,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 diff --git a/src/Matrix.jl b/src/Matrix.jl index 03be1c9189..c79303d3b1 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -6653,6 +6653,7 @@ julia> using LinearAlgebra ; matrix(GF(5), I(2)) """ function matrix(R::NCRing, arr::AbstractMatrix{T}) where {T} Base.require_one_based_indexing(arr) + @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 @@ -6664,6 +6665,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 @@ -6702,6 +6704,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) @@ -7086,6 +7089,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) diff --git a/src/NCPoly.jl b/src/NCPoly.jl index 0559efaafb..ded12acb62 100644 --- a/src/NCPoly.jl +++ b/src/NCPoly.jl @@ -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 diff --git a/src/Residue.jl b/src/Residue.jl index 89126cb566..8247fba0c0 100644 --- a/src/Residue.jl +++ b/src/Residue.jl @@ -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")) @@ -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) diff --git a/src/ResidueField.jl b/src/ResidueField.jl index 0bea998023..aa473655f2 100644 --- a/src/ResidueField.jl +++ b/src/ResidueField.jl @@ -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) From 37b8a646216c415f14ae625434c19873f9934bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Fri, 11 Oct 2024 10:51:45 +0200 Subject: [PATCH 2/3] Revert matrix changes --- src/MatRing.jl | 3 +-- src/Matrix.jl | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/MatRing.jl b/src/MatRing.jl index 7bad1c4575..49d3e48745 100644 --- a/src/MatRing.jl +++ b/src/MatRing.jl @@ -446,6 +446,5 @@ Return parent object corresponding to the ring of $n\times n$ matrices over the ring $R$. """ function matrix_ring(R::NCRing, n::Int) - @req !is_trivial(R) "Zero rings are currently not supported as base ring." - return Generic.matrix_ring(R, n) + Generic.matrix_ring(R, n) end diff --git a/src/Matrix.jl b/src/Matrix.jl index c79303d3b1..03be1c9189 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -6653,7 +6653,6 @@ julia> using LinearAlgebra ; matrix(GF(5), I(2)) """ function matrix(R::NCRing, arr::AbstractMatrix{T}) where {T} Base.require_one_based_indexing(arr) - @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 @@ -6665,7 +6664,6 @@ 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 @@ -6704,7 +6702,6 @@ 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) @@ -7089,7 +7086,6 @@ 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) From b274c89ce3bce7520ba67757373349bc87d51764 Mon Sep 17 00:00:00 2001 From: Tommy Hofmann Date: Fri, 15 Nov 2024 19:54:51 +0100 Subject: [PATCH 3/3] add some characteristic --- src/generic/Misc/Localization.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/generic/Misc/Localization.jl b/src/generic/Misc/Localization.jl index 490f768b67..92e75e17e9 100644 --- a/src/generic/Misc/Localization.jl +++ b/src/generic/Misc/Localization.jl @@ -113,6 +113,8 @@ base_ring(L::LocalizedEuclideanRing) = L.base_ring::base_ring_type(L) parent(a::LocalizedEuclideanRingElem) = a.parent +characteristic(::LocalizedEuclideanRing) = characteristic(base_ring(L)) + ############################################################################### # # Basic manipulation