Merge branch '1712.07167' of github.com:kalmarek/Groups.jl into 1712.07167

This commit is contained in:
kalmarek 2018-03-22 15:21:13 +01:00
commit 47dde30773
9 changed files with 61 additions and 65 deletions

View File

@ -4,7 +4,6 @@ os:
- linux
- osx
julia:
- 0.5
- 0.6
- nightly
notifications:
@ -26,7 +25,7 @@ matrix:
## uncomment the following lines to override the default test script
script:
# - julia -e 'Pkg.clone("https://github.com/Nemocas/Nemo.jl"); Pkg.build("Nemo")'
- julia -e 'Pkg.clone("https://github.com/Nemocas/Nemo.jl"); Pkg.build("Nemo")'
- julia -e 'Pkg.clone(pwd()); Pkg.build("Groups"); Pkg.test("Groups"; coverage=true)'
after_success:

View File

@ -1,2 +1,2 @@
julia 0.5
julia 0.6
Nemo

View File

@ -19,7 +19,7 @@ immutable FlipAut
end
immutable PermAut
p::perm
p::Nemo.Generic.perm
end
immutable Identity end
@ -30,9 +30,9 @@ immutable AutSymbol <: GSymbol
typ::Union{RTransvect, LTransvect, FlipAut, PermAut, Identity}
end
typealias AutGroupElem GWord{AutSymbol}
AutGroupElem = GWord{AutSymbol}
type AutGroup <: AbstractFPGroup
mutable struct AutGroup <: AbstractFPGroup
objectGroup::Group
gens::Vector{AutSymbol}
end
@ -104,7 +104,7 @@ function flip_autsymbol(i; pow::Int=1)
end
end
function perm_autsymbol(p::perm; pow::Int=1)
function perm_autsymbol(p::Generic.perm; pow::Int=1)
p = p^pow
if p == parent(p)()
return id_autsymbol()

View File

