module plfa.part2.Confluence where

Introduction

In this chapter we prove that beta reduction is confluent, a property also known as Church-Rosser. That is, if there are reduction sequences from any term L to two different terms M₁ and Mβ‚‚, then there exist reduction sequences from those two terms to some common term N. In pictures:

    L
   / \
  /   \
 /     \
M₁      Mβ‚‚
 \     /
  \   /
   \ /
    N

where downward lines are instances of β€”β† .

Confluence is studied in many other kinds of rewrite systems besides the lambda calculus, and it is well known how to prove confluence in rewrite systems that enjoy the diamond property, a single-step version of confluence. Let ⇛ be a relation. Then ⇛ has the diamond property if whenever L ⇛ M₁ and L ⇛ Mβ‚‚, then there exists an N such that M₁ ⇛ N and Mβ‚‚ ⇛ N. This is just an instance of the same picture above, where downward lines are now instance of ⇛. If we write ⇛* for the reflexive and transitive closure of ⇛, then confluence of ⇛* follows immediately from the diamond property.

Unfortunately, reduction in the lambda calculus does not satisfy the diamond property. Here is a counter example.

(Ξ» x. x x)((Ξ» x. x) a) β€”β†’ (Ξ» x. x x) a
(Ξ» x. x x)((Ξ» x. x) a) β€”β†’ ((Ξ» x. x) a) ((Ξ» x. x) a)

Both terms can reduce to a a, but the second term requires two steps to get there, not one.

To side-step this problem, we’ll define an auxilliary reduction relation, called parallel reduction, that can perform many reductions simultaneously and thereby satisfy the diamond property. Furthermore, we show that a parallel reduction sequence exists between any two terms if and only if a beta reduction sequence exists between them. Thus, we can reduce the proof of confluence for beta reduction to confluence for parallel reduction.

Imports

open import Relation.Binary.PropositionalEquality using (_≑_; refl)
open import Function using (_∘_)
open import Data.Product using (_Γ—_; Ξ£; Ξ£-syntax; βˆƒ; βˆƒ-syntax; proj₁; projβ‚‚)
  renaming (_,_ to ⟨_,_⟩)
open import plfa.part2.Substitution using (Rename; Subst)
open import plfa.part2.Untyped
  using (_β€”β†’_; Ξ²; ξ₁; ΞΎβ‚‚; ΞΆ; _β€”β† _; begin_; _β€”β†’βŸ¨_⟩_; _β€”β† βŸ¨_⟩_; _∎;
  abs-cong; appL-cong; appR-cong; β€”β† -trans;
  _⊒_; _βˆ‹_; `_; #_; _,_; β˜…; Ζ›_; _Β·_; _[_];
  rename; ext; exts; Z; S_; subst; subst-zero)

Parallel Reduction

The parallel reduction relation is defined as follows.

infix 2 _⇛_

data _⇛_ : βˆ€ {Ξ“ A} β†’ (Ξ“ ⊒ A) β†’ (Ξ“ ⊒ A) β†’ Set where

  pvar : βˆ€{Ξ“ A}{x : Ξ“ βˆ‹ A}
      ---------
    β†’ (` x) ⇛ (` x)

  pabs : βˆ€{Ξ“}{N Nβ€² : Ξ“ , β˜… ⊒ β˜…}
    β†’ N ⇛ Nβ€²
      ----------
    β†’ Ζ› N ⇛ Ζ› Nβ€²

  papp : βˆ€{Ξ“}{L Lβ€² M Mβ€² : Ξ“ ⊒ β˜…}
    β†’ L ⇛ Lβ€²
    β†’ M ⇛ Mβ€²
      -----------------
    β†’ L Β· M ⇛ Lβ€² Β· Mβ€²

  pbeta : βˆ€{Ξ“}{N Nβ€²  : Ξ“ , β˜… ⊒ β˜…}{M Mβ€² : Ξ“ ⊒ β˜…}
    β†’ N ⇛ Nβ€²
    β†’ M ⇛ Mβ€²
      -----------------------
    β†’ (Ζ› N) Β· M  ⇛  Nβ€² [ Mβ€² ]

The first three rules are congruences that reduce each of their parts simultaneously. The last rule reduces a lambda term and term in parallel followed by a beta step.

We remark that the pabs, papp, and pbeta rules perform reduction on all their subexpressions simultaneously. Also, the pabs rule is akin to the ΞΆ rule and pbeta is akin to Ξ².

Parallel reduction is reflexive.

par-refl : βˆ€{Ξ“ A}{M : Ξ“ ⊒ A} β†’ M ⇛ M
par-refl {Ξ“} {A} {` x} = pvar
par-refl {Ξ“} {β˜…} {Ζ› N} = pabs par-refl
par-refl {Ξ“} {β˜…} {L Β· M} = papp par-refl par-refl

