# Want to generate picture of all the algebraic integers for all the polynomials of a given degree

So I'm looking for a function that takes in the degree of the polynomial and the range of coefficients from -c to c, and outputs a list of all the monic polynomials of that degree and with coefficients in that range.

I already have code to numerically compute the roots and plot in the complex plane, I just need a way to compute this list. I haven't been able to find previously posted code to do this task on stackexchange.

## 2 Answers

toMonicpol[lis_] := x^(Length[lis]) + Dot[lis, Table[x^r, {r, 0, Length[lis] - 1}]]

pols[deg_, c_] := Map[toMonicpol[#] &, Tuples[Range[-c, c], deg]]

pols[2, 3]

{-3 - 3 x + x^2, -3 - 2 x + x^2, -3 - x + x^2, -3 + x^2, -3 + x + x^2, -3 + 2 x + x^2, -3 + 3 x + x^2, -2 - 3 x + x^2, -2 - 2 x + x^2, -2 - x + x^2, -2 + x^2, -2 + x + x^2, -2 + 2 x + x^2, -2 + 3 x + x^2, -1 - 3 x + x^2, -1 - 2 x + x^2, -1 - x + x^2, -1 + x^2, -1 + x + x^2, -1 + 2 x + x^2, -1 + 3 x + x^2, -3 x + x^2, -2 x + x^2, -x + x^2, x^2, x + x^2, 2 x + x^2, 3 x + x^2, 1 - 3 x + x^2, 1 - 2 x + x^2, 1 - x + x^2, 1 + x^2, 1 + x + x^2, 1 + 2 x + x^2, 1 + 3 x + x^2, 2 - 3 x + x^2, 2 - 2 x + x^2, 2 - x + x^2, 2 + x^2, 2 + x + x^2, 2 + 2 x + x^2, 2 + 3 x + x^2, 3 - 3 x + x^2, 3 - 2 x + x^2, 3 - x + x^2, 3 + x^2, 3 + x + x^2, 3 + 2 x + x^2, 3 + 3 x + x^2}

Note that we can use FromDigits[{1, a, b, c}, x] to get a polynomial of degree Length[{a,b,c}] in x with leading coefficient 1:

 Expand @ FromDigits[{1, a, b, c}, x]


c + b x + a x^2 + x^3

Using Tuples[Range[-c,c], deg], as in ulvi's answer, to generate all tuples (i.e., all possible non-leading coefficients in a polynomial with degree deg), and Prepending each tuple with 1, we can use FromDigits on each list to get the desired list of monic polynomials:

mp[d_, c_] := Expand @ FromDigits[Prepend[#, 1], x] & /@ Tuples[Range[-c, c], d];


This gives the same list of polynomials as ulvi's pols:

Sort[mp[2, 3] ] == Sort[pols[2, 3]]


True