A factor outside of the GCD that is raised to power

Using Mathematica (v.7), basically I want to give an expression like this

(x + x^2 + x^3)^4 

to

 x^4 (1 + x + x^2)^4 

What would be the best way to take a term, such as a GCD, from an expression that was raised to power and in factorized form; then put this term outside the brackets and store the value of the exponent to which it was raised. He would have to know that value rises to power before taking it out. Here is my attempt.

 In[28]:= example = (x + x^2 + x^3)^4 Out[28]= (x + x^2 + x^3)^4 In[37]:= gcdVar = PolynomialGCD[Sequence @@ Level[example, {2}]] Out[37]= x In[40]:= step1 = Map[Divide[#, gcdVar] &, example, {2}] Out[40]= (1 + x + x^2)^4 In[55]:= step2 = Times[step1, Power[gcdVar, Last[Level[example, {1}]]]] Out[55]= x^4 (1 + x + x^2)^4 

I examined all the various functions related to this area: Collect, Factor, Expand, Simplify, Solve. I do not think that any of them can make the conclusion that I need. Is there a built-in, more efficient, scalable, and shorter way to do this, perhaps using template / form matching?

+4
source share
2 answers

This does what you make the quick "n" dirty style, but on one line:

 example /. Power_[Plus_[f__], k_] :> ( PolynomialGCD@f )^k Simplify@ ( Plus@f / PolynomialGCD@f )^k 

This is not a very reliable solution, and you better create your own small module that checks that the greatest common divisor actually exists.

EDIT: you can add some inline checks as follows:

 example /. Power_[Plus_[f__], k_] /; !( PolynomialGCD@f === 1) :> ( PolynomialGCD@f )^k Simplify@ ( Plus@f / PolynomialGCD@f )^k 
+3
source

Factor @Expand seems to do what you want for the given example. Do you need a more general solution?

 Factor@Expand [(x + x^2 + x^3)^4] Out[8]= x^4 (1 + x + x^2)^4 

(I am using Mathematica 7)

+4
source

Source: https://habr.com/ru/post/1333993/


All Articles