Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 935003e

Browse files
kim-emdigama0
andcommitted
chore(data/nat/basic): add @[simp] to some lemmas about numerals (#6652)
Allows the simplifier to make more progress in equalities of numerals (both in nat, and in `[(semi)ring R] [no_zero_divisors R] [char_zero R]`). Also adds `@[simp]` to `nat.succ_ne_zero` and `nat.succ_ne_self`. Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Mario Carneiro <di.gama@gmail.com>
1 parent e0a7918 commit 935003e

File tree

5 files changed

+80
-12
lines changed

5 files changed

+80
-12
lines changed

src/algebra/char_zero.lean

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,57 @@ end
108108
section
109109
variables {R : Type*} [semiring R] [no_zero_divisors R] [char_zero R]
110110

111+
@[simp]
111112
lemma add_self_eq_zero {a : R} : a + a = 0 ↔ a = 0 :=
112113
by simp only [(two_mul a).symm, mul_eq_zero, two_ne_zero', false_or]
113114

115+
@[simp]
114116
lemma bit0_eq_zero {a : R} : bit0 a = 0 ↔ a = 0 := add_self_eq_zero
117+
@[simp]
118+
lemma zero_eq_bit0 {a : R} : 0 = bit0 a ↔ a = 0 :=
119+
by { rw [eq_comm], exact bit0_eq_zero }
120+
end
121+
122+
section
123+
variables {R : Type*} [ring R] [no_zero_divisors R] [char_zero R]
124+
125+
lemma nat_mul_inj {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) : n = 0 ∨ a = b :=
126+
begin
127+
rw [←sub_eq_zero, ←mul_sub, mul_eq_zero, sub_eq_zero] at h,
128+
exact_mod_cast h,
129+
end
130+
131+
lemma nat_mul_inj' {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) (w : n ≠ 0) : a = b :=
132+
by simpa [w] using nat_mul_inj h
133+
134+
lemma bit0_injective : function.injective (bit0 : R → R) :=
135+
λ a b h, begin
136+
dsimp [bit0] at h,
137+
simp only [(two_mul a).symm, (two_mul b).symm] at h,
138+
refine nat_mul_inj' _ two_ne_zero,
139+
exact_mod_cast h,
140+
end
141+
142+
lemma bit1_injective : function.injective (bit1 : R → R) :=
143+
λ a b h, begin
144+
simp only [bit1, add_left_inj] at h,
145+
exact bit0_injective h,
146+
end
147+
148+
@[simp] lemma bit0_eq_bit0 {a b : R} : bit0 a = bit0 b ↔ a = b :=
149+
bit0_injective.eq_iff
150+
151+
@[simp] lemma bit1_eq_bit1 {a b : R} : bit1 a = bit1 b ↔ a = b :=
152+
bit1_injective.eq_iff
153+
154+
@[simp]
155+
lemma bit1_eq_one {a : R} : bit1 a = 1 ↔ a = 0 :=
156+
by rw [show (1 : R) = bit1 0, by simp, bit1_eq_bit1]
157+
158+
@[simp]
159+
lemma one_eq_bit1 {a : R} : 1 = bit1 a ↔ a = 0 :=
160+
by { rw [eq_comm], exact bit1_eq_one }
161+
115162
end
116163

117164
section

src/analysis/normed_space/operator_norm.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ begin
126126
{ assume h,
127127
have : x₀ ∈ f.ker, by { rw h, exact (linear_map.ker f).zero_mem },
128128
exact x₀ker this },
129-
have rx₀_ne_zero : r * ∥x₀∥ ≠ 0, by { simp [norm_eq_zero, this], norm_num },
129+
have rx₀_ne_zero : r * ∥x₀∥ ≠ 0, by { simp [norm_eq_zero, this], },
130130
have : ∀x, ∥f x∥ ≤ (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥,
131131
{ assume x,
132132
by_cases hx : f x = 0,

src/data/nat/basic.lean

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ instance nat.comm_cancel_monoid_with_zero : comm_cancel_monoid_with_zero ℕ :=
115115
λ _ _ _ h1 h2, nat.eq_of_mul_eq_mul_right (nat.pos_of_ne_zero h1) h2,
116116
.. (infer_instance : comm_monoid_with_zero ℕ) }
117117

118-
attribute [simp] nat.not_lt_zero
118+
attribute [simp] nat.not_lt_zero nat.succ_ne_zero nat.succ_ne_self
119+
nat.zero_ne_one nat.one_ne_zero
120+
nat.zero_ne_bit1 nat.bit1_ne_zero
121+
nat.bit0_ne_one nat.one_ne_bit0
122+
nat.bit0_ne_bit1 nat.bit1_ne_bit0
119123

120124
/-!
121125
Inject some simple facts into the type class system.
@@ -1434,6 +1438,23 @@ by unfold bodd div2; cases bodd_div2 n; refl
14341438

14351439
/-! ### `bit0` and `bit1` -/
14361440

1441+
-- There is no need to prove `bit0_eq_zero : bit0 n = 0 ↔ n = 0`
1442+
-- as this is true for any `[semiring R] [no_zero_divisors R] [char_zero R]`
1443+
1444+
-- However the lemmas `bit0_eq_bit0`, `bit1_eq_bit1`, `bit1_eq_one`, `one_eq_bit1`
1445+
-- need `[ring R] [no_zero_divisors R] [char_zero R]` in general,
1446+
-- so we prove `ℕ` specialized versions here.
1447+
@[simp] lemma bit0_eq_bit0 {m n : ℕ} : bit0 m = bit0 n ↔ m = n :=
1448+
⟨nat.bit0_inj, λ h, by subst h⟩
1449+
1450+
@[simp] lemma bit1_eq_bit1 {m n : ℕ} : bit1 m = bit1 n ↔ m = n :=
1451+
⟨nat.bit1_inj, λ h, by subst h⟩
1452+
1453+
@[simp] lemma bit1_eq_one {n : ℕ} : bit1 n = 1 ↔ n = 0 :=
1454+
⟨@nat.bit1_inj n 0, λ h, by subst h⟩
1455+
@[simp] lemma one_eq_bit1 {n : ℕ} : 1 = bit1 n ↔ n = 0 :=
1456+
⟨λ h, (@nat.bit1_inj 0 n h).symm, λ h, by subst h⟩
1457+
14371458
protected theorem bit0_le {n m : ℕ} (h : n ≤ m) : bit0 n ≤ bit0 m :=
14381459
add_le_add h h
14391460

src/data/sym2.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,22 @@ def sym2_equiv_sym' {α : Type*} : equiv (sym2 α) (sym' α 2) :=
273273
(by { rintros _ _ ⟨_⟩, { refl }, apply list.perm.swap', refl }),
274274
inv_fun := quotient.map from_vector (begin
275275
rintros ⟨x, hx⟩ ⟨y, hy⟩ h,
276-
cases x with _ x, { simp at hx; tauto },
277-
cases x with _ x, { simp at hx; norm_num at hx },
278-
cases x with _ x, swap, { exfalso, simp at hx; linarith [hx] },
279-
cases y with _ y, { simp at hy; tauto },
280-
cases y with _ y, { simp at hy; norm_num at hy },
281-
cases y with _ y, swap, { exfalso, simp at hy; linarith [hy] },
276+
cases x with _ x, { simpa using hx, },
277+
cases x with _ x, { simpa using hx, },
278+
cases x with _ x, swap, { exfalso, simp at hx, linarith [hx] },
279+
cases y with _ y, { simpa using hy, },
280+
cases y with _ y, { simpa using hy, },
281+
cases y with _ y, swap, { exfalso, simp at hy, linarith [hy] },
282282
rcases perm_card_two_iff.mp h with ⟨rfl,rfl⟩|⟨rfl,rfl⟩, { refl },
283283
apply sym2.rel.swap,
284284
end),
285285
left_inv := by tidy,
286286
right_inv := λ x, begin
287287
refine quotient.rec_on_subsingleton x (λ x, _),
288288
{ cases x with x hx,
289-
cases x with _ x, { simp at hx; tauto },
290-
cases x with _ x, { simp at hx; norm_num at hx },
291-
cases x with _ x, swap, { exfalso, simp at hx; linarith [hx] },
289+
cases x with _ x, { simpa using hx, },
290+
cases x with _ x, { simpa using hx, },
291+
cases x with _ x, swap, { exfalso, simp at hx, linarith [hx] },
292292
refl },
293293
end }
294294

src/ring_theory/polynomial/bernstein.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ begin
154154
replace w := nat.lt_succ_iff.mp w,
155155
revert w,
156156
induction k with k ih generalizing n ν,
157-
{ simp [eval_at_0], rintro ⟨⟩, },
157+
{ simp [eval_at_0], },
158158
{ simp only [derivative_succ, int.coe_nat_eq_zero, int.nat_cast_eq_coe_nat, mul_eq_zero,
159159
function.comp_app, function.iterate_succ,
160160
polynomial.iterate_derivative_sub, polynomial.iterate_derivative_cast_nat_mul,

0 commit comments

Comments
 (0)