@@ -1160,6 +1160,11 @@ le_iff_le_iff_lt_iff_lt.1 to_nat_le
1160
1160
@[simp] lemma le_to_nat_iff {n : ℕ} {z : ℤ} (h : 0 ≤ z) : n ≤ z.to_nat ↔ (n : ℤ) ≤ z :=
1161
1161
by rw [←int.coe_nat_le_coe_nat_iff, int.to_nat_of_nonneg h]
1162
1162
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
+
1163
1168
theorem to_nat_le_to_nat {a b : ℤ} (h : a ≤ b) : to_nat a ≤ to_nat b :=
1164
1169
by rw to_nat_le; exact le_trans h (le_to_nat b)
1165
1170
@@ -1215,9 +1220,22 @@ theorem mem_to_nat' : ∀ (a : ℤ) (n : ℕ), n ∈ to_nat' a ↔ a = n
1215
1220
| -[1 + m] n := by split; intro h; cases h
1216
1221
1217
1222
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⟩
1221
1239
1222
1240
/-! ### units -/
1223
1241
0 commit comments