# 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.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'

edit retag close merge delete

Sort by » oldest newest most voted

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,

more

Just for completeness, to get the expected answer in the OP, it suffices to convert to integer the output of solve :

sage: factor(ZZ(sols.right()))
2 * 3


Another, more pythonic way, would be :

ZZ((x==6).solve(x).rhs()).factor()