From 02ce259eb4f9f8f7b4fce8b7c76b6f4db9c4206a Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 25 Mar 2020 00:43:04 +0100 Subject: [PATCH] rewrite simplifyperms! in the new word api --- src/AutGroup.jl | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/AutGroup.jl b/src/AutGroup.jl index 31acf96..3838ad9 100644 --- a/src/AutGroup.jl +++ b/src/AutGroup.jl @@ -335,31 +335,22 @@ end # ############################################################################### -function getperm(s::AutSymbol) - if s.pow != 1 - @warn("Power for perm_symbol should be never 0!") - return s.fn.perm^s.pow - else - return s.fn.perm - end -end +getperm(s::AutSymbol) = s.fn.perm^s.pow -function simplifyperms!(W::Automorphism{N}) where N +function simplifyperms!(::Type{Bool}, w::Automorphism{N}) where N reduced = true - to_delete = Int[] - for i in 1:length(W.symbols)-1 - if W.symbols[i].pow == 0 + for i in 1:syllablelength(w)-1 + s, ns = syllables(w)[i], syllables(w)[i+1] + if isone(s) continue - elseif W.symbols[i].fn isa PermAut && W.symbols[i+1].fn isa PermAut + elseif s.fn isa PermAut && ns.fn isa PermAut reduced = false - c = W.symbols[i] - n = W.symbols[i+1] - W.symbols[i+1] = perm_autsymbol(getperm(c)*getperm(n)) - push!(to_delete, i) + setmodified!(w) + syllables(w)[i+1] = AutSymbol(getperm(s)*getperm(ns)) + syllables(w)[i] = change_pow(s, 0) end end - deleteat!(W.symbols, to_delete) - deleteids!(W) + filter!(!isone, syllables(w)) return reduced end