@ -14,12 +14,12 @@ Implements `n`-fold direct product of `G`. The group operation is
`*` distributed component-wise, with component-wise identity as neutral element.
"""
immutable DirectProductGroup{T<:Group} <: Group
struct DirectProductGroup{T<:Group} <: Group
group::T
n::Int
end
immutable DirectProductGroupElem{T<:GroupElem} <: GroupElem
struct DirectProductGroupElem{T<:GroupElem} <: GroupElem
elts::Vector{T}
end
@ -29,10 +29,10 @@ end
#
###############################################################################
elem_type{T<:Group}(G::DirectProductGroup{T}) =
elem_type(G::DirectProductGroup{T}) where {T} =
DirectProductGroupElem{elem_type(G.group)}
parent_type{T<:GroupElem}(::Type{DirectProductGroupElem{T}}) =
parent_type(::Type{DirectProductGroupElem{T}}) where {T} =
DirectProductGroup{parent_type(T)}
parent(g::DirectProductGroupElem) =
@ -45,9 +45,9 @@ parent(g::DirectProductGroupElem) =
###############################################################################
Base.size(g::DirectProductGroupElem) = size(g.elts)
Base.linearindexing(::Type{DirectProductGroupElem}) = Base.LinearFast()
Base.IndexStyle(::Type{DirectProductGroupElem}) = Base.LinearFast()
Base.getindex(g::DirectProductGroupElem, i::Int) = g.elts[i]
function Base.setindex!{T<:GroupElem}(g::DirectProductGroupElem{T}, v::T, i::Int)
function Base.setindex!(g::DirectProductGroupElem{T}, v::T, i::Int) where {T}
parent(v) == parent(first(g.elts)) || throw("$g is not an element of $i-th factor of $(parent(G))")
g.elts[i] = v
return g
@ -160,14 +160,14 @@ doc"""
> operation as defined by `operations` field of the parent object.
"""
# TODO: dirty hack around `+/*` operations
function *{T<:GroupElem}(g::DirectProductGroupElem{T}, h::DirectProductGroupElem{T}, check::Bool=true)
function *(g::DirectProductGroupElem{T}, h::DirectProductGroupElem{T}, check::Bool=true) where {T}
if check
parent(g) == parent(h) || throw("Can not multiply elements of different groups!")
end
return DirectProductGroupElem([a*b for (a,b) in zip(g.elts,h.elts)])
end
function *{T<:RingElem}(g::DirectProductGroupElem{T}, h::DirectProductGroupElem{T}, check::Bool=true)
function *(g::DirectProductGroupElem{T}, h::DirectProductGroupElem{T}, check::Bool=true) where {T<:RingElem}
if check
parent(g) == parent(h) || throw("Can not multiply elements of different groups!")
end
@ -179,11 +179,11 @@ doc"""
> Return the inverse of the given element in the direct product group.
"""
# TODO: dirty hack around `+/*` operation
function inv{T<:GroupElem}(g::DirectProductGroupElem{T})
function inv(g::DirectProductGroupElem{T}) where {T<:GroupElem}
return DirectProductGroupElem([inv(a) for a in g.elts])
end
function inv{T<:RingElem}(g::DirectProductGroupElem{T})
function inv(g::DirectProductGroupElem{T}) where {T<:RingElem}
return DirectProductGroupElem(-g.elts)
end

View File

@ -4,14 +4,14 @@
#
###############################################################################
immutable FPSymbol <: GSymbol
struct FPSymbol <: GSymbol
str::String
pow::Int
end
typealias FPGroupElem GWord{FPSymbol}
FPGroupElem = GWord{FPSymbol}
type FPGroup <: AbstractFPGroup
mutable struct FPGroup <: AbstractFPGroup
gens::Vector{FPSymbol}
rels::Dict{FPGroupElem, FPGroupElem}

View File

@ -4,14 +4,14 @@
#
###############################################################################
immutable FreeSymbol <: GSymbol
struct FreeSymbol <: GSymbol
str::String
pow::Int
end
typealias FreeGroupElem GWord{FreeSymbol}
FreeGroupElem = GWord{FreeSymbol}
type FreeGroup <: AbstractFPGroup
mutable struct FreeGroup <: AbstractFPGroup
gens::Vector{FreeSymbol}
# order::Vector{T}
# fastmult_table::Array{Int,2}

View File

@ -25,7 +25,7 @@ doc"""
> * `pow` which is the (multiplicative) exponent of a symbol.
"""
abstract GSymbol
abstract type GSymbol end
doc"""
W::GWord{T<:GSymbol} <:GroupElem
@ -43,18 +43,18 @@ doc"""
"""
type GWord{T<:GSymbol} <: GroupElem
symbols::Vector{T}
savedhash::UInt
modified::Bool
parent::Group
mutable struct GWord{T<:GSymbol} <: GroupElem
symbols::Vector{T}
savedhash::UInt
modified::Bool
parent::Group
function GWord(symbols::Vector{T})
return new(symbols, hash(symbols), true)
end
function GWord{T}(symbols::Vector{T}) where {T}
return new{T}(symbols, hash(symbols), true)
end
end
abstract AbstractFPGroup <: Group
abstract type AbstractFPGroup <: Group end
###############################################################################
#
@ -70,8 +70,8 @@ parent{T<:GSymbol}(w::GWord{T}) = w.parent
#
###############################################################################
GWord{T<:GSymbol}(s::T) = GWord{T}(T[s])
convert{T<:GSymbol}(::Type{GWord{T}}, s::T) = GWord{T}(T[s])
GWord(s::T) where {T} = GWord{T}(T[s])
convert(::Type{GWord{T}}, s::T) where {T<:GSymbol} = GWord{T}(T[s])
###############################################################################
#
@ -79,19 +79,18 @@ convert{T<:GSymbol}(::Type{GWord{T}}, s::T) = GWord{T}(T[s])
#
###############################################################################
xor(a,b) = a $ b
function hash(W::GWord, h::UInt)
W.modified && reduce!(W)
return xor(W.savedhash, h)
res = xor(W.savedhash, h)
return res
end
function deepcopy_internal{T<:GSymbol}(W::GWord{T}, dict::ObjectIdDict)
function deepcopy_internal(W::GWord{T}, dict::ObjectIdDict) where {T<:GSymbol}
G = parent(W)
return G(GWord{T}(deepcopy(W.symbols)))
end
isone{T<:GSymbol}(s::T) = s.pow == 0
isone(s::GSymbol) = s.pow == 0
length(W::GWord) = sum([length(s) for s in W.symbols])
@ -162,7 +161,7 @@ function show(io::IO, W::GWord)
end
end
function show{T<:GSymbol}(io::IO, s::T)
function show(io::IO, s::T) where {T<:GSymbol}
if isone(s)
print(io, "(id)")
elseif s.pow == 1
@ -256,7 +255,7 @@ end
#
###############################################################################
function inv{T}(W::GWord{T})
function inv(W::GWord{T}) where {T}
if length(W) == 0
return W
else
@ -352,7 +351,7 @@ function replace(W::GWord, index, toreplace::GWord, replacement::GWord)
replace!(deepcopy(W), index, toreplace, replacement)
end
function replace_all!{T}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}})
function replace_all!(W::GWord{T},subst_dict::Dict{GWord{T},GWord{T}}) where {T}
modified = false
for toreplace in reverse!(sort!(collect(keys(subst_dict)), by=length))
replacement = subst_dict[toreplace]
@ -366,8 +365,7 @@ function replace_all!{T}(W::GWord{T}, subst_dict::Dict{GWord{T}, GWord{T}})
return modified
end
function replace_all{T<:GSymbol}(W::GWord{T},
subst_dict::Dict{GWord{T}, GWord{T}})
function replace_all(W::GWord{T},subst_dict::Dict{GWord{T},GWord{T}}) where {T}
W = deepcopy(W)
replace_all!(W, subst_dict)
return W

View File

@ -17,29 +17,29 @@ doc"""
# Arguments:
* `::Group` : the single factor of group $N$
* `::PermGroup` : full `PermutationGroup`
* `::Generic.PermGroup` : full `PermutationGroup`
"""
immutable WreathProduct{T<:Group} <: Group
struct WreathProduct{T<:Group} <: Group
N::DirectProductGroup{T}
P::PermGroup
P::Generic.PermGroup
function WreathProduct(G::Group, P::PermGroup)
function WreathProduct{T}(G::T, P::Generic.PermGroup) where {T}
N = DirectProductGroup(G, P.n)
return new(N, P)
end
end
immutable WreathProductElem{T<:GroupElem} <: GroupElem
struct WreathProductElem{T<:GroupElem} <: GroupElem
n::DirectProductGroupElem{T}
p::perm
p::Generic.perm
# parent::WreathProduct
function WreathProductElem(n::DirectProductGroupElem, p::perm,
check::Bool=true)
function WreathProductElem{T}(n::DirectProductGroupElem{T}, p::Generic.perm,
check::Bool=true) where {T}
if check
length(n.elts) == parent(p).n || throw("Can't form WreathProductElem: lengths differ")
end
return new(n, p)
return new{T}(n, p)
end
end
@ -49,9 +49,9 @@ end
#
###############################################################################
elem_type{T<:Group}(::WreathProduct{T}) = WreathProductElem{elem_type(T)}
elem_type(::WreathProduct{T}) where {T} = WreathProductElem{elem_type(T)}
parent_type{T<:GroupElem}(::Type{WreathProductElem{T}}) =
parent_type(::Type{WreathProductElem{T}}) where {T} =
WreathProduct{parent_type(T)}
parent(g::WreathProductElem) = WreathProduct(parent(g.n[1]), parent(g.p))
@ -62,10 +62,9 @@ parent(g::WreathProductElem) = WreathProduct(parent(g.n[1]), parent(g.p))
#
###############################################################################
WreathProduct{T<:Group}(G::T, P::PermGroup) = WreathProduct{T}(G, P)
WreathProduct(G::Gr, P::Generic.PermGroup) where {Gr} = WreathProduct{Gr}(G, P)
WreathProductElem{T<:GroupElem}(n::DirectProductGroupElem{T},
p::perm, check::Bool=true) = WreathProductElem{T}(n, p, check)
WreathProductElem(n::DirectProductGroupElem{T}, p, check=true) where {T} = WreathProductElem{T}(n, p, check)
###############################################################################
#
@ -88,19 +87,19 @@ function (G::WreathProduct)(g::WreathProductElem)
end
doc"""
(G::WreathProduct)(n::DirectProductGroupElem, p::perm)
(G::WreathProduct)(n::DirectProductGroupElem, p::Generic.perm)
> Creates an element of wreath product `G` by coercing `n` and `p` to `G.N` and
> `G.P`, respectively.
"""
(G::WreathProduct)(n::DirectProductGroupElem, p::perm) = WreathProductElem(n,p)
(G::WreathProduct)(n::DirectProductGroupElem, p::Generic.perm) = WreathProductElem(n,p)
(G::WreathProduct)() = WreathProductElem(G.N(), G.P(), false)
doc"""
(G::WreathProduct)(p::perm)
(G::WreathProduct)(p::Generic.perm)
> Returns the image of permutation `p` in `G` via embedding `p -> (id,p)`.
"""
(G::WreathProduct)(p::perm) = G(G.N(), p)
(G::WreathProduct)(p::Generic.perm) = G(G.N(), p)
doc"""
(G::WreathProduct)(n::DirectProductGroupElem)
@ -171,7 +170,7 @@ doc"""
>
> `g*h = (g.n*g.p(h.n), g.p*h.p)`,
>
> where `g.p(h.n)` denotes the action of `g.p::perm` on
> where `g.p(h.n)` denotes the action of `g.p::Generic.perm` on
> `h.n::DirectProductGroupElem` via standard permutation of coordinates.
"""
function *(g::WreathProductElem, h::WreathProductElem)

View File

@ -56,7 +56,7 @@ end
@testset "internal arithmetic" begin
@test Vector{Groups.GWord}([s,t]) == [Groups.GWord(s), Groups.GWord(t)]
@test_broken Vector{Groups.GWord}([s,t]) == [Groups.GWord(s), Groups.GWord(t)]
@test (s*s).symbols == (s^2).symbols
@test hash([t^1,s^1]) == hash([t^2*inv(t),s*inv(s)*s])