Closed gabegorelick closed 5 years ago
That's a really good observation. I'll update the article to include that, and credit the person who brought it up.
I don't know how to get around the pathological case, I guess 64 bits can only record so much, and the method of selecting mediants as midpoints prioritizes the potential lengths of some paths over others. Hopefully the case of continued insertion on just one side is more common than going LRLRLR down the tree.
Would renormalization help?
The fraction arithmetic functions do detect overflow and raise ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE
. The code calling rational_intermediate
could catch that error, renormalize and try again. The renormalization is interesting because I don't know if it's one-size-fits-all. Like maybe a table is sorted, but the order applies per-category of thing. So the normalization would need to know to apply to just rows in a category? Or maybe I'm overthinking it.
The Hacker News discussion on your blog post has some interesting points, particularly this comment which identifies a pathological case when taking mediants: