1 / 8

CONSTANTS: Type: <const> Predicate: const? represented concretely as <number>s VARIABLES:

D x (c) = 0 D x (x) = 1 D x (y) = 0 for y an independent variable D x (u+v) = D x (u) + D x (v) D x (uv) = u D x (v) + v D x (u) D x (u n ) = nu n-1 D x (u) for n > 0. CONSTANTS: Type: <const> Predicate: const? represented concretely as <number>s VARIABLES: Type: <var>

Download Presentation

CONSTANTS: Type: <const> Predicate: const? represented concretely as <number>s VARIABLES:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dx(c) = 0Dx(x) = 1Dx(y) = 0 for y an independent variableDx(u+v) = Dx(u) + Dx(v)Dx(uv) = u Dx(v) + v Dx(u)Dx(un) = nun-1 Dx(u) for n > 0

  2. CONSTANTS: • Type: <const> • Predicate: const? • represented concretely as <number>s • VARIABLES: • Type: <var> • Predicate: var?  (same-var? v1 v2) • represented concretely as <symbol>s

  3. SUM: • Type: <sum> • Predicate: sum? • Accessors: sum-addend, sum-augend • Constructor: make-sum • Contract: If x = (make-sum a b) • then (+ (sum-addend x)  (sum-augend x)) = a + b • PRODUCT: • Type: <prod> • Predicate: prod? • Accessors: prod-multiplier, prod-multiplicand • Constructor: make-prod • Contract: If x = (make-prod a b) • then (* (prod-multiplier x) (prod-multiplicand x)) = ab

  4. EXPONENT: (^ a b) • Type: <expt> • Predicate: expt? • Accessors: expt-base, expt-power • Constructor: make-expt • Contract: If x = (make-expt a b) • then (^ (expt-base x) (expt-power x)) = ab

  5. (define (deriv e (v <var>))    (cond ((const? e) 0)         ((var? e) (if (same-var? e v) 1 0))         ((sum? e) (make-sum (deriv (get-sum-addend e) v)                             (deriv (get-sum-augend e) v)))         ((prod? e) (make-sum (make-prod (get-prod-multiplier e)                         (deriv (get-prod-multiplicand e) v))              (make-prod (deriv (get-prod-multiplier e) v)                         (get-prod-multiplicand e))))         ((expt? e) (make-prod (make-prod (get-expt-power e)                         (make-expt (get-expt-base e) (make-sum (get-expt-power e) -1)))              (deriv (get-expt-base e) v)))))))

  6. (define (make-sum x y) (list '+ x y)) (define (sum? x) (and (list? x) (= 3 (length x)) (eq? '+ (first x)))) (define (get-sum-addend x) (if (sum? x) (second x) (error "..."))) (define (get-sum-augend x) (if (sum? x) (third x) (error "...")))

  7. (make-sum a b) ==> • If a or b is zero, just return the other one • If a and b are both numbers, add them. • (make-product a b) ==> • If a=0 or b=0, return 0 • If a=1 or b=1, return the other. • If both are numbers, multiply them. • (make-expt a b) ==> • If a=0 or a=1, return a • If b=0, return 1 • If b=1, return a • If both are numbers, do the computation.

  8. (define (make-sum x y)  (cond ((and (const? x) (const? y)) (+ x y))        ((and (const? x) (= x 0)) y)        ((and (const? y) (= y 0)) x)        (else (make <sum> :addend x :augend y))))

More Related