Skip to content

Commit cd4b371

Browse files
committed
fix: notation typeclass for substitution
1 parent 1d867fb commit cd4b371

4 files changed

Lines changed: 44 additions & 64 deletions

File tree

Cslib/Languages/LambdaCalculus/Unscoped/Untyped/BetaReduction.lean

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public import Cslib.Languages.LambdaCalculus.Unscoped.Untyped.DeBruijnSyntax
99
public import Cslib.Foundations.Data.Relation
1010

1111
/-!
12-
# One-step β-reduction and its reflexive-transitive closure
12+
# One-step β-reduction and its reflexive-transitive closure (Star)
1313
1414
This file defines the usual compatible one-step β-reduction on de Bruijn lambda terms.
1515
It also introduces its reflexive-transitive closure and proves basic closure lemmas for
@@ -18,25 +18,20 @@ application and abstraction.
1818
## Main definitions
1919
2020
* `Lambda.Beta`: one-step β-reduction.
21-
* `Lambda.BetaStar`: the reflexive-transitive closure of `Beta`.
2221
2322
## Main lemmas
2423
2524
Inside `namespace BetaStar` we provide the standard constructors and congruence lemmas:
2625
27-
* `BetaStar.refl`
28-
* `BetaStar.head`
29-
* `BetaStar.tail`
30-
* `BetaStar.trans`
31-
* `BetaStar.appL`, `BetaStar.appR`, `BetaStar.app`
32-
* `BetaStar.abs`
26+
* `BetaStar.appL`, `BetaStar.appR`, `BetaStar.app`, `BetaStar.abs`
3327
3428
These lemmas are used later to compare β-reduction with parallel reduction.
3529
-/
3630

3731

3832
namespace Lambda
3933
open Term
34+
open Relation.ReflTransGen
4035

