diff_version::"0.1",diff_date::"07.11.2007"; cti::0; *** only for debugging powersymb::string2symbol "expt"; termless(st,tt):: with s :: if listq st and length st = 3 and first st === powersymb then second st else st endif, t :: if listq tt and length tt = 3 and first tt === powersymb then second tt else tt endif do *** displayln("termless - s t :",s," ",t), (s~=0 and not t~=0) or (s~=1 and not t~=0 and not t~=1) or (integerq s and integerq t and abs s < abs t) or (integerq s and integerq t and abs s=abs t and s3 and first t in {plussymb,timessymb} then *** displayln("inner termsort: ",t), t:=termsorti flatten {first t,second t,termsort cons(first t,rest rest t)} endif, *** displayln("termsort special af: ",t), t endwith else s endif; removedollar::schemesymbol "removedollar"; subsex1(fo,re,ex):: begin displayln("subssex1: ex is ",ex), if listq ex and not nullq ex and first ex === 'DIFF then ex else subsex(fo,re,ex) endif end; diff(symfun,+var):: with funarg :: nullq var, v :: if funarg then first second symfun else first var endif, expr :: if funarg then subsex(v,'$,third symfun) else subsex(v,'$,symfun) endif, res :: #f, t :: #f do dif(ex) :: begin *** displayln("dif:",ex), match ex pattern $ then 1 pattern _N then 0 pattern _R then 0 pattern _N*$ then N pattern -_N*$ then -N pattern _N*$+_N1 then N pattern _N*$+_R then N pattern _N+$ then 1 pattern $+_N then 1 pattern _N+_R then 0 pattern _R+_N then 0 pattern _N-_R then 0 pattern _R-_N then 0 pattern $*_N then N pattern $^_Z then 0 pattern $^_U then 1 pattern $^_N then quasi %N*$^%(N-1) pattern _a^_N then quasi %N*(%a)^%(N-1)*%dif(a) pattern _N+_a then dif(a) pattern _a+_N then dif(a) pattern _a+_b then quasi %dif(a) + %dif (b) pattern _a-_b then quasi %dif(a)-%dif(b) pattern _a+_b+___ then quasi %dif(a)+%dif(append(list(plussymb),b)) pattern _a*_b then quasi %dif(a) * %b + %a*%dif(b) pattern _a*_b*___ then quasi %dif(a)*%cons(timessymb,b) +%a*%dif(cons(timessymb,b)) pattern 1/$ then quote -$^(-2) pattern 1/_a then quasi (-%dif(a))/%a^2 pattern sin($) then 'cos($) pattern sqrt($) then quote 0.5*$^(-0.5) pattern ln($) then quasi 1/$ pattern cos($) then quasi -sin($) pattern exp($) then quasi exp($) pattern tan($) then quasi 1/cos($)^2 pattern atan($) then quasi 1/(1+$^2) pattern _R^$ then quasi ln(%R)*(%R)^$ pattern _N^$ then quasi %ln(N)*%N^$ pattern _a^_b then dif(quasi exp(%b*ln(%a))) pattern -_T then quasi - %dif(T) pattern _R(_T) then list(timessymb,subsex('$,T,dif(list(R,'$))),dif(T)) else t:= if listq ex and length ex = 2 and symbolq first ex then {{'D,first ex},'$} else {'D,{string2symbol "lambda",{'$$},subsex('$,'$$,ex)},'$} endif, *** displayln(">>>",t,"<<<"), t endmatch end, res:=termsort subsex('$,v,flatten(dif(termsort expr))), if funarg then list(string2symbol "lambda",list v,res) else res endif endwith; displayln("--- esl file \"diff\" (Version ",diff_version,", ",diff_date,")");