エレファント・ビジュアライザー調査記録

ビジュアルプログラミングで数式の変形を表すことを考えていくブロクです。

人工知能的代数学(2)

置換の分類

Visual Studio でデザイナーが開けなくなったので、C# を使うのをやめて、Google Colab というのを使ってみました。これは Python を使うことになります。これにはプログラムを書いてくれる機能があって、「 n を指定して、 n 次の対称群のすべての元を偶置換と奇置換に分類するプログラムを書いてください」と入力すると、正しい結果が得られました。これは「置換のパリティー」などで書いたことで、普通の数学の本に書かれているものです。

Visual StudioPython を使えるようにしていたことがわかったので、こっちでやってみることにしました。これはデザイナーを使わないので大丈夫です。ChatGPT で同様のことをやってみると、こちらも正しい結果が得られました。こちらの方を書いてみます。以下のようなプログラムが得られました。

from itertools import permutations

def is_even_permutation(perm):
    """Check if a permutation is even."""
    inversions = 0
    for i in range(len(perm)):
        for j in range(i+1, len(perm)):
            if perm[i] > perm[j]:
                inversions += 1
    return inversions % 2 == 0

def symmetric_group_elements(n):
    """Generate all elements of the symmetric group of degree n."""
    if n == 1:
        return [[1]]
    else:
        perms = []
        for perm in symmetric_group_elements(n-1):
            for i in range(n):
                new_perm = perm[:i] + [n] + perm[i:]
                perms.append(new_perm)
        return perms

def classify_permutations(n):
    """Classify permutations into even and odd permutations."""
    symmetric_perms = symmetric_group_elements(n)
    even_perms = []
    odd_perms = []
    for perm in symmetric_perms:
        if is_even_permutation(perm):
            even_perms.append(perm)
        else:
            odd_perms.append(perm)
    return even_perms, odd_perms

n = int(input("Enter the value of n: "))
even_perms, odd_perms = classify_permutations(n)
print(f"Even permutations: {even_perms}")
print(f"Odd permutations: {odd_perms}")
結果( n = 3)

Even permutations: [[2, 3, 1], [3, 1, 2], [1, 2, 3]]
Odd permutations: [[3, 2, 1], [2, 1, 3], [1, 3, 2]]

結果( n = 4)

Even permutations: [[4, 3, 2, 1], [3, 2, 4, 1], [2, 4, 3, 1], [2, 3, 1, 4], [4, 2, 1, 3], [2, 1, 4, 3], [3, 4, 1, 2], [3, 1, 2, 4], [4, 1, 3, 2], [1, 3, 4, 2], [1, 4, 2, 3], [1, 2, 3, 4]]
Odd permutations: [[3, 4, 2, 1], [3, 2, 1, 4], [4, 2, 3, 1], [2, 3, 4, 1], [2, 4, 1, 3], [2, 1, 3, 4], [4, 3, 1, 2], [3, 1, 4, 2], [1, 4, 3, 2], [1, 3, 2, 4], [4, 1, 2, 3], [1, 2, 4, 3]]

結果( n = 5)

