Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic...
Transcript of Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic...
Basics of Staged Computation on Modal Logic
Joonwon Choi
11. 18. 2011
ROPAS Show & Tell
Contents
• Modal Logic / S4
• Modal logic and staged computation
• Modal λ-Calculus (Explicit)
• (Kripke-Style) Modal λ-Calculus (Implicit)
• A Limitation
• Future works
Modal Logic - Introduction
• Extends classical propositional and predicate logic to include operators expressing modality.
• Modals qualify a statement.
• For a statement p, – □p (necessarily p)
– ◇p (possibly p)
– ◇p ↔ ~□~p
– □p ↔ ~◇~p
Modal Logic - Frame, Model
• Frame – Non-empty set G
– Binary relation R
• Model: < 𝐺, 𝑅, ⊨ > – 𝑤 ⊨ ~𝑝 iff 𝑤 ⊭ 𝑝
– 𝑤 ⊨ 𝑝 ∧ 𝑞 iff 𝑤 ⊨ 𝑝 and 𝑤 ⊨ 𝑞
– 𝑤 ⊨ □𝑝 iff ∀𝑣 ∈ 𝐺 𝑠. 𝑡. 𝑤𝑅𝑣, 𝑣 ⊨ 𝑝
– 𝑤 ⊨ ⋄ 𝑝 iff ∃𝑣 ∈ 𝐺 𝑠. 𝑡. 𝑤𝑅𝑣, 𝑣 ⊨ 𝑝
Modal Logic - Logics
• K : no conditions
• D : serial – ∀𝑤 ∈ 𝐺, ∃𝑣 𝑠. 𝑡. 𝑤𝑅𝑣
• T : reflexive – ∀𝑤 ∈ 𝐺, 𝑤𝑅𝑤
• S4 : T + transitive – ∀𝑤, 𝑣, 𝑞 ∈ 𝐺, 𝑤𝑅𝑣 ∧ 𝑣𝑅𝑞 → 𝑤𝑅𝑞
• S5 : S4 + symmetric + euclidean – ∀𝑤, 𝑣 ∈ 𝐺, 𝑤𝑅𝑣 ↔ 𝑣𝑅𝑤
– ∀𝑤, 𝑣, 𝑞 ∈ 𝐺, 𝑤𝑅𝑞 ∧ 𝑣𝑅𝑞 → 𝑤𝑅𝑣 ∧ 𝑣𝑅𝑤
Modal Logic - Axiomatic
• N : (necessitation rule) If p is a theorem, then □p is a theorem.
• K : (distribution rule) □(p → q) → (□p → □q)
• T : □p → p
• 4 : □p → □□p
• B : p → □◇p
• D : □p → ◇p
• 5 : ◇p → □◇p
• K = K + N / T = K + T
• S4 = T + 4 / S5 = S4 + 5 / D = K + D
S4
• Preorder frame condition – Relation which is reflexive and transitive
• Thinking with the modality – Accessibility / Reachability
Modal logic and staged computation
• Key idea – □C represents code of type C.
– A constructor box where box E : □C
• Why modal logic, S4? – Validity
– Reachable world
Modal logic and staged computation - Harmony / Meaningful connective
• To know the balance between introduction and elimination rules, we need to check two properties.
– Local soundness: Elimination rules are not too strong.
• β-reduction
– Local completeness: Elimination rules are not too weak.
• η-expansion
Modal logic and staged computation - Harmony / Meaningful connective (2)
• Example: Conjunction – Local soundness
– Local completeness
Modal logic and staged computation - Validity
• A is valid if A true has a proof that does not require any truth assumptions. – 𝐴 𝑣𝑎𝑙𝑖𝑑 𝑖𝑓 ⋅ ⊢ 𝐴 𝑡𝑟𝑢𝑒
• Introduction(necessitation) : 𝐴 𝑣𝑎𝑙𝑖𝑑
Γ ⊢ □𝐴 𝑡𝑟𝑢𝑒 □𝐼
– Raises several problems…
• Elimination : Γ ⊢ □𝐴 𝑡𝑟𝑢𝑒
𝐴 𝑣𝑎𝑙𝑖𝑑 ?
– Unsound ∀𝐴,
□𝐴 𝑡𝑟𝑢𝑒 ⊢ □𝐴 𝑡𝑟𝑢𝑒𝐴 𝑣𝑎𝑙𝑖𝑑
Modal logic and staged computation - Finding the elimination rule (1)
• Elimination : Γ ⊢ □𝐴 𝑡𝑟𝑢𝑒
Γ ⊢ 𝐴 𝑡𝑟𝑢𝑒 ?
– Locally sound!
– But not locally complete; cannot apply the introduction rule
Γ ⊢ □𝐴 𝑡𝑟𝑢𝑒
Γ ⊢ 𝐴 𝑡𝑟𝑢𝑒Γ ⊢ □𝐴 𝑡𝑟𝑢𝑒 ?
Modal logic and staged computation - Finding the elimination rule (2)
• Solution: Introducing a judgment on propositions – “A is valid.”
• Write
– Under the hypothesis that
𝑢1: 𝐴1, … , 𝑢𝑚: 𝐴𝑚 are valid and 𝑥1: 𝐵1, … , 𝑥𝑛: 𝐵𝑛 are true, 𝐶 is true.
– Γ; Δ ⊢𝑒 𝐸: 𝐶
Modal logic and staged computation - Finding the elimination rule (3)
• New introduction rule
• And the elimination rule
Modal logic and staged computation - Subject reduction fails
• Another problem in subject reduction
Modal logic and staged computation - Subject reduction fails (2)
• Proof-term:
– Original : Correct!
– After performing a reduction : No longer well-typed…
Modal logic and staged computation - Subject reduction fails (3)
• One solution: – Fix it by constructing a modal substitution rule
Modal λ-Calculus (Explicit) - Inference
• Ordinary
• Modal
Modal λ-Calculus (Explicit) - Substitution
• Ordinary
• Modal
Modal λ-Calculus (Explicit) - Introduction / Elimination
• Ordinary
• Modal
Modal λ-Calculus (Explicit) - Local soundness / completeness
• Local soundness
• Local completeness
In case of modality
Modal λ-Calculus (Explicit) - Syntax / Typing rules
• Syntax
• Typing rules
Modal λ-Calculus (Explicit) - Type preservation
• Need to verify the characteristic properties – Exchange
– Weakening
– Contraction
– Substitution
• And subject reduction and expansion
Modal λ-Calculus (Implicit)
• Key idea – Explicit : Validity. Safe evaluation.
– Implicit : Multiple-world interpretation.
• Judgment
– Ψ : Context Stack
– Example
Modal λ-Calculus (Implicit) - Inference / Substitution
• Inference
• Substitution 𝐼𝑓 Ψ; Γ ⊢𝑖 𝑀1: 𝐴 𝑎𝑛𝑑 Ψ; Γ, 𝑥: 𝐴, Γ′ ; Ψ′ ⊢𝑖 𝑀2: 𝐶 𝑡ℎ𝑒𝑛 Ψ; Γ, Γ′ ; Ψ′ ⊢𝑖 𝑀1/𝑥 𝑀2: 𝐶
Modal λ-Calculus (Implicit) - Introduction / Elimination
• Ordinary
• Modal
Modal λ-Calculus (Implicit) - Local soundness / completeness
• Local soundness
• Local completeness
In case of modality
Modal λ-Calculus (Implicit) - Syntax / Typing rules
• Syntax
• Typing rules
Modal λ-Calculus (Implicit) - Subject reduction, revisited
• Substitution principle makes the failure of subject reduction again.
• Solution: Add a new rule
– Example:
Modal λ-Calculus (Implicit) - Type preservation ← Relabeling
• Also need to verify – Exchange, weakening, contraction, and substitution
• For proving the rules of subject reduction and expansion, we need to introduce relabeling.
Modal λ-Calculus (Implicit) - Relabeling → Subject reduction and expansion
• A relabeling theorem
– 𝐼𝑓 Ψ; Γ0; Δ1; … ; Δ𝑚 ⊢𝑖 𝑀: 𝐴 𝑡ℎ𝑒𝑛 Ψ; Γ0; … ; Γ𝑛, Δ1 ; … ; Δ𝑚 ⊢𝑖 {𝑛/𝑚}𝑀: 𝐴
• Subject reduction and expansion
Modal λ-Calculus (Implicit) - Relabeling → Subject reduction and expansion
• A relabeling theorem
– 𝐼𝑓 Ψ; Γ0; Δ1; … ; Δ𝑚 ⊢𝑖 𝑀: 𝐴 𝑡ℎ𝑒𝑛 Ψ; Γ0; … ; Γ𝑛, Δ1 ; … ; Δ𝑚 ⊢𝑖 {𝑛/𝑚}𝑀: 𝐴
• Subject reduction and expansion
A Limitation
• Two modal λ-Calculus systems cannot infer the type of following term.
• Reason 1. Polymorphism: X is an arbitrary argument.
2. Validity: X will not necessarily be bound to code.
– Compare to
𝜆𝑥. 𝐛𝐨𝐱 𝑥
𝜆𝑥. 𝐛𝐨𝐱 𝑥 1
A Limitation (continued)
• What if we can store a type environment whenever we construct box?
• 𝜆𝑜𝑝𝑒𝑛𝑠𝑖𝑚
–
"A Polymorphic Modal Type System for Lisp-Like Multi-Staged Languages." Ik-Soon Kim and Kwangkeun Yi and Cristiano Calcagno. Proceedings of The ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 2006. pp. 257--269.
Future works
• Study – Multi-staged languages
• Review – A Polymorphic Modal Type System for Lisp-Like Multi-Staged
Languages
– Static Analysis of Multi-Staged Programs via Unstaging Translation
Thank you!