Factorization over an Algebraic Extension

Factorization over an Algebraic Extension
We start by defining an indeterminate over Q and the polynomial that defines the extension.
We also form the extension, get the root of the polynomial, and define an indeterminate over
the extension (which we call y to distinguish it).
gap> x:=X(Rationals,"x");;f:=x^3+x+1;;
gap> e:=AlgebraicExtension(Rationals,f);
<field in characteristic 0>
gap> theta:=RootOfDefiningPolynomial(e);
gap> y:=X(e,"y");
Next we form the polynomial that we want to factor. We also form a second polynomial
over Q in which we replace θ by an indeterminate.
gap> g:=y^3+(theta^2+theta+1)*y^2+(theta^2-1)*y-theta;
gap> z:=X(Rationals,"z");;
gap> gvar:=x^3+(z^2+z+1)*x^2+(z^2-1)*x-z;
The norm turns out to be squarefree, so we calculate its factors
gap> norm:=Resultant(Value(f,z),gvar,z);
gap> Gcd(norm,Derivative(norm));
gap> fac:=Factors(norm);
[ x^3+x^2+1, x^6-x^4+2*x^3+x^2-x+1 ]
We now transfer the factors into polynomials over the extension, by substituting y for x.
The Gcds with g give the factorization:
gap> facext:=List(fac,i->Value(i,y));
[ y^3+y^2+!1, y^6-y^4+!2*y^3+y^2-y+!1 ]
gap> List(facext,i->Gcd(g,i));
[ y+(1+a^2), y^2+(a)*y+(a^2) ]
The factors thus are x + (θ2 + 1) and (x2 + θx + θ2 ).