2014-11-07 19:38:09 +00:00
|
|
|
|
/-
|
|
|
|
|
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
|
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
Author: Jeremy Avigad
|
|
|
|
|
|
2015-06-28 04:23:45 +00:00
|
|
|
|
Weak orders "≤", strict orders "<", and structures that include both.
|
2014-11-07 19:38:09 +00:00
|
|
|
|
-/
|
2015-07-01 00:34:35 +00:00
|
|
|
|
import logic.eq logic.connectives algebra.binary algebra.priority
|
2014-11-07 19:38:09 +00:00
|
|
|
|
open eq eq.ops
|
|
|
|
|
|
|
|
|
|
variable {A : Type}
|
|
|
|
|
|
|
|
|
|
/- weak orders -/
|
|
|
|
|
|
|
|
|
|
structure weak_order [class] (A : Type) extends has_le A :=
|
2014-11-17 20:19:46 +00:00
|
|
|
|
(le_refl : ∀a, le a a)
|
|
|
|
|
(le_trans : ∀a b c, le a b → le b c → le a c)
|
2014-12-26 21:25:05 +00:00
|
|
|
|
(le_antisymm : ∀a b, le a b → le b a → a = b)
|
2014-11-07 19:38:09 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
section
|
|
|
|
|
variable [s : weak_order A]
|
|
|
|
|
include s
|
2014-11-07 19:38:09 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem le.refl (a : A) : a ≤ a := !weak_order.le_refl
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
2015-12-09 05:02:05 +00:00
|
|
|
|
theorem le_of_eq {a b : A} (H : a = b) : a ≤ b := H ▸ le.refl a
|
|
|
|
|
|
2015-05-02 22:15:35 +00:00
|
|
|
|
theorem le.trans [trans] {a b c : A} : a ≤ b → b ≤ c → a ≤ c := !weak_order.le_trans
|
2014-11-07 19:38:09 +00:00
|
|
|
|
|
2015-05-02 22:15:35 +00:00
|
|
|
|
theorem ge.trans [trans] {a b c : A} (H1 : a ≥ b) (H2: b ≥ c) : a ≥ c := le.trans H2 H1
|
2015-01-27 01:38:00 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem le.antisymm {a b : A} : a ≤ b → b ≤ a → a = b := !weak_order.le_antisymm
|
2015-05-17 02:54:36 +00:00
|
|
|
|
|
2015-06-28 04:23:45 +00:00
|
|
|
|
-- Alternate syntax. (Abbreviations do not migrate well.)
|
2015-05-17 02:54:36 +00:00
|
|
|
|
theorem eq_of_le_of_ge {a b : A} : a ≤ b → b ≤ a → a = b := !le.antisymm
|
2014-12-26 21:25:05 +00:00
|
|
|
|
end
|
2014-11-07 19:38:09 +00:00
|
|
|
|
|
|
|
|
|
structure linear_weak_order [class] (A : Type) extends weak_order A :=
|
|
|
|
|
(le_total : ∀a b, le a b ∨ le b a)
|
|
|
|
|
|
2014-12-12 23:22:19 +00:00
|
|
|
|
theorem le.total [s : linear_weak_order A] (a b : A) : a ≤ b ∨ b ≤ a :=
|
2014-11-07 19:38:09 +00:00
|
|
|
|
!linear_weak_order.le_total
|
|
|
|
|
|
|
|
|
|
/- strict orders -/
|
|
|
|
|
|
|
|
|
|
structure strict_order [class] (A : Type) extends has_lt A :=
|
2014-11-17 20:19:46 +00:00
|
|
|
|
(lt_irrefl : ∀a, ¬ lt a a)
|
2014-11-07 19:38:09 +00:00
|
|
|
|
(lt_trans : ∀a b c, lt a b → lt b c → lt a c)
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
section
|
|
|
|
|
variable [s : strict_order A]
|
|
|
|
|
include s
|
2014-11-07 19:38:09 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem lt.irrefl (a : A) : ¬ a < a := !strict_order.lt_irrefl
|
2015-05-17 02:54:36 +00:00
|
|
|
|
theorem not_lt_self (a : A) : ¬ a < a := !lt.irrefl -- alternate syntax
|
2014-11-07 19:38:09 +00:00
|
|
|
|
|
2015-12-06 07:52:16 +00:00
|
|
|
|
theorem lt_self_iff_false (a : A) : a < a ↔ false :=
|
2015-10-22 20:09:26 +00:00
|
|
|
|
iff_false_intro (lt.irrefl a)
|
|
|
|
|
|
2015-05-02 22:15:35 +00:00
|
|
|
|
theorem lt.trans [trans] {a b c : A} : a < b → b < c → a < c := !strict_order.lt_trans
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
2015-05-02 22:15:35 +00:00
|
|
|
|
theorem gt.trans [trans] {a b c : A} (H1 : a > b) (H2: b > c) : a > c := lt.trans H2 H1
|
2015-01-27 01:38:00 +00:00
|
|
|
|
|
2015-04-16 02:25:02 +00:00
|
|
|
|
theorem ne_of_lt {a b : A} (lt_ab : a < b) : a ≠ b :=
|
|
|
|
|
assume eq_ab : a = b,
|
2014-12-26 21:25:05 +00:00
|
|
|
|
show false, from lt.irrefl b (eq_ab ▸ lt_ab)
|
2014-11-07 19:38:09 +00:00
|
|
|
|
|
2015-04-16 02:25:02 +00:00
|
|
|
|
theorem ne_of_gt {a b : A} (gt_ab : a > b) : a ≠ b :=
|
|
|
|
|
ne.symm (ne_of_lt gt_ab)
|
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem lt.asymm {a b : A} (H : a < b) : ¬ b < a :=
|
|
|
|
|
assume H1 : b < a, lt.irrefl _ (lt.trans H H1)
|
2015-05-17 02:54:36 +00:00
|
|
|
|
|
2015-05-25 09:48:07 +00:00
|
|
|
|
theorem not_lt_of_gt {a b : A} (H : a > b) : ¬ a < b := !lt.asymm H -- alternate syntax
|
2014-12-26 21:25:05 +00:00
|
|
|
|
end
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
|
|
|
|
/- well-founded orders -/
|
|
|
|
|
|
2014-11-07 19:38:09 +00:00
|
|
|
|
structure wf_strict_order [class] (A : Type) extends strict_order A :=
|
|
|
|
|
(wf_rec : ∀P : A → Type, (∀x, (∀y, lt y x → P y) → P x) → ∀x, P x)
|
|
|
|
|
|
2014-11-28 23:13:01 +00:00
|
|
|
|
definition wf.rec_on {A : Type} [s : wf_strict_order A] {P : A → Type}
|
2014-11-17 20:19:46 +00:00
|
|
|
|
(x : A) (H : ∀x, (∀y, wf_strict_order.lt y x → P y) → P x) : P x :=
|
2014-11-07 19:38:09 +00:00
|
|
|
|
wf_strict_order.wf_rec P H x
|
|
|
|
|
|
2014-11-28 23:13:01 +00:00
|
|
|
|
theorem wf.ind_on.{u v} {A : Type.{u}} [s : wf_strict_order.{u 0} A] {P : A → Prop}
|
2014-11-17 20:19:46 +00:00
|
|
|
|
(x : A) (H : ∀x, (∀y, wf_strict_order.lt y x → P y) → P x) : P x :=
|
2014-11-28 23:13:01 +00:00
|
|
|
|
wf.rec_on x H
|
2014-11-07 19:38:09 +00:00
|
|
|
|
|
|
|
|
|
/- structures with a weak and a strict order -/
|
|
|
|
|
|
|
|
|
|
structure order_pair [class] (A : Type) extends weak_order A, has_lt A :=
|
2015-05-29 03:33:45 +00:00
|
|
|
|
(le_of_lt : ∀ a b, lt a b → le a b)
|
|
|
|
|
(lt_of_lt_of_le : ∀ a b c, lt a b → le b c → lt a c)
|
|
|
|
|
(lt_of_le_of_lt : ∀ a b c, le a b → lt b c → lt a c)
|
|
|
|
|
(lt_irrefl : ∀ a, ¬ lt a a)
|
2014-11-07 19:38:09 +00:00
|
|
|
|
|
2014-12-12 23:22:19 +00:00
|
|
|
|
section
|
|
|
|
|
variable [s : order_pair A]
|
|
|
|
|
variables {a b c : A}
|
|
|
|
|
include s
|
|
|
|
|
|
2015-05-29 03:33:45 +00:00
|
|
|
|
theorem le_of_lt : a < b → a ≤ b := !order_pair.le_of_lt
|
2014-12-12 23:22:19 +00:00
|
|
|
|
|
2015-05-29 03:33:45 +00:00
|
|
|
|
theorem lt_of_lt_of_le [trans] : a < b → b ≤ c → a < c := !order_pair.lt_of_lt_of_le
|
2014-12-12 23:22:19 +00:00
|
|
|
|
|
2015-05-29 03:33:45 +00:00
|
|
|
|
theorem lt_of_le_of_lt [trans] : a ≤ b → b < c → a < c := !order_pair.lt_of_le_of_lt
|
2014-12-12 23:22:19 +00:00
|
|
|
|
|
2015-05-29 03:33:45 +00:00
|
|
|
|
private theorem lt_irrefl (s' : order_pair A) (a : A) : ¬ a < a := !order_pair.lt_irrefl
|
2015-01-20 23:28:46 +00:00
|
|
|
|
|
2015-03-04 00:52:12 +00:00
|
|
|
|
private theorem lt_trans (s' : order_pair A) (a b c: A) (lt_ab : a < b) (lt_bc : b < c) : a < c :=
|
2015-05-29 03:33:45 +00:00
|
|
|
|
lt_of_lt_of_le lt_ab (le_of_lt lt_bc)
|
2015-01-20 23:28:46 +00:00
|
|
|
|
|
2015-11-11 19:32:05 +00:00
|
|
|
|
definition order_pair.to_strict_order [trans_instance] [reducible] : strict_order A :=
|
2015-01-20 23:28:46 +00:00
|
|
|
|
⦃ strict_order, s, lt_irrefl := lt_irrefl s, lt_trans := lt_trans s ⦄
|
2014-12-12 23:22:19 +00:00
|
|
|
|
|
2015-05-02 22:15:35 +00:00
|
|
|
|
theorem gt_of_gt_of_ge [trans] (H1 : a > b) (H2 : b ≥ c) : a > c := lt_of_le_of_lt H2 H1
|
2015-01-27 01:38:00 +00:00
|
|
|
|
|
2015-05-02 22:15:35 +00:00
|
|
|
|
theorem gt_of_ge_of_gt [trans] (H1 : a ≥ b) (H2 : b > c) : a > c := lt_of_lt_of_le H2 H1
|
2014-12-12 23:22:19 +00:00
|
|
|
|
|
2015-05-25 09:48:07 +00:00
|
|
|
|
theorem not_le_of_gt (H : a > b) : ¬ a ≤ b :=
|
|
|
|
|
assume H1 : a ≤ b,
|
2014-12-12 23:22:19 +00:00
|
|
|
|
lt.irrefl _ (lt_of_lt_of_le H H1)
|
|
|
|
|
|
2015-05-25 09:48:07 +00:00
|
|
|
|
theorem not_lt_of_ge (H : a ≥ b) : ¬ a < b :=
|
|
|
|
|
assume H1 : a < b,
|
2014-12-12 23:22:19 +00:00
|
|
|
|
lt.irrefl _ (lt_of_le_of_lt H H1)
|
|
|
|
|
end
|
2014-11-17 20:19:46 +00:00
|
|
|
|
|
2015-06-28 04:23:45 +00:00
|
|
|
|
structure strong_order_pair [class] (A : Type) extends weak_order A, has_lt A :=
|
2014-11-07 19:38:09 +00:00
|
|
|
|
(le_iff_lt_or_eq : ∀a b, le a b ↔ lt a b ∨ a = b)
|
2015-05-29 03:33:45 +00:00
|
|
|
|
(lt_irrefl : ∀ a, ¬ lt a a)
|
2014-11-07 19:38:09 +00:00
|
|
|
|
|
|
|
|
|
theorem le_iff_lt_or_eq [s : strong_order_pair A] {a b : A} : a ≤ b ↔ a < b ∨ a = b :=
|
|
|
|
|
!strong_order_pair.le_iff_lt_or_eq
|
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem lt_or_eq_of_le [s : strong_order_pair A] {a b : A} (le_ab : a ≤ b) : a < b ∨ a = b :=
|
2014-11-07 19:38:09 +00:00
|
|
|
|
iff.mp le_iff_lt_or_eq le_ab
|
|
|
|
|
|
2015-05-29 03:33:45 +00:00
|
|
|
|
theorem le_of_lt_or_eq [s : strong_order_pair A] {a b : A} (lt_or_eq : a < b ∨ a = b) : a ≤ b :=
|
2015-07-18 09:28:53 +00:00
|
|
|
|
iff.mpr le_iff_lt_or_eq lt_or_eq
|
2015-05-29 03:33:45 +00:00
|
|
|
|
|
2015-06-21 19:36:43 +00:00
|
|
|
|
private theorem lt_irrefl' [s : strong_order_pair A] (a : A) : ¬ a < a :=
|
2015-06-28 04:23:45 +00:00
|
|
|
|
!strong_order_pair.lt_irrefl
|
2015-05-29 03:33:45 +00:00
|
|
|
|
|
2015-06-21 19:36:43 +00:00
|
|
|
|
private theorem le_of_lt' [s : strong_order_pair A] (a b : A) : a < b → a ≤ b :=
|
2015-06-28 04:23:45 +00:00
|
|
|
|
take Hlt, le_of_lt_or_eq (or.inl Hlt)
|
2015-05-29 03:33:45 +00:00
|
|
|
|
|
2015-06-21 19:36:43 +00:00
|
|
|
|
private theorem lt_iff_le_and_ne [s : strong_order_pair A] {a b : A} : a < b ↔ (a ≤ b ∧ a ≠ b) :=
|
2015-06-28 04:23:45 +00:00
|
|
|
|
iff.intro
|
|
|
|
|
(take Hlt, and.intro (le_of_lt_or_eq (or.inl Hlt)) (take Hab, absurd (Hab ▸ Hlt) !lt_irrefl'))
|
|
|
|
|
(take Hand,
|
|
|
|
|
have Hor : a < b ∨ a = b, from lt_or_eq_of_le (and.left Hand),
|
|
|
|
|
or_resolve_left Hor (and.right Hand))
|
2015-05-29 03:33:45 +00:00
|
|
|
|
|
|
|
|
|
theorem lt_of_le_of_ne [s : strong_order_pair A] {a b : A} : a ≤ b → a ≠ b → a < b :=
|
2015-07-18 09:28:53 +00:00
|
|
|
|
take H1 H2, iff.mpr lt_iff_le_and_ne (and.intro H1 H2)
|
2015-05-29 03:33:45 +00:00
|
|
|
|
|
|
|
|
|
private theorem ne_of_lt' [s : strong_order_pair A] {a b : A} (H : a < b) : a ≠ b :=
|
2015-06-28 04:23:45 +00:00
|
|
|
|
and.right ((iff.mp lt_iff_le_and_ne) H)
|
2015-05-29 03:33:45 +00:00
|
|
|
|
|
|
|
|
|
private theorem lt_of_lt_of_le' [s : strong_order_pair A] (a b c : A) : a < b → b ≤ c → a < c :=
|
2015-06-28 04:23:45 +00:00
|
|
|
|
assume lt_ab : a < b,
|
|
|
|
|
assume le_bc : b ≤ c,
|
|
|
|
|
have le_ac : a ≤ c, from le.trans (le_of_lt' _ _ lt_ab) le_bc,
|
|
|
|
|
have ne_ac : a ≠ c, from
|
|
|
|
|
assume eq_ac : a = c,
|
|
|
|
|
have le_ba : b ≤ a, from eq_ac⁻¹ ▸ le_bc,
|
|
|
|
|
have eq_ab : a = b, from le.antisymm (le_of_lt' _ _ lt_ab) le_ba,
|
|
|
|
|
show false, from ne_of_lt' lt_ab eq_ab,
|
2015-07-18 09:28:53 +00:00
|
|
|
|
show a < c, from iff.mpr (lt_iff_le_and_ne) (and.intro le_ac ne_ac)
|
2015-06-28 04:23:45 +00:00
|
|
|
|
|
|
|
|
|
theorem lt_of_le_of_lt' [s : strong_order_pair A] (a b c : A) : a ≤ b → b < c → a < c :=
|
|
|
|
|
assume le_ab : a ≤ b,
|
|
|
|
|
assume lt_bc : b < c,
|
|
|
|
|
have le_ac : a ≤ c, from le.trans le_ab (le_of_lt' _ _ lt_bc),
|
|
|
|
|
have ne_ac : a ≠ c, from
|
|
|
|
|
assume eq_ac : a = c,
|
|
|
|
|
have le_cb : c ≤ b, from eq_ac ▸ le_ab,
|
|
|
|
|
have eq_bc : b = c, from le.antisymm (le_of_lt' _ _ lt_bc) le_cb,
|
|
|
|
|
show false, from ne_of_lt' lt_bc eq_bc,
|
2015-07-18 09:28:53 +00:00
|
|
|
|
show a < c, from iff.mpr (lt_iff_le_and_ne) (and.intro le_ac ne_ac)
|
2015-06-28 04:23:45 +00:00
|
|
|
|
|
2015-11-11 19:32:05 +00:00
|
|
|
|
definition strong_order_pair.to_order_pair [trans_instance] [reducible]
|
2015-06-28 04:23:45 +00:00
|
|
|
|
[s : strong_order_pair A] : order_pair A :=
|
|
|
|
|
⦃ order_pair, s,
|
|
|
|
|
lt_irrefl := lt_irrefl',
|
|
|
|
|
le_of_lt := le_of_lt',
|
|
|
|
|
lt_of_le_of_lt := lt_of_le_of_lt',
|
2015-06-29 02:09:31 +00:00
|
|
|
|
lt_of_lt_of_le := lt_of_lt_of_le' ⦄
|
2014-11-28 23:13:01 +00:00
|
|
|
|
|
|
|
|
|
/- linear orders -/
|
2014-11-07 19:38:09 +00:00
|
|
|
|
|
2014-12-12 23:22:19 +00:00
|
|
|
|
structure linear_order_pair [class] (A : Type) extends order_pair A, linear_weak_order A
|
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
structure linear_strong_order_pair [class] (A : Type) extends strong_order_pair A,
|
|
|
|
|
linear_weak_order A
|
2014-12-12 23:22:19 +00:00
|
|
|
|
|
2015-11-11 19:32:05 +00:00
|
|
|
|
definition linear_strong_order_pair.to_linear_order_pair [trans_instance] [reducible]
|
2015-05-29 03:33:45 +00:00
|
|
|
|
[s : linear_strong_order_pair A] : linear_order_pair A :=
|
2015-06-29 02:09:31 +00:00
|
|
|
|
⦃ linear_order_pair, s, strong_order_pair.to_order_pair ⦄
|
2015-05-29 03:33:45 +00:00
|
|
|
|
|
2014-12-12 23:22:19 +00:00
|
|
|
|
section
|
|
|
|
|
variable [s : linear_strong_order_pair A]
|
|
|
|
|
variables (a b c : A)
|
|
|
|
|
include s
|
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem lt.trichotomy : a < b ∨ a = b ∨ b < a :=
|
|
|
|
|
or.elim (le.total a b)
|
|
|
|
|
(assume H : a ≤ b,
|
|
|
|
|
or.elim (iff.mp !le_iff_lt_or_eq H) (assume H1, or.inl H1) (assume H1, or.inr (or.inl H1)))
|
|
|
|
|
(assume H : b ≤ a,
|
|
|
|
|
or.elim (iff.mp !le_iff_lt_or_eq H)
|
|
|
|
|
(assume H1, or.inr (or.inr H1))
|
|
|
|
|
(assume H1, or.inr (or.inl (H1⁻¹))))
|
2014-12-12 23:22:19 +00:00
|
|
|
|
|
2014-12-26 21:25:05 +00:00
|
|
|
|
theorem lt.by_cases {a b : A} {P : Prop}
|
2014-12-12 23:22:19 +00:00
|
|
|
|
(H1 : a < b → P) (H2 : a = b → P) (H3 : b < a → P) : P :=
|
2014-12-26 21:25:05 +00:00
|
|
|
|
or.elim !lt.trichotomy
|
|
|
|
|
(assume H, H1 H)
|
|
|
|
|
(assume H, or.elim H (assume H', H2 H') (assume H', H3 H'))
|
2014-12-12 23:22:19 +00:00
|
|
|
|
|
2015-12-09 05:02:05 +00:00
|
|
|
|
definition lt_ge_by_cases {a b : A} {P : Prop} (H1 : a < b → P) (H2 : a ≥ b → P) : P :=
|
|
|
|
|
lt.by_cases H1 (λH, H2 (H ▸ le.refl a)) (λH, H2 (le_of_lt H))
|
|
|
|
|
|
2015-05-25 09:48:07 +00:00
|
|
|
|
theorem le_of_not_gt {a b : A} (H : ¬ a > b) : a ≤ b :=
|
2014-12-26 21:25:05 +00:00
|
|
|
|
lt.by_cases (assume H', absurd H' H) (assume H', H' ▸ !le.refl) (assume H', le_of_lt H')
|
2014-12-12 23:22:19 +00:00
|
|
|
|
|
2015-05-25 09:48:07 +00:00
|
|
|
|
theorem lt_of_not_ge {a b : A} (H : ¬ a ≥ b) : a < b :=
|
2014-12-26 21:25:05 +00:00
|
|
|
|
lt.by_cases
|
2014-12-12 23:22:19 +00:00
|
|
|
|
(assume H', absurd (le_of_lt H') H)
|
|
|
|
|
(assume H', absurd (H' ▸ !le.refl) H)
|
|
|
|
|
(assume H', H')
|
2015-01-07 01:44:04 +00:00
|
|
|
|
|
2015-01-20 21:22:47 +00:00
|
|
|
|
theorem lt_or_ge : a < b ∨ a ≥ b :=
|
2015-01-07 01:44:04 +00:00
|
|
|
|
lt.by_cases
|
|
|
|
|
(assume H1 : a < b, or.inl H1)
|
|
|
|
|
(assume H1 : a = b, or.inr (H1 ▸ le.refl a))
|
|
|
|
|
(assume H1 : a > b, or.inr (le_of_lt H1))
|
|
|
|
|
|
2015-01-20 21:22:47 +00:00
|
|
|
|
theorem le_or_gt : a ≤ b ∨ a > b :=
|
2015-01-07 01:44:04 +00:00
|
|
|
|
!or.swap (lt_or_ge b a)
|
2015-01-20 21:22:47 +00:00
|
|
|
|
|
|
|
|
|
theorem lt_or_gt_of_ne {a b : A} (H : a ≠ b) : a < b ∨ a > b :=
|
|
|
|
|
lt.by_cases (assume H1, or.inl H1) (assume H1, absurd H1 H) (assume H1, or.inr H1)
|
|
|
|
|
end
|
|
|
|
|
|
2015-06-28 22:03:58 +00:00
|
|
|
|
open decidable
|
|
|
|
|
|
2015-01-20 21:22:47 +00:00
|
|
|
|
structure decidable_linear_order [class] (A : Type) extends linear_strong_order_pair A :=
|
|
|
|
|
(decidable_lt : decidable_rel lt)
|
|
|
|
|
|
|
|
|
|
section
|
|
|
|
|
variable [s : decidable_linear_order A]
|
|
|
|
|
variables {a b c d : A}
|
|
|
|
|
include s
|
|
|
|
|
open decidable
|
|
|
|
|
|
|
|
|
|
definition decidable_lt [instance] : decidable (a < b) :=
|
|
|
|
|
@decidable_linear_order.decidable_lt _ _ _ _
|
|
|
|
|
|
|
|
|
|
definition decidable_le [instance] : decidable (a ≤ b) :=
|
|
|
|
|
by_cases
|
|
|
|
|
(assume H : a < b, inl (le_of_lt H))
|
|
|
|
|
(assume H : ¬ a < b,
|
2015-05-25 09:48:07 +00:00
|
|
|
|
have H1 : b ≤ a, from le_of_not_gt H,
|
2015-01-20 21:22:47 +00:00
|
|
|
|
by_cases
|
2015-05-25 09:48:07 +00:00
|
|
|
|
(assume H2 : b < a, inr (not_le_of_gt H2))
|
|
|
|
|
(assume H2 : ¬ b < a, inl (le_of_not_gt H2)))
|
2015-01-20 21:22:47 +00:00
|
|
|
|
|
2015-05-16 07:49:59 +00:00
|
|
|
|
definition has_decidable_eq [instance] : decidable (a = b) :=
|
2015-01-20 21:22:47 +00:00
|
|
|
|
by_cases
|
|
|
|
|
(assume H : a ≤ b,
|
|
|
|
|
by_cases
|
|
|
|
|
(assume H1 : b ≤ a, inl (le.antisymm H H1))
|
|
|
|
|
(assume H1 : ¬ b ≤ a, inr (assume H2 : a = b, H1 (H2 ▸ le.refl a))))
|
|
|
|
|
(assume H : ¬ a ≤ b,
|
|
|
|
|
(inr (assume H1 : a = b, H (H1 ▸ !le.refl))))
|
|
|
|
|
|
2015-09-15 22:56:26 +00:00
|
|
|
|
theorem eq_or_lt_of_not_lt {a b : A} (H : ¬ a < b) : a = b ∨ b < a :=
|
|
|
|
|
if Heq : a = b then or.inl Heq else or.inr (lt_of_not_ge (λ Hge, H (lt_of_le_of_ne Hge Heq)))
|
|
|
|
|
|
|
|
|
|
theorem eq_or_lt_of_le {a b : A} (H : a ≤ b) : a = b ∨ a < b :=
|
|
|
|
|
begin
|
|
|
|
|
cases eq_or_lt_of_not_lt (not_lt_of_ge H),
|
|
|
|
|
exact or.inl a_1⁻¹,
|
|
|
|
|
exact or.inr a_1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2015-01-21 20:50:42 +00:00
|
|
|
|
-- testing equality first may result in more definitional equalities
|
|
|
|
|
definition lt.cases {B : Type} (a b : A) (t_lt t_eq t_gt : B) : B :=
|
|
|
|
|
if a = b then t_eq else (if a < b then t_lt else t_gt)
|
|
|
|
|
|
|
|
|
|
theorem lt.cases_of_eq {B : Type} {a b : A} {t_lt t_eq t_gt : B} (H : a = b) :
|
|
|
|
|
lt.cases a b t_lt t_eq t_gt = t_eq := if_pos H
|
|
|
|
|
|
|
|
|
|
theorem lt.cases_of_lt {B : Type} {a b : A} {t_lt t_eq t_gt : B} (H : a < b) :
|
|
|
|
|
lt.cases a b t_lt t_eq t_gt = t_lt :=
|
|
|
|
|
if_neg (ne_of_lt H) ⬝ if_pos H
|
|
|
|
|
|
|
|
|
|
theorem lt.cases_of_gt {B : Type} {a b : A} {t_lt t_eq t_gt : B} (H : a > b) :
|
|
|
|
|
lt.cases a b t_lt t_eq t_gt = t_gt :=
|
|
|
|
|
if_neg (ne.symm (ne_of_lt H)) ⬝ if_neg (lt.asymm H)
|
2015-05-26 01:45:09 +00:00
|
|
|
|
|
2015-08-04 02:41:37 +00:00
|
|
|
|
definition min (a b : A) : A := if a ≤ b then a else b
|
|
|
|
|
definition max (a b : A) : A := if a ≤ b then b else a
|
2015-06-28 22:03:58 +00:00
|
|
|
|
|
2015-08-04 02:41:37 +00:00
|
|
|
|
/- these show min and max form a lattice -/
|
2015-06-28 22:03:58 +00:00
|
|
|
|
|
2015-08-04 02:41:37 +00:00
|
|
|
|
theorem min_le_left (a b : A) : min a b ≤ a :=
|
2015-06-28 22:03:58 +00:00
|
|
|
|
by_cases
|
2015-08-04 02:41:37 +00:00
|
|
|
|
(assume H : a ≤ b, by rewrite [↑min, if_pos H]; apply le.refl)
|
|
|
|
|
(assume H : ¬ a ≤ b, by rewrite [↑min, if_neg H]; apply le_of_lt (lt_of_not_ge H))
|
2015-06-28 22:03:58 +00:00
|
|
|
|
|
2015-08-04 02:41:37 +00:00
|
|
|
|
theorem min_le_right (a b : A) : min a b ≤ b :=
|
2015-06-28 22:03:58 +00:00
|
|
|
|
by_cases
|
2015-08-04 02:41:37 +00:00
|
|
|
|
(assume H : a ≤ b, by rewrite [↑min, if_pos H]; apply H)
|
|
|
|
|
(assume H : ¬ a ≤ b, by rewrite [↑min, if_neg H]; apply le.refl)
|
2015-06-28 22:03:58 +00:00
|
|
|
|
|
2015-08-04 02:41:37 +00:00
|
|
|
|
theorem le_min {a b c : A} (H₁ : c ≤ a) (H₂ : c ≤ b) : c ≤ min a b :=
|
2015-06-28 22:03:58 +00:00
|
|
|
|
by_cases
|
2015-08-04 02:41:37 +00:00
|
|
|
|
(assume H : a ≤ b, by rewrite [↑min, if_pos H]; apply H₁)
|
|
|
|
|
(assume H : ¬ a ≤ b, by rewrite [↑min, if_neg H]; apply H₂)
|
2015-06-28 22:03:58 +00:00
|
|
|
|
|
2015-08-04 02:41:37 +00:00
|
|
|
|
theorem le_max_left (a b : A) : a ≤ max a b :=
|
2015-06-28 22:03:58 +00:00
|
|
|
|
by_cases
|
2015-08-04 02:41:37 +00:00
|
|
|
|
(assume H : a ≤ b, by rewrite [↑max, if_pos H]; apply H)
|
|
|
|
|
(assume H : ¬ a ≤ b, by rewrite [↑max, if_neg H]; apply le.refl)
|
2015-06-28 22:03:58 +00:00
|
|
|
|
|
2015-08-04 02:41:37 +00:00
|
|
|
|
theorem le_max_right (a b : A) : b ≤ max a b :=
|
2015-06-28 22:03:58 +00:00
|
|
|
|
by_cases
|
2015-08-04 02:41:37 +00:00
|
|
|
|
(assume H : a ≤ b, by rewrite [↑max, if_pos H]; apply le.refl)
|
|
|
|
|
(assume H : ¬ a ≤ b, by rewrite [↑max, if_neg H]; apply le_of_lt (lt_of_not_ge H))
|
2015-06-28 22:03:58 +00:00
|
|
|
|
|
2015-08-04 02:41:37 +00:00
|
|
|
|
theorem max_le {a b c : A} (H₁ : a ≤ c) (H₂ : b ≤ c) : max a b ≤ c :=
|
2015-06-28 22:03:58 +00:00
|
|
|
|
by_cases
|
2015-08-04 02:41:37 +00:00
|
|
|
|
(assume H : a ≤ b, by rewrite [↑max, if_pos H]; apply H₂)
|
|
|
|
|
(assume H : ¬ a ≤ b, by rewrite [↑max, if_neg H]; apply H₁)
|
2015-05-26 01:45:09 +00:00
|
|
|
|
|
2015-12-06 07:52:16 +00:00
|
|
|
|
theorem le_max_left_iff_true (a b : A) : a ≤ max a b ↔ true :=
|
2015-10-22 19:31:58 +00:00
|
|
|
|
iff_true_intro (le_max_left a b)
|
|
|
|
|
|
2015-12-06 07:52:16 +00:00
|
|
|
|
theorem le_max_right_iff_true (a b : A) : b ≤ max a b ↔ true :=
|
2015-10-22 19:31:58 +00:00
|
|
|
|
iff_true_intro (le_max_right a b)
|
|
|
|
|
|
2015-08-04 02:41:37 +00:00
|
|
|
|
/- these are also proved for lattices, but with inf and sup in place of min and max -/
|
2015-06-21 19:36:43 +00:00
|
|
|
|
|
2015-08-04 02:41:37 +00:00
|
|
|
|
theorem eq_min {a b c : A} (H₁ : c ≤ a) (H₂ : c ≤ b) (H₃ : ∀{d}, d ≤ a → d ≤ b → d ≤ c) :
|
|
|
|
|
c = min a b :=
|
|
|
|
|
le.antisymm (le_min H₁ H₂) (H₃ !min_le_left !min_le_right)
|
|
|
|
|
|
|
|
|
|
theorem min.comm (a b : A) : min a b = min b a :=
|
|
|
|
|
eq_min !min_le_right !min_le_left (λ c H₁ H₂, le_min H₂ H₁)
|
|
|
|
|
|
|
|
|
|
theorem min.assoc (a b c : A) : min (min a b) c = min a (min b c) :=
|
|
|
|
|
begin
|
|
|
|
|
apply eq_min,
|
|
|
|
|
{ apply le.trans, apply min_le_left, apply min_le_left },
|
|
|
|
|
{ apply le_min, apply le.trans, apply min_le_left, apply min_le_right, apply min_le_right },
|
|
|
|
|
{ intros [d, H₁, H₂], apply le_min, apply le_min H₁, apply le.trans H₂, apply min_le_left,
|
|
|
|
|
apply le.trans H₂, apply min_le_right }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
theorem min.left_comm (a b c : A) : min a (min b c) = min b (min a c) :=
|
|
|
|
|
binary.left_comm (@min.comm A s) (@min.assoc A s) a b c
|
|
|
|
|
|
|
|
|
|
theorem min.right_comm (a b c : A) : min (min a b) c = min (min a c) b :=
|
|
|
|
|
binary.right_comm (@min.comm A s) (@min.assoc A s) a b c
|
|
|
|
|
|
|
|
|
|
theorem min_self (a : A) : min a a = a :=
|
|
|
|
|
by apply eq.symm; apply eq_min (le.refl a) !le.refl; intros; assumption
|
|
|
|
|
|
|
|
|
|
theorem min_eq_left {a b : A} (H : a ≤ b) : min a b = a :=
|
|
|
|
|
by apply eq.symm; apply eq_min !le.refl H; intros; assumption
|
|
|
|
|
|
|
|
|
|
theorem min_eq_right {a b : A} (H : b ≤ a) : min a b = b :=
|
|
|
|
|
eq.subst !min.comm (min_eq_left H)
|
|
|
|
|
|
|
|
|
|
theorem eq_max {a b c : A} (H₁ : a ≤ c) (H₂ : b ≤ c) (H₃ : ∀{d}, a ≤ d → b ≤ d → c ≤ d) :
|
|
|
|
|
c = max a b :=
|
|
|
|
|
le.antisymm (H₃ !le_max_left !le_max_right) (max_le H₁ H₂)
|
|
|
|
|
|
|
|
|
|
theorem max.comm (a b : A) : max a b = max b a :=
|
|
|
|
|
eq_max !le_max_right !le_max_left (λ c H₁ H₂, max_le H₂ H₁)
|
|
|
|
|
|
|
|
|
|
theorem max.assoc (a b c : A) : max (max a b) c = max a (max b c) :=
|
|
|
|
|
begin
|
|
|
|
|
apply eq_max,
|
|
|
|
|
{ apply le.trans, apply le_max_left a b, apply le_max_left },
|
|
|
|
|
{ apply max_le, apply le.trans, apply le_max_right a b, apply le_max_left, apply le_max_right },
|
|
|
|
|
{ intros [d, H₁, H₂], apply max_le, apply max_le H₁, apply le.trans !le_max_left H₂,
|
|
|
|
|
apply le.trans !le_max_right H₂}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
theorem max.left_comm (a b c : A) : max a (max b c) = max b (max a c) :=
|
|
|
|
|
binary.left_comm (@max.comm A s) (@max.assoc A s) a b c
|
|
|
|
|
|
|
|
|
|
theorem max.right_comm (a b c : A) : max (max a b) c = max (max a c) b :=
|
|
|
|
|
binary.right_comm (@max.comm A s) (@max.assoc A s) a b c
|
|
|
|
|
|
|
|
|
|
theorem max_self (a : A) : max a a = a :=
|
|
|
|
|
by apply eq.symm; apply eq_max (le.refl a) !le.refl; intros; assumption
|
|
|
|
|
|
|
|
|
|
theorem max_eq_left {a b : A} (H : b ≤ a) : max a b = a :=
|
|
|
|
|
by apply eq.symm; apply eq_max !le.refl H; intros; assumption
|
|
|
|
|
|
|
|
|
|
theorem max_eq_right {a b : A} (H : a ≤ b) : max a b = b :=
|
|
|
|
|
eq.subst !max.comm (max_eq_left H)
|
|
|
|
|
|
|
|
|
|
/- these rely on lt_of_lt -/
|
2015-08-04 00:49:20 +00:00
|
|
|
|
|
|
|
|
|
theorem min_eq_left_of_lt {a b : A} (H : a < b) : min a b = a :=
|
|
|
|
|
min_eq_left (le_of_lt H)
|
|
|
|
|
|
|
|
|
|
theorem min_eq_right_of_lt {a b : A} (H : b < a) : min a b = b :=
|
|
|
|
|
min_eq_right (le_of_lt H)
|
|
|
|
|
|
|
|
|
|
theorem max_eq_left_of_lt {a b : A} (H : b < a) : max a b = a :=
|
|
|
|
|
max_eq_left (le_of_lt H)
|
|
|
|
|
|
2015-08-04 02:41:37 +00:00
|
|
|
|
theorem max_eq_right_of_lt {a b : A} (H : a < b) : max a b = b :=
|
2015-08-04 00:49:20 +00:00
|
|
|
|
max_eq_right (le_of_lt H)
|
2015-08-04 02:41:37 +00:00
|
|
|
|
|
|
|
|
|
/- these use the fact that it is a linear ordering -/
|
|
|
|
|
|
|
|
|
|
theorem lt_min {a b c : A} (H₁ : a < b) (H₂ : a < c) : a < min b c :=
|
|
|
|
|
or.elim !le_or_gt
|
|
|
|
|
(assume H : b ≤ c, by rewrite (min_eq_left H); apply H₁)
|
|
|
|
|
(assume H : b > c, by rewrite (min_eq_right_of_lt H); apply H₂)
|
|
|
|
|
|
|
|
|
|
theorem max_lt {a b c : A} (H₁ : a < c) (H₂ : b < c) : max a b < c :=
|
|
|
|
|
or.elim !le_or_gt
|
|
|
|
|
(assume H : a ≤ b, by rewrite (max_eq_right H); apply H₂)
|
|
|
|
|
(assume H : a > b, by rewrite (max_eq_left_of_lt H); apply H₁)
|
2014-12-12 23:22:19 +00:00
|
|
|
|
end
|
2016-01-04 21:03:47 +00:00
|
|
|
|
|
|
|
|
|
/- order instances -/
|
|
|
|
|
|
|
|
|
|
definition weak_order_Prop [instance] : weak_order Prop :=
|
|
|
|
|
⦃ weak_order,
|
|
|
|
|
le := λx y, x → y,
|
|
|
|
|
le_refl := λx, id,
|
|
|
|
|
le_trans := λa b c H1 H2 x, H2 (H1 x),
|
|
|
|
|
le_antisymm := λf g H1 H2, propext (and.intro H1 H2)
|
|
|
|
|
⦄
|
|
|
|
|
|
2016-01-06 15:20:38 +00:00
|
|
|
|
definition weak_order_fun [instance] (A B : Type) [weak_order B] : weak_order (A → B) :=
|
2016-01-04 21:03:47 +00:00
|
|
|
|
⦃ weak_order,
|
|
|
|
|
le := λx y, ∀b, x b ≤ y b,
|
|
|
|
|
le_refl := λf b, !le.refl,
|
|
|
|
|
le_trans := λf g h H1 H2 b, !le.trans (H1 b) (H2 b),
|
|
|
|
|
le_antisymm := λf g H1 H2, funext (λb, !le.antisymm (H1 b) (H2 b))
|
|
|
|
|
⦄
|
|
|
|
|
|
|
|
|
|
definition weak_order_dual {A : Type} (wo : weak_order A) : weak_order A :=
|
|
|
|
|
⦃ weak_order,
|
|
|
|
|
le := λx y, y ≤ x,
|
|
|
|
|
le_refl := le.refl,
|
|
|
|
|
le_trans := take a b c `b ≤ a` `c ≤ b`, le.trans `c ≤ b` `b ≤ a`,
|
|
|
|
|
le_antisymm := take a b `b ≤ a` `a ≤ b`, le.antisymm `a ≤ b` `b ≤ a` ⦄
|
|
|
|
|
|
2016-01-06 15:13:39 +00:00
|
|
|
|
lemma le_dual_eq_le {A : Type} (wo : weak_order A) (a b : A) :
|
2016-01-04 21:03:47 +00:00
|
|
|
|
@le _ (@weak_order.to_has_le _ (weak_order_dual wo)) a b =
|
|
|
|
|
@le _ (@weak_order.to_has_le _ wo) b a :=
|
|
|
|
|
rfl
|
|
|
|
|
|
|
|
|
|
-- what to do with the strict variants?
|