def test_generators(): assert list(cyclic(6)) == [Permutation([0, 1, 2, 3, 4, 5]), Permutation([1, 2, 3, 4, 5, 0]), \ Permutation([2, 3, 4, 5, 0, 1]), Permutation([3, 4, 5, 0, 1, 2]), \ Permutation([4, 5, 0, 1, 2, 3]), Permutation([5, 0, 1, 2, 3, 4])] assert list(cyclic(10)) == [Permutation([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), \ Permutation([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), \ Permutation([2, 3, 4, 5, 6, 7, 8, 9, 0, 1]), \ Permutation([3, 4, 5, 6, 7, 8, 9, 0, 1, 2]), \ Permutation([4, 5, 6, 7, 8, 9, 0, 1, 2, 3]), \ Permutation([5, 6, 7, 8, 9, 0, 1, 2, 3, 4]), \ Permutation([6, 7, 8, 9, 0, 1, 2, 3, 4, 5]), \ Permutation([7, 8, 9, 0, 1, 2, 3, 4, 5, 6]), \ Permutation([8, 9, 0, 1, 2, 3, 4, 5, 6, 7]), \ Permutation([9, 0, 1, 2, 3, 4, 5, 6, 7, 8])] assert list(alternating(4)) == [Permutation([0, 1, 2, 3]), Permutation([0, 2, 3, 1]), \ Permutation([0, 3, 1, 2]), Permutation([1, 0, 3, 2]), \ Permutation([1, 2, 0, 3]), Permutation([1, 3, 2, 0]), \ Permutation([2, 0, 1, 3]), Permutation([2, 1, 3, 0]), \ Permutation([2, 3, 0, 1]), Permutation([3, 0, 2, 1]), \ Permutation([3, 1, 0, 2]), Permutation([3, 2, 1, 0])] assert list(symmetric(3)) == [Permutation([0, 1, 2]), Permutation([0, 2, 1]), Permutation([1, 0, 2]), \ Permutation([1, 2, 0]), Permutation([2, 0, 1]), Permutation([2, 1, 0])] assert list(symmetric(4)) == [Permutation([0, 1, 2, 3]), Permutation([0, 1, 3, 2]), Permutation([0, 2, 1, 3]), \ Permutation([0, 2, 3, 1]), Permutation([0, 3, 1, 2]), Permutation([0, 3, 2, 1]), \ Permutation([1, 0, 2, 3]), Permutation([1, 0, 3, 2]), Permutation([1, 2, 0, 3]), \ Permutation([1, 2, 3, 0]), Permutation([1, 3, 0, 2]), Permutation([1, 3, 2, 0]), \ Permutation([2, 0, 1, 3]), Permutation([2, 0, 3, 1]), Permutation([2, 1, 0, 3]), \ Permutation([2, 1, 3, 0]), Permutation([2, 3, 0, 1]), Permutation([2, 3, 1, 0]), \ Permutation([3, 0, 1, 2]), Permutation([3, 0, 2, 1]), Permutation([3, 1, 0, 2]), \ Permutation([3, 1, 2, 0]), Permutation([3, 2, 0, 1]), Permutation([3, 2, 1, 0])] assert list(dihedral(2)) == [Permutation([0, 1, 2, 3]), Permutation([1, 0, 3, 2]), \ Permutation([2, 3, 0, 1]), Permutation([3, 2, 1, 0])] assert list(dihedral(3)) == [Permutation([0, 1, 2]), Permutation([2, 1, 0]), Permutation([1, 2, 0]), \ Permutation([0, 2, 1]), Permutation([2, 0, 1]), Permutation([1, 0, 2])] assert list(dihedral(5)) == [Permutation([0, 1, 2, 3, 4]), Permutation([4, 3, 2, 1, 0]), \ Permutation([1, 2, 3, 4, 0]), Permutation([0, 4, 3, 2, 1]), \ Permutation([2, 3, 4, 0, 1]), Permutation([1, 0, 4, 3, 2]), \ Permutation([3, 4, 0, 1, 2]), Permutation([2, 1, 0, 4, 3]), \ Permutation([4, 0, 1, 2, 3]), Permutation([3, 2, 1, 0, 4])]
def enumerate_standard_Young_tableax(partition): n=sum(partition) orig = triangleOfNumbers(partition) o=[] for permutation in symmetric(n): new = [[permutation(i) for i in j] for j in orig] #new = [permutation(j) for j in orig] if isStandard(new): #yield new o.append(new) return o
def enumerate_Young_tableax_and_count_standard(partition): n=sum(partition) orig = triangleOfNumbers(partition) o=[] count=0 for permutation in symmetric(n): new = [[permutation(i) for i in j] for j in orig] #new = [permutation(j) for j in orig] if isStandard(new): count += 1 o.append(new) return o,count
def _gl_invariant_for_identity(dim,level): assert level % dim == 0 weight = level // dim result = dict() for taus in itertools.product(symmetric(dim),repeat=weight): index = [] sign = 1 for tau in taus: sign *= tau.signature() for i in range(dim): index.append( (i^tau) + 1) result[ words.ShuffleWord(index) ] = sign return lc.LinearCombination(result)
def _so_invariants_with_one_det(dim,level): # no determinant fits or, using one determinant, the other spots cannot be used for inner products if level < dim or (level - dim) % 2 == 1: yield from [] elif level == dim: yield _gl_invariant_for_identity(dim, dim) else: for det_positions in itertools.combinations(range(level),dim): # positions for the determinant rest = set(range(level))-set(det_positions) for partitions in equal_size_partitions(rest, 2): inv = defaultdict(int) for tau in symmetric(dim): for letters in itertools.product( range(1,dim+1), repeat=level//2 ): current_word = np.zeros( level, dtype=np.int8 ) for i in range( (level-dim)//2 ): current_word[ partitions[i][0] ] = letters[i] current_word[ partitions[i][1] ] = letters[i] det_letters = [ (i^tau) + 1 for i in range(dim) ] for i in range(dim): current_word[ det_positions[i] ] = det_letters[i] sign = tau.signature() inv[ words.ShuffleWord(current_word) ] += sign yield lc.LinearCombination( inv )
def generate_groups(): alternating_6 = list(gens.alternating(6)) odd_6 = [x for x in list(gens.symmetric(6)) if x not in alternating_6] return alternating_6, odd_6
def getRowColumnPermutations(partition): each_row_permutation = [list(symmetric(i)) for i in partition] each_col_permutation = [list(symmetric(i)) for i in conjugatePartition(partition)] return each_row_permutation,each_col_permutation
def possible_draws_without_repetition( S, n ): """All (ordered) sequences of drawing n times from S, without repetition.""" for subset in itertools.combinations(S,n): for p in symmetric(n): yield [ subset[i^p] for i in range(n) ]