phi :: Int -> Int -> CycleStructure -> CycleStructure
phi k i pi = phi' $ rescale i pi where
  phi' [] = [[i]]
  phi' pi'@(c1:cs)
    | i < head c1        = [i]:c1:cs
    | length c1 == k     = case c1 of (a1:a2:as) -> (a1:i:as) : phi k a2 cs
    | length c1 == k - 1 = p i $ psi k c1 cs
    | otherwise          = p i pi'
phi :: Int -> Int -> CycleStructure -> CycleStructure
phi k i pi = phi' $ rescale i pi where
  phi' [] = [[i]]
  phi' pi'@(c1:cs)
    | i < head c1        = [i]:c1:cs
    | length c1 == k     = case c1 of (a1:a2:as) -> (a1:i:as) : phi k a2 cs
    | length c1 == k - 1 = p i $ psi k c1 cs
    | otherwise          = p i pi'
phi k i pi = phi' $ rescale i pi where
  phi' [] = [[i]]
  phi' pi'@(c1:cs)
    | i < head c1        = [i]:c1:cs
    | length c1 == k     = case c1 of (a1:a2:as) -> (a1:i:as) : phi k a2 cs
    | length c1 == k - 1 = p i $ psi k c1 cs
    | otherwise          = p i pi'