Even permutations: [[5, 4, 3, 2, 1], [4, 3, 5, 2, 1], [4, 3, 2, 1, 5], [3, 5, 4, 2, 1], [3, 4, 2, 5, 1], [5, 3, 2, 4, 1], [3, 2, 5, 4, 1], [3, 2, 4, 1, 5], [3, 5, 2, 1, 4], [3, 2, 1, 5, 4], [4, 5, 2, 3, 1], [4, 2, 3, 5, 1], [5, 2, 4, 3, 1], [2, 4, 5, 3, 1], [2, 4, 3, 1, 5], [2, 5, 3, 4, 1], [2, 3, 4, 5, 1], [5, 2, 3, 1, 4], [2, 3, 5, 1, 4], [2, 3, 1, 4, 5], [5, 4, 2, 1, 3], [4, 2, 5, 1, 3], [4, 2, 1, 3, 5], [2, 5, 4, 1, 3], [2, 4, 1, 5, 3], [5, 2, 1, 4, 3], [2, 1, 5, 4, 3], [2, 1, 4, 3, 5], [2, 5, 1, 3, 4], [2, 1, 3, 5, 4], [4, 5, 3, 1, 2], [4, 3, 1, 5, 2], [5, 3, 4, 1, 2], [3, 4, 5, 1, 2], [3, 4, 1, 2, 5], [3, 5, 1, 4, 2], [3, 1, 4, 5, 2], [5, 3, 1, 2, 4], [3, 1, 5, 2, 4], [3, 1, 2, 4, 5], [5, 4, 1, 3, 2], [4, 1, 5, 3, 2], [4, 1, 3, 2, 5], [1, 5, 4, 3, 2], [1, 4, 3, 5, 2], [5, 1, 3, 4, 2], [1, 3, 5, 4, 2], [1, 3, 4, 2, 5], [1, 5, 3, 2, 4], [1, 3, 2, 5, 4], [4, 5, 1, 2, 3], [4, 1, 2, 5, 3], [5, 1, 4, 2, 3], [1, 4, 5, 2, 3], [1, 4, 2, 3, 5], [1, 5, 2, 4, 3], [1, 2, 4, 5, 3], [5, 1, 2, 3, 4], [1, 2, 5, 3, 4], [1, 2, 3, 4, 5]]
Odd permutations: [[4, 5, 3, 2, 1], [4, 3, 2, 5, 1], [5, 3, 4, 2, 1], [3, 4, 5, 2, 1], [3, 4, 2, 1, 5], [3, 5, 2, 4, 1], [3, 2, 4, 5, 1], [5, 3, 2, 1, 4], [3, 2, 5, 1, 4], [3, 2, 1, 4, 5], [5, 4, 2, 3, 1], [4, 2, 5, 3, 1], [4, 2, 3, 1, 5], [2, 5, 4, 3, 1], [2, 4, 3, 5, 1], [5, 2, 3, 4, 1], [2, 3, 5, 4, 1], [2, 3, 4, 1, 5], [2, 5, 3, 1, 4], [2, 3, 1, 5, 4], [4, 5, 2, 1, 3], [4, 2, 1, 5, 3], [5, 2, 4, 1, 3], [2, 4, 5, 1, 3], [2, 4, 1, 3, 5], [2, 5, 1, 4, 3], [2, 1, 4, 5, 3], [5, 2, 1, 3, 4], [2, 1, 5, 3, 4], [2, 1, 3, 4, 5], [5, 4, 3, 1, 2], [4, 3, 5, 1, 2], [4, 3, 1, 2, 5], [3, 5, 4, 1, 2], [3, 4, 1, 5, 2], [5, 3, 1, 4, 2], [3, 1, 5, 4, 2], [3, 1, 4, 2, 5], [3, 5, 1, 2, 4], [3, 1, 2, 5, 4], [4, 5, 1, 3, 2], [4, 1, 3, 5, 2], [5, 1, 4, 3, 2], [1, 4, 5, 3, 2], [1, 4, 3, 2, 5], [1, 5, 3, 4, 2], [1, 3, 4, 5, 2], [5, 1, 3, 2, 4], [1, 3, 5, 2, 4], [1, 3, 2, 4, 5], [5, 4, 1, 2, 3], [4, 1, 5, 2, 3], [4, 1, 2, 3, 5], [1, 5, 4, 2, 3], [1, 4, 2, 5, 3], [5, 1, 2, 4, 3], [1, 2, 5, 4, 3], [1, 2, 4, 3, 5], [1, 5, 2, 3, 4], [1, 2, 3, 5, 4]]

対称群の導来部分群

