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

Commit 5d0960b

Browse files
committed
feat(data/int/basic): add three lemmas about ints, nats and int_nat_abs (#12380)
[Zulip discussion](https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there.20code.20for.20X.3F/topic/int.2Eto_nat_eq_zero)
1 parent cdb69d5 commit 5d0960b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/data/int/basic.lean

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,11 @@ le_iff_le_iff_lt_iff_lt.1 to_nat_le
11601160
@[simp]lemma le_to_nat_iff {n : ℕ} {z : ℤ} (h : 0 ≤ z) : n ≤ z.to_nat ↔ (n : ℤ) ≤ z :=
11611161
by rw [←int.coe_nat_le_coe_nat_iff, int.to_nat_of_nonneg h]
11621162

1163+
@[simp]
1164+
lemma coe_nat_nonpos_iff {n : ℕ} : (n : ℤ) ≤ 0 ↔ n = 0 :=
1165+
⟨ λ h, le_antisymm (int.coe_nat_le.mp (h.trans int.coe_nat_zero.le)) n.zero_le,
1166+
λ h, (coe_nat_eq_zero.mpr h).le⟩
1167+
11631168
theorem to_nat_le_to_nat {a b : ℤ} (h : a ≤ b) : to_nat a ≤ to_nat b :=
11641169
by rw to_nat_le; exact le_trans h (le_to_nat b)
11651170

@@ -1215,9 +1220,22 @@ theorem mem_to_nat' : ∀ (a : ℤ) (n : ℕ), n ∈ to_nat' a ↔ a = n
12151220
| -[1+ m] n := by split; intro h; cases h
12161221

12171222
lemma to_nat_of_nonpos : ∀ {z : ℤ}, z ≤ 0 → z.to_nat = 0
1218-
| (0 : ℕ) := λ _, rfl
1219-
| (n + 1 : ℕ) := λ h, (h.not_lt (by { exact_mod_cast nat.succ_pos n })).elim
1220-
| (-[1+ n]) := λ _, rfl
1223+
| 0 _ := rfl
1224+
| (n + 1 : ℕ) h := (h.not_lt (coe_nat_succ_pos _)).elim
1225+
| -[1+ n] _ := rfl
1226+
1227+
@[simp]
1228+
lemma to_nat_neg_nat : ∀ (n : ℕ), (-(n : ℤ)).to_nat = 0
1229+
| 0 := rfl
1230+
| (n + 1) := rfl
1231+
1232+
@[simp]
1233+
lemma to_nat_eq_zero : ∀ {n : ℤ}, n.to_nat = 0 ↔ n ≤ 0
1234+
| (n : ℕ) := calc _ ↔ (n = 0) : ⟨(to_nat_coe_nat n).symm.trans, (to_nat_coe_nat n).trans⟩
1235+
... ↔ _ : coe_nat_nonpos_iff.symm
1236+
| -[1+ n] := show ((-((n : ℤ) + 1)).to_nat = 0) ↔ (-(n + 1) : ℤ) ≤ 0, from
1237+
calc _ ↔ true : ⟨λ _, trivial, λ h, to_nat_neg_nat _⟩
1238+
... ↔ _ : ⟨λ h, neg_nonpos_of_nonneg (coe_zero_le _), λ _, trivial⟩
12211239

12221240
/-! ### units -/
12231241

0 commit comments

Comments
 (0)