> # Polynomials and Rational Functions (i.e. quotients of polynomials) > # Univariate and Multivariate polys > > # expanded canonical form , coefficients, leading coefficient, degree > # the coefficients can be almost anything (for now int, reals, rationals) > > p1:= 7*x^4 - 2* x^3 + x^2 + 6 - 3*x; 4 3 2 p1 := 7 x - 2 x + x - 3 x + 6 -------------------------------------------------------------------------------- > # canonical form ---- coeff sorted in descending order with respect to the degree > > lco := lcoeff(p1); lco := 7 -------------------------------------------------------------------------------- > deg := degree (p1); deg := 4 -------------------------------------------------------------------------------- > p2:= x^2; 2 p2 := x -------------------------------------------------------------------------------- > p1 + p2; 4 3 2 7 x - 2 x + 2 x - 3 x + 6 -------------------------------------------------------------------------------- > p3:= p1 * p2; 4 3 2 2 p3 := (7 x - 2 x + x - 3 x + 6) x -------------------------------------------------------------------------------- > expand (p3); 6 5 4 3 2 7 x - 2 x + x - 3 x + 6 x -------------------------------------------------------------------------------- > p4:= (2*x -4)^ 10; 10 p4 := (2 x - 4) -------------------------------------------------------------------------------- > expand (p4); 10 9 8 7 6 5 1024 x - 20480 x + 184320 x - 983040 x + 3440640 x - 8257536 x 4 3 2 + 13762560 x - 15728640 x + 11796480 x - 5242880 x + 1048576 -------------------------------------------------------------------------------- > # sort in case the terms are mixed up --- sort will change the internal data struct. )simpl. table) > sort("); 10 9 8 7 6 5 1024 x - 20480 x + 184320 x - 983040 x + 3440640 x - 8257536 x 4 3 2 + 13762560 x - 15728640 x + 11796480 x - 5242880 x + 1048576 -------------------------------------------------------------------------------- > # elementary simplifications to test equivalence of expressions > > > p2; 2 x -------------------------------------------------------------------------------- > p1; 4 3 2 7 x - 2 x + x - 3 x + 6 -------------------------------------------------------------------------------- > coeff(p1, x^3); -2 -------------------------------------------------------------------------------- > # trailing coefficient > tcoeff(p1); 6 -------------------------------------------------------------------------------- > p3:= x^2-x*(x-1); 2 p3 := x - x (x - 1) -------------------------------------------------------------------------------- > coeff(p3, x^2); Error, unable to compute coeff -------------------------------------------------------------------------------- > # it must be in collected form > coeff(expand(p3), x^2); 0 -------------------------------------------------------------------------------- > # quotient and remainder (p1/ p2) > q5:= quo (p1, p2, x, 'r'); 2 q5 := 7 x - 2 x + 1 -------------------------------------------------------------------------------- > r; - 3 x + 6 -------------------------------------------------------------------------------- > r1:= rem(p1, p2, x, 'q1'); r1 := - 3 x + 6 -------------------------------------------------------------------------------- > q1; 2 7 x - 2 x + 1 -------------------------------------------------------------------------------- > # GCD of polys over the rationals > gcd(p1, p2); 1 -------------------------------------------------------------------------------- > # Factorization --- write it as a product of irreducible polys (over Q) > p5:= expand(p3 * p1); 5 4 3 2 p5 := 7 x - 2 x + x - 3 x + 6 x -------------------------------------------------------------------------------- > factor(p5); 4 3 2 x (7 x - 2 x + x - 3 x + 6) -------------------------------------------------------------------------------- > # factorization over the field Z2 (0,1 ); -------------------------------------------------------------------------------- > Factor(p5) mod 2; 2 3 x (x + x + 1) -------------------------------------------------------------------------------- > > > # MULTIVARIATE POLYS > # two or more indeterminates > p6:= 6*x*y^5 + 12*y^4 - x^2*y^3 + 21*x^5 -9*x*y^2; 5 4 2 3 5 2 p6 := 6 x y + 12 y - x y + 21 x - 9 x y -------------------------------------------------------------------------------- > #term ordering > sort(p6, [x,y], 'plex'); 5 2 3 5 2 4 21 x - x y + 6 x y - 9 x y + 12 y -------------------------------------------------------------------------------- > # pure lexicographic order > > > # total degree order > sort(p6); 5 5 2 3 4 2 6 x y + 21 x - x y + 12 y - 9 x y -------------------------------------------------------------------------------- > # this poly can be considered as a poly in the indeterminate x with coeffs polys in y > collect(p6, x); 5 2 3 5 2 4 21 x - x y + (6 y - 9 y ) x + 12 y > collect(p6, y); 5 5 2 3 4 2 6 x y + 21 x - x y + 12 y - 9 x y -------------------------------------------------------------------------------- > sort(", y); 5 4 2 3 2 5 6 x y + 12 y - x y - 9 x y + 21 x > coeffs("", y, 'powers'); 2 5 6 x, - x , - 9 x, 12, 21 x -------------------------------------------------------------------------------- > powers; 5 3 2 4 y , y , y , y , 1 -------------------------------------------------------------------------------- > # RATIONAL FUNCTIONS in the unknown x ------- f/g and f, g polys in g -------------------------------------------------------------------------------- > f:= x^2 + 3*x + 2; 2 f := x + 3 x + 2 -------------------------------------------------------------------------------- > g:= x^2 + 5*x + 6; 2 g := x + 5 x + 6 -------------------------------------------------------------------------------- > h:= f/g; 2 x + 3 x + 2 h := ------------ 2 x + 5 x + 6 -------------------------------------------------------------------------------- > numer(h); 2 x + 3 x + 2 -------------------------------------------------------------------------------- > normal (h); x + 1 ----- x + 3 -------------------------------------------------------------------------------- > factor(f,x); (x + 2) (x + 1) -------------------------------------------------------------------------------- > factor(g,x); (x + 3) (x + 2) -------------------------------------------------------------------------------- > # So MAPLE does not do simplification automatically of rational expressions into a form where the numer and > # denom are relatively prime. > gcd(f,g); x + 2 -------------------------------------------------------------------------------- > # why not automatically???????? time consuming, try ... the fllowing > > normal( (x^100 - 1) / (x-1)); 76 75 25 24 23 22 21 20 19 18 17 16 15 x + x + x + x + x + x + x + x + x + x + x + x + x 14 13 12 11 10 9 8 7 6 74 73 72 71 + x + x + x + x + x + x + x + x + x + x + x + x + x 70 69 68 67 66 65 64 63 62 61 60 59 + x + x + x + x + x + x + x + x + x + x + x + x 58 57 55 54 53 52 56 51 49 48 47 46 + x + x + x + x + x + x + x + x + x + x + x + x 45 44 43 42 41 40 39 38 37 36 35 34 + x + x + x + x + x + x + x + x + x + x + x + x 33 32 30 29 28 27 26 50 31 99 97 98 + x + x + x + x + x + x + x + x + x + x + x + x 96 95 94 93 92 91 90 89 88 87 86 85 + x + x + x + x + x + x + x + x + x + x + x + x 84 83 82 81 80 79 78 77 2 5 4 3 + x + x + x + x + x + x + x + x + 1 + x + x + x + x + x -------------------------------------------------------------------------------- > p1; 4 3 2 7 x - 2 x + x - 3 x + 6 -------------------------------------------------------------------------------- > readlib(cost)(p1); 4 additions + 9 multiplications -------------------------------------------------------------------------------- > p7:=convert(p1, 'horner'); p7 := 6 + (- 3 + (1 + (7 x - 2) x) x) x -------------------------------------------------------------------------------- > cost(p7); 4 additions + 4 multiplications -------------------------------------------------------------------------------- > # convert the poly for efficiency reasons > > expand(p7); 4 3 2 7 x - 2 x + x - 3 x + 6 > # expansion to the expanded canonical form > p8:= (x+1) ^8; 8 p8 := (x + 1) -------------------------------------------------------------------------------- > expand("); 8 7 6 5 4 3 2 x + 8 x + 28 x + 56 x + 70 x + 56 x + 28 x + 8 x + 1 -------------------------------------------------------------------------------- > # distributes powers over sums > > # however not for negative powers > p9:=(x+1)^(-2); 1 p9 := -------- 2 (x + 1) -------------------------------------------------------------------------------- > expand("); 1 -------- 2 (x + 1) -------------------------------------------------------------------------------- > # polys defined over finite fields -------- e.g Expannsion over Z5 > Expand( (x+1)^5) mod 8; 5 4 3 2 x + 5 x + 2 x + 2 x + 5 x + 1 -------------------------------------------------------------------------------- > # FACTORIZATION of a poly over the rationals in irreducible factors > > # ---over Z2, Z3, Z5 > > Factor(p1) mod 2; 3 x (x + x + 1) -------------------------------------------------------------------------------- > Factor(p1) mod 3; 2 2 x (x + 2) -------------------------------------------------------------------------------- > Factor(p1) mod 5; 3 2 2 (x + 3) (x + x + 1) -------------------------------------------------------------------------------- >