R<y> := PolynomialRing(RationalField());
f := y^5 - 5*y^3 + 4*y -1;
print "f has discriminant", Discriminant(f);

RR := PolynomialRing(RealField());
roots := [r[1] : r in Roots(RR!f)];
print "roots = ", roots;

K<a> := NumberField(f);   // a is image of y in K.
A := MaximalOrder(K);  
"h_A = ", ClassNumber(A);
function EmbeddingSigns(z)
   h := RR!Eltseq(K!z);
   return [Sign(Evaluate(h, roots[i])) : i in [1..#roots]];
end function;

d := (a^4 -4*a^2 + 1)/(5*a^4 - 15*a^2 + 4);
dprime := d/(a+2);

print "\nEmbeddingSigns(d) =", EmbeddingSigns(d);
print "EmbeddingSigns(dprime) =", EmbeddingSigns(dprime);

print "\nNorm(d) =",Norm(d);
print "Norm(dprime) =",Norm(dprime);
print "Norm(1/f'(y)) =", Norm(1/Evaluate(Derivative(f),a));

B_d := MatrixAlgebra(Integers(),5)!
             [Trace(d*A.r*A.c) : r in [1..5], c in [1..5]];

B_dprime := MatrixAlgebra(Integers(),5)!
             [Trace(dprime*A.r*A.c) : r in [1..5], c in [1..5]];

print "\nB_d =", B_d;
print "B_dprime =", B_dprime;
print "\nDeterminant(B_d) =", Determinant(B_d);
print "Determinant(B_dprime) =", Determinant(B_dprime);

L_d := LatticeWithGram(B_d);
L_dprime := LatticeWithGram(B_dprime);

short_d := [v[1] : v in ShortVectors(L_d,1)];
short_dprime := [v[1] : v in ShortVectors(L_dprime,1)];

print "\nThe length 1 vectors for L_d up to sign, are:", short_d;
print "\nThe length 1 vectors for L_dprime up to sign, are:", short_dprime;

print "\nThe inner-product matrix of the short vectors with respect";
print "to the first form <m,m'> = Tr(dmm') is:";

C := MatrixAlgebra(Rationals(),5)!
          [InnerProduct(short_d[r], L_d!Eltseq(short_dprime[c])) : 
                          r in [1..5], c in [1..5]];

print "Short product matrix:", C;
print "which has determinant", Determinant(C);

