Skip to content

Commit a3a3160

Browse files
authored
Merge pull request #25 from KlausC:krc/cleanupandluebeckstart
multiple improvements ZZZ, Galois, added lübeck
2 parents e7eafd5 + e904696 commit a3a3160

28 files changed

+987
-242
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
with:
3636
version: ${{ matrix.version }}
3737
arch: ${{ matrix.arch }}
38-
- uses: actions/cache@v1
38+
- uses: actions/cache@v4
3939
env:
4040
cache-name: cache-artifacts
4141
with:

src/CommutativeRings.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export characteristic, dimension, order
3737
export ofindex
3838
export generator, generators
3939
export homomorphism
40-
export num_primitives, isprimitive
40+
export num_primitives, isprimitive, ismonomprimitive
4141
export elementary_symmetric, newton_symmetric
4242

4343
export VectorSpace, complement, sum, intersect, isequal, issubset
@@ -97,6 +97,7 @@ include("fourier.jl")
9797
include("fastmultiply.jl")
9898
include("algebraic.jl")
9999
include("numberfield.jl")
100+
include("luebeck.jl")
100101

101102
using .SpecialPowerSeries
102103
using .Conway

src/algebraic.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ end
393393
394394
Return the algebraic number at `exp(pi * r * im)`.
395395
"""
396-
Base.cispi(q::Q) where Q<:QQ = cispi(Q, value(q))
397-
function Base.cispi(Q::Type{<:QQ}, r::Rational{<:Integer})
396+
Base.cispi(q::Q) where Q<:QQ = _cispi(Q, value(q))
397+
function _cispi(Q::Type{<:QQ}, r::Rational{<:Integer})
398398
r = mod(r + 1, 2) - 1
399399
r //= 2
400400
num = numerator(r)

src/conway.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ function conway(p::Integer, n::Integer, X::Symbol = :x)
5252
end
5353

5454
"""
55-
isconway(::Type{GaloisField})
55+
is_conway(::Type{GaloisField})
5656
5757
Return true, iff the modulus of the field is the standard conway polynomial.
5858
"""
5959
function is_conway(::Type{G}) where {G<:Union{GaloisField,Quotient{<:UnivariatePolynomial}}}
6060
p = modulus(G)
6161
p == conway(characteristic(G), dimension(G), varname(p))
6262
end
63+
is_conway(a::Type{Union{}}) = merror(is_conway, (a,))
6364

6465
"""
6566
quasi_conway(p, m, X::Symbol, nr::Integer=1, factors=nothing)

src/determinant.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,6 @@ function reduce_off_diagonal!(a, u, k, piv, round)
457457
end
458458
end
459459

460-
Base.div(a::T, b::T, round::RoundingMode) where T<:ZZ = T(div(value(a), value(b), round))
461-
Base.div(a::T, b::T, ::RoundingMode) where T<:Ring = div(a, b)
462-
463460
#
464461
# u, v unimodular, d diagonal with mod(d[i+1,i+1], d[i,i]) == 0
465462
# u * a * v = d

src/enumerations.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function iterate(::Type{Z}, s) where Z<:ZZmod
1717
v = Z(s.val + 1)
1818
iszero(v) ? nothing : (v, v)
1919
end
20-
function iterate(::Type{Q}, s) where {Z<:ZZmod,P<:UnivariatePolynomial{Z},Q<:Quotient{P}}
20+
function iterate(::Type{Q}, s) where {Z,P<:UnivariatePolynomial{Z},Q<:Quotient{P}}
2121
c = coeffs(s.val)
2222
m = length(c)
2323
n = deg(modulus(Q))
@@ -46,22 +46,21 @@ function next(c)
4646
cs === nothing ? nothing : cs[1]
4747
end
4848

49-
function iterate(::Type{G}) where G<:GaloisField
50-
G(0), 0
51-
end
49+
iterate(::Type{G}, s...) where G<:GaloisField = _iterate(CType(G), s...)
50+
_iterate(::CType{G}) where G<:GaloisField = (G(0), 0)
5251

53-
function iterate(::Type{G}, s::Integer) where G<:GaloisField
52+
function _iterate(::CType{G}, s::Integer) where G<:GaloisField
5453
s += 1
5554
s >= order(G) && return nothing
5655
ofindex(s, G), s
5756
end
5857

5958
function next(g::G) where G<:GaloisField
60-
s = gettypevar(G).exptable[g.val+1] + 1
59+
s = tonumber(g) + 1
6160
s >= order(G) ? nothing : ofindex(s, G)
6261
end
6362

64-
Base.eltype(::Monic{Z,X}) where {X,Z<:Ring} = Z[X]
63+
Base.eltype(::Type{<:Monic{Z,X}}) where {X,Z<:Ring} = Z[X]
6564
IteratorSize(::Type{<:Monic{Z}}) where Z = IteratorSize(Z)
6665
length(m::Monic{Z}) where Z = intpower(length(Z), m.n)
6766

@@ -93,6 +92,11 @@ function _iterate(mo::Monic{Z,X}, s, ::IsInfinite) where {X,Z}
9392
ofindex(s, P, mo.n) + monom(P, mo.n), s + 1
9493
end
9594

