{-# OPTIONS --allow-unsolved-metas #-}
module A201607.WIP2.BasicIS4.Semantics.Sketch5 where
open import A201607.Common.Semantics public
open import A201607.BasicIS4.Syntax.Common public
record Model : Set₁ where
infix 3 _⊪ᵅ_ _[⊢]_
infix 5 _≤_ _R_
infixl 5 _[,]_ _[m,]_
field
World : Set
_≤_ : World → World → Set
refl≤ : ∀ {w} → w ≤ w
trans≤ : ∀ {w w′ w″} → w ≤ w′ → w′ ≤ w″ → w ≤ w″
_R_ : World → World → Set
reflR : ∀ {w} → w R w
transR : ∀ {w w′ w″} → w R w′ → w′ R w″ → w R w″
_≤⨾R_ : World → World → Set
_≤⨾R_ = _≤_ ⨾ _R_
_R⨾≤_ : World → World → Set
_R⨾≤_ = _R_ ⨾ _≤_
field
≤⨾R→R : ∀ {v′ w} → w ≤⨾R v′ → w R v′
⌊_⌋ : World → World
≤→⌊≤⌋ : ∀ {w w′} → w ≤ w′ → ⌊ w ⌋ ≤ ⌊ w′ ⌋
R→⌊≤⌋ : ∀ {w w′} → w R w′ → ⌊ w ⌋ ≤ ⌊ w′ ⌋
lem₁ : ∀ {w} → ⌊ w ⌋ ≤ w
lem₂ : ∀ {w} → ⌊ w ⌋ ≤ ⌊ ⌊ w ⌋ ⌋
lem₃ : ∀ {w} → ⌊ ⌊ w ⌋ ⌋ ≤ ⌊ w ⌋
[∅] : World
_[,]_ : World → Ty → World
_[m,]_ : World → Ty → World
_[∈]_ : Ty → World → Set
_[m∈]_ : Ty → World → Set
_[⊢]_ : World → Ty → Set
mono[⊢] : ∀ {A w w′} → w ≤ w′ → w [⊢] A → w′ [⊢] A
[var] : ∀ {A w} → A [∈] w → w [⊢] A
[lam] : ∀ {A B w} → w [,] A [⊢] B → w [⊢] A ▻ B
[app] : ∀ {A B w} → w [⊢] A ▻ B → w [⊢] A → w [⊢] B
[mvar] : ∀ {A w} → A [m∈] w → w [⊢] A
[box] : ∀ {A w} → ⌊ w ⌋ [⊢] A → w [⊢] □ A
[unbox] : ∀ {A C w} → w [⊢] □ A → w [m,] A [⊢] C → w [⊢] C
[pair] : ∀ {A B w} → w [⊢] A → w [⊢] B → w [⊢] A ∧ B
[fst] : ∀ {A B w} → w [⊢] A ∧ B → w [⊢] A
[snd] : ∀ {A B w} → w [⊢] A ∧ B → w [⊢] B
[unit] : ∀ {w} → w [⊢] ⊤
_[⊢ⁿᶠ]_ : World → Ty → Set
_⊪ᵅ_ : World → Atom → Set
mono⊪ᵅ : ∀ {P w w′} → w ≤ w′ → w ⊪ᵅ P → w′ ⊪ᵅ P
≤⨾R→R⨾≤ : ∀ {v′ w} → w ≤⨾R v′ → w R⨾≤ v′
≤⨾R→R⨾≤ {v′} ξ,ζ = v′ , (≤⨾R→R ξ,ζ , refl≤)
reflR⨾≤ : ∀ {w} → w R⨾≤ w
reflR⨾≤ {w} = w , (reflR , refl≤)
transR⨾≤ : ∀ {w′ w w″} → w R⨾≤ w′ → w′ R⨾≤ w″ → w R⨾≤ w″
transR⨾≤ {w′} (v , (ζ , ξ)) (v′ , (ζ′ , ξ′)) = let v″ , (ζ″ , ξ″) = ≤⨾R→R⨾≤ (w′ , (ξ , ζ′))
in v″ , (transR ζ ζ″ , trans≤ ξ″ ξ′)
≤→R : ∀ {v′ w} → w ≤ v′ → w R v′
≤→R {v′} ξ = ≤⨾R→R (v′ , (ξ , reflR))
infix 3 _[⊢]⋆_
_[⊢]⋆_ : World → Cx Ty → Set
w [⊢]⋆ ∅ = 𝟙
w [⊢]⋆ Ξ , A = w [⊢]⋆ Ξ × w [⊢] A
mono[⊢]⋆ : ∀ {Ξ w w′} → w ≤ w′ → w [⊢]⋆ Ξ → w′ [⊢]⋆ Ξ
mono[⊢]⋆ {∅} ξ ∙ = ∙
mono[⊢]⋆ {Ξ , A} ξ (ts , t) = mono[⊢]⋆ ξ ts , mono[⊢] ξ t
open Model {{…}} public
module _ {{_ : Model}} where
mutual
infix 3 _⊪_
_⊪_ : World → Ty → Set
w ⊪ α P = w ⊪ᵅ P
w ⊪ A ▻ B = ∀ {w′ : World} → w ≤ w′ → w′ ⊩ A → w′ ⊩ B
w ⊪ □ A = ∀ {w′ : World} → w R w′ → Glue (⌊ w′ ⌋ [⊢] A) (⌊ w′ ⌋ ⊩ A)
w ⊪ A ∧ B = w ⊩ A × w ⊩ B
w ⊪ ⊤ = 𝟙
infix 3 _⊩_
_⊩_ : World → Ty → Set
w ⊩ A = ∀ {C} {w′ : World} → w ≤ w′ → (∀ {w″ : World} → w′ ≤ w″ → w″ ⊪ A → w″ [⊢ⁿᶠ] C) → w′ [⊢ⁿᶠ] C
infix 3 _⊩⋆_
_⊩⋆_ : World → Cx Ty → Set
w ⊩⋆ ∅ = 𝟙
w ⊩⋆ Ξ , A = w ⊩⋆ Ξ × w ⊩ A
module _ {{_ : Model}} where
mutual
mono⊪ : ∀ {A} {w w′ : World} → w ≤ w′ → w ⊪ A → w′ ⊪ A
mono⊪ {α P} ξ s = mono⊪ᵅ ξ s
mono⊪ {A ▻ B} ξ s = λ ξ′ a → s (trans≤ ξ ξ′) a
mono⊪ {□ A} ξ s = λ ζ′ → s (transR (≤→R ξ) ζ′)
mono⊪ {A ∧ B} ξ s = mono⊩ {A} ξ (π₁ s) , mono⊩ {B} ξ (π₂ s)
mono⊪ {⊤} ξ s = ∙
mono⊩ : ∀ {A} {w w′ : World} → w ≤ w′ → w ⊩ A → w′ ⊩ A
mono⊩ ξ a = λ ξ′ k′ → a (trans≤ ξ ξ′) k′
mono⊩⋆ : ∀ {Ξ} {w w′ : World} → w ≤ w′ → w ⊩⋆ Ξ → w′ ⊩⋆ Ξ
mono⊩⋆ {∅} ξ ∙ = ∙
mono⊩⋆ {Ξ , A} ξ (γ , a) = mono⊩⋆ {Ξ} ξ γ , mono⊩ {A} ξ a
module _ {{_ : Model}} where
_⟪$⟫_ : ∀ {A B} {w : World} → w ⊪ A ▻ B → w ⊩ A → w ⊩ B
s ⟪$⟫ a = s refl≤ a
return : ∀ {A} {w : World} → w ⊪ A → w ⊩ A
return {A} a = λ ξ k → k refl≤ (mono⊪ {A} ξ a)
bind : ∀ {A B} {w : World} → w ⊩ A → (∀ {w′ : World} → w ≤ w′ → w′ ⊪ A → w′ ⊩ B) → w ⊩ B
bind a k = λ ξ k′ → a ξ (λ ξ′ a′ → k (trans≤ ξ ξ′) a′ refl≤ (λ ξ″ a″ → k′ (trans≤ ξ′ ξ″) a″))
infix 3 _⊨_
_⊨_ : Cx² Ty Ty → Ty → Set₁
Γ ⁏ Δ ⊨ A = ∀ {{_ : Model}} {w : World} → w ⊩⋆ Γ → ⌊ w ⌋ [⊢]⋆ Δ → ⌊ w ⌋ ⊩⋆ Δ → w ⊩ A
infix 3 _⊨⋆_
_⊨⋆_ : Cx² Ty Ty → Cx Ty → Set₁
Γ ⁏ Δ ⊨⋆ Ξ = ∀ {{_ : Model}} {w : World} → w ⊩⋆ Γ → ⌊ w ⌋ [⊢]⋆ Δ → ⌊ w ⌋ ⊩⋆ Δ → w ⊩⋆ Ξ
module _ {{_ : Model}} where
lookup : ∀ {A Γ} {w : World} → A ∈ Γ → w ⊩⋆ Γ → w ⊩ A
lookup top (γ , a) = a
lookup (pop i) (γ , b) = lookup i γ
open import A201607.BasicIS4.Syntax.DyadicGentzenNormalForm public
module _ {{_ : Model}} where
⌈_⌉ : Cx² Ty Ty → World
⌈ ∅ ⁏ ∅ ⌉ = [∅]
⌈ Γ , A ⁏ ∅ ⌉ = ⌈ Γ ⁏ ∅ ⌉ [,] A
⌈ ∅ ⁏ Δ , B ⌉ = ⌈ ∅ ⁏ Δ ⌉ [m,] B
⌈ Γ , A ⁏ Δ , B ⌉ = ⌈ Γ ⁏ Δ ⌉ [,] A [m,] B
postulate
lemᵢ : ∀ {Δ Γ A} → A [∈] ⌈ Γ , A ⁏ Δ ⌉
lemᵢᵢ : ∀ {Δ Γ A B} → A [∈] ⌈ Γ ⁏ Δ ⌉ → A [∈] ⌈ Γ , B ⁏ Δ ⌉
lemₘ : ∀ {Γ Δ A} → A [m∈] ⌈ Γ ⁏ Δ , A ⌉
lemₘₘ : ∀ {Γ Δ A B} → A [m∈] ⌈ Γ ⁏ Δ ⌉ → A [m∈] ⌈ Γ ⁏ Δ , B ⌉
⟨_⟩ : ∀ {Δ Γ A} → A ∈ Γ → A [∈] ⌈ Γ ⁏ Δ ⌉
⟨_⟩ {Δ} top = lemᵢ {Δ}
⟨_⟩ {Δ} (pop i) = lemᵢᵢ {Δ} ⟨ i ⟩
m⟨_⟩ : ∀ {Γ Δ A} → A ∈ Δ → A [m∈] ⌈ Γ ⁏ Δ ⌉
m⟨_⟩ {Γ} top = lemₘ {Γ}
m⟨_⟩ {Γ} (pop i) = lemₘₘ {Γ} (m⟨_⟩ {Γ} i)
postulate
lem₄ : ∀ {A Γ Δ} → ⌈ Γ ⁏ Δ ⌉ [,] A ≡ ⌈ Γ , A ⁏ Δ ⌉
lem₅ : ∀ {A Γ Δ} → ⌈ Γ ⁏ Δ ⌉ [m,] A ≡ ⌈ Γ ⁏ Δ , A ⌉
lem₆ : ∀ {Δ A B Γ} → ⌈ Γ , A ⁏ Δ ⌉ [⊢] B → ⌈ Γ ⁏ Δ ⌉ [,] A [⊢] B
lem₇ : ∀ {Γ A C Δ} → ⌈ Γ ⁏ Δ , A ⌉ [⊢] C → ⌈ Γ ⁏ Δ ⌉ [m,] A [⊢] C
lem₈ : ∀ {Γ A Δ} → ⌈ ∅ ⁏ Δ ⌉ [⊢] A → ⌊ ⌈ Γ ⁏ Δ ⌉ ⌋ [⊢] A
[_] : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → ⌈ Γ ⁏ Δ ⌉ [⊢] A
[ var i ] = [var] ⟨ i ⟩
[ lam {Δ = Δ} t ] = [lam] (lem₆ {Δ} [ t ])
[ app t u ] = [app] [ t ] [ u ]
[ mvar {Γ = Γ} i ] = [mvar] (m⟨_⟩ {Γ} i)
[ box {Γ = Γ} t ] = [box] (lem₈ {Γ} [ t ])
[ unbox {Γ = Γ} t u ] = [unbox] [ t ] (lem₇ {Γ} [ u ])
[ pair t u ] = [pair] [ t ] [ u ]
[ fst t ] = [fst] [ t ]
[ snd t ] = [snd] [ t ]
[ unit ] = [unit]
postulate
bla₁ : ∀ {Γ Δ} → ⌈ Γ ⁏ ∅ ⌉ ≤ ⌈ Γ ⁏ Δ ⌉
bla₂ : ∀ {Γ Δ A} → ⌈ ∅ ⁏ Δ ⌉ [⊢] A → ⌊ ⌈ Γ ⁏ Δ ⌉ ⌋ [⊢] A
ble₁ : ∀ {w : World} → [∅] ≤ ⌊ w ⌋
ble₂ : ∀ {A} {w : World} → ⌊ w ⌋ [⊢] A → ⌊ ⌊ w ⌋ ⌋ [⊢] A
ugh₁ : ∀ {Δ} {w : World} {A} → ⌊ w ⌋ [⊢]⋆ Δ → ⌈ ∅ ⁏ Δ ⌉ [⊢] A → ⌊ w ⌋ [⊢] A
ugh₁ {∅} {w} ∙ u = {!!}
ugh₁ {Δ , B} {w} (ts , t) u = [unbox] ([box] (ble₂ t)) {!u!}
module _ {{_ : Model}} where
cor₁ : ∀ {w w′ : World} → ⌊ w ⌋ ≤ ⌊ w′ ⌋ → ⌊ w ⌋ ≤ ⌊ ⌊ w′ ⌋ ⌋
cor₁ ξ = trans≤ ξ lem₂
eval : ∀ {Γ Δ A} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊨ A
eval (var i) γ ד δ = lookup i γ
eval (lam {A} {B} t) γ ד δ = return {A ▻ B} λ ξ a →
eval t (mono⊩⋆ ξ γ , a)
(mono[⊢]⋆ (≤→⌊≤⌋ ξ) ד)
(mono⊩⋆ (≤→⌊≤⌋ ξ) δ)
eval (app {A} {B} t u) γ ד δ = bind {A ▻ B} {B} (eval t γ ד δ) λ ξ f →
_⟪$⟫_ {A} {B} f (eval u (mono⊩⋆ ξ γ)
(mono[⊢]⋆ (≤→⌊≤⌋ ξ) ד)
(mono⊩⋆ (≤→⌊≤⌋ ξ) δ))
eval (mvar {A} i) γ ד δ = mono⊩ {A} lem₁ (lookup i δ)
eval {Γ} {Δ} (box {A} t) γ ד δ = return {□ A} λ ζ →
let ד′ = mono[⊢]⋆ (R→⌊≤⌋ ζ) ד
t′ = [ t ]
in {!!} ⅋
eval t ∙
(mono[⊢]⋆ (cor₁ (R→⌊≤⌋ ζ)) ד)
(mono⊩⋆ (cor₁ (R→⌊≤⌋ ζ)) δ)
eval (unbox {A} {C} t u) γ ד δ = bind {□ A} {C} (eval t γ ד δ) λ ξ a →
eval u (mono⊩⋆ ξ γ)
(mono[⊢]⋆ (≤→⌊≤⌋ ξ) ד , syn (a reflR))
(mono⊩⋆ (≤→⌊≤⌋ ξ) δ , sem (a reflR))
eval (pair {A} {B} t u) γ ד δ = return {A ∧ B} (eval t γ ד δ , eval u γ ד δ)
eval (fst {A} {B} t) γ ד δ = bind {A ∧ B} {A} (eval t γ ד δ) (K π₁)
eval (snd {A} {B} t) γ ד δ = bind {A ∧ B} {B} (eval t γ ד δ) (K π₂)
eval unit γ ד δ = return {⊤} ∙
eval⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ ⊨⋆ Ξ
eval⋆ {∅} ∙ γ ד δ = ∙
eval⋆ {Ξ , A} (ts , t) γ ד δ = eval⋆ ts γ ד δ , eval t γ ד δ
private
instance
canon : Model
canon = record
{ World = Cx² Ty Ty
; _≤_ = _⊆²_
; refl≤ = refl⊆²
; trans≤ = trans⊆²
; _R_ = λ { (Γ ⁏ Δ) (Γ′ ⁏ Δ′) → Δ ⊆ Δ′ }
; reflR = refl⊆
; transR = trans⊆
; ≤⨾R→R = λ { (w′ , ((η , θ) , θ′)) → trans⊆ θ θ′ }
; ⌊_⌋ = λ { (Γ ⁏ Δ) → ∅ ⁏ Δ }
; ≤→⌊≤⌋ = λ { (η , θ) → refl⊆ , θ }
; R→⌊≤⌋ = λ θ → refl⊆ , θ
; lem₁ = bot⊆ , refl⊆
; lem₂ = refl⊆²
; lem₃ = refl⊆²
; [∅] = ∅ ⁏ ∅
; _[,]_ = λ { (Γ ⁏ Δ) A → Γ , A ⁏ Δ }
; _[m,]_ = λ { (Γ ⁏ Δ) A → Γ ⁏ Δ , A }
; _[∈]_ = λ { A (Γ ⁏ Δ) → A ∈ Γ }
; _[m∈]_ = λ { A (Γ ⁏ Δ) → A ∈ Δ }
; _[⊢]_ = _⊢_
; mono[⊢] = mono²⊢
; [var] = var
; [lam] = lam
; [app] = app
; [mvar] = mvar
; [box] = box
; [unbox] = unbox
; [pair] = pair
; [fst] = fst
; [snd] = snd
; [unit] = unit
; _[⊢ⁿᶠ]_ = _⊢ⁿᶠ_
; _⊪ᵅ_ = λ { (Γ ⁏ Δ) P → Γ ⁏ Δ ⊢ⁿᵉ α P }
; mono⊪ᵅ = mono²⊢ⁿᵉ
}
module _ {U : Set} where
grab∈ : ∀ {A : U} {Γ Γ′} → Γ , A ⊆ Γ′ → A ∈ Γ′
grab∈ (skip η) = pop (grab∈ η)
grab∈ (keep η) = top
mutual
reifyᶜ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊩ A → Γ ⁏ Δ ⊢ⁿᶠ A
reifyᶜ {α P} k = k refl⊆² λ ξ s → neⁿᶠ s
reifyᶜ {A ▻ B} k = k refl⊆² λ ξ s → lamⁿᶠ (reifyᶜ (s weak⊆²₁ (reflectᶜ {A} (varⁿᵉ top))))
reifyᶜ {□ A} k = k refl⊆² λ {w} ξ s → boxⁿᶠ (syn (s {w} refl⊆))
reifyᶜ {A ∧ B} k = k refl⊆² λ ξ s → pairⁿᶠ (reifyᶜ (π₁ s)) (reifyᶜ (π₂ s))
reifyᶜ {⊤} k = k refl⊆² λ ξ s → unitⁿᶠ
reflectᶜ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ⁿᵉ A → Γ ⁏ Δ ⊩ A
reflectᶜ {α P} t = return {α P} t
reflectᶜ {A ▻ B} t = return {A ▻ B} λ { (η , θ) a →
reflectᶜ {B} (appⁿᵉ (mono²⊢ⁿᵉ (η , θ) t) (reifyᶜ a)) }
reflectᶜ {□ A} t = λ { (η , θ) k →
neⁿᶠ (unboxⁿᵉ (mono²⊢ⁿᵉ (η , θ) t) (k (refl⊆ , weak⊆) λ θ′ →
mvar (grab∈ θ′) ⅋
reflectᶜ {A} (mvarⁿᵉ (grab∈ θ′))))}
reflectᶜ {A ∧ B} t = return {A ∧ B} (reflectᶜ (fstⁿᵉ t) , reflectᶜ (sndⁿᵉ t))
reflectᶜ {⊤} t = return {⊤} ∙
reifyᶜ⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊩⋆ Ξ → Γ ⁏ Δ ⊢⋆ⁿᶠ Ξ
reifyᶜ⋆ {∅} ∙ = ∙
reifyᶜ⋆ {Ξ , A} (ts , t) = reifyᶜ⋆ ts , reifyᶜ t
reflectᶜ⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊢⋆ⁿᵉ Ξ → Γ ⁏ Δ ⊩⋆ Ξ
reflectᶜ⋆ {∅} ∙ = ∙
reflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t
refl⊩⋆ : ∀ {Γ Δ} → Γ ⁏ Δ ⊩⋆ Γ
refl⊩⋆ = reflectᶜ⋆ refl⊢⋆ⁿᵉ
mrefl₀[⊢]⋆ : ∀ {Δ} → ∅ ⁏ Δ [⊢]⋆ Δ
mrefl₀[⊢]⋆ {∅} = ∙
mrefl₀[⊢]⋆ {Δ , A} = mono[⊢]⋆ (refl⊆ , weak⊆) mrefl₀[⊢]⋆ , [mvar] top
mrefl₀⊢⋆ⁿᵉ : ∀ {Δ} → ∅ ⁏ Δ ⊢⋆ⁿᵉ Δ
mrefl₀⊢⋆ⁿᵉ {∅} = ∙
mrefl₀⊢⋆ⁿᵉ {Γ , A} = mmono⊢⋆ⁿᵉ weak⊆ mrefl₀⊢⋆ⁿᵉ , mvarⁿᵉ top
mrefl₀⊩⋆ : ∀ {Δ} → ∅ ⁏ Δ ⊩⋆ Δ
mrefl₀⊩⋆ = reflectᶜ⋆ mrefl₀⊢⋆ⁿᵉ
quot : ∀ {A Γ Δ} → Γ ⁏ Δ ⊨ A → Γ ⁏ Δ ⊢ⁿᶠ A
quot s = reifyᶜ (s refl⊩⋆ mrefl₀[⊢]⋆ mrefl₀⊩⋆)
norm : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ⁿᶠ A
norm = quot ∘ eval