Skip to content

Instantly share code, notes, and snippets.

@jaymzcd
Created January 24, 2012 23:43
Show Gist options
  • Select an option

  • Save jaymzcd/1673542 to your computer and use it in GitHub Desktop.

Select an option

Save jaymzcd/1673542 to your computer and use it in GitHub Desktop.
use sage & pylab to plot a finite field's multiplication table for given f_size prime
#!/usr/bin/env sage
import pickle
from math import *
from pylab import *
"""
See: http://goo.gl/y2A78 for information
and how this was put together/concepted
"""
f_size = 127 # this *has* to be prime
G = GF(f_size) # generate finite field
N = G.order() # need order for size (or f_size - 1)
lst = list(enumerate(G))
vals = np.empty((N, N), dtype=int)
# This can probably be some fancy numpy func
for (i,a) in lst:
for (j,b) in lst:
k = a*b
vals[i, j] = k
# Careful, interpol. of "None" ends up as default, you want the string
# 'none' instead to actually *not* interpolate between elements
# note that the version of pylab shipped with sage (using py2.6) doesn't
# actually have this, so you might want to serialize the array and
# fire up (recent) pylab yourself (hence the repr)
with open('farray.obj', 'wb') as f:
pickle.dump(vals, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment