@@ -17,7 +17,7 @@ function iterate(::Type{Z}, s) where Z<:ZZmod
1717 v = Z (s. val + 1 )
1818 iszero (v) ? nothing : (v, v)
1919end
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 ]
4747end
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
5756end
5857
5958function 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)
6261end
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]
6564IteratorSize (:: Type{<:Monic{Z}} ) where Z = IteratorSize (Z)
6665length (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
9493end
9594
95+ """
96+ isqrt2(i::Integer)
97+
98+ Return the smallest integer `x`, for which `x^2 >= 2i`.
99+ """
96100isqrt2 (i:: T ) where T<: Integer = T (floor (sqrt (8 * i + 1 ) - 1 )) ÷ 2
97101function ipair (i:: Integer )
98102 m = isqrt2 (i)
@@ -139,6 +143,7 @@ function indexv(i::T, nn::Vector{T}) where T<:Integer
139143end
140144
141145len (:: Type , d... ) = 0
146+ len (:: Type{Union{}} , d... ) = 0
142147len (T:: Type{<:ZZmod} , d... ) = modulus (T)
143148function 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
148153len (T:: Type{<:QuotientRing{S}} ) where S<: UnivariatePolynomial = len (S, deg (modulus (T) - 1 ))
149154len (T:: Type{<:GaloisField} ) = order (T)
150155
156+ ofindex (a:: Integer , u:: Type{Union{}} ) = throw (MethodError (ofindex, (a, u)))
151157ofindex (a:: Integer , T:: Type{<:Unsigned} ) = T (a)
152158ofindex (a:: Integer , T:: Type{<:Signed} ) = iseven (a) ? - (T (a) >> 1 ) : T (a + 1 ) >> 1
153159ofindex (a:: Integer , T:: Type{ZZ{S}} ) where S = T (ofindex (a, S))
0 commit comments