Extension field adjoining two roots
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^3+2*x+5 # f = P([5,2,0,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^3 + 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?
Edit
Let me emphasize that I'm looking for a method that works for an arbitrary degree not just for degree 3. My actual problem goes on a degree four polynomial. So take as an example:
f = x^4+2*x+5
instead of the previous one.
May I suggest leaving the original example, and adding the new example in the "Edit" part?
Note: also asked as math StackExchange question #2586636: Extension field adjoining two roots in Sage.