Skip to content

Commit 1d84eb6

Browse files
committed
feat: miscellaneous grind golfs (#29700)
1 parent 5ec827a commit 1d84eb6

File tree

11 files changed

+17
-58
lines changed

11 files changed

+17
-58
lines changed

Mathlib/Algebra/Order/Floor/Ring.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ theorem fract_sub_self (a : R) : fract a - a = -⌊a⌋ :=
315315
theorem fract_add (a b : R) : ∃ z : ℤ, fract (a + b) - fract a - fract b = z :=
316316
⟨⌊a⌋ + ⌊b⌋ - ⌊a + b⌋, by
317317
unfold fract
318-
simp only [sub_eq_add_neg, neg_add_rev, neg_neg, cast_add, cast_neg]
319-
abel⟩
318+
grind⟩
320319

321320
variable [IsStrictOrderedRing R]
322321

Mathlib/Algebra/Polynomial/Derivative.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,7 @@ theorem derivative_mul {f g : R[X]} : derivative (f * g) = derivative f * g + f
255255
| succ m =>
256256
cases n with
257257
| zero => simp only [add_zero, Nat.cast_zero, mul_zero, map_zero]
258-
| succ n =>
259-
simp only [Nat.add_succ_sub_one, add_tsub_cancel_right]
260-
rw [add_assoc, add_comm n 1]
258+
| succ n => grind
261259

262260
theorem derivative_eval (p : R[X]) (x : R) :
263261
p.derivative.eval x = p.sum fun n a => a * n * x ^ (n - 1) := by

Mathlib/Combinatorics/Matroid/Map.lean

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ def comap (N : Matroid β) (f : α → β) : Matroid α :=
162162
@[simp] lemma comap_dep_iff :
163163
(N.comap f).Dep I ↔ N.Dep (f '' I) ∨ (N.Indep (f '' I) ∧ ¬ InjOn f I) := by
164164
rw [Dep, comap_indep_iff, not_and, comap_ground_eq, Dep, image_subset_iff]
165-
refine ⟨fun ⟨hi, h⟩ ↦ ?_, ?_⟩
166-
· rw [and_iff_left h, ← imp_iff_not_or]
167-
exact fun hI ↦ ⟨hI, hi hI⟩
165+
refine ⟨by grind, ?_⟩
168166
rintro (⟨hI, hIE⟩ | hI)
169167
· exact ⟨fun h ↦ (hI h).elim, hIE⟩
170168
rw [iff_true_intro hI.1, iff_true_intro hI.2, implies_true, true_and]
@@ -459,9 +457,7 @@ lemma map_comap {f : α → β} (h_range : N.E ⊆ range f) (hf : InjOn f (f ⁻
459457
(N.comap f).map f hf = N := by
460458
refine ext_indep (by simpa [image_preimage_eq_iff]) ?_
461459
simp only [map_ground, comap_ground_eq, map_indep_iff, comap_indep_iff, forall_subset_image_iff]
462-
refine fun I hI ↦ ⟨fun ⟨I₀, ⟨hI₀, _⟩, hII₀⟩ ↦ ?_, fun h ↦ ⟨_, ⟨h, hf.mono hI⟩, rfl⟩⟩
463-
suffices h : I₀ ⊆ f ⁻¹' N.E by rw [InjOn.image_eq_image_iff hf hI h] at hII₀; rwa [hII₀]
464-
exact (subset_preimage_image f I₀).trans <| preimage_mono (f := f) hI₀.subset_ground
460+
exact fun I hI ↦ ⟨by grind, fun h ↦ ⟨_, ⟨h, hf.mono hI⟩, rfl⟩⟩
465461

466462
lemma comap_map {f : α → β} (hf : f.Injective) : (M.map f hf.injOn).comap f = M := by
467463
simp [ext_iff_indep, preimage_image_eq _ hf, and_iff_left hf.injOn,

Mathlib/Data/Int/Init.lean

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ where
107107
neg : ∀ n : ℕ, motive (b + -[n+1])
108108
| 0 => pred _ Int.le_rfl zero
109109
| n + 1 => by
110-
refine cast (by rw [Int.add_sub_assoc]; rfl) (pred _ (Int.le_of_lt ?_) (neg n))
110+
refine cast (by cutsat) (pred _ (Int.le_of_lt ?_) (neg n))
111111
cutsat
112112

113113
variable {z b zero succ pred}
@@ -143,13 +143,7 @@ end inductionOn'
143143
@[elab_as_elim]
144144
protected lemma le_induction {m : ℤ} {motive : ∀ n, m ≤ n → Prop} (base : motive m m.le_refl)
145145
(succ : ∀ n hmn, motive n hmn → motive (n + 1) (le_add_one hmn)) : ∀ n hmn, motive n hmn := by
146-
refine fun n ↦ Int.inductionOn' n m ?_ ?_ ?_
147-
· intro
148-
exact base
149-
· intro k hle hi _
150-
exact succ k hle (hi hle)
151-
· intro k hle _ hle'
152-
cutsat
146+
refine fun n ↦ Int.inductionOn' n m ?_ ?_ ?_ <;> grind
153147

154148
/-- See `Int.inductionOn'` for an induction in both directions. -/
155149
@[elab_as_elim]

Mathlib/Data/Nat/Bits.lean

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ Copyright (c) 2022 Praneeth Kolichala. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Praneeth Kolichala
55
-/
6-
import Mathlib.Data.Nat.Basic
76
import Mathlib.Data.Nat.BinaryRec
87
import Mathlib.Data.List.Defs
98
import Mathlib.Tactic.Convert
109
import Mathlib.Tactic.GeneralizeProofs
1110
import Mathlib.Tactic.Says
11+
import Mathlib.Util.AssertExists
1212

1313
/-!
1414
# Additional properties of binary recursion on `Nat`
@@ -101,6 +101,7 @@ lemma bodd_add_div2 : ∀ n, (bodd n).toNat + 2 * div2 n = n
101101
· simp
102102
· simp; cutsat
103103

104+
@[grind =]
104105
lemma div2_val (n) : div2 n = n / 2 := by
105106
refine Nat.eq_of_mul_eq_mul_left (by decide)
106107
(Nat.add_left_cancel (Eq.trans ?_ (Nat.mod_add_div n 2).symm))
@@ -138,12 +139,7 @@ lemma shiftLeft'_false : ∀ n, shiftLeft' false m n = m <<< n
138139
@[simp] lemma shiftLeft_eq' (m n : Nat) : shiftLeft m n = m <<< n := rfl
139140
@[simp] lemma shiftRight_eq (m n : Nat) : shiftRight m n = m >>> n := rfl
140141

141-
lemma binaryRec_decreasing (h : n ≠ 0) : div2 n < n := by
142-
rw [div2_val]
143-
apply (div_lt_iff_lt_mul <| succ_pos 1).2
144-
have := Nat.mul_lt_mul_of_pos_left (lt_succ_self 1)
145-
(lt_of_le_of_ne n.zero_le h.symm)
146-
rwa [Nat.mul_one] at this
142+
lemma binaryRec_decreasing (h : n ≠ 0) : div2 n < n := by grind
147143

148144
/-- `size n` : Returns the size of a natural number in
149145
bits i.e. the length of its binary representation -/

Mathlib/Data/Nat/Digits/Lemmas.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ theorem ofDigits_eq_sum_mapIdx_aux (b : ℕ) (l : List ℕ) :
2828
l.zipWith (fun a i : ℕ => a * b ^ (i + 1)) (List.range l.length) =
2929
l.zipWith (fun a i=> b * (a * b ^ i)) (List.range l.length)
3030
by simp [this]
31-
congr; ext; simp [pow_succ]; ring
31+
congr; ext; ring
3232

3333
theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) :
3434
ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by

Mathlib/Data/Nat/Size.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
66
import Mathlib.Algebra.Group.Nat.Defs
77
import Mathlib.Algebra.Group.Basic
88
import Mathlib.Data.Nat.Bits
9+
import Mathlib.Data.Nat.Basic
910

1011
/-! Lemmas about `size`. -/
1112

Mathlib/Data/PEquiv.lean

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -386,17 +386,7 @@ instance [DecidableEq α] [DecidableEq β] : SemilatticeInf (α ≃. β) :=
386386
have hf := @mem_iff_mem _ _ f a b
387387
have hg := @mem_iff_mem _ _ g a b
388388
simp only [Option.mem_def] at *
389-
split_ifs with h1 h2 h2 <;> try simp [hf]
390-
· contrapose! h2
391-
rw [h2]
392-
rw [← h1, hf, h2] at hg
393-
simp only [true_iff] at hg
394-
rw [hg]
395-
· contrapose! h1
396-
rw [h1] at hf h2
397-
rw [← h2] at hg
398-
simp only [iff_true] at hf hg
399-
rw [hf, hg] }
389+
grind }
400390
inf_le_left := fun _ _ _ _ => by simp only [coe_mk, mem_def]; split_ifs <;> simp [*]
401391
inf_le_right := fun _ _ _ _ => by simp only [coe_mk, mem_def]; split_ifs <;> simp [*]
402392
le_inf := fun f g h fg gh a b => by

Mathlib/MeasureTheory/Constructions/Cylinders.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ theorem comap_eval_le_generateFrom_squareCylinders_singleton
122122
convert ht
123123
simp only [cast_heq]
124124
· simp only [hji, not_false_iff, dif_neg, MeasurableSet.univ]
125-
· simp only [eq_mpr_eq_cast, ← h]
126-
ext1 x
127-
simp only [Function.eval, cast_eq, dite_eq_ite, ite_true, mem_preimage]
125+
· grind
128126

129127
/-- The square cylinders formed from measurable sets generate the product σ-algebra. -/
130128
theorem generateFrom_squareCylinders [∀ i, MeasurableSpace (α i)] :

Mathlib/MeasureTheory/PiSystem.lean

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -407,17 +407,8 @@ theorem isPiSystem_piiUnionInter (π : ι → Set (Set α)) (hpi : ∀ x, IsPiSy
407407
rw [ht1_eq, ht2_eq]
408408
simp_rw [← Set.inf_eq_inter]
409409
ext1 x
410-
simp only [g, inf_eq_inter, mem_inter_iff, mem_iInter, Finset.mem_union]
411-
refine ⟨fun h i _ => ?_, fun h => ⟨fun i hi1 => ?_, fun i hi2 => ?_⟩⟩
412-
· split_ifs with h_1 h_2 h_2
413-
exacts [⟨h.1 i h_1, h.2 i h_2⟩, ⟨h.1 i h_1, Set.mem_univ _⟩, ⟨Set.mem_univ _, h.2 i h_2⟩,
414-
⟨Set.mem_univ _, Set.mem_univ _⟩]
415-
· specialize h i (Or.inl hi1)
416-
rw [if_pos hi1] at h
417-
exact h.1
418-
· specialize h i (Or.inr hi2)
419-
rw [if_pos hi2] at h
420-
exact h.2
410+
simp only [inf_eq_inter, mem_inter_iff, mem_iInter]
411+
grind
421412
refine ⟨fun n hn => ?_, h_inter_eq⟩
422413
simp only [g]
423414
split_ifs with hn1 hn2 h
@@ -427,8 +418,7 @@ theorem isPiSystem_piiUnionInter (π : ι → Set (Set α)) (hpi : ∀ x, IsPiSy
427418
(Set.not_nonempty_iff_eq_empty.mpr h_empty) h_nonempty
428419
refine le_antisymm (Set.iInter_subset_of_subset n ?_) (Set.empty_subset _)
429420
refine Set.iInter_subset_of_subset hn ?_
430-
simp_rw [g, if_pos hn1, if_pos hn2]
431-
exact h.subset
421+
grind
432422
· simp [hf1m n hn1]
433423
· simp [hf2m n h]
434424
· exact absurd hn (by simp [hn1, h])

0 commit comments

Comments
 (0)