WFactorTex:= function (n) if n eq 1 then return 1; end if; n:=Factorization(n); s:=""; for i in [1..#n] do s:=s*IntegerToString(n[i][1]); if n[i][2] gt 1 then s:=s*"^{"*IntegerToString(n[i][2])*"}"; end if; if i lt #n then s:=s*"\\cdot"; end if; end for; return s; end function; Pri:=function(n) if IsPrime(n) eq true then return IntegerToString(n); end if; return IntegerToString(n)*" = "*WFactorTex(n); end function; ListToTex:=function(s: selected := [], factors := []) a:=Open(s,"r"); b:=Open(Substring(s,1,#s-3)*"tex.res","w"); s:=Gets(a); t:=#StringToIntegerSequence(s); if #selected eq 0 then selected := [1..t]; end if; inf:=selected[1]; Remove(~selected,1); while IsEof(s) ne true do s:=StringToIntegerSequence(s); t:= inf in factors select Pri(s[inf]) else s[inf]; for i in selected do t*:= " & "; t*:= i in factors select Pri(s[i]) else IntegerToString(s[i]); end for; t*:="\\\\\n"; fprintf b, t; s:=Gets(a); end while; delete(a); delete(b); return true; end function; PrintMatrixFile:=function(s,A) b:=Open(s,"w"); for i in [1..#A] do for j in [1..#A[i]] do fprintf b,"%o ",A[i][j]; end for; fprintf b,"\n"; Flush(b); end for; delete b; return(true); end function; OpenAndRead:=function(s) a:=Open(s,"r"); s:=Gets(a); A:=[]; while IsEof(s) ne true do Append(~A,StringToIntegerSequence(s)); s:=Gets(a); end while; delete(a); return(A); end function; Ordena:=function(s,n:invers:=false, sortida) if Type(s) eq MonStgElt then A:=OpenAndRead(s); elif Type(s) eq SeqEnum then A:=s; else return false; end if; for i in [1..#A] do Insert(~A[i],1,0,[A[i][n]]); Remove(~A[i],n+1); end for; Sort(~A); for i in [1..#A] do Insert(~A[i],n+1,n,[A[i][1]]); Remove(~A[i],1); end for; if invers then for i in [1..Floor(#A/2)] do aux:=A[i]; A[i]:=A[#A-i+1]; A[#A-i+1]:=aux; end for; end if; if Type(sortida) eq MonStgElt then return(PrintMatrixFile(sortida,A)); elif Type(sortida) eq SeqEnum then return A; else return(PrintMatrixFile(Substring(s,1,#s-3)*"ord.res",A)); end if; return(false); end function; OrderByBiggestExponent:=function(s:invers:=false) A:=OpenAndRead(s); B:=[]; for i in [1..#A] do f:=Factorization(A[i][8]); m:=0; for j in [1..#f] do if f[j][2] gt m then m:=f[j][2]; end if; end for; p:=1; for j in [1..#f] do if f[j][2] eq m then p:=f[j][1]*p; end if; end for; Append(~B, [A[i][1],A[i][2],A[i][3],A[i][4],A[i][8], p, m]); end for; aux:=Ordena(B,7:invers:=invers, sortida:= Substring(s,1,#s-3)*"max.ord.res"); return(aux); end function; pPart:=function(N,p) while Integers()!N mod p eq 0 do N:=N/p; end while; return Integers()!N; end function; ProbablyIrred:= function(N,i,l); A:=Open("prob-red-primes.res","r"); s:=Gets(A); while not IsEof(s) do s:=StringToIntegerSequence(s); if s[1] eq N and s[2] eq i then p:=Factorization(s[3]); for i in p do l:=pPart(l,i[1]); end for; return l; end if; s:=Gets(A); end while; return false; end function; NotRamified:= function(N,i,l); A:=Open("ramif-primes.res","r"); s:=Gets(A); while not IsEof(s) do s:=StringToIntegerSequence(s); if s[1] eq N and s[2] eq i then p:=Factorization(s[3]); for i in p do l:=pPart(l,i[1]); end for; return l; end if; s:=Gets(A); end while; return false; end function; IsMinimal:=function(N, i, l) a:=Open("1-2000.txt","r"); s:=Gets(a); while IsEof(s) ne true do s:=StringToIntegerSequence(s); if s[1] gt N then delete(a); return true; end if; if s[1] eq N and s[2] eq i and s[1] ne s[3] and s[5] mod l eq 0 then delete(a); return false; end if; s:=Gets(a); end while; delete(a); return true; end function;