Exercise 6.11
Let $Γ ⊢M : N$ in λC and $Γ ≡ x_1 : A_1,...,x_n : A_n$.
(a) Prove that the $x_1, ..., x_n$ are distinct.
(b) Prove the Free Variables Lemma (Lemma 6.3.3) for λC.
(c) Prove that $FV(A_i) ⊆\{x_1,...,x_{i−1}\}$, for $1 ≤i ≤n$.
(a) Definition 2.4.2 (3) states that "a context is a list of declarations with different subjects". So by definition, all the subjects $x_1, \ldots, x_n$ are distinct.
An alternative argument is to consider which derivation rules for λC allow for the building of a context. These are the (var) and (weak) rules. In both cases, a subject $x$ can only be added to an existing context if it doesn't already exist in that context. In this way, a derived context can only have distinct subjects.
(b) The Free Variables Lemma 6.3.3 for λC is
If $Γ ⊢A : B$, then $FV(A), FV(B) ⊆ dom(Γ)$.
The Free Variables Lemma for λC covers not just the term $A$ but also the type B, unlike λ→ for example.
To prove the lemma we use structural induction on the derivation rules for λC, reproduced here for ease of reference.
(sort) rule
There are no free variables in the expression $A \equiv *$, nor in $B \equiv \Box$. Thus the proposition is trivially true for $∅⊢*:☐$. That is, both $FV(A)$ and $FV(B)$ are empty sets, and so are subsets of any set, including $∅ \equiv dom(Γ)$.
(var) rule
Here the conclusion of the rule is $Γ,x:A ⊢ x:A$.
The induction hypothesis is that the lemma holds for the premise $Γ⊢A:s$. That is, $FV(A), FV(s) ⊆ dom(Γ)$.
Because the context $Γ,x:A$ is an extension of $Γ$ with $x:A$, this means $FV(x) ⊆ dom(Γ, x:A)$. We already have $FV(A) ⊆ dom(Γ)$, and since $dom(Γ) ⊆ dom(Γ,x:A)$, we have $FV(A) ⊆ dom(Γ, x:A)$.
Together, this means $FV(x), FV(A) ⊆ dom(Γ, x:A)$.
So the lemma holds for judgements resulting from the (var) rule.
(weak) rule
Here the conclusion of the rule is $Γ,x:C⊢A:B$.
The induction hypothesis is that the lemma holds for both premises $Γ⊢A:B$ and $Γ⊢C:s$. That is, $FV(A), FV(B) ⊆ dom(Γ)$ and $FV(C), FV(s) ⊆ dom(Γ)$.
Since the context $Γ,x:C$ is an extension of $Γ$ with $x:C$, we immediately have $FV(A), FV(B) ⊆ dom(Γ,x:A)$.
So the lemma holds for judgements resulting from the (weak) rule.
(form) rule
Here the conclusion of the rule is $Γ⊢\Pi x:A.B \; : \;s_2$.
The induction hypothesis is that the lemma holds for both premises $Γ⊢A:s_1$ and $Γ,x:A⊢B:s_2$. That is, $FV(A), FV(s_1) ⊆ dom(Γ)$ and $FV(B), FV(s_2) ⊆ dom(Γ,x:A)$.
We need to show that $FV(\Pi x:A.B), FV(s_2) ⊆ dom(Γ)$.
The free variables in $\Pi x:A,B$ are the free variables in $A$ and $B$ all except $x$, that is, $FV(A) \cup FV(B) \setminus {x}$. Since we know $FV(A)⊆dom(Γ)$ and $FV(B)⊆dom(Γ,x:A)$, we have $FV(\Pi x:A.B)⊆dom(Γ)$, since
$$\begin{align} FV(\Pi x:A.B) &= FV(A) \cup FV(B) \setminus \{x\} \\ \\ &⊆ dom(Γ) \cup dom(Γ,x:A) \setminus \{x\} \\ \\ & = dom(Γ, x:A) \setminus \{x\} \\ \\ & = dom(Γ) \end{align}$$
Now we consider $FV(s_2)$. By definition $s_2$ can only be $*$ or $\Box$, and so has no free variables. So vacuously $FV(s_2) ⊆ dom(Γ)$.
We've shown that $FV(\Pi x:A.B), FV(s_2) ⊆ dom(Γ)$, and so the lemma holds for judgements resulting from the (form) rule.
(appl) rule
Here the conclusion of the rule is $Γ⊢MN:B[x:=N]$.
The induction hypothesis is that the lemma holds for both premises $Γ⊢M:\Pi x:A.B$ and $Γ⊢N:A$. That is, $FV(M), FV(\Pi x:A.B) ⊆dom(Γ)$ and $FV(N), FV(A) ⊆ dom(Γ)$.
We need to show that $FV(MN), FV(B[x:=N]) ⊆ dom(Γ)$.
Since $FV(MN)= FV(M) \cup FV(N)$, we have $FV(MN) ⊆ dom(Γ)$.
Let's now consider $FV(B[x:=N])$. This is the set of free variables in $B$ except $x$ which has been substituted for $N$. So $FV(B[x:=N]) = FV(B) \setminus \{x\}$. We have $FV(\Pi x:A.B) ⊆dom(Γ) = FV(A) \cup FV(B) \setminus \{x\} ⊆dom(Γ)$.
Now, $FV(B) \setminus \{x\} ⊆ FV(A) \cup FV(B) \setminus \{x\}$, and so we conclude $FV(B) \setminus \{x\} ⊆ dom(Γ)$. That is, $FV(B[x:=N]) ⊆ dom(Γ)$.
So the lemma holds for judgements resulting from the (appl) rule.
(abst) rule
The conclusion of the rule is $Γ⊢λx:A.M : \Pi x:A.B$.
The induction hypotheses is that the lemma holds for both premises $Γ, x:A⊢M:B$ and $Γ⊢\Pi x:A.B:s$. That is $FV(M), FV(B) ⊆ dom(Γ,x:A)$ and $FV(A) \cup FV(B) \setminus \{x\}, FV(s) ⊆ dom(Γ)$.
We need to show that $FV(\lambda x:A.M), FV(\Pi x:A.B) ⊆ dom(Γ)$.
Let's start with $FV(\lambda x:A.M) = FV(A) \cup FV(M) \setminus \{x\}$. We know $FV(M)⊆dom(Γ, x:A)$ so $FV(M) \setminus \{x\} ⊆dom(Γ)$. We also know $FV(A) \cup FV(B) \setminus \{x\} ⊆ dom(Γ)$, which gives us $FV(A) \setminus \{x\} ⊆ dom(Γ)$. Together this gives us $FV(A) \cup FV(M) \setminus \{x\} ⊆ dom(Γ)$. That is, $FV(\lambda x:A.M) ⊆ dom(Γ)$.
Now let's consider $FV(\Pi x:A.B)$. We already know $FV(\Pi x:A.B) ⊆dom(Γ)$.
Together we have $FV(\lambda x:A.M), FV(\Pi x:A.B) ⊆ dom(Γ)$.
So the lemma holds for judgments resulting from the (abst) rule.
(conv) rule
The conclusion of the rule is $Γ⊢A:B'$.
The induction hypotheses is that the lemma holds for both premises $Γ⊢A:B$ and $Γ⊢B':s$. That is $FV(A), FV(B) ⊆dom(Γ)$ and $FV(B'), FV(s) ⊆dom(Γ)$.
We need to show that $FV(A), FV(B') ⊆dom(Γ)$.
We already have $FV(A)⊆dom(Γ)$ from the induction hypothesis. We also have $FV(B')⊆dom(Γ)$ from the induction hypothesis.
Together this is $FV(A), FV(B') ⊆dom(Γ)$.
So the lemma holds for judgements resulting from the (conv) rule.
Structural Induction
By showing that the lemma holds for the conclusion of each construction rule, assuming it holds for the premises, we have shown the lemma holds for all derivable judgements.
(c) We use structural induction on the derivation of the judgement $Γ ⊢M : N$ from premises using the rules for λC. Let's consider each rule in turn.
For each rule we assume the premises have well-scoped contexts, that is each free variable in each $A_i$ is defined earlier in the context. This assumption is the induction hypothesis. We aim to show the rule conclusion also has a well-scoped context.
(sort) rule
There is no premise. The context is empty, so it is vacuously true that it is well-scoped.
(var) rule
The premise is $Γ⊢A:s$, and for the induction hypothesis we assume the context is well scoped.
We need to show the context of the conclusion $Γ,x:A⊢x:A$ is also well-scoped.
Applying the Free Variables Lemma to the premise $Γ⊢A:s$ tells us that all the free variables in $A$ are in $Γ$. This means $Γ,x:A⊢x:A$ is well-scoped.
(weak) rule
The same logic applies to the (weak) rule as for the (var) rule.
(form), (appl), (abst), (conv) rules
All of these rules have same context in the premise as in the conclusion. The induction hypotheses that. the premise contexts are well-scoped immediately tells us the conclusion contexts are well-scoped too.
We have shown that all judgements derivable by the λC rules have well-scoped contexts.
So by structural induction we have finally shown that $FV(A_i) ⊆ \{x_1,...,x_{i−1}\}$, for $1 ≤i ≤n$.