-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymGrpAndReps.jl
201 lines (167 loc) · 4.54 KB
/
SymGrpAndReps.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
function Sym(A::Array)
if length(A) >= 14
error("Slow down... be careful, n >= 14, and |S_n| = $(factorial(big(length(A)))) ")
end
Perms = Array{eltype(A),1}[]
function continuePerm(head,tail)
if length(tail) > 0
for (i,t) in enumerate(tail)
newHead = vcat(head, t)
newTail = vcat(tail[1:(i-1)], tail[(i+1):end])
continuePerm(newHead, newTail)
end
else
push!(Perms, head)
end
end
continuePerm(eltype(A)[], A)
return Perms
end
function Sym(A::Set)
if length(A) >= 14
error("Slow down... be careful, n >= 14, and |S_n| = $(factorial(big(length(A)))) ")
end
Perms = Array{eltype(A),1}[]
function continuePerm(head,tail)
if length(tail) > 0
for t in tail
newHead = union(head, [t])
newTail = setdiff(tail, [t])
continuePerm(newHead, newTail)
end
else
push!(Perms, head)
end
end
continuePerm(eltype(A)[], A)
return Perms
end
function Sym(n::Integer)
if n >= 14
error("Slow down... be careful, n >= 14, and |S_n| = $(factorial(big(n))) ")
end
A = collect(Int8, 1:n)
Perms = Array{Int8,1}[]
function continuePerm(head,tail)
if length(tail) > 0
for t in tail
newHead = union(head, [t])
newTail = setdiff(tail, [t])
continuePerm(newHead, newTail)
end
else
push!(Perms, head)
end
end
continuePerm(Int8[], A)
return Perms
end
function RepSym(n::Integer)
if n >= 14
error("Slow down... be careful, n >= 14, and |S_n| = $(factorial(big(n))) ")
end
MatPerms = BitArray{2}[]
function continuePerm( M ,tail)
if length(tail) > 0
c = n - length(tail) + 1
for t in tail
newM = deepcopy(M)
newM[ t , c ] = 1
newTail = setdiff(tail, [t])
continuePerm( newM , newTail)
end
else
push!( MatPerms, M )
end
end
# Init function w/ nxn BitArray of 0s and dense [1,2,...,n]
continuePerm( falses(n,n) , BitSet(1:n) )
return MatPerms
end
function Rep(t::Array)
M = falses(length(t),length(t))
for i in 1:length(t)
M[ t[i] , i ] = 1
end
return M
end
function Rep(t::Array, Res::Array)
if !(issubset(Res, t))
error("Restriction is not contained in the domain of the perm, t.")
end
M = falses(length(t), length(t))
for j in Res
M[ t[j] , j ] = 1
end
return M
end
function Rep(t::Array, Ind::Array)
if !(issubset(t, Ind))
error("The image of the perm t is not contained in the Induced space")
end
M = falses( length(Ind), length(Ind))
for j in sort(t)
M[ t[j] , j ] = 1
end
return M
end
#function TensorRep(t::)
function sgn(a::Array{Int8,1})
d = length(a)
return prod([ sign(a[j] - a[i]) for i in 1:d for j in i+1:d ])
end
function sgn(M::BitArray{2})
d = size(M,1)
negs = 0
for i in 1:d
ti = findfirst( M[:,i] )
negs += sum( M[ 1:(ti-1) , (i+1):d ] )
end
return negs%2 == 0 ? 1 : -1
end
# Symmetrization operations
# for a permutation
function SymOp( M::Array{<:Number, d}) where d
return 1//factorial(d) * mapreduce( p -> permutedims(M, p), +, Sym(d) )
end
# for a d-dimensional array
function SymOp( M::BitArray{d}) where d
return 1/factorial(d) * mapreduce( p -> permutedims(M, p), +, Sym(d) )
end
# Alternating operations
# for a permutation
function AltOp( M::Array{<:Number, d}) where d
return 1//factorial(d)* mapreduce( p -> sgn(p)*permutedims(M, p), +, Sym(d) )
end
# for a d-dimensional array
function AltOp( M::BitArray{d}) where d
return 1/factorial(d)* mapreduce( p -> sgn(p)*permutedims(M, p), +, Sym(d) )
end
#=
setindex!(::typeof(f), ::Int64, ::Int64)
f(1) = 1
struct Group <: Union{ Set{Function}, Function }
A::Set{Function}
op::Function
assert( all( g * h for a in A, h in A))
end
struct Group <: Union{ Set{Function}, Function }
A::Set{Function}
op::Function
assert( all( g * h for a in A, h in A))
end
Type Group <: Union{Set,Function} end
struct Group
abstract type Group <: Union{ Set{T}, Function{T,T}{T} } end
Sym(C::Set) = ({ All Permuations of C } , ∘ )
Group = ( {things} , op: )
struct Group{T}
S::Set{T}
op::Function
end
struct SymmetricGroup
C::Set{Countries}
op::Function{Countries,Countries}
end
=#
#dlkfsdjfjls