nf=nfinit(y^2+1);
rnfidealmul(rnfinit(nf,x^4-x-1),2,3)
rnfidealmul(rnfinit(nf,[x^4-x-1,10^3]),2,3)
rnfidealup(rnfinit(nf,x),[;])
nf=nfinit(quadpoly(1129,y));ord=rnfpseudobasis(nf,quadray(1129,1));rnfsteinitz(nf,ord)
rnflllgram(nf,x^3+2,rnfpseudobasis(nf,x^3+2))
nf=nfinit(y^2-y-4);T=x^11-11*x^10+31*x^9-26*x^8+36*x^7+7*x^6+15*x^5-27*x^4+26*x^3+20*x^2-33*x+42;
rnfpseudobasis(nf,T)
rnfpseudobasis(nf,[T,10^3])
T = x^2+1009^3*(10^6+3)^2*y;
rnfpseudobasis(nf,T)
rnfpseudobasis(nf,[T,100])
rnfpseudobasis(nf,[T,1010])
rnfdisc(nf,T)
rnfdisc(nf,[T,100])
rnfdisc(nf,[T,1010])
Q = bnfinit(y); T=x^4+x^3-71*x^2+72*x+5184;
rnfconductor(Q,T)
rnfconductor(Q,[T,10^3])
rnfconductor(Q,galoissubcyclo(117,116))[1]
K=bnfinit(quadpoly(1596,y),1); rnfbasis(K,rnfsteinitz(K,rnfpseudobasis(K,quadray(K,1))));

K = nfinit(x^2-x+2); M = [1, 0, x; 0, x, 0; 0,0,2+x]; N = [1, 1, 1];
nfsnf(K, [M, N, N])
rnfisabelian(y,x)
rnfisabelian(y^2+23,x^3+x^2-1)
T = polcyclo(7, x+Mod(y, nf.pol));
rnfisabelian(nf.pol, T)
rnfisabelian(nf, T)
rnfisabelian(a^2+1,5*x^3+2)
rnfisabelian(4*a^2+1, 9*x^2 + (12*a+3)*x + 2*a)
rnfisabelian(y^4+2,polsubcyclo(13,6))

pol = y^3+y^2-2*y-1;
bnf = bnfinit(pol);
T=rnfisnorminit(bnf, x^3-y);
do(T,u,flag=0)=liftpol(rnfisnorm(T,u,flag));
do(T,y)
[a,b]=rnfisnorm(T,2,100);
liftpol(norm(a)*b)
[a,b]=rnfisnorm(T,2,-2*3*5*7);
liftpol(norm(a)*b)

T=rnfisnorminit(y^2+23, x^2-y);
do(T,y)
do(T,2,100)

\\#1157
rnfisnorminit(y,x^2-Mod(2+y,y));

\\#1778
K = bnfinit(x^4-2*x^3-27*x^2+28*x+53);
t = varhigher("t");
L = rnfisnorminit(K,t^2-310*x^3+465*x^2+11005*x-274660);
[a,b]=rnfisnorm(L,-28124/93*x^3+14062/31*x^2+562480/93*x+166769/31);
liftpol(norm(a)*b)

\\#1255
K = nfinit(z^3+z^2-2*z-1); rnf = rnfinit(K, x^2+Mod(-z,z^3+z^2-2*z-1)*x+1);
a = rnfeltup(rnf,z^2)
rnfeltdown(rnf, a)

setrand(1);a=matrix(3,4,j,k,vectorv(3,l,random(21)));
idx=idealprimedec(K,3)[1];
aid=[idx,1,1,1];
[A,U]=nfhnf(K,[a,aid],1);
A
U
lift(matbasistoalg(K,a)*matbasistoalg(K,U))

a=a[,1..3];
[A,U,V]=nfsnf(K,[a, aid[1..3], [1,1,1]],1);
A
U
V
lift(matbasistoalg(K,U)*matbasistoalg(K,a)*matbasistoalg(K,V))

nf=nfinit(y); A = [[1,1/2;0,1],[1,1]];
nfhnfmod(nf, A, nfdetint(nf,A))

K=bnfinit(y^2-40);
bnfisnorm(K,2, 0)
bnfisnorm(K,6, 0)

K=bnfinit(y^3-21);
bnfisnorm(K,2)
bnfisnorm(K,6)
L=rnfinit(K,x^2-y);

v = [2,1/2,x+y,Mod(1,K.pol),Mod(1/2,K.pol),Mod(y,K.pol),Mod(1,L.polabs),Mod(1/2,L.polabs),Mod(x,L.polabs),Mod(x+y/2,L.pol),y,z,Mod(y+1/2,y^2+1),[1]~,[1,2]~,[1,y]~,[1,I]~, y+I,x^2];
f=[rnfalgtobasis,rnfbasistoalg,rnfeltabstorel,rnfeltreltoabs,rnfeltup,rnfeltdown,rnfelttrace,rnfeltnorm];

