ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 08 Mar 2019 11:02:18 -0600Factor a solve outputhttp://ask.sagemath.org/question/45716/factor-a-solve-output/ I am new to sage. So, sorry if my question is too trivial.
I can not factor the output of "solve". For instance, this very simple example
x= var('x')
sols=solve(x==6, x)
factor(sols[0].right())
gives me
6
Why I am not getting the following?
2 * 3
which of course is the output of
factor(6).
PS: I guess that the "type" is a crucial thing here, but anyways I'd need to factor 'sage.symbolic.expression.Expression'Thu, 07 Mar 2019 17:25:05 -0600http://ask.sagemath.org/question/45716/factor-a-solve-output/Answer by Emmanuel Charpentier for <p>I am new to sage. So, sorry if my question is too trivial.</p>
<p>I can not factor the output of "solve". For instance, this very simple example</p>
<pre><code>x= var('x')
sols=solve(x==6, x)
factor(sols[0].right())
</code></pre>
<p>gives me </p>
<pre><code>6
</code></pre>
<p>Why I am not getting the following?</p>
<pre><code>2 * 3
</code></pre>
<p>which of course is the output of </p>
<pre><code>factor(6).
</code></pre>
<p>PS: I guess that the "type" is a crucial thing here, but anyways I'd need to factor 'sage.symbolic.expression.Expression'</p>
http://ask.sagemath.org/question/45716/factor-a-solve-output/?answer=45721#post-id-45721`factor` does not mean the same thing in $\mathbb{Z}$ (or $\mathbb{Q}$) and in `SR`: if, on both cases, `factor` aims at (recursively) transforming its input in a product of "simpler" elements, the meaning of "simpler" differs:
* In $\mathbb{Z}$ (or $\mathbb{Q}$), the "simplest" elements are *primes*;
* in `SR`, they are (roughly) polynomials.
In `SR`, 6 is already a monomial, hence a non-simplifiable element, whereas, in $\mathbb{Z}$, it is *not* a prime, hence factorizable as a product of primes.
Another illustration:
sage: factor(6/5)
2 * 3 * 5^-1
sage: factor(SR(6/5))
6/5
HTH,
Fri, 08 Mar 2019 01:02:33 -0600http://ask.sagemath.org/question/45716/factor-a-solve-output/?answer=45721#post-id-45721Comment by Emmanuel Charpentier for <p><code>factor</code> does not mean the same thing in $\mathbb{Z}$ (or $\mathbb{Q}$) and in <code>SR</code>: if, on both cases, <code>factor</code> aims at (recursively) transforming its input in a product of "simpler" elements, the meaning of "simpler" differs:</p>
<ul>
<li><p>In $\mathbb{Z}$ (or $\mathbb{Q}$), the "simplest" elements are <em>primes</em>;</p></li>
<li><p>in <code>SR</code>, they are (roughly) polynomials.</p></li>
</ul>
<p>In <code>SR</code>, 6 is already a monomial, hence a non-simplifiable element, whereas, in $\mathbb{Z}$, it is <em>not</em> a prime, hence factorizable as a product of primes.</p>
<p>Another illustration:</p>
<pre><code>sage: factor(6/5)
2 * 3 * 5^-1
sage: factor(SR(6/5))
6/5
</code></pre>
<p>HTH,</p>
http://ask.sagemath.org/question/45716/factor-a-solve-output/?comment=45726#post-id-45726Another, more pythonic way, would be :
ZZ((x==6).solve(x)[0].rhs()).factor()Fri, 08 Mar 2019 11:02:18 -0600http://ask.sagemath.org/question/45716/factor-a-solve-output/?comment=45726#post-id-45726Comment by Juanjo for <p><code>factor</code> does not mean the same thing in $\mathbb{Z}$ (or $\mathbb{Q}$) and in <code>SR</code>: if, on both cases, <code>factor</code> aims at (recursively) transforming its input in a product of "simpler" elements, the meaning of "simpler" differs:</p>
<ul>
<li><p>In $\mathbb{Z}$ (or $\mathbb{Q}$), the "simplest" elements are <em>primes</em>;</p></li>
<li><p>in <code>SR</code>, they are (roughly) polynomials.</p></li>
</ul>
<p>In <code>SR</code>, 6 is already a monomial, hence a non-simplifiable element, whereas, in $\mathbb{Z}$, it is <em>not</em> a prime, hence factorizable as a product of primes.</p>
<p>Another illustration:</p>
<pre><code>sage: factor(6/5)
2 * 3 * 5^-1
sage: factor(SR(6/5))
6/5
</code></pre>
<p>HTH,</p>
http://ask.sagemath.org/question/45716/factor-a-solve-output/?comment=45722#post-id-45722Just for completeness, to get the expected answer in the OP, it suffices to convert to integer the output of `solve` :
sage: factor(ZZ(sols[0].right()))
2 * 3Fri, 08 Mar 2019 04:57:04 -0600http://ask.sagemath.org/question/45716/factor-a-solve-output/?comment=45722#post-id-45722