Symmetric group action in Julia

Viewed 109

I am new in Julia. I want to do a program where I can use group Actions.

For example: Take a vector $(a,b,c,d)$ in $\mathbb{R}^{4}$, and consider the action of elements of $S_{4}$ on this, such as the cycle $(1,2,3,4)$. I would like to have a program which computes:

$$(1,2,3,4)(a,b,c,d) = (d,a,b,c)$$

It would be great if this would be possible for any permutation. Do you have any ideas which packages must I download? and How must I write it?

thank you for your help.

1 Answers

You might like the package Permutations, https://github.com/scheinerman/Permutations.jl.

julia> using Permutations

julia> p = Permutation([2,3,4,1]) # an element of S_4
(1,2,3,4)                         # printed in cycle notation

julia> p(1)  # apply it to one element
2

julia> two_row(p)  # alternative way to print this
2×4 Matrix{Int64}:
 1  2  3  4
 2  3  4  1

julia> inv(p)
(1,4,3,2)

julia> input = [:a, :b, :c, :d];  # an array of any 4 things

julia> [input[p(i)] for i in eachindex(input)]  # permute those?
4-element Vector{Symbol}:
 :b
 :c
 :d
 :a

julia> ans == input[p.(eachindex(input))]  # another way to write the same
true

julia> input[inv(p).(eachindex(input))]  # with inv(p)
4-element Vector{Symbol}:
 :d
 :a
 :b
 :c

julia> Permutation([2,3,1,4,6,5])
(1,2,3)(4)(5,6)                   # it really prints the cycles
Related