Refactoring 2

Extension of a version space

If v is a version space, it's extension is written [[vv]] and defined recursively as:

  • [[ii]]={i}
  • [[λvλv]]={λe:e[[vv]]}
  • [[(v1 v2)(v1 v2)]]={(e1 e2):e1[[v1v1]] ,e2[[v2v2]]}
  • [[+V+V]]={e:vV and e[[vv]]}
β

Iβ(u)={(λb)v:vbS0(u)}{ if u is a primitive or index or : if u is Λ:{Λ} if u=λb:{λIβ(b)} if u=(fx):{(Iβ(f)x),(fIβ(x))} if u=V:{Iβ(u)uV}

So what is this mysterious Iβ? well, if p was a program in [[uu]], then [[Iβ(u)Iβ(u)]] suggests programs p for which pp is a semantically equivalent re-write.

Iβ is consistent

For any p[[Iβ(u)Iβ(u)]], there exists p[[uu]] such that pp.

proof:


Theorem 4: Completeness of Iβ

Statement:
Let pp and p[u]. Then p[Iβ(u)].

Proof:
We proceed by structural induction on u.

  1. Base Case: u=V
    There exists a vV such that p[v]. By induction on v, combined with the definition of Iβ, we have
    p[Iβ(v)][Iβ(u)],
    which is what we needed to show.

  2. Inductive Case: Assume uV.

    From the definition of pp, at least one of the following cases must hold:

    • Case 1: p=(λb)v and p=1[$01v]b
      Since 1[$01v]b[u], we can invoke the completeness of Sn to construct a (vb)S0(u) such that v[v] and b[b]. Combining these facts with the definition of Iβ, we get:
      p=(λb)v[(λb)v][Iβ(u)].

    • Case 2: p=λb and p=λb where bb
      Because p=λb[u] and by assumption uV, we know that u=λv and b[v]. By induction, b[Iβ(v)]. Combining with the definition of Iβ, we get:
      p=λb[λIβ(v)][Iβ(u)].

    • Case 3: p=(fx) and p=(fx) where xx
      This case is symmetric to the previous case and follows a similar argument.


Theorem 5: Consistency and Completeness of Iβn

Statement:
Let p and p be programs. Then:
p⟶⟶⟶n times p
if and only if p[Iβn(p)].

Proof:
We proceed by induction on n.

  1. Base Case: n=0
    In this case, [Iβn(p)]={p} and p=p. The theorem holds immediately.

  2. Inductive Step: Assume n>0.
    If p⟶⟶⟶n times p, then there exists a q such that
    qn1 times p.
    By induction on n, we have q[Iβn1(p)]. Combined with pq, we can invoke the completeness of Iβ to get:
    p[Iβ(Iβn1(p))][Iβn(p)].

    Conversely, if p[Iβn(p)], by unrolling the definitions, p reduces to p in at most n steps. This completes the proof.