Skip to content

Commit 17ba14e

Browse files
authored
Document (m)poly_type, (m)poly_ring_type in the manual (#2314)
1 parent e7f5559 commit 17ba14e

4 files changed

Lines changed: 64 additions & 17 deletions

File tree

docs/src/mpoly_interface.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,31 @@ Note that both abstract types are parameterised. The type `T` should usually be
4848
of elements of the coefficient ring of the polynomial ring. For example, in the case of
4949
$\mathbb{Z}[x, y]$ the type `T` would be the type of an integer, e.g. `BigInt`.
5050

51+
Given a type for the coefficients, we can obtain the corresponding type of a
52+
multivariate polynomial having that type of coefficient:
53+
54+
```@docs
55+
mpoly_type
56+
```
57+
58+
Analogously, given a type for the coefficients, we can obtain the corresponding
59+
type of the ring of multivariate polynomials having that type of coefficient:
60+
61+
```@docs
62+
mpoly_ring_type
63+
```
64+
65+
### Identical polynomial rings
66+
5167
Multivariate polynomial rings should be made unique on the system by caching parent
5268
objects (unless an optional `cache` parameter is set to `false`). Multivariate
5369
polynomial rings should at least be distinguished based on their base (coefficient)
5470
ring and number of variables. But if they have the same base ring, symbols (for their
5571
variables/generators) and ordering, they should certainly have the same parent object.
5672

57-
See `src/generic/GenericTypes.jl` for an example of how to implement such a cache (which
58-
usually makes use of a dictionary).
73+
Implementaors of a new type of polynomial ring should see `src/generic/GenericTypes.jl`
74+
for an example of how to implement such a cache (which usually makes use of a dictionary).
75+
In particular look at `MPolyID`.
5976

6077
## Required functionality for multivariate polynomials
6178

docs/src/poly_interface.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,19 @@ Return the array `[s]` where `s` is a `Symbol` representing the variable of the
135135
polynomial ring. This is provided for uniformity with the multivariate interface, where
136136
there is more than one variable and hence an array of symbols.
137137

138-
```julia
139-
poly_type(::Type{T}) where T <: RingElement
138+
Given a type for the coefficients, we can obtain the corresponding type of a
139+
univariate polynomial having that type of coefficient:
140+
141+
```@docs
142+
poly_type
140143
```
141144

142-
Return the type of a polynomial whose coefficients have the given type. In our
143-
example `MyPoly{T}`.
145+
Analogously, given a type for the coefficients, we can obtain the corresponding
146+
type of the ring of univariate polynomials having that type of coefficient:
144147

145-
This function is defined for generic polynomials and only needs to be defined for
146-
custom polynomial rings, e.g. ones defined by a C implementation.
148+
```@docs
149+
poly_ring_type
150+
```
147151

148152
```@docs
149153
poly_ring(R::Ring, s::Symbol; cached::Bool=false)

src/MPoly.jl

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ coefficient_ring(R::MPolyRing) = base_ring(R)
2121
mpoly_type(::Type{S}) where S<:Ring
2222
mpoly_type(::S) where S<:Ring
2323
24-
The type of multivariate polynomials with coefficients of type `T` respectively `elem_type(S)`.
25-
Falls back to `Generic.MPoly{T}`.
24+
Return the type of a (multivariate) polynomial whose coefficients have type `T` or
25+
type `elem_type(S)`.
26+
The type of the corresponding polynomial ring can be found via [`mpoly_ring_type`](@ref).
2627
27-
See also [`mpoly_ring_type`](@ref), [`poly_type`](@ref) and [`poly_ring_type`](@ref).
28+
For univariate polynomials see [`poly_type`](@ref).
29+
30+
# Implementation
31+
32+
This function is already defined for generic multivariate polynomials (namely `Generic.MPoly{T}`),
33+
so _needs to be defined only for_ special polynomial rings, _e.g._ those defined by
34+
a C implementation.
2835
2936
# Examples
3037
```jldoctest
@@ -41,6 +48,8 @@ julia> mpoly_type(typeof(AbstractAlgebra.ZZ))
4148
AbstractAlgebra.Generic.MPoly{BigInt}
4249
```
4350
"""
51+
mpoly_type
52+
4453
mpoly_type(::Type{T}) where T<:RingElement = Generic.MPoly{T}
4554
mpoly_type(::Type{S}) where S<:Ring = mpoly_type(elem_type(S))
4655
mpoly_type(x) = mpoly_type(typeof(x)) # to stop this method from eternally recursing on itself, we better add ...
@@ -53,10 +62,18 @@ mpoly_type(T::Type{Union{}}) = throw(MethodError(mpoly_type, (T,)))
5362
mpoly_ring_type(::Type{S}) where S<:Ring
5463
mpoly_ring_type(::S) where S<:Ring
5564
56-
The type of multivariate polynomial rings with coefficients of type `T`
57-
respectively `elem_type(S)`. Implemented via [`mpoly_type`](@ref).
65+
Return the type of the parent of a (multivariate) polynomial whose coefficients
66+
have type `T` or type `elem_type(S)`.
67+
The type of the polynomials themselves can be found via [`mpoly_type`](@ref).
68+
69+
For univariate polynomials see [`poly_ring_type`](@ref).
70+
71+
# Implementation
72+
73+
This function is already defined for generic multivariate polynomials (namely `Generic.MPoly{T}`),
74+
so _needs to be defined only for_ special polynomial rings, _e.g._ those defined by
75+
a C implementation.
5876
59-
See also [`poly_type`](@ref) and [`poly_ring_type`](@ref).
6077
6178
# Examples
6279
```jldoctest

src/NCPoly.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@ end
2525
poly_type(::Type{S}) where S<:NCRing
2626
poly_type(::S) where S<:NCRing
2727
28-
The type of univariate polynomials with coefficients of type `T` respectively `elem_type(S)`.
29-
Falls back to `Generic.NCPoly{T}` respectively `Generic.Poly{T}`.
28+
Return the type of a (univariate) polynomial whose coefficients have type `T` or
29+
type `elem_type(S)`.
30+
The type of the corresponding polynomial ring can be found via [`poly_ring_type`](@ref).
3031
31-
See also [`poly_ring_type`](@ref), [`mpoly_type`](@ref) and [`mpoly_ring_type`](@ref).
32+
For multivariate polynomials see [`mpoly_ring_type`](@ref).
33+
34+
# Implementation
35+
36+
This function is already defined for generic univariate polynomials (namely `Generic.NCPoly{T}` or `Generic.Poly{T}`),
37+
so _needs to be defined only for_ special polynomial rings, _e.g._ those defined by
38+
a C implementation.
3239
3340
# Examples
3441
```jldoctest
@@ -45,6 +52,8 @@ julia> poly_type(typeof(AbstractAlgebra.ZZ))
4552
AbstractAlgebra.Generic.Poly{BigInt}
4653
```
4754
"""
55+
poly_type
56+
4857
poly_type(::Type{T}) where T<:NCRingElement = Generic.NCPoly{T}
4958
poly_type(::Type{S}) where S<:NCRing = poly_type(elem_type(S))
5059
poly_type(x) = poly_type(typeof(x)) # to stop this method from eternally recursing on itself, we better add ...

0 commit comments

Comments
 (0)