次に「 n を指定して、 n 次の対称群の 1 次導来部分群と 2 次導来部分群が一致するかどうかを調べるプログラムを書いてください」ということをやってみました。これは計算すればできるのですが、普通の数学の本に簡単な証明が書かれていることもあります。これは ChatGPT でも Google Colab でも正しいプログラムはできなかったのですが、ChatGPT で間違っているところや追加したいところを質問して、得られたプログラムを組み合わせて、間違っているところを直すと動くようになりました。導来部分群は交換子全体で生成される部分群なのですが、このプログラムでは交換子全体を調べているだけなので、一致する場合はこれで良い(生成元が一致するだけで良い)のですが、一致しない場合は本来は部分群であることを確かめる必要があります(ここでやったものは部分群になっています)。これについての説明をwikipediaから引用して後に付け加えておきます。

プログラムと結果は以下のようになります。

from itertools import permutations

def symmetric_group(n):
    return list(permutations(range(1, n + 1)))

def commutator_permutations(perm1, perm2):
    # 逆元を計算
    inv_perm1 = inverse_permutation(perm1)
    inv_perm2 = inverse_permutation(perm2)
    
    # 交換子を計算
    comm = multiply_permutations(inv_perm1, multiply_permutations(inv_perm2, multiply_permutations(perm1, perm2)))
    return comm

# 置換の積を計算する関数
def multiply_permutations(perm1, perm2):
    product = [0] * len(perm1)
    for i in range(len(perm1)):
        product[i] = perm1[perm2[i] - 1]
    return product

# 置換の逆元を計算する関数
def inverse_permutation(perm):
    inverse = [0] * len(perm)
    for i in range(len(perm)):
        inverse[perm[i] - 1] = i + 1
    return inverse

def commutator(a, b):
    return commutator_permutations(a, b)

def derived_subgroup(group):
    derived = set()
    for a in group:
        for b in group:
            comm = commutator(a, b)
            derived.add(tuple(comm))
    return derived

def print_subgroup(subgroup, title):
    print(title)
    if not subgroup:
        print("Empty")
    else:
        print(subgroup)

def is_derived_equal(n):
    sym_group = symmetric_group(n)
    derived_1 = derived_subgroup(sym_group)
    derived_2 = derived_subgroup(derived_1)
    
    print_subgroup(sym_group, "Symmetric Group:")
    print_subgroup(derived_1, "1st Derived Subgroup:")
    print_subgroup(derived_2, "2nd Derived Subgroup:")

    return derived_1 == derived_2

n = int(input("Enter the value of n: "))
if is_derived_equal(n):
    print("1st and 2nd derived subgroups are equal.")
else:
    print("1st and 2nd derived subgroups are not equal.")
結果( n = 3)

Enter the value of n: Symmetric Group:
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
1st Derived Subgroup:
{(2, 3, 1), (1, 2, 3), (3, 1, 2)}
2nd Derived Subgroup:
{(1, 2, 3)}
1st and 2nd derived subgroups are not equal.

結果( n = 4)

Enter the value of n: Symmetric Group:
[(1, 2, 3, 4), (1, 2, 4, 3), (1, 3, 2, 4), (1, 3, 4, 2), (1, 4, 2, 3), (1, 4, 3, 2), (2, 1, 3, 4), (2, 1, 4, 3), (2, 3, 1, 4), (2, 3, 4, 1), (2, 4, 1, 3), (2, 4, 3, 1), (3, 1, 2, 4), (3, 1, 4, 2), (3, 2, 1, 4), (3, 2, 4, 1), (3, 4, 1, 2), (3, 4, 2, 1), (4, 1, 2, 3), (4, 1, 3, 2), (4, 2, 1, 3), (4, 2, 3, 1), (4, 3, 1, 2), (4, 3, 2, 1)]
1st Derived Subgroup:
{(1, 4, 2, 3), (4, 2, 1, 3), (1, 3, 4, 2), (2, 3, 1, 4), (1, 2, 3, 4), (3, 1, 2, 4), (3, 2, 4, 1), (2, 1, 4, 3), (2, 4, 3, 1), (4, 3, 2, 1), (4, 1, 3, 2), (3, 4, 1, 2)}
2nd Derived Subgroup:
{(1, 2, 3, 4), (2, 1, 4, 3), (4, 3, 2, 1), (3, 4, 1, 2)}
1st and 2nd derived subgroups are not equal.

