gpt4 book ai didi

julia - Julia 中的对称组 Action

转载 作者:行者123 更新时间:2023-12-03 23:40:46 25 4
gpt4 key购买 nike

我是 Julia 的新人。我想做一个可以使用组操作的程序。
例如:在$\mathbb{R}^{4}$中取一个向量$(a,b,c,d)$,考虑$S_{4}$的元素对此的作用,如循环$(1,2,3,4)$。我想要一个程序来计算:
$$(1,2,3,4)(a,b,c,d) = (d,a,b,c)$$
如果可以进行任何排列,那就太好了。您知道我必须下载哪些软件包吗?以及我该怎么写?
感谢您的帮助。

最佳答案

您可能喜欢 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

关于julia - Julia 中的对称组 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65997763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com