jell(x)=if(#x,x.j,[]);
{
test(p,f) = setrand(1); a = ffgen([p,f], 'a); [
a^2+3*a+1,
a/(1+a),
2*(a+1)/3,
1/5+a,
if (6*a, 5/6/(a+1)),
if (6*a, 5/6*(a+1)),
shiftmul(a+1,10),
if (2*a, shiftmul(a+1,-10)),
a^-1,
-a,
sqr(a),
sqrt(a^(2^10)),
sqrtn((a^2+a+1)^3,3),
sqrtn((a^2+a+1)^3,3,&z),
z,
if (ispower(a,3), a^(2/3)),
norm(a^2+1),
trace(a),
charpoly(a),
minpoly(a),
conjvec(a),
factor(x^6-a*x^3+1),
jell(ellinit([a,1])),
a/x,
(x+a)/(x-a),
b=ffprimroot(a),
fforder(a),
b^fflog(a,b),
factorff(x^2+x+a),
polrootsff(x^2+x+a)
];
}
default(echo,1);

test(2, 20)
test(7, 7)
test(precprime(2^32), 3)
test(nextprime(2^32), 3)

ffgen(ffinit(2^32-5,101),'a)^10000
ffgen(ffinit(2^64-59,101),'a)^10000

for(i=1,10,print(ffnbirred(11,i)));
for(i=1,10,print(ffnbirred(11,i,1)));

do(f,p,T)=centerlift(lift(polrootsff(f,p,T)));
do(x^3+x^2+x-1,3,t^3+t^2+t-1)
t = ffgen(3^3,'t); do((x^3+x^2+x-1)*t^0, t.p, t.mod)
polrootsff(x^4+1,2,y^2+y+1)

t = ffgen(2^64)^((2^64-1)\5);1/t

t = ffgen(('t^2+'t+1)*Mod(1,2));
factorff(x^12 + t*x^10 + x^6 + (t+1)*x^2 + 1)

\\ #1241
polrootsff(x^2 - x - ffgen((v^2+1) * Mod(1,3)))
\\ #1350
polrootsff(2*x+1,2,y)
sqrt(Mod(-1,4296540161))
sqrt(Mod(-1,18446744073944432641))
centerlift(factorcantor(prod(i=-10,10,(x^2-i)),2^64+13)[,1])
#polrootsff(x^107+2*x^3+1,3,ffinit(3,107,'a))
ffgen(x^2+x+Mod(1,3))
conjvec(Mod(x, x^2+Mod(1,3)))
t = ffgen(5^4,'t);
factor((x^24-1)*t^0)
factorff(Pol(0),t.p,t.mod)
factorff(Pol(1),t.p,t.mod)
factorff(x^4-t,t.p,t.mod)

test(q)=
{
  my(t = ffgen(q,'t), m=[t,t^2,1+t^3; 1+t,1+t^2,1+t^3]);
  print(matker(m));
  print(matimage(m));
  print(matrank(m));
  my(M = [t,2*t^0,3*t^0; t,t^2,1+t^3; 1+t,1+t^2,1+t^3]);
  print(matdet(M));
  print(M^(-1)*M);
  my(v = [t^0, t^1, t^2]~);
  print(M*v);
}
test(2^5)
test(7^5)
test((2^64+13)^5)

test(q)={
  my(t = ffgen(q, 't), M = matrix(10, 10, i, j, random(t)));
  subst(charpoly(M), 'x, M) == 0;
}
test(nextprime(2^7)^5)
test(nextprime(2^15)^5)
test(nextprime(2^31)^5)
test(nextprime(2^63)^5)
