Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified interface for constructors containing variable names #1360

Merged
merged 128 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
f5c9f35
Implement `variable_names`
mgkurtz May 10, 2023
275409b
Complete first draft
mgkurtz May 10, 2023
52d930a
Reorganize
mgkurtz May 10, 2023
1340d02
Include VarNames.jl
mgkurtz May 10, 2023
a81d130
Actually use `@add_varnames_interface`
mgkurtz May 10, 2023
5f5c162
Allow variable dims in `@polynomial_ring ZZ x[v...]`
mgkurtz May 11, 2023
eb1543c
Purge old `@polynomial_ring` macro
mgkurtz May 11, 2023
6c694b8
Add example for variable dims
mgkurtz May 11, 2023
16fa095
Simplify interface
mgkurtz Jun 29, 2023
ae7ef3c
Work on special cases
mgkurtz Jun 30, 2023
538307f
Purge superfluous old constructors
mgkurtz Jun 30, 2023
dba232e
fix
mgkurtz Jun 30, 2023
da55ef9
fix
mgkurtz Jun 30, 2023
2b5ce8e
fix
mgkurtz Jun 30, 2023
f0ed25d
Add `VarNames` type
mgkurtz Jun 30, 2023
071848c
Cleanup
mgkurtz Jun 30, 2023
f721599
Revert to `x1` instead of `x[1]`
mgkurtz Jun 30, 2023
2b3a811
fix doctests
mgkurtz Jun 30, 2023
3c51812
fix doctest expectations
mgkurtz Jun 30, 2023
b5d2e06
Fix some tests
mgkurtz Jun 30, 2023
5b2b40f
Make `R[x...]` equal `polynomial_ring(R, x...)`
mgkurtz Jun 30, 2023
5d0e423
fix
mgkurtz Jun 30, 2023
1a6558f
Fix doctest expectations
mgkurtz Jun 30, 2023
5c6cf05
fix tests
mgkurtz Jun 30, 2023
882d142
fix tests
mgkurtz Jun 30, 2023
e90605e
fix doctest expectations
mgkurtz Jul 2, 2023
a6af257
Use MacroTools
mgkurtz Jul 3, 2023
7db520a
Change to `1:n` syntax
mgkurtz Oct 4, 2023
371f925
change ?: to if-else
mgkurtz Oct 5, 2023
ec33f3e
towards introducing x0,x1,...
mgkurtz Oct 5, 2023
3610817
Make it work
mgkurtz Oct 5, 2023
99f5a68
Add `x#` and `x##` syntax
mgkurtz Oct 5, 2023
41a8873
Autodetect small indices in `x#` syntax
mgkurtz Oct 5, 2023
4e8316f
Examples and `x[%]` syntax
mgkurtz Oct 5, 2023
8fe7ec1
Use `x#` syntax to simplify example presentation
mgkurtz Oct 5, 2023
da5a271
Remove now disfunct example with `x[variable]`
mgkurtz Oct 5, 2023
dc62f65
Update docstrings
mgkurtz Oct 5, 2023
2f337ec
Roughly include in docs
mgkurtz Oct 5, 2023
48f5834
Add docstring for `VarName`
mgkurtz Oct 5, 2023
84ef57e
Fix tests
mgkurtz Oct 5, 2023
ff49194
Deprecate `power_series_ring(R, weights, ...)`
mgkurtz Oct 5, 2023
7c4ecb0
Document `@varnames_interface` options
mgkurtz Oct 5, 2023
33c4508
typo
mgkurtz Oct 5, 2023
8b5de4e
typo
mgkurtz Oct 5, 2023
f9257f9
No deprecations for now
mgkurtz Oct 5, 2023
218288e
Add printf formatting
mgkurtz Oct 5, 2023
003e75a
typo
mgkurtz Oct 5, 2023
baeb931
Fix docstring inclusions
mgkurtz Oct 5, 2023
767948c
Clarify docstring
mgkurtz Oct 6, 2023
81fbcb4
Require at least one vararg
mgkurtz Oct 6, 2023
da46e36
lowercase `laurent_polynomial_ring`
mgkurtz Oct 6, 2023
8ef16c9
Compatibility with julia 1.6
mgkurtz Oct 6, 2023
25e3122
Pass on keyword arguments in macros
mgkurtz Oct 6, 2023
75a649e
Compatibility with julia 1.6
mgkurtz Oct 6, 2023
bafd958
Fix bug in error string
mgkurtz Oct 6, 2023
635d38f
docstring change
mgkurtz Oct 6, 2023
45e515b
One more julia 1.6 compatibility
mgkurtz Oct 6, 2023
6c192bc
remove done todo
mgkurtz Oct 6, 2023
58db772
Add more constructors
mgkurtz Oct 6, 2023
2b2de20
docs change
mgkurtz Oct 6, 2023
1f2d9d7
Back to julia 1.6
mgkurtz Oct 6, 2023
a9afea1
Minor cleanup
mgkurtz Oct 6, 2023
b5bfff0
Replace option `n` by two options `n` and `range`
mgkurtz Oct 7, 2023
09b54e0
Add missing `kv...`
mgkurtz Oct 7, 2023
e7de8e1
Big clean up
mgkurtz Oct 8, 2023
e57eed9
Rearrange code
mgkurtz Oct 8, 2023
40e3ffb
Fix new doctests
mgkurtz Oct 8, 2023
68d1235
Fix new doctests
mgkurtz Oct 8, 2023
e47891d
Comment change
mgkurtz Oct 8, 2023
86bcc4e
getindex needs at least one `VarNames`
mgkurtz Oct 8, 2023
7f9eb7e
Less options in `variable_names`
mgkurtz Oct 8, 2023
de8fb99
`@f` mimics `f`
mgkurtz Oct 9, 2023
804c6a9
Lowercase constructors in `constructors.md`
mgkurtz Oct 9, 2023
709a7f6
Lowercase constructors
mgkurtz Oct 9, 2023
877624c
Lowercase rational_function_field
mgkurtz Oct 12, 2023
3f60bba
Lowercase function_field
mgkurtz Oct 12, 2023
0982488
Rewrite `polynomial_ring` docstring
mgkurtz Oct 12, 2023
e22d92f
Rewrite `polynomial_ring` docstring
mgkurtz Oct 12, 2023
8bca2ae
Rewrite `polynomial_ring` docstring
mgkurtz Oct 12, 2023
8cf19a2
Add `polynomial_ring` docstrings to docs
mgkurtz Oct 12, 2023
de2df7a
Remove Printf dependency
mgkurtz Oct 19, 2023
f6d240b
Remove @req
mgkurtz Oct 30, 2023
c9c7f5a
Merge branch master into mgk/varnames
mgkurtz Nov 2, 2023
f64ae2e
fix doctests to comply with #1476
mgkurtz Nov 2, 2023
eaf8643
Remove support for univariate methods
mgkurtz Nov 2, 2023
4498bbe
Undo cosmetic changes to `rational_function_field`
mgkurtz Nov 2, 2023
db9ce24
factor out cleaning up
mgkurtz Nov 2, 2023
a82b416
Undo cosmetic docs changes
mgkurtz Nov 2, 2023
d2424f0
Undo moving of some constructors
mgkurtz Nov 2, 2023
cb65306
Include RationalFunctionField.jl again
mgkurtz Nov 2, 2023
cb7786c
Keep old `power_series_ring` method
mgkurtz Nov 2, 2023
ff75348
Update `laurent_polynomial_ring` docs
mgkurtz Nov 2, 2023
98f1d7d
Revert "Revert "Fix printing multivariate polynomial ring with many v…
thofma Nov 2, 2023
571e9ef
warn about non-identifier names
mgkurtz Nov 3, 2023
6b94c8b
remove dated `missing` support
mgkurtz Nov 3, 2023
9c7d1f0
For macro "x" works as "x#"
mgkurtz Nov 3, 2023
664b358
Also warn in `@f(:x => -3,3)`
mgkurtz Nov 3, 2023
8415a30
Remove old char replacing function
mgkurtz Nov 3, 2023
c4974ab
Check indices to equal 1:n
mgkurtz Nov 3, 2023
fef259e
Adapt to string indices
mgkurtz Nov 3, 2023
806b478
details
mgkurtz Nov 3, 2023
bcf6cb7
only check names in macros
mgkurtz Nov 3, 2023
702e421
fix
mgkurtz Nov 3, 2023
81c9025
fix
mgkurtz Nov 13, 2023
7808001
cosmetics
mgkurtz Nov 13, 2023
417f93f
Use curly brackets for indices
mgkurtz Nov 13, 2023
664ce9d
fix doctests
mgkurtz Nov 13, 2023
00b8f0c
Merge branch th/revrevrev into mgk/varnames
mgkurtz Nov 13, 2023
b80aaaf
Apply suggestions from code review
mgkurtz Nov 13, 2023
1010a5c
Changes from code review
mgkurtz Nov 13, 2023
91c6fca
Docs changes
mgkurtz Nov 13, 2023
419eea7
Back to brackets
mgkurtz Nov 13, 2023
43fb1b4
fix
mgkurtz Nov 13, 2023
5620ca5
Broaden test coverage
mgkurtz Nov 14, 2023
6388c3f
Complete code coverage
mgkurtz Nov 14, 2023
2225794
fix for julia 1.6
mgkurtz Nov 15, 2023
177a2e7
Fix more issues reported by JET (#1478)
fingolfin Nov 3, 2023
23f0ac1
Replace multiple calls to precision(::AbsMSeries) (#1481)
fingolfin Nov 3, 2023
90ae3e5
Remove redundant 'convert' invocation (#1491)
fingolfin Nov 4, 2023
cd7d8b8
Resolve ambiguity between divexact methods (#1484)
fingolfin Nov 5, 2023
e97b991
Move stuff from Oscar to AbstractAlgebra (#1494)
fingolfin Nov 5, 2023
f6fa6c7
Improve with_unicode (#1495)
fingolfin Nov 6, 2023
7e73dd1
Enable more functionality for matrices of NCRing (#1499)
lgoettgens Nov 9, 2023
6ed8479
Export new macros
fingolfin Nov 21, 2023
017fbd2
Update some comments
fingolfin Nov 21, 2023
d0cf734
Merge branch 'master' into mgk/varnames
fingolfin Nov 21, 2023
704b29b
Revert implementation for `R[:x, :y]`
mgkurtz Nov 22, 2023
181d615
fix tests
fingolfin Nov 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions docs/src/constructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ For example, to create a parent object for univariate polynomials over the integ
we use the `polynomial_ring` parent object constructor.

```julia
R, x = polynomial_ring(ZZ, "x")
R, x = polynomial_ring(ZZ, :x)
f = x^3 + 3x + 1
g = R(12)
```
Expand All @@ -57,19 +57,36 @@ $12$ to an element of the polynomial ring $\mathbb{Z}[x]$.
For convenience, we provide a list of all the parent object constructors in
AbstractAlgebra.jl and explain what mathematical domains they represent.

| Mathematics | AbstractAlgebra.jl constructor |
|----------------------------------|---------------------------------------------|
| $R = \mathbb{Z}$ | `R = ZZ` |
| $R = \mathbb{Q}$ | `R = QQ` |
| $R = \mathbb{F}_{p}$ | `R = GF(p)` |
| $R = \mathbb{Z}/n\mathbb{Z}$ | `R = residue_ring(ZZ, n)` |
| $S = R[x]$ | `S, x = polynomial_ring(R, "x")` |
| $S = R[x, y]$ | `S, (x, y) = polynomial_ring(R, ["x", "y"])`|
| $S = R[[x]]$ (to precision $n$) | `S, x = power_series_ring(R, n, "x")` |
| $S = R((x))$ (to precision $n$) | `S, x = laurent_series_ring(R, n, "x")` |
| $S = K((x))$ (to precision $n$) | `S, x = laurent_series_field(K, n, "x")` |
| $S = \mathrm{Frac}_R$ | `S = fraction_field(R)` |
| $S = R/(f)$ | `S = residue_ring(R, f)` |
| $S = R/(f)$ (with $(f)$ maximal) | `S = residue_field(R, f)` |
| $S = \mathrm{Mat}_{m\times n}(R)$| `S = matrix_space(R, m, n)` |
| $S = \mathbb{Q}[x]/(f)$ | `S, a = number_field(f, "a")` |
| Mathematics | AbstractAlgebra.jl constructor |
|:-------------------------------------|:------------------------------------------------------|
| $R = \mathbb{Z}$ | `R = ZZ` |
| $R = \mathbb{Q}$ | `R = QQ` |
| $R = \mathbb{F}_{p}$ | `R = GF(p)` |
| $R = \mathbb{Z}/n\mathbb{Z}$ | `R = residue_ring(ZZ, n)` |
| $S = R[x]$ | `S, x = polynomial_ring(R, :x)` |
| $S = R[x, y]$ | `S, (x, y) = polynomial_ring(R, [:x, :y])` |
| $S = R\langle x, y\rangle$ | `S, (x, y) = free_associative_algebra(R, [:x, :y])` |
| $S = K(x)$ | `S, x = rational_function_field(K, :x)` |
| $S = K(x, y)$ | `S, (x, y) = rational_function_field(K, [:x, :y])` |
| $S = R[[x]]$ (to precision $n$) | `S, x = power_series_ring(R, n, :x)` |
| $S = R[[x, y]]$ (to precision $n$) | `S, (x, y) = power_series_ring(R, n, [:x, :y])` |
| $S = R((x))$ (to precision $n$) | `S, x = laurent_series_ring(R, n, :x)` |
| $S = K((x))$ (to precision $n$) | `S, x = laurent_series_field(K, n, :x)` |
| $S = R((x, y))$ (to precision $n$) | `S, (x, y) = laurent_polynomial_ring(R, n, [:x, :y])` |
| Puiseux series ring to precision $n$ | `S, x = PuiseuxSeriesRing(R, n, :x)` |
mgkurtz marked this conversation as resolved.
Show resolved Hide resolved
| $S = K(x)(y)/(f)$ | `S, y = function_field(f, :y)` with $f\in K(x)[t]$ |
| $S = \mathrm{Frac}_R$ | `S = fraction_field(R)` |
| $S = R/(f)$ | `S = residue_ring(R, f)` |
| $S = R/(f)$ (with $(f)$ maximal) | `S = residue_field(R, f)` |
| $S = \mathrm{Mat}_{m\times n}(R)$ | `S = matrix_space(R, m, n)` |
| $S = \mathbb{Q}[x]/(f)$ | `S, a = number_field(f, :a)` |

## Parent objects with variable names

The multivariate parent object constructors (`polynomial_ring`, `power_series_ring`, `free_associative_algebra`, `laurent_polynomial_ring`, and `rational_function_field`) share a common interface for specifying the variable names, which is provided by `@varnames_interface`.

```@docs
AbstractAlgebra.@varnames_interface
AbstractAlgebra.variable_names
AbstractAlgebra.reshape_to_varnames
```
8 changes: 5 additions & 3 deletions docs/src/mpolynomial.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ and the polynomial ring types belong to the abstract type `MPolyRing{T}`.
## Polynomial ring constructors

In order to construct multivariate polynomials in AbstractAlgebra.jl, one must first
construct the polynomial ring itself. This is accomplished with one of the following
construct the polynomial ring itself. This is accomplished with the following
constructors.

```@docs
polynomial_ring(R::Ring, S::Vector{VarName}; cached::Bool = true, ordering::Symbol=:lex)
polynomial_ring(R::Ring, n::Int, s::VarName; cached::Bool = false, ordering::Symbol = :lex)
polynomial_ring(::Ring, ::Vector{Symbol})
polynomial_ring(::Ring, ::Vararg)
polynomial_ring(::Ring, ::Int)
@polynomial_ring
```

Like for univariate polynomials, a shorthand constructor is
Expand Down
4 changes: 2 additions & 2 deletions docs/src/polynomial.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ can accept any AbstractAlgebra polynomial type.
In order to construct polynomials in AbstractAlgebra.jl, one must first construct the
polynomial ring itself. This is accomplished with the following constructor.

```@docs
polynomial_ring(R::Ring, s::VarName; cached::Bool = true)
```@docs; canonical=false
polynomial_ring(R::NCRing, s::VarName; cached::Bool = true)
```

A shorthand version of this function is provided: given a base ring `R`, we abbreviate
Expand Down
39 changes: 0 additions & 39 deletions src/AbsMSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,42 +214,3 @@ when it was created.
function rand(S::MSeriesRing, term_range, v...)
rand(GLOBAL_RNG, S, term_range, v...)
end

###############################################################################
#
# power_series_ring constructor
#
###############################################################################

function power_series_ring(R::Ring, weights::Vector{Int}, prec::Int,
s::Vector{Symbol}; cached::Bool=true, model=:capped_absolute)
return Generic.power_series_ring(R, weights, prec, s; cached=cached, model=model)
end

function power_series_ring(R::Ring, prec::Vector{Int},
s::Vector{Symbol}; cached::Bool=true, model=:capped_absolute)
return Generic.power_series_ring(R, prec, s; cached=cached, model=model)
end

function power_series_ring(R::Ring, prec::Vector{Int},
s::AbstractVector{<:VarName}; cached::Bool=true, model=:capped_absolute)
sym = [Symbol(v) for v in s]
return power_series_ring(R, prec, sym; cached=cached, model=model)
end

function power_series_ring(R::Ring, weights::Vector{Int}, prec::Int,
s::AbstractVector{<:VarName}; cached::Bool=true, model=:capped_absolute)
sym = [Symbol(v) for v in s]
return power_series_ring(R, weights, prec, sym; cached=cached, model=model)
end

function power_series_ring(R::Ring, prec::Int,
s::Vector{Symbol}; cached::Bool=true, model=:capped_absolute)
return Generic.power_series_ring(R, prec, s; cached=cached, model=model)
end

function power_series_ring(R::Ring, prec::Int,
s::AbstractVector{<:VarName}; cached::Bool=true, model=:capped_absolute)
sym = [Symbol(v) for v in s]
return power_series_ring(R, prec, sym; cached=cached, model=model)
end
28 changes: 16 additions & 12 deletions src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1238,13 +1238,26 @@ export Generic

###############################################################################
#
# Polynomial Ring S, x = R["x"] syntax
# misc
#
###############################################################################

include("misc/ProductIterator.jl")
include("misc/Evaluate.jl")
include("misc/VarNames.jl")

###############################################################################
#
# Polynomial Ring S, x = R[:x] syntax
#
###############################################################################

getindex(R::NCRing, s::VarName) = polynomial_ring(R, s)
getindex(R::NCRing, s::VarName, ss::VarName...) =
polynomial_ring(R, [Symbol(x) for x in (s, ss...)])
# For compatibility `R[:x, :y]` returns `S, [x, y]` instead of `S, x, y`
mgkurtz marked this conversation as resolved.
Show resolved Hide resolved
getindex(R::Ring, s1::VarNames, s::VarNames...) = ((S, x...) = polynomial_ring(R, s1, s...); (S, collect(x)))
getindex(R::Ring, s::Tuple{Vararg{VarNames}}) = ((S, x...) = polynomial_ring(R, s); (S, collect(x)))
mgkurtz marked this conversation as resolved.
Show resolved Hide resolved
# Resolve ambiguity
getindex(R::Ring, s::VarName) = polynomial_ring(R, s)

# syntax: Rxy, y = R[:x][:y]
getindex(R::Union{Tuple{PolyRing, PolyRingElem}, Tuple{NCPolyRing, NCPolyRingElem}}, s::VarName) = polynomial_ring(R[1], s)
Expand Down Expand Up @@ -1273,15 +1286,6 @@ Base.typed_vcat(R::NCRing, args...) = _matrix(R, vcat(args...))
_matrix(R::NCRing, a::AbstractVector) = matrix(R, length(a), isempty(a) ? 0 : 1, a)
_matrix(R::NCRing, a::AbstractMatrix) = matrix(R, a)

###############################################################################
#
# misc
#
###############################################################################

include("misc/ProductIterator.jl")
include("misc/Evaluate.jl")

###############################################################################
#
# Load error objects
Expand Down
44 changes: 0 additions & 44 deletions src/FreeAssAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,47 +255,3 @@ end
function rand(S::FreeAssAlgebra, term_range, exp_bound, v...)
rand(GLOBAL_RNG, S, term_range, exp_bound, v...)
end

###############################################################################
#
# free_associative_algebra constructor
#
###############################################################################

function free_associative_algebra(
R::Ring,
s::AbstractVector{<:VarName};
cached::Bool = true)

S = [Symbol(v) for v in s]
return Generic.free_associative_algebra(R, S, cached=cached)
end

function free_associative_algebra(
R::Ring,
s::Vector{Symbol};
cached::Bool = true)

return Generic.free_associative_algebra(R, s, cached=cached)
end

function free_associative_algebra(
R::Ring,
n::Int,
s::VarName;
cached::Bool = false)

S = [Symbol(s, i) for i in 1:n]
return Generic.free_associative_algebra(R, S; cached=cached)
end

function free_associative_algebra(
R::Ring,
n::Int,
s::Symbol=:x;
cached::Bool = false)

S = [Symbol(s, i) for i in 1:n]
return Generic.free_associative_algebra(R, S; cached=cached)
end

32 changes: 13 additions & 19 deletions src/LaurentMPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,18 @@ end
###############################################################################

@doc raw"""
laurent_polynomial_ring(R::Ring, s::Vector{T}; cached::Bool = true) where T <: VarName

Given a base ring `R` and an array of strings `s` specifying how the
generators (variables) should be printed, return a tuple `T, (x1, x2, ...)`
representing the new ring $T = R[x1, 1/x1, x2, 1/x2, ...]$ and the generators
$x1, x2, ...$ of the ring. By default the parent object `T` will
depend only on `R` and `x1, x2, ...` and will be cached. Setting the optional
argument `cached` to `false` will prevent the parent object `T` from being
cached.
"""
function laurent_polynomial_ring(R::Ring, s::AbstractVector{<:VarName}; cached::Bool = true)
return Generic.laurent_polynomial_ring(R, [Symbol(v) for v in s], cached=cached)
end
laurent_polynomial_ring(R::Ring, varnames...; cached::Bool = true)

function laurent_polynomial_ring(R::Ring, s::Vector{Symbol}; cached::Bool = true)
return Generic.laurent_polynomial_ring(R, s; cached=cached)
end
Given a base ring `R` and variable names `varnames...`, say `:x, :y, :z`, return
a tuple `S, x, y, z` representing the new ring $S = R[x, 1/x, y, 1/y, z, 1/z]$
and the generators $x, y, z$ of the ring.

function laurent_polynomial_ring(R::Ring, n::Int, s::VarName=:x; cached::Bool = false)
return Generic.laurent_polynomial_ring(R, [Symbol(s, i) for i=1:n]; cached=cached)
end
By default (`cached=true`), the output `S` will be cached, i.e. if
`polynomial_ring` is invoked again with the same arguments, the same
mgkurtz marked this conversation as resolved.
Show resolved Hide resolved
(*identical*) ring is returned. Setting `cached` to `false` ensures a distinct
new ring is returned, and will also prevent it from being cached.

For ways to give `varnames...` refer to [`polynomial_ring`](@ref) or the
mgkurtz marked this conversation as resolved.
Show resolved Hide resolved
specification in [`AbstractAlgebra.@varnames_interface`](@ref).
"""
laurent_polynomial_ring(R::Ring, s::Vector{Symbol})
Loading
Loading