Substitution Lemma - NoginCS101 Lecture 3 Type Preservation in -Calculus October 12, 2005 – p. 3...

5
CS101 Special Topics in Computer Science Language-Based Security Lecture 3: Type Preservation in λ-Calculus Aleksey Nogin October 12, 2005 CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 1 Reminder: λ-Calculus Typing Rules Here Γ and Δ stand for arbitrary number of hypotheses in a sequent. Γ n int (Number ) Γ; x : tx t (Var ) Γ e 1 int Γ e 2 int Γ e 1 op e 2 int (Binop ) Γ e 1 t 1 t 2 Γ e 2 t 1 Γ (e 1 e 2 ) t 2 (Apply ) Γ; x : t 1 e t 2 Γ λx : t 1 .e (t 1 t 2 ) (Fun ) CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 2 Substitution Lemma Lemma. If Γ; x : t 1 e t 2 and Γ; Δ e 0 t 1 , then Γ; Δ e[e 0 /x] t 2 . CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 3 Substitution Lemma Lemma. If Γ; x : t 1 e t 2 and Γ; Δ e 0 t 1 , then Γ; Δ e[e 0 /x] t 2 . Proof. By induction on the derivation of Γ; x : t 1 e t 2 CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 3

Transcript of Substitution Lemma - NoginCS101 Lecture 3 Type Preservation in -Calculus October 12, 2005 – p. 3...

Page 1: Substitution Lemma - NoginCS101 Lecture 3 Type Preservation in -Calculus October 12, 2005 – p. 3 Reminder: -Calculus Evaluation Numbers and functions are values: n ! n x : t:e !

CS101

Special Topics in Computer Science

Language-Based Security

Lecture 3: Type Preservation in λ-Calculus

Aleksey Nogin

October 12, 2005

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 1

Reminder:λ-Calculus Typing Rules

Here Γ and ∆ stand for arbitrary number of hypotheses in asequent.

Γ ` n ∈ int

(Number)Γ; x : t; ∆ ` x ∈ t

(Var)

Γ ` e1 ∈ int Γ ` e2 ∈ int

Γ ` e1 op e2 ∈ int

(Binop)

Γ ` e1 ∈ t1 → t2 Γ ` e2 ∈ t1

Γ ` (e1 e2) ∈ t2(Apply)

Γ; x : t1 ` e ∈ t2

Γ ` λx : t1.e ∈ (t1 → t2)(Fun)

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 2

Substitution LemmaLemma.If Γ; x : t1; ∆ ` e ∈ t2 and Γ; ∆ ` e′ ∈ t1, thenΓ; ∆ ` e[e′/x] ∈ t2.

Proof. By induction on the derivation of Γ; x : t1; ∆ ` e ∈ t2

CaseΓ ` n ∈ int

(Number) . Here e is n, t2 is int, e[e′/x] is

also n, Γ; ∆ ` e[e′/x] ∈ t2 can be proven using (Number).

CaseΓ; x : t; ∆ ` x ∈ t

(Var) . e is x, e[e′/x] is e′, t1 = t2.

CaseΓ; y : t; ∆ ` y ∈ t

(Var) .

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 3

Substitution LemmaLemma.If Γ; x : t1; ∆ ` e ∈ t2 and Γ; ∆ ` e′ ∈ t1, thenΓ; ∆ ` e[e′/x] ∈ t2.Proof. By induction on the derivation of Γ; x : t1; ∆ ` e ∈ t2

CaseΓ ` n ∈ int

(Number) . Here e is n, t2 is int, e[e′/x] is

also n, Γ; ∆ ` e[e′/x] ∈ t2 can be proven using (Number).

CaseΓ; x : t; ∆ ` x ∈ t

(Var) . e is x, e[e′/x] is e′, t1 = t2.

CaseΓ; y : t; ∆ ` y ∈ t

(Var) .

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 3

