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

open import Definition.Typed.EqualityRelation

module Definition.LogicalRelation.Substitution.Introductions.Nat {{eqrel : EqRelSet}} where
open EqRelSet {{...}}

open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Introductions.Universe

open import Tools.Unit
open import Tools.Product


-- Validity of the natural number type.
ℕᵛ :  {Γ l} ([Γ] : ⊩ᵛ Γ)  Γ ⊩ᵛ⟨ l   / [Γ]
ℕᵛ [Γ] ⊢Δ [σ] =  (idRed:*: ( ⊢Δ)) , λ _ x₂  id ( ⊢Δ)

-- Validity of the natural number type as a term.
ℕᵗᵛ :  {Γ} ([Γ] : ⊩ᵛ Γ)
     Γ ⊩ᵛ⟨ ¹    U / [Γ] / Uᵛ [Γ]
ℕᵗᵛ [Γ] ⊢Δ [σ] = let ⊢ℕ  =  ⊢Δ
                     [ℕ] =  (idRed:*: ( ⊢Δ))
                 in  Uₜ  (idRedTerm:*: ⊢ℕ)  (≅ₜ-ℕrefl ⊢Δ) [ℕ]
                 ,    x x₁  Uₜ₌   (idRedTerm:*: ⊢ℕ) (idRedTerm:*: ⊢ℕ)  
                                   (≅ₜ-ℕrefl ⊢Δ) [ℕ] [ℕ] (id ( ⊢Δ)))

-- Validity of zero.
zeroᵛ :  {Γ l} ([Γ] : ⊩ᵛ Γ)
       Γ ⊩ᵛ⟨ l  zero   / [Γ] / ℕᵛ [Γ]
zeroᵛ [Γ] ⊢Δ [σ] =
  ℕₜ zero (idRedTerm:*: (zero ⊢Δ)) (≅ₜ-zerorefl ⊢Δ) zero
    ,  _ x₁  ℕₜ₌ zero zero (idRedTerm:*: (zero ⊢Δ)) (idRedTerm:*: (zero ⊢Δ))
                    (≅ₜ-zerorefl ⊢Δ) zero)

-- Validity of successor of valid natural numbers.
sucᵛ :  {Γ n l} ([Γ] : ⊩ᵛ Γ)
         ([ℕ] : Γ ⊩ᵛ⟨ l   / [Γ])
      Γ ⊩ᵛ⟨ l  n   / [Γ] / [ℕ]
      Γ ⊩ᵛ⟨ l  suc n   / [Γ] / [ℕ]
sucᵛ ⊢Γ [ℕ] [n] ⊢Δ [σ] =
  sucTerm (proj₁ ([ℕ] ⊢Δ [σ])) (proj₁ ([n] ⊢Δ [σ]))
  ,  x x₁  sucEqTerm (proj₁ ([ℕ] ⊢Δ [σ])) (proj₂ ([n] ⊢Δ [σ]) x x₁))