An axiomatic number system in python
We are given four "axiom" functions,
zero()
returns a zero objectis_zero(obj)
returnsTrue
if the given object is a zeronext(obj)
returns the next object from the given objectprev(obj)
returns the previous object from the given object
This is similar to how a stack works,
>>> from axiom import zero, is_zero, next, prev
>>> is_zero(zero())
True
>>> is_zero(next(zero()))
False
>>> is_zero(prev(next(zero())))
True
Nothing is less than than a zero object.
Objects are not necessarily immutable (e.g., a list
). This constraint might be added later.
Arbitrary loops (e.g., while
, recursion) are forbidden. Iterate over generators instead.
We have one general-purpose generator,
compose(fn, arg)
yieldsarg
,fn(arg)
,fn(fn(arg))
, etc.
Derived functions are grouped by depth from the axioms. For example, we group dist
and add
because they are derived from the axioms. We group eq
and multiples
because they are derived from dist
and add
(respectively).
There are exceptions, such as dividing by zero.
By convention, 00 equals 1 and does not throw an exception.
Some useful sequences may be generated,
counting()
yields 0 1 2 3 4...fib()
yields 0 1 1 2 3 5 8 13...multiples(n)
yields n 2n 3n 4n 5n...primes()
yields 2 3 5 7 11 13 17 19...catalan()
yields 1 1 2 5 14 42 132...fact()
yields 1 1 2 6 24 120...powers(n)
yields 1 n n2 n3 n4 n5...pascal_column(k)
yields kth column of Pascal's trianglepascal_row(n)
yields nth row of Pascal's triangle