# Extension field adjoining two roots in Sage

This is a question related to this one. I'm working with sage and I'm trying to construct the following situation (perhaps some of you have done it beofre):

I'm trying to construct given an irreducible polynomial $f \in \mathbb{Q}[X]$ an extension field that adjoins two of its roots $\alpha_1,\alpha_2$. I'm trying to follow the approach suggested in this question . However, with the following code:

P.<x> = QQ[]
f = x^4+2*x+5 # f = P([5,2,0,1]) if you want
f_roots = f.roots(QQbar, multiplicities=False)
print f_roots
alpha = f_roots[0]
beta = f_roots[1]
K = QQ[alpha,beta]
K['x'](f).is_irreducible()


But this gives the error:

ValueError: defining polynomial (x^4 + 2*x + 5) must be irreducible


Although, the polynomial is clearly irreducible over $\mathbb{Q}$. Doing it as:

P.<x> = QQ[]
f = x^3+2*x+5
f_roots = f.roots(QQbar, multiplicities=False)
alpha = f_roots[0]
K.<a> = QQ[alpha]
beta = f_roots[1]
K1.<b> = K[beta]


Gives error:

ValueError: base field and extension cannot have the same name 'a'


What is going wrong? Is this the right way to construct the extension field with two roots?

One could define successive extensions, but the nicest might be to define individual extensions separately and to construct a composite field from those.

Define P, f, alpha, beta as in the question.

sage: P.<x> = QQ[]
sage: f = P([5, 2, 0, 0, 1])
sage: f_roots = f.roots(QQbar, multiplicities=False)
sage: f_roots
[-1.068757255260645? - 0.8212240798160035?*I,
-1.068757255260645? + 0.8212240798160035?*I,
1.068757255260645? - 1.268887367765514?*I,
1.068757255260645? + 1.268887367765514?*I]
sage: alpha, beta = f_roots[:2]
sage: alpha, beta
(-1.068757255260645? - 0.8212240798160035?*I,
-1.068757255260645? + 0.8212240798160035?*I)


Define the number fields $\mathbb{Q}[\alpha]$, $\mathbb{Q}[\beta]$ as embedded number fields, with embeddings in QQbar.

sage: K.<a> = NumberField(f, 'a', embedding=alpha)
sage: L.<b> = NumberField(f, 'b', embedding=beta)


Now the list of composite fields will contain the only compatible embedded number field. (Had K and L been constructed without embeddings, there would be several possible composite fields).

sage: K.composite_fields(L, 'c', both_maps=True)
[(Number Field in c with defining polynomial
x^12 - 54*x^9 + 335*x^8 + 1900*x^6 - 17820*x^5 - 12725*x^4
- 17928*x^3 + 421660*x^2 - 2103750*x + 6284221,
Ring morphism:
From: Number Field in a with defining polynomial x^4 + 2*x + 5
To:   Number Field in c with defining polynomial
x^12 - 54*x^9 + 335*x^8 + 1900*x^6 - 17820*x^5 - 12725*x^4
- 17928*x^3 + 421660*x^2 - 2103750*x + 6284221
Defn: a |--> -4787089492308500/19095694682980435222089*c^11
- 60072370481993649/50921852487947827258904*c^10
- 107347330062640525/25460926243973913629452*c^9
+ 54770246058614250/6365231560993478407363*c^8
- 830196451346905669/19095694682980435222089*c^7
- 6929297573110815045/25460926243973913629452*c^6
- 80217555206153510375/38191389365960870444178*c^5
+ 32869508519243998767/25460926243973913629452*c^4
+ 218621879478829109530/19095694682980435222089*c^3
+ 3195870754505273678775/50921852487947827258904*c^2
- 33579832334379607364857/76382778731921740888356*c
+ 315450855301503993255/1106996793216257114324,
Ring morphism:
From: Number Field in b with defining polynomial x^4 + 2*x + 5
To:   Number Field in c with defining polynomial
x^12 - 54*x^9 + 335*x^8 + 1900*x^6 - 17820*x^5 - 12725*x^4
- 17928*x^3 + 421660*x^2 - 2103750*x + 6284221
Defn: b |--> -9574178984617000/19095694682980435222089*c^11
- 60072370481993649/25460926243973913629452*c^10
- 107347330062640525/12730463121986956814726*c^9
+ 109540492117228500/6365231560993478407363*c^8
- 1660392902693811338/19095694682980435222089*c^7
- 6929297573110815045/12730463121986956814726*c^6
- 80217555206153510375/19095694682980435222089*c^5
+ 32869508519243998767/12730463121986956814726*c^4
+ 437243758957658219060/19095694682980435222089*c^3
+ 3195870754505273678775/25460926243973913629452*c^2
+ 4611557031581263079321/38191389365960870444178*c
+ 315450855301503993255/553498396608128557162,
-2)]


Extract this composite field.

sage: M.<c>, phi_KM, phi_LM, k = K.composite_fields(L, 'c', both_maps=True)[0]
sage: M
Number Field in c with defining polynomial
x^12 - 54*x^9 + 335*x^8 + 1900*x^6 - 17820*x^5 - 12725*x^4
- 17928*x^3 + 421660*x^2 - 2103750*x + 6284221
sage: M(a)
-4787089492308500/19095694682980435222089*c^11
- 60072370481993649/50921852487947827258904*c^10
- 107347330062640525/25460926243973913629452*c^9
+ 54770246058614250/6365231560993478407363*c^8
- 830196451346905669/19095694682980435222089*c^7
- 6929297573110815045/25460926243973913629452*c^6
- 80217555206153510375/38191389365960870444178*c^5
+ 32869508519243998767/25460926243973913629452*c^4
+ 218621879478829109530/19095694682980435222089*c^3
+ 3195870754505273678775/50921852487947827258904*c^2
- 33579832334379607364857/76382778731921740888356*c
+ 315450855301503993255/1106996793216257114324
sage: M(b)
-9574178984617000/19095694682980435222089*c^11
- 60072370481993649/25460926243973913629452*c^10
- 107347330062640525/12730463121986956814726*c^9
+ 109540492117228500/6365231560993478407363*c^8
- 1660392902693811338/19095694682980435222089*c^7
- 6929297573110815045/12730463121986956814726*c^6
- 80217555206153510375/19095694682980435222089*c^5
+ 32869508519243998767/12730463121986956814726*c^4
+ 437243758957658219060/19095694682980435222089*c^3
+ 3195870754505273678775/25460926243973913629452*c^2
+ 4611557031581263079321/38191389365960870444178*c
+ 315450855301503993255/553498396608128557162


Do some computations.

sage: QQbar(M(a)*M(b))
1.81665105994191? + 0.?e-14*I
sage: alpha*beta
1.81665105994191? + 0.?e-14*I
sage: QQbar(M(a)*M(b)) == alpha*beta
True
sage: QQbar(M(a) + M(b))
-2.137514510521290? + 0.?e-15*I
sage: alpha + beta
-2.137514510521290? + 0.?e-15*I
sage: QQbar(M(a) + M(b)) == alpha + beta
True