Lecture 29: Neural networks🔗

This assignment is due on Sunday, April 21 at 11:59pm. Submit it using Handin as assignment lecture29. You only need to submit the first exercise.

Watch the first 10 minutes of the following video.
Here’s the data definition for a Formula:
; A Formula is one of:
; - Number
; - "x"
; - (make-add Formula Formula)
; - (make-mul Formula Formula)
(define-struct add [first second])
(define-struct mul [first second])
For example, x²+2x+1 is represented by this Formula:
(define formula1
  (make-add (make-add (make-mul "x" "x")
                      (make-mul 2 "x"))

Exercise 1. Design a function eval that takes a formula and a value for x, and returns the value of the formula at that x.
(check-expect (eval formula1 10) 121)
Hint: The template for processing a Formula can use the built-in functions number? and string?.

For the rest of this page, you don’t need to submit anything.

Exercise 2. Computers can do calculus for us! Design a function dx that takes a formula and returns another formula that is the derivative of the given formula.
(check-expect (eval (dx formula1) 10) 22)
Hint: Handle the mul case using the product rule.

The code we will go over in class is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.

Optional: watch as a computer scientist explains machine learning in 5 levels of difficulty.