Comment by eru
1 year ago
Thanks!
I was actually toying with writing a rational number library going in the direction you sketch out. My inspiration was a trick in computational geometry for dealing with points at infinity. I think it's called homogeneous coordinates.
My point was to treat both p and q in p/q as symmetrically as possible.
Oh, I remember now: the motivating example was to write a nice implementation of an optimal player for the 'guessing game' for rational numbers.
One player, Alice, commits to a (rational) number. The other player, Bob, makes guesses, and Alice answers whether the guess was too high, too low or was correct. Bob can solve this in O(log p + log q). And the continued-fraction-based strategy Bob wants to use is generally symmetrical between p and q. So I was looking into expressing the code as symmetrically as possible, too.
No comments yet
Contribute on Hacker News ↗