Chuangjie Xu, 2015

\begin{code}

{-# OPTIONS --safe --without-K --no-exact-split #-} --

module ContinuityAxiom.Preliminaries where

open import MLTT.Plus-Properties
open import MLTT.Spartan
open import UF.Subsingletons

\end{code}

Less-than relation.

\begin{code}

infix 30 _≤_
infix 30 _<_

data _≤_ :     Set where
 ≤-zero : ∀{n : }  0  n
 ≤-succ : ∀{m n : }  m  n  succ m  succ n

≤-is-prop : {n m : }  is-prop (n  m)
≤-is-prop  ≤-zero     ≤-zero    = refl
≤-is-prop (≤-succ r) (≤-succ s) = ap ≤-succ (≤-is-prop r s)

_<_ :     Set
m < n = succ m  n

≤-refl : {n : }  n  n
≤-refl {0}      = ≤-zero
≤-refl {succ n} = ≤-succ ≤-refl

≤-trans : {a b c : }  a  b  b  c  a  c
≤-trans ≤-zero     v          = ≤-zero
≤-trans (≤-succ u) (≤-succ v) = ≤-succ (≤-trans u v)

≤-r-succ : {n m : }  n  m  n  succ m
≤-r-succ ≤-zero     = ≤-zero
≤-r-succ (≤-succ r) = ≤-succ (≤-r-succ r)

Lemma[n≤m+1→n≤m+n=m+1] : {n m : }  n  succ m  (n  m) + (n  succ m)
Lemma[n≤m+1→n≤m+n=m+1] {0}      {m}      r = inl ≤-zero
Lemma[n≤m+1→n≤m+n=m+1] {succ 0} {0}      r = inr refl
Lemma[n≤m+1→n≤m+n=m+1] {succ (succ n)} {0} (≤-succ ())
Lemma[n≤m+1→n≤m+n=m+1] {succ n} {succ m} (≤-succ r) = +functor c₀ c₁ IH
 where
  c₀ : n  m  succ n  succ m
  c₀ = ≤-succ

  c₁ : n  succ m  succ n  succ (succ m)
  c₁ = ap succ

  IH : (n  m) + (n  succ m)
  IH = Lemma[n≤m+1→n≤m+n=m+1] {n} {m} r

Lemma[n≰m→m<n] : {n m : }  ¬(n  m)  m < n
Lemma[n≰m→m<n] {0}      {m}      f = 𝟘-elim (f ≤-zero)
Lemma[n≰m→m<n] {succ n} {0}      f = ≤-succ ≤-zero
Lemma[n≰m→m<n] {succ n} {succ m} f = ≤-succ (Lemma[n≰m→m<n] (f  ≤-succ))

Lemma[m≤n∧n≤m→m=n] : ∀{m n : }  m  n  n  m  m  n
Lemma[m≤n∧n≤m→m=n] {0}      {0}      ≤-zero     ≤-zero      = refl
Lemma[m≤n∧n≤m→m=n] {0}      {succ n} ≤-zero     ()
Lemma[m≤n∧n≤m→m=n] {succ m} {0}      ()         ≤-zero
Lemma[m≤n∧n≤m→m=n] {succ m} {succ n} (≤-succ r) (≤-succ r') = ap succ (Lemma[m≤n∧n≤m→m=n] r r')

CoV-induction : {P :   Set}
               (∀ n  (∀ m  m < n  P m)  P n)
                n  P n
CoV-induction {P} step n = step n (claim n)
 where
  Q :   Set
  Q n =  m  succ m  n  P m

  qbase : Q 0
  qbase m ()

  qstep :  n  Q n  Q(succ n)
  qstep n qn m (≤-succ r) = step m  k u  qn k (≤-trans u r))

  claim :  n  Q n
  claim = ℕ-induction qbase qstep

\end{code}

Binary sequences

\begin{code}

₂ℕ : Set
₂ℕ =   𝟚

 : ₂ℕ
 i = 
 : ₂ℕ
 i = 

infixr 50 _∷_

data ₂Fin :   Set where
 ⟨⟩ : ₂Fin 0
 _∷_ : {n : }  𝟚  ₂Fin n  ₂Fin (succ n)

take : (m : )  ₂ℕ  ₂Fin m
take 0 α = ⟨⟩
take (succ n) α = α 0  take n (α  succ)

drop :   ₂ℕ  ₂ℕ
drop 0 α = α
drop (succ m) α = drop m (α  succ)

cons : {m : }  ₂Fin m  ₂ℕ  ₂ℕ
cons ⟨⟩      α          = α
cons (h  _) α 0        = h
cons (_  t) α (succ i) = cons t α i

Lemma[₂Fin-decidability] : (n : )  (Y : ₂Fin n  Set)
                          (∀ s  is-decidable (Y s))  is-decidable (∀ s  Y s)
Lemma[₂Fin-decidability] 0 Y decY = +functor c₀ c₁ (decY ⟨⟩)
 where
  c₀ : Y ⟨⟩   s  Y s
  c₀ y ⟨⟩ = y

  c₁ : ¬ (Y ⟨⟩)  ¬ (∀ s  Y s)
  c₁ f g = f (g ⟨⟩)
