MathGroup Archive 2004

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

Search the Archive

Re: Please, can someone explain this small function?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50808] Re: Please, can someone explain this small function?
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Wed, 22 Sep 2004 00:11:12 -0400 (EDT)
  • Organization: The University of Western Australia
  • References: <cih0hn$md$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <cih0hn$md$1 at smc.vnet.net>,
 Cole Turner <REMOVEcole.turner at liwest.at> wrote:

> input: two polynomials as lists

Why not input polynomials as polynomials?

> output: the GCD

For which there is PolynomialGCD.

> methinks, this is the Euclidean Algorithm, what I don't get is how the
> "mon" is constructed here and what exactly the "MapIndexed" function
> does here - the MATHEMATICA help wasn't too helpful!
> thanks a lot in advance!!!!
> 
> In[1]:=
> myGCD[p1_List,p2_List]:=
>     Module[{mon,x,pol1,pol2,num},
>       mon[a_,{b_}]:=a*x^(b-1);
>       pol1=Factor[Plus@@MapIndexed[mon,p1]];
>       pol2=Factor[Plus@@MapIndexed[mon,p2]];

A simpler alternative is to use Dot:

  ToPolynomial[p_List][x_] := p . x^(Range[Length[p]]-1)

There is no need to use Factor here.

>       num=Numerator[pol1/pol2];
>       CoefficientList[pol1/num,x]

Use PolynomialGCD instead -- so the routine then becomes

  myGCD[p1_List,p2_List]:=
    Module[{x},
      CoefficientList[
        PolynomialGCD[ToPolynomial[p1][x], ToPolynomial[p2][x]], 
      x] 
    ]

but I do not see the advantage of this to and fro conversion between the 
list of coefficients and polynomials.

Cheers,
Paul

-- 
Paul Abbott                                   Phone: +61 8 6488 2734
School of Physics, M013                         Fax: +61 8 6488 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: Bilinear Transforms-> Möbius transforms
  • Next by Date: Re: Inline Formulas and Answers
  • Previous by thread: Re: Please, can someone explain this small function?
  • Next by thread: Re: Re: Please, can someone explain this small function?