Homework 8

This commit is contained in:
Jonathan Chan 2025-04-18 16:47:32 -04:00
parent 7c971a7989
commit 43f1499c72
1 changed files with 91 additions and 0 deletions

91
Homework 8.md Normal file
View File

@ -0,0 +1,91 @@
**Exercise 26.3.5**:
```
SBool ≜ ∀X <: . T <: X. F <: X. T F X
STrue ≜ ∀X <: . T <: X. F <: X. T F T
SFalse ≜ ∀X <: . T <: X. F <: X. T F F
notft : SFalse → STrue
notft = λsfalse : SFalse. ΛX <: . ΛT <: X. ΛF <: X. λt : T. λf : F. t
nottf : STrue → SFalse
nottf = λstrue : STrue. ΛX <: . ΛT <: X. ΛF <: X. λt : T. λf : F. f
```
**Exercise 26.4.11**:
1. If Γ ⊢ S₁ → S₂ <: T, then T = or T = T₁ T with Γ T <: S and Γ S <: T.
2. If Γ ⊢ ∀X <: U. S <: T, then T = or T = ∀X <: U. T with Γ, X <: U S <: T.
3. If Γ ⊢ X <: T, then T = or T = X or Γ S <: T with X <: S Γ.
4. If Γ ⊢ <: T, then T = .
**Proof**:
4. By induction on the subtyping derivation. The cases not listed are impossible.
* S-Refl: T = .
* S-Trans: The premises are Γ ⊢ <: U and Γ U <: T.
By the induction hypothesis, U = and T = .
* S-Top: Trivial.
1. By induction on the subtyping derivation. The cases not listed are impossible.
* S-Refl: T = S₁ → S₂ with Γ ⊢ S₁ <: S and Γ S <: S by S-Refl.
* S-Trans: The premises are Γ ⊢ S₁ → S₂ <: U and Γ U <: T.
By the induction hypothesis on the first premise, either U = , so T = by (4),
or U = U₁ → U₂ with Γ ⊢ U₁ <: S and Γ S <: U.
By the induction hypothesis on the second premise, either T = ,
or T = T₁ → T₂ with Γ ⊢ T₁ <: U and Γ U <: T.
Then by S-Trans, Γ ⊢ T₁ <: S and Γ S <: T.
* S-Arrow: Trivially the second case by the premises.
2. By induction on the subtyping derivation. The cases not listed are impossible.
* S-Refl: T = ∀X <: U. S with Γ, X <: U S <: S by S-Refl.
* S-Trans: The premises are Γ ∀X <: U. S <: V and Γ V <: T.
By the induction hypothesis on the first premise, either V = , so T = by (4),
or V = ∀X <: U. V with Γ, X <: U S <: V.
By the induction hypothesis on the second premise, either T = ,
or T = ∀X <: U. T with Γ, X <: U V <: T.
Then by S-Trans, Γ, X <: U S <: T.
* S-All: Trivially the second case by the premise.
3. By induction on the subtyping derivation. The cases not listed are impossible.
* S-Refl: Trivially the second case.
* S-Trans: The premises are Γ ⊢ X <: U and Γ U <: T.
By the induction hypothesis on the first premise, there are three possibilities:
- U = , so T = by (4).
- U = X. By the induction hypothesis on the second premise,
either T = by (4), or T = X, or Γ ⊢ S <: T with X <: S Γ, as desired.
- Γ ⊢ S <: U with X <: S Γ. Then by S-Trans, Γ S <: T.
* S-Var: Trivially the last case with Γ ⊢ T <: T by S-Refl.
**Exercise 28.2.3**:
2. If Γ ⊢ t : T, then Γ ⊢> t : M with Γ ⊢ M <: T.
**Proof**:
1. Case T-TApp: The premises are Γ ⊢ t₁ : ∀X <: T. T and Γ T <: T.
We wish to show that Γ ⊢> t₁ [T₂] : M₂ for some M₂ with Γ ⊢ M₂ <: T[X T].
By the induction hypothesis, we have Γ ⊢> t₁ : M₁ with Γ ⊢ M₁ <: X <: T. T.
Let M₁ ⇑ N₁, knowing that N₁ is not a variable.
By the exposure lemma, we have Γ ⊢ N₁ <: X <: T. T.
By inversion, N₁ = ∀X <: S. S with Γ T <: S and Γ, X <: S S <: T.
By S-Trans, Γ ⊢ T₂ <: S.
By TA-TApp, we have Γ ⊢> t₁ [T₂] : S₁₂[X ↦ T₂].
Finally, we have Γ ⊢ S₁₂[X ↦ T₂] <: T[X T] by preservation of subtyping under substitution.
**Exercise 28.7.1**:
It seems to me that you would also need to compute a *maximal X-free subtype*,
which I'll call Q{X,Γ}(T), defined mutually with R{X,Γ}(T)
both by recursion on the type.
```
R{X,Γ} : Type → Type
Q{X,Γ} : Option Type → Type
R{X,Γ}(Y) ≜ if X == Y then else Y
R{X,Γ}(S → T) ≜
case Q{X,Γ}(S) of
some S' ⇒ S' → R{X,Γ}(T)
none ⇒
R{X,Γ}(∀Y <: U. T) Y <: U. R{X,Γ}(T)
R{X,Γ}(∃Y <: S. T) Y <: R{X,Γ}(S). R{X,Γ}(T)
Q{X,Γ}(Y) ≜ if X == Y then none else some Y
Q{X,Γ}(S → T) ≜
case Q{X,Γ}(T) of
some T' ⇒ R{X,Γ}(S) → T'
none ⇒ none
Q{X,Γ}(∀Y <: U. T) Y <: U. Q{X,Γ}(T)
Q{X,Γ}(∃Y <: S. T) Y <: Q{X,Γ}(S). Q{X,Γ}(T)
```