4136
/-- One-step β-reduction (compatible closure). -/
4237
@[reduction_sys "β"]
@@ -45,51 +40,33 @@ public inductive Beta : Term → Term → Prop
4540
| appL {t t' u} : Beta t t' → Beta (t·u) (t'·u)
4641
| appR {t u u'} : Beta u u' → Beta (t·u) (t·u')
4742
| red (t' s : Term) : Beta ((λ.t')·s) (t'.sub 0 s)
48-
public abbrev BetaStar := Relation.ReflTransGen Beta
4943

5044
namespace BetaStar
5145

52-
public theorem refl (t : Term) : BetaStar t t :=
53-
Relation.ReflTransGen.refl
54-
55-
public theorem head {a b c} (hab : Beta a b) (hbc : BetaStar b c) :
56-
BetaStar a c :=
57-
Relation.ReflTransGen.head hab hbc
58-
59-
public theorem tail {a b c} (hab : BetaStar a b) (hbc : Beta b c) :
60-
BetaStar a c :=
61-
Relation.ReflTransGen.tail hab hbc
62-
63-
public theorem trans {a b c}
64-
(hab : BetaStar a b) (hbc : BetaStar b c) :
65-
BetaStar a c :=
66-
Relation.ReflTransGen.trans hab hbc
67-
68-
public theorem appL {t t' u : Term} (h : BetaStar t t') :
69-
BetaStar (t·u) (t'·u) := by
46+
public theorem appL {t t' u : Term} (h : t ↠β t') :
47+
(t·u) ↠β (t'·u) := by
7048
induction h with
71-
| refl => exact BetaStar.refl (t·u)
72-
| tail hab hbc ih => exact BetaStar.tail ih (Beta.appL hbc)
49+
| refl => exact refl (t·u)
50+
| tail hab hbc ih => exact tail ih (Beta.appL hbc)
7351

74-
public theorem appR {t u u' : Term} (h : BetaStar u u') :
75-
BetaStar (t·u) (t·u') := by
52+
public theorem appR {t u u' : Term} (h : u ↠β u') :
53+
(t·u) ↠β (t·u') := by
7654
induction h with
77-
| refl => exact BetaStar.refl (t·u)
78-
| tail hab hbc ih => exact BetaStar.tail ih (Beta.appR hbc)
55+
| refl => exact refl (t·u)
56+
| tail hab hbc ih => exact tail ih (Beta.appR hbc)
7957

8058
public theorem app {t t' u u'}
81-
(ht : BetaStar t t')
82-
(hu : BetaStar u u') :
83-
BetaStar (t·u) (t'·u') := by
59+
(ht : t ↠β t') (hu : u ↠β u') :
60+
(t·u) ↠β (t'·u') := by
8461
induction ht with
85-
| refl => exact BetaStar.appR hu
86-
| tail hab hbc ih => exact BetaStar.tail ih (Beta.appL hbc)
62+
| refl => exact appR hu
63+
| tail hab hbc ih => exact tail ih (Beta.appL hbc)
8764

88-
public theorem abs {t t' : Term} (h : BetaStar t t') :
89-
BetaStar (λ.t) (λ.t') := by
65+
public theorem abs {t t' : Term} (h : t ↠β t') :
66+
(λ.t) ↠β (λ.t') := by
9067
induction h with
91-
| refl => exact BetaStar.refl (λ.t)
92-
| tail hab hbc ih => exact BetaStar.tail ih (Beta.abs hbc)
68+
| refl => exact refl (λ.t)
69+
| tail hab hbc ih => exact tail ih (Beta.abs hbc)
9370

9471
end BetaStar
9572
end Lambda

Cslib/Languages/LambdaCalculus/Unscoped/Untyped/ChurchRosser.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public theorem churchRosser_beta : Confluent Beta := by
4444
have hPar : Confluent Par :=
4545
Diamond.toConfluent (r := Par) diamond_par
4646
-- Identify BetaStar and ParStar via sandwich
47-
have hEq {a b : Term} : BetaStar a b ↔ ParStar a b :=
47+
have hEq {a b : Term} : a ↠β b ↔ a ↠∥ b :=
4848
ReflTransGen.sandwich_to_eq (r := Beta) (p := Par)
4949
(by intro a b h; exact beta_subset_par h)
5050
(by intro a b h; exact par_subset_betaStar h)
5151
-- Transport confluence
5252
intro a b c hab hac
53-
have hab' : ParStar a b := (hEq).1 hab
54-
have hac' : ParStar a c := (hEq).1 hac
53+
have hab' : a ↠∥ b := (hEq).1 hab
54+
have hac' : a ↠∥ c := (hEq).1 hac
5555
rcases hPar hab' hac' with ⟨d, hbd, hcd⟩
5656
exact ⟨d, (hEq).2 hbd, (hEq).2 hcd⟩
5757

Cslib/Languages/LambdaCalculus/Unscoped/Untyped/DeBruijnSyntax.lean

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ infixl:77 "·" => Term.app
8080
| app t u => app (decre i l t) (decre i l u)
8181

8282
/-- Substitute into the body of a lambda: `(λ.t) s` -/
83-
@[expose] public def sub (t : Term) (n : Nat) (s : Term) := decre 1 n (subst n (incre 1 n s) t)
83+
@[expose] public def sub (t : Term) (n : Nat) (s : Term) :=
84+
decre 1 n (subst n (incre 1 n s) t)
8485

85-
@[expose] public instance :
86-
Cslib.HasSubstitution Term Nat Term where
87-
subst t n s := t.sub n s
86+
/-- Notation typeclass for substitution, t[n := s] ≃ t.sub n s
87+
which substitute nth variable in t with s. -/
88+
@[expose] public instance : Cslib.HasSubstitution Term Nat Term
89+
where subst := sub
8890

8991
/-- Increment of 0 is identity -/
9092
@[simp] public theorem incre_rfl {l t} : incre 0 l t = t := by
@@ -95,7 +97,8 @@ infixl:77 "·" => Term.app
9597

9698
/-- Decrement of increment with same bound is the same.
9799
Lemma for `var_sub` -/
98-
@[simp] public theorem decre_incre_elim {l t} : decre 1 l (incre 1 l t) = t := by
100+
@[simp] public theorem decre_incre_elim {l t} :
101+
decre 1 l (incre 1 l t) = t := by
99102
induction t generalizing l with
100103
| var k =>
101104
unfold decre incre

Cslib/Languages/LambdaCalculus/Unscoped/Untyped/ParallelReduction.lean

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,35 @@ public inductive Par : Term → Term → Prop
5151
public abbrev ParStar := Relation.ReflTransGen Par
5252

5353
/-- reflexivity of Par. -/
54-
@[simp] public theorem par_refl {t} : Par t t := by
54+
@[simp] public theorem par_refl {t} : t ⭢∥ t := by
5555
induction t with
5656
| var n => exact Par.var n
5757
| app t u iht ihu => exact Par.app iht ihu
5858
| abs t iht => exact Par.abs iht
5959

6060
/-- `Beta ⊆ Par`. -/
61-
public theorem beta_subset_par {a b} (h : Beta a b) : Par a b := by
61+
public theorem beta_subset_par {a b} (h : a ⭢β b) : a ⭢∥ b := by
6262
induction h with
6363
| appL h ih => exact Par.app ih par_refl
6464
| appR h ih => exact Par.app par_refl ih
6565
| abs h ih => exact Par.abs ih
6666
| red t s => exact Par.red par_refl par_refl
6767

6868
/-- Simulation lemma: `Par ⊆ BetaStar`. -/
69-
public theorem par_subset_betaStar {a b} (h : Par a b) :
70-
BetaStar a b := by
69+
public theorem par_subset_betaStar {a b} (h : a ⭢∥ b) :
70+
a ↠β b := by
7171
induction h with
72-
| var n => exact BetaStar.refl (𝕧 n)
72+
| var n => exact refl (𝕧 n)
7373
| app hpt hpu hbt hbu =>
74-
exact BetaStar.trans
74+
exact .trans
7575
(BetaStar.appL hbt) (BetaStar.appR hbu)
7676
| abs h ht => exact BetaStar.abs ht
7777
| red ht hs iht ihs =>
78-
exact BetaStar.trans (BetaStar.appL (BetaStar.abs iht))
79-
(BetaStar.tail (BetaStar.appR ihs) (Beta.red _ _))
78+
exact .trans (BetaStar.appL (BetaStar.abs iht))
79+
(.tail (BetaStar.appR ihs) (Beta.red _ _))
8080

81-
@[simp] public theorem incre_par {a b i l} (h : Par a b) :
82-
Par (incre i l a) (incre i l b) := by
81+
@[simp] public theorem incre_par {a b i l} (h : a ⭢∥ b) :
82+
(incre i l a) ⭢∥ (incre i l b) := by
8383
induction h generalizing l with
8484
| var n => exact par_refl
8585
| abs ht ih => exact Par.abs ih
@@ -95,9 +95,9 @@ public theorem par_subset_betaStar {a b} (h : Par a b) :
9595
exact Par.red iht ihs
9696

9797
/-- Substitution lemma for `par_to_dev`. -/
98-
private lemma par_subst {t t' u u'} (ht : Par t t') (hu : Par u u')
98+
private lemma par_subst {t t' u u'} (ht : t ⭢∥ t') (hu : u ⭢∥ u')
9999
(k : Nat) (n : Nat) :
100-
Par (t.sub n (incre k 0 u)) (t'.sub n (incre k 0 u')) := by
100+
(t.sub n (incre k 0 u)) ⭢∥ (t'.sub n (incre k 0 u')) := by
101101
match t, t' with
102102
| var t, var t' => match ht with
103103
| Par.var t => cases em (t = n) with
@@ -146,7 +146,7 @@ public def Term.dev : Term → Term
146146
| t·u => t.dev·u.dev
147147

148148
/-- t.dev is a par reduction for t. -/
149-
public theorem par_dev (t : Term) : Par t t.dev :=
149+
public theorem par_dev (t : Term) : t ⭢∥ t.dev :=
150150
match t with
151151
| 𝕧 n => Par.var n
152152
| λ.t => Par.abs (par_dev t)
@@ -157,7 +157,7 @@ public theorem par_dev (t : Term) : Par t t.dev :=
157157
| app t₁ t₂ => Par.app (par_dev (t₁·t₂)) (par_dev u)
158158

159159
/-- t.dev is max par reduction for t. -/
160-
public theorem par_to_dev {t u} (h : Par t u) : Par u (t.dev) := by
160+
public theorem par_to_dev {t u} (h : t ⭢∥ u) : u ⭢∥ (t.dev) := by
161161
match t, u with
162162
| var t', var u' =>
163163
match h with | Par.var t' => exact Par.var t'

0 commit comments

Comments
 (0)