SetEchoInput(true);
P<x> := PolynomialRing(Integers());
K<a> := NumberField(x^2 + 2);
_<x> := PolynomialRing(K);
KK := NumberField(x^2 + a);
f := x^2 + 3;
assert GaloisGroup(f) eq Sym(2);
assert GaloisGroup(Polynomial(Integers(), f)) eq Sym(2);
f *:= (x^5 + 5);
G := GaloisGroup(f);
assert PermutationGroup<7 |  
    \[ 2, 1, 3, 4, 5, 6, 7 ],
    \[ 1, 2, 5, 6, 4, 3, 7 ],
    \[ 1, 2, 4, 3, 6, 5, 7 ],
    \[ 1, 2, 5, 3, 7, 4, 6 ]
        /* order = 40 = 2^3 * 5 */ >
eq G;
G := GaloisGroup(Polynomial(Integers(), f));
assert IsIsomorphic(PermutationGroup<7 |  
    \[ 2, 1, 3, 4, 5, 6, 7 ],
    \[ 1, 2, 5, 6, 4, 3, 7 ],
    \[ 1, 2, 4, 3, 6, 5, 7 ],
    \[ 1, 2, 5, 3, 7, 4, 6 ]
        /* order = 40 = 2^3 * 5 */ >
, G);
G := GaloisGroup(Polynomial(KK, f));
assert PermutationGroup<7 |  
    \[ 2, 1, 3, 4, 5, 6, 7 ],
    \[ 1, 2, 5, 6, 4, 3, 7 ],
    \[ 1, 2, 4, 3, 6, 5, 7 ],
    \[ 1, 2, 5, 3, 7, 4, 6 ]
        /* order = 40 = 2^3 * 5 */ >
eq G;
f *:= (x^7 + 7);
assert IsIsomorphic(PermutationGroup<14 |  
    \[ 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 6, 3, 5, 7, 4, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 7, 6, 5, 4, 3, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 4, 6, 3, 7, 5, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 12, 11, 9, 10, 13, 8, 14 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 9, 8, 13, 12, 11, 10, 14 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 14, 11, 12, 13, 8, 10, 9 ]
        /* order = 1680 = 2^4 * 3 * 5 * 7 */ >,
GaloisGroup(f));
assert IsIsomorphic(PermutationGroup<14 |  
    \[ 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 6, 3, 5, 7, 4, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 7, 6, 5, 4, 3, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 4, 6, 3, 7, 5, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 12, 11, 9, 10, 13, 8, 14 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 9, 8, 13, 12, 11, 10, 14 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 14, 11, 12, 13, 8, 10, 9 ]
        /* order = 1680 = 2^4 * 3 * 5 * 7 */ >
, GaloisGroup(Polynomial(Integers(), f)));
assert IsIsomorphic(PermutationGroup<14 |  
    \[ 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 6, 3, 5, 7, 4, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 7, 6, 5, 4, 3, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 4, 6, 3, 7, 5, 8, 9, 10, 11, 12, 13, 14 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 12, 11, 9, 10, 13, 8, 14 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 9, 8, 13, 12, 11, 10, 14 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 14, 11, 12, 13, 8, 10, 9 ]
        /* order = 1680 = 2^4 * 3 * 5 * 7 */ >
, GaloisGroup(Polynomial(KK, f)));
f := x^2 + 3;
f *:= x^2 + a;
S := [GaloisGroup(x^2 + 3), GaloisGroup(x^2 + a)];
assert IsIsomorphic(GaloisGroup(f), DirectProduct(S));
assert IsIsomorphic(GaloisGroup(x^2 + 3), GaloisGroup(Polynomial(KK, f)));
K<a> := NumberField(x^3 + 2);
_<x> := PolynomialRing(K);
KK := ext<K | x^2 + x + a>;
f := x^4 + 1;
f *:= Evaluate(f, Polynomial(K, [1, 1]));
G := GaloisGroup(f);
assert IsIsomorphic(G, GaloisGroup(Polynomial(K, x^4 + 1)));
assert MyIsConjugateSubgroup(Sym(Degree(G)),
                        GaloisGroup(Polynomial(Integers(), f)), G);
			assert IsIsomorphic(G, GaloisGroup(Polynomial(KK, f)));
