General
Material
Lecture 1
 Slides Practical Session
Lecture 2
 Slides Practical Session
Lecture 3
 Slides Practical Session
Lecture 4
 Slides Practical Session
Lecture 5
 Slides Practical Session

# A representation of natural numbers

Nowadays, when human beings write numerals, they usually use decimal notation (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, and so on) but as you probably know, there are many other notations. Here is a way of writing numerals, which is sometimes used in mathematical logic. It makes use of just four symbols: 0, succ, and the left and right brackets. This style of numeral is defined by the following inductive definition:

1. 0 is a numeral.
2. If X is a numeral, then so is succ(X).
As is probably clear, succ can be read as short for successor. That is, succ(X) represents the number obtained by adding one to the number represented by X. So this is a very simple notation: it simply says that 0 is a numeral, and that all other numerals are built by stacking succ symbols in front. For instance, the numeral corresponding to the number 3 is succ(succ(succ(X))).

Define a predicate `numeral/1` which test whether its argument is a number in the 'succ-notation' just described. The predicate should, for example, behave as follows:

```?- numeral(0).
yes
?- numeral(4).
no
?- numeral(succ(succ(succ))).
no
?- numeral(succ(succ(0))).
yes
```
Hint

Define a predicate `greater_than/2` that takes two numbers in the 'succ-notation' and as arguments and decides whether the first one is greater than the second one. For example:

```?- greater_than(succ(succ(succ(0))),0).
yes
?- greater_than(succ(succ(succ(0))),succ(0)).
yes
?- greater_than(succ(succ(0)),succ(succ(succ(0)))).
no
```
Hint

Define a predicate `add/3` that adds two numbers in the 'succ-notation'. That is `add(X,Y,Z)` should be true if `Z` is the sum of `X` and `Y`. For example:

```?- add(succ(succ(succ(0))),succ(0),R).
R = succ(succ(succ(succ(0))))
yes