Skip to content

Commit

Permalink
Merge branch 'master' into js/setbreaking
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens authored Sep 17, 2024
2 parents 2f058a3 + 2116f53 commit 1e5e54e
Show file tree
Hide file tree
Showing 79 changed files with 760 additions and 693 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AbstractAlgebra"
uuid = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
version = "0.42.2"
version = "0.43.0-DEV"

[deps]
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand Down
2 changes: 2 additions & 0 deletions docs/src/euclidean_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ crt(r1::T, m1::T, r2::T, m2::T; check::Bool=true) where T <: RingElement
crt(r::Vector{T}, m::Vector{T}; check::Bool=true) where T <: RingElement
crt_with_lcm(r1::T, m1::T, r2::T, m2::T; check::Bool=true) where T <: RingElement
crt_with_lcm(r::Vector{T}, m::Vector{T}; check::Bool=true) where T <: RingElement
coprime_base
coprime_base_push!
```
74 changes: 37 additions & 37 deletions docs/src/free_associative_algebra.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ end

# Free algebras

AbstractAlgebra.jl provides a module, implemented in `src/FreeAssAlgebra.jl` for
AbstractAlgebra.jl provides a module, implemented in `src/FreeAssociativeAlgebra.jl` for
free associative algebras over any commutative ring belonging to the
AbstractAlgebra abstract type hierarchy.

## Generic free algebra types

AbstractAlgebra provides a generic type `Generic.FreeAssAlgElem{T}`
AbstractAlgebra provides a generic type `Generic.FreeAssociativeAlgebraElem{T}`
where `T` is the type of elements of the coefficient ring. The elements are
implemented using a Julia array of coefficients and a vector of
vectors of `Int`s for the monomial words. Parent objects of such elements have
type `Generic.FreeAssAlgebra{T}`.
type `Generic.FreeAssociativeAlgebra{T}`.

The element types belong to the abstract type `NCRingElem`,
and the algebra types belong to the abstract type `NCRing`.

The following basic functions are implemented.
```julia
base_ring(R::FreeAssAlgebra)
base_ring(a::FreeAssAlgElem)
parent(a::FreeAssAlgElem)
characteristic(R::FreeAssAlgebra)
base_ring(R::FreeAssociativeAlgebra)
base_ring(a::FreeAssociativeAlgebraElem)
parent(a::FreeAssociativeAlgebraElem)
characteristic(R::FreeAssociativeAlgebra)
```

## Free algebra constructors
Expand All @@ -53,7 +53,7 @@ the parent object `S` from being cached.

```jldoctest
julia> R, (x, y) = free_associative_algebra(ZZ, ["x", "y"])
(Free associative algebra on 2 indeterminates over integers, AbstractAlgebra.Generic.FreeAssAlgElem{BigInt}[x, y])
(Free associative algebra on 2 indeterminates over integers, AbstractAlgebra.Generic.FreeAssociativeAlgebraElem{BigInt}[x, y])
julia> (x + y + 1)^2
x^2 + x*y + y*x + y^2 + 2*x + 2*y + 1
Expand All @@ -74,7 +74,7 @@ with coefficients and monomial words and not exponent vectors.

```jldoctest
julia> R, (x, y, z) = free_associative_algebra(ZZ, ["x", "y", "z"])
(Free associative algebra on 3 indeterminates over integers, AbstractAlgebra.Generic.FreeAssAlgElem{BigInt}[x, y, z])
(Free associative algebra on 3 indeterminates over integers, AbstractAlgebra.Generic.FreeAssociativeAlgebraElem{BigInt}[x, y, z])
julia> B = MPolyBuildCtx(R)
Builder for an element of free associative algebra
Expand All @@ -86,7 +86,7 @@ julia> push_term!(B, ZZ(3), [3,3,3]); push_term!(B, ZZ(4), Int[]); finish(B)
3*z^3 + 4
julia> [gen(R, 2), R(9)]
2-element Vector{AbstractAlgebra.Generic.FreeAssAlgElem{BigInt}}:
2-element Vector{AbstractAlgebra.Generic.FreeAssociativeAlgebraElem{BigInt}}:
y
9
```
Expand All @@ -99,13 +99,13 @@ The standard ring functions are available. The following functions from the
multivariate polynomial interface are provided.

```julia
symbols(S::FreeAssAlgebra)
number_of_variables(f::FreeAssAlgebra)
gens(S::FreeAssAlgebra)
gen(S::FreeAssAlgebra, i::Int)
is_gen(x::FreeAssAlgElem)
total_degree(a::FreeAssAlgElem)
length(f::FreeAssAlgElem)
symbols(S::FreeAssociativeAlgebra)
number_of_variables(f::FreeAssociativeAlgebra)
gens(S::FreeAssociativeAlgebra)
gen(S::FreeAssociativeAlgebra, i::Int)
is_gen(x::FreeAssociativeAlgebraElem)
total_degree(a::FreeAssociativeAlgebraElem)
length(f::FreeAssociativeAlgebraElem)
```

