Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168740
Image: ubuntu2004
def show_values_GF(q,f): # shows the number of times the trace of the polynomial f over F_q takes each possible value k.<a>=GF(q) vars=f.variables() n=len(vars) R=PolynomialRing(k,vars) f=R(f) p=k.characteristic() V=zero_matrix(2,p) for z in range(p): V[0,z]=z for s in k^n: if n>1: t=f(s.list()).trace() else: t=f(s[0]).trace() V[1,t]+=1 return V def plot_values_GF(q,f): # plots the number of times the trace of the polynomial f over F_q takes each possible value k.<a>=GF(q) vars=f.variables() n=len(vars) p=k.characteristic() V=show_values_GF(q,f) P=circle((0,0),1,aspect_ratio=1,axes=false) media=0 zeta=exp(2*pi*I/p).n() for z in range(p): if V[1,z]>0: P+=point(((zeta^z).real_part(),(zeta^z).imag_part()),color="blue",pointsize=20) P+=text(V[1,z],(1.1*(zeta^z).real_part(),1.1*(zeta^z).imag_part())) media+=V[1,z]*zeta^z P+=arrow((0,0),(media.real_part()/q^n,media.imag_part()/q^n),color="red") P+=text(media.n(digits=3).abs()/q^n,(0.9,0.9),color="brown") return P
def consecutive_squares(p,pattern=[1,1]): P=circle((0,0),1,aspect_ratio=1,axes=false) zeta=exp(2*pi*I/p).n() v=[0 for i in range(p)] N=0 for z in range(p): v[z^2 % p]=1 for z in range(p): if v[z]: P+=point(((zeta^z).real_part(),(zeta^z).imag_part()),color="blue",pointsize=20) else: P+=point(((zeta^z).real_part(),(zeta^z).imag_part()),color="red",pointsize=20) for z in range(p): if prod(ZZ(v[(z+j) % p]==pattern[j]) for j in range(len(pattern))): N=N+1 P+=arrow(((1.1)*(zeta^z).real_part(),(1.1)*(zeta^z).imag_part()),((zeta^z).real_part(),(zeta^z).imag_part())) T=sum(v[i] for i in range(p)) P+=text(str(N)+"/"+str(p),(0.9,0.9),color="brown") return P