• 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

Revisión698f6818f630ab65f89ba3649a0e205b4f3432f3 (tree)
Tiempo2020-02-20 13:27:56
AutorEric Hopper <hopper@omni...>
CommiterEric Hopper

Log Message

No more fumbling with the multiplicative inverse in presentations.

Cambiar Resumen

Diferencia incremental

diff -r 3e43d3f153fe -r 698f6818f630 numtheory_utils.py
--- a/numtheory_utils.py Sun Feb 16 01:06:20 2020 -0800
+++ b/numtheory_utils.py Wed Feb 19 20:27:56 2020 -0800
@@ -54,3 +54,15 @@
5454 result = op(a, b)
5555 print(f' {result:{width}} |', end='')
5656 print()
57+
58+
59+def mult_inverses(a, b):
60+ am, bm, g = extended_gcd(a, b)
61+ if g == 0:
62+ raise ValueError(f"{a} and {b} are not relatively prime.")
63+ if am < 0:
64+ am = b + am
65+ if bm < 0:
66+ bm = a + bm
67+ return f"{a} * {am} % {b} == {a * am % b}"\
68+ f"\n{b} * {bm} % {a} == {b * bm % a}"