You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
· -- If a = b, then in proj Sigma w, b will only appear if b ∈ Sigma.
139
187
-- But since a ∉ Sigma, b ∉ Sigma, so proj Sigma (b :: w') = proj Sigma w'.
140
188
-- cancel_left (proj Sigma w') a = proj Sigma w' by induction.
141
-
rw [h_ab] at h
142
-
simp [proj, h]
189
+
have h_bS : b ∉ Sigma := h_ab ▸ h
190
+
simp [proj, h_bS]
143
191
exact IH
144
192
· -- If a ≠ b, consider whether b ∈ Sigma.
145
193
by_cases h_bS : b ∈ Sigma
146
194
· -- If b ∈ Sigma, then proj Sigma (b :: w') = b :: proj Sigma w'.
147
195
-- cancel_left (b :: proj Sigma w') a = b :: cancel_left (proj Sigma w') a
148
196
-- By induction, cancel_left (proj Sigma w') a = proj Sigma w', so both sides match.
149
197
simp [proj, h_bS]
150
-
simp [cancel_left, h_ab]
198
+
simp [h_ab]
151
199
exact IH
152
200
· -- If b ∉ Sigma, then proj Sigma (b :: w') = proj Sigma w'.
153
201
-- cancel_left (proj Sigma w') a = proj Sigma w' by induction.
154
202
simp [proj, h_bS]
155
203
exact IH
156
204
205
+
/--
206
+
Projection commutes with left-cancellation: projecting then cancelling is the same as cancelling then projecting.
207
+
-/
157
208
@[simp]
158
-
lemmaproj_and_cancel_left_commute (Sigma : Alphabet α) (w : List α) (a : α) :
209
+
lemmaproj_commutes_with_cancel_left (Sigma : Alphabet α) (w : List α) (a : α) :
159
210
cancel_left (proj Sigma w) a = proj Sigma (cancel_left w a) := by
160
211
-- We prove by induction on w.
161
212
induction w with
@@ -173,11 +224,11 @@ lemma proj_and_cancel_left_commute (Sigma : Alphabet α) (w : List α) (a : α)
173
224
by_cases h_ab : a = b
174
225
· -- If a = b, then cancel_left (b :: proj Sigma w') a = proj Sigma w'.
175
226
-- On the right, cancel_left (b :: w') a = w', so proj Sigma w' = proj Sigma w'.
176
-
simp [cancel_left, h_ab]
227
+
simp [h_ab]
177
228
· -- If a ≠ b, then cancel_left (b :: proj Sigma w') a = b :: cancel_left (proj Sigma w') a
178
229
-- By induction, cancel_left (proj Sigma w') a = proj Sigma (cancel_left w' a)
179
230
-- On the right, cancel_left (b :: w') a = b :: cancel_left w' a, so proj Sigma (b :: cancel_left w' a) = b :: proj Sigma (cancel_left w' a)
180
-
simp [cancel_left, h_ab]
231
+
simp [h_ab]
181
232
simp [proj, h_bS]
182
233
exact IH
183
234
· -- If b ∉ Sigma, then proj Sigma (b :: w') = proj Sigma w'.
@@ -191,14 +242,79 @@ lemma proj_and_cancel_left_commute (Sigma : Alphabet α) (w : List α) (a : α)
191
242
simp [proj, h_bS]
192
243
exact IH
193
244
245
+
/--
246
+
Cancel the first occurrence of a symbol from the right of a word.
247
+
-/
194
248
defcancel_right (w : List α) (a : α) : List α :=
195
249
reverse (cancel_left (reverse w) a)
196
250
251
+
/--
252
+
Right-cancelling from an empty list yields an empty list.
253
+
-/
254
+
@[simp]
255
+
lemmacancel_right_nil (a : α) : cancel_right [] a = [] := by
256
+
-- By definition, cancel_right [] a = reverse (cancel_left (reverse []) a) = reverse (cancel_left [] a) = reverse [] = []
257
+
simp [cancel_right]
258
+
259
+
/--
260
+
Right-cancelling from a nonempty list: if the last element matches the target, remove it; otherwise, cancellation recurses on the prefix and preserves the last element.
261
+
-/
262
+
@[simp]
263
+
lemmacancel_right_snoc (w : List α) (a b : α) :
264
+
cancel_right (w ++ [b]) a = if a = b then w else cancel_right w a ++ [b] := by
265
+
by_cases h : a = b
266
+
· -- If a = b, then cancel_right (w ++ [b]) a = reverse (cancel_left (reverse (w ++ [b])) a)
267
+
-- = reverse (cancel_left (reverse [b] ++ reverse w) a) = reverse (cancel_left ([b] ++ reverse w) a)
268
+
-- = reverse (cancel_left (b :: reverse w) a) = reverse (reverse w) = w
269
+
simp [cancel_right, h]
270
+
· -- If a ≠ b, then cancel_right (w ++ [b]) a = reverse (cancel_left (reverse (w ++ [b])) a)
271
+
-- = reverse (cancel_left (reverse [b] ++ reverse w) a) = reverse (cancel_left ([b] ++ reverse w) a)
272
+
-- = reverse (cancel_left (b :: reverse w) a) = reverse (b :: cancel_left (reverse w) a) = reverse (cancel_left (reverse w) a) ++ [b] = cancel_right w a ++ [b]
273
+
simp [cancel_right, h]
274
+
275
+
/--
276
+
If the symbol `a` is not in the alphabet, then projecting and then cancelling `a` from the right does nothing.
277
+
-/
278
+
@[simp]
279
+
lemmacancel_right_proj_eq_self_when_symb_notin_alph (Sigma : Alphabet α) (w : List α) (a : α) :
280
+
a ∉ Sigma → cancel_right (proj Sigma w) a = proj Sigma w := by
281
+
induction w using induction_right with
282
+
| nil =>
283
+
-- Base case: w = [].
284
+
-- Both sides are cancel_right [] a = [] and proj Sigma [] = [], so equality holds.
285
+
simp [cancel_right, proj]
286
+
| snoc w' b IH =>
287
+
intro h
288
+
by_cases h_ab : a = b
289
+
· -- Case 1: a = b. Since a ∉ Sigma, b ∉ Sigma as well.
290
+
-- The projection removes b, so proj Sigma (w' ++ [b]) = proj Sigma w'.
291
+
-- Right-cancelling a from proj Sigma w is the same as right-cancelling from proj Sigma w',
292
+
-- which by the induction hypothesis is just proj Sigma w'.
293
+
have h_bS : b ∉ Sigma := h_ab ▸ h
294
+
simp [proj, h_bS]
295
+
exact IH h
296
+
· -- Case 2: a ≠ b. Now consider whether b ∈ Sigma.
297
+
by_cases h_bS : b ∈ Sigma
298
+
· -- Subcase: b ∈ Sigma. Then proj Sigma (w' ++ [b]) = proj Sigma w' ++ [b].
299
+
-- Right-cancelling a from proj Sigma w is cancel_right (proj Sigma w') a ++ [b].
300
+
-- By the induction hypothesis, cancel_right (proj Sigma w') a = proj Sigma w', so both sides match.
301
+
simp [proj, h_bS]
302
+
simp [h_ab]
303
+
exact IH h
304
+
· -- Subcase: b ∉ Sigma. Then proj Sigma (w' ++ [b]) = proj Sigma w'.
305
+
-- Right-cancelling a from proj Sigma w is the same as right-cancelling from proj Sigma w',
306
+
-- which by the induction hypothesis is just proj Sigma w'.
307
+
simp [proj, h_bS]
308
+
exact IH h
309
+
310
+
/--
311
+
Projection commutes with right-cancellation: projecting then cancelling is the same as cancelling then projecting.
312
+
-/
197
313
@[simp]
198
-
lemmaproj_and_cancel_right_commute (Sigma : Alphabet α) (w : List α) (a : α) :
314
+
lemmaproj_commutes_with_cancel_right (Sigma : Alphabet α) (w : List α) (a : α) :
199
315
cancel_right (proj Sigma w) a = proj Sigma (cancel_right w a) := by
200
316
-- The right-cancellation is defined as reversing, left-cancelling, then reversing again.
201
317
-- Since proj and reverse commute (by proj_and_reverse_commute), the operations can be swapped.
0 commit comments