# Write Integer powers as products

I need to wirte all occasions of

(a+b)^3,Ftp^2, Sin[th]^2, ...etc


as

(a+b)*(a+b)*(a+b), Ftp*Ftp, Sin[th]*Sin[th], ...etc


For

(a+b)^3


it would also be ok to write

a*a*a + 3*a*a*b + 3*a*b*b + b*b*b


Here is an Example expression for wich I need to do this:

(gamma^2*M*Sin[th]*((Fmpb*Fp^2*gamma^2*Cos[th] + 2*Fmp*Fp*Fpb*gamma^2*Cos[th] + (Fmtb*Fp + Fmt*Fpb)*Fpp*gamma^2*Sin[th] - Fmpb*Fp*Ftp*gamma^2*Sin[th] - Fmp*Fpb*Ftp*gamma^2*Sin[th] - Fmp*Fp*Ftpb*gamma^2*Sin[th] + Ft*(Fmtb*Ftp + Fmt*Ftpb - Fmpb*Ftt - Fmp*Fttb)*gamma^2*Sin[th]^3 + Ftb*(Fmt*Ftp*gamma^2 - Fmp*Ftt*gamma^2 + M*omega^2*αlpha*Cos[th])*Sin[th]^3 + Fttb*M*omega^2*αlpha*Sin[th]^4 + Fppb*Sin[th]*(Fmt*Fp*gamma^2 + M*omega^2*αlpha*Sin[th]))*(-(Fp^2*Cos[th]*Sin[ph - phH]*Sin[thH]) + Fp*(Ftp*Sin[ph - phH]*Sin[th]*Sin[thH] + Fpp*(-(Cos[thH]*Sin[th]) + Cos[ph - phH]*Cos[th]*Sin[thH])) + Ft*Sin[th]^2*(Ftt*Sin[ph - phH]*Sin[th]*Sin[thH] + Ftp*(-(Cos[thH]*Sin[th]) + Cos[ph - phH]*Cos[th]*Sin[thH]))) - (Fmp*Fp^2*gamma^2*Cos[th] - Fmp*Fp*Ftp*gamma^2*Sin[th] + Ft*(Fmt*Ftp*gamma^2 - Fmp*Ftt*gamma^2 + M*omega^2*αlpha*Cos[th])*Sin[th]^3 + Ftt*M*omega^2*αlpha*Sin[th]^4 + Fpp*Sin[th]*(Fmt*Fp*gamma^2 + M*omega^2*αlpha*Sin[th]))*(-2*Fp*Fpb*Cos[th]*Sin[ph - phH]*Sin[thH] + Fpb*(Ftp*Sin[ph - phH]*Sin[th]*Sin[thH] + Fpp*(-(Cos[thH]*Sin[th]) + Cos[ph - phH]*Cos[th]*Sin[thH])) + Fp*(Ftpb*Sin[ph - phH]*Sin[th]*Sin[thH] + Fppb*(-(Cos[thH]*Sin[th]) + Cos[ph - phH]*Cos[th]*Sin[thH])) + Ftb*Sin[th]^2*(Ftt*Sin[ph - phH]*Sin[th]*Sin[thH] + Ftp*(-(Cos[thH]*Sin[th]) + Cos[ph - phH]*Cos[th]*Sin[thH])) + Ft*Sin[th]^2*(Fttb*Sin[ph - phH]*Sin[th]*Sin[thH] + Ftpb*(-(Cos[thH]*Sin[th]) + Cos[ph - phH]*Cos[th]*Sin[thH])))))/(Fmp*Fp^2*gamma^2*Cos[th] - Fmp*Fp*Ftp*gamma^2*Sin[th] + Ft*(Fmt*Ftp*gamma^2 - Fmp*Ftt*gamma^2 + M*omega^2*αlpha*Cos[th])*Sin[th]^3 + Ftt*M*omega^2*αlpha*Sin[th]^4 + Fpp*Sin[th]*(Fmt*Fp*gamma^2 + M*omega^2*αlpha*Sin[th]))^2


I always have integer powers and all of them need to be "falttened out" into products.

Thank you for any Help.

If you have Version 10:

rF = # /. Power[x_,y_]:>Inactive[Times]@@Table[x,{y}]&;
(* or rF = # /. Power->(Inactive[Times]@@Table[#,{#2}]&)&; *)

lst = {(a + b)^3, Ftp^2, Sin[th]^2};
rF@lst
(* {(a+b)*(a+b)*(a+b),Ftp*Ftp,Sin[th]*Sin[th]} *)


Or

rF2 = Block[{Power=Inactive[Times]@@Table[#,{#2}]&},#]&
rF2 @ lst
(* {(a+b)*(a+b)*(a+b),Ftp*Ftp,Sin[th]*Sin[th]} *)


For Version 9:

rF3 = # /. Power[x_, y_] :> (Fold[Composition[Defer, Times], x, Table[x, {y - 1}]]) &;

rF3@lst
(* {((a + b) (a + b)) (a + b), Ftp Ftp, Sin[th] Sin[th]} *)

• Thank you very much, i was running on version 9, but just installed 10 to use your code. I'v made a small addition for when i evaluate the example above i get "...M Sin[th] Inactive[Times][] gamma*gamma..." so I used (rF@lst) /. Inactive[Times][] -> 1 – Walter Lars Lee Dec 21 '14 at 13:24
• @Walter, my pleasure. Welcome to mma.se. – kglr Dec 21 '14 at 13:34