Advertisement
Guest User

Untitled

a guest
May 28th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. {-
  2.  
  3. An illustration of the McKinsey-Tarski translation of intuitionistic
  4. propositional logic into the modal logic S4, or normalisation by evaluation
  5. for the simply typed λ-calculus.
  6.  
  7. -}
  8.  
  9. module IPCMcKinseyTarski where
  10.  
  11. open import Data.Product using (_×_ ; _,_ ; proj₁ ; proj₂)
  12. open import Data.String using (String)
  13. open import Data.Unit using () renaming (⊤ to Unit ; tt to unit)
  14. open import Function using (_∘_)
  15. open import Relation.Binary using (Reflexive ; Transitive ; _Respects_)
  16. open import Relation.Binary.PropositionalEquality using (_≡_ ; refl)
  17.  
  18.  
  19. -- Propositional variables.
  20.  
  21. Atom : Set
  22. Atom = String
  23.  
  24.  
  25. -- Generic contexts.
  26.  
  27. data Cx (Ty : Set) : Set where
  28. ∅ : Cx Ty
  29. _,_ : Cx Ty → Ty → Cx Ty
  30.  
  31.  
  32. -- Context extensions.
  33.  
  34. data _⊆_ {Ty : Set} : Cx Ty → Cx Ty → Set where
  35. refl⊆ : ∀ {Γ} → Γ ⊆ Γ
  36. wk⊆ : ∀ {Γ Γ′ A} → Γ ⊆ Γ′ → Γ ⊆ (Γ′ , A)
  37.  
  38. trans⊆ : ∀ {Ty} {Γ Γ′ Γ″ : Cx Ty} → Γ ⊆ Γ′ → Γ′ ⊆ Γ″ → Γ ⊆ Γ″
  39. trans⊆ η refl⊆ = η
  40. trans⊆ η (wk⊆ η′) = wk⊆ (trans⊆ η η′)
  41.  
  42.  
  43. -- Syntax.
  44.  
  45. infixl 6 _∧_
  46. infixr 5 _⊃_
  47. data Ty : Set where
  48. ι_ : Atom → Ty
  49. ⊤ : Ty
  50. _∧_ : Ty → Ty → Ty
  51. _⊃_ : Ty → Ty → Ty
  52.  
  53. infix 0 _⊢_
  54. data _⊢_ : Cx Ty → Ty → Set where
  55. hyp : ∀ {Γ A} → Γ , A ⊢ A
  56. wk : ∀ {Γ A B} → Γ ⊢ A → Γ , B ⊢ A
  57. unit : ∀ {Γ} → Γ ⊢ ⊤
  58. pair : ∀ {Γ A B} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ∧ B
  59. fst : ∀ {Γ A B} → Γ ⊢ A ∧ B → Γ ⊢ A
  60. snd : ∀ {Γ A B} → Γ ⊢ A ∧ B → Γ ⊢ B
  61. lam : ∀ {Γ A B} → Γ , A ⊢ B → Γ ⊢ A ⊃ B
  62. app : ∀ {Γ A B} → Γ ⊢ A ⊃ B → Γ ⊢ A → Γ ⊢ B
  63.  
  64. mono⊢ : ∀ {Γ Γ′ A} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A
  65. mono⊢ refl⊆ t = t
  66. mono⊢ (wk⊆ η) t = wk (mono⊢ η t)
  67.  
  68.  
  69. -- Intuitionistic Kripke models.
  70.  
  71. record Model : Set₁ where
  72. field
  73. World : Set
  74.  
  75. -- Accessibility.
  76. _≤_ : World → World → Set
  77. refl≤ : Reflexive _≤_
  78. trans≤ : Transitive _≤_
  79.  
  80. -- Forcing for propositional variables.
  81. _⊩∙_ : World → Atom → Set
  82. mono⊩∙ : ∀ {x} → (_⊩∙ x) Respects _≤_
  83.  
  84. open Model {{...}}
  85.  
  86.  
  87. -- Semantics, after McKinsey-Tarski.
  88.  
  89. infix 0 _⊨_
  90. _⊨_ : ∀ {{_ : Model}} → World → Ty → Set
  91. w ⊨ (ι x) = w ⊩∙ x
  92. w ⊨ ⊤ = Unit
  93. w ⊨ A ∧ B = (w ⊨ A) × (w ⊨ B)
  94. w ⊨ A ⊃ B = ∀ {w′} → w ≤ w′ → (w′ ⊨ A) → (w′ ⊨ B)
  95.  
  96. mono⊨ : ∀ {{_ : Model}} {w w′} A → w ≤ w′ → w ⊨ A → w′ ⊨ A
  97. mono⊨ (ι x) ξ s = mono⊩∙ ξ s
  98. mono⊨ ⊤ ξ s = unit
  99. mono⊨ (A ∧ B) ξ s = mono⊨ A ξ (proj₁ s) , mono⊨ B ξ (proj₂ s)
  100. mono⊨ (A ⊃ B) ξ s = λ ξ′ a → s (trans≤ ξ ξ′) a
  101.  
  102.  
  103. -- Closure over contexts.
  104.  
  105. infix 0 _⊨*_
  106. _⊨*_ : ∀ {{_ : Model}} → World → Cx Ty → Set
  107. w ⊨* ∅ = Unit
  108. w ⊨* Γ , A = (w ⊨* Γ) × (w ⊨ A)
  109.  
  110. mono⊨* : ∀ {{_ : Model}} {w w′} Γ → w ≤ w′ → w ⊨* Γ → w′ ⊨* Γ
  111. mono⊨* ∅ ξ unit = unit
  112. mono⊨* (Γ , A) ξ (γ , a) = mono⊨* Γ ξ γ , mono⊨ A ξ a
  113.  
  114.  
  115. -- The canonical model.
  116.  
  117. instance
  118. ⟪IPC⟫ : Model
  119. ⟪IPC⟫ = record
  120. { World = Cx Ty
  121. ; _≤_ = _⊆_
  122. ; refl≤ = refl⊆
  123. ; trans≤ = trans⊆
  124. ; _⊩∙_ = λ w x → w ⊢ ι x
  125. ; mono⊩∙ = mono⊢
  126. }
  127.  
  128.  
  129. -- Completeness and soundness with respect to the canonical model.
  130.  
  131. mutual
  132. reify : ∀ {Γ} A → Γ ⊨ A → Γ ⊢ A
  133. reify (ι x) s = s
  134. reify ⊤ s = unit
  135. reify (A ∧ B) s = pair (reify A (proj₁ s)) (reify B (proj₂ s))
  136. reify (A ⊃ B) s = lam (reify B (s (wk⊆ refl⊆) (reflect A hyp)))
  137.  
  138. reflect : ∀ {Γ} A → Γ ⊢ A → Γ ⊨ A
  139. reflect (ι x) t = t
  140. reflect ⊤ t = unit
  141. reflect (A ∧ B) t = reflect A (fst t) , reflect B (snd t)
  142. reflect (A ⊃ B) t = λ ξ a → reflect B (app (mono⊢ ξ t) (reify A a))
  143.  
  144.  
  145. -- TODO: What is the right name for this?
  146.  
  147. id⊨* : ∀ {Γ} → Γ ⊨* Γ
  148. id⊨* {∅} = unit
  149. id⊨* {Γ , A} = mono⊨* Γ (wk⊆ refl⊆) id⊨* , reflect A hyp
  150.  
  151.  
  152. -- Forcing for propositions.
  153.  
  154. infix 0 _⊩_
  155. _⊩_ : Cx Ty → Ty → Set₁
  156. Γ ⊩ A = ∀ {{m : Model}} {w : World {{m}}} → w ⊨* Γ → w ⊨ A
  157.  
  158.  
  159. -- Completeness.
  160.  
  161. quot : ∀ {Γ A} → Γ ⊩ A → Γ ⊢ A
  162. quot {A = A} t = reify A (t id⊨*)
  163.  
  164.  
  165. -- Soundness.
  166.  
  167. eval : ∀ {Γ A} → Γ ⊢ A → Γ ⊩ A
  168. eval hyp (γ , a) = a
  169. eval (wk t) (γ , a) = eval t γ
  170. eval unit γ = unit
  171. eval (pair t₁ t₂) γ = eval t₁ γ , eval t₂ γ
  172. eval (fst t) γ = proj₁ (eval t γ)
  173. eval (snd t) γ = proj₂ (eval t γ)
  174. eval (lam t) γ = λ ξ a → eval t (mono⊨* _ ξ γ , a)
  175. eval (app t₁ t₂) γ = (eval t₁ γ) refl≤ (eval t₂ γ)
  176.  
  177.  
  178. -- TODO: What is the right name for this?
  179.  
  180. canon₁ : ∀ {Γ} A → Γ ⊩ A → Γ ⊨ A
  181. canon₁ A = reflect A ∘ quot
  182.  
  183. canon₂ : ∀ {Γ} A → Γ ⊨ A → Γ ⊩ A
  184. canon₂ A = eval ∘ reify A
  185.  
  186.  
  187. -- Normalisation by evaluation.
  188.  
  189. norm : ∀ {Γ A} → Γ ⊢ A → Γ ⊢ A
  190. norm = quot ∘ eval
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement