We often forget how Smalltalk handles some stuff with class (no pun intended!), efficiency and precision… Mostly because it’s always been that way! That’s a given for Smalltalkers!
Recently, I was brutally reminded how sad this world is while trying to solve the Burma14 TSP problem. I couldn’t figure out why I kept having a +24 km difference for the optimal tour so I started looking on the internet. My program was finding the optimal tour but I could never get a tour length of 3323 km!
I first thought I wasn’t using the proper function to calculate distances. Then I thought the reference ellipsoid I was using might be different than the one used to come up with 3323 km. Then I though it could be caused by rounding errors in my code so I used ScaledDecimal, then I thought this, then I thought that, then I read more, then followed links, then more links, then more debugging, then…
Then I found the TSPLIB FAQ. The culprit happens to be in the degrees to radians conversion method that is used in TSPLIB calculations. It’s not precise. It’s not very precise at least. And the value of Pi used in the calculations seems good enough to do the job but, quite frankly, I don’t think it is! If I can get a 24km difference for a tour of only 14 cities, what would it be like for a tour of a few thousand cities?
Smalltalkers often forget that, in our world, 1/7 + 6/7 equals 1. And that evaluating 1000!/999! doesn’t bomb and it equals 1000. And I’m grateful that things are as they should be… in Smalltalk!
Note: if you look at the image at the beginning of this post, you’ll see that in Smalltalk evaluating 1/7 + 6/7 = 1 and 1000!/999! = 1000. And Pi is a little bit more than 3.141592.