# Peano Numbers and Arithmetic in JavaScript

Whilst completing the Functional Programming Principles in Scala course a couple of years ago one of the exercises was in the realm of Peano numbers. This subject fascinated me, how we were able to represent non-negative natural numbers without any preformed concepts - relying solely on the logical expressions and recursive algorithms. Peano numbers allow us to represent all natural numbers using a defined zero value and a successor function.

Following these rules we have created the concept of zero (represented as false within our host language), along with the successor function which wraps and returns this value in a new lambda upon each invocation. We have also supplied accompanying zero comparator and predecessor functions which will assist us in upcoming examples.

## Arithmetic

Using this representation as a basis we are able to expand on the example by describing the four common-place arithmetic operations.

Looking at the definitions above you can see how we have been able to represent these operations using recursion and the functions defined before hand.

## Logic

We are also able to as easily represent logical operations which return the host languages boolean value type.

## Example

Finally, we are able to combine all these operations into succinct examples.