elefantstn


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 12 8 8 6 a b 24 4 16 6 16

1.4:

Use the sign of b to determine whether to add or subtract it, hence the effect of adding b's absolute value.

1.5:

In an applicative order interpreter, the y in the second half of the if condition won't be expanded, so the result will be 0. In a normal order interpreter, attempting to expand the function test will result in an error.

1.6:

Without a special instruction to short-circuit the 'else', the new-if expands an endless loop of good-enough? tests.

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

(define (sum-of-squares x y)
  (+ (* x x)
     (* y y)))
     
(define (sum-of-largest-squares x y z)
  (cond ((and (< x y) (< x z)) (sum-of-squares y z))
        ((and (< y x) (< y z)) (sum-of-squares x z))
        ((else (sum-of-squares x y))))
  )


(define (cube x) (* x x x))

(define (good-enough? guess x)
        (< (abs (- (cube guess) x)) 0.001))

(define (improve guess x)
        (/ (+ (/ x (square guess)) (* 2 guess))
            3))
        
(define (cube-iter guess x)
        (if (good-enough? guess x)
            guess
            (cube-iter (improve guess x) x)))

(define (cubert x) (cube-iter 1.0 x))


elefantstn 2 years ago