Added algebra for ZOL and syntax and initial morphism and the proof of it being initial

This commit is contained in:
Mysaa 2023-08-02 23:55:25 +02:00
parent d70739091e
commit 370daed594
Signed by: Mysaa
GPG Key ID: 7054D5D6A90F084F
7 changed files with 1188 additions and 38 deletions

View File

@ -1,4 +1,4 @@
\begin{code}
git s\begin{code}
{-# OPTIONS --prop --rewriting #-}
open import PropUtil
@ -281,6 +281,12 @@ module FFOLInitial where
εₚ : Subp Δₚ ◇p
_,ₚ_ : {A : For Δₜ} → (σ : Subp Δₚ Δₚ') → Pf Δₜ Δₚ A → Subp Δₚ (Δₚ' ▹p⁰ A)
-- We write down the access functions from the algebra, in restricted versions
πₚ¹ : ∀{Γₜ}{Γₚ Δₚ : Conp Γₜ} {A : For Γₜ} → Subp Δₚ (Γₚ ▹p⁰ A) → Subp Δₚ Γₚ
πₚ¹ (σₚ ,ₚ pf) = σₚ
πₚ² : ∀{Γₜ}{Γₚ Δₚ : Conp Γₜ} {A : For Γₜ} → Subp Δₚ (Γₚ ▹p⁰ A) → Pf Γₜ Δₚ A
πₚ² (σₚ ,ₚ pf) = pf
-- The action of Cont's morphisms on Subp
_[_]σₚ : Subp {Δₜ} Δₚ Δₚ' → (σ : Subt Γₜ Δₜ) → Subp {Γₜ} (Δₚ [ σ ]c) (Δₚ' [ σ ]c)
εₚ [ σₜ ]σₚ = εₚ
@ -400,12 +406,10 @@ module FFOLInitial where
,ₜ∘* : {Γ Δ Ξ : Con}{σ : Sub Γ Ξ}{δ : Sub Δ Γ}{t : Tm (Con.t Γ)} → (σ ,ₜ* t) ∘ δ ≡ (σ ∘ δ) ,ₜ* (t [ Sub.t δ ]t)
,ₜ∘* {Γ} {Δ} {Ξ} {sub σₜ σₚ} {sub δₜ δₚ} {t} = sub= refl
-- And for proof substitutions
πₚ₁ : ∀{Γₜ}{Γₚ Δₚ : Conp Γₜ} {A : For Γₜ} → Subp Δₚ (Γₚ ▹p⁰ A) → Subp Δₚ Γₚ
πₚ₁ (σₚ ,ₚ pf) = σₚ
-- And for proof substitutions
πₚ¹* : {Γ Δ : Con} {A : For (Con.t Γ)} → Sub Δ (Γ ▹p A) → Sub Δ Γ
πₚ¹* (sub σₜ σaₚ) = sub σₜ (πₚ σaₚ)
πₚ¹* (sub σₜ σaₚ) = sub σₜ (πₚ¹ σaₚ)
πₚ²* : {Γ Δ : Con} {F : For (Con.t Γ)} (σ : Sub Δ (Γ ▹p F)) → Pf (Con.t Δ) (Con.p Δ) (F [ Sub.t (πₚ¹* σ) ]f)
πₚ²* (sub σₜ (σₚ ,ₚ pf)) = pf
_,ₚ*_ : {Γ Δ : Con} {F : For (Con.t Γ)} (σ : Sub Δ Γ) → Pf (Con.t Δ) (Con.p Δ) (F [ Sub.t σ ]f) → Sub Δ (Γ ▹p F)
@ -511,37 +515,96 @@ module FFOLInitial where
Pf*-∘ {Ξₚ = ◇p} α β = tt
Pf*-∘ {Ξₚ = Ξₚ ▹p⁰ A} α β = ⟨ Pf*-∘ (proj₁ α) β , Pf*Pf β (proj₂ α) ⟩
{-
module InitialMorphism (M : FFOL {lsuc lzero} {lsuc lzero} {lsuc lzero} {lsuc lzero} {lsuc lzero}) where
{-# TERMINATING #-}
mCon : Con → (FFOL.Con M)
mFor : {Γ : Con} → (For (Con.t Γ)) → (FFOL.For M (mCon Γ))
mTm : {Γ : Con} → (Tm (Con.t Γ)) → (FFOL.Tm M (mCon Γ))
mSub : {Δ : Con}{Γ : Con} → Sub Δ Γ → (FFOL.Sub M (mCon Δ) (mCon Γ))
m⊢ : {Γ : Con} {A : For (Con.t Γ)} → Pf (Con.t Γ) (Con.p Γ) A → FFOL._⊢_ M (mCon Γ) (mFor A)
e▹ₜ : {Γ : Con} → mCon (con (Con.t Γ ▹t⁰) (Con.p Γ [ wkₜσₜ idₜ ]c)) ≡ FFOL._▹ₜ M (mCon Γ)
e▹ₚ : {Γ : Con}{A : For (Con.t Γ)} → mCon (Γ ▹p A) ≡ FFOL._▹ₚ_ M (mCon Γ) (mFor A)
e[]f : {Γ Δ : Con}{A : For (Con.t Γ)}{σ : Sub Δ Γ} → mFor (A [ Sub.t σ ]f) ≡ FFOL._[_]f M (mFor A) (mSub σ)
mCon (con ◇t ◇p) = FFOL.◇ M
mCon (con (Γₜ ▹t⁰) ◇p) = FFOL._▹ₜ M (mCon (con Γₜ ◇p))
mCon (con Γₜ (Γₚ ▹p⁰ A)) = FFOL._▹ₚ_ M (mCon (con Γₜ Γₚ)) (mFor {con Γₜ Γₚ} A)
mSub {Γ = con ◇t ◇p} (sub εₜ εₚ) = FFOL.ε M
mSub {Γ = con (Γₜ ▹t⁰) ◇p} (sub (σₜ ,ₜ t) εₚ) = FFOL._,ₜ_ M (mSub (sub σₜ εₚ)) (mTm t)
mSub {Δ = Δ} {Γ = con Γₜ (Γₚ ▹p⁰ A)} (sub σₜ (σₚ ,ₚ pf)) = subst (FFOL.Sub M (mCon Δ)) (≡sym e▹ₚ) (FFOL._,ₚ_ M (mSub (sub σₜ σₚ)) (substP (FFOL._⊢_ M (mCon Δ)) e[]f (m⊢ pf)))
mCont : Cont → (FFOL.Con M)
mCont ◇t = FFOL.◇ M
mCont (Γₜ ▹t⁰) = FFOL._▹ₜ M (mCont Γₜ)
mTmT : {Γₜ : Cont} → Tm Γₜ → (FFOL.Tm M (mCont Γₜ))
-- Zero is (πₜ² id)
mTm {con (Γₜ ▹t⁰) ◇p} (var tvzero) = FFOL.πₜ² M (FFOL.id M)
mTmT {Γₜ ▹t⁰} (var tvzero) = FFOL.πₜ² M (FFOL.id M)
-- N+1 is wk[tm N]
mTm {con (Γₜ ▹t⁰) ◇p} (var (tvnext tv)) = (FFOL._[_]t M (mTm (var tv)) (FFOL.πₜ¹ M (FFOL.id M)))
-- If we have a formula in context, we proof-weaken the term (should not change a thing)
mTm {con (Γₜ ▹t⁰) (Γₚ ▹p⁰ A)} (var tv) = FFOL._[_]t M (mTm {con (Γₜ ▹t⁰) Γₚ} (var tv)) (FFOL.πₚ¹ M (FFOL.id M))
mTmT {Γₜ ▹t⁰} (var (tvnext tv)) = (FFOL._[_]t M (mTmT (var tv)) (FFOL.πₜ¹ M (FFOL.id M)))
mFor (R t u) = FFOL.R M (mTm t) (mTm u)
mFor (A ⇒ B) = FFOL._⇒_ M (mFor A) (mFor B)
mFor {Γ} (∀∀ A) = FFOL.∀∀ M (subst (FFOL.For M) (e▹ₜ {Γ = Γ}) (mFor {Γ = Γ ▹t} A))
mForT : {Γₜ : Cont} → (For Γₜ) → (FFOL.For M (mCont Γₜ))
mForT (R t u) = FFOL.R M (mTmT t) (mTmT u)
mForT (A ⇒ B) = FFOL._⇒_ M (mForT A) (mForT B)
mForT {Γ} (∀∀ A) = FFOL.∀∀ M (mForT A)
mSubt : {Δₜ : Cont}{Γₜ : Cont} → Subt Δₜ Γₜ → (FFOL.Sub M (mCont Δₜ) (mCont Γₜ))
mSubt εₜ = FFOL.ε M
mSubt (σₜ ,ₜ t) = FFOL._,ₜ_ M (mSubt σₜ) (mTmT t)
mConp : {Γₜ : Cont} → Conp Γₜ → (FFOL.Con M)
mForP : {Γₜ : Cont} {Γₚ : Conp Γₜ} → (For Γₜ) → (FFOL.For M (mConp Γₚ))
mConp {Γₜ} ◇p = mCont Γₜ
mConp {Γₜ} (Γₚ ▹p⁰ A) = FFOL._▹ₚ_ M (mConp Γₚ) (mForP {Γₚ = Γₚ} A)
mForP {Γₜ} {Γₚ = ◇p} A = mForT {Γₜ} A
mForP {Γₚ = Γₚ ▹p⁰ B} A = FFOL._[_]f M (mForP {Γₚ = Γₚ} A) (FFOL.πₚ¹ M (FFOL.id M))
mTmP : {Γₜ : Cont}{Γₚ : Conp Γₜ} → Tm Γₜ → (FFOL.Tm M (mConp Γₚ))
mTmP {Γₜ}{Γₚ = ◇p} t = mTmT {Γₜ} t
mTmP {Γₚ = Γₚ ▹p⁰ x} t = FFOL._[_]t M (mTmP {Γₚ = Γₚ} t) (FFOL.πₚ¹ M (FFOL.id M))
mCon : Con → (FFOL.Con M)
mCon Γ = mConp {Con.t Γ} (Con.p Γ)
mFor : {Γ : Con} → (For (Con.t Γ)) → (FFOL.For M (mCon Γ))
mFor {Γ} A = mForP {Con.t Γ} {Con.p Γ} A
mTm : {Γ : Con} → Tm (Con.t Γ) → (FFOL.Tm M (mCon Γ))
mTm {Γ} t = mTmP {Con.t Γ} {Con.p Γ} t
e▹ₜT : {Γₜ : Cont} → mCont (Γₜ ▹t⁰) ≡ FFOL._▹ₜ M (mCont Γₜ)
e▹ₜT = refl
e▹ₜP : {Γₜ : Cont}{Γₚ : Conp Γₜ} → mConp {Γₜ ▹t⁰} (Γₚ [ wkₜσₜ idₜ ]c) ≡ FFOL._▹ₜ M (mConp Γₚ)
e▹ₜP {Γₜ = Γₜ} {Γₚ = ◇p} = e▹ₜT {Γₜ = Γₜ}
e▹ₜP {Γₚ = Γₚ ▹p⁰ A} = {!!}
e▹ₜ : {Γ : Con} → mCon (con (Con.t Γ ▹t⁰) (Con.p Γ [ wkₜσₜ idₜ ]c)) ≡ FFOL._▹ₜ M (mCon Γ)
e▹ₜ {Γ} = e▹ₜP {Γₜ = Con.t Γ} {Γₚ = Con.p Γ}
mForT⇒ : {Γₜ : Cont}{A B : For Γₜ} → mForT {Γₜ} (A ⇒ B) ≡ FFOL._⇒_ M (mForT {Γₜ} A) (mForT {Γₜ} B)
mForT⇒ = refl
mForP⇒ : {Γₜ : Cont}{Γₚ : Conp Γₜ}{A B : For Γₜ} → mForP {Γₜ} {Γₚ} (A ⇒ B) ≡ FFOL._⇒_ M (mForP {Γₜ} {Γₚ} A) (mForP {Γₜ} {Γₚ} B)
mForP⇒ {Γₜ} {Γₚ = ◇p}{A}{B} = mForT⇒ {Γₜ}{A}{B}
mForP⇒ {Γₚ = Γₚ ▹p⁰ C}{A}{B} = ≡tran (cong (λ X → (M FFOL.[ X ]f) _) (mForP⇒ {Γₚ = Γₚ})) (FFOL.[]f-⇒ M {F = mForP {Γₚ = Γₚ} A} {G = mForP {Γₚ = Γₚ} B} {σ = (FFOL.πₚ¹ M (FFOL.id M))})
mFor⇒ : {Γ : Con}{A B : For (Con.t Γ)} → mFor {Γ} (A ⇒ B) ≡ FFOL._⇒_ M (mFor {Γ} A) (mFor {Γ} B)
mFor⇒ {Γ} = mForP⇒ {Con.t Γ} {Con.p Γ}
mForT∀∀ : {Γₜ : Cont}{A : For (Γₜ ▹t⁰)} → mForT {Γₜ} (∀∀ A) ≡ FFOL.∀∀ M (mForT {Γₜ ▹t⁰} A)
mForT∀∀ = refl
mForP∀∀ : {Γₜ : Cont}{Γₚ : Conp Γₜ}{A : For (Γₜ ▹t⁰)} → mForP {Γₜ} {Γₚ} (∀∀ A) ≡ FFOL.∀∀ M (subst (FFOL.For M) (e▹ₜP {Γₜ} {Γₚ}) (mForP {Γₜ ▹t⁰} {Γₚ ▹tp} A))
-- mFor∀∀ : {Γ : Con}{A : For ((Con.t Γ) ▹t⁰)} → mFor {Γ} (∀∀ A) ≡ FFOL.∀∀ M (mFor {Γ ▹t} A)
--mForL : {Γ : Con}{A : For (Con.t Γ ▹t⁰)}{t : Tm (Con.t Γ)} → FFOL._[_]f M (mFor {Γ = {!Γ ▹t!}} A) (FFOL._,ₜ_ M (FFOL.id M) (mTm {Γ = Γ} t)) ≡ mFor {Γ = Γ} (A [ idₜ ,ₜ t ]f)
m⊢ : {Γ : Con} {A : For (Con.t Γ)} → Pf (Con.t Γ) (Con.p Γ) A → FFOL._⊢_ M (mCon Γ) (mFor {Γ = Γ} A)
m⊢ (var pvzero) = FFOL.πₚ² M (FFOL.id M)
m⊢ (var (pvnext pv)) = FFOL._[_]p M (m⊢ (var pv)) (FFOL.πₚ¹ M (FFOL.id M))
m⊢ {Γ} {B} (app {A = A} pf pf') = FFOL.app M (substP (FFOL._⊢_ M _) (mFor⇒ {Γ}{A}{B}) (m⊢ pf)) (m⊢ pf')
m⊢ {Γ} {A ⇒ B} (lam pf) = substP (FFOL._⊢_ M _) (≡sym (mFor⇒ {Γ}{A}{B})) (FFOL.lam M (m⊢ pf))
m⊢ {Γ} (p∀∀e {A = A} {t = t} pf) = substP (FFOL._⊢_ M _) {!!} (FFOL.∀e M {F = mFor {{!!}} A} (substP (FFOL._⊢_ M _) {!!} (m⊢ pf)) {t = mTm {Γ} t})
m⊢ {Γ} (p∀∀i {A = A} pf) = substP (FFOL._⊢_ M _) (≡sym mForP∀∀) (FFOL.∀i M (substP (λ Ξ → FFOL._⊢_ M Ξ (mFor A)) e▹ₜ (m⊢ pf)))
mSubp : {Γₜ : Cont}{Δₚ Γₚ : Conp Γₜ} → Subp {Γₜ} Δₚ Γₚ → (FFOL.Sub M (mConp Δₚ) (mConp Γₚ))
mSubp {Γₜ} {Γₚ = ◇p} σₚ = {!FFOL.ε M!}
mSubp {Γₚ = Γₚ ▹p⁰ A} σₚ = FFOL._,ₚ_ M (mSubp (πₚ¹ σₚ)) {!m⊢ (πₚ² σₚ)!}
mSub : {Δ : Con}{Γ : Con} → Sub Δ Γ → (FFOL.Sub M (mCon Δ) (mCon Γ))
mSub {Δ}{Γ} σ = FFOL._∘_ M (subst (FFOL.Sub M (mCont (Con.t Δ))) {!!} (mSubt (Sub.t σ))) ({!mSubp (Sub.p σ)!})
e▹ₚ : {Γ : Con}{A : For (Con.t Γ)} → mCon (Γ ▹p A) ≡ FFOL._▹ₚ_ M (mCon Γ) (mFor {Γ} A)
e[]f : {Γ Δ : Con}{A : For (Con.t Γ)}{σ : Sub Δ Γ} → mFor {Δ} (A [ Sub.t σ ]f) ≡ FFOL._[_]f M (mFor {Γ} A) (mSub σ)
{-
e▹ₜ {con Γₜ ◇p} = refl
e▹ₜ {con Γₜ (Γₚ ▹p⁰ A)} = ≡tran²
(cong₂' (FFOL._▹ₚ_ M) (e▹ₜ {con Γₜ Γₚ}) (cong (subst (FFOL.For M) (e▹ₜ {Γ = con Γₜ Γₚ})) (e[]f {A = A}{σ = πₜ¹* id})))
@ -552,13 +615,8 @@ module FFOLInitial where
{!!})
(cong (M FFOL.▹ₜ) (≡sym (e▹ₚ {con Γₜ Γₚ})))
-- substP (λ X → FFOL._▹ₚ_ M X (mFor {Γ = ?} (A [ wkₜσₜ idₜ ]f)) ≡ (FFOL._▹ₜ M (mCon (con Γₜ (Γₚ ▹p⁰ A))))) (≡sym (e▹ₜ {Γ = con Γₜ Γₚ})) ?
-}
m⊢ {Γ}{A}(var pvzero) = {!substP (λ X → FFOL._⊢_ M X (mFor A)) (≡sym e▹ₚ) ?!}
m⊢ (var (pvnext pv)) = {!!}
m⊢ (app pf pf') = FFOL.app M (m⊢ pf) (m⊢ pf')
m⊢ (lam pf) = FFOL.lam M {!m⊢ pf!}
m⊢ (p∀∀e pf) = {!FFOL.∀e M (m⊢ pf)!}
m⊢ {Γ}{∀∀ A}(p∀∀i pf) = FFOL.∀i M (substP (λ X → FFOL._⊢_ M X (subst (FFOL.For M) (≡sym e▹ₜ) (mFor A))) e▹ₜ {!m⊢ pf!})
e[]f = {!!}
e▹ₚ = {!!}
@ -603,9 +661,9 @@ module FFOLInitial where
e∀∀ = {!!}
-}
m : Mapping ffol M
m = record { mCon = mCon ; mSub = mSub ; mTm = mTm ; mFor = mFor ; m⊢ = m⊢ }
m = record { mCon = mCon ; mSub = mSub ; mTm = λ {Γ} t → mTm {Γ} t ; mFor = λ {Γ} A → mFor {Γ} A ; m⊢ = m⊢ }
--mor : (M : FFOL) → Morphism ffol M
--mor M = record {InitialMorphism M}
-}
\end{code}

