MathGroup Archive 1995

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

Search the Archive

Re: Re: FactorInteger Print Formatting

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg767] Re: [mg694] Re: [mg650] FactorInteger Print Formatting
  • From: tiggj at iswaps.lonnds.ml.com (Jason Tigg SWAP GROUP ANALYST X2312 LDN)
  • Date: Tue, 18 Apr 1995 00:58:05 -0400

Hi,
	this may be what you want

In[1] := Format[ factorform[a_List] ] :=
	StringTake[ Apply[ StringJoin, Map[gform, a]], {1,-2}];
	gform[{b_,1}] := ToString[b] <> "*";
	gform[{b_,n_}] := ToString[b] <> "^" <> ToString[n] <> "*";

In[2] := 2^12 5^5 199
Out[2] = 2547200000

In[3] := factorform[ FactorInteger[%]] 
Out[3] = 2^12*5^5*199


jason

> 
> Dear Alan:
> 
> Here is a clue.  It is not exactly what you asked for, and it still needs
> an automatic way to generate the [[4]] at the end, but I think it is some
> progress.
> 
> In[23]:=  Trace[FactorInteger[400] /. {a_,b_}->a^b][[4]]
> 
>             5   2
> Out[23]=  {2 , 4 }
> 
> If you try to go beyond this kind of list output to the product form you
> asked for, the automatic exponent evaluation machinery takes over and
> destroys all progress.  This is closely related to a question I asked
> recently, which I suspect has no answer; viz:    How do you prevent 
> 
> In[34]:=  Sqrt[8]
> 
> Out[34]=  2 Sqrt[2]
> 
> I think what we need is an new option, like AnswerForm->pattern, which
> would stop evaluation if the desired pattern is created anywhere along the
> evaluation chain. 
> 
> Has anybody given any thought to this, WRI?
> 
> Regards-  Martin
> 
> >Could anyone suggest a neat way to reformat the output of
> >FactorInteger into a more usable print format?
> >
> >FactorInteger[n] gives a list of prime factors of the integer n
> >in ascending order, together with their exponents viz:
> >
> >  FactorInteger[900]    produces the list   {{2,2},{3,2},{5,2}}
> >
> >What I need is a function called say factorform[list] such that:
> >
> >  Print[ factorform[{{2,2},{3,2},{5,2}}] ]  produces  2^2*3^2*5^2
> >
> >Ideally exponents equal to 1 would be suppressed so that when
> >
> >  ff = FactorInteger[30]    produces    {{2,1},{3,1},{5,1}}    then
> >
> >  Print[factorform[ff]]  would give  2*3*5  instead of  2^1*3^1*5^1  and
> >
> >  Print[factorform[FactorInteger[2^6*3*5^2*7]]]  would give  2^6*3*5^2*7
> >
> >A procedural solution is possible, but I was unable to create a simple
> >function which would give the desired result.
> >
> >
> >Alan Powell          POWELLA at delphi.com
> 
> 
> 



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