Skip to content

Commit 437d801

Browse files
committed
upd: \@\[expose\] public section
1 parent 1b9eba8 commit 437d801

4 files changed

Lines changed: 44 additions & 33 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,45 +28,49 @@ Inside `namespace BetaStar` we provide the standard constructors and congruence
2828
These lemmas are used later to compare β-reduction with parallel reduction.
2929
-/
3030

31+
@[expose] public section
3132

3233
namespace Cslib.LambdaCalculus.Unscoped.Untyped
34+
3335
open Term
36+
3437
open Relation.ReflTransGen
3538

3639
/-- One-step β-reduction (compatible closure). -/
3740
@[reduction_sys "β"]
38-
public inductive Beta : Term → Term → Prop
41+
inductive Beta : Term → Term → Prop
3942
| abs {t t'} : Beta t t' → Beta (abs t) (abs t')
4043
| appL {t t' u} : Beta t t' → Beta (app t u) (app t' u)
4144
| appR {t u u'} : Beta u u' → Beta (app t u) (app t u')
4245
| red (t' s : Term) : Beta (app (abs t') s) (t'.sub 0 s)
4346

4447
namespace BetaStar
4548

46-
public theorem appL {t t' u : Term} (h : t ↠β t') :
49+
theorem appL {t t' u : Term} (h : t ↠β t') :
4750
(app t u) ↠β (app t' u) := by
4851
induction h with
4952
| refl => exact refl (app t u)
5053
| tail hab hbc ih => exact tail ih (Beta.appL hbc)
5154

52-
public theorem appR {t u u' : Term} (h : u ↠β u') :
55+
theorem appR {t u u' : Term} (h : u ↠β u') :
5356
(app t u) ↠β (app t u') := by
5457
induction h with
5558
| refl => exact refl (app t u)
5659
| tail hab hbc ih => exact tail ih (Beta.appR hbc)
5760

58-
public theorem app {t t' u u'}
61+
theorem app {t t' u u'}
5962
(ht : t ↠β t') (hu : u ↠β u') :
6063
(app t u) ↠β (app t' u') := by
6164
induction ht with
6265
| refl => exact appR hu
6366
| tail hab hbc ih => exact tail ih (Beta.appL hbc)
6467

65-
public theorem abs {t t' : Term} (h : t ↠β t') :
68+
theorem abs {t t' : Term} (h : t ↠β t') :
6669
(abs t) ↠β (abs t') := by
6770
induction h with
6871
| refl => exact refl
6972
| tail hab hbc ih => exact tail ih (Beta.abs hbc)
7073

7174
end BetaStar
75+
7276
end Cslib.LambdaCalculus.Unscoped.Untyped

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ The proof relies on the generic rewriting lemmas from `ConfluentReduction` toget
3030
the complete-development machinery from `ParallelReduction`.
3131
-/
3232

33+
@[expose] public section
34+
3335
namespace Cslib.LambdaCalculus.Unscoped.Untyped
36+
3437
open Relation
3538

3639
/-- Parallel Reduction is Diamond. -/
@@ -39,7 +42,7 @@ private lemma diamond_par : Diamond Par := by
3942
exact ⟨a.dev, par_to_dev hab, par_to_dev hac⟩
4043

4144
/-- Church–Rosser: β is confluent (on RTC). -/
42-
public theorem churchRosser_beta : Confluent Beta := by
45+
theorem churchRosser_beta : Confluent Beta := by
4346
-- Confluence of Par from diamond
4447
have hPar : Confluent Par :=
4548
Diamond.toConfluent (r := Par) diamond_par

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ parallel reduction, and the Church–Rosser theorem.
4040
* <https://en.wikipedia.org/wiki/De_Bruijn_index>
4141
-/
4242

43+
@[expose] public section
4344

4445
namespace Cslib.LambdaCalculus.Unscoped.Untyped
4546

@@ -52,7 +53,7 @@ Constructors:
5253
* `abs t`: abstraction
5354
* `app t u`: application (apply `u` to `t`)
5455
-/
55-
public inductive Term : Type where
56+
inductive Term : Type where
5657
| var : Nat → Term
5758
| abs : Term → Term
5859
| app : Term → Term → Term
@@ -61,13 +62,13 @@ deriving DecidableEq, Repr
6162
namespace Term
6263

6364
/-- `incre i l t` increments `i` for all free vars `≥ l`. -/
64-
@[expose] public def incre (i : Nat) (l : Nat) : Term → Term
65+
def incre (i : Nat) (l : Nat) : Term → Term
6566
| var k => if l ≤ k then var (k + i) else var k
6667
| abs t => abs (incre i (l + 1) t)
6768
| app t u => app (incre i l t) (incre i l u)
6869

6970
/-- `subst j s t` substitutes `j` with term `s` in `t`. -/
70-
@[expose] public def subst (j : Nat) (s : Term) : Term → Term
71+
def subst (j : Nat) (s : Term) : Term → Term
7172
| var k => if k = j then s else var k
7273
| abs t => abs (subst (j + 1) (incre 1 0 s) t)
7374
| app t u => app (subst j s t) (subst j s u)
@@ -77,30 +78,30 @@ namespace Term
7778
free variable elimination. For example, after eliminating
7879
`var k` for Term `t` from the most outside, `decre 1 k t`
7980
will close the gap caused by `k` elimination. -/
80-
@[expose] public def decre (i : Nat) (l : Nat) : Term → Term
81+
def decre (i : Nat) (l : Nat) : Term → Term
8182
| var k => if l + i ≤ k then var (k - i) else var k
8283
| abs t => abs (decre i (l + 1) t)
8384
| app t u => app (decre i l t) (decre i l u)
8485

8586
/-- Substitute into the body of a lambda: `(abs t) s` -/
86-
@[expose] public def sub (t : Term) (n : Nat) (s : Term) : Term :=
87+
def sub (t : Term) (n : Nat) (s : Term) : Term :=
8788
decre 1 n (subst n (incre 1 n s) t)
8889

8990
/-- Notation typeclass for substitution, t[n := s] ≃ t.sub n s
9091
which substitute nth variable in t with s. -/
91-
@[expose] public instance : Cslib.HasSubstitution Term Nat Term
92+
instance : Cslib.HasSubstitution Term Nat Term
9293
where subst := sub
9394

9495
/-- Increment of 0 is identity -/
95-
@[simp] public theorem incre_rfl {l t} : incre 0 l t = t := by
96+
@[simp] theorem incre_rfl {l t} : incre 0 l t = t := by
9697
induction t generalizing l with
9798
| var k => simp_all only [incre, Nat.add_zero, ite_self]
9899
| abs t ih => simp_all only [incre]
99100
| app t u iht ihu => simp_all only [incre]
100101

101102
/-- Decrement of increment with same bound is the same.
102103
Lemma for `var_sub` -/
103-
@[simp] public theorem decre_incre_elim {l t} :
104+
@[simp] theorem decre_incre_elim {l t} :
104105
decre 1 l (incre 1 l t) = t := by
105106
induction t generalizing l with
106107
| var k =>
@@ -115,18 +116,18 @@ Lemma for `var_sub` -/
115116
| app t u iht ihu => simp_all only [incre, decre]
116117

117118
/-- Substitution of var n. -/
118-
@[simp] public theorem var_sub_elim {n s} : ((var n).sub) n s = s := by
119+
@[simp] theorem var_sub_elim {n s} : ((var n).sub) n s = s := by
119120
simp_all only [sub, subst, ↓reduceIte, decre_incre_elim]
120121

121122
/-- Vacuously Substitution of var k to var k. -/
122-
@[simp] public theorem var_lt_sub {k n s} (hk : k < n) :
123+
@[simp] theorem var_lt_sub {k n s} (hk : k < n) :
123124
((var k).sub) n s = var k := by
124125
have : ¬(n + 1 ≤ k) := by omega
125126
simp_all only [sub, subst, Nat.ne_of_lt hk,
126127
↓reduceIte, decre]
127128

128129
/-- Vacuously Substitution of var k to var k - 1. -/
129-
@[simp] public theorem var_gt_sub {k n s} (hk : k > n) :
130+
@[simp] theorem var_gt_sub {k n s} (hk : k > n) :
130131
((var k).sub) n s = var (k - 1) := by
131132
have : n + 1 ≤ k := by omega
132133
simp_all only [gt_iff_lt, sub, subst,
@@ -135,7 +136,7 @@ Lemma for `var_sub` -/
135136
/-- Increments elimination for same lower bound.
136137
Special thanks to professor Radziwill @maksym-radziwill about
137138
his idea of generalizing proper variable. -/
138-
@[simp] public theorem incre_same_bound_elim {i j n t} :
139+
@[simp] theorem incre_same_bound_elim {i j n t} :
139140
(incre i n (incre j n t)) = (incre (i + j) n t) := by
140141
induction t generalizing i n with
141142
| var k =>
@@ -149,7 +150,7 @@ his idea of generalizing proper variable. -/
149150
| app t₁ t₂ ih₁ ih₂ => simp_all only [incre]
150151

151152
/-- Communitivity of incre. -/
152-
public theorem incre_comm {i j k l t} :
153+
theorem incre_comm {i j k l t} :
153154
(incre j (k + l + i) (incre i l t))=
154155
(incre i l (incre j (k + l) t)) := by
155156
induction t generalizing l with
@@ -181,13 +182,13 @@ public theorem incre_comm {i j k l t} :
181182
simp_all only [Nat.add_comm, incre, Nat.add_assoc]
182183
| app t₁ t₂ ih₁ ih₂ => simp_all only [incre]
183184

184-
public theorem incre_comm_zero {n s} :
185+
theorem incre_comm_zero {n s} :
185186
incre 1 (n + 1) (incre 1 0 s) =
186187
incre 1 0 (incre 1 n s) := by
187188
simpa only [Nat.add_zero]
188189
using (incre_comm (i := 1) (l := 0) (j := 1) (k := n) (t := s))
189190

190-
@[simp] public theorem abs_sub_zero {t n s} :
191+
@[simp] theorem abs_sub_zero {t n s} :
191192
((abs t).sub n s) = abs (t.sub (n + 1) (incre 1 0 s)) := by
192193
simp_all only [sub, subst, decre, incre_comm_zero]
193194

@@ -229,7 +230,7 @@ private lemma incre_sub_var {i l n k s} :
229230
exact (this h).elim
230231

231232
/-- The communitivity between sub and incre for free var. -/
232-
@[simp] public theorem incre_sub {i l n t s} :
233+
@[simp] theorem incre_sub {i l n t s} :
233234
((incre i (l + n + 1) t).sub n (incre i (l + n) s)) =
234235
(incre i (l + n) (t.sub n s)) := by
235236
induction t generalizing l n s with
@@ -259,7 +260,7 @@ private lemma sub_incre_same {u r m} :
259260
((incre 1 m u).sub m r) = u := by
260261
simp_all only [sub, subst_zero_incre, decre_incre_elim]
261262

262-
@[simp] public theorem sub_lift_zero {i t n u} :
263+
@[simp] theorem sub_lift_zero {i t n u} :
263264
((incre 1 i t).sub (n + i + 1) (incre 1 i u)) =
264265
incre 1 i (t.sub (n + i) u) := by
265266
induction t generalizing n u i with
@@ -350,7 +351,7 @@ private lemma sub_comm_var {k n m u s} :
350351
have nh : ¬(n + m < k) := by omega
351352
exact (nh h).elim
352353

353-
public theorem sub_comm {t : Term} {n m s u} :
354+
theorem sub_comm {t : Term} {n m s u} :
354355
((t.sub ((n + m) + 1) (incre 1 m u)).sub m (s.sub (n + m) u))
355356
= ((t.sub m s).sub (n + m) u) := by
356357
induction t generalizing n m s u with
@@ -369,7 +370,7 @@ public theorem sub_comm {t : Term} {n m s u} :
369370
(m := m + 1) (u := incre 1 0 u) (s := incre 1 0 s))
370371
| app t₁ t₂ ih₁ ih₂ => simp_all only [sub, subst, decre]
371372

372-
public theorem sub_sub_incre {t : Term} {n k u s} :
373+
theorem sub_sub_incre {t : Term} {n k u s} :
373374
((t.sub (n + 1) (incre (1 + k) 0 u)).sub 0 (s.sub n (incre k 0 u)))
374375
= ((t.sub 0 s).sub n (incre k 0 u)) := by
375376
have h' :

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ parallel reduct further reduces in parallel to this complete development.
3737
These results provide the diamond argument used in the final Church–Rosser proof.
3838
-/
3939

40+
@[expose] public section
41+
4042
namespace Cslib.LambdaCalculus.Unscoped.Untyped
43+
4144
open Term
4245

4346
/-- Parallel β-reduction (syntax-directed). -/
4447
@[reduction_sys "∥"]
45-
public inductive Par : Term → Term → Prop
48+
inductive Par : Term → Term → Prop
4649
| var (n) : Par (var n) (var n)
4750
| abs {t t'} : Par t t' → Par (abs t) (abs t')
4851
| app {t t' u u'} : Par t t' → Par u u' →
@@ -52,22 +55,22 @@ public inductive Par : Term → Term → Prop
5255
public abbrev ParStar := Relation.ReflTransGen Par
5356

5457
/-- reflexivity of Par. -/
55-
@[simp] public theorem par_refl {t} : t ⭢∥ t := by
58+
@[simp] theorem par_refl {t} : t ⭢∥ t := by
5659
induction t with
5760
| var n => exact Par.var n
5861
| app t u iht ihu => exact Par.app iht ihu
5962
| abs t iht => exact Par.abs iht
6063

6164
/-- `Beta ⊆ Par`. -/
62-
public theorem beta_subset_par {a b} (h : a ⭢β b) : a ⭢∥ b := by
65+
theorem beta_subset_par {a b} (h : a ⭢β b) : a ⭢∥ b := by
6366
induction h with
6467
| appL h ih => exact Par.app ih par_refl
6568
| appR h ih => exact Par.app par_refl ih
6669
| abs h ih => exact Par.abs ih
6770
| red t s => exact Par.red par_refl par_refl
6871

6972
/-- Simulation lemma: `Par ⊆ BetaStar`. -/
70-
public theorem par_subset_betaStar {a b} (h : a ⭢∥ b) :
73+
theorem par_subset_betaStar {a b} (h : a ⭢∥ b) :
7174
a ↠β b := by
7275
induction h with
7376
| var n => exact refl (var n)
@@ -79,7 +82,7 @@ public theorem par_subset_betaStar {a b} (h : a ⭢∥ b) :
7982
exact .trans (BetaStar.appL (BetaStar.abs iht))
8083
(.tail (BetaStar.appR ihs) (Beta.red _ _))
8184

82-
@[simp] public theorem incre_par {a b i l} (h : a ⭢∥ b) :
85+
@[simp] theorem incre_par {a b i l} (h : a ⭢∥ b) :
8386
(incre i l a) ⭢∥ (incre i l b) := by
8487
induction h generalizing l with
8588
| var n => exact par_refl
@@ -135,14 +138,14 @@ private lemma par_subst {t t' u u'} (ht : t ⭢∥ t') (hu : u ⭢∥ u')
135138
(par_subst ht₁ hu k n) (par_subst ht₂ hu k n)
136139

137140
/-- Complete development (maximal Par) for a term. -/
138-
public def Term.dev : Term → Term
141+
def Term.dev : Term → Term
139142
| var n => var n
140143
| abs t => abs (t.dev)
141144
| app (abs t) s => t.dev.sub 0 s.dev
142145
| app t u => app t.dev u.dev
143146

144147
/-- t.dev is a par reduction for t. -/
145-
public theorem par_dev (t : Term) : t ⭢∥ t.dev :=
148+
theorem par_dev (t : Term) : t ⭢∥ t.dev :=
146149
match t with
147150
| var n => Par.var n
148151
| abs t => Par.abs (par_dev t)
@@ -153,7 +156,7 @@ public theorem par_dev (t : Term) : t ⭢∥ t.dev :=
153156
| app t₁ t₂ => Par.app (par_dev (app t₁ t₂)) (par_dev u)
154157

155158
/-- t.dev is max par reduction for t. -/
156-
public theorem par_to_dev {t u} (h : t ⭢∥ u) : u ⭢∥ (t.dev) := by
159+
theorem par_to_dev {t u} (h : t ⭢∥ u) : u ⭢∥ (t.dev) := by
157160
match t, u with
158161
| var t', var u' =>
159162
match h with | Par.var t' => exact Par.var t'

0 commit comments

Comments
 (0)