Use cases vs functional specs

January 29, 2010

I’ve come to the firm belief that writing detailed functional specs upfront for software projects is a total waste of time. Software is meant oto be used and in order to find out what it’s use is going to be software architects need use cases. writing specs is just moronic when you have no idea on how it’s going to be used


Ex 1.8 – Structure and Interpretation of Computer Programs

January 25, 2010

; Ex 1.8
(define improve-cube-root
  (lambda (x y)
    (/ (+ (/ x (* y y)) (* 2 y))
       3)))

(define cube-root-iter
  (lambda (guess x )
    (define next-guess ( / ( + (/ x (* guess guess)) (* 2 guess))
                           3))
    (if (good-enough-2? next-guess guess)
        next-guess
        (cube-root-iter next-guess x))))

(define cube-root
  (lambda (x)
    (cube-root-iter 1.0 x)))


Ex 1.7 – Structure and Interpretation of Computer Programs

January 25, 2010

; Ex 1.7
(define (good-enough-2? guess prev-guess)
  (< (abs (- guess prev-guess)) 0.0001))

(define sqrt-iter-2
  (lambda (guess x)
    (define next-guess (improve guess x))
    (if (good-enough-2? next-guess guess)
        next-guess
        (sqrt-iter-2 next-guess x))))


Ex 1.6 – Structure and Interpretation of Computer Programs

January 25, 2010

; Ex 1.6
; The function will run forever, because Scheme is applicative order
; so the argument for the else clause will be evaluated causing the
; to routine to run forever.


Ex 1.13 – Structure and Interpretation of Computer Programs

January 23, 2010

Exercise 1.13 – SICP

We already know that

clip_image002[4](1)

We also know that

clip_image004[4] where clip_image006[4]

From the hint clip_image008[5] where clip_image010[5]

So clip_image012[5]

So according to the finonacci definition (1)

clip_image014[4]

Using wolfram alpha we can compute

clip_image016[9]

If you plugin the values in the wolfram alpha , you can see that that both expansions at clip_image018[4]are also the same

Edit hmmm, looks like I missed the point of the problem. The real problem was to prove that Fib(n) approx= phi^n / 2 where phi = (1+sqrt(5))/2. I think I’ll have to redo this proof.


Excercise 1.11 Structure and Interpretation of Computer Programs (SICP)

January 16, 2010

I’m going through the “Structure and Interpretation of Computer Programs” as a way of compensating for my lack of geek cred.
I was having some problem with wrapping my head around the iterative solution of this exercise (hey it was after a long day at work), so I cheated a bit and looked it up on the internet and found a solution here. So in order to come up with my own solution, I decided to implement a solution using the collector function  or continuation technique for recursion shown or taught in the “Little Schemer” in chapter 8. Below is what I came up with

; Ex 1.11
; recursive solution
(define f-r
  (lambda (n)
    (cond ((< n 3) n)
          (else ( + (f-r (- n 1))
                    (* 2 (f-r (- n 2)))
                    (* 3 (f-r (- n 3))))))))

; Iterative Solution
(define f&co
  (lambda (n col)
    (cond ((< n 3) (col n 1 0))
          ( else (f&co (- n 1)
                       (lambda (a b c)
                         (col (+ a (* 2 b) (* 3 c))
                              a
                              b)))))))

(define f-i
  (lambda (n)
    (f&co n (lambda (a b c) a))))
(display “Recursive Solution”)
(newline)
(map f-r ‘(0 1 2 3 4 5 6))
(display “Iterative Solution using collector function”)
(newline)
(map f-i ‘(0 1 2 3 4 5 6))
                                


Moving from Scheme to OCAML

December 20, 2009

So I started learning OCAML and I’m already missing Scheme …


Programming a Brain

December 19, 2009

The other day I was thinking that its only a matter of time that an artificial machine would be constructed that would be as sophisticated and  powerful as the human brain is today. That would become the “brain” of something. But then I thought that would actually be the easy part. “Easy” being a relative term here. The really hard problem would be programming this machine. Would it even be possible for human beings to program this computing machine? And if it was possible to program this machine,  would it  be economically feasible to program this machine so that it works correctly? Producing bug-free software to run any reasonably complex system is virtually impossible today. Hell, we can’t even get bug-free drivers for a simple devices yet. How in the world are we going to get program a computing device of the complexity of a human brain.

My own take is that we’ll probably figure out how to replicate the human brain within the century. Human beings are then going to have to find a short-cut to program the machine because with our current software production model I don’t think we’re never be able to release a software to run this machine. All this singularity stuff is still far off in the future. 


Slimdx

November 18, 2009

I’ve been working on some graphics work using SlimDx. I really like the library but the documentation is sparse in some places


ScribeFire and formatting code

November 1, 2009

Apparently ScribeFire doesn’t do C# source code formatting very well.