Ask Your Question
1

Factor a solve output

asked 2019-03-07 17:25:05 -0500

tidesson gravatar image

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'

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-03-08 01:02:33 -0500

Emmanuel Charpentier gravatar image

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,

edit flag offensive delete link more

Comments

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[0].right()))
2 * 3
Juanjo gravatar imageJuanjo ( 2019-03-08 04:57:04 -0500 )edit

Another, more pythonic way, would be :

ZZ((x==6).solve(x)[0].rhs()).factor()
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2019-03-08 11:02:18 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-03-07 17:25:05 -0500

Seen: 37 times

Last updated: Mar 08