;;;;; ;;;;; ;;;;; Integration ;;;;; ;;;;; (define $Sd (lambda [$x $f] (match f math-expr {[?simple-term? (match [x f] [symbol-expr symbol-expr] {[[ ] (* f x)] [[ ] (* (/ 1 2) x^2)] [[_ (,exp ,x)] (exp x)] [[_ (,cos ,x)] (sin x)] [[_ (,sin ,x)] (* -1 (cos x))] [[_ (,log ,x)] (multSd x 1 (log x))] [[_ ($f $y)] (substitute {[tmpvar y]} (Sd tmpvar (* (f tmpvar) (d/d (inverse tmpvar y x) tmpvar))))] [[_ (,** $a ,x)] (/ (** a x) (log a))] [[_ (,** $a $y)] (substitute {[tmpvar y]} (Sd tmpvar (* (** a tmpvar) (d/d (inverse tmpvar y x) tmpvar))))] [[_ _] (Sd' x f)] })] [?term? (match f term-expr {[> (let {[$b (foldl *' a (map 2#(**' %1 %2) ts))]} (if (contain-symbol? x b) (Sd' x f) (/ (* b (** x (+ n 1))) (+ n 1))))] [ (let {[[$fxs $cs] (partition (contain-symbol? x $) (from-assoc ts))]} (match fxs (list math-expr) {[ (* f x)] [> (* a (Sd x fx) (foldl *' 1 cs))] [_ (Sd' x f)]}))]})] [?polynomial? (match f poly-expr {[ (sum (map (Sd x $) ts))]})] [_ (match f math-expr {[
(match (coefficients p2 x) (list math-expr) {[> (/ (Sd x p1) a)] [_ (Sd' x f)]})]})] }))) (define $multSd (lambda [$x $f $g] (let {[$F (Sd x f)]} (- (* F g) (Sd x (* F (d/d g x))))))) (define $Sd' (lambda [$x $f] (to-math-expr ))) (define $dSd (lambda [$x $a $b $f] (let {[$F (Sd x f)]} (- (substitute {[x b]} F) (substitute {[x a]} F)))))