# factorize symbolic expression

(ax+bx).factor()=x(a+b) but (2a+2b).factor()=(2a+2b) how to obtain 2(a+b) ?

Thanks in advance...

factorize symbolic expression

(ax+bx).factor()=x(a+b) but (2a+2b).factor()=(2a+2b) how to obtain 2(a+b) ?

Thanks in advance...

0

You can work with elements of a polynomial ring instead of with symbolic expressions:

```
sage: R.<a,b,c> = ZZ[] # polynomials with integer coefficients, variables a, b, c
sage: (a*2+b*2).factor()
2 * (a + b)
sage: (a*c+b*c).factor()
c * (a + b)
```

The notion of factorization is algebraic and depends on the ring in which you are working. For example `x^2+1`

factors over the complex numbers but not the reals, and `x^2-2`

factors over the reals but not the rationals. So when you're dealing with factorization, it's a good idea to precisely specify the ring.

Asked: **
2019-12-15 08:36:29 -0500
**

Seen: **118 times**

Last updated: **Dec 17 '19**

Factorize characteristic polynomial in SR base ring

Force Convert a Polynomial Ring into Multivariate Polynomial

Getting the denominator takes ages...

how to append to a symbolic expression in a loop?

Exponential change of variables in symbolic ring

What's wrong with Лобачевский function?

List common factors of integers

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.

There exists the

`collect_common_factors`

method that should do the trick, I think. But it seems a bit buggy. This works as expected:However, this fails:

Looks like a bug to me, since

`(2*a*x + 2*b*x).factor()`

returns`2*(a + b)*x`

.