• R/O
  • SSH

Commit

Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonwindowsphpgamebathyscapheguic翻訳omegattwitterframeworkbtronvb.net計画中(planning stage)testdomarduinodirectxpreviewerゲームエンジン

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


Commit MetaInfo

Revision9fe5a2f278f632dcec7f3fa0d848ddfe12ff1cb9 (tree)
Time2017-06-17 02:37:41
AuthorEric Hopper <hopper@omni...>
CommiterEric Hopper

Log Message

Remove possibility of division imprecision.

If coefficients were floats the way things were being done before might
result in some very strange answers.

Change Summary

Incremental Difference

diff -r a6fa33805b0a -r 9fe5a2f278f6 polyops.py
--- a/polyops.py Fri Jun 16 10:12:59 2017 -0700
+++ b/polyops.py Fri Jun 16 10:37:41 2017 -0700
@@ -189,11 +189,12 @@
189189 else:
190190 return (next(iter(points))[1],)
191191 xzero = type(next(iter(points))[0])()
192- master_poly = reduce(polymul,
193- ((xzero - x, 1) for x, y in points),
194- (xone,))
195- xpolys = ((polydiv(master_poly, (xzero - x, xone))[0], x, y)
196- for x, y in points)
197- xpolys = (polyscalarmul(xp, y / evalpoly(xp, x))
198- for xp, x, y in xpolys)
192+
193+ def compute_xpoly(x, y):
194+ xpoly = reduce(polymul, ((xzero - px, xone)
195+ for px, py in enumerate(points)
196+ if px != x))
197+ return polyscalarmul(xpoly, y / evalpoly(xpoly, x))
198+
199+ xpolys = (compute_xpoly(x, y) for x, y in points)
199200 return normalized(reduce(polyadd, xpolys, ()))