* 1.1

=> 10
10

=> (+ 5 3 4)
12

=> (+ (* 2 4) (- 4 6))
6

* 1.2

notate the equation referenced in book

#+BEGIN_SRC scheme

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

#+END_SRC

#+RESULTS:
: -37/150

* 1.3

write a procedure to calculate the sum of the squares of the two
largest numbers among three

#+BEGIN_SRC scheme

  (define (square x)
    (* x x))

  (define (bigger x y)
    (if (> x y) x y))

  (define (biggest x y z)
    (bigger (bigger x y)
	    (bigger y z)))

  (define (middle? a x y)
    (or (and (> a x) (< a y))
	(and (< a x) (> a y))
	(and (= a x) (< a y))
	(and (= a y) (< a x))
	(and (= a y) (= a x))))

  (define (middle x y z)
    (cond ((middle? x y z) x)
	  ((middle? y x z) y)
	  ((middle? z x y) z)))

  (define (big-squares a b c)
    (+ (square (biggest a b c))
       (square (middle a b c))))

  (big-squares 3 5 2)

#+END_SRC

#+RESULTS:
: 34

* 1.4

#+BEGIN_SRC scheme
  (define (a-plus-abs-b a b)
     ((if (> b 0) + -) a b))
#+END_SRC

combine a and b, using + as the operator if b is positive
                   use - as the operator if b is negative

* 1.5

#+BEGIN_SRC scheme

  (define (p) (p))

  (define (test x y)p
    (if (= x 0)
        0
	y))

  (test 0 (p))

#+END_SRC

#+RESULTS:

applicative order: decides predicate (= x 0), returning 0

normal order: tries to infinitely expand (p)

im not firm (a litte shaky) on my understanding of this

* 1.6

#+BEGIN_SRC scheme

  (define (new-if predicate then-clause else-clause)
    (cond (predicate then-clause)
	  (else else-clause)))
  (new-if (= 2 3) 0 5)
  (new-if (= 1 1) 0 5)

  (define (sqrt-iter guess x)
    (new-if (good-enough? guess x)
	    guess
	    (sqrt-iter (improve guess x)
		       x)))

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

  (sqrt 2) ;; too much recursion

#+END_SRC

I do not have an explanation for why this is :/

* 1.8

Create a similar guessing method using Newton's method for cube roots.

#+BEGIN_SRC scheme

  (define (qbrt x)
    (qbrt-iter 1.0 x))
  (define (qbrt-iter guess x)
    (if (good-enough? guess x)
	guess
	(qbrt-iter (improve guess x)
		   x)))
  (define (cube x)
    (* x x x))
  (define (good-enough? guess x)
    (< (abs (- (cube guess) x)) 0.001))
  (define (improve guess x)
    (/
      (+
       (/ x
	  (* guess guess))
       (* 2 guess))
      3))
  (qbrt 125)

#+END_SRC

#+RESULTS:
: 5.000000000287929