95+
"""
96+
isqrt2(i::Integer)
97+
98+
Return the smallest integer `x`, for which `x^2 >= 2i`.
99+
"""
96100
isqrt2(i::T) where T<:Integer = T(floor(sqrt(8 * i + 1) - 1)) ÷ 2
97101
function ipair(i::Integer)
98102
m = isqrt2(i)
@@ -139,6 +143,7 @@ function indexv(i::T, nn::Vector{T}) where T<:Integer
139143
end
140144

141145
len(::Type, d...) = 0
146+
len(::Type{Union{}}, d...) = 0
142147
len(T::Type{<:ZZmod}, d...) = modulus(T)
143148
function len(T::Type{<:FractionRing{S}}, d...) where S
144149
n = len(S, d...)
@@ -148,6 +153,7 @@ len(T::Type{<:UnivariatePolynomial{S}}, d::Integer) where S = intpower(len(S), d
148153
len(T::Type{<:QuotientRing{S}}) where S<:UnivariatePolynomial = len(S, deg(modulus(T) - 1))
149154
len(T::Type{<:GaloisField}) = order(T)
150155

156+
ofindex(a::Integer, u::Type{Union{}}) = throw(MethodError(ofindex, (a, u)))
151157
ofindex(a::Integer, T::Type{<:Unsigned}) = T(a)
152158
ofindex(a::Integer, T::Type{<:Signed}) = iseven(a) ? -(T(a) >> 1) : T(a + 1) >> 1
153159
ofindex(a::Integer, T::Type{ZZ{S}}) where S = T(ofindex(a, S))

src/factorization.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ end
1818
function num_irreducibles(::Type{G}, r) where G<:Ring
1919
num_irreducibles(G[:x], r)
2020
end
21+
num_irreducibles(a::Type{Union{}}) = throw(MethodError(num_irreducibles, (a,)))
2122

2223
"""
2324
isirreducible(p::F[X])
@@ -42,6 +43,7 @@ import Base.Iterators: Filter, take, drop
4243
4344
Returns an irreducible polynomial with in `P` with degree `n`. Skip first `nr` hits.
4445
"""
46+
irreducible(a::Type{Union{}}, s...) = merror(irreducible, (a, s...))
4547
irreducible(::Type{P}, n) where P<:UnivariatePolynomial = first(irreducibles(P, n))
4648
function irreducible(::Type{P}, n, nr::Integer) where P<:UnivariatePolynomial
4749
first(drop(irreducibles(P, n), nr))
@@ -51,6 +53,7 @@ end
5153
5254
Returns a reducible polynomial with in `P` with degree `n`. Skip first `nr` hits.
5355
"""
56+
reducible(a::Type{Union{}}, s...) = merror(reducible, (a, s...))
5457
reducible(::Type{P}, n) where P<:UnivariatePolynomial = first(reducibles(P, n))
5558
function reducible(::Type{P}, n, nr::Integer) where P<:UnivariatePolynomial
5659
first(drop(reducibles(P, n), nr))
@@ -68,6 +71,7 @@ reducibles(P, n)
6871
6972
Returns iterator of all reducible monic polynomials in `P` with degree `n`.
7073
"""
74+
irreducibles(a::Type{Union{}}, s...) = merror(reducibles, (a, s...))
7175
function reducibles(::Type{P}, n) where P<:UnivariatePolynomial{<:Ring}
7276
Base.Iterators.Filter(!isirreducible, Monic(P, n))
7377
end
@@ -228,11 +232,11 @@ function isddf(f::P) where {Z<:QuotientRing,P<:UnivariatePolynomial{Z}}
228232
q = order(Z)
229233
x = monom(typeof(f), 1)
230234
i = 1
231-
fs = f
232235
xqi = x
233-
while deg(fs) >= 2i
234-
xqi = powermod(xqi, q, fs)
235-
g = gcd(fs, xqi - x)
236+
d = deg(f)
237+
while d >= 2i
238+
xqi = powermod(xqi, q, f)
239+
g = gcd(f, xqi - x)
236240
deg(g) > 0 && return false
237241
i += 1
238242
end

src/fraction.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
# class constructors
3+
Frac(a::Type{Union{}}, s...) = merror(irreducible, (a, s...))
34
Frac(::Type{R}) where R<:Ring = Frac{R}
45
Frac(::Type{<:ZZ{R}}) where R<:Integer = QQ{R}
56
Frac(::Type{R}) where R<:Integer = QQ{R}
@@ -93,7 +94,7 @@ function Frac(a::T, b::T) where T<:Polynomial
9394
a /= s
9495
Frac{typeof(a)}(a, b, NOCHECK)
9596
end
96-
Frac(a::T, b::T) where T<:ZZ = QQ(a, b)
97+
Frac(a::T, b::T) where T<:ZI = QQ(a, b)
9798

9899
//(a::T, b::T) where T<:QQ = a / b
99100
//(a::T, b::T) where T<:Ring = Frac(a, b)

0 commit comments

Comments
 (0)