MathGroup Archive 1995

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

Search the Archive

Re: FactorInteger Print Formatting

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg774] Re: FactorInteger Print Formatting
  • From: Count Dracula <lk3a at kelvin.seas.virginia.edu>
  • Date: Tue, 18 Apr 1995 01:08:17 -0400
  • Organization: University of Virginia

In Article 89 (Paul A. Rubin) rubin at msu.edu wrote:

> In[1]:= faclist[ x_Integer ] := ff[ FactorInteger[ x ] ]
> In[2]:= Format[ ff[ {n_Integer, 1} ] ] := n
> In[3]:= Format[ ff[ {n_Integer, m_Integer} ] ] := SequenceForm[ n, "^", m ]
> In[4]:= Format[ ff[ x_List ] ] := 
>            SequenceForm[ ff[ x[[1]] ], "*", ff[ Rest[ x ] ] ]
> In[5]:= Format[ ff[ {x_List} ] ] := ff[ x ]

> This defines a function faclist that wraps the output of FactorInteger in a 
> dummy head "ff."  

Why not directly wrap SequenceForm around the object via the 
following easier definition?

faclistnew[1] = SequenceForm[1]
 
faclistnew[x_Integer] := Apply[SequenceForm, Drop[Flatten[FactorInteger[x] /. 
      {{n_, 1} :> {n, "*"}, {n_Integer, m_} :> {n, "^", m, "*"}}], -1]]


It seems that the appeareances do not change but we save the extra overhead
of the extra Head ff:

In[6]:= faclistnew[2400]

Out[6]= 2^5*3*5^2

In[7]:= FullForm[%]

Out[7]//FullForm= SequenceForm[2, "^", 5, "*", 3, "*", 5, "^", 2]

In[8]:= faclist[2400]

Out[8]= 2^5*3*5^2

In[9]:= FullForm[%]

Out[9]//FullForm= ff[List[List[2, 5], List[3, 1], List[5, 2]]]


By the way, a separate definition for 1 is necessary because FactorInteger[1]
returns {} and consequently:

In[10]:= faclist[1]

Part::partw: Part 1 of {} does not exist.

Rest::norest: Cannot take Rest of expression {} with length zero.
Out[10]= ff[{}[[1]]]*ff[Rest[{}]]

-- 
 ___________________________________________________________________________________
 Levent Kitis           lk3a at cars.mech.virginia.edu    lk3a at kelvin.seas.virginia.edu
 University of Virginia  Department of Mechanical, Aerospace and Nuclear Engineering  
 ___________________________________________________________________________________


  • Prev by Date: Re: How do you input a solution from FindRoot into another equation?
  • Next by Date: P:Re: FactorInteger Print Formatting
  • Previous by thread: Re: FactorInteger Print Formatting
  • Next by thread: Re: FactorInteger Print Formatting