Page 2: Substitution Lemma - NoginCS101 Lecture 3 Type Preservation in -Calculus October 12, 2005 – p. 3 Reminder: -Calculus Evaluation Numbers and functions are values: n ! n x : t:e !

Substitution LemmaLemma.If Γ; x : t1; ∆ ` e ∈ t2 and Γ; ∆ ` e′ ∈ t1, thenΓ; ∆ ` e[e′/x] ∈ t2.Proof. By induction on the derivation of Γ; x : t1; ∆ ` e ∈ t2

CaseΓ ` n ∈ int

(Number) .

Here e is n, t2 is int, e[e′/x] is

also n, Γ; ∆ ` e[e′/x] ∈ t2 can be proven using (Number).

CaseΓ; x : t; ∆ ` x ∈ t

(Var) . e is x, e[e′/x] is e′, t1 = t2.

CaseΓ; y : t; ∆ ` y ∈ t

(Var) .

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 3

Substitution LemmaLemma.If Γ; x : t1; ∆ ` e ∈ t2 and Γ; ∆ ` e′ ∈ t1, thenΓ; ∆ ` e[e′/x] ∈ t2.Proof. By induction on the derivation of Γ; x : t1; ∆ ` e ∈ t2

CaseΓ ` n ∈ int

(Number) . Here e is n, t2 is int, e[e′/x] is

also n, Γ; ∆ ` e[e′/x] ∈ t2 can be proven using (Number).

CaseΓ; x : t; ∆ ` x ∈ t

(Var) . e is x, e[e′/x] is e′, t1 = t2.

CaseΓ; y : t; ∆ ` y ∈ t

(Var) .

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 3

Substitution LemmaLemma.If Γ; x : t1; ∆ ` e ∈ t2 and Γ; ∆ ` e′ ∈ t1, thenΓ; ∆ ` e[e′/x] ∈ t2.Proof. By induction on the derivation of Γ; x : t1; ∆ ` e ∈ t2

CaseΓ ` n ∈ int

(Number) . Here e is n, t2 is int, e[e′/x] is

also n, Γ; ∆ ` e[e′/x] ∈ t2 can be proven using (Number).

CaseΓ; x : t; ∆ ` x ∈ t

(Var) .

e is x, e[e′/x] is e′, t1 = t2.

CaseΓ; y : t; ∆ ` y ∈ t

(Var) .

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 3

Substitution LemmaLemma.If Γ; x : t1; ∆ ` e ∈ t2 and Γ; ∆ ` e′ ∈ t1, thenΓ; ∆ ` e[e′/x] ∈ t2.Proof. By induction on the derivation of Γ; x : t1; ∆ ` e ∈ t2

CaseΓ ` n ∈ int

(Number) . Here e is n, t2 is int, e[e′/x] is

also n, Γ; ∆ ` e[e′/x] ∈ t2 can be proven using (Number).

CaseΓ; x : t; ∆ ` x ∈ t

(Var) . e is x, e[e′/x] is e′, t1 = t2.

CaseΓ; y : t; ∆ ` y ∈ t

(Var) .

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 3

Page 3: Substitution Lemma - NoginCS101 Lecture 3 Type Preservation in -Calculus October 12, 2005 – p. 3 Reminder: -Calculus Evaluation Numbers and functions are values: n ! n x : t:e !

Substitution LemmaLemma.If Γ; x : t1; ∆ ` e ∈ t2 and Γ; ∆ ` e′ ∈ t1, thenΓ; ∆ ` e[e′/x] ∈ t2.Proof. By induction on the derivation of Γ; x : t1; ∆ ` e ∈ t2

CaseΓ ` n ∈ int

(Number) . Here e is n, t2 is int, e[e′/x] is

also n, Γ; ∆ ` e[e′/x] ∈ t2 can be proven using (Number).

CaseΓ; x : t; ∆ ` x ∈ t

(Var) . e is x, e[e′/x] is e′, t1 = t2.

CaseΓ; y : t; ∆ ` y ∈ t

(Var) .

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 3

Reminder:λ-Calculus Evaluation

