3 ms·
that is cool and informative - mind sharing the source for generating the sums?
by shaunxcode 17y ago
that is cool and informative - mind sharing the source for generating the sums?
- defen 17y agohttp://pastebin.com/m3387c4ae http://pastebin.com/m3387c4ae It's part of a game (in the Conway sense) framework I wrote up when I was learning about surreal numbers. Games are an even more general construct, where the left side is not required to be 'less than' the right side. Anyway, to use it, fire up GHCi and `:l game`. I've pre-defined -1, 0, and 1, but you can theoretically create any number with a finite representation (of course, the data structure and algorithms used are deliberately naive and incredibly inefficient and slow, so don't try anything crazy). For example, 5+3 requires 1156 characters to display, 5+4 requires 2556, and 5+5 requires 5118. This is because my code doesn't attempt to "reduce" any of the numbers - numbers can have multiple representations, and with finite representations you can just take the largest element of the left set and the smallest element of the right set and get the same number. My code doesn't do that. Anyway, there's also a fromInteger definition so you can mix Numbers and integers in computations. Examples: Prelude> :l game [1 of 1] Compiling Game ( game.hs, interpreted ) Ok, modules loaded: Game. *Game> zero { | } *Game> 5 :: Game {{{{{{ | } | } | } | } | } | } *Game> let half = Game [zero] [one] *Game> half {{ | } | {{ | } | }} *Game> half < one True *Game> half > 1 False *Game> half + half == 1 True *Game> half * 1 == half True *Game> half * (one + one) > 1 False The best resources for learning are both by Conway: "Winning Ways for your Mathematical Plays" (WW) and "On Numbers and Games" (ONAG). WW is more accessible and introduces you to numbers via games, whereas ONAG is more of a hard-core math book that explains games via numbers. WW is probably better if you don't have a strong math background, ONAG if you do.
- timwiseman 17y agoSurreal numbers where first described in Conway's "On Number's and Games." Since then there have been numerous other articles and books about them including a very nice one by Donald Knuth called "Surreal Numbers".