結果( n = 5)

Enter the value of n: Symmetric Group:
[(1, 2, 3, 4, 5), (1, 2, 3, 5, 4), (1, 2, 4, 3, 5), (1, 2, 4, 5, 3), (1, 2, 5, 3, 4), (1, 2, 5, 4, 3), (1, 3, 2, 4, 5), (1, 3, 2, 5, 4), (1, 3, 4, 2, 5), (1, 3, 4, 5, 2), (1, 3, 5, 2, 4), (1, 3, 5, 4, 2), (1, 4, 2, 3, 5), (1, 4, 2, 5, 3), (1, 4, 3, 2, 5), (1, 4, 3, 5, 2), (1, 4, 5, 2, 3), (1, 4, 5, 3, 2), (1, 5, 2, 3, 4), (1, 5, 2, 4, 3), (1, 5, 3, 2, 4), (1, 5, 3, 4, 2), (1, 5, 4, 2, 3), (1, 5, 4, 3, 2), (2, 1, 3, 4, 5), (2, 1, 3, 5, 4), (2, 1, 4, 3, 5), (2, 1, 4, 5, 3), (2, 1, 5, 3, 4), (2, 1, 5, 4, 3), (2, 3, 1, 4, 5), (2, 3, 1, 5, 4), (2, 3, 4, 1, 5), (2, 3, 4, 5, 1), (2, 3, 5, 1, 4), (2, 3, 5, 4, 1), (2, 4, 1, 3, 5), (2, 4, 1, 5, 3), (2, 4, 3, 1, 5), (2, 4, 3, 5, 1), (2, 4, 5, 1, 3), (2, 4, 5, 3, 1), (2, 5, 1, 3, 4), (2, 5, 1, 4, 3), (2, 5, 3, 1, 4), (2, 5, 3, 4, 1), (2, 5, 4, 1, 3), (2, 5, 4, 3, 1), (3, 1, 2, 4, 5), (3, 1, 2, 5, 4), (3, 1, 4, 2, 5), (3, 1, 4, 5, 2), (3, 1, 5, 2, 4), (3, 1, 5, 4, 2), (3, 2, 1, 4, 5), (3, 2, 1, 5, 4), (3, 2, 4, 1, 5), (3, 2, 4, 5, 1), (3, 2, 5, 1, 4), (3, 2, 5, 4, 1), (3, 4, 1, 2, 5), (3, 4, 1, 5, 2), (3, 4, 2, 1, 5), (3, 4, 2, 5, 1), (3, 4, 5, 1, 2), (3, 4, 5, 2, 1), (3, 5, 1, 2, 4), (3, 5, 1, 4, 2), (3, 5, 2, 1, 4), (3, 5, 2, 4, 1), (3, 5, 4, 1, 2), (3, 5, 4, 2, 1), (4, 1, 2, 3, 5), (4, 1, 2, 5, 3), (4, 1, 3, 2, 5), (4, 1, 3, 5, 2), (4, 1, 5, 2, 3), (4, 1, 5, 3, 2), (4, 2, 1, 3, 5), (4, 2, 1, 5, 3), (4, 2, 3, 1, 5), (4, 2, 3, 5, 1), (4, 2, 5, 1, 3), (4, 2, 5, 3, 1), (4, 3, 1, 2, 5), (4, 3, 1, 5, 2), (4, 3, 2, 1, 5), (4, 3, 2, 5, 1), (4, 3, 5, 1, 2), (4, 3, 5, 2, 1), (4, 5, 1, 2, 3), (4, 5, 1, 3, 2), (4, 5, 2, 1, 3), (4, 5, 2, 3, 1), (4, 5, 3, 1, 2), (4, 5, 3, 2, 1), (5, 1, 2, 3, 4), (5, 1, 2, 4, 3), (5, 1, 3, 2, 4), (5, 1, 3, 4, 2), (5, 1, 4, 2, 3), (5, 1, 4, 3, 2), (5, 2, 1, 3, 4), (5, 2, 1, 4, 3), (5, 2, 3, 1, 4), (5, 2, 3, 4, 1), (5, 2, 4, 1, 3), (5, 2, 4, 3, 1), (5, 3, 1, 2, 4), (5, 3, 1, 4, 2), (5, 3, 2, 1, 4), (5, 3, 2, 4, 1), (5, 3, 4, 1, 2), (5, 3, 4, 2, 1), (5, 4, 1, 2, 3), (5, 4, 1, 3, 2), (5, 4, 2, 1, 3), (5, 4, 2, 3, 1), (5, 4, 3, 1, 2), (5, 4, 3, 2, 1)]
1st Derived Subgroup:
{(5, 4, 1, 3, 2), (3, 1, 4, 5, 2), (1, 4, 3, 5, 2), (4, 3, 1, 5, 2), (5, 1, 2, 3, 4), (2, 3, 4, 5, 1), (2, 3, 1, 4, 5), (2, 5, 3, 4, 1), (5, 3, 1, 2, 4), (3, 4, 1, 2, 5), (2, 1, 4, 3, 5), (5, 3, 2, 4, 1), (1, 5, 3, 2, 4), (3, 5, 2, 1, 4), (5, 4, 2, 1, 3), (4, 3, 5, 2, 1), (5, 4, 3, 2, 1), (4, 2, 5, 1, 3), (2, 5, 1, 3, 4), (5, 1, 3, 4, 2), (3, 5, 1, 4, 2), (2, 4, 3, 1, 5), (3, 5, 4, 2, 1), (4, 1, 5, 3, 2), (4, 1, 2, 5, 3), (3, 1, 5, 2, 4), (1, 2, 3, 4, 5), (2, 3, 5, 1, 4), (4, 2, 3, 5, 1), (1, 3, 5, 4, 2), (2, 5, 4, 1, 3), (4, 5, 1, 2, 3), (5, 1, 4, 2, 3), (2, 1, 3, 5, 4), (5, 2, 1, 4, 3), (5, 2, 4, 3, 1), (2, 4, 1, 5, 3), (3, 4, 2, 5, 1), (3, 2, 4, 1, 5), (4, 5, 2, 3, 1), (1, 3, 2, 5, 4), (4, 3, 2, 1, 5), (3, 2, 5, 4, 1), (1, 2, 4, 5, 3), (1, 3, 4, 2, 5), (3, 4, 5, 1, 2), (4, 1, 3, 2, 5), (5, 2, 3, 1, 4), (4, 5, 3, 1, 2), (3, 1, 2, 4, 5), (2, 4, 5, 3, 1), (3, 2, 1, 5, 4), (1, 5, 4, 3, 2), (1, 4, 2, 3, 5), (1, 4, 5, 2, 3), (4, 2, 1, 3, 5), (1, 5, 2, 4, 3), (2, 1, 5, 4, 3), (1, 2, 5, 3, 4), (5, 3, 4, 1, 2)}
2nd Derived Subgroup:
{(5, 4, 1, 3, 2), (3, 1, 4, 5, 2), (1, 4, 3, 5, 2), (4, 3, 1, 5, 2), (5, 1, 2, 3, 4), (2, 3, 1, 4, 5), (5, 3, 1, 2, 4), (2, 5, 3, 4, 1), (2, 3, 4, 5, 1), (3, 4, 1, 2, 5), (2, 1, 4, 3, 5), (5, 3, 2, 4, 1), (1, 5, 3, 2, 4), (3, 5, 2, 1, 4), (5, 4, 2, 1, 3), (4, 3, 5, 2, 1), (5, 4, 3, 2, 1), (4, 2, 5, 1, 3), (2, 5, 1, 3, 4), (5, 1, 3, 4, 2), (3, 5, 1, 4, 2), (2, 4, 3, 1, 5), (3, 5, 4, 2, 1), (4, 1, 5, 3, 2), (4, 1, 2, 5, 3), (3, 1, 5, 2, 4), (1, 2, 3, 4, 5), (2, 3, 5, 1, 4), (4, 2, 3, 5, 1), (1, 3, 5, 4, 2), (4, 5, 1, 2, 3), (2, 5, 4, 1, 3), (5, 1, 4, 2, 3), (2, 1, 3, 5, 4), (5, 2, 1, 4, 3), (5, 2, 4, 3, 1), (2, 4, 1, 5, 3), (3, 4, 2, 5, 1), (3, 2, 4, 1, 5), (4, 5, 2, 3, 1), (1, 3, 2, 5, 4), (4, 3, 2, 1, 5), (3, 2, 5, 4, 1), (1, 2, 4, 5, 3), (1, 3, 4, 2, 5), (3, 4, 5, 1, 2), (4, 1, 3, 2, 5), (5, 2, 3, 1, 4), (4, 5, 3, 1, 2), (3, 1, 2, 4, 5), (2, 4, 5, 3, 1), (1, 5, 4, 3, 2), (1, 5, 2, 4, 3), (1, 4, 5, 2, 3), (2, 1, 5, 4, 3), (4, 2, 1, 3, 5), (1, 4, 2, 3, 5), (3, 2, 1, 5, 4), (1, 2, 5, 3, 4), (5, 3, 4, 1, 2)}
1st and 2nd derived subgroups are equal.