We define the sequences of parallel reduction as follows.

infix  2 _⇛*_
infixr 2 _β‡›βŸ¨_⟩_
infix  3 _∎

data _⇛*_ : βˆ€ {Ξ“ A} β†’ (Ξ“ ⊒ A) β†’ (Ξ“ ⊒ A) β†’ Set where

  _∎ : βˆ€ {Ξ“ A} (M : Ξ“ ⊒ A)
      --------
    β†’ M ⇛* M

  _β‡›βŸ¨_⟩_ : βˆ€ {Ξ“ A} (L : Ξ“ ⊒ A) {M N : Ξ“ ⊒ A}
    β†’ L ⇛ M
    β†’ M ⇛* N
      ---------
    β†’ L ⇛* N

Exercise par-diamond-eg (practice)

Revisit the counter example to the diamond property for reduction by showing that the diamond property holds for parallel reduction in that case.

-- Your code goes here

Equivalence between parallel reduction and reduction

Here we prove that for any M and N, M ⇛* N if and only if M β€”β†  N. The only-if direction is particularly easy. We start by showing that if M β€”β†’ N, then M ⇛ N. The proof is by induction on the reduction M β€”β†’ N.

beta-par : βˆ€{Ξ“ A}{M N : Ξ“ ⊒ A}
  β†’ M β€”β†’ N
    ------
  β†’ M ⇛ N
beta-par {Ξ“} {β˜…} {L Β· M} (ξ₁ r) = papp (beta-par {M = L} r) par-refl
beta-par {Ξ“} {β˜…} {L Β· M} (ΞΎβ‚‚ r) = papp par-refl (beta-par {M = M} r)
beta-par {Ξ“} {β˜…} {(Ζ› N) Β· M} Ξ² = pbeta par-refl par-refl
beta-par {Ξ“} {β˜…} {Ζ› N} (ΞΆ r) = pabs (beta-par r)

With this lemma in hand we complete the only-if direction, that M β€”β†  N implies M ⇛* N. The proof is a straightforward induction on the reduction sequence M β€”β†  N.

betas-pars : βˆ€{Ξ“ A} {M N : Ξ“ ⊒ A}
  β†’ M β€”β†  N
    ------
  β†’ M ⇛* N
betas-pars {Ξ“} {A} {M₁} {.M₁} (M₁ ∎) = M₁ ∎
betas-pars {Ξ“} {A} {.L} {N} (L β€”β†’βŸ¨ b ⟩ bs) =
   L β‡›βŸ¨ beta-par b ⟩ betas-pars bs

Now for the other direction, that M ⇛* N implies M β€”β†  N. The proof of this direction is a bit different because it’s not the case that M ⇛ N implies M β€”β†’ N. After all, M ⇛ N performs many reductions. So instead we shall prove that M ⇛ N implies M β€”β†  N.

par-betas : βˆ€{Ξ“ A}{M N : Ξ“ ⊒ A}
  β†’ M ⇛ N
    ------
  β†’ M β€”β†  N
