Skip to content

Commit

Permalink
Coinductive definition of the conatural numbers (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrik-bakke authored Jan 4, 2025
1 parent 6152336 commit 4545c3a
Show file tree
Hide file tree
Showing 13 changed files with 822 additions and 31 deletions.
10 changes: 10 additions & 0 deletions src/elementary-number-theory.lagda.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Elementary number theory

```agda
{-# OPTIONS --guardedness #-}
```

## Modules in the elementary number theory namespace

```agda
Expand Down Expand Up @@ -27,6 +31,7 @@ open import elementary-number-theory.cofibonacci public
open import elementary-number-theory.collatz-bijection public
open import elementary-number-theory.collatz-conjecture public
open import elementary-number-theory.commutative-semiring-of-natural-numbers public
open import elementary-number-theory.conatural-numbers public
open import elementary-number-theory.congruence-integers public
open import elementary-number-theory.congruence-natural-numbers public
open import elementary-number-theory.cross-multiplication-difference-integer-fractions public
Expand Down Expand Up @@ -66,11 +71,13 @@ open import elementary-number-theory.greatest-common-divisor-natural-numbers pub
open import elementary-number-theory.group-of-integers public
open import elementary-number-theory.half-integers public
open import elementary-number-theory.hardy-ramanujan-number public
open import elementary-number-theory.inclusion-natural-numbers-conatural-numbers public
open import elementary-number-theory.inequality-integer-fractions public
open import elementary-number-theory.inequality-integers public
open import elementary-number-theory.inequality-natural-numbers public
open import elementary-number-theory.inequality-rational-numbers public
open import elementary-number-theory.inequality-standard-finite-types public
open import elementary-number-theory.infinite-conatural-numbers public
open import elementary-number-theory.infinitude-of-primes public
open import elementary-number-theory.initial-segments-natural-numbers public
open import elementary-number-theory.integer-fractions public
Expand Down Expand Up @@ -117,6 +124,7 @@ open import elementary-number-theory.peano-arithmetic public
open import elementary-number-theory.pisano-periods public
open import elementary-number-theory.poset-of-natural-numbers-ordered-by-divisibility public
open import elementary-number-theory.positive-and-negative-integers public
open import elementary-number-theory.positive-conatural-numbers public
open import elementary-number-theory.positive-integer-fractions public
open import elementary-number-theory.positive-integers public
open import elementary-number-theory.positive-rational-numbers public
Expand Down Expand Up @@ -158,9 +166,11 @@ open import elementary-number-theory.twin-prime-conjecture public
open import elementary-number-theory.type-arithmetic-natural-numbers public
open import elementary-number-theory.unit-elements-standard-finite-types public
open import elementary-number-theory.unit-similarity-standard-finite-types public
open import elementary-number-theory.universal-property-conatural-numbers public
open import elementary-number-theory.universal-property-integers public
open import elementary-number-theory.universal-property-natural-numbers public
open import elementary-number-theory.upper-bounds-natural-numbers public
open import elementary-number-theory.well-ordering-principle-natural-numbers public
open import elementary-number-theory.well-ordering-principle-standard-finite-types public
open import elementary-number-theory.zero-conatural-numbers public
```
172 changes: 172 additions & 0 deletions src/elementary-number-theory/conatural-numbers.lagda.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Conatural numbers

```agda
{-# OPTIONS --guardedness #-}

module elementary-number-theory.conatural-numbers where
```

<details><summary>Imports</summary>

```agda
open import foundation.action-on-identifications-functions
open import foundation.coproduct-types
open import foundation.dependent-pair-types
open import foundation.homotopies
open import foundation.injective-maps
open import foundation.maybe
open import foundation.negated-equality
open import foundation.retractions
open import foundation.sections
open import foundation.universe-levels

open import foundation-core.identity-types
```

</details>

## Idea

The {{#concept "conatural numbers" Agda=ℕ∞}} `ℕ∞` is a
[set](foundation-core.sets.md) that satisfies the dual of the universal property
of [natural numbers](elementary-number-theory.natural-numbers.md) in the sense
that it is the final coalgebra of the functor `X ↦ 1 + X` rather than the
initial algebra.

## Definitions

### The coinductive type of conatural numbers

```agda
record ℕ∞ : UU lzero
where
coinductive
field
decons-ℕ∞ : Maybe ℕ∞

open ℕ∞ public
```

### The zero element of the conatural numbers

```agda
zero-ℕ∞ : ℕ∞
decons-ℕ∞ zero-ℕ∞ = exception-Maybe
```

### The element at infinity of the conatural numbers

```agda
infinity-ℕ∞ : ℕ∞
decons-ℕ∞ infinity-ℕ∞ = unit-Maybe infinity-ℕ∞
```

### The successor function on the conatural numbers

```agda
succ-ℕ∞ : ℕ∞ ℕ∞
decons-ℕ∞ (succ-ℕ∞ x) = unit-Maybe x
```

### The constructor function for conatural numbers

```agda
cons-ℕ∞ : Maybe ℕ∞ ℕ∞
cons-ℕ∞ (inl x) = succ-ℕ∞ x
cons-ℕ∞ (inr x) = zero-ℕ∞
```

### Alternative definition of the deconstructor function for conatural numbers

```agda
decons-ℕ∞' : ℕ∞ Maybe ℕ∞
decons-ℕ∞' x = rec-coproduct inl inr (decons-ℕ∞ x)

compute-decons-ℕ∞ : decons-ℕ∞' ~ decons-ℕ∞
compute-decons-ℕ∞ x with decons-ℕ∞ x
compute-decons-ℕ∞ x | inl q = refl
compute-decons-ℕ∞ x | inr q = refl
```

### The coiterator function for conatural numbers

```agda
coit-ℕ∞ : {l : Level} {A : UU l} (A Maybe A) A ℕ∞
decons-ℕ∞ (coit-ℕ∞ f x) with f x
decons-ℕ∞ (coit-ℕ∞ f x) | inl a = unit-Maybe (coit-ℕ∞ f a)
decons-ℕ∞ (coit-ℕ∞ f x) | inr _ = exception-Maybe
```

### The corecursor function for conatural numbers

```agda
corec-ℕ∞ : {l : Level} {A : UU l} (A ℕ∞ + Maybe A) A ℕ∞
decons-ℕ∞ (corec-ℕ∞ f x) with f x
decons-ℕ∞ (corec-ℕ∞ f x) | inl q = unit-Maybe q
decons-ℕ∞ (corec-ℕ∞ f x) | inr (inl a) = unit-Maybe (corec-ℕ∞ f a)
decons-ℕ∞ (corec-ℕ∞ f x) | inr (inr *) = inr *
```

## Properties

### Zero is not a successor

```agda
neq-zero-succ-ℕ∞ : (x : ℕ∞) succ-ℕ∞ x ≠ zero-ℕ∞
neq-zero-succ-ℕ∞ x p = is-not-exception-unit-Maybe x (ap decons-ℕ∞ p)
```

### Zero is not the point at infinity

```agda
neq-zero-infinity-ℕ∞ : infinity-ℕ∞ ≠ zero-ℕ∞
neq-zero-infinity-ℕ∞ p =
is-not-exception-unit-Maybe infinity-ℕ∞ (ap decons-ℕ∞ p)

neq-infinity-zero-ℕ∞ : zero-ℕ∞ ≠ infinity-ℕ∞
neq-infinity-zero-ℕ∞ =
is-symmetric-nonequal infinity-ℕ∞ zero-ℕ∞ neq-zero-infinity-ℕ∞
```

### The constructor function is a section of the deconstructor

```agda
is-section-cons-ℕ∞ : is-section decons-ℕ∞ cons-ℕ∞
is-section-cons-ℕ∞ (inl x) = refl
is-section-cons-ℕ∞ (inr x) = refl

section-decons-ℕ∞ : section decons-ℕ∞
section-decons-ℕ∞ = cons-ℕ∞ , is-section-cons-ℕ∞

retraction-cons-ℕ∞ : retraction cons-ℕ∞
retraction-cons-ℕ∞ = decons-ℕ∞ , is-section-cons-ℕ∞

is-injective-cons-ℕ∞ : is-injective cons-ℕ∞
is-injective-cons-ℕ∞ = is-injective-retraction cons-ℕ∞ retraction-cons-ℕ∞
```

```agda
is-section-cons-ℕ∞' : is-section decons-ℕ∞' cons-ℕ∞
is-section-cons-ℕ∞' (inl x) = refl
is-section-cons-ℕ∞' (inr x) = refl

section-decons-ℕ∞' : section decons-ℕ∞'
section-decons-ℕ∞' = cons-ℕ∞ , is-section-cons-ℕ∞'

retraction-cons-ℕ∞' : retraction cons-ℕ∞
retraction-cons-ℕ∞' = decons-ℕ∞' , is-section-cons-ℕ∞'
```

### The successor function is injective

```agda
is-injective-succ-ℕ∞ : is-injective succ-ℕ∞
is-injective-succ-ℕ∞ p = is-injective-inl (is-injective-cons-ℕ∞ p)
```

## External links

- [CoNaturals](https://martinescardo.github.io/TypeTopology/CoNaturals.index.html)
at TypeTopology
- [extended natural numbers](https://ncatlab.org/nlab/show/extended+natural+number)
at $n$Lab
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# The inclusion of the natural numbers into the conatural numbers

```agda
{-# OPTIONS --guardedness #-}

module elementary-number-theory.inclusion-natural-numbers-conatural-numbers where
```

<details><summary>Imports</summary>

```agda
open import elementary-number-theory.conatural-numbers
open import elementary-number-theory.infinite-conatural-numbers
open import elementary-number-theory.natural-numbers

open import foundation.action-on-identifications-functions
open import foundation.existential-quantification
open import foundation.injective-maps
open import foundation.negated-equality
open import foundation.negation
open import foundation.surjective-maps

open import foundation-core.empty-types
open import foundation-core.identity-types
```

</details>

## Idea

The
{{#concept "inclusion of the nautural numbers into the conatural numbers" Agda=ℕ∞}}
is the inductively defined map

```text
conatural-ℕ : ℕ∞
```

that sends zero to zero, and the successor of a natural number to the successor
of its inclusion.

## Definitions

### The canonical inclusion of the natural numbers into the conatural numbers

```agda
conatural-ℕ : ℕ∞
conatural-ℕ zero-ℕ = zero-ℕ∞
conatural-ℕ (succ-ℕ x) = succ-ℕ∞ (conatural-ℕ x)
```

## Properties

### The canonical inclusion of the natural numbers is injective

```agda
is-injective-conatural-ℕ : is-injective conatural-ℕ
is-injective-conatural-ℕ {zero-ℕ} {zero-ℕ} p = refl
is-injective-conatural-ℕ {zero-ℕ} {succ-ℕ y} p =
ex-falso (neq-zero-succ-ℕ∞ (conatural-ℕ y) (inv p))
is-injective-conatural-ℕ {succ-ℕ x} {zero-ℕ} p =
ex-falso (neq-zero-succ-ℕ∞ (conatural-ℕ x) p)
is-injective-conatural-ℕ {succ-ℕ x} {succ-ℕ y} p =
ap succ-ℕ (is-injective-conatural-ℕ {x} {y} (is-injective-succ-ℕ∞ p))
```

### The canonical inclusion of the natural numbers is not surjective

The canonical inclusion of the natural numbers is not surjective because it does
not hit the point at infinity.

```text
neq-infinity-conatural-ℕ : (n : ℕ) conatural-ℕ n ≠ infinity-ℕ∞
neq-infinity-conatural-ℕ zero-ℕ = neq-infinity-zero-ℕ∞
neq-infinity-conatural-ℕ (succ-ℕ n) p =
neq-infinity-conatural-ℕ n
( is-injective-succ-ℕ∞ (p ∙ {! is-infinite-successor-condition-infinity-ℕ∞ !}))

is-not-surjective-conatural-ℕ : ¬ (is-surjective conatural-ℕ)
is-not-surjective-conatural-ℕ H =
elim-exists empty-Prop neq-infinity-conatural-ℕ (H infinity-ℕ∞)
```
Loading

0 comments on commit 4545c3a

Please sign in to comment.