Iterator protocol for elements of Nemo.FinField

This commit is contained in:
kalmar 2017-06-08 19:51:48 +02:00
parent 6d07adabf3
commit 762f069cbd

View File

@ -11,20 +11,47 @@ import Nemo.elements
using JLD
function elements(F::Nemo.FqNmodFiniteField)
deg = Int(degree(F))
char = Int(characteristic(F))
z = (gen(F)^i for i in 0:deg-1)
crtsn_prd = Base.product([0:char-1 for i in 1:deg]...)
include("Projections.jl")
function _it()
for crt in crtsn_prd
g = sum([b*a for (a,b) in zip(z,crt)])
produce(g)
end
###############################################################################
#
# Iterator protocol for Nemo.FinField
#
###############################################################################
type FFEltsIter{T<:Nemo.FinField}
all::Int
field::T
function FFEltsIter(F::T)
return new(Int(characteristic(F)^degree(F)), F)
end
return Task(_it)
end
FFEltsIter{T<:Nemo.FinField}(F::T) = FFEltsIter{T}(F)
import Base: start, next, done, eltype, length
Base.start(A::FFEltsIter) = (zero(A.field), 0)
Base.next(A::FFEltsIter, state) = next_ffelem(state...)
Base.done(A::FFEltsIter, state) = state[2] >= A.all
Base.eltype(::Type{FFEltsIter}) = elem_type(A.field)
Base.length(A::FFEltsIter) = A.all
function next_ffelem(f::Nemo.FinFieldElem, c::Int)
if c == 0
return (f, (f, 1))
elseif c == 1
f = one(parent(f))
return (f, (f, 2))
else
f = gen(parent(f))*f
return (f, (f, c+1))
end
end
import Nemo.elements
elements(F::Nemo.FinField) = FFEltsIter(F)
function AutFG_emb(A::AutGroup, g::WreathProductElem)
isa(A.objectGroup, FreeGroup) || throw("Not an Aut(Fₙ)")