pgcd ( p q -- a d )
Polynomials
Prev:p/mod ( p q -- z w )
Next:polyval ( x p -- p[x] )


Vocabulary
math.polynomials

Inputs and outputs
pa polynomial
qa polynomial
aa polynomial
da polynomial


Word description
Computes the greatest common divisor d of p and q, and another value a satisfying:
a*q = d mod p


Notes
GCD in the case of polynomials is a monic polynomial of the highest possible degree that divides into both p and q.

Examples
USING: kernel math.polynomials prettyprint ; { 1 1 1 1 } { 1 1 } pgcd [ . ] bi@
{ 0 0 } { 1 1 }


Definition
USING: arrays kernel math.polynomials.private ;

IN: math.polynomials

: pgcd ( p q -- a d )
[ V{ 0 } clone V{ 1 } clone ] 2dip swap (pgcd)
[ >array ] bi@ ;