Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 2c53e5e

Browse files
committed
chore(order/well_founded): move to a file (#4568)
I want to use `order/rel_classes` before `data/set/basic`.
1 parent 4dbebe3 commit 2c53e5e

File tree

6 files changed

+167
-157
lines changed

6 files changed

+167
-157
lines changed

archive/imo/imo1988_q6.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Johan Commelin
55
-/
66

77
import data.rat.basic
8+
import order.well_founded
89
import tactic.linarith
910
import tactic.omega
1011

src/data/fintype/basic.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import data.finset.powerset
1010
import data.finset.lattice
1111
import data.finset.pi
1212
import data.array.lemmas
13+
import order.well_founded
1314

1415
open_locale nat
1516

src/order/lattice.lean

Lines changed: 45 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Johannes Hölzl
55
66
Defines the inf/sup (semi)-lattice with optionally top/bot type class hierarchy.
77
-/
8-
import order.basic
8+
import order.rel_classes
99

1010
set_option old_structure_cmd true
1111

@@ -42,6 +42,9 @@ class semilattice_sup (α : Type u) extends has_sup α, partial_order α :=
4242
(le_sup_right : ∀ a b : α, b ≤ a ⊔ b)
4343
(sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c)
4444

45+
instance (α : Type*) [has_inf α] : has_sup (order_dual α) := ⟨((⊓) : α → α → α)⟩
46+
instance (α : Type*) [has_sup α] : has_inf (order_dual α) := ⟨((⊔) : α → α → α)⟩
47+
4548
section semilattice_sup
4649
variables [semilattice_sup α] {a b c d : α}
4750

@@ -104,12 +107,14 @@ lemma sup_ind [is_total α (≤)] (a b : α) {p : α → Prop} (ha : p a) (hb :
104107
(is_total.total a b).elim (λ h : a ≤ b, by rwa sup_eq_right.2 h) (λ h, by rwa sup_eq_left.2 h)
105108

106109
@[simp] lemma sup_lt_iff [is_total α (≤)] {a b c : α} : b ⊔ c < a ↔ b < a ∧ c < a :=
107-
⟨λ h, ⟨lt_of_le_of_lt le_sup_left h, lt_of_le_of_lt le_sup_right h⟩,
108-
λ h, sup_ind b c h.1 h.2
110+
⟨λ h, ⟨le_sup_left.trans_lt h, le_sup_right.trans_lt h⟩, λ h, sup_ind b c h.1 h.2
109111

110112
@[simp] lemma le_sup_iff [is_total α (≤)] {a b c : α} : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c :=
111113
by rw [← not_iff_not]; simp only [not_or_distrib, @sup_lt_iff α, @not_le (as_linear_order α)]
112114

115+
@[simp] lemma lt_sup_iff [is_total α (≤)] {a b c : α} : a < b ⊔ c ↔ a < b ∨ a < c :=
116+
by { rw ← not_iff_not, simp only [not_or_distrib, @not_lt (as_linear_order α), sup_le_iff] }
117+
113118
@[simp] theorem sup_idem : a ⊔ a = a :=
114119
by apply le_antisymm; simp
115120

@@ -171,6 +176,18 @@ class semilattice_inf (α : Type u) extends has_inf α, partial_order α :=
171176
(inf_le_right : ∀ a b : α, a ⊓ b ≤ b)
172177
(le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ b ⊓ c)
173178

179+
instance (α) [semilattice_inf α] : semilattice_sup (order_dual α) :=
180+
{ le_sup_left := semilattice_inf.inf_le_left,
181+
le_sup_right := semilattice_inf.inf_le_right,
182+
sup_le := assume a b c hca hcb, @semilattice_inf.le_inf α _ _ _ _ hca hcb,
183+
.. order_dual.partial_order α, .. order_dual.has_sup α }
184+
185+
instance (α) [semilattice_sup α] : semilattice_inf (order_dual α) :=
186+
{ inf_le_left := @le_sup_left α _,
187+
inf_le_right := @le_sup_right α _,
188+
le_inf := assume a b c hca hcb, @sup_le α _ _ _ _ hca hcb,
189+
.. order_dual.partial_order α, .. order_dual.has_inf α }
190+
174191
section semilattice_inf
175192
variables [semilattice_inf α] {a b c d : α}
176193

@@ -196,8 +213,7 @@ theorem inf_le_right_of_le (h : b ≤ c) : a ⊓ b ≤ c :=
196213
le_trans inf_le_right h
197214

198215
@[simp] theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c :=
199-
⟨assume h : a ≤ b ⊓ c, ⟨le_trans h inf_le_left, le_trans h inf_le_right⟩,
200-
assume ⟨h₁, h₂⟩, le_inf h₁ h₂⟩
216+
@sup_le_iff (order_dual α) _ _ _ _
201217

202218
@[simp] theorem inf_eq_left : a ⊓ b = a ↔ a ≤ b :=
203219
le_antisymm_iff.trans $ by simp [le_refl]
@@ -230,51 +246,40 @@ theorem le_of_inf_eq (h : a ⊓ b = a) : a ≤ b :=
230246
by { rw ← h, simp }
231247

232248
lemma inf_ind [is_total α (≤)] (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊓ b) :=
233-
(is_total.total a b).elim (λ h : a ≤ b, by rwa inf_eq_left.2 h) (λ h, by rwa inf_eq_right.2 h)
249+
@sup_ind (order_dual α) _ _ _ _ _ ha hb
234250

235251
@[simp] lemma lt_inf_iff [is_total α (≤)] {a b c : α} : a < b ⊓ c ↔ a < b ∧ a < c :=
236-
⟨λ h, ⟨lt_of_lt_of_le h inf_le_left, lt_of_lt_of_le h inf_le_right⟩,
237-
λ h, inf_ind b c h.1 h.2
252+
@sup_lt_iff (order_dual α) _ _ _ _ _
238253

239254
@[simp] lemma inf_le_iff [is_total α (≤)] {a b c : α} : b ⊓ c ≤ a ↔ b ≤ a ∨ c ≤ a :=
240-
by rw [← not_iff_not]; simp only [not_or_distrib, @lt_inf_iff α, @not_le (as_linear_order α)]
255+
@le_sup_iff (order_dual α) _ _ _ _ _
241256

242257
@[simp] theorem inf_idem : a ⊓ a = a :=
243-
by apply le_antisymm; simp
258+
@sup_idem (order_dual α) _ _
244259

245260
instance inf_is_idempotent : is_idempotent α (⊓) := ⟨@inf_idem _ _⟩
246261

247262
theorem inf_comm : a ⊓ b = b ⊓ a :=
248-
by apply le_antisymm; simp
263+
@sup_comm (order_dual α) _ _ _
249264

250265
instance inf_is_commutative : is_commutative α (⊓) := ⟨@inf_comm _ _⟩
251266

252267
theorem inf_assoc : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) :=
253-
le_antisymm
254-
(le_inf
255-
(inf_le_left_of_le inf_le_left)
256-
(le_inf (inf_le_left_of_le inf_le_right) inf_le_right))
257-
(le_inf
258-
(le_inf inf_le_left (inf_le_right_of_le inf_le_left))
259-
(inf_le_right_of_le inf_le_right))
268+
@sup_assoc (order_dual α) _ a b c
260269

261270
instance inf_is_associative : is_associative α (⊓) := ⟨@inf_assoc _ _⟩
262271

263272
@[simp] lemma inf_left_idem : a ⊓ (a ⊓ b) = a ⊓ b :=
264-
by rw [← inf_assoc, inf_idem]
273+
@sup_left_idem (order_dual α) _ a b
265274

266275
@[simp] lemma inf_right_idem : (a ⊓ b) ⊓ b = a ⊓ b :=
267-
by rw [inf_assoc, inf_idem]
276+
@sup_right_idem (order_dual α) _ a b
268277

269278
lemma inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) :=
270-
by rw [← inf_assoc, ← inf_assoc, @inf_comm α _ a]
279+
@sup_left_comm (order_dual α) _ a b c
271280

