Merge branch 'master' of git://github.com/erikcharlebois/factor
commit
e1f80b4930
|
@ -17,6 +17,7 @@ IN: math.polynomials.tests
|
|||
[ { 4 8 0 12 } ] [ 4 { 1 2 0 3 } n*p ] unit-test
|
||||
[ { 1 4 4 0 0 } ] [ { 1 2 0 } p-sq ] unit-test
|
||||
[ { 1 6 12 8 0 0 0 } ] [ { 1 2 0 } 3 p^ ] unit-test
|
||||
[ { 1 } ] [ { 1 2 0 } 0 p^ ] unit-test
|
||||
[ { 1 4 7 6 0 0 0 0 0 } ] [ { 1 2 3 0 0 0 } { 1 2 0 0 } p* ] unit-test
|
||||
[ V{ 7 -2 1 } V{ -20 0 0 } ] [ { 1 1 1 1 } { 3 1 } p/mod ] unit-test
|
||||
[ V{ 0 0 } V{ 1 1 } ] [ { 1 1 } { 1 1 1 1 } p/mod ] unit-test
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! 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 ;
|
||||
splitting vectors macros combinators math.bits ;
|
||||
IN: math.polynomials
|
||||
|
||||
<PRIVATE
|
||||
|
@ -40,12 +40,13 @@ PRIVATE>
|
|||
|
||||
ERROR: negative-power-polynomial p n ;
|
||||
|
||||
: (p^) ( p n -- p^n )
|
||||
make-bits { 1 } [ [ over p* ] when [ p-sq ] dip ] reduce nip ;
|
||||
|
||||
: p^ ( p n -- p^n )
|
||||
{
|
||||
{ [ dup 0 > ] [ 1 - dupd [ p* ] with times ] }
|
||||
{ [ dup 0 = ] [ 2drop { 1 } ] }
|
||||
{ [ dup 0 < ] [ negative-power-polynomial ] }
|
||||
} cond ;
|
||||
dup 0 >=
|
||||
[ (p^) ]
|
||||
[ negative-power-polynomial ] if ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
|
|
Loading…
Reference in New Issue