A small kernel of code for playing with Galois fields of arbitrary characteristic
リビジョン | 3e43d3f153fea219b8401accdcf5277d39eacf2e (tree) |
---|---|
日時 | 2020-02-16 18:06:20 |
作者 | Eric Hopper <hopper@omni...> |
コミッター | Eric Hopper |
Add a function to print out a group table for presentation.
@@ -40,3 +40,17 @@ | ||
40 | 40 | # (1 * 16 - 0 * 23) - 2 * (1 * 23 - 1 * 16) = 3 * 16 - 2 * 23 = 2 |
41 | 41 | # (1 * 23 - 1 * 16) - 3 * (3 * 16 - 2 * 23) = 7 * 23 - 10 * 16 = 1 |
42 | 42 | # 13 * 16 - 9 * 23 = 1 |
43 | + | |
44 | + | |
45 | +def print_group_table(elements, op): | |
46 | + width = max(len(str(x)) for x in elements) | |
47 | + print(f'{" ":{width}} |', end='') | |
48 | + for a in elements: | |
49 | + print(f' {a:{width}} |', end='') | |
50 | + print() | |
51 | + for a in elements: | |
52 | + print(f'{a:{width}} |', end='') | |
53 | + for b in elements: | |
54 | + result = op(a, b) | |
55 | + print(f' {result:{width}} |', end='') | |
56 | + print() |