As with multivariate polynomials, an implementation must provide access to
Expand All @@ -115,34 +115,34 @@ provide the first such term.


```julia
leading_coefficient(a::FreeAssAlgElem)
leading_monomial(a::FreeAssAlgElem)
leading_term(a::FreeAssAlgElem)
leading_exponent_word(a::FreeAssAlgElem)
leading_coefficient(a::FreeAssociativeAlgebraElem)
leading_monomial(a::FreeAssociativeAlgebraElem)
leading_term(a::FreeAssociativeAlgebraElem)
leading_exponent_word(a::FreeAssociativeAlgebraElem)
```

For types that allow constant time access to coefficients, the following are
also available, allowing access to the given coefficient, monomial or term.
Terms are numbered from the most significant first.

```julia
coeff(f::FreeAssAlgElem, n::Int)
monomial(f::FreeAssAlgElem, n::Int)
term(f::FreeAssAlgElem, n::Int)
coeff(f::FreeAssociativeAlgebraElem, n::Int)
monomial(f::FreeAssociativeAlgebraElem, n::Int)
term(f::FreeAssociativeAlgebraElem, n::Int)
```

In contrast with the interface for multivariable polynomials, the function
`exponent_vector` is replaced by `exponent_word`

```@docs
exponent_word(a::Generic.FreeAssAlgElem{T}, i::Int) where T <: RingElement
exponent_word(a::Generic.FreeAssociativeAlgebraElem{T}, i::Int) where T <: RingElement
```

**Examples**

```jldoctest
julia> R, (x, y, z) = free_associative_algebra(ZZ, ["x", "y", "z"])
(Free associative algebra on 3 indeterminates over integers, AbstractAlgebra.Generic.FreeAssAlgElem{BigInt}[x, y, z])
(Free associative algebra on 3 indeterminates over integers, AbstractAlgebra.Generic.FreeAssociativeAlgebraElem{BigInt}[x, y, z])
julia> map(total_degree, (R(0), R(1), -x^2*y^2*z^2*x + z*y))
(-1, 0, 7)
Expand All @@ -168,7 +168,7 @@ julia> exponent_word(-x^2*y^2*z^2*x + z*y, 1)
```

```@docs
evaluate(a::AbstractAlgebra.FreeAssAlgElem{T}, vals::Vector{U}) where {T <: RingElement, U <: NCRingElem}
evaluate(a::AbstractAlgebra.FreeAssociativeAlgebraElem{T}, vals::Vector{U}) where {T <: RingElement, U <: NCRingElem}
```

### Iterators
Expand All @@ -178,20 +178,20 @@ with `exponent_words` providing the analogous functionality that `exponent_vecto
provides for multivariate polynomials.

```julia
terms(p::FreeAssAlgElem)
coefficients(p::FreeAssAlgElem)
monomials(p::FreeAssAlgElem)
terms(p::FreeAssociativeAlgebraElem)
coefficients(p::FreeAssociativeAlgebraElem)
monomials(p::FreeAssociativeAlgebraElem)
```

```@docs
exponent_words(a::FreeAssAlgElem{T}) where T <: RingElement
exponent_words(a::FreeAssociativeAlgebraElem{T}) where T <: RingElement
```

**Examples**

```jldoctest
julia> R, (a, b, c) = free_associative_algebra(ZZ, ["a", "b", "c"])
(Free associative algebra on 3 indeterminates over integers, AbstractAlgebra.Generic.FreeAssAlgElem{BigInt}[a, b, c])
(Free associative algebra on 3 indeterminates over integers, AbstractAlgebra.Generic.FreeAssociativeAlgebraElem{BigInt}[a, b, c])
julia> collect(terms(3*b*a*c - b + c + 2))
4-element Vector{Any}:
Expand Down Expand Up @@ -230,11 +230,11 @@ Since such a Groebner basis is not necessarily finite, one can additionally pass
to the function, to only compute a partial Groebner basis.

```@docs
groebner_basis(g::Vector{FreeAssAlgElem{T}}, reduction_bound::Int = typemax(Int), remove_redundancies::Bool = false) where T <: FieldElement
groebner_basis(g::Vector{FreeAssociativeAlgebraElem{T}}, reduction_bound::Int = typemax(Int), remove_redundancies::Bool = false) where T <: FieldElement
normal_form(f::FreeAssAlgElem{T}, g::Vector{FreeAssAlgElem{T}}, aut::AhoCorasickAutomaton) where T
normal_form(f::FreeAssociativeAlgebraElem{T}, g::Vector{FreeAssociativeAlgebraElem{T}}, aut::AhoCorasickAutomaton) where T
interreduce!(g::Vector{FreeAssAlgElem{T}}) where T
interreduce!(g::Vector{FreeAssociativeAlgebraElem{T}}) where T
```

