問題解答
問2.56
(define (make-exponentiation base exp) (cond ((= exp 0) 1) ((= exp 1) base) (else (list '** base exp)))) (define (exponentiation? x) (if (eq? (car x) '**) #t #f)) (define (base x) (cadr x)) (define (exponent x) (caddr x)) (define (deriv exp var) (cond ((number? exp) 0) ((variable? exp) (if (same-variable? exp var) 1 0)) ((sum? exp) (make-sum (deriv (addend exp) var) (deriv (augend exp) var))) ((product? exp) (make-sum (make-product (multiplier exp) (deriv (multiplicand exp) var)) (make-product (deriv (multiplier exp) var) (multiplicand exp)))) ((exponentiation? exp) (make-product (make-product (exponent exp) (make-exponentiation (base exp) (make-sum (exponent exp) -1))) (deriv (base exp) var))) (else (error "unknown expression type -- DERIV" exp)))) (deriv '(** x 2) 'x) (deriv '(** x 3) 'x)
問題だけ見るとなんじゃこりゃこんなの解けないよ?って思うんですが、ヒントを元にやってみると簡単で驚きます。こんな簡単な方法で記号微分って表現できるんですね。すごい。