From 9ebc78151e7cdbdc00495cc75c543211a15722a6 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 10 Oct 2024 13:58:17 +0200 Subject: [PATCH] Add `is_finite` methods for various ring types (#1842) Also add missing (but documented) `characteristic` method for `FreeAssociativeAlgebra` --- src/FreeAssociativeAlgebra.jl | 4 ++++ src/LaurentMPoly.jl | 10 ++++++++++ src/LaurentPoly.jl | 10 ++++++++++ src/MPoly.jl | 7 ++++--- src/MatRing.jl | 4 +++- src/NCPoly.jl | 2 ++ src/Poly.jl | 2 ++ src/Rings.jl | 7 ++++++- src/generic/LaurentMPoly.jl | 2 -- 9 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/FreeAssociativeAlgebra.jl b/src/FreeAssociativeAlgebra.jl index 2e31cdae6..752c8a397 100644 --- a/src/FreeAssociativeAlgebra.jl +++ b/src/FreeAssociativeAlgebra.jl @@ -20,6 +20,10 @@ function is_exact_type(a::Type{S}) where {T <: RingElement, S <: FreeAssociative return is_exact_type(T) end +characteristic(R::FreeAssociativeAlgebra) = characteristic(base_ring(R)) + +is_finite(R::FreeAssociativeAlgebra) = is_trivial(base_ring(R)) || (nvars(R) == 0 && is_finite(base_ring(R))) + ############################################################################### # # String IO diff --git a/src/LaurentMPoly.jl b/src/LaurentMPoly.jl index c5018b271..38755573f 100644 --- a/src/LaurentMPoly.jl +++ b/src/LaurentMPoly.jl @@ -4,6 +4,16 @@ # ############################################################################### +############################################################################### +# +# Data type and parent object methods +# +############################################################################### + +characteristic(R::LaurentMPolyRing) = characteristic(base_ring(R)) + +is_finite(R::LaurentMPolyRing) = is_trivial(base_ring(R)) || (nvars(R) == 0 && is_finite(base_ring(R))) + ############################################################################### # # String I/O diff --git a/src/LaurentPoly.jl b/src/LaurentPoly.jl index 9ed6200ae..77fdacee4 100644 --- a/src/LaurentPoly.jl +++ b/src/LaurentPoly.jl @@ -4,6 +4,16 @@ # ############################################################################### +############################################################################### +# +# Data type and parent object methods +# +############################################################################### + +characteristic(R::LaurentPolyRing) = characteristic(base_ring(R)) + +is_finite(R::LaurentPolyRing) = is_trivial(R) + ############################################################################### # # laurent_polynomial_ring constructor diff --git a/src/MPoly.jl b/src/MPoly.jl index 0c6e85e5a..e626c3814 100644 --- a/src/MPoly.jl +++ b/src/MPoly.jl @@ -138,9 +138,10 @@ function var_index(x::MPolyRingElem{T}) where {T <: RingElement} return index end -function characteristic(a::MPolyRing{T}) where T <: RingElement - return characteristic(base_ring(a)) -end +characteristic(R::MPolyRing) = characteristic(base_ring(R)) + +is_finite(R::MPolyRing) = is_trivial(base_ring(R)) || (nvars(R) == 0 && is_finite(base_ring(R))) + ############################################################################### # diff --git a/src/MatRing.jl b/src/MatRing.jl index f778d255f..7791420a0 100644 --- a/src/MatRing.jl +++ b/src/MatRing.jl @@ -66,10 +66,12 @@ end function characteristic(a::MatRing) - iszero(a.n) && return 1 + iszero(nrows(a)) && return 1 return characteristic(base_ring(a)) end +is_finite(R::MatRing) = iszero(nrows(a)) || is_finite(base_ring(R)) + ############################################################################### # # Similar and zero diff --git a/src/NCPoly.jl b/src/NCPoly.jl index 5e45040a2..e27c49c39 100644 --- a/src/NCPoly.jl +++ b/src/NCPoly.jl @@ -102,6 +102,8 @@ number_of_variables(a::NCPolyRing) = 1 characteristic(a::NCPolyRing) = characteristic(base_ring(a)) +is_finite(a::NCPolyRing) = is_trivial(a) + ############################################################################### # # Basic manipulation diff --git a/src/Poly.jl b/src/Poly.jl index 59e171c2f..2bbaf01c1 100644 --- a/src/Poly.jl +++ b/src/Poly.jl @@ -49,6 +49,8 @@ number_of_variables(a::PolyRing) = 1 characteristic(a::PolyRing) = characteristic(base_ring(a)) +is_finite(a::PolyRing) = is_trivial(a) + Base.copy(a::PolyRingElem) = deepcopy(a) ############################################################################### diff --git a/src/Rings.jl b/src/Rings.jl index c6be31e71..7a14c0d77 100644 --- a/src/Rings.jl +++ b/src/Rings.jl @@ -207,4 +207,9 @@ is_perfect(F::Field) = characteristic(F) == 0 || F isa FinField || is_finite(F::FinField) = true -is_finite(F::Field) = characteristic(F) != 0 && throw(NotImplementedError(:is_finite, F)) +function is_finite(R::NCRing) + c = characteristic(R) + c == 0 && return false + c == 1 && return true + throw(NotImplementedError(:is_finite, R)) +end diff --git a/src/generic/LaurentMPoly.jl b/src/generic/LaurentMPoly.jl index 62fb1c1a2..2c00ddc84 100644 --- a/src/generic/LaurentMPoly.jl +++ b/src/generic/LaurentMPoly.jl @@ -29,8 +29,6 @@ number_of_variables(R::LaurentMPolyWrapRing) = number_of_variables(R.mpolyring) number_of_generators(R::LaurentMPolyWrapRing) = number_of_variables(R.mpolyring) -characteristic(R::LaurentMPolyWrapRing) = characteristic(R.mpolyring) - ############################################################################### # # Basic manipulation