_<x> := PolynomialRing(Integers());
K<a> := NumberField(x^2 + 2);
_<y> := PolynomialRing(K);
f := (y^3 + 2)*(y^2 + 3)*(y^5 + 4);
assert PermutationGroup<10 |  
\[ 1, 2, 3, 4, 5, 7, 6, 10, 9, 8 ],
\[ 1, 2, 3, 4, 5, 6, 9, 10, 8, 7 ],
\[ 2, 1, 4, 3, 5, 6, 7, 8, 9, 10 ],
\[ 2, 1, 3, 5, 4, 6, 7, 8, 9, 10 ]
/* order = 120 = 2^3 * 3 * 5 */ >
eq GaloisGroup(f);
assert IsIsomorphic(PermutationGroup<10 |  
\[ 1, 2, 3, 4, 5, 7, 6, 10, 9, 8 ],
\[ 1, 2, 3, 4, 5, 6, 9, 10, 8, 7 ],
\[ 2, 1, 4, 3, 5, 6, 7, 8, 9, 10 ],
\[ 2, 1, 3, 5, 4, 6, 7, 8, 9, 10 ]
/* order = 120 = 2^3 * 3 * 5 */ >
, GaloisGroup(Polynomial(Integers(), f)));

KK, R, G := GaloisSplittingField((y^3 + 2)*(y^2 + 3)*(y^5 + 4));
assert &and[Evaluate((y^3 + 2)*(y^2 + 3)*(y^5 + 4), r) eq 0: r in R];
assert #G eq AbsoluteDegree(KK)/AbsoluteDegree(K);
assert &and[Degree(f[1]) eq 1 : f in Factorization((y^3 + 2)*(y^2 + 3)*(y^5 + 4), KK)];

if false then 
f *:= (x^11 + 11);
assert PermutationGroup<25 |  
    \[ 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 5, 3, 7, 6, 4, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 7, 5, 4, 6, 3, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 6, 3, 4, 7, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 12, 8, 11, 14, 9, 13, 10, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 10, 14, 8, 12, 11, 13, 9, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 13, 14, 11, 9, 8, 10, 12, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 24, 18, 19, 20, 25, 17, 
    23, 16, 15, 22, 21 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 17, 19, 23, 15, 16, 
    25, 22, 24, 21, 18 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 24, 21, 15, 
    19, 16, 17, 18, 25 ]
        /* order = 184800 = 2^5 * 3 * 5^2 * 7 * 11 */ >
eq GaloisGroup(f);
assert IsIsomorphic(PermutationGroup<25 |  
    \[ 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 5, 3, 7, 6, 4, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 7, 5, 4, 6, 3, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 6, 3, 4, 7, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 12, 8, 11, 14, 9, 13, 10, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 10, 14, 8, 12, 11, 13, 9, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 13, 14, 11, 9, 8, 10, 12, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 24, 18, 19, 20, 25, 17, 
    23, 16, 15, 22, 21 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 17, 19, 23, 15, 16, 
    25, 22, 24, 21, 18 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 24, 21, 15, 
    19, 16, 17, 18, 25 ]
        /* order = 184800 = 2^5 * 3 * 5^2 * 7 * 11 */ >
, GaloisGroup(Polynomial(Integers(), f)));
assert IsIsomorphic(PermutationGroup<25 |  
    \[ 2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 5, 3, 7, 6, 4, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 7, 5, 4, 6, 3, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 6, 3, 4, 7, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 12, 8, 11, 14, 9, 13, 10, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 10, 14, 8, 12, 11, 13, 9, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 13, 14, 11, 9, 8, 10, 12, 15, 16, 17, 18, 19, 20, 
    21, 22, 23, 24, 25 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 24, 18, 19, 20, 25, 17, 
    23, 16, 15, 22, 21 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 17, 19, 23, 15, 16, 
    25, 22, 24, 21, 18 ],
    \[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 24, 21, 15, 
    19, 16, 17, 18, 25 ]
        /* order = 184800 = 2^5 * 3 * 5^2 * 7 * 11 */ >
, GaloisGroup(Polynomial(KK, f)));
end if;