par-betas {Ξ“} {A} {.(` _)} (pvar{x = x}) = (` x) ∎
par-betas {Ξ“} {β˜…} {Ζ› N} (pabs p) = abs-cong (par-betas p)
par-betas {Ξ“} {β˜…} {L Β· M} (papp {L = L}{Lβ€²}{M}{Mβ€²} p₁ pβ‚‚) =
    begin
    L Β· M   β€”β† βŸ¨ appL-cong{M = M} (par-betas p₁) ⟩
    Lβ€² Β· M  β€”β† βŸ¨ appR-cong (par-betas pβ‚‚) ⟩
    Lβ€² Β· Mβ€²
    ∎
par-betas {Ξ“} {β˜…} {(Ζ› N) Β· M} (pbeta{Nβ€² = Nβ€²}{Mβ€² = Mβ€²} p₁ pβ‚‚) =
    begin
    (Ζ› N) Β· M                    β€”β† βŸ¨ appL-cong{M = M} (abs-cong (par-betas p₁)) ⟩
    (Ζ› Nβ€²) Β· M                   β€”β† βŸ¨ appR-cong{L = Ζ› Nβ€²} (par-betas pβ‚‚)  ⟩
    (Ζ› Nβ€²) Β· Mβ€²                  β€”β†’βŸ¨ Ξ² ⟩
     Nβ€² [ Mβ€² ]
    ∎

The proof is by induction on M ⇛ N.

  • Suppose x ⇛ x. We immediately have x β€”β†  x.

  • Suppose Ζ› N ⇛ Ζ› Nβ€² because N ⇛ Nβ€². By the induction hypothesis we have N β€”β†  Nβ€². We conclude that Ζ› N β€”β†  Ζ› Nβ€² because β€”β†  is a congruence.

  • Suppose L Β· M ⇛ Lβ€² Β· Mβ€² because L ⇛ Lβ€² and M ⇛ Mβ€². By the induction hypothesis, we have L β€”β†  Lβ€² and M β€”β†  Mβ€². So L Β· M β€”β†  Lβ€² Β· M and then Lβ€² Β· M β€”β†  Lβ€² Β· Mβ€² because β€”β†  is a congruence.

  • Suppose (Ζ› N) Β· M ⇛ Nβ€² [ Mβ€² ] because N ⇛ Nβ€² and M ⇛ Mβ€². By similar reasoning, we have (Ζ› N) Β· M β€”β†  (Ζ› Nβ€²) Β· Mβ€² which we can following with the Ξ² reduction (Ζ› Nβ€²) Β· Mβ€² β€”β†’ Nβ€² [ Mβ€² ].

With this lemma in hand, we complete the proof that M ⇛* N implies M β€”β†  N with a simple induction on M ⇛* N.

pars-betas : βˆ€{Ξ“ A} {M N : Ξ“ ⊒ A}
  β†’ M ⇛* N
    ------
  β†’ M β€”β†  N
pars-betas (M₁ ∎) = M₁ ∎
pars-betas (L β‡›βŸ¨ p ⟩ ps) = β€”β† -trans (par-betas p) (pars-betas ps)

Substitution lemma for parallel reduction

Our next goal is the prove the diamond property for parallel reduction. But to do that, we need to prove that substitution respects parallel reduction. That is, if N ⇛ Nβ€² and M ⇛ Mβ€², then N [ M ] ⇛ Nβ€² [ Mβ€² ]. We cannot prove this directly by induction, so we generalize it to: if N ⇛ Nβ€² and the substitution Οƒ pointwise parallel reduces to Ο„, then subst Οƒ N ⇛ subst Ο„ Nβ€². We define the notion of pointwise parallel reduction as follows.

par-subst : βˆ€{Ξ“ Ξ”} β†’ Subst Ξ“ Ξ” β†’ Subst Ξ“ Ξ” β†’ Set
par-subst {Ξ“}{Ξ”} Οƒ Οƒβ€² = βˆ€{A}{x : Ξ“ βˆ‹ A} β†’ Οƒ x ⇛ Οƒβ€² x

Because substitution depends on the extension function exts, which in turn relies on rename, we start with a version of the substitution lemma, called par-rename, that is specialized to renamings. The proof of par-rename relies on the fact that renaming and substitution commute with one another, which is a lemma that we import from Chapter Substitution and restate here.

rename-subst-commute : βˆ€{Ξ“ Ξ”}{N : Ξ“ , β˜… ⊒ β˜…}{M : Ξ“ ⊒ β˜…}{ρ : Rename Ξ“ Ξ” }
    β†’ (rename (ext ρ) N) [ rename ρ M ] ≑ rename ρ (N [ M ])
rename-subst-commute {N = N} = plfa.part2.Substitution.rename-subst-commute {N = N}

Now for the par-rename lemma.

par-rename : βˆ€{Ξ“ Ξ” A} {ρ : Rename Ξ“ Ξ”} {M Mβ€² : Ξ“ ⊒ A}
  β†’ M ⇛ Mβ€²
    ------------------------
  β†’ rename ρ M ⇛ rename ρ Mβ€²
par-rename pvar = pvar
par-rename (pabs p) = pabs (par-rename p)
par-rename (papp p₁ pβ‚‚) = papp (par-rename p₁) (par-rename pβ‚‚)
par-rename {Ξ“}{Ξ”}{A}{ρ} (pbeta{Ξ“}{N}{Nβ€²}{M}{Mβ€²} p₁ pβ‚‚)
    with pbeta (par-rename{ρ = ext ρ} p₁) (par-rename{ρ = ρ} pβ‚‚)
... | G rewrite rename-subst-commute{Ξ“}{Ξ”}{Nβ€²}{Mβ€²}{ρ} = G

The proof is by induction on M ⇛ Mβ€². The first four cases are straightforward so we just consider the last one for pbeta.

  • Suppose (Ζ› N) Β· M ⇛ Nβ€² [ Mβ€² ] because N ⇛ Nβ€² and M ⇛ Mβ€². By the induction hypothesis, we have rename (ext ρ) N ⇛ rename (ext ρ) Nβ€² and rename ρ M ⇛ rename ρ Mβ€². So by pbeta we have (Ζ› rename (ext ρ) N) Β· (rename ρ M) ⇛ (rename (ext ρ) N) [ rename ρ M ]. However, to conclude we instead need parallel reduction to rename ρ (N [ M ]). But thankfully, renaming and substitution commute with one another.

With the par-rename lemma in hand, it is straightforward to show that extending substitutions preserves the pointwise parallel reduction relation.

par-subst-exts : βˆ€{Ξ“ Ξ”} {Οƒ Ο„ : Subst Ξ“ Ξ”}
  β†’ par-subst Οƒ Ο„
    ------------------------------------------
  β†’ βˆ€{B} β†’ par-subst (exts Οƒ {B = B}) (exts Ο„)
par-subst-exts s {x = Z} = pvar
par-subst-exts s {x = S x} = par-rename s

The next lemma that we need for proving that substitution respects parallel reduction is the following which states that simultaneoous substitution commutes with single substitution. We import this lemma from Chapter Substitution and restate it below.

subst-commute : βˆ€{Ξ“ Ξ”}{N : Ξ“ , β˜… ⊒ β˜…}{M : Ξ“ ⊒ β˜…}{Οƒ : Subst Ξ“ Ξ” }
  β†’ subst (exts Οƒ) N [ subst Οƒ M ] ≑ subst Οƒ (N [ M ])
subst-commute {N = N} = plfa.part2.Substitution.subst-commute {N = N}

We are ready to prove that substitution respects parallel reduction.

subst-par : βˆ€{Ξ“ Ξ” A} {Οƒ Ο„ : Subst Ξ“ Ξ”} {M Mβ€² : Ξ“ ⊒ A}
  β†’ par-subst Οƒ Ο„  β†’  M ⇛ Mβ€²
    --------------------------
  β†’ subst Οƒ M ⇛ subst Ο„ Mβ€²
subst-par {Ξ“} {Ξ”} {A} {Οƒ} {Ο„} {` x} s pvar = s
subst-par {Ξ“} {Ξ”} {A} {Οƒ} {Ο„} {Ζ› N} s (pabs p) =
  pabs (subst-par {Οƒ = exts Οƒ} {Ο„ = exts Ο„}
        (Ξ» {A}{x} β†’ par-subst-exts s {x = x}) p)
subst-par {Ξ“} {Ξ”} {β˜…} {Οƒ} {Ο„} {L Β· M} s (papp p₁ pβ‚‚) =
  papp (subst-par s p₁) (subst-par s pβ‚‚)
subst-par {Ξ“} {Ξ”} {β˜…} {Οƒ} {Ο„} {(Ζ› N) Β· M} s (pbeta{Nβ€² = Nβ€²}{Mβ€² = Mβ€²} p₁ pβ‚‚)
    with pbeta (subst-par{Οƒ = exts Οƒ}{Ο„ = exts Ο„}{M = N}
                        (Ξ»{A}{x} β†’ par-subst-exts s {x = x}) p₁)
               (subst-par {Οƒ = Οƒ} s pβ‚‚)
... | G rewrite subst-commute{N = Nβ€²}{M = Mβ€²}{Οƒ = Ο„} = G

We proceed by induction on M ⇛ Mβ€².

  • Suppose x ⇛ x. We conclude that Οƒ x ⇛ Ο„ x using the premise par-subst Οƒ Ο„.

  • Suppose Ζ› N ⇛ Ζ› Nβ€² because N ⇛ Nβ€². To use the induction hypothesis, we need par-subst (exts Οƒ) (exts Ο„), which we obtain by par-subst-exts. So we have subst (exts Οƒ) N ⇛ subst (exts Ο„) Nβ€² and conclude by rule pabs.

  • Suppose L Β· M ⇛ Lβ€² Β· Mβ€² because L ⇛ Lβ€² and M ⇛ Mβ€². By the induction hypothesis we have subst Οƒ L ⇛ subst Ο„ Lβ€² and subst Οƒ M ⇛ subst Ο„ Mβ€², so we conclude by rule papp.

  • Suppose (Ζ› N) Β· M ⇛ Nβ€² [ Mβ€² ] because N ⇛ Nβ€² and M ⇛ Mβ€². Again we obtain par-subst (exts Οƒ) (exts Ο„) by par-subst-exts. So by the induction hypothesis, we have subst (exts Οƒ) N ⇛ subst (exts Ο„) Nβ€² and subst Οƒ M ⇛ subst Ο„ Mβ€². Then by rule pbeta, we have parallel reduction to subst (exts Ο„) Nβ€² [ subst Ο„ Mβ€² ]. Substitution commutes with itself in the following sense. For any Οƒ, N, and M, we have

      (subst (exts Οƒ) N) [ subst Οƒ M ] ≑ subst Οƒ (N [ M ])
    

    So we have parallel reduction to subst Ο„ (Nβ€² [ Mβ€² ]).

Of course, if M ⇛ Mβ€², then subst-zero M pointwise parallel reduces to subst-zero Mβ€².

par-subst-zero : βˆ€{Ξ“}{A}{M Mβ€² : Ξ“ ⊒ A}
       β†’ M ⇛ Mβ€²
       β†’ par-subst (subst-zero M) (subst-zero Mβ€²)
par-subst-zero {M} {Mβ€²} p {A} {Z} = p
par-subst-zero {M} {Mβ€²} p {A} {S x} = pvar

We conclude this section with the desired corollary, that substitution respects parallel reduction.

sub-par : βˆ€{Ξ“ A B} {N Nβ€² : Ξ“ , A ⊒ B} {M Mβ€² : Ξ“ ⊒ A}
  β†’ N ⇛ Nβ€²
  β†’ M ⇛ Mβ€²
    --------------------------
  β†’ N [ M ] ⇛ Nβ€² [ Mβ€² ]
sub-par pn pm = subst-par (par-subst-zero pm) pn

Parallel reduction satisfies the diamond property

The heart of the confluence proof is made of stone, or rather, of diamond! We show that parallel reduction satisfies the diamond property: that if M ⇛ N and M ⇛ Nβ€², then N ⇛ L and Nβ€² ⇛ L for some L. The proof is relatively easy; it is parallel reduction’s raison d’etre.

par-diamond : βˆ€{Ξ“ A} {M N Nβ€² : Ξ“ ⊒ A}
  β†’ M ⇛ N
  β†’ M ⇛ Nβ€²
    ---------------------------------
  β†’ Ξ£[ L ∈ Ξ“ ⊒ A ] (N ⇛ L) Γ— (Nβ€² ⇛ L)
par-diamond (pvar{x = x}) pvar = ⟨ ` x , ⟨ pvar , pvar ⟩ ⟩
par-diamond (pabs p1) (pabs p2)
    with par-diamond p1 p2
... | ⟨ Lβ€² , ⟨ p3 , p4 ⟩ ⟩ =
      ⟨ Ζ› Lβ€² , ⟨ pabs p3 , pabs p4 ⟩ ⟩
par-diamond{Ξ“}{A}{L Β· M}{N}{Nβ€²} (papp{Ξ“}{L}{L₁}{M}{M₁} p1 p3)
                                (papp{Ξ“}{L}{Lβ‚‚}{M}{Mβ‚‚} p2 p4)
    with par-diamond p1 p2
... | ⟨ L₃ , ⟨ p5 , p6 ⟩ ⟩
      with par-diamond p3 p4
...   | ⟨ M₃ , ⟨ p7 , p8 ⟩ ⟩ =
        ⟨ (L₃ Β· M₃) , ⟨ (papp p5 p7) , (papp p6 p8) ⟩ ⟩
par-diamond (papp (pabs p1) p3) (pbeta p2 p4)
    with par-diamond p1 p2
... | ⟨ N₃ , ⟨ p5 , p6 ⟩ ⟩
      with par-diamond p3 p4
...   | ⟨ M₃ , ⟨ p7 , p8 ⟩ ⟩ =
        ⟨ N₃ [ M₃ ] , ⟨ pbeta p5 p7 , sub-par p6 p8 ⟩ ⟩
par-diamond (pbeta p1 p3) (papp (pabs p2) p4)
    with par-diamond p1 p2
... | ⟨ N₃ , ⟨ p5 , p6 ⟩ ⟩
      with par-diamond p3 p4
...   | ⟨ M₃ , ⟨ p7 , p8 ⟩ ⟩ =
        ⟨ (N₃ [ M₃ ]) , ⟨ sub-par p5  p7 , pbeta p6 p8 ⟩ ⟩
par-diamond {Ξ“}{A} (pbeta p1 p3) (pbeta p2 p4)
    with par-diamond p1 p2
... | ⟨ N₃ , ⟨ p5 , p6 ⟩ ⟩
      with par-diamond p3 p4
...   | ⟨ M₃ , ⟨ p7 , p8 ⟩ ⟩ =
        ⟨ N₃ [ M₃ ] , ⟨ sub-par p5 p7 , sub-par p6 p8 ⟩ ⟩

The proof is by induction on both premises.

  • Suppose x ⇛ x and x ⇛ x. We choose L = x and immediately have x ⇛ x and x ⇛ x.

  • Suppose Ζ› N ⇛ Ζ› N₁ and Ζ› N ⇛ Ζ› Nβ‚‚. By the induction hypothesis, there exists Lβ€² such that N₁ ⇛ Lβ€² and Nβ‚‚ ⇛ Lβ€². We choose L = Ζ› Lβ€² and by pabs conclude that Ζ› N₁ ⇛ Ζ› Lβ€² and `Ζ› Nβ‚‚ ⇛ Ζ› Lβ€².

  • Suppose that L Β· M ⇛ L₁ Β· M₁ and L Β· M ⇛ Lβ‚‚ Β· Mβ‚‚. By the induction hypothesis we have L₁ ⇛ L₃ and Lβ‚‚ ⇛ L₃ for some L₃. Likewise, we have M₁ ⇛ M₃ and Mβ‚‚ ⇛ M₃ for some M₃. We choose L = L₃ Β· M₃ and conclude with two uses of papp.

  • Suppose that (Ζ› N) Β· M ⇛ (Ζ› N₁) Β· M₁ and (Ζ› N) Β· M ⇛ Nβ‚‚ [ Mβ‚‚ ] By the induction hypothesis we have N₁ ⇛ N₃ and Nβ‚‚ ⇛ N₃ for some N₃. Likewise, we have M₁ ⇛ M₃ and Mβ‚‚ ⇛ M₃ for some M₃. We choose L = N₃ [ M₃ ]. We have (Ζ› N₁) Β· M₁ ⇛ N₃ [ M₃ ] by rule pbeta and conclude that Nβ‚‚ [ Mβ‚‚ ] ⇛ N₃ [ M₃ ] because substitution respects parallel reduction.

  • Suppose that (Ζ› N) Β· M ⇛ N₁ [ M₁ ] and (Ζ› N) Β· M ⇛ (Ζ› Nβ‚‚) Β· Mβ‚‚. The proof of this case is the mirror image of the last one.

  • Suppose that (Ζ› N) Β· M ⇛ N₁ [ M₁ ] and (Ζ› N) Β· M ⇛ Nβ‚‚ [ Mβ‚‚ ]. By the induction hypothesis we have N₁ ⇛ N₃ and Nβ‚‚ ⇛ N₃ for some N₃. Likewise, we have M₁ ⇛ M₃ and Mβ‚‚ ⇛ M₃ for some M₃. We choose L = N₃ [ M₃ ]. We have both (Ζ› N₁) Β· M₁ ⇛ N₃ [ M₃ ] and (Ζ› Nβ‚‚) Β· Mβ‚‚ ⇛ N₃ [ M₃ ] by rule pbeta

Exercise (practice)

Draw pictures that represent the proofs of each of the six cases in the above proof of par-diamond. The pictures should consist of nodes and directed edges, where each node is labeled with a term and each edge represents parallel reduction.

Proof of confluence for parallel reduction

As promised at the beginning, the proof that parallel reduction is confluent is easy now that we know it satisfies the diamond property. We just need to prove the strip lemma, which states that if M ⇛ N and M ⇛* Nβ€², then N ⇛* L and Nβ€² ⇛ L for some L. The following diagram illustrates the strip lemma

    M
   / \
  1   *
 /     \
N       Nβ€²
 \     /
  *   1
   \ /
    L

where downward lines are instances of ⇛ or ⇛*, depending on how they are marked.

The proof of the strip lemma is a straightforward induction on M ⇛* Nβ€², using the diamond property in the induction step.

strip : βˆ€{Ξ“ A} {M N Nβ€² : Ξ“ ⊒ A}
  β†’ M ⇛ N
  β†’ M ⇛* Nβ€²
    ------------------------------------
  β†’ Ξ£[ L ∈ Ξ“ ⊒ A ] (N ⇛* L)  Γ—  (Nβ€² ⇛ L)
strip{Ξ“}{A}{M}{N}{Nβ€²} mn (M ∎) = ⟨ N , ⟨ N ∎ , mn ⟩ ⟩
strip{Ξ“}{A}{M}{N}{Nβ€²} mn (M β‡›βŸ¨ mm' ⟩ m'n')
    with par-diamond mn mm'
... | ⟨ L , ⟨ nl , m'l ⟩ ⟩
      with strip m'l m'n'
...   | ⟨ Lβ€² , ⟨ ll' , n'l' ⟩ ⟩ =
        ⟨ Lβ€² , ⟨ (N β‡›βŸ¨ nl ⟩ ll') , n'l' ⟩ ⟩

The proof of confluence for parallel reduction is now proved by induction on the sequence M ⇛* N, using the above lemma in the induction step.

par-confluence : βˆ€{Ξ“ A} {L M₁ Mβ‚‚ : Ξ“ ⊒ A}
  β†’ L ⇛* M₁
  β†’ L ⇛* Mβ‚‚
    ------------------------------------
  β†’ Ξ£[ N ∈ Ξ“ ⊒ A ] (M₁ ⇛* N) Γ— (Mβ‚‚ ⇛* N)
par-confluence {Ξ“}{A}{L}{.L}{N} (L ∎) L⇛*N = ⟨ N , ⟨ L⇛*N , N ∎ ⟩ ⟩
par-confluence {Ξ“}{A}{L}{M₁′}{Mβ‚‚} (L β‡›βŸ¨ L⇛M₁ ⟩ M₁⇛*M₁′) L⇛*Mβ‚‚
    with strip L⇛M₁ L⇛*Mβ‚‚
... | ⟨ N , ⟨ M₁⇛*N , M₂⇛N ⟩ ⟩
      with par-confluence M₁⇛*M₁′ M₁⇛*N
...   | ⟨ Nβ€² , ⟨ M₁′⇛*Nβ€² , N⇛*Nβ€² ⟩ ⟩ =
        ⟨ Nβ€² , ⟨ M₁′⇛*Nβ€² , (Mβ‚‚ β‡›βŸ¨ M₂⇛N ⟩ N⇛*Nβ€²) ⟩ ⟩

The step case may be illustrated as follows:

        L
       / \
      1   *
     /     \
    M₁ (a)  Mβ‚‚
   / \     /
  *   *   1
 /     \ /
M₁′(b)  N
 \     /
  *   *
   \ /
    Nβ€²

where downward lines are instances of ⇛ or ⇛*, depending on how they are marked. Here (a) holds by strip and (b) holds by induction.

Proof of confluence for reduction

Confluence of reduction is a corollary of confluence for parallel reduction. From L β€”β†  M₁ and L β€”β†  Mβ‚‚ we have L ⇛* M₁ and L ⇛* Mβ‚‚ by betas-pars. Then by confluence we obtain some L such that M₁ ⇛* N and Mβ‚‚ ⇛* N, from which we conclude that M₁ β€”β†  N and Mβ‚‚ β€”β†  N by pars-betas.

confluence : βˆ€{Ξ“ A} {L M₁ Mβ‚‚ : Ξ“ ⊒ A}
  β†’ L β€”β†  M₁
  β†’ L β€”β†  Mβ‚‚
    -----------------------------------
  β†’ Ξ£[ N ∈ Ξ“ ⊒ A ] (M₁ β€”β†  N) Γ— (Mβ‚‚ β€”β†  N)
confluence Lβ† M₁ Lβ† Mβ‚‚
    with par-confluence (betas-pars Lβ† M₁) (betas-pars Lβ† Mβ‚‚)
... | ⟨ N , ⟨ M₁⇛N , M₂⇛N ⟩ ⟩ =
      ⟨ N , ⟨ pars-betas M₁⇛N , pars-betas M₂⇛N ⟩ ⟩

Notes

Broadly speaking, this proof of confluence, based on parallel reduction, is due to W. Tait and P. Martin-Lof (see Barendredgt 1984, Section 3.2). Details of the mechanization come from several sources. The subst-par lemma is the β€œstrong substitutivity” lemma of Shafer, Tebbi, and Smolka (ITP 2015). The proofs of par-diamond, strip, and par-confluence are based on Pfenning’s 1992 technical report about the Church-Rosser theorem. In addition, we consulted Nipkow and Berghofer’s mechanization in Isabelle, which is based on an earlier article by Nipkow (JAR 1996). We opted not to use the β€œcomplete developments” approach of Takahashi (1995) because we felt that the proof was simple enough based solely on parallel reduction. There are many more mechanizations of the Church-Rosser theorem that we have not yet had the time to read, including Shankar’s (J. ACM 1988) and Homeier’s (TPHOLs 2001).

Unicode

This chapter uses the following unicode:

⇛  U+3015  RIGHTWARDS TRIPLE ARROW (\r== or \Rrightarrow)