Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm studying polynomial rings and i would like to know some tricks for generating lots of examples.

For instance, suppose i'm interested in polynomials over the integers mod (2,x^3 + 1). To get a feel for the structure i would like to expand a bunch of random polynomials and see what happens.

I would like to do this without typing each individually.

Any suggestions?

Thank you!

share|improve this question
Ok. Well what i do now is go like Expand[(5 x + 43/5) (23 x - 45/2) (12 x + 90/2)] and see what happens. Use the PolynomialMod function on it see what i get. But this is just one example. I want to generate lots of examples. And i dont want to do it by typing each one out. I just want to know how i would go about generating lots of examples like the one i just discussed, which was just a random polynomial. – Fawkes5 Nov 26 '12 at 5:05
up vote 2 down vote accepted

This hopefully will get you started. It asks for the polynomial order, generate random integers from 1 to 10 for the coefficients of the polynomial, then uses FromDigits to build the polynomial in x. It also asks for the Mod integer value to use. It then calls PolynomialMod and shows the original polynomial and the polynomial mod the integer.

Not pretty, just a quick hack. Just to first see if this is what you want before going more.


 Module[{p, m},
  p = makePolynomial[n, x];
  m = PolynomialMod[p, mod];

    {"polynomial", Expand[p]},
    {Row[{"polynomial mod ", mod}], m}
    }, Alignment -> Left, Frame -> All]

 {{n, 2, "polynomial order"}, 2, 10, 1, Appearance -> "Labeled"},
 {{mod, 2, "mod"}, 1, 10, 1, Appearance -> "Labeled"},
 Button["make another", doit = Date[], ImageSize -> 100],
 ContentSize -> {550, 80},

 Initialization :>
   makePolynomial[n_Integer, x_Symbol] := Module[{z, c},
     z = RandomChoice[{-1, 1}] RandomInteger[{1, 10}];
     c = Table[RandomInteger[{-10, 10}], {n}];
     FromDigits[Reverse[AppendTo[c, z]], x]

enter image description here

share|improve this answer
Yah thats exactly the kinda of thing i'm looking for. Thanks for getting me started :). – Fawkes5 Nov 26 '12 at 14:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.