CIS6700-Spring2025/Homework 8.md

91 lines
4.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

**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)
```