Spaces:
Paused
Paused
| import numpy as np | |
| import itertools | |
| def signed_perm_mats_det_plus_1(): | |
| """生成所有 3x3 的 ±1 置换矩阵,且 det=+1(24 个)""" | |
| mats = [] | |
| for perm in itertools.permutations(range(3)): # 6 种列置换 | |
| P = np.zeros((3,3), int) | |
| for r, c in enumerate(perm): | |
| P[r, c] = 1 | |
| for signs in itertools.product([1, -1], repeat=3): # 行符号 | |
| R = P * np.array(signs)[:, None] # 每行乘 ±1 | |
| if int(round(np.linalg.det(R))) == 1: | |
| mats.append(R) | |
| # 去重(以 tuple 做 key) | |
| uniq = {} | |
| for R in mats: | |
| key = tuple(R.reshape(-1)) | |
| uniq[key] = R | |
| return list(uniq.values()) | |
| def check_transformation_invariance(): | |
| """严格验证变换后的矩阵仍在群中""" | |
| R24 = signed_perm_mats_det_plus_1() # 使用您的可靠生成器 | |
| R_z180 = np.array([[-1, 0, 0], | |
| [0, -1, 0], | |
| [0, 0, 1]], dtype=int) # 确保整数类型 | |
| failed_cases = [] | |
| for i, R in enumerate(R24): | |
| transformed = R_z180 @ R | |
| # 精确匹配(因所有矩阵均为整数) | |
| found = any(np.array_equal(transformed, M) for M in R24) | |
| if not found: | |
| failed_cases.append((i, R, transformed)) | |
| if not failed_cases: | |
| print("✅ 所有24个矩阵经过变换后仍在集合中") | |
| return True | |
| else: | |
| print(f"❌ 发现{len(failed_cases)}个不符合的案例:") | |
| for idx, orig, trans in failed_cases: | |
| print(f"\n案例 {idx}:") | |
| print("原矩阵(行列式={}):\n{}".format(int(np.linalg.det(orig)), orig)) | |
| print("变换后(行列式={}):\n{}".format(int(np.linalg.det(transformed)), trans)) | |
| return False | |
| # 执行验证 | |
| check_transformation_invariance() |