Section 8.2 Powers
ΒΆxxxxxxxxxx
layout=[['p','a']]) (
def _(p=(7,prime_range(50)),a=(3,[0..50])):
b=mod(a,p)
top=ceil(2*p/10)*10
pretty_print(html("If we look at some of the powers of $%s$"%(a,)))
pretty_print(html("modulo the prime $%s$, we get:"%(p,)))
pretty_print(html("<ul>"))
for m in [0..top]:
pretty_print(html(r"<li>$%s^{%s}\equiv %s\text{ (mod }%s)$</li>"%(a,m,b^m,p)))
pretty_print(html("</ul>"))
Subsection 8.2.1 Returning to visualizing
ΒΆStill, this is a lot of data to assimilate. Is there some way to think about it differently? This next interact is super-cool, because it combines the short, color-coded format with the much less familiar material of powers.
xxxxxxxxxx
import matplotlib.pyplot as plt
from matplotlib.ticker import IndexLocator, FuncFormatter
def power_table_plot(p=(11,prime_range(100))):
mycmap = plt.get_cmap('gist_earth',p-1)
myloc = IndexLocator(floor(p/5),.5)
myform = FuncFormatter(lambda x,y: int(x+1))
cbaropts = { 'ticks':myloc, 'drawedges':True, 'boundaries':srange(.5,p+.5,1)}
P=matrix_plot(matrix(p-1,[mod(a,p)^b for a in range(1,p) for b in srange(p)]), cmap=mycmap,colorbar=True, colorbar_options=cbaropts, ticks=[myloc,myloc], tick_formatter=[None,myform])
show(P,figsize=6)
Sage note 8.2.2. Colorful options.
If you don't like the colors, you can change the word in the quotes in the command mycmap = plt.get_cmap(...)
(currently 'gist_earth'
); for instance, 'gray'
gives a grayscale plot, which is most appropriate for certain vision-impaired users. Some others you could try are 'Oranges'
or 'hsv'
or β¦ Well, see the next Sage cell if you really want to know all of them!
xxxxxxxxxx
for c in colormaps:
print(c)