MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: FactorInteger Print Formatting

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg719] Re: FactorInteger Print Formatting
  • From: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
  • Date: 11 Apr 1995 16:43:46 GMT
  • Organization: University of Colorado, Boulder

>Alan Powell <POWELLA at delphi.com> wrote:
>
>>Could anyone suggest a neat way to reformat the output of
>>FactorInteger into a more usable print format?
>< details deleted >

Here is a method that prints an integer factorization in standard
Mathematica OutputForm.  (Be sure to view this message using a
fixed-width font.)

The basic strategy I took was this: is there some way I can construct an
expression that *would* evaluate the factorization, but keep it wrapped
in HoldForm so that it doesn't evaluate, but looks like it should?
Here goes:

In[23]:=
    FactorInteger[238500]
Out[23]=
    {{2, 2}, {3, 2}, {5, 3}, {53, 1}}

n[24]:=
    Hold[Times] @@ Apply[Hold[Power], %, {1}]
Out[24]=
    Hold[Times][Hold[Power][2, 2], Hold[Power][3, 2], 
      Hold[Power][5, 3], Hold[Power][53, 1]]

In[25]:=
    HoldForm[Evaluate[%]]
Out[25]=
    Hold[Times][Hold[Power][2, 2], Hold[Power][3, 2], 
      Hold[Power][5, 3], Hold[Power][53, 1]]

(* Note that HoldForm holds its argument but doesn't print *)
(* Now get rid of the individual Hold's *)

In[26]:=
    % /. Hold[x_] -> x
Out[26]=
     2  2  3   1
    2  3  5  53

In[27]:=
    FullForm[%]
Out[27]//FullForm=
    HoldForm[Times[Power[2, 2], Power[3, 2], Power[5, 3], 
       Power[53, 1]]]

(* As a bonus, you can reconstruct the original integer at any time: *)

In[28]:=
    ReleaseHold[%]
Out[28]=
    238500


		Dave Wagner
		Principia Consulting
		(303) 786-8371
		princon at csn.net
		http://www.csn.net/princon


  • Prev by Date: Evaluating Abs
  • Next by Date: tried to post to newsgroup, it din't appear ?!
  • Previous by thread: Re: FactorInteger Print Formatting
  • Next by thread: Re: FactorInteger Print Formatting