Numbers and functions are values:

n −→ n λx : t.e −→ λx : t.e

Binary operations: e1 −→ n1 e2 −→ n2 n = n1 op n2

e1 op e2 −→ nFunction applications:e1 −→ λx : t.e′

1e2 −→ v e′

1[v/x] −→ v′

e1 e2 −→ v′

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 4

Homework IReminder:Homework I due Friday in class.

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 5

λ-Calculus:“Small-Step” Evaluation

Binary operations:

n1 op n2 → n(n = n1 op n2)

e1 → e′

1

e1 op e2 → e′

1op e2

e2 → e′

2

v op e2 → v op e′

2

Applications:

λx : t.e v → e[v/x]

e1 → e′

1

e1 e2 → e′

1e2

e2 → e′

2

v e2 → v e′

2

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 6

Page 4: Substitution Lemma - NoginCS101 Lecture 3 Type Preservation in -Calculus October 12, 2005 – p. 3 Reminder: -Calculus Evaluation Numbers and functions are values: n ! n x : t:e !

λ-Calculus:“Small-Step” Evaluation

Binary operations:

n1 op n2 → n(n = n1 op n2)

e1 → e′

1

e1 op e2 →

e′

1op e2

e2 → e′

2

v op e2 → v op e′

2

Applications:

λx : t.e v → e[v/x]

e1 → e′

1

e1 e2 → e′

1e2

e2 → e′

2

v e2 → v e′

2

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 6

λ-Calculus:“Small-Step” Evaluation

Binary operations:

n1 op n2 → n(n = n1 op n2)

e1 → e′

1

e1 op e2 →

e′

1op e2

e2 → e′

2

v op e2 → v op e′

2

Applications:

λx : t.e v → e[v/x]

e1 → e′

1

e1 e2 → e′

1e2

e2 → e′

2

v e2 → v e′

2

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 6

λ-Calculus:“Small-Step” Evaluation

Binary operations:

n1 op n2 → n(n = n1 op n2)

e1 → e′

1

e1 op e2 → e′

1op e2

e2 → e′

2

v op e2 → v op e′

2

Applications:

λx : t.e v → e[v/x]

e1 → e′

1

e1 e2 → e′

1e2

e2 → e′

2

v e2 → v e′

2

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 6

λ-Calculus:“Small-Step” Evaluation

Binary operations:

n1 op n2 → n(n = n1 op n2)

e1 → e′

1

e1 op e2 → e′

1op e2

e2 → e′

2

v op e2 → v op e′

2

Applications:

λx : t.e v → e[v/x]

e1 → e′

1

e1 e2 → e′

1e2

e2 → e′

2

v e2 → v e′

2

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 6

Page 5: Substitution Lemma - NoginCS101 Lecture 3 Type Preservation in -Calculus October 12, 2005 – p. 3 Reminder: -Calculus Evaluation Numbers and functions are values: n ! n x : t:e !

λ-Calculus:“Small-Step” Evaluation

Binary operations:

n1 op n2 → n(n = n1 op n2)

e1 → e′

1

e1 op e2 → e′

1op e2

e2 → e′

2

v op e2 → v op e′

2

Applications:

λx : t.e v → e[v/x]

e1 → e′

1

e1 e2 → e′

1e2

e2 → e′

2

v e2 → v e′

2

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 6

λ-Calculus:“Small-Step” Evaluation

Binary operations:

n1 op n2 → n(n = n1 op n2)

e1 → e′

1

e1 op e2 → e′

1op e2

e2 → e′

2

v op e2 → v op e′

2

Applications:

λx : t.e v → e[v/x]

e1 → e′

1

e1 e2 → e′

1e2

e2 → e′

2

v e2 → v e′

2

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 6

Type PreservationTheorem

Theorem. If ` e ∈ t and e → e′, then ` e′ ∈ t.Proof. By induction on derivation of e → e′.

CS101 Lecture 3 Type Preservation in λ-Calculus October 12, 2005 – p. 7