test(L,v) =
{
  for (i=1,#v,
    for (j=1,#f, print([i,j], ": ", iferr(f[j](L,v[i]), E,E)))
  );
  my (K = L.nf);
  for (i=1,#v,
    print(i, ": ", iferr(rnfcharpoly(K,x^2-y,v[i]),E,E))
  );
}
test(L,v);
KQ = nfinit(y+1);
LQ = rnfinit(KQ, x^2-y);
vQ = [2,1/2,x+y, Mod(1/2,KQ.pol), y, Mod(Mod(x/2+1,KQ.pol),LQ.pol), Mod(x,LQ.pol), Mod(x,LQ.polabs), Mod(x+y/2,x^2-y), x, [1]~,[1,2]~,[y]~];
test(LQ, vQ);

nf = nfinit(y);
rnf = rnfinit(nf,x^2-2);
rel = Mod(Mod(1,y)+0*y,x^2-2);
a = rnfeltreltoabs(rnf,rel)
variable(lift(a))

Labs = nfinit(L);
idL = idealhnf(Labs, x^3+x^2+10);
idK = idealhnf(K, y^2+10*y+5);
id = rnfidealabstorel(L,Labs.zk*idL)
rnfidealnormabs(L,id) == idealnorm(Labs, idL)
m = rnfidealreltoabs(L, id)
mathnf(matalgtobasis(Labs,m)) == idL

P3 = idealprimedec(K,3);
\\ pr[5] depends on 32/64-bit arch
strip5(pr)=pr[1..4];
apply(strip5, rnfidealprimedec(L, P3[1]))
my(v=rnfidealprimedec(L,7)); [apply(strip5, v[1]), apply(strip5, v[2][1])]

rnffa(rnf,id)=my(fa=rnfidealfactor(rnf,id)); fa[,1] = apply(strip5,fa[,1]); fa;
rnffa(L,7)
rnffa(L,x)
rnffa(L,y)
rnfidealfactor(L,id) == rnfidealfactor(L,idL)

m = rnfidealup(L, idK)
mabs = rnfidealup(L, idK, 1);
mathnf( Mat(apply(x->nfalgtobasis(Labs,x), m)) ) == mabs
rnfidealdown(L, m) == idK
rnfidealdown(L, mabs) == idK
m = rnfidealdown(L, Labs.zk*idL)
M=rnfidealup(L, m)
mathnf(matalgtobasis(Labs,M)) == rnfidealup(L, m, 1)
\\
V=concat(v, [[;], [], 0, [[;],[]], idealprimedec(K,2)[1], idK, idL, Labs.zk*idL, id]);
f=[rnfidealhnf,rnfidealreltoabs,rnfidealabstorel,rnfidealdown,rnfidealup,rnfidealnormrel,rnfidealnormabs,rnfidealtwoelt];
{
for (i=1,#V,
  print(i,":");
  for (j=1, #f,
    print(iferr(f[j](L,V[i]),E,E))
  )
)
}
rnfidealmul(L, 0,1)
rnfidealmul(L, 1,0)
rnfidealmul(L, x,y)
rnfidealmul(L, y,x)
rnfidealmul(L, id,x)
rnfidealmul(L, x,id)
rnfdet(K,[[;],[]])
rnfdet(K,id)
rnfbasis(bnfinit(y^2-1105),x^2-y)
\\#1508
K=nfinit(y); L=rnfinit(K,x^3-2); rnfeltdown(L,Mod(Mod(1,K.pol),L.polabs))

k1=bnfinit(y^3+y^2-2*y-1);
u=x^3+y*x^2+(y-2)*x+(y^2-y-1);
rnfconductor(k1,u)

K = nfinit(y^2+y+1);
rnfislocalcyclo(rnfinit(K, x^3-2))
rnfislocalcyclo(rnfinit(K, x))
rnfislocalcyclo(rnfinit(K, x^3 - y))
rnfislocalcyclo(rnfinit(K, x^3 - y + 3^6))

nf=nfinit(y^2+9); \\ 3 divides index
P=idealprimedec(nf,3)[1];
rnfdedekind(nf, (x+y/3)^3+3*y, P)

nf = nfinit(y^2-3); P = x^3 - 2*y;
pr3 = idealprimedec(nf,3)[1];
pr2 = idealprimedec(nf,2)[1];

rnfdedekind(nf, P, pr2)
rnfdedekind(nf, P, pr3)
rnfdedekind(nf, P, pr2, 1)
rnfdedekind(nf, P, pr3, 1)
rnfdedekind(nf, P)
rnfdedekind(nf, P, [pr2,pr3])

P = (y+1)*x^4 + x^2 + x + 2;
rnfdedekind(nf, P, pr3, 1)

t = 't; T = polcyclo(9,t);
pol = y^2 + Mod(t^5+t^2+t-1, T)*y + Mod(1-t, T);
Qchi=nfinit([T,10^6]);
rnfinit(Qchi,[pol,10^6]); \\ segv in 2.11

\\ Errors, keep at end of file
rnfdedekind(nf, P, pr2, 1)
rnfdedekind(nf, P)
rnfdedekind(nf, P, [pr2,pr3])

rnfislocalcyclo(rnfinit(K, x^6-y+1))
\\#1530
L=rnfinit(nfinit(y^2-3),x^2+23);
rnfidealtwoelt(L, [[1;0], [1/104]])

\\#2093
nf = nfinit(y);
rnf = rnfinit(nf,x^2+5);
rnfidealup(rnf,Mat(3),1);

