3
$\begingroup$

I am trying to illustrate some simple ideas with exponents. I can manually express something like $5^4$ as $5 \cdot 5 \cdot 5 \cdot 5$, but wondered how to get Mathematica to do that for me.

I found the example below in the documentation, but can't figure out how to "massage" it to work with a number that only has one factor, for example I would like $625$ to be represented as $5 \cdot 5 \cdot 5 \cdot 5$:

CenterDot @@ (Superscript @@@ FactorInteger[20!])

Any ideas would be appreciated.

$\endgroup$
10
$\begingroup$

Here's a way that seems to work:

CenterDot @@ Flatten[ConstantArray @@@ FactorInteger[20!]]

enter image description here

CenterDot @@ Flatten[ConstantArray @@@ FactorInteger[625]]

enter image description here

To get the number back, merely do

Times @@ expr

where expr is the name for the expression that results from the code above.

$\endgroup$
10
$\begingroup$

You can also make use of Inactive to allow you to calculate the value later.

Starting with march's solution and altering the Apply.

n = 20!;
t = Inactive[Times] @@ Flatten[ConstantArray @@@ FactorInteger[n]]
(* 2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*3*3*3*3*3*3*3*3*5*5*5*5*7*7*11*13*17*19 *)

t can be Activated to calculate the value.

Activate@t == n
(* True *)

Hope this helps

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.