765
FFOLInitial2.lagda Normal file
View File

@ -0,0 +1,765 @@
git s\begin{code}
{-# OPTIONS --prop --rewriting #-}
open import PropUtil
module FFOLInitial2 where
open import FFOL
open import Agda.Primitive
open import ListUtil
data Con : Set₁
data TmVar : Con → Set₁
data Tm : Con → Set₁
data For : Con → Set₁
data Con where
◇ : Con
_▹ₜ : Con → Con
_▹ₚ_ : (Γ : Con) → For Γ → Con
variable
Γ Δ Ξ : Con
-- A term variable is a de-bruijn variable, TmVar n ≈ ⟦0,n-1⟧
data TmVar where
tvzero : TmVar (Γ ▹ₜ)
tvnext : TmVar Γ → TmVar (Γ ▹ₜ)
-- For now, we only have term variables (no function symbol)
data Tm where
var : TmVar Γ → Tm Γ
-- Now we can define formulæ
data For where
R : Tm Γ → Tm Γ → For Γ
_⇒_ : For Γ → For Γ → For Γ
∀∀ : For (Γ ▹ₜ) → For Γ
-------------------------------------------------------------------
-------------------------------------------------------------------
data Sub : Con → Con → Set₁
data Ren : Con → Con → Set₁
id : Sub Γ Γ
idᵣ : Ren Γ Γ
_∘_ : {Γ Δ Ξ : Con} → Sub Δ Ξ → Sub Γ Δ → Sub Γ Ξ
_∘ᵣ_ : {Γ Δ Ξ : Con} → Ren Δ Ξ → Ren Γ Δ → Ren Γ Ξ
_[_]t : Tm Γ → Sub Δ Γ → Tm Δ
_[_]f : For Γ → Sub Δ Γ → For Δ
_[_]tvᵣ : TmVar Γ → Ren Δ Γ → TmVar Δ
_[_]tᵣ : Tm Γ → Ren Δ Γ → Tm Δ
_[_]fᵣ : For Γ → Ren Δ Γ → For Δ
[]f-∘ : {Γ Δ Ξ : Con} → {α : Sub Ξ Δ}{β : Sub Δ Γ}{A : For Γ} → A [ β ∘ α ]f ≡ (A [ β ]f) [ α ]f
[]t-∘ : {Γ Δ Ξ : Con} → {α : Sub Ξ Δ}{β : Sub Δ Γ}{t : Tm Γ} → t [ β ∘ α ]t ≡ (t [ β ]t) [ α ]t
[]fᵣ-∘ᵣ : {Γ Δ Ξ : Con} → {α : Ren Ξ Δ}{β : Ren Δ Γ}{A : For Γ} → A [ β ∘ᵣ α ]fᵣ ≡ (A [ β ]fᵣ) [ α ]fᵣ
[]tᵣ-∘ᵣ : {Γ Δ Ξ : Con} → {α : Ren Ξ Δ}{β : Ren Δ Γ}{t : Tm Γ} → t [ β ∘ᵣ α ]tᵣ ≡ (t [ β ]tᵣ) [ α ]tᵣ
data PfVar : (Γ : Con) → For Γ → Prop₁
data Pf : (Γ : Con) → For Γ → Prop₁
πₜ¹ : Sub Δ (Γ ▹ₜ) → Sub Δ Γ
πₜ² : Sub Δ (Γ ▹ₜ) → Tm Δ
πₚ¹ : {Γ Δ : Con} {A : For Γ} → Sub Δ (Γ ▹ₚ A) → Sub Δ Γ
πₚ² : {Γ Δ : Con} {A : For Γ} → (σ : Sub Δ (Γ ▹ₚ A)) → Pf Δ (A [ πₚ¹ σ ]f)
_[_]p : {Γ Δ : Con} → {A : For Γ} → Pf Γ A → (σ : Sub Δ Γ) → Pf Δ (A [ σ ]f)
_[_]pvᵣ : {Γ Δ : Con} → {A : For Γ} → PfVar Γ A → (σ : Ren Δ Γ) → PfVar Δ (A [ σ ]fᵣ)
data Sub where
ε : Sub Γ ◇
_,ₜ_ : Sub Δ Γ → Tm Δ → Sub Δ (Γ ▹ₜ)
_,ₚ_ : {A : For Γ} → (σ : Sub Δ Γ) → Pf Δ (A [ σ ]f) → Sub Δ (Γ ▹ₚ A)
πₜ¹ (σ ,ₜ t) = σ
πₜ² (σ ,ₜ t) = t
πₚ¹ (σ ,ₚ pf) = σ
πₚ² (σ ,ₚ pf) = pf
data Ren where
εᵣ : Ren Γ ◇
_,ₜᵣ_ : Ren Δ Γ → TmVar Δ → Ren Δ (Γ ▹ₜ)
_,ₚᵣ_ : {A : For Γ} → (σ : Ren Δ Γ) → PfVar Δ (A [ σ ]fᵣ) → Ren Δ (Γ ▹ₚ A)
πₜ¹ᵣ : Ren Δ (Γ ▹ₜ) → Ren Δ Γ
πₜ²ᵣ : Ren Δ (Γ ▹ₜ) → TmVar Δ
πₚ¹ᵣ : {Γ Δ : Con} {A : For Γ} → Ren Δ (Γ ▹ₚ A) → Ren Δ Γ
πₚ²ᵣ : {Γ Δ : Con} {A : For Γ} → (σ : Ren Δ (Γ ▹ₚ A)) → PfVar Δ (A [ πₚ¹ᵣ σ ]fᵣ)
πₜ¹ᵣ (σ ,ₜᵣ t) = σ
πₜ²ᵣ (σ ,ₜᵣ t) = t
πₚ¹ᵣ (σ ,ₚᵣ pf) = σ
πₚ²ᵣ (σ ,ₚᵣ pf) = pf
liftᵣₜ : Ren Δ Γ → Ren (Δ ▹ₜ) (Γ ▹ₜ)
liftᵣₜ εᵣ = εᵣ ,ₜᵣ tvzero
liftᵣₜ (σ ,ₜᵣ t) = (liftᵣₜ σ) ,ₜᵣ tvzero
liftᵣₜ (σ ,ₚᵣ p) = {!!}
idᵣ {◇} = εᵣ
idᵣ {Γ ▹ₜ} = liftᵣₜ (idᵣ {Γ})
idᵣ {Γ ▹ₚ A} = {!!}
εᵣ ∘ᵣ β = εᵣ
(α ,ₜᵣ t) ∘ᵣ β = (α ∘ᵣ β) ,ₜᵣ (t [ β ]tvᵣ)
(α ,ₚᵣ pf) ∘ᵣ β = (α ∘ᵣ β) ,ₚᵣ substP (PfVar _) (≡sym []fᵣ-∘ᵣ) (pf [ β ]pvᵣ)
tvzero [ _ ,ₜᵣ tv ]tvᵣ = tv
tvnext tv [ σ ,ₜᵣ _ ]tvᵣ = tv [ σ ]tvᵣ
var tv [ σ ]tᵣ = var (tv [ σ ]tvᵣ)
(R t u) [ σ ]fᵣ = R (t [ σ ]tᵣ) (u [ σ ]tᵣ)
(A ⇒ B) [ σ ]fᵣ = (A [ σ ]fᵣ) ⇒ (B [ σ ]fᵣ)
(∀∀ A) [ σ ]fᵣ = ∀∀ (A [ (σ ∘ᵣ πₜ¹ᵣ idᵣ) ,ₜᵣ (πₜ²ᵣ idᵣ) ]fᵣ)
{-
-- We now show how we can extend renamings
rightRen :{A : For Δₜ} → Ren Γₚ Δₚ → Ren Γₚ (Δₚ ▹p⁰ A)
rightRen zeroRen = zeroRen
rightRen (leftRen x h) = leftRen (pvnext x) (rightRen h)
bothRen : {A : For Γₜ} → Ren Γₚ Δₚ → Ren (Γₚ ▹p⁰ A) (Δₚ ▹p⁰ A)
bothRen zeroRen = leftRen pvzero zeroRen
bothRen (leftRen x h) = leftRen pvzero (leftRen (pvnext x) (rightRen h))
reflRen : Ren Γₚ Γₚ
reflRen {Γₚ = ◇p} = zeroRen
reflRen {Γₚ = Γₚ ▹p⁰ x} = bothRen reflRen
-}
id = {!!}
ε ∘ β = ε
(α ,ₜ t) ∘ β = (α ∘ β) ,ₜ (t [ β ]t)
(α ,ₚ pf) ∘ β = (α ∘ β) ,ₚ substP (Pf _) (≡sym []f-∘) (pf [ β ]p)
var tvzero [ σ ,ₜ t ]t = t
var (tvnext tv) [ σ ,ₜ t ]t = var tv [ σ ]t
(R t u) [ σ ]f = R (t [ σ ]t) (u [ σ ]t)
(A ⇒ B) [ σ ]f = (A [ σ ]f) ⇒ (B [ σ ]f)
(∀∀ A) [ σ ]f = ∀∀ (A [ (σ ∘ πₜ¹ id) ,ₜ πₜ² id ]f)
[]t-∘ {β = β ,ₜ t} {t = var tvzero} = {!!}
[]t-∘ {t = var (tvnext tv)} = {!!}
[]f-∘ {A = R t u} = {!cong₂ R!}
[]f-∘ {A = A ⇒ B} = {!!}
[]f-∘ {A = ∀∀ A} = {!!}
data PfVar where
pvzero : {A : For Γ} → PfVar (Γ ▹ₚ A) (A [ πₚ¹ id ]f)
pvnext : {A B : For Γ} → PfVar Γ A → PfVar (Γ ▹ₚ B) (A [ πₚ¹ id ]f)
data Pf where
var : {A : For Γ} → PfVar Γ A → Pf Γ A
app : {A B : For Γ} → Pf Γ (A ⇒ B) → Pf Γ A → Pf Γ B
lam : {A B : For Γ} → Pf (Γ ▹ₚ A) (B [ πₚ¹ id ]f) → Pf Γ (A ⇒ B)
p∀∀e : {A : For (Γ ▹ₜ)} → {t : Tm Γ} → Pf Γ (∀∀ A) → Pf Γ (A [ id ,ₜ t ]f)
p∀∀i : {A : For (Γ ▹ₜ)} → Pf (Γ ▹ₜ) A → Pf Γ (∀∀ A)
var pvzero [ σ ,ₚ pf ]p = {!pf!}
var (pvnext pv) [ σ ]p = {!!}
app pf pf' [ σ ]p = {!!}
lam pf [ σ ]p = {!!}
p∀∀e pf [ σ ]p = {!!}
p∀∀i pf [ σ ]p = {!!}
{-
{-- TERM CONTEXTS - TERMS - FORMULAE - TERM SUBSTITUTIONS --}
-- Term contexts are isomorphic to Nat
data Cont : Set₁ where
◇t : Cont
_▹t⁰ : Cont → Cont
variable
Γₜ Δₜ Ξₜ : Cont
-- Then we define term substitutions
-- We write down the access functions from the algebra, in restricted versions
-- And their equalities (the fact that there are reciprocical)
πₜ²∘,ₜ : {σₜ : Subt Δₜ Γₜ} → {t : Tm Δₜ} → πₜ² (σₜ ,ₜ t) ≡ t
πₜ²∘,ₜ = refl
πₜ¹∘,ₜ : {σₜ : Subt Δₜ Γₜ} → {t : Tm Δₜ} → πₜ¹ (σₜ ,ₜ t) ≡ σₜ
πₜ¹∘,ₜ = refl
,ₜ∘πₜ : {σₜ : Subt Δₜ (Γₜ ▹t⁰)} → (πₜ¹ σₜ) ,ₜ (πₜ² σₜ) ≡ σₜ
,ₜ∘πₜ {σₜ = σₜ ,ₜ t} = refl
-- We now define the action of term substitutions on terms
-- We define weakenings of the term-context for terms
-- «A term of n variables can be seen as a term of n+1 variables»
wkₜt : Tm Γₜ → Tm (Γₜ ▹t⁰)
wkₜt (var tv) = var (tvnext tv)
-- From a substition into n variables, we get a substitution into n+1 variables which don't use the last one
wkₜσₜ : Subt Δₜ Γₜ → Subt (Δₜ ▹t⁰) Γₜ
wkₜσₜ εₜ = εₜ
wkₜσₜ (σ ,ₜ t) = (wkₜσσ) ,ₜ (wkₜt t)
-- From a substitution into n variables, we construct a substitution from n+1 variables to n+1 variables which maps it to itself
-- i.e. 0 -> 0 and for all i ->(old) σ(i) we get i+1 -> σ(i)+1
lfₜσₜ : Subt Δₜ Γₜ → Subt (Δₜ ▹t⁰) (Γₜ ▹t⁰)
lfₜσσ = (wkₜσσ) ,ₜ (var tvzero)
-- We show how wkₜt and interacts with [_]t
wkₜ[]t : {α : Subt Δₜ Γₜ} → {t : Tm Γₜ} → wkₜt (t [ α ]t) ≡ (wkₜt t [ lfₜσα ]t)
wkₜ[]t {α = α ,ₜ t} {var tvzero} = refl
wkₜ[]t {α = α ,ₜ t} {var (tvnext tv)} = wkₜ[]t {t = var tv}
-- We can now subst on formulæ
-- We now can define identity and composition of term substitutions
idₜ : Subt Γₜ Γₜ
idₜ {◇t} = εₜ
idₜ {Γₜ ▹t⁰} = lfₜσₜ (idₜ {Γₜ})
_∘ₜ_ : Subt Δₜ Γₜ → Subt Ξₜ Δₜ → Subt Ξₜ Γₜ
εₜ ∘ₜ β = εₜ
(α ,ₜ x) ∘ₜ β = (α ∘ₜ β) ,ₜ (x [ β ]t)
-- We now have to show all their equalities (idₜ and ∘ₜ respect []t, []f, wkₜ, lfₜ, categorical rules
-- Substitution for terms
[]t-id : {t : Tm Γₜ} → t [ idₜ {Γₜ} ]t ≡ t
[]t-id {Γₜ ▹t⁰} {var tvzero} = refl
[]t-id {Γₜ ▹t⁰} {var (tvnext tv)} = substP (λ t → t ≡ var (tvnext tv)) (wkₜ[]t {t = var tv}) (substP (λ t → wkₜt t ≡ var (tvnext tv)) (≡sym ([]t-id {t = var tv})) refl)
[]t-∘ : {α : Subt Ξₜ Δₜ} → {β : Subt Δₜ Γₜ} → {t : Tm Γₜ} → t [ β ∘ₜ α ]t ≡ (t [ β ]t) [ α ]t
[]t-∘ {α = α} {β = β ,ₜ t} {t = var tvzero} = refl
[]t-∘ {α = α} {β = β ,ₜ t} {t = var (tvnext tv)} = []t-∘ {t = var tv}
-- Weakenings and liftings of substitutions
wkₜσₜ-∘ₜl : {α : Subt Ξₜ Δₜ} → {β : Subt Δₜ Γₜ} → wkₜσₜ (β ∘ₜ α) ≡ (wkₜσₜ β ∘ₜ lfₜσα)
wkₜσₜ-∘ₜl {β = εₜ} = refl
wkₜσₜ-∘ₜl {β = β ,ₜ t} = cong₂ _,ₜ_ wkₜσₜ-∘ₜl (wkₜ[]t {t = t})
wkₜσₜ-∘ₜr : {α : Subt Γₜ Δₜ} → {β : Subt Ξₜ Γₜ} → α ∘ₜ (wkₜσₜ β) ≡ wkₜσₜ (α ∘ₜ β)
wkₜσₜ-∘ₜr {α = εₜ} = refl
wkₜσₜ-∘ₜr {α = α ,ₜ var tv} = cong₂ _,ₜ_ (wkₜσₜ-∘ₜr {α = α}) (≡sym (wkₜ[]t {t = var tv}))
lfₜσₜ-∘ : {α : Subt Ξₜ Δₜ} → {β : Subt Δₜ Γₜ} → lfₜσₜ (β ∘ₜ α) ≡ (lfₜσₜ β) ∘ₜ (lfₜσα)
lfₜσₜ-∘ {α = α} {β = εₜ} = refl
lfₜσₜ-∘ {α = α} {β = β ,ₜ t} = cong₂ _,ₜ_ (cong₂ _,ₜ_ wkₜσₜ-∘ₜl (wkₜ[]t {t = t})) refl
-- Cancelling a weakening with a ,ₜ
wkₜ[,]t : {t : Tm Γₜ}{u : Tm Δₜ}{β : Subt Δₜ Γₜ} → (wkₜt t) [ β ,ₜ u ]t ≡ t [ β ]t
wkₜ[,]t {t = var tvzero} = refl
wkₜ[,]t {t = var (tvnext tv)} = refl
wkₜ∘ₜ,ₜ : {α : Subt Γₜ Δₜ}{β : Subt Ξₜ Γₜ}{t : Tm Ξₜ} → (wkₜσα) ∘ₜ (β ,ₜ t) ≡ (α ∘ₜ β)
wkₜ∘ₜ,ₜ {α = εₜ} = refl
wkₜ∘ₜ,ₜ {α = α ,ₜ t} {β = β} = cong₂ _,ₜ_ (wkₜ∘ₜ,ₜ {α = α}) (wkₜ[,]t {t = t} {β = β})
-- Categorical rules are respected by idₜ and ∘ₜ
idlₜ : {α : Subt Δₜ Γₜ} → idₜ ∘ₜ αα
idlₜ {α = εₜ} = refl
idlₜ {α = α ,ₜ x} = cong₂ _,ₜ_ (≡tran wkₜ∘ₜ,ₜ idlₜ) refl
idrₜ : {α : Subt Δₜ Γₜ} → α ∘ₜ idₜ ≡ α
idrₜ {α = εₜ} = refl
idrₜ {α = α ,ₜ x} = cong₂ _,ₜ_ idrₜ []t-id
∘ₜ-ass : {Γₜ Δₜ Ξₜ Ψₜ : Cont}{α : Subt Γₜ Δₜ}{β : Subt Δₜ Ξₜ}{γ : Subt Ξₜ Ψₜ} → (γ ∘ₜ β) ∘ₜ αγ ∘ₜ (β ∘ₜ α)
∘ₜ-ass {α = α} {β} {εₜ} = refl
∘ₜ-ass {α = α} {β} {γ ,ₜ x} = cong₂ _,ₜ_ ∘ₜ-ass (≡sym ([]t-∘ {t = x}))
-- Unicity of the terminal morphism
εₜ-u : {σₜ : Subt Γₜ ◇t} → σₜ ≡ εₜ
εₜ-u {σₜ = εₜ} = refl
-- Substitution for formulæ
[]f-id : {F : For Γₜ} → F [ idₜ {Γₜ} ]f ≡ F
[]f-id {F = R t u} = cong₂ R []t-id []t-id
[]f-id {F = F ⇒ G} = cong₂ _⇒_ []f-id []f-id
[]f-id {F = ∀∀ F} = cong ∀∀ []f-id
[]f-∘ : {α : Subt Ξₜ Δₜ} → {β : Subt Δₜ Γₜ} → {F : For Γₜ} → F [ β ∘ₜ α ]f ≡ (F [ β ]f) [ α ]f
[]f-∘ {α = α} {β = β} {F = R t u} = cong₂ R ([]t-∘ {α = α} {β = β} {t = t}) ([]t-∘ {α = α} {β = β} {t = u})
[]f-∘ {F = F ⇒ G} = cong₂ _⇒_ []f-∘ []f-∘
[]f-∘ {F = ∀∀ F} = cong ∀∀ (≡tran (cong (λ σ → F [ σ ]f) lfₜσₜ-∘) []f-∘)
-- Substitution for formulæ constructors
-- we omit []f-R and []f-⇒ as they are directly refl
[]f-∀∀ : {A : For (Γₜ ▹t⁰)} → {σₜ : Subt Δₜ Γₜ} → (∀∀ A) [ σₜ ]f ≡ (∀∀ (A [ (σₜ ∘ₜ πₜ¹ idₜ) ,ₜ πₜ² idₜ ]f))
[]f-∀∀ {A = A} = cong ∀∀ (cong (_[_]f A) (cong₂ _,ₜ_ (≡tran (cong wkₜσₜ (≡sym idrₜ)) (≡sym wkₜσₜ-∘ₜr)) refl))
-- We can now define proof contexts, which are indexed by a term context
-- i.e. we know which terms a proof context can use
data Conp : Cont → Set₁ where
◇p : Conp Γₜ
_▹p⁰_ : Conp Γₜ → For Γₜ → Conp Γₜ
variable
Γₚ Γₚ' : Conp Γₜ
Δₚ Δₚ' : Conp Δₜ
Ξₚ Ξₚ' : Conp Ξₜ
-- The actions of Subt's is extended to contexts
_[_]c : Conp Γₜ → Subt Δₜ Γₜ → Conp Δₜ
◇p [ σₜ ]c = ◇p
(Γₚ ▹p⁰ A) [ σₜ ]c = (Γₚ [ σₜ ]c) ▹p⁰ (A [ σₜ ]f)
-- This Conp is indeed a functor
[]c-id : Γₚ [ idₜ ]c ≡ Γₚ
[]c-id {Γₚ = ◇p} = refl
[]c-id {Γₚ = Γₚ ▹p⁰ x} = cong₂ _▹p⁰_ []c-id []f-id
[]c-∘ : {α : Subt Δₜ Ξₜ} {β : Subt Γₜ Δₜ} {Ξₚ : Conp Ξₜ} → Ξₚ [ α ∘ₜ β ]c ≡ (Ξₚ [ α ]c) [ β ]c
[]c-∘ {α = α} {β = β} {◇p} = refl
[]c-∘ {α = α} {β = β} {Ξₚ ▹p⁰ A} = cong₂ _▹p⁰_ []c-∘ []f-∘
-- We can also add a term that will not be used in the formulæ already present
-- (that's why we use wkₜσₜ)
_▹tp : Conp Γₜ → Conp (Γₜ ▹t⁰)
Γ ▹tp = Γ [ wkₜσₜ idₜ ]c
-- We show how it interacts with ,ₜ and lfₜσ
▹tp,ₜ : {σₜ : Subt Γₜ Δₜ}{t : Tm Γₜ} → (Γₚ ▹tp) [ σₜ ,ₜ t ]c ≡ Γₚ [ σₜ ]c
▹tp,ₜ {Γₚ = Γₚ} = ≡tran (≡sym []c-∘) (cong (λ ξ → Γₚ [ ξ ]c) (≡tran wkₜ∘ₜ,ₜ idlₜ))
▹tp-lfₜ : {σ : Subt Δₜ Γₜ} → ((Δₚ ▹tp) [ lfₜσσ ]c) ≡ ((Δₚ [ σ ]c) ▹tp)
▹tp-lfₜ {Δₚ = Δₚ} = ≡tran² (≡sym []c-∘) (cong (λ ξ → Δₚ [ ξ ]c) (≡tran² (≡sym wkₜσₜ-∘ₜl) (cong wkₜσₜ (≡tran idlₜ (≡sym idrₜ))) (≡sym wkₜσₜ-∘ₜr))) []c-∘
-- With those contexts, we have everything to define proofs
-- The action on Cont's morphisms of Pf functor
_[_]pvₜ : {A : For Δₜ}→ PfVar Δₜ Δₚ A → (σ : Subt Γₜ Δₜ)→ PfVar Γₜ (Δₚ [ σ ]c) (A [ σ ]f)
pvzero [ σ ]pvₜ = pvzero
pvnext pv [ σ ]pvₜ = pvnext (pv [ σ ]pvₜ)
_[_]pₜ : {A : For Δₜ} → Pf Δₜ Δₚ A → (σ : Subt Γₜ Δₜ) → Pf Γₜ (Δₚ [ σ ]c) (A [ σ ]f)
var pv [ σ ]pₜ = var (pv [ σ ]pvₜ)
app pf pf' [ σ ]pₜ = app (pf [ σ ]pₜ) (pf' [ σ ]pₜ)
lam pf [ σ ]pₜ = lam (pf [ σ ]pₜ)
_[_]pₜ {Δₚ = Δₚ} {Γₜ = Γₜ} (p∀∀e {A = A} {t = t} pf) σ =
substP (λ F → Pf Γₜ (Δₚ [ σ ]c) F) (≡tran² (≡sym []f-∘) (cong (λ σ → A [ σ ]f)
(cong₂ _,ₜ_ (≡tran² wkₜ∘ₜ,ₜ idrₜ (≡sym idlₜ)) refl)) ([]f-∘))
(p∀∀e {t = t [ σ ]t} (pf [ σ ]pₜ))
_[_]pₜ {Γₜ = Γₜ} (p∀∀i pf) σ
= p∀∀i (substP (λ Ξₚ → Pf (Γₜ ▹t⁰) (Ξₚ) _) ▹tp-lfₜ (pf [ lfₜσσ ]pₜ))
-- We now can create Renamings, a subcategory from (Conp,Subp) that
-- A renaming from a context Γₚ to a context Δₚ means when they are seen
-- as lists, that every element of Γₚ is an element of Δₚ
-- In other words, we can prove Γₚ from Δₚ using only proof variables (var)
-- We can extend renamings with term variables
PfVar▹tp : {A : For Δₜ} → PfVar Δₜ Δₚ A → PfVar (Δₜ ▹t⁰) (Δₚ ▹tp) (A [ wkₜσₜ idₜ ]f)
PfVar▹tp pvzero = pvzero
PfVar▹tp (pvnext x) = pvnext (PfVar▹tp x)
Ren▹tp : Ren Γₚ Δₚ → Ren (Γₚ ▹tp) (Δₚ ▹tp)
Ren▹tp zeroRen = zeroRen
Ren▹tp (leftRen x s) = leftRen (PfVar▹tp x) (Ren▹tp s)
-- Renamings can be used to (strongly) weaken proofs
wkᵣpv : {A : For Δₜ} → Ren Δₚ' Δₚ → PfVar Δₜ Δₚ' A → PfVar Δₜ Δₚ A
wkᵣpv (leftRen x x₁) pvzero = x
wkᵣpv (leftRen x x₁) (pvnext s) = wkᵣpv x₁ s
wkᵣp : {A : For Δₜ} → Ren Δₚ Δₚ' → Pf Δₜ Δₚ A → Pf Δₜ Δₚ' A
wkᵣp s (var pv) = var (wkᵣpv s pv)
wkᵣp s (app pf pf₁) = app (wkᵣp s pf) (wkᵣp s pf₁)
wkᵣp s (lam {A = A} pf) = lam (wkᵣp (bothRen s) pf)
wkᵣp s (p∀∀e pf) = p∀∀e (wkᵣp s pf)
wkᵣp s (p∀∀i pf) = p∀∀i (wkᵣp (Ren▹tp s) pf)
-- But we need something stronger than just renamings
-- introducing: Proof substitutions
-- They are basicly a list of proofs for the formulæ contained in
-- the goal context.
-- It is not defined between all contexts, only those with the same term context
data Subp : {Δₜ : Cont} → Conp Δₜ → Conp Δₜ → Prop₁ where
εₚ : Subp Δₚ ◇p
-- We write down the access functions from the algebra, in restricted versions
-- The action of Cont's morphisms on Subp
_[_]σₚ : Subp {Δₜ} Δₚ Δₚ' → (σ : Subt Γₜ Δₜ) → Subp {Γₜ} (Δₚ [ σ ]c) (Δₚ' [ σ ]c)
εₚ [ σₜ ]σₚ = εₚ
(σₚ ,ₚ pf) [ σₜ ]σₚ = (σₚ [ σₜ ]σₚ) ,ₚ (pf [ σₜ ]pₜ)
-- They are indeed stronger than renamings
Ren→Sub : Ren Δₚ Δₚ' → Subp {Δₜ} Δₚ' Δₚ
Ren→Sub zeroRen = εₚ
Ren→Sub (leftRen x s) = Ren→Sub s ,ₚ var x
-- From a substition into n variables, we get a substitution into n+1 variables which don't use the last one
wkₚσₚ : {Δₜ : Cont} {Δₚ Γₚ : Conp Δₜ}{A : For Δₜ} → Subp {Δₜ} Δₚ Γₚ → Subp {Δₜ} (Δₚ ▹p⁰ A) Γₚ
wkₚσₚ εₚ = εₚ
wkₚσₚ (σₚ ,ₚ pf) = (wkₚσₚ σₚ) ,ₚ wkᵣp (rightRen reflRen) pf
-- From a substitution into n variables, we construct a substitution from n+1 variables to n+1 variables which maps it to itself
-- i.e. 0 -> 0 and for all i ->(old) σ(i) we get i+1 -> σ(i)+1
lfₚσₚ : {Δₜ : Cont}{Δₚ Γₚ : Conp Δₜ}{A : For Δₜ} → Subp {Δₜ} Δₚ Γₚ → Subp {Δₜ} (Δₚ ▹p⁰ A) (Γₚ ▹p⁰ A)
lfₚσσ = (wkₚσσ) ,ₚ (var pvzero)
wkₜσₚ : Subp {Δₜ} Δₚ' Δₚ → Subp {Δₜ ▹t⁰} (Δₚ' ▹tp) (Δₚ ▹tp)
wkₜσₚ εₚ = εₚ
wkₜσₚ {Δₜ = Δₜ} (_,ₚ_ {A = A} σₚ pf) = (wkₜσₚ σₚ) ,ₚ substP (λ Ξₚ → Pf (Δₜ ▹t⁰) Ξₚ (A [ wkₜσₜ idₜ ]f)) refl (_[_]pₜ {Γₜ = Δₜ ▹t⁰} pf (wkₜσₜ idₜ))
_[_]p : {A : For Δₜ} → Pf Δₜ Δₚ A → (σ : Subp {Δₜ} Δₚ' Δₚ) → Pf Δₜ Δₚ' A
var pvzero [ σ ,ₚ pf ]p = pf
var (pvnext pv) [ σ ,ₚ pf ]p = var pv [ σ ]p
app pf pf₁ [ σ ]p = app (pf [ σ ]p) (pf₁ [ σ ]p)
lam pf [ σ ]p = lam (pf [ wkₚσσ ,ₚ var pvzero ]p)
p∀∀e pf [ σ ]p = p∀∀e (pf [ σ ]p)
p∀∀i pf [ σ ]p = p∀∀i (pf [ wkₜσσ ]p)
-- We can now define identity and composition on proof substitutions
idₚ : Subp {Δₜ} Δₚ Δₚ
idₚ {Δₚ = ◇p} = εₚ
idₚ {Δₚ = Δₚ ▹p⁰ x} = lfₚσₚ (idₚ {Δₚ = Δₚ})
-- We can now merge the two notions of contexts, substitutions, and everything
record Con : Set₁ where
constructor con
field
t : Cont
p : Conp t
variable
Γ Δ Ξ : Con
record Sub (Γ : Con) (Δ : Con) : Set₁ where
constructor sub
field
t : Subt (Con.t Γ) (Con.t Δ)
p : Subp {Con.t Γ} (Con.p Γ) ((Con.p Δ) [ t ]c)
-- We need this to apply term-substitution theorems to global substitutions
sub= : {Γ Δ : Con}{σₜ σₜ' : Subt (Con.t Γ) (Con.t Δ)} →
σₜ ≡ σₜ' →
{σₚ : Subp {Con.t Γ} (Con.p Γ) ((Con.p Δ) [ σₜ ]c)}
{σₚ' : Subp {Con.t Γ} (Con.p Γ) ((Con.p Δ) [ σₜ' ]c)} →
sub σₜ σₚ ≡ sub σₜ' σₚ'
sub= refl = refl
-- (Con,Sub) is a category with an initial object
id : Sub Γ Γ
id {Γ} = sub idₜ (substP (Subp _) (≡sym []c-id) idₚ)
_∘_ : Sub Δ Ξ → Sub Γ Δ → Sub Γ Ξ
sub αₜ αₚ ∘ sub βₜ βₚ = sub (αₜ ∘ₜ βₜ) (substP (Subp _) (≡sym []c-∘) (αₚ [ βₜ ]σₚ) ∘ₚ βₚ)
-- We have our two context extension operators
_▹t : Con → Con
Γ ▹t = con ((Con.t Γ) ▹t⁰) (Con.p Γ ▹tp)
_▹p_ : (Γ : Con) → For (Con.t Γ) → Con
Γ ▹p A = con (Con.t Γ) (Con.p Γ ▹p⁰ A)
-- We define the access function from the algebra, but defined for fully-featured substitutions
-- For term substitutions
πₜ¹* : {Γ Δ : Con} → Sub Δ (Γ ▹t) → Sub Δ Γ
πₜ¹* (sub (σₜ ,ₜ t) σₚ) = sub σₜ (substP (Subp _) ▹tp,ₜ σₚ)
πₜ²* : {Γ Δ : Con} → Sub Δ (Γ ▹t) → Tm (Con.t Δ)
πₜ²* (sub (σₜ ,ₜ t) σₚ) = t
_,ₜ*_ : {Γ Δ : Con} → Sub Δ Γ → Tm (Con.t Δ) → Sub Δ (Γ ▹t)
(sub σₜ σₚ) ,ₜ* t = sub (σₜ ,ₜ t) (substP (Subp _) (≡sym ▹tp,ₜ) σₚ)
-- And the equations
πₜ²∘,ₜ* : {Γ Δ : Con} → {σ : Sub Δ Γ} → {t : Tm (Con.t Δ)} → πₜ²* (σ ,ₜ* t) ≡ t
πₜ²∘,ₜ* = refl
πₜ¹∘,ₜ* : {Γ Δ : Con} → {σ : Sub Δ Γ} → {t : Tm (Con.t Δ)} → πₜ¹* (σ ,ₜ* t) ≡ σ
πₜ¹∘,ₜ* {Γ}{Δ}{σ}{t} = sub= refl
,ₜ∘πₜ* : {Γ Δ : Con} → {σ : Sub Δ (Γ ▹t)} → (πₜ¹* σ) ,ₜ* (πₜ²* σ) ≡ σ
,ₜ∘πₜ* {Γ} {Δ} {sub (σₜ ,ₜ t) σₚ} = sub= refl
,ₜ∘* : {Γ Δ Ξ : Con}{σ : Sub Γ Ξ}{δ : Sub Δ Γ}{t : Tm (Con.t Γ)} → (σ ,ₜ* t) ∘ δ ≡ (σ ∘ δ) ,ₜ* (t [ Sub.t δ ]t)
,ₜ∘* {Γ} {Δ} {Ξ} {sub σₜ σₚ} {sub δₜ δₚ} {t} = sub= refl
-- And for proof substitutions
πₚ¹* : {Γ Δ : Con} {A : For (Con.t Γ)} → Sub Δ (Γ ▹p A) → Sub Δ Γ
πₚ¹* (sub σₜ σaₚ) = sub σₜ (πₚ¹ σaₚ)
πₚ²* : {Γ Δ : Con} {F : For (Con.t Γ)} (σ : Sub Δ (Γ ▹p F)) → Pf (Con.t Δ) (Con.p Δ) (F [ Sub.t (πₚ¹* σ) ]f)
πₚ²* (sub σₜ (σₚ ,ₚ pf)) = pf
_,ₚ*_ : {Γ Δ : Con} {F : For (Con.t Γ)} (σ : Sub Δ Γ) → Pf (Con.t Δ) (Con.p Δ) (F [ Sub.t σ ]f) → Sub Δ (Γ ▹p F)
sub σₜ σₚ ,ₚ* pf = sub σₜ (σₚ ,ₚ pf)
-- And the equations
,ₚ∘πₚ : {Γ Δ : Con} → {F : For (Con.t Γ)} → {σ : Sub Δ (Γ ▹p F)} → (πₚ¹* σ) ,ₚ* (πₚ²* σ) ≡ σ
,ₚ∘πₚ {σ = sub σₜ (σₚ ,ₚ p)} = refl
,ₚ∘ : {Γ Δ Ξ : Con}{σ : Sub Γ Ξ}{δ : Sub Δ Γ}{F : For (Con.t Ξ)}{prf : Pf (Con.t Γ) (Con.p Γ) (F [ Sub.t σ ]f)}
→ (σ ,ₚ* prf) ∘ δ ≡ (σ ∘ δ) ,ₚ* (substP (λ F → Pf (Con.t Δ) (Con.p Δ) F) (≡sym []f-∘) ((prf [ Sub.t δ ]pₜ) [ Sub.p δ ]p))
,ₚ∘ {Γ}{Δ}{Ξ}{σ = sub σₜ σₚ} {sub δₜ δₚ} {F = A} {prf} = sub= refl
-- and FINALLY, we compile everything into an implementation of the FFOL record
ffol : FFOL {lsuc lzero} {lsuc lzero} {lsuc lzero} {lsuc lzero}
ffol = record
{ Con = Con
; Sub = Sub
; _∘_ = _∘_
; ∘-ass = sub= ∘ₜ-ass
; id = id
; idl = sub= idlₜ
; idr = sub= idrₜ
; ◇ = con ◇t ◇p
; ε = sub εₜ εₚ
; ε-u = sub= εₜ-u
; Tm = λ Γ → Tm (Con.t Γ)
; _[_]t = λ t σ → t [ Sub.t σ ]t
; []t-id = []t-id
; []t-∘ = λ {Γ}{Δ}{Ξ}{α}{β}{t} → []t-∘ {α = Sub.t α} {β = Sub.t β} {t = t}
; _▹ₜ = _▹t
; πₜ¹ = πₜ¹*
; πₜ² = πₜ²*
; _,ₜ_ = _,ₜ*_
; πₜ²∘,ₜ = refl
; πₜ¹∘,ₜ = λ {Γ}{Δ}{σ}{t} → πₜ¹∘,ₜ* {Γ}{Δ}{σ}{t}
; ,ₜ∘πₜ = ,ₜ∘πₜ*
; ,ₜ∘ = λ {Γ}{Δ}{Ξ}{σ}{δ}{t} → ,ₜ∘* {Γ}{Δ}{Ξ}{σ}{δ}{t}
; For = λ Γ → For (Con.t Γ)
; _[_]f = λ A σ → A [ Sub.t σ ]f
; []f-id = []f-id
; []f-∘ = []f-∘
; R = R
; R[] = refl
; _⊢_ = λ Γ A → Pf (Con.t Γ) (Con.p Γ) A
; _[_]p = λ pf σ → (pf [ Sub.t σ ]pₜ) [ Sub.p σ ]p
; _▹ₚ_ = _▹p_
; πₚ¹ = πₚ¹*
; πₚ² = πₚ²*
; _,ₚ_ = _,ₚ*_
; ,ₚ∘πₚ = ,ₚ∘πₚ
; πₚ¹∘,ₚ = refl
; ,ₚ∘ = λ {Γ}{Δ}{Ξ}{σ}{δ}{F}{prf} → ,ₚ∘ {Γ}{Δ}{Ξ}{σ}{δ}{F}{prf}
; _⇒_ = _⇒_
; []f-⇒ = refl
; ∀∀ = ∀∀
; []f-∀∀ = []f-∀∀
; lam = λ {Γ}{F}{G} pf → substP (λ H → Pf (Con.t Γ) (Con.p Γ) (F ⇒ H)) []f-id (lam pf)
; app = app
; ∀i = p∀∀i
; ∀e = λ {Γ} {F} pf {t} → p∀∀e pf
}
-- We define normal and neutral forms
data Ne : (Γₜ : Cont) → (Γₚ : Conp Γₜ) → For Γₜ → Prop₁
data Nf : (Γₜ : Cont) → (Γₚ : Conp Γₜ) → For Γₜ → Prop₁
data Ne where
var : {A : For Γₜ} → PfVar Γₜ Γₚ A → Ne Γₜ Γₚ A
app : {A B : For Γₜ} → Ne Γₜ Γₚ (A ⇒ B) → Nf Γₜ Γₚ A → Ne Γₜ Γₚ B
p∀∀e : {A : For (Γₜ ▹t⁰)} → {t : Tm Γₜ} → Ne Γₜ Γₚ (∀∀ A) → Ne Γₜ Γₚ (A [ idₜ ,ₜ t ]f)
data Nf where
R : {t u : Tm Γₜ} → Ne Γₜ Γₚ (R t u) → Nf Γₜ Γₚ (R t u)
lam : {A B : For Γₜ} → Nf Γₜ (Γₚ ▹p⁰ A) B → Nf Γₜ Γₚ (A ⇒ B)
p∀∀i : {A : For (Γₜ ▹t⁰)} → Nf (Γₜ ▹t⁰) (Γₚ ▹tp) A → Nf Γₜ Γₚ (∀∀ A)
Pf* : (Γₜ : Cont) → Conp Γₜ → Conp Γₜ → Prop₁
Pf* Γₜ Γₚ ◇p =
Pf* Γₜ Γₚ (Γₚ' ▹p⁰ A) = (Pf* Γₜ Γₚ Γₚ') ∧ (Pf Γₜ Γₚ A)
Sub→Pf* : {Γₜ : Cont} {Γₚ Γₚ' : Conp Γₜ} → Subp {Γₜ} Γₚ Γₚ' → Pf* Γₜ Γₚ Γₚ'
Sub→Pf* εₚ = tt
Sub→Pf* (σₚ ,ₚ pf) = ⟨ (Sub→Pf* σₚ) , pf ⟩
Pf*-id : {Γₜ : Cont} {Γₚ : Conp Γₜ} → Pf* Γₜ Γₚ Γₚ
Pf*-id = Sub→Pf* idₚ
Pf*▹p : {Γₜ : Cont}{Γₚ Γₚ' : Conp Γₜ}{A : For Γₜ} → Pf* Γₜ Γₚ Γₚ' → Pf* Γₜ (Γₚ ▹p⁰ A) Γₚ'
Pf*▹p {Γₚ' = ◇p} s = tt
Pf*▹p {Γₚ' = Γₚ' ▹p⁰ x} s = ⟨ (Pf*▹p (proj₁ s)) , (wkᵣp (rightRen reflRen) (proj₂ s)) ⟩
Pf*▹tp : {Γₜ : Cont}{Γₚ Γₚ' : Conp Γₜ} → Pf* Γₜ Γₚ Γₚ' → Pf* (Γₜ ▹t⁰) (Γₚ ▹tp) (Γₚ' ▹tp)
Pf*▹tp {Γₚ' = ◇p} s = tt
Pf*▹tp {Γₚ' = Γₚ' ▹p⁰ A} s = ⟨ Pf*▹tp (proj₁ s) , (proj₂ s) [ wkₜσₜ idₜ ]pₜ ⟩
Pf*Pf : {Γₜ : Cont} {Γₚ Γₚ' : Conp Γₜ} {A : For Γₜ} → Pf* Γₜ Γₚ Γₚ' → Pf Γₜ Γₚ' A → Pf Γₜ Γₚ A
Pf*Pf s (var pvzero) = proj₂ s
Pf*Pf s (var (pvnext pv)) = Pf*Pf (proj₁ s) (var pv)
Pf*Pf s (app p p') = app (Pf*Pf s p) (Pf*Pf s p')
Pf*Pf s (lam p) = lam (Pf*Pf (⟨ (Pf*▹p s) , (var pvzero) ⟩) p)
Pf*Pf s (p∀∀e p) = p∀∀e (Pf*Pf s p)
Pf*Pf s (p∀∀i p) = p∀∀i (Pf*Pf (Pf*▹tp s) p)
Pf*-∘ : {Γₜ : Cont} {Γₚ Δₚ Ξₚ : Conp Γₜ} → Pf* Γₜ Δₚ Ξₚ → Pf* Γₜ Γₚ Δₚ → Pf* Γₜ Γₚ Ξₚ
Pf*-∘ {Ξₚ = ◇p} α β = tt
Pf*-∘ {Ξₚ = Ξₚ ▹p⁰ A} α β = ⟨ Pf*-∘ (proj₁ α) β , Pf*Pf β (proj₂ α) ⟩
-}
{-
module InitialMorphism (M : FFOL {lsuc lzero} {lsuc lzero} {lsuc lzero} {lsuc lzero} {lsuc lzero}) where
{-# TERMINATING #-}
mCont : Cont → (FFOL.Con M)
mCont ◇t = FFOL.◇ M
mCont (Γₜ ▹t⁰) = FFOL._▹ₜ M (mCont Γₜ)
mTmT : {Γₜ : Cont} → Tm Γₜ → (FFOL.Tm M (mCont Γₜ))
-- Zero is (πₜ² id)
mTmT {Γₜ ▹t⁰} (var tvzero) = FFOL.πₜ² M (FFOL.id M)
-- N+1 is wk[tm N]
mTmT {Γₜ ▹t⁰} (var (tvnext tv)) = (FFOL._[_]t M (mTmT (var tv)) (FFOL.πₜ¹ M (FFOL.id M)))
mForT : {Γₜ : Cont} → (For Γₜ) → (FFOL.For M (mCont Γₜ))
mForT (R t u) = FFOL.R M (mTmT t) (mTmT u)
mForT (A ⇒ B) = FFOL._⇒_ M (mForT A) (mForT B)
mForT {Γ} (∀∀ A) = FFOL.∀∀ M (mForT A)
mSubt : {Δₜ : Cont}{Γₜ : Cont} → Subt Δₜ Γₜ → (FFOL.Sub M (mCont Δₜ) (mCont Γₜ))
mSubt εₜ = FFOL.ε M
mSubt (σₜ ,ₜ t) = FFOL._,ₜ_ M (mSubt σₜ) (mTmT t)
mConp : {Γₜ : Cont} → Conp Γₜ → (FFOL.Con M)
mForP : {Γₜ : Cont} {Γₚ : Conp Γₜ} → (For Γₜ) → (FFOL.For M (mConp Γₚ))
mConp {Γₜ} ◇p = mCont Γₜ
mConp {Γₜ} (Γₚ ▹p⁰ A) = FFOL._▹ₚ_ M (mConp Γₚ) (mForP {Γₚ = Γₚ} A)
mForP {Γₜ} {Γₚ = ◇p} A = mForT {Γₜ} A
mForP {Γₚ = Γₚ ▹p⁰ B} A = FFOL._[_]f M (mForP {Γₚ = Γₚ} A) (FFOL.πₚ¹ M (FFOL.id M))
mTmP : {Γₜ : Cont}{Γₚ : Conp Γₜ} → Tm Γₜ → (FFOL.Tm M (mConp Γₚ))
mTmP {Γₜ}{Γₚ = ◇p} t = mTmT {Γₜ} t
mTmP {Γₚ = Γₚ ▹p⁰ x} t = FFOL._[_]t M (mTmP {Γₚ = Γₚ} t) (FFOL.πₚ¹ M (FFOL.id M))
mCon : Con → (FFOL.Con M)
mCon Γ = mConp {Con.t Γ} (Con.p Γ)
mFor : {Γ : Con} → (For (Con.t Γ)) → (FFOL.For M (mCon Γ))
mFor {Γ} A = mForP {Con.t Γ} {Con.p Γ} A
mTm : {Γ : Con} → Tm (Con.t Γ) → (FFOL.Tm M (mCon Γ))
mTm {Γ} t = mTmP {Con.t Γ} {Con.p Γ} t
e▹ₜT : {Γₜ : Cont} → mCont (Γₜ ▹t⁰) ≡ FFOL._▹ₜ M (mCont Γₜ)
e▹ₜT = refl
e▹ₜP : {Γₜ : Cont}{Γₚ : Conp Γₜ} → mConp {Γₜ ▹t⁰} (Γₚ [ wkₜσₜ idₜ ]c) ≡ FFOL._▹ₜ M (mConp Γₚ)
e▹ₜP {Γₜ = Γₜ} {Γₚ = ◇p} = e▹ₜT {Γₜ = Γₜ}
e▹ₜP {Γₚ = Γₚ ▹p⁰ A} = {!!}
e▹ₜ : {Γ : Con} → mCon (con (Con.t Γ ▹t⁰) (Con.p Γ [ wkₜσₜ idₜ ]c)) ≡ FFOL._▹ₜ M (mCon Γ)
e▹ₜ {Γ} = e▹ₜP {Γₜ = Con.t Γ} {Γₚ = Con.p Γ}
mForT⇒ : {Γₜ : Cont}{A B : For Γₜ} → mForT {Γₜ} (A ⇒ B) ≡ FFOL._⇒_ M (mForT {Γₜ} A) (mForT {Γₜ} B)
mForT⇒ = refl
mForP⇒ : {Γₜ : Cont}{Γₚ : Conp Γₜ}{A B : For Γₜ} → mForP {Γₜ} {Γₚ} (A ⇒ B) ≡ FFOL._⇒_ M (mForP {Γₜ} {Γₚ} A) (mForP {Γₜ} {Γₚ} B)
mForP⇒ {Γₜ} {Γₚ = ◇p}{A}{B} = mForT⇒ {Γₜ}{A}{B}
mForP⇒ {Γₚ = Γₚ ▹p⁰ C}{A}{B} = ≡tran (cong (λ X → (M FFOL.[ X ]f) _) (mForP⇒ {Γₚ = Γₚ})) (FFOL.[]f-⇒ M {F = mForP {Γₚ = Γₚ} A} {G = mForP {Γₚ = Γₚ} B} {σ = (FFOL.πₚ¹ M (FFOL.id M))})
mFor⇒ : {Γ : Con}{A B : For (Con.t Γ)} → mFor {Γ} (A ⇒ B) ≡ FFOL._⇒_ M (mFor {Γ} A) (mFor {Γ} B)
mFor⇒ {Γ} = mForP⇒ {Con.t Γ} {Con.p Γ}
mForT∀∀ : {Γₜ : Cont}{A : For (Γₜ ▹t⁰)} → mForT {Γₜ} (∀∀ A) ≡ FFOL.∀∀ M (mForT {Γₜ ▹t⁰} A)
mForT∀∀ = refl
mForP∀∀ : {Γₜ : Cont}{Γₚ : Conp Γₜ}{A : For (Γₜ ▹t⁰)} → mForP {Γₜ} {Γₚ} (∀∀ A) ≡ FFOL.∀∀ M (subst (FFOL.For M) (e▹ₜP {Γₜ} {Γₚ}) (mForP {Γₜ ▹t⁰} {Γₚ ▹tp} A))
-- mFor∀∀ : {Γ : Con}{A : For ((Con.t Γ) ▹t⁰)} → mFor {Γ} (∀∀ A) ≡ FFOL.∀∀ M (mFor {Γ ▹t} A)
--mForL : {Γ : Con}{A : For (Con.t Γ ▹t⁰)}{t : Tm (Con.t Γ)} → FFOL._[_]f M (mFor {Γ = {!Γ ▹t!}} A) (FFOL._,ₜ_ M (FFOL.id M) (mTm {Γ = Γ} t)) ≡ mFor {Γ = Γ} (A [ idₜ ,ₜ t ]f)
m⊢ : {Γ : Con} {A : For (Con.t Γ)} → Pf (Con.t Γ) (Con.p Γ) A → FFOL._⊢_ M (mCon Γ) (mFor {Γ = Γ} A)
m⊢ (var pvzero) = FFOL.πₚ² M (FFOL.id M)
m⊢ (var (pvnext pv)) = FFOL._[_]p M (m⊢ (var pv)) (FFOL.πₚ¹ M (FFOL.id M))
m⊢ {Γ} {B} (app {A = A} pf pf') = FFOL.app M (substP (FFOL._⊢_ M _) (mFor⇒ {Γ}{A}{B}) (m⊢ pf)) (m⊢ pf')
m⊢ {Γ} {A ⇒ B} (lam pf) = substP (FFOL._⊢_ M _) (≡sym (mFor⇒ {Γ}{A}{B})) (FFOL.lam M (m⊢ pf))
m⊢ {Γ} (p∀∀e {A = A} {t = t} pf) = substP (FFOL._⊢_ M _) {!!} (FFOL.∀e M {F = mFor {{!!}} A} (substP (FFOL._⊢_ M _) {!!} (m⊢ pf)) {t = mTm {Γ} t})
m⊢ {Γ} (p∀∀i {A = A} pf) = substP (FFOL._⊢_ M _) (≡sym mForP∀∀) (FFOL.∀i M (substP (λ Ξ → FFOL._⊢_ M Ξ (mFor A)) e▹ₜ (m⊢ pf)))
mSubp : {Γₜ : Cont}{Δₚ Γₚ : Conp Γₜ} → Subp {Γₜ} Δₚ Γₚ → (FFOL.Sub M (mConp Δₚ) (mConp Γₚ))
mSubp {Γₜ} {Γₚ = ◇p} σₚ = {!FFOL.ε M!}
mSubp {Γₚ = Γₚ ▹p⁰ A} σₚ = FFOL._,ₚ_ M (mSubp (πₚ¹ σₚ)) {!m⊢ (πₚ² σₚ)!}
mSub : {Δ : Con}{Γ : Con} → Sub Δ Γ → (FFOL.Sub M (mCon Δ) (mCon Γ))
mSub {Δ}{Γ} σ = FFOL._∘_ M (subst (FFOL.Sub M (mCont (Con.t Δ))) {!!} (mSubt (Sub.t σ))) ({!mSubp (Sub.p σ)!})
e▹ₚ : {Γ : Con}{A : For (Con.t Γ)} → mCon (Γ ▹p A) ≡ FFOL._▹ₚ_ M (mCon Γ) (mFor {Γ} A)
e[]f : {Γ Δ : Con}{A : For (Con.t Γ)}{σ : Sub Δ Γ} → mFor {Δ} (A [ Sub.t σ ]f) ≡ FFOL._[_]f M (mFor {Γ} A) (mSub σ)
{-
e▹ₜ {con Γₜ ◇p} = refl
e▹ₜ {con Γₜ (Γₚ ▹p⁰ A)} = ≡tran²
(cong₂' (FFOL._▹ₚ_ M) (e▹ₜ {con Γₜ Γₚ}) (cong (subst (FFOL.For M) (e▹ₜ {Γ = con Γₜ Γₚ})) (e[]f {A = A}{σ = πₜ¹* id})))
(substP (λ X → (M FFOL.▹ₚ (M FFOL.▹ₜ) (mCon (con Γₜ Γₚ))) X ≡ (M FFOL.▹ₜ) ((M FFOL.▹ₚ mCon (con Γₜ Γₚ)) (mFor A)))
(≡tran
(coeshift {!!})
(cong (λ X → subst (FFOL.For M) _ (FFOL._[_]f M (mFor A) (mSub (sub (wkₜσₜ idₜ) X)))) (≡sym (coecoe-coe {eq1 = {!!}} {x = idₚ {Δₚ = Γₚ}}))))
{!!})
(cong (M FFOL.▹ₜ) (≡sym (e▹ₚ {con Γₜ Γₚ})))
-- substP (λ X → FFOL._▹ₚ_ M X (mFor {Γ = ?} (A [ wkₜσₜ idₜ ]f)) ≡ (FFOL._▹ₜ M (mCon (con Γₜ (Γₚ ▹p⁰ A))))) (≡sym (e▹ₜ {Γ = con Γₜ Γₚ})) ?
-}
e[]f = {!!}
e▹ₚ = {!!}
{-
e∘ : {Γ Δ Ξ : Con}{δ : Sub Δ Ξ}{σ : Sub Γ Δ} → mSub (δ ∘ σ) ≡ FFOL._∘_ M (mSub δ) (mSub σ)
e∘ = {!!}
eid : {Γ : Con} → mSub (id {Γ}) ≡ FFOL.id M {mCon Γ}
eid = {!!}
e◇ : mCon ◇ ≡ FFOL.◇ M
e◇ = {!!}
eε : {Γ : Con} → mSub (sub (εₜ {Con.t Γ}) (εₚ {Con.t Γ} {Con.p Γ})) ≡ subst (FFOL.Sub M (mCon Γ)) (≡sym e◇) (FFOL.ε M {mCon Γ})
eε = {!!}
e[]t : {Γ Δ : Con}{t : Tm (Con.t Γ)}{σ : Sub Δ Γ} → mTm (t [ Sub.t σ ]t) ≡ FFOL._[_]t M (mTm t) (mSub σ)
e[]t = {!!}
eπₜ¹ : {Γ Δ : Con}{σ : Sub Δ (Γ ▹t)} → mSub (πₜ¹* σ) ≡ FFOL.πₜ¹ M (subst (FFOL.Sub M (mCon Δ)) e▹ₜ (mSub σ))
eπₜ¹ = {!!}
eπₜ² : {Γ Δ : Con}{σ : Sub Δ (Γ ▹t)} → mTm (πₜ²* σ) ≡ FFOL.πₜ² M (subst (FFOL.Sub M (mCon Δ)) e▹ₜ (mSub σ))
eπₜ² = {!!}
e,ₜ : {Γ Δ : Con}{σ : Sub Δ Γ}{t : Tm (Con.t Δ)} → mSub (σ ,ₜ* t) ≡ subst (FFOL.Sub M (mCon Δ)) (≡sym e▹ₜ) (FFOL._,ₜ_ M (mSub σ) (mTm t))
e,ₜ = {!!}
-- Proofs are in prop, so no equation needed
--[]p : {Γ Δ : Con}{A : For Γ}{pf : FFOL._⊢_ S Γ A}{σ : FFOL.Sub S Δ Γ} → m⊢ (FFOL._[_]p S pf σ) ≡ FFOL._[_]p M (m⊢ pf) (mSub σ)
e▹ₚ = {!!}
eπₚ¹ : {Γ Δ : Con}{A : For (Con.t Γ)}{σ : Sub Δ (Γ ▹p A)} → mSub (πₚ¹* σ) ≡ FFOL.πₚ¹ M (subst (FFOL.Sub M (mCon Δ)) e▹ₚ (mSub σ))
eπₚ¹ = {!!}
--πₚ² : {Γ Δ : Con}{A : For Γ}{σ : Sub Δ (Γ ▹p A)} → m⊢ (πₚ²* σ) ≡ FFOL.πₚ¹ M (subst (FFOL.Sub M (mCon Δ)) e▹ₚ (mSub σ))
e,ₚ : {Γ Δ : Con}{A : For (Con.t Γ)}{σ : Sub Δ Γ}{pf : Pf (Con.t Δ) (Con.p Δ) (A [ Sub.t σ ]f)}
→ mSub (σ ,ₚ* pf) ≡ subst (FFOL.Sub M (mCon Δ)) (≡sym e▹ₚ) (FFOL._,ₚ_ M (mSub σ) (substP (FFOL._⊢_ M (mCon Δ)) e[]f (m⊢ pf)))
e,ₚ = {!!}
eR : {Γ : Con}{t u : Tm (Con.t Γ)} → mFor (R t u) ≡ FFOL.R M (mTm t) (mTm u)
eR = {!!}
e⇒ : {Γ : Con}{A B : For (Con.t Γ)} → mFor (A ⇒ B) ≡ FFOL._⇒_ M (mFor A) (mFor B)
e⇒ = {!!}
e∀∀ : {Γ : Con}{A : For ((Con.t Γ) ▹t⁰)} → mFor (∀∀ A) ≡ FFOL.∀∀ M (subst (FFOL.For M) e▹ₜ (mFor A))
e∀∀ = {!!}
-}
m : Mapping ffol M
m = record { mCon = mCon ; mSub = mSub ; mTm = λ {Γ} t → mTm {Γ} t ; mFor = λ {Γ} A → mFor {Γ} A ; m⊢ = m⊢ }
--mor : (M : FFOL) → Morphism ffol M
--mor M = record {InitialMorphism M}
-}
\end{code}

View File

@ -158,6 +158,11 @@ module PropUtil where
congsubst : { ' : Level}{A : Set }{P : A Set '}{a a' : A}{e : a a}{p : P a}{p' : P a} p p' subst P e p subst P e p'
congsubst {P = P} {e = refl} h = cong (subst P refl) h
substpoly : { ' : Level}{A : Set }{P : A Set '}{f : {ξ : A} P ξ}
{α β : A}{eq : α β}
subst P eq (f {α}) f {β}
substpoly {eq = refl} = coerefl
substfpoly : { ' : Level}{A : Set }{P R : A Set '}{α β : A}
{eq : α β} {f : {ξ : A} R ξ P ξ} {x : R α}
coe (cong P eq) (f {α} x) f (coe (cong R eq) x)

104
ZOL2.lagda Normal file
View File

@ -0,0 +1,104 @@
\begin{code}
{-# OPTIONS --prop --rewriting #-}
open import PropUtil
module ZOL2 where
open import Agda.Primitive
open import ListUtil
variable
ℓ¹ ℓ² ℓ³ ℓ⁴ ℓ⁵ : Level
record ZOL : Set (lsuc (ℓ¹ ⊔ ℓ² ⊔ ℓ³ ⊔ ℓ⁴)) where
infixr 10 _∘_
field
-- We first make the base category with its terminal object
Con : Set ℓ¹
Sub : Con → Con → Prop ℓ² -- It makes a category
_∘_ : {Γ Δ Ξ : Con} → Sub Δ Ξ → Sub Γ Δ → Sub Γ Ξ
--∘-ass : {Γ Δ Ξ Ψ : Con}{α : Sub Γ Δ}{β : Sub Δ Ξ}{γ : Sub Ξ Ψ}
-- → (γ ∘ β) ∘ αγ ∘ (β ∘ α)
id : {Γ : Con} → Sub Γ Γ
--idl : {Γ Δ : Con} {σ : Sub Γ Δ} → (id {Δ}) ∘ σσ
--idr : {Γ Δ : Con} {σ : Sub Γ Δ} → σ ∘ (id {Γ}) ≡ σ
◇ : Con -- The terminal object of the category
ε : {Γ : Con} → Sub Γ ◇ -- The morphism from any object to the terminal
--ε-u : {Γ : Con} → {σ : Sub Γ ◇} → σ ≡ ε {Γ}
-- Functor Con → Set called For
For : Con → Set ℓ³
_[_]f : {Γ Δ : Con} → For Γ → Sub Δ Γ → For Δ -- Action on morphisms
[]f-id : {Γ : Con} → {F : For Γ} → F [ id {Γ} ]f ≡ F
[]f-∘ : {Γ Δ Ξ : Con} → {α : Sub Ξ Δ} → {β : Sub Δ Γ} → {F : For Γ}
→ F [ β ∘ α ]f ≡ (F [ β ]f) [ α ]f
-- Functor Con × For → Prop called Pf or ⊢
Pf : (Γ : Con) → For Γ → Prop ℓ⁴
-- Action on morphisms
_[_]p : {Γ Δ : Con} → {F : For Γ} → Pf Γ F → (σ : Sub Δ Γ) → Pf Δ (F [ σ ]f)
-- Equalities below are useless because Pf Γ F is in prop
-- []p-id : {Γ : Con} → {F : For Γ} → {prf : Pf Γ F}
-- → prf [ id {Γ} ]p ≡ prf
-- []p-∘ : {Γ Δ Ξ : Con}{α : Sub Ξ Δ}{β : Sub Δ Γ}{F : For Γ}{prf : Pf Γ F}
-- → prf [ α ∘ β ]p ≡ (prf [ β ]p) [ α ]p
-- → Prop⁺
_▹ₚ_ : (Γ : Con) → For Γ → Con
πₚ¹ : {Γ Δ : Con}{F : For Γ} → Sub Δ (Γ ▹ₚ F) → Sub Δ Γ
πₚ² : {Γ Δ : Con}{F : For Γ} → (σ : Sub Δ (Γ ▹ₚ F)) → Pf Δ (F [ πₚ¹ σ ]f)
_,ₚ_ : {Γ Δ : Con}{F : For Γ} → (σ : Sub Δ Γ) → Pf Δ (F [ σ ]f) → Sub Δ (Γ ▹ₚ F)
--,ₚ∘πₚ : {Γ Δ : Con}{F : For Γ}{σ : Sub Δ (Γ ▹ₚ F)} → (πₚ¹ σ) ,ₚ (πₚ² σ) ≡ σ
--πₚ¹∘,ₚ : {Γ Δ : Con}{σ : Sub Δ Γ}{F : For Γ}{prf : Pf Δ (F [ σ ]f)}
-- → πₚ¹ (σ ,ₚ prf) ≡ σ
-- Equality below is useless because Pf Γ F is in Prop
-- πₚ²∘,ₚ : {Γ Δ : Con}{σ : Sub Δ Γ}{F : For Γ}{prf : Pf Δ (F [ σ ]f)}
-- → πₚ² (σ ,ₚ prf) ≡ prf
--,ₚ∘ : {Γ Δ Ξ : Con}{σ : Sub Γ Ξ}{δ : Sub Δ Γ}{F : For Ξ}{prf : Pf Γ (F [ σ ]f)}
-- → (σ ,ₚ prf) ∘ δ ≡ (σ ∘ δ) ,ₚ (substP (Pf Δ) (≡sym []f-∘) (prf [ δ ]p))
{-- FORMULAE CONSTRUCTORS --}
-- i formula
ι : {Γ : Con} → For Γ
[]f-ι : {Γ Δ : Con} {σ : Sub Δ Γ}→ ι [ σ ]f ≡ ι
-- Implication
_⇒_ : {Γ : Con} → For Γ → For Γ → For Γ
[]f-⇒ : {Γ Δ : Con} → {F G : For Γ} → {σ : Sub Δ Γ}
→ (F ⇒ G) [ σ ]f ≡ (F [ σ ]f) ⇒ (G [ σ ]f)
{-- PROOFS CONSTRUCTORS --}
-- Again, we don't have to write the _[_]p equalities as Proofs are in Prop
-- Lam & App
lam : {Γ : Con}{F G : For Γ} → Pf (Γ ▹ₚ F) (G [ πₚ¹ id ]f) → Pf Γ (F ⇒ G)
app : {Γ : Con}{F G : For Γ} → Pf Γ (F ⇒ G) → Pf Γ F → Pf Γ G
record Mapping (S : ZOL {ℓ¹} {ℓ²} {ℓ³} {ℓ⁴}) (D : ZOL {ℓ¹} {ℓ²} {ℓ³} {ℓ⁴}) : Set (lsuc (ℓ¹ ⊔ ℓ² ⊔ ℓ³ ⊔ ℓ⁴)) where
field
-- We first make the base category with its final object
mCon : (ZOL.Con S) → (ZOL.Con D)
mSub : {Δ : (ZOL.Con S)}{Γ : (ZOL.Con S)} → (ZOL.Sub S Δ Γ) → (ZOL.Sub D (mCon Δ) (mCon Γ))
mFor : {Γ : (ZOL.Con S)} → (ZOL.For S Γ) → (ZOL.For D (mCon Γ))
mPf : {Γ : (ZOL.Con S)} {A : ZOL.For S Γ} → ZOL.Pf S Γ A → ZOL.Pf D (mCon Γ) (mFor A)
record Morphism (S : ZOL {ℓ¹} {ℓ²} {ℓ³} {ℓ⁴}) (D : ZOL {ℓ¹} {ℓ²} {ℓ³} {ℓ⁴}) : Set (lsuc (ℓ¹ ⊔ ℓ² ⊔ ℓ³ ⊔ ℓ⁴)) where
field m : Mapping S D
mCon = Mapping.mCon m
mSub = Mapping.mSub m
mFor = Mapping.mFor m
mPf = Mapping.mPf m
field
e◇ : mCon (ZOL.◇ S) ≡ ZOL.◇ D
e[]f : {Γ Δ : ZOL.Con S}{A : ZOL.For S Γ}{σ : ZOL.Sub S Δ Γ} → mFor (ZOL._[_]f S A σ) ≡ ZOL._[_]f D (mFor A) (mSub σ)
e▹ₚ : {Γ : ZOL.Con S}{A : ZOL.For S Γ} → mCon (ZOL._▹ₚ_ S Γ A) ≡ ZOL._▹ₚ_ D (mCon Γ) (mFor A)
eι : {Γ : ZOL.Con S} → mFor (ZOL.ι S {Γ}) ≡ ZOL.ι D {mCon Γ}
e⇒ : {Γ : ZOL.Con S}{A B : ZOL.For S Γ} → mFor (ZOL._⇒_ S A B) ≡ ZOL._⇒_ D (mFor A) (mFor B)
-- No equation needed for lam, app, ∀i, ∀e as their output are in prop
\end{code}

180
ZOLInitial.lagda Normal file
View File

@ -0,0 +1,180 @@
git s\begin{code}
{-# OPTIONS --prop --rewriting #-}
open import PropUtil
module ZOLInitial where
open import ZOL2
open import Agda.Primitive
open import ListUtil
data For : Set where
ι : For
_⇒_ : For → For → For
data Con : Set where
◇ : Con
_▹ₚ_ : Con → For → Con
variable
Γ Δ Ξ : Con
A B : For
data PfVar : Con → For → Prop where
pvzero : PfVar (Γ ▹ₚ A) A
pvnext : PfVar Γ A → PfVar (Γ ▹ₚ B) A
data Pf : Con → For → Prop where
var : PfVar Γ A → Pf Γ A
lam : Pf (Γ ▹ₚ A) B → Pf Γ (A ⇒ B)
app : Pf Γ (A ⇒ B) → Pf Γ A → Pf Γ B
data Ren : Con → Con → Prop where
ε : Ren Γ ◇
_,ₚR_ : Ren Δ Γ → PfVar Δ A → Ren Δ (Γ ▹ₚ A)
rightR : Ren Δ Γ → Ren (Δ ▹ₚ A) Γ
rightR ε = ε
rightR (σ ,ₚR pv) = (rightR σ) ,ₚR (pvnext pv)
idR : Ren Γ Γ
idR {◇} = ε
idR {Γ ▹ₚ A} = (rightR (idR {Γ})) ,ₚR pvzero
data Sub : Con → Con → Prop where
ε : Sub Γ ◇
_,ₚ_ : Sub Δ Γ → Pf Δ A → Sub Δ (Γ ▹ₚ A)
πₚ¹ : Sub Δ (Γ ▹ₚ A) → Sub Δ Γ
πₚ² : Sub Δ (Γ ▹ₚ A) → Pf Δ A
πₚ¹ (σ ,ₚ pf) = σ
πₚ² (σ ,ₚ pf) = pf
SubR : Ren Γ Δ → Sub Γ Δ
SubR ε = ε
SubR (σ ,ₚR pv) = SubR σ ,ₚ var pv
id : Sub Γ Γ
id = SubR idR
_[_]pvr : PfVar Γ A → Ren Δ Γ → PfVar Δ A
pvzero [ _ ,ₚR pv ]pvr = pv
pvnext pv [ σ ,ₚR _ ]pvr = pv [ σ ]pvr
_[_]pr : Pf Γ A → Ren Δ Γ → Pf Δ A
var pv [ σ ]pr = var (pv [ σ ]pvr)
lam pf [ σ ]pr = lam (pf [ (rightR σ) ,ₚR pvzero ]pr)
app pf pf' [ σ ]pr = app (pf [ σ ]pr) (pf' [ σ ]pr)
wkSub : Sub Δ Γ → Sub (Δ ▹ₚ A) Γ
wkSub ε = ε
wkSub (σ ,ₚ pf) = (wkSub σ) ,ₚ (pf [ rightR idR ]pr)
_[_]p : Pf Γ A → Sub Δ Γ → Pf Δ A
var pvzero [ _ ,ₚ pf ]p = pf
var (pvnext pv) [ σ ,ₚ _ ]p = var pv [ σ ]p
lam pf [ σ ]p = lam (pf [ wkSub σ ,ₚ var pvzero ]p)
app pf pf' [ σ ]p = app (pf [ σ ]p) (pf' [ σ ]p)
_∘_ : {Γ Δ Ξ : Con} → Sub Δ Ξ → Sub Γ Δ → Sub Γ Ξ
ε ∘ β = ε
(α ,ₚ pf) ∘ β = (α ∘ β) ,ₚ (pf [ β ]p)
zol : ZOL
zol = record
{ Con = Con
; Sub = Sub
; _∘_ = _∘_
; id = id
; ◇ = ◇
; ε = ε
; For = λ Γ → For
; _[_]f = λ A σ → A
; []f-id = refl
; []f-∘ = refl
; Pf = Pf
; _[_]p = _[_]p
; _▹ₚ_ = _▹ₚ_
; πₚ¹ = πₚ¹
; πₚ² = πₚ²
; _,ₚ_ = _,ₚ_
; ι = ι
; []f-ι = refl
; _⇒_ = _⇒_
; []f-⇒ = refl
; lam = lam
; app = app
}
module InitialMorphism (M : ZOL {lzero} {lzero} {lzero} {lzero}) where
mCon : Con → (ZOL.Con M)
mFor : {Γ : Con} → For → (ZOL.For M (mCon Γ))
mCon ◇ = ZOL.◇ M
mCon (Γ ▹ₚ A) = ZOL._▹ₚ_ M (mCon Γ) (mFor {Γ} A)
mFor {Γ} ι = ZOL.ι M
mFor {Γ} (A ⇒ B) = ZOL._⇒_ M (mFor {Γ} A) (mFor {Γ} B)
mSub : {Δ : Con}{Γ : Con} → Sub Δ Γ → (ZOL.Sub M (mCon Δ) (mCon Γ))
mPf : {Γ : Con} {A : For} → Pf Γ A → ZOL.Pf M (mCon Γ) (mFor {Γ} A)
e[]f⁰ : {Γ : Con}{A B : For} → mFor {Γ ▹ₚ B} A ≡ ZOL._[_]f M (mFor {Γ} A) (ZOL.πₚ¹ M (ZOL.id M))
e[]f⁰ {A = ι} = ≡sym (ZOL.[]f-ι M)
e[]f⁰ {A = A ⇒ B} = ≡sym (≡tran (ZOL.[]f-⇒ M) (cong₂ (ZOL._⇒_ M) (≡sym (e[]f⁰ {A = A})) (≡sym (e[]f⁰ {A = B}))))
e[]f : {Γ Δ : Con}{A : For}{σ : Sub Δ Γ} → mFor {Δ} A ≡ ZOL._[_]f M (mFor {Γ} A) (mSub σ)
e[]f {A = ι} = ≡sym (ZOL.[]f-ι M)
e[]f {Γ} {Δ} {A = A ⇒ B} {σ} = ≡sym (≡tran (ZOL.[]f-⇒ M) (cong₂ (ZOL._⇒_ M) (≡sym (e[]f {A = A}{σ})) (≡sym (e[]f {A = B}{σ}))))
mPf {A = A} (var (pvzero {Γ})) = substP (ZOL.Pf M _) (≡sym (e[]f⁰ {Γ} {A} {A})) (ZOL.πₚ² M (ZOL.id M))
mPf {A = A} (var (pvnext {Γ} {B = B} pv)) = substP (ZOL.Pf M _) (≡sym (e[]f⁰ {Γ} {A} {B})) (ZOL._[_]p M (mPf (var pv)) (ZOL.πₚ¹ M (ZOL.id M)))
mPf {Γ} (lam {A = A} {B} pf) = ZOL.lam M (substP (ZOL.Pf M _) (e[]f⁰ {Γ} {B} {A}) (mPf pf))
mPf (app pf pf') = ZOL.app M (mPf pf) (mPf pf')
mSub ε = ZOL.ε M
mSub (_,ₚ_ {Δ} {Γ = Γ} {A} σ pf) = ZOL._,ₚ_ M (mSub σ) (substP (ZOL.Pf M _) (e[]f {Γ} {Δ} {A} {σ}) (mPf pf))
mor : Morphism zol M
mor = record {
m = record {
mCon = mCon
; mSub = mSub
; mFor = λ {Γ} A → mFor {Γ} A
; mPf = mPf
}
; e◇ = refl
; e[]f = λ {Γ}{Δ}{A}{σ} → e[]f {A = A} {σ}
; e▹ₚ = refl
; eι = refl
; e⇒ = refl
}
module InitialMorphismUniqueness {M : ZOL {lzero} {lzero} {lzero} {lzero}} {m : Morphism zol M} where
open InitialMorphism M
mCon≡ : {Γ : Con} → mCon Γ ≡ (Morphism.mCon m Γ)
mFor≡ : {Γ : Con} {A : For} → mFor {Γ} A ≡ subst (ZOL.For M) (≡sym mCon≡) (Morphism.mFor m {Γ} A)
mCon≡ {◇} = ≡sym (Morphism.e◇ m)
mCon≡ {Γ ▹ₚ A} = ≡sym (≡tran (Morphism.e▹ₚ m) (cong₂' (ZOL._▹ₚ_ M) (≡sym mCon≡) (≡sym mFor≡)))
mFor≡ {Γ} {ι} = ≡sym (≡tran
(cong (subst (ZOL.For M) (≡sym mCon≡)) (Morphism.eι m))
(substpoly {f = λ {Ξ} → ZOL.ι M {Ξ}} {eq = ≡sym mCon≡})
)
mFor≡ {Γ} {A ⇒ B} = ≡sym (≡tran²
(cong (subst (ZOL.For M) (≡sym mCon≡)) (Morphism.e⇒ m))
(substppoly {eq = ≡sym (mCon≡ {Γ})} {f = λ {ξ} X Y → ZOL._⇒_ M {ξ} X Y})
(cong₂ (ZOL._⇒_ M) (≡sym (mFor≡ {Γ} {A})) (≡sym (mFor≡ {Γ} {B}))))
-- Those two lines are not needed as those sorts are in Prop
--mSub≡ : {Δ : Con}{Γ : Con}{σ : Sub Δ Γ} → mSub {Δ} {Γ} σ ≡ Morphism.mSub m {Δ} {Γ} σ
--mPf≡ : {Γ : Con} {A : For}{p : Pf Γ A} → mPf {Γ} {A} p ≡ Morphism.mPf m {Γ} {A} p
\end{code}

View File

@ -36,7 +36,44 @@
\subsection{Structure of this report}
\section{A first account of Completeness and Normalization}
\subsection{Normalization for Propositional Logic}
\begin{figure}
\begin{tcolorbox}
\[
\begin{array}{lcl}
\For & : & \Set \\
- \implies - & : & \For \rightarrow \For \rightarrow \For\\
ι & : & \For \\
\\
\Pf & : & \For \rightarrow \Prop^+ \\
\lam & : & (\Pf A \rightarrow^+ \Pf B) \rightarrow \Pf (A \implies B)\\
\app & : & \Pf (A \implies B) \rightarrow (\Pf A \rightarrow \Pf B)
\end{array}
\]
\end{tcolorbox}
\caption{ZOL Sogat Presentation}
\label{fig:zol-sogat}
\end{figure}
\subsection{Normalization for Infinitary First Order Logic}
\begin{figure}
\begin{tcolorbox}
\[
\begin{array}{lcl}
\For & : & \Set \\
- \implies - & : & \For \rightarrow \For \rightarrow \For\\
\forall & : & (\operatorname{TM} \rightarrow \For) \rightarrow \For \\
\R & : & \operatorname{TM} \rightarrow \operatorname{TM} \rightarrow \For\\
\\
\Pf & : & \For \rightarrow \Prop^+ \\
\lam & : & (\Pf A \rightarrow^+ \Pf B) \rightarrow \Pf (A \implies B)\\
\app & : & \Pf (A \implies B) \rightarrow (\Pf A \rightarrow \Pf B)\\
\foralli & : & (t : \operatorname{TM} \rightarrow A\;t) \rightarrow \Pf (\forall A)\\
\foralle & : & \Pf (\forall A) \rightarrow (t : \operatorname{TM}) \rightarrow \Pf (A\;t)\\
\end{array}
\]
\end{tcolorbox}
\caption{ZOL Sogat Presentation}
\label{fig:ifol-sogat}
\end{figure}
\subsection{Merging the two proofs}
\section{Predicate Logic}
\subsection{SOGAT Presentation of Predicate Logic}

View File

@ -121,6 +121,7 @@
\newunicodechar{δ}{\textdelta}
\newunicodechar{ε}{\textvarepsilon}
\newunicodechar{σ}{\textsigma}
\newunicodechar{ι}{\textiota}
\newunicodechar{π}{\textpi}
\newunicodechar{λ}{\textlambda}
\newunicodechar{}{\ensuremath{\mathnormal{\triangleright}}}