Re: Writing prime factor decomposision in conventional form
- To: mathgroup at smc.vnet.net
- Subject: [mg65371] Re: Writing prime factor decomposision in conventional form
- From: Cca <cca at gregosetroianos.mat.br>
- Date: Wed, 29 Mar 2006 06:34:09 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Wolfgang,
Much to my surprise, no one seems to have noticed that a solution
(surely due to Robby Villegas) is presented in the HelpBrowser under
MakeBoxes.
Below I offer some little variations. (Notice that the outputs
are evaluatable.)
------------------------------------------------------
FactoredInteger[0]=0;
FactoredInteger[1]=1;
FactoredInteger[n_Integer /; n > 1, multsign_: " "] :=
Module[{facs}, facs = FactorInteger[n];
DisplayForm@
Replace[Replace[Hold[Evaluate[facs]], {p_, a_} :> p^a, {2}],
Hold[{pots___}] :>
If[Length[facs] === 1, MakeBoxes[pots, StandardForm],
MakeBoxes[Times[pots],
StandardForm] /. " "-> multsign]]]
FactoredInteger[n_/;n<0]:=-FactoredInteger[-n]
Examples:
FactoredInteger[238500]
FactoredInteger[238500,"×"]
FactoredInteger[238500,"*"]
CenterDot=Times;
FactoredInteger[238500,"·"]
------------------------------------------------------
FactoredInteger2[n_Integer /; n > 1, multsign_: " "] :=
With[{facs = FactorInteger[n]}, DisplayForm@
Replace[Replace[Hold[facs], {p_, a_} :> p^a, {2}],
Hold[{pots___}] :>
If[Length[facs] === 1,
MakeBoxes[pots,
StandardForm] /. {SuperscriptBox[a_, b_] :>
RowBox[{a, "^", b}], " " -> multsign},
MakeBoxes[Times[pots],
StandardForm] /. {SuperscriptBox[a_, b_] :>
RowBox[{a, "^", b}], " " -> multsign}]]]
Examples:
In[10]:=
FactoredInteger2[238500,"*"]
Out[10]//DisplayForm=
2^2*3^2*5^3*53^1
In[11]:=
FactoredInteger2[238500,"×"]
Out[11]//DisplayForm=
2^2×3^2×5^3×53^1
Carlos César de Araújo
Gregos & Troianos Educacional
www.gregosetroianos.mat.br
Belo Horizonte, MG, Brasil
(31) 3283-1122