• R/O
  • SSH

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A small kernel of code for playing with Galois fields of arbitrary characteristic


Commit MetaInfo

Revisionef5953b8a8d2c99936acfe856c1c020121ced8d2 (tree)
Time2019-08-01 14:34:22
AuthorEric Hopper <hopper@omni...>
CommiterEric Hopper

Log Message

Preparing for a rpesentation on group theory.

Change Summary

Incremental Difference

diff -r e00c7a17d072 -r ef5953b8a8d2 numtheory_utils.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/numtheory_utils.py Wed Jul 31 22:34:22 2019 -0700
@@ -0,0 +1,42 @@
1+def extended_gcd(x, y):
2+ sx = 1 if x > 0 else -1
3+ x = abs(x)
4+ sy = 1 if y > 0 else -1
5+ y = abs(y)
6+ pa, pb = 1, 0
7+ a, b = 0, -1
8+ done = False
9+ while True:
10+ m = (pa * x - pb * y) // (a * x - b * y)
11+ na = pa - m * a
12+ nb = pb - m * b
13+ pa, a = a, na
14+ pb, b = b, nb
15+ if (a * x - b * y) in (0, 1):
16+ if (a < 0) and (b < 0):
17+ if x < y:
18+ return (y + a, -x - b, (a * x - b * y))
19+ else:
20+ return (a, -b, (a * x - b * y))
21+ else:
22+ if x < y:
23+ return (a, -b, (a * x - b * y))
24+ else:
25+ return (a - y, x - b, (a * x - b * y))
26+
27+# This is basically the kind of calculation that the above function is trying
28+# to replicate.
29+#
30+# 1 * 23 - 0 * 15 = 23
31+# 1 * 15 - 0 * 23 = 15
32+# (1 * 23 - 0 * 15) - (1 * 15 - 0 * 23) = 1 * 23 - 1 * 15 = 8
33+# (1 * 15 - 0 * 23) - (1 * 23 - 1 * 15) = 2 * 15 - 1 * 23 = 7
34+# (1 * 23 - 1 * 15) - (2 * 15 - 1 * 23) = 2 * 23 - 3 * 15 = 1
35+# 20 * 15 - 13 * 23 = 1
36+
37+# 1 * 23 - 0 * 16 = 23
38+# 1 * 16 - 0 * 23 = 16
39+# (1 * 23 - 0 * 16) - (1 * 16 - 0 * 23) = 1 * 23 - 1 * 16 = 7
40+# (1 * 16 - 0 * 23) - 2 * (1 * 23 - 1 * 16) = 3 * 16 - 2 * 23 = 2
41+# (1 * 23 - 1 * 16) - 3 * (3 * 16 - 2 * 23) = 7 * 23 - 10 * 16 = 1
42+# 13 * 16 - 9 * 23 = 1