Lemma[₂Fin-decidability] (succ n) Y decY = cases c₀ c₁ IH₀
 where
  Y₀ : ₂Fin n  Set
  Y₀ s = Y (  s)

  decY₀ :  s  is-decidable (Y₀ s)
  decY₀ s = decY (  s)

  IH₀ : is-decidable (∀ s  Y₀ s)
  IH₀ = Lemma[₂Fin-decidability] n Y₀ decY₀

  Y₁ : ₂Fin n  Set
  Y₁ s = Y (  s)

  decY₁ :  s  is-decidable (Y₁ s)
  decY₁ s = decY (  s)

  IH₁ : is-decidable (∀ s  Y₁ s)
  IH₁ = Lemma[₂Fin-decidability] n Y₁ decY₁

  c₀ : (∀ s  Y₀ s)  is-decidable (∀ s  Y s)
  c₀ y₀ = +functor sc₀ sc₁ IH₁
   where
    sc₀ : (∀ s  Y₁ s)   s  Y s
    sc₀ y₁ (  s) = y₀ s
    sc₀ y₁ (  s) = y₁ s

    sc₁ : ¬ (∀ s  Y₁ s)  ¬ (∀ s  Y s)
    sc₁ f₁ ys = f₁  s  ys (  s))
  c₁ : ¬ (∀ s  Y₀ s)  is-decidable (∀ s  Y s)
  c₁ f₀ = inr  ys  f₀  s  ys (  s)))

\end{code}

"Agree with" relation over infinite sequences, which is an equivalence
relation and a deciable type:

\begin{code}

infixl 10 _=⟦_⟧_

data _=⟦_⟧_ {X : Set} : (  X)    (  X)  Set where
 =⟦zero⟧ : {α β :   X}  α =⟦ 0  β
 =⟦succ⟧ : {α β :   X}{n : }  α =⟦ n  β  α n  β n  α =⟦ succ n  β

=⟦⟧-sym : {n : }{α β : ₂ℕ}  α =⟦ n  β  β =⟦ n  α
=⟦⟧-sym {0}      =⟦zero⟧        = =⟦zero⟧
=⟦⟧-sym {succ n} (=⟦succ⟧ en e) = =⟦succ⟧ (=⟦⟧-sym en) (e ⁻¹)

=⟦⟧-trans : {n : }{α₀ α₁ α𝟚 : ₂ℕ}  α₀ =⟦ n  α₁  α₁ =⟦ n  α𝟚  α₀ =⟦ n  α𝟚
=⟦⟧-trans {0}      =⟦zero⟧        =⟦zero⟧          = =⟦zero⟧
=⟦⟧-trans {succ n} (=⟦succ⟧ en e) (=⟦succ⟧ en' e') = =⟦succ⟧ (=⟦⟧-trans en en') (e  e')

Lemma[=⟦]-cons-take] : {α β : ₂ℕ}  ∀(n : )  α =⟦ n  cons (take n α) β
Lemma[=⟦]-cons-take] {α} {β} n = lemma₁ n n ≤-refl
 where
  lemma₀ : ∀(α β : ₂ℕ)(m k : )  succ m  k  α m  cons (take k α) β m
  lemma₀ α β m        0        ()
  lemma₀ α β 0        (succ k) r          = refl
  lemma₀ α β (succ m) (succ k) (≤-succ r) = lemma₀ (α  succ) β m k r
  lemma₁ : ∀(m k : )  m  k  α =⟦ m  cons (take k α) β
  lemma₁ 0        k        ≤-zero     = =⟦zero⟧
  lemma₁ (succ m) 0        ()
  lemma₁ (succ m) (succ k) (≤-succ r) = =⟦succ⟧ (lemma₁ m (succ k) (≤-r-succ r))
                                                (lemma₀ α β m (succ k) (≤-succ r))

Lemma[=⟦]-=⟦]-take] : {α β γ : ₂ℕ}  ∀(n : )  α =⟦ n  β  β =⟦ n  cons (take n α) γ
Lemma[=⟦]-=⟦]-take] n en = =⟦⟧-trans (=⟦⟧-sym en) (Lemma[=⟦]-cons-take] n)

Lemma[cons-take-0] : {α β : ₂ℕ}  ∀(n : )  β 0  cons (take n α) β n
Lemma[cons-take-0]  0       = refl
Lemma[cons-take-0] (succ n) = Lemma[cons-take-0] n

Lemma[cons-=⟦]-≤] : {n m : }{α β : ₂ℕ}  (s : ₂Fin n)  m  n  cons s α =⟦ m  cons s β
Lemma[cons-=⟦]-≤] _ ≤-zero     = =⟦zero⟧
Lemma[cons-=⟦]-≤] s (≤-succ r) = =⟦succ⟧ (Lemma[cons-=⟦]-≤] s (≤-r-succ r)) (lemma s r)
 where
  lemma : {n m : }{α β : ₂ℕ}  (s : ₂Fin (succ n))  m  n  cons s α m  cons s β m
  lemma (b  s) ≤-zero     = refl
  lemma (b  s) (≤-succ r) = lemma s r

\end{code}