ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 22 Jan 2016 11:42:12 +0100Factoring a polynomial over algebraic numbers?https://ask.sagemath.org/question/32308/factoring-a-polynomial-over-algebraic-numbers/ Actually, what I want is to be able to factor a polynomial over the quadratic closure of the rationals, so that I could factor `x^2-3` say, as `(x+sqrt(3)*(x-sqrt(3))`. I don't know enough about factoring algorithms to know whether this is easy or not, but is this at all possible in Sage?
I know I can build an extension field of the rationals by the use of an irreducible quadratic, but that just gives me access to one square root. So if I added `sqrt(3)` then I could factorize the example above, but not `x^2-5`. Is it possible to include all square roots - in other words, can Sage work with the the field of [constructible numbers](https://en.wikipedia.org/wiki/Constructible_number)?Thu, 21 Jan 2016 11:12:09 +0100https://ask.sagemath.org/question/32308/factoring-a-polynomial-over-algebraic-numbers/Answer by B r u n o for <p>Actually, what I want is to be able to factor a polynomial over the quadratic closure of the rationals, so that I could factor <code>x^2-3</code> say, as <code>(x+sqrt(3)*(x-sqrt(3))</code>. I don't know enough about factoring algorithms to know whether this is easy or not, but is this at all possible in Sage?</p>
<p>I know I can build an extension field of the rationals by the use of an irreducible quadratic, but that just gives me access to one square root. So if I added <code>sqrt(3)</code> then I could factorize the example above, but not <code>x^2-5</code>. Is it possible to include all square roots - in other words, can Sage work with the the field of <a href="https://en.wikipedia.org/wiki/Constructible_number">constructible numbers</a>?</p>
https://ask.sagemath.org/question/32308/factoring-a-polynomial-over-algebraic-numbers/?answer=32311#post-id-32311Though it is not exactly what you are looking for, an approach may be to work in the so-called Algebraic Real Field which contains the constructible numbers:
sage: AA
Algebraic Real Field
sage: R.<x> = AA[]
sage: p = x^2-3
sage: p.factor()
(x - 1.732050807568878?) * (x + 1.732050807568878?)
sage: q = x^2-5
sage: q.factor()
(x - 2.236067977499790?) * (x + 2.236067977499790?)
Note that even though the printed values contain a limited number of digits, they are internally exactly represented (the `?` indicates this fact), and you can for instance compute radical expressions for them like this:
sage: f0 = p.factor()[0][0].constant_coefficient()
sage: f0
-1.732050807568878?
sage: f0.radical_expression()
-sqrt(3)
I do not know if it is possible to obtain directly the factorization of `p` with coefficients expressed as a list of radicals, but you can construct such a representation quite easily (by hand).Thu, 21 Jan 2016 15:33:21 +0100https://ask.sagemath.org/question/32308/factoring-a-polynomial-over-algebraic-numbers/?answer=32311#post-id-32311Comment by vdelecroix for <p>Though it is not exactly what you are looking for, an approach may be to work in the so-called Algebraic Real Field which contains the constructible numbers:</p>
<pre><code>sage: AA
Algebraic Real Field
sage: R.<x> = AA[]
sage: p = x^2-3
sage: p.factor()
(x - 1.732050807568878?) * (x + 1.732050807568878?)
sage: q = x^2-5
sage: q.factor()
(x - 2.236067977499790?) * (x + 2.236067977499790?)
</code></pre>
<p>Note that even though the printed values contain a limited number of digits, they are internally exactly represented (the <code>?</code> indicates this fact), and you can for instance compute radical expressions for them like this:</p>
<pre><code>sage: f0 = p.factor()[0][0].constant_coefficient()
sage: f0
-1.732050807568878?
sage: f0.radical_expression()
-sqrt(3)
</code></pre>
<p>I do not know if it is possible to obtain directly the factorization of <code>p</code> with coefficients expressed as a list of radicals, but you can construct such a representation quite easily (by hand).</p>
https://ask.sagemath.org/question/32308/factoring-a-polynomial-over-algebraic-numbers/?comment=32313#post-id-32313As it is explicitely mentioned, the OP wants to work with the set of **constructible** numbers which is much smaller than the set of algebraic numbers.Thu, 21 Jan 2016 20:22:48 +0100https://ask.sagemath.org/question/32308/factoring-a-polynomial-over-algebraic-numbers/?comment=32313#post-id-32313Comment by B r u n o for <p>Though it is not exactly what you are looking for, an approach may be to work in the so-called Algebraic Real Field which contains the constructible numbers:</p>
<pre><code>sage: AA
Algebraic Real Field
sage: R.<x> = AA[]
sage: p = x^2-3
sage: p.factor()
(x - 1.732050807568878?) * (x + 1.732050807568878?)
sage: q = x^2-5
sage: q.factor()
(x - 2.236067977499790?) * (x + 2.236067977499790?)
</code></pre>
<p>Note that even though the printed values contain a limited number of digits, they are internally exactly represented (the <code>?</code> indicates this fact), and you can for instance compute radical expressions for them like this:</p>
<pre><code>sage: f0 = p.factor()[0][0].constant_coefficient()
sage: f0
-1.732050807568878?
sage: f0.radical_expression()
-sqrt(3)
</code></pre>
<p>I do not know if it is possible to obtain directly the factorization of <code>p</code> with coefficients expressed as a list of radicals, but you can construct such a representation quite easily (by hand).</p>
https://ask.sagemath.org/question/32308/factoring-a-polynomial-over-algebraic-numbers/?comment=32315#post-id-32315Right, I edited my answer. Hope it helps the OP anyway ;-)Fri, 22 Jan 2016 11:42:12 +0100https://ask.sagemath.org/question/32308/factoring-a-polynomial-over-algebraic-numbers/?comment=32315#post-id-32315