The implementation uses a non-commutative version of the Buchberger algorithm as described in
Expand All @@ -246,10 +246,10 @@ The implementation uses a non-commutative version of the Buchberger algorithm as

```jldoctest; setup = :(using AbstractAlgebra)
julia> R, (x, y, u, v, t, s) = free_associative_algebra(GF(2), ["x", "y", "u", "v", "t", "s"])
(Free associative algebra on 6 indeterminates over finite field F_2, AbstractAlgebra.Generic.FreeAssAlgElem{AbstractAlgebra.GFElem{Int64}}[x, y, u, v, t, s])
(Free associative algebra on 6 indeterminates over finite field F_2, AbstractAlgebra.Generic.FreeAssociativeAlgebraElem{AbstractAlgebra.GFElem{Int64}}[x, y, u, v, t, s])
julia> g = Generic.groebner_basis([u*(x*y)^3 + u*(x*y)^2 + u + v, (y*x)^3*t + (y*x)^2*t + t + s])
5-element Vector{AbstractAlgebra.Generic.FreeAssAlgElem{AbstractAlgebra.GFElem{Int64}}}:
5-element Vector{AbstractAlgebra.Generic.FreeAssociativeAlgebraElem{AbstractAlgebra.GFElem{Int64}}}:
u*x*y*x*y*x*y + u*x*y*x*y + u + v
y*x*y*x*y*x*t + y*x*y*x*t + t + s
u*x*s + v*x*t
Expand Down
6 changes: 6 additions & 0 deletions docs/src/matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,12 @@ det{T <: RingElem}(::MatElem{T})
rank{T <: RingElem}(::MatElem{T})
```

### Nilpotency

```@docs
is_nilpotent(::MatrixElem{T}) where {T <: RingElement}
```

### Minors

