11

Peano natural numbers in Haskell defined as data Peano = Zero | Succ Peano are quite strange beasts: besides plain naturals and bottom values, there is an "infinite integer" inf = Succ inf among them.

Are there any other inhabitants of the Peano type? Does this infinite number has a name?

pad
  • 41,040
  • 7
  • 92
  • 166
nponeccop
  • 13,527
  • 1
  • 44
  • 106

2 Answers2

17

They're not strange, they're simply coinductive naturals. Leaving aside the issue of ⊥, we can define the natural number type here as consisting of either Zero, or Succ applied to a natural number. An inductive definition would assume a well-defined end, i.e., that any number starts from a Zero constructor. The coinductive definition merely says that given any natural number, it will either be Zero or we can remove the outer Succ to get another natural number.

The seemingly subtle difference there is that the coinductive definition includes an endless series of Succ constructors, which really is a true representation of infinity. This is meaningful because, while an inductive definition is about ensuring that recursion will reach a well-defined base case, coinductive definitions are about ensuring that there will always be a well-define next step available.

The coinductive interpretation is convenient and in some ways obligatory in Haskell, due to data constructors being lazy.

So, this infinite number really is infinity, or ω if you need to specify which infinity, as Daniel Fischer said. It's just a coinductive infinity, much like the infinite lists that are more commonly encountered.

If you think of natural numbers via their church encoding, finite numbers mean "iterate this function N times"; ω means "iterate this function indefinitely".

C. A. McCann
  • 76,893
  • 19
  • 209
  • 302
  • 2
    This is typically called the "extended natural numbers" and it arises frequently in a pretty straightforward way: http://ncatlab.org/nlab/show/extended%20natural%20number%20system, http://golem.ph.utexas.edu/category/2008/12/the_status_of_coalgebra.html – sclv Dec 12 '11 at 17:23
  • 1
    @sclv: My favorite thing about being a Haskell programmer is people saying that something is "straightforward" and then illustrating it with a link to nLab, haha. But yes, I've read those before, they're interesting. – C. A. McCann Dec 12 '11 at 17:32
  • haha I think I have a moving target of "straightforward" which I use to mean "I can actually wave my hands a bit and sort of explain it," just like folks use "trivial" to mean "given enough time, I'm sure I can prove this." – sclv Dec 12 '11 at 17:36
  • @sclv: I like Feynman's definition of "trivial" based on observing math students, which was roughly "anything that has ever been proven or obviously could be proven with some effort". The antonym of "trivial" would presumably be "an open problem". – C. A. McCann Dec 12 '11 at 17:40
10

Well, there are Succ _|_, Succ (Succ _|_) etc. You may have included those among the 'bottom values', though. inf = Succ inf is usually called infinity or omega (as the ordinal of natural numbers).

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
  • But since `inf = Succ inf`, it can't be the ordinal of natural numbers, right? It would be ω and ω+1 simultaneously. Isn't `inf` more akin to aleph-null, the cardinality of N? – Fred Foo Dec 14 '11 at 13:29
  • 1
    @larsmans depends on whether you interpret `Succ n` as `n+1` or as `1+n`, `1 + ω = ω /= ω + 1`. – Daniel Fischer Dec 14 '11 at 13:39