272281
lemma forall_le_or_exists_lt_inf (a : α) : (∀b, a ≤ b) ∨ (∃b, b < a) :=
273-
suffices (∃b, ¬a ≤ b) → (∃b, b < a),
274-
by rwa [or_iff_not_imp_left, not_forall],
275-
assume ⟨b, hb⟩,
276-
have a ⊓ b ≠ a, from assume eq, hb $ eq ▸ inf_le_right,
277-
⟨a ⊓ b, lt_of_le_of_ne inf_le_left ‹a ⊓ b ≠ a›⟩
282+
@forall_le_or_exists_lt_sup (order_dual α) _ a
278283

279284
theorem semilattice_inf.ext_inf {α} {A B : semilattice_inf α}
280285
(H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y)
@@ -293,11 +298,14 @@ end
293298

294299
end semilattice_inf
295300

296-
/- Lattices -/
301+
/-! ### Lattices -/
297302

298303
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
299304
class lattice (α : Type u) extends semilattice_sup α, semilattice_inf α
300305

306+
instance (α) [lattice α] : lattice (order_dual α) :=
307+
{ .. order_dual.semilattice_sup α, .. order_dual.semilattice_inf α }
308+
301309
section lattice
302310
variables [lattice α] {a b c d : α}
303311

@@ -355,6 +363,10 @@ calc x ⊓ (y ⊔ z) = (x ⊓ (x ⊔ z)) ⊓ (y ⊔ z) : by rw [inf_sup_se
355363
... = ((x ⊓ y) ⊔ x) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_comm]
356364
... = (x ⊓ y) ⊔ (x ⊓ z) : by rw [sup_inf_left]
357365

366+
instance (α : Type*) [distrib_lattice α] : distrib_lattice (order_dual α) :=
367+
{ le_sup_inf := assume x y z, le_of_eq inf_sup_left.symm,
368+
.. order_dual.lattice α }
369+
358370
theorem inf_sup_right : (y ⊔ z) ⊓ x = (y ⊓ x) ⊔ (z ⊓ x) :=
359371
by simp only [inf_sup_left, λy:α, @inf_comm α _ y x, eq_self_iff_true]
360372

@@ -374,10 +386,13 @@ le_antisymm
374386

375387
end distrib_lattice
376388

377-
/- Lattices derived from linear orders -/
389+
/-!
390+
### Lattices derived from linear orders
391+
-/
378392

379393
@[priority 100] -- see Note [lower instance priority]
380-
instance lattice_of_decidable_linear_order {α : Type u} [o : decidable_linear_order α] : lattice α :=
394+
instance lattice_of_decidable_linear_order {α : Type u} [o : decidable_linear_order α] :
395+
lattice α :=
381396
{ sup := max,
382397
le_sup_left := le_max_left,
383398
le_sup_right := le_max_right,
@@ -427,39 +442,10 @@ le_inf (h inf_le_left) (h inf_le_right)
427442
lemma map_inf [semilattice_inf α] [is_total α (≤)] [semilattice_inf β] {f : α → β}
428443
(hf : monotone f) (x y : α) :
429444
f (x ⊓ y) = f x ⊓ f y :=
430-
(is_total.total x y).elim
431-
(λ h : x ≤ y, by simp only [h, hf h, inf_of_le_left])
432-
(λ h, by simp only [h, hf h, inf_of_le_right])
445+
@monotone.map_sup (order_dual α) _ _ _ _ _ hf.order_dual x y
433446

434447
end monotone
435448

436-
namespace order_dual
437-
variable (α)
438-
439-
instance [has_inf α] : has_sup (order_dual α) := ⟨((⊓) : α → α → α)⟩
440-
instance [has_sup α] : has_inf (order_dual α) := ⟨((⊔) : α → α → α)⟩
441-
442-
instance [semilattice_inf α] : semilattice_sup (order_dual α) :=
443-
{ le_sup_left := @inf_le_left α _,
444-
le_sup_right := @inf_le_right α _,
445-
sup_le := assume a b c hca hcb, @le_inf α _ _ _ _ hca hcb,
446-
.. order_dual.partial_order α, .. order_dual.has_sup α }
447-
448-
instance [semilattice_sup α] : semilattice_inf (order_dual α) :=
449-
{ inf_le_left := @le_sup_left α _,
450-
inf_le_right := @le_sup_right α _,
451-
le_inf := assume a b c hca hcb, @sup_le α _ _ _ _ hca hcb,
452-
.. order_dual.partial_order α, .. order_dual.has_inf α }
453-
454-
instance [lattice α] : lattice (order_dual α) :=
455-
{ .. order_dual.semilattice_sup α, .. order_dual.semilattice_inf α }
456-
457-
instance [distrib_lattice α] : distrib_lattice (order_dual α) :=
458-
{ le_sup_inf := assume x y z, le_of_eq inf_sup_left.symm,
459-
.. order_dual.lattice α }
460-
461-
end order_dual
462-
463449
namespace prod
464450
variables (α β)
465451

src/order/pilex.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Chris Hughes
55
-/
66
import algebra.group.pi
7-
import order.rel_classes
7+
import order.well_founded
88
import algebra.order_functions
99

1010
variables {ι : Type*} {β : ι → Type*} (r : ι → ι → Prop)

src/order/rel_classes.lean

Lines changed: 4 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Copyright (c) 2020 Jeremy Avigad. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Jeremy Avigad, Mario Carneiro, Yury G. Kudryashov
55
-/
6-
import data.set.basic
6+
import order.basic
77

88
/-!
99
# Unbundled relation classes
@@ -80,6 +80,9 @@ instance [linear_order α] : is_linear_order α (≥) := {}
8080
instance [linear_order α] : is_trichotomous α (<) := ⟨lt_trichotomy⟩
8181
instance [linear_order α] : is_trichotomous α (>) := is_trichotomous.swap _
8282

83+
instance order_dual.is_total_le [has_le α] [is_total α (≤)] : is_total (order_dual α) (≤) :=
84+
@is_total.swap α _ _
85+
8386
lemma trans_trichotomous_left [is_trans α r] [is_trichotomous α r] {a b c : α} :
8487
¬r b a → r b c → r a c :=
8588
begin
@@ -273,99 +276,3 @@ end
273276

274277
@[simp] lemma not_unbounded_iff {r : α → α → Prop} (s : set α) : ¬unbounded r s ↔ bounded r s :=
275278
by { classical, rw [not_iff_comm, not_bounded_iff] }
276-
277-
namespace well_founded
278-
/-- If `r` is a well-founded relation, then any nonempty set has a minimal element
279-
with respect to `r`. -/
280-
theorem has_min {α} {r : α → α → Prop} (H : well_founded r)
281-
(s : set α) : s.nonempty → ∃ a ∈ s, ∀ x ∈ s, ¬ r x a
282-
| ⟨a, ha⟩ := (acc.rec_on (H.apply a) $ λ x _ IH, not_imp_not.1 $ λ hne hx, hne $
283-
⟨x, hx, λ y hy hyx, hne $ IH y hyx hy⟩) ha
284-
285-
/-- A minimal element of a nonempty set in a well-founded order -/
286-
noncomputable def min {α} {r : α → α → Prop} (H : well_founded r)
287-
(p : set α) (h : p.nonempty) : α :=
288-
classical.some (H.has_min p h)
289-
290-
theorem min_mem {α} {r : α → α → Prop} (H : well_founded r)
291-
(p : set α) (h : p.nonempty) : H.min p h ∈ p :=
292-
let ⟨h, _⟩ := classical.some_spec (H.has_min p h) in h
293-
294-
theorem not_lt_min {α} {r : α → α → Prop} (H : well_founded r)
295-
(p : set α) (h : p.nonempty) {x} (xp : x ∈ p) : ¬ r x (H.min p h) :=
296-
let ⟨_, h'⟩ := classical.some_spec (H.has_min p h) in h' _ xp
297-
298-
theorem well_founded_iff_has_min {α} {r : α → α → Prop} : (well_founded r) ↔
299-
∀ (p : set α), p.nonempty → ∃ m ∈ p, ∀ x ∈ p, ¬ r x m :=
300-
begin
301-
classical,
302-
split,
303-
{ exact has_min, },
304-
{ set counterexamples := { x : α | ¬ acc r x},
305-
intro exists_max,
306-
fconstructor,
307-
intro x,
308-
by_contra hx,
309-
obtain ⟨m, m_mem, hm⟩ := exists_max counterexamples ⟨x, hx⟩,
310-
refine m_mem (acc.intro _ ( λ y y_gt_m, _)),
311-
by_contra hy,
312-
exact hm y hy y_gt_m, },
313-
end
314-
315-
lemma eq_iff_not_lt_of_le {α} [partial_order α] {x y : α} : x ≤ y → y = x ↔ ¬ x < y :=
316-
begin
317-
split,
318-
{ intros xle nge,
319-
cases le_not_le_of_lt nge,
320-
rw xle left at nge,
321-
exact lt_irrefl x nge },
322-
{ intros ngt xle,
323-
contrapose! ngt,
324-
exact lt_of_le_of_ne xle (ne.symm ngt) }
325-
end
326-
327-
theorem well_founded_iff_has_max' [partial_order α] : (well_founded ((>) : α → α → Prop) ↔
328-
∀ (p : set α), p.nonempty → ∃ m ∈ p, ∀ x ∈ p, m ≤ x → x = m) :=
329-
by simp only [eq_iff_not_lt_of_le, well_founded_iff_has_min]
330-
331-
theorem well_founded_iff_has_min' [partial_order α] : (well_founded (has_lt.lt : α → α → Prop)) ↔
332-
∀ (p : set α), p.nonempty → ∃ m ∈ p, ∀ x ∈ p, x ≤ m → x = m :=
333-
@well_founded_iff_has_max' (order_dual α) _
334-
335-
open set
336-
/-- The supremum of a bounded, well-founded order -/
337-
protected noncomputable def sup {α} {r : α → α → Prop} (wf : well_founded r) (s : set α)
338-
(h : bounded r s) : α :=
339-
wf.min { x | ∀a ∈ s, r a x } h
340-
341-
protected lemma lt_sup {α} {r : α → α → Prop} (wf : well_founded r) {s : set α} (h : bounded r s)
342-
{x} (hx : x ∈ s) : r x (wf.sup s h) :=
343-
min_mem wf { x | ∀a ∈ s, r a x } h x hx
344-
345-
section
346-
open_locale classical
347-
/-- A successor of an element `x` in a well-founded order is a minimal element `y` such that
348-
`x < y` if one exists. Otherwise it is `x` itself. -/
349-
protected noncomputable def succ {α} {r : α → α → Prop} (wf : well_founded r) (x : α) : α :=
350-
if h : ∃y, r x y then wf.min { y | r x y } h else x
351-
352-
protected lemma lt_succ {α} {r : α → α → Prop} (wf : well_founded r) {x : α} (h : ∃y, r x y) :
353-
r x (wf.succ x) :=
354-
by { rw [well_founded.succ, dif_pos h], apply min_mem }
355-
end
356-
357-
protected lemma lt_succ_iff {α} {r : α → α → Prop} [wo : is_well_order α r] {x : α} (h : ∃y, r x y)
358-
(y : α) : r y (wo.wf.succ x) ↔ r y x ∨ y = x :=
359-
begin
360-
split,
361-
{ intro h', have : ¬r x y,
362-
{ intro hy, rw [well_founded.succ, dif_pos] at h',
363-
exact wo.wf.not_lt_min _ h hy h' },
364-
rcases trichotomous_of r x y with hy | hy | hy,
365-
exfalso, exact this hy,
366-
right, exact hy.symm,
367-
left, exact hy },
368-
rintro (hy | rfl), exact trans hy (wo.wf.lt_succ h), exact wo.wf.lt_succ h
369-
end
370-
371-
end well_founded

0 commit comments

Comments
 (0)