MathGroup Archive 1995

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

Search the Archive

Re: FactorInteger Print Formatting

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg701] Re: FactorInteger Print Formatting
  • From: novak (John M. Novak)
  • Date: Mon, 10 Apr 1995 14:31:01 -0500

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 >

Well, here is a solution. I think it is hardly the most elegant, but it
is fairly brief...  The technique used here is to convert the list of
pairs of integers to a string, by using a transformation rule on
the pairs to insert a caret where necessary, and then
transposing the list of strings with a list of asterisks (dropping
the last one), and joining them all together.

factorform[a:{{_Integer, _Integer}..}] :=
    StringJoin @@ Drop[Flatten[
        Transpose[{a/.{{n_Integer, 1} :> ToString[n],
                       {n_Integer, m_Integer} :>
                           ToString[n]<>"^"<>ToString[m]
                      },
                   Table["*", {Length[a]} ]}
        ]
    ],-1]

I tried a solution based on formatting rules, but that would have
involved attaching a formatting rule to List, which could not be
done.

As usual with Mathematica, many other solutions are possible!

--John Novak
novak at wri.com




  • Prev by Date: How to search network for cycles?
  • Next by Date: Re: FactorInteger Print Formatting
  • Previous by thread: Re: FactorInteger Print Formatting
  • Next by thread: Re: FactorInteger Print Formatting