sample hand evaluation

A hand-evaluation consists of a series of expressions, all of whom have the same value. They are the expressions that you see when using DrScheme's Stepper. For example, if we had these two functions defined:

;; square: number --> number         
;; Given a, return a^2.
;;
(define (square a) (* a a))         
;; hypotenuse: number, number --> number
;; Given the length of two legs a,b of a triangle,
;; return the length of the hypotenuse.
;; a,b are expected to be non-negative.
;;
(define (hypotenuse a b)
  (sqrt (+ (square a) (square b))))
;; Tests:
(square 7)
49

(square 0)
0

(square -2)
4
;; Tests:
(hypotenuse 0 0)
0

(hypotenuse 0 7)
7

(hypotenuse 3 4)
5

Here would be a sample hand-evaluation:

  (hypotenuse 12 5)
= (sqrt (+ (square 12) (square 5)))
= (sqrt (+ (* 12 12) (square 5)))
= (sqrt (+ 144 (square 5)))
= (sqrt (+ 144 (* 5 5)))
= (sqrt (+ 144 25))
= (sqrt 169)
= 13
This example is a more involved than the one on hw1! The highlighted text indicates the sub-expression about to be evaluated next.

You can double-check this in drscheme by typing this into the definition window without the =; pressing Execute you'll see 13, repeated eight times.

However, in what you turn in, include the equal-signs, since you really do want to link these eight statements together, asserting that they really are equal. Do not use other symbols instead of =. In particular, many people want to use arrows. You never wrote "2 + 3 --> 5" in junior high; 2+3 doesn't transform into 5; it is 5.

Alternately, if you don't like the disconnect between having to add the =s to your printout by hand, you can make the hand-evaluation into pure scheme by calling the function "=", applied to eight things:

(= (hypotenuse 12 5)
   (sqrt (+ (square 12) (square 5)))
   (sqrt (+ (* 12 12) (square 5)))
   (sqrt (+ 144 (square 5)))
   (sqrt (+ 144 (* 5 5)))
   (sqrt (+ 144 25))
   (sqrt 169)
   13)
We'll see soon, that = is (just another) function that takes in numbers and returns true or false, depending on whether the input(s) are equal. So if you did each step correctly, what should this evaluate one expression evaluate to?