Restore previous display for sum and product signs in ASCII art mode;
[maxima.git] / archive / share / trash / gendif.mac
blob0a6aa14da007321294cd5e77ea7ac73bf498749f
1 /* general differentiation simplification: diff(e,x,n), for
2 n symbolic  */
3 gendiff(e,x,n):= if numberp(n)then if integerp(n) then diff(e,x,n) else (print ("fractional derivatives not supported"),'diff(e,x,n)) 
4 else if freeof(x,e) then 0
5  else if atom(e) then 'diff(e,x,n)
6  else if inpart(e,0)="+" then map(lambda([u],gendiff(u,x,n)),e)
7  else if inpart(e,0)="*" then gendiffprod(inpart(e,1),e/inpart(e,1),x,n)
8  else if inpart(e,0)="^" then gendiffpow(inpart(e,1),inpart(e,2),x,n)
9  else 'diff(e,x,n)$
11 /* diff of x1^x2 wrt x n times */
12 gendiffpow(x1,x2,x,n):=
13 if x1=x then genfact(x2,n,1)*x^(x2-n)
14 else 
15  if (x1=%e)and freeof(x,diff(x2,x)) then diff(x2,x)^n*%e^x2 
16  else 
17  if integerp(x2) and x2>1 then gendiff(ratexpand(x2),x,n) else 
18  'diff(x1^x2,x,n)$
20 /* replaced by 3-arg version
21 GENDIFF1(Q):=GENDIFF(Q,X,N)$
24 /* a first approach */
25 gendiffprod(a,b,x,n):=if freeof(x,a)then a*gendiff(b,x,n) else
26  if freeof(x,b) then b*gendiff(a,x,n) else
27 (block([q,r,i],
28 q:gendiff(a,x,i),
29 r:gendiff(b,x,n-i),
30 return(sum(binomial(n,i)*q*r,i,0,n))))$