|
|
|
|
|
by quickthrower2
1367 days ago
|
|
In Lambda calculus, numbers are encoded using 0 and successor. So 3 = S(S(S(0))) Adding these would be O(N+M) where N and M are the numbers, not the number of bits. Multiplying is O(N*M) where again it is the numbers. 1000*1000 would require a million operations at least. It takes a million operations just to store/read the number million! See: https://en.wikipedia.org/wiki/Church_encoding Unless this HN submitted implementation doesn't use church encoding. In which case I am wrong. |
|
You could also come up with an encoding based on booleans as bits:
then bytes: which you could merge up into larger integers just like real computers.or for one less based on the 8-bits and to keep the infinite range you could just represent integers as lists of binary numbers:
which you could imagine using to implement a way more efficient shift-and-add multiply, O(log M * log N)