numerals
numerals copied to clipboard
Gives the same numeral "one sescentillion" for both 10^321 and 10^1803
λ> EN.us_cardinal defaultInflection (10^321) :: Maybe String
Just "one sescentillion"
λ> EN.us_cardinal defaultInflection (10^1803) :: Maybe String
Just "one sescentillion"
Similarly,
- "one sescentillion" == 10^321 == 10^1803
- "one sesmillinillion" == 10^3021 == 10^18003
- "one sescentmillinillion" == 10^3321 == 10^4803
- "one dumillinsescentillion" == 10^6321 == 10^7803
- "one tremillinsescentillion" == 10^9321 == 10^10803
- "one quadrimillinsescentillion" == 10^12321 == 10^13803
- "one quinmillinsescentillion" == 10^15321 == 10^16803
- "one sesmillinsescentillion" == 10^18321 == 10^19803
- "one septinmillinsescentillion" == 10^21321 == 10^22803
- "one octinmillinsescentillion" == 10^24321 == 10^25803
- "one nonmillinsescentillion" == 10^27321 == 10^28803
I’m guessing these names were extrapolated from this Wikipedia article, which seems to have some inconsistencies (as noted on its talk page). This may be a more useful source: http://mrob.com/pub/math/largenum.html#conway-wechsler
Here’s some code I hacked together from the algorithm described at http://mrob.com/pub/math/largenum.html#conway-wechsler. If nothing else, it might be useful as another implementation to test against. Usage:
λ> illion 106
"sexcentillion"
λ> illion 600
"sescentillion"
λ> illion 314159265
"quattuordecitrecentillinovenquinquagintacentilliquinsexagintaducentillion"
import Data.List
import Data.Monoid
data State = I | H | M | MS | MX | N | NS | NX
table :: [[State -> (State, String)]]
table =
[[nil,
i "m" "un",
i "b" "duo",
i_xs "tr" "tre",
i "quadr" "quattuor",
i "quint" "quin" {- corrected from quinqua -},
i_sx "sext" "se",
i_mn "sept" "septe",
i "oct" "octo",
i_mn "non" "nove"],
[nil,
x N "dec" "i",
x MS "vigint" "i",
x NS "trigint" "a",
x NS "quadragint" "a",
x NS "quinquagint" "a",
x N "sexagint" "a",
x N "septuagint" "a",
x MX "octogint" "a",
x H "nonagint" "a"],
[nil,
x NX "cent" "i",
x N "ducent" "i",
x NS "trecent" "i",
x NS "quadringent" "i",
x NS "quingent" "i",
x N "sescent" "i",
x N "septingent" "i",
x MX "octingent" "i",
x H "nongent" "i"]]
where
i s _ I = (H, s)
i _ s _ = (H, s)
i_xs _ s MS = (H, mappend s "s")
i_xs _ s NS = (H, mappend s "s")
i_xs _ s MX = (H, mappend s "s")
i_xs _ s NX = (H, mappend s "s")
i_xs s s' st = i s s' st
i_sx _ s MS = (H, mappend s "s")
i_sx _ s NS = (H, mappend s "s")
i_sx _ s MX = (H, mappend s "x")
i_sx _ s NX = (H, mappend s "x")
i_sx s s' st = i s s' st
i_mn _ s M = (H, mappend s "m")
i_mn _ s MS = (H, mappend s "m")
i_mn _ s MX = (H, mappend s "m")
i_mn _ s N = (H, mappend s "n")
i_mn _ s NS = (H, mappend s "n")
i_mn _ s NX = (H, mappend s "n")
i_mn s s' st = i s s' st
x st' s _ I = (st', s)
x st' s v _ = (st', mappend s v)
nil :: State -> (State, String)
nil st = (st, "")
illi :: State -> (State, String)
illi I = (I, "illin")
illi _ = (I, "illi")
on :: String
on = "on"
smash :: Monoid s => (st -> (st, s)) -> (st -> (st, s)) -> st -> (st, s)
smash f' f st = (st'', mappend s' s) where
(st', s) = f st
(st'', s') = f' st'
illion :: Integer -> String
illion = \n -> mappend (snd (latin n H)) on where
latin 0 = nil
latin n = smash (smash (latin (div n 1000)) (latin' table (mod n 1000))) illi
latin' _ 0 = nil
latin' [] _ = error "Broken table"
latin' (t : ts) n =
smash (genericIndex t (mod n 10)) (latin' ts (div n 10))
Thank you for looking into this Anders! You correctly guessed the Wikipedia article I used as a base for the big number names. Its talk page is interesting. It makes me realize that above a certain value the number names become largely academic. They are not really used by anyone. Perhaps I'll have to support multiple systems.
In any way, your code is very useful. I will use it either as part of the test framework, or as the definition.
Ooh, I found another implementation (Python) at https://github.com/sneilan/BigNumberNames. I checked that it matches mine up through at least illion 1000000 == "millinillinillion".
(Since I forgot to make this explicit, you’re welcome to use or modify my code above under BSD3.)