Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic...

36
Basics of Staged Computation on Modal Logic Joonwon Choi 11. 18. 2011 ROPAS Show & Tell

Transcript of Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic...

Page 1: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Basics of Staged Computation on Modal Logic

Joonwon Choi

11. 18. 2011

ROPAS Show & Tell

Page 2: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Contents

• Modal Logic / S4

• Modal logic and staged computation

• Modal λ-Calculus (Explicit)

• (Kripke-Style) Modal λ-Calculus (Implicit)

• A Limitation

• Future works

Page 3: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

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

Page 4: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal Logic - Frame, Model

• Frame – Non-empty set G

– Binary relation R

• Model: < 𝐺, 𝑅, ⊨ > – 𝑤 ⊨ ~𝑝 iff 𝑤 ⊭ 𝑝

– 𝑤 ⊨ 𝑝 ∧ 𝑞 iff 𝑤 ⊨ 𝑝 and 𝑤 ⊨ 𝑞

– 𝑤 ⊨ □𝑝 iff ∀𝑣 ∈ 𝐺 𝑠. 𝑡. 𝑤𝑅𝑣, 𝑣 ⊨ 𝑝

– 𝑤 ⊨ ⋄ 𝑝 iff ∃𝑣 ∈ 𝐺 𝑠. 𝑡. 𝑤𝑅𝑣, 𝑣 ⊨ 𝑝

Page 5: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal Logic - Logics

• K : no conditions

• D : serial – ∀𝑤 ∈ 𝐺, ∃𝑣 𝑠. 𝑡. 𝑤𝑅𝑣

• T : reflexive – ∀𝑤 ∈ 𝐺, 𝑤𝑅𝑤

• S4 : T + transitive – ∀𝑤, 𝑣, 𝑞 ∈ 𝐺, 𝑤𝑅𝑣 ∧ 𝑣𝑅𝑞 → 𝑤𝑅𝑞

• S5 : S4 + symmetric + euclidean – ∀𝑤, 𝑣 ∈ 𝐺, 𝑤𝑅𝑣 ↔ 𝑣𝑅𝑤

– ∀𝑤, 𝑣, 𝑞 ∈ 𝐺, 𝑤𝑅𝑞 ∧ 𝑣𝑅𝑞 → 𝑤𝑅𝑣 ∧ 𝑣𝑅𝑤

Page 6: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

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

Page 7: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

S4

• Preorder frame condition – Relation which is reflexive and transitive

• Thinking with the modality – Accessibility / Reachability

Page 8: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

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

Page 9: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

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

Page 10: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal logic and staged computation - Harmony / Meaningful connective (2)

• Example: Conjunction – Local soundness

– Local completeness

Page 11: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

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 ∀𝐴,

□𝐴 𝑡𝑟𝑢𝑒 ⊢ □𝐴 𝑡𝑟𝑢𝑒𝐴 𝑣𝑎𝑙𝑖𝑑

Page 12: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal logic and staged computation - Finding the elimination rule (1)

• Elimination : Γ ⊢ □𝐴 𝑡𝑟𝑢𝑒

Γ ⊢ 𝐴 𝑡𝑟𝑢𝑒 ?

– Locally sound!

– But not locally complete; cannot apply the introduction rule

Γ ⊢ □𝐴 𝑡𝑟𝑢𝑒

Γ ⊢ 𝐴 𝑡𝑟𝑢𝑒Γ ⊢ □𝐴 𝑡𝑟𝑢𝑒 ?

Page 13: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

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.

– Γ; Δ ⊢𝑒 𝐸: 𝐶

Page 14: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal logic and staged computation - Finding the elimination rule (3)

• New introduction rule

• And the elimination rule

Page 15: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal logic and staged computation - Subject reduction fails

• Another problem in subject reduction

Page 16: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal logic and staged computation - Subject reduction fails (2)

• Proof-term:

– Original : Correct!

– After performing a reduction : No longer well-typed…

Page 17: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal logic and staged computation - Subject reduction fails (3)

• One solution: – Fix it by constructing a modal substitution rule

Page 18: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Explicit) - Inference

• Ordinary

• Modal

Page 19: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Explicit) - Substitution

• Ordinary

• Modal

Page 20: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Explicit) - Introduction / Elimination

• Ordinary

• Modal

Page 21: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Explicit) - Local soundness / completeness

• Local soundness

• Local completeness

In case of modality

Page 22: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Explicit) - Syntax / Typing rules

• Syntax

• Typing rules

Page 23: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Explicit) - Type preservation

• Need to verify the characteristic properties – Exchange

– Weakening

– Contraction

– Substitution

• And subject reduction and expansion

Page 24: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Implicit)

• Key idea – Explicit : Validity. Safe evaluation.

– Implicit : Multiple-world interpretation.

• Judgment

– Ψ : Context Stack

– Example

Page 25: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Implicit) - Inference / Substitution

• Inference

• Substitution 𝐼𝑓 Ψ; Γ ⊢𝑖 𝑀1: 𝐴 𝑎𝑛𝑑 Ψ; Γ, 𝑥: 𝐴, Γ′ ; Ψ′ ⊢𝑖 𝑀2: 𝐶 𝑡ℎ𝑒𝑛 Ψ; Γ, Γ′ ; Ψ′ ⊢𝑖 𝑀1/𝑥 𝑀2: 𝐶

Page 26: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Implicit) - Introduction / Elimination

• Ordinary

• Modal

Page 27: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Implicit) - Local soundness / completeness

• Local soundness

• Local completeness

In case of modality

Page 28: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Implicit) - Syntax / Typing rules

• Syntax

• Typing rules

Page 29: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Implicit) - Subject reduction, revisited

• Substitution principle makes the failure of subject reduction again.

• Solution: Add a new rule

– Example:

Page 30: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

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.

Page 31: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Implicit) - Relabeling → Subject reduction and expansion

• A relabeling theorem

– 𝐼𝑓 Ψ; Γ0; Δ1; … ; Δ𝑚 ⊢𝑖 𝑀: 𝐴 𝑡ℎ𝑒𝑛 Ψ; Γ0; … ; Γ𝑛, Δ1 ; … ; Δ𝑚 ⊢𝑖 {𝑛/𝑚}𝑀: 𝐴

• Subject reduction and expansion

Page 32: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Modal λ-Calculus (Implicit) - Relabeling → Subject reduction and expansion

• A relabeling theorem

– 𝐼𝑓 Ψ; Γ0; Δ1; … ; Δ𝑚 ⊢𝑖 𝑀: 𝐴 𝑡ℎ𝑒𝑛 Ψ; Γ0; … ; Γ𝑛, Δ1 ; … ; Δ𝑚 ⊢𝑖 {𝑛/𝑚}𝑀: 𝐴

• Subject reduction and expansion

Page 33: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

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

Page 34: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

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.

Page 35: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

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

Page 36: Basics of Staged Computation on Modal Logicjwchoi/talks/snt111118.pdf · 2013-03-15 · Modal logic and staged computation - Harmony / Meaningful connective • To know the balance

Thank you!