Skip to content

Commit 24899be

Browse files
thomaskwaringtwwarchenson2018
authored
chore(CombinatoryLogic): miscellaneous grind golfing (#345)
Low priority --------- Co-authored-by: twwar <tom.waring@unimelb.edu.au> Co-authored-by: Chris Henson <chrishenson.net@gmail.com>
1 parent 1bb3a54 commit 24899be

4 files changed

Lines changed: 19 additions & 55 deletions

File tree

Cslib/Languages/CombinatoryLogic/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ theorem Polynomial.toSKI_correct {n : Nat} (Γ : SKI.Polynomial n) (xs : List SK
140140
replace ⟨ys, z, h⟩ := h
141141
-- apply inductive step, using elimVar_correct
142142
have : ys.length = n := by
143-
replace h := congr_arg List.length <| h
143+
replace h := congr_arg List.length h
144144
simp_rw [List.length_append, List.length_singleton, hxs] at h
145145
exact Nat.succ_inj.mp h.symm
146146
simp_rw [h, applyList_concat]

Cslib/Languages/CombinatoryLogic/Confluence.lean

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,9 @@ theorem parallelReduction_diamond : Diamond ParallelReduction := by
172172
let ⟨a'', c', h⟩ := Sab_irreducible a c a' ha'
173173
rw [h.2.2]
174174
use a'' ⬝ b' ⬝ (c' ⬝ b'), .red_S a'' c' b'
175-
apply ParallelReduction.par
176-
· apply ParallelReduction.par
177-
· exact h.1
178-
· exact hb'
179-
· apply ParallelReduction.par
180-
· exact h.2.1
181-
· exact hb'
175+
apply ParallelReduction.par <;>
176+
apply ParallelReduction.par <;>
177+
grind
182178
case red_I =>
183179
cases h₂
184180
case refl => use a₁; exact ⟨.refl a₁, .red_I a₁⟩
@@ -201,7 +197,7 @@ theorem parallelReduction_diamond : Diamond ParallelReduction := by
201197
cases h₂
202198
case refl =>
203199
use a ⬝ c ⬝ (b ⬝ c)
204-
exact ⟨.refl _, .red_S _ _ _
200+
exact ⟨.refl _, .red_S ..
205201
case par d c' hd hc =>
206202
let ⟨a', b', h⟩ := Sab_irreducible a b d hd
207203
rw [h.2.2]
@@ -210,7 +206,7 @@ theorem parallelReduction_diamond : Diamond ParallelReduction := by
210206
· apply ParallelReduction.par
211207
· exact .par h.left hc
212208
· exact .par h.2.1 hc
213-
· exact .red_S _ _ _
209+
· exact .red_S ..
214210
case red_S => exact ⟨a ⬝ c ⬝ (b ⬝ c), .refl _, .refl _,⟩
215211

216212
theorem join_parallelReduction_equivalence :

Cslib/Languages/CombinatoryLogic/Evaluation.lean

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,7 @@ instance : DecidablePred RedexFree := fun _ => decidable_of_iff' _ redexFree_iff
169169
/-- A term is redex free iff its only many-step reduction is itself. -/
170170
theorem redexFree_iff_mred_eq {x : SKI} : x.RedexFree ↔ ∀ y, (x ↠ y) ↔ x = y := by
171171
constructor
172-
case mp =>
173-
intro h y
174-
constructor
175-
case mp =>
176-
intro h'
177-
cases h'.cases_head
178-
case inl => assumption
179-
case inr h' =>
180-
obtain ⟨z, hz, _⟩ := h'
181-
cases h.normal_red ⟨_, hz⟩
182-
case mpr =>
183-
intro h
184-
rw [h]
172+
case mp => grind [RedexFree.normal_red]
185173
case mpr =>
186174
intro h
187175
rw [redexFree_iff]
@@ -232,21 +220,7 @@ theorem isBool_injective (x y : SKI) (u v : Bool) (hx : IsBool u x) (hy : IsBool
232220
· exact mJoin_red_head K <| mJoin_red_head S hxy
233221
· apply Relation.MJoin.single
234222
exact hy S K
235-
by_cases u
236-
case pos hu =>
237-
by_cases v
238-
case pos hv =>
239-
rw [hu, hv]
240-
case neg hv =>
241-
simp_rw [hu, hv, Bool.false_eq_true, reduceIte] at h
242-
exact False.elim <| sk_nequiv h
243-
case neg hu =>
244-
by_cases v
245-
case pos hv =>
246-
simp_rw [hu, hv, Bool.false_eq_true, reduceIte] at h
247-
exact False.elim <| sk_nequiv (mJoin_red_equivalence.symm h)
248-
case neg hv =>
249-
simp_rw [hu, hv]
223+
grind [sk_nequiv, mJoin_red_equivalence.symm h]
250224

251225
lemma TF_nequiv : ¬ MJoin Red TT FF := fun h =>
252226
(Bool.eq_not_self true).mp <| isBool_injective TT FF true false TT_correct FF_correct h

Cslib/Languages/CombinatoryLogic/Recursion.lean

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -304,23 +304,17 @@ theorem RFindAbove_correct (fNat : Nat → Nat) (f x : SKI)
304304
induction n generalizing m x
305305
all_goals apply isChurch_trans (a' := RFindAboveAux ⬝ RFindAbove ⬝ x ⬝ f)
306306
case zero.a =>
307-
apply isChurch_trans (a' := x)
308-
· have : IsChurch (fNat m) (f ⬝ x) := hf m x hx
309-
rw [Nat.add_zero] at hroot
310-
simp_rw [hroot] at this
311-
apply rfindAboveAux_base
312-
assumption
313-
· assumption
307+
apply isChurch_trans (a' := x) <;>
308+
grind [rfindAboveAux_base]
314309
case succ.a n ih =>
315-
unfold RFindAbove
316310
apply isChurch_trans (a' := RFindAbove ⬝ (SKI.Succ ⬝ x) ⬝ f)
317311
· let y := (fNat m).pred
318-
have : IsChurch (y+1) (f ⬝ x) := by
312+
have : IsChurch (y + 1) (f ⬝ x) := by
319313
subst y
320314
exact Nat.succ_pred_eq_of_ne_zero (hpos 0 (by simp)) ▸ hf m x hx
321315
apply rfindAboveAux_step
322316
assumption
323-
· replace ih := ih (SKI.Succ ⬝ x) (m+1) (succ_correct _ x hx)
317+
· replace ih := ih (SKI.Succ ⬝ x) (m + 1) (succ_correct _ x hx)
324318
grind
325319
-- close the `h` goals of the above `apply isChurch_trans`
326320
all_goals {apply MRed.head; apply MRed.head; exact fixedPoint_correct _}
@@ -347,8 +341,8 @@ theorem add_def (a b : SKI) : (SKI.Add ⬝ a ⬝ b) ↠ a ⬝ SKI.Succ ⬝ b :=
347341
AddPoly.toSKI_correct [a, b] (by simp)
348342

349343
theorem add_correct (n m : Nat) (a b : SKI) (ha : IsChurch n a) (hb : IsChurch m b) :
350-
IsChurch (n+m) (SKI.Add ⬝ a ⬝ b) := by
351-
refine isChurch_trans (n+m) (a' := Church n SKI.Succ b) ?_ ?_
344+
IsChurch (n + m) (SKI.Add ⬝ a ⬝ b) := by
345+
refine isChurch_trans (n + m) (a' := Church n SKI.Succ b) ?_ ?_
352346
· calc
353347
_ ↠ a ⬝ SKI.Succ ⬝ b := add_def a b
354348
_ ↠ Church n SKI.Succ b := ha SKI.Succ b
@@ -367,15 +361,15 @@ theorem mul_def (a b : SKI) : (SKI.Mul ⬝ a ⬝ b) ↠ a ⬝ (SKI.Add ⬝ b)
367361
MulPoly.toSKI_correct [a, b] (by simp)
368362

369363
theorem mul_correct {n m : Nat} {a b : SKI} (ha : IsChurch n a) (hb : IsChurch m b) :
370-
IsChurch (n*m) (SKI.Mul ⬝ a ⬝ b) := by
371-
refine isChurch_trans (n*m) (a' := Church n (SKI.Add ⬝ b) SKI.Zero) ?_ ?_
364+
IsChurch (n * m) (SKI.Mul ⬝ a ⬝ b) := by
365+
refine isChurch_trans (n * m) (a' := Church n (SKI.Add ⬝ b) SKI.Zero) ?_ ?_
372366
· exact Trans.trans (mul_def a b) (ha (SKI.Add ⬝ b) SKI.Zero)
373367
· clear ha
374368
induction n with
375369
| zero => simp_rw [Nat.zero_mul, Church]; exact zero_correct
376370
| succ n ih =>
377371
simp_rw [Nat.add_mul, Nat.one_mul, Nat.add_comm, Church]
378-
exact add_correct m (n*m) b (Church n (SKI.Add ⬝ b) SKI.Zero) hb ih
372+
exact add_correct m (n * m) b (Church n (SKI.Add ⬝ b) SKI.Zero) hb ih
379373

380374
/-- Subtraction: λ n m. n Pred m -/
381375
def SubPoly : SKI.Polynomial 2 := &1 ⬝' Pred ⬝' &0
@@ -385,8 +379,8 @@ theorem sub_def (a b : SKI) : (SKI.Sub ⬝ a ⬝ b) ↠ b ⬝ Pred ⬝ a :=
385379
SubPoly.toSKI_correct [a, b] (by simp)
386380

387381
theorem sub_correct (n m : Nat) (a b : SKI) (ha : IsChurch n a) (hb : IsChurch m b) :
388-
IsChurch (n-m) (SKI.Sub ⬝ a ⬝ b) := by
389-
refine isChurch_trans (n-m) (a' := Church m Pred a) ?_ ?_
382+
IsChurch (n - m) (SKI.Sub ⬝ a ⬝ b) := by
383+
refine isChurch_trans (n - m) (a' := Church m Pred a) ?_ ?_
390384
· calc
391385
_ ↠ b ⬝ Pred ⬝ a := sub_def a b
392386
_ ↠ Church m Pred a := hb Pred a

0 commit comments

Comments
 (0)