Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The inverse ``~p`` of a SymPy permutation ``p`` gives the expected result when accessed like ``i^~p``, but ``~p(i) gives a negative result. This script converts these weird results into normal permutations, and shows the resulting pattern.
- # https://en.wikiversity.org/wiki/Permutation_notation#SymPy
- from itertools import permutations
- from sympy.combinatorics import Permutation
- from bidict import bidict
- from math import factorial
- for n in range(2, 6):
- print('\n============================== ', n, ' ==============================\n')
- fact_n = factorial(n)
- perms_iter = permutations([i for i in range(n)])
- perms = bidict()
- for i, perm in enumerate(perms_iter):
- perms[fact_n-1-i] = Permutation(perm[::-1]) # create reverse colexicographic order
- converted_list = []
- for index1 in range(fact_n):
- perm1 = perms[index1]
- for index2 in range(fact_n):
- perm2 = perms[index2]
- if ~perm2 == perm1:
- weird_perm = [~perm2(i) for i in range(n)] # the result with negative numbers
- converted_perm = [n+weird_perm[i] for i in range(n)]
- converted_perm_object = Permutation(converted_perm)
- for index3 in range(fact_n):
- perm3 = perms[index3]
- if perm3 == converted_perm_object:
- converted_list.append(index3)
- print(index1, converted_perm, index3)
- print('\n', converted_list)
- """
- ============================== 2 ==============================
- 0 [1, 0] 1
- 1 [0, 1] 0
- [1, 0]
- ============================== 3 ==============================
- 0 [2, 1, 0] 5
- 1 [1, 2, 0] 4
- 2 [2, 0, 1] 3
- 3 [1, 0, 2] 1
- 4 [0, 2, 1] 2
- 5 [0, 1, 2] 0
- [5, 4, 3, 1, 2, 0]
- ============================== 4 ==============================
- 0 [3, 2, 1, 0] 23
- 1 [2, 3, 1, 0] 22
- 2 [3, 1, 2, 0] 21
- 3 [2, 1, 3, 0] 19
- 4 [1, 3, 2, 0] 20
- 5 [1, 2, 3, 0] 18
- 6 [3, 2, 0, 1] 17
- 7 [2, 3, 0, 1] 16
- 8 [3, 1, 0, 2] 11
- 9 [2, 1, 0, 3] 5
- 10 [1, 3, 0, 2] 10
- 11 [1, 2, 0, 3] 4
- 12 [3, 0, 2, 1] 15
- 13 [2, 0, 3, 1] 13
- 14 [3, 0, 1, 2] 9
- 15 [2, 0, 1, 3] 3
- 16 [1, 0, 3, 2] 7
- 17 [1, 0, 2, 3] 1
- 18 [0, 3, 2, 1] 14
- 19 [0, 2, 3, 1] 12
- 20 [0, 3, 1, 2] 8
- 21 [0, 2, 1, 3] 2
- 22 [0, 1, 3, 2] 6
- 23 [0, 1, 2, 3] 0
- [23, 22, 21, 19, 20, 18, 17, 16, 11, 5, 10, 4, 15, 13, 9, 3, 7, 1, 14, 12, 8, 2, 6, 0]
- ============================== 5 ==============================
- 0 [4, 3, 2, 1, 0] 119
- 1 [3, 4, 2, 1, 0] 118
- 2 [4, 2, 3, 1, 0] 117
- 3 [3, 2, 4, 1, 0] 115
- 4 [2, 4, 3, 1, 0] 116
- 5 [2, 3, 4, 1, 0] 114
- 6 [4, 3, 1, 2, 0] 113
- 7 [3, 4, 1, 2, 0] 112
- 8 [4, 2, 1, 3, 0] 107
- 9 [3, 2, 1, 4, 0] 101
- 10 [2, 4, 1, 3, 0] 106
- 11 [2, 3, 1, 4, 0] 100
- 12 [4, 1, 3, 2, 0] 111
- 13 [3, 1, 4, 2, 0] 109
- 14 [4, 1, 2, 3, 0] 105
- 15 [3, 1, 2, 4, 0] 99
- 16 [2, 1, 4, 3, 0] 103
- 17 [2, 1, 3, 4, 0] 97
- 18 [1, 4, 3, 2, 0] 110
- 19 [1, 3, 4, 2, 0] 108
- 20 [1, 4, 2, 3, 0] 104
- 21 [1, 3, 2, 4, 0] 98
- 22 [1, 2, 4, 3, 0] 102
- 23 [1, 2, 3, 4, 0] 96
- 24 [4, 3, 2, 0, 1] 95
- 25 [3, 4, 2, 0, 1] 94
- 26 [4, 2, 3, 0, 1] 93
- 27 [3, 2, 4, 0, 1] 91
- 28 [2, 4, 3, 0, 1] 92
- 29 [2, 3, 4, 0, 1] 90
- 30 [4, 3, 1, 0, 2] 71
- 31 [3, 4, 1, 0, 2] 70
- 32 [4, 2, 1, 0, 3] 47
- 33 [3, 2, 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 80 [4, 0, 2, 1, 3] 39
- 81 [3, 0, 2, 1, 4] 15
- 82 [2, 0, 4, 1, 3] 37
- 83 [2, 0, 3, 1, 4] 13
- 84 [4, 0, 1, 3, 2] 57
- 85 [3, 0, 1, 4, 2] 51
- 86 [4, 0, 1, 2, 3] 33
- 87 [3, 0, 1, 2, 4] 9
- 88 [2, 0, 1, 4, 3] 27
- 89 [2, 0, 1, 3, 4] 3
- 90 [1, 0, 4, 3, 2] 55
- 91 [1, 0, 3, 4, 2] 49
- 92 [1, 0, 4, 2, 3] 31
- 93 [1, 0, 3, 2, 4] 7
- 94 [1, 0, 2, 4, 3] 25
- 95 [1, 0, 2, 3, 4] 1
- 96 [0, 4, 3, 2, 1] 86
- 97 [0, 3, 4, 2, 1] 84
- 98 [0, 4, 2, 3, 1] 80
- 99 [0, 3, 2, 4, 1] 74
- 100 [0, 2, 4, 3, 1] 78
- 101 [0, 2, 3, 4, 1] 72
- 102 [0, 4, 3, 1, 2] 62
- 103 [0, 3, 4, 1, 2] 60
- 104 [0, 4, 2, 1, 3] 38
- 105 [0, 3, 2, 1, 4] 14
- 106 [0, 2, 4, 1, 3] 36
- 107 [0, 2, 3, 1, 4] 12
- 108 [0, 4, 1, 3, 2] 56
- 109 [0, 3, 1, 4, 2] 50
- 110 [0, 4, 1, 2, 3] 32
- 111 [0, 3, 1, 2, 4] 8
- 112 [0, 2, 1, 4, 3] 26
- 113 [0, 2, 1, 3, 4] 2
- 114 [0, 1, 4, 3, 2] 54
- 115 [0, 1, 3, 4, 2] 48
- 116 [0, 1, 4, 2, 3] 30
- 117 [0, 1, 3, 2, 4] 6
- 118 [0, 1, 2, 4, 3] 24
- 119 [0, 1, 2, 3, 4] 0
- [119, 118, 117, 115, 116, 114, 113, 112, 107, 101, 106, 100, 111, 109, 105, 99, 103, 97, 110, 108, 104, 98, 102, 96, 95, 94, 93, 91, 92, 90, 71, 70, 47, 23, 46, 22, 69, 67, 45, 21, 43, 19, 68, 66, 44, 20, 42, 18, 89, 88, 83, 77, 82, 76, 65, 64, 41, 17, 40, 16, 59, 53, 35, 11, 29, 5, 58, 52, 34, 10, 28, 4, 87, 85, 81, 75, 79, 73, 63, 61, 39, 15, 37, 13, 57, 51, 33, 9, 27, 3, 55, 49, 31, 7, 25, 1, 86, 84, 80, 74, 78, 72, 62, 60, 38, 14, 36, 12, 56, 50, 32, 8, 26, 2, 54, 48, 30, 6, 24, 0]
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement