|
| 1 | +/- |
| 2 | +Copyright (c) 2019 Chris Hughes. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Chris Hughes |
| 5 | +-/ |
| 6 | + |
| 7 | +import algebra.order_functions tactic.tauto algebra.pi_instances |
| 8 | + |
| 9 | +variables {ι : Type*} {β : ι → Type*} (r : ι → ι → Prop) |
| 10 | + (s : Π {i}, β i → β i → Prop) |
| 11 | + |
| 12 | +def pi.lex (x y : Π i, β i) : Prop := |
| 13 | +∃ i, (∀ j, r j i → x j = y j) ∧ s (x i) (y i) |
| 14 | + |
| 15 | +def pilex (α : Type*) (β : α → Type*) : Type* := Π a, β a |
| 16 | + |
| 17 | +instance [has_lt ι] [∀ a, has_lt (β a)] : has_lt (pilex ι β) := |
| 18 | +{ lt := pi.lex (<) (λ _, (<)) } |
| 19 | + |
| 20 | +set_option eqn_compiler.zeta true |
| 21 | + |
| 22 | +instance [linear_order ι] [∀ a, partial_order (β a)] : partial_order (pilex ι β) := |
| 23 | +let I : decidable_linear_order ι := classical.decidable_linear_order in |
| 24 | +have lt_not_symm : ∀ {x y : pilex ι β}, ¬ (x < y ∧ y < x), |
| 25 | + from λ x y ⟨⟨i, hi⟩, ⟨j, hj⟩⟩, begin |
| 26 | + rcases lt_trichotomy i j with hij | hij | hji, |
| 27 | + { exact lt_irrefl (x i) (by simpa [hj.1 _ hij] using hi.2) }, |
| 28 | + { exact not_le_of_gt hj.2 (hij ▸ le_of_lt hi.2) }, |
| 29 | + { exact lt_irrefl (x j) (by simpa [hi.1 _ hji] using hj.2) }, |
| 30 | + end, |
| 31 | +{ le := λ x y, x < y ∨ x = y, |
| 32 | + le_refl := λ _, or.inr rfl, |
| 33 | + le_antisymm := λ x y hxy hyx, |
| 34 | + hxy.elim (λ hxy, hyx.elim (λ hyx, false.elim (lt_not_symm ⟨hxy, hyx⟩)) eq.symm) id, |
| 35 | + le_trans := |
| 36 | + λ x y z hxy hyz, |
| 37 | + hxy.elim |
| 38 | + (λ ⟨i, hi⟩, hyz.elim |
| 39 | + (λ ⟨j, hj⟩, or.inl |
| 40 | + ⟨by exactI min i j, by resetI; exact |
| 41 | + λ k hk, by rw [hi.1 _ (lt_min_iff.1 hk).1, hj.1 _ (lt_min_iff.1 hk).2], |
| 42 | + by resetI; exact (le_total i j).elim |
| 43 | + (λ hij, by rw [min_eq_left hij]; |
| 44 | + exact lt_of_lt_of_le hi.2 |
| 45 | + ((lt_or_eq_of_le hij).elim (λ h, le_of_eq (hj.1 _ h)) |
| 46 | + (λ h, h.symm ▸ le_of_lt hj.2))) |
| 47 | + (λ hji, by rw [min_eq_right hji]; |
| 48 | + exact lt_of_le_of_lt |
| 49 | + ((lt_or_eq_of_le hji).elim (λ h, le_of_eq (hi.1 _ h)) |
| 50 | + (λ h, h.symm ▸ le_of_lt hi.2)) |
| 51 | + hj.2)⟩) |
| 52 | + (λ hyz, hyz ▸ hxy)) |
| 53 | + (λ hxy, hxy.symm ▸ hyz), |
| 54 | + lt_iff_le_not_le := λ x y, show x < y ↔ (x < y ∨ x = y) ∧ ¬ (y < x ∨ y = x), |
| 55 | + from ⟨λ ⟨i, hi⟩, ⟨or.inl ⟨i, hi⟩, |
| 56 | + λ h, h.elim (λ ⟨j, hj⟩, begin |
| 57 | + rcases lt_trichotomy i j with hij | hij | hji, |
| 58 | + { exact lt_irrefl (x i) (by simpa [hj.1 _ hij] using hi.2) }, |
| 59 | + { exact not_le_of_gt hj.2 (hij ▸ le_of_lt hi.2) }, |
| 60 | + { exact lt_irrefl (x j) (by simpa [hi.1 _ hji] using hj.2) }, |
| 61 | + end) |
| 62 | + (λ hyx, lt_irrefl (x i) (by simpa [hyx] using hi.2))⟩, by tauto⟩, |
| 63 | + ..pilex.has_lt } |
| 64 | + |
| 65 | +instance [linear_order ι] (wf : well_founded ((<) : ι → ι → Prop)) [∀ a, linear_order (β a)] : |
| 66 | + linear_order (pilex ι β) := |
| 67 | +{ le_total := λ x y, by classical; exact |
| 68 | + or_iff_not_imp_left.2 (λ hxy, begin |
| 69 | + have := not_or_distrib.1 hxy, |
| 70 | + let i : ι := well_founded.min wf _ |
| 71 | + (set.ne_empty_iff_exists_mem.2 (classical.not_forall.1 (this.2 ∘ funext))), |
| 72 | + have hjiyx : ∀ j < i, y j = x j, |
| 73 | + { assume j, |
| 74 | + rw [eq_comm, ← not_imp_not], |
| 75 | + exact λ h, well_founded.not_lt_min wf _ _ h }, |
| 76 | + refine or.inl ⟨i, hjiyx, _⟩, |
| 77 | + { refine lt_of_not_ge (λ hyx, _), |
| 78 | + exact this.1 ⟨i, (λ j hj, (hjiyx j hj).symm), |
| 79 | + lt_of_le_of_ne hyx (well_founded.min_mem _ {i | x i ≠ y i} _)⟩ } |
| 80 | + end), |
| 81 | + ..pilex.partial_order } |
| 82 | + |
| 83 | +instance [linear_order ι] [∀ a, ordered_comm_group (β a)] : ordered_comm_group (pilex ι β) := |
| 84 | +{ add_le_add_left := λ x y hxy z, |
| 85 | + hxy.elim |
| 86 | + (λ ⟨i, hi⟩, |
| 87 | + or.inl ⟨i, λ j hji, show z j + x j = z j + y j, by rw [hi.1 j hji], |
| 88 | + add_lt_add_left hi.2 _⟩) |
| 89 | + (λ hxy, hxy ▸ le_refl _), |
| 90 | + add_lt_add_left := λ x y ⟨i, hi⟩ z, |
| 91 | + ⟨i, λ j hji, show z j + x j = z j + y j, by rw [hi.1 j hji], |
| 92 | + add_lt_add_left hi.2 _⟩, |
| 93 | + ..pilex.partial_order, |
| 94 | + ..pi.add_comm_group } |
0 commit comments