Thursday, October 15, 2015

Some programming basics

As our programming knowledge grows, we sometimes forget that computers are not human. Although the incremental and consistent growth of AI techniques, mining may make us believe otherwise :) This is not a blog about AI or ML, but about some basics

From my understanding of real numbers, I can easily postulate that

0.1 + 0.1 = 0.2 -- (1)
and
0.1 + 0.1 + 0.1 = 0.3 -- (2)

But for a computer formula (2) can be hard to comprehend and as a computer programmer we forget that from time to time

I asked my python interpreter

>>> 0.1+0.1+0.1 == 0.3
False

and later asked what is 0.1+0.1+0.1

>>> 0.1+0.1+0.1
0.30000000000000004

Try this in your favorite language and see what you get -- the math underneath should be the same

Reference - https://docs.python.org/2/tutorial/floatingpoint.html

Ranking and Unranking permutations

I've been a big fan of Skiena's Algorithm Design Manual , I recently found my first edition of the book (although I own the third ed...