Jibe


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

1.1

  • 10
  • 4
  • 8
  • 3
  • 6
  • None
  • None
  • 19
  • f

  • 4
  • 16
  • 6
  • 16

1.2

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

1.4

Adds absolute value of b by subtracting b from a if it is negative otherwise adding the a and b

1.5

The expression will not evaluate in an interpreter that uses applicative order. In normal order the expression will evaluate to 0. In an applicative order interpreter 0 and (p) are evaluated prior to their binding in test; in a normal order interpreter the arguments are not evaluated until they are used inside the function test. In essence in normal order all forms are special forms.

1.6

The function will never return since it evaluates both the then-clause and else-clause prior to the call the function new-if.

; 1.3

(define (Exercise-1.3 x y z)
  (cond ((and (< z y) (< z x))
	 (+ (* x x) (* y y)))
	((and (< y z) (< y x))
	 (+ (* x x) (* z z)))
	(else
	 (+ (* y y) (* z z)))))
	
(define (sqrt-iter-2 guess x prev)
  (if (good-enough-2? guess prev)
      guess
      (sqrt-iter-2 (improve guess x) x guess)))


(define (good-enough-2? guess prev)
  (< (abs (/ (- guess prev) guess)) 1/100))

; 1.8
(define (improve-cubed-root guess x)
  (average guess (/ (+ (/ x (* guess guess)) (* 2 guess)) 3)))

(define (good-enough-cubed? guess x)
  (< (abs (- x (* guess guess guess))) .001))

(define (cubed-root guess x)
  (if (good-enough-cubed? guess x)
      guess
      (cubed-root (improve-cubed-root guess x) x)))

Jibe 2 years ago