2

I need to convert input expressions with explicit powers e.g.:

  • $x^2 + 2*y^6$

to this format:

  • $xx + 2 y y y y y y$

or this:

  • $x*x + 2*y*y*y*y*y*y$

and then preserve this new format for other conversions using HoldForm[...]. Is any way how to do this as easily as possible? I have idea to do some parsing in cycle in this way:

  • $2*y^6$ >> $2*y^5*y$ >> $2*y^4*y*y$ >> ... >> $2*y*y*y*y*y*y$

But it seems to be too complicated.

blenderman
  • 35
  • 2
  • What kind of "other conversions" do you need to do? Perhaps there might be a way of doing those without having to this present conversion... – MarcoB Apr 06 '16 at 20:25
  • I have to replace different occurences of same variable with some values i.e. y^6 is only 1 occurence of variable y and I need get 6 occurences. I have alredy written code for this purpose so I only need to convert input. Maybe easier way will be to do it in some other editor but I am interested if it is feasible in mathematica. – blenderman Apr 06 '16 at 20:32

1 Answers1

3

Perhaps

f = #/. Power[a_,b_]:>(Inactive[Times]@@ConstantArray[a,b])&

f[x^2+2 y^5]
(*  x*x+2 (y*y*y*y*y) *)
kglr
  • 394,356
  • 18
  • 477
  • 896