Skip to content

Commit

Permalink
Add is_finite methods for various ring types (#1842)
Browse files Browse the repository at this point in the history
Also add missing (but documented) `characteristic` method for
`FreeAssociativeAlgebra`
  • Loading branch information
fingolfin authored Oct 10, 2024
1 parent 5170909 commit 9ebc781
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/FreeAssociativeAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/LaurentMPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/LaurentPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)))


###############################################################################
#
Expand Down
4 changes: 3 additions & 1 deletion src/MatRing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/NCPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

###############################################################################
Expand Down
7 changes: 6 additions & 1 deletion src/Rings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions src/generic/LaurentMPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ebc781

Please sign in to comment.