2014-12-05 22:03:24 +00:00
|
|
|
|
/-
|
|
|
|
|
Copyright (c) 2014 Floris van Doorn. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
Authors: Floris van Doorn, Jeremy Avigad
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
The order relation on the integers. We show that int is an instance of linear_comm_ordered_ring
|
|
|
|
|
and transfer the results.
|
2014-12-05 22:03:24 +00:00
|
|
|
|
-/
|
2014-12-26 21:25:05 +00:00
|
|
|
|
import .basic algebra.ordered_ring
|
2014-12-23 22:34:16 +00:00
|
|
|
|
open nat
|
2015-10-12 03:35:45 +00:00
|
|
|
|
open algebra
|
2014-09-03 23:00:38 +00:00
|
|
|
|
open decidable
|
2014-10-02 00:51:17 +00:00
|
|
|
|
open int eq.ops
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
|
|
|
|
namespace int
|
|
|
|
|
|
2015-02-11 20:49:27 +00:00
|
|
|
|
private definition nonneg (a : ℤ) : Prop := int.cases_on a (take n, true) (take n, false)
|
2015-10-07 23:44:47 +00:00
|
|
|
|
protected definition le (a b : ℤ) : Prop := nonneg (b - a)
|
2014-12-22 19:21:22 +00:00
|
|
|
|
|
2015-10-07 23:44:47 +00:00
|
|
|
|
definition int_has_le [instance] [reducible] [priority int.prio]: has_le int :=
|
|
|
|
|
has_le.mk int.le
|
|
|
|
|
|
|
|
|
|
protected definition lt (a b : ℤ) : Prop := (a + 1) ≤ b
|
|
|
|
|
|
|
|
|
|
definition int_has_lt [instance] [reducible] [priority int.prio]: has_lt int :=
|
|
|
|
|
has_lt.mk int.lt
|
2014-12-22 19:21:22 +00:00
|
|
|
|
|
2015-02-24 22:09:20 +00:00
|
|
|
|
local attribute nonneg [reducible]
|
2015-02-11 20:49:27 +00:00
|
|
|
|
private definition decidable_nonneg [instance] (a : ℤ) : decidable (nonneg a) := int.cases_on a _ _
|
2014-12-22 19:21:22 +00:00
|
|
|
|
definition decidable_le [instance] (a b : ℤ) : decidable (a ≤ b) := decidable_nonneg _
|
|
|
|
|
definition decidable_lt [instance] (a b : ℤ) : decidable (a < b) := decidable_nonneg _
|
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
private theorem nonneg.elim {a : ℤ} : nonneg a → ∃n : ℕ, a = n :=
|
2015-07-24 15:56:18 +00:00
|
|
|
|
int.cases_on a (take n H, exists.intro n rfl) (take n', false.elim)
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
private theorem nonneg_or_nonneg_neg (a : ℤ) : nonneg a ∨ nonneg (-a) :=
|
2015-02-11 20:49:27 +00:00
|
|
|
|
int.cases_on a (take n, or.inl trivial) (take n, or.inr trivial)
|
2014-12-26 21:25:05 +00:00
|
|
|
|
|
|
|
|
|
theorem le.intro {a b : ℤ} {n : ℕ} (H : a + n = b) : a ≤ b :=
|
2015-10-07 23:44:47 +00:00
|
|
|
|
have n = b - a, from eq_add_neg_of_add_eq (begin rewrite [add.comm, H] end), -- !add.comm ▸ H),
|
2015-07-24 15:56:18 +00:00
|
|
|
|
show nonneg (b - a), from this ▸ trivial
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem le.elim {a b : ℤ} (H : a ≤ b) : ∃n : ℕ, a + n = b :=
|
|
|
|
|
obtain (n : ℕ) (H1 : b - a = n), from nonneg.elim H,
|
2015-07-18 09:28:53 +00:00
|
|
|
|
exists.intro n (!add.comm ▸ iff.mpr !add_eq_iff_eq_add_neg (H1⁻¹))
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem le_total (a b : ℤ) : a ≤ b ∨ b ≤ a :=
|
2015-07-24 15:56:18 +00:00
|
|
|
|
or.imp_right
|
2014-12-26 21:25:05 +00:00
|
|
|
|
(assume H : nonneg (-(b - a)),
|
2015-07-24 15:56:18 +00:00
|
|
|
|
have -(b - a) = a - b, from !neg_sub,
|
2015-09-12 14:00:34 +00:00
|
|
|
|
show nonneg (a - b), from this ▸ H)
|
2015-07-24 15:56:18 +00:00
|
|
|
|
(nonneg_or_nonneg_neg (b - a))
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
2015-05-25 11:52:20 +00:00
|
|
|
|
theorem of_nat_le_of_nat_of_le {m n : ℕ} (H : #nat m ≤ n) : of_nat m ≤ of_nat n :=
|
2015-02-25 19:14:57 +00:00
|
|
|
|
obtain (k : ℕ) (Hk : m + k = n), from nat.le.elim H,
|
2015-05-25 10:00:41 +00:00
|
|
|
|
le.intro (Hk ▸ (of_nat_add m k)⁻¹)
|
2015-02-25 19:14:57 +00:00
|
|
|
|
|
|
|
|
|
theorem le_of_of_nat_le_of_nat {m n : ℕ} (H : of_nat m ≤ of_nat n) : (#nat m ≤ n) :=
|
|
|
|
|
obtain (k : ℕ) (Hk : of_nat m + of_nat k = of_nat n), from le.elim H,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have m + k = n, from of_nat.inj (of_nat_add m k ⬝ Hk),
|
|
|
|
|
nat.le.intro this
|
2015-02-25 19:14:57 +00:00
|
|
|
|
|
2015-09-12 14:00:34 +00:00
|
|
|
|
theorem of_nat_le_of_nat_iff (m n : ℕ) : of_nat m ≤ of_nat n ↔ m ≤ n :=
|
2015-05-25 11:52:20 +00:00
|
|
|
|
iff.intro le_of_of_nat_le_of_nat of_nat_le_of_nat_of_le
|
2014-12-26 21:25:05 +00:00
|
|
|
|
|
|
|
|
|
theorem lt_add_succ (a : ℤ) (n : ℕ) : a < a + succ n :=
|
|
|
|
|
le.intro (show a + 1 + n = a + succ n, from
|
|
|
|
|
calc
|
|
|
|
|
a + 1 + n = a + (1 + n) : add.assoc
|
2015-10-22 20:36:45 +00:00
|
|
|
|
... = a + (n + 1) : by rewrite (int.add_comm 1 n)
|
2014-12-26 21:25:05 +00:00
|
|
|
|
... = a + succ n : rfl)
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem lt.intro {a b : ℤ} {n : ℕ} (H : a + succ n = b) : a < b :=
|
|
|
|
|
H ▸ lt_add_succ a n
|
|
|
|
|
|
|
|
|
|
theorem lt.elim {a b : ℤ} (H : a < b) : ∃n : ℕ, a + succ n = b :=
|
|
|
|
|
obtain (n : ℕ) (Hn : a + 1 + n = b), from le.elim H,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have a + succ n = b, from
|
2014-12-26 21:25:05 +00:00
|
|
|
|
calc
|
2015-10-22 20:36:45 +00:00
|
|
|
|
a + succ n = a + 1 + n : by rewrite [add.assoc, int.add_comm 1 n]
|
2015-07-22 17:13:19 +00:00
|
|
|
|
... = b : Hn,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
exists.intro n this
|
2014-12-26 21:25:05 +00:00
|
|
|
|
|
2015-09-12 14:00:34 +00:00
|
|
|
|
theorem of_nat_lt_of_nat_iff (n m : ℕ) : of_nat n < of_nat m ↔ n < m :=
|
2014-12-26 21:25:05 +00:00
|
|
|
|
calc
|
|
|
|
|
of_nat n < of_nat m ↔ of_nat n + 1 ≤ of_nat m : iff.refl
|
2015-05-15 00:18:29 +00:00
|
|
|
|
... ↔ of_nat (nat.succ n) ≤ of_nat m : of_nat_succ n ▸ !iff.refl
|
2015-09-12 14:00:34 +00:00
|
|
|
|
... ↔ nat.succ n ≤ m : of_nat_le_of_nat_iff
|
2014-12-26 21:25:05 +00:00
|
|
|
|
... ↔ n < m : iff.symm (lt_iff_succ_le _ _)
|
|
|
|
|
|
2015-02-25 19:14:57 +00:00
|
|
|
|
theorem lt_of_of_nat_lt_of_nat {m n : ℕ} (H : of_nat m < of_nat n) : #nat m < n :=
|
2015-09-12 14:00:34 +00:00
|
|
|
|
iff.mp !of_nat_lt_of_nat_iff H
|
2015-02-25 19:14:57 +00:00
|
|
|
|
|
2015-05-25 11:52:20 +00:00
|
|
|
|
theorem of_nat_lt_of_nat_of_lt {m n : ℕ} (H : #nat m < n) : of_nat m < of_nat n :=
|
2015-09-12 14:00:34 +00:00
|
|
|
|
iff.mpr !of_nat_lt_of_nat_iff H
|
2015-02-25 19:14:57 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
/- show that the integers form an ordered additive group -/
|
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem le_refl (a : ℤ) : a ≤ a :=
|
2014-12-26 21:25:05 +00:00
|
|
|
|
le.intro (add_zero a)
|
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem le_trans {a b c : ℤ} (H1 : a ≤ b) (H2 : b ≤ c) : a ≤ c :=
|
2014-12-26 21:25:05 +00:00
|
|
|
|
obtain (n : ℕ) (Hn : a + n = b), from le.elim H1,
|
|
|
|
|
obtain (m : ℕ) (Hm : b + m = c), from le.elim H2,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have a + of_nat (n + m) = c, from
|
2014-08-23 00:56:25 +00:00
|
|
|
|
calc
|
2015-05-25 10:00:41 +00:00
|
|
|
|
a + of_nat (n + m) = a + (of_nat n + m) : {of_nat_add n m}
|
2014-12-17 18:32:38 +00:00
|
|
|
|
... = a + n + m : (add.assoc a n m)⁻¹
|
2014-08-23 00:56:25 +00:00
|
|
|
|
... = b + m : {Hn}
|
|
|
|
|
... = c : Hm,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
le.intro this
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem le_antisymm : ∀ {a b : ℤ}, a ≤ b → b ≤ a → a = b :=
|
2015-03-28 19:50:28 +00:00
|
|
|
|
take a b : ℤ, assume (H₁ : a ≤ b) (H₂ : b ≤ a),
|
|
|
|
|
obtain (n : ℕ) (Hn : a + n = b), from le.elim H₁,
|
|
|
|
|
obtain (m : ℕ) (Hm : b + m = a), from le.elim H₂,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have a + of_nat (n + m) = a + 0, from
|
2014-08-23 00:56:25 +00:00
|
|
|
|
calc
|
2015-10-09 19:47:55 +00:00
|
|
|
|
a + of_nat (n + m) = a + (of_nat n + m) : by rewrite of_nat_add
|
|
|
|
|
... = a + n + m : by rewrite add.assoc
|
|
|
|
|
... = b + m : by rewrite Hn
|
|
|
|
|
... = a : by rewrite Hm
|
|
|
|
|
... = a + 0 : by rewrite add_zero,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have of_nat (n + m) = of_nat 0, from add.left_cancel this,
|
|
|
|
|
have n + m = 0, from of_nat.inj this,
|
2015-10-12 03:29:31 +00:00
|
|
|
|
assert n = 0, from nat.eq_zero_of_add_eq_zero_right this,
|
2014-08-23 00:56:25 +00:00
|
|
|
|
show a = b, from
|
|
|
|
|
calc
|
2015-10-12 03:29:31 +00:00
|
|
|
|
a = a + 0 : add_zero
|
|
|
|
|
... = a + n : by rewrite this
|
|
|
|
|
... = b : Hn
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem lt_irrefl (a : ℤ) : ¬ a < a :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(suppose a < a,
|
|
|
|
|
obtain (n : ℕ) (Hn : a + succ n = a), from lt.elim this,
|
|
|
|
|
have a + succ n = a + 0, from
|
2015-07-24 15:56:18 +00:00
|
|
|
|
Hn ⬝ !add_zero⁻¹,
|
|
|
|
|
!succ_ne_zero (of_nat.inj (add.left_cancel this)))
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem ne_of_lt {a b : ℤ} (H : a < b) : a ≠ b :=
|
|
|
|
|
(suppose a = b, absurd (this ▸ H) (int.lt_irrefl b))
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem le_of_lt {a b : ℤ} (H : a < b) : a ≤ b :=
|
|
|
|
|
obtain (n : ℕ) (Hn : a + succ n = b), from lt.elim H,
|
|
|
|
|
le.intro Hn
|
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem lt_iff_le_and_ne (a b : ℤ) : a < b ↔ (a ≤ b ∧ a ≠ b) :=
|
2014-12-26 21:25:05 +00:00
|
|
|
|
iff.intro
|
2015-10-22 20:36:45 +00:00
|
|
|
|
(assume H, and.intro (le_of_lt H) (int.ne_of_lt H))
|
2014-12-26 21:25:05 +00:00
|
|
|
|
(assume H,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have a ≤ b, from and.elim_left H,
|
|
|
|
|
have a ≠ b, from and.elim_right H,
|
|
|
|
|
obtain (n : ℕ) (Hn : a + n = b), from le.elim `a ≤ b`,
|
|
|
|
|
have n ≠ 0, from (assume H' : n = 0, `a ≠ b` (!add_zero ▸ H' ▸ Hn)),
|
|
|
|
|
obtain (k : ℕ) (Hk : n = nat.succ k), from nat.exists_eq_succ_of_ne_zero this,
|
2014-12-26 21:25:05 +00:00
|
|
|
|
lt.intro (Hk ▸ Hn))
|
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem le_iff_lt_or_eq (a b : ℤ) : a ≤ b ↔ (a < b ∨ a = b) :=
|
2014-12-26 21:25:05 +00:00
|
|
|
|
iff.intro
|
|
|
|
|
(assume H,
|
|
|
|
|
by_cases
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(suppose a = b, or.inr this)
|
|
|
|
|
(suppose a ≠ b,
|
2014-12-26 21:25:05 +00:00
|
|
|
|
obtain (n : ℕ) (Hn : a + n = b), from le.elim H,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have n ≠ 0, from (assume H' : n = 0, `a ≠ b` (!add_zero ▸ H' ▸ Hn)),
|
|
|
|
|
obtain (k : ℕ) (Hk : n = nat.succ k), from nat.exists_eq_succ_of_ne_zero this,
|
2014-12-26 21:25:05 +00:00
|
|
|
|
or.inl (lt.intro (Hk ▸ Hn))))
|
|
|
|
|
(assume H,
|
|
|
|
|
or.elim H
|
|
|
|
|
(assume H1, le_of_lt H1)
|
2015-10-22 20:36:45 +00:00
|
|
|
|
(assume H1, H1 ▸ !int.le_refl))
|
2014-08-23 00:56:25 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem lt_succ (a : ℤ) : a < a + 1 :=
|
2015-10-22 20:36:45 +00:00
|
|
|
|
int.le_refl (a + 1)
|
2014-12-26 21:25:05 +00:00
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem add_le_add_left {a b : ℤ} (H : a ≤ b) (c : ℤ) : c + a ≤ c + b :=
|
2014-12-26 21:25:05 +00:00
|
|
|
|
obtain (n : ℕ) (Hn : a + n = b), from le.elim H,
|
2014-08-23 00:56:25 +00:00
|
|
|
|
have H2 : c + a + n = c + b, from
|
|
|
|
|
calc
|
2014-12-17 18:32:38 +00:00
|
|
|
|
c + a + n = c + (a + n) : add.assoc c a n
|
2014-08-23 00:56:25 +00:00
|
|
|
|
... = c + b : {Hn},
|
2014-12-26 21:25:05 +00:00
|
|
|
|
le.intro H2
|
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem add_lt_add_left {a b : ℤ} (H : a < b) (c : ℤ) : c + a < c + b :=
|
2015-06-01 01:39:59 +00:00
|
|
|
|
let H' := le_of_lt H in
|
2015-10-22 20:36:45 +00:00
|
|
|
|
(iff.mpr (int.lt_iff_le_and_ne _ _)) (and.intro (int.add_le_add_left H' _)
|
2015-05-29 03:34:57 +00:00
|
|
|
|
(take Heq, let Heq' := add_left_cancel Heq in
|
2015-10-22 20:36:45 +00:00
|
|
|
|
!int.lt_irrefl (Heq' ▸ H)))
|
2015-05-29 03:34:57 +00:00
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem mul_nonneg {a b : ℤ} (Ha : 0 ≤ a) (Hb : 0 ≤ b) : 0 ≤ a * b :=
|
2014-12-26 21:25:05 +00:00
|
|
|
|
obtain (n : ℕ) (Hn : 0 + n = a), from le.elim Ha,
|
|
|
|
|
obtain (m : ℕ) (Hm : 0 + m = b), from le.elim Hb,
|
|
|
|
|
le.intro
|
|
|
|
|
(eq.symm
|
|
|
|
|
(calc
|
2015-10-09 19:47:55 +00:00
|
|
|
|
a * b = (0 + n) * b : by rewrite Hn
|
|
|
|
|
... = n * b : by rewrite zero_add
|
|
|
|
|
... = n * (0 + m) : by rewrite Hm
|
|
|
|
|
... = n * m : by rewrite zero_add
|
|
|
|
|
... = 0 + n * m : by rewrite zero_add))
|
2014-12-26 21:25:05 +00:00
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem mul_pos {a b : ℤ} (Ha : 0 < a) (Hb : 0 < b) : 0 < a * b :=
|
2015-05-15 00:18:29 +00:00
|
|
|
|
obtain (n : ℕ) (Hn : 0 + nat.succ n = a), from lt.elim Ha,
|
|
|
|
|
obtain (m : ℕ) (Hm : 0 + nat.succ m = b), from lt.elim Hb,
|
2014-12-26 21:25:05 +00:00
|
|
|
|
lt.intro
|
|
|
|
|
(eq.symm
|
|
|
|
|
(calc
|
2015-10-09 19:47:55 +00:00
|
|
|
|
a * b = (0 + nat.succ n) * b : by rewrite Hn
|
|
|
|
|
... = nat.succ n * b : by rewrite zero_add
|
|
|
|
|
... = nat.succ n * (0 + nat.succ m) : by rewrite Hm
|
|
|
|
|
... = nat.succ n * nat.succ m : by rewrite zero_add
|
|
|
|
|
... = of_nat (nat.succ n * nat.succ m) : by rewrite of_nat_mul
|
|
|
|
|
... = of_nat (nat.succ n * m + nat.succ n) : by rewrite nat.mul_succ
|
|
|
|
|
... = of_nat (nat.succ (nat.succ n * m + n)) : by rewrite nat.add_succ
|
|
|
|
|
... = 0 + nat.succ (nat.succ n * m + n) : by rewrite zero_add))
|
2014-12-26 21:25:05 +00:00
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem zero_lt_one : (0 : ℤ) < 1 := trivial
|
2015-05-29 03:34:57 +00:00
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem not_le_of_gt {a b : ℤ} (H : a < b) : ¬ b ≤ a :=
|
2015-05-29 03:34:57 +00:00
|
|
|
|
assume Hba,
|
2015-10-22 20:36:45 +00:00
|
|
|
|
let Heq := int.le_antisymm (le_of_lt H) Hba in
|
|
|
|
|
!int.lt_irrefl (Heq ▸ H)
|
2015-05-29 03:34:57 +00:00
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem lt_of_lt_of_le {a b c : ℤ} (Hab : a < b) (Hbc : b ≤ c) : a < c :=
|
2015-05-29 03:34:57 +00:00
|
|
|
|
let Hab' := le_of_lt Hab in
|
2015-10-22 20:36:45 +00:00
|
|
|
|
let Hac := int.le_trans Hab' Hbc in
|
|
|
|
|
(iff.mpr !int.lt_iff_le_and_ne) (and.intro Hac
|
|
|
|
|
(assume Heq, int.not_le_of_gt (Heq ▸ Hab) Hbc))
|
2015-05-29 03:34:57 +00:00
|
|
|
|
|
2015-10-22 20:36:45 +00:00
|
|
|
|
protected theorem lt_of_le_of_lt {a b c : ℤ} (Hab : a ≤ b) (Hbc : b < c) : a < c :=
|
2015-05-29 03:34:57 +00:00
|
|
|
|
let Hbc' := le_of_lt Hbc in
|
2015-10-22 20:36:45 +00:00
|
|
|
|
let Hac := int.le_trans Hab Hbc' in
|
|
|
|
|
(iff.mpr !int.lt_iff_le_and_ne) (and.intro Hac
|
|
|
|
|
(assume Heq, int.not_le_of_gt (Heq⁻¹ ▸ Hbc) Hab))
|
2015-05-29 03:34:57 +00:00
|
|
|
|
|
2015-10-09 21:50:17 +00:00
|
|
|
|
protected definition linear_ordered_comm_ring [reducible] [trans_instance] :
|
2015-01-26 17:01:19 +00:00
|
|
|
|
algebra.linear_ordered_comm_ring int :=
|
2015-10-07 23:44:47 +00:00
|
|
|
|
⦃algebra.linear_ordered_comm_ring, int.integral_domain,
|
|
|
|
|
le := int.le,
|
2015-10-22 20:36:45 +00:00
|
|
|
|
le_refl := int.le_refl,
|
|
|
|
|
le_trans := @int.le_trans,
|
|
|
|
|
le_antisymm := @int.le_antisymm,
|
2015-10-07 23:44:47 +00:00
|
|
|
|
lt := int.lt,
|
2015-10-22 20:36:45 +00:00
|
|
|
|
le_of_lt := @int.le_of_lt,
|
|
|
|
|
lt_irrefl := int.lt_irrefl,
|
|
|
|
|
lt_of_lt_of_le := @int.lt_of_lt_of_le,
|
|
|
|
|
lt_of_le_of_lt := @int.lt_of_le_of_lt,
|
|
|
|
|
add_le_add_left := @int.add_le_add_left,
|
|
|
|
|
mul_nonneg := @int.mul_nonneg,
|
|
|
|
|
mul_pos := @int.mul_pos,
|
|
|
|
|
le_iff_lt_or_eq := int.le_iff_lt_or_eq,
|
|
|
|
|
le_total := int.le_total,
|
|
|
|
|
zero_ne_one := int.zero_ne_one,
|
|
|
|
|
zero_lt_one := int.zero_lt_one,
|
|
|
|
|
add_lt_add_left := @int.add_lt_add_left⦄
|
2015-10-07 23:44:47 +00:00
|
|
|
|
|
|
|
|
|
protected definition decidable_linear_ordered_comm_ring [reducible] [instance] :
|
2015-01-21 20:50:42 +00:00
|
|
|
|
algebra.decidable_linear_ordered_comm_ring int :=
|
2015-10-07 23:44:47 +00:00
|
|
|
|
⦃algebra.decidable_linear_ordered_comm_ring,
|
|
|
|
|
int.linear_ordered_comm_ring,
|
|
|
|
|
decidable_lt := decidable_lt⦄
|
2014-12-26 21:25:05 +00:00
|
|
|
|
|
|
|
|
|
/- more facts specific to int -/
|
|
|
|
|
|
2015-05-25 11:52:20 +00:00
|
|
|
|
theorem of_nat_nonneg (n : ℕ) : 0 ≤ of_nat n := trivial
|
|
|
|
|
|
|
|
|
|
theorem of_nat_pos {n : ℕ} (Hpos : #nat n > 0) : of_nat n > 0 :=
|
|
|
|
|
of_nat_lt_of_nat_of_lt Hpos
|
2014-12-26 21:25:05 +00:00
|
|
|
|
|
2015-06-10 02:46:30 +00:00
|
|
|
|
theorem of_nat_succ_pos (n : nat) : of_nat (nat.succ n) > 0 :=
|
|
|
|
|
of_nat_pos !nat.succ_pos
|
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem exists_eq_of_nat {a : ℤ} (H : 0 ≤ a) : ∃n : ℕ, a = of_nat n :=
|
|
|
|
|
obtain (n : ℕ) (H1 : 0 + of_nat n = a), from le.elim H,
|
|
|
|
|
exists.intro n (!zero_add ▸ (H1⁻¹))
|
|
|
|
|
|
|
|
|
|
theorem exists_eq_neg_of_nat {a : ℤ} (H : a ≤ 0) : ∃n : ℕ, a = -(of_nat n) :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have -a ≥ 0, from iff.mpr !neg_nonneg_iff_nonpos H,
|
|
|
|
|
obtain (n : ℕ) (Hn : -a = of_nat n), from exists_eq_of_nat this,
|
2014-12-26 21:25:05 +00:00
|
|
|
|
exists.intro n (eq_neg_of_eq_neg (Hn⁻¹))
|
|
|
|
|
|
|
|
|
|
theorem of_nat_nat_abs_of_nonneg {a : ℤ} (H : a ≥ 0) : of_nat (nat_abs a) = a :=
|
|
|
|
|
obtain (n : ℕ) (Hn : a = of_nat n), from exists_eq_of_nat H,
|
|
|
|
|
Hn⁻¹ ▸ congr_arg of_nat (nat_abs_of_nat n)
|
|
|
|
|
|
|
|
|
|
theorem of_nat_nat_abs_of_nonpos {a : ℤ} (H : a ≤ 0) : of_nat (nat_abs a) = -a :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have -a ≥ 0, from iff.mpr !neg_nonneg_iff_nonpos H,
|
2014-12-26 21:25:05 +00:00
|
|
|
|
calc
|
|
|
|
|
of_nat (nat_abs a) = of_nat (nat_abs (-a)) : nat_abs_neg
|
2015-07-21 16:10:56 +00:00
|
|
|
|
... = -a : of_nat_nat_abs_of_nonneg this
|
2014-12-26 21:25:05 +00:00
|
|
|
|
|
2015-02-25 23:18:21 +00:00
|
|
|
|
theorem of_nat_nat_abs (b : ℤ) : nat_abs b = abs b :=
|
2015-02-25 19:14:57 +00:00
|
|
|
|
or.elim (le.total 0 b)
|
|
|
|
|
(assume H : b ≥ 0, of_nat_nat_abs_of_nonneg H ⬝ (abs_of_nonneg H)⁻¹)
|
|
|
|
|
(assume H : b ≤ 0, of_nat_nat_abs_of_nonpos H ⬝ (abs_of_nonpos H)⁻¹)
|
|
|
|
|
|
2015-06-01 01:39:59 +00:00
|
|
|
|
theorem nat_abs_abs (a : ℤ) : nat_abs (abs a) = nat_abs a :=
|
|
|
|
|
abs.by_cases rfl !nat_abs_neg
|
|
|
|
|
|
2015-02-25 19:14:57 +00:00
|
|
|
|
theorem lt_of_add_one_le {a b : ℤ} (H : a + 1 ≤ b) : a < b :=
|
2015-10-07 23:44:47 +00:00
|
|
|
|
obtain (n : nat) (H1 : a + 1 + n = b), from le.elim H,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have a + succ n = b, by rewrite [-H1, add.assoc, add.comm 1],
|
|
|
|
|
lt.intro this
|
2015-02-25 19:14:57 +00:00
|
|
|
|
|
|
|
|
|
theorem add_one_le_of_lt {a b : ℤ} (H : a < b) : a + 1 ≤ b :=
|
2015-10-07 23:44:47 +00:00
|
|
|
|
obtain (n : nat) (H1 : a + succ n = b), from lt.elim H,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have a + 1 + n = b, by rewrite [-H1, add.assoc, add.comm 1],
|
|
|
|
|
le.intro this
|
2015-02-25 19:14:57 +00:00
|
|
|
|
|
2015-03-13 03:43:19 +00:00
|
|
|
|
theorem lt_add_one_of_le {a b : ℤ} (H : a ≤ b) : a < b + 1 :=
|
|
|
|
|
lt_add_of_le_of_pos H trivial
|
|
|
|
|
|
|
|
|
|
theorem le_of_lt_add_one {a b : ℤ} (H : a < b + 1) : a ≤ b :=
|
|
|
|
|
have H1 : a + 1 ≤ b + 1, from add_one_le_of_lt H,
|
|
|
|
|
le_of_add_le_add_right H1
|
|
|
|
|
|
|
|
|
|
theorem sub_one_le_of_lt {a b : ℤ} (H : a ≤ b) : a - 1 < b :=
|
2015-10-07 23:44:47 +00:00
|
|
|
|
lt_of_add_one_le (begin rewrite algebra.sub_add_cancel, exact H end)
|
2015-03-13 03:43:19 +00:00
|
|
|
|
|
|
|
|
|
theorem lt_of_sub_one_le {a b : ℤ} (H : a - 1 < b) : a ≤ b :=
|
|
|
|
|
!sub_add_cancel ▸ add_one_le_of_lt H
|
|
|
|
|
|
|
|
|
|
theorem le_sub_one_of_lt {a b : ℤ} (H : a < b) : a ≤ b - 1 :=
|
2015-10-09 19:47:55 +00:00
|
|
|
|
le_of_lt_add_one begin rewrite algebra.sub_add_cancel, exact H end
|
2015-03-13 03:43:19 +00:00
|
|
|
|
|
|
|
|
|
theorem lt_of_le_sub_one {a b : ℤ} (H : a ≤ b - 1) : a < b :=
|
|
|
|
|
!sub_add_cancel ▸ (lt_add_one_of_le H)
|
|
|
|
|
|
2015-05-15 00:18:29 +00:00
|
|
|
|
theorem sign_of_succ (n : nat) : sign (nat.succ n) = 1 :=
|
2015-02-25 19:14:57 +00:00
|
|
|
|
sign_of_pos (of_nat_pos !nat.succ_pos)
|
|
|
|
|
|
2015-06-29 05:16:58 +00:00
|
|
|
|
theorem exists_eq_neg_succ_of_nat {a : ℤ} : a < 0 → ∃m : ℕ, a = -[1+m] :=
|
2015-02-25 19:14:57 +00:00
|
|
|
|
int.cases_on a
|
2015-10-07 23:44:47 +00:00
|
|
|
|
(take (m : nat) H, absurd (of_nat_nonneg m : 0 ≤ m) (not_le_of_gt H))
|
|
|
|
|
(take (m : nat) H, exists.intro m rfl)
|
2015-02-25 19:14:57 +00:00
|
|
|
|
|
2015-06-01 01:39:59 +00:00
|
|
|
|
theorem eq_one_of_mul_eq_one_right {a b : ℤ} (H : a ≥ 0) (H' : a * b = 1) : a = 1 :=
|
2015-07-21 16:10:56 +00:00
|
|
|
|
have a * b > 0, by rewrite H'; apply trivial,
|
|
|
|
|
have b > 0, from pos_of_mul_pos_left this H,
|
|
|
|
|
have a > 0, from pos_of_mul_pos_right `a * b > 0` (le_of_lt `b > 0`),
|
2015-06-01 01:39:59 +00:00
|
|
|
|
or.elim (le_or_gt a 1)
|
2015-07-21 16:10:56 +00:00
|
|
|
|
(suppose a ≤ 1,
|
|
|
|
|
show a = 1, from le.antisymm this (add_one_le_of_lt `a > 0`))
|
|
|
|
|
(suppose a > 1,
|
|
|
|
|
assert a * b ≥ 2 * 1,
|
|
|
|
|
from mul_le_mul (add_one_le_of_lt `a > 1`) (add_one_le_of_lt `b > 0`) trivial H,
|
|
|
|
|
have false, by rewrite [H' at this]; exact this,
|
|
|
|
|
false.elim this)
|
2015-06-01 01:39:59 +00:00
|
|
|
|
|
|
|
|
|
theorem eq_one_of_mul_eq_one_left {a b : ℤ} (H : b ≥ 0) (H' : a * b = 1) : b = 1 :=
|
|
|
|
|
eq_one_of_mul_eq_one_right H (!mul.comm ▸ H')
|
|
|
|
|
|
|
|
|
|
theorem eq_one_of_mul_eq_self_left {a b : ℤ} (Hpos : a ≠ 0) (H : b * a = a) : b = 1 :=
|
|
|
|
|
eq_of_mul_eq_mul_right Hpos (H ⬝ (one_mul a)⁻¹)
|
|
|
|
|
|
|
|
|
|
theorem eq_one_of_mul_eq_self_right {a b : ℤ} (Hpos : b ≠ 0) (H : b * a = b) : a = 1 :=
|
|
|
|
|
eq_one_of_mul_eq_self_left Hpos (!mul.comm ▸ H)
|
|
|
|
|
|
|
|
|
|
theorem eq_one_of_dvd_one {a : ℤ} (H : a ≥ 0) (H' : a ∣ 1) : a = 1 :=
|
|
|
|
|
dvd.elim H'
|
|
|
|
|
(take b,
|
2015-07-21 16:10:56 +00:00
|
|
|
|
suppose 1 = a * b,
|
|
|
|
|
eq_one_of_mul_eq_one_right H this⁻¹)
|
2015-09-11 03:00:18 +00:00
|
|
|
|
|
2015-09-13 00:51:34 +00:00
|
|
|
|
theorem exists_least_of_bdd {P : ℤ → Prop} [HP : decidable_pred P]
|
|
|
|
|
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, z ≤ b → ¬ P z)
|
2015-09-11 03:00:18 +00:00
|
|
|
|
(Hinh : ∃ z : ℤ, P z) : ∃ lb : ℤ, P lb ∧ (∀ z : ℤ, z < lb → ¬ P z) :=
|
|
|
|
|
begin
|
|
|
|
|
cases Hbdd with [b, Hb],
|
|
|
|
|
cases Hinh with [elt, Helt],
|
|
|
|
|
existsi b + of_nat (least (λ n, P (b + of_nat n)) (nat.succ (nat_abs (elt - b)))),
|
|
|
|
|
have Heltb : elt > b, begin
|
2015-10-07 23:44:47 +00:00
|
|
|
|
apply lt_of_not_ge,
|
2015-09-11 03:00:18 +00:00
|
|
|
|
intro Hge,
|
|
|
|
|
apply (Hb _ Hge) Helt
|
|
|
|
|
end,
|
|
|
|
|
have H' : P (b + of_nat (nat_abs (elt - b))), begin
|
2015-10-07 23:44:47 +00:00
|
|
|
|
rewrite [of_nat_nat_abs_of_nonneg (int.le_of_lt (iff.mpr !sub_pos_iff_lt Heltb)),
|
|
|
|
|
add.comm, algebra.sub_add_cancel],
|
2015-09-11 03:00:18 +00:00
|
|
|
|
apply Helt
|
|
|
|
|
end,
|
|
|
|
|
apply and.intro,
|
|
|
|
|
apply least_of_lt _ !lt_succ_self H',
|
|
|
|
|
intros z Hz,
|
|
|
|
|
cases em (z ≤ b) with [Hzb, Hzb],
|
|
|
|
|
apply Hb _ Hzb,
|
2015-10-07 23:44:47 +00:00
|
|
|
|
let Hzb' := lt_of_not_ge Hzb,
|
|
|
|
|
let Hpos := iff.mpr !sub_pos_iff_lt Hzb',
|
2015-09-11 03:00:18 +00:00
|
|
|
|
have Hzbk : z = b + of_nat (nat_abs (z - b)),
|
2015-10-22 20:36:45 +00:00
|
|
|
|
by rewrite [of_nat_nat_abs_of_nonneg (int.le_of_lt Hpos), int.add_comm, algebra.sub_add_cancel],
|
2015-09-11 03:00:18 +00:00
|
|
|
|
have Hk : nat_abs (z - b) < least (λ n, P (b + of_nat n)) (nat.succ (nat_abs (elt - b))), begin
|
2015-10-07 23:44:47 +00:00
|
|
|
|
let Hz' := iff.mp !lt_add_iff_sub_lt_left Hz,
|
2015-09-11 03:00:18 +00:00
|
|
|
|
rewrite [-of_nat_nat_abs_of_nonneg (int.le_of_lt Hpos) at Hz'],
|
2015-09-12 14:00:34 +00:00
|
|
|
|
apply lt_of_of_nat_lt_of_nat Hz'
|
2015-09-11 03:00:18 +00:00
|
|
|
|
end,
|
2015-10-07 23:44:47 +00:00
|
|
|
|
let Hk' := algebra.not_le_of_gt Hk,
|
2015-09-11 03:00:18 +00:00
|
|
|
|
rewrite Hzbk,
|
|
|
|
|
apply λ p, mt (ge_least_of_lt _ p) Hk',
|
2015-10-22 21:35:27 +00:00
|
|
|
|
apply nat.lt_trans Hk,
|
2015-09-11 03:00:18 +00:00
|
|
|
|
apply least_lt _ !lt_succ_self H'
|
|
|
|
|
end
|
|
|
|
|
|
2015-09-13 00:51:34 +00:00
|
|
|
|
theorem exists_greatest_of_bdd {P : ℤ → Prop} [HP : decidable_pred P]
|
|
|
|
|
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, z ≥ b → ¬ P z)
|
2015-09-11 03:00:18 +00:00
|
|
|
|
(Hinh : ∃ z : ℤ, P z) : ∃ ub : ℤ, P ub ∧ (∀ z : ℤ, z > ub → ¬ P z) :=
|
|
|
|
|
begin
|
|
|
|
|
cases Hbdd with [b, Hb],
|
|
|
|
|
cases Hinh with [elt, Helt],
|
|
|
|
|
existsi b - of_nat (least (λ n, P (b - of_nat n)) (nat.succ (nat_abs (b - elt)))),
|
|
|
|
|
have Heltb : elt < b, begin
|
2015-10-07 23:44:47 +00:00
|
|
|
|
apply lt_of_not_ge,
|
2015-09-11 03:00:18 +00:00
|
|
|
|
intro Hge,
|
|
|
|
|
apply (Hb _ Hge) Helt
|
|
|
|
|
end,
|
|
|
|
|
have H' : P (b - of_nat (nat_abs (b - elt))), begin
|
2015-10-07 23:44:47 +00:00
|
|
|
|
rewrite [of_nat_nat_abs_of_nonneg (int.le_of_lt (iff.mpr !sub_pos_iff_lt Heltb)),
|
|
|
|
|
sub_sub_self],
|
2015-09-11 03:00:18 +00:00
|
|
|
|
apply Helt
|
|
|
|
|
end,
|
|
|
|
|
apply and.intro,
|
|
|
|
|
apply least_of_lt _ !lt_succ_self H',
|
|
|
|
|
intros z Hz,
|
|
|
|
|
cases em (z ≥ b) with [Hzb, Hzb],
|
|
|
|
|
apply Hb _ Hzb,
|
2015-10-07 23:44:47 +00:00
|
|
|
|
let Hzb' := lt_of_not_ge Hzb,
|
|
|
|
|
let Hpos := iff.mpr !sub_pos_iff_lt Hzb',
|
2015-09-11 03:00:18 +00:00
|
|
|
|
have Hzbk : z = b - of_nat (nat_abs (b - z)),
|
2015-10-07 23:44:47 +00:00
|
|
|
|
by rewrite [of_nat_nat_abs_of_nonneg (int.le_of_lt Hpos), sub_sub_self],
|
2015-09-11 03:00:18 +00:00
|
|
|
|
have Hk : nat_abs (b - z) < least (λ n, P (b - of_nat n)) (nat.succ (nat_abs (b - elt))), begin
|
2015-10-07 23:44:47 +00:00
|
|
|
|
let Hz' := iff.mp !lt_add_iff_sub_lt_left (iff.mpr !lt_add_iff_sub_lt_right Hz),
|
2015-09-11 03:00:18 +00:00
|
|
|
|
rewrite [-of_nat_nat_abs_of_nonneg (int.le_of_lt Hpos) at Hz'],
|
2015-09-12 14:00:34 +00:00
|
|
|
|
apply lt_of_of_nat_lt_of_nat Hz'
|
2015-09-11 03:00:18 +00:00
|
|
|
|
end,
|
2015-10-07 23:44:47 +00:00
|
|
|
|
let Hk' := algebra.not_le_of_gt Hk,
|
2015-09-11 03:00:18 +00:00
|
|
|
|
rewrite Hzbk,
|
|
|
|
|
apply λ p, mt (ge_least_of_lt _ p) Hk',
|
2015-10-22 21:35:27 +00:00
|
|
|
|
apply nat.lt_trans Hk,
|
2015-09-11 03:00:18 +00:00
|
|
|
|
apply least_lt _ !lt_succ_self H'
|
|
|
|
|
end
|
2015-06-01 01:39:59 +00:00
|
|
|
|
|
2014-08-23 00:56:25 +00:00
|
|
|
|
end int
|