Module docstring
{"# Further lemmas about Int relying on omega automation.
","### miscellaneous lemmas ","### toNat ","### natAbs ","### min and max ","### bmod "}
{"# Further lemmas about Int relying on omega automation.
","### miscellaneous lemmas ","### toNat ","### natAbs ","### min and max ","### bmod "}
Int.natCast_le_zero
theorem
: {n : Nat} → (n : Int) ≤ 0 ↔ n = 0
@[simp] theorem natCast_le_zero : {n : Nat} → (n : Int) ≤ 0 ↔ n = 0 := by omega
Int.sub_eq_iff_eq_add
theorem
{b a c : Int} : a - b = c ↔ a = c + b
protected theorem sub_eq_iff_eq_add {b a c : Int} : a - b = c ↔ a = c + b := by omega
Int.sub_eq_iff_eq_add'
theorem
{b a c : Int} : a - b = c ↔ a = b + c
protected theorem sub_eq_iff_eq_add' {b a c : Int} : a - b = c ↔ a = b + c := by omega
Int.neg_nonpos_iff
theorem
(i : Int) : -i ≤ 0 ↔ 0 ≤ i
@[simp] protected theorem neg_nonpos_iff (i : Int) : -i ≤ 0 ↔ 0 ≤ i := by omega
Int.zero_le_ofNat
theorem
(n : Nat) : 0 ≤ ((no_index (OfNat.ofNat n)) : Int)
@[simp] theorem zero_le_ofNat (n : Nat) : 0 ≤ ((no_index (OfNat.ofNat n)) : Int) :=
ofNat_nonneg _
Int.neg_natCast_le_natCast
theorem
(n m : Nat) : -(n : Int) ≤ (m : Int)
@[simp] theorem neg_natCast_le_natCast (n m : Nat) : -(n : Int) ≤ (m : Int) :=
Int.le_trans (by simp) (ofNat_zero_le m)
Int.neg_natCast_le_ofNat
theorem
(n m : Nat) : -(n : Int) ≤ (no_index (OfNat.ofNat m))
@[simp] theorem neg_natCast_le_ofNat (n m : Nat) : -(n : Int) ≤ (no_index (OfNat.ofNat m)) :=
Int.le_trans (by simp) (ofNat_zero_le m)
Int.neg_ofNat_le_ofNat
theorem
(n m : Nat) : -(no_index (OfNat.ofNat n)) ≤ (no_index (OfNat.ofNat m))
@[simp] theorem neg_ofNat_le_ofNat (n m : Nat) : -(no_index (OfNat.ofNat n)) ≤ (no_index (OfNat.ofNat m)) :=
Int.le_trans (by simp) (ofNat_zero_le m)
Int.neg_ofNat_le_natCast
theorem
(n m : Nat) : -(no_index (OfNat.ofNat n)) ≤ (m : Int)
@[simp] theorem neg_ofNat_le_natCast (n m : Nat) : -(no_index (OfNat.ofNat n)) ≤ (m : Int) :=
Int.le_trans (by simp) (ofNat_zero_le m)
Int.neg_lt_self_iff
theorem
{n : Int} : -n < n ↔ 0 < n
theorem neg_lt_self_iff {n : Int} : -n < n ↔ 0 < n := by
omega
Int.toNat_sub'
theorem
(a : Int) (b : Nat) : (a - b).toNat = a.toNat - b
@[simp] theorem toNat_sub' (a : Int) (b : Nat) : (a - b).toNat = a.toNat - b := by
symm
simp only [Int.toNat]
split <;> rename_i x a
· simp only [Int.ofNat_eq_coe]
split <;> rename_i y b h
· simp at h
omega
· simp [Int.negSucc_eq] at h
omega
· simp only [Nat.zero_sub]
split <;> rename_i y b h
· simp [Int.negSucc_eq] at h
omega
· rfl
Int.toNat_sub_max_self
theorem
(a : Int) : (a - max a 0).toNat = 0
@[simp] theorem toNat_sub_max_self (a : Int) : (a - max a 0).toNat = 0 := by
simp [toNat]
split <;> simp_all <;> omega
Int.toNat_sub_self_max
theorem
(a : Int) : (a - max 0 a).toNat = 0
@[simp] theorem toNat_sub_self_max (a : Int) : (a - max 0 a).toNat = 0 := by
simp [toNat]
split <;> simp_all <;> omega
Int.toNat_eq_zero
theorem
: ∀ {n : Int}, n.toNat = 0 ↔ n ≤ 0
@[simp] theorem toNat_eq_zero : ∀ {n : Int}, n.toNat = 0 ↔ n ≤ 0 := by omega
Int.toNat_le
theorem
{m : Int} {n : Nat} : m.toNat ≤ n ↔ m ≤ n
@[simp] theorem toNat_le {m : Int} {n : Nat} : m.toNat ≤ n ↔ m ≤ n := by omega
Int.toNat_lt'
theorem
{m : Int} {n : Nat} (hn : 0 < n) : m.toNat < n ↔ m < n
@[simp] theorem toNat_lt' {m : Int} {n : Nat} (hn : 0 < n) : m.toNat < n ↔ m < n := by omega
Int.pos_iff_toNat_pos
theorem
{n : Int} : 0 < n ↔ 0 < n.toNat
theorem pos_iff_toNat_pos {n : Int} : 0 < n ↔ 0 < n.toNat := by
omega
Int.ofNat_toNat_eq_self
theorem
{a : Int} : a.toNat = a ↔ 0 ≤ a
theorem ofNat_toNat_eq_self {a : Int} : a.toNat = a ↔ 0 ≤ a := by omega
Int.toNat_le_toNat
theorem
{n m : Int} (h : n ≤ m) : n.toNat ≤ m.toNat
theorem toNat_le_toNat {n m : Int} (h : n ≤ m) : n.toNat ≤ m.toNat := by omega
Int.toNat_lt_toNat
theorem
{n m : Int} (hn : 0 < m) : n.toNat < m.toNat ↔ n < m
theorem toNat_lt_toNat {n m : Int} (hn : 0 < m) : n.toNat < m.toNat ↔ n < m := by omega
Int.min_assoc
theorem
: ∀ (a b c : Int), min (min a b) c = min a (min b c)
Int.instAssociativeNatMin
instance
: Std.Associative (α := Nat) min
instance : Std.Associative (α := Nat) min := ⟨Nat.min_assoc⟩
Int.min_self_assoc
theorem
{m n : Int} : min m (min m n) = min m n
@[simp] protected theorem min_self_assoc {m n : Int} : min m (min m n) = min m n := by
rw [← Int.min_assoc, Int.min_self]
Int.min_self_assoc'
theorem
{m n : Int} : min n (min m n) = min n m
@[simp] protected theorem min_self_assoc' {m n : Int} : min n (min m n) = min n m := by
rw [Int.min_comm m n, ← Int.min_assoc, Int.min_self]
Int.max_assoc
theorem
(a b c : Int) : max (max a b) c = max a (max b c)
Int.instAssociativeNatMax
instance
: Std.Associative (α := Nat) max
instance : Std.Associative (α := Nat) max := ⟨Nat.max_assoc⟩
Int.max_self_assoc
theorem
{m n : Int} : max m (max m n) = max m n
@[simp] protected theorem max_self_assoc {m n : Int} : max m (max m n) = max m n := by
rw [← Int.max_assoc, Int.max_self]
Int.max_self_assoc'
theorem
{m n : Int} : max n (max m n) = max n m
@[simp] protected theorem max_self_assoc' {m n : Int} : max n (max m n) = max n m := by
rw [Int.max_comm m n, ← Int.max_assoc, Int.max_self]
Int.max_min_distrib_left
theorem
(a b c : Int) : max a (min b c) = min (max a b) (max a c)
Int.min_max_distrib_left
theorem
(a b c : Int) : min a (max b c) = max (min a b) (min a c)
Int.max_min_distrib_right
theorem
(a b c : Int) : max (min a b) c = min (max a c) (max b c)
Int.min_max_distrib_right
theorem
(a b c : Int) : min (max a b) c = max (min a c) (min b c)
Int.sub_min_sub_right
theorem
(a b c : Int) : min (a - c) (b - c) = min a b - c
protected theorem sub_min_sub_right (a b c : Int) : min (a - c) (b - c) = min a b - c := by omega
Int.sub_max_sub_right
theorem
(a b c : Int) : max (a - c) (b - c) = max a b - c
protected theorem sub_max_sub_right (a b c : Int) : max (a - c) (b - c) = max a b - c := by omega
Int.sub_min_sub_left
theorem
(a b c : Int) : min (a - b) (a - c) = a - max b c
protected theorem sub_min_sub_left (a b c : Int) : min (a - b) (a - c) = a - max b c := by omega
Int.sub_max_sub_left
theorem
(a b c : Int) : max (a - b) (a - c) = a - min b c
protected theorem sub_max_sub_left (a b c : Int) : max (a - b) (a - c) = a - min b c := by omega
Int.bmod_neg_iff
theorem
{m : Nat} {x : Int} (h2 : -m ≤ x) (h1 : x < m) : (x.bmod m) < 0 ↔ (-(m / 2) ≤ x ∧ x < 0) ∨ ((m + 1) / 2 ≤ x)
theorem bmod_neg_iff {m : Nat} {x : Int} (h2 : -m ≤ x) (h1 : x < m) :
(x.bmod m) < 0 ↔ (-(m / 2) ≤ x ∧ x < 0) ∨ ((m + 1) / 2 ≤ x) := by
simp only [Int.bmod_def]
by_cases xpos : 0 ≤ x
· rw [Int.emod_eq_of_lt xpos (by omega)]; omega
· rw [Int.add_emod_self.symm, Int.emod_eq_of_lt (by omega) (by omega)]; omega
Int.bmod_eq_self_of_le
theorem
{n : Int} {m : Nat} (hn' : -(m / 2) ≤ n) (hn : n < (m + 1) / 2) : n.bmod m = n
theorem bmod_eq_self_of_le {n : Int} {m : Nat} (hn' : -(m / 2) ≤ n) (hn : n < (m + 1) / 2) :
n.bmod m = n := by
rw [← Int.sub_eq_zero]
have := le_bmod (x := n) (m := m) (by omega)
have := bmod_lt (x := n) (m := m) (by omega)
apply eq_zero_of_dvd_of_natAbs_lt_natAbs Int.dvd_bmod_sub_self
omega
Int.bmod_bmod_of_dvd
theorem
{a : Int} {n m : Nat} (hnm : n ∣ m) : (a.bmod m).bmod n = a.bmod n
theorem bmod_bmod_of_dvd {a : Int} {n m : Nat} (hnm : n ∣ m) :
(a.bmod m).bmod n = a.bmod n := by
rw [← Int.sub_eq_iff_eq_add.2 (bmod_add_bdiv a m).symm]
obtain ⟨k, rfl⟩ := hnm
simp [Int.mul_assoc]