Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Re: Pretty output

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35156] Re: Pretty output
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 27 Jun 2002 00:23:20 -0400 (EDT)
  • References: <afbih4$54r$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Robert,
Using ToString seems to be causing the printing to be in OutputForm which is
clearly not very good.
The following will print in readable StandardForm

    Do[s = Sum[x^i, {i, 0, 2^n}];
      Print[Factor[s, Modulus -> 2]], {n, 1, 10}].

However, since you want to find the number of factors it is best not to use
Print and Do but to make a list of the factorized expressions.


    fcts=Table[Factor[Sum[x^i,{i,0,2^n}], Modulus->2],{n,1,10}];

The output is not shown because of the final semicolon.
If you want to look at the list it might be better to use

    TableForm[fcts]

We can extract individual expressions: for example

    Part[fcts, 9]

But if we only need the number of factors in each expression then the
following works

    Map[Length, a fcts]-1

        {1,1,2,2,4,6,10,16,30,52}

Here I used the trick of  multiplying by a dummy expression a and later
subtracting one because the first two expressions are

1 + x + x^2,
1 + x + x^2 + x^3 + x^4

and, for example, Length[1 + x + x^2] would give 3, the number of summands,
whereas Length[a*(1 + x + x^2)] gives the number of multiplicands, 2;  and
on subtracting 1 we get 1, the answer that we want.
The trick is not necessary with  the third entry, (1 + x + x^2)*(1 + x^3 +
x^6), but it still gives the right answer.
--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"Robert G. Wilson v" <rgwv at kspaint.com> wrote in message
news:afbih4$54r$1 at smc.vnet.net...
> Help please.
>
> I put in the following Mathematica code: Do[s = Sum[x^i, {i, 0, 2^n}];
> Print[ ToString[ Factor[ s, Modulus -> 2]]], {n, 1, 10}]
>
> The output was fairly straight forward until n=6 and beyond. What I am
> seeing is:
>
> "          2    3    4        4    5    6    7    8    12        2
> 5    6    7    10    12        2    3    4    6    8    9   \
>  10    12            3    5    6    7    9    11    12            2
> 3    4    5    6    7    8    9    10    11    12\n(1 + x \
> + x  + x  + x ) (1 + x  + x  + x  + x  + x  + x  ) (1 + x  + x  + x  +
> x  + x   + x  ) (1 + x  + x  + x  + x  + x  + x  + x   + x \
>  ) (1 + x + x  + x  + x  + x  + x  + x   + x  ) (1 + x + x  + x  + x  +
> x  + x  + x  + x  + x  + x   + x   + x  )"
>
> What is the deal here?
>
> Also what is the easiest way to count the number of factors?
>
> Thank you for any assistance in advance.
>
> Sincerely yours,
>
> Robert G. Wilson, V
>




  • Prev by Date: Re: Pretty output
  • Next by Date: DISPLAY-EPS
  • Previous by thread: RE: Pretty output
  • Next by thread: Re: Pretty output