Ask Your Question
1

Why won't sage (maxima) factor the symbolic expression 2*a3 - 2*a6?

asked 2020-12-03 01:49:54 +0100

TheHiggsBozo gravatar image

updated 2020-12-03 01:51:03 +0100

Here is some sample code.

maxima_calculus('algebraic: true;')

var('a3 a6')

(2*a3 - 2*a6).factor()

Does it not bother with integer factors with linear expressions, for some reason? It seems to handle more complicated expressions well, but now I'm a bit skeptical. For example, sage factors 2*a3^2 + 4*a3*a6 + 2*a6^2 just fine.

edit retag flag offensive close merge delete

Comments

Just an information: I tried with Maxima (version 19.01.2x) itself (not in SageMath) and it factorizes correctly:

Enter: factor(2 * a3 - 2 * a6);

The output is: -2*(a6-a3)

tolga gravatar imagetolga ( 2020-12-03 08:46:47 +0100 )edit

Thanks for the reply! That's definitely strange. The answer below gave a few more instances of sage factoring like this.

TheHiggsBozo gravatar imageTheHiggsBozo ( 2020-12-04 22:25:29 +0100 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2020-12-03 22:57:28 +0100

Emmanuel Charpentier gravatar image

contemplate :

sage: maxima.factor(2*a3 - 2*a6)
-2*(_SAGE_VAR_a6-_SAGE_VAR_a3)
sage: maxima.factor(2*a3 - 2*a6).sage()
2*a3 - 2*a6

Appaeently, Sage's output algorithm chooses the sum of two monomials to the product of such a sum by another monomial. Because it is "simplet" ? And, BTW :

sage: (2*a3 - 2*a6).factor()
2*a3 - 2*a6
sage: (2*a3 - 2*a6).collect_common_factors()
2*a3 - 2*a6
sage: (2*a3 - 2*a6).maxima_methods().factor()
2*a3 - 2*a6

HTH,

edit flag offensive delete link more

Comments

I guess it's time to replace ".factor( with "maxima.factor(" everywhere in my code. Thanks a lot! I'm curious if this is a bug or working as intended.

TheHiggsBozo gravatar imageTheHiggsBozo ( 2020-12-04 22:24:10 +0100 )edit

I guess it's time to replace ".factor( with "maxima.factor(" everywhere in my code.

Nope. Consider :

sage: var("a,b")
(a, b)
sage: a.parent()
Symbolic Ring
sage: maxima(a).parent()
Maxima
sage: maxima(a)*b
_SAGE_VAR_a*_SAGE_VAR_b
sage: (maxima(a)*b).parent()
Maxima

And there is no guarantee that you can do to a Maxima object the same things you do to a Symbolic Ring object.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-12-05 10:19:20 +0100 )edit
0

answered 2020-12-05 13:35:23 +0100

slelievre gravatar image

Sage has several ways to factor polynomial expressions.

Defined as symbolic expressions living in the symbolic ring, they factor as observed in the question.

It seems symbolic expressions in Sage are not able to hold a factor if it is a constant. As observed in the answer by @Emmanuel Charpentier, this is in contrast to Maxima.

To further illustrate that, consider the following example:

sage: a3, a6 = SR.var('a3, a6')
sage: q = (a3 - a6)
sage: p = x * q
sage: p
(a3 - a6)*x
sage: p.subs({x: 2})
2*a3 - 2*a6

There might or might not be a way to remedy that for symbolic expressions.

Defined in a polynomial ring, such expressions will factor differently though.

Define a polynomial ring over the integers:

sage: R.<a3, a6> = ZZ[]
sage: R
Multivariate Polynomial Ring in a3, a6 over Integer Ring

Define a polynomial in that ring:

sage: p = 2*a3 - 2*a6
sage: p
2*a3 - 2*a6

Factor it:

sage: p.factor()
2 * (a3 - a6)

Note that factoring in polynomials over the rationals would work differently.

edit flag offensive delete link more

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: 2020-12-03 01:49:54 +0100

Seen: 363 times

Last updated: Dec 05 '20