omnifarious

# GaloisField

• R/O
• SSH

## Commit

##### Tags

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

### Commit MetaInfo

Revision 9fe5a2f278f632dcec7f3fa0d848ddfe12ff1cb9 (tree) 2017-06-17 02:37:41 Eric Hopper Eric 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.

### 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 @@ 189 189 else: 190 190 return (next(iter(points))[1],) 191 191 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) 199 200 return normalized(reduce(polyadd, xpolys, ()))