share/tensor/itensor.lisp: make X and D shared lexical variables for the functions...
[maxima.git] / share / pdiff / rtest_pdiff.mac
blob7ccf86addb5b08a034795685b6f5b3af2fd82c46
1 (load(pdiff),kill(all), 0);
2 0$ 
4 pderivop(f);
5 f$
7 pderivop(f,0);
8 f$
10 pderivop(42,0)(x);
11 42$
13 pderivop(42,1)(x);
16 op(pderivop(%pi));
17 lambda$
19 pderivop(%pi)(a,b,2);
20 %pi$
22 pderivop(12.1,1)(x);
25 pderivop('log,1)(x);
26 1/x$
28 pderivop('abs,1)(x);
29 x/abs(x)$
31 pderivop('acos,2)(x);
32 ''(diff(acos(x),x,2))$
34 pderivop(bessel_i,0,1)(n,x);
35 ''(diff(bessel_i(n,x),x))$
37 pderivop(bessel_j,0,1)(n,x);
38 ''(diff(bessel_j(n,x),x))$
40 pderivop(bessel_k,0,1)(n,x);
41 ''(diff(bessel_k(n,x),x))$
43 pderivop(bessel_y,0,1)(n,x);
44 ''(diff(bessel_y(n,x),x))$
46 makelist(pderivop('sqrt,k)(x),k,0,5);
47 ''(makelist(diff(sqrt(x),x,k),k,0,5))$
49 pderivop('erf,1)(x);
50 ''(diff(erf(x),x))$
52 [pderivop("^",1,0)(a,b),pderivop("^",0,1)(a,b), pderivop("^",1,1)(a,b)];
53 ''([diff(a^b,a), diff(a^b,b),diff(a^b,a,1,b,1)])$
55 [pderivop("^^",1,0)(a,b),pderivop("^^",0,1)(a,b), pderivop("^^",1,1)(a,b)];
56 ''([diff(a^^b,a), diff(a^^b,b),diff(a^^b,a,1,b,1)])$
58 [pderivop(".",1,0)(a,b),pderivop(".",0,1)(a,b), pderivop(".",1,1)(a,b)];
59 ''([diff(a.b,a), diff(a.b,b),diff(a.b,a,1,b,1)])$
61 is(op(pderivop(lambda([[x]], x),1)) = 'pderivop);
62 true$
64 (gradef(ff(a,b),a+b,a-b), [pderivop(ff,1,0)(x,y), pderivop(ff,0,1)(x,y), pderivop(ff,1,1)(x,y)]);
65 [y+x,x-y,1]$
67 errcatch(pderivop(ff,1));
68 []$
70 (remove(ff,gradef),0);
73 (gradef(ff(a), ff(a-1)), [pderivop(ff)(x), pderivop(ff,1)(x), pderivop(ff,2)(x)]);
74 [ff(x),ff(x-1),ff(x-2)]$
76 (remove(ff,gradef),0);
79 convert_to_diff(pderivop(f[5],1,1)(x,y));
80 ''(diff(f[5](x,y),x,1,y,1))$
82 errcatch(pderivop(f,1,2)(x));
83 []$
85 errcatch(pderivop(f,1,2)());
86 []$
88 errcatch(pderivop(f,1,2)(x,x,x));
89 []$
91 (pderivop(f,x), subst(x = 5,%%));
92 pderivop(f,5)$
94 (pderivop(f,x,y), ratsubst(5,x,%%), ratsubst(7,y,%%));
95 pderivop(f,5,7)$
97 (clear_rules(), tellsimpafter(pderivop(f,1)(a),1), tellsimpafter(pderivop(f,2)(a),1),0);
100 subst(x=a, diff(f(x),x,2) + diff(f(x),x));
103 (clear_rules(),0);
106 (commute_partial_derivatives : true,0);
109 pderivop(pderivop(f,1,0),0,1) - pderivop(f,1,1);
112 (commute_partial_derivatives : false,0);
115 is(pderivop(pderivop(f,1,0),0,1) = pderivop(f,1,1));
116 false$
118 (reset(commute_partial_derivatives),0);
121 pderivop(lambda([s], s^2),1)(x);
122 2 *x$
124 pderivop(lambda([s], 42),1)(x);
127 pderivop(lambda([a,b], f(a,b)))(x,y);
128 f(x,y)$
130 pderivop(lambda([a,b], f(a,b)),1,0)(x,y) - diff(f(x,y),x);
133 pderivop(lambda([a,b], f(a,b)),1,1)(x,y) - diff(f(x,y),x,1,y,1);
136 (diff(f(x,y),x,1,y,1), subst([x=1,y=2],%%), %% - at(diff(f(x,y),x,1,y,1),[x=1,y=2]));
139 (f(x) := x^3, g : pderivop(f,1), [op(g), g(6)]);
140 [lambda,108]$
142 (remfunction(f), remvalue(g),0);
145 (commute_partial_derivatives : true, pderivop(pderivop(f,0,1),1,0));
146 pderivop(f,1,1)$
148 /* examples from pdiff-doc.pdf */
150 ratdisrep(taylor(f(x+x^2),x,0,2));
151 ''(f(0) + at(diff(f(x + x^2),x),x = 0) * x + at(diff(f(x + x^2),x,2),x = 0) * x^2/2)$
153 (f(x - c*t) + f(x + c * t), expand(diff(%%,t,2) - c^2 * diff(%%,x,2)));
156 (diff(f(x,y),x,1,y,1), subst(p(s),y, %%), 
157   convert_to_diff(%%), ev(%%, 'diff, 'at));
158 ''(subst(p(s),y, diff(f(x,y),x,1,y,1)))$
160 (tellsimpafter(pderivop(f,1)(1),1), 
161   tellsimpafter(pderivop(f,2)(1),2), 
162   diff(f(x),x,2) + diff(f(x),x),
163   subst(1,x,%%));
166 (clear_rules(),0);
169 (tellsimpafter(pderivop(f,1,0)(0,0),a),
170   tellsimpafter(pderivop(f,0,1)(0,0),b),
171   sublis([x = 0, y = 0], diff(f(x,y),x) + diff(f(x,y),y)));
172 a+b$
174 (clear_rules(),0);
177 (commute_partial_derivatives : true, pderivop(pderivop(f,3,4),1,2));
178 pderivop(f,4,6)$
180 (pderivop(f,1), apply(%%,[z]));
181 ''(diff(f(z),z))$
183 (f(x) := x^2, pderivop(f,2), apply(%%,[10]));
186 (remfunction(f),0);
189 (pderivop(lambda([x],x^2),1), op(%%));
190 lambda$
192 (de : 4*x^2 * 'diff(y,x,2) + 4*x * 'diff(y,x,1) + (x-1)*y = 0,
193  de : subst(g(x^n),y,de),
194  de : ev(de, diff),
195  de : radcan(subst(x^(1/n),x, de)),
196  de : block ([ctxt:newcontext(), foo], assume(x >= 0), foo:subst(1/2,n, de), killcontext(ctxt), foo),
197  convert_to_diff(de)),logexpand;
198 x^2 * 'diff(g(x),x,2)+x*'diff(g(x),x,1)+(x^2-1)*g(x)=0$
200 (remvalue(de),0);
203 /* end of examples from pdiff-doc.pdf */
205 convert_to_diff([-1,42, 123.0, -7.8b0, x, cos(q), a+b, [], a # b, f(x)]);
206 [-1,42, 123.0, -7.8b0, x, cos(q), a+b, [], a # b, f(x)]$
208 convert_to_diff(f[5](x));
209 f[5](x)$
211 convert_to_diff(f[g[5]](x));
212 f[g[5]](x)$
214 convert_to_diff(pderviop(f,4,5));
215 pderviop(f,4,5)$
217 convert_to_diff(diff(f(x),x));
218 'diff(f(x),x,1)$
220 convert_to_diff(diff(f(x),x,5));
221 'diff(f(x),x,5)$
223 convert_to_diff(42 + diff(f(x),x,5) + diff(g(x),x));
224 42 + 'diff(f(x),x,5) + 'diff(g(x),x)$
226 (diff(f(x),x), subst(x=10,%%), convert_to_diff(%%), ev(%%, f(x) := x^7, 'diff, 'at));
227 7000000$
229 (diff(f(x),x), subst(x=a,%%), convert_to_diff(%%), ev(%%, f(x) := x^7, 'diff, 'at));
230 7 * a^6$
232 (diff(f(x,y),x,1,y,1), subst([x=a,y=b], %%), convert_to_diff(%%), ev(%%, f(x,y) := x^2 * y^2, 'diff, 'at));
233 4*a*b$
235 (clear_rules(),0);
238 (tellsimpafter(f(0),6),tellsimpafter(''(subst(x=0, diff(f(x),x))), 28), taylor(f(x),x,0,1));
239 6+28*x$
241 (clear_rules(),0);
244 /*chain rule tests */
245 is(equal(diff(f(g(x)),x), diff(g(x),x) * pderivop(f,1)(g(x))));
246 true$
248 is(equal(diff(f(g(x), h(x)),x), diff(g(x),x) * pderivop(f,1,0)(g(x), h(x)) + 
249     diff(h(x),x) * pderivop(f,0,1)(g(x), h(x))));
250 true$
252 (diff(f(x^3),x), convert_to_diff(%%), ev(%%, f(x) := x^5, diff, at));
253 ''(diff((x^5)^3,x))$
255 (diff(f(x^2,x*y),x), subst(x = 1, %%), ev(%%, f(x,y) := x^2 * y^2, diff, at));
256 ''(subst(x=1, diff((x^2)^2 * (x*y)^2,x)))$
258 /* subscripted functions */
260 pderivop(f[2]);
261 f[2]$
263 pderivop(f[2],0);
264 f[2]$
266 (pderivop(f[2],1), %%(x), convert_to_diff(%%));
267 'diff(f[2](x),x,1)$
269 (pderivop(f[x],1), %%(x), convert_to_diff(%%));
270 'diff(f[x](x),x,1)$
272 (pderivop(f[2],1,1), %%(x,y), convert_to_diff(%%));
273 'diff(f[2](x,y),x,1,y,1)$
275 (pderivop(f,1,1), %%(x,y), subst(y=10,%%), convert_to_diff(%%), ev(%%, f(x,y) := x^2 * y^2, diff, at));
276 ''(subst(y=10, diff(x^2*y^2,x,1,y,1)))$
278 [pderivop(%pi)(), pderivop(%pi)(a), pderivop(%pi)(a,b,c)];
279 [%pi, %pi, %pi]$
281 (diff(f(x^2),x), ev(%%, f = sin));
282 2*x*cos(x^2)$
284 /* check that the default for use_pdiff is false */
285 (reset(use_pdiff),0);
288 use_pdiff;
289 false$