I'm doing the exercises in Algorithms and Data Structures in Java, Second Edition, by Adam Drozdek.
One question is:
The set of natural numbers $\mathbb{N}$ defined at the beginning of this chapter includes the numbers $10,11,\dotsc,20,21,\dotsc$,and also the numbers $00,000,01,001,\dotsc$.Modify this definition to allow only numbers with non leading zeros.
Here is the definition given at the beginning of the chapter (the faulty one):
- $0, 1, 2, 3, 4, 5, 6, 7, 8, 9 \in \mathbb{N}$;
- if $n \in \mathbb{N}$, then $n0, n1, n2, n3, n4, n5, n6, n7, n8, n9 \in \mathbb{N}$;
- these are the only natural numbers.
My modified definition, to exclude leading zeros, is:
- $1, 2, 3, 4, 5, 6, 7, 8, 9 \in \mathbb{N}$;
- if $n \in \mathbb{N}$, then $n0, n1, n2, n3, n4, n5, n6, n7, n8, n9 \in \mathbb{N}$;
- these are the only natural numbers.
Is my modified version correct?
Note that $0 \notin \mathbb{N}$ in your modified definition, so it cannot be correct.
A couple of ways to fix it are:
or