Examples cleanup
[maxima.git] / tests / rtest5.mac
blobc721a6ee95624b16641521ffd7bc8d6b31fcd1ff
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 done$
11 partition(2*a*x*f(x),x);
12 [2*a,x*f(x)]$
13 partition(a+b,x);
14 [b+a,0]$
15 2*(a*log(x)+2*a*log(y));
16 2*(2*a*log(y)+a*log(x))$
17 logcontract(%);
18 a*log(x^2*y^4)$
19 ratsimp(logcontract(log(sqrt(x+1)+sqrt(x))+log(sqrt(x+1)-sqrt(x))));
22 /* Two examples from Bug report ID: 947808 - logcontract and ratfac */
23 logexpand:false; /* To prevent simplification of the expected result */
24 false;
25 logcontract(2*log(x+1)+1);
26 log((x+1)^2)+1;
27 logexpand:true;
28 true;
29 logcontract(1000*log(x+1)+log(x));
30 log(x*(x+1)^1000)$
32 rootsconmode:false;
33 false$
35 rootscontract(x^(1/2)*y^(3/2));
36 sqrt(x*y^3)$
38 rootscontract(x^(1/2)*y^(1/4));
39 sqrt(x)*y^(1/4)$
41 rootsconmode:true;
42 true$
44 expand(rootscontract(x^(1/2)*y^(1/4)) - sqrt(x*sqrt(y)),0,0);
47 expand(rootscontract(x^(1/2)*y^(1/3)) - sqrt(x)*y^(1/3),0,0);
50 rootsconmode:all;
51 all$
52 expand(rootscontract(x^(1/2)*y^(1/4)) - (x^2*y)^(1/4),0,0);
55 expand(rootscontract(x^(1/2)*y^(1/3)) -(x^3*y^2)^(1/6),0,0);
58 rootsconmode:false;
59 false$
60 rootscontract(sqrt(sqrt(x+1)+sqrt(x))*sqrt(sqrt(x+1)-sqrt(x)));
62 rootsconmode:true;
63 true$
65 rootscontract(sqrt(sqrt(5)+5)-5^(1/4)*sqrt(sqrt(5)+1));
68 kill(f,g,h,x,y);
69 done$
70 diff(sin(x)+x^3+2*x^2,x);
71 cos(x)+3*x^2+4*x$
72 diff(sin(x)*cos(x),x);
73 cos(x)^2-sin(x)^2$
74 diff(sin(x)*cos(x),x,2);
75 -4*cos(x)*sin(x)$
76 derivabbrev:true;
77 true$
78 diff(exp(f(x)),x,2);
79 %e^f(x)*'diff(f(x),x,2)+%e^f(x)*('diff(f(x),x,1))^2$
80 'integrate(f(x,y),y,g(x),h(x));
81 'integrate(f(x,y),y,g(x),h(x))$
82 diff(%,x);
83 'integrate('diff(f(x,y),x,1),y,g(x),h(x))
84  +f(x,h(x))*'diff(h(x),x,1)-f(x,g(x))*'diff(g(x),x,1)$
85 kill(a,x,f,y,t);
86 done$
88 /* -----------------------------------------------------------------------------
89  * Examples for dependencies
90  * -------------------------------------------------------------------------- */
91 depends(a,x);
92 [a(x)]$
93 diff(a . a,x);
94 'diff(a,x,1) . a+a . 'diff(a,x,1)$
95 depends(f,[x,y],[x,y],t);
96 [f(x,y),x(t),y(t)]$
97 diff(f,t);
98 'diff(f,y,1)*'diff(y,t,1)+'diff(f,x,1)*'diff(x,t,1)$
99 depends(y,x);
100 [y(x)]$
101 kill(f,g,j);
102 done$
104 /* More examples with subscribted variables */
106 depends(g,f,f,[x[1],x[2],x[3]],x,t);
107 [g(f),f(x[1],x[2],x[3]),x(t)]$
108 diff(g,f);
109 'diff(g,f,1)$
110 diff(f,x[1]);
111 'diff(f,x[1],1)$
112 diff(f,x[1],2);
113 'diff(f,x[1],2)$
114 diff(x[1],t);
115 'diff(x[1],t,1)$
116 diff(f,x[1],1,x[2],1,x[3],1);
117 'diff(f,x[1],1,x[2],1,x[3],1)$
118 diff(f,t);
119 'diff(x[3],t,1)*'diff(f,x[3],1)+'diff(x[2],t,1)*'diff(f,x[2],1)
120                                +'diff(x[1],t,1)*'diff(f,x[1],1)$
121 diff(g,t);
122 ('diff(x[3],t,1)*'diff(f,x[3],1)+'diff(x[2],t,1)*'diff(f,x[2],1)
123                                 +'diff(x[1],t,1)*'diff(f,x[1],1))
124  *'diff(g,f,1)$
125 kill(g,f,x);
126 done;
128 /* The subscript is not differentiated, it is a constant */
130 depends(f,x[a],x,t,t,a);
131 [f(x[a]),x(t),t(a)]$
132 diff(f,x[a]);
133 'diff(f,x[a],1)$
134 diff(f,t);
135 'diff(x[a],t,1)*'diff(f,x[a],1)$
136 diff(f,a);
137 'diff(x[a],t,1)*'diff(f,x[a],1)*'diff(t,a,1)$
138 kill(f,x,t);
139 done;
141 /* Maxima has not a problem with circular defined dependencies */
143 depends(f,x,x,t,t,f);
144 [f(x),x(t),t(f)]$
145 diff(f,x);
146 'diff(f,x,1)$
147 diff(f,t);
148 'diff(f,x,1)*'diff(x,t,1)$
149 diff(t,f);
150 'diff(t,f,1)$
151 diff(t,x);
152 'diff(f,x,1)*'diff(t,f,1)$
153 kill(f,x,t);
154 done;
155 /* -------------------------------------------------------------------------- */
157 gradef(f(x,y),x^2,g(x,y));
158 f(x,y)$
159 diff(f(x,y),x);
160 g(x,y)*'diff(y,x,1)+x^2$
161 gradef(j(n,z),'diff(j(n,z),n),j(n-1,z)-n/z*j(n,z));
162 j(n,z)$
163 ratsimp(diff(j(2,x),x,2));
164 (j(0,x)*x^2-3*j(1,x)*x+6*j(2,x))/x^2$
165 test(f):=block([u],u:integrate(f,x),ratsimp(f-diff(u,x)));
166 test(f):=block([u],u:integrate(f,x),ratsimp(f-diff(u,x)))$
167 test(sin(x));
169 test(1/(1+x));
171 test(1/(1+x^2));
173 integrate(sin(x)^3,x);
174 cos(x)^3/3-cos(x)$
175 kill(q);
176 done$
177 integrate(%e^x/(%e^x+2),x);
178 log(%e^x+2)$
179 integrate(1/(x*log(x)),x);
180 log(log(x))$
181 integrate(sin(2*x+3),x);
182 -cos(2*x+3)/2$
184 /* Correct simplification after change to risch.lisp revision 1.17 */
186 integrate(%e^x*erf(x),x);
187 %e^x*erf(x)-%e^(1/4)*erf(x-1/2)$
189 integrate(x/(x^3+1),x);
190 log(x^2-x+1)/6+atan((2*x-1)/sqrt(3))/sqrt(3)-log(x+1)/3$
191 diff(%,x);
192 2/(3*((2*x-1)^2/3+1))+(2*x-1)/(6*(x^2-x+1))-1/(3*(x+1))$
193 ratsimp(%);
194 x/(x^3+1)$