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

Commit b190131

Browse files
kim-emjcommelin
andcommitted
feat(data/int/basic): lemmas about int and int.to_nat (#6253)
Golfing welcome. This adds a `@[simp]` lemma `int.add_minus_one : i + -1 = i - 1`, which I think is mostly helpful, but needs to be turned off in `data/num/lemmas.lean`, which is perhaps an argument against it. I've also added a lemma ``` @[simp] lemma lt_self_iff_false [preorder α] (a : α) : a < a ↔ false := ``` (not just for `int`), which I've often found useful (e.g. `simpa` works well when it can reduce a hypothesis to `false`). This lemma seems harmless, but I'm happy to hear objections if it is too general. Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Johan Commelin <johan@commelin.net>
1 parent 8b8a5a2 commit b190131

File tree

7 files changed

+35
-5
lines changed

7 files changed

+35
-5
lines changed

src/algebra/group_power/lemmas.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ by induction b; simp [*, mul_add, pow_succ, add_comm]
717717
@[simp] lemma int.to_add_gpow (a : multiplicative ℤ) (b : ℤ) : to_add (a ^ b) = to_add a * b :=
718718
int.induction_on b (by simp)
719719
(by simp [gpow_add, mul_add] {contextual := tt})
720-
(by simp [gpow_add, mul_add, sub_eq_add_neg] {contextual := tt})
720+
(by simp [gpow_add, mul_add, sub_eq_add_neg, -int.add_minus_one] {contextual := tt})
721721

722722
@[simp] lemma int.of_add_mul (a b : ℤ) : of_add (a * b) = of_add a ^ b :=
723723
(int.to_add_gpow _ _).symm

src/data/int/basic.lean

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ instance : linear_ordered_comm_ring int :=
6060
instance : linear_ordered_add_comm_group int :=
6161
by apply_instance
6262

63+
@[simp] lemma add_minus_one (i : ℤ) : i + -1 = i - 1 := rfl
64+
6365
theorem abs_eq_nat_abs : ∀ a : ℤ, abs a = nat_abs a
6466
| (n : ℕ) := abs_of_nonneg $ coe_zero_le _
6567
| -[1+ n] := abs_of_nonpos $ le_of_lt $ neg_succ_lt_zero _
@@ -81,6 +83,13 @@ attribute [simp] int.of_nat_eq_coe int.bodd
8183
@[simp] theorem add_def {a b : ℤ} : int.add a b = a + b := rfl
8284
@[simp] theorem mul_def {a b : ℤ} : int.mul a b = a * b := rfl
8385

86+
@[simp] lemma neg_succ_not_nonneg (n : ℕ) : 0 ≤ -[1+ n] ↔ false :=
87+
by { simp only [not_le, iff_false], exact int.neg_succ_lt_zero n, }
88+
89+
@[simp] lemma neg_succ_not_pos (n : ℕ) : 0 < -[1+ n] ↔ false :=
90+
by simp only [not_lt, iff_false]
91+
92+
@[simp] lemma neg_succ_sub_one (n : ℕ) : -[1+ n] - 1 = -[1+ (n+1)] := rfl
8493
@[simp] theorem coe_nat_mul_neg_succ (m n : ℕ) : (m : ℤ) * -[1+ n] = -(m * succ n) := rfl
8594
@[simp] theorem neg_succ_mul_coe_nat (m n : ℕ) : -[1+ m] * n = -(succ m * n) := rfl
8695
@[simp] theorem neg_succ_mul_neg_succ (m n : ℕ) : -[1+ m] * -[1+ n] = succ m * succ n := rfl
@@ -154,6 +163,12 @@ theorem add_one_le_iff {a b : ℤ} : a + 1 ≤ b ↔ a < b := iff.rfl
154163
theorem lt_add_one_iff {a b : ℤ} : a < b + 1 ↔ a ≤ b :=
155164
@add_le_add_iff_right _ _ a b 1
156165

166+
@[simp] lemma succ_coe_nat_pos (n : ℕ) : 0 < (n : ℤ) + 1 :=
167+
lt_add_one_iff.mpr (by simp)
168+
169+
@[norm_cast] lemma coe_pred_of_pos (n : ℕ) (h : 0 < n) : ((n - 1 : ℕ) : ℤ) = (n : ℤ) - 1 :=
170+
by { cases n, cases h, simp, }
171+
157172
lemma le_add_one {a b : ℤ} (h : a ≤ b) : a ≤ b + 1 :=
158173
le_of_lt (int.lt_add_one_iff.mpr h)
159174

@@ -1012,6 +1027,16 @@ end
10121027
lemma to_nat_add_one {a : ℤ} (h : 0 ≤ a) : (a + 1).to_nat = a.to_nat + 1 :=
10131028
to_nat_add h (zero_le_one)
10141029

1030+
@[simp]
1031+
lemma pred_to_nat : ∀ (i : ℤ), (i - 1).to_nat = i.to_nat - 1
1032+
| (0:ℕ) := rfl
1033+
| (n+1:ℕ) := by simp
1034+
| -[1+ n] := rfl
1035+
1036+
@[simp]
1037+
lemma to_nat_pred_coe_of_pos {i : ℤ} (h : 0 < i) : ((i.to_nat - 1 : ℕ) : ℤ) = i - 1 :=
1038+
by simp [h, le_of_lt h] with push_cast
1039+
10151040
/-- If `n : ℕ`, then `int.to_nat' n = some n`, if `n : ℤ` is negative, then `int.to_nat' n = none`.
10161041
-/
10171042
def to_nat' : ℤ → option ℕ

src/data/num/lemmas.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ begin
822822
conv { to_lhs, rw ← zneg_zneg n },
823823
rw [← zneg_bit1, cast_zneg, cast_bit1],
824824
have : ((-1 + n + n : ℤ) : α) = (n + n + -1 : ℤ), {simp [add_comm, add_left_comm]},
825-
simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg]
825+
simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg, -int.add_minus_one]
826826
end
827827

