Skip to content

Commit

Permalink
Add is_finite methods for various ring types
Browse files Browse the repository at this point in the history
Also add missing (but documented) `characteristic` method for
`FreeAssociativeAlgebra`
  • Loading branch information
fingolfin committed Oct 10, 2024
1 parent 69ba0a5 commit 791f95f
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)))

Check warning on line 25 in src/FreeAssociativeAlgebra.jl

View check run for this annotation

Codecov / codecov/patch

src/FreeAssociativeAlgebra.jl#L25

Added line #L25 was not covered by tests

###############################################################################
#
# 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)))

Check warning on line 15 in src/LaurentMPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/LaurentMPoly.jl#L15

Added line #L15 was not covered by tests

###############################################################################
#
# 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))

Check warning on line 13 in src/LaurentPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/LaurentPoly.jl#L13

Added line #L13 was not covered by tests

is_finite(R::LaurentPolyRing) = is_trivial(R)

Check warning on line 15 in src/LaurentPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/LaurentPoly.jl#L15

Added line #L15 was not covered by tests

###############################################################################
#
# 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)))

Check warning on line 143 in src/MPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/MPoly.jl#L143

Added line #L143 was not covered by tests


###############################################################################
#
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))

Check warning on line 73 in src/MatRing.jl

View check run for this annotation

Codecov / codecov/patch

src/MatRing.jl#L73

Added line #L73 was not covered by tests

###############################################################################
#
# 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)

Check warning on line 105 in src/NCPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/NCPoly.jl#L105

Added line #L105 was not covered by tests

###############################################################################
#
# 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)

Check warning on line 52 in src/Poly.jl

View check run for this annotation

Codecov / codecov/patch

src/Poly.jl#L52

Added line #L52 was not covered by tests

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))

Check warning on line 214 in src/Rings.jl

View check run for this annotation

Codecov / codecov/patch

src/Rings.jl#L213-L214

Added lines #L213 - L214 were not covered by tests
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 791f95f

Please sign in to comment.