1 USING: help.markup help.syntax math sequences ;
4 ARTICLE: "polynomials" "Polynomials"
5 "A polynomial is a vector with the highest powers on the right:"
6 { $code "{ 1 1 0 1 } -> 1 + x + x^3" "{ } -> 0" }
7 "Numerous words are defined to help with polynomial arithmetic:"
13 { $subsection powers }
17 { $subsection polyval }
19 { $subsection pextend-conv }
21 { $subsection 2ptrim } ;
26 { $values { "n" integer } { "x" number } { "seq" sequence } }
27 { $description "Output a sequence having " { $snippet "n" } " elements in the format: " { $snippet "{ 1 x x^2 x^3 ... }" } "." }
28 { $examples { $example "USING: math.polynomials prettyprint ;" "4 2 powers ." "{ 1 2 4 8 }" } } ;
31 { $values { "p" "a polynomial" } { "q" "a polynomial" } { "?" "a boolean" } }
32 { $description "Tests if two polynomials are equal." }
33 { $examples { $example "USING: math.polynomials prettyprint ;" "{ 0 1 } { 0 1 0 } p= ." "t" } } ;
36 { $values { "p" "a polynomial" } { "p" "a polynomial" } }
37 { $description "Trims excess zeros from a polynomial." }
38 { $examples { $example "USING: math.polynomials prettyprint ;" "{ 0 1 0 0 } ptrim ." "{ 0 1 }" } } ;
41 { $values { "p" "a polynomial" } { "q" "a polynomial" } { "p" "a polynomial" } { "q" "a polynomial" } }
42 { $description "Trims excess zeros from two polynomials." }
43 { $examples { $example "USING: kernel math.polynomials prettyprint ;" "{ 0 1 0 0 } { 1 0 0 } 2ptrim [ . ] bi@" "{ 0 1 }\n{ 1 }" } } ;
46 { $values { "p" "a polynomial" } { "q" "a polynomial" } { "r" "a polynomial" } }
47 { $description "Adds " { $snippet "p" } " and " { $snippet "q" } " component-wise." }
48 { $examples { $example "USING: math.polynomials prettyprint ;" "{ 1 0 1 } { 0 1 } p+ ." "{ 1 1 1 }" } } ;
51 { $values { "p" "a polynomial" } { "q" "a polynomial" } { "r" "a polynomial" } }
52 { $description "Subtracts " { $snippet "q" } " from " { $snippet "p" } " component-wise." }
53 { $examples { $example "USING: math.polynomials prettyprint ;" "{ 1 1 1 } { 0 1 } p- ." "{ 1 0 1 }" } } ;
56 { $values { "n" number } { "p" "a polynomial" } { "n*p" "a polynomial" } }
57 { $description "Multiplies each element of " { $snippet "p" } " by " { $snippet "n" } "." }
58 { $examples { $example "USING: math.polynomials prettyprint ;" "4 { 3 0 1 } n*p ." "{ 12 0 4 }" } } ;
61 { $values { "p" "a polynomial" } { "q" "a polynomial" } { "p" "a polynomial" } { "q" "a polynomial" } }
62 { $description "Convulution, extending to " { $snippet "p_m + q_n - 1" } "." }
63 { $examples { $example "USING: kernel math.polynomials prettyprint ;" "{ 1 0 1 } { 0 1 } pextend-conv [ . ] bi@" "V{ 1 0 1 0 }\nV{ 0 1 0 0 }" } } ;
66 { $values { "p" "a polynomial" } { "q" "a polynomial" } { "r" "a polynomial" } }
67 { $description "Multiplies two polynomials." }
68 { $examples { $example "USING: math.polynomials prettyprint ;" "{ 1 2 3 0 0 0 } { 1 2 0 0 } p* ." "{ 1 4 7 6 0 0 0 0 0 }" } } ;
71 { $values { "p" "a polynomial" } { "p^2" "a polynomial" } }
72 { $description "Squares a polynomial." }
73 { $examples { $example "USING: math.polynomials prettyprint ;" "{ 1 2 0 } p-sq ." "{ 1 4 4 0 0 }" } } ;
76 { $values { "p" "a polynomial" } { "q" "a polynomial" } { "z" "a polynomial" } { "w" "a polynomial" } }
77 { $description "Computes to quotient " { $snippet "z" } " and remainder " { $snippet "w" } " of dividing " { $snippet "p" } " by " { $snippet "q" } "." }
78 { $examples { $example "USING: kernel math.polynomials prettyprint ;" "{ 1 1 1 1 } { 3 1 } p/mod [ . ] bi@" "V{ 7 -2 1 }\nV{ -20 0 0 }" } } ;
81 { $values { "p" "a polynomial" } { "q" "a polynomial" } { "a" "a polynomial" } { "d" "a polynomial" } }
82 { $description "Computes the greatest common divisor " { $snippet "d" } " of " { $snippet "p" } " and " { $snippet "q" } ", and another value " { $snippet "a" } " satisfying:" { $code "a*q = d mod p" } }
83 { $notes "GCD in the case of polynomials is a monic polynomial of the highest possible degree that divides into both " { $snippet "p" } " and " { $snippet "q" } "." }
85 { $example "USING: kernel math.polynomials prettyprint ;"
86 "{ 1 1 1 1 } { 1 1 } pgcd [ . ] bi@"
92 { $values { "p" "a polynomial" } { "p'" "a polynomial" } }
93 { $description "Finds the derivative of " { $snippet "p" } "." } ;
96 { $values { "p" "a polynomial" } { "x" number } { "p[x]" number } }
97 { $description "Evaluate " { $snippet "p" } " with the input " { $snippet "x" } "." }
98 { $examples { $example "USING: math.polynomials prettyprint ;" "{ 1 0 1 } 2 polyval ." "5" } } ;