Windows installer: Update help text for the maxima_longnames program.
[maxima/cygwin.git] / tests / rtest9.mac
blob576eeb54e17207f5eb3cbcf50734dfdc59512f87
1 /*************** -*- Mode: MACSYMA; Package: MAXIMA -*-  ******************/
2 /***************************************************************************
3 ***                                                                    *****
4 ***     Copyright (c) 1984 by William Schelter,University of Texas     *****
5 ***     All rights reserved                                            *****
6 ***************************************************************************/
9 (kill(all),
10 declare(l,scalar,[m1,m2,m3],nonscalar));
11 done$
12 expand((1-l*m1) . (1-l*m2) . (1-l*m3));
13 -(l*m3)+(l*m2) . (l*m3)-(l*m2)+(l*m1) . (l*m3)-(l*m1) . (l*m2) . (l*m3)+(l*m1) . (l*m2)-l*m1+1;
14 ev(%,dotscrules);
15 -l*m3+l^2*(m2 . m3)-l*m2+l^2*(m1 . m3)-l^3*(m1 . m2 . m3)+l^2*(m1 . m2)-l*m1+1$
16 rat(%,l);
17 ''(rat(-(m1 . m2 . m3)*l^3+(m2 . m3+m1 . m3+m1 . m2)*l^2+(-m3-m2-m1)*l+1,l))$
18 rat(x^2);
19 ''(rat(x^2))$
20 diff(f(%),x);
21 'diff(f(x^2),x,1)$
22 ((x-2*y)^4/(x^2-4*y^2)^2+1)*(y+a)*(2*y+x)/(4*y^2+x^2);
23 (y+a)*(2*y+x)*((x-2*y)^4/(x^2-4*y^2)^2+1)/(4*y^2+x^2)$
24 rat(%,y,a,x);
25 ''(rat(2*a+2*y)/(x+2*y))$
26 (x+3)^20;
27 (x+3)^20$
28 rat(%);
29 ''(rat(x^20+60*x^19+1710*x^18+30780*x^17+392445*x^16+3767472*x^15+28256040*x^14
30     +169536240*x^13+826489170*x^12+3305956680*x^11+10909657044*x^10
31     +29753610120*x^9+66945622770*x^8+123591918960*x^7+185387878440*x^6
32     +222465454128*x^5+208561363245*x^4+147219785820*x^3+73609892910*x^2
33     +23245229340*x+3486784401))$
34 diff(%,x);
35 ''(rat(20*x^19+1140*x^18+30780*x^17+523260*x^16+6279120*x^15+56512080*x^14
36        +395584560*x^13+2203971120*x^12+9917870040*x^11+36365523480*x^10
37        +109096570440*x^9+267782491080*x^8+535564982160*x^7+865143432720*x^6
38        +1112327270640*x^5+1112327270640*x^4+834245452980*x^3+441659357460*x^2
39        +147219785820*x+23245229340))$
40 factor(%);
41 20*(x+3)^19$
42 ratweight(a,1,b,1);
43 [a,1,b,1]$
44 exp:rat(a+b+1);
45 ''(rat(b+a+1))$
46 %^2;
47 ''(rat(b^2+(2*a+2)*b+a^2+2*a+1))$
48 ev(exp^2,ratwtlvl:1);
49 ''(rat(2*b+2*a+1))$
50 poly:1.0e-20*x^2-5.5*x+5.2e+20;
51 1.0e-20*x^2-5.5*x+5.2e+20$
52 errcatch(ev(%,x = 1.0e+20));
53 [7.0e19];
54 /*  []$ floating point on lispm or tops20 can't do this */
55 ev(horner(poly,x),keepfloat);
56 1.0*((9.9999999999999995*10^-21*x-5.5)*x+5.2*10^+20)$
57 ev(%,x = 1.0e+20);
58 7.0e19;
59 divide(x+y,x-y,x);
60 [1,2*y]$
61 divide(x+y,x-y);
62 [-1,2*x]$
63 content(2*x*y+4*x^2*y^2,y);
64 [2*x,2*x*y^2+y]$
65 resultant(a*y+x^2+1,y^2+x*y+b,x);
66 y^4+a*y^3+(2*b+1)*y^2+b^2$
67 bezout(a*y+x^2+1,y^2+x*y+b,x);
68 matrix([y^2+b,-a*y^2-y],[y,y^2+b])$
69 expand(determinant(%));
70 y^4+a*y^3+2*b*y^2+y^2+b^2$
71 %-expand(resultant(a*y+x^2+1,y^2+x*y+b,x));
73 factor(poly_discriminant((x-a)*(x-b)*(x-c),x));
74 (b-a)^2*(c-a)^2*(c-b)^2$
75 exp:(4*x^3+10*x-11)/(x^5+5);
76 (4*x^3+10*x-11)/(x^5+5)$
77 ev(polymod(%),modulus:3);
78 (x^2+x-1)/(x^4+x^3+x^2+x+1)$
79 ratdiff(exp,x);
80 -((8*x^7+40*x^5-55*x^4-60*x^2-50)/(x^10+10*x^5+25))$
81 10*(1+%i)/(3^(1/3)+%i);
82 10*(%i+1)/(%i+3^(1/3))$
83 ev(ratdisrep(rat(%)),algebraic);
84 (4*3^(2/3)-2*3^(1/3)-4)*%i+2*3^(2/3)+4*3^(1/3)-2$
85 tellrat(a^2+a+1);
86 [a^2+a+1]$
87 a/(sqrt(2)+sqrt(3))+1/(a*sqrt(2)-1);
88 1/(sqrt(2)*a-1)+a/(sqrt(3)+sqrt(2))$
89 ev(ratdisrep(rat(%)),algebraic);
90 ((7*sqrt(3)-10*sqrt(2)+2)*a-2*sqrt(2)-1)/7$
91 tellrat(y^2 = x^2);
92 [y^2-x^2,a^2+a+1]$
93 taylor(1+x,[x,0,3]);
94 1+x$
95 1/%;
96 1-x+x^2-x^3$
97 taylor(1+x+y+z,[x,0,3],[y,1,2],[z,2,1]);
98 4+(z-2)+(y-1)+x$
99 1/%;
100 1/4-(z-2)/16+(-1/16+(z-2)/32)*(y-1)+(1/64-3*(z-2)/256)*(y-1)^2
101  +(-1/16+(z-2)/32+(1/32-3*(z-2)/128)*(y-1)+(-3/256+3*(z-2)/256)*(y-1)^2)*x
102  +(1/64-3*(z-2)/256+(-3/256+3*(z-2)/256)*(y-1)+(3/512-15*(z-2)/2048)*(y-1)^2)
103   *x^2
104  +(-1/256+(z-2)/256+(1/256-5*(z-2)/1024)*(y-1)
105                    +(-5/2048+15*(z-2)/4096)*(y-1)^2)
106   *x^3$
107 taylor(1+x+y+z,[x,0,3],[y,0,3],[z,0,3]);
108 1+z+y+x$
109 1/%;
110 1-z+z^2-z^3+(-1+2*z-3*z^2+4*z^3)*y+(1-3*z+6*z^2-10*z^3)*y^2
111            +(-1+4*z-10*z^2+20*z^3)*y^3
112  +(-1+2*z-3*z^2+4*z^3+(2-6*z+12*z^2-20*z^3)*y+(-3+12*z-30*z^2+60*z^3)*y^2
113                      +(4-20*z+60*z^2-140*z^3)*y^3)
114   *x
115  +(1-3*z+6*z^2-10*z^3+(-3+12*z-30*z^2+60*z^3)*y+(6-30*z+90*z^2-210*z^3)*y^2
116                      +(-10+60*z-210*z^2+560*z^3)*y^3)
117   *x^2
118  +(-1+4*z-10*z^2+20*z^3+(4-20*z+60*z^2-140*z^3)*y
119                        +(-10+60*z-210*z^2+560*z^3)*y^2
120                        +(20-140*z+560*z^2-1680*z^3)*y^3)
121   *x^3$
122 ev(sum(i^2+2^i,i,0,n),simpsum);
123 2^(n+1)+(2*n^3+3*n^2+n)/6-1$
124 ev(sum(3^-i,i,1,inf),simpsum);
125 1/2$
126 ev(sum(i^2,i,1,4)*sum(1/i^2,i,1,inf),simpsum);
127 5*%pi^2$
128 sum(i^2,i,1,5);
130 product(x+i*(i+1)/2,i,1,4);
131 (x+1)*(x+3)*(x+6)*(x+10)$
132 limit(x*log(x),x,0,plus);
134 limit((1+x)^(1/x),x,0);
136 limit(%e^x/x,x,inf);
137 inf$
138 limit(sin(1/x),x,0);
139 ind$
140 nusum(n*n!,n,0,n);
141 (n+1)!-1$
142 map('ratsimp, nusum(n^4*4^n/binomial(2*n,n),n,0,n));
143 ((126*n^5+350*n^4+260*n^3-8*n^2-38*n+6)*4^n)/(693*binomial(2*n,n))-2/231$
144 unsum(%,n);
145 n^4*4^n/binomial(2*n,n)$
146 unsum(product(i^2,i,1,n),n);
147 ('product(i^2,i,1,n-1))*(n-1)*(n+1)$
148 nusum(%,n,1,n);
149 'product(i^2,i,1,n)-1$
150 funcsolve((n+1)*f(n)-(n+3)*f(n+1)/(n+1) = (n-1)/(n+2),f(n));
151 f(n) = n/((n+1)*(n+2))$
152 (untellrat(a),'done);
153 done$
154 residue(s/(s^2+a^2),s,a*%i);
155 1/2$
156 residue(sin(a*x)/x**4,x,0);
157 -a^3/6$
158 taylor(sqrt(1+a*x+sin(x)),x,0,3);
159 1+(a+1)*x/2 - ((a^2+2*a+1)*x^2/8) + (3*a^3+9*a^2+9*a-1)*x^3/48$
161 %^2;
162 1+(a+1)*x-x^3/6$
163 taylor(sqrt(1+x),x,0,5);
164 1+x/2-x^2/8+x^3/16-5*x^4/128+7*x^5/256$
165 %^2;
166 1+x$
168 /* The following test does not work as expected.
169  * The product does not preserve the floating point number.
170  * Therefore the following taylor expansion gives a result
171  * in terms of rational numbers. We change the expected
172  * result accordingly.
173  * After revision 1.36 of asum.lisp it works as expected (DK 02/2010).
174  */
175 keepfloat:true;
176 true;
177 product((x^i+1)^2.5,i,1,inf)/(x^2+1);
178 ('product((x^i+1)^2.5,i,1,inf))/(x^2+1)$
179 ratdisrep(taylor(%,x,0,3));
180 1+2.5*x+3.375*x^2+6.5625*x^3;
181 keepfloat:false;
182 false;
184 taylor(1/log(1+x),x,0,3);
185 1/x+1/2-x/12+x^2/24-19*x^3/720$
186 taylor(cos(x)-sec(x),x,0,5);
187 -x^2-x^4/6$
188 taylor((cos(x)-sec(x))^3,x,0,5);
190 taylor((cos(x)-sec(x))^-3,x,0,5);
191 -1/x^6+1/(2*x^4)+11/(120*x^2)-347/15120-6767*x^2/604800-15377*x^4/7983360$
193 taylor(sqrt(1-k^2*sin(x)^2),x,0,6);
194 1-(k^2*x^2/2)-((3*k^4-4*k^2)*x^4/24)-((45*k^6-60*k^4+16*k^2)*x^6/720)$
195 taylor((1+x)^n,x,0,4);
196 1+n*x+(n^2-n)*x^2/2+(n^3-3*n^2+2*n)*x^3/6+(n^4-6*n^3+11*n^2-6*n)*x^4/24$
198 taylor(sin(x+y),x,0,3,y,0,3);
199 -(y^3/6) + x^2*(y^3/12-(y/2))+x^3*(y^2/12-1/6)+x*(1-y^2/2)+y$
201 taylor(sin(x+y),[x,y],0,3);
202 -((y^3+3*x*y^2+3*x^2*y+x^3)/6) + y + x$
204 taylor(1/sin(x+y),x,0,3,y,0,3);
205 1/y+y/6+(-1/y^2+1/6)*x+(+1/y^3)*x^2+(+(-1/y^4))*x^3$
207 /* additional tests for integer modulus, adapted from email 2008-01-27 */
209 (modulus : false,
210  m : matrix ([15, 2, 7], [8, 10, 23], [0, 2, 8]),
211  determinant(m)); /* calculate over Z */
212 494;
214 (modulus : 23, rm : rat(m));
215 ''(rat (matrix ([-8, 2, 7], [8, 10, 0], [0, 2, 8])));
217 determinant(rm); /* calculate over Z23 */
218 ''(rat(11));
220 rm^^-1; /* inverse over Z23 */
221 ''(rat (matrix ([1, 4, 2], [-10, -10, 3], [-9, -9, 8])));
223 rm . rm^^-1;
224 ''(rat (matrix ([1, 0, 0], [0, 1, 0], [0, 0, 1])));
226 modulus : false;
227 false;
229 /* [ 2604950 ] rats with keepfloat */
230 ratsimp ((a*b - 0.5*a*(b - c))/a), keepfloat;
231 0.5*c + 0.5*b;
233 /* SF bug #2982: "Display of taylor series in wrong order" */
235 string (taylor(1/(1-x), x, 0, 10));
236 "1+x+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9+x^10";
238 args (taylor(1/(1-x), x, 0, 10));
239 [1, x, x^2, x^3, x^4, x^5, x^6, x^7, x^8, x^9, x^10];
241 string (taylor(sin(x),x,0,4));
242 "x-x^3/6";
244 args (taylor(sin(x),x,0,4));
245 [x, -x^3/6];