Back from the Dead

September 9, 2010

The previous post in this blog is more than nine months old, and before that it already had been inactive for six more. There have been good reasons for that long silence. Chiefly, the birth of Gabriela, our second child, in November 2009.

Well, all that is about to change!

Business as usual will resume shortly with a post on Fibonacci numbers, and there’s also stuff in the making regarding the Chinese remainder theorem as a preliminary to the prime-factor FFT algorithm. The general plan from over a year ago sort of still holds. And I’m sticking with Python 2.x, at least for the time being.

But I have more ambitious plans, and have to decide if this blog will be part of them…

Over the past months I have spent quite a bit of time looking into several physics problems. Things like the speed at which a liquid evaporates, the rolling resistance of a deformable wheel or the stability of a bicycle. Yes, my wife agrees: I have weird ways of enjoying my free time… So that my newly acquired knowledge will not be lost like tears in the rain, I have the firm intention of writing about all that stuff. Not that any of those subjects would in anyway fit within this blog as it is, so I have registered another one just in case.

Also, after 10 years in the same company, and 5 years doing the same job, I am starting to feel an itching urge to give my career a good shake. As a Spanish saying goes, “el hombre propone y Dios dispone,” (man proposes and then God decides) but the firm intention is to leave Spain and find a challenging, enjoyable, better paying job abroad within the next couple of years. If you happen to want to hire an experienced R&D engineer with an EU passport, do contact me.

Not that I expect my inbox to be flooded by this announcement, so I will also be working on honing some skills to better sell myself in the free market, and will definitely want to leave written testimony of my exploits. Some statistics and data analysis posts could see the light here, but I don’t really see relational databases or web programming fitting in this blog. I could of course open yet another one devoted to more generic programming topics, but at some point I’ll have to decide if it isn’t better to have a single one with more varied content.

Anyway, if there’s anyone out there still listening: welcome back, make yourselves comfortable, and enjoy the ride!


Home Sweet Home

May 25, 2009

The move to wordpress is now completed… All the relevant content that was in blogspot, is now here for your enjoyment. The importing was smooth, but I had to do a lot of reformatting by hand, and with python’s sensitivity to whitespace errors, I can’t guarantee that I haven’t messed anything up. If you find anything broken, let me know and I’ll fix it.

Once I got started, I got a little carried away, and have done some more housekeeping:

  • There now is a Coming Soon page on the top menu.
  • There is also a Post Index there, which should provide a convenient way to access the content.

And the big news is that I have set up a Mercurial repository at bitbucket, here’s the link. This should provide two very convenient features for the future:

  • No longer will anyone wanting to try out some of the code I post have to cut and paste from several older posts to get the functions running, as any dependencies will now be handled through a few modules stored in the repository.
  • For future blog entries, rather than cutting and pasting from the posted code, a single file containing all the code will also be available at bitbucket.

Lastly, I am starting to consider moving on to python 3.0 a wise choice. If there are any regular readers out there with an opinion on this, your comments are more than welcome.

Excusatio Non Petita

March 4, 2009

The year probably was 1994, so I guess its understandable that I don’t exactly recall how did I come across a copy of Numerical Recipes in C: The Art of Scientific Computing. But while skimming through the pages, I eventually got to the part on evaluating polynomials, and read something that struck me very deeply. The paragraph that described what I now know is Horner’s scheme read as follows:

We assume that you know enough never to evaluate a polynomial this way:

p=c[0]+c[1]*x+c[2]*x*x+c[3]*x*x*x +c[4]*x*x*x*x;

or (even worse!),


Come the (computer) revolution, all persons found guilty of such criminal behavior will be summarily executed, and their programs won’t be! It is a matter of taste, however, whether to write




Boy was I guilty! Who would have ever thought there was another way of evaluating a polynomial than the obvious one? And that it would be so much more elegant and efficient?

Would be nice if it was just a polynomial thing, but of course it isn’t, and the more complicated the math you are trying to get your computer to do, the larger the chance you are doing it terribly bad. And although much has been written about algorithms, the gospel doesn’t seem to be spreading too swiftly: as I am writing this, the first match for a search of “prime numbers python ” that google returns is this. And he is not alone

So what am I in for? The idea is to bridge the gap between straightforward brute force (a sin I have been as guilty as anyone else of) and the elegant simplicity of efficient code. Hopefully, this will allow me to escape the guillotine when the Jacobins take over…

There are some simple rules that I intend to follow, at least until I decide not to:

  1. Uncomplicated complexity. The math content will be kept reasonably simple. Or maybe simple isn’t the word, as things may get utterly complex. But I will try to stay out of unnecessary complications, so a high school diploma should be all you need to come along on the ride…
  2. Plain python. Sure, C++ is a zillion times faster, but python takes care of most gory details, and makes it easier to concentrate on the algorithm. Plus, it’s so cool and trendy!
  3. No libraries. Sage, SciPy, PARI, qhull, FFTW… whatever it is you are trying to achieve computationally, there is a faster way than replicating the code you find in this blog. And interesting as that may be, it would take a lot of the charm of writing this blog, if it turned into a description of somebody else’s API. So yes, we will even code our own FFTs!