I'm writing a library in Haskell that represents the class of surreal numbers, which like many things can be read about here. I've run into a problem in converting between other classes of numbers (specifically, rational numbers), and surreals. In an attempt to write a function that converts a rational number into a surreal number, I've noted a few things:
- Not all rational numbers have finite representations as surreal numbers (in fact, I believe any rational number that is represented fractionally with a denominator that is not a power of 2 fails in this respect); I'm willing to ignore these for now
- The function is likely to be defined recursively, like most operations on or concerning surreal numbers
- I have already defined addition, multiplication, negation (and by extension subtraction), and a function that converts an integer into a surreal number
- I would use division of two surreal numbers obtained via integer conversion (the numerator and denominator of the rational number), except that I'm having trouble defining division without already having defined division (simply a quirk with how surreal number division is defined)
I've glanced briefly through "the book" on the topic of surreal numbers (On Numbers and Games by John H. Conway), and while he mentions that the rational numbers are fully contained within the surreals (as are all ordered fields), the only thing he noted that I found that looks something like a conversion equation is the following:
If x is a rational number whose denominator divides $2^n$, then $x = \{x-(1/2)^n|x+(1/2)^n\}$
This seems circularly defined, and unsuitable for an algorithm (at least, as far as I have tried to use it, though that could simply be inexperience). Is there a sensible mapping between the rational numbers and surreal numbers that I can use to input a rational and get out a surreal, and if so, how does it work?