```@docs
Expand Down
7 changes: 3 additions & 4 deletions docs/src/ring.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,21 @@ right, respectively, of `a`.

## Unsafe ring operators

To speed up polynomial arithmetic, various unsafe operators are provided, which
To speed up polynomial arithmetic, various unsafe operators are provided, which may
mutate the output rather than create a new object.

```julia
zero!(a::NCRingElement)
mul!(a::T, b::T, c::T) where T <: NCRingElement
add!(a::T, b::T, c::T) where T <: NCRingElement
addeq!(a::T, b::T) where T <: NCRingElement
addmul!(a::T, b::T, c::T, t::T) where T <: NCRingElement
```

In each case the mutated object is the leftmost parameter.

The `addeq!(a, b)` operation does the same thing as `add!(a, a, b)`. The
The `add!(a, b)` operation does the same thing as `add!(a, a, b)`. The
optional `addmul!(a, b, c, t)` operation does the same thing as
`mul!(t, b, c); addeq!(a, t)` where `t` is a temporary which can be mutated so
`mul!(t, b, c); add!(a, t)` where `t` is a temporary which can be mutated so
that an addition allocation is not needed.

## Random generation
Expand Down
13 changes: 1 addition & 12 deletions docs/src/ring_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,6 @@ add!(c::MyElem, a::MyElem, b::MyElem)

Set $c$ to the value $a + b$ in place. Return the mutated value. Aliasing is permitted.

```julia
addeq!(a::MyElem, b::MyElem)
```

Set $a$ to $a + b$ in place. Return the mutated value. Aliasing is permitted.

### Random generation

The random functions are only used for test code to generate test data. They therefore
Expand Down Expand Up @@ -813,7 +807,7 @@ using Random: Random, SamplerTrivial, GLOBAL_RNG
using RandomExtensions: RandomExtensions, Make2, AbstractRNG

import AbstractAlgebra: parent_type, elem_type, base_ring, base_ring_type, parent, is_domain_type,
is_exact_type, canonical_unit, isequal, divexact, zero!, mul!, add!, addeq!,
is_exact_type, canonical_unit, isequal, divexact, zero!, mul!, add!,
get_cached!, is_unit, characteristic, Ring, RingElem, expressify

import Base: show, +, -, *, ^, ==, inv, isone, iszero, one, zero, rand,
Expand Down Expand Up @@ -980,11 +974,6 @@ function add!(f::ConstPoly{T}, g::ConstPoly{T}, h::ConstPoly{T}) where T <: Ring
return f
end

function addeq!(f::ConstPoly{T}, g::ConstPoly{T}) where T <: RingElement
f.c += g.c
return f
end

# Random generation

RandomExtensions.maketype(R::ConstPolyRing, _) = elem_type(R)
Expand Down
12 changes: 6 additions & 6 deletions src/AbsSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ function *(a::AbsPowerSeriesRingElem{T}, b::AbsPowerSeriesRingElem{T}) where T <
if lenz > i
for j = 2:min(lenb, lenz - i + 1)
t = mul!(t, coeff(a, i - 1), coeff(b, j - 1))
d[i + j - 1] = addeq!(d[i + j - 1], t)
d[i + j - 1] = add!(d[i + j - 1], t)
end
end
end
Expand Down Expand Up @@ -732,7 +732,7 @@ function Base.inv(a::AbsPowerSeriesRingElem{T}) where T <: FieldElement
x = _set_precision_raw!(x, la[n])
y = _set_precision_raw!(y, la[n])
y = mul!(y, minus_a, x)
y = addeq!(y, two)
y = add!(y, two)
x = mul!(x, x, y)
n -= 1
end
Expand Down Expand Up @@ -878,13 +878,13 @@ function sqrt_classical(a::AbsPowerSeriesRingElem; check::Bool=true)
for i = 1:div(n - 1, 2)
j = n - i
p = mul!(p, coeff(asqrt, aval2 + i), coeff(asqrt, aval2 + j))
c = addeq!(c, p)
c = add!(c, p)
end
c *= 2
if (n % 2) == 0
i = div(n, 2)
p = mul!(p, coeff(asqrt, aval2 + i), coeff(asqrt, aval2 + i))
c = addeq!(c, p)
c = add!(c, p)
end
c = coeff(a, n + aval) - c
if check
Expand Down Expand Up @@ -1031,8 +1031,8 @@ function Base.exp(a::AbsPowerSeriesRingElem{T}) where T <: FieldElement
x = _set_precision_raw!(x, la[n])
one1 = _set_precision_raw!(one1, la[n])
t = -log(x)
t = addeq!(t, one1)
t = addeq!(t, a)
t = add!(t, one1)
t = add!(t, a)
x = mul!(x, x, t)
n -= 1
end
Expand Down
3 changes: 2 additions & 1 deletion src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ include("Fraction.jl")
include("TotalFraction.jl")
include("MPoly.jl")
include("UnivPoly.jl")
include("FreeAssAlgebra.jl")
include("FreeAssociativeAlgebra.jl")
include("LaurentMPoly.jl")
include("MatrixNormalForms.jl")

Expand Down Expand Up @@ -409,6 +409,7 @@ include("algorithms/MPolyEvaluate.jl")
include("algorithms/MPolyFactor.jl")
include("algorithms/MPolyNested.jl")
include("algorithms/DensePoly.jl")
include("algorithms/coprime_base.jl")

###############################################################################
#
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ abstract type MatSpace{T} <: Module{T} end

abstract type MatRing{T} <: NCRing end

abstract type FreeAssAlgebra{T} <: NCRing end
abstract type FreeAssociativeAlgebra{T} <: NCRing end

# Abstract types for number fields, parmeterised by the element type of
# the base field.
Expand Down Expand Up @@ -144,7 +144,7 @@ abstract type MatElem{T} <: ModuleElem{T} end

abstract type MatRingElem{T} <: NCRingElem end

abstract type FreeAssAlgElem{T} <: NCRingElem end
abstract type FreeAssociativeAlgebraElem{T} <: NCRingElem end

abstract type NumFieldElem{T} <: FieldElem end

Expand Down
15 changes: 2 additions & 13 deletions src/Attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ end


"""
@attr [RetType] funcdef
@attr RetType funcdef
This macro is applied to the definition of a unary function, and enables
caching ("memoization") of its return values based on the argument. This
Expand Down Expand Up @@ -323,22 +323,11 @@ julia> myattr(obj) # second time uses the cached result
```
"""
macro attr(ex1, exs...)
if length(exs) == 0
rettype = Any
expr = ex1
elseif length(exs) == 1
rettype = ex1
expr = exs[1]
else
throw(ArgumentError("too many macro arguments"))
end
macro attr(rettype, expr::Expr)
d = MacroTools.splitdef(expr)
length(d[:args]) == 1 || throw(ArgumentError("Only unary functions are supported"))
length(d[:kwargs]) == 0 || throw(ArgumentError("Keyword arguments are not supported"))

# TODO: handle optional ::RetType

# store the original function name
name = d[:name]

Expand Down
Loading

0 comments on commit 1e5e54e

Please sign in to comment.