交換子

wikipedia:交換子 から必要な部分を引用します。

 G の二つの元  x, y の交換子を  [x, y] = x^{-1}y^{-1}xy と定義します。 x^y = y^{-1}xy と定義します。
 x^{y}=x[x,y]
 [y,x]=[x,y]^{-1}
 [xy,z]=[x,z]^{y}[y,z]
 [x,yz]=[x,z][x,y]^{z}
 [x,y^{-1}]=[y,x]^{y^{-1}}
 [x^{-1},y]=[y,x]^{x^{-1}}
 [[x,y^{-1}],z]^{y}[[y,z^{-1}],x]^{z}[[z,x^{-1}],y]^{x}=1
 [[x,y],z^{x}][[z,x],y^{z}][[y,z],x^{y}]=1
が成り立ちます。

交換子部分群

wikipedia:交換子部分群 から必要な部分を引用します。

 G の交換子全体が生成する部分群
 [G,G]={\big \langle }\left\{\,[x,y]\mid x,y\in G\,\right\}{\big \rangle }
 G の交換子部分群または導来部分群と呼びます。交換子部分群は
 G', \ G^{(1)}, \ \gamma_{2}(G), \ D(G)
と表すこともあります。

交換子の逆元も交換子なので、交換子部分群  [G, G] の任意の元は有限個の交換子の積
 [x_{1},y_{1}][x_{2},y_{2}]\cdots [x_{n},y_{n}]
の形に書くことができます。

 [x, y]^z = [x^z, y^z] であることから
 \displaystyle ([x_{1},y_{1}]\cdots [x_{n},y_{n}])^{z}=[x_{1}^{z},y_{1}^{z}]\cdots [x_{n}^{z},y_{n}^{z}]
が成り立ち、交換子部分群は  G正規部分群になります。

導来群を作る操作を繰り返して
 G^{(0)}:=G
 G^{(n)}:=[G^{(n-1)},G^{(n-1)}] \ (n \in \mathbb{N})
と定義します。このとき部分群  G^{(n)} n 次導来部分群、降正規列
 G=G^{(0)} \triangleright G^{(1)} \triangleright G^{(2)} \triangleright \cdots
を導来列と呼びます。