This leaves us with the cases in which we have one path contained in another. We'll need to tuck a few more appropriate lemmas under our belt before we can essay the remaining cases.
We'll need to prove these using induction on path-length, so let's define this useful concept.
length(s::p) = 1+length(p)
Also, a certain amount of hand-waving with respect to -conversion (and other matters) is going to occur. This is marked by the symbol
SC1 It is always the case that seen(v,E,())
SC2 Otherwise, if E = u, a variable, or E = c, a constant, then seen(v,E,p) holds.
SC3 Otherwise, if E = (F G), an application, then
SC3.1 If hd(p) = 0 then seen(v,E,p) iff seen(v,F,tl(p))
SC3.2 If hd(p) = 1 then seen(v,E,p) iff seen(v,G,tl(p))
SC4 Otherwise, if E = v.G then it is not the case that seen(v,E,p). In this case, we say that v goes out of scope.
SC5 Otherwise, if E = u.G then
SC5.1 If hd(p) = 0 then seen(v,E,p)
SC5.2 If hd(p) = 1 then seen(v,E,p) iff seen(v,G,tl(p))
We now proceed by induction on the length of p.
E'[p][v:=F] = C[p'][v:=F] = C[v:=F][p']
The last step above uses the inductive hypothesis, justified because length(p') = n, and seen(v,C,p') by SC3. On the other hand, using S5
Hence the result holds in this sub-case.
Since substitution converts an abstraction into an abstraction. So the result holds for this sub-case.
E'[p][v:=F] = (x . H)[p][v:=F]
= H[p'][v:=F]
= H[v:=F][p']
using the inductive hypothesis. On the other hand, we have our very favourite can of worms when we come to
E'[v:=F][p]
because we have to consider cases S5-S7 of the definition of substitution.
In this sub-sub-case, v goes out of scope, so, by ex falsa libet the result holds.
So the result holds in this sub-sub-case
This sub-case can't occur because of the way we have defined E'.
We now proceed by induction on the length of p.
E'[p:=G][v:=F] = (C[p':=G] D)[v:=F]
= (C[p':=G][v:=F] D[v:=F])
= (C[v:=F][p':=G[v:=F]] D[v:=F])
The last step above uses the inductive hypothesis, justified because length(p') = n, and seen(v,C,p') by SC3. On the other hand, using S5
= (C[v:=F][p':=G[v:=F]] D[v:=F])
Hence the result holds in this sub-case.
= (x . H)[v:=F]
= (x . H)[v:=F][p:=G[v:=F]]
Since substitution converts an abstraction into an abstraction. So the result holds for this sub-case.
Now we again (sigh!) have to consider cases S5-S7 of the definition of substitution.
In this sub-sub-case, v goes out of scope, so, by ex falsa libet the result holds.
= (x . H[p':=G])[v:=F] = (x . H[p':=G][v:=F])
= (x. H[v:=F][p':=G[v:=F]])
On the other hand,
= (x. H[v:=F])[p:=G[v:=F]]
= (x. H[v:=F][p':=G[v:=F]])
So the result holds in this sub-sub-case
Base Case n=0
By Lemma Sub.1, since v FV(F).
On the other hand
So the result is satisfied for this case.
On the other hand
by Lemma Sub.1, since u FV(G)
On the other hand
So the lemma holds in this case.
Suppose E = c C.
This case is similar to the preceding one.
Inductive Step
Suppose for a given n we have for any term E for which height(E) n
Consider an expression E of height n+1 We must show our result holds for E
.Using S4 repeatedly we obtain:
E[u:=F][v:=G] = (C D)[u:=F][v:=G]
= (C[u:=F] D[u:=F])[v:=G] = (C[u:=F][v:=G] D[u:=F][v:=G])
So using the inductive hypothesis.
= (C[v:=G][u:=F] D[v:=G][u:=F])
On the other hand,
(C[v:=G] D[v:=G])[u:=F]
= (C[v:=G][u:=F] D[v:=G][u:=F])
So the lemma holds in this case.
E[u:=F][v:=G] = (u . H)[u:=F][v:=G]
= (u . H)[v:=G]
= (u . H[v:=G])
since u G.
On the other hand
= (u . H[v:=G])[u:=F]
= (u . H[v:=G])
thus the lemma holds for this case.
E[u:=F][v:=G] = (v . H)[u:=F][v:=G]
= (v . H[u:=F])[v:=G]
since v FV[F]
= (v . H[u:=F])
On the other hand
= (v . H)[u:=F] = (v . H[u:=F])
Since v FV(F)
thus the lemma holds for this case.
Hence
E[u:=F][v:=G] = (x . H)[u:=F][v:=G]
= (x . H[u:=F])[v:=G]
= (x . H[u:=F][v:=G])
= (x . H[v:=G][u:=F])
by the inductive hypothesis.
On the other hand
since x FV[F] FV[G] this
= (x . H[v:=G])[u:=F]
= (x . H[v:=G][u:=F])
Let p be a path for which E[p] = ( v.D) H) where hd(p)=0 and hd(tl(p))=1. and also seen(u,E,p). Let p' = tl(tl(p)). Then
Let (E' = ( u'.C') G) and let v', D', H' be the converted forms of v,D,H.
Consider that by Lemma PT3.
= E'[p][u':=G] = (( v'.D') H)[u':=G]
= (( v'.D')[u':=G] H[u':=G])
= (( v'.D'[u':=G]) H[u':=G])
Which is a redex. So, we can work out
= (E'[p:=D'[v':=H']],())
= ((( u'. C'[p':=D'[v':=H']])G)),())
= C'[p':=D'[v':=H']][u':=G]
= C'[u':=G][p':=D'[v':=H'][u':=G]]
= C'[u':=G][p':=D'[u':=G][v':=H']]