@@ -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
4445namespace 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
6162namespace 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.
102103Lemma 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.
136137Special thanks to professor Radziwill @maksym-radziwill about
137138his 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' :
0 commit comments