From af60fd09ecfcfbbb2dabf54c1e26b90668d76e01 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 7 Oct 2024 23:32:51 +0200 Subject: [PATCH] Add `is_finite` methods for various ring types 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 | 2 ++ src/NCPoly.jl | 2 ++ src/Poly.jl | 2 ++ src/Rings.jl | 2 +- src/generic/LaurentMPoly.jl | 2 -- 9 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/FreeAssociativeAlgebra.jl b/src/FreeAssociativeAlgebra.jl index 2e31cdae64..752c8a397a 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 c5018b271c..a4fad8d360 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) = characteristic(a) == 1 || (nvars(R) == 0 && is_finite(base_ring(R))) + ############################################################################### # # String I/O diff --git a/src/LaurentPoly.jl b/src/LaurentPoly.jl index 9ed6200ae5..77fdacee41 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 0c6e85e5a7..e626c38140 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 f778d255f7..a7741e8242 100644 --- a/src/MatRing.jl +++ b/src/MatRing.jl @@ -70,6 +70,8 @@ function characteristic(a::MatRing) return characteristic(base_ring(a)) end +is_finite(R::MatRing) = iszero(a.n) || is_finite(base_ring(R)) + ############################################################################### # # Similar and zero diff --git a/src/NCPoly.jl b/src/NCPoly.jl index 5e45040a29..e27c49c396 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 59e171c2f0..2bbaf01c1a 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 c6be31e719..e09815d3b9 100644 --- a/src/Rings.jl +++ b/src/Rings.jl @@ -207,4 +207,4 @@ 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)) +is_finite(R::NCRing) = characteristic(R) != 0 && throw(NotImplementedError(:is_finite, R)) diff --git a/src/generic/LaurentMPoly.jl b/src/generic/LaurentMPoly.jl index 62fb1c1a2f..2c00ddc846 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