Tom de Jong
Reboot: 22 January 2021
Earlier version: 18 September 2020

We construct the type of integers with the aim of using them in constructing the
circle as the type of ℤ-torsors, as described in "Construction of the circle in
UniMath" by Bezem, Buchholtz, Grayson and Shulman
(doi:10.1016/j.jpaa.2021.106687).

See Integers-Properties and Integers-SymmetricInduction for (more) properties of
the type of integers.

\begin{code}

{-# OPTIONS --safe --without-K #-}

open import MLTT.Spartan

module Circle.Integers where

ℤ : š“¤ā‚€ ̇
ℤ = šŸ™ + ā„• + ā„•

pattern šŸŽ     = inl ⋆
pattern pos i = inr (inl i)
pattern neg i = inr (inr i)

ā„•-to-ā„¤ā‚Š : ā„• → ℤ
ā„•-to-ā„¤ā‚Š 0        = šŸŽ
ā„•-to-ā„¤ā‚Š (succ n) = pos n

ā„•-to-ℤ₋ : ā„• → ℤ
ā„•-to-ℤ₋ 0        = šŸŽ
ā„•-to-ℤ₋ (succ n) = neg n

ℤ-induction : {š“¤ : Universe} (P : ℤ → š“¤ ̇ )
            → P šŸŽ
            → ((n : ā„•) → P (ā„•-to-ā„¤ā‚Š n) → P (ā„•-to-ā„¤ā‚Š (succ n)))
            → ((n : ā„•) → P (ā„•-to-ℤ₋ n) → P (ā„•-to-ℤ₋ (succ n)))
            → (z : ℤ) → P z
ℤ-induction {š“¤} P pā‚€ pā‚Š pā‚‹ šŸŽ       = pā‚€
ℤ-induction {š“¤} P pā‚€ pā‚Š pā‚‹ (pos i) = h (succ i)
 where
  Pā‚Š : ā„• → š“¤ ̇
  Pā‚Š = P ∘ ā„•-to-ā„¤ā‚Š
  h : (n : ā„•) → Pā‚Š n
  h = ā„•-induction pā‚€ pā‚Š
ℤ-induction {š“¤} P pā‚€ pā‚Š pā‚‹ (neg i) = h (succ i)
 where
  Pā‚‹ : ā„• → š“¤ ̇
  Pā‚‹ = P ∘ ā„•-to-ℤ₋
  h : (n : ā„•) → Pā‚‹ n
  h = ā„•-induction pā‚€ pā‚‹

\end{code}