sriley


Joined 2 years ago
Homeworks submitted:
Homework comments:
1
0

About Me

No description provided.

Classes

Structure and Interpretation of Computer Programs

Class status: Established
Role: Student
. 7% complete

Submitted Assignments

Structure and Interpretation of Computer Programs: Lesson 1, HW 1

ex1.1 10; 12; 8; 3; 6; 19; #f; 4; 16; 6; 16

ex1.2 (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 3))))) (* 3 (- 6 2) (- 2 7)))

ex1.4 if b > 0 the procedure simplifies to (+ a b) if b >= 0 it simplifies to (- a b) the end result is the procedure adds the absolute value of b to a

ex1.5 Applicative order only evaluates the expression when it is used. Result is 0. Normal order expands all expressions and then colapses them. Result is endless recursion.

ex1.6 new-if is not a special form. The arguments to new-if are calculated before new-if is called. One of the arguments is another call to new-if resulting in endless recursion.

;1.3
(define (f a b c)
  (cond ((and (>= a c) (>= b c)) (+ (* a a) (* b b)))
	((and (>= a b) (>= c b)) (+ (* a a) (* c c)))
	((and (>= b a) (>= c a)) (+ (* b b) (* c c)))))

;1.7
(define (sqrt-iter old-guess guess x)
  (if (good-enough? old-guess guess)
      guess
      (sqrt-iter guess
		 (improve guess x)
                 x)))

(define (improve guess x)
  (average guess (/ x guess)))

(define (average x y)
  (/ (+ x y) 2))

(define (good-enough? old-guess guess)
  (< (abs (- old-guess guess)) (/ guess 1000)))

(define (sqrt x)
  (sqrt-iter 1.0 (improve 1.0 x) x))

;1.8 replace improve in sqrt with
(define (improve guess x)
  (/ (+ (/ x (* guess guess))
	(* 2 guess))
     3))

sriley 2 years ago