Martin Escardo & Chuangjie Xu, 2015

One of Brouwer's continuity principles is the following

    All functions ₂ℕ → ℕ are uniformly continuous

whose logical formulation is

    ∀ (f : ₂ℕ → ℕ ,  ∃ m : ℕ , ∀ α,β : ₂ℕ , α =[m] β → f α = f β

where α =[m] β expresses that the sequences α and β agree up to the
first m positions.

\begin{code}

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

module ContinuityAxiom.UniformContinuity where

open import ContinuityAxiom.ExitingTruncations
open import ContinuityAxiom.Preliminaries
open import MLTT.Spartan
open import MLTT.Two-Properties
open import UF.DiscreteAndSeparated
open import UF.FunExt
open import UF.Subsingletons

\end{code}

If function extensionality is available, then for any f : ₂ℕ → ℕ,
the type

  UC(f) = Σ n : ℕ , ∀(α β : ₂ℕ) → α =⟦ n ] β → f α = f β

has a propositional truncation, using the main lemma, because the
type family A(f) : ℕ → Set, defined by


  A(f,n) = (α β : ₂ℕ) → α =⟦ n ] β → f α = f β,

satisfies

(1) A(f,n) is a proposition for all n (using funext), and

(2) if A(f,n) holds then A(f,m) is decidable for all m < n.

\begin{code}

A : (₂ℕ  )    Set
A f n = (α β : ₂ℕ)  α =⟦ n  β  f α  f β

A-is-prop : Fun-Ext  (f : ₂ℕ  )   n  is-prop (A f n)
A-is-prop fe f n p q = dfunext fe  α
                      dfunext fe  β
                      dfunext fe  e
                      ℕ-is-set (p α β e) (q α β e))))

A-≤-is-decidable : ∀(f : ₂ℕ  )   n  A f n   m  m  n  is-decidable (A f m)
A-≤-is-decidable f  0       a _ _ = inl  α β _  a α β =⟦zero⟧)
A-≤-is-decidable f (succ n) a m r = cases c₀ c₁ (Lemma[n≤m+1→n≤m+n=m+1] r)
 where
  c₀ : m  n  is-decidable (A f m)
  c₀ r' = cases sc₀' sc₁' claim
   where
    claim : is-decidable ((s : ₂Fin n)  f (cons s )  f (cons s ))
    claim = Lemma[₂Fin-decidability] n  s  f (cons s )  f (cons s ))
                                        s  ℕ-is-discrete (f (cons s )) (f (cons s )))
    sc₀ : ((s : ₂Fin n)  f (cons s )  f (cons s )) 
          (α β : ₂ℕ)  α =⟦ n  β  f α  f β
    sc₀ efs α β en = cases ssc₀ ssc₁ (𝟚-is-discrete (α n) (β n))
     where
      ssc₀ : α n  β n  f α  f β
      ssc₀ e = a α β (=⟦succ⟧ en e)

      ssc₁ : ¬ (α n  β n)  f α  f β
      ssc₁ ne = cases sssc₀ sssc₁ Lemma[b=₀+b=₁]
       where
        s : ₂Fin n
        s = take n α

        sssc₀ : α n    f α  f β
        sssc₀ eα₀ = claim₁  (efs s)  claim₃ ⁻¹
         where
          eβ₁ : β n  
          eβ₁ = Lemma[b≠₀→b=₁]  eβ₀  ne (eα₀  eβ₀ ⁻¹))

          claim₀ : α =⟦ succ n  cons s 
          claim₀ = =⟦succ⟧ (Lemma[=⟦]-cons-take] n) (eα₀  (Lemma[cons-take-0] n))

          claim₁ : f α  f (cons s )
          claim₁ = a α (cons s ) claim₀

          claim₂ : β =⟦ succ n  cons s 
          claim₂ = =⟦succ⟧ (Lemma[=⟦]-=⟦]-take] n en) (eβ₁  (Lemma[cons-take-0] n))

          claim₃ : f β  f (cons s )
          claim₃ = a β (cons s ) claim₂

        sssc₁ : α n    f α  f β
        sssc₁ eα₁ = claim₁  (efs s)⁻¹  claim₃ ⁻¹
         where
          eβ₀ : β n  
          eβ₀ = Lemma[b≠₁→b=₀]  eβ₁  ne (eα₁  eβ₁ ⁻¹))

          claim₀ : α =⟦ succ n  (cons s )
          claim₀ = =⟦succ⟧ (Lemma[=⟦]-cons-take] n) (eα₁  (Lemma[cons-take-0] n))

          claim₁ : f α  f (cons s )
          claim₁ = a α (cons s ) claim₀

          claim₂ : β =⟦ succ n  (cons s )
          claim₂ = =⟦succ⟧ (Lemma[=⟦]-=⟦]-take] n en) (eβ₀  (Lemma[cons-take-0] n))

          claim₃ : f β  f (cons s )
          claim₃ = a β (cons s ) claim₂

    sc₀' : (∀(s : ₂Fin n)
          f (cons s )  f (cons s ))
          is-decidable (∀(α β : ₂ℕ)  α =⟦ m  β  f α  f β)
    sc₀' ps = A-≤-is-decidable f n (sc₀ ps) m r'

    sc₁ : ¬ (∀(s : ₂Fin n)  f (cons s )  f (cons s ))
         ¬ (∀(α β : ₂ℕ)  α =⟦ m  β  f α  f β)
    sc₁ fs pn = fs  s  pn (cons s ) (cons s ) (Lemma[cons-=⟦]-≤] s r'))

    sc₁' : ¬ (∀(s : ₂Fin n)  f (cons s )  f (cons s ))
          is-decidable (∀(α β : ₂ℕ)  α =⟦ m  β  f α  f β)
    sc₁' fs = inr (sc₁ fs)

  c₁ : m  succ n  is-decidable (A f m)
  c₁ e = inl (transport (A f) (e ⁻¹) a)

\end{code}

Therefore, the truncation of UC(f) exists and hence we have two
formulations of the uniform continuity principle:

\begin{code}

UC : Set
UC = (f : ₂ℕ  )  ∥Σ (\(n : )  (α β : ₂ℕ)  α =⟦ n  β  f α  f β) 

CH-UC : Set
CH-UC = (f : ₂ℕ  )  Σ \(n : )  (α β : ₂ℕ)  α =⟦ n  β  f α  f β

\end{code}

Moreover, the above types are logically equivalent.

\begin{code}

Theorem : CH-UC  UC
Theorem =  ch-uc f  ΣA→∥ΣA∥ (A-≤-is-decidable f) (ch-uc f)) ,
           uc f   ∥ΣA∥→ΣA (uc f))

\end{code}