]> gitweb.factorcode.org Git - factor.git/commitdiff
Polynomials work with arrays or vectors as input. Output is not standardized to array...
authorDoug Coleman <erg@trifocus.net>
Mon, 31 Oct 2005 18:13:06 +0000 (18:13 +0000)
committerDoug Coleman <erg@trifocus.net>
Mon, 31 Oct 2005 18:13:06 +0000 (18:13 +0000)
contrib/math/polynomials.factor
contrib/math/test.factor

index 498ed09463d00d9d6a17847656097c29dbd9aab0..15090d1682fbc96a7ecb4b726a471d5cf6674335 100644 (file)
@@ -1,5 +1,5 @@
 IN: polynomials-internals
-USING: kernel sequences vectors math math-internals namespaces ;
+USING: kernel sequences vectors math math-internals namespaces arrays ;
 
 : 2length ( seq seq -- ) [ length ] 2apply ;
 
@@ -24,7 +24,7 @@ USING: kernel sequences vectors math math-internals namespaces ;
     2dup max-length [ swap zero-extend ] keep swap zero-extend ;
 
 : pextend ( p p -- p p )
-    2dup 2zero-extend ;
+    [ >vector ] 2apply 2dup 2zero-extend ;
 
 IN: math-contrib
 
@@ -32,6 +32,7 @@ IN: math-contrib
     pextend = ;
 
 : ptrim ( p -- p )
+    >vector
     dup length 1 > [ dup peek 0 = [ dup pop drop ptrim ] when ] when ;
 
 : 2ptrim ( p -- p )
index c7ab316ed1552131beea3e6e24ca4f7c409f6773..5e11f3ab6de44bb684973cb1acc299ea96a6ba36 100644 (file)
@@ -2,30 +2,29 @@ IN: temporary
 USING: kernel math test sequences math-contrib ;
 
 ! Tests
-[ { 0 1 } ] [ { 0 1 0 0 } ptrim ] unit-test
-[ { 1 } ] [ { 1 0 0 } ptrim ] unit-test
-[ { 0 } ] [ { 0 } ptrim ] unit-test
-[ { 3 10 8 } ] [ { 1 2 } { 3 4 } p* ] unit-test
-[ { 3 10 8 } ] [ { 3 4 } { 1 2 } p* ] unit-test
-[ { 0 0 0 0 0 0 0 0 0 0 } ] [ { 0 0 0 } { 0 0 0 0 0 0 0 0 } p* ] unit-test
-[ { 0 1 } ] [ { 0 1 } { 1 } p* ] unit-test
-[ { 0 0 0 } ] [ { 0 0 0 } { 0 0 0 } p+ ] unit-test
-[ { 0 0 0 } ] [ { 0 0 0 } { 0 0 0 } p- ] unit-test
+[ V{ 0 1 } ] [ { 0 1 0 0 } ptrim ] unit-test
+[ V{ 1 } ] [ { 1 0 0 } ptrim ] unit-test
+[ V{ 0 } ] [ { 0 } ptrim ] unit-test
+[ V{ 3 10 8 } ] [ { 1 2 } { 3 4 } p* ] unit-test
+[ V{ 3 10 8 } ] [ { 3 4 } { 1 2 } p* ] unit-test
+[ V{ 0 0 0 0 0 0 0 0 0 0 } ] [ { 0 0 0 } { 0 0 0 0 0 0 0 0 } p* ] unit-test
+[ V{ 0 1 } ] [ { 0 1 } { 1 } p* ] unit-test
+[ V{ 0 0 0 } ] [ { 0 0 0 } { 0 0 0 } p+ ] unit-test
+[ V{ 0 0 0 } ] [ { 0 0 0 } { 0 0 0 } p- ] unit-test
 [ { 0 0 0 } ] [ 4 { 0 0 0 } n*p ] unit-test
 [ { 4 8 0 12 } ] [ 4 { 1 2 0 3 } n*p ] unit-test
-[ { 1 4 7 6 0 0 0 0 0 } ] [ { 1 2 3 0 0 0 } { 1 2 0 0 } conv ] unit-test
-[ { 1 4 7 6 0 0 0 0 0 } ] [ { 1 2 3 0 0 0 } { 1 2 0 0 } p* ] unit-test
-[ { 7 -2 1 } { -20 0 0 } ] [ { 1 1 1 1 } { 3 1 } p/mod ] unit-test
-[ { 0 0 } { 1 1 } ] [ { 1 1 } { 1 1 1 1 } p/mod ] unit-test
-[ { 1 0 1 } { 0 0 0 } ] [ { 1 1 1 1 } { 1 1 } p/mod ] unit-test
-[ { 1 0 1 } { 0 0 0 } ] [ { 1 1 1 1 } { 1 1 0 0 0 0 0 0 } p/mod ] unit-test
-[ { 1 0 1 } { 0 0 0 } ] [ { 1 1 1 1 0 0 0 0 } { 1 1 0 0 } p/mod ] unit-test
+[ V{ 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
+[ V{ 1 0 1 } V{ 0 0 0 } ] [ { 1 1 1 1 } { 1 1 } p/mod ] unit-test
+[ V{ 1 0 1 } V{ 0 0 0 } ] [ { 1 1 1 1 } { 1 1 0 0 0 0 0 0 } p/mod ] unit-test
+[ V{ 1 0 1 } V{ 0 0 0 } ] [ { 1 1 1 1 0 0 0 0 } { 1 1 0 0 } p/mod ] unit-test
 ! [ { 5.0 } { 0.0 } ] [ { 10.0 } { 2.0 } p/mod ] unit-test
 ! [ { 15/16 } { 0 } ] [ { 3/4 } { 4/5 } p/mod ] unit-test
 [ t ] [ { 0 1 } { 0 1 0 } p= ] unit-test
 [ f ] [ { 0 0 1 } { 0 1 0 } p= ] unit-test
 [ t ] [ { 1 1 1 } { 1 1 1 } p= ] unit-test
-[ { 0 0 } { 1 1 } ] [ { 1 1 1 1 } { 1 1 } pgcd ] unit-test
+[ V{ 0 0 } V{ 1 1 } ] [ { 1 1 1 1 } { 1 1 } pgcd ] unit-test
 
 [ t ] [ 10 3 nPk 10 factorial 7 factorial / = ] unit-test
 [ t ] [ 10 3 nCk 10 factorial 3 factorial 7 factorial * / = ] unit-test