828828
theorem add_zero (n : znum) : n + 0 = n := by cases n; refl
@@ -843,6 +843,8 @@ theorem cast_to_znum : ∀ n : pos_num, (n : znum) = znum.pos n
843843
| (bit0 p) := (znum.bit0_of_bit0 p).trans $ congr_arg _ (cast_to_znum p)
844844
| (bit1 p) := (znum.bit1_of_bit1 p).trans $ congr_arg _ (cast_to_znum p)
845845

846+
local attribute [-simp] int.add_minus_one
847+
846848
theorem cast_sub' [add_group α] [has_one α] : ∀ m n : pos_num, (sub' m n : α) = m - n
847849
| a 1 := by rw [sub'_one, num.cast_to_znum,
848850
← num.cast_to_nat, pred'_to_nat, ← nat.sub_one];

src/data/rat/basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ theorem coe_int_eq_mk : ∀ (z : ℤ), ↑z = z /. 1
577577
induction n with n IH, {refl},
578578
show -(n + 1 + 1 : ℚ) = -[1+ n.succ] /. 1,
579579
rw [neg_add, IH],
580-
simpa [show -1 = (-1) /. 1, from rfl]
580+
simp [show -1 = (-1) /. 1, from rfl],
581581
end
582582

583583
theorem mk_eq_div (n d : ℤ) : n /. d = ((n : ℚ) / d) :=

src/data/string/basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ instance decidable_lt : @decidable_rel string (<) := by apply_instance -- short-
3636
intros,
3737
induction s₁ with a s₁ IH generalizing p₁ p₂ s₂;
3838
cases s₂ with b s₂; rw ltb; simp [iterator.has_next],
39-
{ exact iff_of_false bool.ff_ne_tt (lt_irrefl _) },
39+
{ refl, },
4040
{ exact iff_of_true rfl list.lex.nil },
4141
{ exact iff_of_false bool.ff_ne_tt (not_lt_of_lt list.lex.nil) },
4242
{ dsimp [iterator.has_next,

src/group_theory/free_group.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def free_group_unit_equiv_int : free_group unit ≃ ℤ :=
648648
right_inv :=
649649
λ x, int.induction_on x (by simp)
650650
(λ i ih, by simp at ih; simp [gpow_add, ih])
651-
(λ i ih, by simp at ih; simp [gpow_add, ih, sub_eq_add_neg])
651+
(λ i ih, by simp at ih; simp [gpow_add, ih, sub_eq_add_neg, -int.add_minus_one])
652652
}
653653

654654
section category

src/order/basic.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ preorder, order, partial order, linear order, monotone, strictly monotone
5656
universes u v w
5757
variables {α : Type u} {β : Type v} {γ : Type w} {r : α → α → Prop}
5858

59+
@[simp] lemma lt_self_iff_false [preorder α] (a : α) : a < a ↔ false :=
60+
by simp [lt_irrefl a]
61+
5962
theorem preorder.ext {α} {A B : preorder α}
6063
(H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B :=
6164
begin

0 commit comments

Comments
 (0)