MathGroup Archive 2010

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

Search the Archive

Re: Generation of polynomials

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112990] Re: Generation of polynomials
  • From: "Nasser M. Abbasi" <nma at 12000.org>
  • Date: Sun, 10 Oct 2010 06:40:47 -0400 (EDT)
  • References: <i8pgh5$fij$1@smc.vnet.net>
  • Reply-to: nma at 12000.org

On 10/9/2010 3:35 AM, pier.mail at gmail.com wrote:
> Hi!
> This is probably trivial, but I am a total novice with Mathematica...
> is it possible to generate all complete polynomials in x,y up to a
> certain degree, i.e
>
> 1
> 1+x+y
> 1+x+y+x^2+y^2+xy
> 1+x+y+x^2+y^2+xy+x^3+y^3+x^2y+y^2x
> 1+x+y+x^2+y^2+xy+x^3+y^3+x^2y+y^2x+x^4+y^4+x^3y+y^3x+x^2y^2
> ...
>
> Thanks,
> Pier
>
>

I am sure the experts here will gives you a better (more functional) 
solution, but this is my try at it. Here is a table for up to degree 5. 
If you spot a bug, pls let me know.

(*hack by Nasser M. Abbasi to generate complete polynomials*)
generateCompletePoly[x_, y_, degree_] := Module[{data, r, i},
  data = Flatten[Table[{x^i, y^i}, {i, 1, degree}]];
  r = Union@Flatten@{data, Outer[Times, data, data]};
  r = CoefficientRules[r, {x, y}];
  r = Select[r[[All, 1, 1]], Total[#] <= degree &];
  1 + Total[(Inner[Power, {x, y}, #, Times]) & /@ r]
  ];

Clear[x, y];

Table[generateCompletePoly[x, y, degree], {degree, 1, 5}]

  1 + x + y,

  1 + x + x^2 + y + x*y + y^2,

  1 + x + x^2 + x^3 + y + x*y + x^2*y + y^2 + x*y^2 + y^3,

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

  1 + x + x^2 + x^3 + x^4 + x^5 + y + x*y + x^2*y + x^3*y + x^4*y + y^2 
+ x*y^2 + x^2*y^2 + x^3*y^2 + y^3 + x*y^3 + x^2*y^3 + y^4 + x*y^4 + y^5


--Nasser





  • Prev by Date: Lists and Loops
  • Next by Date: Re: Further expanding d[xy]/dx in the output of a Dt calculation
  • Previous by thread: Re: Generation of polynomials
  • Next by thread: Re: Generation of polynomials