\\ Centered vector for cyclic indices. t_center (v) = {my (n=#v,d=n\2); vector(n,i,v[(i+d)%n+1])} \\ Fourier transform on a cyclic group. t_ft (v,realpart=0) = {my (n,m,Omstar); n=#v; w=exp(2*Pi*I/n); Omstar=matrix(n,n,j,k,w^(-(j-1)*(k-1))); t=(v*Omstar)/n; if (!realpart,t,apply(real,t))} t_ftabs (v,center=1) = {my (w); w=t_ft(v); if (center, w=t_center(w)); apply(abs,w)} t_ftarg (v,center=1) = {my (w); w=t_ft(v); if (center, w=t_center(w)); apply(arg,w)} \\ Perhaps obsolete. t_ftstrabs (v,d=2,center=1) = {my (w); w=t_ft(v); if (center, w=t_center(w)); \\apply(abs,w)} apply(x->Strprintf("%.*f",d,abs(x)),w)} \\ Perhaps obsolete. t_ftstrarg (v,d=2,center=1) = {my (w); w=t_ft(v); if (center, w=t_center(w)); apply(x->Strprintf("%.*f",d,arg(x)),w)} \\Inverse Fourier transform on a cyclic group. t_fti (v,realpart=0) = {my (n,m,Om); n=#v; w=exp(2*Pi*I/n); Om=matrix(n,n,j,k,w^((j-1)*(k-1))); t=v*Om; if (!realpart,t,apply(real,t))} \\ Walsh transform. t_ftw (f) = {my (fW); fW=t_ftwi(f); vector(#f,i,fW[i]/#f)} \\ Inverse Walsh transform. t_ftwi (f) = {my (n,j,falfa,fbeta,p,q,u,v); n=#f; if (n==1, return(f)); j=n\2; falfa=vecextract(f,[1..j]); fbeta=vecextract(f,[j+1..n]); p=self()(falfa); q=self()(fbeta); u=vector(j,i,p[i]+q[i]); v=vector(j,i,p[i]-q[i]); concat(u,v)} \\ Perhaps inconsistencies. t_ftwrite (F,X,name,G=F) = {my (u,v); u=apply(G,X); v=apply(F,X); t_writeplotpairs(Strprintf("%s.fun",name),u); \\ t_writeplotpairs(Strprintf("%s.abs",name),t_ftstrabs(v)); \\ t_writeplotpairs(Strprintf("%s.arg",name),t_ftstrarg(v)); } t_ftwritev (v,name,u=v,m=200,fase=0) = {m=min(m,#v); u=u[1..m]; v=v[1..m]; t_writeplotpairs(Strprintf("%s.fun",name),u); t_writeplotpairs(Strprintf("%s.abs",name),t_ftstrabs(v)); if (fase, t_writeplotpairs(Strprintf("%s.arg",name),t_ftstrarg(v)))}