1 /* -*- Mode: Macsyma -*- */
3 /*************************************************************************************
4 Demo of Coeflist package.
5 This package defines tools for extracting coefficients of polynomials,
6 trigonometric sums and power and Taylor series
7 *************************************************************************************/
9 /* COEFFS: Coefficients of Polynomials */
11 coeffs(a+b*x^2*y+c*x^3*y^2+d*x^4,x);
13 ptest : (a+b*x^2*y+c*x^3*y^2+d*x^4)^2 + (d*y+c*x^2+a*x^4)^2$
14 ctest:coeffs(ptest,x);
17 /* GET_COEF finds a particular coefficient. UNCOEF rebuilds the result. */
19 ratsimp(ptest-uncoef(ctest));
21 /* Stretching the definition of Polynomials: */
22 coeffs(x^m*(x+x^2+x^m)+x^(2*m),x);
24 nptest:(a+b*sin(x)*x^2)^3$
27 /* Partitioning a polynomial: */
28 partition_poly(ptest,'evenp,x);
30 /* TRIG_COEFFS: Trigonometric series */
31 trig_coeffs(a*cos(x+y)+b*sin(x+2*y),x);
33 ftest : (a*cos(x+y)+b*sin(x+2*y))^2+(a*cos(x-y)+b*cos(2*x+3*y))^2$
35 trig_coeffs(ftest,x,y);
37 /* SERIES_COEFFS & TAYLOR_COEFFS: Power Series & Taylor series*/
38 series_coeffs(ptest,x,4);
39 Taylor_coeffs(ptest,x,4);
40 /* Notice Series only expands over arithmetic: */
41 series_coeffs(nptest,x,4);
42 Taylor_coeffs(nptest,x,4);
44 /* Alternative specification of variables */
45 sqrtp(s) := not(atom(s)) and op(s)='sqrt$
46 coeffs(a+sqrt(1+b)+c,match('sqrtp));
47 coeffs(a*log(x)+log(y)*log(x),operator(log));
49 /* Additional Utilities: */
50 matching_parts(a+sqrt(1+b)+c,'sqrtp);
51 function_calls(a*log(x)+log(y)*log(x),log);
52 function_arguments(a*log(x)+log(y)*log(x),log);
55 (remvalue(ptest,ctest,nptest,ftest),remfunction(sqrtp))$