Tag Archives: programming

Language oriented programming

The best way to write programs is to write a programming language and then start programming in that language.

If anybody thinks it is too much of effort and this statement is just an exaggeration, then I would like to disprove these thoughts in this post. My experience says that this sentence forms a basic philosophy needed to write good programs.

As usual wordpress is not good place to write about code! So refer to my original post here.


Fibonacci in O(log N)

I found this beautiful algorithm while going through suggested exercise in SICP . For more detailed discussion see http://vikrant.infogami.com/blog/efficientfib

    fibiter a b p q count
| count == 0        = b
| odd count         = fibiter (b*q + a*q + a*p) (b*p + a*q) p q (count -1)
| otherwise         = fibiter a b p1 q1 (count `div` 2)
p1 = p*p + q*q
q1 = q*q + 2*p*qefficientfib = fibiter 1 0 0 1

efficientfib = fibiter 1 0 0 1