egison-3.6.1: lib/math/analysis/integral.egi
;;;;;
;;;;;
;;;;; Integration
;;;;;
;;;;;
(define $Sd
(lambda [$x $f]
(match f math-expr
{; symbols
[,x (* (/ 1 2) x^2)]
[<symbol _> (* f x)]
; function application
[(,exp ,x) (exp x)]
[(,cos ,x) (sin x)]
[(,sin ,x) (* -1 (cos x))]
[(,log ,x) (multSd x 1 (log x))]
[(,** $a ,x) (/ (** a x) (log a))]
[(,** $a $y) (with-symbols {t}
(substitute {[t y]} (Sd t (* (** a t) (d/d (inverse t y x) t)))))]
[(,Sd $y $g) (`Sd x (`Sd y g))]
[($f $y) (with-symbols {t}
(substitute {[t y]} (Sd t (* (f t) (d/d (inverse t y x) t)))))]
; term (constant)
[,0 0]
[<term $c <nil>> (* c x)]
; term (multiplication)
[<mult $a <ncons $n ,x $r>>
(if (contain-symbol? x r)
(`Sd x f)
(* (/ a (+ n 1)) (** x (+ n 1)) r))]
; polynomial
[<poly $ts> (sum (map (Sd x $) ts))]
; quotient
[<div <plus $ts> $p2>
(sum (map 1#(Sd x (/ %1 p2)) ts))]
[<div $p1 $p2>
(if (contain-symbol? x p2)
(`Sd x f)
(/ (Sd x p1) p2))]
})))
(define $multSd
(lambda [$x $f $g]
(let {[$F (Sd x f)]}
(- (* F g)
(Sd x (* F (d/d g x)))))))
(define $dSd
(lambda [$x $a $b $f]
(let {[$F (Sd x f)]}
(- (substitute {[x b]} F)
(substitute {[x a]} F)))))