https://github.com/vimkim/peanopython
Most Elegant Peano Arithmatic in Python
https://github.com/vimkim/peanopython
Last synced: 10 months ago
JSON representation
Most Elegant Peano Arithmatic in Python
- Host: GitHub
- URL: https://github.com/vimkim/peanopython
- Owner: vimkim
- License: mit
- Created: 2022-09-05T19:23:45.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-05T19:40:44.000Z (almost 4 years ago)
- Last Synced: 2024-04-23T14:00:11.813Z (about 2 years ago)
- Language: Python
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PeanoPython
Most Elegant Peano Arithmatic Implementation in Python
``` python
def main() -> None:
zero: NatNum = Zero()
print("zero:", zero)
one: NatNum = Succ(Zero())
print("one:", one)
two: NatNum = Succ(Succ(Zero()))
print("two:", two)
three: NatNum = Succ(Succ(Succ(Zero())))
print("three:", three)
four1: NatNum = one.add(three)
four2: NatNum = two.add(two)
four3: NatNum = three.add(one)
four4: NatNum = four3.add(zero)
four5: NatNum = zero.add(four4)
print("\nprinting 4...")
print(four1)
print(four2)
print(four3)
print(four4)
print(four5)
```
```bash
$ py main.py
zero: ZERO
one: SUCC ZERO
two: SUCC SUCC ZERO
three: SUCC SUCC SUCC ZERO
printing 4...
SUCC SUCC SUCC SUCC ZERO
SUCC SUCC SUCC SUCC ZERO
SUCC SUCC SUCC SUCC ZERO
SUCC SUCC SUCC SUCC ZERO
SUCC SUCC SUCC SUCC ZERO
```