class Algebra::Permutation
Attributes
perm[RW]
Public Class Methods
[](*a)
click to toggle source
# File lib/algebra/permutation-group.rb, line 49 def self.[](*a) new(a) end
cyclic2perm(c, n = nil)
click to toggle source
# File lib/algebra/permutation-group.rb, line 218 def self.cyclic2perm(c, n = nil) n = c.flatten.max + 1 unless n a = (0...n).collect do |i| c.each do |b| if j = b.index(i) i = b[(j + 1) % b.size] end end i end new(a) end
new(x)
click to toggle source
# File lib/algebra/permutation-group.rb, line 57 def initialize(x) @perm = x end
unity(d)
click to toggle source
# File lib/algebra/permutation-group.rb, line 53 def self.unity(d) new((0...d).to_a) end
Public Instance Methods
[](i)
click to toggle source
# File lib/algebra/permutation-group.rb, line 95 def [](i) @perm[i] || i end
Also aliased as: call
conjugate(g)
click to toggle source
# File lib/algebra/permutation-group.rb, line 138 def conjugate(g) g * self * g.inverse end
decompose_cyclic()
click to toggle source
# File lib/algebra/permutation-group.rb, line 142 def decompose_cyclic s = [] remain = (0...size).to_a while f = remain.shift a = [f] i = f loop do j = self[i] if j == f s.push a if a.size > 1 break else remain.delete j a.push j i = j end end end s end
decompose_transposition()
click to toggle source
# File lib/algebra/permutation-group.rb, line 197 def decompose_transposition a = [] (0...degree).each do |i| a << [i, self[i]] end r = [] loop do a.delete_if { |i, x| i == x } break if a.empty? i, x = a.shift x, j = alpha = a.assoc(x) a.delete(alpha) unless j == i a.rassoc(i)[1] = j r.unshift [i, j] end r.unshift [i, x] end r end
degree()
click to toggle source
# File lib/algebra/permutation-group.rb, line 67 def degree @perm.size end
Also aliased as: size
each(&b)
click to toggle source
# File lib/algebra/permutation-group.rb, line 73 def each(&b) @perm.each(&b) end
eql?(other)
click to toggle source
# File lib/algebra/permutation-group.rb, line 77 def eql?(other) @perm.eql?(other.perm) end
Also aliased as: ==
hash()
click to toggle source
# File lib/algebra/permutation-group.rb, line 83 def hash @perm.hash end
index(i)
click to toggle source
def []=(i, x); @perm = x; end
# File lib/algebra/permutation-group.rb, line 103 def index(i) @perm.index(i) end
inspect()
click to toggle source
# File lib/algebra/permutation-group.rb, line 87 def inspect @perm.inspect end
inverse()
click to toggle source
alias * left_act
# File lib/algebra/permutation-group.rb, line 119 def inverse self.class.new((0...degree).collect { |i| index(i) }) end
Also aliased as: inv
left_act(other)
click to toggle source
# File lib/algebra/permutation-group.rb, line 113 def left_act(other) self.class.new(other.collect { |i| self[i] }) end
right_act(other)
click to toggle source
# File lib/algebra/permutation-group.rb, line 107 def right_act(other) # permutation's traditional product (g*h)[x] == h[g[x]] self.class.new(collect { |i| other[i] }) end
Also aliased as: *
sign()
click to toggle source
# File lib/algebra/permutation-group.rb, line 125 def sign a = perm.dup b = inverse.perm s = 1 (0...(degree - 1)).each do |i| next unless (j = a[i]) != i a[b[i]] = j b[j] = b[i] s = -s end s end
to_map()
click to toggle source
require “algebra/finite-map”
# File lib/algebra/permutation-group.rb, line 189 def to_map m = Map.phi @perm.each_with_index do |x, i| m.append!(i, x) end m end
to_s()
click to toggle source
# File lib/algebra/permutation-group.rb, line 91 def to_s @perm.inspect end
unity()
click to toggle source
# File lib/algebra/permutation-group.rb, line 63 def unity self.class.unity(@perm.size) end