 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays kernel make math math.order math.vectors sequences
-splitting vectors macros combinators math.bits ;
+USING: arrays combinators fry kernel macros make math math.bits
+math.order math.vectors sequences splitting vectors ;
 IN: math.polynomials
 
 <PRIVATE

: 2ptrim ( p q -- p' q' ) [ ptrim ] bi@ ;
: p+ ( p q -- r ) pextend v+ ;
: p- ( p q -- r ) pextend v- ;
: n*p ( n p -- n*p ) n*v ;

: pextend-conv ( p q -- p' q' )
    2dup [ length ] bi@ + 1 - 2pad-tail [ >vector ] bi@ ;

: p* ( p q -- r )
    2unempty pextend-conv <reversed> dup length iota
    [ over length pick <slice> pick [ * ] 2map sum ] map 2nip reverse ;

: p-sq ( p -- p^2 )
    dup p* ;

ERROR: negative-power-polynomial p n ;


    dup 1 < [ drop 1 ] when
    [ over length + 0 pad-head pextend ] keep 1 + ;

: /-last ( seq1 seq2 -- x ) [ last ] bi@ / ;

: (p/mod) ( p p -- p p )
    2dup /-last
