Skip to content

Commit 5294c69

Browse files
authored
Add coefficient_ring for modules and series and improve the docs for base_ring (#2185)
1 parent 56de351 commit 5294c69

12 files changed

+106
-3
lines changed

docs/src/extending_abstractalgebra.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ base_ring
2929
base_ring_type
3030
```
3131

32+
If there is a well-defined notion of a coefficient ring (e.g. in the case of
33+
polynomial rings or modules), then one should implement
34+
35+
```@docs
36+
coefficient_ring
37+
coefficient_ring_type
38+
```
39+
3240
## Special elements
3341

3442
For rings, one has to extend the following methods:

src/RelSeries.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ base_ring_type(::Type{<:SeriesRing{T}}) where T <: RingElement = parent_type(T)
2929

3030
base_ring(R::SeriesRing{T}) where T <: RingElement = R.base_ring::parent_type(T)
3131

32+
coefficient_ring_type(T::Type{<:SeriesRing}) = base_ring_type(T)
33+
34+
coefficient_ring(R::SeriesRing) = base_ring(R)
35+
3236
function is_domain_type(::Type{T}) where {S <: RingElement, T <: SeriesElem{S}}
3337
return is_domain_type(S)
3438
end

src/fundamental_interface.jl

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ parent_type(T::DataType) = throw(MethodError(parent_type, (T,)))
7777
@doc raw"""
7878
base_ring(a)
7979
80-
Return base ring $R$ of given element or parent $a$.
80+
Return the internal base ring of the given element or parent $a$.
8181
8282
# Examples
8383
```jldoctest
@@ -101,7 +101,7 @@ base_ring(x::NCRingElement) = base_ring(parent(x))
101101
@doc raw"""
102102
base_ring_type(a)
103103
104-
Return the type of the base ring of the given element, element type, parent or parent type $a$.
104+
Return the type of the internal base ring of the given element, element type, parent or parent type $a$.
105105
106106
# Examples
107107
```jldoctest
@@ -133,9 +133,52 @@ base_ring_type(x::Type{<:ModuleElem}) = base_ring_type(parent_type(x))
133133
base_ring_type(x::Type{<:Ideal}) = base_ring_type(parent_type(x))
134134
base_ring_type(T::DataType) = throw(MethodError(base_ring_type, (T,)))
135135

136-
# generic coefficient_ring method
136+
@doc raw"""
137+
coefficient_ring(a)
138+
139+
Return the coefficient ring of the given element or parent $a$.
140+
141+
# Examples
142+
```jldoctest
143+
julia> R, x = polynomial_ring(QQ, :x)
144+
(Univariate polynomial ring in x over rationals, x)
145+
146+
julia> coefficient_ring(x^2+1) == QQ
147+
true
148+
149+
julia> S, (z,w) = universal_polynomial_ring(QQ, [:z,:w])
150+
(Universal Polynomial Ring over Rationals, AbstractAlgebra.Generic.UnivPoly{Rational{BigInt}}[z, w])
151+
152+
julia> coefficient_ring(S) == QQ
153+
true
154+
```
155+
"""
156+
function coefficient_ring end
137157
coefficient_ring(x::NCRingElement) = coefficient_ring(parent(x))
138158

159+
@doc raw"""
160+
coefficient_ring_type(a)
161+
162+
Return the type of the coefficient ring of the given element, element type, parent or parent type $a$.
163+
164+
# Examples
165+
```jldoctest
166+
julia> R, x = polynomial_ring(ZZ, :x)
167+
(Univariate polynomial ring in x over integers, x)
168+
169+
julia> coefficient_ring_type(R) == typeof(coefficient_ring(R))
170+
true
171+
172+
julia> coefficient_ring_type(zero(R)) == typeof(coefficient_ring(zero(R)))
173+
true
174+
175+
julia> coefficient_ring_type(typeof(R)) == typeof(coefficient_ring(R))
176+
true
177+
178+
julia> coefficient_ring_type(typeof(zero(R))) == typeof(coefficient_ring(zero(R)))
179+
true
180+
```
181+
"""
139182
coefficient_ring_type(x) = coefficient_ring_type(typeof(x))
140183
coefficient_ring_type(x::Type{<:NCRingElement}) = coefficient_ring_type(parent_type(x))
141184
coefficient_ring_type(x::Type{<:ModuleElem}) = coefficient_ring_type(parent_type(x))

src/generic/FreeModule.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ base_ring_type(::Type{FreeModule{T}}) where T <: NCRingElement = parent_type(T)
1616

1717
base_ring(M::FreeModule{T}) where T <: NCRingElement = M.base_ring::parent_type(T)
1818

19+
coefficient_ring_type(T::Type{<:FreeModule}) = base_ring_type(T)
20+
21+
coefficient_ring(M::FreeModule) = base_ring(M)
22+
1923
elem_type(::Type{FreeModule{T}}) where T <: NCRingElement = FreeModuleElem{T}
2024

2125
parent(m::FreeModuleElem{T}) where T <: NCRingElement = m.parent

src/generic/LaurentSeries.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ base_ring(R::LaurentSeriesRing{T}) where T <: RingElement = R.base_ring::parent_
4141

4242
base_ring(R::LaurentSeriesField{T}) where T <: FieldElement = R.base_ring::parent_type(T)
4343

44+
coefficient_ring_type(T::Type{<:LaurentSeriesRing}) = base_ring_type(T)
45+
46+
coefficient_ring_type(T::Type{<:LaurentSeriesField}) = base_ring_type(T)
47+
48+
coefficient_ring(R::LaurentSeriesRing) = base_ring(R)
49+
50+
coefficient_ring(R::LaurentSeriesField) = base_ring(R)
51+
4452
function is_domain_type(::Type{T}) where {S <: RingElement, T <: LaurentSeriesElem{S}}
4553
return is_domain_type(S)
4654
end

src/generic/PuiseuxSeries.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ base_ring(R::PuiseuxSeriesRing{T}) where T <: RingElement = base_ring(laurent_ri
5757

5858
base_ring(R::PuiseuxSeriesField{T}) where T <: FieldElement = base_ring(laurent_ring(R))
5959

60+
coefficient_ring_type(T::Type{<:PuiseuxSeriesRing}) = base_ring_type(T)
61+
62+
coefficient_ring_type(T::Type{<:PuiseuxSeriesField}) = base_ring_type(T)
63+
64+
coefficient_ring(R::PuiseuxSeriesRing) = base_ring(R)
65+
66+
coefficient_ring(R::PuiseuxSeriesField) = base_ring(R)
67+
6068
@doc raw"""
6169
max_precision(R::PuiseuxSeriesRing{T}) where T <: RingElement
6270

src/generic/QuotientModule.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ base_ring_type(::Type{QuotientModule{T}}) where T <: RingElement = parent_type(T
2020

2121
base_ring(N::QuotientModule{T}) where T <: RingElement = N.base_ring::parent_type(T)
2222

23+
coefficient_ring_type(T::Type{<:QuotientModule}) = base_ring_type(T)
24+
25+
coefficient_ring(N::QuotientModule) = base_ring(N)
26+
2327
number_of_generators(N::QuotientModule{T}) where T <: RingElement = length(N.gen_cols)
2428

2529
gens(N::QuotientModule{T}) where T <: RingElement = elem_type(N)[gen(N, i) for i = 1:ngens(N)]

test/generic/FreeModule-test.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
@test elem_type(Generic.FreeModule{elem_type(R)}) == Generic.FreeModuleElem{elem_type(R)}
1212
@test parent_type(Generic.FreeModuleElem{elem_type(R)}) == Generic.FreeModule{elem_type(R)}
1313

14+
@test coefficient_ring(M) == R
15+
@test coefficient_ring_type(M) == typeof(coefficient_ring(M))
16+
1417
@test isa(M, Generic.FreeModule)
1518

1619
@test isa(M([x, x, x, x, x]), Generic.FreeModuleElem)

test/generic/LaurentSeries-test.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ end
4040
@test elem_type(Generic.LaurentSeriesRing{elem_type(S)}) == Generic.LaurentSeriesRingElem{elem_type(S)}
4141
@test parent_type(Generic.LaurentSeriesRingElem{elem_type(S)}) == Generic.LaurentSeriesRing{elem_type(S)}
4242

43+
@test coefficient_ring(T) == S
44+
@test coefficient_ring_type(T) == typeof(coefficient_ring(T))
45+
4346
@test elem_type(U) == Generic.LaurentSeriesFieldElem{Rational{BigInt}}
4447
@test elem_type(Generic.LaurentSeriesField{Rational{BigInt}}) == Generic.LaurentSeriesFieldElem{Rational{BigInt}}
4548
@test parent_type(Generic.LaurentSeriesFieldElem{Rational{BigInt}}) == Generic.LaurentSeriesField{Rational{BigInt}}
4649

50+
@test coefficient_ring(U) === QQ
51+
@test coefficient_ring_type(U) == typeof(coefficient_ring(U))
52+
4753
@test isa(R, Generic.LaurentSeriesRing)
4854
@test isa(T, Generic.LaurentSeriesRing)
4955
@test isa(U, Generic.LaurentSeriesField)

test/generic/PuiseuxSeries-test.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ end
4242
@test elem_type(Generic.PuiseuxSeriesRing{elem_type(S)}) == Generic.PuiseuxSeriesRingElem{elem_type(S)}
4343
@test parent_type(Generic.PuiseuxSeriesRingElem{elem_type(S)}) == Generic.PuiseuxSeriesRing{elem_type(S)}
4444

45+
@test coefficient_ring(T) == S
46+
@test coefficient_ring_type(T) == typeof(coefficient_ring(T))
47+
4548
@test elem_type(U) == Generic.PuiseuxSeriesFieldElem{Rational{BigInt}}
4649
@test elem_type(Generic.PuiseuxSeriesField{Rational{BigInt}}) == Generic.PuiseuxSeriesFieldElem{Rational{BigInt}}
4750
@test parent_type(Generic.PuiseuxSeriesFieldElem{Rational{BigInt}}) == Generic.PuiseuxSeriesField{Rational{BigInt}}
4851

52+
@test coefficient_ring(U) === QQ
53+
@test coefficient_ring_type(U) == typeof(coefficient_ring(U))
54+
4955
@test isa(R, Generic.PuiseuxSeriesRing)
5056
@test isa(T, Generic.PuiseuxSeriesRing)
5157
@test isa(U, Generic.PuiseuxSeriesField)

0 commit comments

Comments
 (0)