
procedure check_autos(L)
    try
	G, Aut, h := AutomorphismGroup(L);                                
    catch e
	G, Aut, h := AutomorphismGroup(L : Partial);
    end try;

    autos := [];
    for i in [0 .. Ngens(G)] do
	Append(~autos, h(G.i));
    end for;
    assert autos[1](L.1) eq L.1;
    assert (autos[1]*autos[1])(L.1) eq L.1;

    for a in autos do
	assert a(L.1^2) eq a(L.1)*a(L.1);
	assert a(2*L.1) eq 2*a(L.1);
	assert a(1) eq 1;
	assert a(L.1 + 1) eq a(L.1) + a(1);

	assert Evaluate(DefiningPolynomial(L), a(L.1)) eq 0;
    end for;

    for a1 in autos do
	for a2 in autos do
	    assert (a1*a2)(L.1) eq a2(a1(L.1));
	end for;
    end for;

    for i in [0 .. Ngens(G)] do
	for j in [0 .. Ngens(G)] do
	    assert h(G.i*G.j) eq h(G.i)*h(G.j);
	end for;
    end for;
end procedure;

P<x> := PolynomialRing(Integers());
f:= x^21 - 17661*x^19 + 133676109*x^17 - 566271801592*x^15 +
1302811602*x^14 + 1470724454105340*x^13 - 15339303801948*x^12 -
    2411914568510052333*x^11 + 70951949735910474*x^10 +
2479180185920721570287*x^9 - 162737971985183750820*x^8 -
    1531753764094466310898677*x^7 + 191607688215355348215468*x^6 +
519814902460568249482660902*x^5 -
    107428043859409231899472392*x^4 - 80273332028881385623594264711*x^3
+ 22586746221440791006864070418*x^2 +
    3400366308229299981300979482204*x - 7672371389998131343252651220296;
L := NumberField(f);
check_autos(L);

for i in [1 .. 30] do
    i;
    f := Polynomial(Integers(), RandomIrreduciblePolynomial(GF(NextPrime(100*i)), 4));
    G, r, S := GaloisGroup(f);
    f := GaloisSubgroup(S, sub<G | G.0>);
    L := NumberField(f);
    check_autos(L);
end for;
