path stringlengths 11 71 | content stringlengths 75 124k |
|---|---|
NumberTheory\NumberField\House.lean | /-
Copyright (c) 2024 Michail Karatarakis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michail Karatarakis
-/
import Mathlib.NumberTheory.SiegelsLemma
import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.Basic
import Mathlib.NumberTheory.NumberField.EquivReindex
/-!
# House of an algebraic number
This file defines the house of an algebraic number `α`, which is
the largest of the modulus of its conjugates.
## References
* [D. Marcus, *Number Fields*][marcus1977number]
* [Keng, H. L, *Introduction to number theory*][keng1982house]
## Tagshouse
number field, algebraic number, house
-/
variable {K : Type*} [Field K] [NumberField K]
namespace NumberField
noncomputable section
open Module.Free FiniteDimensional canonicalEmbedding Matrix Finset
attribute [local instance] Matrix.seminormedAddCommGroup
/-- The house of an algebraic number as the norm of its image by the canonical embedding. -/
def house (α : K) : ℝ := ‖canonicalEmbedding K α‖
/-- The house is the largest of the modulus of the conjugates of an algebraic number. -/
theorem house_eq_sup' (α : K) :
house α = univ.sup' univ_nonempty (fun φ : K →+* ℂ ↦ ‖φ α‖₊) := by
rw [house, ← coe_nnnorm, nnnorm_eq, ← sup'_eq_sup univ_nonempty]
theorem house_sum_le_sum_house {ι : Type*} (s : Finset ι) (α : ι → K) :
house (∑ i ∈ s, α i) ≤ ∑ i ∈ s, house (α i) := by
simp only [house, map_sum]; apply norm_sum_le_of_le; intros; rfl
theorem house_nonneg (α : K) : 0 ≤ house α := norm_nonneg _
theorem house_mul_le (α β : K) : house (α * β) ≤ house α * house β := by
simp only [house, _root_.map_mul]; apply norm_mul_le
@[simp] theorem house_intCast (x : ℤ) : house (x : K) = |x| := by
simp only [house, map_intCast, Pi.intCast_def, pi_norm_const, Complex.norm_eq_abs,
Complex.abs_intCast, Int.cast_abs]
end
end NumberField
namespace NumberField.house
noncomputable section
variable (K)
open Module.Free FiniteDimensional canonicalEmbedding Matrix Finset
attribute [local instance] Matrix.seminormedAddCommGroup
section DecidableEq
variable [DecidableEq (K →+* ℂ)]
/-- `c` is defined as the product of the maximum absolute
value of the entries of the inverse of the matrix `basisMatrix` and `finrank ℚ K`. -/
private def c := (finrank ℚ K) * ‖((basisMatrix K).transpose)⁻¹‖
private theorem c_nonneg : 0 ≤ c K := by
rw [c, mul_nonneg_iff]; left
exact ⟨by simp only [Nat.cast_nonneg], norm_nonneg ((basisMatrix K).transpose)⁻¹⟩
theorem basis_repr_abs_le_const_mul_house (α : 𝓞 K) (i : K →+* ℂ) :
Complex.abs (((integralBasis K).reindex (equivReindex K).symm).repr α i) ≤
(c K) * house (algebraMap (𝓞 K) K α) := by
let σ := canonicalEmbedding K
calc
_ ≤ ∑ j, ‖((basisMatrix K).transpose)⁻¹‖ * Complex.abs (σ (algebraMap (𝓞 K) K α) j) := ?_
_ ≤ ∑ _ : K →+* ℂ, ‖fun i j => ((basisMatrix K).transpose)⁻¹ i j‖
* house (algebraMap (𝓞 K) K α) := ?_
_ = ↑(finrank ℚ K) * ‖((basisMatrix K).transpose)⁻¹‖ * house (algebraMap (𝓞 K) K α) := ?_
· rw [← inverse_basisMatrix_mulVec_eq_repr]
apply le_trans
· apply le_trans (AbsoluteValue.sum_le Complex.abs _ _)
· exact sum_le_sum (fun _ _ => (AbsoluteValue.map_mul Complex.abs _ _).le)
· apply sum_le_sum (fun _ _ => mul_le_mul_of_nonneg_right ?_
(AbsoluteValue.nonneg Complex.abs _))
· exact norm_entry_le_entrywise_sup_norm ((basisMatrix K).transpose)⁻¹
· apply sum_le_sum; intros j _
apply mul_le_mul_of_nonneg_left _ (norm_nonneg fun i j ↦ ((basisMatrix K).transpose)⁻¹ i j)
· exact norm_le_pi_norm (σ ((algebraMap (𝓞 K) K) α)) j
· rw [sum_const, card_univ, nsmul_eq_mul, Embeddings.card, mul_assoc]
/-- `newBasis K` defines a reindexed basis of the ring of integers of `K`,
adjusted by the inverse of the equivalence `equivReindex`. -/
private def newBasis := (RingOfIntegers.basis K).reindex (equivReindex K).symm
/-- `supOfBasis K` calculates the supremum of the absolute values of
the elements in `newBasis K`. -/
private def supOfBasis : ℝ := univ.sup' univ_nonempty
fun r ↦ house (algebraMap (𝓞 K) K (newBasis K r))
end DecidableEq
private theorem supOfBasis_nonneg : 0 ≤ supOfBasis K := by
simp only [supOfBasis, le_sup'_iff, mem_univ, and_self,
exists_const, house_nonneg]
variable {α : Type*} {β : Type*} (a : Matrix α β (𝓞 K))
/-- `a' K a` returns the integer coefficients of the basis vector in the
expansion of the product of an algebraic integer and a basis vectors. -/
private def a' : α → β → (K →+* ℂ) → (K →+* ℂ) → ℤ := fun k l r =>
(newBasis K).repr (a k l * (newBasis K) r)
/--`asiegel K a` the integer matrix of the coefficients of the
product of matrix elements and basis vectors -/
private def asiegel : Matrix (α × (K →+* ℂ)) (β × (K →+* ℂ)) ℤ := fun k l => a' K a k.1 l.1 l.2 k.2
variable (ha : a ≠ 0)
private theorem asiegel_ne_0 : asiegel K a ≠ 0 := by
simp (config := { unfoldPartialApp := true }) only [asiegel, a']
simp only [ne_eq]
rw [Function.funext_iff]; intros hs
simp only [Prod.forall] at hs;
apply ha
rw [← Matrix.ext_iff]; intros k' l
specialize hs k'
let ⟨b⟩ := Fintype.card_pos_iff.1 (Fintype.card_pos (α := (K →+* ℂ)))
have := ((newBasis K).repr.map_eq_zero_iff (x := (a k' l * (newBasis K) b))).1 <| by
ext b'
specialize hs b'
rw [Function.funext_iff] at hs
simp only [Prod.forall] at hs
apply hs
simp only [mul_eq_zero] at this
exact this.resolve_right (Basis.ne_zero (newBasis K) b)
variable {p q : ℕ} (h0p : 0 < p) (hpq : p < q) (x : β × (K →+* ℂ) → ℤ) (hxl : x ≠ 0)
/-- `ξ` is the the product of `x (l, r)` and the `r`-th basis element of the newBasis of `K`. -/
private def ξ : β → 𝓞 K := fun l => ∑ r : K →+* ℂ, x (l, r) * (newBasis K r)
private theorem ξ_ne_0 : ξ K x ≠ 0 := by
intro H
apply hxl
ext ⟨l, r⟩
rw [Function.funext_iff] at H
have hblin := Basis.linearIndependent (newBasis K)
simp only [zsmul_eq_mul, Fintype.linearIndependent_iff] at hblin
exact hblin (fun r ↦ x (l,r)) (H _) r
private theorem lin_1 (l k r) : a k l * (newBasis K) r =
∑ u, (a' K a k l r u) * (newBasis K) u := by
simp only [Basis.sum_repr (newBasis K) (a k l * (newBasis K) r), a', ← zsmul_eq_mul]
variable [Fintype β] (cardβ : Fintype.card β = q) (hmulvec0 : asiegel K a *ᵥ x = 0)
private theorem ξ_mulVec_eq_0 : a *ᵥ ξ K x = 0 := by
funext k; simp only [Pi.zero_apply]; rw [eq_comm]
have lin_0 : ∀ u, ∑ r, ∑ l, (a' K a k l r u * x (l, r) : 𝓞 K) = 0 := by
intros u
have hξ := ξ_ne_0 K x hxl
rw [Ne, Function.funext_iff, not_forall] at hξ
rcases hξ with ⟨l, hξ⟩
rw [Function.funext_iff] at hmulvec0
specialize hmulvec0 ⟨k, u⟩
simp only [Fintype.sum_prod_type, mulVec, dotProduct, asiegel] at hmulvec0
rw [sum_comm] at hmulvec0
exact mod_cast hmulvec0
have : 0 = ∑ u, (∑ r, ∑ l, a' K a k l r u * x (l, r) : 𝓞 K) * (newBasis K) u := by
simp only [lin_0, zero_mul, sum_const_zero]
have : 0 = ∑ r, ∑ l, x (l, r) * ∑ u, a' K a k l r u * (newBasis K) u := by
conv at this => enter [2, 2, u]; rw [sum_mul]
rw [sum_comm] at this
rw [this]; congr 1; ext1 r
conv => enter [1, 2, l]; rw [sum_mul]
rw [sum_comm]; congr 1; ext1 r
rw [mul_sum]; congr 1; ext1 r
ring
rw [sum_comm] at this
rw [this]; congr 1; ext1 l
rw [ξ, mul_sum]; congr 1; ext1 l
rw [← lin_1]; ring
variable {A : ℝ} (habs : ∀ k l, (house ((algebraMap (𝓞 K) K) (a k l))) ≤ A)
variable [DecidableEq (K →+* ℂ)]
/-- `c₂` is the product of the maximum of `1` and `c`, and `supOfBasis`. -/
private abbrev c₂ := max 1 (c K) * (supOfBasis K)
private theorem c₂_nonneg : 0 ≤ c₂ K :=
mul_nonneg (le_trans zero_le_one (le_max_left ..)) (supOfBasis_nonneg _)
variable [Fintype α] (cardα : Fintype.card α = p) (Apos : 0 ≤ A)
(hxbound : ‖x‖ ≤ (q * finrank ℚ K * ‖asiegel K a‖) ^ ((p : ℝ) / (q - p)))
private theorem asiegel_remark : ‖asiegel K a‖ ≤ c₂ K * A := by
rw [Matrix.norm_le_iff]
· intro kr lu
calc
‖asiegel K a kr lu‖ = |asiegel K a kr lu| := ?_
_ ≤ (c K) *
house ((algebraMap (𝓞 K) K) (a kr.1 lu.1 * ((newBasis K) lu.2))) := ?_
_ ≤ (c K) * house ((algebraMap (𝓞 K) K) (a kr.1 lu.1)) *
house ((algebraMap (𝓞 K) K) ((newBasis K) lu.2)) := ?_
_ ≤ (c K) * A * house ((algebraMap (𝓞 K) K) ((newBasis K) lu.2)) := ?_
_ ≤ (c K) * A * (supOfBasis K) := ?_
_ ≤ (c₂ K) * A := ?_
· simp only [Int.cast_abs, ← Real.norm_eq_abs (asiegel K a kr lu)]; rfl
· have remark := basis_repr_abs_le_const_mul_house K
simp only [Basis.repr_reindex, Finsupp.mapDomain_equiv_apply,
integralBasis_repr_apply, eq_intCast, Rat.cast_intCast,
Complex.abs_intCast] at remark
exact mod_cast remark ((a kr.1 lu.1 * ((newBasis K) lu.2))) kr.2
· simp only [house, _root_.map_mul, mul_assoc]
exact mul_le_mul_of_nonneg_left (norm_mul_le _ _) (c_nonneg K)
· rw [mul_assoc, mul_assoc]
apply mul_le_mul_of_nonneg_left ?_ (c_nonneg K)
· apply mul_le_mul_of_nonneg_right (habs kr.1 lu.1) ?_
· exact norm_nonneg ((canonicalEmbedding K) ((algebraMap (𝓞 K) K)
((newBasis K) lu.2)))
· apply mul_le_mul_of_nonneg_left ?_ (mul_nonneg (c_nonneg K) Apos)
· simp only [supOfBasis, le_sup'_iff, mem_univ]; use lu.2
· rw [mul_right_comm]
exact mul_le_mul_of_nonneg_right
(mul_le_mul_of_nonneg_right (le_max_right ..) (supOfBasis_nonneg K)) Apos
· rw [mul_nonneg_iff]; left; exact ⟨c₂_nonneg K, Apos⟩
/-- `c₁ K` is the product of `finrank ℚ K` and `c₂ K` and depends on `K`. -/
private def c₁ := finrank ℚ K * c₂ K
private theorem house_le_bound : ∀ l, house (ξ K x l).1 ≤ (c₁ K) *
((c₁ K * q * A)^((p : ℝ) / (q - p))) := by
let h := finrank ℚ K
intros l
calc _ = house (algebraMap (𝓞 K) K (∑ r, (x (l, r)) * ((newBasis K) r))) := rfl
_ ≤ ∑ r, house (((algebraMap (𝓞 K) K) (x (l, r))) *
((algebraMap (𝓞 K) K) ((newBasis K) r))) := ?_
_ ≤ ∑ r, ‖x (l,r)‖ * house ((algebraMap (𝓞 K) K) ((newBasis K) r)) := ?_
_ ≤ ∑ r, ‖x (l, r)‖ * (supOfBasis K) := ?_
_ ≤ ∑ _r : K →+* ℂ, ((↑q * h * ‖asiegel K a‖) ^ ((p : ℝ) / (q - p))) * supOfBasis K := ?_
_ ≤ h * (c₂ K) * ((q * c₁ K * A) ^ ((p : ℝ) / (q - p))) := ?_
_ ≤ c₁ K * ((c₁ K * ↑q * A) ^ ((p : ℝ) / (q - p))) := ?_
· simp_rw [← _root_.map_mul, map_sum]; apply house_sum_le_sum_house
· apply sum_le_sum; intros r _; convert house_mul_le ..
simp only [map_intCast, house_intCast, Int.cast_abs, Int.norm_eq_abs]
· apply sum_le_sum; intros r _; unfold supOfBasis
apply mul_le_mul_of_nonneg_left ?_ (norm_nonneg (x (l,r)))
· simp only [le_sup'_iff, mem_univ, true_and]; use r
· apply sum_le_sum; intros r _
apply mul_le_mul_of_nonneg_right ?_ (supOfBasis_nonneg K)
exact le_trans (norm_le_pi_norm x ⟨l, r⟩) hxbound
· simp only [Nat.cast_mul, sum_const, card_univ, nsmul_eq_mul]
rw [Embeddings.card, mul_comm _ (supOfBasis K), c₂, c₁, ← mul_assoc]
apply mul_le_mul
· apply mul_le_mul_of_nonneg_left ?_ (Nat.cast_nonneg' _)
· exact le_mul_of_one_le_left (supOfBasis_nonneg K) (le_max_left ..)
· apply Real.rpow_le_rpow (mul_nonneg (mul_nonneg (Nat.cast_nonneg' _) (Nat.cast_nonneg' _))
(norm_nonneg _))
· rw [← mul_assoc, mul_assoc (_*_)]
apply mul_le_mul_of_nonneg_left (asiegel_remark K a habs Apos)
(mul_nonneg (Nat.cast_nonneg' _) (Nat.cast_nonneg _))
· exact div_nonneg (Nat.cast_nonneg' _) (sub_nonneg.2 (mod_cast hpq.le))
· apply Real.rpow_nonneg
exact mul_nonneg (mul_nonneg (Nat.cast_nonneg' _) (Nat.cast_nonneg' _))
(norm_nonneg _)
· exact mul_nonneg (Nat.cast_nonneg' _) (mul_nonneg (le_trans zero_le_one (le_max_left ..))
(supOfBasis_nonneg _))
· rw [mul_comm (q : ℝ) (c₁ K)]; rfl
/-- There exists a "small" non-zero algebraic integral solution of an
non-trivial underdetermined system of linear equations with algebraic integer coefficients.-/
theorem exists_ne_zero_int_vec_house_le :
∃ (ξ : β → 𝓞 K), ξ ≠ 0 ∧ a *ᵥ ξ = 0 ∧
∀ l, house (ξ l).1 ≤ c₁ K * ((c₁ K * q * A) ^ ((p : ℝ) / (q - p))) := by
classical
let h := finrank ℚ K
have hphqh : p * h < q * h := mul_lt_mul_of_pos_right hpq finrank_pos
have h0ph : 0 < p * h := by rw [mul_pos_iff]; constructor; exact ⟨h0p, finrank_pos⟩
have hfinp : Fintype.card (α × (K →+* ℂ)) = p * h := by
rw [Fintype.card_prod, cardα, Embeddings.card]
have hfinq : Fintype.card (β × (K →+* ℂ)) = q * h := by
rw [Fintype.card_prod, cardβ, Embeddings.card]
have ⟨x, hxl, hmulvec0, hxbound⟩ :=
Int.Matrix.exists_ne_zero_int_vec_norm_le' (asiegel K a)
(by rwa [hfinp, hfinq]) (by rwa [hfinp]) (asiegel_ne_0 K a ha)
simp only [hfinp, hfinq, Nat.cast_mul] at hmulvec0 hxbound
rw [← sub_mul, mul_div_mul_right _ _ (mod_cast finrank_pos.ne')] at hxbound
have Apos : 0 ≤ A := by
have ⟨k⟩ := Fintype.card_pos_iff.1 (cardα ▸ h0p)
have ⟨l⟩ := Fintype.card_pos_iff.1 (cardβ ▸ h0p.trans hpq)
exact le_trans (house_nonneg _) (habs k l)
use ξ K x, ξ_ne_0 K x hxl, ξ_mulVec_eq_0 K a x hxl hmulvec0,
house_le_bound K a hpq x habs Apos hxbound
end
end NumberField.house
|
NumberTheory\NumberField\Norm.lean | /-
Copyright (c) 2022 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca, Eric Rodriguez
-/
import Mathlib.NumberTheory.NumberField.Basic
import Mathlib.RingTheory.Localization.NormTrace
/-!
# Norm in number fields
Given a finite extension of number fields, we define the norm morphism as a function between the
rings of integers.
## Main definitions
* `RingOfIntegers.norm K` : `Algebra.norm` as a morphism `(𝓞 L) →* (𝓞 K)`.
## Main results
* `RingOfIntegers.dvd_norm` : if `L/K` is a finite Galois extension of fields, then, for all
`(x : 𝓞 L)` we have that `x ∣ algebraMap (𝓞 K) (𝓞 L) (norm K x)`.
-/
open scoped NumberField
open Finset NumberField Algebra FiniteDimensional
section Rat
variable {K : Type*} [Field K] [NumberField K] (x : 𝓞 K)
theorem Algebra.coe_norm_int : (Algebra.norm ℤ x : ℚ) = Algebra.norm ℚ (x : K) :=
(Algebra.norm_localization (R := ℤ) (Rₘ := ℚ) (S := 𝓞 K) (Sₘ := K) (nonZeroDivisors ℤ) x).symm
theorem Algebra.coe_trace_int : (Algebra.trace ℤ _ x : ℚ) = Algebra.trace ℚ K (x : K) :=
(Algebra.trace_localization (R := ℤ) (Rₘ := ℚ) (S := 𝓞 K) (Sₘ := K) (nonZeroDivisors ℤ) x).symm
end Rat
namespace RingOfIntegers
variable {L : Type*} (K : Type*) [Field K] [Field L] [Algebra K L] [FiniteDimensional K L]
/-- `Algebra.norm` as a morphism betwen the rings of integers. -/
noncomputable def norm [Algebra.IsSeparable K L] : 𝓞 L →* 𝓞 K :=
RingOfIntegers.restrict_monoidHom
((Algebra.norm K).comp (algebraMap (𝓞 L) L : (𝓞 L) →* L))
fun x => isIntegral_norm K x.2
@[simp] lemma coe_norm [Algebra.IsSeparable K L] (x : 𝓞 L) :
norm K x = Algebra.norm K (x : L) := rfl
theorem coe_algebraMap_norm [Algebra.IsSeparable K L] (x : 𝓞 L) :
(algebraMap (𝓞 K) (𝓞 L) (norm K x) : L) = algebraMap K L (Algebra.norm K (x : L)) :=
rfl
theorem algebraMap_norm_algebraMap [Algebra.IsSeparable K L] (x : 𝓞 K) :
algebraMap _ K (norm K (algebraMap (𝓞 K) (𝓞 L) x)) =
Algebra.norm K (algebraMap K L (algebraMap _ _ x)) := rfl
theorem norm_algebraMap [Algebra.IsSeparable K L] (x : 𝓞 K) :
norm K (algebraMap (𝓞 K) (𝓞 L) x) = x ^ finrank K L := by
rw [RingOfIntegers.ext_iff, RingOfIntegers.coe_eq_algebraMap,
RingOfIntegers.algebraMap_norm_algebraMap, Algebra.norm_algebraMap,
RingOfIntegers.coe_eq_algebraMap, map_pow]
theorem isUnit_norm_of_isGalois [IsGalois K L] {x : 𝓞 L} : IsUnit (norm K x) ↔ IsUnit x := by
classical
refine ⟨fun hx => ?_, IsUnit.map _⟩
replace hx : IsUnit (algebraMap (𝓞 K) (𝓞 L) <| norm K x) := hx.map (algebraMap (𝓞 K) <| 𝓞 L)
refine @isUnit_of_mul_isUnit_right (𝓞 L) _
⟨(univ \ {AlgEquiv.refl}).prod fun σ : L ≃ₐ[K] L => σ x,
prod_mem fun σ _ => x.2.map (σ : L →+* L).toIntAlgHom⟩ _ ?_
convert hx using 1
ext
convert_to ((univ \ {AlgEquiv.refl}).prod fun σ : L ≃ₐ[K] L => σ x) *
∏ σ ∈ {(AlgEquiv.refl : L ≃ₐ[K] L)}, σ x = _
· rw [prod_singleton, AlgEquiv.coe_refl, _root_.id, RingOfIntegers.coe_eq_algebraMap, map_mul,
RingOfIntegers.map_mk]
· rw [prod_sdiff <| subset_univ _, ← norm_eq_prod_automorphisms, coe_algebraMap_norm]
/-- If `L/K` is a finite Galois extension of fields, then, for all `(x : 𝓞 L)` we have that
`x ∣ algebraMap (𝓞 K) (𝓞 L) (norm K x)`. -/
theorem dvd_norm [IsGalois K L] (x : 𝓞 L) : x ∣ algebraMap (𝓞 K) (𝓞 L) (norm K x) := by
classical
have hint :
IsIntegral ℤ (∏ σ ∈ univ.erase (AlgEquiv.refl : L ≃ₐ[K] L), σ x) :=
IsIntegral.prod _ (fun σ _ =>
((RingOfIntegers.isIntegral_coe x).map σ))
refine ⟨⟨_, hint⟩, ?_⟩
ext
rw [coe_algebraMap_norm K x, norm_eq_prod_automorphisms]
simp [← Finset.mul_prod_erase _ _ (mem_univ AlgEquiv.refl)]
variable (F : Type*) [Field F] [Algebra K F] [Algebra.IsSeparable K F] [FiniteDimensional K F]
theorem norm_norm [Algebra.IsSeparable K L] [Algebra F L] [Algebra.IsSeparable F L]
[FiniteDimensional F L] [IsScalarTower K F L] (x : 𝓞 L) : norm K (norm F x) = norm K x := by
rw [RingOfIntegers.ext_iff, coe_norm, coe_norm, coe_norm, Algebra.norm_norm]
variable {F}
theorem isUnit_norm [CharZero K] {x : 𝓞 F} : IsUnit (norm K x) ↔ IsUnit x := by
letI : Algebra K (AlgebraicClosure K) := AlgebraicClosure.instAlgebra K
let L := normalClosure K F (AlgebraicClosure F)
haveI : FiniteDimensional F L := FiniteDimensional.right K F L
haveI : IsAlgClosure K (AlgebraicClosure F) :=
IsAlgClosure.ofAlgebraic K F (AlgebraicClosure F)
haveI : IsGalois F L := IsGalois.tower_top_of_isGalois K F L
calc
IsUnit (norm K x) ↔ IsUnit ((norm K) x ^ finrank F L) :=
(isUnit_pow_iff (pos_iff_ne_zero.mp finrank_pos)).symm
_ ↔ IsUnit (norm K (algebraMap (𝓞 F) (𝓞 L) x)) := by
rw [← norm_norm K F (algebraMap (𝓞 F) (𝓞 L) x), norm_algebraMap F _, map_pow]
_ ↔ IsUnit (algebraMap (𝓞 F) (𝓞 L) x) := isUnit_norm_of_isGalois K
_ ↔ IsUnit (norm F (algebraMap (𝓞 F) (𝓞 L) x)) := (isUnit_norm_of_isGalois F).symm
_ ↔ IsUnit (x ^ finrank F L) := (congr_arg IsUnit (norm_algebraMap F _)).to_iff
_ ↔ IsUnit x := isUnit_pow_iff (pos_iff_ne_zero.mp finrank_pos)
end RingOfIntegers
|
NumberTheory\NumberField\CanonicalEmbedding\Basic.lean | /-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.Algebra.Module.Zlattice.Basic
import Mathlib.NumberTheory.NumberField.Embeddings
import Mathlib.NumberTheory.NumberField.FractionalIdeal
/-!
# Canonical embedding of a number field
The canonical embedding of a number field `K` of degree `n` is the ring homomorphism
`K →+* ℂ^n` that sends `x ∈ K` to `(φ_₁(x),...,φ_n(x))` where the `φ_i`'s are the complex
embeddings of `K`. Note that we do not choose an ordering of the embeddings, but instead map `K`
into the type `(K →+* ℂ) → ℂ` of `ℂ`-vectors indexed by the complex embeddings.
## Main definitions and results
* `NumberField.canonicalEmbedding`: the ring homomorphism `K →+* ((K →+* ℂ) → ℂ)` defined by
sending `x : K` to the vector `(φ x)` indexed by `φ : K →+* ℂ`.
* `NumberField.canonicalEmbedding.integerLattice.inter_ball_finite`: the intersection of the
image of the ring of integers by the canonical embedding and any ball centered at `0` of finite
radius is finite.
* `NumberField.mixedEmbedding`: the ring homomorphism from `K →+* ({ w // IsReal w } → ℝ) ×
({ w // IsComplex w } → ℂ)` that sends `x ∈ K` to `(φ_w x)_w` where `φ_w` is the embedding
associated to the infinite place `w`. In particular, if `w` is real then `φ_w : K →+* ℝ` and, if
`w` is complex, `φ_w` is an arbitrary choice between the two complex embeddings defining the place
`w`.
## Tags
number field, infinite places
-/
variable (K : Type*) [Field K]
namespace NumberField.canonicalEmbedding
--open NumberField
/-- The canonical embedding of a number field `K` of degree `n` into `ℂ^n`. -/
def _root_.NumberField.canonicalEmbedding : K →+* ((K →+* ℂ) → ℂ) := Pi.ringHom fun φ => φ
theorem _root_.NumberField.canonicalEmbedding_injective [NumberField K] :
Function.Injective (NumberField.canonicalEmbedding K) := RingHom.injective _
variable {K}
@[simp]
theorem apply_at (φ : K →+* ℂ) (x : K) : (NumberField.canonicalEmbedding K x) φ = φ x := rfl
open scoped ComplexConjugate
/-- The image of `canonicalEmbedding` lives in the `ℝ`-submodule of the `x ∈ ((K →+* ℂ) → ℂ)` such
that `conj x_φ = x_(conj φ)` for all `∀ φ : K →+* ℂ`. -/
theorem conj_apply {x : ((K →+* ℂ) → ℂ)} (φ : K →+* ℂ)
(hx : x ∈ Submodule.span ℝ (Set.range (canonicalEmbedding K))) :
conj (x φ) = x (ComplexEmbedding.conjugate φ) := by
refine Submodule.span_induction hx ?_ ?_ (fun _ _ hx hy => ?_) (fun a _ hx => ?_)
· rintro _ ⟨x, rfl⟩
rw [apply_at, apply_at, ComplexEmbedding.conjugate_coe_eq]
· rw [Pi.zero_apply, Pi.zero_apply, map_zero]
· rw [Pi.add_apply, Pi.add_apply, map_add, hx, hy]
· rw [Pi.smul_apply, Complex.real_smul, map_mul, Complex.conj_ofReal]
exact congrArg ((a : ℂ) * ·) hx
theorem nnnorm_eq [NumberField K] (x : K) :
‖canonicalEmbedding K x‖₊ = Finset.univ.sup (fun φ : K →+* ℂ => ‖φ x‖₊) := by
simp_rw [Pi.nnnorm_def, apply_at]
theorem norm_le_iff [NumberField K] (x : K) (r : ℝ) :
‖canonicalEmbedding K x‖ ≤ r ↔ ∀ φ : K →+* ℂ, ‖φ x‖ ≤ r := by
obtain hr | hr := lt_or_le r 0
· obtain ⟨φ⟩ := (inferInstance : Nonempty (K →+* ℂ))
refine iff_of_false ?_ ?_
· exact (hr.trans_le (norm_nonneg _)).not_le
· exact fun h => hr.not_le (le_trans (norm_nonneg _) (h φ))
· lift r to NNReal using hr
simp_rw [← coe_nnnorm, nnnorm_eq, NNReal.coe_le_coe, Finset.sup_le_iff, Finset.mem_univ,
forall_true_left]
variable (K)
/-- The image of `𝓞 K` as a subring of `ℂ^n`. -/
def integerLattice : Subring ((K →+* ℂ) → ℂ) :=
(RingHom.range (algebraMap (𝓞 K) K)).map (canonicalEmbedding K)
theorem integerLattice.inter_ball_finite [NumberField K] (r : ℝ) :
((integerLattice K : Set ((K →+* ℂ) → ℂ)) ∩ Metric.closedBall 0 r).Finite := by
obtain hr | _ := lt_or_le r 0
· simp [Metric.closedBall_eq_empty.2 hr]
· have heq : ∀ x, canonicalEmbedding K x ∈ Metric.closedBall 0 r ↔
∀ φ : K →+* ℂ, ‖φ x‖ ≤ r := by
intro x; rw [← norm_le_iff, mem_closedBall_zero_iff]
convert (Embeddings.finite_of_norm_le K ℂ r).image (canonicalEmbedding K)
ext; constructor
· rintro ⟨⟨_, ⟨x, rfl⟩, rfl⟩, hx⟩
exact ⟨x, ⟨SetLike.coe_mem x, fun φ => (heq _).mp hx φ⟩, rfl⟩
· rintro ⟨x, ⟨hx1, hx2⟩, rfl⟩
exact ⟨⟨x, ⟨⟨x, hx1⟩, rfl⟩, rfl⟩, (heq x).mpr hx2⟩
open Module Fintype FiniteDimensional
/-- A `ℂ`-basis of `ℂ^n` that is also a `ℤ`-basis of the `integerLattice`. -/
noncomputable def latticeBasis [NumberField K] :
Basis (Free.ChooseBasisIndex ℤ (𝓞 K)) ℂ ((K →+* ℂ) → ℂ) := by
classical
-- Let `B` be the canonical basis of `(K →+* ℂ) → ℂ`. We prove that the determinant of
-- the image by `canonicalEmbedding` of the integral basis of `K` is nonzero. This
-- will imply the result.
let B := Pi.basisFun ℂ (K →+* ℂ)
let e : (K →+* ℂ) ≃ Free.ChooseBasisIndex ℤ (𝓞 K) :=
equivOfCardEq ((Embeddings.card K ℂ).trans (finrank_eq_card_basis (integralBasis K)))
let M := B.toMatrix (fun i => canonicalEmbedding K (integralBasis K (e i)))
suffices M.det ≠ 0 by
rw [← isUnit_iff_ne_zero, ← Basis.det_apply, ← is_basis_iff_det] at this
refine basisOfLinearIndependentOfCardEqFinrank
((linearIndependent_equiv e.symm).mpr this.1) ?_
rw [← finrank_eq_card_chooseBasisIndex, RingOfIntegers.rank, finrank_fintype_fun_eq_card,
Embeddings.card]
-- In order to prove that the determinant is nonzero, we show that it is equal to the
-- square of the discriminant of the integral basis and thus it is not zero
let N := Algebra.embeddingsMatrixReindex ℚ ℂ (fun i => integralBasis K (e i))
RingHom.equivRatAlgHom
rw [show M = N.transpose by { ext : 2; rfl }]
rw [Matrix.det_transpose, ← pow_ne_zero_iff two_ne_zero]
convert (map_ne_zero_iff _ (algebraMap ℚ ℂ).injective).mpr
(Algebra.discr_not_zero_of_basis ℚ (integralBasis K))
rw [← Algebra.discr_reindex ℚ (integralBasis K) e.symm]
exact (Algebra.discr_eq_det_embeddingsMatrixReindex_pow_two ℚ ℂ
(fun i => integralBasis K (e i)) RingHom.equivRatAlgHom).symm
@[simp]
theorem latticeBasis_apply [NumberField K] (i : Free.ChooseBasisIndex ℤ (𝓞 K)) :
latticeBasis K i = (canonicalEmbedding K) (integralBasis K i) := by
simp only [latticeBasis, integralBasis_apply, coe_basisOfLinearIndependentOfCardEqFinrank,
Function.comp_apply, Equiv.apply_symm_apply]
theorem mem_span_latticeBasis [NumberField K] (x : (K →+* ℂ) → ℂ) :
x ∈ Submodule.span ℤ (Set.range (latticeBasis K)) ↔
x ∈ ((canonicalEmbedding K).comp (algebraMap (𝓞 K) K)).range := by
rw [show Set.range (latticeBasis K) =
(canonicalEmbedding K).toIntAlgHom.toLinearMap '' (Set.range (integralBasis K)) by
rw [← Set.range_comp]; exact congrArg Set.range (funext (fun i => latticeBasis_apply K i))]
rw [← Submodule.map_span, ← SetLike.mem_coe, Submodule.map_coe]
rw [← RingHom.map_range, Subring.mem_map, Set.mem_image]
simp only [SetLike.mem_coe, mem_span_integralBasis K]
rfl
theorem mem_rat_span_latticeBasis [NumberField K] (x : K) :
canonicalEmbedding K x ∈ Submodule.span ℚ (Set.range (latticeBasis K)) := by
rw [← Basis.sum_repr (integralBasis K) x, map_sum]
simp_rw [map_rat_smul]
refine Submodule.sum_smul_mem _ _ (fun i _ ↦ Submodule.subset_span ?_)
rw [← latticeBasis_apply]
exact Set.mem_range_self i
theorem integralBasis_repr_apply [NumberField K] (x : K) (i : Free.ChooseBasisIndex ℤ (𝓞 K)) :
(latticeBasis K).repr (canonicalEmbedding K x) i = (integralBasis K).repr x i := by
rw [← Basis.restrictScalars_repr_apply ℚ _ ⟨_, mem_rat_span_latticeBasis K x⟩, eq_ratCast,
Rat.cast_inj]
let f := (canonicalEmbedding K).toRatAlgHom.toLinearMap.codRestrict _
(fun x ↦ mem_rat_span_latticeBasis K x)
suffices ((latticeBasis K).restrictScalars ℚ).repr.toLinearMap ∘ₗ f =
(integralBasis K).repr.toLinearMap from DFunLike.congr_fun (LinearMap.congr_fun this x) i
refine Basis.ext (integralBasis K) (fun i ↦ ?_)
have : f (integralBasis K i) = ((latticeBasis K).restrictScalars ℚ) i := by
apply Subtype.val_injective
rw [LinearMap.codRestrict_apply, AlgHom.toLinearMap_apply, Basis.restrictScalars_apply,
latticeBasis_apply]
rfl
simp_rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, this, Basis.repr_self]
end NumberField.canonicalEmbedding
namespace NumberField.mixedEmbedding
open NumberField.InfinitePlace FiniteDimensional Finset
/-- The space `ℝ^r₁ × ℂ^r₂` with `(r₁, r₂)` the signature of `K`. -/
local notation "E" K =>
({w : InfinitePlace K // IsReal w} → ℝ) × ({w : InfinitePlace K // IsComplex w} → ℂ)
/-- The mixed embedding of a number field `K` of signature `(r₁, r₂)` into `ℝ^r₁ × ℂ^r₂`. -/
noncomputable def _root_.NumberField.mixedEmbedding : K →+* (E K) :=
RingHom.prod (Pi.ringHom fun w => embedding_of_isReal w.prop)
(Pi.ringHom fun w => w.val.embedding)
instance [NumberField K] : Nontrivial (E K) := by
obtain ⟨w⟩ := (inferInstance : Nonempty (InfinitePlace K))
obtain hw | hw := w.isReal_or_isComplex
· have : Nonempty {w : InfinitePlace K // IsReal w} := ⟨⟨w, hw⟩⟩
exact nontrivial_prod_left
· have : Nonempty {w : InfinitePlace K // IsComplex w} := ⟨⟨w, hw⟩⟩
exact nontrivial_prod_right
protected theorem finrank [NumberField K] : finrank ℝ (E K) = finrank ℚ K := by
classical
rw [finrank_prod, finrank_pi, finrank_pi_fintype, Complex.finrank_real_complex, sum_const,
card_univ, ← NrRealPlaces, ← NrComplexPlaces, ← card_real_embeddings, Algebra.id.smul_eq_mul,
mul_comm, ← card_complex_embeddings, ← NumberField.Embeddings.card K ℂ,
Fintype.card_subtype_compl, Nat.add_sub_of_le (Fintype.card_subtype_le _)]
theorem _root_.NumberField.mixedEmbedding_injective [NumberField K] :
Function.Injective (NumberField.mixedEmbedding K) := by
exact RingHom.injective _
section commMap
/-- The linear map that makes `canonicalEmbedding` and `mixedEmbedding` commute, see
`commMap_canonical_eq_mixed`. -/
noncomputable def commMap : ((K →+* ℂ) → ℂ) →ₗ[ℝ] (E K) where
toFun := fun x => ⟨fun w => (x w.val.embedding).re, fun w => x w.val.embedding⟩
map_add' := by
simp only [Pi.add_apply, Complex.add_re, Prod.mk_add_mk, Prod.mk.injEq]
exact fun _ _ => ⟨rfl, rfl⟩
map_smul' := by
simp only [Pi.smul_apply, Complex.real_smul, Complex.mul_re, Complex.ofReal_re,
Complex.ofReal_im, zero_mul, sub_zero, RingHom.id_apply, Prod.smul_mk, Prod.mk.injEq]
exact fun _ _ => ⟨rfl, rfl⟩
theorem commMap_apply_of_isReal (x : (K →+* ℂ) → ℂ) {w : InfinitePlace K} (hw : IsReal w) :
(commMap K x).1 ⟨w, hw⟩ = (x w.embedding).re := rfl
theorem commMap_apply_of_isComplex (x : (K →+* ℂ) → ℂ) {w : InfinitePlace K} (hw : IsComplex w) :
(commMap K x).2 ⟨w, hw⟩ = x w.embedding := rfl
@[simp]
theorem commMap_canonical_eq_mixed (x : K) :
commMap K (canonicalEmbedding K x) = mixedEmbedding K x := by
simp only [canonicalEmbedding, commMap, LinearMap.coe_mk, AddHom.coe_mk, Pi.ringHom_apply,
mixedEmbedding, RingHom.prod_apply, Prod.mk.injEq]
exact ⟨rfl, rfl⟩
/-- This is a technical result to ensure that the image of the `ℂ`-basis of `ℂ^n` defined in
`canonicalEmbedding.latticeBasis` is a `ℝ`-basis of `ℝ^r₁ × ℂ^r₂`,
see `mixedEmbedding.latticeBasis`. -/
theorem disjoint_span_commMap_ker [NumberField K] :
Disjoint (Submodule.span ℝ (Set.range (canonicalEmbedding.latticeBasis K)))
(LinearMap.ker (commMap K)) := by
refine LinearMap.disjoint_ker.mpr (fun x h_mem h_zero => ?_)
replace h_mem : x ∈ Submodule.span ℝ (Set.range (canonicalEmbedding K)) := by
refine (Submodule.span_mono ?_) h_mem
rintro _ ⟨i, rfl⟩
exact ⟨integralBasis K i, (canonicalEmbedding.latticeBasis_apply K i).symm⟩
ext1 φ
rw [Pi.zero_apply]
by_cases hφ : ComplexEmbedding.IsReal φ
· apply Complex.ext
· rw [← embedding_mk_eq_of_isReal hφ, ← commMap_apply_of_isReal K x ⟨φ, hφ, rfl⟩]
exact congrFun (congrArg (fun x => x.1) h_zero) ⟨InfinitePlace.mk φ, _⟩
· rw [Complex.zero_im, ← Complex.conj_eq_iff_im, canonicalEmbedding.conj_apply _ h_mem,
ComplexEmbedding.isReal_iff.mp hφ]
· have := congrFun (congrArg (fun x => x.2) h_zero) ⟨InfinitePlace.mk φ, ⟨φ, hφ, rfl⟩⟩
cases embedding_mk_eq φ with
| inl h => rwa [← h, ← commMap_apply_of_isComplex K x ⟨φ, hφ, rfl⟩]
| inr h =>
apply RingHom.injective (starRingEnd ℂ)
rwa [canonicalEmbedding.conj_apply _ h_mem, ← h, map_zero,
← commMap_apply_of_isComplex K x ⟨φ, hφ, rfl⟩]
end commMap
noncomputable section norm
open scoped Classical
variable {K}
/-- The norm at the infinite place `w` of an element of
`({w // IsReal w} → ℝ) × ({ w // IsComplex w } → ℂ)`. -/
def normAtPlace (w : InfinitePlace K) : (E K) →*₀ ℝ where
toFun x := if hw : IsReal w then ‖x.1 ⟨w, hw⟩‖ else ‖x.2 ⟨w, not_isReal_iff_isComplex.mp hw⟩‖
map_zero' := by simp
map_one' := by simp
map_mul' x y := by split_ifs <;> simp
theorem normAtPlace_nonneg (w : InfinitePlace K) (x : E K) :
0 ≤ normAtPlace w x := by
rw [normAtPlace, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk]
split_ifs <;> exact norm_nonneg _
theorem normAtPlace_neg (w : InfinitePlace K) (x : E K) :
normAtPlace w (- x) = normAtPlace w x := by
rw [normAtPlace, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk]
split_ifs <;> simp
theorem normAtPlace_add_le (w : InfinitePlace K) (x y : E K) :
normAtPlace w (x + y) ≤ normAtPlace w x + normAtPlace w y := by
rw [normAtPlace, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk]
split_ifs <;> exact norm_add_le _ _
theorem normAtPlace_smul (w : InfinitePlace K) (x : E K) (c : ℝ) :
normAtPlace w (c • x) = |c| * normAtPlace w x := by
rw [normAtPlace, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk]
split_ifs
· rw [Prod.smul_fst, Pi.smul_apply, norm_smul, Real.norm_eq_abs]
· rw [Prod.smul_snd, Pi.smul_apply, norm_smul, Real.norm_eq_abs, Complex.norm_eq_abs]
theorem normAtPlace_real (w : InfinitePlace K) (c : ℝ) :
normAtPlace w ((fun _ ↦ c, fun _ ↦ c) : (E K)) = |c| := by
rw [show ((fun _ ↦ c, fun _ ↦ c) : (E K)) = c • 1 by ext <;> simp, normAtPlace_smul, map_one,
mul_one]
theorem normAtPlace_apply_isReal {w : InfinitePlace K} (hw : IsReal w) (x : E K) :
normAtPlace w x = ‖x.1 ⟨w, hw⟩‖ := by
rw [normAtPlace, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk, dif_pos]
theorem normAtPlace_apply_isComplex {w : InfinitePlace K} (hw : IsComplex w) (x : E K) :
normAtPlace w x = ‖x.2 ⟨w, hw⟩‖ := by
rw [normAtPlace, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk,
dif_neg (not_isReal_iff_isComplex.mpr hw)]
@[simp]
theorem normAtPlace_apply (w : InfinitePlace K) (x : K) :
normAtPlace w (mixedEmbedding K x) = w x := by
simp_rw [normAtPlace, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk, mixedEmbedding,
RingHom.prod_apply, Pi.ringHom_apply, norm_embedding_of_isReal, norm_embedding_eq, dite_eq_ite,
ite_id]
theorem normAtPlace_eq_zero {x : E K} :
(∀ w, normAtPlace w x = 0) ↔ x = 0 := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· ext w
· exact norm_eq_zero'.mp (normAtPlace_apply_isReal w.prop _ ▸ h w.1)
· exact norm_eq_zero'.mp (normAtPlace_apply_isComplex w.prop _ ▸ h w.1)
· simp_rw [h, map_zero, implies_true]
variable [NumberField K]
theorem nnnorm_eq_sup_normAtPlace (x : E K) :
‖x‖₊ = univ.sup fun w ↦ ⟨normAtPlace w x, normAtPlace_nonneg w x⟩ := by
have :
(univ : Finset (InfinitePlace K)) =
(univ.image (fun w : {w : InfinitePlace K // IsReal w} ↦ w.1)) ∪
(univ.image (fun w : {w : InfinitePlace K // IsComplex w} ↦ w.1)) := by
ext; simp [isReal_or_isComplex]
rw [this, sup_union, univ.sup_image, univ.sup_image, sup_eq_max,
Prod.nnnorm_def', Pi.nnnorm_def, Pi.nnnorm_def]
congr
· ext w
simp [normAtPlace_apply_isReal w.prop]
· ext w
simp [normAtPlace_apply_isComplex w.prop]
theorem norm_eq_sup'_normAtPlace (x : E K) :
‖x‖ = univ.sup' univ_nonempty fun w ↦ normAtPlace w x := by
rw [← coe_nnnorm, nnnorm_eq_sup_normAtPlace, ← sup'_eq_sup univ_nonempty, ← NNReal.val_eq_coe,
← OrderHom.Subtype.val_coe, map_finset_sup', OrderHom.Subtype.val_coe]
simp only [Function.comp_apply]
/-- The norm of `x` is `∏ w, (normAtPlace x) ^ mult w`. It is defined such that the norm of
`mixedEmbedding K a` for `a : K` is equal to the absolute value of the norm of `a` over `ℚ`,
see `norm_eq_norm`. -/
protected def norm : (E K) →*₀ ℝ where
toFun x := ∏ w, (normAtPlace w x) ^ (mult w)
map_one' := by simp only [map_one, one_pow, prod_const_one]
map_zero' := by simp [mult]
map_mul' _ _ := by simp only [map_mul, mul_pow, prod_mul_distrib]
protected theorem norm_apply (x : E K) :
mixedEmbedding.norm x = ∏ w, (normAtPlace w x) ^ (mult w) := rfl
protected theorem norm_nonneg (x : E K) :
0 ≤ mixedEmbedding.norm x := univ.prod_nonneg fun _ _ ↦ pow_nonneg (normAtPlace_nonneg _ _) _
protected theorem norm_eq_zero_iff {x : E K} :
mixedEmbedding.norm x = 0 ↔ ∃ w, normAtPlace w x = 0 := by
simp_rw [mixedEmbedding.norm, MonoidWithZeroHom.coe_mk, ZeroHom.coe_mk, prod_eq_zero_iff,
mem_univ, true_and, pow_eq_zero_iff mult_ne_zero]
protected theorem norm_ne_zero_iff {x : E K} :
mixedEmbedding.norm x ≠ 0 ↔ ∀ w, normAtPlace w x ≠ 0 := by
rw [← not_iff_not]
simp_rw [ne_eq, mixedEmbedding.norm_eq_zero_iff, not_not, not_forall, not_not]
theorem norm_smul (c : ℝ) (x : E K) :
mixedEmbedding.norm (c • x) = |c| ^ finrank ℚ K * (mixedEmbedding.norm x) := by
simp_rw [mixedEmbedding.norm_apply, normAtPlace_smul, mul_pow, prod_mul_distrib,
prod_pow_eq_pow_sum, sum_mult_eq]
theorem norm_real (c : ℝ) :
mixedEmbedding.norm ((fun _ ↦ c, fun _ ↦ c) : (E K)) = |c| ^ finrank ℚ K := by
rw [show ((fun _ ↦ c, fun _ ↦ c) : (E K)) = c • 1 by ext <;> simp, norm_smul, map_one, mul_one]
@[simp]
theorem norm_eq_norm (x : K) :
mixedEmbedding.norm (mixedEmbedding K x) = |Algebra.norm ℚ x| := by
simp_rw [mixedEmbedding.norm_apply, normAtPlace_apply, prod_eq_abs_norm]
theorem norm_eq_zero_iff' {x : E K} (hx : x ∈ Set.range (mixedEmbedding K)) :
mixedEmbedding.norm x = 0 ↔ x = 0 := by
obtain ⟨a, rfl⟩ := hx
rw [norm_eq_norm, Rat.cast_abs, abs_eq_zero, Rat.cast_eq_zero, Algebra.norm_eq_zero_iff,
map_eq_zero]
end norm
noncomputable section stdBasis
open scoped Classical
open Complex MeasureTheory MeasureTheory.Measure Zspan Matrix ComplexConjugate
variable [NumberField K]
/-- The type indexing the basis `stdBasis`. -/
abbrev index := {w : InfinitePlace K // IsReal w} ⊕ ({w : InfinitePlace K // IsComplex w}) × (Fin 2)
/-- The `ℝ`-basis of `({w // IsReal w} → ℝ) × ({ w // IsComplex w } → ℂ)` formed by the vector
equal to `1` at `w` and `0` elsewhere for `IsReal w` and by the couple of vectors equal to `1`
(resp. `I`) at `w` and `0` elsewhere for `IsComplex w`. -/
def stdBasis : Basis (index K) ℝ (E K) :=
Basis.prod (Pi.basisFun ℝ _)
(Basis.reindex (Pi.basis fun _ => basisOneI) (Equiv.sigmaEquivProd _ _))
variable {K}
@[simp]
theorem stdBasis_apply_ofIsReal (x : E K) (w : {w : InfinitePlace K // IsReal w}) :
(stdBasis K).repr x (Sum.inl w) = x.1 w := rfl
@[simp]
theorem stdBasis_apply_ofIsComplex_fst (x : E K) (w : {w : InfinitePlace K // IsComplex w}) :
(stdBasis K).repr x (Sum.inr ⟨w, 0⟩) = (x.2 w).re := rfl
@[simp]
theorem stdBasis_apply_ofIsComplex_snd (x : E K) (w : {w : InfinitePlace K // IsComplex w}) :
(stdBasis K).repr x (Sum.inr ⟨w, 1⟩) = (x.2 w).im := rfl
variable (K)
theorem fundamentalDomain_stdBasis :
fundamentalDomain (stdBasis K) =
(Set.univ.pi fun _ => Set.Ico 0 1) ×ˢ
(Set.univ.pi fun _ => Complex.measurableEquivPi⁻¹' (Set.univ.pi fun _ => Set.Ico 0 1)) := by
ext
simp [stdBasis, mem_fundamentalDomain, Complex.measurableEquivPi]
theorem volume_fundamentalDomain_stdBasis :
volume (fundamentalDomain (stdBasis K)) = 1 := by
rw [fundamentalDomain_stdBasis, volume_eq_prod, prod_prod, volume_pi, volume_pi, pi_pi, pi_pi,
Complex.volume_preserving_equiv_pi.measure_preimage ?_, volume_pi, pi_pi, Real.volume_Ico,
sub_zero, ENNReal.ofReal_one, prod_const_one, prod_const_one, prod_const_one, one_mul]
exact (MeasurableSet.pi Set.countable_univ (fun _ _ => measurableSet_Ico)).nullMeasurableSet
/-- The `Equiv` between `index K` and `K →+* ℂ` defined by sending a real infinite place `w` to
the unique corresponding embedding `w.embedding`, and the pair `⟨w, 0⟩` (resp. `⟨w, 1⟩`) for a
complex infinite place `w` to `w.embedding` (resp. `conjugate w.embedding`). -/
def indexEquiv : (index K) ≃ (K →+* ℂ) := by
refine Equiv.ofBijective (fun c => ?_)
((Fintype.bijective_iff_surjective_and_card _).mpr ⟨?_, ?_⟩)
· cases c with
| inl w => exact w.val.embedding
| inr wj => rcases wj with ⟨w, j⟩
exact if j = 0 then w.val.embedding else ComplexEmbedding.conjugate w.val.embedding
· intro φ
by_cases hφ : ComplexEmbedding.IsReal φ
· exact ⟨Sum.inl (InfinitePlace.mkReal ⟨φ, hφ⟩), by simp [embedding_mk_eq_of_isReal hφ]⟩
· by_cases hw : (InfinitePlace.mk φ).embedding = φ
· exact ⟨Sum.inr ⟨InfinitePlace.mkComplex ⟨φ, hφ⟩, 0⟩, by simp [hw]⟩
· exact ⟨Sum.inr ⟨InfinitePlace.mkComplex ⟨φ, hφ⟩, 1⟩,
by simp [(embedding_mk_eq φ).resolve_left hw]⟩
· rw [Embeddings.card, ← mixedEmbedding.finrank K,
← FiniteDimensional.finrank_eq_card_basis (stdBasis K)]
variable {K}
@[simp]
theorem indexEquiv_apply_ofIsReal (w : {w : InfinitePlace K // IsReal w}) :
(indexEquiv K) (Sum.inl w) = w.val.embedding := rfl
@[simp]
theorem indexEquiv_apply_ofIsComplex_fst (w : {w : InfinitePlace K // IsComplex w}) :
(indexEquiv K) (Sum.inr ⟨w, 0⟩) = w.val.embedding := rfl
@[simp]
theorem indexEquiv_apply_ofIsComplex_snd (w : {w : InfinitePlace K // IsComplex w}) :
(indexEquiv K) (Sum.inr ⟨w, 1⟩) = ComplexEmbedding.conjugate w.val.embedding := rfl
variable (K)
/-- The matrix that gives the representation on `stdBasis` of the image by `commMap` of an
element `x` of `(K →+* ℂ) → ℂ` fixed by the map `x_φ ↦ conj x_(conjugate φ)`,
see `stdBasis_repr_eq_matrixToStdBasis_mul`. -/
def matrixToStdBasis : Matrix (index K) (index K) ℂ :=
fromBlocks (diagonal fun _ => 1) 0 0 <| reindex (Equiv.prodComm _ _) (Equiv.prodComm _ _)
(blockDiagonal (fun _ => (2 : ℂ)⁻¹ • !![1, 1; - I, I]))
theorem det_matrixToStdBasis :
(matrixToStdBasis K).det = (2⁻¹ * I) ^ NrComplexPlaces K :=
calc
_ = ∏ _k : { w : InfinitePlace K // IsComplex w }, det ((2 : ℂ)⁻¹ • !![1, 1; -I, I]) := by
rw [matrixToStdBasis, det_fromBlocks_zero₂₁, det_diagonal, prod_const_one, one_mul,
det_reindex_self, det_blockDiagonal]
_ = ∏ _k : { w : InfinitePlace K // IsComplex w }, (2⁻¹ * Complex.I) := by
refine prod_congr (Eq.refl _) (fun _ _ => ?_)
field_simp; ring
_ = (2⁻¹ * Complex.I) ^ Fintype.card {w : InfinitePlace K // IsComplex w} := by
rw [prod_const, Fintype.card]
/-- Let `x : (K →+* ℂ) → ℂ` such that `x_φ = conj x_(conj φ)` for all `φ : K →+* ℂ`, then the
representation of `commMap K x` on `stdBasis` is given (up to reindexing) by the product of
`matrixToStdBasis` by `x`. -/
theorem stdBasis_repr_eq_matrixToStdBasis_mul (x : (K →+* ℂ) → ℂ)
(hx : ∀ φ, conj (x φ) = x (ComplexEmbedding.conjugate φ)) (c : index K) :
((stdBasis K).repr (commMap K x) c : ℂ) =
(matrixToStdBasis K *ᵥ (x ∘ (indexEquiv K))) c := by
simp_rw [commMap, matrixToStdBasis, LinearMap.coe_mk, AddHom.coe_mk,
mulVec, dotProduct, Function.comp_apply, index, Fintype.sum_sum_type,
diagonal_one, reindex_apply, ← univ_product_univ, sum_product,
indexEquiv_apply_ofIsReal, Fin.sum_univ_two, indexEquiv_apply_ofIsComplex_fst,
indexEquiv_apply_ofIsComplex_snd, smul_of, smul_cons, smul_eq_mul,
mul_one, Matrix.smul_empty, Equiv.prodComm_symm, Equiv.coe_prodComm]
cases c with
| inl w =>
simp_rw [stdBasis_apply_ofIsReal, fromBlocks_apply₁₁, fromBlocks_apply₁₂,
one_apply, Matrix.zero_apply, ite_mul, one_mul, zero_mul, sum_ite_eq, mem_univ, ite_true,
add_zero, sum_const_zero, add_zero, ← conj_eq_iff_re, hx (embedding w.val),
conjugate_embedding_eq_of_isReal w.prop]
| inr c =>
rcases c with ⟨w, j⟩
fin_cases j
· simp_rw [Fin.mk_zero, stdBasis_apply_ofIsComplex_fst, fromBlocks_apply₂₁,
fromBlocks_apply₂₂, Matrix.zero_apply, submatrix_apply,
blockDiagonal_apply, Prod.swap_prod_mk, ite_mul, zero_mul, sum_const_zero, zero_add,
sum_add_distrib, sum_ite_eq, mem_univ, ite_true, of_apply, cons_val', cons_val_zero,
cons_val_one, head_cons, ← hx (embedding w), re_eq_add_conj]
field_simp
· simp_rw [Fin.mk_one, stdBasis_apply_ofIsComplex_snd, fromBlocks_apply₂₁,
fromBlocks_apply₂₂, Matrix.zero_apply, submatrix_apply, blockDiagonal_apply,
Prod.swap_prod_mk, ite_mul, zero_mul, sum_const_zero, zero_add, sum_add_distrib, sum_ite_eq,
mem_univ, ite_true, of_apply, cons_val', cons_val_zero, cons_val_one, head_cons,
← hx (embedding w), im_eq_sub_conj]
ring_nf; field_simp
end stdBasis
noncomputable section integerLattice
variable [NumberField K]
open Module.Free
open scoped nonZeroDivisors
/-- A `ℝ`-basis of `ℝ^r₁ × ℂ^r₂` that is also a `ℤ`-basis of the image of `𝓞 K`. -/
def latticeBasis :
Basis (ChooseBasisIndex ℤ (𝓞 K)) ℝ (E K) := by
classical
-- We construct an `ℝ`-linear independent family from the image of
-- `canonicalEmbedding.lattice_basis` by `commMap`
have := LinearIndependent.map (LinearIndependent.restrict_scalars
(by { simpa only [Complex.real_smul, mul_one] using Complex.ofReal_injective })
(canonicalEmbedding.latticeBasis K).linearIndependent)
(disjoint_span_commMap_ker K)
-- and it's a basis since it has the right cardinality
refine basisOfLinearIndependentOfCardEqFinrank this ?_
rw [← finrank_eq_card_chooseBasisIndex, RingOfIntegers.rank, finrank_prod, finrank_pi,
finrank_pi_fintype, Complex.finrank_real_complex, sum_const, card_univ, ← NrRealPlaces,
← NrComplexPlaces, ← card_real_embeddings, Algebra.id.smul_eq_mul, mul_comm,
← card_complex_embeddings, ← NumberField.Embeddings.card K ℂ, Fintype.card_subtype_compl,
Nat.add_sub_of_le (Fintype.card_subtype_le _)]
@[simp]
theorem latticeBasis_apply (i : ChooseBasisIndex ℤ (𝓞 K)) :
latticeBasis K i = (mixedEmbedding K) (integralBasis K i) := by
simp only [latticeBasis, coe_basisOfLinearIndependentOfCardEqFinrank, Function.comp_apply,
canonicalEmbedding.latticeBasis_apply, integralBasis_apply, commMap_canonical_eq_mixed]
theorem mem_span_latticeBasis (x : (E K)) :
x ∈ Submodule.span ℤ (Set.range (latticeBasis K)) ↔
x ∈ ((mixedEmbedding K).comp (algebraMap (𝓞 K) K)).range := by
rw [show Set.range (latticeBasis K) =
(mixedEmbedding K).toIntAlgHom.toLinearMap '' (Set.range (integralBasis K)) by
rw [← Set.range_comp]; exact congrArg Set.range (funext (fun i => latticeBasis_apply K i))]
rw [← Submodule.map_span, ← SetLike.mem_coe, Submodule.map_coe]
simp only [Set.mem_image, SetLike.mem_coe, mem_span_integralBasis K,
RingHom.mem_range, exists_exists_eq_and]
rfl
theorem mem_rat_span_latticeBasis (x : K) :
mixedEmbedding K x ∈ Submodule.span ℚ (Set.range (latticeBasis K)) := by
rw [← Basis.sum_repr (integralBasis K) x, map_sum]
simp_rw [map_rat_smul]
refine Submodule.sum_smul_mem _ _ (fun i _ ↦ Submodule.subset_span ?_)
rw [← latticeBasis_apply]
exact Set.mem_range_self i
theorem latticeBasis_repr_apply (x : K) (i : ChooseBasisIndex ℤ (𝓞 K)) :
(latticeBasis K).repr (mixedEmbedding K x) i = (integralBasis K).repr x i := by
rw [← Basis.restrictScalars_repr_apply ℚ _ ⟨_, mem_rat_span_latticeBasis K x⟩, eq_ratCast,
Rat.cast_inj]
let f := (mixedEmbedding K).toRatAlgHom.toLinearMap.codRestrict _
(fun x ↦ mem_rat_span_latticeBasis K x)
suffices ((latticeBasis K).restrictScalars ℚ).repr.toLinearMap ∘ₗ f =
(integralBasis K).repr.toLinearMap from DFunLike.congr_fun (LinearMap.congr_fun this x) i
refine Basis.ext (integralBasis K) (fun i ↦ ?_)
have : f (integralBasis K i) = ((latticeBasis K).restrictScalars ℚ) i := by
apply Subtype.val_injective
rw [LinearMap.codRestrict_apply, AlgHom.toLinearMap_apply, Basis.restrictScalars_apply,
latticeBasis_apply]
rfl
simp_rw [LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, this, Basis.repr_self]
variable (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ)
/-- The generalized index of the lattice generated by `I` in the lattice generated by
`𝓞 K` is equal to the norm of the ideal `I`. The result is stated in terms of base change
determinant and is the translation of `NumberField.det_basisOfFractionalIdeal_eq_absNorm` in
`ℝ^r₁ × ℂ^r₂`. This is useful, in particular, to prove that the family obtained from
the `ℤ`-basis of `I` is actually an `ℝ`-basis of `ℝ^r₁ × ℂ^r₂`, see
`fractionalIdealLatticeBasis`. -/
theorem det_basisOfFractionalIdeal_eq_norm
(e : (ChooseBasisIndex ℤ (𝓞 K)) ≃ (ChooseBasisIndex ℤ I)) :
|Basis.det (latticeBasis K) ((mixedEmbedding K ∘ (basisOfFractionalIdeal K I) ∘ e))| =
FractionalIdeal.absNorm I.1 := by
suffices Basis.det (latticeBasis K) ((mixedEmbedding K ∘ (basisOfFractionalIdeal K I) ∘ e)) =
(algebraMap ℚ ℝ) ((Basis.det (integralBasis K)) ((basisOfFractionalIdeal K I) ∘ e)) by
rw [this, eq_ratCast, ← Rat.cast_abs, ← Equiv.symm_symm e, ← Basis.coe_reindex,
det_basisOfFractionalIdeal_eq_absNorm K I e]
rw [Basis.det_apply, Basis.det_apply, RingHom.map_det]
congr
ext i j
simp_rw [RingHom.mapMatrix_apply, Matrix.map_apply, Basis.toMatrix_apply, Function.comp_apply]
exact latticeBasis_repr_apply K _ i
/-- A `ℝ`-basis of `ℝ^r₁ × ℂ^r₂` that is also a `ℤ`-basis of the image of the fractional
ideal `I`. -/
def fractionalIdealLatticeBasis :
Basis (ChooseBasisIndex ℤ I) ℝ (E K) := by
let e : (ChooseBasisIndex ℤ (𝓞 K)) ≃ (ChooseBasisIndex ℤ I) := by
refine Fintype.equivOfCardEq ?_
rw [← finrank_eq_card_chooseBasisIndex, ← finrank_eq_card_chooseBasisIndex,
fractionalIdeal_rank]
refine Basis.reindex ?_ e
suffices IsUnit ((latticeBasis K).det ((mixedEmbedding K) ∘ (basisOfFractionalIdeal K I) ∘ e)) by
rw [← is_basis_iff_det] at this
exact Basis.mk this.1 (by rw [this.2])
rw [isUnit_iff_ne_zero, ne_eq, ← abs_eq_zero.not, det_basisOfFractionalIdeal_eq_norm,
Rat.cast_eq_zero, FractionalIdeal.absNorm_eq_zero_iff]
exact Units.ne_zero I
@[simp]
theorem fractionalIdealLatticeBasis_apply (i : ChooseBasisIndex ℤ I) :
fractionalIdealLatticeBasis K I i = (mixedEmbedding K) (basisOfFractionalIdeal K I i) := by
simp only [fractionalIdealLatticeBasis, Basis.coe_reindex, Basis.coe_mk, Function.comp_apply,
Equiv.apply_symm_apply]
theorem mem_span_fractionalIdealLatticeBasis (x : (E K)) :
x ∈ Submodule.span ℤ (Set.range (fractionalIdealLatticeBasis K I)) ↔
x ∈ mixedEmbedding K '' I := by
rw [show Set.range (fractionalIdealLatticeBasis K I) =
(mixedEmbedding K).toIntAlgHom.toLinearMap '' (Set.range (basisOfFractionalIdeal K I)) by
rw [← Set.range_comp]
exact congr_arg Set.range (funext (fun i ↦ fractionalIdealLatticeBasis_apply K I i))]
rw [← Submodule.map_span, ← SetLike.mem_coe, Submodule.map_coe]
rw [show Submodule.span ℤ (Set.range (basisOfFractionalIdeal K I)) = (I : Set K) by
ext; erw [mem_span_basisOfFractionalIdeal]]
rfl
end integerLattice
end NumberField.mixedEmbedding
|
NumberTheory\NumberField\CanonicalEmbedding\ConvexBody.lean | /-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.MeasureTheory.Group.GeometryOfNumbers
import Mathlib.MeasureTheory.Measure.Lebesgue.VolumeOfBalls
import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.Basic
/-!
# Convex Bodies
The file contains the definitions of several convex bodies lying in the space `ℝ^r₁ × ℂ^r₂`
associated to a number field of signature `K` and proves several existence theorems by applying
*Minkowski Convex Body Theorem* to those.
## Main definitions and results
* `NumberField.mixedEmbedding.convexBodyLT`: The set of points `x` such that `‖x w‖ < f w` for all
infinite places `w` with `f : InfinitePlace K → ℝ≥0`.
* `NumberField.mixedEmbedding.convexBodySum`: The set of points `x` such that
`∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B`
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_lt`: Let `I` be a fractional ideal of `K`.
Assume that `f` is such that `minkowskiBound K I < volume (convexBodyLT K f)`, then there exists a
nonzero algebraic number `a` in `I` such that `w a < f w` for all infinite places `w`.
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_of_norm_le`: Let `I` be a fractional ideal
of `K`. Assume that `B` is such that `minkowskiBound K I < volume (convexBodySum K B)` (see
`convexBodySum_volume` for the computation of this volume), then there exists a nonzero algebraic
number `a` in `I` such that `|Norm a| < (B / d) ^ d` where `d` is the degree of `K`.
## Tags
number field, infinite places
-/
variable (K : Type*) [Field K]
namespace NumberField.mixedEmbedding
open NumberField NumberField.InfinitePlace FiniteDimensional
/-- The space `ℝ^r₁ × ℂ^r₂` with `(r₁, r₂)` the signature of `K`. -/
local notation "E" K =>
({w : InfinitePlace K // IsReal w} → ℝ) × ({w : InfinitePlace K // IsComplex w} → ℂ)
section convexBodyLT
open Metric NNReal
variable (f : InfinitePlace K → ℝ≥0)
/-- The convex body defined by `f`: the set of points `x : E` such that `‖x w‖ < f w` for all
infinite places `w`. -/
abbrev convexBodyLT : Set (E K) :=
(Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } => ball 0 (f w))) ×ˢ
(Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } => ball 0 (f w)))
theorem convexBodyLT_mem {x : K} :
mixedEmbedding K x ∈ (convexBodyLT K f) ↔ ∀ w : InfinitePlace K, w x < f w := by
simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ,
forall_true_left, mem_ball_zero_iff, Pi.ringHom_apply, ← Complex.norm_real,
embedding_of_isReal_apply, Subtype.forall, ← forall₂_or_left, ← not_isReal_iff_isComplex, em,
forall_true_left, norm_embedding_eq]
theorem convexBodyLT_neg_mem (x : E K) (hx : x ∈ (convexBodyLT K f)) :
-x ∈ (convexBodyLT K f) := by
simp only [Set.mem_prod, Prod.fst_neg, Set.mem_pi, Set.mem_univ, Pi.neg_apply,
mem_ball_zero_iff, norm_neg, Real.norm_eq_abs, forall_true_left, Subtype.forall,
Prod.snd_neg, Complex.norm_eq_abs] at hx ⊢
exact hx
theorem convexBodyLT_convex : Convex ℝ (convexBodyLT K f) :=
Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => convex_ball _ _))
open Fintype MeasureTheory MeasureTheory.Measure ENNReal
open scoped Classical
variable [NumberField K]
instance : IsAddHaarMeasure (volume : Measure (E K)) := prod.instIsAddHaarMeasure volume volume
instance : NoAtoms (volume : Measure (E K)) := by
obtain ⟨w⟩ := (inferInstance : Nonempty (InfinitePlace K))
by_cases hw : IsReal w
· exact @prod.instNoAtoms_fst _ _ _ _ volume volume _ (pi_noAtoms ⟨w, hw⟩)
· exact @prod.instNoAtoms_snd _ _ _ _ volume volume _
(pi_noAtoms ⟨w, not_isReal_iff_isComplex.mp hw⟩)
/-- The fudge factor that appears in the formula for the volume of `convexBodyLT`. -/
noncomputable abbrev convexBodyLTFactor : ℝ≥0 :=
(2 : ℝ≥0) ^ NrRealPlaces K * NNReal.pi ^ NrComplexPlaces K
theorem convexBodyLTFactor_ne_zero : convexBodyLTFactor K ≠ 0 :=
mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero)
theorem one_le_convexBodyLTFactor : 1 ≤ convexBodyLTFactor K :=
one_le_mul₀ (one_le_pow_of_one_le one_le_two _)
(one_le_pow_of_one_le (le_trans one_le_two Real.two_le_pi) _)
/-- The volume of `(ConvexBodyLt K f)` where `convexBodyLT K f` is the set of points `x`
such that `‖x w‖ < f w` for all infinite places `w`. -/
theorem convexBodyLT_volume :
volume (convexBodyLT K f) = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by
calc
_ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) *
∏ x : {w // InfinitePlace.IsComplex w}, ENNReal.ofReal (f x.val) ^ 2 * NNReal.pi := by
simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball, Complex.volume_ball]
_ = ((2 : ℝ≥0) ^ NrRealPlaces K
* (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val)))
* ((∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) *
NNReal.pi ^ NrComplexPlaces K) := by
simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const,
Finset.card_univ, ofReal_ofNat, ofReal_coe_nnreal, coe_ofNat]
_ = (convexBodyLTFactor K) * ((∏ x : {w // InfinitePlace.IsReal w}, .ofReal (f x.val)) *
(∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2)) := by
simp_rw [convexBodyLTFactor, coe_mul, ENNReal.coe_pow]
ring
_ = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by
simp_rw [mult, pow_ite, pow_one, Finset.prod_ite, ofReal_coe_nnreal, not_isReal_iff_isComplex,
coe_mul, coe_finset_prod, ENNReal.coe_pow]
congr 2
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞))).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞) ^ 2)).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
variable {f}
/-- This is a technical result: quite often, we want to impose conditions at all infinite places
but one and choose the value at the remaining place so that we can apply
`exists_ne_zero_mem_ringOfIntegers_lt`. -/
theorem adjust_f {w₁ : InfinitePlace K} (B : ℝ≥0) (hf : ∀ w, w ≠ w₁ → f w ≠ 0) :
∃ g : InfinitePlace K → ℝ≥0, (∀ w, w ≠ w₁ → g w = f w) ∧ ∏ w, (g w) ^ mult w = B := by
let S := ∏ w ∈ Finset.univ.erase w₁, (f w) ^ mult w
refine ⟨Function.update f w₁ ((B * S⁻¹) ^ (mult w₁ : ℝ)⁻¹), ?_, ?_⟩
· exact fun w hw => Function.update_noteq hw _ f
· rw [← Finset.mul_prod_erase Finset.univ _ (Finset.mem_univ w₁), Function.update_same,
Finset.prod_congr rfl fun w hw => by rw [Function.update_noteq (Finset.ne_of_mem_erase hw)],
← NNReal.rpow_natCast, ← NNReal.rpow_mul, inv_mul_cancel, NNReal.rpow_one, mul_assoc,
inv_mul_cancel, mul_one]
· rw [Finset.prod_ne_zero_iff]
exact fun w hw => pow_ne_zero _ (hf w (Finset.ne_of_mem_erase hw))
· rw [mult]; split_ifs <;> norm_num
end convexBodyLT
section convexBodyLT'
open Metric ENNReal NNReal
open scoped Classical
variable (f : InfinitePlace K → ℝ≥0) (w₀ : {w : InfinitePlace K // IsComplex w})
/-- A version of `convexBodyLT` with an additional condition at a fixed complex place. This is
needed to ensure the element constructed is not real, see for example
`exists_primitive_element_lt_of_isComplex`.
-/
abbrev convexBodyLT' : Set (E K) :=
(Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } ↦ ball 0 (f w))) ×ˢ
(Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } ↦
if w = w₀ then {x | |x.re| < 1 ∧ |x.im| < (f w : ℝ) ^ 2} else ball 0 (f w)))
theorem convexBodyLT'_mem {x : K} :
mixedEmbedding K x ∈ convexBodyLT' K f w₀ ↔
(∀ w : InfinitePlace K, w ≠ w₀ → w x < f w) ∧
|(w₀.val.embedding x).re| < 1 ∧ |(w₀.val.embedding x).im| < (f w₀ : ℝ) ^ 2 := by
simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ,
forall_true_left, Pi.ringHom_apply, apply_ite, mem_ball_zero_iff, ← Complex.norm_real,
embedding_of_isReal_apply, norm_embedding_eq, Subtype.forall, Set.mem_setOf_eq]
refine ⟨fun ⟨h₁, h₂⟩ ↦ ⟨fun w h_ne ↦ ?_, ?_⟩, fun ⟨h₁, h₂⟩ ↦ ⟨fun w hw ↦ ?_, fun w hw ↦ ?_⟩⟩
· by_cases hw : IsReal w
· exact norm_embedding_eq w _ ▸ h₁ w hw
· specialize h₂ w (not_isReal_iff_isComplex.mp hw)
rwa [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)] at h₂
· simpa [if_true] using h₂ w₀.val w₀.prop
· exact h₁ w (ne_of_isReal_isComplex hw w₀.prop)
· by_cases h_ne : w = w₀
· simpa [h_ne]
· rw [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)]
exact h₁ w h_ne
theorem convexBodyLT'_neg_mem (x : E K) (hx : x ∈ convexBodyLT' K f w₀) :
-x ∈ convexBodyLT' K f w₀ := by
simp only [Set.mem_prod, Set.mem_pi, Set.mem_univ, mem_ball, dist_zero_right, Real.norm_eq_abs,
true_implies, Subtype.forall, Prod.fst_neg, Pi.neg_apply, norm_neg, Prod.snd_neg] at hx ⊢
convert hx using 3
split_ifs <;> simp
theorem convexBodyLT'_convex : Convex ℝ (convexBodyLT' K f w₀) := by
refine Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => ?_))
split_ifs
· simp_rw [abs_lt]
refine Convex.inter ((convex_halfspace_re_gt _).inter (convex_halfspace_re_lt _))
((convex_halfspace_im_gt _).inter (convex_halfspace_im_lt _))
· exact convex_ball _ _
open MeasureTheory MeasureTheory.Measure
open scoped Classical
variable [NumberField K]
/-- The fudge factor that appears in the formula for the volume of `convexBodyLT'`. -/
noncomputable abbrev convexBodyLT'Factor : ℝ≥0 :=
(2 : ℝ≥0) ^ (NrRealPlaces K + 2) * NNReal.pi ^ (NrComplexPlaces K - 1)
theorem convexBodyLT'Factor_ne_zero : convexBodyLT'Factor K ≠ 0 :=
mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero)
theorem one_le_convexBodyLT'Factor : 1 ≤ convexBodyLT'Factor K :=
one_le_mul₀ (one_le_pow_of_one_le one_le_two _)
(one_le_pow_of_one_le (le_trans one_le_two Real.two_le_pi) _)
theorem convexBodyLT'_volume :
volume (convexBodyLT' K f w₀) = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by
have vol_box : ∀ B : ℝ≥0, volume {x : ℂ | |x.re| < 1 ∧ |x.im| < B^2} = 4*B^2 := by
intro B
rw [← (Complex.volume_preserving_equiv_real_prod.symm).measure_preimage]
· simp_rw [Set.preimage_setOf_eq, Complex.measurableEquivRealProd_symm_apply]
rw [show {a : ℝ × ℝ | |a.1| < 1 ∧ |a.2| < B ^ 2} =
Set.Ioo (-1 : ℝ) (1 : ℝ) ×ˢ Set.Ioo (- (B : ℝ) ^ 2) ((B : ℝ) ^ 2) by
ext; simp_rw [Set.mem_setOf_eq, Set.mem_prod, Set.mem_Ioo, abs_lt]]
simp_rw [volume_eq_prod, prod_prod, Real.volume_Ioo, sub_neg_eq_add, one_add_one_eq_two,
← two_mul, ofReal_mul zero_le_two, ofReal_pow (coe_nonneg B), ofReal_ofNat,
ofReal_coe_nnreal, ← mul_assoc, show (2 : ℝ≥0∞) * 2 = 4 by norm_num]
· refine (MeasurableSet.inter ?_ ?_).nullMeasurableSet
· exact measurableSet_lt (measurable_norm.comp Complex.measurable_re) measurable_const
· exact measurableSet_lt (measurable_norm.comp Complex.measurable_im) measurable_const
calc
_ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) *
((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2 * pi) *
(4 * (f w₀) ^ 2)) := by
simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball]
rw [← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀)]
congr 2
· refine Finset.prod_congr rfl (fun w' hw' ↦ ?_)
rw [if_neg (Finset.ne_of_mem_erase hw'), Complex.volume_ball]
· simpa only [ite_true] using vol_box (f w₀)
_ = ((2 : ℝ≥0) ^ NrRealPlaces K *
(∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))) *
((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2) *
↑pi ^ (NrComplexPlaces K - 1) * (4 * (f w₀) ^ 2)) := by
simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const,
Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, ofReal_ofNat,
ofReal_coe_nnreal, coe_ofNat]
_ = convexBodyLT'Factor K * (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))
* (∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) := by
rw [show (4 : ℝ≥0∞) = (2 : ℝ≥0) ^ 2 by norm_num, convexBodyLT'Factor, pow_add,
← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀), ofReal_coe_nnreal]
simp_rw [coe_mul, ENNReal.coe_pow]
ring
_ = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by
simp_rw [mult, pow_ite, pow_one, Finset.prod_ite, ofReal_coe_nnreal, not_isReal_iff_isComplex,
coe_mul, coe_finset_prod, ENNReal.coe_pow, mul_assoc]
congr 3
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞))).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
· refine (Finset.prod_subtype (Finset.univ.filter _) ?_ (fun w => (f w : ℝ≥0∞) ^ 2)).symm
exact fun _ => by simp only [Finset.mem_univ, forall_true_left, Finset.mem_filter, true_and]
end convexBodyLT'
section convexBodySum
open ENNReal MeasureTheory Fintype
open scoped Real Classical NNReal
variable [NumberField K] (B : ℝ)
variable {K}
/-- The function that sends `x : ({w // IsReal w} → ℝ) × ({w // IsComplex w} → ℂ)` to
`∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖`. It defines a norm and it used to define `convexBodySum`. -/
noncomputable abbrev convexBodySumFun (x : E K) : ℝ := ∑ w, mult w * normAtPlace w x
theorem convexBodySumFun_apply (x : E K) :
convexBodySumFun x = ∑ w, mult w * normAtPlace w x := rfl
theorem convexBodySumFun_apply' (x : E K) :
convexBodySumFun x = ∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖ := by
simp_rw [convexBodySumFun_apply, ← Finset.sum_add_sum_compl {w | IsReal w}.toFinset,
Set.toFinset_setOf, Finset.compl_filter, not_isReal_iff_isComplex, ← Finset.subtype_univ,
← Finset.univ.sum_subtype_eq_sum_filter, Finset.mul_sum]
congr
· ext w
rw [mult, if_pos w.prop, normAtPlace_apply_isReal, Nat.cast_one, one_mul]
· ext w
rw [mult, if_neg (not_isReal_iff_isComplex.mpr w.prop), normAtPlace_apply_isComplex,
Nat.cast_ofNat]
theorem convexBodySumFun_nonneg (x : E K) :
0 ≤ convexBodySumFun x :=
Finset.sum_nonneg (fun _ _ => mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _))
theorem convexBodySumFun_neg (x : E K) :
convexBodySumFun (- x) = convexBodySumFun x := by
simp_rw [convexBodySumFun, normAtPlace_neg]
theorem convexBodySumFun_add_le (x y : E K) :
convexBodySumFun (x + y) ≤ convexBodySumFun x + convexBodySumFun y := by
simp_rw [convexBodySumFun, ← Finset.sum_add_distrib, ← mul_add]
exact Finset.sum_le_sum
fun _ _ ↦ mul_le_mul_of_nonneg_left (normAtPlace_add_le _ x y) (Nat.cast_pos.mpr mult_pos).le
theorem convexBodySumFun_smul (c : ℝ) (x : E K) :
convexBodySumFun (c • x) = |c| * convexBodySumFun x := by
simp_rw [convexBodySumFun, normAtPlace_smul, ← mul_assoc, mul_comm, Finset.mul_sum, mul_assoc]
theorem convexBodySumFun_eq_zero_iff (x : E K) :
convexBodySumFun x = 0 ↔ x = 0 := by
rw [← normAtPlace_eq_zero, convexBodySumFun, Finset.sum_eq_zero_iff_of_nonneg fun _ _ =>
mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _)]
conv =>
enter [1, w, hw]
rw [mul_left_mem_nonZeroDivisors_eq_zero_iff
(mem_nonZeroDivisors_iff_ne_zero.mpr <| Nat.cast_ne_zero.mpr mult_ne_zero)]
simp_rw [Finset.mem_univ, true_implies]
theorem norm_le_convexBodySumFun (x : E K) : ‖x‖ ≤ convexBodySumFun x := by
rw [norm_eq_sup'_normAtPlace]
refine (Finset.sup'_le_iff _ _).mpr fun w _ ↦ ?_
rw [convexBodySumFun_apply, ← Finset.univ.add_sum_erase _ (Finset.mem_univ w)]
refine le_add_of_le_of_nonneg ?_ ?_
· exact le_mul_of_one_le_left (normAtPlace_nonneg w x) one_le_mult
· exact Finset.sum_nonneg (fun _ _ => mul_nonneg (Nat.cast_pos.mpr mult_pos).le
(normAtPlace_nonneg _ _))
variable (K)
theorem convexBodySumFun_continuous :
Continuous (convexBodySumFun : (E K) → ℝ) := by
refine continuous_finset_sum Finset.univ fun w ↦ ?_
obtain hw | hw := isReal_or_isComplex w
all_goals
· simp only [normAtPlace_apply_isReal, normAtPlace_apply_isComplex, hw]
fun_prop
/-- The convex body equal to the set of points `x : E` such that
`∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B`. -/
abbrev convexBodySum : Set (E K) := { x | convexBodySumFun x ≤ B }
theorem convexBodySum_volume_eq_zero_of_le_zero {B} (hB : B ≤ 0) :
volume (convexBodySum K B) = 0 := by
obtain hB | hB := lt_or_eq_of_le hB
· suffices convexBodySum K B = ∅ by rw [this, measure_empty]
ext x
refine ⟨fun hx => ?_, fun h => h.elim⟩
rw [Set.mem_setOf] at hx
linarith [convexBodySumFun_nonneg x]
· suffices convexBodySum K B = { 0 } by rw [this, measure_singleton]
ext
rw [convexBodySum, Set.mem_setOf_eq, Set.mem_singleton_iff, hB, ← convexBodySumFun_eq_zero_iff]
exact (convexBodySumFun_nonneg _).le_iff_eq
theorem convexBodySum_mem {x : K} :
mixedEmbedding K x ∈ (convexBodySum K B) ↔
∑ w : InfinitePlace K, (mult w) * w.val x ≤ B := by
simp_rw [Set.mem_setOf_eq, convexBodySumFun, normAtPlace_apply]
rfl
theorem convexBodySum_neg_mem {x : E K} (hx : x ∈ (convexBodySum K B)) :
-x ∈ (convexBodySum K B) := by
rw [Set.mem_setOf, convexBodySumFun_neg]
exact hx
theorem convexBodySum_convex : Convex ℝ (convexBodySum K B) := by
refine Convex_subadditive_le (fun _ _ => convexBodySumFun_add_le _ _) (fun c x h => ?_) B
convert le_of_eq (convexBodySumFun_smul c x)
exact (abs_eq_self.mpr h).symm
theorem convexBodySum_isBounded : Bornology.IsBounded (convexBodySum K B) := by
refine Metric.isBounded_iff.mpr ⟨B + B, fun x hx y hy => ?_⟩
refine le_trans (norm_sub_le x y) (add_le_add ?_ ?_)
· exact le_trans (norm_le_convexBodySumFun x) hx
· exact le_trans (norm_le_convexBodySumFun y) hy
theorem convexBodySum_compact : IsCompact (convexBodySum K B) := by
rw [Metric.isCompact_iff_isClosed_bounded]
refine ⟨?_, convexBodySum_isBounded K B⟩
convert IsClosed.preimage (convexBodySumFun_continuous K) (isClosed_Icc : IsClosed (Set.Icc 0 B))
ext
simp [convexBodySumFun_nonneg]
/-- The fudge factor that appears in the formula for the volume of `convexBodyLt`. -/
noncomputable abbrev convexBodySumFactor : ℝ≥0 :=
(2 : ℝ≥0) ^ NrRealPlaces K * (NNReal.pi / 2) ^ NrComplexPlaces K / (finrank ℚ K).factorial
theorem convexBodySumFactor_ne_zero : convexBodySumFactor K ≠ 0 := by
refine div_ne_zero ?_ <| Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _)
exact mul_ne_zero (pow_ne_zero _ two_ne_zero)
(pow_ne_zero _ (div_ne_zero NNReal.pi_ne_zero two_ne_zero))
open MeasureTheory MeasureTheory.Measure Real in
theorem convexBodySum_volume :
volume (convexBodySum K B) = (convexBodySumFactor K) * (.ofReal B) ^ (finrank ℚ K) := by
obtain hB | hB := le_or_lt B 0
· rw [convexBodySum_volume_eq_zero_of_le_zero K hB, ofReal_eq_zero.mpr hB, zero_pow, mul_zero]
exact finrank_pos.ne'
· suffices volume (convexBodySum K 1) = (convexBodySumFactor K) by
rw [mul_comm]
convert addHaar_smul volume B (convexBodySum K 1)
· simp_rw [← Set.preimage_smul_inv₀ (ne_of_gt hB), Set.preimage_setOf_eq, convexBodySumFun,
normAtPlace_smul, abs_inv, abs_eq_self.mpr (le_of_lt hB), ← mul_assoc, mul_comm, mul_assoc,
← Finset.mul_sum, inv_mul_le_iff hB, mul_one]
· rw [abs_pow, ofReal_pow (abs_nonneg _), abs_eq_self.mpr (le_of_lt hB),
mixedEmbedding.finrank]
· exact this.symm
rw [MeasureTheory.measure_le_eq_lt _ ((convexBodySumFun_eq_zero_iff 0).mpr rfl)
convexBodySumFun_neg convexBodySumFun_add_le
(fun hx => (convexBodySumFun_eq_zero_iff _).mp hx)
(fun r x => le_of_eq (convexBodySumFun_smul r x))]
rw [measure_lt_one_eq_integral_div_gamma (g := fun x : (E K) => convexBodySumFun x)
volume ((convexBodySumFun_eq_zero_iff 0).mpr rfl) convexBodySumFun_neg convexBodySumFun_add_le
(fun hx => (convexBodySumFun_eq_zero_iff _).mp hx)
(fun r x => le_of_eq (convexBodySumFun_smul r x)) zero_lt_one]
simp_rw [mixedEmbedding.finrank, div_one, Gamma_nat_eq_factorial, ofReal_div_of_pos
(Nat.cast_pos.mpr (Nat.factorial_pos _)), Real.rpow_one, ofReal_natCast]
suffices ∫ x : E K, exp (-convexBodySumFun x) =
(2 : ℝ) ^ NrRealPlaces K * (π / 2) ^ NrComplexPlaces K by
rw [this, convexBodySumFactor, ofReal_mul (by positivity), ofReal_pow zero_le_two,
ofReal_pow (by positivity), ofReal_div_of_pos zero_lt_two, ofReal_ofNat,
← NNReal.coe_real_pi, ofReal_coe_nnreal, coe_div (Nat.cast_ne_zero.mpr
(Nat.factorial_ne_zero _)), coe_mul, coe_pow, coe_pow, coe_ofNat, coe_div two_ne_zero,
coe_ofNat, coe_natCast]
calc
_ = (∫ x : {w : InfinitePlace K // IsReal w} → ℝ, ∏ w, exp (- ‖x w‖)) *
(∫ x : {w : InfinitePlace K // IsComplex w} → ℂ, ∏ w, exp (- 2 * ‖x w‖)) := by
simp_rw [convexBodySumFun_apply', neg_add, ← neg_mul, Finset.mul_sum,
← Finset.sum_neg_distrib, exp_add, exp_sum, ← integral_prod_mul, volume_eq_prod]
_ = (∫ x : ℝ, exp (-|x|)) ^ NrRealPlaces K *
(∫ x : ℂ, Real.exp (-2 * ‖x‖)) ^ NrComplexPlaces K := by
rw [integral_fintype_prod_eq_pow _ (fun x => exp (- ‖x‖)), integral_fintype_prod_eq_pow _
(fun x => exp (- 2 * ‖x‖))]
simp_rw [norm_eq_abs]
_ = (2 * Gamma (1 / 1 + 1)) ^ NrRealPlaces K *
(π * (2 : ℝ) ^ (-(2 : ℝ) / 1) * Gamma (2 / 1 + 1)) ^ NrComplexPlaces K := by
rw [integral_comp_abs (f := fun x => exp (- x)), ← integral_exp_neg_rpow zero_lt_one,
← Complex.integral_exp_neg_mul_rpow le_rfl zero_lt_two]
simp_rw [Real.rpow_one]
_ = (2 : ℝ) ^ NrRealPlaces K * (π / 2) ^ NrComplexPlaces K := by
simp_rw [div_one, one_add_one_eq_two, Gamma_add_one two_ne_zero, Gamma_two, mul_one,
mul_assoc, ← Real.rpow_add_one two_ne_zero, show (-2 : ℝ) + 1 = -1 by norm_num,
Real.rpow_neg_one]
rfl
end convexBodySum
section minkowski
open scoped Classical
open MeasureTheory MeasureTheory.Measure FiniteDimensional Zspan Real Submodule
open scoped ENNReal NNReal nonZeroDivisors IntermediateField
variable [NumberField K] (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ)
/-- The bound that appears in **Minkowski Convex Body theorem**, see
`MeasureTheory.exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure`. See
`NumberField.mixedEmbedding.volume_fundamentalDomain_idealLatticeBasis_eq` and
`NumberField.mixedEmbedding.volume_fundamentalDomain_latticeBasis` for the computation of
`volume (fundamentalDomain (idealLatticeBasis K))`. -/
noncomputable def minkowskiBound : ℝ≥0∞ :=
volume (fundamentalDomain (fractionalIdealLatticeBasis K I)) * (2 : ℝ≥0∞) ^ (finrank ℝ (E K))
theorem volume_fundamentalDomain_fractionalIdealLatticeBasis :
volume (fundamentalDomain (fractionalIdealLatticeBasis K I)) =
.ofReal (FractionalIdeal.absNorm I.1) * volume (fundamentalDomain (latticeBasis K)) := by
let e : (Module.Free.ChooseBasisIndex ℤ I) ≃ (Module.Free.ChooseBasisIndex ℤ (𝓞 K)) := by
refine Fintype.equivOfCardEq ?_
rw [← finrank_eq_card_chooseBasisIndex, ← finrank_eq_card_chooseBasisIndex,
fractionalIdeal_rank]
rw [← fundamentalDomain_reindex (fractionalIdealLatticeBasis K I) e,
measure_fundamentalDomain ((fractionalIdealLatticeBasis K I).reindex e)]
· rw [show (fractionalIdealLatticeBasis K I).reindex e = (mixedEmbedding K) ∘
(basisOfFractionalIdeal K I) ∘ e.symm by
ext1; simp only [Basis.coe_reindex, Function.comp_apply, fractionalIdealLatticeBasis_apply]]
rw [mixedEmbedding.det_basisOfFractionalIdeal_eq_norm]
theorem minkowskiBound_lt_top : minkowskiBound K I < ⊤ := by
refine ENNReal.mul_lt_top ?_ ?_
· exact ne_of_lt (fundamentalDomain_isBounded _).measure_lt_top
· exact ne_of_lt (ENNReal.pow_lt_top (lt_top_iff_ne_top.mpr ENNReal.two_ne_top) _)
theorem minkowskiBound_pos : 0 < minkowskiBound K I := by
refine zero_lt_iff.mpr (mul_ne_zero ?_ ?_)
· exact Zspan.measure_fundamentalDomain_ne_zero _
· exact ENNReal.pow_ne_zero two_ne_zero _
variable {f : InfinitePlace K → ℝ≥0} (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ)
/-- Let `I` be a fractional ideal of `K`. Assume that `f : InfinitePlace K → ℝ≥0` is such that
`minkowskiBound K I < volume (convexBodyLT K f)` where `convexBodyLT K f` is the set of
points `x` such that `‖x w‖ < f w` for all infinite places `w` (see `convexBodyLT_volume` for
the computation of this volume), then there exists a nonzero algebraic number `a` in `I` such
that `w a < f w` for all infinite places `w`. -/
theorem exists_ne_zero_mem_ideal_lt (h : minkowskiBound K I < volume (convexBodyLT K f)) :
∃ a ∈ (I : FractionalIdeal (𝓞 K)⁰ K), a ≠ 0 ∧ ∀ w : InfinitePlace K, w a < f w := by
have h_fund := Zspan.isAddFundamentalDomain (fractionalIdealLatticeBasis K I) volume
have : Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I))).toAddSubgroup := by
change Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I)) : Set (E K))
infer_instance
obtain ⟨⟨x, hx⟩, h_nz, h_mem⟩ := exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure
h_fund (convexBodyLT_neg_mem K f) (convexBodyLT_convex K f) h
rw [mem_toAddSubgroup, mem_span_fractionalIdealLatticeBasis] at hx
obtain ⟨a, ha, rfl⟩ := hx
exact ⟨a, ha, by simpa using h_nz, (convexBodyLT_mem K f).mp h_mem⟩
/-- A version of `exists_ne_zero_mem_ideal_lt` where the absolute value of the real part of `a` is
smaller than `1` at some fixed complex place. This is useful to ensure that `a` is not real. -/
theorem exists_ne_zero_mem_ideal_lt' (w₀ : {w : InfinitePlace K // IsComplex w})
(h : minkowskiBound K I < volume (convexBodyLT' K f w₀)) :
∃ a ∈ (I : FractionalIdeal (𝓞 K)⁰ K), a ≠ 0 ∧ (∀ w : InfinitePlace K, w ≠ w₀ → w a < f w) ∧
|(w₀.val.embedding a).re| < 1 ∧ |(w₀.val.embedding a).im| < (f w₀ : ℝ) ^ 2 := by
have h_fund := Zspan.isAddFundamentalDomain (fractionalIdealLatticeBasis K I) volume
have : Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I))).toAddSubgroup := by
change Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I)) : Set (E K))
infer_instance
obtain ⟨⟨x, hx⟩, h_nz, h_mem⟩ := exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure
h_fund (convexBodyLT'_neg_mem K f w₀) (convexBodyLT'_convex K f w₀) h
rw [mem_toAddSubgroup, mem_span_fractionalIdealLatticeBasis] at hx
obtain ⟨a, ha, rfl⟩ := hx
exact ⟨a, ha, by simpa using h_nz, (convexBodyLT'_mem K f w₀).mp h_mem⟩
/-- A version of `exists_ne_zero_mem_ideal_lt` for the ring of integers of `K`. -/
theorem exists_ne_zero_mem_ringOfIntegers_lt (h : minkowskiBound K ↑1 < volume (convexBodyLT K f)) :
∃ a : 𝓞 K, a ≠ 0 ∧ ∀ w : InfinitePlace K, w a < f w := by
obtain ⟨_, h_mem, h_nz, h_bd⟩ := exists_ne_zero_mem_ideal_lt K ↑1 h
obtain ⟨a, rfl⟩ := (FractionalIdeal.mem_one_iff _).mp h_mem
exact ⟨a, RingOfIntegers.coe_ne_zero_iff.mp h_nz, h_bd⟩
/-- A version of `exists_ne_zero_mem_ideal_lt'` for the ring of integers of `K`. -/
theorem exists_ne_zero_mem_ringOfIntegers_lt' (w₀ : {w : InfinitePlace K // IsComplex w})
(h : minkowskiBound K ↑1 < volume (convexBodyLT' K f w₀)) :
∃ a : 𝓞 K, a ≠ 0 ∧ (∀ w : InfinitePlace K, w ≠ w₀ → w a < f w) ∧
|(w₀.val.embedding a).re| < 1 ∧ |(w₀.val.embedding a).im| < (f w₀ : ℝ) ^ 2 := by
obtain ⟨_, h_mem, h_nz, h_bd⟩ := exists_ne_zero_mem_ideal_lt' K ↑1 w₀ h
obtain ⟨a, rfl⟩ := (FractionalIdeal.mem_one_iff _).mp h_mem
exact ⟨a, RingOfIntegers.coe_ne_zero_iff.mp h_nz, h_bd⟩
theorem exists_primitive_element_lt_of_isReal {w₀ : InfinitePlace K} (hw₀ : IsReal w₀) {B : ℝ≥0}
(hB : minkowskiBound K ↑1 < convexBodyLTFactor K * B) :
∃ a : 𝓞 K, ℚ⟮(a : K)⟯ = ⊤ ∧
∀ w : InfinitePlace K, w a < max B 1 := by
have : minkowskiBound K ↑1 < volume (convexBodyLT K (fun w ↦ if w = w₀ then B else 1)) := by
rw [convexBodyLT_volume, ← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀)]
simp_rw [ite_pow, one_pow]
rw [Finset.prod_ite_eq']
simp_rw [Finset.not_mem_erase, ite_false, mult, hw₀, ite_true, one_mul, pow_one]
exact hB
obtain ⟨a, h_nz, h_le⟩ := exists_ne_zero_mem_ringOfIntegers_lt K this
refine ⟨a, ?_, fun w ↦ lt_of_lt_of_le (h_le w) ?_⟩
· exact is_primitive_element_of_infinitePlace_lt h_nz
(fun w h_ne ↦ by convert (if_neg h_ne) ▸ h_le w) (Or.inl hw₀)
· split_ifs <;> simp
theorem exists_primitive_element_lt_of_isComplex {w₀ : InfinitePlace K} (hw₀ : IsComplex w₀)
{B : ℝ≥0} (hB : minkowskiBound K ↑1 < convexBodyLT'Factor K * B) :
∃ a : 𝓞 K, ℚ⟮(a : K)⟯ = ⊤ ∧
∀ w : InfinitePlace K, w a < Real.sqrt (1 + B ^ 2) := by
have : minkowskiBound K ↑1 <
volume (convexBodyLT' K (fun w ↦ if w = w₀ then NNReal.sqrt B else 1) ⟨w₀, hw₀⟩) := by
rw [convexBodyLT'_volume, ← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀)]
simp_rw [ite_pow, one_pow]
rw [Finset.prod_ite_eq']
simp_rw [Finset.not_mem_erase, ite_false, mult, not_isReal_iff_isComplex.mpr hw₀,
ite_true, ite_false, one_mul, NNReal.sq_sqrt]
exact hB
obtain ⟨a, h_nz, h_le, h_le₀⟩ := exists_ne_zero_mem_ringOfIntegers_lt' K ⟨w₀, hw₀⟩ this
refine ⟨a, ?_, fun w ↦ ?_⟩
· exact is_primitive_element_of_infinitePlace_lt h_nz
(fun w h_ne ↦ by convert if_neg h_ne ▸ h_le w h_ne) (Or.inr h_le₀.1)
· by_cases h_eq : w = w₀
· rw [if_pos rfl] at h_le₀
dsimp only at h_le₀
rw [h_eq, ← norm_embedding_eq, Real.lt_sqrt (norm_nonneg _), ← Complex.re_add_im
(embedding w₀ _), Complex.norm_eq_abs, Complex.abs_add_mul_I, Real.sq_sqrt (by positivity)]
refine add_lt_add ?_ ?_
· rw [← sq_abs, sq_lt_one_iff (abs_nonneg _)]
exact h_le₀.1
· rw [sq_lt_sq, NNReal.abs_eq, ← NNReal.sq_sqrt B]
exact h_le₀.2
· refine lt_of_lt_of_le (if_neg h_eq ▸ h_le w h_eq) ?_
rw [NNReal.coe_one, Real.le_sqrt' zero_lt_one, one_pow]
norm_num
/-- Let `I` be a fractional ideal of `K`. Assume that `B : ℝ` is such that
`minkowskiBound K I < volume (convexBodySum K B)` where `convexBodySum K B` is the set of points
`x` such that `∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B` (see `convexBodySum_volume` for
the computation of this volume), then there exists a nonzero algebraic number `a` in `I` such
that `|Norm a| < (B / d) ^ d` where `d` is the degree of `K`. -/
theorem exists_ne_zero_mem_ideal_of_norm_le {B : ℝ}
(h : (minkowskiBound K I) ≤ volume (convexBodySum K B)) :
∃ a ∈ (I : FractionalIdeal (𝓞 K)⁰ K), a ≠ 0 ∧
|Algebra.norm ℚ (a : K)| ≤ (B / finrank ℚ K) ^ finrank ℚ K := by
have hB : 0 ≤ B := by
contrapose! h
rw [convexBodySum_volume_eq_zero_of_le_zero K (le_of_lt h)]
exact minkowskiBound_pos K I
-- Some inequalities that will be useful later on
have h1 : 0 < (finrank ℚ K : ℝ)⁻¹ := inv_pos.mpr (Nat.cast_pos.mpr finrank_pos)
have h2 : 0 ≤ B / (finrank ℚ K) := div_nonneg hB (Nat.cast_nonneg _)
have h_fund := Zspan.isAddFundamentalDomain (fractionalIdealLatticeBasis K I) volume
have : Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I))).toAddSubgroup := by
change Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I)) : Set (E K))
infer_instance
obtain ⟨⟨x, hx⟩, h_nz, h_mem⟩ := exists_ne_zero_mem_lattice_of_measure_mul_two_pow_le_measure
h_fund (fun _ ↦ convexBodySum_neg_mem K B) (convexBodySum_convex K B)
(convexBodySum_compact K B) h
rw [mem_toAddSubgroup, mem_span_fractionalIdealLatticeBasis] at hx
obtain ⟨a, ha, rfl⟩ := hx
refine ⟨a, ha, by simpa using h_nz, ?_⟩
rw [← rpow_natCast, ← rpow_le_rpow_iff (by simp only [Rat.cast_abs, abs_nonneg])
(rpow_nonneg h2 _) h1, ← rpow_mul h2, mul_inv_cancel (Nat.cast_ne_zero.mpr
(ne_of_gt finrank_pos)), rpow_one, le_div_iff' (Nat.cast_pos.mpr finrank_pos)]
refine le_trans ?_ ((convexBodySum_mem K B).mp h_mem)
rw [← le_div_iff' (Nat.cast_pos.mpr finrank_pos), ← sum_mult_eq, Nat.cast_sum]
refine le_trans ?_ (geom_mean_le_arith_mean Finset.univ _ _ (fun _ _ => Nat.cast_nonneg _)
?_ (fun _ _ => AbsoluteValue.nonneg _ _))
· simp_rw [← prod_eq_abs_norm, rpow_natCast]
exact le_of_eq rfl
· rw [← Nat.cast_sum, sum_mult_eq, Nat.cast_pos]
exact finrank_pos
theorem exists_ne_zero_mem_ringOfIntegers_of_norm_le {B : ℝ}
(h : (minkowskiBound K ↑1) ≤ volume (convexBodySum K B)) :
∃ a : 𝓞 K, a ≠ 0 ∧ |Algebra.norm ℚ (a : K)| ≤ (B / finrank ℚ K) ^ finrank ℚ K := by
obtain ⟨_, h_mem, h_nz, h_bd⟩ := exists_ne_zero_mem_ideal_of_norm_le K ↑1 h
obtain ⟨a, rfl⟩ := (FractionalIdeal.mem_one_iff _).mp h_mem
exact ⟨a, RingOfIntegers.coe_ne_zero_iff.mp h_nz, h_bd⟩
end minkowski
end NumberField.mixedEmbedding
|
NumberTheory\NumberField\Units\Basic.lean | /-
Copyright (c) 2023 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.NumberTheory.NumberField.Embeddings
/-!
# Units of a number field
We prove some basic results on the group `(𝓞 K)ˣ` of units of the ring of integers `𝓞 K` of a number
field `K` and its torsion subgroup.
## Main definition
* `NumberField.Units.torsion`: the torsion subgroup of a number field.
## Main results
* `NumberField.isUnit_iff_norm`: an algebraic integer `x : 𝓞 K` is a unit if and only if
`|norm ℚ x| = 1`.
* `NumberField.Units.mem_torsion`: a unit `x : (𝓞 K)ˣ` is torsion iff `w x = 1` for all infinite
places `w` of `K`.
## Tags
number field, units
-/
open scoped NumberField
noncomputable section
open NumberField Units
section Rat
theorem Rat.RingOfIntegers.isUnit_iff {x : 𝓞 ℚ} : IsUnit x ↔ (x : ℚ) = 1 ∨ (x : ℚ) = -1 := by
simp_rw [(isUnit_map_iff (Rat.ringOfIntegersEquiv : 𝓞 ℚ →+* ℤ) x).symm, Int.isUnit_iff,
RingEquiv.coe_toRingHom, RingEquiv.map_eq_one_iff, RingEquiv.map_eq_neg_one_iff, ←
Subtype.coe_injective.eq_iff]; rfl
end Rat
variable (K : Type*) [Field K]
section IsUnit
variable {K}
theorem NumberField.isUnit_iff_norm [NumberField K] {x : 𝓞 K} :
IsUnit x ↔ |(RingOfIntegers.norm ℚ x : ℚ)| = 1 := by
convert (RingOfIntegers.isUnit_norm ℚ (F := K)).symm
rw [← abs_one, abs_eq_abs, ← Rat.RingOfIntegers.isUnit_iff]
end IsUnit
namespace NumberField.Units
section coe
instance : CoeHTC (𝓞 K)ˣ K :=
⟨fun x => algebraMap _ K (Units.val x)⟩
theorem coe_injective : Function.Injective ((↑) : (𝓞 K)ˣ → K) :=
RingOfIntegers.coe_injective.comp Units.ext
variable {K}
theorem coe_coe (u : (𝓞 K)ˣ) : ((u : 𝓞 K) : K) = (u : K) := rfl
theorem coe_mul (x y : (𝓞 K)ˣ) : ((x * y : (𝓞 K)ˣ) : K) = (x : K) * (y : K) := rfl
theorem coe_pow (x : (𝓞 K)ˣ) (n : ℕ) : ((x ^ n : (𝓞 K)ˣ) : K) = (x : K) ^ n := by
rw [← map_pow, ← val_pow_eq_pow_val]
theorem coe_zpow (x : (𝓞 K)ˣ) (n : ℤ) : (↑(x ^ n) : K) = (x : K) ^ n := by
change ((Units.coeHom K).comp (map (algebraMap (𝓞 K) K))) (x ^ n) = _
exact map_zpow _ x n
theorem coe_one : ((1 : (𝓞 K)ˣ) : K) = (1 : K) := rfl
theorem coe_neg_one : ((-1 : (𝓞 K)ˣ) : K) = (-1 : K) := rfl
theorem coe_ne_zero (x : (𝓞 K)ˣ) : (x : K) ≠ 0 :=
Subtype.coe_injective.ne_iff.mpr (_root_.Units.ne_zero x)
end coe
open NumberField.InfinitePlace
@[simp]
protected theorem norm [NumberField K] (x : (𝓞 K)ˣ) :
|Algebra.norm ℚ (x : K)| = 1 := by
rw [← RingOfIntegers.coe_norm, isUnit_iff_norm.mp x.isUnit]
section torsion
/-- The torsion subgroup of the group of units. -/
def torsion : Subgroup (𝓞 K)ˣ := CommGroup.torsion (𝓞 K)ˣ
theorem mem_torsion {x : (𝓞 K)ˣ} [NumberField K] :
x ∈ torsion K ↔ ∀ w : InfinitePlace K, w x = 1 := by
rw [eq_iff_eq (x : K) 1, torsion, CommGroup.mem_torsion]
refine ⟨fun hx φ ↦ (((φ.comp $ algebraMap (𝓞 K) K).toMonoidHom.comp $
Units.coeHom _).isOfFinOrder hx).norm_eq_one, fun h ↦ isOfFinOrder_iff_pow_eq_one.2 ?_⟩
obtain ⟨n, hn, hx⟩ := Embeddings.pow_eq_one_of_norm_eq_one K ℂ x.val.isIntegral_coe h
exact ⟨n, hn, by ext; rw [NumberField.RingOfIntegers.coe_eq_algebraMap, coe_pow, hx,
NumberField.RingOfIntegers.coe_eq_algebraMap, coe_one]⟩
/-- The torsion subgroup is finite. -/
instance [NumberField K] : Fintype (torsion K) := by
refine @Fintype.ofFinite _ (Set.finite_coe_iff.mpr ?_)
refine Set.Finite.of_finite_image ?_ (coe_injective K).injOn
refine (Embeddings.finite_of_norm_le K ℂ 1).subset
(fun a ⟨u, ⟨h_tors, h_ua⟩⟩ => ⟨?_, fun φ => ?_⟩)
· rw [← h_ua]
exact u.val.prop
· rw [← h_ua]
exact le_of_eq ((eq_iff_eq _ 1).mp ((mem_torsion K).mp h_tors) φ)
instance : Nonempty (torsion K) := One.instNonempty
/-- The torsion subgroup is cylic. -/
instance [NumberField K] : IsCyclic (torsion K) := subgroup_units_cyclic _
/-- The order of the torsion subgroup as a positive integer. -/
def torsionOrder [NumberField K] : ℕ+ := ⟨Fintype.card (torsion K), Fintype.card_pos⟩
/-- If `k` does not divide `torsionOrder` then there are no nontrivial roots of unity of
order dividing `k`. -/
theorem rootsOfUnity_eq_one [NumberField K] {k : ℕ+} (hc : Nat.Coprime k (torsionOrder K))
{ζ : (𝓞 K)ˣ} : ζ ∈ rootsOfUnity k (𝓞 K) ↔ ζ = 1 := by
rw [mem_rootsOfUnity]
refine ⟨fun h => ?_, fun h => by rw [h, one_pow]⟩
refine orderOf_eq_one_iff.mp (Nat.eq_one_of_dvd_coprimes hc ?_ ?_)
· exact orderOf_dvd_of_pow_eq_one h
· have hζ : ζ ∈ torsion K := by
rw [torsion, CommGroup.mem_torsion, isOfFinOrder_iff_pow_eq_one]
exact ⟨k, k.prop, h⟩
rw [orderOf_submonoid (⟨ζ, hζ⟩ : torsion K)]
exact orderOf_dvd_card
/-- The group of roots of unity of order dividing `torsionOrder` is equal to the torsion
group. -/
theorem rootsOfUnity_eq_torsion [NumberField K] :
rootsOfUnity (torsionOrder K) (𝓞 K) = torsion K := by
ext ζ
rw [torsion, mem_rootsOfUnity]
refine ⟨fun h => ?_, fun h => ?_⟩
· rw [CommGroup.mem_torsion, isOfFinOrder_iff_pow_eq_one]
exact ⟨↑(torsionOrder K), (torsionOrder K).prop, h⟩
· exact Subtype.ext_iff.mp (@pow_card_eq_one (torsion K) _ _ ⟨ζ, h⟩)
end torsion
end Units
end NumberField
|
NumberTheory\NumberField\Units\DirichletTheorem.lean | /-
Copyright (c) 2023 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.LinearAlgebra.Matrix.Gershgorin
import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.ConvexBody
import Mathlib.NumberTheory.NumberField.Units.Basic
import Mathlib.RingTheory.RootsOfUnity.Basic
/-!
# Dirichlet theorem on the group of units of a number field
This file is devoted to the proof of Dirichlet unit theorem that states that the group of
units `(𝓞 K)ˣ` of units of the ring of integers `𝓞 K` of a number field `K` modulo its torsion
subgroup is a free `ℤ`-module of rank `card (InfinitePlace K) - 1`.
## Main definitions
* `NumberField.Units.rank`: the unit rank of the number field `K`.
* `NumberField.Units.fundSystem`: a fundamental system of units of `K`.
* `NumberField.Units.basisModTorsion`: a `ℤ`-basis of `(𝓞 K)ˣ ⧸ (torsion K)`
as an additive `ℤ`-module.
## Main results
* `NumberField.Units.rank_modTorsion`: the `ℤ`-rank of `(𝓞 K)ˣ ⧸ (torsion K)` is equal to
`card (InfinitePlace K) - 1`.
* `NumberField.Units.exist_unique_eq_mul_prod`: **Dirichlet Unit Theorem**. Any unit of `𝓞 K`
can be written uniquely as the product of a root of unity and powers of the units of the
fundamental system `fundSystem`.
## Tags
number field, units, Dirichlet unit theorem
-/
open scoped NumberField
noncomputable section
open NumberField NumberField.InfinitePlace NumberField.Units BigOperators
variable (K : Type*) [Field K]
namespace NumberField.Units.dirichletUnitTheorem
/-!
### Dirichlet Unit Theorem
We define a group morphism from `(𝓞 K)ˣ` to `{w : InfinitePlace K // w ≠ w₀} → ℝ` where `w₀` is a
distinguished (arbitrary) infinite place, prove that its kernel is the torsion subgroup (see
`logEmbedding_eq_zero_iff`) and that its image, called `unitLattice`, is a full `ℤ`-lattice. It
follows that `unitLattice` is a free `ℤ`-module (see `instModuleFree_unitLattice`) of rank
`card (InfinitePlaces K) - 1` (see `unitLattice_rank`). To prove that the `unitLattice` is a full
`ℤ`-lattice, we need to prove that it is discrete (see `unitLattice_inter_ball_finite`) and that it
spans the full space over `ℝ` (see `unitLattice_span_eq_top`); this is the main part of the proof,
see the section `span_top` below for more details.
-/
open scoped Classical
open Finset
variable {K}
section NumberField
variable [NumberField K]
/-- The distinguished infinite place. -/
def w₀ : InfinitePlace K := (inferInstance : Nonempty (InfinitePlace K)).some
variable (K)
/-- The logarithmic embedding of the units (seen as an `Additive` group). -/
def _root_.NumberField.Units.logEmbedding :
Additive ((𝓞 K)ˣ) →+ ({w : InfinitePlace K // w ≠ w₀} → ℝ) :=
{ toFun := fun x w => mult w.val * Real.log (w.val ↑(Additive.toMul x))
map_zero' := by simp; rfl
map_add' := fun _ _ => by simp [Real.log_mul, mul_add]; rfl }
variable {K}
@[simp]
theorem logEmbedding_component (x : (𝓞 K)ˣ) (w : {w : InfinitePlace K // w ≠ w₀}) :
(logEmbedding K x) w = mult w.val * Real.log (w.val x) := rfl
theorem sum_logEmbedding_component (x : (𝓞 K)ˣ) :
∑ w, logEmbedding K x w = - mult (w₀ : InfinitePlace K) * Real.log (w₀ (x : K)) := by
have h := congr_arg Real.log (prod_eq_abs_norm (x : K))
rw [Units.norm, Rat.cast_one, Real.log_one, Real.log_prod] at h
· simp_rw [Real.log_pow] at h
rw [← insert_erase (mem_univ w₀), sum_insert (not_mem_erase w₀ univ), add_comm,
add_eq_zero_iff_eq_neg] at h
convert h using 1
· refine (sum_subtype _ (fun w => ?_) (fun w => (mult w) * (Real.log (w (x : K))))).symm
exact ⟨ne_of_mem_erase, fun h => mem_erase_of_ne_of_mem h (mem_univ w)⟩
· norm_num
· exact fun w _ => pow_ne_zero _ (AbsoluteValue.ne_zero _ (coe_ne_zero x))
end NumberField
theorem mult_log_place_eq_zero {x : (𝓞 K)ˣ} {w : InfinitePlace K} :
mult w * Real.log (w x) = 0 ↔ w x = 1 := by
rw [mul_eq_zero, or_iff_right, Real.log_eq_zero, or_iff_right, or_iff_left]
· linarith [(apply_nonneg _ _ : 0 ≤ w x)]
· simp only [ne_eq, map_eq_zero, coe_ne_zero x, not_false_eq_true]
· refine (ne_of_gt ?_)
rw [mult]; split_ifs <;> norm_num
variable [NumberField K]
theorem logEmbedding_eq_zero_iff {x : (𝓞 K)ˣ} :
logEmbedding K x = 0 ↔ x ∈ torsion K := by
rw [mem_torsion]
refine ⟨fun h w => ?_, fun h => ?_⟩
· by_cases hw : w = w₀
· suffices -mult w₀ * Real.log (w₀ (x : K)) = 0 by
rw [neg_mul, neg_eq_zero, ← hw] at this
exact mult_log_place_eq_zero.mp this
rw [← sum_logEmbedding_component, sum_eq_zero]
exact fun w _ => congrFun h w
· exact mult_log_place_eq_zero.mp (congrFun h ⟨w, hw⟩)
· ext w
rw [logEmbedding_component, h w.val, Real.log_one, mul_zero, Pi.zero_apply]
theorem logEmbedding_component_le {r : ℝ} {x : (𝓞 K)ˣ} (hr : 0 ≤ r) (h : ‖logEmbedding K x‖ ≤ r)
(w : {w : InfinitePlace K // w ≠ w₀}) : |logEmbedding K x w| ≤ r := by
lift r to NNReal using hr
simp_rw [Pi.norm_def, NNReal.coe_le_coe, Finset.sup_le_iff, ← NNReal.coe_le_coe] at h
exact h w (mem_univ _)
theorem log_le_of_logEmbedding_le {r : ℝ} {x : (𝓞 K)ˣ} (hr : 0 ≤ r) (h : ‖logEmbedding K x‖ ≤ r)
(w : InfinitePlace K) : |Real.log (w x)| ≤ (Fintype.card (InfinitePlace K)) * r := by
have tool : ∀ x : ℝ, 0 ≤ x → x ≤ mult w * x := fun x hx => by
nth_rw 1 [← one_mul x]
refine mul_le_mul ?_ le_rfl hx ?_
all_goals { rw [mult]; split_ifs <;> norm_num }
by_cases hw : w = w₀
· have hyp := congr_arg (‖·‖) (sum_logEmbedding_component x).symm
replace hyp := (le_of_eq hyp).trans (norm_sum_le _ _)
simp_rw [norm_mul, norm_neg, Real.norm_eq_abs, Nat.abs_cast] at hyp
refine (le_trans ?_ hyp).trans ?_
· rw [← hw]
exact tool _ (abs_nonneg _)
· refine (sum_le_card_nsmul univ _ _
(fun w _ => logEmbedding_component_le hr h w)).trans ?_
rw [nsmul_eq_mul]
refine mul_le_mul ?_ le_rfl hr (Fintype.card (InfinitePlace K)).cast_nonneg
simp [card_univ]
· have hyp := logEmbedding_component_le hr h ⟨w, hw⟩
rw [logEmbedding_component, abs_mul, Nat.abs_cast] at hyp
refine (le_trans ?_ hyp).trans ?_
· exact tool _ (abs_nonneg _)
· nth_rw 1 [← one_mul r]
exact mul_le_mul (Nat.one_le_cast.mpr Fintype.card_pos) (le_of_eq rfl) hr (Nat.cast_nonneg _)
variable (K)
/-- The lattice formed by the image of the logarithmic embedding. -/
noncomputable def _root_.NumberField.Units.unitLattice :
AddSubgroup ({w : InfinitePlace K // w ≠ w₀} → ℝ) :=
AddSubgroup.map (logEmbedding K) ⊤
theorem unitLattice_inter_ball_finite (r : ℝ) :
((unitLattice K : Set ({ w : InfinitePlace K // w ≠ w₀} → ℝ)) ∩
Metric.closedBall 0 r).Finite := by
obtain hr | hr := lt_or_le r 0
· convert Set.finite_empty
rw [Metric.closedBall_eq_empty.mpr hr]
exact Set.inter_empty _
· suffices {x : (𝓞 K)ˣ | IsIntegral ℤ (x : K) ∧
∀ (φ : K →+* ℂ), ‖φ x‖ ≤ Real.exp ((Fintype.card (InfinitePlace K)) * r)}.Finite by
refine (Set.Finite.image (logEmbedding K) this).subset ?_
rintro _ ⟨⟨x, ⟨_, rfl⟩⟩, hx⟩
refine ⟨x, ⟨x.val.prop, (le_iff_le _ _).mp (fun w => (Real.log_le_iff_le_exp ?_).mp ?_)⟩, rfl⟩
· exact pos_iff.mpr (coe_ne_zero x)
· rw [mem_closedBall_zero_iff] at hx
exact (le_abs_self _).trans (log_le_of_logEmbedding_le hr hx w)
refine Set.Finite.of_finite_image ?_ (coe_injective K).injOn
refine (Embeddings.finite_of_norm_le K ℂ
(Real.exp ((Fintype.card (InfinitePlace K)) * r))).subset ?_
rintro _ ⟨x, ⟨⟨h_int, h_le⟩, rfl⟩⟩
exact ⟨h_int, h_le⟩
section span_top
/-!
#### Section `span_top`
In this section, we prove that the span over `ℝ` of the `unitLattice` is equal to the full space.
For this, we construct for each infinite place `w₁ ≠ w₀` a unit `u_w₁` of `K` such that, for all
infinite places `w` such that `w ≠ w₁`, we have `Real.log w (u_w₁) < 0`
(and thus `Real.log w₁ (u_w₁) > 0`). It follows then from a determinant computation
(using `Matrix.det_ne_zero_of_sum_col_lt_diag`) that the image by `logEmbedding` of these units is
a `ℝ`-linearly independent family. The unit `u_w₁` is obtained by constructing a sequence `seq n`
of nonzero algebraic integers that is strictly decreasing at infinite places distinct from `w₁` and
of norm `≤ B`. Since there are finitely many ideals of norm `≤ B`, there exists two term in the
sequence defining the same ideal and their quotient is the desired unit `u_w₁` (see `exists_unit`).
-/
open NumberField.mixedEmbedding NNReal
variable (w₁ : InfinitePlace K) {B : ℕ} (hB : minkowskiBound K 1 < (convexBodyLTFactor K) * B)
/-- This result shows that there always exists a next term in the sequence. -/
theorem seq_next {x : 𝓞 K} (hx : x ≠ 0) :
∃ y : 𝓞 K, y ≠ 0 ∧
(∀ w, w ≠ w₁ → w y < w x) ∧
|Algebra.norm ℚ (y : K)| ≤ B := by
have hx' := RingOfIntegers.coe_ne_zero_iff.mpr hx
let f : InfinitePlace K → ℝ≥0 :=
fun w => ⟨(w x) / 2, div_nonneg (AbsoluteValue.nonneg _ _) (by norm_num)⟩
suffices ∀ w, w ≠ w₁ → f w ≠ 0 by
obtain ⟨g, h_geqf, h_gprod⟩ := adjust_f K B this
obtain ⟨y, h_ynz, h_yle⟩ := exists_ne_zero_mem_ringOfIntegers_lt (f := g)
(by rw [convexBodyLT_volume]; convert hB; exact congr_arg ((↑) : NNReal → ENNReal) h_gprod)
refine ⟨y, h_ynz, fun w hw => (h_geqf w hw ▸ h_yle w).trans ?_, ?_⟩
· rw [← Rat.cast_le (K := ℝ), Rat.cast_natCast]
calc
_ = ∏ w : InfinitePlace K, w (algebraMap _ K y) ^ mult w :=
(prod_eq_abs_norm (algebraMap _ K y)).symm
_ ≤ ∏ w : InfinitePlace K, (g w : ℝ) ^ mult w := by
refine prod_le_prod ?_ ?_
· exact fun _ _ => pow_nonneg (by positivity) _
· exact fun w _ => pow_le_pow_left (by positivity) (le_of_lt (h_yle w)) (mult w)
_ ≤ (B : ℝ) := by
simp_rw [← NNReal.coe_pow, ← NNReal.coe_prod]
exact le_of_eq (congr_arg toReal h_gprod)
· refine div_lt_self ?_ (by norm_num)
exact pos_iff.mpr hx'
intro _ _
rw [ne_eq, Nonneg.mk_eq_zero, div_eq_zero_iff, map_eq_zero, not_or]
exact ⟨hx', by norm_num⟩
/-- An infinite sequence of nonzero algebraic integers of `K` satisfying the following properties:
• `seq n` is nonzero;
• for `w : InfinitePlace K`, `w ≠ w₁ → w (seq n+1) < w (seq n)`;
• `∣norm (seq n)∣ ≤ B`. -/
def seq : ℕ → { x : 𝓞 K // x ≠ 0 }
| 0 => ⟨1, by norm_num⟩
| n + 1 =>
⟨(seq_next K w₁ hB (seq n).prop).choose, (seq_next K w₁ hB (seq n).prop).choose_spec.1⟩
/-- The terms of the sequence are nonzero. -/
theorem seq_ne_zero (n : ℕ) : algebraMap (𝓞 K) K (seq K w₁ hB n) ≠ 0 :=
RingOfIntegers.coe_ne_zero_iff.mpr (seq K w₁ hB n).prop
/-- The terms of the sequence have nonzero norm. -/
theorem seq_norm_ne_zero (n : ℕ) : Algebra.norm ℤ (seq K w₁ hB n : 𝓞 K) ≠ 0 :=
Algebra.norm_ne_zero_iff.mpr (Subtype.coe_ne_coe.1 (seq_ne_zero K w₁ hB n))
/-- The sequence is strictly decreasing at infinite places distinct from `w₁`. -/
theorem seq_decreasing {n m : ℕ} (h : n < m) (w : InfinitePlace K) (hw : w ≠ w₁) :
w (algebraMap (𝓞 K) K (seq K w₁ hB m)) < w (algebraMap (𝓞 K) K (seq K w₁ hB n)) := by
induction m with
| zero =>
exfalso
exact Nat.not_succ_le_zero n h
| succ m m_ih =>
cases eq_or_lt_of_le (Nat.le_of_lt_succ h) with
| inl hr =>
rw [hr]
exact (seq_next K w₁ hB (seq K w₁ hB m).prop).choose_spec.2.1 w hw
| inr hr =>
refine lt_trans ?_ (m_ih hr)
exact (seq_next K w₁ hB (seq K w₁ hB m).prop).choose_spec.2.1 w hw
/-- The terms of the sequence have norm bounded by `B`. -/
theorem seq_norm_le (n : ℕ) :
Int.natAbs (Algebra.norm ℤ (seq K w₁ hB n : 𝓞 K)) ≤ B := by
cases n with
| zero =>
have : 1 ≤ B := by
contrapose! hB
simp only [Nat.lt_one_iff.mp hB, CharP.cast_eq_zero, mul_zero, zero_le]
simp only [ne_eq, seq, map_one, Int.natAbs_one, this]
| succ n =>
rw [← Nat.cast_le (α := ℚ), Int.cast_natAbs, Int.cast_abs, Algebra.coe_norm_int]
exact (seq_next K w₁ hB (seq K w₁ hB n).prop).choose_spec.2.2
/-- Construct a unit associated to the place `w₁`. The family, for `w₁ ≠ w₀`, formed by the
image by the `logEmbedding` of these units is `ℝ`-linearly independent, see
`unitLattice_span_eq_top`. -/
theorem exists_unit (w₁ : InfinitePlace K) :
∃ u : (𝓞 K)ˣ, ∀ w : InfinitePlace K, w ≠ w₁ → Real.log (w u) < 0 := by
obtain ⟨B, hB⟩ : ∃ B : ℕ, minkowskiBound K 1 < (convexBodyLTFactor K) * B := by
conv => congr; ext; rw [mul_comm]
exact ENNReal.exists_nat_mul_gt (ENNReal.coe_ne_zero.mpr (convexBodyLTFactor_ne_zero K))
(ne_of_lt (minkowskiBound_lt_top K 1))
rsuffices ⟨n, m, hnm, h⟩ : ∃ n m, n < m ∧
(Ideal.span ({ (seq K w₁ hB n : 𝓞 K) }) = Ideal.span ({ (seq K w₁ hB m : 𝓞 K) }))
· have hu := Ideal.span_singleton_eq_span_singleton.mp h
refine ⟨hu.choose, fun w hw => Real.log_neg ?_ ?_⟩
· exact pos_iff.mpr (coe_ne_zero _)
· calc
_ = w (algebraMap (𝓞 K) K (seq K w₁ hB m) * (algebraMap (𝓞 K) K (seq K w₁ hB n))⁻¹) := by
rw [← congr_arg (algebraMap (𝓞 K) K) hu.choose_spec, mul_comm, map_mul (algebraMap _ _),
← mul_assoc, inv_mul_cancel (seq_ne_zero K w₁ hB n), one_mul]
_ = w (algebraMap (𝓞 K) K (seq K w₁ hB m)) * w (algebraMap (𝓞 K) K (seq K w₁ hB n))⁻¹ :=
_root_.map_mul _ _ _
_ < 1 := by
rw [map_inv₀, mul_inv_lt_iff (pos_iff.mpr (seq_ne_zero K w₁ hB n)), mul_one]
exact seq_decreasing K w₁ hB hnm w hw
refine Set.Finite.exists_lt_map_eq_of_forall_mem
(t := { I : Ideal (𝓞 K) | 1 ≤ Ideal.absNorm I ∧ Ideal.absNorm I ≤ B })
(fun n => ?_) ?_
· rw [Set.mem_setOf_eq, Ideal.absNorm_span_singleton]
refine ⟨?_, seq_norm_le K w₁ hB n⟩
exact Nat.one_le_iff_ne_zero.mpr (Int.natAbs_ne_zero.mpr (seq_norm_ne_zero K w₁ hB n))
· rw [show { I : Ideal (𝓞 K) | 1 ≤ Ideal.absNorm I ∧ Ideal.absNorm I ≤ B } =
(⋃ n ∈ Set.Icc 1 B, { I : Ideal (𝓞 K) | Ideal.absNorm I = n }) by ext; simp]
exact Set.Finite.biUnion (Set.finite_Icc _ _) (fun n hn => Ideal.finite_setOf_absNorm_eq hn.1)
theorem unitLattice_span_eq_top :
Submodule.span ℝ (unitLattice K : Set ({w : InfinitePlace K // w ≠ w₀} → ℝ)) = ⊤ := by
refine le_antisymm le_top ?_
-- The standard basis
let B := Pi.basisFun ℝ {w : InfinitePlace K // w ≠ w₀}
-- The image by log_embedding of the family of units constructed above
let v := fun w : { w : InfinitePlace K // w ≠ w₀ } => logEmbedding K (exists_unit K w).choose
-- To prove the result, it is enough to prove that the family `v` is linearly independent
suffices B.det v ≠ 0 by
rw [← isUnit_iff_ne_zero, ← is_basis_iff_det] at this
rw [← this.2]
exact Submodule.span_monotone (fun _ ⟨w, hw⟩ =>
⟨(exists_unit K w).choose, trivial, by rw [← hw]⟩)
rw [Basis.det_apply]
-- We use a specific lemma to prove that this determinant is nonzero
refine det_ne_zero_of_sum_col_lt_diag (fun w => ?_)
simp_rw [Real.norm_eq_abs, B, Basis.coePiBasisFun.toMatrix_eq_transpose, Matrix.transpose_apply]
rw [← sub_pos, sum_congr rfl (fun x hx => abs_of_neg ?_), sum_neg_distrib, sub_neg_eq_add,
sum_erase_eq_sub (mem_univ _), ← add_comm_sub]
· refine add_pos_of_nonneg_of_pos ?_ ?_
· rw [sub_nonneg]
exact le_abs_self _
· rw [sum_logEmbedding_component (exists_unit K w).choose]
refine mul_pos_of_neg_of_neg ?_ ((exists_unit K w).choose_spec _ w.prop.symm)
rw [mult]; split_ifs <;> norm_num
· refine mul_neg_of_pos_of_neg ?_ ((exists_unit K w).choose_spec x ?_)
· rw [mult]; split_ifs <;> norm_num
· exact Subtype.ext_iff_val.not.mp (ne_of_mem_erase hx)
end span_top
end dirichletUnitTheorem
section statements
variable [NumberField K]
open scoped Classical
open dirichletUnitTheorem FiniteDimensional
/-- The unit rank of the number field `K`, it is equal to `card (InfinitePlace K) - 1`. -/
def rank : ℕ := Fintype.card (InfinitePlace K) - 1
instance instDiscrete_unitLattice : DiscreteTopology (unitLattice K) := by
refine discreteTopology_of_isOpen_singleton_zero ?_
refine isOpen_singleton_of_finite_mem_nhds 0 (s := Metric.closedBall 0 1) ?_ ?_
· exact Metric.closedBall_mem_nhds _ (by norm_num)
· refine Set.Finite.of_finite_image ?_ (Set.injOn_of_injective Subtype.val_injective)
convert unitLattice_inter_ball_finite K 1
ext x
refine ⟨?_, fun ⟨hx1, hx2⟩ => ⟨⟨x, hx1⟩, hx2, rfl⟩⟩
rintro ⟨x, hx, rfl⟩
exact ⟨Subtype.mem x, hx⟩
instance instZlattice_unitLattice : IsZlattice ℝ (unitLattice K) where
span_top := unitLattice_span_eq_top K
protected theorem finrank_eq_rank :
finrank ℝ ({w : InfinitePlace K // w ≠ w₀} → ℝ) = Units.rank K := by
simp only [finrank_fintype_fun_eq_card, Fintype.card_subtype_compl,
Fintype.card_ofSubsingleton, rank]
@[simp]
theorem unitLattice_rank :
finrank ℤ (unitLattice K) = Units.rank K := by
rw [← Units.finrank_eq_rank, Zlattice.rank ℝ]
/-- The map obtained by quotienting by the kernel of `logEmbedding`. -/
def logEmbeddingQuot :
Additive ((𝓞 K)ˣ ⧸ (torsion K)) →+ ({w : InfinitePlace K // w ≠ w₀} → ℝ) :=
MonoidHom.toAdditive' <|
(QuotientGroup.kerLift (AddMonoidHom.toMultiplicative' (logEmbedding K))).comp
(QuotientGroup.quotientMulEquivOfEq (by
ext
rw [MonoidHom.mem_ker, AddMonoidHom.toMultiplicative'_apply_apply, ofAdd_eq_one,
← logEmbedding_eq_zero_iff]
rfl)).toMonoidHom
@[simp]
theorem logEmbeddingQuot_apply (x : (𝓞 K)ˣ) :
logEmbeddingQuot K ⟦x⟧ = logEmbedding K x := rfl
theorem logEmbeddingQuot_injective :
Function.Injective (logEmbeddingQuot K) := by
unfold logEmbeddingQuot
intro _ _ h
simp_rw [MonoidHom.toAdditive'_apply_apply, MonoidHom.coe_comp, MulEquiv.coe_toMonoidHom,
Function.comp_apply, EmbeddingLike.apply_eq_iff_eq] at h
exact (EmbeddingLike.apply_eq_iff_eq _).mp <| (QuotientGroup.kerLift_injective _).eq_iff.mp h
#adaptation_note
/--
After https://github.com/leanprover/lean4/pull/4119
the `Module ℤ (Additive ((𝓞 K)ˣ ⧸ NumberField.Units.torsion K))` instance required below isn't found
unless we use `set_option maxSynthPendingDepth 2`, or add
explicit instances:
```
local instance : CommGroup (𝓞 K)ˣ := inferInstance
```
-/
set_option maxSynthPendingDepth 2 -- Note this is active for the remainder of the file.
/-- The linear equivalence between `(𝓞 K)ˣ ⧸ (torsion K)` as an additive `ℤ`-module and
`unitLattice` . -/
def logEmbeddingEquiv :
Additive ((𝓞 K)ˣ ⧸ (torsion K)) ≃ₗ[ℤ] (unitLattice K) :=
(AddEquiv.ofBijective (AddMonoidHom.codRestrict (logEmbeddingQuot K) _
(Quotient.ind fun x ↦ logEmbeddingQuot_apply K _ ▸ AddSubgroup.mem_map_of_mem _ trivial))
⟨fun _ _ ↦ by
rw [AddMonoidHom.codRestrict_apply, AddMonoidHom.codRestrict_apply, Subtype.mk.injEq]
apply logEmbeddingQuot_injective K, fun ⟨a, ⟨b, _, ha⟩⟩ ↦ ⟨⟦b⟧, by simp [ha]⟩⟩).toIntLinearEquiv
@[simp]
theorem logEmbeddingEquiv_apply (x : (𝓞 K)ˣ) :
logEmbeddingEquiv K ⟦x⟧ = logEmbedding K x := rfl
instance : Module.Free ℤ (Additive ((𝓞 K)ˣ ⧸ (torsion K))) :=
Module.Free.of_equiv (logEmbeddingEquiv K).symm
instance : Module.Finite ℤ (Additive ((𝓞 K)ˣ ⧸ (torsion K))) :=
Module.Finite.equiv (logEmbeddingEquiv K).symm
-- Note that we prove this instance first and then deduce from it the instance
-- `Monoid.FG (𝓞 K)ˣ`, and not the other way around, due to no `Subgroup` version
-- of `Submodule.fg_of_fg_map_of_fg_inf_ker` existing.
instance : Module.Finite ℤ (Additive (𝓞 K)ˣ) := by
rw [Module.finite_def]
refine Submodule.fg_of_fg_map_of_fg_inf_ker
(MonoidHom.toAdditive (QuotientGroup.mk' (torsion K))).toIntLinearMap ?_ ?_
· rw [Submodule.map_top, LinearMap.range_eq_top.mpr
(by exact QuotientGroup.mk'_surjective (torsion K)), ← Module.finite_def]
infer_instance
· rw [inf_of_le_right le_top, AddMonoidHom.coe_toIntLinearMap_ker, MonoidHom.coe_toAdditive_ker,
QuotientGroup.ker_mk', Submodule.fg_iff_add_subgroup_fg,
AddSubgroup.toIntSubmodule_toAddSubgroup, ← AddGroup.fg_iff_addSubgroup_fg]
have : Finite (Subgroup.toAddSubgroup (torsion K)) := (inferInstance : Finite (torsion K))
exact AddGroup.fg_of_finite
instance : Monoid.FG (𝓞 K)ˣ := by
rw [Monoid.fg_iff_add_fg, ← AddGroup.fg_iff_addMonoid_fg, ← Module.Finite.iff_addGroup_fg]
infer_instance
theorem rank_modTorsion :
FiniteDimensional.finrank ℤ (Additive ((𝓞 K)ˣ ⧸ (torsion K))) = rank K := by
rw [← LinearEquiv.finrank_eq (logEmbeddingEquiv K).symm, unitLattice_rank]
/-- A basis of the quotient `(𝓞 K)ˣ ⧸ (torsion K)` seen as an additive ℤ-module. -/
def basisModTorsion : Basis (Fin (rank K)) ℤ (Additive ((𝓞 K)ˣ ⧸ (torsion K))) :=
Basis.reindex (Module.Free.chooseBasis ℤ _) (Fintype.equivOfCardEq <| by
rw [← FiniteDimensional.finrank_eq_card_chooseBasisIndex, rank_modTorsion, Fintype.card_fin])
/-- A fundamental system of units of `K`. The units of `fundSystem` are arbitrary lifts of the
units in `basisModTorsion`. -/
def fundSystem : Fin (rank K) → (𝓞 K)ˣ :=
-- `:)` prevents the `⧸` decaying to a quotient by `leftRel` when we unfold this later
fun i => Quotient.out' (Additive.toMul (basisModTorsion K i):)
theorem fundSystem_mk (i : Fin (rank K)) :
Additive.ofMul ⟦fundSystem K i⟧ = (basisModTorsion K i) := by
rw [fundSystem, Equiv.apply_eq_iff_eq_symm_apply, @Quotient.mk_eq_iff_out,
Quotient.out', Quotient.out_equiv_out]
rfl
/-- The exponents that appear in the unique decomposition of a unit as the product of
a root of unity and powers of the units of the fundamental system `fundSystem` (see
`exist_unique_eq_mul_prod`) are given by the representation of the unit on `basisModTorsion`. -/
theorem fun_eq_repr {x ζ : (𝓞 K)ˣ} {f : Fin (rank K) → ℤ} (hζ : ζ ∈ torsion K)
(h : x = ζ * ∏ i, (fundSystem K i) ^ (f i)) :
f = (basisModTorsion K).repr (Additive.ofMul ↑x) := by
suffices Additive.ofMul ↑x = ∑ i, (f i) • (basisModTorsion K i) by
rw [← (basisModTorsion K).repr_sum_self f, ← this]
calc
Additive.ofMul ↑x
_ = ∑ i, (f i) • Additive.ofMul ↑(fundSystem K i) := by
rw [h, QuotientGroup.mk_mul, (QuotientGroup.eq_one_iff _).mpr hζ, one_mul,
QuotientGroup.mk_prod, ofMul_prod]; rfl
_ = ∑ i, (f i) • (basisModTorsion K i) := by
simp_rw [fundSystem, QuotientGroup.out_eq', ofMul_toMul]
/-- **Dirichlet Unit Theorem**. Any unit `x` of `𝓞 K` can be written uniquely as the product of
a root of unity and powers of the units of the fundamental system `fundSystem`. -/
theorem exist_unique_eq_mul_prod (x : (𝓞 K)ˣ) : ∃! ζe : torsion K × (Fin (rank K) → ℤ),
x = ζe.1 * ∏ i, (fundSystem K i) ^ (ζe.2 i) := by
let ζ := x * (∏ i, (fundSystem K i) ^ ((basisModTorsion K).repr (Additive.ofMul ↑x) i))⁻¹
have h_tors : ζ ∈ torsion K := by
rw [← QuotientGroup.eq_one_iff, QuotientGroup.mk_mul, QuotientGroup.mk_inv, ← ofMul_eq_zero,
ofMul_mul, ofMul_inv, QuotientGroup.mk_prod, ofMul_prod]
simp_rw [QuotientGroup.mk_zpow, ofMul_zpow, fundSystem, QuotientGroup.out_eq']
rw [add_eq_zero_iff_eq_neg, neg_neg]
exact ((basisModTorsion K).sum_repr (Additive.ofMul ↑x)).symm
refine ⟨⟨⟨ζ, h_tors⟩, ((basisModTorsion K).repr (Additive.ofMul ↑x) : Fin (rank K) → ℤ)⟩, ?_, ?_⟩
· simp only [ζ, _root_.inv_mul_cancel_right]
· rintro ⟨⟨ζ', h_tors'⟩, η⟩ hf
simp only [ζ, ← fun_eq_repr K h_tors' hf, Prod.mk.injEq, Subtype.mk.injEq, and_true]
nth_rewrite 1 [hf]
rw [_root_.mul_inv_cancel_right]
end statements
end NumberField.Units
|
NumberTheory\NumberField\Units\Regulator.lean | /-
Copyright (c) 2024 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.Algebra.Module.Zlattice.Covolume
import Mathlib.LinearAlgebra.Matrix.Determinant.Misc
import Mathlib.NumberTheory.NumberField.Units.DirichletTheorem
/-!
# Regulator of a number field
We define and prove basic results about the regulator of a number field `K`.
## Main definitions and results
* `NumberField.Units.regulator`: the regulator of the number field `K`.
* `Number.Field.Units.regulator_eq_det`: For any infinite place `w'`, the regulator is equal to
the absolute value of the determinant of the matrix `(mult w * log w (fundSystem K i)))_i, w`
where `w` runs through the infinite places distinct from `w'`.
## Tags
number field, units, regulator
-/
open scoped NumberField
noncomputable section
namespace NumberField.Units
variable (K : Type*) [Field K]
open MeasureTheory Classical BigOperators NumberField.InfinitePlace
NumberField NumberField.Units.dirichletUnitTheorem
variable [NumberField K]
/-- The regulator of a number fied `K`. -/
def regulator : ℝ := Zlattice.covolume (unitLattice K)
theorem regulator_ne_zero : regulator K ≠ 0 := Zlattice.covolume_ne_zero (unitLattice K) volume
theorem regulator_pos : 0 < regulator K := Zlattice.covolume_pos (unitLattice K) volume
#adaptation_note
/--
After https://github.com/leanprover/lean4/pull/4119
the `Module ℤ (Additive ((𝓞 K)ˣ ⧸ NumberField.Units.torsion K))` instance required below isn't found
unless we use `set_option maxSynthPendingDepth 2`, or add
explicit instances:
```
local instance : CommGroup (𝓞 K)ˣ := inferInstance
```
-/
set_option maxSynthPendingDepth 2 -- Note this is active for the remainder of the file.
theorem regulator_eq_det' (e : {w : InfinitePlace K // w ≠ w₀} ≃ Fin (rank K)) :
regulator K = |(Matrix.of fun i ↦ (logEmbedding K) (fundSystem K (e i))).det| := by
simp_rw [regulator, Zlattice.covolume_eq_det _
(((basisModTorsion K).map (logEmbeddingEquiv K)).reindex e.symm), Basis.coe_reindex,
Function.comp, Basis.map_apply, ← fundSystem_mk, Equiv.symm_symm]
rfl
/-- Let `u : Fin (rank K) → (𝓞 K)ˣ` be a family of units and let `w₁` and `w₂` be two infinite
places. Then, the two square matrices with entries `(mult w * log w (u i))_i, {w ≠ w_i}`, `i = 1,2`,
have the same determinant in absolute value. -/
theorem abs_det_eq_abs_det (u : Fin (rank K) → (𝓞 K)ˣ)
{w₁ w₂ : InfinitePlace K} (e₁ : {w // w ≠ w₁} ≃ Fin (rank K))
(e₂ : {w // w ≠ w₂} ≃ Fin (rank K)) :
|(Matrix.of fun i w : {w // w ≠ w₁} ↦ (mult w.val : ℝ) * (w.val (u (e₁ i) : K)).log).det| =
|(Matrix.of fun i w : {w // w ≠ w₂} ↦ (mult w.val : ℝ) * (w.val (u (e₂ i) : K)).log).det| := by
-- We construct an equiv `Fin (rank K + 1) ≃ InfinitePlace K` from `e₂.symm`
let f : Fin (rank K + 1) ≃ InfinitePlace K :=
(finSuccEquiv _).trans ((Equiv.optionSubtype _).symm e₁.symm).val
-- And `g` corresponds to the restriction of `f⁻¹` to `{w // w ≠ w₂}`
let g : {w // w ≠ w₂} ≃ Fin (rank K) :=
(Equiv.subtypeEquiv f.symm (fun _ ↦ by simp [f])).trans
(finSuccAboveEquiv (f.symm w₂)).symm
have h_col := congr_arg abs <| Matrix.det_permute (g.trans e₂.symm)
(Matrix.of fun i w : {w // w ≠ w₂} ↦ (mult w.val : ℝ) * (w.val (u (e₂ i) : K)).log)
rw [abs_mul, ← Int.cast_abs, Equiv.Perm.sign_abs, Int.cast_one, one_mul] at h_col
rw [← h_col]
have h := congr_arg abs <| Matrix.submatrix_succAbove_det_eq_negOnePow_submatrix_succAbove_det'
(Matrix.of fun i w ↦ (mult (f w) : ℝ) * ((f w) (u i)).log) ?_ 0 (f.symm w₂)
· rw [← Matrix.det_reindex_self e₁, ← Matrix.det_reindex_self g]
· rw [Units.smul_def, abs_zsmul, Int.abs_negOnePow, one_smul] at h
convert h
· ext; simp only [ne_eq, Matrix.reindex_apply, Matrix.submatrix_apply, Matrix.of_apply,
Equiv.apply_symm_apply, Equiv.trans_apply, Fin.succAbove_zero, id_eq, finSuccEquiv_succ,
Equiv.optionSubtype_symm_apply_apply_coe, f]
· ext; simp only [ne_eq, Equiv.coe_trans, Matrix.reindex_apply, Matrix.submatrix_apply,
Function.comp_apply, Equiv.apply_symm_apply, id_eq, Matrix.of_apply]; rfl
· intro _
simp_rw [Matrix.of_apply, ← Real.log_pow]
rw [← Real.log_prod, Equiv.prod_comp f (fun w ↦ (w (u _) ^ (mult w))), prod_eq_abs_norm,
Units.norm, Rat.cast_one, Real.log_one]
exact fun _ _ ↦ pow_ne_zero _ <| (map_ne_zero _).mpr (coe_ne_zero _)
/-- For any infinite place `w'`, the regulator is equal to the absolute value of the determinant
of the matrix `(mult w * log w (fundSystem K i)))_i, {w ≠ w'}`. -/
theorem regulator_eq_det (w' : InfinitePlace K) (e : {w // w ≠ w'} ≃ Fin (rank K)) :
regulator K =
|(Matrix.of fun i w : {w // w ≠ w'} ↦ (mult w.val : ℝ) *
Real.log (w.val (fundSystem K (e i) : K))).det| := by
let e' : {w : InfinitePlace K // w ≠ w₀} ≃ Fin (rank K) := Fintype.equivOfCardEq (by
rw [Fintype.card_subtype_compl, Fintype.card_ofSubsingleton, Fintype.card_fin, rank])
simp_rw [regulator_eq_det' K e', logEmbedding, AddMonoidHom.coe_mk, ZeroHom.coe_mk]
exact abs_det_eq_abs_det K (fun i ↦ fundSystem K i) e' e
end Units
end NumberField
|
NumberTheory\Padics\Hensel.lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import Mathlib.Algebra.Polynomial.Identities
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.NumberTheory.Padics.PadicIntegers
import Mathlib.Topology.Algebra.Polynomial
import Mathlib.Topology.MetricSpace.CauSeqFilter
/-!
# Hensel's lemma on ℤ_p
This file proves Hensel's lemma on ℤ_p, roughly following Keith Conrad's writeup:
<http://www.math.uconn.edu/~kconrad/blurbs/gradnumthy/hensel.pdf>
Hensel's lemma gives a simple condition for the existence of a root of a polynomial.
The proof and motivation are described in the paper
[R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019].
## References
* <http://www.math.uconn.edu/~kconrad/blurbs/gradnumthy/hensel.pdf>
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/Hensel%27s_lemma>
## Tags
p-adic, p adic, padic, p-adic integer
-/
noncomputable section
open Topology
-- We begin with some general lemmas that are used below in the computation.
theorem padic_polynomial_dist {p : ℕ} [Fact p.Prime] (F : Polynomial ℤ_[p]) (x y : ℤ_[p]) :
‖F.eval x - F.eval y‖ ≤ ‖x - y‖ :=
let ⟨z, hz⟩ := F.evalSubFactor x y
calc
‖F.eval x - F.eval y‖ = ‖z‖ * ‖x - y‖ := by simp [hz]
_ ≤ 1 * ‖x - y‖ := by gcongr; apply PadicInt.norm_le_one
_ = ‖x - y‖ := by simp
open Filter Metric
private theorem comp_tendsto_lim {p : ℕ} [Fact p.Prime] {F : Polynomial ℤ_[p]}
(ncs : CauSeq ℤ_[p] norm) : Tendsto (fun i => F.eval (ncs i)) atTop (𝓝 (F.eval ncs.lim)) :=
Filter.Tendsto.comp (@Polynomial.continuousAt _ _ _ _ F _) ncs.tendsto_limit
section
-- Porting note: replaced `parameter` with `variable`
variable {p : ℕ} [Fact p.Prime] {ncs : CauSeq ℤ_[p] norm} {F : Polynomial ℤ_[p]}
{a : ℤ_[p]} (ncs_der_val : ∀ n, ‖F.derivative.eval (ncs n)‖ = ‖F.derivative.eval a‖)
private theorem ncs_tendsto_const :
Tendsto (fun i => ‖F.derivative.eval (ncs i)‖) atTop (𝓝 ‖F.derivative.eval a‖) := by
convert @tendsto_const_nhds ℝ ℕ _ _ _; rw [ncs_der_val]
private theorem ncs_tendsto_lim :
Tendsto (fun i => ‖F.derivative.eval (ncs i)‖) atTop (𝓝 ‖F.derivative.eval ncs.lim‖) :=
Tendsto.comp (continuous_iff_continuousAt.1 continuous_norm _) (comp_tendsto_lim _)
private theorem norm_deriv_eq : ‖F.derivative.eval ncs.lim‖ = ‖F.derivative.eval a‖ :=
tendsto_nhds_unique ncs_tendsto_lim (ncs_tendsto_const ncs_der_val)
end
section
-- Porting note: replaced `parameter` with `variable`
variable {p : ℕ} [Fact p.Prime] {ncs : CauSeq ℤ_[p] norm} {F : Polynomial ℤ_[p]}
(hnorm : Tendsto (fun i => ‖F.eval (ncs i)‖) atTop (𝓝 0))
private theorem tendsto_zero_of_norm_tendsto_zero : Tendsto (fun i => F.eval (ncs i)) atTop (𝓝 0) :=
tendsto_iff_norm_sub_tendsto_zero.2 (by simpa using hnorm)
theorem limit_zero_of_norm_tendsto_zero : F.eval ncs.lim = 0 :=
tendsto_nhds_unique (comp_tendsto_lim _) (tendsto_zero_of_norm_tendsto_zero hnorm)
end
section Hensel
open Nat
-- Porting note: replaced `parameter` with `variable`
variable (p : ℕ) [Fact p.Prime] (F : Polynomial ℤ_[p]) (a : ℤ_[p])
(hnorm : ‖F.eval a‖ < ‖F.derivative.eval a‖ ^ 2) (hnsol : F.eval a ≠ 0)
-- Porting note: renamed this `def` and used a local notation to provide arguments automatically
/-- `T` is an auxiliary value that is used to control the behavior of the polynomial `F`. -/
private def T_gen : ℝ := ‖F.eval a / ((F.derivative.eval a ^ 2 : ℤ_[p]) : ℚ_[p])‖
local notation "T" => @T_gen p _ F a
variable {p F a}
private theorem deriv_sq_norm_pos : 0 < ‖F.derivative.eval a‖ ^ 2 :=
lt_of_le_of_lt (norm_nonneg _) hnorm
private theorem deriv_sq_norm_ne_zero : ‖F.derivative.eval a‖ ^ 2 ≠ 0 :=
ne_of_gt (deriv_sq_norm_pos hnorm)
private theorem deriv_norm_ne_zero : ‖F.derivative.eval a‖ ≠ 0 := fun h =>
deriv_sq_norm_ne_zero hnorm (by simp [*, sq])
private theorem deriv_norm_pos : 0 < ‖F.derivative.eval a‖ :=
lt_of_le_of_ne (norm_nonneg _) (Ne.symm (deriv_norm_ne_zero hnorm))
private theorem deriv_ne_zero : F.derivative.eval a ≠ 0 :=
mt norm_eq_zero.2 (deriv_norm_ne_zero hnorm)
private theorem T_def : T = ‖F.eval a‖ / ‖F.derivative.eval a‖ ^ 2 := by
simp [T_gen, ← PadicInt.norm_def]
private theorem T_lt_one : T < 1 := by
have h := (div_lt_one (deriv_sq_norm_pos hnorm)).2 hnorm
rw [T_def]; exact h
private theorem T_nonneg : 0 ≤ T := norm_nonneg _
private theorem T_pow_nonneg (n : ℕ) : 0 ≤ T ^ n := pow_nonneg T_nonneg _
private theorem T_pow {n : ℕ} (hn : n ≠ 0) : T ^ n < 1 := pow_lt_one T_nonneg (T_lt_one hnorm) hn
private theorem T_pow' (n : ℕ) : T ^ 2 ^ n < 1 := T_pow hnorm (pow_ne_zero _ two_ne_zero)
-- Porting note: renamed this `def` and used a local notation to provide arguments automatically
/-- We will construct a sequence of elements of ℤ_p satisfying successive values of `ih`. -/
private def ih_gen (n : ℕ) (z : ℤ_[p]) : Prop :=
‖F.derivative.eval z‖ = ‖F.derivative.eval a‖ ∧ ‖F.eval z‖ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n
local notation "ih" => @ih_gen p _ F a
private theorem ih_0 : ih 0 a :=
⟨rfl, by simp [T_def, mul_div_cancel₀ _ (ne_of_gt (deriv_sq_norm_pos hnorm))]⟩
private theorem calc_norm_le_one {n : ℕ} {z : ℤ_[p]} (hz : ih n z) :
‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ ≤ 1 :=
calc
‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ =
‖(↑(F.eval z) : ℚ_[p])‖ / ‖(↑(F.derivative.eval z) : ℚ_[p])‖ :=
norm_div _ _
_ = ‖F.eval z‖ / ‖F.derivative.eval a‖ := by simp [hz.1]
_ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n / ‖F.derivative.eval a‖ := by
gcongr
apply hz.2
_ = ‖F.derivative.eval a‖ * T ^ 2 ^ n := div_sq_cancel _ _
_ ≤ 1 := mul_le_one (PadicInt.norm_le_one _) (T_pow_nonneg _) (le_of_lt (T_pow' hnorm _))
private theorem calc_deriv_dist {z z' z1 : ℤ_[p]} (hz' : z' = z - z1)
(hz1 : ‖z1‖ = ‖F.eval z‖ / ‖F.derivative.eval a‖) {n} (hz : ih n z) :
‖F.derivative.eval z' - F.derivative.eval z‖ < ‖F.derivative.eval a‖ :=
calc
‖F.derivative.eval z' - F.derivative.eval z‖ ≤ ‖z' - z‖ := padic_polynomial_dist _ _ _
_ = ‖z1‖ := by simp only [sub_eq_add_neg, add_assoc, hz', add_add_neg_cancel'_right, norm_neg]
_ = ‖F.eval z‖ / ‖F.derivative.eval a‖ := hz1
_ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n / ‖F.derivative.eval a‖ := by
gcongr
apply hz.2
_ = ‖F.derivative.eval a‖ * T ^ 2 ^ n := div_sq_cancel _ _
_ < ‖F.derivative.eval a‖ := (mul_lt_iff_lt_one_right (deriv_norm_pos hnorm)).2
(T_pow' hnorm _)
private def calc_eval_z' {z z' z1 : ℤ_[p]} (hz' : z' = z - z1) {n} (hz : ih n z)
(h1 : ‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ ≤ 1) (hzeq : z1 = ⟨_, h1⟩) :
{ q : ℤ_[p] // F.eval z' = q * z1 ^ 2 } := by
have hdzne : F.derivative.eval z ≠ 0 :=
mt norm_eq_zero.2 (by rw [hz.1]; apply deriv_norm_ne_zero; assumption)
have hdzne' : (↑(F.derivative.eval z) : ℚ_[p]) ≠ 0 := fun h => hdzne (Subtype.ext_iff_val.2 h)
obtain ⟨q, hq⟩ := F.binomExpansion z (-z1)
have : ‖(↑(F.derivative.eval z) * (↑(F.eval z) / ↑(F.derivative.eval z)) : ℚ_[p])‖ ≤ 1 := by
rw [padicNormE.mul]
exact mul_le_one (PadicInt.norm_le_one _) (norm_nonneg _) h1
have : F.derivative.eval z * -z1 = -F.eval z := by
calc
F.derivative.eval z * -z1 =
F.derivative.eval z * -⟨↑(F.eval z) / ↑(F.derivative.eval z), h1⟩ := by rw [hzeq]
_ = -(F.derivative.eval z * ⟨↑(F.eval z) / ↑(F.derivative.eval z), h1⟩) := mul_neg _ _
_ = -⟨F.derivative.eval z * (F.eval z / (F.derivative.eval z : ℤ_[p]) : ℚ_[p]), this⟩ :=
(Subtype.ext <| by simp only [PadicInt.coe_neg, PadicInt.coe_mul, Subtype.coe_mk])
_ = -F.eval z := by simp only [mul_div_cancel₀ _ hdzne', Subtype.coe_eta]
exact ⟨q, by simpa only [sub_eq_add_neg, this, hz', add_right_neg, neg_sq, zero_add] using hq⟩
private def calc_eval_z'_norm {z z' z1 : ℤ_[p]} {n} (hz : ih n z) {q} (heq : F.eval z' = q * z1 ^ 2)
(h1 : ‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ ≤ 1) (hzeq : z1 = ⟨_, h1⟩) :
‖F.eval z'‖ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ (n + 1) := by
calc
‖F.eval z'‖ = ‖q‖ * ‖z1‖ ^ 2 := by simp [heq]
_ ≤ 1 * ‖z1‖ ^ 2 := by gcongr; apply PadicInt.norm_le_one
_ = ‖F.eval z‖ ^ 2 / ‖F.derivative.eval a‖ ^ 2 := by simp [hzeq, hz.1, div_pow]
_ ≤ (‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n) ^ 2 / ‖F.derivative.eval a‖ ^ 2 := by
gcongr
exact hz.2
_ = (‖F.derivative.eval a‖ ^ 2) ^ 2 * (T ^ 2 ^ n) ^ 2 / ‖F.derivative.eval a‖ ^ 2 := by
simp only [mul_pow]
_ = ‖F.derivative.eval a‖ ^ 2 * (T ^ 2 ^ n) ^ 2 := div_sq_cancel _ _
_ = ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ (n + 1) := by rw [← pow_mul, pow_succ 2]
-- Porting note: unsupported option eqn_compiler.zeta
-- set_option eqn_compiler.zeta true
/-- Given `z : ℤ_[p]` satisfying `ih n z`, construct `z' : ℤ_[p]` satisfying `ih (n+1) z'`. We need
the hypothesis `ih n z`, since otherwise `z'` is not necessarily an integer. -/
private def ih_n {n : ℕ} {z : ℤ_[p]} (hz : ih n z) : { z' : ℤ_[p] // ih (n + 1) z' } :=
have h1 : ‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ ≤ 1 := calc_norm_le_one hnorm hz
let z1 : ℤ_[p] := ⟨_, h1⟩
let z' : ℤ_[p] := z - z1
⟨z',
have hdist : ‖F.derivative.eval z' - F.derivative.eval z‖ < ‖F.derivative.eval a‖ :=
calc_deriv_dist hnorm rfl (by simp [z1, hz.1]) hz
have hfeq : ‖F.derivative.eval z'‖ = ‖F.derivative.eval a‖ := by
rw [sub_eq_add_neg, ← hz.1, ← norm_neg (F.derivative.eval z)] at hdist
have := PadicInt.norm_eq_of_norm_add_lt_right hdist
rwa [norm_neg, hz.1] at this
let ⟨q, heq⟩ := calc_eval_z' hnorm rfl hz h1 rfl
have hnle : ‖F.eval z'‖ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ (n + 1) :=
calc_eval_z'_norm hz heq h1 rfl
⟨hfeq, hnle⟩⟩
-- Porting note: unsupported option eqn_compiler.zeta
-- set_option eqn_compiler.zeta false
private def newton_seq_aux : ∀ n : ℕ, { z : ℤ_[p] // ih n z }
| 0 => ⟨a, ih_0 hnorm⟩
| k + 1 => ih_n hnorm (newton_seq_aux k).2
-- Porting note: renamed this `def` and used a local notation to provide arguments automatically
private def newton_seq_gen (n : ℕ) : ℤ_[p] :=
(newton_seq_aux hnorm n).1
local notation "newton_seq" => newton_seq_gen hnorm
private theorem newton_seq_deriv_norm (n : ℕ) :
‖F.derivative.eval (newton_seq n)‖ = ‖F.derivative.eval a‖ :=
(newton_seq_aux hnorm n).2.1
private theorem newton_seq_norm_le (n : ℕ) :
‖F.eval (newton_seq n)‖ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n :=
(newton_seq_aux hnorm n).2.2
private theorem newton_seq_norm_eq (n : ℕ) :
‖newton_seq (n + 1) - newton_seq n‖ =
‖F.eval (newton_seq n)‖ / ‖F.derivative.eval (newton_seq n)‖ := by
rw [newton_seq_gen, newton_seq_gen, newton_seq_aux, ih_n]
simp [sub_eq_add_neg, add_comm]
private theorem newton_seq_succ_dist (n : ℕ) :
‖newton_seq (n + 1) - newton_seq n‖ ≤ ‖F.derivative.eval a‖ * T ^ 2 ^ n :=
calc
‖newton_seq (n + 1) - newton_seq n‖ =
‖F.eval (newton_seq n)‖ / ‖F.derivative.eval (newton_seq n)‖ :=
newton_seq_norm_eq hnorm _
_ = ‖F.eval (newton_seq n)‖ / ‖F.derivative.eval a‖ := by rw [newton_seq_deriv_norm]
_ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n / ‖F.derivative.eval a‖ :=
((div_le_div_right (deriv_norm_pos hnorm)).2 (newton_seq_norm_le hnorm _))
_ = ‖F.derivative.eval a‖ * T ^ 2 ^ n := div_sq_cancel _ _
private theorem T_pos : T > 0 := by
rw [T_def]
exact div_pos (norm_pos_iff.2 hnsol) (deriv_sq_norm_pos hnorm)
private theorem newton_seq_succ_dist_weak (n : ℕ) :
‖newton_seq (n + 2) - newton_seq (n + 1)‖ < ‖F.eval a‖ / ‖F.derivative.eval a‖ :=
have : 2 ≤ 2 ^ (n + 1) := by
have := pow_le_pow_right (by norm_num : 1 ≤ 2) (Nat.le_add_left _ _ : 1 ≤ n + 1)
simpa using this
calc
‖newton_seq (n + 2) - newton_seq (n + 1)‖ ≤ ‖F.derivative.eval a‖ * T ^ 2 ^ (n + 1) :=
newton_seq_succ_dist hnorm _
_ ≤ ‖F.derivative.eval a‖ * T ^ 2 :=
(mul_le_mul_of_nonneg_left (pow_le_pow_of_le_one (norm_nonneg _)
(le_of_lt (T_lt_one hnorm)) this) (norm_nonneg _))
_ < ‖F.derivative.eval a‖ * T ^ 1 :=
(mul_lt_mul_of_pos_left (pow_lt_pow_right_of_lt_one (T_pos hnorm hnsol)
(T_lt_one hnorm) (by norm_num)) (deriv_norm_pos hnorm))
_ = ‖F.eval a‖ / ‖F.derivative.eval a‖ := by
rw [T_gen, sq, pow_one, norm_div, ← mul_div_assoc, PadicInt.padic_norm_e_of_padicInt,
PadicInt.coe_mul, padicNormE.mul]
apply mul_div_mul_left
apply deriv_norm_ne_zero; assumption
private theorem newton_seq_dist_aux (n : ℕ) :
∀ k : ℕ, ‖newton_seq (n + k) - newton_seq n‖ ≤ ‖F.derivative.eval a‖ * T ^ 2 ^ n
| 0 => by simp [T_pow_nonneg, mul_nonneg]
| k + 1 =>
have : 2 ^ n ≤ 2 ^ (n + k) := by
apply pow_le_pow_right
· norm_num
· apply Nat.le_add_right
calc
‖newton_seq (n + (k + 1)) - newton_seq n‖ = ‖newton_seq (n + k + 1) - newton_seq n‖ := by
rw [add_assoc]
_ = ‖newton_seq (n + k + 1) - newton_seq (n + k) + (newton_seq (n + k) - newton_seq n)‖ := by
rw [← sub_add_sub_cancel]
_ ≤ max ‖newton_seq (n + k + 1) - newton_seq (n + k)‖ ‖newton_seq (n + k) - newton_seq n‖ :=
(PadicInt.nonarchimedean _ _)
_ ≤ max (‖F.derivative.eval a‖ * T ^ 2 ^ (n + k)) (‖F.derivative.eval a‖ * T ^ 2 ^ n) :=
(max_le_max (newton_seq_succ_dist _ _) (newton_seq_dist_aux _ _))
_ = ‖F.derivative.eval a‖ * T ^ 2 ^ n :=
max_eq_right <|
mul_le_mul_of_nonneg_left (pow_le_pow_of_le_one (norm_nonneg _)
(le_of_lt (T_lt_one hnorm)) this) (norm_nonneg _)
private theorem newton_seq_dist {n k : ℕ} (hnk : n ≤ k) :
‖newton_seq k - newton_seq n‖ ≤ ‖F.derivative.eval a‖ * T ^ 2 ^ n := by
have hex : ∃ m, k = n + m := Nat.exists_eq_add_of_le hnk
let ⟨_, hex'⟩ := hex
rw [hex']; apply newton_seq_dist_aux
private theorem newton_seq_dist_to_a :
∀ n : ℕ, 0 < n → ‖newton_seq n - a‖ = ‖F.eval a‖ / ‖F.derivative.eval a‖
| 1, _h => by simp [sub_eq_add_neg, add_assoc, newton_seq_gen, newton_seq_aux, ih_n]
| k + 2, _h =>
have hlt : ‖newton_seq (k + 2) - newton_seq (k + 1)‖ < ‖newton_seq (k + 1) - a‖ := by
rw [newton_seq_dist_to_a (k + 1) (succ_pos _)]; apply newton_seq_succ_dist_weak
assumption
have hne' : ‖newton_seq (k + 2) - newton_seq (k + 1)‖ ≠ ‖newton_seq (k + 1) - a‖ := ne_of_lt hlt
calc
‖newton_seq (k + 2) - a‖ =
‖newton_seq (k + 2) - newton_seq (k + 1) + (newton_seq (k + 1) - a)‖ := by
rw [← sub_add_sub_cancel]
_ = max ‖newton_seq (k + 2) - newton_seq (k + 1)‖ ‖newton_seq (k + 1) - a‖ :=
(PadicInt.norm_add_eq_max_of_ne hne')
_ = ‖newton_seq (k + 1) - a‖ := max_eq_right_of_lt hlt
_ = ‖Polynomial.eval a F‖ / ‖Polynomial.eval a (Polynomial.derivative F)‖ :=
newton_seq_dist_to_a (k + 1) (succ_pos _)
private theorem bound' : Tendsto (fun n : ℕ => ‖F.derivative.eval a‖ * T ^ 2 ^ n) atTop (𝓝 0) := by
rw [← mul_zero ‖F.derivative.eval a‖]
exact
tendsto_const_nhds.mul
(Tendsto.comp (tendsto_pow_atTop_nhds_zero_of_lt_one (norm_nonneg _) (T_lt_one hnorm))
(Nat.tendsto_pow_atTop_atTop_of_one_lt (by norm_num)))
private theorem bound :
∀ {ε}, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → ‖F.derivative.eval a‖ * T ^ 2 ^ n < ε := fun hε ↦
eventually_atTop.1 <| (bound' hnorm).eventually <| gt_mem_nhds hε
private theorem bound'_sq :
Tendsto (fun n : ℕ => ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n) atTop (𝓝 0) := by
rw [← mul_zero ‖F.derivative.eval a‖, sq]
simp only [mul_assoc]
apply Tendsto.mul
· apply tendsto_const_nhds
· apply bound'
assumption
private theorem newton_seq_is_cauchy : IsCauSeq norm newton_seq := fun _ε hε ↦
(bound hnorm hε).imp fun _N hN _j hj ↦ (newton_seq_dist hnorm hj).trans_lt <| hN le_rfl
private def newton_cau_seq : CauSeq ℤ_[p] norm := ⟨_, newton_seq_is_cauchy hnorm⟩
-- Porting note: renamed this `def` and used a local notation to provide arguments automatically
private def soln_gen : ℤ_[p] := (newton_cau_seq hnorm).lim
local notation "soln" => soln_gen hnorm
private theorem soln_spec {ε : ℝ} (hε : ε > 0) :
∃ N : ℕ, ∀ {i : ℕ}, i ≥ N → ‖soln - newton_cau_seq hnorm i‖ < ε :=
Setoid.symm (CauSeq.equiv_lim (newton_cau_seq hnorm)) _ hε
private theorem soln_deriv_norm : ‖F.derivative.eval soln‖ = ‖F.derivative.eval a‖ :=
norm_deriv_eq (newton_seq_deriv_norm hnorm)
private theorem newton_seq_norm_tendsto_zero :
Tendsto (fun i => ‖F.eval (newton_cau_seq hnorm i)‖) atTop (𝓝 0) :=
squeeze_zero (fun _ => norm_nonneg _) (newton_seq_norm_le hnorm) (bound'_sq hnorm)
private theorem newton_seq_dist_tendsto :
Tendsto (fun n => ‖newton_cau_seq hnorm n - a‖)
atTop (𝓝 (‖F.eval a‖ / ‖F.derivative.eval a‖)) :=
tendsto_const_nhds.congr' (eventually_atTop.2
⟨1, fun _ hx => (newton_seq_dist_to_a hnorm hnsol _ hx).symm⟩)
private theorem newton_seq_dist_tendsto' :
Tendsto (fun n => ‖newton_cau_seq hnorm n - a‖) atTop (𝓝 ‖soln - a‖) :=
(continuous_norm.tendsto _).comp ((newton_cau_seq hnorm).tendsto_limit.sub tendsto_const_nhds)
private theorem soln_dist_to_a : ‖soln - a‖ = ‖F.eval a‖ / ‖F.derivative.eval a‖ :=
tendsto_nhds_unique (newton_seq_dist_tendsto' hnorm) (newton_seq_dist_tendsto hnorm hnsol)
private theorem soln_dist_to_a_lt_deriv : ‖soln - a‖ < ‖F.derivative.eval a‖ := by
rw [soln_dist_to_a, div_lt_iff (deriv_norm_pos _), ← sq] <;> assumption
private theorem eval_soln : F.eval soln = 0 :=
limit_zero_of_norm_tendsto_zero (newton_seq_norm_tendsto_zero hnorm)
private theorem soln_unique (z : ℤ_[p]) (hev : F.eval z = 0)
(hnlt : ‖z - a‖ < ‖F.derivative.eval a‖) : z = soln :=
have soln_dist : ‖z - soln‖ < ‖F.derivative.eval a‖ :=
calc
‖z - soln‖ = ‖z - a + (a - soln)‖ := by rw [sub_add_sub_cancel]
_ ≤ max ‖z - a‖ ‖a - soln‖ := PadicInt.nonarchimedean _ _
_ < ‖F.derivative.eval a‖ :=
max_lt hnlt ((norm_sub_rev soln a ▸ (soln_dist_to_a_lt_deriv hnorm)) hnsol)
let h := z - soln
let ⟨q, hq⟩ := F.binomExpansion soln h
have : (F.derivative.eval soln + q * h) * h = 0 :=
Eq.symm
(calc
0 = F.eval (soln + h) := by simp [h, hev]
_ = F.derivative.eval soln * h + q * h ^ 2 := by rw [hq, eval_soln, zero_add]
_ = (F.derivative.eval soln + q * h) * h := by rw [sq, right_distrib, mul_assoc]
)
have : h = 0 :=
by_contra fun hne =>
have : F.derivative.eval soln + q * h = 0 :=
(eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_right hne
have : F.derivative.eval soln = -q * h := by simpa using eq_neg_of_add_eq_zero_left this
lt_irrefl ‖F.derivative.eval soln‖
(calc
‖F.derivative.eval soln‖ = ‖-q * h‖ := by rw [this]
_ ≤ 1 * ‖h‖ := by
rw [PadicInt.norm_mul]
exact mul_le_mul_of_nonneg_right (PadicInt.norm_le_one _) (norm_nonneg _)
_ = ‖z - soln‖ := by simp
_ < ‖F.derivative.eval soln‖ := by rw [soln_deriv_norm]; apply soln_dist
)
eq_of_sub_eq_zero (by rw [← this])
end Hensel
variable {p : ℕ} [Fact p.Prime] {F : Polynomial ℤ_[p]} {a : ℤ_[p]}
private theorem a_soln_is_unique (ha : F.eval a = 0) (z' : ℤ_[p]) (hz' : F.eval z' = 0)
(hnormz' : ‖z' - a‖ < ‖F.derivative.eval a‖) : z' = a :=
let h := z' - a
let ⟨q, hq⟩ := F.binomExpansion a h
have : (F.derivative.eval a + q * h) * h = 0 :=
Eq.symm
(calc
0 = F.eval (a + h) := show 0 = F.eval (a + (z' - a)) by rw [add_comm]; simp [hz']
_ = F.derivative.eval a * h + q * h ^ 2 := by rw [hq, ha, zero_add]
_ = (F.derivative.eval a + q * h) * h := by rw [sq, right_distrib, mul_assoc]
)
have : h = 0 :=
by_contra fun hne =>
have : F.derivative.eval a + q * h = 0 :=
(eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_right hne
have : F.derivative.eval a = -q * h := by simpa using eq_neg_of_add_eq_zero_left this
lt_irrefl ‖F.derivative.eval a‖
(calc
‖F.derivative.eval a‖ = ‖q‖ * ‖h‖ := by simp [this]
_ ≤ 1 * ‖h‖ := by gcongr; apply PadicInt.norm_le_one
_ < ‖F.derivative.eval a‖ := by simpa
)
eq_of_sub_eq_zero (by rw [← this])
variable (hnorm : ‖F.eval a‖ < ‖F.derivative.eval a‖ ^ 2)
private theorem a_is_soln (ha : F.eval a = 0) :
F.eval a = 0 ∧
‖a - a‖ < ‖F.derivative.eval a‖ ∧
‖F.derivative.eval a‖ = ‖F.derivative.eval a‖ ∧
∀ z', F.eval z' = 0 → ‖z' - a‖ < ‖F.derivative.eval a‖ → z' = a :=
⟨ha, by simp [deriv_ne_zero hnorm], rfl, a_soln_is_unique ha⟩
theorem hensels_lemma :
∃ z : ℤ_[p],
F.eval z = 0 ∧
‖z - a‖ < ‖F.derivative.eval a‖ ∧
‖F.derivative.eval z‖ = ‖F.derivative.eval a‖ ∧
∀ z', F.eval z' = 0 → ‖z' - a‖ < ‖F.derivative.eval a‖ → z' = z := by
classical
exact if ha : F.eval a = 0 then ⟨a, a_is_soln hnorm ha⟩
else by
exact ⟨soln_gen hnorm, eval_soln hnorm,
soln_dist_to_a_lt_deriv hnorm ha, soln_deriv_norm hnorm, fun z => soln_unique hnorm ha z⟩
|
NumberTheory\Padics\PadicIntegers.lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Mario Carneiro, Johan Commelin
-/
import Mathlib.NumberTheory.Padics.PadicNumbers
import Mathlib.RingTheory.DiscreteValuationRing.Basic
/-!
# p-adic integers
This file defines the `p`-adic integers `ℤ_[p]` as the subtype of `ℚ_[p]` with norm `≤ 1`.
We show that `ℤ_[p]`
* is complete,
* is nonarchimedean,
* is a normed ring,
* is a local ring, and
* is a discrete valuation ring.
The relation between `ℤ_[p]` and `ZMod p` is established in another file.
## Important definitions
* `PadicInt` : the type of `p`-adic integers
## Notation
We introduce the notation `ℤ_[p]` for the `p`-adic integers.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking `[Fact p.Prime]` as a type class argument.
Coercions into `ℤ_[p]` are set up to work with the `norm_cast` tactic.
## References
* [F. Q. Gouvêa, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, p-adic integer
-/
open Padic Metric LocalRing
noncomputable section
/-- The `p`-adic integers `ℤ_[p]` are the `p`-adic numbers with norm `≤ 1`. -/
def PadicInt (p : ℕ) [Fact p.Prime] :=
{ x : ℚ_[p] // ‖x‖ ≤ 1 }
/-- The ring of `p`-adic integers. -/
notation "ℤ_[" p "]" => PadicInt p
namespace PadicInt
/-! ### Ring structure and coercion to `ℚ_[p]` -/
variable {p : ℕ} [Fact p.Prime]
instance : Coe ℤ_[p] ℚ_[p] :=
⟨Subtype.val⟩
theorem ext {x y : ℤ_[p]} : (x : ℚ_[p]) = y → x = y :=
Subtype.ext
variable (p)
/-- The `p`-adic integers as a subring of `ℚ_[p]`. -/
def subring : Subring ℚ_[p] where
carrier := { x : ℚ_[p] | ‖x‖ ≤ 1 }
zero_mem' := by norm_num
one_mem' := by norm_num
add_mem' hx hy := (padicNormE.nonarchimedean _ _).trans <| max_le_iff.2 ⟨hx, hy⟩
mul_mem' hx hy := (padicNormE.mul _ _).trans_le <| mul_le_one hx (norm_nonneg _) hy
neg_mem' hx := (norm_neg _).trans_le hx
@[simp]
theorem mem_subring_iff {x : ℚ_[p]} : x ∈ subring p ↔ ‖x‖ ≤ 1 := Iff.rfl
variable {p}
/-- Addition on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : Add ℤ_[p] := (by infer_instance : Add (subring p))
/-- Multiplication on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : Mul ℤ_[p] := (by infer_instance : Mul (subring p))
/-- Negation on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : Neg ℤ_[p] := (by infer_instance : Neg (subring p))
/-- Subtraction on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : Sub ℤ_[p] := (by infer_instance : Sub (subring p))
/-- Zero on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : Zero ℤ_[p] := (by infer_instance : Zero (subring p))
instance : Inhabited ℤ_[p] := ⟨0⟩
/-- One on `ℤ_[p]` is inherited from `ℚ_[p]`. -/
instance : One ℤ_[p] := ⟨⟨1, by norm_num⟩⟩
@[simp]
theorem mk_zero {h} : (⟨0, h⟩ : ℤ_[p]) = (0 : ℤ_[p]) := rfl
@[simp, norm_cast]
theorem coe_add (z1 z2 : ℤ_[p]) : ((z1 + z2 : ℤ_[p]) : ℚ_[p]) = z1 + z2 := rfl
@[simp, norm_cast]
theorem coe_mul (z1 z2 : ℤ_[p]) : ((z1 * z2 : ℤ_[p]) : ℚ_[p]) = z1 * z2 := rfl
@[simp, norm_cast]
theorem coe_neg (z1 : ℤ_[p]) : ((-z1 : ℤ_[p]) : ℚ_[p]) = -z1 := rfl
@[simp, norm_cast]
theorem coe_sub (z1 z2 : ℤ_[p]) : ((z1 - z2 : ℤ_[p]) : ℚ_[p]) = z1 - z2 := rfl
@[simp, norm_cast]
theorem coe_one : ((1 : ℤ_[p]) : ℚ_[p]) = 1 := rfl
@[simp, norm_cast]
theorem coe_zero : ((0 : ℤ_[p]) : ℚ_[p]) = 0 := rfl
theorem coe_eq_zero (z : ℤ_[p]) : (z : ℚ_[p]) = 0 ↔ z = 0 := by rw [← coe_zero, Subtype.coe_inj]
theorem coe_ne_zero (z : ℤ_[p]) : (z : ℚ_[p]) ≠ 0 ↔ z ≠ 0 := z.coe_eq_zero.not
instance : AddCommGroup ℤ_[p] := (by infer_instance : AddCommGroup (subring p))
instance instCommRing : CommRing ℤ_[p] := (by infer_instance : CommRing (subring p))
@[simp, norm_cast]
theorem coe_natCast (n : ℕ) : ((n : ℤ_[p]) : ℚ_[p]) = n := rfl
@[deprecated (since := "2024-04-17")]
alias coe_nat_cast := coe_natCast
@[simp, norm_cast]
theorem coe_intCast (z : ℤ) : ((z : ℤ_[p]) : ℚ_[p]) = z := rfl
@[deprecated (since := "2024-04-17")]
alias coe_int_cast := coe_intCast
/-- The coercion from `ℤ_[p]` to `ℚ_[p]` as a ring homomorphism. -/
def Coe.ringHom : ℤ_[p] →+* ℚ_[p] := (subring p).subtype
@[simp, norm_cast]
theorem coe_pow (x : ℤ_[p]) (n : ℕ) : (↑(x ^ n) : ℚ_[p]) = (↑x : ℚ_[p]) ^ n := rfl
-- @[simp] -- Porting note: not in simpNF
theorem mk_coe (k : ℤ_[p]) : (⟨k, k.2⟩ : ℤ_[p]) = k := Subtype.coe_eta _ _
/-- The inverse of a `p`-adic integer with norm equal to `1` is also a `p`-adic integer.
Otherwise, the inverse is defined to be `0`. -/
def inv : ℤ_[p] → ℤ_[p]
| ⟨k, _⟩ => if h : ‖k‖ = 1 then ⟨k⁻¹, by simp [h]⟩ else 0
instance : CharZero ℤ_[p] where
cast_injective m n h := Nat.cast_injective (by rw [Subtype.ext_iff] at h; norm_cast at h)
@[norm_cast] -- @[simp] -- Porting note: not in simpNF
theorem intCast_eq (z1 z2 : ℤ) : (z1 : ℤ_[p]) = z2 ↔ z1 = z2 := by
suffices (z1 : ℚ_[p]) = z2 ↔ z1 = z2 from Iff.trans (by norm_cast) this
norm_cast
@[deprecated (since := "2024-04-05")] alias coe_int_eq := intCast_eq
/-- A sequence of integers that is Cauchy with respect to the `p`-adic norm converges to a `p`-adic
integer. -/
def ofIntSeq (seq : ℕ → ℤ) (h : IsCauSeq (padicNorm p) fun n => seq n) : ℤ_[p] :=
⟨⟦⟨_, h⟩⟧,
show ↑(PadicSeq.norm _) ≤ (1 : ℝ) by
rw [PadicSeq.norm]
split_ifs with hne <;> norm_cast
apply padicNorm.of_int⟩
end PadicInt
namespace PadicInt
/-! ### Instances
We now show that `ℤ_[p]` is a
* complete metric space
* normed ring
* integral domain
-/
variable (p : ℕ) [Fact p.Prime]
instance : MetricSpace ℤ_[p] := Subtype.metricSpace
instance : IsUltrametricDist ℤ_[p] := IsUltrametricDist.subtype _
instance completeSpace : CompleteSpace ℤ_[p] :=
have : IsClosed { x : ℚ_[p] | ‖x‖ ≤ 1 } := isClosed_le continuous_norm continuous_const
this.completeSpace_coe
instance : Norm ℤ_[p] := ⟨fun z => ‖(z : ℚ_[p])‖⟩
variable {p}
theorem norm_def {z : ℤ_[p]} : ‖z‖ = ‖(z : ℚ_[p])‖ := rfl
variable (p)
instance : NormedCommRing ℤ_[p] :=
{ PadicInt.instCommRing with
dist_eq := fun ⟨_, _⟩ ⟨_, _⟩ => rfl
norm_mul := by simp [norm_def]
norm := norm }
instance : NormOneClass ℤ_[p] :=
⟨norm_def.trans norm_one⟩
instance isAbsoluteValue : IsAbsoluteValue fun z : ℤ_[p] => ‖z‖ where
abv_nonneg' := norm_nonneg
abv_eq_zero' := by simp [norm_eq_zero]
abv_add' := fun ⟨_, _⟩ ⟨_, _⟩ => norm_add_le _ _
abv_mul' _ _ := by simp only [norm_def, padicNormE.mul, PadicInt.coe_mul]
variable {p}
instance : IsDomain ℤ_[p] := Function.Injective.isDomain (subring p).subtype Subtype.coe_injective
end PadicInt
namespace PadicInt
/-! ### Norm -/
variable {p : ℕ} [Fact p.Prime]
theorem norm_le_one (z : ℤ_[p]) : ‖z‖ ≤ 1 := z.2
@[simp]
theorem norm_mul (z1 z2 : ℤ_[p]) : ‖z1 * z2‖ = ‖z1‖ * ‖z2‖ := by simp [norm_def]
@[simp]
theorem norm_pow (z : ℤ_[p]) : ∀ n : ℕ, ‖z ^ n‖ = ‖z‖ ^ n
| 0 => by simp
| k + 1 => by
rw [pow_succ, pow_succ, norm_mul]
congr
apply norm_pow
theorem nonarchimedean (q r : ℤ_[p]) : ‖q + r‖ ≤ max ‖q‖ ‖r‖ := padicNormE.nonarchimedean _ _
theorem norm_add_eq_max_of_ne {q r : ℤ_[p]} : ‖q‖ ≠ ‖r‖ → ‖q + r‖ = max ‖q‖ ‖r‖ :=
padicNormE.add_eq_max_of_ne
theorem norm_eq_of_norm_add_lt_right {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z2‖) : ‖z1‖ = ‖z2‖ :=
by_contra fun hne =>
not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; apply le_max_right) h
theorem norm_eq_of_norm_add_lt_left {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z1‖) : ‖z1‖ = ‖z2‖ :=
by_contra fun hne =>
not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; apply le_max_left) h
@[simp]
theorem padic_norm_e_of_padicInt (z : ℤ_[p]) : ‖(z : ℚ_[p])‖ = ‖z‖ := by simp [norm_def]
theorem norm_intCast_eq_padic_norm (z : ℤ) : ‖(z : ℤ_[p])‖ = ‖(z : ℚ_[p])‖ := by simp [norm_def]
@[deprecated (since := "2024-04-17")]
alias norm_int_cast_eq_padic_norm := norm_intCast_eq_padic_norm
@[simp]
theorem norm_eq_padic_norm {q : ℚ_[p]} (hq : ‖q‖ ≤ 1) : @norm ℤ_[p] _ ⟨q, hq⟩ = ‖q‖ := rfl
@[simp]
theorem norm_p : ‖(p : ℤ_[p])‖ = (p : ℝ)⁻¹ := padicNormE.norm_p
-- @[simp] -- Porting note: not in simpNF
theorem norm_p_pow (n : ℕ) : ‖(p : ℤ_[p]) ^ n‖ = (p : ℝ) ^ (-n : ℤ) := padicNormE.norm_p_pow n
private def cauSeq_to_rat_cauSeq (f : CauSeq ℤ_[p] norm) : CauSeq ℚ_[p] fun a => ‖a‖ :=
⟨fun n => f n, fun _ hε => by simpa [norm, norm_def] using f.cauchy hε⟩
variable (p)
instance complete : CauSeq.IsComplete ℤ_[p] norm :=
⟨fun f =>
have hqn : ‖CauSeq.lim (cauSeq_to_rat_cauSeq f)‖ ≤ 1 :=
padicNormE_lim_le zero_lt_one fun _ => norm_le_one _
⟨⟨_, hqn⟩, fun ε => by
simpa [norm, norm_def] using CauSeq.equiv_lim (cauSeq_to_rat_cauSeq f) ε⟩⟩
end PadicInt
namespace PadicInt
variable (p : ℕ) [hp : Fact p.Prime]
theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by
obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹
use k
rw [← inv_lt_inv hε (_root_.zpow_pos_of_pos _ _)]
· rw [zpow_neg, inv_inv, zpow_natCast]
apply lt_of_lt_of_le hk
norm_cast
apply le_of_lt
convert Nat.lt_pow_self _ _ using 1
exact hp.1.one_lt
· exact mod_cast hp.1.pos
theorem exists_pow_neg_lt_rat {ε : ℚ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℚ) ^ (-(k : ℤ)) < ε := by
obtain ⟨k, hk⟩ := @exists_pow_neg_lt p _ ε (mod_cast hε)
use k
rw [show (p : ℝ) = (p : ℚ) by simp] at hk
exact mod_cast hk
variable {p}
theorem norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℤ_[p])‖ < 1 ↔ (p : ℤ) ∣ k :=
suffices ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k by rwa [norm_intCast_eq_padic_norm]
padicNormE.norm_int_lt_one_iff_dvd k
theorem norm_int_le_pow_iff_dvd {k : ℤ} {n : ℕ} :
‖(k : ℤ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k :=
suffices ‖(k : ℚ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k by
simpa [norm_intCast_eq_padic_norm]
padicNormE.norm_int_le_pow_iff_dvd _ _
/-! ### Valuation on `ℤ_[p]` -/
/-- `PadicInt.valuation` lifts the `p`-adic valuation on `ℚ` to `ℤ_[p]`. -/
def valuation (x : ℤ_[p]) :=
Padic.valuation (x : ℚ_[p])
theorem norm_eq_pow_val {x : ℤ_[p]} (hx : x ≠ 0) : ‖x‖ = (p : ℝ) ^ (-x.valuation) := by
refine @Padic.norm_eq_pow_val p hp x ?_
contrapose! hx
exact Subtype.val_injective hx
@[simp]
theorem valuation_zero : valuation (0 : ℤ_[p]) = 0 := Padic.valuation_zero
@[simp]
theorem valuation_one : valuation (1 : ℤ_[p]) = 0 := Padic.valuation_one
@[simp]
theorem valuation_p : valuation (p : ℤ_[p]) = 1 := by simp [valuation]
theorem valuation_nonneg (x : ℤ_[p]) : 0 ≤ x.valuation := by
by_cases hx : x = 0
· simp [hx]
have h : (1 : ℝ) < p := mod_cast hp.1.one_lt
rw [← neg_nonpos, ← (zpow_strictMono h).le_iff_le]
show (p : ℝ) ^ (-valuation x) ≤ (p : ℝ) ^ (0 : ℤ)
rw [← norm_eq_pow_val hx]
simpa using x.property
@[simp]
theorem valuation_p_pow_mul (n : ℕ) (c : ℤ_[p]) (hc : c ≠ 0) :
((p : ℤ_[p]) ^ n * c).valuation = n + c.valuation := by
have : ‖(p : ℤ_[p]) ^ n * c‖ = ‖(p : ℤ_[p]) ^ n‖ * ‖c‖ := norm_mul _ _
have aux : (p : ℤ_[p]) ^ n * c ≠ 0 := by
contrapose! hc
rw [mul_eq_zero] at hc
cases' hc with hc hc
· refine (hp.1.ne_zero ?_).elim
exact_mod_cast pow_eq_zero hc
· exact hc
rwa [norm_eq_pow_val aux, norm_p_pow, norm_eq_pow_val hc, ← zpow_add₀, ← neg_add,
zpow_inj, neg_inj] at this
· exact mod_cast hp.1.pos
· exact mod_cast hp.1.ne_one
· exact mod_cast hp.1.ne_zero
section Units
/-! ### Units of `ℤ_[p]` -/
-- Porting note: `reducible` cannot be local and making it global breaks a lot of things
-- attribute [local reducible] PadicInt
theorem mul_inv : ∀ {z : ℤ_[p]}, ‖z‖ = 1 → z * z.inv = 1
| ⟨k, _⟩, h => by
have hk : k ≠ 0 := fun h' => zero_ne_one' ℚ_[p] (by simp [h'] at h)
unfold PadicInt.inv
rw [norm_eq_padic_norm] at h
dsimp only
rw [dif_pos h]
apply Subtype.ext_iff_val.2
simp [mul_inv_cancel hk]
theorem inv_mul {z : ℤ_[p]} (hz : ‖z‖ = 1) : z.inv * z = 1 := by rw [mul_comm, mul_inv hz]
theorem isUnit_iff {z : ℤ_[p]} : IsUnit z ↔ ‖z‖ = 1 :=
⟨fun h => by
rcases isUnit_iff_dvd_one.1 h with ⟨w, eq⟩
refine le_antisymm (norm_le_one _) ?_
have := mul_le_mul_of_nonneg_left (norm_le_one w) (norm_nonneg z)
rwa [mul_one, ← norm_mul, ← eq, norm_one] at this, fun h =>
⟨⟨z, z.inv, mul_inv h, inv_mul h⟩, rfl⟩⟩
theorem norm_lt_one_add {z1 z2 : ℤ_[p]} (hz1 : ‖z1‖ < 1) (hz2 : ‖z2‖ < 1) : ‖z1 + z2‖ < 1 :=
lt_of_le_of_lt (nonarchimedean _ _) (max_lt hz1 hz2)
theorem norm_lt_one_mul {z1 z2 : ℤ_[p]} (hz2 : ‖z2‖ < 1) : ‖z1 * z2‖ < 1 :=
calc
‖z1 * z2‖ = ‖z1‖ * ‖z2‖ := by simp
_ < 1 := mul_lt_one_of_nonneg_of_lt_one_right (norm_le_one _) (norm_nonneg _) hz2
-- @[simp] -- Porting note: not in simpNF
theorem mem_nonunits {z : ℤ_[p]} : z ∈ nonunits ℤ_[p] ↔ ‖z‖ < 1 := by
rw [lt_iff_le_and_ne]; simp [norm_le_one z, nonunits, isUnit_iff]
/-- A `p`-adic number `u` with `‖u‖ = 1` is a unit of `ℤ_[p]`. -/
def mkUnits {u : ℚ_[p]} (h : ‖u‖ = 1) : ℤ_[p]ˣ :=
let z : ℤ_[p] := ⟨u, le_of_eq h⟩
⟨z, z.inv, mul_inv h, inv_mul h⟩
@[simp]
theorem mkUnits_eq {u : ℚ_[p]} (h : ‖u‖ = 1) : ((mkUnits h : ℤ_[p]) : ℚ_[p]) = u := rfl
@[simp]
theorem norm_units (u : ℤ_[p]ˣ) : ‖(u : ℤ_[p])‖ = 1 := isUnit_iff.mp <| by simp
/-- `unitCoeff hx` is the unit `u` in the unique representation `x = u * p ^ n`.
See `unitCoeff_spec`. -/
def unitCoeff {x : ℤ_[p]} (hx : x ≠ 0) : ℤ_[p]ˣ :=
let u : ℚ_[p] := x * (p : ℚ_[p]) ^ (-x.valuation)
have hu : ‖u‖ = 1 := by
simp [u, hx, Nat.zpow_ne_zero_of_pos (mod_cast hp.1.pos) x.valuation, norm_eq_pow_val,
zpow_neg, inv_mul_cancel]
mkUnits hu
@[simp]
theorem unitCoeff_coe {x : ℤ_[p]} (hx : x ≠ 0) :
(unitCoeff hx : ℚ_[p]) = x * (p : ℚ_[p]) ^ (-x.valuation) := rfl
theorem unitCoeff_spec {x : ℤ_[p]} (hx : x ≠ 0) :
x = (unitCoeff hx : ℤ_[p]) * (p : ℤ_[p]) ^ Int.natAbs (valuation x) := by
apply Subtype.coe_injective
push_cast
have repr : (x : ℚ_[p]) = unitCoeff hx * (p : ℚ_[p]) ^ x.valuation := by
rw [unitCoeff_coe, mul_assoc, ← zpow_add₀]
· simp
· exact mod_cast hp.1.ne_zero
convert repr using 2
rw [← zpow_natCast, Int.natAbs_of_nonneg (valuation_nonneg x)]
end Units
section NormLeIff
/-! ### Various characterizations of open unit balls -/
theorem norm_le_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ ↑n ≤ x.valuation := by
rw [norm_eq_pow_val hx]
lift x.valuation to ℕ using x.valuation_nonneg with k
simp only [Int.ofNat_le, zpow_neg, zpow_natCast]
have aux : ∀ m : ℕ, 0 < (p : ℝ) ^ m := by
intro m
refine pow_pos ?_ m
exact mod_cast hp.1.pos
rw [inv_le_inv (aux _) (aux _)]
have : p ^ n ≤ p ^ k ↔ n ≤ k := (pow_right_strictMono hp.1.one_lt).le_iff_le
rw [← this]
norm_cast
theorem mem_span_pow_iff_le_valuation (x : ℤ_[p]) (hx : x ≠ 0) (n : ℕ) :
x ∈ (Ideal.span {(p : ℤ_[p]) ^ n} : Ideal ℤ_[p]) ↔ ↑n ≤ x.valuation := by
rw [Ideal.mem_span_singleton]
constructor
· rintro ⟨c, rfl⟩
suffices c ≠ 0 by
rw [valuation_p_pow_mul _ _ this, le_add_iff_nonneg_right]
apply valuation_nonneg
contrapose! hx
rw [hx, mul_zero]
· nth_rewrite 2 [unitCoeff_spec hx]
lift x.valuation to ℕ using x.valuation_nonneg with k
simp only [Int.natAbs_ofNat, Units.isUnit, IsUnit.dvd_mul_left, Int.ofNat_le]
intro H
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le H
simp only [pow_add, dvd_mul_right]
theorem norm_le_pow_iff_mem_span_pow (x : ℤ_[p]) (n : ℕ) :
‖x‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ x ∈ (Ideal.span {(p : ℤ_[p]) ^ n} : Ideal ℤ_[p]) := by
by_cases hx : x = 0
· subst hx
simp only [norm_zero, zpow_neg, zpow_natCast, inv_nonneg, iff_true_iff, Submodule.zero_mem]
exact mod_cast Nat.zero_le _
rw [norm_le_pow_iff_le_valuation x hx, mem_span_pow_iff_le_valuation x hx]
theorem norm_le_pow_iff_norm_lt_pow_add_one (x : ℤ_[p]) (n : ℤ) :
‖x‖ ≤ (p : ℝ) ^ n ↔ ‖x‖ < (p : ℝ) ^ (n + 1) := by
rw [norm_def]; exact Padic.norm_le_pow_iff_norm_lt_pow_add_one _ _
theorem norm_lt_pow_iff_norm_le_pow_sub_one (x : ℤ_[p]) (n : ℤ) :
‖x‖ < (p : ℝ) ^ n ↔ ‖x‖ ≤ (p : ℝ) ^ (n - 1) := by
rw [norm_le_pow_iff_norm_lt_pow_add_one, sub_add_cancel]
theorem norm_lt_one_iff_dvd (x : ℤ_[p]) : ‖x‖ < 1 ↔ ↑p ∣ x := by
have := norm_le_pow_iff_mem_span_pow x 1
rw [Ideal.mem_span_singleton, pow_one] at this
rw [← this, norm_le_pow_iff_norm_lt_pow_add_one]
simp only [zpow_zero, Int.ofNat_zero, Int.ofNat_succ, add_left_neg, zero_add]
@[simp]
theorem pow_p_dvd_int_iff (n : ℕ) (a : ℤ) : (p : ℤ_[p]) ^ n ∣ a ↔ (p ^ n : ℤ) ∣ a := by
rw [← Nat.cast_pow, ← norm_int_le_pow_iff_dvd, norm_le_pow_iff_mem_span_pow,
Ideal.mem_span_singleton, Nat.cast_pow]
end NormLeIff
section Dvr
/-! ### Discrete valuation ring -/
instance : LocalRing ℤ_[p] :=
LocalRing.of_nonunits_add <| by simp only [mem_nonunits]; exact fun x y => norm_lt_one_add
theorem p_nonnunit : (p : ℤ_[p]) ∈ nonunits ℤ_[p] := by
have : (p : ℝ)⁻¹ < 1 := inv_lt_one <| mod_cast hp.1.one_lt
rwa [← norm_p, ← mem_nonunits] at this
theorem maximalIdeal_eq_span_p : maximalIdeal ℤ_[p] = Ideal.span {(p : ℤ_[p])} := by
apply le_antisymm
· intro x hx
simp only [LocalRing.mem_maximalIdeal, mem_nonunits] at hx
rwa [Ideal.mem_span_singleton, ← norm_lt_one_iff_dvd]
· rw [Ideal.span_le, Set.singleton_subset_iff]
exact p_nonnunit
theorem prime_p : Prime (p : ℤ_[p]) := by
rw [← Ideal.span_singleton_prime, ← maximalIdeal_eq_span_p]
· infer_instance
· exact mod_cast hp.1.ne_zero
theorem irreducible_p : Irreducible (p : ℤ_[p]) := Prime.irreducible prime_p
instance : DiscreteValuationRing ℤ_[p] :=
DiscreteValuationRing.ofHasUnitMulPowIrreducibleFactorization
⟨p, irreducible_p, fun {x hx} =>
⟨x.valuation.natAbs, unitCoeff hx, by rw [mul_comm, ← unitCoeff_spec hx]⟩⟩
theorem ideal_eq_span_pow_p {s : Ideal ℤ_[p]} (hs : s ≠ ⊥) :
∃ n : ℕ, s = Ideal.span {(p : ℤ_[p]) ^ n} :=
DiscreteValuationRing.ideal_eq_span_pow_irreducible hs irreducible_p
open CauSeq
instance : IsAdicComplete (maximalIdeal ℤ_[p]) ℤ_[p] where
prec' x hx := by
simp only [← Ideal.one_eq_top, smul_eq_mul, mul_one, SModEq.sub_mem, maximalIdeal_eq_span_p,
Ideal.span_singleton_pow, ← norm_le_pow_iff_mem_span_pow] at hx ⊢
let x' : CauSeq ℤ_[p] norm := ⟨x, ?_⟩; swap
· intro ε hε
obtain ⟨m, hm⟩ := exists_pow_neg_lt p hε
refine ⟨m, fun n hn => lt_of_le_of_lt ?_ hm⟩
rw [← neg_sub, norm_neg]
exact hx hn
· refine ⟨x'.lim, fun n => ?_⟩
have : (0 : ℝ) < (p : ℝ) ^ (-n : ℤ) := by
apply zpow_pos_of_pos
exact mod_cast hp.1.pos
obtain ⟨i, hi⟩ := equiv_def₃ (equiv_lim x') this
by_cases hin : i ≤ n
· exact (hi i le_rfl n hin).le
· push_neg at hin
specialize hi i le_rfl i le_rfl
specialize hx hin.le
have := nonarchimedean (x n - x i : ℤ_[p]) (x i - x'.lim)
rw [sub_add_sub_cancel] at this
exact this.trans (max_le_iff.mpr ⟨hx, hi.le⟩)
end Dvr
section FractionRing
instance algebra : Algebra ℤ_[p] ℚ_[p] :=
Algebra.ofSubring (subring p)
@[simp]
theorem algebraMap_apply (x : ℤ_[p]) : algebraMap ℤ_[p] ℚ_[p] x = x :=
rfl
instance isFractionRing : IsFractionRing ℤ_[p] ℚ_[p] where
map_units' := fun ⟨x, hx⟩ => by
rwa [algebraMap_apply, isUnit_iff_ne_zero, PadicInt.coe_ne_zero, ←
mem_nonZeroDivisors_iff_ne_zero]
surj' x := by
by_cases hx : ‖x‖ ≤ 1
· use (⟨x, hx⟩, 1)
rw [Submonoid.coe_one, map_one, mul_one, PadicInt.algebraMap_apply, Subtype.coe_mk]
· set n := Int.toNat (-x.valuation) with hn
have hn_coe : (n : ℤ) = -x.valuation := by
rw [hn, Int.toNat_of_nonneg]
rw [Right.nonneg_neg_iff]
rw [Padic.norm_le_one_iff_val_nonneg, not_le] at hx
exact hx.le
set a := x * (p : ℚ_[p]) ^ n with ha
have ha_norm : ‖a‖ = 1 := by
have hx : x ≠ 0 := by
intro h0
rw [h0, norm_zero] at hx
exact hx zero_le_one
rw [ha, padicNormE.mul, padicNormE.norm_p_pow, Padic.norm_eq_pow_val hx, ← zpow_add',
hn_coe, neg_neg, add_left_neg, zpow_zero]
exact Or.inl (Nat.cast_ne_zero.mpr (NeZero.ne p))
use
(⟨a, le_of_eq ha_norm⟩,
⟨(p ^ n : ℤ_[p]), mem_nonZeroDivisors_iff_ne_zero.mpr (NeZero.ne _)⟩)
simp only [map_pow, map_natCast, algebraMap_apply, PadicInt.coe_pow, PadicInt.coe_natCast,
Subtype.coe_mk, Nat.cast_pow]
exists_of_eq := by
simp_rw [algebraMap_apply, Subtype.coe_inj]
exact fun h => ⟨1, by rw [h]⟩
end FractionRing
end PadicInt
|
NumberTheory\Padics\PadicNorm.lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import Mathlib.Algebra.Order.Field.Power
import Mathlib.NumberTheory.Padics.PadicVal
/-!
# p-adic norm
This file defines the `p`-adic norm on `ℚ`.
The `p`-adic valuation on `ℚ` is the difference of the multiplicities of `p` in the numerator and
denominator of `q`. This function obeys the standard properties of a valuation, with the appropriate
assumptions on `p`.
The valuation induces a norm on `ℚ`. This norm is a nonarchimedean absolute value.
It takes values in {0} ∪ {1/p^k | k ∈ ℤ}.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking `[Fact p.Prime]` as a type class argument.
## References
* [F. Q. Gouvêa, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, norm, valuation
-/
/-- If `q ≠ 0`, the `p`-adic norm of a rational `q` is `p ^ (-padicValRat p q)`.
If `q = 0`, the `p`-adic norm of `q` is `0`. -/
def padicNorm (p : ℕ) (q : ℚ) : ℚ :=
if q = 0 then 0 else (p : ℚ) ^ (-padicValRat p q)
namespace padicNorm
open padicValRat
variable {p : ℕ}
/-- Unfolds the definition of the `p`-adic norm of `q` when `q ≠ 0`. -/
@[simp]
protected theorem eq_zpow_of_nonzero {q : ℚ} (hq : q ≠ 0) :
padicNorm p q = (p : ℚ) ^ (-padicValRat p q) := by simp [hq, padicNorm]
/-- The `p`-adic norm is nonnegative. -/
protected theorem nonneg (q : ℚ) : 0 ≤ padicNorm p q :=
if hq : q = 0 then by simp [hq, padicNorm]
else by
unfold padicNorm
split_ifs
apply zpow_nonneg
exact mod_cast Nat.zero_le _
/-- The `p`-adic norm of `0` is `0`. -/
@[simp]
protected theorem zero : padicNorm p 0 = 0 := by simp [padicNorm]
/-- The `p`-adic norm of `1` is `1`. -/
-- @[simp] -- Porting note (#10618): simp can prove this
protected theorem one : padicNorm p 1 = 1 := by simp [padicNorm]
/-- The `p`-adic norm of `p` is `p⁻¹` if `p > 1`.
See also `padicNorm.padicNorm_p_of_prime` for a version assuming `p` is prime. -/
theorem padicNorm_p (hp : 1 < p) : padicNorm p p = (p : ℚ)⁻¹ := by
simp [padicNorm, (pos_of_gt hp).ne', padicValNat.self hp]
/-- The `p`-adic norm of `p` is `p⁻¹` if `p` is prime.
See also `padicNorm.padicNorm_p` for a version assuming `1 < p`. -/
@[simp]
theorem padicNorm_p_of_prime [Fact p.Prime] : padicNorm p p = (p : ℚ)⁻¹ :=
padicNorm_p <| Nat.Prime.one_lt Fact.out
/-- The `p`-adic norm of `q` is `1` if `q` is prime and not equal to `p`. -/
theorem padicNorm_of_prime_of_ne {q : ℕ} [p_prime : Fact p.Prime] [q_prime : Fact q.Prime]
(neq : p ≠ q) : padicNorm p q = 1 := by
have p : padicValRat p q = 0 := mod_cast padicValNat_primes neq
rw [padicNorm, p]
simp [q_prime.1.ne_zero]
/-- The `p`-adic norm of `p` is less than `1` if `1 < p`.
See also `padicNorm.padicNorm_p_lt_one_of_prime` for a version assuming `p` is prime. -/
theorem padicNorm_p_lt_one (hp : 1 < p) : padicNorm p p < 1 := by
rw [padicNorm_p hp, inv_lt_one_iff]
exact mod_cast Or.inr hp
/-- The `p`-adic norm of `p` is less than `1` if `p` is prime.
See also `padicNorm.padicNorm_p_lt_one` for a version assuming `1 < p`. -/
theorem padicNorm_p_lt_one_of_prime [Fact p.Prime] : padicNorm p p < 1 :=
padicNorm_p_lt_one <| Nat.Prime.one_lt Fact.out
/-- `padicNorm p q` takes discrete values `p ^ -z` for `z : ℤ`. -/
protected theorem values_discrete {q : ℚ} (hq : q ≠ 0) : ∃ z : ℤ, padicNorm p q = (p : ℚ) ^ (-z) :=
⟨padicValRat p q, by simp [padicNorm, hq]⟩
/-- `padicNorm p` is symmetric. -/
@[simp]
protected theorem neg (q : ℚ) : padicNorm p (-q) = padicNorm p q :=
if hq : q = 0 then by simp [hq] else by simp [padicNorm, hq]
variable [hp : Fact p.Prime]
/-- If `q ≠ 0`, then `padicNorm p q ≠ 0`. -/
protected theorem nonzero {q : ℚ} (hq : q ≠ 0) : padicNorm p q ≠ 0 := by
rw [padicNorm.eq_zpow_of_nonzero hq]
apply zpow_ne_zero
exact mod_cast ne_of_gt hp.1.pos
/-- If the `p`-adic norm of `q` is 0, then `q` is `0`. -/
theorem zero_of_padicNorm_eq_zero {q : ℚ} (h : padicNorm p q = 0) : q = 0 := by
apply by_contradiction; intro hq
unfold padicNorm at h; rw [if_neg hq] at h
apply absurd h
apply zpow_ne_zero
exact mod_cast hp.1.ne_zero
/-- The `p`-adic norm is multiplicative. -/
@[simp]
protected theorem mul (q r : ℚ) : padicNorm p (q * r) = padicNorm p q * padicNorm p r :=
if hq : q = 0 then by simp [hq]
else
if hr : r = 0 then by simp [hr]
else by
have : (p : ℚ) ≠ 0 := by simp [hp.1.ne_zero]
simp [padicNorm, *, padicValRat.mul, zpow_add₀ this, mul_comm]
/-- The `p`-adic norm respects division. -/
@[simp]
protected theorem div (q r : ℚ) : padicNorm p (q / r) = padicNorm p q / padicNorm p r :=
if hr : r = 0 then by simp [hr]
else eq_div_of_mul_eq (padicNorm.nonzero hr) (by rw [← padicNorm.mul, div_mul_cancel₀ _ hr])
/-- The `p`-adic norm of an integer is at most `1`. -/
protected theorem of_int (z : ℤ) : padicNorm p z ≤ 1 :=
if hz : z = 0 then by simp [hz, zero_le_one]
else by
unfold padicNorm
rw [if_neg _]
· refine zpow_le_one_of_nonpos ?_ ?_
· exact mod_cast le_of_lt hp.1.one_lt
· rw [padicValRat.of_int, neg_nonpos]
norm_cast
simp
exact mod_cast hz
private theorem nonarchimedean_aux {q r : ℚ} (h : padicValRat p q ≤ padicValRat p r) :
padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) :=
have hnqp : padicNorm p q ≥ 0 := padicNorm.nonneg _
have hnrp : padicNorm p r ≥ 0 := padicNorm.nonneg _
if hq : q = 0 then by simp [hq, max_eq_right hnrp, le_max_right]
else
if hr : r = 0 then by simp [hr, max_eq_left hnqp, le_max_left]
else
if hqr : q + r = 0 then le_trans (by simpa [hqr] using hnqp) (le_max_left _ _)
else by
unfold padicNorm; split_ifs
apply le_max_iff.2
left
apply zpow_le_of_le
· exact mod_cast le_of_lt hp.1.one_lt
· apply neg_le_neg
have : padicValRat p q = min (padicValRat p q) (padicValRat p r) := (min_eq_left h).symm
rw [this]
exact min_le_padicValRat_add hqr
/-- The `p`-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p`
and the norm of `q`. -/
protected theorem nonarchimedean {q r : ℚ} :
padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) := by
wlog hle : padicValRat p q ≤ padicValRat p r generalizing q r
· rw [add_comm, max_comm]
exact this (le_of_not_le hle)
exact nonarchimedean_aux hle
/-- The `p`-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of
`p` plus the norm of `q`. -/
theorem triangle_ineq (q r : ℚ) : padicNorm p (q + r) ≤ padicNorm p q + padicNorm p r :=
calc
padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) := padicNorm.nonarchimedean
_ ≤ padicNorm p q + padicNorm p r :=
max_le_add_of_nonneg (padicNorm.nonneg _) (padicNorm.nonneg _)
/-- The `p`-adic norm of a difference is at most the max of each component. Restates the archimedean
property of the `p`-adic norm. -/
protected theorem sub {q r : ℚ} : padicNorm p (q - r) ≤ max (padicNorm p q) (padicNorm p r) := by
rw [sub_eq_add_neg, ← padicNorm.neg r]
exact padicNorm.nonarchimedean
/-- If the `p`-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max
of the norms of `q` and `r`. -/
theorem add_eq_max_of_ne {q r : ℚ} (hne : padicNorm p q ≠ padicNorm p r) :
padicNorm p (q + r) = max (padicNorm p q) (padicNorm p r) := by
wlog hlt : padicNorm p r < padicNorm p q
· rw [add_comm, max_comm]
exact this hne.symm (hne.lt_or_lt.resolve_right hlt)
have : padicNorm p q ≤ max (padicNorm p (q + r)) (padicNorm p r) :=
calc
padicNorm p q = padicNorm p (q + r + (-r)) := by ring_nf
_ ≤ max (padicNorm p (q + r)) (padicNorm p (-r)) := padicNorm.nonarchimedean
_ = max (padicNorm p (q + r)) (padicNorm p r) := by simp
have hnge : padicNorm p r ≤ padicNorm p (q + r) := by
apply le_of_not_gt
intro hgt
rw [max_eq_right_of_lt hgt] at this
exact not_lt_of_ge this hlt
have : padicNorm p q ≤ padicNorm p (q + r) := by rwa [max_eq_left hnge] at this
apply _root_.le_antisymm
· apply padicNorm.nonarchimedean
· rwa [max_eq_left_of_lt hlt]
/-- The `p`-adic norm is an absolute value: positive-definite and multiplicative, satisfying the
triangle inequality. -/
instance : IsAbsoluteValue (padicNorm p) where
abv_nonneg' := padicNorm.nonneg
abv_eq_zero' := ⟨zero_of_padicNorm_eq_zero, fun hx ↦ by simp [hx]⟩
abv_add' := padicNorm.triangle_ineq
abv_mul' := padicNorm.mul
theorem dvd_iff_norm_le {n : ℕ} {z : ℤ} : ↑(p ^ n) ∣ z ↔ padicNorm p z ≤ (p : ℚ) ^ (-n : ℤ) := by
unfold padicNorm; split_ifs with hz
· norm_cast at hz
simp [hz]
· rw [zpow_le_iff_le, neg_le_neg_iff, padicValRat.of_int,
padicValInt.of_ne_one_ne_zero hp.1.ne_one _]
· norm_cast
rw [← PartENat.coe_le_coe, PartENat.natCast_get, ← multiplicity.pow_dvd_iff_le_multiplicity,
Nat.cast_pow]
exact mod_cast hz
· exact mod_cast hp.1.one_lt
/-- The `p`-adic norm of an integer `m` is one iff `p` doesn't divide `m`. -/
theorem int_eq_one_iff (m : ℤ) : padicNorm p m = 1 ↔ ¬(p : ℤ) ∣ m := by
nth_rw 2 [← pow_one p]
simp only [dvd_iff_norm_le, Int.cast_natCast, Nat.cast_one, zpow_neg, zpow_one, not_le]
constructor
· intro h
rw [h, inv_lt_one_iff_of_pos] <;> norm_cast
· exact Nat.Prime.one_lt Fact.out
· exact Nat.Prime.pos Fact.out
· simp only [padicNorm]
split_ifs
· rw [inv_lt_zero, ← Nat.cast_zero, Nat.cast_lt]
intro h
exact (Nat.not_lt_zero p h).elim
· have : 1 < (p : ℚ) := by norm_cast; exact Nat.Prime.one_lt (Fact.out : Nat.Prime p)
rw [← zpow_neg_one, zpow_lt_iff_lt this]
have : 0 ≤ padicValRat p m := by simp only [of_int, Nat.cast_nonneg]
intro h
rw [← zpow_zero (p : ℚ), zpow_inj] <;> linarith
theorem int_lt_one_iff (m : ℤ) : padicNorm p m < 1 ↔ (p : ℤ) ∣ m := by
rw [← not_iff_not, ← int_eq_one_iff, eq_iff_le_not_lt]
simp only [padicNorm.of_int, true_and_iff]
theorem of_nat (m : ℕ) : padicNorm p m ≤ 1 :=
padicNorm.of_int (m : ℤ)
/-- The `p`-adic norm of a natural `m` is one iff `p` doesn't divide `m`. -/
theorem nat_eq_one_iff (m : ℕ) : padicNorm p m = 1 ↔ ¬p ∣ m := by
rw [← Int.natCast_dvd_natCast, ← int_eq_one_iff, Int.cast_natCast]
theorem nat_lt_one_iff (m : ℕ) : padicNorm p m < 1 ↔ p ∣ m := by
rw [← Int.natCast_dvd_natCast, ← int_lt_one_iff, Int.cast_natCast]
/-- If a rational is not a p-adic integer, it is not an integer. -/
theorem not_int_of_not_padic_int (p : ℕ) {a : ℚ} [hp : Fact (Nat.Prime p)]
(H : 1 < padicNorm p a) : ¬ a.isInt := by
contrapose! H
rw [Rat.eq_num_of_isInt H]
apply padicNorm.of_int
theorem sum_lt {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α} :
s.Nonempty → (∀ i ∈ s, padicNorm p (F i) < t) → padicNorm p (∑ i ∈ s, F i) < t := by
classical
refine s.induction_on (by rintro ⟨-, ⟨⟩⟩) ?_
rintro a S haS IH - ht
by_cases hs : S.Nonempty
· rw [Finset.sum_insert haS]
exact
lt_of_le_of_lt padicNorm.nonarchimedean
(max_lt (ht a (Finset.mem_insert_self a S))
(IH hs fun b hb ↦ ht b (Finset.mem_insert_of_mem hb)))
· simp_all
theorem sum_le {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α} :
s.Nonempty → (∀ i ∈ s, padicNorm p (F i) ≤ t) → padicNorm p (∑ i ∈ s, F i) ≤ t := by
classical
refine s.induction_on (by rintro ⟨-, ⟨⟩⟩) ?_
rintro a S haS IH - ht
by_cases hs : S.Nonempty
· rw [Finset.sum_insert haS]
exact
padicNorm.nonarchimedean.trans
(max_le (ht a (Finset.mem_insert_self a S))
(IH hs fun b hb ↦ ht b (Finset.mem_insert_of_mem hb)))
· simp_all
theorem sum_lt' {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α}
(hF : ∀ i ∈ s, padicNorm p (F i) < t) (ht : 0 < t) : padicNorm p (∑ i ∈ s, F i) < t := by
obtain rfl | hs := Finset.eq_empty_or_nonempty s
· simp [ht]
· exact sum_lt hs hF
theorem sum_le' {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α}
(hF : ∀ i ∈ s, padicNorm p (F i) ≤ t) (ht : 0 ≤ t) : padicNorm p (∑ i ∈ s, F i) ≤ t := by
obtain rfl | hs := Finset.eq_empty_or_nonempty s
· simp [ht]
· exact sum_le hs hF
end padicNorm
|
NumberTheory\Padics\PadicNumbers.lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import Mathlib.RingTheory.Valuation.Basic
import Mathlib.NumberTheory.Padics.PadicNorm
import Mathlib.Analysis.Normed.Field.Basic
import Mathlib.Tactic.Peel
import Mathlib.Topology.MetricSpace.Ultra.Basic
/-!
# p-adic numbers
This file defines the `p`-adic numbers (rationals) `ℚ_[p]` as
the completion of `ℚ` with respect to the `p`-adic norm.
We show that the `p`-adic norm on `ℚ` extends to `ℚ_[p]`, that `ℚ` is embedded in `ℚ_[p]`,
and that `ℚ_[p]` is Cauchy complete.
## Important definitions
* `Padic` : the type of `p`-adic numbers
* `padicNormE` : the rational valued `p`-adic norm on `ℚ_[p]`
* `Padic.addValuation` : the additive `p`-adic valuation on `ℚ_[p]`, with values in `WithTop ℤ`
## Notation
We introduce the notation `ℚ_[p]` for the `p`-adic numbers.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking `[Fact p.Prime]` as a type class argument.
We use the same concrete Cauchy sequence construction that is used to construct `ℝ`.
`ℚ_[p]` inherits a field structure from this construction.
The extension of the norm on `ℚ` to `ℚ_[p]` is *not* analogous to extending the absolute value to
`ℝ` and hence the proof that `ℚ_[p]` is complete is different from the proof that ℝ is complete.
A small special-purpose simplification tactic, `padic_index_simp`, is used to manipulate sequence
indices in the proof that the norm extends.
`padicNormE` is the rational-valued `p`-adic norm on `ℚ_[p]`.
To instantiate `ℚ_[p]` as a normed field, we must cast this into an `ℝ`-valued norm.
The `ℝ`-valued norm, using notation `‖ ‖` from normed spaces,
is the canonical representation of this norm.
`simp` prefers `padicNorm` to `padicNormE` when possible.
Since `padicNormE` and `‖ ‖` have different types, `simp` does not rewrite one to the other.
Coercions from `ℚ` to `ℚ_[p]` are set up to work with the `norm_cast` tactic.
## References
* [F. Q. Gouvêa, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion
-/
noncomputable section
open Nat multiplicity padicNorm CauSeq CauSeq.Completion Metric
/-- The type of Cauchy sequences of rationals with respect to the `p`-adic norm. -/
abbrev PadicSeq (p : ℕ) :=
CauSeq _ (padicNorm p)
namespace PadicSeq
section
variable {p : ℕ} [Fact p.Prime]
/-- The `p`-adic norm of the entries of a nonzero Cauchy sequence of rationals is eventually
constant. -/
theorem stationary {f : CauSeq ℚ (padicNorm p)} (hf : ¬f ≈ 0) :
∃ N, ∀ m n, N ≤ m → N ≤ n → padicNorm p (f n) = padicNorm p (f m) :=
have : ∃ ε > 0, ∃ N1, ∀ j ≥ N1, ε ≤ padicNorm p (f j) :=
CauSeq.abv_pos_of_not_limZero <| not_limZero_of_not_congr_zero hf
let ⟨ε, hε, N1, hN1⟩ := this
let ⟨N2, hN2⟩ := CauSeq.cauchy₂ f hε
⟨max N1 N2, fun n m hn hm ↦ by
have : padicNorm p (f n - f m) < ε := hN2 _ (max_le_iff.1 hn).2 _ (max_le_iff.1 hm).2
have : padicNorm p (f n - f m) < padicNorm p (f n) :=
lt_of_lt_of_le this <| hN1 _ (max_le_iff.1 hn).1
have : padicNorm p (f n - f m) < max (padicNorm p (f n)) (padicNorm p (f m)) :=
lt_max_iff.2 (Or.inl this)
by_contra hne
rw [← padicNorm.neg (f m)] at hne
have hnam := add_eq_max_of_ne hne
rw [padicNorm.neg, max_comm] at hnam
rw [← hnam, sub_eq_add_neg, add_comm] at this
apply _root_.lt_irrefl _ this⟩
/-- For all `n ≥ stationaryPoint f hf`, the `p`-adic norm of `f n` is the same. -/
def stationaryPoint {f : PadicSeq p} (hf : ¬f ≈ 0) : ℕ :=
Classical.choose <| stationary hf
theorem stationaryPoint_spec {f : PadicSeq p} (hf : ¬f ≈ 0) :
∀ {m n},
stationaryPoint hf ≤ m → stationaryPoint hf ≤ n → padicNorm p (f n) = padicNorm p (f m) :=
@(Classical.choose_spec <| stationary hf)
open Classical in
/-- Since the norm of the entries of a Cauchy sequence is eventually stationary,
we can lift the norm to sequences. -/
def norm (f : PadicSeq p) : ℚ :=
if hf : f ≈ 0 then 0 else padicNorm p (f (stationaryPoint hf))
theorem norm_zero_iff (f : PadicSeq p) : f.norm = 0 ↔ f ≈ 0 := by
constructor
· intro h
by_contra hf
unfold norm at h
split_ifs at h
apply hf
intro ε hε
exists stationaryPoint hf
intro j hj
have heq := stationaryPoint_spec hf le_rfl hj
simpa [h, heq]
· intro h
simp [norm, h]
end
section Embedding
open CauSeq
variable {p : ℕ} [Fact p.Prime]
theorem equiv_zero_of_val_eq_of_equiv_zero {f g : PadicSeq p}
(h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) (hf : f ≈ 0) : g ≈ 0 := fun ε hε ↦
let ⟨i, hi⟩ := hf _ hε
⟨i, fun j hj ↦ by simpa [h] using hi _ hj⟩
theorem norm_nonzero_of_not_equiv_zero {f : PadicSeq p} (hf : ¬f ≈ 0) : f.norm ≠ 0 :=
hf ∘ f.norm_zero_iff.1
theorem norm_eq_norm_app_of_nonzero {f : PadicSeq p} (hf : ¬f ≈ 0) :
∃ k, f.norm = padicNorm p k ∧ k ≠ 0 :=
have heq : f.norm = padicNorm p (f <| stationaryPoint hf) := by simp [norm, hf]
⟨f <| stationaryPoint hf, heq, fun h ↦
norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)⟩
theorem not_limZero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬LimZero (const (padicNorm p) q) :=
fun h' ↦ hq <| const_limZero.1 h'
theorem not_equiv_zero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬const (padicNorm p) q ≈ 0 :=
fun h : LimZero (const (padicNorm p) q - 0) ↦ not_limZero_const_of_nonzero hq <| by simpa using h
theorem norm_nonneg (f : PadicSeq p) : 0 ≤ f.norm := by
classical exact if hf : f ≈ 0 then by simp [hf, norm] else by simp [norm, hf, padicNorm.nonneg]
/-- An auxiliary lemma for manipulating sequence indices. -/
theorem lift_index_left_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v2 v3 : ℕ) :
padicNorm p (f (stationaryPoint hf)) =
padicNorm p (f (max (stationaryPoint hf) (max v2 v3))) := by
apply stationaryPoint_spec hf
· apply le_max_left
· exact le_rfl
/-- An auxiliary lemma for manipulating sequence indices. -/
theorem lift_index_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v3 : ℕ) :
padicNorm p (f (stationaryPoint hf)) =
padicNorm p (f (max v1 (max (stationaryPoint hf) v3))) := by
apply stationaryPoint_spec hf
· apply le_trans
· apply le_max_left _ v3
· apply le_max_right
· exact le_rfl
/-- An auxiliary lemma for manipulating sequence indices. -/
theorem lift_index_right {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v2 : ℕ) :
padicNorm p (f (stationaryPoint hf)) =
padicNorm p (f (max v1 (max v2 (stationaryPoint hf)))) := by
apply stationaryPoint_spec hf
· apply le_trans
· apply le_max_right v2
· apply le_max_right
· exact le_rfl
end Embedding
section Valuation
open CauSeq
variable {p : ℕ} [Fact p.Prime]
/-! ### Valuation on `PadicSeq` -/
open Classical in
/-- The `p`-adic valuation on `ℚ` lifts to `PadicSeq p`.
`Valuation f` is defined to be the valuation of the (`ℚ`-valued) stationary point of `f`. -/
def valuation (f : PadicSeq p) : ℤ :=
if hf : f ≈ 0 then 0 else padicValRat p (f (stationaryPoint hf))
theorem norm_eq_pow_val {f : PadicSeq p} (hf : ¬f ≈ 0) : f.norm = (p : ℚ) ^ (-f.valuation : ℤ) := by
rw [norm, valuation, dif_neg hf, dif_neg hf, padicNorm, if_neg]
intro H
apply CauSeq.not_limZero_of_not_congr_zero hf
intro ε hε
use stationaryPoint hf
intro n hn
rw [stationaryPoint_spec hf le_rfl hn]
simpa [H] using hε
theorem val_eq_iff_norm_eq {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) :
f.valuation = g.valuation ↔ f.norm = g.norm := by
rw [norm_eq_pow_val hf, norm_eq_pow_val hg, ← neg_inj, zpow_inj]
· exact mod_cast (Fact.out : p.Prime).pos
· exact mod_cast (Fact.out : p.Prime).ne_one
end Valuation
end PadicSeq
section
open PadicSeq
-- Porting note: Commented out `padic_index_simp` tactic
/-
private unsafe def index_simp_core (hh hf hg : expr)
(at_ : Interactive.Loc := Interactive.Loc.ns [none]) : tactic Unit := do
let [v1, v2, v3] ← [hh, hf, hg].mapM fun n => tactic.mk_app `` stationary_point [n] <|> return n
let e1 ← tactic.mk_app `` lift_index_left_left [hh, v2, v3] <|> return q(True)
let e2 ← tactic.mk_app `` lift_index_left [hf, v1, v3] <|> return q(True)
let e3 ← tactic.mk_app `` lift_index_right [hg, v1, v2] <|> return q(True)
let sl ← [e1, e2, e3].foldlM (fun s e => simp_lemmas.add s e) simp_lemmas.mk
when at_ (tactic.simp_target sl >> tactic.skip)
let hs ← at_.get_locals
hs (tactic.simp_hyp sl [])
/-- This is a special-purpose tactic that lifts `padicNorm (f (stationary_point f))` to
`padicNorm (f (max _ _ _))`. -/
unsafe def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list)
(at_ : interactive.parse interactive.types.location) : tactic Unit := do
let [h, f, g] ← l.mapM tactic.i_to_expr
index_simp_core h f g at_
-/
end
namespace PadicSeq
section Embedding
open CauSeq
variable {p : ℕ} [hp : Fact p.Prime]
theorem norm_mul (f g : PadicSeq p) : (f * g).norm = f.norm * g.norm := by
classical
exact if hf : f ≈ 0 then by
have hg : f * g ≈ 0 := mul_equiv_zero' _ hf
simp only [hf, hg, norm, dif_pos, zero_mul]
else
if hg : g ≈ 0 then by
have hf : f * g ≈ 0 := mul_equiv_zero _ hg
simp only [hf, hg, norm, dif_pos, mul_zero]
else by
unfold norm
split_ifs with hfg
· exact (mul_not_equiv_zero hf hg hfg).elim
-- Porting note: originally `padic_index_simp [hfg, hf, hg]`
rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg]
apply padicNorm.mul
theorem eq_zero_iff_equiv_zero (f : PadicSeq p) : mk f = 0 ↔ f ≈ 0 :=
mk_eq
theorem ne_zero_iff_nequiv_zero (f : PadicSeq p) : mk f ≠ 0 ↔ ¬f ≈ 0 :=
not_iff_not.2 (eq_zero_iff_equiv_zero _)
theorem norm_const (q : ℚ) : norm (const (padicNorm p) q) = padicNorm p q :=
if hq : q = 0 then by
have : const (padicNorm p) q ≈ 0 := by simpa [hq] using Setoid.refl (const (padicNorm p) 0)
subst hq; simp [norm, this]
else by
have : ¬const (padicNorm p) q ≈ 0 := not_equiv_zero_const_of_nonzero hq
simp [norm, this]
theorem norm_values_discrete (a : PadicSeq p) (ha : ¬a ≈ 0) : ∃ z : ℤ, a.norm = (p : ℚ) ^ (-z) := by
let ⟨k, hk, hk'⟩ := norm_eq_norm_app_of_nonzero ha
simpa [hk] using padicNorm.values_discrete hk'
theorem norm_one : norm (1 : PadicSeq p) = 1 := by
have h1 : ¬(1 : PadicSeq p) ≈ 0 := one_not_equiv_zero _
simp [h1, norm, hp.1.one_lt]
private theorem norm_eq_of_equiv_aux {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g)
(h : padicNorm p (f (stationaryPoint hf)) ≠ padicNorm p (g (stationaryPoint hg)))
(hlt : padicNorm p (g (stationaryPoint hg)) < padicNorm p (f (stationaryPoint hf))) :
False := by
have hpn : 0 < padicNorm p (f (stationaryPoint hf)) - padicNorm p (g (stationaryPoint hg)) :=
sub_pos_of_lt hlt
cases' hfg _ hpn with N hN
let i := max N (max (stationaryPoint hf) (stationaryPoint hg))
have hi : N ≤ i := le_max_left _ _
have hN' := hN _ hi
-- Porting note: originally `padic_index_simp [N, hf, hg] at hN' h hlt`
rw [lift_index_left hf N (stationaryPoint hg), lift_index_right hg N (stationaryPoint hf)]
at hN' h hlt
have hpne : padicNorm p (f i) ≠ padicNorm p (-g i) := by rwa [← padicNorm.neg (g i)] at h
rw [CauSeq.sub_apply, sub_eq_add_neg, add_eq_max_of_ne hpne, padicNorm.neg, max_eq_left_of_lt hlt]
at hN'
have : padicNorm p (f i) < padicNorm p (f i) := by
apply lt_of_lt_of_le hN'
apply sub_le_self
apply padicNorm.nonneg
exact lt_irrefl _ this
private theorem norm_eq_of_equiv {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g) :
padicNorm p (f (stationaryPoint hf)) = padicNorm p (g (stationaryPoint hg)) := by
by_contra h
cases'
Decidable.em
(padicNorm p (g (stationaryPoint hg)) < padicNorm p (f (stationaryPoint hf))) with
hlt hnlt
· exact norm_eq_of_equiv_aux hf hg hfg h hlt
· apply norm_eq_of_equiv_aux hg hf (Setoid.symm hfg) (Ne.symm h)
apply lt_of_le_of_ne
· apply le_of_not_gt hnlt
· apply h
theorem norm_equiv {f g : PadicSeq p} (hfg : f ≈ g) : f.norm = g.norm := by
classical
exact if hf : f ≈ 0 then by
have hg : g ≈ 0 := Setoid.trans (Setoid.symm hfg) hf
simp [norm, hf, hg]
else by
have hg : ¬g ≈ 0 := hf ∘ Setoid.trans hfg
unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg
private theorem norm_nonarchimedean_aux {f g : PadicSeq p} (hfg : ¬f + g ≈ 0) (hf : ¬f ≈ 0)
(hg : ¬g ≈ 0) : (f + g).norm ≤ max f.norm g.norm := by
unfold norm; split_ifs
-- Porting note: originally `padic_index_simp [hfg, hf, hg]`
rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg]
apply padicNorm.nonarchimedean
theorem norm_nonarchimedean (f g : PadicSeq p) : (f + g).norm ≤ max f.norm g.norm := by
classical
exact if hfg : f + g ≈ 0 then by
have : 0 ≤ max f.norm g.norm := le_max_of_le_left (norm_nonneg _)
simpa only [hfg, norm]
else
if hf : f ≈ 0 then by
have hfg' : f + g ≈ g := by
change LimZero (f - 0) at hf
show LimZero (f + g - g); · simpa only [sub_zero, add_sub_cancel_right] using hf
have hcfg : (f + g).norm = g.norm := norm_equiv hfg'
have hcl : f.norm = 0 := (norm_zero_iff f).2 hf
have : max f.norm g.norm = g.norm := by rw [hcl]; exact max_eq_right (norm_nonneg _)
rw [this, hcfg]
else
if hg : g ≈ 0 then by
have hfg' : f + g ≈ f := by
change LimZero (g - 0) at hg
show LimZero (f + g - f); · simpa only [add_sub_cancel_left, sub_zero] using hg
have hcfg : (f + g).norm = f.norm := norm_equiv hfg'
have hcl : g.norm = 0 := (norm_zero_iff g).2 hg
have : max f.norm g.norm = f.norm := by rw [hcl]; exact max_eq_left (norm_nonneg _)
rw [this, hcfg]
else norm_nonarchimedean_aux hfg hf hg
theorem norm_eq {f g : PadicSeq p} (h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) :
f.norm = g.norm := by
classical
exact if hf : f ≈ 0 then by
have hg : g ≈ 0 := equiv_zero_of_val_eq_of_equiv_zero h hf
simp only [hf, hg, norm, dif_pos]
else by
have hg : ¬g ≈ 0 := fun hg ↦
hf <| equiv_zero_of_val_eq_of_equiv_zero (by simp only [h, forall_const, eq_self_iff_true]) hg
simp only [hg, hf, norm, dif_neg, not_false_iff]
let i := max (stationaryPoint hf) (stationaryPoint hg)
have hpf : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f i) := by
apply stationaryPoint_spec
· apply le_max_left
· exact le_rfl
have hpg : padicNorm p (g (stationaryPoint hg)) = padicNorm p (g i) := by
apply stationaryPoint_spec
· apply le_max_right
· exact le_rfl
rw [hpf, hpg, h]
theorem norm_neg (a : PadicSeq p) : (-a).norm = a.norm :=
norm_eq <| by simp
theorem norm_eq_of_add_equiv_zero {f g : PadicSeq p} (h : f + g ≈ 0) : f.norm = g.norm := by
have : LimZero (f + g - 0) := h
have : f ≈ -g := show LimZero (f - -g) by simpa only [sub_zero, sub_neg_eq_add]
have : f.norm = (-g).norm := norm_equiv this
simpa only [norm_neg] using this
theorem add_eq_max_of_ne {f g : PadicSeq p} (hfgne : f.norm ≠ g.norm) :
(f + g).norm = max f.norm g.norm := by
classical
have hfg : ¬f + g ≈ 0 := mt norm_eq_of_add_equiv_zero hfgne
exact if hf : f ≈ 0 then by
have : LimZero (f - 0) := hf
have : f + g ≈ g := show LimZero (f + g - g) by simpa only [sub_zero, add_sub_cancel_right]
have h1 : (f + g).norm = g.norm := norm_equiv this
have h2 : f.norm = 0 := (norm_zero_iff _).2 hf
rw [h1, h2, max_eq_right (norm_nonneg _)]
else
if hg : g ≈ 0 then by
have : LimZero (g - 0) := hg
have : f + g ≈ f := show LimZero (f + g - f) by simpa only [add_sub_cancel_left, sub_zero]
have h1 : (f + g).norm = f.norm := norm_equiv this
have h2 : g.norm = 0 := (norm_zero_iff _).2 hg
rw [h1, h2, max_eq_left (norm_nonneg _)]
else by
unfold norm at hfgne ⊢; split_ifs at hfgne ⊢
-- Porting note: originally `padic_index_simp [hfg, hf, hg] at hfgne ⊢`
rw [lift_index_left hf, lift_index_right hg] at hfgne
· rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg]
exact padicNorm.add_eq_max_of_ne hfgne
end Embedding
end PadicSeq
/-- The `p`-adic numbers `ℚ_[p]` are the Cauchy completion of `ℚ` with respect to the `p`-adic norm.
-/
def Padic (p : ℕ) [Fact p.Prime] :=
CauSeq.Completion.Cauchy (padicNorm p)
/-- notation for p-padic rationals -/
notation "ℚ_[" p "]" => Padic p
namespace Padic
section Completion
variable {p : ℕ} [Fact p.Prime]
instance field : Field ℚ_[p] :=
Cauchy.field
instance : Inhabited ℚ_[p] :=
⟨0⟩
-- short circuits
instance : CommRing ℚ_[p] :=
Cauchy.commRing
instance : Ring ℚ_[p] :=
Cauchy.ring
instance : Zero ℚ_[p] := by infer_instance
instance : One ℚ_[p] := by infer_instance
instance : Add ℚ_[p] := by infer_instance
instance : Mul ℚ_[p] := by infer_instance
instance : Sub ℚ_[p] := by infer_instance
instance : Neg ℚ_[p] := by infer_instance
instance : Div ℚ_[p] := by infer_instance
instance : AddCommGroup ℚ_[p] := by infer_instance
/-- Builds the equivalence class of a Cauchy sequence of rationals. -/
def mk : PadicSeq p → ℚ_[p] :=
Quotient.mk'
variable (p)
theorem zero_def : (0 : ℚ_[p]) = ⟦0⟧ := rfl
theorem mk_eq {f g : PadicSeq p} : mk f = mk g ↔ f ≈ g :=
Quotient.eq'
theorem const_equiv {q r : ℚ} : const (padicNorm p) q ≈ const (padicNorm p) r ↔ q = r :=
⟨fun heq ↦ eq_of_sub_eq_zero <| const_limZero.1 heq, fun heq ↦ by
rw [heq]⟩
@[norm_cast]
theorem coe_inj {q r : ℚ} : (↑q : ℚ_[p]) = ↑r ↔ q = r :=
⟨(const_equiv p).1 ∘ Quotient.eq'.1, fun h ↦ by rw [h]⟩
instance : CharZero ℚ_[p] :=
⟨fun m n ↦ by
rw [← Rat.cast_natCast]
norm_cast
exact id⟩
@[norm_cast]
theorem coe_add : ∀ {x y : ℚ}, (↑(x + y) : ℚ_[p]) = ↑x + ↑y :=
Rat.cast_add _ _
@[norm_cast]
theorem coe_neg : ∀ {x : ℚ}, (↑(-x) : ℚ_[p]) = -↑x :=
Rat.cast_neg _
@[norm_cast]
theorem coe_mul : ∀ {x y : ℚ}, (↑(x * y) : ℚ_[p]) = ↑x * ↑y :=
Rat.cast_mul _ _
@[norm_cast]
theorem coe_sub : ∀ {x y : ℚ}, (↑(x - y) : ℚ_[p]) = ↑x - ↑y :=
Rat.cast_sub _ _
@[norm_cast]
theorem coe_div : ∀ {x y : ℚ}, (↑(x / y) : ℚ_[p]) = ↑x / ↑y :=
Rat.cast_div _ _
@[norm_cast]
theorem coe_one : (↑(1 : ℚ) : ℚ_[p]) = 1 := rfl
@[norm_cast]
theorem coe_zero : (↑(0 : ℚ) : ℚ_[p]) = 0 := rfl
end Completion
end Padic
/-- The rational-valued `p`-adic norm on `ℚ_[p]` is lifted from the norm on Cauchy sequences. The
canonical form of this function is the normed space instance, with notation `‖ ‖`. -/
def padicNormE {p : ℕ} [hp : Fact p.Prime] : AbsoluteValue ℚ_[p] ℚ where
toFun := Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _
map_mul' q r := Quotient.inductionOn₂ q r <| PadicSeq.norm_mul
nonneg' q := Quotient.inductionOn q <| PadicSeq.norm_nonneg
eq_zero' q := Quotient.inductionOn q fun r ↦ by
rw [Padic.zero_def, Quotient.eq]
exact PadicSeq.norm_zero_iff r
add_le' q r := by
trans
max ((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) q)
((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) r)
· exact Quotient.inductionOn₂ q r <| PadicSeq.norm_nonarchimedean
refine max_le_add_of_nonneg (Quotient.inductionOn q <| PadicSeq.norm_nonneg) ?_
exact Quotient.inductionOn r <| PadicSeq.norm_nonneg
namespace padicNormE
section Embedding
open PadicSeq
variable {p : ℕ} [Fact p.Prime]
-- Porting note: Expanded `⟦f⟧` to `Padic.mk f`
theorem defn (f : PadicSeq p) {ε : ℚ} (hε : 0 < ε) :
∃ N, ∀ i ≥ N, padicNormE (Padic.mk f - f i : ℚ_[p]) < ε := by
dsimp [padicNormE]
-- `change ∃ N, ∀ i ≥ N, (f - const _ (f i)).norm < ε` also works, but is very slow
suffices hyp : ∃ N, ∀ i ≥ N, (f - const _ (f i)).norm < ε by peel hyp with N; use N
by_contra! h
cases' cauchy₂ f hε with N hN
rcases h N with ⟨i, hi, hge⟩
have hne : ¬f - const (padicNorm p) (f i) ≈ 0 := fun h ↦ by
rw [PadicSeq.norm, dif_pos h] at hge
exact not_lt_of_ge hge hε
unfold PadicSeq.norm at hge; split_ifs at hge
apply not_le_of_gt _ hge
cases' _root_.em (N ≤ stationaryPoint hne) with hgen hngen
· apply hN _ hgen _ hi
· have := stationaryPoint_spec hne le_rfl (le_of_not_le hngen)
rw [← this]
exact hN _ le_rfl _ hi
/-- Theorems about `padicNormE` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`‖ ‖`). -/
theorem nonarchimedean' (q r : ℚ_[p]) :
padicNormE (q + r : ℚ_[p]) ≤ max (padicNormE q) (padicNormE r) :=
Quotient.inductionOn₂ q r <| norm_nonarchimedean
/-- Theorems about `padicNormE` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`‖ ‖`). -/
theorem add_eq_max_of_ne' {q r : ℚ_[p]} :
padicNormE q ≠ padicNormE r → padicNormE (q + r : ℚ_[p]) = max (padicNormE q) (padicNormE r) :=
Quotient.inductionOn₂ q r fun _ _ ↦ PadicSeq.add_eq_max_of_ne
@[simp]
theorem eq_padic_norm' (q : ℚ) : padicNormE (q : ℚ_[p]) = padicNorm p q :=
norm_const _
protected theorem image' {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, padicNormE q = (p : ℚ) ^ (-n) :=
Quotient.inductionOn q fun f hf ↦
have : ¬f ≈ 0 := (ne_zero_iff_nequiv_zero f).1 hf
norm_values_discrete f this
end Embedding
end padicNormE
namespace Padic
section Complete
open PadicSeq Padic
variable {p : ℕ} [Fact p.Prime] (f : CauSeq _ (@padicNormE p _))
theorem rat_dense' (q : ℚ_[p]) {ε : ℚ} (hε : 0 < ε) : ∃ r : ℚ, padicNormE (q - r : ℚ_[p]) < ε :=
Quotient.inductionOn q fun q' ↦
have : ∃ N, ∀ m ≥ N, ∀ n ≥ N, padicNorm p (q' m - q' n) < ε := cauchy₂ _ hε
let ⟨N, hN⟩ := this
⟨q' N, by
classical
dsimp [padicNormE]
-- Porting note: `change` → `convert_to` (`change` times out!)
-- and add `PadicSeq p` type annotation
convert_to PadicSeq.norm (q' - const _ (q' N) : PadicSeq p) < ε
cases' Decidable.em (q' - const (padicNorm p) (q' N) ≈ 0) with heq hne'
· simpa only [heq, PadicSeq.norm, dif_pos]
· simp only [PadicSeq.norm, dif_neg hne']
change padicNorm p (q' _ - q' _) < ε
cases' Decidable.em (stationaryPoint hne' ≤ N) with hle hle
· -- Porting note: inlined `stationaryPoint_spec` invocation.
have := (stationaryPoint_spec hne' le_rfl hle).symm
simp only [const_apply, sub_apply, padicNorm.zero, sub_self] at this
simpa only [this]
· exact hN _ (lt_of_not_ge hle).le _ le_rfl⟩
private theorem div_nat_pos (n : ℕ) : 0 < 1 / (n + 1 : ℚ) :=
div_pos zero_lt_one (mod_cast succ_pos _)
/-- `limSeq f`, for `f` a Cauchy sequence of `p`-adic numbers, is a sequence of rationals with the
same limit point as `f`. -/
def limSeq : ℕ → ℚ :=
fun n ↦ Classical.choose (rat_dense' (f n) (div_nat_pos n))
theorem exi_rat_seq_conv {ε : ℚ} (hε : 0 < ε) :
∃ N, ∀ i ≥ N, padicNormE (f i - (limSeq f i : ℚ_[p]) : ℚ_[p]) < ε := by
refine (exists_nat_gt (1 / ε)).imp fun N hN i hi ↦ ?_
have h := Classical.choose_spec (rat_dense' (f i) (div_nat_pos i))
refine lt_of_lt_of_le h ((div_le_iff' <| mod_cast succ_pos _).mpr ?_)
rw [right_distrib]
apply le_add_of_le_of_nonneg
· exact (div_le_iff hε).mp (le_trans (le_of_lt hN) (mod_cast hi))
· apply le_of_lt
simpa
theorem exi_rat_seq_conv_cauchy : IsCauSeq (padicNorm p) (limSeq f) := fun ε hε ↦ by
have hε3 : 0 < ε / 3 := div_pos hε (by norm_num)
let ⟨N, hN⟩ := exi_rat_seq_conv f hε3
let ⟨N2, hN2⟩ := f.cauchy₂ hε3
exists max N N2
intro j hj
suffices
padicNormE (limSeq f j - f (max N N2) + (f (max N N2) - limSeq f (max N N2)) : ℚ_[p]) < ε by
ring_nf at this ⊢
rw [← padicNormE.eq_padic_norm']
exact mod_cast this
apply lt_of_le_of_lt
· apply padicNormE.add_le
· rw [← add_thirds ε]
apply _root_.add_lt_add
· suffices padicNormE (limSeq f j - f j + (f j - f (max N N2)) : ℚ_[p]) < ε / 3 + ε / 3 by
simpa only [sub_add_sub_cancel]
apply lt_of_le_of_lt
· apply padicNormE.add_le
· apply _root_.add_lt_add
· rw [padicNormE.map_sub]
apply mod_cast hN j
exact le_of_max_le_left hj
· exact hN2 _ (le_of_max_le_right hj) _ (le_max_right _ _)
· apply mod_cast hN (max N N2)
apply le_max_left
private def lim' : PadicSeq p :=
⟨_, exi_rat_seq_conv_cauchy f⟩
private def lim : ℚ_[p] :=
⟦lim' f⟧
theorem complete' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padicNormE (q - f i : ℚ_[p]) < ε :=
⟨lim f, fun ε hε ↦ by
obtain ⟨N, hN⟩ := exi_rat_seq_conv f (half_pos hε)
obtain ⟨N2, hN2⟩ := padicNormE.defn (lim' f) (half_pos hε)
refine ⟨max N N2, fun i hi ↦ ?_⟩
rw [← sub_add_sub_cancel _ (lim' f i : ℚ_[p]) _]
refine (padicNormE.add_le _ _).trans_lt ?_
rw [← add_halves ε]
apply _root_.add_lt_add
· apply hN2 _ (le_of_max_le_right hi)
· rw [padicNormE.map_sub]
exact hN _ (le_of_max_le_left hi)⟩
theorem complete'' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padicNormE (f i - q : ℚ_[p]) < ε := by
obtain ⟨x, hx⟩ := complete' f
refine ⟨x, fun ε hε => ?_⟩
obtain ⟨N, hN⟩ := hx ε hε
refine ⟨N, fun i hi => ?_⟩
rw [padicNormE.map_sub]
exact hN i hi
end Complete
section NormedSpace
variable (p : ℕ) [Fact p.Prime]
instance : Dist ℚ_[p] :=
⟨fun x y ↦ padicNormE (x - y : ℚ_[p])⟩
instance : IsUltrametricDist ℚ_[p] :=
⟨fun x y z ↦ by simpa [dist] using padicNormE.nonarchimedean' (x - y) (y - z)⟩
instance metricSpace : MetricSpace ℚ_[p] where
dist_self := by simp [dist]
dist := dist
dist_comm x y := by simp [dist, ← padicNormE.map_neg (x - y : ℚ_[p])]
dist_triangle x y z := by
dsimp [dist]
exact mod_cast padicNormE.sub_le x y z
eq_of_dist_eq_zero := by
dsimp [dist]; intro _ _ h
apply eq_of_sub_eq_zero
apply padicNormE.eq_zero.1
exact mod_cast h
instance : Norm ℚ_[p] :=
⟨fun x ↦ padicNormE x⟩
instance normedField : NormedField ℚ_[p] :=
{ Padic.field,
Padic.metricSpace p with
dist_eq := fun _ _ ↦ rfl
norm_mul' := by simp [Norm.norm, map_mul]
norm := norm }
instance isAbsoluteValue : IsAbsoluteValue fun a : ℚ_[p] ↦ ‖a‖ where
abv_nonneg' := norm_nonneg
abv_eq_zero' := norm_eq_zero
abv_add' := norm_add_le
abv_mul' := by simp [Norm.norm, map_mul]
theorem rat_dense (q : ℚ_[p]) {ε : ℝ} (hε : 0 < ε) : ∃ r : ℚ, ‖q - r‖ < ε :=
let ⟨ε', hε'l, hε'r⟩ := exists_rat_btwn hε
let ⟨r, hr⟩ := rat_dense' q (ε := ε') (by simpa using hε'l)
⟨r, lt_trans (by simpa [Norm.norm] using hr) hε'r⟩
end NormedSpace
end Padic
namespace padicNormE
section NormedSpace
variable {p : ℕ} [hp : Fact p.Prime]
-- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned
@[simp (high)]
protected theorem mul (q r : ℚ_[p]) : ‖q * r‖ = ‖q‖ * ‖r‖ := by simp [Norm.norm, map_mul]
protected theorem is_norm (q : ℚ_[p]) : ↑(padicNormE q) = ‖q‖ := rfl
theorem nonarchimedean (q r : ℚ_[p]) : ‖q + r‖ ≤ max ‖q‖ ‖r‖ := by
dsimp [norm]
exact mod_cast nonarchimedean' _ _
theorem add_eq_max_of_ne {q r : ℚ_[p]} (h : ‖q‖ ≠ ‖r‖) : ‖q + r‖ = max ‖q‖ ‖r‖ := by
dsimp [norm] at h ⊢
have : padicNormE q ≠ padicNormE r := mod_cast h
exact mod_cast add_eq_max_of_ne' this
@[simp]
theorem eq_padicNorm (q : ℚ) : ‖(q : ℚ_[p])‖ = padicNorm p q := by
dsimp [norm]
rw [← padicNormE.eq_padic_norm']
@[simp]
theorem norm_p : ‖(p : ℚ_[p])‖ = (p : ℝ)⁻¹ := by
rw [← @Rat.cast_natCast ℝ _ p]
rw [← @Rat.cast_natCast ℚ_[p] _ p]
simp [hp.1.ne_zero, hp.1.ne_one, norm, padicNorm, padicValRat, padicValInt, zpow_neg,
-Rat.cast_natCast]
theorem norm_p_lt_one : ‖(p : ℚ_[p])‖ < 1 := by
rw [norm_p]
apply inv_lt_one
exact mod_cast hp.1.one_lt
-- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned
@[simp (high)]
theorem norm_p_zpow (n : ℤ) : ‖(p : ℚ_[p]) ^ n‖ = (p : ℝ) ^ (-n) := by
rw [norm_zpow, norm_p, zpow_neg, inv_zpow]
-- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned
@[simp (high)]
theorem norm_p_pow (n : ℕ) : ‖(p : ℚ_[p]) ^ n‖ = (p : ℝ) ^ (-n : ℤ) := by
rw [← norm_p_zpow, zpow_natCast]
instance : NontriviallyNormedField ℚ_[p] :=
{ Padic.normedField p with
non_trivial :=
⟨p⁻¹, by
rw [norm_inv, norm_p, inv_inv]
exact mod_cast hp.1.one_lt⟩ }
protected theorem image {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, ‖q‖ = ↑((p : ℚ) ^ (-n)) :=
Quotient.inductionOn q fun f hf ↦
have : ¬f ≈ 0 := (PadicSeq.ne_zero_iff_nequiv_zero f).1 hf
let ⟨n, hn⟩ := PadicSeq.norm_values_discrete f this
⟨n, by rw [← hn]; rfl⟩
protected theorem is_rat (q : ℚ_[p]) : ∃ q' : ℚ, ‖q‖ = q' := by
classical
exact if h : q = 0 then ⟨0, by simp [h]⟩
else
let ⟨n, hn⟩ := padicNormE.image h
⟨_, hn⟩
/-- `ratNorm q`, for a `p`-adic number `q` is the `p`-adic norm of `q`, as rational number.
The lemma `padicNormE.eq_ratNorm` asserts `‖q‖ = ratNorm q`. -/
def ratNorm (q : ℚ_[p]) : ℚ :=
Classical.choose (padicNormE.is_rat q)
theorem eq_ratNorm (q : ℚ_[p]) : ‖q‖ = ratNorm q :=
Classical.choose_spec (padicNormE.is_rat q)
theorem norm_rat_le_one : ∀ {q : ℚ} (_ : ¬p ∣ q.den), ‖(q : ℚ_[p])‖ ≤ 1
| ⟨n, d, hn, hd⟩ => fun hq : ¬p ∣ d ↦
if hnz : n = 0 then by
have : (⟨n, d, hn, hd⟩ : ℚ) = 0 := Rat.zero_iff_num_zero.mpr hnz
norm_num [this]
else by
have hnz' : (⟨n, d, hn, hd⟩ : ℚ) ≠ 0 := mt Rat.zero_iff_num_zero.1 hnz
rw [padicNormE.eq_padicNorm]
norm_cast
-- Porting note: `Nat.cast_zero` instead of another `norm_cast` call
rw [padicNorm.eq_zpow_of_nonzero hnz', padicValRat, neg_sub,
padicValNat.eq_zero_of_not_dvd hq, Nat.cast_zero, zero_sub, zpow_neg, zpow_natCast]
apply inv_le_one
norm_cast
apply one_le_pow
exact hp.1.pos
theorem norm_int_le_one (z : ℤ) : ‖(z : ℚ_[p])‖ ≤ 1 :=
suffices ‖((z : ℚ) : ℚ_[p])‖ ≤ 1 by simpa
norm_rat_le_one <| by simp [hp.1.ne_one]
theorem norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k := by
constructor
· intro h
contrapose! h
apply le_of_eq
rw [eq_comm]
calc
‖(k : ℚ_[p])‖ = ‖((k : ℚ) : ℚ_[p])‖ := by norm_cast
_ = padicNorm p k := padicNormE.eq_padicNorm _
_ = 1 := mod_cast (int_eq_one_iff k).mpr h
· rintro ⟨x, rfl⟩
push_cast
rw [padicNormE.mul]
calc
_ ≤ ‖(p : ℚ_[p])‖ * 1 :=
mul_le_mul le_rfl (by simpa using norm_int_le_one _) (norm_nonneg _) (norm_nonneg _)
_ < 1 := by
rw [mul_one, padicNormE.norm_p]
apply inv_lt_one
exact mod_cast hp.1.one_lt
theorem norm_int_le_pow_iff_dvd (k : ℤ) (n : ℕ) :
‖(k : ℚ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k := by
have : (p : ℝ) ^ (-n : ℤ) = (p : ℚ) ^ (-n : ℤ) := by simp
rw [show (k : ℚ_[p]) = ((k : ℚ) : ℚ_[p]) by norm_cast, eq_padicNorm, this]
norm_cast
rw [← padicNorm.dvd_iff_norm_le]
theorem eq_of_norm_add_lt_right {z1 z2 : ℚ_[p]} (h : ‖z1 + z2‖ < ‖z2‖) : ‖z1‖ = ‖z2‖ :=
_root_.by_contradiction fun hne ↦
not_lt_of_ge (by rw [padicNormE.add_eq_max_of_ne hne]; apply le_max_right) h
theorem eq_of_norm_add_lt_left {z1 z2 : ℚ_[p]} (h : ‖z1 + z2‖ < ‖z1‖) : ‖z1‖ = ‖z2‖ :=
_root_.by_contradiction fun hne ↦
not_lt_of_ge (by rw [padicNormE.add_eq_max_of_ne hne]; apply le_max_left) h
end NormedSpace
end padicNormE
namespace Padic
variable {p : ℕ} [hp : Fact p.Prime]
-- Porting note: remove `set_option eqn_compiler.zeta true`
instance complete : CauSeq.IsComplete ℚ_[p] norm where
isComplete f := by
have cau_seq_norm_e : IsCauSeq padicNormE f := fun ε hε => by
have h := isCauSeq f ε (mod_cast hε)
dsimp [norm] at h
exact mod_cast h
-- Porting note: Padic.complete' works with `f i - q`, but the goal needs `q - f i`,
-- using `rewrite [padicNormE.map_sub]` causes time out, so a separate lemma is created
cases' Padic.complete'' ⟨f, cau_seq_norm_e⟩ with q hq
exists q
intro ε hε
cases' exists_rat_btwn hε with ε' hε'
norm_cast at hε'
cases' hq ε' hε'.1 with N hN
exists N
intro i hi
have h := hN i hi
change norm (f i - q) < ε
refine lt_trans ?_ hε'.2
dsimp [norm]
exact mod_cast h
theorem padicNormE_lim_le {f : CauSeq ℚ_[p] norm} {a : ℝ} (ha : 0 < a) (hf : ∀ i, ‖f i‖ ≤ a) :
‖f.lim‖ ≤ a := by
-- Porting note: `Setoid.symm` cannot work out which `Setoid` to use, so instead swap the order
-- now, I use a rewrite to swap it later
obtain ⟨N, hN⟩ := (CauSeq.equiv_lim f) _ ha
rw [← sub_add_cancel f.lim (f N)]
refine le_trans (padicNormE.nonarchimedean _ _) ?_
rw [norm_sub_rev]
exact max_le (le_of_lt (hN _ le_rfl)) (hf _)
-- Porting note: the following nice `calc` block does not work
-- exact calc
-- ‖f.lim‖ = ‖f.lim - f N + f N‖ := sorry
-- ‖f.lim - f N + f N‖ ≤ max ‖f.lim - f N‖ ‖f N‖ := sorry -- (padicNormE.nonarchimedean _ _)
-- max ‖f.lim - f N‖ ‖f N‖ = max ‖f N - f.lim‖ ‖f N‖ := sorry -- by congr; rw [norm_sub_rev]
-- max ‖f N - f.lim‖ ‖f N‖ ≤ a := sorry -- max_le (le_of_lt (hN _ le_rfl)) (hf _)
open Filter Set
instance : CompleteSpace ℚ_[p] := by
apply complete_of_cauchySeq_tendsto
intro u hu
let c : CauSeq ℚ_[p] norm := ⟨u, Metric.cauchySeq_iff'.mp hu⟩
refine ⟨c.lim, fun s h ↦ ?_⟩
rcases Metric.mem_nhds_iff.1 h with ⟨ε, ε0, hε⟩
have := c.equiv_lim ε ε0
simp only [mem_map, mem_atTop_sets, mem_setOf_eq]
exact this.imp fun N hN n hn ↦ hε (hN n hn)
/-! ### Valuation on `ℚ_[p]` -/
/-- `Padic.valuation` lifts the `p`-adic valuation on rationals to `ℚ_[p]`. -/
def valuation : ℚ_[p] → ℤ :=
Quotient.lift (@PadicSeq.valuation p _) fun f g h ↦ by
by_cases hf : f ≈ 0
· have hg : g ≈ 0 := Setoid.trans (Setoid.symm h) hf
simp [hf, hg, PadicSeq.valuation]
· have hg : ¬g ≈ 0 := fun hg ↦ hf (Setoid.trans h hg)
rw [PadicSeq.val_eq_iff_norm_eq hf hg]
exact PadicSeq.norm_equiv h
@[simp]
theorem valuation_zero : valuation (0 : ℚ_[p]) = 0 :=
dif_pos ((const_equiv p).2 rfl)
@[simp]
theorem valuation_one : valuation (1 : ℚ_[p]) = 0 := by
classical
change dite (CauSeq.const (padicNorm p) 1 ≈ _) _ _ = _
have h : ¬CauSeq.const (padicNorm p) 1 ≈ 0 := by
intro H
erw [const_equiv p] at H
exact one_ne_zero H
rw [dif_neg h]
simp
theorem norm_eq_pow_val {x : ℚ_[p]} : x ≠ 0 → ‖x‖ = (p : ℝ) ^ (-x.valuation) := by
refine Quotient.inductionOn' x fun f hf => ?_
change (PadicSeq.norm _ : ℝ) = (p : ℝ) ^ (-PadicSeq.valuation _)
rw [PadicSeq.norm_eq_pow_val]
· change ↑((p : ℚ) ^ (-PadicSeq.valuation f)) = (p : ℝ) ^ (-PadicSeq.valuation f)
rw [Rat.cast_zpow, Rat.cast_natCast]
· apply CauSeq.not_limZero_of_not_congr_zero
-- Porting note: was `contrapose! hf`
intro hf'
apply hf
apply Quotient.sound
simpa using hf'
@[simp]
theorem valuation_p : valuation (p : ℚ_[p]) = 1 := by
have h : (1 : ℝ) < p := mod_cast (Fact.out : p.Prime).one_lt
refine neg_injective ((zpow_strictMono h).injective <| (norm_eq_pow_val ?_).symm.trans ?_)
· exact mod_cast (Fact.out : p.Prime).ne_zero
· simp
theorem valuation_map_add {x y : ℚ_[p]} (hxy : x + y ≠ 0) :
min (valuation x) (valuation y) ≤ valuation (x + y : ℚ_[p]) := by
by_cases hx : x = 0
· rw [hx, zero_add]
exact min_le_right _ _
· by_cases hy : y = 0
· rw [hy, add_zero]
exact min_le_left _ _
· have h_norm : ‖x + y‖ ≤ max ‖x‖ ‖y‖ := padicNormE.nonarchimedean x y
have hp_one : (1 : ℝ) < p := by
rw [← Nat.cast_one, Nat.cast_lt]
exact Nat.Prime.one_lt hp.elim
rwa [norm_eq_pow_val hx, norm_eq_pow_val hy, norm_eq_pow_val hxy,
zpow_le_max_iff_min_le hp_one] at h_norm
@[simp]
theorem valuation_map_mul {x y : ℚ_[p]} (hx : x ≠ 0) (hy : y ≠ 0) :
valuation (x * y : ℚ_[p]) = valuation x + valuation y := by
have h_norm : ‖x * y‖ = ‖x‖ * ‖y‖ := norm_mul x y
have hp_ne_one : (p : ℝ) ≠ 1 := by
rw [← Nat.cast_one, Ne, Nat.cast_inj]
exact Nat.Prime.ne_one hp.elim
have hp_pos : (0 : ℝ) < p := by
rw [← Nat.cast_zero, Nat.cast_lt]
exact Nat.Prime.pos hp.elim
rw [norm_eq_pow_val hx, norm_eq_pow_val hy, norm_eq_pow_val (mul_ne_zero hx hy), ←
zpow_add₀ (ne_of_gt hp_pos), zpow_inj hp_pos hp_ne_one, ← neg_add, neg_inj] at h_norm
exact h_norm
open Classical in
/-- The additive `p`-adic valuation on `ℚ_[p]`, with values in `WithTop ℤ`. -/
def addValuationDef : ℚ_[p] → WithTop ℤ :=
fun x ↦ if x = 0 then ⊤ else x.valuation
@[simp]
theorem AddValuation.map_zero : addValuationDef (0 : ℚ_[p]) = ⊤ := by
rw [addValuationDef, if_pos (Eq.refl _)]
@[simp]
theorem AddValuation.map_one : addValuationDef (1 : ℚ_[p]) = 0 := by
rw [addValuationDef, if_neg one_ne_zero, valuation_one, WithTop.coe_zero]
theorem AddValuation.map_mul (x y : ℚ_[p]) :
addValuationDef (x * y : ℚ_[p]) = addValuationDef x + addValuationDef y := by
simp only [addValuationDef]
by_cases hx : x = 0
· rw [hx, if_pos (Eq.refl _), zero_mul, if_pos (Eq.refl _), WithTop.top_add]
· by_cases hy : y = 0
· rw [hy, if_pos (Eq.refl _), mul_zero, if_pos (Eq.refl _), WithTop.add_top]
· rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), ← WithTop.coe_add, WithTop.coe_eq_coe,
valuation_map_mul hx hy]
theorem AddValuation.map_add (x y : ℚ_[p]) :
min (addValuationDef x) (addValuationDef y) ≤ addValuationDef (x + y : ℚ_[p]) := by
simp only [addValuationDef]
by_cases hxy : x + y = 0
· rw [hxy, if_pos (Eq.refl _)]
exact le_top
· by_cases hx : x = 0
· rw [hx, if_pos (Eq.refl _), min_eq_right, zero_add]
exact le_top
· by_cases hy : y = 0
· rw [hy, if_pos (Eq.refl _), min_eq_left, add_zero]
exact le_top
· rw [if_neg hx, if_neg hy, if_neg hxy, ← WithTop.coe_min, WithTop.coe_le_coe]
exact valuation_map_add hxy
/-- The additive `p`-adic valuation on `ℚ_[p]`, as an `addValuation`. -/
def addValuation : AddValuation ℚ_[p] (WithTop ℤ) :=
AddValuation.of addValuationDef AddValuation.map_zero AddValuation.map_one AddValuation.map_add
AddValuation.map_mul
@[simp]
theorem addValuation.apply {x : ℚ_[p]} (hx : x ≠ 0) :
Padic.addValuation x = (x.valuation : WithTop ℤ) := by
simp only [Padic.addValuation, AddValuation.of_apply, addValuationDef, if_neg hx]
section NormLEIff
/-! ### Various characterizations of open unit balls -/
theorem norm_le_pow_iff_norm_lt_pow_add_one (x : ℚ_[p]) (n : ℤ) :
‖x‖ ≤ (p : ℝ) ^ n ↔ ‖x‖ < (p : ℝ) ^ (n + 1) := by
have aux : ∀ n : ℤ, 0 < ((p : ℝ) ^ n) := by
apply Nat.zpow_pos_of_pos
exact hp.1.pos
by_cases hx0 : x = 0
· simp [hx0, norm_zero, aux, le_of_lt (aux _)]
rw [norm_eq_pow_val hx0]
have h1p : 1 < (p : ℝ) := mod_cast hp.1.one_lt
have H := zpow_strictMono h1p
rw [H.le_iff_le, H.lt_iff_lt, Int.lt_add_one_iff]
theorem norm_lt_pow_iff_norm_le_pow_sub_one (x : ℚ_[p]) (n : ℤ) :
‖x‖ < (p : ℝ) ^ n ↔ ‖x‖ ≤ (p : ℝ) ^ (n - 1) := by
rw [norm_le_pow_iff_norm_lt_pow_add_one, sub_add_cancel]
theorem norm_le_one_iff_val_nonneg (x : ℚ_[p]) : ‖x‖ ≤ 1 ↔ 0 ≤ x.valuation := by
by_cases hx : x = 0
· simp only [hx, norm_zero, valuation_zero, zero_le_one, le_refl]
· rw [norm_eq_pow_val hx, ← zpow_zero (p : ℝ), zpow_le_iff_le, Right.neg_nonpos_iff]
exact Nat.one_lt_cast.2 (Nat.Prime.one_lt' p).1
end NormLEIff
end Padic
|
NumberTheory\Padics\PadicVal.lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Matthew Robert Ballard
-/
import Mathlib.NumberTheory.Divisors
import Mathlib.Data.Nat.Digits
import Mathlib.Data.Nat.MaxPowDiv
import Mathlib.Data.Nat.Multiplicity
import Mathlib.Tactic.IntervalCases
/-!
# `p`-adic Valuation
This file defines the `p`-adic valuation on `ℕ`, `ℤ`, and `ℚ`.
The `p`-adic valuation on `ℚ` is the difference of the multiplicities of `p` in the numerator and
denominator of `q`. This function obeys the standard properties of a valuation, with the appropriate
assumptions on `p`. The `p`-adic valuations on `ℕ` and `ℤ` agree with that on `ℚ`.
The valuation induces a norm on `ℚ`. This norm is defined in padicNorm.lean.
## Notations
This file uses the local notation `/.` for `Rat.mk`.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking `[Fact p.Prime]` as a type class argument.
## Calculations with `p`-adic valuations
* `padicValNat_factorial`: Legendre's Theorem. The `p`-adic valuation of `n!` is the sum of the
quotients `n / p ^ i`. This sum is expressed over the finset `Ico 1 b` where `b` is any bound
greater than `log p n`. See `Nat.Prime.multiplicity_factorial` for the same result but stated in the
language of prime multiplicity.
* `sub_one_mul_padicValNat_factorial`: Legendre's Theorem. Taking (`p - 1`) times
the `p`-adic valuation of `n!` equals `n` minus the sum of base `p` digits of `n`.
* `padicValNat_choose`: Kummer's Theorem. The `p`-adic valuation of `n.choose k` is the number
of carries when `k` and `n - k` are added in base `p`. This sum is expressed over the finset
`Ico 1 b` where `b` is any bound greater than `log p n`. See `Nat.Prime.multiplicity_choose` for the
same result but stated in the language of prime multiplicity.
* `sub_one_mul_padicValNat_choose_eq_sub_sum_digits`: Kummer's Theorem. Taking (`p - 1`) times the
`p`-adic valuation of the binomial `n` over `k` equals the sum of the digits of `k` plus the sum of
the digits of `n - k` minus the sum of digits of `n`, all base `p`.
## References
* [F. Q. Gouvêa, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, norm, valuation
-/
universe u
open Nat
open Rat
open multiplicity
/-- For `p ≠ 1`, the `p`-adic valuation of a natural `n ≠ 0` is the largest natural number `k` such
that `p^k` divides `n`. If `n = 0` or `p = 1`, then `padicValNat p q` defaults to `0`. -/
def padicValNat (p : ℕ) (n : ℕ) : ℕ :=
if h : p ≠ 1 ∧ 0 < n then (multiplicity p n).get (multiplicity.finite_nat_iff.2 h) else 0
namespace padicValNat
open multiplicity
variable {p : ℕ}
/-- `padicValNat p 0` is `0` for any `p`. -/
@[simp]
protected theorem zero : padicValNat p 0 = 0 := by simp [padicValNat]
/-- `padicValNat p 1` is `0` for any `p`. -/
@[simp]
protected theorem one : padicValNat p 1 = 0 := by
unfold padicValNat
split_ifs
· simp
· rfl
/-- If `p ≠ 0` and `p ≠ 1`, then `padicValNat p p` is `1`. -/
@[simp]
theorem self (hp : 1 < p) : padicValNat p p = 1 := by
have neq_one : ¬p = 1 ↔ True := iff_of_true hp.ne' trivial
have eq_zero_false : p = 0 ↔ False := iff_false_intro (zero_lt_one.trans hp).ne'
simp [padicValNat, neq_one, eq_zero_false]
@[simp]
theorem eq_zero_iff {n : ℕ} : padicValNat p n = 0 ↔ p = 1 ∨ n = 0 ∨ ¬p ∣ n := by
simp only [padicValNat, dite_eq_right_iff, PartENat.get_eq_iff_eq_coe, Nat.cast_zero,
multiplicity_eq_zero, and_imp, pos_iff_ne_zero, Ne, ← or_iff_not_imp_left]
theorem eq_zero_of_not_dvd {n : ℕ} (h : ¬p ∣ n) : padicValNat p n = 0 :=
eq_zero_iff.2 <| Or.inr <| Or.inr h
open Nat.maxPowDiv
theorem maxPowDiv_eq_multiplicity {p n : ℕ} (hp : 1 < p) (hn : 0 < n) :
p.maxPowDiv n = multiplicity p n := by
apply multiplicity.unique <| pow_dvd p n
intro h
apply Nat.not_lt.mpr <| le_of_dvd hp hn h
simp
theorem maxPowDiv_eq_multiplicity_get {p n : ℕ} (hp : 1 < p) (hn : 0 < n) (h : Finite p n) :
p.maxPowDiv n = (multiplicity p n).get h := by
rw [PartENat.get_eq_iff_eq_coe.mpr]
apply maxPowDiv_eq_multiplicity hp hn|>.symm
/-- Allows for more efficient code for `padicValNat` -/
@[csimp]
theorem padicValNat_eq_maxPowDiv : @padicValNat = @maxPowDiv := by
ext p n
by_cases h : 1 < p ∧ 0 < n
· dsimp [padicValNat]
rw [dif_pos ⟨Nat.ne_of_gt h.1,h.2⟩, maxPowDiv_eq_multiplicity_get h.1 h.2]
· simp only [not_and_or,not_gt_eq,Nat.le_zero] at h
apply h.elim
· intro h
interval_cases p
· simp [Classical.em]
· dsimp [padicValNat, maxPowDiv]
rw [go, if_neg]; simp
· intro h
simp [h]
end padicValNat
/-- For `p ≠ 1`, the `p`-adic valuation of an integer `z ≠ 0` is the largest natural number `k` such
that `p^k` divides `z`. If `x = 0` or `p = 1`, then `padicValInt p q` defaults to `0`. -/
def padicValInt (p : ℕ) (z : ℤ) : ℕ :=
padicValNat p z.natAbs
namespace padicValInt
open multiplicity
variable {p : ℕ}
theorem of_ne_one_ne_zero {z : ℤ} (hp : p ≠ 1) (hz : z ≠ 0) :
padicValInt p z =
(multiplicity (p : ℤ) z).get
(by
apply multiplicity.finite_int_iff.2
simp [hp, hz]) := by
rw [padicValInt, padicValNat, dif_pos (And.intro hp (Int.natAbs_pos.mpr hz))]
simp only [multiplicity.Int.natAbs p z]
/-- `padicValInt p 0` is `0` for any `p`. -/
@[simp]
protected theorem zero : padicValInt p 0 = 0 := by simp [padicValInt]
/-- `padicValInt p 1` is `0` for any `p`. -/
@[simp]
protected theorem one : padicValInt p 1 = 0 := by simp [padicValInt]
/-- The `p`-adic value of a natural is its `p`-adic value as an integer. -/
@[simp]
theorem of_nat {n : ℕ} : padicValInt p n = padicValNat p n := by simp [padicValInt]
/-- If `p ≠ 0` and `p ≠ 1`, then `padicValInt p p` is `1`. -/
theorem self (hp : 1 < p) : padicValInt p p = 1 := by simp [padicValNat.self hp]
theorem eq_zero_of_not_dvd {z : ℤ} (h : ¬(p : ℤ) ∣ z) : padicValInt p z = 0 := by
rw [padicValInt, padicValNat]
split_ifs <;> simp [multiplicity.Int.natAbs, multiplicity_eq_zero.2 h]
end padicValInt
/-- `padicValRat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the
valuation of `q.den`. If `q = 0` or `p = 1`, then `padicValRat p q` defaults to `0`. -/
def padicValRat (p : ℕ) (q : ℚ) : ℤ :=
padicValInt p q.num - padicValNat p q.den
lemma padicValRat_def (p : ℕ) (q : ℚ) :
padicValRat p q = padicValInt p q.num - padicValNat p q.den :=
rfl
namespace padicValRat
open multiplicity
variable {p : ℕ}
/-- `padicValRat p q` is symmetric in `q`. -/
@[simp]
protected theorem neg (q : ℚ) : padicValRat p (-q) = padicValRat p q := by
simp [padicValRat, padicValInt]
/-- `padicValRat p 0` is `0` for any `p`. -/
@[simp]
protected theorem zero : padicValRat p 0 = 0 := by simp [padicValRat]
/-- `padicValRat p 1` is `0` for any `p`. -/
@[simp]
protected theorem one : padicValRat p 1 = 0 := by simp [padicValRat]
/-- The `p`-adic value of an integer `z ≠ 0` is its `p`-adic_value as a rational. -/
@[simp]
theorem of_int {z : ℤ} : padicValRat p z = padicValInt p z := by simp [padicValRat]
/-- The `p`-adic value of an integer `z ≠ 0` is the multiplicity of `p` in `z`. -/
theorem of_int_multiplicity {z : ℤ} (hp : p ≠ 1) (hz : z ≠ 0) :
padicValRat p (z : ℚ) = (multiplicity (p : ℤ) z).get (finite_int_iff.2 ⟨hp, hz⟩) := by
rw [of_int, padicValInt.of_ne_one_ne_zero hp hz]
theorem multiplicity_sub_multiplicity {q : ℚ} (hp : p ≠ 1) (hq : q ≠ 0) :
padicValRat p q =
(multiplicity (p : ℤ) q.num).get (finite_int_iff.2 ⟨hp, Rat.num_ne_zero.2 hq⟩) -
(multiplicity p q.den).get
(by
rw [← finite_iff_dom, finite_nat_iff]
exact ⟨hp, q.pos⟩) := by
rw [padicValRat, padicValInt.of_ne_one_ne_zero hp, padicValNat, dif_pos]
· exact ⟨hp, q.pos⟩
· exact Rat.num_ne_zero.2 hq
/-- The `p`-adic value of an integer `z ≠ 0` is its `p`-adic value as a rational. -/
@[simp]
theorem of_nat {n : ℕ} : padicValRat p n = padicValNat p n := by simp [padicValRat]
/-- If `p ≠ 0` and `p ≠ 1`, then `padicValRat p p` is `1`. -/
theorem self (hp : 1 < p) : padicValRat p p = 1 := by simp [hp]
end padicValRat
section padicValNat
variable {p : ℕ}
theorem zero_le_padicValRat_of_nat (n : ℕ) : 0 ≤ padicValRat p n := by simp
/-- `padicValRat` coincides with `padicValNat`. -/
@[norm_cast]
theorem padicValRat_of_nat (n : ℕ) : ↑(padicValNat p n) = padicValRat p n := by simp
/-- A simplification of `padicValNat` when one input is prime, by analogy with
`padicValRat_def`. -/
theorem padicValNat_def [hp : Fact p.Prime] {n : ℕ} (hn : 0 < n) :
padicValNat p n = (multiplicity p n).get (multiplicity.finite_nat_iff.2 ⟨hp.out.ne_one, hn⟩) :=
dif_pos ⟨hp.out.ne_one, hn⟩
theorem padicValNat_def' {n : ℕ} (hp : p ≠ 1) (hn : 0 < n) :
↑(padicValNat p n) = multiplicity p n := by simp [padicValNat, hp, hn]
@[simp]
theorem padicValNat_self [Fact p.Prime] : padicValNat p p = 1 := by
rw [padicValNat_def (@Fact.out p.Prime).pos]
simp
theorem one_le_padicValNat_of_dvd {n : ℕ} [hp : Fact p.Prime] (hn : 0 < n) (div : p ∣ n) :
1 ≤ padicValNat p n := by
rwa [← PartENat.coe_le_coe, padicValNat_def' hp.out.ne_one hn, ← pow_dvd_iff_le_multiplicity,
pow_one]
theorem dvd_iff_padicValNat_ne_zero {p n : ℕ} [Fact p.Prime] (hn0 : n ≠ 0) :
p ∣ n ↔ padicValNat p n ≠ 0 :=
⟨fun h => one_le_iff_ne_zero.mp (one_le_padicValNat_of_dvd hn0.bot_lt h), fun h =>
Classical.not_not.1 (mt padicValNat.eq_zero_of_not_dvd h)⟩
open List
theorem le_multiplicity_iff_replicate_subperm_primeFactorsList {a b : ℕ} {n : ℕ} (ha : a.Prime)
(hb : b ≠ 0) :
↑n ≤ multiplicity a b ↔ replicate n a <+~ b.primeFactorsList :=
(replicate_subperm_primeFactorsList_iff ha hb).trans
multiplicity.pow_dvd_iff_le_multiplicity |>.symm
@[deprecated (since := "2024-07-17")]
alias le_multiplicity_iff_replicate_subperm_factors :=
le_multiplicity_iff_replicate_subperm_primeFactorsList
theorem le_padicValNat_iff_replicate_subperm_primeFactorsList {a b : ℕ} {n : ℕ} (ha : a.Prime)
(hb : b ≠ 0) :
n ≤ padicValNat a b ↔ replicate n a <+~ b.primeFactorsList := by
rw [← le_multiplicity_iff_replicate_subperm_primeFactorsList ha hb,
← padicValNat_def' ha.ne_one (Nat.pos_of_ne_zero hb), Nat.cast_le]
@[deprecated (since := "2024-07-17")]
alias le_padicValNat_iff_replicate_subperm_factors :=
le_padicValNat_iff_replicate_subperm_primeFactorsList
end padicValNat
namespace padicValRat
open multiplicity
variable {p : ℕ} [hp : Fact p.Prime]
/-- The multiplicity of `p : ℕ` in `a : ℤ` is finite exactly when `a ≠ 0`. -/
theorem finite_int_prime_iff {a : ℤ} : Finite (p : ℤ) a ↔ a ≠ 0 := by
simp [finite_int_iff, hp.1.ne_one]
/-- A rewrite lemma for `padicValRat p q` when `q` is expressed in terms of `Rat.mk`. -/
protected theorem defn (p : ℕ) [hp : Fact p.Prime] {q : ℚ} {n d : ℤ} (hqz : q ≠ 0)
(qdf : q = n /. d) :
padicValRat p q =
(multiplicity (p : ℤ) n).get
(finite_int_iff.2 ⟨hp.1.ne_one, fun hn => by simp_all⟩) -
(multiplicity (p : ℤ) d).get
(finite_int_iff.2 ⟨hp.1.ne_one, fun hd => by simp_all⟩) := by
have hd : d ≠ 0 := Rat.mk_denom_ne_zero_of_ne_zero hqz qdf
let ⟨c, hc1, hc2⟩ := Rat.num_den_mk hd qdf
rw [padicValRat.multiplicity_sub_multiplicity hp.1.ne_one hqz]
simp only [Nat.isUnit_iff, hc1, hc2]
rw [multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1),
multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1)]
rw [Nat.cast_add, Nat.cast_add]
simp_rw [Int.natCast_multiplicity p q.den]
ring
-- Porting note: was
-- simp only [hc1, hc2, multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1),
-- hp.1.ne_one, hqz, pos_iff_ne_zero, Int.natCast_multiplicity p q.den
/-- A rewrite lemma for `padicValRat p (q * r)` with conditions `q ≠ 0`, `r ≠ 0`. -/
protected theorem mul {q r : ℚ} (hq : q ≠ 0) (hr : r ≠ 0) :
padicValRat p (q * r) = padicValRat p q + padicValRat p r := by
have : q * r = (q.num * r.num) /. (q.den * r.den) := by
rw [Rat.mul_eq_mkRat, Rat.mkRat_eq_divInt, Nat.cast_mul]
have hq' : q.num /. q.den ≠ 0 := by rwa [Rat.num_divInt_den]
have hr' : r.num /. r.den ≠ 0 := by rwa [Rat.num_divInt_den]
have hp' : Prime (p : ℤ) := Nat.prime_iff_prime_int.1 hp.1
rw [padicValRat.defn p (mul_ne_zero hq hr) this]
conv_rhs =>
rw [← q.num_divInt_den, padicValRat.defn p hq', ← r.num_divInt_den, padicValRat.defn p hr']
rw [multiplicity.mul' hp', multiplicity.mul' hp', Nat.cast_add, Nat.cast_add]
ring
-- Porting note: was
-- simp [add_comm, add_left_comm, sub_eq_add_neg]
/-- A rewrite lemma for `padicValRat p (q^k)` with condition `q ≠ 0`. -/
protected theorem pow {q : ℚ} (hq : q ≠ 0) {k : ℕ} :
padicValRat p (q ^ k) = k * padicValRat p q := by
induction k <;>
simp [*, padicValRat.mul hq (pow_ne_zero _ hq), _root_.pow_succ', add_mul, add_comm]
/-- A rewrite lemma for `padicValRat p (q⁻¹)` with condition `q ≠ 0`. -/
protected theorem inv (q : ℚ) : padicValRat p q⁻¹ = -padicValRat p q := by
by_cases hq : q = 0
· simp [hq]
· rw [eq_neg_iff_add_eq_zero, ← padicValRat.mul (inv_ne_zero hq) hq, inv_mul_cancel hq,
padicValRat.one]
/-- A rewrite lemma for `padicValRat p (q / r)` with conditions `q ≠ 0`, `r ≠ 0`. -/
protected theorem div {q r : ℚ} (hq : q ≠ 0) (hr : r ≠ 0) :
padicValRat p (q / r) = padicValRat p q - padicValRat p r := by
rw [div_eq_mul_inv, padicValRat.mul hq (inv_ne_zero hr), padicValRat.inv r, sub_eq_add_neg]
/-- A condition for `padicValRat p (n₁ / d₁) ≤ padicValRat p (n₂ / d₂)`, in terms of
divisibility by `p^n`. -/
theorem padicValRat_le_padicValRat_iff {n₁ n₂ d₁ d₂ : ℤ} (hn₁ : n₁ ≠ 0) (hn₂ : n₂ ≠ 0)
(hd₁ : d₁ ≠ 0) (hd₂ : d₂ ≠ 0) :
padicValRat p (n₁ /. d₁) ≤ padicValRat p (n₂ /. d₂) ↔
∀ n : ℕ, (p : ℤ) ^ n ∣ n₁ * d₂ → (p : ℤ) ^ n ∣ n₂ * d₁ := by
have hf1 : Finite (p : ℤ) (n₁ * d₂) := finite_int_prime_iff.2 (mul_ne_zero hn₁ hd₂)
have hf2 : Finite (p : ℤ) (n₂ * d₁) := finite_int_prime_iff.2 (mul_ne_zero hn₂ hd₁)
conv =>
lhs
rw [padicValRat.defn p (Rat.divInt_ne_zero_of_ne_zero hn₁ hd₁) rfl,
padicValRat.defn p (Rat.divInt_ne_zero_of_ne_zero hn₂ hd₂) rfl, sub_le_iff_le_add', ←
add_sub_assoc, _root_.le_sub_iff_add_le]
norm_cast
rw [← multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1) hf1, add_comm, ←
multiplicity.mul' (Nat.prime_iff_prime_int.1 hp.1) hf2, PartENat.get_le_get,
multiplicity_le_multiplicity_iff]
/-- Sufficient conditions to show that the `p`-adic valuation of `q` is less than or equal to the
`p`-adic valuation of `q + r`. -/
theorem le_padicValRat_add_of_le {q r : ℚ} (hqr : q + r ≠ 0)
(h : padicValRat p q ≤ padicValRat p r) : padicValRat p q ≤ padicValRat p (q + r) :=
if hq : q = 0 then by simpa [hq] using h
else
if hr : r = 0 then by simp [hr]
else by
have hqn : q.num ≠ 0 := Rat.num_ne_zero.2 hq
have hqd : (q.den : ℤ) ≠ 0 := mod_cast Rat.den_nz _
have hrn : r.num ≠ 0 := Rat.num_ne_zero.2 hr
have hrd : (r.den : ℤ) ≠ 0 := mod_cast Rat.den_nz _
have hqreq : q + r = (q.num * r.den + q.den * r.num) /. (q.den * r.den) := Rat.add_num_den _ _
have hqrd : q.num * r.den + q.den * r.num ≠ 0 := Rat.mk_num_ne_zero_of_ne_zero hqr hqreq
conv_lhs => rw [← q.num_divInt_den]
rw [hqreq, padicValRat_le_padicValRat_iff hqn hqrd hqd (mul_ne_zero hqd hrd), ←
multiplicity_le_multiplicity_iff, mul_left_comm,
multiplicity.mul (Nat.prime_iff_prime_int.1 hp.1), add_mul]
rw [← q.num_divInt_den, ← r.num_divInt_den, padicValRat_le_padicValRat_iff hqn hrn hqd hrd, ←
multiplicity_le_multiplicity_iff] at h
calc
_ ≤
min (multiplicity (↑p) (q.num * r.den * q.den))
(multiplicity (↑p) (↑q.den * r.num * ↑q.den)) :=
le_min
(by rw [@multiplicity.mul _ _ _ _ (_ * _) _ (Nat.prime_iff_prime_int.1 hp.1), add_comm])
(by
rw [mul_assoc,
@multiplicity.mul _ _ _ _ (q.den : ℤ) (_ * _)
(Nat.prime_iff_prime_int.1 hp.1)]
exact add_le_add_left h _)
_ ≤ _ := min_le_multiplicity_add
/-- The minimum of the valuations of `q` and `r` is at most the valuation of `q + r`. -/
theorem min_le_padicValRat_add {q r : ℚ} (hqr : q + r ≠ 0) :
min (padicValRat p q) (padicValRat p r) ≤ padicValRat p (q + r) :=
(le_total (padicValRat p q) (padicValRat p r)).elim
(fun h => by rw [min_eq_left h]; exact le_padicValRat_add_of_le hqr h)
(fun h => by rw [min_eq_right h, add_comm]; exact le_padicValRat_add_of_le (by rwa [add_comm]) h)
/-- Ultrametric property of a p-adic valuation. -/
lemma add_eq_min {q r : ℚ} (hqr : q + r ≠ 0) (hq : q ≠ 0) (hr : r ≠ 0)
(hval : padicValRat p q ≠ padicValRat p r) :
padicValRat p (q + r) = min (padicValRat p q) (padicValRat p r) := by
have h1 := min_le_padicValRat_add (p := p) hqr
have h2 := min_le_padicValRat_add (p := p) (ne_of_eq_of_ne (add_neg_cancel_right q r) hq)
have h3 := min_le_padicValRat_add (p := p) (ne_of_eq_of_ne (add_neg_cancel_right r q) hr)
rw [add_neg_cancel_right, padicValRat.neg] at h2 h3
rw [add_comm] at h3
refine le_antisymm (le_min ?_ ?_) h1
· contrapose! h2
rw [min_eq_right h2.le] at h3
exact lt_min h2 (lt_of_le_of_ne h3 hval)
· contrapose! h3
rw [min_eq_right h3.le] at h2
exact lt_min h3 (lt_of_le_of_ne h2 hval.symm)
lemma add_eq_of_lt {q r : ℚ} (hqr : q + r ≠ 0)
(hq : q ≠ 0) (hr : r ≠ 0) (hval : padicValRat p q < padicValRat p r) :
padicValRat p (q + r) = padicValRat p q := by
rw [add_eq_min hqr hq hr (ne_of_lt hval), min_eq_left (le_of_lt hval)]
lemma lt_add_of_lt {q r₁ r₂ : ℚ} (hqr : r₁ + r₂ ≠ 0)
(hval₁ : padicValRat p q < padicValRat p r₁) (hval₂ : padicValRat p q < padicValRat p r₂) :
padicValRat p q < padicValRat p (r₁ + r₂) :=
lt_of_lt_of_le (lt_min hval₁ hval₂) (padicValRat.min_le_padicValRat_add hqr)
@[simp]
lemma self_pow_inv (r : ℕ) : padicValRat p ((p : ℚ) ^ r)⁻¹ = -r := by
rw [padicValRat.inv, neg_inj, padicValRat.pow (Nat.cast_ne_zero.mpr hp.elim.ne_zero),
padicValRat.self hp.elim.one_lt, mul_one]
/-- A finite sum of rationals with positive `p`-adic valuation has positive `p`-adic valuation
(if the sum is non-zero). -/
theorem sum_pos_of_pos {n : ℕ} {F : ℕ → ℚ} (hF : ∀ i, i < n → 0 < padicValRat p (F i))
(hn0 : ∑ i ∈ Finset.range n, F i ≠ 0) : 0 < padicValRat p (∑ i ∈ Finset.range n, F i) := by
induction' n with d hd
· exact False.elim (hn0 rfl)
· rw [Finset.sum_range_succ] at hn0 ⊢
by_cases h : ∑ x ∈ Finset.range d, F x = 0
· rw [h, zero_add]
exact hF d (lt_add_one _)
· refine lt_of_lt_of_le ?_ (min_le_padicValRat_add hn0)
refine lt_min (hd (fun i hi => ?_) h) (hF d (lt_add_one _))
exact hF _ (lt_trans hi (lt_add_one _))
/-- If the p-adic valuation of a finite set of positive rationals is greater than a given rational
number, then the p-adic valuation of their sum is also greater than the same rational number. -/
theorem lt_sum_of_lt {p j : ℕ} [hp : Fact (Nat.Prime p)] {F : ℕ → ℚ} {S : Finset ℕ}
(hS : S.Nonempty) (hF : ∀ i, i ∈ S → padicValRat p (F j) < padicValRat p (F i))
(hn1 : ∀ i : ℕ, 0 < F i) : padicValRat p (F j) < padicValRat p (∑ i ∈ S, F i) := by
induction' hS using Finset.Nonempty.cons_induction with k s S' Hnot Hne Hind
· rw [Finset.sum_singleton]
exact hF k (by simp)
· rw [Finset.cons_eq_insert, Finset.sum_insert Hnot]
exact padicValRat.lt_add_of_lt
(ne_of_gt (add_pos (hn1 s) (Finset.sum_pos (fun i _ => hn1 i) Hne)))
(hF _ (by simp [Finset.mem_insert, true_or]))
(Hind (fun i hi => hF _ (by rw [Finset.cons_eq_insert,Finset.mem_insert]; exact Or.inr hi)))
end padicValRat
namespace padicValNat
variable {p a b : ℕ} [hp : Fact p.Prime]
/-- A rewrite lemma for `padicValNat p (a * b)` with conditions `a ≠ 0`, `b ≠ 0`. -/
protected theorem mul : a ≠ 0 → b ≠ 0 → padicValNat p (a * b) = padicValNat p a + padicValNat p b :=
mod_cast padicValRat.mul (p := p) (q := a) (r := b)
protected theorem div_of_dvd (h : b ∣ a) :
padicValNat p (a / b) = padicValNat p a - padicValNat p b := by
rcases eq_or_ne a 0 with (rfl | ha)
· simp
obtain ⟨k, rfl⟩ := h
obtain ⟨hb, hk⟩ := mul_ne_zero_iff.mp ha
rw [mul_comm, k.mul_div_cancel hb.bot_lt, padicValNat.mul hk hb, Nat.add_sub_cancel]
/-- Dividing out by a prime factor reduces the `padicValNat` by `1`. -/
protected theorem div (dvd : p ∣ b) : padicValNat p (b / p) = padicValNat p b - 1 := by
rw [padicValNat.div_of_dvd dvd, padicValNat_self]
/-- A version of `padicValRat.pow` for `padicValNat`. -/
protected theorem pow (n : ℕ) (ha : a ≠ 0) : padicValNat p (a ^ n) = n * padicValNat p a := by
simpa only [← @Nat.cast_inj ℤ, push_cast] using padicValRat.pow (Nat.cast_ne_zero.mpr ha)
@[simp]
protected theorem prime_pow (n : ℕ) : padicValNat p (p ^ n) = n := by
rw [padicValNat.pow _ (@Fact.out p.Prime).ne_zero, padicValNat_self, mul_one]
protected theorem div_pow (dvd : p ^ a ∣ b) : padicValNat p (b / p ^ a) = padicValNat p b - a := by
rw [padicValNat.div_of_dvd dvd, padicValNat.prime_pow]
protected theorem div' {m : ℕ} (cpm : Coprime p m) {b : ℕ} (dvd : m ∣ b) :
padicValNat p (b / m) = padicValNat p b := by
rw [padicValNat.div_of_dvd dvd, eq_zero_of_not_dvd (hp.out.coprime_iff_not_dvd.mp cpm),
Nat.sub_zero]
end padicValNat
section padicValNat
variable {p : ℕ}
theorem dvd_of_one_le_padicValNat {n : ℕ} (hp : 1 ≤ padicValNat p n) : p ∣ n := by
by_contra h
rw [padicValNat.eq_zero_of_not_dvd h] at hp
exact lt_irrefl 0 (lt_of_lt_of_le zero_lt_one hp)
theorem pow_padicValNat_dvd {n : ℕ} : p ^ padicValNat p n ∣ n := by
rcases n.eq_zero_or_pos with (rfl | hn); · simp
rcases eq_or_ne p 1 with (rfl | hp); · simp
rw [multiplicity.pow_dvd_iff_le_multiplicity, padicValNat_def'] <;> assumption
theorem padicValNat_dvd_iff_le [hp : Fact p.Prime] {a n : ℕ} (ha : a ≠ 0) :
p ^ n ∣ a ↔ n ≤ padicValNat p a := by
rw [pow_dvd_iff_le_multiplicity, ← padicValNat_def' hp.out.ne_one ha.bot_lt, PartENat.coe_le_coe]
theorem padicValNat_dvd_iff (n : ℕ) [hp : Fact p.Prime] (a : ℕ) :
p ^ n ∣ a ↔ a = 0 ∨ n ≤ padicValNat p a := by
rcases eq_or_ne a 0 with (rfl | ha)
· exact iff_of_true (dvd_zero _) (Or.inl rfl)
· rw [padicValNat_dvd_iff_le ha, or_iff_right ha]
theorem pow_succ_padicValNat_not_dvd {n : ℕ} [hp : Fact p.Prime] (hn : n ≠ 0) :
¬p ^ (padicValNat p n + 1) ∣ n := by
rw [padicValNat_dvd_iff_le hn, not_le]
exact Nat.lt_succ_self _
theorem padicValNat_primes {q : ℕ} [hp : Fact p.Prime] [hq : Fact q.Prime] (neq : p ≠ q) :
padicValNat p q = 0 :=
@padicValNat.eq_zero_of_not_dvd p q <|
(not_congr (Iff.symm (prime_dvd_prime_iff_eq hp.1 hq.1))).mp neq
theorem padicValNat_prime_prime_pow {q : ℕ} [hp : Fact p.Prime] [hq : Fact q.Prime]
(n : ℕ) (neq : p ≠ q) : padicValNat p (q ^ n) = 0 := by
rw [padicValNat.pow _ <| Nat.Prime.ne_zero hq.elim, padicValNat_primes neq, mul_zero]
theorem padicValNat_mul_pow_left {q : ℕ} [hp : Fact p.Prime] [hq : Fact q.Prime]
(n m : ℕ) (neq : p ≠ q) : padicValNat p (p^n * q^m) = n := by
rw [padicValNat.mul (NeZero.ne' (p^n)).symm (NeZero.ne' (q^m)).symm,
padicValNat.prime_pow, padicValNat_prime_prime_pow m neq, add_zero]
theorem padicValNat_mul_pow_right {q : ℕ} [hp : Fact p.Prime] [hq : Fact q.Prime]
(n m : ℕ) (neq : q ≠ p) : padicValNat q (p^n * q^m) = m := by
rw [mul_comm (p^n) (q^m)]
exact padicValNat_mul_pow_left m n neq
/-- The p-adic valuation of `n` is less than or equal to its logarithm w.r.t `p`. -/
lemma padicValNat_le_nat_log (n : ℕ) : padicValNat p n ≤ Nat.log p n := by
rcases n with _ | n
· simp
rcases p with _ | _ | p
· simp
· simp
exact Nat.le_log_of_pow_le p.one_lt_succ_succ (le_of_dvd n.succ_pos pow_padicValNat_dvd)
/-- The p-adic valuation of `n` is equal to the logarithm w.r.t `p` iff
`n` is less than `p` raised to one plus the p-adic valuation of `n`. -/
lemma nat_log_eq_padicValNat_iff {n : ℕ} [hp : Fact (Nat.Prime p)] (hn : 0 < n) :
Nat.log p n = padicValNat p n ↔ n < p ^ (padicValNat p n + 1) := by
rw [Nat.log_eq_iff (Or.inr ⟨(Nat.Prime.one_lt' p).out, by omega⟩), and_iff_right_iff_imp]
exact fun _ => Nat.le_of_dvd hn pow_padicValNat_dvd
lemma Nat.log_ne_padicValNat_succ {n : ℕ} (hn : n ≠ 0) : log 2 n ≠ padicValNat 2 (n + 1) := by
rw [Ne, log_eq_iff (by simp [hn])]
rintro ⟨h1, h2⟩
rw [← Nat.lt_add_one_iff, ← mul_one (2 ^ _)] at h1
rw [← add_one_le_iff, Nat.pow_succ] at h2
refine not_dvd_of_between_consec_multiples h1 (lt_of_le_of_ne' h2 ?_) pow_padicValNat_dvd
-- TODO(kmill): Why is this `p := 2` necessary?
exact pow_succ_padicValNat_not_dvd (p := 2) n.succ_ne_zero ∘ dvd_of_eq
lemma Nat.max_log_padicValNat_succ_eq_log_succ (n : ℕ) :
max (log 2 n) (padicValNat 2 (n + 1)) = log 2 (n + 1) := by
apply le_antisymm (max_le (le_log_of_pow_le one_lt_two (pow_log_le_add_one 2 n))
(padicValNat_le_nat_log (n + 1)))
rw [le_max_iff, or_iff_not_imp_left, not_le]
intro h
replace h := le_antisymm (add_one_le_iff.mpr (lt_pow_of_log_lt one_lt_two h))
(pow_log_le_self 2 n.succ_ne_zero)
rw [h, padicValNat.prime_pow, ← h]
theorem range_pow_padicValNat_subset_divisors {n : ℕ} (hn : n ≠ 0) :
(Finset.range (padicValNat p n + 1)).image (p ^ ·) ⊆ n.divisors := by
intro t ht
simp only [exists_prop, Finset.mem_image, Finset.mem_range] at ht
obtain ⟨k, hk, rfl⟩ := ht
rw [Nat.mem_divisors]
exact ⟨(pow_dvd_pow p <| by omega).trans pow_padicValNat_dvd, hn⟩
theorem range_pow_padicValNat_subset_divisors' {n : ℕ} [hp : Fact p.Prime] :
((Finset.range (padicValNat p n)).image fun t => p ^ (t + 1)) ⊆ n.divisors.erase 1 := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
intro t ht
simp only [exists_prop, Finset.mem_image, Finset.mem_range] at ht
obtain ⟨k, hk, rfl⟩ := ht
rw [Finset.mem_erase, Nat.mem_divisors]
refine ⟨?_, (pow_dvd_pow p <| succ_le_iff.2 hk).trans pow_padicValNat_dvd, hn⟩
exact (Nat.one_lt_pow k.succ_ne_zero hp.out.one_lt).ne'
/-- The `p`-adic valuation of `(p * n)!` is `n` more than that of `n!`. -/
theorem padicValNat_factorial_mul (n : ℕ) [hp : Fact p.Prime] :
padicValNat p (p * n) ! = padicValNat p n ! + n := by
refine PartENat.natCast_inj.mp ?_
rw [padicValNat_def' (Nat.Prime.ne_one hp.out) <| factorial_pos (p * n), Nat.cast_add,
padicValNat_def' (Nat.Prime.ne_one hp.out) <| factorial_pos n]
exact Prime.multiplicity_factorial_mul hp.out
/-- The `p`-adic valuation of `m` equals zero if it is between `p * k` and `p * (k + 1)` for
some `k`. -/
theorem padicValNat_eq_zero_of_mem_Ioo {m k : ℕ}
(hm : m ∈ Set.Ioo (p * k) (p * (k + 1))) : padicValNat p m = 0 :=
padicValNat.eq_zero_of_not_dvd <| not_dvd_of_between_consec_multiples hm.1 hm.2
theorem padicValNat_factorial_mul_add {n : ℕ} (m : ℕ) [hp : Fact p.Prime] (h : n < p) :
padicValNat p (p * m + n) ! = padicValNat p (p * m) ! := by
induction' n with n hn
· rw [add_zero]
· rw [add_succ, factorial_succ,
padicValNat.mul (succ_ne_zero (p * m + n)) <| factorial_ne_zero (p * m + _),
hn <| lt_of_succ_lt h, ← add_succ,
padicValNat_eq_zero_of_mem_Ioo ⟨(Nat.lt_add_of_pos_right <| succ_pos n),
(Nat.mul_add _ _ _▸ Nat.mul_one _ ▸ ((add_lt_add_iff_left (p * m)).mpr h))⟩,
zero_add]
/-- The `p`-adic valuation of `n!` is equal to the `p`-adic valuation of the factorial of the
largest multiple of `p` below `n`, i.e. `(p * ⌊n / p⌋)!`. -/
@[simp] theorem padicValNat_mul_div_factorial (n : ℕ) [hp : Fact p.Prime] :
padicValNat p (p * (n / p))! = padicValNat p n ! := by
nth_rw 2 [← div_add_mod n p]
exact (padicValNat_factorial_mul_add (n / p) <| mod_lt n hp.out.pos).symm
/-- **Legendre's Theorem**
The `p`-adic valuation of `n!` is the sum of the quotients `n / p ^ i`. This sum is expressed
over the finset `Ico 1 b` where `b` is any bound greater than `log p n`. -/
theorem padicValNat_factorial {n b : ℕ} [hp : Fact p.Prime] (hnb : log p n < b) :
padicValNat p (n !) = ∑ i ∈ Finset.Ico 1 b, n / p ^ i :=
PartENat.natCast_inj.mp ((padicValNat_def' (Nat.Prime.ne_one hp.out) <| factorial_pos _) ▸
Prime.multiplicity_factorial hp.out hnb)
/-- **Legendre's Theorem**
Taking (`p - 1`) times the `p`-adic valuation of `n!` equals `n` minus the sum of base `p` digits
of `n`. -/
theorem sub_one_mul_padicValNat_factorial [hp : Fact p.Prime] (n : ℕ) :
(p - 1) * padicValNat p (n !) = n - (p.digits n).sum := by
rw [padicValNat_factorial <| lt_succ_of_lt <| lt.base (log p n)]
nth_rw 2 [← zero_add 1]
rw [Nat.succ_eq_add_one, ← Finset.sum_Ico_add' _ 0 _ 1,
Ico_zero_eq_range, ← sub_one_mul_sum_log_div_pow_eq_sub_sum_digits, Nat.succ_eq_add_one]
/-- **Kummer's Theorem**
The `p`-adic valuation of `n.choose k` is the number of carries when `k` and `n - k` are added
in base `p`. This sum is expressed over the finset `Ico 1 b` where `b` is any bound greater than
`log p n`. -/
theorem padicValNat_choose {n k b : ℕ} [hp : Fact p.Prime] (hkn : k ≤ n) (hnb : log p n < b) :
padicValNat p (choose n k) =
((Finset.Ico 1 b).filter fun i => p ^ i ≤ k % p ^ i + (n - k) % p ^ i).card :=
PartENat.natCast_inj.mp <| (padicValNat_def' (Nat.Prime.ne_one hp.out) <| choose_pos hkn) ▸
Prime.multiplicity_choose hp.out hkn hnb
/-- **Kummer's Theorem**
The `p`-adic valuation of `(n + k).choose k` is the number of carries when `k` and `n` are added
in base `p`. This sum is expressed over the finset `Ico 1 b` where `b` is any bound greater than
`log p (n + k)`. -/
theorem padicValNat_choose' {n k b : ℕ} [hp : Fact p.Prime] (hnb : log p (n + k) < b) :
padicValNat p (choose (n + k) k) =
((Finset.Ico 1 b).filter fun i => p ^ i ≤ k % p ^ i + n % p ^ i).card :=
PartENat.natCast_inj.mp <| (padicValNat_def' (Nat.Prime.ne_one hp.out) <| choose_pos <|
Nat.le_add_left k n)▸ Prime.multiplicity_choose' hp.out hnb
/-- **Kummer's Theorem**
Taking (`p - 1`) times the `p`-adic valuation of the binomial `n + k` over `k` equals the sum of the
digits of `k` plus the sum of the digits of `n` minus the sum of digits of `n + k`, all base `p`.
-/
theorem sub_one_mul_padicValNat_choose_eq_sub_sum_digits' {k n : ℕ} [hp : Fact p.Prime] :
(p - 1) * padicValNat p (choose (n + k) k) =
(p.digits k).sum + (p.digits n).sum - (p.digits (n + k)).sum := by
have h : k ≤ n + k := by exact Nat.le_add_left k n
simp only [Nat.choose_eq_factorial_div_factorial h]
rw [padicValNat.div_of_dvd <| factorial_mul_factorial_dvd_factorial h, Nat.mul_sub_left_distrib,
padicValNat.mul (factorial_ne_zero _) (factorial_ne_zero _), Nat.mul_add]
simp only [sub_one_mul_padicValNat_factorial]
rw [← Nat.sub_add_comm <| digit_sum_le p k, Nat.add_sub_cancel n k, ← Nat.add_sub_assoc <|
digit_sum_le p n, Nat.sub_sub (k + n), ← Nat.sub_right_comm, Nat.sub_sub, sub_add_eq,
add_comm, tsub_tsub_assoc (Nat.le_refl (k + n)) <| (add_comm k n) ▸ (Nat.add_le_add
(digit_sum_le p n) (digit_sum_le p k)), Nat.sub_self (k + n), zero_add, add_comm]
/-- **Kummer's Theorem**
Taking (`p - 1`) times the `p`-adic valuation of the binomial `n` over `k` equals the sum of the
digits of `k` plus the sum of the digits of `n - k` minus the sum of digits of `n`, all base `p`.
-/
theorem sub_one_mul_padicValNat_choose_eq_sub_sum_digits {k n : ℕ} [hp : Fact p.Prime]
(h : k ≤ n) : (p - 1) * padicValNat p (choose n k) =
(p.digits k).sum + (p.digits (n - k)).sum - (p.digits n).sum := by
convert @sub_one_mul_padicValNat_choose_eq_sub_sum_digits' _ _ _ ‹_›
all_goals omega
end padicValNat
section padicValInt
variable {p : ℕ} [hp : Fact p.Prime]
theorem padicValInt_dvd_iff (n : ℕ) (a : ℤ) : (p : ℤ) ^ n ∣ a ↔ a = 0 ∨ n ≤ padicValInt p a := by
rw [padicValInt, ← Int.natAbs_eq_zero, ← padicValNat_dvd_iff, ← Int.natCast_dvd, Int.natCast_pow]
theorem padicValInt_dvd (a : ℤ) : (p : ℤ) ^ padicValInt p a ∣ a := by
rw [padicValInt_dvd_iff]
exact Or.inr le_rfl
theorem padicValInt_self : padicValInt p p = 1 :=
padicValInt.self hp.out.one_lt
theorem padicValInt.mul {a b : ℤ} (ha : a ≠ 0) (hb : b ≠ 0) :
padicValInt p (a * b) = padicValInt p a + padicValInt p b := by
simp_rw [padicValInt]
rw [Int.natAbs_mul, padicValNat.mul] <;> rwa [Int.natAbs_ne_zero]
theorem padicValInt_mul_eq_succ (a : ℤ) (ha : a ≠ 0) :
padicValInt p (a * p) = padicValInt p a + 1 := by
rw [padicValInt.mul ha (Int.natCast_ne_zero.mpr hp.out.ne_zero)]
simp only [eq_self_iff_true, padicValInt.of_nat, padicValNat_self]
end padicValInt
|
NumberTheory\Padics\RingHoms.lean | /-
Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.NumberTheory.Padics.PadicIntegers
import Mathlib.RingTheory.ZMod
/-!
# Relating `ℤ_[p]` to `ZMod (p ^ n)`
In this file we establish connections between the `p`-adic integers $\mathbb{Z}_p$
and the integers modulo powers of `p`, $\mathbb{Z}/p^n\mathbb{Z}$.
## Main declarations
We show that $\mathbb{Z}_p$ has a ring hom to $\mathbb{Z}/p^n\mathbb{Z}$ for each `n`.
The case for `n = 1` is handled separately, since it is used in the general construction
and we may want to use it without the `^1` getting in the way.
* `PadicInt.toZMod`: ring hom to `ZMod p`
* `PadicInt.toZModPow`: ring hom to `ZMod (p^n)`
* `PadicInt.ker_toZMod` / `PadicInt.ker_toZModPow`: the kernels of these maps are the ideals
generated by `p^n`
We also establish the universal property of $\mathbb{Z}_p$ as a projective limit.
Given a family of compatible ring homs $f_k : R \to \mathbb{Z}/p^n\mathbb{Z}$,
there is a unique limit $R \to \mathbb{Z}_p$.
* `PadicInt.lift`: the limit function
* `PadicInt.lift_spec` / `PadicInt.lift_unique`: the universal property
## Implementation notes
The ring hom constructions go through an auxiliary constructor `PadicInt.toZModHom`,
which removes some boilerplate code.
-/
noncomputable section
open scoped Classical
open Nat LocalRing Padic
namespace PadicInt
variable {p : ℕ} [hp_prime : Fact p.Prime]
section RingHoms
/-! ### Ring homomorphisms to `ZMod p` and `ZMod (p ^ n)` -/
variable (p) (r : ℚ)
/-- `modPart p r` is an integer that satisfies
`‖(r - modPart p r : ℚ_[p])‖ < 1` when `‖(r : ℚ_[p])‖ ≤ 1`,
see `PadicInt.norm_sub_modPart`.
It is the unique non-negative integer that is `< p` with this property.
(Note that this definition assumes `r : ℚ`.
See `PadicInt.zmodRepr` for a version that takes values in `ℕ`
and works for arbitrary `x : ℤ_[p]`.) -/
def modPart : ℤ :=
r.num * gcdA r.den p % p
variable {p}
theorem modPart_lt_p : modPart p r < p := by
convert Int.emod_lt _ _
· simp
· exact mod_cast hp_prime.1.ne_zero
theorem modPart_nonneg : 0 ≤ modPart p r :=
Int.emod_nonneg _ <| mod_cast hp_prime.1.ne_zero
theorem isUnit_den (r : ℚ) (h : ‖(r : ℚ_[p])‖ ≤ 1) : IsUnit (r.den : ℤ_[p]) := by
rw [isUnit_iff]
apply le_antisymm (r.den : ℤ_[p]).2
rw [← not_lt, coe_natCast]
intro norm_denom_lt
have hr : ‖(r * r.den : ℚ_[p])‖ = ‖(r.num : ℚ_[p])‖ := by
congr
rw_mod_cast [@Rat.mul_den_eq_num r]
rw [padicNormE.mul] at hr
have key : ‖(r.num : ℚ_[p])‖ < 1 := by
calc
_ = _ := hr.symm
_ < 1 * 1 := mul_lt_mul' h norm_denom_lt (norm_nonneg _) zero_lt_one
_ = 1 := mul_one 1
have : ↑p ∣ r.num ∧ (p : ℤ) ∣ r.den := by
simp only [← norm_int_lt_one_iff_dvd, ← padic_norm_e_of_padicInt]
exact ⟨key, norm_denom_lt⟩
apply hp_prime.1.not_dvd_one
rwa [← r.reduced.gcd_eq_one, Nat.dvd_gcd_iff, ← Int.natCast_dvd, ← Int.natCast_dvd_natCast]
theorem norm_sub_modPart_aux (r : ℚ) (h : ‖(r : ℚ_[p])‖ ≤ 1) :
↑p ∣ r.num - r.num * r.den.gcdA p % p * ↑r.den := by
rw [← ZMod.intCast_zmod_eq_zero_iff_dvd]
simp only [Int.cast_natCast, ZMod.natCast_mod, Int.cast_mul, Int.cast_sub]
have := congr_arg (fun x => x % p : ℤ → ZMod p) (gcd_eq_gcd_ab r.den p)
simp only [Int.cast_natCast, CharP.cast_eq_zero, EuclideanDomain.mod_zero, Int.cast_add,
Int.cast_mul, zero_mul, add_zero] at this
push_cast
rw [mul_right_comm, mul_assoc, ← this]
suffices rdcp : r.den.Coprime p by
rw [rdcp.gcd_eq_one]
simp only [mul_one, cast_one, sub_self]
apply Coprime.symm
apply (coprime_or_dvd_of_prime hp_prime.1 _).resolve_right
rw [← Int.natCast_dvd_natCast, ← norm_int_lt_one_iff_dvd, not_lt]
apply ge_of_eq
rw [← isUnit_iff]
exact isUnit_den r h
theorem norm_sub_modPart (h : ‖(r : ℚ_[p])‖ ≤ 1) : ‖(⟨r, h⟩ - modPart p r : ℤ_[p])‖ < 1 := by
let n := modPart p r
rw [norm_lt_one_iff_dvd, ← (isUnit_den r h).dvd_mul_right]
suffices ↑p ∣ r.num - n * r.den by
convert (Int.castRingHom ℤ_[p]).map_dvd this
simp only [sub_mul, Int.cast_natCast, eq_intCast, Int.cast_mul, sub_left_inj, Int.cast_sub]
apply Subtype.coe_injective
simp only [coe_mul, Subtype.coe_mk, coe_natCast]
rw_mod_cast [@Rat.mul_den_eq_num r]
rfl
exact norm_sub_modPart_aux r h
theorem exists_mem_range_of_norm_rat_le_one (h : ‖(r : ℚ_[p])‖ ≤ 1) :
∃ n : ℤ, 0 ≤ n ∧ n < p ∧ ‖(⟨r, h⟩ - n : ℤ_[p])‖ < 1 :=
⟨modPart p r, modPart_nonneg _, modPart_lt_p _, norm_sub_modPart _ h⟩
theorem zmod_congr_of_sub_mem_span_aux (n : ℕ) (x : ℤ_[p]) (a b : ℤ)
(ha : x - a ∈ (Ideal.span {(p : ℤ_[p]) ^ n}))
(hb : x - b ∈ (Ideal.span {(p : ℤ_[p]) ^ n})) : (a : ZMod (p ^ n)) = b := by
rw [Ideal.mem_span_singleton] at ha hb
rw [← sub_eq_zero, ← Int.cast_sub, ZMod.intCast_zmod_eq_zero_iff_dvd, Int.natCast_pow]
rw [← dvd_neg, neg_sub] at ha
have := dvd_add ha hb
rwa [sub_eq_add_neg, sub_eq_add_neg, add_assoc, neg_add_cancel_left, ← sub_eq_add_neg, ←
Int.cast_sub, pow_p_dvd_int_iff] at this
theorem zmod_congr_of_sub_mem_span (n : ℕ) (x : ℤ_[p]) (a b : ℕ)
(ha : x - a ∈ (Ideal.span {(p : ℤ_[p]) ^ n}))
(hb : x - b ∈ (Ideal.span {(p : ℤ_[p]) ^ n})) : (a : ZMod (p ^ n)) = b := by
simpa using zmod_congr_of_sub_mem_span_aux n x a b ha hb
theorem zmod_congr_of_sub_mem_max_ideal (x : ℤ_[p]) (m n : ℕ) (hm : x - m ∈ maximalIdeal ℤ_[p])
(hn : x - n ∈ maximalIdeal ℤ_[p]) : (m : ZMod p) = n := by
rw [maximalIdeal_eq_span_p] at hm hn
have := zmod_congr_of_sub_mem_span_aux 1 x m n
simp only [pow_one] at this
specialize this hm hn
apply_fun ZMod.castHom (show p ∣ p ^ 1 by rw [pow_one]) (ZMod p) at this
simp only [map_intCast] at this
simpa only [Int.cast_natCast] using this
variable (x : ℤ_[p])
theorem exists_mem_range : ∃ n : ℕ, n < p ∧ x - n ∈ maximalIdeal ℤ_[p] := by
simp only [maximalIdeal_eq_span_p, Ideal.mem_span_singleton, ← norm_lt_one_iff_dvd]
obtain ⟨r, hr⟩ := rat_dense p (x : ℚ_[p]) zero_lt_one
have H : ‖(r : ℚ_[p])‖ ≤ 1 := by
rw [norm_sub_rev] at hr
calc
_ = ‖(r : ℚ_[p]) - x + x‖ := by ring_nf
_ ≤ _ := padicNormE.nonarchimedean _ _
_ ≤ _ := max_le (le_of_lt hr) x.2
obtain ⟨n, hzn, hnp, hn⟩ := exists_mem_range_of_norm_rat_le_one r H
lift n to ℕ using hzn
use n
constructor
· exact mod_cast hnp
simp only [norm_def, coe_sub, Subtype.coe_mk, coe_natCast] at hn ⊢
rw [show (x - n : ℚ_[p]) = x - r + (r - n) by ring]
apply lt_of_le_of_lt (padicNormE.nonarchimedean _ _)
apply max_lt hr
simpa using hn
/-- `zmod_repr x` is the unique natural number smaller than `p`
satisfying `‖(x - zmod_repr x : ℤ_[p])‖ < 1`.
-/
def zmodRepr : ℕ :=
Classical.choose (exists_mem_range x)
theorem zmodRepr_spec : zmodRepr x < p ∧ x - zmodRepr x ∈ maximalIdeal ℤ_[p] :=
Classical.choose_spec (exists_mem_range x)
theorem zmodRepr_lt_p : zmodRepr x < p :=
(zmodRepr_spec _).1
theorem sub_zmodRepr_mem : x - zmodRepr x ∈ maximalIdeal ℤ_[p] :=
(zmodRepr_spec _).2
/-- `toZModHom` is an auxiliary constructor for creating ring homs from `ℤ_[p]` to `ZMod v`.
-/
def toZModHom (v : ℕ) (f : ℤ_[p] → ℕ) (f_spec : ∀ x, x - f x ∈ (Ideal.span {↑v} : Ideal ℤ_[p]))
(f_congr :
∀ (x : ℤ_[p]) (a b : ℕ),
x - a ∈ (Ideal.span {↑v} : Ideal ℤ_[p]) →
x - b ∈ (Ideal.span {↑v} : Ideal ℤ_[p]) → (a : ZMod v) = b) :
ℤ_[p] →+* ZMod v where
toFun x := f x
map_zero' := by
dsimp only
rw [f_congr (0 : ℤ_[p]) _ 0, cast_zero]
· exact f_spec _
· simp only [sub_zero, cast_zero, Submodule.zero_mem]
map_one' := by
dsimp only
rw [f_congr (1 : ℤ_[p]) _ 1, cast_one]
· exact f_spec _
· simp only [sub_self, cast_one, Submodule.zero_mem]
map_add' := by
intro x y
dsimp only
rw [f_congr (x + y) _ (f x + f y), cast_add]
· exact f_spec _
· convert Ideal.add_mem _ (f_spec x) (f_spec y) using 1
rw [cast_add]
ring
map_mul' := by
intro x y
dsimp only
rw [f_congr (x * y) _ (f x * f y), cast_mul]
· exact f_spec _
· let I : Ideal ℤ_[p] := Ideal.span {↑v}
convert I.add_mem (I.mul_mem_left x (f_spec y)) (I.mul_mem_right ↑(f y) (f_spec x)) using 1
rw [cast_mul]
ring
/-- `toZMod` is a ring hom from `ℤ_[p]` to `ZMod p`,
with the equality `toZMod x = (zmodRepr x : ZMod p)`.
-/
def toZMod : ℤ_[p] →+* ZMod p :=
toZModHom p zmodRepr
(by
rw [← maximalIdeal_eq_span_p]
exact sub_zmodRepr_mem)
(by
rw [← maximalIdeal_eq_span_p]
exact zmod_congr_of_sub_mem_max_ideal)
/-- `z - (toZMod z : ℤ_[p])` is contained in the maximal ideal of `ℤ_[p]`, for every `z : ℤ_[p]`.
The coercion from `ZMod p` to `ℤ_[p]` is `ZMod.cast`,
which coerces `ZMod p` into arbitrary rings.
This is unfortunate, but a consequence of the fact that we allow `ZMod p`
to coerce to rings of arbitrary characteristic, instead of only rings of characteristic `p`.
This coercion is only a ring homomorphism if it coerces into a ring whose characteristic divides
`p`. While this is not the case here we can still make use of the coercion.
-/
theorem toZMod_spec : x - (ZMod.cast (toZMod x) : ℤ_[p]) ∈ maximalIdeal ℤ_[p] := by
convert sub_zmodRepr_mem x using 2
dsimp [toZMod, toZModHom]
rcases Nat.exists_eq_add_of_lt hp_prime.1.pos with ⟨p', rfl⟩
change ↑((_ : ZMod (0 + p' + 1)).val) = (_ : ℤ_[0 + p' + 1])
simp only [ZMod.val_natCast, add_zero, add_def, Nat.cast_inj, zero_add]
apply mod_eq_of_lt
simpa only [zero_add] using zmodRepr_lt_p x
theorem ker_toZMod : RingHom.ker (toZMod : ℤ_[p] →+* ZMod p) = maximalIdeal ℤ_[p] := by
ext x
rw [RingHom.mem_ker]
constructor
· intro h
simpa only [h, ZMod.cast_zero, sub_zero] using toZMod_spec x
· intro h
rw [← sub_zero x] at h
dsimp [toZMod, toZModHom]
convert zmod_congr_of_sub_mem_max_ideal x _ 0 _ h
· norm_cast
· apply sub_zmodRepr_mem
/-- `appr n x` gives a value `v : ℕ` such that `x` and `↑v : ℤ_p` are congruent mod `p^n`.
See `appr_spec`. -/
-- Porting note: removing irreducible solves a lot of problems
noncomputable def appr : ℤ_[p] → ℕ → ℕ
| _x, 0 => 0
| x, n + 1 =>
let y := x - appr x n
if hy : y = 0 then appr x n
else
let u := (unitCoeff hy : ℤ_[p])
appr x n + p ^ n * (toZMod ((u * (p : ℤ_[p]) ^ (y.valuation - n).natAbs) : ℤ_[p])).val
theorem appr_lt (x : ℤ_[p]) (n : ℕ) : x.appr n < p ^ n := by
induction' n with n ih generalizing x
· simp only [appr, zero_eq, _root_.pow_zero, zero_lt_one]
simp only [appr, map_natCast, ZMod.natCast_self, RingHom.map_pow, Int.natAbs, RingHom.map_mul]
have hp : p ^ n < p ^ (n + 1) := by apply pow_lt_pow_right hp_prime.1.one_lt (lt_add_one n)
split_ifs with h
· apply lt_trans (ih _) hp
· calc
_ < p ^ n + p ^ n * (p - 1) := ?_
_ = p ^ (n + 1) := ?_
· apply add_lt_add_of_lt_of_le (ih _)
apply Nat.mul_le_mul_left
apply le_pred_of_lt
apply ZMod.val_lt
· rw [mul_tsub, mul_one, ← _root_.pow_succ]
apply add_tsub_cancel_of_le (le_of_lt hp)
theorem appr_mono (x : ℤ_[p]) : Monotone x.appr := by
apply monotone_nat_of_le_succ
intro n
dsimp [appr]
split_ifs; · rfl
apply Nat.le_add_right
theorem dvd_appr_sub_appr (x : ℤ_[p]) (m n : ℕ) (h : m ≤ n) : p ^ m ∣ x.appr n - x.appr m := by
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le h; clear h
induction' k with k ih
· simp only [zero_eq, add_zero, le_refl, tsub_eq_zero_of_le, ne_eq, Nat.isUnit_iff, dvd_zero]
rw [← add_assoc]
dsimp [appr]
split_ifs with h
· exact ih
rw [add_comm, add_tsub_assoc_of_le (appr_mono _ (Nat.le_add_right m k))]
apply dvd_add _ ih
apply dvd_mul_of_dvd_left
apply pow_dvd_pow _ (Nat.le_add_right m k)
theorem appr_spec (n : ℕ) : ∀ x : ℤ_[p], x - appr x n ∈ Ideal.span {(p : ℤ_[p]) ^ n} := by
simp only [Ideal.mem_span_singleton]
induction' n with n ih
· simp only [zero_eq, _root_.pow_zero, isUnit_one, IsUnit.dvd, forall_const]
intro x
dsimp only [appr]
split_ifs with h
· rw [h]
apply dvd_zero
push_cast
rw [sub_add_eq_sub_sub]
obtain ⟨c, hc⟩ := ih x
simp only [map_natCast, ZMod.natCast_self, RingHom.map_pow, RingHom.map_mul, ZMod.natCast_val]
have hc' : c ≠ 0 := by
rintro rfl
simp only [mul_zero] at hc
contradiction
conv_rhs =>
congr
simp only [hc]
rw [show (x - (appr x n : ℤ_[p])).valuation = ((p : ℤ_[p]) ^ n * c).valuation by rw [hc]]
rw [valuation_p_pow_mul _ _ hc', add_sub_cancel_left, _root_.pow_succ, ← mul_sub]
apply mul_dvd_mul_left
obtain hc0 | hc0 := eq_or_ne c.valuation.natAbs 0
· simp only [hc0, mul_one, _root_.pow_zero]
rw [mul_comm, unitCoeff_spec h] at hc
suffices c = unitCoeff h by
rw [← this, ← Ideal.mem_span_singleton, ← maximalIdeal_eq_span_p]
apply toZMod_spec
obtain ⟨c, rfl⟩ : IsUnit c := by
-- TODO: write a `CanLift` instance for units
rw [Int.natAbs_eq_zero] at hc0
rw [isUnit_iff, norm_eq_pow_val hc', hc0, neg_zero, zpow_zero]
rw [DiscreteValuationRing.unit_mul_pow_congr_unit _ _ _ _ _ hc]
exact irreducible_p
· simp only [zero_pow hc0, sub_zero, ZMod.cast_zero, mul_zero]
rw [unitCoeff_spec hc']
exact (dvd_pow_self (p : ℤ_[p]) hc0).mul_left _
/-- A ring hom from `ℤ_[p]` to `ZMod (p^n)`, with underlying function `PadicInt.appr n`. -/
def toZModPow (n : ℕ) : ℤ_[p] →+* ZMod (p ^ n) :=
toZModHom (p ^ n) (fun x => appr x n)
(by
intros
rw [Nat.cast_pow]
exact appr_spec n _)
(by
intro x a b ha hb
apply zmod_congr_of_sub_mem_span n x a b
· simpa using ha
· simpa using hb)
theorem ker_toZModPow (n : ℕ) :
RingHom.ker (toZModPow n : ℤ_[p] →+* ZMod (p ^ n)) = Ideal.span {(p : ℤ_[p]) ^ n} := by
ext x
rw [RingHom.mem_ker]
constructor
· intro h
suffices x.appr n = 0 by
convert appr_spec n x
simp only [this, sub_zero, cast_zero]
dsimp [toZModPow, toZModHom] at h
rw [ZMod.natCast_zmod_eq_zero_iff_dvd] at h
apply eq_zero_of_dvd_of_lt h (appr_lt _ _)
· intro h
rw [← sub_zero x] at h
dsimp [toZModPow, toZModHom]
rw [zmod_congr_of_sub_mem_span n x _ 0 _ h, cast_zero]
apply appr_spec
-- @[simp] -- Porting note: not in simpNF
theorem zmod_cast_comp_toZModPow (m n : ℕ) (h : m ≤ n) :
(ZMod.castHom (pow_dvd_pow p h) (ZMod (p ^ m))).comp (@toZModPow p _ n) = @toZModPow p _ m := by
apply ZMod.ringHom_eq_of_ker_eq
ext x
rw [RingHom.mem_ker, RingHom.mem_ker]
simp only [Function.comp_apply, ZMod.castHom_apply, RingHom.coe_comp]
simp only [toZModPow, toZModHom, RingHom.coe_mk]
dsimp
rw [ZMod.cast_natCast (pow_dvd_pow p h),
zmod_congr_of_sub_mem_span m (x.appr n) (x.appr n) (x.appr m)]
· rw [sub_self]
apply Ideal.zero_mem _
· rw [Ideal.mem_span_singleton]
rcases dvd_appr_sub_appr x m n h with ⟨c, hc⟩
use c
rw [← Nat.cast_sub (appr_mono _ h), hc, Nat.cast_mul, Nat.cast_pow]
@[simp]
theorem cast_toZModPow (m n : ℕ) (h : m ≤ n) (x : ℤ_[p]) :
ZMod.cast (toZModPow n x) = toZModPow m x := by
rw [← zmod_cast_comp_toZModPow _ _ h]
rfl
theorem denseRange_natCast : DenseRange (Nat.cast : ℕ → ℤ_[p]) := by
intro x
rw [Metric.mem_closure_range_iff]
intro ε hε
obtain ⟨n, hn⟩ := exists_pow_neg_lt p hε
use x.appr n
rw [dist_eq_norm]
apply lt_of_le_of_lt _ hn
rw [norm_le_pow_iff_mem_span_pow]
apply appr_spec
@[deprecated (since := "2024-04-17")]
alias denseRange_nat_cast := denseRange_natCast
theorem denseRange_intCast : DenseRange (Int.cast : ℤ → ℤ_[p]) := by
intro x
refine DenseRange.induction_on denseRange_natCast x ?_ ?_
· exact isClosed_closure
· intro a
apply subset_closure
exact Set.mem_range_self _
@[deprecated (since := "2024-04-17")]
alias denseRange_int_cast := denseRange_intCast
end RingHoms
section lift
/-! ### Universal property as projective limit -/
open CauSeq PadicSeq
variable {R : Type*} [NonAssocSemiring R] (f : ∀ k : ℕ, R →+* ZMod (p ^ k))
(f_compat : ∀ (k1 k2) (hk : k1 ≤ k2), (ZMod.castHom (pow_dvd_pow p hk) _).comp (f k2) = f k1)
/-- Given a family of ring homs `f : Π n : ℕ, R →+* ZMod (p ^ n)`,
`nthHom f r` is an integer-valued sequence
whose `n`th value is the unique integer `k` such that `0 ≤ k < p ^ n`
and `f n r = (k : ZMod (p ^ n))`.
-/
def nthHom (r : R) : ℕ → ℤ := fun n => (f n r : ZMod (p ^ n)).val
@[simp]
theorem nthHom_zero : nthHom f 0 = 0 := by
simp (config := { unfoldPartialApp := true }) [nthHom]
rfl
variable {f}
theorem pow_dvd_nthHom_sub (r : R) (i j : ℕ) (h : i ≤ j) :
(p : ℤ) ^ i ∣ nthHom f r j - nthHom f r i := by
specialize f_compat i j h
rw [← Int.natCast_pow, ← ZMod.intCast_zmod_eq_zero_iff_dvd, Int.cast_sub]
dsimp [nthHom]
rw [← f_compat, RingHom.comp_apply]
simp only [ZMod.cast_id, ZMod.castHom_apply, sub_self, ZMod.natCast_val, ZMod.intCast_cast]
theorem isCauSeq_nthHom (r : R) : IsCauSeq (padicNorm p) fun n => nthHom f r n := by
intro ε hε
obtain ⟨k, hk⟩ : ∃ k : ℕ, (p : ℚ) ^ (-((k : ℕ) : ℤ)) < ε := exists_pow_neg_lt_rat p hε
use k
intro j hj
refine lt_of_le_of_lt ?_ hk
-- Need to do beta reduction first, as `norm_cast` doesn't.
-- Added to adapt to leanprover/lean4#2734.
beta_reduce
norm_cast
rw [← padicNorm.dvd_iff_norm_le]
exact mod_cast pow_dvd_nthHom_sub f_compat r k j hj
/-- `nthHomSeq f_compat r` bundles `PadicInt.nthHom f r`
as a Cauchy sequence of rationals with respect to the `p`-adic norm.
The `n`th value of the sequence is `((f n r).val : ℚ)`.
-/
def nthHomSeq (r : R) : PadicSeq p :=
⟨fun n => nthHom f r n, isCauSeq_nthHom f_compat r⟩
-- this lemma ran into issues after changing to `NeZero` and I'm not sure why.
theorem nthHomSeq_one : nthHomSeq f_compat 1 ≈ 1 := by
intro ε hε
change _ < _ at hε
use 1
intro j hj
haveI : Fact (1 < p ^ j) := ⟨Nat.one_lt_pow (by omega) hp_prime.1.one_lt⟩
suffices (ZMod.cast (1 : ZMod (p ^ j)) : ℚ) = 1 by simp [nthHomSeq, nthHom, this, hε]
rw [ZMod.cast_eq_val, ZMod.val_one, Nat.cast_one]
theorem nthHomSeq_add (r s : R) :
nthHomSeq f_compat (r + s) ≈ nthHomSeq f_compat r + nthHomSeq f_compat s := by
intro ε hε
obtain ⟨n, hn⟩ := exists_pow_neg_lt_rat p hε
use n
intro j hj
dsimp [nthHomSeq]
apply lt_of_le_of_lt _ hn
rw [← Int.cast_add, ← Int.cast_sub, ← padicNorm.dvd_iff_norm_le, ←
ZMod.intCast_zmod_eq_zero_iff_dvd]
dsimp [nthHom]
simp only [ZMod.natCast_val, RingHom.map_add, Int.cast_sub, ZMod.intCast_cast, Int.cast_add]
rw [ZMod.cast_add (show p ^ n ∣ p ^ j from pow_dvd_pow _ hj)]
simp only [cast_add, ZMod.natCast_val, Int.cast_add, ZMod.intCast_cast, sub_self]
theorem nthHomSeq_mul (r s : R) :
nthHomSeq f_compat (r * s) ≈ nthHomSeq f_compat r * nthHomSeq f_compat s := by
intro ε hε
obtain ⟨n, hn⟩ := exists_pow_neg_lt_rat p hε
use n
intro j hj
dsimp [nthHomSeq]
apply lt_of_le_of_lt _ hn
rw [← Int.cast_mul, ← Int.cast_sub, ← padicNorm.dvd_iff_norm_le, ←
ZMod.intCast_zmod_eq_zero_iff_dvd]
dsimp [nthHom]
simp only [ZMod.natCast_val, RingHom.map_mul, Int.cast_sub, ZMod.intCast_cast, Int.cast_mul]
rw [ZMod.cast_mul (show p ^ n ∣ p ^ j from pow_dvd_pow _ hj), sub_self]
/--
`limNthHom f_compat r` is the limit of a sequence `f` of compatible ring homs `R →+* ZMod (p^k)`.
This is itself a ring hom: see `PadicInt.lift`.
-/
def limNthHom (r : R) : ℤ_[p] :=
ofIntSeq (nthHom f r) (isCauSeq_nthHom f_compat r)
theorem limNthHom_spec (r : R) :
∀ ε : ℝ, 0 < ε → ∃ N : ℕ, ∀ n ≥ N, ‖limNthHom f_compat r - nthHom f r n‖ < ε := by
intro ε hε
obtain ⟨ε', hε'0, hε'⟩ : ∃ v : ℚ, (0 : ℝ) < v ∧ ↑v < ε := exists_rat_btwn hε
norm_cast at hε'0
obtain ⟨N, hN⟩ := padicNormE.defn (nthHomSeq f_compat r) hε'0
use N
intro n hn
apply _root_.lt_trans _ hε'
change (padicNormE _ : ℝ) < _
norm_cast
exact hN _ hn
theorem limNthHom_zero : limNthHom f_compat 0 = 0 := by simp [limNthHom]; rfl
theorem limNthHom_one : limNthHom f_compat 1 = 1 :=
Subtype.ext <| Quot.sound <| nthHomSeq_one f_compat
theorem limNthHom_add (r s : R) :
limNthHom f_compat (r + s) = limNthHom f_compat r + limNthHom f_compat s :=
Subtype.ext <| Quot.sound <| nthHomSeq_add f_compat _ _
theorem limNthHom_mul (r s : R) :
limNthHom f_compat (r * s) = limNthHom f_compat r * limNthHom f_compat s :=
Subtype.ext <| Quot.sound <| nthHomSeq_mul f_compat _ _
-- TODO: generalize this to arbitrary complete discrete valuation rings
/-- `lift f_compat` is the limit of a sequence `f` of compatible ring homs `R →+* ZMod (p^k)`,
with the equality `lift f_compat r = PadicInt.limNthHom f_compat r`.
-/
def lift : R →+* ℤ_[p] where
toFun := limNthHom f_compat
map_one' := limNthHom_one f_compat
map_mul' := limNthHom_mul f_compat
map_zero' := limNthHom_zero f_compat
map_add' := limNthHom_add f_compat
theorem lift_sub_val_mem_span (r : R) (n : ℕ) :
lift f_compat r - (f n r).val ∈ (Ideal.span {(p : ℤ_[p]) ^ n}) := by
obtain ⟨k, hk⟩ :=
limNthHom_spec f_compat r _
(show (0 : ℝ) < (p : ℝ) ^ (-n : ℤ) from Nat.zpow_pos_of_pos hp_prime.1.pos _)
have := le_of_lt (hk (max n k) (le_max_right _ _))
rw [norm_le_pow_iff_mem_span_pow] at this
dsimp [lift]
rw [sub_eq_sub_add_sub (limNthHom f_compat r) _ ↑(nthHom f r (max n k))]
apply Ideal.add_mem _ _ this
rw [Ideal.mem_span_singleton]
convert
(Int.castRingHom ℤ_[p]).map_dvd (pow_dvd_nthHom_sub f_compat r n (max n k) (le_max_left _ _))
· rw [map_pow]; rfl
· rw [map_sub]; rfl
/-- One part of the universal property of `ℤ_[p]` as a projective limit.
See also `PadicInt.lift_unique`.
-/
theorem lift_spec (n : ℕ) : (toZModPow n).comp (lift f_compat) = f n := by
ext r
rw [RingHom.comp_apply, ← ZMod.natCast_zmod_val (f n r), ← map_natCast <| toZModPow n, ←
sub_eq_zero, ← RingHom.map_sub, ← RingHom.mem_ker, ker_toZModPow]
apply lift_sub_val_mem_span
/-- One part of the universal property of `ℤ_[p]` as a projective limit.
See also `PadicInt.lift_spec`.
-/
theorem lift_unique (g : R →+* ℤ_[p]) (hg : ∀ n, (toZModPow n).comp g = f n) :
lift f_compat = g := by
ext1 r
apply eq_of_forall_dist_le
intro ε hε
obtain ⟨n, hn⟩ := exists_pow_neg_lt p hε
apply le_trans _ (le_of_lt hn)
rw [dist_eq_norm, norm_le_pow_iff_mem_span_pow, ← ker_toZModPow, RingHom.mem_ker,
RingHom.map_sub, ← RingHom.comp_apply, ← RingHom.comp_apply, lift_spec, hg, sub_self]
@[simp]
theorem lift_self (z : ℤ_[p]) : @lift p _ ℤ_[p] _ toZModPow zmod_cast_comp_toZModPow z = z := by
show _ = RingHom.id _ z
rw [@lift_unique p _ ℤ_[p] _ _ zmod_cast_comp_toZModPow (RingHom.id ℤ_[p])]
intro; rw [RingHom.comp_id]
end lift
theorem ext_of_toZModPow {x y : ℤ_[p]} : (∀ n, toZModPow n x = toZModPow n y) ↔ x = y := by
constructor
· intro h
rw [← lift_self x, ← lift_self y]
simp (config := { unfoldPartialApp := true }) [lift, limNthHom, nthHom, h]
· rintro rfl _
rfl
theorem toZModPow_eq_iff_ext {R : Type*} [NonAssocSemiring R] {g g' : R →+* ℤ_[p]} :
(∀ n, (toZModPow n).comp g = (toZModPow n).comp g') ↔ g = g' := by
constructor
· intro hg
ext x : 1
apply ext_of_toZModPow.mp
intro n
show (toZModPow n).comp g x = (toZModPow n).comp g' x
rw [hg n]
· rintro rfl _
rfl
end PadicInt
|
NumberTheory\Zsqrtd\Basic.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Associated.Basic
import Mathlib.Algebra.Star.Unitary
import Mathlib.RingTheory.Int.Basic
import Mathlib.RingTheory.PrincipalIdealDomain
import Mathlib.Tactic.Ring
/-! # ℤ[√d]
The ring of integers adjoined with a square root of `d : ℤ`.
After defining the norm, we show that it is a linearly ordered commutative ring,
as well as an integral domain.
We provide the universal property, that ring homomorphisms `ℤ√d →+* R` correspond
to choices of square roots of `d` in `R`.
-/
/-- The ring of integers adjoined with a square root of `d`.
These have the form `a + b √d` where `a b : ℤ`. The components
are called `re` and `im` by analogy to the negative `d` case. -/
@[ext]
structure Zsqrtd (d : ℤ) where
re : ℤ
im : ℤ
deriving DecidableEq
prefix:100 "ℤ√" => Zsqrtd
namespace Zsqrtd
section
variable {d : ℤ}
/-- Convert an integer to a `ℤ√d` -/
def ofInt (n : ℤ) : ℤ√d :=
⟨n, 0⟩
theorem ofInt_re (n : ℤ) : (ofInt n : ℤ√d).re = n :=
rfl
theorem ofInt_im (n : ℤ) : (ofInt n : ℤ√d).im = 0 :=
rfl
/-- The zero of the ring -/
instance : Zero (ℤ√d) :=
⟨ofInt 0⟩
@[simp]
theorem zero_re : (0 : ℤ√d).re = 0 :=
rfl
@[simp]
theorem zero_im : (0 : ℤ√d).im = 0 :=
rfl
instance : Inhabited (ℤ√d) :=
⟨0⟩
/-- The one of the ring -/
instance : One (ℤ√d) :=
⟨ofInt 1⟩
@[simp]
theorem one_re : (1 : ℤ√d).re = 1 :=
rfl
@[simp]
theorem one_im : (1 : ℤ√d).im = 0 :=
rfl
/-- The representative of `√d` in the ring -/
def sqrtd : ℤ√d :=
⟨0, 1⟩
@[simp]
theorem sqrtd_re : (sqrtd : ℤ√d).re = 0 :=
rfl
@[simp]
theorem sqrtd_im : (sqrtd : ℤ√d).im = 1 :=
rfl
/-- Addition of elements of `ℤ√d` -/
instance : Add (ℤ√d) :=
⟨fun z w => ⟨z.1 + w.1, z.2 + w.2⟩⟩
@[simp]
theorem add_def (x y x' y' : ℤ) : (⟨x, y⟩ + ⟨x', y'⟩ : ℤ√d) = ⟨x + x', y + y'⟩ :=
rfl
@[simp]
theorem add_re (z w : ℤ√d) : (z + w).re = z.re + w.re :=
rfl
@[simp]
theorem add_im (z w : ℤ√d) : (z + w).im = z.im + w.im :=
rfl
/-- Negation in `ℤ√d` -/
instance : Neg (ℤ√d) :=
⟨fun z => ⟨-z.1, -z.2⟩⟩
@[simp]
theorem neg_re (z : ℤ√d) : (-z).re = -z.re :=
rfl
@[simp]
theorem neg_im (z : ℤ√d) : (-z).im = -z.im :=
rfl
/-- Multiplication in `ℤ√d` -/
instance : Mul (ℤ√d) :=
⟨fun z w => ⟨z.1 * w.1 + d * z.2 * w.2, z.1 * w.2 + z.2 * w.1⟩⟩
@[simp]
theorem mul_re (z w : ℤ√d) : (z * w).re = z.re * w.re + d * z.im * w.im :=
rfl
@[simp]
theorem mul_im (z w : ℤ√d) : (z * w).im = z.re * w.im + z.im * w.re :=
rfl
instance addCommGroup : AddCommGroup (ℤ√d) := by
refine
{ add := (· + ·)
zero := (0 : ℤ√d)
sub := fun a b => a + -b
neg := Neg.neg
nsmul := @nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩
zsmul := @zsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ ⟨Neg.neg⟩ (@nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩)
add_assoc := ?_
zero_add := ?_
add_zero := ?_
add_left_neg := ?_
add_comm := ?_ } <;>
intros <;>
ext <;>
simp [add_comm, add_left_comm]
@[simp]
theorem sub_re (z w : ℤ√d) : (z - w).re = z.re - w.re :=
rfl
@[simp]
theorem sub_im (z w : ℤ√d) : (z - w).im = z.im - w.im :=
rfl
instance addGroupWithOne : AddGroupWithOne (ℤ√d) :=
{ Zsqrtd.addCommGroup with
natCast := fun n => ofInt n
intCast := ofInt
one := 1 }
instance commRing : CommRing (ℤ√d) := by
refine
{ Zsqrtd.addGroupWithOne with
mul := (· * ·)
npow := @npowRec (ℤ√d) ⟨1⟩ ⟨(· * ·)⟩,
add_comm := ?_
left_distrib := ?_
right_distrib := ?_
zero_mul := ?_
mul_zero := ?_
mul_assoc := ?_
one_mul := ?_
mul_one := ?_
mul_comm := ?_ } <;>
intros <;>
ext <;>
simp <;>
ring
instance : AddMonoid (ℤ√d) := by infer_instance
instance : Monoid (ℤ√d) := by infer_instance
instance : CommMonoid (ℤ√d) := by infer_instance
instance : CommSemigroup (ℤ√d) := by infer_instance
instance : Semigroup (ℤ√d) := by infer_instance
instance : AddCommSemigroup (ℤ√d) := by infer_instance
instance : AddSemigroup (ℤ√d) := by infer_instance
instance : CommSemiring (ℤ√d) := by infer_instance
instance : Semiring (ℤ√d) := by infer_instance
instance : Ring (ℤ√d) := by infer_instance
instance : Distrib (ℤ√d) := by infer_instance
/-- Conjugation in `ℤ√d`. The conjugate of `a + b √d` is `a - b √d`. -/
instance : Star (ℤ√d) where
star z := ⟨z.1, -z.2⟩
@[simp]
theorem star_mk (x y : ℤ) : star (⟨x, y⟩ : ℤ√d) = ⟨x, -y⟩ :=
rfl
@[simp]
theorem star_re (z : ℤ√d) : (star z).re = z.re :=
rfl
@[simp]
theorem star_im (z : ℤ√d) : (star z).im = -z.im :=
rfl
instance : StarRing (ℤ√d) where
star_involutive x := Zsqrtd.ext rfl (neg_neg _)
star_mul a b := by ext <;> simp <;> ring
star_add a b := Zsqrtd.ext rfl (neg_add _ _)
-- Porting note: proof was `by decide`
instance nontrivial : Nontrivial (ℤ√d) :=
⟨⟨0, 1, Zsqrtd.ext_iff.not.mpr (by simp)⟩⟩
@[simp]
theorem natCast_re (n : ℕ) : (n : ℤ√d).re = n :=
rfl
@[simp]
theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : ℤ√d).re = n :=
rfl
@[simp]
theorem natCast_im (n : ℕ) : (n : ℤ√d).im = 0 :=
rfl
@[simp]
theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : ℤ√d).im = 0 :=
rfl
theorem natCast_val (n : ℕ) : (n : ℤ√d) = ⟨n, 0⟩ :=
rfl
@[simp]
theorem intCast_re (n : ℤ) : (n : ℤ√d).re = n := by cases n <;> rfl
@[simp]
theorem intCast_im (n : ℤ) : (n : ℤ√d).im = 0 := by cases n <;> rfl
theorem intCast_val (n : ℤ) : (n : ℤ√d) = ⟨n, 0⟩ := by ext <;> simp
instance : CharZero (ℤ√d) where cast_injective m n := by simp [Zsqrtd.ext_iff]
@[simp]
theorem ofInt_eq_intCast (n : ℤ) : (ofInt n : ℤ√d) = n := by ext <;> simp [ofInt_re, ofInt_im]
@[deprecated (since := "2024-04-05")] alias coe_nat_re := natCast_re
@[deprecated (since := "2024-04-05")] alias coe_nat_im := natCast_im
@[deprecated (since := "2024-04-05")] alias coe_nat_val := natCast_val
@[deprecated (since := "2024-04-05")] alias coe_int_re := intCast_re
@[deprecated (since := "2024-04-05")] alias coe_int_im := intCast_im
@[deprecated (since := "2024-04-05")] alias coe_int_val := intCast_val
@[deprecated (since := "2024-04-05")] alias ofInt_eq_coe := ofInt_eq_intCast
@[simp]
theorem smul_val (n x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp
theorem smul_re (a : ℤ) (b : ℤ√d) : (↑a * b).re = a * b.re := by simp
theorem smul_im (a : ℤ) (b : ℤ√d) : (↑a * b).im = a * b.im := by simp
@[simp]
theorem muld_val (x y : ℤ) : sqrtd (d := d) * ⟨x, y⟩ = ⟨d * y, x⟩ := by ext <;> simp
@[simp]
theorem dmuld : sqrtd (d := d) * sqrtd (d := d) = d := by ext <;> simp
@[simp]
theorem smuld_val (n x y : ℤ) : sqrtd * (n : ℤ√d) * ⟨x, y⟩ = ⟨d * n * y, n * x⟩ := by ext <;> simp
theorem decompose {x y : ℤ} : (⟨x, y⟩ : ℤ√d) = x + sqrtd (d := d) * y := by ext <;> simp
theorem mul_star {x y : ℤ} : (⟨x, y⟩ * star ⟨x, y⟩ : ℤ√d) = x * x - d * y * y := by
ext <;> simp [sub_eq_add_neg, mul_comm]
@[deprecated (since := "2024-05-25")] alias coe_int_add := Int.cast_add
@[deprecated (since := "2024-05-25")] alias coe_int_sub := Int.cast_sub
@[deprecated (since := "2024-05-25")] alias coe_int_mul := Int.cast_mul
@[deprecated (since := "2024-05-25")] alias coe_int_inj := Int.cast_inj
theorem intCast_dvd (z : ℤ) (a : ℤ√d) : ↑z ∣ a ↔ z ∣ a.re ∧ z ∣ a.im := by
constructor
· rintro ⟨x, rfl⟩
simp only [add_zero, intCast_re, zero_mul, mul_im, dvd_mul_right, and_self_iff,
mul_re, mul_zero, intCast_im]
· rintro ⟨⟨r, hr⟩, ⟨i, hi⟩⟩
use ⟨r, i⟩
rw [smul_val, Zsqrtd.ext_iff]
exact ⟨hr, hi⟩
@[simp, norm_cast]
theorem intCast_dvd_intCast (a b : ℤ) : (a : ℤ√d) ∣ b ↔ a ∣ b := by
rw [intCast_dvd]
constructor
· rintro ⟨hre, -⟩
rwa [intCast_re] at hre
· rw [intCast_re, intCast_im]
exact fun hc => ⟨hc, dvd_zero a⟩
@[deprecated (since := "2024-05-25")] alias coe_int_dvd_iff := intCast_dvd
@[deprecated (since := "2024-05-25")] alias coe_int_dvd_coe_int := intCast_dvd_intCast
protected theorem eq_of_smul_eq_smul_left {a : ℤ} {b c : ℤ√d} (ha : a ≠ 0) (h : ↑a * b = a * c) :
b = c := by
rw [Zsqrtd.ext_iff] at h ⊢
apply And.imp _ _ h <;> simpa only [smul_re, smul_im] using mul_left_cancel₀ ha
section Gcd
theorem gcd_eq_zero_iff (a : ℤ√d) : Int.gcd a.re a.im = 0 ↔ a = 0 := by
simp only [Int.gcd_eq_zero_iff, Zsqrtd.ext_iff, eq_self_iff_true, zero_im, zero_re]
theorem gcd_pos_iff (a : ℤ√d) : 0 < Int.gcd a.re a.im ↔ a ≠ 0 :=
pos_iff_ne_zero.trans <| not_congr a.gcd_eq_zero_iff
theorem coprime_of_dvd_coprime {a b : ℤ√d} (hcoprime : IsCoprime a.re a.im) (hdvd : b ∣ a) :
IsCoprime b.re b.im := by
apply isCoprime_of_dvd
· rintro ⟨hre, him⟩
obtain rfl : b = 0 := Zsqrtd.ext hre him
rw [zero_dvd_iff] at hdvd
simp [hdvd, zero_im, zero_re, not_isCoprime_zero_zero] at hcoprime
· rintro z hz - hzdvdu hzdvdv
apply hz
obtain ⟨ha, hb⟩ : z ∣ a.re ∧ z ∣ a.im := by
rw [← intCast_dvd]
apply dvd_trans _ hdvd
rw [intCast_dvd]
exact ⟨hzdvdu, hzdvdv⟩
exact hcoprime.isUnit_of_dvd' ha hb
theorem exists_coprime_of_gcd_pos {a : ℤ√d} (hgcd : 0 < Int.gcd a.re a.im) :
∃ b : ℤ√d, a = ((Int.gcd a.re a.im : ℤ) : ℤ√d) * b ∧ IsCoprime b.re b.im := by
obtain ⟨re, im, H1, Hre, Him⟩ := Int.exists_gcd_one hgcd
rw [mul_comm] at Hre Him
refine ⟨⟨re, im⟩, ?_, ?_⟩
· rw [smul_val, ← Hre, ← Him]
· rw [← Int.gcd_eq_one_iff_coprime, H1]
end Gcd
/-- Read `SqLe a c b d` as `a √c ≤ b √d` -/
def SqLe (a c b d : ℕ) : Prop :=
c * a * a ≤ d * b * b
theorem sqLe_of_le {c d x y z w : ℕ} (xz : z ≤ x) (yw : y ≤ w) (xy : SqLe x c y d) : SqLe z c w d :=
le_trans (mul_le_mul (Nat.mul_le_mul_left _ xz) xz (Nat.zero_le _) (Nat.zero_le _)) <|
le_trans xy (mul_le_mul (Nat.mul_le_mul_left _ yw) yw (Nat.zero_le _) (Nat.zero_le _))
theorem sqLe_add_mixed {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) :
c * (x * z) ≤ d * (y * w) :=
Nat.mul_self_le_mul_self_iff.1 <| by
simpa [mul_comm, mul_left_comm] using mul_le_mul xy zw (Nat.zero_le _) (Nat.zero_le _)
theorem sqLe_add {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) :
SqLe (x + z) c (y + w) d := by
have xz := sqLe_add_mixed xy zw
simp? [SqLe, mul_assoc] at xy zw says simp only [SqLe, mul_assoc] at xy zw
simp [SqLe, mul_add, mul_comm, mul_left_comm, add_le_add, *]
theorem sqLe_cancel {c d x y z w : ℕ} (zw : SqLe y d x c) (h : SqLe (x + z) c (y + w) d) :
SqLe z c w d := by
apply le_of_not_gt
intro l
refine not_le_of_gt ?_ h
simp only [SqLe, mul_add, mul_comm, mul_left_comm, add_assoc, gt_iff_lt]
have hm := sqLe_add_mixed zw (le_of_lt l)
simp only [SqLe, mul_assoc, gt_iff_lt] at l zw
exact
lt_of_le_of_lt (add_le_add_right zw _)
(add_lt_add_left (add_lt_add_of_le_of_lt hm (add_lt_add_of_le_of_lt hm l)) _)
theorem sqLe_smul {c d x y : ℕ} (n : ℕ) (xy : SqLe x c y d) : SqLe (n * x) c (n * y) d := by
simpa [SqLe, mul_left_comm, mul_assoc] using Nat.mul_le_mul_left (n * n) xy
theorem sqLe_mul {d x y z w : ℕ} :
(SqLe x 1 y d → SqLe z 1 w d → SqLe (x * w + y * z) d (x * z + d * y * w) 1) ∧
(SqLe x 1 y d → SqLe w d z 1 → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧
(SqLe y d x 1 → SqLe z 1 w d → SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧
(SqLe y d x 1 → SqLe w d z 1 → SqLe (x * w + y * z) d (x * z + d * y * w) 1) := by
refine ⟨?_, ?_, ?_, ?_⟩ <;>
· intro xy zw
have :=
Int.mul_nonneg (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le xy))
(sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le zw))
refine Int.le_of_ofNat_le_ofNat (le_of_sub_nonneg ?_)
convert this using 1
simp only [one_mul, Int.ofNat_add, Int.ofNat_mul]
ring
open Int in
/-- "Generalized" `nonneg`. `nonnegg c d x y` means `a √c + b √d ≥ 0`;
we are interested in the case `c = 1` but this is more symmetric -/
def Nonnegg (c d : ℕ) : ℤ → ℤ → Prop
| (a : ℕ), (b : ℕ) => True
| (a : ℕ), -[b+1] => SqLe (b + 1) c a d
| -[a+1], (b : ℕ) => SqLe (a + 1) d b c
| -[_+1], -[_+1] => False
theorem nonnegg_comm {c d : ℕ} {x y : ℤ} : Nonnegg c d x y = Nonnegg d c y x := by
induction x <;> induction y <;> rfl
theorem nonnegg_neg_pos {c d} : ∀ {a b : ℕ}, Nonnegg c d (-a) b ↔ SqLe a d b c
| 0, b => ⟨by simp [SqLe, Nat.zero_le], fun _ => trivial⟩
| a + 1, b => by rw [← Int.negSucc_coe]; rfl
theorem nonnegg_pos_neg {c d} {a b : ℕ} : Nonnegg c d a (-b) ↔ SqLe b c a d := by
rw [nonnegg_comm]; exact nonnegg_neg_pos
open Int in
theorem nonnegg_cases_right {c d} {a : ℕ} :
∀ {b : ℤ}, (∀ x : ℕ, b = -x → SqLe x c a d) → Nonnegg c d a b
| (b : Nat), _ => trivial
| -[b+1], h => h (b + 1) rfl
theorem nonnegg_cases_left {c d} {b : ℕ} {a : ℤ} (h : ∀ x : ℕ, a = -x → SqLe x d b c) :
Nonnegg c d a b :=
cast nonnegg_comm (nonnegg_cases_right h)
section Norm
/-- The norm of an element of `ℤ[√d]`. -/
def norm (n : ℤ√d) : ℤ :=
n.re * n.re - d * n.im * n.im
theorem norm_def (n : ℤ√d) : n.norm = n.re * n.re - d * n.im * n.im :=
rfl
@[simp]
theorem norm_zero : norm (0 : ℤ√d) = 0 := by simp [norm]
@[simp]
theorem norm_one : norm (1 : ℤ√d) = 1 := by simp [norm]
@[simp]
theorem norm_intCast (n : ℤ) : norm (n : ℤ√d) = n * n := by simp [norm]
@[deprecated (since := "2024-04-17")]
alias norm_int_cast := norm_intCast
@[simp]
theorem norm_natCast (n : ℕ) : norm (n : ℤ√d) = n * n :=
norm_intCast n
@[deprecated (since := "2024-04-17")]
alias norm_nat_cast := norm_natCast
@[simp]
theorem norm_mul (n m : ℤ√d) : norm (n * m) = norm n * norm m := by
simp only [norm, mul_im, mul_re]
ring
/-- `norm` as a `MonoidHom`. -/
def normMonoidHom : ℤ√d →* ℤ where
toFun := norm
map_mul' := norm_mul
map_one' := norm_one
theorem norm_eq_mul_conj (n : ℤ√d) : (norm n : ℤ√d) = n * star n := by
ext <;> simp [norm, star, mul_comm, sub_eq_add_neg]
@[simp]
theorem norm_neg (x : ℤ√d) : (-x).norm = x.norm :=
-- Porting note: replaced `simp` with `rw`
-- See https://github.com/leanprover-community/mathlib4/issues/5026
Int.cast_inj.1 <| by rw [norm_eq_mul_conj, star_neg, neg_mul_neg, norm_eq_mul_conj]
@[simp]
theorem norm_conj (x : ℤ√d) : (star x).norm = x.norm :=
-- Porting note: replaced `simp` with `rw`
-- See https://github.com/leanprover-community/mathlib4/issues/5026
Int.cast_inj.1 <| by rw [norm_eq_mul_conj, star_star, mul_comm, norm_eq_mul_conj]
theorem norm_nonneg (hd : d ≤ 0) (n : ℤ√d) : 0 ≤ n.norm :=
add_nonneg (mul_self_nonneg _)
(by
rw [mul_assoc, neg_mul_eq_neg_mul]
exact mul_nonneg (neg_nonneg.2 hd) (mul_self_nonneg _))
theorem norm_eq_one_iff {x : ℤ√d} : x.norm.natAbs = 1 ↔ IsUnit x :=
⟨fun h =>
isUnit_iff_dvd_one.2 <|
(le_total 0 (norm x)).casesOn
(fun hx =>
⟨star x, by
rwa [← Int.natCast_inj, Int.natAbs_of_nonneg hx, ← @Int.cast_inj (ℤ√d) _ _,
norm_eq_mul_conj, eq_comm] at h⟩)
fun hx =>
⟨-star x, by
rwa [← Int.natCast_inj, Int.ofNat_natAbs_of_nonpos hx, ← @Int.cast_inj (ℤ√d) _ _,
Int.cast_neg, norm_eq_mul_conj, neg_mul_eq_mul_neg, eq_comm] at h⟩,
fun h => by
let ⟨y, hy⟩ := isUnit_iff_dvd_one.1 h
have := congr_arg (Int.natAbs ∘ norm) hy
rw [Function.comp_apply, Function.comp_apply, norm_mul, Int.natAbs_mul, norm_one,
Int.natAbs_one, eq_comm, mul_eq_one] at this
exact this.1⟩
theorem isUnit_iff_norm_isUnit {d : ℤ} (z : ℤ√d) : IsUnit z ↔ IsUnit z.norm := by
rw [Int.isUnit_iff_natAbs_eq, norm_eq_one_iff]
theorem norm_eq_one_iff' {d : ℤ} (hd : d ≤ 0) (z : ℤ√d) : z.norm = 1 ↔ IsUnit z := by
rw [← norm_eq_one_iff, ← Int.natCast_inj, Int.natAbs_of_nonneg (norm_nonneg hd z), Int.ofNat_one]
theorem norm_eq_zero_iff {d : ℤ} (hd : d < 0) (z : ℤ√d) : z.norm = 0 ↔ z = 0 := by
constructor
· intro h
rw [norm_def, sub_eq_add_neg, mul_assoc] at h
have left := mul_self_nonneg z.re
have right := neg_nonneg.mpr (mul_nonpos_of_nonpos_of_nonneg hd.le (mul_self_nonneg z.im))
obtain ⟨ha, hb⟩ := (add_eq_zero_iff' left right).mp h
ext <;> apply eq_zero_of_mul_self_eq_zero
· exact ha
· rw [neg_eq_zero, mul_eq_zero] at hb
exact hb.resolve_left hd.ne
· rintro rfl
exact norm_zero
theorem norm_eq_of_associated {d : ℤ} (hd : d ≤ 0) {x y : ℤ√d} (h : Associated x y) :
x.norm = y.norm := by
obtain ⟨u, rfl⟩ := h
rw [norm_mul, (norm_eq_one_iff' hd _).mpr u.isUnit, mul_one]
end Norm
end
section
variable {d : ℕ}
/-- Nonnegativity of an element of `ℤ√d`. -/
def Nonneg : ℤ√d → Prop
| ⟨a, b⟩ => Nonnegg d 1 a b
instance : LE (ℤ√d) :=
⟨fun a b => Nonneg (b - a)⟩
instance : LT (ℤ√d) :=
⟨fun a b => ¬b ≤ a⟩
instance decidableNonnegg (c d a b) : Decidable (Nonnegg c d a b) := by
cases a <;> cases b <;> unfold Nonnegg SqLe <;> infer_instance
instance decidableNonneg : ∀ a : ℤ√d, Decidable (Nonneg a)
| ⟨_, _⟩ => Zsqrtd.decidableNonnegg _ _ _ _
instance decidableLE : @DecidableRel (ℤ√d) (· ≤ ·) := fun _ _ => decidableNonneg _
open Int in
theorem nonneg_cases : ∀ {a : ℤ√d}, Nonneg a → ∃ x y : ℕ, a = ⟨x, y⟩ ∨ a = ⟨x, -y⟩ ∨ a = ⟨-x, y⟩
| ⟨(x : ℕ), (y : ℕ)⟩, _ => ⟨x, y, Or.inl rfl⟩
| ⟨(x : ℕ), -[y+1]⟩, _ => ⟨x, y + 1, Or.inr <| Or.inl rfl⟩
| ⟨-[x+1], (y : ℕ)⟩, _ => ⟨x + 1, y, Or.inr <| Or.inr rfl⟩
| ⟨-[_+1], -[_+1]⟩, h => False.elim h
open Int in
theorem nonneg_add_lem {x y z w : ℕ} (xy : Nonneg (⟨x, -y⟩ : ℤ√d)) (zw : Nonneg (⟨-z, w⟩ : ℤ√d)) :
Nonneg (⟨x, -y⟩ + ⟨-z, w⟩ : ℤ√d) := by
have : Nonneg ⟨Int.subNatNat x z, Int.subNatNat w y⟩ :=
Int.subNatNat_elim x z
(fun m n i => SqLe y d m 1 → SqLe n 1 w d → Nonneg ⟨i, Int.subNatNat w y⟩)
(fun j k =>
Int.subNatNat_elim w y
(fun m n i => SqLe n d (k + j) 1 → SqLe k 1 m d → Nonneg ⟨Int.ofNat j, i⟩)
(fun _ _ _ _ => trivial) fun m n xy zw => sqLe_cancel zw xy)
(fun j k =>
Int.subNatNat_elim w y
(fun m n i => SqLe n d k 1 → SqLe (k + j + 1) 1 m d → Nonneg ⟨-[j+1], i⟩)
(fun m n xy zw => sqLe_cancel xy zw) fun m n xy zw =>
let t := Nat.le_trans zw (sqLe_of_le (Nat.le_add_right n (m + 1)) le_rfl xy)
have : k + j + 1 ≤ k :=
Nat.mul_self_le_mul_self_iff.1 (by simpa [one_mul] using t)
absurd this (not_le_of_gt <| Nat.succ_le_succ <| Nat.le_add_right _ _))
(nonnegg_pos_neg.1 xy) (nonnegg_neg_pos.1 zw)
rw [add_def, neg_add_eq_sub]
rwa [Int.subNatNat_eq_coe, Int.subNatNat_eq_coe] at this
theorem Nonneg.add {a b : ℤ√d} (ha : Nonneg a) (hb : Nonneg b) : Nonneg (a + b) := by
rcases nonneg_cases ha with ⟨x, y, rfl | rfl | rfl⟩ <;>
rcases nonneg_cases hb with ⟨z, w, rfl | rfl | rfl⟩
· trivial
· refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 hb)
· dsimp only at h
exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro y (by simp [add_comm, *])))
· apply Nat.le_add_left
· refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 hb)
· dsimp only at h
exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro x (by simp [add_comm, *])))
· apply Nat.le_add_left
· refine nonnegg_cases_right fun i h => sqLe_of_le ?_ ?_ (nonnegg_pos_neg.1 ha)
· dsimp only at h
exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro w (by simp [*])))
· apply Nat.le_add_right
· have : Nonneg ⟨_, _⟩ :=
nonnegg_pos_neg.2 (sqLe_add (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb))
rw [Nat.cast_add, Nat.cast_add, neg_add] at this
rwa [add_def]
-- Porting note: was
-- simpa [add_comm] using
-- nonnegg_pos_neg.2 (sqLe_add (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb))
· exact nonneg_add_lem ha hb
· refine nonnegg_cases_left fun i h => sqLe_of_le ?_ ?_ (nonnegg_neg_pos.1 ha)
· dsimp only at h
exact Int.ofNat_le.1 (le_of_neg_le_neg (Int.le.intro _ h))
· apply Nat.le_add_right
· dsimp
rw [add_comm, add_comm (y : ℤ)]
exact nonneg_add_lem hb ha
· have : Nonneg ⟨_, _⟩ :=
nonnegg_neg_pos.2 (sqLe_add (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb))
rw [Nat.cast_add, Nat.cast_add, neg_add] at this
rwa [add_def]
-- Porting note: was
-- simpa [add_comm] using
-- nonnegg_neg_pos.2 (sqLe_add (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb))
theorem nonneg_iff_zero_le {a : ℤ√d} : Nonneg a ↔ 0 ≤ a :=
show _ ↔ Nonneg _ by simp
theorem le_of_le_le {x y z w : ℤ} (xz : x ≤ z) (yw : y ≤ w) : (⟨x, y⟩ : ℤ√d) ≤ ⟨z, w⟩ :=
show Nonneg ⟨z - x, w - y⟩ from
match z - x, w - y, Int.le.dest_sub xz, Int.le.dest_sub yw with
| _, _, ⟨_, rfl⟩, ⟨_, rfl⟩ => trivial
open Int in
protected theorem nonneg_total : ∀ a : ℤ√d, Nonneg a ∨ Nonneg (-a)
| ⟨(x : ℕ), (y : ℕ)⟩ => Or.inl trivial
| ⟨-[_+1], -[_+1]⟩ => Or.inr trivial
| ⟨0, -[_+1]⟩ => Or.inr trivial
| ⟨-[_+1], 0⟩ => Or.inr trivial
| ⟨(_ + 1 : ℕ), -[_+1]⟩ => Nat.le_total _ _
| ⟨-[_+1], (_ + 1 : ℕ)⟩ => Nat.le_total _ _
protected theorem le_total (a b : ℤ√d) : a ≤ b ∨ b ≤ a := by
have t := (b - a).nonneg_total
rwa [neg_sub] at t
instance preorder : Preorder (ℤ√d) where
le := (· ≤ ·)
le_refl a := show Nonneg (a - a) by simp only [sub_self]; trivial
le_trans a b c hab hbc := by simpa [sub_add_sub_cancel'] using hab.add hbc
lt := (· < ·)
lt_iff_le_not_le a b := (and_iff_right_of_imp (Zsqrtd.le_total _ _).resolve_left).symm
open Int in
theorem le_arch (a : ℤ√d) : ∃ n : ℕ, a ≤ n := by
obtain ⟨x, y, (h : a ≤ ⟨x, y⟩)⟩ : ∃ x y : ℕ, Nonneg (⟨x, y⟩ + -a) :=
match -a with
| ⟨Int.ofNat x, Int.ofNat y⟩ => ⟨0, 0, by trivial⟩
| ⟨Int.ofNat x, -[y+1]⟩ => ⟨0, y + 1, by simp [add_def, Int.negSucc_coe, add_assoc]; trivial⟩
| ⟨-[x+1], Int.ofNat y⟩ => ⟨x + 1, 0, by simp [Int.negSucc_coe, add_assoc]; trivial⟩
| ⟨-[x+1], -[y+1]⟩ => ⟨x + 1, y + 1, by simp [Int.negSucc_coe, add_assoc]; trivial⟩
refine ⟨x + d * y, h.trans ?_⟩
change Nonneg ⟨↑x + d * y - ↑x, 0 - ↑y⟩
cases' y with y
· simp
trivial
have h : ∀ y, SqLe y d (d * y) 1 := fun y => by
simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_right (y * y) (Nat.le_mul_self d)
rw [show (x : ℤ) + d * Nat.succ y - x = d * Nat.succ y by simp]
exact h (y + 1)
protected theorem add_le_add_left (a b : ℤ√d) (ab : a ≤ b) (c : ℤ√d) : c + a ≤ c + b :=
show Nonneg _ by rw [add_sub_add_left_eq_sub]; exact ab
protected theorem le_of_add_le_add_left (a b c : ℤ√d) (h : c + a ≤ c + b) : a ≤ b := by
simpa using Zsqrtd.add_le_add_left _ _ h (-c)
protected theorem add_lt_add_left (a b : ℤ√d) (h : a < b) (c) : c + a < c + b := fun h' =>
h (Zsqrtd.le_of_add_le_add_left _ _ _ h')
theorem nonneg_smul {a : ℤ√d} {n : ℕ} (ha : Nonneg a) : Nonneg ((n : ℤ√d) * a) := by
rw [← Int.cast_natCast n]
exact
match a, nonneg_cases ha, ha with
| _, ⟨x, y, Or.inl rfl⟩, _ => by rw [smul_val]; trivial
| _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ha => by
rw [smul_val]; simpa using nonnegg_pos_neg.2 (sqLe_smul n <| nonnegg_pos_neg.1 ha)
| _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ha => by
rw [smul_val]; simpa using nonnegg_neg_pos.2 (sqLe_smul n <| nonnegg_neg_pos.1 ha)
theorem nonneg_muld {a : ℤ√d} (ha : Nonneg a) : Nonneg (sqrtd * a) :=
match a, nonneg_cases ha, ha with
| _, ⟨_, _, Or.inl rfl⟩, _ => trivial
| _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ha => by
simp only [muld_val, mul_neg]
apply nonnegg_neg_pos.2
simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_left d (nonnegg_pos_neg.1 ha)
| _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ha => by
simp only [muld_val]
apply nonnegg_pos_neg.2
simpa [SqLe, mul_comm, mul_left_comm] using Nat.mul_le_mul_left d (nonnegg_neg_pos.1 ha)
theorem nonneg_mul_lem {x y : ℕ} {a : ℤ√d} (ha : Nonneg a) : Nonneg (⟨x, y⟩ * a) := by
have : (⟨x, y⟩ * a : ℤ√d) = (x : ℤ√d) * a + sqrtd * ((y : ℤ√d) * a) := by
rw [decompose, right_distrib, mul_assoc, Int.cast_natCast, Int.cast_natCast]
rw [this]
exact (nonneg_smul ha).add (nonneg_muld <| nonneg_smul ha)
theorem nonneg_mul {a b : ℤ√d} (ha : Nonneg a) (hb : Nonneg b) : Nonneg (a * b) :=
match a, b, nonneg_cases ha, nonneg_cases hb, ha, hb with
| _, _, ⟨_, _, Or.inl rfl⟩, ⟨_, _, Or.inl rfl⟩, _, _ => trivial
| _, _, ⟨x, y, Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, _, hb => nonneg_mul_lem hb
| _, _, ⟨x, y, Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, _, hb => nonneg_mul_lem hb
| _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inl rfl⟩, ha, _ => by
rw [mul_comm]; exact nonneg_mul_lem ha
| _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inl rfl⟩, ha, _ => by
rw [mul_comm]; exact nonneg_mul_lem ha
| _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, ha, hb => by
rw [calc
(⟨-x, y⟩ * ⟨-z, w⟩ : ℤ√d) = ⟨_, _⟩ := rfl
_ = ⟨x * z + d * y * w, -(x * w + y * z)⟩ := by simp [add_comm]
]
exact nonnegg_pos_neg.2 (sqLe_mul.left (nonnegg_neg_pos.1 ha) (nonnegg_neg_pos.1 hb))
| _, _, ⟨x, y, Or.inr <| Or.inr rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, ha, hb => by
rw [calc
(⟨-x, y⟩ * ⟨z, -w⟩ : ℤ√d) = ⟨_, _⟩ := rfl
_ = ⟨-(x * z + d * y * w), x * w + y * z⟩ := by simp [add_comm]
]
exact nonnegg_neg_pos.2 (sqLe_mul.right.left (nonnegg_neg_pos.1 ha) (nonnegg_pos_neg.1 hb))
| _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inr rfl⟩, ha, hb => by
rw [calc
(⟨x, -y⟩ * ⟨-z, w⟩ : ℤ√d) = ⟨_, _⟩ := rfl
_ = ⟨-(x * z + d * y * w), x * w + y * z⟩ := by simp [add_comm]
]
exact
nonnegg_neg_pos.2 (sqLe_mul.right.right.left (nonnegg_pos_neg.1 ha) (nonnegg_neg_pos.1 hb))
| _, _, ⟨x, y, Or.inr <| Or.inl rfl⟩, ⟨z, w, Or.inr <| Or.inl rfl⟩, ha, hb => by
rw [calc
(⟨x, -y⟩ * ⟨z, -w⟩ : ℤ√d) = ⟨_, _⟩ := rfl
_ = ⟨x * z + d * y * w, -(x * w + y * z)⟩ := by simp [add_comm]
]
exact
nonnegg_pos_neg.2
(sqLe_mul.right.right.right (nonnegg_pos_neg.1 ha) (nonnegg_pos_neg.1 hb))
protected theorem mul_nonneg (a b : ℤ√d) : 0 ≤ a → 0 ≤ b → 0 ≤ a * b := by
simp_rw [← nonneg_iff_zero_le]
exact nonneg_mul
theorem not_sqLe_succ (c d y) (h : 0 < c) : ¬SqLe (y + 1) c 0 d :=
not_le_of_gt <| mul_pos (mul_pos h <| Nat.succ_pos _) <| Nat.succ_pos _
-- Porting note: renamed field and added theorem to make `x` explicit
/-- A nonsquare is a natural number that is not equal to the square of an
integer. This is implemented as a typeclass because it's a necessary condition
for much of the Pell equation theory. -/
class Nonsquare (x : ℕ) : Prop where
ns' : ∀ n : ℕ, x ≠ n * n
theorem Nonsquare.ns (x : ℕ) [Nonsquare x] : ∀ n : ℕ, x ≠ n * n := ns'
variable [dnsq : Nonsquare d]
theorem d_pos : 0 < d :=
lt_of_le_of_ne (Nat.zero_le _) <| Ne.symm <| Nonsquare.ns d 0
theorem divides_sq_eq_zero {x y} (h : x * x = d * y * y) : x = 0 ∧ y = 0 :=
let g := x.gcd y
Or.elim g.eq_zero_or_pos
(fun H => ⟨Nat.eq_zero_of_gcd_eq_zero_left H, Nat.eq_zero_of_gcd_eq_zero_right H⟩) fun gpos =>
False.elim <| by
let ⟨m, n, co, (hx : x = m * g), (hy : y = n * g)⟩ := Nat.exists_coprime _ _
rw [hx, hy] at h
have : m * m = d * (n * n) := by
refine mul_left_cancel₀ (mul_pos gpos gpos).ne' ?_
-- Porting note: was `simpa [mul_comm, mul_left_comm] using h`
calc
g * g * (m * m)
_ = m * g * (m * g) := by ring
_ = d * (n * g) * (n * g) := h
_ = g * g * (d * (n * n)) := by ring
have co2 :=
let co1 := co.mul_right co
co1.mul co1
exact
Nonsquare.ns d m
(Nat.dvd_antisymm (by rw [this]; apply dvd_mul_right) <|
co2.dvd_of_dvd_mul_right <| by simp [this])
theorem divides_sq_eq_zero_z {x y : ℤ} (h : x * x = d * y * y) : x = 0 ∧ y = 0 := by
rw [mul_assoc, ← Int.natAbs_mul_self, ← Int.natAbs_mul_self, ← Int.ofNat_mul, ← mul_assoc] at h
exact
let ⟨h1, h2⟩ := divides_sq_eq_zero (Int.ofNat.inj h)
⟨Int.natAbs_eq_zero.mp h1, Int.natAbs_eq_zero.mp h2⟩
theorem not_divides_sq (x y) : (x + 1) * (x + 1) ≠ d * (y + 1) * (y + 1) := fun e => by
have t := (divides_sq_eq_zero e).left
contradiction
open Int in
theorem nonneg_antisymm : ∀ {a : ℤ√d}, Nonneg a → Nonneg (-a) → a = 0
| ⟨0, 0⟩, _, _ => rfl
| ⟨-[x+1], -[y+1]⟩, xy, _ => False.elim xy
| ⟨(x + 1 : Nat), (y + 1 : Nat)⟩, _, yx => False.elim yx
| ⟨-[x+1], 0⟩, xy, _ => absurd xy (not_sqLe_succ _ _ _ (by decide))
| ⟨(x + 1 : Nat), 0⟩, _, yx => absurd yx (not_sqLe_succ _ _ _ (by decide))
| ⟨0, -[y+1]⟩, xy, _ => absurd xy (not_sqLe_succ _ _ _ d_pos)
| ⟨0, (y + 1 : Nat)⟩, _, yx => absurd yx (not_sqLe_succ _ _ _ d_pos)
| ⟨(x + 1 : Nat), -[y+1]⟩, (xy : SqLe _ _ _ _), (yx : SqLe _ _ _ _) => by
let t := le_antisymm yx xy
rw [one_mul] at t
exact absurd t (not_divides_sq _ _)
| ⟨-[x+1], (y + 1 : Nat)⟩, (xy : SqLe _ _ _ _), (yx : SqLe _ _ _ _) => by
let t := le_antisymm xy yx
rw [one_mul] at t
exact absurd t (not_divides_sq _ _)
theorem le_antisymm {a b : ℤ√d} (ab : a ≤ b) (ba : b ≤ a) : a = b :=
eq_of_sub_eq_zero <| nonneg_antisymm ba (by rwa [neg_sub])
instance linearOrder : LinearOrder (ℤ√d) :=
{ Zsqrtd.preorder with
le_antisymm := fun _ _ => Zsqrtd.le_antisymm
le_total := Zsqrtd.le_total
decidableLE := Zsqrtd.decidableLE }
protected theorem eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {a b : ℤ√d}, a * b = 0 → a = 0 ∨ b = 0
| ⟨x, y⟩, ⟨z, w⟩, h => by
injection h with h1 h2
have h1 : x * z = -(d * y * w) := eq_neg_of_add_eq_zero_left h1
have h2 : x * w = -(y * z) := eq_neg_of_add_eq_zero_left h2
have fin : x * x = d * y * y → (⟨x, y⟩ : ℤ√d) = 0 := fun e =>
match x, y, divides_sq_eq_zero_z e with
| _, _, ⟨rfl, rfl⟩ => rfl
exact
if z0 : z = 0 then
if w0 : w = 0 then
Or.inr
(match z, w, z0, w0 with
| _, _, rfl, rfl => rfl)
else
Or.inl <|
fin <|
mul_right_cancel₀ w0 <|
calc
x * x * w = -y * (x * z) := by simp [h2, mul_assoc, mul_left_comm]
_ = d * y * y * w := by simp [h1, mul_assoc, mul_left_comm]
else
Or.inl <|
fin <|
mul_right_cancel₀ z0 <|
calc
x * x * z = d * -y * (x * w) := by simp [h1, mul_assoc, mul_left_comm]
_ = d * y * y * z := by simp [h2, mul_assoc, mul_left_comm]
instance : NoZeroDivisors (ℤ√d) where
eq_zero_or_eq_zero_of_mul_eq_zero := Zsqrtd.eq_zero_or_eq_zero_of_mul_eq_zero
instance : IsDomain (ℤ√d) :=
NoZeroDivisors.to_isDomain _
protected theorem mul_pos (a b : ℤ√d) (a0 : 0 < a) (b0 : 0 < b) : 0 < a * b := fun ab =>
Or.elim
(eq_zero_or_eq_zero_of_mul_eq_zero
(le_antisymm ab (Zsqrtd.mul_nonneg _ _ (le_of_lt a0) (le_of_lt b0))))
(fun e => ne_of_gt a0 e) fun e => ne_of_gt b0 e
instance : LinearOrderedCommRing (ℤ√d) :=
{ Zsqrtd.commRing, Zsqrtd.linearOrder, Zsqrtd.nontrivial with
add_le_add_left := Zsqrtd.add_le_add_left
mul_pos := Zsqrtd.mul_pos
zero_le_one := by trivial }
instance : LinearOrderedRing (ℤ√d) := by infer_instance
instance : OrderedRing (ℤ√d) := by infer_instance
end
theorem norm_eq_zero {d : ℤ} (h_nonsquare : ∀ n : ℤ, d ≠ n * n) (a : ℤ√d) : norm a = 0 ↔ a = 0 := by
refine ⟨fun ha => Zsqrtd.ext_iff.mpr ?_, fun h => by rw [h, norm_zero]⟩
dsimp only [norm] at ha
rw [sub_eq_zero] at ha
by_cases h : 0 ≤ d
· obtain ⟨d', rfl⟩ := Int.eq_ofNat_of_zero_le h
haveI : Nonsquare d' := ⟨fun n h => h_nonsquare n <| mod_cast h⟩
exact divides_sq_eq_zero_z ha
· push_neg at h
suffices a.re * a.re = 0 by
rw [eq_zero_of_mul_self_eq_zero this] at ha ⊢
simpa only [true_and_iff, or_self_right, zero_re, zero_im, eq_self_iff_true, zero_eq_mul,
mul_zero, mul_eq_zero, h.ne, false_or_iff, or_self_iff] using ha
apply _root_.le_antisymm _ (mul_self_nonneg _)
rw [ha, mul_assoc]
exact mul_nonpos_of_nonpos_of_nonneg h.le (mul_self_nonneg _)
variable {R : Type}
@[ext]
theorem hom_ext [Ring R] {d : ℤ} (f g : ℤ√d →+* R) (h : f sqrtd = g sqrtd) : f = g := by
ext ⟨x_re, x_im⟩
simp [decompose, h]
variable [CommRing R]
/-- The unique `RingHom` from `ℤ√d` to a ring `R`, constructed by replacing `√d` with the provided
root. Conversely, this associates to every mapping `ℤ√d →+* R` a value of `√d` in `R`. -/
@[simps]
def lift {d : ℤ} : { r : R // r * r = ↑d } ≃ (ℤ√d →+* R) where
toFun r :=
{ toFun := fun a => a.1 + a.2 * (r : R)
map_zero' := by simp
map_add' := fun a b => by
simp only [add_re, Int.cast_add, add_im]
ring
map_one' := by simp
map_mul' := fun a b => by
have :
(a.re + a.im * r : R) * (b.re + b.im * r) =
a.re * b.re + (a.re * b.im + a.im * b.re) * r + a.im * b.im * (r * r) := by
ring
simp only [mul_re, Int.cast_add, Int.cast_mul, mul_im, this, r.prop]
ring }
invFun f := ⟨f sqrtd, by rw [← f.map_mul, dmuld, map_intCast]⟩
left_inv r := by
ext
simp
right_inv f := by
-- Porting note: was `ext`
refine hom_ext _ _ ?_
simp
/-- `lift r` is injective if `d` is non-square, and R has characteristic zero (that is, the map from
`ℤ` into `R` is injective). -/
theorem lift_injective [CharZero R] {d : ℤ} (r : { r : R // r * r = ↑d })
(hd : ∀ n : ℤ, d ≠ n * n) : Function.Injective (lift r) :=
(injective_iff_map_eq_zero (lift r)).mpr fun a ha => by
have h_inj : Function.Injective ((↑) : ℤ → R) := Int.cast_injective
suffices lift r a.norm = 0 by
simp only [intCast_re, add_zero, lift_apply_apply, intCast_im, Int.cast_zero,
zero_mul] at this
rwa [← Int.cast_zero, h_inj.eq_iff, norm_eq_zero hd] at this
rw [norm_eq_mul_conj, RingHom.map_mul, ha, zero_mul]
/-- An element of `ℤ√d` has norm equal to `1` if and only if it is contained in the submonoid
of unitary elements. -/
theorem norm_eq_one_iff_mem_unitary {d : ℤ} {a : ℤ√d} : a.norm = 1 ↔ a ∈ unitary (ℤ√d) := by
rw [unitary.mem_iff_self_mul_star, ← norm_eq_mul_conj]
norm_cast
/-- The kernel of the norm map on `ℤ√d` equals the submonoid of unitary elements. -/
theorem mker_norm_eq_unitary {d : ℤ} : MonoidHom.mker (@normMonoidHom d) = unitary (ℤ√d) :=
Submonoid.ext fun _ => norm_eq_one_iff_mem_unitary
end Zsqrtd
|
NumberTheory\Zsqrtd\GaussianInt.lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.NumberTheory.Zsqrtd.Basic
import Mathlib.RingTheory.PrincipalIdealDomain
import Mathlib.Data.Complex.Basic
import Mathlib.Data.Real.Archimedean
/-!
# Gaussian integers
The Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both
integers.
## Main definitions
The Euclidean domain structure on `ℤ[i]` is defined in this file.
The homomorphism `GaussianInt.toComplex` into the complex numbers is also defined in this file.
## See also
See `NumberTheory.Zsqrtd.QuadraticReciprocity` for:
* `prime_iff_mod_four_eq_three_of_nat_prime`:
A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4`
## Notations
This file uses the local notation `ℤ[i]` for `GaussianInt`
## Implementation notes
Gaussian integers are implemented using the more general definition `Zsqrtd`, the type of integers
adjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties
and definitions about `Zsqrtd` can easily be used.
-/
open Zsqrtd Complex
open scoped ComplexConjugate
/-- The Gaussian integers, defined as `ℤ√(-1)`. -/
abbrev GaussianInt : Type :=
Zsqrtd (-1)
local notation "ℤ[i]" => GaussianInt
namespace GaussianInt
instance : Repr ℤ[i] :=
⟨fun x _ => "⟨" ++ repr x.re ++ ", " ++ repr x.im ++ "⟩"⟩
instance instCommRing : CommRing ℤ[i] :=
Zsqrtd.commRing
section
attribute [-instance] Complex.instField -- Avoid making things noncomputable unnecessarily.
/-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/
def toComplex : ℤ[i] →+* ℂ :=
Zsqrtd.lift ⟨I, by simp⟩
end
instance : Coe ℤ[i] ℂ :=
⟨toComplex⟩
theorem toComplex_def (x : ℤ[i]) : (x : ℂ) = x.re + x.im * I :=
rfl
theorem toComplex_def' (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ) = x + y * I := by simp [toComplex_def]
theorem toComplex_def₂ (x : ℤ[i]) : (x : ℂ) = ⟨x.re, x.im⟩ := by
apply Complex.ext <;> simp [toComplex_def]
@[simp]
theorem to_real_re (x : ℤ[i]) : ((x.re : ℤ) : ℝ) = (x : ℂ).re := by simp [toComplex_def]
@[simp]
theorem to_real_im (x : ℤ[i]) : ((x.im : ℤ) : ℝ) = (x : ℂ).im := by simp [toComplex_def]
@[simp]
theorem toComplex_re (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).re = x := by simp [toComplex_def]
@[simp]
theorem toComplex_im (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).im = y := by simp [toComplex_def]
-- Porting note (#10618): @[simp] can prove this
theorem toComplex_add (x y : ℤ[i]) : ((x + y : ℤ[i]) : ℂ) = x + y :=
toComplex.map_add _ _
-- Porting note (#10618): @[simp] can prove this
theorem toComplex_mul (x y : ℤ[i]) : ((x * y : ℤ[i]) : ℂ) = x * y :=
toComplex.map_mul _ _
-- Porting note (#10618): @[simp] can prove this
theorem toComplex_one : ((1 : ℤ[i]) : ℂ) = 1 :=
toComplex.map_one
-- Porting note (#10618): @[simp] can prove this
theorem toComplex_zero : ((0 : ℤ[i]) : ℂ) = 0 :=
toComplex.map_zero
-- Porting note (#10618): @[simp] can prove this
theorem toComplex_neg (x : ℤ[i]) : ((-x : ℤ[i]) : ℂ) = -x :=
toComplex.map_neg _
-- Porting note (#10618): @[simp] can prove this
theorem toComplex_sub (x y : ℤ[i]) : ((x - y : ℤ[i]) : ℂ) = x - y :=
toComplex.map_sub _ _
@[simp]
theorem toComplex_star (x : ℤ[i]) : ((star x : ℤ[i]) : ℂ) = conj (x : ℂ) := by
rw [toComplex_def₂, toComplex_def₂]
exact congr_arg₂ _ rfl (Int.cast_neg _)
@[simp]
theorem toComplex_inj {x y : ℤ[i]} : (x : ℂ) = y ↔ x = y := by
cases x; cases y; simp [toComplex_def₂]
lemma toComplex_injective : Function.Injective GaussianInt.toComplex :=
fun ⦃_ _⦄ ↦ toComplex_inj.mp
@[simp]
theorem toComplex_eq_zero {x : ℤ[i]} : (x : ℂ) = 0 ↔ x = 0 := by
rw [← toComplex_zero, toComplex_inj]
@[simp]
theorem intCast_real_norm (x : ℤ[i]) : (x.norm : ℝ) = Complex.normSq (x : ℂ) := by
rw [Zsqrtd.norm, normSq]; simp
@[deprecated (since := "2024-04-17")]
alias int_cast_real_norm := intCast_real_norm
@[simp]
theorem intCast_complex_norm (x : ℤ[i]) : (x.norm : ℂ) = Complex.normSq (x : ℂ) := by
cases x; rw [Zsqrtd.norm, normSq]; simp
@[deprecated (since := "2024-04-17")]
alias int_cast_complex_norm := intCast_complex_norm
theorem norm_nonneg (x : ℤ[i]) : 0 ≤ norm x :=
Zsqrtd.norm_nonneg (by norm_num) _
@[simp]
theorem norm_eq_zero {x : ℤ[i]} : norm x = 0 ↔ x = 0 := by rw [← @Int.cast_inj ℝ _ _ _]; simp
theorem norm_pos {x : ℤ[i]} : 0 < norm x ↔ x ≠ 0 := by
rw [lt_iff_le_and_ne, Ne, eq_comm, norm_eq_zero]; simp [norm_nonneg]
theorem abs_natCast_norm (x : ℤ[i]) : (x.norm.natAbs : ℤ) = x.norm :=
Int.natAbs_of_nonneg (norm_nonneg _)
@[deprecated (since := "2024-04-05")] alias abs_coe_nat_norm := abs_natCast_norm
@[simp]
theorem natCast_natAbs_norm {α : Type*} [Ring α] (x : ℤ[i]) : (x.norm.natAbs : α) = x.norm := by
rw [← Int.cast_natCast, abs_natCast_norm]
@[deprecated (since := "2024-04-17")]
alias nat_cast_natAbs_norm := natCast_natAbs_norm
theorem natAbs_norm_eq (x : ℤ[i]) :
x.norm.natAbs = x.re.natAbs * x.re.natAbs + x.im.natAbs * x.im.natAbs :=
Int.ofNat.inj <| by simp; simp [Zsqrtd.norm]
instance : Div ℤ[i] :=
⟨fun x y =>
let n := (norm y : ℚ)⁻¹
let c := star y
⟨round ((x * c).re * n : ℚ), round ((x * c).im * n : ℚ)⟩⟩
theorem div_def (x y : ℤ[i]) :
x / y = ⟨round ((x * star y).re / norm y : ℚ), round ((x * star y).im / norm y : ℚ)⟩ :=
show Zsqrtd.mk _ _ = _ by simp [div_eq_mul_inv]
theorem toComplex_div_re (x y : ℤ[i]) : ((x / y : ℤ[i]) : ℂ).re = round (x / y : ℂ).re := by
rw [div_def, ← @Rat.round_cast ℝ _ _]
simp [-Rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul]
theorem toComplex_div_im (x y : ℤ[i]) : ((x / y : ℤ[i]) : ℂ).im = round (x / y : ℂ).im := by
rw [div_def, ← @Rat.round_cast ℝ _ _, ← @Rat.round_cast ℝ _ _]
simp [-Rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul]
theorem normSq_le_normSq_of_re_le_of_im_le {x y : ℂ} (hre : |x.re| ≤ |y.re|)
(him : |x.im| ≤ |y.im|) : Complex.normSq x ≤ Complex.normSq y := by
rw [normSq_apply, normSq_apply, ← _root_.abs_mul_self, _root_.abs_mul, ←
_root_.abs_mul_self y.re, _root_.abs_mul y.re, ← _root_.abs_mul_self x.im,
_root_.abs_mul x.im, ← _root_.abs_mul_self y.im, _root_.abs_mul y.im]
exact
add_le_add (mul_self_le_mul_self (abs_nonneg _) hre) (mul_self_le_mul_self (abs_nonneg _) him)
theorem normSq_div_sub_div_lt_one (x y : ℤ[i]) :
Complex.normSq ((x / y : ℂ) - ((x / y : ℤ[i]) : ℂ)) < 1 :=
calc
Complex.normSq ((x / y : ℂ) - ((x / y : ℤ[i]) : ℂ))
_ = Complex.normSq
((x / y : ℂ).re - ((x / y : ℤ[i]) : ℂ).re + ((x / y : ℂ).im - ((x / y : ℤ[i]) : ℂ).im) *
I : ℂ) :=
congr_arg _ <| by apply Complex.ext <;> simp
_ ≤ Complex.normSq (1 / 2 + 1 / 2 * I) := by
have : |(2⁻¹ : ℝ)| = 2⁻¹ := abs_of_nonneg (by norm_num)
exact normSq_le_normSq_of_re_le_of_im_le
(by rw [toComplex_div_re]; simp [normSq, this]; simpa using abs_sub_round (x / y : ℂ).re)
(by rw [toComplex_div_im]; simp [normSq, this]; simpa using abs_sub_round (x / y : ℂ).im)
_ < 1 := by simp [normSq]; norm_num
instance : Mod ℤ[i] :=
⟨fun x y => x - y * (x / y)⟩
theorem mod_def (x y : ℤ[i]) : x % y = x - y * (x / y) :=
rfl
theorem norm_mod_lt (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) : (x % y).norm < y.norm :=
have : (y : ℂ) ≠ 0 := by rwa [Ne, ← toComplex_zero, toComplex_inj]
(@Int.cast_lt ℝ _ _ _ _).1 <|
calc
↑(Zsqrtd.norm (x % y)) = Complex.normSq (x - y * (x / y : ℤ[i]) : ℂ) := by simp [mod_def]
_ = Complex.normSq (y : ℂ) * Complex.normSq (x / y - (x / y : ℤ[i]) : ℂ) := by
rw [← normSq_mul, mul_sub, mul_div_cancel₀ _ this]
_ < Complex.normSq (y : ℂ) * 1 :=
(mul_lt_mul_of_pos_left (normSq_div_sub_div_lt_one _ _) (normSq_pos.2 this))
_ = Zsqrtd.norm y := by simp
theorem natAbs_norm_mod_lt (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) :
(x % y).norm.natAbs < y.norm.natAbs :=
Int.ofNat_lt.1 (by simp [-Int.ofNat_lt, norm_mod_lt x hy])
theorem norm_le_norm_mul_left (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) :
(norm x).natAbs ≤ (norm (x * y)).natAbs := by
rw [Zsqrtd.norm_mul, Int.natAbs_mul]
exact le_mul_of_one_le_right (Nat.zero_le _) (Int.ofNat_le.1 (by
rw [abs_natCast_norm]
exact Int.add_one_le_of_lt (norm_pos.2 hy)))
instance instNontrivial : Nontrivial ℤ[i] :=
⟨⟨0, 1, by decide⟩⟩
instance : EuclideanDomain ℤ[i] :=
{ GaussianInt.instCommRing,
GaussianInt.instNontrivial with
quotient := (· / ·)
remainder := (· % ·)
quotient_zero := by simp [div_def]; rfl
quotient_mul_add_remainder_eq := fun _ _ => by simp [mod_def]
r := _
r_wellFounded := (measure (Int.natAbs ∘ norm)).wf
remainder_lt := natAbs_norm_mod_lt
mul_left_not_lt := fun a b hb0 => not_lt_of_ge <| norm_le_norm_mul_left a hb0 }
open PrincipalIdealRing
theorem sq_add_sq_of_nat_prime_of_not_irreducible (p : ℕ) [hp : Fact p.Prime]
(hpi : ¬Irreducible (p : ℤ[i])) : ∃ a b, a ^ 2 + b ^ 2 = p :=
have hpu : ¬IsUnit (p : ℤ[i]) :=
mt norm_eq_one_iff.2 <| by
rw [norm_natCast, Int.natAbs_mul, mul_eq_one]
exact fun h => (ne_of_lt hp.1.one_lt).symm h.1
have hab : ∃ a b, (p : ℤ[i]) = a * b ∧ ¬IsUnit a ∧ ¬IsUnit b := by
-- Porting note: was
-- simpa [irreducible_iff, hpu, not_forall, not_or] using hpi
simpa only [true_and, not_false_iff, exists_prop, irreducible_iff, hpu, not_forall, not_or]
using hpi
let ⟨a, b, hpab, hau, hbu⟩ := hab
have hnap : (norm a).natAbs = p :=
((hp.1.mul_eq_prime_sq_iff (mt norm_eq_one_iff.1 hau) (mt norm_eq_one_iff.1 hbu)).1 <| by
rw [← Int.natCast_inj, Int.natCast_pow, sq, ← @norm_natCast (-1), hpab]; simp).1
⟨a.re.natAbs, a.im.natAbs, by simpa [natAbs_norm_eq, sq] using hnap⟩
end GaussianInt
|
NumberTheory\Zsqrtd\QuadraticReciprocity.lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.NumberTheory.Zsqrtd.GaussianInt
import Mathlib.NumberTheory.LegendreSymbol.Basic
import Mathlib.Analysis.Normed.Field.Basic
/-!
# Facts about the gaussian integers relying on quadratic reciprocity.
## Main statements
`prime_iff_mod_four_eq_three_of_nat_prime`
A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4`
-/
open Zsqrtd Complex
open scoped ComplexConjugate
local notation "ℤ[i]" => GaussianInt
namespace GaussianInt
open PrincipalIdealRing
theorem mod_four_eq_three_of_nat_prime_of_prime (p : ℕ) [hp : Fact p.Prime]
(hpi : Prime (p : ℤ[i])) : p % 4 = 3 :=
hp.1.eq_two_or_odd.elim
(fun hp2 =>
absurd hpi
(mt irreducible_iff_prime.2 fun ⟨_, h⟩ => by
have := h ⟨1, 1⟩ ⟨1, -1⟩ (hp2.symm ▸ rfl)
rw [← norm_eq_one_iff, ← norm_eq_one_iff] at this
exact absurd this (by decide)))
fun hp1 =>
by_contradiction fun hp3 : p % 4 ≠ 3 => by
have hp41 : p % 4 = 1 := by
rw [← Nat.mod_mul_left_mod p 2 2, show 2 * 2 = 4 from rfl] at hp1
have := Nat.mod_lt p (show 0 < 4 by decide)
revert this hp3 hp1
generalize p % 4 = m
intros; interval_cases m <;> simp_all -- Porting note (#11043): was `decide!`
let ⟨k, hk⟩ := (ZMod.exists_sq_eq_neg_one_iff (p := p)).2 <| by rw [hp41]; decide
obtain ⟨k, k_lt_p, rfl⟩ : ∃ (k' : ℕ) (_ : k' < p), (k' : ZMod p) = k := by
exact ⟨k.val, k.val_lt, ZMod.natCast_zmod_val k⟩
have hpk : p ∣ k ^ 2 + 1 := by
rw [pow_two, ← CharP.cast_eq_zero_iff (ZMod p) p, Nat.cast_add, Nat.cast_mul, Nat.cast_one,
← hk, add_left_neg]
have hkmul : (k ^ 2 + 1 : ℤ[i]) = ⟨k, 1⟩ * ⟨k, -1⟩ := by ext <;> simp [sq]
have hkltp : 1 + k * k < p * p :=
calc
1 + k * k ≤ k + k * k := by
apply add_le_add_right
exact (Nat.pos_of_ne_zero fun (hk0 : k = 0) => by clear_aux_decl; simp_all [pow_succ'])
_ = k * (k + 1) := by simp [add_comm, mul_add]
_ < p * p := mul_lt_mul k_lt_p k_lt_p (Nat.succ_pos _) (Nat.zero_le _)
have hpk₁ : ¬(p : ℤ[i]) ∣ ⟨k, -1⟩ := fun ⟨x, hx⟩ =>
lt_irrefl (p * x : ℤ[i]).norm.natAbs <|
calc
(norm (p * x : ℤ[i])).natAbs = (Zsqrtd.norm ⟨k, -1⟩).natAbs := by rw [hx]
_ < (norm (p : ℤ[i])).natAbs := by simpa [add_comm, Zsqrtd.norm] using hkltp
_ ≤ (norm (p * x : ℤ[i])).natAbs :=
norm_le_norm_mul_left _ fun hx0 =>
show (-1 : ℤ) ≠ 0 by decide <| by simpa [hx0] using congr_arg Zsqrtd.im hx
have hpk₂ : ¬(p : ℤ[i]) ∣ ⟨k, 1⟩ := fun ⟨x, hx⟩ =>
lt_irrefl (p * x : ℤ[i]).norm.natAbs <|
calc
(norm (p * x : ℤ[i])).natAbs = (Zsqrtd.norm ⟨k, 1⟩).natAbs := by rw [hx]
_ < (norm (p : ℤ[i])).natAbs := by simpa [add_comm, Zsqrtd.norm] using hkltp
_ ≤ (norm (p * x : ℤ[i])).natAbs :=
norm_le_norm_mul_left _ fun hx0 =>
show (1 : ℤ) ≠ 0 by decide <| by simpa [hx0] using congr_arg Zsqrtd.im hx
obtain ⟨y, hy⟩ := hpk
have := hpi.2.2 ⟨k, 1⟩ ⟨k, -1⟩ ⟨y, by rw [← hkmul, ← Nat.cast_mul p, ← hy]; simp⟩
clear_aux_decl
tauto
theorem prime_of_nat_prime_of_mod_four_eq_three (p : ℕ) [hp : Fact p.Prime] (hp3 : p % 4 = 3) :
Prime (p : ℤ[i]) :=
irreducible_iff_prime.1 <|
by_contradiction fun hpi =>
let ⟨a, b, hab⟩ := sq_add_sq_of_nat_prime_of_not_irreducible p hpi
have : ∀ a b : ZMod 4, a ^ 2 + b ^ 2 ≠ (p : ZMod 4) := by
erw [← ZMod.natCast_mod p 4, hp3]; decide
this a b (hab ▸ by simp)
/-- A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4` -/
theorem prime_iff_mod_four_eq_three_of_nat_prime (p : ℕ) [Fact p.Prime] :
Prime (p : ℤ[i]) ↔ p % 4 = 3 :=
⟨mod_four_eq_three_of_nat_prime_of_prime p, prime_of_nat_prime_of_mod_four_eq_three p⟩
end GaussianInt
|
NumberTheory\Zsqrtd\ToReal.lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Data.Real.Sqrt
import Mathlib.NumberTheory.Zsqrtd.Basic
/-!
# Image of `Zsqrtd` in `ℝ`
This file defines `Zsqrtd.toReal` and related lemmas.
It is in a separate file to avoid pulling in all of `Data.Real` into `Data.Zsqrtd`.
-/
namespace Zsqrtd
/-- The image of `Zsqrtd` in `ℝ`, using `Real.sqrt` which takes the positive root of `d`.
If the negative root is desired, use `toReal h (star a)`. -/
@[simps!]
noncomputable def toReal {d : ℤ} (h : 0 ≤ d) : ℤ√d →+* ℝ :=
lift ⟨√↑d, Real.mul_self_sqrt (Int.cast_nonneg.mpr h)⟩
theorem toReal_injective {d : ℤ} (h0d : 0 ≤ d) (hd : ∀ n : ℤ, d ≠ n * n) :
Function.Injective (toReal h0d) :=
lift_injective _ hd
end Zsqrtd
|
Order\Antichain.lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Set.Pairwise.Basic
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Directed
import Mathlib.Order.Hom.Set
/-!
# Antichains
This file defines antichains. An antichain is a set where any two distinct elements are not related.
If the relation is `(≤)`, this corresponds to incomparability and usual order antichains. If the
relation is `G.adj` for `G : SimpleGraph α`, this corresponds to independent sets of `G`.
## Definitions
* `IsAntichain r s`: Any two elements of `s : Set α` are unrelated by `r : α → α → Prop`.
* `IsStrongAntichain r s`: Any two elements of `s : Set α` are not related by `r : α → α → Prop`
to a common element.
* `IsAntichain.mk r s`: Turns `s` into an antichain by keeping only the "maximal" elements.
-/
open Function Set
section General
variable {α β : Type*} {r r₁ r₂ : α → α → Prop} {r' : β → β → Prop} {s t : Set α} {a b : α}
protected theorem Symmetric.compl (h : Symmetric r) : Symmetric rᶜ := fun _ _ hr hr' =>
hr <| h hr'
/-- An antichain is a set such that no two distinct elements are related. -/
def IsAntichain (r : α → α → Prop) (s : Set α) : Prop :=
s.Pairwise rᶜ
namespace IsAntichain
protected theorem subset (hs : IsAntichain r s) (h : t ⊆ s) : IsAntichain r t :=
hs.mono h
theorem mono (hs : IsAntichain r₁ s) (h : r₂ ≤ r₁) : IsAntichain r₂ s :=
hs.mono' <| compl_le_compl h
theorem mono_on (hs : IsAntichain r₁ s) (h : s.Pairwise fun ⦃a b⦄ => r₂ a b → r₁ a b) :
IsAntichain r₂ s :=
hs.imp_on <| h.imp fun _ _ h h₁ h₂ => h₁ <| h h₂
protected theorem eq (hs : IsAntichain r s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) (h : r a b) :
a = b :=
Set.Pairwise.eq hs ha hb <| not_not_intro h
protected theorem eq' (hs : IsAntichain r s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) (h : r b a) :
a = b :=
(hs.eq hb ha h).symm
protected theorem isAntisymm (h : IsAntichain r univ) : IsAntisymm α r :=
⟨fun _ _ ha _ => h.eq trivial trivial ha⟩
protected theorem subsingleton [IsTrichotomous α r] (h : IsAntichain r s) : s.Subsingleton := by
rintro a ha b hb
obtain hab | hab | hab := trichotomous_of r a b
· exact h.eq ha hb hab
· exact hab
· exact h.eq' ha hb hab
protected theorem flip (hs : IsAntichain r s) : IsAntichain (flip r) s := fun _ ha _ hb h =>
hs hb ha h.symm
theorem swap (hs : IsAntichain r s) : IsAntichain (swap r) s :=
hs.flip
theorem image (hs : IsAntichain r s) (f : α → β) (h : ∀ ⦃a b⦄, r' (f a) (f b) → r a b) :
IsAntichain r' (f '' s) := by
rintro _ ⟨b, hb, rfl⟩ _ ⟨c, hc, rfl⟩ hbc hr
exact hs hb hc (ne_of_apply_ne _ hbc) (h hr)
theorem preimage (hs : IsAntichain r s) {f : β → α} (hf : Injective f)
(h : ∀ ⦃a b⦄, r' a b → r (f a) (f b)) : IsAntichain r' (f ⁻¹' s) := fun _ hb _ hc hbc hr =>
hs hb hc (hf.ne hbc) <| h hr
theorem _root_.isAntichain_insert :
IsAntichain r (insert a s) ↔ IsAntichain r s ∧ ∀ ⦃b⦄, b ∈ s → a ≠ b → ¬r a b ∧ ¬r b a :=
Set.pairwise_insert
protected theorem insert (hs : IsAntichain r s) (hl : ∀ ⦃b⦄, b ∈ s → a ≠ b → ¬r b a)
(hr : ∀ ⦃b⦄, b ∈ s → a ≠ b → ¬r a b) : IsAntichain r (insert a s) :=
isAntichain_insert.2 ⟨hs, fun _ hb hab => ⟨hr hb hab, hl hb hab⟩⟩
theorem _root_.isAntichain_insert_of_symmetric (hr : Symmetric r) :
IsAntichain r (insert a s) ↔ IsAntichain r s ∧ ∀ ⦃b⦄, b ∈ s → a ≠ b → ¬r a b :=
pairwise_insert_of_symmetric hr.compl
theorem insert_of_symmetric (hs : IsAntichain r s) (hr : Symmetric r)
(h : ∀ ⦃b⦄, b ∈ s → a ≠ b → ¬r a b) : IsAntichain r (insert a s) :=
(isAntichain_insert_of_symmetric hr).2 ⟨hs, h⟩
theorem image_relEmbedding (hs : IsAntichain r s) (φ : r ↪r r') : IsAntichain r' (φ '' s) := by
intro b hb b' hb' h₁ h₂
rw [Set.mem_image] at hb hb'
obtain ⟨⟨a, has, rfl⟩, ⟨a', has', rfl⟩⟩ := hb, hb'
exact hs has has' (fun haa' => h₁ (by rw [haa'])) (φ.map_rel_iff.mp h₂)
theorem preimage_relEmbedding {t : Set β} (ht : IsAntichain r' t) (φ : r ↪r r') :
IsAntichain r (φ ⁻¹' t) := fun _ ha _s ha' hne hle =>
ht ha ha' (fun h => hne (φ.injective h)) (φ.map_rel_iff.mpr hle)
theorem image_relIso (hs : IsAntichain r s) (φ : r ≃r r') : IsAntichain r' (φ '' s) :=
hs.image_relEmbedding φ
theorem preimage_relIso {t : Set β} (hs : IsAntichain r' t) (φ : r ≃r r') :
IsAntichain r (φ ⁻¹' t) :=
hs.preimage_relEmbedding φ
theorem image_relEmbedding_iff {φ : r ↪r r'} : IsAntichain r' (φ '' s) ↔ IsAntichain r s :=
⟨fun h => (φ.injective.preimage_image s).subst (h.preimage_relEmbedding φ), fun h =>
h.image_relEmbedding φ⟩
theorem image_relIso_iff {φ : r ≃r r'} : IsAntichain r' (φ '' s) ↔ IsAntichain r s :=
@image_relEmbedding_iff _ _ _ _ _ (φ : r ↪r r')
theorem image_embedding [LE α] [LE β] (hs : IsAntichain (· ≤ ·) s) (φ : α ↪o β) :
IsAntichain (· ≤ ·) (φ '' s) :=
image_relEmbedding hs _
theorem preimage_embedding [LE α] [LE β] {t : Set β} (ht : IsAntichain (· ≤ ·) t) (φ : α ↪o β) :
IsAntichain (· ≤ ·) (φ ⁻¹' t) :=
preimage_relEmbedding ht _
theorem image_embedding_iff [LE α] [LE β] {φ : α ↪o β} :
IsAntichain (· ≤ ·) (φ '' s) ↔ IsAntichain (· ≤ ·) s :=
image_relEmbedding_iff
theorem image_iso [LE α] [LE β] (hs : IsAntichain (· ≤ ·) s) (φ : α ≃o β) :
IsAntichain (· ≤ ·) (φ '' s) :=
image_relEmbedding hs _
theorem image_iso_iff [LE α] [LE β] {φ : α ≃o β} :
IsAntichain (· ≤ ·) (φ '' s) ↔ IsAntichain (· ≤ ·) s :=
image_relEmbedding_iff
theorem preimage_iso [LE α] [LE β] {t : Set β} (ht : IsAntichain (· ≤ ·) t) (φ : α ≃o β) :
IsAntichain (· ≤ ·) (φ ⁻¹' t) :=
preimage_relEmbedding ht _
theorem preimage_iso_iff [LE α] [LE β] {t : Set β} {φ : α ≃o β} :
IsAntichain (· ≤ ·) (φ ⁻¹' t) ↔ IsAntichain (· ≤ ·) t :=
⟨fun h => (φ.image_preimage t).subst (h.image_iso φ), fun h => h.preimage_iso _⟩
theorem to_dual [LE α] (hs : IsAntichain (· ≤ ·) s) : @IsAntichain αᵒᵈ (· ≤ ·) s :=
fun _ ha _ hb hab => hs hb ha hab.symm
theorem to_dual_iff [LE α] : IsAntichain (· ≤ ·) s ↔ @IsAntichain αᵒᵈ (· ≤ ·) s :=
⟨to_dual, to_dual⟩
theorem image_compl [BooleanAlgebra α] (hs : IsAntichain (· ≤ ·) s) :
IsAntichain (· ≤ ·) (compl '' s) :=
(hs.image_embedding (OrderIso.compl α).toOrderEmbedding).flip
theorem preimage_compl [BooleanAlgebra α] (hs : IsAntichain (· ≤ ·) s) :
IsAntichain (· ≤ ·) (compl ⁻¹' s) := fun _ ha _ ha' hne hle =>
hs ha' ha (fun h => hne (compl_inj_iff.mp h.symm)) (compl_le_compl hle)
end IsAntichain
theorem isAntichain_singleton (a : α) (r : α → α → Prop) : IsAntichain r {a} :=
pairwise_singleton _ _
theorem Set.Subsingleton.isAntichain (hs : s.Subsingleton) (r : α → α → Prop) : IsAntichain r s :=
hs.pairwise _
section Preorder
variable [Preorder α]
theorem IsAntichain.not_lt (hs : IsAntichain (· ≤ ·) s) (ha : a ∈ s) (hb : b ∈ s) : ¬a < b :=
fun h => hs ha hb h.ne h.le
theorem isAntichain_and_least_iff : IsAntichain (· ≤ ·) s ∧ IsLeast s a ↔ s = {a} :=
⟨fun h => eq_singleton_iff_unique_mem.2 ⟨h.2.1, fun b hb => h.1.eq' hb h.2.1 (h.2.2 hb)⟩, by
rintro rfl
exact ⟨isAntichain_singleton _ _, isLeast_singleton⟩⟩
theorem isAntichain_and_greatest_iff : IsAntichain (· ≤ ·) s ∧ IsGreatest s a ↔ s = {a} :=
⟨fun h => eq_singleton_iff_unique_mem.2 ⟨h.2.1, fun b hb => h.1.eq hb h.2.1 (h.2.2 hb)⟩, by
rintro rfl
exact ⟨isAntichain_singleton _ _, isGreatest_singleton⟩⟩
theorem IsAntichain.least_iff (hs : IsAntichain (· ≤ ·) s) : IsLeast s a ↔ s = {a} :=
(and_iff_right hs).symm.trans isAntichain_and_least_iff
theorem IsAntichain.greatest_iff (hs : IsAntichain (· ≤ ·) s) : IsGreatest s a ↔ s = {a} :=
(and_iff_right hs).symm.trans isAntichain_and_greatest_iff
theorem IsLeast.antichain_iff (hs : IsLeast s a) : IsAntichain (· ≤ ·) s ↔ s = {a} :=
(and_iff_left hs).symm.trans isAntichain_and_least_iff
theorem IsGreatest.antichain_iff (hs : IsGreatest s a) : IsAntichain (· ≤ ·) s ↔ s = {a} :=
(and_iff_left hs).symm.trans isAntichain_and_greatest_iff
theorem IsAntichain.bot_mem_iff [OrderBot α] (hs : IsAntichain (· ≤ ·) s) : ⊥ ∈ s ↔ s = {⊥} :=
isLeast_bot_iff.symm.trans hs.least_iff
theorem IsAntichain.top_mem_iff [OrderTop α] (hs : IsAntichain (· ≤ ·) s) : ⊤ ∈ s ↔ s = {⊤} :=
isGreatest_top_iff.symm.trans hs.greatest_iff
end Preorder
section PartialOrder
variable [PartialOrder α]
theorem isAntichain_iff_forall_not_lt :
IsAntichain (· ≤ ·) s ↔ ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → ¬a < b :=
⟨fun hs _ ha _ => hs.not_lt ha, fun hs _ ha _ hb h h' => hs ha hb <| h'.lt_of_ne h⟩
end PartialOrder
/-! ### Strong antichains -/
/-- A strong (upward) antichain is a set such that no two distinct elements are related to a common
element. -/
def IsStrongAntichain (r : α → α → Prop) (s : Set α) : Prop :=
s.Pairwise fun a b => ∀ c, ¬r a c ∨ ¬r b c
namespace IsStrongAntichain
protected theorem subset (hs : IsStrongAntichain r s) (h : t ⊆ s) : IsStrongAntichain r t :=
hs.mono h
theorem mono (hs : IsStrongAntichain r₁ s) (h : r₂ ≤ r₁) : IsStrongAntichain r₂ s :=
hs.mono' fun _ _ hab c => (hab c).imp (compl_le_compl h _ _) (compl_le_compl h _ _)
theorem eq (hs : IsStrongAntichain r s) {a b c : α} (ha : a ∈ s) (hb : b ∈ s) (hac : r a c)
(hbc : r b c) : a = b :=
(Set.Pairwise.eq hs ha hb) fun h =>
False.elim <| (h c).elim (not_not_intro hac) (not_not_intro hbc)
protected theorem isAntichain [IsRefl α r] (h : IsStrongAntichain r s) : IsAntichain r s :=
h.imp fun _ b hab => (hab b).resolve_right (not_not_intro <| refl _)
protected theorem subsingleton [IsDirected α r] (h : IsStrongAntichain r s) : s.Subsingleton :=
fun a ha b hb =>
let ⟨_, hac, hbc⟩ := directed_of r a b
h.eq ha hb hac hbc
protected theorem flip [IsSymm α r] (hs : IsStrongAntichain r s) : IsStrongAntichain (flip r) s :=
fun _ ha _ hb h c => (hs ha hb h c).imp (mt <| symm_of r) (mt <| symm_of r)
theorem swap [IsSymm α r] (hs : IsStrongAntichain r s) : IsStrongAntichain (swap r) s :=
hs.flip
theorem image (hs : IsStrongAntichain r s) {f : α → β} (hf : Surjective f)
(h : ∀ a b, r' (f a) (f b) → r a b) : IsStrongAntichain r' (f '' s) := by
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ hab c
obtain ⟨c, rfl⟩ := hf c
exact (hs ha hb (ne_of_apply_ne _ hab) _).imp (mt <| h _ _) (mt <| h _ _)
theorem preimage (hs : IsStrongAntichain r s) {f : β → α} (hf : Injective f)
(h : ∀ a b, r' a b → r (f a) (f b)) : IsStrongAntichain r' (f ⁻¹' s) := fun _ ha _ hb hab _ =>
(hs ha hb (hf.ne hab) _).imp (mt <| h _ _) (mt <| h _ _)
theorem _root_.isStrongAntichain_insert :
IsStrongAntichain r (insert a s) ↔
IsStrongAntichain r s ∧ ∀ ⦃b⦄, b ∈ s → a ≠ b → ∀ c, ¬r a c ∨ ¬r b c :=
Set.pairwise_insert_of_symmetric fun _ _ h c => (h c).symm
protected theorem insert (hs : IsStrongAntichain r s)
(h : ∀ ⦃b⦄, b ∈ s → a ≠ b → ∀ c, ¬r a c ∨ ¬r b c) : IsStrongAntichain r (insert a s) :=
isStrongAntichain_insert.2 ⟨hs, h⟩
end IsStrongAntichain
theorem Set.Subsingleton.isStrongAntichain (hs : s.Subsingleton) (r : α → α → Prop) :
IsStrongAntichain r s :=
hs.pairwise _
variable [PartialOrder α] [PartialOrder β] {f : α → β} {s : Set α}
lemma IsAntichain.of_strictMonoOn_antitoneOn (hf : StrictMonoOn f s) (hf' : AntitoneOn f s) :
IsAntichain (· ≤ ·) s :=
fun _a ha _b hb hab' hab ↦ (hf ha hb $ hab.lt_of_ne hab').not_le (hf' ha hb hab)
lemma IsAntichain.of_monotoneOn_strictAntiOn (hf : MonotoneOn f s) (hf' : StrictAntiOn f s) :
IsAntichain (· ≤ ·) s :=
fun _a ha _b hb hab' hab ↦ (hf ha hb hab).not_lt (hf' ha hb $ hab.lt_of_ne hab')
end General
/-! ### Weak antichains -/
section Pi
variable {ι : Type*} {α : ι → Type*} [∀ i, Preorder (α i)] {s t : Set (∀ i, α i)}
{a b c : ∀ i, α i}
@[inherit_doc]
local infixl:50 " ≺ " => StrongLT
/-- A weak antichain in `Π i, α i` is a set such that no two distinct elements are strongly less
than each other. -/
def IsWeakAntichain (s : Set (∀ i, α i)) : Prop :=
IsAntichain (· ≺ ·) s
namespace IsWeakAntichain
protected theorem subset (hs : IsWeakAntichain s) : t ⊆ s → IsWeakAntichain t :=
IsAntichain.subset hs
protected theorem eq (hs : IsWeakAntichain s) : a ∈ s → b ∈ s → a ≺ b → a = b :=
IsAntichain.eq hs
protected theorem insert (hs : IsWeakAntichain s) :
(∀ ⦃b⦄, b ∈ s → a ≠ b → ¬b ≺ a) →
(∀ ⦃b⦄, b ∈ s → a ≠ b → ¬a ≺ b) → IsWeakAntichain (insert a s) :=
IsAntichain.insert hs
end IsWeakAntichain
theorem _root_.isWeakAntichain_insert :
IsWeakAntichain (insert a s) ↔ IsWeakAntichain s ∧ ∀ ⦃b⦄, b ∈ s → a ≠ b → ¬a ≺ b ∧ ¬b ≺ a :=
isAntichain_insert
protected theorem IsAntichain.isWeakAntichain (hs : IsAntichain (· ≤ ·) s) : IsWeakAntichain s :=
hs.mono fun _ _ => le_of_strongLT
theorem Set.Subsingleton.isWeakAntichain (hs : s.Subsingleton) : IsWeakAntichain s :=
hs.isAntichain _
end Pi
|
Order\Antisymmetrization.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Hom.Basic
import Mathlib.Logic.Relation
/-!
# Turning a preorder into a partial order
This file allows to make a preorder into a partial order by quotienting out the elements `a`, `b`
such that `a ≤ b` and `b ≤ a`.
`Antisymmetrization` is a functor from `Preorder` to `PartialOrder`. See `Preorder_to_PartialOrder`.
## Main declarations
* `AntisymmRel`: The antisymmetrization relation. `AntisymmRel r a b` means that `a` and `b` are
related both ways by `r`.
* `Antisymmetrization α r`: The quotient of `α` by `AntisymmRel r`. Even when `r` is just a
preorder, `Antisymmetrization α` is a partial order.
-/
/- Porting note: There are many changes from `toAntisymmetrization (· ≤ ·)` to
`@toAntisymmetrization α (· ≤ ·) _` -/
open Function OrderDual
variable {α β : Type*}
section Relation
variable (r : α → α → Prop)
/-- The antisymmetrization relation. -/
def AntisymmRel (a b : α) : Prop :=
r a b ∧ r b a
theorem antisymmRel_swap : AntisymmRel (swap r) = AntisymmRel r :=
funext fun _ => funext fun _ => propext and_comm
@[refl]
theorem antisymmRel_refl [IsRefl α r] (a : α) : AntisymmRel r a a :=
⟨refl _, refl _⟩
variable {r}
@[symm]
theorem AntisymmRel.symm {a b : α} : AntisymmRel r a b → AntisymmRel r b a :=
And.symm
@[trans]
theorem AntisymmRel.trans [IsTrans α r] {a b c : α} (hab : AntisymmRel r a b)
(hbc : AntisymmRel r b c) : AntisymmRel r a c :=
⟨_root_.trans hab.1 hbc.1, _root_.trans hbc.2 hab.2⟩
instance AntisymmRel.decidableRel [DecidableRel r] : DecidableRel (AntisymmRel r) := fun _ _ =>
instDecidableAnd
@[simp]
theorem antisymmRel_iff_eq [IsRefl α r] [IsAntisymm α r] {a b : α} : AntisymmRel r a b ↔ a = b :=
antisymm_iff
alias ⟨AntisymmRel.eq, _⟩ := antisymmRel_iff_eq
end Relation
section IsPreorder
variable (α) (r : α → α → Prop) [IsPreorder α r]
/-- The antisymmetrization relation as an equivalence relation. -/
@[simps]
def AntisymmRel.setoid : Setoid α :=
⟨AntisymmRel r, antisymmRel_refl _, AntisymmRel.symm, AntisymmRel.trans⟩
/-- The partial order derived from a preorder by making pairwise comparable elements equal. This is
the quotient by `fun a b => a ≤ b ∧ b ≤ a`. -/
def Antisymmetrization : Type _ :=
Quotient <| AntisymmRel.setoid α r
variable {α}
/-- Turn an element into its antisymmetrization. -/
def toAntisymmetrization : α → Antisymmetrization α r :=
Quotient.mk _
/-- Get a representative from the antisymmetrization. -/
noncomputable def ofAntisymmetrization : Antisymmetrization α r → α :=
Quotient.out'
instance [Inhabited α] : Inhabited (Antisymmetrization α r) := by
unfold Antisymmetrization; infer_instance
@[elab_as_elim]
protected theorem Antisymmetrization.ind {p : Antisymmetrization α r → Prop} :
(∀ a, p <| toAntisymmetrization r a) → ∀ q, p q :=
Quot.ind
@[elab_as_elim]
protected theorem Antisymmetrization.induction_on {p : Antisymmetrization α r → Prop}
(a : Antisymmetrization α r) (h : ∀ a, p <| toAntisymmetrization r a) : p a :=
Quotient.inductionOn' a h
@[simp]
theorem toAntisymmetrization_ofAntisymmetrization (a : Antisymmetrization α r) :
toAntisymmetrization r (ofAntisymmetrization r a) = a :=
Quotient.out_eq' _
end IsPreorder
section Preorder
variable [Preorder α] [Preorder β] {a b : α}
theorem AntisymmRel.image {a b : α} (h : AntisymmRel (· ≤ ·) a b) {f : α → β} (hf : Monotone f) :
AntisymmRel (· ≤ ·) (f a) (f b) :=
⟨hf h.1, hf h.2⟩
instance instPartialOrderAntisymmetrization : PartialOrder (Antisymmetrization α (· ≤ ·)) where
le a b :=
(Quotient.liftOn₂' a b (· ≤ ·)) fun (_ _ _ _ : α) h₁ h₂ =>
propext ⟨fun h => h₁.2.trans <| h.trans h₂.1, fun h => h₁.1.trans <| h.trans h₂.2⟩
lt a b :=
(Quotient.liftOn₂' a b (· < ·)) fun (_ _ _ _ : α) h₁ h₂ =>
propext ⟨fun h => h₁.2.trans_lt <| h.trans_le h₂.1, fun h =>
h₁.1.trans_lt <| h.trans_le h₂.2⟩
le_refl a := Quotient.inductionOn' a <| le_refl
le_trans a b c := Quotient.inductionOn₃' a b c fun _ _ _ => le_trans
lt_iff_le_not_le a b := Quotient.inductionOn₂' a b fun _ _ => lt_iff_le_not_le
le_antisymm a b := Quotient.inductionOn₂' a b fun _ _ hab hba => Quotient.sound' ⟨hab, hba⟩
theorem antisymmetrization_fibration :
Relation.Fibration (· < ·) (· < ·) (@toAntisymmetrization α (· ≤ ·) _) := by
rintro a ⟨b⟩ h
exact ⟨b, h, rfl⟩
theorem acc_antisymmetrization_iff : Acc (· < ·)
(@toAntisymmetrization α (· ≤ ·) _ a) ↔ Acc (· < ·) a :=
acc_liftOn₂'_iff
theorem wellFounded_antisymmetrization_iff :
WellFounded (@LT.lt (Antisymmetrization α (· ≤ ·)) _) ↔ WellFounded (@LT.lt α _) :=
wellFounded_liftOn₂'_iff
instance [WellFoundedLT α] : WellFoundedLT (Antisymmetrization α (· ≤ ·)) :=
⟨wellFounded_antisymmetrization_iff.2 IsWellFounded.wf⟩
instance [@DecidableRel α (· ≤ ·)] [@DecidableRel α (· < ·)] [IsTotal α (· ≤ ·)] :
LinearOrder (Antisymmetrization α (· ≤ ·)) :=
{ instPartialOrderAntisymmetrization with
le_total := fun a b => Quotient.inductionOn₂' a b <| total_of (· ≤ ·),
decidableLE := fun _ _ => show Decidable (Quotient.liftOn₂' _ _ _ _) from inferInstance,
decidableLT := fun _ _ => show Decidable (Quotient.liftOn₂' _ _ _ _) from inferInstance }
@[simp]
theorem toAntisymmetrization_le_toAntisymmetrization_iff :
@toAntisymmetrization α (· ≤ ·) _ a ≤ @toAntisymmetrization α (· ≤ ·) _ b ↔ a ≤ b :=
Iff.rfl
@[simp]
theorem toAntisymmetrization_lt_toAntisymmetrization_iff :
@toAntisymmetrization α (· ≤ ·) _ a < @toAntisymmetrization α (· ≤ ·) _ b ↔ a < b :=
Iff.rfl
@[simp]
theorem ofAntisymmetrization_le_ofAntisymmetrization_iff {a b : Antisymmetrization α (· ≤ ·)} :
ofAntisymmetrization (· ≤ ·) a ≤ ofAntisymmetrization (· ≤ ·) b ↔ a ≤ b :=
(Quotient.out'RelEmbedding _).map_rel_iff
@[simp]
theorem ofAntisymmetrization_lt_ofAntisymmetrization_iff {a b : Antisymmetrization α (· ≤ ·)} :
ofAntisymmetrization (· ≤ ·) a < ofAntisymmetrization (· ≤ ·) b ↔ a < b :=
(Quotient.out'RelEmbedding _).map_rel_iff
@[mono]
theorem toAntisymmetrization_mono : Monotone (@toAntisymmetrization α (· ≤ ·) _) := fun _ _ => id
private theorem liftFun_antisymmRel (f : α →o β) :
((AntisymmRel.setoid α (· ≤ ·)).r ⇒ (AntisymmRel.setoid β (· ≤ ·)).r) f f := fun _ _ h =>
⟨f.mono h.1, f.mono h.2⟩
/-- Turns an order homomorphism from `α` to `β` into one from `Antisymmetrization α` to
`Antisymmetrization β`. `Antisymmetrization` is actually a functor. See `Preorder_to_PartialOrder`.
-/
protected def OrderHom.antisymmetrization (f : α →o β) :
Antisymmetrization α (· ≤ ·) →o Antisymmetrization β (· ≤ ·) :=
⟨Quotient.map' f <| liftFun_antisymmRel f, fun a b => Quotient.inductionOn₂' a b <| f.mono⟩
@[simp]
theorem OrderHom.coe_antisymmetrization (f : α →o β) :
⇑f.antisymmetrization = Quotient.map' f (liftFun_antisymmRel f) :=
rfl
/- Porting note: Removed @[simp] attribute. With this `simp` lemma the LHS of
`OrderHom.antisymmetrization_apply_mk` is not in normal-form -/
theorem OrderHom.antisymmetrization_apply (f : α →o β) (a : Antisymmetrization α (· ≤ ·)) :
f.antisymmetrization a = Quotient.map' f (liftFun_antisymmRel f) a :=
rfl
@[simp]
theorem OrderHom.antisymmetrization_apply_mk (f : α →o β) (a : α) :
f.antisymmetrization (toAntisymmetrization _ a) = toAntisymmetrization _ (f a) :=
@Quotient.map_mk _ _ (_root_.id _) (_root_.id _) f (liftFun_antisymmRel f) _
variable (α)
/-- `ofAntisymmetrization` as an order embedding. -/
@[simps]
noncomputable def OrderEmbedding.ofAntisymmetrization : Antisymmetrization α (· ≤ ·) ↪o α :=
{ Quotient.out'RelEmbedding _ with toFun := _root_.ofAntisymmetrization _ }
/-- `Antisymmetrization` and `orderDual` commute. -/
def OrderIso.dualAntisymmetrization :
(Antisymmetrization α (· ≤ ·))ᵒᵈ ≃o Antisymmetrization αᵒᵈ (· ≤ ·) where
toFun := (Quotient.map' id) fun _ _ => And.symm
invFun := (Quotient.map' id) fun _ _ => And.symm
left_inv a := Quotient.inductionOn' a fun a => by simp_rw [Quotient.map'_mk'', id]
right_inv a := Quotient.inductionOn' a fun a => by simp_rw [Quotient.map'_mk'', id]
map_rel_iff' := @fun a b => Quotient.inductionOn₂' a b fun a b => Iff.rfl
@[simp]
theorem OrderIso.dualAntisymmetrization_apply (a : α) :
OrderIso.dualAntisymmetrization _ (toDual <| toAntisymmetrization _ a) =
toAntisymmetrization _ (toDual a) :=
rfl
@[simp]
theorem OrderIso.dualAntisymmetrization_symm_apply (a : α) :
(OrderIso.dualAntisymmetrization _).symm (toAntisymmetrization _ <| toDual a) =
toDual (toAntisymmetrization _ a) :=
rfl
end Preorder
|
Order\Atoms.lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Data.Set.Lattice
import Mathlib.Order.ModularLattice
import Mathlib.Order.SuccPred.Basic
import Mathlib.Order.WellFounded
import Mathlib.Tactic.Nontriviality
/-!
# Atoms, Coatoms, and Simple Lattices
This module defines atoms, which are minimal non-`⊥` elements in bounded lattices, simple lattices,
which are lattices with only two elements, and related ideas.
## Main definitions
### Atoms and Coatoms
* `IsAtom a` indicates that the only element below `a` is `⊥`.
* `IsCoatom a` indicates that the only element above `a` is `⊤`.
### Atomic and Atomistic Lattices
* `IsAtomic` indicates that every element other than `⊥` is above an atom.
* `IsCoatomic` indicates that every element other than `⊤` is below a coatom.
* `IsAtomistic` indicates that every element is the `sSup` of a set of atoms.
* `IsCoatomistic` indicates that every element is the `sInf` of a set of coatoms.
* `IsStronglyAtomic` indicates that for all `a < b`, there is some `x` with `a ⋖ x ≤ b`.
* `IsStronglyCoatomic` indicates that for all `a < b`, there is some `x` with `a ≤ x ⋖ b`.
### Simple Lattices
* `IsSimpleOrder` indicates that an order has only two unique elements, `⊥` and `⊤`.
* `IsSimpleOrder.boundedOrder`
* `IsSimpleOrder.distribLattice`
* Given an instance of `IsSimpleOrder`, we provide the following definitions. These are not
made global instances as they contain data :
* `IsSimpleOrder.booleanAlgebra`
* `IsSimpleOrder.completeLattice`
* `IsSimpleOrder.completeBooleanAlgebra`
## Main results
* `isAtom_dual_iff_isCoatom` and `isCoatom_dual_iff_isAtom` express the (definitional) duality
of `IsAtom` and `IsCoatom`.
* `isSimpleOrder_iff_isAtom_top` and `isSimpleOrder_iff_isCoatom_bot` express the
connection between atoms, coatoms, and simple lattices
* `IsCompl.isAtom_iff_isCoatom` and `IsCompl.isCoatom_if_isAtom`: In a modular
bounded lattice, a complement of an atom is a coatom and vice versa.
* `isAtomic_iff_isCoatomic`: A modular complemented lattice is atomic iff it is coatomic.
-/
variable {ι : Sort*} {α β : Type*}
section Atoms
section IsAtom
section Preorder
variable [Preorder α] [OrderBot α] {a b x : α}
/-- An atom of an `OrderBot` is an element with no other element between it and `⊥`,
which is not `⊥`. -/
def IsAtom (a : α) : Prop :=
a ≠ ⊥ ∧ ∀ b, b < a → b = ⊥
theorem IsAtom.Iic (ha : IsAtom a) (hax : a ≤ x) : IsAtom (⟨a, hax⟩ : Set.Iic x) :=
⟨fun con => ha.1 (Subtype.mk_eq_mk.1 con), fun ⟨b, _⟩ hba => Subtype.mk_eq_mk.2 (ha.2 b hba)⟩
theorem IsAtom.of_isAtom_coe_Iic {a : Set.Iic x} (ha : IsAtom a) : IsAtom (a : α) :=
⟨fun con => ha.1 (Subtype.ext con), fun b hba =>
Subtype.mk_eq_mk.1 (ha.2 ⟨b, hba.le.trans a.prop⟩ hba)⟩
theorem isAtom_iff_le_of_ge : IsAtom a ↔ a ≠ ⊥ ∧ ∀ b ≠ ⊥, b ≤ a → a ≤ b :=
and_congr Iff.rfl <|
forall_congr' fun b => by
simp only [Ne, @not_imp_comm (b = ⊥), Classical.not_imp, lt_iff_le_not_le]
end Preorder
section PartialOrder
variable [PartialOrder α] [OrderBot α] {a b x : α}
theorem IsAtom.lt_iff (h : IsAtom a) : x < a ↔ x = ⊥ :=
⟨h.2 x, fun hx => hx.symm ▸ h.1.bot_lt⟩
theorem IsAtom.le_iff (h : IsAtom a) : x ≤ a ↔ x = ⊥ ∨ x = a := by rw [le_iff_lt_or_eq, h.lt_iff]
lemma IsAtom.le_iff_eq (ha : IsAtom a) (hb : b ≠ ⊥) : b ≤ a ↔ b = a :=
ha.le_iff.trans <| or_iff_right hb
theorem IsAtom.Iic_eq (h : IsAtom a) : Set.Iic a = {⊥, a} :=
Set.ext fun _ => h.le_iff
@[simp]
theorem bot_covBy_iff : ⊥ ⋖ a ↔ IsAtom a := by
simp only [CovBy, bot_lt_iff_ne_bot, IsAtom, not_imp_not]
alias ⟨CovBy.is_atom, IsAtom.bot_covBy⟩ := bot_covBy_iff
end PartialOrder
theorem atom_le_iSup [Order.Frame α] {a : α} (ha : IsAtom a) {f : ι → α} :
a ≤ iSup f ↔ ∃ i, a ≤ f i := by
refine ⟨?_, fun ⟨i, hi⟩ => le_trans hi (le_iSup _ _)⟩
show (a ≤ ⨆ i, f i) → _
refine fun h => of_not_not fun ha' => ?_
push_neg at ha'
have ha'' : Disjoint a (⨆ i, f i) :=
disjoint_iSup_iff.2 fun i => fun x hxa hxf => le_bot_iff.2 <| of_not_not fun hx =>
have hxa : x < a := (le_iff_eq_or_lt.1 hxa).resolve_left (by rintro rfl; exact ha' _ hxf)
hx (ha.2 _ hxa)
obtain rfl := le_bot_iff.1 (ha'' le_rfl h)
exact ha.1 rfl
end IsAtom
section IsCoatom
section Preorder
variable [Preorder α]
/-- A coatom of an `OrderTop` is an element with no other element between it and `⊤`,
which is not `⊤`. -/
def IsCoatom [OrderTop α] (a : α) : Prop :=
a ≠ ⊤ ∧ ∀ b, a < b → b = ⊤
@[simp]
theorem isCoatom_dual_iff_isAtom [OrderBot α] {a : α} :
IsCoatom (OrderDual.toDual a) ↔ IsAtom a :=
Iff.rfl
@[simp]
theorem isAtom_dual_iff_isCoatom [OrderTop α] {a : α} :
IsAtom (OrderDual.toDual a) ↔ IsCoatom a :=
Iff.rfl
alias ⟨_, IsAtom.dual⟩ := isCoatom_dual_iff_isAtom
alias ⟨_, IsCoatom.dual⟩ := isAtom_dual_iff_isCoatom
variable [OrderTop α] {a x : α}
theorem IsCoatom.Ici (ha : IsCoatom a) (hax : x ≤ a) : IsCoatom (⟨a, hax⟩ : Set.Ici x) :=
ha.dual.Iic hax
theorem IsCoatom.of_isCoatom_coe_Ici {a : Set.Ici x} (ha : IsCoatom a) : IsCoatom (a : α) :=
@IsAtom.of_isAtom_coe_Iic αᵒᵈ _ _ x a ha
theorem isCoatom_iff_ge_of_le : IsCoatom a ↔ a ≠ ⊤ ∧ ∀ b ≠ ⊤, a ≤ b → b ≤ a :=
isAtom_iff_le_of_ge (α := αᵒᵈ)
end Preorder
section PartialOrder
variable [PartialOrder α] [OrderTop α] {a b x : α}
theorem IsCoatom.lt_iff (h : IsCoatom a) : a < x ↔ x = ⊤ :=
h.dual.lt_iff
theorem IsCoatom.le_iff (h : IsCoatom a) : a ≤ x ↔ x = ⊤ ∨ x = a :=
h.dual.le_iff
lemma IsCoatom.le_iff_eq (ha : IsCoatom a) (hb : b ≠ ⊤) : a ≤ b ↔ b = a := ha.dual.le_iff_eq hb
theorem IsCoatom.Ici_eq (h : IsCoatom a) : Set.Ici a = {⊤, a} :=
h.dual.Iic_eq
@[simp]
theorem covBy_top_iff : a ⋖ ⊤ ↔ IsCoatom a :=
toDual_covBy_toDual_iff.symm.trans bot_covBy_iff
alias ⟨CovBy.isCoatom, IsCoatom.covBy_top⟩ := covBy_top_iff
end PartialOrder
theorem iInf_le_coatom [Order.Coframe α] {a : α} (ha : IsCoatom a) {f : ι → α} :
iInf f ≤ a ↔ ∃ i, f i ≤ a :=
atom_le_iSup (α := αᵒᵈ) ha
end IsCoatom
section PartialOrder
variable [PartialOrder α] {a b : α}
@[simp]
theorem Set.Ici.isAtom_iff {b : Set.Ici a} : IsAtom b ↔ a ⋖ b := by
rw [← bot_covBy_iff]
refine (Set.OrdConnected.apply_covBy_apply_iff (OrderEmbedding.subtype fun c => a ≤ c) ?_).symm
simpa only [OrderEmbedding.subtype_apply, Subtype.range_coe_subtype] using Set.ordConnected_Ici
@[simp]
theorem Set.Iic.isCoatom_iff {a : Set.Iic b} : IsCoatom a ↔ ↑a ⋖ b := by
rw [← covBy_top_iff]
refine (Set.OrdConnected.apply_covBy_apply_iff (OrderEmbedding.subtype fun c => c ≤ b) ?_).symm
simpa only [OrderEmbedding.subtype_apply, Subtype.range_coe_subtype] using Set.ordConnected_Iic
theorem covBy_iff_atom_Ici (h : a ≤ b) : a ⋖ b ↔ IsAtom (⟨b, h⟩ : Set.Ici a) := by simp
theorem covBy_iff_coatom_Iic (h : a ≤ b) : a ⋖ b ↔ IsCoatom (⟨a, h⟩ : Set.Iic b) := by simp
end PartialOrder
section Pairwise
theorem IsAtom.inf_eq_bot_of_ne [SemilatticeInf α] [OrderBot α] {a b : α} (ha : IsAtom a)
(hb : IsAtom b) (hab : a ≠ b) : a ⊓ b = ⊥ :=
hab.not_le_or_not_le.elim (ha.lt_iff.1 ∘ inf_lt_left.2) (hb.lt_iff.1 ∘ inf_lt_right.2)
theorem IsAtom.disjoint_of_ne [SemilatticeInf α] [OrderBot α] {a b : α} (ha : IsAtom a)
(hb : IsAtom b) (hab : a ≠ b) : Disjoint a b :=
disjoint_iff.mpr (IsAtom.inf_eq_bot_of_ne ha hb hab)
theorem IsCoatom.sup_eq_top_of_ne [SemilatticeSup α] [OrderTop α] {a b : α} (ha : IsCoatom a)
(hb : IsCoatom b) (hab : a ≠ b) : a ⊔ b = ⊤ :=
ha.dual.inf_eq_bot_of_ne hb.dual hab
end Pairwise
end Atoms
section Atomic
variable [PartialOrder α] (α)
/-- A lattice is atomic iff every element other than `⊥` has an atom below it. -/
@[mk_iff]
class IsAtomic [OrderBot α] : Prop where
/-- Every element other than `⊥` has an atom below it. -/
eq_bot_or_exists_atom_le : ∀ b : α, b = ⊥ ∨ ∃ a : α, IsAtom a ∧ a ≤ b
/-- A lattice is coatomic iff every element other than `⊤` has a coatom above it. -/
@[mk_iff]
class IsCoatomic [OrderTop α] : Prop where
/-- Every element other than `⊤` has an atom above it. -/
eq_top_or_exists_le_coatom : ∀ b : α, b = ⊤ ∨ ∃ a : α, IsCoatom a ∧ b ≤ a
export IsAtomic (eq_bot_or_exists_atom_le)
export IsCoatomic (eq_top_or_exists_le_coatom)
lemma IsAtomic.exists_atom [OrderBot α] [Nontrivial α] [IsAtomic α] : ∃ a : α, IsAtom a :=
have ⟨b, hb⟩ := exists_ne (⊥ : α)
have ⟨a, ha⟩ := (eq_bot_or_exists_atom_le b).resolve_left hb
⟨a, ha.1⟩
lemma IsCoatomic.exists_coatom [OrderTop α] [Nontrivial α] [IsCoatomic α] : ∃ a : α, IsCoatom a :=
have ⟨b, hb⟩ := exists_ne (⊤ : α)
have ⟨a, ha⟩ := (eq_top_or_exists_le_coatom b).resolve_left hb
⟨a, ha.1⟩
variable {α}
@[simp]
theorem isCoatomic_dual_iff_isAtomic [OrderBot α] : IsCoatomic αᵒᵈ ↔ IsAtomic α :=
⟨fun h => ⟨fun b => by apply h.eq_top_or_exists_le_coatom⟩, fun h =>
⟨fun b => by apply h.eq_bot_or_exists_atom_le⟩⟩
@[simp]
theorem isAtomic_dual_iff_isCoatomic [OrderTop α] : IsAtomic αᵒᵈ ↔ IsCoatomic α :=
⟨fun h => ⟨fun b => by apply h.eq_bot_or_exists_atom_le⟩, fun h =>
⟨fun b => by apply h.eq_top_or_exists_le_coatom⟩⟩
namespace IsAtomic
variable [OrderBot α] [IsAtomic α]
instance _root_.OrderDual.instIsCoatomic : IsCoatomic αᵒᵈ :=
isCoatomic_dual_iff_isAtomic.2 ‹IsAtomic α›
instance Set.Iic.isAtomic {x : α} : IsAtomic (Set.Iic x) :=
⟨fun ⟨y, hy⟩ =>
(eq_bot_or_exists_atom_le y).imp Subtype.mk_eq_mk.2 fun ⟨a, ha, hay⟩ =>
⟨⟨a, hay.trans hy⟩, ha.Iic (hay.trans hy), hay⟩⟩
end IsAtomic
namespace IsCoatomic
variable [OrderTop α] [IsCoatomic α]
instance _root_.OrderDual.instIsAtomic : IsAtomic αᵒᵈ :=
isAtomic_dual_iff_isCoatomic.2 ‹IsCoatomic α›
instance Set.Ici.isCoatomic {x : α} : IsCoatomic (Set.Ici x) :=
⟨fun ⟨y, hy⟩ =>
(eq_top_or_exists_le_coatom y).imp Subtype.mk_eq_mk.2 fun ⟨a, ha, hay⟩ =>
⟨⟨a, le_trans hy hay⟩, ha.Ici (le_trans hy hay), hay⟩⟩
end IsCoatomic
theorem isAtomic_iff_forall_isAtomic_Iic [OrderBot α] :
IsAtomic α ↔ ∀ x : α, IsAtomic (Set.Iic x) :=
⟨@IsAtomic.Set.Iic.isAtomic _ _ _, fun h =>
⟨fun x =>
((@eq_bot_or_exists_atom_le _ _ _ (h x)) (⊤ : Set.Iic x)).imp Subtype.mk_eq_mk.1
(Exists.imp' (↑) fun ⟨_, _⟩ => And.imp_left IsAtom.of_isAtom_coe_Iic)⟩⟩
theorem isCoatomic_iff_forall_isCoatomic_Ici [OrderTop α] :
IsCoatomic α ↔ ∀ x : α, IsCoatomic (Set.Ici x) :=
isAtomic_dual_iff_isCoatomic.symm.trans <|
isAtomic_iff_forall_isAtomic_Iic.trans <|
forall_congr' fun _ => isCoatomic_dual_iff_isAtomic.symm.trans Iff.rfl
section StronglyAtomic
variable {α : Type*} {a b : α} [Preorder α]
/-- An order is strongly atomic if every nontrivial interval `[a, b]`
contains an element covering `a`. -/
@[mk_iff]
class IsStronglyAtomic (α : Type*) [Preorder α] : Prop where
exists_covBy_le_of_lt : ∀ (a b : α), a < b → ∃ x, a ⋖ x ∧ x ≤ b
theorem exists_covBy_le_of_lt [IsStronglyAtomic α] (h : a < b) : ∃ x, a ⋖ x ∧ x ≤ b :=
IsStronglyAtomic.exists_covBy_le_of_lt a b h
alias LT.lt.exists_covby_le := exists_covBy_le_of_lt
/-- An order is strongly coatomic if every nontrivial interval `[a, b]`
contains an element covered by `b`. -/
@[mk_iff]
class IsStronglyCoatomic (α : Type*) [Preorder α] : Prop where
(exists_le_covBy_of_lt : ∀ (a b : α), a < b → ∃ x, a ≤ x ∧ x ⋖ b)
theorem exists_le_covBy_of_lt [IsStronglyCoatomic α] (h : a < b) : ∃ x, a ≤ x ∧ x ⋖ b :=
IsStronglyCoatomic.exists_le_covBy_of_lt a b h
alias LT.lt.exists_le_covby := exists_le_covBy_of_lt
theorem isStronglyAtomic_dual_iff_is_stronglyCoatomic :
IsStronglyAtomic αᵒᵈ ↔ IsStronglyCoatomic α := by
simpa [isStronglyAtomic_iff, OrderDual.exists, OrderDual.forall,
OrderDual.toDual_le_toDual, and_comm, isStronglyCoatomic_iff] using forall_comm
@[simp] theorem isStronglyCoatomic_dual_iff_is_stronglyAtomic :
IsStronglyCoatomic αᵒᵈ ↔ IsStronglyAtomic α := by
rw [← isStronglyAtomic_dual_iff_is_stronglyCoatomic]; rfl
instance OrderDual.instIsStronglyCoatomic [IsStronglyAtomic α] : IsStronglyCoatomic αᵒᵈ := by
rwa [isStronglyCoatomic_dual_iff_is_stronglyAtomic]
instance [IsStronglyCoatomic α] : IsStronglyAtomic αᵒᵈ := by
rwa [isStronglyAtomic_dual_iff_is_stronglyCoatomic]
instance IsStronglyAtomic.isAtomic (α : Type*) [PartialOrder α] [OrderBot α] [IsStronglyAtomic α] :
IsAtomic α where
eq_bot_or_exists_atom_le a := by
rw [or_iff_not_imp_left, ← Ne, ← bot_lt_iff_ne_bot]
refine fun hlt ↦ ?_
obtain ⟨x, hx, hxa⟩ := hlt.exists_covby_le
exact ⟨x, bot_covBy_iff.1 hx, hxa⟩
instance IsStronglyCoatomic.toIsCoatomic (α : Type*) [PartialOrder α] [OrderTop α]
[IsStronglyCoatomic α] : IsCoatomic α :=
isAtomic_dual_iff_isCoatomic.1 <| IsStronglyAtomic.isAtomic (α := αᵒᵈ)
theorem Set.OrdConnected.isStronglyAtomic [IsStronglyAtomic α] {s : Set α}
(h : Set.OrdConnected s) : IsStronglyAtomic s where
exists_covBy_le_of_lt := by
rintro ⟨c, hc⟩ ⟨d, hd⟩ hcd
obtain ⟨x, hcx, hxd⟩ := (Subtype.mk_lt_mk.1 hcd).exists_covby_le
exact ⟨⟨x, h.out' hc hd ⟨hcx.le, hxd⟩⟩,
⟨by simpa using hcx.lt, fun y hy hy' ↦ hcx.2 (by simpa using hy) (by simpa using hy')⟩, hxd⟩
theorem Set.OrdConnected.isStronglyCoatomic [IsStronglyCoatomic α] {s : Set α}
(h : Set.OrdConnected s) : IsStronglyCoatomic s :=
isStronglyAtomic_dual_iff_is_stronglyCoatomic.1 h.dual.isStronglyAtomic
instance [IsStronglyAtomic α] {s : Set α} [Set.OrdConnected s] : IsStronglyAtomic s :=
Set.OrdConnected.isStronglyAtomic <| by assumption
instance [IsStronglyCoatomic α] {s : Set α} [h : Set.OrdConnected s] : IsStronglyCoatomic s :=
Set.OrdConnected.isStronglyCoatomic <| by assumption
instance SuccOrder.toIsStronglyAtomic [SuccOrder α] : IsStronglyAtomic α where
exists_covBy_le_of_lt a _ hab :=
⟨SuccOrder.succ a, Order.covBy_succ_of_not_isMax fun ha ↦ ha.not_lt hab,
SuccOrder.succ_le_of_lt hab⟩
instance [PredOrder α] : IsStronglyCoatomic α := by
rw [← isStronglyAtomic_dual_iff_is_stronglyCoatomic]; infer_instance
end StronglyAtomic
section WellFounded
theorem IsStronglyAtomic.of_wellFounded_lt (h : WellFounded ((· < ·) : α → α → Prop)) :
IsStronglyAtomic α where
exists_covBy_le_of_lt a b hab := by
refine ⟨WellFounded.min h (Set.Ioc a b) ⟨b, hab,rfl.le⟩, ?_⟩
have hmem := (WellFounded.min_mem h (Set.Ioc a b) ⟨b, hab,rfl.le⟩)
exact ⟨⟨hmem.1,fun c hac hlt ↦ WellFounded.not_lt_min h
(Set.Ioc a b) ⟨b, hab,rfl.le⟩ ⟨hac, hlt.le.trans hmem.2⟩ hlt ⟩, hmem.2⟩
theorem IsStronglyCoatomic.of_wellFounded_gt (h : WellFounded ((· > ·) : α → α → Prop)) :
IsStronglyCoatomic α :=
isStronglyAtomic_dual_iff_is_stronglyCoatomic.1 <| IsStronglyAtomic.of_wellFounded_lt (α := αᵒᵈ) h
instance [WellFoundedLT α] : IsStronglyAtomic α :=
IsStronglyAtomic.of_wellFounded_lt wellFounded_lt
instance [WellFoundedGT α] : IsStronglyCoatomic α :=
IsStronglyCoatomic.of_wellFounded_gt wellFounded_gt
theorem isAtomic_of_orderBot_wellFounded_lt [OrderBot α]
(h : WellFounded ((· < ·) : α → α → Prop)) : IsAtomic α :=
(IsStronglyAtomic.of_wellFounded_lt h).isAtomic
theorem isCoatomic_of_orderTop_gt_wellFounded [OrderTop α]
(h : WellFounded ((· > ·) : α → α → Prop)) : IsCoatomic α :=
isAtomic_dual_iff_isCoatomic.1 (@isAtomic_of_orderBot_wellFounded_lt αᵒᵈ _ _ h)
end WellFounded
namespace BooleanAlgebra
theorem le_iff_atom_le_imp {α} [BooleanAlgebra α] [IsAtomic α] {x y : α} :
x ≤ y ↔ ∀ a, IsAtom a → a ≤ x → a ≤ y := by
refine ⟨fun h a _ => (le_trans · h), fun h => ?_⟩
have : x ⊓ yᶜ = ⊥ := of_not_not fun hbot =>
have ⟨a, ha, hle⟩ := (eq_bot_or_exists_atom_le _).resolve_left hbot
have ⟨hx, hy'⟩ := le_inf_iff.1 hle
have hy := h a ha hx
have : a ≤ y ⊓ yᶜ := le_inf_iff.2 ⟨hy, hy'⟩
ha.1 (by simpa using this)
exact (eq_compl_iff_isCompl.1 (by simp)).inf_right_eq_bot_iff.1 this
theorem eq_iff_atom_le_iff {α} [BooleanAlgebra α] [IsAtomic α] {x y : α} :
x = y ↔ ∀ a, IsAtom a → (a ≤ x ↔ a ≤ y) := by
refine ⟨fun h => h ▸ by simp, fun h => ?_⟩
exact le_antisymm (le_iff_atom_le_imp.2 fun a ha hx => (h a ha).1 hx)
(le_iff_atom_le_imp.2 fun a ha hy => (h a ha).2 hy)
end BooleanAlgebra
namespace CompleteBooleanAlgebra
-- See note [reducible non-instances]
abbrev toCompleteAtomicBooleanAlgebra {α} [CompleteBooleanAlgebra α] [IsAtomic α] :
CompleteAtomicBooleanAlgebra α where
__ := ‹CompleteBooleanAlgebra α›
iInf_iSup_eq f := BooleanAlgebra.eq_iff_atom_le_iff.2 fun a ha => by
simp only [le_iInf_iff, atom_le_iSup ha]
rw [Classical.skolem]
end CompleteBooleanAlgebra
end Atomic
section Atomistic
variable (α) [CompleteLattice α]
/-- A lattice is atomistic iff every element is a `sSup` of a set of atoms. -/
class IsAtomistic : Prop where
/-- Every element is a `sSup` of a set of atoms. -/
eq_sSup_atoms : ∀ b : α, ∃ s : Set α, b = sSup s ∧ ∀ a, a ∈ s → IsAtom a
/-- A lattice is coatomistic iff every element is an `sInf` of a set of coatoms. -/
class IsCoatomistic : Prop where
/-- Every element is a `sInf` of a set of coatoms. -/
eq_sInf_coatoms : ∀ b : α, ∃ s : Set α, b = sInf s ∧ ∀ a, a ∈ s → IsCoatom a
export IsAtomistic (eq_sSup_atoms)
export IsCoatomistic (eq_sInf_coatoms)
variable {α}
@[simp]
theorem isCoatomistic_dual_iff_isAtomistic : IsCoatomistic αᵒᵈ ↔ IsAtomistic α :=
⟨fun h => ⟨fun b => by apply h.eq_sInf_coatoms⟩, fun h => ⟨fun b => by apply h.eq_sSup_atoms⟩⟩
@[simp]
theorem isAtomistic_dual_iff_isCoatomistic : IsAtomistic αᵒᵈ ↔ IsCoatomistic α :=
⟨fun h => ⟨fun b => by apply h.eq_sSup_atoms⟩, fun h => ⟨fun b => by apply h.eq_sInf_coatoms⟩⟩
namespace IsAtomistic
instance _root_.OrderDual.instIsCoatomistic [h : IsAtomistic α] : IsCoatomistic αᵒᵈ :=
isCoatomistic_dual_iff_isAtomistic.2 h
variable [IsAtomistic α]
instance (priority := 100) : IsAtomic α :=
⟨fun b => by
rcases eq_sSup_atoms b with ⟨s, rfl, hs⟩
rcases s.eq_empty_or_nonempty with h | h
· simp [h]
· exact Or.intro_right _ ⟨h.some, hs _ h.choose_spec, le_sSup h.choose_spec⟩⟩
end IsAtomistic
section IsAtomistic
variable [IsAtomistic α]
@[simp]
theorem sSup_atoms_le_eq (b : α) : sSup { a : α | IsAtom a ∧ a ≤ b } = b := by
rcases eq_sSup_atoms b with ⟨s, rfl, hs⟩
exact le_antisymm (sSup_le fun _ => And.right) (sSup_le_sSup fun a ha => ⟨hs a ha, le_sSup ha⟩)
@[simp]
theorem sSup_atoms_eq_top : sSup { a : α | IsAtom a } = ⊤ := by
refine Eq.trans (congr rfl (Set.ext fun x => ?_)) (sSup_atoms_le_eq ⊤)
exact (and_iff_left le_top).symm
theorem le_iff_atom_le_imp {a b : α} : a ≤ b ↔ ∀ c : α, IsAtom c → c ≤ a → c ≤ b :=
⟨fun ab c _ ca => le_trans ca ab, fun h => by
rw [← sSup_atoms_le_eq a, ← sSup_atoms_le_eq b]
exact sSup_le_sSup fun c hc => ⟨hc.1, h c hc.1 hc.2⟩⟩
theorem eq_iff_atom_le_iff {a b : α} : a = b ↔ ∀ c, IsAtom c → (c ≤ a ↔ c ≤ b) := by
refine ⟨fun h => h ▸ by simp, fun h => ?_⟩
exact le_antisymm (le_iff_atom_le_imp.2 fun a ha hx => (h a ha).1 hx)
(le_iff_atom_le_imp.2 fun a ha hy => (h a ha).2 hy)
end IsAtomistic
namespace IsCoatomistic
instance _root_.OrderDual.instIsAtomistic [h : IsCoatomistic α] : IsAtomistic αᵒᵈ :=
isAtomistic_dual_iff_isCoatomistic.2 h
variable [IsCoatomistic α]
instance (priority := 100) : IsCoatomic α :=
⟨fun b => by
rcases eq_sInf_coatoms b with ⟨s, rfl, hs⟩
rcases s.eq_empty_or_nonempty with h | h
· simp [h]
· exact Or.intro_right _ ⟨h.some, hs _ h.choose_spec, sInf_le h.choose_spec⟩⟩
end IsCoatomistic
namespace CompleteAtomicBooleanAlgebra
instance {α} [CompleteAtomicBooleanAlgebra α] : IsAtomistic α where
eq_sSup_atoms b := by
inhabit α
refine ⟨{ a | IsAtom a ∧ a ≤ b }, ?_, fun a ha => ha.1⟩
refine le_antisymm ?_ (sSup_le fun c hc => hc.2)
have : (⨅ c : α, ⨆ x, b ⊓ cond x c (cᶜ)) = b := by simp [iSup_bool_eq, iInf_const]
rw [← this]; clear this
simp_rw [iInf_iSup_eq, iSup_le_iff]; intro g
if h : (⨅ a, b ⊓ cond (g a) a (aᶜ)) = ⊥ then simp [h] else
refine le_sSup ⟨⟨h, fun c hc => ?_⟩, le_trans (by rfl) (le_iSup _ g)⟩; clear h
have := lt_of_lt_of_le hc (le_trans (iInf_le _ c) inf_le_right)
revert this
nontriviality α
cases g c <;> simp
instance {α} [CompleteAtomicBooleanAlgebra α] : IsCoatomistic α :=
isAtomistic_dual_iff_isCoatomistic.1 inferInstance
end CompleteAtomicBooleanAlgebra
end Atomistic
/-- An order is simple iff it has exactly two elements, `⊥` and `⊤`. -/
class IsSimpleOrder (α : Type*) [LE α] [BoundedOrder α] extends Nontrivial α : Prop where
/-- Every element is either `⊥` or `⊤` -/
eq_bot_or_eq_top : ∀ a : α, a = ⊥ ∨ a = ⊤
export IsSimpleOrder (eq_bot_or_eq_top)
theorem isSimpleOrder_iff_isSimpleOrder_orderDual [LE α] [BoundedOrder α] :
IsSimpleOrder α ↔ IsSimpleOrder αᵒᵈ := by
constructor <;> intro i <;> haveI := i
· exact
{ exists_pair_ne := @exists_pair_ne α _
eq_bot_or_eq_top := fun a => Or.symm (eq_bot_or_eq_top (OrderDual.ofDual a) : _ ∨ _) }
· exact
{ exists_pair_ne := @exists_pair_ne αᵒᵈ _
eq_bot_or_eq_top := fun a => Or.symm (eq_bot_or_eq_top (OrderDual.toDual a)) }
theorem IsSimpleOrder.bot_ne_top [LE α] [BoundedOrder α] [IsSimpleOrder α] : (⊥ : α) ≠ (⊤ : α) := by
obtain ⟨a, b, h⟩ := exists_pair_ne α
rcases eq_bot_or_eq_top a with (rfl | rfl) <;> rcases eq_bot_or_eq_top b with (rfl | rfl) <;>
first |simpa|simpa using h.symm
section IsSimpleOrder
variable [PartialOrder α] [BoundedOrder α] [IsSimpleOrder α]
instance OrderDual.instIsSimpleOrder {α} [LE α] [BoundedOrder α] [IsSimpleOrder α] :
IsSimpleOrder αᵒᵈ := isSimpleOrder_iff_isSimpleOrder_orderDual.1 (by infer_instance)
/-- A simple `BoundedOrder` induces a preorder. This is not an instance to prevent loops. -/
protected def IsSimpleOrder.preorder {α} [LE α] [BoundedOrder α] [IsSimpleOrder α] :
Preorder α where
le := (· ≤ ·)
le_refl a := by rcases eq_bot_or_eq_top a with (rfl | rfl) <;> simp
le_trans a b c := by
rcases eq_bot_or_eq_top a with (rfl | rfl)
· simp
· rcases eq_bot_or_eq_top b with (rfl | rfl)
· rcases eq_bot_or_eq_top c with (rfl | rfl) <;> simp
· simp
/-- A simple partial ordered `BoundedOrder` induces a linear order.
This is not an instance to prevent loops. -/
protected def IsSimpleOrder.linearOrder [DecidableEq α] : LinearOrder α :=
{ (inferInstance : PartialOrder α) with
le_total := fun a b => by rcases eq_bot_or_eq_top a with (rfl | rfl) <;> simp
decidableLE := fun a b =>
if ha : a = ⊥ then isTrue (ha.le.trans bot_le)
else
if hb : b = ⊤ then isTrue (le_top.trans hb.ge)
else
isFalse fun H =>
hb (top_unique (le_trans (top_le_iff.mpr (Or.resolve_left
(eq_bot_or_eq_top a) ha)) H)) }
@[simp]
theorem isAtom_top : IsAtom (⊤ : α) :=
⟨top_ne_bot, fun a ha => Or.resolve_right (eq_bot_or_eq_top a) (ne_of_lt ha)⟩
@[simp]
theorem isCoatom_bot : IsCoatom (⊥ : α) :=
isAtom_dual_iff_isCoatom.1 isAtom_top
theorem bot_covBy_top : (⊥ : α) ⋖ ⊤ :=
isAtom_top.bot_covBy
end IsSimpleOrder
namespace IsSimpleOrder
section Preorder
variable [Preorder α] [BoundedOrder α] [IsSimpleOrder α] {a b : α} (h : a < b)
theorem eq_bot_of_lt : a = ⊥ :=
(IsSimpleOrder.eq_bot_or_eq_top _).resolve_right h.ne_top
theorem eq_top_of_lt : b = ⊤ :=
(IsSimpleOrder.eq_bot_or_eq_top _).resolve_left h.ne_bot
alias _root_.LT.lt.eq_bot := eq_bot_of_lt
alias _root_.LT.lt.eq_top := eq_top_of_lt
@[deprecated (since := "2024-05-29")] alias LT.lt.eq_bot := _root_.LT.lt.eq_bot
@[deprecated (since := "2024-05-29")] alias LT.lt.eq_top := _root_.LT.lt.eq_top
end Preorder
section BoundedOrder
variable [Lattice α] [BoundedOrder α] [IsSimpleOrder α]
/-- A simple partial ordered `BoundedOrder` induces a lattice.
This is not an instance to prevent loops -/
protected def lattice {α} [DecidableEq α] [PartialOrder α] [BoundedOrder α] [IsSimpleOrder α] :
Lattice α :=
@LinearOrder.toLattice α IsSimpleOrder.linearOrder
/-- A lattice that is a `BoundedOrder` is a distributive lattice.
This is not an instance to prevent loops -/
protected def distribLattice : DistribLattice α :=
{ (inferInstance : Lattice α) with
le_sup_inf := fun x y z => by rcases eq_bot_or_eq_top x with (rfl | rfl) <;> simp }
-- see Note [lower instance priority]
instance (priority := 100) : IsAtomic α :=
⟨fun b => (eq_bot_or_eq_top b).imp_right fun h => ⟨⊤, ⟨isAtom_top, ge_of_eq h⟩⟩⟩
-- see Note [lower instance priority]
instance (priority := 100) : IsCoatomic α :=
isAtomic_dual_iff_isCoatomic.1 (by infer_instance)
end BoundedOrder
-- It is important that in this section `IsSimpleOrder` is the last type-class argument.
section DecidableEq
variable [DecidableEq α] [PartialOrder α] [BoundedOrder α] [IsSimpleOrder α]
/-- Every simple lattice is isomorphic to `Bool`, regardless of order. -/
@[simps]
def equivBool {α} [DecidableEq α] [LE α] [BoundedOrder α] [IsSimpleOrder α] : α ≃ Bool where
toFun x := x = ⊤
invFun x := x.casesOn ⊥ ⊤
left_inv x := by rcases eq_bot_or_eq_top x with (rfl | rfl) <;> simp [bot_ne_top]
right_inv x := by cases x <;> simp [bot_ne_top]
/-- Every simple lattice over a partial order is order-isomorphic to `Bool`. -/
def orderIsoBool : α ≃o Bool :=
{ equivBool with
map_rel_iff' := @fun a b => by
rcases eq_bot_or_eq_top a with (rfl | rfl)
· simp [bot_ne_top]
· rcases eq_bot_or_eq_top b with (rfl | rfl)
· simp [bot_ne_top.symm, bot_ne_top, Bool.false_lt_true]
· simp [bot_ne_top] }
/-- A simple `BoundedOrder` is also a `BooleanAlgebra`. -/
protected def booleanAlgebra {α} [DecidableEq α] [Lattice α] [BoundedOrder α] [IsSimpleOrder α] :
BooleanAlgebra α :=
{ inferInstanceAs (BoundedOrder α), IsSimpleOrder.distribLattice with
compl := fun x => if x = ⊥ then ⊤ else ⊥
sdiff := fun x y => if x = ⊤ ∧ y = ⊥ then ⊤ else ⊥
sdiff_eq := fun x y => by
rcases eq_bot_or_eq_top x with (rfl | rfl) <;> simp [bot_ne_top, SDiff.sdiff, compl]
inf_compl_le_bot := fun x => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· simp
· simp
top_le_sup_compl := fun x => by rcases eq_bot_or_eq_top x with (rfl | rfl) <;> simp }
end DecidableEq
variable [Lattice α] [BoundedOrder α] [IsSimpleOrder α]
open Classical in
/-- A simple `BoundedOrder` is also complete. -/
protected noncomputable def completeLattice : CompleteLattice α :=
{ (inferInstance : Lattice α),
(inferInstance : BoundedOrder α) with
sSup := fun s => if ⊤ ∈ s then ⊤ else ⊥
sInf := fun s => if ⊥ ∈ s then ⊥ else ⊤
le_sSup := fun s x h => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· exact bot_le
· dsimp; rw [if_pos h]
sSup_le := fun s x h => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· dsimp; rw [if_neg]
intro con
exact bot_ne_top (eq_top_iff.2 (h ⊤ con))
· exact le_top
sInf_le := fun s x h => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· dsimp; rw [if_pos h]
· exact le_top
le_sInf := fun s x h => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· exact bot_le
· dsimp; rw [if_neg]
intro con
exact top_ne_bot (eq_bot_iff.2 (h ⊥ con)) }
open Classical in
/-- A simple `BoundedOrder` is also a `CompleteBooleanAlgebra`. -/
protected noncomputable def completeBooleanAlgebra : CompleteBooleanAlgebra α :=
{ __ := IsSimpleOrder.completeLattice
__ := IsSimpleOrder.booleanAlgebra
iInf_sup_le_sup_sInf := fun x s => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· simp [bot_sup_eq, ← sInf_eq_iInf]
· simp only [top_le_iff, top_sup_eq, iInf_top, le_sInf_iff, le_refl]
inf_sSup_le_iSup_inf := fun x s => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· simp only [le_bot_iff, sSup_eq_bot, bot_inf_eq, iSup_bot, le_refl]
· simp only [top_inf_eq, ← sSup_eq_iSup]
exact le_rfl }
instance : ComplementedLattice α :=
letI := IsSimpleOrder.completeBooleanAlgebra (α := α); inferInstance
end IsSimpleOrder
namespace IsSimpleOrder
variable [CompleteLattice α] [IsSimpleOrder α]
--set_option default_priority 100
-- Porting note: not supported, done for each instance individually
instance (priority := 100) : IsAtomistic α :=
⟨fun b =>
(eq_bot_or_eq_top b).elim
(fun h => ⟨∅, ⟨h.trans sSup_empty.symm, fun _ ha => False.elim (Set.not_mem_empty _ ha)⟩⟩)
fun h =>
⟨{⊤}, h.trans sSup_singleton.symm, fun _ ha =>
(Set.mem_singleton_iff.1 ha).symm ▸ isAtom_top⟩⟩
instance : IsCoatomistic α :=
isAtomistic_dual_iff_isCoatomistic.1 (by infer_instance)
end IsSimpleOrder
theorem isSimpleOrder_iff_isAtom_top [PartialOrder α] [BoundedOrder α] :
IsSimpleOrder α ↔ IsAtom (⊤ : α) :=
⟨fun h => @isAtom_top _ _ _ h, fun h =>
{ exists_pair_ne := ⟨⊤, ⊥, h.1⟩
eq_bot_or_eq_top := fun a => ((eq_or_lt_of_le le_top).imp_right (h.2 a)).symm }⟩
theorem isSimpleOrder_iff_isCoatom_bot [PartialOrder α] [BoundedOrder α] :
IsSimpleOrder α ↔ IsCoatom (⊥ : α) :=
isSimpleOrder_iff_isSimpleOrder_orderDual.trans isSimpleOrder_iff_isAtom_top
namespace Set
theorem isSimpleOrder_Iic_iff_isAtom [PartialOrder α] [OrderBot α] {a : α} :
IsSimpleOrder (Iic a) ↔ IsAtom a :=
isSimpleOrder_iff_isAtom_top.trans <|
and_congr (not_congr Subtype.mk_eq_mk)
⟨fun h b ab => Subtype.mk_eq_mk.1 (h ⟨b, le_of_lt ab⟩ ab), fun h ⟨b, _⟩ hbotb =>
Subtype.mk_eq_mk.2 (h b (Subtype.mk_lt_mk.1 hbotb))⟩
theorem isSimpleOrder_Ici_iff_isCoatom [PartialOrder α] [OrderTop α] {a : α} :
IsSimpleOrder (Ici a) ↔ IsCoatom a :=
isSimpleOrder_iff_isCoatom_bot.trans <|
and_congr (not_congr Subtype.mk_eq_mk)
⟨fun h b ab => Subtype.mk_eq_mk.1 (h ⟨b, le_of_lt ab⟩ ab), fun h ⟨b, _⟩ hbotb =>
Subtype.mk_eq_mk.2 (h b (Subtype.mk_lt_mk.1 hbotb))⟩
end Set
namespace OrderEmbedding
variable [PartialOrder α] [PartialOrder β]
theorem isAtom_of_map_bot_of_image [OrderBot α] [OrderBot β] (f : β ↪o α) (hbot : f ⊥ = ⊥) {b : β}
(hb : IsAtom (f b)) : IsAtom b := by
simp only [← bot_covBy_iff] at hb ⊢
exact CovBy.of_image f (hbot.symm ▸ hb)
theorem isCoatom_of_map_top_of_image [OrderTop α] [OrderTop β] (f : β ↪o α) (htop : f ⊤ = ⊤)
{b : β} (hb : IsCoatom (f b)) : IsCoatom b :=
f.dual.isAtom_of_map_bot_of_image htop hb
end OrderEmbedding
namespace GaloisInsertion
variable [PartialOrder α] [PartialOrder β]
theorem isAtom_of_u_bot [OrderBot α] [OrderBot β] {l : α → β} {u : β → α}
(gi : GaloisInsertion l u) (hbot : u ⊥ = ⊥) {b : β} (hb : IsAtom (u b)) : IsAtom b :=
OrderEmbedding.isAtom_of_map_bot_of_image
⟨⟨u, gi.u_injective⟩, @GaloisInsertion.u_le_u_iff _ _ _ _ _ _ gi⟩ hbot hb
theorem isAtom_iff [OrderBot α] [IsAtomic α] [OrderBot β] {l : α → β} {u : β → α}
(gi : GaloisInsertion l u) (hbot : u ⊥ = ⊥) (h_atom : ∀ a, IsAtom a → u (l a) = a) (a : α) :
IsAtom (l a) ↔ IsAtom a := by
refine ⟨fun hla => ?_, fun ha => gi.isAtom_of_u_bot hbot ((h_atom a ha).symm ▸ ha)⟩
obtain ⟨a', ha', hab'⟩ :=
(eq_bot_or_exists_atom_le (u (l a))).resolve_left (hbot ▸ fun h => hla.1 (gi.u_injective h))
have :=
(hla.le_iff.mp <| (gi.l_u_eq (l a) ▸ gi.gc.monotone_l hab' : l a' ≤ l a)).resolve_left fun h =>
ha'.1 (hbot ▸ h_atom a' ha' ▸ congr_arg u h)
have haa' : a = a' :=
(ha'.le_iff.mp <|
(gi.gc.le_u_l a).trans_eq (h_atom a' ha' ▸ congr_arg u this.symm)).resolve_left
(mt (congr_arg l) (gi.gc.l_bot.symm ▸ hla.1))
exact haa'.symm ▸ ha'
theorem isAtom_iff' [OrderBot α] [IsAtomic α] [OrderBot β] {l : α → β} {u : β → α}
(gi : GaloisInsertion l u) (hbot : u ⊥ = ⊥) (h_atom : ∀ a, IsAtom a → u (l a) = a) (b : β) :
IsAtom (u b) ↔ IsAtom b := by rw [← gi.isAtom_iff hbot h_atom, gi.l_u_eq]
theorem isCoatom_of_image [OrderTop α] [OrderTop β] {l : α → β} {u : β → α}
(gi : GaloisInsertion l u) {b : β} (hb : IsCoatom (u b)) : IsCoatom b :=
OrderEmbedding.isCoatom_of_map_top_of_image
⟨⟨u, gi.u_injective⟩, @GaloisInsertion.u_le_u_iff _ _ _ _ _ _ gi⟩ gi.gc.u_top hb
theorem isCoatom_iff [OrderTop α] [IsCoatomic α] [OrderTop β] {l : α → β} {u : β → α}
(gi : GaloisInsertion l u) (h_coatom : ∀ a : α, IsCoatom a → u (l a) = a) (b : β) :
IsCoatom (u b) ↔ IsCoatom b := by
refine ⟨fun hb => gi.isCoatom_of_image hb, fun hb => ?_⟩
obtain ⟨a, ha, hab⟩ :=
(eq_top_or_exists_le_coatom (u b)).resolve_left fun h =>
hb.1 <| (gi.gc.u_top ▸ gi.l_u_eq ⊤ : l ⊤ = ⊤) ▸ gi.l_u_eq b ▸ congr_arg l h
have : l a = b :=
(hb.le_iff.mp (gi.l_u_eq b ▸ gi.gc.monotone_l hab : b ≤ l a)).resolve_left fun hla =>
ha.1 (gi.gc.u_top ▸ h_coatom a ha ▸ congr_arg u hla)
exact this ▸ (h_coatom a ha).symm ▸ ha
end GaloisInsertion
namespace GaloisCoinsertion
variable [PartialOrder α] [PartialOrder β]
theorem isCoatom_of_l_top [OrderTop α] [OrderTop β] {l : α → β} {u : β → α}
(gi : GaloisCoinsertion l u) (hbot : l ⊤ = ⊤) {a : α} (hb : IsCoatom (l a)) : IsCoatom a :=
gi.dual.isAtom_of_u_bot hbot hb.dual
theorem isCoatom_iff [OrderTop α] [OrderTop β] [IsCoatomic β] {l : α → β} {u : β → α}
(gi : GaloisCoinsertion l u) (htop : l ⊤ = ⊤) (h_coatom : ∀ b, IsCoatom b → l (u b) = b)
(b : β) : IsCoatom (u b) ↔ IsCoatom b :=
gi.dual.isAtom_iff htop h_coatom b
theorem isCoatom_iff' [OrderTop α] [OrderTop β] [IsCoatomic β] {l : α → β} {u : β → α}
(gi : GaloisCoinsertion l u) (htop : l ⊤ = ⊤) (h_coatom : ∀ b, IsCoatom b → l (u b) = b)
(a : α) : IsCoatom (l a) ↔ IsCoatom a :=
gi.dual.isAtom_iff' htop h_coatom a
theorem isAtom_of_image [OrderBot α] [OrderBot β] {l : α → β} {u : β → α}
(gi : GaloisCoinsertion l u) {a : α} (hb : IsAtom (l a)) : IsAtom a :=
gi.dual.isCoatom_of_image hb.dual
theorem isAtom_iff [OrderBot α] [OrderBot β] [IsAtomic β] {l : α → β} {u : β → α}
(gi : GaloisCoinsertion l u) (h_atom : ∀ b, IsAtom b → l (u b) = b) (a : α) :
IsAtom (l a) ↔ IsAtom a :=
gi.dual.isCoatom_iff h_atom a
end GaloisCoinsertion
namespace OrderIso
variable [PartialOrder α] [PartialOrder β]
@[simp]
theorem isAtom_iff [OrderBot α] [OrderBot β] (f : α ≃o β) (a : α) : IsAtom (f a) ↔ IsAtom a :=
⟨f.toGaloisCoinsertion.isAtom_of_image, fun ha =>
f.toGaloisInsertion.isAtom_of_u_bot (map_bot f.symm) <| (f.symm_apply_apply a).symm ▸ ha⟩
@[simp]
theorem isCoatom_iff [OrderTop α] [OrderTop β] (f : α ≃o β) (a : α) :
IsCoatom (f a) ↔ IsCoatom a :=
f.dual.isAtom_iff a
theorem isSimpleOrder_iff [BoundedOrder α] [BoundedOrder β] (f : α ≃o β) :
IsSimpleOrder α ↔ IsSimpleOrder β := by
rw [isSimpleOrder_iff_isAtom_top, isSimpleOrder_iff_isAtom_top, ← f.isAtom_iff ⊤,
f.map_top]
theorem isSimpleOrder [BoundedOrder α] [BoundedOrder β] [h : IsSimpleOrder β] (f : α ≃o β) :
IsSimpleOrder α :=
f.isSimpleOrder_iff.mpr h
protected theorem isAtomic_iff [OrderBot α] [OrderBot β] (f : α ≃o β) :
IsAtomic α ↔ IsAtomic β := by
simp only [isAtomic_iff, f.surjective.forall, f.surjective.exists, ← map_bot f, f.eq_iff_eq,
f.le_iff_le, f.isAtom_iff]
protected theorem isCoatomic_iff [OrderTop α] [OrderTop β] (f : α ≃o β) :
IsCoatomic α ↔ IsCoatomic β := by
simp only [← isAtomic_dual_iff_isCoatomic, f.dual.isAtomic_iff]
end OrderIso
section CompleteLattice
variable [CompleteLattice α]
/-- A complete upper-modular lattice that is atomistic is strongly atomic.
Not an instance to prevent loops. -/
theorem CompleteLattice.isStronglyAtomic [IsUpperModularLattice α] [IsAtomistic α] :
IsStronglyAtomic α where
exists_covBy_le_of_lt a b hab := by
obtain ⟨s, rfl, h⟩ := eq_sSup_atoms b
refine by_contra fun hcon ↦ hab.not_le <| sSup_le_iff.2 fun x hx ↦ ?_
simp_rw [not_exists, and_comm (b := _ ≤ _), not_and] at hcon
specialize hcon (x ⊔ a) (sup_le (le_sSup _ _ hx) hab.le)
obtain (hbot | h_inf) := (h x hx).bot_covBy.eq_or_eq (c := x ⊓ a) (by simp) (by simp)
· exact False.elim <| hcon <|
(hbot ▸ IsUpperModularLattice.covBy_sup_of_inf_covBy) (h x hx).bot_covBy
rwa [inf_eq_left] at h_inf
/-- A complete lower-modular lattice that is coatomistic is strongly coatomic.
Not an instance to prevent loops. -/
theorem CompleteLattice.isStronglyCoatomic [IsLowerModularLattice α] [IsCoatomistic α] :
IsStronglyCoatomic α := by
rw [← isStronglyAtomic_dual_iff_is_stronglyCoatomic]
exact CompleteLattice.isStronglyAtomic
end CompleteLattice
section IsModularLattice
variable [Lattice α] [BoundedOrder α] [IsModularLattice α]
namespace IsCompl
variable {a b : α} (hc : IsCompl a b)
theorem isAtom_iff_isCoatom : IsAtom a ↔ IsCoatom b :=
Set.isSimpleOrder_Iic_iff_isAtom.symm.trans <|
hc.IicOrderIsoIci.isSimpleOrder_iff.trans Set.isSimpleOrder_Ici_iff_isCoatom
theorem isCoatom_iff_isAtom : IsCoatom a ↔ IsAtom b :=
hc.symm.isAtom_iff_isCoatom.symm
end IsCompl
variable [ComplementedLattice α]
theorem isCoatomic_of_isAtomic_of_complementedLattice_of_isModular [IsAtomic α] :
IsCoatomic α :=
⟨fun x => by
rcases exists_isCompl x with ⟨y, xy⟩
apply (eq_bot_or_exists_atom_le y).imp _ _
· rintro rfl
exact eq_top_of_isCompl_bot xy
· rintro ⟨a, ha, ay⟩
rcases exists_isCompl (xy.symm.IicOrderIsoIci ⟨a, ay⟩) with ⟨⟨b, xb⟩, hb⟩
refine ⟨↑(⟨b, xb⟩ : Set.Ici x), IsCoatom.of_isCoatom_coe_Ici ?_, xb⟩
rw [← hb.isAtom_iff_isCoatom, OrderIso.isAtom_iff]
apply ha.Iic⟩
theorem isAtomic_of_isCoatomic_of_complementedLattice_of_isModular [IsCoatomic α] :
IsAtomic α :=
isCoatomic_dual_iff_isAtomic.1 isCoatomic_of_isAtomic_of_complementedLattice_of_isModular
theorem isAtomic_iff_isCoatomic : IsAtomic α ↔ IsCoatomic α :=
⟨fun _ => isCoatomic_of_isAtomic_of_complementedLattice_of_isModular,
fun _ => isAtomic_of_isCoatomic_of_complementedLattice_of_isModular⟩
/-- A complemented modular atomic lattice is strongly atomic.
Not an instance to prevent loops. -/
theorem ComplementedLattice.isStronglyAtomic [IsAtomic α] : IsStronglyAtomic α where
exists_covBy_le_of_lt a b hab := by
obtain ⟨⟨a', ha'b : a' ≤ b⟩, ha'⟩ := exists_isCompl (α := Set.Iic b) ⟨a, hab.le⟩
obtain (rfl | ⟨d, hd⟩) := eq_bot_or_exists_atom_le a'
· obtain rfl : a = b := by simpa [codisjoint_bot, ← Subtype.coe_inj] using ha'.codisjoint
exact False.elim <| hab.ne rfl
refine ⟨d ⊔ a, IsUpperModularLattice.covBy_sup_of_inf_covBy ?_, sup_le (hd.2.trans ha'b) hab.le⟩
convert hd.1.bot_covBy
rw [← le_bot_iff, ← show a ⊓ a' = ⊥ by simpa using Subtype.coe_inj.2 ha'.inf_eq_bot, inf_comm]
exact inf_le_inf_left _ hd.2
/-- A complemented modular coatomic lattice is strongly coatomic.
Not an instance to prevent loops. -/
theorem ComplementedLattice.isStronglyCoatomic [IsCoatomic α] : IsStronglyCoatomic α :=
isStronglyAtomic_dual_iff_is_stronglyCoatomic.1 <| ComplementedLattice.isStronglyAtomic
/-- A complemented modular atomic lattice is strongly coatomic.
Not an instance to prevent loops. -/
theorem ComplementedLattice.isStronglyAtomic' [h : IsAtomic α] : IsStronglyCoatomic α := by
rw [isAtomic_iff_isCoatomic] at h
exact isStronglyCoatomic
/-- A complemented modular coatomic lattice is strongly atomic.
Not an instance to prevent loops. -/
theorem ComplementedLattice.isStronglyCoatomic' [h : IsCoatomic α] : IsStronglyAtomic α := by
rw [← isAtomic_iff_isCoatomic] at h
exact isStronglyAtomic
end IsModularLattice
namespace «Prop»
@[simp] theorem isAtom_iff {p : Prop} : IsAtom p ↔ p := by
simp [IsAtom, show ⊥ = False from rfl, fun q r : Prop => show q < r ↔ _ ∧ _ from .rfl]
@[simp] theorem isCoatom_iff {p : Prop} : IsCoatom p ↔ ¬ p := by
simp [IsCoatom, show ⊤ = True from rfl, fun q r : Prop => show q < r ↔ _ ∧ _ from .rfl]; tauto
instance : IsSimpleOrder Prop where
eq_bot_or_eq_top p := by simp [em']
end «Prop»
namespace Pi
universe u
variable {ι : Type*} {π : ι → Type u}
protected theorem eq_bot_iff [∀ i, Bot (π i)] {f : ∀ i, π i} : f = ⊥ ↔ ∀ i, f i = ⊥ :=
⟨(· ▸ by simp), fun h => funext fun i => by simp [h]⟩
theorem isAtom_iff {f : ∀ i, π i} [∀ i, PartialOrder (π i)] [∀ i, OrderBot (π i)] :
IsAtom f ↔ ∃ i, IsAtom (f i) ∧ ∀ j, j ≠ i → f j = ⊥ := by
classical
constructor
case mpr =>
rintro ⟨i, ⟨hfi, hlt⟩, hbot⟩
refine ⟨fun h => hfi ((Pi.eq_bot_iff.1 h) _), fun g hgf => Pi.eq_bot_iff.2 fun j => ?_⟩
have ⟨hgf, k, hgfk⟩ := Pi.lt_def.1 hgf
obtain rfl : i = k := of_not_not fun hki => by rw [hbot _ (Ne.symm hki)] at hgfk; simp at hgfk
if hij : j = i then subst hij; refine hlt _ hgfk else
exact eq_bot_iff.2 <| le_trans (hgf _) (eq_bot_iff.1 (hbot _ hij))
case mp =>
rintro ⟨hbot, h⟩
have ⟨i, hbot⟩ : ∃ i, f i ≠ ⊥ := by rw [ne_eq, Pi.eq_bot_iff, not_forall] at hbot; exact hbot
refine ⟨i, ⟨hbot, ?c⟩, ?d⟩
case c =>
intro b hb
have := h (Function.update ⊥ i b)
simp only [lt_def, le_def, Pi.eq_bot_iff, and_imp, forall_exists_index] at this
simpa using this
(fun j => by by_cases h : j = i; { subst h; simpa using le_of_lt hb }; simp [h])
i (by simpa using hb) i
case d =>
intro j hj
have := h (Function.update ⊥ j (f j))
simp only [lt_def, le_def, Pi.eq_bot_iff, and_imp, forall_exists_index] at this
simpa using this (fun k => by by_cases h : k = j; { subst h; simp }; simp [h]) i
(by rwa [Function.update_noteq (Ne.symm hj), bot_apply, bot_lt_iff_ne_bot]) j
theorem isAtom_single {i : ι} [DecidableEq ι] [∀ i, PartialOrder (π i)] [∀ i, OrderBot (π i)]
{a : π i} (h : IsAtom a) : IsAtom (Function.update (⊥ : ∀ i, π i) i a) :=
isAtom_iff.2 ⟨i, by simpa, fun j hji => Function.update_noteq hji _ _⟩
theorem isAtom_iff_eq_single [DecidableEq ι] [∀ i, PartialOrder (π i)]
[∀ i, OrderBot (π i)] {f : ∀ i, π i} :
IsAtom f ↔ ∃ i a, IsAtom a ∧ f = Function.update ⊥ i a := by
constructor
case mp =>
intro h
have ⟨i, h, hbot⟩ := isAtom_iff.1 h
refine ⟨_, _, h, funext fun j => if hij : j = i then hij ▸ by simp else ?_⟩
rw [Function.update_noteq hij, hbot _ hij, bot_apply]
case mpr =>
rintro ⟨i, a, h, rfl⟩
exact isAtom_single h
instance isAtomic [∀ i, PartialOrder (π i)] [∀ i, OrderBot (π i)] [∀ i, IsAtomic (π i)] :
IsAtomic (∀ i, π i) where
eq_bot_or_exists_atom_le b := or_iff_not_imp_left.2 fun h =>
have ⟨i, hi⟩ : ∃ i, b i ≠ ⊥ := not_forall.1 (h.imp Pi.eq_bot_iff.2)
have ⟨a, ha, hab⟩ := (eq_bot_or_exists_atom_le (b i)).resolve_left hi
have : DecidableEq ι := open scoped Classical in inferInstance
⟨Function.update ⊥ i a, isAtom_single ha, update_le_iff.2 ⟨hab, by simp⟩⟩
instance isCoatomic [∀ i, PartialOrder (π i)] [∀ i, OrderTop (π i)] [∀ i, IsCoatomic (π i)] :
IsCoatomic (∀ i, π i) :=
isAtomic_dual_iff_isCoatomic.1 <|
show IsAtomic (∀ i, (π i)ᵒᵈ) from inferInstance
instance isAtomistic [∀ i, CompleteLattice (π i)] [∀ i, IsAtomistic (π i)] :
IsAtomistic (∀ i, π i) where
eq_sSup_atoms s := by
classical
refine ⟨{ f | IsAtom f ∧ f ≤ s }, ?_, by simp; tauto⟩
ext i
rw [← sSup_atoms_le_eq (s i)]
simp_rw [isAtom_iff_eq_single]
refine le_antisymm ?le ?ge
case le =>
refine sSup_le fun a ⟨ha, hle⟩ => ?_
refine le_sSup ⟨⟨_, ⟨_, _, ha, rfl⟩, fun j => ?_⟩, by simp⟩
if hij : j = i then subst hij; simpa else simp [hij]
case ge =>
refine sSup_le ?_
rintro _ ⟨⟨_, ⟨j, a, ha, rfl⟩, hle⟩, rfl⟩
if hij : i = j then ?_ else simp [Function.update_noteq hij]
subst hij; simp only [Function.update_same]
exact le_sSup ⟨ha, by simpa using hle i⟩
instance isCoatomistic [∀ i, CompleteLattice (π i)] [∀ i, IsCoatomistic (π i)] :
IsCoatomistic (∀ i, π i) :=
isAtomistic_dual_iff_isCoatomistic.1 <|
show IsAtomistic (∀ i, (π i)ᵒᵈ) from inferInstance
end Pi
section BooleanAlgebra
variable [BooleanAlgebra α] {a b : α}
@[simp] lemma isAtom_compl : IsAtom aᶜ ↔ IsCoatom a := isCompl_compl.symm.isAtom_iff_isCoatom
@[simp] lemma isCoatom_compl : IsCoatom aᶜ ↔ IsAtom a := isCompl_compl.symm.isCoatom_iff_isAtom
protected alias ⟨IsAtom.of_compl, IsCoatom.compl⟩ := isAtom_compl
protected alias ⟨IsCoatom.of_compl, IsAtom.compl⟩ := isCoatom_compl
end BooleanAlgebra
namespace Set
theorem isAtom_singleton (x : α) : IsAtom ({x} : Set α) :=
⟨singleton_ne_empty _, fun _ hs => ssubset_singleton_iff.mp hs⟩
theorem isAtom_iff {s : Set α} : IsAtom s ↔ ∃ x, s = {x} := by
refine
⟨?_, by
rintro ⟨x, rfl⟩
exact isAtom_singleton x⟩
rw [isAtom_iff_le_of_ge, bot_eq_empty, ← nonempty_iff_ne_empty]
rintro ⟨⟨x, hx⟩, hs⟩
exact
⟨x, eq_singleton_iff_unique_mem.2
⟨hx, fun y hy => (hs {y} (singleton_ne_empty _) (singleton_subset_iff.2 hy) hx).symm⟩⟩
theorem isCoatom_iff (s : Set α) : IsCoatom s ↔ ∃ x, s = {x}ᶜ := by
rw [isCompl_compl.isCoatom_iff_isAtom, isAtom_iff]
simp_rw [@eq_comm _ s, compl_eq_comm]
theorem isCoatom_singleton_compl (x : α) : IsCoatom ({x}ᶜ : Set α) :=
(isCoatom_iff {x}ᶜ).mpr ⟨x, rfl⟩
instance : IsAtomistic (Set α) where
eq_sSup_atoms s :=
⟨(fun x => {x}) '' s, by rw [sSup_eq_sUnion, sUnion_image, biUnion_of_singleton],
by { rintro _ ⟨x, _, rfl⟩
exact isAtom_singleton x }⟩
instance : IsCoatomistic (Set α) where
eq_sInf_coatoms s :=
⟨(fun x => {x}ᶜ) '' sᶜ,
by { rw [sInf_eq_sInter, sInter_image, ← compl_iUnion₂, biUnion_of_singleton, compl_compl] },
by { rintro _ ⟨x, _, rfl⟩
exact isCoatom_singleton_compl x }⟩
end Set
|
Order\Basic.lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Init.Order.LinearOrder
import Mathlib.Data.Prod.Basic
import Mathlib.Data.Subtype
import Mathlib.Tactic.Spread
import Mathlib.Tactic.Convert
import Mathlib.Tactic.SimpRw
import Mathlib.Tactic.Cases
import Mathlib.Order.Notation
import Batteries.Data.Sum.Lemmas
import Batteries.Tactic.Classical
/-!
# Basic definitions about `≤` and `<`
This file proves basic results about orders, provides extensive dot notation, defines useful order
classes and allows to transfer order instances.
## Type synonyms
* `OrderDual α` : A type synonym reversing the meaning of all inequalities, with notation `αᵒᵈ`.
* `AsLinearOrder α`: A type synonym to promote `PartialOrder α` to `LinearOrder α` using
`IsTotal α (≤)`.
### Transferring orders
- `Order.Preimage`, `Preorder.lift`: Transfers a (pre)order on `β` to an order on `α`
using a function `f : α → β`.
- `PartialOrder.lift`, `LinearOrder.lift`: Transfers a partial (resp., linear) order on `β` to a
partial (resp., linear) order on `α` using an injective function `f`.
### Extra class
* `DenselyOrdered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such
that `a < c < b`.
## Notes
`≤` and `<` are highly favored over `≥` and `>` in mathlib. The reason is that we can formulate all
lemmas using `≤`/`<`, and `rw` has trouble unifying `≤` and `≥`. Hence choosing one direction spares
us useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos.
Dot notation is particularly useful on `≤` (`LE.le`) and `<` (`LT.lt`). To that end, we
provide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with
`LE.le.trans` and can be used to construct `hab.trans hbc : a ≤ c` when `hab : a ≤ b`,
`hbc : b ≤ c`, `lt_of_le_of_lt` is aliased as `LE.le.trans_lt` and can be used to construct
`hab.trans hbc : a < c` when `hab : a ≤ b`, `hbc : b < c`.
## TODO
- expand module docs
- automatic construction of dual definitions / theorems
## Tags
preorder, order, partial order, poset, linear order, chain
-/
open Function
variable {ι α β : Type*} {π : ι → Type*}
section Preorder
variable [Preorder α] {a b c : α}
theorem le_trans' : b ≤ c → a ≤ b → a ≤ c :=
flip le_trans
theorem lt_trans' : b < c → a < b → a < c :=
flip lt_trans
theorem lt_of_le_of_lt' : b ≤ c → a < b → a < c :=
flip lt_of_lt_of_le
theorem lt_of_lt_of_le' : b < c → a ≤ b → a < c :=
flip lt_of_le_of_lt
end Preorder
section PartialOrder
variable [PartialOrder α] {a b : α}
theorem ge_antisymm : a ≤ b → b ≤ a → b = a :=
flip le_antisymm
theorem lt_of_le_of_ne' : a ≤ b → b ≠ a → a < b := fun h₁ h₂ ↦ lt_of_le_of_ne h₁ h₂.symm
theorem Ne.lt_of_le : a ≠ b → a ≤ b → a < b :=
flip lt_of_le_of_ne
theorem Ne.lt_of_le' : b ≠ a → a ≤ b → a < b :=
flip lt_of_le_of_ne'
end PartialOrder
attribute [simp] le_refl
attribute [ext] LE
alias LE.le.trans := le_trans
alias LE.le.trans' := le_trans'
alias LE.le.trans_lt := lt_of_le_of_lt
alias LE.le.trans_lt' := lt_of_le_of_lt'
alias LE.le.antisymm := le_antisymm
alias LE.le.antisymm' := ge_antisymm
alias LE.le.lt_of_ne := lt_of_le_of_ne
alias LE.le.lt_of_ne' := lt_of_le_of_ne'
alias LE.le.lt_of_not_le := lt_of_le_not_le
alias LE.le.lt_or_eq := lt_or_eq_of_le
alias LE.le.lt_or_eq_dec := Decidable.lt_or_eq_of_le
alias LT.lt.le := le_of_lt
alias LT.lt.trans := lt_trans
alias LT.lt.trans' := lt_trans'
alias LT.lt.trans_le := lt_of_lt_of_le
alias LT.lt.trans_le' := lt_of_lt_of_le'
alias LT.lt.ne := ne_of_lt
alias LT.lt.asymm := lt_asymm
alias LT.lt.not_lt := lt_asymm
alias Eq.le := le_of_eq
-- Porting note: no `decidable_classical` linter
-- attribute [nolint decidable_classical] LE.le.lt_or_eq_dec
section
variable [Preorder α] {a b c : α}
@[simp]
theorem lt_self_iff_false (x : α) : x < x ↔ False :=
⟨lt_irrefl x, False.elim⟩
theorem le_of_le_of_eq' : b ≤ c → a = b → a ≤ c :=
flip le_of_eq_of_le
theorem le_of_eq_of_le' : b = c → a ≤ b → a ≤ c :=
flip le_of_le_of_eq
theorem lt_of_lt_of_eq' : b < c → a = b → a < c :=
flip lt_of_eq_of_lt
theorem lt_of_eq_of_lt' : b = c → a < b → a < c :=
flip lt_of_lt_of_eq
alias LE.le.trans_eq := le_of_le_of_eq
alias LE.le.trans_eq' := le_of_le_of_eq'
alias LT.lt.trans_eq := lt_of_lt_of_eq
alias LT.lt.trans_eq' := lt_of_lt_of_eq'
alias Eq.trans_le := le_of_eq_of_le
alias Eq.trans_ge := le_of_eq_of_le'
alias Eq.trans_lt := lt_of_eq_of_lt
alias Eq.trans_gt := lt_of_eq_of_lt'
end
namespace Eq
variable [Preorder α] {x y z : α}
/-- If `x = y` then `y ≤ x`. Note: this lemma uses `y ≤ x` instead of `x ≥ y`, because `le` is used
almost exclusively in mathlib. -/
protected theorem ge (h : x = y) : y ≤ x :=
h.symm.le
theorem not_lt (h : x = y) : ¬x < y := fun h' ↦ h'.ne h
theorem not_gt (h : x = y) : ¬y < x :=
h.symm.not_lt
end Eq
section
variable [Preorder α] {a b : α}
@[simp] lemma le_of_subsingleton [Subsingleton α] : a ≤ b := (Subsingleton.elim a b).le
-- Making this a @[simp] lemma causes confluences problems downstream.
lemma not_lt_of_subsingleton [Subsingleton α] : ¬a < b := (Subsingleton.elim a b).not_lt
end
namespace LE.le
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem ge [LE α] {x y : α} (h : x ≤ y) : y ≥ x :=
h
section PartialOrder
variable [PartialOrder α] {a b : α}
theorem lt_iff_ne (h : a ≤ b) : a < b ↔ a ≠ b :=
⟨fun h ↦ h.ne, h.lt_of_ne⟩
theorem gt_iff_ne (h : a ≤ b) : a < b ↔ b ≠ a :=
⟨fun h ↦ h.ne.symm, h.lt_of_ne'⟩
theorem not_lt_iff_eq (h : a ≤ b) : ¬a < b ↔ a = b :=
h.lt_iff_ne.not_left
theorem not_gt_iff_eq (h : a ≤ b) : ¬a < b ↔ b = a :=
h.gt_iff_ne.not_left
theorem le_iff_eq (h : a ≤ b) : b ≤ a ↔ b = a :=
⟨fun h' ↦ h'.antisymm h, Eq.le⟩
theorem ge_iff_eq (h : a ≤ b) : b ≤ a ↔ a = b :=
⟨h.antisymm, Eq.ge⟩
end PartialOrder
theorem lt_or_le [LinearOrder α] {a b : α} (h : a ≤ b) (c : α) : a < c ∨ c ≤ b :=
((lt_or_ge a c).imp id) fun hc ↦ le_trans hc h
theorem le_or_lt [LinearOrder α] {a b : α} (h : a ≤ b) (c : α) : a ≤ c ∨ c < b :=
((le_or_gt a c).imp id) fun hc ↦ lt_of_lt_of_le hc h
theorem le_or_le [LinearOrder α] {a b : α} (h : a ≤ b) (c : α) : a ≤ c ∨ c ≤ b :=
(h.le_or_lt c).elim Or.inl fun h ↦ Or.inr <| le_of_lt h
end LE.le
namespace LT.lt
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem gt [LT α] {x y : α} (h : x < y) : y > x :=
h
protected theorem false [Preorder α] {x : α} : x < x → False :=
lt_irrefl x
theorem ne' [Preorder α] {x y : α} (h : x < y) : y ≠ x :=
h.ne.symm
theorem lt_or_lt [LinearOrder α] {x y : α} (h : x < y) (z : α) : x < z ∨ z < y :=
(lt_or_ge z y).elim Or.inr fun hz ↦ Or.inl <| h.trans_le hz
end LT.lt
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem GE.ge.le [LE α] {x y : α} (h : x ≥ y) : y ≤ x :=
h
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem GT.gt.lt [LT α] {x y : α} (h : x > y) : y < x :=
h
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
theorem ge_of_eq [Preorder α] {a b : α} (h : a = b) : a ≥ b :=
h.ge
theorem not_le_of_lt [Preorder α] {a b : α} (h : a < b) : ¬b ≤ a :=
(le_not_le_of_lt h).right
alias LT.lt.not_le := not_le_of_lt
theorem not_lt_of_le [Preorder α] {a b : α} (h : a ≤ b) : ¬b < a := fun hba ↦ hba.not_le h
alias LE.le.not_lt := not_lt_of_le
theorem ne_of_not_le [Preorder α] {a b : α} (h : ¬a ≤ b) : a ≠ b := fun hab ↦ h (le_of_eq hab)
-- See Note [decidable namespace]
protected theorem Decidable.le_iff_eq_or_lt [PartialOrder α] [@DecidableRel α (· ≤ ·)] {a b : α} :
a ≤ b ↔ a = b ∨ a < b :=
Decidable.le_iff_lt_or_eq.trans or_comm
theorem le_iff_eq_or_lt [PartialOrder α] {a b : α} : a ≤ b ↔ a = b ∨ a < b :=
le_iff_lt_or_eq.trans or_comm
theorem lt_iff_le_and_ne [PartialOrder α] {a b : α} : a < b ↔ a ≤ b ∧ a ≠ b :=
⟨fun h ↦ ⟨le_of_lt h, ne_of_lt h⟩, fun ⟨h1, h2⟩ ↦ h1.lt_of_ne h2⟩
theorem eq_iff_not_lt_of_le [PartialOrder α] {x y : α} : x ≤ y → y = x ↔ ¬x < y := by
rw [lt_iff_le_and_ne, not_and, Classical.not_not, eq_comm]
-- See Note [decidable namespace]
protected theorem Decidable.eq_iff_le_not_lt [PartialOrder α] [@DecidableRel α (· ≤ ·)] {a b : α} :
a = b ↔ a ≤ b ∧ ¬a < b :=
⟨fun h ↦ ⟨h.le, h ▸ lt_irrefl _⟩, fun ⟨h₁, h₂⟩ ↦
h₁.antisymm <| Decidable.by_contradiction fun h₃ ↦ h₂ (h₁.lt_of_not_le h₃)⟩
theorem eq_iff_le_not_lt [PartialOrder α] {a b : α} : a = b ↔ a ≤ b ∧ ¬a < b :=
haveI := Classical.dec
Decidable.eq_iff_le_not_lt
theorem eq_or_lt_of_le [PartialOrder α] {a b : α} (h : a ≤ b) : a = b ∨ a < b :=
h.lt_or_eq.symm
theorem eq_or_gt_of_le [PartialOrder α] {a b : α} (h : a ≤ b) : b = a ∨ a < b :=
h.lt_or_eq.symm.imp Eq.symm id
theorem gt_or_eq_of_le [PartialOrder α] {a b : α} (h : a ≤ b) : a < b ∨ b = a :=
(eq_or_gt_of_le h).symm
alias LE.le.eq_or_lt_dec := Decidable.eq_or_lt_of_le
alias LE.le.eq_or_lt := eq_or_lt_of_le
alias LE.le.eq_or_gt := eq_or_gt_of_le
alias LE.le.gt_or_eq := gt_or_eq_of_le
-- Porting note: no `decidable_classical` linter
-- attribute [nolint decidable_classical] LE.le.eq_or_lt_dec
theorem eq_of_le_of_not_lt [PartialOrder α] {a b : α} (hab : a ≤ b) (hba : ¬a < b) : a = b :=
hab.eq_or_lt.resolve_right hba
theorem eq_of_ge_of_not_gt [PartialOrder α] {a b : α} (hab : a ≤ b) (hba : ¬a < b) : b = a :=
(hab.eq_or_lt.resolve_right hba).symm
alias LE.le.eq_of_not_lt := eq_of_le_of_not_lt
alias LE.le.eq_of_not_gt := eq_of_ge_of_not_gt
theorem Ne.le_iff_lt [PartialOrder α] {a b : α} (h : a ≠ b) : a ≤ b ↔ a < b :=
⟨fun h' ↦ lt_of_le_of_ne h' h, fun h ↦ h.le⟩
theorem Ne.not_le_or_not_le [PartialOrder α] {a b : α} (h : a ≠ b) : ¬a ≤ b ∨ ¬b ≤ a :=
not_and_or.1 <| le_antisymm_iff.not.1 h
-- See Note [decidable namespace]
protected theorem Decidable.ne_iff_lt_iff_le [PartialOrder α] [DecidableEq α] {a b : α} :
(a ≠ b ↔ a < b) ↔ a ≤ b :=
⟨fun h ↦ Decidable.byCases le_of_eq (le_of_lt ∘ h.mp), fun h ↦ ⟨lt_of_le_of_ne h, ne_of_lt⟩⟩
@[simp]
theorem ne_iff_lt_iff_le [PartialOrder α] {a b : α} : (a ≠ b ↔ a < b) ↔ a ≤ b :=
haveI := Classical.dec
Decidable.ne_iff_lt_iff_le
-- Variant of `min_def` with the branches reversed.
theorem min_def' [LinearOrder α] (a b : α) : min a b = if b ≤ a then b else a := by
rw [min_def]
rcases lt_trichotomy a b with (lt | eq | gt)
· rw [if_pos lt.le, if_neg (not_le.mpr lt)]
· rw [if_pos eq.le, if_pos eq.ge, eq]
· rw [if_neg (not_le.mpr gt.gt), if_pos gt.le]
-- Variant of `min_def` with the branches reversed.
-- This is sometimes useful as it used to be the default.
theorem max_def' [LinearOrder α] (a b : α) : max a b = if b ≤ a then a else b := by
rw [max_def]
rcases lt_trichotomy a b with (lt | eq | gt)
· rw [if_pos lt.le, if_neg (not_le.mpr lt)]
· rw [if_pos eq.le, if_pos eq.ge, eq]
· rw [if_neg (not_le.mpr gt.gt), if_pos gt.le]
theorem lt_of_not_le [LinearOrder α] {a b : α} (h : ¬b ≤ a) : a < b :=
((le_total _ _).resolve_right h).lt_of_not_le h
theorem lt_iff_not_le [LinearOrder α] {x y : α} : x < y ↔ ¬y ≤ x :=
⟨not_le_of_lt, lt_of_not_le⟩
theorem Ne.lt_or_lt [LinearOrder α] {x y : α} (h : x ≠ y) : x < y ∨ y < x :=
lt_or_gt_of_ne h
/-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/
@[simp]
theorem lt_or_lt_iff_ne [LinearOrder α] {x y : α} : x < y ∨ y < x ↔ x ≠ y :=
ne_iff_lt_or_gt.symm
theorem not_lt_iff_eq_or_lt [LinearOrder α] {a b : α} : ¬a < b ↔ a = b ∨ b < a :=
not_lt.trans <| Decidable.le_iff_eq_or_lt.trans <| or_congr eq_comm Iff.rfl
theorem exists_ge_of_linear [LinearOrder α] (a b : α) : ∃ c, a ≤ c ∧ b ≤ c :=
match le_total a b with
| Or.inl h => ⟨_, h, le_rfl⟩
| Or.inr h => ⟨_, le_rfl, h⟩
lemma exists_forall_ge_and [LinearOrder α] {p q : α → Prop} :
(∃ i, ∀ j ≥ i, p j) → (∃ i, ∀ j ≥ i, q j) → ∃ i, ∀ j ≥ i, p j ∧ q j
| ⟨a, ha⟩, ⟨b, hb⟩ =>
let ⟨c, hac, hbc⟩ := exists_ge_of_linear a b
⟨c, fun _d hcd ↦ ⟨ha _ $ hac.trans hcd, hb _ $ hbc.trans hcd⟩⟩
theorem lt_imp_lt_of_le_imp_le {β} [LinearOrder α] [Preorder β] {a b : α} {c d : β}
(H : a ≤ b → c ≤ d) (h : d < c) : b < a :=
lt_of_not_le fun h' ↦ (H h').not_lt h
theorem le_imp_le_iff_lt_imp_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} :
a ≤ b → c ≤ d ↔ d < c → b < a :=
⟨lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt⟩
theorem lt_iff_lt_of_le_iff_le' {β} [Preorder α] [Preorder β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) (H' : b ≤ a ↔ d ≤ c) : b < a ↔ d < c :=
lt_iff_le_not_le.trans <| (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm
theorem lt_iff_lt_of_le_iff_le {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) : b < a ↔ d < c :=
not_le.symm.trans <| (not_congr H).trans <| not_le
theorem le_iff_le_iff_lt_iff_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} :
(a ≤ b ↔ c ≤ d) ↔ (b < a ↔ d < c) :=
⟨lt_iff_lt_of_le_iff_le, fun H ↦ not_lt.symm.trans <| (not_congr H).trans <| not_lt⟩
theorem eq_of_forall_le_iff [PartialOrder α] {a b : α} (H : ∀ c, c ≤ a ↔ c ≤ b) : a = b :=
((H _).1 le_rfl).antisymm ((H _).2 le_rfl)
theorem le_of_forall_le [Preorder α] {a b : α} (H : ∀ c, c ≤ a → c ≤ b) : a ≤ b :=
H _ le_rfl
theorem le_of_forall_le' [Preorder α] {a b : α} (H : ∀ c, a ≤ c → b ≤ c) : b ≤ a :=
H _ le_rfl
theorem le_of_forall_lt [LinearOrder α] {a b : α} (H : ∀ c, c < a → c < b) : a ≤ b :=
le_of_not_lt fun h ↦ lt_irrefl _ (H _ h)
theorem forall_lt_iff_le [LinearOrder α] {a b : α} : (∀ ⦃c⦄, c < a → c < b) ↔ a ≤ b :=
⟨le_of_forall_lt, fun h _ hca ↦ lt_of_lt_of_le hca h⟩
theorem le_of_forall_lt' [LinearOrder α] {a b : α} (H : ∀ c, a < c → b < c) : b ≤ a :=
le_of_not_lt fun h ↦ lt_irrefl _ (H _ h)
theorem forall_lt_iff_le' [LinearOrder α] {a b : α} : (∀ ⦃c⦄, a < c → b < c) ↔ b ≤ a :=
⟨le_of_forall_lt', fun h _ hac ↦ lt_of_le_of_lt h hac⟩
theorem eq_of_forall_ge_iff [PartialOrder α] {a b : α} (H : ∀ c, a ≤ c ↔ b ≤ c) : a = b :=
((H _).2 le_rfl).antisymm ((H _).1 le_rfl)
theorem eq_of_forall_lt_iff [LinearOrder α] {a b : α} (h : ∀ c, c < a ↔ c < b) : a = b :=
(le_of_forall_lt fun _ ↦ (h _).1).antisymm <| le_of_forall_lt fun _ ↦ (h _).2
theorem eq_of_forall_gt_iff [LinearOrder α] {a b : α} (h : ∀ c, a < c ↔ b < c) : a = b :=
(le_of_forall_lt' fun _ ↦ (h _).2).antisymm <| le_of_forall_lt' fun _ ↦ (h _).1
/-- A symmetric relation implies two values are equal, when it implies they're less-equal. -/
theorem rel_imp_eq_of_rel_imp_le [PartialOrder β] (r : α → α → Prop) [IsSymm α r] {f : α → β}
(h : ∀ a b, r a b → f a ≤ f b) {a b : α} : r a b → f a = f b := fun hab ↦
le_antisymm (h a b hab) (h b a <| symm hab)
/-- monotonicity of `≤` with respect to `→` -/
theorem le_implies_le_of_le_of_le {a b c d : α} [Preorder α] (hca : c ≤ a) (hbd : b ≤ d) :
a ≤ b → c ≤ d :=
fun hab ↦ (hca.trans hab).trans hbd
section PartialOrder
variable [PartialOrder α]
/-- To prove commutativity of a binary operation `○`, we only to check `a ○ b ≤ b ○ a` for all `a`,
`b`. -/
theorem commutative_of_le {f : β → β → α} (comm : ∀ a b, f a b ≤ f b a) : ∀ a b, f a b = f b a :=
fun _ _ ↦ (comm _ _).antisymm <| comm _ _
/-- To prove associativity of a commutative binary operation `○`, we only to check
`(a ○ b) ○ c ≤ a ○ (b ○ c)` for all `a`, `b`, `c`. -/
theorem associative_of_commutative_of_le {f : α → α → α} (comm : Commutative f)
(assoc : ∀ a b c, f (f a b) c ≤ f a (f b c)) : Associative f := fun a b c ↦
le_antisymm (assoc _ _ _) <| by
rw [comm, comm b, comm _ c, comm a]
exact assoc _ _ _
end PartialOrder
@[ext]
theorem Preorder.toLE_injective : Function.Injective (@Preorder.toLE α) :=
fun A B h ↦ match A, B with
| { lt := A_lt, lt_iff_le_not_le := A_iff, .. },
{ lt := B_lt, lt_iff_le_not_le := B_iff, .. } => by
cases h
have : A_lt = B_lt := by
funext a b
show (LT.mk A_lt).lt a b = (LT.mk B_lt).lt a b
rw [A_iff, B_iff]
cases this
congr
@[ext]
theorem PartialOrder.toPreorder_injective :
Function.Injective (@PartialOrder.toPreorder α) := fun A B h ↦ by
cases A
cases B
cases h
congr
@[ext]
theorem LinearOrder.toPartialOrder_injective :
Function.Injective (@LinearOrder.toPartialOrder α) :=
fun A B h ↦ match A, B with
| { le := A_le, lt := A_lt,
decidableLE := A_decidableLE, decidableEq := A_decidableEq, decidableLT := A_decidableLT
min := A_min, max := A_max, min_def := A_min_def, max_def := A_max_def,
compare := A_compare, compare_eq_compareOfLessAndEq := A_compare_canonical, .. },
{ le := B_le, lt := B_lt,
decidableLE := B_decidableLE, decidableEq := B_decidableEq, decidableLT := B_decidableLT
min := B_min, max := B_max, min_def := B_min_def, max_def := B_max_def,
compare := B_compare, compare_eq_compareOfLessAndEq := B_compare_canonical, .. } => by
cases h
obtain rfl : A_decidableLE = B_decidableLE := Subsingleton.elim _ _
obtain rfl : A_decidableEq = B_decidableEq := Subsingleton.elim _ _
obtain rfl : A_decidableLT = B_decidableLT := Subsingleton.elim _ _
have : A_min = B_min := by
funext a b
exact (A_min_def _ _).trans (B_min_def _ _).symm
cases this
have : A_max = B_max := by
funext a b
exact (A_max_def _ _).trans (B_max_def _ _).symm
cases this
have : A_compare = B_compare := by
funext a b
exact (A_compare_canonical _ _).trans (B_compare_canonical _ _).symm
congr
theorem Preorder.ext {A B : Preorder α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by
ext x y
exact H x y
theorem PartialOrder.ext {A B : PartialOrder α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by
ext x y
exact H x y
theorem LinearOrder.ext {A B : LinearOrder α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by
ext x y
exact H x y
/-- Given a relation `R` on `β` and a function `f : α → β`, the preimage relation on `α` is defined
by `x ≤ y ↔ f x ≤ f y`. It is the unique relation on `α` making `f` a `RelEmbedding` (assuming `f`
is injective). -/
@[simp]
def Order.Preimage (f : α → β) (s : β → β → Prop) (x y : α) : Prop :=
s (f x) (f y)
@[inherit_doc]
infixl:80 " ⁻¹'o " => Order.Preimage
/-- The preimage of a decidable order is decidable. -/
instance Order.Preimage.decidable (f : α → β) (s : β → β → Prop) [H : DecidableRel s] :
DecidableRel (f ⁻¹'o s) := fun _ _ ↦ H _ _
section ltByCases
variable [LinearOrder α] {P : Sort*} {x y : α}
@[simp]
lemma ltByCases_lt (h : x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₁ h := dif_pos h
@[simp]
lemma ltByCases_gt (h : y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₃ h := (dif_neg h.not_lt).trans (dif_pos h)
@[simp]
lemma ltByCases_eq (h : x = y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₂ h := (dif_neg h.not_lt).trans (dif_neg h.not_gt)
lemma ltByCases_not_lt (h : ¬ x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ y < x → x = y := fun h' => (le_antisymm (le_of_not_gt h') (le_of_not_gt h))) :
ltByCases x y h₁ h₂ h₃ = if h' : y < x then h₃ h' else h₂ (p h') := dif_neg h
lemma ltByCases_not_gt (h : ¬ y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ x < y → x = y := fun h' => (le_antisymm (le_of_not_gt h) (le_of_not_gt h'))) :
ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₂ (p h') :=
dite_congr rfl (fun _ => rfl) (fun _ => dif_neg h)
lemma ltByCases_ne (h : x ≠ y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ x < y → y < x := fun h' => h.lt_or_lt.resolve_left h') :
ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₃ (p h') :=
dite_congr rfl (fun _ => rfl) (fun _ => dif_pos _)
lemma ltByCases_comm {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : y = x → x = y := fun h' => h'.symm) :
ltByCases x y h₁ h₂ h₃ = ltByCases y x h₃ (h₂ ∘ p) h₁ := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· rw [ltByCases_lt h, ltByCases_gt h]
· rw [ltByCases_eq h, ltByCases_eq h.symm, comp_apply]
· rw [ltByCases_lt h, ltByCases_gt h]
lemma eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt {x' y' : α}
(ltc : (x < y) ↔ (x' < y')) (gtc : (y < x) ↔ (y' < x')) :
x = y ↔ x' = y' := by simp_rw [eq_iff_le_not_lt, ← not_lt, ltc, gtc]
lemma ltByCases_rec {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : P)
(hlt : (h : x < y) → h₁ h = p) (heq : (h : x = y) → h₂ h = p)
(hgt : (h : y < x) → h₃ h = p) :
ltByCases x y h₁ h₂ h₃ = p :=
ltByCases x y
(fun h => ltByCases_lt h ▸ hlt h)
(fun h => ltByCases_eq h ▸ heq h)
(fun h => ltByCases_gt h ▸ hgt h)
lemma ltByCases_eq_iff {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} {p : P} :
ltByCases x y h₁ h₂ h₃ = p ↔ (∃ h, h₁ h = p) ∨ (∃ h, h₂ h = p) ∨ (∃ h, h₃ h = p) := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· simp only [ltByCases_lt, exists_prop_of_true, h, h.not_lt, not_false_eq_true,
exists_prop_of_false, or_false, h.ne]
· simp only [h, lt_self_iff_false, ltByCases_eq, not_false_eq_true,
exists_prop_of_false, exists_prop_of_true, or_false, false_or]
· simp only [ltByCases_gt, exists_prop_of_true, h, h.not_lt, not_false_eq_true,
exists_prop_of_false, false_or, h.ne']
lemma ltByCases_congr {x' y' : α} {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
{h₁' : x' < y' → P} {h₂' : x' = y' → P} {h₃' : y' < x' → P} (ltc : (x < y) ↔ (x' < y'))
(gtc : (y < x) ↔ (y' < x')) (hh'₁ : ∀ (h : x' < y'), h₁ (ltc.mpr h) = h₁' h)
(hh'₂ : ∀ (h : x' = y'), h₂ ((eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc).mpr h) = h₂' h)
(hh'₃ : ∀ (h : y' < x'), h₃ (gtc.mpr h) = h₃' h) :
ltByCases x y h₁ h₂ h₃ = ltByCases x' y' h₁' h₂' h₃' := by
refine ltByCases_rec _ (fun h => ?_) (fun h => ?_) (fun h => ?_)
· rw [ltByCases_lt (ltc.mp h), hh'₁]
· rw [eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc] at h
rw [ltByCases_eq h, hh'₂]
· rw [ltByCases_gt (gtc.mp h), hh'₃]
/-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order,
non-dependently. -/
abbrev ltTrichotomy (x y : α) (p q r : P) := ltByCases x y (fun _ => p) (fun _ => q) (fun _ => r)
variable {p q r s : P}
@[simp]
lemma ltTrichotomy_lt (h : x < y) : ltTrichotomy x y p q r = p := ltByCases_lt h
@[simp]
lemma ltTrichotomy_gt (h : y < x) : ltTrichotomy x y p q r = r := ltByCases_gt h
@[simp]
lemma ltTrichotomy_eq (h : x = y) : ltTrichotomy x y p q r = q := ltByCases_eq h
lemma ltTrichotomy_not_lt (h : ¬ x < y) :
ltTrichotomy x y p q r = if y < x then r else q := ltByCases_not_lt h
lemma ltTrichotomy_not_gt (h : ¬ y < x) :
ltTrichotomy x y p q r = if x < y then p else q := ltByCases_not_gt h
lemma ltTrichotomy_ne (h : x ≠ y) :
ltTrichotomy x y p q r = if x < y then p else r := ltByCases_ne h
lemma ltTrichotomy_comm : ltTrichotomy x y p q r = ltTrichotomy y x r q p := ltByCases_comm
lemma ltTrichotomy_self {p : P} : ltTrichotomy x y p p p = p :=
ltByCases_rec p (fun _ => rfl) (fun _ => rfl) (fun _ => rfl)
lemma ltTrichotomy_eq_iff : ltTrichotomy x y p q r = s ↔
(x < y ∧ p = s) ∨ (x = y ∧ q = s) ∨ (y < x ∧ r = s) := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· simp only [ltTrichotomy_lt, false_and, true_and, or_false, h, h.not_lt, h.ne]
· simp only [ltTrichotomy_eq, false_and, true_and, or_false, false_or, h, lt_irrefl]
· simp only [ltTrichotomy_gt, false_and, true_and, false_or, h, h.not_lt, h.ne']
lemma ltTrichotomy_congr {x' y' : α} {p' q' r' : P} (ltc : (x < y) ↔ (x' < y'))
(gtc : (y < x) ↔ (y' < x')) (hh'₁ : x' < y' → p = p')
(hh'₂ : x' = y' → q = q') (hh'₃ : y' < x' → r = r') :
ltTrichotomy x y p q r = ltTrichotomy x' y' p' q' r' :=
ltByCases_congr ltc gtc hh'₁ hh'₂ hh'₃
end ltByCases
/-! ### Order dual -/
/-- Type synonym to equip a type with the dual order: `≤` means `≥` and `<` means `>`. `αᵒᵈ` is
notation for `OrderDual α`. -/
def OrderDual (α : Type*) : Type _ :=
α
@[inherit_doc]
notation:max α "ᵒᵈ" => OrderDual α
namespace OrderDual
instance (α : Type*) [h : Nonempty α] : Nonempty αᵒᵈ :=
h
instance (α : Type*) [h : Subsingleton α] : Subsingleton αᵒᵈ :=
h
instance (α : Type*) [LE α] : LE αᵒᵈ :=
⟨fun x y : α ↦ y ≤ x⟩
instance (α : Type*) [LT α] : LT αᵒᵈ :=
⟨fun x y : α ↦ y < x⟩
instance instPreorder (α : Type*) [Preorder α] : Preorder αᵒᵈ where
le_refl := fun _ ↦ le_refl _
le_trans := fun _ _ _ hab hbc ↦ hbc.trans hab
lt_iff_le_not_le := fun _ _ ↦ lt_iff_le_not_le
instance instPartialOrder (α : Type*) [PartialOrder α] : PartialOrder αᵒᵈ where
__ := inferInstanceAs (Preorder αᵒᵈ)
le_antisymm := fun a b hab hba ↦ @le_antisymm α _ a b hba hab
instance instLinearOrder (α : Type*) [LinearOrder α] : LinearOrder αᵒᵈ where
__ := inferInstanceAs (PartialOrder αᵒᵈ)
le_total := fun a b : α ↦ le_total b a
max := fun a b ↦ (min a b : α)
min := fun a b ↦ (max a b : α)
min_def := fun a b ↦ show (max .. : α) = _ by rw [max_comm, max_def]; rfl
max_def := fun a b ↦ show (min .. : α) = _ by rw [min_comm, min_def]; rfl
decidableLE := (inferInstance : DecidableRel (fun a b : α ↦ b ≤ a))
decidableLT := (inferInstance : DecidableRel (fun a b : α ↦ b < a))
instance : ∀ [Inhabited α], Inhabited αᵒᵈ := fun [x : Inhabited α] => x
theorem Preorder.dual_dual (α : Type*) [H : Preorder α] : OrderDual.instPreorder αᵒᵈ = H :=
Preorder.ext fun _ _ ↦ Iff.rfl
theorem instPartialOrder.dual_dual (α : Type*) [H : PartialOrder α] :
OrderDual.instPartialOrder αᵒᵈ = H :=
PartialOrder.ext fun _ _ ↦ Iff.rfl
theorem instLinearOrder.dual_dual (α : Type*) [H : LinearOrder α] :
OrderDual.instLinearOrder αᵒᵈ = H :=
LinearOrder.ext fun _ _ ↦ Iff.rfl
end OrderDual
/-! ### `HasCompl` -/
instance Prop.hasCompl : HasCompl Prop :=
⟨Not⟩
instance Pi.hasCompl [∀ i, HasCompl (π i)] : HasCompl (∀ i, π i) :=
⟨fun x i ↦ (x i)ᶜ⟩
theorem Pi.compl_def [∀ i, HasCompl (π i)] (x : ∀ i, π i) :
xᶜ = fun i ↦ (x i)ᶜ :=
rfl
@[simp]
theorem Pi.compl_apply [∀ i, HasCompl (π i)] (x : ∀ i, π i) (i : ι) :
xᶜ i = (x i)ᶜ :=
rfl
instance IsIrrefl.compl (r) [IsIrrefl α r] : IsRefl α rᶜ :=
⟨@irrefl α r _⟩
instance IsRefl.compl (r) [IsRefl α r] : IsIrrefl α rᶜ :=
⟨fun a ↦ not_not_intro (refl a)⟩
/-! ### Order instances on the function space -/
instance Pi.hasLe [∀ i, LE (π i)] :
LE (∀ i, π i) where le x y := ∀ i, x i ≤ y i
theorem Pi.le_def [∀ i, LE (π i)] {x y : ∀ i, π i} :
x ≤ y ↔ ∀ i, x i ≤ y i :=
Iff.rfl
instance Pi.preorder [∀ i, Preorder (π i)] : Preorder (∀ i, π i) where
__ := inferInstanceAs (LE (∀ i, π i))
le_refl := fun a i ↦ le_refl (a i)
le_trans := fun a b c h₁ h₂ i ↦ le_trans (h₁ i) (h₂ i)
theorem Pi.lt_def [∀ i, Preorder (π i)] {x y : ∀ i, π i} :
x < y ↔ x ≤ y ∧ ∃ i, x i < y i := by
simp (config := { contextual := true }) [lt_iff_le_not_le, Pi.le_def]
instance Pi.partialOrder [∀ i, PartialOrder (π i)] : PartialOrder (∀ i, π i) where
__ := Pi.preorder
le_antisymm := fun _ _ h1 h2 ↦ funext fun b ↦ (h1 b).antisymm (h2 b)
namespace Sum
variable {α₁ α₂ : Type*} [LE β]
@[simp]
lemma elim_le_elim_iff {u₁ v₁ : α₁ → β} {u₂ v₂ : α₂ → β} :
Sum.elim u₁ u₂ ≤ Sum.elim v₁ v₂ ↔ u₁ ≤ v₁ ∧ u₂ ≤ v₂ :=
Sum.forall
lemma const_le_elim_iff {b : β} {v₁ : α₁ → β} {v₂ : α₂ → β} :
Function.const _ b ≤ Sum.elim v₁ v₂ ↔ Function.const _ b ≤ v₁ ∧ Function.const _ b ≤ v₂ :=
elim_const_const b ▸ elim_le_elim_iff ..
lemma elim_le_const_iff {b : β} {u₁ : α₁ → β} {u₂ : α₂ → β} :
Sum.elim u₁ u₂ ≤ Function.const _ b ↔ u₁ ≤ Function.const _ b ∧ u₂ ≤ Function.const _ b :=
elim_const_const b ▸ elim_le_elim_iff ..
end Sum
section Pi
/-- A function `a` is strongly less than a function `b` if `a i < b i` for all `i`. -/
def StrongLT [∀ i, LT (π i)] (a b : ∀ i, π i) : Prop :=
∀ i, a i < b i
@[inherit_doc]
local infixl:50 " ≺ " => StrongLT
variable [∀ i, Preorder (π i)] {a b c : ∀ i, π i}
theorem le_of_strongLT (h : a ≺ b) : a ≤ b := fun _ ↦ (h _).le
theorem lt_of_strongLT [Nonempty ι] (h : a ≺ b) : a < b := by
inhabit ι
exact Pi.lt_def.2 ⟨le_of_strongLT h, default, h _⟩
theorem strongLT_of_strongLT_of_le (hab : a ≺ b) (hbc : b ≤ c) : a ≺ c := fun _ ↦
(hab _).trans_le <| hbc _
theorem strongLT_of_le_of_strongLT (hab : a ≤ b) (hbc : b ≺ c) : a ≺ c := fun _ ↦
(hab _).trans_lt <| hbc _
alias StrongLT.le := le_of_strongLT
alias StrongLT.lt := lt_of_strongLT
alias StrongLT.trans_le := strongLT_of_strongLT_of_le
alias LE.le.trans_strongLT := strongLT_of_le_of_strongLT
end Pi
section Function
variable [DecidableEq ι] [∀ i, Preorder (π i)] {x y : ∀ i, π i} {i : ι} {a b : π i}
theorem le_update_iff : x ≤ Function.update y i a ↔ x i ≤ a ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j :=
Function.forall_update_iff _ fun j z ↦ x j ≤ z
theorem update_le_iff : Function.update x i a ≤ y ↔ a ≤ y i ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j :=
Function.forall_update_iff _ fun j z ↦ z ≤ y j
theorem update_le_update_iff :
Function.update x i a ≤ Function.update y i b ↔ a ≤ b ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j := by
simp (config := { contextual := true }) [update_le_iff]
@[simp]
theorem update_le_update_iff' : update x i a ≤ update x i b ↔ a ≤ b := by
simp [update_le_update_iff]
@[simp]
theorem update_lt_update_iff : update x i a < update x i b ↔ a < b :=
lt_iff_lt_of_le_iff_le' update_le_update_iff' update_le_update_iff'
@[simp]
theorem le_update_self_iff : x ≤ update x i a ↔ x i ≤ a := by simp [le_update_iff]
@[simp]
theorem update_le_self_iff : update x i a ≤ x ↔ a ≤ x i := by simp [update_le_iff]
@[simp]
theorem lt_update_self_iff : x < update x i a ↔ x i < a := by simp [lt_iff_le_not_le]
@[simp]
theorem update_lt_self_iff : update x i a < x ↔ a < x i := by simp [lt_iff_le_not_le]
end Function
instance Pi.sdiff [∀ i, SDiff (π i)] : SDiff (∀ i, π i) :=
⟨fun x y i ↦ x i \ y i⟩
theorem Pi.sdiff_def [∀ i, SDiff (π i)] (x y : ∀ i, π i) :
x \ y = fun i ↦ x i \ y i :=
rfl
@[simp]
theorem Pi.sdiff_apply [∀ i, SDiff (π i)] (x y : ∀ i, π i) (i : ι) :
(x \ y) i = x i \ y i :=
rfl
namespace Function
variable [Preorder α] [Nonempty β] {a b : α}
@[simp]
theorem const_le_const : const β a ≤ const β b ↔ a ≤ b := by simp [Pi.le_def]
@[simp]
theorem const_lt_const : const β a < const β b ↔ a < b := by simpa [Pi.lt_def] using le_of_lt
end Function
/-! ### `min`/`max` recursors -/
section MinMaxRec
variable [LinearOrder α] {p : α → Prop} {x y : α}
theorem min_rec (hx : x ≤ y → p x) (hy : y ≤ x → p y) : p (min x y) :=
(le_total x y).rec (fun h ↦ (min_eq_left h).symm.subst (hx h)) fun h ↦
(min_eq_right h).symm.subst (hy h)
theorem max_rec (hx : y ≤ x → p x) (hy : x ≤ y → p y) : p (max x y) :=
@min_rec αᵒᵈ _ _ _ _ hx hy
theorem min_rec' (p : α → Prop) (hx : p x) (hy : p y) : p (min x y) :=
min_rec (fun _ ↦ hx) fun _ ↦ hy
theorem max_rec' (p : α → Prop) (hx : p x) (hy : p y) : p (max x y) :=
max_rec (fun _ ↦ hx) fun _ ↦ hy
theorem min_def_lt (x y : α) : min x y = if x < y then x else y := by
rw [min_comm, min_def, ← ite_not]
simp only [not_le]
theorem max_def_lt (x y : α) : max x y = if x < y then y else x := by
rw [max_comm, max_def, ← ite_not]
simp only [not_le]
end MinMaxRec
/-! ### Lifts of order instances -/
/-- Transfer a `Preorder` on `β` to a `Preorder` on `α` using a function `f : α → β`.
See note [reducible non-instances]. -/
abbrev Preorder.lift [Preorder β] (f : α → β) : Preorder α where
le x y := f x ≤ f y
le_refl _ := le_rfl
le_trans _ _ _ := _root_.le_trans
lt x y := f x < f y
lt_iff_le_not_le _ _ := _root_.lt_iff_le_not_le
/-- Transfer a `PartialOrder` on `β` to a `PartialOrder` on `α` using an injective
function `f : α → β`. See note [reducible non-instances]. -/
abbrev PartialOrder.lift [PartialOrder β] (f : α → β) (inj : Injective f) : PartialOrder α :=
{ Preorder.lift f with le_antisymm := fun _ _ h₁ h₂ ↦ inj (h₁.antisymm h₂) }
theorem compare_of_injective_eq_compareOfLessAndEq (a b : α) [LinearOrder β]
[DecidableEq α] (f : α → β) (inj : Injective f)
[Decidable (LT.lt (self := PartialOrder.lift f inj |>.toLT) a b)] :
compare (f a) (f b) =
@compareOfLessAndEq _ a b (PartialOrder.lift f inj |>.toLT) _ _ := by
have h := LinearOrder.compare_eq_compareOfLessAndEq (f a) (f b)
simp only [h, compareOfLessAndEq]
split_ifs <;> try (first | rfl | contradiction)
· have : ¬ f a = f b := by rename_i h; exact inj.ne h
contradiction
· have : f a = f b := by rename_i h; exact congrArg f h
contradiction
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version takes `[Sup α]` and `[Inf α]` as arguments, then uses
them for `max` and `min` fields. See `LinearOrder.lift'` for a version that autogenerates `min` and
`max` fields, and `LinearOrder.liftWithOrd` for one that does not auto-generate `compare`
fields. See note [reducible non-instances]. -/
abbrev LinearOrder.lift [LinearOrder β] [Sup α] [Inf α] (f : α → β) (inj : Injective f)
(hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) :
LinearOrder α :=
letI instOrdα : Ord α := ⟨fun a b ↦ compare (f a) (f b)⟩
letI decidableLE := fun x y ↦ (inferInstance : Decidable (f x ≤ f y))
letI decidableLT := fun x y ↦ (inferInstance : Decidable (f x < f y))
letI decidableEq := fun x y ↦ decidable_of_iff (f x = f y) inj.eq_iff
{ PartialOrder.lift f inj, instOrdα with
le_total := fun x y ↦ le_total (f x) (f y)
decidableLE := decidableLE
decidableLT := decidableLT
decidableEq := decidableEq
min := (· ⊓ ·)
max := (· ⊔ ·)
min_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hinf _ _).trans (min_def _ _)
max_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hsup _ _).trans (max_def _ _)
compare_eq_compareOfLessAndEq := fun a b ↦
compare_of_injective_eq_compareOfLessAndEq a b f inj }
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version autogenerates `min` and `max` fields. See `LinearOrder.lift`
for a version that takes `[Sup α]` and `[Inf α]`, then uses them as `max` and `min`. See
`LinearOrder.liftWithOrd'` for a version which does not auto-generate `compare` fields.
See note [reducible non-instances]. -/
abbrev LinearOrder.lift' [LinearOrder β] (f : α → β) (inj : Injective f) : LinearOrder α :=
@LinearOrder.lift α β _ ⟨fun x y ↦ if f x ≤ f y then y else x⟩
⟨fun x y ↦ if f x ≤ f y then x else y⟩ f inj
(fun _ _ ↦ (apply_ite f _ _ _).trans (max_def _ _).symm) fun _ _ ↦
(apply_ite f _ _ _).trans (min_def _ _).symm
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version takes `[Sup α]` and `[Inf α]` as arguments, then uses
them for `max` and `min` fields. It also takes `[Ord α]` as an argument and uses them for `compare`
fields. See `LinearOrder.lift` for a version that autogenerates `compare` fields, and
`LinearOrder.liftWithOrd'` for one that auto-generates `min` and `max` fields.
fields. See note [reducible non-instances]. -/
abbrev LinearOrder.liftWithOrd [LinearOrder β] [Sup α] [Inf α] [Ord α] (f : α → β)
(inj : Injective f) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y))
(hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y))
(compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α :=
letI decidableLE := fun x y ↦ (inferInstance : Decidable (f x ≤ f y))
letI decidableLT := fun x y ↦ (inferInstance : Decidable (f x < f y))
letI decidableEq := fun x y ↦ decidable_of_iff (f x = f y) inj.eq_iff
{ PartialOrder.lift f inj with
le_total := fun x y ↦ le_total (f x) (f y)
decidableLE := decidableLE
decidableLT := decidableLT
decidableEq := decidableEq
min := (· ⊓ ·)
max := (· ⊔ ·)
min_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hinf _ _).trans (min_def _ _)
max_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hsup _ _).trans (max_def _ _)
compare_eq_compareOfLessAndEq := fun a b ↦
(compare_f a b).trans <| compare_of_injective_eq_compareOfLessAndEq a b f inj }
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version auto-generates `min` and `max` fields. It also takes `[Ord α]`
as an argument and uses them for `compare` fields. See `LinearOrder.lift` for a version that
autogenerates `compare` fields, and `LinearOrder.liftWithOrd` for one that doesn't auto-generate
`min` and `max` fields. fields. See note [reducible non-instances]. -/
abbrev LinearOrder.liftWithOrd' [LinearOrder β] [Ord α] (f : α → β)
(inj : Injective f)
(compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α :=
@LinearOrder.liftWithOrd α β _ ⟨fun x y ↦ if f x ≤ f y then y else x⟩
⟨fun x y ↦ if f x ≤ f y then x else y⟩ _ f inj
(fun _ _ ↦ (apply_ite f _ _ _).trans (max_def _ _).symm)
(fun _ _ ↦ (apply_ite f _ _ _).trans (min_def _ _).symm)
compare_f
/-! ### Subtype of an order -/
namespace Subtype
instance le [LE α] {p : α → Prop} : LE (Subtype p) :=
⟨fun x y ↦ (x : α) ≤ y⟩
instance lt [LT α] {p : α → Prop} : LT (Subtype p) :=
⟨fun x y ↦ (x : α) < y⟩
@[simp]
theorem mk_le_mk [LE α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} :
(⟨x, hx⟩ : Subtype p) ≤ ⟨y, hy⟩ ↔ x ≤ y :=
Iff.rfl
@[simp]
theorem mk_lt_mk [LT α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} :
(⟨x, hx⟩ : Subtype p) < ⟨y, hy⟩ ↔ x < y :=
Iff.rfl
@[simp, norm_cast]
theorem coe_le_coe [LE α] {p : α → Prop} {x y : Subtype p} : (x : α) ≤ y ↔ x ≤ y :=
Iff.rfl
@[simp, norm_cast]
theorem coe_lt_coe [LT α] {p : α → Prop} {x y : Subtype p} : (x : α) < y ↔ x < y :=
Iff.rfl
instance preorder [Preorder α] (p : α → Prop) : Preorder (Subtype p) :=
Preorder.lift (fun (a : Subtype p) ↦ (a : α))
instance partialOrder [PartialOrder α] (p : α → Prop) : PartialOrder (Subtype p) :=
PartialOrder.lift (fun (a : Subtype p) ↦ (a : α)) Subtype.coe_injective
instance decidableLE [Preorder α] [h : @DecidableRel α (· ≤ ·)] {p : α → Prop} :
@DecidableRel (Subtype p) (· ≤ ·) := fun a b ↦ h a b
instance decidableLT [Preorder α] [h : @DecidableRel α (· < ·)] {p : α → Prop} :
@DecidableRel (Subtype p) (· < ·) := fun a b ↦ h a b
/-- A subtype of a linear order is a linear order. We explicitly give the proofs of decidable
equality and decidable order in order to ensure the decidability instances are all definitionally
equal. -/
instance instLinearOrder [LinearOrder α] (p : α → Prop) : LinearOrder (Subtype p) :=
@LinearOrder.lift (Subtype p) _ _ ⟨fun x y ↦ ⟨max x y, max_rec' _ x.2 y.2⟩⟩
⟨fun x y ↦ ⟨min x y, min_rec' _ x.2 y.2⟩⟩ (fun (a : Subtype p) ↦ (a : α))
Subtype.coe_injective (fun _ _ ↦ rfl) fun _ _ ↦
rfl
end Subtype
/-!
### Pointwise order on `α × β`
The lexicographic order is defined in `Data.Prod.Lex`, and the instances are available via the
type synonym `α ×ₗ β = α × β`.
-/
namespace Prod
instance (α β : Type*) [LE α] [LE β] : LE (α × β) :=
⟨fun p q ↦ p.1 ≤ q.1 ∧ p.2 ≤ q.2⟩
-- Porting note (#10754): new instance
instance instDecidableLE (α β : Type*) [LE α] [LE β] (x y : α × β)
[Decidable (x.1 ≤ y.1)] [Decidable (x.2 ≤ y.2)] : Decidable (x ≤ y) := And.decidable
theorem le_def [LE α] [LE β] {x y : α × β} : x ≤ y ↔ x.1 ≤ y.1 ∧ x.2 ≤ y.2 :=
Iff.rfl
@[simp]
theorem mk_le_mk [LE α] [LE β] {x₁ x₂ : α} {y₁ y₂ : β} : (x₁, y₁) ≤ (x₂, y₂) ↔ x₁ ≤ x₂ ∧ y₁ ≤ y₂ :=
Iff.rfl
@[simp]
theorem swap_le_swap [LE α] [LE β] {x y : α × β} : x.swap ≤ y.swap ↔ x ≤ y :=
and_comm
section Preorder
variable [Preorder α] [Preorder β] {a a₁ a₂ : α} {b b₁ b₂ : β} {x y : α × β}
instance (α β : Type*) [Preorder α] [Preorder β] : Preorder (α × β) where
__ := inferInstanceAs (LE (α × β))
le_refl := fun ⟨a, b⟩ ↦ ⟨le_refl a, le_refl b⟩
le_trans := fun ⟨a, b⟩ ⟨c, d⟩ ⟨e, f⟩ ⟨hac, hbd⟩ ⟨hce, hdf⟩ ↦ ⟨le_trans hac hce, le_trans hbd hdf⟩
@[simp]
theorem swap_lt_swap : x.swap < y.swap ↔ x < y :=
and_congr swap_le_swap (not_congr swap_le_swap)
theorem mk_le_mk_iff_left : (a₁, b) ≤ (a₂, b) ↔ a₁ ≤ a₂ :=
and_iff_left le_rfl
theorem mk_le_mk_iff_right : (a, b₁) ≤ (a, b₂) ↔ b₁ ≤ b₂ :=
and_iff_right le_rfl
theorem mk_lt_mk_iff_left : (a₁, b) < (a₂, b) ↔ a₁ < a₂ :=
lt_iff_lt_of_le_iff_le' mk_le_mk_iff_left mk_le_mk_iff_left
theorem mk_lt_mk_iff_right : (a, b₁) < (a, b₂) ↔ b₁ < b₂ :=
lt_iff_lt_of_le_iff_le' mk_le_mk_iff_right mk_le_mk_iff_right
theorem lt_iff : x < y ↔ x.1 < y.1 ∧ x.2 ≤ y.2 ∨ x.1 ≤ y.1 ∧ x.2 < y.2 := by
refine ⟨fun h ↦ ?_, ?_⟩
· by_cases h₁ : y.1 ≤ x.1
· exact Or.inr ⟨h.1.1, LE.le.lt_of_not_le h.1.2 fun h₂ ↦ h.2 ⟨h₁, h₂⟩⟩
· exact Or.inl ⟨LE.le.lt_of_not_le h.1.1 h₁, h.1.2⟩
· rintro (⟨h₁, h₂⟩ | ⟨h₁, h₂⟩)
· exact ⟨⟨h₁.le, h₂⟩, fun h ↦ h₁.not_le h.1⟩
· exact ⟨⟨h₁, h₂.le⟩, fun h ↦ h₂.not_le h.2⟩
@[simp]
theorem mk_lt_mk : (a₁, b₁) < (a₂, b₂) ↔ a₁ < a₂ ∧ b₁ ≤ b₂ ∨ a₁ ≤ a₂ ∧ b₁ < b₂ :=
lt_iff
protected lemma lt_of_lt_of_le (h₁ : x.1 < y.1) (h₂ : x.2 ≤ y.2) : x < y := by simp [lt_iff, *]
protected lemma lt_of_le_of_lt (h₁ : x.1 ≤ y.1) (h₂ : x.2 < y.2) : x < y := by simp [lt_iff, *]
lemma mk_lt_mk_of_lt_of_le (h₁ : a₁ < a₂) (h₂ : b₁ ≤ b₂) : (a₁, b₁) < (a₂, b₂) := by
simp [lt_iff, *]
lemma mk_lt_mk_of_le_of_lt (h₁ : a₁ ≤ a₂) (h₂ : b₁ < b₂) : (a₁, b₁) < (a₂, b₂) := by
simp [lt_iff, *]
end Preorder
/-- The pointwise partial order on a product.
(The lexicographic ordering is defined in `Order.Lexicographic`, and the instances are
available via the type synonym `α ×ₗ β = α × β`.) -/
instance instPartialOrder (α β : Type*) [PartialOrder α] [PartialOrder β] :
PartialOrder (α × β) where
__ := inferInstanceAs (Preorder (α × β))
le_antisymm := fun _ _ ⟨hac, hbd⟩ ⟨hca, hdb⟩ ↦ Prod.ext (hac.antisymm hca) (hbd.antisymm hdb)
end Prod
/-! ### Additional order classes -/
/-- An order is dense if there is an element between any pair of distinct comparable elements. -/
class DenselyOrdered (α : Type*) [LT α] : Prop where
/-- An order is dense if there is an element between any pair of distinct elements. -/
dense : ∀ a₁ a₂ : α, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂
theorem exists_between [LT α] [DenselyOrdered α] : ∀ {a₁ a₂ : α}, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂ :=
DenselyOrdered.dense _ _
instance OrderDual.denselyOrdered (α : Type*) [LT α] [h : DenselyOrdered α] :
DenselyOrdered αᵒᵈ :=
⟨fun _ _ ha ↦ (@exists_between α _ h _ _ ha).imp fun _ ↦ And.symm⟩
@[simp]
theorem denselyOrdered_orderDual [LT α] : DenselyOrdered αᵒᵈ ↔ DenselyOrdered α :=
⟨by convert @OrderDual.denselyOrdered αᵒᵈ _, @OrderDual.denselyOrdered α _⟩
instance [Preorder α] [Preorder β] [DenselyOrdered α] [DenselyOrdered β] : DenselyOrdered (α × β) :=
⟨fun a b ↦ by
simp_rw [Prod.lt_iff]
rintro (⟨h₁, h₂⟩ | ⟨h₁, h₂⟩)
· obtain ⟨c, ha, hb⟩ := exists_between h₁
exact ⟨(c, _), Or.inl ⟨ha, h₂⟩, Or.inl ⟨hb, le_rfl⟩⟩
· obtain ⟨c, ha, hb⟩ := exists_between h₂
exact ⟨(_, c), Or.inr ⟨h₁, ha⟩, Or.inr ⟨le_rfl, hb⟩⟩⟩
instance [∀ i, Preorder (π i)] [∀ i, DenselyOrdered (π i)] :
DenselyOrdered (∀ i, π i) :=
⟨fun a b ↦ by
classical
simp_rw [Pi.lt_def]
rintro ⟨hab, i, hi⟩
obtain ⟨c, ha, hb⟩ := exists_between hi
exact
⟨Function.update a i c,
⟨le_update_iff.2 ⟨ha.le, fun _ _ ↦ le_rfl⟩, i, by rwa [update_same]⟩,
update_le_iff.2 ⟨hb.le, fun _ _ ↦ hab _⟩, i, by rwa [update_same]⟩⟩
theorem le_of_forall_le_of_dense [LinearOrder α] [DenselyOrdered α] {a₁ a₂ : α}
(h : ∀ a, a₂ < a → a₁ ≤ a) : a₁ ≤ a₂ :=
le_of_not_gt fun ha ↦
let ⟨a, ha₁, ha₂⟩ := exists_between ha
lt_irrefl a <| lt_of_lt_of_le ‹a < a₁› (h _ ‹a₂ < a›)
theorem eq_of_le_of_forall_le_of_dense [LinearOrder α] [DenselyOrdered α] {a₁ a₂ : α} (h₁ : a₂ ≤ a₁)
(h₂ : ∀ a, a₂ < a → a₁ ≤ a) : a₁ = a₂ :=
le_antisymm (le_of_forall_le_of_dense h₂) h₁
theorem le_of_forall_ge_of_dense [LinearOrder α] [DenselyOrdered α] {a₁ a₂ : α}
(h : ∀ a₃ < a₁, a₃ ≤ a₂) : a₁ ≤ a₂ :=
le_of_not_gt fun ha ↦
let ⟨a, ha₁, ha₂⟩ := exists_between ha
lt_irrefl a <| lt_of_le_of_lt (h _ ‹a < a₁›) ‹a₂ < a›
theorem eq_of_le_of_forall_ge_of_dense [LinearOrder α] [DenselyOrdered α] {a₁ a₂ : α} (h₁ : a₂ ≤ a₁)
(h₂ : ∀ a₃ < a₁, a₃ ≤ a₂) : a₁ = a₂ :=
(le_of_forall_ge_of_dense h₂).antisymm h₁
theorem dense_or_discrete [LinearOrder α] (a₁ a₂ : α) :
(∃ a, a₁ < a ∧ a < a₂) ∨ (∀ a, a₁ < a → a₂ ≤ a) ∧ ∀ a < a₂, a ≤ a₁ :=
or_iff_not_imp_left.2 fun h ↦
⟨fun a ha₁ ↦ le_of_not_gt fun ha₂ ↦ h ⟨a, ha₁, ha₂⟩,
fun a ha₂ ↦ le_of_not_gt fun ha₁ ↦ h ⟨a, ha₁, ha₂⟩⟩
/-- If a linear order has no elements `x < y < z`, then it has at most two elements. -/
lemma eq_or_eq_or_eq_of_forall_not_lt_lt [LinearOrder α]
(h : ∀ ⦃x y z : α⦄, x < y → y < z → False) (x y z : α) : x = y ∨ y = z ∨ x = z := by
by_contra hne
simp only [not_or, ← Ne.eq_def] at hne
cases' hne.1.lt_or_lt with h₁ h₁ <;> cases' hne.2.1.lt_or_lt with h₂ h₂ <;>
cases' hne.2.2.lt_or_lt with h₃ h₃
exacts [h h₁ h₂, h h₂ h₃, h h₃ h₂, h h₃ h₁, h h₁ h₃, h h₂ h₃, h h₁ h₃, h h₂ h₁]
namespace PUnit
variable (a b : PUnit)
instance instLinearOrder : LinearOrder PUnit where
le := fun _ _ ↦ True
lt := fun _ _ ↦ False
max := fun _ _ ↦ unit
min := fun _ _ ↦ unit
decidableEq := inferInstance
decidableLE := fun _ _ ↦ Decidable.isTrue trivial
decidableLT := fun _ _ ↦ Decidable.isFalse id
le_refl := by intros; trivial
le_trans := by intros; trivial
le_total := by intros; exact Or.inl trivial
le_antisymm := by intros; rfl
lt_iff_le_not_le := by simp only [not_true, and_false, forall_const]
theorem max_eq : max a b = unit :=
rfl
theorem min_eq : min a b = unit :=
rfl
-- Porting note (#10618): simp can prove this @[simp]
protected theorem le : a ≤ b :=
trivial
-- Porting note (#10618): simp can prove this @[simp]
theorem not_lt : ¬a < b :=
not_false
instance : DenselyOrdered PUnit :=
⟨fun _ _ ↦ False.elim⟩
end PUnit
section «Prop»
/-- Propositions form a complete boolean algebra, where the `≤` relation is given by implication. -/
instance Prop.le : LE Prop :=
⟨(· → ·)⟩
@[simp]
theorem le_Prop_eq : ((· ≤ ·) : Prop → Prop → Prop) = (· → ·) :=
rfl
theorem subrelation_iff_le {r s : α → α → Prop} : Subrelation r s ↔ r ≤ s :=
Iff.rfl
instance Prop.partialOrder : PartialOrder Prop where
__ := Prop.le
le_refl _ := id
le_trans _ _ _ f g := g ∘ f
le_antisymm _ _ Hab Hba := propext ⟨Hab, Hba⟩
end «Prop»
/-! ### Linear order from a total partial order -/
/-- Type synonym to create an instance of `LinearOrder` from a `PartialOrder` and `IsTotal α (≤)` -/
def AsLinearOrder (α : Type*) :=
α
instance [Inhabited α] : Inhabited (AsLinearOrder α) :=
⟨(default : α)⟩
noncomputable instance AsLinearOrder.linearOrder [PartialOrder α] [IsTotal α (· ≤ ·)] :
LinearOrder (AsLinearOrder α) where
__ := inferInstanceAs (PartialOrder α)
le_total := @total_of α (· ≤ ·) _
decidableLE := Classical.decRel _
section dite
variable [One α] {p : Prop} [Decidable p] {a : p → α} {b : ¬ p → α}
@[to_additive dite_nonneg]
lemma one_le_dite [LE α] (ha : ∀ h, 1 ≤ a h) (hb : ∀ h, 1 ≤ b h) : 1 ≤ dite p a b := by
split; exacts [ha ‹_›, hb ‹_›]
@[to_additive]
lemma dite_le_one [LE α] (ha : ∀ h, a h ≤ 1) (hb : ∀ h, b h ≤ 1) : dite p a b ≤ 1 := by
split; exacts [ha ‹_›, hb ‹_›]
@[to_additive dite_pos]
lemma one_lt_dite [LT α] (ha : ∀ h, 1 < a h) (hb : ∀ h, 1 < b h) : 1 < dite p a b := by
split; exacts [ha ‹_›, hb ‹_›]
@[to_additive]
lemma dite_lt_one [LT α] (ha : ∀ h, a h < 1) (hb : ∀ h, b h < 1) : dite p a b < 1 := by
split; exacts [ha ‹_›, hb ‹_›]
end dite
section
variable [One α] {p : Prop} [Decidable p] {a b : α}
@[to_additive ite_nonneg]
lemma one_le_ite [LE α] (ha : 1 ≤ a) (hb : 1 ≤ b) : 1 ≤ ite p a b := by split <;> assumption
@[to_additive]
lemma ite_le_one [LE α] (ha : a ≤ 1) (hb : b ≤ 1) : ite p a b ≤ 1 := by split <;> assumption
@[to_additive ite_pos]
lemma one_lt_ite [LT α] (ha : 1 < a) (hb : 1 < b) : 1 < ite p a b := by split <;> assumption
@[to_additive]
lemma ite_lt_one [LT α] (ha : a < 1) (hb : b < 1) : ite p a b < 1 := by split <;> assumption
end
|
Order\Birkhoff.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Filipo A. E. Nuccio, Sam van Gool
-/
import Mathlib.Order.Interval.Finset.Basic
import Mathlib.Data.Fintype.Order
import Mathlib.Order.Irreducible
import Mathlib.Order.UpperLower.Basic
/-!
# Birkhoff representation
This file proves two facts which together are commonly referred to as "Birkhoff representation":
1. Any nonempty finite partial order is isomorphic to the partial order of sup-irreducible elements
in its lattice of lower sets.
2. Any nonempty finite distributive lattice is isomorphic to the lattice of lower sets of its
partial order of sup-irreducible elements.
## Main declarations
For a finite nonempty partial order `α`:
* `OrderEmbedding.supIrredLowerSet`: `α` is isomorphic to the order of its irreducible lower sets.
If `α` is moreover a distributive lattice:
* `OrderIso.lowerSetSupIrred`: `α` is isomorphic to the lattice of lower sets of its irreducible
elements.
* `OrderEmbedding.birkhoffSet`, `OrderEmbedding.birkhoffFinset`: Order embedding of `α` into the
powerset lattice of its irreducible elements.
* `LatticeHom.birkhoffSet`, `LatticeHom.birkhoffFinet`: Same as the previous two, but bundled as
an injective lattice homomorphism.
* `exists_birkhoff_representation`: `α` embeds into some powerset algebra. You should prefer using
this over the explicit Birkhoff embedding because the Birkhoff embedding is littered with
decidability footguns that this existential-packaged version can afford to avoid.
## See also
These results form the object part of finite Stone duality: the functorial contravariant
equivalence between the category of finite distributive lattices and the category of finite
partial orders. TODO: extend to morphisms.
## References
* [G. Birkhoff, *Rings of sets*][birkhoff1937]
## Tags
birkhoff, representation, stone duality, lattice embedding
-/
open Finset Function OrderDual UpperSet LowerSet
variable {α : Type*}
section PartialOrder
variable [PartialOrder α]
namespace UpperSet
variable {s : UpperSet α}
@[simp] lemma infIrred_Ici (a : α) : InfIrred (Ici a) := by
refine ⟨fun h ↦ Ici_ne_top h.eq_top, fun s t hst ↦ ?_⟩
have := mem_Ici_iff.2 (le_refl a)
rw [← hst] at this
exact this.imp (fun ha ↦ le_antisymm (le_Ici.2 ha) <| hst.ge.trans inf_le_left) fun ha ↦
le_antisymm (le_Ici.2 ha) <| hst.ge.trans inf_le_right
variable [Finite α]
@[simp] lemma infIrred_iff_of_finite : InfIrred s ↔ ∃ a, Ici a = s := by
refine ⟨fun hs ↦ ?_, ?_⟩
· obtain ⟨a, ha, has⟩ := (s : Set α).toFinite.exists_minimal_wrt id _ (coe_nonempty.2 hs.ne_top)
exact ⟨a, (hs.2 <| erase_inf_Ici ha <| by simpa [eq_comm] using has).resolve_left
(lt_erase.2 ha).ne'⟩
· rintro ⟨a, rfl⟩
exact infIrred_Ici _
end UpperSet
namespace LowerSet
variable {s : LowerSet α}
@[simp] lemma supIrred_Iic (a : α) : SupIrred (Iic a) := by
refine ⟨fun h ↦ Iic_ne_bot h.eq_bot, fun s t hst ↦ ?_⟩
have := mem_Iic_iff.2 (le_refl a)
rw [← hst] at this
exact this.imp (fun ha ↦ (le_sup_left.trans_eq hst).antisymm <| Iic_le.2 ha) fun ha ↦
(le_sup_right.trans_eq hst).antisymm <| Iic_le.2 ha
variable [Finite α]
@[simp] lemma supIrred_iff_of_finite : SupIrred s ↔ ∃ a, Iic a = s := by
refine ⟨fun hs ↦ ?_, ?_⟩
· obtain ⟨a, ha, has⟩ := (s : Set α).toFinite.exists_maximal_wrt id _ (coe_nonempty.2 hs.ne_bot)
exact ⟨a, (hs.2 <| erase_sup_Iic ha <| by simpa [eq_comm] using has).resolve_left
(erase_lt.2 ha).ne⟩
· rintro ⟨a, rfl⟩
exact supIrred_Iic _
end LowerSet
namespace OrderEmbedding
/-- The **Birkhoff Embedding** of a finite partial order as sup-irreducible elements in its
lattice of lower sets. -/
def supIrredLowerSet : α ↪o {s : LowerSet α // SupIrred s} where
toFun a := ⟨Iic a, supIrred_Iic _⟩
inj' _ := by simp
map_rel_iff' := by simp
/-- The **Birkhoff Embedding** of a finite partial order as inf-irreducible elements in its
lattice of lower sets. -/
def infIrredUpperSet : α ↪o {s : UpperSet α // InfIrred s} where
toFun a := ⟨Ici a, infIrred_Ici _⟩
inj' _ := by simp
map_rel_iff' := by simp
@[simp] lemma supIrredLowerSet_apply (a : α) : supIrredLowerSet a = ⟨Iic a, supIrred_Iic _⟩ := rfl
@[simp] lemma infIrredUpperSet_apply (a : α) : infIrredUpperSet a = ⟨Ici a, infIrred_Ici _⟩ := rfl
variable [Finite α]
lemma supIrredLowerSet_surjective : Surjective (supIrredLowerSet (α := α)) := by
aesop (add simp Surjective)
lemma infIrredUpperSet_surjective : Surjective (infIrredUpperSet (α := α)) := by
aesop (add simp Surjective)
end OrderEmbedding
namespace OrderIso
variable [Finite α]
/-- **Birkhoff Representation for partial orders.** Any partial order is isomorphic
to the partial order of sup-irreducible elements in its lattice of lower sets. -/
noncomputable def supIrredLowerSet : α ≃o {s : LowerSet α // SupIrred s} :=
RelIso.ofSurjective _ OrderEmbedding.supIrredLowerSet_surjective
/-- **Birkhoff Representation for partial orders.** Any partial order is isomorphic
to the partial order of inf-irreducible elements in its lattice of upper sets. -/
noncomputable def infIrredUpperSet : α ≃o {s : UpperSet α // InfIrred s} :=
RelIso.ofSurjective _ OrderEmbedding.infIrredUpperSet_surjective
@[simp] lemma supIrredLowerSet_apply (a : α) : supIrredLowerSet a = ⟨Iic a, supIrred_Iic _⟩ := rfl
@[simp] lemma infIrredUpperSet_apply (a : α) : infIrredUpperSet a = ⟨Ici a, infIrred_Ici _⟩ := rfl
end OrderIso
end PartialOrder
namespace OrderIso
section SemilatticeSup
variable [SemilatticeSup α] [OrderBot α] [Finite α]
@[simp] lemma supIrredLowerSet_symm_apply (s : {s : LowerSet α // SupIrred s}) [Fintype s] :
supIrredLowerSet.symm s = (s.1 : Set α).toFinset.sup id := by
classical
obtain ⟨s, hs⟩ := s
obtain ⟨a, rfl⟩ := supIrred_iff_of_finite.1 hs
cases nonempty_fintype α
have : LocallyFiniteOrder α := Fintype.toLocallyFiniteOrder
simp [symm_apply_eq]
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] [OrderTop α] [Finite α]
@[simp] lemma infIrredUpperSet_symm_apply (s : {s : UpperSet α // InfIrred s}) [Fintype s] :
infIrredUpperSet.symm s = (s.1 : Set α).toFinset.inf id := by
classical
obtain ⟨s, hs⟩ := s
obtain ⟨a, rfl⟩ := infIrred_iff_of_finite.1 hs
cases nonempty_fintype α
have : LocallyFiniteOrder α := Fintype.toLocallyFiniteOrder
simp [symm_apply_eq]
end SemilatticeInf
end OrderIso
section DistribLattice
variable [DistribLattice α] [Fintype α] [@DecidablePred α SupIrred]
open Classical in
/-- **Birkhoff Representation for finite distributive lattices**. Any nonempty finite distributive
lattice is isomorphic to the lattice of lower sets of its sup-irreducible elements. -/
noncomputable def OrderIso.lowerSetSupIrred [OrderBot α] : α ≃o LowerSet {a : α // SupIrred a} :=
Equiv.toOrderIso
{ toFun := fun a ↦ ⟨{b | ↑b ≤ a}, fun b c hcb hba ↦ hba.trans' hcb⟩
invFun := fun s ↦ (s : Set {a : α // SupIrred a}).toFinset.sup (↑)
left_inv := fun a ↦ by
refine le_antisymm (Finset.sup_le fun b ↦ Set.mem_toFinset.1) ?_
obtain ⟨s, rfl, hs⟩ := exists_supIrred_decomposition a
exact Finset.sup_le fun i hi ↦
le_sup_of_le (b := ⟨i, hs hi⟩) (Set.mem_toFinset.2 <| le_sup (f := id) hi) le_rfl
right_inv := fun s ↦ by
ext a
dsimp
refine ⟨fun ha ↦ ?_, fun ha ↦ ?_⟩
· obtain ⟨i, hi, ha⟩ := a.2.supPrime.le_finset_sup.1 ha
exact s.lower ha (Set.mem_toFinset.1 hi)
· dsimp
exact le_sup (Set.mem_toFinset.2 ha) }
(fun b c hbc d ↦ le_trans' hbc) fun s t hst ↦ Finset.sup_mono <| Set.toFinset_mono hst
namespace OrderEmbedding
/-- **Birkhoff's Representation Theorem**. Any finite distributive lattice can be embedded in a
powerset lattice. -/
noncomputable def birkhoffSet : α ↪o Set {a : α // SupIrred a} := by
by_cases h : IsEmpty α
· exact OrderEmbedding.ofIsEmpty
rw [not_isEmpty_iff] at h
have := Fintype.toOrderBot α
exact OrderIso.lowerSetSupIrred.toOrderEmbedding.trans ⟨⟨_, SetLike.coe_injective⟩, Iff.rfl⟩
/-- **Birkhoff's Representation Theorem**. Any finite distributive lattice can be embedded in a
powerset lattice. -/
noncomputable def birkhoffFinset : α ↪o Finset {a : α // SupIrred a} := by
exact birkhoffSet.trans Fintype.finsetOrderIsoSet.symm.toOrderEmbedding
@[simp] lemma coe_birkhoffFinset (a : α) : birkhoffFinset a = birkhoffSet a := by
classical
-- TODO: This should be a single `simp` call but `simp` refuses to use
-- `OrderIso.coe_toOrderEmbedding` and `Fintype.coe_finsetOrderIsoSet_symm`
simp [birkhoffFinset]
rw [OrderIso.coe_toOrderEmbedding, Fintype.coe_finsetOrderIsoSet_symm]
simp
@[simp] lemma birkhoffSet_sup (a b : α) : birkhoffSet (a ⊔ b) = birkhoffSet a ∪ birkhoffSet b := by
unfold OrderEmbedding.birkhoffSet; split <;> simp [eq_iff_true_of_subsingleton]
@[simp] lemma birkhoffSet_inf (a b : α) : birkhoffSet (a ⊓ b) = birkhoffSet a ∩ birkhoffSet b := by
unfold OrderEmbedding.birkhoffSet; split <;> simp [eq_iff_true_of_subsingleton]
@[simp] lemma birkhoffSet_apply [OrderBot α] (a : α) :
birkhoffSet a = OrderIso.lowerSetSupIrred a := by
simp [birkhoffSet]; have : Subsingleton (OrderBot α) := inferInstance; convert rfl
variable [DecidableEq α]
@[simp] lemma birkhoffFinset_sup (a b : α) :
birkhoffFinset (a ⊔ b) = birkhoffFinset a ∪ birkhoffFinset b := by
classical
dsimp [OrderEmbedding.birkhoffFinset]
rw [birkhoffSet_sup, OrderIso.coe_toOrderEmbedding]
simp
@[simp] lemma birkhoffFinset_inf (a b : α) :
birkhoffFinset (a ⊓ b) = birkhoffFinset a ∩ birkhoffFinset b := by
classical
dsimp [OrderEmbedding.birkhoffFinset]
rw [birkhoffSet_inf, OrderIso.coe_toOrderEmbedding]
simp
end OrderEmbedding
namespace LatticeHom
/-- **Birkhoff's Representation Theorem**. Any finite distributive lattice can be embedded in a
powerset lattice. -/
noncomputable def birkhoffSet : LatticeHom α (Set {a : α // SupIrred a}) where
toFun := OrderEmbedding.birkhoffSet
map_sup' := OrderEmbedding.birkhoffSet_sup
map_inf' := OrderEmbedding.birkhoffSet_inf
open Classical in
/-- **Birkhoff's Representation Theorem**. Any finite distributive lattice can be embedded in a
powerset lattice. -/
noncomputable def birkhoffFinset : LatticeHom α (Finset {a : α // SupIrred a}) where
toFun := OrderEmbedding.birkhoffFinset
map_sup' := OrderEmbedding.birkhoffFinset_sup
map_inf' := OrderEmbedding.birkhoffFinset_inf
lemma birkhoffFinset_injective : Injective (birkhoffFinset (α := α)) :=
OrderEmbedding.birkhoffFinset.injective
end LatticeHom
lemma exists_birkhoff_representation.{u} (α : Type u) [Finite α] [DistribLattice α] :
∃ (β : Type u) (_ : DecidableEq β) (_ : Fintype β) (f : LatticeHom α (Finset β)),
Injective f := by
classical
cases nonempty_fintype α
exact ⟨{a : α // SupIrred a}, _, inferInstance, _, LatticeHom.birkhoffFinset_injective⟩
end DistribLattice
|
Order\BooleanAlgebra.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Bryan Gin-ge Chen
-/
import Mathlib.Order.Heyting.Basic
/-!
# (Generalized) Boolean algebras
A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras
generalize the (classical) logic of propositions and the lattice of subsets of a set.
Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which
do not necessarily have a top element (`⊤`) (and hence not all elements may have complements). One
example in mathlib is `Finset α`, the type of all finite subsets of an arbitrary
(not-necessarily-finite) type `α`.
`GeneralizedBooleanAlgebra α` is defined to be a distributive lattice with bottom (`⊥`) admitting
a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`).
For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra`
so that it is also bundled with a `\` operator.
(A terminological point: `x \ y` is the complement of `y` relative to the interval `[⊥, x]`. We do
not yet have relative complements for arbitrary intervals, as we do not even have lattice
intervals.)
## Main declarations
* `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras
* `BooleanAlgebra`: a type class for Boolean algebras.
* `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop`
## Implementation notes
The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in
`GeneralizedBooleanAlgebra` are taken from
[Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations).
[Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative
complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption
that for all `a, b : α` where `a ≤ b`, the equations `x ⊔ a = b` and `x ⊓ a = ⊥` have a solution
`x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`.
## References
* <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations>
* [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935]
* [*Lattice Theory: Foundation*, George Grätzer][Gratzer2011]
## Tags
generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl
-/
open Function OrderDual
universe u v
variable {α : Type u} {β : Type*} {w x y z : α}
/-!
### Generalized Boolean algebras
Some of the lemmas in this section are from:
* [*Lattice Theory: Foundation*, George Grätzer][Gratzer2011]
* <https://ncatlab.org/nlab/show/relative+complement>
* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>
-/
/-- A generalized Boolean algebra is a distributive lattice with `⊥` and a relative complement
operation `\` (called `sdiff`, after "set difference") satisfying `(a ⊓ b) ⊔ (a \ b) = a` and
`(a ⊓ b) ⊓ (a \ b) = ⊥`, i.e. `a \ b` is the complement of `b` in `a`.
This is a generalization of Boolean algebras which applies to `Finset α` for arbitrary
(not-necessarily-`Fintype`) `α`. -/
class GeneralizedBooleanAlgebra (α : Type u) extends DistribLattice α, SDiff α, Bot α where
/-- For any `a`, `b`, `(a ⊓ b) ⊔ (a / b) = a` -/
sup_inf_sdiff : ∀ a b : α, a ⊓ b ⊔ a \ b = a
/-- For any `a`, `b`, `(a ⊓ b) ⊓ (a / b) = ⊥` -/
inf_inf_sdiff : ∀ a b : α, a ⊓ b ⊓ a \ b = ⊥
-- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`,
-- however we'd need another type class for lattices with bot, and all the API for that.
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra α]
@[simp]
theorem sup_inf_sdiff (x y : α) : x ⊓ y ⊔ x \ y = x :=
GeneralizedBooleanAlgebra.sup_inf_sdiff _ _
@[simp]
theorem inf_inf_sdiff (x y : α) : x ⊓ y ⊓ x \ y = ⊥ :=
GeneralizedBooleanAlgebra.inf_inf_sdiff _ _
@[simp]
theorem sup_sdiff_inf (x y : α) : x \ y ⊔ x ⊓ y = x := by rw [sup_comm, sup_inf_sdiff]
@[simp]
theorem inf_sdiff_inf (x y : α) : x \ y ⊓ (x ⊓ y) = ⊥ := by rw [inf_comm, inf_inf_sdiff]
-- see Note [lower instance priority]
instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot α where
__ := GeneralizedBooleanAlgebra.toBot
bot_le a := by
rw [← inf_inf_sdiff a a, inf_assoc]
exact inf_le_left
theorem disjoint_inf_sdiff : Disjoint (x ⊓ y) (x \ y) :=
disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le
-- TODO: in distributive lattices, relative complements are unique when they exist
theorem sdiff_unique (s : x ⊓ y ⊔ z = x) (i : x ⊓ y ⊓ z = ⊥) : x \ y = z := by
conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm]
rw [sup_comm] at s
conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm]
rw [inf_comm] at i
exact (eq_of_inf_eq_sup_eq i s).symm
-- Use `sdiff_le`
private theorem sdiff_le' : x \ y ≤ x :=
calc
x \ y ≤ x ⊓ y ⊔ x \ y := le_sup_right
_ = x := sup_inf_sdiff x y
-- Use `sdiff_sup_self`
private theorem sdiff_sup_self' : y \ x ⊔ x = y ⊔ x :=
calc
y \ x ⊔ x = y \ x ⊔ (x ⊔ x ⊓ y) := by rw [sup_inf_self]
_ = y ⊓ x ⊔ y \ x ⊔ x := by ac_rfl
_ = y ⊔ x := by rw [sup_inf_sdiff]
@[simp]
theorem sdiff_inf_sdiff : x \ y ⊓ y \ x = ⊥ :=
Eq.symm <|
calc
⊥ = x ⊓ y ⊓ x \ y := by rw [inf_inf_sdiff]
_ = x ⊓ (y ⊓ x ⊔ y \ x) ⊓ x \ y := by rw [sup_inf_sdiff]
_ = (x ⊓ (y ⊓ x) ⊔ x ⊓ y \ x) ⊓ x \ y := by rw [inf_sup_left]
_ = (y ⊓ (x ⊓ x) ⊔ x ⊓ y \ x) ⊓ x \ y := by ac_rfl
_ = (y ⊓ x ⊔ x ⊓ y \ x) ⊓ x \ y := by rw [inf_idem]
_ = x ⊓ y ⊓ x \ y ⊔ x ⊓ y \ x ⊓ x \ y := by rw [inf_sup_right, inf_comm x y]
_ = x ⊓ y \ x ⊓ x \ y := by rw [inf_inf_sdiff, bot_sup_eq]
_ = x ⊓ x \ y ⊓ y \ x := by ac_rfl
_ = x \ y ⊓ y \ x := by rw [inf_of_le_right sdiff_le']
theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) :=
disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le
@[simp]
theorem inf_sdiff_self_right : x ⊓ y \ x = ⊥ :=
calc
x ⊓ y \ x = (x ⊓ y ⊔ x \ y) ⊓ y \ x := by rw [sup_inf_sdiff]
_ = x ⊓ y ⊓ y \ x ⊔ x \ y ⊓ y \ x := by rw [inf_sup_right]
_ = ⊥ := by rw [inf_comm x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq]
@[simp]
theorem inf_sdiff_self_left : y \ x ⊓ x = ⊥ := by rw [inf_comm, inf_sdiff_self_right]
-- see Note [lower instance priority]
instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra :
GeneralizedCoheytingAlgebra α where
__ := ‹GeneralizedBooleanAlgebra α›
__ := GeneralizedBooleanAlgebra.toOrderBot
sdiff := (· \ ·)
sdiff_le_iff y x z :=
⟨fun h =>
le_of_inf_le_sup_le
(le_of_eq
(calc
y ⊓ y \ x = y \ x := inf_of_le_right sdiff_le'
_ = x ⊓ y \ x ⊔ z ⊓ y \ x := by
rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq]
_ = (x ⊔ z) ⊓ y \ x := by rw [← inf_sup_right]))
(calc
y ⊔ y \ x = y := sup_of_le_left sdiff_le'
_ ≤ y ⊔ (x ⊔ z) := le_sup_left
_ = y \ x ⊔ x ⊔ z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y]
_ = x ⊔ z ⊔ y \ x := by ac_rfl),
fun h =>
le_of_inf_le_sup_le
(calc
y \ x ⊓ x = ⊥ := inf_sdiff_self_left
_ ≤ z ⊓ x := bot_le)
(calc
y \ x ⊔ x = y ⊔ x := sdiff_sup_self'
_ ≤ x ⊔ z ⊔ x := sup_le_sup_right h x
_ ≤ z ⊔ x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩
theorem disjoint_sdiff_self_left : Disjoint (y \ x) x :=
disjoint_iff_inf_le.mpr inf_sdiff_self_left.le
theorem disjoint_sdiff_self_right : Disjoint x (y \ x) :=
disjoint_iff_inf_le.mpr inf_sdiff_self_right.le
lemma le_sdiff : x ≤ y \ z ↔ x ≤ y ∧ Disjoint x z :=
⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦
by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩
@[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y :=
⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩
/- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using
`Disjoint x (y \ x)` and `x ⊔ (y \ x) = y` as axioms. -/
theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x ⊔ z = y) : y \ x = z :=
have h : y ⊓ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le
sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot])
protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≤ y) (hs : y ≤ x ⊔ z) :
y \ x = z :=
sdiff_unique
(by
rw [← inf_eq_right] at hs
rwa [sup_inf_right, inf_sup_right, sup_comm x, inf_sup_self, inf_comm, sup_comm z,
hs, sup_eq_left])
(by rw [inf_assoc, hd.eq_bot, inf_bot_eq])
-- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff`
theorem disjoint_sdiff_iff_le (hz : z ≤ y) (hx : x ≤ y) : Disjoint z (y \ x) ↔ z ≤ x :=
⟨fun H =>
le_of_inf_le_sup_le (le_trans H.le_bot bot_le)
(by
rw [sup_sdiff_cancel_right hx]
refine le_trans (sup_le_sup_left sdiff_le z) ?_
rw [sup_eq_right.2 hz]),
fun H => disjoint_sdiff_self_right.mono_left H⟩
-- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff`
theorem le_iff_disjoint_sdiff (hz : z ≤ y) (hx : x ≤ y) : z ≤ x ↔ Disjoint z (y \ x) :=
(disjoint_sdiff_iff_le hz hx).symm
-- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff`
theorem inf_sdiff_eq_bot_iff (hz : z ≤ y) (hx : x ≤ y) : z ⊓ y \ x = ⊥ ↔ z ≤ x := by
rw [← disjoint_iff]
exact disjoint_sdiff_iff_le hz hx
-- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff`
theorem le_iff_eq_sup_sdiff (hz : z ≤ y) (hx : x ≤ y) : x ≤ z ↔ y = z ⊔ y \ x :=
⟨fun H => by
apply le_antisymm
· conv_lhs => rw [← sup_inf_sdiff y x]
apply sup_le_sup_right
rwa [inf_eq_right.2 hx]
· apply le_trans
· apply sup_le_sup_right hz
· rw [sup_sdiff_left],
fun H => by
conv_lhs at H => rw [← sup_sdiff_cancel_right hx]
refine le_of_inf_le_sup_le ?_ H.le
rw [inf_sdiff_self_right]
exact bot_le⟩
-- cf. `IsCompl.sup_inf`
theorem sdiff_sup : y \ (x ⊔ z) = y \ x ⊓ y \ z :=
sdiff_unique
(calc
y ⊓ (x ⊔ z) ⊔ y \ x ⊓ y \ z = (y ⊓ (x ⊔ z) ⊔ y \ x) ⊓ (y ⊓ (x ⊔ z) ⊔ y \ z) := by
rw [sup_inf_left]
_ = (y ⊓ x ⊔ y ⊓ z ⊔ y \ x) ⊓ (y ⊓ x ⊔ y ⊓ z ⊔ y \ z) := by rw [@inf_sup_left _ _ y]
_ = (y ⊓ z ⊔ (y ⊓ x ⊔ y \ x)) ⊓ (y ⊓ x ⊔ (y ⊓ z ⊔ y \ z)) := by ac_rfl
_ = (y ⊓ z ⊔ y) ⊓ (y ⊓ x ⊔ y) := by rw [sup_inf_sdiff, sup_inf_sdiff]
_ = (y ⊔ y ⊓ z) ⊓ (y ⊔ y ⊓ x) := by ac_rfl
_ = y := by rw [sup_inf_self, sup_inf_self, inf_idem])
(calc
y ⊓ (x ⊔ z) ⊓ (y \ x ⊓ y \ z) = (y ⊓ x ⊔ y ⊓ z) ⊓ (y \ x ⊓ y \ z) := by rw [inf_sup_left]
_ = y ⊓ x ⊓ (y \ x ⊓ y \ z) ⊔ y ⊓ z ⊓ (y \ x ⊓ y \ z) := by rw [inf_sup_right]
_ = y ⊓ x ⊓ y \ x ⊓ y \ z ⊔ y \ x ⊓ (y \ z ⊓ (y ⊓ z)) := by ac_rfl
_ = ⊥ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, inf_comm (y \ z),
inf_inf_sdiff, inf_bot_eq])
theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y ⊓ x = y ⊓ z :=
⟨fun h => eq_of_inf_eq_sup_eq (a := y \ x) (by rw [inf_inf_sdiff, h, inf_inf_sdiff])
(by rw [sup_inf_sdiff, h, sup_inf_sdiff]),
fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩
theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x :=
calc
x \ y = x ↔ x \ y = x \ ⊥ := by rw [sdiff_bot]
_ ↔ x ⊓ y = x ⊓ ⊥ := sdiff_eq_sdiff_iff_inf_eq_inf
_ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff]
theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by
rw [sdiff_eq_self_iff_disjoint, disjoint_comm]
theorem sdiff_lt (hx : y ≤ x) (hy : y ≠ ⊥) : x \ y < x := by
refine sdiff_le.lt_of_ne fun h => hy ?_
rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h
rw [← h, inf_eq_right.mpr hx]
@[simp]
theorem le_sdiff_iff : x ≤ y \ x ↔ x = ⊥ :=
⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩
@[simp] lemma sdiff_eq_right : x \ y = y ↔ x = ⊥ ∧ y = ⊥ := by
rw [disjoint_sdiff_self_left.eq_iff]; aesop
lemma sdiff_ne_right : x \ y ≠ y ↔ x ≠ ⊥ ∨ y ≠ ⊥ := sdiff_eq_right.not.trans not_and_or
theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≤ x) : x \ z < y \ z :=
(sdiff_le_sdiff_right h.le).lt_of_not_le
fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz
theorem sup_inf_inf_sdiff : x ⊓ y ⊓ z ⊔ y \ z = x ⊓ y ⊔ y \ z :=
calc
x ⊓ y ⊓ z ⊔ y \ z = x ⊓ (y ⊓ z) ⊔ y \ z := by rw [inf_assoc]
_ = (x ⊔ y \ z) ⊓ y := by rw [sup_inf_right, sup_inf_sdiff]
_ = x ⊓ y ⊔ y \ z := by rw [inf_sup_right, inf_sdiff_left]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y ⊔ x ⊓ y ⊓ z := by
rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff]
apply sdiff_unique
· calc
x ⊓ y \ z ⊔ (z ⊓ x ⊔ x \ y) = (x ⊔ (z ⊓ x ⊔ x \ y)) ⊓ (y \ z ⊔ (z ⊓ x ⊔ x \ y)) := by
rw [sup_inf_right]
_ = (x ⊔ x ⊓ z ⊔ x \ y) ⊓ (y \ z ⊔ (x ⊓ z ⊔ x \ y)) := by ac_rfl
_ = x ⊓ (y \ z ⊔ x ⊓ z ⊔ x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc]
_ = x ⊓ (y \ z ⊓ (z ⊔ y) ⊔ x ⊓ (z ⊔ y) ⊔ x \ y) := by
rw [sup_inf_left, sdiff_sup_self', inf_sup_right, sup_comm y]
_ = x ⊓ (y \ z ⊔ (x ⊓ z ⊔ x ⊓ y) ⊔ x \ y) := by
rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y]
_ = x ⊓ (y \ z ⊔ (x ⊓ z ⊔ (x ⊓ y ⊔ x \ y))) := by ac_rfl
_ = x ⊓ (y \ z ⊔ (x ⊔ x ⊓ z)) := by rw [sup_inf_sdiff, sup_comm (x ⊓ z)]
_ = x := by rw [sup_inf_self, sup_comm, inf_sup_self]
· calc
x ⊓ y \ z ⊓ (z ⊓ x ⊔ x \ y) = x ⊓ y \ z ⊓ (z ⊓ x) ⊔ x ⊓ y \ z ⊓ x \ y := by rw [inf_sup_left]
_ = x ⊓ (y \ z ⊓ z ⊓ x) ⊔ x ⊓ y \ z ⊓ x \ y := by ac_rfl
_ = x ⊓ y \ z ⊓ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq]
_ = x ⊓ (y \ z ⊓ y) ⊓ x \ y := by conv_lhs => rw [← inf_sdiff_left]
_ = x ⊓ (y \ z ⊓ (y ⊓ x \ y)) := by ac_rfl
_ = ⊥ := by rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq]
theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y ⊔ x ⊓ z :=
calc
x \ (y \ z) = x \ y ⊔ x ⊓ y ⊓ z := sdiff_sdiff_right
_ = z ⊓ x ⊓ y ⊔ x \ y := by ac_rfl
_ = x \ y ⊔ x ⊓ z := by rw [sup_inf_inf_sdiff, sup_comm, inf_comm]
theorem sdiff_sdiff_eq_sdiff_sup (h : z ≤ x) : x \ (y \ z) = x \ y ⊔ z := by
rw [sdiff_sdiff_right', inf_eq_right.2 h]
@[simp]
theorem sdiff_sdiff_right_self : x \ (x \ y) = x ⊓ y := by
rw [sdiff_sdiff_right, inf_idem, sdiff_self, bot_sup_eq]
theorem sdiff_sdiff_eq_self (h : y ≤ x) : x \ (x \ y) = y := by
rw [sdiff_sdiff_right_self, inf_of_le_right h]
theorem sdiff_eq_symm (hy : y ≤ x) (h : x \ y = z) : x \ z = y := by
rw [← h, sdiff_sdiff_eq_self hy]
theorem sdiff_eq_comm (hy : y ≤ x) (hz : z ≤ x) : x \ y = z ↔ x \ z = y :=
⟨sdiff_eq_symm hy, sdiff_eq_symm hz⟩
theorem eq_of_sdiff_eq_sdiff (hxz : x ≤ z) (hyz : y ≤ z) (h : z \ x = z \ y) : x = y := by
rw [← sdiff_sdiff_eq_self hxz, h, sdiff_sdiff_eq_self hyz]
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y ⊓ x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y ⊔ y \ x) = z ⊓ (z \ x ⊔ y) ⊓ (z \ y ⊔ x) :=
calc
z \ (x \ y ⊔ y \ x) = (z \ x ⊔ z ⊓ x ⊓ y) ⊓ (z \ y ⊔ z ⊓ y ⊓ x) := by
rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z ⊓ (z \ x ⊔ y) ⊓ (z \ y ⊔ z ⊓ y ⊓ x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z ⊓ (z \ x ⊔ y) ⊓ (z ⊓ (z \ y ⊔ x)) := by
rw [sup_inf_left, sup_comm (z \ y), sup_inf_sdiff]
_ = z ⊓ z ⊓ (z \ x ⊔ y) ⊓ (z \ y ⊔ x) := by ac_rfl
_ = z ⊓ (z \ x ⊔ y) ⊓ (z \ y ⊔ x) := by rw [inf_idem]
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y ⊔ y \ x) = z ⊓ x ⊓ y ⊔ z \ x ⊓ z \ y :=
calc
z \ (x \ y ⊔ y \ x) = z \ (x \ y) ⊓ z \ (y \ x) := sdiff_sup
_ = (z \ x ⊔ z ⊓ x ⊓ y) ⊓ (z \ y ⊔ z ⊓ y ⊓ x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x ⊔ z ⊓ y ⊓ x) ⊓ (z \ y ⊔ z ⊓ y ⊓ x) := by ac_rfl
_ = z \ x ⊓ z \ y ⊔ z ⊓ y ⊓ x := by rw [← sup_inf_right]
_ = z ⊓ x ⊓ y ⊔ z \ x ⊓ z \ y := by ac_rfl
lemma sdiff_sdiff_sdiff_cancel_left (hca : z ≤ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z ≤ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact ⟨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcb⟩
theorem inf_sdiff : (x ⊓ y) \ z = x \ z ⊓ y \ z :=
sdiff_unique
(calc
x ⊓ y ⊓ z ⊔ x \ z ⊓ y \ z = (x ⊓ y ⊓ z ⊔ x \ z) ⊓ (x ⊓ y ⊓ z ⊔ y \ z) := by rw [sup_inf_left]
_ = (x ⊓ y ⊓ (z ⊔ x) ⊔ x \ z) ⊓ (x ⊓ y ⊓ z ⊔ y \ z) := by
rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y ⊓ (x ⊓ (x ⊔ z)) ⊔ x \ z) ⊓ (x ⊓ y ⊓ z ⊔ y \ z) := by ac_rfl
_ = (y ⊓ x ⊔ x \ z) ⊓ (x ⊓ y ⊔ y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x ⊓ y ⊔ x \ z ⊓ y \ z := by rw [inf_comm y, sup_inf_left]
_ = x ⊓ y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x ⊓ y ⊓ z ⊓ (x \ z ⊓ y \ z) = x ⊓ y ⊓ (z ⊓ x \ z) ⊓ y \ z := by ac_rfl
_ = ⊥ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
theorem inf_sdiff_assoc : (x ⊓ y) \ z = x ⊓ y \ z :=
sdiff_unique
(calc
x ⊓ y ⊓ z ⊔ x ⊓ y \ z = x ⊓ (y ⊓ z) ⊔ x ⊓ y \ z := by rw [inf_assoc]
_ = x ⊓ (y ⊓ z ⊔ y \ z) := by rw [← inf_sup_left]
_ = x ⊓ y := by rw [sup_inf_sdiff])
(calc
x ⊓ y ⊓ z ⊓ (x ⊓ y \ z) = x ⊓ x ⊓ (y ⊓ z ⊓ y \ z) := by ac_rfl
_ = ⊥ := by rw [inf_inf_sdiff, inf_bot_eq])
theorem inf_sdiff_right_comm : x \ z ⊓ y = (x ⊓ y) \ z := by
rw [inf_comm x, inf_comm, inf_sdiff_assoc]
theorem inf_sdiff_distrib_left (a b c : α) : a ⊓ b \ c = (a ⊓ b) \ (a ⊓ c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
theorem inf_sdiff_distrib_right (a b c : α) : a \ b ⊓ c = (a ⊓ c) \ (b ⊓ c) := by
simp_rw [inf_comm _ c, inf_sdiff_distrib_left]
theorem disjoint_sdiff_comm : Disjoint (x \ z) y ↔ Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x ⊔ y = x \ y ⊔ y \ x ⊔ x ⊓ y :=
Eq.symm <|
calc
x \ y ⊔ y \ x ⊔ x ⊓ y = (x \ y ⊔ y \ x ⊔ x) ⊓ (x \ y ⊔ y \ x ⊔ y) := by rw [sup_inf_left]
_ = (x \ y ⊔ x ⊔ y \ x) ⊓ (x \ y ⊔ (y \ x ⊔ y)) := by ac_rfl
_ = (x ⊔ y \ x) ⊓ (x \ y ⊔ y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x ⊔ y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x ≤ z) : x ⊔ y < z := by
rw [← sup_sdiff_cancel_right hxz]
refine (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le ?_
rw [← sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y ≤ z) : x ⊔ y < z := by
rw [← sdiff_sup_cancel hyz]
refine (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le ?_
rw [← sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra β] :
GeneralizedBooleanAlgebra (α × β) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ι : Type*} {α : ι → Type*}
[∀ i, GeneralizedBooleanAlgebra (α i)] : GeneralizedBooleanAlgebra (∀ i, α i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `ᶜ` such that
`x ⊓ xᶜ = ⊥` and `x ⊔ xᶜ = ⊤`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `⇨` satisfying `x \ y = x ⊓ yᶜ` and `x ⇨ y = y ⊔ xᶜ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (α : Type u) extends
DistribLattice α, HasCompl α, SDiff α, HImp α, Top α, Bot α where
/-- The infimum of `x` and `xᶜ` is at most `⊥` -/
inf_compl_le_bot : ∀ x : α, x ⊓ xᶜ ≤ ⊥
/-- The supremum of `x` and `xᶜ` is at least `⊤` -/
top_le_sup_compl : ∀ x : α, ⊤ ≤ x ⊔ xᶜ
/-- `⊤` is the greatest element -/
le_top : ∀ a : α, a ≤ ⊤
/-- `⊥` is the least element -/
bot_le : ∀ a : α, ⊥ ≤ a
/-- `x \ y` is equal to `x ⊓ yᶜ` -/
sdiff := fun x y => x ⊓ yᶜ
/-- `x ⇨ y` is equal to `y ⊔ xᶜ` -/
himp := fun x y => y ⊔ xᶜ
/-- `x \ y` is equal to `x ⊓ yᶜ` -/
sdiff_eq : ∀ x y : α, x \ y = x ⊓ yᶜ := by aesop
/-- `x ⇨ y` is equal to `y ⊔ xᶜ` -/
himp_eq : ∀ x y : α, x ⇨ y = y ⊔ xᶜ := by aesop
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra α] : BoundedOrder α :=
{ h with }
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
abbrev GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra α] [OrderTop α] :
BooleanAlgebra α where
__ := ‹GeneralizedBooleanAlgebra α›
__ := GeneralizedBooleanAlgebra.toOrderBot
__ := ‹OrderTop α›
compl a := ⊤ \ a
inf_compl_le_bot _ := disjoint_sdiff_self_right.le_bot
top_le_sup_compl _ := le_sup_sdiff
sdiff_eq _ _ := by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [← inf_sdiff_assoc, inf_top_eq]
section BooleanAlgebra
variable [BooleanAlgebra α]
theorem inf_compl_eq_bot' : x ⊓ xᶜ = ⊥ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
@[simp]
theorem sup_compl_eq_top : x ⊔ xᶜ = ⊤ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
@[simp]
theorem compl_sup_eq_top : xᶜ ⊔ x = ⊤ := by rw [sup_comm, sup_compl_eq_top]
theorem isCompl_compl : IsCompl x xᶜ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
theorem sdiff_eq : x \ y = x ⊓ yᶜ :=
BooleanAlgebra.sdiff_eq x y
theorem himp_eq : x ⇨ y = y ⊔ xᶜ :=
BooleanAlgebra.himp_eq x y
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice α :=
⟨fun x => ⟨xᶜ, isCompl_compl⟩⟩
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra α where
__ := ‹BooleanAlgebra α›
sup_inf_sdiff a b := by rw [sdiff_eq, ← inf_sup_left, sup_compl_eq_top, inf_top_eq]
inf_inf_sdiff a b := by
rw [sdiff_eq, ← inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq]
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra α where
__ := ‹BooleanAlgebra α›
__ := GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra
hnot := compl
le_himp_iff a b c := by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le]
himp_bot _ := _root_.himp_eq.trans (bot_sup_eq _)
top_sdiff a := by rw [sdiff_eq, top_inf_eq]; rfl
@[simp]
theorem hnot_eq_compl : ¬x = xᶜ :=
rfl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : ⊤ \ x = xᶜ :=
top_sdiff' x
theorem eq_compl_iff_isCompl : x = yᶜ ↔ IsCompl x y :=
⟨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_compl⟩
theorem compl_eq_iff_isCompl : xᶜ = y ↔ IsCompl x y :=
⟨fun h => by
rw [← h]
exact isCompl_compl, IsCompl.compl_eq⟩
theorem compl_eq_comm : xᶜ = y ↔ yᶜ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
theorem eq_compl_comm : x = yᶜ ↔ y = xᶜ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
@[simp]
theorem compl_compl (x : α) : xᶜᶜ = x :=
(@isCompl_compl _ x _).symm.compl_eq
theorem compl_comp_compl : compl ∘ compl = @id α :=
funext compl_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : α → α) :=
compl_compl
theorem compl_bijective : Function.Bijective (compl : α → α) :=
compl_involutive.bijective
theorem compl_surjective : Function.Surjective (compl : α → α) :=
compl_involutive.surjective
theorem compl_injective : Function.Injective (compl : α → α) :=
compl_involutive.injective
@[simp]
theorem compl_inj_iff : xᶜ = yᶜ ↔ x = y :=
compl_injective.eq_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zᶜ = y ↔ z = x :=
h.compl_eq ▸ compl_inj_iff
@[simp]
theorem compl_eq_top : xᶜ = ⊤ ↔ x = ⊥ :=
isCompl_bot_top.compl_eq_iff
@[simp]
theorem compl_eq_bot : xᶜ = ⊥ ↔ x = ⊤ :=
isCompl_top_bot.compl_eq_iff
@[simp]
theorem compl_inf : (x ⊓ y)ᶜ = xᶜ ⊔ yᶜ :=
hnot_inf_distrib _ _
@[simp]
theorem compl_le_compl_iff_le : yᶜ ≤ xᶜ ↔ x ≤ y :=
⟨fun h => by have h := compl_le_compl h; simpa using h, compl_le_compl⟩
@[simp] lemma compl_lt_compl_iff_lt : yᶜ < xᶜ ↔ x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yᶜ ≤ x) : xᶜ ≤ y := by
simpa only [compl_compl] using compl_le_compl h
theorem compl_le_iff_compl_le : xᶜ ≤ y ↔ yᶜ ≤ x :=
⟨compl_le_of_compl_le, compl_le_of_compl_le⟩
@[simp] theorem compl_le_self : xᶜ ≤ x ↔ x = ⊤ := by simpa using le_compl_self (a := xᶜ)
@[simp] theorem compl_lt_self [Nontrivial α] : xᶜ < x ↔ x = ⊤ := by
simpa using lt_compl_self (a := xᶜ)
@[simp]
theorem sdiff_compl : x \ yᶜ = x ⊓ y := by rw [sdiff_eq, compl_compl]
instance OrderDual.instBooleanAlgebra : BooleanAlgebra αᵒᵈ where
__ := instDistribLattice α
__ := instHeytingAlgebra
sdiff_eq _ _ := @himp_eq α _ _ _
himp_eq _ _ := @sdiff_eq α _ _ _
inf_compl_le_bot a := (@codisjoint_hnot_right _ _ (ofDual a)).top_le
top_le_sup_compl a := (@disjoint_compl_right _ _ (ofDual a)).le_bot
@[simp]
theorem sup_inf_inf_compl : x ⊓ y ⊔ x ⊓ yᶜ = x := by rw [← sdiff_eq, sup_inf_sdiff _ _]
theorem compl_sdiff : (x \ y)ᶜ = x ⇨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
@[simp]
theorem compl_himp : (x ⇨ y)ᶜ = x \ y :=
@compl_sdiff αᵒᵈ _ _ _
theorem compl_sdiff_compl : xᶜ \ yᶜ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
@[simp]
theorem compl_himp_compl : xᶜ ⇨ yᶜ = y ⇨ x :=
@compl_sdiff_compl αᵒᵈ _ _ _
theorem disjoint_compl_left_iff : Disjoint xᶜ y ↔ y ≤ x := by
rw [← le_compl_iff_disjoint_left, compl_compl]
theorem disjoint_compl_right_iff : Disjoint x yᶜ ↔ x ≤ y := by
rw [← le_compl_iff_disjoint_right, compl_compl]
theorem codisjoint_himp_self_left : Codisjoint (x ⇨ y) x :=
@disjoint_sdiff_self_left αᵒᵈ _ _ _
theorem codisjoint_himp_self_right : Codisjoint x (x ⇨ y) :=
@disjoint_sdiff_self_right αᵒᵈ _ _ _
theorem himp_le : x ⇨ y ≤ z ↔ y ≤ z ∧ Codisjoint x z :=
(@le_sdiff αᵒᵈ _ _ _ _).trans <| and_congr_right' <| @Codisjoint_comm _ (_) _ _ _
@[simp] lemma himp_le_iff : x ⇨ y ≤ x ↔ x = ⊤ :=
⟨fun h ↦ codisjoint_self.1 <| codisjoint_himp_self_right.mono_right h, fun h ↦ le_top.trans h.ge⟩
@[simp] lemma himp_eq_left : x ⇨ y = x ↔ x = ⊤ ∧ y = ⊤ := by
rw [codisjoint_himp_self_left.eq_iff]; aesop
lemma himp_ne_right : x ⇨ y ≠ x ↔ x ≠ ⊤ ∨ y ≠ ⊤ := himp_eq_left.not.trans not_and_or
end BooleanAlgebra
instance Prop.instBooleanAlgebra : BooleanAlgebra Prop where
__ := Prop.instHeytingAlgebra
__ := GeneralizedHeytingAlgebra.toDistribLattice
compl := Not
himp_eq p q := propext imp_iff_or_not
inf_compl_le_bot p H := H.2 H.1
top_le_sup_compl p _ := Classical.em p
instance Prod.instBooleanAlgebra [BooleanAlgebra α] [BooleanAlgebra β] :
BooleanAlgebra (α × β) where
__ := instDistribLattice α β
__ := instHeytingAlgebra
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.instBooleanAlgebra {ι : Type u} {α : ι → Type v} [∀ i, BooleanAlgebra (α i)] :
BooleanAlgebra (∀ i, α i) where
__ := instDistribLattice
__ := instHeytingAlgebra
sdiff_eq _ _ := funext fun _ => sdiff_eq
himp_eq _ _ := funext fun _ => himp_eq
inf_compl_le_bot _ _ := BooleanAlgebra.inf_compl_le_bot _
top_le_sup_compl _ _ := BooleanAlgebra.top_le_sup_compl _
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := instDistribLattice
__ := linearOrder
__ := instBoundedOrder
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (· ⊔ ·) = or :=
rfl
@[simp]
theorem Bool.inf_eq_band : (· ⊓ ·) = and :=
rfl
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
protected abbrev Function.Injective.generalizedBooleanAlgebra [Sup α] [Inf α] [Bot α] [SDiff α]
[GeneralizedBooleanAlgebra β] (f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_bot : f ⊥ = ⊥) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra α where
__ := hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff
__ := hf.distribLattice f map_sup map_inf
sup_inf_sdiff a b := hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff]
inf_inf_sdiff a b := hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot]
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
protected abbrev Function.Injective.booleanAlgebra [Sup α] [Inf α] [Top α] [Bot α] [HasCompl α]
[SDiff α] [HImp α] [BooleanAlgebra β] (f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) (map_compl : ∀ a, f aᶜ = (f a)ᶜ)
(map_sdiff : ∀ a b, f (a \ b) = f a \ f b) (map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b) :
BooleanAlgebra α where
__ := hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff
compl := compl
himp := himp
top := ⊤
le_top a := (@le_top β _ _ _).trans map_top.ge
bot_le a := map_bot.le.trans bot_le
inf_compl_le_bot a := ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le
top_le_sup_compl a := ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge
sdiff_eq a b := by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl]
himp_eq a b := hf $ (map_himp _ _).trans $ himp_eq.trans $ by rw [map_sup, map_compl]
end lift
instance PUnit.instBooleanAlgebra : BooleanAlgebra PUnit where
__ := PUnit.instBiheytingAlgebra
le_sup_inf := by simp
inf_compl_le_bot _ := trivial
top_le_sup_compl _ := trivial
namespace DistribLattice
variable (α : Type*) [DistribLattice α]
/--
An alternative constructor for boolean algebras:
a distributive lattice that is complemented is a boolean algebra.
This is not an instance, because it creates data using choice.
-/
noncomputable
def booleanAlgebraOfComplemented [BoundedOrder α] [ComplementedLattice α] : BooleanAlgebra α where
__ := (inferInstanceAs (DistribLattice α))
__ := (inferInstanceAs (BoundedOrder α))
compl a := Classical.choose <| exists_isCompl a
inf_compl_le_bot a := (Classical.choose_spec (exists_isCompl a)).disjoint.le_bot
top_le_sup_compl a := (Classical.choose_spec (exists_isCompl a)).codisjoint.top_le
end DistribLattice
|
Order\BooleanGenerators.lean | /-
Copyright (c) 2024 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Order.CompleteLattice
import Mathlib.Order.CompactlyGenerated.Basic
/-!
# Generators for boolean algebras
In this file, we provide an alternative constructor for boolean algebras.
A set of *boolean generators* in a compactly generated complete lattice is a subset `S` such that
* the elements of `S` are all atoms, and
* the set `S` satisfies an atomicity condition:
any compact element below the supremum of a subset `s` of generators
is equal to the supremum of a subset of `s`.
## Main declarations
* `IsCompactlyGenerated.BooleanGenerators`:
the predicate described above.
* `IsCompactlyGenerated.BooleanGenerators.complementedLattice_of_sSup_eq_top`:
if `S` generates the entire lattice, then it is complemented.
* `IsCompactlyGenerated.BooleanGenerators.distribLattice_of_sSup_eq_top`:
if `S` generates the entire lattice, then it is distributive.
* `IsCompactlyGenerated.BooleanGenerators.booleanAlgebra_of_sSup_eq_top`:
if `S` generates the entire lattice, then it is a boolean algebra.
-/
namespace IsCompactlyGenerated
open CompleteLattice
variable {α : Type*} [CompleteLattice α]
/--
An alternative constructor for boolean algebras.
A set of *boolean generators* in a compactly generated complete lattice is a subset `S` such that
* the elements of `S` are all atoms, and
* the set `S` satisfies an atomicity condition:
any compact element below the supremum of a finite subset `s` of generators
is equal to the supremum of a subset of `s`.
If the supremum of `S` is the whole lattice,
then the lattice is a boolean algebra
(see `IsCompactlyGenerated.BooleanGenerators.booleanAlgebra_of_sSup_eq_top`).
-/
structure BooleanGenerators (S : Set α) : Prop where
/-- The elements in a collection of boolean generators are all atoms. -/
isAtom : ∀ I ∈ S, IsAtom I
/-- The elements in a collection of boolean generators satisfy an atomicity condition:
any compact element below the supremum of a finite subset `s` of generators
is equal to the supremum of a subset of `s`. -/
finitelyAtomistic : ∀ (s : Finset α) (a : α),
↑s ⊆ S → IsCompactElement a → a ≤ s.sup id → ∃ t ⊆ s, a = t.sup id
namespace BooleanGenerators
variable {S : Set α}
lemma mono (hS : BooleanGenerators S) {T : Set α} (hTS : T ⊆ S) : BooleanGenerators T where
isAtom I hI := hS.isAtom I (hTS hI)
finitelyAtomistic := fun s a hs ↦ hS.finitelyAtomistic s a (le_trans hs hTS)
variable [IsCompactlyGenerated α]
lemma atomistic (hS : BooleanGenerators S) (a : α) (ha : a ≤ sSup S) : ∃ T ⊆ S, a = sSup T := by
obtain ⟨C, hC, rfl⟩ := IsCompactlyGenerated.exists_sSup_eq a
have aux : ∀ b : α, IsCompactElement b → b ≤ sSup S → ∃ T ⊆ S, b = sSup T := by
intro b hb hbS
obtain ⟨s, hs₁, hs₂⟩ := hb S hbS
obtain ⟨t, ht, rfl⟩ := hS.finitelyAtomistic s b hs₁ hb hs₂
refine ⟨t, ?_, Finset.sup_id_eq_sSup t⟩
refine Set.Subset.trans ?_ hs₁
simpa only [Finset.coe_subset] using ht
choose T hT₁ hT₂ using aux
use sSup {T c h₁ h₂ | (c ∈ C) (h₁ : IsCompactElement c) (h₂ : c ≤ sSup S)}
constructor
· apply _root_.sSup_le
rintro _ ⟨c, -, h₁, h₂, rfl⟩
apply hT₁
· apply le_antisymm
· apply _root_.sSup_le
intro c hc
rw [hT₂ c (hC _ hc) ((le_sSup hc).trans ha)]
apply sSup_le_sSup
apply _root_.le_sSup
use c, hc, hC _ hc, (le_sSup hc).trans ha
· simp only [Set.sSup_eq_sUnion, sSup_le_iff, Set.mem_sUnion, Set.mem_setOf_eq,
forall_exists_index, and_imp]
rintro a T b hbC hb hbS rfl haT
apply (le_sSup haT).trans
rw [← hT₂]
exact le_sSup hbC
lemma isAtomistic_of_sSup_eq_top (hS : BooleanGenerators S) (h : sSup S = ⊤) :
IsAtomistic α := by
refine ⟨fun a ↦ ?_⟩
obtain ⟨s, hs, hs'⟩ := hS.atomistic a (h ▸ le_top)
exact ⟨s, hs', fun I hI ↦ hS.isAtom I (hs hI)⟩
lemma mem_of_isAtom_of_le_sSup_atoms (hS : BooleanGenerators S) (a : α) (ha : IsAtom a)
(haS : a ≤ sSup S) : a ∈ S := by
obtain ⟨T, hT, rfl⟩ := hS.atomistic a haS
obtain rfl | ⟨a, haT⟩ := T.eq_empty_or_nonempty
· simp only [sSup_empty] at ha
exact (ha.1 rfl).elim
suffices sSup T = a from this ▸ hT haT
have : a ≤ sSup T := le_sSup haT
rwa [ha.le_iff_eq, eq_comm] at this
exact (hS.isAtom a (hT haT)).1
lemma sSup_inter (hS : BooleanGenerators S) {T₁ T₂ : Set α} (hT₁ : T₁ ⊆ S) (hT₂ : T₂ ⊆ S) :
sSup (T₁ ∩ T₂) = (sSup T₁) ⊓ (sSup T₂) := by
apply le_antisymm
· apply le_inf
· apply sSup_le_sSup Set.inter_subset_left
· apply sSup_le_sSup Set.inter_subset_right
obtain ⟨X, hX, hX'⟩ := hS.atomistic (sSup T₁ ⊓ sSup T₂) (inf_le_left.trans (sSup_le_sSup hT₁))
rw [hX']
apply _root_.sSup_le
intro I hI
apply _root_.le_sSup
constructor
· apply (hS.mono hT₁).mem_of_isAtom_of_le_sSup_atoms _ _ _
· exact (hS.mono hX).isAtom I hI
· exact (_root_.le_sSup hI).trans (hX'.ge.trans inf_le_left)
· apply (hS.mono hT₂).mem_of_isAtom_of_le_sSup_atoms _ _ _
· exact (hS.mono hX).isAtom I hI
· exact (_root_.le_sSup hI).trans (hX'.ge.trans inf_le_right)
/-- A lattice generated by boolean generators is a distributive lattice. -/
def distribLattice_of_sSup_eq_top (hS : BooleanGenerators S) (h : sSup S = ⊤) :
DistribLattice α where
le_sup_inf a b c := by
obtain ⟨Ta, hTa, rfl⟩ := hS.atomistic a (h ▸ le_top)
obtain ⟨Tb, hTb, rfl⟩ := hS.atomistic b (h ▸ le_top)
obtain ⟨Tc, hTc, rfl⟩ := hS.atomistic c (h ▸ le_top)
apply le_of_eq
rw [← sSup_union, ← sSup_union, ← hS.sSup_inter hTb hTc, ← hS.sSup_inter, ← sSup_union]
on_goal 1 => congr 1; ext
all_goals
simp only [Set.union_subset_iff, Set.mem_inter_iff, Set.mem_union]
tauto
lemma complementedLattice_of_sSup_eq_top (hS : BooleanGenerators S) (h : sSup S = ⊤) :
ComplementedLattice α := by
let _i := hS.distribLattice_of_sSup_eq_top h
have _i₁ := isAtomistic_of_sSup_eq_top hS h
apply complementedLattice_of_isAtomistic
/-- A compactly generated complete lattice generated by boolean generators is a boolean algebra. -/
noncomputable
def booleanAlgebra_of_sSup_eq_top (hS : BooleanGenerators S) (h : sSup S = ⊤) : BooleanAlgebra α :=
let _i := hS.distribLattice_of_sSup_eq_top h
have := hS.complementedLattice_of_sSup_eq_top h
DistribLattice.booleanAlgebraOfComplemented α
lemma sSup_le_sSup_iff_of_atoms (hS : BooleanGenerators S) (X Y : Set α) (hX : X ⊆ S) (hY : Y ⊆ S) :
sSup X ≤ sSup Y ↔ X ⊆ Y := by
refine ⟨?_, sSup_le_sSup⟩
intro h a ha
apply (hS.mono hY).mem_of_isAtom_of_le_sSup_atoms _ _ ((le_sSup ha).trans h)
exact (hS.mono hX).isAtom a ha
lemma eq_atoms_of_sSup_eq_top (hS : BooleanGenerators S) (h : sSup S = ⊤) :
S = {a : α | IsAtom a} := by
apply le_antisymm
· exact hS.isAtom
intro a ha
obtain ⟨T, hT, rfl⟩ := hS.atomistic a (le_top.trans h.ge)
exact hS.mem_of_isAtom_of_le_sSup_atoms _ ha (sSup_le_sSup hT)
end BooleanGenerators
end IsCompactlyGenerated
|
Order\Booleanisation.lean | /-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Hom.Lattice
/-!
# Adding complements to a generalized Boolean algebra
This file embeds any generalized Boolean algebra into a Boolean algebra.
This concretely proves that any equation holding true in the theory of Boolean algebras that does
not reference `ᶜ` also holds true in the theory of generalized Boolean algebras. Put another way,
one does not need the existence of complements to prove something which does not talk about
complements.
## Main declarations
* `Booleanisation`: Boolean algebra containing a given generalised Boolean algebra as a sublattice.
* `Booleanisation.liftLatticeHom`: Boolean algebra containing a given generalised Boolean algebra as
a sublattice.
## Future work
If mathlib ever acquires `GenBoolAlg`, the category of generalised Boolean algebras, then one could
show that `Booleanisation` is the free functor from `GenBoolAlg` to `BoolAlg`.
-/
open Function
variable {α : Type*}
/-- Boolean algebra containing a given generalised Boolean algebra `α` as a sublattice.
This should be thought of as made of a copy of `α` (representing elements of `α`) living under
another copy of `α` (representing complements of elements of `α`). -/
def Booleanisation (α : Type*) := α ⊕ α
namespace Booleanisation
instance instDecidableEq [DecidableEq α] : DecidableEq (Booleanisation α) :=
inferInstanceAs <| DecidableEq (α ⊕ α)
/-- The natural inclusion `a ↦ a` from a generalized Boolean algebra to its generated Boolean
algebra. -/
@[match_pattern] def lift : α → Booleanisation α := Sum.inl
/-- The inclusion `a ↦ aᶜ from a generalized Boolean algebra to its generated Boolean algebra. -/
@[match_pattern] def comp : α → Booleanisation α := Sum.inr
/-- The complement operator on `Booleanisation α` sends `a` to `aᶜ` and `aᶜ` to `a`, for `a : α`. -/
instance instCompl : HasCompl (Booleanisation α) where
compl x := match x with
| lift a => comp a
| comp a => lift a
@[simp] lemma compl_lift (a : α) : (lift a)ᶜ = comp a := rfl
@[simp] lemma compl_comp (a : α) : (comp a)ᶜ = lift a := rfl
variable [GeneralizedBooleanAlgebra α] {x y : Booleanisation α} {a b : α}
/-- The order on `Booleanisation α` is as follows: For `a b : α`,
* `a ≤ b` iff `a ≤ b` in `α`
* `a ≤ bᶜ` iff `a` and `b` are disjoint in `α`
* `aᶜ ≤ bᶜ` iff `b ≤ a` in `α`
* `¬ aᶜ ≤ b` -/
protected inductive LE : Booleanisation α → Booleanisation α → Prop
| protected lift {a b} : a ≤ b → Booleanisation.LE (lift a) (lift b)
| protected comp {a b} : a ≤ b → Booleanisation.LE (comp b) (comp a)
| protected sep {a b} : Disjoint a b → Booleanisation.LE (lift a) (comp b)
/-- The order on `Booleanisation α` is as follows: For `a b : α`,
* `a < b` iff `a < b` in `α`
* `a < bᶜ` iff `a` and `b` are disjoint in `α`
* `aᶜ < bᶜ` iff `b < a` in `α`
* `¬ aᶜ < b` -/
protected inductive LT : Booleanisation α → Booleanisation α → Prop
| protected lift {a b} : a < b → Booleanisation.LT (lift a) (lift b)
| protected comp {a b} : a < b → Booleanisation.LT (comp b) (comp a)
| protected sep {a b} : Disjoint a b → Booleanisation.LT (lift a) (comp b)
@[inherit_doc Booleanisation.LE]
instance instLE : LE (Booleanisation α) where
le := Booleanisation.LE
@[inherit_doc Booleanisation.LT]
instance instLT : LT (Booleanisation α) where
lt := Booleanisation.LT
/-- The supremum on `Booleanisation α` is as follows: For `a b : α`,
* `a ⊔ b` is `a ⊔ b`
* `a ⊔ bᶜ` is `(b \ a)ᶜ`
* `aᶜ ⊔ b` is `(a \ b)ᶜ`
* `aᶜ ⊔ bᶜ` is `(a ⊓ b)ᶜ` -/
instance instSup : Sup (Booleanisation α) where
sup x y := match x, y with
| lift a, lift b => lift (a ⊔ b)
| lift a, comp b => comp (b \ a)
| comp a, lift b => comp (a \ b)
| comp a, comp b => comp (a ⊓ b)
/-- The infimum on `Booleanisation α` is as follows: For `a b : α`,
* `a ⊓ b` is `a ⊓ b`
* `a ⊓ bᶜ` is `a \ b`
* `aᶜ ⊓ b` is `b \ a`
* `aᶜ ⊓ bᶜ` is `(a ⊔ b)ᶜ` -/
instance instInf : Inf (Booleanisation α) where
inf x y := match x, y with
| lift a, lift b => lift (a ⊓ b)
| lift a, comp b => lift (a \ b)
| comp a, lift b => lift (b \ a)
| comp a, comp b => comp (a ⊔ b)
/-- The bottom element of `Booleanisation α` is the bottom element of `α`. -/
instance instBot : Bot (Booleanisation α) where
bot := lift ⊥
/-- The top element of `Booleanisation α` is the complement of the bottom element of `α`. -/
instance instTop : Top (Booleanisation α) where
top := comp ⊥
/-- The difference operator on `Booleanisation α` is as follows: For `a b : α`,
* `a \ b` is `a \ b`
* `a \ bᶜ` is `a ⊓ b`
* `aᶜ \ b` is `(a ⊔ b)ᶜ`
* `aᶜ \ bᶜ` is `b \ a` -/
instance instSDiff : SDiff (Booleanisation α) where
sdiff x y := match x, y with
| lift a, lift b => lift (a \ b)
| lift a, comp b => lift (a ⊓ b)
| comp a, lift b => comp (a ⊔ b)
| comp a, comp b => lift (b \ a)
@[simp] lemma lift_le_lift : lift a ≤ lift b ↔ a ≤ b := ⟨by rintro ⟨_⟩; assumption, LE.lift⟩
@[simp] lemma comp_le_comp : comp a ≤ comp b ↔ b ≤ a := ⟨by rintro ⟨_⟩; assumption, LE.comp⟩
@[simp] lemma lift_le_comp : lift a ≤ comp b ↔ Disjoint a b := ⟨by rintro ⟨_⟩; assumption, LE.sep⟩
@[simp] lemma not_comp_le_lift : ¬ comp a ≤ lift b := fun h ↦ nomatch h
@[simp] lemma lift_lt_lift : lift a < lift b ↔ a < b := ⟨by rintro ⟨_⟩; assumption, LT.lift⟩
@[simp] lemma comp_lt_comp : comp a < comp b ↔ b < a := ⟨by rintro ⟨_⟩; assumption, LT.comp⟩
@[simp] lemma lift_lt_comp : lift a < comp b ↔ Disjoint a b := ⟨by rintro ⟨_⟩; assumption, LT.sep⟩
@[simp] lemma not_comp_lt_lift : ¬ comp a < lift b := fun h ↦ nomatch h
@[simp] lemma lift_sup_lift (a b : α) : lift a ⊔ lift b = lift (a ⊔ b) := rfl
@[simp] lemma lift_sup_comp (a b : α) : lift a ⊔ comp b = comp (b \ a) := rfl
@[simp] lemma comp_sup_lift (a b : α) : comp a ⊔ lift b = comp (a \ b) := rfl
@[simp] lemma comp_sup_comp (a b : α) : comp a ⊔ comp b = comp (a ⊓ b) := rfl
@[simp] lemma lift_inf_lift (a b : α) : lift a ⊓ lift b = lift (a ⊓ b) := rfl
@[simp] lemma lift_inf_comp (a b : α) : lift a ⊓ comp b = lift (a \ b) := rfl
@[simp] lemma comp_inf_lift (a b : α) : comp a ⊓ lift b = lift (b \ a) := rfl
@[simp] lemma comp_inf_comp (a b : α) : comp a ⊓ comp b = comp (a ⊔ b) := rfl
@[simp] lemma lift_bot : lift (⊥ : α) = ⊥ := rfl
@[simp] lemma comp_bot : comp (⊥ : α) = ⊤ := rfl
@[simp] lemma lift_sdiff_lift (a b : α) : lift a \ lift b = lift (a \ b) := rfl
@[simp] lemma lift_sdiff_comp (a b : α) : lift a \ comp b = lift (a ⊓ b) := rfl
@[simp] lemma comp_sdiff_lift (a b : α) : comp a \ lift b = comp (a ⊔ b) := rfl
@[simp] lemma comp_sdiff_comp (a b : α) : comp a \ comp b = lift (b \ a) := rfl
instance instPreorder : Preorder (Booleanisation α) where
lt := (· < ·)
lt_iff_le_not_le x y := match x, y with
| lift a, lift b => by simp [lt_iff_le_not_le]
| lift a, comp b => by simp
| comp a, lift b => by simp
| comp a, comp b => by simp [lt_iff_le_not_le]
le_refl x := match x with
| lift a => LE.lift le_rfl
| comp a => LE.comp le_rfl
le_trans x y z hxy hyz := match x, y, z, hxy, hyz with
| lift a, lift b, lift c, LE.lift hab, LE.lift hbc => LE.lift <| hab.trans hbc
| lift a, lift b, comp c, LE.lift hab, LE.sep hbc => LE.sep <| hbc.mono_left hab
| lift a, comp b, comp c, LE.sep hab, LE.comp hcb => LE.sep <| hab.mono_right hcb
| comp a, comp b, comp c, LE.comp hba, LE.comp hcb => LE.comp <| hcb.trans hba
instance instPartialOrder : PartialOrder (Booleanisation α) where
le_antisymm x y hxy hyx := match x, y, hxy, hyx with
| lift a, lift b, LE.lift hab, LE.lift hba => by rw [hab.antisymm hba]
| comp a, comp b, LE.comp hab, LE.comp hba => by rw [hab.antisymm hba]
-- The linter significantly hinders readability here.
set_option linter.unusedVariables false in
instance instSemilatticeSup : SemilatticeSup (Booleanisation α) where
le_sup_left x y := match x, y with
| lift a, lift b => LE.lift le_sup_left
| lift a, comp b => LE.sep disjoint_sdiff_self_right
| comp a, lift b => LE.comp sdiff_le
| comp a, comp b => LE.comp inf_le_left
le_sup_right x y := match x, y with
| lift a, lift b => LE.lift le_sup_right
| lift a, comp b => LE.comp sdiff_le
| comp a, lift b => LE.sep disjoint_sdiff_self_right
| comp a, comp b => LE.comp inf_le_right
sup_le x y z hxz hyz := match x, y, z, hxz, hyz with
| lift a, lift b, lift c, LE.lift hac, LE.lift hbc => LE.lift <| sup_le hac hbc
| lift a, lift b, comp c, LE.sep hac, LE.sep hbc => LE.sep <| hac.sup_left hbc
| lift a, comp b, comp c, LE.sep hac, LE.comp hcb => LE.comp <| le_sdiff.2 ⟨hcb, hac.symm⟩
| comp a, lift b, comp c, LE.comp hca, LE.sep hbc => LE.comp <| le_sdiff.2 ⟨hca, hbc.symm⟩
| comp a, comp b, comp c, LE.comp hca, LE.comp hcb => LE.comp <| le_inf hca hcb
-- The linter significantly hinders readability here.
set_option linter.unusedVariables false in
instance instSemilatticeInf : SemilatticeInf (Booleanisation α) where
inf_le_left x y := match x, y with
| lift a, lift b => LE.lift inf_le_left
| lift a, comp b => LE.lift sdiff_le
| comp a, lift b => LE.sep disjoint_sdiff_self_left
| comp a, comp b => LE.comp le_sup_left
inf_le_right x y := match x, y with
| lift a, lift b => LE.lift inf_le_right
| lift a, comp b => LE.sep disjoint_sdiff_self_left
| comp a, lift b => LE.lift sdiff_le
| comp a, comp b => LE.comp le_sup_right
le_inf x y z hxz hyz := match x, y, z, hxz, hyz with
| lift a, lift b, lift c, LE.lift hab, LE.lift hac => LE.lift <| le_inf hab hac
| lift a, lift b, comp c, LE.lift hab, LE.sep hac => LE.lift <| le_sdiff.2 ⟨hab, hac⟩
| lift a, comp b, lift c, LE.sep hab, LE.lift hac => LE.lift <| le_sdiff.2 ⟨hac, hab⟩
| lift a, comp b, comp c, LE.sep hab, LE.sep hac => LE.sep <| hab.sup_right hac
| comp a, comp b, comp c, LE.comp hba, LE.comp hca => LE.comp <| sup_le hba hca
instance instDistribLattice : DistribLattice (Booleanisation α) where
inf_le_left _ _ := inf_le_left
inf_le_right _ _ := inf_le_right
le_inf _ _ _ := le_inf
le_sup_inf x y z := match x, y, z with
| lift a, lift b, lift c => LE.lift le_sup_inf
| lift a, lift b, comp c => LE.lift <| by simp [sup_left_comm, sup_comm]
| lift a, comp b, lift c => LE.lift <| by
simp [sup_left_comm (a := b \ a), sup_comm (a := b \ a)]
| lift a, comp b, comp c => LE.comp <| by rw [sup_sdiff]
| comp a, lift b, lift c => LE.comp <| by rw [sdiff_inf]
| comp a, lift b, comp c => LE.comp <| by rw [sdiff_sdiff_right']
| comp a, comp b, lift c => LE.comp <| by rw [sdiff_sdiff_right', sup_comm]
| comp a, comp b, comp c => LE.comp (inf_sup_left _ _ _).le
-- The linter significantly hinders readability here.
set_option linter.unusedVariables false in
instance instBoundedOrder : BoundedOrder (Booleanisation α) where
le_top x := match x with
| lift a => LE.sep disjoint_bot_right
| comp a => LE.comp bot_le
bot_le x := match x with
| lift a => LE.lift bot_le
| comp a => LE.sep disjoint_bot_left
instance instBooleanAlgebra : BooleanAlgebra (Booleanisation α) where
le_top _ := le_top
bot_le _ := bot_le
inf_compl_le_bot x := match x with
| lift a => by simp
| comp a => by simp
top_le_sup_compl x := match x with
| lift a => by simp
| comp a => by simp
sdiff_eq x y := match x, y with
| lift a, lift b => by simp
| lift a, comp b => by simp
| comp a, lift b => by simp
| comp a, comp b => by simp
/-- The embedding from a generalised Boolean algebra to its generated Boolean algebra. -/
def liftLatticeHom : LatticeHom α (Booleanisation α) where
toFun := lift
map_sup' _ _ := rfl
map_inf' _ _ := rfl
lemma liftLatticeHom_injective : Injective (liftLatticeHom (α := α)) := Sum.inl_injective
end Booleanisation
|
Order\Bounded.lean | /-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.Order.RelClasses
import Mathlib.Order.Interval.Set.Basic
/-!
# Bounded and unbounded sets
We prove miscellaneous lemmas about bounded and unbounded sets. Many of these are just variations on
the same ideas, or similar results with a few minor differences. The file is divided into these
different general ideas.
-/
namespace Set
variable {α : Type*} {r : α → α → Prop} {s t : Set α}
/-! ### Subsets of bounded and unbounded sets -/
theorem Bounded.mono (hst : s ⊆ t) (hs : Bounded r t) : Bounded r s :=
hs.imp fun _ ha b hb => ha b (hst hb)
theorem Unbounded.mono (hst : s ⊆ t) (hs : Unbounded r s) : Unbounded r t := fun a =>
let ⟨b, hb, hb'⟩ := hs a
⟨b, hst hb, hb'⟩
/-! ### Alternate characterizations of unboundedness on orders -/
theorem unbounded_le_of_forall_exists_lt [Preorder α] (h : ∀ a, ∃ b ∈ s, a < b) :
Unbounded (· ≤ ·) s := fun a =>
let ⟨b, hb, hb'⟩ := h a
⟨b, hb, fun hba => hba.not_lt hb'⟩
theorem unbounded_le_iff [LinearOrder α] : Unbounded (· ≤ ·) s ↔ ∀ a, ∃ b ∈ s, a < b := by
simp only [Unbounded, not_le]
theorem unbounded_lt_of_forall_exists_le [Preorder α] (h : ∀ a, ∃ b ∈ s, a ≤ b) :
Unbounded (· < ·) s := fun a =>
let ⟨b, hb, hb'⟩ := h a
⟨b, hb, fun hba => hba.not_le hb'⟩
theorem unbounded_lt_iff [LinearOrder α] : Unbounded (· < ·) s ↔ ∀ a, ∃ b ∈ s, a ≤ b := by
simp only [Unbounded, not_lt]
theorem unbounded_ge_of_forall_exists_gt [Preorder α] (h : ∀ a, ∃ b ∈ s, b < a) :
Unbounded (· ≥ ·) s :=
@unbounded_le_of_forall_exists_lt αᵒᵈ _ _ h
theorem unbounded_ge_iff [LinearOrder α] : Unbounded (· ≥ ·) s ↔ ∀ a, ∃ b ∈ s, b < a :=
⟨fun h a =>
let ⟨b, hb, hba⟩ := h a
⟨b, hb, lt_of_not_ge hba⟩,
unbounded_ge_of_forall_exists_gt⟩
theorem unbounded_gt_of_forall_exists_ge [Preorder α] (h : ∀ a, ∃ b ∈ s, b ≤ a) :
Unbounded (· > ·) s := fun a =>
let ⟨b, hb, hb'⟩ := h a
⟨b, hb, fun hba => not_le_of_gt hba hb'⟩
theorem unbounded_gt_iff [LinearOrder α] : Unbounded (· > ·) s ↔ ∀ a, ∃ b ∈ s, b ≤ a :=
⟨fun h a =>
let ⟨b, hb, hba⟩ := h a
⟨b, hb, le_of_not_gt hba⟩,
unbounded_gt_of_forall_exists_ge⟩
/-! ### Relation between boundedness by strict and nonstrict orders. -/
/-! #### Less and less or equal -/
theorem Bounded.rel_mono {r' : α → α → Prop} (h : Bounded r s) (hrr' : r ≤ r') : Bounded r' s :=
let ⟨a, ha⟩ := h
⟨a, fun b hb => hrr' b a (ha b hb)⟩
theorem bounded_le_of_bounded_lt [Preorder α] (h : Bounded (· < ·) s) : Bounded (· ≤ ·) s :=
h.rel_mono fun _ _ => le_of_lt
theorem Unbounded.rel_mono {r' : α → α → Prop} (hr : r' ≤ r) (h : Unbounded r s) : Unbounded r' s :=
fun a =>
let ⟨b, hb, hba⟩ := h a
⟨b, hb, fun hba' => hba (hr b a hba')⟩
theorem unbounded_lt_of_unbounded_le [Preorder α] (h : Unbounded (· ≤ ·) s) : Unbounded (· < ·) s :=
h.rel_mono fun _ _ => le_of_lt
theorem bounded_le_iff_bounded_lt [Preorder α] [NoMaxOrder α] :
Bounded (· ≤ ·) s ↔ Bounded (· < ·) s := by
refine ⟨fun h => ?_, bounded_le_of_bounded_lt⟩
cases' h with a ha
cases' exists_gt a with b hb
exact ⟨b, fun c hc => lt_of_le_of_lt (ha c hc) hb⟩
theorem unbounded_lt_iff_unbounded_le [Preorder α] [NoMaxOrder α] :
Unbounded (· < ·) s ↔ Unbounded (· ≤ ·) s := by
simp_rw [← not_bounded_iff, bounded_le_iff_bounded_lt]
/-! #### Greater and greater or equal -/
theorem bounded_ge_of_bounded_gt [Preorder α] (h : Bounded (· > ·) s) : Bounded (· ≥ ·) s :=
let ⟨a, ha⟩ := h
⟨a, fun b hb => le_of_lt (ha b hb)⟩
theorem unbounded_gt_of_unbounded_ge [Preorder α] (h : Unbounded (· ≥ ·) s) : Unbounded (· > ·) s :=
fun a =>
let ⟨b, hb, hba⟩ := h a
⟨b, hb, fun hba' => hba (le_of_lt hba')⟩
theorem bounded_ge_iff_bounded_gt [Preorder α] [NoMinOrder α] :
Bounded (· ≥ ·) s ↔ Bounded (· > ·) s :=
@bounded_le_iff_bounded_lt αᵒᵈ _ _ _
theorem unbounded_gt_iff_unbounded_ge [Preorder α] [NoMinOrder α] :
Unbounded (· > ·) s ↔ Unbounded (· ≥ ·) s :=
@unbounded_lt_iff_unbounded_le αᵒᵈ _ _ _
/-! ### The universal set -/
theorem unbounded_le_univ [LE α] [NoTopOrder α] : Unbounded (· ≤ ·) (@Set.univ α) := fun a =>
let ⟨b, hb⟩ := exists_not_le a
⟨b, ⟨⟩, hb⟩
theorem unbounded_lt_univ [Preorder α] [NoTopOrder α] : Unbounded (· < ·) (@Set.univ α) :=
unbounded_lt_of_unbounded_le unbounded_le_univ
theorem unbounded_ge_univ [LE α] [NoBotOrder α] : Unbounded (· ≥ ·) (@Set.univ α) := fun a =>
let ⟨b, hb⟩ := exists_not_ge a
⟨b, ⟨⟩, hb⟩
theorem unbounded_gt_univ [Preorder α] [NoBotOrder α] : Unbounded (· > ·) (@Set.univ α) :=
unbounded_gt_of_unbounded_ge unbounded_ge_univ
/-! ### Bounded and unbounded intervals -/
theorem bounded_self (a : α) : Bounded r { b | r b a } :=
⟨a, fun _ => id⟩
/-! #### Half-open bounded intervals -/
theorem bounded_lt_Iio [Preorder α] (a : α) : Bounded (· < ·) (Iio a) :=
bounded_self a
theorem bounded_le_Iio [Preorder α] (a : α) : Bounded (· ≤ ·) (Iio a) :=
bounded_le_of_bounded_lt (bounded_lt_Iio a)
theorem bounded_le_Iic [Preorder α] (a : α) : Bounded (· ≤ ·) (Iic a) :=
bounded_self a
theorem bounded_lt_Iic [Preorder α] [NoMaxOrder α] (a : α) : Bounded (· < ·) (Iic a) := by
simp only [← bounded_le_iff_bounded_lt, bounded_le_Iic]
theorem bounded_gt_Ioi [Preorder α] (a : α) : Bounded (· > ·) (Ioi a) :=
bounded_self a
theorem bounded_ge_Ioi [Preorder α] (a : α) : Bounded (· ≥ ·) (Ioi a) :=
bounded_ge_of_bounded_gt (bounded_gt_Ioi a)
theorem bounded_ge_Ici [Preorder α] (a : α) : Bounded (· ≥ ·) (Ici a) :=
bounded_self a
theorem bounded_gt_Ici [Preorder α] [NoMinOrder α] (a : α) : Bounded (· > ·) (Ici a) := by
simp only [← bounded_ge_iff_bounded_gt, bounded_ge_Ici]
/-! #### Other bounded intervals -/
theorem bounded_lt_Ioo [Preorder α] (a b : α) : Bounded (· < ·) (Ioo a b) :=
(bounded_lt_Iio b).mono Set.Ioo_subset_Iio_self
theorem bounded_lt_Ico [Preorder α] (a b : α) : Bounded (· < ·) (Ico a b) :=
(bounded_lt_Iio b).mono Set.Ico_subset_Iio_self
theorem bounded_lt_Ioc [Preorder α] [NoMaxOrder α] (a b : α) : Bounded (· < ·) (Ioc a b) :=
(bounded_lt_Iic b).mono Set.Ioc_subset_Iic_self
theorem bounded_lt_Icc [Preorder α] [NoMaxOrder α] (a b : α) : Bounded (· < ·) (Icc a b) :=
(bounded_lt_Iic b).mono Set.Icc_subset_Iic_self
theorem bounded_le_Ioo [Preorder α] (a b : α) : Bounded (· ≤ ·) (Ioo a b) :=
(bounded_le_Iio b).mono Set.Ioo_subset_Iio_self
theorem bounded_le_Ico [Preorder α] (a b : α) : Bounded (· ≤ ·) (Ico a b) :=
(bounded_le_Iio b).mono Set.Ico_subset_Iio_self
theorem bounded_le_Ioc [Preorder α] (a b : α) : Bounded (· ≤ ·) (Ioc a b) :=
(bounded_le_Iic b).mono Set.Ioc_subset_Iic_self
theorem bounded_le_Icc [Preorder α] (a b : α) : Bounded (· ≤ ·) (Icc a b) :=
(bounded_le_Iic b).mono Set.Icc_subset_Iic_self
theorem bounded_gt_Ioo [Preorder α] (a b : α) : Bounded (· > ·) (Ioo a b) :=
(bounded_gt_Ioi a).mono Set.Ioo_subset_Ioi_self
theorem bounded_gt_Ioc [Preorder α] (a b : α) : Bounded (· > ·) (Ioc a b) :=
(bounded_gt_Ioi a).mono Set.Ioc_subset_Ioi_self
theorem bounded_gt_Ico [Preorder α] [NoMinOrder α] (a b : α) : Bounded (· > ·) (Ico a b) :=
(bounded_gt_Ici a).mono Set.Ico_subset_Ici_self
theorem bounded_gt_Icc [Preorder α] [NoMinOrder α] (a b : α) : Bounded (· > ·) (Icc a b) :=
(bounded_gt_Ici a).mono Set.Icc_subset_Ici_self
theorem bounded_ge_Ioo [Preorder α] (a b : α) : Bounded (· ≥ ·) (Ioo a b) :=
(bounded_ge_Ioi a).mono Set.Ioo_subset_Ioi_self
theorem bounded_ge_Ioc [Preorder α] (a b : α) : Bounded (· ≥ ·) (Ioc a b) :=
(bounded_ge_Ioi a).mono Set.Ioc_subset_Ioi_self
theorem bounded_ge_Ico [Preorder α] (a b : α) : Bounded (· ≥ ·) (Ico a b) :=
(bounded_ge_Ici a).mono Set.Ico_subset_Ici_self
theorem bounded_ge_Icc [Preorder α] (a b : α) : Bounded (· ≥ ·) (Icc a b) :=
(bounded_ge_Ici a).mono Set.Icc_subset_Ici_self
/-! #### Unbounded intervals -/
theorem unbounded_le_Ioi [SemilatticeSup α] [NoMaxOrder α] (a : α) :
Unbounded (· ≤ ·) (Ioi a) := fun b =>
let ⟨c, hc⟩ := exists_gt (a ⊔ b)
⟨c, le_sup_left.trans_lt hc, (le_sup_right.trans_lt hc).not_le⟩
theorem unbounded_le_Ici [SemilatticeSup α] [NoMaxOrder α] (a : α) :
Unbounded (· ≤ ·) (Ici a) :=
(unbounded_le_Ioi a).mono Set.Ioi_subset_Ici_self
theorem unbounded_lt_Ioi [SemilatticeSup α] [NoMaxOrder α] (a : α) :
Unbounded (· < ·) (Ioi a) :=
unbounded_lt_of_unbounded_le (unbounded_le_Ioi a)
theorem unbounded_lt_Ici [SemilatticeSup α] (a : α) : Unbounded (· < ·) (Ici a) := fun b =>
⟨a ⊔ b, le_sup_left, le_sup_right.not_lt⟩
/-! ### Bounded initial segments -/
theorem bounded_inter_not (H : ∀ a b, ∃ m, ∀ c, r c a ∨ r c b → r c m) (a : α) :
Bounded r (s ∩ { b | ¬r b a }) ↔ Bounded r s := by
refine ⟨?_, Bounded.mono inter_subset_left⟩
rintro ⟨b, hb⟩
cases' H a b with m hm
exact ⟨m, fun c hc => hm c (or_iff_not_imp_left.2 fun hca => hb c ⟨hc, hca⟩)⟩
theorem unbounded_inter_not (H : ∀ a b, ∃ m, ∀ c, r c a ∨ r c b → r c m) (a : α) :
Unbounded r (s ∩ { b | ¬r b a }) ↔ Unbounded r s := by
simp_rw [← not_bounded_iff, bounded_inter_not H]
/-! #### Less or equal -/
theorem bounded_le_inter_not_le [SemilatticeSup α] (a : α) :
Bounded (· ≤ ·) (s ∩ { b | ¬b ≤ a }) ↔ Bounded (· ≤ ·) s :=
bounded_inter_not (fun x y => ⟨x ⊔ y, fun _ h => h.elim le_sup_of_le_left le_sup_of_le_right⟩) a
theorem unbounded_le_inter_not_le [SemilatticeSup α] (a : α) :
Unbounded (· ≤ ·) (s ∩ { b | ¬b ≤ a }) ↔ Unbounded (· ≤ ·) s := by
rw [← not_bounded_iff, ← not_bounded_iff, not_iff_not]
exact bounded_le_inter_not_le a
theorem bounded_le_inter_lt [LinearOrder α] (a : α) :
Bounded (· ≤ ·) (s ∩ { b | a < b }) ↔ Bounded (· ≤ ·) s := by
simp_rw [← not_le, bounded_le_inter_not_le]
theorem unbounded_le_inter_lt [LinearOrder α] (a : α) :
Unbounded (· ≤ ·) (s ∩ { b | a < b }) ↔ Unbounded (· ≤ ·) s := by
convert @unbounded_le_inter_not_le _ s _ a
exact lt_iff_not_le
theorem bounded_le_inter_le [LinearOrder α] (a : α) :
Bounded (· ≤ ·) (s ∩ { b | a ≤ b }) ↔ Bounded (· ≤ ·) s := by
refine ⟨?_, Bounded.mono Set.inter_subset_left⟩
rw [← @bounded_le_inter_lt _ s _ a]
exact Bounded.mono fun x ⟨hx, hx'⟩ => ⟨hx, le_of_lt hx'⟩
theorem unbounded_le_inter_le [LinearOrder α] (a : α) :
Unbounded (· ≤ ·) (s ∩ { b | a ≤ b }) ↔ Unbounded (· ≤ ·) s := by
rw [← not_bounded_iff, ← not_bounded_iff, not_iff_not]
exact bounded_le_inter_le a
/-! #### Less than -/
theorem bounded_lt_inter_not_lt [SemilatticeSup α] (a : α) :
Bounded (· < ·) (s ∩ { b | ¬b < a }) ↔ Bounded (· < ·) s :=
bounded_inter_not (fun x y => ⟨x ⊔ y, fun _ h => h.elim lt_sup_of_lt_left lt_sup_of_lt_right⟩) a
theorem unbounded_lt_inter_not_lt [SemilatticeSup α] (a : α) :
Unbounded (· < ·) (s ∩ { b | ¬b < a }) ↔ Unbounded (· < ·) s := by
rw [← not_bounded_iff, ← not_bounded_iff, not_iff_not]
exact bounded_lt_inter_not_lt a
theorem bounded_lt_inter_le [LinearOrder α] (a : α) :
Bounded (· < ·) (s ∩ { b | a ≤ b }) ↔ Bounded (· < ·) s := by
convert @bounded_lt_inter_not_lt _ s _ a
exact not_lt.symm
theorem unbounded_lt_inter_le [LinearOrder α] (a : α) :
Unbounded (· < ·) (s ∩ { b | a ≤ b }) ↔ Unbounded (· < ·) s := by
convert @unbounded_lt_inter_not_lt _ s _ a
exact not_lt.symm
theorem bounded_lt_inter_lt [LinearOrder α] [NoMaxOrder α] (a : α) :
Bounded (· < ·) (s ∩ { b | a < b }) ↔ Bounded (· < ·) s := by
rw [← bounded_le_iff_bounded_lt, ← bounded_le_iff_bounded_lt]
exact bounded_le_inter_lt a
theorem unbounded_lt_inter_lt [LinearOrder α] [NoMaxOrder α] (a : α) :
Unbounded (· < ·) (s ∩ { b | a < b }) ↔ Unbounded (· < ·) s := by
rw [← not_bounded_iff, ← not_bounded_iff, not_iff_not]
exact bounded_lt_inter_lt a
/-! #### Greater or equal -/
theorem bounded_ge_inter_not_ge [SemilatticeInf α] (a : α) :
Bounded (· ≥ ·) (s ∩ { b | ¬a ≤ b }) ↔ Bounded (· ≥ ·) s :=
@bounded_le_inter_not_le αᵒᵈ s _ a
theorem unbounded_ge_inter_not_ge [SemilatticeInf α] (a : α) :
Unbounded (· ≥ ·) (s ∩ { b | ¬a ≤ b }) ↔ Unbounded (· ≥ ·) s :=
@unbounded_le_inter_not_le αᵒᵈ s _ a
theorem bounded_ge_inter_gt [LinearOrder α] (a : α) :
Bounded (· ≥ ·) (s ∩ { b | b < a }) ↔ Bounded (· ≥ ·) s :=
@bounded_le_inter_lt αᵒᵈ s _ a
theorem unbounded_ge_inter_gt [LinearOrder α] (a : α) :
Unbounded (· ≥ ·) (s ∩ { b | b < a }) ↔ Unbounded (· ≥ ·) s :=
@unbounded_le_inter_lt αᵒᵈ s _ a
theorem bounded_ge_inter_ge [LinearOrder α] (a : α) :
Bounded (· ≥ ·) (s ∩ { b | b ≤ a }) ↔ Bounded (· ≥ ·) s :=
@bounded_le_inter_le αᵒᵈ s _ a
theorem unbounded_ge_iff_unbounded_inter_ge [LinearOrder α] (a : α) :
Unbounded (· ≥ ·) (s ∩ { b | b ≤ a }) ↔ Unbounded (· ≥ ·) s :=
@unbounded_le_inter_le αᵒᵈ s _ a
/-! #### Greater than -/
theorem bounded_gt_inter_not_gt [SemilatticeInf α] (a : α) :
Bounded (· > ·) (s ∩ { b | ¬a < b }) ↔ Bounded (· > ·) s :=
@bounded_lt_inter_not_lt αᵒᵈ s _ a
theorem unbounded_gt_inter_not_gt [SemilatticeInf α] (a : α) :
Unbounded (· > ·) (s ∩ { b | ¬a < b }) ↔ Unbounded (· > ·) s :=
@unbounded_lt_inter_not_lt αᵒᵈ s _ a
theorem bounded_gt_inter_ge [LinearOrder α] (a : α) :
Bounded (· > ·) (s ∩ { b | b ≤ a }) ↔ Bounded (· > ·) s :=
@bounded_lt_inter_le αᵒᵈ s _ a
theorem unbounded_inter_ge [LinearOrder α] (a : α) :
Unbounded (· > ·) (s ∩ { b | b ≤ a }) ↔ Unbounded (· > ·) s :=
@unbounded_lt_inter_le αᵒᵈ s _ a
theorem bounded_gt_inter_gt [LinearOrder α] [NoMinOrder α] (a : α) :
Bounded (· > ·) (s ∩ { b | b < a }) ↔ Bounded (· > ·) s :=
@bounded_lt_inter_lt αᵒᵈ s _ _ a
theorem unbounded_gt_inter_gt [LinearOrder α] [NoMinOrder α] (a : α) :
Unbounded (· > ·) (s ∩ { b | b < a }) ↔ Unbounded (· > ·) s :=
@unbounded_lt_inter_lt αᵒᵈ s _ _ a
end Set
|
Order\BoundedOrder.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Order.Lattice
import Mathlib.Order.ULift
import Mathlib.Tactic.PushNeg
/-!
# ⊤ and ⊥, bounded lattices and variants
This file defines top and bottom elements (greatest and least elements) of a type, the bounded
variants of different kinds of lattices, sets up the typeclass hierarchy between them and provides
instances for `Prop` and `fun`.
## Main declarations
* `<Top/Bot> α`: Typeclasses to declare the `⊤`/`⊥` notation.
* `Order<Top/Bot> α`: Order with a top/bottom element.
* `BoundedOrder α`: Order with a top and bottom element.
## Common lattices
* Distributive lattices with a bottom element. Notated by `[DistribLattice α] [OrderBot α]`
It captures the properties of `Disjoint` that are common to `GeneralizedBooleanAlgebra` and
`DistribLattice` when `OrderBot`.
* Bounded and distributive lattice. Notated by `[DistribLattice α] [BoundedOrder α]`.
Typical examples include `Prop` and `Det α`.
-/
open Function OrderDual
universe u v
variable {α : Type u} {β : Type v} {γ δ : Type*}
/-! ### Top, bottom element -/
/-- An order is an `OrderTop` if it has a greatest element.
We state this using a data mixin, holding the value of `⊤` and the greatest element constraint. -/
class OrderTop (α : Type u) [LE α] extends Top α where
/-- `⊤` is the greatest element -/
le_top : ∀ a : α, a ≤ ⊤
section OrderTop
/-- An order is (noncomputably) either an `OrderTop` or a `NoTopOrder`. Use as
`casesI topOrderOrNoTopOrder α`. -/
noncomputable def topOrderOrNoTopOrder (α : Type*) [LE α] : OrderTop α ⊕' NoTopOrder α := by
by_cases H : ∀ a : α, ∃ b, ¬b ≤ a
· exact PSum.inr ⟨H⟩
· push_neg at H
letI : Top α := ⟨Classical.choose H⟩
exact PSum.inl ⟨Classical.choose_spec H⟩
section LE
variable [LE α] [OrderTop α] {a : α}
@[simp]
theorem le_top : a ≤ ⊤ :=
OrderTop.le_top a
@[simp]
theorem isTop_top : IsTop (⊤ : α) := fun _ => le_top
end LE
section Preorder
variable [Preorder α] [OrderTop α] {a b : α}
@[simp]
theorem isMax_top : IsMax (⊤ : α) :=
isTop_top.isMax
@[simp]
theorem not_top_lt : ¬⊤ < a :=
isMax_top.not_lt
theorem ne_top_of_lt (h : a < b) : a ≠ ⊤ :=
(h.trans_le le_top).ne
alias LT.lt.ne_top := ne_top_of_lt
end Preorder
variable [PartialOrder α] [OrderTop α] [Preorder β] {f : α → β} {a b : α}
@[simp]
theorem isMax_iff_eq_top : IsMax a ↔ a = ⊤ :=
⟨fun h => h.eq_of_le le_top, fun h _ _ => h.symm ▸ le_top⟩
@[simp]
theorem isTop_iff_eq_top : IsTop a ↔ a = ⊤ :=
⟨fun h => h.isMax.eq_of_le le_top, fun h _ => h.symm ▸ le_top⟩
theorem not_isMax_iff_ne_top : ¬IsMax a ↔ a ≠ ⊤ :=
isMax_iff_eq_top.not
theorem not_isTop_iff_ne_top : ¬IsTop a ↔ a ≠ ⊤ :=
isTop_iff_eq_top.not
alias ⟨IsMax.eq_top, _⟩ := isMax_iff_eq_top
alias ⟨IsTop.eq_top, _⟩ := isTop_iff_eq_top
@[simp]
theorem top_le_iff : ⊤ ≤ a ↔ a = ⊤ :=
le_top.le_iff_eq.trans eq_comm
theorem top_unique (h : ⊤ ≤ a) : a = ⊤ :=
le_top.antisymm h
theorem eq_top_iff : a = ⊤ ↔ ⊤ ≤ a :=
top_le_iff.symm
theorem eq_top_mono (h : a ≤ b) (h₂ : a = ⊤) : b = ⊤ :=
top_unique <| h₂ ▸ h
theorem lt_top_iff_ne_top : a < ⊤ ↔ a ≠ ⊤ :=
le_top.lt_iff_ne
@[simp]
theorem not_lt_top_iff : ¬a < ⊤ ↔ a = ⊤ :=
lt_top_iff_ne_top.not_left
theorem eq_top_or_lt_top (a : α) : a = ⊤ ∨ a < ⊤ :=
le_top.eq_or_lt
theorem Ne.lt_top (h : a ≠ ⊤) : a < ⊤ :=
lt_top_iff_ne_top.mpr h
theorem Ne.lt_top' (h : ⊤ ≠ a) : a < ⊤ :=
h.symm.lt_top
theorem ne_top_of_le_ne_top (hb : b ≠ ⊤) (hab : a ≤ b) : a ≠ ⊤ :=
(hab.trans_lt hb.lt_top).ne
theorem StrictMono.apply_eq_top_iff (hf : StrictMono f) : f a = f ⊤ ↔ a = ⊤ :=
⟨fun h => not_lt_top_iff.1 fun ha => (hf ha).ne h, congr_arg _⟩
theorem StrictAnti.apply_eq_top_iff (hf : StrictAnti f) : f a = f ⊤ ↔ a = ⊤ :=
⟨fun h => not_lt_top_iff.1 fun ha => (hf ha).ne' h, congr_arg _⟩
variable [Nontrivial α]
theorem not_isMin_top : ¬IsMin (⊤ : α) := fun h =>
let ⟨_, ha⟩ := exists_ne (⊤ : α)
ha <| top_le_iff.1 <| h le_top
end OrderTop
theorem StrictMono.maximal_preimage_top [LinearOrder α] [Preorder β] [OrderTop β] {f : α → β}
(H : StrictMono f) {a} (h_top : f a = ⊤) (x : α) : x ≤ a :=
H.maximal_of_maximal_image
(fun p => by
rw [h_top]
exact le_top)
x
theorem OrderTop.ext_top {α} {hA : PartialOrder α} (A : OrderTop α) {hB : PartialOrder α}
(B : OrderTop α) (H : ∀ x y : α, (haveI := hA; x ≤ y) ↔ x ≤ y) :
(@Top.top α (@OrderTop.toTop α hA.toLE A)) = (@Top.top α (@OrderTop.toTop α hB.toLE B)) := by
cases PartialOrder.ext H
apply top_unique
exact @le_top _ _ A _
/-- An order is an `OrderBot` if it has a least element.
We state this using a data mixin, holding the value of `⊥` and the least element constraint. -/
class OrderBot (α : Type u) [LE α] extends Bot α where
/-- `⊥` is the least element -/
bot_le : ∀ a : α, ⊥ ≤ a
section OrderBot
/-- An order is (noncomputably) either an `OrderBot` or a `NoBotOrder`. Use as
`casesI botOrderOrNoBotOrder α`. -/
noncomputable def botOrderOrNoBotOrder (α : Type*) [LE α] : OrderBot α ⊕' NoBotOrder α := by
by_cases H : ∀ a : α, ∃ b, ¬a ≤ b
· exact PSum.inr ⟨H⟩
· push_neg at H
letI : Bot α := ⟨Classical.choose H⟩
exact PSum.inl ⟨Classical.choose_spec H⟩
section LE
variable [LE α] [OrderBot α] {a : α}
@[simp]
theorem bot_le : ⊥ ≤ a :=
OrderBot.bot_le a
@[simp]
theorem isBot_bot : IsBot (⊥ : α) := fun _ => bot_le
end LE
namespace OrderDual
variable (α)
instance instTop [Bot α] : Top αᵒᵈ :=
⟨(⊥ : α)⟩
instance instBot [Top α] : Bot αᵒᵈ :=
⟨(⊤ : α)⟩
instance instOrderTop [LE α] [OrderBot α] : OrderTop αᵒᵈ where
__ := inferInstanceAs (Top αᵒᵈ)
le_top := @bot_le α _ _
instance instOrderBot [LE α] [OrderTop α] : OrderBot αᵒᵈ where
__ := inferInstanceAs (Bot αᵒᵈ)
bot_le := @le_top α _ _
@[simp]
theorem ofDual_bot [Top α] : ofDual ⊥ = (⊤ : α) :=
rfl
@[simp]
theorem ofDual_top [Bot α] : ofDual ⊤ = (⊥ : α) :=
rfl
@[simp]
theorem toDual_bot [Bot α] : toDual (⊥ : α) = ⊤ :=
rfl
@[simp]
theorem toDual_top [Top α] : toDual (⊤ : α) = ⊥ :=
rfl
end OrderDual
section Preorder
variable [Preorder α] [OrderBot α] {a b : α}
@[simp]
theorem isMin_bot : IsMin (⊥ : α) :=
isBot_bot.isMin
@[simp]
theorem not_lt_bot : ¬a < ⊥ :=
isMin_bot.not_lt
theorem ne_bot_of_gt (h : a < b) : b ≠ ⊥ :=
(bot_le.trans_lt h).ne'
alias LT.lt.ne_bot := ne_bot_of_gt
end Preorder
variable [PartialOrder α] [OrderBot α] [Preorder β] {f : α → β} {a b : α}
@[simp]
theorem isMin_iff_eq_bot : IsMin a ↔ a = ⊥ :=
⟨fun h => h.eq_of_ge bot_le, fun h _ _ => h.symm ▸ bot_le⟩
@[simp]
theorem isBot_iff_eq_bot : IsBot a ↔ a = ⊥ :=
⟨fun h => h.isMin.eq_of_ge bot_le, fun h _ => h.symm ▸ bot_le⟩
theorem not_isMin_iff_ne_bot : ¬IsMin a ↔ a ≠ ⊥ :=
isMin_iff_eq_bot.not
theorem not_isBot_iff_ne_bot : ¬IsBot a ↔ a ≠ ⊥ :=
isBot_iff_eq_bot.not
alias ⟨IsMin.eq_bot, _⟩ := isMin_iff_eq_bot
alias ⟨IsBot.eq_bot, _⟩ := isBot_iff_eq_bot
@[simp]
theorem le_bot_iff : a ≤ ⊥ ↔ a = ⊥ :=
bot_le.le_iff_eq
theorem bot_unique (h : a ≤ ⊥) : a = ⊥ :=
h.antisymm bot_le
theorem eq_bot_iff : a = ⊥ ↔ a ≤ ⊥ :=
le_bot_iff.symm
theorem eq_bot_mono (h : a ≤ b) (h₂ : b = ⊥) : a = ⊥ :=
bot_unique <| h₂ ▸ h
theorem bot_lt_iff_ne_bot : ⊥ < a ↔ a ≠ ⊥ :=
bot_le.lt_iff_ne.trans ne_comm
@[simp]
theorem not_bot_lt_iff : ¬⊥ < a ↔ a = ⊥ :=
bot_lt_iff_ne_bot.not_left
theorem eq_bot_or_bot_lt (a : α) : a = ⊥ ∨ ⊥ < a :=
bot_le.eq_or_gt
theorem eq_bot_of_minimal (h : ∀ b, ¬b < a) : a = ⊥ :=
(eq_bot_or_bot_lt a).resolve_right (h ⊥)
theorem Ne.bot_lt (h : a ≠ ⊥) : ⊥ < a :=
bot_lt_iff_ne_bot.mpr h
theorem Ne.bot_lt' (h : ⊥ ≠ a) : ⊥ < a :=
h.symm.bot_lt
theorem ne_bot_of_le_ne_bot (hb : b ≠ ⊥) (hab : b ≤ a) : a ≠ ⊥ :=
(hb.bot_lt.trans_le hab).ne'
theorem StrictMono.apply_eq_bot_iff (hf : StrictMono f) : f a = f ⊥ ↔ a = ⊥ :=
hf.dual.apply_eq_top_iff
theorem StrictAnti.apply_eq_bot_iff (hf : StrictAnti f) : f a = f ⊥ ↔ a = ⊥ :=
hf.dual.apply_eq_top_iff
variable [Nontrivial α]
theorem not_isMax_bot : ¬IsMax (⊥ : α) :=
@not_isMin_top αᵒᵈ _ _ _
end OrderBot
theorem StrictMono.minimal_preimage_bot [LinearOrder α] [PartialOrder β] [OrderBot β] {f : α → β}
(H : StrictMono f) {a} (h_bot : f a = ⊥) (x : α) : a ≤ x :=
H.minimal_of_minimal_image
(fun p => by
rw [h_bot]
exact bot_le)
x
theorem OrderBot.ext_bot {α} {hA : PartialOrder α} (A : OrderBot α) {hB : PartialOrder α}
(B : OrderBot α) (H : ∀ x y : α, (haveI := hA; x ≤ y) ↔ x ≤ y) :
(@Bot.bot α (@OrderBot.toBot α hA.toLE A)) = (@Bot.bot α (@OrderBot.toBot α hB.toLE B)) := by
cases PartialOrder.ext H
apply bot_unique
exact @bot_le _ _ A _
section SemilatticeSupTop
variable [SemilatticeSup α] [OrderTop α] {a : α}
-- Porting note: Not simp because simp can prove it
theorem top_sup_eq (a : α) : ⊤ ⊔ a = ⊤ :=
sup_of_le_left le_top
-- Porting note: Not simp because simp can prove it
theorem sup_top_eq (a : α) : a ⊔ ⊤ = ⊤ :=
sup_of_le_right le_top
end SemilatticeSupTop
section SemilatticeSupBot
variable [SemilatticeSup α] [OrderBot α] {a b : α}
-- Porting note: Not simp because simp can prove it
theorem bot_sup_eq (a : α) : ⊥ ⊔ a = a :=
sup_of_le_right bot_le
-- Porting note: Not simp because simp can prove it
theorem sup_bot_eq (a : α) : a ⊔ ⊥ = a :=
sup_of_le_left bot_le
@[simp]
theorem sup_eq_bot_iff : a ⊔ b = ⊥ ↔ a = ⊥ ∧ b = ⊥ := by rw [eq_bot_iff, sup_le_iff]; simp
end SemilatticeSupBot
section SemilatticeInfTop
variable [SemilatticeInf α] [OrderTop α] {a b : α}
-- Porting note: Not simp because simp can prove it
lemma top_inf_eq (a : α) : ⊤ ⊓ a = a := inf_of_le_right le_top
-- Porting note: Not simp because simp can prove it
lemma inf_top_eq (a : α) : a ⊓ ⊤ = a := inf_of_le_left le_top
@[simp]
theorem inf_eq_top_iff : a ⊓ b = ⊤ ↔ a = ⊤ ∧ b = ⊤ :=
@sup_eq_bot_iff αᵒᵈ _ _ _ _
end SemilatticeInfTop
section SemilatticeInfBot
variable [SemilatticeInf α] [OrderBot α] {a : α}
-- Porting note: Not simp because simp can prove it
lemma bot_inf_eq (a : α) : ⊥ ⊓ a = ⊥ := inf_of_le_left bot_le
-- Porting note: Not simp because simp can prove it
lemma inf_bot_eq (a : α) : a ⊓ ⊥ = ⊥ := inf_of_le_right bot_le
end SemilatticeInfBot
/-! ### Bounded order -/
/-- A bounded order describes an order `(≤)` with a top and bottom element,
denoted `⊤` and `⊥` respectively. -/
class BoundedOrder (α : Type u) [LE α] extends OrderTop α, OrderBot α
instance OrderDual.instBoundedOrder (α : Type u) [LE α] [BoundedOrder α] : BoundedOrder αᵒᵈ where
__ := inferInstanceAs (OrderTop αᵒᵈ)
__ := inferInstanceAs (OrderBot αᵒᵈ)
section PartialOrder
variable [PartialOrder α]
instance OrderBot.instSubsingleton : Subsingleton (OrderBot α) where
allEq := by rintro @⟨⟨a⟩, ha⟩ @⟨⟨b⟩, hb⟩; congr; exact le_antisymm (ha _) (hb _)
instance OrderTop.instSubsingleton : Subsingleton (OrderTop α) where
allEq := by rintro @⟨⟨a⟩, ha⟩ @⟨⟨b⟩, hb⟩; congr; exact le_antisymm (hb _) (ha _)
instance BoundedOrder.instSubsingleton : Subsingleton (BoundedOrder α) where
allEq := by rintro ⟨⟩ ⟨⟩; congr <;> exact Subsingleton.elim _ _
end PartialOrder
section Logic
/-!
#### In this section we prove some properties about monotone and antitone operations on `Prop`
-/
section Preorder
variable [Preorder α]
theorem monotone_and {p q : α → Prop} (m_p : Monotone p) (m_q : Monotone q) :
Monotone fun x => p x ∧ q x :=
fun _ _ h => And.imp (m_p h) (m_q h)
-- Note: by finish [monotone] doesn't work
theorem monotone_or {p q : α → Prop} (m_p : Monotone p) (m_q : Monotone q) :
Monotone fun x => p x ∨ q x :=
fun _ _ h => Or.imp (m_p h) (m_q h)
theorem monotone_le {x : α} : Monotone (x ≤ ·) := fun _ _ h' h => h.trans h'
theorem monotone_lt {x : α} : Monotone (x < ·) := fun _ _ h' h => h.trans_le h'
theorem antitone_le {x : α} : Antitone (· ≤ x) := fun _ _ h' h => h'.trans h
theorem antitone_lt {x : α} : Antitone (· < x) := fun _ _ h' h => h'.trans_lt h
theorem Monotone.forall {P : β → α → Prop} (hP : ∀ x, Monotone (P x)) :
Monotone fun y => ∀ x, P x y :=
fun _ _ hy h x => hP x hy <| h x
theorem Antitone.forall {P : β → α → Prop} (hP : ∀ x, Antitone (P x)) :
Antitone fun y => ∀ x, P x y :=
fun _ _ hy h x => hP x hy (h x)
theorem Monotone.ball {P : β → α → Prop} {s : Set β} (hP : ∀ x ∈ s, Monotone (P x)) :
Monotone fun y => ∀ x ∈ s, P x y := fun _ _ hy h x hx => hP x hx hy (h x hx)
theorem Antitone.ball {P : β → α → Prop} {s : Set β} (hP : ∀ x ∈ s, Antitone (P x)) :
Antitone fun y => ∀ x ∈ s, P x y := fun _ _ hy h x hx => hP x hx hy (h x hx)
theorem Monotone.exists {P : β → α → Prop} (hP : ∀ x, Monotone (P x)) :
Monotone fun y => ∃ x, P x y :=
fun _ _ hy ⟨x, hx⟩ ↦ ⟨x, hP x hy hx⟩
theorem Antitone.exists {P : β → α → Prop} (hP : ∀ x, Antitone (P x)) :
Antitone fun y => ∃ x, P x y :=
fun _ _ hy ⟨x, hx⟩ ↦ ⟨x, hP x hy hx⟩
theorem forall_ge_iff {P : α → Prop} {x₀ : α} (hP : Monotone P) :
(∀ x ≥ x₀, P x) ↔ P x₀ :=
⟨fun H ↦ H x₀ le_rfl, fun H _ hx ↦ hP hx H⟩
theorem forall_le_iff {P : α → Prop} {x₀ : α} (hP : Antitone P) :
(∀ x ≤ x₀, P x) ↔ P x₀ :=
⟨fun H ↦ H x₀ le_rfl, fun H _ hx ↦ hP hx H⟩
end Preorder
section SemilatticeSup
variable [SemilatticeSup α]
theorem exists_ge_and_iff_exists {P : α → Prop} {x₀ : α} (hP : Monotone P) :
(∃ x, x₀ ≤ x ∧ P x) ↔ ∃ x, P x :=
⟨fun h => h.imp fun _ h => h.2, fun ⟨x, hx⟩ => ⟨x ⊔ x₀, le_sup_right, hP le_sup_left hx⟩⟩
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α]
theorem exists_le_and_iff_exists {P : α → Prop} {x₀ : α} (hP : Antitone P) :
(∃ x, x ≤ x₀ ∧ P x) ↔ ∃ x, P x :=
exists_ge_and_iff_exists <| hP.dual_left
end SemilatticeInf
end Logic
/-! ### Function lattices -/
namespace Pi
variable {ι : Type*} {α' : ι → Type*}
instance [∀ i, Bot (α' i)] : Bot (∀ i, α' i) :=
⟨fun _ => ⊥⟩
@[simp]
theorem bot_apply [∀ i, Bot (α' i)] (i : ι) : (⊥ : ∀ i, α' i) i = ⊥ :=
rfl
theorem bot_def [∀ i, Bot (α' i)] : (⊥ : ∀ i, α' i) = fun _ => ⊥ :=
rfl
instance [∀ i, Top (α' i)] : Top (∀ i, α' i) :=
⟨fun _ => ⊤⟩
@[simp]
theorem top_apply [∀ i, Top (α' i)] (i : ι) : (⊤ : ∀ i, α' i) i = ⊤ :=
rfl
theorem top_def [∀ i, Top (α' i)] : (⊤ : ∀ i, α' i) = fun _ => ⊤ :=
rfl
instance instOrderTop [∀ i, LE (α' i)] [∀ i, OrderTop (α' i)] : OrderTop (∀ i, α' i) where
le_top _ := fun _ => le_top
instance instOrderBot [∀ i, LE (α' i)] [∀ i, OrderBot (α' i)] : OrderBot (∀ i, α' i) where
bot_le _ := fun _ => bot_le
instance instBoundedOrder [∀ i, LE (α' i)] [∀ i, BoundedOrder (α' i)] :
BoundedOrder (∀ i, α' i) where
__ := inferInstanceAs (OrderTop (∀ i, α' i))
__ := inferInstanceAs (OrderBot (∀ i, α' i))
end Pi
section Subsingleton
variable [PartialOrder α] [BoundedOrder α]
theorem eq_bot_of_bot_eq_top (hα : (⊥ : α) = ⊤) (x : α) : x = (⊥ : α) :=
eq_bot_mono le_top (Eq.symm hα)
theorem eq_top_of_bot_eq_top (hα : (⊥ : α) = ⊤) (x : α) : x = (⊤ : α) :=
eq_top_mono bot_le hα
theorem subsingleton_of_top_le_bot (h : (⊤ : α) ≤ (⊥ : α)) : Subsingleton α :=
⟨fun _ _ => le_antisymm
(le_trans le_top <| le_trans h bot_le) (le_trans le_top <| le_trans h bot_le)⟩
theorem subsingleton_of_bot_eq_top (hα : (⊥ : α) = (⊤ : α)) : Subsingleton α :=
subsingleton_of_top_le_bot (ge_of_eq hα)
theorem subsingleton_iff_bot_eq_top : (⊥ : α) = (⊤ : α) ↔ Subsingleton α :=
⟨subsingleton_of_bot_eq_top, fun _ => Subsingleton.elim ⊥ ⊤⟩
end Subsingleton
section lift
-- See note [reducible non-instances]
/-- Pullback an `OrderTop`. -/
abbrev OrderTop.lift [LE α] [Top α] [LE β] [OrderTop β] (f : α → β)
(map_le : ∀ a b, f a ≤ f b → a ≤ b) (map_top : f ⊤ = ⊤) : OrderTop α :=
⟨fun a =>
map_le _ _ <| by
rw [map_top]
-- Porting note: lean3 didn't need the type annotation
exact @le_top β _ _ _⟩
-- See note [reducible non-instances]
/-- Pullback an `OrderBot`. -/
abbrev OrderBot.lift [LE α] [Bot α] [LE β] [OrderBot β] (f : α → β)
(map_le : ∀ a b, f a ≤ f b → a ≤ b) (map_bot : f ⊥ = ⊥) : OrderBot α :=
⟨fun a =>
map_le _ _ <| by
rw [map_bot]
-- Porting note: lean3 didn't need the type annotation
exact @bot_le β _ _ _⟩
-- See note [reducible non-instances]
/-- Pullback a `BoundedOrder`. -/
abbrev BoundedOrder.lift [LE α] [Top α] [Bot α] [LE β] [BoundedOrder β] (f : α → β)
(map_le : ∀ a b, f a ≤ f b → a ≤ b) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) :
BoundedOrder α where
__ := OrderTop.lift f map_le map_top
__ := OrderBot.lift f map_le map_bot
end lift
/-! ### Subtype, order dual, product lattices -/
namespace Subtype
variable {p : α → Prop}
-- See note [reducible non-instances]
/-- A subtype remains a `⊥`-order if the property holds at `⊥`. -/
protected abbrev orderBot [LE α] [OrderBot α] (hbot : p ⊥) : OrderBot { x : α // p x } where
bot := ⟨⊥, hbot⟩
bot_le _ := bot_le
-- See note [reducible non-instances]
/-- A subtype remains a `⊤`-order if the property holds at `⊤`. -/
protected abbrev orderTop [LE α] [OrderTop α] (htop : p ⊤) : OrderTop { x : α // p x } where
top := ⟨⊤, htop⟩
le_top _ := le_top
-- See note [reducible non-instances]
/-- A subtype remains a bounded order if the property holds at `⊥` and `⊤`. -/
protected abbrev boundedOrder [LE α] [BoundedOrder α] (hbot : p ⊥) (htop : p ⊤) :
BoundedOrder (Subtype p) where
__ := Subtype.orderTop htop
__ := Subtype.orderBot hbot
variable [PartialOrder α]
@[simp]
theorem mk_bot [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) : mk ⊥ hbot = ⊥ :=
le_bot_iff.1 <| coe_le_coe.1 bot_le
@[simp]
theorem mk_top [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) : mk ⊤ htop = ⊤ :=
top_le_iff.1 <| coe_le_coe.1 le_top
theorem coe_bot [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) : ((⊥ : Subtype p) : α) = ⊥ :=
congr_arg Subtype.val (mk_bot hbot).symm
theorem coe_top [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) : ((⊤ : Subtype p) : α) = ⊤ :=
congr_arg Subtype.val (mk_top htop).symm
@[simp]
theorem coe_eq_bot_iff [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) {x : { x // p x }} :
(x : α) = ⊥ ↔ x = ⊥ := by
rw [← coe_bot hbot, Subtype.ext_iff]
@[simp]
theorem coe_eq_top_iff [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) {x : { x // p x }} :
(x : α) = ⊤ ↔ x = ⊤ := by
rw [← coe_top htop, Subtype.ext_iff]
@[simp]
theorem mk_eq_bot_iff [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) {x : α} (hx : p x) :
(⟨x, hx⟩ : Subtype p) = ⊥ ↔ x = ⊥ :=
(coe_eq_bot_iff hbot).symm
@[simp]
theorem mk_eq_top_iff [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) {x : α} (hx : p x) :
(⟨x, hx⟩ : Subtype p) = ⊤ ↔ x = ⊤ :=
(coe_eq_top_iff htop).symm
end Subtype
namespace Prod
variable (α β)
instance instTop [Top α] [Top β] : Top (α × β) :=
⟨⟨⊤, ⊤⟩⟩
instance instBot [Bot α] [Bot β] : Bot (α × β) :=
⟨⟨⊥, ⊥⟩⟩
theorem fst_top [Top α] [Top β] : (⊤ : α × β).fst = ⊤ := rfl
theorem snd_top [Top α] [Top β] : (⊤ : α × β).snd = ⊤ := rfl
theorem fst_bot [Bot α] [Bot β] : (⊥ : α × β).fst = ⊥ := rfl
theorem snd_bot [Bot α] [Bot β] : (⊥ : α × β).snd = ⊥ := rfl
instance instOrderTop [LE α] [LE β] [OrderTop α] [OrderTop β] : OrderTop (α × β) where
__ := inferInstanceAs (Top (α × β))
le_top _ := ⟨le_top, le_top⟩
instance instOrderBot [LE α] [LE β] [OrderBot α] [OrderBot β] : OrderBot (α × β) where
__ := inferInstanceAs (Bot (α × β))
bot_le _ := ⟨bot_le, bot_le⟩
instance instBoundedOrder [LE α] [LE β] [BoundedOrder α] [BoundedOrder β] :
BoundedOrder (α × β) where
__ := inferInstanceAs (OrderTop (α × β))
__ := inferInstanceAs (OrderBot (α × β))
end Prod
namespace ULift
instance [Top α] : Top (ULift.{v} α) where top := up ⊤
@[simp] theorem up_top [Top α] : up (⊤ : α) = ⊤ := rfl
@[simp] theorem down_top [Top α] : down (⊤ : ULift α) = ⊤ := rfl
instance [Bot α] : Bot (ULift.{v} α) where bot := up ⊥
@[simp] theorem up_bot [Bot α] : up (⊥ : α) = ⊥ := rfl
@[simp] theorem down_bot [Bot α] : down (⊥ : ULift α) = ⊥ := rfl
instance [LE α] [OrderBot α] : OrderBot (ULift.{v} α) :=
OrderBot.lift ULift.down (fun _ _ => down_le.mp) down_bot
instance [LE α] [OrderTop α] : OrderTop (ULift.{v} α) :=
OrderTop.lift ULift.down (fun _ _ => down_le.mp) down_top
instance [LE α] [BoundedOrder α] : BoundedOrder (ULift.{v} α) where
end ULift
section LinearOrder
variable [LinearOrder α]
-- `simp` can prove these, so they shouldn't be simp-lemmas.
theorem min_bot_left [OrderBot α] (a : α) : min ⊥ a = ⊥ := bot_inf_eq _
theorem max_top_left [OrderTop α] (a : α) : max ⊤ a = ⊤ := top_sup_eq _
theorem min_top_left [OrderTop α] (a : α) : min ⊤ a = a := top_inf_eq _
theorem max_bot_left [OrderBot α] (a : α) : max ⊥ a = a := bot_sup_eq _
theorem min_top_right [OrderTop α] (a : α) : min a ⊤ = a := inf_top_eq _
theorem max_bot_right [OrderBot α] (a : α) : max a ⊥ = a := sup_bot_eq _
theorem min_bot_right [OrderBot α] (a : α) : min a ⊥ = ⊥ := inf_bot_eq _
theorem max_top_right [OrderTop α] (a : α) : max a ⊤ = ⊤ := sup_top_eq _
@[simp]
theorem min_eq_bot [OrderBot α] {a b : α} : min a b = ⊥ ↔ a = ⊥ ∨ b = ⊥ := by
simp only [← inf_eq_min, ← le_bot_iff, inf_le_iff]
@[simp]
theorem max_eq_top [OrderTop α] {a b : α} : max a b = ⊤ ↔ a = ⊤ ∨ b = ⊤ :=
@min_eq_bot αᵒᵈ _ _ a b
@[simp]
theorem max_eq_bot [OrderBot α] {a b : α} : max a b = ⊥ ↔ a = ⊥ ∧ b = ⊥ :=
sup_eq_bot_iff
@[simp]
theorem min_eq_top [OrderTop α] {a b : α} : min a b = ⊤ ↔ a = ⊤ ∧ b = ⊤ :=
inf_eq_top_iff
end LinearOrder
section Nontrivial
variable [PartialOrder α] [BoundedOrder α] [Nontrivial α]
@[simp]
theorem bot_ne_top : (⊥ : α) ≠ ⊤ := fun h => not_subsingleton _ <| subsingleton_of_bot_eq_top h
@[simp]
theorem top_ne_bot : (⊤ : α) ≠ ⊥ :=
bot_ne_top.symm
@[simp]
theorem bot_lt_top : (⊥ : α) < ⊤ :=
lt_top_iff_ne_top.2 bot_ne_top
end Nontrivial
section Bool
open Bool
instance Bool.instBoundedOrder : BoundedOrder Bool where
top := true
le_top := Bool.le_true
bot := false
bot_le := Bool.false_le
@[simp]
theorem top_eq_true : ⊤ = true :=
rfl
@[simp]
theorem bot_eq_false : ⊥ = false :=
rfl
end Bool
|
Order\Chain.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Set.Pairwise.Basic
import Mathlib.Data.Set.Lattice
import Mathlib.Data.SetLike.Basic
/-!
# Chains and flags
This file defines chains for an arbitrary relation and flags for an order and proves Hausdorff's
Maximality Principle.
## Main declarations
* `IsChain s`: A chain `s` is a set of comparable elements.
* `maxChain_spec`: Hausdorff's Maximality Principle.
* `Flag`: The type of flags, aka maximal chains, of an order.
## Notes
Originally ported from Isabelle/HOL. The
[original file](https://isabelle.in.tum.de/dist/library/HOL/HOL/Zorn.html) was written by Jacques D.
Fleuriot, Tobias Nipkow, Christian Sternagel.
-/
open Set
variable {α β : Type*}
/-! ### Chains -/
section Chain
variable (r : α → α → Prop)
/-- In this file, we use `≺` as a local notation for any relation `r`. -/
local infixl:50 " ≺ " => r
/-- A chain is a set `s` satisfying `x ≺ y ∨ x = y ∨ y ≺ x` for all `x y ∈ s`. -/
def IsChain (s : Set α) : Prop :=
s.Pairwise fun x y => x ≺ y ∨ y ≺ x
/-- `SuperChain s t` means that `t` is a chain that strictly includes `s`. -/
def SuperChain (s t : Set α) : Prop :=
IsChain r t ∧ s ⊂ t
/-- A chain `s` is a maximal chain if there does not exists a chain strictly including `s`. -/
def IsMaxChain (s : Set α) : Prop :=
IsChain r s ∧ ∀ ⦃t⦄, IsChain r t → s ⊆ t → s = t
variable {r} {c c₁ c₂ c₃ s t : Set α} {a b x y : α}
theorem isChain_empty : IsChain r ∅ :=
Set.pairwise_empty _
theorem Set.Subsingleton.isChain (hs : s.Subsingleton) : IsChain r s :=
hs.pairwise _
theorem IsChain.mono : s ⊆ t → IsChain r t → IsChain r s :=
Set.Pairwise.mono
theorem IsChain.mono_rel {r' : α → α → Prop} (h : IsChain r s) (h_imp : ∀ x y, r x y → r' x y) :
IsChain r' s :=
h.mono' fun x y => Or.imp (h_imp x y) (h_imp y x)
/-- This can be used to turn `IsChain (≥)` into `IsChain (≤)` and vice-versa. -/
theorem IsChain.symm (h : IsChain r s) : IsChain (flip r) s :=
h.mono' fun _ _ => Or.symm
theorem isChain_of_trichotomous [IsTrichotomous α r] (s : Set α) : IsChain r s :=
fun a _ b _ hab => (trichotomous_of r a b).imp_right fun h => h.resolve_left hab
protected theorem IsChain.insert (hs : IsChain r s) (ha : ∀ b ∈ s, a ≠ b → a ≺ b ∨ b ≺ a) :
IsChain r (insert a s) :=
hs.insert_of_symmetric (fun _ _ => Or.symm) ha
theorem isChain_univ_iff : IsChain r (univ : Set α) ↔ IsTrichotomous α r := by
refine ⟨fun h => ⟨fun a b => ?_⟩, fun h => @isChain_of_trichotomous _ _ h univ⟩
rw [or_left_comm, or_iff_not_imp_left]
exact h trivial trivial
theorem IsChain.image (r : α → α → Prop) (s : β → β → Prop) (f : α → β)
(h : ∀ x y, r x y → s (f x) (f y)) {c : Set α} (hrc : IsChain r c) : IsChain s (f '' c) :=
fun _ ⟨_, ha₁, ha₂⟩ _ ⟨_, hb₁, hb₂⟩ =>
ha₂ ▸ hb₂ ▸ fun hxy => (hrc ha₁ hb₁ <| ne_of_apply_ne f hxy).imp (h _ _) (h _ _)
theorem Monotone.isChain_range [LinearOrder α] [Preorder β] {f : α → β} (hf : Monotone f) :
IsChain (· ≤ ·) (range f) := by
rw [← image_univ]
exact (isChain_of_trichotomous _).image (· ≤ ·) _ _ hf
theorem IsChain.lt_of_le [PartialOrder α] {s : Set α} (h : IsChain (· ≤ ·) s) :
IsChain (· < ·) s := fun _a ha _b hb hne ↦
(h ha hb hne).imp hne.lt_of_le hne.lt_of_le'
section Total
variable [IsRefl α r]
theorem IsChain.total (h : IsChain r s) (hx : x ∈ s) (hy : y ∈ s) : x ≺ y ∨ y ≺ x :=
(eq_or_ne x y).elim (fun e => Or.inl <| e ▸ refl _) (h hx hy)
theorem IsChain.directedOn (H : IsChain r s) : DirectedOn r s := fun x hx y hy =>
((H.total hx hy).elim fun h => ⟨y, hy, h, refl _⟩) fun h => ⟨x, hx, refl _, h⟩
protected theorem IsChain.directed {f : β → α} {c : Set β} (h : IsChain (f ⁻¹'o r) c) :
Directed r fun x : { a : β // a ∈ c } => f x :=
fun ⟨a, ha⟩ ⟨b, hb⟩ =>
(by_cases fun hab : a = b => by
simp only [hab, exists_prop, and_self_iff, Subtype.exists]
exact ⟨b, hb, refl _⟩)
fun hab => ((h ha hb hab).elim fun h => ⟨⟨b, hb⟩, h, refl _⟩) fun h => ⟨⟨a, ha⟩, refl _, h⟩
theorem IsChain.exists3 (hchain : IsChain r s) [IsTrans α r] {a b c} (mem1 : a ∈ s) (mem2 : b ∈ s)
(mem3 : c ∈ s) : ∃ (z : _) (_ : z ∈ s), r a z ∧ r b z ∧ r c z := by
rcases directedOn_iff_directed.mpr (IsChain.directed hchain) a mem1 b mem2 with ⟨z, mem4, H1, H2⟩
rcases directedOn_iff_directed.mpr (IsChain.directed hchain) z mem4 c mem3 with
⟨z', mem5, H3, H4⟩
exact ⟨z', mem5, _root_.trans H1 H3, _root_.trans H2 H3, H4⟩
end Total
theorem IsMaxChain.isChain (h : IsMaxChain r s) : IsChain r s :=
h.1
theorem IsMaxChain.not_superChain (h : IsMaxChain r s) : ¬SuperChain r s t := fun ht =>
ht.2.ne <| h.2 ht.1 ht.2.1
theorem IsMaxChain.bot_mem [LE α] [OrderBot α] (h : IsMaxChain (· ≤ ·) s) : ⊥ ∈ s :=
(h.2 (h.1.insert fun _ _ _ => Or.inl bot_le) <| subset_insert _ _).symm ▸ mem_insert _ _
theorem IsMaxChain.top_mem [LE α] [OrderTop α] (h : IsMaxChain (· ≤ ·) s) : ⊤ ∈ s :=
(h.2 (h.1.insert fun _ _ _ => Or.inr le_top) <| subset_insert _ _).symm ▸ mem_insert _ _
open Classical in
/-- Given a set `s`, if there exists a chain `t` strictly including `s`, then `SuccChain s`
is one of these chains. Otherwise it is `s`. -/
def SuccChain (r : α → α → Prop) (s : Set α) : Set α :=
if h : ∃ t, IsChain r s ∧ SuperChain r s t then h.choose else s
theorem succChain_spec (h : ∃ t, IsChain r s ∧ SuperChain r s t) :
SuperChain r s (SuccChain r s) := by
have : IsChain r s ∧ SuperChain r s h.choose := h.choose_spec
simpa [SuccChain, dif_pos, exists_and_left.mp h] using this.2
open Classical in
theorem IsChain.succ (hs : IsChain r s) : IsChain r (SuccChain r s) :=
if h : ∃ t, IsChain r s ∧ SuperChain r s t then (succChain_spec h).1
else by
rw [exists_and_left] at h
simpa [SuccChain, dif_neg, h] using hs
theorem IsChain.superChain_succChain (hs₁ : IsChain r s) (hs₂ : ¬IsMaxChain r s) :
SuperChain r s (SuccChain r s) := by
simp only [IsMaxChain, _root_.not_and, not_forall, exists_prop, exists_and_left] at hs₂
obtain ⟨t, ht, hst⟩ := hs₂ hs₁
exact succChain_spec ⟨t, hs₁, ht, ssubset_iff_subset_ne.2 hst⟩
open Classical in
theorem subset_succChain : s ⊆ SuccChain r s :=
if h : ∃ t, IsChain r s ∧ SuperChain r s t then (succChain_spec h).2.1
else by
rw [exists_and_left] at h
simp [SuccChain, dif_neg, h, Subset.rfl]
/-- Predicate for whether a set is reachable from `∅` using `SuccChain` and `⋃₀`. -/
inductive ChainClosure (r : α → α → Prop) : Set α → Prop
| succ : ∀ {s}, ChainClosure r s → ChainClosure r (SuccChain r s)
| union : ∀ {s}, (∀ a ∈ s, ChainClosure r a) → ChainClosure r (⋃₀s)
/-- An explicit maximal chain. `maxChain` is taken to be the union of all sets in `ChainClosure`.
-/
def maxChain (r : α → α → Prop) : Set α :=
⋃₀ setOf (ChainClosure r)
theorem chainClosure_empty : ChainClosure r ∅ := by
have : ChainClosure r (⋃₀∅) := ChainClosure.union fun a h => (not_mem_empty _ h).elim
simpa using this
theorem chainClosure_maxChain : ChainClosure r (maxChain r) :=
ChainClosure.union fun _ => id
private theorem chainClosure_succ_total_aux (hc₁ : ChainClosure r c₁)
(h : ∀ ⦃c₃⦄, ChainClosure r c₃ → c₃ ⊆ c₂ → c₂ = c₃ ∨ SuccChain r c₃ ⊆ c₂) :
SuccChain r c₂ ⊆ c₁ ∨ c₁ ⊆ c₂ := by
induction hc₁ with
| @succ c₃ hc₃ ih =>
cases' ih with ih ih
· exact Or.inl (ih.trans subset_succChain)
· exact (h hc₃ ih).imp_left fun (h : c₂ = c₃) => h ▸ Subset.rfl
| union _ ih =>
refine or_iff_not_imp_left.2 fun hn => sUnion_subset fun a ha => ?_
exact (ih a ha).resolve_left fun h => hn <| h.trans <| subset_sUnion_of_mem ha
private theorem chainClosure_succ_total (hc₁ : ChainClosure r c₁) (hc₂ : ChainClosure r c₂)
(h : c₁ ⊆ c₂) : c₂ = c₁ ∨ SuccChain r c₁ ⊆ c₂ := by
induction hc₂ generalizing c₁ hc₁ with
| succ _ ih =>
refine ((chainClosure_succ_total_aux hc₁) fun c₁ => ih).imp h.antisymm' fun h₁ => ?_
obtain rfl | h₂ := ih hc₁ h₁
· exact Subset.rfl
· exact h₂.trans subset_succChain
| union _ ih =>
apply Or.imp_left h.antisymm'
apply by_contradiction
simp only [sUnion_subset_iff, not_or, not_forall, exists_prop, and_imp, forall_exists_index]
intro c₃ hc₃ h₁ h₂
obtain h | h := chainClosure_succ_total_aux hc₁ fun c₄ => ih _ hc₃
· exact h₁ (subset_succChain.trans h)
obtain h' | h' := ih c₃ hc₃ hc₁ h
· exact h₁ h'.subset
· exact h₂ (h'.trans <| subset_sUnion_of_mem hc₃)
theorem ChainClosure.total (hc₁ : ChainClosure r c₁) (hc₂ : ChainClosure r c₂) :
c₁ ⊆ c₂ ∨ c₂ ⊆ c₁ :=
((chainClosure_succ_total_aux hc₂) fun _ hc₃ => chainClosure_succ_total hc₃ hc₁).imp_left
subset_succChain.trans
theorem ChainClosure.succ_fixpoint (hc₁ : ChainClosure r c₁) (hc₂ : ChainClosure r c₂)
(hc : SuccChain r c₂ = c₂) : c₁ ⊆ c₂ := by
induction hc₁ with
| succ hc₁ h => exact (chainClosure_succ_total hc₁ hc₂ h).elim (fun h => h ▸ hc.subset) id
| union _ ih => exact sUnion_subset ih
theorem ChainClosure.succ_fixpoint_iff (hc : ChainClosure r c) :
SuccChain r c = c ↔ c = maxChain r :=
⟨fun h => (subset_sUnion_of_mem hc).antisymm <| chainClosure_maxChain.succ_fixpoint hc h,
fun h => subset_succChain.antisymm' <| (subset_sUnion_of_mem hc.succ).trans h.symm.subset⟩
theorem ChainClosure.isChain (hc : ChainClosure r c) : IsChain r c := by
induction hc with
| succ _ h => exact h.succ
| union hs h =>
exact fun c₁ ⟨t₁, ht₁, (hc₁ : c₁ ∈ t₁)⟩ c₂ ⟨t₂, ht₂, (hc₂ : c₂ ∈ t₂)⟩ hneq =>
((hs _ ht₁).total <| hs _ ht₂).elim (fun ht => h t₂ ht₂ (ht hc₁) hc₂ hneq) fun ht =>
h t₁ ht₁ hc₁ (ht hc₂) hneq
/-- **Hausdorff's maximality principle**
There exists a maximal totally ordered set of `α`.
Note that we do not require `α` to be partially ordered by `r`. -/
theorem maxChain_spec : IsMaxChain r (maxChain r) :=
by_contradiction fun h =>
let ⟨_, H⟩ := chainClosure_maxChain.isChain.superChain_succChain h
H.ne (chainClosure_maxChain.succ_fixpoint_iff.mpr rfl).symm
end Chain
/-! ### Flags -/
/-- The type of flags, aka maximal chains, of an order. -/
structure Flag (α : Type*) [LE α] where
/-- The `carrier` of a flag is the underlying set. -/
carrier : Set α
/-- By definition, a flag is a chain -/
Chain' : IsChain (· ≤ ·) carrier
/-- By definition, a flag is a maximal chain -/
max_chain' : ∀ ⦃s⦄, IsChain (· ≤ ·) s → carrier ⊆ s → carrier = s
namespace Flag
section LE
variable [LE α] {s t : Flag α} {a : α}
instance : SetLike (Flag α) α where
coe := carrier
coe_injective' s t h := by
cases s
cases t
congr
@[ext]
theorem ext : (s : Set α) = t → s = t :=
SetLike.ext'
-- Porting note (#10618): `simp` can now prove this
-- @[simp]
theorem mem_coe_iff : a ∈ (s : Set α) ↔ a ∈ s :=
Iff.rfl
@[simp]
theorem coe_mk (s : Set α) (h₁ h₂) : (mk s h₁ h₂ : Set α) = s :=
rfl
@[simp]
theorem mk_coe (s : Flag α) : mk (s : Set α) s.Chain' s.max_chain' = s :=
ext rfl
theorem chain_le (s : Flag α) : IsChain (· ≤ ·) (s : Set α) :=
s.Chain'
protected theorem maxChain (s : Flag α) : IsMaxChain (· ≤ ·) (s : Set α) :=
⟨s.chain_le, s.max_chain'⟩
theorem top_mem [OrderTop α] (s : Flag α) : (⊤ : α) ∈ s :=
s.maxChain.top_mem
theorem bot_mem [OrderBot α] (s : Flag α) : (⊥ : α) ∈ s :=
s.maxChain.bot_mem
end LE
section Preorder
variable [Preorder α] {a b : α}
protected theorem le_or_le (s : Flag α) (ha : a ∈ s) (hb : b ∈ s) : a ≤ b ∨ b ≤ a :=
s.chain_le.total ha hb
instance [OrderTop α] (s : Flag α) : OrderTop s :=
Subtype.orderTop s.top_mem
instance [OrderBot α] (s : Flag α) : OrderBot s :=
Subtype.orderBot s.bot_mem
instance [BoundedOrder α] (s : Flag α) : BoundedOrder s :=
Subtype.boundedOrder s.bot_mem s.top_mem
end Preorder
section PartialOrder
variable [PartialOrder α]
theorem chain_lt (s : Flag α) : IsChain (· < ·) (s : Set α) := s.chain_le.lt_of_le
instance [@DecidableRel α (· ≤ ·)] [@DecidableRel α (· < ·)] (s : Flag α) :
LinearOrder s :=
{ Subtype.partialOrder _ with
le_total := fun a b => s.le_or_le a.2 b.2
decidableLE := Subtype.decidableLE
decidableLT := Subtype.decidableLT }
end PartialOrder
instance [LinearOrder α] : Unique (Flag α) where
default := ⟨univ, isChain_of_trichotomous _, fun s _ => s.subset_univ.antisymm'⟩
uniq s := SetLike.coe_injective <| s.3 (isChain_of_trichotomous _) <| subset_univ _
end Flag
|
Order\Circular.lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Set.Basic
/-!
# Circular order hierarchy
This file defines circular preorders, circular partial orders and circular orders.
## Hierarchy
* A ternary "betweenness" relation `btw : α → α → α → Prop` forms a `CircularOrder` if it is
- reflexive: `btw a a a`
- cyclic: `btw a b c → btw b c a`
- antisymmetric: `btw a b c → btw c b a → a = b ∨ b = c ∨ c = a`
- total: `btw a b c ∨ btw c b a`
along with a strict betweenness relation `sbtw : α → α → α → Prop` which respects
`sbtw a b c ↔ btw a b c ∧ ¬ btw c b a`, analogously to how `<` and `≤` are related, and is
- transitive: `sbtw a b c → sbtw b d c → sbtw a d c`.
* A `CircularPartialOrder` drops totality.
* A `CircularPreorder` further drops antisymmetry.
The intuition is that a circular order is a circle and `btw a b c` means that going around
clockwise from `a` you reach `b` before `c` (`b` is between `a` and `c` is meaningless on an
unoriented circle). A circular partial order is several, potentially intersecting, circles. A
circular preorder is like a circular partial order, but several points can coexist.
Note that the relations between `CircularPreorder`, `CircularPartialOrder` and `CircularOrder`
are subtler than between `Preorder`, `PartialOrder`, `LinearOrder`. In particular, one cannot
simply extend the `Btw` of a `CircularPartialOrder` to make it a `CircularOrder`.
One can translate from usual orders to circular ones by "closing the necklace at infinity". See
`LE.toBtw` and `LT.toSBtw`. Going the other way involves "cutting the necklace" or
"rolling the necklace open".
## Examples
Some concrete circular orders one encounters in the wild are `ZMod n` for `0 < n`, `Circle`,
`Real.Angle`...
## Main definitions
* `Set.cIcc`: Closed-closed circular interval.
* `Set.cIoo`: Open-open circular interval.
## Notes
There's an unsolved diamond on `OrderDual α` here. The instances `LE α → Btw αᵒᵈ` and
`LT α → SBtw αᵒᵈ` can each be inferred in two ways:
* `LE α` → `Btw α` → `Btw αᵒᵈ` vs
`LE α` → `LE αᵒᵈ` → `Btw αᵒᵈ`
* `LT α` → `SBtw α` → `SBtw αᵒᵈ` vs
`LT α` → `LT αᵒᵈ` → `SBtw αᵒᵈ`
The fields are propeq, but not defeq. It is temporarily fixed by turning the circularizing instances
into definitions.
## TODO
Antisymmetry is quite weak in the sense that there's no way to discriminate which two points are
equal. This prevents defining closed-open intervals `cIco` and `cIoc` in the neat `=`-less way. We
currently haven't defined them at all.
What is the correct generality of "rolling the necklace" open? At least, this works for `α × β` and
`β × α` where `α` is a circular order and `β` is a linear order.
What's next is to define circular groups and provide instances for `ZMod n`, the usual circle group
`Circle`, and `RootsOfUnity M`. What conditions do we need on `M` for this last one
to work?
We should have circular order homomorphisms. The typical example is
`days_to_month : days_of_the_year →c months_of_the_year` which relates the circular order of days
and the circular order of months. Is `α →c β` a good notation?
## References
* https://en.wikipedia.org/wiki/Cyclic_order
* https://en.wikipedia.org/wiki/Partial_cyclic_order
## Tags
circular order, cyclic order, circularly ordered set, cyclically ordered set
-/
/-- Syntax typeclass for a betweenness relation. -/
class Btw (α : Type*) where
/-- Betweenness for circular orders. `btw a b c` states that `b` is between `a` and `c` (in that
order). -/
btw : α → α → α → Prop
export Btw (btw)
/-- Syntax typeclass for a strict betweenness relation. -/
class SBtw (α : Type*) where
/-- Strict betweenness for circular orders. `sbtw a b c` states that `b` is strictly between `a`
and `c` (in that order). -/
sbtw : α → α → α → Prop
export SBtw (sbtw)
/-- A circular preorder is the analogue of a preorder where you can loop around. `≤` and `<` are
replaced by ternary relations `btw` and `sbtw`. `btw` is reflexive and cyclic. `sbtw` is transitive.
-/
class CircularPreorder (α : Type*) extends Btw α, SBtw α where
/-- `a` is between `a` and `a`. -/
btw_refl (a : α) : btw a a a
/-- If `b` is between `a` and `c`, then `c` is between `b` and `a`.
This is motivated by imagining three points on a circle. -/
btw_cyclic_left {a b c : α} : btw a b c → btw b c a
sbtw := fun a b c => btw a b c ∧ ¬btw c b a
/-- Strict betweenness is given by betweenness in one direction and non-betweenness in the other.
I.e., if `b` is between `a` and `c` but not between `c` and `a`, then we say `b` is strictly
between `a` and `c`. -/
sbtw_iff_btw_not_btw {a b c : α} : sbtw a b c ↔ btw a b c ∧ ¬btw c b a := by intros; rfl
/-- For any fixed `c`, `fun a b ↦ sbtw a b c` is a transitive relation.
I.e., given `a` `b` `d` `c` in that "order", if we have `b` strictly between `a` and `c`, and `d`
strictly between `b` and `c`, then `d` is strictly between `a` and `c`. -/
sbtw_trans_left {a b c d : α} : sbtw a b c → sbtw b d c → sbtw a d c
export CircularPreorder (btw_refl btw_cyclic_left sbtw_trans_left)
/-- A circular partial order is the analogue of a partial order where you can loop around. `≤` and
`<` are replaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic and
antisymmetric. `sbtw` is transitive. -/
class CircularPartialOrder (α : Type*) extends CircularPreorder α where
/-- If `b` is between `a` and `c` and also between `c` and `a`, then at least one pair of points
among `a`, `b`, `c` are identical. -/
btw_antisymm {a b c : α} : btw a b c → btw c b a → a = b ∨ b = c ∨ c = a
export CircularPartialOrder (btw_antisymm)
/-- A circular order is the analogue of a linear order where you can loop around. `≤` and `<` are
replaced by ternary relations `btw` and `sbtw`. `btw` is reflexive, cyclic, antisymmetric and total.
`sbtw` is transitive. -/
class CircularOrder (α : Type*) extends CircularPartialOrder α where
/-- For any triple of points, the second is between the other two one way or another. -/
btw_total : ∀ a b c : α, btw a b c ∨ btw c b a
export CircularOrder (btw_total)
/-! ### Circular preorders -/
section CircularPreorder
variable {α : Type*} [CircularPreorder α]
theorem btw_rfl {a : α} : btw a a a :=
btw_refl _
-- TODO: `alias` creates a def instead of a lemma (because `btw_cyclic_left` is a def).
-- alias btw_cyclic_left ← Btw.btw.cyclic_left
theorem Btw.btw.cyclic_left {a b c : α} (h : btw a b c) : btw b c a :=
btw_cyclic_left h
theorem btw_cyclic_right {a b c : α} (h : btw a b c) : btw c a b :=
h.cyclic_left.cyclic_left
alias Btw.btw.cyclic_right := btw_cyclic_right
/-- The order of the `↔` has been chosen so that `rw [btw_cyclic]` cycles to the right while
`rw [← btw_cyclic]` cycles to the left (thus following the prepended arrow). -/
theorem btw_cyclic {a b c : α} : btw a b c ↔ btw c a b :=
⟨btw_cyclic_right, btw_cyclic_left⟩
theorem sbtw_iff_btw_not_btw {a b c : α} : sbtw a b c ↔ btw a b c ∧ ¬btw c b a :=
CircularPreorder.sbtw_iff_btw_not_btw
theorem btw_of_sbtw {a b c : α} (h : sbtw a b c) : btw a b c :=
(sbtw_iff_btw_not_btw.1 h).1
alias SBtw.sbtw.btw := btw_of_sbtw
theorem not_btw_of_sbtw {a b c : α} (h : sbtw a b c) : ¬btw c b a :=
(sbtw_iff_btw_not_btw.1 h).2
alias SBtw.sbtw.not_btw := not_btw_of_sbtw
theorem not_sbtw_of_btw {a b c : α} (h : btw a b c) : ¬sbtw c b a := fun h' => h'.not_btw h
alias Btw.btw.not_sbtw := not_sbtw_of_btw
theorem sbtw_of_btw_not_btw {a b c : α} (habc : btw a b c) (hcba : ¬btw c b a) : sbtw a b c :=
sbtw_iff_btw_not_btw.2 ⟨habc, hcba⟩
alias Btw.btw.sbtw_of_not_btw := sbtw_of_btw_not_btw
theorem sbtw_cyclic_left {a b c : α} (h : sbtw a b c) : sbtw b c a :=
h.btw.cyclic_left.sbtw_of_not_btw fun h' => h.not_btw h'.cyclic_left
alias SBtw.sbtw.cyclic_left := sbtw_cyclic_left
theorem sbtw_cyclic_right {a b c : α} (h : sbtw a b c) : sbtw c a b :=
h.cyclic_left.cyclic_left
alias SBtw.sbtw.cyclic_right := sbtw_cyclic_right
/-- The order of the `↔` has been chosen so that `rw [sbtw_cyclic]` cycles to the right while
`rw [← sbtw_cyclic]` cycles to the left (thus following the prepended arrow). -/
theorem sbtw_cyclic {a b c : α} : sbtw a b c ↔ sbtw c a b :=
⟨sbtw_cyclic_right, sbtw_cyclic_left⟩
-- TODO: `alias` creates a def instead of a lemma (because `sbtw_trans_left` is a def).
-- alias btw_trans_left ← SBtw.sbtw.trans_left
theorem SBtw.sbtw.trans_left {a b c d : α} (h : sbtw a b c) : sbtw b d c → sbtw a d c :=
sbtw_trans_left h
theorem sbtw_trans_right {a b c d : α} (hbc : sbtw a b c) (hcd : sbtw a c d) : sbtw a b d :=
(hbc.cyclic_left.trans_left hcd.cyclic_left).cyclic_right
alias SBtw.sbtw.trans_right := sbtw_trans_right
theorem sbtw_asymm {a b c : α} (h : sbtw a b c) : ¬sbtw c b a :=
h.btw.not_sbtw
alias SBtw.sbtw.not_sbtw := sbtw_asymm
theorem sbtw_irrefl_left_right {a b : α} : ¬sbtw a b a := fun h => h.not_btw h.btw
theorem sbtw_irrefl_left {a b : α} : ¬sbtw a a b := fun h => sbtw_irrefl_left_right h.cyclic_left
theorem sbtw_irrefl_right {a b : α} : ¬sbtw a b b := fun h => sbtw_irrefl_left_right h.cyclic_right
theorem sbtw_irrefl (a : α) : ¬sbtw a a a :=
sbtw_irrefl_left_right
end CircularPreorder
/-! ### Circular partial orders -/
section CircularPartialOrder
variable {α : Type*} [CircularPartialOrder α]
-- TODO: `alias` creates a def instead of a lemma (because `btw_antisymm` is a def).
-- alias btw_antisymm ← Btw.btw.antisymm
theorem Btw.btw.antisymm {a b c : α} (h : btw a b c) : btw c b a → a = b ∨ b = c ∨ c = a :=
btw_antisymm h
end CircularPartialOrder
/-! ### Circular orders -/
section CircularOrder
variable {α : Type*} [CircularOrder α]
theorem btw_refl_left_right (a b : α) : btw a b a :=
or_self_iff.1 (btw_total a b a)
theorem btw_rfl_left_right {a b : α} : btw a b a :=
btw_refl_left_right _ _
theorem btw_refl_left (a b : α) : btw a a b :=
btw_rfl_left_right.cyclic_right
theorem btw_rfl_left {a b : α} : btw a a b :=
btw_refl_left _ _
theorem btw_refl_right (a b : α) : btw a b b :=
btw_rfl_left_right.cyclic_left
theorem btw_rfl_right {a b : α} : btw a b b :=
btw_refl_right _ _
theorem sbtw_iff_not_btw {a b c : α} : sbtw a b c ↔ ¬btw c b a := by
rw [sbtw_iff_btw_not_btw]
exact and_iff_right_of_imp (btw_total _ _ _).resolve_left
theorem btw_iff_not_sbtw {a b c : α} : btw a b c ↔ ¬sbtw c b a :=
iff_not_comm.1 sbtw_iff_not_btw
end CircularOrder
/-! ### Circular intervals -/
namespace Set
section CircularPreorder
variable {α : Type*} [CircularPreorder α]
/-- Closed-closed circular interval -/
def cIcc (a b : α) : Set α :=
{ x | btw a x b }
/-- Open-open circular interval -/
def cIoo (a b : α) : Set α :=
{ x | sbtw a x b }
@[simp]
theorem mem_cIcc {a b x : α} : x ∈ cIcc a b ↔ btw a x b :=
Iff.rfl
@[simp]
theorem mem_cIoo {a b x : α} : x ∈ cIoo a b ↔ sbtw a x b :=
Iff.rfl
end CircularPreorder
section CircularOrder
variable {α : Type*} [CircularOrder α]
theorem left_mem_cIcc (a b : α) : a ∈ cIcc a b :=
btw_rfl_left
theorem right_mem_cIcc (a b : α) : b ∈ cIcc a b :=
btw_rfl_right
theorem compl_cIcc {a b : α} : (cIcc a b)ᶜ = cIoo b a := by
ext
rw [Set.mem_cIoo, sbtw_iff_not_btw, cIcc, mem_compl_iff, mem_setOf]
theorem compl_cIoo {a b : α} : (cIoo a b)ᶜ = cIcc b a := by
ext
rw [Set.mem_cIcc, btw_iff_not_sbtw, cIoo, mem_compl_iff, mem_setOf]
end CircularOrder
end Set
/-! ### Circularizing instances -/
/-- The betweenness relation obtained from "looping around" `≤`.
See note [reducible non-instances]. -/
abbrev LE.toBtw (α : Type*) [LE α] : Btw α where
btw a b c := a ≤ b ∧ b ≤ c ∨ b ≤ c ∧ c ≤ a ∨ c ≤ a ∧ a ≤ b
/-- The strict betweenness relation obtained from "looping around" `<`.
See note [reducible non-instances]. -/
abbrev LT.toSBtw (α : Type*) [LT α] : SBtw α where
sbtw a b c := a < b ∧ b < c ∨ b < c ∧ c < a ∨ c < a ∧ a < b
/-- The circular preorder obtained from "looping around" a preorder.
See note [reducible non-instances]. -/
abbrev Preorder.toCircularPreorder (α : Type*) [Preorder α] : CircularPreorder α where
btw a b c := a ≤ b ∧ b ≤ c ∨ b ≤ c ∧ c ≤ a ∨ c ≤ a ∧ a ≤ b
sbtw a b c := a < b ∧ b < c ∨ b < c ∧ c < a ∨ c < a ∧ a < b
btw_refl a := Or.inl ⟨le_rfl, le_rfl⟩
btw_cyclic_left {a b c} h := by
dsimp
rwa [← or_assoc, or_comm]
sbtw_trans_left {a b c d} := by
rintro (⟨hab, hbc⟩ | ⟨hbc, hca⟩ | ⟨hca, hab⟩) (⟨hbd, hdc⟩ | ⟨hdc, hcb⟩ | ⟨hcb, hbd⟩)
· exact Or.inl ⟨hab.trans hbd, hdc⟩
· exact (hbc.not_lt hcb).elim
· exact (hbc.not_lt hcb).elim
· exact Or.inr (Or.inl ⟨hdc, hca⟩)
· exact Or.inr (Or.inl ⟨hdc, hca⟩)
· exact (hbc.not_lt hcb).elim
· exact Or.inr (Or.inl ⟨hdc, hca⟩)
· exact Or.inr (Or.inl ⟨hdc, hca⟩)
· exact Or.inr (Or.inr ⟨hca, hab.trans hbd⟩)
sbtw_iff_btw_not_btw {a b c} := by
simp_rw [lt_iff_le_not_le]
have h1 := le_trans a b c
have h2 := le_trans b c a
have h3 := le_trans c a b
-- Porting note: was `tauto`, but this is a much faster tactic proof
revert h1 h2 h3
generalize (a ≤ b) = p1
generalize (b ≤ a) = p2
generalize (a ≤ c) = p3
generalize (c ≤ a) = p4
generalize (b ≤ c) = p5
by_cases p1 <;> by_cases p2 <;> by_cases p3 <;> by_cases p4 <;> by_cases p5 <;> simp [*]
/-- The circular partial order obtained from "looping around" a partial order.
See note [reducible non-instances]. -/
abbrev PartialOrder.toCircularPartialOrder (α : Type*) [PartialOrder α] : CircularPartialOrder α :=
{ Preorder.toCircularPreorder α with
btw_antisymm := fun {a b c} => by
rintro (⟨hab, hbc⟩ | ⟨hbc, hca⟩ | ⟨hca, hab⟩) (⟨hcb, hba⟩ | ⟨hba, hac⟩ | ⟨hac, hcb⟩)
· exact Or.inl (hab.antisymm hba)
· exact Or.inl (hab.antisymm hba)
· exact Or.inr (Or.inl <| hbc.antisymm hcb)
· exact Or.inr (Or.inl <| hbc.antisymm hcb)
· exact Or.inr (Or.inr <| hca.antisymm hac)
· exact Or.inr (Or.inl <| hbc.antisymm hcb)
· exact Or.inl (hab.antisymm hba)
· exact Or.inl (hab.antisymm hba)
· exact Or.inr (Or.inr <| hca.antisymm hac) }
/-- The circular order obtained from "looping around" a linear order.
See note [reducible non-instances]. -/
abbrev LinearOrder.toCircularOrder (α : Type*) [LinearOrder α] : CircularOrder α :=
{ PartialOrder.toCircularPartialOrder α with
btw_total := fun a b c => by
rcases le_total a b with hab | hba <;> rcases le_total b c with hbc | hcb <;>
rcases le_total c a with hca | hac
· exact Or.inl (Or.inl ⟨hab, hbc⟩)
· exact Or.inl (Or.inl ⟨hab, hbc⟩)
· exact Or.inl (Or.inr <| Or.inr ⟨hca, hab⟩)
· exact Or.inr (Or.inr <| Or.inr ⟨hac, hcb⟩)
· exact Or.inl (Or.inr <| Or.inl ⟨hbc, hca⟩)
· exact Or.inr (Or.inr <| Or.inl ⟨hba, hac⟩)
· exact Or.inr (Or.inl ⟨hcb, hba⟩)
· exact Or.inr (Or.inr <| Or.inl ⟨hba, hac⟩) }
/-! ### Dual constructions -/
namespace OrderDual
instance btw (α : Type*) [Btw α] : Btw αᵒᵈ :=
⟨fun a b c : α => Btw.btw c b a⟩
instance sbtw (α : Type*) [SBtw α] : SBtw αᵒᵈ :=
⟨fun a b c : α => SBtw.sbtw c b a⟩
instance circularPreorder (α : Type*) [CircularPreorder α] : CircularPreorder αᵒᵈ :=
{ OrderDual.btw α,
OrderDual.sbtw α with
btw_refl := fun _ => @btw_refl α _ _
btw_cyclic_left := fun {_ _ _} => @btw_cyclic_right α _ _ _ _
sbtw_trans_left := fun {_ _ _ _} habc hbdc => hbdc.trans_right habc
sbtw_iff_btw_not_btw := fun {a b c} => @sbtw_iff_btw_not_btw α _ c b a }
instance circularPartialOrder (α : Type*) [CircularPartialOrder α] : CircularPartialOrder αᵒᵈ :=
{ OrderDual.circularPreorder α with
btw_antisymm := fun {_ _ _} habc hcba => @btw_antisymm α _ _ _ _ hcba habc }
instance (α : Type*) [CircularOrder α] : CircularOrder αᵒᵈ :=
{ OrderDual.circularPartialOrder α with
btw_total := fun {a b c} => @btw_total α _ c b a }
end OrderDual
|
Order\Closure.lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Yaël Dillies
-/
import Mathlib.Data.Set.Lattice
import Mathlib.Data.SetLike.Basic
import Mathlib.Order.GaloisConnection
import Mathlib.Order.Hom.Basic
/-!
# Closure operators between preorders
We define (bundled) closure operators on a preorder as monotone (increasing), extensive
(inflationary) and idempotent functions.
We define closed elements for the operator as elements which are fixed by it.
Lower adjoints to a function between preorders `u : β → α` allow to generalise closure operators to
situations where the closure operator we are dealing with naturally decomposes as `u ∘ l` where `l`
is a worthy function to have on its own. Typical examples include
`l : Set G → Subgroup G := Subgroup.closure`, `u : Subgroup G → Set G := (↑)`, where `G` is a group.
This shows there is a close connection between closure operators, lower adjoints and Galois
connections/insertions: every Galois connection induces a lower adjoint which itself induces a
closure operator by composition (see `GaloisConnection.lowerAdjoint` and
`LowerAdjoint.closureOperator`), and every closure operator on a partial order induces a Galois
insertion from the set of closed elements to the underlying type (see `ClosureOperator.gi`).
## Main definitions
* `ClosureOperator`: A closure operator is a monotone function `f : α → α` such that
`∀ x, x ≤ f x` and `∀ x, f (f x) = f x`.
* `LowerAdjoint`: A lower adjoint to `u : β → α` is a function `l : α → β` such that `l` and `u`
form a Galois connection.
## Implementation details
Although `LowerAdjoint` is technically a generalisation of `ClosureOperator` (by defining
`toFun := id`), it is desirable to have both as otherwise `id`s would be carried all over the
place when using concrete closure operators such as `ConvexHull`.
`LowerAdjoint` really is a semibundled `structure` version of `GaloisConnection`.
## References
* https://en.wikipedia.org/wiki/Closure_operator#Closure_operators_on_partially_ordered_sets
-/
open Set
/-! ### Closure operator -/
variable (α : Type*) {ι : Sort*} {κ : ι → Sort*}
/-- A closure operator on the preorder `α` is a monotone function which is extensive (every `x`
is less than its closure) and idempotent. -/
structure ClosureOperator [Preorder α] extends α →o α where
/-- An element is less than or equal its closure -/
le_closure' : ∀ x, x ≤ toFun x
/-- Closures are idempotent -/
idempotent' : ∀ x, toFun (toFun x) = toFun x
/-- Predicate for an element to be closed.
By default, this is defined as `c.IsClosed x := (c x = x)` (see `isClosed_iff`).
We allow an override to fix definitional equalities. -/
IsClosed (x : α) : Prop := toFun x = x
isClosed_iff {x : α} : IsClosed x ↔ toFun x = x := by aesop
namespace ClosureOperator
instance [Preorder α] : FunLike (ClosureOperator α) α α where
coe c := c.1
coe_injective' := by rintro ⟨⟩ ⟨⟩ h; obtain rfl := DFunLike.ext' h; congr with x; simp_all
instance [Preorder α] : OrderHomClass (ClosureOperator α) α α where
map_rel f _ _ h := f.mono h
initialize_simps_projections ClosureOperator (toFun → apply, IsClosed → isClosed)
/-- If `c` is a closure operator on `α` and `e` an order-isomorphism
between `α` and `β` then `e ∘ c ∘ e⁻¹` is a closure operator on `β`. -/
@[simps apply]
def conjBy {α β} [Preorder α] [Preorder β] (c : ClosureOperator α)
(e : α ≃o β) : ClosureOperator β where
toFun := e.conj c
IsClosed b := c.IsClosed (e.symm b)
monotone' _ _ h :=
(map_le_map_iff e).mpr <| c.monotone <| (map_le_map_iff e.symm).mpr h
le_closure' _ := e.symm_apply_le.mp (c.le_closure' _)
idempotent' _ :=
congrArg e <| Eq.trans (congrArg c (e.symm_apply_apply _)) (c.idempotent' _)
isClosed_iff := Iff.trans c.isClosed_iff e.eq_symm_apply
lemma conjBy_refl {α} [Preorder α] (c : ClosureOperator α) :
c.conjBy (OrderIso.refl α) = c := rfl
lemma conjBy_trans {α β γ} [Preorder α] [Preorder β] [Preorder γ]
(e₁ : α ≃o β) (e₂ : β ≃o γ) (c : ClosureOperator α) :
c.conjBy (e₁.trans e₂) = (c.conjBy e₁).conjBy e₂ := rfl
section PartialOrder
variable [PartialOrder α]
/-- The identity function as a closure operator. -/
@[simps!]
def id : ClosureOperator α where
toOrderHom := OrderHom.id
le_closure' _ := le_rfl
idempotent' _ := rfl
IsClosed _ := True
instance : Inhabited (ClosureOperator α) :=
⟨id α⟩
variable {α}
variable (c : ClosureOperator α)
@[ext]
theorem ext : ∀ c₁ c₂ : ClosureOperator α, (∀ x, c₁ x = c₂ x) → c₁ = c₂ :=
DFunLike.ext
/-- Constructor for a closure operator using the weaker idempotency axiom: `f (f x) ≤ f x`. -/
@[simps]
def mk' (f : α → α) (hf₁ : Monotone f) (hf₂ : ∀ x, x ≤ f x) (hf₃ : ∀ x, f (f x) ≤ f x) :
ClosureOperator α where
toFun := f
monotone' := hf₁
le_closure' := hf₂
idempotent' x := (hf₃ x).antisymm (hf₁ (hf₂ x))
/-- Convenience constructor for a closure operator using the weaker minimality axiom:
`x ≤ f y → f x ≤ f y`, which is sometimes easier to prove in practice. -/
@[simps]
def mk₂ (f : α → α) (hf : ∀ x, x ≤ f x) (hmin : ∀ ⦃x y⦄, x ≤ f y → f x ≤ f y) :
ClosureOperator α where
toFun := f
monotone' _ y hxy := hmin (hxy.trans (hf y))
le_closure' := hf
idempotent' _ := (hmin le_rfl).antisymm (hf _)
/-- Construct a closure operator from an inflationary function `f` and a "closedness" predicate `p`
witnessing minimality of `f x` among closed elements greater than `x`. -/
@[simps!]
def ofPred (f : α → α) (p : α → Prop) (hf : ∀ x, x ≤ f x) (hfp : ∀ x, p (f x))
(hmin : ∀ ⦃x y⦄, x ≤ y → p y → f x ≤ y) : ClosureOperator α where
__ := mk₂ f hf fun _ y hxy => hmin hxy (hfp y)
IsClosed := p
isClosed_iff := ⟨fun hx ↦ (hmin le_rfl hx).antisymm <| hf _, fun hx ↦ hx ▸ hfp _⟩
@[mono]
theorem monotone : Monotone c :=
c.monotone'
/-- Every element is less than its closure. This property is sometimes referred to as extensivity or
inflationarity. -/
theorem le_closure (x : α) : x ≤ c x :=
c.le_closure' x
@[simp]
theorem idempotent (x : α) : c (c x) = c x :=
c.idempotent' x
@[simp] lemma isClosed_closure (x : α) : c.IsClosed (c x) := c.isClosed_iff.2 <| c.idempotent x
/-- The type of elements closed under a closure operator. -/
abbrev Closeds := {x // c.IsClosed x}
/-- Send an element to a closed element (by taking the closure). -/
def toCloseds (x : α) : c.Closeds := ⟨c x, c.isClosed_closure x⟩
variable {c} {x y : α}
theorem IsClosed.closure_eq : c.IsClosed x → c x = x := c.isClosed_iff.1
theorem isClosed_iff_closure_le : c.IsClosed x ↔ c x ≤ x :=
⟨fun h ↦ h.closure_eq.le, fun h ↦ c.isClosed_iff.2 <| h.antisymm <| c.le_closure x⟩
/-- The set of closed elements for `c` is exactly its range. -/
theorem setOf_isClosed_eq_range_closure : {x | c.IsClosed x} = Set.range c := by
ext x; exact ⟨fun hx ↦ ⟨x, hx.closure_eq⟩, by rintro ⟨y, rfl⟩; exact c.isClosed_closure _⟩
theorem le_closure_iff : x ≤ c y ↔ c x ≤ c y :=
⟨fun h ↦ c.idempotent y ▸ c.monotone h, (c.le_closure x).trans⟩
@[simp]
theorem IsClosed.closure_le_iff (hy : c.IsClosed y) : c x ≤ y ↔ x ≤ y := by
rw [← hy.closure_eq, ← le_closure_iff]
lemma closure_min (hxy : x ≤ y) (hy : c.IsClosed y) : c x ≤ y := hy.closure_le_iff.2 hxy
lemma closure_isGLB (x : α) : IsGLB { y | x ≤ y ∧ c.IsClosed y } (c x) where
left _ := and_imp.mpr closure_min
right _ h := h ⟨c.le_closure x, c.isClosed_closure x⟩
theorem ext_isClosed (c₁ c₂ : ClosureOperator α)
(h : ∀ x, c₁.IsClosed x ↔ c₂.IsClosed x) : c₁ = c₂ :=
ext c₁ c₂ <| fun x => IsGLB.unique (c₁.closure_isGLB x) <|
(Set.ext (and_congr_right' <| h ·)).substr (c₂.closure_isGLB x)
/-- A closure operator is equal to the closure operator obtained by feeding `c.closed` into the
`ofPred` constructor. -/
theorem eq_ofPred_closed (c : ClosureOperator α) :
c = ofPred c c.IsClosed c.le_closure c.isClosed_closure fun x y ↦ closure_min := by
ext
rfl
end PartialOrder
variable {α}
section OrderTop
variable [PartialOrder α] [OrderTop α] (c : ClosureOperator α)
@[simp]
theorem closure_top : c ⊤ = ⊤ :=
le_top.antisymm (c.le_closure _)
@[simp] lemma isClosed_top : c.IsClosed ⊤ := c.isClosed_iff.2 c.closure_top
end OrderTop
theorem closure_inf_le [SemilatticeInf α] (c : ClosureOperator α) (x y : α) :
c (x ⊓ y) ≤ c x ⊓ c y :=
c.monotone.map_inf_le _ _
section SemilatticeSup
variable [SemilatticeSup α] (c : ClosureOperator α)
theorem closure_sup_closure_le (x y : α) : c x ⊔ c y ≤ c (x ⊔ y) :=
c.monotone.le_map_sup _ _
theorem closure_sup_closure_left (x y : α) : c (c x ⊔ y) = c (x ⊔ y) :=
(le_closure_iff.1
(sup_le (c.monotone le_sup_left) (le_sup_right.trans (c.le_closure _)))).antisymm
(c.monotone (sup_le_sup_right (c.le_closure _) _))
theorem closure_sup_closure_right (x y : α) : c (x ⊔ c y) = c (x ⊔ y) := by
rw [sup_comm, closure_sup_closure_left, sup_comm (a := x)]
theorem closure_sup_closure (x y : α) : c (c x ⊔ c y) = c (x ⊔ y) := by
rw [closure_sup_closure_left, closure_sup_closure_right]
end SemilatticeSup
section CompleteLattice
variable [CompleteLattice α] (c : ClosureOperator α) {p : α → Prop}
/-- Define a closure operator from a predicate that's preserved under infima. -/
@[simps!]
def ofCompletePred (p : α → Prop) (hsinf : ∀ s, (∀ a ∈ s, p a) → p (sInf s)) : ClosureOperator α :=
ofPred (fun a ↦ ⨅ b : {b // a ≤ b ∧ p b}, b) p
(fun a ↦ by set_option tactic.skipAssignedInstances false in simp [forall_swap])
(fun a ↦ hsinf _ <| forall_mem_range.2 fun b ↦ b.2.2)
(fun a b hab hb ↦ iInf_le_of_le ⟨b, hab, hb⟩ le_rfl)
theorem sInf_isClosed {c : ClosureOperator α} {S : Set α}
(H : ∀ x ∈ S, c.IsClosed x) : c.IsClosed (sInf S) :=
isClosed_iff_closure_le.mpr <| le_of_le_of_eq c.monotone.map_sInf_le <|
Eq.trans (biInf_congr (c.isClosed_iff.mp <| H · ·)) sInf_eq_iInf.symm
@[simp]
theorem closure_iSup_closure (f : ι → α) : c (⨆ i, c (f i)) = c (⨆ i, f i) :=
le_antisymm (le_closure_iff.1 <| iSup_le fun i => c.monotone <| le_iSup f i) <|
c.monotone <| iSup_mono fun _ => c.le_closure _
@[simp]
theorem closure_iSup₂_closure (f : ∀ i, κ i → α) :
c (⨆ (i) (j), c (f i j)) = c (⨆ (i) (j), f i j) :=
le_antisymm (le_closure_iff.1 <| iSup₂_le fun i j => c.monotone <| le_iSup₂ i j) <|
c.monotone <| iSup₂_mono fun _ _ => c.le_closure _
end CompleteLattice
end ClosureOperator
/-- Conjugating `ClosureOperators` on `α` and on `β` by a fixed isomorphism
`e : α ≃o β` gives an equivalence `ClosureOperator α ≃ ClosureOperator β`. -/
@[simps apply symm_apply]
def OrderIso.equivClosureOperator {α β} [Preorder α] [Preorder β] (e : α ≃o β) :
ClosureOperator α ≃ ClosureOperator β where
toFun c := c.conjBy e
invFun c := c.conjBy e.symm
left_inv c := Eq.trans (c.conjBy_trans _ _).symm
<| Eq.trans (congrArg _ e.self_trans_symm) c.conjBy_refl
right_inv c := Eq.trans (c.conjBy_trans _ _).symm
<| Eq.trans (congrArg _ e.symm_trans_self) c.conjBy_refl
/-! ### Lower adjoint -/
variable {α} {β : Type*}
/-- A lower adjoint of `u` on the preorder `α` is a function `l` such that `l` and `u` form a Galois
connection. It allows us to define closure operators whose output does not match the input. In
practice, `u` is often `(↑) : β → α`. -/
structure LowerAdjoint [Preorder α] [Preorder β] (u : β → α) where
/-- The underlying function -/
toFun : α → β
/-- The underlying function is a lower adjoint. -/
gc' : GaloisConnection toFun u
namespace LowerAdjoint
variable (α)
/-- The identity function as a lower adjoint to itself. -/
@[simps]
protected def id [Preorder α] : LowerAdjoint (id : α → α) where
toFun x := x
gc' := GaloisConnection.id
variable {α}
instance [Preorder α] : Inhabited (LowerAdjoint (id : α → α)) :=
⟨LowerAdjoint.id α⟩
section Preorder
variable [Preorder α] [Preorder β] {u : β → α} (l : LowerAdjoint u)
instance : CoeFun (LowerAdjoint u) fun _ => α → β where coe := toFun
theorem gc : GaloisConnection l u :=
l.gc'
@[ext]
theorem ext : ∀ l₁ l₂ : LowerAdjoint u, (l₁ : α → β) = (l₂ : α → β) → l₁ = l₂
| ⟨l₁, _⟩, ⟨l₂, _⟩, h => by
congr
@[mono]
theorem monotone : Monotone (u ∘ l) :=
l.gc.monotone_u.comp l.gc.monotone_l
/-- Every element is less than its closure. This property is sometimes referred to as extensivity or
inflationarity. -/
theorem le_closure (x : α) : x ≤ u (l x) :=
l.gc.le_u_l _
end Preorder
section PartialOrder
variable [PartialOrder α] [Preorder β] {u : β → α} (l : LowerAdjoint u)
/-- Every lower adjoint induces a closure operator given by the composition. This is the partial
order version of the statement that every adjunction induces a monad. -/
@[simps]
def closureOperator : ClosureOperator α where
toFun x := u (l x)
monotone' := l.monotone
le_closure' := l.le_closure
idempotent' x := l.gc.u_l_u_eq_u (l x)
theorem idempotent (x : α) : u (l (u (l x))) = u (l x) :=
l.closureOperator.idempotent _
theorem le_closure_iff (x y : α) : x ≤ u (l y) ↔ u (l x) ≤ u (l y) :=
l.closureOperator.le_closure_iff
end PartialOrder
section Preorder
variable [Preorder α] [Preorder β] {u : β → α} (l : LowerAdjoint u)
/-- An element `x` is closed for `l : LowerAdjoint u` if it is a fixed point: `u (l x) = x` -/
def closed : Set α := {x | u (l x) = x}
theorem mem_closed_iff (x : α) : x ∈ l.closed ↔ u (l x) = x :=
Iff.rfl
theorem closure_eq_self_of_mem_closed {x : α} (h : x ∈ l.closed) : u (l x) = x :=
h
end Preorder
section PartialOrder
variable [PartialOrder α] [PartialOrder β] {u : β → α} (l : LowerAdjoint u)
theorem mem_closed_iff_closure_le (x : α) : x ∈ l.closed ↔ u (l x) ≤ x :=
l.closureOperator.isClosed_iff_closure_le
@[simp, nolint simpNF] -- Porting note: lemma does prove itself, seems to be a linter error
theorem closure_is_closed (x : α) : u (l x) ∈ l.closed :=
l.idempotent x
/-- The set of closed elements for `l` is the range of `u ∘ l`. -/
theorem closed_eq_range_close : l.closed = Set.range (u ∘ l) :=
l.closureOperator.setOf_isClosed_eq_range_closure
/-- Send an `x` to an element of the set of closed elements (by taking the closure). -/
def toClosed (x : α) : l.closed :=
⟨u (l x), l.closure_is_closed x⟩
@[simp]
theorem closure_le_closed_iff_le (x : α) {y : α} (hy : l.closed y) : u (l x) ≤ y ↔ x ≤ y :=
(show l.closureOperator.IsClosed y from hy).closure_le_iff
end PartialOrder
theorem closure_top [PartialOrder α] [OrderTop α] [Preorder β] {u : β → α} (l : LowerAdjoint u) :
u (l ⊤) = ⊤ :=
l.closureOperator.closure_top
theorem closure_inf_le [SemilatticeInf α] [Preorder β] {u : β → α} (l : LowerAdjoint u) (x y : α) :
u (l (x ⊓ y)) ≤ u (l x) ⊓ u (l y) :=
l.closureOperator.closure_inf_le x y
section SemilatticeSup
variable [SemilatticeSup α] [Preorder β] {u : β → α} (l : LowerAdjoint u)
theorem closure_sup_closure_le (x y : α) : u (l x) ⊔ u (l y) ≤ u (l (x ⊔ y)) :=
l.closureOperator.closure_sup_closure_le x y
theorem closure_sup_closure_left (x y : α) : u (l (u (l x) ⊔ y)) = u (l (x ⊔ y)) :=
l.closureOperator.closure_sup_closure_left x y
theorem closure_sup_closure_right (x y : α) : u (l (x ⊔ u (l y))) = u (l (x ⊔ y)) :=
l.closureOperator.closure_sup_closure_right x y
theorem closure_sup_closure (x y : α) : u (l (u (l x) ⊔ u (l y))) = u (l (x ⊔ y)) :=
l.closureOperator.closure_sup_closure x y
end SemilatticeSup
section CompleteLattice
variable [CompleteLattice α] [Preorder β] {u : β → α} (l : LowerAdjoint u)
theorem closure_iSup_closure (f : ι → α) : u (l (⨆ i, u (l (f i)))) = u (l (⨆ i, f i)) :=
l.closureOperator.closure_iSup_closure _
theorem closure_iSup₂_closure (f : ∀ i, κ i → α) :
u (l <| ⨆ (i) (j), u (l <| f i j)) = u (l <| ⨆ (i) (j), f i j) :=
l.closureOperator.closure_iSup₂_closure _
end CompleteLattice
-- Lemmas for `LowerAdjoint ((↑) : α → Set β)`, where `SetLike α β`
section CoeToSet
variable [SetLike α β] (l : LowerAdjoint ((↑) : α → Set β))
theorem subset_closure (s : Set β) : s ⊆ l s :=
l.le_closure s
theorem not_mem_of_not_mem_closure {s : Set β} {P : β} (hP : P ∉ l s) : P ∉ s := fun h =>
hP (subset_closure _ s h)
theorem le_iff_subset (s : Set β) (S : α) : l s ≤ S ↔ s ⊆ S :=
l.gc s S
theorem mem_iff (s : Set β) (x : β) : x ∈ l s ↔ ∀ S : α, s ⊆ S → x ∈ S := by
simp_rw [← SetLike.mem_coe, ← Set.singleton_subset_iff, ← l.le_iff_subset]
exact ⟨fun h S => h.trans, fun h => h _ le_rfl⟩
theorem eq_of_le {s : Set β} {S : α} (h₁ : s ⊆ S) (h₂ : S ≤ l s) : l s = S :=
((l.le_iff_subset _ _).2 h₁).antisymm h₂
theorem closure_union_closure_subset (x y : α) : (l x : Set β) ∪ l y ⊆ l (x ∪ y) :=
l.closure_sup_closure_le x y
@[simp]
theorem closure_union_closure_left (x y : α) : l (l x ∪ y) = l (x ∪ y) :=
SetLike.coe_injective (l.closure_sup_closure_left x y)
@[simp]
theorem closure_union_closure_right (x y : α) : l (x ∪ l y) = l (x ∪ y) :=
SetLike.coe_injective (l.closure_sup_closure_right x y)
theorem closure_union_closure (x y : α) : l (l x ∪ l y) = l (x ∪ y) := by
rw [closure_union_closure_right, closure_union_closure_left]
@[simp]
theorem closure_iUnion_closure (f : ι → α) : l (⋃ i, l (f i)) = l (⋃ i, f i) :=
SetLike.coe_injective <| l.closure_iSup_closure _
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
@[simp]
theorem closure_iUnion₂_closure (f : ∀ i, κ i → α) :
l (⋃ (i) (j), l (f i j)) = l (⋃ (i) (j), f i j) :=
SetLike.coe_injective <| l.closure_iSup₂_closure _
end CoeToSet
end LowerAdjoint
/-! ### Translations between `GaloisConnection`, `LowerAdjoint`, `ClosureOperator` -/
/-- Every Galois connection induces a lower adjoint. -/
@[simps]
def GaloisConnection.lowerAdjoint [Preorder α] [Preorder β] {l : α → β} {u : β → α}
(gc : GaloisConnection l u) : LowerAdjoint u where
toFun := l
gc' := gc
/-- Every Galois connection induces a closure operator given by the composition. This is the partial
order version of the statement that every adjunction induces a monad. -/
@[simps!]
def GaloisConnection.closureOperator [PartialOrder α] [Preorder β] {l : α → β} {u : β → α}
(gc : GaloisConnection l u) : ClosureOperator α :=
gc.lowerAdjoint.closureOperator
/-- The set of closed elements has a Galois insertion to the underlying type. -/
def ClosureOperator.gi [PartialOrder α] (c : ClosureOperator α) :
GaloisInsertion c.toCloseds (↑) where
choice x hx := ⟨x, isClosed_iff_closure_le.2 hx⟩
gc _ y := y.2.closure_le_iff
le_l_u _ := c.le_closure _
choice_eq x hx := le_antisymm (c.le_closure x) hx
/-- The Galois insertion associated to a closure operator can be used to reconstruct the closure
operator.
Note that the inverse in the opposite direction does not hold in general. -/
@[simp]
theorem closureOperator_gi_self [PartialOrder α] (c : ClosureOperator α) :
c.gi.gc.closureOperator = c := by
ext x
rfl
|
Order\Compare.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Ordering.Basic
import Mathlib.Order.Synonym
/-!
# Comparison
This file provides basic results about orderings and comparison in linear orders.
## Definitions
* `CmpLE`: An `Ordering` from `≤`.
* `Ordering.Compares`: Turns an `Ordering` into `<` and `=` propositions.
* `linearOrderOfCompares`: Constructs a `LinearOrder` instance from the fact that any two
elements that are not one strictly less than the other either way are equal.
-/
variable {α β : Type*}
/-- Like `cmp`, but uses a `≤` on the type instead of `<`. Given two elements `x` and `y`, returns a
three-way comparison result `Ordering`. -/
def cmpLE {α} [LE α] [@DecidableRel α (· ≤ ·)] (x y : α) : Ordering :=
if x ≤ y then if y ≤ x then Ordering.eq else Ordering.lt else Ordering.gt
theorem cmpLE_swap {α} [LE α] [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] (x y : α) :
(cmpLE x y).swap = cmpLE y x := by
by_cases xy : x ≤ y <;> by_cases yx : y ≤ x <;> simp [cmpLE, *, Ordering.swap]
cases not_or_of_not xy yx (total_of _ _ _)
theorem cmpLE_eq_cmp {α} [Preorder α] [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)]
[@DecidableRel α (· < ·)] (x y : α) : cmpLE x y = cmp x y := by
by_cases xy : x ≤ y <;> by_cases yx : y ≤ x <;> simp [cmpLE, lt_iff_le_not_le, *, cmp, cmpUsing]
cases not_or_of_not xy yx (total_of _ _ _)
namespace Ordering
/-- `Compares o a b` means that `a` and `b` have the ordering relation `o` between them, assuming
that the relation `a < b` is defined. -/
-- Porting note: we have removed `@[simp]` here in favour of separate simp lemmas,
-- otherwise this definition will unfold to a match.
def Compares [LT α] : Ordering → α → α → Prop
| lt, a, b => a < b
| eq, a, b => a = b
| gt, a, b => a > b
@[simp]
lemma compares_lt [LT α] (a b : α) : Compares lt a b = (a < b) := rfl
@[simp]
lemma compares_eq [LT α] (a b : α) : Compares eq a b = (a = b) := rfl
@[simp]
lemma compares_gt [LT α] (a b : α) : Compares gt a b = (a > b) := rfl
theorem compares_swap [LT α] {a b : α} {o : Ordering} : o.swap.Compares a b ↔ o.Compares b a := by
cases o
· exact Iff.rfl
· exact eq_comm
· exact Iff.rfl
alias ⟨Compares.of_swap, Compares.swap⟩ := compares_swap
theorem swap_eq_iff_eq_swap {o o' : Ordering} : o.swap = o' ↔ o = o'.swap := by
rw [← swap_inj, swap_swap]
theorem Compares.eq_lt [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o = lt ↔ a < b)
| lt, a, b, h => ⟨fun _ => h, fun _ => rfl⟩
| eq, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_lt h' h).elim⟩
| gt, a, b, h => ⟨fun h => by injection h, fun h' => (lt_asymm h h').elim⟩
theorem Compares.ne_lt [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o ≠ lt ↔ b ≤ a)
| lt, a, b, h => ⟨absurd rfl, fun h' => (not_le_of_lt h h').elim⟩
| eq, a, b, h => ⟨fun _ => ge_of_eq h, fun _ h => by injection h⟩
| gt, a, b, h => ⟨fun _ => le_of_lt h, fun _ h => by injection h⟩
theorem Compares.eq_eq [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o = eq ↔ a = b)
| lt, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_lt h h').elim⟩
| eq, a, b, h => ⟨fun _ => h, fun _ => rfl⟩
| gt, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_gt h h').elim⟩
theorem Compares.eq_gt [Preorder α] {o} {a b : α} (h : Compares o a b) : o = gt ↔ b < a :=
swap_eq_iff_eq_swap.symm.trans h.swap.eq_lt
theorem Compares.ne_gt [Preorder α] {o} {a b : α} (h : Compares o a b) : o ≠ gt ↔ a ≤ b :=
(not_congr swap_eq_iff_eq_swap.symm).trans h.swap.ne_lt
theorem Compares.le_total [Preorder α] {a b : α} : ∀ {o}, Compares o a b → a ≤ b ∨ b ≤ a
| lt, h => Or.inl (le_of_lt h)
| eq, h => Or.inl (le_of_eq h)
| gt, h => Or.inr (le_of_lt h)
theorem Compares.le_antisymm [Preorder α] {a b : α} : ∀ {o}, Compares o a b → a ≤ b → b ≤ a → a = b
| lt, h, _, hba => (not_le_of_lt h hba).elim
| eq, h, _, _ => h
| gt, h, hab, _ => (not_le_of_lt h hab).elim
theorem Compares.inj [Preorder α] {o₁} :
∀ {o₂} {a b : α}, Compares o₁ a b → Compares o₂ a b → o₁ = o₂
| lt, _, _, h₁, h₂ => h₁.eq_lt.2 h₂
| eq, _, _, h₁, h₂ => h₁.eq_eq.2 h₂
| gt, _, _, h₁, h₂ => h₁.eq_gt.2 h₂
-- Porting note: mathlib3 proof uses `change ... at hab`
theorem compares_iff_of_compares_impl [LinearOrder α] [Preorder β] {a b : α} {a' b' : β}
(h : ∀ {o}, Compares o a b → Compares o a' b') (o) : Compares o a b ↔ Compares o a' b' := by
refine ⟨h, fun ho => ?_⟩
cases' lt_trichotomy a b with hab hab
· have hab : Compares Ordering.lt a b := hab
rwa [ho.inj (h hab)]
· cases' hab with hab hab
· have hab : Compares Ordering.eq a b := hab
rwa [ho.inj (h hab)]
· have hab : Compares Ordering.gt a b := hab
rwa [ho.inj (h hab)]
theorem swap_orElse (o₁ o₂) : (orElse o₁ o₂).swap = orElse o₁.swap o₂.swap := by
cases o₁ <;> rfl
theorem orElse_eq_lt (o₁ o₂) : orElse o₁ o₂ = lt ↔ o₁ = lt ∨ o₁ = eq ∧ o₂ = lt := by
cases o₁ <;> cases o₂ <;> decide
end Ordering
open Ordering OrderDual
@[simp]
theorem toDual_compares_toDual [LT α] {a b : α} {o : Ordering} :
Compares o (toDual a) (toDual b) ↔ Compares o b a := by
cases o
exacts [Iff.rfl, eq_comm, Iff.rfl]
@[simp]
theorem ofDual_compares_ofDual [LT α] {a b : αᵒᵈ} {o : Ordering} :
Compares o (ofDual a) (ofDual b) ↔ Compares o b a := by
cases o
exacts [Iff.rfl, eq_comm, Iff.rfl]
theorem cmp_compares [LinearOrder α] (a b : α) : (cmp a b).Compares a b := by
obtain h | h | h := lt_trichotomy a b <;> simp [cmp, cmpUsing, h, h.not_lt]
theorem Ordering.Compares.cmp_eq [LinearOrder α] {a b : α} {o : Ordering} (h : o.Compares a b) :
cmp a b = o :=
(cmp_compares a b).inj h
@[simp]
theorem cmp_swap [Preorder α] [@DecidableRel α (· < ·)] (a b : α) : (cmp a b).swap = cmp b a := by
unfold cmp cmpUsing
by_cases h : a < b <;> by_cases h₂ : b < a <;> simp [h, h₂, Ordering.swap]
exact lt_asymm h h₂
-- Porting note: Not sure why the simpNF linter doesn't like this. @semorrison
@[simp, nolint simpNF]
theorem cmpLE_toDual [LE α] [@DecidableRel α (· ≤ ·)] (x y : α) :
cmpLE (toDual x) (toDual y) = cmpLE y x :=
rfl
@[simp]
theorem cmpLE_ofDual [LE α] [@DecidableRel α (· ≤ ·)] (x y : αᵒᵈ) :
cmpLE (ofDual x) (ofDual y) = cmpLE y x :=
rfl
-- Porting note: Not sure why the simpNF linter doesn't like this. @semorrison
@[simp, nolint simpNF]
theorem cmp_toDual [LT α] [@DecidableRel α (· < ·)] (x y : α) :
cmp (toDual x) (toDual y) = cmp y x :=
rfl
@[simp]
theorem cmp_ofDual [LT α] [@DecidableRel α (· < ·)] (x y : αᵒᵈ) :
cmp (ofDual x) (ofDual y) = cmp y x :=
rfl
/-- Generate a linear order structure from a preorder and `cmp` function. -/
def linearOrderOfCompares [Preorder α] (cmp : α → α → Ordering)
(h : ∀ a b, (cmp a b).Compares a b) : LinearOrder α :=
let H : DecidableRel (α := α) (· ≤ ·) := fun a b => decidable_of_iff _ (h a b).ne_gt
{ inferInstanceAs (Preorder α) with
le_antisymm := fun a b => (h a b).le_antisymm,
le_total := fun a b => (h a b).le_total,
toMin := minOfLe,
toMax := maxOfLe,
decidableLE := H,
decidableLT := fun a b => decidable_of_iff _ (h a b).eq_lt,
decidableEq := fun a b => decidable_of_iff _ (h a b).eq_eq }
variable [LinearOrder α] (x y : α)
@[simp]
theorem cmp_eq_lt_iff : cmp x y = Ordering.lt ↔ x < y :=
Ordering.Compares.eq_lt (cmp_compares x y)
@[simp]
theorem cmp_eq_eq_iff : cmp x y = Ordering.eq ↔ x = y :=
Ordering.Compares.eq_eq (cmp_compares x y)
@[simp]
theorem cmp_eq_gt_iff : cmp x y = Ordering.gt ↔ y < x :=
Ordering.Compares.eq_gt (cmp_compares x y)
@[simp]
theorem cmp_self_eq_eq : cmp x x = Ordering.eq := by rw [cmp_eq_eq_iff]
variable {x y} {β : Type*} [LinearOrder β] {x' y' : β}
theorem cmp_eq_cmp_symm : cmp x y = cmp x' y' ↔ cmp y x = cmp y' x' :=
⟨fun h => by rwa [← cmp_swap x', ← cmp_swap, swap_inj],
fun h => by rwa [← cmp_swap y', ← cmp_swap, swap_inj]⟩
theorem lt_iff_lt_of_cmp_eq_cmp (h : cmp x y = cmp x' y') : x < y ↔ x' < y' := by
rw [← cmp_eq_lt_iff, ← cmp_eq_lt_iff, h]
theorem le_iff_le_of_cmp_eq_cmp (h : cmp x y = cmp x' y') : x ≤ y ↔ x' ≤ y' := by
rw [← not_lt, ← not_lt]
apply not_congr
apply lt_iff_lt_of_cmp_eq_cmp
rwa [cmp_eq_cmp_symm]
theorem eq_iff_eq_of_cmp_eq_cmp (h : cmp x y = cmp x' y') : x = y ↔ x' = y' := by
rw [le_antisymm_iff, le_antisymm_iff, le_iff_le_of_cmp_eq_cmp h,
le_iff_le_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 h)]
theorem LT.lt.cmp_eq_lt (h : x < y) : cmp x y = Ordering.lt :=
(cmp_eq_lt_iff _ _).2 h
theorem LT.lt.cmp_eq_gt (h : x < y) : cmp y x = Ordering.gt :=
(cmp_eq_gt_iff _ _).2 h
theorem Eq.cmp_eq_eq (h : x = y) : cmp x y = Ordering.eq :=
(cmp_eq_eq_iff _ _).2 h
theorem Eq.cmp_eq_eq' (h : x = y) : cmp y x = Ordering.eq :=
h.symm.cmp_eq_eq
|
Order\CompleteBooleanAlgebra.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yaël Dillies
-/
import Mathlib.Order.CompleteLattice
import Mathlib.Order.Directed
import Mathlib.Logic.Equiv.Set
/-!
# Frames, completely distributive lattices and complete Boolean algebras
In this file we define and provide API for (co)frames, completely distributive lattices and
complete Boolean algebras.
We distinguish two different distributivity properties:
1. `inf_iSup_eq : (a ⊓ ⨆ i, f i) = ⨆ i, a ⊓ f i` (finite `⊓` distributes over infinite `⨆`).
This is required by `Frame`, `CompleteDistribLattice`, and `CompleteBooleanAlgebra`
(`Coframe`, etc., require the dual property).
2. `iInf_iSup_eq : (⨅ i, ⨆ j, f i j) = ⨆ s, ⨅ i, f i (s i)`
(infinite `⨅` distributes over infinite `⨆`).
This stronger property is called "completely distributive",
and is required by `CompletelyDistribLattice` and `CompleteAtomicBooleanAlgebra`.
## Typeclasses
* `Order.Frame`: Frame: A complete lattice whose `⊓` distributes over `⨆`.
* `Order.Coframe`: Coframe: A complete lattice whose `⊔` distributes over `⨅`.
* `CompleteDistribLattice`: Complete distributive lattices: A complete lattice whose `⊓` and `⊔`
distribute over `⨆` and `⨅` respectively.
* `CompleteBooleanAlgebra`: Complete Boolean algebra: A Boolean algebra whose `⊓`
and `⊔` distribute over `⨆` and `⨅` respectively.
* `CompletelyDistribLattice`: Completely distributive lattices: A complete lattice whose
`⨅` and `⨆` satisfy `iInf_iSup_eq`.
* `CompleteBooleanAlgebra`: Complete Boolean algebra: A Boolean algebra whose `⊓`
and `⊔` distribute over `⨆` and `⨅` respectively.
* `CompleteAtomicBooleanAlgebra`: Complete atomic Boolean algebra:
A complete Boolean algebra which is additionally completely distributive.
(This implies that it's (co)atom(ist)ic.)
A set of opens gives rise to a topological space precisely if it forms a frame. Such a frame is also
completely distributive, but not all frames are. `Filter` is a coframe but not a completely
distributive lattice.
## References
* [Wikipedia, *Complete Heyting algebra*](https://en.wikipedia.org/wiki/Complete_Heyting_algebra)
* [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3]
-/
open Function Set
universe u v w w'
variable {α : Type u} {β : Type v} {ι : Sort w} {κ : ι → Sort w'}
/-- Structure containing the minimal axioms required to check that an order is a frame. Do NOT use,
except for implementing `Order.Frame` via `Order.Frame.ofMinimalAxioms`.
This structure omits the `himp`, `compl` fields, which can be recovered using
`Order.Frame.ofMinimalAxioms`. -/
class Order.Frame.MinimalAxioms (α : Type u) extends CompleteLattice α where
inf_sSup_le_iSup_inf (a : α) (s : Set α) : a ⊓ sSup s ≤ ⨆ b ∈ s, a ⊓ b
/-- Structure containing the minimal axioms required to check that an order is a coframe. Do NOT
use, except for implementing `Order.Coframe` via `Order.Coframe.ofMinimalAxioms`.
This structure omits the `sdiff`, `hnot` fields, which can be recovered using
`Order.Coframe.ofMinimalAxioms`. -/
class Order.Coframe.MinimalAxioms (α : Type u) extends CompleteLattice α where
iInf_sup_le_sup_sInf (a : α) (s : Set α) : ⨅ b ∈ s, a ⊔ b ≤ a ⊔ sInf s
/-- A frame, aka complete Heyting algebra, is a complete lattice whose `⊓` distributes over `⨆`. -/
class Order.Frame (α : Type*) extends CompleteLattice α, HeytingAlgebra α where
/-- `⊓` distributes over `⨆`. -/
inf_sSup_le_iSup_inf (a : α) (s : Set α) : a ⊓ sSup s ≤ ⨆ b ∈ s, a ⊓ b
/-- A coframe, aka complete Brouwer algebra or complete co-Heyting algebra, is a complete lattice
whose `⊔` distributes over `⨅`. -/
class Order.Coframe (α : Type*) extends CompleteLattice α, CoheytingAlgebra α where
/-- `⊔` distributes over `⨅`. -/
iInf_sup_le_sup_sInf (a : α) (s : Set α) : ⨅ b ∈ s, a ⊔ b ≤ a ⊔ sInf s
open Order
/-- Structure containing the minimal axioms required to check that an order is a complete
distributive lattice. Do NOT use, except for implementing `CompleteDistribLattice` via
`CompleteDistribLattice.ofMinimalAxioms`.
This structure omits the `himp`, `compl`, `sdiff`, `hnot` fields, which can be recovered using
`CompleteDistribLattice.ofMinimalAxioms`. -/
structure CompleteDistribLattice.MinimalAxioms (α : Type u)
extends CompleteLattice α, Frame.MinimalAxioms α, Coframe.MinimalAxioms α where
-- We give those projections better name further down
attribute [nolint docBlame] CompleteDistribLattice.MinimalAxioms.toMinimalAxioms
CompleteDistribLattice.MinimalAxioms.toMinimalAxioms_1
/-- A complete distributive lattice is a complete lattice whose `⊔` and `⊓` respectively
distribute over `⨅` and `⨆`. -/
class CompleteDistribLattice (α : Type*) extends Frame α, Coframe α, BiheytingAlgebra α
/-- In a complete distributive lattice, `⊔` distributes over `⨅`. -/
add_decl_doc CompleteDistribLattice.iInf_sup_le_sup_sInf
/-- Structure containing the minimal axioms required to check that an order is a completely
distributive. Do NOT use, except for implementing `CompletelyDistribLattice` via
`CompletelyDistribLattice.ofMinimalAxioms`.
This structure omits the `himp`, `compl`, `sdiff`, `hnot` fields, which can be recovered using
`CompletelyDistribLattice.ofMinimalAxioms`. -/
structure CompletelyDistribLattice.MinimalAxioms (α : Type u) extends CompleteLattice α where
protected iInf_iSup_eq {ι : Type u} {κ : ι → Type u} (f : ∀ a, κ a → α) :
(⨅ a, ⨆ b, f a b) = ⨆ g : ∀ a, κ a, ⨅ a, f a (g a)
/-- A completely distributive lattice is a complete lattice whose `⨅` and `⨆`
distribute over each other. -/
class CompletelyDistribLattice (α : Type u) extends CompleteLattice α, BiheytingAlgebra α where
protected iInf_iSup_eq {ι : Type u} {κ : ι → Type u} (f : ∀ a, κ a → α) :
(⨅ a, ⨆ b, f a b) = ⨆ g : ∀ a, κ a, ⨅ a, f a (g a)
theorem le_iInf_iSup [CompleteLattice α] {f : ∀ a, κ a → α} :
(⨆ g : ∀ a, κ a, ⨅ a, f a (g a)) ≤ ⨅ a, ⨆ b, f a b :=
iSup_le fun _ => le_iInf fun a => le_trans (iInf_le _ a) (le_iSup _ _)
lemma iSup_iInf_le [CompleteLattice α] {f : ∀ a, κ a → α} :
⨆ a, ⨅ b, f a b ≤ ⨅ g : ∀ a, κ a, ⨆ a, f a (g a) :=
le_iInf_iSup (α := αᵒᵈ)
namespace Order.Frame.MinimalAxioms
variable (minAx : MinimalAxioms α) {s : Set α} {a b : α}
lemma inf_sSup_eq : a ⊓ sSup s = ⨆ b ∈ s, a ⊓ b :=
(minAx.inf_sSup_le_iSup_inf _ _).antisymm iSup_inf_le_inf_sSup
lemma sSup_inf_eq : sSup s ⊓ b = ⨆ a ∈ s, a ⊓ b := by
simpa only [inf_comm] using @inf_sSup_eq α _ s b
lemma iSup_inf_eq (f : ι → α) (a : α) : (⨆ i, f i) ⊓ a = ⨆ i, f i ⊓ a := by
rw [iSup, sSup_inf_eq, iSup_range]
lemma inf_iSup_eq (a : α) (f : ι → α) : (a ⊓ ⨆ i, f i) = ⨆ i, a ⊓ f i := by
simpa only [inf_comm] using minAx.iSup_inf_eq f a
lemma inf_iSup₂_eq {f : ∀ i, κ i → α} (a : α) : (a ⊓ ⨆ i, ⨆ j, f i j) = ⨆ i, ⨆ j, a ⊓ f i j := by
simp only [inf_iSup_eq]
/-- The `Order.Frame.MinimalAxioms` element corresponding to a frame. -/
def of [Frame α] : MinimalAxioms α := { ‹Frame α› with }
end MinimalAxioms
/-- Construct a frame instance using the minimal amount of work needed.
This sets `a ⇨ b := sSup {c | c ⊓ a ≤ b}` and `aᶜ := a ⇨ ⊥`. -/
-- See note [reducible non instances]
abbrev ofMinimalAxioms (minAx : MinimalAxioms α) : Frame α where
__ := minAx
himp a b := sSup {c | c ⊓ a ≤ b}
le_himp_iff a b c :=
⟨fun h ↦ (inf_le_inf_right _ h).trans (by simp [minAx.sSup_inf_eq]), fun h ↦ le_sSup h⟩
himp_bot _ := rfl
end Order.Frame
namespace Order.Coframe.MinimalAxioms
variable (minAx : MinimalAxioms α) {s : Set α} {a b : α}
lemma sup_sInf_eq : a ⊔ sInf s = ⨅ b ∈ s, a ⊔ b :=
sup_sInf_le_iInf_sup.antisymm (minAx.iInf_sup_le_sup_sInf _ _)
lemma sInf_sup_eq : sInf s ⊔ b = ⨅ a ∈ s, a ⊔ b := by
simpa only [sup_comm] using @sup_sInf_eq α _ s b
lemma iInf_sup_eq (f : ι → α) (a : α) : (⨅ i, f i) ⊔ a = ⨅ i, f i ⊔ a := by
rw [iInf, sInf_sup_eq, iInf_range]
lemma sup_iInf_eq (a : α) (f : ι → α) : (a ⊔ ⨅ i, f i) = ⨅ i, a ⊔ f i := by
simpa only [sup_comm] using minAx.iInf_sup_eq f a
lemma sup_iInf₂_eq {f : ∀ i, κ i → α} (a : α) : (a ⊔ ⨅ i, ⨅ j, f i j) = ⨅ i, ⨅ j, a ⊔ f i j := by
simp only [sup_iInf_eq]
/-- The `Order.Coframe.MinimalAxioms` element corresponding to a frame. -/
def of [Coframe α] : MinimalAxioms α := { ‹Coframe α› with }
end MinimalAxioms
/-- Construct a coframe instance using the minimal amount of work needed.
This sets `a \ b := sInf {c | a ≤ b ⊔ c}` and `¬a := ⊤ \ a`. -/
-- See note [reducible non instances]
abbrev ofMinimalAxioms (minAx : MinimalAxioms α) : Coframe α where
__ := minAx
sdiff a b := sInf {c | a ≤ b ⊔ c}
sdiff_le_iff a b c :=
⟨fun h ↦ (sup_le_sup_left h _).trans' (by simp [minAx.sup_sInf_eq]), fun h ↦ sInf_le h⟩
top_sdiff _ := rfl
end Order.Coframe
namespace CompleteDistribLattice.MinimalAxioms
variable (minAx : MinimalAxioms α) {s : Set α} {a b : α}
/-- The `CompleteDistribLattice.MinimalAxioms` element corresponding to a complete distrib lattice.
-/
def of [CompleteDistribLattice α] : MinimalAxioms α := { ‹CompleteDistribLattice α› with }
/-- Turn minimal axioms for `CompleteDistribLattice` into minimal axioms for `Order.Frame`. -/
abbrev toFrame : Frame.MinimalAxioms α := minAx.toMinimalAxioms
/-- Turn minimal axioms for `CompleteDistribLattice` into minimal axioms for `Order.Coframe`. -/
abbrev toCoframe : Coframe.MinimalAxioms α where __ := minAx
end MinimalAxioms
/-- Construct a complete distrib lattice instance using the minimal amount of work needed.
This sets `a ⇨ b := sSup {c | c ⊓ a ≤ b}`, `aᶜ := a ⇨ ⊥`, `a \ b := sInf {c | a ≤ b ⊔ c}` and
`¬a := ⊤ \ a`. -/
-- See note [reducible non instances]
abbrev ofMinimalAxioms (minAx : MinimalAxioms α) : CompleteDistribLattice α where
__ := Frame.ofMinimalAxioms minAx.toFrame
__ := Coframe.ofMinimalAxioms minAx.toCoframe
end CompleteDistribLattice
namespace CompletelyDistribLattice.MinimalAxioms
variable (minAx : MinimalAxioms α)
lemma iInf_iSup_eq' (f : ∀ a, κ a → α) :
let _ := minAx.toCompleteLattice
⨅ i, ⨆ j, f i j = ⨆ g : ∀ i, κ i, ⨅ i, f i (g i) := by
let _ := minAx.toCompleteLattice
refine le_antisymm ?_ le_iInf_iSup
calc
_ = ⨅ a : range (range <| f ·), ⨆ b : a.1, b.1 := by
simp_rw [iInf_subtype, iInf_range, iSup_subtype, iSup_range]
_ = _ := minAx.iInf_iSup_eq _
_ ≤ _ := iSup_le fun g => by
refine le_trans ?_ <| le_iSup _ fun a => Classical.choose (g ⟨_, a, rfl⟩).2
refine le_iInf fun a => le_trans (iInf_le _ ⟨range (f a), a, rfl⟩) ?_
rw [← Classical.choose_spec (g ⟨_, a, rfl⟩).2]
lemma iSup_iInf_eq (f : ∀ i, κ i → α) :
let _ := minAx.toCompleteLattice
⨆ i, ⨅ j, f i j = ⨅ g : ∀ i, κ i, ⨆ i, f i (g i) := by
let _ := minAx.toCompleteLattice
refine le_antisymm iSup_iInf_le ?_
rw [minAx.iInf_iSup_eq']
refine iSup_le fun g => ?_
have ⟨a, ha⟩ : ∃ a, ∀ b, ∃ f, ∃ h : a = g f, h ▸ b = f (g f) := of_not_not fun h => by
push_neg at h
choose h hh using h
have := hh _ h rfl
contradiction
refine le_trans ?_ (le_iSup _ a)
refine le_iInf fun b => ?_
obtain ⟨h, rfl, rfl⟩ := ha b
exact iInf_le _ _
/-- Turn minimal axioms for `CompletelyDistribLattice` into minimal axioms for
`CompleteDistribLattice`. -/
abbrev toCompleteDistribLattice : CompleteDistribLattice.MinimalAxioms α where
__ := minAx
inf_sSup_le_iSup_inf a s := by
let _ := minAx.toCompleteLattice
calc
_ = ⨅ i : ULift.{u} Bool, ⨆ j : match i with | .up true => PUnit.{u + 1} | .up false => s,
match i with
| .up true => a
| .up false => j := by simp [le_antisymm_iff, sSup_eq_iSup', iSup_unique, iInf_bool_eq]
_ ≤ _ := by
simp only [minAx.iInf_iSup_eq, iInf_ulift, iInf_bool_eq, iSup_le_iff]
exact fun x ↦ le_biSup _ (x (.up false)).2
iInf_sup_le_sup_sInf a s := by
let _ := minAx.toCompleteLattice
calc
_ ≤ ⨆ i : ULift.{u} Bool, ⨅ j : match i with | .up true => PUnit.{u + 1} | .up false => s,
match i with
| .up true => a
| .up false => j := by
simp only [minAx.iSup_iInf_eq, iSup_ulift, iSup_bool_eq, le_iInf_iff]
exact fun x ↦ biInf_le _ (x (.up false)).2
_ = _ := by simp [le_antisymm_iff, sInf_eq_iInf', iInf_unique, iSup_bool_eq]
/-- The `CompletelyDistribLattice.MinimalAxioms` element corresponding to a frame. -/
def of [CompletelyDistribLattice α] : MinimalAxioms α := { ‹CompletelyDistribLattice α› with }
end MinimalAxioms
/-- Construct a completely distributive lattice instance using the minimal amount of work needed.
This sets `a ⇨ b := sSup {c | c ⊓ a ≤ b}`, `aᶜ := a ⇨ ⊥`, `a \ b := sInf {c | a ≤ b ⊔ c}` and
`¬a := ⊤ \ a`. -/
-- See note [reducible non instances]
abbrev ofMinimalAxioms (minAx : MinimalAxioms α) : CompletelyDistribLattice α where
__ := minAx
__ := CompleteDistribLattice.ofMinimalAxioms minAx.toCompleteDistribLattice
end CompletelyDistribLattice
theorem iInf_iSup_eq [CompletelyDistribLattice α] {f : ∀ a, κ a → α} :
(⨅ a, ⨆ b, f a b) = ⨆ g : ∀ a, κ a, ⨅ a, f a (g a) :=
CompletelyDistribLattice.MinimalAxioms.of.iInf_iSup_eq' _
theorem iSup_iInf_eq [CompletelyDistribLattice α] {f : ∀ a, κ a → α} :
(⨆ a, ⨅ b, f a b) = ⨅ g : ∀ a, κ a, ⨆ a, f a (g a) :=
CompletelyDistribLattice.MinimalAxioms.of.iSup_iInf_eq _
instance (priority := 100) CompletelyDistribLattice.toCompleteDistribLattice
[CompletelyDistribLattice α] : CompleteDistribLattice α where
__ := ‹CompletelyDistribLattice α›
__ := CompleteDistribLattice.ofMinimalAxioms MinimalAxioms.of.toCompleteDistribLattice
-- See note [lower instance priority]
instance (priority := 100) CompleteLinearOrder.toCompletelyDistribLattice [CompleteLinearOrder α] :
CompletelyDistribLattice α where
__ := ‹CompleteLinearOrder α›
iInf_iSup_eq {α β} g := by
let lhs := ⨅ a, ⨆ b, g a b
let rhs := ⨆ h : ∀ a, β a, ⨅ a, g a (h a)
suffices lhs ≤ rhs from le_antisymm this le_iInf_iSup
if h : ∃ x, rhs < x ∧ x < lhs then
rcases h with ⟨x, hr, hl⟩
suffices rhs ≥ x from nomatch not_lt.2 this hr
have : ∀ a, ∃ b, x < g a b := fun a =>
lt_iSup_iff.1 <| lt_of_not_le fun h =>
lt_irrefl x (lt_of_lt_of_le hl (le_trans (iInf_le _ a) h))
choose f hf using this
refine le_trans ?_ (le_iSup _ f)
exact le_iInf fun a => le_of_lt (hf a)
else
refine le_of_not_lt fun hrl : rhs < lhs => not_le_of_lt hrl ?_
replace h : ∀ x, x ≤ rhs ∨ lhs ≤ x := by
simpa only [not_exists, not_and_or, not_or, not_lt] using h
have : ∀ a, ∃ b, rhs < g a b := fun a =>
lt_iSup_iff.1 <| lt_of_lt_of_le hrl (iInf_le _ a)
choose f hf using this
have : ∀ a, lhs ≤ g a (f a) := fun a =>
(h (g a (f a))).resolve_left (by simpa using hf a)
refine le_trans ?_ (le_iSup _ f)
exact le_iInf fun a => this _
section Frame
variable [Frame α] {s t : Set α} {a b : α}
instance OrderDual.instCoframe : Coframe αᵒᵈ where
__ := instCompleteLattice
__ := instCoheytingAlgebra
iInf_sup_le_sup_sInf := @Frame.inf_sSup_le_iSup_inf α _
theorem inf_sSup_eq : a ⊓ sSup s = ⨆ b ∈ s, a ⊓ b :=
(Frame.inf_sSup_le_iSup_inf _ _).antisymm iSup_inf_le_inf_sSup
theorem sSup_inf_eq : sSup s ⊓ b = ⨆ a ∈ s, a ⊓ b := by
simpa only [inf_comm] using @inf_sSup_eq α _ s b
theorem iSup_inf_eq (f : ι → α) (a : α) : (⨆ i, f i) ⊓ a = ⨆ i, f i ⊓ a := by
rw [iSup, sSup_inf_eq, iSup_range]
theorem inf_iSup_eq (a : α) (f : ι → α) : (a ⊓ ⨆ i, f i) = ⨆ i, a ⊓ f i := by
simpa only [inf_comm] using iSup_inf_eq f a
theorem iSup₂_inf_eq {f : ∀ i, κ i → α} (a : α) :
(⨆ (i) (j), f i j) ⊓ a = ⨆ (i) (j), f i j ⊓ a := by
simp only [iSup_inf_eq]
theorem inf_iSup₂_eq {f : ∀ i, κ i → α} (a : α) :
(a ⊓ ⨆ (i) (j), f i j) = ⨆ (i) (j), a ⊓ f i j := by
simp only [inf_iSup_eq]
theorem iSup_inf_iSup {ι ι' : Type*} {f : ι → α} {g : ι' → α} :
((⨆ i, f i) ⊓ ⨆ j, g j) = ⨆ i : ι × ι', f i.1 ⊓ g i.2 := by
simp_rw [iSup_inf_eq, inf_iSup_eq, iSup_prod]
theorem biSup_inf_biSup {ι ι' : Type*} {f : ι → α} {g : ι' → α} {s : Set ι} {t : Set ι'} :
((⨆ i ∈ s, f i) ⊓ ⨆ j ∈ t, g j) = ⨆ p ∈ s ×ˢ t, f (p : ι × ι').1 ⊓ g p.2 := by
simp only [iSup_subtype', iSup_inf_iSup]
exact (Equiv.surjective _).iSup_congr (Equiv.Set.prod s t).symm fun x => rfl
theorem sSup_inf_sSup : sSup s ⊓ sSup t = ⨆ p ∈ s ×ˢ t, (p : α × α).1 ⊓ p.2 := by
simp only [sSup_eq_iSup, biSup_inf_biSup]
theorem iSup_disjoint_iff {f : ι → α} : Disjoint (⨆ i, f i) a ↔ ∀ i, Disjoint (f i) a := by
simp only [disjoint_iff, iSup_inf_eq, iSup_eq_bot]
theorem disjoint_iSup_iff {f : ι → α} : Disjoint a (⨆ i, f i) ↔ ∀ i, Disjoint a (f i) := by
simpa only [disjoint_comm] using @iSup_disjoint_iff
theorem iSup₂_disjoint_iff {f : ∀ i, κ i → α} :
Disjoint (⨆ (i) (j), f i j) a ↔ ∀ i j, Disjoint (f i j) a := by
simp_rw [iSup_disjoint_iff]
theorem disjoint_iSup₂_iff {f : ∀ i, κ i → α} :
Disjoint a (⨆ (i) (j), f i j) ↔ ∀ i j, Disjoint a (f i j) := by
simp_rw [disjoint_iSup_iff]
theorem sSup_disjoint_iff {s : Set α} : Disjoint (sSup s) a ↔ ∀ b ∈ s, Disjoint b a := by
simp only [disjoint_iff, sSup_inf_eq, iSup_eq_bot]
theorem disjoint_sSup_iff {s : Set α} : Disjoint a (sSup s) ↔ ∀ b ∈ s, Disjoint a b := by
simpa only [disjoint_comm] using @sSup_disjoint_iff
theorem iSup_inf_of_monotone {ι : Type*} [Preorder ι] [IsDirected ι (· ≤ ·)] {f g : ι → α}
(hf : Monotone f) (hg : Monotone g) : ⨆ i, f i ⊓ g i = (⨆ i, f i) ⊓ ⨆ i, g i := by
refine (le_iSup_inf_iSup f g).antisymm ?_
rw [iSup_inf_iSup]
refine iSup_mono' fun i => ?_
rcases directed_of (· ≤ ·) i.1 i.2 with ⟨j, h₁, h₂⟩
exact ⟨j, inf_le_inf (hf h₁) (hg h₂)⟩
theorem iSup_inf_of_antitone {ι : Type*} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {f g : ι → α}
(hf : Antitone f) (hg : Antitone g) : ⨆ i, f i ⊓ g i = (⨆ i, f i) ⊓ ⨆ i, g i :=
@iSup_inf_of_monotone α _ ιᵒᵈ _ _ f g hf.dual_left hg.dual_left
-- see Note [lower instance priority]
instance (priority := 100) Frame.toDistribLattice : DistribLattice α :=
DistribLattice.ofInfSupLe fun a b c => by
rw [← sSup_pair, ← sSup_pair, inf_sSup_eq, ← sSup_image, image_pair]
instance Prod.instFrame [Frame α] [Frame β] : Frame (α × β) where
__ := instCompleteLattice
__ := instHeytingAlgebra
inf_sSup_le_iSup_inf a s := by
simp [Prod.le_def, sSup_eq_iSup, fst_iSup, snd_iSup, fst_iInf, snd_iInf, inf_iSup_eq]
instance Pi.instFrame {ι : Type*} {π : ι → Type*} [∀ i, Frame (π i)] : Frame (∀ i, π i) where
__ := instCompleteLattice
__ := instHeytingAlgebra
inf_sSup_le_iSup_inf a s i := by
simp only [sSup_apply, iSup_apply, inf_apply, inf_iSup_eq, ← iSup_subtype'']; rfl
end Frame
section Coframe
variable [Coframe α] {s t : Set α} {a b : α}
instance OrderDual.instFrame : Frame αᵒᵈ where
__ := instCompleteLattice
__ := instHeytingAlgebra
inf_sSup_le_iSup_inf := @Coframe.iInf_sup_le_sup_sInf α _
theorem sup_sInf_eq : a ⊔ sInf s = ⨅ b ∈ s, a ⊔ b :=
@inf_sSup_eq αᵒᵈ _ _ _
theorem sInf_sup_eq : sInf s ⊔ b = ⨅ a ∈ s, a ⊔ b :=
@sSup_inf_eq αᵒᵈ _ _ _
theorem iInf_sup_eq (f : ι → α) (a : α) : (⨅ i, f i) ⊔ a = ⨅ i, f i ⊔ a :=
@iSup_inf_eq αᵒᵈ _ _ _ _
theorem sup_iInf_eq (a : α) (f : ι → α) : (a ⊔ ⨅ i, f i) = ⨅ i, a ⊔ f i :=
@inf_iSup_eq αᵒᵈ _ _ _ _
theorem iInf₂_sup_eq {f : ∀ i, κ i → α} (a : α) : (⨅ (i) (j), f i j) ⊔ a = ⨅ (i) (j), f i j ⊔ a :=
@iSup₂_inf_eq αᵒᵈ _ _ _ _ _
theorem sup_iInf₂_eq {f : ∀ i, κ i → α} (a : α) : (a ⊔ ⨅ (i) (j), f i j) = ⨅ (i) (j), a ⊔ f i j :=
@inf_iSup₂_eq αᵒᵈ _ _ _ _ _
theorem iInf_sup_iInf {ι ι' : Type*} {f : ι → α} {g : ι' → α} :
((⨅ i, f i) ⊔ ⨅ i, g i) = ⨅ i : ι × ι', f i.1 ⊔ g i.2 :=
@iSup_inf_iSup αᵒᵈ _ _ _ _ _
theorem biInf_sup_biInf {ι ι' : Type*} {f : ι → α} {g : ι' → α} {s : Set ι} {t : Set ι'} :
((⨅ i ∈ s, f i) ⊔ ⨅ j ∈ t, g j) = ⨅ p ∈ s ×ˢ t, f (p : ι × ι').1 ⊔ g p.2 :=
@biSup_inf_biSup αᵒᵈ _ _ _ _ _ _ _
theorem sInf_sup_sInf : sInf s ⊔ sInf t = ⨅ p ∈ s ×ˢ t, (p : α × α).1 ⊔ p.2 :=
@sSup_inf_sSup αᵒᵈ _ _ _
theorem iInf_sup_of_monotone {ι : Type*} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {f g : ι → α}
(hf : Monotone f) (hg : Monotone g) : ⨅ i, f i ⊔ g i = (⨅ i, f i) ⊔ ⨅ i, g i :=
@iSup_inf_of_antitone αᵒᵈ _ _ _ _ _ _ hf.dual_right hg.dual_right
theorem iInf_sup_of_antitone {ι : Type*} [Preorder ι] [IsDirected ι (· ≤ ·)] {f g : ι → α}
(hf : Antitone f) (hg : Antitone g) : ⨅ i, f i ⊔ g i = (⨅ i, f i) ⊔ ⨅ i, g i :=
@iSup_inf_of_monotone αᵒᵈ _ _ _ _ _ _ hf.dual_right hg.dual_right
-- see Note [lower instance priority]
instance (priority := 100) Coframe.toDistribLattice : DistribLattice α where
__ := ‹Coframe α›
le_sup_inf a b c := by
rw [← sInf_pair, ← sInf_pair, sup_sInf_eq, ← sInf_image, image_pair]
instance Prod.instCoframe [Coframe β] : Coframe (α × β) where
__ := instCompleteLattice
__ := instCoheytingAlgebra
iInf_sup_le_sup_sInf a s := by
simp [Prod.le_def, sInf_eq_iInf, fst_iSup, snd_iSup, fst_iInf, snd_iInf, sup_iInf_eq]
instance Pi.instCoframe {ι : Type*} {π : ι → Type*} [∀ i, Coframe (π i)] : Coframe (∀ i, π i) where
__ := instCompleteLattice
__ := instCoheytingAlgebra
iInf_sup_le_sup_sInf a s i := by
simp only [sInf_apply, iInf_apply, sup_apply, sup_iInf_eq, ← iInf_subtype'']; rfl
end Coframe
section CompleteDistribLattice
variable [CompleteDistribLattice α] {a b : α} {s t : Set α}
instance OrderDual.instCompleteDistribLattice [CompleteDistribLattice α] :
CompleteDistribLattice αᵒᵈ where
__ := instFrame
__ := instCoframe
instance Prod.instCompleteDistribLattice [CompleteDistribLattice β] :
CompleteDistribLattice (α × β) where
__ := instFrame
__ := instCoframe
instance Pi.instCompleteDistribLattice {ι : Type*} {π : ι → Type*}
[∀ i, CompleteDistribLattice (π i)] : CompleteDistribLattice (∀ i, π i) where
__ := instFrame
__ := instCoframe
end CompleteDistribLattice
section CompletelyDistribLattice
instance OrderDual.instCompletelyDistribLattice [CompletelyDistribLattice α] :
CompletelyDistribLattice αᵒᵈ where
__ := instFrame
__ := instCoframe
iInf_iSup_eq _ := iSup_iInf_eq (α := α)
instance Prod.instCompletelyDistribLattice [CompletelyDistribLattice α]
[CompletelyDistribLattice β] : CompletelyDistribLattice (α × β) where
__ := instFrame
__ := instCoframe
iInf_iSup_eq f := by ext <;> simp [fst_iSup, fst_iInf, snd_iSup, snd_iInf, iInf_iSup_eq]
instance Pi.instCompletelyDistribLattice {ι : Type*} {π : ι → Type*}
[∀ i, CompletelyDistribLattice (π i)] : CompletelyDistribLattice (∀ i, π i) where
__ := instFrame
__ := instCoframe
iInf_iSup_eq f := by ext i; simp only [iInf_apply, iSup_apply, iInf_iSup_eq]
end CompletelyDistribLattice
/--
A complete Boolean algebra is a Boolean algebra that is also a complete distributive lattice.
It is only completely distributive if it is also atomic.
-/
-- We do not directly extend `CompleteDistribLattice` to avoid having the `hnot` field
class CompleteBooleanAlgebra (α) extends CompleteLattice α, BooleanAlgebra α where
/-- `⊓` distributes over `⨆`. -/
inf_sSup_le_iSup_inf (a : α) (s : Set α) : a ⊓ sSup s ≤ ⨆ b ∈ s, a ⊓ b
/-- `⊔` distributes over `⨅`. -/
iInf_sup_le_sup_sInf (a : α) (s : Set α) : ⨅ b ∈ s, a ⊔ b ≤ a ⊔ sInf s
-- See note [lower instance priority]
instance (priority := 100) CompleteBooleanAlgebra.toCompleteDistribLattice
[CompleteBooleanAlgebra α] : CompleteDistribLattice α where
__ := ‹CompleteBooleanAlgebra α›
__ := BooleanAlgebra.toBiheytingAlgebra
instance Prod.instCompleteBooleanAlgebra [CompleteBooleanAlgebra α] [CompleteBooleanAlgebra β] :
CompleteBooleanAlgebra (α × β) where
__ := instBooleanAlgebra
__ := instCompleteDistribLattice
instance Pi.instCompleteBooleanAlgebra {ι : Type*} {π : ι → Type*}
[∀ i, CompleteBooleanAlgebra (π i)] : CompleteBooleanAlgebra (∀ i, π i) where
__ := instBooleanAlgebra
__ := instCompleteDistribLattice
instance OrderDual.instCompleteBooleanAlgebra [CompleteBooleanAlgebra α] :
CompleteBooleanAlgebra αᵒᵈ where
__ := instBooleanAlgebra
__ := instCompleteDistribLattice
section CompleteBooleanAlgebra
variable [CompleteBooleanAlgebra α] {a b : α} {s : Set α} {f : ι → α}
theorem compl_iInf : (iInf f)ᶜ = ⨆ i, (f i)ᶜ :=
le_antisymm
(compl_le_of_compl_le <| le_iInf fun i => compl_le_of_compl_le <|
le_iSup (HasCompl.compl ∘ f) i)
(iSup_le fun _ => compl_le_compl <| iInf_le _ _)
theorem compl_iSup : (iSup f)ᶜ = ⨅ i, (f i)ᶜ :=
compl_injective (by simp [compl_iInf])
theorem compl_sInf : (sInf s)ᶜ = ⨆ i ∈ s, iᶜ := by simp only [sInf_eq_iInf, compl_iInf]
theorem compl_sSup : (sSup s)ᶜ = ⨅ i ∈ s, iᶜ := by simp only [sSup_eq_iSup, compl_iSup]
theorem compl_sInf' : (sInf s)ᶜ = sSup (HasCompl.compl '' s) :=
compl_sInf.trans sSup_image.symm
theorem compl_sSup' : (sSup s)ᶜ = sInf (HasCompl.compl '' s) :=
compl_sSup.trans sInf_image.symm
open scoped symmDiff in
/-- The symmetric difference of two `iSup`s is at most the `iSup` of the symmetric differences. -/
theorem iSup_symmDiff_iSup_le {g : ι → α} : (⨆ i, f i) ∆ (⨆ i, g i) ≤ ⨆ i, ((f i) ∆ (g i)) := by
simp_rw [symmDiff_le_iff, ← iSup_sup_eq]
exact ⟨iSup_mono fun i ↦ sup_comm (g i) _ ▸ le_symmDiff_sup_right ..,
iSup_mono fun i ↦ sup_comm (f i) _ ▸ symmDiff_comm (f i) _ ▸ le_symmDiff_sup_right ..⟩
open scoped symmDiff in
/-- A `biSup` version of `iSup_symmDiff_iSup_le`. -/
theorem biSup_symmDiff_biSup_le {p : ι → Prop} {f g : (i : ι) → p i → α} :
(⨆ i, ⨆ (h : p i), f i h) ∆ (⨆ i, ⨆ (h : p i), g i h) ≤
⨆ i, ⨆ (h : p i), ((f i h) ∆ (g i h)) :=
le_trans iSup_symmDiff_iSup_le <|iSup_mono fun _ ↦ iSup_symmDiff_iSup_le
end CompleteBooleanAlgebra
/--
A complete atomic Boolean algebra is a complete Boolean algebra
that is also completely distributive.
We take iSup_iInf_eq as the definition here,
and prove later on that this implies atomicity.
-/
-- We do not directly extend `CompletelyDistribLattice` to avoid having the `hnot` field
-- We do not directly extend `CompleteBooleanAlgebra` to avoid having the `inf_sSup_le_iSup_inf` and
-- `iInf_sup_le_sup_sInf` fields
class CompleteAtomicBooleanAlgebra (α : Type u) extends CompleteLattice α, BooleanAlgebra α where
protected iInf_iSup_eq {ι : Type u} {κ : ι → Type u} (f : ∀ a, κ a → α) :
(⨅ a, ⨆ b, f a b) = ⨆ g : ∀ a, κ a, ⨅ a, f a (g a)
-- See note [lower instance priority]
instance (priority := 100) CompleteAtomicBooleanAlgebra.toCompletelyDistribLattice
[CompleteAtomicBooleanAlgebra α] : CompletelyDistribLattice α where
__ := ‹CompleteAtomicBooleanAlgebra α›
__ := BooleanAlgebra.toBiheytingAlgebra
-- See note [lower instance priority]
instance (priority := 100) CompleteAtomicBooleanAlgebra.toCompleteBooleanAlgebra
[CompleteAtomicBooleanAlgebra α] : CompleteBooleanAlgebra α where
__ := ‹CompleteAtomicBooleanAlgebra α›
__ := CompletelyDistribLattice.toCompleteDistribLattice
instance Prod.instCompleteAtomicBooleanAlgebra [CompleteAtomicBooleanAlgebra α]
[CompleteAtomicBooleanAlgebra β] : CompleteAtomicBooleanAlgebra (α × β) where
__ := instBooleanAlgebra
__ := instCompletelyDistribLattice
instance Pi.instCompleteAtomicBooleanAlgebra {ι : Type*} {π : ι → Type*}
[∀ i, CompleteAtomicBooleanAlgebra (π i)] : CompleteAtomicBooleanAlgebra (∀ i, π i) where
__ := Pi.instCompleteBooleanAlgebra
iInf_iSup_eq f := by ext; rw [iInf_iSup_eq]
instance OrderDual.instCompleteAtomicBooleanAlgebra [CompleteAtomicBooleanAlgebra α] :
CompleteAtomicBooleanAlgebra αᵒᵈ where
__ := instCompleteBooleanAlgebra
__ := instCompletelyDistribLattice
instance Prop.instCompleteAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra Prop where
__ := Prop.instCompleteLattice
__ := Prop.instBooleanAlgebra
iInf_iSup_eq f := by simp [Classical.skolem]
instance Prop.instCompleteBooleanAlgebra : CompleteBooleanAlgebra Prop := inferInstance
section lift
-- See note [reducible non-instances]
/-- Pullback an `Order.Frame.MinimalAxioms` along an injection. -/
protected abbrev Function.Injective.frameMinimalAxioms [Sup α] [Inf α] [SupSet α] [InfSet α] [Top α]
[Bot α] (minAx : Frame.MinimalAxioms β) (f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_sSup : ∀ s, f (sSup s) = ⨆ a ∈ s, f a) (map_sInf : ∀ s, f (sInf s) = ⨅ a ∈ s, f a)
(map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) : Frame.MinimalAxioms α where
__ := hf.completeLattice f map_sup map_inf map_sSup map_sInf map_top map_bot
inf_sSup_le_iSup_inf a s := by
change f (a ⊓ sSup s) ≤ f _
rw [← sSup_image, map_inf, map_sSup s, minAx.inf_iSup₂_eq]
simp_rw [← map_inf]
exact ((map_sSup _).trans iSup_image).ge
-- See note [reducible non-instances]
/-- Pullback an `Order.Coframe.MinimalAxioms` along an injection. -/
protected abbrev Function.Injective.coframeMinimalAxioms [Sup α] [Inf α] [SupSet α] [InfSet α]
[Top α] [Bot α] (minAx : Coframe.MinimalAxioms β) (f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_sSup : ∀ s, f (sSup s) = ⨆ a ∈ s, f a) (map_sInf : ∀ s, f (sInf s) = ⨅ a ∈ s, f a)
(map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) : Coframe.MinimalAxioms α where
__ := hf.completeLattice f map_sup map_inf map_sSup map_sInf map_top map_bot
iInf_sup_le_sup_sInf a s := by
change f _ ≤ f (a ⊔ sInf s)
rw [← sInf_image, map_sup, map_sInf s, minAx.sup_iInf₂_eq]
simp_rw [← map_sup]
exact ((map_sInf _).trans iInf_image).le
-- See note [reducible non-instances]
/-- Pullback an `Order.Frame` along an injection. -/
protected abbrev Function.Injective.frame [Sup α] [Inf α] [SupSet α] [InfSet α] [Top α] [Bot α]
[HasCompl α] [HImp α] [Frame β] (f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_sSup : ∀ s, f (sSup s) = ⨆ a ∈ s, f a) (map_sInf : ∀ s, f (sInf s) = ⨅ a ∈ s, f a)
(map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) (map_compl : ∀ a, f aᶜ = (f a)ᶜ)
(map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b) : Frame α where
__ := hf.frameMinimalAxioms .of f map_sup map_inf map_sSup map_sInf map_top map_bot
__ := hf.heytingAlgebra f map_sup map_inf map_top map_bot map_compl map_himp
-- See note [reducible non-instances]
/-- Pullback an `Order.Coframe` along an injection. -/
protected abbrev Function.Injective.coframe [Sup α] [Inf α] [SupSet α] [InfSet α] [Top α] [Bot α]
[HNot α] [SDiff α] [Coframe β] (f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_sSup : ∀ s, f (sSup s) = ⨆ a ∈ s, f a) (map_sInf : ∀ s, f (sInf s) = ⨅ a ∈ s, f a)
(map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) (map_hnot : ∀ a, f (¬a) = ¬f a)
(map_sdiff : ∀ a b, f (a \ b) = f a \ f b) : Coframe α where
__ := hf.coframeMinimalAxioms .of f map_sup map_inf map_sSup map_sInf map_top map_bot
__ := hf.coheytingAlgebra f map_sup map_inf map_top map_bot map_hnot map_sdiff
-- See note [reducible non-instances]
/-- Pullback a `CompleteDistribLattice.MinimalAxioms` along an injection. -/
protected abbrev Function.Injective.completeDistribLatticeMinimalAxioms [Sup α] [Inf α] [SupSet α]
[InfSet α] [Top α] [Bot α] (minAx : CompleteDistribLattice.MinimalAxioms β) (f : α → β)
(hf : Injective f) (map_sup : let _ := minAx.toCompleteLattice
∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : let _ := minAx.toCompleteLattice
∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_sSup : let _ := minAx.toCompleteLattice
∀ s, f (sSup s) = ⨆ a ∈ s, f a) (map_sInf : let _ := minAx.toCompleteLattice
∀ s, f (sInf s) = ⨅ a ∈ s, f a) (map_top : let _ := minAx.toCompleteLattice
f ⊤ = ⊤) (map_bot : let _ := minAx.toCompleteLattice
f ⊥ = ⊥) :
CompleteDistribLattice.MinimalAxioms α where
__ := hf.frameMinimalAxioms minAx.toFrame f map_sup map_inf map_sSup map_sInf map_top map_bot
__ := hf.coframeMinimalAxioms minAx.toCoframe f map_sup map_inf map_sSup map_sInf map_top map_bot
-- See note [reducible non-instances]
/-- Pullback a `CompleteDistribLattice` along an injection. -/
protected abbrev Function.Injective.completeDistribLattice [Sup α] [Inf α] [SupSet α] [InfSet α]
[Top α] [Bot α] [HasCompl α] [HImp α] [HNot α] [SDiff α] [CompleteDistribLattice β] (f : α → β)
(hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_sSup : ∀ s, f (sSup s) = ⨆ a ∈ s, f a) (map_sInf : ∀ s, f (sInf s) = ⨅ a ∈ s, f a)
(map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥)
(map_compl : ∀ a, f aᶜ = (f a)ᶜ) (map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b)
(map_hnot : ∀ a, f (¬a) = ¬f a) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) :
CompleteDistribLattice α where
__ := hf.frame f map_sup map_inf map_sSup map_sInf map_top map_bot map_compl map_himp
__ := hf.coframe f map_sup map_inf map_sSup map_sInf map_top map_bot map_hnot map_sdiff
-- See note [reducible non-instances]
/-- Pullback a `CompletelyDistribLattice.MinimalAxioms` along an injection. -/
protected abbrev Function.Injective.completelyDistribLatticeMinimalAxioms [Sup α] [Inf α] [SupSet α]
[InfSet α] [Top α] [Bot α] (minAx : CompletelyDistribLattice.MinimalAxioms β) (f : α → β)
(hf : Injective f) (map_sup : let _ := minAx.toCompleteLattice
∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : let _ := minAx.toCompleteLattice
∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_sSup : let _ := minAx.toCompleteLattice
∀ s, f (sSup s) = ⨆ a ∈ s, f a) (map_sInf : let _ := minAx.toCompleteLattice
∀ s, f (sInf s) = ⨅ a ∈ s, f a) (map_top : let _ := minAx.toCompleteLattice
f ⊤ = ⊤) (map_bot : let _ := minAx.toCompleteLattice
f ⊥ = ⊥) :
CompletelyDistribLattice.MinimalAxioms α where
__ := hf.completeDistribLatticeMinimalAxioms minAx.toCompleteDistribLattice f map_sup map_inf
map_sSup map_sInf map_top map_bot
iInf_iSup_eq g := hf <| by
simp_rw [iInf, map_sInf, iInf_range, iSup, map_sSup, iSup_range, map_sInf, iInf_range,
minAx.iInf_iSup_eq']
-- See note [reducible non-instances]
/-- Pullback a `CompletelyDistribLattice` along an injection. -/
protected abbrev Function.Injective.completelyDistribLattice [Sup α] [Inf α] [SupSet α] [InfSet α]
[Top α] [Bot α] [HasCompl α] [HImp α] [HNot α] [SDiff α] [CompletelyDistribLattice β]
(f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_sSup : ∀ s, f (sSup s) = ⨆ a ∈ s, f a) (map_sInf : ∀ s, f (sInf s) = ⨅ a ∈ s, f a)
(map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥)
(map_compl : ∀ a, f aᶜ = (f a)ᶜ) (map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b)
(map_hnot : ∀ a, f (¬a) = ¬f a) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) :
CompletelyDistribLattice α where
__ := hf.completeLattice f map_sup map_inf map_sSup map_sInf map_top map_bot
__ := hf.biheytingAlgebra f map_sup map_inf map_top map_bot map_compl map_hnot map_himp map_sdiff
iInf_iSup_eq g := hf <| by
simp_rw [iInf, map_sInf, iInf_range, iSup, map_sSup, iSup_range, map_sInf, iInf_range,
iInf_iSup_eq]
-- See note [reducible non-instances]
/-- Pullback a `CompleteBooleanAlgebra` along an injection. -/
protected abbrev Function.Injective.completeBooleanAlgebra [Sup α] [Inf α] [SupSet α] [InfSet α]
[Top α] [Bot α] [HasCompl α] [HImp α] [SDiff α] [CompleteBooleanAlgebra β] (f : α → β)
(hf : Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b)
(map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_sSup : ∀ s, f (sSup s) = ⨆ a ∈ s, f a)
(map_sInf : ∀ s, f (sInf s) = ⨅ a ∈ s, f a) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥)
(map_compl : ∀ a, f aᶜ = (f a)ᶜ) (map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b)
(map_sdiff : ∀ a b, f (a \ b) = f a \ f b) :
CompleteBooleanAlgebra α where
__ := hf.completeLattice f map_sup map_inf map_sSup map_sInf map_top map_bot
__ := hf.booleanAlgebra f map_sup map_inf map_top map_bot map_compl map_sdiff map_himp
inf_sSup_le_iSup_inf a s := by
change f (a ⊓ sSup s) ≤ f _
rw [← sSup_image, map_inf, map_sSup s, inf_iSup₂_eq]
simp_rw [← map_inf]
exact ((map_sSup _).trans iSup_image).ge
iInf_sup_le_sup_sInf a s := by
change f _ ≤ f (a ⊔ sInf s)
rw [← sInf_image, map_sup, map_sInf s, sup_iInf₂_eq]
simp_rw [← map_sup]
exact ((map_sInf _).trans iInf_image).le
-- See note [reducible non-instances]
/-- Pullback a `CompleteAtomicBooleanAlgebra` along an injection. -/
protected abbrev Function.Injective.completeAtomicBooleanAlgebra [Sup α] [Inf α] [SupSet α]
[InfSet α] [Top α] [Bot α] [HasCompl α] [HImp α] [HNot α] [SDiff α]
[CompleteAtomicBooleanAlgebra β] (f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_sSup : ∀ s, f (sSup s) = ⨆ a ∈ s, f a) (map_sInf : ∀ s, f (sInf s) = ⨅ a ∈ s, f a)
(map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥)
(map_compl : ∀ a, f aᶜ = (f a)ᶜ) (map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b)
(map_hnot : ∀ a, f (¬a) = ¬f a) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) :
CompleteAtomicBooleanAlgebra α where
__ := hf.completelyDistribLattice f map_sup map_inf map_sSup map_sInf map_top map_bot map_compl
map_himp map_hnot map_sdiff
__ := hf.booleanAlgebra f map_sup map_inf map_top map_bot map_compl map_sdiff map_himp
end lift
namespace PUnit
variable (s : Set PUnit.{u + 1}) (x y : PUnit.{u + 1})
instance instCompleteAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra PUnit where
__ := PUnit.instBooleanAlgebra
sSup _ := unit
sInf _ := unit
le_sSup _ _ _ := trivial
sSup_le _ _ _ := trivial
sInf_le _ _ _ := trivial
le_sInf _ _ _ := trivial
iInf_iSup_eq _ := rfl
instance instCompleteBooleanAlgebra : CompleteBooleanAlgebra PUnit := inferInstance
@[simp]
theorem sSup_eq : sSup s = unit :=
rfl
@[simp]
theorem sInf_eq : sInf s = unit :=
rfl
end PUnit
|
Order\CompleteLattice.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Bool.Set
import Mathlib.Data.Nat.Set
import Mathlib.Data.Set.Prod
import Mathlib.Data.ULift
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Hom.Set
import Mathlib.Order.SetNotation
/-!
# Theory of complete lattices
## Main definitions
* `sSup` and `sInf` are the supremum and the infimum of a set;
* `iSup (f : ι → α)` and `iInf (f : ι → α)` are indexed supremum and infimum of a function,
defined as `sSup` and `sInf` of the range of this function;
* class `CompleteLattice`: a bounded lattice such that `sSup s` is always the least upper boundary
of `s` and `sInf s` is always the greatest lower boundary of `s`;
* class `CompleteLinearOrder`: a linear ordered complete lattice.
## Naming conventions
In lemma names,
* `sSup` is called `sSup`
* `sInf` is called `sInf`
* `⨆ i, s i` is called `iSup`
* `⨅ i, s i` is called `iInf`
* `⨆ i j, s i j` is called `iSup₂`. This is an `iSup` inside an `iSup`.
* `⨅ i j, s i j` is called `iInf₂`. This is an `iInf` inside an `iInf`.
* `⨆ i ∈ s, t i` is called `biSup` for "bounded `iSup`". This is the special case of `iSup₂`
where `j : i ∈ s`.
* `⨅ i ∈ s, t i` is called `biInf` for "bounded `iInf`". This is the special case of `iInf₂`
where `j : i ∈ s`.
## Notation
* `⨆ i, f i` : `iSup f`, the supremum of the range of `f`;
* `⨅ i, f i` : `iInf f`, the infimum of the range of `f`.
-/
open Function OrderDual Set
variable {α β β₂ γ : Type*} {ι ι' : Sort*} {κ : ι → Sort*} {κ' : ι' → Sort*}
@[simp] lemma iSup_ulift {ι : Type*} [SupSet α] (f : ULift ι → α) :
⨆ i : ULift ι, f i = ⨆ i, f (.up i) := by simp [iSup]; congr with x; simp
@[simp] lemma iInf_ulift {ι : Type*} [InfSet α] (f : ULift ι → α) :
⨅ i : ULift ι, f i = ⨅ i, f (.up i) := by simp [iInf]; congr with x; simp
instance OrderDual.supSet (α) [InfSet α] : SupSet αᵒᵈ :=
⟨(sInf : Set α → α)⟩
instance OrderDual.infSet (α) [SupSet α] : InfSet αᵒᵈ :=
⟨(sSup : Set α → α)⟩
/-- Note that we rarely use `CompleteSemilatticeSup`
(in fact, any such object is always a `CompleteLattice`, so it's usually best to start there).
Nevertheless it is sometimes a useful intermediate step in constructions.
-/
class CompleteSemilatticeSup (α : Type*) extends PartialOrder α, SupSet α where
/-- Any element of a set is less than the set supremum. -/
le_sSup : ∀ s, ∀ a ∈ s, a ≤ sSup s
/-- Any upper bound is more than the set supremum. -/
sSup_le : ∀ s a, (∀ b ∈ s, b ≤ a) → sSup s ≤ a
section
variable [CompleteSemilatticeSup α] {s t : Set α} {a b : α}
theorem le_sSup : a ∈ s → a ≤ sSup s :=
CompleteSemilatticeSup.le_sSup s a
theorem sSup_le : (∀ b ∈ s, b ≤ a) → sSup s ≤ a :=
CompleteSemilatticeSup.sSup_le s a
theorem isLUB_sSup (s : Set α) : IsLUB s (sSup s) :=
⟨fun _ ↦ le_sSup, fun _ ↦ sSup_le⟩
lemma isLUB_iff_sSup_eq : IsLUB s a ↔ sSup s = a :=
⟨(isLUB_sSup s).unique, by rintro rfl; exact isLUB_sSup _⟩
alias ⟨IsLUB.sSup_eq, _⟩ := isLUB_iff_sSup_eq
theorem le_sSup_of_le (hb : b ∈ s) (h : a ≤ b) : a ≤ sSup s :=
le_trans h (le_sSup hb)
@[gcongr]
theorem sSup_le_sSup (h : s ⊆ t) : sSup s ≤ sSup t :=
(isLUB_sSup s).mono (isLUB_sSup t) h
@[simp]
theorem sSup_le_iff : sSup s ≤ a ↔ ∀ b ∈ s, b ≤ a :=
isLUB_le_iff (isLUB_sSup s)
theorem le_sSup_iff : a ≤ sSup s ↔ ∀ b ∈ upperBounds s, a ≤ b :=
⟨fun h _ hb => le_trans h (sSup_le hb), fun hb => hb _ fun _ => le_sSup⟩
theorem le_iSup_iff {s : ι → α} : a ≤ iSup s ↔ ∀ b, (∀ i, s i ≤ b) → a ≤ b := by
simp [iSup, le_sSup_iff, upperBounds]
theorem sSup_le_sSup_of_forall_exists_le (h : ∀ x ∈ s, ∃ y ∈ t, x ≤ y) : sSup s ≤ sSup t :=
le_sSup_iff.2 fun _ hb =>
sSup_le fun a ha =>
let ⟨_, hct, hac⟩ := h a ha
hac.trans (hb hct)
-- We will generalize this to conditionally complete lattices in `csSup_singleton`.
theorem sSup_singleton {a : α} : sSup {a} = a :=
isLUB_singleton.sSup_eq
end
/-- Note that we rarely use `CompleteSemilatticeInf`
(in fact, any such object is always a `CompleteLattice`, so it's usually best to start there).
Nevertheless it is sometimes a useful intermediate step in constructions.
-/
class CompleteSemilatticeInf (α : Type*) extends PartialOrder α, InfSet α where
/-- Any element of a set is more than the set infimum. -/
sInf_le : ∀ s, ∀ a ∈ s, sInf s ≤ a
/-- Any lower bound is less than the set infimum. -/
le_sInf : ∀ s a, (∀ b ∈ s, a ≤ b) → a ≤ sInf s
section
variable [CompleteSemilatticeInf α] {s t : Set α} {a b : α}
theorem sInf_le : a ∈ s → sInf s ≤ a :=
CompleteSemilatticeInf.sInf_le s a
theorem le_sInf : (∀ b ∈ s, a ≤ b) → a ≤ sInf s :=
CompleteSemilatticeInf.le_sInf s a
theorem isGLB_sInf (s : Set α) : IsGLB s (sInf s) :=
⟨fun _ => sInf_le, fun _ => le_sInf⟩
lemma isGLB_iff_sInf_eq : IsGLB s a ↔ sInf s = a :=
⟨(isGLB_sInf s).unique, by rintro rfl; exact isGLB_sInf _⟩
alias ⟨IsGLB.sInf_eq, _⟩ := isGLB_iff_sInf_eq
theorem sInf_le_of_le (hb : b ∈ s) (h : b ≤ a) : sInf s ≤ a :=
le_trans (sInf_le hb) h
@[gcongr]
theorem sInf_le_sInf (h : s ⊆ t) : sInf t ≤ sInf s :=
(isGLB_sInf s).mono (isGLB_sInf t) h
@[simp]
theorem le_sInf_iff : a ≤ sInf s ↔ ∀ b ∈ s, a ≤ b :=
le_isGLB_iff (isGLB_sInf s)
theorem sInf_le_iff : sInf s ≤ a ↔ ∀ b ∈ lowerBounds s, b ≤ a :=
⟨fun h _ hb => le_trans (le_sInf hb) h, fun hb => hb _ fun _ => sInf_le⟩
theorem iInf_le_iff {s : ι → α} : iInf s ≤ a ↔ ∀ b, (∀ i, b ≤ s i) → b ≤ a := by
simp [iInf, sInf_le_iff, lowerBounds]
theorem sInf_le_sInf_of_forall_exists_le (h : ∀ x ∈ s, ∃ y ∈ t, y ≤ x) : sInf t ≤ sInf s :=
le_sInf fun x hx ↦ let ⟨_y, hyt, hyx⟩ := h x hx; sInf_le_of_le hyt hyx
-- We will generalize this to conditionally complete lattices in `csInf_singleton`.
theorem sInf_singleton {a : α} : sInf {a} = a :=
isGLB_singleton.sInf_eq
end
/-- A complete lattice is a bounded lattice which has suprema and infima for every subset. -/
class CompleteLattice (α : Type*) extends Lattice α, CompleteSemilatticeSup α,
CompleteSemilatticeInf α, Top α, Bot α where
/-- Any element is less than the top one. -/
protected le_top : ∀ x : α, x ≤ ⊤
/-- Any element is more than the bottom one. -/
protected bot_le : ∀ x : α, ⊥ ≤ x
-- see Note [lower instance priority]
instance (priority := 100) CompleteLattice.toBoundedOrder [h : CompleteLattice α] :
BoundedOrder α :=
{ h with }
/-- Create a `CompleteLattice` from a `PartialOrder` and `InfSet`
that returns the greatest lower bound of a set. Usually this constructor provides
poor definitional equalities. If other fields are known explicitly, they should be
provided; for example, if `inf` is known explicitly, construct the `CompleteLattice`
instance as
```
instance : CompleteLattice my_T where
inf := better_inf
le_inf := ...
inf_le_right := ...
inf_le_left := ...
-- don't care to fix sup, sSup, bot, top
__ := completeLatticeOfInf my_T _
```
-/
def completeLatticeOfInf (α : Type*) [H1 : PartialOrder α] [H2 : InfSet α]
(isGLB_sInf : ∀ s : Set α, IsGLB s (sInf s)) : CompleteLattice α where
__ := H1; __ := H2
bot := sInf univ
bot_le x := (isGLB_sInf univ).1 trivial
top := sInf ∅
le_top a := (isGLB_sInf ∅).2 <| by simp
sup a b := sInf { x : α | a ≤ x ∧ b ≤ x }
inf a b := sInf {a, b}
le_inf a b c hab hac := by
apply (isGLB_sInf _).2
simp [*]
inf_le_right a b := (isGLB_sInf _).1 <| mem_insert_of_mem _ <| mem_singleton _
inf_le_left a b := (isGLB_sInf _).1 <| mem_insert _ _
sup_le a b c hac hbc := (isGLB_sInf _).1 <| by simp [*]
le_sup_left a b := (isGLB_sInf _).2 fun x => And.left
le_sup_right a b := (isGLB_sInf _).2 fun x => And.right
le_sInf s a ha := (isGLB_sInf s).2 ha
sInf_le s a ha := (isGLB_sInf s).1 ha
sSup s := sInf (upperBounds s)
le_sSup s a ha := (isGLB_sInf (upperBounds s)).2 fun b hb => hb ha
sSup_le s a ha := (isGLB_sInf (upperBounds s)).1 ha
/-- Any `CompleteSemilatticeInf` is in fact a `CompleteLattice`.
Note that this construction has bad definitional properties:
see the doc-string on `completeLatticeOfInf`.
-/
def completeLatticeOfCompleteSemilatticeInf (α : Type*) [CompleteSemilatticeInf α] :
CompleteLattice α :=
completeLatticeOfInf α fun s => isGLB_sInf s
/-- Create a `CompleteLattice` from a `PartialOrder` and `SupSet`
that returns the least upper bound of a set. Usually this constructor provides
poor definitional equalities. If other fields are known explicitly, they should be
provided; for example, if `inf` is known explicitly, construct the `CompleteLattice`
instance as
```
instance : CompleteLattice my_T where
inf := better_inf
le_inf := ...
inf_le_right := ...
inf_le_left := ...
-- don't care to fix sup, sInf, bot, top
__ := completeLatticeOfSup my_T _
```
-/
def completeLatticeOfSup (α : Type*) [H1 : PartialOrder α] [H2 : SupSet α]
(isLUB_sSup : ∀ s : Set α, IsLUB s (sSup s)) : CompleteLattice α where
__ := H1; __ := H2
top := sSup univ
le_top x := (isLUB_sSup univ).1 trivial
bot := sSup ∅
bot_le x := (isLUB_sSup ∅).2 <| by simp
sup a b := sSup {a, b}
sup_le a b c hac hbc := (isLUB_sSup _).2 (by simp [*])
le_sup_left a b := (isLUB_sSup _).1 <| mem_insert _ _
le_sup_right a b := (isLUB_sSup _).1 <| mem_insert_of_mem _ <| mem_singleton _
inf a b := sSup { x | x ≤ a ∧ x ≤ b }
le_inf a b c hab hac := (isLUB_sSup _).1 <| by simp [*]
inf_le_left a b := (isLUB_sSup _).2 fun x => And.left
inf_le_right a b := (isLUB_sSup _).2 fun x => And.right
sInf s := sSup (lowerBounds s)
sSup_le s a ha := (isLUB_sSup s).2 ha
le_sSup s a ha := (isLUB_sSup s).1 ha
sInf_le s a ha := (isLUB_sSup (lowerBounds s)).2 fun b hb => hb ha
le_sInf s a ha := (isLUB_sSup (lowerBounds s)).1 ha
/-- Any `CompleteSemilatticeSup` is in fact a `CompleteLattice`.
Note that this construction has bad definitional properties:
see the doc-string on `completeLatticeOfSup`.
-/
def completeLatticeOfCompleteSemilatticeSup (α : Type*) [CompleteSemilatticeSup α] :
CompleteLattice α :=
completeLatticeOfSup α fun s => isLUB_sSup s
-- Porting note: as we cannot rename fields while extending,
-- `CompleteLinearOrder` does not directly extend `LinearOrder`.
-- Instead we add the fields by hand, and write a manual instance.
/-- A complete linear order is a linear order whose lattice structure is complete. -/
class CompleteLinearOrder (α : Type*) extends CompleteLattice α, BiheytingAlgebra α where
/-- A linear order is total. -/
le_total (a b : α) : a ≤ b ∨ b ≤ a
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
decidableLE : DecidableRel (· ≤ · : α → α → Prop)
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
decidableEq : DecidableEq α := @decidableEqOfDecidableLE _ _ decidableLE
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
decidableLT : DecidableRel (· < · : α → α → Prop) :=
@decidableLTOfDecidableLE _ _ decidableLE
instance CompleteLinearOrder.toLinearOrder [i : CompleteLinearOrder α] : LinearOrder α where
__ := i
min := Inf.inf
max := Sup.sup
min_def a b := by
split_ifs with h
· simp [h]
· simp [(CompleteLinearOrder.le_total a b).resolve_left h]
max_def a b := by
split_ifs with h
· simp [h]
· simp [(CompleteLinearOrder.le_total a b).resolve_left h]
namespace OrderDual
instance instCompleteLattice [CompleteLattice α] : CompleteLattice αᵒᵈ where
__ := instBoundedOrder α
le_sSup := @CompleteLattice.sInf_le α _
sSup_le := @CompleteLattice.le_sInf α _
sInf_le := @CompleteLattice.le_sSup α _
le_sInf := @CompleteLattice.sSup_le α _
instance instCompleteLinearOrder [CompleteLinearOrder α] : CompleteLinearOrder αᵒᵈ where
__ := instCompleteLattice
__ := instBiheytingAlgebra
__ := instLinearOrder α
end OrderDual
open OrderDual
section
variable [CompleteLattice α] {s t : Set α} {a b : α}
@[simp]
theorem toDual_sSup (s : Set α) : toDual (sSup s) = sInf (ofDual ⁻¹' s) :=
rfl
@[simp]
theorem toDual_sInf (s : Set α) : toDual (sInf s) = sSup (ofDual ⁻¹' s) :=
rfl
@[simp]
theorem ofDual_sSup (s : Set αᵒᵈ) : ofDual (sSup s) = sInf (toDual ⁻¹' s) :=
rfl
@[simp]
theorem ofDual_sInf (s : Set αᵒᵈ) : ofDual (sInf s) = sSup (toDual ⁻¹' s) :=
rfl
@[simp]
theorem toDual_iSup (f : ι → α) : toDual (⨆ i, f i) = ⨅ i, toDual (f i) :=
rfl
@[simp]
theorem toDual_iInf (f : ι → α) : toDual (⨅ i, f i) = ⨆ i, toDual (f i) :=
rfl
@[simp]
theorem ofDual_iSup (f : ι → αᵒᵈ) : ofDual (⨆ i, f i) = ⨅ i, ofDual (f i) :=
rfl
@[simp]
theorem ofDual_iInf (f : ι → αᵒᵈ) : ofDual (⨅ i, f i) = ⨆ i, ofDual (f i) :=
rfl
theorem sInf_le_sSup (hs : s.Nonempty) : sInf s ≤ sSup s :=
isGLB_le_isLUB (isGLB_sInf s) (isLUB_sSup s) hs
theorem sSup_union {s t : Set α} : sSup (s ∪ t) = sSup s ⊔ sSup t :=
((isLUB_sSup s).union (isLUB_sSup t)).sSup_eq
theorem sInf_union {s t : Set α} : sInf (s ∪ t) = sInf s ⊓ sInf t :=
((isGLB_sInf s).union (isGLB_sInf t)).sInf_eq
theorem sSup_inter_le {s t : Set α} : sSup (s ∩ t) ≤ sSup s ⊓ sSup t :=
sSup_le fun _ hb => le_inf (le_sSup hb.1) (le_sSup hb.2)
theorem le_sInf_inter {s t : Set α} : sInf s ⊔ sInf t ≤ sInf (s ∩ t) :=
@sSup_inter_le αᵒᵈ _ _ _
@[simp]
theorem sSup_empty : sSup ∅ = (⊥ : α) :=
(@isLUB_empty α _ _).sSup_eq
@[simp]
theorem sInf_empty : sInf ∅ = (⊤ : α) :=
(@isGLB_empty α _ _).sInf_eq
@[simp]
theorem sSup_univ : sSup univ = (⊤ : α) :=
(@isLUB_univ α _ _).sSup_eq
@[simp]
theorem sInf_univ : sInf univ = (⊥ : α) :=
(@isGLB_univ α _ _).sInf_eq
-- TODO(Jeremy): get this automatically
@[simp]
theorem sSup_insert {a : α} {s : Set α} : sSup (insert a s) = a ⊔ sSup s :=
((isLUB_sSup s).insert a).sSup_eq
@[simp]
theorem sInf_insert {a : α} {s : Set α} : sInf (insert a s) = a ⊓ sInf s :=
((isGLB_sInf s).insert a).sInf_eq
theorem sSup_le_sSup_of_subset_insert_bot (h : s ⊆ insert ⊥ t) : sSup s ≤ sSup t :=
(sSup_le_sSup h).trans_eq (sSup_insert.trans (bot_sup_eq _))
theorem sInf_le_sInf_of_subset_insert_top (h : s ⊆ insert ⊤ t) : sInf t ≤ sInf s :=
(sInf_le_sInf h).trans_eq' (sInf_insert.trans (top_inf_eq _)).symm
@[simp]
theorem sSup_diff_singleton_bot (s : Set α) : sSup (s \ {⊥}) = sSup s :=
(sSup_le_sSup diff_subset).antisymm <|
sSup_le_sSup_of_subset_insert_bot <| subset_insert_diff_singleton _ _
@[simp]
theorem sInf_diff_singleton_top (s : Set α) : sInf (s \ {⊤}) = sInf s :=
@sSup_diff_singleton_bot αᵒᵈ _ s
theorem sSup_pair {a b : α} : sSup {a, b} = a ⊔ b :=
(@isLUB_pair α _ a b).sSup_eq
theorem sInf_pair {a b : α} : sInf {a, b} = a ⊓ b :=
(@isGLB_pair α _ a b).sInf_eq
@[simp]
theorem sSup_eq_bot : sSup s = ⊥ ↔ ∀ a ∈ s, a = ⊥ :=
⟨fun h _ ha => bot_unique <| h ▸ le_sSup ha, fun h =>
bot_unique <| sSup_le fun a ha => le_bot_iff.2 <| h a ha⟩
@[simp]
theorem sInf_eq_top : sInf s = ⊤ ↔ ∀ a ∈ s, a = ⊤ :=
@sSup_eq_bot αᵒᵈ _ _
lemma sSup_eq_bot' {s : Set α} : sSup s = ⊥ ↔ s = ∅ ∨ s = {⊥} := by
rw [sSup_eq_bot, ← subset_singleton_iff_eq, subset_singleton_iff]
theorem eq_singleton_bot_of_sSup_eq_bot_of_nonempty {s : Set α} (h_sup : sSup s = ⊥)
(hne : s.Nonempty) : s = {⊥} := by
rw [Set.eq_singleton_iff_nonempty_unique_mem]
rw [sSup_eq_bot] at h_sup
exact ⟨hne, h_sup⟩
theorem eq_singleton_top_of_sInf_eq_top_of_nonempty : sInf s = ⊤ → s.Nonempty → s = {⊤} :=
@eq_singleton_bot_of_sSup_eq_bot_of_nonempty αᵒᵈ _ _
/-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b`
is larger than all elements of `s`, and that this is not the case of any `w < b`.
See `csSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in conditionally complete
lattices. -/
theorem sSup_eq_of_forall_le_of_forall_lt_exists_gt (h₁ : ∀ a ∈ s, a ≤ b)
(h₂ : ∀ w, w < b → ∃ a ∈ s, w < a) : sSup s = b :=
(sSup_le h₁).eq_of_not_lt fun h =>
let ⟨_, ha, ha'⟩ := h₂ _ h
((le_sSup ha).trans_lt ha').false
/-- Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b`
is smaller than all elements of `s`, and that this is not the case of any `w > b`.
See `csInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in conditionally complete
lattices. -/
theorem sInf_eq_of_forall_ge_of_forall_gt_exists_lt :
(∀ a ∈ s, b ≤ a) → (∀ w, b < w → ∃ a ∈ s, a < w) → sInf s = b :=
@sSup_eq_of_forall_le_of_forall_lt_exists_gt αᵒᵈ _ _ _
end
section CompleteLinearOrder
variable [CompleteLinearOrder α] {s t : Set α} {a b : α}
theorem lt_sSup_iff : b < sSup s ↔ ∃ a ∈ s, b < a :=
lt_isLUB_iff <| isLUB_sSup s
theorem sInf_lt_iff : sInf s < b ↔ ∃ a ∈ s, a < b :=
isGLB_lt_iff <| isGLB_sInf s
theorem sSup_eq_top : sSup s = ⊤ ↔ ∀ b < ⊤, ∃ a ∈ s, b < a :=
⟨fun h _ hb => lt_sSup_iff.1 <| hb.trans_eq h.symm, fun h =>
top_unique <|
le_of_not_gt fun h' =>
let ⟨_, ha, h⟩ := h _ h'
(h.trans_le <| le_sSup ha).false⟩
theorem sInf_eq_bot : sInf s = ⊥ ↔ ∀ b > ⊥, ∃ a ∈ s, a < b :=
@sSup_eq_top αᵒᵈ _ _
theorem lt_iSup_iff {f : ι → α} : a < iSup f ↔ ∃ i, a < f i :=
lt_sSup_iff.trans exists_range_iff
theorem iInf_lt_iff {f : ι → α} : iInf f < a ↔ ∃ i, f i < a :=
sInf_lt_iff.trans exists_range_iff
end CompleteLinearOrder
/-
### iSup & iInf
-/
section SupSet
variable [SupSet α] {f g : ι → α}
theorem sSup_range : sSup (range f) = iSup f :=
rfl
theorem sSup_eq_iSup' (s : Set α) : sSup s = ⨆ a : s, (a : α) := by rw [iSup, Subtype.range_coe]
theorem iSup_congr (h : ∀ i, f i = g i) : ⨆ i, f i = ⨆ i, g i :=
congr_arg _ <| funext h
theorem biSup_congr {p : ι → Prop} (h : ∀ i, p i → f i = g i) :
⨆ (i) (_ : p i), f i = ⨆ (i) (_ : p i), g i :=
iSup_congr fun i ↦ iSup_congr (h i)
theorem biSup_congr' {p : ι → Prop} {f g : (i : ι) → p i → α}
(h : ∀ i (hi : p i), f i hi = g i hi) :
⨆ i, ⨆ (hi : p i), f i hi = ⨆ i, ⨆ (hi : p i), g i hi := by
congr; ext i; congr; ext hi; exact h i hi
theorem Function.Surjective.iSup_comp {f : ι → ι'} (hf : Surjective f) (g : ι' → α) :
⨆ x, g (f x) = ⨆ y, g y := by
simp only [iSup.eq_1]
congr
exact hf.range_comp g
theorem Equiv.iSup_comp {g : ι' → α} (e : ι ≃ ι') : ⨆ x, g (e x) = ⨆ y, g y :=
e.surjective.iSup_comp _
protected theorem Function.Surjective.iSup_congr {g : ι' → α} (h : ι → ι') (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⨆ x, f x = ⨆ y, g y := by
convert h1.iSup_comp g
exact (h2 _).symm
protected theorem Equiv.iSup_congr {g : ι' → α} (e : ι ≃ ι') (h : ∀ x, g (e x) = f x) :
⨆ x, f x = ⨆ y, g y :=
e.surjective.iSup_congr _ h
@[congr]
theorem iSup_congr_Prop {p q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iSup f₁ = iSup f₂ := by
obtain rfl := propext pq
congr with x
apply f
theorem iSup_plift_up (f : PLift ι → α) : ⨆ i, f (PLift.up i) = ⨆ i, f i :=
(PLift.up_surjective.iSup_congr _) fun _ => rfl
theorem iSup_plift_down (f : ι → α) : ⨆ i, f (PLift.down i) = ⨆ i, f i :=
(PLift.down_surjective.iSup_congr _) fun _ => rfl
theorem iSup_range' (g : β → α) (f : ι → β) : ⨆ b : range f, g b = ⨆ i, g (f i) := by
rw [iSup, iSup, ← image_eq_range, ← range_comp]
rfl
theorem sSup_image' {s : Set β} {f : β → α} : sSup (f '' s) = ⨆ a : s, f a := by
rw [iSup, image_eq_range]
end SupSet
section InfSet
variable [InfSet α] {f g : ι → α}
theorem sInf_range : sInf (range f) = iInf f :=
rfl
theorem sInf_eq_iInf' (s : Set α) : sInf s = ⨅ a : s, (a : α) :=
@sSup_eq_iSup' αᵒᵈ _ _
theorem iInf_congr (h : ∀ i, f i = g i) : ⨅ i, f i = ⨅ i, g i :=
congr_arg _ <| funext h
theorem biInf_congr {p : ι → Prop} (h : ∀ i, p i → f i = g i) :
⨅ (i) (_ : p i), f i = ⨅ (i) (_ : p i), g i :=
biSup_congr (α := αᵒᵈ) h
theorem biInf_congr' {p : ι → Prop} {f g : (i : ι) → p i → α}
(h : ∀ i (hi : p i), f i hi = g i hi) :
⨅ i, ⨅ (hi : p i), f i hi = ⨅ i, ⨅ (hi : p i), g i hi := by
congr; ext i; congr; ext hi; exact h i hi
theorem Function.Surjective.iInf_comp {f : ι → ι'} (hf : Surjective f) (g : ι' → α) :
⨅ x, g (f x) = ⨅ y, g y :=
@Function.Surjective.iSup_comp αᵒᵈ _ _ _ f hf g
theorem Equiv.iInf_comp {g : ι' → α} (e : ι ≃ ι') : ⨅ x, g (e x) = ⨅ y, g y :=
@Equiv.iSup_comp αᵒᵈ _ _ _ _ e
protected theorem Function.Surjective.iInf_congr {g : ι' → α} (h : ι → ι') (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⨅ x, f x = ⨅ y, g y :=
@Function.Surjective.iSup_congr αᵒᵈ _ _ _ _ _ h h1 h2
protected theorem Equiv.iInf_congr {g : ι' → α} (e : ι ≃ ι') (h : ∀ x, g (e x) = f x) :
⨅ x, f x = ⨅ y, g y :=
@Equiv.iSup_congr αᵒᵈ _ _ _ _ _ e h
@[congr]
theorem iInf_congr_Prop {p q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInf f₁ = iInf f₂ :=
@iSup_congr_Prop αᵒᵈ _ p q f₁ f₂ pq f
theorem iInf_plift_up (f : PLift ι → α) : ⨅ i, f (PLift.up i) = ⨅ i, f i :=
(PLift.up_surjective.iInf_congr _) fun _ => rfl
theorem iInf_plift_down (f : ι → α) : ⨅ i, f (PLift.down i) = ⨅ i, f i :=
(PLift.down_surjective.iInf_congr _) fun _ => rfl
theorem iInf_range' (g : β → α) (f : ι → β) : ⨅ b : range f, g b = ⨅ i, g (f i) :=
@iSup_range' αᵒᵈ _ _ _ _ _
theorem sInf_image' {s : Set β} {f : β → α} : sInf (f '' s) = ⨅ a : s, f a :=
@sSup_image' αᵒᵈ _ _ _ _
end InfSet
section
variable [CompleteLattice α] {f g s t : ι → α} {a b : α}
theorem le_iSup (f : ι → α) (i : ι) : f i ≤ iSup f :=
le_sSup ⟨i, rfl⟩
theorem iInf_le (f : ι → α) (i : ι) : iInf f ≤ f i :=
sInf_le ⟨i, rfl⟩
theorem le_iSup' (f : ι → α) (i : ι) : f i ≤ iSup f :=
le_sSup ⟨i, rfl⟩
theorem iInf_le' (f : ι → α) (i : ι) : iInf f ≤ f i :=
sInf_le ⟨i, rfl⟩
theorem isLUB_iSup : IsLUB (range f) (⨆ j, f j) :=
isLUB_sSup _
theorem isGLB_iInf : IsGLB (range f) (⨅ j, f j) :=
isGLB_sInf _
theorem IsLUB.iSup_eq (h : IsLUB (range f) a) : ⨆ j, f j = a :=
h.sSup_eq
theorem IsGLB.iInf_eq (h : IsGLB (range f) a) : ⨅ j, f j = a :=
h.sInf_eq
theorem le_iSup_of_le (i : ι) (h : a ≤ f i) : a ≤ iSup f :=
h.trans <| le_iSup _ i
theorem iInf_le_of_le (i : ι) (h : f i ≤ a) : iInf f ≤ a :=
(iInf_le _ i).trans h
theorem le_iSup₂ {f : ∀ i, κ i → α} (i : ι) (j : κ i) : f i j ≤ ⨆ (i) (j), f i j :=
le_iSup_of_le i <| le_iSup (f i) j
theorem iInf₂_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) : ⨅ (i) (j), f i j ≤ f i j :=
iInf_le_of_le i <| iInf_le (f i) j
theorem le_iSup₂_of_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) (h : a ≤ f i j) :
a ≤ ⨆ (i) (j), f i j :=
h.trans <| le_iSup₂ i j
theorem iInf₂_le_of_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) (h : f i j ≤ a) :
⨅ (i) (j), f i j ≤ a :=
(iInf₂_le i j).trans h
theorem iSup_le (h : ∀ i, f i ≤ a) : iSup f ≤ a :=
sSup_le fun _ ⟨i, Eq⟩ => Eq ▸ h i
theorem le_iInf (h : ∀ i, a ≤ f i) : a ≤ iInf f :=
le_sInf fun _ ⟨i, Eq⟩ => Eq ▸ h i
theorem iSup₂_le {f : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ a) : ⨆ (i) (j), f i j ≤ a :=
iSup_le fun i => iSup_le <| h i
theorem le_iInf₂ {f : ∀ i, κ i → α} (h : ∀ i j, a ≤ f i j) : a ≤ ⨅ (i) (j), f i j :=
le_iInf fun i => le_iInf <| h i
theorem iSup₂_le_iSup (κ : ι → Sort*) (f : ι → α) : ⨆ (i) (_ : κ i), f i ≤ ⨆ i, f i :=
iSup₂_le fun i _ => le_iSup f i
theorem iInf_le_iInf₂ (κ : ι → Sort*) (f : ι → α) : ⨅ i, f i ≤ ⨅ (i) (_ : κ i), f i :=
le_iInf₂ fun i _ => iInf_le f i
@[gcongr]
theorem iSup_mono (h : ∀ i, f i ≤ g i) : iSup f ≤ iSup g :=
iSup_le fun i => le_iSup_of_le i <| h i
@[gcongr]
theorem iInf_mono (h : ∀ i, f i ≤ g i) : iInf f ≤ iInf g :=
le_iInf fun i => iInf_le_of_le i <| h i
theorem iSup₂_mono {f g : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ g i j) :
⨆ (i) (j), f i j ≤ ⨆ (i) (j), g i j :=
iSup_mono fun i => iSup_mono <| h i
theorem iInf₂_mono {f g : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ g i j) :
⨅ (i) (j), f i j ≤ ⨅ (i) (j), g i j :=
iInf_mono fun i => iInf_mono <| h i
theorem iSup_mono' {g : ι' → α} (h : ∀ i, ∃ i', f i ≤ g i') : iSup f ≤ iSup g :=
iSup_le fun i => Exists.elim (h i) le_iSup_of_le
theorem iInf_mono' {g : ι' → α} (h : ∀ i', ∃ i, f i ≤ g i') : iInf f ≤ iInf g :=
le_iInf fun i' => Exists.elim (h i') iInf_le_of_le
theorem iSup₂_mono' {f : ∀ i, κ i → α} {g : ∀ i', κ' i' → α} (h : ∀ i j, ∃ i' j', f i j ≤ g i' j') :
⨆ (i) (j), f i j ≤ ⨆ (i) (j), g i j :=
iSup₂_le fun i j =>
let ⟨i', j', h⟩ := h i j
le_iSup₂_of_le i' j' h
theorem iInf₂_mono' {f : ∀ i, κ i → α} {g : ∀ i', κ' i' → α} (h : ∀ i j, ∃ i' j', f i' j' ≤ g i j) :
⨅ (i) (j), f i j ≤ ⨅ (i) (j), g i j :=
le_iInf₂ fun i j =>
let ⟨i', j', h⟩ := h i j
iInf₂_le_of_le i' j' h
theorem iSup_const_mono (h : ι → ι') : ⨆ _ : ι, a ≤ ⨆ _ : ι', a :=
iSup_le <| le_iSup _ ∘ h
theorem iInf_const_mono (h : ι' → ι) : ⨅ _ : ι, a ≤ ⨅ _ : ι', a :=
le_iInf <| iInf_le _ ∘ h
theorem iSup_iInf_le_iInf_iSup (f : ι → ι' → α) : ⨆ i, ⨅ j, f i j ≤ ⨅ j, ⨆ i, f i j :=
iSup_le fun i => iInf_mono fun j => le_iSup (fun i => f i j) i
theorem biSup_mono {p q : ι → Prop} (hpq : ∀ i, p i → q i) :
⨆ (i) (_ : p i), f i ≤ ⨆ (i) (_ : q i), f i :=
iSup_mono fun i => iSup_const_mono (hpq i)
theorem biInf_mono {p q : ι → Prop} (hpq : ∀ i, p i → q i) :
⨅ (i) (_ : q i), f i ≤ ⨅ (i) (_ : p i), f i :=
iInf_mono fun i => iInf_const_mono (hpq i)
@[simp]
theorem iSup_le_iff : iSup f ≤ a ↔ ∀ i, f i ≤ a :=
(isLUB_le_iff isLUB_iSup).trans forall_mem_range
@[simp]
theorem le_iInf_iff : a ≤ iInf f ↔ ∀ i, a ≤ f i :=
(le_isGLB_iff isGLB_iInf).trans forall_mem_range
theorem iSup₂_le_iff {f : ∀ i, κ i → α} : ⨆ (i) (j), f i j ≤ a ↔ ∀ i j, f i j ≤ a := by
simp_rw [iSup_le_iff]
theorem le_iInf₂_iff {f : ∀ i, κ i → α} : (a ≤ ⨅ (i) (j), f i j) ↔ ∀ i j, a ≤ f i j := by
simp_rw [le_iInf_iff]
theorem iSup_lt_iff : iSup f < a ↔ ∃ b, b < a ∧ ∀ i, f i ≤ b :=
⟨fun h => ⟨iSup f, h, le_iSup f⟩, fun ⟨_, h, hb⟩ => (iSup_le hb).trans_lt h⟩
theorem lt_iInf_iff : a < iInf f ↔ ∃ b, a < b ∧ ∀ i, b ≤ f i :=
⟨fun h => ⟨iInf f, h, iInf_le f⟩, fun ⟨_, h, hb⟩ => h.trans_le <| le_iInf hb⟩
theorem sSup_eq_iSup {s : Set α} : sSup s = ⨆ a ∈ s, a :=
le_antisymm (sSup_le le_iSup₂) (iSup₂_le fun _ => le_sSup)
theorem sInf_eq_iInf {s : Set α} : sInf s = ⨅ a ∈ s, a :=
@sSup_eq_iSup αᵒᵈ _ _
theorem Monotone.le_map_iSup [CompleteLattice β] {f : α → β} (hf : Monotone f) :
⨆ i, f (s i) ≤ f (iSup s) :=
iSup_le fun _ => hf <| le_iSup _ _
theorem Antitone.le_map_iInf [CompleteLattice β] {f : α → β} (hf : Antitone f) :
⨆ i, f (s i) ≤ f (iInf s) :=
hf.dual_left.le_map_iSup
theorem Monotone.le_map_iSup₂ [CompleteLattice β] {f : α → β} (hf : Monotone f) (s : ∀ i, κ i → α) :
⨆ (i) (j), f (s i j) ≤ f (⨆ (i) (j), s i j) :=
iSup₂_le fun _ _ => hf <| le_iSup₂ _ _
theorem Antitone.le_map_iInf₂ [CompleteLattice β] {f : α → β} (hf : Antitone f) (s : ∀ i, κ i → α) :
⨆ (i) (j), f (s i j) ≤ f (⨅ (i) (j), s i j) :=
hf.dual_left.le_map_iSup₂ _
theorem Monotone.le_map_sSup [CompleteLattice β] {s : Set α} {f : α → β} (hf : Monotone f) :
⨆ a ∈ s, f a ≤ f (sSup s) := by rw [sSup_eq_iSup]; exact hf.le_map_iSup₂ _
theorem Antitone.le_map_sInf [CompleteLattice β] {s : Set α} {f : α → β} (hf : Antitone f) :
⨆ a ∈ s, f a ≤ f (sInf s) :=
hf.dual_left.le_map_sSup
theorem OrderIso.map_iSup [CompleteLattice β] (f : α ≃o β) (x : ι → α) :
f (⨆ i, x i) = ⨆ i, f (x i) :=
eq_of_forall_ge_iff <| f.surjective.forall.2
fun x => by simp only [f.le_iff_le, iSup_le_iff]
theorem OrderIso.map_iInf [CompleteLattice β] (f : α ≃o β) (x : ι → α) :
f (⨅ i, x i) = ⨅ i, f (x i) :=
OrderIso.map_iSup f.dual _
theorem OrderIso.map_sSup [CompleteLattice β] (f : α ≃o β) (s : Set α) :
f (sSup s) = ⨆ a ∈ s, f a := by
simp only [sSup_eq_iSup, OrderIso.map_iSup]
theorem OrderIso.map_sInf [CompleteLattice β] (f : α ≃o β) (s : Set α) :
f (sInf s) = ⨅ a ∈ s, f a :=
OrderIso.map_sSup f.dual _
theorem iSup_comp_le {ι' : Sort*} (f : ι' → α) (g : ι → ι') : ⨆ x, f (g x) ≤ ⨆ y, f y :=
iSup_mono' fun _ => ⟨_, le_rfl⟩
theorem le_iInf_comp {ι' : Sort*} (f : ι' → α) (g : ι → ι') : ⨅ y, f y ≤ ⨅ x, f (g x) :=
iInf_mono' fun _ => ⟨_, le_rfl⟩
theorem Monotone.iSup_comp_eq [Preorder β] {f : β → α} (hf : Monotone f) {s : ι → β}
(hs : ∀ x, ∃ i, x ≤ s i) : ⨆ x, f (s x) = ⨆ y, f y :=
le_antisymm (iSup_comp_le _ _) (iSup_mono' fun x => (hs x).imp fun _ hi => hf hi)
theorem Monotone.iInf_comp_eq [Preorder β] {f : β → α} (hf : Monotone f) {s : ι → β}
(hs : ∀ x, ∃ i, s i ≤ x) : ⨅ x, f (s x) = ⨅ y, f y :=
le_antisymm (iInf_mono' fun x => (hs x).imp fun _ hi => hf hi) (le_iInf_comp _ _)
theorem Antitone.map_iSup_le [CompleteLattice β] {f : α → β} (hf : Antitone f) :
f (iSup s) ≤ ⨅ i, f (s i) :=
le_iInf fun _ => hf <| le_iSup _ _
theorem Monotone.map_iInf_le [CompleteLattice β] {f : α → β} (hf : Monotone f) :
f (iInf s) ≤ ⨅ i, f (s i) :=
hf.dual_left.map_iSup_le
theorem Antitone.map_iSup₂_le [CompleteLattice β] {f : α → β} (hf : Antitone f) (s : ∀ i, κ i → α) :
f (⨆ (i) (j), s i j) ≤ ⨅ (i) (j), f (s i j) :=
hf.dual.le_map_iInf₂ _
theorem Monotone.map_iInf₂_le [CompleteLattice β] {f : α → β} (hf : Monotone f) (s : ∀ i, κ i → α) :
f (⨅ (i) (j), s i j) ≤ ⨅ (i) (j), f (s i j) :=
hf.dual.le_map_iSup₂ _
theorem Antitone.map_sSup_le [CompleteLattice β] {s : Set α} {f : α → β} (hf : Antitone f) :
f (sSup s) ≤ ⨅ a ∈ s, f a := by
rw [sSup_eq_iSup]
exact hf.map_iSup₂_le _
theorem Monotone.map_sInf_le [CompleteLattice β] {s : Set α} {f : α → β} (hf : Monotone f) :
f (sInf s) ≤ ⨅ a ∈ s, f a :=
hf.dual_left.map_sSup_le
theorem iSup_const_le : ⨆ _ : ι, a ≤ a :=
iSup_le fun _ => le_rfl
theorem le_iInf_const : a ≤ ⨅ _ : ι, a :=
le_iInf fun _ => le_rfl
-- We generalize this to conditionally complete lattices in `ciSup_const` and `ciInf_const`.
theorem iSup_const [Nonempty ι] : ⨆ _ : ι, a = a := by rw [iSup, range_const, sSup_singleton]
theorem iInf_const [Nonempty ι] : ⨅ _ : ι, a = a :=
@iSup_const αᵒᵈ _ _ a _
lemma iSup_unique [Unique ι] (f : ι → α) : ⨆ i, f i = f default := by
simp only [congr_arg f (Unique.eq_default _), iSup_const]
lemma iInf_unique [Unique ι] (f : ι → α) : ⨅ i, f i = f default := by
simp only [congr_arg f (Unique.eq_default _), iInf_const]
@[simp]
theorem iSup_bot : (⨆ _ : ι, ⊥ : α) = ⊥ :=
bot_unique iSup_const_le
@[simp]
theorem iInf_top : (⨅ _ : ι, ⊤ : α) = ⊤ :=
top_unique le_iInf_const
@[simp]
theorem iSup_eq_bot : iSup s = ⊥ ↔ ∀ i, s i = ⊥ :=
sSup_eq_bot.trans forall_mem_range
@[simp]
theorem iInf_eq_top : iInf s = ⊤ ↔ ∀ i, s i = ⊤ :=
sInf_eq_top.trans forall_mem_range
theorem iSup₂_eq_bot {f : ∀ i, κ i → α} : ⨆ (i) (j), f i j = ⊥ ↔ ∀ i j, f i j = ⊥ := by
simp
theorem iInf₂_eq_top {f : ∀ i, κ i → α} : ⨅ (i) (j), f i j = ⊤ ↔ ∀ i j, f i j = ⊤ := by
simp
@[simp]
theorem iSup_pos {p : Prop} {f : p → α} (hp : p) : ⨆ h : p, f h = f hp :=
le_antisymm (iSup_le fun _ => le_rfl) (le_iSup _ _)
@[simp]
theorem iInf_pos {p : Prop} {f : p → α} (hp : p) : ⨅ h : p, f h = f hp :=
le_antisymm (iInf_le _ _) (le_iInf fun _ => le_rfl)
@[simp]
theorem iSup_neg {p : Prop} {f : p → α} (hp : ¬p) : ⨆ h : p, f h = ⊥ :=
le_antisymm (iSup_le fun h => (hp h).elim) bot_le
@[simp]
theorem iInf_neg {p : Prop} {f : p → α} (hp : ¬p) : ⨅ h : p, f h = ⊤ :=
le_antisymm le_top <| le_iInf fun h => (hp h).elim
/-- Introduction rule to prove that `b` is the supremum of `f`: it suffices to check that `b`
is larger than `f i` for all `i`, and that this is not the case of any `w<b`.
See `ciSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in conditionally complete
lattices. -/
theorem iSup_eq_of_forall_le_of_forall_lt_exists_gt {f : ι → α} (h₁ : ∀ i, f i ≤ b)
(h₂ : ∀ w, w < b → ∃ i, w < f i) : ⨆ i : ι, f i = b :=
sSup_eq_of_forall_le_of_forall_lt_exists_gt (forall_mem_range.mpr h₁) fun w hw =>
exists_range_iff.mpr <| h₂ w hw
/-- Introduction rule to prove that `b` is the infimum of `f`: it suffices to check that `b`
is smaller than `f i` for all `i`, and that this is not the case of any `w>b`.
See `ciInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in conditionally complete
lattices. -/
theorem iInf_eq_of_forall_ge_of_forall_gt_exists_lt :
(∀ i, b ≤ f i) → (∀ w, b < w → ∃ i, f i < w) → ⨅ i, f i = b :=
@iSup_eq_of_forall_le_of_forall_lt_exists_gt αᵒᵈ _ _ _ _
theorem iSup_eq_dif {p : Prop} [Decidable p] (a : p → α) :
⨆ h : p, a h = if h : p then a h else ⊥ := by by_cases h : p <;> simp [h]
theorem iSup_eq_if {p : Prop} [Decidable p] (a : α) : ⨆ _ : p, a = if p then a else ⊥ :=
iSup_eq_dif fun _ => a
theorem iInf_eq_dif {p : Prop} [Decidable p] (a : p → α) :
⨅ h : p, a h = if h : p then a h else ⊤ :=
@iSup_eq_dif αᵒᵈ _ _ _ _
theorem iInf_eq_if {p : Prop} [Decidable p] (a : α) : ⨅ _ : p, a = if p then a else ⊤ :=
iInf_eq_dif fun _ => a
theorem iSup_comm {f : ι → ι' → α} : ⨆ (i) (j), f i j = ⨆ (j) (i), f i j :=
le_antisymm (iSup_le fun i => iSup_mono fun j => le_iSup (fun i => f i j) i)
(iSup_le fun _ => iSup_mono fun _ => le_iSup _ _)
theorem iInf_comm {f : ι → ι' → α} : ⨅ (i) (j), f i j = ⨅ (j) (i), f i j :=
@iSup_comm αᵒᵈ _ _ _ _
theorem iSup₂_comm {ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*}
(f : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → α) :
⨆ (i₁) (j₁) (i₂) (j₂), f i₁ j₁ i₂ j₂ = ⨆ (i₂) (j₂) (i₁) (j₁), f i₁ j₁ i₂ j₂ := by
simp only [@iSup_comm _ (κ₁ _), @iSup_comm _ ι₁]
theorem iInf₂_comm {ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*}
(f : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → α) :
⨅ (i₁) (j₁) (i₂) (j₂), f i₁ j₁ i₂ j₂ = ⨅ (i₂) (j₂) (i₁) (j₁), f i₁ j₁ i₂ j₂ := by
simp only [@iInf_comm _ (κ₁ _), @iInf_comm _ ι₁]
/- TODO: this is strange. In the proof below, we get exactly the desired
among the equalities, but close does not get it.
begin
apply @le_antisymm,
simp, intros,
begin [smt]
ematch, ematch, ematch, trace_state, have := le_refl (f i_1 i),
trace_state, close
end
end
-/
@[simp]
theorem iSup_iSup_eq_left {b : β} {f : ∀ x : β, x = b → α} : ⨆ x, ⨆ h : x = b, f x h = f b rfl :=
(@le_iSup₂ _ _ _ _ f b rfl).antisymm'
(iSup_le fun c =>
iSup_le <| by
rintro rfl
rfl)
@[simp]
theorem iInf_iInf_eq_left {b : β} {f : ∀ x : β, x = b → α} : ⨅ x, ⨅ h : x = b, f x h = f b rfl :=
@iSup_iSup_eq_left αᵒᵈ _ _ _ _
@[simp]
theorem iSup_iSup_eq_right {b : β} {f : ∀ x : β, b = x → α} : ⨆ x, ⨆ h : b = x, f x h = f b rfl :=
(le_iSup₂ b rfl).antisymm'
(iSup₂_le fun c => by
rintro rfl
rfl)
@[simp]
theorem iInf_iInf_eq_right {b : β} {f : ∀ x : β, b = x → α} : ⨅ x, ⨅ h : b = x, f x h = f b rfl :=
@iSup_iSup_eq_right αᵒᵈ _ _ _ _
theorem iSup_subtype {p : ι → Prop} {f : Subtype p → α} : iSup f = ⨆ (i) (h : p i), f ⟨i, h⟩ :=
le_antisymm (iSup_le fun ⟨i, h⟩ => @le_iSup₂ _ _ p _ (fun i h => f ⟨i, h⟩) i h)
(iSup₂_le fun _ _ => le_iSup _ _)
theorem iInf_subtype : ∀ {p : ι → Prop} {f : Subtype p → α}, iInf f = ⨅ (i) (h : p i), f ⟨i, h⟩ :=
@iSup_subtype αᵒᵈ _ _
theorem iSup_subtype' {p : ι → Prop} {f : ∀ i, p i → α} :
⨆ (i) (h), f i h = ⨆ x : Subtype p, f x x.property :=
(@iSup_subtype _ _ _ p fun x => f x.val x.property).symm
theorem iInf_subtype' {p : ι → Prop} {f : ∀ i, p i → α} :
⨅ (i) (h : p i), f i h = ⨅ x : Subtype p, f x x.property :=
(@iInf_subtype _ _ _ p fun x => f x.val x.property).symm
theorem iSup_subtype'' {ι} (s : Set ι) (f : ι → α) : ⨆ i : s, f i = ⨆ (t : ι) (_ : t ∈ s), f t :=
iSup_subtype
theorem iInf_subtype'' {ι} (s : Set ι) (f : ι → α) : ⨅ i : s, f i = ⨅ (t : ι) (_ : t ∈ s), f t :=
iInf_subtype
theorem biSup_const {ι : Sort _} {a : α} {s : Set ι} (hs : s.Nonempty) : ⨆ i ∈ s, a = a := by
haveI : Nonempty s := Set.nonempty_coe_sort.mpr hs
rw [← iSup_subtype'', iSup_const]
theorem biInf_const {ι : Sort _} {a : α} {s : Set ι} (hs : s.Nonempty) : ⨅ i ∈ s, a = a :=
@biSup_const αᵒᵈ _ ι _ s hs
theorem iSup_sup_eq : ⨆ x, f x ⊔ g x = (⨆ x, f x) ⊔ ⨆ x, g x :=
le_antisymm (iSup_le fun _ => sup_le_sup (le_iSup _ _) <| le_iSup _ _)
(sup_le (iSup_mono fun _ => le_sup_left) <| iSup_mono fun _ => le_sup_right)
theorem iInf_inf_eq : ⨅ x, f x ⊓ g x = (⨅ x, f x) ⊓ ⨅ x, g x :=
@iSup_sup_eq αᵒᵈ _ _ _ _
lemma Equiv.biSup_comp {ι ι' : Type*} {g : ι' → α} (e : ι ≃ ι') (s : Set ι') :
⨆ i ∈ e.symm '' s, g (e i) = ⨆ i ∈ s, g i := by
simpa only [iSup_subtype'] using (image e.symm s).symm.iSup_comp (g := g ∘ (↑))
lemma Equiv.biInf_comp {ι ι' : Type*} {g : ι' → α} (e : ι ≃ ι') (s : Set ι') :
⨅ i ∈ e.symm '' s, g (e i) = ⨅ i ∈ s, g i :=
e.biSup_comp s (α := αᵒᵈ)
lemma biInf_le {ι : Type*} {s : Set ι} (f : ι → α) {i : ι} (hi : i ∈ s) :
⨅ i ∈ s, f i ≤ f i := by
simpa only [iInf_subtype'] using iInf_le (ι := s) (f := f ∘ (↑)) ⟨i, hi⟩
lemma le_biSup {ι : Type*} {s : Set ι} (f : ι → α) {i : ι} (hi : i ∈ s) :
f i ≤ ⨆ i ∈ s, f i :=
biInf_le (α := αᵒᵈ) f hi
/- TODO: here is another example where more flexible pattern matching
might help.
begin
apply @le_antisymm,
safe, pose h := f a ⊓ g a, begin [smt] ematch, ematch end
end
-/
theorem iSup_sup [Nonempty ι] {f : ι → α} {a : α} : (⨆ x, f x) ⊔ a = ⨆ x, f x ⊔ a := by
rw [iSup_sup_eq, iSup_const]
theorem iInf_inf [Nonempty ι] {f : ι → α} {a : α} : (⨅ x, f x) ⊓ a = ⨅ x, f x ⊓ a := by
rw [iInf_inf_eq, iInf_const]
theorem sup_iSup [Nonempty ι] {f : ι → α} {a : α} : (a ⊔ ⨆ x, f x) = ⨆ x, a ⊔ f x := by
rw [iSup_sup_eq, iSup_const]
theorem inf_iInf [Nonempty ι] {f : ι → α} {a : α} : (a ⊓ ⨅ x, f x) = ⨅ x, a ⊓ f x := by
rw [iInf_inf_eq, iInf_const]
theorem biSup_sup {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) :
(⨆ (i) (h : p i), f i h) ⊔ a = ⨆ (i) (h : p i), f i h ⊔ a := by
haveI : Nonempty { i // p i } :=
let ⟨i, hi⟩ := h
⟨⟨i, hi⟩⟩
rw [iSup_subtype', iSup_subtype', iSup_sup]
theorem sup_biSup {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) :
(a ⊔ ⨆ (i) (h : p i), f i h) = ⨆ (i) (h : p i), a ⊔ f i h := by
simpa only [sup_comm] using @biSup_sup α _ _ p _ _ h
theorem biInf_inf {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) :
(⨅ (i) (h : p i), f i h) ⊓ a = ⨅ (i) (h : p i), f i h ⊓ a :=
@biSup_sup αᵒᵈ ι _ p f _ h
theorem inf_biInf {p : ι → Prop} {f : ∀ i, p i → α} {a : α} (h : ∃ i, p i) :
(a ⊓ ⨅ (i) (h : p i), f i h) = ⨅ (i) (h : p i), a ⊓ f i h :=
@sup_biSup αᵒᵈ ι _ p f _ h
/-! ### `iSup` and `iInf` under `Prop` -/
theorem iSup_false {s : False → α} : iSup s = ⊥ := by simp
theorem iInf_false {s : False → α} : iInf s = ⊤ := by simp
theorem iSup_true {s : True → α} : iSup s = s trivial :=
iSup_pos trivial
theorem iInf_true {s : True → α} : iInf s = s trivial :=
iInf_pos trivial
@[simp]
theorem iSup_exists {p : ι → Prop} {f : Exists p → α} : ⨆ x, f x = ⨆ (i) (h), f ⟨i, h⟩ :=
le_antisymm (iSup_le fun ⟨i, h⟩ => @le_iSup₂ _ _ _ _ (fun _ _ => _) i h)
(iSup₂_le fun _ _ => le_iSup _ _)
@[simp]
theorem iInf_exists {p : ι → Prop} {f : Exists p → α} : ⨅ x, f x = ⨅ (i) (h), f ⟨i, h⟩ :=
@iSup_exists αᵒᵈ _ _ _ _
theorem iSup_and {p q : Prop} {s : p ∧ q → α} : iSup s = ⨆ (h₁) (h₂), s ⟨h₁, h₂⟩ :=
le_antisymm (iSup_le fun ⟨i, h⟩ => @le_iSup₂ _ _ _ _ (fun _ _ => _) i h)
(iSup₂_le fun _ _ => le_iSup _ _)
theorem iInf_and {p q : Prop} {s : p ∧ q → α} : iInf s = ⨅ (h₁) (h₂), s ⟨h₁, h₂⟩ :=
@iSup_and αᵒᵈ _ _ _ _
/-- The symmetric case of `iSup_and`, useful for rewriting into a supremum over a conjunction -/
theorem iSup_and' {p q : Prop} {s : p → q → α} :
⨆ (h₁ : p) (h₂ : q), s h₁ h₂ = ⨆ h : p ∧ q, s h.1 h.2 :=
Eq.symm iSup_and
/-- The symmetric case of `iInf_and`, useful for rewriting into an infimum over a conjunction -/
theorem iInf_and' {p q : Prop} {s : p → q → α} :
⨅ (h₁ : p) (h₂ : q), s h₁ h₂ = ⨅ h : p ∧ q, s h.1 h.2 :=
Eq.symm iInf_and
theorem iSup_or {p q : Prop} {s : p ∨ q → α} :
⨆ x, s x = (⨆ i, s (Or.inl i)) ⊔ ⨆ j, s (Or.inr j) :=
le_antisymm
(iSup_le fun i =>
match i with
| Or.inl _ => le_sup_of_le_left <| le_iSup (fun _ => s _) _
| Or.inr _ => le_sup_of_le_right <| le_iSup (fun _ => s _) _)
(sup_le (iSup_comp_le _ _) (iSup_comp_le _ _))
theorem iInf_or {p q : Prop} {s : p ∨ q → α} :
⨅ x, s x = (⨅ i, s (Or.inl i)) ⊓ ⨅ j, s (Or.inr j) :=
@iSup_or αᵒᵈ _ _ _ _
section
variable (p : ι → Prop) [DecidablePred p]
theorem iSup_dite (f : ∀ i, p i → α) (g : ∀ i, ¬p i → α) :
⨆ i, (if h : p i then f i h else g i h) = (⨆ (i) (h : p i), f i h) ⊔ ⨆ (i) (h : ¬p i),
g i h := by
rw [← iSup_sup_eq]
congr 1 with i
split_ifs with h <;> simp [h]
theorem iInf_dite (f : ∀ i, p i → α) (g : ∀ i, ¬p i → α) :
⨅ i, (if h : p i then f i h else g i h) = (⨅ (i) (h : p i), f i h) ⊓ ⨅ (i) (h : ¬p i), g i h :=
iSup_dite p (show ∀ i, p i → αᵒᵈ from f) g
theorem iSup_ite (f g : ι → α) :
⨆ i, (if p i then f i else g i) = (⨆ (i) (_ : p i), f i) ⊔ ⨆ (i) (_ : ¬p i), g i :=
iSup_dite _ _ _
theorem iInf_ite (f g : ι → α) :
⨅ i, (if p i then f i else g i) = (⨅ (i) (_ : p i), f i) ⊓ ⨅ (i) (_ : ¬p i), g i :=
iInf_dite _ _ _
end
theorem iSup_range {g : β → α} {f : ι → β} : ⨆ b ∈ range f, g b = ⨆ i, g (f i) := by
rw [← iSup_subtype'', iSup_range']
theorem iInf_range : ∀ {g : β → α} {f : ι → β}, ⨅ b ∈ range f, g b = ⨅ i, g (f i) :=
@iSup_range αᵒᵈ _ _ _
theorem sSup_image {s : Set β} {f : β → α} : sSup (f '' s) = ⨆ a ∈ s, f a := by
rw [← iSup_subtype'', sSup_image']
theorem sInf_image {s : Set β} {f : β → α} : sInf (f '' s) = ⨅ a ∈ s, f a :=
@sSup_image αᵒᵈ _ _ _ _
theorem OrderIso.map_sSup_eq_sSup_symm_preimage [CompleteLattice β] (f : α ≃o β) (s : Set α) :
f (sSup s) = sSup (f.symm ⁻¹' s) := by
rw [map_sSup, ← sSup_image, f.image_eq_preimage]
theorem OrderIso.map_sInf_eq_sInf_symm_preimage [CompleteLattice β] (f : α ≃o β) (s : Set α) :
f (sInf s) = sInf (f.symm ⁻¹' s) := by
rw [map_sInf, ← sInf_image, f.image_eq_preimage]
/-
### iSup and iInf under set constructions
-/
theorem iSup_emptyset {f : β → α} : ⨆ x ∈ (∅ : Set β), f x = ⊥ := by simp
theorem iInf_emptyset {f : β → α} : ⨅ x ∈ (∅ : Set β), f x = ⊤ := by simp
theorem iSup_univ {f : β → α} : ⨆ x ∈ (univ : Set β), f x = ⨆ x, f x := by simp
theorem iInf_univ {f : β → α} : ⨅ x ∈ (univ : Set β), f x = ⨅ x, f x := by simp
theorem iSup_union {f : β → α} {s t : Set β} :
⨆ x ∈ s ∪ t, f x = (⨆ x ∈ s, f x) ⊔ ⨆ x ∈ t, f x := by
simp_rw [mem_union, iSup_or, iSup_sup_eq]
theorem iInf_union {f : β → α} {s t : Set β} : ⨅ x ∈ s ∪ t, f x = (⨅ x ∈ s, f x) ⊓ ⨅ x ∈ t, f x :=
@iSup_union αᵒᵈ _ _ _ _ _
theorem iSup_split (f : β → α) (p : β → Prop) :
⨆ i, f i = (⨆ (i) (_ : p i), f i) ⊔ ⨆ (i) (_ : ¬p i), f i := by
simpa [Classical.em] using @iSup_union _ _ _ f { i | p i } { i | ¬p i }
theorem iInf_split :
∀ (f : β → α) (p : β → Prop), ⨅ i, f i = (⨅ (i) (_ : p i), f i) ⊓ ⨅ (i) (_ : ¬p i), f i :=
@iSup_split αᵒᵈ _ _
theorem iSup_split_single (f : β → α) (i₀ : β) : ⨆ i, f i = f i₀ ⊔ ⨆ (i) (_ : i ≠ i₀), f i := by
convert iSup_split f (fun i => i = i₀)
simp
theorem iInf_split_single (f : β → α) (i₀ : β) : ⨅ i, f i = f i₀ ⊓ ⨅ (i) (_ : i ≠ i₀), f i :=
@iSup_split_single αᵒᵈ _ _ _ _
theorem iSup_le_iSup_of_subset {f : β → α} {s t : Set β} : s ⊆ t → ⨆ x ∈ s, f x ≤ ⨆ x ∈ t, f x :=
biSup_mono
theorem iInf_le_iInf_of_subset {f : β → α} {s t : Set β} : s ⊆ t → ⨅ x ∈ t, f x ≤ ⨅ x ∈ s, f x :=
biInf_mono
theorem iSup_insert {f : β → α} {s : Set β} {b : β} :
⨆ x ∈ insert b s, f x = f b ⊔ ⨆ x ∈ s, f x :=
Eq.trans iSup_union <| congr_arg (fun x => x ⊔ ⨆ x ∈ s, f x) iSup_iSup_eq_left
theorem iInf_insert {f : β → α} {s : Set β} {b : β} :
⨅ x ∈ insert b s, f x = f b ⊓ ⨅ x ∈ s, f x :=
Eq.trans iInf_union <| congr_arg (fun x => x ⊓ ⨅ x ∈ s, f x) iInf_iInf_eq_left
theorem iSup_singleton {f : β → α} {b : β} : ⨆ x ∈ (singleton b : Set β), f x = f b := by simp
theorem iInf_singleton {f : β → α} {b : β} : ⨅ x ∈ (singleton b : Set β), f x = f b := by simp
theorem iSup_pair {f : β → α} {a b : β} : ⨆ x ∈ ({a, b} : Set β), f x = f a ⊔ f b := by
rw [iSup_insert, iSup_singleton]
theorem iInf_pair {f : β → α} {a b : β} : ⨅ x ∈ ({a, b} : Set β), f x = f a ⊓ f b := by
rw [iInf_insert, iInf_singleton]
theorem iSup_image {γ} {f : β → γ} {g : γ → α} {t : Set β} :
⨆ c ∈ f '' t, g c = ⨆ b ∈ t, g (f b) := by rw [← sSup_image, ← sSup_image, ← image_comp]; rfl
theorem iInf_image :
∀ {γ} {f : β → γ} {g : γ → α} {t : Set β}, ⨅ c ∈ f '' t, g c = ⨅ b ∈ t, g (f b) :=
@iSup_image αᵒᵈ _ _
theorem iSup_extend_bot {e : ι → β} (he : Injective e) (f : ι → α) :
⨆ j, extend e f ⊥ j = ⨆ i, f i := by
rw [iSup_split _ fun j => ∃ i, e i = j]
simp (config := { contextual := true }) [he.extend_apply, extend_apply', @iSup_comm _ β ι]
theorem iInf_extend_top {e : ι → β} (he : Injective e) (f : ι → α) :
⨅ j, extend e f ⊤ j = iInf f :=
@iSup_extend_bot αᵒᵈ _ _ _ _ he _
/-!
### `iSup` and `iInf` under `Type`
-/
theorem iSup_of_empty' {α ι} [SupSet α] [IsEmpty ι] (f : ι → α) : iSup f = sSup (∅ : Set α) :=
congr_arg sSup (range_eq_empty f)
theorem iInf_of_isEmpty {α ι} [InfSet α] [IsEmpty ι] (f : ι → α) : iInf f = sInf (∅ : Set α) :=
congr_arg sInf (range_eq_empty f)
theorem iSup_of_empty [IsEmpty ι] (f : ι → α) : iSup f = ⊥ :=
(iSup_of_empty' f).trans sSup_empty
theorem iInf_of_empty [IsEmpty ι] (f : ι → α) : iInf f = ⊤ :=
@iSup_of_empty αᵒᵈ _ _ _ f
theorem iSup_bool_eq {f : Bool → α} : ⨆ b : Bool, f b = f true ⊔ f false := by
rw [iSup, Bool.range_eq, sSup_pair, sup_comm]
theorem iInf_bool_eq {f : Bool → α} : ⨅ b : Bool, f b = f true ⊓ f false :=
@iSup_bool_eq αᵒᵈ _ _
theorem sup_eq_iSup (x y : α) : x ⊔ y = ⨆ b : Bool, cond b x y := by
rw [iSup_bool_eq, Bool.cond_true, Bool.cond_false]
theorem inf_eq_iInf (x y : α) : x ⊓ y = ⨅ b : Bool, cond b x y :=
@sup_eq_iSup αᵒᵈ _ _ _
theorem isGLB_biInf {s : Set β} {f : β → α} : IsGLB (f '' s) (⨅ x ∈ s, f x) := by
simpa only [range_comp, Subtype.range_coe, iInf_subtype'] using
@isGLB_iInf α s _ (f ∘ fun x => (x : β))
theorem isLUB_biSup {s : Set β} {f : β → α} : IsLUB (f '' s) (⨆ x ∈ s, f x) := by
simpa only [range_comp, Subtype.range_coe, iSup_subtype'] using
@isLUB_iSup α s _ (f ∘ fun x => (x : β))
theorem iSup_sigma {p : β → Type*} {f : Sigma p → α} : ⨆ x, f x = ⨆ (i) (j), f ⟨i, j⟩ :=
eq_of_forall_ge_iff fun c => by simp only [iSup_le_iff, Sigma.forall]
theorem iInf_sigma {p : β → Type*} {f : Sigma p → α} : ⨅ x, f x = ⨅ (i) (j), f ⟨i, j⟩ :=
@iSup_sigma αᵒᵈ _ _ _ _
lemma iSup_sigma' {κ : β → Type*} (f : ∀ i, κ i → α) :
(⨆ i, ⨆ j, f i j) = ⨆ x : Σ i, κ i, f x.1 x.2 :=
(iSup_sigma (f := fun x ↦ f x.1 x.2)).symm
lemma iInf_sigma' {κ : β → Type*} (f : ∀ i, κ i → α) :
(⨅ i, ⨅ j, f i j) = ⨅ x : Σ i, κ i, f x.1 x.2 :=
(iInf_sigma (f := fun x ↦ f x.1 x.2)).symm
theorem iSup_prod {f : β × γ → α} : ⨆ x, f x = ⨆ (i) (j), f (i, j) :=
eq_of_forall_ge_iff fun c => by simp only [iSup_le_iff, Prod.forall]
theorem iInf_prod {f : β × γ → α} : ⨅ x, f x = ⨅ (i) (j), f (i, j) :=
@iSup_prod αᵒᵈ _ _ _ _
lemma iSup_prod' (f : β → γ → α) : (⨆ i, ⨆ j, f i j) = ⨆ x : β × γ, f x.1 x.2 :=
(iSup_prod (f := fun x ↦ f x.1 x.2)).symm
lemma iInf_prod' (f : β → γ → α) : (⨅ i, ⨅ j, f i j) = ⨅ x : β × γ, f x.1 x.2 :=
(iInf_prod (f := fun x ↦ f x.1 x.2)).symm
theorem biSup_prod {f : β × γ → α} {s : Set β} {t : Set γ} :
⨆ x ∈ s ×ˢ t, f x = ⨆ (a ∈ s) (b ∈ t), f (a, b) := by
simp_rw [iSup_prod, mem_prod, iSup_and]
exact iSup_congr fun _ => iSup_comm
theorem biInf_prod {f : β × γ → α} {s : Set β} {t : Set γ} :
⨅ x ∈ s ×ˢ t, f x = ⨅ (a ∈ s) (b ∈ t), f (a, b) :=
@biSup_prod αᵒᵈ _ _ _ _ _ _
theorem iSup_sum {f : β ⊕ γ → α} : ⨆ x, f x = (⨆ i, f (Sum.inl i)) ⊔ ⨆ j, f (Sum.inr j) :=
eq_of_forall_ge_iff fun c => by simp only [sup_le_iff, iSup_le_iff, Sum.forall]
theorem iInf_sum {f : β ⊕ γ → α} : ⨅ x, f x = (⨅ i, f (Sum.inl i)) ⊓ ⨅ j, f (Sum.inr j) :=
@iSup_sum αᵒᵈ _ _ _ _
theorem iSup_option (f : Option β → α) : ⨆ o, f o = f none ⊔ ⨆ b, f (Option.some b) :=
eq_of_forall_ge_iff fun c => by simp only [iSup_le_iff, sup_le_iff, Option.forall]
theorem iInf_option (f : Option β → α) : ⨅ o, f o = f none ⊓ ⨅ b, f (Option.some b) :=
@iSup_option αᵒᵈ _ _ _
/-- A version of `iSup_option` useful for rewriting right-to-left. -/
theorem iSup_option_elim (a : α) (f : β → α) : ⨆ o : Option β, o.elim a f = a ⊔ ⨆ b, f b := by
simp [iSup_option]
/-- A version of `iInf_option` useful for rewriting right-to-left. -/
theorem iInf_option_elim (a : α) (f : β → α) : ⨅ o : Option β, o.elim a f = a ⊓ ⨅ b, f b :=
@iSup_option_elim αᵒᵈ _ _ _ _
/-- When taking the supremum of `f : ι → α`, the elements of `ι` on which `f` gives `⊥` can be
dropped, without changing the result. -/
@[simp]
theorem iSup_ne_bot_subtype (f : ι → α) : ⨆ i : { i // f i ≠ ⊥ }, f i = ⨆ i, f i := by
by_cases htriv : ∀ i, f i = ⊥
· simp only [iSup_bot, (funext htriv : f = _)]
refine (iSup_comp_le f _).antisymm (iSup_mono' fun i => ?_)
by_cases hi : f i = ⊥
· rw [hi]
obtain ⟨i₀, hi₀⟩ := not_forall.mp htriv
exact ⟨⟨i₀, hi₀⟩, bot_le⟩
· exact ⟨⟨i, hi⟩, rfl.le⟩
/-- When taking the infimum of `f : ι → α`, the elements of `ι` on which `f` gives `⊤` can be
dropped, without changing the result. -/
theorem iInf_ne_top_subtype (f : ι → α) : ⨅ i : { i // f i ≠ ⊤ }, f i = ⨅ i, f i :=
@iSup_ne_bot_subtype αᵒᵈ ι _ f
theorem sSup_image2 {f : β → γ → α} {s : Set β} {t : Set γ} :
sSup (image2 f s t) = ⨆ (a ∈ s) (b ∈ t), f a b := by rw [← image_prod, sSup_image, biSup_prod]
theorem sInf_image2 {f : β → γ → α} {s : Set β} {t : Set γ} :
sInf (image2 f s t) = ⨅ (a ∈ s) (b ∈ t), f a b := by rw [← image_prod, sInf_image, biInf_prod]
/-!
### `iSup` and `iInf` under `ℕ`
-/
theorem iSup_ge_eq_iSup_nat_add (u : ℕ → α) (n : ℕ) : ⨆ i ≥ n, u i = ⨆ i, u (i + n) := by
apply le_antisymm <;> simp only [iSup_le_iff]
· refine fun i hi => le_sSup ⟨i - n, ?_⟩
dsimp only
rw [Nat.sub_add_cancel hi]
· exact fun i => le_sSup ⟨i + n, iSup_pos (Nat.le_add_left _ _)⟩
theorem iInf_ge_eq_iInf_nat_add (u : ℕ → α) (n : ℕ) : ⨅ i ≥ n, u i = ⨅ i, u (i + n) :=
@iSup_ge_eq_iSup_nat_add αᵒᵈ _ _ _
theorem Monotone.iSup_nat_add {f : ℕ → α} (hf : Monotone f) (k : ℕ) : ⨆ n, f (n + k) = ⨆ n, f n :=
le_antisymm (iSup_le fun i => le_iSup _ (i + k)) <| iSup_mono fun i => hf <| Nat.le_add_right i k
theorem Antitone.iInf_nat_add {f : ℕ → α} (hf : Antitone f) (k : ℕ) : ⨅ n, f (n + k) = ⨅ n, f n :=
hf.dual_right.iSup_nat_add k
-- Porting note: the linter doesn't like this being marked as `@[simp]`,
-- saying that it doesn't work when called on its LHS.
-- Mysteriously, it *does* work. Nevertheless, per
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/complete_lattice.20and.20has_sup/near/316497982
-- "the subterm ?f (i + ?k) produces an ugly higher-order unification problem."
-- @[simp]
theorem iSup_iInf_ge_nat_add (f : ℕ → α) (k : ℕ) :
⨆ n, ⨅ i ≥ n, f (i + k) = ⨆ n, ⨅ i ≥ n, f i := by
have hf : Monotone fun n => ⨅ i ≥ n, f i := fun n m h => biInf_mono fun i => h.trans
rw [← Monotone.iSup_nat_add hf k]
· simp_rw [iInf_ge_eq_iInf_nat_add, ← Nat.add_assoc]
-- Porting note: removing `@[simp]`, see discussion on `iSup_iInf_ge_nat_add`.
-- @[simp]
theorem iInf_iSup_ge_nat_add :
∀ (f : ℕ → α) (k : ℕ), ⨅ n, ⨆ i ≥ n, f (i + k) = ⨅ n, ⨆ i ≥ n, f i :=
@iSup_iInf_ge_nat_add αᵒᵈ _
theorem sup_iSup_nat_succ (u : ℕ → α) : (u 0 ⊔ ⨆ i, u (i + 1)) = ⨆ i, u i :=
calc
(u 0 ⊔ ⨆ i, u (i + 1)) = ⨆ x ∈ {0} ∪ range Nat.succ, u x := by
{ rw [iSup_union, iSup_singleton, iSup_range] }
_ = ⨆ i, u i := by rw [Nat.zero_union_range_succ, iSup_univ]
theorem inf_iInf_nat_succ (u : ℕ → α) : (u 0 ⊓ ⨅ i, u (i + 1)) = ⨅ i, u i :=
@sup_iSup_nat_succ αᵒᵈ _ u
theorem iInf_nat_gt_zero_eq (f : ℕ → α) : ⨅ i > 0, f i = ⨅ i, f (i + 1) := by
rw [← iInf_range, Nat.range_succ]
simp
theorem iSup_nat_gt_zero_eq (f : ℕ → α) : ⨆ i > 0, f i = ⨆ i, f (i + 1) :=
@iInf_nat_gt_zero_eq αᵒᵈ _ f
end
section CompleteLinearOrder
variable [CompleteLinearOrder α]
theorem iSup_eq_top (f : ι → α) : iSup f = ⊤ ↔ ∀ b < ⊤, ∃ i, b < f i := by
simp only [← sSup_range, sSup_eq_top, Set.exists_range_iff]
theorem iInf_eq_bot (f : ι → α) : iInf f = ⊥ ↔ ∀ b > ⊥, ∃ i, f i < b := by
simp only [← sInf_range, sInf_eq_bot, Set.exists_range_iff]
end CompleteLinearOrder
/-!
### Instances
-/
instance Prop.instCompleteLattice : CompleteLattice Prop where
__ := Prop.instBoundedOrder
__ := Prop.instDistribLattice
sSup s := ∃ a ∈ s, a
le_sSup _ a h p := ⟨a, h, p⟩
sSup_le _ _ h := fun ⟨b, h', p⟩ => h b h' p
sInf s := ∀ a, a ∈ s → a
sInf_le _ a h p := p a h
le_sInf _ _ h p b hb := h b hb p
noncomputable instance Prop.instCompleteLinearOrder : CompleteLinearOrder Prop where
__ := Prop.instCompleteLattice
__ := Prop.linearOrder
__ := BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem sSup_Prop_eq {s : Set Prop} : sSup s = ∃ p ∈ s, p :=
rfl
@[simp]
theorem sInf_Prop_eq {s : Set Prop} : sInf s = ∀ p ∈ s, p :=
rfl
@[simp]
theorem iSup_Prop_eq {p : ι → Prop} : ⨆ i, p i = ∃ i, p i :=
le_antisymm (fun ⟨_, ⟨i, (eq : p i = _)⟩, hq⟩ => ⟨i, eq.symm ▸ hq⟩) fun ⟨i, hi⟩ =>
⟨p i, ⟨i, rfl⟩, hi⟩
@[simp]
theorem iInf_Prop_eq {p : ι → Prop} : ⨅ i, p i = ∀ i, p i :=
le_antisymm (fun h i => h _ ⟨i, rfl⟩) fun h _ ⟨i, Eq⟩ => Eq ▸ h i
instance Pi.supSet {α : Type*} {β : α → Type*} [∀ i, SupSet (β i)] : SupSet (∀ i, β i) :=
⟨fun s i => ⨆ f : s, (f : ∀ i, β i) i⟩
instance Pi.infSet {α : Type*} {β : α → Type*} [∀ i, InfSet (β i)] : InfSet (∀ i, β i) :=
⟨fun s i => ⨅ f : s, (f : ∀ i, β i) i⟩
instance Pi.instCompleteLattice {α : Type*} {β : α → Type*} [∀ i, CompleteLattice (β i)] :
CompleteLattice (∀ i, β i) where
__ := instBoundedOrder
le_sSup s f hf := fun i => le_iSup (fun f : s => (f : ∀ i, β i) i) ⟨f, hf⟩
sInf_le s f hf := fun i => iInf_le (fun f : s => (f : ∀ i, β i) i) ⟨f, hf⟩
sSup_le _ _ hf := fun i => iSup_le fun g => hf g g.2 i
le_sInf _ _ hf := fun i => le_iInf fun g => hf g g.2 i
@[simp]
theorem sSup_apply {α : Type*} {β : α → Type*} [∀ i, SupSet (β i)] {s : Set (∀ a, β a)} {a : α} :
(sSup s) a = ⨆ f : s, (f : ∀ a, β a) a :=
rfl
@[simp]
theorem sInf_apply {α : Type*} {β : α → Type*} [∀ i, InfSet (β i)] {s : Set (∀ a, β a)} {a : α} :
sInf s a = ⨅ f : s, (f : ∀ a, β a) a :=
rfl
@[simp]
theorem iSup_apply {α : Type*} {β : α → Type*} {ι : Sort*} [∀ i, SupSet (β i)] {f : ι → ∀ a, β a}
{a : α} : (⨆ i, f i) a = ⨆ i, f i a := by
rw [iSup, sSup_apply, iSup, iSup, ← image_eq_range (fun f : ∀ i, β i => f a) (range f), ←
range_comp]; rfl
@[simp]
theorem iInf_apply {α : Type*} {β : α → Type*} {ι : Sort*} [∀ i, InfSet (β i)] {f : ι → ∀ a, β a}
{a : α} : (⨅ i, f i) a = ⨅ i, f i a :=
@iSup_apply α (fun i => (β i)ᵒᵈ) _ _ _ _
theorem unary_relation_sSup_iff {α : Type*} (s : Set (α → Prop)) {a : α} :
sSup s a ↔ ∃ r : α → Prop, r ∈ s ∧ r a := by
rw [sSup_apply]
simp [← eq_iff_iff]
theorem unary_relation_sInf_iff {α : Type*} (s : Set (α → Prop)) {a : α} :
sInf s a ↔ ∀ r : α → Prop, r ∈ s → r a := by
rw [sInf_apply]
simp [← eq_iff_iff]
theorem binary_relation_sSup_iff {α β : Type*} (s : Set (α → β → Prop)) {a : α} {b : β} :
sSup s a b ↔ ∃ r : α → β → Prop, r ∈ s ∧ r a b := by
rw [sSup_apply]
simp [← eq_iff_iff]
theorem binary_relation_sInf_iff {α β : Type*} (s : Set (α → β → Prop)) {a : α} {b : β} :
sInf s a b ↔ ∀ r : α → β → Prop, r ∈ s → r a b := by
rw [sInf_apply]
simp [← eq_iff_iff]
section CompleteLattice
variable {ι : Sort*} [Preorder α] [CompleteLattice β] {s : Set (α → β)} {f : ι → α → β}
protected lemma Monotone.sSup (hs : ∀ f ∈ s, Monotone f) : Monotone (sSup s) :=
fun _ _ h ↦ iSup_mono fun f ↦ hs f f.2 h
protected lemma Monotone.sInf (hs : ∀ f ∈ s, Monotone f) : Monotone (sInf s) :=
fun _ _ h ↦ iInf_mono fun f ↦ hs f f.2 h
protected lemma Antitone.sSup (hs : ∀ f ∈ s, Antitone f) : Antitone (sSup s) :=
fun _ _ h ↦ iSup_mono fun f ↦ hs f f.2 h
protected lemma Antitone.sInf (hs : ∀ f ∈ s, Antitone f) : Antitone (sInf s) :=
fun _ _ h ↦ iInf_mono fun f ↦ hs f f.2 h
@[deprecated (since := "2024-05-29")] alias monotone_sSup_of_monotone := Monotone.sSup
@[deprecated (since := "2024-05-29")] alias monotone_sInf_of_monotone := Monotone.sInf
protected lemma Monotone.iSup (hf : ∀ i, Monotone (f i)) : Monotone (⨆ i, f i) :=
Monotone.sSup (by simpa)
protected lemma Monotone.iInf (hf : ∀ i, Monotone (f i)) : Monotone (⨅ i, f i) :=
Monotone.sInf (by simpa)
protected lemma Antitone.iSup (hf : ∀ i, Antitone (f i)) : Antitone (⨆ i, f i) :=
Antitone.sSup (by simpa)
protected lemma Antitone.iInf (hf : ∀ i, Antitone (f i)) : Antitone (⨅ i, f i) :=
Antitone.sInf (by simpa)
end CompleteLattice
namespace Prod
variable (α β)
instance supSet [SupSet α] [SupSet β] : SupSet (α × β) :=
⟨fun s => (sSup (Prod.fst '' s), sSup (Prod.snd '' s))⟩
instance infSet [InfSet α] [InfSet β] : InfSet (α × β) :=
⟨fun s => (sInf (Prod.fst '' s), sInf (Prod.snd '' s))⟩
variable {α β}
theorem fst_sInf [InfSet α] [InfSet β] (s : Set (α × β)) : (sInf s).fst = sInf (Prod.fst '' s) :=
rfl
theorem snd_sInf [InfSet α] [InfSet β] (s : Set (α × β)) : (sInf s).snd = sInf (Prod.snd '' s) :=
rfl
theorem swap_sInf [InfSet α] [InfSet β] (s : Set (α × β)) : (sInf s).swap = sInf (Prod.swap '' s) :=
Prod.ext (congr_arg sInf <| image_comp Prod.fst swap s)
(congr_arg sInf <| image_comp Prod.snd swap s)
theorem fst_sSup [SupSet α] [SupSet β] (s : Set (α × β)) : (sSup s).fst = sSup (Prod.fst '' s) :=
rfl
theorem snd_sSup [SupSet α] [SupSet β] (s : Set (α × β)) : (sSup s).snd = sSup (Prod.snd '' s) :=
rfl
theorem swap_sSup [SupSet α] [SupSet β] (s : Set (α × β)) : (sSup s).swap = sSup (Prod.swap '' s) :=
Prod.ext (congr_arg sSup <| image_comp Prod.fst swap s)
(congr_arg sSup <| image_comp Prod.snd swap s)
theorem fst_iInf [InfSet α] [InfSet β] (f : ι → α × β) : (iInf f).fst = ⨅ i, (f i).fst :=
congr_arg sInf (range_comp _ _).symm
theorem snd_iInf [InfSet α] [InfSet β] (f : ι → α × β) : (iInf f).snd = ⨅ i, (f i).snd :=
congr_arg sInf (range_comp _ _).symm
theorem swap_iInf [InfSet α] [InfSet β] (f : ι → α × β) : (iInf f).swap = ⨅ i, (f i).swap := by
simp_rw [iInf, swap_sInf, ← range_comp, Function.comp] -- Porting note: need to unfold `∘`
theorem iInf_mk [InfSet α] [InfSet β] (f : ι → α) (g : ι → β) :
⨅ i, (f i, g i) = (⨅ i, f i, ⨅ i, g i) :=
congr_arg₂ Prod.mk (fst_iInf _) (snd_iInf _)
theorem fst_iSup [SupSet α] [SupSet β] (f : ι → α × β) : (iSup f).fst = ⨆ i, (f i).fst :=
congr_arg sSup (range_comp _ _).symm
theorem snd_iSup [SupSet α] [SupSet β] (f : ι → α × β) : (iSup f).snd = ⨆ i, (f i).snd :=
congr_arg sSup (range_comp _ _).symm
theorem swap_iSup [SupSet α] [SupSet β] (f : ι → α × β) : (iSup f).swap = ⨆ i, (f i).swap := by
simp_rw [iSup, swap_sSup, ← range_comp, Function.comp] -- Porting note: need to unfold `∘`
theorem iSup_mk [SupSet α] [SupSet β] (f : ι → α) (g : ι → β) :
⨆ i, (f i, g i) = (⨆ i, f i, ⨆ i, g i) :=
congr_arg₂ Prod.mk (fst_iSup _) (snd_iSup _)
instance instCompleteLattice [CompleteLattice α] [CompleteLattice β] : CompleteLattice (α × β) where
__ := instBoundedOrder α β
le_sSup _ _ hab := ⟨le_sSup <| mem_image_of_mem _ hab, le_sSup <| mem_image_of_mem _ hab⟩
sSup_le _ _ h :=
⟨sSup_le <| forall_mem_image.2 fun p hp => (h p hp).1,
sSup_le <| forall_mem_image.2 fun p hp => (h p hp).2⟩
sInf_le _ _ hab := ⟨sInf_le <| mem_image_of_mem _ hab, sInf_le <| mem_image_of_mem _ hab⟩
le_sInf _ _ h :=
⟨le_sInf <| forall_mem_image.2 fun p hp => (h p hp).1,
le_sInf <| forall_mem_image.2 fun p hp => (h p hp).2⟩
end Prod
lemma sInf_prod [InfSet α] [InfSet β] {s : Set α} {t : Set β} (hs : s.Nonempty) (ht : t.Nonempty) :
sInf (s ×ˢ t) = (sInf s, sInf t) :=
congr_arg₂ Prod.mk (congr_arg sInf <| fst_image_prod _ ht) (congr_arg sInf <| snd_image_prod hs _)
lemma sSup_prod [SupSet α] [SupSet β] {s : Set α} {t : Set β} (hs : s.Nonempty) (ht : t.Nonempty) :
sSup (s ×ˢ t) = (sSup s, sSup t) :=
congr_arg₂ Prod.mk (congr_arg sSup <| fst_image_prod _ ht) (congr_arg sSup <| snd_image_prod hs _)
section CompleteLattice
variable [CompleteLattice α] {a : α} {s : Set α}
/-- This is a weaker version of `sup_sInf_eq` -/
theorem sup_sInf_le_iInf_sup : a ⊔ sInf s ≤ ⨅ b ∈ s, a ⊔ b :=
le_iInf₂ fun _ h => sup_le_sup_left (sInf_le h) _
/-- This is a weaker version of `inf_sSup_eq` -/
theorem iSup_inf_le_inf_sSup : ⨆ b ∈ s, a ⊓ b ≤ a ⊓ sSup s :=
@sup_sInf_le_iInf_sup αᵒᵈ _ _ _
/-- This is a weaker version of `sInf_sup_eq` -/
theorem sInf_sup_le_iInf_sup : sInf s ⊔ a ≤ ⨅ b ∈ s, b ⊔ a :=
le_iInf₂ fun _ h => sup_le_sup_right (sInf_le h) _
/-- This is a weaker version of `sSup_inf_eq` -/
theorem iSup_inf_le_sSup_inf : ⨆ b ∈ s, b ⊓ a ≤ sSup s ⊓ a :=
@sInf_sup_le_iInf_sup αᵒᵈ _ _ _
theorem le_iSup_inf_iSup (f g : ι → α) : ⨆ i, f i ⊓ g i ≤ (⨆ i, f i) ⊓ ⨆ i, g i :=
le_inf (iSup_mono fun _ => inf_le_left) (iSup_mono fun _ => inf_le_right)
theorem iInf_sup_iInf_le (f g : ι → α) : (⨅ i, f i) ⊔ ⨅ i, g i ≤ ⨅ i, f i ⊔ g i :=
@le_iSup_inf_iSup αᵒᵈ ι _ f g
theorem disjoint_sSup_left {a : Set α} {b : α} (d : Disjoint (sSup a) b) {i} (hi : i ∈ a) :
Disjoint i b :=
disjoint_iff_inf_le.mpr (iSup₂_le_iff.1 (iSup_inf_le_sSup_inf.trans d.le_bot) i hi : _)
theorem disjoint_sSup_right {a : Set α} {b : α} (d : Disjoint b (sSup a)) {i} (hi : i ∈ a) :
Disjoint b i :=
disjoint_iff_inf_le.mpr (iSup₂_le_iff.mp (iSup_inf_le_inf_sSup.trans d.le_bot) i hi : _)
end CompleteLattice
-- See note [reducible non-instances]
/-- Pullback a `CompleteLattice` along an injection. -/
protected abbrev Function.Injective.completeLattice [Sup α] [Inf α] [SupSet α] [InfSet α] [Top α]
[Bot α] [CompleteLattice β] (f : α → β) (hf : Function.Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_sSup : ∀ s, f (sSup s) = ⨆ a ∈ s, f a) (map_sInf : ∀ s, f (sInf s) = ⨅ a ∈ s, f a)
(map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) : CompleteLattice α where
-- we cannot use BoundedOrder.lift here as the `LE` instance doesn't exist yet
__ := hf.lattice f map_sup map_inf
le_sSup _ a h := (le_iSup₂ a h).trans (map_sSup _).ge
sSup_le _ _ h := (map_sSup _).trans_le <| iSup₂_le h
sInf_le _ a h := (map_sInf _).trans_le <| iInf₂_le a h
le_sInf _ _ h := (le_iInf₂ h).trans (map_sInf _).ge
top := ⊤
le_top _ := (@le_top β _ _ _).trans map_top.ge
bot := ⊥
bot_le _ := map_bot.le.trans bot_le
namespace ULift
universe v
instance supSet [SupSet α] : SupSet (ULift.{v} α) where sSup s := ULift.up (sSup <| ULift.up ⁻¹' s)
theorem down_sSup [SupSet α] (s : Set (ULift.{v} α)) : (sSup s).down = sSup (ULift.up ⁻¹' s) := rfl
theorem up_sSup [SupSet α] (s : Set α) : up (sSup s) = sSup (ULift.down ⁻¹' s) := rfl
instance infSet [InfSet α] : InfSet (ULift.{v} α) where sInf s := ULift.up (sInf <| ULift.up ⁻¹' s)
theorem down_sInf [InfSet α] (s : Set (ULift.{v} α)) : (sInf s).down = sInf (ULift.up ⁻¹' s) := rfl
theorem up_sInf [InfSet α] (s : Set α) : up (sInf s) = sInf (ULift.down ⁻¹' s) := rfl
theorem down_iSup [SupSet α] (f : ι → ULift.{v} α) : (⨆ i, f i).down = ⨆ i, (f i).down :=
congr_arg sSup <| (preimage_eq_iff_eq_image ULift.up_bijective).mpr <|
Eq.symm (range_comp _ _).symm
theorem up_iSup [SupSet α] (f : ι → α) : up (⨆ i, f i) = ⨆ i, up (f i) :=
congr_arg ULift.up <| (down_iSup _).symm
theorem down_iInf [InfSet α] (f : ι → ULift.{v} α) : (⨅ i, f i).down = ⨅ i, (f i).down :=
congr_arg sInf <| (preimage_eq_iff_eq_image ULift.up_bijective).mpr <|
Eq.symm (range_comp _ _).symm
theorem up_iInf [InfSet α] (f : ι → α) : up (⨅ i, f i) = ⨅ i, up (f i) :=
congr_arg ULift.up <| (down_iInf _).symm
instance instCompleteLattice [CompleteLattice α] : CompleteLattice (ULift.{v} α) :=
ULift.down_injective.completeLattice _ down_sup down_inf
(fun s => by rw [sSup_eq_iSup', down_iSup, iSup_subtype''])
(fun s => by rw [sInf_eq_iInf', down_iInf, iInf_subtype'']) down_top down_bot
end ULift
namespace PUnit
instance instCompleteLinearOrder : CompleteLinearOrder PUnit where
__ := instBooleanAlgebra
__ := instLinearOrder
sSup := fun _ => unit
sInf := fun _ => unit
le_sSup := by intros; trivial
sSup_le := by intros; trivial
sInf_le := by intros; trivial
le_sInf := by intros; trivial
le_himp_iff := by intros; trivial
himp_bot := by intros; trivial
sdiff_le_iff := by intros; trivial
top_sdiff := by intros; trivial
end PUnit
|
Order\CompleteLatticeIntervals.lean | /-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.LatticeIntervals
import Mathlib.Order.Interval.Set.OrdConnected
/-! # Subtypes of conditionally complete linear orders
In this file we give conditions on a subset of a conditionally complete linear order, to ensure that
the subtype is itself conditionally complete.
We check that an `OrdConnected` set satisfies these conditions.
## TODO
Add appropriate instances for all `Set.Ixx`. This requires a refactor that will allow different
default values for `sSup` and `sInf`.
-/
open Set
variable {ι : Sort*} {α : Type*} (s : Set α)
section SupSet
variable [Preorder α] [SupSet α]
open Classical in
/-- `SupSet` structure on a nonempty subset `s` of a preorder with `SupSet`. This definition is
non-canonical (it uses `default s`); it should be used only as here, as an auxiliary instance in the
construction of the `ConditionallyCompleteLinearOrder` structure. -/
noncomputable def subsetSupSet [Inhabited s] : SupSet s where
sSup t :=
if ht : t.Nonempty ∧ BddAbove t ∧ sSup ((↑) '' t : Set α) ∈ s
then ⟨sSup ((↑) '' t : Set α), ht.2.2⟩
else default
attribute [local instance] subsetSupSet
open Classical in
@[simp]
theorem subset_sSup_def [Inhabited s] :
@sSup s _ = fun t =>
if ht : t.Nonempty ∧ BddAbove t ∧ sSup ((↑) '' t : Set α) ∈ s
then ⟨sSup ((↑) '' t : Set α), ht.2.2⟩
else default :=
rfl
theorem subset_sSup_of_within [Inhabited s] {t : Set s}
(h' : t.Nonempty) (h'' : BddAbove t) (h : sSup ((↑) '' t : Set α) ∈ s) :
sSup ((↑) '' t : Set α) = (@sSup s _ t : α) := by simp [dif_pos, h, h', h'']
theorem subset_sSup_emptyset [Inhabited s] :
sSup (∅ : Set s) = default := by
simp [sSup]
theorem subset_sSup_of_not_bddAbove [Inhabited s] {t : Set s} (ht : ¬BddAbove t) :
sSup t = default := by
simp [sSup, ht]
end SupSet
section InfSet
variable [Preorder α] [InfSet α]
open Classical in
/-- `InfSet` structure on a nonempty subset `s` of a preorder with `InfSet`. This definition is
non-canonical (it uses `default s`); it should be used only as here, as an auxiliary instance in the
construction of the `ConditionallyCompleteLinearOrder` structure. -/
noncomputable def subsetInfSet [Inhabited s] : InfSet s where
sInf t :=
if ht : t.Nonempty ∧ BddBelow t ∧ sInf ((↑) '' t : Set α) ∈ s
then ⟨sInf ((↑) '' t : Set α), ht.2.2⟩
else default
attribute [local instance] subsetInfSet
open Classical in
@[simp]
theorem subset_sInf_def [Inhabited s] :
@sInf s _ = fun t =>
if ht : t.Nonempty ∧ BddBelow t ∧ sInf ((↑) '' t : Set α) ∈ s
then ⟨sInf ((↑) '' t : Set α), ht.2.2⟩ else
default :=
rfl
theorem subset_sInf_of_within [Inhabited s] {t : Set s}
(h' : t.Nonempty) (h'' : BddBelow t) (h : sInf ((↑) '' t : Set α) ∈ s) :
sInf ((↑) '' t : Set α) = (@sInf s _ t : α) := by simp [dif_pos, h, h', h'']
theorem subset_sInf_emptyset [Inhabited s] :
sInf (∅ : Set s) = default := by
simp [sInf]
theorem subset_sInf_of_not_bddBelow [Inhabited s] {t : Set s} (ht : ¬BddBelow t) :
sInf t = default := by
simp [sInf, ht]
end InfSet
section OrdConnected
variable [ConditionallyCompleteLinearOrder α]
attribute [local instance] subsetSupSet
attribute [local instance] subsetInfSet
/-- For a nonempty subset of a conditionally complete linear order to be a conditionally complete
linear order, it suffices that it contain the `sSup` of all its nonempty bounded-above subsets, and
the `sInf` of all its nonempty bounded-below subsets.
See note [reducible non-instances]. -/
noncomputable abbrev subsetConditionallyCompleteLinearOrder [Inhabited s]
(h_Sup : ∀ {t : Set s} (_ : t.Nonempty) (_h_bdd : BddAbove t), sSup ((↑) '' t : Set α) ∈ s)
(h_Inf : ∀ {t : Set s} (_ : t.Nonempty) (_h_bdd : BddBelow t), sInf ((↑) '' t : Set α) ∈ s) :
ConditionallyCompleteLinearOrder s :=
{ subsetSupSet s, subsetInfSet s, DistribLattice.toLattice, (inferInstance : LinearOrder s) with
le_csSup := by
rintro t c h_bdd hct
rw [← Subtype.coe_le_coe, ← subset_sSup_of_within s ⟨c, hct⟩ h_bdd (h_Sup ⟨c, hct⟩ h_bdd)]
exact (Subtype.mono_coe _).le_csSup_image hct h_bdd
csSup_le := by
rintro t B ht hB
rw [← Subtype.coe_le_coe, ← subset_sSup_of_within s ht ⟨B, hB⟩ (h_Sup ht ⟨B, hB⟩)]
exact (Subtype.mono_coe s).csSup_image_le ht hB
le_csInf := by
intro t B ht hB
rw [← Subtype.coe_le_coe, ← subset_sInf_of_within s ht ⟨B, hB⟩ (h_Inf ht ⟨B, hB⟩)]
exact (Subtype.mono_coe s).le_csInf_image ht hB
csInf_le := by
rintro t c h_bdd hct
rw [← Subtype.coe_le_coe, ← subset_sInf_of_within s ⟨c, hct⟩ h_bdd (h_Inf ⟨c, hct⟩ h_bdd)]
exact (Subtype.mono_coe s).csInf_image_le hct h_bdd
csSup_of_not_bddAbove := fun t ht ↦ by simp [ht]
csInf_of_not_bddBelow := fun t ht ↦ by simp [ht] }
/-- The `sSup` function on a nonempty `OrdConnected` set `s` in a conditionally complete linear
order takes values within `s`, for all nonempty bounded-above subsets of `s`. -/
theorem sSup_within_of_ordConnected {s : Set α} [hs : OrdConnected s] ⦃t : Set s⦄ (ht : t.Nonempty)
(h_bdd : BddAbove t) : sSup ((↑) '' t : Set α) ∈ s := by
obtain ⟨c, hct⟩ : ∃ c, c ∈ t := ht
obtain ⟨B, hB⟩ : ∃ B, B ∈ upperBounds t := h_bdd
refine hs.out c.2 B.2 ⟨?_, ?_⟩
· exact (Subtype.mono_coe s).le_csSup_image hct ⟨B, hB⟩
· exact (Subtype.mono_coe s).csSup_image_le ⟨c, hct⟩ hB
/-- The `sInf` function on a nonempty `OrdConnected` set `s` in a conditionally complete linear
order takes values within `s`, for all nonempty bounded-below subsets of `s`. -/
theorem sInf_within_of_ordConnected {s : Set α} [hs : OrdConnected s] ⦃t : Set s⦄ (ht : t.Nonempty)
(h_bdd : BddBelow t) : sInf ((↑) '' t : Set α) ∈ s := by
obtain ⟨c, hct⟩ : ∃ c, c ∈ t := ht
obtain ⟨B, hB⟩ : ∃ B, B ∈ lowerBounds t := h_bdd
refine hs.out B.2 c.2 ⟨?_, ?_⟩
· exact (Subtype.mono_coe s).le_csInf_image ⟨c, hct⟩ hB
· exact (Subtype.mono_coe s).csInf_image_le hct ⟨B, hB⟩
/-- A nonempty `OrdConnected` set in a conditionally complete linear order is naturally a
conditionally complete linear order. -/
noncomputable instance ordConnectedSubsetConditionallyCompleteLinearOrder [Inhabited s]
[OrdConnected s] : ConditionallyCompleteLinearOrder s :=
subsetConditionallyCompleteLinearOrder s
(fun h => sSup_within_of_ordConnected h)
(fun h => sInf_within_of_ordConnected h)
end OrdConnected
section Icc
open Classical in
/-- Complete lattice structure on `Set.Icc` -/
noncomputable def Set.Icc.completeLattice [ConditionallyCompleteLattice α]
{a b : α} (h : a ≤ b) : CompleteLattice (Set.Icc a b) where
__ := Set.Icc.boundedOrder h
sSup S := if hS : S = ∅ then ⟨a, le_rfl, h⟩ else ⟨sSup ((↑) '' S), by
rw [← Set.not_nonempty_iff_eq_empty, not_not] at hS
refine ⟨?_, csSup_le (hS.image (↑)) (fun _ ⟨c, _, hc⟩ ↦ hc ▸ c.2.2)⟩
obtain ⟨c, hc⟩ := hS
exact c.2.1.trans (le_csSup ⟨b, fun _ ⟨d, _, hd⟩ ↦ hd ▸ d.2.2⟩ ⟨c, hc, rfl⟩)⟩
le_sSup S c hc := by
by_cases hS : S = ∅ <;> simp only [hS, dite_true, dite_false]
· simp [hS] at hc
· exact le_csSup ⟨b, fun _ ⟨d, _, hd⟩ ↦ hd ▸ d.2.2⟩ ⟨c, hc, rfl⟩
sSup_le S c hc := by
by_cases hS : S = ∅ <;> simp only [hS, dite_true, dite_false]
· exact c.2.1
· exact csSup_le ((Set.nonempty_iff_ne_empty.mpr hS).image (↑))
(fun _ ⟨d, h, hd⟩ ↦ hd ▸ hc d h)
sInf S := if hS : S = ∅ then ⟨b, h, le_rfl⟩ else ⟨sInf ((↑) '' S), by
rw [← Set.not_nonempty_iff_eq_empty, not_not] at hS
refine ⟨le_csInf (hS.image (↑)) (fun _ ⟨c, _, hc⟩ ↦ hc ▸ c.2.1), ?_⟩
obtain ⟨c, hc⟩ := hS
exact le_trans (csInf_le ⟨a, fun _ ⟨d, _, hd⟩ ↦ hd ▸ d.2.1⟩ ⟨c, hc, rfl⟩) c.2.2⟩
sInf_le S c hc := by
by_cases hS : S = ∅ <;> simp only [hS, dite_true, dite_false]
· simp [hS] at hc
· exact csInf_le ⟨a, fun _ ⟨d, _, hd⟩ ↦ hd ▸ d.2.1⟩ ⟨c, hc, rfl⟩
le_sInf S c hc := by
by_cases hS : S = ∅ <;> simp only [hS, dite_true, dite_false]
· exact c.2.2
· exact le_csInf ((Set.nonempty_iff_ne_empty.mpr hS).image (↑))
(fun _ ⟨d, h, hd⟩ ↦ hd ▸ hc d h)
/-- Complete linear order structure on `Set.Icc` -/
noncomputable def Set.Icc.completeLinearOrder [ConditionallyCompleteLinearOrder α]
{a b : α} (h : a ≤ b) : CompleteLinearOrder (Set.Icc a b) := by
let _ := completeLattice h
exact { completeLattice h, Subtype.instLinearOrder _, LinearOrder.toBiheytingAlgebra with }
lemma Set.Icc.coe_sSup [ConditionallyCompleteLattice α] {a b : α} (h : a ≤ b)
{S : Set (Set.Icc a b)} (hS : S.Nonempty) : letI := Set.Icc.completeLattice h
↑(sSup S) = sSup ((↑) '' S : Set α) :=
congrArg Subtype.val (dif_neg hS.ne_empty)
lemma Set.Icc.coe_sInf [ConditionallyCompleteLattice α] {a b : α} (h : a ≤ b)
{S : Set (Set.Icc a b)} (hS : S.Nonempty) : letI := Set.Icc.completeLattice h
↑(sInf S) = sInf ((↑) '' S : Set α) :=
congrArg Subtype.val (dif_neg hS.ne_empty)
lemma Set.Icc.coe_iSup [ConditionallyCompleteLattice α] {a b : α} (h : a ≤ b)
[Nonempty ι] {S : ι → Set.Icc a b} : letI := Set.Icc.completeLattice h
↑(iSup S) = (⨆ i, S i : α) :=
(Set.Icc.coe_sSup h (range_nonempty S)).trans (congrArg sSup (range_comp Subtype.val S).symm)
lemma Set.Icc.coe_iInf [ConditionallyCompleteLattice α] {a b : α} (h : a ≤ b)
[Nonempty ι] {S : ι → Set.Icc a b} : letI := Set.Icc.completeLattice h
↑(iInf S) = (⨅ i, S i : α) :=
(Set.Icc.coe_sInf h (range_nonempty S)).trans (congrArg sInf (range_comp Subtype.val S).symm)
end Icc
namespace Set.Iic
variable [CompleteLattice α] {a : α}
instance instCompleteLattice : CompleteLattice (Iic a) where
sSup S := ⟨sSup ((↑) '' S), by simpa using fun b hb _ ↦ hb⟩
sInf S := ⟨a ⊓ sInf ((↑) '' S), by simp⟩
le_sSup S b hb := le_sSup <| mem_image_of_mem Subtype.val hb
sSup_le S b hb := sSup_le <| fun c' ⟨c, hc, hc'⟩ ↦ hc' ▸ hb c hc
sInf_le S b hb := inf_le_of_right_le <| sInf_le <| mem_image_of_mem Subtype.val hb
le_sInf S b hb := le_inf_iff.mpr ⟨b.property, le_sInf fun d' ⟨d, hd, hd'⟩ ↦ hd' ▸ hb d hd⟩
le_top := by simp
bot_le := by simp
variable (S : Set <| Iic a) (f : ι → Iic a) (p : ι → Prop)
@[simp] theorem coe_sSup : (↑(sSup S) : α) = sSup ((↑) '' S) := rfl
@[simp] theorem coe_iSup : (↑(⨆ i, f i) : α) = ⨆ i, (f i : α) := by
rw [iSup, coe_sSup]; congr; ext; simp
theorem coe_biSup : (↑(⨆ i, ⨆ (_ : p i), f i) : α) = ⨆ i, ⨆ (_ : p i), (f i : α) := by simp
@[simp] theorem coe_sInf : (↑(sInf S) : α) = a ⊓ sInf ((↑) '' S) := rfl
@[simp] theorem coe_iInf : (↑(⨅ i, f i) : α) = a ⊓ ⨅ i, (f i : α) := by
rw [iInf, coe_sInf]; congr; ext; simp
theorem coe_biInf : (↑(⨅ i, ⨅ (_ : p i), f i) : α) = a ⊓ ⨅ i, ⨅ (_ : p i), (f i : α) := by
cases isEmpty_or_nonempty ι
· simp
· simp_rw [coe_iInf, ← inf_iInf, ← inf_assoc, inf_idem]
end Set.Iic
assert_not_exists Multiset
|
Order\CompletePartialOrder.lean | /-
Copyright (c) 2023 Christopher Hoskin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christopher Hoskin
-/
import Mathlib.Order.OmegaCompletePartialOrder
/-!
# Complete Partial Orders
This file considers complete partial orders (sometimes called directedly complete partial orders).
These are partial orders for which every directed set has a least upper bound.
## Main declarations
- `CompletePartialOrder`: Typeclass for (directly) complete partial orders.
## Main statements
- `CompletePartialOrder.toOmegaCompletePartialOrder`: A complete partial order is an ω-complete
partial order.
- `CompleteLattice.toCompletePartialOrder`: A complete lattice is a complete partial order.
## References
- [B. A. Davey and H. A. Priestley, Introduction to lattices and order][davey_priestley]
## Tags
complete partial order, directedly complete partial order
-/
variable {ι : Sort*} {α β : Type*}
section CompletePartialOrder
/--
Complete partial orders are partial orders where every directed set has a least upper bound.
-/
class CompletePartialOrder (α : Type*) extends PartialOrder α, SupSet α where
/-- For each directed set `d`, `sSup d` is the least upper bound of `d`. -/
lubOfDirected : ∀ d, DirectedOn (· ≤ ·) d → IsLUB d (sSup d)
variable [CompletePartialOrder α] [Preorder β] {f : ι → α} {d : Set α} {a : α}
protected lemma DirectedOn.isLUB_sSup : DirectedOn (· ≤ ·) d → IsLUB d (sSup d) :=
CompletePartialOrder.lubOfDirected _
protected lemma DirectedOn.le_sSup (hd : DirectedOn (· ≤ ·) d) (ha : a ∈ d) : a ≤ sSup d :=
hd.isLUB_sSup.1 ha
protected lemma DirectedOn.sSup_le (hd : DirectedOn (· ≤ ·) d) (ha : ∀ b ∈ d, b ≤ a) : sSup d ≤ a :=
hd.isLUB_sSup.2 ha
protected lemma Directed.le_iSup (hf : Directed (· ≤ ·) f) (i : ι) : f i ≤ ⨆ j, f j :=
hf.directedOn_range.le_sSup <| Set.mem_range_self _
protected lemma Directed.iSup_le (hf : Directed (· ≤ ·) f) (ha : ∀ i, f i ≤ a) : ⨆ i, f i ≤ a :=
hf.directedOn_range.sSup_le <| Set.forall_mem_range.2 ha
--TODO: We could mimic more `sSup`/`iSup` lemmas
/-- Scott-continuity takes on a simpler form in complete partial orders. -/
lemma CompletePartialOrder.scottContinuous {f : α → β} :
ScottContinuous f ↔
∀ ⦃d : Set α⦄, d.Nonempty → DirectedOn (· ≤ ·) d → IsLUB (f '' d) (f (sSup d)) := by
refine ⟨fun h d hd₁ hd₂ ↦ h hd₁ hd₂ hd₂.isLUB_sSup, fun h d hne hd a hda ↦ ?_⟩
rw [hda.unique hd.isLUB_sSup]
exact h hne hd
open OmegaCompletePartialOrder
/-- A complete partial order is an ω-complete partial order. -/
instance CompletePartialOrder.toOmegaCompletePartialOrder : OmegaCompletePartialOrder α where
ωSup c := ⨆ n, c n
le_ωSup c := c.directed.le_iSup
ωSup_le c _ := c.directed.iSup_le
end CompletePartialOrder
/-- A complete lattice is a complete partial order. -/
instance CompleteLattice.toCompletePartialOrder [CompleteLattice α] : CompletePartialOrder α where
sSup := sSup
lubOfDirected _ _ := isLUB_sSup _
|
Order\CompleteSublattice.lean | /-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Order.Sublattice
import Mathlib.Order.Hom.CompleteLattice
/-!
# Complete Sublattices
This file defines complete sublattices. These are subsets of complete lattices which are closed
under arbitrary suprema and infima. As a standard example one could take the complete sublattice of
invariant submodules of some module with respect to a linear map.
## Main definitions:
* `CompleteSublattice`: the definition of a complete sublattice
* `CompleteSublattice.mk'`: an alternate constructor for a complete sublattice, demanding fewer
hypotheses
* `CompleteSublattice.instCompleteLattice`: a complete sublattice is a complete lattice
* `CompleteSublattice.map`: complete sublattices push forward under complete lattice morphisms.
* `CompleteSublattice.comap`: complete sublattices pull back under complete lattice morphisms.
-/
open Function Set
variable (α β : Type*) [CompleteLattice α] [CompleteLattice β] (f : CompleteLatticeHom α β)
/-- A complete sublattice is a subset of a complete lattice that is closed under arbitrary suprema
and infima. -/
structure CompleteSublattice extends Sublattice α where
sSupClosed' : ∀ ⦃s : Set α⦄, s ⊆ carrier → sSup s ∈ carrier
sInfClosed' : ∀ ⦃s : Set α⦄, s ⊆ carrier → sInf s ∈ carrier
variable {α β}
namespace CompleteSublattice
/-- To check that a subset is a complete sublattice, one does not need to check that it is closed
under binary `Sup` since this follows from the stronger `sSup` condition. Likewise for infima. -/
@[simps] def mk' (carrier : Set α)
(sSupClosed' : ∀ ⦃s : Set α⦄, s ⊆ carrier → sSup s ∈ carrier)
(sInfClosed' : ∀ ⦃s : Set α⦄, s ⊆ carrier → sInf s ∈ carrier) :
CompleteSublattice α where
carrier := carrier
sSupClosed' := sSupClosed'
sInfClosed' := sInfClosed'
supClosed' := fun x hx y hy ↦ by
suffices x ⊔ y = sSup {x, y} by exact this ▸ sSupClosed' (fun z hz ↦ by aesop)
simp [sSup_singleton]
infClosed' := fun x hx y hy ↦ by
suffices x ⊓ y = sInf {x, y} by exact this ▸ sInfClosed' (fun z hz ↦ by aesop)
simp [sInf_singleton]
variable {L : CompleteSublattice α}
instance instSetLike : SetLike (CompleteSublattice α) α where
coe L := L.carrier
coe_injective' L M h := by cases L; cases M; congr; exact SetLike.coe_injective' h
instance instBot : Bot L where
bot := ⟨⊥, by simpa using L.sSupClosed' <| empty_subset _⟩
instance instTop : Top L where
top := ⟨⊤, by simpa using L.sInfClosed' <| empty_subset _⟩
instance instSupSet : SupSet L where
sSup s := ⟨sSup s, L.sSupClosed' image_val_subset⟩
instance instInfSet : InfSet L where
sInf s := ⟨sInf s, L.sInfClosed' image_val_subset⟩
theorem sSupClosed {s : Set α} (h : s ⊆ L) : sSup s ∈ L := L.sSupClosed' h
theorem sInfClosed {s : Set α} (h : s ⊆ L) : sInf s ∈ L := L.sInfClosed' h
@[simp] theorem coe_bot : (↑(⊥ : L) : α) = ⊥ := rfl
@[simp] theorem coe_top : (↑(⊤ : L) : α) = ⊤ := rfl
@[simp] theorem coe_sSup (S : Set L) : (↑(sSup S) : α) = sSup {(s : α) | s ∈ S} := rfl
theorem coe_sSup' (S : Set L) : (↑(sSup S) : α) = ⨆ N ∈ S, (N : α) := by
rw [coe_sSup, ← Set.image, sSup_image]
@[simp] theorem coe_sInf (S : Set L) : (↑(sInf S) : α) = sInf {(s : α) | s ∈ S} := rfl
theorem coe_sInf' (S : Set L) : (↑(sInf S) : α) = ⨅ N ∈ S, (N : α) := by
rw [coe_sInf, ← Set.image, sInf_image]
instance instCompleteLattice : CompleteLattice L :=
Subtype.coe_injective.completeLattice _
Sublattice.coe_sup Sublattice.coe_inf coe_sSup' coe_sInf' coe_top coe_bot
/-- The push forward of a complete sublattice under a complete lattice hom is a complete
sublattice. -/
@[simps] def map (L : CompleteSublattice α) : CompleteSublattice β where
carrier := f '' L
supClosed' := L.supClosed.image f
infClosed' := L.infClosed.image f
sSupClosed' := fun s hs ↦ by
obtain ⟨t, ht, rfl⟩ := subset_image_iff.mp hs
rw [← map_sSup]
exact mem_image_of_mem f (sSupClosed ht)
sInfClosed' := fun s hs ↦ by
obtain ⟨t, ht, rfl⟩ := subset_image_iff.mp hs
rw [← map_sInf]
exact mem_image_of_mem f (sInfClosed ht)
@[simp] theorem mem_map {b : β} : b ∈ L.map f ↔ ∃ a ∈ L, f a = b := Iff.rfl
/-- The pull back of a complete sublattice under a complete lattice hom is a complete sublattice. -/
@[simps] def comap (L : CompleteSublattice β) : CompleteSublattice α where
carrier := f ⁻¹' L
supClosed' := L.supClosed.preimage f
infClosed' := L.infClosed.preimage f
sSupClosed' s hs := by
simpa only [mem_preimage, map_sSup, SetLike.mem_coe] using sSupClosed <| mapsTo'.mp hs
sInfClosed' s hs := by
simpa only [mem_preimage, map_sInf, SetLike.mem_coe] using sInfClosed <| mapsTo'.mp hs
@[simp] theorem mem_comap {L : CompleteSublattice β} {a : α} : a ∈ L.comap f ↔ f a ∈ L := Iff.rfl
protected lemma disjoint_iff {a b : L} :
Disjoint a b ↔ Disjoint (a : α) (b : α) := by
rw [disjoint_iff, disjoint_iff, ← Sublattice.coe_inf, ← coe_bot (L := L),
Subtype.coe_injective.eq_iff]
protected lemma codisjoint_iff {a b : L} :
Codisjoint a b ↔ Codisjoint (a : α) (b : α) := by
rw [codisjoint_iff, codisjoint_iff, ← Sublattice.coe_sup, ← coe_top (L := L),
Subtype.coe_injective.eq_iff]
protected lemma isCompl_iff {a b : L} :
IsCompl a b ↔ IsCompl (a : α) (b : α) := by
rw [isCompl_iff, isCompl_iff, CompleteSublattice.disjoint_iff, CompleteSublattice.codisjoint_iff]
lemma isComplemented_iff : ComplementedLattice L ↔ ∀ a ∈ L, ∃ b ∈ L, IsCompl a b := by
refine ⟨fun ⟨h⟩ a ha ↦ ?_, fun h ↦ ⟨fun ⟨a, ha⟩ ↦ ?_⟩⟩
· obtain ⟨b, hb⟩ := h ⟨a, ha⟩
exact ⟨b, b.property, CompleteSublattice.isCompl_iff.mp hb⟩
· obtain ⟨b, hb, hb'⟩ := h a ha
exact ⟨⟨b, hb⟩, CompleteSublattice.isCompl_iff.mpr hb'⟩
instance : Top (CompleteSublattice α) := ⟨mk' univ (fun _ _ ↦ mem_univ _) (fun _ _ ↦ mem_univ _)⟩
variable (L)
/-- Copy of a complete sublattice with a new `carrier` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (s : Set α) (hs : s = L) : CompleteSublattice α :=
mk' s (hs ▸ L.sSupClosed') (hs ▸ L.sInfClosed')
@[simp, norm_cast] lemma coe_copy (s : Set α) (hs) : L.copy s hs = s := rfl
lemma copy_eq (s : Set α) (hs) : L.copy s hs = L := SetLike.coe_injective hs
end CompleteSublattice
namespace CompleteLatticeHom
/-- The range of a `CompleteLatticeHom` is a `CompleteSublattice`.
See Note [range copy pattern]. -/
protected def range : CompleteSublattice β :=
(CompleteSublattice.map f ⊤).copy (range f) image_univ.symm
theorem range_coe : (f.range : Set β) = range f := rfl
/-- We can regard a complete lattice homomorphism as an order equivalence to its range. -/
@[simps! apply] noncomputable def toOrderIsoRangeOfInjective (hf : Injective f) : α ≃o f.range :=
(orderEmbeddingOfInjective f hf).orderIso
end CompleteLatticeHom
|
Order\Concept.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Set.Lattice
/-!
# Formal concept analysis
This file defines concept lattices. A concept of a relation `r : α → β → Prop` is a pair of sets
`s : Set α` and `t : Set β` such that `s` is the set of all `a : α` that are related to all elements
of `t`, and `t` is the set of all `b : β` that are related to all elements of `s`.
Ordering the concepts of a relation `r` by inclusion on the first component gives rise to a
*concept lattice*. Every concept lattice is complete and in fact every complete lattice arises as
the concept lattice of its `≤`.
## Implementation notes
Concept lattices are usually defined from a *context*, that is the triple `(α, β, r)`, but the type
of `r` determines `α` and `β` already, so we do not define contexts as a separate object.
## TODO
Prove the fundamental theorem of concept lattices.
## References
* [Davey, Priestley *Introduction to Lattices and Order*][davey_priestley]
## Tags
concept, formal concept analysis, intent, extend, attribute
-/
open Function OrderDual Set
variable {ι : Sort*} {α β γ : Type*} {κ : ι → Sort*} (r : α → β → Prop) {s s₁ s₂ : Set α}
{t t₁ t₂ : Set β}
/-! ### Intent and extent -/
/-- The intent closure of `s : Set α` along a relation `r : α → β → Prop` is the set of all elements
which `r` relates to all elements of `s`. -/
def intentClosure (s : Set α) : Set β :=
{ b | ∀ ⦃a⦄, a ∈ s → r a b }
/-- The extent closure of `t : Set β` along a relation `r : α → β → Prop` is the set of all elements
which `r` relates to all elements of `t`. -/
def extentClosure (t : Set β) : Set α :=
{ a | ∀ ⦃b⦄, b ∈ t → r a b }
variable {r}
theorem subset_intentClosure_iff_subset_extentClosure :
t ⊆ intentClosure r s ↔ s ⊆ extentClosure r t :=
⟨fun h _ ha _ hb => h hb ha, fun h _ hb _ ha => h ha hb⟩
variable (r)
theorem gc_intentClosure_extentClosure :
GaloisConnection (toDual ∘ intentClosure r) (extentClosure r ∘ ofDual) := fun _ _ =>
subset_intentClosure_iff_subset_extentClosure
theorem intentClosure_swap (t : Set β) : intentClosure (swap r) t = extentClosure r t :=
rfl
theorem extentClosure_swap (s : Set α) : extentClosure (swap r) s = intentClosure r s :=
rfl
@[simp]
theorem intentClosure_empty : intentClosure r ∅ = univ :=
eq_univ_of_forall fun _ _ => False.elim
@[simp]
theorem extentClosure_empty : extentClosure r ∅ = univ :=
intentClosure_empty _
@[simp]
theorem intentClosure_union (s₁ s₂ : Set α) :
intentClosure r (s₁ ∪ s₂) = intentClosure r s₁ ∩ intentClosure r s₂ :=
Set.ext fun _ => forall₂_or_left
@[simp]
theorem extentClosure_union (t₁ t₂ : Set β) :
extentClosure r (t₁ ∪ t₂) = extentClosure r t₁ ∩ extentClosure r t₂ :=
intentClosure_union _ _ _
@[simp]
theorem intentClosure_iUnion (f : ι → Set α) :
intentClosure r (⋃ i, f i) = ⋂ i, intentClosure r (f i) :=
(gc_intentClosure_extentClosure r).l_iSup
@[simp]
theorem extentClosure_iUnion (f : ι → Set β) :
extentClosure r (⋃ i, f i) = ⋂ i, extentClosure r (f i) :=
intentClosure_iUnion _ _
theorem intentClosure_iUnion₂ (f : ∀ i, κ i → Set α) :
intentClosure r (⋃ (i) (j), f i j) = ⋂ (i) (j), intentClosure r (f i j) :=
(gc_intentClosure_extentClosure r).l_iSup₂
theorem extentClosure_iUnion₂ (f : ∀ i, κ i → Set β) :
extentClosure r (⋃ (i) (j), f i j) = ⋂ (i) (j), extentClosure r (f i j) :=
intentClosure_iUnion₂ _ _
theorem subset_extentClosure_intentClosure (s : Set α) :
s ⊆ extentClosure r (intentClosure r s) :=
(gc_intentClosure_extentClosure r).le_u_l _
theorem subset_intentClosure_extentClosure (t : Set β) :
t ⊆ intentClosure r (extentClosure r t) :=
subset_extentClosure_intentClosure _ t
@[simp]
theorem intentClosure_extentClosure_intentClosure (s : Set α) :
intentClosure r (extentClosure r <| intentClosure r s) = intentClosure r s :=
(gc_intentClosure_extentClosure r).l_u_l_eq_l _
@[simp]
theorem extentClosure_intentClosure_extentClosure (t : Set β) :
extentClosure r (intentClosure r <| extentClosure r t) = extentClosure r t :=
intentClosure_extentClosure_intentClosure _ t
theorem intentClosure_anti : Antitone (intentClosure r) :=
(gc_intentClosure_extentClosure r).monotone_l
theorem extentClosure_anti : Antitone (extentClosure r) :=
intentClosure_anti _
/-! ### Concepts -/
variable (α β)
/-- The formal concepts of a relation. A concept of `r : α → β → Prop` is a pair of sets `s`, `t`
such that `s` is the set of all elements that are `r`-related to all of `t` and `t` is the set of
all elements that are `r`-related to all of `s`. -/
structure Concept extends Set α × Set β where
/-- The axiom of a `Concept` stating that the closure of the first set is the second set. -/
closure_fst : intentClosure r fst = snd
/-- The axiom of a `Concept` stating that the closure of the second set is the first set. -/
closure_snd : extentClosure r snd = fst
initialize_simps_projections Concept (+toProd, -fst, -snd)
namespace Concept
variable {r α β}
variable {c d : Concept α β r}
attribute [simp] closure_fst closure_snd
@[ext]
theorem ext (h : c.fst = d.fst) : c = d := by
obtain ⟨⟨s₁, t₁⟩, h₁, _⟩ := c
obtain ⟨⟨s₂, t₂⟩, h₂, _⟩ := d
dsimp at h₁ h₂ h
substs h h₁ h₂
rfl
theorem ext' (h : c.snd = d.snd) : c = d := by
obtain ⟨⟨s₁, t₁⟩, _, h₁⟩ := c
obtain ⟨⟨s₂, t₂⟩, _, h₂⟩ := d
dsimp at h₁ h₂ h
substs h h₁ h₂
rfl
theorem fst_injective : Injective fun c : Concept α β r => c.fst := fun _ _ => ext
theorem snd_injective : Injective fun c : Concept α β r => c.snd := fun _ _ => ext'
instance instSupConcept : Sup (Concept α β r) :=
⟨fun c d =>
{ fst := extentClosure r (c.snd ∩ d.snd)
snd := c.snd ∩ d.snd
closure_fst := by
rw [← c.closure_fst, ← d.closure_fst, ← intentClosure_union,
intentClosure_extentClosure_intentClosure]
closure_snd := rfl }⟩
instance instInfConcept : Inf (Concept α β r) :=
⟨fun c d =>
{ fst := c.fst ∩ d.fst
snd := intentClosure r (c.fst ∩ d.fst)
closure_fst := rfl
closure_snd := by
rw [← c.closure_snd, ← d.closure_snd, ← extentClosure_union,
extentClosure_intentClosure_extentClosure] }⟩
instance instSemilatticeInfConcept : SemilatticeInf (Concept α β r) :=
(fst_injective.semilatticeInf _) fun _ _ => rfl
@[simp]
theorem fst_subset_fst_iff : c.fst ⊆ d.fst ↔ c ≤ d :=
Iff.rfl
@[simp]
theorem fst_ssubset_fst_iff : c.fst ⊂ d.fst ↔ c < d :=
Iff.rfl
@[simp]
theorem snd_subset_snd_iff : c.snd ⊆ d.snd ↔ d ≤ c := by
refine ⟨fun h => ?_, fun h => ?_⟩
· rw [← fst_subset_fst_iff, ← c.closure_snd, ← d.closure_snd]
exact extentClosure_anti _ h
· rw [← c.closure_fst, ← d.closure_fst]
exact intentClosure_anti _ h
@[simp]
theorem snd_ssubset_snd_iff : c.snd ⊂ d.snd ↔ d < c := by
rw [ssubset_iff_subset_not_subset, lt_iff_le_not_le, snd_subset_snd_iff, snd_subset_snd_iff]
theorem strictMono_fst : StrictMono (Prod.fst ∘ toProd : Concept α β r → Set α) := fun _ _ =>
fst_ssubset_fst_iff.2
theorem strictAnti_snd : StrictAnti (Prod.snd ∘ toProd : Concept α β r → Set β) := fun _ _ =>
snd_ssubset_snd_iff.2
instance instLatticeConcept : Lattice (Concept α β r) :=
{ Concept.instSemilatticeInfConcept with
sup := (· ⊔ ·)
le_sup_left := fun c d => snd_subset_snd_iff.1 inter_subset_left
le_sup_right := fun c d => snd_subset_snd_iff.1 inter_subset_right
sup_le := fun c d e => by
simp_rw [← snd_subset_snd_iff]
exact subset_inter }
instance instBoundedOrderConcept : BoundedOrder (Concept α β r) where
top := ⟨⟨univ, intentClosure r univ⟩, rfl, eq_univ_of_forall fun _ _ hb => hb trivial⟩
le_top _ := subset_univ _
bot := ⟨⟨extentClosure r univ, univ⟩, eq_univ_of_forall fun _ _ ha => ha trivial, rfl⟩
bot_le _ := snd_subset_snd_iff.1 <| subset_univ _
instance : SupSet (Concept α β r) :=
⟨fun S =>
{ fst := extentClosure r (⋂ c ∈ S, (c : Concept _ _ _).snd)
snd := ⋂ c ∈ S, (c : Concept _ _ _).snd
closure_fst := by
simp_rw [← closure_fst, ← intentClosure_iUnion₂,
intentClosure_extentClosure_intentClosure]
closure_snd := rfl }⟩
instance : InfSet (Concept α β r) :=
⟨fun S =>
{ fst := ⋂ c ∈ S, (c : Concept _ _ _).fst
snd := intentClosure r (⋂ c ∈ S, (c : Concept _ _ _).fst)
closure_fst := rfl
closure_snd := by
simp_rw [← closure_snd, ← extentClosure_iUnion₂,
extentClosure_intentClosure_extentClosure] }⟩
instance : CompleteLattice (Concept α β r) :=
{ Concept.instLatticeConcept,
Concept.instBoundedOrderConcept with
sup := Concept.instSupConcept.sup
le_sSup := fun _ _ hc => snd_subset_snd_iff.1 <| biInter_subset_of_mem hc
sSup_le := fun _ _ hc =>
snd_subset_snd_iff.1 <| subset_iInter₂ fun d hd => snd_subset_snd_iff.2 <| hc d hd
inf := Concept.instInfConcept.inf
sInf_le := fun _ _ => biInter_subset_of_mem
le_sInf := fun _ _ => subset_iInter₂ }
@[simp]
theorem top_fst : (⊤ : Concept α β r).fst = univ :=
rfl
@[simp]
theorem top_snd : (⊤ : Concept α β r).snd = intentClosure r univ :=
rfl
@[simp]
theorem bot_fst : (⊥ : Concept α β r).fst = extentClosure r univ :=
rfl
@[simp]
theorem bot_snd : (⊥ : Concept α β r).snd = univ :=
rfl
@[simp]
theorem sup_fst (c d : Concept α β r) : (c ⊔ d).fst = extentClosure r (c.snd ∩ d.snd) :=
rfl
@[simp]
theorem sup_snd (c d : Concept α β r) : (c ⊔ d).snd = c.snd ∩ d.snd :=
rfl
@[simp]
theorem inf_fst (c d : Concept α β r) : (c ⊓ d).fst = c.fst ∩ d.fst :=
rfl
@[simp]
theorem inf_snd (c d : Concept α β r) : (c ⊓ d).snd = intentClosure r (c.fst ∩ d.fst) :=
rfl
@[simp]
theorem sSup_fst (S : Set (Concept α β r)) :
(sSup S).fst = extentClosure r (⋂ c ∈ S, (c : Concept _ _ _).snd) :=
rfl
@[simp]
theorem sSup_snd (S : Set (Concept α β r)) : (sSup S).snd = ⋂ c ∈ S, (c : Concept _ _ _).snd :=
rfl
@[simp]
theorem sInf_fst (S : Set (Concept α β r)) : (sInf S).fst = ⋂ c ∈ S, (c : Concept _ _ _).fst :=
rfl
@[simp]
theorem sInf_snd (S : Set (Concept α β r)) :
(sInf S).snd = intentClosure r (⋂ c ∈ S, (c : Concept _ _ _).fst) :=
rfl
instance : Inhabited (Concept α β r) :=
⟨⊥⟩
/-- Swap the sets of a concept to make it a concept of the dual context. -/
@[simps]
def swap (c : Concept α β r) : Concept β α (swap r) :=
⟨c.toProd.swap, c.closure_snd, c.closure_fst⟩
@[simp]
theorem swap_swap (c : Concept α β r) : c.swap.swap = c :=
ext rfl
@[simp]
theorem swap_le_swap_iff : c.swap ≤ d.swap ↔ d ≤ c :=
snd_subset_snd_iff
@[simp]
theorem swap_lt_swap_iff : c.swap < d.swap ↔ d < c :=
snd_ssubset_snd_iff
/-- The dual of a concept lattice is isomorphic to the concept lattice of the dual context. -/
@[simps]
def swapEquiv : (Concept α β r)ᵒᵈ ≃o Concept β α (Function.swap r) where
toFun := swap ∘ ofDual
invFun := toDual ∘ swap
left_inv := swap_swap
right_inv := swap_swap
map_rel_iff' := swap_le_swap_iff
end Concept
|
Order\Copy.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Yaël Dillies
-/
import Mathlib.Order.ConditionallyCompleteLattice.Basic
/-!
# Tooling to make copies of lattice structures
Sometimes it is useful to make a copy of a lattice structure
where one replaces the data parts with provably equal definitions
that have better definitional properties.
-/
open Order
universe u
variable {α : Type u}
/-- A function to create a provable equal copy of a top order
with possibly different definitional equalities. -/
def OrderTop.copy {h : LE α} {h' : LE α} (c : @OrderTop α h')
(top : α) (eq_top : top = (by infer_instance : Top α).top)
(le_eq : ∀ x y : α, (@LE.le α h) x y ↔ x ≤ y) : @OrderTop α h :=
@OrderTop.mk α h { top := top } fun _ ↦ by simp [eq_top, le_eq]
/-- A function to create a provable equal copy of a bottom order
with possibly different definitional equalities. -/
def OrderBot.copy {h : LE α} {h' : LE α} (c : @OrderBot α h')
(bot : α) (eq_bot : bot = (by infer_instance : Bot α).bot)
(le_eq : ∀ x y : α, (@LE.le α h) x y ↔ x ≤ y) : @OrderBot α h :=
@OrderBot.mk α h { bot := bot } fun _ ↦ by simp [eq_bot, le_eq]
/-- A function to create a provable equal copy of a bounded order
with possibly different definitional equalities. -/
def BoundedOrder.copy {h : LE α} {h' : LE α} (c : @BoundedOrder α h')
(top : α) (eq_top : top = (by infer_instance : Top α).top)
(bot : α) (eq_bot : bot = (by infer_instance : Bot α).bot)
(le_eq : ∀ x y : α, (@LE.le α h) x y ↔ x ≤ y) : @BoundedOrder α h :=
@BoundedOrder.mk α h (@OrderTop.mk α h { top := top } (fun _ ↦ by simp [eq_top, le_eq]))
(@OrderBot.mk α h { bot := bot } (fun _ ↦ by simp [eq_bot, le_eq]))
/-- A function to create a provable equal copy of a lattice
with possibly different definitional equalities. -/
def Lattice.copy (c : Lattice α)
(le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf) : Lattice α where
le := le
sup := sup
inf := inf
lt := fun a b ↦ le a b ∧ ¬ le b a
le_refl := by intros; simp [eq_le]
le_trans := by intro _ _ _ hab hbc; rw [eq_le] at hab hbc ⊢; exact le_trans hab hbc
le_antisymm := by intro _ _ hab hba; simp_rw [eq_le] at hab hba; exact le_antisymm hab hba
le_sup_left := by intros; simp [eq_le, eq_sup]
le_sup_right := by intros; simp [eq_le, eq_sup]
sup_le := by intro _ _ _ hac hbc; simp_rw [eq_le] at hac hbc ⊢; simp [eq_sup, hac, hbc]
inf_le_left := by intros; simp [eq_le, eq_inf]
inf_le_right := by intros; simp [eq_le, eq_inf]
le_inf := by intro _ _ _ hac hbc; simp_rw [eq_le] at hac hbc ⊢; simp [eq_inf, hac, hbc]
/-- A function to create a provable equal copy of a distributive lattice
with possibly different definitional equalities. -/
def DistribLattice.copy (c : DistribLattice α)
(le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf) : DistribLattice α where
toLattice := Lattice.copy (@DistribLattice.toLattice α c) le eq_le sup eq_sup inf eq_inf
le_sup_inf := by intros; simp [eq_le, eq_sup, eq_inf, le_sup_inf]
/-- A function to create a provable equal copy of a generalised heyting algebra
with possibly different definitional equalities. -/
def GeneralizedHeytingAlgebra.copy (c : GeneralizedHeytingAlgebra α)
(le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(top : α) (eq_top : top = (by infer_instance : Top α).top)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf)
(himp : α → α → α) (eq_himp : himp = (by infer_instance : HImp α).himp) :
GeneralizedHeytingAlgebra α where
__ := Lattice.copy (@GeneralizedHeytingAlgebra.toLattice α c) le eq_le sup eq_sup inf eq_inf
__ := OrderTop.copy (@GeneralizedHeytingAlgebra.toOrderTop α c) top eq_top
(by rw [← eq_le]; exact fun _ _ ↦ .rfl)
himp := himp
le_himp_iff _ _ _ := by simp [eq_le, eq_himp, eq_inf]
/-- A function to create a provable equal copy of a generalised coheyting algebra
with possibly different definitional equalities. -/
def GeneralizedCoheytingAlgebra.copy (c : GeneralizedCoheytingAlgebra α)
(le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(bot : α) (eq_bot : bot = (by infer_instance : Bot α).bot)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf)
(sdiff : α → α → α) (eq_sdiff : sdiff = (by infer_instance : SDiff α).sdiff) :
GeneralizedCoheytingAlgebra α where
__ := Lattice.copy (@GeneralizedCoheytingAlgebra.toLattice α c) le eq_le sup eq_sup inf eq_inf
__ := OrderBot.copy (@GeneralizedCoheytingAlgebra.toOrderBot α c) bot eq_bot
(by rw [← eq_le]; exact fun _ _ ↦ .rfl)
sdiff := sdiff
sdiff_le_iff := by simp [eq_le, eq_sdiff, eq_sup]
/-- A function to create a provable equal copy of a heyting algebra
with possibly different definitional equalities. -/
def HeytingAlgebra.copy (c : HeytingAlgebra α)
(le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(top : α) (eq_top : top = (by infer_instance : Top α).top)
(bot : α) (eq_bot : bot = (by infer_instance : Bot α).bot)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf)
(himp : α → α → α) (eq_himp : himp = (by infer_instance : HImp α).himp)
(compl : α → α) (eq_compl : compl = (by infer_instance : HasCompl α).compl) :
HeytingAlgebra α where
toGeneralizedHeytingAlgebra := GeneralizedHeytingAlgebra.copy
(@HeytingAlgebra.toGeneralizedHeytingAlgebra α c) le eq_le top eq_top sup eq_sup inf eq_inf himp
eq_himp
__ := OrderBot.copy (@HeytingAlgebra.toOrderBot α c) bot eq_bot
(by rw [← eq_le]; exact fun _ _ ↦ .rfl)
compl := compl
himp_bot := by simp [eq_le, eq_himp, eq_bot, eq_compl]
/-- A function to create a provable equal copy of a coheyting algebra
with possibly different definitional equalities. -/
def CoheytingAlgebra.copy (c : CoheytingAlgebra α)
(le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(top : α) (eq_top : top = (by infer_instance : Top α).top)
(bot : α) (eq_bot : bot = (by infer_instance : Bot α).bot)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf)
(sdiff : α → α → α) (eq_sdiff : sdiff = (by infer_instance : SDiff α).sdiff)
(hnot : α → α) (eq_hnot : hnot = (by infer_instance : HNot α).hnot) :
CoheytingAlgebra α where
toGeneralizedCoheytingAlgebra := GeneralizedCoheytingAlgebra.copy
(@CoheytingAlgebra.toGeneralizedCoheytingAlgebra α c) le eq_le bot eq_bot sup eq_sup inf eq_inf
sdiff eq_sdiff
__ := OrderTop.copy (@CoheytingAlgebra.toOrderTop α c) top eq_top
(by rw [← eq_le]; exact fun _ _ ↦ .rfl)
hnot := hnot
top_sdiff := by simp [eq_le, eq_sdiff, eq_top, eq_hnot]
/-- A function to create a provable equal copy of a biheyting algebra
with possibly different definitional equalities. -/
def BiheytingAlgebra.copy (c : BiheytingAlgebra α)
(le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(top : α) (eq_top : top = (by infer_instance : Top α).top)
(bot : α) (eq_bot : bot = (by infer_instance : Bot α).bot)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf)
(sdiff : α → α → α) (eq_sdiff : sdiff = (by infer_instance : SDiff α).sdiff)
(hnot : α → α) (eq_hnot : hnot = (by infer_instance : HNot α).hnot)
(himp : α → α → α) (eq_himp : himp = (by infer_instance : HImp α).himp)
(compl : α → α) (eq_compl : compl = (by infer_instance : HasCompl α).compl) :
BiheytingAlgebra α where
toHeytingAlgebra := HeytingAlgebra.copy (@BiheytingAlgebra.toHeytingAlgebra α c) le eq_le top
eq_top bot eq_bot sup eq_sup inf eq_inf himp eq_himp compl eq_compl
__ := CoheytingAlgebra.copy (@BiheytingAlgebra.toCoheytingAlgebra α c) le eq_le top eq_top bot
eq_bot sup eq_sup inf eq_inf sdiff eq_sdiff hnot eq_hnot
/-- A function to create a provable equal copy of a complete lattice
with possibly different definitional equalities. -/
def CompleteLattice.copy (c : CompleteLattice α)
(le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(top : α) (eq_top : top = (by infer_instance : Top α).top)
(bot : α) (eq_bot : bot = (by infer_instance : Bot α).bot)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf)
(sSup : Set α → α) (eq_sSup : sSup = (by infer_instance : SupSet α).sSup)
(sInf : Set α → α) (eq_sInf : sInf = (by infer_instance : InfSet α).sInf) :
CompleteLattice α where
toLattice := Lattice.copy (@CompleteLattice.toLattice α c) le eq_le sup eq_sup inf eq_inf
top := top
bot := bot
sSup := sSup
sInf := sInf
le_sSup := by intro _ _ h; simp [eq_le, eq_sSup, le_sSup _ _ h]
sSup_le := by intro _ _ h; simpa [eq_le, eq_sSup] using h
sInf_le := by intro _ _ h; simp [eq_le, eq_sInf, sInf_le _ _ h]
le_sInf := by intro _ _ h; simpa [eq_le, eq_sInf] using h
le_top := by intros; simp [eq_le, eq_top]
bot_le := by intros; simp [eq_le, eq_bot]
/-- A function to create a provable equal copy of a frame with possibly different definitional
equalities. -/
def Frame.copy (c : Frame α) (le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(top : α) (eq_top : top = (by infer_instance : Top α).top)
(bot : α) (eq_bot : bot = (by infer_instance : Bot α).bot)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf)
(himp : α → α → α) (eq_himp : himp = (by infer_instance : HImp α).himp)
(compl : α → α) (eq_compl : compl = (by infer_instance : HasCompl α).compl)
(sSup : Set α → α) (eq_sSup : sSup = (by infer_instance : SupSet α).sSup)
(sInf : Set α → α) (eq_sInf : sInf = (by infer_instance : InfSet α).sInf) : Frame α where
toCompleteLattice := CompleteLattice.copy (@Frame.toCompleteLattice α c)
le eq_le top eq_top bot eq_bot sup eq_sup inf eq_inf sSup eq_sSup sInf eq_sInf
inf_sSup_le_iSup_inf := fun a s => by
simp [eq_le, eq_sup, eq_inf, eq_sSup, @Order.Frame.inf_sSup_le_iSup_inf α _ a s]
__ := HeytingAlgebra.copy (@Frame.toHeytingAlgebra α c)
le eq_le top eq_top bot eq_bot sup eq_sup inf eq_inf himp eq_himp compl eq_compl
/-- A function to create a provable equal copy of a coframe with possibly different definitional
equalities. -/
def Coframe.copy (c : Coframe α) (le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(top : α) (eq_top : top = (by infer_instance : Top α).top)
(bot : α) (eq_bot : bot = (by infer_instance : Bot α).bot)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf)
(sdiff : α → α → α) (eq_sdiff : sdiff = (by infer_instance : SDiff α).sdiff)
(hnot : α → α) (eq_hnot : hnot = (by infer_instance : HNot α).hnot)
(sSup : Set α → α) (eq_sSup : sSup = (by infer_instance : SupSet α).sSup)
(sInf : Set α → α) (eq_sInf : sInf = (by infer_instance : InfSet α).sInf) : Coframe α where
toCompleteLattice := CompleteLattice.copy (@Coframe.toCompleteLattice α c)
le eq_le top eq_top bot eq_bot sup eq_sup inf eq_inf sSup eq_sSup sInf eq_sInf
iInf_sup_le_sup_sInf := fun a s => by
simp [eq_le, eq_sup, eq_inf, eq_sInf, @Order.Coframe.iInf_sup_le_sup_sInf α _ a s]
__ := CoheytingAlgebra.copy (@Coframe.toCoheytingAlgebra α c)
le eq_le top eq_top bot eq_bot sup eq_sup inf eq_inf sdiff eq_sdiff hnot eq_hnot
/-- A function to create a provable equal copy of a complete distributive lattice
with possibly different definitional equalities. -/
def CompleteDistribLattice.copy (c : CompleteDistribLattice α)
(le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(top : α) (eq_top : top = (by infer_instance : Top α).top)
(bot : α) (eq_bot : bot = (by infer_instance : Bot α).bot)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf)
(sdiff : α → α → α) (eq_sdiff : sdiff = (by infer_instance : SDiff α).sdiff)
(hnot : α → α) (eq_hnot : hnot = (by infer_instance : HNot α).hnot)
(himp : α → α → α) (eq_himp : himp = (by infer_instance : HImp α).himp)
(compl : α → α) (eq_compl : compl = (by infer_instance : HasCompl α).compl)
(sSup : Set α → α) (eq_sSup : sSup = (by infer_instance : SupSet α).sSup)
(sInf : Set α → α) (eq_sInf : sInf = (by infer_instance : InfSet α).sInf) :
CompleteDistribLattice α where
toFrame := Frame.copy (@CompleteDistribLattice.toFrame α c) le eq_le top eq_top bot eq_bot sup
eq_sup inf eq_inf himp eq_himp compl eq_compl sSup eq_sSup sInf eq_sInf
__ := Coframe.copy (@CompleteDistribLattice.toCoframe α c) le eq_le top eq_top bot eq_bot sup
eq_sup inf eq_inf sdiff eq_sdiff hnot eq_hnot sSup eq_sSup sInf eq_sInf
/-- A function to create a provable equal copy of a conditionally complete lattice
with possibly different definitional equalities. -/
def ConditionallyCompleteLattice.copy (c : ConditionallyCompleteLattice α)
(le : α → α → Prop) (eq_le : le = (by infer_instance : LE α).le)
(sup : α → α → α) (eq_sup : sup = (by infer_instance : Sup α).sup)
(inf : α → α → α) (eq_inf : inf = (by infer_instance : Inf α).inf)
(sSup : Set α → α) (eq_sSup : sSup = (by infer_instance : SupSet α).sSup)
(sInf : Set α → α) (eq_sInf : sInf = (by infer_instance : InfSet α).sInf) :
ConditionallyCompleteLattice α where
toLattice := Lattice.copy (@ConditionallyCompleteLattice.toLattice α c)
le eq_le sup eq_sup inf eq_inf
sSup := sSup
sInf := sInf
le_csSup := by intro _ _ hb h; subst_vars; exact le_csSup _ _ hb h
csSup_le := by intro _ _ hb h; subst_vars; exact csSup_le _ _ hb h
csInf_le := by intro _ _ hb h; subst_vars; exact csInf_le _ _ hb h
le_csInf := by intro _ _ hb h; subst_vars; exact le_csInf _ _ hb h
|
Order\CountableDenseLinearOrder.lean | /-
Copyright (c) 2020 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn
-/
import Mathlib.Order.Ideal
import Mathlib.Data.Finset.Lattice
/-!
# The back and forth method and countable dense linear orders
## Results
Suppose `α β` are linear orders, with `α` countable and `β` dense, nontrivial. Then there is an
order embedding `α ↪ β`. If in addition `α` is dense, nonempty, without endpoints and `β` is
countable, without endpoints, then we can upgrade this to an order isomorphism `α ≃ β`.
The idea for both results is to consider "partial isomorphisms", which identify a finite subset of
`α` with a finite subset of `β`, and prove that for any such partial isomorphism `f` and `a : α`, we
can extend `f` to include `a` in its domain.
## References
https://en.wikipedia.org/wiki/Back-and-forth_method
## Tags
back and forth, dense, countable, order
-/
noncomputable section
namespace Order
/-- Suppose `α` is a nonempty dense linear order without endpoints, and
suppose `lo`, `hi`, are finite subsets with all of `lo` strictly
before `hi`. Then there is an element of `α` strictly between `lo`
and `hi`. -/
theorem exists_between_finsets {α : Type*} [LinearOrder α] [DenselyOrdered α] [NoMinOrder α]
[NoMaxOrder α] [nonem : Nonempty α] (lo hi : Finset α) (lo_lt_hi : ∀ x ∈ lo, ∀ y ∈ hi, x < y) :
∃ m : α, (∀ x ∈ lo, x < m) ∧ ∀ y ∈ hi, m < y :=
if nlo : lo.Nonempty then
if nhi : hi.Nonempty then
-- both sets are nonempty, use `DenselyOrdered`
Exists.elim
(exists_between (lo_lt_hi _ (Finset.max'_mem _ nlo) _ (Finset.min'_mem _ nhi))) fun m hm ↦
⟨m, fun x hx ↦ lt_of_le_of_lt (Finset.le_max' lo x hx) hm.1, fun y hy ↦
lt_of_lt_of_le hm.2 (Finset.min'_le hi y hy)⟩
else-- upper set is empty, use `NoMaxOrder`
Exists.elim
(exists_gt (Finset.max' lo nlo)) fun m hm ↦
⟨m, fun x hx ↦ lt_of_le_of_lt (Finset.le_max' lo x hx) hm, fun y hy ↦ (nhi ⟨y, hy⟩).elim⟩
else
if nhi : hi.Nonempty then
-- lower set is empty, use `NoMinOrder`
Exists.elim
(exists_lt (Finset.min' hi nhi)) fun m hm ↦
⟨m, fun x hx ↦ (nlo ⟨x, hx⟩).elim, fun y hy ↦ lt_of_lt_of_le hm (Finset.min'_le hi y hy)⟩
else -- both sets are empty, use `Nonempty`
nonem.elim
fun m ↦ ⟨m, fun x hx ↦ (nlo ⟨x, hx⟩).elim, fun y hy ↦ (nhi ⟨y, hy⟩).elim⟩
variable (α β : Type*) [LinearOrder α] [LinearOrder β]
-- Porting note: Mathport warning: expanding binder collection (p q «expr ∈ » f)
/-- The type of partial order isomorphisms between `α` and `β` defined on finite subsets.
A partial order isomorphism is encoded as a finite subset of `α × β`, consisting
of pairs which should be identified. -/
def PartialIso : Type _ :=
{ f : Finset (α × β) //
∀ p ∈ f, ∀ q ∈ f,
cmp (Prod.fst p) (Prod.fst q) = cmp (Prod.snd p) (Prod.snd q) }
namespace PartialIso
instance : Inhabited (PartialIso α β) := ⟨⟨∅, fun _p h _q ↦ (Finset.not_mem_empty _ h).elim⟩⟩
instance : Preorder (PartialIso α β) := Subtype.preorder _
variable {α β}
/-- For each `a`, we can find a `b` in the codomain, such that `a`'s relation to
the domain of `f` is `b`'s relation to the image of `f`.
Thus, if `a` is not already in `f`, then we can extend `f` by sending `a` to `b`.
-/
theorem exists_across [DenselyOrdered β] [NoMinOrder β] [NoMaxOrder β] [Nonempty β]
(f : PartialIso α β) (a : α) :
∃ b : β, ∀ p ∈ f.val, cmp (Prod.fst p) a = cmp (Prod.snd p) b := by
by_cases h : ∃ b, (a, b) ∈ f.val
· cases' h with b hb
exact ⟨b, fun p hp ↦ f.prop _ hp _ hb⟩
have :
∀ x ∈ (f.val.filter fun p : α × β ↦ p.fst < a).image Prod.snd,
∀ y ∈ (f.val.filter fun p : α × β ↦ a < p.fst).image Prod.snd, x < y := by
intro x hx y hy
rw [Finset.mem_image] at hx hy
rcases hx with ⟨p, hp1, rfl⟩
rcases hy with ⟨q, hq1, rfl⟩
rw [Finset.mem_filter] at hp1 hq1
rw [← lt_iff_lt_of_cmp_eq_cmp (f.prop _ hp1.1 _ hq1.1)]
exact lt_trans hp1.right hq1.right
cases' exists_between_finsets _ _ this with b hb
use b
rintro ⟨p1, p2⟩ hp
have : p1 ≠ a := fun he ↦ h ⟨p2, he ▸ hp⟩
cases' lt_or_gt_of_ne this with hl hr
· have : p1 < a ∧ p2 < b :=
⟨hl, hb.1 _ (Finset.mem_image.mpr ⟨(p1, p2), Finset.mem_filter.mpr ⟨hp, hl⟩, rfl⟩)⟩
rw [← cmp_eq_lt_iff, ← cmp_eq_lt_iff] at this
exact this.1.trans this.2.symm
· have : a < p1 ∧ b < p2 :=
⟨hr, hb.2 _ (Finset.mem_image.mpr ⟨(p1, p2), Finset.mem_filter.mpr ⟨hp, hr⟩, rfl⟩)⟩
rw [← cmp_eq_gt_iff, ← cmp_eq_gt_iff] at this
exact this.1.trans this.2.symm
/-- A partial isomorphism between `α` and `β` is also a partial isomorphism between `β` and `α`. -/
protected def comm : PartialIso α β → PartialIso β α :=
Subtype.map (Finset.image (Equiv.prodComm _ _)) fun f hf p hp q hq ↦
Eq.symm <|
hf ((Equiv.prodComm α β).symm p)
(by
rw [← Finset.mem_coe, Finset.coe_image, Equiv.image_eq_preimage] at hp
rwa [← Finset.mem_coe])
((Equiv.prodComm α β).symm q)
(by
rw [← Finset.mem_coe, Finset.coe_image, Equiv.image_eq_preimage] at hq
rwa [← Finset.mem_coe])
variable (β)
/-- The set of partial isomorphisms defined at `a : α`, together with a proof that any
partial isomorphism can be extended to one defined at `a`. -/
def definedAtLeft [DenselyOrdered β] [NoMinOrder β] [NoMaxOrder β] [Nonempty β] (a : α) :
Cofinal (PartialIso α β) where
carrier := {f | ∃ b : β, (a, b) ∈ f.val}
mem_gt f := by
cases' exists_across f a with b a_b
refine
⟨⟨insert (a, b) f.val, fun p hp q hq ↦ ?_⟩, ⟨b, Finset.mem_insert_self _ _⟩,
Finset.subset_insert _ _⟩
rw [Finset.mem_insert] at hp hq
rcases hp with (rfl | pf) <;> rcases hq with (rfl | qf)
· simp only [cmp_self_eq_eq]
· rw [cmp_eq_cmp_symm]
exact a_b _ qf
· exact a_b _ pf
· exact f.prop _ pf _ qf
variable (α) {β}
/-- The set of partial isomorphisms defined at `b : β`, together with a proof that any
partial isomorphism can be extended to include `b`. We prove this by symmetry. -/
def definedAtRight [DenselyOrdered α] [NoMinOrder α] [NoMaxOrder α] [Nonempty α] (b : β) :
Cofinal (PartialIso α β) where
carrier := {f | ∃ a, (a, b) ∈ f.val}
mem_gt f := by
rcases (definedAtLeft α b).mem_gt f.comm with ⟨f', ⟨a, ha⟩, hl⟩
refine ⟨f'.comm, ⟨a, ?_⟩, ?_⟩
· change (a, b) ∈ f'.val.image _
rwa [← Finset.mem_coe, Finset.coe_image, Equiv.image_eq_preimage]
· change _ ⊆ f'.val.image _
rwa [← Finset.coe_subset, Finset.coe_image, ← Equiv.symm_image_subset, ← Finset.coe_image,
Finset.coe_subset]
variable {α}
/-- Given an ideal which intersects `definedAtLeft β a`, pick `b : β` such that
some partial function in the ideal maps `a` to `b`. -/
def funOfIdeal [DenselyOrdered β] [NoMinOrder β] [NoMaxOrder β] [Nonempty β] (a : α)
(I : Ideal (PartialIso α β)) :
(∃ f, f ∈ definedAtLeft β a ∧ f ∈ I) → { b // ∃ f ∈ I, (a, b) ∈ Subtype.val f } :=
Classical.indefiniteDescription _ ∘ fun ⟨f, ⟨b, hb⟩, hf⟩ ↦ ⟨b, f, hf, hb⟩
/-- Given an ideal which intersects `definedAtRight α b`, pick `a : α` such that
some partial function in the ideal maps `a` to `b`. -/
def invOfIdeal [DenselyOrdered α] [NoMinOrder α] [NoMaxOrder α] [Nonempty α] (b : β)
(I : Ideal (PartialIso α β)) :
(∃ f, f ∈ definedAtRight α b ∧ f ∈ I) → { a // ∃ f ∈ I, (a, b) ∈ Subtype.val f } :=
Classical.indefiniteDescription _ ∘ fun ⟨f, ⟨a, ha⟩, hf⟩ ↦ ⟨a, f, hf, ha⟩
end PartialIso
open PartialIso
-- variable (α β)
/-- Any countable linear order embeds in any nontrivial dense linear order. -/
theorem embedding_from_countable_to_dense [Countable α] [DenselyOrdered β] [Nontrivial β] :
Nonempty (α ↪o β) := by
cases nonempty_encodable α
rcases exists_pair_lt β with ⟨x, y, hxy⟩
cases' exists_between hxy with a ha
haveI : Nonempty (Set.Ioo x y) := ⟨⟨a, ha⟩⟩
let our_ideal : Ideal (PartialIso α _) :=
idealOfCofinals default (definedAtLeft (Set.Ioo x y))
let F a := funOfIdeal a our_ideal (cofinal_meets_idealOfCofinals _ _ a)
refine
⟨RelEmbedding.trans (OrderEmbedding.ofStrictMono (fun a ↦ (F a).val) fun a₁ a₂ ↦ ?_)
(OrderEmbedding.subtype _)⟩
rcases (F a₁).prop with ⟨f, hf, ha₁⟩
rcases (F a₂).prop with ⟨g, hg, ha₂⟩
rcases our_ideal.directed _ hf _ hg with ⟨m, _hm, fm, gm⟩
exact (lt_iff_lt_of_cmp_eq_cmp <| m.prop (a₁, _) (fm ha₁) (a₂, _) (gm ha₂)).mp
/-- Any two countable dense, nonempty linear orders without endpoints are order isomorphic. -/
theorem iso_of_countable_dense [Countable α] [DenselyOrdered α] [NoMinOrder α] [NoMaxOrder α]
[Nonempty α] [Countable β] [DenselyOrdered β] [NoMinOrder β] [NoMaxOrder β] [Nonempty β] :
Nonempty (α ≃o β) := by
cases nonempty_encodable α
cases nonempty_encodable β
let to_cofinal : α ⊕ β → Cofinal (PartialIso α β) := fun p ↦
Sum.recOn p (definedAtLeft β) (definedAtRight α)
let our_ideal : Ideal (PartialIso α β) := idealOfCofinals default to_cofinal
let F a := funOfIdeal a our_ideal (cofinal_meets_idealOfCofinals _ to_cofinal (Sum.inl a))
let G b := invOfIdeal b our_ideal (cofinal_meets_idealOfCofinals _ to_cofinal (Sum.inr b))
exact ⟨OrderIso.ofCmpEqCmp (fun a ↦ (F a).val) (fun b ↦ (G b).val) fun a b ↦ by
rcases (F a).prop with ⟨f, hf, ha⟩
rcases (G b).prop with ⟨g, hg, hb⟩
rcases our_ideal.directed _ hf _ hg with ⟨m, _, fm, gm⟩
exact m.prop (a, _) (fm ha) (_, b) (gm hb)⟩
end Order
|
Order\Cover.lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Violeta Hernández Palacios, Grayson Burton, Floris van Doorn
-/
import Mathlib.Order.Interval.Set.OrdConnected
import Mathlib.Order.Antisymmetrization
/-!
# The covering relation
This file defines the covering relation in an order. `b` is said to cover `a` if `a < b` and there
is no element in between. We say that `b` weakly covers `a` if `a ≤ b` and there is no element
between `a` and `b`. In a partial order this is equivalent to `a ⋖ b ∨ a = b`, in a preorder this
is equivalent to `a ⋖ b ∨ (a ≤ b ∧ b ≤ a)`
## Notation
* `a ⋖ b` means that `b` covers `a`.
* `a ⩿ b` means that `b` weakly covers `a`.
-/
open Set OrderDual
variable {α β : Type*}
section WeaklyCovers
section Preorder
variable [Preorder α] [Preorder β] {a b c : α}
/-- `WCovBy a b` means that `a = b` or `b` covers `a`.
This means that `a ≤ b` and there is no element in between.
-/
def WCovBy (a b : α) : Prop :=
a ≤ b ∧ ∀ ⦃c⦄, a < c → ¬c < b
/-- Notation for `WCovBy a b`. -/
infixl:50 " ⩿ " => WCovBy
theorem WCovBy.le (h : a ⩿ b) : a ≤ b :=
h.1
theorem WCovBy.refl (a : α) : a ⩿ a :=
⟨le_rfl, fun _ hc => hc.not_lt⟩
@[simp] lemma WCovBy.rfl : a ⩿ a := WCovBy.refl a
protected theorem Eq.wcovBy (h : a = b) : a ⩿ b :=
h ▸ WCovBy.rfl
theorem wcovBy_of_le_of_le (h1 : a ≤ b) (h2 : b ≤ a) : a ⩿ b :=
⟨h1, fun _ hac hcb => (hac.trans hcb).not_le h2⟩
alias LE.le.wcovBy_of_le := wcovBy_of_le_of_le
theorem AntisymmRel.wcovBy (h : AntisymmRel (· ≤ ·) a b) : a ⩿ b :=
wcovBy_of_le_of_le h.1 h.2
theorem WCovBy.wcovBy_iff_le (hab : a ⩿ b) : b ⩿ a ↔ b ≤ a :=
⟨fun h => h.le, fun h => h.wcovBy_of_le hab.le⟩
theorem wcovBy_of_eq_or_eq (hab : a ≤ b) (h : ∀ c, a ≤ c → c ≤ b → c = a ∨ c = b) : a ⩿ b :=
⟨hab, fun c ha hb => (h c ha.le hb.le).elim ha.ne' hb.ne⟩
theorem AntisymmRel.trans_wcovBy (hab : AntisymmRel (· ≤ ·) a b) (hbc : b ⩿ c) : a ⩿ c :=
⟨hab.1.trans hbc.le, fun _ had hdc => hbc.2 (hab.2.trans_lt had) hdc⟩
theorem wcovBy_congr_left (hab : AntisymmRel (· ≤ ·) a b) : a ⩿ c ↔ b ⩿ c :=
⟨hab.symm.trans_wcovBy, hab.trans_wcovBy⟩
theorem WCovBy.trans_antisymm_rel (hab : a ⩿ b) (hbc : AntisymmRel (· ≤ ·) b c) : a ⩿ c :=
⟨hab.le.trans hbc.1, fun _ had hdc => hab.2 had <| hdc.trans_le hbc.2⟩
theorem wcovBy_congr_right (hab : AntisymmRel (· ≤ ·) a b) : c ⩿ a ↔ c ⩿ b :=
⟨fun h => h.trans_antisymm_rel hab, fun h => h.trans_antisymm_rel hab.symm⟩
/-- If `a ≤ b`, then `b` does not cover `a` iff there's an element in between. -/
theorem not_wcovBy_iff (h : a ≤ b) : ¬a ⩿ b ↔ ∃ c, a < c ∧ c < b := by
simp_rw [WCovBy, h, true_and_iff, not_forall, exists_prop, not_not]
instance WCovBy.isRefl : IsRefl α (· ⩿ ·) :=
⟨WCovBy.refl⟩
theorem WCovBy.Ioo_eq (h : a ⩿ b) : Ioo a b = ∅ :=
eq_empty_iff_forall_not_mem.2 fun _ hx => h.2 hx.1 hx.2
theorem wcovBy_iff_Ioo_eq : a ⩿ b ↔ a ≤ b ∧ Ioo a b = ∅ :=
and_congr_right' <| by simp [eq_empty_iff_forall_not_mem]
lemma WCovBy.of_le_of_le (hac : a ⩿ c) (hab : a ≤ b) (hbc : b ≤ c) : b ⩿ c :=
⟨hbc, fun _x hbx hxc ↦ hac.2 (hab.trans_lt hbx) hxc⟩
lemma WCovBy.of_le_of_le' (hac : a ⩿ c) (hab : a ≤ b) (hbc : b ≤ c) : a ⩿ b :=
⟨hab, fun _x hax hxb ↦ hac.2 hax <| hxb.trans_le hbc⟩
theorem WCovBy.of_image (f : α ↪o β) (h : f a ⩿ f b) : a ⩿ b :=
⟨f.le_iff_le.mp h.le, fun _ hac hcb => h.2 (f.lt_iff_lt.mpr hac) (f.lt_iff_lt.mpr hcb)⟩
theorem WCovBy.image (f : α ↪o β) (hab : a ⩿ b) (h : (range f).OrdConnected) : f a ⩿ f b := by
refine ⟨f.monotone hab.le, fun c ha hb => ?_⟩
obtain ⟨c, rfl⟩ := h.out (mem_range_self _) (mem_range_self _) ⟨ha.le, hb.le⟩
rw [f.lt_iff_lt] at ha hb
exact hab.2 ha hb
theorem Set.OrdConnected.apply_wcovBy_apply_iff (f : α ↪o β) (h : (range f).OrdConnected) :
f a ⩿ f b ↔ a ⩿ b :=
⟨fun h2 => h2.of_image f, fun hab => hab.image f h⟩
@[simp]
theorem apply_wcovBy_apply_iff {E : Type*} [EquivLike E α β] [OrderIsoClass E α β] (e : E) :
e a ⩿ e b ↔ a ⩿ b :=
(ordConnected_range (e : α ≃o β)).apply_wcovBy_apply_iff ((e : α ≃o β) : α ↪o β)
@[simp]
theorem toDual_wcovBy_toDual_iff : toDual b ⩿ toDual a ↔ a ⩿ b :=
and_congr_right' <| forall_congr' fun _ => forall_swap
@[simp]
theorem ofDual_wcovBy_ofDual_iff {a b : αᵒᵈ} : ofDual a ⩿ ofDual b ↔ b ⩿ a :=
and_congr_right' <| forall_congr' fun _ => forall_swap
alias ⟨_, WCovBy.toDual⟩ := toDual_wcovBy_toDual_iff
alias ⟨_, WCovBy.ofDual⟩ := ofDual_wcovBy_ofDual_iff
end Preorder
section PartialOrder
variable [PartialOrder α] {a b c : α}
theorem WCovBy.eq_or_eq (h : a ⩿ b) (h2 : a ≤ c) (h3 : c ≤ b) : c = a ∨ c = b := by
rcases h2.eq_or_lt with (h2 | h2); · exact Or.inl h2.symm
rcases h3.eq_or_lt with (h3 | h3); · exact Or.inr h3
exact (h.2 h2 h3).elim
/-- An `iff` version of `WCovBy.eq_or_eq` and `wcovBy_of_eq_or_eq`. -/
theorem wcovBy_iff_le_and_eq_or_eq : a ⩿ b ↔ a ≤ b ∧ ∀ c, a ≤ c → c ≤ b → c = a ∨ c = b :=
⟨fun h => ⟨h.le, fun _ => h.eq_or_eq⟩, And.rec wcovBy_of_eq_or_eq⟩
theorem WCovBy.le_and_le_iff (h : a ⩿ b) : a ≤ c ∧ c ≤ b ↔ c = a ∨ c = b := by
refine ⟨fun h2 => h.eq_or_eq h2.1 h2.2, ?_⟩; rintro (rfl | rfl)
exacts [⟨le_rfl, h.le⟩, ⟨h.le, le_rfl⟩]
theorem WCovBy.Icc_eq (h : a ⩿ b) : Icc a b = {a, b} := by
ext c
exact h.le_and_le_iff
theorem WCovBy.Ico_subset (h : a ⩿ b) : Ico a b ⊆ {a} := by
rw [← Icc_diff_right, h.Icc_eq, diff_singleton_subset_iff, pair_comm]
theorem WCovBy.Ioc_subset (h : a ⩿ b) : Ioc a b ⊆ {b} := by
rw [← Icc_diff_left, h.Icc_eq, diff_singleton_subset_iff]
end PartialOrder
section SemilatticeSup
variable [SemilatticeSup α] {a b c : α}
theorem WCovBy.sup_eq (hac : a ⩿ c) (hbc : b ⩿ c) (hab : a ≠ b) : a ⊔ b = c :=
(sup_le hac.le hbc.le).eq_of_not_lt fun h =>
hab.lt_sup_or_lt_sup.elim (fun h' => hac.2 h' h) fun h' => hbc.2 h' h
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] {a b c : α}
theorem WCovBy.inf_eq (hca : c ⩿ a) (hcb : c ⩿ b) (hab : a ≠ b) : a ⊓ b = c :=
(le_inf hca.le hcb.le).eq_of_not_gt fun h => hab.inf_lt_or_inf_lt.elim (hca.2 h) (hcb.2 h)
end SemilatticeInf
end WeaklyCovers
section LT
variable [LT α] {a b : α}
/-- `CovBy a b` means that `b` covers `a`: `a < b` and there is no element in between. -/
def CovBy (a b : α) : Prop :=
a < b ∧ ∀ ⦃c⦄, a < c → ¬c < b
/-- Notation for `CovBy a b`. -/
infixl:50 " ⋖ " => CovBy
theorem CovBy.lt (h : a ⋖ b) : a < b :=
h.1
/-- If `a < b`, then `b` does not cover `a` iff there's an element in between. -/
theorem not_covBy_iff (h : a < b) : ¬a ⋖ b ↔ ∃ c, a < c ∧ c < b := by
simp_rw [CovBy, h, true_and_iff, not_forall, exists_prop, not_not]
alias ⟨exists_lt_lt_of_not_covBy, _⟩ := not_covBy_iff
alias LT.lt.exists_lt_lt := exists_lt_lt_of_not_covBy
/-- In a dense order, nothing covers anything. -/
theorem not_covBy [DenselyOrdered α] : ¬a ⋖ b := fun h =>
let ⟨_, hc⟩ := exists_between h.1
h.2 hc.1 hc.2
theorem denselyOrdered_iff_forall_not_covBy : DenselyOrdered α ↔ ∀ a b : α, ¬a ⋖ b :=
⟨fun h _ _ => @not_covBy _ _ _ _ h, fun h =>
⟨fun _ _ hab => exists_lt_lt_of_not_covBy hab <| h _ _⟩⟩
@[deprecated (since := "2024-04-04")]
alias densely_ordered_iff_forall_not_covBy := denselyOrdered_iff_forall_not_covBy
@[simp]
theorem toDual_covBy_toDual_iff : toDual b ⋖ toDual a ↔ a ⋖ b :=
and_congr_right' <| forall_congr' fun _ => forall_swap
@[simp]
theorem ofDual_covBy_ofDual_iff {a b : αᵒᵈ} : ofDual a ⋖ ofDual b ↔ b ⋖ a :=
and_congr_right' <| forall_congr' fun _ => forall_swap
alias ⟨_, CovBy.toDual⟩ := toDual_covBy_toDual_iff
alias ⟨_, CovBy.ofDual⟩ := ofDual_covBy_ofDual_iff
end LT
section Preorder
variable [Preorder α] [Preorder β] {a b c : α}
theorem CovBy.le (h : a ⋖ b) : a ≤ b :=
h.1.le
protected theorem CovBy.ne (h : a ⋖ b) : a ≠ b :=
h.lt.ne
theorem CovBy.ne' (h : a ⋖ b) : b ≠ a :=
h.lt.ne'
protected theorem CovBy.wcovBy (h : a ⋖ b) : a ⩿ b :=
⟨h.le, h.2⟩
theorem WCovBy.covBy_of_not_le (h : a ⩿ b) (h2 : ¬b ≤ a) : a ⋖ b :=
⟨h.le.lt_of_not_le h2, h.2⟩
theorem WCovBy.covBy_of_lt (h : a ⩿ b) (h2 : a < b) : a ⋖ b :=
⟨h2, h.2⟩
lemma CovBy.of_le_of_lt (hac : a ⋖ c) (hab : a ≤ b) (hbc : b < c) : b ⋖ c :=
⟨hbc, fun _x hbx hxc ↦ hac.2 (hab.trans_lt hbx) hxc⟩
lemma CovBy.of_lt_of_le (hac : a ⋖ c) (hab : a < b) (hbc : b ≤ c) : a ⋖ b :=
⟨hab, fun _x hax hxb ↦ hac.2 hax <| hxb.trans_le hbc⟩
theorem not_covBy_of_lt_of_lt (h₁ : a < b) (h₂ : b < c) : ¬a ⋖ c :=
(not_covBy_iff (h₁.trans h₂)).2 ⟨b, h₁, h₂⟩
theorem covBy_iff_wcovBy_and_lt : a ⋖ b ↔ a ⩿ b ∧ a < b :=
⟨fun h => ⟨h.wcovBy, h.lt⟩, fun h => h.1.covBy_of_lt h.2⟩
theorem covBy_iff_wcovBy_and_not_le : a ⋖ b ↔ a ⩿ b ∧ ¬b ≤ a :=
⟨fun h => ⟨h.wcovBy, h.lt.not_le⟩, fun h => h.1.covBy_of_not_le h.2⟩
theorem wcovBy_iff_covBy_or_le_and_le : a ⩿ b ↔ a ⋖ b ∨ a ≤ b ∧ b ≤ a :=
⟨fun h => or_iff_not_imp_right.mpr fun h' => h.covBy_of_not_le fun hba => h' ⟨h.le, hba⟩,
fun h' => h'.elim (fun h => h.wcovBy) fun h => h.1.wcovBy_of_le h.2⟩
alias ⟨WCovBy.covBy_or_le_and_le, _⟩ := wcovBy_iff_covBy_or_le_and_le
theorem AntisymmRel.trans_covBy (hab : AntisymmRel (· ≤ ·) a b) (hbc : b ⋖ c) : a ⋖ c :=
⟨hab.1.trans_lt hbc.lt, fun _ had hdc => hbc.2 (hab.2.trans_lt had) hdc⟩
theorem covBy_congr_left (hab : AntisymmRel (· ≤ ·) a b) : a ⋖ c ↔ b ⋖ c :=
⟨hab.symm.trans_covBy, hab.trans_covBy⟩
theorem CovBy.trans_antisymmRel (hab : a ⋖ b) (hbc : AntisymmRel (· ≤ ·) b c) : a ⋖ c :=
⟨hab.lt.trans_le hbc.1, fun _ had hdb => hab.2 had <| hdb.trans_le hbc.2⟩
theorem covBy_congr_right (hab : AntisymmRel (· ≤ ·) a b) : c ⋖ a ↔ c ⋖ b :=
⟨fun h => h.trans_antisymmRel hab, fun h => h.trans_antisymmRel hab.symm⟩
instance : IsNonstrictStrictOrder α (· ⩿ ·) (· ⋖ ·) :=
⟨fun _ _ =>
covBy_iff_wcovBy_and_not_le.trans <| and_congr_right fun h => h.wcovBy_iff_le.not.symm⟩
instance CovBy.isIrrefl : IsIrrefl α (· ⋖ ·) :=
⟨fun _ ha => ha.ne rfl⟩
theorem CovBy.Ioo_eq (h : a ⋖ b) : Ioo a b = ∅ :=
h.wcovBy.Ioo_eq
theorem covBy_iff_Ioo_eq : a ⋖ b ↔ a < b ∧ Ioo a b = ∅ :=
and_congr_right' <| by simp [eq_empty_iff_forall_not_mem]
theorem CovBy.of_image (f : α ↪o β) (h : f a ⋖ f b) : a ⋖ b :=
⟨f.lt_iff_lt.mp h.lt, fun _ hac hcb => h.2 (f.lt_iff_lt.mpr hac) (f.lt_iff_lt.mpr hcb)⟩
theorem CovBy.image (f : α ↪o β) (hab : a ⋖ b) (h : (range f).OrdConnected) : f a ⋖ f b :=
(hab.wcovBy.image f h).covBy_of_lt <| f.strictMono hab.lt
theorem Set.OrdConnected.apply_covBy_apply_iff (f : α ↪o β) (h : (range f).OrdConnected) :
f a ⋖ f b ↔ a ⋖ b :=
⟨CovBy.of_image f, fun hab => hab.image f h⟩
@[simp]
theorem apply_covBy_apply_iff {E : Type*} [EquivLike E α β] [OrderIsoClass E α β] (e : E) :
e a ⋖ e b ↔ a ⋖ b :=
(ordConnected_range (e : α ≃o β)).apply_covBy_apply_iff ((e : α ≃o β) : α ↪o β)
theorem covBy_of_eq_or_eq (hab : a < b) (h : ∀ c, a ≤ c → c ≤ b → c = a ∨ c = b) : a ⋖ b :=
⟨hab, fun c ha hb => (h c ha.le hb.le).elim ha.ne' hb.ne⟩
end Preorder
section PartialOrder
variable [PartialOrder α] {a b c : α}
theorem WCovBy.covBy_of_ne (h : a ⩿ b) (h2 : a ≠ b) : a ⋖ b :=
⟨h.le.lt_of_ne h2, h.2⟩
theorem covBy_iff_wcovBy_and_ne : a ⋖ b ↔ a ⩿ b ∧ a ≠ b :=
⟨fun h => ⟨h.wcovBy, h.ne⟩, fun h => h.1.covBy_of_ne h.2⟩
theorem wcovBy_iff_covBy_or_eq : a ⩿ b ↔ a ⋖ b ∨ a = b := by
rw [le_antisymm_iff, wcovBy_iff_covBy_or_le_and_le]
theorem wcovBy_iff_eq_or_covBy : a ⩿ b ↔ a = b ∨ a ⋖ b :=
wcovBy_iff_covBy_or_eq.trans or_comm
alias ⟨WCovBy.covBy_or_eq, _⟩ := wcovBy_iff_covBy_or_eq
alias ⟨WCovBy.eq_or_covBy, _⟩ := wcovBy_iff_eq_or_covBy
theorem CovBy.eq_or_eq (h : a ⋖ b) (h2 : a ≤ c) (h3 : c ≤ b) : c = a ∨ c = b :=
h.wcovBy.eq_or_eq h2 h3
/-- An `iff` version of `CovBy.eq_or_eq` and `covBy_of_eq_or_eq`. -/
theorem covBy_iff_lt_and_eq_or_eq : a ⋖ b ↔ a < b ∧ ∀ c, a ≤ c → c ≤ b → c = a ∨ c = b :=
⟨fun h => ⟨h.lt, fun _ => h.eq_or_eq⟩, And.rec covBy_of_eq_or_eq⟩
theorem CovBy.Ico_eq (h : a ⋖ b) : Ico a b = {a} := by
rw [← Ioo_union_left h.lt, h.Ioo_eq, empty_union]
theorem CovBy.Ioc_eq (h : a ⋖ b) : Ioc a b = {b} := by
rw [← Ioo_union_right h.lt, h.Ioo_eq, empty_union]
theorem CovBy.Icc_eq (h : a ⋖ b) : Icc a b = {a, b} :=
h.wcovBy.Icc_eq
end PartialOrder
section LinearOrder
variable [LinearOrder α] {a b c : α}
theorem CovBy.Ioi_eq (h : a ⋖ b) : Ioi a = Ici b := by
rw [← Ioo_union_Ici_eq_Ioi h.lt, h.Ioo_eq, empty_union]
theorem CovBy.Iio_eq (h : a ⋖ b) : Iio b = Iic a := by
rw [← Iic_union_Ioo_eq_Iio h.lt, h.Ioo_eq, union_empty]
theorem WCovBy.le_of_lt (hab : a ⩿ b) (hcb : c < b) : c ≤ a :=
not_lt.1 fun hac => hab.2 hac hcb
theorem WCovBy.ge_of_gt (hab : a ⩿ b) (hac : a < c) : b ≤ c :=
not_lt.1 <| hab.2 hac
theorem CovBy.le_of_lt (hab : a ⋖ b) : c < b → c ≤ a :=
hab.wcovBy.le_of_lt
theorem CovBy.ge_of_gt (hab : a ⋖ b) : a < c → b ≤ c :=
hab.wcovBy.ge_of_gt
theorem CovBy.unique_left (ha : a ⋖ c) (hb : b ⋖ c) : a = b :=
(hb.le_of_lt ha.lt).antisymm <| ha.le_of_lt hb.lt
theorem CovBy.unique_right (hb : a ⋖ b) (hc : a ⋖ c) : b = c :=
(hb.ge_of_gt hc.lt).antisymm <| hc.ge_of_gt hb.lt
/-- If `a`, `b`, `c` are consecutive and `a < x < c` then `x = b`. -/
theorem CovBy.eq_of_between {x : α} (hab : a ⋖ b) (hbc : b ⋖ c) (hax : a < x) (hxc : x < c) :
x = b :=
le_antisymm (le_of_not_lt fun h => hbc.2 h hxc) (le_of_not_lt <| hab.2 hax)
/-- If `a < b` then there exist `a' > a` and `b' < b` such that `Set.Iio a'` is strictly to the left
of `Set.Ioi b'`. -/
lemma LT.lt.exists_disjoint_Iio_Ioi (h : a < b) :
∃ a' > a, ∃ b' < b, ∀ x < a', ∀ y > b', x < y := by
by_cases h' : a ⋖ b
· exact ⟨b, h, a, h, fun x hx y hy => hx.trans_le <| h'.ge_of_gt hy⟩
· rcases h.exists_lt_lt h' with ⟨c, ha, hb⟩
exact ⟨c, ha, c, hb, fun _ h₁ _ => lt_trans h₁⟩
end LinearOrder
namespace Set
variable {s t : Set α} {a : α}
@[simp] lemma wcovBy_insert (x : α) (s : Set α) : s ⩿ insert x s := by
refine wcovBy_of_eq_or_eq (subset_insert x s) fun t hst h2t => ?_
by_cases h : x ∈ t
· exact Or.inr (subset_antisymm h2t <| insert_subset_iff.mpr ⟨h, hst⟩)
· refine Or.inl (subset_antisymm ?_ hst)
rwa [← diff_singleton_eq_self h, diff_singleton_subset_iff]
@[simp] lemma sdiff_singleton_wcovBy (s : Set α) (a : α) : s \ {a} ⩿ s := by
by_cases ha : a ∈ s
· convert wcovBy_insert a _
ext
simp [ha]
· simp [ha]
@[simp] lemma covBy_insert (ha : a ∉ s) : s ⋖ insert a s :=
(wcovBy_insert _ _).covBy_of_lt <| ssubset_insert ha
@[simp] lemma sdiff_singleton_covBy (ha : a ∈ s) : s \ {a} ⋖ s :=
⟨sdiff_lt (singleton_subset_iff.2 ha) <| singleton_ne_empty _, (sdiff_singleton_wcovBy _ _).2⟩
lemma _root_.CovBy.exists_set_insert (h : s ⋖ t) : ∃ a ∉ s, insert a s = t :=
let ⟨a, ha, hst⟩ := ssubset_iff_insert.1 h.lt
⟨a, ha, (hst.eq_of_not_ssuperset <| h.2 <| ssubset_insert ha).symm⟩
lemma _root_.CovBy.exists_set_sdiff_singleton (h : s ⋖ t) : ∃ a ∈ t, t \ {a} = s :=
let ⟨a, ha, hst⟩ := ssubset_iff_sdiff_singleton.1 h.lt
⟨a, ha, (hst.eq_of_not_ssubset fun h' ↦ h.2 h' <|
sdiff_lt (singleton_subset_iff.2 ha) <| singleton_ne_empty _).symm⟩
lemma covBy_iff_exists_insert : s ⋖ t ↔ ∃ a ∉ s, insert a s = t :=
⟨CovBy.exists_set_insert, by rintro ⟨a, ha, rfl⟩; exact covBy_insert ha⟩
lemma covBy_iff_exists_sdiff_singleton : s ⋖ t ↔ ∃ a ∈ t, t \ {a} = s :=
⟨CovBy.exists_set_sdiff_singleton, by rintro ⟨a, ha, rfl⟩; exact sdiff_singleton_covBy ha⟩
end Set
section Relation
open Relation
lemma wcovBy_eq_reflGen_covBy [PartialOrder α] : ((· : α) ⩿ ·) = ReflGen (· ⋖ ·) := by
ext x y; simp_rw [wcovBy_iff_eq_or_covBy, @eq_comm _ x, reflGen_iff]
lemma transGen_wcovBy_eq_reflTransGen_covBy [PartialOrder α] :
TransGen ((· : α) ⩿ ·) = ReflTransGen (· ⋖ ·) := by
rw [wcovBy_eq_reflGen_covBy, transGen_reflGen]
lemma reflTransGen_wcovBy_eq_reflTransGen_covBy [PartialOrder α] :
ReflTransGen ((· : α) ⩿ ·) = ReflTransGen (· ⋖ ·) := by
rw [wcovBy_eq_reflGen_covBy, reflTransGen_reflGen]
end Relation
namespace Prod
variable [PartialOrder α] [PartialOrder β] {a a₁ a₂ : α} {b b₁ b₂ : β} {x y : α × β}
@[simp]
theorem swap_wcovBy_swap : x.swap ⩿ y.swap ↔ x ⩿ y :=
apply_wcovBy_apply_iff (OrderIso.prodComm : α × β ≃o β × α)
@[simp]
theorem swap_covBy_swap : x.swap ⋖ y.swap ↔ x ⋖ y :=
apply_covBy_apply_iff (OrderIso.prodComm : α × β ≃o β × α)
theorem fst_eq_or_snd_eq_of_wcovBy : x ⩿ y → x.1 = y.1 ∨ x.2 = y.2 := by
refine fun h => of_not_not fun hab => ?_
push_neg at hab
exact
h.2 (mk_lt_mk.2 <| Or.inl ⟨hab.1.lt_of_le h.1.1, le_rfl⟩)
(mk_lt_mk.2 <| Or.inr ⟨le_rfl, hab.2.lt_of_le h.1.2⟩)
theorem _root_.WCovBy.fst (h : x ⩿ y) : x.1 ⩿ y.1 :=
⟨h.1.1, fun _ h₁ h₂ => h.2 (mk_lt_mk_iff_left.2 h₁) ⟨⟨h₂.le, h.1.2⟩, fun hc => h₂.not_le hc.1⟩⟩
theorem _root_.WCovBy.snd (h : x ⩿ y) : x.2 ⩿ y.2 :=
⟨h.1.2, fun _ h₁ h₂ => h.2 (mk_lt_mk_iff_right.2 h₁) ⟨⟨h.1.1, h₂.le⟩, fun hc => h₂.not_le hc.2⟩⟩
theorem mk_wcovBy_mk_iff_left : (a₁, b) ⩿ (a₂, b) ↔ a₁ ⩿ a₂ := by
refine ⟨WCovBy.fst, (And.imp mk_le_mk_iff_left.2) fun h c h₁ h₂ => ?_⟩
have : c.2 = b := h₂.le.2.antisymm h₁.le.2
rw [← @Prod.mk.eta _ _ c, this, mk_lt_mk_iff_left] at h₁ h₂
exact h h₁ h₂
theorem mk_wcovBy_mk_iff_right : (a, b₁) ⩿ (a, b₂) ↔ b₁ ⩿ b₂ :=
swap_wcovBy_swap.trans mk_wcovBy_mk_iff_left
theorem mk_covBy_mk_iff_left : (a₁, b) ⋖ (a₂, b) ↔ a₁ ⋖ a₂ := by
simp_rw [covBy_iff_wcovBy_and_lt, mk_wcovBy_mk_iff_left, mk_lt_mk_iff_left]
theorem mk_covBy_mk_iff_right : (a, b₁) ⋖ (a, b₂) ↔ b₁ ⋖ b₂ := by
simp_rw [covBy_iff_wcovBy_and_lt, mk_wcovBy_mk_iff_right, mk_lt_mk_iff_right]
theorem mk_wcovBy_mk_iff : (a₁, b₁) ⩿ (a₂, b₂) ↔ a₁ ⩿ a₂ ∧ b₁ = b₂ ∨ b₁ ⩿ b₂ ∧ a₁ = a₂ := by
refine ⟨fun h => ?_, ?_⟩
· obtain rfl | rfl : a₁ = a₂ ∨ b₁ = b₂ := fst_eq_or_snd_eq_of_wcovBy h
· exact Or.inr ⟨mk_wcovBy_mk_iff_right.1 h, rfl⟩
· exact Or.inl ⟨mk_wcovBy_mk_iff_left.1 h, rfl⟩
· rintro (⟨h, rfl⟩ | ⟨h, rfl⟩)
· exact mk_wcovBy_mk_iff_left.2 h
· exact mk_wcovBy_mk_iff_right.2 h
theorem mk_covBy_mk_iff : (a₁, b₁) ⋖ (a₂, b₂) ↔ a₁ ⋖ a₂ ∧ b₁ = b₂ ∨ b₁ ⋖ b₂ ∧ a₁ = a₂ := by
refine ⟨fun h => ?_, ?_⟩
· obtain rfl | rfl : a₁ = a₂ ∨ b₁ = b₂ := fst_eq_or_snd_eq_of_wcovBy h.wcovBy
· exact Or.inr ⟨mk_covBy_mk_iff_right.1 h, rfl⟩
· exact Or.inl ⟨mk_covBy_mk_iff_left.1 h, rfl⟩
· rintro (⟨h, rfl⟩ | ⟨h, rfl⟩)
· exact mk_covBy_mk_iff_left.2 h
· exact mk_covBy_mk_iff_right.2 h
theorem wcovBy_iff : x ⩿ y ↔ x.1 ⩿ y.1 ∧ x.2 = y.2 ∨ x.2 ⩿ y.2 ∧ x.1 = y.1 := by
cases x
cases y
exact mk_wcovBy_mk_iff
theorem covBy_iff : x ⋖ y ↔ x.1 ⋖ y.1 ∧ x.2 = y.2 ∨ x.2 ⋖ y.2 ∧ x.1 = y.1 := by
cases x
cases y
exact mk_covBy_mk_iff
end Prod
|
Order\Defs.lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.Init.Algebra.Classes
import Mathlib.Data.Ordering.Basic
import Mathlib.Tactic.SplitIfs
import Mathlib.Tactic.TypeStar
import Batteries.Classes.Order
/-!
# Orders
Defines classes for preorders, partial orders, and linear orders
and proves some basic lemmas about them.
-/
universe u
variable {α : Type u}
section Preorder
/-!
### Definition of `Preorder` and lemmas about types with a `Preorder`
-/
/-- A preorder is a reflexive, transitive relation `≤` with `a < b` defined in the obvious way. -/
class Preorder (α : Type u) extends LE α, LT α where
le_refl : ∀ a : α, a ≤ a
le_trans : ∀ a b c : α, a ≤ b → b ≤ c → a ≤ c
lt := fun a b => a ≤ b ∧ ¬b ≤ a
lt_iff_le_not_le : ∀ a b : α, a < b ↔ a ≤ b ∧ ¬b ≤ a := by intros; rfl
variable [Preorder α]
/-- The relation `≤` on a preorder is reflexive. -/
@[refl]
theorem le_refl : ∀ a : α, a ≤ a :=
Preorder.le_refl
/-- A version of `le_refl` where the argument is implicit -/
theorem le_rfl {a : α} : a ≤ a :=
le_refl a
/-- The relation `≤` on a preorder is transitive. -/
@[trans]
theorem le_trans : ∀ {a b c : α}, a ≤ b → b ≤ c → a ≤ c :=
Preorder.le_trans _ _ _
theorem lt_iff_le_not_le : ∀ {a b : α}, a < b ↔ a ≤ b ∧ ¬b ≤ a :=
Preorder.lt_iff_le_not_le _ _
theorem lt_of_le_not_le : ∀ {a b : α}, a ≤ b → ¬b ≤ a → a < b
| _a, _b, hab, hba => lt_iff_le_not_le.mpr ⟨hab, hba⟩
theorem le_not_le_of_lt : ∀ {a b : α}, a < b → a ≤ b ∧ ¬b ≤ a
| _a, _b, hab => lt_iff_le_not_le.mp hab
theorem le_of_eq {a b : α} : a = b → a ≤ b := fun h => h ▸ le_refl a
@[trans]
theorem ge_trans : ∀ {a b c : α}, a ≥ b → b ≥ c → a ≥ c := fun h₁ h₂ => le_trans h₂ h₁
theorem lt_irrefl : ∀ a : α, ¬a < a
| _a, haa =>
match le_not_le_of_lt haa with
| ⟨h1, h2⟩ => h2 h1
theorem gt_irrefl : ∀ a : α, ¬a > a :=
lt_irrefl
@[trans]
theorem lt_trans : ∀ {a b c : α}, a < b → b < c → a < c
| _a, _b, _c, hab, hbc =>
match le_not_le_of_lt hab, le_not_le_of_lt hbc with
| ⟨hab, _hba⟩, ⟨hbc, hcb⟩ =>
lt_of_le_not_le (le_trans hab hbc) fun hca => hcb (le_trans hca hab)
@[trans]
theorem gt_trans : ∀ {a b c : α}, a > b → b > c → a > c := fun h₁ h₂ => lt_trans h₂ h₁
theorem ne_of_lt {a b : α} (h : a < b) : a ≠ b := fun he => absurd h (he ▸ lt_irrefl a)
theorem ne_of_gt {a b : α} (h : b < a) : a ≠ b := fun he => absurd h (he ▸ lt_irrefl a)
theorem lt_asymm {a b : α} (h : a < b) : ¬b < a := fun h1 : b < a => lt_irrefl a (lt_trans h h1)
theorem le_of_lt : ∀ {a b : α}, a < b → a ≤ b
| _a, _b, hab => (le_not_le_of_lt hab).left
@[trans]
theorem lt_of_lt_of_le : ∀ {a b c : α}, a < b → b ≤ c → a < c
| _a, _b, _c, hab, hbc =>
let ⟨hab, hba⟩ := le_not_le_of_lt hab
lt_of_le_not_le (le_trans hab hbc) fun hca => hba (le_trans hbc hca)
@[trans]
theorem lt_of_le_of_lt : ∀ {a b c : α}, a ≤ b → b < c → a < c
| _a, _b, _c, hab, hbc =>
let ⟨hbc, hcb⟩ := le_not_le_of_lt hbc
lt_of_le_not_le (le_trans hab hbc) fun hca => hcb (le_trans hca hab)
@[trans]
theorem gt_of_gt_of_ge {a b c : α} (h₁ : a > b) (h₂ : b ≥ c) : a > c :=
lt_of_le_of_lt h₂ h₁
@[trans]
theorem gt_of_ge_of_gt {a b c : α} (h₁ : a ≥ b) (h₂ : b > c) : a > c :=
lt_of_lt_of_le h₂ h₁
-- Porting note (#10754): new instance
instance (priority := 900) : @Trans α α α LE.le LE.le LE.le := ⟨le_trans⟩
instance (priority := 900) : @Trans α α α LT.lt LT.lt LT.lt := ⟨lt_trans⟩
instance (priority := 900) : @Trans α α α LT.lt LE.le LT.lt := ⟨lt_of_lt_of_le⟩
instance (priority := 900) : @Trans α α α LE.le LT.lt LT.lt := ⟨lt_of_le_of_lt⟩
instance (priority := 900) : @Trans α α α GE.ge GE.ge GE.ge := ⟨ge_trans⟩
instance (priority := 900) : @Trans α α α GT.gt GT.gt GT.gt := ⟨gt_trans⟩
instance (priority := 900) : @Trans α α α GT.gt GE.ge GT.gt := ⟨gt_of_gt_of_ge⟩
instance (priority := 900) : @Trans α α α GE.ge GT.gt GT.gt := ⟨gt_of_ge_of_gt⟩
theorem not_le_of_gt {a b : α} (h : a > b) : ¬a ≤ b :=
(le_not_le_of_lt h).right
theorem not_lt_of_ge {a b : α} (h : a ≥ b) : ¬a < b := fun hab => not_le_of_gt hab h
theorem le_of_lt_or_eq : ∀ {a b : α}, a < b ∨ a = b → a ≤ b
| _a, _b, Or.inl hab => le_of_lt hab
| _a, _b, Or.inr hab => hab ▸ le_refl _
theorem le_of_eq_or_lt {a b : α} (h : a = b ∨ a < b) : a ≤ b :=
Or.elim h le_of_eq le_of_lt
/-- `<` is decidable if `≤` is. -/
def decidableLTOfDecidableLE [@DecidableRel α (· ≤ ·)] : @DecidableRel α (· < ·)
| a, b =>
if hab : a ≤ b then
if hba : b ≤ a then isFalse fun hab' => not_le_of_gt hab' hba
else isTrue <| lt_of_le_not_le hab hba
else isFalse fun hab' => hab (le_of_lt hab')
end Preorder
section PartialOrder
/-!
### Definition of `PartialOrder` and lemmas about types with a partial order
-/
/-- A partial order is a reflexive, transitive, antisymmetric relation `≤`. -/
class PartialOrder (α : Type u) extends Preorder α where
le_antisymm : ∀ a b : α, a ≤ b → b ≤ a → a = b
variable [PartialOrder α]
theorem le_antisymm : ∀ {a b : α}, a ≤ b → b ≤ a → a = b :=
PartialOrder.le_antisymm _ _
alias eq_of_le_of_le := le_antisymm
theorem le_antisymm_iff {a b : α} : a = b ↔ a ≤ b ∧ b ≤ a :=
⟨fun e => ⟨le_of_eq e, le_of_eq e.symm⟩, fun ⟨h1, h2⟩ => le_antisymm h1 h2⟩
theorem lt_of_le_of_ne {a b : α} : a ≤ b → a ≠ b → a < b := fun h₁ h₂ =>
lt_of_le_not_le h₁ <| mt (le_antisymm h₁) h₂
/-- Equality is decidable if `≤` is. -/
def decidableEqOfDecidableLE [@DecidableRel α (· ≤ ·)] : DecidableEq α
| a, b =>
if hab : a ≤ b then
if hba : b ≤ a then isTrue (le_antisymm hab hba) else isFalse fun heq => hba (heq ▸ le_refl _)
else isFalse fun heq => hab (heq ▸ le_refl _)
namespace Decidable
variable [@DecidableRel α (· ≤ ·)]
theorem lt_or_eq_of_le {a b : α} (hab : a ≤ b) : a < b ∨ a = b :=
if hba : b ≤ a then Or.inr (le_antisymm hab hba) else Or.inl (lt_of_le_not_le hab hba)
theorem eq_or_lt_of_le {a b : α} (hab : a ≤ b) : a = b ∨ a < b :=
(lt_or_eq_of_le hab).symm
theorem le_iff_lt_or_eq {a b : α} : a ≤ b ↔ a < b ∨ a = b :=
⟨lt_or_eq_of_le, le_of_lt_or_eq⟩
end Decidable
attribute [local instance] Classical.propDecidable
theorem lt_or_eq_of_le {a b : α} : a ≤ b → a < b ∨ a = b :=
Decidable.lt_or_eq_of_le
theorem le_iff_lt_or_eq {a b : α} : a ≤ b ↔ a < b ∨ a = b :=
Decidable.le_iff_lt_or_eq
end PartialOrder
section LinearOrder
/-!
### Definition of `LinearOrder` and lemmas about types with a linear order
-/
/-- Default definition of `max`. -/
def maxDefault {α : Type u} [LE α] [DecidableRel ((· ≤ ·) : α → α → Prop)] (a b : α) :=
if a ≤ b then b else a
/-- Default definition of `min`. -/
def minDefault {α : Type u} [LE α] [DecidableRel ((· ≤ ·) : α → α → Prop)] (a b : α) :=
if a ≤ b then a else b
/-- This attempts to prove that a given instance of `compare` is equal to `compareOfLessAndEq` by
introducing the arguments and trying the following approaches in order:
1. seeing if `rfl` works
2. seeing if the `compare` at hand is nonetheless essentially `compareOfLessAndEq`, but, because of
implicit arguments, requires us to unfold the defs and split the `if`s in the definition of
`compareOfLessAndEq`
3. seeing if we can split by cases on the arguments, then see if the defs work themselves out
(useful when `compare` is defined via a `match` statement, as it is for `Bool`) -/
macro "compareOfLessAndEq_rfl" : tactic =>
`(tactic| (intros a b; first | rfl |
(simp only [compare, compareOfLessAndEq]; split_ifs <;> rfl) |
(induction a <;> induction b <;> simp (config := {decide := true}) only [])))
/-- A linear order is reflexive, transitive, antisymmetric and total relation `≤`.
We assume that every linear ordered type has decidable `(≤)`, `(<)`, and `(=)`. -/
class LinearOrder (α : Type u) extends PartialOrder α, Min α, Max α, Ord α :=
/-- A linear order is total. -/
le_total (a b : α) : a ≤ b ∨ b ≤ a
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
decidableLE : DecidableRel (· ≤ · : α → α → Prop)
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
decidableEq : DecidableEq α := @decidableEqOfDecidableLE _ _ decidableLE
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
decidableLT : DecidableRel (· < · : α → α → Prop) :=
@decidableLTOfDecidableLE _ _ decidableLE
min := fun a b => if a ≤ b then a else b
max := fun a b => if a ≤ b then b else a
/-- The minimum function is equivalent to the one you get from `minOfLe`. -/
min_def : ∀ a b, min a b = if a ≤ b then a else b := by intros; rfl
/-- The minimum function is equivalent to the one you get from `maxOfLe`. -/
max_def : ∀ a b, max a b = if a ≤ b then b else a := by intros; rfl
compare a b := compareOfLessAndEq a b
/-- Comparison via `compare` is equal to the canonical comparison given decidable `<` and `=`. -/
compare_eq_compareOfLessAndEq : ∀ a b, compare a b = compareOfLessAndEq a b := by
compareOfLessAndEq_rfl
variable [LinearOrder α]
attribute [local instance] LinearOrder.decidableLE
theorem le_total : ∀ a b : α, a ≤ b ∨ b ≤ a :=
LinearOrder.le_total
theorem le_of_not_ge {a b : α} : ¬a ≥ b → a ≤ b :=
Or.resolve_left (le_total b a)
theorem le_of_not_le {a b : α} : ¬a ≤ b → b ≤ a :=
Or.resolve_left (le_total a b)
theorem not_lt_of_gt {a b : α} (h : a > b) : ¬a < b :=
lt_asymm h
theorem lt_trichotomy (a b : α) : a < b ∨ a = b ∨ b < a :=
Or.elim (le_total a b)
(fun h : a ≤ b =>
Or.elim (Decidable.lt_or_eq_of_le h) (fun h : a < b => Or.inl h) fun h : a = b =>
Or.inr (Or.inl h))
fun h : b ≤ a =>
Or.elim (Decidable.lt_or_eq_of_le h) (fun h : b < a => Or.inr (Or.inr h)) fun h : b = a =>
Or.inr (Or.inl h.symm)
theorem le_of_not_lt {a b : α} (h : ¬b < a) : a ≤ b :=
match lt_trichotomy a b with
| Or.inl hlt => le_of_lt hlt
| Or.inr (Or.inl HEq) => HEq ▸ le_refl a
| Or.inr (Or.inr hgt) => absurd hgt h
theorem le_of_not_gt {a b : α} : ¬a > b → a ≤ b :=
le_of_not_lt
theorem lt_of_not_ge {a b : α} (h : ¬a ≥ b) : a < b :=
lt_of_le_not_le ((le_total _ _).resolve_right h) h
theorem lt_or_le (a b : α) : a < b ∨ b ≤ a :=
if hba : b ≤ a then Or.inr hba else Or.inl <| lt_of_not_ge hba
theorem le_or_lt (a b : α) : a ≤ b ∨ b < a :=
(lt_or_le b a).symm
theorem lt_or_ge : ∀ a b : α, a < b ∨ a ≥ b :=
lt_or_le
theorem le_or_gt : ∀ a b : α, a ≤ b ∨ a > b :=
le_or_lt
theorem lt_or_gt_of_ne {a b : α} (h : a ≠ b) : a < b ∨ a > b :=
match lt_trichotomy a b with
| Or.inl hlt => Or.inl hlt
| Or.inr (Or.inl HEq) => absurd HEq h
| Or.inr (Or.inr hgt) => Or.inr hgt
theorem ne_iff_lt_or_gt {a b : α} : a ≠ b ↔ a < b ∨ a > b :=
⟨lt_or_gt_of_ne, fun o => Or.elim o ne_of_lt ne_of_gt⟩
theorem lt_iff_not_ge (x y : α) : x < y ↔ ¬x ≥ y :=
⟨not_le_of_gt, lt_of_not_ge⟩
@[simp]
theorem not_lt {a b : α} : ¬a < b ↔ b ≤ a :=
⟨le_of_not_gt, not_lt_of_ge⟩
@[simp]
theorem not_le {a b : α} : ¬a ≤ b ↔ b < a :=
(lt_iff_not_ge _ _).symm
instance (priority := 900) (a b : α) : Decidable (a < b) :=
LinearOrder.decidableLT a b
instance (priority := 900) (a b : α) : Decidable (a ≤ b) :=
LinearOrder.decidableLE a b
instance (priority := 900) (a b : α) : Decidable (a = b) :=
LinearOrder.decidableEq a b
theorem eq_or_lt_of_not_lt {a b : α} (h : ¬a < b) : a = b ∨ b < a :=
if h₁ : a = b then Or.inl h₁ else Or.inr (lt_of_not_ge fun hge => h (lt_of_le_of_ne hge h₁))
instance : IsTotalPreorder α (· ≤ ·) where
trans := @le_trans _ _
total := le_total
-- TODO(Leo): decide whether we should keep this instance or not
instance isStrictWeakOrder_of_linearOrder : IsStrictWeakOrder α (· < ·) :=
have : IsTotalPreorder α (· ≤ ·) := by infer_instance -- Porting note: added
isStrictWeakOrder_of_isTotalPreorder lt_iff_not_ge
-- TODO(Leo): decide whether we should keep this instance or not
instance isStrictTotalOrder_of_linearOrder : IsStrictTotalOrder α (· < ·) where
trichotomous := lt_trichotomy
/-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order. -/
def ltByCases (x y : α) {P : Sort*} (h₁ : x < y → P) (h₂ : x = y → P) (h₃ : y < x → P) : P :=
if h : x < y then h₁ h
else if h' : y < x then h₃ h' else h₂ (le_antisymm (le_of_not_gt h') (le_of_not_gt h))
theorem le_imp_le_of_lt_imp_lt {α β} [Preorder α] [LinearOrder β] {a b : α} {c d : β}
(H : d < c → b < a) (h : a ≤ b) : c ≤ d :=
le_of_not_lt fun h' => not_le_of_gt (H h') h
-- Porting note: new
section Ord
theorem compare_lt_iff_lt {a b : α} : (compare a b = .lt) ↔ a < b := by
rw [LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq]
split_ifs <;> simp only [*, lt_irrefl]
theorem compare_gt_iff_gt {a b : α} : (compare a b = .gt) ↔ a > b := by
rw [LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq]
split_ifs <;> simp only [*, lt_irrefl, not_lt_of_gt]
case _ h₁ h₂ =>
have h : b < a := lt_trichotomy a b |>.resolve_left h₁ |>.resolve_left h₂
exact true_iff_iff.2 h
theorem compare_eq_iff_eq {a b : α} : (compare a b = .eq) ↔ a = b := by
rw [LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq]
split_ifs <;> try simp only
case _ h => exact false_iff_iff.2 <| ne_iff_lt_or_gt.2 <| .inl h
case _ _ h => exact true_iff_iff.2 h
case _ _ h => exact false_iff_iff.2 h
theorem compare_le_iff_le {a b : α} : (compare a b ≠ .gt) ↔ a ≤ b := by
cases h : compare a b <;> simp
· exact le_of_lt <| compare_lt_iff_lt.1 h
· exact le_of_eq <| compare_eq_iff_eq.1 h
· exact compare_gt_iff_gt.1 h
theorem compare_ge_iff_ge {a b : α} : (compare a b ≠ .lt) ↔ a ≥ b := by
cases h : compare a b <;> simp
· exact compare_lt_iff_lt.1 h
· exact le_of_eq <| (·.symm) <| compare_eq_iff_eq.1 h
· exact le_of_lt <| compare_gt_iff_gt.1 h
theorem compare_iff (a b : α) {o : Ordering} : compare a b = o ↔ o.toRel a b := by
cases o <;> simp only [Ordering.toRel]
· exact compare_lt_iff_lt
· exact compare_eq_iff_eq
· exact compare_gt_iff_gt
instance : Batteries.TransCmp (compare (α := α)) where
symm a b := by
cases h : compare a b <;>
simp only [Ordering.swap] <;> symm
· exact compare_gt_iff_gt.2 <| compare_lt_iff_lt.1 h
· exact compare_eq_iff_eq.2 <| compare_eq_iff_eq.1 h |>.symm
· exact compare_lt_iff_lt.2 <| compare_gt_iff_gt.1 h
le_trans := fun h₁ h₂ ↦
compare_le_iff_le.2 <| le_trans (compare_le_iff_le.1 h₁) (compare_le_iff_le.1 h₂)
end Ord
end LinearOrder
|
Order\Directed.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yaël Dillies
-/
import Mathlib.Data.Set.Image
/-!
# Directed indexed families and sets
This file defines directed indexed families and directed sets. An indexed family/set is
directed iff each pair of elements has a shared upper bound.
## Main declarations
* `Directed r f`: Predicate stating that the indexed family `f` is `r`-directed.
* `DirectedOn r s`: Predicate stating that the set `s` is `r`-directed.
* `IsDirected α r`: Prop-valued mixin stating that `α` is `r`-directed. Follows the style of the
unbundled relation classes such as `IsTotal`.
* `ScottContinuous`: Predicate stating that a function between preorders preserves `IsLUB` on
directed sets.
## TODO
Define connected orders (the transitive symmetric closure of `≤` is everything) and show that
(co)directed orders are connected.
## References
* [Gierz et al, *A Compendium of Continuous Lattices*][GierzEtAl1980]
-/
open Function
universe u v w
variable {α : Type u} {β : Type v} {ι : Sort w} (r r' s : α → α → Prop)
/-- Local notation for a relation -/
local infixl:50 " ≼ " => r
/-- A family of elements of α is directed (with respect to a relation `≼` on α)
if there is a member of the family `≼`-above any pair in the family. -/
def Directed (f : ι → α) :=
∀ x y, ∃ z, f x ≼ f z ∧ f y ≼ f z
/-- A subset of α is directed if there is an element of the set `≼`-above any
pair of elements in the set. -/
def DirectedOn (s : Set α) :=
∀ x ∈ s, ∀ y ∈ s, ∃ z ∈ s, x ≼ z ∧ y ≼ z
variable {r r'}
theorem directedOn_iff_directed {s} : @DirectedOn α r s ↔ Directed r (Subtype.val : s → α) := by
simp only [DirectedOn, Directed, Subtype.exists, exists_and_left, exists_prop, Subtype.forall]
exact forall₂_congr fun x _ => by simp [And.comm, and_assoc]
alias ⟨DirectedOn.directed_val, _⟩ := directedOn_iff_directed
theorem directedOn_range {f : ι → α} : Directed r f ↔ DirectedOn r (Set.range f) := by
simp_rw [Directed, DirectedOn, Set.forall_mem_range, Set.exists_range_iff]
-- Porting note: This alias was misplaced in `order/compactly_generated.lean` in mathlib3
alias ⟨Directed.directedOn_range, _⟩ := directedOn_range
-- Porting note: `attribute [protected]` doesn't work
-- attribute [protected] Directed.directedOn_range
theorem directedOn_image {s : Set β} {f : β → α} :
DirectedOn r (f '' s) ↔ DirectedOn (f ⁻¹'o r) s := by
simp only [DirectedOn, Set.mem_image, exists_exists_and_eq_and, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂, Order.Preimage]
theorem DirectedOn.mono' {s : Set α} (hs : DirectedOn r s)
(h : ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → r a b → r' a b) : DirectedOn r' s := fun _ hx _ hy =>
let ⟨z, hz, hxz, hyz⟩ := hs _ hx _ hy
⟨z, hz, h hx hz hxz, h hy hz hyz⟩
theorem DirectedOn.mono {s : Set α} (h : DirectedOn r s) (H : ∀ ⦃a b⦄, r a b → r' a b) :
DirectedOn r' s :=
h.mono' fun _ _ _ _ h ↦ H h
theorem directed_comp {ι} {f : ι → β} {g : β → α} : Directed r (g ∘ f) ↔ Directed (g ⁻¹'o r) f :=
Iff.rfl
theorem Directed.mono {s : α → α → Prop} {ι} {f : ι → α} (H : ∀ a b, r a b → s a b)
(h : Directed r f) : Directed s f := fun a b =>
let ⟨c, h₁, h₂⟩ := h a b
⟨c, H _ _ h₁, H _ _ h₂⟩
-- Porting note: due to some interaction with the local notation, `r` became explicit here in lean3
theorem Directed.mono_comp (r : α → α → Prop) {ι} {rb : β → β → Prop} {g : α → β} {f : ι → α}
(hg : ∀ ⦃x y⦄, r x y → rb (g x) (g y)) (hf : Directed r f) : Directed rb (g ∘ f) :=
directed_comp.2 <| hf.mono hg
/-- A set stable by supremum is `≤`-directed. -/
theorem directedOn_of_sup_mem [SemilatticeSup α] {S : Set α}
(H : ∀ ⦃i j⦄, i ∈ S → j ∈ S → i ⊔ j ∈ S) : DirectedOn (· ≤ ·) S := fun a ha b hb =>
⟨a ⊔ b, H ha hb, le_sup_left, le_sup_right⟩
theorem Directed.extend_bot [Preorder α] [OrderBot α] {e : ι → β} {f : ι → α}
(hf : Directed (· ≤ ·) f) (he : Function.Injective e) :
Directed (· ≤ ·) (Function.extend e f ⊥) := by
intro a b
rcases (em (∃ i, e i = a)).symm with (ha | ⟨i, rfl⟩)
· use b
simp [Function.extend_apply' _ _ _ ha]
rcases (em (∃ i, e i = b)).symm with (hb | ⟨j, rfl⟩)
· use e i
simp [Function.extend_apply' _ _ _ hb]
rcases hf i j with ⟨k, hi, hj⟩
use e k
simp only [he.extend_apply, *, true_and_iff]
/-- A set stable by infimum is `≥`-directed. -/
theorem directedOn_of_inf_mem [SemilatticeInf α] {S : Set α}
(H : ∀ ⦃i j⦄, i ∈ S → j ∈ S → i ⊓ j ∈ S) : DirectedOn (· ≥ ·) S :=
directedOn_of_sup_mem (α := αᵒᵈ) H
theorem IsTotal.directed [IsTotal α r] (f : ι → α) : Directed r f := fun i j =>
Or.casesOn (total_of r (f i) (f j)) (fun h => ⟨j, h, refl _⟩) fun h => ⟨i, refl _, h⟩
/-- `IsDirected α r` states that for any elements `a`, `b` there exists an element `c` such that
`r a c` and `r b c`. -/
class IsDirected (α : Type*) (r : α → α → Prop) : Prop where
/-- For every pair of elements `a` and `b` there is a `c` such that `r a c` and `r b c` -/
directed (a b : α) : ∃ c, r a c ∧ r b c
theorem directed_of (r : α → α → Prop) [IsDirected α r] (a b : α) : ∃ c, r a c ∧ r b c :=
IsDirected.directed _ _
theorem directed_id [IsDirected α r] : Directed r id := directed_of r
theorem directed_id_iff : Directed r id ↔ IsDirected α r :=
⟨fun h => ⟨h⟩, @directed_id _ _⟩
theorem directedOn_univ [IsDirected α r] : DirectedOn r Set.univ := fun a _ b _ =>
let ⟨c, hc⟩ := directed_of r a b
⟨c, trivial, hc⟩
theorem directedOn_univ_iff : DirectedOn r Set.univ ↔ IsDirected α r :=
⟨fun h =>
⟨fun a b =>
let ⟨c, _, hc⟩ := h a trivial b trivial
⟨c, hc⟩⟩,
@directedOn_univ _ _⟩
-- see Note [lower instance priority]
instance (priority := 100) IsTotal.to_isDirected [IsTotal α r] : IsDirected α r :=
directed_id_iff.1 <| IsTotal.directed _
theorem isDirected_mono [IsDirected α r] (h : ∀ ⦃a b⦄, r a b → s a b) : IsDirected α s :=
⟨fun a b =>
let ⟨c, ha, hb⟩ := IsDirected.directed a b
⟨c, h ha, h hb⟩⟩
theorem exists_ge_ge [LE α] [IsDirected α (· ≤ ·)] (a b : α) : ∃ c, a ≤ c ∧ b ≤ c :=
directed_of (· ≤ ·) a b
theorem exists_le_le [LE α] [IsDirected α (· ≥ ·)] (a b : α) : ∃ c, c ≤ a ∧ c ≤ b :=
directed_of (· ≥ ·) a b
instance OrderDual.isDirected_ge [LE α] [IsDirected α (· ≤ ·)] : IsDirected αᵒᵈ (· ≥ ·) := by
assumption
instance OrderDual.isDirected_le [LE α] [IsDirected α (· ≥ ·)] : IsDirected αᵒᵈ (· ≤ ·) := by
assumption
/-- A monotone function on an upwards-directed type is directed. -/
theorem directed_of_isDirected_le [LE α] [IsDirected α (· ≤ ·)] {f : α → β} {r : β → β → Prop}
(H : ∀ ⦃i j⦄, i ≤ j → r (f i) (f j)) : Directed r f :=
directed_id.mono_comp H
theorem Monotone.directed_le [Preorder α] [IsDirected α (· ≤ ·)] [Preorder β] {f : α → β} :
Monotone f → Directed (· ≤ ·) f :=
directed_of_isDirected_le
theorem Antitone.directed_ge [Preorder α] [IsDirected α (· ≤ ·)] [Preorder β] {f : α → β}
(hf : Antitone f) : Directed (· ≥ ·) f :=
directed_of_isDirected_le hf
/-- An antitone function on a downwards-directed type is directed. -/
theorem directed_of_isDirected_ge [LE α] [IsDirected α (· ≥ ·)] {r : β → β → Prop} {f : α → β}
(hf : ∀ a₁ a₂, a₁ ≤ a₂ → r (f a₂) (f a₁)) : Directed r f :=
directed_of_isDirected_le (α := αᵒᵈ) fun _ _ ↦ hf _ _
theorem Monotone.directed_ge [Preorder α] [IsDirected α (· ≥ ·)] [Preorder β] {f : α → β}
(hf : Monotone f) : Directed (· ≥ ·) f :=
directed_of_isDirected_ge hf
theorem Antitone.directed_le [Preorder α] [IsDirected α (· ≥ ·)] [Preorder β] {f : α → β}
(hf : Antitone f) : Directed (· ≤ ·) f :=
directed_of_isDirected_ge hf
section Reflexive
protected theorem DirectedOn.insert (h : Reflexive r) (a : α) {s : Set α} (hd : DirectedOn r s)
(ha : ∀ b ∈ s, ∃ c ∈ s, a ≼ c ∧ b ≼ c) : DirectedOn r (insert a s) := by
rintro x (rfl | hx) y (rfl | hy)
· exact ⟨y, Set.mem_insert _ _, h _, h _⟩
· obtain ⟨w, hws, hwr⟩ := ha y hy
exact ⟨w, Set.mem_insert_of_mem _ hws, hwr⟩
· obtain ⟨w, hws, hwr⟩ := ha x hx
exact ⟨w, Set.mem_insert_of_mem _ hws, hwr.symm⟩
· obtain ⟨w, hws, hwr⟩ := hd x hx y hy
exact ⟨w, Set.mem_insert_of_mem _ hws, hwr⟩
theorem directedOn_singleton (h : Reflexive r) (a : α) : DirectedOn r ({a} : Set α) :=
fun x hx _ hy => ⟨x, hx, h _, hx.symm ▸ hy.symm ▸ h _⟩
theorem directedOn_pair (h : Reflexive r) {a b : α} (hab : a ≼ b) : DirectedOn r ({a, b} : Set α) :=
(directedOn_singleton h _).insert h _ fun c hc => ⟨c, hc, hc.symm ▸ hab, h _⟩
theorem directedOn_pair' (h : Reflexive r) {a b : α} (hab : a ≼ b) :
DirectedOn r ({b, a} : Set α) := by
rw [Set.pair_comm]
apply directedOn_pair h hab
end Reflexive
section Preorder
variable [Preorder α] {a : α}
protected theorem IsMin.isBot [IsDirected α (· ≥ ·)] (h : IsMin a) : IsBot a := fun b =>
let ⟨_, hca, hcb⟩ := exists_le_le a b
(h hca).trans hcb
protected theorem IsMax.isTop [IsDirected α (· ≤ ·)] (h : IsMax a) : IsTop a :=
h.toDual.isBot
lemma DirectedOn.is_bot_of_is_min {s : Set α} (hd : DirectedOn (· ≥ ·) s)
{m} (hm : m ∈ s) (hmin : ∀ a ∈ s, a ≤ m → m ≤ a) : ∀ a ∈ s, m ≤ a := fun a as =>
let ⟨x, xs, xm, xa⟩ := hd m hm a as
(hmin x xs xm).trans xa
lemma DirectedOn.is_top_of_is_max {s : Set α} (hd : DirectedOn (· ≤ ·) s)
{m} (hm : m ∈ s) (hmax : ∀ a ∈ s, m ≤ a → a ≤ m) : ∀ a ∈ s, a ≤ m :=
@DirectedOn.is_bot_of_is_min αᵒᵈ _ s hd m hm hmax
theorem isTop_or_exists_gt [IsDirected α (· ≤ ·)] (a : α) : IsTop a ∨ ∃ b, a < b :=
(em (IsMax a)).imp IsMax.isTop not_isMax_iff.mp
theorem isBot_or_exists_lt [IsDirected α (· ≥ ·)] (a : α) : IsBot a ∨ ∃ b, b < a :=
@isTop_or_exists_gt αᵒᵈ _ _ a
theorem isBot_iff_isMin [IsDirected α (· ≥ ·)] : IsBot a ↔ IsMin a :=
⟨IsBot.isMin, IsMin.isBot⟩
theorem isTop_iff_isMax [IsDirected α (· ≤ ·)] : IsTop a ↔ IsMax a :=
⟨IsTop.isMax, IsMax.isTop⟩
variable (β) [PartialOrder β]
theorem exists_lt_of_directed_ge [IsDirected β (· ≥ ·)] [Nontrivial β] : ∃ a b : β, a < b := by
rcases exists_pair_ne β with ⟨a, b, hne⟩
rcases isBot_or_exists_lt a with (ha | ⟨c, hc⟩)
exacts [⟨a, b, (ha b).lt_of_ne hne⟩, ⟨_, _, hc⟩]
theorem exists_lt_of_directed_le [IsDirected β (· ≤ ·)] [Nontrivial β] : ∃ a b : β, a < b :=
let ⟨a, b, h⟩ := exists_lt_of_directed_ge βᵒᵈ
⟨b, a, h⟩
variable {f : α → β} {s : Set α}
-- TODO: Generalise the following two lemmas to connected orders
/-- If `f` is monotone and antitone on a directed order, then `f` is constant. -/
lemma constant_of_monotone_antitone [IsDirected α (· ≤ ·)] (hf : Monotone f) (hf' : Antitone f)
(a b : α) : f a = f b := by
obtain ⟨c, hac, hbc⟩ := exists_ge_ge a b
exact le_antisymm ((hf hac).trans $ hf' hbc) ((hf hbc).trans $ hf' hac)
/-- If `f` is monotone and antitone on a directed set `s`, then `f` is constant on `s`. -/
lemma constant_of_monotoneOn_antitoneOn (hf : MonotoneOn f s) (hf' : AntitoneOn f s)
(hs : DirectedOn (· ≤ ·) s) : ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → f a = f b := by
rintro a ha b hb
obtain ⟨c, hc, hac, hbc⟩ := hs _ ha _ hb
exact le_antisymm ((hf ha hc hac).trans $ hf' hb hc hbc) ((hf hb hc hbc).trans $ hf' ha hc hac)
end Preorder
-- see Note [lower instance priority]
instance (priority := 100) SemilatticeSup.to_isDirected_le [SemilatticeSup α] :
IsDirected α (· ≤ ·) :=
⟨fun a b => ⟨a ⊔ b, le_sup_left, le_sup_right⟩⟩
-- see Note [lower instance priority]
instance (priority := 100) SemilatticeInf.to_isDirected_ge [SemilatticeInf α] :
IsDirected α (· ≥ ·) :=
⟨fun a b => ⟨a ⊓ b, inf_le_left, inf_le_right⟩⟩
-- see Note [lower instance priority]
instance (priority := 100) OrderTop.to_isDirected_le [LE α] [OrderTop α] : IsDirected α (· ≤ ·) :=
⟨fun _ _ => ⟨⊤, le_top _, le_top _⟩⟩
-- see Note [lower instance priority]
instance (priority := 100) OrderBot.to_isDirected_ge [LE α] [OrderBot α] : IsDirected α (· ≥ ·) :=
⟨fun _ _ => ⟨⊥, bot_le _, bot_le _⟩⟩
|
Order\Disjoint.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Aesop
import Mathlib.Order.BoundedOrder
/-!
# Disjointness and complements
This file defines `Disjoint`, `Codisjoint`, and the `IsCompl` predicate.
## Main declarations
* `Disjoint x y`: two elements of a lattice are disjoint if their `inf` is the bottom element.
* `Codisjoint x y`: two elements of a lattice are codisjoint if their `join` is the top element.
* `IsCompl x y`: In a bounded lattice, predicate for "`x` is a complement of `y`". Note that in a
non distributive lattice, an element can have several complements.
* `ComplementedLattice α`: Typeclass stating that any element of a lattice has a complement.
-/
open Function
variable {α : Type*}
section Disjoint
section PartialOrderBot
variable [PartialOrder α] [OrderBot α] {a b c d : α}
/-- Two elements of a lattice are disjoint if their inf is the bottom element.
(This generalizes disjoint sets, viewed as members of the subset lattice.)
Note that we define this without reference to `⊓`, as this allows us to talk about orders where
the infimum is not unique, or where implementing `Inf` would require additional `Decidable`
arguments. -/
def Disjoint (a b : α) : Prop :=
∀ ⦃x⦄, x ≤ a → x ≤ b → x ≤ ⊥
@[simp]
theorem disjoint_of_subsingleton [Subsingleton α] : Disjoint a b :=
fun x _ _ ↦ le_of_eq (Subsingleton.elim x ⊥)
theorem disjoint_comm : Disjoint a b ↔ Disjoint b a :=
forall_congr' fun _ ↦ forall_swap
@[symm]
theorem Disjoint.symm ⦃a b : α⦄ : Disjoint a b → Disjoint b a :=
disjoint_comm.1
theorem symmetric_disjoint : Symmetric (Disjoint : α → α → Prop) :=
Disjoint.symm
@[simp]
theorem disjoint_bot_left : Disjoint ⊥ a := fun _ hbot _ ↦ hbot
@[simp]
theorem disjoint_bot_right : Disjoint a ⊥ := fun _ _ hbot ↦ hbot
theorem Disjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : Disjoint b d → Disjoint a c :=
fun h _ ha hc ↦ h (ha.trans h₁) (hc.trans h₂)
theorem Disjoint.mono_left (h : a ≤ b) : Disjoint b c → Disjoint a c :=
Disjoint.mono h le_rfl
theorem Disjoint.mono_right : b ≤ c → Disjoint a c → Disjoint a b :=
Disjoint.mono le_rfl
@[simp]
theorem disjoint_self : Disjoint a a ↔ a = ⊥ :=
⟨fun hd ↦ bot_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ ha.trans_eq h⟩
/- TODO: Rename `Disjoint.eq_bot` to `Disjoint.inf_eq` and `Disjoint.eq_bot_of_self` to
`Disjoint.eq_bot` -/
alias ⟨Disjoint.eq_bot_of_self, _⟩ := disjoint_self
theorem Disjoint.ne (ha : a ≠ ⊥) (hab : Disjoint a b) : a ≠ b :=
fun h ↦ ha <| disjoint_self.1 <| by rwa [← h] at hab
theorem Disjoint.eq_bot_of_le (hab : Disjoint a b) (h : a ≤ b) : a = ⊥ :=
eq_bot_iff.2 <| hab le_rfl h
theorem Disjoint.eq_bot_of_ge (hab : Disjoint a b) : b ≤ a → b = ⊥ :=
hab.symm.eq_bot_of_le
lemma Disjoint.eq_iff (hab : Disjoint a b) : a = b ↔ a = ⊥ ∧ b = ⊥ := by aesop
lemma Disjoint.ne_iff (hab : Disjoint a b) : a ≠ b ↔ a ≠ ⊥ ∨ b ≠ ⊥ :=
hab.eq_iff.not.trans not_and_or
end PartialOrderBot
section PartialBoundedOrder
variable [PartialOrder α] [BoundedOrder α] {a : α}
@[simp]
theorem disjoint_top : Disjoint a ⊤ ↔ a = ⊥ :=
⟨fun h ↦ bot_unique <| h le_rfl le_top, fun h _ ha _ ↦ ha.trans_eq h⟩
@[simp]
theorem top_disjoint : Disjoint ⊤ a ↔ a = ⊥ :=
⟨fun h ↦ bot_unique <| h le_top le_rfl, fun h _ _ ha ↦ ha.trans_eq h⟩
end PartialBoundedOrder
section SemilatticeInfBot
variable [SemilatticeInf α] [OrderBot α] {a b c d : α}
theorem disjoint_iff_inf_le : Disjoint a b ↔ a ⊓ b ≤ ⊥ :=
⟨fun hd ↦ hd inf_le_left inf_le_right, fun h _ ha hb ↦ (le_inf ha hb).trans h⟩
theorem disjoint_iff : Disjoint a b ↔ a ⊓ b = ⊥ :=
disjoint_iff_inf_le.trans le_bot_iff
theorem Disjoint.le_bot : Disjoint a b → a ⊓ b ≤ ⊥ :=
disjoint_iff_inf_le.mp
theorem Disjoint.eq_bot : Disjoint a b → a ⊓ b = ⊥ :=
bot_unique ∘ Disjoint.le_bot
theorem disjoint_assoc : Disjoint (a ⊓ b) c ↔ Disjoint a (b ⊓ c) := by
rw [disjoint_iff_inf_le, disjoint_iff_inf_le, inf_assoc]
theorem disjoint_left_comm : Disjoint a (b ⊓ c) ↔ Disjoint b (a ⊓ c) := by
simp_rw [disjoint_iff_inf_le, inf_left_comm]
theorem disjoint_right_comm : Disjoint (a ⊓ b) c ↔ Disjoint (a ⊓ c) b := by
simp_rw [disjoint_iff_inf_le, inf_right_comm]
variable (c)
theorem Disjoint.inf_left (h : Disjoint a b) : Disjoint (a ⊓ c) b :=
h.mono_left inf_le_left
theorem Disjoint.inf_left' (h : Disjoint a b) : Disjoint (c ⊓ a) b :=
h.mono_left inf_le_right
theorem Disjoint.inf_right (h : Disjoint a b) : Disjoint a (b ⊓ c) :=
h.mono_right inf_le_left
theorem Disjoint.inf_right' (h : Disjoint a b) : Disjoint a (c ⊓ b) :=
h.mono_right inf_le_right
variable {c}
theorem Disjoint.of_disjoint_inf_of_le (h : Disjoint (a ⊓ b) c) (hle : a ≤ c) : Disjoint a b :=
disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_left_le hle
theorem Disjoint.of_disjoint_inf_of_le' (h : Disjoint (a ⊓ b) c) (hle : b ≤ c) : Disjoint a b :=
disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_right_le hle
end SemilatticeInfBot
section DistribLatticeBot
variable [DistribLattice α] [OrderBot α] {a b c : α}
@[simp]
theorem disjoint_sup_left : Disjoint (a ⊔ b) c ↔ Disjoint a c ∧ Disjoint b c := by
simp only [disjoint_iff, inf_sup_right, sup_eq_bot_iff]
@[simp]
theorem disjoint_sup_right : Disjoint a (b ⊔ c) ↔ Disjoint a b ∧ Disjoint a c := by
simp only [disjoint_iff, inf_sup_left, sup_eq_bot_iff]
theorem Disjoint.sup_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a ⊔ b) c :=
disjoint_sup_left.2 ⟨ha, hb⟩
theorem Disjoint.sup_right (hb : Disjoint a b) (hc : Disjoint a c) : Disjoint a (b ⊔ c) :=
disjoint_sup_right.2 ⟨hb, hc⟩
theorem Disjoint.left_le_of_le_sup_right (h : a ≤ b ⊔ c) (hd : Disjoint a c) : a ≤ b :=
le_of_inf_le_sup_le (le_trans hd.le_bot bot_le) <| sup_le h le_sup_right
theorem Disjoint.left_le_of_le_sup_left (h : a ≤ c ⊔ b) (hd : Disjoint a c) : a ≤ b :=
hd.left_le_of_le_sup_right <| by rwa [sup_comm]
end DistribLatticeBot
end Disjoint
section Codisjoint
section PartialOrderTop
variable [PartialOrder α] [OrderTop α] {a b c d : α}
/-- Two elements of a lattice are codisjoint if their sup is the top element.
Note that we define this without reference to `⊔`, as this allows us to talk about orders where
the supremum is not unique, or where implement `Sup` would require additional `Decidable`
arguments. -/
def Codisjoint (a b : α) : Prop :=
∀ ⦃x⦄, a ≤ x → b ≤ x → ⊤ ≤ x
theorem Codisjoint_comm : Codisjoint a b ↔ Codisjoint b a :=
forall_congr' fun _ ↦ forall_swap
@[symm]
theorem Codisjoint.symm ⦃a b : α⦄ : Codisjoint a b → Codisjoint b a :=
Codisjoint_comm.1
theorem symmetric_codisjoint : Symmetric (Codisjoint : α → α → Prop) :=
Codisjoint.symm
@[simp]
theorem codisjoint_top_left : Codisjoint ⊤ a := fun _ htop _ ↦ htop
@[simp]
theorem codisjoint_top_right : Codisjoint a ⊤ := fun _ _ htop ↦ htop
theorem Codisjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : Codisjoint a c → Codisjoint b d :=
fun h _ ha hc ↦ h (h₁.trans ha) (h₂.trans hc)
theorem Codisjoint.mono_left (h : a ≤ b) : Codisjoint a c → Codisjoint b c :=
Codisjoint.mono h le_rfl
theorem Codisjoint.mono_right : b ≤ c → Codisjoint a b → Codisjoint a c :=
Codisjoint.mono le_rfl
@[simp]
theorem codisjoint_self : Codisjoint a a ↔ a = ⊤ :=
⟨fun hd ↦ top_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ h.symm.trans_le ha⟩
/- TODO: Rename `Codisjoint.eq_top` to `Codisjoint.sup_eq` and `Codisjoint.eq_top_of_self` to
`Codisjoint.eq_top` -/
alias ⟨Codisjoint.eq_top_of_self, _⟩ := codisjoint_self
theorem Codisjoint.ne (ha : a ≠ ⊤) (hab : Codisjoint a b) : a ≠ b :=
fun h ↦ ha <| codisjoint_self.1 <| by rwa [← h] at hab
theorem Codisjoint.eq_top_of_le (hab : Codisjoint a b) (h : b ≤ a) : a = ⊤ :=
eq_top_iff.2 <| hab le_rfl h
theorem Codisjoint.eq_top_of_ge (hab : Codisjoint a b) : a ≤ b → b = ⊤ :=
hab.symm.eq_top_of_le
lemma Codisjoint.eq_iff (hab : Codisjoint a b) : a = b ↔ a = ⊤ ∧ b = ⊤ := by aesop
lemma Codisjoint.ne_iff (hab : Codisjoint a b) : a ≠ b ↔ a ≠ ⊤ ∨ b ≠ ⊤ :=
hab.eq_iff.not.trans not_and_or
end PartialOrderTop
section PartialBoundedOrder
variable [PartialOrder α] [BoundedOrder α] {a b : α}
@[simp]
theorem codisjoint_bot : Codisjoint a ⊥ ↔ a = ⊤ :=
⟨fun h ↦ top_unique <| h le_rfl bot_le, fun h _ ha _ ↦ h.symm.trans_le ha⟩
@[simp]
theorem bot_codisjoint : Codisjoint ⊥ a ↔ a = ⊤ :=
⟨fun h ↦ top_unique <| h bot_le le_rfl, fun h _ _ ha ↦ h.symm.trans_le ha⟩
lemma Codisjoint.ne_bot_of_ne_top (h : Codisjoint a b) (ha : a ≠ ⊤) : b ≠ ⊥ := by
rintro rfl; exact ha <| by simpa using h
lemma Codisjoint.ne_bot_of_ne_top' (h : Codisjoint a b) (hb : b ≠ ⊤) : a ≠ ⊥ := by
rintro rfl; exact hb <| by simpa using h
end PartialBoundedOrder
section SemilatticeSupTop
variable [SemilatticeSup α] [OrderTop α] {a b c d : α}
theorem codisjoint_iff_le_sup : Codisjoint a b ↔ ⊤ ≤ a ⊔ b :=
@disjoint_iff_inf_le αᵒᵈ _ _ _ _
theorem codisjoint_iff : Codisjoint a b ↔ a ⊔ b = ⊤ :=
@disjoint_iff αᵒᵈ _ _ _ _
theorem Codisjoint.top_le : Codisjoint a b → ⊤ ≤ a ⊔ b :=
@Disjoint.le_bot αᵒᵈ _ _ _ _
theorem Codisjoint.eq_top : Codisjoint a b → a ⊔ b = ⊤ :=
@Disjoint.eq_bot αᵒᵈ _ _ _ _
theorem codisjoint_assoc : Codisjoint (a ⊔ b) c ↔ Codisjoint a (b ⊔ c) :=
@disjoint_assoc αᵒᵈ _ _ _ _ _
theorem codisjoint_left_comm : Codisjoint a (b ⊔ c) ↔ Codisjoint b (a ⊔ c) :=
@disjoint_left_comm αᵒᵈ _ _ _ _ _
theorem codisjoint_right_comm : Codisjoint (a ⊔ b) c ↔ Codisjoint (a ⊔ c) b :=
@disjoint_right_comm αᵒᵈ _ _ _ _ _
variable (c)
theorem Codisjoint.sup_left (h : Codisjoint a b) : Codisjoint (a ⊔ c) b :=
h.mono_left le_sup_left
theorem Codisjoint.sup_left' (h : Codisjoint a b) : Codisjoint (c ⊔ a) b :=
h.mono_left le_sup_right
theorem Codisjoint.sup_right (h : Codisjoint a b) : Codisjoint a (b ⊔ c) :=
h.mono_right le_sup_left
theorem Codisjoint.sup_right' (h : Codisjoint a b) : Codisjoint a (c ⊔ b) :=
h.mono_right le_sup_right
variable {c}
theorem Codisjoint.of_codisjoint_sup_of_le (h : Codisjoint (a ⊔ b) c) (hle : c ≤ a) :
Codisjoint a b :=
@Disjoint.of_disjoint_inf_of_le αᵒᵈ _ _ _ _ _ h hle
theorem Codisjoint.of_codisjoint_sup_of_le' (h : Codisjoint (a ⊔ b) c) (hle : c ≤ b) :
Codisjoint a b :=
@Disjoint.of_disjoint_inf_of_le' αᵒᵈ _ _ _ _ _ h hle
end SemilatticeSupTop
section DistribLatticeTop
variable [DistribLattice α] [OrderTop α] {a b c : α}
@[simp]
theorem codisjoint_inf_left : Codisjoint (a ⊓ b) c ↔ Codisjoint a c ∧ Codisjoint b c := by
simp only [codisjoint_iff, sup_inf_right, inf_eq_top_iff]
@[simp]
theorem codisjoint_inf_right : Codisjoint a (b ⊓ c) ↔ Codisjoint a b ∧ Codisjoint a c := by
simp only [codisjoint_iff, sup_inf_left, inf_eq_top_iff]
theorem Codisjoint.inf_left (ha : Codisjoint a c) (hb : Codisjoint b c) : Codisjoint (a ⊓ b) c :=
codisjoint_inf_left.2 ⟨ha, hb⟩
theorem Codisjoint.inf_right (hb : Codisjoint a b) (hc : Codisjoint a c) : Codisjoint a (b ⊓ c) :=
codisjoint_inf_right.2 ⟨hb, hc⟩
theorem Codisjoint.left_le_of_le_inf_right (h : a ⊓ b ≤ c) (hd : Codisjoint b c) : a ≤ c :=
@Disjoint.left_le_of_le_sup_right αᵒᵈ _ _ _ _ _ h hd.symm
theorem Codisjoint.left_le_of_le_inf_left (h : b ⊓ a ≤ c) (hd : Codisjoint b c) : a ≤ c :=
hd.left_le_of_le_inf_right <| by rwa [inf_comm]
end DistribLatticeTop
end Codisjoint
open OrderDual
theorem Disjoint.dual [SemilatticeInf α] [OrderBot α] {a b : α} :
Disjoint a b → Codisjoint (toDual a) (toDual b) :=
id
theorem Codisjoint.dual [SemilatticeSup α] [OrderTop α] {a b : α} :
Codisjoint a b → Disjoint (toDual a) (toDual b) :=
id
@[simp]
theorem disjoint_toDual_iff [SemilatticeSup α] [OrderTop α] {a b : α} :
Disjoint (toDual a) (toDual b) ↔ Codisjoint a b :=
Iff.rfl
@[simp]
theorem disjoint_ofDual_iff [SemilatticeInf α] [OrderBot α] {a b : αᵒᵈ} :
Disjoint (ofDual a) (ofDual b) ↔ Codisjoint a b :=
Iff.rfl
@[simp]
theorem codisjoint_toDual_iff [SemilatticeInf α] [OrderBot α] {a b : α} :
Codisjoint (toDual a) (toDual b) ↔ Disjoint a b :=
Iff.rfl
@[simp]
theorem codisjoint_ofDual_iff [SemilatticeSup α] [OrderTop α] {a b : αᵒᵈ} :
Codisjoint (ofDual a) (ofDual b) ↔ Disjoint a b :=
Iff.rfl
section DistribLattice
variable [DistribLattice α] [BoundedOrder α] {a b c : α}
theorem Disjoint.le_of_codisjoint (hab : Disjoint a b) (hbc : Codisjoint b c) : a ≤ c := by
rw [← @inf_top_eq _ _ _ a, ← @bot_sup_eq _ _ _ c, ← hab.eq_bot, ← hbc.eq_top, sup_inf_right]
exact inf_le_inf_right _ le_sup_left
end DistribLattice
section IsCompl
/-- Two elements `x` and `y` are complements of each other if `x ⊔ y = ⊤` and `x ⊓ y = ⊥`. -/
structure IsCompl [PartialOrder α] [BoundedOrder α] (x y : α) : Prop where
/-- If `x` and `y` are to be complementary in an order, they should be disjoint. -/
protected disjoint : Disjoint x y
/-- If `x` and `y` are to be complementary in an order, they should be codisjoint. -/
protected codisjoint : Codisjoint x y
theorem isCompl_iff [PartialOrder α] [BoundedOrder α] {a b : α} :
IsCompl a b ↔ Disjoint a b ∧ Codisjoint a b :=
⟨fun h ↦ ⟨h.1, h.2⟩, fun h ↦ ⟨h.1, h.2⟩⟩
namespace IsCompl
section BoundedPartialOrder
variable [PartialOrder α] [BoundedOrder α] {x y z : α}
@[symm]
protected theorem symm (h : IsCompl x y) : IsCompl y x :=
⟨h.1.symm, h.2.symm⟩
lemma _root_.isCompl_comm : IsCompl x y ↔ IsCompl y x := ⟨IsCompl.symm, IsCompl.symm⟩
theorem dual (h : IsCompl x y) : IsCompl (toDual x) (toDual y) :=
⟨h.2, h.1⟩
theorem ofDual {a b : αᵒᵈ} (h : IsCompl a b) : IsCompl (ofDual a) (ofDual b) :=
⟨h.2, h.1⟩
end BoundedPartialOrder
section BoundedLattice
variable [Lattice α] [BoundedOrder α] {x y z : α}
theorem of_le (h₁ : x ⊓ y ≤ ⊥) (h₂ : ⊤ ≤ x ⊔ y) : IsCompl x y :=
⟨disjoint_iff_inf_le.mpr h₁, codisjoint_iff_le_sup.mpr h₂⟩
theorem of_eq (h₁ : x ⊓ y = ⊥) (h₂ : x ⊔ y = ⊤) : IsCompl x y :=
⟨disjoint_iff.mpr h₁, codisjoint_iff.mpr h₂⟩
theorem inf_eq_bot (h : IsCompl x y) : x ⊓ y = ⊥ :=
h.disjoint.eq_bot
theorem sup_eq_top (h : IsCompl x y) : x ⊔ y = ⊤ :=
h.codisjoint.eq_top
end BoundedLattice
variable [DistribLattice α] [BoundedOrder α] {a b x y z : α}
theorem inf_left_le_of_le_sup_right (h : IsCompl x y) (hle : a ≤ b ⊔ y) : a ⊓ x ≤ b :=
calc
a ⊓ x ≤ (b ⊔ y) ⊓ x := inf_le_inf hle le_rfl
_ = b ⊓ x ⊔ y ⊓ x := inf_sup_right _ _ _
_ = b ⊓ x := by rw [h.symm.inf_eq_bot, sup_bot_eq]
_ ≤ b := inf_le_left
theorem le_sup_right_iff_inf_left_le {a b} (h : IsCompl x y) : a ≤ b ⊔ y ↔ a ⊓ x ≤ b :=
⟨h.inf_left_le_of_le_sup_right, h.symm.dual.inf_left_le_of_le_sup_right⟩
theorem inf_left_eq_bot_iff (h : IsCompl y z) : x ⊓ y = ⊥ ↔ x ≤ z := by
rw [← le_bot_iff, ← h.le_sup_right_iff_inf_left_le, bot_sup_eq]
theorem inf_right_eq_bot_iff (h : IsCompl y z) : x ⊓ z = ⊥ ↔ x ≤ y :=
h.symm.inf_left_eq_bot_iff
theorem disjoint_left_iff (h : IsCompl y z) : Disjoint x y ↔ x ≤ z := by
rw [disjoint_iff]
exact h.inf_left_eq_bot_iff
theorem disjoint_right_iff (h : IsCompl y z) : Disjoint x z ↔ x ≤ y :=
h.symm.disjoint_left_iff
theorem le_left_iff (h : IsCompl x y) : z ≤ x ↔ Disjoint z y :=
h.disjoint_right_iff.symm
theorem le_right_iff (h : IsCompl x y) : z ≤ y ↔ Disjoint z x :=
h.symm.le_left_iff
theorem left_le_iff (h : IsCompl x y) : x ≤ z ↔ Codisjoint z y :=
h.dual.le_left_iff
theorem right_le_iff (h : IsCompl x y) : y ≤ z ↔ Codisjoint z x :=
h.symm.left_le_iff
protected theorem Antitone {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') (hx : x ≤ x') : y' ≤ y :=
h'.right_le_iff.2 <| h.symm.codisjoint.mono_right hx
theorem right_unique (hxy : IsCompl x y) (hxz : IsCompl x z) : y = z :=
le_antisymm (hxz.Antitone hxy <| le_refl x) (hxy.Antitone hxz <| le_refl x)
theorem left_unique (hxz : IsCompl x z) (hyz : IsCompl y z) : x = y :=
hxz.symm.right_unique hyz.symm
theorem sup_inf {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x ⊔ x') (y ⊓ y') :=
of_eq
(by rw [inf_sup_right, ← inf_assoc, h.inf_eq_bot, bot_inf_eq, bot_sup_eq, inf_left_comm,
h'.inf_eq_bot, inf_bot_eq])
(by rw [sup_inf_left, sup_comm x, sup_assoc, h.sup_eq_top, sup_top_eq, top_inf_eq,
sup_assoc, sup_left_comm, h'.sup_eq_top, sup_top_eq])
theorem inf_sup {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x ⊓ x') (y ⊔ y') :=
(h.symm.sup_inf h'.symm).symm
end IsCompl
namespace Prod
variable {β : Type*} [PartialOrder α] [PartialOrder β]
protected theorem disjoint_iff [OrderBot α] [OrderBot β] {x y : α × β} :
Disjoint x y ↔ Disjoint x.1 y.1 ∧ Disjoint x.2 y.2 := by
constructor
· intro h
refine ⟨fun a hx hy ↦ (@h (a, ⊥) ⟨hx, ?_⟩ ⟨hy, ?_⟩).1,
fun b hx hy ↦ (@h (⊥, b) ⟨?_, hx⟩ ⟨?_, hy⟩).2⟩
all_goals exact bot_le
· rintro ⟨ha, hb⟩ z hza hzb
exact ⟨ha hza.1 hzb.1, hb hza.2 hzb.2⟩
protected theorem codisjoint_iff [OrderTop α] [OrderTop β] {x y : α × β} :
Codisjoint x y ↔ Codisjoint x.1 y.1 ∧ Codisjoint x.2 y.2 :=
@Prod.disjoint_iff αᵒᵈ βᵒᵈ _ _ _ _ _ _
protected theorem isCompl_iff [BoundedOrder α] [BoundedOrder β] {x y : α × β} :
IsCompl x y ↔ IsCompl x.1 y.1 ∧ IsCompl x.2 y.2 := by
simp_rw [isCompl_iff, Prod.disjoint_iff, Prod.codisjoint_iff, and_and_and_comm]
end Prod
section
variable [Lattice α] [BoundedOrder α] {a b x : α}
@[simp]
theorem isCompl_toDual_iff : IsCompl (toDual a) (toDual b) ↔ IsCompl a b :=
⟨IsCompl.ofDual, IsCompl.dual⟩
@[simp]
theorem isCompl_ofDual_iff {a b : αᵒᵈ} : IsCompl (ofDual a) (ofDual b) ↔ IsCompl a b :=
⟨IsCompl.dual, IsCompl.ofDual⟩
theorem isCompl_bot_top : IsCompl (⊥ : α) ⊤ :=
IsCompl.of_eq (bot_inf_eq _) (sup_top_eq _)
theorem isCompl_top_bot : IsCompl (⊤ : α) ⊥ :=
IsCompl.of_eq (inf_bot_eq _) (top_sup_eq _)
theorem eq_top_of_isCompl_bot (h : IsCompl x ⊥) : x = ⊤ := by rw [← sup_bot_eq x, h.sup_eq_top]
theorem eq_top_of_bot_isCompl (h : IsCompl ⊥ x) : x = ⊤ :=
eq_top_of_isCompl_bot h.symm
theorem eq_bot_of_isCompl_top (h : IsCompl x ⊤) : x = ⊥ :=
eq_top_of_isCompl_bot h.dual
theorem eq_bot_of_top_isCompl (h : IsCompl ⊤ x) : x = ⊥ :=
eq_top_of_bot_isCompl h.dual
end
section IsComplemented
section Lattice
variable [Lattice α] [BoundedOrder α]
/-- An element is *complemented* if it has a complement. -/
def IsComplemented (a : α) : Prop :=
∃ b, IsCompl a b
theorem isComplemented_bot : IsComplemented (⊥ : α) :=
⟨⊤, isCompl_bot_top⟩
theorem isComplemented_top : IsComplemented (⊤ : α) :=
⟨⊥, isCompl_top_bot⟩
end Lattice
variable [DistribLattice α] [BoundedOrder α] {a b : α}
theorem IsComplemented.sup : IsComplemented a → IsComplemented b → IsComplemented (a ⊔ b) :=
fun ⟨a', ha⟩ ⟨b', hb⟩ => ⟨a' ⊓ b', ha.sup_inf hb⟩
theorem IsComplemented.inf : IsComplemented a → IsComplemented b → IsComplemented (a ⊓ b) :=
fun ⟨a', ha⟩ ⟨b', hb⟩ => ⟨a' ⊔ b', ha.inf_sup hb⟩
end IsComplemented
/-- A complemented bounded lattice is one where every element has a (not necessarily unique)
complement. -/
class ComplementedLattice (α) [Lattice α] [BoundedOrder α] : Prop where
/-- In a `ComplementedLattice`, every element admits a complement. -/
exists_isCompl : ∀ a : α, ∃ b : α, IsCompl a b
export ComplementedLattice (exists_isCompl)
instance Subsingleton.instComplementedLattice
[Lattice α] [BoundedOrder α] [Subsingleton α] : ComplementedLattice α := by
refine ⟨fun a ↦ ⟨⊥, disjoint_bot_right, ?_⟩⟩
rw [Subsingleton.elim ⊥ ⊤]
exact codisjoint_top_right
namespace ComplementedLattice
variable [Lattice α] [BoundedOrder α] [ComplementedLattice α]
instance : ComplementedLattice αᵒᵈ :=
⟨fun a ↦
let ⟨b, hb⟩ := exists_isCompl (show α from a)
⟨b, hb.dual⟩⟩
end ComplementedLattice
-- TODO: Define as a sublattice?
/-- The sublattice of complemented elements. -/
abbrev Complementeds (α : Type*) [Lattice α] [BoundedOrder α] : Type _ :=
{a : α // IsComplemented a}
namespace Complementeds
section Lattice
variable [Lattice α] [BoundedOrder α] {a b : Complementeds α}
instance hasCoeT : CoeTC (Complementeds α) α := ⟨Subtype.val⟩
theorem coe_injective : Injective ((↑) : Complementeds α → α) := Subtype.coe_injective
@[simp, norm_cast]
theorem coe_inj : (a : α) = b ↔ a = b := Subtype.coe_inj
-- Porting note: removing `simp` because `Subtype.coe_le_coe` already proves it
@[norm_cast]
theorem coe_le_coe : (a : α) ≤ b ↔ a ≤ b := by simp
-- Porting note: removing `simp` because `Subtype.coe_lt_coe` already proves it
@[norm_cast]
theorem coe_lt_coe : (a : α) < b ↔ a < b := Iff.rfl
instance : BoundedOrder (Complementeds α) :=
Subtype.boundedOrder isComplemented_bot isComplemented_top
@[simp, norm_cast]
theorem coe_bot : ((⊥ : Complementeds α) : α) = ⊥ := rfl
@[simp, norm_cast]
theorem coe_top : ((⊤ : Complementeds α) : α) = ⊤ := rfl
-- Porting note: removing `simp` because `Subtype.mk_bot` already proves it
theorem mk_bot : (⟨⊥, isComplemented_bot⟩ : Complementeds α) = ⊥ := rfl
-- Porting note: removing `simp` because `Subtype.mk_top` already proves it
theorem mk_top : (⟨⊤, isComplemented_top⟩ : Complementeds α) = ⊤ := rfl
instance : Inhabited (Complementeds α) := ⟨⊥⟩
end Lattice
variable [DistribLattice α] [BoundedOrder α] {a b : Complementeds α}
instance : Sup (Complementeds α) :=
⟨fun a b => ⟨a ⊔ b, a.2.sup b.2⟩⟩
instance : Inf (Complementeds α) :=
⟨fun a b => ⟨a ⊓ b, a.2.inf b.2⟩⟩
@[simp, norm_cast]
theorem coe_sup (a b : Complementeds α) : ↑(a ⊔ b) = (a : α) ⊔ b := rfl
@[simp, norm_cast]
theorem coe_inf (a b : Complementeds α) : ↑(a ⊓ b) = (a : α) ⊓ b := rfl
@[simp]
theorem mk_sup_mk {a b : α} (ha : IsComplemented a) (hb : IsComplemented b) :
(⟨a, ha⟩ ⊔ ⟨b, hb⟩ : Complementeds α) = ⟨a ⊔ b, ha.sup hb⟩ := rfl
@[simp]
theorem mk_inf_mk {a b : α} (ha : IsComplemented a) (hb : IsComplemented b) :
(⟨a, ha⟩ ⊓ ⟨b, hb⟩ : Complementeds α) = ⟨a ⊓ b, ha.inf hb⟩ := rfl
instance : DistribLattice (Complementeds α) :=
Complementeds.coe_injective.distribLattice _ coe_sup coe_inf
@[simp, norm_cast]
theorem disjoint_coe : Disjoint (a : α) b ↔ Disjoint a b := by
rw [disjoint_iff, disjoint_iff, ← coe_inf, ← coe_bot, coe_inj]
@[simp, norm_cast]
theorem codisjoint_coe : Codisjoint (a : α) b ↔ Codisjoint a b := by
rw [codisjoint_iff, codisjoint_iff, ← coe_sup, ← coe_top, coe_inj]
@[simp, norm_cast]
theorem isCompl_coe : IsCompl (a : α) b ↔ IsCompl a b := by
simp_rw [isCompl_iff, disjoint_coe, codisjoint_coe]
instance : ComplementedLattice (Complementeds α) :=
⟨fun ⟨a, b, h⟩ => ⟨⟨b, a, h.symm⟩, isCompl_coe.1 h⟩⟩
end Complementeds
end IsCompl
|
Order\Disjointed.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yaël Dillies
-/
import Mathlib.Order.PartialSups
/-!
# Consecutive differences of sets
This file defines the way to make a sequence of elements into a sequence of disjoint elements with
the same partial sups.
For a sequence `f : ℕ → α`, this new sequence will be `f 0`, `f 1 \ f 0`, `f 2 \ (f 0 ⊔ f 1)`.
It is actually unique, as `disjointed_unique` shows.
## Main declarations
* `disjointed f`: The sequence `f 0`, `f 1 \ f 0`, `f 2 \ (f 0 ⊔ f 1)`, ....
* `partialSups_disjointed`: `disjointed f` has the same partial sups as `f`.
* `disjoint_disjointed`: The elements of `disjointed f` are pairwise disjoint.
* `disjointed_unique`: `disjointed f` is the only pairwise disjoint sequence having the same partial
sups as `f`.
* `iSup_disjointed`: `disjointed f` has the same supremum as `f`. Limiting case of
`partialSups_disjointed`.
We also provide set notation variants of some lemmas.
## TODO
Find a useful statement of `disjointedRec_succ`.
One could generalize `disjointed` to any locally finite bot preorder domain, in place of `ℕ`.
Related to the TODO in the module docstring of `Mathlib.Order.PartialSups`.
-/
variable {α β : Type*}
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra α]
/-- If `f : ℕ → α` is a sequence of elements, then `disjointed f` is the sequence formed by
subtracting each element from the nexts. This is the unique disjoint sequence whose partial sups
are the same as the original sequence. -/
def disjointed (f : ℕ → α) : ℕ → α
| 0 => f 0
| n + 1 => f (n + 1) \ partialSups f n
@[simp]
theorem disjointed_zero (f : ℕ → α) : disjointed f 0 = f 0 :=
rfl
theorem disjointed_succ (f : ℕ → α) (n : ℕ) : disjointed f (n + 1) = f (n + 1) \ partialSups f n :=
rfl
theorem disjointed_le_id : disjointed ≤ (id : (ℕ → α) → ℕ → α) := by
rintro f n
cases n
· rfl
· exact sdiff_le
theorem disjointed_le (f : ℕ → α) : disjointed f ≤ f :=
disjointed_le_id f
theorem disjoint_disjointed (f : ℕ → α) : Pairwise (Disjoint on disjointed f) := by
refine (Symmetric.pairwise_on Disjoint.symm _).2 fun m n h => ?_
cases n
· exact (Nat.not_lt_zero _ h).elim
exact
disjoint_sdiff_self_right.mono_left
((disjointed_le f m).trans (le_partialSups_of_le f (Nat.lt_add_one_iff.1 h)))
-- Porting note: `disjointedRec` had a change in universe level.
/-- An induction principle for `disjointed`. To define/prove something on `disjointed f n`, it's
enough to define/prove it for `f n` and being able to extend through diffs. -/
def disjointedRec {f : ℕ → α} {p : α → Sort*} (hdiff : ∀ ⦃t i⦄, p t → p (t \ f i)) :
∀ ⦃n⦄, p (f n) → p (disjointed f n)
| 0 => id
| n + 1 => fun h => by
suffices H : ∀ k, p (f (n + 1) \ partialSups f k) from H n
rintro k
induction' k with k ih
· exact hdiff h
rw [partialSups_succ, ← sdiff_sdiff_left]
exact hdiff ih
@[simp]
theorem disjointedRec_zero {f : ℕ → α} {p : α → Sort*} (hdiff : ∀ ⦃t i⦄, p t → p (t \ f i))
(h₀ : p (f 0)) : disjointedRec hdiff h₀ = h₀ :=
rfl
-- TODO: Find a useful statement of `disjointedRec_succ`.
protected lemma Monotone.disjointed_succ {f : ℕ → α} (hf : Monotone f) (n : ℕ) :
disjointed f (n + 1) = f (n + 1) \ f n := by rw [disjointed_succ, hf.partialSups_eq]
protected lemma Monotone.disjointed_succ_sup {f : ℕ → α} (hf : Monotone f) (n : ℕ) :
disjointed f (n + 1) ⊔ f n = f (n + 1) := by
rw [hf.disjointed_succ, sdiff_sup_cancel]; exact hf n.le_succ
@[simp]
theorem partialSups_disjointed (f : ℕ → α) : partialSups (disjointed f) = partialSups f := by
ext n
induction' n with k ih
· rw [partialSups_zero, partialSups_zero, disjointed_zero]
· rw [partialSups_succ, partialSups_succ, disjointed_succ, ih, sup_sdiff_self_right]
/-- `disjointed f` is the unique sequence that is pairwise disjoint and has the same partial sups
as `f`. -/
theorem disjointed_unique {f d : ℕ → α} (hdisj : Pairwise (Disjoint on d))
(hsups : partialSups d = partialSups f) : d = disjointed f := by
ext n
cases' n with n
· rw [← partialSups_zero d, hsups, partialSups_zero, disjointed_zero]
suffices h : d n.succ = partialSups d n.succ \ partialSups d n by
rw [h, hsups, partialSups_succ, disjointed_succ, sup_sdiff, sdiff_self, bot_sup_eq]
rw [partialSups_succ, sup_sdiff, sdiff_self, bot_sup_eq, eq_comm, sdiff_eq_self_iff_disjoint]
suffices h : ∀ m ≤ n, Disjoint (partialSups d m) (d n.succ) from h n le_rfl
rintro m hm
induction' m with m ih
· exact hdisj (Nat.succ_ne_zero _).symm
rw [partialSups_succ, disjoint_iff, inf_sup_right, sup_eq_bot_iff, ← disjoint_iff, ← disjoint_iff]
exact ⟨ih (Nat.le_of_succ_le hm), hdisj (Nat.lt_succ_of_le hm).ne⟩
end GeneralizedBooleanAlgebra
section CompleteBooleanAlgebra
variable [CompleteBooleanAlgebra α]
theorem iSup_disjointed (f : ℕ → α) : ⨆ n, disjointed f n = ⨆ n, f n :=
iSup_eq_iSup_of_partialSups_eq_partialSups (partialSups_disjointed f)
theorem disjointed_eq_inf_compl (f : ℕ → α) (n : ℕ) : disjointed f n = f n ⊓ ⨅ i < n, (f i)ᶜ := by
cases n
· rw [disjointed_zero, eq_comm, inf_eq_left]
simp_rw [le_iInf_iff]
exact fun i hi => (i.not_lt_zero hi).elim
simp_rw [disjointed_succ, partialSups_eq_biSup, sdiff_eq, compl_iSup]
congr
ext i
rw [Nat.lt_succ_iff]
end CompleteBooleanAlgebra
/-! ### Set notation variants of lemmas -/
theorem disjointed_subset (f : ℕ → Set α) (n : ℕ) : disjointed f n ⊆ f n :=
disjointed_le f n
theorem iUnion_disjointed {f : ℕ → Set α} : ⋃ n, disjointed f n = ⋃ n, f n :=
iSup_disjointed f
theorem disjointed_eq_inter_compl (f : ℕ → Set α) (n : ℕ) :
disjointed f n = f n ∩ ⋂ i < n, (f i)ᶜ :=
disjointed_eq_inf_compl f n
theorem preimage_find_eq_disjointed (s : ℕ → Set α) (H : ∀ x, ∃ n, x ∈ s n)
[∀ x n, Decidable (x ∈ s n)] (n : ℕ) : (fun x => Nat.find (H x)) ⁻¹' {n} = disjointed s n := by
ext x
simp [Nat.find_eq_iff, disjointed_eq_inter_compl]
|
Order\Estimator.lean | /-
Copyright (c) 2023 Kim Liesinger. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Liesinger
-/
import Mathlib.Data.Set.Defs
import Mathlib.Order.Heyting.Basic
import Mathlib.Order.RelClasses
import Mathlib.Order.Hom.Basic
import Mathlib.Lean.Thunk
/-!
# Improvable lower bounds.
The typeclass `Estimator a ε`, where `a : Thunk α` and `ε : Type`,
states that `e : ε` carries the data of a lower bound for `a.get`,
in the form `bound_le : bound a e ≤ a.get`,
along with a mechanism for asking for a better bound `improve e : Option ε`,
satisfying
```
match improve e with
| none => bound e = a.get
| some e' => bound e < bound e'
```
i.e. it returns `none` if the current bound is already optimal,
and otherwise a strictly better bound.
(The value in `α` is hidden inside a `Thunk` to prevent evaluating it:
the point of this typeclass is to work with cheap-to-compute lower bounds for expensive values.)
An appropriate well-foundedness condition would then ensure that repeated improvements reach
the exact value.
-/
variable {α ε : Type*}
/--
Given `[EstimatorData a ε]`
* a term `e : ε` can be interpreted via `bound a e : α` as a lower bound for `a`, and
* we can ask for an improved lower bound via `improve a e : Option ε`.
The value `a` in `α` that we are estimating is hidden inside a `Thunk` to avoid evaluation.
-/
class EstimatorData (a : Thunk α) (ε : Type*) where
/-- The value of the bound for `a` representation by a term of `ε`. -/
bound : ε → α
/-- Generate an improved lower bound. -/
improve : ε → Option ε
/--
Given `[Estimator a ε]`
* we have `bound a e ≤ a.get`, and
* `improve a e` returns none iff `bound a e = a.get`,
and otherwise it returns a strictly better bound.
-/
class Estimator [Preorder α] (a : Thunk α) (ε : Type*) extends EstimatorData a ε where
/-- The calculated bounds are always lower bounds. -/
bound_le e : bound e ≤ a.get
/-- Calling `improve` either gives a strictly better bound,
or a proof that the current bound is exact. -/
improve_spec e : match improve e with
| none => bound e = a.get
| some e' => bound e < bound e'
open EstimatorData Set
section trivial
variable [Preorder α]
/-- A trivial estimator, containing the actual value. -/
abbrev Estimator.trivial.{u} {α : Type u} (a : α) : Type u := { b : α // b = a }
instance {a : α} : Bot (Estimator.trivial a) := ⟨⟨a, rfl⟩⟩
instance : WellFoundedGT Unit where
wf := ⟨fun .unit => ⟨.unit, nofun⟩⟩
instance (a : α) : WellFoundedGT (Estimator.trivial a) :=
let f : Estimator.trivial a ≃o Unit := RelIso.relIsoOfUniqueOfRefl _ _
let f' : Estimator.trivial a ↪o Unit := f.toOrderEmbedding
f'.wellFoundedGT
instance {a : α} : Estimator (Thunk.pure a) (Estimator.trivial a) where
bound b := b.val
improve _ := none
bound_le b := b.prop.le
improve_spec b := b.prop
end trivial
section improveUntil
variable [Preorder α]
attribute [local instance] WellFoundedGT.toWellFoundedRelation in
/-- Implementation of `Estimator.improveUntil`. -/
def Estimator.improveUntilAux
(a : Thunk α) (p : α → Bool) [Estimator a ε]
[WellFoundedGT (range (bound a : ε → α))]
(e : ε) (r : Bool) : Except (Option ε) ε :=
if p (bound a e) then
return e
else
match improve a e, improve_spec e with
| none, _ => .error <| if r then none else e
| some e', _ =>
improveUntilAux a p e' true
termination_by (⟨_, mem_range_self e⟩ : range (bound a))
/--
Improve an estimate until it satisfies a predicate,
or else return the best available estimate, if any improvement was made.
-/
def Estimator.improveUntil (a : Thunk α) (p : α → Bool)
[Estimator a ε] [WellFoundedGT (range (bound a : ε → α))] (e : ε) :
Except (Option ε) ε :=
Estimator.improveUntilAux a p e false
attribute [local instance] WellFoundedGT.toWellFoundedRelation in
/--
If `Estimator.improveUntil a p e` returns `some e'`, then `bound a e'` satisfies `p`.
Otherwise, that value `a` must not satisfy `p`.
-/
theorem Estimator.improveUntilAux_spec (a : Thunk α) (p : α → Bool)
[Estimator a ε] [WellFoundedGT (range (bound a : ε → α))] (e : ε) (r : Bool) :
match Estimator.improveUntilAux a p e r with
| .error _ => ¬ p a.get
| .ok e' => p (bound a e') := by
rw [Estimator.improveUntilAux]
by_cases h : p (bound a e)
· simp only [h]; exact h
· simp only [h]
match improve a e, improve_spec e with
| none, eq =>
simp only [Bool.not_eq_true]
rw [eq] at h
exact Bool.bool_eq_false h
| some e', _ =>
exact Estimator.improveUntilAux_spec a p e' true
termination_by (⟨_, mem_range_self e⟩ : range (bound a))
/--
If `Estimator.improveUntil a p e` returns `some e'`, then `bound a e'` satisfies `p`.
Otherwise, that value `a` must not satisfy `p`.
-/
theorem Estimator.improveUntil_spec
(a : Thunk α) (p : α → Bool) [Estimator a ε] [WellFoundedGT (range (bound a : ε → α))] (e : ε) :
match Estimator.improveUntil a p e with
| .error _ => ¬ p a.get
| .ok e' => p (bound a e') :=
Estimator.improveUntilAux_spec a p e false
end improveUntil
/-! Estimators for sums. -/
section add
variable [Preorder α]
@[simps]
instance [Add α] {a b : Thunk α} (εa εb : Type*) [EstimatorData a εa] [EstimatorData b εb] :
EstimatorData (a + b) (εa × εb) where
bound e := bound a e.1 + bound b e.2
improve e := match improve a e.1 with
| some e' => some { e with fst := e' }
| none => match improve b e.2 with
| some e' => some { e with snd := e' }
| none => none
instance (a b : Thunk ℕ) {εa εb : Type*} [Estimator a εa] [Estimator b εb] :
Estimator (a + b) (εa × εb) where
bound_le e :=
Nat.add_le_add (Estimator.bound_le e.1) (Estimator.bound_le e.2)
improve_spec e := by
dsimp
have s₁ := Estimator.improve_spec (a := a) e.1
have s₂ := Estimator.improve_spec (a := b) e.2
revert s₁ s₂
cases improve a e.fst <;> cases improve b e.snd <;> intro s₁ s₂ <;> simp_all only
· apply Nat.add_lt_add_left s₂
· apply Nat.add_lt_add_right s₁
· apply Nat.add_lt_add_right s₁
end add
/-! Estimator for the first component of a pair. -/
section fst
variable {β : Type*} [PartialOrder α] [PartialOrder β]
/--
An estimator for `(a, b)` can be turned into an estimator for `a`,
simply by repeatedly running `improve` until the first factor "improves".
The hypothesis that `>` is well-founded on `{ q // q ≤ (a, b) }` ensures this terminates.
-/
structure Estimator.fst
(p : Thunk (α × β)) (ε : Type*) [Estimator p ε] where
/-- The wrapped bound for a value in `α × β`,
which we will use as a bound for the first component. -/
inner : ε
variable [∀ a : α, WellFoundedGT { x // x ≤ a }]
instance {a : Thunk α} [Estimator a ε] : WellFoundedGT (range (bound a : ε → α)) :=
let f : range (bound a : ε → α) ↪o { x // x ≤ a.get } :=
Subtype.orderEmbedding (by rintro _ ⟨e, rfl⟩; exact Estimator.bound_le e)
f.wellFoundedGT
instance [DecidableRel ((· : α) < ·)] {a : Thunk α} {b : Thunk β}
(ε : Type*) [Estimator (a.prod b) ε] [∀ (p : α × β), WellFoundedGT { q // q ≤ p }] :
EstimatorData a (Estimator.fst (a.prod b) ε) where
bound e := (bound (a.prod b) e.inner).1
improve e :=
let bd := (bound (a.prod b) e.inner).1
Estimator.improveUntil (a.prod b) (fun p => bd < p.1) e.inner
|>.toOption |>.map Estimator.fst.mk
/-- Given an estimator for a pair, we can extract an estimator for the first factor. -/
-- This isn't an instance as at the sole use case we need to provide
-- the instance arguments by hand anyway.
def Estimator.fstInst [DecidableRel ((· : α) < ·)] [∀ (p : α × β), WellFoundedGT { q // q ≤ p }]
(a : Thunk α) (b : Thunk β) (i : Estimator (a.prod b) ε) :
Estimator a (Estimator.fst (a.prod b) ε) where
bound_le e := (Estimator.bound_le e.inner : bound (a.prod b) e.inner ≤ (a.get, b.get)).1
improve_spec e := by
let bd := (bound (a.prod b) e.inner).1
have := Estimator.improveUntil_spec (a.prod b) (fun p => bd < p.1) e.inner
revert this
simp only [EstimatorData.improve, decide_eq_true_eq]
match Estimator.improveUntil (a.prod b) _ _ with
| .error _ =>
simp only [Option.map_none']
exact fun w =>
eq_of_le_of_not_lt
(Estimator.bound_le e.inner : bound (a.prod b) e.inner ≤ (a.get, b.get)).1 w
| .ok e' => exact fun w => w
end fst
|
Order\FixedPoints.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau, Yury Kudryashov
-/
import Mathlib.Dynamics.FixedPoints.Basic
import Mathlib.Order.Hom.Order
/-!
# Fixed point construction on complete lattices
This file sets up the basic theory of fixed points of a monotone function in a complete lattice.
## Main definitions
* `OrderHom.lfp`: The least fixed point of a bundled monotone function.
* `OrderHom.gfp`: The greatest fixed point of a bundled monotone function.
* `OrderHom.prevFixed`: The greatest fixed point of a bundled monotone function smaller than or
equal to a given element.
* `OrderHom.nextFixed`: The least fixed point of a bundled monotone function greater than or
equal to a given element.
* `fixedPoints.completeLattice`: The Knaster-Tarski theorem: fixed points of a monotone
self-map of a complete lattice form themselves a complete lattice.
## Tags
fixed point, complete lattice, monotone function
-/
universe u v w
variable {α : Type u} {β : Type v} {γ : Type w}
open Function (fixedPoints IsFixedPt)
namespace OrderHom
section Basic
variable [CompleteLattice α] (f : α →o α)
/-- Least fixed point of a monotone function -/
def lfp : (α →o α) →o α where
toFun f := sInf { a | f a ≤ a }
monotone' _ _ hle := sInf_le_sInf fun a ha => (hle a).trans ha
/-- Greatest fixed point of a monotone function -/
def gfp : (α →o α) →o α where
toFun f := sSup { a | a ≤ f a }
monotone' _ _ hle := sSup_le_sSup fun a ha => le_trans ha (hle a)
theorem lfp_le {a : α} (h : f a ≤ a) : lfp f ≤ a :=
sInf_le h
theorem lfp_le_fixed {a : α} (h : f a = a) : lfp f ≤ a :=
f.lfp_le h.le
theorem le_lfp {a : α} (h : ∀ b, f b ≤ b → a ≤ b) : a ≤ lfp f :=
le_sInf h
-- Porting note: for the rest of the file, replace the dot notation `_.lfp` with `lfp _`
-- same for `_.gfp`, `_.dual`
-- Probably related to https://github.com/leanprover/lean4/issues/1910
theorem map_le_lfp {a : α} (ha : a ≤ lfp f) : f a ≤ lfp f :=
f.le_lfp fun _ hb => (f.mono <| le_sInf_iff.1 ha _ hb).trans hb
@[simp]
theorem map_lfp : f (lfp f) = lfp f :=
have h : f (lfp f) ≤ lfp f := f.map_le_lfp le_rfl
h.antisymm <| f.lfp_le <| f.mono h
theorem isFixedPt_lfp : IsFixedPt f (lfp f) :=
f.map_lfp
theorem lfp_le_map {a : α} (ha : lfp f ≤ a) : lfp f ≤ f a :=
calc
lfp f = f (lfp f) := f.map_lfp.symm
_ ≤ f a := f.mono ha
theorem isLeast_lfp_le : IsLeast { a | f a ≤ a } (lfp f) :=
⟨f.map_lfp.le, fun _ => f.lfp_le⟩
theorem isLeast_lfp : IsLeast (fixedPoints f) (lfp f) :=
⟨f.isFixedPt_lfp, fun _ => f.lfp_le_fixed⟩
theorem lfp_induction {p : α → Prop} (step : ∀ a, p a → a ≤ lfp f → p (f a))
(hSup : ∀ s, (∀ a ∈ s, p a) → p (sSup s)) : p (lfp f) := by
set s := { a | a ≤ lfp f ∧ p a }
specialize hSup s fun a => And.right
suffices sSup s = lfp f from this ▸ hSup
have h : sSup s ≤ lfp f := sSup_le fun b => And.left
have hmem : f (sSup s) ∈ s := ⟨f.map_le_lfp h, step _ hSup h⟩
exact h.antisymm (f.lfp_le <| le_sSup hmem)
theorem le_gfp {a : α} (h : a ≤ f a) : a ≤ gfp f :=
le_sSup h
theorem gfp_le {a : α} (h : ∀ b, b ≤ f b → b ≤ a) : gfp f ≤ a :=
sSup_le h
theorem isFixedPt_gfp : IsFixedPt f (gfp f) :=
f.dual.isFixedPt_lfp
@[simp]
theorem map_gfp : f (gfp f) = gfp f :=
f.dual.map_lfp
theorem map_le_gfp {a : α} (ha : a ≤ gfp f) : f a ≤ gfp f :=
f.dual.lfp_le_map ha
theorem gfp_le_map {a : α} (ha : gfp f ≤ a) : gfp f ≤ f a :=
f.dual.map_le_lfp ha
theorem isGreatest_gfp_le : IsGreatest { a | a ≤ f a } (gfp f) :=
f.dual.isLeast_lfp_le
theorem isGreatest_gfp : IsGreatest (fixedPoints f) (gfp f) :=
f.dual.isLeast_lfp
theorem gfp_induction {p : α → Prop} (step : ∀ a, p a → gfp f ≤ a → p (f a))
(hInf : ∀ s, (∀ a ∈ s, p a) → p (sInf s)) : p (gfp f) :=
f.dual.lfp_induction step hInf
end Basic
section Eqn
variable [CompleteLattice α] [CompleteLattice β] (f : β →o α) (g : α →o β)
-- Rolling rule
theorem map_lfp_comp : f (lfp (g.comp f)) = lfp (f.comp g) :=
le_antisymm ((f.comp g).map_lfp ▸ f.mono (lfp_le_fixed _ <| congr_arg g (f.comp g).map_lfp)) <|
lfp_le _ (congr_arg f (g.comp f).map_lfp).le
theorem map_gfp_comp : f (gfp (g.comp f)) = gfp (f.comp g) :=
f.dual.map_lfp_comp (OrderHom.dual g)
-- Diagonal rule
theorem lfp_lfp (h : α →o α →o α) : lfp (lfp.comp h) = lfp h.onDiag := by
let a := lfp (lfp.comp h)
refine (lfp_le _ ?_).antisymm (lfp_le _ (Eq.le ?_))
· exact lfp_le _ h.onDiag.map_lfp.le
have ha : (lfp ∘ h) a = a := (lfp.comp h).map_lfp
calc
h a a = h a (lfp (h a)) := congr_arg (h a) ha.symm
_ = lfp (h a) := (h a).map_lfp
_ = a := ha
theorem gfp_gfp (h : α →o α →o α) : gfp (gfp.comp h) = gfp h.onDiag :=
@lfp_lfp αᵒᵈ _ <| (OrderHom.dualIso αᵒᵈ αᵒᵈ).symm.toOrderEmbedding.toOrderHom.comp
(OrderHom.dual h)
end Eqn
section PrevNext
variable [CompleteLattice α] (f : α →o α)
theorem gfp_const_inf_le (x : α) : gfp (const α x ⊓ f) ≤ x :=
(gfp_le _) fun _ hb => hb.trans inf_le_left
/-- Previous fixed point of a monotone map. If `f` is a monotone self-map of a complete lattice and
`x` is a point such that `f x ≤ x`, then `f.prevFixed x hx` is the greatest fixed point of `f`
that is less than or equal to `x`. -/
def prevFixed (x : α) (hx : f x ≤ x) : fixedPoints f :=
⟨gfp (const α x ⊓ f),
calc
f (gfp (const α x ⊓ f)) = x ⊓ f (gfp (const α x ⊓ f)) :=
Eq.symm <| inf_of_le_right <| (f.mono <| f.gfp_const_inf_le x).trans hx
_ = gfp (const α x ⊓ f) := (const α x ⊓ f).map_gfp
⟩
/-- Next fixed point of a monotone map. If `f` is a monotone self-map of a complete lattice and
`x` is a point such that `x ≤ f x`, then `f.nextFixed x hx` is the least fixed point of `f`
that is greater than or equal to `x`. -/
def nextFixed (x : α) (hx : x ≤ f x) : fixedPoints f :=
{ f.dual.prevFixed x hx with val := lfp (const α x ⊔ f) }
theorem prevFixed_le {x : α} (hx : f x ≤ x) : ↑(f.prevFixed x hx) ≤ x :=
f.gfp_const_inf_le x
theorem le_nextFixed {x : α} (hx : x ≤ f x) : x ≤ f.nextFixed x hx :=
f.dual.prevFixed_le hx
theorem nextFixed_le {x : α} (hx : x ≤ f x) {y : fixedPoints f} (h : x ≤ y) :
f.nextFixed x hx ≤ y :=
Subtype.coe_le_coe.1 <| lfp_le _ <| sup_le h y.2.le
@[simp]
theorem nextFixed_le_iff {x : α} (hx : x ≤ f x) {y : fixedPoints f} :
f.nextFixed x hx ≤ y ↔ x ≤ y :=
⟨fun h => (f.le_nextFixed hx).trans h, f.nextFixed_le hx⟩
@[simp]
theorem le_prevFixed_iff {x : α} (hx : f x ≤ x) {y : fixedPoints f} :
y ≤ f.prevFixed x hx ↔ ↑y ≤ x :=
f.dual.nextFixed_le_iff hx
theorem le_prevFixed {x : α} (hx : f x ≤ x) {y : fixedPoints f} (h : ↑y ≤ x) :
y ≤ f.prevFixed x hx :=
(f.le_prevFixed_iff hx).2 h
theorem le_map_sup_fixedPoints (x y : fixedPoints f) : (x ⊔ y : α) ≤ f (x ⊔ y) :=
calc
(x ⊔ y : α) = f x ⊔ f y := congr_arg₂ (· ⊔ ·) x.2.symm y.2.symm
_ ≤ f (x ⊔ y) := f.mono.le_map_sup x y
-- Porting note: `x ⊓ y` without the `.val`sw fails to synthesize `Inf` instance
theorem map_inf_fixedPoints_le (x y : fixedPoints f) : f (x ⊓ y) ≤ x.val ⊓ y.val :=
f.dual.le_map_sup_fixedPoints x y
theorem le_map_sSup_subset_fixedPoints (A : Set α) (hA : A ⊆ fixedPoints f) :
sSup A ≤ f (sSup A) :=
sSup_le fun _ hx => hA hx ▸ (f.mono <| le_sSup hx)
theorem map_sInf_subset_fixedPoints_le (A : Set α) (hA : A ⊆ fixedPoints f) :
f (sInf A) ≤ sInf A :=
le_sInf fun _ hx => hA hx ▸ (f.mono <| sInf_le hx)
end PrevNext
end OrderHom
namespace fixedPoints
open OrderHom
variable [CompleteLattice α] (f : α →o α)
instance : SemilatticeSup (fixedPoints f) :=
{ Subtype.partialOrder _ with
sup := fun x y => f.nextFixed (x ⊔ y) (f.le_map_sup_fixedPoints x y)
le_sup_left := fun _ _ => Subtype.coe_le_coe.1 <| le_sup_left.trans (f.le_nextFixed _)
le_sup_right := fun _ _ => Subtype.coe_le_coe.1 <| le_sup_right.trans (f.le_nextFixed _)
sup_le := fun _ _ _ hxz hyz => f.nextFixed_le _ <| sup_le hxz hyz }
/- porting note: removed `Subtype.partialOrder _` from mathlib3port version,
threw `typeclass instance` error and was seemingly unnecessary?-/
instance : SemilatticeInf (fixedPoints f) :=
{ OrderDual.instSemilatticeInf (fixedPoints (OrderHom.dual f)) with
inf := fun x y => f.prevFixed (x ⊓ y) (f.map_inf_fixedPoints_le x y) }
-- Porting note: `coe` replaced with `Subtype.val`
instance : CompleteSemilatticeSup (fixedPoints f) :=
{ Subtype.partialOrder _ with
sSup := fun s =>
f.nextFixed (sSup (Subtype.val '' s))
(f.le_map_sSup_subset_fixedPoints (Subtype.val '' s)
fun _ ⟨x, hx⟩ => hx.2 ▸ x.2)
le_sSup := fun _ _ hx =>
Subtype.coe_le_coe.1 <| le_trans (le_sSup <| Set.mem_image_of_mem _ hx) (f.le_nextFixed _)
sSup_le := fun _ _ hx => f.nextFixed_le _ <| sSup_le <| Set.forall_mem_image.2 hx }
instance : CompleteSemilatticeInf (fixedPoints f) :=
{ Subtype.partialOrder _ with
sInf := fun s =>
f.prevFixed (sInf (Subtype.val '' s))
(f.map_sInf_subset_fixedPoints_le (Subtype.val '' s) fun _ ⟨x, hx⟩ => hx.2 ▸ x.2)
le_sInf := fun _ _ hx => f.le_prevFixed _ <| le_sInf <| Set.forall_mem_image.2 hx
sInf_le := fun _ _ hx =>
Subtype.coe_le_coe.1 <| le_trans (f.prevFixed_le _) (sInf_le <| Set.mem_image_of_mem _ hx) }
/- porting note: mathlib3port version contained the instances as a list,
giving various "expected structure" errors -/
/-- **Knaster-Tarski Theorem**: The fixed points of `f` form a complete lattice. -/
instance completeLattice : CompleteLattice (fixedPoints f) where
__ := inferInstanceAs (SemilatticeInf (fixedPoints f))
__ := inferInstanceAs (SemilatticeSup (fixedPoints f))
__ := inferInstanceAs (CompleteSemilatticeInf (fixedPoints f))
__ := inferInstanceAs (CompleteSemilatticeSup (fixedPoints f))
top := ⟨gfp f, f.isFixedPt_gfp⟩
bot := ⟨lfp f, f.isFixedPt_lfp⟩
le_top x := f.le_gfp x.2.ge
bot_le x := f.lfp_le x.2.le
end fixedPoints
|
Order\GaloisConnection.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Order.CompleteLattice
import Mathlib.Order.Synonym
import Mathlib.Order.Hom.Set
import Mathlib.Order.Bounds.Basic
/-!
# Galois connections, insertions and coinsertions
Galois connections are order theoretic adjoints, i.e. a pair of functions `u` and `l`,
such that `∀ a b, l a ≤ b ↔ a ≤ u b`.
## Main definitions
* `GaloisConnection`: A Galois connection is a pair of functions `l` and `u` satisfying
`l a ≤ b ↔ a ≤ u b`. They are special cases of adjoint functors in category theory,
but do not depend on the category theory library in mathlib.
* `GaloisInsertion`: A Galois insertion is a Galois connection where `l ∘ u = id`
* `GaloisCoinsertion`: A Galois coinsertion is a Galois connection where `u ∘ l = id`
## Implementation details
Galois insertions can be used to lift order structures from one type to another.
For example, if `α` is a complete lattice, and `l : α → β` and `u : β → α` form a Galois insertion,
then `β` is also a complete lattice. `l` is the lower adjoint and `u` is the upper adjoint.
An example of a Galois insertion is in group theory. If `G` is a group, then there is a Galois
insertion between the set of subsets of `G`, `Set G`, and the set of subgroups of `G`,
`Subgroup G`. The lower adjoint is `Subgroup.closure`, taking the `Subgroup` generated by a `Set`,
and the upper adjoint is the coercion from `Subgroup G` to `Set G`, taking the underlying set
of a subgroup.
Naively lifting a lattice structure along this Galois insertion would mean that the definition
of `inf` on subgroups would be `Subgroup.closure (↑S ∩ ↑T)`. This is an undesirable definition
because the intersection of subgroups is already a subgroup, so there is no need to take the
closure. For this reason a `choice` function is added as a field to the `GaloisInsertion`
structure. It has type `Π S : Set G, ↑(closure S) ≤ S → Subgroup G`. When `↑(closure S) ≤ S`, then
`S` is already a subgroup, so this function can be defined using `Subgroup.mk` and not `closure`.
This means the infimum of subgroups will be defined to be the intersection of sets, paired
with a proof that intersection of subgroups is a subgroup, rather than the closure of the
intersection.
-/
open Function OrderDual Set
universe u v w x
variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {κ : ι → Sort*} {a a₁ a₂ : α}
{b b₁ b₂ : β}
/-- A Galois connection is a pair of functions `l` and `u` satisfying
`l a ≤ b ↔ a ≤ u b`. They are special cases of adjoint functors in category theory,
but do not depend on the category theory library in mathlib. -/
def GaloisConnection [Preorder α] [Preorder β] (l : α → β) (u : β → α) :=
∀ a b, l a ≤ b ↔ a ≤ u b
/-- Makes a Galois connection from an order-preserving bijection. -/
theorem OrderIso.to_galoisConnection [Preorder α] [Preorder β] (oi : α ≃o β) :
GaloisConnection oi oi.symm := fun _ _ => oi.rel_symm_apply.symm
namespace GaloisConnection
section
variable [Preorder α] [Preorder β] {l : α → β} {u : β → α} (gc : GaloisConnection l u)
theorem monotone_intro (hu : Monotone u) (hl : Monotone l) (hul : ∀ a, a ≤ u (l a))
(hlu : ∀ a, l (u a) ≤ a) : GaloisConnection l u := fun _ _ =>
⟨fun h => (hul _).trans (hu h), fun h => (hl h).trans (hlu _)⟩
protected theorem dual {l : α → β} {u : β → α} (gc : GaloisConnection l u) :
GaloisConnection (OrderDual.toDual ∘ u ∘ OrderDual.ofDual)
(OrderDual.toDual ∘ l ∘ OrderDual.ofDual) :=
fun a b => (gc b a).symm
theorem le_iff_le {a : α} {b : β} : l a ≤ b ↔ a ≤ u b :=
gc _ _
theorem l_le {a : α} {b : β} : a ≤ u b → l a ≤ b :=
(gc _ _).mpr
theorem le_u {a : α} {b : β} : l a ≤ b → a ≤ u b :=
(gc _ _).mp
theorem le_u_l (a) : a ≤ u (l a) :=
gc.le_u <| le_rfl
theorem l_u_le (a) : l (u a) ≤ a :=
gc.l_le <| le_rfl
theorem monotone_u : Monotone u := fun a _ H => gc.le_u ((gc.l_u_le a).trans H)
theorem monotone_l : Monotone l :=
gc.dual.monotone_u.dual
theorem upperBounds_l_image (gc : GaloisConnection l u) (s : Set α) :
upperBounds (l '' s) = u ⁻¹' upperBounds s :=
Set.ext fun b => by simp [upperBounds, gc _ _]
theorem lowerBounds_u_image (gc : GaloisConnection l u) (s : Set β) :
lowerBounds (u '' s) = l ⁻¹' lowerBounds s :=
gc.dual.upperBounds_l_image s
theorem bddAbove_l_image {s : Set α} : BddAbove (l '' s) ↔ BddAbove s :=
⟨fun ⟨x, hx⟩ => ⟨u x, by rwa [gc.upperBounds_l_image] at hx⟩, gc.monotone_l.map_bddAbove⟩
theorem bddBelow_u_image {s : Set β} : BddBelow (u '' s) ↔ BddBelow s :=
gc.dual.bddAbove_l_image
theorem isLUB_l_image {s : Set α} {a : α} (h : IsLUB s a) : IsLUB (l '' s) (l a) :=
⟨gc.monotone_l.mem_upperBounds_image h.left, fun b hb =>
gc.l_le <| h.right <| by rwa [gc.upperBounds_l_image] at hb⟩
theorem isGLB_u_image {s : Set β} {b : β} (h : IsGLB s b) : IsGLB (u '' s) (u b) :=
gc.dual.isLUB_l_image h
theorem isLeast_l {a : α} : IsLeast { b | a ≤ u b } (l a) :=
⟨gc.le_u_l _, fun _ hb => gc.l_le hb⟩
theorem isGreatest_u {b : β} : IsGreatest { a | l a ≤ b } (u b) :=
gc.dual.isLeast_l
theorem isGLB_l {a : α} : IsGLB { b | a ≤ u b } (l a) :=
gc.isLeast_l.isGLB
theorem isLUB_u {b : β} : IsLUB { a | l a ≤ b } (u b) :=
gc.isGreatest_u.isLUB
/-- If `(l, u)` is a Galois connection, then the relation `x ≤ u (l y)` is a transitive relation.
If `l` is a closure operator (`Submodule.span`, `Subgroup.closure`, ...) and `u` is the coercion to
`Set`, this reads as "if `U` is in the closure of `V` and `V` is in the closure of `W` then `U` is
in the closure of `W`". -/
theorem le_u_l_trans {x y z : α} (hxy : x ≤ u (l y)) (hyz : y ≤ u (l z)) : x ≤ u (l z) :=
hxy.trans (gc.monotone_u <| gc.l_le hyz)
theorem l_u_le_trans {x y z : β} (hxy : l (u x) ≤ y) (hyz : l (u y) ≤ z) : l (u x) ≤ z :=
(gc.monotone_l <| gc.le_u hxy).trans hyz
end
section PartialOrder
variable [PartialOrder α] [Preorder β] {l : α → β} {u : β → α} (gc : GaloisConnection l u)
theorem u_l_u_eq_u (b : β) : u (l (u b)) = u b :=
(gc.monotone_u (gc.l_u_le _)).antisymm (gc.le_u_l _)
theorem u_l_u_eq_u' : u ∘ l ∘ u = u :=
funext gc.u_l_u_eq_u
theorem u_unique {l' : α → β} {u' : β → α} (gc' : GaloisConnection l' u') (hl : ∀ a, l a = l' a)
{b : β} : u b = u' b :=
le_antisymm (gc'.le_u <| hl (u b) ▸ gc.l_u_le _) (gc.le_u <| (hl (u' b)).symm ▸ gc'.l_u_le _)
/-- If there exists a `b` such that `a = u a`, then `b = l a` is one such element. -/
theorem exists_eq_u (a : α) : (∃ b : β, a = u b) ↔ a = u (l a) :=
⟨fun ⟨_, hS⟩ => hS.symm ▸ (gc.u_l_u_eq_u _).symm, fun HI => ⟨_, HI⟩⟩
theorem u_eq (gc : GaloisConnection l u) {z : α} {y : β} : u y = z ↔ ∀ x, x ≤ z ↔ l x ≤ y := by
constructor
· rintro rfl x
exact (gc x y).symm
· intro H
exact ((H <| u y).mpr (gc.l_u_le y)).antisymm ((gc _ _).mp <| (H z).mp le_rfl)
end PartialOrder
section PartialOrder
variable [Preorder α] [PartialOrder β] {l : α → β} {u : β → α} (gc : GaloisConnection l u)
theorem l_u_l_eq_l (a : α) : l (u (l a)) = l a := gc.dual.u_l_u_eq_u _
theorem l_u_l_eq_l' : l ∘ u ∘ l = l := funext gc.l_u_l_eq_l
theorem l_unique {l' : α → β} {u' : β → α} (gc' : GaloisConnection l' u') (hu : ∀ b, u b = u' b)
{a : α} : l a = l' a :=
gc.dual.u_unique gc'.dual hu
/-- If there exists an `a` such that `b = l a`, then `a = u b` is one such element. -/
theorem exists_eq_l (b : β) : (∃ a : α, b = l a) ↔ b = l (u b) := gc.dual.exists_eq_u _
theorem l_eq {x : α} {z : β} : l x = z ↔ ∀ y, z ≤ y ↔ x ≤ u y := gc.dual.u_eq
end PartialOrder
section OrderTop
variable [PartialOrder α] [Preorder β] [OrderTop α]
theorem u_eq_top {l : α → β} {u : β → α} (gc : GaloisConnection l u) {x} : u x = ⊤ ↔ l ⊤ ≤ x :=
top_le_iff.symm.trans gc.le_iff_le.symm
theorem u_top [OrderTop β] {l : α → β} {u : β → α} (gc : GaloisConnection l u) : u ⊤ = ⊤ :=
gc.u_eq_top.2 le_top
end OrderTop
section OrderBot
variable [Preorder α] [PartialOrder β] [OrderBot β]
theorem l_eq_bot {l : α → β} {u : β → α} (gc : GaloisConnection l u) {x} : l x = ⊥ ↔ x ≤ u ⊥ :=
gc.dual.u_eq_top
theorem l_bot [OrderBot α] {l : α → β} {u : β → α} (gc : GaloisConnection l u) : l ⊥ = ⊥ :=
gc.dual.u_top
end OrderBot
section SemilatticeSup
variable [SemilatticeSup α] [SemilatticeSup β] {l : α → β} {u : β → α} (gc : GaloisConnection l u)
theorem l_sup : l (a₁ ⊔ a₂) = l a₁ ⊔ l a₂ :=
(gc.isLUB_l_image isLUB_pair).unique <| by simp only [image_pair, isLUB_pair]
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] [SemilatticeInf β] {l : α → β} {u : β → α} (gc : GaloisConnection l u)
theorem u_inf : u (b₁ ⊓ b₂) = u b₁ ⊓ u b₂ := gc.dual.l_sup
end SemilatticeInf
section CompleteLattice
variable [CompleteLattice α] [CompleteLattice β] {l : α → β} {u : β → α}
theorem l_iSup (gc : GaloisConnection l u) {f : ι → α} : l (iSup f) = ⨆ i, l (f i) :=
Eq.symm <|
IsLUB.iSup_eq <|
show IsLUB (range (l ∘ f)) (l (iSup f)) by
rw [range_comp, ← sSup_range]; exact gc.isLUB_l_image (isLUB_sSup _)
theorem l_iSup₂ (gc : GaloisConnection l u) {f : ∀ i, κ i → α} :
l (⨆ (i) (j), f i j) = ⨆ (i) (j), l (f i j) := by
simp_rw [gc.l_iSup]
variable (gc : GaloisConnection l u)
theorem u_iInf {f : ι → β} : u (iInf f) = ⨅ i, u (f i) :=
gc.dual.l_iSup
theorem u_iInf₂ {f : ∀ i, κ i → β} : u (⨅ (i) (j), f i j) = ⨅ (i) (j), u (f i j) :=
gc.dual.l_iSup₂
theorem l_sSup (gc : GaloisConnection l u) {s : Set α} : l (sSup s) = ⨆ a ∈ s, l a := by
simp only [sSup_eq_iSup, gc.l_iSup]
theorem u_sInf {s : Set β} : u (sInf s) = ⨅ a ∈ s, u a :=
gc.dual.l_sSup
end CompleteLattice
section LinearOrder
variable [LinearOrder α] [LinearOrder β] {l : α → β} {u : β → α} (gc : GaloisConnection l u)
theorem lt_iff_lt {a : α} {b : β} : b < l a ↔ u b < a :=
lt_iff_lt_of_le_iff_le (gc a b)
end LinearOrder
-- Constructing Galois connections
section Constructions
protected theorem id [pα : Preorder α] : @GaloisConnection α α pα pα id id := fun _ _ =>
Iff.intro (fun x => x) fun x => x
protected theorem compose [Preorder α] [Preorder β] [Preorder γ] {l1 : α → β} {u1 : β → α}
{l2 : β → γ} {u2 : γ → β} (gc1 : GaloisConnection l1 u1) (gc2 : GaloisConnection l2 u2) :
GaloisConnection (l2 ∘ l1) (u1 ∘ u2) := fun _ _ ↦ (gc2 _ _).trans (gc1 _ _)
protected theorem dfun {ι : Type u} {α : ι → Type v} {β : ι → Type w} [∀ i, Preorder (α i)]
[∀ i, Preorder (β i)] (l : ∀ i, α i → β i) (u : ∀ i, β i → α i)
(gc : ∀ i, GaloisConnection (l i) (u i)) :
GaloisConnection (fun (a : ∀ i, α i) i => l i (a i)) fun b i => u i (b i) := fun a b =>
forall_congr' fun i => gc i (a i) (b i)
protected theorem compl [BooleanAlgebra α] [BooleanAlgebra β] {l : α → β} {u : β → α}
(gc : GaloisConnection l u) :
GaloisConnection (compl ∘ u ∘ compl) (compl ∘ l ∘ compl) := fun a b ↦ by
dsimp
rw [le_compl_iff_le_compl, gc, compl_le_iff_compl_le]
end Constructions
theorem l_comm_of_u_comm {X : Type*} [Preorder X] {Y : Type*} [Preorder Y] {Z : Type*}
[Preorder Z] {W : Type*} [PartialOrder W] {lYX : X → Y} {uXY : Y → X}
(hXY : GaloisConnection lYX uXY) {lWZ : Z → W} {uZW : W → Z} (hZW : GaloisConnection lWZ uZW)
{lWY : Y → W} {uYW : W → Y} (hWY : GaloisConnection lWY uYW) {lZX : X → Z} {uXZ : Z → X}
(hXZ : GaloisConnection lZX uXZ) (h : ∀ w, uXZ (uZW w) = uXY (uYW w)) {x : X} :
lWZ (lZX x) = lWY (lYX x) :=
(hXZ.compose hZW).l_unique (hXY.compose hWY) h
theorem u_comm_of_l_comm {X : Type*} [PartialOrder X] {Y : Type*} [Preorder Y] {Z : Type*}
[Preorder Z] {W : Type*} [Preorder W] {lYX : X → Y} {uXY : Y → X}
(hXY : GaloisConnection lYX uXY) {lWZ : Z → W} {uZW : W → Z} (hZW : GaloisConnection lWZ uZW)
{lWY : Y → W} {uYW : W → Y} (hWY : GaloisConnection lWY uYW) {lZX : X → Z} {uXZ : Z → X}
(hXZ : GaloisConnection lZX uXZ) (h : ∀ x, lWZ (lZX x) = lWY (lYX x)) {w : W} :
uXZ (uZW w) = uXY (uYW w) :=
(hXZ.compose hZW).u_unique (hXY.compose hWY) h
theorem l_comm_iff_u_comm {X : Type*} [PartialOrder X] {Y : Type*} [Preorder Y] {Z : Type*}
[Preorder Z] {W : Type*} [PartialOrder W] {lYX : X → Y} {uXY : Y → X}
(hXY : GaloisConnection lYX uXY) {lWZ : Z → W} {uZW : W → Z} (hZW : GaloisConnection lWZ uZW)
{lWY : Y → W} {uYW : W → Y} (hWY : GaloisConnection lWY uYW) {lZX : X → Z} {uXZ : Z → X}
(hXZ : GaloisConnection lZX uXZ) :
(∀ w : W, uXZ (uZW w) = uXY (uYW w)) ↔ ∀ x : X, lWZ (lZX x) = lWY (lYX x) :=
⟨hXY.l_comm_of_u_comm hZW hWY hXZ, hXY.u_comm_of_l_comm hZW hWY hXZ⟩
end GaloisConnection
section
/-- `sSup` and `Iic` form a Galois connection. -/
theorem gc_sSup_Iic [CompleteSemilatticeSup α] :
GaloisConnection (sSup : Set α → α) (Iic : α → Set α) :=
fun _ _ ↦ sSup_le_iff
/-- `toDual ∘ Ici` and `sInf ∘ ofDual` form a Galois connection. -/
theorem gc_Ici_sInf [CompleteSemilatticeInf α] :
GaloisConnection (toDual ∘ Ici : α → (Set α)ᵒᵈ) (sInf ∘ ofDual : (Set α)ᵒᵈ → α) :=
fun _ _ ↦ le_sInf_iff.symm
variable [CompleteLattice α] [CompleteLattice β] [CompleteLattice γ] {f : α → β → γ} {s : Set α}
{t : Set β} {l u : α → β → γ} {l₁ u₁ : β → γ → α} {l₂ u₂ : α → γ → β}
theorem sSup_image2_eq_sSup_sSup (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b))
(h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) : sSup (image2 l s t) = l (sSup s) (sSup t) := by
simp_rw [sSup_image2, ← (h₂ _).l_sSup, ← (h₁ _).l_sSup]
theorem sSup_image2_eq_sSup_sInf (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b))
(h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) :
sSup (image2 l s t) = l (sSup s) (sInf t) :=
sSup_image2_eq_sSup_sSup (β := βᵒᵈ) h₁ h₂
theorem sSup_image2_eq_sInf_sSup (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b))
(h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) : sSup (image2 l s t) = l (sInf s) (sSup t) :=
sSup_image2_eq_sSup_sSup (α := αᵒᵈ) h₁ h₂
theorem sSup_image2_eq_sInf_sInf (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b))
(h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) :
sSup (image2 l s t) = l (sInf s) (sInf t) :=
sSup_image2_eq_sSup_sSup (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂
theorem sInf_image2_eq_sInf_sInf (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b))
(h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) : sInf (image2 u s t) = u (sInf s) (sInf t) := by
simp_rw [sInf_image2, ← (h₂ _).u_sInf, ← (h₁ _).u_sInf]
theorem sInf_image2_eq_sInf_sSup (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b))
(h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) :
sInf (image2 u s t) = u (sInf s) (sSup t) :=
sInf_image2_eq_sInf_sInf (β := βᵒᵈ) h₁ h₂
theorem sInf_image2_eq_sSup_sInf (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual))
(h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) : sInf (image2 u s t) = u (sSup s) (sInf t) :=
sInf_image2_eq_sInf_sInf (α := αᵒᵈ) h₁ h₂
theorem sInf_image2_eq_sSup_sSup (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual))
(h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) :
sInf (image2 u s t) = u (sSup s) (sSup t) :=
sInf_image2_eq_sInf_sInf (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂
end
namespace OrderIso
variable [Preorder α] [Preorder β]
@[simp]
theorem bddAbove_image (e : α ≃o β) {s : Set α} : BddAbove (e '' s) ↔ BddAbove s :=
e.to_galoisConnection.bddAbove_l_image
@[simp]
theorem bddBelow_image (e : α ≃o β) {s : Set α} : BddBelow (e '' s) ↔ BddBelow s :=
e.dual.bddAbove_image
@[simp]
theorem bddAbove_preimage (e : α ≃o β) {s : Set β} : BddAbove (e ⁻¹' s) ↔ BddAbove s := by
rw [← e.bddAbove_image, e.image_preimage]
@[simp]
theorem bddBelow_preimage (e : α ≃o β) {s : Set β} : BddBelow (e ⁻¹' s) ↔ BddBelow s := by
rw [← e.bddBelow_image, e.image_preimage]
end OrderIso
namespace Nat
theorem galoisConnection_mul_div {k : ℕ} (h : 0 < k) :
GaloisConnection (fun n => n * k) fun n => n / k := fun _ _ => (le_div_iff_mul_le h).symm
end Nat
-- Porting note(#5171): this used to have a `@[nolint has_nonempty_instance]`
/-- A Galois insertion is a Galois connection where `l ∘ u = id`. It also contains a constructive
choice function, to give better definitional equalities when lifting order structures. Dual
to `GaloisCoinsertion` -/
structure GaloisInsertion {α β : Type*} [Preorder α] [Preorder β] (l : α → β) (u : β → α) where
/-- A contructive choice function for images of `l`. -/
choice : ∀ x : α, u (l x) ≤ x → β
/-- The Galois connection associated to a Galois insertion. -/
gc : GaloisConnection l u
/-- Main property of a Galois insertion. -/
le_l_u : ∀ x, x ≤ l (u x)
/-- Property of the choice function. -/
choice_eq : ∀ a h, choice a h = l a
/-- A constructor for a Galois insertion with the trivial `choice` function. -/
def GaloisInsertion.monotoneIntro {α β : Type*} [Preorder α] [Preorder β] {l : α → β} {u : β → α}
(hu : Monotone u) (hl : Monotone l) (hul : ∀ a, a ≤ u (l a)) (hlu : ∀ b, l (u b) = b) :
GaloisInsertion l u where
choice x _ := l x
gc := GaloisConnection.monotone_intro hu hl hul fun b => le_of_eq (hlu b)
le_l_u b := le_of_eq <| (hlu b).symm
choice_eq _ _ := rfl
/-- Makes a Galois insertion from an order-preserving bijection. -/
protected def OrderIso.toGaloisInsertion [Preorder α] [Preorder β] (oi : α ≃o β) :
GaloisInsertion oi oi.symm where
choice b _ := oi b
gc := oi.to_galoisConnection
le_l_u g := le_of_eq (oi.right_inv g).symm
choice_eq _ _ := rfl
/-- Make a `GaloisInsertion l u` from a `GaloisConnection l u` such that `∀ b, b ≤ l (u b)` -/
def GaloisConnection.toGaloisInsertion {α β : Type*} [Preorder α] [Preorder β] {l : α → β}
{u : β → α} (gc : GaloisConnection l u) (h : ∀ b, b ≤ l (u b)) : GaloisInsertion l u :=
{ choice := fun x _ => l x
gc
le_l_u := h
choice_eq := fun _ _ => rfl }
/-- Lift the bottom along a Galois connection -/
def GaloisConnection.liftOrderBot {α β : Type*} [Preorder α] [OrderBot α] [PartialOrder β]
{l : α → β} {u : β → α} (gc : GaloisConnection l u) :
OrderBot β where
bot := l ⊥
bot_le _ := gc.l_le <| bot_le
namespace GaloisInsertion
variable {l : α → β} {u : β → α}
theorem l_u_eq [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) (b : β) : l (u b) = b :=
(gi.gc.l_u_le _).antisymm (gi.le_l_u _)
theorem leftInverse_l_u [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) :
LeftInverse l u :=
gi.l_u_eq
theorem l_top [Preorder α] [PartialOrder β] [OrderTop α] [OrderTop β]
(gi : GaloisInsertion l u) : l ⊤ = ⊤ :=
top_unique <| (gi.le_l_u _).trans <| gi.gc.monotone_l le_top
theorem l_surjective [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) : Surjective l :=
gi.leftInverse_l_u.surjective
theorem u_injective [Preorder α] [PartialOrder β] (gi : GaloisInsertion l u) : Injective u :=
gi.leftInverse_l_u.injective
theorem l_sup_u [SemilatticeSup α] [SemilatticeSup β] (gi : GaloisInsertion l u) (a b : β) :
l (u a ⊔ u b) = a ⊔ b :=
calc
l (u a ⊔ u b) = l (u a) ⊔ l (u b) := gi.gc.l_sup
_ = a ⊔ b := by simp only [gi.l_u_eq]
theorem l_iSup_u [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) {ι : Sort x}
(f : ι → β) : l (⨆ i, u (f i)) = ⨆ i, f i :=
calc
l (⨆ i : ι, u (f i)) = ⨆ i : ι, l (u (f i)) := gi.gc.l_iSup
_ = ⨆ i : ι, f i := congr_arg _ <| funext fun i => gi.l_u_eq (f i)
theorem l_biSup_u [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) {ι : Sort x}
{p : ι → Prop} (f : ∀ i, p i → β) : l (⨆ (i) (hi), u (f i hi)) = ⨆ (i) (hi), f i hi := by
simp only [iSup_subtype', gi.l_iSup_u]
theorem l_sSup_u_image [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u)
(s : Set β) : l (sSup (u '' s)) = sSup s := by rw [sSup_image, gi.l_biSup_u, sSup_eq_iSup]
theorem l_inf_u [SemilatticeInf α] [SemilatticeInf β] (gi : GaloisInsertion l u) (a b : β) :
l (u a ⊓ u b) = a ⊓ b :=
calc
l (u a ⊓ u b) = l (u (a ⊓ b)) := congr_arg l gi.gc.u_inf.symm
_ = a ⊓ b := by simp only [gi.l_u_eq]
theorem l_iInf_u [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) {ι : Sort x}
(f : ι → β) : l (⨅ i, u (f i)) = ⨅ i, f i :=
calc
l (⨅ i : ι, u (f i)) = l (u (⨅ i : ι, f i)) := congr_arg l gi.gc.u_iInf.symm
_ = ⨅ i : ι, f i := gi.l_u_eq _
theorem l_biInf_u [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u) {ι : Sort x}
{p : ι → Prop} (f : ∀ (i) (_ : p i), β) : l (⨅ (i) (hi), u (f i hi)) = ⨅ (i) (hi), f i hi := by
simp only [iInf_subtype', gi.l_iInf_u]
theorem l_sInf_u_image [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u)
(s : Set β) : l (sInf (u '' s)) = sInf s := by rw [sInf_image, gi.l_biInf_u, sInf_eq_iInf]
theorem l_iInf_of_ul_eq_self [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u)
{ι : Sort x} (f : ι → α) (hf : ∀ i, u (l (f i)) = f i) : l (⨅ i, f i) = ⨅ i, l (f i) :=
calc
l (⨅ i, f i) = l (⨅ i : ι, u (l (f i))) := by simp [hf]
_ = ⨅ i, l (f i) := gi.l_iInf_u _
theorem l_biInf_of_ul_eq_self [CompleteLattice α] [CompleteLattice β] (gi : GaloisInsertion l u)
{ι : Sort x} {p : ι → Prop} (f : ∀ (i) (_ : p i), α) (hf : ∀ i hi, u (l (f i hi)) = f i hi) :
l (⨅ (i) (hi), f i hi) = ⨅ (i) (hi), l (f i hi) := by
rw [iInf_subtype', iInf_subtype']
exact gi.l_iInf_of_ul_eq_self _ fun _ => hf _ _
theorem u_le_u_iff [Preorder α] [Preorder β] (gi : GaloisInsertion l u) {a b} : u a ≤ u b ↔ a ≤ b :=
⟨fun h => (gi.le_l_u _).trans (gi.gc.l_le h), fun h => gi.gc.monotone_u h⟩
theorem strictMono_u [Preorder α] [Preorder β] (gi : GaloisInsertion l u) : StrictMono u :=
strictMono_of_le_iff_le fun _ _ => gi.u_le_u_iff.symm
theorem isLUB_of_u_image [Preorder α] [Preorder β] (gi : GaloisInsertion l u) {s : Set β} {a : α}
(hs : IsLUB (u '' s) a) : IsLUB s (l a) :=
⟨fun x hx => (gi.le_l_u x).trans <| gi.gc.monotone_l <| hs.1 <| mem_image_of_mem _ hx, fun _ hx =>
gi.gc.l_le <| hs.2 <| gi.gc.monotone_u.mem_upperBounds_image hx⟩
theorem isGLB_of_u_image [Preorder α] [Preorder β] (gi : GaloisInsertion l u) {s : Set β} {a : α}
(hs : IsGLB (u '' s) a) : IsGLB s (l a) :=
⟨fun _ hx => gi.gc.l_le <| hs.1 <| mem_image_of_mem _ hx, fun x hx =>
(gi.le_l_u x).trans <| gi.gc.monotone_l <| hs.2 <| gi.gc.monotone_u.mem_lowerBounds_image hx⟩
section lift
variable [PartialOrder β]
-- See note [reducible non instances]
/-- Lift the suprema along a Galois insertion -/
abbrev liftSemilatticeSup [SemilatticeSup α] (gi : GaloisInsertion l u) : SemilatticeSup β :=
{ ‹PartialOrder β› with
sup := fun a b => l (u a ⊔ u b)
le_sup_left := fun a _ => (gi.le_l_u a).trans <| gi.gc.monotone_l <| le_sup_left
le_sup_right := fun _ b => (gi.le_l_u b).trans <| gi.gc.monotone_l <| le_sup_right
sup_le := fun a b c hac hbc =>
gi.gc.l_le <| sup_le (gi.gc.monotone_u hac) (gi.gc.monotone_u hbc) }
-- See note [reducible non instances]
/-- Lift the infima along a Galois insertion -/
abbrev liftSemilatticeInf [SemilatticeInf α] (gi : GaloisInsertion l u) : SemilatticeInf β :=
{ ‹PartialOrder β› with
inf := fun a b =>
gi.choice (u a ⊓ u b) <|
le_inf (gi.gc.monotone_u <| gi.gc.l_le <| inf_le_left)
(gi.gc.monotone_u <| gi.gc.l_le <| inf_le_right)
inf_le_left := by simp only [gi.choice_eq]; exact fun a b => gi.gc.l_le inf_le_left
inf_le_right := by simp only [gi.choice_eq]; exact fun a b => gi.gc.l_le inf_le_right
le_inf := by
simp only [gi.choice_eq]
exact fun a b c hac hbc =>
(gi.le_l_u a).trans <|
gi.gc.monotone_l <| le_inf (gi.gc.monotone_u hac) (gi.gc.monotone_u hbc) }
-- See note [reducible non instances]
/-- Lift the suprema and infima along a Galois insertion -/
abbrev liftLattice [Lattice α] (gi : GaloisInsertion l u) : Lattice β :=
{ gi.liftSemilatticeSup, gi.liftSemilatticeInf with }
-- See note [reducible non instances]
/-- Lift the top along a Galois insertion -/
abbrev liftOrderTop [Preorder α] [OrderTop α] (gi : GaloisInsertion l u) :
OrderTop β where
top := gi.choice ⊤ <| le_top
le_top := by
simp only [gi.choice_eq]; exact fun b => (gi.le_l_u b).trans (gi.gc.monotone_l le_top)
-- See note [reducible non instances]
/-- Lift the top, bottom, suprema, and infima along a Galois insertion -/
abbrev liftBoundedOrder [Preorder α] [BoundedOrder α] (gi : GaloisInsertion l u) : BoundedOrder β :=
{ gi.liftOrderTop, gi.gc.liftOrderBot with }
-- See note [reducible non instances]
/-- Lift all suprema and infima along a Galois insertion -/
abbrev liftCompleteLattice [CompleteLattice α] (gi : GaloisInsertion l u) : CompleteLattice β :=
{ gi.liftBoundedOrder, gi.liftLattice with
sSup := fun s => l (sSup (u '' s))
sSup_le := fun s => (gi.isLUB_of_u_image (isLUB_sSup _)).2
le_sSup := fun s => (gi.isLUB_of_u_image (isLUB_sSup _)).1
sInf := fun s =>
gi.choice (sInf (u '' s)) <|
(isGLB_sInf _).2 <|
gi.gc.monotone_u.mem_lowerBounds_image (gi.isGLB_of_u_image <| isGLB_sInf _).1
sInf_le := fun s => by dsimp; rw [gi.choice_eq]; exact (gi.isGLB_of_u_image (isGLB_sInf _)).1
le_sInf := fun s => by dsimp; rw [gi.choice_eq]; exact (gi.isGLB_of_u_image (isGLB_sInf _)).2 }
end lift
end GaloisInsertion
-- Porting note(#5171): this used to have a `@[nolint has_nonempty_instance]`
/-- A Galois coinsertion is a Galois connection where `u ∘ l = id`. It also contains a constructive
choice function, to give better definitional equalities when lifting order structures. Dual to
`GaloisInsertion` -/
structure GaloisCoinsertion [Preorder α] [Preorder β] (l : α → β) (u : β → α) where
/-- A contructive choice function for images of `u`. -/
choice : ∀ x : β, x ≤ l (u x) → α
/-- The Galois connection associated to a Galois coinsertion. -/
gc : GaloisConnection l u
/-- Main property of a Galois coinsertion. -/
u_l_le : ∀ x, u (l x) ≤ x
/-- Property of the choice function. -/
choice_eq : ∀ a h, choice a h = u a
/-- Make a `GaloisInsertion` between `αᵒᵈ` and `βᵒᵈ` from a `GaloisCoinsertion` between `α` and
`β`. -/
def GaloisCoinsertion.dual [Preorder α] [Preorder β] {l : α → β} {u : β → α} :
GaloisCoinsertion l u → GaloisInsertion (toDual ∘ u ∘ ofDual) (toDual ∘ l ∘ ofDual) :=
fun x => ⟨x.1, x.2.dual, x.3, x.4⟩
/-- Make a `GaloisCoinsertion` between `αᵒᵈ` and `βᵒᵈ` from a `GaloisInsertion` between `α` and
`β`. -/
def GaloisInsertion.dual [Preorder α] [Preorder β] {l : α → β} {u : β → α} :
GaloisInsertion l u → GaloisCoinsertion (toDual ∘ u ∘ ofDual) (toDual ∘ l ∘ ofDual) :=
fun x => ⟨x.1, x.2.dual, x.3, x.4⟩
/-- Make a `GaloisInsertion` between `α` and `β` from a `GaloisCoinsertion` between `αᵒᵈ` and
`βᵒᵈ`. -/
def GaloisCoinsertion.ofDual [Preorder α] [Preorder β] {l : αᵒᵈ → βᵒᵈ} {u : βᵒᵈ → αᵒᵈ} :
GaloisCoinsertion l u → GaloisInsertion (ofDual ∘ u ∘ toDual) (ofDual ∘ l ∘ toDual) :=
fun x => ⟨x.1, x.2.dual, x.3, x.4⟩
/-- Make a `GaloisCoinsertion` between `α` and `β` from a `GaloisInsertion` between `αᵒᵈ` and
`βᵒᵈ`. -/
def GaloisInsertion.ofDual [Preorder α] [Preorder β] {l : αᵒᵈ → βᵒᵈ} {u : βᵒᵈ → αᵒᵈ} :
GaloisInsertion l u → GaloisCoinsertion (ofDual ∘ u ∘ toDual) (ofDual ∘ l ∘ toDual) :=
fun x => ⟨x.1, x.2.dual, x.3, x.4⟩
/-- Makes a Galois coinsertion from an order-preserving bijection. -/
protected def OrderIso.toGaloisCoinsertion [Preorder α] [Preorder β] (oi : α ≃o β) :
GaloisCoinsertion oi oi.symm where
choice b _ := oi.symm b
gc := oi.to_galoisConnection
u_l_le g := le_of_eq (oi.left_inv g)
choice_eq _ _ := rfl
/-- A constructor for a Galois coinsertion with the trivial `choice` function. -/
def GaloisCoinsertion.monotoneIntro [Preorder α] [Preorder β] {l : α → β} {u : β → α}
(hu : Monotone u) (hl : Monotone l) (hlu : ∀ b, l (u b) ≤ b) (hul : ∀ a, u (l a) = a) :
GaloisCoinsertion l u :=
(GaloisInsertion.monotoneIntro hl.dual hu.dual hlu hul).ofDual
/-- Make a `GaloisCoinsertion l u` from a `GaloisConnection l u` such that `∀ a, u (l a) ≤ a` -/
def GaloisConnection.toGaloisCoinsertion {α β : Type*} [Preorder α] [Preorder β] {l : α → β}
{u : β → α} (gc : GaloisConnection l u) (h : ∀ a, u (l a) ≤ a) : GaloisCoinsertion l u :=
{ choice := fun x _ => u x
gc
u_l_le := h
choice_eq := fun _ _ => rfl }
/-- Lift the top along a Galois connection -/
def GaloisConnection.liftOrderTop {α β : Type*} [PartialOrder α] [Preorder β] [OrderTop β]
{l : α → β} {u : β → α} (gc : GaloisConnection l u) :
OrderTop α where
top := u ⊤
le_top _ := gc.le_u <| le_top
namespace GaloisCoinsertion
variable {l : α → β} {u : β → α}
theorem u_l_eq [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) (a : α) : u (l a) = a :=
gi.dual.l_u_eq a
theorem u_l_leftInverse [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) :
LeftInverse u l :=
gi.u_l_eq
theorem u_bot [PartialOrder α] [Preorder β] [OrderBot α] [OrderBot β] (gi : GaloisCoinsertion l u) :
u ⊥ = ⊥ :=
gi.dual.l_top
theorem u_surjective [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) : Surjective u :=
gi.dual.l_surjective
theorem l_injective [PartialOrder α] [Preorder β] (gi : GaloisCoinsertion l u) : Injective l :=
gi.dual.u_injective
theorem u_inf_l [SemilatticeInf α] [SemilatticeInf β] (gi : GaloisCoinsertion l u) (a b : α) :
u (l a ⊓ l b) = a ⊓ b :=
gi.dual.l_sup_u a b
theorem u_iInf_l [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u) {ι : Sort x}
(f : ι → α) : u (⨅ i, l (f i)) = ⨅ i, f i :=
gi.dual.l_iSup_u _
theorem u_sInf_l_image [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u)
(s : Set α) : u (sInf (l '' s)) = sInf s :=
gi.dual.l_sSup_u_image _
theorem u_sup_l [SemilatticeSup α] [SemilatticeSup β] (gi : GaloisCoinsertion l u) (a b : α) :
u (l a ⊔ l b) = a ⊔ b :=
gi.dual.l_inf_u _ _
theorem u_iSup_l [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u) {ι : Sort x}
(f : ι → α) : u (⨆ i, l (f i)) = ⨆ i, f i :=
gi.dual.l_iInf_u _
theorem u_biSup_l [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u) {ι : Sort x}
{p : ι → Prop} (f : ∀ (i) (_ : p i), α) : u (⨆ (i) (hi), l (f i hi)) = ⨆ (i) (hi), f i hi :=
gi.dual.l_biInf_u _
theorem u_sSup_l_image [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u)
(s : Set α) : u (sSup (l '' s)) = sSup s :=
gi.dual.l_sInf_u_image _
theorem u_iSup_of_lu_eq_self [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u)
{ι : Sort x} (f : ι → β) (hf : ∀ i, l (u (f i)) = f i) : u (⨆ i, f i) = ⨆ i, u (f i) :=
gi.dual.l_iInf_of_ul_eq_self _ hf
theorem u_biSup_of_lu_eq_self [CompleteLattice α] [CompleteLattice β] (gi : GaloisCoinsertion l u)
{ι : Sort x} {p : ι → Prop} (f : ∀ (i) (_ : p i), β) (hf : ∀ i hi, l (u (f i hi)) = f i hi) :
u (⨆ (i) (hi), f i hi) = ⨆ (i) (hi), u (f i hi) :=
gi.dual.l_biInf_of_ul_eq_self _ hf
theorem l_le_l_iff [Preorder α] [Preorder β] (gi : GaloisCoinsertion l u) {a b} :
l a ≤ l b ↔ a ≤ b :=
gi.dual.u_le_u_iff
theorem strictMono_l [Preorder α] [Preorder β] (gi : GaloisCoinsertion l u) : StrictMono l :=
fun _ _ h => gi.dual.strictMono_u h
theorem isGLB_of_l_image [Preorder α] [Preorder β] (gi : GaloisCoinsertion l u) {s : Set α} {a : β}
(hs : IsGLB (l '' s) a) : IsGLB s (u a) :=
gi.dual.isLUB_of_u_image hs
theorem isLUB_of_l_image [Preorder α] [Preorder β] (gi : GaloisCoinsertion l u) {s : Set α} {a : β}
(hs : IsLUB (l '' s) a) : IsLUB s (u a) :=
gi.dual.isGLB_of_u_image hs
section lift
variable [PartialOrder α]
-- Porting note: In `liftSemilatticeInf` and `liftSemilatticeSup` below, the elaborator
-- seems to struggle with αᵒᵈ vs α; the `by exact`s are not present in Lean 3, but without
-- them the declarations compile much more slowly for some reason.
-- Possibly related to the issue discussed at
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Performance.20issue.20with.20.60CompleteBooleanAlgebra.60/near/316760798
-- See note [reducible non instances]
/-- Lift the infima along a Galois coinsertion -/
abbrev liftSemilatticeInf [SemilatticeInf β] (gi : GaloisCoinsertion l u) : SemilatticeInf α :=
{ ‹PartialOrder α› with
inf_le_left := fun a b => by
exact (@OrderDual.instSemilatticeInf αᵒᵈ gi.dual.liftSemilatticeSup).inf_le_left a b
inf_le_right := fun a b => by
exact (@OrderDual.instSemilatticeInf αᵒᵈ gi.dual.liftSemilatticeSup).inf_le_right a b
le_inf := fun a b c => by
exact (@OrderDual.instSemilatticeInf αᵒᵈ gi.dual.liftSemilatticeSup).le_inf a b c
inf := fun a b => u (l a ⊓ l b) }
-- See note [reducible non instances]
/-- Lift the suprema along a Galois coinsertion -/
abbrev liftSemilatticeSup [SemilatticeSup β] (gi : GaloisCoinsertion l u) : SemilatticeSup α :=
{ ‹PartialOrder α› with
sup := fun a b =>
gi.choice (l a ⊔ l b) <|
sup_le (gi.gc.monotone_l <| gi.gc.le_u <| le_sup_left)
(gi.gc.monotone_l <| gi.gc.le_u <| le_sup_right)
le_sup_left := fun a b => by
exact (@OrderDual.instSemilatticeSup αᵒᵈ gi.dual.liftSemilatticeInf).le_sup_left a b
le_sup_right := fun a b => by
exact (@OrderDual.instSemilatticeSup αᵒᵈ gi.dual.liftSemilatticeInf).le_sup_right a b
sup_le := fun a b c => by
exact (@OrderDual.instSemilatticeSup αᵒᵈ gi.dual.liftSemilatticeInf).sup_le a b c }
-- See note [reducible non instances]
/-- Lift the suprema and infima along a Galois coinsertion -/
abbrev liftLattice [Lattice β] (gi : GaloisCoinsertion l u) : Lattice α :=
{ gi.liftSemilatticeSup, gi.liftSemilatticeInf with }
-- See note [reducible non instances]
/-- Lift the bot along a Galois coinsertion -/
abbrev liftOrderBot [Preorder β] [OrderBot β] (gi : GaloisCoinsertion l u) : OrderBot α :=
{ @OrderDual.instOrderBot _ _ gi.dual.liftOrderTop with bot := gi.choice ⊥ <| bot_le }
-- See note [reducible non instances]
/-- Lift the top, bottom, suprema, and infima along a Galois coinsertion -/
abbrev liftBoundedOrder
[Preorder β] [BoundedOrder β] (gi : GaloisCoinsertion l u) : BoundedOrder α :=
{ gi.liftOrderBot, gi.gc.liftOrderTop with }
-- See note [reducible non instances]
/-- Lift all suprema and infima along a Galois coinsertion -/
abbrev liftCompleteLattice [CompleteLattice β] (gi : GaloisCoinsertion l u) : CompleteLattice α :=
{ @OrderDual.instCompleteLattice αᵒᵈ gi.dual.liftCompleteLattice with
sInf := fun s => u (sInf (l '' s))
sSup := fun s => gi.choice (sSup (l '' s)) _ }
end lift
end GaloisCoinsertion
/-- `sSup` and `Iic` form a Galois insertion. -/
def gi_sSup_Iic [CompleteSemilatticeSup α] :
GaloisInsertion (sSup : Set α → α) (Iic : α → Set α) :=
gc_sSup_Iic.toGaloisInsertion fun _ ↦ le_sSup le_rfl
/-- `toDual ∘ Ici` and `sInf ∘ ofDual` form a Galois coinsertion. -/
def gci_Ici_sInf [CompleteSemilatticeInf α] :
GaloisCoinsertion (toDual ∘ Ici : α → (Set α)ᵒᵈ) (sInf ∘ ofDual : (Set α)ᵒᵈ → α) :=
gc_Ici_sInf.toGaloisCoinsertion fun _ ↦ sInf_le le_rfl
/-- If `α` is a partial order with bottom element (e.g., `ℕ`, `ℝ≥0`), then `WithBot.unbot' ⊥` and
coercion form a Galois insertion. -/
def WithBot.giUnbot'Bot [Preorder α] [OrderBot α] :
GaloisInsertion (WithBot.unbot' ⊥) (some : α → WithBot α) where
gc _ _ := WithBot.unbot'_le_iff (fun _ ↦ bot_le)
le_l_u _ := le_rfl
choice o _ := o.unbot' ⊥
choice_eq _ _ := rfl
|
Order\GameAdd.lean | /-
Copyright (c) 2022 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import Mathlib.Data.Sym.Sym2
import Mathlib.Logic.Relation
/-!
# Game addition relation
This file defines, given relations `rα : α → α → Prop` and `rβ : β → β → Prop`, a relation
`Prod.GameAdd` on pairs, such that `GameAdd rα rβ x y` iff `x` can be reached from `y` by
decreasing either entry (with respect to `rα` and `rβ`). It is so called since it models the
subsequency relation on the addition of combinatorial games.
We also define `Sym2.GameAdd`, which is the unordered pair analog of `Prod.GameAdd`.
## Main definitions and results
- `Prod.GameAdd`: the game addition relation on ordered pairs.
- `WellFounded.prod_gameAdd`: formalizes induction on ordered pairs, where exactly one entry
decreases at a time.
- `Sym2.GameAdd`: the game addition relation on unordered pairs.
- `WellFounded.sym2_gameAdd`: formalizes induction on unordered pairs, where exactly one entry
decreases at a time.
-/
variable {α β : Type*} {rα : α → α → Prop} {rβ : β → β → Prop} {a : α} {b : β}
/-! ### `Prod.GameAdd` -/
namespace Prod
variable (rα rβ)
/-- `Prod.GameAdd rα rβ x y` means that `x` can be reached from `y` by decreasing either entry with
respect to the relations `rα` and `rβ`.
It is so called, as it models game addition within combinatorial game theory. If `rα a₁ a₂` means
that `a₂ ⟶ a₁` is a valid move in game `α`, and `rβ b₁ b₂` means that `b₂ ⟶ b₁` is a valid move
in game `β`, then `GameAdd rα rβ` specifies the valid moves in the juxtaposition of `α` and `β`:
the player is free to choose one of the games and make a move in it, while leaving the other game
unchanged.
See `Sym2.GameAdd` for the unordered pair analog. -/
inductive GameAdd : α × β → α × β → Prop
| fst {a₁ a₂ b} : rα a₁ a₂ → GameAdd (a₁, b) (a₂, b)
| snd {a b₁ b₂} : rβ b₁ b₂ → GameAdd (a, b₁) (a, b₂)
theorem gameAdd_iff {rα rβ} {x y : α × β} :
GameAdd rα rβ x y ↔ rα x.1 y.1 ∧ x.2 = y.2 ∨ rβ x.2 y.2 ∧ x.1 = y.1 := by
constructor
· rintro (@⟨a₁, a₂, b, h⟩ | @⟨a, b₁, b₂, h⟩)
exacts [Or.inl ⟨h, rfl⟩, Or.inr ⟨h, rfl⟩]
· revert x y
rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ (⟨h, rfl : b₁ = b₂⟩ | ⟨h, rfl : a₁ = a₂⟩)
exacts [GameAdd.fst h, GameAdd.snd h]
theorem gameAdd_mk_iff {rα rβ} {a₁ a₂ : α} {b₁ b₂ : β} :
GameAdd rα rβ (a₁, b₁) (a₂, b₂) ↔ rα a₁ a₂ ∧ b₁ = b₂ ∨ rβ b₁ b₂ ∧ a₁ = a₂ :=
gameAdd_iff
@[simp]
theorem gameAdd_swap_swap : ∀ a b : α × β, GameAdd rβ rα a.swap b.swap ↔ GameAdd rα rβ a b :=
fun ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ => by rw [Prod.swap, Prod.swap, gameAdd_mk_iff, gameAdd_mk_iff, or_comm]
theorem gameAdd_swap_swap_mk (a₁ a₂ : α) (b₁ b₂ : β) :
GameAdd rα rβ (a₁, b₁) (a₂, b₂) ↔ GameAdd rβ rα (b₁, a₁) (b₂, a₂) :=
gameAdd_swap_swap rβ rα (b₁, a₁) (b₂, a₂)
/-- `Prod.GameAdd` is a subrelation of `Prod.Lex`. -/
theorem gameAdd_le_lex : GameAdd rα rβ ≤ Prod.Lex rα rβ := fun _ _ h =>
h.rec (Prod.Lex.left _ _) (Prod.Lex.right _)
/-- `Prod.RProd` is a subrelation of the transitive closure of `Prod.GameAdd`. -/
theorem rprod_le_transGen_gameAdd : RProd rα rβ ≤ Relation.TransGen (GameAdd rα rβ)
| _, _, h => h.rec (by
intro _ _ _ _ hα hβ
exact Relation.TransGen.tail (Relation.TransGen.single <| GameAdd.fst hα) (GameAdd.snd hβ))
end Prod
/-- If `a` is accessible under `rα` and `b` is accessible under `rβ`, then `(a, b)` is
accessible under `Prod.GameAdd rα rβ`. Notice that `Prod.lexAccessible` requires the
stronger condition `∀ b, Acc rβ b`. -/
theorem Acc.prod_gameAdd (ha : Acc rα a) (hb : Acc rβ b) :
Acc (Prod.GameAdd rα rβ) (a, b) := by
induction' ha with a _ iha generalizing b
induction' hb with b hb ihb
refine Acc.intro _ fun h => ?_
rintro (⟨ra⟩ | ⟨rb⟩)
exacts [iha _ ra (Acc.intro b hb), ihb _ rb]
/-- The `Prod.GameAdd` relation on well-founded inputs is well-founded.
In particular, the sum of two well-founded games is well-founded. -/
theorem WellFounded.prod_gameAdd (hα : WellFounded rα) (hβ : WellFounded rβ) :
WellFounded (Prod.GameAdd rα rβ) :=
⟨fun ⟨a, b⟩ => (hα.apply a).prod_gameAdd (hβ.apply b)⟩
namespace Prod
/-- Recursion on the well-founded `Prod.GameAdd` relation.
Note that it's strictly more general to recurse on the lexicographic order instead. -/
def GameAdd.fix {C : α → β → Sort*} (hα : WellFounded rα) (hβ : WellFounded rβ)
(IH : ∀ a₁ b₁, (∀ a₂ b₂, GameAdd rα rβ (a₂, b₂) (a₁, b₁) → C a₂ b₂) → C a₁ b₁) (a : α) (b : β) :
C a b :=
@WellFounded.fix (α × β) (fun x => C x.1 x.2) _ (hα.prod_gameAdd hβ)
(fun ⟨x₁, x₂⟩ IH' => IH x₁ x₂ fun a' b' => IH' ⟨a', b'⟩) ⟨a, b⟩
theorem GameAdd.fix_eq {C : α → β → Sort*} (hα : WellFounded rα) (hβ : WellFounded rβ)
(IH : ∀ a₁ b₁, (∀ a₂ b₂, GameAdd rα rβ (a₂, b₂) (a₁, b₁) → C a₂ b₂) → C a₁ b₁) (a : α) (b : β) :
GameAdd.fix hα hβ IH a b = IH a b fun a' b' _ => GameAdd.fix hα hβ IH a' b' :=
WellFounded.fix_eq _ _ _
/-- Induction on the well-founded `Prod.GameAdd` relation.
Note that it's strictly more general to induct on the lexicographic order instead. -/
theorem GameAdd.induction {C : α → β → Prop} :
WellFounded rα →
WellFounded rβ →
(∀ a₁ b₁, (∀ a₂ b₂, GameAdd rα rβ (a₂, b₂) (a₁, b₁) → C a₂ b₂) → C a₁ b₁) → ∀ a b, C a b :=
GameAdd.fix
end Prod
/-! ### `Sym2.GameAdd` -/
namespace Sym2
/-- `Sym2.GameAdd rα x y` means that `x` can be reached from `y` by decreasing either entry with
respect to the relation `rα`.
See `Prod.GameAdd` for the ordered pair analog. -/
def GameAdd (rα : α → α → Prop) : Sym2 α → Sym2 α → Prop :=
Sym2.lift₂
⟨fun a₁ b₁ a₂ b₂ => Prod.GameAdd rα rα (a₁, b₁) (a₂, b₂) ∨ Prod.GameAdd rα rα (b₁, a₁) (a₂, b₂),
fun a₁ b₁ a₂ b₂ => by
dsimp
rw [Prod.gameAdd_swap_swap_mk _ _ b₁ b₂ a₁ a₂, Prod.gameAdd_swap_swap_mk _ _ a₁ b₂ b₁ a₂]
simp [or_comm]⟩
theorem gameAdd_iff : ∀ {x y : α × α},
GameAdd rα (Sym2.mk x) (Sym2.mk y) ↔ Prod.GameAdd rα rα x y ∨ Prod.GameAdd rα rα x.swap y := by
rintro ⟨_, _⟩ ⟨_, _⟩
rfl
theorem gameAdd_mk'_iff {a₁ a₂ b₁ b₂ : α} :
GameAdd rα s(a₁, b₁) s(a₂, b₂) ↔
Prod.GameAdd rα rα (a₁, b₁) (a₂, b₂) ∨ Prod.GameAdd rα rα (b₁, a₁) (a₂, b₂) :=
Iff.rfl
theorem _root_.Prod.GameAdd.to_sym2 {a₁ a₂ b₁ b₂ : α} (h : Prod.GameAdd rα rα (a₁, b₁) (a₂, b₂)) :
Sym2.GameAdd rα s(a₁, b₁) s(a₂, b₂) :=
gameAdd_mk'_iff.2 <| Or.inl <| h
theorem GameAdd.fst {a₁ a₂ b : α} (h : rα a₁ a₂) : GameAdd rα s(a₁, b) s(a₂, b) :=
(Prod.GameAdd.fst h).to_sym2
theorem GameAdd.snd {a b₁ b₂ : α} (h : rα b₁ b₂) : GameAdd rα s(a, b₁) s(a, b₂) :=
(Prod.GameAdd.snd h).to_sym2
theorem GameAdd.fst_snd {a₁ a₂ b : α} (h : rα a₁ a₂) : GameAdd rα s(a₁, b) s(b, a₂) := by
rw [Sym2.eq_swap]
exact GameAdd.snd h
theorem GameAdd.snd_fst {a₁ a₂ b : α} (h : rα a₁ a₂) : GameAdd rα s(b, a₁) s(a₂, b) := by
rw [Sym2.eq_swap]
exact GameAdd.fst h
end Sym2
theorem Acc.sym2_gameAdd {a b} (ha : Acc rα a) (hb : Acc rα b) :
Acc (Sym2.GameAdd rα) s(a, b) := by
induction' ha with a _ iha generalizing b
induction' hb with b hb ihb
refine Acc.intro _ fun s => ?_
induction' s with c d
rw [Sym2.GameAdd]
dsimp
rintro ((rc | rd) | (rd | rc))
· exact iha c rc ⟨b, hb⟩
· exact ihb d rd
· rw [Sym2.eq_swap]
exact iha d rd ⟨b, hb⟩
· rw [Sym2.eq_swap]
exact ihb c rc
/-- The `Sym2.GameAdd` relation on well-founded inputs is well-founded. -/
theorem WellFounded.sym2_gameAdd (h : WellFounded rα) : WellFounded (Sym2.GameAdd rα) :=
⟨fun i => Sym2.inductionOn i fun x y => (h.apply x).sym2_gameAdd (h.apply y)⟩
namespace Sym2
attribute [local instance] Sym2.Rel.setoid
/-- Recursion on the well-founded `Sym2.GameAdd` relation. -/
def GameAdd.fix {C : α → α → Sort*} (hr : WellFounded rα)
(IH : ∀ a₁ b₁, (∀ a₂ b₂, Sym2.GameAdd rα s(a₂, b₂) s(a₁, b₁) → C a₂ b₂) → C a₁ b₁) (a b : α) :
C a b := by
-- Porting note: this was refactored for #3414 (reenableeta), and could perhaps be cleaned up.
have := hr.sym2_gameAdd
dsimp only [GameAdd, lift₂, DFunLike.coe, EquivLike.coe] at this
exact @WellFounded.fix (α × α) (fun x => C x.1 x.2) _ this.of_quotient_lift₂
(fun ⟨x₁, x₂⟩ IH' => IH x₁ x₂ fun a' b' => IH' ⟨a', b'⟩) (a, b)
theorem GameAdd.fix_eq {C : α → α → Sort*} (hr : WellFounded rα)
(IH : ∀ a₁ b₁, (∀ a₂ b₂, Sym2.GameAdd rα s(a₂, b₂) s(a₁, b₁) → C a₂ b₂) → C a₁ b₁) (a b : α) :
GameAdd.fix hr IH a b = IH a b fun a' b' _ => GameAdd.fix hr IH a' b' := by
-- Porting note: this was refactored for #3414 (reenableeta), and could perhaps be cleaned up.
dsimp [GameAdd.fix]
exact WellFounded.fix_eq _ _ _
/-- Induction on the well-founded `Sym2.GameAdd` relation. -/
theorem GameAdd.induction {C : α → α → Prop} :
WellFounded rα →
(∀ a₁ b₁, (∀ a₂ b₂, Sym2.GameAdd rα s(a₂, b₂) s(a₁, b₁) → C a₂ b₂) → C a₁ b₁) →
∀ a b, C a b :=
GameAdd.fix
end Sym2
|
Order\Grade.lean | /-
Copyright (c) 2022 Yaël Dillies, Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Violeta Hernández Palacios, Grayson Burton, Vladimir Ivanov
-/
import Mathlib.Data.Int.SuccPred
import Mathlib.Order.Fin.Basic
/-!
# Graded orders
This file defines graded orders, also known as ranked orders.
An `𝕆`-graded order is an order `α` equipped with a distinguished "grade" function `α → 𝕆` which
should be understood as giving the "height" of the elements. Usual graded orders are `ℕ`-graded,
cograded orders are `ℕᵒᵈ`-graded, but we can also grade by `ℤ`, and polytopes are naturally
`Fin n`-graded.
Visually, `grade ℕ a` is the height of `a` in the Hasse diagram of `α`.
## Main declarations
* `GradeOrder`: Graded order.
* `GradeMinOrder`: Graded order where minimal elements have minimal grades.
* `GradeMaxOrder`: Graded order where maximal elements have maximal grades.
* `GradeBoundedOrder`: Graded order where minimal elements have minimal grades and maximal
elements have maximal grades.
* `grade`: The grade of an element. Because an order can admit several gradings, the first argument
is the order we grade by.
## How to grade your order
Here are the translations between common references and our `GradeOrder`:
* [Stanley][stanley2012] defines a graded order of rank `n` as an order where all maximal chains
have "length" `n` (so the number of elements of a chain is `n + 1`). This corresponds to
`GradeBoundedOrder (Fin (n + 1)) α`.
* [Engel][engel1997]'s ranked orders are somewhere between `GradeOrder ℕ α` and
`GradeMinOrder ℕ α`, in that he requires `∃ a, IsMin a ∧ grade ℕ a = 0` rather than
`∀ a, IsMin a → grade ℕ a = 0`. He defines a graded order as an order where all minimal elements
have grade `0` and all maximal elements have the same grade. This is roughly a less bundled
version of `GradeBoundedOrder (Fin n) α`, assuming we discard orders with infinite chains.
## Implementation notes
One possible definition of graded orders is as the bounded orders whose flags (maximal chains)
all have the same finite length (see Stanley p. 99). However, this means that all graded orders must
have minimal and maximal elements and that the grade is not data.
Instead, we define graded orders by their grade function, without talking about flags yet.
## References
* [Konrad Engel, *Sperner Theory*][engel1997]
* [Richard Stanley, *Enumerative Combinatorics*][stanley2012]
-/
open Nat OrderDual
variable {𝕆 ℙ α β : Type*}
/-- An `𝕆`-graded order is an order `α` equipped with a strictly monotone function
`grade 𝕆 : α → 𝕆` which preserves order covering (`CovBy`). -/
class GradeOrder (𝕆 α : Type*) [Preorder 𝕆] [Preorder α] where
/-- The grading function. -/
protected grade : α → 𝕆
/-- `grade` is strictly monotonic. -/
grade_strictMono : StrictMono grade
/-- `grade` preserves `CovBy`. -/
covBy_grade ⦃a b : α⦄ : a ⋖ b → grade a ⋖ grade b
/-- An `𝕆`-graded order where minimal elements have minimal grades. -/
class GradeMinOrder (𝕆 α : Type*) [Preorder 𝕆] [Preorder α] extends GradeOrder 𝕆 α where
/-- Minimal elements have minimal grades. -/
isMin_grade ⦃a : α⦄ : IsMin a → IsMin (grade a)
/-- An `𝕆`-graded order where maximal elements have maximal grades. -/
class GradeMaxOrder (𝕆 α : Type*) [Preorder 𝕆] [Preorder α] extends GradeOrder 𝕆 α where
/-- Maximal elements have maximal grades. -/
isMax_grade ⦃a : α⦄ : IsMax a → IsMax (grade a)
/-- An `𝕆`-graded order where minimal elements have minimal grades and maximal elements have maximal
grades. -/
class GradeBoundedOrder (𝕆 α : Type*) [Preorder 𝕆] [Preorder α] extends GradeMinOrder 𝕆 α,
GradeMaxOrder 𝕆 α
section Preorder -- grading
variable [Preorder 𝕆]
section Preorder -- graded order
variable [Preorder α]
section GradeOrder
variable (𝕆)
variable [GradeOrder 𝕆 α] {a b : α}
/-- The grade of an element in a graded order. Morally, this is the number of elements you need to
go down by to get to `⊥`. -/
def grade : α → 𝕆 :=
GradeOrder.grade
protected theorem CovBy.grade (h : a ⋖ b) : grade 𝕆 a ⋖ grade 𝕆 b :=
GradeOrder.covBy_grade h
variable {𝕆}
theorem grade_strictMono : StrictMono (grade 𝕆 : α → 𝕆) :=
GradeOrder.grade_strictMono
theorem covBy_iff_lt_covBy_grade : a ⋖ b ↔ a < b ∧ grade 𝕆 a ⋖ grade 𝕆 b :=
⟨fun h => ⟨h.1, h.grade _⟩,
And.imp_right fun h _ ha hb => h.2 (grade_strictMono ha) <| grade_strictMono hb⟩
end GradeOrder
section GradeMinOrder
variable (𝕆)
variable [GradeMinOrder 𝕆 α] {a : α}
protected theorem IsMin.grade (h : IsMin a) : IsMin (grade 𝕆 a) :=
GradeMinOrder.isMin_grade h
variable {𝕆}
@[simp]
theorem isMin_grade_iff : IsMin (grade 𝕆 a) ↔ IsMin a :=
⟨grade_strictMono.isMin_of_apply, IsMin.grade _⟩
end GradeMinOrder
section GradeMaxOrder
variable (𝕆)
variable [GradeMaxOrder 𝕆 α] {a : α}
protected theorem IsMax.grade (h : IsMax a) : IsMax (grade 𝕆 a) :=
GradeMaxOrder.isMax_grade h
variable {𝕆}
@[simp]
theorem isMax_grade_iff : IsMax (grade 𝕆 a) ↔ IsMax a :=
⟨grade_strictMono.isMax_of_apply, IsMax.grade _⟩
end GradeMaxOrder
end Preorder
-- graded order
theorem grade_mono [PartialOrder α] [GradeOrder 𝕆 α] : Monotone (grade 𝕆 : α → 𝕆) :=
grade_strictMono.monotone
section LinearOrder
-- graded order
variable [LinearOrder α] [GradeOrder 𝕆 α] {a b : α}
theorem grade_injective : Function.Injective (grade 𝕆 : α → 𝕆) :=
grade_strictMono.injective
@[simp]
theorem grade_le_grade_iff : grade 𝕆 a ≤ grade 𝕆 b ↔ a ≤ b :=
grade_strictMono.le_iff_le
@[simp]
theorem grade_lt_grade_iff : grade 𝕆 a < grade 𝕆 b ↔ a < b :=
grade_strictMono.lt_iff_lt
@[simp]
theorem grade_eq_grade_iff : grade 𝕆 a = grade 𝕆 b ↔ a = b :=
grade_injective.eq_iff
theorem grade_ne_grade_iff : grade 𝕆 a ≠ grade 𝕆 b ↔ a ≠ b :=
grade_injective.ne_iff
theorem grade_covBy_grade_iff : grade 𝕆 a ⋖ grade 𝕆 b ↔ a ⋖ b :=
(covBy_iff_lt_covBy_grade.trans <| and_iff_right_of_imp fun h => grade_lt_grade_iff.1 h.1).symm
end LinearOrder
-- graded order
end Preorder
-- grading
section PartialOrder
variable [PartialOrder 𝕆] [Preorder α]
@[simp]
theorem grade_bot [OrderBot 𝕆] [OrderBot α] [GradeMinOrder 𝕆 α] : grade 𝕆 (⊥ : α) = ⊥ :=
(isMin_bot.grade _).eq_bot
@[simp]
theorem grade_top [OrderTop 𝕆] [OrderTop α] [GradeMaxOrder 𝕆 α] : grade 𝕆 (⊤ : α) = ⊤ :=
(isMax_top.grade _).eq_top
end PartialOrder
/-! ### Instances -/
variable [Preorder 𝕆] [Preorder ℙ] [Preorder α] [Preorder β]
instance Preorder.toGradeBoundedOrder : GradeBoundedOrder α α where
grade := id
isMin_grade _ := id
isMax_grade _ := id
grade_strictMono := strictMono_id
covBy_grade _ _ := id
@[simp]
theorem grade_self (a : α) : grade α a = a :=
rfl
/-! #### Dual -/
instance OrderDual.gradeOrder [GradeOrder 𝕆 α] : GradeOrder 𝕆ᵒᵈ αᵒᵈ where
grade := toDual ∘ grade 𝕆 ∘ ofDual
grade_strictMono := grade_strictMono.dual
covBy_grade _ _ h := (h.ofDual.grade _).toDual
instance OrderDual.gradeMinOrder [GradeMaxOrder 𝕆 α] : GradeMinOrder 𝕆ᵒᵈ αᵒᵈ :=
{ OrderDual.gradeOrder with isMin_grade := fun _ => IsMax.grade (α := α) 𝕆 }
instance OrderDual.gradeMaxOrder [GradeMinOrder 𝕆 α] : GradeMaxOrder 𝕆ᵒᵈ αᵒᵈ :=
{ OrderDual.gradeOrder with isMax_grade := fun _ => IsMin.grade (α := α) 𝕆 }
instance [GradeBoundedOrder 𝕆 α] : GradeBoundedOrder 𝕆ᵒᵈ αᵒᵈ :=
{ OrderDual.gradeMinOrder, OrderDual.gradeMaxOrder with }
@[simp]
theorem grade_toDual [GradeOrder 𝕆 α] (a : α) : grade 𝕆ᵒᵈ (toDual a) = toDual (grade 𝕆 a) :=
rfl
@[simp]
theorem grade_ofDual [GradeOrder 𝕆 α] (a : αᵒᵈ) : grade 𝕆 (ofDual a) = ofDual (grade 𝕆ᵒᵈ a) :=
rfl
/-! #### Lifting a graded order -/
-- See note [reducible non-instances]
/-- Lifts a graded order along a strictly monotone function. -/
abbrev GradeOrder.liftLeft [GradeOrder 𝕆 α] (f : 𝕆 → ℙ) (hf : StrictMono f)
(hcovBy : ∀ a b, a ⋖ b → f a ⋖ f b) : GradeOrder ℙ α where
grade := f ∘ grade 𝕆
grade_strictMono := hf.comp grade_strictMono
covBy_grade _ _ h := hcovBy _ _ <| h.grade _
-- See note [reducible non-instances]
/-- Lifts a graded order along a strictly monotone function. -/
abbrev GradeMinOrder.liftLeft [GradeMinOrder 𝕆 α] (f : 𝕆 → ℙ) (hf : StrictMono f)
(hcovBy : ∀ a b, a ⋖ b → f a ⋖ f b) (hmin : ∀ a, IsMin a → IsMin (f a)) : GradeMinOrder ℙ α :=
{ GradeOrder.liftLeft f hf hcovBy with isMin_grade := fun _ ha => hmin _ <| ha.grade _ }
-- See note [reducible non-instances]
/-- Lifts a graded order along a strictly monotone function. -/
abbrev GradeMaxOrder.liftLeft [GradeMaxOrder 𝕆 α] (f : 𝕆 → ℙ) (hf : StrictMono f)
(hcovBy : ∀ a b, a ⋖ b → f a ⋖ f b) (hmax : ∀ a, IsMax a → IsMax (f a)) : GradeMaxOrder ℙ α :=
{ GradeOrder.liftLeft f hf hcovBy with isMax_grade := fun _ ha => hmax _ <| ha.grade _ }
-- See note [reducible non-instances]
/-- Lifts a graded order along a strictly monotone function. -/
abbrev GradeBoundedOrder.liftLeft [GradeBoundedOrder 𝕆 α] (f : 𝕆 → ℙ) (hf : StrictMono f)
(hcovBy : ∀ a b, a ⋖ b → f a ⋖ f b) (hmin : ∀ a, IsMin a → IsMin (f a))
(hmax : ∀ a, IsMax a → IsMax (f a)) : GradeBoundedOrder ℙ α :=
{ GradeMinOrder.liftLeft f hf hcovBy hmin, GradeMaxOrder.liftLeft f hf hcovBy hmax with }
-- See note [reducible non-instances]
/-- Lifts a graded order along a strictly monotone function. -/
abbrev GradeOrder.liftRight [GradeOrder 𝕆 β] (f : α → β) (hf : StrictMono f)
(hcovBy : ∀ a b, a ⋖ b → f a ⋖ f b) : GradeOrder 𝕆 α where
grade := grade 𝕆 ∘ f
grade_strictMono := grade_strictMono.comp hf
covBy_grade _ _ h := (hcovBy _ _ h).grade _
-- See note [reducible non-instances]
/-- Lifts a graded order along a strictly monotone function. -/
abbrev GradeMinOrder.liftRight [GradeMinOrder 𝕆 β] (f : α → β) (hf : StrictMono f)
(hcovBy : ∀ a b, a ⋖ b → f a ⋖ f b) (hmin : ∀ a, IsMin a → IsMin (f a)) : GradeMinOrder 𝕆 α :=
{ GradeOrder.liftRight f hf hcovBy with isMin_grade := fun _ ha => (hmin _ ha).grade _ }
-- See note [reducible non-instances]
/-- Lifts a graded order along a strictly monotone function. -/
abbrev GradeMaxOrder.liftRight [GradeMaxOrder 𝕆 β] (f : α → β) (hf : StrictMono f)
(hcovBy : ∀ a b, a ⋖ b → f a ⋖ f b) (hmax : ∀ a, IsMax a → IsMax (f a)) : GradeMaxOrder 𝕆 α :=
{ GradeOrder.liftRight f hf hcovBy with isMax_grade := fun _ ha => (hmax _ ha).grade _ }
-- See note [reducible non-instances]
/-- Lifts a graded order along a strictly monotone function. -/
abbrev GradeBoundedOrder.liftRight [GradeBoundedOrder 𝕆 β] (f : α → β) (hf : StrictMono f)
(hcovBy : ∀ a b, a ⋖ b → f a ⋖ f b) (hmin : ∀ a, IsMin a → IsMin (f a))
(hmax : ∀ a, IsMax a → IsMax (f a)) : GradeBoundedOrder 𝕆 α :=
{ GradeMinOrder.liftRight f hf hcovBy hmin, GradeMaxOrder.liftRight f hf hcovBy hmax with }
/-! #### `Fin n`-graded to `ℕ`-graded to `ℤ`-graded -/
-- See note [reducible non-instances]
/-- A `Fin n`-graded order is also `ℕ`-graded. We do not mark this an instance because `n` is not
inferrable. -/
abbrev GradeOrder.finToNat (n : ℕ) [GradeOrder (Fin n) α] : GradeOrder ℕ α :=
(GradeOrder.liftLeft (_ : Fin n → ℕ) Fin.val_strictMono) fun _ _ => CovBy.coe_fin
-- See note [reducible non-instances]
/-- A `Fin n`-graded order is also `ℕ`-graded. We do not mark this an instance because `n` is not
inferrable. -/
abbrev GradeMinOrder.finToNat (n : ℕ) [GradeMinOrder (Fin n) α] : GradeMinOrder ℕ α :=
(GradeMinOrder.liftLeft (_ : Fin n → ℕ) Fin.val_strictMono fun _ _ => CovBy.coe_fin) fun a h => by
cases n
· exact a.elim0
rw [h.eq_bot, Fin.bot_eq_zero]
exact isMin_bot
instance GradeOrder.natToInt [GradeOrder ℕ α] : GradeOrder ℤ α :=
(GradeOrder.liftLeft _ Int.natCast_strictMono) fun _ _ => CovBy.intCast
theorem GradeOrder.wellFoundedLT (𝕆 : Type*) [Preorder 𝕆] [GradeOrder 𝕆 α]
[WellFoundedLT 𝕆] : WellFoundedLT α :=
(grade_strictMono (𝕆 := 𝕆)).wellFoundedLT
theorem GradeOrder.wellFoundedGT (𝕆 : Type*) [Preorder 𝕆] [GradeOrder 𝕆 α]
[WellFoundedGT 𝕆] : WellFoundedGT α :=
(grade_strictMono (𝕆 := 𝕆)).wellFoundedGT
instance [GradeOrder ℕ α] : WellFoundedLT α :=
GradeOrder.wellFoundedLT ℕ
instance [GradeOrder ℕᵒᵈ α] : WellFoundedGT α :=
GradeOrder.wellFoundedGT ℕᵒᵈ
|
Order\Height.lean | /-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Data.ENat.Lattice
import Mathlib.Order.OrderIsoNat
import Mathlib.Tactic.TFAE
/-!
# Maximal length of chains
This file contains lemmas to work with the maximal length of strictly descending finite
sequences (chains) in a partial order.
## Main definition
- `Set.subchain`: The set of strictly ascending lists of `α` contained in a `Set α`.
- `Set.chainHeight`: The maximal length of a strictly ascending sequence in a partial order.
This is defined as the maximum of the lengths of `Set.subchain`s, valued in `ℕ∞`.
## Main results
- `Set.exists_chain_of_le_chainHeight`: For each `n : ℕ` such that `n ≤ s.chainHeight`, there
exists `s.subchain` of length `n`.
- `Set.chainHeight_mono`: If `s ⊆ t` then `s.chainHeight ≤ t.chainHeight`.
- `Set.chainHeight_image`: If `f` is an order embedding, then
`(f '' s).chainHeight = s.chainHeight`.
- `Set.chainHeight_insert_of_forall_lt`: If `∀ y ∈ s, y < x`, then
`(insert x s).chainHeight = s.chainHeight + 1`.
- `Set.chainHeight_insert_of_forall_gt`: If `∀ y ∈ s, x < y`, then
`(insert x s).chainHeight = s.chainHeight + 1`.
- `Set.chainHeight_union_eq`: If `∀ x ∈ s, ∀ y ∈ t, s ≤ t`, then
`(s ∪ t).chainHeight = s.chainHeight + t.chainHeight`.
- `Set.wellFoundedGT_of_chainHeight_ne_top`:
If `s` has finite height, then `>` is well-founded on `s`.
- `Set.wellFoundedLT_of_chainHeight_ne_top`:
If `s` has finite height, then `<` is well-founded on `s`.
-/
open List hiding le_antisymm
open OrderDual
universe u v
variable {α β : Type*}
namespace Set
section LT
variable [LT α] [LT β] (s t : Set α)
/-- The set of strictly ascending lists of `α` contained in a `Set α`. -/
def subchain : Set (List α) :=
{ l | l.Chain' (· < ·) ∧ ∀ i ∈ l, i ∈ s }
@[simp] -- porting note: new `simp`
theorem nil_mem_subchain : [] ∈ s.subchain := ⟨trivial, fun _ ↦ nofun⟩
variable {s} {l : List α} {a : α}
theorem cons_mem_subchain_iff :
(a::l) ∈ s.subchain ↔ a ∈ s ∧ l ∈ s.subchain ∧ ∀ b ∈ l.head?, a < b := by
simp only [subchain, mem_setOf_eq, forall_mem_cons, chain'_cons', and_left_comm, and_comm,
and_assoc]
@[simp]
theorem singleton_mem_subchain_iff : [a] ∈ s.subchain ↔ a ∈ s := by simp [cons_mem_subchain_iff]
instance : Nonempty s.subchain :=
⟨⟨[], s.nil_mem_subchain⟩⟩
variable (s)
/-- The maximal length of a strictly ascending sequence in a partial order. -/
noncomputable def chainHeight : ℕ∞ :=
⨆ l ∈ s.subchain, length l
theorem chainHeight_eq_iSup_subtype : s.chainHeight = ⨆ l : s.subchain, ↑l.1.length :=
iSup_subtype'
theorem exists_chain_of_le_chainHeight {n : ℕ} (hn : ↑n ≤ s.chainHeight) :
∃ l ∈ s.subchain, length l = n := by
rcases (le_top : s.chainHeight ≤ ⊤).eq_or_lt with ha | ha <;>
rw [chainHeight_eq_iSup_subtype] at ha
· obtain ⟨_, ⟨⟨l, h₁, h₂⟩, rfl⟩, h₃⟩ :=
not_bddAbove_iff'.mp (WithTop.iSup_coe_eq_top.1 ha) n
exact ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩,
(l.length_take n).trans <| min_eq_left <| le_of_not_ge h₃⟩
· rw [ENat.iSup_coe_lt_top] at ha
obtain ⟨⟨l, h₁, h₂⟩, e : l.length = _⟩ := Nat.sSup_mem (Set.range_nonempty _) ha
refine
⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩,
(l.length_take n).trans <| min_eq_left <| ?_⟩
rwa [e, ← Nat.cast_le (α := ℕ∞), sSup_range, ENat.coe_iSup ha, ← chainHeight_eq_iSup_subtype]
theorem le_chainHeight_TFAE (n : ℕ) :
TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by
tfae_have 1 → 2; · exact s.exists_chain_of_le_chainHeight
tfae_have 2 → 3; · rintro ⟨l, hls, he⟩; exact ⟨l, hls, he.ge⟩
tfae_have 3 → 1; · rintro ⟨l, hs, hn⟩; exact le_iSup₂_of_le l hs (WithTop.coe_le_coe.2 hn)
tfae_finish
variable {s t}
theorem le_chainHeight_iff {n : ℕ} : ↑n ≤ s.chainHeight ↔ ∃ l ∈ s.subchain, length l = n :=
(le_chainHeight_TFAE s n).out 0 1
theorem length_le_chainHeight_of_mem_subchain (hl : l ∈ s.subchain) : ↑l.length ≤ s.chainHeight :=
le_chainHeight_iff.mpr ⟨l, hl, rfl⟩
theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by
refine ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ ?_⟩
contrapose! h; obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 h
exact ⟨n + 1, fun l hs ↦ (Nat.lt_succ_iff.2 <| Nat.cast_le.1 <|
(length_le_chainHeight_of_mem_subchain hs).trans_eq hn.symm).ne⟩
@[simp]
theorem one_le_chainHeight_iff : 1 ≤ s.chainHeight ↔ s.Nonempty := by
rw [← Nat.cast_one, Set.le_chainHeight_iff]
simp only [length_eq_one, @and_comm (_ ∈ _), @eq_comm _ _ [_], exists_exists_eq_and,
singleton_mem_subchain_iff, Set.Nonempty]
@[simp]
theorem chainHeight_eq_zero_iff : s.chainHeight = 0 ↔ s = ∅ := by
rw [← not_iff_not, ← Ne, ← ENat.one_le_iff_ne_zero, one_le_chainHeight_iff,
nonempty_iff_ne_empty]
@[simp]
theorem chainHeight_empty : (∅ : Set α).chainHeight = 0 :=
chainHeight_eq_zero_iff.2 rfl
@[simp]
theorem chainHeight_of_isEmpty [IsEmpty α] : s.chainHeight = 0 :=
chainHeight_eq_zero_iff.mpr (Subsingleton.elim _ _)
theorem le_chainHeight_add_nat_iff {n m : ℕ} :
↑n ≤ s.chainHeight + m ↔ ∃ l ∈ s.subchain, n ≤ length l + m := by
simp_rw [← tsub_le_iff_right, ← ENat.coe_sub, (le_chainHeight_TFAE s (n - m)).out 0 2]
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
s.chainHeight + n ≤ t.chainHeight + m ↔
∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
refine
⟨fun e l h ↦
le_chainHeight_add_nat_iff.1
((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
fun H ↦ ?_⟩
by_cases h : s.chainHeight = ⊤
· suffices t.chainHeight = ⊤ by
rw [this, top_add]
exact le_top
rw [chainHeight_eq_top_iff] at h ⊢
intro k
have := (le_chainHeight_TFAE t k).out 1 2
rw [this]
obtain ⟨l, hs, hl⟩ := h (k + m)
obtain ⟨l', ht, hl'⟩ := H l hs
exact ⟨l', ht, (add_le_add_iff_right m).1 <| _root_.trans (hl.symm.trans_le le_self_add) hl'⟩
· obtain ⟨k, hk⟩ := WithTop.ne_top_iff_exists.1 h
obtain ⟨l, hs, hl⟩ := le_chainHeight_iff.1 hk.le
rw [← hk, ← hl]
exact le_chainHeight_add_nat_iff.2 (H l hs)
theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) :
TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l',
∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by
tfae_have 1 ↔ 3
· convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> apply add_zero
tfae_have 2 ↔ 3
· refine forall₂_congr fun l hl ↦ ?_
simp_rw [← (le_chainHeight_TFAE t l.length).out 1 2, eq_comm]
tfae_finish
theorem chainHeight_le_chainHeight_iff {t : Set β} :
s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l' :=
(chainHeight_le_chainHeight_TFAE s t).out 0 1
theorem chainHeight_le_chainHeight_iff_le {t : Set β} :
s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l' :=
(chainHeight_le_chainHeight_TFAE s t).out 0 2
theorem chainHeight_mono (h : s ⊆ t) : s.chainHeight ≤ t.chainHeight :=
chainHeight_le_chainHeight_iff.2 fun l hl ↦ ⟨l, ⟨hl.1, fun i hi ↦ h <| hl.2 i hi⟩, rfl⟩
theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) :
(f '' s).chainHeight = s.chainHeight := by
apply le_antisymm <;> rw [chainHeight_le_chainHeight_iff]
· suffices ∀ l ∈ (f '' s).subchain, ∃ l' ∈ s.subchain, map f l' = l by
intro l hl
obtain ⟨l', h₁, rfl⟩ := this l hl
exact ⟨l', h₁, length_map _ _⟩
intro l
induction' l with x xs hx
· exact fun _ ↦ ⟨nil, ⟨trivial, fun x h ↦ (not_mem_nil x h).elim⟩, rfl⟩
· intro h
rw [cons_mem_subchain_iff] at h
obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h
obtain ⟨l', h₃, rfl⟩ := hx h₁
refine ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, ?_⟩, rfl⟩
cases l'
· simp
· simpa [← hf] using h₂
· intro l hl
refine ⟨l.map f, ⟨?_, ?_⟩, ?_⟩
· simp_rw [chain'_map, ← hf]
exact hl.1
· intro _ e
obtain ⟨a, ha, rfl⟩ := mem_map.mp e
exact Set.mem_image_of_mem _ (hl.2 _ ha)
· rw [length_map]
variable (s)
@[simp]
theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by
apply le_antisymm <;>
· rw [chainHeight_le_chainHeight_iff]
rintro l ⟨h₁, h₂⟩
exact ⟨l.reverse, ⟨chain'_reverse.mpr h₁, fun i h ↦ h₂ i (mem_reverse.mp h)⟩,
(length_reverse _).symm⟩
end LT
section Preorder
variable (s t : Set α) [Preorder α]
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
apply le_antisymm
· refine iSup₂_le ?_
rintro (_ | ⟨x, xs⟩) h
· exact zero_le _
· apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1)
apply length_le_chainHeight_of_mem_subchain
refine ⟨h.1, fun i hi ↦ ⟨h.2 i hi, ?_⟩⟩
cases hi
· exact left_mem_Ici
rename_i hi
cases' chain'_iff_pairwise.mp h.1 with _ _ h'
exact (h' _ hi).le
· exact iSup₂_le fun i _ ↦ chainHeight_mono Set.inter_subset_left
theorem chainHeight_eq_iSup_Iic : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Iic i).chainHeight := by
simp_rw [← chainHeight_dual (_ ∩ _)]
rw [← chainHeight_dual, chainHeight_eq_iSup_Ici]
rfl
variable {s t}
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
(insert a s).chainHeight = s.chainHeight + 1 := by
rw [← add_zero (insert a s).chainHeight]
change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add]
· rintro (_ | ⟨y, ys⟩) h
· exact ⟨[], nil_mem_subchain _, zero_le _⟩
· have h' := cons_mem_subchain_iff.mp h
refine ⟨ys, ⟨h'.2.1.1, fun i hi ↦ ?_⟩, by simp⟩
apply (h'.2.1.2 i hi).resolve_left
rintro rfl
cases' chain'_iff_pairwise.mp h.1 with _ _ hy
cases' h'.1 with h' h'
exacts [(hy _ hi).ne h', not_le_of_gt (hy _ hi) (hx _ h').le]
· intro l hl
refine ⟨a::l, ⟨?_, ?_⟩, by simp⟩
· rw [chain'_cons']
exact ⟨fun y hy ↦ hx _ (hl.2 _ (mem_of_mem_head? hy)), hl.1⟩
· -- Porting note: originally this was
-- rintro x (rfl | hx)
-- exacts [Or.inl (Set.mem_singleton x), Or.inr (hl.2 x hx)]
-- but this fails because `List.Mem` is now an inductive prop.
-- I couldn't work out how to drive `rcases` here but asked at
-- https://leanprover.zulipchat.com/#narrow/stream/348111-std4/topic/rcases.3F/near/347976083
rintro x (_ | _)
exacts [Or.inl (Set.mem_singleton a), Or.inr (hl.2 x ‹_›)]
theorem chainHeight_insert_of_forall_lt (a : α) (ha : ∀ b ∈ s, b < a) :
(insert a s).chainHeight = s.chainHeight + 1 := by
rw [← chainHeight_dual, ← chainHeight_dual s]
exact chainHeight_insert_of_forall_gt _ ha
theorem chainHeight_union_le : (s ∪ t).chainHeight ≤ s.chainHeight + t.chainHeight := by
classical
refine iSup₂_le fun l hl ↦ ?_
let l₁ := l.filter (· ∈ s)
let l₂ := l.filter (· ∈ t)
have hl₁ : ↑l₁.length ≤ s.chainHeight := by
apply Set.length_le_chainHeight_of_mem_subchain
exact ⟨hl.1.sublist (filter_sublist _), fun i h ↦ by simpa using (of_mem_filter h : _)⟩
have hl₂ : ↑l₂.length ≤ t.chainHeight := by
apply Set.length_le_chainHeight_of_mem_subchain
exact ⟨hl.1.sublist (filter_sublist _), fun i h ↦ by simpa using (of_mem_filter h : _)⟩
refine le_trans ?_ (add_le_add hl₁ hl₂)
simp_rw [l₁, l₂, ← Nat.cast_add, ← Multiset.coe_card, ← Multiset.card_add,
← Multiset.filter_coe]
rw [Multiset.filter_add_filter, Multiset.filter_eq_self.mpr, Multiset.card_add, Nat.cast_add]
exacts [le_add_right rfl.le, hl.2]
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
(s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
cases h : t.chainHeight
· rw [add_top, eq_top_iff, ← h]
exact Set.chainHeight_mono subset_union_right
apply le_antisymm
· rw [← h]
exact chainHeight_union_le
rw [← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero,
ENat.some_eq_coe, chainHeight_add_le_chainHeight_add]
intro l hl
obtain ⟨l', hl', rfl⟩ := exists_chain_of_le_chainHeight t h.symm.le
refine ⟨l ++ l', ⟨Chain'.append hl.1 hl'.1 fun x hx y hy ↦ ?_, fun i hi ↦ ?_⟩, by simp⟩
· exact H x (hl.2 _ <| mem_of_mem_getLast? hx) y (hl'.2 _ <| mem_of_mem_head? hy)
· rw [mem_append] at hi
cases' hi with hi hi
exacts [Or.inl (hl.2 _ hi), Or.inr (hl'.2 _ hi)]
theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
WellFoundedGT s := by
-- Porting note: added
haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance
obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs
refine ⟨RelEmbedding.wellFounded_iff_no_descending_seq.2 ⟨fun f ↦ ?_⟩⟩
refine n.lt_succ_self.not_le (WithTop.coe_le_coe.1 <| hn.symm ▸ ?_)
refine le_iSup₂_of_le ((ofFn (n := n.succ) fun i ↦ f i).map Subtype.val)
⟨chain'_map_of_chain' ((↑) : {x // x ∈ s} → α) (fun _ _ ↦ id)
(chain'_iff_pairwise.2 <| pairwise_ofFn.2 fun i j ↦ f.map_rel_iff.2), fun i h ↦ ?_⟩ ?_
· obtain ⟨a, -, rfl⟩ := mem_map.1 h
exact a.prop
· rw [length_map, length_ofFn]
exact le_rfl
theorem wellFoundedLT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
WellFoundedLT s :=
wellFoundedGT_of_chainHeight_ne_top (ofDual ⁻¹' s) <| by rwa [chainHeight_dual]
end Preorder
end Set
|
Order\Ideal.lean | /-
Copyright (c) 2020 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn
-/
import Mathlib.Logic.Encodable.Basic
import Mathlib.Order.Atoms
import Mathlib.Order.Chain
import Mathlib.Order.UpperLower.Basic
import Mathlib.Data.Set.Subsingleton
/-!
# Order ideals, cofinal sets, and the Rasiowa–Sikorski lemma
## Main definitions
Throughout this file, `P` is at least a preorder, but some sections require more
structure, such as a bottom element, a top element, or a join-semilattice structure.
- `Order.Ideal P`: the type of nonempty, upward directed, and downward closed subsets of `P`.
Dual to the notion of a filter on a preorder.
- `Order.IsIdeal I`: a predicate for when a `Set P` is an ideal.
- `Order.Ideal.principal p`: the principal ideal generated by `p : P`.
- `Order.Ideal.IsProper I`: a predicate for proper ideals.
Dual to the notion of a proper filter.
- `Order.Ideal.IsMaximal I`: a predicate for maximal ideals.
Dual to the notion of an ultrafilter.
- `Order.Cofinal P`: the type of subsets of `P` containing arbitrarily large elements.
Dual to the notion of 'dense set' used in forcing.
- `Order.idealOfCofinals p 𝒟`, where `p : P`, and `𝒟` is a countable family of cofinal
subsets of `P`: an ideal in `P` which contains `p` and intersects every set in `𝒟`. (This a form
of the Rasiowa–Sikorski lemma.)
## References
- <https://en.wikipedia.org/wiki/Ideal_(order_theory)>
- <https://en.wikipedia.org/wiki/Cofinal_(mathematics)>
- <https://en.wikipedia.org/wiki/Rasiowa%E2%80%93Sikorski_lemma>
Note that for the Rasiowa–Sikorski lemma, Wikipedia uses the opposite ordering on `P`,
in line with most presentations of forcing.
## Tags
ideal, cofinal, dense, countable, generic
-/
open Function Set
namespace Order
variable {P : Type*}
/-- An ideal on an order `P` is a subset of `P` that is
- nonempty
- upward directed (any pair of elements in the ideal has an upper bound in the ideal)
- downward closed (any element less than an element of the ideal is in the ideal). -/
structure Ideal (P) [LE P] extends LowerSet P where
/-- The ideal is nonempty. -/
nonempty' : carrier.Nonempty
/-- The ideal is upward directed. -/
directed' : DirectedOn (· ≤ ·) carrier
-- Porting note (#11215): TODO: remove this configuration and use the default configuration.
-- We keep this to be consistent with Lean 3.
initialize_simps_projections Ideal (+toLowerSet, -carrier)
/-- A subset of a preorder `P` is an ideal if it is
- nonempty
- upward directed (any pair of elements in the ideal has an upper bound in the ideal)
- downward closed (any element less than an element of the ideal is in the ideal). -/
@[mk_iff]
structure IsIdeal {P} [LE P] (I : Set P) : Prop where
/-- The ideal is downward closed. -/
IsLowerSet : IsLowerSet I
/-- The ideal is nonempty. -/
Nonempty : I.Nonempty
/-- The ideal is upward directed. -/
Directed : DirectedOn (· ≤ ·) I
/-- Create an element of type `Order.Ideal` from a set satisfying the predicate
`Order.IsIdeal`. -/
def IsIdeal.toIdeal [LE P] {I : Set P} (h : IsIdeal I) : Ideal P :=
⟨⟨I, h.IsLowerSet⟩, h.Nonempty, h.Directed⟩
namespace Ideal
section LE
variable [LE P]
section
variable {I J s t : Ideal P} {x y : P}
theorem toLowerSet_injective : Injective (toLowerSet : Ideal P → LowerSet P) := fun s t _ ↦ by
cases s
cases t
congr
instance : SetLike (Ideal P) P where
coe s := s.carrier
coe_injective' _ _ h := toLowerSet_injective <| SetLike.coe_injective h
@[ext]
theorem ext {s t : Ideal P} : (s : Set P) = t → s = t :=
SetLike.ext'
@[simp]
theorem carrier_eq_coe (s : Ideal P) : s.carrier = s :=
rfl
@[simp]
theorem coe_toLowerSet (s : Ideal P) : (s.toLowerSet : Set P) = s :=
rfl
protected theorem lower (s : Ideal P) : IsLowerSet (s : Set P) :=
s.lower'
protected theorem nonempty (s : Ideal P) : (s : Set P).Nonempty :=
s.nonempty'
protected theorem directed (s : Ideal P) : DirectedOn (· ≤ ·) (s : Set P) :=
s.directed'
protected theorem isIdeal (s : Ideal P) : IsIdeal (s : Set P) :=
⟨s.lower, s.nonempty, s.directed⟩
theorem mem_compl_of_ge {x y : P} : x ≤ y → x ∈ (I : Set P)ᶜ → y ∈ (I : Set P)ᶜ := fun h ↦
mt <| I.lower h
/-- The partial ordering by subset inclusion, inherited from `Set P`. -/
instance instPartialOrderIdeal : PartialOrder (Ideal P) :=
PartialOrder.lift SetLike.coe SetLike.coe_injective
-- @[simp] -- Porting note (#10618): simp can prove this
theorem coe_subset_coe : (s : Set P) ⊆ t ↔ s ≤ t :=
Iff.rfl
-- @[simp] -- Porting note (#10618): simp can prove this
theorem coe_ssubset_coe : (s : Set P) ⊂ t ↔ s < t :=
Iff.rfl
@[trans]
theorem mem_of_mem_of_le {x : P} {I J : Ideal P} : x ∈ I → I ≤ J → x ∈ J :=
@Set.mem_of_mem_of_subset P x I J
/-- A proper ideal is one that is not the whole set.
Note that the whole set might not be an ideal. -/
@[mk_iff]
class IsProper (I : Ideal P) : Prop where
/-- This ideal is not the whole set. -/
ne_univ : (I : Set P) ≠ univ
theorem isProper_of_not_mem {I : Ideal P} {p : P} (nmem : p ∉ I) : IsProper I :=
⟨fun hp ↦ by
have := mem_univ p
rw [← hp] at this
exact nmem this⟩
/-- An ideal is maximal if it is maximal in the collection of proper ideals.
Note that `IsCoatom` is less general because ideals only have a top element when `P` is directed
and nonempty. -/
@[mk_iff]
class IsMaximal (I : Ideal P) extends IsProper I : Prop where
/-- This ideal is maximal in the collection of proper ideals. -/
maximal_proper : ∀ ⦃J : Ideal P⦄, I < J → (J : Set P) = univ
theorem inter_nonempty [IsDirected P (· ≥ ·)] (I J : Ideal P) : (I ∩ J : Set P).Nonempty := by
obtain ⟨a, ha⟩ := I.nonempty
obtain ⟨b, hb⟩ := J.nonempty
obtain ⟨c, hac, hbc⟩ := exists_le_le a b
exact ⟨c, I.lower hac ha, J.lower hbc hb⟩
end
section Directed
variable [IsDirected P (· ≤ ·)] [Nonempty P] {I : Ideal P}
/-- In a directed and nonempty order, the top ideal of a is `univ`. -/
instance : OrderTop (Ideal P) where
top := ⟨⊤, univ_nonempty, directedOn_univ⟩
le_top _ _ _ := LowerSet.mem_top
@[simp]
theorem top_toLowerSet : (⊤ : Ideal P).toLowerSet = ⊤ :=
rfl
@[simp]
theorem coe_top : ((⊤ : Ideal P) : Set P) = univ :=
rfl
theorem isProper_of_ne_top (ne_top : I ≠ ⊤) : IsProper I :=
⟨fun h ↦ ne_top <| ext h⟩
theorem IsProper.ne_top (_ : IsProper I) : I ≠ ⊤ :=
fun h ↦ IsProper.ne_univ <| congr_arg SetLike.coe h
theorem _root_.IsCoatom.isProper (hI : IsCoatom I) : IsProper I :=
isProper_of_ne_top hI.1
theorem isProper_iff_ne_top : IsProper I ↔ I ≠ ⊤ :=
⟨fun h ↦ h.ne_top, fun h ↦ isProper_of_ne_top h⟩
theorem IsMaximal.isCoatom (_ : IsMaximal I) : IsCoatom I :=
⟨IsMaximal.toIsProper.ne_top, fun _ h ↦ ext <| IsMaximal.maximal_proper h⟩
theorem IsMaximal.isCoatom' [IsMaximal I] : IsCoatom I :=
IsMaximal.isCoatom ‹_›
theorem _root_.IsCoatom.isMaximal (hI : IsCoatom I) : IsMaximal I :=
{ IsCoatom.isProper hI with maximal_proper := fun _ hJ ↦ by simp [hI.2 _ hJ] }
theorem isMaximal_iff_isCoatom : IsMaximal I ↔ IsCoatom I :=
⟨fun h ↦ h.isCoatom, fun h ↦ IsCoatom.isMaximal h⟩
end Directed
section OrderBot
variable [OrderBot P]
@[simp]
theorem bot_mem (s : Ideal P) : ⊥ ∈ s :=
s.lower bot_le s.nonempty'.some_mem
end OrderBot
section OrderTop
variable [OrderTop P] {I : Ideal P}
theorem top_of_top_mem (h : ⊤ ∈ I) : I = ⊤ := by
ext
exact iff_of_true (I.lower le_top h) trivial
theorem IsProper.top_not_mem (hI : IsProper I) : ⊤ ∉ I := fun h ↦ hI.ne_top <| top_of_top_mem h
end OrderTop
end LE
section Preorder
variable [Preorder P]
section
variable {I J : Ideal P} {x y : P}
/-- The smallest ideal containing a given element. -/
@[simps]
def principal (p : P) : Ideal P where
toLowerSet := LowerSet.Iic p
nonempty' := nonempty_Iic
directed' _ hx _ hy := ⟨p, le_rfl, hx, hy⟩
instance [Inhabited P] : Inhabited (Ideal P) :=
⟨Ideal.principal default⟩
@[simp]
theorem principal_le_iff : principal x ≤ I ↔ x ∈ I :=
⟨fun h ↦ h le_rfl, fun hx _ hy ↦ I.lower hy hx⟩
@[simp]
theorem mem_principal : x ∈ principal y ↔ x ≤ y :=
Iff.rfl
lemma mem_principal_self : x ∈ principal x :=
mem_principal.2 (le_refl x)
end
section OrderBot
variable [OrderBot P]
/-- There is a bottom ideal when `P` has a bottom element. -/
instance : OrderBot (Ideal P) where
bot := principal ⊥
bot_le := by simp
@[simp]
theorem principal_bot : principal (⊥ : P) = ⊥ :=
rfl
end OrderBot
section OrderTop
variable [OrderTop P]
@[simp]
theorem principal_top : principal (⊤ : P) = ⊤ :=
toLowerSet_injective <| LowerSet.Iic_top
end OrderTop
end Preorder
section SemilatticeSup
variable [SemilatticeSup P] {x y : P} {I s : Ideal P}
/-- A specific witness of `I.directed` when `P` has joins. -/
theorem sup_mem (hx : x ∈ s) (hy : y ∈ s) : x ⊔ y ∈ s :=
let ⟨_, hz, hx, hy⟩ := s.directed x hx y hy
s.lower (sup_le hx hy) hz
@[simp]
theorem sup_mem_iff : x ⊔ y ∈ I ↔ x ∈ I ∧ y ∈ I :=
⟨fun h ↦ ⟨I.lower le_sup_left h, I.lower le_sup_right h⟩, fun h ↦ sup_mem h.1 h.2⟩
end SemilatticeSup
section SemilatticeSupDirected
variable [SemilatticeSup P] [IsDirected P (· ≥ ·)] {x : P} {I J K s t : Ideal P}
/-- The infimum of two ideals of a co-directed order is their intersection. -/
instance : Inf (Ideal P) :=
⟨fun I J ↦
{ toLowerSet := I.toLowerSet ⊓ J.toLowerSet
nonempty' := inter_nonempty I J
directed' := fun x hx y hy ↦ ⟨x ⊔ y, ⟨sup_mem hx.1 hy.1, sup_mem hx.2 hy.2⟩, by simp⟩ }⟩
/-- The supremum of two ideals of a co-directed order is the union of the down sets of the pointwise
supremum of `I` and `J`. -/
instance : Sup (Ideal P) :=
⟨fun I J ↦
{ carrier := { x | ∃ i ∈ I, ∃ j ∈ J, x ≤ i ⊔ j }
nonempty' := by
cases' inter_nonempty I J with w h
exact ⟨w, w, h.1, w, h.2, le_sup_left⟩
directed' := fun x ⟨xi, _, xj, _, _⟩ y ⟨yi, _, yj, _, _⟩ ↦
⟨x ⊔ y, ⟨xi ⊔ yi, sup_mem ‹_› ‹_›, xj ⊔ yj, sup_mem ‹_› ‹_›,
sup_le
(calc
x ≤ xi ⊔ xj := ‹_›
_ ≤ xi ⊔ yi ⊔ (xj ⊔ yj) := sup_le_sup le_sup_left le_sup_left)
(calc
y ≤ yi ⊔ yj := ‹_›
_ ≤ xi ⊔ yi ⊔ (xj ⊔ yj) := sup_le_sup le_sup_right le_sup_right)⟩,
le_sup_left, le_sup_right⟩
lower' := fun x y h ⟨yi, hi, yj, hj, hxy⟩ ↦ ⟨yi, hi, yj, hj, h.trans hxy⟩ }⟩
instance : Lattice (Ideal P) :=
{ Ideal.instPartialOrderIdeal with
sup := (· ⊔ ·)
le_sup_left := fun _ J i hi ↦
let ⟨w, hw⟩ := J.nonempty
⟨i, hi, w, hw, le_sup_left⟩
le_sup_right := fun I _ j hj ↦
let ⟨w, hw⟩ := I.nonempty
⟨w, hw, j, hj, le_sup_right⟩
sup_le := fun _ _ K hIK hJK _ ⟨_, hi, _, hj, ha⟩ ↦
K.lower ha <| sup_mem (mem_of_mem_of_le hi hIK) (mem_of_mem_of_le hj hJK)
inf := (· ⊓ ·)
inf_le_left := fun _ _ ↦ inter_subset_left
inf_le_right := fun _ _ ↦ inter_subset_right
le_inf := fun _ _ _ ↦ subset_inter }
@[simp]
theorem coe_sup : ↑(s ⊔ t) = { x | ∃ a ∈ s, ∃ b ∈ t, x ≤ a ⊔ b } :=
rfl
-- Porting note: Modified `s ∩ t` to `↑s ∩ ↑t`.
@[simp]
theorem coe_inf : (↑(s ⊓ t) : Set P) = ↑s ∩ ↑t :=
rfl
@[simp]
theorem mem_inf : x ∈ I ⊓ J ↔ x ∈ I ∧ x ∈ J :=
Iff.rfl
@[simp]
theorem mem_sup : x ∈ I ⊔ J ↔ ∃ i ∈ I, ∃ j ∈ J, x ≤ i ⊔ j :=
Iff.rfl
theorem lt_sup_principal_of_not_mem (hx : x ∉ I) : I < I ⊔ principal x :=
le_sup_left.lt_of_ne fun h ↦ hx <| by simpa only [left_eq_sup, principal_le_iff] using h
end SemilatticeSupDirected
section SemilatticeSupOrderBot
variable [SemilatticeSup P] [OrderBot P] {x : P} {I J K : Ideal P}
instance : InfSet (Ideal P) :=
⟨fun S ↦
{ toLowerSet := ⨅ s ∈ S, toLowerSet s
nonempty' :=
⟨⊥, by
rw [LowerSet.carrier_eq_coe, LowerSet.coe_iInf₂, Set.mem_iInter₂]
exact fun s _ ↦ s.bot_mem⟩
directed' := fun a ha b hb ↦
⟨a ⊔ b,
⟨by
rw [LowerSet.carrier_eq_coe, LowerSet.coe_iInf₂, Set.mem_iInter₂] at ha hb ⊢
exact fun s hs ↦ sup_mem (ha _ hs) (hb _ hs), le_sup_left, le_sup_right⟩⟩ }⟩
variable {S : Set (Ideal P)}
@[simp]
theorem coe_sInf : (↑(sInf S) : Set P) = ⋂ s ∈ S, ↑s :=
LowerSet.coe_iInf₂ _
@[simp]
theorem mem_sInf : x ∈ sInf S ↔ ∀ s ∈ S, x ∈ s := by
simp_rw [← SetLike.mem_coe, coe_sInf, mem_iInter₂]
instance : CompleteLattice (Ideal P) :=
{ (inferInstance : Lattice (Ideal P)),
completeLatticeOfInf (Ideal P) fun S ↦ by
refine ⟨fun s hs ↦ ?_, fun s hs ↦ by rwa [← coe_subset_coe, coe_sInf, subset_iInter₂_iff]⟩
rw [← coe_subset_coe, coe_sInf]
exact biInter_subset_of_mem hs with }
end SemilatticeSupOrderBot
section DistribLattice
variable [DistribLattice P]
variable {I J : Ideal P}
theorem eq_sup_of_le_sup {x i j : P} (hi : i ∈ I) (hj : j ∈ J) (hx : x ≤ i ⊔ j) :
∃ i' ∈ I, ∃ j' ∈ J, x = i' ⊔ j' := by
refine ⟨x ⊓ i, I.lower inf_le_right hi, x ⊓ j, J.lower inf_le_right hj, ?_⟩
calc
x = x ⊓ (i ⊔ j) := left_eq_inf.mpr hx
_ = x ⊓ i ⊔ x ⊓ j := inf_sup_left _ _ _
theorem coe_sup_eq : ↑(I ⊔ J) = { x | ∃ i ∈ I, ∃ j ∈ J, x = i ⊔ j } :=
Set.ext fun _ ↦
⟨fun ⟨_, _, _, _, _⟩ ↦ eq_sup_of_le_sup ‹_› ‹_› ‹_›, fun ⟨i, _, j, _, _⟩ ↦
⟨i, ‹_›, j, ‹_›, le_of_eq ‹_›⟩⟩
end DistribLattice
section BooleanAlgebra
variable [BooleanAlgebra P] {x : P} {I : Ideal P}
theorem IsProper.not_mem_of_compl_mem (hI : IsProper I) (hxc : xᶜ ∈ I) : x ∉ I := by
intro hx
apply hI.top_not_mem
have ht : x ⊔ xᶜ ∈ I := sup_mem ‹_› ‹_›
rwa [sup_compl_eq_top] at ht
theorem IsProper.not_mem_or_compl_not_mem (hI : IsProper I) : x ∉ I ∨ xᶜ ∉ I := by
have h : xᶜ ∈ I → x ∉ I := hI.not_mem_of_compl_mem
tauto
end BooleanAlgebra
end Ideal
/-- For a preorder `P`, `Cofinal P` is the type of subsets of `P`
containing arbitrarily large elements. They are the dense sets in
the topology whose open sets are terminal segments. -/
structure Cofinal (P) [Preorder P] where
/-- The carrier of a `Cofinal` is the underlying set. -/
carrier : Set P
/-- The `Cofinal` contains arbitrarily large elements. -/
mem_gt : ∀ x : P, ∃ y ∈ carrier, x ≤ y
namespace Cofinal
variable [Preorder P]
instance : Inhabited (Cofinal P) :=
⟨{ carrier := univ
mem_gt := fun x ↦ ⟨x, trivial, le_rfl⟩ }⟩
instance : Membership P (Cofinal P) :=
⟨fun x D ↦ x ∈ D.carrier⟩
variable (D : Cofinal P) (x : P)
/-- A (noncomputable) element of a cofinal set lying above a given element. -/
noncomputable def above : P :=
Classical.choose <| D.mem_gt x
theorem above_mem : D.above x ∈ D :=
(Classical.choose_spec <| D.mem_gt x).1
theorem le_above : x ≤ D.above x :=
(Classical.choose_spec <| D.mem_gt x).2
end Cofinal
section IdealOfCofinals
variable [Preorder P] (p : P) {ι : Type*} [Encodable ι] (𝒟 : ι → Cofinal P)
/-- Given a starting point, and a countable family of cofinal sets,
this is an increasing sequence that intersects each cofinal set. -/
noncomputable def sequenceOfCofinals : ℕ → P
| 0 => p
| n + 1 =>
match Encodable.decode n with
| none => sequenceOfCofinals n
| some i => (𝒟 i).above (sequenceOfCofinals n)
theorem sequenceOfCofinals.monotone : Monotone (sequenceOfCofinals p 𝒟) := by
apply monotone_nat_of_le_succ
intro n
dsimp only [sequenceOfCofinals, Nat.add]
cases (Encodable.decode n : Option ι)
· rfl
· apply Cofinal.le_above
theorem sequenceOfCofinals.encode_mem (i : ι) :
sequenceOfCofinals p 𝒟 (Encodable.encode i + 1) ∈ 𝒟 i := by
dsimp only [sequenceOfCofinals, Nat.add]
rw [Encodable.encodek]
apply Cofinal.above_mem
/-- Given an element `p : P` and a family `𝒟` of cofinal subsets of a preorder `P`,
indexed by a countable type, `idealOfCofinals p 𝒟` is an ideal in `P` which
- contains `p`, according to `mem_idealOfCofinals p 𝒟`, and
- intersects every set in `𝒟`, according to `cofinal_meets_idealOfCofinals p 𝒟`.
This proves the Rasiowa–Sikorski lemma. -/
def idealOfCofinals : Ideal P where
carrier := { x : P | ∃ n, x ≤ sequenceOfCofinals p 𝒟 n }
lower' := fun _ _ hxy ⟨n, hn⟩ ↦ ⟨n, le_trans hxy hn⟩
nonempty' := ⟨p, 0, le_rfl⟩
directed' := fun _ ⟨n, hn⟩ _ ⟨m, hm⟩ ↦
⟨_, ⟨max n m, le_rfl⟩, le_trans hn <| sequenceOfCofinals.monotone p 𝒟 (le_max_left _ _),
le_trans hm <| sequenceOfCofinals.monotone p 𝒟 (le_max_right _ _)⟩
theorem mem_idealOfCofinals : p ∈ idealOfCofinals p 𝒟 :=
⟨0, le_rfl⟩
/-- `idealOfCofinals p 𝒟` is `𝒟`-generic. -/
theorem cofinal_meets_idealOfCofinals (i : ι) : ∃ x : P, x ∈ 𝒟 i ∧ x ∈ idealOfCofinals p 𝒟 :=
⟨_, sequenceOfCofinals.encode_mem p 𝒟 i, _, le_rfl⟩
end IdealOfCofinals
section sUnion
variable [Preorder P]
/-- A non-empty directed union of ideals of sets in a preorder is an ideal. -/
lemma isIdeal_sUnion_of_directedOn {C : Set (Set P)} (hidl : ∀ I ∈ C, IsIdeal I)
(hD : DirectedOn (· ⊆ ·) C) (hNe : C.Nonempty) : IsIdeal C.sUnion := by
refine ⟨isLowerSet_sUnion (fun I hI ↦ (hidl I hI).1), Set.nonempty_sUnion.2 ?_,
directedOn_sUnion hD (fun J hJ => (hidl J hJ).3)⟩
let ⟨I, hI⟩ := hNe
exact ⟨I, ⟨hI, (hidl I hI).2⟩⟩
/-- A union of a nonempty chain of ideals of sets is an ideal. -/
lemma isIdeal_sUnion_of_isChain {C : Set (Set P)} (hidl : ∀ I ∈ C, IsIdeal I)
(hC : IsChain (· ⊆ ·) C) (hNe : C.Nonempty) : IsIdeal C.sUnion :=
isIdeal_sUnion_of_directedOn hidl hC.directedOn hNe
end sUnion
end Order
|
Order\InitialSeg.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn
-/
import Mathlib.Logic.Equiv.Set
import Mathlib.Order.RelIso.Set
import Mathlib.Order.WellFounded
/-!
# Initial and principal segments
This file defines initial and principal segments.
## Main definitions
* `InitialSeg r s`: type of order embeddings of `r` into `s` for which the range is an initial
segment (i.e., if `b` belongs to the range, then any `b' < b` also belongs to the range).
It is denoted by `r ≼i s`.
* `PrincipalSeg r s`: Type of order embeddings of `r` into `s` for which the range is a principal
segment, i.e., an interval of the form `(-∞, top)` for some element `top`. It is denoted by
`r ≺i s`.
## Notations
These notations belong to the `InitialSeg` locale.
* `r ≼i s`: the type of initial segment embeddings of `r` into `s`.
* `r ≺i s`: the type of principal segment embeddings of `r` into `s`.
-/
/-!
### Initial segments
Order embeddings whose range is an initial segment of `s` (i.e., if `b` belongs to the range, then
any `b' < b` also belongs to the range). The type of these embeddings from `r` to `s` is called
`InitialSeg r s`, and denoted by `r ≼i s`.
-/
variable {α : Type*} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop}
open Function
/-- If `r` is a relation on `α` and `s` in a relation on `β`, then `f : r ≼i s` is an order
embedding whose range is an initial segment. That is, whenever `b < f a` in `β` then `b` is in the
range of `f`. -/
structure InitialSeg {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) extends r ↪r s where
/-- The order embedding is an initial segment -/
init' : ∀ a b, s b (toRelEmbedding a) → ∃ a', toRelEmbedding a' = b
-- Porting note: Deleted `scoped[InitialSeg]`
/-- If `r` is a relation on `α` and `s` in a relation on `β`, then `f : r ≼i s` is an order
embedding whose range is an initial segment. That is, whenever `b < f a` in `β` then `b` is in the
range of `f`. -/
infixl:25 " ≼i " => InitialSeg
namespace InitialSeg
instance : Coe (r ≼i s) (r ↪r s) :=
⟨InitialSeg.toRelEmbedding⟩
instance : FunLike (r ≼i s) α β where
coe f := f.toFun
coe_injective' := by
rintro ⟨f, hf⟩ ⟨g, hg⟩ h
congr with x
exact congr_fun h x
instance : EmbeddingLike (r ≼i s) α β where
injective' f := f.inj'
@[ext] lemma ext {f g : r ≼i s} (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
@[simp]
theorem coe_coe_fn (f : r ≼i s) : ((f : r ↪r s) : α → β) = f :=
rfl
theorem init (f : r ≼i s) {a : α} {b : β} : s b (f a) → ∃ a', f a' = b :=
f.init' _ _
theorem map_rel_iff {a b : α} (f : r ≼i s) : s (f a) (f b) ↔ r a b :=
f.map_rel_iff'
theorem init_iff (f : r ≼i s) {a : α} {b : β} : s b (f a) ↔ ∃ a', f a' = b ∧ r a' a :=
⟨fun h => by
rcases f.init h with ⟨a', rfl⟩
exact ⟨a', rfl, f.map_rel_iff.1 h⟩,
fun ⟨a', e, h⟩ => e ▸ f.map_rel_iff.2 h⟩
/-- An order isomorphism is an initial segment -/
def ofIso (f : r ≃r s) : r ≼i s :=
⟨f, fun _ b _ => ⟨f.symm b, RelIso.apply_symm_apply f _⟩⟩
/-- The identity function shows that `≼i` is reflexive -/
@[refl]
protected def refl (r : α → α → Prop) : r ≼i r :=
⟨RelEmbedding.refl _, fun _ _ _ => ⟨_, rfl⟩⟩
instance (r : α → α → Prop) : Inhabited (r ≼i r) :=
⟨InitialSeg.refl r⟩
/-- Composition of functions shows that `≼i` is transitive -/
@[trans]
protected def trans (f : r ≼i s) (g : s ≼i t) : r ≼i t :=
⟨f.1.trans g.1, fun a c h => by
simp only [RelEmbedding.coe_trans, coe_coe_fn, comp_apply] at h ⊢
rcases g.2 _ _ h with ⟨b, rfl⟩; have h := g.map_rel_iff.1 h
rcases f.2 _ _ h with ⟨a', rfl⟩; exact ⟨a', rfl⟩⟩
@[simp]
theorem refl_apply (x : α) : InitialSeg.refl r x = x :=
rfl
@[simp]
theorem trans_apply (f : r ≼i s) (g : s ≼i t) (a : α) : (f.trans g) a = g (f a) :=
rfl
instance subsingleton_of_trichotomous_of_irrefl [IsTrichotomous β s] [IsIrrefl β s]
[IsWellFounded α r] : Subsingleton (r ≼i s) :=
⟨fun f g => by
ext a
refine IsWellFounded.induction r a fun b IH =>
extensional_of_trichotomous_of_irrefl s fun x => ?_
rw [f.init_iff, g.init_iff]
exact exists_congr fun x => and_congr_left fun hx => IH _ hx ▸ Iff.rfl⟩
instance [IsWellOrder β s] : Subsingleton (r ≼i s) :=
⟨fun a => by let _ := a.isWellFounded; exact Subsingleton.elim a⟩
protected theorem eq [IsWellOrder β s] (f g : r ≼i s) (a) : f a = g a := by
rw [Subsingleton.elim f g]
theorem Antisymm.aux [IsWellOrder α r] (f : r ≼i s) (g : s ≼i r) : LeftInverse g f :=
InitialSeg.eq (f.trans g) (InitialSeg.refl _)
/-- If we have order embeddings between `α` and `β` whose images are initial segments, and `β`
is a well-order then `α` and `β` are order-isomorphic. -/
def antisymm [IsWellOrder β s] (f : r ≼i s) (g : s ≼i r) : r ≃r s :=
haveI := f.toRelEmbedding.isWellOrder
⟨⟨f, g, Antisymm.aux f g, Antisymm.aux g f⟩, f.map_rel_iff'⟩
@[simp]
theorem antisymm_toFun [IsWellOrder β s] (f : r ≼i s) (g : s ≼i r) : (antisymm f g : α → β) = f :=
rfl
@[simp]
theorem antisymm_symm [IsWellOrder α r] [IsWellOrder β s] (f : r ≼i s) (g : s ≼i r) :
(antisymm f g).symm = antisymm g f :=
RelIso.coe_fn_injective rfl
theorem eq_or_principal [IsWellOrder β s] (f : r ≼i s) :
Surjective f ∨ ∃ b, ∀ x, s x b ↔ ∃ y, f y = x :=
or_iff_not_imp_right.2 fun h b =>
Acc.recOn (IsWellFounded.wf.apply b : Acc s b) fun x _ IH =>
not_forall_not.1 fun hn =>
h
⟨x, fun y =>
⟨IH _, fun ⟨a, e⟩ => by
rw [← e]
exact (trichotomous _ _).resolve_right
(not_or_of_not (hn a) fun hl => not_exists.2 hn (f.init hl))⟩⟩
/-- Restrict the codomain of an initial segment -/
def codRestrict (p : Set β) (f : r ≼i s) (H : ∀ a, f a ∈ p) : r ≼i Subrel s p :=
⟨RelEmbedding.codRestrict p f H, fun a ⟨b, m⟩ h =>
let ⟨a', e⟩ := f.init h
⟨a', by subst e; rfl⟩⟩
@[simp]
theorem codRestrict_apply (p) (f : r ≼i s) (H a) : codRestrict p f H a = ⟨f a, H a⟩ :=
rfl
/-- Initial segment from an empty type. -/
def ofIsEmpty (r : α → α → Prop) (s : β → β → Prop) [IsEmpty α] : r ≼i s :=
⟨RelEmbedding.ofIsEmpty r s, isEmptyElim⟩
/-- Initial segment embedding of an order `r` into the disjoint union of `r` and `s`. -/
def leAdd (r : α → α → Prop) (s : β → β → Prop) : r ≼i Sum.Lex r s :=
⟨⟨⟨Sum.inl, fun _ _ => Sum.inl.inj⟩, Sum.lex_inl_inl⟩, fun a b => by
cases b <;> [exact fun _ => ⟨_, rfl⟩; exact False.elim ∘ Sum.lex_inr_inl]⟩
@[simp]
theorem leAdd_apply (r : α → α → Prop) (s : β → β → Prop) (a) : leAdd r s a = Sum.inl a :=
rfl
protected theorem acc (f : r ≼i s) (a : α) : Acc r a ↔ Acc s (f a) :=
⟨by
refine fun h => Acc.recOn h fun a _ ha => Acc.intro _ fun b hb => ?_
obtain ⟨a', rfl⟩ := f.init hb
exact ha _ (f.map_rel_iff.mp hb), f.toRelEmbedding.acc a⟩
end InitialSeg
/-!
### Principal segments
Order embeddings whose range is a principal segment of `s` (i.e., an interval of the form
`(-∞, top)` for some element `top` of `β`). The type of these embeddings from `r` to `s` is called
`PrincipalSeg r s`, and denoted by `r ≺i s`. Principal segments are in particular initial
segments.
-/
/-- If `r` is a relation on `α` and `s` in a relation on `β`, then `f : r ≺i s` is an order
embedding whose range is an open interval `(-∞, top)` for some element `top` of `β`. Such order
embeddings are called principal segments -/
structure PrincipalSeg {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) extends r ↪r s where
/-- The supremum of the principal segment -/
top : β
/-- The image of the order embedding is the set of elements `b` such that `s b top` -/
down' : ∀ b, s b top ↔ ∃ a, toRelEmbedding a = b
-- Porting note: deleted `scoped[InitialSeg]`
/-- If `r` is a relation on `α` and `s` in a relation on `β`, then `f : r ≺i s` is an order
embedding whose range is an open interval `(-∞, top)` for some element `top` of `β`. Such order
embeddings are called principal segments -/
infixl:25 " ≺i " => PrincipalSeg
namespace PrincipalSeg
instance : CoeOut (r ≺i s) (r ↪r s) :=
⟨PrincipalSeg.toRelEmbedding⟩
instance : CoeFun (r ≺i s) fun _ => α → β :=
⟨fun f => f⟩
@[simp]
theorem coe_fn_mk (f : r ↪r s) (t o) : (@PrincipalSeg.mk _ _ r s f t o : α → β) = f :=
rfl
theorem down (f : r ≺i s) : ∀ {b : β}, s b f.top ↔ ∃ a, f a = b :=
f.down' _
theorem lt_top (f : r ≺i s) (a : α) : s (f a) f.top :=
f.down.2 ⟨_, rfl⟩
theorem init [IsTrans β s] (f : r ≺i s) {a : α} {b : β} (h : s b (f a)) : ∃ a', f a' = b :=
f.down.1 <| _root_.trans h <| f.lt_top _
/-- A principal segment is in particular an initial segment. -/
instance hasCoeInitialSeg [IsTrans β s] : Coe (r ≺i s) (r ≼i s) :=
⟨fun f => ⟨f.toRelEmbedding, fun _ _ => f.init⟩⟩
theorem coe_coe_fn' [IsTrans β s] (f : r ≺i s) : ((f : r ≼i s) : α → β) = f :=
rfl
theorem init_iff [IsTrans β s] (f : r ≺i s) {a : α} {b : β} : s b (f a) ↔ ∃ a', f a' = b ∧ r a' a :=
@InitialSeg.init_iff α β r s f a b
theorem irrefl {r : α → α → Prop} [IsWellOrder α r] (f : r ≺i r) : False := by
have h := f.lt_top f.top
rw [show f f.top = f.top from InitialSeg.eq (↑f) (InitialSeg.refl r) f.top] at h
exact _root_.irrefl _ h
instance (r : α → α → Prop) [IsWellOrder α r] : IsEmpty (r ≺i r) :=
⟨fun f => f.irrefl⟩
/-- Composition of a principal segment with an initial segment, as a principal segment -/
def ltLe (f : r ≺i s) (g : s ≼i t) : r ≺i t :=
⟨@RelEmbedding.trans _ _ _ r s t f g, g f.top, fun a => by
simp only [g.init_iff, PrincipalSeg.down, exists_and_left.symm, exists_swap,
RelEmbedding.trans_apply, exists_eq_right', InitialSeg.coe_coe_fn]⟩
@[simp]
theorem lt_le_apply (f : r ≺i s) (g : s ≼i t) (a : α) : (f.ltLe g) a = g (f a) :=
RelEmbedding.trans_apply _ _ _
@[simp]
theorem lt_le_top (f : r ≺i s) (g : s ≼i t) : (f.ltLe g).top = g f.top :=
rfl
/-- Composition of two principal segments as a principal segment -/
@[trans]
protected def trans [IsTrans γ t] (f : r ≺i s) (g : s ≺i t) : r ≺i t :=
ltLe f g
@[simp]
theorem trans_apply [IsTrans γ t] (f : r ≺i s) (g : s ≺i t) (a : α) : (f.trans g) a = g (f a) :=
lt_le_apply _ _ _
@[simp]
theorem trans_top [IsTrans γ t] (f : r ≺i s) (g : s ≺i t) : (f.trans g).top = g f.top :=
rfl
/-- Composition of an order isomorphism with a principal segment, as a principal segment -/
def equivLT (f : r ≃r s) (g : s ≺i t) : r ≺i t :=
⟨@RelEmbedding.trans _ _ _ r s t f g, g.top, fun c =>
suffices (∃ a : β, g a = c) ↔ ∃ a : α, g (f a) = c by simpa [PrincipalSeg.down]
⟨fun ⟨b, h⟩ => ⟨f.symm b, by simp only [h, RelIso.apply_symm_apply]⟩,
fun ⟨a, h⟩ => ⟨f a, h⟩⟩⟩
/-- Composition of a principal segment with an order isomorphism, as a principal segment -/
def ltEquiv {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} (f : PrincipalSeg r s)
(g : s ≃r t) : PrincipalSeg r t :=
⟨@RelEmbedding.trans _ _ _ r s t f g, g f.top, by
intro x
rw [← g.apply_symm_apply x, g.map_rel_iff, f.down', exists_congr]
intro y; exact ⟨congr_arg g, fun h => g.toEquiv.bijective.1 h⟩⟩
@[simp]
theorem equivLT_apply (f : r ≃r s) (g : s ≺i t) (a : α) : (equivLT f g) a = g (f a) :=
RelEmbedding.trans_apply _ _ _
@[simp]
theorem equivLT_top (f : r ≃r s) (g : s ≺i t) : (equivLT f g).top = g.top :=
rfl
/-- Given a well order `s`, there is a most one principal segment embedding of `r` into `s`. -/
instance [IsWellOrder β s] : Subsingleton (r ≺i s) :=
⟨fun f g => by
have ef : (f : α → β) = g := by
show ((f : r ≼i s) : α → β) = (g : r ≼i s)
rw [@Subsingleton.elim _ _ (f : r ≼i s) g]
have et : f.top = g.top := by
refine extensional_of_trichotomous_of_irrefl s fun x => ?_
simp only [PrincipalSeg.down, ef]
cases f
cases g
have := RelEmbedding.coe_fn_injective ef; congr ⟩
theorem top_eq [IsWellOrder γ t] (e : r ≃r s) (f : r ≺i t) (g : s ≺i t) : f.top = g.top := by
rw [Subsingleton.elim f (PrincipalSeg.equivLT e g)]; rfl
theorem topLTTop {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} [IsWellOrder γ t]
(f : PrincipalSeg r s) (g : PrincipalSeg s t) (h : PrincipalSeg r t) : t h.top g.top := by
rw [Subsingleton.elim h (f.trans g)]
apply PrincipalSeg.lt_top
/-- Any element of a well order yields a principal segment -/
def ofElement {α : Type*} (r : α → α → Prop) (a : α) : Subrel r { b | r b a } ≺i r :=
⟨Subrel.relEmbedding _ _, a, fun _ => ⟨fun h => ⟨⟨_, h⟩, rfl⟩, fun ⟨⟨_, h⟩, rfl⟩ => h⟩⟩
-- This lemma was always bad, but the linter only noticed after lean4#2644
@[simp, nolint simpNF]
theorem ofElement_apply {α : Type*} (r : α → α → Prop) (a : α) (b) : ofElement r a b = b.1 :=
rfl
@[simp]
theorem ofElement_top {α : Type*} (r : α → α → Prop) (a : α) : (ofElement r a).top = a :=
rfl
/-- For any principal segment `r ≺i s`, there is a `Subrel` of `s` order isomorphic to `r`. -/
@[simps! symm_apply]
noncomputable def subrelIso (f : r ≺i s) : Subrel s {b | s b f.top} ≃r r :=
RelIso.symm
{ toEquiv := ((Equiv.ofInjective f f.injective).trans (Equiv.setCongr
(funext fun _ ↦ propext f.down.symm))),
map_rel_iff' := f.map_rel_iff }
-- This lemma was always bad, but the linter only noticed after lean4#2644
attribute [nolint simpNF] PrincipalSeg.subrelIso_symm_apply
-- This lemma was always bad, but the linter only noticed after lean4#2644
@[simp, nolint simpNF]
theorem apply_subrelIso (f : r ≺i s) (b : {b | s b f.top}) :
f (f.subrelIso b) = b :=
Equiv.apply_ofInjective_symm f.injective _
-- This lemma was always bad, but the linter only noticed after lean4#2644
@[simp, nolint simpNF]
theorem subrelIso_apply (f : r ≺i s) (a : α) :
f.subrelIso ⟨f a, f.down.mpr ⟨a, rfl⟩⟩ = a :=
Equiv.ofInjective_symm_apply f.injective _
/-- Restrict the codomain of a principal segment -/
def codRestrict (p : Set β) (f : r ≺i s) (H : ∀ a, f a ∈ p) (H₂ : f.top ∈ p) : r ≺i Subrel s p :=
⟨RelEmbedding.codRestrict p f H, ⟨f.top, H₂⟩, fun ⟨_, _⟩ =>
f.down.trans <|
exists_congr fun a => show (⟨f a, H a⟩ : p).1 = _ ↔ _ from ⟨Subtype.eq, congr_arg _⟩⟩
@[simp]
theorem codRestrict_apply (p) (f : r ≺i s) (H H₂ a) : codRestrict p f H H₂ a = ⟨f a, H a⟩ :=
rfl
@[simp]
theorem codRestrict_top (p) (f : r ≺i s) (H H₂) : (codRestrict p f H H₂).top = ⟨f.top, H₂⟩ :=
rfl
/-- Principal segment from an empty type into a type with a minimal element. -/
def ofIsEmpty (r : α → α → Prop) [IsEmpty α] {b : β} (H : ∀ b', ¬s b' b) : r ≺i s :=
{ RelEmbedding.ofIsEmpty r s with
top := b
down' := by simp [H] }
@[simp]
theorem ofIsEmpty_top (r : α → α → Prop) [IsEmpty α] {b : β} (H : ∀ b', ¬s b' b) :
(ofIsEmpty r H).top = b :=
rfl
/-- Principal segment from the empty relation on `PEmpty` to the empty relation on `PUnit`. -/
abbrev pemptyToPunit : @EmptyRelation PEmpty ≺i @EmptyRelation PUnit :=
(@ofIsEmpty _ _ EmptyRelation _ _ PUnit.unit) fun _ => not_false
protected theorem acc [IsTrans β s] (f : r ≺i s) (a : α) : Acc r a ↔ Acc s (f a) :=
(f : r ≼i s).acc a
end PrincipalSeg
/-- A relation is well-founded iff every principal segment of it is well-founded.
In this lemma we use `Subrel` to indicate its principal segments because it's usually more
convenient to use.
-/
theorem wellFounded_iff_wellFounded_subrel {β : Type*} {s : β → β → Prop} [IsTrans β s] :
WellFounded s ↔ ∀ b, WellFounded (Subrel s { b' | s b' b }) := by
refine
⟨fun wf b => ⟨fun b' => ((PrincipalSeg.ofElement _ b).acc b').mpr (wf.apply b')⟩, fun wf =>
⟨fun b => Acc.intro _ fun b' hb' => ?_⟩⟩
let f := PrincipalSeg.ofElement s b
obtain ⟨b', rfl⟩ := f.down.mp ((PrincipalSeg.ofElement_top s b).symm ▸ hb' : s b' f.top)
exact (f.acc b').mp ((wf b).apply b')
theorem wellFounded_iff_principalSeg.{u} {β : Type u} {s : β → β → Prop} [IsTrans β s] :
WellFounded s ↔ ∀ (α : Type u) (r : α → α → Prop) (_ : r ≺i s), WellFounded r :=
⟨fun wf _ _ f => RelHomClass.wellFounded f.toRelEmbedding wf, fun h =>
wellFounded_iff_wellFounded_subrel.mpr fun b => h _ _ (PrincipalSeg.ofElement s b)⟩
/-! ### Properties of initial and principal segments -/
/-- To an initial segment taking values in a well order, one can associate either a principal
segment (if the range is not everything, hence one can take as top the minimum of the complement
of the range) or an order isomorphism (if the range is everything). -/
noncomputable def InitialSeg.ltOrEq [IsWellOrder β s] (f : r ≼i s) : (r ≺i s) ⊕ (r ≃r s) := by
by_cases h : Surjective f
· exact Sum.inr (RelIso.ofSurjective f h)
· have h' : _ := (InitialSeg.eq_or_principal f).resolve_left h
exact Sum.inl ⟨f, Classical.choose h', Classical.choose_spec h'⟩
theorem InitialSeg.ltOrEq_apply_left [IsWellOrder β s] (f : r ≼i s) (g : r ≺i s) (a : α) :
g a = f a :=
@InitialSeg.eq α β r s _ g f a
theorem InitialSeg.ltOrEq_apply_right [IsWellOrder β s] (f : r ≼i s) (g : r ≃r s) (a : α) :
g a = f a :=
InitialSeg.eq (InitialSeg.ofIso g) f a
/-- Composition of an initial segment taking values in a well order and a principal segment. -/
noncomputable def InitialSeg.leLT [IsWellOrder β s] [IsTrans γ t] (f : r ≼i s) (g : s ≺i t) :
r ≺i t :=
match f.ltOrEq with
| Sum.inl f' => f'.trans g
| Sum.inr f' => PrincipalSeg.equivLT f' g
@[simp]
theorem InitialSeg.leLT_apply [IsWellOrder β s] [IsTrans γ t] (f : r ≼i s) (g : s ≺i t) (a : α) :
(f.leLT g) a = g (f a) := by
delta InitialSeg.leLT; cases' f.ltOrEq with f' f'
· simp only [PrincipalSeg.trans_apply, f.ltOrEq_apply_left]
· simp only [PrincipalSeg.equivLT_apply, f.ltOrEq_apply_right]
namespace RelEmbedding
/-- Given an order embedding into a well order, collapse the order embedding by filling the
gaps, to obtain an initial segment. Here, we construct the collapsed order embedding pointwise,
but the proof of the fact that it is an initial segment will be given in `collapse`. -/
noncomputable def collapseF [IsWellOrder β s] (f : r ↪r s) : ∀ a, { b // ¬s (f a) b } :=
(RelEmbedding.wellFounded f <| IsWellFounded.wf).fix fun a IH => by
let S := { b | ∀ a h, s (IH a h).1 b }
have : f a ∈ S := fun a' h =>
((trichotomous _ _).resolve_left fun h' =>
(IH a' h).2 <| _root_.trans (f.map_rel_iff.2 h) h').resolve_left
fun h' => (IH a' h).2 <| h' ▸ f.map_rel_iff.2 h
exact ⟨_, IsWellFounded.wf.not_lt_min _ ⟨_, this⟩ this⟩
theorem collapseF.lt [IsWellOrder β s] (f : r ↪r s) {a : α} :
∀ {a'}, r a' a → s (collapseF f a').1 (collapseF f a).1 := @fun a => by
revert a
show (collapseF f a).1 ∈ { b | ∀ (a') (_ : r a' a), s (collapseF f a').1 b }
unfold collapseF; rw [WellFounded.fix_eq]
dsimp only
apply WellFounded.min_mem _ _
theorem collapseF.not_lt [IsWellOrder β s] (f : r ↪r s) (a : α) {b}
(h : ∀ a' (_ : r a' a), s (collapseF f a').1 b) : ¬s b (collapseF f a).1 := by
unfold collapseF; rw [WellFounded.fix_eq]
dsimp only
exact WellFounded.not_lt_min _ _ _ h
/-- Construct an initial segment from an order embedding into a well order, by collapsing it
to fill the gaps. -/
noncomputable def collapse [IsWellOrder β s] (f : r ↪r s) : r ≼i s :=
haveI := RelEmbedding.isWellOrder f
⟨RelEmbedding.ofMonotone (fun a => (collapseF f a).1) fun a b => collapseF.lt f, fun a b =>
Acc.recOn (IsWellFounded.wf.apply b : Acc s b)
(fun b _ _ a h => by
rcases (@IsWellFounded.wf _ r).has_min { a | ¬s (collapseF f a).1 b }
⟨_, asymm h⟩ with ⟨m, hm, hm'⟩
refine ⟨m, ((@trichotomous _ s _ _ _).resolve_left hm).resolve_right
(collapseF.not_lt f _ fun a' h' => ?_)⟩
by_contra hn
exact hm' _ hn h')
a⟩
theorem collapse_apply [IsWellOrder β s] (f : r ↪r s) (a) : collapse f a = (collapseF f a).1 :=
rfl
end RelEmbedding
attribute [nolint simpNF] PrincipalSeg.ofElement_apply PrincipalSeg.subrelIso_symm_apply
PrincipalSeg.apply_subrelIso PrincipalSeg.subrelIso_apply
|
Order\Irreducible.lean | /-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.Lattice
/-!
# Irreducible and prime elements in an order
This file defines irreducible and prime elements in an order and shows that in a well-founded
lattice every element decomposes as a supremum of irreducible elements.
An element is sup-irreducible (resp. inf-irreducible) if it isn't `⊥` and can't be written as the
supremum of any strictly smaller elements. An element is sup-prime (resp. inf-prime) if it isn't `⊥`
and is greater than the supremum of any two elements less than it.
Primality implies irreducibility in general. The converse only holds in distributive lattices.
Both hold for all (non-minimal) elements in a linear order.
## Main declarations
* `SupIrred a`: Sup-irreducibility, `a` isn't minimal and `a = b ⊔ c → a = b ∨ a = c`
* `InfIrred a`: Inf-irreducibility, `a` isn't maximal and `a = b ⊓ c → a = b ∨ a = c`
* `SupPrime a`: Sup-primality, `a` isn't minimal and `a ≤ b ⊔ c → a ≤ b ∨ a ≤ c`
* `InfIrred a`: Inf-primality, `a` isn't maximal and `a ≥ b ⊓ c → a ≥ b ∨ a ≥ c`
* `exists_supIrred_decomposition`/`exists_infIrred_decomposition`: Decomposition into irreducibles
in a well-founded semilattice.
-/
open Finset OrderDual
variable {ι α : Type*}
/-! ### Irreducible and prime elements -/
section SemilatticeSup
variable [SemilatticeSup α] {a b c : α}
/-- A sup-irreducible element is a non-bottom element which isn't the supremum of anything smaller.
-/
def SupIrred (a : α) : Prop :=
¬IsMin a ∧ ∀ ⦃b c⦄, b ⊔ c = a → b = a ∨ c = a
/-- A sup-prime element is a non-bottom element which isn't less than the supremum of anything
smaller. -/
def SupPrime (a : α) : Prop :=
¬IsMin a ∧ ∀ ⦃b c⦄, a ≤ b ⊔ c → a ≤ b ∨ a ≤ c
theorem SupIrred.not_isMin (ha : SupIrred a) : ¬IsMin a :=
ha.1
theorem SupPrime.not_isMin (ha : SupPrime a) : ¬IsMin a :=
ha.1
theorem IsMin.not_supIrred (ha : IsMin a) : ¬SupIrred a := fun h => h.1 ha
theorem IsMin.not_supPrime (ha : IsMin a) : ¬SupPrime a := fun h => h.1 ha
@[simp]
theorem not_supIrred : ¬SupIrred a ↔ IsMin a ∨ ∃ b c, b ⊔ c = a ∧ b < a ∧ c < a := by
rw [SupIrred, not_and_or]
push_neg
rw [exists₂_congr]
simp (config := { contextual := true }) [@eq_comm _ _ a]
@[simp]
theorem not_supPrime : ¬SupPrime a ↔ IsMin a ∨ ∃ b c, a ≤ b ⊔ c ∧ ¬a ≤ b ∧ ¬a ≤ c := by
rw [SupPrime, not_and_or]; push_neg; rfl
protected theorem SupPrime.supIrred : SupPrime a → SupIrred a :=
And.imp_right fun h b c ha => by simpa [← ha] using h ha.ge
theorem SupPrime.le_sup (ha : SupPrime a) : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c :=
⟨fun h => ha.2 h, fun h => h.elim le_sup_of_le_left le_sup_of_le_right⟩
variable [OrderBot α] {s : Finset ι} {f : ι → α}
@[simp]
theorem not_supIrred_bot : ¬SupIrred (⊥ : α) :=
isMin_bot.not_supIrred
@[simp]
theorem not_supPrime_bot : ¬SupPrime (⊥ : α) :=
isMin_bot.not_supPrime
theorem SupIrred.ne_bot (ha : SupIrred a) : a ≠ ⊥ := by rintro rfl; exact not_supIrred_bot ha
theorem SupPrime.ne_bot (ha : SupPrime a) : a ≠ ⊥ := by rintro rfl; exact not_supPrime_bot ha
theorem SupIrred.finset_sup_eq (ha : SupIrred a) (h : s.sup f = a) : ∃ i ∈ s, f i = a := by
classical
induction' s using Finset.induction with i s _ ih
· simpa [ha.ne_bot] using h.symm
simp only [exists_prop, exists_mem_insert] at ih ⊢
rw [sup_insert] at h
exact (ha.2 h).imp_right ih
theorem SupPrime.le_finset_sup (ha : SupPrime a) : a ≤ s.sup f ↔ ∃ i ∈ s, a ≤ f i := by
classical
induction' s using Finset.induction with i s _ ih
· simp [ha.ne_bot]
· simp only [exists_prop, exists_mem_insert, sup_insert, ha.le_sup, ih]
variable [WellFoundedLT α]
/-- In a well-founded lattice, any element is the supremum of finitely many sup-irreducible
elements. This is the order-theoretic analogue of prime factorisation. -/
theorem exists_supIrred_decomposition (a : α) :
∃ s : Finset α, s.sup id = a ∧ ∀ ⦃b⦄, b ∈ s → SupIrred b := by
classical
apply WellFoundedLT.induction a _
clear a
rintro a ih
by_cases ha : SupIrred a
· exact ⟨{a}, by simp [ha]⟩
rw [not_supIrred] at ha
obtain ha | ⟨b, c, rfl, hb, hc⟩ := ha
· exact ⟨∅, by simp [ha.eq_bot]⟩
obtain ⟨s, rfl, hs⟩ := ih _ hb
obtain ⟨t, rfl, ht⟩ := ih _ hc
exact ⟨s ∪ t, sup_union, forall_mem_union.2 ⟨hs, ht⟩⟩
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] {a b c : α}
/-- An inf-irreducible element is a non-top element which isn't the infimum of anything bigger. -/
def InfIrred (a : α) : Prop :=
¬IsMax a ∧ ∀ ⦃b c⦄, b ⊓ c = a → b = a ∨ c = a
/-- An inf-prime element is a non-top element which isn't bigger than the infimum of anything
bigger. -/
def InfPrime (a : α) : Prop :=
¬IsMax a ∧ ∀ ⦃b c⦄, b ⊓ c ≤ a → b ≤ a ∨ c ≤ a
@[simp]
theorem IsMax.not_infIrred (ha : IsMax a) : ¬InfIrred a := fun h => h.1 ha
@[simp]
theorem IsMax.not_infPrime (ha : IsMax a) : ¬InfPrime a := fun h => h.1 ha
@[simp]
theorem not_infIrred : ¬InfIrred a ↔ IsMax a ∨ ∃ b c, b ⊓ c = a ∧ a < b ∧ a < c :=
@not_supIrred αᵒᵈ _ _
@[simp]
theorem not_infPrime : ¬InfPrime a ↔ IsMax a ∨ ∃ b c, b ⊓ c ≤ a ∧ ¬b ≤ a ∧ ¬c ≤ a :=
@not_supPrime αᵒᵈ _ _
protected theorem InfPrime.infIrred : InfPrime a → InfIrred a :=
And.imp_right fun h b c ha => by simpa [← ha] using h ha.le
theorem InfPrime.inf_le (ha : InfPrime a) : b ⊓ c ≤ a ↔ b ≤ a ∨ c ≤ a :=
⟨fun h => ha.2 h, fun h => h.elim inf_le_of_left_le inf_le_of_right_le⟩
variable [OrderTop α] {s : Finset ι} {f : ι → α}
-- @[simp] Porting note (#10618): simp can prove this.
theorem not_infIrred_top : ¬InfIrred (⊤ : α) :=
isMax_top.not_infIrred
-- @[simp] Porting note (#10618): simp can prove this.
theorem not_infPrime_top : ¬InfPrime (⊤ : α) :=
isMax_top.not_infPrime
theorem InfIrred.ne_top (ha : InfIrred a) : a ≠ ⊤ := by rintro rfl; exact not_infIrred_top ha
theorem InfPrime.ne_top (ha : InfPrime a) : a ≠ ⊤ := by rintro rfl; exact not_infPrime_top ha
theorem InfIrred.finset_inf_eq : InfIrred a → s.inf f = a → ∃ i ∈ s, f i = a :=
@SupIrred.finset_sup_eq _ αᵒᵈ _ _ _ _ _
theorem InfPrime.finset_inf_le (ha : InfPrime a) : s.inf f ≤ a ↔ ∃ i ∈ s, f i ≤ a :=
@SupPrime.le_finset_sup _ αᵒᵈ _ _ _ _ _ ha
variable [WellFoundedGT α]
/-- In a cowell-founded lattice, any element is the infimum of finitely many inf-irreducible
elements. This is the order-theoretic analogue of prime factorisation. -/
theorem exists_infIrred_decomposition (a : α) :
∃ s : Finset α, s.inf id = a ∧ ∀ ⦃b⦄, b ∈ s → InfIrred b :=
exists_supIrred_decomposition (α := αᵒᵈ) _
end SemilatticeInf
section SemilatticeSup
variable [SemilatticeSup α]
@[simp]
theorem infIrred_toDual {a : α} : InfIrred (toDual a) ↔ SupIrred a :=
Iff.rfl
@[simp]
theorem infPrime_toDual {a : α} : InfPrime (toDual a) ↔ SupPrime a :=
Iff.rfl
@[simp]
theorem supIrred_ofDual {a : αᵒᵈ} : SupIrred (ofDual a) ↔ InfIrred a :=
Iff.rfl
@[simp]
theorem supPrime_ofDual {a : αᵒᵈ} : SupPrime (ofDual a) ↔ InfPrime a :=
Iff.rfl
alias ⟨_, SupIrred.dual⟩ := infIrred_toDual
alias ⟨_, SupPrime.dual⟩ := infPrime_toDual
alias ⟨_, InfIrred.ofDual⟩ := supIrred_ofDual
alias ⟨_, InfPrime.ofDual⟩ := supPrime_ofDual
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α]
@[simp]
theorem supIrred_toDual {a : α} : SupIrred (toDual a) ↔ InfIrred a :=
Iff.rfl
@[simp]
theorem supPrime_toDual {a : α} : SupPrime (toDual a) ↔ InfPrime a :=
Iff.rfl
@[simp]
theorem infIrred_ofDual {a : αᵒᵈ} : InfIrred (ofDual a) ↔ SupIrred a :=
Iff.rfl
@[simp]
theorem infPrime_ofDual {a : αᵒᵈ} : InfPrime (ofDual a) ↔ SupPrime a :=
Iff.rfl
alias ⟨_, InfIrred.dual⟩ := supIrred_toDual
alias ⟨_, InfPrime.dual⟩ := supPrime_toDual
alias ⟨_, SupIrred.ofDual⟩ := infIrred_ofDual
alias ⟨_, SupPrime.ofDual⟩ := infPrime_ofDual
end SemilatticeInf
section DistribLattice
variable [DistribLattice α] {a b c : α}
@[simp]
theorem supPrime_iff_supIrred : SupPrime a ↔ SupIrred a :=
⟨SupPrime.supIrred,
And.imp_right fun h b c => by simp_rw [← inf_eq_left, inf_sup_left]; exact @h _ _⟩
@[simp]
theorem infPrime_iff_infIrred : InfPrime a ↔ InfIrred a :=
⟨InfPrime.infIrred,
And.imp_right fun h b c => by simp_rw [← sup_eq_left, sup_inf_left]; exact @h _ _⟩
alias ⟨_, SupIrred.supPrime⟩ := supPrime_iff_supIrred
alias ⟨_, InfIrred.infPrime⟩ := infPrime_iff_infIrred
-- Porting note: was attribute [protected] SupIrred.supPrime InfIrred.infPrime
end DistribLattice
section LinearOrder
variable [LinearOrder α] {a : α}
-- @[simp] Porting note (#10618): simp can prove this
theorem supPrime_iff_not_isMin : SupPrime a ↔ ¬IsMin a :=
and_iff_left <| by simp
-- @[simp] Porting note (#10618): simp can prove thisrove this
theorem infPrime_iff_not_isMax : InfPrime a ↔ ¬IsMax a :=
and_iff_left <| by simp
@[simp]
theorem supIrred_iff_not_isMin : SupIrred a ↔ ¬IsMin a :=
and_iff_left fun _ _ => by simpa only [sup_eq_max, max_eq_iff] using Or.imp And.left And.left
@[simp]
theorem infIrred_iff_not_isMax : InfIrred a ↔ ¬IsMax a :=
and_iff_left fun _ _ => by simpa only [inf_eq_min, min_eq_iff] using Or.imp And.left And.left
end LinearOrder
|
Order\IsWellOrderLimitElement.lean | /-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Order.WellFounded
/-!
# Limit elements in well-ordered types
This file introduces two main definitions:
- `wellOrderSucc a`: the successor of an element `a` in a well-ordered type
- the typeclass `IsWellOrderLimitElement a` which asserts that an element `a` (in a
well-ordered type) is neither a successor nor the smallest element, i.e. `a` is a limit element
Then, the lemma `eq_bot_or_eq_succ_or_isWellOrderLimitElement` shows that an element
in a well-ordered type is either `⊥`, a successor, or a limit element.
-/
variable {α : Type*} [LinearOrder α]
section
variable [IsWellOrder α (· < ·)]
/-- Given an element `a : α` in a well ordered set, this is the successor of `a`,
i.e. the smallest element stricly greater than `a` if it exists (or `a` itself otherwise). -/
noncomputable def wellOrderSucc (a : α) : α :=
(IsWellFounded.wf (r := (· < ·))).succ a
lemma self_le_wellOrderSucc (a : α) : a ≤ wellOrderSucc a := by
by_cases h : ∃ b, a < b
· exact (IsWellFounded.wf.lt_succ h).le
· dsimp [wellOrderSucc, WellFounded.succ]
rw [dif_neg h]
lemma wellOrderSucc_le {a b : α} (ha : a < b) : wellOrderSucc a ≤ b := by
dsimp [wellOrderSucc, WellFounded.succ]
rw [dif_pos ⟨_, ha⟩]
exact WellFounded.min_le _ ha
lemma self_lt_wellOrderSucc {a b : α} (h : a < b) : a < wellOrderSucc a :=
IsWellFounded.wf.lt_succ ⟨b, h⟩
lemma le_of_lt_wellOrderSucc {a b : α} (h : a < wellOrderSucc b) : a ≤ b := by
by_contra!
simpa using lt_of_lt_of_le h (wellOrderSucc_le this)
/-- This property of an element `a : α` in a well-ordered type holds iff `a` is a
limit element, i.e. it is not a successor and it is not the smallest element of `α`. -/
class IsWellOrderLimitElement (a : α) : Prop where
not_bot : ∃ (b : α), b < a
not_succ (b : α) (hb : b < a) : ∃ (c : α), b < c ∧ c < a
end
variable (a : α) [ha : IsWellOrderLimitElement a]
lemma IsWellOrderLimitElement.neq_bot [OrderBot α] : a ≠ ⊥ := by
rintro rfl
obtain ⟨b, hb⟩ := ha.not_bot
simp at hb
lemma IsWellOrderLimitElement.bot_lt [OrderBot α] : ⊥ < a := by
obtain h|h := eq_or_lt_of_le (@bot_le _ _ _ a)
· exact (IsWellOrderLimitElement.neq_bot a h.symm).elim
· exact h
variable {a}
variable [IsWellOrder α (· < ·)]
lemma IsWellOrderLimitElement.wellOrderSucc_lt {b : α} (hb : b < a) :
wellOrderSucc b < a := by
obtain ⟨c, hc₁, hc₂⟩ := ha.not_succ b hb
exact lt_of_le_of_lt (wellOrderSucc_le hc₁) hc₂
lemma eq_bot_or_eq_succ_or_isWellOrderLimitElement [OrderBot α] (a : α) :
a = ⊥ ∨ (∃ b, a = wellOrderSucc b ∧ b < a) ∨ IsWellOrderLimitElement a := by
refine or_iff_not_imp_left.2 <| fun h₁ ↦ or_iff_not_imp_left.2 <| fun h₂ ↦ ?_
refine (IsWellOrderLimitElement.mk ⟨⊥, Ne.bot_lt h₁⟩ fun b hb ↦ ?_)
obtain rfl | h₃ := eq_or_lt_of_le (wellOrderSucc_le hb)
· exact (h₂ ⟨b, rfl, hb⟩).elim
· exact ⟨wellOrderSucc b, self_lt_wellOrderSucc hb, h₃⟩
lemma IsWellOrderLimitElement.neq_succ (a : α) (ha : a < wellOrderSucc a)
[IsWellOrderLimitElement (wellOrderSucc a)] : False := by
simpa using IsWellOrderLimitElement.wellOrderSucc_lt ha
@[simp]
lemma Nat.wellOrderSucc_eq (a : ℕ) : wellOrderSucc a = succ a :=
le_antisymm (wellOrderSucc_le (Nat.lt_succ_self a))
(Nat.succ_le.1 (self_lt_wellOrderSucc (Nat.lt_succ_self a)))
lemma Nat.not_isWellOrderLimitElement (a : ℕ) [IsWellOrderLimitElement a] : False := by
obtain _|a := a
· simpa using IsWellOrderLimitElement.neq_bot (0 : ℕ)
· simpa using IsWellOrderLimitElement.wellOrderSucc_lt (Nat.lt_succ_self a)
|
Order\Iterate.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Logic.Function.Iterate
import Mathlib.Order.Monotone.Basic
/-!
# Inequalities on iterates
In this file we prove some inequalities comparing `f^[n] x` and `g^[n] x` where `f` and `g` are
two self-maps that commute with each other.
Current selection of inequalities is motivated by formalization of the rotation number of
a circle homeomorphism.
-/
open Function
open Function (Commute)
namespace Monotone
variable {α : Type*} [Preorder α] {f : α → α} {x y : ℕ → α}
/-!
### Comparison of two sequences
If $f$ is a monotone function, then $∀ k, x_{k+1} ≤ f(x_k)$ implies that $x_k$ grows slower than
$f^k(x_0)$, and similarly for the reversed inequalities. If $x_k$ and $y_k$ are two sequences such
that $x_{k+1} ≤ f(x_k)$ and $y_{k+1} ≥ f(y_k)$ for all $k < n$, then $x_0 ≤ y_0$ implies
$x_n ≤ y_n$, see `Monotone.seq_le_seq`.
If some of the inequalities in this lemma are strict, then we have $x_n < y_n$. The rest of the
lemmas in this section formalize this fact for different inequalities made strict.
-/
theorem seq_le_seq (hf : Monotone f) (n : ℕ) (h₀ : x 0 ≤ y 0) (hx : ∀ k < n, x (k + 1) ≤ f (x k))
(hy : ∀ k < n, f (y k) ≤ y (k + 1)) : x n ≤ y n := by
induction' n with n ihn
· exact h₀
· refine (hx _ n.lt_succ_self).trans ((hf <| ihn ?_ ?_).trans (hy _ n.lt_succ_self))
· exact fun k hk => hx _ (hk.trans n.lt_succ_self)
· exact fun k hk => hy _ (hk.trans n.lt_succ_self)
theorem seq_pos_lt_seq_of_lt_of_le (hf : Monotone f) {n : ℕ} (hn : 0 < n) (h₀ : x 0 ≤ y 0)
(hx : ∀ k < n, x (k + 1) < f (x k)) (hy : ∀ k < n, f (y k) ≤ y (k + 1)) : x n < y n := by
induction' n with n ihn
· exact hn.false.elim
suffices x n ≤ y n from (hx n n.lt_succ_self).trans_le ((hf this).trans <| hy n n.lt_succ_self)
cases n with
| zero => exact h₀
| succ n =>
refine (ihn n.zero_lt_succ (fun k hk => hx _ ?_) fun k hk => hy _ ?_).le <;>
exact hk.trans n.succ.lt_succ_self
theorem seq_pos_lt_seq_of_le_of_lt (hf : Monotone f) {n : ℕ} (hn : 0 < n) (h₀ : x 0 ≤ y 0)
(hx : ∀ k < n, x (k + 1) ≤ f (x k)) (hy : ∀ k < n, f (y k) < y (k + 1)) : x n < y n :=
hf.dual.seq_pos_lt_seq_of_lt_of_le hn h₀ hy hx
theorem seq_lt_seq_of_lt_of_le (hf : Monotone f) (n : ℕ) (h₀ : x 0 < y 0)
(hx : ∀ k < n, x (k + 1) < f (x k)) (hy : ∀ k < n, f (y k) ≤ y (k + 1)) : x n < y n := by
cases n
exacts [h₀, hf.seq_pos_lt_seq_of_lt_of_le (Nat.zero_lt_succ _) h₀.le hx hy]
theorem seq_lt_seq_of_le_of_lt (hf : Monotone f) (n : ℕ) (h₀ : x 0 < y 0)
(hx : ∀ k < n, x (k + 1) ≤ f (x k)) (hy : ∀ k < n, f (y k) < y (k + 1)) : x n < y n :=
hf.dual.seq_lt_seq_of_lt_of_le n h₀ hy hx
/-!
### Iterates of two functions
In this section we compare the iterates of a monotone function `f : α → α` to iterates of any
function `g : β → β`. If `h : β → α` satisfies `h ∘ g ≤ f ∘ h`, then `h (g^[n] x)` grows slower
than `f^[n] (h x)`, and similarly for the reversed inequality.
Then we specialize these two lemmas to the case `β = α`, `h = id`.
-/
variable {β : Type*} {g : β → β} {h : β → α}
open Function
theorem le_iterate_comp_of_le (hf : Monotone f) (H : h ∘ g ≤ f ∘ h) (n : ℕ) :
h ∘ g^[n] ≤ f^[n] ∘ h := fun x => by
apply hf.seq_le_seq n <;> intros <;>
simp [iterate_succ', -iterate_succ, comp_apply, id_eq, le_refl]
case hx => exact H _
theorem iterate_comp_le_of_le (hf : Monotone f) (H : f ∘ h ≤ h ∘ g) (n : ℕ) :
f^[n] ∘ h ≤ h ∘ g^[n] :=
hf.dual.le_iterate_comp_of_le H n
/-- If `f ≤ g` and `f` is monotone, then `f^[n] ≤ g^[n]`. -/
theorem iterate_le_of_le {g : α → α} (hf : Monotone f) (h : f ≤ g) (n : ℕ) : f^[n] ≤ g^[n] :=
hf.iterate_comp_le_of_le h n
/-- If `f ≤ g` and `g` is monotone, then `f^[n] ≤ g^[n]`. -/
theorem le_iterate_of_le {g : α → α} (hg : Monotone g) (h : f ≤ g) (n : ℕ) : f^[n] ≤ g^[n] :=
hg.dual.iterate_le_of_le h n
end Monotone
/-!
### Comparison of iterations and the identity function
If $f(x) ≤ x$ for all $x$ (we express this as `f ≤ id` in the code), then the same is true for
any iterate of $f$, and similarly for the reversed inequality.
-/
namespace Function
section Preorder
variable {α : Type*} [Preorder α] {f : α → α}
/-- If $x ≤ f x$ for all $x$ (we write this as `id ≤ f`), then the same is true for any iterate
`f^[n]` of `f`. -/
theorem id_le_iterate_of_id_le (h : id ≤ f) (n : ℕ) : id ≤ f^[n] := by
simpa only [iterate_id] using monotone_id.iterate_le_of_le h n
theorem iterate_le_id_of_le_id (h : f ≤ id) (n : ℕ) : f^[n] ≤ id :=
@id_le_iterate_of_id_le αᵒᵈ _ f h n
theorem monotone_iterate_of_id_le (h : id ≤ f) : Monotone fun m => f^[m] :=
monotone_nat_of_le_succ fun n x => by
rw [iterate_succ_apply']
exact h _
theorem antitone_iterate_of_le_id (h : f ≤ id) : Antitone fun m => f^[m] := fun m n hmn =>
@monotone_iterate_of_id_le αᵒᵈ _ f h m n hmn
end Preorder
/-!
### Iterates of commuting functions
If `f` and `g` are monotone and commute, then `f x ≤ g x` implies `f^[n] x ≤ g^[n] x`, see
`Function.Commute.iterate_le_of_map_le`. We also prove two strict inequality versions of this lemma,
as well as `iff` versions.
-/
namespace Commute
section Preorder
variable {α : Type*} [Preorder α] {f g : α → α}
theorem iterate_le_of_map_le (h : Commute f g) (hf : Monotone f) (hg : Monotone g) {x}
(hx : f x ≤ g x) (n : ℕ) : f^[n] x ≤ g^[n] x := by
apply hf.seq_le_seq n
· rfl
· intros; rw [iterate_succ_apply']
· intros; simp [h.iterate_right _ _, hg.iterate _ hx]
theorem iterate_pos_lt_of_map_lt (h : Commute f g) (hf : Monotone f) (hg : StrictMono g) {x}
(hx : f x < g x) {n} (hn : 0 < n) : f^[n] x < g^[n] x := by
apply hf.seq_pos_lt_seq_of_le_of_lt hn
· rfl
· intros; rw [iterate_succ_apply']
· intros; simp [h.iterate_right _ _, hg.iterate _ hx]
theorem iterate_pos_lt_of_map_lt' (h : Commute f g) (hf : StrictMono f) (hg : Monotone g) {x}
(hx : f x < g x) {n} (hn : 0 < n) : f^[n] x < g^[n] x :=
@iterate_pos_lt_of_map_lt αᵒᵈ _ g f h.symm hg.dual hf.dual x hx n hn
end Preorder
variable {α : Type*} [LinearOrder α] {f g : α → α}
theorem iterate_pos_lt_iff_map_lt (h : Commute f g) (hf : Monotone f) (hg : StrictMono g) {x n}
(hn : 0 < n) : f^[n] x < g^[n] x ↔ f x < g x := by
rcases lt_trichotomy (f x) (g x) with (H | H | H)
· simp only [*, iterate_pos_lt_of_map_lt]
· simp only [*, h.iterate_eq_of_map_eq, lt_irrefl]
· simp only [lt_asymm H, lt_asymm (h.symm.iterate_pos_lt_of_map_lt' hg hf H hn)]
theorem iterate_pos_lt_iff_map_lt' (h : Commute f g) (hf : StrictMono f) (hg : Monotone g) {x n}
(hn : 0 < n) : f^[n] x < g^[n] x ↔ f x < g x :=
@iterate_pos_lt_iff_map_lt αᵒᵈ _ _ _ h.symm hg.dual hf.dual x n hn
theorem iterate_pos_le_iff_map_le (h : Commute f g) (hf : Monotone f) (hg : StrictMono g) {x n}
(hn : 0 < n) : f^[n] x ≤ g^[n] x ↔ f x ≤ g x := by
simpa only [not_lt] using not_congr (h.symm.iterate_pos_lt_iff_map_lt' hg hf hn)
theorem iterate_pos_le_iff_map_le' (h : Commute f g) (hf : StrictMono f) (hg : Monotone g) {x n}
(hn : 0 < n) : f^[n] x ≤ g^[n] x ↔ f x ≤ g x := by
simpa only [not_lt] using not_congr (h.symm.iterate_pos_lt_iff_map_lt hg hf hn)
theorem iterate_pos_eq_iff_map_eq (h : Commute f g) (hf : Monotone f) (hg : StrictMono g) {x n}
(hn : 0 < n) : f^[n] x = g^[n] x ↔ f x = g x := by
simp only [le_antisymm_iff, h.iterate_pos_le_iff_map_le hf hg hn,
h.symm.iterate_pos_le_iff_map_le' hg hf hn]
end Commute
end Function
namespace Monotone
variable {α : Type*} [Preorder α] {f : α → α} {x : α}
/-- If `f` is a monotone map and `x ≤ f x` at some point `x`, then the iterates `f^[n] x` form
a monotone sequence. -/
theorem monotone_iterate_of_le_map (hf : Monotone f) (hx : x ≤ f x) : Monotone fun n => f^[n] x :=
monotone_nat_of_le_succ fun n => by
rw [iterate_succ_apply]
exact hf.iterate n hx
/-- If `f` is a monotone map and `f x ≤ x` at some point `x`, then the iterates `f^[n] x` form
an antitone sequence. -/
theorem antitone_iterate_of_map_le (hf : Monotone f) (hx : f x ≤ x) : Antitone fun n => f^[n] x :=
hf.dual.monotone_iterate_of_le_map hx
end Monotone
namespace StrictMono
variable {α : Type*} [Preorder α] {f : α → α} {x : α}
/-- If `f` is a strictly monotone map and `x < f x` at some point `x`, then the iterates `f^[n] x`
form a strictly monotone sequence. -/
theorem strictMono_iterate_of_lt_map (hf : StrictMono f) (hx : x < f x) :
StrictMono fun n => f^[n] x :=
strictMono_nat_of_lt_succ fun n => by
rw [iterate_succ_apply]
exact hf.iterate n hx
/-- If `f` is a strictly antitone map and `f x < x` at some point `x`, then the iterates `f^[n] x`
form a strictly antitone sequence. -/
theorem strictAnti_iterate_of_map_lt (hf : StrictMono f) (hx : f x < x) :
StrictAnti fun n => f^[n] x :=
hf.dual.strictMono_iterate_of_lt_map hx
end StrictMono
|
Order\JordanHolder.lean | /-
Copyright (c) 2021 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Order.Lattice
import Mathlib.Data.List.Sort
import Mathlib.Logic.Equiv.Fin
import Mathlib.Logic.Equiv.Functor
import Mathlib.Data.Fintype.Card
import Mathlib.Order.RelSeries
/-!
# Jordan-Hölder Theorem
This file proves the Jordan Hölder theorem for a `JordanHolderLattice`, a class also defined in
this file. Examples of `JordanHolderLattice` include `Subgroup G` if `G` is a group, and
`Submodule R M` if `M` is an `R`-module. Using this approach the theorem need not be proved
separately for both groups and modules, the proof in this file can be applied to both.
## Main definitions
The main definitions in this file are `JordanHolderLattice` and `CompositionSeries`,
and the relation `Equivalent` on `CompositionSeries`
A `JordanHolderLattice` is the class for which the Jordan Hölder theorem is proved. A
Jordan Hölder lattice is a lattice equipped with a notion of maximality, `IsMaximal`, and a notion
of isomorphism of pairs `Iso`. In the example of subgroups of a group, `IsMaximal H K` means that
`H` is a maximal normal subgroup of `K`, and `Iso (H₁, K₁) (H₂, K₂)` means that the quotient
`H₁ / K₁` is isomorphic to the quotient `H₂ / K₂`. `Iso` must be symmetric and transitive and must
satisfy the second isomorphism theorem `Iso (H, H ⊔ K) (H ⊓ K, K)`.
A `CompositionSeries X` is a finite nonempty series of elements of the lattice `X` such that
each element is maximal inside the next. The length of a `CompositionSeries X` is
one less than the number of elements in the series. Note that there is no stipulation
that a series start from the bottom of the lattice and finish at the top.
For a composition series `s`, `s.last` is the largest element of the series,
and `s.head` is the least element.
Two `CompositionSeries X`, `s₁` and `s₂` are equivalent if there is a bijection
`e : Fin s₁.length ≃ Fin s₂.length` such that for any `i`,
`Iso (s₁ i, s₁ i.succ) (s₂ (e i), s₂ (e i.succ))`
## Main theorems
The main theorem is `CompositionSeries.jordan_holder`, which says that if two composition
series have the same least element and the same largest element,
then they are `Equivalent`.
## TODO
Provide instances of `JordanHolderLattice` for subgroups, and potentially for modular lattices.
It is not entirely clear how this should be done. Possibly there should be no global instances
of `JordanHolderLattice`, and the instances should only be defined locally in order to prove
the Jordan-Hölder theorem for modules/groups and the API should be transferred because many of the
theorems in this file will have stronger versions for modules. There will also need to be an API for
mapping composition series across homomorphisms. It is also probably possible to
provide an instance of `JordanHolderLattice` for any `ModularLattice`, and in this case the
Jordan-Hölder theorem will say that there is a well defined notion of length of a modular lattice.
However an instance of `JordanHolderLattice` for a modular lattice will not be able to contain
the correct notion of isomorphism for modules, so a separate instance for modules will still be
required and this will clash with the instance for modular lattices, and so at least one of these
instances should not be a global instance.
> [!NOTE]
> The previous paragraph indicates that the instance of `JordanHolderLattice` for submodules should
> be obtained via `ModularLattice`. This is not the case in `mathlib4`.
> See `JordanHolderModule.instJordanHolderLattice`.
-/
universe u
open Set RelSeries
/-- A `JordanHolderLattice` is the class for which the Jordan Hölder theorem is proved. A
Jordan Hölder lattice is a lattice equipped with a notion of maximality, `IsMaximal`, and a notion
of isomorphism of pairs `Iso`. In the example of subgroups of a group, `IsMaximal H K` means that
`H` is a maximal normal subgroup of `K`, and `Iso (H₁, K₁) (H₂, K₂)` means that the quotient
`H₁ / K₁` is isomorphic to the quotient `H₂ / K₂`. `Iso` must be symmetric and transitive and must
satisfy the second isomorphism theorem `Iso (H, H ⊔ K) (H ⊓ K, K)`.
Examples include `Subgroup G` if `G` is a group, and `Submodule R M` if `M` is an `R`-module.
-/
class JordanHolderLattice (X : Type u) [Lattice X] where
IsMaximal : X → X → Prop
lt_of_isMaximal : ∀ {x y}, IsMaximal x y → x < y
sup_eq_of_isMaximal : ∀ {x y z}, IsMaximal x z → IsMaximal y z → x ≠ y → x ⊔ y = z
isMaximal_inf_left_of_isMaximal_sup :
∀ {x y}, IsMaximal x (x ⊔ y) → IsMaximal y (x ⊔ y) → IsMaximal (x ⊓ y) x
Iso : X × X → X × X → Prop
iso_symm : ∀ {x y}, Iso x y → Iso y x
iso_trans : ∀ {x y z}, Iso x y → Iso y z → Iso x z
second_iso : ∀ {x y}, IsMaximal x (x ⊔ y) → Iso (x, x ⊔ y) (x ⊓ y, y)
namespace JordanHolderLattice
variable {X : Type u} [Lattice X] [JordanHolderLattice X]
theorem isMaximal_inf_right_of_isMaximal_sup {x y : X} (hxz : IsMaximal x (x ⊔ y))
(hyz : IsMaximal y (x ⊔ y)) : IsMaximal (x ⊓ y) y := by
rw [inf_comm]
rw [sup_comm] at hxz hyz
exact isMaximal_inf_left_of_isMaximal_sup hyz hxz
theorem isMaximal_of_eq_inf (x b : X) {a y : X} (ha : x ⊓ y = a) (hxy : x ≠ y) (hxb : IsMaximal x b)
(hyb : IsMaximal y b) : IsMaximal a y := by
have hb : x ⊔ y = b := sup_eq_of_isMaximal hxb hyb hxy
substs a b
exact isMaximal_inf_right_of_isMaximal_sup hxb hyb
theorem second_iso_of_eq {x y a b : X} (hm : IsMaximal x a) (ha : x ⊔ y = a) (hb : x ⊓ y = b) :
Iso (x, a) (b, y) := by substs a b; exact second_iso hm
theorem IsMaximal.iso_refl {x y : X} (h : IsMaximal x y) : Iso (x, y) (x, y) :=
second_iso_of_eq h (sup_eq_right.2 (le_of_lt (lt_of_isMaximal h)))
(inf_eq_left.2 (le_of_lt (lt_of_isMaximal h)))
end JordanHolderLattice
open JordanHolderLattice
attribute [symm] iso_symm
attribute [trans] iso_trans
/-- A `CompositionSeries X` is a finite nonempty series of elements of a
`JordanHolderLattice` such that each element is maximal inside the next. The length of a
`CompositionSeries X` is one less than the number of elements in the series.
Note that there is no stipulation that a series start from the bottom of the lattice and finish at
the top. For a composition series `s`, `s.last` is the largest element of the series,
and `s.head` is the least element.
-/
abbrev CompositionSeries (X : Type u) [Lattice X] [JordanHolderLattice X] : Type u :=
RelSeries (IsMaximal (X := X))
namespace CompositionSeries
variable {X : Type u} [Lattice X] [JordanHolderLattice X]
theorem lt_succ (s : CompositionSeries X) (i : Fin s.length) :
s (Fin.castSucc i) < s (Fin.succ i) :=
lt_of_isMaximal (s.step _)
protected theorem strictMono (s : CompositionSeries X) : StrictMono s :=
Fin.strictMono_iff_lt_succ.2 s.lt_succ
protected theorem injective (s : CompositionSeries X) : Function.Injective s :=
s.strictMono.injective
@[simp]
protected theorem inj (s : CompositionSeries X) {i j : Fin s.length.succ} : s i = s j ↔ i = j :=
s.injective.eq_iff
theorem total {s : CompositionSeries X} {x y : X} (hx : x ∈ s) (hy : y ∈ s) : x ≤ y ∨ y ≤ x := by
rcases Set.mem_range.1 hx with ⟨i, rfl⟩
rcases Set.mem_range.1 hy with ⟨j, rfl⟩
rw [s.strictMono.le_iff_le, s.strictMono.le_iff_le]
exact le_total i j
theorem toList_sorted (s : CompositionSeries X) : s.toList.Sorted (· < ·) :=
List.pairwise_iff_get.2 fun i j h => by
dsimp only [RelSeries.toList]
rw [List.get_ofFn, List.get_ofFn]
exact s.strictMono h
theorem toList_nodup (s : CompositionSeries X) : s.toList.Nodup :=
s.toList_sorted.nodup
/-- Two `CompositionSeries` are equal if they have the same elements. See also `ext_fun`. -/
@[ext]
theorem ext {s₁ s₂ : CompositionSeries X} (h : ∀ x, x ∈ s₁ ↔ x ∈ s₂) : s₁ = s₂ :=
toList_injective <|
List.eq_of_perm_of_sorted
(by
classical
exact List.perm_of_nodup_nodup_toFinset_eq s₁.toList_nodup s₂.toList_nodup
(Finset.ext <| by simpa only [List.mem_toFinset, RelSeries.mem_toList]))
s₁.toList_sorted s₂.toList_sorted
@[simp]
theorem le_last {s : CompositionSeries X} (i : Fin (s.length + 1)) : s i ≤ s.last :=
s.strictMono.monotone (Fin.le_last _)
theorem le_last_of_mem {s : CompositionSeries X} {x : X} (hx : x ∈ s) : x ≤ s.last :=
let ⟨_i, hi⟩ := Set.mem_range.2 hx
hi ▸ le_last _
@[simp]
theorem head_le {s : CompositionSeries X} (i : Fin (s.length + 1)) : s.head ≤ s i :=
s.strictMono.monotone (Fin.zero_le _)
theorem head_le_of_mem {s : CompositionSeries X} {x : X} (hx : x ∈ s) : s.head ≤ x :=
let ⟨_i, hi⟩ := Set.mem_range.2 hx
hi ▸ head_le _
theorem last_eraseLast_le (s : CompositionSeries X) : s.eraseLast.last ≤ s.last := by
simp [eraseLast, last, s.strictMono.le_iff_le, Fin.le_iff_val_le_val, tsub_le_self]
theorem mem_eraseLast_of_ne_of_mem {s : CompositionSeries X} {x : X}
(hx : x ≠ s.last) (hxs : x ∈ s) : x ∈ s.eraseLast := by
rcases hxs with ⟨i, rfl⟩
have hi : (i : ℕ) < (s.length - 1).succ := by
conv_rhs => rw [← Nat.succ_sub (length_pos_of_nontrivial ⟨_, ⟨i, rfl⟩, _, s.last_mem, hx⟩),
Nat.add_one_sub_one]
exact lt_of_le_of_ne (Nat.le_of_lt_succ i.2) (by simpa [last, s.inj, Fin.ext_iff] using hx)
refine ⟨Fin.castSucc (n := s.length + 1) i, ?_⟩
simp [Fin.ext_iff, Nat.mod_eq_of_lt hi]
theorem mem_eraseLast {s : CompositionSeries X} {x : X} (h : 0 < s.length) :
x ∈ s.eraseLast ↔ x ≠ s.last ∧ x ∈ s := by
simp only [RelSeries.mem_def, eraseLast]
constructor
· rintro ⟨i, rfl⟩
have hi : (i : ℕ) < s.length := by
conv_rhs => rw [← Nat.add_one_sub_one s.length, Nat.succ_sub h]
exact i.2
-- porting note (#10745): was `simp [top, Fin.ext_iff, ne_of_lt hi]`.
simp [last, Fin.ext_iff, ne_of_lt hi, -Set.mem_range, Set.mem_range_self]
· intro h
exact mem_eraseLast_of_ne_of_mem h.1 h.2
theorem lt_last_of_mem_eraseLast {s : CompositionSeries X} {x : X} (h : 0 < s.length)
(hx : x ∈ s.eraseLast) : x < s.last :=
lt_of_le_of_ne (le_last_of_mem ((mem_eraseLast h).1 hx).2) ((mem_eraseLast h).1 hx).1
theorem isMaximal_eraseLast_last {s : CompositionSeries X} (h : 0 < s.length) :
IsMaximal s.eraseLast.last s.last := by
have : s.length - 1 + 1 = s.length := by
conv_rhs => rw [← Nat.add_one_sub_one s.length]; rw [Nat.succ_sub h]
rw [last_eraseLast, last]
convert s.step ⟨s.length - 1, by omega⟩; ext; simp [this]
section FinLemmas
end FinLemmas
theorem eq_snoc_eraseLast {s : CompositionSeries X} (h : 0 < s.length) :
s = snoc (eraseLast s) s.last (isMaximal_eraseLast_last h) := by
ext x
simp only [mem_snoc, mem_eraseLast h, ne_eq]
by_cases h : x = s.last <;> simp [*, s.last_mem]
@[simp]
theorem snoc_eraseLast_last {s : CompositionSeries X} (h : IsMaximal s.eraseLast.last s.last) :
s.eraseLast.snoc s.last h = s :=
have h : 0 < s.length :=
Nat.pos_of_ne_zero (fun hs => ne_of_gt (lt_of_isMaximal h) <| by simp [last, Fin.ext_iff, hs])
(eq_snoc_eraseLast h).symm
/-- Two `CompositionSeries X`, `s₁` and `s₂` are equivalent if there is a bijection
`e : Fin s₁.length ≃ Fin s₂.length` such that for any `i`,
`Iso (s₁ i) (s₁ i.succ) (s₂ (e i), s₂ (e i.succ))` -/
def Equivalent (s₁ s₂ : CompositionSeries X) : Prop :=
∃ f : Fin s₁.length ≃ Fin s₂.length,
∀ i : Fin s₁.length, Iso (s₁ (Fin.castSucc i), s₁ i.succ)
(s₂ (Fin.castSucc (f i)), s₂ (Fin.succ (f i)))
namespace Equivalent
@[refl]
theorem refl (s : CompositionSeries X) : Equivalent s s :=
⟨Equiv.refl _, fun _ => (s.step _).iso_refl⟩
@[symm]
theorem symm {s₁ s₂ : CompositionSeries X} (h : Equivalent s₁ s₂) : Equivalent s₂ s₁ :=
⟨h.choose.symm, fun i => iso_symm (by simpa using h.choose_spec (h.choose.symm i))⟩
@[trans]
theorem trans {s₁ s₂ s₃ : CompositionSeries X} (h₁ : Equivalent s₁ s₂) (h₂ : Equivalent s₂ s₃) :
Equivalent s₁ s₃ :=
⟨h₁.choose.trans h₂.choose,
fun i => iso_trans (h₁.choose_spec i) (h₂.choose_spec (h₁.choose i))⟩
protected theorem smash {s₁ s₂ t₁ t₂ : CompositionSeries X}
(hs : s₁.last = s₂.head) (ht : t₁.last = t₂.head)
(h₁ : Equivalent s₁ t₁) (h₂ : Equivalent s₂ t₂) :
Equivalent (smash s₁ s₂ hs) (smash t₁ t₂ ht) :=
let e : Fin (s₁.length + s₂.length) ≃ Fin (t₁.length + t₂.length) :=
calc
Fin (s₁.length + s₂.length) ≃ (Fin s₁.length) ⊕ (Fin s₂.length) := finSumFinEquiv.symm
_ ≃ (Fin t₁.length) ⊕ (Fin t₂.length) := Equiv.sumCongr h₁.choose h₂.choose
_ ≃ Fin (t₁.length + t₂.length) := finSumFinEquiv
⟨e, by
intro i
refine Fin.addCases ?_ ?_ i
· intro i
simpa [-smash_toFun, e, smash_castAdd, smash_succ_castAdd] using h₁.choose_spec i
· intro i
simpa [-smash_toFun, e, smash_natAdd, smash_succ_natAdd] using h₂.choose_spec i⟩
protected theorem snoc {s₁ s₂ : CompositionSeries X} {x₁ x₂ : X} {hsat₁ : IsMaximal s₁.last x₁}
{hsat₂ : IsMaximal s₂.last x₂} (hequiv : Equivalent s₁ s₂)
(hlast : Iso (s₁.last, x₁) (s₂.last, x₂)) : Equivalent (s₁.snoc x₁ hsat₁) (s₂.snoc x₂ hsat₂) :=
let e : Fin s₁.length.succ ≃ Fin s₂.length.succ :=
calc
Fin (s₁.length + 1) ≃ Option (Fin s₁.length) := finSuccEquivLast
_ ≃ Option (Fin s₂.length) := Functor.mapEquiv Option hequiv.choose
_ ≃ Fin (s₂.length + 1) := finSuccEquivLast.symm
⟨e, fun i => by
refine Fin.lastCases ?_ ?_ i
· simpa [e, apply_last] using hlast
· intro i
simpa [e, Fin.succ_castSucc] using hequiv.choose_spec i⟩
theorem length_eq {s₁ s₂ : CompositionSeries X} (h : Equivalent s₁ s₂) : s₁.length = s₂.length := by
simpa using Fintype.card_congr h.choose
theorem snoc_snoc_swap {s : CompositionSeries X} {x₁ x₂ y₁ y₂ : X} {hsat₁ : IsMaximal s.last x₁}
{hsat₂ : IsMaximal s.last x₂} {hsaty₁ : IsMaximal (snoc s x₁ hsat₁).last y₁}
{hsaty₂ : IsMaximal (snoc s x₂ hsat₂).last y₂} (hr₁ : Iso (s.last, x₁) (x₂, y₂))
(hr₂ : Iso (x₁, y₁) (s.last, x₂)) :
Equivalent (snoc (snoc s x₁ hsat₁) y₁ hsaty₁) (snoc (snoc s x₂ hsat₂) y₂ hsaty₂) :=
let e : Fin (s.length + 1 + 1) ≃ Fin (s.length + 1 + 1) :=
Equiv.swap (Fin.last _) (Fin.castSucc (Fin.last _))
have h1 : ∀ {i : Fin s.length},
(Fin.castSucc (Fin.castSucc i)) ≠ (Fin.castSucc (Fin.last _)) := fun {_} =>
ne_of_lt (by simp [Fin.castSucc_lt_last])
have h2 : ∀ {i : Fin s.length},
(Fin.castSucc (Fin.castSucc i)) ≠ Fin.last _ := fun {_} =>
ne_of_lt (by simp [Fin.castSucc_lt_last])
⟨e, by
intro i
dsimp only [e]
refine Fin.lastCases ?_ (fun i => ?_) i
· erw [Equiv.swap_apply_left, snoc_castSucc,
show (snoc s x₁ hsat₁).toFun (Fin.last _) = x₁ from last_snoc _ _ _, Fin.succ_last,
show ((s.snoc x₁ hsat₁).snoc y₁ hsaty₁).toFun (Fin.last _) = y₁ from last_snoc _ _ _,
snoc_castSucc, snoc_castSucc, Fin.succ_castSucc, snoc_castSucc, Fin.succ_last,
show (s.snoc _ hsat₂).toFun (Fin.last _) = x₂ from last_snoc _ _ _]
exact hr₂
· refine Fin.lastCases ?_ (fun i => ?_) i
· erw [Equiv.swap_apply_right, snoc_castSucc, snoc_castSucc, snoc_castSucc,
Fin.succ_castSucc, snoc_castSucc, Fin.succ_last, last_snoc', last_snoc', last_snoc']
exact hr₁
· erw [Equiv.swap_apply_of_ne_of_ne h2 h1, snoc_castSucc, snoc_castSucc,
snoc_castSucc, snoc_castSucc, Fin.succ_castSucc, snoc_castSucc,
Fin.succ_castSucc, snoc_castSucc, snoc_castSucc, snoc_castSucc]
exact (s.step i).iso_refl⟩
end Equivalent
theorem length_eq_zero_of_head_eq_head_of_last_eq_last_of_length_eq_zero
{s₁ s₂ : CompositionSeries X} (hb : s₁.head = s₂.head)
(ht : s₁.last = s₂.last) (hs₁ : s₁.length = 0) : s₂.length = 0 := by
have : Fin.last s₂.length = (0 : Fin s₂.length.succ) :=
s₂.injective (hb.symm.trans ((congr_arg s₁ (Fin.ext (by simp [hs₁]))).trans ht)).symm
simpa [Fin.ext_iff]
theorem length_pos_of_head_eq_head_of_last_eq_last_of_length_pos {s₁ s₂ : CompositionSeries X}
(hb : s₁.head = s₂.head) (ht : s₁.last = s₂.last) : 0 < s₁.length → 0 < s₂.length :=
not_imp_not.1
(by
simpa only [pos_iff_ne_zero, ne_eq, Decidable.not_not] using
length_eq_zero_of_head_eq_head_of_last_eq_last_of_length_eq_zero hb.symm ht.symm)
theorem eq_of_head_eq_head_of_last_eq_last_of_length_eq_zero {s₁ s₂ : CompositionSeries X}
(hb : s₁.head = s₂.head) (ht : s₁.last = s₂.last) (hs₁0 : s₁.length = 0) : s₁ = s₂ := by
have : ∀ x, x ∈ s₁ ↔ x = s₁.last := fun x =>
⟨fun hx => subsingleton_of_length_eq_zero hs₁0 hx s₁.last_mem, fun hx => hx.symm ▸ s₁.last_mem⟩
have : ∀ x, x ∈ s₂ ↔ x = s₂.last := fun x =>
⟨fun hx =>
subsingleton_of_length_eq_zero
(length_eq_zero_of_head_eq_head_of_last_eq_last_of_length_eq_zero hb ht
hs₁0) hx s₂.last_mem,
fun hx => hx.symm ▸ s₂.last_mem⟩
ext
simp [*]
/-- Given a `CompositionSeries`, `s`, and an element `x`
such that `x` is maximal inside `s.last` there is a series, `t`,
such that `t.last = x`, `t.head = s.head`
and `snoc t s.last _` is equivalent to `s`. -/
theorem exists_last_eq_snoc_equivalent (s : CompositionSeries X) (x : X) (hm : IsMaximal x s.last)
(hb : s.head ≤ x) :
∃ t : CompositionSeries X,
t.head = s.head ∧ t.length + 1 = s.length ∧
∃ htx : t.last = x,
Equivalent s (snoc t s.last (show IsMaximal t.last _ from htx.symm ▸ hm)) := by
induction' hn : s.length with n ih generalizing s x
· exact
(ne_of_gt (lt_of_le_of_lt hb (lt_of_isMaximal hm))
(subsingleton_of_length_eq_zero hn s.last_mem s.head_mem)).elim
· have h0s : 0 < s.length := hn.symm ▸ Nat.succ_pos _
by_cases hetx : s.eraseLast.last = x
· use s.eraseLast
simp [← hetx, hn]
-- Porting note: `rfl` is required.
rfl
· have imxs : IsMaximal (x ⊓ s.eraseLast.last) s.eraseLast.last :=
isMaximal_of_eq_inf x s.last rfl (Ne.symm hetx) hm (isMaximal_eraseLast_last h0s)
have := ih _ _ imxs (le_inf (by simpa) (le_last_of_mem s.eraseLast.head_mem)) (by simp [hn])
rcases this with ⟨t, htb, htl, htt, hteqv⟩
have hmtx : IsMaximal t.last x :=
isMaximal_of_eq_inf s.eraseLast.last s.last (by rw [inf_comm, htt]) hetx
(isMaximal_eraseLast_last h0s) hm
use snoc t x hmtx
refine ⟨by simp [htb], by simp [htl], by simp, ?_⟩
have : s.Equivalent ((snoc t s.eraseLast.last <| show IsMaximal t.last _ from
htt.symm ▸ imxs).snoc s.last
(by simpa using isMaximal_eraseLast_last h0s)) := by
conv_lhs => rw [eq_snoc_eraseLast h0s]
exact Equivalent.snoc hteqv (by simpa using (isMaximal_eraseLast_last h0s).iso_refl)
refine this.trans <| Equivalent.snoc_snoc_swap
(iso_symm
(second_iso_of_eq hm
(sup_eq_of_isMaximal hm (isMaximal_eraseLast_last h0s) (Ne.symm hetx)) htt.symm))
(second_iso_of_eq (isMaximal_eraseLast_last h0s)
(sup_eq_of_isMaximal (isMaximal_eraseLast_last h0s) hm hetx) (by rw [inf_comm, htt]))
/-- The **Jordan-Hölder** theorem, stated for any `JordanHolderLattice`.
If two composition series start and finish at the same place, they are equivalent. -/
theorem jordan_holder (s₁ s₂ : CompositionSeries X)
(hb : s₁.head = s₂.head) (ht : s₁.last = s₂.last) :
Equivalent s₁ s₂ := by
induction' hle : s₁.length with n ih generalizing s₁ s₂
· rw [eq_of_head_eq_head_of_last_eq_last_of_length_eq_zero hb ht hle]
· have h0s₂ : 0 < s₂.length :=
length_pos_of_head_eq_head_of_last_eq_last_of_length_pos hb ht (hle.symm ▸ Nat.succ_pos _)
rcases exists_last_eq_snoc_equivalent s₁ s₂.eraseLast.last
(ht.symm ▸ isMaximal_eraseLast_last h0s₂)
(hb.symm ▸ s₂.head_eraseLast ▸ head_le_of_mem (last_mem _)) with
⟨t, htb, htl, htt, hteq⟩
have := ih t s₂.eraseLast (by simp [htb, ← hb]) htt (Nat.succ_inj'.1 (htl.trans hle))
refine hteq.trans ?_
conv_rhs => rw [eq_snoc_eraseLast h0s₂]
simp only [ht]
exact Equivalent.snoc this (by simpa [htt] using (isMaximal_eraseLast_last h0s₂).iso_refl)
end CompositionSeries
|
Order\KonigLemma.lean | /-
Copyright (c) 2024 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.Order.Atoms.Finite
import Mathlib.Order.Grade
/-!
# Kőnig's infinity lemma
Kőnig's infinity lemma is most often stated as a graph theory result:
every infinite, locally finite connected graph contains an infinite path.
It has links to computability and proof theory, and it has a number of formulations.
In practice, most applications are not to an abstract graph,
but to a concrete collection of objects that are organized in a graph-like way,
often where the graph is a rooted tree representing a graded order.
In fact, the lemma is most easily stated and proved
in terms of covers in a strongly atomic order rather than a graph;
in this setting, the proof is almost trivial.
A common formulation of Kőnig's lemma is in terms of directed systems,
with the grading explicitly represented using an `ℕ`-indexed family of types,
which we also provide in this module.
This is a specialization of the much more general `nonempty_sections_of_finite_cofiltered_system`,
which goes through topology and category theory,
but here it is stated and proved independently with much fewer dependencies.
We leave the explicitly graph-theoretic version of the statement as TODO.
## Main Results
* `exists_seq_covby_of_forall_covby_finite` : Kőnig's lemma for strongly atomic orders.
* `exists_orderEmbedding_covby_of_forall_covby_finite` : Kőnig's lemma, where the sequence
is given as an `OrderEmbedding` instead of a function.
* `exists_orderEmbedding_covby_of_forall_covby_finite_of_bot` : Kőnig's lemma where the sequence
starts at the minimum of an infinite type.
* `exist_seq_forall_proj_of_forall_finite` : Kőnig's lemma for inverse systems,
proved using the above applied to an order on a sigma-type `(i : ℕ) × α i`.
## TODO
Formulate the lemma as a statement about graphs.
-/
open Set
section Sequence
variable {α : Type*} [PartialOrder α] [IsStronglyAtomic α] {a b : α}
/-- **Kőnig's infinity lemma** : if each element in a strongly atomic order
is covered by only finitely many others, and `b` is an element with infinitely many things above it,
then there is a sequence starting with `b` in which each element is covered by the next. -/
theorem exists_seq_covby_of_forall_covby_finite (hfin : ∀ (a : α), {x | a ⋖ x}.Finite)
(hb : (Ici b).Infinite) : ∃ f : ℕ → α, f 0 = b ∧ ∀ i, f i ⋖ f (i+1) :=
let h := fun a : {a : α // (Ici a).Infinite} ↦
exists_covby_infinite_Ici_of_infinite_Ici a.2 (hfin a)
let ks : ℕ → {a : α // (Ici a).Infinite} := Nat.rec ⟨b, hb⟩ fun _ a ↦ ⟨_, (h a).choose_spec.2⟩
⟨fun i ↦ (ks i).1, by simp [ks], fun i ↦ by simpa using (h (ks i)).choose_spec.1⟩
/-- The sequence given by Kőnig's lemma as an order embedding -/
theorem exists_orderEmbedding_covby_of_forall_covby_finite (hfin : ∀ (a : α), {x | a ⋖ x}.Finite)
(hb : (Ici b).Infinite) : ∃ f : ℕ ↪o α, f 0 = b ∧ ∀ i, f i ⋖ f (i+1) := by
obtain ⟨f, hf⟩ := exists_seq_covby_of_forall_covby_finite hfin hb
exact ⟨OrderEmbedding.ofStrictMono f (strictMono_nat_of_lt_succ (fun i ↦ (hf.2 i).lt)), hf⟩
/-- A version of Kőnig's lemma where the sequence starts at the minimum of an infinite order. -/
theorem exists_orderEmbedding_covby_of_forall_covby_finite_of_bot [OrderBot α] [Infinite α]
(hfin : ∀ (a : α), {x | a ⋖ x}.Finite) : ∃ f : ℕ ↪o α, f 0 = ⊥ ∧ ∀ i, f i ⋖ f (i+1) :=
exists_orderEmbedding_covby_of_forall_covby_finite hfin (by simpa using infinite_univ)
theorem GradeMinOrder.exists_nat_orderEmbedding_of_forall_covby_finite
[GradeMinOrder ℕ α] [OrderBot α] [Infinite α] (hfin : ∀ (a : α), {x | a ⋖ x}.Finite) :
∃ f : ℕ ↪o α, f 0 = ⊥ ∧ (∀ i, f i ⋖ f (i+1)) ∧ ∀ i, grade ℕ (f i) = i := by
obtain ⟨f, h0, hf⟩ := exists_orderEmbedding_covby_of_forall_covby_finite_of_bot hfin
refine ⟨f, h0, hf, fun i ↦ ?_⟩
induction' i with i ih; simp [h0]
simpa [Nat.covBy_iff_succ_eq, ih, eq_comm] using CovBy.grade ℕ <| hf i
end Sequence
section Graded
/-- A formulation of Kőnig's infinity lemma, useful in applications.
Given a sequence `α 0, α 1, ...` of nonempty types with `α 0` finite,
and a well-behaved family of projections `π : α j → α i` for all `i ≤ j`,
if each term in each `α i` is the projection of only finitely many terms in `α (i+1)`,
then we can find a sequence `(f 0 : α 0), (f 1 : α 1), ...`
where `f i` is the projection of `f j` for all `i ≤ j`.
In a typical application, the `α i` are function types with increasingly large domains,
and `π hij (f : α j)` is the restriction of the domain of `f` to that of `α i`.
In this case, the sequence given by the lemma is essentially a function whose domain
is the limit of the `α i`.
See also `nonempty_sections_of_finite_cofiltered_system`. -/
theorem exists_seq_forall_proj_of_forall_finite {α : ℕ → Type*} [Finite (α 0)] [∀ i, Nonempty (α i)]
(π : {i j : ℕ} → (hij : i ≤ j) → α j → α i)
(π_refl : ∀ ⦃i⦄ (a : α i), π rfl.le a = a)
(π_trans : ∀ ⦃i j k⦄ (hij : i ≤ j) (hjk : j ≤ k) a, π hij (π hjk a) = π (hij.trans hjk) a)
(hfin : ∀ i a, {b : α (i+1) | π (Nat.le_add_right i 1) b = a}.Finite) :
∃ f : (i : ℕ) → α i, ∀ ⦃i j⦄ (hij : i ≤ j), π hij (f j) = f i := by
set αs := (i : ℕ) × α i
let _ : PartialOrder αs := {
le := fun a b ↦ ∃ h, π h b.2 = a.2
le_refl := fun a ↦ ⟨rfl.le, π_refl _⟩
le_trans := fun _ _ c h h' ↦ ⟨h.1.trans h'.1, by rw [← π_trans h.1 h'.1 c.2, h'.2, h.2]⟩
le_antisymm := by
rintro ⟨i, a⟩ ⟨j, b⟩ ⟨hij : i ≤ j, hab : π hij b = a⟩ ⟨hji : j ≤ i, hba : π hji a = b⟩
obtain rfl := hij.antisymm hji
rw [show a = b by rwa [π_refl] at hba] }
have hcovby : ∀ {a b : αs}, a ⋖ b ↔ a ≤ b ∧ a.1 + 1 = b.1 := by
simp only [covBy_iff_lt_and_eq_or_eq, lt_iff_le_and_ne, ne_eq, Sigma.forall, and_assoc,
and_congr_right_iff, or_iff_not_imp_left]
rintro i a j b ⟨h : i ≤ j, rfl : π h b = a⟩
refine ⟨fun ⟨hne, h'⟩ ↦ ?_, ?_⟩
· have hle' : i + 1 ≤ j := h.lt_of_ne <| by rintro rfl; simp [π_refl] at hne
exact congr_arg Sigma.fst <| h' (i+1) (π hle' b) ⟨by simp, by rw [π_trans]⟩ ⟨hle', by simp⟩
(fun h ↦ by apply_fun Sigma.fst at h; simp at h)
rintro rfl
refine ⟨fun h ↦ by apply_fun Sigma.fst at h; simp at h, ?_⟩
rintro j c ⟨hij : i ≤ j, hcb : π _ c = π _ b⟩ ⟨hji : j ≤ i + 1, rfl : π hji b = c⟩ hne
replace hne := show i ≠ j by rintro rfl; contradiction
obtain rfl := hji.antisymm (hij.lt_of_ne hne)
rw [π_refl]
have : IsStronglyAtomic αs := by
simp_rw [isStronglyAtomic_iff, lt_iff_le_and_ne, hcovby]
rintro ⟨i, a⟩ ⟨j, b⟩ ⟨⟨hij : i ≤ j, h2 : π hij b = a⟩, hne⟩
have hle : i + 1 ≤ j := hij.lt_of_ne (by rintro rfl; simp [← h2, π_refl] at hne)
exact ⟨⟨_, π hle b⟩, ⟨⟨by simp, by rw [π_trans, ← h2]⟩, by simp⟩, ⟨hle, by simp⟩⟩
obtain ⟨a₀, ha₀, ha₀inf⟩ : ∃ a₀ : αs, a₀.1 = 0 ∧ (Ici a₀).Infinite := by
obtain ⟨a₀, ha₀⟩ := Finite.exists_infinite_fiber (fun (a : αs) ↦ π (zero_le a.1) a.2)
refine ⟨⟨0, a₀⟩, rfl, (infinite_coe_iff.1 ha₀).mono ?_⟩
simp only [subset_def, mem_preimage, mem_singleton_iff, mem_Ici, Sigma.forall]
exact fun i x h ↦ ⟨zero_le i, h⟩
have hfin : ∀ (a : αs), {x | a ⋖ x}.Finite := by
refine fun ⟨i,a⟩ ↦ ((hfin i a).image (fun b ↦ ⟨_,b⟩)).subset ?_
simp only [hcovby, subset_def, mem_setOf_eq, mem_image, and_imp, Sigma.forall]
exact fun j b ⟨_, _⟩ hj ↦ ⟨π hj.le b, by rwa [π_trans], by cases hj; rw [π_refl]⟩
obtain ⟨f, hf0, hf⟩ := exists_orderEmbedding_covby_of_forall_covby_finite hfin ha₀inf
have hr : ∀ i, (f i).1 = i :=
Nat.rec (by rw [hf0, ha₀]) (fun i ih ↦ by rw [← (hcovby.1 (hf i)).2, ih])
refine ⟨fun i ↦ by rw [← hr i]; exact (f i).2, fun i j hij ↦ ?_⟩
convert (f.monotone hij).2 <;>
simp [hr]
end Graded
|
Order\KrullDimension.lean | /-
Copyright (c) 2023 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Fangming Li
-/
import Mathlib.Order.RelSeries
import Mathlib.Order.WithBot
import Mathlib.Data.Nat.Lattice
/-!
# Krull dimension of a preordered set
If `α` is a preordered set, then `krullDim α` is defined to be `sup {n | a₀ < a₁ < ... < aₙ}`.
In case that `α` is empty, then its Krull dimension is defined to be negative infinity; if the
length of all series `a₀ < a₁ < ... < aₙ` is unbounded, then its Krull dimension is defined to
be positive infinity.
For `a : α`, its height is defined to be the krull dimension of the subset `(-∞, a]` while its
coheight is defined to be the krull dimension of `[a, +∞)`.
## Implementation notes
Krull dimensions are defined to take value in `WithBot (WithTop ℕ)` so that `(-∞) + (+∞)` is
also negative infinity. This is because we want Krull dimensions to be additive with respect
to product of varieties so that `-∞` being the Krull dimension of empty variety is equal to
sum of `-∞` and the Krull dimension of any other varieties.
We could generalize the notion of Krull dimension to an arbitrary binary relation; many results
in this file would generalize as well. But we don't think it would be useful, so we only define
Krull dimension of a preorder.
-/
section definitions
variable (α : Type*) [Preorder α]
/--
The **Krull dimension** of a preorder `α` is the supremum of the rightmost index of all relation
series of `α` order by `<`. If there is no series `a₀ < a₁ < ... < aₙ` in `α`, then its Krull
dimension is defined to be negative infinity; if the length of all series `a₀ < a₁ < ... < aₙ` is
unbounded, its Krull dimension is defined to be positive infinity.
-/
noncomputable def krullDim : WithBot (WithTop ℕ) :=
⨆ (p : LTSeries α), p.length
/--
Height of an element `a` of a preordered set `α` is the Krull dimension of the subset `(-∞, a]`
-/
noncomputable def height (a : α) : WithBot (WithTop ℕ) := krullDim (Set.Iic a)
/--
Coheight of an element `a` of a pre-ordered set `α` is the Krull dimension of the subset `[a, +∞)`
-/
noncomputable def coheight (a : α) : WithBot (WithTop ℕ) := krullDim (Set.Ici a)
end definitions
section krullDim
variable {α β : Type*}
variable [Preorder α] [Preorder β]
lemma krullDim_nonneg_of_nonempty [Nonempty α] : 0 ≤ krullDim α :=
le_sSup ⟨⟨0, fun _ ↦ @Nonempty.some α inferInstance, fun f ↦ f.elim0⟩, rfl⟩
lemma krullDim_eq_bot_of_isEmpty [IsEmpty α] : krullDim α = ⊥ := WithBot.ciSup_empty _
lemma krullDim_eq_top_of_infiniteDimensionalOrder [InfiniteDimensionalOrder α] :
krullDim α = ⊤ :=
le_antisymm le_top <| le_iSup_iff.mpr <| fun m hm ↦ match m, hm with
| ⊥, hm => False.elim <| by
haveI : Inhabited α := ⟨LTSeries.withLength _ 0 0⟩
exact not_le_of_lt (WithBot.bot_lt_coe _ : ⊥ < (0 : WithBot (WithTop ℕ))) <| hm default
| some ⊤, _ => le_refl _
| some (some m), hm => by
refine (not_lt_of_le (hm (LTSeries.withLength _ (m + 1))) ?_).elim
erw [WithBot.coe_lt_coe, WithTop.coe_lt_coe]
simp
lemma krullDim_le_of_strictMono (f : α → β) (hf : StrictMono f) : krullDim α ≤ krullDim β :=
iSup_le <| fun p ↦ le_sSup ⟨p.map f hf, rfl⟩
lemma height_mono {a b : α} (h : a ≤ b) : height α a ≤ height α b :=
krullDim_le_of_strictMono (fun x ↦ ⟨x, le_trans x.2 h⟩) <| fun _ _ ↦ id
lemma krullDim_eq_length_of_finiteDimensionalOrder [FiniteDimensionalOrder α] :
krullDim α = (LTSeries.longestOf α).length :=
le_antisymm
(iSup_le <| fun _ ↦ WithBot.coe_le_coe.mpr <| WithTop.coe_le_coe.mpr <|
RelSeries.length_le_length_longestOf _ _) <|
le_iSup (fun (i : LTSeries _) ↦ (i.length : WithBot (WithTop ℕ))) <| LTSeries.longestOf _
lemma krullDim_eq_zero_of_unique [Unique α] : krullDim α = 0 := by
rw [krullDim_eq_length_of_finiteDimensionalOrder (α := α), Nat.cast_eq_zero]
refine (LTSeries.longestOf_len_unique (default : LTSeries α) fun q ↦ show _ ≤ 0 from ?_).symm
by_contra r
exact ne_of_lt (q.step ⟨0, not_le.mp r⟩) <| Subsingleton.elim _ _
lemma krullDim_le_of_strictComono_and_surj
(f : α → β) (hf : ∀ ⦃a b⦄, f a < f b → a < b) (hf' : Function.Surjective f) :
krullDim β ≤ krullDim α :=
iSup_le fun p ↦ le_sSup ⟨p.comap _ hf hf', rfl⟩
lemma krullDim_eq_of_orderIso (f : α ≃o β) : krullDim α = krullDim β :=
le_antisymm (krullDim_le_of_strictMono _ f.strictMono) <|
krullDim_le_of_strictMono _ f.symm.strictMono
lemma krullDim_eq_iSup_height : krullDim α = ⨆ (a : α), height α a :=
le_antisymm
(iSup_le fun i ↦ le_iSup_of_le (i ⟨i.length, lt_add_one _⟩) <|
le_sSup ⟨⟨_, fun m ↦ ⟨i m, i.strictMono.monotone <| show m.1 ≤ i.length by omega⟩,
i.step⟩, rfl⟩) <|
iSup_le fun a ↦ krullDim_le_of_strictMono Subtype.val fun _ _ h ↦ h
@[simp] lemma krullDim_orderDual : krullDim αᵒᵈ = krullDim α :=
le_antisymm (iSup_le fun i ↦ le_sSup ⟨i.reverse, rfl⟩) <|
iSup_le fun i ↦ le_sSup ⟨i.reverse, rfl⟩
end krullDim
|
Order\Lattice.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (least upper bound, or `sup`) or meet (greatest
lower bound, or `inf`) operations. Lattices are posets that are both join-semilattices and
meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `⊔` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `⊓` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `⊔` and `⊓` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a ⊔ b`: the supremum or join of `a` and `b`
* `a ⊓ b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
/-- See if the term is `a ⊂ b` and the goal is `a ⊆ b`. -/
@[gcongr_forward] def exactSubsetOfSSubset : Mathlib.Tactic.GCongr.ForwardExt where
eval h goal := do goal.assignIfDefeq (← Lean.Meta.mkAppM ``subset_of_ssubset #[h])
universe u v w
variable {α : Type u} {β : Type v}
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`⊔` which is the least element larger than both factors. -/
class SemilatticeSup (α : Type u) extends Sup α, PartialOrder α where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : ∀ a b : α, a ≤ a ⊔ b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : ∀ a b : α, b ≤ a ⊔ b
/-- The supremum is the *least* upper bound -/
protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {α : Type*} [Sup α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a)
(sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) :
SemilatticeSup α where
sup := (· ⊔ ·)
le a b := a ⊔ b = b
le_refl := sup_idem
le_trans a b c hab hbc := by dsimp; rw [← hbc, ← sup_assoc, hab]
le_antisymm a b hab hba := by rwa [← hba, sup_comm]
le_sup_left a b := by dsimp; rw [← sup_assoc, sup_idem]
le_sup_right a b := by dsimp; rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by dsimp; rwa [sup_assoc, hbc]
instance OrderDual.instSup (α : Type*) [Inf α] : Sup αᵒᵈ :=
⟨((· ⊓ ·) : α → α → α)⟩
instance OrderDual.instInf (α : Type*) [Sup α] : Inf αᵒᵈ :=
⟨((· ⊔ ·) : α → α → α)⟩
section SemilatticeSup
variable [SemilatticeSup α] {a b c d : α}
@[simp]
theorem le_sup_left : a ≤ a ⊔ b :=
SemilatticeSup.le_sup_left a b
@[deprecated (since := "2024-06-04")] alias le_sup_left' := le_sup_left
@[simp]
theorem le_sup_right : b ≤ a ⊔ b :=
SemilatticeSup.le_sup_right a b
@[deprecated (since := "2024-06-04")] alias le_sup_right' := le_sup_right
theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b :=
le_trans h le_sup_left
theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b :=
le_trans h le_sup_right
theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b :=
h.trans_le le_sup_left
theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b :=
h.trans_le le_sup_right
theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c :=
SemilatticeSup.sup_le a b c
@[simp]
theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c :=
⟨fun h : a ⊔ b ≤ c => ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩,
fun ⟨h₁, h₂⟩ => sup_le h₁ h₂⟩
@[simp]
theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a :=
eq_comm.trans sup_eq_left
@[simp]
theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b :=
eq_comm.trans sup_eq_right
alias ⟨_, sup_of_le_left⟩ := sup_eq_left
alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a :=
le_sup_left.lt_iff_ne.trans <| not_congr left_eq_sup
@[simp]
theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b :=
le_sup_right.lt_iff_ne.trans <| not_congr right_eq_sup
theorem left_or_right_lt_sup (h : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
theorem le_iff_exists_sup : a ≤ b ↔ ∃ c, b = a ⊔ c := by
constructor
· intro h
exact ⟨b, (sup_eq_right.mpr h).symm⟩
· rintro ⟨c, rfl : _ = _ ⊔ _⟩
exact le_sup_left
@[gcongr]
theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d :=
sup_le (le_sup_of_le_left h₁) (le_sup_of_le_right h₂)
@[gcongr]
theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b :=
sup_le_sup le_rfl h₁
@[gcongr]
theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c :=
sup_le_sup h₁ le_rfl
theorem sup_idem (a : α) : a ⊔ a = a := by simp
instance : Std.IdempotentOp (α := α) (· ⊔ ·) := ⟨sup_idem⟩
theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by apply le_antisymm <;> simp
instance : Std.Commutative (α := α) (· ⊔ ·) := ⟨sup_comm⟩
theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) :=
eq_of_forall_ge_iff fun x => by simp only [sup_le_iff]; rw [and_assoc]
instance : Std.Associative (α := α) (· ⊔ ·) := ⟨sup_assoc⟩
theorem sup_left_right_swap (a b c : α) : a ⊔ b ⊔ c = c ⊔ b ⊔ a := by
rw [sup_comm, sup_comm a, sup_assoc]
theorem sup_left_idem (a b : α) : a ⊔ (a ⊔ b) = a ⊔ b := by simp
theorem sup_right_idem (a b : α) : a ⊔ b ⊔ b = a ⊔ b := by simp
theorem sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by
rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a]
theorem sup_right_comm (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ b := by
rw [sup_assoc, sup_assoc, sup_comm b]
theorem sup_sup_sup_comm (a b c d : α) : a ⊔ b ⊔ (c ⊔ d) = a ⊔ c ⊔ (b ⊔ d) := by
rw [sup_assoc, sup_left_comm b, ← sup_assoc]
theorem sup_sup_distrib_left (a b c : α) : a ⊔ (b ⊔ c) = a ⊔ b ⊔ (a ⊔ c) := by
rw [sup_sup_sup_comm, sup_idem]
theorem sup_sup_distrib_right (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ (b ⊔ c) := by
rw [sup_sup_sup_comm, sup_idem]
theorem sup_congr_left (hb : b ≤ a ⊔ c) (hc : c ≤ a ⊔ b) : a ⊔ b = a ⊔ c :=
(sup_le le_sup_left hb).antisymm <| sup_le le_sup_left hc
theorem sup_congr_right (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ⊔ c = b ⊔ c :=
(sup_le ha le_sup_right).antisymm <| sup_le hb le_sup_right
theorem sup_eq_sup_iff_left : a ⊔ b = a ⊔ c ↔ b ≤ a ⊔ c ∧ c ≤ a ⊔ b :=
⟨fun h => ⟨h ▸ le_sup_right, h.symm ▸ le_sup_right⟩, fun h => sup_congr_left h.1 h.2⟩
theorem sup_eq_sup_iff_right : a ⊔ c = b ⊔ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c :=
⟨fun h => ⟨h ▸ le_sup_left, h.symm ▸ le_sup_left⟩, fun h => sup_congr_right h.1 h.2⟩
theorem Ne.lt_sup_or_lt_sup (hab : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
/-- If `f` is monotone, `g` is antitone, and `f ≤ g`, then for all `a`, `b` we have `f a ≤ g b`. -/
theorem Monotone.forall_le_of_antitone {β : Type*} [Preorder β] {f g : α → β} (hf : Monotone f)
(hg : Antitone g) (h : f ≤ g) (m n : α) : f m ≤ g n :=
calc
f m ≤ f (m ⊔ n) := hf le_sup_left
_ ≤ g (m ⊔ n) := h _
_ ≤ g n := hg le_sup_right
theorem SemilatticeSup.ext_sup {α} {A B : SemilatticeSup α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y)
(x y : α) :
(haveI := A; x ⊔ y) = x ⊔ y :=
eq_of_forall_ge_iff fun c => by simp only [sup_le_iff]; rw [← H, @sup_le_iff α A, H, H]
theorem SemilatticeSup.ext {α} {A B : SemilatticeSup α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
theorem ite_le_sup (s s' : α) (P : Prop) [Decidable P] : ite P s s' ≤ s ⊔ s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`⊓` which is the greatest element smaller than both factors. -/
class SemilatticeInf (α : Type u) extends Inf α, PartialOrder α where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : ∀ a b : α, a ⊓ b ≤ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : ∀ a b : α, a ⊓ b ≤ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ b ⊓ c
instance OrderDual.instSemilatticeSup (α) [SemilatticeInf α] : SemilatticeSup αᵒᵈ where
__ := inferInstanceAs (PartialOrder αᵒᵈ)
__ := inferInstanceAs (Sup αᵒᵈ)
le_sup_left := @SemilatticeInf.inf_le_left α _
le_sup_right := @SemilatticeInf.inf_le_right α _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf α _ _ _ _ hca hcb
instance OrderDual.instSemilatticeInf (α) [SemilatticeSup α] : SemilatticeInf αᵒᵈ where
__ := inferInstanceAs (PartialOrder αᵒᵈ)
__ := inferInstanceAs (Inf αᵒᵈ)
inf_le_left := @le_sup_left α _
inf_le_right := @le_sup_right α _
le_inf := fun _ _ _ hca hcb => @sup_le α _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (α : Type*) [H : SemilatticeSup α] :
OrderDual.instSemilatticeSup αᵒᵈ = H :=
SemilatticeSup.ext fun _ _ => Iff.rfl
section SemilatticeInf
variable [SemilatticeInf α] {a b c d : α}
@[simp]
theorem inf_le_left : a ⊓ b ≤ a :=
SemilatticeInf.inf_le_left a b
@[deprecated (since := "2024-06-04")] alias inf_le_left' := inf_le_left
@[simp]
theorem inf_le_right : a ⊓ b ≤ b :=
SemilatticeInf.inf_le_right a b
@[deprecated (since := "2024-06-04")] alias inf_le_right' := inf_le_right
theorem le_inf : a ≤ b → a ≤ c → a ≤ b ⊓ c :=
SemilatticeInf.le_inf a b c
theorem inf_le_of_left_le (h : a ≤ c) : a ⊓ b ≤ c :=
le_trans inf_le_left h
theorem inf_le_of_right_le (h : b ≤ c) : a ⊓ b ≤ c :=
le_trans inf_le_right h
theorem inf_lt_of_left_lt (h : a < c) : a ⊓ b < c :=
lt_of_le_of_lt inf_le_left h
theorem inf_lt_of_right_lt (h : b < c) : a ⊓ b < c :=
lt_of_le_of_lt inf_le_right h
@[simp]
theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c :=
@sup_le_iff αᵒᵈ _ _ _ _
@[simp]
theorem inf_eq_left : a ⊓ b = a ↔ a ≤ b :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem inf_eq_right : a ⊓ b = b ↔ b ≤ a :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem left_eq_inf : a = a ⊓ b ↔ a ≤ b :=
eq_comm.trans inf_eq_left
@[simp]
theorem right_eq_inf : b = a ⊓ b ↔ b ≤ a :=
eq_comm.trans inf_eq_right
alias ⟨le_of_inf_eq, inf_of_le_left⟩ := inf_eq_left
alias ⟨_, inf_of_le_right⟩ := inf_eq_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a ⊓ b < a ↔ ¬a ≤ b :=
@left_lt_sup αᵒᵈ _ _ _
@[simp]
theorem inf_lt_right : a ⊓ b < b ↔ ¬b ≤ a :=
@right_lt_sup αᵒᵈ _ _ _
theorem inf_lt_left_or_right (h : a ≠ b) : a ⊓ b < a ∨ a ⊓ b < b :=
@left_or_right_lt_sup αᵒᵈ _ _ _ h
@[gcongr]
theorem inf_le_inf (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊓ c ≤ b ⊓ d :=
@sup_le_sup αᵒᵈ _ _ _ _ _ h₁ h₂
@[gcongr]
theorem inf_le_inf_right (a : α) {b c : α} (h : b ≤ c) : b ⊓ a ≤ c ⊓ a :=
inf_le_inf h le_rfl
@[gcongr]
theorem inf_le_inf_left (a : α) {b c : α} (h : b ≤ c) : a ⊓ b ≤ a ⊓ c :=
inf_le_inf le_rfl h
theorem inf_idem (a : α) : a ⊓ a = a := by simp
instance : Std.IdempotentOp (α := α) (· ⊓ ·) := ⟨inf_idem⟩
theorem inf_comm (a b : α) : a ⊓ b = b ⊓ a := @sup_comm αᵒᵈ _ _ _
instance : Std.Commutative (α := α) (· ⊓ ·) := ⟨inf_comm⟩
theorem inf_assoc (a b c : α) : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := @sup_assoc αᵒᵈ _ _ _ _
instance : Std.Associative (α := α) (· ⊓ ·) := ⟨inf_assoc⟩
theorem inf_left_right_swap (a b c : α) : a ⊓ b ⊓ c = c ⊓ b ⊓ a :=
@sup_left_right_swap αᵒᵈ _ _ _ _
theorem inf_left_idem (a b : α) : a ⊓ (a ⊓ b) = a ⊓ b := by simp
theorem inf_right_idem (a b : α) : a ⊓ b ⊓ b = a ⊓ b := by simp
theorem inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) :=
@sup_left_comm αᵒᵈ _ a b c
theorem inf_right_comm (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ b :=
@sup_right_comm αᵒᵈ _ a b c
theorem inf_inf_inf_comm (a b c d : α) : a ⊓ b ⊓ (c ⊓ d) = a ⊓ c ⊓ (b ⊓ d) :=
@sup_sup_sup_comm αᵒᵈ _ _ _ _ _
theorem inf_inf_distrib_left (a b c : α) : a ⊓ (b ⊓ c) = a ⊓ b ⊓ (a ⊓ c) :=
@sup_sup_distrib_left αᵒᵈ _ _ _ _
theorem inf_inf_distrib_right (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ (b ⊓ c) :=
@sup_sup_distrib_right αᵒᵈ _ _ _ _
theorem inf_congr_left (hb : a ⊓ c ≤ b) (hc : a ⊓ b ≤ c) : a ⊓ b = a ⊓ c :=
@sup_congr_left αᵒᵈ _ _ _ _ hb hc
theorem inf_congr_right (h1 : b ⊓ c ≤ a) (h2 : a ⊓ c ≤ b) : a ⊓ c = b ⊓ c :=
@sup_congr_right αᵒᵈ _ _ _ _ h1 h2
theorem inf_eq_inf_iff_left : a ⊓ b = a ⊓ c ↔ a ⊓ c ≤ b ∧ a ⊓ b ≤ c :=
@sup_eq_sup_iff_left αᵒᵈ _ _ _ _
theorem inf_eq_inf_iff_right : a ⊓ c = b ⊓ c ↔ b ⊓ c ≤ a ∧ a ⊓ c ≤ b :=
@sup_eq_sup_iff_right αᵒᵈ _ _ _ _
theorem Ne.inf_lt_or_inf_lt : a ≠ b → a ⊓ b < a ∨ a ⊓ b < b :=
@Ne.lt_sup_or_lt_sup αᵒᵈ _ _ _
theorem SemilatticeInf.ext_inf {α} {A B : SemilatticeInf α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y)
(x y : α) :
(haveI := A; x ⊓ y) = x ⊓ y :=
eq_of_forall_le_iff fun c => by simp only [le_inf_iff]; rw [← H, @le_inf_iff α A, H, H]
theorem SemilatticeInf.ext {α} {A B : SemilatticeInf α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
theorem SemilatticeInf.dual_dual (α : Type*) [H : SemilatticeInf α] :
OrderDual.instSemilatticeInf αᵒᵈ = H :=
SemilatticeInf.ext fun _ _ => Iff.rfl
theorem inf_le_ite (s s' : α) (P : Prop) [Decidable P] : s ⊓ s' ≤ ite P s s' :=
@ite_le_sup αᵒᵈ _ _ _ _ _
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a ≤ b` unfolds to `b ⊓ a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {α : Type*} [Inf α] (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a)
(inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ a : α, a ⊓ a = a) :
SemilatticeInf α := by
haveI : SemilatticeSup αᵒᵈ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.instSemilatticeInf αᵒᵈ
exact i
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (α : Type u) extends SemilatticeSup α, SemilatticeInf α
instance OrderDual.instLattice (α) [Lattice α] : Lattice αᵒᵈ where
__ := OrderDual.instSemilatticeSup α
__ := OrderDual.instSemilatticeInf α
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a ⊔ a ⊓ b = a`)
and `inf_sup_self` (`a ⊓ (a ⊔ b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{α : Type*} [Sup α] [Inf α]
(sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a) (sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c))
(sup_idem : ∀ a : α, a ⊔ a = a) (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a)
(inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ a : α, a ⊓ a = a)
(sup_inf_self : ∀ a b : α, a ⊔ a ⊓ b = a) (inf_sup_self : ∀ a b : α, a ⊓ (a ⊔ b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext fun a b =>
show a ⊔ b = b ↔ b ⊓ a = a from
⟨fun h => by rw [← h, inf_comm, inf_sup_self], fun h => by rw [← h, sup_comm, sup_inf_self]⟩
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {α : Type*} [Sup α] [Inf α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a)
(sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a)
(inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (sup_inf_self : ∀ a b : α, a ⊔ a ⊓ b = a)
(inf_sup_self : ∀ a b : α, a ⊓ (a ⊔ b) = a) : Lattice α :=
have sup_idem : ∀ b : α, b ⊔ b = b := fun b =>
calc
b ⊔ b = b ⊔ b ⊓ (b ⊔ b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : ∀ b : α, b ⊓ b = b := fun b =>
calc
b ⊓ b = b ⊓ (b ⊔ b ⊓ b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
section Lattice
variable [Lattice α] {a b c d : α}
theorem inf_le_sup : a ⊓ b ≤ a ⊔ b :=
inf_le_left.trans le_sup_left
theorem sup_le_inf : a ⊔ b ≤ a ⊓ b ↔ a = b := by simp [le_antisymm_iff, and_comm]
@[simp] lemma inf_eq_sup : a ⊓ b = a ⊔ b ↔ a = b := by rw [← inf_le_sup.ge_iff_eq, sup_le_inf]
@[simp] lemma sup_eq_inf : a ⊔ b = a ⊓ b ↔ a = b := eq_comm.trans inf_eq_sup
@[simp] lemma inf_lt_sup : a ⊓ b < a ⊔ b ↔ a ≠ b := by rw [inf_le_sup.lt_iff_ne, Ne, inf_eq_sup]
lemma inf_eq_and_sup_eq_iff : a ⊓ b = c ∧ a ⊔ b = c ↔ a = c ∧ b = c := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h
· rintro ⟨rfl, rfl⟩
exact ⟨inf_idem _, sup_idem _⟩
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a ⊔ b ⊓ c ≤ (a ⊔ b) ⊓ (a ⊔ c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
theorem le_inf_sup : a ⊓ b ⊔ a ⊓ c ≤ a ⊓ (b ⊔ c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
theorem inf_sup_self : a ⊓ (a ⊔ b) = a := by simp
theorem sup_inf_self : a ⊔ a ⊓ b = a := by simp
theorem sup_eq_iff_inf_eq : a ⊔ b = b ↔ a ⊓ b = a := by rw [sup_eq_right, ← inf_eq_left]
theorem Lattice.ext {α} {A B : Lattice α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (α) extends Lattice α where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : ∀ x y z : α, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ y ⊓ z
section DistribLattice
variable [DistribLattice α] {x y z : α}
theorem le_sup_inf : ∀ {x y z : α}, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ y ⊓ z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
theorem sup_inf_left (a b c : α) : a ⊔ b ⊓ c = (a ⊔ b) ⊓ (a ⊔ c) :=
le_antisymm sup_inf_le le_sup_inf
theorem sup_inf_right (a b c : α) : a ⊓ b ⊔ c = (a ⊔ c) ⊓ (b ⊔ c) := by
simp only [sup_inf_left, sup_comm _ c, eq_self_iff_true]
theorem inf_sup_left (a b c : α) : a ⊓ (b ⊔ c) = a ⊓ b ⊔ a ⊓ c :=
calc
a ⊓ (b ⊔ c) = a ⊓ (a ⊔ c) ⊓ (b ⊔ c) := by rw [inf_sup_self]
_ = a ⊓ (a ⊓ b ⊔ c) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (a ⊔ a ⊓ b) ⊓ (a ⊓ b ⊔ c) := by rw [sup_inf_self]
_ = (a ⊓ b ⊔ a) ⊓ (a ⊓ b ⊔ c) := by rw [sup_comm]
_ = a ⊓ b ⊔ a ⊓ c := by rw [sup_inf_left]
instance OrderDual.instDistribLattice (α : Type*) [DistribLattice α] : DistribLattice αᵒᵈ where
__ := inferInstanceAs (Lattice αᵒᵈ)
le_sup_inf _ _ _ := (inf_sup_left _ _ _).le
theorem inf_sup_right (a b c : α) : (a ⊔ b) ⊓ c = a ⊓ c ⊔ b ⊓ c := by
simp only [inf_sup_left, inf_comm _ c, eq_self_iff_true]
theorem le_of_inf_le_sup_le (h₁ : x ⊓ z ≤ y ⊓ z) (h₂ : x ⊔ z ≤ y ⊔ z) : x ≤ y :=
calc
x ≤ y ⊓ z ⊔ x := le_sup_right
_ = (y ⊔ x) ⊓ (x ⊔ z) := by rw [sup_inf_right, sup_comm x]
_ ≤ (y ⊔ x) ⊓ (y ⊔ z) := inf_le_inf_left _ h₂
_ = y ⊔ x ⊓ z := by rw [← sup_inf_left]
_ ≤ y ⊔ y ⊓ z := sup_le_sup_left h₁ _
_ ≤ _ := sup_le (le_refl y) inf_le_left
theorem eq_of_inf_eq_sup_eq {a b c : α} (h₁ : b ⊓ a = c ⊓ a) (h₂ : b ⊔ a = c ⊔ a) : b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq h₁) (le_of_eq h₂))
(le_of_inf_le_sup_le (le_of_eq h₁.symm) (le_of_eq h₂.symm))
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
abbrev DistribLattice.ofInfSupLe
[Lattice α] (inf_sup_le : ∀ a b c : α, a ⊓ (b ⊔ c) ≤ a ⊓ b ⊔ a ⊓ c) : DistribLattice α where
le_sup_inf := (@OrderDual.instDistribLattice αᵒᵈ {inferInstanceAs (Lattice αᵒᵈ) with
le_sup_inf := inf_sup_le}).le_sup_inf
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {α : Type u} [o : LinearOrder α] : Lattice α where
__ := o
sup := max
le_sup_left := le_max_left; le_sup_right := le_max_right; sup_le _ _ _ := max_le
inf := min
inf_le_left := min_le_left; inf_le_right := min_le_right; le_inf _ _ _ := le_min
section LinearOrder
variable [LinearOrder α] {a b c d : α}
theorem sup_eq_max : a ⊔ b = max a b :=
rfl
theorem inf_eq_min : a ⊓ b = min a b :=
rfl
theorem sup_ind (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊔ b) :=
(IsTotal.total a b).elim (fun h : a ≤ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
@[simp]
theorem le_sup_iff : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c := by
exact ⟨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_right⟩
@[simp]
theorem lt_sup_iff : a < b ⊔ c ↔ a < b ∨ a < c := by
exact ⟨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim lt_sup_of_lt_left lt_sup_of_lt_right⟩
@[simp]
theorem sup_lt_iff : b ⊔ c < a ↔ b < a ∧ c < a :=
⟨fun h => ⟨le_sup_left.trans_lt h, le_sup_right.trans_lt h⟩,
fun h => sup_ind (p := (· < a)) b c h.1 h.2⟩
theorem inf_ind (a b : α) {p : α → Prop} : p a → p b → p (a ⊓ b) :=
@sup_ind αᵒᵈ _ _ _ _
@[simp]
theorem inf_le_iff : b ⊓ c ≤ a ↔ b ≤ a ∨ c ≤ a :=
@le_sup_iff αᵒᵈ _ _ _ _
@[simp]
theorem inf_lt_iff : b ⊓ c < a ↔ b < a ∨ c < a :=
@lt_sup_iff αᵒᵈ _ _ _ _
@[simp]
theorem lt_inf_iff : a < b ⊓ c ↔ a < b ∧ a < c :=
@sup_lt_iff αᵒᵈ _ _ _ _
variable (a b c d)
theorem max_max_max_comm : max (max a b) (max c d) = max (max a c) (max b d) :=
sup_sup_sup_comm _ _ _ _
theorem min_min_min_comm : min (min a b) (min c d) = min (min a c) (min b d) :=
inf_inf_inf_comm _ _ _ _
end LinearOrder
theorem sup_eq_maxDefault [SemilatticeSup α] [DecidableRel ((· ≤ ·) : α → α → Prop)]
[IsTotal α (· ≤ ·)] :
(· ⊔ ·) = (maxDefault : α → α → α) := by
ext x y
unfold maxDefault
split_ifs with h'
exacts [sup_of_le_right h', sup_of_le_left <| (total_of (· ≤ ·) x y).resolve_left h']
theorem inf_eq_minDefault [SemilatticeInf α] [DecidableRel ((· ≤ ·) : α → α → Prop)]
[IsTotal α (· ≤ ·)] :
(· ⊓ ·) = (minDefault : α → α → α) := by
ext x y
unfold minDefault
split_ifs with h'
exacts [inf_of_le_left h', inf_of_le_right <| (total_of (· ≤ ·) x y).resolve_left h']
/-- A lattice with total order is a linear order.
See note [reducible non-instances]. -/
abbrev Lattice.toLinearOrder (α : Type u) [Lattice α] [DecidableEq α]
[DecidableRel ((· ≤ ·) : α → α → Prop)]
[DecidableRel ((· < ·) : α → α → Prop)] [IsTotal α (· ≤ ·)] : LinearOrder α where
__ := ‹Lattice α›
decidableLE := ‹_›
decidableEq := ‹_›
decidableLT := ‹_›
le_total := total_of (· ≤ ·)
max := (· ⊔ ·)
max_def := by exact congr_fun₂ sup_eq_maxDefault
min := (· ⊓ ·)
min_def := by exact congr_fun₂ inf_eq_minDefault
-- see Note [lower instance priority]
instance (priority := 100) {α : Type u} [LinearOrder α] : DistribLattice α where
__ := inferInstanceAs (Lattice α)
le_sup_inf _ b c :=
match le_total b c with
| Or.inl h => inf_le_of_left_le <| sup_le_sup_left (le_inf (le_refl b) h) _
| Or.inr h => inf_le_of_right_le <| sup_le_sup_left (le_inf h (le_refl c)) _
instance : DistribLattice ℕ := inferInstance
instance : Lattice ℤ := inferInstance
/-! ### Dual order -/
open OrderDual
@[simp]
theorem ofDual_inf [Sup α] (a b : αᵒᵈ) : ofDual (a ⊓ b) = ofDual a ⊔ ofDual b :=
rfl
@[simp]
theorem ofDual_sup [Inf α] (a b : αᵒᵈ) : ofDual (a ⊔ b) = ofDual a ⊓ ofDual b :=
rfl
@[simp]
theorem toDual_inf [Inf α] (a b : α) : toDual (a ⊓ b) = toDual a ⊔ toDual b :=
rfl
@[simp]
theorem toDual_sup [Sup α] (a b : α) : toDual (a ⊔ b) = toDual a ⊓ toDual b :=
rfl
section LinearOrder
variable [LinearOrder α]
@[simp]
theorem ofDual_min (a b : αᵒᵈ) : ofDual (min a b) = max (ofDual a) (ofDual b) :=
rfl
@[simp]
theorem ofDual_max (a b : αᵒᵈ) : ofDual (max a b) = min (ofDual a) (ofDual b) :=
rfl
@[simp]
theorem toDual_min (a b : α) : toDual (min a b) = max (toDual a) (toDual b) :=
rfl
@[simp]
theorem toDual_max (a b : α) : toDual (max a b) = min (toDual a) (toDual b) :=
rfl
end LinearOrder
/-! ### Function lattices -/
namespace Pi
variable {ι : Type*} {α' : ι → Type*}
instance [∀ i, Sup (α' i)] : Sup (∀ i, α' i) :=
⟨fun f g i => f i ⊔ g i⟩
@[simp]
theorem sup_apply [∀ i, Sup (α' i)] (f g : ∀ i, α' i) (i : ι) : (f ⊔ g) i = f i ⊔ g i :=
rfl
theorem sup_def [∀ i, Sup (α' i)] (f g : ∀ i, α' i) : f ⊔ g = fun i => f i ⊔ g i :=
rfl
instance [∀ i, Inf (α' i)] : Inf (∀ i, α' i) :=
⟨fun f g i => f i ⊓ g i⟩
@[simp]
theorem inf_apply [∀ i, Inf (α' i)] (f g : ∀ i, α' i) (i : ι) : (f ⊓ g) i = f i ⊓ g i :=
rfl
theorem inf_def [∀ i, Inf (α' i)] (f g : ∀ i, α' i) : f ⊓ g = fun i => f i ⊓ g i :=
rfl
instance instSemilatticeSup [∀ i, SemilatticeSup (α' i)] : SemilatticeSup (∀ i, α' i) where
le_sup_left _ _ _ := le_sup_left
le_sup_right _ _ _ := le_sup_right
sup_le _ _ _ ac bc i := sup_le (ac i) (bc i)
instance instSemilatticeInf [∀ i, SemilatticeInf (α' i)] : SemilatticeInf (∀ i, α' i) where
inf_le_left _ _ _ := inf_le_left
inf_le_right _ _ _ := inf_le_right
le_inf _ _ _ ac bc i := le_inf (ac i) (bc i)
instance instLattice [∀ i, Lattice (α' i)] : Lattice (∀ i, α' i) where
__ := inferInstanceAs (SemilatticeSup (∀ i, α' i))
__ := inferInstanceAs (SemilatticeInf (∀ i, α' i))
instance instDistribLattice [∀ i, DistribLattice (α' i)] : DistribLattice (∀ i, α' i) where
le_sup_inf _ _ _ _ := le_sup_inf
end Pi
namespace Function
variable {ι : Type*} {π : ι → Type*} [DecidableEq ι]
-- Porting note: Dot notation on `Function.update` broke
theorem update_sup [∀ i, SemilatticeSup (π i)] (f : ∀ i, π i) (i : ι) (a b : π i) :
update f i (a ⊔ b) = update f i a ⊔ update f i b :=
funext fun j => by obtain rfl | hji := eq_or_ne j i <;> simp [update_noteq, *]
theorem update_inf [∀ i, SemilatticeInf (π i)] (f : ∀ i, π i) (i : ι) (a b : π i) :
update f i (a ⊓ b) = update f i a ⊓ update f i b :=
funext fun j => by obtain rfl | hji := eq_or_ne j i <;> simp [update_noteq, *]
end Function
/-!
### Monotone functions and lattices
-/
namespace Monotone
/-- Pointwise supremum of two monotone functions is a monotone function. -/
protected theorem sup [Preorder α] [SemilatticeSup β] {f g : α → β} (hf : Monotone f)
(hg : Monotone g) :
Monotone (f ⊔ g) := fun _ _ h => sup_le_sup (hf h) (hg h)
/-- Pointwise infimum of two monotone functions is a monotone function. -/
protected theorem inf [Preorder α] [SemilatticeInf β] {f g : α → β} (hf : Monotone f)
(hg : Monotone g) :
Monotone (f ⊓ g) := fun _ _ h => inf_le_inf (hf h) (hg h)
/-- Pointwise maximum of two monotone functions is a monotone function. -/
protected theorem max [Preorder α] [LinearOrder β] {f g : α → β} (hf : Monotone f)
(hg : Monotone g) :
Monotone fun x => max (f x) (g x) :=
hf.sup hg
/-- Pointwise minimum of two monotone functions is a monotone function. -/
protected theorem min [Preorder α] [LinearOrder β] {f g : α → β} (hf : Monotone f)
(hg : Monotone g) :
Monotone fun x => min (f x) (g x) :=
hf.inf hg
theorem le_map_sup [SemilatticeSup α] [SemilatticeSup β] {f : α → β} (h : Monotone f) (x y : α) :
f x ⊔ f y ≤ f (x ⊔ y) :=
sup_le (h le_sup_left) (h le_sup_right)
theorem map_inf_le [SemilatticeInf α] [SemilatticeInf β] {f : α → β} (h : Monotone f) (x y : α) :
f (x ⊓ y) ≤ f x ⊓ f y :=
le_inf (h inf_le_left) (h inf_le_right)
theorem of_map_inf [SemilatticeInf α] [SemilatticeInf β] {f : α → β}
(h : ∀ x y, f (x ⊓ y) = f x ⊓ f y) : Monotone f :=
fun x y hxy => inf_eq_left.1 <| by rw [← h, inf_eq_left.2 hxy]
theorem of_map_sup [SemilatticeSup α] [SemilatticeSup β] {f : α → β}
(h : ∀ x y, f (x ⊔ y) = f x ⊔ f y) : Monotone f :=
(@of_map_inf (OrderDual α) (OrderDual β) _ _ _ h).dual
variable [LinearOrder α]
theorem map_sup [SemilatticeSup β] {f : α → β} (hf : Monotone f) (x y : α) :
f (x ⊔ y) = f x ⊔ f y :=
(IsTotal.total x y).elim (fun h : x ≤ y => by simp only [h, hf h, sup_of_le_right]) fun h => by
simp only [h, hf h, sup_of_le_left]
theorem map_inf [SemilatticeInf β] {f : α → β} (hf : Monotone f) (x y : α) :
f (x ⊓ y) = f x ⊓ f y :=
hf.dual.map_sup _ _
end Monotone
namespace MonotoneOn
variable {f : α → β} {s : Set α} {x y : α}
/-- Pointwise supremum of two monotone functions is a monotone function. -/
protected theorem sup [Preorder α] [SemilatticeSup β] {f g : α → β} {s : Set α}
(hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (f ⊔ g) s :=
fun _ hx _ hy h => sup_le_sup (hf hx hy h) (hg hx hy h)
/-- Pointwise infimum of two monotone functions is a monotone function. -/
protected theorem inf [Preorder α] [SemilatticeInf β] {f g : α → β} {s : Set α}
(hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (f ⊓ g) s :=
(hf.dual.sup hg.dual).dual
/-- Pointwise maximum of two monotone functions is a monotone function. -/
protected theorem max [Preorder α] [LinearOrder β] {f g : α → β} {s : Set α} (hf : MonotoneOn f s)
(hg : MonotoneOn g s) : MonotoneOn (fun x => max (f x) (g x)) s :=
hf.sup hg
/-- Pointwise minimum of two monotone functions is a monotone function. -/
protected theorem min [Preorder α] [LinearOrder β] {f g : α → β} {s : Set α} (hf : MonotoneOn f s)
(hg : MonotoneOn g s) : MonotoneOn (fun x => min (f x) (g x)) s :=
hf.inf hg
theorem of_map_inf [SemilatticeInf α] [SemilatticeInf β]
(h : ∀ x ∈ s, ∀ y ∈ s, f (x ⊓ y) = f x ⊓ f y) : MonotoneOn f s := fun x hx y hy hxy =>
inf_eq_left.1 <| by rw [← h _ hx _ hy, inf_eq_left.2 hxy]
theorem of_map_sup [SemilatticeSup α] [SemilatticeSup β]
(h : ∀ x ∈ s, ∀ y ∈ s, f (x ⊔ y) = f x ⊔ f y) : MonotoneOn f s :=
(@of_map_inf αᵒᵈ βᵒᵈ _ _ _ _ h).dual
variable [LinearOrder α]
theorem map_sup [SemilatticeSup β] (hf : MonotoneOn f s) (hx : x ∈ s) (hy : y ∈ s) :
f (x ⊔ y) = f x ⊔ f y := by
cases le_total x y <;> have := hf ?_ ?_ ‹_› <;>
first
| assumption
| simp only [*, sup_of_le_left, sup_of_le_right]
theorem map_inf [SemilatticeInf β] (hf : MonotoneOn f s) (hx : x ∈ s) (hy : y ∈ s) :
f (x ⊓ y) = f x ⊓ f y :=
hf.dual.map_sup hx hy
end MonotoneOn
namespace Antitone
/-- Pointwise supremum of two monotone functions is a monotone function. -/
protected theorem sup [Preorder α] [SemilatticeSup β] {f g : α → β} (hf : Antitone f)
(hg : Antitone g) :
Antitone (f ⊔ g) := fun _ _ h => sup_le_sup (hf h) (hg h)
/-- Pointwise infimum of two monotone functions is a monotone function. -/
protected theorem inf [Preorder α] [SemilatticeInf β] {f g : α → β} (hf : Antitone f)
(hg : Antitone g) :
Antitone (f ⊓ g) := fun _ _ h => inf_le_inf (hf h) (hg h)
/-- Pointwise maximum of two monotone functions is a monotone function. -/
protected theorem max [Preorder α] [LinearOrder β] {f g : α → β} (hf : Antitone f)
(hg : Antitone g) :
Antitone fun x => max (f x) (g x) :=
hf.sup hg
/-- Pointwise minimum of two monotone functions is a monotone function. -/
protected theorem min [Preorder α] [LinearOrder β] {f g : α → β} (hf : Antitone f)
(hg : Antitone g) :
Antitone fun x => min (f x) (g x) :=
hf.inf hg
theorem map_sup_le [SemilatticeSup α] [SemilatticeInf β] {f : α → β} (h : Antitone f) (x y : α) :
f (x ⊔ y) ≤ f x ⊓ f y :=
h.dual_right.le_map_sup x y
theorem le_map_inf [SemilatticeInf α] [SemilatticeSup β] {f : α → β} (h : Antitone f) (x y : α) :
f x ⊔ f y ≤ f (x ⊓ y) :=
h.dual_right.map_inf_le x y
variable [LinearOrder α]
theorem map_sup [SemilatticeInf β] {f : α → β} (hf : Antitone f) (x y : α) :
f (x ⊔ y) = f x ⊓ f y :=
hf.dual_right.map_sup x y
theorem map_inf [SemilatticeSup β] {f : α → β} (hf : Antitone f) (x y : α) :
f (x ⊓ y) = f x ⊔ f y :=
hf.dual_right.map_inf x y
end Antitone
namespace AntitoneOn
variable {f : α → β} {s : Set α} {x y : α}
/-- Pointwise supremum of two antitone functions is an antitone function. -/
protected theorem sup [Preorder α] [SemilatticeSup β] {f g : α → β} {s : Set α}
(hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (f ⊔ g) s :=
fun _ hx _ hy h => sup_le_sup (hf hx hy h) (hg hx hy h)
/-- Pointwise infimum of two antitone functions is an antitone function. -/
protected theorem inf [Preorder α] [SemilatticeInf β] {f g : α → β} {s : Set α}
(hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (f ⊓ g) s :=
(hf.dual.sup hg.dual).dual
/-- Pointwise maximum of two antitone functions is an antitone function. -/
protected theorem max [Preorder α] [LinearOrder β] {f g : α → β} {s : Set α} (hf : AntitoneOn f s)
(hg : AntitoneOn g s) : AntitoneOn (fun x => max (f x) (g x)) s :=
hf.sup hg
/-- Pointwise minimum of two antitone functions is an antitone function. -/
protected theorem min [Preorder α] [LinearOrder β] {f g : α → β} {s : Set α} (hf : AntitoneOn f s)
(hg : AntitoneOn g s) : AntitoneOn (fun x => min (f x) (g x)) s :=
hf.inf hg
theorem of_map_inf [SemilatticeInf α] [SemilatticeSup β]
(h : ∀ x ∈ s, ∀ y ∈ s, f (x ⊓ y) = f x ⊔ f y) : AntitoneOn f s := fun x hx y hy hxy =>
sup_eq_left.1 <| by rw [← h _ hx _ hy, inf_eq_left.2 hxy]
theorem of_map_sup [SemilatticeSup α] [SemilatticeInf β]
(h : ∀ x ∈ s, ∀ y ∈ s, f (x ⊔ y) = f x ⊓ f y) : AntitoneOn f s :=
(@of_map_inf αᵒᵈ βᵒᵈ _ _ _ _ h).dual
variable [LinearOrder α]
theorem map_sup [SemilatticeInf β] (hf : AntitoneOn f s) (hx : x ∈ s) (hy : y ∈ s) :
f (x ⊔ y) = f x ⊓ f y := by
cases le_total x y <;> have := hf ?_ ?_ ‹_› <;>
first
| assumption
| simp only [*, sup_of_le_left, sup_of_le_right, inf_of_le_left, inf_of_le_right]
theorem map_inf [SemilatticeSup β] (hf : AntitoneOn f s) (hx : x ∈ s) (hy : y ∈ s) :
f (x ⊓ y) = f x ⊔ f y :=
hf.dual.map_sup hx hy
end AntitoneOn
/-!
### Products of (semi-)lattices
-/
namespace Prod
variable (α β)
instance [Sup α] [Sup β] : Sup (α × β) :=
⟨fun p q => ⟨p.1 ⊔ q.1, p.2 ⊔ q.2⟩⟩
instance [Inf α] [Inf β] : Inf (α × β) :=
⟨fun p q => ⟨p.1 ⊓ q.1, p.2 ⊓ q.2⟩⟩
@[simp]
theorem mk_sup_mk [Sup α] [Sup β] (a₁ a₂ : α) (b₁ b₂ : β) :
(a₁, b₁) ⊔ (a₂, b₂) = (a₁ ⊔ a₂, b₁ ⊔ b₂) :=
rfl
@[simp]
theorem mk_inf_mk [Inf α] [Inf β] (a₁ a₂ : α) (b₁ b₂ : β) :
(a₁, b₁) ⊓ (a₂, b₂) = (a₁ ⊓ a₂, b₁ ⊓ b₂) :=
rfl
@[simp]
theorem fst_sup [Sup α] [Sup β] (p q : α × β) : (p ⊔ q).fst = p.fst ⊔ q.fst :=
rfl
@[simp]
theorem fst_inf [Inf α] [Inf β] (p q : α × β) : (p ⊓ q).fst = p.fst ⊓ q.fst :=
rfl
@[simp]
theorem snd_sup [Sup α] [Sup β] (p q : α × β) : (p ⊔ q).snd = p.snd ⊔ q.snd :=
rfl
@[simp]
theorem snd_inf [Inf α] [Inf β] (p q : α × β) : (p ⊓ q).snd = p.snd ⊓ q.snd :=
rfl
@[simp]
theorem swap_sup [Sup α] [Sup β] (p q : α × β) : (p ⊔ q).swap = p.swap ⊔ q.swap :=
rfl
@[simp]
theorem swap_inf [Inf α] [Inf β] (p q : α × β) : (p ⊓ q).swap = p.swap ⊓ q.swap :=
rfl
theorem sup_def [Sup α] [Sup β] (p q : α × β) : p ⊔ q = (p.fst ⊔ q.fst, p.snd ⊔ q.snd) :=
rfl
theorem inf_def [Inf α] [Inf β] (p q : α × β) : p ⊓ q = (p.fst ⊓ q.fst, p.snd ⊓ q.snd) :=
rfl
instance instSemilatticeSup [SemilatticeSup α] [SemilatticeSup β] : SemilatticeSup (α × β) where
__ := inferInstanceAs (PartialOrder (α × β))
__ := inferInstanceAs (Sup (α × β))
sup_le _ _ _ h₁ h₂ := ⟨sup_le h₁.1 h₂.1, sup_le h₁.2 h₂.2⟩
le_sup_left _ _ := ⟨le_sup_left, le_sup_left⟩
le_sup_right _ _ := ⟨le_sup_right, le_sup_right⟩
instance instSemilatticeInf [SemilatticeInf α] [SemilatticeInf β] : SemilatticeInf (α × β) where
__ := inferInstanceAs (PartialOrder (α × β))
__ := inferInstanceAs (Inf (α × β))
le_inf _ _ _ h₁ h₂ := ⟨le_inf h₁.1 h₂.1, le_inf h₁.2 h₂.2⟩
inf_le_left _ _ := ⟨inf_le_left, inf_le_left⟩
inf_le_right _ _ := ⟨inf_le_right, inf_le_right⟩
instance instLattice [Lattice α] [Lattice β] : Lattice (α × β) where
__ := inferInstanceAs (SemilatticeSup (α × β))
__ := inferInstanceAs (SemilatticeInf (α × β))
instance instDistribLattice [DistribLattice α] [DistribLattice β] : DistribLattice (α × β) where
__ := inferInstanceAs (Lattice (α × β))
le_sup_inf _ _ _ := ⟨le_sup_inf, le_sup_inf⟩
end Prod
/-!
### Subtypes of (semi-)lattices
-/
namespace Subtype
/-- A subtype forms a `⊔`-semilattice if `⊔` preserves the property.
See note [reducible non-instances]. -/
protected abbrev semilatticeSup [SemilatticeSup α] {P : α → Prop}
(Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) :
SemilatticeSup { x : α // P x } where
sup x y := ⟨x.1 ⊔ y.1, Psup x.2 y.2⟩
le_sup_left _ _ := le_sup_left
le_sup_right _ _ := le_sup_right
sup_le _ _ _ h1 h2 := sup_le h1 h2
/-- A subtype forms a `⊓`-semilattice if `⊓` preserves the property.
See note [reducible non-instances]. -/
protected abbrev semilatticeInf [SemilatticeInf α] {P : α → Prop}
(Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) :
SemilatticeInf { x : α // P x } where
inf x y := ⟨x.1 ⊓ y.1, Pinf x.2 y.2⟩
inf_le_left _ _ := inf_le_left
inf_le_right _ _ := inf_le_right
le_inf _ _ _ h1 h2 := le_inf h1 h2
/-- A subtype forms a lattice if `⊔` and `⊓` preserve the property.
See note [reducible non-instances]. -/
protected abbrev lattice [Lattice α] {P : α → Prop} (Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y))
(Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) : Lattice { x : α // P x } where
__ := Subtype.semilatticeInf Pinf
__ := Subtype.semilatticeSup Psup
@[simp, norm_cast]
theorem coe_sup [SemilatticeSup α] {P : α → Prop}
(Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) (x y : Subtype P) :
(haveI := Subtype.semilatticeSup Psup; (x ⊔ y : Subtype P) : α) = (x ⊔ y : α) :=
rfl
@[simp, norm_cast]
theorem coe_inf [SemilatticeInf α] {P : α → Prop}
(Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) (x y : Subtype P) :
(haveI := Subtype.semilatticeInf Pinf; (x ⊓ y : Subtype P) : α) = (x ⊓ y : α) :=
rfl
@[simp]
theorem mk_sup_mk [SemilatticeSup α] {P : α → Prop}
(Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)) {x y : α} (hx : P x) (hy : P y) :
(haveI := Subtype.semilatticeSup Psup; (⟨x, hx⟩ ⊔ ⟨y, hy⟩ : Subtype P)) =
⟨x ⊔ y, Psup hx hy⟩ :=
rfl
@[simp]
theorem mk_inf_mk [SemilatticeInf α] {P : α → Prop}
(Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)) {x y : α} (hx : P x) (hy : P y) :
(haveI := Subtype.semilatticeInf Pinf; (⟨x, hx⟩ ⊓ ⟨y, hy⟩ : Subtype P)) =
⟨x ⊓ y, Pinf hx hy⟩ :=
rfl
end Subtype
section lift
/-- A type endowed with `⊔` is a `SemilatticeSup`, if it admits an injective map that
preserves `⊔` to a `SemilatticeSup`.
See note [reducible non-instances]. -/
protected abbrev Function.Injective.semilatticeSup [Sup α] [SemilatticeSup β] (f : α → β)
(hf_inj : Function.Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) :
SemilatticeSup α where
__ := PartialOrder.lift f hf_inj
sup := Sup.sup
le_sup_left a b := by
change f a ≤ f (a ⊔ b)
rw [map_sup]
exact le_sup_left
le_sup_right a b := by
change f b ≤ f (a ⊔ b)
rw [map_sup]
exact le_sup_right
sup_le a b c ha hb := by
change f (a ⊔ b) ≤ f c
rw [map_sup]
exact sup_le ha hb
/-- A type endowed with `⊓` is a `SemilatticeInf`, if it admits an injective map that
preserves `⊓` to a `SemilatticeInf`.
See note [reducible non-instances]. -/
protected abbrev Function.Injective.semilatticeInf [Inf α] [SemilatticeInf β] (f : α → β)
(hf_inj : Function.Injective f) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) :
SemilatticeInf α where
__ := PartialOrder.lift f hf_inj
inf := Inf.inf
inf_le_left a b := by
change f (a ⊓ b) ≤ f a
rw [map_inf]
exact inf_le_left
inf_le_right a b := by
change f (a ⊓ b) ≤ f b
rw [map_inf]
exact inf_le_right
le_inf a b c ha hb := by
change f a ≤ f (b ⊓ c)
rw [map_inf]
exact le_inf ha hb
/-- A type endowed with `⊔` and `⊓` is a `Lattice`, if it admits an injective map that
preserves `⊔` and `⊓` to a `Lattice`.
See note [reducible non-instances]. -/
protected abbrev Function.Injective.lattice [Sup α] [Inf α] [Lattice β] (f : α → β)
(hf_inj : Function.Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) :
Lattice α where
__ := hf_inj.semilatticeSup f map_sup
__ := hf_inj.semilatticeInf f map_inf
/-- A type endowed with `⊔` and `⊓` is a `DistribLattice`, if it admits an injective map that
preserves `⊔` and `⊓` to a `DistribLattice`.
See note [reducible non-instances]. -/
protected abbrev Function.Injective.distribLattice [Sup α] [Inf α] [DistribLattice β] (f : α → β)
(hf_inj : Function.Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b)
(map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) :
DistribLattice α where
__ := hf_inj.lattice f map_sup map_inf
le_sup_inf a b c := by
change f ((a ⊔ b) ⊓ (a ⊔ c)) ≤ f (a ⊔ b ⊓ c)
rw [map_inf, map_sup, map_sup, map_sup, map_inf]
exact le_sup_inf
end lift
namespace ULift
instance [SemilatticeSup α] : SemilatticeSup (ULift.{v} α) :=
ULift.down_injective.semilatticeSup _ down_sup
instance [SemilatticeInf α] : SemilatticeInf (ULift.{v} α) :=
ULift.down_injective.semilatticeInf _ down_inf
instance [Lattice α] : Lattice (ULift.{v} α) :=
ULift.down_injective.lattice _ down_sup down_inf
instance [DistribLattice α] : DistribLattice (ULift.{v} α) :=
ULift.down_injective.distribLattice _ down_sup down_inf
instance [LinearOrder α] : LinearOrder (ULift.{v} α) :=
LinearOrder.liftWithOrd ULift.down ULift.down_injective down_sup down_inf
fun _x _y => (down_compare _ _).symm
end ULift
--To avoid noncomputability poisoning from `Bool.completeBooleanAlgebra`
instance Bool.instDistribLattice : DistribLattice Bool :=
inferInstance
|
Order\LatticeIntervals.lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Order.Bounds.Basic
/-!
# Intervals in Lattices
In this file, we provide instances of lattice structures on intervals within lattices.
Some of them depend on the order of the endpoints of the interval, and thus are not made
global instances. These are probably not all of the lattice instances that could be placed on these
intervals, but more can be added easily along the same lines when needed.
## Main definitions
In the following, `*` can represent either `c`, `o`, or `i`.
* `Set.Ic*.orderBot`
* `Set.Ii*.semillaticeInf`
* `Set.I*c.orderTop`
* `Set.I*c.semillaticeInf`
* `Set.I**.lattice`
* `Set.Iic.boundedOrder`, within an `OrderBot`
* `Set.Ici.boundedOrder`, within an `OrderTop`
-/
variable {α : Type*}
namespace Set
namespace Ico
instance semilatticeInf [SemilatticeInf α] {a b : α} : SemilatticeInf (Ico a b) :=
Subtype.semilatticeInf fun _ _ hx hy => ⟨le_inf hx.1 hy.1, lt_of_le_of_lt inf_le_left hx.2⟩
/-- `Ico a b` has a bottom element whenever `a < b`. -/
protected abbrev orderBot [PartialOrder α] {a b : α} (h : a < b) : OrderBot (Ico a b) :=
(isLeast_Ico h).orderBot
end Ico
namespace Iio
instance semilatticeInf [SemilatticeInf α] {a : α} : SemilatticeInf (Iio a) :=
Subtype.semilatticeInf fun _ _ hx _ => lt_of_le_of_lt inf_le_left hx
end Iio
namespace Ioc
instance semilatticeSup [SemilatticeSup α] {a b : α} : SemilatticeSup (Ioc a b) :=
Subtype.semilatticeSup fun _ _ hx hy => ⟨lt_of_lt_of_le hx.1 le_sup_left, sup_le hx.2 hy.2⟩
/-- `Ioc a b` has a top element whenever `a < b`. -/
protected abbrev orderTop [PartialOrder α] {a b : α} (h : a < b) : OrderTop (Ioc a b) :=
(isGreatest_Ioc h).orderTop
end Ioc
namespace Ioi
instance semilatticeSup [SemilatticeSup α] {a : α} : SemilatticeSup (Ioi a) :=
Subtype.semilatticeSup fun _ _ hx _ => lt_of_lt_of_le hx le_sup_left
end Ioi
namespace Iic
variable {a : α}
instance semilatticeInf [SemilatticeInf α] : SemilatticeInf (Iic a) :=
Subtype.semilatticeInf fun _ _ hx _ => le_trans inf_le_left hx
@[simp, norm_cast]
protected lemma coe_inf [SemilatticeInf α] {x y : Iic a} :
(↑(x ⊓ y) : α) = (x : α) ⊓ (y : α) :=
rfl
instance semilatticeSup [SemilatticeSup α] : SemilatticeSup (Iic a) :=
Subtype.semilatticeSup fun _ _ hx hy => sup_le hx hy
@[simp, norm_cast]
protected lemma coe_sup [SemilatticeSup α] {x y : Iic a} :
(↑(x ⊔ y) : α) = (x : α) ⊔ (y : α) :=
rfl
instance [Lattice α] : Lattice (Iic a) :=
{ Iic.semilatticeInf, Iic.semilatticeSup with }
instance orderTop [Preorder α] :
OrderTop (Iic a) where
top := ⟨a, le_refl a⟩
le_top x := x.prop
@[simp]
theorem coe_top [Preorder α] : (⊤ : Iic a) = a :=
rfl
protected lemma eq_top_iff [Preorder α] {x : Iic a} :
x = ⊤ ↔ (x : α) = a := by
simp [Subtype.ext_iff]
instance orderBot [Preorder α] [OrderBot α] :
OrderBot (Iic a) where
bot := ⟨⊥, bot_le⟩
bot_le := fun ⟨_, _⟩ => Subtype.mk_le_mk.2 bot_le
@[simp]
theorem coe_bot [Preorder α] [OrderBot α] : (⊥ : Iic a) = (⊥ : α) :=
rfl
instance [Preorder α] [OrderBot α] : BoundedOrder (Iic a) :=
{ Iic.orderTop, Iic.orderBot with }
protected lemma disjoint_iff [SemilatticeInf α] [OrderBot α] {x y : Iic a} :
Disjoint x y ↔ Disjoint (x : α) (y : α) := by
simp [_root_.disjoint_iff, Subtype.ext_iff]
protected lemma codisjoint_iff [SemilatticeSup α] {x y : Iic a} :
Codisjoint x y ↔ (x : α) ⊔ (y : α) = a := by
simpa only [_root_.codisjoint_iff] using Iic.eq_top_iff
protected lemma isCompl_iff [Lattice α] [BoundedOrder α] {x y : Iic a} :
IsCompl x y ↔ Disjoint (x : α) (y : α) ∧ (x : α) ⊔ (y : α) = a := by
rw [_root_.isCompl_iff, Iic.disjoint_iff, Iic.codisjoint_iff]
end Iic
namespace Ici
instance semilatticeInf [SemilatticeInf α] {a : α} : SemilatticeInf (Ici a) :=
Subtype.semilatticeInf fun _ _ hx hy => le_inf hx hy
instance semilatticeSup [SemilatticeSup α] {a : α} : SemilatticeSup (Ici a) :=
Subtype.semilatticeSup fun _ _ hx _ => le_trans hx le_sup_left
instance lattice [Lattice α] {a : α} : Lattice (Ici a) :=
{ Ici.semilatticeInf, Ici.semilatticeSup with }
instance distribLattice [DistribLattice α] {a : α} : DistribLattice (Ici a) :=
{ Ici.lattice with le_sup_inf := fun _ _ _ => le_sup_inf }
instance orderBot [Preorder α] {a : α} :
OrderBot (Ici a) where
bot := ⟨a, le_refl a⟩
bot_le x := x.prop
@[simp]
theorem coe_bot [Preorder α] {a : α} : ↑(⊥ : Ici a) = a :=
rfl
instance orderTop [Preorder α] [OrderTop α] {a : α} :
OrderTop (Ici a) where
top := ⟨⊤, le_top⟩
le_top := fun ⟨_, _⟩ => Subtype.mk_le_mk.2 le_top
@[simp]
theorem coe_top [Preorder α] [OrderTop α] {a : α} : ↑(⊤ : Ici a) = (⊤ : α) :=
rfl
instance boundedOrder [Preorder α] [OrderTop α] {a : α} : BoundedOrder (Ici a) :=
{ Ici.orderTop, Ici.orderBot with }
end Ici
namespace Icc
instance semilatticeInf [SemilatticeInf α] {a b : α} : SemilatticeInf (Icc a b) :=
Subtype.semilatticeInf fun _ _ hx hy => ⟨le_inf hx.1 hy.1, le_trans inf_le_left hx.2⟩
instance semilatticeSup [SemilatticeSup α] {a b : α} : SemilatticeSup (Icc a b) :=
Subtype.semilatticeSup fun _ _ hx hy => ⟨le_trans hx.1 le_sup_left, sup_le hx.2 hy.2⟩
instance lattice [Lattice α] {a b : α} : Lattice (Icc a b) :=
{ Icc.semilatticeInf, Icc.semilatticeSup with }
/-- `Icc a b` has a bottom element whenever `a ≤ b`. -/
protected abbrev orderBot [Preorder α] {a b : α} (h : a ≤ b) : OrderBot (Icc a b) :=
(isLeast_Icc h).orderBot
/-- `Icc a b` has a top element whenever `a ≤ b`. -/
protected abbrev orderTop [Preorder α] {a b : α} (h : a ≤ b) : OrderTop (Icc a b) :=
(isGreatest_Icc h).orderTop
/-- `Icc a b` is a `BoundedOrder` whenever `a ≤ b`. -/
protected abbrev boundedOrder [Preorder α] {a b : α} (h : a ≤ b) : BoundedOrder (Icc a b) :=
{ Icc.orderTop h, Icc.orderBot h with }
end Icc
end Set
|
Order\LiminfLimsup.lean | /-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl, Rémy Degenne
-/
import Mathlib.Order.Filter.Cofinite
import Mathlib.Order.Hom.CompleteLattice
/-!
# liminfs and limsups of functions and filters
Defines the liminf/limsup of a function taking values in a conditionally complete lattice, with
respect to an arbitrary filter.
We define `limsSup f` (`limsInf f`) where `f` is a filter taking values in a conditionally complete
lattice. `limsSup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for
`limsInf f`). To work with the Limsup along a function `u` use `limsSup (map u f)`.
Usually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter.
For instance, in ℕ along a function `u`, this is `inf_n (sup_{k ≥ n} u k)` (and the latter quantity
decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible
that `u` is not bounded on the whole space, only eventually (think of `limsup (fun x ↦ 1/x)` on ℝ.
Then there is no guarantee that the quantity above really decreases (the value of the `sup`
beforehand is not really well defined, as one can not use ∞), so that the Inf could be anything.
So one can not use this `inf sup ...` definition in conditionally complete lattices, and one has
to use a less tractable definition.
In conditionally complete lattices, the definition is only useful for filters which are eventually
bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and
which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the
space either). We start with definitions of these concepts for arbitrary filters, before turning to
the definitions of Limsup and Liminf.
In complete lattices, however, it coincides with the `Inf Sup` definition.
-/
open Filter Set Function
variable {α β γ ι ι' : Type*}
namespace Filter
section Relation
/-- `f.IsBounded (≺)`: the filter `f` is eventually bounded w.r.t. the relation `≺`, i.e.
eventually, it is bounded by some uniform bound.
`r` will be usually instantiated with `≤` or `≥`. -/
def IsBounded (r : α → α → Prop) (f : Filter α) :=
∃ b, ∀ᶠ x in f, r x b
/-- `f.IsBoundedUnder (≺) u`: the image of the filter `f` under `u` is eventually bounded w.r.t.
the relation `≺`, i.e. eventually, it is bounded by some uniform bound. -/
def IsBoundedUnder (r : α → α → Prop) (f : Filter β) (u : β → α) :=
(map u f).IsBounded r
variable {r : α → α → Prop} {f g : Filter α}
/-- `f` is eventually bounded if and only if, there exists an admissible set on which it is
bounded. -/
theorem isBounded_iff : f.IsBounded r ↔ ∃ s ∈ f.sets, ∃ b, s ⊆ { x | r x b } :=
Iff.intro (fun ⟨b, hb⟩ => ⟨{ a | r a b }, hb, b, Subset.refl _⟩) fun ⟨_, hs, b, hb⟩ =>
⟨b, mem_of_superset hs hb⟩
/-- A bounded function `u` is in particular eventually bounded. -/
theorem isBoundedUnder_of {f : Filter β} {u : β → α} : (∃ b, ∀ x, r (u x) b) → f.IsBoundedUnder r u
| ⟨b, hb⟩ => ⟨b, show ∀ᶠ x in f, r (u x) b from eventually_of_forall hb⟩
theorem isBounded_bot : IsBounded r ⊥ ↔ Nonempty α := by simp [IsBounded, exists_true_iff_nonempty]
theorem isBounded_top : IsBounded r ⊤ ↔ ∃ t, ∀ x, r x t := by simp [IsBounded, eq_univ_iff_forall]
theorem isBounded_principal (s : Set α) : IsBounded r (𝓟 s) ↔ ∃ t, ∀ x ∈ s, r x t := by
simp [IsBounded, subset_def]
theorem isBounded_sup [IsTrans α r] [IsDirected α r] :
IsBounded r f → IsBounded r g → IsBounded r (f ⊔ g)
| ⟨b₁, h₁⟩, ⟨b₂, h₂⟩ =>
let ⟨b, rb₁b, rb₂b⟩ := directed_of r b₁ b₂
⟨b, eventually_sup.mpr
⟨h₁.mono fun _ h => _root_.trans h rb₁b, h₂.mono fun _ h => _root_.trans h rb₂b⟩⟩
theorem IsBounded.mono (h : f ≤ g) : IsBounded r g → IsBounded r f
| ⟨b, hb⟩ => ⟨b, h hb⟩
theorem IsBoundedUnder.mono {f g : Filter β} {u : β → α} (h : f ≤ g) :
g.IsBoundedUnder r u → f.IsBoundedUnder r u := fun hg => IsBounded.mono (map_mono h) hg
theorem IsBoundedUnder.mono_le [Preorder β] {l : Filter α} {u v : α → β}
(hu : IsBoundedUnder (· ≤ ·) l u) (hv : v ≤ᶠ[l] u) : IsBoundedUnder (· ≤ ·) l v := by
apply hu.imp
exact fun b hb => (eventually_map.1 hb).mp <| hv.mono fun x => le_trans
theorem IsBoundedUnder.mono_ge [Preorder β] {l : Filter α} {u v : α → β}
(hu : IsBoundedUnder (· ≥ ·) l u) (hv : u ≤ᶠ[l] v) : IsBoundedUnder (· ≥ ·) l v :=
IsBoundedUnder.mono_le (β := βᵒᵈ) hu hv
theorem isBoundedUnder_const [IsRefl α r] {l : Filter β} {a : α} : IsBoundedUnder r l fun _ => a :=
⟨a, eventually_map.2 <| eventually_of_forall fun _ => refl _⟩
theorem IsBounded.isBoundedUnder {q : β → β → Prop} {u : α → β}
(hu : ∀ a₀ a₁, r a₀ a₁ → q (u a₀) (u a₁)) : f.IsBounded r → f.IsBoundedUnder q u
| ⟨b, h⟩ => ⟨u b, show ∀ᶠ x in f, q (u x) (u b) from h.mono fun x => hu x b⟩
theorem IsBoundedUnder.comp {l : Filter γ} {q : β → β → Prop} {u : γ → α} {v : α → β}
(hv : ∀ a₀ a₁, r a₀ a₁ → q (v a₀) (v a₁)) : l.IsBoundedUnder r u → l.IsBoundedUnder q (v ∘ u)
| ⟨a, h⟩ => ⟨v a, show ∀ᶠ x in map u l, q (v x) (v a) from h.mono fun x => hv x a⟩
/-- A bounded above function `u` is in particular eventually bounded above. -/
lemma _root_.BddAbove.isBoundedUnder [Preorder α] {f : Filter β} {u : β → α} :
BddAbove (Set.range u) → f.IsBoundedUnder (· ≤ ·) u
| ⟨b, hb⟩ => isBoundedUnder_of ⟨b, by simpa [mem_upperBounds] using hb⟩
/-- A bounded below function `u` is in particular eventually bounded below. -/
lemma _root_.BddBelow.isBoundedUnder [Preorder α] {f : Filter β} {u : β → α} :
BddBelow (Set.range u) → f.IsBoundedUnder (· ≥ ·) u
| ⟨b, hb⟩ => isBoundedUnder_of ⟨b, by simpa [mem_lowerBounds] using hb⟩
theorem _root_.Monotone.isBoundedUnder_le_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Monotone v) (hl : l.IsBoundedUnder (· ≤ ·) u) :
l.IsBoundedUnder (· ≤ ·) (v ∘ u) :=
hl.comp hv
theorem _root_.Monotone.isBoundedUnder_ge_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Monotone v) (hl : l.IsBoundedUnder (· ≥ ·) u) :
l.IsBoundedUnder (· ≥ ·) (v ∘ u) :=
hl.comp (swap hv)
theorem _root_.Antitone.isBoundedUnder_le_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Antitone v) (hl : l.IsBoundedUnder (· ≥ ·) u) :
l.IsBoundedUnder (· ≤ ·) (v ∘ u) :=
hl.comp (swap hv)
theorem _root_.Antitone.isBoundedUnder_ge_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α}
{v : α → β} (hv : Antitone v) (hl : l.IsBoundedUnder (· ≤ ·) u) :
l.IsBoundedUnder (· ≥ ·) (v ∘ u) :=
hl.comp hv
theorem not_isBoundedUnder_of_tendsto_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α}
[l.NeBot] (hf : Tendsto f l atTop) : ¬IsBoundedUnder (· ≤ ·) l f := by
rintro ⟨b, hb⟩
rw [eventually_map] at hb
obtain ⟨b', h⟩ := exists_gt b
have hb' := (tendsto_atTop.mp hf) b'
have : { x : α | f x ≤ b } ∩ { x : α | b' ≤ f x } = ∅ :=
eq_empty_of_subset_empty fun x hx => (not_le_of_lt h) (le_trans hx.2 hx.1)
exact (nonempty_of_mem (hb.and hb')).ne_empty this
theorem not_isBoundedUnder_of_tendsto_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α}
[l.NeBot] (hf : Tendsto f l atBot) : ¬IsBoundedUnder (· ≥ ·) l f :=
not_isBoundedUnder_of_tendsto_atTop (β := βᵒᵈ) hf
theorem IsBoundedUnder.bddAbove_range_of_cofinite [Preorder β] [IsDirected β (· ≤ ·)] {f : α → β}
(hf : IsBoundedUnder (· ≤ ·) cofinite f) : BddAbove (range f) := by
rcases hf with ⟨b, hb⟩
haveI : Nonempty β := ⟨b⟩
rw [← image_univ, ← union_compl_self { x | f x ≤ b }, image_union, bddAbove_union]
exact ⟨⟨b, forall_mem_image.2 fun x => id⟩, (hb.image f).bddAbove⟩
theorem IsBoundedUnder.bddBelow_range_of_cofinite [Preorder β] [IsDirected β (· ≥ ·)] {f : α → β}
(hf : IsBoundedUnder (· ≥ ·) cofinite f) : BddBelow (range f) :=
IsBoundedUnder.bddAbove_range_of_cofinite (β := βᵒᵈ) hf
theorem IsBoundedUnder.bddAbove_range [Preorder β] [IsDirected β (· ≤ ·)] {f : ℕ → β}
(hf : IsBoundedUnder (· ≤ ·) atTop f) : BddAbove (range f) := by
rw [← Nat.cofinite_eq_atTop] at hf
exact hf.bddAbove_range_of_cofinite
theorem IsBoundedUnder.bddBelow_range [Preorder β] [IsDirected β (· ≥ ·)] {f : ℕ → β}
(hf : IsBoundedUnder (· ≥ ·) atTop f) : BddBelow (range f) :=
IsBoundedUnder.bddAbove_range (β := βᵒᵈ) hf
/-- `IsCobounded (≺) f` states that the filter `f` does not tend to infinity w.r.t. `≺`. This is
also called frequently bounded. Will be usually instantiated with `≤` or `≥`.
There is a subtlety in this definition: we want `f.IsCobounded` to hold for any `f` in the case of
complete lattices. This will be relevant to deduce theorems on complete lattices from their
versions on conditionally complete lattices with additional assumptions. We have to be careful in
the edge case of the trivial filter containing the empty set: the other natural definition
`¬ ∀ a, ∀ᶠ n in f, a ≤ n`
would not work as well in this case.
-/
def IsCobounded (r : α → α → Prop) (f : Filter α) :=
∃ b, ∀ a, (∀ᶠ x in f, r x a) → r b a
/-- `IsCoboundedUnder (≺) f u` states that the image of the filter `f` under the map `u` does not
tend to infinity w.r.t. `≺`. This is also called frequently bounded. Will be usually instantiated
with `≤` or `≥`. -/
def IsCoboundedUnder (r : α → α → Prop) (f : Filter β) (u : β → α) :=
(map u f).IsCobounded r
/-- To check that a filter is frequently bounded, it suffices to have a witness
which bounds `f` at some point for every admissible set.
This is only an implication, as the other direction is wrong for the trivial filter. -/
theorem IsCobounded.mk [IsTrans α r] (a : α) (h : ∀ s ∈ f, ∃ x ∈ s, r a x) : f.IsCobounded r :=
⟨a, fun _ s =>
let ⟨_, h₁, h₂⟩ := h _ s
_root_.trans h₂ h₁⟩
/-- A filter which is eventually bounded is in particular frequently bounded (in the opposite
direction). At least if the filter is not trivial. -/
theorem IsBounded.isCobounded_flip [IsTrans α r] [NeBot f] : f.IsBounded r → f.IsCobounded (flip r)
| ⟨a, ha⟩ =>
⟨a, fun b hb =>
let ⟨_, rxa, rbx⟩ := (ha.and hb).exists
show r b a from _root_.trans rbx rxa⟩
theorem IsBounded.isCobounded_ge [Preorder α] [NeBot f] (h : f.IsBounded (· ≤ ·)) :
f.IsCobounded (· ≥ ·) :=
h.isCobounded_flip
theorem IsBounded.isCobounded_le [Preorder α] [NeBot f] (h : f.IsBounded (· ≥ ·)) :
f.IsCobounded (· ≤ ·) :=
h.isCobounded_flip
theorem IsBoundedUnder.isCoboundedUnder_flip {u : γ → α} {l : Filter γ} [IsTrans α r] [NeBot l]
(h : l.IsBoundedUnder r u) : l.IsCoboundedUnder (flip r) u :=
h.isCobounded_flip
theorem IsBoundedUnder.isCoboundedUnder_le {u : γ → α} {l : Filter γ} [Preorder α] [NeBot l]
(h : l.IsBoundedUnder (· ≥ ·) u) : l.IsCoboundedUnder (· ≤ ·) u :=
h.isCoboundedUnder_flip
theorem IsBoundedUnder.isCoboundedUnder_ge {u : γ → α} {l : Filter γ} [Preorder α] [NeBot l]
(h : l.IsBoundedUnder (· ≤ ·) u) : l.IsCoboundedUnder (· ≥ ·) u :=
h.isCoboundedUnder_flip
lemma isCoboundedUnder_le_of_eventually_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ᶠ i in l, x ≤ f i) :
IsCoboundedUnder (· ≤ ·) l f :=
IsBoundedUnder.isCoboundedUnder_le ⟨x, hf⟩
lemma isCoboundedUnder_ge_of_eventually_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ᶠ i in l, f i ≤ x) :
IsCoboundedUnder (· ≥ ·) l f :=
IsBoundedUnder.isCoboundedUnder_ge ⟨x, hf⟩
lemma isCoboundedUnder_le_of_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ i, x ≤ f i) :
IsCoboundedUnder (· ≤ ·) l f :=
isCoboundedUnder_le_of_eventually_le l (eventually_of_forall hf)
lemma isCoboundedUnder_ge_of_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α}
(hf : ∀ i, f i ≤ x) :
IsCoboundedUnder (· ≥ ·) l f :=
isCoboundedUnder_ge_of_eventually_le l (eventually_of_forall hf)
theorem isCobounded_bot : IsCobounded r ⊥ ↔ ∃ b, ∀ x, r b x := by simp [IsCobounded]
theorem isCobounded_top : IsCobounded r ⊤ ↔ Nonempty α := by
simp (config := { contextual := true }) [IsCobounded, eq_univ_iff_forall,
exists_true_iff_nonempty]
theorem isCobounded_principal (s : Set α) :
(𝓟 s).IsCobounded r ↔ ∃ b, ∀ a, (∀ x ∈ s, r x a) → r b a := by simp [IsCobounded, subset_def]
theorem IsCobounded.mono (h : f ≤ g) : f.IsCobounded r → g.IsCobounded r
| ⟨b, hb⟩ => ⟨b, fun a ha => hb a (h ha)⟩
end Relation
section add_and_sum
open Filter BigOperators Set
variable {α : Type*} {f : Filter α}
variable {R : Type*}
lemma isBoundedUnder_sum {κ : Type*} [AddCommMonoid R] {r : R → R → Prop}
(hr : ∀ (v₁ v₂ : α → R), f.IsBoundedUnder r v₁ → f.IsBoundedUnder r v₂
→ f.IsBoundedUnder r (v₁ + v₂)) (hr₀ : r 0 0)
{u : κ → α → R} (s : Finset κ) (h : ∀ k ∈ s, f.IsBoundedUnder r (u k)) :
f.IsBoundedUnder r (∑ k ∈ s, u k) := by
induction s using Finset.cons_induction
case empty =>
rw [Finset.sum_empty]
exact ⟨0, by simp_all only [eventually_map, Pi.zero_apply, eventually_true]⟩
case cons k₀ s k₀_notin_s ih =>
simp only [Finset.forall_mem_cons] at *
simpa only [Finset.sum_cons] using hr _ _ h.1 (ih h.2)
variable [Preorder R]
lemma isBoundedUnder_ge_add [Add R]
[CovariantClass R R (fun a b ↦ a + b) (· ≤ ·)] [CovariantClass R R (fun a b ↦ b + a) (· ≤ ·)]
{u v : α → R} (u_bdd_ge : f.IsBoundedUnder (· ≥ ·) u) (v_bdd_ge : f.IsBoundedUnder (· ≥ ·) v) :
f.IsBoundedUnder (· ≥ ·) (u + v) := by
obtain ⟨U, hU⟩ := u_bdd_ge
obtain ⟨V, hV⟩ := v_bdd_ge
use U + V
simp only [eventually_map, Pi.add_apply] at hU hV ⊢
filter_upwards [hU, hV] with a hu hv using add_le_add hu hv
lemma isBoundedUnder_le_add [Add R]
[CovariantClass R R (fun a b ↦ a + b) (· ≤ ·)] [CovariantClass R R (fun a b ↦ b + a) (· ≤ ·)]
{u v : α → R} (u_bdd_le : f.IsBoundedUnder (· ≤ ·) u) (v_bdd_le : f.IsBoundedUnder (· ≤ ·) v) :
f.IsBoundedUnder (· ≤ ·) (u + v) := by
obtain ⟨U, hU⟩ := u_bdd_le
obtain ⟨V, hV⟩ := v_bdd_le
use U + V
simp only [eventually_map, Pi.add_apply] at hU hV ⊢
filter_upwards [hU, hV] with a hu hv using add_le_add hu hv
lemma isBoundedUnder_le_sum {κ : Type*} [AddCommMonoid R]
[CovariantClass R R (fun a b ↦ a + b) (· ≤ ·)] [CovariantClass R R (fun a b ↦ b + a) (· ≤ ·)]
{u : κ → α → R} (s : Finset κ) :
(∀ k ∈ s, f.IsBoundedUnder (· ≤ ·) (u k)) → f.IsBoundedUnder (· ≤ ·) (∑ k ∈ s, u k) := by
apply isBoundedUnder_sum (fun _ _ ↦ isBoundedUnder_le_add) le_rfl
lemma isBoundedUnder_ge_sum {κ : Type*} [AddCommMonoid R]
[CovariantClass R R (fun a b ↦ a + b) (· ≤ ·)] [CovariantClass R R (fun a b ↦ b + a) (· ≤ ·)]
{u : κ → α → R} (s : Finset κ) :
(∀ k ∈ s, f.IsBoundedUnder (· ≥ ·) (u k)) →
f.IsBoundedUnder (· ≥ ·) (∑ k ∈ s, u k) := by
haveI aux : CovariantClass R R (fun a b ↦ a + b) (· ≥ ·) :=
{ elim := fun x _ _ hy ↦ add_le_add_left hy x }
apply isBoundedUnder_sum (fun _ _ ↦ isBoundedUnder_ge_add) le_rfl
end add_and_sum
section Nonempty
variable [Preorder α] [Nonempty α] {f : Filter β} {u : β → α}
theorem isBounded_le_atBot : (atBot : Filter α).IsBounded (· ≤ ·) :=
‹Nonempty α›.elim fun a => ⟨a, eventually_le_atBot _⟩
theorem isBounded_ge_atTop : (atTop : Filter α).IsBounded (· ≥ ·) :=
‹Nonempty α›.elim fun a => ⟨a, eventually_ge_atTop _⟩
theorem Tendsto.isBoundedUnder_le_atBot (h : Tendsto u f atBot) : f.IsBoundedUnder (· ≤ ·) u :=
isBounded_le_atBot.mono h
theorem Tendsto.isBoundedUnder_ge_atTop (h : Tendsto u f atTop) : f.IsBoundedUnder (· ≥ ·) u :=
isBounded_ge_atTop.mono h
theorem bddAbove_range_of_tendsto_atTop_atBot [IsDirected α (· ≤ ·)] {u : ℕ → α}
(hx : Tendsto u atTop atBot) : BddAbove (Set.range u) :=
hx.isBoundedUnder_le_atBot.bddAbove_range
theorem bddBelow_range_of_tendsto_atTop_atTop [IsDirected α (· ≥ ·)] {u : ℕ → α}
(hx : Tendsto u atTop atTop) : BddBelow (Set.range u) :=
hx.isBoundedUnder_ge_atTop.bddBelow_range
end Nonempty
theorem isCobounded_le_of_bot [Preorder α] [OrderBot α] {f : Filter α} : f.IsCobounded (· ≤ ·) :=
⟨⊥, fun _ _ => bot_le⟩
theorem isCobounded_ge_of_top [Preorder α] [OrderTop α] {f : Filter α} : f.IsCobounded (· ≥ ·) :=
⟨⊤, fun _ _ => le_top⟩
theorem isBounded_le_of_top [Preorder α] [OrderTop α] {f : Filter α} : f.IsBounded (· ≤ ·) :=
⟨⊤, eventually_of_forall fun _ => le_top⟩
theorem isBounded_ge_of_bot [Preorder α] [OrderBot α] {f : Filter α} : f.IsBounded (· ≥ ·) :=
⟨⊥, eventually_of_forall fun _ => bot_le⟩
@[simp]
theorem _root_.OrderIso.isBoundedUnder_le_comp [Preorder α] [Preorder β] (e : α ≃o β) {l : Filter γ}
{u : γ → α} : (IsBoundedUnder (· ≤ ·) l fun x => e (u x)) ↔ IsBoundedUnder (· ≤ ·) l u :=
(Function.Surjective.exists e.surjective).trans <|
exists_congr fun a => by simp only [eventually_map, e.le_iff_le]
@[simp]
theorem _root_.OrderIso.isBoundedUnder_ge_comp [Preorder α] [Preorder β] (e : α ≃o β) {l : Filter γ}
{u : γ → α} : (IsBoundedUnder (· ≥ ·) l fun x => e (u x)) ↔ IsBoundedUnder (· ≥ ·) l u :=
OrderIso.isBoundedUnder_le_comp e.dual
@[to_additive (attr := simp)]
theorem isBoundedUnder_le_inv [OrderedCommGroup α] {l : Filter β} {u : β → α} :
(IsBoundedUnder (· ≤ ·) l fun x => (u x)⁻¹) ↔ IsBoundedUnder (· ≥ ·) l u :=
(OrderIso.inv α).isBoundedUnder_ge_comp
@[to_additive (attr := simp)]
theorem isBoundedUnder_ge_inv [OrderedCommGroup α] {l : Filter β} {u : β → α} :
(IsBoundedUnder (· ≥ ·) l fun x => (u x)⁻¹) ↔ IsBoundedUnder (· ≤ ·) l u :=
(OrderIso.inv α).isBoundedUnder_le_comp
theorem IsBoundedUnder.sup [SemilatticeSup α] {f : Filter β} {u v : β → α} :
f.IsBoundedUnder (· ≤ ·) u →
f.IsBoundedUnder (· ≤ ·) v → f.IsBoundedUnder (· ≤ ·) fun a => u a ⊔ v a
| ⟨bu, (hu : ∀ᶠ x in f, u x ≤ bu)⟩, ⟨bv, (hv : ∀ᶠ x in f, v x ≤ bv)⟩ =>
⟨bu ⊔ bv, show ∀ᶠ x in f, u x ⊔ v x ≤ bu ⊔ bv
by filter_upwards [hu, hv] with _ using sup_le_sup⟩
@[simp]
theorem isBoundedUnder_le_sup [SemilatticeSup α] {f : Filter β} {u v : β → α} :
(f.IsBoundedUnder (· ≤ ·) fun a => u a ⊔ v a) ↔
f.IsBoundedUnder (· ≤ ·) u ∧ f.IsBoundedUnder (· ≤ ·) v :=
⟨fun h =>
⟨h.mono_le <| eventually_of_forall fun _ => le_sup_left,
h.mono_le <| eventually_of_forall fun _ => le_sup_right⟩,
fun h => h.1.sup h.2⟩
theorem IsBoundedUnder.inf [SemilatticeInf α] {f : Filter β} {u v : β → α} :
f.IsBoundedUnder (· ≥ ·) u →
f.IsBoundedUnder (· ≥ ·) v → f.IsBoundedUnder (· ≥ ·) fun a => u a ⊓ v a :=
IsBoundedUnder.sup (α := αᵒᵈ)
@[simp]
theorem isBoundedUnder_ge_inf [SemilatticeInf α] {f : Filter β} {u v : β → α} :
(f.IsBoundedUnder (· ≥ ·) fun a => u a ⊓ v a) ↔
f.IsBoundedUnder (· ≥ ·) u ∧ f.IsBoundedUnder (· ≥ ·) v :=
isBoundedUnder_le_sup (α := αᵒᵈ)
theorem isBoundedUnder_le_abs [LinearOrderedAddCommGroup α] {f : Filter β} {u : β → α} :
(f.IsBoundedUnder (· ≤ ·) fun a => |u a|) ↔
f.IsBoundedUnder (· ≤ ·) u ∧ f.IsBoundedUnder (· ≥ ·) u :=
isBoundedUnder_le_sup.trans <| and_congr Iff.rfl isBoundedUnder_le_neg
/-- Filters are automatically bounded or cobounded in complete lattices. To use the same statements
in complete and conditionally complete lattices but let automation fill automatically the
boundedness proofs in complete lattices, we use the tactic `isBoundedDefault` in the statements,
in the form `(hf : f.IsBounded (≥) := by isBoundedDefault)`. -/
macro "isBoundedDefault" : tactic =>
`(tactic| first
| apply isCobounded_le_of_bot
| apply isCobounded_ge_of_top
| apply isBounded_le_of_top
| apply isBounded_ge_of_bot
| assumption)
-- Porting note: The above is a lean 4 reconstruction of (note that applyc is not available (yet?)):
-- unsafe def is_bounded_default : tactic Unit :=
-- tactic.applyc `` is_cobounded_le_of_bot <|>
-- tactic.applyc `` is_cobounded_ge_of_top <|>
-- tactic.applyc `` is_bounded_le_of_top <|> tactic.applyc `` is_bounded_ge_of_bot
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α]
-- Porting note: Renamed from Limsup and Liminf to limsSup and limsInf
/-- The `limsSup` of a filter `f` is the infimum of the `a` such that, eventually for `f`,
holds `x ≤ a`. -/
def limsSup (f : Filter α) : α :=
sInf { a | ∀ᶠ n in f, n ≤ a }
/-- The `limsInf` of a filter `f` is the supremum of the `a` such that, eventually for `f`,
holds `x ≥ a`. -/
def limsInf (f : Filter α) : α :=
sSup { a | ∀ᶠ n in f, a ≤ n }
/-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that,
eventually for `f`, holds `u x ≤ a`. -/
def limsup (u : β → α) (f : Filter β) : α :=
limsSup (map u f)
/-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that,
eventually for `f`, holds `u x ≥ a`. -/
def liminf (u : β → α) (f : Filter β) : α :=
limsInf (map u f)
/-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum
of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/
def blimsup (u : β → α) (f : Filter β) (p : β → Prop) :=
sInf { a | ∀ᶠ x in f, p x → u x ≤ a }
/-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum
of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/
def bliminf (u : β → α) (f : Filter β) (p : β → Prop) :=
sSup { a | ∀ᶠ x in f, p x → a ≤ u x }
section
variable {f : Filter β} {u : β → α} {p : β → Prop}
theorem limsup_eq : limsup u f = sInf { a | ∀ᶠ n in f, u n ≤ a } :=
rfl
theorem liminf_eq : liminf u f = sSup { a | ∀ᶠ n in f, a ≤ u n } :=
rfl
theorem blimsup_eq : blimsup u f p = sInf { a | ∀ᶠ x in f, p x → u x ≤ a } :=
rfl
theorem bliminf_eq : bliminf u f p = sSup { a | ∀ᶠ x in f, p x → a ≤ u x } :=
rfl
lemma liminf_comp (u : β → α) (v : γ → β) (f : Filter γ) :
liminf (u ∘ v) f = liminf u (map v f) := rfl
lemma limsup_comp (u : β → α) (v : γ → β) (f : Filter γ) :
limsup (u ∘ v) f = limsup u (map v f) := rfl
end
@[simp]
theorem blimsup_true (f : Filter β) (u : β → α) : (blimsup u f fun _ => True) = limsup u f := by
simp [blimsup_eq, limsup_eq]
@[simp]
theorem bliminf_true (f : Filter β) (u : β → α) : (bliminf u f fun _ => True) = liminf u f := by
simp [bliminf_eq, liminf_eq]
lemma blimsup_eq_limsup {f : Filter β} {u : β → α} {p : β → Prop} :
blimsup u f p = limsup u (f ⊓ 𝓟 {x | p x}) := by
simp only [blimsup_eq, limsup_eq, eventually_inf_principal, mem_setOf_eq]
lemma bliminf_eq_liminf {f : Filter β} {u : β → α} {p : β → Prop} :
bliminf u f p = liminf u (f ⊓ 𝓟 {x | p x}) :=
blimsup_eq_limsup (α := αᵒᵈ)
theorem blimsup_eq_limsup_subtype {f : Filter β} {u : β → α} {p : β → Prop} :
blimsup u f p = limsup (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := by
rw [blimsup_eq_limsup, limsup, limsup, ← map_map, map_comap_setCoe_val]
theorem bliminf_eq_liminf_subtype {f : Filter β} {u : β → α} {p : β → Prop} :
bliminf u f p = liminf (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) :=
blimsup_eq_limsup_subtype (α := αᵒᵈ)
theorem limsSup_le_of_le {f : Filter α} {a}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ᶠ n in f, n ≤ a) : limsSup f ≤ a :=
csInf_le hf h
theorem le_limsInf_of_le {f : Filter α} {a}
(hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ᶠ n in f, a ≤ n) : a ≤ limsInf f :=
le_csSup hf h
theorem limsup_le_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : ∀ᶠ n in f, u n ≤ a) : limsup u f ≤ a :=
csInf_le hf h
theorem le_liminf_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : ∀ᶠ n in f, a ≤ u n) : a ≤ liminf u f :=
le_csSup hf h
theorem le_limsSup_of_le {f : Filter α} {a}
(hf : f.IsBounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) : a ≤ limsSup f :=
le_csInf hf h
theorem limsInf_le_of_le {f : Filter α} {a}
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) : limsInf f ≤ a :=
csSup_le hf h
theorem le_limsup_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) : a ≤ limsup u f :=
le_csInf hf h
theorem liminf_le_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) : liminf u f ≤ a :=
csSup_le hf h
theorem limsInf_le_limsSup {f : Filter α} [NeBot f]
(h₁ : f.IsBounded (· ≤ ·) := by isBoundedDefault)
(h₂ : f.IsBounded (· ≥ ·) := by isBoundedDefault) :
limsInf f ≤ limsSup f :=
liminf_le_of_le h₂ fun a₀ ha₀ =>
le_limsup_of_le h₁ fun a₁ ha₁ =>
show a₀ ≤ a₁ from
let ⟨_, hb₀, hb₁⟩ := (ha₀.and ha₁).exists
le_trans hb₀ hb₁
theorem liminf_le_limsup {f : Filter β} [NeBot f] {u : β → α}
(h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
liminf u f ≤ limsup u f :=
limsInf_le_limsSup h h'
theorem limsSup_le_limsSup {f g : Filter α}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(hg : g.IsBounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : limsSup f ≤ limsSup g :=
csInf_le_csInf hf hg h
theorem limsInf_le_limsInf {f g : Filter α}
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : limsInf f ≤ limsInf g :=
csSup_le_csSup hg hf h
theorem limsup_le_limsup {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : u ≤ᶠ[f] v)
(hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(hv : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) :
limsup u f ≤ limsup v f :=
limsSup_le_limsSup hu hv fun _ => h.trans
theorem liminf_le_liminf {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a ≤ v a)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(hv : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) :
liminf u f ≤ liminf v f :=
limsup_le_limsup (β := βᵒᵈ) h hv hu
theorem limsSup_le_limsSup_of_le {f g : Filter α} (h : f ≤ g)
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) :
limsSup f ≤ limsSup g :=
limsSup_le_limsSup hf hg fun _ ha => h ha
theorem limsInf_le_limsInf_of_le {f g : Filter α} (h : g ≤ f)
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) :
limsInf f ≤ limsInf g :=
limsInf_le_limsInf hf hg fun _ ha => h ha
theorem limsup_le_limsup_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : f ≤ g)
{u : α → β}
(hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(hg : g.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
limsup u f ≤ limsup u g :=
limsSup_le_limsSup_of_le (map_mono h) hf hg
theorem liminf_le_liminf_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : g ≤ f)
{u : α → β}
(hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(hg : g.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) :
liminf u f ≤ liminf u g :=
limsInf_le_limsInf_of_le (map_mono h) hf hg
theorem limsSup_principal {s : Set α} (h : BddAbove s) (hs : s.Nonempty) :
limsSup (𝓟 s) = sSup s := by
simp only [limsSup, eventually_principal]; exact csInf_upper_bounds_eq_csSup h hs
theorem limsInf_principal {s : Set α} (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s :=
limsSup_principal (α := αᵒᵈ) h hs
theorem limsup_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f := by
rw [limsup_eq]
congr with b
exact eventually_congr (h.mono fun x hx => by simp [hx])
theorem blimsup_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) :
blimsup u f p = blimsup v f p := by
simpa only [blimsup_eq_limsup] using limsup_congr <| eventually_inf_principal.2 h
theorem bliminf_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) :
bliminf u f p = bliminf v f p :=
blimsup_congr (α := αᵒᵈ) h
theorem liminf_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : liminf u f = liminf v f :=
limsup_congr (β := βᵒᵈ) h
@[simp]
theorem limsup_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f]
(b : β) : limsup (fun _ => b) f = b := by
simpa only [limsup_eq, eventually_const] using csInf_Ici
@[simp]
theorem liminf_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f]
(b : β) : liminf (fun _ => b) f = b :=
limsup_const (β := βᵒᵈ) b
theorem HasBasis.liminf_eq_sSup_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) :
liminf f v = sSup (⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i)) := by
simp_rw [liminf_eq, hv.eventually_iff]
congr
ext x
simp only [mem_setOf_eq, iInter_coe_set, mem_iUnion, mem_iInter, mem_Iic, Subtype.exists,
exists_prop]
theorem HasBasis.liminf_eq_sSup_univ_of_empty {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) :
liminf f v = sSup univ := by
simp [hv.eq_bot_iff.2 ⟨i, hi, h'i⟩, liminf_eq]
theorem HasBasis.limsup_eq_sInf_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) :
limsup f v = sInf (⋃ (j : Subtype p), ⋂ (i : s j), Ici (f i)) :=
HasBasis.liminf_eq_sSup_iUnion_iInter (α := αᵒᵈ) hv
theorem HasBasis.limsup_eq_sInf_univ_of_empty {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) :
limsup f v = sInf univ :=
HasBasis.liminf_eq_sSup_univ_of_empty (α := αᵒᵈ) hv i hi h'i
-- Porting note: simp_nf linter incorrectly says: lhs does not simplify when using simp on itself.
@[simp, nolint simpNF]
theorem liminf_nat_add (f : ℕ → α) (k : ℕ) :
liminf (fun i => f (i + k)) atTop = liminf f atTop := by
change liminf (f ∘ (· + k)) atTop = liminf f atTop
rw [liminf, liminf, ← map_map, map_add_atTop_eq_nat]
-- Porting note: simp_nf linter incorrectly says: lhs does not simplify when using simp on itself.
@[simp, nolint simpNF]
theorem limsup_nat_add (f : ℕ → α) (k : ℕ) : limsup (fun i => f (i + k)) atTop = limsup f atTop :=
@liminf_nat_add αᵒᵈ _ f k
end ConditionallyCompleteLattice
section CompleteLattice
variable [CompleteLattice α]
@[simp]
theorem limsSup_bot : limsSup (⊥ : Filter α) = ⊥ :=
bot_unique <| sInf_le <| by simp
@[simp] theorem limsup_bot (f : β → α) : limsup f ⊥ = ⊥ := by simp [limsup]
@[simp]
theorem limsInf_bot : limsInf (⊥ : Filter α) = ⊤ :=
top_unique <| le_sSup <| by simp
@[simp] theorem liminf_bot (f : β → α) : liminf f ⊥ = ⊤ := by simp [liminf]
@[simp]
theorem limsSup_top : limsSup (⊤ : Filter α) = ⊤ :=
top_unique <| le_sInf <| by simp [eq_univ_iff_forall]; exact fun b hb => top_unique <| hb _
@[simp]
theorem limsInf_top : limsInf (⊤ : Filter α) = ⊥ :=
bot_unique <| sSup_le <| by simp [eq_univ_iff_forall]; exact fun b hb => bot_unique <| hb _
@[simp]
theorem blimsup_false {f : Filter β} {u : β → α} : (blimsup u f fun _ => False) = ⊥ := by
simp [blimsup_eq]
@[simp]
theorem bliminf_false {f : Filter β} {u : β → α} : (bliminf u f fun _ => False) = ⊤ := by
simp [bliminf_eq]
/-- Same as limsup_const applied to `⊥` but without the `NeBot f` assumption -/
@[simp]
theorem limsup_const_bot {f : Filter β} : limsup (fun _ : β => (⊥ : α)) f = (⊥ : α) := by
rw [limsup_eq, eq_bot_iff]
exact sInf_le (eventually_of_forall fun _ => le_rfl)
/-- Same as limsup_const applied to `⊤` but without the `NeBot f` assumption -/
@[simp]
theorem liminf_const_top {f : Filter β} : liminf (fun _ : β => (⊤ : α)) f = (⊤ : α) :=
limsup_const_bot (α := αᵒᵈ)
theorem HasBasis.limsSup_eq_iInf_sSup {ι} {p : ι → Prop} {s} {f : Filter α} (h : f.HasBasis p s) :
limsSup f = ⨅ (i) (_ : p i), sSup (s i) :=
le_antisymm (le_iInf₂ fun i hi => sInf_le <| h.eventually_iff.2 ⟨i, hi, fun _ => le_sSup⟩)
(le_sInf fun _ ha =>
let ⟨_, hi, ha⟩ := h.eventually_iff.1 ha
iInf₂_le_of_le _ hi <| sSup_le ha)
theorem HasBasis.limsInf_eq_iSup_sInf {p : ι → Prop} {s : ι → Set α} {f : Filter α}
(h : f.HasBasis p s) : limsInf f = ⨆ (i) (_ : p i), sInf (s i) :=
HasBasis.limsSup_eq_iInf_sSup (α := αᵒᵈ) h
theorem limsSup_eq_iInf_sSup {f : Filter α} : limsSup f = ⨅ s ∈ f, sSup s :=
f.basis_sets.limsSup_eq_iInf_sSup
theorem limsInf_eq_iSup_sInf {f : Filter α} : limsInf f = ⨆ s ∈ f, sInf s :=
limsSup_eq_iInf_sSup (α := αᵒᵈ)
theorem limsup_le_iSup {f : Filter β} {u : β → α} : limsup u f ≤ ⨆ n, u n :=
limsup_le_of_le (by isBoundedDefault) (eventually_of_forall (le_iSup u))
theorem iInf_le_liminf {f : Filter β} {u : β → α} : ⨅ n, u n ≤ liminf u f :=
le_liminf_of_le (by isBoundedDefault) (eventually_of_forall (iInf_le u))
/-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem limsup_eq_iInf_iSup {f : Filter β} {u : β → α} : limsup u f = ⨅ s ∈ f, ⨆ a ∈ s, u a :=
(f.basis_sets.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id]
theorem limsup_eq_iInf_iSup_of_nat {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i ≥ n, u i :=
(atTop_basis.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, iInf_const]; rfl
theorem limsup_eq_iInf_iSup_of_nat' {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) := by
simp only [limsup_eq_iInf_iSup_of_nat, iSup_ge_eq_iSup_nat_add]
theorem HasBasis.limsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(h : f.HasBasis p s) : limsup u f = ⨅ (i) (_ : p i), ⨆ a ∈ s i, u a :=
(h.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id]
theorem blimsup_congr' {f : Filter β} {p q : β → Prop} {u : β → α}
(h : ∀ᶠ x in f, u x ≠ ⊥ → (p x ↔ q x)) : blimsup u f p = blimsup u f q := by
simp only [blimsup_eq]
congr with a
refine eventually_congr (h.mono fun b hb => ?_)
rcases eq_or_ne (u b) ⊥ with hu | hu; · simp [hu]
rw [hb hu]
theorem bliminf_congr' {f : Filter β} {p q : β → Prop} {u : β → α}
(h : ∀ᶠ x in f, u x ≠ ⊤ → (p x ↔ q x)) : bliminf u f p = bliminf u f q :=
blimsup_congr' (α := αᵒᵈ) h
lemma HasBasis.blimsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(hf : f.HasBasis p s) {q : β → Prop} :
blimsup u f q = ⨅ (i) (_ : p i), ⨆ a ∈ s i, ⨆ (_ : q a), u a := by
simp only [blimsup_eq_limsup, (hf.inf_principal _).limsup_eq_iInf_iSup, mem_inter_iff, iSup_and,
mem_setOf_eq]
theorem blimsup_eq_iInf_biSup {f : Filter β} {p : β → Prop} {u : β → α} :
blimsup u f p = ⨅ s ∈ f, ⨆ (b) (_ : p b ∧ b ∈ s), u b := by
simp only [f.basis_sets.blimsup_eq_iInf_iSup, iSup_and', id, and_comm]
theorem blimsup_eq_iInf_biSup_of_nat {p : ℕ → Prop} {u : ℕ → α} :
blimsup u atTop p = ⨅ i, ⨆ (j) (_ : p j ∧ i ≤ j), u j := by
simp only [atTop_basis.blimsup_eq_iInf_iSup, @and_comm (p _), iSup_and, mem_Ici, iInf_true]
/-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem liminf_eq_iSup_iInf {f : Filter β} {u : β → α} : liminf u f = ⨆ s ∈ f, ⨅ a ∈ s, u a :=
limsup_eq_iInf_iSup (α := αᵒᵈ)
theorem liminf_eq_iSup_iInf_of_nat {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i ≥ n, u i :=
@limsup_eq_iInf_iSup_of_nat αᵒᵈ _ u
theorem liminf_eq_iSup_iInf_of_nat' {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) :=
@limsup_eq_iInf_iSup_of_nat' αᵒᵈ _ _
theorem HasBasis.liminf_eq_iSup_iInf {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(h : f.HasBasis p s) : liminf u f = ⨆ (i) (_ : p i), ⨅ a ∈ s i, u a :=
HasBasis.limsup_eq_iInf_iSup (α := αᵒᵈ) h
theorem bliminf_eq_iSup_biInf {f : Filter β} {p : β → Prop} {u : β → α} :
bliminf u f p = ⨆ s ∈ f, ⨅ (b) (_ : p b ∧ b ∈ s), u b :=
@blimsup_eq_iInf_biSup αᵒᵈ β _ f p u
theorem bliminf_eq_iSup_biInf_of_nat {p : ℕ → Prop} {u : ℕ → α} :
bliminf u atTop p = ⨆ i, ⨅ (j) (_ : p j ∧ i ≤ j), u j :=
@blimsup_eq_iInf_biSup_of_nat αᵒᵈ _ p u
theorem limsup_eq_sInf_sSup {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) :
limsup a F = sInf ((fun I => sSup (a '' I)) '' F.sets) := by
apply le_antisymm
· rw [limsup_eq]
refine sInf_le_sInf fun x hx => ?_
rcases (mem_image _ F.sets x).mp hx with ⟨I, ⟨I_mem_F, hI⟩⟩
filter_upwards [I_mem_F] with i hi
exact hI ▸ le_sSup (mem_image_of_mem _ hi)
· refine le_sInf fun b hb => sInf_le_of_le (mem_image_of_mem _ hb) <| sSup_le ?_
rintro _ ⟨_, h, rfl⟩
exact h
theorem liminf_eq_sSup_sInf {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) :
liminf a F = sSup ((fun I => sInf (a '' I)) '' F.sets) :=
@Filter.limsup_eq_sInf_sSup ι (OrderDual R) _ _ a
theorem liminf_le_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β}
(h : ∃ᶠ a in f, u a ≤ x) : liminf u f ≤ x := by
rw [liminf_eq]
refine sSup_le fun b hb => ?_
have hbx : ∃ᶠ _ in f, b ≤ x := by
revert h
rw [← not_imp_not, not_frequently, not_frequently]
exact fun h => hb.mp (h.mono fun a hbx hba hax => hbx (hba.trans hax))
exact hbx.exists.choose_spec
theorem le_limsup_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β}
(h : ∃ᶠ a in f, x ≤ u a) : x ≤ limsup u f :=
liminf_le_of_frequently_le' (β := βᵒᵈ) h
/-- If `f : α → α` is a morphism of complete lattices, then the limsup of its iterates of any
`a : α` is a fixed point. -/
@[simp]
theorem _root_.CompleteLatticeHom.apply_limsup_iterate (f : CompleteLatticeHom α α) (a : α) :
f (limsup (fun n => f^[n] a) atTop) = limsup (fun n => f^[n] a) atTop := by
rw [limsup_eq_iInf_iSup_of_nat', map_iInf]
simp_rw [_root_.map_iSup, ← Function.comp_apply (f := f), ← Function.iterate_succ' f,
← Nat.add_succ]
conv_rhs => rw [iInf_split _ (0 < ·)]
simp only [not_lt, Nat.le_zero, iInf_iInf_eq_left, add_zero, iInf_nat_gt_zero_eq, left_eq_inf]
refine (iInf_le (fun i => ⨆ j, f^[j + (i + 1)] a) 0).trans ?_
simp only [zero_add, Function.comp_apply, iSup_le_iff]
exact fun i => le_iSup (fun i => f^[i] a) (i + 1)
@[deprecated (since := "2024-07-21")]
alias CompleteLatticeHom.apply_limsup_iterate := CompleteLatticeHom.apply_limsup_iterate
/-- If `f : α → α` is a morphism of complete lattices, then the liminf of its iterates of any
`a : α` is a fixed point. -/
theorem _root_.CompleteLatticeHom.apply_liminf_iterate (f : CompleteLatticeHom α α) (a : α) :
f (liminf (fun n => f^[n] a) atTop) = liminf (fun n => f^[n] a) atTop :=
(CompleteLatticeHom.dual f).apply_limsup_iterate _
@[deprecated (since := "2024-07-21")]
alias CompleteLatticeHom.apply_liminf_iterate := CompleteLatticeHom.apply_liminf_iterate
variable {f g : Filter β} {p q : β → Prop} {u v : β → α}
theorem blimsup_mono (h : ∀ x, p x → q x) : blimsup u f p ≤ blimsup u f q :=
sInf_le_sInf fun a ha => ha.mono <| by tauto
theorem bliminf_antitone (h : ∀ x, p x → q x) : bliminf u f q ≤ bliminf u f p :=
sSup_le_sSup fun a ha => ha.mono <| by tauto
theorem mono_blimsup' (h : ∀ᶠ x in f, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p :=
sInf_le_sInf fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.2 hx').trans (hx.1 hx')
theorem mono_blimsup (h : ∀ x, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p :=
mono_blimsup' <| eventually_of_forall h
theorem mono_bliminf' (h : ∀ᶠ x in f, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p :=
sSup_le_sSup fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.1 hx').trans (hx.2 hx')
theorem mono_bliminf (h : ∀ x, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p :=
mono_bliminf' <| eventually_of_forall h
theorem bliminf_antitone_filter (h : f ≤ g) : bliminf u g p ≤ bliminf u f p :=
sSup_le_sSup fun _ ha => ha.filter_mono h
theorem blimsup_monotone_filter (h : f ≤ g) : blimsup u f p ≤ blimsup u g p :=
sInf_le_sInf fun _ ha => ha.filter_mono h
-- @[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux versions below
theorem blimsup_and_le_inf : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p ⊓ blimsup u f q :=
le_inf (blimsup_mono <| by tauto) (blimsup_mono <| by tauto)
@[simp]
theorem bliminf_sup_le_inf_aux_left :
(blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p :=
blimsup_and_le_inf.trans inf_le_left
@[simp]
theorem bliminf_sup_le_inf_aux_right :
(blimsup u f fun x => p x ∧ q x) ≤ blimsup u f q :=
blimsup_and_le_inf.trans inf_le_right
-- @[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux simp version below
theorem bliminf_sup_le_and : bliminf u f p ⊔ bliminf u f q ≤ bliminf u f fun x => p x ∧ q x :=
blimsup_and_le_inf (α := αᵒᵈ)
@[simp]
theorem bliminf_sup_le_and_aux_left : bliminf u f p ≤ bliminf u f fun x => p x ∧ q x :=
le_sup_left.trans bliminf_sup_le_and
@[simp]
theorem bliminf_sup_le_and_aux_right : bliminf u f q ≤ bliminf u f fun x => p x ∧ q x :=
le_sup_right.trans bliminf_sup_le_and
/-- See also `Filter.blimsup_or_eq_sup`. -/
-- @[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux simp versions below
theorem blimsup_sup_le_or : blimsup u f p ⊔ blimsup u f q ≤ blimsup u f fun x => p x ∨ q x :=
sup_le (blimsup_mono <| by tauto) (blimsup_mono <| by tauto)
@[simp]
theorem bliminf_sup_le_or_aux_left : blimsup u f p ≤ blimsup u f fun x => p x ∨ q x :=
le_sup_left.trans blimsup_sup_le_or
@[simp]
theorem bliminf_sup_le_or_aux_right : blimsup u f q ≤ blimsup u f fun x => p x ∨ q x :=
le_sup_right.trans blimsup_sup_le_or
/-- See also `Filter.bliminf_or_eq_inf`. -/
--@[simp] -- Porting note: simp_nf linter, lhs simplifies, added _aux simp versions below
theorem bliminf_or_le_inf : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p ⊓ bliminf u f q :=
blimsup_sup_le_or (α := αᵒᵈ)
@[simp]
theorem bliminf_or_le_inf_aux_left : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p :=
bliminf_or_le_inf.trans inf_le_left
@[simp]
theorem bliminf_or_le_inf_aux_right : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f q :=
bliminf_or_le_inf.trans inf_le_right
theorem _root_.OrderIso.apply_blimsup [CompleteLattice γ] (e : α ≃o γ) :
e (blimsup u f p) = blimsup (e ∘ u) f p := by
simp only [blimsup_eq, map_sInf, Function.comp_apply, e.image_eq_preimage,
Set.preimage_setOf_eq, e.le_symm_apply]
@[deprecated (since := "2024-07-21")]
alias OrderIso.apply_blimsup := OrderIso.apply_blimsup
theorem _root_.OrderIso.apply_bliminf [CompleteLattice γ] (e : α ≃o γ) :
e (bliminf u f p) = bliminf (e ∘ u) f p :=
e.dual.apply_blimsup
@[deprecated (since := "2024-07-21")]
alias OrderIso.apply_bliminf := OrderIso.apply_bliminf
theorem _root_.sSupHom.apply_blimsup_le [CompleteLattice γ] (g : sSupHom α γ) :
g (blimsup u f p) ≤ blimsup (g ∘ u) f p := by
simp only [blimsup_eq_iInf_biSup, Function.comp]
refine ((OrderHomClass.mono g).map_iInf₂_le _).trans ?_
simp only [_root_.map_iSup, le_refl]
@[deprecated (since := "2024-07-21")]
alias SupHom.apply_blimsup_le := sSupHom.apply_blimsup_le
theorem _root_.sInfHom.le_apply_bliminf [CompleteLattice γ] (g : sInfHom α γ) :
bliminf (g ∘ u) f p ≤ g (bliminf u f p) :=
(sInfHom.dual g).apply_blimsup_le
@[deprecated (since := "2024-07-21")]
alias InfHom.le_apply_bliminf := sInfHom.le_apply_bliminf
end CompleteLattice
section CompleteDistribLattice
variable [CompleteDistribLattice α] {f : Filter β} {p q : β → Prop} {u : β → α}
lemma limsup_sup_filter {g} : limsup u (f ⊔ g) = limsup u f ⊔ limsup u g := by
refine le_antisymm ?_
(sup_le (limsup_le_limsup_of_le le_sup_left) (limsup_le_limsup_of_le le_sup_right))
simp_rw [limsup_eq, sInf_sup_eq, sup_sInf_eq, mem_setOf_eq, le_iInf₂_iff]
intro a ha b hb
exact sInf_le ⟨ha.mono fun _ h ↦ h.trans le_sup_left, hb.mono fun _ h ↦ h.trans le_sup_right⟩
lemma liminf_sup_filter {g} : liminf u (f ⊔ g) = liminf u f ⊓ liminf u g :=
limsup_sup_filter (α := αᵒᵈ)
@[simp]
theorem blimsup_or_eq_sup : (blimsup u f fun x => p x ∨ q x) = blimsup u f p ⊔ blimsup u f q := by
simp only [blimsup_eq_limsup, ← limsup_sup_filter, ← inf_sup_left, sup_principal, setOf_or]
@[simp]
theorem bliminf_or_eq_inf : (bliminf u f fun x => p x ∨ q x) = bliminf u f p ⊓ bliminf u f q :=
blimsup_or_eq_sup (α := αᵒᵈ)
@[simp]
lemma blimsup_sup_not : blimsup u f p ⊔ blimsup u f (¬p ·) = limsup u f := by
simp_rw [← blimsup_or_eq_sup, or_not, blimsup_true]
@[simp]
lemma bliminf_inf_not : bliminf u f p ⊓ bliminf u f (¬p ·) = liminf u f :=
blimsup_sup_not (α := αᵒᵈ)
@[simp]
lemma blimsup_not_sup : blimsup u f (¬p ·) ⊔ blimsup u f p = limsup u f := by
simpa only [not_not] using blimsup_sup_not (p := (¬p ·))
@[simp]
lemma bliminf_not_inf : bliminf u f (¬p ·) ⊓ bliminf u f p = liminf u f :=
blimsup_not_sup (α := αᵒᵈ)
lemma limsup_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} :
limsup (s.piecewise u v) f = blimsup u f (· ∈ s) ⊔ blimsup v f (· ∉ s) := by
rw [← blimsup_sup_not (p := (· ∈ s))]
refine congr_arg₂ _ (blimsup_congr ?_) (blimsup_congr ?_) <;>
filter_upwards with _ h using by simp [h]
lemma liminf_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} :
liminf (s.piecewise u v) f = bliminf u f (· ∈ s) ⊓ bliminf v f (· ∉ s) :=
limsup_piecewise (α := αᵒᵈ)
theorem sup_limsup [NeBot f] (a : α) : a ⊔ limsup u f = limsup (fun x => a ⊔ u x) f := by
simp only [limsup_eq_iInf_iSup, iSup_sup_eq, sup_iInf₂_eq]
congr; ext s; congr; ext hs; congr
exact (biSup_const (nonempty_of_mem hs)).symm
theorem inf_liminf [NeBot f] (a : α) : a ⊓ liminf u f = liminf (fun x => a ⊓ u x) f :=
sup_limsup (α := αᵒᵈ) a
theorem sup_liminf (a : α) : a ⊔ liminf u f = liminf (fun x => a ⊔ u x) f := by
simp only [liminf_eq_iSup_iInf]
rw [sup_comm, biSup_sup (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)]
simp_rw [iInf₂_sup_eq, sup_comm (a := a)]
theorem inf_limsup (a : α) : a ⊓ limsup u f = limsup (fun x => a ⊓ u x) f :=
sup_liminf (α := αᵒᵈ) a
end CompleteDistribLattice
section CompleteBooleanAlgebra
variable [CompleteBooleanAlgebra α] (f : Filter β) (u : β → α)
theorem limsup_compl : (limsup u f)ᶜ = liminf (compl ∘ u) f := by
simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply]
theorem liminf_compl : (liminf u f)ᶜ = limsup (compl ∘ u) f := by
simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply]
theorem limsup_sdiff (a : α) : limsup u f \ a = limsup (fun b => u b \ a) f := by
simp only [limsup_eq_iInf_iSup, sdiff_eq]
rw [biInf_inf (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)]
simp_rw [inf_comm, inf_iSup₂_eq, inf_comm]
theorem liminf_sdiff [NeBot f] (a : α) : liminf u f \ a = liminf (fun b => u b \ a) f := by
simp only [sdiff_eq, inf_comm _ aᶜ, inf_liminf]
theorem sdiff_limsup [NeBot f] (a : α) : a \ limsup u f = liminf (fun b => a \ u b) f := by
rw [← compl_inj_iff]
simp only [sdiff_eq, liminf_compl, (· ∘ ·), compl_inf, compl_compl, sup_limsup]
theorem sdiff_liminf (a : α) : a \ liminf u f = limsup (fun b => a \ u b) f := by
rw [← compl_inj_iff]
simp only [sdiff_eq, limsup_compl, (· ∘ ·), compl_inf, compl_compl, sup_liminf]
end CompleteBooleanAlgebra
section SetLattice
variable {p : ι → Prop} {s : ι → Set α} {𝓕 : Filter ι} {a : α}
lemma mem_liminf_iff_eventually_mem : (a ∈ liminf s 𝓕) ↔ (∀ᶠ i in 𝓕, a ∈ s i) := by
simpa only [liminf_eq_iSup_iInf, iSup_eq_iUnion, iInf_eq_iInter, mem_iUnion, mem_iInter]
using ⟨fun ⟨S, hS, hS'⟩ ↦ mem_of_superset hS (by tauto), fun h ↦ ⟨{i | a ∈ s i}, h, by tauto⟩⟩
lemma mem_limsup_iff_frequently_mem : (a ∈ limsup s 𝓕) ↔ (∃ᶠ i in 𝓕, a ∈ s i) := by
simp only [Filter.Frequently, iff_not_comm, ← mem_compl_iff, limsup_compl, comp_apply,
mem_liminf_iff_eventually_mem]
theorem cofinite.blimsup_set_eq :
blimsup s cofinite p = { x | { n | p n ∧ x ∈ s n }.Infinite } := by
simp only [blimsup_eq, le_eq_subset, eventually_cofinite, not_forall, sInf_eq_sInter, exists_prop]
ext x
refine ⟨fun h => ?_, fun hx t h => ?_⟩ <;> contrapose! h
· simp only [mem_sInter, mem_setOf_eq, not_forall, exists_prop]
exact ⟨{x}ᶜ, by simpa using h, by simp⟩
· exact hx.mono fun i hi => ⟨hi.1, fun hit => h (hit hi.2)⟩
theorem cofinite.bliminf_set_eq : bliminf s cofinite p = { x | { n | p n ∧ x ∉ s n }.Finite } := by
rw [← compl_inj_iff]
simp only [bliminf_eq_iSup_biInf, compl_iInf, compl_iSup, ← blimsup_eq_iInf_biSup,
cofinite.blimsup_set_eq]
rfl
/-- In other words, `limsup cofinite s` is the set of elements lying inside the family `s`
infinitely often. -/
theorem cofinite.limsup_set_eq : limsup s cofinite = { x | { n | x ∈ s n }.Infinite } := by
simp only [← cofinite.blimsup_true s, cofinite.blimsup_set_eq, true_and_iff]
/-- In other words, `liminf cofinite s` is the set of elements lying outside the family `s`
finitely often. -/
theorem cofinite.liminf_set_eq : liminf s cofinite = { x | { n | x ∉ s n }.Finite } := by
simp only [← cofinite.bliminf_true s, cofinite.bliminf_set_eq, true_and_iff]
theorem exists_forall_mem_of_hasBasis_mem_blimsup {l : Filter β} {b : ι → Set β} {q : ι → Prop}
(hl : l.HasBasis q b) {u : β → Set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) :
∃ f : { i | q i } → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by
rw [blimsup_eq_iInf_biSup] at hx
simp only [iSup_eq_iUnion, iInf_eq_iInter, mem_iInter, mem_iUnion, exists_prop] at hx
choose g hg hg' using hx
refine ⟨fun i : { i | q i } => g (b i) (hl.mem_of_mem i.2), fun i => ⟨?_, ?_⟩⟩
· exact hg' (b i) (hl.mem_of_mem i.2)
· exact hg (b i) (hl.mem_of_mem i.2)
theorem exists_forall_mem_of_hasBasis_mem_blimsup' {l : Filter β} {b : ι → Set β}
(hl : l.HasBasis (fun _ => True) b) {u : β → Set α} {p : β → Prop} {x : α}
(hx : x ∈ blimsup u l p) : ∃ f : ι → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by
obtain ⟨f, hf⟩ := exists_forall_mem_of_hasBasis_mem_blimsup hl hx
exact ⟨fun i => f ⟨i, trivial⟩, fun i => hf ⟨i, trivial⟩⟩
end SetLattice
section ConditionallyCompleteLinearOrder
theorem frequently_lt_of_lt_limsSup {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(h : a < limsSup f) : ∃ᶠ n in f, a < n := by
contrapose! h
simp only [not_frequently, not_lt] at h
exact limsSup_le_of_le hf h
theorem frequently_lt_of_limsInf_lt {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α}
(hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : limsInf f < a) : ∃ᶠ n in f, n < a :=
frequently_lt_of_lt_limsSup (α := OrderDual α) hf h
theorem eventually_lt_of_lt_liminf {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β}
{b : β} (h : b < liminf u f)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
∀ᶠ a in f, b < u a := by
obtain ⟨c, hc, hbc⟩ : ∃ (c : β) (_ : c ∈ { c : β | ∀ᶠ n : α in f, c ≤ u n }), b < c := by
simp_rw [exists_prop]
exact exists_lt_of_lt_csSup hu h
exact hc.mono fun x hx => lt_of_lt_of_le hbc hx
theorem eventually_lt_of_limsup_lt {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β}
{b : β} (h : limsup u f < b)
(hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
∀ᶠ a in f, u a < b :=
eventually_lt_of_lt_liminf (β := βᵒᵈ) h hu
theorem le_limsup_of_frequently_le {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α}
{u : α → β} {b : β} (hu_le : ∃ᶠ x in f, b ≤ u x)
(hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
b ≤ limsup u f := by
revert hu_le
rw [← not_imp_not, not_frequently]
simp_rw [← lt_iff_not_ge]
exact fun h => eventually_lt_of_limsup_lt h hu
theorem liminf_le_of_frequently_le {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α}
{u : α → β} {b : β} (hu_le : ∃ᶠ x in f, u x ≤ b)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
liminf u f ≤ b :=
le_limsup_of_frequently_le (β := βᵒᵈ) hu_le hu
theorem frequently_lt_of_lt_limsup {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α}
{u : α → β} {b : β}
(hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : b < limsup u f) : ∃ᶠ x in f, b < u x := by
contrapose! h
apply limsSup_le_of_le hu
simpa using h
theorem frequently_lt_of_liminf_lt {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α}
{u : α → β} {b : β}
(hu : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : liminf u f < b) : ∃ᶠ x in f, u x < b :=
frequently_lt_of_lt_limsup (β := βᵒᵈ) hu h
theorem limsup_le_iff {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α} {u : α → β} {x : β}
(h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(h₂ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
limsup u f ≤ x ↔ ∀ y > x, ∀ᶠ a in f, u a < y := by
refine ⟨fun h _ h' ↦ eventually_lt_of_limsup_lt (lt_of_le_of_lt h h') h₂, fun h ↦ ?_⟩
--Two cases: Either `x` is a cluster point from above, or it is not.
--In the first case, we use `forall_lt_iff_le'` and split an interval.
--In the second case, the function `u` must eventually be smaller or equal to `x`.
by_cases h' : ∀ y > x, ∃ z, x < z ∧ z < y
· rw [← forall_lt_iff_le']
intro y x_y
rcases h' y x_y with ⟨z, x_z, z_y⟩
exact lt_of_le_of_lt (limsup_le_of_le h₁ ((h z x_z).mono (fun _ ↦ le_of_lt))) z_y
· apply limsup_le_of_le h₁
set_option push_neg.use_distrib true in push_neg at h'
rcases h' with ⟨z, x_z, hz⟩
exact (h z x_z).mono <| fun w hw ↦ (or_iff_left (not_le_of_lt hw)).1 (hz (u w))
theorem le_limsup_iff {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α} {u : α → β} {x : β}
(h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(h₂ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
x ≤ limsup u f ↔ ∀ y < x, ∃ᶠ a in f, y < u a := by
refine ⟨fun h _ h' ↦ frequently_lt_of_lt_limsup h₁ (lt_of_lt_of_le h' h), fun h ↦ ?_⟩
--Two cases: Either `x` is a cluster point from below, or it is not.
--In the first case, we use `forall_lt_iff_le` and split an interval.
--In the second case, the function `u` must frequently be larger or equal to `x`.
by_cases h' : ∀ y < x, ∃ z, y < z ∧ z < x
· rw [← forall_lt_iff_le]
intro y y_x
rcases h' y y_x with ⟨z, y_z, z_x⟩
exact lt_of_lt_of_le y_z (le_limsup_of_frequently_le ((h z z_x).mono (fun _ ↦ le_of_lt)) h₂)
· apply le_limsup_of_frequently_le _ h₂
set_option push_neg.use_distrib true in push_neg at h'
rcases h' with ⟨z, z_x, hz⟩
exact (h z z_x).mono <| fun w hw ↦ (or_iff_right (not_le_of_lt hw)).1 (hz (u w))
theorem le_liminf_iff {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α} {u : α → β} {x : β}
(h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault)
(h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
x ≤ liminf u f ↔ ∀ y < x, ∀ᶠ a in f, y < u a := limsup_le_iff (β := βᵒᵈ) h₁ h₂
theorem liminf_le_iff {α β} [ConditionallyCompleteLinearOrder β] {f : Filter α} {u : α → β} {x : β}
(h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault)
(h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
liminf u f ≤ x ↔ ∀ y > x, ∃ᶠ a in f, u a < y := le_limsup_iff (β := βᵒᵈ) h₁ h₂
variable [ConditionallyCompleteLinearOrder α] {f : Filter α} {b : α}
-- The linter erroneously claims that I'm not referring to `c`
set_option linter.unusedVariables false in
theorem lt_mem_sets_of_limsSup_lt (h : f.IsBounded (· ≤ ·)) (l : f.limsSup < b) :
∀ᶠ a in f, a < b :=
let ⟨c, (h : ∀ᶠ a in f, a ≤ c), hcb⟩ := exists_lt_of_csInf_lt h l
mem_of_superset h fun _a => hcb.trans_le'
theorem gt_mem_sets_of_limsInf_gt : f.IsBounded (· ≥ ·) → b < f.limsInf → ∀ᶠ a in f, b < a :=
@lt_mem_sets_of_limsSup_lt αᵒᵈ _ _ _
section Classical
open Classical in
/-- Given an indexed family of sets `s j` over `j : Subtype p` and a function `f`, then
`liminf_reparam j` is equal to `j` if `f` is bounded below on `s j`, and otherwise to some
index `k` such that `f` is bounded below on `s k` (if there exists one).
To ensure good measurability behavior, this index `k` is chosen as the minimal suitable index.
This function is used to write down a liminf in a measurable way,
in `Filter.HasBasis.liminf_eq_ciSup_ciInf` and `Filter.HasBasis.liminf_eq_ite`. -/
noncomputable def liminf_reparam
(f : ι → α) (s : ι' → Set ι) (p : ι' → Prop) [Countable (Subtype p)] [Nonempty (Subtype p)]
(j : Subtype p) : Subtype p :=
let m : Set (Subtype p) := {j | BddBelow (range (fun (i : s j) ↦ f i))}
let g : ℕ → Subtype p := (exists_surjective_nat _).choose
have Z : ∃ n, g n ∈ m ∨ ∀ j, j ∉ m := by
by_cases H : ∃ j, j ∈ m
· rcases H with ⟨j, hj⟩
rcases (exists_surjective_nat (Subtype p)).choose_spec j with ⟨n, rfl⟩
exact ⟨n, Or.inl hj⟩
· push_neg at H
exact ⟨0, Or.inr H⟩
if j ∈ m then j else g (Nat.find Z)
/-- Writing a liminf as a supremum of infimum, in a (possibly non-complete) conditionally complete
linear order. A reparametrization trick is needed to avoid taking the infimum of sets which are
not bounded below. -/
theorem HasBasis.liminf_eq_ciSup_ciInf {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)]
(hv : v.HasBasis p s) {f : ι → α} (hs : ∀ (j : Subtype p), (s j).Nonempty)
(H : ∃ (j : Subtype p), BddBelow (range (fun (i : s j) ↦ f i))) :
liminf f v = ⨆ (j : Subtype p), ⨅ (i : s (liminf_reparam f s p j)), f i := by
classical
rcases H with ⟨j0, hj0⟩
let m : Set (Subtype p) := {j | BddBelow (range (fun (i : s j) ↦ f i))}
have : ∀ (j : Subtype p), Nonempty (s j) := fun j ↦ Nonempty.coe_sort (hs j)
have A : ⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i) =
⋃ (j : Subtype p), ⋂ (i : s (liminf_reparam f s p j)), Iic (f i) := by
apply Subset.antisymm
· apply iUnion_subset (fun j ↦ ?_)
by_cases hj : j ∈ m
· have : j = liminf_reparam f s p j := by simp only [liminf_reparam, hj, ite_true]
conv_lhs => rw [this]
apply subset_iUnion _ j
· simp only [m, mem_setOf_eq, ← nonempty_iInter_Iic_iff, not_nonempty_iff_eq_empty] at hj
simp only [hj, empty_subset]
· apply iUnion_subset (fun j ↦ ?_)
exact subset_iUnion (fun (k : Subtype p) ↦ (⋂ (i : s k), Iic (f i))) (liminf_reparam f s p j)
have B : ∀ (j : Subtype p), ⋂ (i : s (liminf_reparam f s p j)), Iic (f i) =
Iic (⨅ (i : s (liminf_reparam f s p j)), f i) := by
intro j
apply (Iic_ciInf _).symm
change liminf_reparam f s p j ∈ m
by_cases Hj : j ∈ m
· simpa only [liminf_reparam, if_pos Hj] using Hj
· simp only [liminf_reparam, if_neg Hj]
have Z : ∃ n, (exists_surjective_nat (Subtype p)).choose n ∈ m ∨ ∀ j, j ∉ m := by
rcases (exists_surjective_nat (Subtype p)).choose_spec j0 with ⟨n, rfl⟩
exact ⟨n, Or.inl hj0⟩
rcases Nat.find_spec Z with hZ|hZ
· exact hZ
· exact (hZ j0 hj0).elim
simp_rw [hv.liminf_eq_sSup_iUnion_iInter, A, B, sSup_iUnion_Iic]
open Classical in
/-- Writing a liminf as a supremum of infimum, in a (possibly non-complete) conditionally complete
linear order. A reparametrization trick is needed to avoid taking the infimum of sets which are
not bounded below. -/
theorem HasBasis.liminf_eq_ite {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι}
[Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) (f : ι → α) :
liminf f v = if ∃ (j : Subtype p), s j = ∅ then sSup univ else
if ∀ (j : Subtype p), ¬BddBelow (range (fun (i : s j) ↦ f i)) then sSup ∅
else ⨆ (j : Subtype p), ⨅ (i : s (liminf_reparam f s p j)), f i := by
by_cases H : ∃ (j : Subtype p), s j = ∅
· rw [if_pos H]
rcases H with ⟨j, hj⟩
simp [hv.liminf_eq_sSup_univ_of_empty j j.2 hj]
rw [if_neg H]
by_cases H' : ∀ (j : Subtype p), ¬BddBelow (range (fun (i : s j) ↦ f i))
· have A : ∀ (j : Subtype p), ⋂ (i : s j), Iic (f i) = ∅ := by
simp_rw [← not_nonempty_iff_eq_empty, nonempty_iInter_Iic_iff]
exact H'
simp_rw [if_pos H', hv.liminf_eq_sSup_iUnion_iInter, A, iUnion_empty]
rw [if_neg H']
apply hv.liminf_eq_ciSup_ciInf
· push_neg at H
simpa only [nonempty_iff_ne_empty] using H
· push_neg at H'
exact H'
/-- Given an indexed family of sets `s j` and a function `f`, then `limsup_reparam j` is equal
to `j` if `f` is bounded above on `s j`, and otherwise to some index `k` such that `f` is bounded
above on `s k` (if there exists one). To ensure good measurability behavior, this index `k` is
chosen as the minimal suitable index. This function is used to write down a limsup in a measurable
way, in `Filter.HasBasis.limsup_eq_ciInf_ciSup` and `Filter.HasBasis.limsup_eq_ite`. -/
noncomputable def limsup_reparam
(f : ι → α) (s : ι' → Set ι) (p : ι' → Prop) [Countable (Subtype p)] [Nonempty (Subtype p)]
(j : Subtype p) : Subtype p :=
liminf_reparam (α := αᵒᵈ) f s p j
/-- Writing a limsup as an infimum of supremum, in a (possibly non-complete) conditionally complete
linear order. A reparametrization trick is needed to avoid taking the supremum of sets which are
not bounded above. -/
theorem HasBasis.limsup_eq_ciInf_ciSup {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)]
(hv : v.HasBasis p s) {f : ι → α} (hs : ∀ (j : Subtype p), (s j).Nonempty)
(H : ∃ (j : Subtype p), BddAbove (range (fun (i : s j) ↦ f i))) :
limsup f v = ⨅ (j : Subtype p), ⨆ (i : s (limsup_reparam f s p j)), f i :=
HasBasis.liminf_eq_ciSup_ciInf (α := αᵒᵈ) hv hs H
open Classical in
/-- Writing a limsup as an infimum of supremum, in a (possibly non-complete) conditionally complete
linear order. A reparametrization trick is needed to avoid taking the supremum of sets which are
not bounded below. -/
theorem HasBasis.limsup_eq_ite {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι}
[Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) (f : ι → α) :
limsup f v = if ∃ (j : Subtype p), s j = ∅ then sInf univ else
if ∀ (j : Subtype p), ¬BddAbove (range (fun (i : s j) ↦ f i)) then sInf ∅
else ⨅ (j : Subtype p), ⨆ (i : s (limsup_reparam f s p j)), f i :=
HasBasis.liminf_eq_ite (α := αᵒᵈ) hv f
end Classical
end ConditionallyCompleteLinearOrder
end Filter
section Order
open Filter
theorem Monotone.isBoundedUnder_le_comp_iff [Nonempty β] [LinearOrder β] [Preorder γ] [NoMaxOrder γ]
{g : β → γ} {f : α → β} {l : Filter α} (hg : Monotone g) (hg' : Tendsto g atTop atTop) :
IsBoundedUnder (· ≤ ·) l (g ∘ f) ↔ IsBoundedUnder (· ≤ ·) l f := by
refine ⟨?_, fun h => h.isBoundedUnder (α := β) hg⟩
rintro ⟨c, hc⟩; rw [eventually_map] at hc
obtain ⟨b, hb⟩ : ∃ b, ∀ a ≥ b, c < g a := eventually_atTop.1 (hg'.eventually_gt_atTop c)
exact ⟨b, hc.mono fun x hx => not_lt.1 fun h => (hb _ h.le).not_le hx⟩
theorem Monotone.isBoundedUnder_ge_comp_iff [Nonempty β] [LinearOrder β] [Preorder γ] [NoMinOrder γ]
{g : β → γ} {f : α → β} {l : Filter α} (hg : Monotone g) (hg' : Tendsto g atBot atBot) :
IsBoundedUnder (· ≥ ·) l (g ∘ f) ↔ IsBoundedUnder (· ≥ ·) l f :=
hg.dual.isBoundedUnder_le_comp_iff hg'
theorem Antitone.isBoundedUnder_le_comp_iff [Nonempty β] [LinearOrder β] [Preorder γ] [NoMaxOrder γ]
{g : β → γ} {f : α → β} {l : Filter α} (hg : Antitone g) (hg' : Tendsto g atBot atTop) :
IsBoundedUnder (· ≤ ·) l (g ∘ f) ↔ IsBoundedUnder (· ≥ ·) l f :=
hg.dual_right.isBoundedUnder_ge_comp_iff hg'
theorem Antitone.isBoundedUnder_ge_comp_iff [Nonempty β] [LinearOrder β] [Preorder γ] [NoMinOrder γ]
{g : β → γ} {f : α → β} {l : Filter α} (hg : Antitone g) (hg' : Tendsto g atTop atBot) :
IsBoundedUnder (· ≥ ·) l (g ∘ f) ↔ IsBoundedUnder (· ≤ ·) l f :=
hg.dual_right.isBoundedUnder_le_comp_iff hg'
theorem GaloisConnection.l_limsup_le [ConditionallyCompleteLattice β]
[ConditionallyCompleteLattice γ] {f : Filter α} {v : α → β} {l : β → γ} {u : γ → β}
(gc : GaloisConnection l u)
(hlv : f.IsBoundedUnder (· ≤ ·) fun x => l (v x) := by isBoundedDefault)
(hv_co : f.IsCoboundedUnder (· ≤ ·) v := by isBoundedDefault) :
l (limsup v f) ≤ limsup (fun x => l (v x)) f := by
refine le_limsSup_of_le hlv fun c hc => ?_
rw [Filter.eventually_map] at hc
simp_rw [gc _ _] at hc ⊢
exact limsSup_le_of_le hv_co hc
theorem OrderIso.limsup_apply {γ} [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ]
{f : Filter α} {u : α → β} (g : β ≃o γ)
(hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(hu_co : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(hgu : f.IsBoundedUnder (· ≤ ·) fun x => g (u x) := by isBoundedDefault)
(hgu_co : f.IsCoboundedUnder (· ≤ ·) fun x => g (u x) := by isBoundedDefault) :
g (limsup u f) = limsup (fun x => g (u x)) f := by
refine le_antisymm ((OrderIso.to_galoisConnection g).l_limsup_le hgu hu_co) ?_
rw [← g.symm.symm_apply_apply <| limsup (fun x => g (u x)) f, g.symm_symm]
refine g.monotone ?_
have hf : u = fun i => g.symm (g (u i)) := funext fun i => (g.symm_apply_apply (u i)).symm
-- Porting note: nth_rw 1 to nth_rw 2
nth_rw 2 [hf]
refine (OrderIso.to_galoisConnection g.symm).l_limsup_le ?_ hgu_co
simp_rw [g.symm_apply_apply]
exact hu
theorem OrderIso.liminf_apply {γ} [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ]
{f : Filter α} {u : α → β} (g : β ≃o γ)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(hu_co : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault)
(hgu : f.IsBoundedUnder (· ≥ ·) fun x => g (u x) := by isBoundedDefault)
(hgu_co : f.IsCoboundedUnder (· ≥ ·) fun x => g (u x) := by isBoundedDefault) :
g (liminf u f) = liminf (fun x => g (u x)) f :=
OrderIso.limsup_apply (β := βᵒᵈ) (γ := γᵒᵈ) g.dual hu hu_co hgu hgu_co
end Order
section MinMax
open Filter
theorem isCoboundedUnder_le_max [LinearOrder β] {f : Filter α} {u v : α → β}
(h : f.IsCoboundedUnder (· ≤ ·) u ∨ f.IsCoboundedUnder (· ≤ ·) v) :
f.IsCoboundedUnder (· ≤ ·) (fun a ↦ max (u a) (v a)) := by
rcases h with (h' | h') <;>
· rcases h' with ⟨b, hb⟩
use b
intro c hc
apply hb c
rw [eventually_map] at hc ⊢
refine hc.mono (fun _ ↦ ?_)
simp (config := { contextual := true }) only [implies_true, max_le_iff, and_imp]
theorem limsup_max [ConditionallyCompleteLinearOrder β] {f : Filter α} {u v : α → β}
(h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(h₂ : f.IsCoboundedUnder (· ≤ ·) v := by isBoundedDefault)
(h₃ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h₄ : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) :
limsup (fun a ↦ max (u a) (v a)) f = max (limsup u f) (limsup v f) := by
have bddmax := IsBoundedUnder.sup h₃ h₄
have cobddmax := isCoboundedUnder_le_max (v := v) (Or.inl h₁)
apply le_antisymm
· refine (limsup_le_iff cobddmax bddmax).2 (fun b hb ↦ ?_)
have hu := eventually_lt_of_limsup_lt (lt_of_le_of_lt (le_max_left _ _) hb) h₃
have hv := eventually_lt_of_limsup_lt (lt_of_le_of_lt (le_max_right _ _) hb) h₄
refine mem_of_superset (inter_mem hu hv) (fun _ ↦ by simp)
· exact max_le (c := limsup (fun a ↦ max (u a) (v a)) f)
(limsup_le_limsup (eventually_of_forall (fun a : α ↦ le_max_left (u a) (v a))) h₁ bddmax)
(limsup_le_limsup (eventually_of_forall (fun a : α ↦ le_max_right (u a) (v a))) h₂ bddmax)
theorem liminf_min [ConditionallyCompleteLinearOrder β] {f : Filter α} {u v : α → β}
(h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault)
(h₂ : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault)
(h₃ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(h₄ : f.IsBoundedUnder (· ≥ ·) v := by isBoundedDefault) :
liminf (fun a ↦ min (u a) (v a)) f = min (liminf u f) (liminf v f) :=
limsup_max (β := βᵒᵈ) h₁ h₂ h₃ h₄
open Finset
theorem isBoundedUnder_le_finset_sup' [LinearOrder β] [Nonempty β] {f : Filter α} {F : ι → α → β}
{s : Finset ι} (hs : s.Nonempty) (h : ∀ i ∈ s, f.IsBoundedUnder (· ≤ ·) (F i)) :
f.IsBoundedUnder (· ≤ ·) (fun a ↦ sup' s hs (fun i ↦ F i a)) := by
choose! m hm using h
use sup' s hs m
simp only [eventually_map] at hm ⊢
rw [← eventually_all_finset s] at hm
refine hm.mono fun a h ↦ ?_
simp only [Finset.sup'_apply, sup'_le_iff]
exact fun i i_s ↦ le_trans (h i i_s) (le_sup' m i_s)
theorem isCoboundedUnder_le_finset_sup' [LinearOrder β] {f : Filter α} {F : ι → α → β}
{s : Finset ι} (hs : s.Nonempty) (h : ∃ i ∈ s, f.IsCoboundedUnder (· ≤ ·) (F i)) :
f.IsCoboundedUnder (· ≤ ·) (fun a ↦ sup' s hs (fun i ↦ F i a)) := by
rcases h with ⟨i, i_s, b, hb⟩
use b
refine fun c hc ↦ hb c ?_
rw [eventually_map] at hc ⊢
refine hc.mono fun a h ↦ ?_
simp only [Finset.sup'_apply, sup'_le_iff] at h ⊢
exact h i i_s
theorem isBoundedUnder_le_finset_sup [LinearOrder β] [OrderBot β] {f : Filter α} {F : ι → α → β}
{s : Finset ι} (h : ∀ i ∈ s, f.IsBoundedUnder (· ≤ ·) (F i)) :
f.IsBoundedUnder (· ≤ ·) (fun a ↦ sup s (fun i ↦ F i a)) := by
choose! m hm using h
use sup s m
simp only [eventually_map] at hm ⊢
rw [← eventually_all_finset s] at hm
exact hm.mono fun _ h ↦ sup_mono_fun h
theorem isBoundedUnder_ge_finset_inf' [LinearOrder β] [Nonempty β] {f : Filter α} {F : ι → α → β}
{s : Finset ι} (hs : s.Nonempty) (h : ∀ i ∈ s, f.IsBoundedUnder (· ≥ ·) (F i)) :
f.IsBoundedUnder (· ≥ ·) (fun a ↦ inf' s hs (fun i ↦ F i a)) :=
isBoundedUnder_le_finset_sup' (β := βᵒᵈ) hs h
theorem isCoboundedUnder_ge_finset_inf' [LinearOrder β] {f : Filter α} {F : ι → α → β}
{s : Finset ι} (hs : s.Nonempty) (h : ∃ i ∈ s, f.IsCoboundedUnder (· ≥ ·) (F i)) :
f.IsCoboundedUnder (· ≥ ·) (fun a ↦ inf' s hs (fun i ↦ F i a)) :=
isCoboundedUnder_le_finset_sup' (β := βᵒᵈ) hs h
theorem isBoundedUnder_ge_finset_inf [LinearOrder β] [OrderTop β] {f : Filter α} {F : ι → α → β}
{s : Finset ι} (h : ∀ i ∈ s, f.IsBoundedUnder (· ≥ ·) (F i)) :
f.IsBoundedUnder (· ≥ ·) (fun a ↦ inf s (fun i ↦ F i a)) :=
isBoundedUnder_le_finset_sup (β := βᵒᵈ) h
theorem limsup_finset_sup' [ConditionallyCompleteLinearOrder β] {f : Filter α}
{F : ι → α → β} {s : Finset ι} (hs : s.Nonempty)
(h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault)
(h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) :
limsup (fun a ↦ sup' s hs (fun i ↦ F i a)) f = sup' s hs (fun i ↦ limsup (F i) f) := by
have bddsup := isBoundedUnder_le_finset_sup' hs h₂
apply le_antisymm
· have h₃ : ∃ i ∈ s, f.IsCoboundedUnder (· ≤ ·) (F i) := by
rcases hs with ⟨i, i_s⟩
use i, i_s
exact h₁ i i_s
have cobddsup := isCoboundedUnder_le_finset_sup' hs h₃
refine (limsup_le_iff cobddsup bddsup).2 (fun b hb ↦ ?_)
rw [eventually_iff_exists_mem]
use ⋂ i ∈ s, {a | F i a < b}
split_ands
· rw [biInter_finset_mem]
suffices key : ∀ i ∈ s, ∀ᶠ a in f, F i a < b from fun i i_s ↦ eventually_iff.1 (key i i_s)
intro i i_s
apply eventually_lt_of_limsup_lt _ (h₂ i i_s)
exact lt_of_le_of_lt (Finset.le_sup' (f := fun i ↦ limsup (F i) f) i_s) hb
· simp only [mem_iInter, mem_setOf_eq, Finset.sup'_apply, sup'_lt_iff, imp_self, implies_true]
· apply Finset.sup'_le hs (fun i ↦ limsup (F i) f)
refine fun i i_s ↦ limsup_le_limsup (eventually_of_forall (fun a ↦ ?_)) (h₁ i i_s) bddsup
simp only [Finset.sup'_apply, le_sup'_iff]
use i, i_s
theorem limsup_finset_sup [ConditionallyCompleteLinearOrder β] [OrderBot β] {f : Filter α}
{F : ι → α → β} {s : Finset ι}
(h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault)
(h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) :
limsup (fun a ↦ sup s (fun i ↦ F i a)) f = sup s (fun i ↦ limsup (F i) f) := by
rcases eq_or_neBot f with (rfl | _)
· simp [limsup_eq, csInf_univ]
rcases Finset.eq_empty_or_nonempty s with (rfl | s_nemp)
· simp only [Finset.sup_apply, sup_empty, limsup_const]
rw [← Finset.sup'_eq_sup s_nemp fun i ↦ limsup (F i) f, ← limsup_finset_sup' s_nemp h₁ h₂]
congr
ext a
exact Eq.symm (Finset.sup'_eq_sup s_nemp (fun i ↦ F i a))
theorem liminf_finset_inf' [ConditionallyCompleteLinearOrder β] {f : Filter α}
{F : ι → α → β} {s : Finset ι} (hs : s.Nonempty)
(h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault)
(h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) :
liminf (fun a ↦ inf' s hs (fun i ↦ F i a)) f = inf' s hs (fun i ↦ liminf (F i) f) :=
limsup_finset_sup' (β := βᵒᵈ) hs h₁ h₂
theorem liminf_finset_inf [ConditionallyCompleteLinearOrder β] [OrderTop β] {f : Filter α}
{F : ι → α → β} {s : Finset ι}
(h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault)
(h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) :
liminf (fun a ↦ inf s (fun i ↦ F i a)) f = inf s (fun i ↦ liminf (F i) f) :=
limsup_finset_sup (β := βᵒᵈ) h₁ h₂
end MinMax
section frequently_bounded
variable {R S : Type*} {F : Filter R} [LinearOrder R] [LinearOrder S]
namespace Filter
/-- For nontrivial filters in linear orders, coboundedness for `≤` implies frequent boundedness
from below. -/
lemma IsCobounded.frequently_ge [NeBot F] (cobdd : IsCobounded (· ≤ ·) F) :
∃ l, ∃ᶠ x in F, l ≤ x := by
obtain ⟨t, ht⟩ := cobdd
by_cases tbot : IsBot t
· refine ⟨t, frequently_of_forall fun r ↦ tbot r⟩
obtain ⟨t', ht'⟩ : ∃ t', t' < t := by
by_contra!
exact tbot this
refine ⟨t', ?_⟩
intro ev
specialize ht t' (by filter_upwards [ev] with _ h using (not_le.mp h).le)
apply lt_irrefl t' <| lt_of_lt_of_le ht' ht
/-- For nontrivial filters in linear orders, coboundedness for `≥` implies frequent boundedness
from above. -/
lemma IsCobounded.frequently_le [NeBot F] (cobdd : IsCobounded (· ≥ ·) F) :
∃ u, ∃ᶠ x in F, x ≤ u :=
cobdd.frequently_ge (R := Rᵒᵈ)
/-- In linear orders, frequent boundedness from below implies coboundedness for `≤`. -/
lemma IsCobounded.of_frequently_ge {l : R} (freq_ge : ∃ᶠ x in F, l ≤ x) :
IsCobounded (· ≤ ·) F := by
by_cases lbot : IsBot l
· refine ⟨l, fun x _ ↦ lbot x⟩
obtain ⟨l', hl'⟩ : ∃ l', l' < l := by
by_contra!
exact lbot this
refine ⟨l', ?_⟩
intro u hu
have key : ∃ᶠ x in F, l ≤ x ∧ x ≤ u := Frequently.and_eventually freq_ge hu
obtain ⟨w, l_le_w, w_le_u⟩ := key.exists
exact hl'.le.trans <| l_le_w.trans w_le_u
/-- In linear orders, frequent boundedness from above implies coboundedness for `≥`. -/
lemma IsCobounded.of_frequently_le {u : R} (freq_le : ∃ᶠ r in F, r ≤ u) :
IsCobounded (· ≥ ·) F :=
IsCobounded.of_frequently_ge (R := Rᵒᵈ) freq_le
end Filter
lemma Monotone.frequently_ge_map_of_frequently_ge {f : R → S} (f_incr : Monotone f)
{l : R} (freq_ge : ∃ᶠ x in F, l ≤ x) :
∃ᶠ x' in F.map f, f l ≤ x' := by
refine fun ev ↦ freq_ge ?_
simp only [not_le, not_lt] at ev freq_ge ⊢
filter_upwards [ev] with z hz
by_contra con
exact lt_irrefl (f l) <| lt_of_le_of_lt (f_incr <| not_lt.mp con) hz
lemma Monotone.frequently_le_map_of_frequently_le {f : R → S} (f_incr : Monotone f)
{u : R} (freq_le : ∃ᶠ x in F, x ≤ u) :
∃ᶠ y in F.map f, y ≤ f u := by
refine fun ev ↦ freq_le ?_
simp only [not_le, not_lt] at ev freq_le ⊢
filter_upwards [ev] with z hz
by_contra con
apply lt_irrefl (f u) <| lt_of_lt_of_le hz <| f_incr (not_lt.mp con)
lemma Antitone.frequently_le_map_of_frequently_ge {f : R → S} (f_decr : Antitone f)
{l : R} (frbdd : ∃ᶠ x in F, l ≤ x) :
∃ᶠ y in F.map f, y ≤ f l :=
Monotone.frequently_ge_map_of_frequently_ge (S := Sᵒᵈ) f_decr frbdd
lemma Antitone.frequently_ge_map_of_frequently_le {f : R → S} (f_decr : Antitone f)
{u : R} (frbdd : ∃ᶠ x in F, x ≤ u) :
∃ᶠ y in F.map f, f u ≤ y :=
Monotone.frequently_le_map_of_frequently_le (S := Sᵒᵈ) f_decr frbdd
lemma Monotone.isCoboundedUnder_le_of_isCobounded {f : R → S} (f_incr : Monotone f)
[NeBot F] (cobdd : IsCobounded (· ≤ ·) F) :
F.IsCoboundedUnder (· ≤ ·) f := by
obtain ⟨l, hl⟩ := IsCobounded.frequently_ge cobdd
exact IsCobounded.of_frequently_ge <| f_incr.frequently_ge_map_of_frequently_ge hl
lemma Monotone.isCoboundedUnder_ge_of_isCobounded {f : R → S} (f_incr : Monotone f)
[NeBot F] (cobdd : IsCobounded (· ≥ ·) F) :
F.IsCoboundedUnder (· ≥ ·) f :=
Monotone.isCoboundedUnder_le_of_isCobounded (R := Rᵒᵈ) (S := Sᵒᵈ) f_incr.dual cobdd
lemma Antitone.isCoboundedUnder_le_of_isCobounded {f : R → S} (f_decr : Antitone f)
[NeBot F] (cobdd : IsCobounded (· ≥ ·) F) :
F.IsCoboundedUnder (· ≤ ·) f :=
Monotone.isCoboundedUnder_le_of_isCobounded (R := Rᵒᵈ) f_decr.dual cobdd
lemma Antitone.isCoboundedUnder_ge_of_isCobounded {f : R → S} (f_decr : Antitone f)
[NeBot F] (cobdd : IsCobounded (· ≤ ·) F) :
F.IsCoboundedUnder (· ≥ ·) f :=
Monotone.isCoboundedUnder_le_of_isCobounded (S := Sᵒᵈ) f_decr cobdd
end frequently_bounded
|
Order\Max.lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Yury Kudryashov, Yaël Dillies
-/
import Mathlib.Order.Synonym
/-!
# Minimal/maximal and bottom/top elements
This file defines predicates for elements to be minimal/maximal or bottom/top and typeclasses
saying that there are no such elements.
## Predicates
* `IsBot`: An element is *bottom* if all elements are greater than it.
* `IsTop`: An element is *top* if all elements are less than it.
* `IsMin`: An element is *minimal* if no element is strictly less than it.
* `IsMax`: An element is *maximal* if no element is strictly greater than it.
See also `isBot_iff_isMin` and `isTop_iff_isMax` for the equivalences in a (co)directed order.
## Typeclasses
* `NoBotOrder`: An order without bottom elements.
* `NoTopOrder`: An order without top elements.
* `NoMinOrder`: An order without minimal elements.
* `NoMaxOrder`: An order without maximal elements.
-/
open OrderDual
universe u v
variable {α β : Type*}
/-- Order without bottom elements. -/
class NoBotOrder (α : Type*) [LE α] : Prop where
/-- For each term `a`, there is some `b` which is either incomparable or strictly smaller. -/
exists_not_ge (a : α) : ∃ b, ¬a ≤ b
/-- Order without top elements. -/
class NoTopOrder (α : Type*) [LE α] : Prop where
/-- For each term `a`, there is some `b` which is either incomparable or strictly larger. -/
exists_not_le (a : α) : ∃ b, ¬b ≤ a
/-- Order without minimal elements. Sometimes called coinitial or dense. -/
class NoMinOrder (α : Type*) [LT α] : Prop where
/-- For each term `a`, there is some strictly smaller `b`. -/
exists_lt (a : α) : ∃ b, b < a
/-- Order without maximal elements. Sometimes called cofinal. -/
class NoMaxOrder (α : Type*) [LT α] : Prop where
/-- For each term `a`, there is some strictly greater `b`. -/
exists_gt (a : α) : ∃ b, a < b
export NoBotOrder (exists_not_ge)
export NoTopOrder (exists_not_le)
export NoMinOrder (exists_lt)
export NoMaxOrder (exists_gt)
instance nonempty_lt [LT α] [NoMinOrder α] (a : α) : Nonempty { x // x < a } :=
nonempty_subtype.2 (exists_lt a)
instance nonempty_gt [LT α] [NoMaxOrder α] (a : α) : Nonempty { x // a < x } :=
nonempty_subtype.2 (exists_gt a)
instance IsEmpty.toNoMaxOrder [LT α] [IsEmpty α] : NoMaxOrder α := ⟨isEmptyElim⟩
instance IsEmpty.toNoMinOrder [LT α] [IsEmpty α] : NoMinOrder α := ⟨isEmptyElim⟩
instance OrderDual.noBotOrder [LE α] [NoTopOrder α] : NoBotOrder αᵒᵈ :=
⟨fun a => exists_not_le (α := α) a⟩
instance OrderDual.noTopOrder [LE α] [NoBotOrder α] : NoTopOrder αᵒᵈ :=
⟨fun a => exists_not_ge (α := α) a⟩
instance OrderDual.noMinOrder [LT α] [NoMaxOrder α] : NoMinOrder αᵒᵈ :=
⟨fun a => exists_gt (α := α) a⟩
instance OrderDual.noMaxOrder [LT α] [NoMinOrder α] : NoMaxOrder αᵒᵈ :=
⟨fun a => exists_lt (α := α) a⟩
-- See note [lower instance priority]
instance (priority := 100) [Preorder α] [NoMinOrder α] : NoBotOrder α :=
⟨fun a => (exists_lt a).imp fun _ => not_le_of_lt⟩
-- See note [lower instance priority]
instance (priority := 100) [Preorder α] [NoMaxOrder α] : NoTopOrder α :=
⟨fun a => (exists_gt a).imp fun _ => not_le_of_lt⟩
instance noMaxOrder_of_left [Preorder α] [Preorder β] [NoMaxOrder α] : NoMaxOrder (α × β) :=
⟨fun ⟨a, b⟩ => by
obtain ⟨c, h⟩ := exists_gt a
exact ⟨(c, b), Prod.mk_lt_mk_iff_left.2 h⟩⟩
instance noMaxOrder_of_right [Preorder α] [Preorder β] [NoMaxOrder β] : NoMaxOrder (α × β) :=
⟨fun ⟨a, b⟩ => by
obtain ⟨c, h⟩ := exists_gt b
exact ⟨(a, c), Prod.mk_lt_mk_iff_right.2 h⟩⟩
instance noMinOrder_of_left [Preorder α] [Preorder β] [NoMinOrder α] : NoMinOrder (α × β) :=
⟨fun ⟨a, b⟩ => by
obtain ⟨c, h⟩ := exists_lt a
exact ⟨(c, b), Prod.mk_lt_mk_iff_left.2 h⟩⟩
instance noMinOrder_of_right [Preorder α] [Preorder β] [NoMinOrder β] : NoMinOrder (α × β) :=
⟨fun ⟨a, b⟩ => by
obtain ⟨c, h⟩ := exists_lt b
exact ⟨(a, c), Prod.mk_lt_mk_iff_right.2 h⟩⟩
instance {ι : Type u} {π : ι → Type*} [Nonempty ι] [∀ i, Preorder (π i)] [∀ i, NoMaxOrder (π i)] :
NoMaxOrder (∀ i, π i) :=
⟨fun a => by
classical
obtain ⟨b, hb⟩ := exists_gt (a <| Classical.arbitrary _)
exact ⟨_, lt_update_self_iff.2 hb⟩⟩
instance {ι : Type u} {π : ι → Type*} [Nonempty ι] [∀ i, Preorder (π i)] [∀ i, NoMinOrder (π i)] :
NoMinOrder (∀ i, π i) :=
⟨fun a => by
classical
obtain ⟨b, hb⟩ := exists_lt (a <| Classical.arbitrary _)
exact ⟨_, update_lt_self_iff.2 hb⟩⟩
-- Porting note: mathlib3 proof uses `convert`
theorem NoBotOrder.to_noMinOrder (α : Type*) [LinearOrder α] [NoBotOrder α] : NoMinOrder α :=
{ exists_lt := fun a => by simpa [not_le] using exists_not_ge a }
-- Porting note: mathlib3 proof uses `convert`
theorem NoTopOrder.to_noMaxOrder (α : Type*) [LinearOrder α] [NoTopOrder α] : NoMaxOrder α :=
{ exists_gt := fun a => by simpa [not_le] using exists_not_le a }
theorem noBotOrder_iff_noMinOrder (α : Type*) [LinearOrder α] : NoBotOrder α ↔ NoMinOrder α :=
⟨fun h =>
haveI := h
NoBotOrder.to_noMinOrder α,
fun h =>
haveI := h
inferInstance⟩
theorem noTopOrder_iff_noMaxOrder (α : Type*) [LinearOrder α] : NoTopOrder α ↔ NoMaxOrder α :=
⟨fun h =>
haveI := h
NoTopOrder.to_noMaxOrder α,
fun h =>
haveI := h
inferInstance⟩
theorem NoMinOrder.not_acc [LT α] [NoMinOrder α] (a : α) : ¬Acc (· < ·) a := fun h =>
Acc.recOn h fun x _ => (exists_lt x).recOn
theorem NoMaxOrder.not_acc [LT α] [NoMaxOrder α] (a : α) : ¬Acc (· > ·) a := fun h =>
Acc.recOn h fun x _ => (exists_gt x).recOn
section LE
variable [LE α] {a b : α}
/-- `a : α` is a bottom element of `α` if it is less than or equal to any other element of `α`.
This predicate is roughly an unbundled version of `OrderBot`, except that a preorder may have
several bottom elements. When `α` is linear, this is useful to make a case disjunction on
`NoMinOrder α` within a proof. -/
def IsBot (a : α) : Prop :=
∀ b, a ≤ b
/-- `a : α` is a top element of `α` if it is greater than or equal to any other element of `α`.
This predicate is roughly an unbundled version of `OrderBot`, except that a preorder may have
several top elements. When `α` is linear, this is useful to make a case disjunction on
`NoMaxOrder α` within a proof. -/
def IsTop (a : α) : Prop :=
∀ b, b ≤ a
/-- `a` is a minimal element of `α` if no element is strictly less than it. We spell it without `<`
to avoid having to convert between `≤` and `<`. Instead, `isMin_iff_forall_not_lt` does the
conversion. -/
def IsMin (a : α) : Prop :=
∀ ⦃b⦄, b ≤ a → a ≤ b
/-- `a` is a maximal element of `α` if no element is strictly greater than it. We spell it without
`<` to avoid having to convert between `≤` and `<`. Instead, `isMax_iff_forall_not_lt` does the
conversion. -/
def IsMax (a : α) : Prop :=
∀ ⦃b⦄, a ≤ b → b ≤ a
@[simp]
theorem not_isBot [NoBotOrder α] (a : α) : ¬IsBot a := fun h =>
let ⟨_, hb⟩ := exists_not_ge a
hb <| h _
@[simp]
theorem not_isTop [NoTopOrder α] (a : α) : ¬IsTop a := fun h =>
let ⟨_, hb⟩ := exists_not_le a
hb <| h _
protected theorem IsBot.isMin (h : IsBot a) : IsMin a := fun b _ => h b
protected theorem IsTop.isMax (h : IsTop a) : IsMax a := fun b _ => h b
@[simp]
theorem isBot_toDual_iff : IsBot (toDual a) ↔ IsTop a :=
Iff.rfl
@[simp]
theorem isTop_toDual_iff : IsTop (toDual a) ↔ IsBot a :=
Iff.rfl
@[simp]
theorem isMin_toDual_iff : IsMin (toDual a) ↔ IsMax a :=
Iff.rfl
@[simp]
theorem isMax_toDual_iff : IsMax (toDual a) ↔ IsMin a :=
Iff.rfl
@[simp]
theorem isBot_ofDual_iff {a : αᵒᵈ} : IsBot (ofDual a) ↔ IsTop a :=
Iff.rfl
@[simp]
theorem isTop_ofDual_iff {a : αᵒᵈ} : IsTop (ofDual a) ↔ IsBot a :=
Iff.rfl
@[simp]
theorem isMin_ofDual_iff {a : αᵒᵈ} : IsMin (ofDual a) ↔ IsMax a :=
Iff.rfl
@[simp]
theorem isMax_ofDual_iff {a : αᵒᵈ} : IsMax (ofDual a) ↔ IsMin a :=
Iff.rfl
alias ⟨_, IsTop.toDual⟩ := isBot_toDual_iff
alias ⟨_, IsBot.toDual⟩ := isTop_toDual_iff
alias ⟨_, IsMax.toDual⟩ := isMin_toDual_iff
alias ⟨_, IsMin.toDual⟩ := isMax_toDual_iff
alias ⟨_, IsTop.ofDual⟩ := isBot_ofDual_iff
alias ⟨_, IsBot.ofDual⟩ := isTop_ofDual_iff
alias ⟨_, IsMax.ofDual⟩ := isMin_ofDual_iff
alias ⟨_, IsMin.ofDual⟩ := isMax_ofDual_iff
end LE
section Preorder
variable [Preorder α] {a b : α}
theorem IsBot.mono (ha : IsBot a) (h : b ≤ a) : IsBot b := fun _ => h.trans <| ha _
theorem IsTop.mono (ha : IsTop a) (h : a ≤ b) : IsTop b := fun _ => (ha _).trans h
theorem IsMin.mono (ha : IsMin a) (h : b ≤ a) : IsMin b := fun _ hc => h.trans <| ha <| hc.trans h
theorem IsMax.mono (ha : IsMax a) (h : a ≤ b) : IsMax b := fun _ hc => (ha <| h.trans hc).trans h
theorem IsMin.not_lt (h : IsMin a) : ¬b < a := fun hb => hb.not_le <| h hb.le
theorem IsMax.not_lt (h : IsMax a) : ¬a < b := fun hb => hb.not_le <| h hb.le
@[simp]
theorem not_isMin_of_lt (h : b < a) : ¬IsMin a := fun ha => ha.not_lt h
@[simp]
theorem not_isMax_of_lt (h : a < b) : ¬IsMax a := fun ha => ha.not_lt h
alias LT.lt.not_isMin := not_isMin_of_lt
alias LT.lt.not_isMax := not_isMax_of_lt
theorem isMin_iff_forall_not_lt : IsMin a ↔ ∀ b, ¬b < a :=
⟨fun h _ => h.not_lt, fun h _ hba => of_not_not fun hab => h _ <| hba.lt_of_not_le hab⟩
theorem isMax_iff_forall_not_lt : IsMax a ↔ ∀ b, ¬a < b :=
⟨fun h _ => h.not_lt, fun h _ hba => of_not_not fun hab => h _ <| hba.lt_of_not_le hab⟩
@[simp]
theorem not_isMin_iff : ¬IsMin a ↔ ∃ b, b < a := by
simp [lt_iff_le_not_le, IsMin, not_forall, exists_prop]
@[simp]
theorem not_isMax_iff : ¬IsMax a ↔ ∃ b, a < b := by
simp [lt_iff_le_not_le, IsMax, not_forall, exists_prop]
@[simp]
theorem not_isMin [NoMinOrder α] (a : α) : ¬IsMin a :=
not_isMin_iff.2 <| exists_lt a
@[simp]
theorem not_isMax [NoMaxOrder α] (a : α) : ¬IsMax a :=
not_isMax_iff.2 <| exists_gt a
namespace Subsingleton
variable [Subsingleton α]
protected theorem isBot (a : α) : IsBot a := fun _ => (Subsingleton.elim _ _).le
protected theorem isTop (a : α) : IsTop a := fun _ => (Subsingleton.elim _ _).le
protected theorem isMin (a : α) : IsMin a :=
(Subsingleton.isBot _).isMin
protected theorem isMax (a : α) : IsMax a :=
(Subsingleton.isTop _).isMax
end Subsingleton
end Preorder
section PartialOrder
variable [PartialOrder α] {a b : α}
protected theorem IsMin.eq_of_le (ha : IsMin a) (h : b ≤ a) : b = a :=
h.antisymm <| ha h
protected theorem IsMin.eq_of_ge (ha : IsMin a) (h : b ≤ a) : a = b :=
h.antisymm' <| ha h
protected theorem IsMax.eq_of_le (ha : IsMax a) (h : a ≤ b) : a = b :=
h.antisymm <| ha h
protected theorem IsMax.eq_of_ge (ha : IsMax a) (h : a ≤ b) : b = a :=
h.antisymm' <| ha h
end PartialOrder
section Prod
variable [Preorder α] [Preorder β] {a a₁ a₂ : α} {b b₁ b₂ : β} {x y : α × β}
theorem IsBot.prod_mk (ha : IsBot a) (hb : IsBot b) : IsBot (a, b) := fun _ => ⟨ha _, hb _⟩
theorem IsTop.prod_mk (ha : IsTop a) (hb : IsTop b) : IsTop (a, b) := fun _ => ⟨ha _, hb _⟩
theorem IsMin.prod_mk (ha : IsMin a) (hb : IsMin b) : IsMin (a, b) := fun _ hc => ⟨ha hc.1, hb hc.2⟩
theorem IsMax.prod_mk (ha : IsMax a) (hb : IsMax b) : IsMax (a, b) := fun _ hc => ⟨ha hc.1, hb hc.2⟩
theorem IsBot.fst (hx : IsBot x) : IsBot x.1 := fun c => (hx (c, x.2)).1
theorem IsBot.snd (hx : IsBot x) : IsBot x.2 := fun c => (hx (x.1, c)).2
theorem IsTop.fst (hx : IsTop x) : IsTop x.1 := fun c => (hx (c, x.2)).1
theorem IsTop.snd (hx : IsTop x) : IsTop x.2 := fun c => (hx (x.1, c)).2
theorem IsMin.fst (hx : IsMin x) : IsMin x.1 :=
fun c hc => (hx <| show (c, x.2) ≤ x from (and_iff_left le_rfl).2 hc).1
theorem IsMin.snd (hx : IsMin x) : IsMin x.2 :=
fun c hc => (hx <| show (x.1, c) ≤ x from (and_iff_right le_rfl).2 hc).2
theorem IsMax.fst (hx : IsMax x) : IsMax x.1 :=
fun c hc => (hx <| show x ≤ (c, x.2) from (and_iff_left le_rfl).2 hc).1
theorem IsMax.snd (hx : IsMax x) : IsMax x.2 :=
fun c hc => (hx <| show x ≤ (x.1, c) from (and_iff_right le_rfl).2 hc).2
theorem Prod.isBot_iff : IsBot x ↔ IsBot x.1 ∧ IsBot x.2 :=
⟨fun hx => ⟨hx.fst, hx.snd⟩, fun h => h.1.prod_mk h.2⟩
theorem Prod.isTop_iff : IsTop x ↔ IsTop x.1 ∧ IsTop x.2 :=
⟨fun hx => ⟨hx.fst, hx.snd⟩, fun h => h.1.prod_mk h.2⟩
theorem Prod.isMin_iff : IsMin x ↔ IsMin x.1 ∧ IsMin x.2 :=
⟨fun hx => ⟨hx.fst, hx.snd⟩, fun h => h.1.prod_mk h.2⟩
theorem Prod.isMax_iff : IsMax x ↔ IsMax x.1 ∧ IsMax x.2 :=
⟨fun hx => ⟨hx.fst, hx.snd⟩, fun h => h.1.prod_mk h.2⟩
end Prod
|
Order\Minimal.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Peter Nelson
-/
import Mathlib.Order.Antichain
import Mathlib.Order.UpperLower.Basic
import Mathlib.Order.Interval.Set.Basic
/-!
# Minimality and Maximality
This file defines minimality and maximality of an element with respect to a predicate `P` on
an ordered type `α`.
## Main declarations
* `Minimal P x`: `x` is minimal satisfying `P`.
* `Maximal P x`: `x` is maximal satisfying `P`.
## Implementation Details
This file underwent a refactor from a version where minimality and maximality were defined using
sets rather than predicates, and with an unbundled order relation rather than a `LE` instance.
A side effect is that it has become less straightforward to state that something is minimal
with respect to a relation that is *not* defeq to the default `LE`.
One possible way would be with a type synonym,
and another would be with an ad hoc `LE` instance and `@` notation.
This was not an issue in practice anywhere in mathlib at the time of the refactor,
but it may be worth re-examining this to make it easier in the future; see the TODO below.
## TODO
* In the linearly ordered case, versions of lemmas like `minimal_mem_image` will hold with
`MonotoneOn`/`AntitoneOn` assumptions rather than the stronger `x ≤ y ↔ f x ≤ f y` assumptions.
* `Set.maximal_iff_forall_insert` and `Set.minimal_iff_forall_diff_singleton` will generalize to
lemmas about covering in the case of an `IsStronglyAtomic`/`IsStronglyCoatomic` order.
* `Finset` versions of the lemmas about sets.
* API to allow for easily expressing min/maximality with respect to an arbitrary non-`LE` relation.
-/
open Set OrderDual
variable {α : Type*} {P Q : α → Prop} {a x y : α}
section LE
variable [LE α]
/-- `Minimal P x` means that `x` is a minimal element satisfying `P`. -/
def Minimal (P : α → Prop) (x : α) : Prop := P x ∧ ∀ ⦃y⦄, P y → y ≤ x → x ≤ y
/-- `Maximal P x` means that `x` is a maximal element satisfying `P`. -/
def Maximal (P : α → Prop) (x : α) : Prop := P x ∧ ∀ ⦃y⦄, P y → x ≤ y → y ≤ x
lemma Minimal.prop (h : Minimal P x) : P x :=
h.1
lemma Maximal.prop (h : Maximal P x) : P x :=
h.1
lemma Minimal.le_of_le (h : Minimal P x) (hy : P y) (hle : y ≤ x) : x ≤ y :=
h.2 hy hle
lemma Maximal.le_of_ge (h : Maximal P x) (hy : P y) (hge : x ≤ y) : y ≤ x :=
h.2 hy hge
@[simp] theorem minimal_toDual : Minimal (fun x ↦ P (ofDual x)) (toDual x) ↔ Maximal P x :=
Iff.rfl
alias ⟨Minimal.of_dual, Minimal.dual⟩ := minimal_toDual
@[simp] theorem maximal_toDual : Maximal (fun x ↦ P (ofDual x)) (toDual x) ↔ Minimal P x :=
Iff.rfl
alias ⟨Maximal.of_dual, Maximal.dual⟩ := maximal_toDual
@[simp] theorem minimal_false : ¬ Minimal (fun _ ↦ False) x := by
simp [Minimal]
@[simp] theorem maximal_false : ¬ Maximal (fun _ ↦ False) x := by
simp [Maximal]
@[simp] theorem minimal_true : Minimal (fun _ ↦ True) x ↔ IsMin x := by
simp [IsMin, Minimal]
@[simp] theorem maximal_true : Maximal (fun _ ↦ True) x ↔ IsMax x :=
minimal_true (α := αᵒᵈ)
@[simp] theorem minimal_subtype {x : Subtype Q} :
Minimal (fun x ↦ P x.1) x ↔ Minimal (P ⊓ Q) x := by
obtain ⟨x, hx⟩ := x
simp only [Minimal, Subtype.forall, Subtype.mk_le_mk, Pi.inf_apply, inf_Prop_eq]
tauto
@[simp] theorem maximal_subtype {x : Subtype Q} :
Maximal (fun x ↦ P x.1) x ↔ Maximal (P ⊓ Q) x :=
minimal_subtype (α := αᵒᵈ)
theorem maximal_true_subtype {x : Subtype P} : Maximal (fun _ ↦ True) x ↔ Maximal P x := by
obtain ⟨x, hx⟩ := x
simp [Maximal, hx]
theorem minimal_true_subtype {x : Subtype P} : Minimal (fun _ ↦ True) x ↔ Minimal P x := by
obtain ⟨x, hx⟩ := x
simp [Minimal, hx]
@[simp] theorem minimal_minimal : Minimal (Minimal P) x ↔ Minimal P x :=
⟨fun h ↦ h.prop, fun h ↦ ⟨h, fun _ hy hyx ↦ h.le_of_le hy.prop hyx⟩⟩
@[simp] theorem maximal_maximal : Maximal (Maximal P) x ↔ Maximal P x :=
minimal_minimal (α := αᵒᵈ)
/-- If `P` is down-closed, then minimal elements satisfying `P` are exactly the globally minimal
elements satisfying `P`. -/
theorem minimal_iff_isMin (hP : ∀ ⦃x y⦄, P y → x ≤ y → P x) : Minimal P x ↔ P x ∧ IsMin x :=
⟨fun h ↦ ⟨h.prop, fun _ h' ↦ h.le_of_le (hP h.prop h') h'⟩, fun h ↦ ⟨h.1, fun _ _ h' ↦ h.2 h'⟩⟩
/-- If `P` is up-closed, then maximal elements satisfying `P` are exactly the globally maximal
elements satisfying `P`. -/
theorem maximal_iff_isMax (hP : ∀ ⦃x y⦄, P y → y ≤ x → P x) : Maximal P x ↔ P x ∧ IsMax x :=
⟨fun h ↦ ⟨h.prop, fun _ h' ↦ h.le_of_ge (hP h.prop h') h'⟩, fun h ↦ ⟨h.1, fun _ _ h' ↦ h.2 h'⟩⟩
theorem Minimal.mono (h : Minimal P x) (hle : Q ≤ P) (hQ : Q x) : Minimal Q x :=
⟨hQ, fun y hQy ↦ h.le_of_le (hle y hQy)⟩
theorem Maximal.mono (h : Maximal P x) (hle : Q ≤ P) (hQ : Q x) : Maximal Q x :=
⟨hQ, fun y hQy ↦ h.le_of_ge (hle y hQy)⟩
theorem Minimal.and_right (h : Minimal P x) (hQ : Q x) : Minimal (fun x ↦ P x ∧ Q x) x :=
h.mono (fun _ ↦ And.left) ⟨h.prop, hQ⟩
theorem Minimal.and_left (h : Minimal P x) (hQ : Q x) : Minimal (fun x ↦ (Q x ∧ P x)) x :=
h.mono (fun _ ↦ And.right) ⟨hQ, h.prop⟩
theorem Maximal.and_right (h : Maximal P x) (hQ : Q x) : Maximal (fun x ↦ (P x ∧ Q x)) x :=
h.mono (fun _ ↦ And.left) ⟨h.prop, hQ⟩
theorem Maximal.and_left (h : Maximal P x) (hQ : Q x) : Maximal (fun x ↦ (Q x ∧ P x)) x :=
h.mono (fun _ ↦ And.right) ⟨hQ, h.prop⟩
@[simp] theorem minimal_eq_iff : Minimal (· = y) x ↔ x = y := by
simp (config := {contextual := true}) [Minimal]
@[simp] theorem maximal_eq_iff : Maximal (· = y) x ↔ x = y := by
simp (config := {contextual := true}) [Maximal]
theorem not_minimal_iff (hx : P x) : ¬ Minimal P x ↔ ∃ y, P y ∧ y ≤ x ∧ ¬ (x ≤ y) := by
simp [Minimal, hx]
theorem not_maximal_iff (hx : P x) : ¬ Maximal P x ↔ ∃ y, P y ∧ x ≤ y ∧ ¬ (y ≤ x) :=
not_minimal_iff (α := αᵒᵈ) hx
theorem Minimal.or (h : Minimal (fun x ↦ P x ∨ Q x) x) : Minimal P x ∨ Minimal Q x := by
obtain ⟨h | h, hmin⟩ := h
· exact .inl ⟨h, fun y hy hyx ↦ hmin (Or.inl hy) hyx⟩
exact .inr ⟨h, fun y hy hyx ↦ hmin (Or.inr hy) hyx⟩
theorem Maximal.or (h : Maximal (fun x ↦ P x ∨ Q x) x) : Maximal P x ∨ Maximal Q x :=
Minimal.or (α := αᵒᵈ) h
theorem minimal_and_iff_right_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) :
Minimal (fun x ↦ P x ∧ Q x) x ↔ (Minimal P x) ∧ Q x := by
simp_rw [and_iff_left_of_imp (fun x ↦ hPQ x), iff_self_and]
exact fun h ↦ hPQ h.prop
theorem minimal_and_iff_left_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) :
Minimal (fun x ↦ Q x ∧ P x) x ↔ Q x ∧ (Minimal P x) := by
simp_rw [iff_comm, and_comm, minimal_and_iff_right_of_imp hPQ, and_comm]
theorem maximal_and_iff_right_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) :
Maximal (fun x ↦ P x ∧ Q x) x ↔ (Maximal P x) ∧ Q x :=
minimal_and_iff_right_of_imp (α := αᵒᵈ) hPQ
theorem maximal_and_iff_left_of_imp (hPQ : ∀ ⦃x⦄, P x → Q x) :
Maximal (fun x ↦ Q x ∧ P x) x ↔ Q x ∧ (Maximal P x) :=
minimal_and_iff_left_of_imp (α := αᵒᵈ) hPQ
end LE
section Preorder
variable [Preorder α]
theorem minimal_iff_forall_lt : Minimal P x ↔ P x ∧ ∀ ⦃y⦄, y < x → ¬ P y := by
simp [Minimal, lt_iff_le_not_le, not_imp_not, imp.swap]
theorem maximal_iff_forall_gt : Maximal P x ↔ P x ∧ ∀ ⦃y⦄, x < y → ¬ P y :=
minimal_iff_forall_lt (α := αᵒᵈ)
theorem Minimal.not_prop_of_lt (h : Minimal P x) (hlt : y < x) : ¬ P y :=
(minimal_iff_forall_lt.1 h).2 hlt
theorem Maximal.not_prop_of_gt (h : Maximal P x) (hlt : x < y) : ¬ P y :=
(maximal_iff_forall_gt.1 h).2 hlt
theorem Minimal.not_lt (h : Minimal P x) (hy : P y) : ¬ (y < x) :=
fun hlt ↦ h.not_prop_of_lt hlt hy
theorem Maximal.not_gt (h : Maximal P x) (hy : P y) : ¬ (x < y) :=
fun hlt ↦ h.not_prop_of_gt hlt hy
@[simp] theorem minimal_le_iff : Minimal (· ≤ y) x ↔ x ≤ y ∧ IsMin x :=
minimal_iff_isMin (fun _ _ h h' ↦ h'.trans h)
@[simp] theorem maximal_ge_iff : Maximal (y ≤ ·) x ↔ y ≤ x ∧ IsMax x :=
minimal_le_iff (α := αᵒᵈ)
@[simp] theorem minimal_lt_iff : Minimal (· < y) x ↔ x < y ∧ IsMin x :=
minimal_iff_isMin (fun _ _ h h' ↦ h'.trans_lt h)
@[simp] theorem maximal_gt_iff : Maximal (y < ·) x ↔ y < x ∧ IsMax x :=
minimal_lt_iff (α := αᵒᵈ)
theorem not_minimal_iff_exists_lt (hx : P x) : ¬ Minimal P x ↔ ∃ y, y < x ∧ P y := by
simp_rw [not_minimal_iff hx, lt_iff_le_not_le, and_comm]
alias ⟨exists_lt_of_not_minimal, _⟩ := not_minimal_iff_exists_lt
theorem not_maximal_iff_exists_gt (hx : P x) : ¬ Maximal P x ↔ ∃ y, x < y ∧ P y :=
not_minimal_iff_exists_lt (α := αᵒᵈ) hx
alias ⟨exists_gt_of_not_maximal, _⟩ := not_maximal_iff_exists_gt
end Preorder
section PartialOrder
variable [PartialOrder α]
theorem Minimal.eq_of_ge (hx : Minimal P x) (hy : P y) (hge : y ≤ x) : x = y :=
(hx.2 hy hge).antisymm hge
theorem Minimal.eq_of_le (hx : Minimal P x) (hy : P y) (hle : y ≤ x) : y = x :=
(hx.eq_of_ge hy hle).symm
theorem Maximal.eq_of_le (hx : Maximal P x) (hy : P y) (hle : x ≤ y) : x = y :=
hle.antisymm <| hx.2 hy hle
theorem Maximal.eq_of_ge (hx : Maximal P x) (hy : P y) (hge : x ≤ y) : y = x :=
(hx.eq_of_le hy hge).symm
theorem minimal_iff : Minimal P x ↔ P x ∧ ∀ ⦃y⦄, P y → y ≤ x → x = y :=
⟨fun h ↦ ⟨h.1, fun _ ↦ h.eq_of_ge⟩, fun h ↦ ⟨h.1, fun _ hy hle ↦ (h.2 hy hle).le⟩⟩
theorem maximal_iff : Maximal P x ↔ P x ∧ ∀ ⦃y⦄, P y → x ≤ y → x = y :=
minimal_iff (α := αᵒᵈ)
theorem minimal_mem_iff {s : Set α} : Minimal (· ∈ s) x ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → y ≤ x → x = y :=
minimal_iff
theorem maximal_mem_iff {s : Set α} : Maximal (· ∈ s) x ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → x ≤ y → x = y :=
maximal_iff
/-- If `P y` holds, and everything satisfying `P` is above `y`, then `y` is the unique minimal
element satisfying `P`. -/
theorem minimal_iff_eq (hy : P y) (hP : ∀ ⦃x⦄, P x → y ≤ x) : Minimal P x ↔ x = y :=
⟨fun h ↦ h.eq_of_ge hy (hP h.prop), by rintro rfl; exact ⟨hy, fun z hz _ ↦ hP hz⟩⟩
/-- If `P y` holds, and everything satisfying `P` is below `y`, then `y` is the unique maximal
element satisfying `P`. -/
theorem maximal_iff_eq (hy : P y) (hP : ∀ ⦃x⦄, P x → x ≤ y) : Maximal P x ↔ x = y :=
minimal_iff_eq (α := αᵒᵈ) hy hP
@[simp] theorem minimal_ge_iff : Minimal (y ≤ ·) x ↔ x = y :=
minimal_iff_eq rfl.le fun _ ↦ id
@[simp] theorem maximal_le_iff : Maximal (· ≤ y) x ↔ x = y :=
maximal_iff_eq rfl.le fun _ ↦ id
theorem minimal_iff_minimal_of_imp_of_forall (hPQ : ∀ ⦃x⦄, Q x → P x)
(h : ∀ ⦃x⦄, P x → ∃ y, y ≤ x ∧ Q y) : Minimal P x ↔ Minimal Q x := by
refine ⟨fun h' ↦ ⟨?_, fun y hy hyx ↦ h'.le_of_le (hPQ hy) hyx⟩,
fun h' ↦ ⟨hPQ h'.prop, fun y hy hyx ↦ ?_⟩⟩
· obtain ⟨y, hyx, hy⟩ := h h'.prop
rwa [((h'.le_of_le (hPQ hy)) hyx).antisymm hyx]
obtain ⟨z, hzy, hz⟩ := h hy
exact (h'.le_of_le hz (hzy.trans hyx)).trans hzy
theorem maximal_iff_maximal_of_imp_of_forall (hPQ : ∀ ⦃x⦄, Q x → P x)
(h : ∀ ⦃x⦄, P x → ∃ y, x ≤ y ∧ Q y) : Maximal P x ↔ Maximal Q x :=
minimal_iff_minimal_of_imp_of_forall (α := αᵒᵈ) hPQ h
end PartialOrder
section Subset
variable {P : Set α → Prop} {s t : Set α}
theorem Minimal.eq_of_superset (h : Minimal P s) (ht : P t) (hts : t ⊆ s) : s = t :=
h.eq_of_ge ht hts
theorem Maximal.eq_of_subset (h : Maximal P s) (ht : P t) (hst : s ⊆ t) : s = t :=
h.eq_of_le ht hst
theorem Minimal.eq_of_subset (h : Minimal P s) (ht : P t) (hts : t ⊆ s) : t = s :=
h.eq_of_le ht hts
theorem Maximal.eq_of_superset (h : Maximal P s) (ht : P t) (hst : s ⊆ t) : t = s :=
h.eq_of_ge ht hst
theorem minimal_subset_iff : Minimal P s ↔ P s ∧ ∀ ⦃t⦄, P t → t ⊆ s → s = t :=
_root_.minimal_iff
theorem maximal_subset_iff : Maximal P s ↔ P s ∧ ∀ ⦃t⦄, P t → s ⊆ t → s = t :=
_root_.maximal_iff
theorem minimal_subset_iff' : Minimal P s ↔ P s ∧ ∀ ⦃t⦄, P t → t ⊆ s → s ⊆ t :=
Iff.rfl
theorem maximal_subset_iff' : Maximal P s ↔ P s ∧ ∀ ⦃t⦄, P t → s ⊆ t → t ⊆ s :=
Iff.rfl
theorem not_minimal_subset_iff (hs : P s) : ¬ Minimal P s ↔ ∃ t, t ⊂ s ∧ P t :=
not_minimal_iff_exists_lt hs
theorem not_maximal_subset_iff (hs : P s) : ¬ Maximal P s ↔ ∃ t, s ⊂ t ∧ P t :=
not_maximal_iff_exists_gt hs
theorem Set.minimal_iff_forall_ssubset : Minimal P s ↔ P s ∧ ∀ ⦃t⦄, t ⊂ s → ¬ P t :=
minimal_iff_forall_lt
theorem Minimal.not_prop_of_ssubset (h : Minimal P s) (ht : t ⊂ s) : ¬ P t :=
(minimal_iff_forall_lt.1 h).2 ht
theorem Minimal.not_ssubset (h : Minimal P s) (ht : P t) : ¬ t ⊂ s :=
h.not_lt ht
theorem Maximal.mem_of_prop_insert (h : Maximal P s) (hx : P (insert x s)) : x ∈ s :=
h.eq_of_subset hx (subset_insert _ _) ▸ mem_insert ..
theorem Minimal.not_mem_of_prop_diff_singleton (h : Minimal P s) (hx : P (s \ {x})) : x ∉ s :=
fun hxs ↦ ((h.eq_of_superset hx diff_subset).subset hxs).2 rfl
theorem Set.minimal_iff_forall_diff_singleton (hP : ∀ ⦃s t⦄, P t → t ⊆ s → P s) :
Minimal P s ↔ P s ∧ ∀ x ∈ s, ¬ P (s \ {x}) :=
⟨fun h ↦ ⟨h.1, fun _ hx hP ↦ h.not_mem_of_prop_diff_singleton hP hx⟩,
fun h ↦ ⟨h.1, fun _ ht hts x hxs ↦ by_contra fun hxt ↦
h.2 x hxs (hP ht <| subset_diff_singleton hts hxt)⟩⟩
theorem Set.exists_diff_singleton_of_not_minimal (hP : ∀ ⦃s t⦄, P t → t ⊆ s → P s) (hs : P s)
(h : ¬ Minimal P s) : ∃ x ∈ s, P (s \ {x}) := by
simpa [Set.minimal_iff_forall_diff_singleton hP, hs] using h
theorem Set.maximal_iff_forall_ssuperset : Maximal P s ↔ P s ∧ ∀ ⦃t⦄, s ⊂ t → ¬ P t :=
maximal_iff_forall_gt
theorem Maximal.not_prop_of_ssuperset (h : Maximal P s) (ht : s ⊂ t) : ¬ P t :=
(maximal_iff_forall_gt.1 h).2 ht
theorem Maximal.not_ssuperset (h : Maximal P s) (ht : P t) : ¬ s ⊂ t :=
h.not_gt ht
theorem Set.maximal_iff_forall_insert (hP : ∀ ⦃s t⦄, P t → s ⊆ t → P s) :
Maximal P s ↔ P s ∧ ∀ x ∉ s, ¬ P (insert x s) := by
simp only [not_imp_not]
exact ⟨fun h ↦ ⟨h.1, fun x ↦ h.mem_of_prop_insert⟩,
fun h ↦ ⟨h.1, fun t ht hst x hxt ↦ h.2 x (hP ht <| insert_subset hxt hst)⟩⟩
theorem Set.exists_insert_of_not_maximal (hP : ∀ ⦃s t⦄, P t → s ⊆ t → P s) (hs : P s)
(h : ¬ Maximal P s) : ∃ x ∉ s, P (insert x s) := by
simpa [Set.maximal_iff_forall_insert hP, hs] using h
/- TODO : generalize `minimal_iff_forall_diff_singleton` and `maximal_iff_forall_insert`
to `IsStronglyCoatomic`/`IsStronglyAtomic` orders. -/
end Subset
section Set
variable {s t : Set α}
section Preorder
variable [Preorder α]
theorem setOf_minimal_subset (s : Set α) : {x | Minimal (· ∈ s) x} ⊆ s :=
sep_subset ..
theorem setOf_maximal_subset (s : Set α) : {x | Minimal (· ∈ s) x} ⊆ s :=
sep_subset ..
theorem Set.Subsingleton.maximal_mem_iff (h : s.Subsingleton) : Maximal (· ∈ s) x ↔ x ∈ s := by
obtain (rfl | ⟨x, rfl⟩) := h.eq_empty_or_singleton <;> simp
theorem Set.Subsingleton.minimal_mem_iff (h : s.Subsingleton) : Minimal (· ∈ s) x ↔ x ∈ s := by
obtain (rfl | ⟨x, rfl⟩) := h.eq_empty_or_singleton <;> simp
theorem IsLeast.minimal (h : IsLeast s x) : Minimal (· ∈ s) x :=
⟨h.1, fun _b hb _ ↦ h.2 hb⟩
theorem IsGreatest.maximal (h : IsGreatest s x) : Maximal (· ∈ s) x :=
⟨h.1, fun _b hb _ ↦ h.2 hb⟩
theorem IsAntichain.minimal_mem_iff (hs : IsAntichain (· ≤ ·) s) : Minimal (· ∈ s) x ↔ x ∈ s :=
⟨fun h ↦ h.prop, fun h ↦ ⟨h, fun _ hys hyx ↦ (hs.eq hys h hyx).symm.le⟩⟩
theorem IsAntichain.maximal_mem_iff (hs : IsAntichain (· ≤ ·) s) : Maximal (· ∈ s) x ↔ x ∈ s :=
hs.to_dual.minimal_mem_iff
/-- If `t` is an antichain shadowing and including the set of maximal elements of `s`,
then `t` *is* the set of maximal elements of `s`. -/
theorem IsAntichain.eq_setOf_maximal (ht : IsAntichain (· ≤ ·) t)
(h : ∀ x, Maximal (· ∈ s) x → x ∈ t) (hs : ∀ a ∈ t, ∃ b, b ≤ a ∧ Maximal (· ∈ s) b) :
{x | Maximal (· ∈ s) x} = t := by
refine Set.ext fun x ↦ ⟨h _, fun hx ↦ ?_⟩
obtain ⟨y, hyx, hy⟩ := hs x hx
rwa [← ht.eq (h y hy) hx hyx]
/-- If `t` is an antichain shadowed by and including the set of minimal elements of `s`,
then `t` *is* the set of minimal elements of `s`. -/
theorem IsAntichain.eq_setOf_minimal (ht : IsAntichain (· ≤ ·) t)
(h : ∀ x, Minimal (· ∈ s) x → x ∈ t) (hs : ∀ a ∈ t, ∃ b, a ≤ b ∧ Minimal (· ∈ s) b) :
{x | Minimal (· ∈ s) x} = t :=
ht.to_dual.eq_setOf_maximal h hs
end Preorder
section PartialOrder
variable [PartialOrder α]
theorem setOf_maximal_antichain (P : α → Prop) : IsAntichain (· ≤ ·) {x | Maximal P x} :=
fun _ hx _ ⟨hy, _⟩ hne hle ↦ hne (hle.antisymm <| hx.2 hy hle)
theorem setOf_minimal_antichain (P : α → Prop) : IsAntichain (· ≤ ·) {x | Minimal P x} :=
(setOf_maximal_antichain (α := αᵒᵈ) P).swap
theorem IsAntichain.minimal_mem_upperClosure_iff_mem (hs : IsAntichain (· ≤ ·) s) :
Minimal (· ∈ upperClosure s) x ↔ x ∈ s := by
simp only [upperClosure, UpperSet.mem_mk, mem_setOf_eq]
refine ⟨fun h ↦ ?_, fun h ↦ ⟨⟨x, h, rfl.le⟩, fun b ⟨a, has, hab⟩ hbx ↦ ?_⟩⟩
· obtain ⟨a, has, hax⟩ := h.prop
rwa [h.eq_of_ge ⟨a, has, rfl.le⟩ hax]
rwa [← hs.eq has h (hab.trans hbx)]
theorem IsAntichain.maximal_mem_lowerClosure_iff_mem (hs : IsAntichain (· ≤ ·) s) :
Maximal (· ∈ lowerClosure s) x ↔ x ∈ s :=
hs.to_dual.minimal_mem_upperClosure_iff_mem
theorem IsLeast.minimal_iff (h : IsLeast s a) : Minimal (· ∈ s) x ↔ x = a :=
⟨fun h' ↦ h'.eq_of_ge h.1 (h.2 h'.prop), fun h' ↦ h' ▸ h.minimal⟩
theorem IsGreatest.maximal_iff (h : IsGreatest s a) : Maximal (· ∈ s) x ↔ x = a :=
⟨fun h' ↦ h'.eq_of_le h.1 (h.2 h'.prop), fun h' ↦ h' ▸ h.maximal⟩
end PartialOrder
end Set
section Image
variable [Preorder α] {β : Type*} [Preorder β] {s : Set α} {t : Set β}
section Function
variable {f : α → β}
theorem minimal_mem_image_monotone (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y))
(hx : Minimal (· ∈ s) x) : Minimal (· ∈ f '' s) (f x) := by
refine ⟨mem_image_of_mem f hx.prop, ?_⟩
rintro _ ⟨y, hy, rfl⟩
rw [hf hx.prop hy, hf hy hx.prop]
exact hx.le_of_le hy
theorem maximal_mem_image_monotone (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y))
(hx : Maximal (· ∈ s) x) : Maximal (· ∈ f '' s) (f x) :=
minimal_mem_image_monotone (α := αᵒᵈ) (β := βᵒᵈ) (s := s) (fun _ _ hx hy ↦ hf hy hx) hx
theorem minimal_mem_image_monotone_iff (ha : a ∈ s)
(hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y)) :
Minimal (· ∈ f '' s) (f a) ↔ Minimal (· ∈ s) a := by
refine ⟨fun h ↦ ⟨ha, fun y hys ↦ ?_⟩, minimal_mem_image_monotone hf⟩
rw [← hf ha hys, ← hf hys ha]
exact h.le_of_le (mem_image_of_mem f hys)
theorem maximal_mem_image_monotone_iff (ha : a ∈ s)
(hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y)) :
Maximal (· ∈ f '' s) (f a) ↔ Maximal (· ∈ s) a :=
minimal_mem_image_monotone_iff (α := αᵒᵈ) (β := βᵒᵈ) (s := s) ha fun _ _ hx hy ↦ hf hy hx
theorem minimal_mem_image_antitone (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ y ≤ x))
(hx : Minimal (· ∈ s) x) : Maximal (· ∈ f '' s) (f x) :=
minimal_mem_image_monotone (β := βᵒᵈ) (fun _ _ h h' ↦ hf h' h) hx
theorem maximal_mem_image_antitone (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ y ≤ x))
(hx : Maximal (· ∈ s) x) : Minimal (· ∈ f '' s) (f x) :=
maximal_mem_image_monotone (β := βᵒᵈ) (fun _ _ h h' ↦ hf h' h) hx
theorem minimal_mem_image_antitone_iff (ha : a ∈ s)
(hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ y ≤ x)) :
Minimal (· ∈ f '' s) (f a) ↔ Maximal (· ∈ s) a :=
maximal_mem_image_monotone_iff (β := βᵒᵈ) ha (fun _ _ h h' ↦ hf h' h)
theorem maximal_mem_image_antitone_iff (ha : a ∈ s)
(hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ y ≤ x)) :
Maximal (· ∈ f '' s) (f a) ↔ Minimal (· ∈ s) a :=
minimal_mem_image_monotone_iff (β := βᵒᵈ) ha (fun _ _ h h' ↦ hf h' h)
theorem image_monotone_setOf_minimal (hf : ∀ ⦃x y⦄, P x → P y → (f x ≤ f y ↔ x ≤ y)) :
f '' {x | Minimal P x} = {x | Minimal (∃ x₀, P x₀ ∧ f x₀ = ·) x} := by
refine Set.ext fun x ↦ ⟨?_, fun h ↦ ?_⟩
· rintro ⟨x, (hx : Minimal _ x), rfl⟩
exact (minimal_mem_image_monotone_iff hx.prop hf).2 hx
obtain ⟨y, hy, rfl⟩ := (mem_setOf_eq ▸ h).prop
exact mem_image_of_mem _ <| (minimal_mem_image_monotone_iff (s := setOf P) hy hf).1 h
theorem image_monotone_setOf_maximal (hf : ∀ ⦃x y⦄, P x → P y → (f x ≤ f y ↔ x ≤ y)) :
f '' {x | Maximal P x} = {x | Maximal (∃ x₀, P x₀ ∧ f x₀ = ·) x} :=
image_monotone_setOf_minimal (α := αᵒᵈ) (β := βᵒᵈ) (fun _ _ hx hy ↦ hf hy hx)
theorem image_antitone_setOf_minimal (hf : ∀ ⦃x y⦄, P x → P y → (f x ≤ f y ↔ y ≤ x)) :
f '' {x | Minimal P x} = {x | Maximal (∃ x₀, P x₀ ∧ f x₀ = ·) x} :=
image_monotone_setOf_minimal (β := βᵒᵈ) (fun _ _ hx hy ↦ hf hy hx)
theorem image_antitone_setOf_maximal (hf : ∀ ⦃x y⦄, P x → P y → (f x ≤ f y ↔ y ≤ x)) :
f '' {x | Maximal P x} = {x | Minimal (∃ x₀, P x₀ ∧ f x₀ = ·) x} :=
image_monotone_setOf_maximal (β := βᵒᵈ) (fun _ _ hx hy ↦ hf hy hx)
theorem image_monotone_setOf_minimal_mem (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y)) :
f '' {x | Minimal (· ∈ s) x} = {x | Minimal (· ∈ f '' s) x} :=
image_monotone_setOf_minimal hf
theorem image_monotone_setOf_maximal_mem (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ x ≤ y)) :
f '' {x | Maximal (· ∈ s) x} = {x | Maximal (· ∈ f '' s) x} :=
image_monotone_setOf_maximal hf
theorem image_antitone_setOf_minimal_mem (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ y ≤ x)) :
f '' {x | Minimal (· ∈ s) x} = {x | Maximal (· ∈ f '' s) x} :=
image_antitone_setOf_minimal hf
theorem image_antitone_setOf_maximal_mem (hf : ∀ ⦃x y⦄, x ∈ s → y ∈ s → (f x ≤ f y ↔ y ≤ x)) :
f '' {x | Maximal (· ∈ s) x} = {x | Minimal (· ∈ f '' s) x} :=
image_antitone_setOf_maximal hf
end Function
namespace OrderEmbedding
variable {f : α ↪o β} {t : Set β}
theorem minimal_mem_image (f : α ↪o β) (hx : Minimal (· ∈ s) x) : Minimal (· ∈ f '' s) (f x) :=
_root_.minimal_mem_image_monotone (by simp [f.le_iff_le]) hx
theorem maximal_mem_image (f : α ↪o β) (hx : Maximal (· ∈ s) x) : Maximal (· ∈ f '' s) (f x) :=
_root_.maximal_mem_image_monotone (by simp [f.le_iff_le]) hx
theorem minimal_mem_image_iff (ha : a ∈ s) : Minimal (· ∈ f '' s) (f a) ↔ Minimal (· ∈ s) a :=
_root_.minimal_mem_image_monotone_iff ha (by simp [f.le_iff_le])
theorem maximal_mem_image_iff (ha : a ∈ s) : Maximal (· ∈ f '' s) (f a) ↔ Maximal (· ∈ s) a :=
_root_.maximal_mem_image_monotone_iff ha (by simp [f.le_iff_le])
theorem minimal_apply_mem_inter_range_iff :
Minimal (· ∈ t ∩ range f) (f x) ↔ Minimal (fun x ↦ f x ∈ t) x := by
refine ⟨fun h ↦ ⟨h.prop.1, fun y hy ↦ ?_⟩, fun h ↦ ⟨⟨h.prop, by simp⟩, ?_⟩⟩
· rw [← f.le_iff_le, ← f.le_iff_le]
exact h.le_of_le ⟨hy, by simp⟩
rintro _ ⟨hyt, ⟨y, rfl⟩⟩
simp_rw [f.le_iff_le]
exact h.le_of_le hyt
theorem maximal_apply_mem_inter_range_iff :
Maximal (· ∈ t ∩ range f) (f x) ↔ Maximal (fun x ↦ f x ∈ t) x :=
f.dual.minimal_apply_mem_inter_range_iff
theorem minimal_apply_mem_iff (ht : t ⊆ Set.range f) :
Minimal (· ∈ t) (f x) ↔ Minimal (fun x ↦ f x ∈ t) x := by
rw [← f.minimal_apply_mem_inter_range_iff, inter_eq_self_of_subset_left ht]
theorem maximal_apply_iff (ht : t ⊆ Set.range f) :
Maximal (· ∈ t) (f x) ↔ Maximal (fun x ↦ f x ∈ t) x :=
f.dual.minimal_apply_mem_iff ht
@[simp] theorem image_setOf_minimal : f '' {x | Minimal (· ∈ s) x} = {x | Minimal (· ∈ f '' s) x} :=
_root_.image_monotone_setOf_minimal (by simp [f.le_iff_le])
@[simp] theorem image_setOf_maximal : f '' {x | Maximal (· ∈ s) x} = {x | Maximal (· ∈ f '' s) x} :=
_root_.image_monotone_setOf_maximal (by simp [f.le_iff_le])
theorem inter_preimage_setOf_minimal_eq_of_subset (hts : t ⊆ f '' s) :
x ∈ s ∩ f ⁻¹' {y | Minimal (· ∈ t) y} ↔ Minimal (· ∈ s ∩ f ⁻¹' t) x := by
simp_rw [mem_inter_iff, preimage_setOf_eq, mem_setOf_eq, mem_preimage,
f.minimal_apply_mem_iff (hts.trans (image_subset_range _ _)),
minimal_and_iff_left_of_imp (fun _ hx ↦ f.injective.mem_set_image.1 <| hts hx)]
theorem inter_preimage_setOf_maximal_eq_of_subset (hts : t ⊆ f '' s) :
x ∈ s ∩ f ⁻¹' {y | Maximal (· ∈ t) y} ↔ Maximal (· ∈ s ∩ f ⁻¹' t) x :=
f.dual.inter_preimage_setOf_minimal_eq_of_subset hts
end OrderEmbedding
namespace OrderIso
theorem image_setOf_minimal (f : α ≃o β) (P : α → Prop) :
f '' {x | Minimal P x} = {x | Minimal (fun x ↦ P (f.symm x)) x} := by
convert _root_.image_monotone_setOf_minimal (f := f) (by simp [f.le_iff_le])
aesop
theorem image_setOf_maximal (f : α ≃o β) (P : α → Prop) :
f '' {x | Maximal P x} = {x | Maximal (fun x ↦ P (f.symm x)) x} := by
convert _root_.image_monotone_setOf_maximal (f := f) (by simp [f.le_iff_le])
aesop
theorem map_minimal_mem (f : s ≃o t) (hx : Minimal (· ∈ s) x) :
Minimal (· ∈ t) (f ⟨x, hx.prop⟩) := by
simpa only [show t = range (Subtype.val ∘ f) by simp, mem_univ, minimal_true_subtype, hx,
true_imp_iff, image_univ] using OrderEmbedding.minimal_mem_image
(f.toOrderEmbedding.trans (OrderEmbedding.subtype t)) (s := univ) (x := ⟨x, hx.prop⟩)
theorem map_maximal_mem (f : s ≃o t) (hx : Maximal (· ∈ s) x) :
Maximal (· ∈ t) (f ⟨x, hx.prop⟩) := by
simpa only [show t = range (Subtype.val ∘ f) by simp, mem_univ, maximal_true_subtype, hx,
true_imp_iff, image_univ] using OrderEmbedding.maximal_mem_image
(f.toOrderEmbedding.trans (OrderEmbedding.subtype t)) (s := univ) (x := ⟨x, hx.prop⟩)
/-- If two sets are order isomorphic, their minimals are also order isomorphic. -/
def mapSetOfMinimal (f : s ≃o t) : {x | Minimal (· ∈ s) x} ≃o {x | Minimal (· ∈ t) x} where
toFun x := ⟨f ⟨x, x.2.1⟩, f.map_minimal_mem x.2⟩
invFun x := ⟨f.symm ⟨x, x.2.1⟩, f.symm.map_minimal_mem x.2⟩
left_inv x := Subtype.ext (by apply congr_arg Subtype.val <| f.left_inv ⟨x, x.2.1⟩)
right_inv x := Subtype.ext (by apply congr_arg Subtype.val <| f.right_inv ⟨x, x.2.1⟩)
map_rel_iff' {_ _} := f.map_rel_iff
/-- If two sets are order isomorphic, their maximals are also order isomorphic. -/
def mapSetOfMaximal (f : s ≃o t) : {x | Maximal (· ∈ s) x} ≃o {x | Maximal (· ∈ t) x} where
toFun x := ⟨f ⟨x, x.2.1⟩, f.map_maximal_mem x.2⟩
invFun x := ⟨f.symm ⟨x, x.2.1⟩, f.symm.map_maximal_mem x.2⟩
__ := (show OrderDual.ofDual ⁻¹' s ≃o OrderDual.ofDual ⁻¹' t from f.dual).mapSetOfMinimal
/-- If two sets are antitonically order isomorphic, their minimals/maximals are too. -/
def setOfMinimalIsoSetOfMaximal (f : s ≃o tᵒᵈ) :
{x | Minimal (· ∈ s) x} ≃o {x | Maximal (· ∈ t) (ofDual x)} where
toFun x := ⟨(f ⟨x.1, x.2.1⟩).1, ((show s ≃o ofDual ⁻¹' t from f).mapSetOfMinimal x).2⟩
invFun x := ⟨(f.symm ⟨x.1, x.2.1⟩).1,
((show ofDual ⁻¹' t ≃o s from f.symm).mapSetOfMinimal x).2⟩
__ := (show s ≃o ofDual⁻¹' t from f).mapSetOfMinimal
/-- If two sets are antitonically order isomorphic, their maximals/minimals are too. -/
def setOfMaximalIsoSetOfMinimal (f : s ≃o tᵒᵈ) :
{x | Maximal (· ∈ s) x} ≃o {x | Minimal (· ∈ t) (ofDual x)} where
toFun x := ⟨(f ⟨x.1, x.2.1⟩).1, ((show s ≃o ofDual ⁻¹' t from f).mapSetOfMaximal x).2⟩
invFun x := ⟨(f.symm ⟨x.1, x.2.1⟩).1,
((show ofDual ⁻¹' t ≃o s from f.symm).mapSetOfMaximal x).2⟩
__ := (show s ≃o ofDual⁻¹' t from f).mapSetOfMaximal
end OrderIso
end Image
section Interval
variable [PartialOrder α] {a b : α}
theorem minimal_mem_Icc (hab : a ≤ b) : Minimal (· ∈ Icc a b) x ↔ x = a :=
minimal_iff_eq ⟨rfl.le, hab⟩ (fun _ ↦ And.left)
theorem maximal_mem_Icc (hab : a ≤ b) : Maximal (· ∈ Icc a b) x ↔ x = b :=
maximal_iff_eq ⟨hab, rfl.le⟩ (fun _ ↦ And.right)
theorem minimal_mem_Ico (hab : a < b) : Minimal (· ∈ Ico a b) x ↔ x = a :=
minimal_iff_eq ⟨rfl.le, hab⟩ (fun _ ↦ And.left)
theorem maximal_mem_Ioc (hab : a < b) : Maximal (· ∈ Ioc a b) x ↔ x = b :=
maximal_iff_eq ⟨hab, rfl.le⟩ (fun _ ↦ And.right)
/- Note : The one-sided interval versions of these lemmas are unnecessary,
since `simp` handles them with `maximal_le_iff` and `minimal_ge_iff`. -/
end Interval
|
Order\MinMax.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Order.Lattice
/-!
# `max` and `min`
This file proves basic properties about maxima and minima on a `LinearOrder`.
## Tags
min, max
-/
universe u v
variable {α : Type u} {β : Type v}
attribute [simp] max_eq_left max_eq_right min_eq_left min_eq_right
section
variable [LinearOrder α] [LinearOrder β] {f : α → β} {s : Set α} {a b c d : α}
-- translate from lattices to linear orders (sup → max, inf → min)
@[simp]
theorem le_min_iff : c ≤ min a b ↔ c ≤ a ∧ c ≤ b :=
le_inf_iff
@[simp]
theorem le_max_iff : a ≤ max b c ↔ a ≤ b ∨ a ≤ c :=
le_sup_iff
@[simp]
theorem min_le_iff : min a b ≤ c ↔ a ≤ c ∨ b ≤ c :=
inf_le_iff
@[simp]
theorem max_le_iff : max a b ≤ c ↔ a ≤ c ∧ b ≤ c :=
sup_le_iff
@[simp]
theorem lt_min_iff : a < min b c ↔ a < b ∧ a < c :=
lt_inf_iff
@[simp]
theorem lt_max_iff : a < max b c ↔ a < b ∨ a < c :=
lt_sup_iff
@[simp]
theorem min_lt_iff : min a b < c ↔ a < c ∨ b < c :=
inf_lt_iff
@[simp]
theorem max_lt_iff : max a b < c ↔ a < c ∧ b < c :=
sup_lt_iff
@[gcongr]
theorem max_le_max : a ≤ c → b ≤ d → max a b ≤ max c d :=
sup_le_sup
@[gcongr] theorem max_le_max_left (c) (h : a ≤ b) : max c a ≤ max c b := sup_le_sup_left h c
@[gcongr] theorem max_le_max_right (c) (h : a ≤ b) : max a c ≤ max b c := sup_le_sup_right h c
@[gcongr]
theorem min_le_min : a ≤ c → b ≤ d → min a b ≤ min c d :=
inf_le_inf
@[gcongr] theorem min_le_min_left (c) (h : a ≤ b) : min c a ≤ min c b := inf_le_inf_left c h
@[gcongr] theorem min_le_min_right (c) (h : a ≤ b) : min a c ≤ min b c := inf_le_inf_right c h
theorem le_max_of_le_left : a ≤ b → a ≤ max b c :=
le_sup_of_le_left
theorem le_max_of_le_right : a ≤ c → a ≤ max b c :=
le_sup_of_le_right
theorem lt_max_of_lt_left (h : a < b) : a < max b c :=
h.trans_le (le_max_left b c)
theorem lt_max_of_lt_right (h : a < c) : a < max b c :=
h.trans_le (le_max_right b c)
theorem min_le_of_left_le : a ≤ c → min a b ≤ c :=
inf_le_of_left_le
theorem min_le_of_right_le : b ≤ c → min a b ≤ c :=
inf_le_of_right_le
theorem min_lt_of_left_lt (h : a < c) : min a b < c :=
(min_le_left a b).trans_lt h
theorem min_lt_of_right_lt (h : b < c) : min a b < c :=
(min_le_right a b).trans_lt h
lemma max_min_distrib_left (a b c : α) : max a (min b c) = min (max a b) (max a c) :=
sup_inf_left _ _ _
lemma max_min_distrib_right (a b c : α) : max (min a b) c = min (max a c) (max b c) :=
sup_inf_right _ _ _
lemma min_max_distrib_left (a b c : α) : min a (max b c) = max (min a b) (min a c) :=
inf_sup_left _ _ _
lemma min_max_distrib_right (a b c : α) : min (max a b) c = max (min a c) (min b c) :=
inf_sup_right _ _ _
theorem min_le_max : min a b ≤ max a b :=
le_trans (min_le_left a b) (le_max_left a b)
@[simp]
theorem min_eq_left_iff : min a b = a ↔ a ≤ b :=
inf_eq_left
@[simp]
theorem min_eq_right_iff : min a b = b ↔ b ≤ a :=
inf_eq_right
@[simp]
theorem max_eq_left_iff : max a b = a ↔ b ≤ a :=
sup_eq_left
@[simp]
theorem max_eq_right_iff : max a b = b ↔ a ≤ b :=
sup_eq_right
/-- For elements `a` and `b` of a linear order, either `min a b = a` and `a ≤ b`,
or `min a b = b` and `b < a`.
Use cases on this lemma to automate linarith in inequalities -/
theorem min_cases (a b : α) : min a b = a ∧ a ≤ b ∨ min a b = b ∧ b < a := by
by_cases h : a ≤ b
· left
exact ⟨min_eq_left h, h⟩
· right
exact ⟨min_eq_right (le_of_lt (not_le.mp h)), not_le.mp h⟩
/-- For elements `a` and `b` of a linear order, either `max a b = a` and `b ≤ a`,
or `max a b = b` and `a < b`.
Use cases on this lemma to automate linarith in inequalities -/
theorem max_cases (a b : α) : max a b = a ∧ b ≤ a ∨ max a b = b ∧ a < b :=
@min_cases αᵒᵈ _ a b
theorem min_eq_iff : min a b = c ↔ a = c ∧ a ≤ b ∨ b = c ∧ b ≤ a := by
constructor
· intro h
refine Or.imp (fun h' => ?_) (fun h' => ?_) (le_total a b) <;> exact ⟨by simpa [h'] using h, h'⟩
· rintro (⟨rfl, h⟩ | ⟨rfl, h⟩) <;> simp [h]
theorem max_eq_iff : max a b = c ↔ a = c ∧ b ≤ a ∨ b = c ∧ a ≤ b :=
@min_eq_iff αᵒᵈ _ a b c
theorem min_lt_min_left_iff : min a c < min b c ↔ a < b ∧ a < c := by
simp_rw [lt_min_iff, min_lt_iff, or_iff_left (lt_irrefl _)]
exact and_congr_left fun h => or_iff_left_of_imp h.trans
theorem min_lt_min_right_iff : min a b < min a c ↔ b < c ∧ b < a := by
simp_rw [min_comm a, min_lt_min_left_iff]
theorem max_lt_max_left_iff : max a c < max b c ↔ a < b ∧ c < b :=
@min_lt_min_left_iff αᵒᵈ _ _ _ _
theorem max_lt_max_right_iff : max a b < max a c ↔ b < c ∧ a < c :=
@min_lt_min_right_iff αᵒᵈ _ _ _ _
/-- An instance asserting that `max a a = a` -/
instance max_idem : Std.IdempotentOp (α := α) max where
idempotent := by simp
-- short-circuit type class inference
/-- An instance asserting that `min a a = a` -/
instance min_idem : Std.IdempotentOp (α := α) min where
idempotent := by simp
-- short-circuit type class inference
theorem min_lt_max : min a b < max a b ↔ a ≠ b :=
inf_lt_sup
-- Porting note: was `by simp [lt_max_iff, max_lt_iff, *]`
theorem max_lt_max (h₁ : a < c) (h₂ : b < d) : max a b < max c d :=
max_lt (lt_max_of_lt_left h₁) (lt_max_of_lt_right h₂)
theorem min_lt_min (h₁ : a < c) (h₂ : b < d) : min a b < min c d :=
@max_lt_max αᵒᵈ _ _ _ _ _ h₁ h₂
theorem min_right_comm (a b c : α) : min (min a b) c = min (min a c) b :=
right_comm min min_comm min_assoc a b c
theorem Max.left_comm (a b c : α) : max a (max b c) = max b (max a c) :=
_root_.left_comm max max_comm max_assoc a b c
theorem Max.right_comm (a b c : α) : max (max a b) c = max (max a c) b :=
_root_.right_comm max max_comm max_assoc a b c
theorem MonotoneOn.map_max (hf : MonotoneOn f s) (ha : a ∈ s) (hb : b ∈ s) : f (max a b) =
max (f a) (f b) := by
rcases le_total a b with h | h <;>
simp only [max_eq_right, max_eq_left, hf ha hb, hf hb ha, h]
theorem MonotoneOn.map_min (hf : MonotoneOn f s) (ha : a ∈ s) (hb : b ∈ s) : f (min a b) =
min (f a) (f b) := hf.dual.map_max ha hb
theorem AntitoneOn.map_max (hf : AntitoneOn f s) (ha : a ∈ s) (hb : b ∈ s) : f (max a b) =
min (f a) (f b) := hf.dual_right.map_max ha hb
theorem AntitoneOn.map_min (hf : AntitoneOn f s) (ha : a ∈ s) (hb : b ∈ s) : f (min a b) =
max (f a) (f b) := hf.dual.map_max ha hb
theorem Monotone.map_max (hf : Monotone f) : f (max a b) = max (f a) (f b) := by
rcases le_total a b with h | h <;> simp [h, hf h]
theorem Monotone.map_min (hf : Monotone f) : f (min a b) = min (f a) (f b) :=
hf.dual.map_max
theorem Antitone.map_max (hf : Antitone f) : f (max a b) = min (f a) (f b) := by
rcases le_total a b with h | h <;> simp [h, hf h]
theorem Antitone.map_min (hf : Antitone f) : f (min a b) = max (f a) (f b) :=
hf.dual.map_max
theorem min_choice (a b : α) : min a b = a ∨ min a b = b := by cases le_total a b <;> simp [*]
theorem max_choice (a b : α) : max a b = a ∨ max a b = b :=
@min_choice αᵒᵈ _ a b
theorem le_of_max_le_left {a b c : α} (h : max a b ≤ c) : a ≤ c :=
le_trans (le_max_left _ _) h
theorem le_of_max_le_right {a b c : α} (h : max a b ≤ c) : b ≤ c :=
le_trans (le_max_right _ _) h
theorem max_commutative : Commutative (max : α → α → α) :=
max_comm
theorem max_associative : Associative (max : α → α → α) :=
max_assoc
instance : Std.Commutative (α := α) max where
comm := max_comm
instance : Std.Associative (α := α) max where
assoc := max_assoc
theorem max_left_commutative : LeftCommutative (max : α → α → α) :=
max_left_comm
theorem min_commutative : Commutative (min : α → α → α) :=
min_comm
theorem min_associative : Associative (α := α) min :=
min_assoc
instance : Std.Commutative (α := α) min where
comm := min_comm
instance : Std.Associative (α := α) min where
assoc := min_assoc
theorem min_left_commutative : LeftCommutative (min : α → α → α) :=
min_left_comm
end
|
Order\ModularLattice.lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Yaël Dillies
-/
import Mathlib.Order.Cover
import Mathlib.Order.LatticeIntervals
import Mathlib.Order.GaloisConnection
/-!
# Modular Lattices
This file defines (semi)modular lattices, a kind of lattice useful in algebra.
For examples, look to the subobject lattices of abelian groups, submodules, and ideals, or consider
any distributive lattice.
## Typeclasses
We define (semi)modularity typeclasses as Prop-valued mixins.
* `IsWeakUpperModularLattice`: Weakly upper modular lattices. Lattice where `a ⊔ b` covers `a`
and `b` if `a` and `b` both cover `a ⊓ b`.
* `IsWeakLowerModularLattice`: Weakly lower modular lattices. Lattice where `a` and `b` cover
`a ⊓ b` if `a ⊔ b` covers both `a` and `b`
* `IsUpperModularLattice`: Upper modular lattices. Lattices where `a ⊔ b` covers `a` if `b`
covers `a ⊓ b`.
* `IsLowerModularLattice`: Lower modular lattices. Lattices where `a` covers `a ⊓ b` if `a ⊔ b`
covers `b`.
- `IsModularLattice`: Modular lattices. Lattices where `a ≤ c → (a ⊔ b) ⊓ c = a ⊔ (b ⊓ c)`. We
only require an inequality because the other direction holds in all lattices.
## Main Definitions
- `infIccOrderIsoIccSup` gives an order isomorphism between the intervals
`[a ⊓ b, a]` and `[b, a ⊔ b]`.
This corresponds to the diamond (or second) isomorphism theorems of algebra.
## Main Results
- `isModularLattice_iff_inf_sup_inf_assoc`:
Modularity is equivalent to the `inf_sup_inf_assoc`: `(x ⊓ z) ⊔ (y ⊓ z) = ((x ⊓ z) ⊔ y) ⊓ z`
- `DistribLattice.isModularLattice`: Distributive lattices are modular.
## References
* [Manfred Stern, *Semimodular lattices. {Theory} and applications*][stern2009]
* [Wikipedia, *Modular Lattice*][https://en.wikipedia.org/wiki/Modular_lattice]
## TODO
- Relate atoms and coatoms in modular lattices
-/
open Set
variable {α : Type*}
/-- A weakly upper modular lattice is a lattice where `a ⊔ b` covers `a` and `b` if `a` and `b` both
cover `a ⊓ b`. -/
class IsWeakUpperModularLattice (α : Type*) [Lattice α] : Prop where
/-- `a ⊔ b` covers `a` and `b` if `a` and `b` both cover `a ⊓ b`. -/
covBy_sup_of_inf_covBy_covBy {a b : α} : a ⊓ b ⋖ a → a ⊓ b ⋖ b → a ⋖ a ⊔ b
/-- A weakly lower modular lattice is a lattice where `a` and `b` cover `a ⊓ b` if `a ⊔ b` covers
both `a` and `b`. -/
class IsWeakLowerModularLattice (α : Type*) [Lattice α] : Prop where
/-- `a` and `b` cover `a ⊓ b` if `a ⊔ b` covers both `a` and `b` -/
inf_covBy_of_covBy_covBy_sup {a b : α} : a ⋖ a ⊔ b → b ⋖ a ⊔ b → a ⊓ b ⋖ a
/-- An upper modular lattice, aka semimodular lattice, is a lattice where `a ⊔ b` covers `a` and `b`
if either `a` or `b` covers `a ⊓ b`. -/
class IsUpperModularLattice (α : Type*) [Lattice α] : Prop where
/-- `a ⊔ b` covers `a` and `b` if either `a` or `b` covers `a ⊓ b` -/
covBy_sup_of_inf_covBy {a b : α} : a ⊓ b ⋖ a → b ⋖ a ⊔ b
/-- A lower modular lattice is a lattice where `a` and `b` both cover `a ⊓ b` if `a ⊔ b` covers
either `a` or `b`. -/
class IsLowerModularLattice (α : Type*) [Lattice α] : Prop where
/-- `a` and `b` both cover `a ⊓ b` if `a ⊔ b` covers either `a` or `b` -/
inf_covBy_of_covBy_sup {a b : α} : a ⋖ a ⊔ b → a ⊓ b ⋖ b
/-- A modular lattice is one with a limited associativity between `⊓` and `⊔`. -/
class IsModularLattice (α : Type*) [Lattice α] : Prop where
/-- Whenever `x ≤ z`, then for any `y`, `(x ⊔ y) ⊓ z ≤ x ⊔ (y ⊓ z)` -/
sup_inf_le_assoc_of_le : ∀ {x : α} (y : α) {z : α}, x ≤ z → (x ⊔ y) ⊓ z ≤ x ⊔ y ⊓ z
section WeakUpperModular
variable [Lattice α] [IsWeakUpperModularLattice α] {a b : α}
theorem covBy_sup_of_inf_covBy_of_inf_covBy_left : a ⊓ b ⋖ a → a ⊓ b ⋖ b → a ⋖ a ⊔ b :=
IsWeakUpperModularLattice.covBy_sup_of_inf_covBy_covBy
theorem covBy_sup_of_inf_covBy_of_inf_covBy_right : a ⊓ b ⋖ a → a ⊓ b ⋖ b → b ⋖ a ⊔ b := by
rw [inf_comm, sup_comm]
exact fun ha hb => covBy_sup_of_inf_covBy_of_inf_covBy_left hb ha
alias CovBy.sup_of_inf_of_inf_left := covBy_sup_of_inf_covBy_of_inf_covBy_left
alias CovBy.sup_of_inf_of_inf_right := covBy_sup_of_inf_covBy_of_inf_covBy_right
instance : IsWeakLowerModularLattice (OrderDual α) :=
⟨fun ha hb => (ha.ofDual.sup_of_inf_of_inf_left hb.ofDual).toDual⟩
end WeakUpperModular
section WeakLowerModular
variable [Lattice α] [IsWeakLowerModularLattice α] {a b : α}
theorem inf_covBy_of_covBy_sup_of_covBy_sup_left : a ⋖ a ⊔ b → b ⋖ a ⊔ b → a ⊓ b ⋖ a :=
IsWeakLowerModularLattice.inf_covBy_of_covBy_covBy_sup
theorem inf_covBy_of_covBy_sup_of_covBy_sup_right : a ⋖ a ⊔ b → b ⋖ a ⊔ b → a ⊓ b ⋖ b := by
rw [sup_comm, inf_comm]
exact fun ha hb => inf_covBy_of_covBy_sup_of_covBy_sup_left hb ha
alias CovBy.inf_of_sup_of_sup_left := inf_covBy_of_covBy_sup_of_covBy_sup_left
alias CovBy.inf_of_sup_of_sup_right := inf_covBy_of_covBy_sup_of_covBy_sup_right
instance : IsWeakUpperModularLattice (OrderDual α) :=
⟨fun ha hb => (ha.ofDual.inf_of_sup_of_sup_left hb.ofDual).toDual⟩
end WeakLowerModular
section UpperModular
variable [Lattice α] [IsUpperModularLattice α] {a b : α}
theorem covBy_sup_of_inf_covBy_left : a ⊓ b ⋖ a → b ⋖ a ⊔ b :=
IsUpperModularLattice.covBy_sup_of_inf_covBy
theorem covBy_sup_of_inf_covBy_right : a ⊓ b ⋖ b → a ⋖ a ⊔ b := by
rw [sup_comm, inf_comm]
exact covBy_sup_of_inf_covBy_left
alias CovBy.sup_of_inf_left := covBy_sup_of_inf_covBy_left
alias CovBy.sup_of_inf_right := covBy_sup_of_inf_covBy_right
-- See note [lower instance priority]
instance (priority := 100) IsUpperModularLattice.to_isWeakUpperModularLattice :
IsWeakUpperModularLattice α :=
⟨fun _ => CovBy.sup_of_inf_right⟩
instance : IsLowerModularLattice (OrderDual α) :=
⟨fun h => h.ofDual.sup_of_inf_left.toDual⟩
end UpperModular
section LowerModular
variable [Lattice α] [IsLowerModularLattice α] {a b : α}
theorem inf_covBy_of_covBy_sup_left : a ⋖ a ⊔ b → a ⊓ b ⋖ b :=
IsLowerModularLattice.inf_covBy_of_covBy_sup
theorem inf_covBy_of_covBy_sup_right : b ⋖ a ⊔ b → a ⊓ b ⋖ a := by
rw [inf_comm, sup_comm]
exact inf_covBy_of_covBy_sup_left
alias CovBy.inf_of_sup_left := inf_covBy_of_covBy_sup_left
alias CovBy.inf_of_sup_right := inf_covBy_of_covBy_sup_right
-- See note [lower instance priority]
instance (priority := 100) IsLowerModularLattice.to_isWeakLowerModularLattice :
IsWeakLowerModularLattice α :=
⟨fun _ => CovBy.inf_of_sup_right⟩
instance : IsUpperModularLattice (OrderDual α) :=
⟨fun h => h.ofDual.inf_of_sup_left.toDual⟩
end LowerModular
section IsModularLattice
variable [Lattice α] [IsModularLattice α]
theorem sup_inf_assoc_of_le {x : α} (y : α) {z : α} (h : x ≤ z) : (x ⊔ y) ⊓ z = x ⊔ y ⊓ z :=
le_antisymm (IsModularLattice.sup_inf_le_assoc_of_le y h)
(le_inf (sup_le_sup_left inf_le_left _) (sup_le h inf_le_right))
theorem IsModularLattice.inf_sup_inf_assoc {x y z : α} : x ⊓ z ⊔ y ⊓ z = (x ⊓ z ⊔ y) ⊓ z :=
(sup_inf_assoc_of_le y inf_le_right).symm
theorem inf_sup_assoc_of_le {x : α} (y : α) {z : α} (h : z ≤ x) : x ⊓ y ⊔ z = x ⊓ (y ⊔ z) := by
rw [inf_comm, sup_comm, ← sup_inf_assoc_of_le y h, inf_comm, sup_comm]
instance : IsModularLattice αᵒᵈ :=
⟨fun y z xz =>
le_of_eq
(by
rw [inf_comm, sup_comm, eq_comm, inf_comm, sup_comm]
exact @sup_inf_assoc_of_le α _ _ _ y _ xz)⟩
variable {x y z : α}
theorem IsModularLattice.sup_inf_sup_assoc : (x ⊔ z) ⊓ (y ⊔ z) = (x ⊔ z) ⊓ y ⊔ z :=
@IsModularLattice.inf_sup_inf_assoc αᵒᵈ _ _ _ _ _
theorem eq_of_le_of_inf_le_of_le_sup (hxy : x ≤ y) (hinf : y ⊓ z ≤ x) (hsup : y ≤ x ⊔ z) :
x = y := by
refine hxy.antisymm ?_
rw [← inf_eq_right, sup_inf_assoc_of_le _ hxy] at hsup
rwa [← hsup, sup_le_iff, and_iff_right rfl.le, inf_comm]
theorem eq_of_le_of_inf_le_of_sup_le (hxy : x ≤ y) (hinf : y ⊓ z ≤ x ⊓ z) (hsup : y ⊔ z ≤ x ⊔ z) :
x = y :=
eq_of_le_of_inf_le_of_le_sup hxy (hinf.trans inf_le_left) (le_sup_left.trans hsup)
theorem sup_lt_sup_of_lt_of_inf_le_inf (hxy : x < y) (hinf : y ⊓ z ≤ x ⊓ z) : x ⊔ z < y ⊔ z :=
lt_of_le_of_ne (sup_le_sup_right (le_of_lt hxy) _) fun hsup =>
ne_of_lt hxy <| eq_of_le_of_inf_le_of_sup_le (le_of_lt hxy) hinf (le_of_eq hsup.symm)
theorem inf_lt_inf_of_lt_of_sup_le_sup (hxy : x < y) (hinf : y ⊔ z ≤ x ⊔ z) : x ⊓ z < y ⊓ z :=
sup_lt_sup_of_lt_of_inf_le_inf (α := αᵒᵈ) hxy hinf
/-- A generalization of the theorem that if `N` is a submodule of `M` and
`N` and `M / N` are both Artinian, then `M` is Artinian. -/
theorem wellFounded_lt_exact_sequence {β γ : Type*} [PartialOrder β] [Preorder γ]
(h₁ : WellFounded ((· < ·) : β → β → Prop)) (h₂ : WellFounded ((· < ·) : γ → γ → Prop)) (K : α)
(f₁ : β → α) (f₂ : α → β) (g₁ : γ → α) (g₂ : α → γ) (gci : GaloisCoinsertion f₁ f₂)
(gi : GaloisInsertion g₂ g₁) (hf : ∀ a, f₁ (f₂ a) = a ⊓ K) (hg : ∀ a, g₁ (g₂ a) = a ⊔ K) :
WellFounded ((· < ·) : α → α → Prop) :=
Subrelation.wf
(@fun A B hAB =>
show Prod.Lex (· < ·) (· < ·) (f₂ A, g₂ A) (f₂ B, g₂ B) by
simp only [Prod.lex_def, lt_iff_le_not_le, ← gci.l_le_l_iff, ← gi.u_le_u_iff, hf, hg,
le_antisymm_iff]
simp only [gci.l_le_l_iff, gi.u_le_u_iff, ← lt_iff_le_not_le, ← le_antisymm_iff]
rcases lt_or_eq_of_le (inf_le_inf_right K (le_of_lt hAB)) with h | h
· exact Or.inl h
· exact Or.inr ⟨h, sup_lt_sup_of_lt_of_inf_le_inf hAB (le_of_eq h.symm)⟩)
(InvImage.wf _ (h₁.prod_lex h₂))
/-- A generalization of the theorem that if `N` is a submodule of `M` and
`N` and `M / N` are both Noetherian, then `M` is Noetherian. -/
theorem wellFounded_gt_exact_sequence {β γ : Type*} [Preorder β] [PartialOrder γ]
(h₁ : WellFounded ((· > ·) : β → β → Prop)) (h₂ : WellFounded ((· > ·) : γ → γ → Prop)) (K : α)
(f₁ : β → α) (f₂ : α → β) (g₁ : γ → α) (g₂ : α → γ) (gci : GaloisCoinsertion f₁ f₂)
(gi : GaloisInsertion g₂ g₁) (hf : ∀ a, f₁ (f₂ a) = a ⊓ K) (hg : ∀ a, g₁ (g₂ a) = a ⊔ K) :
WellFounded ((· > ·) : α → α → Prop) :=
wellFounded_lt_exact_sequence (α := αᵒᵈ) (β := γᵒᵈ) (γ := βᵒᵈ)
h₂ h₁ K g₁ g₂ f₁ f₂ gi.dual gci.dual hg hf
/-- The diamond isomorphism between the intervals `[a ⊓ b, a]` and `[b, a ⊔ b]` -/
@[simps]
def infIccOrderIsoIccSup (a b : α) : Set.Icc (a ⊓ b) a ≃o Set.Icc b (a ⊔ b) where
toFun x := ⟨x ⊔ b, ⟨le_sup_right, sup_le_sup_right x.prop.2 b⟩⟩
invFun x := ⟨a ⊓ x, ⟨inf_le_inf_left a x.prop.1, inf_le_left⟩⟩
left_inv x :=
Subtype.ext
(by
change a ⊓ (↑x ⊔ b) = ↑x
rw [sup_comm, ← inf_sup_assoc_of_le _ x.prop.2, sup_eq_right.2 x.prop.1])
right_inv x :=
Subtype.ext
(by
change a ⊓ ↑x ⊔ b = ↑x
rw [inf_comm, inf_sup_assoc_of_le _ x.prop.1, inf_eq_left.2 x.prop.2])
map_rel_iff' := @fun x y => by
simp only [Subtype.mk_le_mk, Equiv.coe_fn_mk, and_true_iff, le_sup_right]
rw [← Subtype.coe_le_coe]
refine ⟨fun h => ?_, fun h => sup_le_sup_right h _⟩
rw [← sup_eq_right.2 x.prop.1, inf_sup_assoc_of_le _ x.prop.2, sup_comm, ←
sup_eq_right.2 y.prop.1, inf_sup_assoc_of_le _ y.prop.2, sup_comm b]
exact inf_le_inf_left _ h
theorem inf_strictMonoOn_Icc_sup {a b : α} : StrictMonoOn (fun c => a ⊓ c) (Icc b (a ⊔ b)) :=
StrictMono.of_restrict (infIccOrderIsoIccSup a b).symm.strictMono
theorem sup_strictMonoOn_Icc_inf {a b : α} : StrictMonoOn (fun c => c ⊔ b) (Icc (a ⊓ b) a) :=
StrictMono.of_restrict (infIccOrderIsoIccSup a b).strictMono
/-- The diamond isomorphism between the intervals `]a ⊓ b, a[` and `}b, a ⊔ b[`. -/
@[simps]
def infIooOrderIsoIooSup (a b : α) : Ioo (a ⊓ b) a ≃o Ioo b (a ⊔ b) where
toFun c :=
⟨c ⊔ b,
le_sup_right.trans_lt <|
sup_strictMonoOn_Icc_inf (left_mem_Icc.2 inf_le_left) (Ioo_subset_Icc_self c.2) c.2.1,
sup_strictMonoOn_Icc_inf (Ioo_subset_Icc_self c.2) (right_mem_Icc.2 inf_le_left) c.2.2⟩
invFun c :=
⟨a ⊓ c,
inf_strictMonoOn_Icc_sup (left_mem_Icc.2 le_sup_right) (Ioo_subset_Icc_self c.2) c.2.1,
inf_le_left.trans_lt' <|
inf_strictMonoOn_Icc_sup (Ioo_subset_Icc_self c.2) (right_mem_Icc.2 le_sup_right) c.2.2⟩
left_inv c :=
Subtype.ext <| by
dsimp
rw [sup_comm, ← inf_sup_assoc_of_le _ c.prop.2.le, sup_eq_right.2 c.prop.1.le]
right_inv c :=
Subtype.ext <| by
dsimp
rw [inf_comm, inf_sup_assoc_of_le _ c.prop.1.le, inf_eq_left.2 c.prop.2.le]
map_rel_iff' := @fun c d =>
@OrderIso.le_iff_le _ _ _ _ (infIccOrderIsoIccSup _ _) ⟨c.1, Ioo_subset_Icc_self c.2⟩
⟨d.1, Ioo_subset_Icc_self d.2⟩
-- See note [lower instance priority]
instance (priority := 100) IsModularLattice.to_isLowerModularLattice : IsLowerModularLattice α :=
⟨fun {a b} => by
simp_rw [covBy_iff_Ioo_eq, sup_comm a, inf_comm a, ← isEmpty_coe_sort, right_lt_sup,
inf_lt_left, (infIooOrderIsoIooSup b a).symm.toEquiv.isEmpty_congr]
exact id⟩
-- See note [lower instance priority]
instance (priority := 100) IsModularLattice.to_isUpperModularLattice : IsUpperModularLattice α :=
⟨fun {a b} => by
simp_rw [covBy_iff_Ioo_eq, ← isEmpty_coe_sort, right_lt_sup, inf_lt_left,
(infIooOrderIsoIooSup a b).toEquiv.isEmpty_congr]
exact id⟩
end IsModularLattice
namespace IsCompl
variable [Lattice α] [BoundedOrder α] [IsModularLattice α]
/-- The diamond isomorphism between the intervals `Set.Iic a` and `Set.Ici b`. -/
def IicOrderIsoIci {a b : α} (h : IsCompl a b) : Set.Iic a ≃o Set.Ici b :=
(OrderIso.setCongr (Set.Iic a) (Set.Icc (a ⊓ b) a)
(h.inf_eq_bot.symm ▸ Set.Icc_bot.symm)).trans <|
(infIccOrderIsoIccSup a b).trans
(OrderIso.setCongr (Set.Icc b (a ⊔ b)) (Set.Ici b) (h.sup_eq_top.symm ▸ Set.Icc_top))
end IsCompl
theorem isModularLattice_iff_inf_sup_inf_assoc [Lattice α] :
IsModularLattice α ↔ ∀ x y z : α, x ⊓ z ⊔ y ⊓ z = (x ⊓ z ⊔ y) ⊓ z :=
⟨fun h => @IsModularLattice.inf_sup_inf_assoc _ _ h, fun h =>
⟨fun y z xz => by rw [← inf_eq_left.2 xz, h]⟩⟩
namespace DistribLattice
instance (priority := 100) [DistribLattice α] : IsModularLattice α :=
⟨fun y z xz => by rw [inf_sup_right, inf_eq_left.2 xz]⟩
end DistribLattice
namespace Disjoint
variable {a b c : α}
theorem disjoint_sup_right_of_disjoint_sup_left [Lattice α] [OrderBot α]
[IsModularLattice α] (h : Disjoint a b) (hsup : Disjoint (a ⊔ b) c) :
Disjoint a (b ⊔ c) := by
rw [disjoint_iff_inf_le, ← h.eq_bot, sup_comm]
apply le_inf inf_le_left
apply (inf_le_inf_right (c ⊔ b) le_sup_right).trans
rw [sup_comm, IsModularLattice.sup_inf_sup_assoc, hsup.eq_bot, bot_sup_eq]
theorem disjoint_sup_left_of_disjoint_sup_right [Lattice α] [OrderBot α]
[IsModularLattice α] (h : Disjoint b c) (hsup : Disjoint a (b ⊔ c)) :
Disjoint (a ⊔ b) c := by
rw [disjoint_comm, sup_comm]
apply Disjoint.disjoint_sup_right_of_disjoint_sup_left h.symm
rwa [sup_comm, disjoint_comm] at hsup
theorem isCompl_sup_right_of_isCompl_sup_left [Lattice α] [BoundedOrder α] [IsModularLattice α]
(h : Disjoint a b) (hcomp : IsCompl (a ⊔ b) c) :
IsCompl a (b ⊔ c) :=
⟨h.disjoint_sup_right_of_disjoint_sup_left hcomp.disjoint, codisjoint_assoc.mp hcomp.codisjoint⟩
theorem isCompl_sup_left_of_isCompl_sup_right [Lattice α] [BoundedOrder α] [IsModularLattice α]
(h : Disjoint b c) (hcomp : IsCompl a (b ⊔ c)) :
IsCompl (a ⊔ b) c :=
⟨h.disjoint_sup_left_of_disjoint_sup_right hcomp.disjoint, codisjoint_assoc.mpr hcomp.codisjoint⟩
end Disjoint
lemma Set.Iic.isCompl_inf_inf_of_isCompl_of_le [Lattice α] [BoundedOrder α] [IsModularLattice α]
{a b c : α} (h₁ : IsCompl b c) (h₂ : b ≤ a) :
IsCompl (⟨a ⊓ b, inf_le_left⟩ : Iic a) (⟨a ⊓ c, inf_le_left⟩ : Iic a) := by
constructor
· simp [disjoint_iff, Subtype.ext_iff, inf_comm a c, inf_assoc a, ← inf_assoc b, h₁.inf_eq_bot]
· simp only [Iic.codisjoint_iff, inf_comm a, IsModularLattice.inf_sup_inf_assoc]
simp [inf_of_le_left h₂, h₁.sup_eq_top]
namespace IsModularLattice
variable [Lattice α] [IsModularLattice α] {a : α}
instance isModularLattice_Iic : IsModularLattice (Set.Iic a) :=
⟨@fun x y z xz => (sup_inf_le_assoc_of_le (y : α) xz : (↑x ⊔ ↑y) ⊓ ↑z ≤ ↑x ⊔ ↑y ⊓ ↑z)⟩
instance isModularLattice_Ici : IsModularLattice (Set.Ici a) :=
⟨@fun x y z xz => (sup_inf_le_assoc_of_le (y : α) xz : (↑x ⊔ ↑y) ⊓ ↑z ≤ ↑x ⊔ ↑y ⊓ ↑z)⟩
section ComplementedLattice
variable [BoundedOrder α] [ComplementedLattice α]
instance complementedLattice_Iic : ComplementedLattice (Set.Iic a) :=
⟨fun ⟨x, hx⟩ =>
let ⟨y, hy⟩ := exists_isCompl x
⟨⟨y ⊓ a, Set.mem_Iic.2 inf_le_right⟩, by
constructor
· rw [disjoint_iff_inf_le]
change x ⊓ (y ⊓ a) ≤ ⊥
-- improve lattice subtype API
rw [← inf_assoc]
exact le_trans inf_le_left hy.1.le_bot
· rw [codisjoint_iff_le_sup]
change a ≤ x ⊔ y ⊓ a
-- improve lattice subtype API
rw [← sup_inf_assoc_of_le _ (Set.mem_Iic.1 hx), hy.2.eq_top, top_inf_eq]⟩⟩
instance complementedLattice_Ici : ComplementedLattice (Set.Ici a) :=
⟨fun ⟨x, hx⟩ =>
let ⟨y, hy⟩ := exists_isCompl x
⟨⟨y ⊔ a, Set.mem_Ici.2 le_sup_right⟩, by
constructor
· rw [disjoint_iff_inf_le]
change x ⊓ (y ⊔ a) ≤ a
-- improve lattice subtype API
rw [← inf_sup_assoc_of_le _ (Set.mem_Ici.1 hx), hy.1.eq_bot, bot_sup_eq]
· rw [codisjoint_iff_le_sup]
change ⊤ ≤ x ⊔ (y ⊔ a)
-- improve lattice subtype API
rw [← sup_assoc]
exact le_trans hy.2.top_le le_sup_left⟩⟩
end ComplementedLattice
end IsModularLattice
|
Order\Nat.lean | /-
Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Order.BoundedOrder
/-!
# The natural numbers form a linear order
This file contains the linear order instance on the natural numbers.
See note [foundational algebra order theory].
## TODO
Move the `LinearOrder ℕ` instance here (#13092).
-/
namespace Nat
instance instOrderBot : OrderBot ℕ where
bot := 0
bot_le := zero_le
/-! ### Miscellaneous lemmas -/
-- We want to use this lemma earlier than the lemma simp can prove it with
@[simp, nolint simpNF] protected lemma bot_eq_zero : ⊥ = 0 := rfl
end Nat
|
Order\Notation.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov, Yaël Dillies
-/
import Mathlib.Tactic.Basic
import Mathlib.Tactic.Simps.NotationClass
/-!
# Notation classes for lattice operations
In this file we introduce typeclasses and definitions for lattice operations.
## Main definitions
* `Sup`: type class for the `⊔` notation
* `Inf`: type class for the `⊓` notation
* `HasCompl`: type class for the `ᶜ` notation
* `Top`: type class for the `⊤` notation
* `Bot`: type class for the `⊥` notation
## Notations
* `x ⊔ y`: lattice join operation;
* `x ⊓ y`: lattice meet operation;
* `xᶜ`: complement in a lattice;
-/
/-- Set / lattice complement -/
@[notation_class]
class HasCompl (α : Type*) where
/-- Set / lattice complement -/
compl : α → α
export HasCompl (compl)
@[inherit_doc]
postfix:1024 "ᶜ" => compl
/-! ### `Sup` and `Inf` -/
/-- Typeclass for the `⊔` (`\lub`) notation -/
@[notation_class, ext]
class Sup (α : Type*) where
/-- Least upper bound (`\lub` notation) -/
sup : α → α → α
/-- Typeclass for the `⊓` (`\glb`) notation -/
@[notation_class, ext]
class Inf (α : Type*) where
/-- Greatest lower bound (`\glb` notation) -/
inf : α → α → α
@[inherit_doc]
infixl:68 " ⊔ " => Sup.sup
@[inherit_doc]
infixl:69 " ⊓ " => Inf.inf
/-- Syntax typeclass for Heyting implication `⇨`. -/
@[notation_class]
class HImp (α : Type*) where
/-- Heyting implication `⇨` -/
himp : α → α → α
/-- Syntax typeclass for Heyting negation `¬`.
The difference between `HasCompl` and `HNot` is that the former belongs to Heyting algebras,
while the latter belongs to co-Heyting algebras. They are both pseudo-complements, but `compl`
underestimates while `HNot` overestimates. In boolean algebras, they are equal.
See `hnot_eq_compl`.
-/
@[notation_class]
class HNot (α : Type*) where
/-- Heyting negation `¬` -/
hnot : α → α
export HImp (himp)
export SDiff (sdiff)
export HNot (hnot)
/-- Heyting implication -/
infixr:60 " ⇨ " => himp
/-- Heyting negation -/
prefix:72 "¬" => hnot
/-- Typeclass for the `⊤` (`\top`) notation -/
@[notation_class, ext]
class Top (α : Type*) where
/-- The top (`⊤`, `\top`) element -/
top : α
/-- Typeclass for the `⊥` (`\bot`) notation -/
@[notation_class, ext]
class Bot (α : Type*) where
/-- The bot (`⊥`, `\bot`) element -/
bot : α
/-- The top (`⊤`, `\top`) element -/
notation "⊤" => Top.top
/-- The bot (`⊥`, `\bot`) element -/
notation "⊥" => Bot.bot
instance (priority := 100) top_nonempty (α : Type*) [Top α] : Nonempty α :=
⟨⊤⟩
instance (priority := 100) bot_nonempty (α : Type*) [Bot α] : Nonempty α :=
⟨⊥⟩
attribute [match_pattern] Bot.bot Top.top
|
Order\OmegaCompletePartialOrder.lean | /-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import Mathlib.Control.Monad.Basic
import Mathlib.Order.Chain
import Mathlib.Order.Hom.Order
import Mathlib.Order.Part
/-!
# Omega Complete Partial Orders
An omega-complete partial order is a partial order with a supremum
operation on increasing sequences indexed by natural numbers (which we
call `ωSup`). In this sense, it is strictly weaker than join complete
semi-lattices as only ω-sized totally ordered sets have a supremum.
The concept of an omega-complete partial order (ωCPO) is useful for the
formalization of the semantics of programming languages. Its notion of
supremum helps define the meaning of recursive procedures.
## Main definitions
* class `OmegaCompletePartialOrder`
* `ite`, `map`, `bind`, `seq` as continuous morphisms
## Instances of `OmegaCompletePartialOrder`
* `Part`
* every `CompleteLattice`
* pi-types
* product types
* `OrderHom`
* `ContinuousHom` (with notation →𝒄)
* an instance of `OmegaCompletePartialOrder (α →𝒄 β)`
* `ContinuousHom.ofFun`
* `ContinuousHom.ofMono`
* continuous functions:
* `id`
* `ite`
* `const`
* `Part.bind`
* `Part.map`
* `Part.seq`
## References
* [Chain-complete posets and directed sets with applications][markowsky1976]
* [Recursive definitions of partial functions and their computations][cadiou1972]
* [Semantics of Programming Languages: Structures and Techniques][gunter1992]
-/
assert_not_exists OrderedCommMonoid
universe u v
namespace OmegaCompletePartialOrder
/-- A chain is a monotone sequence.
See the definition on page 114 of [gunter1992]. -/
def Chain (α : Type u) [Preorder α] :=
ℕ →o α
namespace Chain
variable {α : Type u} {β : Type v} {γ : Type*}
variable [Preorder α] [Preorder β] [Preorder γ]
instance : FunLike (Chain α) ℕ α := inferInstanceAs <| FunLike (ℕ →o α) ℕ α
instance : OrderHomClass (Chain α) ℕ α := inferInstanceAs <| OrderHomClass (ℕ →o α) ℕ α
instance : CoeFun (Chain α) fun _ => ℕ → α := ⟨DFunLike.coe⟩
instance [Inhabited α] : Inhabited (Chain α) :=
⟨⟨default, fun _ _ _ => le_rfl⟩⟩
instance : Membership α (Chain α) :=
⟨fun a (c : ℕ →o α) => ∃ i, a = c i⟩
variable (c c' : Chain α)
variable (f : α →o β)
variable (g : β →o γ)
instance : LE (Chain α) where le x y := ∀ i, ∃ j, x i ≤ y j
lemma isChain_range : IsChain (· ≤ ·) (Set.range c) := Monotone.isChain_range (OrderHomClass.mono c)
lemma directed : Directed (· ≤ ·) c := directedOn_range.2 c.isChain_range.directedOn
/-- `map` function for `Chain` -/
-- Porting note: `simps` doesn't work with type synonyms
-- @[simps! (config := .asFn)]
def map : Chain β :=
f.comp c
@[simp] theorem map_coe : ⇑(map c f) = f ∘ c := rfl
variable {f}
theorem mem_map (x : α) : x ∈ c → f x ∈ Chain.map c f :=
fun ⟨i, h⟩ => ⟨i, h.symm ▸ rfl⟩
theorem exists_of_mem_map {b : β} : b ∈ c.map f → ∃ a, a ∈ c ∧ f a = b :=
fun ⟨i, h⟩ => ⟨c i, ⟨i, rfl⟩, h.symm⟩
@[simp]
theorem mem_map_iff {b : β} : b ∈ c.map f ↔ ∃ a, a ∈ c ∧ f a = b :=
⟨exists_of_mem_map _, fun h => by
rcases h with ⟨w, h, h'⟩
subst b
apply mem_map c _ h⟩
@[simp]
theorem map_id : c.map OrderHom.id = c :=
OrderHom.comp_id _
theorem map_comp : (c.map f).map g = c.map (g.comp f) :=
rfl
@[mono]
theorem map_le_map {g : α →o β} (h : f ≤ g) : c.map f ≤ c.map g :=
fun i => by simp only [map_coe, Function.comp_apply]; exists i; apply h
/-- `OmegaCompletePartialOrder.Chain.zip` pairs up the elements of two chains
that have the same index. -/
-- Porting note: `simps` doesn't work with type synonyms
-- @[simps!]
def zip (c₀ : Chain α) (c₁ : Chain β) : Chain (α × β) :=
OrderHom.prod c₀ c₁
@[simp] theorem zip_coe (c₀ : Chain α) (c₁ : Chain β) (n : ℕ) : c₀.zip c₁ n = (c₀ n, c₁ n) := rfl
end Chain
end OmegaCompletePartialOrder
open OmegaCompletePartialOrder
-- Porting note: removed "set_option extends_priority 50"
/-- An omega-complete partial order is a partial order with a supremum
operation on increasing sequences indexed by natural numbers (which we
call `ωSup`). In this sense, it is strictly weaker than join complete
semi-lattices as only ω-sized totally ordered sets have a supremum.
See the definition on page 114 of [gunter1992]. -/
class OmegaCompletePartialOrder (α : Type*) extends PartialOrder α where
/-- The supremum of an increasing sequence -/
ωSup : Chain α → α
/-- `ωSup` is an upper bound of the increasing sequence -/
le_ωSup : ∀ c : Chain α, ∀ i, c i ≤ ωSup c
/-- `ωSup` is a lower bound of the set of upper bounds of the increasing sequence -/
ωSup_le : ∀ (c : Chain α) (x), (∀ i, c i ≤ x) → ωSup c ≤ x
namespace OmegaCompletePartialOrder
variable {α : Type u} {β : Type v} {γ : Type*}
variable [OmegaCompletePartialOrder α]
/-- Transfer an `OmegaCompletePartialOrder` on `β` to an `OmegaCompletePartialOrder` on `α`
using a strictly monotone function `f : β →o α`, a definition of ωSup and a proof that `f` is
continuous with regard to the provided `ωSup` and the ωCPO on `α`. -/
protected abbrev lift [PartialOrder β] (f : β →o α) (ωSup₀ : Chain β → β)
(h : ∀ x y, f x ≤ f y → x ≤ y) (h' : ∀ c, f (ωSup₀ c) = ωSup (c.map f)) :
OmegaCompletePartialOrder β where
ωSup := ωSup₀
ωSup_le c x hx := h _ _ (by rw [h']; apply ωSup_le; intro i; apply f.monotone (hx i))
le_ωSup c i := h _ _ (by rw [h']; apply le_ωSup (c.map f))
theorem le_ωSup_of_le {c : Chain α} {x : α} (i : ℕ) (h : x ≤ c i) : x ≤ ωSup c :=
le_trans h (le_ωSup c _)
theorem ωSup_total {c : Chain α} {x : α} (h : ∀ i, c i ≤ x ∨ x ≤ c i) : ωSup c ≤ x ∨ x ≤ ωSup c :=
by_cases
(fun (this : ∀ i, c i ≤ x) => Or.inl (ωSup_le _ _ this))
(fun (this : ¬∀ i, c i ≤ x) =>
have : ∃ i, ¬c i ≤ x := by simp only [not_forall] at this ⊢; assumption
let ⟨i, hx⟩ := this
have : x ≤ c i := (h i).resolve_left hx
Or.inr <| le_ωSup_of_le _ this)
@[mono]
theorem ωSup_le_ωSup_of_le {c₀ c₁ : Chain α} (h : c₀ ≤ c₁) : ωSup c₀ ≤ ωSup c₁ :=
(ωSup_le _ _) fun i => by
obtain ⟨_, h⟩ := h i
exact le_trans h (le_ωSup _ _)
theorem ωSup_le_iff (c : Chain α) (x : α) : ωSup c ≤ x ↔ ∀ i, c i ≤ x := by
constructor <;> intros
· trans ωSup c
· exact le_ωSup _ _
· assumption
exact ωSup_le _ _ ‹_›
lemma isLUB_range_ωSup (c : Chain α) : IsLUB (Set.range c) (ωSup c) := by
constructor
· simp only [upperBounds, Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff,
Set.mem_setOf_eq]
exact fun a ↦ le_ωSup c a
· simp only [lowerBounds, upperBounds, Set.mem_range, forall_exists_index,
forall_apply_eq_imp_iff, Set.mem_setOf_eq]
exact fun ⦃a⦄ a_1 ↦ ωSup_le c a a_1
lemma ωSup_eq_of_isLUB {c : Chain α} {a : α} (h : IsLUB (Set.range c) a) : a = ωSup c := by
rw [le_antisymm_iff]
simp only [IsLUB, IsLeast, upperBounds, lowerBounds, Set.mem_range, forall_exists_index,
forall_apply_eq_imp_iff, Set.mem_setOf_eq] at h
constructor
· apply h.2
exact fun a ↦ le_ωSup c a
· rw [ωSup_le_iff]
apply h.1
/-- A subset `p : α → Prop` of the type closed under `ωSup` induces an
`OmegaCompletePartialOrder` on the subtype `{a : α // p a}`. -/
def subtype {α : Type*} [OmegaCompletePartialOrder α] (p : α → Prop)
(hp : ∀ c : Chain α, (∀ i ∈ c, p i) → p (ωSup c)) : OmegaCompletePartialOrder (Subtype p) :=
OmegaCompletePartialOrder.lift (OrderHom.Subtype.val p)
(fun c => ⟨ωSup _, hp (c.map (OrderHom.Subtype.val p)) fun _ ⟨n, q⟩ => q.symm ▸ (c n).2⟩)
(fun _ _ h => h) (fun _ => rfl)
section Continuity
open Chain
variable [OmegaCompletePartialOrder β]
variable [OmegaCompletePartialOrder γ]
/-- A monotone function `f : α →o β` is continuous if it distributes over ωSup.
In order to distinguish it from the (more commonly used) continuity from topology
(see `Mathlib/Topology/Basic.lean`), the present definition is often referred to as
"Scott-continuity" (referring to Dana Scott). It corresponds to continuity
in Scott topological spaces (not defined here). -/
def Continuous (f : α →o β) : Prop :=
∀ c : Chain α, f (ωSup c) = ωSup (c.map f)
/-- `Continuous' f` asserts that `f` is both monotone and continuous. -/
def Continuous' (f : α → β) : Prop :=
∃ hf : Monotone f, Continuous ⟨f, hf⟩
lemma isLUB_of_scottContinuous {c : Chain α} {f : α → β} (hf : ScottContinuous f) :
IsLUB (Set.range (Chain.map c ⟨f, (ScottContinuous.monotone hf)⟩)) (f (ωSup c)) := by
simp only [map_coe, OrderHom.coe_mk]
rw [(Set.range_comp f ↑c)]
exact hf (Set.range_nonempty ↑c) (IsChain.directedOn (isChain_range c)) (isLUB_range_ωSup c)
lemma ScottContinuous.continuous' {f : α → β} (hf : ScottContinuous f) : Continuous' f := by
constructor
· intro c
rw [← (ωSup_eq_of_isLUB (isLUB_of_scottContinuous hf))]
simp only [OrderHom.coe_mk]
theorem Continuous'.to_monotone {f : α → β} (hf : Continuous' f) : Monotone f :=
hf.fst
theorem Continuous.of_bundled (f : α → β) (hf : Monotone f) (hf' : Continuous ⟨f, hf⟩) :
Continuous' f :=
⟨hf, hf'⟩
theorem Continuous.of_bundled' (f : α →o β) (hf' : Continuous f) : Continuous' f :=
⟨f.mono, hf'⟩
theorem Continuous'.to_bundled (f : α → β) (hf : Continuous' f) : Continuous ⟨f, hf.to_monotone⟩ :=
hf.snd
@[simp, norm_cast]
theorem continuous'_coe : ∀ {f : α →o β}, Continuous' f ↔ Continuous f
| ⟨_, hf⟩ => ⟨fun ⟨_, hc⟩ => hc, fun hc => ⟨hf, hc⟩⟩
variable (f : α →o β) (g : β →o γ)
theorem continuous_id : Continuous (@OrderHom.id α _) := by intro c; rw [c.map_id]; rfl
theorem continuous_comp (hfc : Continuous f) (hgc : Continuous g) : Continuous (g.comp f) := by
dsimp [Continuous] at *; intro
rw [hfc, hgc, Chain.map_comp]
theorem id_continuous' : Continuous' (@id α) :=
continuous_id.of_bundled' _
theorem continuous_const (x : β) : Continuous (OrderHom.const α x) := fun c =>
eq_of_forall_ge_iff fun z => by rw [ωSup_le_iff, Chain.map_coe, OrderHom.const_coe_coe]; simp
theorem const_continuous' (x : β) : Continuous' (Function.const α x) :=
Continuous.of_bundled' (OrderHom.const α x) (continuous_const x)
end Continuity
end OmegaCompletePartialOrder
namespace Part
variable {α : Type u} {β : Type v} {γ : Type*}
open OmegaCompletePartialOrder
theorem eq_of_chain {c : Chain (Part α)} {a b : α} (ha : some a ∈ c) (hb : some b ∈ c) : a = b := by
cases' ha with i ha; replace ha := ha.symm
cases' hb with j hb; replace hb := hb.symm
rw [eq_some_iff] at ha hb
rcases le_total i j with hij | hji
· have := c.monotone hij _ ha; apply mem_unique this hb
· have := c.monotone hji _ hb; apply Eq.symm; apply mem_unique this ha
-- Porting note: Old proof
-- wlog h : i ≤ j := le_total i j using a b i j, b a j i
-- rw [eq_some_iff] at ha hb
-- have := c.monotone h _ ha; apply mem_unique this hb
open Classical in
/-- The (noncomputable) `ωSup` definition for the `ω`-CPO structure on `Part α`. -/
protected noncomputable def ωSup (c : Chain (Part α)) : Part α :=
if h : ∃ a, some a ∈ c then some (Classical.choose h) else none
theorem ωSup_eq_some {c : Chain (Part α)} {a : α} (h : some a ∈ c) : Part.ωSup c = some a :=
have : ∃ a, some a ∈ c := ⟨a, h⟩
have a' : some (Classical.choose this) ∈ c := Classical.choose_spec this
calc
Part.ωSup c = some (Classical.choose this) := dif_pos this
_ = some a := congr_arg _ (eq_of_chain a' h)
theorem ωSup_eq_none {c : Chain (Part α)} (h : ¬∃ a, some a ∈ c) : Part.ωSup c = none :=
dif_neg h
theorem mem_chain_of_mem_ωSup {c : Chain (Part α)} {a : α} (h : a ∈ Part.ωSup c) : some a ∈ c := by
simp only [Part.ωSup] at h; split_ifs at h with h_1
· have h' := Classical.choose_spec h_1
rw [← eq_some_iff] at h
rw [← h]
exact h'
· rcases h with ⟨⟨⟩⟩
noncomputable instance omegaCompletePartialOrder :
OmegaCompletePartialOrder (Part α) where
ωSup := Part.ωSup
le_ωSup c i := by
intro x hx
rw [← eq_some_iff] at hx ⊢
rw [ωSup_eq_some]
rw [← hx]
exact ⟨i, rfl⟩
ωSup_le := by
rintro c x hx a ha
replace ha := mem_chain_of_mem_ωSup ha
cases' ha with i ha
apply hx i
rw [← ha]
apply mem_some
section Inst
theorem mem_ωSup (x : α) (c : Chain (Part α)) : x ∈ ωSup c ↔ some x ∈ c := by
simp only [ωSup, Part.ωSup]
constructor
· split_ifs with h
swap
· rintro ⟨⟨⟩⟩
intro h'
have hh := Classical.choose_spec h
simp only [mem_some_iff] at h'
subst x
exact hh
· intro h
have h' : ∃ a : α, some a ∈ c := ⟨_, h⟩
rw [dif_pos h']
have hh := Classical.choose_spec h'
rw [eq_of_chain hh h]
simp
end Inst
end Part
namespace Pi
variable {α : Type*} {β : α → Type*} {γ : Type*}
open OmegaCompletePartialOrder OmegaCompletePartialOrder.Chain
instance [∀ a, OmegaCompletePartialOrder (β a)] :
OmegaCompletePartialOrder (∀ a, β a) where
ωSup c a := ωSup (c.map (Pi.evalOrderHom a))
ωSup_le c f hf a :=
ωSup_le _ _ <| by
rintro i
apply hf
le_ωSup c i x := le_ωSup_of_le _ <| le_rfl
namespace OmegaCompletePartialOrder
variable [∀ x, OmegaCompletePartialOrder <| β x]
variable [OmegaCompletePartialOrder γ]
theorem flip₁_continuous' (f : ∀ x : α, γ → β x) (a : α) (hf : Continuous' fun x y => f y x) :
Continuous' (f a) :=
Continuous.of_bundled _ (fun _ _ h => hf.to_monotone h a) fun c => congr_fun (hf.to_bundled _ c) a
theorem flip₂_continuous' (f : γ → ∀ x, β x) (hf : ∀ x, Continuous' fun g => f g x) :
Continuous' f :=
Continuous.of_bundled _ (fun x y h a => (hf a).to_monotone h)
(by intro c; ext a; apply (hf a).to_bundled _ c)
end OmegaCompletePartialOrder
end Pi
namespace Prod
open OmegaCompletePartialOrder
variable {α : Type*} {β : Type*} {γ : Type*}
variable [OmegaCompletePartialOrder α]
variable [OmegaCompletePartialOrder β]
variable [OmegaCompletePartialOrder γ]
/-- The supremum of a chain in the product `ω`-CPO. -/
@[simps]
protected def ωSup (c : Chain (α × β)) : α × β :=
(ωSup (c.map OrderHom.fst), ωSup (c.map OrderHom.snd))
@[simps! ωSup_fst ωSup_snd]
instance : OmegaCompletePartialOrder (α × β) where
ωSup := Prod.ωSup
ωSup_le := fun _ _ h => ⟨ωSup_le _ _ fun i => (h i).1, ωSup_le _ _ fun i => (h i).2⟩
le_ωSup c i := ⟨le_ωSup (c.map OrderHom.fst) i, le_ωSup (c.map OrderHom.snd) i⟩
theorem ωSup_zip (c₀ : Chain α) (c₁ : Chain β) : ωSup (c₀.zip c₁) = (ωSup c₀, ωSup c₁) := by
apply eq_of_forall_ge_iff; rintro ⟨z₁, z₂⟩
simp [ωSup_le_iff, forall_and]
end Prod
open OmegaCompletePartialOrder
namespace CompleteLattice
variable (α : Type u)
-- see Note [lower instance priority]
/-- Any complete lattice has an `ω`-CPO structure where the countable supremum is a special case
of arbitrary suprema. -/
instance (priority := 100) [CompleteLattice α] : OmegaCompletePartialOrder α where
ωSup c := ⨆ i, c i
ωSup_le := fun ⟨c, _⟩ s hs => by
simp only [iSup_le_iff, OrderHom.coe_mk] at hs ⊢; intro i; apply hs i
le_ωSup := fun ⟨c, _⟩ i => by simp only [OrderHom.coe_mk]; apply le_iSup_of_le i; rfl
variable {α} {β : Type v} [OmegaCompletePartialOrder α] [CompleteLattice β]
theorem sSup_continuous (s : Set <| α →o β) (hs : ∀ f ∈ s, Continuous f) : Continuous (sSup s) := by
intro c
apply eq_of_forall_ge_iff
intro z
suffices (∀ f ∈ s, ∀ (n), (f : _) (c n) ≤ z) ↔ ∀ (n), ∀ f ∈ s, (f : _) (c n) ≤ z by
simpa (config := { contextual := true }) [ωSup_le_iff, hs _ _ _] using this
exact ⟨fun H n f hf => H f hf n, fun H f hf n => H n f hf⟩
theorem iSup_continuous {ι : Sort*} {f : ι → α →o β} (h : ∀ i, Continuous (f i)) :
Continuous (⨆ i, f i) :=
sSup_continuous _ <| Set.forall_mem_range.2 h
theorem sSup_continuous' (s : Set (α → β)) (hc : ∀ f ∈ s, Continuous' f) :
Continuous' (sSup s) := by
lift s to Set (α →o β) using fun f hf => (hc f hf).to_monotone
simp only [Set.forall_mem_image, continuous'_coe] at hc
rw [sSup_image]
norm_cast
exact iSup_continuous fun f ↦ iSup_continuous fun hf ↦ hc hf
theorem sup_continuous {f g : α →o β} (hf : Continuous f) (hg : Continuous g) :
Continuous (f ⊔ g) := by
rw [← sSup_pair]; apply sSup_continuous
rintro f (rfl | rfl | _) <;> assumption
theorem top_continuous : Continuous (⊤ : α →o β) := by
intro c; apply eq_of_forall_ge_iff; intro z
simp only [OrderHom.instTopOrderHom_top, OrderHom.const_coe_coe, Function.const, top_le_iff,
ωSup_le_iff, Chain.map_coe, Function.comp, forall_const]
theorem bot_continuous : Continuous (⊥ : α →o β) := by
rw [← sSup_empty]
exact sSup_continuous _ fun f hf => hf.elim
end CompleteLattice
namespace CompleteLattice
variable {α β : Type*} [OmegaCompletePartialOrder α] [CompleteLinearOrder β]
theorem inf_continuous (f g : α →o β) (hf : Continuous f) (hg : Continuous g) :
Continuous (f ⊓ g) := by
refine fun c => eq_of_forall_ge_iff fun z => ?_
simp only [inf_le_iff, hf c, hg c, ωSup_le_iff, ← forall_or_left, ← forall_or_right,
Chain.map_coe, OrderHom.coe_inf, Pi.inf_apply, Function.comp]
exact ⟨fun h _ ↦ h _ _, fun h i j ↦
(h (max j i)).imp (le_trans <| f.mono <| c.mono <| le_max_left _ _)
(le_trans <| g.mono <| c.mono <| le_max_right _ _)⟩
theorem inf_continuous' {f g : α → β} (hf : Continuous' f) (hg : Continuous' g) :
Continuous' (f ⊓ g) :=
⟨_, inf_continuous _ _ hf.snd hg.snd⟩
end CompleteLattice
namespace OmegaCompletePartialOrder
variable {α : Type u} {α' : Type*} {β : Type v} {β' : Type*} {γ : Type*} {φ : Type*}
variable [OmegaCompletePartialOrder α] [OmegaCompletePartialOrder β]
variable [OmegaCompletePartialOrder γ] [OmegaCompletePartialOrder φ]
variable [OmegaCompletePartialOrder α'] [OmegaCompletePartialOrder β']
namespace OrderHom
/-- The `ωSup` operator for monotone functions. -/
@[simps]
protected def ωSup (c : Chain (α →o β)) : α →o β where
toFun a := ωSup (c.map (OrderHom.apply a))
monotone' _ _ h := ωSup_le_ωSup_of_le ((Chain.map_le_map _) fun a => a.monotone h)
@[simps! ωSup_coe]
instance omegaCompletePartialOrder : OmegaCompletePartialOrder (α →o β) :=
OmegaCompletePartialOrder.lift OrderHom.coeFnHom OrderHom.ωSup (fun _ _ h => h) fun _ => rfl
end OrderHom
section
variable (α β)
/-- A monotone function on `ω`-continuous partial orders is said to be continuous
if for every chain `c : chain α`, `f (⊔ i, c i) = ⊔ i, f (c i)`.
This is just the bundled version of `OrderHom.continuous`. -/
structure ContinuousHom extends OrderHom α β where
/-- The underlying function of a `ContinuousHom` is continuous, i.e. it preserves `ωSup` -/
cont : Continuous toOrderHom
attribute [nolint docBlame] ContinuousHom.toOrderHom
@[inherit_doc] infixr:25 " →𝒄 " => ContinuousHom -- Input: \r\MIc
instance : FunLike (α →𝒄 β) α β where
coe f := f.toFun
coe_injective' := by rintro ⟨⟩ ⟨⟩ h; congr; exact DFunLike.ext' h
instance : OrderHomClass (α →𝒄 β) α β where
map_rel f _ _ h := f.mono h
-- Porting note: removed to avoid conflict with the generic instance
-- instance : Coe (α →𝒄 β) (α →o β) where coe := ContinuousHom.toOrderHom
instance : PartialOrder (α →𝒄 β) :=
(PartialOrder.lift fun f => f.toOrderHom.toFun) <| by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ h; congr
end
namespace ContinuousHom
-- Not a `simp` lemma because in many cases projection is simpler than a generic coercion
theorem toOrderHom_eq_coe (f : α →𝒄 β) : f.1 = f := rfl
@[simp] theorem coe_mk (f : α →o β) (hf : Continuous f) : ⇑(mk f hf) = f := rfl
@[simp] theorem coe_toOrderHom (f : α →𝒄 β) : ⇑f.1 = f := rfl
/-- See Note [custom simps projection]. We specify this explicitly because we don't have a DFunLike
instance.
-/
def Simps.apply (h : α →𝒄 β) : α → β :=
h
initialize_simps_projections ContinuousHom (toFun → apply)
protected theorem congr_fun {f g : α →𝒄 β} (h : f = g) (x : α) : f x = g x :=
DFunLike.congr_fun h x
protected theorem congr_arg (f : α →𝒄 β) {x y : α} (h : x = y) : f x = f y :=
congr_arg f h
protected theorem monotone (f : α →𝒄 β) : Monotone f :=
f.monotone'
@[mono]
theorem apply_mono {f g : α →𝒄 β} {x y : α} (h₁ : f ≤ g) (h₂ : x ≤ y) : f x ≤ g y :=
OrderHom.apply_mono (show (f : α →o β) ≤ g from h₁) h₂
theorem ite_continuous' {p : Prop} [hp : Decidable p] (f g : α → β) (hf : Continuous' f)
(hg : Continuous' g) : Continuous' fun x => if p then f x else g x := by
split_ifs <;> simp [*]
theorem ωSup_bind {β γ : Type v} (c : Chain α) (f : α →o Part β) (g : α →o β → Part γ) :
ωSup (c.map (f.partBind g)) = ωSup (c.map f) >>= ωSup (c.map g) := by
apply eq_of_forall_ge_iff; intro x
simp only [ωSup_le_iff, Part.bind_le, Chain.mem_map_iff, and_imp, OrderHom.partBind_coe,
exists_imp]
constructor <;> intro h'''
· intro b hb
apply ωSup_le _ _ _
rintro i y hy
simp only [Part.mem_ωSup] at hb
rcases hb with ⟨j, hb⟩
replace hb := hb.symm
simp only [Part.eq_some_iff, Chain.map_coe, Function.comp_apply, OrderHom.apply_coe] at hy hb
replace hb : b ∈ f (c (max i j)) := f.mono (c.mono (le_max_right i j)) _ hb
replace hy : y ∈ g (c (max i j)) b := g.mono (c.mono (le_max_left i j)) _ _ hy
apply h''' (max i j)
simp only [exists_prop, Part.bind_eq_bind, Part.mem_bind_iff, Chain.map_coe,
Function.comp_apply, OrderHom.partBind_coe]
exact ⟨_, hb, hy⟩
· intro i
intro y hy
simp only [exists_prop, Part.bind_eq_bind, Part.mem_bind_iff, Chain.map_coe,
Function.comp_apply, OrderHom.partBind_coe] at hy
rcases hy with ⟨b, hb₀, hb₁⟩
apply h''' b _
· apply le_ωSup (c.map g) _ _ _ hb₁
· apply le_ωSup (c.map f) i _ hb₀
theorem bind_continuous' {β γ : Type v} (f : α → Part β) (g : α → β → Part γ) :
Continuous' f → Continuous' g → Continuous' fun x => f x >>= g x
| ⟨hf, hf'⟩, ⟨hg, hg'⟩ =>
Continuous.of_bundled' (OrderHom.partBind ⟨f, hf⟩ ⟨g, hg⟩)
(by intro c; rw [ωSup_bind, ← hf', ← hg']; rfl)
theorem map_continuous' {β γ : Type v} (f : β → γ) (g : α → Part β) (hg : Continuous' g) :
Continuous' fun x => f <$> g x := by
simp only [map_eq_bind_pure_comp]; apply bind_continuous' _ _ hg; apply const_continuous'
theorem seq_continuous' {β γ : Type v} (f : α → Part (β → γ)) (g : α → Part β) (hf : Continuous' f)
(hg : Continuous' g) : Continuous' fun x => f x <*> g x := by
simp only [seq_eq_bind_map]
apply bind_continuous' _ _ hf
apply Pi.OmegaCompletePartialOrder.flip₂_continuous'
intro
apply map_continuous' _ _ hg
theorem continuous (F : α →𝒄 β) (C : Chain α) : F (ωSup C) = ωSup (C.map F) :=
ContinuousHom.cont _ _
/-- Construct a continuous function from a bare function, a continuous function, and a proof that
they are equal. -/
-- Porting note: removed `@[reducible]`
@[simps!]
def copy (f : α → β) (g : α →𝒄 β) (h : f = g) : α →𝒄 β where
toOrderHom := g.1.copy f h
cont := by rw [OrderHom.copy_eq]; exact g.cont
-- Porting note: `of_mono` now defeq `mk`
/-- The identity as a continuous function. -/
@[simps!]
def id : α →𝒄 α := ⟨OrderHom.id, continuous_id⟩
/-- The composition of continuous functions. -/
@[simps!]
def comp (f : β →𝒄 γ) (g : α →𝒄 β) : α →𝒄 γ := ⟨.comp f.1 g.1, continuous_comp _ _ g.cont f.cont⟩
@[ext]
protected theorem ext (f g : α →𝒄 β) (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h
protected theorem coe_inj (f g : α →𝒄 β) (h : (f : α → β) = g) : f = g :=
DFunLike.ext' h
@[simp]
theorem comp_id (f : β →𝒄 γ) : f.comp id = f := rfl
@[simp]
theorem id_comp (f : β →𝒄 γ) : id.comp f = f := rfl
@[simp]
theorem comp_assoc (f : γ →𝒄 φ) (g : β →𝒄 γ) (h : α →𝒄 β) : f.comp (g.comp h) = (f.comp g).comp h :=
rfl
@[simp]
theorem coe_apply (a : α) (f : α →𝒄 β) : (f : α →o β) a = f a :=
rfl
/-- `Function.const` is a continuous function. -/
@[simps!]
def const (x : β) : α →𝒄 β := ⟨.const _ x, continuous_const x⟩
instance [Inhabited β] : Inhabited (α →𝒄 β) :=
⟨const default⟩
/-- The map from continuous functions to monotone functions is itself a monotone function. -/
@[simps]
def toMono : (α →𝒄 β) →o α →o β where
toFun f := f
monotone' _ _ h := h
/-- When proving that a chain of applications is below a bound `z`, it suffices to consider the
functions and values being selected from the same index in the chains.
This lemma is more specific than necessary, i.e. `c₀` only needs to be a
chain of monotone functions, but it is only used with continuous functions. -/
@[simp]
theorem forall_forall_merge (c₀ : Chain (α →𝒄 β)) (c₁ : Chain α) (z : β) :
(∀ i j : ℕ, (c₀ i) (c₁ j) ≤ z) ↔ ∀ i : ℕ, (c₀ i) (c₁ i) ≤ z := by
constructor <;> introv h
· apply h
· apply le_trans _ (h (max i j))
trans c₀ i (c₁ (max i j))
· apply (c₀ i).monotone
apply c₁.monotone
apply le_max_right
· apply c₀.monotone
apply le_max_left
@[simp]
theorem forall_forall_merge' (c₀ : Chain (α →𝒄 β)) (c₁ : Chain α) (z : β) :
(∀ j i : ℕ, (c₀ i) (c₁ j) ≤ z) ↔ ∀ i : ℕ, (c₀ i) (c₁ i) ≤ z := by
rw [forall_swap, forall_forall_merge]
/-- The `ωSup` operator for continuous functions, which takes the pointwise countable supremum
of the functions in the `ω`-chain. -/
@[simps!]
protected def ωSup (c : Chain (α →𝒄 β)) : α →𝒄 β :=
.mk (ωSup <| c.map toMono) fun c' ↦ by
apply eq_of_forall_ge_iff; intro z
simp only [ωSup_le_iff, (c _).continuous, Chain.map_coe, OrderHom.apply_coe, toMono_coe,
OrderHom.omegaCompletePartialOrder_ωSup_coe, forall_forall_merge, OrderHomClass.coe_coe,
forall_forall_merge', (· ∘ ·), Function.eval]
@[simps ωSup]
instance : OmegaCompletePartialOrder (α →𝒄 β) :=
OmegaCompletePartialOrder.lift ContinuousHom.toMono ContinuousHom.ωSup
(fun _ _ h => h) (fun _ => rfl)
namespace Prod
/-- The application of continuous functions as a continuous function. -/
@[simps]
def apply : (α →𝒄 β) × α →𝒄 β where
toFun f := f.1 f.2
monotone' x y h := by
dsimp
trans y.fst x.snd <;> [apply h.1; apply y.1.monotone h.2]
cont := by
intro c
apply le_antisymm
· apply ωSup_le
intro i
dsimp
rw [(c _).fst.continuous]
apply ωSup_le
intro j
apply le_ωSup_of_le (max i j)
apply apply_mono
· exact monotone_fst (OrderHom.mono _ (le_max_left _ _))
· exact monotone_snd (OrderHom.mono _ (le_max_right _ _))
· apply ωSup_le
intro i
apply le_ωSup_of_le i
dsimp
apply OrderHom.mono _
apply le_ωSup_of_le i
rfl
end Prod
theorem ωSup_def (c : Chain (α →𝒄 β)) (x : α) : ωSup c x = ContinuousHom.ωSup c x :=
rfl
theorem ωSup_apply_ωSup (c₀ : Chain (α →𝒄 β)) (c₁ : Chain α) :
ωSup c₀ (ωSup c₁) = Prod.apply (ωSup (c₀.zip c₁)) := by simp [Prod.apply_apply, Prod.ωSup_zip]
/-- A family of continuous functions yields a continuous family of functions. -/
@[simps]
def flip {α : Type*} (f : α → β →𝒄 γ) : β →𝒄 α → γ where
toFun x y := f y x
monotone' x y h a := (f a).monotone h
cont := by intro _; ext x; change f _ _ = _; rw [(f _).continuous]; rfl
/-- `Part.bind` as a continuous function. -/
@[simps! apply] -- Porting note: removed `(config := { rhsMd := reducible })`
noncomputable def bind {β γ : Type v} (f : α →𝒄 Part β) (g : α →𝒄 β → Part γ) : α →𝒄 Part γ :=
.mk (OrderHom.partBind f g.toOrderHom) fun c => by
rw [ωSup_bind, ← f.continuous, g.toOrderHom_eq_coe, ← g.continuous]
rfl
/-- `Part.map` as a continuous function. -/
@[simps! apply] -- Porting note: removed `(config := { rhsMd := reducible })`
noncomputable def map {β γ : Type v} (f : β → γ) (g : α →𝒄 Part β) : α →𝒄 Part γ :=
.copy (fun x => f <$> g x) (bind g (const (pure ∘ f))) <| by
ext1
simp only [map_eq_bind_pure_comp, bind, coe_mk, OrderHom.partBind_coe, coe_apply,
coe_toOrderHom, const_apply, Part.bind_eq_bind]
/-- `Part.seq` as a continuous function. -/
@[simps! apply] -- Porting note: removed `(config := { rhsMd := reducible })`
noncomputable def seq {β γ : Type v} (f : α →𝒄 Part (β → γ)) (g : α →𝒄 Part β) : α →𝒄 Part γ :=
.copy (fun x => f x <*> g x) (bind f <| flip <| _root_.flip map g) <| by
ext
simp only [seq_eq_bind_map, Part.bind_eq_bind, Part.mem_bind_iff, flip_apply, _root_.flip,
map_apply, bind_apply, Part.map_eq_map]
end ContinuousHom
end OmegaCompletePartialOrder
|
Order\OrdContinuous.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov, Johannes Hölzl
-/
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.RelIso.Basic
/-!
# Order continuity
We say that a function is *left order continuous* if it sends all least upper bounds
to least upper bounds. The order dual notion is called *right order continuity*.
For monotone functions `ℝ → ℝ` these notions correspond to the usual left and right continuity.
We prove some basic lemmas (`map_sup`, `map_sSup` etc) and prove that a `RelIso` is both left
and right order continuous.
-/
universe u v w x
variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}
open Function OrderDual Set
/-!
### Definitions
-/
/-- A function `f` between preorders is left order continuous if it preserves all suprema. We
define it using `IsLUB` instead of `sSup` so that the proof works both for complete lattices and
conditionally complete lattices. -/
def LeftOrdContinuous [Preorder α] [Preorder β] (f : α → β) :=
∀ ⦃s : Set α⦄ ⦃x⦄, IsLUB s x → IsLUB (f '' s) (f x)
/-- A function `f` between preorders is right order continuous if it preserves all infima. We
define it using `IsGLB` instead of `sInf` so that the proof works both for complete lattices and
conditionally complete lattices. -/
def RightOrdContinuous [Preorder α] [Preorder β] (f : α → β) :=
∀ ⦃s : Set α⦄ ⦃x⦄, IsGLB s x → IsGLB (f '' s) (f x)
namespace LeftOrdContinuous
section Preorder
variable (α) [Preorder α] [Preorder β] [Preorder γ] {g : β → γ} {f : α → β}
protected theorem id : LeftOrdContinuous (id : α → α) := fun s x h => by
simpa only [image_id] using h
variable {α}
-- Porting note: not sure what is the correct name for this
protected theorem order_dual : LeftOrdContinuous f → RightOrdContinuous (toDual ∘ f ∘ ofDual) :=
id
theorem map_isGreatest (hf : LeftOrdContinuous f) {s : Set α} {x : α} (h : IsGreatest s x) :
IsGreatest (f '' s) (f x) :=
⟨mem_image_of_mem f h.1, (hf h.isLUB).1⟩
theorem mono (hf : LeftOrdContinuous f) : Monotone f := fun a₁ a₂ h =>
have : IsGreatest {a₁, a₂} a₂ := ⟨Or.inr rfl, by simp [*]⟩
(hf.map_isGreatest this).2 <| mem_image_of_mem _ (Or.inl rfl)
theorem comp (hg : LeftOrdContinuous g) (hf : LeftOrdContinuous f) : LeftOrdContinuous (g ∘ f) :=
fun s x h => by simpa only [image_image] using hg (hf h)
-- Porting note: how to do this in non-tactic mode?
protected theorem iterate {f : α → α} (hf : LeftOrdContinuous f) (n : ℕ) :
LeftOrdContinuous f^[n] := by
induction n with
| zero => exact LeftOrdContinuous.id α
| succ n ihn => exact ihn.comp hf
end Preorder
section SemilatticeSup
variable [SemilatticeSup α] [SemilatticeSup β] {f : α → β}
theorem map_sup (hf : LeftOrdContinuous f) (x y : α) : f (x ⊔ y) = f x ⊔ f y :=
(hf isLUB_pair).unique <| by simp only [image_pair, isLUB_pair]
theorem le_iff (hf : LeftOrdContinuous f) (h : Injective f) {x y} : f x ≤ f y ↔ x ≤ y := by
simp only [← sup_eq_right, ← hf.map_sup, h.eq_iff]
theorem lt_iff (hf : LeftOrdContinuous f) (h : Injective f) {x y} : f x < f y ↔ x < y := by
simp only [lt_iff_le_not_le, hf.le_iff h]
variable (f)
/-- Convert an injective left order continuous function to an order embedding. -/
def toOrderEmbedding (hf : LeftOrdContinuous f) (h : Injective f) : α ↪o β :=
⟨⟨f, h⟩, hf.le_iff h⟩
variable {f}
@[simp]
theorem coe_toOrderEmbedding (hf : LeftOrdContinuous f) (h : Injective f) :
⇑(hf.toOrderEmbedding f h) = f :=
rfl
end SemilatticeSup
section CompleteLattice
variable [CompleteLattice α] [CompleteLattice β] {f : α → β}
theorem map_sSup' (hf : LeftOrdContinuous f) (s : Set α) : f (sSup s) = sSup (f '' s) :=
(hf <| isLUB_sSup s).sSup_eq.symm
theorem map_sSup (hf : LeftOrdContinuous f) (s : Set α) : f (sSup s) = ⨆ x ∈ s, f x := by
rw [hf.map_sSup', sSup_image]
theorem map_iSup (hf : LeftOrdContinuous f) (g : ι → α) : f (⨆ i, g i) = ⨆ i, f (g i) := by
simp only [iSup, hf.map_sSup', ← range_comp]
rfl
end CompleteLattice
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β] [Nonempty ι] {f : α → β}
theorem map_csSup (hf : LeftOrdContinuous f) {s : Set α} (sne : s.Nonempty) (sbdd : BddAbove s) :
f (sSup s) = sSup (f '' s) :=
((hf <| isLUB_csSup sne sbdd).csSup_eq <| sne.image f).symm
theorem map_ciSup (hf : LeftOrdContinuous f) {g : ι → α} (hg : BddAbove (range g)) :
f (⨆ i, g i) = ⨆ i, f (g i) := by
simp only [iSup, hf.map_csSup (range_nonempty _) hg, ← range_comp]
rfl
end ConditionallyCompleteLattice
end LeftOrdContinuous
namespace RightOrdContinuous
section Preorder
variable (α) [Preorder α] [Preorder β] [Preorder γ] {g : β → γ} {f : α → β}
protected theorem id : RightOrdContinuous (id : α → α) := fun s x h => by
simpa only [image_id] using h
variable {α}
protected theorem orderDual : RightOrdContinuous f → LeftOrdContinuous (toDual ∘ f ∘ ofDual) :=
id
theorem map_isLeast (hf : RightOrdContinuous f) {s : Set α} {x : α} (h : IsLeast s x) :
IsLeast (f '' s) (f x) :=
hf.orderDual.map_isGreatest h
theorem mono (hf : RightOrdContinuous f) : Monotone f :=
hf.orderDual.mono.dual
theorem comp (hg : RightOrdContinuous g) (hf : RightOrdContinuous f) : RightOrdContinuous (g ∘ f) :=
hg.orderDual.comp hf.orderDual
protected theorem iterate {f : α → α} (hf : RightOrdContinuous f) (n : ℕ) :
RightOrdContinuous f^[n] :=
hf.orderDual.iterate n
end Preorder
section SemilatticeInf
variable [SemilatticeInf α] [SemilatticeInf β] {f : α → β}
theorem map_inf (hf : RightOrdContinuous f) (x y : α) : f (x ⊓ y) = f x ⊓ f y :=
hf.orderDual.map_sup x y
theorem le_iff (hf : RightOrdContinuous f) (h : Injective f) {x y} : f x ≤ f y ↔ x ≤ y :=
hf.orderDual.le_iff h
theorem lt_iff (hf : RightOrdContinuous f) (h : Injective f) {x y} : f x < f y ↔ x < y :=
hf.orderDual.lt_iff h
variable (f)
/-- Convert an injective left order continuous function to an `OrderEmbedding`. -/
def toOrderEmbedding (hf : RightOrdContinuous f) (h : Injective f) : α ↪o β :=
⟨⟨f, h⟩, hf.le_iff h⟩
variable {f}
@[simp]
theorem coe_toOrderEmbedding (hf : RightOrdContinuous f) (h : Injective f) :
⇑(hf.toOrderEmbedding f h) = f :=
rfl
end SemilatticeInf
section CompleteLattice
variable [CompleteLattice α] [CompleteLattice β] {f : α → β}
theorem map_sInf' (hf : RightOrdContinuous f) (s : Set α) : f (sInf s) = sInf (f '' s) :=
hf.orderDual.map_sSup' s
theorem map_sInf (hf : RightOrdContinuous f) (s : Set α) : f (sInf s) = ⨅ x ∈ s, f x :=
hf.orderDual.map_sSup s
theorem map_iInf (hf : RightOrdContinuous f) (g : ι → α) : f (⨅ i, g i) = ⨅ i, f (g i) :=
hf.orderDual.map_iSup g
end CompleteLattice
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β] [Nonempty ι] {f : α → β}
theorem map_csInf (hf : RightOrdContinuous f) {s : Set α} (sne : s.Nonempty) (sbdd : BddBelow s) :
f (sInf s) = sInf (f '' s) :=
hf.orderDual.map_csSup sne sbdd
theorem map_ciInf (hf : RightOrdContinuous f) {g : ι → α} (hg : BddBelow (range g)) :
f (⨅ i, g i) = ⨅ i, f (g i) :=
hf.orderDual.map_ciSup hg
end ConditionallyCompleteLattice
end RightOrdContinuous
namespace OrderIso
section Preorder
variable [Preorder α] [Preorder β] (e : α ≃o β) {s : Set α} {x : α}
protected theorem leftOrdContinuous : LeftOrdContinuous e := fun _ _ hx =>
⟨Monotone.mem_upperBounds_image (fun _ _ => e.map_rel_iff.2) hx.1, fun _ hy =>
e.rel_symm_apply.1 <|
(isLUB_le_iff hx).2 fun _ hx' => e.rel_symm_apply.2 <| hy <| mem_image_of_mem _ hx'⟩
protected theorem rightOrdContinuous : RightOrdContinuous e :=
OrderIso.leftOrdContinuous e.dual
end Preorder
end OrderIso
|
Order\OrderIsoNat.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Nat.Lattice
import Mathlib.Logic.Denumerable
import Mathlib.Logic.Function.Iterate
import Mathlib.Order.Hom.Basic
import Mathlib.Data.Set.Subsingleton
/-!
# Relation embeddings from the naturals
This file allows translation from monotone functions `ℕ → α` to order embeddings `ℕ ↪ α` and
defines the limit value of an eventually-constant sequence.
## Main declarations
* `natLT`/`natGT`: Make an order embedding `Nat ↪ α` from
an increasing/decreasing function `Nat → α`.
* `monotonicSequenceLimit`: The limit of an eventually-constant monotone sequence `Nat →o α`.
* `monotonicSequenceLimitIndex`: The index of the first occurrence of `monotonicSequenceLimit`
in the sequence.
-/
variable {α : Type*}
namespace RelEmbedding
variable {r : α → α → Prop} [IsStrictOrder α r]
/-- If `f` is a strictly `r`-increasing sequence, then this returns `f` as an order embedding. -/
def natLT (f : ℕ → α) (H : ∀ n : ℕ, r (f n) (f (n + 1))) : ((· < ·) : ℕ → ℕ → Prop) ↪r r :=
ofMonotone f <| Nat.rel_of_forall_rel_succ_of_lt r H
@[simp]
theorem coe_natLT {f : ℕ → α} {H : ∀ n : ℕ, r (f n) (f (n + 1))} : ⇑(natLT f H) = f :=
rfl
/-- If `f` is a strictly `r`-decreasing sequence, then this returns `f` as an order embedding. -/
def natGT (f : ℕ → α) (H : ∀ n : ℕ, r (f (n + 1)) (f n)) : ((· > ·) : ℕ → ℕ → Prop) ↪r r :=
haveI := IsStrictOrder.swap r
RelEmbedding.swap (natLT f H)
@[simp]
theorem coe_natGT {f : ℕ → α} {H : ∀ n : ℕ, r (f (n + 1)) (f n)} : ⇑(natGT f H) = f :=
rfl
theorem exists_not_acc_lt_of_not_acc {a : α} {r} (h : ¬Acc r a) : ∃ b, ¬Acc r b ∧ r b a := by
contrapose! h
refine ⟨_, fun b hr => ?_⟩
by_contra hb
exact h b hb hr
/-- A value is accessible iff it isn't contained in any infinite decreasing sequence. -/
theorem acc_iff_no_decreasing_seq {x} :
Acc r x ↔ IsEmpty { f : ((· > ·) : ℕ → ℕ → Prop) ↪r r // x ∈ Set.range f } := by
constructor
· refine fun h => h.recOn fun x _ IH => ?_
constructor
rintro ⟨f, k, hf⟩
exact IsEmpty.elim' (IH (f (k + 1)) (hf ▸ f.map_rel_iff.2 (Nat.lt_succ_self _))) ⟨f, _, rfl⟩
· have : ∀ x : { a // ¬Acc r a }, ∃ y : { a // ¬Acc r a }, r y.1 x.1 := by
rintro ⟨x, hx⟩
cases exists_not_acc_lt_of_not_acc hx with
| intro w h => exact ⟨⟨w, h.1⟩, h.2⟩
choose f h using this
refine fun E =>
by_contradiction fun hx => E.elim' ⟨natGT (fun n => (f^[n] ⟨x, hx⟩).1) fun n => ?_, 0, rfl⟩
simp only [Function.iterate_succ']
apply h
theorem not_acc_of_decreasing_seq (f : ((· > ·) : ℕ → ℕ → Prop) ↪r r) (k : ℕ) : ¬Acc r (f k) := by
rw [acc_iff_no_decreasing_seq, not_isEmpty_iff]
exact ⟨⟨f, k, rfl⟩⟩
/-- A relation is well-founded iff it doesn't have any infinite decreasing sequence. -/
theorem wellFounded_iff_no_descending_seq :
WellFounded r ↔ IsEmpty (((· > ·) : ℕ → ℕ → Prop) ↪r r) := by
constructor
· rintro ⟨h⟩
exact ⟨fun f => not_acc_of_decreasing_seq f 0 (h _)⟩
· intro h
exact ⟨fun x => acc_iff_no_decreasing_seq.2 inferInstance⟩
theorem not_wellFounded_of_decreasing_seq (f : ((· > ·) : ℕ → ℕ → Prop) ↪r r) : ¬WellFounded r := by
rw [wellFounded_iff_no_descending_seq, not_isEmpty_iff]
exact ⟨f⟩
end RelEmbedding
namespace Nat
variable (s : Set ℕ) [Infinite s]
/-- An order embedding from `ℕ` to itself with a specified range -/
def orderEmbeddingOfSet [DecidablePred (· ∈ s)] : ℕ ↪o ℕ :=
(RelEmbedding.orderEmbeddingOfLTEmbedding
(RelEmbedding.natLT (Nat.Subtype.ofNat s) fun _ => Nat.Subtype.lt_succ_self _)).trans
(OrderEmbedding.subtype s)
/-- `Nat.Subtype.ofNat` as an order isomorphism between `ℕ` and an infinite subset. See also
`Nat.Nth` for a version where the subset may be finite. -/
noncomputable def Subtype.orderIsoOfNat : ℕ ≃o s := by
classical
exact
RelIso.ofSurjective
(RelEmbedding.orderEmbeddingOfLTEmbedding
(RelEmbedding.natLT (Nat.Subtype.ofNat s) fun n => Nat.Subtype.lt_succ_self _))
Nat.Subtype.ofNat_surjective
variable {s}
@[simp]
theorem coe_orderEmbeddingOfSet [DecidablePred (· ∈ s)] :
⇑(orderEmbeddingOfSet s) = (↑) ∘ Subtype.ofNat s :=
rfl
theorem orderEmbeddingOfSet_apply [DecidablePred (· ∈ s)] {n : ℕ} :
orderEmbeddingOfSet s n = Subtype.ofNat s n :=
rfl
@[simp]
theorem Subtype.orderIsoOfNat_apply [dP : DecidablePred (· ∈ s)] {n : ℕ} :
Subtype.orderIsoOfNat s n = Subtype.ofNat s n := by
simp [orderIsoOfNat]; congr!
variable (s)
theorem orderEmbeddingOfSet_range [DecidablePred (· ∈ s)] :
Set.range (Nat.orderEmbeddingOfSet s) = s :=
Subtype.coe_comp_ofNat_range
theorem exists_subseq_of_forall_mem_union {s t : Set α} (e : ℕ → α) (he : ∀ n, e n ∈ s ∪ t) :
∃ g : ℕ ↪o ℕ, (∀ n, e (g n) ∈ s) ∨ ∀ n, e (g n) ∈ t := by
classical
have : Infinite (e ⁻¹' s) ∨ Infinite (e ⁻¹' t) := by
simp only [Set.infinite_coe_iff, ← Set.infinite_union, ← Set.preimage_union,
Set.eq_univ_of_forall fun n => Set.mem_preimage.2 (he n), Set.infinite_univ]
cases this
exacts [⟨Nat.orderEmbeddingOfSet (e ⁻¹' s), Or.inl fun n => (Nat.Subtype.ofNat (e ⁻¹' s) _).2⟩,
⟨Nat.orderEmbeddingOfSet (e ⁻¹' t), Or.inr fun n => (Nat.Subtype.ofNat (e ⁻¹' t) _).2⟩]
end Nat
theorem exists_increasing_or_nonincreasing_subseq' (r : α → α → Prop) (f : ℕ → α) :
∃ g : ℕ ↪o ℕ,
(∀ n : ℕ, r (f (g n)) (f (g (n + 1)))) ∨ ∀ m n : ℕ, m < n → ¬r (f (g m)) (f (g n)) := by
classical
let bad : Set ℕ := { m | ∀ n, m < n → ¬r (f m) (f n) }
by_cases hbad : Infinite bad
· haveI := hbad
refine ⟨Nat.orderEmbeddingOfSet bad, Or.intro_right _ fun m n mn => ?_⟩
have h := @Set.mem_range_self _ _ ↑(Nat.orderEmbeddingOfSet bad) m
rw [Nat.orderEmbeddingOfSet_range bad] at h
exact h _ ((OrderEmbedding.lt_iff_lt _).2 mn)
· rw [Set.infinite_coe_iff, Set.Infinite, not_not] at hbad
obtain ⟨m, hm⟩ : ∃ m, ∀ n, m ≤ n → ¬n ∈ bad := by
by_cases he : hbad.toFinset.Nonempty
· refine
⟨(hbad.toFinset.max' he).succ, fun n hn nbad =>
Nat.not_succ_le_self _
(hn.trans (hbad.toFinset.le_max' n (hbad.mem_toFinset.2 nbad)))⟩
· exact ⟨0, fun n _ nbad => he ⟨n, hbad.mem_toFinset.2 nbad⟩⟩
have h : ∀ n : ℕ, ∃ n' : ℕ, n < n' ∧ r (f (n + m)) (f (n' + m)) := by
intro n
have h := hm _ (Nat.le_add_left m n)
simp only [bad, exists_prop, not_not, Set.mem_setOf_eq, not_forall] at h
obtain ⟨n', hn1, hn2⟩ := h
refine ⟨n + n' - n - m, by omega, ?_⟩
convert hn2
omega
let g' : ℕ → ℕ := @Nat.rec (fun _ => ℕ) m fun n gn => Nat.find (h gn)
exact
⟨(RelEmbedding.natLT (fun n => g' n + m) fun n =>
Nat.add_lt_add_right (Nat.find_spec (h (g' n))).1 m).orderEmbeddingOfLTEmbedding,
Or.intro_left _ fun n => (Nat.find_spec (h (g' n))).2⟩
/-- This is the infinitary Erdős–Szekeres theorem, and an important lemma in the usual proof of
Bolzano-Weierstrass for `ℝ`. -/
theorem exists_increasing_or_nonincreasing_subseq (r : α → α → Prop) [IsTrans α r] (f : ℕ → α) :
∃ g : ℕ ↪o ℕ,
(∀ m n : ℕ, m < n → r (f (g m)) (f (g n))) ∨ ∀ m n : ℕ, m < n → ¬r (f (g m)) (f (g n)) := by
obtain ⟨g, hr | hnr⟩ := exists_increasing_or_nonincreasing_subseq' r f
· refine ⟨g, Or.intro_left _ fun m n mn => ?_⟩
obtain ⟨x, rfl⟩ := Nat.exists_eq_add_of_le (Nat.succ_le_iff.2 mn)
induction' x with x ih
· apply hr
· apply IsTrans.trans _ _ _ _ (hr _)
exact ih (lt_of_lt_of_le m.lt_succ_self (Nat.le_add_right _ _))
· exact ⟨g, Or.intro_right _ hnr⟩
theorem WellFounded.monotone_chain_condition' [Preorder α] :
WellFounded ((· > ·) : α → α → Prop) ↔ ∀ a : ℕ →o α, ∃ n, ∀ m, n ≤ m → ¬a n < a m := by
refine ⟨fun h a => ?_, fun h => ?_⟩
· have hne : (Set.range a).Nonempty := ⟨a 0, by simp⟩
obtain ⟨x, ⟨n, rfl⟩, H⟩ := h.has_min _ hne
exact ⟨n, fun m _ => H _ (Set.mem_range_self _)⟩
· refine RelEmbedding.wellFounded_iff_no_descending_seq.2 ⟨fun a => ?_⟩
obtain ⟨n, hn⟩ := h (a.swap : ((· < ·) : ℕ → ℕ → Prop) →r ((· < ·) : α → α → Prop)).toOrderHom
exact hn n.succ n.lt_succ_self.le ((RelEmbedding.map_rel_iff _).2 n.lt_succ_self)
/-- The "monotone chain condition" below is sometimes a convenient form of well foundedness. -/
theorem WellFounded.monotone_chain_condition [PartialOrder α] :
WellFounded ((· > ·) : α → α → Prop) ↔ ∀ a : ℕ →o α, ∃ n, ∀ m, n ≤ m → a n = a m :=
WellFounded.monotone_chain_condition'.trans <| by
congrm ∀ a, ∃ n, ∀ m h, ?_
rw [lt_iff_le_and_ne]
simp [a.mono h]
/-- Given an eventually-constant monotone sequence `a₀ ≤ a₁ ≤ a₂ ≤ ...` in a partially-ordered
type, `monotonicSequenceLimitIndex a` is the least natural number `n` for which `aₙ` reaches the
constant value. For sequences that are not eventually constant, `monotonicSequenceLimitIndex a`
is defined, but is a junk value. -/
noncomputable def monotonicSequenceLimitIndex [Preorder α] (a : ℕ →o α) : ℕ :=
sInf { n | ∀ m, n ≤ m → a n = a m }
/-- The constant value of an eventually-constant monotone sequence `a₀ ≤ a₁ ≤ a₂ ≤ ...` in a
partially-ordered type. -/
noncomputable def monotonicSequenceLimit [Preorder α] (a : ℕ →o α) :=
a (monotonicSequenceLimitIndex a)
theorem WellFounded.iSup_eq_monotonicSequenceLimit [CompleteLattice α]
(h : WellFounded ((· > ·) : α → α → Prop)) (a : ℕ →o α) :
iSup a = monotonicSequenceLimit a := by
refine (iSup_le fun m => ?_).antisymm (le_iSup a _)
rcases le_or_lt m (monotonicSequenceLimitIndex a) with hm | hm
· exact a.monotone hm
· cases' WellFounded.monotone_chain_condition'.1 h a with n hn
have : n ∈ {n | ∀ m, n ≤ m → a n = a m} := fun k hk => (a.mono hk).eq_of_not_lt (hn k hk)
exact (Nat.sInf_mem ⟨n, this⟩ m hm.le).ge
|
Order\Part.lean | /-
Copyright (c) 2024 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Part
import Mathlib.Order.Hom.Basic
import Mathlib.Tactic.Common
/-!
# Monotonicity of monadic operations on `Part`
-/
open Part
variable {α β γ : Type*} [Preorder α]
section bind
variable {f : α → Part β} {g : α → β → Part γ}
lemma Monotone.partBind (hf : Monotone f) (hg : Monotone g) :
Monotone fun x ↦ (f x).bind (g x) := by
rintro x y h a
simp only [and_imp, exists_prop, Part.bind_eq_bind, Part.mem_bind_iff, exists_imp]
exact fun b hb ha ↦ ⟨b, hf h _ hb, hg h _ _ ha⟩
lemma Antitone.partBind (hf : Antitone f) (hg : Antitone g) :
Antitone fun x ↦ (f x).bind (g x) := by
rintro x y h a
simp only [and_imp, exists_prop, Part.bind_eq_bind, Part.mem_bind_iff, exists_imp]
exact fun b hb ha ↦ ⟨b, hf h _ hb, hg h _ _ ha⟩
end bind
section map
variable {f : β → γ} {g : α → Part β}
lemma Monotone.partMap (hg : Monotone g) : Monotone fun x ↦ (g x).map f := by
simpa only [← bind_some_eq_map] using hg.partBind monotone_const
lemma Antitone.partMap (hg : Antitone g) : Antitone fun x ↦ (g x).map f := by
simpa only [← bind_some_eq_map] using hg.partBind antitone_const
end map
section seq
variable {β γ : Type _} {f : α → Part (β → γ)} {g : α → Part β}
lemma Monotone.partSeq (hf : Monotone f) (hg : Monotone g) : Monotone fun x ↦ f x <*> g x := by
simpa only [seq_eq_bind_map] using hf.partBind $ Monotone.of_apply₂ fun _ ↦ hg.partMap
lemma Antitone.partSeq (hf : Antitone f) (hg : Antitone g) : Antitone fun x ↦ f x <*> g x := by
simpa only [seq_eq_bind_map] using hf.partBind $ Antitone.of_apply₂ fun _ ↦ hg.partMap
end seq
namespace OrderHom
/-- `Part.bind` as a monotone function -/
@[simps]
def partBind (f : α →o Part β) (g : α →o β → Part γ) : α →o Part γ where
toFun x := (f x).bind (g x)
monotone' := f.2.partBind g.2
@[deprecated (since := "2024-07-04")] alias bind := partBind
end OrderHom
|
Order\PartialSups.lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Data.Finset.Lattice
import Mathlib.Order.Hom.Basic
import Mathlib.Data.Set.Finite
import Mathlib.Order.ConditionallyCompleteLattice.Basic
/-!
# The monotone sequence of partial supremums of a sequence
We define `partialSups : (ℕ → α) → ℕ →o α` inductively. For `f : ℕ → α`, `partialSups f` is
the sequence `f 0`, `f 0 ⊔ f 1`, `f 0 ⊔ f 1 ⊔ f 2`, ... The point of this definition is that
* it doesn't need a `⨆`, as opposed to `⨆ (i ≤ n), f i` (which also means the wrong thing on
`ConditionallyCompleteLattice`s).
* it doesn't need a `⊥`, as opposed to `(Finset.range (n + 1)).sup f`.
* it avoids needing to prove that `Finset.range (n + 1)` is nonempty to use `Finset.sup'`.
Equivalence with those definitions is shown by `partialSups_eq_biSup`, `partialSups_eq_sup_range`,
and `partialSups_eq_sup'_range` respectively.
## Notes
One might dispute whether this sequence should start at `f 0` or `⊥`. We choose the former because :
* Starting at `⊥` requires... having a bottom element.
* `fun f n ↦ (Finset.range n).sup f` is already effectively the sequence starting at `⊥`.
* If we started at `⊥` we wouldn't have the Galois insertion. See `partialSups.gi`.
## TODO
One could generalize `partialSups` to any locally finite bot preorder domain, in place of `ℕ`.
Necessary for the TODO in the module docstring of `Order.disjointed`.
-/
variable {α : Type*}
section SemilatticeSup
variable [SemilatticeSup α]
/-- The monotone sequence whose value at `n` is the supremum of the `f m` where `m ≤ n`. -/
def partialSups (f : ℕ → α) : ℕ →o α :=
⟨@Nat.rec (fun _ => α) (f 0) fun (n : ℕ) (a : α) => a ⊔ f (n + 1),
monotone_nat_of_le_succ fun _ => le_sup_left⟩
@[simp]
theorem partialSups_zero (f : ℕ → α) : partialSups f 0 = f 0 :=
rfl
@[simp]
theorem partialSups_succ (f : ℕ → α) (n : ℕ) :
partialSups f (n + 1) = partialSups f n ⊔ f (n + 1) :=
rfl
lemma partialSups_iff_forall {f : ℕ → α} (p : α → Prop)
(hp : ∀ {a b}, p (a ⊔ b) ↔ p a ∧ p b) : ∀ {n : ℕ}, p (partialSups f n) ↔ ∀ k ≤ n, p (f k)
| 0 => by simp
| (n + 1) => by simp [hp, partialSups_iff_forall, ← Nat.lt_succ_iff, ← Nat.forall_lt_succ]
@[simp]
lemma partialSups_le_iff {f : ℕ → α} {n : ℕ} {a : α} : partialSups f n ≤ a ↔ ∀ k ≤ n, f k ≤ a :=
partialSups_iff_forall (· ≤ a) sup_le_iff
theorem le_partialSups_of_le (f : ℕ → α) {m n : ℕ} (h : m ≤ n) : f m ≤ partialSups f n :=
partialSups_le_iff.1 le_rfl m h
theorem le_partialSups (f : ℕ → α) : f ≤ partialSups f := fun _n => le_partialSups_of_le f le_rfl
theorem partialSups_le (f : ℕ → α) (n : ℕ) (a : α) (w : ∀ m, m ≤ n → f m ≤ a) :
partialSups f n ≤ a :=
partialSups_le_iff.2 w
@[simp]
lemma upperBounds_range_partialSups (f : ℕ → α) :
upperBounds (Set.range (partialSups f)) = upperBounds (Set.range f) := by
ext a
simp only [mem_upperBounds, Set.forall_mem_range, partialSups_le_iff]
exact ⟨fun h _ ↦ h _ _ le_rfl, fun h _ _ _ ↦ h _⟩
@[simp]
theorem bddAbove_range_partialSups {f : ℕ → α} :
BddAbove (Set.range (partialSups f)) ↔ BddAbove (Set.range f) :=
.of_eq <| congr_arg Set.Nonempty <| upperBounds_range_partialSups f
theorem Monotone.partialSups_eq {f : ℕ → α} (hf : Monotone f) : (partialSups f : ℕ → α) = f := by
ext n
induction' n with n ih
· rfl
· rw [partialSups_succ, ih, sup_eq_right.2 (hf (Nat.le_succ _))]
theorem partialSups_mono : Monotone (partialSups : (ℕ → α) → ℕ →o α) := fun _f _g h _n ↦
partialSups_le_iff.2 fun k hk ↦ (h k).trans (le_partialSups_of_le _ hk)
/-- `partialSups` forms a Galois insertion with the coercion from monotone functions to functions.
-/
def partialSups.gi : GaloisInsertion (partialSups : (ℕ → α) → ℕ →o α) (↑) where
choice f h :=
⟨f, by convert (partialSups f).monotone using 1; exact (le_partialSups f).antisymm h⟩
gc f g := by
refine ⟨(le_partialSups f).trans, fun h => ?_⟩
convert partialSups_mono h
exact OrderHom.ext _ _ g.monotone.partialSups_eq.symm
le_l_u f := le_partialSups f
choice_eq f h := OrderHom.ext _ _ ((le_partialSups f).antisymm h)
theorem partialSups_eq_sup'_range (f : ℕ → α) (n : ℕ) :
partialSups f n = (Finset.range (n + 1)).sup' ⟨n, Finset.self_mem_range_succ n⟩ f :=
eq_of_forall_ge_iff fun _ ↦ by simp [Nat.lt_succ_iff]
lemma partialSups_apply {ι : Type*} {π : ι → Type*} [(i : ι) → SemilatticeSup (π i)]
(f : ℕ → (i : ι) → π i) (n : ℕ) (i : ι) : partialSups f n i = partialSups (f · i) n := by
simp only [partialSups_eq_sup'_range, Finset.sup'_apply]
end SemilatticeSup
theorem partialSups_eq_sup_range [SemilatticeSup α] [OrderBot α] (f : ℕ → α) (n : ℕ) :
partialSups f n = (Finset.range (n + 1)).sup f :=
eq_of_forall_ge_iff fun _ ↦ by simp [Nat.lt_succ_iff]
@[simp]
lemma disjoint_partialSups_left [DistribLattice α] [OrderBot α] {f : ℕ → α} {n : ℕ} {x : α} :
Disjoint (partialSups f n) x ↔ ∀ k ≤ n, Disjoint (f k) x :=
partialSups_iff_forall (Disjoint · x) disjoint_sup_left
@[simp]
lemma disjoint_partialSups_right [DistribLattice α] [OrderBot α] {f : ℕ → α} {n : ℕ} {x : α} :
Disjoint x (partialSups f n) ↔ ∀ k ≤ n, Disjoint x (f k) :=
partialSups_iff_forall (Disjoint x) disjoint_sup_right
/- Note this lemma requires a distributive lattice, so is not useful (or true) in situations such as
submodules. -/
theorem partialSups_disjoint_of_disjoint [DistribLattice α] [OrderBot α] (f : ℕ → α)
(h : Pairwise (Disjoint on f)) {m n : ℕ} (hmn : m < n) : Disjoint (partialSups f m) (f n) :=
disjoint_partialSups_left.2 fun _k hk ↦ h <| (hk.trans_lt hmn).ne
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α]
theorem partialSups_eq_ciSup_Iic (f : ℕ → α) (n : ℕ) : partialSups f n = ⨆ i : Set.Iic n, f i :=
eq_of_forall_ge_iff fun _ ↦ by
rw [ciSup_set_le_iff Set.nonempty_Iic ((Set.finite_le_nat _).image _).bddAbove,
partialSups_le_iff]; rfl
@[simp]
theorem ciSup_partialSups_eq {f : ℕ → α} (h : BddAbove (Set.range f)) :
⨆ n, partialSups f n = ⨆ n, f n := by
refine (ciSup_le fun n => ?_).antisymm (ciSup_mono ?_ <| le_partialSups f)
· rw [partialSups_eq_ciSup_Iic]
exact ciSup_le fun i => le_ciSup h _
· rwa [bddAbove_range_partialSups]
end ConditionallyCompleteLattice
section CompleteLattice
variable [CompleteLattice α]
theorem partialSups_eq_biSup (f : ℕ → α) (n : ℕ) : partialSups f n = ⨆ i ≤ n, f i := by
simpa only [iSup_subtype] using partialSups_eq_ciSup_Iic f n
-- Porting note (#10618): simp can prove this @[simp]
theorem iSup_partialSups_eq (f : ℕ → α) : ⨆ n, partialSups f n = ⨆ n, f n :=
ciSup_partialSups_eq <| OrderTop.bddAbove _
theorem iSup_le_iSup_of_partialSups_le_partialSups {f g : ℕ → α}
(h : partialSups f ≤ partialSups g) : ⨆ n, f n ≤ ⨆ n, g n := by
rw [← iSup_partialSups_eq f, ← iSup_partialSups_eq g]
exact iSup_mono h
theorem iSup_eq_iSup_of_partialSups_eq_partialSups {f g : ℕ → α}
(h : partialSups f = partialSups g) : ⨆ n, f n = ⨆ n, g n := by
simp_rw [← iSup_partialSups_eq f, ← iSup_partialSups_eq g, h]
end CompleteLattice
|
Order\PFilter.lean | /-
Copyright (c) 2020 Mathieu Guay-Paquet. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mathieu Guay-Paquet
-/
import Mathlib.Order.Ideal
/-!
# Order filters
## Main definitions
Throughout this file, `P` is at least a preorder, but some sections require more structure,
such as a bottom element, a top element, or a join-semilattice structure.
- `Order.PFilter P`: The type of nonempty, downward directed, upward closed subsets of `P`.
This is dual to `Order.Ideal`, so it simply wraps `Order.Ideal Pᵒᵈ`.
- `Order.IsPFilter P`: a predicate for when a `Set P` is a filter.
Note the relation between `Order/Filter` and `Order/PFilter`: for any type `α`,
`Filter α` represents the same mathematical object as `PFilter (Set α)`.
## References
- <https://en.wikipedia.org/wiki/Filter_(mathematics)>
## Tags
pfilter, filter, ideal, dual
-/
open OrderDual
namespace Order
/-- A filter on a preorder `P` is a subset of `P` that is
- nonempty
- downward directed
- upward closed. -/
structure PFilter (P : Type*) [Preorder P] where
dual : Ideal Pᵒᵈ
variable {P : Type*}
/-- A predicate for when a subset of `P` is a filter. -/
def IsPFilter [Preorder P] (F : Set P) : Prop :=
IsIdeal (OrderDual.ofDual ⁻¹' F)
theorem IsPFilter.of_def [Preorder P] {F : Set P} (nonempty : F.Nonempty)
(directed : DirectedOn (· ≥ ·) F) (mem_of_le : ∀ {x y : P}, x ≤ y → x ∈ F → y ∈ F) :
IsPFilter F :=
⟨fun _ _ _ _ => mem_of_le ‹_› ‹_›, nonempty, directed⟩
/-- Create an element of type `Order.PFilter` from a set satisfying the predicate
`Order.IsPFilter`. -/
def IsPFilter.toPFilter [Preorder P] {F : Set P} (h : IsPFilter F) : PFilter P :=
⟨h.toIdeal⟩
namespace PFilter
section Preorder
variable [Preorder P] {x y : P} (F s t : PFilter P)
instance [Inhabited P] : Inhabited (PFilter P) := ⟨⟨default⟩⟩
/-- A filter on `P` is a subset of `P`. -/
instance : SetLike (PFilter P) P where
coe F := toDual ⁻¹' F.dual.carrier
coe_injective' := fun ⟨_⟩ ⟨_⟩ h => congr_arg mk <| Ideal.ext h
theorem isPFilter : IsPFilter (F : Set P) := F.dual.isIdeal
protected theorem nonempty : (F : Set P).Nonempty := F.dual.nonempty
theorem directed : DirectedOn (· ≥ ·) (F : Set P) := F.dual.directed
theorem mem_of_le {F : PFilter P} : x ≤ y → x ∈ F → y ∈ F := fun h => F.dual.lower h
/-- Two filters are equal when their underlying sets are equal. -/
@[ext]
theorem ext (h : (s : Set P) = t) : s = t := SetLike.ext' h
@[trans]
theorem mem_of_mem_of_le {F G : PFilter P} (hx : x ∈ F) (hle : F ≤ G) : x ∈ G :=
hle hx
/-- The smallest filter containing a given element. -/
def principal (p : P) : PFilter P :=
⟨Ideal.principal (toDual p)⟩
@[simp]
theorem mem_mk (x : P) (I : Ideal Pᵒᵈ) : x ∈ (⟨I⟩ : PFilter P) ↔ toDual x ∈ I :=
Iff.rfl
@[simp]
theorem principal_le_iff {F : PFilter P} : principal x ≤ F ↔ x ∈ F :=
Ideal.principal_le_iff (x := toDual x)
@[simp] theorem mem_principal : x ∈ principal y ↔ y ≤ x := Iff.rfl
theorem principal_le_principal_iff {p q : P} : principal q ≤ principal p ↔ p ≤ q := by simp
-- defeq abuse
theorem antitone_principal : Antitone (principal : P → PFilter P) := fun _ _ =>
principal_le_principal_iff.2
end Preorder
section OrderTop
variable [Preorder P] [OrderTop P] {F : PFilter P}
/-- A specific witness of `pfilter.nonempty` when `P` has a top element. -/
@[simp] theorem top_mem : ⊤ ∈ F := Ideal.bot_mem _
/-- There is a bottom filter when `P` has a top element. -/
instance : OrderBot (PFilter P) where
bot := ⟨⊥⟩
bot_le F := (bot_le : ⊥ ≤ F.dual)
end OrderTop
/-- There is a top filter when `P` has a bottom element. -/
instance {P} [Preorder P] [OrderBot P] : OrderTop (PFilter P) where
top := ⟨⊤⟩
le_top F := (le_top : F.dual ≤ ⊤)
section SemilatticeInf
variable [SemilatticeInf P] {x y : P} {F : PFilter P}
/-- A specific witness of `pfilter.directed` when `P` has meets. -/
theorem inf_mem (hx : x ∈ F) (hy : y ∈ F) : x ⊓ y ∈ F :=
Ideal.sup_mem hx hy
@[simp]
theorem inf_mem_iff : x ⊓ y ∈ F ↔ x ∈ F ∧ y ∈ F :=
Ideal.sup_mem_iff
end SemilatticeInf
section CompleteSemilatticeInf
variable [CompleteSemilatticeInf P] {F : PFilter P}
theorem sInf_gc :
GaloisConnection (fun x => toDual (principal x)) fun F => sInf (ofDual F : PFilter P) :=
fun x F => by simp only [le_sInf_iff, SetLike.mem_coe, toDual_le, SetLike.le_def, mem_principal]
/-- If a poset `P` admits arbitrary `Inf`s, then `principal` and `Inf` form a Galois coinsertion. -/
def infGi :
GaloisCoinsertion (fun x => toDual (principal x)) fun F => sInf (ofDual F : PFilter P) :=
sInf_gc.toGaloisCoinsertion fun _ => sInf_le <| mem_principal.2 le_rfl
end CompleteSemilatticeInf
end PFilter
end Order
|
Order\PiLex.lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Order.WellFounded
import Mathlib.Tactic.Common
/-!
# Lexicographic order on Pi types
This file defines the lexicographic order for Pi types. `a` is less than `b` if `a i = b i` for all
`i` up to some point `k`, and `a k < b k`.
## Notation
* `Πₗ i, α i`: Pi type equipped with the lexicographic order. Type synonym of `Π i, α i`.
## See also
Related files are:
* `Data.Finset.Colex`: Colexicographic order on finite sets.
* `Data.List.Lex`: Lexicographic order on lists.
* `Data.Sigma.Order`: Lexicographic order on `Σₗ i, α i`.
* `Data.PSigma.Order`: Lexicographic order on `Σₗ' i, α i`.
* `Data.Prod.Lex`: Lexicographic order on `α × β`.
-/
assert_not_exists Monoid
variable {ι : Type*} {β : ι → Type*} (r : ι → ι → Prop) (s : ∀ {i}, β i → β i → Prop)
namespace Pi
/-- The lexicographic relation on `Π i : ι, β i`, where `ι` is ordered by `r`,
and each `β i` is ordered by `s`. -/
protected def Lex (x y : ∀ i, β i) : Prop :=
∃ i, (∀ j, r j i → x j = y j) ∧ s (x i) (y i)
/- This unfortunately results in a type that isn't delta-reduced, so we keep the notation out of the
basic API, just in case -/
/-- The notation `Πₗ i, α i` refers to a pi type equipped with the lexicographic order. -/
notation3 (prettyPrint := false) "Πₗ "(...)", "r:(scoped p => Lex (∀ i, p i)) => r
@[simp]
theorem toLex_apply (x : ∀ i, β i) (i : ι) : toLex x i = x i :=
rfl
@[simp]
theorem ofLex_apply (x : Lex (∀ i, β i)) (i : ι) : ofLex x i = x i :=
rfl
theorem lex_lt_of_lt_of_preorder [∀ i, Preorder (β i)] {r} (hwf : WellFounded r) {x y : ∀ i, β i}
(hlt : x < y) : ∃ i, (∀ j, r j i → x j ≤ y j ∧ y j ≤ x j) ∧ x i < y i :=
let h' := Pi.lt_def.1 hlt
let ⟨i, hi, hl⟩ := hwf.has_min _ h'.2
⟨i, fun j hj => ⟨h'.1 j, not_not.1 fun h => hl j (lt_of_le_not_le (h'.1 j) h) hj⟩, hi⟩
theorem lex_lt_of_lt [∀ i, PartialOrder (β i)] {r} (hwf : WellFounded r) {x y : ∀ i, β i}
(hlt : x < y) : Pi.Lex r (@fun i => (· < ·)) x y := by
simp_rw [Pi.Lex, le_antisymm_iff]
exact lex_lt_of_lt_of_preorder hwf hlt
theorem isTrichotomous_lex [∀ i, IsTrichotomous (β i) s] (wf : WellFounded r) :
IsTrichotomous (∀ i, β i) (Pi.Lex r @s) :=
{ trichotomous := fun a b => by
rcases eq_or_ne a b with hab | hab
· exact Or.inr (Or.inl hab)
· rw [Function.ne_iff] at hab
let i := wf.min _ hab
have hri : ∀ j, r j i → a j = b j := by
intro j
rw [← not_imp_not]
exact fun h' => wf.not_lt_min _ _ h'
have hne : a i ≠ b i := wf.min_mem _ hab
cases' trichotomous_of s (a i) (b i) with hi hi
exacts [Or.inl ⟨i, hri, hi⟩,
Or.inr <| Or.inr <| ⟨i, fun j hj => (hri j hj).symm, hi.resolve_left hne⟩] }
instance [LT ι] [∀ a, LT (β a)] : LT (Lex (∀ i, β i)) :=
⟨Pi.Lex (· < ·) @fun _ => (· < ·)⟩
instance Lex.isStrictOrder [LinearOrder ι] [∀ a, PartialOrder (β a)] :
IsStrictOrder (Lex (∀ i, β i)) (· < ·) where
irrefl := fun a ⟨k, _, hk₂⟩ => lt_irrefl (a k) hk₂
trans := by
rintro a b c ⟨N₁, lt_N₁, a_lt_b⟩ ⟨N₂, lt_N₂, b_lt_c⟩
rcases lt_trichotomy N₁ N₂ with (H | rfl | H)
exacts [⟨N₁, fun j hj => (lt_N₁ _ hj).trans (lt_N₂ _ <| hj.trans H), lt_N₂ _ H ▸ a_lt_b⟩,
⟨N₁, fun j hj => (lt_N₁ _ hj).trans (lt_N₂ _ hj), a_lt_b.trans b_lt_c⟩,
⟨N₂, fun j hj => (lt_N₁ _ (hj.trans H)).trans (lt_N₂ _ hj), (lt_N₁ _ H).symm ▸ b_lt_c⟩]
instance [LinearOrder ι] [∀ a, PartialOrder (β a)] : PartialOrder (Lex (∀ i, β i)) :=
partialOrderOfSO (· < ·)
/-- `Πₗ i, α i` is a linear order if the original order is well-founded. -/
noncomputable instance [LinearOrder ι] [IsWellOrder ι (· < ·)] [∀ a, LinearOrder (β a)] :
LinearOrder (Lex (∀ i, β i)) :=
@linearOrderOfSTO (Πₗ i, β i) (· < ·)
{ trichotomous := (isTrichotomous_lex _ _ IsWellFounded.wf).1 } (Classical.decRel _)
section PartialOrder
variable [LinearOrder ι] [IsWellOrder ι (· < ·)] [∀ i, PartialOrder (β i)] {x y : ∀ i, β i} {i : ι}
{a : β i}
open Function
theorem toLex_monotone : Monotone (@toLex (∀ i, β i)) := fun a b h =>
or_iff_not_imp_left.2 fun hne =>
let ⟨i, hi, hl⟩ := IsWellFounded.wf.has_min (r := (· < ·)) { i | a i ≠ b i }
(Function.ne_iff.1 hne)
⟨i, fun j hj => by
contrapose! hl
exact ⟨j, hl, hj⟩, (h i).lt_of_ne hi⟩
theorem toLex_strictMono : StrictMono (@toLex (∀ i, β i)) := fun a b h =>
let ⟨i, hi, hl⟩ := IsWellFounded.wf.has_min (r := (· < ·)) { i | a i ≠ b i }
(Function.ne_iff.1 h.ne)
⟨i, fun j hj => by
contrapose! hl
exact ⟨j, hl, hj⟩, (h.le i).lt_of_ne hi⟩
@[simp]
theorem lt_toLex_update_self_iff : toLex x < toLex (update x i a) ↔ x i < a := by
refine ⟨?_, fun h => toLex_strictMono <| lt_update_self_iff.2 h⟩
rintro ⟨j, hj, h⟩
dsimp at h
obtain rfl : j = i := by
by_contra H
rw [update_noteq H] at h
exact h.false
rwa [update_same] at h
@[simp]
theorem toLex_update_lt_self_iff : toLex (update x i a) < toLex x ↔ a < x i := by
refine ⟨?_, fun h => toLex_strictMono <| update_lt_self_iff.2 h⟩
rintro ⟨j, hj, h⟩
dsimp at h
obtain rfl : j = i := by
by_contra H
rw [update_noteq H] at h
exact h.false
rwa [update_same] at h
@[simp]
theorem le_toLex_update_self_iff : toLex x ≤ toLex (update x i a) ↔ x i ≤ a := by
simp_rw [le_iff_lt_or_eq, lt_toLex_update_self_iff, toLex_inj, eq_update_self_iff]
@[simp]
theorem toLex_update_le_self_iff : toLex (update x i a) ≤ toLex x ↔ a ≤ x i := by
simp_rw [le_iff_lt_or_eq, toLex_update_lt_self_iff, toLex_inj, update_eq_self_iff]
end PartialOrder
instance [LinearOrder ι] [IsWellOrder ι (· < ·)] [∀ a, PartialOrder (β a)] [∀ a, OrderBot (β a)] :
OrderBot (Lex (∀ a, β a)) where
bot := toLex ⊥
bot_le _ := toLex_monotone bot_le
instance [LinearOrder ι] [IsWellOrder ι (· < ·)] [∀ a, PartialOrder (β a)] [∀ a, OrderTop (β a)] :
OrderTop (Lex (∀ a, β a)) where
top := toLex ⊤
le_top _ := toLex_monotone le_top
instance [LinearOrder ι] [IsWellOrder ι (· < ·)] [∀ a, PartialOrder (β a)]
[∀ a, BoundedOrder (β a)] : BoundedOrder (Lex (∀ a, β a)) :=
{ }
instance [Preorder ι] [∀ i, LT (β i)] [∀ i, DenselyOrdered (β i)] :
DenselyOrdered (Lex (∀ i, β i)) :=
⟨by
rintro _ a₂ ⟨i, h, hi⟩
obtain ⟨a, ha₁, ha₂⟩ := exists_between hi
classical
refine ⟨Function.update a₂ _ a, ⟨i, fun j hj => ?_, ?_⟩, i, fun j hj => ?_, ?_⟩
· rw [h j hj]
dsimp only at hj
rw [Function.update_noteq hj.ne a]
· rwa [Function.update_same i a]
· rw [Function.update_noteq hj.ne a]
· rwa [Function.update_same i a]⟩
theorem Lex.noMaxOrder' [Preorder ι] [∀ i, LT (β i)] (i : ι) [NoMaxOrder (β i)] :
NoMaxOrder (Lex (∀ i, β i)) :=
⟨fun a => by
let ⟨b, hb⟩ := exists_gt (a i)
classical
exact ⟨Function.update a i b, i, fun j hj =>
(Function.update_noteq hj.ne b a).symm, by rwa [Function.update_same i b]⟩⟩
instance [LinearOrder ι] [IsWellOrder ι (· < ·)] [Nonempty ι] [∀ i, PartialOrder (β i)]
[∀ i, NoMaxOrder (β i)] : NoMaxOrder (Lex (∀ i, β i)) :=
⟨fun a =>
let ⟨_, hb⟩ := exists_gt (ofLex a)
⟨_, toLex_strictMono hb⟩⟩
instance [LinearOrder ι] [IsWellOrder ι (· < ·)] [Nonempty ι] [∀ i, PartialOrder (β i)]
[∀ i, NoMinOrder (β i)] : NoMinOrder (Lex (∀ i, β i)) :=
⟨fun a =>
let ⟨_, hb⟩ := exists_lt (ofLex a)
⟨_, toLex_strictMono hb⟩⟩
/-- If we swap two strictly decreasing values in a function, then the result is lexicographically
smaller than the original function. -/
theorem lex_desc {α} [Preorder ι] [DecidableEq ι] [Preorder α] {f : ι → α} {i j : ι} (h₁ : i ≤ j)
(h₂ : f j < f i) : toLex (f ∘ Equiv.swap i j) < toLex f :=
⟨i, fun k hik => congr_arg f (Equiv.swap_apply_of_ne_of_ne hik.ne (hik.trans_le h₁).ne), by
simpa only [Pi.toLex_apply, Function.comp_apply, Equiv.swap_apply_left] using h₂⟩
end Pi
|
Order\PrimeIdeal.lean | /-
Copyright (c) 2021 Noam Atar. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Noam Atar
-/
import Mathlib.Order.Ideal
import Mathlib.Order.PFilter
/-!
# Prime ideals
## Main definitions
Throughout this file, `P` is at least a preorder, but some sections require more
structure, such as a bottom element, a top element, or a join-semilattice structure.
- `Order.Ideal.PrimePair`: A pair of an `Order.Ideal` and an `Order.PFilter` which form a partition
of `P`. This is useful as giving the data of a prime ideal is the same as giving the data of a
prime filter.
- `Order.Ideal.IsPrime`: a predicate for prime ideals. Dual to the notion of a prime filter.
- `Order.PFilter.IsPrime`: a predicate for prime filters. Dual to the notion of a prime ideal.
## References
- <https://en.wikipedia.org/wiki/Ideal_(order_theory)>
## Tags
ideal, prime
-/
open Order.PFilter
namespace Order
variable {P : Type*}
namespace Ideal
/-- A pair of an `Order.Ideal` and an `Order.PFilter` which form a partition of `P`.
-/
-- Porting note(#5171): this linter isn't ported yet.
-- @[nolint has_nonempty_instance]
structure PrimePair (P : Type*) [Preorder P] where
I : Ideal P
F : PFilter P
isCompl_I_F : IsCompl (I : Set P) F
namespace PrimePair
variable [Preorder P] (IF : PrimePair P)
theorem compl_I_eq_F : (IF.I : Set P)ᶜ = IF.F :=
IF.isCompl_I_F.compl_eq
theorem compl_F_eq_I : (IF.F : Set P)ᶜ = IF.I :=
IF.isCompl_I_F.eq_compl.symm
theorem I_isProper : IsProper IF.I := by
cases' IF.F.nonempty with w h
apply isProper_of_not_mem (_ : w ∉ IF.I)
rwa [← IF.compl_I_eq_F] at h
protected theorem disjoint : Disjoint (IF.I : Set P) IF.F :=
IF.isCompl_I_F.disjoint
theorem I_union_F : (IF.I : Set P) ∪ IF.F = Set.univ :=
IF.isCompl_I_F.sup_eq_top
theorem F_union_I : (IF.F : Set P) ∪ IF.I = Set.univ :=
IF.isCompl_I_F.symm.sup_eq_top
end PrimePair
/-- An ideal `I` is prime if its complement is a filter.
-/
@[mk_iff]
class IsPrime [Preorder P] (I : Ideal P) extends IsProper I : Prop where
compl_filter : IsPFilter (I : Set P)ᶜ
section Preorder
variable [Preorder P]
/-- Create an element of type `Order.Ideal.PrimePair` from an ideal satisfying the predicate
`Order.Ideal.IsPrime`. -/
def IsPrime.toPrimePair {I : Ideal P} (h : IsPrime I) : PrimePair P :=
{ I
F := h.compl_filter.toPFilter
isCompl_I_F := isCompl_compl }
theorem PrimePair.I_isPrime (IF : PrimePair P) : IsPrime IF.I :=
{ IF.I_isProper with
compl_filter := by
rw [IF.compl_I_eq_F]
exact IF.F.isPFilter }
end Preorder
section SemilatticeInf
variable [SemilatticeInf P] {x y : P} {I : Ideal P}
theorem IsPrime.mem_or_mem (hI : IsPrime I) {x y : P} : x ⊓ y ∈ I → x ∈ I ∨ y ∈ I := by
contrapose!
let F := hI.compl_filter.toPFilter
show x ∈ F ∧ y ∈ F → x ⊓ y ∈ F
exact fun h => inf_mem h.1 h.2
theorem IsPrime.of_mem_or_mem [IsProper I] (hI : ∀ {x y : P}, x ⊓ y ∈ I → x ∈ I ∨ y ∈ I) :
IsPrime I := by
rw [isPrime_iff]
use ‹_›
refine .of_def ?_ ?_ ?_
· exact Set.nonempty_compl.2 (I.isProper_iff.1 ‹_›)
· intro x hx y hy
exact ⟨x ⊓ y, fun h => (hI h).elim hx hy, inf_le_left, inf_le_right⟩
· exact @mem_compl_of_ge _ _ _
theorem isPrime_iff_mem_or_mem [IsProper I] : IsPrime I ↔ ∀ {x y : P}, x ⊓ y ∈ I → x ∈ I ∨ y ∈ I :=
⟨IsPrime.mem_or_mem, IsPrime.of_mem_or_mem⟩
end SemilatticeInf
section DistribLattice
variable [DistribLattice P] {I : Ideal P}
instance (priority := 100) IsMaximal.isPrime [IsMaximal I] : IsPrime I := by
rw [isPrime_iff_mem_or_mem]
intro x y
contrapose!
rintro ⟨hx, hynI⟩ hxy
apply hynI
let J := I ⊔ principal x
have hJuniv : (J : Set P) = Set.univ :=
IsMaximal.maximal_proper (lt_sup_principal_of_not_mem ‹_›)
have hyJ : y ∈ (J : Set P) := Set.eq_univ_iff_forall.mp hJuniv y
rw [coe_sup_eq] at hyJ
rcases hyJ with ⟨a, ha, b, hb, hy⟩
rw [hy]
refine sup_mem ha (I.lower (le_inf hb ?_) hxy)
rw [hy]
exact le_sup_right
end DistribLattice
section BooleanAlgebra
variable [BooleanAlgebra P] {x : P} {I : Ideal P}
theorem IsPrime.mem_or_compl_mem (hI : IsPrime I) : x ∈ I ∨ xᶜ ∈ I := by
apply hI.mem_or_mem
rw [inf_compl_eq_bot]
exact I.bot_mem
theorem IsPrime.mem_compl_of_not_mem (hI : IsPrime I) (hxnI : x ∉ I) : xᶜ ∈ I :=
hI.mem_or_compl_mem.resolve_left hxnI
theorem isPrime_of_mem_or_compl_mem [IsProper I] (h : ∀ {x : P}, x ∈ I ∨ xᶜ ∈ I) : IsPrime I := by
simp only [isPrime_iff_mem_or_mem, or_iff_not_imp_left]
intro x y hxy hxI
have hxcI : xᶜ ∈ I := h.resolve_left hxI
have ass : x ⊓ y ⊔ y ⊓ xᶜ ∈ I := sup_mem hxy (I.lower inf_le_right hxcI)
rwa [inf_comm, sup_inf_inf_compl] at ass
theorem isPrime_iff_mem_or_compl_mem [IsProper I] : IsPrime I ↔ ∀ {x : P}, x ∈ I ∨ xᶜ ∈ I :=
⟨fun h _ => h.mem_or_compl_mem, isPrime_of_mem_or_compl_mem⟩
instance (priority := 100) IsPrime.isMaximal [IsPrime I] : IsMaximal I := by
simp only [isMaximal_iff, Set.eq_univ_iff_forall, IsPrime.toIsProper, true_and]
intro J hIJ x
rcases Set.exists_of_ssubset hIJ with ⟨y, hyJ, hyI⟩
suffices ass : x ⊓ y ⊔ x ⊓ yᶜ ∈ J by rwa [sup_inf_inf_compl] at ass
exact
sup_mem (J.lower inf_le_right hyJ)
(hIJ.le <| I.lower inf_le_right <| IsPrime.mem_compl_of_not_mem ‹_› hyI)
end BooleanAlgebra
end Ideal
namespace PFilter
variable [Preorder P]
/-- A filter `F` is prime if its complement is an ideal.
-/
@[mk_iff]
class IsPrime (F : PFilter P) : Prop where
compl_ideal : IsIdeal (F : Set P)ᶜ
/-- Create an element of type `Order.Ideal.PrimePair` from a filter satisfying the predicate
`Order.PFilter.IsPrime`. -/
def IsPrime.toPrimePair {F : PFilter P} (h : IsPrime F) : Ideal.PrimePair P :=
{ I := h.compl_ideal.toIdeal
F
isCompl_I_F := isCompl_compl.symm }
theorem _root_.Order.Ideal.PrimePair.F_isPrime (IF : Ideal.PrimePair P) : IsPrime IF.F :=
{
compl_ideal := by
rw [IF.compl_F_eq_I]
exact IF.I.isIdeal }
end PFilter
end Order
|
Order\PrimeSeparator.lean | /-
Copyright (c) 2024 Sam van Gool. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sam van Gool
-/
import Mathlib.Order.PrimeIdeal
import Mathlib.Order.Zorn
/-!
# Separating prime filters and ideals
In a bounded distributive lattice, if $F$ is a filter, $I$ is an ideal, and $F$ and $I$ are
disjoint, then there exists a prime ideal $J$ containing $I$ with $J$ still disjoint from $F$.
This theorem is a crucial ingredient to [Stone's][Sto1938] duality for bounded distributive
lattices. The construction of the separator relies on Zorn's lemma.
## Tags
ideal, filter, prime, distributive lattice
## References
* [M. H. Stone, Topological representations of distributive lattices and Brouwerian logics
(1938)][Sto1938]
-/
universe u
variable {α : Type*}
open Order Ideal Set
variable [DistribLattice α] [BoundedOrder α]
variable {F : PFilter α} {I : Ideal α}
namespace DistribLattice
lemma mem_ideal_sup_principal (a b : α) (J : Ideal α) : b ∈ J ⊔ principal a ↔ ∃ j ∈ J, b ≤ j ⊔ a :=
⟨fun ⟨j, ⟨jJ, _, ha', bja'⟩⟩ => ⟨j, jJ, le_trans bja' (sup_le_sup_left ha' j)⟩,
fun ⟨j, hj, hbja⟩ => ⟨j, hj, a, le_refl a, hbja⟩⟩
theorem prime_ideal_of_disjoint_filter_ideal (hFI : Disjoint (F : Set α) (I : Set α)) :
∃ J : Ideal α, (IsPrime J) ∧ I ≤ J ∧ Disjoint (F : Set α) J := by
-- Let S be the set of ideals containing I and disjoint from F.
set S : Set (Set α) := { J : Set α | IsIdeal J ∧ I ≤ J ∧ Disjoint (F : Set α) J }
-- Then I is in S...
have IinS : ↑I ∈ S := by
refine ⟨Order.Ideal.isIdeal I, by trivial⟩
-- ...and S contains upper bounds for any non-empty chains.
have chainub : ∀ c ⊆ S, IsChain (· ⊆ ·) c → c.Nonempty → ∃ ub ∈ S, ∀ s ∈ c, s ⊆ ub := by
intros c hcS hcC hcNe
use sUnion c
refine ⟨?_, fun s hs ↦ le_sSup hs⟩
simp only [le_eq_subset, mem_setOf_eq, disjoint_sUnion_right, S]
let ⟨J, hJ⟩ := hcNe
refine ⟨Order.isIdeal_sUnion_of_isChain (fun _ hJ ↦ (hcS hJ).1) hcC hcNe,
⟨le_trans (hcS hJ).2.1 (le_sSup hJ), fun J hJ ↦ (hcS hJ).2.2⟩⟩
-- Thus, by Zorn's lemma, we can pick a maximal ideal J in S.
obtain ⟨Jset, ⟨Jidl, IJ, JF⟩, ⟨_, Jmax⟩⟩ := zorn_subset_nonempty S chainub I IinS
set J := IsIdeal.toIdeal Jidl
use J
have IJ' : I ≤ J := IJ
clear chainub IinS
-- By construction, J contains I and is disjoint from F. It remains to prove that J is prime.
refine ⟨?_, ⟨IJ, JF⟩⟩
-- First note that J is proper: ⊤ ∈ F so ⊤ ∉ J because F and J are disjoint.
have Jpr : IsProper J := isProper_of_not_mem (Set.disjoint_left.1 JF F.top_mem)
-- Suppose that a₁ ∉ J, a₂ ∉ J. We need to prove that a₁ ⊔ a₂ ∉ J.
rw [isPrime_iff_mem_or_mem]
intros a₁ a₂
contrapose!
intro ⟨ha₁, ha₂⟩
-- Consider the ideals J₁, J₂ generated by J ∪ {a₁} and J ∪ {a₂}, respectively.
let J₁ := J ⊔ principal a₁
let J₂ := J ⊔ principal a₂
-- For each i, Jᵢ is an ideal that contains aᵢ, and is not equal to J.
have a₁J₁ : a₁ ∈ J₁ := mem_of_subset_of_mem (le_sup_right : _ ≤ J ⊔ _) mem_principal_self
have a₂J₂ : a₂ ∈ J₂ := mem_of_subset_of_mem (le_sup_right : _ ≤ J ⊔ _) mem_principal_self
have J₁J : ↑J₁ ≠ Jset := ne_of_mem_of_not_mem' a₁J₁ ha₁
have J₂J : ↑J₂ ≠ Jset := ne_of_mem_of_not_mem' a₂J₂ ha₂
-- Therefore, since J is maximal, we must have Jᵢ ∉ S.
have J₁S : ↑J₁ ∉ S := fun h => J₁J (Jmax J₁ h (le_sup_left : J ≤ J₁))
have J₂S : ↑J₂ ∉ S := fun h => J₂J (Jmax J₂ h (le_sup_left : J ≤ J₂))
-- Since Jᵢ is an ideal that contains I, we have that Jᵢ is not disjoint from F.
have J₁F : ¬ (Disjoint (F : Set α) J₁) := by
intro hdis
apply J₁S
simp only [le_eq_subset, mem_setOf_eq, SetLike.coe_subset_coe, S]
exact ⟨J₁.isIdeal, le_trans IJ' le_sup_left, hdis⟩
have J₂F : ¬ (Disjoint (F : Set α) J₂) := by
intro hdis
apply J₂S
simp only [le_eq_subset, mem_setOf_eq, SetLike.coe_subset_coe, S]
exact ⟨J₂.isIdeal, le_trans IJ' le_sup_left, hdis⟩
-- Thus, pick cᵢ ∈ F ∩ Jᵢ.
let ⟨c₁, ⟨c₁F, c₁J₁⟩⟩ := Set.not_disjoint_iff.1 J₁F
let ⟨c₂, ⟨c₂F, c₂J₂⟩⟩ := Set.not_disjoint_iff.1 J₂F
-- Using the definition of Jᵢ, we can pick bᵢ ∈ J such that cᵢ ≤ bᵢ ⊔ aᵢ.
let ⟨b₁, ⟨b₁J, cba₁⟩⟩ := (mem_ideal_sup_principal a₁ c₁ J).1 c₁J₁
let ⟨b₂, ⟨b₂J, cba₂⟩⟩ := (mem_ideal_sup_principal a₂ c₂ J).1 c₂J₂
-- Since J is an ideal, we have b := b₁ ⊔ b₂ ∈ J.
let b := b₁ ⊔ b₂
have bJ : b ∈ J := sup_mem b₁J b₂J
-- We now prove a key inequality, using crucially that the lattice is distributive.
have ineq : c₁ ⊓ c₂ ≤ b ⊔ (a₁ ⊓ a₂) :=
calc
c₁ ⊓ c₂ ≤ (b₁ ⊔ a₁) ⊓ (b₂ ⊔ a₂) := inf_le_inf cba₁ cba₂
_ ≤ (b ⊔ a₁) ⊓ (b ⊔ a₂) := by
apply inf_le_inf <;> apply sup_le_sup_right; exact le_sup_left; exact le_sup_right
_ = b ⊔ (a₁ ⊓ a₂) := (sup_inf_left b a₁ a₂).symm
-- Note that c₁ ⊓ c₂ ∈ F, since c₁ and c₂ are both in F and F is a filter.
-- Since F is an upper set, it now follows that b ⊔ (a₁ ⊓ a₂) ∈ F.
have ba₁a₂F : b ⊔ (a₁ ⊓ a₂) ∈ F := PFilter.mem_of_le ineq (PFilter.inf_mem c₁F c₂F)
-- Now, if we would have a₁ ⊓ a₂ ∈ J, then, since J is an ideal and b ∈ J, we would also get
-- b ⊔ (a₁ ⊓ a₂) ∈ J. But this contradicts that J is disjoint from F.
contrapose! JF with ha₁a₂
rw [Set.not_disjoint_iff]
use b ⊔ (a₁ ⊓ a₂)
exact ⟨ba₁a₂F, sup_mem bJ ha₁a₂⟩
-- TODO: Define prime filters in Mathlib so that the following corollary can be stated and proved.
-- theorem prime_filter_of_disjoint_filter_ideal (hFI : Disjoint (F : Set α) (I : Set α)) :
-- ∃ G : PFilter α, (IsPrime G) ∧ F ≤ G ∧ Disjoint (G : Set α) I := by sorry
end DistribLattice
|
Order\PropInstances.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Order.Disjoint
/-!
# The order on `Prop`
Instances on `Prop` such as `DistribLattice`, `BoundedOrder`, `LinearOrder`.
-/
/-- Propositions form a distributive lattice. -/
instance Prop.instDistribLattice : DistribLattice Prop where
sup := Or
le_sup_left := @Or.inl
le_sup_right := @Or.inr
sup_le := fun _ _ _ => Or.rec
inf := And
inf_le_left := @And.left
inf_le_right := @And.right
le_inf := fun _ _ _ Hab Hac Ha => And.intro (Hab Ha) (Hac Ha)
le_sup_inf := fun _ _ _ => or_and_left.2
/-- Propositions form a bounded order. -/
instance Prop.instBoundedOrder : BoundedOrder Prop where
top := True
le_top _ _ := True.intro
bot := False
bot_le := @False.elim
@[simp]
theorem Prop.bot_eq_false : (⊥ : Prop) = False :=
rfl
@[simp]
theorem Prop.top_eq_true : (⊤ : Prop) = True :=
rfl
instance Prop.le_isTotal : IsTotal Prop (· ≤ ·) :=
⟨fun p q => by by_cases h : q <;> simp [h]⟩
noncomputable instance Prop.linearOrder : LinearOrder Prop := by
classical
exact Lattice.toLinearOrder Prop
@[simp]
theorem sup_Prop_eq : (· ⊔ ·) = (· ∨ ·) :=
rfl
@[simp]
theorem inf_Prop_eq : (· ⊓ ·) = (· ∧ ·) :=
rfl
namespace Pi
variable {ι : Type*} {α' : ι → Type*} [∀ i, PartialOrder (α' i)]
theorem disjoint_iff [∀ i, OrderBot (α' i)] {f g : ∀ i, α' i} :
Disjoint f g ↔ ∀ i, Disjoint (f i) (g i) := by
classical
constructor
· intro h i x hf hg
exact (update_le_iff.mp <| h (update_le_iff.mpr ⟨hf, fun _ _ => bot_le⟩)
(update_le_iff.mpr ⟨hg, fun _ _ => bot_le⟩)).1
· intro h x hf hg i
apply h i (hf i) (hg i)
theorem codisjoint_iff [∀ i, OrderTop (α' i)] {f g : ∀ i, α' i} :
Codisjoint f g ↔ ∀ i, Codisjoint (f i) (g i) :=
@disjoint_iff _ (fun i => (α' i)ᵒᵈ) _ _ _ _
theorem isCompl_iff [∀ i, BoundedOrder (α' i)] {f g : ∀ i, α' i} :
IsCompl f g ↔ ∀ i, IsCompl (f i) (g i) := by
simp_rw [_root_.isCompl_iff, disjoint_iff, codisjoint_iff, forall_and]
end Pi
@[simp]
theorem Prop.disjoint_iff {P Q : Prop} : Disjoint P Q ↔ ¬(P ∧ Q) :=
disjoint_iff_inf_le
@[simp]
theorem Prop.codisjoint_iff {P Q : Prop} : Codisjoint P Q ↔ P ∨ Q :=
codisjoint_iff_le_sup.trans <| forall_const True
@[simp]
theorem Prop.isCompl_iff {P Q : Prop} : IsCompl P Q ↔ ¬(P ↔ Q) := by
rw [_root_.isCompl_iff, Prop.disjoint_iff, Prop.codisjoint_iff, not_iff]
by_cases P <;> by_cases Q <;> simp [*]
-- Porting note: Lean 3 would unfold these for us, but we need to do it manually now
section decidable_instances
universe u
variable {α : Type u}
instance Prop.decidablePredBot : DecidablePred (⊥ : α → Prop) := fun _ => instDecidableFalse
instance Prop.decidablePredTop : DecidablePred (⊤ : α → Prop) := fun _ => instDecidableTrue
instance Prop.decidableRelBot : DecidableRel (⊥ : α → α → Prop) := fun _ _ => instDecidableFalse
instance Prop.decidableRelTop : DecidableRel (⊤ : α → α → Prop) := fun _ _ => instDecidableTrue
end decidable_instances
|
Order\Radical.lean | /-
Copyright (c) 2024 Colva Roney-Dougal. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Colva Roney-Dougal, Inna Capdeboscq, Susanna Fishel, Kim Morrison
-/
import Mathlib.Order.CompleteLattice
import Mathlib.Order.Atoms
/-!
# The radical of a lattice
This file contains results on the order radical of a lattice: the infimum of the coatoms.
-/
/--
The infimum of all coatoms.
This notion specializes, e.g. in the subgroup lattice of a group to the Frattini subgroup,
or in the lattices of ideals in a ring `R` to the Jacobson ideal.
-/
def Order.radical (α : Type*) [Preorder α] [OrderTop α] [InfSet α] : α :=
⨅ a ∈ {H | IsCoatom H}, a
variable {α : Type*} [CompleteLattice α]
lemma Order.radical_le_coatom {a : α} (h : IsCoatom a) : radical α ≤ a := biInf_le _ h
variable {β : Type*} [CompleteLattice β]
theorem OrderIso.map_radical (f : α ≃o β) : f (Order.radical α) = Order.radical β := by
unfold Order.radical
simp only [OrderIso.map_iInf]
fapply Equiv.iInf_congr
· exact f.toEquiv
· simp
theorem Order.radical_nongenerating [IsCoatomic α] {a : α} (h : a ⊔ radical α = ⊤) : a = ⊤ := by
-- Since the lattice is coatomic, either `a` is already the top element,
-- or there is a coatom above it.
obtain (rfl | w) := eq_top_or_exists_le_coatom a
· -- In the first case, we're done, this was already the goal.
rfl
· obtain ⟨m, c, le⟩ := w
have q : a ⊔ radical α ≤ m := sup_le le (radical_le_coatom c)
-- Now note that `a ⊔ radical α ≤ m` since both `a ≤ m` and `radical α ≤ m`.
rw [h, top_le_iff] at q
simpa using c.1 q
|
Order\RelClasses.lean | /-
Copyright (c) 2020 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro, Yury G. Kudryashov
-/
import Mathlib.Data.Nat.Defs
import Mathlib.Logic.IsEmpty
import Mathlib.Order.Basic
import Mathlib.Tactic.MkIffOfInductiveProp
import Batteries.WF
/-!
# Unbundled relation classes
In this file we prove some properties of `Is*` classes defined in `Init.Algebra.Classes`. The main
difference between these classes and the usual order classes (`Preorder` etc) is that usual classes
extend `LE` and/or `LT` while these classes take a relation as an explicit argument.
-/
universe u v
variable {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop}
open Function
theorem of_eq [IsRefl α r] : ∀ {a b}, a = b → r a b
| _, _, .refl _ => refl _
theorem comm [IsSymm α r] {a b : α} : r a b ↔ r b a :=
⟨symm, symm⟩
theorem antisymm' [IsAntisymm α r] {a b : α} : r a b → r b a → b = a := fun h h' => antisymm h' h
theorem antisymm_iff [IsRefl α r] [IsAntisymm α r] {a b : α} : r a b ∧ r b a ↔ a = b :=
⟨fun h => antisymm h.1 h.2, by
rintro rfl
exact ⟨refl _, refl _⟩⟩
/-- A version of `antisymm` with `r` explicit.
This lemma matches the lemmas from lean core in `Init.Algebra.Classes`, but is missing there. -/
@[elab_without_expected_type]
theorem antisymm_of (r : α → α → Prop) [IsAntisymm α r] {a b : α} : r a b → r b a → a = b :=
antisymm
/-- A version of `antisymm'` with `r` explicit.
This lemma matches the lemmas from lean core in `Init.Algebra.Classes`, but is missing there. -/
@[elab_without_expected_type]
theorem antisymm_of' (r : α → α → Prop) [IsAntisymm α r] {a b : α} : r a b → r b a → b = a :=
antisymm'
/-- A version of `comm` with `r` explicit.
This lemma matches the lemmas from lean core in `Init.Algebra.Classes`, but is missing there. -/
theorem comm_of (r : α → α → Prop) [IsSymm α r] {a b : α} : r a b ↔ r b a :=
comm
theorem IsRefl.swap (r) [IsRefl α r] : IsRefl α (swap r) :=
⟨refl_of r⟩
theorem IsIrrefl.swap (r) [IsIrrefl α r] : IsIrrefl α (swap r) :=
⟨irrefl_of r⟩
theorem IsTrans.swap (r) [IsTrans α r] : IsTrans α (swap r) :=
⟨fun _ _ _ h₁ h₂ => trans_of r h₂ h₁⟩
theorem IsAntisymm.swap (r) [IsAntisymm α r] : IsAntisymm α (swap r) :=
⟨fun _ _ h₁ h₂ => _root_.antisymm h₂ h₁⟩
theorem IsAsymm.swap (r) [IsAsymm α r] : IsAsymm α (swap r) :=
⟨fun _ _ h₁ h₂ => asymm_of r h₂ h₁⟩
theorem IsTotal.swap (r) [IsTotal α r] : IsTotal α (swap r) :=
⟨fun a b => (total_of r a b).symm⟩
theorem IsTrichotomous.swap (r) [IsTrichotomous α r] : IsTrichotomous α (swap r) :=
⟨fun a b => by simpa [Function.swap, or_comm, or_left_comm] using trichotomous_of r a b⟩
theorem IsPreorder.swap (r) [IsPreorder α r] : IsPreorder α (swap r) :=
{ @IsRefl.swap α r _, @IsTrans.swap α r _ with }
theorem IsStrictOrder.swap (r) [IsStrictOrder α r] : IsStrictOrder α (swap r) :=
{ @IsIrrefl.swap α r _, @IsTrans.swap α r _ with }
theorem IsPartialOrder.swap (r) [IsPartialOrder α r] : IsPartialOrder α (swap r) :=
{ @IsPreorder.swap α r _, @IsAntisymm.swap α r _ with }
theorem IsTotalPreorder.swap (r) [IsTotalPreorder α r] : IsTotalPreorder α (swap r) :=
{ @IsPreorder.swap α r _, @IsTotal.swap α r _ with }
theorem IsLinearOrder.swap (r) [IsLinearOrder α r] : IsLinearOrder α (swap r) :=
{ @IsPartialOrder.swap α r _, @IsTotal.swap α r _ with }
protected theorem IsAsymm.isAntisymm (r) [IsAsymm α r] : IsAntisymm α r :=
⟨fun _ _ h₁ h₂ => (_root_.asymm h₁ h₂).elim⟩
protected theorem IsAsymm.isIrrefl [IsAsymm α r] : IsIrrefl α r :=
⟨fun _ h => _root_.asymm h h⟩
protected theorem IsTotal.isTrichotomous (r) [IsTotal α r] : IsTrichotomous α r :=
⟨fun a b => or_left_comm.1 (Or.inr <| total_of r a b)⟩
-- see Note [lower instance priority]
instance (priority := 100) IsTotal.to_isRefl (r) [IsTotal α r] : IsRefl α r :=
⟨fun a => or_self_iff.1 <| total_of r a a⟩
theorem ne_of_irrefl {r} [IsIrrefl α r] : ∀ {x y : α}, r x y → x ≠ y
| _, _, h, rfl => irrefl _ h
theorem ne_of_irrefl' {r} [IsIrrefl α r] : ∀ {x y : α}, r x y → y ≠ x
| _, _, h, rfl => irrefl _ h
theorem not_rel_of_subsingleton (r) [IsIrrefl α r] [Subsingleton α] (x y) : ¬r x y :=
Subsingleton.elim x y ▸ irrefl x
theorem rel_of_subsingleton (r) [IsRefl α r] [Subsingleton α] (x y) : r x y :=
Subsingleton.elim x y ▸ refl x
@[simp]
theorem empty_relation_apply (a b : α) : EmptyRelation a b ↔ False :=
Iff.rfl
theorem eq_empty_relation (r) [IsIrrefl α r] [Subsingleton α] : r = EmptyRelation :=
funext₂ <| by simpa using not_rel_of_subsingleton r
instance : IsIrrefl α EmptyRelation :=
⟨fun _ => id⟩
theorem trans_trichotomous_left [IsTrans α r] [IsTrichotomous α r] {a b c : α} :
¬r b a → r b c → r a c := by
intro h₁ h₂
rcases trichotomous_of r a b with (h₃ | rfl | h₃)
exacts [_root_.trans h₃ h₂, h₂, absurd h₃ h₁]
theorem trans_trichotomous_right [IsTrans α r] [IsTrichotomous α r] {a b c : α} :
r a b → ¬r c b → r a c := by
intro h₁ h₂
rcases trichotomous_of r b c with (h₃ | rfl | h₃)
exacts [_root_.trans h₁ h₃, h₁, absurd h₃ h₂]
theorem transitive_of_trans (r : α → α → Prop) [IsTrans α r] : Transitive r := IsTrans.trans
/-- In a trichotomous irreflexive order, every element is determined by the set of predecessors. -/
theorem extensional_of_trichotomous_of_irrefl (r : α → α → Prop) [IsTrichotomous α r] [IsIrrefl α r]
{a b : α} (H : ∀ x, r x a ↔ r x b) : a = b :=
((@trichotomous _ r _ a b).resolve_left <| mt (H _).2 <| irrefl a).resolve_right <| mt (H _).1
<| irrefl b
/-- Construct a partial order from an `isStrictOrder` relation.
See note [reducible non-instances]. -/
abbrev partialOrderOfSO (r) [IsStrictOrder α r] : PartialOrder α where
le x y := x = y ∨ r x y
lt := r
le_refl x := Or.inl rfl
le_trans x y z h₁ h₂ :=
match y, z, h₁, h₂ with
| _, _, Or.inl rfl, h₂ => h₂
| _, _, h₁, Or.inl rfl => h₁
| _, _, Or.inr h₁, Or.inr h₂ => Or.inr (_root_.trans h₁ h₂)
le_antisymm x y h₁ h₂ :=
match y, h₁, h₂ with
| _, Or.inl rfl, _ => rfl
| _, _, Or.inl rfl => rfl
| _, Or.inr h₁, Or.inr h₂ => (asymm h₁ h₂).elim
lt_iff_le_not_le x y :=
⟨fun h => ⟨Or.inr h, not_or_of_not (fun e => by rw [e] at h; exact irrefl _ h) (asymm h)⟩,
fun ⟨h₁, h₂⟩ => h₁.resolve_left fun e => h₂ <| e ▸ Or.inl rfl⟩
/-- Construct a linear order from an `IsStrictTotalOrder` relation.
See note [reducible non-instances]. -/
abbrev linearOrderOfSTO (r) [IsStrictTotalOrder α r] [∀ x y, Decidable ¬r x y] : LinearOrder α :=
let hD : DecidableRel (fun x y => x = y ∨ r x y) := fun x y =>
decidable_of_iff (¬r y x)
⟨fun h => ((trichotomous_of r y x).resolve_left h).imp Eq.symm id, fun h =>
h.elim (fun h => h ▸ irrefl_of _ _) (asymm_of r)⟩
{ __ := partialOrderOfSO r
le_total := fun x y =>
match y, trichotomous_of r x y with
| y, Or.inl h => Or.inl (Or.inr h)
| _, Or.inr (Or.inl rfl) => Or.inl (Or.inl rfl)
| _, Or.inr (Or.inr h) => Or.inr (Or.inr h),
toMin := minOfLe,
toMax := maxOfLe,
decidableLE := hD }
theorem IsStrictTotalOrder.swap (r) [IsStrictTotalOrder α r] : IsStrictTotalOrder α (swap r) :=
{ IsTrichotomous.swap r, IsStrictOrder.swap r with }
/-! ### Order connection -/
/-- A connected order is one satisfying the condition `a < c → a < b ∨ b < c`.
This is recognizable as an intuitionistic substitute for `a ≤ b ∨ b ≤ a` on
the constructive reals, and is also known as negative transitivity,
since the contrapositive asserts transitivity of the relation `¬ a < b`. -/
class IsOrderConnected (α : Type u) (lt : α → α → Prop) : Prop where
/-- A connected order is one satisfying the condition `a < c → a < b ∨ b < c`. -/
conn : ∀ a b c, lt a c → lt a b ∨ lt b c
theorem IsOrderConnected.neg_trans {r : α → α → Prop} [IsOrderConnected α r] {a b c}
(h₁ : ¬r a b) (h₂ : ¬r b c) : ¬r a c :=
mt (IsOrderConnected.conn a b c) <| by simp [h₁, h₂]
theorem isStrictWeakOrder_of_isOrderConnected [IsAsymm α r] [IsOrderConnected α r] :
IsStrictWeakOrder α r :=
{ @IsAsymm.isIrrefl α r _ with
trans := fun _ _ c h₁ h₂ => (IsOrderConnected.conn _ c _ h₁).resolve_right (asymm h₂),
incomp_trans := fun _ _ _ ⟨h₁, h₂⟩ ⟨h₃, h₄⟩ =>
⟨IsOrderConnected.neg_trans h₁ h₃, IsOrderConnected.neg_trans h₄ h₂⟩ }
-- see Note [lower instance priority]
instance (priority := 100) isStrictOrderConnected_of_isStrictTotalOrder [IsStrictTotalOrder α r] :
IsOrderConnected α r :=
⟨fun _ _ _ h ↦ (trichotomous _ _).imp_right
fun o ↦ o.elim (fun e ↦ e ▸ h) fun h' ↦ _root_.trans h' h⟩
-- see Note [lower instance priority]
instance (priority := 100) isStrictTotalOrder_of_isStrictTotalOrder [IsStrictTotalOrder α r] :
IsStrictWeakOrder α r :=
{ isStrictWeakOrder_of_isOrderConnected with }
/-! ### Well-order -/
/-- A well-founded relation. Not to be confused with `IsWellOrder`. -/
@[mk_iff] class IsWellFounded (α : Type u) (r : α → α → Prop) : Prop where
/-- The relation is `WellFounded`, as a proposition. -/
wf : WellFounded r
instance WellFoundedRelation.isWellFounded [h : WellFoundedRelation α] :
IsWellFounded α WellFoundedRelation.rel :=
{ h with }
theorem WellFoundedRelation.asymmetric {α : Sort*} [WellFoundedRelation α] {a b : α} :
WellFoundedRelation.rel a b → ¬ WellFoundedRelation.rel b a :=
fun hab hba => WellFoundedRelation.asymmetric hba hab
termination_by a
lemma WellFounded.prod_lex {ra : α → α → Prop} {rb : β → β → Prop} (ha : WellFounded ra)
(hb : WellFounded rb) : WellFounded (Prod.Lex ra rb) :=
(Prod.lex ⟨_, ha⟩ ⟨_, hb⟩).wf
namespace IsWellFounded
variable (r) [IsWellFounded α r]
/-- Induction on a well-founded relation. -/
theorem induction {C : α → Prop} : ∀ a, (∀ x, (∀ y, r y x → C y) → C x) → C a :=
wf.induction
/-- All values are accessible under the well-founded relation. -/
theorem apply : ∀ a, Acc r a :=
wf.apply
/-- Creates data, given a way to generate a value from all that compare as less under a well-founded
relation. See also `IsWellFounded.fix_eq`. -/
def fix {C : α → Sort*} : (∀ x : α, (∀ y : α, r y x → C y) → C x) → ∀ x : α, C x :=
wf.fix
/-- The value from `IsWellFounded.fix` is built from the previous ones as specified. -/
theorem fix_eq {C : α → Sort*} (F : ∀ x : α, (∀ y : α, r y x → C y) → C x) :
∀ x, fix r F x = F x fun y _ => fix r F y :=
wf.fix_eq F
/-- Derive a `WellFoundedRelation` instance from an `isWellFounded` instance. -/
def toWellFoundedRelation : WellFoundedRelation α :=
⟨r, IsWellFounded.wf⟩
end IsWellFounded
theorem WellFounded.asymmetric {α : Sort*} {r : α → α → Prop} (h : WellFounded r) (a b) :
r a b → ¬r b a :=
@WellFoundedRelation.asymmetric _ ⟨_, h⟩ _ _
-- see Note [lower instance priority]
instance (priority := 100) (r : α → α → Prop) [IsWellFounded α r] : IsAsymm α r :=
⟨IsWellFounded.wf.asymmetric⟩
-- see Note [lower instance priority]
instance (priority := 100) (r : α → α → Prop) [IsWellFounded α r] : IsIrrefl α r :=
IsAsymm.isIrrefl
instance (r : α → α → Prop) [i : IsWellFounded α r] : IsWellFounded α (Relation.TransGen r) :=
⟨i.wf.transGen⟩
/-- A class for a well founded relation `<`. -/
abbrev WellFoundedLT (α : Type*) [LT α] : Prop :=
IsWellFounded α (· < ·)
/-- A class for a well founded relation `>`. -/
abbrev WellFoundedGT (α : Type*) [LT α] : Prop :=
IsWellFounded α (· > ·)
lemma wellFounded_lt [LT α] [WellFoundedLT α] : @WellFounded α (· < ·) := IsWellFounded.wf
lemma wellFounded_gt [LT α] [WellFoundedGT α] : @WellFounded α (· > ·) := IsWellFounded.wf
-- See note [lower instance priority]
instance (priority := 100) (α : Type*) [LT α] [h : WellFoundedLT α] : WellFoundedGT αᵒᵈ :=
h
-- See note [lower instance priority]
instance (priority := 100) (α : Type*) [LT α] [h : WellFoundedGT α] : WellFoundedLT αᵒᵈ :=
h
theorem wellFoundedGT_dual_iff (α : Type*) [LT α] : WellFoundedGT αᵒᵈ ↔ WellFoundedLT α :=
⟨fun h => ⟨h.wf⟩, fun h => ⟨h.wf⟩⟩
theorem wellFoundedLT_dual_iff (α : Type*) [LT α] : WellFoundedLT αᵒᵈ ↔ WellFoundedGT α :=
⟨fun h => ⟨h.wf⟩, fun h => ⟨h.wf⟩⟩
/-- A well order is a well-founded linear order. -/
class IsWellOrder (α : Type u) (r : α → α → Prop) extends
IsTrichotomous α r, IsTrans α r, IsWellFounded α r : Prop
-- see Note [lower instance priority]
instance (priority := 100) {α} (r : α → α → Prop) [IsWellOrder α r] :
IsStrictTotalOrder α r where
-- see Note [lower instance priority]
instance (priority := 100) {α} (r : α → α → Prop) [IsWellOrder α r] : IsTrichotomous α r := by
infer_instance
-- see Note [lower instance priority]
instance (priority := 100) {α} (r : α → α → Prop) [IsWellOrder α r] : IsTrans α r := by
infer_instance
-- see Note [lower instance priority]
instance (priority := 100) {α} (r : α → α → Prop) [IsWellOrder α r] : IsIrrefl α r := by
infer_instance
-- see Note [lower instance priority]
instance (priority := 100) {α} (r : α → α → Prop) [IsWellOrder α r] : IsAsymm α r := by
infer_instance
namespace WellFoundedLT
variable [LT α] [WellFoundedLT α]
/-- Inducts on a well-founded `<` relation. -/
theorem induction {C : α → Prop} : ∀ a, (∀ x, (∀ y, y < x → C y) → C x) → C a :=
IsWellFounded.induction _
/-- All values are accessible under the well-founded `<`. -/
theorem apply : ∀ a : α, Acc (· < ·) a :=
IsWellFounded.apply _
/-- Creates data, given a way to generate a value from all that compare as lesser. See also
`WellFoundedLT.fix_eq`. -/
def fix {C : α → Sort*} : (∀ x : α, (∀ y : α, y < x → C y) → C x) → ∀ x : α, C x :=
IsWellFounded.fix (· < ·)
/-- The value from `WellFoundedLT.fix` is built from the previous ones as specified. -/
theorem fix_eq {C : α → Sort*} (F : ∀ x : α, (∀ y : α, y < x → C y) → C x) :
∀ x, fix F x = F x fun y _ => fix F y :=
IsWellFounded.fix_eq _ F
/-- Derive a `WellFoundedRelation` instance from a `WellFoundedLT` instance. -/
def toWellFoundedRelation : WellFoundedRelation α :=
IsWellFounded.toWellFoundedRelation (· < ·)
end WellFoundedLT
namespace WellFoundedGT
variable [LT α] [WellFoundedGT α]
/-- Inducts on a well-founded `>` relation. -/
theorem induction {C : α → Prop} : ∀ a, (∀ x, (∀ y, x < y → C y) → C x) → C a :=
IsWellFounded.induction _
/-- All values are accessible under the well-founded `>`. -/
theorem apply : ∀ a : α, Acc (· > ·) a :=
IsWellFounded.apply _
/-- Creates data, given a way to generate a value from all that compare as greater. See also
`WellFoundedGT.fix_eq`. -/
def fix {C : α → Sort*} : (∀ x : α, (∀ y : α, x < y → C y) → C x) → ∀ x : α, C x :=
IsWellFounded.fix (· > ·)
/-- The value from `WellFoundedGT.fix` is built from the successive ones as specified. -/
theorem fix_eq {C : α → Sort*} (F : ∀ x : α, (∀ y : α, x < y → C y) → C x) :
∀ x, fix F x = F x fun y _ => fix F y :=
IsWellFounded.fix_eq _ F
/-- Derive a `WellFoundedRelation` instance from a `WellFoundedGT` instance. -/
def toWellFoundedRelation : WellFoundedRelation α :=
IsWellFounded.toWellFoundedRelation (· > ·)
end WellFoundedGT
/-- Construct a decidable linear order from a well-founded linear order. -/
noncomputable def IsWellOrder.linearOrder (r : α → α → Prop) [IsWellOrder α r] : LinearOrder α :=
letI := fun x y => Classical.dec ¬r x y
linearOrderOfSTO r
/-- Derive a `WellFoundedRelation` instance from an `IsWellOrder` instance. -/
def IsWellOrder.toHasWellFounded [LT α] [hwo : IsWellOrder α (· < ·)] : WellFoundedRelation α where
rel := (· < ·)
wf := hwo.wf
-- This isn't made into an instance as it loops with `IsIrrefl α r`.
theorem Subsingleton.isWellOrder [Subsingleton α] (r : α → α → Prop) [hr : IsIrrefl α r] :
IsWellOrder α r :=
{ hr with
trichotomous := fun a b => Or.inr <| Or.inl <| Subsingleton.elim a b,
trans := fun a b _ h => (not_rel_of_subsingleton r a b h).elim,
wf := ⟨fun a => ⟨_, fun y h => (not_rel_of_subsingleton r y a h).elim⟩⟩ }
instance [Subsingleton α] : IsWellOrder α EmptyRelation :=
Subsingleton.isWellOrder _
instance (priority := 100) [IsEmpty α] (r : α → α → Prop) : IsWellOrder α r where
trichotomous := isEmptyElim
trans := isEmptyElim
wf := wellFounded_of_isEmpty r
instance [IsWellFounded α r] [IsWellFounded β s] : IsWellFounded (α × β) (Prod.Lex r s) :=
⟨IsWellFounded.wf.prod_lex IsWellFounded.wf⟩
instance [IsWellOrder α r] [IsWellOrder β s] : IsWellOrder (α × β) (Prod.Lex r s) where
trichotomous := fun ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ =>
match @trichotomous _ r _ a₁ b₁ with
| Or.inl h₁ => Or.inl <| Prod.Lex.left _ _ h₁
| Or.inr (Or.inr h₁) => Or.inr <| Or.inr <| Prod.Lex.left _ _ h₁
| Or.inr (Or.inl (.refl _)) =>
match @trichotomous _ s _ a₂ b₂ with
| Or.inl h => Or.inl <| Prod.Lex.right _ h
| Or.inr (Or.inr h) => Or.inr <| Or.inr <| Prod.Lex.right _ h
| Or.inr (Or.inl (.refl _)) => Or.inr <| Or.inl rfl
trans a b c h₁ h₂ := by
cases' h₁ with a₁ a₂ b₁ b₂ ab a₁ b₁ b₂ ab <;> cases' h₂ with _ _ c₁ c₂ bc _ _ c₂ bc
exacts [.left _ _ (_root_.trans ab bc), .left _ _ ab, .left _ _ bc,
.right _ (_root_.trans ab bc)]
instance (r : α → α → Prop) [IsWellFounded α r] (f : β → α) : IsWellFounded _ (InvImage r f) :=
⟨InvImage.wf f IsWellFounded.wf⟩
instance (f : α → ℕ) : IsWellFounded _ (InvImage (· < ·) f) :=
⟨(measure f).wf⟩
theorem Subrelation.isWellFounded (r : α → α → Prop) [IsWellFounded α r] {s : α → α → Prop}
(h : Subrelation s r) : IsWellFounded α s :=
⟨h.wf IsWellFounded.wf⟩
instance Prod.wellFoundedLT [PartialOrder α] [WellFoundedLT α] [Preorder β] [WellFoundedLT β] :
WellFoundedLT (α × β) where
wf := by
refine @Subrelation.wf (α × β) (Prod.Lex (· < ·) (· < ·)) (· < ·) ?_ IsWellFounded.wf
rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ w
simp only [Prod.mk_lt_mk] at w
rcases eq_or_ne a₁ a₂ with rfl | ha
· right
simpa using w
· left
rcases w with ⟨a_lt, _⟩ | ⟨a_le, _⟩
· assumption
· exact Ne.lt_of_le ha a_le
instance Prod.wellFoundedGT [PartialOrder α] [WellFoundedGT α] [Preorder β] [WellFoundedGT β] :
WellFoundedGT (α × β) :=
@Prod.wellFoundedLT αᵒᵈ βᵒᵈ _ _ _ _
namespace Set
/-- An unbounded or cofinal set. -/
def Unbounded (r : α → α → Prop) (s : Set α) : Prop :=
∀ a, ∃ b ∈ s, ¬r b a
/-- A bounded or final set. Not to be confused with `Bornology.IsBounded`. -/
def Bounded (r : α → α → Prop) (s : Set α) : Prop :=
∃ a, ∀ b ∈ s, r b a
@[simp]
theorem not_bounded_iff {r : α → α → Prop} (s : Set α) : ¬Bounded r s ↔ Unbounded r s := by
simp only [Bounded, Unbounded, not_forall, not_exists, exists_prop, not_and, not_not]
@[simp]
theorem not_unbounded_iff {r : α → α → Prop} (s : Set α) : ¬Unbounded r s ↔ Bounded r s := by
rw [not_iff_comm, not_bounded_iff]
theorem unbounded_of_isEmpty [IsEmpty α] {r : α → α → Prop} (s : Set α) : Unbounded r s :=
isEmptyElim
end Set
namespace Order.Preimage
instance instIsRefl {r : α → α → Prop} [IsRefl α r] {f : β → α} : IsRefl β (f ⁻¹'o r) :=
⟨fun a => refl_of r (f a)⟩
instance instIsTrans {r : α → α → Prop} [IsTrans α r] {f : β → α} : IsTrans β (f ⁻¹'o r) :=
⟨fun _ _ _ => trans_of r⟩
end Order.Preimage
/-! ### Strict-non strict relations -/
/-- An unbundled relation class stating that `r` is the nonstrict relation corresponding to the
strict relation `s`. Compare `Preorder.lt_iff_le_not_le`. This is mostly meant to provide dot
notation on `(⊆)` and `(⊂)`. -/
class IsNonstrictStrictOrder (α : Type*) (r : semiOutParam (α → α → Prop)) (s : α → α → Prop) :
Prop where
/-- The relation `r` is the nonstrict relation corresponding to the strict relation `s`. -/
right_iff_left_not_left (a b : α) : s a b ↔ r a b ∧ ¬r b a
theorem right_iff_left_not_left {r s : α → α → Prop} [IsNonstrictStrictOrder α r s] {a b : α} :
s a b ↔ r a b ∧ ¬r b a :=
IsNonstrictStrictOrder.right_iff_left_not_left _ _
/-- A version of `right_iff_left_not_left` with explicit `r` and `s`. -/
theorem right_iff_left_not_left_of (r s : α → α → Prop) [IsNonstrictStrictOrder α r s] {a b : α} :
s a b ↔ r a b ∧ ¬r b a :=
right_iff_left_not_left
instance {s : α → α → Prop} [IsNonstrictStrictOrder α r s] : IsIrrefl α s :=
⟨fun _ h => ((right_iff_left_not_left_of r s).1 h).2 ((right_iff_left_not_left_of r s).1 h).1⟩
/-! #### `⊆` and `⊂` -/
section Subset
variable [HasSubset α] {a b c : α}
lemma subset_of_eq_of_subset (hab : a = b) (hbc : b ⊆ c) : a ⊆ c := by rwa [hab]
lemma subset_of_subset_of_eq (hab : a ⊆ b) (hbc : b = c) : a ⊆ c := by rwa [← hbc]
@[refl, simp]
lemma subset_refl [IsRefl α (· ⊆ ·)] (a : α) : a ⊆ a := refl _
lemma subset_rfl [IsRefl α (· ⊆ ·)] : a ⊆ a := refl _
lemma subset_of_eq [IsRefl α (· ⊆ ·)] : a = b → a ⊆ b := fun h => h ▸ subset_rfl
lemma superset_of_eq [IsRefl α (· ⊆ ·)] : a = b → b ⊆ a := fun h => h ▸ subset_rfl
lemma ne_of_not_subset [IsRefl α (· ⊆ ·)] : ¬a ⊆ b → a ≠ b := mt subset_of_eq
lemma ne_of_not_superset [IsRefl α (· ⊆ ·)] : ¬a ⊆ b → b ≠ a := mt superset_of_eq
@[trans]
lemma subset_trans [IsTrans α (· ⊆ ·)] {a b c : α} : a ⊆ b → b ⊆ c → a ⊆ c := _root_.trans
lemma subset_antisymm [IsAntisymm α (· ⊆ ·)] : a ⊆ b → b ⊆ a → a = b := antisymm
lemma superset_antisymm [IsAntisymm α (· ⊆ ·)] : a ⊆ b → b ⊆ a → b = a := antisymm'
alias Eq.trans_subset := subset_of_eq_of_subset
alias HasSubset.subset.trans_eq := subset_of_subset_of_eq
alias Eq.subset' := subset_of_eq --TODO: Fix it and kill `Eq.subset`
alias Eq.superset := superset_of_eq
alias HasSubset.Subset.trans := subset_trans
alias HasSubset.Subset.antisymm := subset_antisymm
alias HasSubset.Subset.antisymm' := superset_antisymm
theorem subset_antisymm_iff [IsRefl α (· ⊆ ·)] [IsAntisymm α (· ⊆ ·)] : a = b ↔ a ⊆ b ∧ b ⊆ a :=
⟨fun h => ⟨h.subset', h.superset⟩, fun h => h.1.antisymm h.2⟩
theorem superset_antisymm_iff [IsRefl α (· ⊆ ·)] [IsAntisymm α (· ⊆ ·)] : a = b ↔ b ⊆ a ∧ a ⊆ b :=
⟨fun h => ⟨h.superset, h.subset'⟩, fun h => h.1.antisymm' h.2⟩
end Subset
section Ssubset
variable [HasSSubset α] {a b c : α}
lemma ssubset_of_eq_of_ssubset (hab : a = b) (hbc : b ⊂ c) : a ⊂ c := by rwa [hab]
lemma ssubset_of_ssubset_of_eq (hab : a ⊂ b) (hbc : b = c) : a ⊂ c := by rwa [← hbc]
lemma ssubset_irrefl [IsIrrefl α (· ⊂ ·)] (a : α) : ¬a ⊂ a := irrefl _
lemma ssubset_irrfl [IsIrrefl α (· ⊂ ·)] {a : α} : ¬a ⊂ a := irrefl _
lemma ne_of_ssubset [IsIrrefl α (· ⊂ ·)] {a b : α} : a ⊂ b → a ≠ b := ne_of_irrefl
lemma ne_of_ssuperset [IsIrrefl α (· ⊂ ·)] {a b : α} : a ⊂ b → b ≠ a := ne_of_irrefl'
@[trans]
lemma ssubset_trans [IsTrans α (· ⊂ ·)] {a b c : α} : a ⊂ b → b ⊂ c → a ⊂ c := _root_.trans
lemma ssubset_asymm [IsAsymm α (· ⊂ ·)] {a b : α} : a ⊂ b → ¬b ⊂ a := asymm
alias Eq.trans_ssubset := ssubset_of_eq_of_ssubset
alias HasSSubset.SSubset.trans_eq := ssubset_of_ssubset_of_eq
alias HasSSubset.SSubset.false := ssubset_irrfl
alias HasSSubset.SSubset.ne := ne_of_ssubset
alias HasSSubset.SSubset.ne' := ne_of_ssuperset
alias HasSSubset.SSubset.trans := ssubset_trans
alias HasSSubset.SSubset.asymm := ssubset_asymm
end Ssubset
section SubsetSsubset
variable [HasSubset α] [HasSSubset α] [IsNonstrictStrictOrder α (· ⊆ ·) (· ⊂ ·)] {a b c : α}
theorem ssubset_iff_subset_not_subset : a ⊂ b ↔ a ⊆ b ∧ ¬b ⊆ a :=
right_iff_left_not_left
theorem subset_of_ssubset (h : a ⊂ b) : a ⊆ b :=
(ssubset_iff_subset_not_subset.1 h).1
theorem not_subset_of_ssubset (h : a ⊂ b) : ¬b ⊆ a :=
(ssubset_iff_subset_not_subset.1 h).2
theorem not_ssubset_of_subset (h : a ⊆ b) : ¬b ⊂ a := fun h' => not_subset_of_ssubset h' h
theorem ssubset_of_subset_not_subset (h₁ : a ⊆ b) (h₂ : ¬b ⊆ a) : a ⊂ b :=
ssubset_iff_subset_not_subset.2 ⟨h₁, h₂⟩
alias HasSSubset.SSubset.subset := subset_of_ssubset
alias HasSSubset.SSubset.not_subset := not_subset_of_ssubset
alias HasSubset.Subset.not_ssubset := not_ssubset_of_subset
alias HasSubset.Subset.ssubset_of_not_subset := ssubset_of_subset_not_subset
theorem ssubset_of_subset_of_ssubset [IsTrans α (· ⊆ ·)] (h₁ : a ⊆ b) (h₂ : b ⊂ c) : a ⊂ c :=
(h₁.trans h₂.subset).ssubset_of_not_subset fun h => h₂.not_subset <| h.trans h₁
theorem ssubset_of_ssubset_of_subset [IsTrans α (· ⊆ ·)] (h₁ : a ⊂ b) (h₂ : b ⊆ c) : a ⊂ c :=
(h₁.subset.trans h₂).ssubset_of_not_subset fun h => h₁.not_subset <| h₂.trans h
theorem ssubset_of_subset_of_ne [IsAntisymm α (· ⊆ ·)] (h₁ : a ⊆ b) (h₂ : a ≠ b) : a ⊂ b :=
h₁.ssubset_of_not_subset <| mt h₁.antisymm h₂
theorem ssubset_of_ne_of_subset [IsAntisymm α (· ⊆ ·)] (h₁ : a ≠ b) (h₂ : a ⊆ b) : a ⊂ b :=
ssubset_of_subset_of_ne h₂ h₁
theorem eq_or_ssubset_of_subset [IsAntisymm α (· ⊆ ·)] (h : a ⊆ b) : a = b ∨ a ⊂ b :=
(em (b ⊆ a)).imp h.antisymm h.ssubset_of_not_subset
theorem ssubset_or_eq_of_subset [IsAntisymm α (· ⊆ ·)] (h : a ⊆ b) : a ⊂ b ∨ a = b :=
(eq_or_ssubset_of_subset h).symm
lemma eq_of_subset_of_not_ssubset [IsAntisymm α (· ⊆ ·)] (hab : a ⊆ b) (hba : ¬ a ⊂ b) : a = b :=
(eq_or_ssubset_of_subset hab).resolve_right hba
lemma eq_of_superset_of_not_ssuperset [IsAntisymm α (· ⊆ ·)] (hab : a ⊆ b) (hba : ¬ a ⊂ b) :
b = a := ((eq_or_ssubset_of_subset hab).resolve_right hba).symm
alias HasSubset.Subset.trans_ssubset := ssubset_of_subset_of_ssubset
alias HasSSubset.SSubset.trans_subset := ssubset_of_ssubset_of_subset
alias HasSubset.Subset.ssubset_of_ne := ssubset_of_subset_of_ne
alias Ne.ssubset_of_subset := ssubset_of_ne_of_subset
alias HasSubset.Subset.eq_or_ssubset := eq_or_ssubset_of_subset
alias HasSubset.Subset.ssubset_or_eq := ssubset_or_eq_of_subset
alias HasSubset.Subset.eq_of_not_ssubset := eq_of_subset_of_not_ssubset
alias HasSubset.Subset.eq_of_not_ssuperset := eq_of_superset_of_not_ssuperset
theorem ssubset_iff_subset_ne [IsAntisymm α (· ⊆ ·)] : a ⊂ b ↔ a ⊆ b ∧ a ≠ b :=
⟨fun h => ⟨h.subset, h.ne⟩, fun h => h.1.ssubset_of_ne h.2⟩
theorem subset_iff_ssubset_or_eq [IsRefl α (· ⊆ ·)] [IsAntisymm α (· ⊆ ·)] :
a ⊆ b ↔ a ⊂ b ∨ a = b :=
⟨fun h => h.ssubset_or_eq, fun h => h.elim subset_of_ssubset subset_of_eq⟩
end SubsetSsubset
/-! ### Conversion of bundled order typeclasses to unbundled relation typeclasses -/
instance [Preorder α] : IsRefl α (· ≤ ·) :=
⟨le_refl⟩
instance [Preorder α] : IsRefl α (· ≥ ·) :=
IsRefl.swap _
instance [Preorder α] : IsTrans α (· ≤ ·) :=
⟨@le_trans _ _⟩
instance [Preorder α] : IsTrans α (· ≥ ·) :=
IsTrans.swap _
instance [Preorder α] : IsPreorder α (· ≤ ·) where
instance [Preorder α] : IsPreorder α (· ≥ ·) where
instance [Preorder α] : IsIrrefl α (· < ·) :=
⟨lt_irrefl⟩
instance [Preorder α] : IsIrrefl α (· > ·) :=
IsIrrefl.swap _
instance [Preorder α] : IsTrans α (· < ·) :=
⟨@lt_trans _ _⟩
instance [Preorder α] : IsTrans α (· > ·) :=
IsTrans.swap _
instance [Preorder α] : IsAsymm α (· < ·) :=
⟨@lt_asymm _ _⟩
instance [Preorder α] : IsAsymm α (· > ·) :=
IsAsymm.swap _
instance [Preorder α] : IsAntisymm α (· < ·) :=
IsAsymm.isAntisymm _
instance [Preorder α] : IsAntisymm α (· > ·) :=
IsAsymm.isAntisymm _
instance [Preorder α] : IsStrictOrder α (· < ·) where
instance [Preorder α] : IsStrictOrder α (· > ·) where
instance [Preorder α] : IsNonstrictStrictOrder α (· ≤ ·) (· < ·) :=
⟨@lt_iff_le_not_le _ _⟩
instance [PartialOrder α] : IsAntisymm α (· ≤ ·) :=
⟨@le_antisymm _ _⟩
instance [PartialOrder α] : IsAntisymm α (· ≥ ·) :=
IsAntisymm.swap _
instance [PartialOrder α] : IsPartialOrder α (· ≤ ·) where
instance [PartialOrder α] : IsPartialOrder α (· ≥ ·) where
instance LE.isTotal [LinearOrder α] : IsTotal α (· ≤ ·) :=
⟨le_total⟩
instance [LinearOrder α] : IsTotal α (· ≥ ·) :=
IsTotal.swap _
-- Porting note: this was `by infer_instance` before
instance [LinearOrder α] : IsTotalPreorder α (· ≤ ·) where
instance [LinearOrder α] : IsTotalPreorder α (· ≥ ·) where
instance [LinearOrder α] : IsLinearOrder α (· ≤ ·) where
instance [LinearOrder α] : IsLinearOrder α (· ≥ ·) where
instance [LinearOrder α] : IsTrichotomous α (· < ·) :=
⟨lt_trichotomy⟩
instance [LinearOrder α] : IsTrichotomous α (· > ·) :=
IsTrichotomous.swap _
instance [LinearOrder α] : IsTrichotomous α (· ≤ ·) :=
IsTotal.isTrichotomous _
instance [LinearOrder α] : IsTrichotomous α (· ≥ ·) :=
IsTotal.isTrichotomous _
instance [LinearOrder α] : IsStrictTotalOrder α (· < ·) where
instance [LinearOrder α] : IsOrderConnected α (· < ·) := by infer_instance
instance [LinearOrder α] : IsIncompTrans α (· < ·) := by infer_instance
instance [LinearOrder α] : IsStrictWeakOrder α (· < ·) := by infer_instance
theorem transitive_le [Preorder α] : Transitive (@LE.le α _) :=
transitive_of_trans _
theorem transitive_lt [Preorder α] : Transitive (@LT.lt α _) :=
transitive_of_trans _
theorem transitive_ge [Preorder α] : Transitive (@GE.ge α _) :=
transitive_of_trans _
theorem transitive_gt [Preorder α] : Transitive (@GT.gt α _) :=
transitive_of_trans _
instance OrderDual.isTotal_le [LE α] [h : IsTotal α (· ≤ ·)] : IsTotal αᵒᵈ (· ≤ ·) :=
@IsTotal.swap α _ h
instance : WellFoundedLT ℕ :=
⟨Nat.lt_wfRel.wf⟩
instance Nat.lt.isWellOrder : IsWellOrder ℕ (· < ·) where
instance [LinearOrder α] [h : IsWellOrder α (· < ·)] : IsWellOrder αᵒᵈ (· > ·) := h
instance [LinearOrder α] [h : IsWellOrder α (· > ·)] : IsWellOrder αᵒᵈ (· < ·) := h
|
Order\RelSeries.lean | /-
Copyright (c) 2023 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Fangming Li
-/
import Mathlib.Algebra.Ring.Int
import Mathlib.Data.List.Chain
import Mathlib.Data.List.OfFn
import Mathlib.Data.Rel
import Mathlib.Order.Fin.Basic
import Mathlib.Tactic.Abel
import Mathlib.Tactic.Linarith
/-!
# Series of a relation
If `r` is a relation on `α` then a relation series of length `n` is a series
`a_0, a_1, ..., a_n` such that `r a_i a_{i+1}` for all `i < n`
-/
variable {α : Type*} (r : Rel α α)
variable {β : Type*} (s : Rel β β)
/--
Let `r` be a relation on `α`, a relation series of `r` of length `n` is a series
`a_0, a_1, ..., a_n` such that `r a_i a_{i+1}` for all `i < n`
-/
structure RelSeries where
/-- The number of inequalities in the series -/
length : ℕ
/-- The underlying function of a relation series -/
toFun : Fin (length + 1) → α
/-- Adjacent elements are related -/
step : ∀ (i : Fin length), r (toFun (Fin.castSucc i)) (toFun i.succ)
namespace RelSeries
instance : CoeFun (RelSeries r) (fun x ↦ Fin (x.length + 1) → α) :=
{ coe := RelSeries.toFun }
/--
For any type `α`, each term of `α` gives a relation series with the right most index to be 0.
-/
@[simps!] def singleton (a : α) : RelSeries r where
length := 0
toFun _ := a
step := Fin.elim0
instance [IsEmpty α] : IsEmpty (RelSeries r) where
false x := IsEmpty.false (x 0)
instance [Inhabited α] : Inhabited (RelSeries r) where
default := singleton r default
instance [Nonempty α] : Nonempty (RelSeries r) :=
Nonempty.map (singleton r) inferInstance
variable {r}
@[ext (iff := false)]
lemma ext {x y : RelSeries r} (length_eq : x.length = y.length)
(toFun_eq : x.toFun = y.toFun ∘ Fin.cast (by rw [length_eq])) : x = y := by
rcases x with ⟨nx, fx⟩
dsimp only at length_eq toFun_eq
subst length_eq toFun_eq
rfl
lemma rel_of_lt [IsTrans α r] (x : RelSeries r) {i j : Fin (x.length + 1)} (h : i < j) :
r (x i) (x j) :=
(Fin.liftFun_iff_succ r).mpr x.step h
lemma rel_or_eq_of_le [IsTrans α r] (x : RelSeries r) {i j : Fin (x.length + 1)} (h : i ≤ j) :
r (x i) (x j) ∨ x i = x j :=
(Fin.lt_or_eq_of_le h).imp (x.rel_of_lt ·) (by rw [·])
/--
Given two relations `r, s` on `α` such that `r ≤ s`, any relation series of `r` induces a relation
series of `s`
-/
@[simps!]
def ofLE (x : RelSeries r) {s : Rel α α} (h : r ≤ s) : RelSeries s where
length := x.length
toFun := x
step _ := h _ _ <| x.step _
lemma coe_ofLE (x : RelSeries r) {s : Rel α α} (h : r ≤ s) :
(x.ofLE h : _ → _) = x := rfl
/-- Every relation series gives a list -/
def toList (x : RelSeries r) : List α := List.ofFn x
@[simp]
lemma length_toList (x : RelSeries r) : x.toList.length = x.length + 1 :=
List.length_ofFn _
lemma toList_chain' (x : RelSeries r) : x.toList.Chain' r := by
rw [List.chain'_iff_get]
intros i h
convert x.step ⟨i, by simpa [toList] using h⟩ <;> apply List.get_ofFn
lemma toList_ne_nil (x : RelSeries r) : x.toList ≠ [] := fun m =>
List.eq_nil_iff_forall_not_mem.mp m (x 0) <| (List.mem_ofFn _ _).mpr ⟨_, rfl⟩
/-- Every nonempty list satisfying the chain condition gives a relation series-/
@[simps]
def fromListChain' (x : List α) (x_ne_nil : x ≠ []) (hx : x.Chain' r) : RelSeries r where
length := x.length.pred
toFun := x.get ∘ Fin.cast (Nat.succ_pred_eq_of_pos <| List.length_pos.mpr x_ne_nil)
step i := List.chain'_iff_get.mp hx i i.2
/-- Relation series of `r` and nonempty list of `α` satisfying `r`-chain condition bijectively
corresponds to each other. -/
protected def Equiv : RelSeries r ≃ {x : List α | x ≠ [] ∧ x.Chain' r} where
toFun x := ⟨_, x.toList_ne_nil, x.toList_chain'⟩
invFun x := fromListChain' _ x.2.1 x.2.2
left_inv x := ext (by simp [toList]) <| by ext; apply List.get_ofFn
right_inv x := by
refine Subtype.ext (List.ext_get ?_ fun n hn1 _ => List.get_ofFn _ _)
have := Nat.succ_pred_eq_of_pos <| List.length_pos.mpr x.2.1
simp_all [toList]
lemma toList_injective : Function.Injective (RelSeries.toList (r := r)) :=
fun _ _ h ↦ (RelSeries.Equiv).injective <| Subtype.ext h
-- TODO : build a similar bijection between `RelSeries α` and `Quiver.Path`
end RelSeries
namespace Rel
/-- A relation `r` is said to be finite dimensional iff there is a relation series of `r` with the
maximum length. -/
class FiniteDimensional : Prop where
/-- A relation `r` is said to be finite dimensional iff there is a relation series of `r` with the
maximum length. -/
exists_longest_relSeries : ∃ x : RelSeries r, ∀ y : RelSeries r, y.length ≤ x.length
/-- A relation `r` is said to be infinite dimensional iff there exists relation series of arbitrary
length. -/
class InfiniteDimensional : Prop where
/-- A relation `r` is said to be infinite dimensional iff there exists relation series of
arbitrary length. -/
exists_relSeries_with_length : ∀ n : ℕ, ∃ x : RelSeries r, x.length = n
end Rel
namespace RelSeries
/-- The longest relational series when a relation is finite dimensional -/
protected noncomputable def longestOf [r.FiniteDimensional] : RelSeries r :=
Rel.FiniteDimensional.exists_longest_relSeries.choose
lemma length_le_length_longestOf [r.FiniteDimensional] (x : RelSeries r) :
x.length ≤ (RelSeries.longestOf r).length :=
Rel.FiniteDimensional.exists_longest_relSeries.choose_spec _
/-- A relation series with length `n` if the relation is infinite dimensional -/
protected noncomputable def withLength [r.InfiniteDimensional] (n : ℕ) : RelSeries r :=
(Rel.InfiniteDimensional.exists_relSeries_with_length n).choose
@[simp] lemma length_withLength [r.InfiniteDimensional] (n : ℕ) :
(RelSeries.withLength r n).length = n :=
(Rel.InfiniteDimensional.exists_relSeries_with_length n).choose_spec
section
variable {r} {s : RelSeries r} {x : α}
/-- If a relation on `α` is infinite dimensional, then `α` is nonempty. -/
lemma nonempty_of_infiniteDimensional [r.InfiniteDimensional] : Nonempty α :=
⟨RelSeries.withLength r 0 0⟩
instance membership : Membership α (RelSeries r) :=
⟨(· ∈ Set.range ·)⟩
theorem mem_def : x ∈ s ↔ x ∈ Set.range s := Iff.rfl
@[simp] theorem mem_toList : x ∈ s.toList ↔ x ∈ s := by
rw [RelSeries.toList, List.mem_ofFn, RelSeries.mem_def]
theorem subsingleton_of_length_eq_zero (hs : s.length = 0) : {x | x ∈ s}.Subsingleton := by
rintro - ⟨i, rfl⟩ - ⟨j, rfl⟩
congr!
exact finCongr (by rw [hs, zero_add]) |>.injective <| Subsingleton.elim (α := Fin 1) _ _
theorem length_ne_zero_of_nontrivial (h : {x | x ∈ s}.Nontrivial) : s.length ≠ 0 :=
fun hs ↦ h.not_subsingleton $ subsingleton_of_length_eq_zero hs
theorem length_pos_of_nontrivial (h : {x | x ∈ s}.Nontrivial) : 0 < s.length :=
Nat.pos_iff_ne_zero.mpr <| length_ne_zero_of_nontrivial h
theorem length_ne_zero (irrefl : Irreflexive r) : s.length ≠ 0 ↔ {x | x ∈ s}.Nontrivial := by
refine ⟨fun h ↦ ⟨s 0, by simp [mem_def], s 1, by simp [mem_def], fun rid ↦ irrefl (s 0) ?_⟩,
length_ne_zero_of_nontrivial⟩
nth_rw 2 [rid]
convert s.step ⟨0, by omega⟩
ext
simpa [Nat.pos_iff_ne_zero]
theorem length_pos (irrefl : Irreflexive r) : 0 < s.length ↔ {x | x ∈ s}.Nontrivial :=
Nat.pos_iff_ne_zero.trans <| length_ne_zero irrefl
lemma length_eq_zero (irrefl : Irreflexive r) : s.length = 0 ↔ {x | x ∈ s}.Subsingleton := by
rw [← not_ne_iff, length_ne_zero irrefl, Set.not_nontrivial_iff]
/-- Start of a series, i.e. for `a₀ -r→ a₁ -r→ ... -r→ aₙ`, its head is `a₀`.
Since a relation series is assumed to be non-empty, this is well defined. -/
def head (x : RelSeries r) : α := x 0
/-- End of a series, i.e. for `a₀ -r→ a₁ -r→ ... -r→ aₙ`, its last element is `aₙ`.
Since a relation series is assumed to be non-empty, this is well defined. -/
def last (x : RelSeries r) : α := x <| Fin.last _
lemma apply_last (x : RelSeries r) : x (Fin.last <| x.length) = x.last := rfl
lemma head_mem (x : RelSeries r) : x.head ∈ x := ⟨_, rfl⟩
lemma last_mem (x : RelSeries r) : x.last ∈ x := ⟨_, rfl⟩
@[simp]
lemma head_singleton {r : Rel α α} (x : α) : (singleton r x).head = x := by simp [singleton, head]
@[simp]
lemma last_singleton {r : Rel α α} (x : α) : (singleton r x).last = x := by simp [singleton, last]
end
variable {r s}
/--
If `a₀ -r→ a₁ -r→ ... -r→ aₙ` and `b₀ -r→ b₁ -r→ ... -r→ bₘ` are two strict series
such that `r aₙ b₀`, then there is a chain of length `n + m + 1` given by
`a₀ -r→ a₁ -r→ ... -r→ aₙ -r→ b₀ -r→ b₁ -r→ ... -r→ bₘ`.
-/
@[simps length]
def append (p q : RelSeries r) (connect : r p.last q.head) : RelSeries r where
length := p.length + q.length + 1
toFun := Fin.append p q ∘ Fin.cast (by abel)
step i := by
obtain hi | rfl | hi :=
lt_trichotomy i (Fin.castLE (by omega) (Fin.last _ : Fin (p.length + 1)))
· convert p.step ⟨i.1, hi⟩ <;> convert Fin.append_left p q _ <;> rfl
· convert connect
· convert Fin.append_left p q _
· convert Fin.append_right p q _; rfl
· set x := _; set y := _
change r (Fin.append p q x) (Fin.append p q y)
have hx : x = Fin.natAdd _ ⟨i - (p.length + 1), Nat.sub_lt_left_of_lt_add hi <|
i.2.trans <| by omega⟩ := by
ext; dsimp [x, y]; rw [Nat.add_sub_cancel']; exact hi
have hy : y = Fin.natAdd _ ⟨i - p.length, Nat.sub_lt_left_of_lt_add (le_of_lt hi)
(by exact i.2)⟩ := by
ext
dsimp
conv_rhs => rw [Nat.add_comm p.length 1, add_assoc,
Nat.add_sub_cancel' <| le_of_lt (show p.length < i.1 from hi), add_comm]
rfl
rw [hx, Fin.append_right, hy, Fin.append_right]
convert q.step ⟨i - (p.length + 1), Nat.sub_lt_left_of_lt_add hi <|
by convert i.2 using 1; abel⟩
rw [Fin.succ_mk, Nat.sub_eq_iff_eq_add (le_of_lt hi : p.length ≤ i),
Nat.add_assoc _ 1, add_comm 1, Nat.sub_add_cancel]
exact hi
lemma append_apply_left (p q : RelSeries r) (connect : r p.last q.head)
(i : Fin (p.length + 1)) :
p.append q connect ((i.castAdd (q.length + 1)).cast (by dsimp; abel)) = p i := by
delta append
simp only [Function.comp_apply]
convert Fin.append_left _ _ _
lemma append_apply_right (p q : RelSeries r) (connect : r p.last q.head)
(i : Fin (q.length + 1)) :
p.append q connect (i.natAdd p.length + 1) = q i := by
delta append
simp only [Fin.coe_natAdd, Nat.cast_add, Function.comp_apply]
convert Fin.append_right _ _ _
ext
simp only [Fin.coe_cast, Fin.coe_natAdd]
conv_rhs => rw [add_assoc, add_comm 1, ← add_assoc]
change _ % _ = _
simp only [Nat.add_mod_mod, Nat.mod_add_mod, Nat.one_mod, Nat.mod_succ_eq_iff_lt]
omega
@[simp] lemma head_append (p q : RelSeries r) (connect : r p.last q.head) :
(p.append q connect).head = p.head :=
append_apply_left p q connect 0
@[simp] lemma last_append (p q : RelSeries r) (connect : r p.last q.head) :
(p.append q connect).last = q.last := by
delta last
convert append_apply_right p q connect (Fin.last _)
ext
change _ = _ % _
simp only [append_length, Fin.val_last, Fin.natAdd_last, Nat.one_mod, Nat.mod_add_mod,
Nat.mod_succ]
/--
For two types `α, β` and relation on them `r, s`, if `f : α → β` preserves relation `r`, then an
`r`-series can be pushed out to an `s`-series by
`a₀ -r→ a₁ -r→ ... -r→ aₙ ↦ f a₀ -s→ f a₁ -s→ ... -s→ f aₙ`
-/
@[simps length]
def map (p : RelSeries r) (f : r →r s) : RelSeries s where
length := p.length
toFun := f.1.comp p
step := (f.2 <| p.step ·)
@[simp] lemma map_apply (p : RelSeries r) (f : r →r s) (i : Fin (p.length + 1)) :
p.map f i = f (p i) := rfl
@[simp] lemma head_map (p : RelSeries r) (f : r →r s) : (p.map f).head = f p.head := rfl
@[simp] lemma last_map (p : RelSeries r) (f : r →r s) : (p.map f).last = f p.last := rfl
/--
If `a₀ -r→ a₁ -r→ ... -r→ aₙ` is an `r`-series and `a` is such that
`aᵢ -r→ a -r→ a_ᵢ₊₁`, then
`a₀ -r→ a₁ -r→ ... -r→ aᵢ -r→ a -r→ aᵢ₊₁ -r→ ... -r→ aₙ`
is another `r`-series
-/
@[simps]
def insertNth (p : RelSeries r) (i : Fin p.length) (a : α)
(prev_connect : r (p (Fin.castSucc i)) a) (connect_next : r a (p i.succ)) : RelSeries r where
toFun := (Fin.castSucc i.succ).insertNth a p
step m := by
set x := _; set y := _; change r x y
obtain hm | hm | hm := lt_trichotomy m.1 i.1
· convert p.step ⟨m, hm.trans i.2⟩
· show Fin.insertNth _ _ _ _ = _
rw [Fin.insertNth_apply_below]
pick_goal 2
· exact hm.trans (lt_add_one _)
simp
· show Fin.insertNth _ _ _ _ = _
rw [Fin.insertNth_apply_below]
pick_goal 2
· change m.1 + 1 < i.1 + 1; rwa [add_lt_add_iff_right]
simp; rfl
· rw [show x = p m from show Fin.insertNth _ _ _ _ = _ by
rw [Fin.insertNth_apply_below]
pick_goal 2
· show m.1 < i.1 + 1; exact hm ▸ lt_add_one _
simp]
convert prev_connect
· ext; exact hm
· change Fin.insertNth _ _ _ _ = _
rw [show m.succ = i.succ.castSucc by ext; change _ + 1 = _ + 1; rw [hm],
Fin.insertNth_apply_same]
· rw [Nat.lt_iff_add_one_le, le_iff_lt_or_eq] at hm
obtain hm | hm := hm
· convert p.step ⟨m.1 - 1, Nat.sub_lt_right_of_lt_add (by omega) m.2⟩
· change Fin.insertNth _ _ _ _ = _
rw [Fin.insertNth_apply_above (h := hm)]
aesop
· change Fin.insertNth _ _ _ _ = _
rw [Fin.insertNth_apply_above]
swap
· exact hm.trans (lt_add_one _)
simp only [Fin.val_succ, Nat.zero_eq, Fin.pred_succ, eq_rec_constant, Fin.succ_mk]
congr
exact Fin.ext <| Eq.symm <| Nat.succ_pred_eq_of_pos (lt_trans (Nat.zero_lt_succ _) hm)
· convert connect_next
· change Fin.insertNth _ _ _ _ = _
rw [show m.castSucc = i.succ.castSucc from Fin.ext hm.symm, Fin.insertNth_apply_same]
· change Fin.insertNth _ _ _ _ = _
rw [Fin.insertNth_apply_above]
swap
· change i.1 + 1 < m.1 + 1; rw [hm]; exact lt_add_one _
simp only [Fin.pred_succ, eq_rec_constant]
congr; ext; exact hm.symm
/--
A relation series `a₀ -r→ a₁ -r→ ... -r→ aₙ` of `r` gives a relation series of the reverse of `r`
by reversing the series `aₙ ←r- aₙ₋₁ ←r- ... ←r- a₁ ←r- a₀`.
-/
@[simps length]
def reverse (p : RelSeries r) : RelSeries (fun (a b : α) ↦ r b a) where
length := p.length
toFun := p ∘ Fin.rev
step i := by
rw [Function.comp_apply, Function.comp_apply]
have hi : i.1 + 1 ≤ p.length := by omega
convert p.step ⟨p.length - (i.1 + 1), Nat.sub_lt_self (by omega) hi⟩
· ext; simp
· ext
simp only [Fin.val_rev, Fin.coe_castSucc, Nat.succ_sub_succ_eq_sub, Fin.val_succ]
rw [Nat.sub_eq_iff_eq_add, add_assoc, add_comm 1 i.1, Nat.sub_add_cancel] <;>
omega
@[simp] lemma reverse_apply (p : RelSeries r) (i : Fin (p.length + 1)) :
p.reverse i = p i.rev := rfl
@[simp] lemma last_reverse (p : RelSeries r) : p.reverse.last = p.head := by
simp [RelSeries.last, RelSeries.head]
@[simp] lemma head_reverse (p : RelSeries r) : p.reverse.head = p.last := by
simp [RelSeries.last, RelSeries.head]
/--
Given a series `a₀ -r→ a₁ -r→ ... -r→ aₙ` and an `a` such that `a₀ -r→ a` holds, there is
a series of length `n+1`: `a -r→ a₀ -r→ a₁ -r→ ... -r→ aₙ`.
-/
@[simps! length]
def cons (p : RelSeries r) (newHead : α) (rel : r newHead p.head) : RelSeries r :=
(singleton r newHead).append p rel
@[simp] lemma head_cons (p : RelSeries r) (newHead : α) (rel : r newHead p.head) :
(p.cons newHead rel).head = newHead := rfl
@[simp] lemma last_cons (p : RelSeries r) (newHead : α) (rel : r newHead p.head) :
(p.cons newHead rel).last = p.last := by
delta cons
rw [last_append]
/--
Given a series `a₀ -r→ a₁ -r→ ... -r→ aₙ` and an `a` such that `aₙ -r→ a` holds, there is
a series of length `n+1`: `a₀ -r→ a₁ -r→ ... -r→ aₙ -r→ a`.
-/
@[simps! length]
def snoc (p : RelSeries r) (newLast : α) (rel : r p.last newLast) : RelSeries r :=
p.append (singleton r newLast) rel
@[simp] lemma head_snoc (p : RelSeries r) (newLast : α) (rel : r p.last newLast) :
(p.snoc newLast rel).head = p.head := by
delta snoc; rw [head_append]
@[simp] lemma last_snoc (p : RelSeries r) (newLast : α) (rel : r p.last newLast) :
(p.snoc newLast rel).last = newLast := last_append _ _ _
-- This lemma is useful because `last_snoc` is about `Fin.last (p.snoc _ _).length`, but we often
-- see `Fin.last (p.length + 1)` in practice. They are equal by definition, but sometimes simplifier
-- does not pick up `last_snoc`
@[simp] lemma last_snoc' (p : RelSeries r) (newLast : α) (rel : r p.last newLast) :
p.snoc newLast rel (Fin.last (p.length + 1)) = newLast := last_append _ _ _
@[simp] lemma snoc_castSucc (s : RelSeries r) (a : α) (connect : r s.last a)
(i : Fin (s.length + 1)) : snoc s a connect (Fin.castSucc i) = s i :=
Fin.append_left _ _ i
lemma mem_snoc {p : RelSeries r} {newLast : α} {rel : r p.last newLast} {x : α} :
x ∈ p.snoc newLast rel ↔ x ∈ p ∨ x = newLast := by
simp only [snoc, append, singleton_length, Nat.add_zero, Nat.reduceAdd, Fin.cast_refl,
Function.comp_id, mem_def, id_eq, Set.mem_range]
constructor
· rintro ⟨i, rfl⟩
exact Fin.lastCases (Or.inr <| Fin.append_right _ _ 0) (fun i => Or.inl ⟨⟨i.1, i.2⟩,
(Fin.append_left _ _ _).symm⟩) i
· intro h
rcases h with (⟨i, rfl⟩ | rfl)
· exact ⟨i.castSucc, Fin.append_left _ _ _⟩
· exact ⟨Fin.last _, Fin.append_right _ _ 0⟩
/--
If a series `a₀ -r→ a₁ -r→ ...` has positive length, then `a₁ -r→ ...` is another series
-/
@[simps]
def tail (p : RelSeries r) (len_pos : p.length ≠ 0) : RelSeries r where
length := p.length - 1
toFun := Fin.tail p ∘ (Fin.cast <| Nat.succ_pred_eq_of_pos <| Nat.pos_of_ne_zero len_pos)
step i := p.step ⟨i.1 + 1, Nat.lt_pred_iff.mp i.2⟩
@[simp] lemma head_tail (p : RelSeries r) (len_pos : p.length ≠ 0) :
(p.tail len_pos).head = p 1 := by
show p (Fin.succ _) = p 1
congr
ext
show (1 : ℕ) = (1 : ℕ) % _
rw [Nat.mod_eq_of_lt]
simpa only [lt_add_iff_pos_left, Nat.pos_iff_ne_zero]
@[simp] lemma last_tail (p : RelSeries r) (len_pos : p.length ≠ 0) :
(p.tail len_pos).last = p.last := by
show p _ = p _
congr
ext
simp only [tail_length, Fin.val_succ, Fin.coe_cast, Fin.val_last]
exact Nat.succ_pred_eq_of_pos (by simpa [Nat.pos_iff_ne_zero] using len_pos)
/--
If a series ``a₀ -r→ a₁ -r→ ... -r→ aₙ``, then `a₀ -r→ a₁ -r→ ... -r→ aₙ₋₁` is
another series -/
@[simps]
def eraseLast (p : RelSeries r) : RelSeries r where
length := p.length - 1
toFun i := p ⟨i, lt_of_lt_of_le i.2 (Nat.succ_le_succ tsub_le_self)⟩
step i := p.step ⟨i, lt_of_lt_of_le i.2 tsub_le_self⟩
@[simp] lemma head_eraseLast (p : RelSeries r) : p.eraseLast.head = p.head := rfl
@[simp] lemma last_eraseLast (p : RelSeries r) :
p.eraseLast.last = p ⟨p.length.pred, Nat.lt_succ_iff.2 (Nat.pred_le _)⟩ := rfl
/--
Given two series of the form `a₀ -r→ ... -r→ X` and `X -r→ b ---> ...`,
then `a₀ -r→ ... -r→ X -r→ b ...` is another series obtained by combining the given two.
-/
@[simps]
def smash (p q : RelSeries r) (connect : p.last = q.head) : RelSeries r where
length := p.length + q.length
toFun i :=
if H : i.1 < p.length
then p ⟨i.1, H.trans (lt_add_one _)⟩
else q ⟨i.1 - p.length,
Nat.sub_lt_left_of_lt_add (by rwa [not_lt] at H) (by rw [← add_assoc]; exact i.2)⟩
step i := by
dsimp only
by_cases h₂ : i.1 + 1 < p.length
· have h₁ : i.1 < p.length := lt_trans (lt_add_one _) h₂
erw [dif_pos h₁, dif_pos h₂]
convert p.step ⟨i, h₁⟩ using 1
· erw [dif_neg h₂]
by_cases h₁ : i.1 < p.length
· erw [dif_pos h₁]
have h₃ : p.length = i.1 + 1 := by omega
convert p.step ⟨i, h₁⟩ using 1
convert connect.symm
· aesop
· congr; aesop
· erw [dif_neg h₁]
convert q.step ⟨i.1 - p.length, _⟩ using 1
· congr
change (i.1 + 1) - _ = _
rw [Nat.sub_add_comm]
rwa [not_lt] at h₁
· refine Nat.sub_lt_left_of_lt_add ?_ i.2
rwa [not_lt] at h₁
lemma smash_castAdd {p q : RelSeries r} (connect : p.last = q.head) (i : Fin p.length) :
p.smash q connect (Fin.castSucc <| i.castAdd q.length) = p (Fin.castSucc i) := by
unfold smash
dsimp
rw [dif_pos i.2]
rfl
lemma smash_succ_castAdd {p q : RelSeries r} (h : p.last = q.head)
(i : Fin p.length) : p.smash q h (i.castAdd q.length).succ = p i.succ := by
rw [smash_toFun]
split_ifs with H
· congr
· simp only [Fin.val_succ, Fin.coe_castAdd] at H
convert h.symm
· congr
simp only [Fin.val_succ, Fin.coe_castAdd, Nat.zero_mod, tsub_eq_zero_iff_le]
omega
· congr
ext
change i.1 + 1 = p.length
omega
lemma smash_natAdd {p q : RelSeries r} (h : p.last = q.head) (i : Fin q.length) :
smash p q h (Fin.castSucc <| i.natAdd p.length) = q (Fin.castSucc i) := by
rw [smash_toFun, dif_neg (by simp)]
congr
exact Nat.add_sub_self_left _ _
lemma smash_succ_natAdd {p q : RelSeries r} (h : p.last = q.head) (i : Fin q.length) :
smash p q h (i.natAdd p.length).succ = q i.succ := by
rw [smash_toFun]
split_ifs with H
· have H' : p.length < p.length + (i.1 + 1) := by omega
exact (lt_irrefl _ (H.trans H')).elim
· congr
simp only [Fin.val_succ, Fin.coe_natAdd]
rw [add_assoc, Nat.add_sub_cancel_left]
@[simp] lemma head_smash {p q : RelSeries r} (h : p.last = q.head) :
(smash p q h).head = p.head := by
delta head smash
simp only [Fin.val_zero, Fin.zero_eta, zero_le, tsub_eq_zero_of_le, dite_eq_ite,
ite_eq_left_iff, not_lt, nonpos_iff_eq_zero]
intro H; convert h.symm; congr; aesop
@[simp] lemma last_smash {p q : RelSeries r} (h : p.last = q.head) :
(smash p q h).last = q.last := by
delta smash last; aesop
/-- Given the series `a₀ -r→ … -r→ aᵢ -r→ … -r→ aₙ`, the series `a₀ -r→ … -r→ aᵢ`. -/
@[simps! length]
def take {r : Rel α α} (p : RelSeries r) (i : Fin (p.length + 1)) : RelSeries r where
length := i
toFun := fun ⟨j, h⟩ => p.toFun ⟨j, by omega⟩
step := fun ⟨j, h⟩ => p.step ⟨j, by omega⟩
@[simp]
lemma head_take (p : RelSeries r) (i : Fin (p.length + 1)) :
(p.take i).head = p.head := by simp [take, head]
@[simp]
lemma last_take (p : RelSeries r) (i : Fin (p.length + 1)) :
(p.take i).last = p i := by simp [take, last, Fin.last]
/-- Given the series `a₀ -r→ … -r→ aᵢ -r→ … -r→ aₙ`, the series `aᵢ₊₁ -r→ … -r→ aᵢ`. -/
@[simps! length]
def drop (p : RelSeries r) (i : Fin (p.length + 1)) : RelSeries r where
length := p.length - i
toFun := fun ⟨j, h⟩ => p.toFun ⟨j+i, by omega⟩
step := fun ⟨j, h⟩ => by
convert p.step ⟨j+i.1, by omega⟩
simp only [Nat.succ_eq_add_one, Fin.succ_mk]; omega
@[simp]
lemma head_drop (p : RelSeries r) (i : Fin (p.length + 1)) : (p.drop i).head = p.toFun i := by
simp [drop, head]
@[simp]
lemma last_drop (p : RelSeries r) (i : Fin (p.length + 1)) : (p.drop i).last = p.last := by
simp only [last, drop, Fin.last]
congr
omega
end RelSeries
/-- A type is finite dimensional if its `LTSeries` has bounded length. -/
abbrev FiniteDimensionalOrder (γ : Type*) [Preorder γ] :=
Rel.FiniteDimensional ((· < ·) : γ → γ → Prop)
instance FiniteDimensionalOrder.ofUnique (γ : Type*) [Preorder γ] [Unique γ] :
FiniteDimensionalOrder γ where
exists_longest_relSeries := ⟨.singleton _ default, fun x ↦ by
by_contra! r
exact (ne_of_lt <| x.step ⟨0, by omega⟩) <| Subsingleton.elim _ _⟩
/-- A type is infinite dimensional if it has `LTSeries` of at least arbitrary length -/
abbrev InfiniteDimensionalOrder (γ : Type*) [Preorder γ] :=
Rel.InfiniteDimensional ((· < ·) : γ → γ → Prop)
section LTSeries
variable (α) [Preorder α] [Preorder β]
/--
If `α` is a preorder, a LTSeries is a relation series of the less than relation.
-/
abbrev LTSeries := RelSeries ((· < ·) : Rel α α)
namespace LTSeries
/-- The longest `<`-series when a type is finite dimensional -/
protected noncomputable def longestOf [FiniteDimensionalOrder α] : LTSeries α :=
RelSeries.longestOf _
/-- A `<`-series with length `n` if the relation is infinite dimensional -/
protected noncomputable def withLength [InfiniteDimensionalOrder α] (n : ℕ) : LTSeries α :=
RelSeries.withLength _ n
@[simp] lemma length_withLength [InfiniteDimensionalOrder α] (n : ℕ) :
(LTSeries.withLength α n).length = n :=
RelSeries.length_withLength _ _
/-- if `α` is infinite dimensional, then `α` is nonempty. -/
lemma nonempty_of_infiniteDimensionalType [InfiniteDimensionalOrder α] : Nonempty α :=
⟨LTSeries.withLength α 0 0⟩
variable {α}
lemma longestOf_is_longest [FiniteDimensionalOrder α] (x : LTSeries α) :
x.length ≤ (LTSeries.longestOf α).length :=
RelSeries.length_le_length_longestOf _ _
lemma longestOf_len_unique [FiniteDimensionalOrder α] (p : LTSeries α)
(is_longest : ∀ (q : LTSeries α), q.length ≤ p.length) :
p.length = (LTSeries.longestOf α).length :=
le_antisymm (longestOf_is_longest _) (is_longest _)
lemma strictMono (x : LTSeries α) : StrictMono x :=
fun _ _ h => x.rel_of_lt h
lemma monotone (x : LTSeries α) : Monotone x :=
x.strictMono.monotone
/-- An alternative constructor of `LTSeries` from a strictly monotone function. -/
@[simps]
def mk (length : ℕ) (toFun : Fin (length + 1) → α) (strictMono : StrictMono toFun) :
LTSeries α where
toFun := toFun
step i := strictMono <| lt_add_one i.1
/--
For two preorders `α, β`, if `f : α → β` is strictly monotonic, then a strict chain of `α`
can be pushed out to a strict chain of `β` by
`a₀ < a₁ < ... < aₙ ↦ f a₀ < f a₁ < ... < f aₙ`
-/
@[simps!]
def map (p : LTSeries α) (f : α → β) (hf : StrictMono f) : LTSeries β :=
LTSeries.mk p.length (f.comp p) (hf.comp p.strictMono)
@[simp] lemma head_map (p : LTSeries α) (f : α → β) (hf : StrictMono f) :
(p.map f hf).head = f p.head := rfl
@[simp] lemma last_map (p : LTSeries α) (f : α → β) (hf : StrictMono f) :
(p.map f hf).last = f p.last := rfl
/--
For two preorders `α, β`, if `f : α → β` is surjective and strictly comonotonic, then a
strict series of `β` can be pulled back to a strict chain of `α` by
`b₀ < b₁ < ... < bₙ ↦ f⁻¹ b₀ < f⁻¹ b₁ < ... < f⁻¹ bₙ` where `f⁻¹ bᵢ` is an arbitrary element in the
preimage of `f⁻¹ {bᵢ}`.
-/
@[simps!]
noncomputable def comap (p : LTSeries β) (f : α → β)
(comap : ∀ ⦃x y⦄, f x < f y → x < y)
(surjective : Function.Surjective f) :
LTSeries α := mk p.length (fun i ↦ (surjective (p i)).choose)
(fun i j h ↦ comap (by simpa only [(surjective _).choose_spec] using p.strictMono h))
end LTSeries
end LTSeries
/-- If `f : α → β` is a strictly monotonic function and `α` is an infinite dimensional type then so
is `β`. -/
lemma infiniteDimensionalOrder_of_strictMono [Preorder α] [Preorder β]
(f : α → β) (hf : StrictMono f) [InfiniteDimensionalOrder α] :
InfiniteDimensionalOrder β :=
⟨fun n ↦ ⟨(LTSeries.withLength _ n).map f hf, LTSeries.length_withLength α n⟩⟩
|
Order\SemiconjSup.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Algebra.Group.Units.Equiv
import Mathlib.Logic.Function.Conjugate
import Mathlib.Order.Bounds.OrderIso
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.OrdContinuous
import Mathlib.Order.RelIso.Group
/-!
# Semiconjugate by `sSup`
In this file we prove two facts about semiconjugate (families of) functions.
First, if an order isomorphism `fa : α → α` is semiconjugate to an order embedding `fb : β → β` by
`g : α → β`, then `fb` is semiconjugate to `fa` by `y ↦ sSup {x | g x ≤ y}`, see
`Semiconj.symm_adjoint`.
Second, consider two actions `f₁ f₂ : G → α → α` of a group on a complete lattice by order
isomorphisms. Then the map `x ↦ ⨆ g : G, (f₁ g)⁻¹ (f₂ g x)` semiconjugates each `f₁ g'` to `f₂ g'`,
see `Function.sSup_div_semiconj`. In the case of a conditionally complete lattice, a similar
statement holds true under an additional assumption that each set `{(f₁ g)⁻¹ (f₂ g x) | g : G}` is
bounded above, see `Function.csSup_div_semiconj`.
The lemmas come from [Étienne Ghys, Groupes d'homéomorphismes du cercle et cohomologie
bornée][ghys87:groupes], Proposition 2.1 and 5.4 respectively. In the paper they are formulated for
homeomorphisms of the circle, so in order to apply results from this file one has to lift these
homeomorphisms to the real line first.
-/
variable {α β γ : Type*}
open Set
/-- We say that `g : β → α` is an order right adjoint function for `f : α → β` if it sends each `y`
to a least upper bound for `{x | f x ≤ y}`. If `α` is a partial order, and `f : α → β` has
a right adjoint, then this right adjoint is unique. -/
def IsOrderRightAdjoint [Preorder α] [Preorder β] (f : α → β) (g : β → α) :=
∀ y, IsLUB { x | f x ≤ y } (g y)
theorem isOrderRightAdjoint_sSup [CompleteLattice α] [Preorder β] (f : α → β) :
IsOrderRightAdjoint f fun y => sSup { x | f x ≤ y } := fun _ => isLUB_sSup _
theorem isOrderRightAdjoint_csSup [ConditionallyCompleteLattice α] [Preorder β] (f : α → β)
(hne : ∀ y, ∃ x, f x ≤ y) (hbdd : ∀ y, BddAbove { x | f x ≤ y }) :
IsOrderRightAdjoint f fun y => sSup { x | f x ≤ y } := fun y => isLUB_csSup (hne y) (hbdd y)
namespace IsOrderRightAdjoint
protected theorem unique [PartialOrder α] [Preorder β] {f : α → β} {g₁ g₂ : β → α}
(h₁ : IsOrderRightAdjoint f g₁) (h₂ : IsOrderRightAdjoint f g₂) : g₁ = g₂ :=
funext fun y => (h₁ y).unique (h₂ y)
theorem right_mono [Preorder α] [Preorder β] {f : α → β} {g : β → α} (h : IsOrderRightAdjoint f g) :
Monotone g := fun y₁ y₂ hy => ((h y₁).mono (h y₂)) fun _ hx => le_trans hx hy
theorem orderIso_comp [Preorder α] [Preorder β] [Preorder γ] {f : α → β} {g : β → α}
(h : IsOrderRightAdjoint f g) (e : β ≃o γ) : IsOrderRightAdjoint (e ∘ f) (g ∘ e.symm) :=
fun y => by simpa [e.le_symm_apply] using h (e.symm y)
theorem comp_orderIso [Preorder α] [Preorder β] [Preorder γ] {f : α → β} {g : β → α}
(h : IsOrderRightAdjoint f g) (e : γ ≃o α) : IsOrderRightAdjoint (f ∘ e) (e.symm ∘ g) := by
intro y
change IsLUB (e ⁻¹' { x | f x ≤ y }) (e.symm (g y))
rw [e.isLUB_preimage, e.apply_symm_apply]
exact h y
end IsOrderRightAdjoint
namespace Function
/-- If an order automorphism `fa` is semiconjugate to an order embedding `fb` by a function `g`
and `g'` is an order right adjoint of `g` (i.e. `g' y = sSup {x | f x ≤ y}`), then `fb` is
semiconjugate to `fa` by `g'`.
This is a version of Proposition 2.1 from [Étienne Ghys, Groupes d'homéomorphismes du cercle et
cohomologie bornée][ghys87:groupes]. -/
theorem Semiconj.symm_adjoint [PartialOrder α] [Preorder β] {fa : α ≃o α} {fb : β ↪o β} {g : α → β}
(h : Function.Semiconj g fa fb) {g' : β → α} (hg' : IsOrderRightAdjoint g g') :
Function.Semiconj g' fb fa := by
refine fun y => (hg' _).unique ?_
rw [← fa.surjective.image_preimage { x | g x ≤ fb y }, preimage_setOf_eq]
simp only [h.eq, fb.le_iff_le, fa.leftOrdContinuous (hg' _)]
variable {G : Type*}
theorem semiconj_of_isLUB [PartialOrder α] [Group G] (f₁ f₂ : G →* α ≃o α) {h : α → α}
(H : ∀ x, IsLUB (range fun g' => (f₁ g')⁻¹ (f₂ g' x)) (h x)) (g : G) :
Function.Semiconj h (f₂ g) (f₁ g) := by
refine fun y => (H _).unique ?_
have := (f₁ g).leftOrdContinuous (H y)
rw [← range_comp, ← (Equiv.mulRight g).surjective.range_comp _] at this
simpa [(· ∘ ·)] using this
/-- Consider two actions `f₁ f₂ : G → α → α` of a group on a complete lattice by order
isomorphisms. Then the map `x ↦ ⨆ g : G, (f₁ g)⁻¹ (f₂ g x)` semiconjugates each `f₁ g'` to `f₂ g'`.
This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homéomorphismes du cercle et
cohomologie bornée][ghys87:groupes]. -/
theorem sSup_div_semiconj [CompleteLattice α] [Group G] (f₁ f₂ : G →* α ≃o α) (g : G) :
Function.Semiconj (fun x => ⨆ g' : G, (f₁ g')⁻¹ (f₂ g' x)) (f₂ g) (f₁ g) :=
semiconj_of_isLUB f₁ f₂ (fun _ => isLUB_iSup) _
/-- Consider two actions `f₁ f₂ : G → α → α` of a group on a conditionally complete lattice by order
isomorphisms. Suppose that each set $s(x)=\{f_1(g)^{-1} (f_2(g)(x)) | g \in G\}$ is bounded above.
Then the map `x ↦ sSup s(x)` semiconjugates each `f₁ g'` to `f₂ g'`.
This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homéomorphismes du cercle et
cohomologie bornée][ghys87:groupes]. -/
theorem csSup_div_semiconj [ConditionallyCompleteLattice α] [Group G] (f₁ f₂ : G →* α ≃o α)
(hbdd : ∀ x, BddAbove (range fun g => (f₁ g)⁻¹ (f₂ g x))) (g : G) :
Function.Semiconj (fun x => ⨆ g' : G, (f₁ g')⁻¹ (f₂ g' x)) (f₂ g) (f₁ g) :=
semiconj_of_isLUB f₁ f₂ (fun x => isLUB_csSup (range_nonempty _) (hbdd x)) _
-- Guard against import creep
assert_not_exists Finset
end Function
|
Order\SetNotation.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Yury Kudryashov
-/
import Mathlib.Data.Set.Defs
import Mathlib.Mathport.Notation
/-!
# Notation classes for set supremum and infimum
In this file we introduce notation for indexed suprema, infima, unions, and intersections.
## Main definitions
- `SupSet α`: typeclass introducing the operation `SupSet.sSup` (exported to the root namespace);
`sSup s` is the supremum of the set `s`;
- `InfSet`: similar typeclass for infimum of a set;
- `iSup f`, `iInf f`: supremum and infimum of an indexed family of elements,
defined as `sSup (Set.range f)` and `sInf (Set.range f)`, respectively;
- `Set.sUnion s`, `Set.sInter s`: same as `sSup s` and `sInf s`,
but works only for sets of sets;
- `Set.iUnion s`, `Set.iInter s`: same as `iSup s` and `iInf s`,
but works only for indexed families of sets.
## Notation
- `⨆ i, f i`, `⨅ i, f i`: supremum and infimum of an indexed family, respectively;
- `⋃₀ s`, `⋂₀ s`: union and intersection of a set of sets;
- `⋃ i, s i`, `⋂ i, s i`: union and intersection of an indexed family of sets.
-/
open Set
universe u v
variable {α : Type u} {ι : Sort v}
/-- Class for the `sSup` operator -/
class SupSet (α : Type*) where
/-- Supremum of a set -/
sSup : Set α → α
/-- Class for the `sInf` operator -/
class InfSet (α : Type*) where
/-- Infimum of a set -/
sInf : Set α → α
export SupSet (sSup)
export InfSet (sInf)
/-- Indexed supremum -/
def iSup [SupSet α] (s : ι → α) : α :=
sSup (range s)
/-- Indexed infimum -/
def iInf [InfSet α] (s : ι → α) : α :=
sInf (range s)
instance (priority := 50) infSet_to_nonempty (α) [InfSet α] : Nonempty α :=
⟨sInf ∅⟩
instance (priority := 50) supSet_to_nonempty (α) [SupSet α] : Nonempty α :=
⟨sSup ∅⟩
/-
Porting note: the code below could replace the `notation3` command
open Batteries.ExtendedBinder in
syntax "⨆ " extBinder ", " term:51 : term
macro_rules
| `(⨆ $x:ident, $p) => `(iSup fun $x:ident ↦ $p)
| `(⨆ $x:ident : $t, $p) => `(iSup fun $x:ident : $t ↦ $p)
| `(⨆ $x:ident $b:binderPred, $p) =>
`(iSup fun $x:ident ↦ satisfies_binder_pred% $x $b ∧ $p) -/
/-- Indexed supremum. -/
notation3 "⨆ "(...)", "r:60:(scoped f => iSup f) => r
/-- Indexed infimum. -/
notation3 "⨅ "(...)", "r:60:(scoped f => iInf f) => r
section delaborators
open Lean Lean.PrettyPrinter.Delaborator
/-- Delaborator for indexed supremum. -/
@[delab app.iSup]
def iSup_delab : Delab := whenPPOption Lean.getPPNotation <| withOverApp 4 do
let #[_, ι, _, f] := (← SubExpr.getExpr).getAppArgs | failure
unless f.isLambda do failure
let prop ← Meta.isProp ι
let dep := f.bindingBody!.hasLooseBVar 0
let ppTypes ← getPPOption getPPFunBinderTypes
let stx ← SubExpr.withAppArg do
let dom ← SubExpr.withBindingDomain delab
withBindingBodyUnusedName fun x => do
let x : TSyntax `ident := .mk x
let body ← delab
if prop && !dep then
`(⨆ (_ : $dom), $body)
else if prop || ppTypes then
`(⨆ ($x:ident : $dom), $body)
else
`(⨆ $x:ident, $body)
-- Cute binders
let stx : Term ←
match stx with
| `(⨆ $x:ident, ⨆ (_ : $y:ident ∈ $s), $body)
| `(⨆ ($x:ident : $_), ⨆ (_ : $y:ident ∈ $s), $body) =>
if x == y then `(⨆ $x:ident ∈ $s, $body) else pure stx
| _ => pure stx
return stx
/-- Delaborator for indexed infimum. -/
@[delab app.iInf]
def iInf_delab : Delab := whenPPOption Lean.getPPNotation <| withOverApp 4 do
let #[_, ι, _, f] := (← SubExpr.getExpr).getAppArgs | failure
unless f.isLambda do failure
let prop ← Meta.isProp ι
let dep := f.bindingBody!.hasLooseBVar 0
let ppTypes ← getPPOption getPPFunBinderTypes
let stx ← SubExpr.withAppArg do
let dom ← SubExpr.withBindingDomain delab
withBindingBodyUnusedName fun x => do
let x : TSyntax `ident := .mk x
let body ← delab
if prop && !dep then
`(⨅ (_ : $dom), $body)
else if prop || ppTypes then
`(⨅ ($x:ident : $dom), $body)
else
`(⨅ $x:ident, $body)
-- Cute binders
let stx : Term ←
match stx with
| `(⨅ $x:ident, ⨅ (_ : $y:ident ∈ $s), $body)
| `(⨅ ($x:ident : $_), ⨅ (_ : $y:ident ∈ $s), $body) =>
if x == y then `(⨅ $x:ident ∈ $s, $body) else pure stx
| _ => pure stx
return stx
end delaborators
namespace Set
instance : InfSet (Set α) :=
⟨fun s => { a | ∀ t ∈ s, a ∈ t }⟩
instance : SupSet (Set α) :=
⟨fun s => { a | ∃ t ∈ s, a ∈ t }⟩
/-- Intersection of a set of sets. -/
def sInter (S : Set (Set α)) : Set α :=
sInf S
/-- Notation for `Set.sInter` Intersection of a set of sets. -/
prefix:110 "⋂₀ " => sInter
/-- Union of a set of sets. -/
def sUnion (S : Set (Set α)) : Set α :=
sSup S
/-- Notation for `Set.sUnion`. Union of a set of sets. -/
prefix:110 "⋃₀ " => sUnion
@[simp]
theorem mem_sInter {x : α} {S : Set (Set α)} : x ∈ ⋂₀ S ↔ ∀ t ∈ S, x ∈ t :=
Iff.rfl
@[simp]
theorem mem_sUnion {x : α} {S : Set (Set α)} : x ∈ ⋃₀ S ↔ ∃ t ∈ S, x ∈ t :=
Iff.rfl
/-- Indexed union of a family of sets -/
def iUnion (s : ι → Set α) : Set α :=
iSup s
/-- Indexed intersection of a family of sets -/
def iInter (s : ι → Set α) : Set α :=
iInf s
/-- Notation for `Set.iUnion`. Indexed union of a family of sets -/
notation3 "⋃ "(...)", "r:60:(scoped f => iUnion f) => r
/-- Notation for `Set.iInter`. Indexed intersection of a family of sets -/
notation3 "⋂ "(...)", "r:60:(scoped f => iInter f) => r
section delaborators
open Lean Lean.PrettyPrinter.Delaborator
/-- Delaborator for indexed unions. -/
@[delab app.Set.iUnion]
def iUnion_delab : Delab := whenPPOption Lean.getPPNotation do
let #[_, ι, f] := (← SubExpr.getExpr).getAppArgs | failure
unless f.isLambda do failure
let prop ← Meta.isProp ι
let dep := f.bindingBody!.hasLooseBVar 0
let ppTypes ← getPPOption getPPFunBinderTypes
let stx ← SubExpr.withAppArg do
let dom ← SubExpr.withBindingDomain delab
withBindingBodyUnusedName fun x => do
let x : TSyntax `ident := .mk x
let body ← delab
if prop && !dep then
`(⋃ (_ : $dom), $body)
else if prop || ppTypes then
`(⋃ ($x:ident : $dom), $body)
else
`(⋃ $x:ident, $body)
-- Cute binders
let stx : Term ←
match stx with
| `(⋃ $x:ident, ⋃ (_ : $y:ident ∈ $s), $body)
| `(⋃ ($x:ident : $_), ⋃ (_ : $y:ident ∈ $s), $body) =>
if x == y then `(⋃ $x:ident ∈ $s, $body) else pure stx
| _ => pure stx
return stx
/-- Delaborator for indexed intersections. -/
@[delab app.Set.iInter]
def sInter_delab : Delab := whenPPOption Lean.getPPNotation do
let #[_, ι, f] := (← SubExpr.getExpr).getAppArgs | failure
unless f.isLambda do failure
let prop ← Meta.isProp ι
let dep := f.bindingBody!.hasLooseBVar 0
let ppTypes ← getPPOption getPPFunBinderTypes
let stx ← SubExpr.withAppArg do
let dom ← SubExpr.withBindingDomain delab
withBindingBodyUnusedName fun x => do
let x : TSyntax `ident := .mk x
let body ← delab
if prop && !dep then
`(⋂ (_ : $dom), $body)
else if prop || ppTypes then
`(⋂ ($x:ident : $dom), $body)
else
`(⋂ $x:ident, $body)
-- Cute binders
let stx : Term ←
match stx with
| `(⋂ $x:ident, ⋂ (_ : $y:ident ∈ $s), $body)
| `(⋂ ($x:ident : $_), ⋂ (_ : $y:ident ∈ $s), $body) =>
if x == y then `(⋂ $x:ident ∈ $s, $body) else pure stx
| _ => pure stx
return stx
end delaborators
@[simp]
theorem mem_iUnion {x : α} {s : ι → Set α} : (x ∈ ⋃ i, s i) ↔ ∃ i, x ∈ s i :=
⟨fun ⟨_, ⟨⟨a, (t_eq : s a = _)⟩, (h : x ∈ _)⟩⟩ => ⟨a, t_eq.symm ▸ h⟩, fun ⟨a, h⟩ =>
⟨s a, ⟨⟨a, rfl⟩, h⟩⟩⟩
@[simp]
theorem mem_iInter {x : α} {s : ι → Set α} : (x ∈ ⋂ i, s i) ↔ ∀ i, x ∈ s i :=
⟨fun (h : ∀ a ∈ { a : Set α | ∃ i, s i = a }, x ∈ a) a => h (s a) ⟨a, rfl⟩,
fun h _ ⟨a, (eq : s a = _)⟩ => eq ▸ h a⟩
@[simp]
theorem sSup_eq_sUnion (S : Set (Set α)) : sSup S = ⋃₀S :=
rfl
@[simp]
theorem sInf_eq_sInter (S : Set (Set α)) : sInf S = ⋂₀ S :=
rfl
@[simp]
theorem iSup_eq_iUnion (s : ι → Set α) : iSup s = iUnion s :=
rfl
@[simp]
theorem iInf_eq_iInter (s : ι → Set α) : iInf s = iInter s :=
rfl
end Set
|
Order\Sublattice.lean | /-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.SupClosed
/-!
# Sublattices
This file defines sublattices.
## TODO
Subsemilattices, if people care about them.
## Tags
sublattice
-/
open Function Set
variable {ι : Sort*} (α β γ : Type*) [Lattice α] [Lattice β] [Lattice γ]
/-- A sublattice of a lattice is a set containing the suprema and infima of any of its elements. -/
structure Sublattice where
/-- The underlying set of a sublattice. **Do not use directly**. Instead, use the coercion
`Sublattice α → Set α`, which Lean should automatically insert for you in most cases. -/
carrier : Set α
supClosed' : SupClosed carrier
infClosed' : InfClosed carrier
variable {α β γ}
namespace Sublattice
variable {L M : Sublattice α} {f : LatticeHom α β} {s t : Set α} {a : α}
initialize_simps_projections Sublattice (carrier → coe)
instance instSetLike : SetLike (Sublattice α) α where
coe L := L.carrier
coe_injective' L M h := by cases L; congr
/-- Turn a set closed under supremum and infimum into a sublattice. -/
abbrev ofIsSublattice (s : Set α) (hs : IsSublattice s) : Sublattice α := ⟨s, hs.1, hs.2⟩
lemma coe_inj : (L : Set α) = M ↔ L = M := SetLike.coe_set_eq
@[simp] lemma supClosed (L : Sublattice α) : SupClosed (L : Set α) := L.supClosed'
@[simp] lemma infClosed (L : Sublattice α) : InfClosed (L : Set α) := L.infClosed'
@[simp] lemma isSublattice (L : Sublattice α) : IsSublattice (L : Set α) :=
⟨L.supClosed, L.infClosed⟩
@[simp] lemma mem_carrier : a ∈ L.carrier ↔ a ∈ L := Iff.rfl
@[simp] lemma mem_mk (h_sup h_inf) : a ∈ mk s h_sup h_inf ↔ a ∈ s := Iff.rfl
@[simp, norm_cast] lemma coe_mk (h_sup h_inf) : mk s h_sup h_inf = s := rfl
@[simp] lemma mk_le_mk (hs_sup hs_inf ht_sup ht_inf) :
mk s hs_sup hs_inf ≤ mk t ht_sup ht_inf ↔ s ⊆ t := Iff.rfl
@[simp] lemma mk_lt_mk (hs_sup hs_inf ht_sup ht_inf) :
mk s hs_sup hs_inf < mk t ht_sup ht_inf ↔ s ⊂ t := Iff.rfl
/-- Copy of a sublattice with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (L : Sublattice α) (s : Set α) (hs : s = L) : Sublattice α where
carrier := s
supClosed' := hs.symm ▸ L.supClosed'
infClosed' := hs.symm ▸ L.infClosed'
@[simp, norm_cast] lemma coe_copy (L : Sublattice α) (s : Set α) (hs) : L.copy s hs = s := rfl
lemma copy_eq (L : Sublattice α) (s : Set α) (hs) : L.copy s hs = L := SetLike.coe_injective hs
/-- Two sublattices are equal if they have the same elements. -/
lemma ext : (∀ a, a ∈ L ↔ a ∈ M) → L = M := SetLike.ext
/-- A sublattice of a lattice inherits a supremum. -/
instance instSupCoe : Sup L where
sup a b := ⟨a ⊔ b, L.supClosed a.2 b.2⟩
/-- A sublattice of a lattice inherits an infimum. -/
instance instInfCoe : Inf L where
inf a b := ⟨a ⊓ b, L.infClosed a.2 b.2⟩
@[simp, norm_cast] lemma coe_sup (a b : L) : a ⊔ b = (a : α) ⊔ b := rfl
@[simp, norm_cast] lemma coe_inf (a b : L) : a ⊓ b = (a : α) ⊓ b := rfl
@[simp] lemma mk_sup_mk (a b : α) (ha hb) : (⟨a, ha⟩ ⊔ ⟨b, hb⟩ : L) = ⟨a ⊔ b, L.supClosed ha hb⟩ :=
rfl
@[simp] lemma mk_inf_mk (a b : α) (ha hb) : (⟨a, ha⟩ ⊓ ⟨b, hb⟩ : L) = ⟨a ⊓ b, L.infClosed ha hb⟩ :=
rfl
/-- A sublattice of a lattice inherits a lattice structure. -/
instance instLatticeCoe (L : Sublattice α) : Lattice L :=
Subtype.coe_injective.lattice _ (fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
/-- A sublattice of a distributive lattice inherits a distributive lattice structure. -/
instance instDistribLatticeCoe {α : Type*} [DistribLattice α] (L : Sublattice α) :
DistribLattice L :=
Subtype.coe_injective.distribLattice _ (fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
/-- The natural lattice hom from a sublattice to the original lattice. -/
def subtype (L : Sublattice α) : LatticeHom L α where
toFun := ((↑) : L → α)
map_sup' _ _ := rfl
map_inf' _ _ := rfl
@[simp, norm_cast] lemma coe_subtype (L : Sublattice α) : L.subtype = ((↑) : L → α) := rfl
lemma subtype_apply (L : Sublattice α) (a : L) : L.subtype a = a := rfl
lemma subtype_injective (L : Sublattice α) : Injective <| subtype L := Subtype.coe_injective
/-- The inclusion homomorphism from a sublattice `L` to a bigger sublattice `M`. -/
def inclusion (h : L ≤ M) : LatticeHom L M where
toFun := Set.inclusion h
map_sup' _ _ := rfl
map_inf' _ _ := rfl
@[simp] lemma coe_inclusion (h : L ≤ M) : inclusion h = Set.inclusion h := rfl
lemma inclusion_apply (h : L ≤ M) (a : L) : inclusion h a = Set.inclusion h a := rfl
lemma inclusion_injective (h : L ≤ M) : Injective <| inclusion h := Set.inclusion_injective h
@[simp] lemma inclusion_rfl (L : Sublattice α) : inclusion le_rfl = LatticeHom.id L := rfl
@[simp] lemma subtype_comp_inclusion (h : L ≤ M) : M.subtype.comp (inclusion h) = L.subtype := rfl
/-- The maximum sublattice of a lattice. -/
instance instTop : Top (Sublattice α) where
top.carrier := univ
top.supClosed' := supClosed_univ
top.infClosed' := infClosed_univ
/-- The empty sublattice of a lattice. -/
instance instBot : Bot (Sublattice α) where
bot.carrier := ∅
bot.supClosed' := supClosed_empty
bot.infClosed' := infClosed_empty
/-- The inf of two sublattices is their intersection. -/
instance instInf : Inf (Sublattice α) where
inf L M := { carrier := L ∩ M
supClosed' := L.supClosed.inter M.supClosed
infClosed' := L.infClosed.inter M.infClosed }
/-- The inf of sublattices is their intersection. -/
instance instInfSet : InfSet (Sublattice α) where
sInf S := { carrier := ⨅ L ∈ S, L
supClosed' := supClosed_sInter <| forall_mem_range.2 fun L ↦ supClosed_sInter <|
forall_mem_range.2 fun _ ↦ L.supClosed
infClosed' := infClosed_sInter <| forall_mem_range.2 fun L ↦ infClosed_sInter <|
forall_mem_range.2 fun _ ↦ L.infClosed }
instance instInhabited : Inhabited (Sublattice α) := ⟨⊥⟩
/-- The top sublattice is isomorphic to the lattice.
This is the sublattice version of `Equiv.Set.univ α`. -/
def topEquiv : (⊤ : Sublattice α) ≃o α where
toEquiv := Equiv.Set.univ _
map_rel_iff' := Iff.rfl
@[simp, norm_cast] lemma coe_top : (⊤ : Sublattice α) = (univ : Set α) := rfl
@[simp, norm_cast] lemma coe_bot : (⊥ : Sublattice α) = (∅ : Set α) := rfl
@[simp, norm_cast] lemma coe_inf' (L M : Sublattice α) : L ⊓ M = (L : Set α) ∩ M := rfl
@[simp, norm_cast] lemma coe_sInf (S : Set (Sublattice α)) : sInf S = ⋂ L ∈ S, (L : Set α) := rfl
@[simp, norm_cast] lemma coe_iInf (f : ι → Sublattice α) : ⨅ i, f i = ⋂ i, (f i : Set α) := by
simp [iInf]
@[simp, norm_cast] lemma coe_eq_univ : L = (univ : Set α) ↔ L = ⊤ := by rw [← coe_top, coe_inj]
@[simp, norm_cast] lemma coe_eq_empty : L = (∅ : Set α) ↔ L = ⊥ := by rw [← coe_bot, coe_inj]
@[simp] lemma not_mem_bot (a : α) : a ∉ (⊥ : Sublattice α) := id
@[simp] lemma mem_top (a : α) : a ∈ (⊤ : Sublattice α) := mem_univ _
@[simp] lemma mem_inf : a ∈ L ⊓ M ↔ a ∈ L ∧ a ∈ M := Iff.rfl
@[simp] lemma mem_sInf {S : Set (Sublattice α)} : a ∈ sInf S ↔ ∀ L ∈ S, a ∈ L := by
rw [← SetLike.mem_coe]; simp
@[simp] lemma mem_iInf {f : ι → Sublattice α} : a ∈ ⨅ i, f i ↔ ∀ i, a ∈ f i := by
rw [← SetLike.mem_coe]; simp
/-- Sublattices of a lattice form a complete lattice. -/
instance instCompleteLattice : CompleteLattice (Sublattice α) where
bot := ⊥
bot_le := fun _S _a ↦ False.elim
top := ⊤
le_top := fun _S a _ha ↦ mem_top a
inf := (· ⊓ ·)
le_inf := fun _L _M _N hM hN _a ha ↦ ⟨hM ha, hN ha⟩
inf_le_left := fun _L _M _a ↦ And.left
inf_le_right := fun _L _M _a ↦ And.right
__ := completeLatticeOfInf (Sublattice α)
fun _s ↦ IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf
lemma subsingleton_iff : Subsingleton (Sublattice α) ↔ IsEmpty α :=
⟨fun _ ↦ univ_eq_empty_iff.1 <| coe_inj.2 <| Subsingleton.elim ⊤ ⊥,
fun _ ↦ SetLike.coe_injective.subsingleton⟩
instance [IsEmpty α] : Unique (Sublattice α) where
uniq _ := @Subsingleton.elim _ (subsingleton_iff.2 ‹_›) _ _
/-- The preimage of a sublattice along a lattice homomorphism. -/
def comap (f : LatticeHom α β) (L : Sublattice β) : Sublattice α where
carrier := f ⁻¹' L
supClosed' := L.supClosed.preimage _
infClosed' := L.infClosed.preimage _
@[simp, norm_cast] lemma coe_comap (L : Sublattice β) (f : LatticeHom α β) : L.comap f = f ⁻¹' L :=
rfl
@[simp] lemma mem_comap {L : Sublattice β} : a ∈ L.comap f ↔ f a ∈ L := Iff.rfl
lemma comap_mono : Monotone (comap f) := fun _ _ ↦ preimage_mono
@[simp] lemma comap_id (L : Sublattice α) : L.comap (LatticeHom.id _) = L := rfl
@[simp] lemma comap_comap (L : Sublattice γ) (g : LatticeHom β γ) (f : LatticeHom α β) :
(L.comap g).comap f = L.comap (g.comp f) := rfl
/-- The image of a sublattice along a monoid homomorphism is a sublattice. -/
def map (f : LatticeHom α β) (L : Sublattice α) : Sublattice β where
carrier := f '' L
supClosed' := L.supClosed.image f
infClosed' := L.infClosed.image f
@[simp] lemma coe_map (f : LatticeHom α β) (L : Sublattice α) : (L.map f : Set β) = f '' L := rfl
@[simp] lemma mem_map {b : β} : b ∈ L.map f ↔ ∃ a ∈ L, f a = b := Iff.rfl
lemma mem_map_of_mem (f : LatticeHom α β) {a : α} : a ∈ L → f a ∈ L.map f := mem_image_of_mem f
lemma apply_coe_mem_map (f : LatticeHom α β) (a : L) : f a ∈ L.map f := mem_map_of_mem f a.prop
lemma map_mono : Monotone (map f) := fun _ _ ↦ image_subset _
@[simp] lemma map_id : L.map (LatticeHom.id α) = L := SetLike.coe_injective <| image_id _
@[simp] lemma map_map (g : LatticeHom β γ) (f : LatticeHom α β) :
(L.map f).map g = L.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _
lemma mem_map_equiv {f : α ≃o β} {a : β} : a ∈ L.map f ↔ f.symm a ∈ L := Set.mem_image_equiv
lemma apply_mem_map_iff (hf : Injective f) : f a ∈ L.map f ↔ a ∈ L := hf.mem_set_image
lemma map_equiv_eq_comap_symm (f : α ≃o β) (L : Sublattice α) :
L.map f = L.comap (f.symm : LatticeHom β α) :=
SetLike.coe_injective <| f.toEquiv.image_eq_preimage L
lemma comap_equiv_eq_map_symm (f : β ≃o α) (L : Sublattice α) :
L.comap f = L.map (f.symm : LatticeHom α β) := (map_equiv_eq_comap_symm f.symm L).symm
lemma map_symm_eq_iff_eq_map {M : Sublattice β} {e : β ≃o α} :
L.map ↑e.symm = M ↔ L = M.map ↑e := by
simp_rw [← coe_inj]; exact (Equiv.eq_image_iff_symm_image_eq _ _ _).symm
lemma map_le_iff_le_comap {f : LatticeHom α β} {M : Sublattice β} : L.map f ≤ M ↔ L ≤ M.comap f :=
image_subset_iff
lemma gc_map_comap (f : LatticeHom α β) : GaloisConnection (map f) (comap f) :=
fun _ _ ↦ map_le_iff_le_comap
@[simp] lemma map_bot (f : LatticeHom α β) : (⊥ : Sublattice α).map f = ⊥ := (gc_map_comap f).l_bot
lemma map_sup (f : LatticeHom α β) (L M : Sublattice α) : (L ⊔ M).map f = L.map f ⊔ M.map f :=
(gc_map_comap f).l_sup
lemma map_iSup (f : LatticeHom α β) (L : ι → Sublattice α) : (⨆ i, L i).map f = ⨆ i, (L i).map f :=
(gc_map_comap f).l_iSup
@[simp] lemma comap_top (f : LatticeHom α β) : (⊤ : Sublattice β).comap f = ⊤ :=
(gc_map_comap f).u_top
lemma comap_inf (L M : Sublattice β) (f : LatticeHom α β) :
(L ⊓ M).comap f = L.comap f ⊓ M.comap f := (gc_map_comap f).u_inf
lemma comap_iInf (f : LatticeHom α β) (s : ι → Sublattice β) :
(iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf
lemma map_inf_le (L M : Sublattice α) (f : LatticeHom α β) : map f (L ⊓ M) ≤ map f L ⊓ map f M :=
map_mono.map_inf_le _ _
lemma le_comap_sup (L M : Sublattice β) (f : LatticeHom α β) :
comap f L ⊔ comap f M ≤ comap f (L ⊔ M) := comap_mono.le_map_sup _ _
lemma le_comap_iSup (f : LatticeHom α β) (L : ι → Sublattice β) :
⨆ i, (L i).comap f ≤ (⨆ i, L i).comap f := comap_mono.le_map_iSup
lemma map_inf (L M : Sublattice α) (f : LatticeHom α β) (hf : Injective f) :
map f (L ⊓ M) = map f L ⊓ map f M := by
rw [← SetLike.coe_set_eq]
simp [Set.image_inter hf]
lemma map_top (f : LatticeHom α β) (h : Surjective f) : Sublattice.map f ⊤ = ⊤ :=
SetLike.coe_injective <| by simp [h.range_eq]
end Sublattice
|
Order\SupClosed.lean | /-
Copyright (c) 2023 Yaël Dillies, Christopher Hoskin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Christopher Hoskin
-/
import Mathlib.Data.Finset.Lattice
import Mathlib.Data.Set.Finite
import Mathlib.Order.Closure
import Mathlib.Order.UpperLower.Basic
/-!
# Sets closed under join/meet
This file defines predicates for sets closed under `⊔` and shows that each set in a join-semilattice
generates a join-closed set and that a semilattice where every directed set has a least upper bound
is automatically complete. All dually for `⊓`.
## Main declarations
* `SupClosed`: Predicate for a set to be closed under join (`a ∈ s` and `b ∈ s` imply `a ⊔ b ∈ s`).
* `InfClosed`: Predicate for a set to be closed under meet (`a ∈ s` and `b ∈ s` imply `a ⊓ b ∈ s`).
* `IsSublattice`: Predicate for a set to be closed under meet and join.
* `supClosure`: Sup-closure. Smallest sup-closed set containing a given set.
* `infClosure`: Inf-closure. Smallest inf-closed set containing a given set.
* `latticeClosure`: Smallest sublattice containing a given set.
* `SemilatticeSup.toCompleteSemilatticeSup`: A join-semilattice where every sup-closed set has a
least upper bound is automatically complete.
* `SemilatticeInf.toCompleteSemilatticeInf`: A meet-semilattice where every inf-closed set has a
greatest lower bound is automatically complete.
-/
variable {F α β : Type*}
section SemilatticeSup
variable [SemilatticeSup α] [SemilatticeSup β]
section Set
variable {ι : Sort*} {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α}
open Set
/-- A set `s` is *sup-closed* if `a ⊔ b ∈ s` for all `a ∈ s`, `b ∈ s`. -/
def SupClosed (s : Set α) : Prop := ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → a ⊔ b ∈ s
@[simp] lemma supClosed_empty : SupClosed (∅ : Set α) := by simp [SupClosed]
@[simp] lemma supClosed_singleton : SupClosed ({a} : Set α) := by simp [SupClosed]
@[simp] lemma supClosed_univ : SupClosed (univ : Set α) := by simp [SupClosed]
lemma SupClosed.inter (hs : SupClosed s) (ht : SupClosed t) : SupClosed (s ∩ t) :=
fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩
lemma supClosed_sInter (hS : ∀ s ∈ S, SupClosed s) : SupClosed (⋂₀ S) :=
fun _a ha _b hb _s hs ↦ hS _ hs (ha _ hs) (hb _ hs)
lemma supClosed_iInter (hf : ∀ i, SupClosed (f i)) : SupClosed (⋂ i, f i) :=
supClosed_sInter <| forall_mem_range.2 hf
lemma SupClosed.directedOn (hs : SupClosed s) : DirectedOn (· ≤ ·) s :=
fun _a ha _b hb ↦ ⟨_, hs ha hb, le_sup_left, le_sup_right⟩
lemma IsUpperSet.supClosed (hs : IsUpperSet s) : SupClosed s := fun _a _ _b ↦ hs le_sup_right
lemma SupClosed.preimage [FunLike F β α] [SupHomClass F β α] (hs : SupClosed s) (f : F) :
SupClosed (f ⁻¹' s) :=
fun a ha b hb ↦ by simpa [map_sup] using hs ha hb
lemma SupClosed.image [FunLike F α β] [SupHomClass F α β] (hs : SupClosed s) (f : F) :
SupClosed (f '' s) := by
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩
rw [← map_sup]
exact Set.mem_image_of_mem _ <| hs ha hb
lemma supClosed_range [FunLike F α β] [SupHomClass F α β] (f : F) : SupClosed (Set.range f) := by
simpa using supClosed_univ.image f
lemma SupClosed.prod {t : Set β} (hs : SupClosed s) (ht : SupClosed t) : SupClosed (s ×ˢ t) :=
fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩
lemma supClosed_pi {ι : Type*} {α : ι → Type*} [∀ i, SemilatticeSup (α i)] {s : Set ι}
{t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, SupClosed (t i)) : SupClosed (s.pi t) :=
fun _a ha _b hb _i hi ↦ ht _ hi (ha _ hi) (hb _ hi)
end Set
section Finset
variable {ι : Type*} {f : ι → α} {s : Set α} {t : Finset ι} {a : α}
open Finset
lemma SupClosed.finsetSup'_mem (hs : SupClosed s) (ht : t.Nonempty) :
(∀ i ∈ t, f i ∈ s) → t.sup' ht f ∈ s :=
sup'_induction _ _ hs
lemma SupClosed.finsetSup_mem [OrderBot α] (hs : SupClosed s) (ht : t.Nonempty) :
(∀ i ∈ t, f i ∈ s) → t.sup f ∈ s :=
sup'_eq_sup ht f ▸ hs.finsetSup'_mem ht
end Finset
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] [SemilatticeInf β]
section Set
variable {ι : Sort*} {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α}
open Set
/-- A set `s` is *inf-closed* if `a ⊓ b ∈ s` for all `a ∈ s`, `b ∈ s`. -/
def InfClosed (s : Set α) : Prop := ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → a ⊓ b ∈ s
@[simp] lemma infClosed_empty : InfClosed (∅ : Set α) := by simp [InfClosed]
@[simp] lemma infClosed_singleton : InfClosed ({a} : Set α) := by simp [InfClosed]
@[simp] lemma infClosed_univ : InfClosed (univ : Set α) := by simp [InfClosed]
lemma InfClosed.inter (hs : InfClosed s) (ht : InfClosed t) : InfClosed (s ∩ t) :=
fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩
lemma infClosed_sInter (hS : ∀ s ∈ S, InfClosed s) : InfClosed (⋂₀ S) :=
fun _a ha _b hb _s hs ↦ hS _ hs (ha _ hs) (hb _ hs)
lemma infClosed_iInter (hf : ∀ i, InfClosed (f i)) : InfClosed (⋂ i, f i) :=
infClosed_sInter <| forall_mem_range.2 hf
lemma InfClosed.codirectedOn (hs : InfClosed s) : DirectedOn (· ≥ ·) s :=
fun _a ha _b hb ↦ ⟨_, hs ha hb, inf_le_left, inf_le_right⟩
lemma IsLowerSet.infClosed (hs : IsLowerSet s) : InfClosed s := fun _a _ _b ↦ hs inf_le_right
lemma InfClosed.preimage [FunLike F β α] [InfHomClass F β α] (hs : InfClosed s) (f : F) :
InfClosed (f ⁻¹' s) :=
fun a ha b hb ↦ by simpa [map_inf] using hs ha hb
lemma InfClosed.image [FunLike F α β] [InfHomClass F α β] (hs : InfClosed s) (f : F) :
InfClosed (f '' s) := by
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩
rw [← map_inf]
exact Set.mem_image_of_mem _ <| hs ha hb
lemma infClosed_range [FunLike F α β] [InfHomClass F α β] (f : F) : InfClosed (Set.range f) := by
simpa using infClosed_univ.image f
lemma InfClosed.prod {t : Set β} (hs : InfClosed s) (ht : InfClosed t) : InfClosed (s ×ˢ t) :=
fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩
lemma infClosed_pi {ι : Type*} {α : ι → Type*} [∀ i, SemilatticeInf (α i)] {s : Set ι}
{t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, InfClosed (t i)) : InfClosed (s.pi t) :=
fun _a ha _b hb _i hi ↦ ht _ hi (ha _ hi) (hb _ hi)
end Set
section Finset
variable {ι : Type*} {f : ι → α} {s : Set α} {t : Finset ι} {a : α}
open Finset
lemma InfClosed.finsetInf'_mem (hs : InfClosed s) (ht : t.Nonempty) :
(∀ i ∈ t, f i ∈ s) → t.inf' ht f ∈ s :=
inf'_induction _ _ hs
lemma InfClosed.finsetInf_mem [OrderTop α] (hs : InfClosed s) (ht : t.Nonempty) :
(∀ i ∈ t, f i ∈ s) → t.inf f ∈ s :=
inf'_eq_inf ht f ▸ hs.finsetInf'_mem ht
end Finset
end SemilatticeInf
open Finset OrderDual
section Lattice
variable {ι : Sort*} [Lattice α] [Lattice β] {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α}
open Set
/-- A set `s` is a *sublattice* if `a ⊔ b ∈ s` and `a ⊓ b ∈ s` for all `a ∈ s`, `b ∈ s`.
Note: This is not the preferred way to declare a sublattice. One should instead use `Sublattice`.
TODO: Define `Sublattice`. -/
structure IsSublattice (s : Set α) : Prop where
supClosed : SupClosed s
infClosed : InfClosed s
@[simp] lemma isSublattice_empty : IsSublattice (∅ : Set α) := ⟨supClosed_empty, infClosed_empty⟩
@[simp] lemma isSublattice_singleton : IsSublattice ({a} : Set α) :=
⟨supClosed_singleton, infClosed_singleton⟩
@[simp] lemma isSublattice_univ : IsSublattice (Set.univ : Set α) :=
⟨supClosed_univ, infClosed_univ⟩
lemma IsSublattice.inter (hs : IsSublattice s) (ht : IsSublattice t) : IsSublattice (s ∩ t) :=
⟨hs.1.inter ht.1, hs.2.inter ht.2⟩
lemma isSublattice_sInter (hS : ∀ s ∈ S, IsSublattice s) : IsSublattice (⋂₀ S) :=
⟨supClosed_sInter fun _s hs ↦ (hS _ hs).1, infClosed_sInter fun _s hs ↦ (hS _ hs).2⟩
lemma isSublattice_iInter (hf : ∀ i, IsSublattice (f i)) : IsSublattice (⋂ i, f i) :=
⟨supClosed_iInter fun _i ↦ (hf _).1, infClosed_iInter fun _i ↦ (hf _).2⟩
lemma IsSublattice.preimage [FunLike F β α] [LatticeHomClass F β α]
(hs : IsSublattice s) (f : F) :
IsSublattice (f ⁻¹' s) := ⟨hs.1.preimage _, hs.2.preimage _⟩
lemma IsSublattice.image [FunLike F α β] [LatticeHomClass F α β] (hs : IsSublattice s) (f : F) :
IsSublattice (f '' s) := ⟨hs.1.image _, hs.2.image _⟩
lemma IsSublattice_range [FunLike F α β] [LatticeHomClass F α β] (f : F) :
IsSublattice (Set.range f) :=
⟨supClosed_range _, infClosed_range _⟩
lemma IsSublattice.prod {t : Set β} (hs : IsSublattice s) (ht : IsSublattice t) :
IsSublattice (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩
lemma isSublattice_pi {ι : Type*} {α : ι → Type*} [∀ i, Lattice (α i)] {s : Set ι}
{t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, IsSublattice (t i)) : IsSublattice (s.pi t) :=
⟨supClosed_pi fun _i hi ↦ (ht _ hi).1, infClosed_pi fun _i hi ↦ (ht _ hi).2⟩
@[simp] lemma supClosed_preimage_toDual {s : Set αᵒᵈ} :
SupClosed (toDual ⁻¹' s) ↔ InfClosed s := Iff.rfl
@[simp] lemma infClosed_preimage_toDual {s : Set αᵒᵈ} :
InfClosed (toDual ⁻¹' s) ↔ SupClosed s := Iff.rfl
@[simp] lemma supClosed_preimage_ofDual {s : Set α} :
SupClosed (ofDual ⁻¹' s) ↔ InfClosed s := Iff.rfl
@[simp] lemma infClosed_preimage_ofDual {s : Set α} :
InfClosed (ofDual ⁻¹' s) ↔ SupClosed s := Iff.rfl
@[simp] lemma isSublattice_preimage_toDual {s : Set αᵒᵈ} :
IsSublattice (toDual ⁻¹' s) ↔ IsSublattice s := ⟨fun h ↦ ⟨h.2, h.1⟩, fun h ↦ ⟨h.2, h.1⟩⟩
@[simp] lemma isSublattice_preimage_ofDual :
IsSublattice (ofDual ⁻¹' s) ↔ IsSublattice s := ⟨fun h ↦ ⟨h.2, h.1⟩, fun h ↦ ⟨h.2, h.1⟩⟩
alias ⟨_, InfClosed.dual⟩ := supClosed_preimage_ofDual
alias ⟨_, SupClosed.dual⟩ := infClosed_preimage_ofDual
alias ⟨_, IsSublattice.dual⟩ := isSublattice_preimage_ofDual
alias ⟨_, IsSublattice.of_dual⟩ := isSublattice_preimage_toDual
end Lattice
section LinearOrder
variable [LinearOrder α]
@[simp] protected lemma LinearOrder.supClosed (s : Set α) : SupClosed s :=
fun a ha b hb ↦ by cases le_total a b <;> simp [*]
@[simp] protected lemma LinearOrder.infClosed (s : Set α) : InfClosed s :=
fun a ha b hb ↦ by cases le_total a b <;> simp [*]
@[simp] protected lemma LinearOrder.isSublattice (s : Set α) : IsSublattice s :=
⟨LinearOrder.supClosed _, LinearOrder.infClosed _⟩
end LinearOrder
/-! ## Closure -/
open Finset
section SemilatticeSup
variable [SemilatticeSup α] [SemilatticeSup β] {s t : Set α} {a b : α}
/-- Every set in a join-semilattice generates a set closed under join. -/
@[simps! isClosed]
def supClosure : ClosureOperator (Set α) := .ofPred
(fun s ↦ {a | ∃ (t : Finset α) (ht : t.Nonempty), ↑t ⊆ s ∧ t.sup' ht id = a})
SupClosed
(fun s a ha ↦ ⟨{a}, singleton_nonempty _, by simpa⟩)
(by
classical
rintro s _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩
refine ⟨_, ht.mono subset_union_left, ?_, sup'_union ht hu _⟩
rw [coe_union]
exact Set.union_subset hts hus)
(by rintro s₁ s₂ hs h₂ _ ⟨t, ht, hts, rfl⟩; exact h₂.finsetSup'_mem ht fun i hi ↦ hs <| hts hi)
@[simp] lemma subset_supClosure {s : Set α} : s ⊆ supClosure s := supClosure.le_closure _
@[simp] lemma supClosed_supClosure : SupClosed (supClosure s) := supClosure.isClosed_closure _
lemma supClosure_mono : Monotone (supClosure : Set α → Set α) := supClosure.monotone
@[simp] lemma supClosure_eq_self : supClosure s = s ↔ SupClosed s := supClosure.isClosed_iff.symm
alias ⟨_, SupClosed.supClosure_eq⟩ := supClosure_eq_self
lemma supClosure_idem (s : Set α) : supClosure (supClosure s) = supClosure s :=
supClosure.idempotent _
@[simp] lemma supClosure_empty : supClosure (∅ : Set α) = ∅ := by simp
@[simp] lemma supClosure_singleton : supClosure {a} = {a} := by simp
@[simp] lemma supClosure_univ : supClosure (Set.univ : Set α) = Set.univ := by simp
@[simp] lemma upperBounds_supClosure (s : Set α) : upperBounds (supClosure s) = upperBounds s :=
(upperBounds_mono_set subset_supClosure).antisymm <| by
rintro a ha _ ⟨t, ht, hts, rfl⟩
exact sup'_le _ _ fun b hb ↦ ha <| hts hb
@[simp] lemma isLUB_supClosure : IsLUB (supClosure s) a ↔ IsLUB s a := by simp [IsLUB]
lemma sup_mem_supClosure (ha : a ∈ s) (hb : b ∈ s) : a ⊔ b ∈ supClosure s :=
supClosed_supClosure (subset_supClosure ha) (subset_supClosure hb)
lemma finsetSup'_mem_supClosure {ι : Type*} {t : Finset ι} (ht : t.Nonempty) {f : ι → α}
(hf : ∀ i ∈ t, f i ∈ s) : t.sup' ht f ∈ supClosure s :=
supClosed_supClosure.finsetSup'_mem _ fun _i hi ↦ subset_supClosure <| hf _ hi
lemma supClosure_min : s ⊆ t → SupClosed t → supClosure s ⊆ t := supClosure.closure_min
/-- The semilatice generated by a finite set is finite. -/
protected lemma Set.Finite.supClosure (hs : s.Finite) : (supClosure s).Finite := by
lift s to Finset α using hs
classical
refine ((s.powerset.filter Finset.Nonempty).attach.image
fun t ↦ t.1.sup' (mem_filter.1 t.2).2 id).finite_toSet.subset ?_
rintro _ ⟨t, ht, hts, rfl⟩
simp only [id_eq, coe_image, mem_image, mem_coe, mem_attach, true_and, Subtype.exists,
Finset.mem_powerset, Finset.not_nonempty_iff_eq_empty, mem_filter]
exact ⟨t, ⟨hts, ht⟩, rfl⟩
@[simp] lemma supClosure_prod (s : Set α) (t : Set β) :
supClosure (s ×ˢ t) = supClosure s ×ˢ supClosure t :=
le_antisymm (supClosure_min (Set.prod_mono subset_supClosure subset_supClosure) $
supClosed_supClosure.prod supClosed_supClosure) $ by
rintro ⟨_, _⟩ ⟨⟨u, hu, hus, rfl⟩, v, hv, hvt, rfl⟩
refine ⟨u ×ˢ v, hu.product hv, ?_, ?_⟩
· simpa only [coe_product] using Set.prod_mono hus hvt
· simp [prodMk_sup'_sup']
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] [SemilatticeInf β] {s t : Set α} {a b : α}
/-- Every set in a join-semilattice generates a set closed under join. -/
@[simps! isClosed]
def infClosure : ClosureOperator (Set α) := ClosureOperator.ofPred
(fun s ↦ {a | ∃ (t : Finset α) (ht : t.Nonempty), ↑t ⊆ s ∧ t.inf' ht id = a})
InfClosed
(fun s a ha ↦ ⟨{a}, singleton_nonempty _, by simpa⟩)
(by
classical
rintro s _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩
refine ⟨_, ht.mono subset_union_left, ?_, inf'_union ht hu _⟩
rw [coe_union]
exact Set.union_subset hts hus)
(by rintro s₁ s₂ hs h₂ _ ⟨t, ht, hts, rfl⟩; exact h₂.finsetInf'_mem ht fun i hi ↦ hs <| hts hi)
@[simp] lemma subset_infClosure {s : Set α} : s ⊆ infClosure s := infClosure.le_closure _
@[simp] lemma infClosed_infClosure : InfClosed (infClosure s) := infClosure.isClosed_closure _
lemma infClosure_mono : Monotone (infClosure : Set α → Set α) := infClosure.monotone
@[simp] lemma infClosure_eq_self : infClosure s = s ↔ InfClosed s := infClosure.isClosed_iff.symm
alias ⟨_, InfClosed.infClosure_eq⟩ := infClosure_eq_self
lemma infClosure_idem (s : Set α) : infClosure (infClosure s) = infClosure s :=
infClosure.idempotent _
@[simp] lemma infClosure_empty : infClosure (∅ : Set α) = ∅ := by simp
@[simp] lemma infClosure_singleton : infClosure {a} = {a} := by simp
@[simp] lemma infClosure_univ : infClosure (Set.univ : Set α) = Set.univ := by simp
@[simp] lemma lowerBounds_infClosure (s : Set α) : lowerBounds (infClosure s) = lowerBounds s :=
(lowerBounds_mono_set subset_infClosure).antisymm <| by
rintro a ha _ ⟨t, ht, hts, rfl⟩
exact le_inf' _ _ fun b hb ↦ ha <| hts hb
@[simp] lemma isGLB_infClosure : IsGLB (infClosure s) a ↔ IsGLB s a := by simp [IsGLB]
lemma inf_mem_infClosure (ha : a ∈ s) (hb : b ∈ s) : a ⊓ b ∈ infClosure s :=
infClosed_infClosure (subset_infClosure ha) (subset_infClosure hb)
lemma finsetInf'_mem_infClosure {ι : Type*} {t : Finset ι} (ht : t.Nonempty) {f : ι → α}
(hf : ∀ i ∈ t, f i ∈ s) : t.inf' ht f ∈ infClosure s :=
infClosed_infClosure.finsetInf'_mem _ fun _i hi ↦ subset_infClosure <| hf _ hi
lemma infClosure_min : s ⊆ t → InfClosed t → infClosure s ⊆ t := infClosure.closure_min
/-- The semilatice generated by a finite set is finite. -/
protected lemma Set.Finite.infClosure (hs : s.Finite) : (infClosure s).Finite := by
lift s to Finset α using hs
classical
refine ((s.powerset.filter Finset.Nonempty).attach.image
fun t ↦ t.1.inf' (mem_filter.1 t.2).2 id).finite_toSet.subset ?_
rintro _ ⟨t, ht, hts, rfl⟩
simp only [id_eq, coe_image, mem_image, mem_coe, mem_attach, true_and, Subtype.exists,
Finset.mem_powerset, Finset.not_nonempty_iff_eq_empty, mem_filter]
exact ⟨t, ⟨hts, ht⟩, rfl⟩
@[simp] lemma infClosure_prod (s : Set α) (t : Set β) :
infClosure (s ×ˢ t) = infClosure s ×ˢ infClosure t :=
le_antisymm (infClosure_min (Set.prod_mono subset_infClosure subset_infClosure) $
infClosed_infClosure.prod infClosed_infClosure) $ by
rintro ⟨_, _⟩ ⟨⟨u, hu, hus, rfl⟩, v, hv, hvt, rfl⟩
refine ⟨u ×ˢ v, hu.product hv, ?_, ?_⟩
· simpa only [coe_product] using Set.prod_mono hus hvt
· simp [prodMk_inf'_inf']
end SemilatticeInf
section Lattice
variable [Lattice α] {s t : Set α}
/-- Every set in a join-semilattice generates a set closed under join. -/
@[simps! isClosed]
def latticeClosure : ClosureOperator (Set α) :=
.ofCompletePred IsSublattice fun _ ↦ isSublattice_sInter
@[simp] lemma subset_latticeClosure : s ⊆ latticeClosure s := latticeClosure.le_closure _
@[simp] lemma isSublattice_latticeClosure : IsSublattice (latticeClosure s) :=
latticeClosure.isClosed_closure _
lemma latticeClosure_min : s ⊆ t → IsSublattice t → latticeClosure s ⊆ t :=
latticeClosure.closure_min
lemma latticeClosure_mono : Monotone (latticeClosure : Set α → Set α) := latticeClosure.monotone
@[simp] lemma latticeClosure_eq_self : latticeClosure s = s ↔ IsSublattice s :=
latticeClosure.isClosed_iff.symm
alias ⟨_, IsSublattice.latticeClosure_eq⟩ := latticeClosure_eq_self
lemma latticeClosure_idem (s : Set α) : latticeClosure (latticeClosure s) = latticeClosure s :=
latticeClosure.idempotent _
@[simp] lemma latticeClosure_empty : latticeClosure (∅ : Set α) = ∅ := by simp
@[simp] lemma latticeClosure_singleton (a : α) : latticeClosure {a} = {a} := by simp
@[simp] lemma latticeClosure_univ : latticeClosure (Set.univ : Set α) = Set.univ := by simp
end Lattice
section DistribLattice
variable [DistribLattice α] [DistribLattice β] {s : Set α}
open Finset
protected lemma SupClosed.infClosure (hs : SupClosed s) : SupClosed (infClosure s) := by
rintro _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩
rw [inf'_sup_inf']
exact finsetInf'_mem_infClosure _
fun i hi ↦ hs (hts (mem_product.1 hi).1) (hus (mem_product.1 hi).2)
protected lemma InfClosed.supClosure (hs : InfClosed s) : InfClosed (supClosure s) := by
rintro _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩
rw [sup'_inf_sup']
exact finsetSup'_mem_supClosure _
fun i hi ↦ hs (hts (mem_product.1 hi).1) (hus (mem_product.1 hi).2)
@[simp] lemma supClosure_infClosure (s : Set α) : supClosure (infClosure s) = latticeClosure s :=
le_antisymm (supClosure_min (infClosure_min subset_latticeClosure isSublattice_latticeClosure.2)
isSublattice_latticeClosure.1) <| latticeClosure_min (subset_infClosure.trans subset_supClosure)
⟨supClosed_supClosure, infClosed_infClosure.supClosure⟩
@[simp] lemma infClosure_supClosure (s : Set α) : infClosure (supClosure s) = latticeClosure s :=
le_antisymm (infClosure_min (supClosure_min subset_latticeClosure isSublattice_latticeClosure.1)
isSublattice_latticeClosure.2) <| latticeClosure_min (subset_supClosure.trans subset_infClosure)
⟨supClosed_supClosure.infClosure, infClosed_infClosure⟩
lemma Set.Finite.latticeClosure (hs : s.Finite) : (latticeClosure s).Finite := by
rw [← supClosure_infClosure]; exact hs.infClosure.supClosure
@[simp] lemma latticeClosure_prod (s : Set α) (t : Set β) :
latticeClosure (s ×ˢ t) = latticeClosure s ×ˢ latticeClosure t := by
simp_rw [← supClosure_infClosure]; simp
end DistribLattice
/-- A join-semilattice where every sup-closed set has a least upper bound is automatically complete.
-/
def SemilatticeSup.toCompleteSemilatticeSup [SemilatticeSup α] (sSup : Set α → α)
(h : ∀ s, SupClosed s → IsLUB s (sSup s)) : CompleteSemilatticeSup α where
sSup := fun s => sSup (supClosure s)
le_sSup s a ha := (h _ supClosed_supClosure).1 <| subset_supClosure ha
sSup_le s a ha := (isLUB_le_iff <| h _ supClosed_supClosure).2 <| by rwa [upperBounds_supClosure]
/-- A meet-semilattice where every inf-closed set has a greatest lower bound is automatically
complete. -/
def SemilatticeInf.toCompleteSemilatticeInf [SemilatticeInf α] (sInf : Set α → α)
(h : ∀ s, InfClosed s → IsGLB s (sInf s)) : CompleteSemilatticeInf α where
sInf := fun s => sInf (infClosure s)
sInf_le s a ha := (h _ infClosed_infClosure).1 <| subset_infClosure ha
le_sInf s a ha := (le_isGLB_iff <| h _ infClosed_infClosure).2 <| by rwa [lowerBounds_infClosure]
|
Order\SupIndep.lean | /-
Copyright (c) 2021 Aaron Anderson, Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Kevin Buzzard, Yaël Dillies, Eric Wieser
-/
import Mathlib.Data.Finset.Sigma
import Mathlib.Data.Finset.Pairwise
import Mathlib.Data.Finset.Powerset
import Mathlib.Data.Fintype.Basic
import Mathlib.Order.CompleteLatticeIntervals
/-!
# Supremum independence
In this file, we define supremum independence of indexed sets. An indexed family `f : ι → α` is
sup-independent if, for all `a`, `f a` and the supremum of the rest are disjoint.
## Main definitions
* `Finset.SupIndep s f`: a family of elements `f` are supremum independent on the finite set `s`.
* `CompleteLattice.SetIndependent s`: a set of elements are supremum independent.
* `CompleteLattice.Independent f`: a family of elements are supremum independent.
## Main statements
* In a distributive lattice, supremum independence is equivalent to pairwise disjointness:
* `Finset.supIndep_iff_pairwiseDisjoint`
* `CompleteLattice.setIndependent_iff_pairwiseDisjoint`
* `CompleteLattice.independent_iff_pairwiseDisjoint`
* Otherwise, supremum independence is stronger than pairwise disjointness:
* `Finset.SupIndep.pairwiseDisjoint`
* `CompleteLattice.SetIndependent.pairwiseDisjoint`
* `CompleteLattice.Independent.pairwiseDisjoint`
## Implementation notes
For the finite version, we avoid the "obvious" definition
`∀ i ∈ s, Disjoint (f i) ((s.erase i).sup f)` because `erase` would require decidable equality on
`ι`.
-/
variable {α β ι ι' : Type*}
/-! ### On lattices with a bottom element, via `Finset.sup` -/
namespace Finset
section Lattice
variable [Lattice α] [OrderBot α]
/-- Supremum independence of finite sets. We avoid the "obvious" definition using `s.erase i`
because `erase` would require decidable equality on `ι`. -/
def SupIndep (s : Finset ι) (f : ι → α) : Prop :=
∀ ⦃t⦄, t ⊆ s → ∀ ⦃i⦄, i ∈ s → i ∉ t → Disjoint (f i) (t.sup f)
variable {s t : Finset ι} {f : ι → α} {i : ι}
instance [DecidableEq ι] [DecidableEq α] : Decidable (SupIndep s f) := by
refine @Finset.decidableForallOfDecidableSubsets _ _ _ (?_)
rintro t -
refine @Finset.decidableDforallFinset _ _ _ (?_)
rintro i -
have : Decidable (Disjoint (f i) (sup t f)) := decidable_of_iff' (_ = ⊥) disjoint_iff
infer_instance
theorem SupIndep.subset (ht : t.SupIndep f) (h : s ⊆ t) : s.SupIndep f := fun _ hu _ hi =>
ht (hu.trans h) (h hi)
@[simp]
theorem supIndep_empty (f : ι → α) : (∅ : Finset ι).SupIndep f := fun _ _ a ha =>
(not_mem_empty a ha).elim
theorem supIndep_singleton (i : ι) (f : ι → α) : ({i} : Finset ι).SupIndep f :=
fun s hs j hji hj => by
rw [eq_empty_of_ssubset_singleton ⟨hs, fun h => hj (h hji)⟩, sup_empty]
exact disjoint_bot_right
theorem SupIndep.pairwiseDisjoint (hs : s.SupIndep f) : (s : Set ι).PairwiseDisjoint f :=
fun _ ha _ hb hab =>
sup_singleton.subst <| hs (singleton_subset_iff.2 hb) ha <| not_mem_singleton.2 hab
theorem SupIndep.le_sup_iff (hs : s.SupIndep f) (hts : t ⊆ s) (hi : i ∈ s) (hf : ∀ i, f i ≠ ⊥) :
f i ≤ t.sup f ↔ i ∈ t := by
refine ⟨fun h => ?_, le_sup⟩
by_contra hit
exact hf i (disjoint_self.1 <| (hs hts hi hit).mono_right h)
/-- The RHS looks like the definition of `CompleteLattice.Independent`. -/
theorem supIndep_iff_disjoint_erase [DecidableEq ι] :
s.SupIndep f ↔ ∀ i ∈ s, Disjoint (f i) ((s.erase i).sup f) :=
⟨fun hs _ hi => hs (erase_subset _ _) hi (not_mem_erase _ _), fun hs _ ht i hi hit =>
(hs i hi).mono_right (sup_mono fun _ hj => mem_erase.2 ⟨ne_of_mem_of_not_mem hj hit, ht hj⟩)⟩
theorem SupIndep.image [DecidableEq ι] {s : Finset ι'} {g : ι' → ι} (hs : s.SupIndep (f ∘ g)) :
(s.image g).SupIndep f := by
intro t ht i hi hit
rw [mem_image] at hi
obtain ⟨i, hi, rfl⟩ := hi
haveI : DecidableEq ι' := Classical.decEq _
suffices hts : t ⊆ (s.erase i).image g by
refine (supIndep_iff_disjoint_erase.1 hs i hi).mono_right ((sup_mono hts).trans ?_)
rw [sup_image]
rintro j hjt
obtain ⟨j, hj, rfl⟩ := mem_image.1 (ht hjt)
exact mem_image_of_mem _ (mem_erase.2 ⟨ne_of_apply_ne g (ne_of_mem_of_not_mem hjt hit), hj⟩)
theorem supIndep_map {s : Finset ι'} {g : ι' ↪ ι} : (s.map g).SupIndep f ↔ s.SupIndep (f ∘ g) := by
refine ⟨fun hs t ht i hi hit => ?_, fun hs => ?_⟩
· rw [← sup_map]
exact hs (map_subset_map.2 ht) ((mem_map' _).2 hi) (by rwa [mem_map'])
· classical
rw [map_eq_image]
exact hs.image
@[simp]
theorem supIndep_pair [DecidableEq ι] {i j : ι} (hij : i ≠ j) :
({i, j} : Finset ι).SupIndep f ↔ Disjoint (f i) (f j) :=
⟨fun h => h.pairwiseDisjoint (by simp) (by simp) hij,
fun h => by
rw [supIndep_iff_disjoint_erase]
intro k hk
rw [Finset.mem_insert, Finset.mem_singleton] at hk
obtain rfl | rfl := hk
· convert h using 1
rw [Finset.erase_insert, Finset.sup_singleton]
simpa using hij
· convert h.symm using 1
have : ({i, k} : Finset ι).erase k = {i} := by
ext
rw [mem_erase, mem_insert, mem_singleton, mem_singleton, and_or_left, Ne,
not_and_self_iff, or_false_iff, and_iff_right_of_imp]
rintro rfl
exact hij
rw [this, Finset.sup_singleton]⟩
theorem supIndep_univ_bool (f : Bool → α) :
(Finset.univ : Finset Bool).SupIndep f ↔ Disjoint (f false) (f true) :=
haveI : true ≠ false := by simp only [Ne, not_false_iff]
(supIndep_pair this).trans disjoint_comm
@[simp]
theorem supIndep_univ_fin_two (f : Fin 2 → α) :
(Finset.univ : Finset (Fin 2)).SupIndep f ↔ Disjoint (f 0) (f 1) :=
haveI : (0 : Fin 2) ≠ 1 := by simp
supIndep_pair this
theorem SupIndep.attach (hs : s.SupIndep f) : s.attach.SupIndep fun a => f a := by
intro t _ i _ hi
classical
have : (fun (a : { x // x ∈ s }) => f ↑a) = f ∘ (fun a : { x // x ∈ s } => ↑a) := rfl
rw [this, ← Finset.sup_image]
refine hs (image_subset_iff.2 fun (j : { x // x ∈ s }) _ => j.2) i.2 fun hi' => hi ?_
rw [mem_image] at hi'
obtain ⟨j, hj, hji⟩ := hi'
rwa [Subtype.ext hji] at hj
/-
Porting note: simpNF linter returns
"Left-hand side does not simplify, when using the simp lemma on itself."
However, simp does indeed solve the following. leanprover/std4#71 is related.
example {α ι} [Lattice α] [OrderBot α] (s : Finset ι) (f : ι → α) :
(s.attach.SupIndep fun a => f a) ↔ s.SupIndep f := by simp
-/
@[simp, nolint simpNF]
theorem supIndep_attach : (s.attach.SupIndep fun a => f a) ↔ s.SupIndep f := by
refine ⟨fun h t ht i his hit => ?_, SupIndep.attach⟩
classical
convert h (filter_subset (fun (i : { x // x ∈ s }) => (i : ι) ∈ t) _) (mem_attach _ ⟨i, ‹_›⟩)
fun hi => hit <| by simpa using hi using 1
refine eq_of_forall_ge_iff ?_
simp only [Finset.sup_le_iff, mem_filter, mem_attach, true_and_iff, Function.comp_apply,
Subtype.forall, Subtype.coe_mk]
exact fun a => forall_congr' fun j => ⟨fun h _ => h, fun h hj => h (ht hj) hj⟩
end Lattice
section DistribLattice
variable [DistribLattice α] [OrderBot α] {s : Finset ι} {f : ι → α}
theorem supIndep_iff_pairwiseDisjoint : s.SupIndep f ↔ (s : Set ι).PairwiseDisjoint f :=
⟨SupIndep.pairwiseDisjoint, fun hs _ ht _ hi hit =>
Finset.disjoint_sup_right.2 fun _ hj => hs hi (ht hj) (ne_of_mem_of_not_mem hj hit).symm⟩
alias ⟨sup_indep.pairwise_disjoint, _root_.Set.PairwiseDisjoint.supIndep⟩ :=
supIndep_iff_pairwiseDisjoint
/-- Bind operation for `SupIndep`. -/
theorem SupIndep.sup [DecidableEq ι] {s : Finset ι'} {g : ι' → Finset ι} {f : ι → α}
(hs : s.SupIndep fun i => (g i).sup f) (hg : ∀ i' ∈ s, (g i').SupIndep f) :
(s.sup g).SupIndep f := by
simp_rw [supIndep_iff_pairwiseDisjoint] at hs hg ⊢
rw [sup_eq_biUnion, coe_biUnion]
exact hs.biUnion_finset hg
/-- Bind operation for `SupIndep`. -/
theorem SupIndep.biUnion [DecidableEq ι] {s : Finset ι'} {g : ι' → Finset ι} {f : ι → α}
(hs : s.SupIndep fun i => (g i).sup f) (hg : ∀ i' ∈ s, (g i').SupIndep f) :
(s.biUnion g).SupIndep f := by
rw [← sup_eq_biUnion]
exact hs.sup hg
/-- Bind operation for `SupIndep`. -/
theorem SupIndep.sigma {β : ι → Type*} {s : Finset ι} {g : ∀ i, Finset (β i)} {f : Sigma β → α}
(hs : s.SupIndep fun i => (g i).sup fun b => f ⟨i, b⟩)
(hg : ∀ i ∈ s, (g i).SupIndep fun b => f ⟨i, b⟩) : (s.sigma g).SupIndep f := by
rintro t ht ⟨i, b⟩ hi hit
rw [Finset.disjoint_sup_right]
rintro ⟨j, c⟩ hj
have hbc := (ne_of_mem_of_not_mem hj hit).symm
replace hj := ht hj
rw [mem_sigma] at hi hj
obtain rfl | hij := eq_or_ne i j
· exact (hg _ hj.1).pairwiseDisjoint hi.2 hj.2 (sigma_mk_injective.ne_iff.1 hbc)
· refine (hs.pairwiseDisjoint hi.1 hj.1 hij).mono ?_ ?_
· convert le_sup (α := α) hi.2; simp
· convert le_sup (α := α) hj.2; simp
theorem SupIndep.product {s : Finset ι} {t : Finset ι'} {f : ι × ι' → α}
(hs : s.SupIndep fun i => t.sup fun i' => f (i, i'))
(ht : t.SupIndep fun i' => s.sup fun i => f (i, i')) : (s ×ˢ t).SupIndep f := by
rintro u hu ⟨i, i'⟩ hi hiu
rw [Finset.disjoint_sup_right]
rintro ⟨j, j'⟩ hj
have hij := (ne_of_mem_of_not_mem hj hiu).symm
replace hj := hu hj
rw [mem_product] at hi hj
obtain rfl | hij := eq_or_ne i j
· refine (ht.pairwiseDisjoint hi.2 hj.2 <| (Prod.mk.inj_left _).ne_iff.1 hij).mono ?_ ?_
· convert le_sup (α := α) hi.1; simp
· convert le_sup (α := α) hj.1; simp
· refine (hs.pairwiseDisjoint hi.1 hj.1 hij).mono ?_ ?_
· convert le_sup (α := α) hi.2; simp
· convert le_sup (α := α) hj.2; simp
theorem supIndep_product_iff {s : Finset ι} {t : Finset ι'} {f : ι × ι' → α} :
(s.product t).SupIndep f ↔ (s.SupIndep fun i => t.sup fun i' => f (i, i'))
∧ t.SupIndep fun i' => s.sup fun i => f (i, i') := by
refine ⟨?_, fun h => h.1.product h.2⟩
simp_rw [supIndep_iff_pairwiseDisjoint]
refine fun h => ⟨fun i hi j hj hij => ?_, fun i hi j hj hij => ?_⟩ <;>
simp_rw [Finset.disjoint_sup_left, Finset.disjoint_sup_right] <;>
intro i' hi' j' hj'
· exact h (mk_mem_product hi hi') (mk_mem_product hj hj') (ne_of_apply_ne Prod.fst hij)
· exact h (mk_mem_product hi' hi) (mk_mem_product hj' hj) (ne_of_apply_ne Prod.snd hij)
end DistribLattice
end Finset
/-! ### On complete lattices via `sSup` -/
namespace CompleteLattice
variable [CompleteLattice α]
open Set Function
/-- An independent set of elements in a complete lattice is one in which every element is disjoint
from the `Sup` of the rest. -/
def SetIndependent (s : Set α) : Prop :=
∀ ⦃a⦄, a ∈ s → Disjoint a (sSup (s \ {a}))
variable {s : Set α} (hs : SetIndependent s)
@[simp]
theorem setIndependent_empty : SetIndependent (∅ : Set α) := fun x hx =>
(Set.not_mem_empty x hx).elim
theorem SetIndependent.mono {t : Set α} (hst : t ⊆ s) : SetIndependent t := fun _ ha =>
(hs (hst ha)).mono_right (sSup_le_sSup (diff_subset_diff_left hst))
/-- If the elements of a set are independent, then any pair within that set is disjoint. -/
theorem SetIndependent.pairwiseDisjoint : s.PairwiseDisjoint id := fun _ hx y hy h =>
disjoint_sSup_right (hs hx) ((mem_diff y).mpr ⟨hy, h.symm⟩)
theorem setIndependent_singleton (a : α) : SetIndependent ({a} : Set α) := fun i hi ↦ by
simp_all
theorem setIndependent_pair {a b : α} (hab : a ≠ b) :
SetIndependent ({a, b} : Set α) ↔ Disjoint a b := by
constructor
· intro h
exact h.pairwiseDisjoint (mem_insert _ _) (mem_insert_of_mem _ (mem_singleton _)) hab
· rintro h c ((rfl : c = a) | (rfl : c = b))
· convert h using 1
simp [hab, sSup_singleton]
· convert h.symm using 1
simp [hab, sSup_singleton]
/-- If the elements of a set are independent, then any element is disjoint from the `sSup` of some
subset of the rest. -/
theorem SetIndependent.disjoint_sSup {x : α} {y : Set α} (hx : x ∈ s) (hy : y ⊆ s) (hxy : x ∉ y) :
Disjoint x (sSup y) := by
have := (hs.mono <| insert_subset_iff.mpr ⟨hx, hy⟩) (mem_insert x _)
rw [insert_diff_of_mem _ (mem_singleton _), diff_singleton_eq_self hxy] at this
exact this
/-- An independent indexed family of elements in a complete lattice is one in which every element
is disjoint from the `iSup` of the rest.
Example: an indexed family of non-zero elements in a
vector space is linearly independent iff the indexed family of subspaces they generate is
independent in this sense.
Example: an indexed family of submodules of a module is independent in this sense if
and only the natural map from the direct sum of the submodules to the module is injective. -/
def Independent {ι : Sort*} {α : Type*} [CompleteLattice α] (t : ι → α) : Prop :=
∀ i : ι, Disjoint (t i) (⨆ (j) (_ : j ≠ i), t j)
theorem setIndependent_iff {α : Type*} [CompleteLattice α] (s : Set α) :
SetIndependent s ↔ Independent ((↑) : s → α) := by
simp_rw [Independent, SetIndependent, SetCoe.forall, sSup_eq_iSup]
refine forall₂_congr fun a ha => ?_
simp [iSup_subtype, iSup_and]
variable {t : ι → α} (ht : Independent t)
theorem independent_def : Independent t ↔ ∀ i : ι, Disjoint (t i) (⨆ (j) (_ : j ≠ i), t j) :=
Iff.rfl
theorem independent_def' : Independent t ↔ ∀ i, Disjoint (t i) (sSup (t '' { j | j ≠ i })) := by
simp_rw [sSup_image]
rfl
theorem independent_def'' :
Independent t ↔ ∀ i, Disjoint (t i) (sSup { a | ∃ j ≠ i, t j = a }) := by
rw [independent_def']
aesop
@[simp]
theorem independent_empty (t : Empty → α) : Independent t :=
nofun
@[simp]
theorem independent_pempty (t : PEmpty → α) : Independent t :=
nofun
/-- If the elements of a set are independent, then any pair within that set is disjoint. -/
theorem Independent.pairwiseDisjoint : Pairwise (Disjoint on t) := fun x y h =>
disjoint_sSup_right (ht x) ⟨y, iSup_pos h.symm⟩
theorem Independent.mono {s t : ι → α} (hs : Independent s) (hst : t ≤ s) : Independent t :=
fun i => (hs i).mono (hst i) <| iSup₂_mono fun j _ => hst j
/-- Composing an independent indexed family with an injective function on the index results in
another indepedendent indexed family. -/
theorem Independent.comp {ι ι' : Sort*} {t : ι → α} {f : ι' → ι} (ht : Independent t)
(hf : Injective f) : Independent (t ∘ f) := fun i =>
(ht (f i)).mono_right <| by
refine (iSup_mono fun i => ?_).trans (iSup_comp_le _ f)
exact iSup_const_mono hf.ne
theorem Independent.comp' {ι ι' : Sort*} {t : ι → α} {f : ι' → ι} (ht : Independent <| t ∘ f)
(hf : Surjective f) : Independent t := by
intro i
obtain ⟨i', rfl⟩ := hf i
rw [← hf.iSup_comp]
exact (ht i').mono_right (biSup_mono fun j' hij => mt (congr_arg f) hij)
theorem Independent.setIndependent_range (ht : Independent t) : SetIndependent <| range t := by
rw [setIndependent_iff]
rw [← coe_comp_rangeFactorization t] at ht
exact ht.comp' surjective_onto_range
@[simp]
theorem independent_ne_bot_iff_independent :
Independent (fun i : {i // t i ≠ ⊥} ↦ t i) ↔ Independent t := by
refine ⟨fun h ↦ ?_, fun h ↦ h.comp Subtype.val_injective⟩
simp only [independent_def] at h ⊢
intro i
cases eq_or_ne (t i) ⊥ with
| inl hi => simp [hi]
| inr hi => ?_
convert h ⟨i, hi⟩
have : ∀ j, ⨆ (_ : t j = ⊥), t j = ⊥ := fun j ↦ by simp only [iSup_eq_bot, imp_self]
rw [iSup_split _ (fun j ↦ t j = ⊥), iSup_subtype]
simp only [iSup_comm (ι' := _ ≠ i), this, ne_eq, sup_of_le_right, Subtype.mk.injEq, iSup_bot,
bot_le]
theorem Independent.injOn (ht : Independent t) : InjOn t {i | t i ≠ ⊥} := by
rintro i _ j (hj : t j ≠ ⊥) h
by_contra! contra
apply hj
suffices t j ≤ ⨆ (k) (_ : k ≠ i), t k by
replace ht := (ht i).mono_right this
rwa [h, disjoint_self] at ht
replace contra : j ≠ i := Ne.symm contra
-- Porting note: needs explicit `f`
exact le_iSup₂ (f := fun x _ ↦ t x) j contra
theorem Independent.injective (ht : Independent t) (h_ne_bot : ∀ i, t i ≠ ⊥) : Injective t := by
suffices univ = {i | t i ≠ ⊥} by rw [injective_iff_injOn_univ, this]; exact ht.injOn
aesop
theorem independent_pair {i j : ι} (hij : i ≠ j) (huniv : ∀ k, k = i ∨ k = j) :
Independent t ↔ Disjoint (t i) (t j) := by
constructor
· exact fun h => h.pairwiseDisjoint hij
· rintro h k
obtain rfl | rfl := huniv k
· refine h.mono_right (iSup_le fun i => iSup_le fun hi => Eq.le ?_)
rw [(huniv i).resolve_left hi]
· refine h.symm.mono_right (iSup_le fun j => iSup_le fun hj => Eq.le ?_)
rw [(huniv j).resolve_right hj]
/-- Composing an independent indexed family with an order isomorphism on the elements results in
another independent indexed family. -/
theorem Independent.map_orderIso {ι : Sort*} {α β : Type*} [CompleteLattice α]
[CompleteLattice β] (f : α ≃o β) {a : ι → α} (ha : Independent a) : Independent (f ∘ a) :=
fun i => ((ha i).map_orderIso f).mono_right (f.monotone.le_map_iSup₂ _)
@[simp]
theorem independent_map_orderIso_iff {ι : Sort*} {α β : Type*} [CompleteLattice α]
[CompleteLattice β] (f : α ≃o β) {a : ι → α} : Independent (f ∘ a) ↔ Independent a :=
⟨fun h =>
have hf : f.symm ∘ f ∘ a = a := congr_arg (· ∘ a) f.left_inv.comp_eq_id
hf ▸ h.map_orderIso f.symm,
fun h => h.map_orderIso f⟩
/-- If the elements of a set are independent, then any element is disjoint from the `iSup` of some
subset of the rest. -/
theorem Independent.disjoint_biSup {ι : Type*} {α : Type*} [CompleteLattice α] {t : ι → α}
(ht : Independent t) {x : ι} {y : Set ι} (hx : x ∉ y) : Disjoint (t x) (⨆ i ∈ y, t i) :=
Disjoint.mono_right (biSup_mono fun _ hi => (ne_of_mem_of_not_mem hi hx : _)) (ht x)
lemma independent_of_independent_coe_Iic_comp {ι : Sort*} {a : α} {t : ι → Set.Iic a}
(ht : Independent ((↑) ∘ t : ι → α)) : Independent t := by
intro i x
specialize ht i
simp_rw [Function.comp_apply, ← Set.Iic.coe_iSup] at ht
exact @ht x
end CompleteLattice
theorem CompleteLattice.independent_iff_supIndep [CompleteLattice α] {s : Finset ι} {f : ι → α} :
CompleteLattice.Independent (f ∘ ((↑) : s → ι)) ↔ s.SupIndep f := by
classical
rw [Finset.supIndep_iff_disjoint_erase]
refine Subtype.forall.trans (forall₂_congr fun a b => ?_)
rw [Finset.sup_eq_iSup]
congr! 1
refine iSup_subtype.trans ?_
congr! 1
simp [iSup_and, @iSup_comm _ (_ ∈ s)]
alias ⟨CompleteLattice.Independent.supIndep, Finset.SupIndep.independent⟩ :=
CompleteLattice.independent_iff_supIndep
theorem CompleteLattice.Independent.supIndep' [CompleteLattice α] {f : ι → α} (s : Finset ι)
(h : CompleteLattice.Independent f) : s.SupIndep f :=
CompleteLattice.Independent.supIndep (h.comp Subtype.coe_injective)
/-- A variant of `CompleteLattice.independent_iff_supIndep` for `Fintype`s. -/
theorem CompleteLattice.independent_iff_supIndep_univ [CompleteLattice α] [Fintype ι] {f : ι → α} :
CompleteLattice.Independent f ↔ Finset.univ.SupIndep f := by
classical
simp [Finset.supIndep_iff_disjoint_erase, CompleteLattice.Independent, Finset.sup_eq_iSup]
alias ⟨CompleteLattice.Independent.sup_indep_univ, Finset.SupIndep.independent_of_univ⟩ :=
CompleteLattice.independent_iff_supIndep_univ
section Frame
namespace CompleteLattice
variable [Order.Frame α]
theorem setIndependent_iff_pairwiseDisjoint {s : Set α} :
SetIndependent s ↔ s.PairwiseDisjoint id :=
⟨SetIndependent.pairwiseDisjoint, fun hs _ hi =>
disjoint_sSup_iff.2 fun _ hj => hs hi hj.1 <| Ne.symm hj.2⟩
alias ⟨_, _root_.Set.PairwiseDisjoint.setIndependent⟩ := setIndependent_iff_pairwiseDisjoint
theorem independent_iff_pairwiseDisjoint {f : ι → α} : Independent f ↔ Pairwise (Disjoint on f) :=
⟨Independent.pairwiseDisjoint, fun hs _ =>
disjoint_iSup_iff.2 fun _ => disjoint_iSup_iff.2 fun hij => hs hij.symm⟩
end CompleteLattice
end Frame
|
Order\SymmDiff.lean | /-
Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Bryan Gin-ge Chen, Yaël Dillies
-/
import Mathlib.Order.BooleanAlgebra
import Mathlib.Logic.Equiv.Basic
/-!
# Symmetric difference and bi-implication
This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras.
## Examples
Some examples are
* The symmetric difference of two sets is the set of elements that are in either but not both.
* The symmetric difference on propositions is `Xor'`.
* The symmetric difference on `Bool` is `Bool.xor`.
* The equivalence of propositions. Two propositions are equivalent if they imply each other.
* The symmetric difference translates to addition when considering a Boolean algebra as a Boolean
ring.
## Main declarations
* `symmDiff`: The symmetric difference operator, defined as `(a \ b) ⊔ (b \ a)`
* `bihimp`: The bi-implication operator, defined as `(b ⇨ a) ⊓ (a ⇨ b)`
In generalized Boolean algebras, the symmetric difference operator is:
* `symmDiff_comm`: commutative, and
* `symmDiff_assoc`: associative.
## Notations
* `a ∆ b`: `symmDiff a b`
* `a ⇔ b`: `bihimp a b`
## References
The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A
Proof from the Book" by John McCuan:
* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>
## Tags
boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication,
Heyting
-/
open Function OrderDual
variable {ι α β : Type*} {π : ι → Type*}
/-- The symmetric difference operator on a type with `⊔` and `\` is `(A \ B) ⊔ (B \ A)`. -/
def symmDiff [Sup α] [SDiff α] (a b : α) : α :=
a \ b ⊔ b \ a
/-- The Heyting bi-implication is `(b ⇨ a) ⊓ (a ⇨ b)`. This generalizes equivalence of
propositions. -/
def bihimp [Inf α] [HImp α] (a b : α) : α :=
(b ⇨ a) ⊓ (a ⇨ b)
/-- Notation for symmDiff -/
scoped[symmDiff] infixl:100 " ∆ " => symmDiff
/-- Notation for bihimp -/
scoped[symmDiff] infixl:100 " ⇔ " => bihimp
open scoped symmDiff
theorem symmDiff_def [Sup α] [SDiff α] (a b : α) : a ∆ b = a \ b ⊔ b \ a :=
rfl
theorem bihimp_def [Inf α] [HImp α] (a b : α) : a ⇔ b = (b ⇨ a) ⊓ (a ⇨ b) :=
rfl
theorem symmDiff_eq_Xor' (p q : Prop) : p ∆ q = Xor' p q :=
rfl
@[simp]
theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) :=
(iff_iff_implies_and_implies _ _).symm.trans Iff.comm
@[simp]
theorem Bool.symmDiff_eq_xor : ∀ p q : Bool, p ∆ q = xor p q := by decide
section GeneralizedCoheytingAlgebra
variable [GeneralizedCoheytingAlgebra α] (a b c d : α)
@[simp]
theorem toDual_symmDiff : toDual (a ∆ b) = toDual a ⇔ toDual b :=
rfl
@[simp]
theorem ofDual_bihimp (a b : αᵒᵈ) : ofDual (a ⇔ b) = ofDual a ∆ ofDual b :=
rfl
theorem symmDiff_comm : a ∆ b = b ∆ a := by simp only [symmDiff, sup_comm]
instance symmDiff_isCommutative : Std.Commutative (α := α) (· ∆ ·) :=
⟨symmDiff_comm⟩
@[simp]
theorem symmDiff_self : a ∆ a = ⊥ := by rw [symmDiff, sup_idem, sdiff_self]
@[simp]
theorem symmDiff_bot : a ∆ ⊥ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq]
@[simp]
theorem bot_symmDiff : ⊥ ∆ a = a := by rw [symmDiff_comm, symmDiff_bot]
@[simp]
theorem symmDiff_eq_bot {a b : α} : a ∆ b = ⊥ ↔ a = b := by
simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff]
theorem symmDiff_of_le {a b : α} (h : a ≤ b) : a ∆ b = b \ a := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq]
theorem symmDiff_of_ge {a b : α} (h : b ≤ a) : a ∆ b = a \ b := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq]
theorem symmDiff_le {a b c : α} (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ∆ b ≤ c :=
sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb
theorem symmDiff_le_iff {a b c : α} : a ∆ b ≤ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := by
simp_rw [symmDiff, sup_le_iff, sdiff_le_iff]
@[simp]
theorem symmDiff_le_sup {a b : α} : a ∆ b ≤ a ⊔ b :=
sup_le_sup sdiff_le sdiff_le
theorem symmDiff_eq_sup_sdiff_inf : a ∆ b = (a ⊔ b) \ (a ⊓ b) := by simp [sup_sdiff, symmDiff]
theorem Disjoint.symmDiff_eq_sup {a b : α} (h : Disjoint a b) : a ∆ b = a ⊔ b := by
rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right]
theorem symmDiff_sdiff : a ∆ b \ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) := by
rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left]
@[simp]
theorem symmDiff_sdiff_inf : a ∆ b \ (a ⊓ b) = a ∆ b := by
rw [symmDiff_sdiff]
simp [symmDiff]
@[simp]
theorem symmDiff_sdiff_eq_sup : a ∆ (b \ a) = a ⊔ b := by
rw [symmDiff, sdiff_idem]
exact
le_antisymm (sup_le_sup sdiff_le sdiff_le)
(sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup)
@[simp]
theorem sdiff_symmDiff_eq_sup : (a \ b) ∆ b = a ⊔ b := by
rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm]
@[simp]
theorem symmDiff_sup_inf : a ∆ b ⊔ a ⊓ b = a ⊔ b := by
refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_
rw [sup_inf_left, symmDiff]
refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right)
· rw [sup_right_comm]
exact le_sup_of_le_left le_sdiff_sup
· rw [sup_assoc]
exact le_sup_of_le_right le_sdiff_sup
@[simp]
theorem inf_sup_symmDiff : a ⊓ b ⊔ a ∆ b = a ⊔ b := by rw [sup_comm, symmDiff_sup_inf]
@[simp]
theorem symmDiff_symmDiff_inf : a ∆ b ∆ (a ⊓ b) = a ⊔ b := by
rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf]
@[simp]
theorem inf_symmDiff_symmDiff : (a ⊓ b) ∆ (a ∆ b) = a ⊔ b := by
rw [symmDiff_comm, symmDiff_symmDiff_inf]
theorem symmDiff_triangle : a ∆ c ≤ a ∆ b ⊔ b ∆ c := by
refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_
rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff]
theorem le_symmDiff_sup_right (a b : α) : a ≤ (a ∆ b) ⊔ b := by
convert symmDiff_triangle a b ⊥ <;> rw [symmDiff_bot]
theorem le_symmDiff_sup_left (a b : α) : b ≤ (a ∆ b) ⊔ a :=
symmDiff_comm a b ▸ le_symmDiff_sup_right ..
end GeneralizedCoheytingAlgebra
section GeneralizedHeytingAlgebra
variable [GeneralizedHeytingAlgebra α] (a b c d : α)
@[simp]
theorem toDual_bihimp : toDual (a ⇔ b) = toDual a ∆ toDual b :=
rfl
@[simp]
theorem ofDual_symmDiff (a b : αᵒᵈ) : ofDual (a ∆ b) = ofDual a ⇔ ofDual b :=
rfl
theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(· ⇔ ·), inf_comm]
instance bihimp_isCommutative : Std.Commutative (α := α) (· ⇔ ·) :=
⟨bihimp_comm⟩
@[simp]
theorem bihimp_self : a ⇔ a = ⊤ := by rw [bihimp, inf_idem, himp_self]
@[simp]
theorem bihimp_top : a ⇔ ⊤ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq]
@[simp]
theorem top_bihimp : ⊤ ⇔ a = a := by rw [bihimp_comm, bihimp_top]
@[simp]
theorem bihimp_eq_top {a b : α} : a ⇔ b = ⊤ ↔ a = b :=
@symmDiff_eq_bot αᵒᵈ _ _ _
theorem bihimp_of_le {a b : α} (h : a ≤ b) : a ⇔ b = b ⇨ a := by
rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq]
theorem bihimp_of_ge {a b : α} (h : b ≤ a) : a ⇔ b = a ⇨ b := by
rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq]
theorem le_bihimp {a b c : α} (hb : a ⊓ b ≤ c) (hc : a ⊓ c ≤ b) : a ≤ b ⇔ c :=
le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb
theorem le_bihimp_iff {a b c : α} : a ≤ b ⇔ c ↔ a ⊓ b ≤ c ∧ a ⊓ c ≤ b := by
simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm]
@[simp]
theorem inf_le_bihimp {a b : α} : a ⊓ b ≤ a ⇔ b :=
inf_le_inf le_himp le_himp
theorem bihimp_eq_inf_himp_inf : a ⇔ b = a ⊔ b ⇨ a ⊓ b := by simp [himp_inf_distrib, bihimp]
theorem Codisjoint.bihimp_eq_inf {a b : α} (h : Codisjoint a b) : a ⇔ b = a ⊓ b := by
rw [bihimp, h.himp_eq_left, h.himp_eq_right]
theorem himp_bihimp : a ⇨ b ⇔ c = (a ⊓ c ⇨ b) ⊓ (a ⊓ b ⇨ c) := by
rw [bihimp, himp_inf_distrib, himp_himp, himp_himp]
@[simp]
theorem sup_himp_bihimp : a ⊔ b ⇨ a ⇔ b = a ⇔ b := by
rw [himp_bihimp]
simp [bihimp]
@[simp]
theorem bihimp_himp_eq_inf : a ⇔ (a ⇨ b) = a ⊓ b :=
@symmDiff_sdiff_eq_sup αᵒᵈ _ _ _
@[simp]
theorem himp_bihimp_eq_inf : (b ⇨ a) ⇔ b = a ⊓ b :=
@sdiff_symmDiff_eq_sup αᵒᵈ _ _ _
@[simp]
theorem bihimp_inf_sup : a ⇔ b ⊓ (a ⊔ b) = a ⊓ b :=
@symmDiff_sup_inf αᵒᵈ _ _ _
@[simp]
theorem sup_inf_bihimp : (a ⊔ b) ⊓ a ⇔ b = a ⊓ b :=
@inf_sup_symmDiff αᵒᵈ _ _ _
@[simp]
theorem bihimp_bihimp_sup : a ⇔ b ⇔ (a ⊔ b) = a ⊓ b :=
@symmDiff_symmDiff_inf αᵒᵈ _ _ _
@[simp]
theorem sup_bihimp_bihimp : (a ⊔ b) ⇔ (a ⇔ b) = a ⊓ b :=
@inf_symmDiff_symmDiff αᵒᵈ _ _ _
theorem bihimp_triangle : a ⇔ b ⊓ b ⇔ c ≤ a ⇔ c :=
@symmDiff_triangle αᵒᵈ _ _ _ _
end GeneralizedHeytingAlgebra
section CoheytingAlgebra
variable [CoheytingAlgebra α] (a : α)
@[simp]
theorem symmDiff_top' : a ∆ ⊤ = ¬a := by simp [symmDiff]
@[simp]
theorem top_symmDiff' : ⊤ ∆ a = ¬a := by simp [symmDiff]
@[simp]
theorem hnot_symmDiff_self : (¬a) ∆ a = ⊤ := by
rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self]
exact Codisjoint.top_le codisjoint_hnot_left
@[simp]
theorem symmDiff_hnot_self : a ∆ (¬a) = ⊤ := by rw [symmDiff_comm, hnot_symmDiff_self]
theorem IsCompl.symmDiff_eq_top {a b : α} (h : IsCompl a b) : a ∆ b = ⊤ := by
rw [h.eq_hnot, hnot_symmDiff_self]
end CoheytingAlgebra
section HeytingAlgebra
variable [HeytingAlgebra α] (a : α)
@[simp]
theorem bihimp_bot : a ⇔ ⊥ = aᶜ := by simp [bihimp]
@[simp]
theorem bot_bihimp : ⊥ ⇔ a = aᶜ := by simp [bihimp]
@[simp]
theorem compl_bihimp_self : aᶜ ⇔ a = ⊥ :=
@hnot_symmDiff_self αᵒᵈ _ _
@[simp]
theorem bihimp_hnot_self : a ⇔ aᶜ = ⊥ :=
@symmDiff_hnot_self αᵒᵈ _ _
theorem IsCompl.bihimp_eq_bot {a b : α} (h : IsCompl a b) : a ⇔ b = ⊥ := by
rw [h.eq_compl, compl_bihimp_self]
end HeytingAlgebra
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra α] (a b c d : α)
@[simp]
theorem sup_sdiff_symmDiff : (a ⊔ b) \ a ∆ b = a ⊓ b :=
sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf])
theorem disjoint_symmDiff_inf : Disjoint (a ∆ b) (a ⊓ b) := by
rw [symmDiff_eq_sup_sdiff_inf]
exact disjoint_sdiff_self_left
theorem inf_symmDiff_distrib_left : a ⊓ b ∆ c = (a ⊓ b) ∆ (a ⊓ c) := by
rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left,
symmDiff_eq_sup_sdiff_inf]
theorem inf_symmDiff_distrib_right : a ∆ b ⊓ c = (a ⊓ c) ∆ (b ⊓ c) := by
simp_rw [inf_comm _ c, inf_symmDiff_distrib_left]
theorem sdiff_symmDiff : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ a ⊓ c \ b := by
simp only [(· ∆ ·), sdiff_sdiff_sup_sdiff']
theorem sdiff_symmDiff' : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ (a ⊔ b) := by
rw [sdiff_symmDiff, sdiff_sup]
@[simp]
theorem symmDiff_sdiff_left : a ∆ b \ a = b \ a := by
rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq]
@[simp]
theorem symmDiff_sdiff_right : a ∆ b \ b = a \ b := by rw [symmDiff_comm, symmDiff_sdiff_left]
@[simp]
theorem sdiff_symmDiff_left : a \ a ∆ b = a ⊓ b := by simp [sdiff_symmDiff]
@[simp]
theorem sdiff_symmDiff_right : b \ a ∆ b = a ⊓ b := by
rw [symmDiff_comm, inf_comm, sdiff_symmDiff_left]
theorem symmDiff_eq_sup : a ∆ b = a ⊔ b ↔ Disjoint a b := by
refine ⟨fun h => ?_, Disjoint.symmDiff_eq_sup⟩
rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h
exact h.of_disjoint_inf_of_le le_sup_left
@[simp]
theorem le_symmDiff_iff_left : a ≤ a ∆ b ↔ Disjoint a b := by
refine ⟨fun h => ?_, fun h => h.symmDiff_eq_sup.symm ▸ le_sup_left⟩
rw [symmDiff_eq_sup_sdiff_inf] at h
exact disjoint_iff_inf_le.mpr (le_sdiff_iff.1 <| inf_le_of_left_le h).le
@[simp]
theorem le_symmDiff_iff_right : b ≤ a ∆ b ↔ Disjoint a b := by
rw [symmDiff_comm, le_symmDiff_iff_left, disjoint_comm]
theorem symmDiff_symmDiff_left :
a ∆ b ∆ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c :=
calc
a ∆ b ∆ c = a ∆ b \ c ⊔ c \ a ∆ b := symmDiff_def _ _
_ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ (c \ (a ⊔ b) ⊔ c ⊓ a ⊓ b) := by
{ rw [sdiff_symmDiff', sup_comm (c ⊓ a ⊓ b), symmDiff_sdiff] }
_ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := by ac_rfl
theorem symmDiff_symmDiff_right :
a ∆ (b ∆ c) = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c :=
calc
a ∆ (b ∆ c) = a \ b ∆ c ⊔ b ∆ c \ a := symmDiff_def _ _
_ = a \ (b ⊔ c) ⊔ a ⊓ b ⊓ c ⊔ (b \ (c ⊔ a) ⊔ c \ (b ⊔ a)) := by
{ rw [sdiff_symmDiff', sup_comm (a ⊓ b ⊓ c), symmDiff_sdiff] }
_ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := by ac_rfl
theorem symmDiff_assoc : a ∆ b ∆ c = a ∆ (b ∆ c) := by
rw [symmDiff_symmDiff_left, symmDiff_symmDiff_right]
instance symmDiff_isAssociative : Std.Associative (α := α) (· ∆ ·) :=
⟨symmDiff_assoc⟩
theorem symmDiff_left_comm : a ∆ (b ∆ c) = b ∆ (a ∆ c) := by
simp_rw [← symmDiff_assoc, symmDiff_comm]
theorem symmDiff_right_comm : a ∆ b ∆ c = a ∆ c ∆ b := by simp_rw [symmDiff_assoc, symmDiff_comm]
theorem symmDiff_symmDiff_symmDiff_comm : a ∆ b ∆ (c ∆ d) = a ∆ c ∆ (b ∆ d) := by
simp_rw [symmDiff_assoc, symmDiff_left_comm]
@[simp]
theorem symmDiff_symmDiff_cancel_left : a ∆ (a ∆ b) = b := by simp [← symmDiff_assoc]
@[simp]
theorem symmDiff_symmDiff_cancel_right : b ∆ a ∆ a = b := by simp [symmDiff_assoc]
@[simp]
theorem symmDiff_symmDiff_self' : a ∆ b ∆ a = b := by
rw [symmDiff_comm, symmDiff_symmDiff_cancel_left]
theorem symmDiff_left_involutive (a : α) : Involutive (· ∆ a) :=
symmDiff_symmDiff_cancel_right _
theorem symmDiff_right_involutive (a : α) : Involutive (a ∆ ·) :=
symmDiff_symmDiff_cancel_left _
theorem symmDiff_left_injective (a : α) : Injective (· ∆ a) :=
Function.Involutive.injective (symmDiff_left_involutive a)
theorem symmDiff_right_injective (a : α) : Injective (a ∆ ·) :=
Function.Involutive.injective (symmDiff_right_involutive _)
theorem symmDiff_left_surjective (a : α) : Surjective (· ∆ a) :=
Function.Involutive.surjective (symmDiff_left_involutive _)
theorem symmDiff_right_surjective (a : α) : Surjective (a ∆ ·) :=
Function.Involutive.surjective (symmDiff_right_involutive _)
variable {a b c}
@[simp]
theorem symmDiff_left_inj : a ∆ b = c ∆ b ↔ a = c :=
(symmDiff_left_injective _).eq_iff
@[simp]
theorem symmDiff_right_inj : a ∆ b = a ∆ c ↔ b = c :=
(symmDiff_right_injective _).eq_iff
@[simp]
theorem symmDiff_eq_left : a ∆ b = a ↔ b = ⊥ :=
calc
a ∆ b = a ↔ a ∆ b = a ∆ ⊥ := by rw [symmDiff_bot]
_ ↔ b = ⊥ := by rw [symmDiff_right_inj]
@[simp]
theorem symmDiff_eq_right : a ∆ b = b ↔ a = ⊥ := by rw [symmDiff_comm, symmDiff_eq_left]
protected theorem Disjoint.symmDiff_left (ha : Disjoint a c) (hb : Disjoint b c) :
Disjoint (a ∆ b) c := by
rw [symmDiff_eq_sup_sdiff_inf]
exact (ha.sup_left hb).disjoint_sdiff_left
protected theorem Disjoint.symmDiff_right (ha : Disjoint a b) (hb : Disjoint a c) :
Disjoint a (b ∆ c) :=
(ha.symm.symmDiff_left hb.symm).symm
theorem symmDiff_eq_iff_sdiff_eq (ha : a ≤ c) : a ∆ b = c ↔ c \ a = b := by
rw [← symmDiff_of_le ha]
exact ((symmDiff_right_involutive a).toPerm _).apply_eq_iff_eq_symm_apply.trans eq_comm
end GeneralizedBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra α] (a b c d : α)
/-! `CogeneralizedBooleanAlgebra` isn't actually a typeclass, but the lemmas in here are dual to
the `GeneralizedBooleanAlgebra` ones -/
section CogeneralizedBooleanAlgebra
@[simp]
theorem inf_himp_bihimp : a ⇔ b ⇨ a ⊓ b = a ⊔ b :=
@sup_sdiff_symmDiff αᵒᵈ _ _ _
theorem codisjoint_bihimp_sup : Codisjoint (a ⇔ b) (a ⊔ b) :=
@disjoint_symmDiff_inf αᵒᵈ _ _ _
@[simp]
theorem himp_bihimp_left : a ⇨ a ⇔ b = a ⇨ b :=
@symmDiff_sdiff_left αᵒᵈ _ _ _
@[simp]
theorem himp_bihimp_right : b ⇨ a ⇔ b = b ⇨ a :=
@symmDiff_sdiff_right αᵒᵈ _ _ _
@[simp]
theorem bihimp_himp_left : a ⇔ b ⇨ a = a ⊔ b :=
@sdiff_symmDiff_left αᵒᵈ _ _ _
@[simp]
theorem bihimp_himp_right : a ⇔ b ⇨ b = a ⊔ b :=
@sdiff_symmDiff_right αᵒᵈ _ _ _
@[simp]
theorem bihimp_eq_inf : a ⇔ b = a ⊓ b ↔ Codisjoint a b :=
@symmDiff_eq_sup αᵒᵈ _ _ _
@[simp]
theorem bihimp_le_iff_left : a ⇔ b ≤ a ↔ Codisjoint a b :=
@le_symmDiff_iff_left αᵒᵈ _ _ _
@[simp]
theorem bihimp_le_iff_right : a ⇔ b ≤ b ↔ Codisjoint a b :=
@le_symmDiff_iff_right αᵒᵈ _ _ _
theorem bihimp_assoc : a ⇔ b ⇔ c = a ⇔ (b ⇔ c) :=
@symmDiff_assoc αᵒᵈ _ _ _ _
instance bihimp_isAssociative : Std.Associative (α := α) (· ⇔ ·) :=
⟨bihimp_assoc⟩
theorem bihimp_left_comm : a ⇔ (b ⇔ c) = b ⇔ (a ⇔ c) := by simp_rw [← bihimp_assoc, bihimp_comm]
theorem bihimp_right_comm : a ⇔ b ⇔ c = a ⇔ c ⇔ b := by simp_rw [bihimp_assoc, bihimp_comm]
theorem bihimp_bihimp_bihimp_comm : a ⇔ b ⇔ (c ⇔ d) = a ⇔ c ⇔ (b ⇔ d) := by
simp_rw [bihimp_assoc, bihimp_left_comm]
@[simp]
theorem bihimp_bihimp_cancel_left : a ⇔ (a ⇔ b) = b := by simp [← bihimp_assoc]
@[simp]
theorem bihimp_bihimp_cancel_right : b ⇔ a ⇔ a = b := by simp [bihimp_assoc]
@[simp]
theorem bihimp_bihimp_self : a ⇔ b ⇔ a = b := by rw [bihimp_comm, bihimp_bihimp_cancel_left]
theorem bihimp_left_involutive (a : α) : Involutive (· ⇔ a) :=
bihimp_bihimp_cancel_right _
theorem bihimp_right_involutive (a : α) : Involutive (a ⇔ ·) :=
bihimp_bihimp_cancel_left _
theorem bihimp_left_injective (a : α) : Injective (· ⇔ a) :=
@symmDiff_left_injective αᵒᵈ _ _
theorem bihimp_right_injective (a : α) : Injective (a ⇔ ·) :=
@symmDiff_right_injective αᵒᵈ _ _
theorem bihimp_left_surjective (a : α) : Surjective (· ⇔ a) :=
@symmDiff_left_surjective αᵒᵈ _ _
theorem bihimp_right_surjective (a : α) : Surjective (a ⇔ ·) :=
@symmDiff_right_surjective αᵒᵈ _ _
variable {a b c}
@[simp]
theorem bihimp_left_inj : a ⇔ b = c ⇔ b ↔ a = c :=
(bihimp_left_injective _).eq_iff
@[simp]
theorem bihimp_right_inj : a ⇔ b = a ⇔ c ↔ b = c :=
(bihimp_right_injective _).eq_iff
@[simp]
theorem bihimp_eq_left : a ⇔ b = a ↔ b = ⊤ :=
@symmDiff_eq_left αᵒᵈ _ _ _
@[simp]
theorem bihimp_eq_right : a ⇔ b = b ↔ a = ⊤ :=
@symmDiff_eq_right αᵒᵈ _ _ _
protected theorem Codisjoint.bihimp_left (ha : Codisjoint a c) (hb : Codisjoint b c) :
Codisjoint (a ⇔ b) c :=
(ha.inf_left hb).mono_left inf_le_bihimp
protected theorem Codisjoint.bihimp_right (ha : Codisjoint a b) (hb : Codisjoint a c) :
Codisjoint a (b ⇔ c) :=
(ha.inf_right hb).mono_right inf_le_bihimp
end CogeneralizedBooleanAlgebra
theorem symmDiff_eq : a ∆ b = a ⊓ bᶜ ⊔ b ⊓ aᶜ := by simp only [(· ∆ ·), sdiff_eq]
theorem bihimp_eq : a ⇔ b = (a ⊔ bᶜ) ⊓ (b ⊔ aᶜ) := by simp only [(· ⇔ ·), himp_eq]
theorem symmDiff_eq' : a ∆ b = (a ⊔ b) ⊓ (aᶜ ⊔ bᶜ) := by
rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq, compl_inf]
theorem bihimp_eq' : a ⇔ b = a ⊓ b ⊔ aᶜ ⊓ bᶜ :=
@symmDiff_eq' αᵒᵈ _ _ _
theorem symmDiff_top : a ∆ ⊤ = aᶜ :=
symmDiff_top' _
theorem top_symmDiff : ⊤ ∆ a = aᶜ :=
top_symmDiff' _
@[simp]
theorem compl_symmDiff : (a ∆ b)ᶜ = a ⇔ b := by
simp_rw [symmDiff, compl_sup_distrib, compl_sdiff, bihimp, inf_comm]
@[simp]
theorem compl_bihimp : (a ⇔ b)ᶜ = a ∆ b :=
@compl_symmDiff αᵒᵈ _ _ _
@[simp]
theorem compl_symmDiff_compl : aᶜ ∆ bᶜ = a ∆ b :=
(sup_comm _ _).trans <| by simp_rw [compl_sdiff_compl, sdiff_eq, symmDiff_eq]
@[simp]
theorem compl_bihimp_compl : aᶜ ⇔ bᶜ = a ⇔ b :=
@compl_symmDiff_compl αᵒᵈ _ _ _
@[simp]
theorem symmDiff_eq_top : a ∆ b = ⊤ ↔ IsCompl a b := by
rw [symmDiff_eq', ← compl_inf, inf_eq_top_iff, compl_eq_top, isCompl_iff, disjoint_iff,
codisjoint_iff, and_comm]
@[simp]
theorem bihimp_eq_bot : a ⇔ b = ⊥ ↔ IsCompl a b := by
rw [bihimp_eq', ← compl_sup, sup_eq_bot_iff, compl_eq_bot, isCompl_iff, disjoint_iff,
codisjoint_iff]
@[simp]
theorem compl_symmDiff_self : aᶜ ∆ a = ⊤ :=
hnot_symmDiff_self _
@[simp]
theorem symmDiff_compl_self : a ∆ aᶜ = ⊤ :=
symmDiff_hnot_self _
theorem symmDiff_symmDiff_right' :
a ∆ (b ∆ c) = a ⊓ b ⊓ c ⊔ a ⊓ bᶜ ⊓ cᶜ ⊔ aᶜ ⊓ b ⊓ cᶜ ⊔ aᶜ ⊓ bᶜ ⊓ c :=
calc
a ∆ (b ∆ c) = a ⊓ (b ⊓ c ⊔ bᶜ ⊓ cᶜ) ⊔ (b ⊓ cᶜ ⊔ c ⊓ bᶜ) ⊓ aᶜ := by
{ rw [symmDiff_eq, compl_symmDiff, bihimp_eq', symmDiff_eq] }
_ = a ⊓ b ⊓ c ⊔ a ⊓ bᶜ ⊓ cᶜ ⊔ b ⊓ cᶜ ⊓ aᶜ ⊔ c ⊓ bᶜ ⊓ aᶜ := by
{ rw [inf_sup_left, inf_sup_right, ← sup_assoc, ← inf_assoc, ← inf_assoc] }
_ = a ⊓ b ⊓ c ⊔ a ⊓ bᶜ ⊓ cᶜ ⊔ aᶜ ⊓ b ⊓ cᶜ ⊔ aᶜ ⊓ bᶜ ⊓ c := (by
congr 1
· congr 1
rw [inf_comm, inf_assoc]
· apply inf_left_right_swap)
variable {a b c}
theorem Disjoint.le_symmDiff_sup_symmDiff_left (h : Disjoint a b) : c ≤ a ∆ c ⊔ b ∆ c := by
trans c \ (a ⊓ b)
· rw [h.eq_bot, sdiff_bot]
· rw [sdiff_inf]
exact sup_le_sup le_sup_right le_sup_right
theorem Disjoint.le_symmDiff_sup_symmDiff_right (h : Disjoint b c) : a ≤ a ∆ b ⊔ a ∆ c := by
simp_rw [symmDiff_comm a]
exact h.le_symmDiff_sup_symmDiff_left
theorem Codisjoint.bihimp_inf_bihimp_le_left (h : Codisjoint a b) : a ⇔ c ⊓ b ⇔ c ≤ c :=
h.dual.le_symmDiff_sup_symmDiff_left
theorem Codisjoint.bihimp_inf_bihimp_le_right (h : Codisjoint b c) : a ⇔ b ⊓ a ⇔ c ≤ a :=
h.dual.le_symmDiff_sup_symmDiff_right
end BooleanAlgebra
/-! ### Prod -/
section Prod
@[simp]
theorem symmDiff_fst [GeneralizedCoheytingAlgebra α] [GeneralizedCoheytingAlgebra β]
(a b : α × β) : (a ∆ b).1 = a.1 ∆ b.1 :=
rfl
@[simp]
theorem symmDiff_snd [GeneralizedCoheytingAlgebra α] [GeneralizedCoheytingAlgebra β]
(a b : α × β) : (a ∆ b).2 = a.2 ∆ b.2 :=
rfl
@[simp]
theorem bihimp_fst [GeneralizedHeytingAlgebra α] [GeneralizedHeytingAlgebra β] (a b : α × β) :
(a ⇔ b).1 = a.1 ⇔ b.1 :=
rfl
@[simp]
theorem bihimp_snd [GeneralizedHeytingAlgebra α] [GeneralizedHeytingAlgebra β] (a b : α × β) :
(a ⇔ b).2 = a.2 ⇔ b.2 :=
rfl
end Prod
/-! ### Pi -/
namespace Pi
theorem symmDiff_def [∀ i, GeneralizedCoheytingAlgebra (π i)] (a b : ∀ i, π i) :
a ∆ b = fun i => a i ∆ b i :=
rfl
theorem bihimp_def [∀ i, GeneralizedHeytingAlgebra (π i)] (a b : ∀ i, π i) :
a ⇔ b = fun i => a i ⇔ b i :=
rfl
@[simp]
theorem symmDiff_apply [∀ i, GeneralizedCoheytingAlgebra (π i)] (a b : ∀ i, π i) (i : ι) :
(a ∆ b) i = a i ∆ b i :=
rfl
@[simp]
theorem bihimp_apply [∀ i, GeneralizedHeytingAlgebra (π i)] (a b : ∀ i, π i) (i : ι) :
(a ⇔ b) i = a i ⇔ b i :=
rfl
end Pi
|
Order\Synonym.lean | /-
Copyright (c) 2020 Johan Commelin, Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Damiano Testa, Yaël Dillies
-/
import Mathlib.Logic.Equiv.Defs
import Mathlib.Logic.Nontrivial.Defs
import Mathlib.Order.Basic
/-!
# Type synonyms
This file provides two type synonyms for order theory:
* `OrderDual α`: Type synonym of `α` to equip it with the dual order (`a ≤ b` becomes `b ≤ a`).
* `Lex α`: Type synonym of `α` to equip it with its lexicographic order. The precise meaning depends
on the type we take the lex of. Examples include `Prod`, `Sigma`, `List`, `Finset`.
## Notation
`αᵒᵈ` is notation for `OrderDual α`.
The general rule for notation of `Lex` types is to append `ₗ` to the usual notation.
## Implementation notes
One should not abuse definitional equality between `α` and `αᵒᵈ`/`Lex α`. Instead, explicit
coercions should be inserted:
* `OrderDual`: `OrderDual.toDual : α → αᵒᵈ` and `OrderDual.ofDual : αᵒᵈ → α`
* `Lex`: `toLex : α → Lex α` and `ofLex : Lex α → α`.
## See also
This file is similar to `Algebra.Group.TypeTags`.
-/
variable {α β γ : Type*}
/-! ### Order dual -/
namespace OrderDual
instance [h : Nontrivial α] : Nontrivial αᵒᵈ :=
h
/-- `toDual` is the identity function to the `OrderDual` of a linear order. -/
def toDual : α ≃ αᵒᵈ :=
Equiv.refl _
/-- `ofDual` is the identity function from the `OrderDual` of a linear order. -/
def ofDual : αᵒᵈ ≃ α :=
Equiv.refl _
@[simp]
theorem toDual_symm_eq : (@toDual α).symm = ofDual := rfl
@[simp]
theorem ofDual_symm_eq : (@ofDual α).symm = toDual := rfl
@[simp]
theorem toDual_ofDual (a : αᵒᵈ) : toDual (ofDual a) = a :=
rfl
@[simp]
theorem ofDual_toDual (a : α) : ofDual (toDual a) = a :=
rfl
-- Porting note:
-- removed @[simp] since this already follows by `simp only [EmbeddingLike.apply_eq_iff_eq]`
theorem toDual_inj {a b : α} : toDual a = toDual b ↔ a = b :=
Iff.rfl
-- Porting note:
-- removed @[simp] since this already follows by `simp only [EmbeddingLike.apply_eq_iff_eq]`
theorem ofDual_inj {a b : αᵒᵈ} : ofDual a = ofDual b ↔ a = b :=
Iff.rfl
@[simp]
theorem toDual_le_toDual [LE α] {a b : α} : toDual a ≤ toDual b ↔ b ≤ a :=
Iff.rfl
@[simp]
theorem toDual_lt_toDual [LT α] {a b : α} : toDual a < toDual b ↔ b < a :=
Iff.rfl
@[simp]
theorem ofDual_le_ofDual [LE α] {a b : αᵒᵈ} : ofDual a ≤ ofDual b ↔ b ≤ a :=
Iff.rfl
@[simp]
theorem ofDual_lt_ofDual [LT α] {a b : αᵒᵈ} : ofDual a < ofDual b ↔ b < a :=
Iff.rfl
theorem le_toDual [LE α] {a : αᵒᵈ} {b : α} : a ≤ toDual b ↔ b ≤ ofDual a :=
Iff.rfl
theorem lt_toDual [LT α] {a : αᵒᵈ} {b : α} : a < toDual b ↔ b < ofDual a :=
Iff.rfl
theorem toDual_le [LE α] {a : α} {b : αᵒᵈ} : toDual a ≤ b ↔ ofDual b ≤ a :=
Iff.rfl
theorem toDual_lt [LT α] {a : α} {b : αᵒᵈ} : toDual a < b ↔ ofDual b < a :=
Iff.rfl
/-- Recursor for `αᵒᵈ`. -/
@[elab_as_elim]
protected def rec {C : αᵒᵈ → Sort*} (h₂ : ∀ a : α, C (toDual a)) : ∀ a : αᵒᵈ, C a :=
h₂
@[simp]
protected theorem «forall» {p : αᵒᵈ → Prop} : (∀ a, p a) ↔ ∀ a, p (toDual a) :=
Iff.rfl
@[simp]
protected theorem «exists» {p : αᵒᵈ → Prop} : (∃ a, p a) ↔ ∃ a, p (toDual a) :=
Iff.rfl
alias ⟨_, _root_.LE.le.dual⟩ := toDual_le_toDual
alias ⟨_, _root_.LT.lt.dual⟩ := toDual_lt_toDual
alias ⟨_, _root_.LE.le.ofDual⟩ := ofDual_le_ofDual
alias ⟨_, _root_.LT.lt.ofDual⟩ := ofDual_lt_ofDual
end OrderDual
/-! ### Lexicographic order -/
/-- A type synonym to equip a type with its lexicographic order. -/
def Lex (α : Type*) :=
α
/-- `toLex` is the identity function to the `Lex` of a type. -/
@[match_pattern]
def toLex : α ≃ Lex α :=
Equiv.refl _
/-- `ofLex` is the identity function from the `Lex` of a type. -/
@[match_pattern]
def ofLex : Lex α ≃ α :=
Equiv.refl _
@[simp]
theorem toLex_symm_eq : (@toLex α).symm = ofLex :=
rfl
@[simp]
theorem ofLex_symm_eq : (@ofLex α).symm = toLex :=
rfl
@[simp]
theorem toLex_ofLex (a : Lex α) : toLex (ofLex a) = a :=
rfl
@[simp]
theorem ofLex_toLex (a : α) : ofLex (toLex a) = a :=
rfl
-- Porting note:
-- removed @[simp] since this already follows by `simp only [EmbeddingLike.apply_eq_iff_eq]`
theorem toLex_inj {a b : α} : toLex a = toLex b ↔ a = b :=
Iff.rfl
-- Porting note:
-- removed @[simp] since this already follows by `simp only [EmbeddingLike.apply_eq_iff_eq]`
theorem ofLex_inj {a b : Lex α} : ofLex a = ofLex b ↔ a = b :=
Iff.rfl
/-- A recursor for `Lex`. Use as `induction x`. -/
@[elab_as_elim, induction_eliminator, cases_eliminator]
protected def Lex.rec {β : Lex α → Sort*} (h : ∀ a, β (toLex a)) : ∀ a, β a := fun a => h (ofLex a)
@[simp] lemma Lex.forall {p : Lex α → Prop} : (∀ a, p a) ↔ ∀ a, p (toLex a) := Iff.rfl
@[simp] lemma Lex.exists {p : Lex α → Prop} : (∃ a, p a) ↔ ∃ a, p (toLex a) := Iff.rfl
|
Order\ULift.lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Logic.Function.ULift
import Mathlib.Order.Basic
/-! # Ordered structures on `ULift.{v} α`
Once these basic instances are setup, the instances of more complex typeclasses should live next to
the corresponding `Prod` instances.
-/
namespace ULift
universe v u
variable {α : Type u}
instance [LE α] : LE (ULift.{v} α) where le x y := x.down ≤ y.down
@[simp] theorem up_le [LE α] {a b : α} : up a ≤ up b ↔ a ≤ b := Iff.rfl
@[simp] theorem down_le [LE α] {a b : ULift α} : down a ≤ down b ↔ a ≤ b := Iff.rfl
instance [LT α] : LT (ULift.{v} α) where lt x y := x.down < y.down
@[simp] theorem up_lt [LT α] {a b : α} : up a < up b ↔ a < b := Iff.rfl
@[simp] theorem down_lt [LT α] {a b : ULift α} : down a < down b ↔ a < b := Iff.rfl
instance [Ord α] : Ord (ULift.{v} α) where compare x y := compare x.down y.down
@[simp] theorem up_compare [Ord α] (a b : α) : compare (up a) (up b) = compare a b := rfl
@[simp] theorem down_compare [Ord α] (a b : ULift α) :
compare (down a) (down b) = compare a b := rfl
instance [Sup α] : Sup (ULift.{v} α) where sup x y := up <| x.down ⊔ y.down
@[simp] theorem up_sup [Sup α] (a b : α) : up (a ⊔ b) = up a ⊔ up b := rfl
@[simp] theorem down_sup [Sup α] (a b : ULift α) : down (a ⊔ b) = down a ⊔ down b := rfl
instance [Inf α] : Inf (ULift.{v} α) where inf x y := up <| x.down ⊓ y.down
@[simp] theorem up_inf [Inf α] (a b : α) : up (a ⊓ b) = up a ⊓ up b := rfl
@[simp] theorem down_inf [Inf α] (a b : ULift α) : down (a ⊓ b) = down a ⊓ down b := rfl
instance [SDiff α] : SDiff (ULift.{v} α) where sdiff x y := up <| x.down \ y.down
@[simp] theorem up_sdiff [SDiff α] (a b : α) : up (a \ b) = up a \ up b := rfl
@[simp] theorem down_sdiff [SDiff α] (a b : ULift α) : down (a \ b) = down a \ down b := rfl
instance [HasCompl α] : HasCompl (ULift.{v} α) where compl x := up <| x.downᶜ
@[simp] theorem up_compl [HasCompl α] (a : α) : up (aᶜ) = (up a)ᶜ := rfl
@[simp] theorem down_compl [HasCompl α] (a : ULift α) : down aᶜ = (down a)ᶜ := rfl
instance [Preorder α] : Preorder (ULift.{v} α) :=
Preorder.lift ULift.down
instance [PartialOrder α] : PartialOrder (ULift.{v} α) :=
PartialOrder.lift ULift.down ULift.down_injective
end ULift
|
Order\WellFounded.lean | /-
Copyright (c) 2020 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Data.Set.Basic
/-!
# Well-founded relations
A relation is well-founded if it can be used for induction: for each `x`, `(∀ y, r y x → P y) → P x`
implies `P x`. Well-founded relations can be used for induction and recursion, including
construction of fixed points in the space of dependent functions `Π x : α , β x`.
The predicate `WellFounded` is defined in the core library. In this file we prove some extra lemmas
and provide a few new definitions: `WellFounded.min`, `WellFounded.sup`, and `WellFounded.succ`,
and an induction principle `WellFounded.induction_bot`.
-/
variable {α β γ : Type*}
namespace WellFounded
variable {r r' : α → α → Prop}
protected theorem isAsymm (h : WellFounded r) : IsAsymm α r := ⟨h.asymmetric⟩
protected theorem isIrrefl (h : WellFounded r) : IsIrrefl α r := @IsAsymm.isIrrefl α r h.isAsymm
instance [WellFoundedRelation α] : IsAsymm α WellFoundedRelation.rel :=
WellFoundedRelation.wf.isAsymm
instance : IsIrrefl α WellFoundedRelation.rel := IsAsymm.isIrrefl
theorem mono (hr : WellFounded r) (h : ∀ a b, r' a b → r a b) : WellFounded r' :=
Subrelation.wf (h _ _) hr
theorem onFun {α β : Sort*} {r : β → β → Prop} {f : α → β} :
WellFounded r → WellFounded (r on f) :=
InvImage.wf _
/-- If `r` is a well-founded relation, then any nonempty set has a minimal element
with respect to `r`. -/
theorem has_min {α} {r : α → α → Prop} (H : WellFounded r) (s : Set α) :
s.Nonempty → ∃ a ∈ s, ∀ x ∈ s, ¬r x a
| ⟨a, ha⟩ => show ∃ b ∈ s, ∀ x ∈ s, ¬r x b from
Acc.recOn (H.apply a) (fun x _ IH =>
not_imp_not.1 fun hne hx => hne <| ⟨x, hx, fun y hy hyx => hne <| IH y hyx hy⟩)
ha
/-- A minimal element of a nonempty set in a well-founded order.
If you're working with a nonempty linear order, consider defining a
`ConditionallyCompleteLinearOrderBot` instance via
`WellFounded.conditionallyCompleteLinearOrderWithBot` and using `Inf` instead. -/
noncomputable def min {r : α → α → Prop} (H : WellFounded r) (s : Set α) (h : s.Nonempty) : α :=
Classical.choose (H.has_min s h)
theorem min_mem {r : α → α → Prop} (H : WellFounded r) (s : Set α) (h : s.Nonempty) :
H.min s h ∈ s :=
let ⟨h, _⟩ := Classical.choose_spec (H.has_min s h)
h
theorem not_lt_min {r : α → α → Prop} (H : WellFounded r) (s : Set α) (h : s.Nonempty) {x}
(hx : x ∈ s) : ¬r x (H.min s h) :=
let ⟨_, h'⟩ := Classical.choose_spec (H.has_min s h)
h' _ hx
theorem wellFounded_iff_has_min {r : α → α → Prop} :
WellFounded r ↔ ∀ s : Set α, s.Nonempty → ∃ m ∈ s, ∀ x ∈ s, ¬r x m := by
refine ⟨fun h => h.has_min, fun h => ⟨fun x => ?_⟩⟩
by_contra hx
obtain ⟨m, hm, hm'⟩ := h {x | ¬Acc r x} ⟨x, hx⟩
refine hm ⟨_, fun y hy => ?_⟩
by_contra hy'
exact hm' y hy' hy
open Set
/-- The supremum of a bounded, well-founded order -/
protected noncomputable def sup {r : α → α → Prop} (wf : WellFounded r) (s : Set α)
(h : Bounded r s) : α :=
wf.min { x | ∀ a ∈ s, r a x } h
protected theorem lt_sup {r : α → α → Prop} (wf : WellFounded r) {s : Set α} (h : Bounded r s) {x}
(hx : x ∈ s) : r x (wf.sup s h) :=
min_mem wf { x | ∀ a ∈ s, r a x } h x hx
section
open Classical in
/-- A successor of an element `x` in a well-founded order is a minimal element `y` such that
`x < y` if one exists. Otherwise it is `x` itself. -/
protected noncomputable def succ {r : α → α → Prop} (wf : WellFounded r) (x : α) : α :=
if h : ∃ y, r x y then wf.min { y | r x y } h else x
protected theorem lt_succ {r : α → α → Prop} (wf : WellFounded r) {x : α} (h : ∃ y, r x y) :
r x (wf.succ x) := by
rw [WellFounded.succ, dif_pos h]
apply min_mem
end
protected theorem lt_succ_iff {r : α → α → Prop} [wo : IsWellOrder α r] {x : α} (h : ∃ y, r x y)
(y : α) : r y (wo.wf.succ x) ↔ r y x ∨ y = x := by
constructor
· intro h'
have : ¬r x y := by
intro hy
rw [WellFounded.succ, dif_pos] at h'
exact wo.wf.not_lt_min _ h hy h'
rcases trichotomous_of r x y with (hy | hy | hy)
· exfalso
exact this hy
· right
exact hy.symm
left
exact hy
rintro (hy | rfl); (· exact _root_.trans hy (wo.wf.lt_succ h)); exact wo.wf.lt_succ h
section LinearOrder
variable [LinearOrder β] [PartialOrder γ]
theorem min_le (h : WellFounded ((· < ·) : β → β → Prop)) {x : β} {s : Set β} (hx : x ∈ s)
(hne : s.Nonempty := ⟨x, hx⟩) : h.min s hne ≤ x :=
not_lt.1 <| h.not_lt_min _ _ hx
private theorem eq_strictMono_iff_eq_range_aux {f g : β → γ} (hf : StrictMono f)
(hg : StrictMono g) (hfg : Set.range f = Set.range g) {b : β} (H : ∀ a < b, f a = g a) :
f b ≤ g b := by
obtain ⟨c, hc⟩ : g b ∈ Set.range f := by
rw [hfg]
exact Set.mem_range_self b
cases' lt_or_le c b with hcb hbc
· rw [H c hcb] at hc
rw [hg.injective hc] at hcb
exact hcb.false.elim
· rw [← hc]
exact hf.monotone hbc
theorem eq_strictMono_iff_eq_range (h : WellFounded ((· < ·) : β → β → Prop)) {f g : β → γ}
(hf : StrictMono f) (hg : StrictMono g) :
Set.range f = Set.range g ↔ f = g :=
⟨fun hfg => by
funext a
apply h.induction a
exact fun b H =>
le_antisymm (eq_strictMono_iff_eq_range_aux hf hg hfg H)
(eq_strictMono_iff_eq_range_aux hg hf hfg.symm fun a hab => (H a hab).symm),
congr_arg _⟩
theorem self_le_of_strictMono (h : WellFounded ((· < ·) : β → β → Prop)) {f : β → β}
(hf : StrictMono f) : ∀ n, n ≤ f n := by
by_contra! h₁
have h₂ := h.min_mem _ h₁
exact h.not_lt_min _ h₁ (hf h₂) h₂
end LinearOrder
end WellFounded
namespace Function
variable (f : α → β)
section LT
variable [LT β] (h : WellFounded ((· < ·) : β → β → Prop))
/-- Given a function `f : α → β` where `β` carries a well-founded `<`, this is an element of `α`
whose image under `f` is minimal in the sense of `Function.not_lt_argmin`. -/
noncomputable def argmin [Nonempty α] : α :=
WellFounded.min (InvImage.wf f h) Set.univ Set.univ_nonempty
theorem not_lt_argmin [Nonempty α] (a : α) : ¬f a < f (argmin f h) :=
WellFounded.not_lt_min (InvImage.wf f h) _ _ (Set.mem_univ a)
/-- Given a function `f : α → β` where `β` carries a well-founded `<`, and a non-empty subset `s`
of `α`, this is an element of `s` whose image under `f` is minimal in the sense of
`Function.not_lt_argminOn`. -/
noncomputable def argminOn (s : Set α) (hs : s.Nonempty) : α :=
WellFounded.min (InvImage.wf f h) s hs
@[simp]
theorem argminOn_mem (s : Set α) (hs : s.Nonempty) : argminOn f h s hs ∈ s :=
WellFounded.min_mem _ _ _
-- Porting note (#11119): @[simp] removed as it will never apply
theorem not_lt_argminOn (s : Set α) {a : α} (ha : a ∈ s)
(hs : s.Nonempty := Set.nonempty_of_mem ha) : ¬f a < f (argminOn f h s hs) :=
WellFounded.not_lt_min (InvImage.wf f h) s hs ha
end LT
section LinearOrder
variable [LinearOrder β] (h : WellFounded ((· < ·) : β → β → Prop))
-- Porting note (#11119): @[simp] removed as it will never apply
theorem argmin_le (a : α) [Nonempty α] : f (argmin f h) ≤ f a :=
not_lt.mp <| not_lt_argmin f h a
-- Porting note (#11119): @[simp] removed as it will never apply
theorem argminOn_le (s : Set α) {a : α} (ha : a ∈ s) (hs : s.Nonempty := Set.nonempty_of_mem ha) :
f (argminOn f h s hs) ≤ f a :=
not_lt.mp <| not_lt_argminOn f h s ha hs
end LinearOrder
end Function
section Induction
/-- Let `r` be a relation on `α`, let `f : α → β` be a function, let `C : β → Prop`, and
let `bot : α`. This induction principle shows that `C (f bot)` holds, given that
* some `a` that is accessible by `r` satisfies `C (f a)`, and
* for each `b` such that `f b ≠ f bot` and `C (f b)` holds, there is `c`
satisfying `r c b` and `C (f c)`. -/
theorem Acc.induction_bot' {α β} {r : α → α → Prop} {a bot : α} (ha : Acc r a) {C : β → Prop}
{f : α → β} (ih : ∀ b, f b ≠ f bot → C (f b) → ∃ c, r c b ∧ C (f c)) : C (f a) → C (f bot) :=
(@Acc.recOn _ _ (fun x _ => C (f x) → C (f bot)) _ ha) fun x _ ih' hC =>
(eq_or_ne (f x) (f bot)).elim (fun h => h ▸ hC) (fun h =>
let ⟨y, hy₁, hy₂⟩ := ih x h hC
ih' y hy₁ hy₂)
/-- Let `r` be a relation on `α`, let `C : α → Prop` and let `bot : α`.
This induction principle shows that `C bot` holds, given that
* some `a` that is accessible by `r` satisfies `C a`, and
* for each `b ≠ bot` such that `C b` holds, there is `c` satisfying `r c b` and `C c`. -/
theorem Acc.induction_bot {α} {r : α → α → Prop} {a bot : α} (ha : Acc r a) {C : α → Prop}
(ih : ∀ b, b ≠ bot → C b → ∃ c, r c b ∧ C c) : C a → C bot :=
ha.induction_bot' ih
/-- Let `r` be a well-founded relation on `α`, let `f : α → β` be a function,
let `C : β → Prop`, and let `bot : α`.
This induction principle shows that `C (f bot)` holds, given that
* some `a` satisfies `C (f a)`, and
* for each `b` such that `f b ≠ f bot` and `C (f b)` holds, there is `c`
satisfying `r c b` and `C (f c)`. -/
theorem WellFounded.induction_bot' {α β} {r : α → α → Prop} (hwf : WellFounded r) {a bot : α}
{C : β → Prop} {f : α → β} (ih : ∀ b, f b ≠ f bot → C (f b) → ∃ c, r c b ∧ C (f c)) :
C (f a) → C (f bot) :=
(hwf.apply a).induction_bot' ih
/-- Let `r` be a well-founded relation on `α`, let `C : α → Prop`, and let `bot : α`.
This induction principle shows that `C bot` holds, given that
* some `a` satisfies `C a`, and
* for each `b` that satisfies `C b`, there is `c` satisfying `r c b` and `C c`.
The naming is inspired by the fact that when `r` is transitive, it follows that `bot` is
the smallest element w.r.t. `r` that satisfies `C`. -/
theorem WellFounded.induction_bot {α} {r : α → α → Prop} (hwf : WellFounded r) {a bot : α}
{C : α → Prop} (ih : ∀ b, b ≠ bot → C b → ∃ c, r c b ∧ C c) : C a → C bot :=
hwf.induction_bot' ih
end Induction
section WellFoundedLT
variable [Preorder α] [Preorder β] {f : α → β}
theorem StrictMono.wellFoundedLT [WellFoundedLT β] (hf : StrictMono f) : WellFoundedLT α where
wf := WellFounded.wellFounded_iff_has_min.2 fun s hne ↦ by
have hs' : (f '' s).Nonempty := ⟨f hne.some, _, hne.some_mem, rfl⟩
obtain ⟨x, hx, hex⟩ := WellFounded.min_mem wellFounded_lt (f '' s) hs'
refine ⟨x, hx, fun y hy hlt ↦ ?_⟩
apply WellFounded.not_lt_min wellFounded_lt (s.image f) hs' (Set.mem_image_of_mem _ hy)
rw [← hex]
exact hf hlt
theorem StrictAnti.wellFoundedLT [WellFoundedGT β] (hf : StrictAnti f) : WellFoundedLT α :=
StrictMono.wellFoundedLT (β := βᵒᵈ) hf
theorem StrictMono.wellFoundedGT [WellFoundedGT β] (hf : StrictMono f) : WellFoundedGT α :=
StrictMono.wellFoundedLT (α := αᵒᵈ) (β := βᵒᵈ) (fun _ _ h ↦ hf h)
theorem StrictAnti.wellFoundedGT [WellFoundedLT β] (hf : StrictAnti f) : WellFoundedGT α :=
StrictMono.wellFoundedLT (α := αᵒᵈ) (fun _ _ h ↦ hf h)
end WellFoundedLT
|
Order\WellFoundedSet.lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Init.Data.Sigma.Lex
import Mathlib.Data.Prod.Lex
import Mathlib.Data.Sigma.Lex
import Mathlib.Order.Antichain
import Mathlib.Order.OrderIsoNat
import Mathlib.Order.WellFounded
import Mathlib.Tactic.TFAE
/-!
# Well-founded sets
A well-founded subset of an ordered type is one on which the relation `<` is well-founded.
## Main Definitions
* `Set.WellFoundedOn s r` indicates that the relation `r` is
well-founded when restricted to the set `s`.
* `Set.IsWF s` indicates that `<` is well-founded when restricted to `s`.
* `Set.PartiallyWellOrderedOn s r` indicates that the relation `r` is
partially well-ordered (also known as well quasi-ordered) when restricted to the set `s`.
* `Set.IsPWO s` indicates that any infinite sequence of elements in `s` contains an infinite
monotone subsequence. Note that this is equivalent to containing only two comparable elements.
## Main Results
* Higman's Lemma, `Set.PartiallyWellOrderedOn.partiallyWellOrderedOn_sublistForall₂`,
shows that if `r` is partially well-ordered on `s`, then `List.SublistForall₂` is partially
well-ordered on the set of lists of elements of `s`. The result was originally published by
Higman, but this proof more closely follows Nash-Williams.
* `Set.wellFoundedOn_iff` relates `well_founded_on` to the well-foundedness of a relation on the
original type, to avoid dealing with subtypes.
* `Set.IsWF.mono` shows that a subset of a well-founded subset is well-founded.
* `Set.IsWF.union` shows that the union of two well-founded subsets is well-founded.
* `Finset.isWF` shows that all `Finset`s are well-founded.
## TODO
Prove that `s` is partial well ordered iff it has no infinite descending chain or antichain.
## References
* [Higman, *Ordering by Divisibility in Abstract Algebras*][Higman52]
* [Nash-Williams, *On Well-Quasi-Ordering Finite Trees*][Nash-Williams63]
-/
assert_not_exists OrderedSemiring
variable {ι α β γ : Type*} {π : ι → Type*}
namespace Set
/-! ### Relations well-founded on sets -/
/-- `s.WellFoundedOn r` indicates that the relation `r` is well-founded when restricted to `s`. -/
def WellFoundedOn (s : Set α) (r : α → α → Prop) : Prop :=
WellFounded fun a b : s => r a b
@[simp]
theorem wellFoundedOn_empty (r : α → α → Prop) : WellFoundedOn ∅ r :=
wellFounded_of_isEmpty _
section WellFoundedOn
variable {r r' : α → α → Prop}
section AnyRel
variable {f : β → α} {s t : Set α} {x y : α}
theorem wellFoundedOn_iff :
s.WellFoundedOn r ↔ WellFounded fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s := by
have f : RelEmbedding (fun (a : s) (b : s) => r a b) fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s :=
⟨⟨(↑), Subtype.coe_injective⟩, by simp⟩
refine ⟨fun h => ?_, f.wellFounded⟩
rw [WellFounded.wellFounded_iff_has_min]
intro t ht
by_cases hst : (s ∩ t).Nonempty
· rw [← Subtype.preimage_coe_nonempty] at hst
rcases h.has_min (Subtype.val ⁻¹' t) hst with ⟨⟨m, ms⟩, mt, hm⟩
exact ⟨m, mt, fun x xt ⟨xm, xs, _⟩ => hm ⟨x, xs⟩ xt xm⟩
· rcases ht with ⟨m, mt⟩
exact ⟨m, mt, fun x _ ⟨_, _, ms⟩ => hst ⟨m, ⟨ms, mt⟩⟩⟩
@[simp]
theorem wellFoundedOn_univ : (univ : Set α).WellFoundedOn r ↔ WellFounded r := by
simp [wellFoundedOn_iff]
theorem _root_.WellFounded.wellFoundedOn : WellFounded r → s.WellFoundedOn r :=
InvImage.wf _
@[simp]
theorem wellFoundedOn_range : (range f).WellFoundedOn r ↔ WellFounded (r on f) := by
let f' : β → range f := fun c => ⟨f c, c, rfl⟩
refine ⟨fun h => (InvImage.wf f' h).mono fun c c' => id, fun h => ⟨?_⟩⟩
rintro ⟨_, c, rfl⟩
refine Acc.of_downward_closed f' ?_ _ ?_
· rintro _ ⟨_, c', rfl⟩ -
exact ⟨c', rfl⟩
· exact h.apply _
@[simp]
theorem wellFoundedOn_image {s : Set β} : (f '' s).WellFoundedOn r ↔ s.WellFoundedOn (r on f) := by
rw [image_eq_range]; exact wellFoundedOn_range
namespace WellFoundedOn
protected theorem induction (hs : s.WellFoundedOn r) (hx : x ∈ s) {P : α → Prop}
(hP : ∀ y ∈ s, (∀ z ∈ s, r z y → P z) → P y) : P x := by
let Q : s → Prop := fun y => P y
change Q ⟨x, hx⟩
refine WellFounded.induction hs ⟨x, hx⟩ ?_
simpa only [Subtype.forall]
protected theorem mono (h : t.WellFoundedOn r') (hle : r ≤ r') (hst : s ⊆ t) :
s.WellFoundedOn r := by
rw [wellFoundedOn_iff] at *
exact Subrelation.wf (fun xy => ⟨hle _ _ xy.1, hst xy.2.1, hst xy.2.2⟩) h
theorem mono' (h : ∀ (a) (_ : a ∈ s) (b) (_ : b ∈ s), r' a b → r a b) :
s.WellFoundedOn r → s.WellFoundedOn r' :=
Subrelation.wf @fun a b => h _ a.2 _ b.2
theorem subset (h : t.WellFoundedOn r) (hst : s ⊆ t) : s.WellFoundedOn r :=
h.mono le_rfl hst
open Relation
open List in
/-- `a` is accessible under the relation `r` iff `r` is well-founded on the downward transitive
closure of `a` under `r` (including `a` or not). -/
theorem acc_iff_wellFoundedOn {α} {r : α → α → Prop} {a : α} :
TFAE [Acc r a,
WellFoundedOn { b | ReflTransGen r b a } r,
WellFoundedOn { b | TransGen r b a } r] := by
tfae_have 1 → 2
· refine fun h => ⟨fun b => InvImage.accessible _ ?_⟩
rw [← acc_transGen_iff] at h ⊢
obtain h' | h' := reflTransGen_iff_eq_or_transGen.1 b.2
· rwa [h'] at h
· exact h.inv h'
tfae_have 2 → 3
· exact fun h => h.subset fun _ => TransGen.to_reflTransGen
tfae_have 3 → 1
· refine fun h => Acc.intro _ (fun b hb => (h.apply ⟨b, .single hb⟩).of_fibration Subtype.val ?_)
exact fun ⟨c, hc⟩ d h => ⟨⟨d, .head h hc⟩, h, rfl⟩
tfae_finish
end WellFoundedOn
end AnyRel
section IsStrictOrder
variable [IsStrictOrder α r] {s t : Set α}
instance IsStrictOrder.subset : IsStrictOrder α fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s where
toIsIrrefl := ⟨fun a con => irrefl_of r a con.1⟩
toIsTrans := ⟨fun _ _ _ ab bc => ⟨trans_of r ab.1 bc.1, ab.2.1, bc.2.2⟩⟩
theorem wellFoundedOn_iff_no_descending_seq :
s.WellFoundedOn r ↔ ∀ f : ((· > ·) : ℕ → ℕ → Prop) ↪r r, ¬∀ n, f n ∈ s := by
simp only [wellFoundedOn_iff, RelEmbedding.wellFounded_iff_no_descending_seq, ← not_exists, ←
not_nonempty_iff, not_iff_not]
constructor
· rintro ⟨⟨f, hf⟩⟩
have H : ∀ n, f n ∈ s := fun n => (hf.2 n.lt_succ_self).2.2
refine ⟨⟨f, ?_⟩, H⟩
simpa only [H, and_true_iff] using @hf
· rintro ⟨⟨f, hf⟩, hfs : ∀ n, f n ∈ s⟩
refine ⟨⟨f, ?_⟩⟩
simpa only [hfs, and_true_iff] using @hf
theorem WellFoundedOn.union (hs : s.WellFoundedOn r) (ht : t.WellFoundedOn r) :
(s ∪ t).WellFoundedOn r := by
rw [wellFoundedOn_iff_no_descending_seq] at *
rintro f hf
rcases Nat.exists_subseq_of_forall_mem_union f hf with ⟨g, hg | hg⟩
exacts [hs (g.dual.ltEmbedding.trans f) hg, ht (g.dual.ltEmbedding.trans f) hg]
@[simp]
theorem wellFoundedOn_union : (s ∪ t).WellFoundedOn r ↔ s.WellFoundedOn r ∧ t.WellFoundedOn r :=
⟨fun h => ⟨h.subset subset_union_left, h.subset subset_union_right⟩, fun h =>
h.1.union h.2⟩
end IsStrictOrder
end WellFoundedOn
/-! ### Sets well-founded w.r.t. the strict inequality -/
section LT
variable [LT α] {s t : Set α}
/-- `s.IsWF` indicates that `<` is well-founded when restricted to `s`. -/
def IsWF (s : Set α) : Prop :=
WellFoundedOn s (· < ·)
@[simp]
theorem isWF_empty : IsWF (∅ : Set α) :=
wellFounded_of_isEmpty _
theorem isWF_univ_iff : IsWF (univ : Set α) ↔ WellFounded ((· < ·) : α → α → Prop) := by
simp [IsWF, wellFoundedOn_iff]
theorem IsWF.mono (h : IsWF t) (st : s ⊆ t) : IsWF s := h.subset st
end LT
section Preorder
variable [Preorder α] {s t : Set α} {a : α}
protected nonrec theorem IsWF.union (hs : IsWF s) (ht : IsWF t) : IsWF (s ∪ t) := hs.union ht
@[simp] theorem isWF_union : IsWF (s ∪ t) ↔ IsWF s ∧ IsWF t := wellFoundedOn_union
end Preorder
section Preorder
variable [Preorder α] {s t : Set α} {a : α}
theorem isWF_iff_no_descending_seq :
IsWF s ↔ ∀ f : ℕ → α, StrictAnti f → ¬∀ n, f (OrderDual.toDual n) ∈ s :=
wellFoundedOn_iff_no_descending_seq.trans
⟨fun H f hf => H ⟨⟨f, hf.injective⟩, hf.lt_iff_lt⟩, fun H f => H f fun _ _ => f.map_rel_iff.2⟩
end Preorder
/-!
### Partially well-ordered sets
A set is partially well-ordered by a relation `r` when any infinite sequence contains two elements
where the first is related to the second by `r`. Equivalently, any antichain (see `IsAntichain`) is
finite, see `Set.partiallyWellOrderedOn_iff_finite_antichains`.
-/
/-- A subset is partially well-ordered by a relation `r` when any infinite sequence contains
two elements where the first is related to the second by `r`. -/
def PartiallyWellOrderedOn (s : Set α) (r : α → α → Prop) : Prop :=
∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ m n : ℕ, m < n ∧ r (f m) (f n)
section PartiallyWellOrderedOn
variable {r : α → α → Prop} {r' : β → β → Prop} {f : α → β} {s : Set α} {t : Set α} {a : α}
theorem PartiallyWellOrderedOn.mono (ht : t.PartiallyWellOrderedOn r) (h : s ⊆ t) :
s.PartiallyWellOrderedOn r := fun f hf => ht f fun n => h <| hf n
@[simp]
theorem partiallyWellOrderedOn_empty (r : α → α → Prop) : PartiallyWellOrderedOn ∅ r := fun _ h =>
(h 0).elim
theorem PartiallyWellOrderedOn.union (hs : s.PartiallyWellOrderedOn r)
(ht : t.PartiallyWellOrderedOn r) : (s ∪ t).PartiallyWellOrderedOn r := by
rintro f hf
rcases Nat.exists_subseq_of_forall_mem_union f hf with ⟨g, hgs | hgt⟩
· rcases hs _ hgs with ⟨m, n, hlt, hr⟩
exact ⟨g m, g n, g.strictMono hlt, hr⟩
· rcases ht _ hgt with ⟨m, n, hlt, hr⟩
exact ⟨g m, g n, g.strictMono hlt, hr⟩
@[simp]
theorem partiallyWellOrderedOn_union :
(s ∪ t).PartiallyWellOrderedOn r ↔ s.PartiallyWellOrderedOn r ∧ t.PartiallyWellOrderedOn r :=
⟨fun h => ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h =>
h.1.union h.2⟩
theorem PartiallyWellOrderedOn.image_of_monotone_on (hs : s.PartiallyWellOrderedOn r)
(hf : ∀ a₁ ∈ s, ∀ a₂ ∈ s, r a₁ a₂ → r' (f a₁) (f a₂)) : (f '' s).PartiallyWellOrderedOn r' := by
intro g' hg'
choose g hgs heq using hg'
obtain rfl : f ∘ g = g' := funext heq
obtain ⟨m, n, hlt, hmn⟩ := hs g hgs
exact ⟨m, n, hlt, hf _ (hgs m) _ (hgs n) hmn⟩
theorem _root_.IsAntichain.finite_of_partiallyWellOrderedOn (ha : IsAntichain r s)
(hp : s.PartiallyWellOrderedOn r) : s.Finite := by
refine not_infinite.1 fun hi => ?_
obtain ⟨m, n, hmn, h⟩ := hp (fun n => hi.natEmbedding _ n) fun n => (hi.natEmbedding _ n).2
exact hmn.ne ((hi.natEmbedding _).injective <| Subtype.val_injective <|
ha.eq (hi.natEmbedding _ m).2 (hi.natEmbedding _ n).2 h)
section IsRefl
variable [IsRefl α r]
protected theorem Finite.partiallyWellOrderedOn (hs : s.Finite) : s.PartiallyWellOrderedOn r := by
intro f hf
obtain ⟨m, n, hmn, h⟩ := hs.exists_lt_map_eq_of_forall_mem hf
exact ⟨m, n, hmn, h.subst <| refl (f m)⟩
theorem _root_.IsAntichain.partiallyWellOrderedOn_iff (hs : IsAntichain r s) :
s.PartiallyWellOrderedOn r ↔ s.Finite :=
⟨hs.finite_of_partiallyWellOrderedOn, Finite.partiallyWellOrderedOn⟩
@[simp]
theorem partiallyWellOrderedOn_singleton (a : α) : PartiallyWellOrderedOn {a} r :=
(finite_singleton a).partiallyWellOrderedOn
@[nontriviality]
theorem Subsingleton.partiallyWellOrderedOn (hs : s.Subsingleton) : PartiallyWellOrderedOn s r :=
hs.finite.partiallyWellOrderedOn
@[simp]
theorem partiallyWellOrderedOn_insert :
PartiallyWellOrderedOn (insert a s) r ↔ PartiallyWellOrderedOn s r := by
simp only [← singleton_union, partiallyWellOrderedOn_union,
partiallyWellOrderedOn_singleton, true_and_iff]
protected theorem PartiallyWellOrderedOn.insert (h : PartiallyWellOrderedOn s r) (a : α) :
PartiallyWellOrderedOn (insert a s) r :=
partiallyWellOrderedOn_insert.2 h
theorem partiallyWellOrderedOn_iff_finite_antichains [IsSymm α r] :
s.PartiallyWellOrderedOn r ↔ ∀ t, t ⊆ s → IsAntichain r t → t.Finite := by
refine ⟨fun h t ht hrt => hrt.finite_of_partiallyWellOrderedOn (h.mono ht), ?_⟩
rintro hs f hf
by_contra! H
refine infinite_range_of_injective (fun m n hmn => ?_) (hs _ (range_subset_iff.2 hf) ?_)
· obtain h | h | h := lt_trichotomy m n
· refine (H _ _ h ?_).elim
rw [hmn]
exact refl _
· exact h
· refine (H _ _ h ?_).elim
rw [hmn]
exact refl _
rintro _ ⟨m, hm, rfl⟩ _ ⟨n, hn, rfl⟩ hmn
obtain h | h := (ne_of_apply_ne _ hmn).lt_or_lt
· exact H _ _ h
· exact mt symm (H _ _ h)
variable [IsTrans α r]
theorem PartiallyWellOrderedOn.exists_monotone_subseq (h : s.PartiallyWellOrderedOn r) (f : ℕ → α)
(hf : ∀ n, f n ∈ s) : ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) := by
obtain ⟨g, h1 | h2⟩ := exists_increasing_or_nonincreasing_subseq r f
· refine ⟨g, fun m n hle => ?_⟩
obtain hlt | rfl := hle.lt_or_eq
exacts [h1 m n hlt, refl_of r _]
· exfalso
obtain ⟨m, n, hlt, hle⟩ := h (f ∘ g) fun n => hf _
exact h2 m n hlt hle
theorem partiallyWellOrderedOn_iff_exists_monotone_subseq :
s.PartiallyWellOrderedOn r ↔
∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) := by
constructor <;> intro h f hf
· exact h.exists_monotone_subseq f hf
· obtain ⟨g, gmon⟩ := h f hf
exact ⟨g 0, g 1, g.lt_iff_lt.2 Nat.zero_lt_one, gmon _ _ (Nat.zero_le 1)⟩
protected theorem PartiallyWellOrderedOn.prod {t : Set β} (hs : PartiallyWellOrderedOn s r)
(ht : PartiallyWellOrderedOn t r') :
PartiallyWellOrderedOn (s ×ˢ t) fun x y : α × β => r x.1 y.1 ∧ r' x.2 y.2 := by
intro f hf
obtain ⟨g₁, h₁⟩ := hs.exists_monotone_subseq (Prod.fst ∘ f) fun n => (hf n).1
obtain ⟨m, n, hlt, hle⟩ := ht (Prod.snd ∘ f ∘ g₁) fun n => (hf _).2
exact ⟨g₁ m, g₁ n, g₁.strictMono hlt, h₁ _ _ hlt.le, hle⟩
end IsRefl
theorem PartiallyWellOrderedOn.wellFoundedOn [IsPreorder α r] (h : s.PartiallyWellOrderedOn r) :
s.WellFoundedOn fun a b => r a b ∧ ¬r b a := by
letI : Preorder α :=
{ le := r
le_refl := refl_of r
le_trans := fun _ _ _ => trans_of r }
change s.WellFoundedOn (· < ·)
replace h : s.PartiallyWellOrderedOn (· ≤ ·) := h -- Porting note: was `change _ at h`
rw [wellFoundedOn_iff_no_descending_seq]
intro f hf
obtain ⟨m, n, hlt, hle⟩ := h f hf
exact (f.map_rel_iff.2 hlt).not_le hle
end PartiallyWellOrderedOn
section IsPWO
variable [Preorder α] [Preorder β] {s t : Set α}
/-- A subset of a preorder is partially well-ordered when any infinite sequence contains
a monotone subsequence of length 2 (or equivalently, an infinite monotone subsequence). -/
def IsPWO (s : Set α) : Prop :=
PartiallyWellOrderedOn s (· ≤ ·)
nonrec theorem IsPWO.mono (ht : t.IsPWO) : s ⊆ t → s.IsPWO := ht.mono
nonrec theorem IsPWO.exists_monotone_subseq (h : s.IsPWO) (f : ℕ → α) (hf : ∀ n, f n ∈ s) :
∃ g : ℕ ↪o ℕ, Monotone (f ∘ g) :=
h.exists_monotone_subseq f hf
theorem isPWO_iff_exists_monotone_subseq :
s.IsPWO ↔ ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, Monotone (f ∘ g) :=
partiallyWellOrderedOn_iff_exists_monotone_subseq
protected theorem IsPWO.isWF (h : s.IsPWO) : s.IsWF := by
simpa only [← lt_iff_le_not_le] using h.wellFoundedOn
nonrec theorem IsPWO.prod {t : Set β} (hs : s.IsPWO) (ht : t.IsPWO) : IsPWO (s ×ˢ t) :=
hs.prod ht
theorem IsPWO.image_of_monotoneOn (hs : s.IsPWO) {f : α → β} (hf : MonotoneOn f s) :
IsPWO (f '' s) :=
hs.image_of_monotone_on hf
theorem IsPWO.image_of_monotone (hs : s.IsPWO) {f : α → β} (hf : Monotone f) : IsPWO (f '' s) :=
hs.image_of_monotone_on (hf.monotoneOn _)
protected nonrec theorem IsPWO.union (hs : IsPWO s) (ht : IsPWO t) : IsPWO (s ∪ t) :=
hs.union ht
@[simp]
theorem isPWO_union : IsPWO (s ∪ t) ↔ IsPWO s ∧ IsPWO t :=
partiallyWellOrderedOn_union
protected theorem Finite.isPWO (hs : s.Finite) : IsPWO s := hs.partiallyWellOrderedOn
@[simp] theorem isPWO_of_finite [Finite α] : s.IsPWO := s.toFinite.isPWO
@[simp] theorem isPWO_singleton (a : α) : IsPWO ({a} : Set α) := (finite_singleton a).isPWO
@[simp] theorem isPWO_empty : IsPWO (∅ : Set α) := finite_empty.isPWO
protected theorem Subsingleton.isPWO (hs : s.Subsingleton) : IsPWO s := hs.finite.isPWO
@[simp]
theorem isPWO_insert {a} : IsPWO (insert a s) ↔ IsPWO s := by
simp only [← singleton_union, isPWO_union, isPWO_singleton, true_and_iff]
protected theorem IsPWO.insert (h : IsPWO s) (a : α) : IsPWO (insert a s) :=
isPWO_insert.2 h
protected theorem Finite.isWF (hs : s.Finite) : IsWF s := hs.isPWO.isWF
@[simp] theorem isWF_singleton {a : α} : IsWF ({a} : Set α) := (finite_singleton a).isWF
protected theorem Subsingleton.isWF (hs : s.Subsingleton) : IsWF s := hs.isPWO.isWF
@[simp]
theorem isWF_insert {a} : IsWF (insert a s) ↔ IsWF s := by
simp only [← singleton_union, isWF_union, isWF_singleton, true_and_iff]
protected theorem IsWF.insert (h : IsWF s) (a : α) : IsWF (insert a s) :=
isWF_insert.2 h
end IsPWO
section WellFoundedOn
variable {r : α → α → Prop} [IsStrictOrder α r] {s : Set α} {a : α}
protected theorem Finite.wellFoundedOn (hs : s.Finite) : s.WellFoundedOn r :=
letI := partialOrderOfSO r
hs.isWF
@[simp]
theorem wellFoundedOn_singleton : WellFoundedOn ({a} : Set α) r :=
(finite_singleton a).wellFoundedOn
protected theorem Subsingleton.wellFoundedOn (hs : s.Subsingleton) : s.WellFoundedOn r :=
hs.finite.wellFoundedOn
@[simp]
theorem wellFoundedOn_insert : WellFoundedOn (insert a s) r ↔ WellFoundedOn s r := by
simp only [← singleton_union, wellFoundedOn_union, wellFoundedOn_singleton, true_and_iff]
protected theorem WellFoundedOn.insert (h : WellFoundedOn s r) (a : α) :
WellFoundedOn (insert a s) r :=
wellFoundedOn_insert.2 h
end WellFoundedOn
section LinearOrder
variable [LinearOrder α] {s : Set α}
protected theorem IsWF.isPWO (hs : s.IsWF) : s.IsPWO := by
intro f hf
lift f to ℕ → s using hf
rcases hs.has_min (range f) (range_nonempty _) with ⟨_, ⟨m, rfl⟩, hm⟩
simp only [forall_mem_range, not_lt] at hm
exact ⟨m, m + 1, by omega, hm _⟩
/-- In a linear order, the predicates `Set.IsWF` and `Set.IsPWO` are equivalent. -/
theorem isWF_iff_isPWO : s.IsWF ↔ s.IsPWO :=
⟨IsWF.isPWO, IsPWO.isWF⟩
end LinearOrder
end Set
namespace Finset
variable {r : α → α → Prop}
@[simp]
protected theorem partiallyWellOrderedOn [IsRefl α r] (s : Finset α) :
(s : Set α).PartiallyWellOrderedOn r :=
s.finite_toSet.partiallyWellOrderedOn
@[simp]
protected theorem isPWO [Preorder α] (s : Finset α) : Set.IsPWO (↑s : Set α) :=
s.partiallyWellOrderedOn
@[simp]
protected theorem isWF [Preorder α] (s : Finset α) : Set.IsWF (↑s : Set α) :=
s.finite_toSet.isWF
@[simp]
protected theorem wellFoundedOn [IsStrictOrder α r] (s : Finset α) :
Set.WellFoundedOn (↑s : Set α) r :=
letI := partialOrderOfSO r
s.isWF
theorem wellFoundedOn_sup [IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} :
(s.sup f).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r :=
Finset.cons_induction_on s (by simp) fun a s ha hs => by simp [-sup_set_eq_biUnion, hs]
theorem partiallyWellOrderedOn_sup (s : Finset ι) {f : ι → Set α} :
(s.sup f).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r :=
Finset.cons_induction_on s (by simp) fun a s ha hs => by simp [-sup_set_eq_biUnion, hs]
theorem isWF_sup [Preorder α] (s : Finset ι) {f : ι → Set α} :
(s.sup f).IsWF ↔ ∀ i ∈ s, (f i).IsWF :=
s.wellFoundedOn_sup
theorem isPWO_sup [Preorder α] (s : Finset ι) {f : ι → Set α} :
(s.sup f).IsPWO ↔ ∀ i ∈ s, (f i).IsPWO :=
s.partiallyWellOrderedOn_sup
@[simp]
theorem wellFoundedOn_bUnion [IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r := by
simpa only [Finset.sup_eq_iSup] using s.wellFoundedOn_sup
@[simp]
theorem partiallyWellOrderedOn_bUnion (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r := by
simpa only [Finset.sup_eq_iSup] using s.partiallyWellOrderedOn_sup
@[simp]
theorem isWF_bUnion [Preorder α] (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).IsWF ↔ ∀ i ∈ s, (f i).IsWF :=
s.wellFoundedOn_bUnion
@[simp]
theorem isPWO_bUnion [Preorder α] (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).IsPWO ↔ ∀ i ∈ s, (f i).IsPWO :=
s.partiallyWellOrderedOn_bUnion
end Finset
namespace Set
section Preorder
variable [Preorder α] {s t : Set α} {a : α}
/-- `Set.IsWF.min` returns a minimal element of a nonempty well-founded set. -/
noncomputable nonrec def IsWF.min (hs : IsWF s) (hn : s.Nonempty) : α :=
hs.min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)
theorem IsWF.min_mem (hs : IsWF s) (hn : s.Nonempty) : hs.min hn ∈ s :=
(WellFounded.min hs univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)).2
nonrec theorem IsWF.not_lt_min (hs : IsWF s) (hn : s.Nonempty) (ha : a ∈ s) : ¬a < hs.min hn :=
hs.not_lt_min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype) (mem_univ (⟨a, ha⟩ : s))
theorem IsWF.min_of_subset_not_lt_min {hs : s.IsWF} {hsn : s.Nonempty} {ht : t.IsWF}
{htn : t.Nonempty} (hst : s ⊆ t) : ¬hs.min hsn < ht.min htn :=
ht.not_lt_min htn (hst (min_mem hs hsn))
@[simp]
theorem isWF_min_singleton (a) {hs : IsWF ({a} : Set α)} {hn : ({a} : Set α).Nonempty} :
hs.min hn = a :=
eq_of_mem_singleton (IsWF.min_mem hs hn)
end Preorder
section LinearOrder
variable [LinearOrder α] {s t : Set α} {a : α}
theorem IsWF.min_le (hs : s.IsWF) (hn : s.Nonempty) (ha : a ∈ s) : hs.min hn ≤ a :=
le_of_not_lt (hs.not_lt_min hn ha)
theorem IsWF.le_min_iff (hs : s.IsWF) (hn : s.Nonempty) : a ≤ hs.min hn ↔ ∀ b, b ∈ s → a ≤ b :=
⟨fun ha _b hb => le_trans ha (hs.min_le hn hb), fun h => h _ (hs.min_mem _)⟩
theorem IsWF.min_le_min_of_subset {hs : s.IsWF} {hsn : s.Nonempty} {ht : t.IsWF} {htn : t.Nonempty}
(hst : s ⊆ t) : ht.min htn ≤ hs.min hsn :=
(IsWF.le_min_iff _ _).2 fun _b hb => ht.min_le htn (hst hb)
theorem IsWF.min_union (hs : s.IsWF) (hsn : s.Nonempty) (ht : t.IsWF) (htn : t.Nonempty) :
(hs.union ht).min (union_nonempty.2 (Or.intro_left _ hsn)) =
Min.min (hs.min hsn) (ht.min htn) := by
refine le_antisymm (le_min (IsWF.min_le_min_of_subset subset_union_left)
(IsWF.min_le_min_of_subset subset_union_right)) ?_
rw [min_le_iff]
exact ((mem_union _ _ _).1 ((hs.union ht).min_mem (union_nonempty.2 (.inl hsn)))).imp
(hs.min_le _) (ht.min_le _)
end LinearOrder
end Set
open Set
section LocallyFiniteOrder
variable {s : Set α} [Preorder α] [LocallyFiniteOrder α]
theorem BddBelow.wellFoundedOn_lt : BddBelow s → s.WellFoundedOn (· < ·) := by
rw [wellFoundedOn_iff_no_descending_seq]
rintro ⟨a, ha⟩ f hf
refine infinite_range_of_injective f.injective ?_
exact (finite_Icc a <| f 0).subset <| range_subset_iff.2 <| fun n =>
⟨ha <| hf _,
antitone_iff_forall_lt.2 (fun a b hab => (f.map_rel_iff.2 hab).le) <| Nat.zero_le _⟩
theorem BddAbove.wellFoundedOn_gt : BddAbove s → s.WellFoundedOn (· > ·) :=
fun h => h.dual.wellFoundedOn_lt
end LocallyFiniteOrder
namespace Set.PartiallyWellOrderedOn
variable {r : α → α → Prop}
/-- In the context of partial well-orderings, a bad sequence is a nonincreasing sequence
whose range is contained in a particular set `s`. One exists if and only if `s` is not
partially well-ordered. -/
def IsBadSeq (r : α → α → Prop) (s : Set α) (f : ℕ → α) : Prop :=
(∀ n, f n ∈ s) ∧ ∀ m n : ℕ, m < n → ¬r (f m) (f n)
theorem iff_forall_not_isBadSeq (r : α → α → Prop) (s : Set α) :
s.PartiallyWellOrderedOn r ↔ ∀ f, ¬IsBadSeq r s f :=
forall_congr' fun f => by simp [IsBadSeq]
/-- This indicates that every bad sequence `g` that agrees with `f` on the first `n`
terms has `rk (f n) ≤ rk (g n)`. -/
def IsMinBadSeq (r : α → α → Prop) (rk : α → ℕ) (s : Set α) (n : ℕ) (f : ℕ → α) : Prop :=
∀ g : ℕ → α, (∀ m : ℕ, m < n → f m = g m) → rk (g n) < rk (f n) → ¬IsBadSeq r s g
/-- Given a bad sequence `f`, this constructs a bad sequence that agrees with `f` on the first `n`
terms and is minimal at `n`.
-/
noncomputable def minBadSeqOfBadSeq (r : α → α → Prop) (rk : α → ℕ) (s : Set α) (n : ℕ) (f : ℕ → α)
(hf : IsBadSeq r s f) :
{ g : ℕ → α // (∀ m : ℕ, m < n → f m = g m) ∧ IsBadSeq r s g ∧ IsMinBadSeq r rk s n g } := by
classical
have h : ∃ (k : ℕ) (g : ℕ → α), (∀ m, m < n → f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = k :=
⟨_, f, fun _ _ => rfl, hf, rfl⟩
obtain ⟨h1, h2, h3⟩ := Classical.choose_spec (Nat.find_spec h)
refine ⟨Classical.choose (Nat.find_spec h), h1, by convert h2, fun g hg1 hg2 con => ?_⟩
refine Nat.find_min h ?_ ⟨g, fun m mn => (h1 m mn).trans (hg1 m mn), con, rfl⟩
rwa [← h3]
theorem exists_min_bad_of_exists_bad (r : α → α → Prop) (rk : α → ℕ) (s : Set α) :
(∃ f, IsBadSeq r s f) → ∃ f, IsBadSeq r s f ∧ ∀ n, IsMinBadSeq r rk s n f := by
rintro ⟨f0, hf0 : IsBadSeq r s f0⟩
let fs : ∀ n : ℕ, { f : ℕ → α // IsBadSeq r s f ∧ IsMinBadSeq r rk s n f } := by
refine Nat.rec ?_ fun n fn => ?_
· exact ⟨(minBadSeqOfBadSeq r rk s 0 f0 hf0).1, (minBadSeqOfBadSeq r rk s 0 f0 hf0).2.2⟩
· exact ⟨(minBadSeqOfBadSeq r rk s (n + 1) fn.1 fn.2.1).1,
(minBadSeqOfBadSeq r rk s (n + 1) fn.1 fn.2.1).2.2⟩
have h : ∀ m n, m ≤ n → (fs m).1 m = (fs n).1 m := fun m n mn => by
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le mn; clear mn
induction' k with k ih
· rfl
· rw [ih, (minBadSeqOfBadSeq r rk s (m + k + 1) (fs (m + k)).1 (fs (m + k)).2.1).2.1 m
(Nat.lt_succ_iff.2 (Nat.add_le_add_left k.zero_le m))]
rfl
refine ⟨fun n => (fs n).1 n, ⟨fun n => (fs n).2.1.1 n, fun m n mn => ?_⟩, fun n g hg1 hg2 => ?_⟩
· dsimp
rw [h m n mn.le]
exact (fs n).2.1.2 m n mn
· refine (fs n).2.2 g (fun m mn => ?_) hg2
rw [← h m n mn.le, ← hg1 m mn]
theorem iff_not_exists_isMinBadSeq (rk : α → ℕ) {s : Set α} :
s.PartiallyWellOrderedOn r ↔ ¬∃ f, IsBadSeq r s f ∧ ∀ n, IsMinBadSeq r rk s n f := by
rw [iff_forall_not_isBadSeq, ← not_exists, not_congr]
constructor
· apply exists_min_bad_of_exists_bad
· rintro ⟨f, hf1, -⟩
exact ⟨f, hf1⟩
/-- Higman's Lemma, which states that for any reflexive, transitive relation `r` which is
partially well-ordered on a set `s`, the relation `List.SublistForall₂ r` is partially
well-ordered on the set of lists of elements of `s`. That relation is defined so that
`List.SublistForall₂ r l₁ l₂` whenever `l₁` related pointwise by `r` to a sublist of `l₂`. -/
theorem partiallyWellOrderedOn_sublistForall₂ (r : α → α → Prop) [IsRefl α r] [IsTrans α r]
{s : Set α} (h : s.PartiallyWellOrderedOn r) :
{ l : List α | ∀ x, x ∈ l → x ∈ s }.PartiallyWellOrderedOn (List.SublistForall₂ r) := by
rcases isEmpty_or_nonempty α
· exact subsingleton_of_subsingleton.partiallyWellOrderedOn
inhabit α
rw [iff_not_exists_isMinBadSeq List.length]
rintro ⟨f, hf1, hf2⟩
have hnil : ∀ n, f n ≠ List.nil := fun n con =>
hf1.2 n n.succ n.lt_succ_self (con.symm ▸ List.SublistForall₂.nil)
have : ∀ n, (f n).headI ∈ s :=
fun n => hf1.1 n _ (List.head!_mem_self (hnil n))
obtain ⟨g, hg⟩ := h.exists_monotone_subseq (fun n => (f n).headI) this
have hf' :=
hf2 (g 0) (fun n => if n < g 0 then f n else List.tail (f (g (n - g 0))))
(fun m hm => (if_pos hm).symm) ?_
swap
· simp only [if_neg (lt_irrefl (g 0)), Nat.sub_self]
rw [List.length_tail, ← Nat.pred_eq_sub_one]
exact Nat.pred_lt fun con => hnil _ (List.length_eq_zero.1 con)
rw [IsBadSeq] at hf'
push_neg at hf'
obtain ⟨m, n, mn, hmn⟩ := hf' fun n x hx => by
split_ifs at hx with hn
exacts [hf1.1 _ _ hx, hf1.1 _ _ (List.tail_subset _ hx)]
by_cases hn : n < g 0
· apply hf1.2 m n mn
rwa [if_pos hn, if_pos (mn.trans hn)] at hmn
· obtain ⟨n', rfl⟩ := Nat.exists_eq_add_of_le (not_lt.1 hn)
rw [if_neg hn, add_comm (g 0) n', Nat.add_sub_cancel_right] at hmn
split_ifs at hmn with hm
· apply hf1.2 m (g n') (lt_of_lt_of_le hm (g.monotone n'.zero_le))
exact _root_.trans hmn (List.tail_sublistForall₂_self _)
· rw [← Nat.sub_lt_iff_lt_add (le_of_not_lt hm)] at mn
apply hf1.2 _ _ (g.lt_iff_lt.2 mn)
rw [← List.cons_head!_tail (hnil (g (m - g 0))), ← List.cons_head!_tail (hnil (g n'))]
exact List.SublistForall₂.cons (hg _ _ (le_of_lt mn)) hmn
theorem subsetProdLex [PartialOrder α] [Preorder β] {s : Set (α ×ₗ β)}
(hα : ((fun (x : α ×ₗ β) => (ofLex x).1)'' s).IsPWO)
(hβ : ∀ a, {y | toLex (a, y) ∈ s}.IsPWO) : s.IsPWO := by
intro f hf
rw [isPWO_iff_exists_monotone_subseq] at hα
obtain ⟨g, hg⟩ : ∃ (g : (ℕ ↪o ℕ)), Monotone fun n => (ofLex f (g n)).1 :=
hα (fun n => (ofLex f n).1) (fun k => mem_image_of_mem (fun x => (ofLex x).1) (hf k))
have hhg : ∀ n, (ofLex f (g 0)).1 ≤ (ofLex f (g n)).1 := fun n => hg n.zero_le
by_cases hc : ∃ n, (ofLex f (g 0)).1 < (ofLex f (g n)).1
· obtain ⟨n, hn⟩ := hc
use (g 0), (g n)
constructor
· by_contra hx
simp_all
· exact (Prod.Lex.le_iff (f (g 0)) _).mpr <| Or.inl hn
· have hhc : ∀ n, (ofLex f (g 0)).1 = (ofLex f (g n)).1 := by
intro n
rw [not_exists] at hc
exact (hhg n).eq_of_not_lt (hc n)
obtain ⟨g', hg'⟩ : ∃ g' : ℕ ↪o ℕ, Monotone ((fun n ↦ (ofLex f (g (g' n))).2)) := by
simp_rw [isPWO_iff_exists_monotone_subseq] at hβ
apply hβ (ofLex f (g 0)).1 fun n ↦ (ofLex f (g n)).2
intro n
rw [hhc n]
simpa using hf _
use (g (g' 0)), (g (g' 1))
suffices (f (g (g' 0))) ≤ (f (g (g' 1))) by simpa
· refine (Prod.Lex.le_iff (f (g (g' 0))) (f (g (g' 1)))).mpr ?_
right
constructor
· exact (hhc (g' 0)).symm.trans (hhc (g' 1))
· exact hg' (Nat.zero_le 1)
theorem imageProdLex [PartialOrder α] [Preorder β] {s : Set (α ×ₗ β)}
(hαβ : s.IsPWO) : ((fun (x : α ×ₗ β) => (ofLex x).1)'' s).IsPWO :=
IsPWO.image_of_monotone hαβ Prod.Lex.monotone_fst
theorem fiberProdLex [PartialOrder α] [Preorder β] {s : Set (α ×ₗ β)}
(hαβ : s.IsPWO) (a : α) : {y | toLex (a, y) ∈ s}.IsPWO := by
let f : α ×ₗ β → β := fun x => (ofLex x).2
have h : {y | toLex (a, y) ∈ s} = f '' (s ∩ (fun x ↦ (ofLex x).1) ⁻¹' {a}) := by
ext x
simp [f]
rw [h]
apply IsPWO.image_of_monotoneOn (hαβ.mono inter_subset_left)
rintro b ⟨-, hb⟩ c ⟨-, hc⟩ hbc
simp only [mem_preimage, mem_singleton_iff] at hb hc
have : (ofLex b).1 < (ofLex c).1 ∨ (ofLex b).1 = (ofLex c).1 ∧ f b ≤ f c :=
(Prod.Lex.le_iff b c).mp hbc
simp_all only [lt_self_iff_false, true_and, false_or]
theorem ProdLex_iff [PartialOrder α] [Preorder β] {s : Set (α ×ₗ β)} :
s.IsPWO ↔
((fun (x : α ×ₗ β) ↦ (ofLex x).1) '' s).IsPWO ∧ ∀ a, {y | toLex (a, y) ∈ s}.IsPWO :=
⟨fun h ↦ ⟨imageProdLex h, fiberProdLex h⟩, fun h ↦ subsetProdLex h.1 h.2⟩
end Set.PartiallyWellOrderedOn
theorem WellFounded.isWF [LT α] (h : WellFounded ((· < ·) : α → α → Prop)) (s : Set α) : s.IsWF :=
(Set.isWF_univ_iff.2 h).mono s.subset_univ
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPWO`. -/
theorem Pi.isPWO {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
[Finite ι] (s : Set (∀ i, α i)) : s.IsPWO := by
cases nonempty_fintype ι
suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
refine isPWO_iff_exists_monotone_subseq.2 fun f _ => ?_
simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
refine Finset.cons_induction ?_ ?_
· intro f
exists RelEmbedding.refl (· ≤ ·)
simp only [IsEmpty.forall_iff, imp_true_iff, forall_const, Finset.not_mem_empty]
· intro x s hx ih f
obtain ⟨g, hg⟩ :=
(IsWellFounded.wf.isWF univ).isPWO.exists_monotone_subseq (fun n => f n x) mem_univ
obtain ⟨g', hg'⟩ := ih (f ∘ g)
refine ⟨g'.trans g, fun a b hab => (Finset.forall_mem_cons _ _).2 ?_⟩
exact ⟨hg (OrderHomClass.mono g' hab), hg' hab⟩
section ProdLex
variable {rα : α → α → Prop} {rβ : β → β → Prop} {f : γ → α} {g : γ → β} {s : Set γ}
/-- Stronger version of `WellFounded.prod_lex`. Instead of requiring `rβ on g` to be well-founded,
we only require it to be well-founded on fibers of `f`. -/
theorem WellFounded.prod_lex_of_wellFoundedOn_fiber (hα : WellFounded (rα on f))
(hβ : ∀ a, (f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
WellFounded (Prod.Lex rα rβ on fun c => (f c, g c)) := by
refine ((PSigma.lex_wf (wellFoundedOn_range.2 hα) fun a => hβ a).onFun
(f := fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩)).mono fun c c' h => ?_
obtain h' | h' := Prod.lex_iff.1 h
· exact PSigma.Lex.left _ _ h'
· dsimp only [InvImage, (· on ·)] at h' ⊢
convert PSigma.Lex.right (⟨_, c', rfl⟩ : range f) _ using 1; swap
exacts [⟨c, h'.1⟩, PSigma.subtype_ext (Subtype.ext h'.1) rfl, h'.2]
theorem Set.WellFoundedOn.prod_lex_of_wellFoundedOn_fiber (hα : s.WellFoundedOn (rα on f))
(hβ : ∀ a, (s ∩ f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
s.WellFoundedOn (Prod.Lex rα rβ on fun c => (f c, g c)) :=
WellFounded.prod_lex_of_wellFoundedOn_fiber hα
fun a ↦ ((hβ a).onFun (f := fun x => ⟨x, x.1.2, x.2⟩)).mono (fun b c h ↦ ‹_›)
end ProdLex
section SigmaLex
variable {rι : ι → ι → Prop} {rπ : ∀ i, π i → π i → Prop} {f : γ → ι} {g : ∀ i, γ → π i} {s : Set γ}
/-- Stronger version of `PSigma.lex_wf`. Instead of requiring `rπ on g` to be well-founded, we only
require it to be well-founded on fibers of `f`. -/
theorem WellFounded.sigma_lex_of_wellFoundedOn_fiber (hι : WellFounded (rι on f))
(hπ : ∀ i, (f ⁻¹' {i}).WellFoundedOn (rπ i on g i)) :
WellFounded (Sigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩) := by
refine ((PSigma.lex_wf (wellFoundedOn_range.2 hι) fun a => hπ a).onFun
(f := fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩)).mono fun c c' h => ?_
obtain h' | ⟨h', h''⟩ := Sigma.lex_iff.1 h
· exact PSigma.Lex.left _ _ h'
· dsimp only [InvImage, (· on ·)] at h' ⊢
convert PSigma.Lex.right (⟨_, c', rfl⟩ : range f) _ using 1; swap
· exact ⟨c, h'⟩
· exact PSigma.subtype_ext (Subtype.ext h') rfl
· dsimp only [Subtype.coe_mk] at *
revert h'
generalize f c = d
rintro rfl h''
exact h''
theorem Set.WellFoundedOn.sigma_lex_of_wellFoundedOn_fiber (hι : s.WellFoundedOn (rι on f))
(hπ : ∀ i, (s ∩ f ⁻¹' {i}).WellFoundedOn (rπ i on g i)) :
s.WellFoundedOn (Sigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩) := by
show WellFounded (Sigma.Lex rι rπ on fun c : s => ⟨f c, g (f c) c⟩)
exact
@WellFounded.sigma_lex_of_wellFoundedOn_fiber _ s _ _ rπ (fun c => f c) (fun i c => g _ c) hι
fun i => ((hπ i).onFun (f := fun x => ⟨x, x.1.2, x.2⟩)).mono (fun b c h => ‹_›)
end SigmaLex
|
Order\WithBot.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Init.Algebra.Classes
import Mathlib.Logic.Nontrivial.Basic
import Mathlib.Order.BoundedOrder
import Mathlib.Data.Option.NAry
import Mathlib.Tactic.Lift
import Mathlib.Data.Option.Basic
/-!
# `WithBot`, `WithTop`
Adding a `bot` or a `top` to an order.
## Main declarations
* `With<Top/Bot> α`: Equips `Option α` with the order on `α` plus `none` as the top/bottom element.
-/
variable {α β γ δ : Type*}
/-- Attach `⊥` to a type. -/
def WithBot (α : Type*) :=
Option α
namespace WithBot
variable {a b : α}
instance [Repr α] : Repr (WithBot α) :=
⟨fun o _ =>
match o with
| none => "⊥"
| some a => "↑" ++ repr a⟩
/-- The canonical map from `α` into `WithBot α` -/
@[coe, match_pattern] def some : α → WithBot α :=
Option.some
-- Porting note: changed this from `CoeTC` to `Coe` but I am not 100% confident that's correct.
instance coe : Coe α (WithBot α) :=
⟨some⟩
instance bot : Bot (WithBot α) :=
⟨none⟩
instance inhabited : Inhabited (WithBot α) :=
⟨⊥⟩
instance nontrivial [Nonempty α] : Nontrivial (WithBot α) :=
Option.nontrivial
open Function
theorem coe_injective : Injective ((↑) : α → WithBot α) :=
Option.some_injective _
@[simp, norm_cast]
theorem coe_inj : (a : WithBot α) = b ↔ a = b :=
Option.some_inj
protected theorem «forall» {p : WithBot α → Prop} : (∀ x, p x) ↔ p ⊥ ∧ ∀ x : α, p x :=
Option.forall
protected theorem «exists» {p : WithBot α → Prop} : (∃ x, p x) ↔ p ⊥ ∨ ∃ x : α, p x :=
Option.exists
theorem none_eq_bot : (none : WithBot α) = (⊥ : WithBot α) :=
rfl
theorem some_eq_coe (a : α) : (Option.some a : WithBot α) = (↑a : WithBot α) :=
rfl
@[simp]
theorem bot_ne_coe : ⊥ ≠ (a : WithBot α) :=
nofun
@[simp]
theorem coe_ne_bot : (a : WithBot α) ≠ ⊥ :=
nofun
/-- Recursor for `WithBot` using the preferred forms `⊥` and `↑a`. -/
@[elab_as_elim, induction_eliminator, cases_eliminator]
def recBotCoe {C : WithBot α → Sort*} (bot : C ⊥) (coe : ∀ a : α, C a) : ∀ n : WithBot α, C n
| ⊥ => bot
| (a : α) => coe a
@[simp]
theorem recBotCoe_bot {C : WithBot α → Sort*} (d : C ⊥) (f : ∀ a : α, C a) :
@recBotCoe _ C d f ⊥ = d :=
rfl
@[simp]
theorem recBotCoe_coe {C : WithBot α → Sort*} (d : C ⊥) (f : ∀ a : α, C a) (x : α) :
@recBotCoe _ C d f ↑x = f x :=
rfl
/-- Specialization of `Option.getD` to values in `WithBot α` that respects API boundaries.
-/
def unbot' (d : α) (x : WithBot α) : α :=
recBotCoe d id x
@[simp]
theorem unbot'_bot {α} (d : α) : unbot' d ⊥ = d :=
rfl
@[simp]
theorem unbot'_coe {α} (d x : α) : unbot' d x = x :=
rfl
theorem coe_eq_coe : (a : WithBot α) = b ↔ a = b := coe_inj
theorem unbot'_eq_iff {d y : α} {x : WithBot α} : unbot' d x = y ↔ x = y ∨ x = ⊥ ∧ y = d := by
induction x <;> simp [@eq_comm _ d]
@[simp] theorem unbot'_eq_self_iff {d : α} {x : WithBot α} : unbot' d x = d ↔ x = d ∨ x = ⊥ := by
simp [unbot'_eq_iff]
theorem unbot'_eq_unbot'_iff {d : α} {x y : WithBot α} :
unbot' d x = unbot' d y ↔ x = y ∨ x = d ∧ y = ⊥ ∨ x = ⊥ ∧ y = d := by
induction y <;> simp [unbot'_eq_iff, or_comm]
/-- Lift a map `f : α → β` to `WithBot α → WithBot β`. Implemented using `Option.map`. -/
def map (f : α → β) : WithBot α → WithBot β :=
Option.map f
@[simp]
theorem map_bot (f : α → β) : map f ⊥ = ⊥ :=
rfl
@[simp]
theorem map_coe (f : α → β) (a : α) : map f a = f a :=
rfl
theorem map_comm {f₁ : α → β} {f₂ : α → γ} {g₁ : β → δ} {g₂ : γ → δ}
(h : g₁ ∘ f₁ = g₂ ∘ f₂) (a : α) :
map g₁ (map f₁ a) = map g₂ (map f₂ a) :=
Option.map_comm h _
/-- The image of a binary function `f : α → β → γ` as a function
`WithBot α → WithBot β → WithBot γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def map₂ : (α → β → γ) → WithBot α → WithBot β → WithBot γ := Option.map₂
lemma map₂_coe_coe (f : α → β → γ) (a : α) (b : β) : map₂ f a b = f a b := rfl
@[simp] lemma map₂_bot_left (f : α → β → γ) (b) : map₂ f ⊥ b = ⊥ := rfl
@[simp] lemma map₂_bot_right (f : α → β → γ) (a) : map₂ f a ⊥ = ⊥ := by cases a <;> rfl
@[simp] lemma map₂_coe_left (f : α → β → γ) (a : α) (b) : map₂ f a b = b.map fun b ↦ f a b := rfl
@[simp] lemma map₂_coe_right (f : α → β → γ) (a) (b : β) : map₂ f a b = a.map (f · b) := by
cases a <;> rfl
@[simp] lemma map₂_eq_bot_iff {f : α → β → γ} {a : WithBot α} {b : WithBot β} :
map₂ f a b = ⊥ ↔ a = ⊥ ∨ b = ⊥ := Option.map₂_eq_none_iff
lemma ne_bot_iff_exists {x : WithBot α} : x ≠ ⊥ ↔ ∃ a : α, ↑a = x := Option.ne_none_iff_exists
lemma forall_ne_iff_eq_bot {x : WithBot α} : (∀ a : α, ↑a ≠ x) ↔ x = ⊥ :=
Option.forall_some_ne_iff_eq_none
/-- Deconstruct a `x : WithBot α` to the underlying value in `α`, given a proof that `x ≠ ⊥`. -/
def unbot : ∀ x : WithBot α, x ≠ ⊥ → α | (x : α), _ => x
@[simp] lemma coe_unbot : ∀ (x : WithBot α) hx, x.unbot hx = x | (x : α), _ => rfl
@[simp]
theorem unbot_coe (x : α) (h : (x : WithBot α) ≠ ⊥ := coe_ne_bot) : (x : WithBot α).unbot h = x :=
rfl
instance canLift : CanLift (WithBot α) α (↑) fun r => r ≠ ⊥ where
prf x h := ⟨x.unbot h, coe_unbot _ _⟩
instance instTop [Top α] : Top (WithBot α) where
top := (⊤ : α)
@[simp, norm_cast] lemma coe_top [Top α] : ((⊤ : α) : WithBot α) = ⊤ := rfl
@[simp, norm_cast] lemma coe_eq_top [Top α] {a : α} : (a : WithBot α) = ⊤ ↔ a = ⊤ := coe_eq_coe
@[simp, norm_cast] lemma top_eq_coe [Top α] {a : α} : ⊤ = (a : WithBot α) ↔ ⊤ = a := coe_eq_coe
theorem unbot_eq_iff {a : WithBot α} {b : α} (h : a ≠ ⊥) :
a.unbot h = b ↔ a = b := by
induction a
· simpa using h rfl
· simp
theorem eq_unbot_iff {a : α} {b : WithBot α} (h : b ≠ ⊥) :
a = b.unbot h ↔ a = b := by
induction b
· simpa using h rfl
· simp
section LE
variable [LE α]
instance (priority := 10) le : LE (WithBot α) :=
⟨fun o₁ o₂ => ∀ a : α, o₁ = ↑a → ∃ b : α, o₂ = ↑b ∧ a ≤ b⟩
@[simp, norm_cast]
theorem coe_le_coe : (a : WithBot α) ≤ b ↔ a ≤ b := by
simp [LE.le]
instance orderBot : OrderBot (WithBot α) where
bot_le _ := fun _ h => Option.noConfusion h
@[simp, deprecated coe_le_coe "Don't mix Option and WithBot" (since := "2024-05-27")]
theorem some_le_some : @LE.le (WithBot α) _ (Option.some a) (Option.some b) ↔ a ≤ b :=
coe_le_coe
@[simp, deprecated bot_le "Don't mix Option and WithBot" (since := "2024-05-27")]
theorem none_le {a : WithBot α} : @LE.le (WithBot α) _ none a := bot_le
instance orderTop [OrderTop α] : OrderTop (WithBot α) where
le_top o a ha := by cases ha; exact ⟨_, rfl, le_top⟩
instance instBoundedOrder [OrderTop α] : BoundedOrder (WithBot α) :=
{ WithBot.orderBot, WithBot.orderTop with }
theorem not_coe_le_bot (a : α) : ¬(a : WithBot α) ≤ ⊥ := fun h =>
let ⟨_, hb, _⟩ := h _ rfl
Option.not_mem_none _ hb
/-- There is a general version `le_bot_iff`, but this lemma does not require a `PartialOrder`. -/
@[simp]
protected theorem le_bot_iff : ∀ {a : WithBot α}, a ≤ ⊥ ↔ a = ⊥
| (a : α) => by simp [not_coe_le_bot _]
| ⊥ => by simp
theorem coe_le : ∀ {o : Option α}, b ∈ o → ((a : WithBot α) ≤ o ↔ a ≤ b)
| _, rfl => coe_le_coe
theorem coe_le_iff : ∀ {x : WithBot α}, (a : WithBot α) ≤ x ↔ ∃ b : α, x = b ∧ a ≤ b
| (x : α) => by simp
| ⊥ => iff_of_false (not_coe_le_bot _) <| by simp
theorem le_coe_iff : ∀ {x : WithBot α}, x ≤ b ↔ ∀ a : α, x = ↑a → a ≤ b
| (b : α) => by simp
| ⊥ => by simp
protected theorem _root_.IsMax.withBot (h : IsMax a) : IsMax (a : WithBot α)
| ⊥, _ => bot_le
| (_ : α), hb => coe_le_coe.2 <| h <| coe_le_coe.1 hb
theorem le_unbot_iff {a : α} {b : WithBot α} (h : b ≠ ⊥) :
a ≤ unbot b h ↔ (a : WithBot α) ≤ b := by
match b, h with
| some _, _ => simp only [unbot_coe, coe_le_coe]
theorem unbot_le_iff {a : WithBot α} (h : a ≠ ⊥) {b : α} :
unbot a h ≤ b ↔ a ≤ (b : WithBot α) := by
match a, h with
| some _, _ => simp only [unbot_coe, coe_le_coe]
theorem unbot'_le_iff {a : WithBot α} {b c : α} (h : a = ⊥ → b ≤ c) :
a.unbot' b ≤ c ↔ a ≤ c := by
induction a
· simpa using h rfl
· simp
end LE
section LT
variable [LT α]
instance (priority := 10) lt : LT (WithBot α) :=
⟨fun o₁ o₂ : WithBot α => ∃ b : α, o₂ = ↑b ∧ ∀ a : α, o₁ = ↑a → a < b⟩
@[simp, norm_cast]
theorem coe_lt_coe : (a : WithBot α) < b ↔ a < b := by
simp [LT.lt]
@[simp]
theorem bot_lt_coe (a : α) : ⊥ < (a : WithBot α) :=
⟨a, rfl, fun _ hb => (Option.not_mem_none _ hb).elim⟩
@[simp]
protected theorem not_lt_bot (a : WithBot α) : ¬a < ⊥ :=
fun ⟨_, h, _⟩ => Option.not_mem_none _ h
@[simp, deprecated coe_lt_coe "Don't mix Option and WithBot" (since := "2024-05-27")]
theorem some_lt_some : @LT.lt (WithBot α) _ (Option.some a) (Option.some b) ↔ a < b :=
coe_lt_coe
@[simp, deprecated bot_lt_coe "Don't mix Option and WithBot" (since := "2024-05-27")]
theorem none_lt_some (a : α) : @LT.lt (WithBot α) _ none (some a) := bot_lt_coe _
@[simp, deprecated not_lt_bot "Don't mix Option and WithBot" (since := "2024-05-27")]
theorem not_lt_none (a : WithBot α) : ¬@LT.lt (WithBot α) _ a none := WithBot.not_lt_bot _
theorem lt_iff_exists_coe : ∀ {a b : WithBot α}, a < b ↔ ∃ p : α, b = p ∧ a < p
| a, some b => by simp [coe_eq_coe]
| a, ⊥ => iff_of_false (WithBot.not_lt_bot _) <| by simp
theorem lt_coe_iff : ∀ {x : WithBot α}, x < b ↔ ∀ a : α, x = a → a < b
| (_ : α) => by simp
| ⊥ => by simp [bot_lt_coe]
/-- A version of `bot_lt_iff_ne_bot` for `WithBot` that only requires `LT α`, not
`PartialOrder α`. -/
protected theorem bot_lt_iff_ne_bot : ∀ {x : WithBot α}, ⊥ < x ↔ x ≠ ⊥
| ⊥ => iff_of_false (WithBot.not_lt_bot _) <| by simp
| (x : α) => by simp [bot_lt_coe]
theorem lt_unbot_iff {a : α} {b : WithBot α} (h : b ≠ ⊥) :
a < unbot b h ↔ (a : WithBot α) < b := by
induction b
· simpa [bot_lt_coe] using h rfl
· simp
theorem unbot_lt_iff {a : WithBot α} (h : a ≠ ⊥) {b : α} :
unbot a h < b ↔ a < (b : WithBot α) := by
induction a
· simpa [bot_lt_coe] using h rfl
· simp
theorem unbot'_lt_iff {a : WithBot α} {b c : α} (h : a = ⊥ → b < c) :
a.unbot' b < c ↔ a < c := by
induction a
· simpa [bot_lt_coe] using h rfl
· simp
end LT
instance preorder [Preorder α] : Preorder (WithBot α) where
le := (· ≤ ·)
lt := (· < ·)
lt_iff_le_not_le := by
intros a b
cases a <;> cases b <;> simp [lt_iff_le_not_le]
le_refl o a ha := ⟨a, ha, le_rfl⟩
le_trans o₁ o₂ o₃ h₁ h₂ a ha :=
let ⟨b, hb, ab⟩ := h₁ a ha
let ⟨c, hc, bc⟩ := h₂ b hb
⟨c, hc, le_trans ab bc⟩
instance partialOrder [PartialOrder α] : PartialOrder (WithBot α) :=
{ WithBot.preorder with
le_antisymm := fun o₁ o₂ h₁ h₂ => by
cases' o₁ with a
· cases' o₂ with b
· rfl
rcases h₂ b rfl with ⟨_, ⟨⟩, _⟩
· rcases h₁ a rfl with ⟨b, ⟨⟩, h₁'⟩
rcases h₂ b rfl with ⟨_, ⟨⟩, h₂'⟩
rw [le_antisymm h₁' h₂'] }
section Preorder
variable [Preorder α] [Preorder β]
theorem coe_strictMono : StrictMono (fun (a : α) => (a : WithBot α)) := fun _ _ => coe_lt_coe.2
theorem coe_mono : Monotone (fun (a : α) => (a : WithBot α)) := fun _ _ => coe_le_coe.2
theorem monotone_iff {f : WithBot α → β} :
Monotone f ↔ Monotone (fun a ↦ f a : α → β) ∧ ∀ x : α, f ⊥ ≤ f x :=
⟨fun h ↦ ⟨h.comp WithBot.coe_mono, fun _ ↦ h bot_le⟩, fun h ↦
WithBot.forall.2
⟨WithBot.forall.2 ⟨fun _ => le_rfl, fun x _ => h.2 x⟩, fun _ =>
WithBot.forall.2 ⟨fun h => (not_coe_le_bot _ h).elim,
fun _ hle => h.1 (coe_le_coe.1 hle)⟩⟩⟩
@[simp]
theorem monotone_map_iff {f : α → β} : Monotone (WithBot.map f) ↔ Monotone f :=
monotone_iff.trans <| by simp [Monotone]
alias ⟨_, _root_.Monotone.withBot_map⟩ := monotone_map_iff
theorem strictMono_iff {f : WithBot α → β} :
StrictMono f ↔ StrictMono (fun a => f a : α → β) ∧ ∀ x : α, f ⊥ < f x :=
⟨fun h => ⟨h.comp WithBot.coe_strictMono, fun _ => h (bot_lt_coe _)⟩, fun h =>
WithBot.forall.2
⟨WithBot.forall.2 ⟨flip absurd (lt_irrefl _), fun x _ => h.2 x⟩, fun _ =>
WithBot.forall.2 ⟨fun h => (not_lt_bot h).elim, fun _ hle => h.1 (coe_lt_coe.1 hle)⟩⟩⟩
theorem strictAnti_iff {f : WithBot α → β} :
StrictAnti f ↔ StrictAnti (fun a ↦ f a : α → β) ∧ ∀ x : α, f x < f ⊥ :=
strictMono_iff (β := βᵒᵈ)
@[simp]
theorem strictMono_map_iff {f : α → β} :
StrictMono (WithBot.map f) ↔ StrictMono f :=
strictMono_iff.trans <| by simp [StrictMono, bot_lt_coe]
alias ⟨_, _root_.StrictMono.withBot_map⟩ := strictMono_map_iff
theorem map_le_iff (f : α → β) (mono_iff : ∀ {a b}, f a ≤ f b ↔ a ≤ b) :
∀ a b : WithBot α, a.map f ≤ b.map f ↔ a ≤ b
| ⊥, _ => by simp only [map_bot, bot_le]
| (a : α), ⊥ => by simp only [map_coe, map_bot, coe_ne_bot, not_coe_le_bot _]
| (a : α), (b : α) => by simpa only [map_coe, coe_le_coe] using mono_iff
theorem le_coe_unbot' : ∀ (a : WithBot α) (b : α), a ≤ a.unbot' b
| (a : α), _ => le_rfl
| ⊥, _ => bot_le
@[simp]
theorem lt_coe_bot [OrderBot α] : ∀ {x : WithBot α}, x < (⊥ : α) ↔ x = ⊥
| (x : α) => by simp
| ⊥ => by simp
end Preorder
instance semilatticeSup [SemilatticeSup α] : SemilatticeSup (WithBot α) where
sup
-- note this is `Option.liftOrGet`, but with the right defeq when unfolding
| ⊥, ⊥ => ⊥
| (a : α), ⊥ => a
| ⊥, (b : α) => b
| (a : α), (b : α) => ↑(a ⊔ b)
le_sup_left := fun o₁ o₂ a ha => by cases ha; cases o₂ <;> simp
le_sup_right := fun o₁ o₂ a ha => by cases ha; cases o₁ <;> simp
sup_le := fun o₁ o₂ o₃ h₁ h₂ a ha => by
cases' o₁ with b <;> cases' o₂ with c <;> cases ha
· exact h₂ a rfl
· exact h₁ a rfl
· rcases h₁ b rfl with ⟨d, ⟨⟩, h₁'⟩
simp only [coe_le_coe] at h₂
exact ⟨d, rfl, sup_le h₁' h₂⟩
theorem coe_sup [SemilatticeSup α] (a b : α) : ((a ⊔ b : α) : WithBot α) = (a : WithBot α) ⊔ b :=
rfl
instance semilatticeInf [SemilatticeInf α] : SemilatticeInf (WithBot α) :=
{ WithBot.partialOrder, @WithBot.orderBot α _ with
inf := WithBot.map₂ (· ⊓ ·),
inf_le_left := fun o₁ o₂ a ha => by
rcases Option.mem_map₂_iff.1 ha with ⟨a, b, (rfl : _ = _), (rfl : _ = _), rfl⟩
exact ⟨_, rfl, inf_le_left⟩,
inf_le_right := fun o₁ o₂ a ha => by
rcases Option.mem_map₂_iff.1 ha with ⟨a, b, (rfl : _ = _), (rfl : _ = _), rfl⟩
exact ⟨_, rfl, inf_le_right⟩,
le_inf := fun o₁ o₂ o₃ h₁ h₂ a ha => by
cases ha
rcases h₁ a rfl with ⟨b, ⟨⟩, ab⟩
rcases h₂ a rfl with ⟨c, ⟨⟩, ac⟩
exact ⟨_, rfl, le_inf ab ac⟩ }
theorem coe_inf [SemilatticeInf α] (a b : α) : ((a ⊓ b : α) : WithBot α) = (a : WithBot α) ⊓ b :=
rfl
instance lattice [Lattice α] : Lattice (WithBot α) :=
{ WithBot.semilatticeSup, WithBot.semilatticeInf with }
instance distribLattice [DistribLattice α] : DistribLattice (WithBot α) :=
{ WithBot.lattice with
le_sup_inf := fun o₁ o₂ o₃ =>
match o₁, o₂, o₃ with
| ⊥, ⊥, ⊥ => le_rfl
| ⊥, ⊥, (a₁ : α) => le_rfl
| ⊥, (a₁ : α), ⊥ => le_rfl
| ⊥, (a₁ : α), (a₃ : α) => le_rfl
| (a₁ : α), ⊥, ⊥ => inf_le_left
| (a₁ : α), ⊥, (a₃ : α) => inf_le_left
| (a₁ : α), (a₂ : α), ⊥ => inf_le_right
| (a₁ : α), (a₂ : α), (a₃ : α) => coe_le_coe.mpr le_sup_inf }
instance decidableEq [DecidableEq α] : DecidableEq (WithBot α) :=
inferInstanceAs <| DecidableEq (Option α)
instance decidableLE [LE α] [@DecidableRel α (· ≤ ·)] : @DecidableRel (WithBot α) (· ≤ ·)
| none, x => isTrue fun a h => Option.noConfusion h
| Option.some x, Option.some y =>
if h : x ≤ y then isTrue (coe_le_coe.2 h) else isFalse <| by simp [*]
| Option.some x, none => isFalse fun h => by rcases h x rfl with ⟨y, ⟨_⟩, _⟩
instance decidableLT [LT α] [@DecidableRel α (· < ·)] : @DecidableRel (WithBot α) (· < ·)
| none, Option.some x => isTrue <| by exists x, rfl; rintro _ ⟨⟩
| Option.some x, Option.some y =>
if h : x < y then isTrue <| by simp [*] else isFalse <| by simp [*]
| x, none => isFalse <| by rintro ⟨a, ⟨⟨⟩⟩⟩
instance isTotal_le [LE α] [IsTotal α (· ≤ ·)] : IsTotal (WithBot α) (· ≤ ·) :=
⟨fun a b =>
match a, b with
| none, _ => Or.inl bot_le
| _, none => Or.inr bot_le
| Option.some x, Option.some y => (total_of (· ≤ ·) x y).imp coe_le_coe.2 coe_le_coe.2⟩
instance linearOrder [LinearOrder α] : LinearOrder (WithBot α) :=
Lattice.toLinearOrder _
@[simp, norm_cast]
theorem coe_min [LinearOrder α] (x y : α) : ((min x y : α) : WithBot α) = min (x : WithBot α) y :=
rfl
@[simp, norm_cast]
theorem coe_max [LinearOrder α] (x y : α) : ((max x y : α) : WithBot α) = max (x : WithBot α) y :=
rfl
instance instWellFoundedLT [LT α] [WellFoundedLT α] : WellFoundedLT (WithBot α) where
wf :=
have not_lt_bot : ∀ a : WithBot α, ¬ a < ⊥ := nofun
have acc_bot := ⟨_, by simp [not_lt_bot]⟩
.intro fun
| ⊥ => acc_bot
| (a : α) => (wellFounded_lt.1 a).rec fun a _ ih =>
.intro _ fun
| ⊥, _ => acc_bot
| (b : α), hlt => ih _ (coe_lt_coe.1 hlt)
instance _root_.WithBot.instWellFoundedGT [LT α] [WellFoundedGT α] : WellFoundedGT (WithBot α) where
wf :=
have acc_some (a : α) : Acc ((· > ·) : WithBot α → WithBot α → Prop) a :=
(wellFounded_gt.1 a).rec fun _ _ ih =>
.intro _ fun
| (b : α), hlt => ih _ (coe_lt_coe.1 hlt)
| ⊥, hlt => absurd hlt (WithBot.not_lt_bot _)
.intro fun
| (a : α) => acc_some a
| ⊥ => .intro _ fun
| (b : α), _ => acc_some b
| ⊥, hlt => absurd hlt (WithBot.not_lt_bot _)
instance denselyOrdered [LT α] [DenselyOrdered α] [NoMinOrder α] : DenselyOrdered (WithBot α) :=
⟨fun a b =>
match a, b with
| a, none => fun h : a < ⊥ => (WithBot.not_lt_bot _ h).elim
| none, Option.some b => fun _ =>
let ⟨a, ha⟩ := exists_lt b
⟨a, bot_lt_coe a, coe_lt_coe.2 ha⟩
| Option.some _, Option.some _ => fun h =>
let ⟨a, ha₁, ha₂⟩ := exists_between (coe_lt_coe.1 h)
⟨a, coe_lt_coe.2 ha₁, coe_lt_coe.2 ha₂⟩⟩
theorem lt_iff_exists_coe_btwn [Preorder α] [DenselyOrdered α] [NoMinOrder α] {a b : WithBot α} :
a < b ↔ ∃ x : α, a < ↑x ∧ ↑x < b :=
⟨fun h =>
let ⟨_, hy⟩ := exists_between h
let ⟨x, hx⟩ := lt_iff_exists_coe.1 hy.1
⟨x, hx.1 ▸ hy⟩,
fun ⟨_, hx⟩ => lt_trans hx.1 hx.2⟩
instance noTopOrder [LE α] [NoTopOrder α] [Nonempty α] : NoTopOrder (WithBot α) :=
⟨by
apply recBotCoe
· exact ‹Nonempty α›.elim fun a => ⟨a, not_coe_le_bot a⟩
· intro a
obtain ⟨b, h⟩ := exists_not_le a
exact ⟨b, by rwa [coe_le_coe]⟩
⟩
instance noMaxOrder [LT α] [NoMaxOrder α] [Nonempty α] : NoMaxOrder (WithBot α) :=
⟨by
apply WithBot.recBotCoe
· apply ‹Nonempty α›.elim
exact fun a => ⟨a, WithBot.bot_lt_coe a⟩
· intro a
obtain ⟨b, ha⟩ := exists_gt a
exact ⟨b, coe_lt_coe.mpr ha⟩
⟩
end WithBot
--TODO(Mario): Construct using order dual on `WithBot`
/-- Attach `⊤` to a type. -/
def WithTop (α : Type*) :=
Option α
namespace WithTop
variable {a b : α}
instance [Repr α] : Repr (WithTop α) :=
⟨fun o _ =>
match o with
| none => "⊤"
| some a => "↑" ++ repr a⟩
/-- The canonical map from `α` into `WithTop α` -/
@[coe, match_pattern] def some : α → WithTop α :=
Option.some
instance coeTC : CoeTC α (WithTop α) :=
⟨some⟩
instance top : Top (WithTop α) :=
⟨none⟩
instance inhabited : Inhabited (WithTop α) :=
⟨⊤⟩
instance nontrivial [Nonempty α] : Nontrivial (WithTop α) :=
Option.nontrivial
open Function
theorem coe_injective : Injective ((↑) : α → WithTop α) :=
Option.some_injective _
@[norm_cast]
theorem coe_inj : (a : WithTop α) = b ↔ a = b :=
Option.some_inj
protected theorem «forall» {p : WithTop α → Prop} : (∀ x, p x) ↔ p ⊤ ∧ ∀ x : α, p x :=
Option.forall
protected theorem «exists» {p : WithTop α → Prop} : (∃ x, p x) ↔ p ⊤ ∨ ∃ x : α, p x :=
Option.exists
theorem none_eq_top : (none : WithTop α) = (⊤ : WithTop α) :=
rfl
theorem some_eq_coe (a : α) : (Option.some a : WithTop α) = (↑a : WithTop α) :=
rfl
@[simp]
theorem top_ne_coe : ⊤ ≠ (a : WithTop α) :=
nofun
@[simp]
theorem coe_ne_top : (a : WithTop α) ≠ ⊤ :=
nofun
/-- Recursor for `WithTop` using the preferred forms `⊤` and `↑a`. -/
@[elab_as_elim, induction_eliminator, cases_eliminator]
def recTopCoe {C : WithTop α → Sort*} (top : C ⊤) (coe : ∀ a : α, C a) : ∀ n : WithTop α, C n
| none => top
| Option.some a => coe a
@[simp]
theorem recTopCoe_top {C : WithTop α → Sort*} (d : C ⊤) (f : ∀ a : α, C a) :
@recTopCoe _ C d f ⊤ = d :=
rfl
@[simp]
theorem recTopCoe_coe {C : WithTop α → Sort*} (d : C ⊤) (f : ∀ a : α, C a) (x : α) :
@recTopCoe _ C d f ↑x = f x :=
rfl
/-- `WithTop.toDual` is the equivalence sending `⊤` to `⊥` and any `a : α` to `toDual a : αᵒᵈ`.
See `WithTop.toDualBotEquiv` for the related order-iso.
-/
protected def toDual : WithTop α ≃ WithBot αᵒᵈ :=
Equiv.refl _
/-- `WithTop.ofDual` is the equivalence sending `⊤` to `⊥` and any `a : αᵒᵈ` to `ofDual a : α`.
See `WithTop.toDualBotEquiv` for the related order-iso.
-/
protected def ofDual : WithTop αᵒᵈ ≃ WithBot α :=
Equiv.refl _
/-- `WithBot.toDual` is the equivalence sending `⊥` to `⊤` and any `a : α` to `toDual a : αᵒᵈ`.
See `WithBot.toDual_top_equiv` for the related order-iso.
-/
protected def _root_.WithBot.toDual : WithBot α ≃ WithTop αᵒᵈ :=
Equiv.refl _
/-- `WithBot.ofDual` is the equivalence sending `⊥` to `⊤` and any `a : αᵒᵈ` to `ofDual a : α`.
See `WithBot.ofDual_top_equiv` for the related order-iso.
-/
protected def _root_.WithBot.ofDual : WithBot αᵒᵈ ≃ WithTop α :=
Equiv.refl _
@[simp]
theorem toDual_symm_apply (a : WithBot αᵒᵈ) : WithTop.toDual.symm a = WithBot.ofDual a :=
rfl
@[simp]
theorem ofDual_symm_apply (a : WithBot α) : WithTop.ofDual.symm a = WithBot.toDual a :=
rfl
@[simp]
theorem toDual_apply_top : WithTop.toDual (⊤ : WithTop α) = ⊥ :=
rfl
@[simp]
theorem ofDual_apply_top : WithTop.ofDual (⊤ : WithTop α) = ⊥ :=
rfl
open OrderDual
@[simp]
theorem toDual_apply_coe (a : α) : WithTop.toDual (a : WithTop α) = toDual a :=
rfl
@[simp]
theorem ofDual_apply_coe (a : αᵒᵈ) : WithTop.ofDual (a : WithTop αᵒᵈ) = ofDual a :=
rfl
/-- Specialization of `Option.getD` to values in `WithTop α` that respects API boundaries.
-/
def untop' (d : α) (x : WithTop α) : α :=
recTopCoe d id x
@[simp]
theorem untop'_top {α} (d : α) : untop' d ⊤ = d :=
rfl
@[simp]
theorem untop'_coe {α} (d x : α) : untop' d x = x :=
rfl
@[simp, norm_cast] -- Porting note: added `simp`
theorem coe_eq_coe : (a : WithTop α) = b ↔ a = b :=
Option.some_inj
theorem untop'_eq_iff {d y : α} {x : WithTop α} : untop' d x = y ↔ x = y ∨ x = ⊤ ∧ y = d :=
WithBot.unbot'_eq_iff
@[simp] theorem untop'_eq_self_iff {d : α} {x : WithTop α} : untop' d x = d ↔ x = d ∨ x = ⊤ :=
WithBot.unbot'_eq_self_iff
theorem untop'_eq_untop'_iff {d : α} {x y : WithTop α} :
untop' d x = untop' d y ↔ x = y ∨ x = d ∧ y = ⊤ ∨ x = ⊤ ∧ y = d :=
WithBot.unbot'_eq_unbot'_iff
/-- Lift a map `f : α → β` to `WithTop α → WithTop β`. Implemented using `Option.map`. -/
def map (f : α → β) : WithTop α → WithTop β :=
Option.map f
@[simp]
theorem map_top (f : α → β) : map f ⊤ = ⊤ :=
rfl
@[simp]
theorem map_coe (f : α → β) (a : α) : map f a = f a :=
rfl
theorem map_comm {f₁ : α → β} {f₂ : α → γ} {g₁ : β → δ} {g₂ : γ → δ}
(h : g₁ ∘ f₁ = g₂ ∘ f₂) (a : α) : map g₁ (map f₁ a) = map g₂ (map f₂ a) :=
Option.map_comm h _
/-- The image of a binary function `f : α → β → γ` as a function
`WithTop α → WithTop β → WithTop γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def map₂ : (α → β → γ) → WithTop α → WithTop β → WithTop γ := Option.map₂
lemma map₂_coe_coe (f : α → β → γ) (a : α) (b : β) : map₂ f a b = f a b := rfl
@[simp] lemma map₂_top_left (f : α → β → γ) (b) : map₂ f ⊤ b = ⊤ := rfl
@[simp] lemma map₂_top_right (f : α → β → γ) (a) : map₂ f a ⊤ = ⊤ := by cases a <;> rfl
@[simp] lemma map₂_coe_left (f : α → β → γ) (a : α) (b) : map₂ f a b = b.map fun b ↦ f a b := rfl
@[simp] lemma map₂_coe_right (f : α → β → γ) (a) (b : β) : map₂ f a b = a.map (f · b) := by
cases a <;> rfl
@[simp] lemma map₂_eq_top_iff {f : α → β → γ} {a : WithTop α} {b : WithTop β} :
map₂ f a b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := Option.map₂_eq_none_iff
theorem map_toDual (f : αᵒᵈ → βᵒᵈ) (a : WithBot α) :
map f (WithBot.toDual a) = a.map (toDual ∘ f) :=
rfl
theorem map_ofDual (f : α → β) (a : WithBot αᵒᵈ) : map f (WithBot.ofDual a) = a.map (ofDual ∘ f) :=
rfl
theorem toDual_map (f : α → β) (a : WithTop α) :
WithTop.toDual (map f a) = WithBot.map (toDual ∘ f ∘ ofDual) (WithTop.toDual a) :=
rfl
theorem ofDual_map (f : αᵒᵈ → βᵒᵈ) (a : WithTop αᵒᵈ) :
WithTop.ofDual (map f a) = WithBot.map (ofDual ∘ f ∘ toDual) (WithTop.ofDual a) :=
rfl
lemma ne_top_iff_exists {x : WithTop α} : x ≠ ⊤ ↔ ∃ a : α, ↑a = x := Option.ne_none_iff_exists
lemma forall_ne_iff_eq_top {x : WithTop α} : (∀ a : α, ↑a ≠ x) ↔ x = ⊤ :=
Option.forall_some_ne_iff_eq_none
/-- Deconstruct a `x : WithTop α` to the underlying value in `α`, given a proof that `x ≠ ⊤`. -/
def untop : ∀ x : WithTop α, x ≠ ⊤ → α | (x : α), _ => x
@[simp] lemma coe_untop : ∀ (x : WithTop α) hx, x.untop hx = x | (x : α), _ => rfl
@[simp]
theorem untop_coe (x : α) (h : (x : WithTop α) ≠ ⊤ := coe_ne_top) : (x : WithTop α).untop h = x :=
rfl
instance canLift : CanLift (WithTop α) α (↑) fun r => r ≠ ⊤ where
prf x h := ⟨x.untop h, coe_untop _ _⟩
instance instBot [Bot α] : Bot (WithTop α) where
bot := (⊥ : α)
@[simp, norm_cast] lemma coe_bot [Bot α] : ((⊥ : α) : WithTop α) = ⊥ := rfl
@[simp, norm_cast] lemma coe_eq_bot [Bot α] {a : α} : (a : WithTop α) = ⊥ ↔ a = ⊥ := coe_eq_coe
@[simp, norm_cast] lemma bot_eq_coe [Bot α] {a : α} : (⊥ : WithTop α) = a ↔ ⊥ = a := coe_eq_coe
theorem untop_eq_iff {a : WithTop α} {b : α} (h : a ≠ ⊤) :
a.untop h = b ↔ a = b :=
WithBot.unbot_eq_iff (α := αᵒᵈ) h
theorem eq_untop_iff {a : α} {b : WithTop α} (h : b ≠ ⊤) :
a = b.untop h ↔ a = b :=
WithBot.eq_unbot_iff (α := αᵒᵈ) h
section LE
variable [LE α]
instance (priority := 10) le : LE (WithTop α) :=
⟨fun o₁ o₂ => ∀ a : α, o₂ = ↑a → ∃ b : α, o₁ = ↑b ∧ b ≤ a⟩
theorem toDual_le_iff {a : WithTop α} {b : WithBot αᵒᵈ} :
WithTop.toDual a ≤ b ↔ WithBot.ofDual b ≤ a :=
Iff.rfl
theorem le_toDual_iff {a : WithBot αᵒᵈ} {b : WithTop α} :
a ≤ WithTop.toDual b ↔ b ≤ WithBot.ofDual a :=
Iff.rfl
@[simp]
theorem toDual_le_toDual_iff {a b : WithTop α} : WithTop.toDual a ≤ WithTop.toDual b ↔ b ≤ a :=
Iff.rfl
theorem ofDual_le_iff {a : WithTop αᵒᵈ} {b : WithBot α} :
WithTop.ofDual a ≤ b ↔ WithBot.toDual b ≤ a :=
Iff.rfl
theorem le_ofDual_iff {a : WithBot α} {b : WithTop αᵒᵈ} :
a ≤ WithTop.ofDual b ↔ b ≤ WithBot.toDual a :=
Iff.rfl
@[simp]
theorem ofDual_le_ofDual_iff {a b : WithTop αᵒᵈ} : WithTop.ofDual a ≤ WithTop.ofDual b ↔ b ≤ a :=
Iff.rfl
@[simp, norm_cast]
theorem coe_le_coe : (a : WithTop α) ≤ b ↔ a ≤ b := by
simp only [← toDual_le_toDual_iff, toDual_apply_coe, WithBot.coe_le_coe, toDual_le_toDual]
@[simp, deprecated coe_le_coe "Don't mix Option and WithTop" (since := "2024-05-27")]
theorem some_le_some : @LE.le (WithTop α) _ (Option.some a) (Option.some b) ↔ a ≤ b :=
coe_le_coe
instance orderTop : OrderTop (WithTop α) where
le_top := fun _ => toDual_le_toDual_iff.mp bot_le
@[simp, deprecated le_top "Don't mix Option and WithTop" (since := "2024-05-27")]
theorem le_none {a : WithTop α} : @LE.le (WithTop α) _ a none := le_top
instance orderBot [OrderBot α] : OrderBot (WithTop α) where
bot_le o a ha := by cases ha; exact ⟨_, rfl, bot_le⟩
instance boundedOrder [OrderBot α] : BoundedOrder (WithTop α) :=
{ WithTop.orderTop, WithTop.orderBot with }
theorem not_top_le_coe (a : α) : ¬(⊤ : WithTop α) ≤ ↑a :=
WithBot.not_coe_le_bot (toDual a)
/-- There is a general version `top_le_iff`, but this lemma does not require a `PartialOrder`. -/
@[simp]
protected theorem top_le_iff : ∀ {a : WithTop α}, ⊤ ≤ a ↔ a = ⊤
| (a : α) => by simp [not_top_le_coe _]
| ⊤ => by simp
theorem le_coe : ∀ {o : Option α}, a ∈ o → (@LE.le (WithTop α) _ o b ↔ a ≤ b)
| _, rfl => coe_le_coe
theorem le_coe_iff {x : WithTop α} : x ≤ b ↔ ∃ a : α, x = a ∧ a ≤ b :=
@WithBot.coe_le_iff (αᵒᵈ) _ _ (toDual x)
theorem coe_le_iff {x : WithTop α} : ↑a ≤ x ↔ ∀ b : α, x = ↑b → a ≤ b :=
@WithBot.le_coe_iff (αᵒᵈ) _ _ (toDual x)
protected theorem _root_.IsMin.withTop (h : IsMin a) : IsMin (a : WithTop α) := by
-- defeq to is_max_to_dual_iff.mp (is_max.with_bot _), but that breaks API boundary
intro _ hb
rw [← toDual_le_toDual_iff] at hb
simpa [toDual_le_iff] using h.toDual.withBot hb
theorem untop_le_iff {a : WithTop α} {b : α} (h : a ≠ ⊤) :
untop a h ≤ b ↔ a ≤ (b : WithTop α) :=
@WithBot.le_unbot_iff αᵒᵈ _ _ _ _
theorem le_untop_iff {a : α} {b : WithTop α} (h : b ≠ ⊤) :
a ≤ untop b h ↔ (a : WithTop α) ≤ b :=
@WithBot.unbot_le_iff αᵒᵈ _ _ _ _
theorem le_untop'_iff {a : WithTop α} {b c : α} (h : a = ⊤ → c ≤ b) :
c ≤ a.untop' b ↔ c ≤ a :=
WithBot.unbot'_le_iff (α := αᵒᵈ) h
end LE
section LT
variable [LT α]
instance (priority := 10) lt : LT (WithTop α) :=
⟨fun o₁ o₂ : Option α => ∃ b ∈ o₁, ∀ a ∈ o₂, b < a⟩
theorem toDual_lt_iff {a : WithTop α} {b : WithBot αᵒᵈ} :
WithTop.toDual a < b ↔ WithBot.ofDual b < a :=
Iff.rfl
theorem lt_toDual_iff {a : WithBot αᵒᵈ} {b : WithTop α} :
a < WithTop.toDual b ↔ b < WithBot.ofDual a :=
Iff.rfl
@[simp]
theorem toDual_lt_toDual_iff {a b : WithTop α} : WithTop.toDual a < WithTop.toDual b ↔ b < a :=
Iff.rfl
theorem ofDual_lt_iff {a : WithTop αᵒᵈ} {b : WithBot α} :
WithTop.ofDual a < b ↔ WithBot.toDual b < a :=
Iff.rfl
theorem lt_ofDual_iff {a : WithBot α} {b : WithTop αᵒᵈ} :
a < WithTop.ofDual b ↔ b < WithBot.toDual a :=
Iff.rfl
@[simp]
theorem ofDual_lt_ofDual_iff {a b : WithTop αᵒᵈ} : WithTop.ofDual a < WithTop.ofDual b ↔ b < a :=
Iff.rfl
theorem lt_untop_iff {a : α} {b : WithTop α} (h : b ≠ ⊤) :
a < b.untop h ↔ a < b :=
WithBot.unbot_lt_iff (α := αᵒᵈ) h
theorem untop_lt_iff {a : WithTop α} {b : α} (h : a ≠ ⊤) :
a.untop h < b ↔ a < b :=
WithBot.lt_unbot_iff (α := αᵒᵈ) h
theorem lt_untop'_iff {a : WithTop α} {b c : α} (h : a = ⊤ → c < b) :
c < a.untop' b ↔ c < a :=
WithBot.unbot'_lt_iff (α := αᵒᵈ) h
end LT
end WithTop
namespace WithBot
open OrderDual
@[simp]
theorem toDual_symm_apply (a : WithTop αᵒᵈ) : WithBot.toDual.symm a = WithTop.ofDual a :=
rfl
@[simp]
theorem ofDual_symm_apply (a : WithTop α) : WithBot.ofDual.symm a = WithTop.toDual a :=
rfl
@[simp]
theorem toDual_apply_bot : WithBot.toDual (⊥ : WithBot α) = ⊤ :=
rfl
@[simp]
theorem ofDual_apply_bot : WithBot.ofDual (⊥ : WithBot α) = ⊤ :=
rfl
@[simp]
theorem toDual_apply_coe (a : α) : WithBot.toDual (a : WithBot α) = toDual a :=
rfl
@[simp]
theorem ofDual_apply_coe (a : αᵒᵈ) : WithBot.ofDual (a : WithBot αᵒᵈ) = ofDual a :=
rfl
theorem map_toDual (f : αᵒᵈ → βᵒᵈ) (a : WithTop α) :
WithBot.map f (WithTop.toDual a) = a.map (toDual ∘ f) :=
rfl
theorem map_ofDual (f : α → β) (a : WithTop αᵒᵈ) :
WithBot.map f (WithTop.ofDual a) = a.map (ofDual ∘ f) :=
rfl
theorem toDual_map (f : α → β) (a : WithBot α) :
WithBot.toDual (WithBot.map f a) = map (toDual ∘ f ∘ ofDual) (WithBot.toDual a) :=
rfl
theorem ofDual_map (f : αᵒᵈ → βᵒᵈ) (a : WithBot αᵒᵈ) :
WithBot.ofDual (WithBot.map f a) = map (ofDual ∘ f ∘ toDual) (WithBot.ofDual a) :=
rfl
lemma forall_lt_iff_eq_bot [Preorder α] {x : WithBot α} :
(∀ y : α, x < y) ↔ x = ⊥ :=
⟨fun h ↦ forall_ne_iff_eq_bot.mp (fun x ↦ (h x).ne'), fun h ↦ h ▸ fun y ↦ bot_lt_coe y⟩
section LE
variable [LE α] {a b : α}
theorem toDual_le_iff {a : WithBot α} {b : WithTop αᵒᵈ} :
WithBot.toDual a ≤ b ↔ WithTop.ofDual b ≤ a :=
Iff.rfl
theorem le_toDual_iff {a : WithTop αᵒᵈ} {b : WithBot α} :
a ≤ WithBot.toDual b ↔ b ≤ WithTop.ofDual a :=
Iff.rfl
@[simp]
theorem toDual_le_toDual_iff {a b : WithBot α} : WithBot.toDual a ≤ WithBot.toDual b ↔ b ≤ a :=
Iff.rfl
theorem ofDual_le_iff {a : WithBot αᵒᵈ} {b : WithTop α} :
WithBot.ofDual a ≤ b ↔ WithTop.toDual b ≤ a :=
Iff.rfl
theorem le_ofDual_iff {a : WithTop α} {b : WithBot αᵒᵈ} :
a ≤ WithBot.ofDual b ↔ b ≤ WithTop.toDual a :=
Iff.rfl
@[simp]
theorem ofDual_le_ofDual_iff {a b : WithBot αᵒᵈ} : WithBot.ofDual a ≤ WithBot.ofDual b ↔ b ≤ a :=
Iff.rfl
end LE
section LT
variable [LT α] {a b : α}
theorem toDual_lt_iff {a : WithBot α} {b : WithTop αᵒᵈ} :
WithBot.toDual a < b ↔ WithTop.ofDual b < a :=
Iff.rfl
theorem lt_toDual_iff {a : WithTop αᵒᵈ} {b : WithBot α} :
a < WithBot.toDual b ↔ b < WithTop.ofDual a :=
Iff.rfl
@[simp]
theorem toDual_lt_toDual_iff {a b : WithBot α} : WithBot.toDual a < WithBot.toDual b ↔ b < a :=
Iff.rfl
theorem ofDual_lt_iff {a : WithBot αᵒᵈ} {b : WithTop α} :
WithBot.ofDual a < b ↔ WithTop.toDual b < a :=
Iff.rfl
theorem lt_ofDual_iff {a : WithTop α} {b : WithBot αᵒᵈ} :
a < WithBot.ofDual b ↔ b < WithTop.toDual a :=
Iff.rfl
@[simp]
theorem ofDual_lt_ofDual_iff {a b : WithBot αᵒᵈ} : WithBot.ofDual a < WithBot.ofDual b ↔ b < a :=
Iff.rfl
end LT
end WithBot
namespace WithTop
section LT
variable [LT α] {a b : α}
open OrderDual
@[simp, norm_cast]
theorem coe_lt_coe : (a : WithTop α) < b ↔ a < b := by
simp only [← toDual_lt_toDual_iff, toDual_apply_coe, WithBot.coe_lt_coe, toDual_lt_toDual]
@[simp]
theorem coe_lt_top (a : α) : (a : WithTop α) < ⊤ := by
simp [← toDual_lt_toDual_iff, WithBot.bot_lt_coe]
@[simp]
protected theorem not_top_lt (a : WithTop α) : ¬⊤ < a := by
rw [← toDual_lt_toDual_iff]
exact WithBot.not_lt_bot _
@[simp, deprecated coe_lt_coe "Don't mix Option and WithTop" (since := "2024-05-27")]
theorem some_lt_some : @LT.lt (WithTop α) _ (Option.some a) (Option.some b) ↔ a < b := coe_lt_coe
@[simp, deprecated coe_lt_top "Don't mix Option and WithTop" (since := "2024-05-27")]
theorem some_lt_none (a : α) : @LT.lt (WithTop α) _ (Option.some a) none := coe_lt_top a
@[simp, deprecated not_top_lt "Don't mix Option and WithTop" (since := "2024-05-27")]
theorem not_none_lt (a : WithTop α) : ¬@LT.lt (WithTop α) _ none a := WithTop.not_top_lt _
theorem lt_iff_exists_coe {a b : WithTop α} : a < b ↔ ∃ p : α, a = p ∧ ↑p < b := by
rw [← toDual_lt_toDual_iff, WithBot.lt_iff_exists_coe, OrderDual.exists]
exact exists_congr fun _ => and_congr_left' Iff.rfl
theorem coe_lt_iff {x : WithTop α} : ↑a < x ↔ ∀ b : α, x = ↑b → a < b :=
WithBot.lt_coe_iff (α := αᵒᵈ)
/-- A version of `lt_top_iff_ne_top` for `WithTop` that only requires `LT α`, not
`PartialOrder α`. -/
protected theorem lt_top_iff_ne_top {x : WithTop α} : x < ⊤ ↔ x ≠ ⊤ :=
@WithBot.bot_lt_iff_ne_bot αᵒᵈ _ x
end LT
instance preorder [Preorder α] : Preorder (WithTop α) where
le := (· ≤ ·)
lt := (· < ·)
lt_iff_le_not_le := @lt_iff_le_not_le (WithBot αᵒᵈ)ᵒᵈ _
le_refl := @le_refl (WithBot αᵒᵈ)ᵒᵈ _
le_trans := @le_trans (WithBot αᵒᵈ)ᵒᵈ _
instance partialOrder [PartialOrder α] : PartialOrder (WithTop α) where
le_antisymm := @le_antisymm (WithBot αᵒᵈ)ᵒᵈ _
section Preorder
variable [Preorder α] [Preorder β]
theorem coe_strictMono : StrictMono (fun a : α => (a : WithTop α)) := fun _ _ => coe_lt_coe.2
theorem coe_mono : Monotone (fun a : α => (a : WithTop α)) := fun _ _ => coe_le_coe.2
theorem monotone_iff {f : WithTop α → β} :
Monotone f ↔ Monotone (fun (a : α) => f a) ∧ ∀ x : α, f x ≤ f ⊤ :=
⟨fun h => ⟨h.comp WithTop.coe_mono, fun _ => h le_top⟩, fun h =>
WithTop.forall.2
⟨WithTop.forall.2 ⟨fun _ => le_rfl, fun _ h => (not_top_le_coe _ h).elim⟩, fun x =>
WithTop.forall.2 ⟨fun _ => h.2 x, fun _ hle => h.1 (coe_le_coe.1 hle)⟩⟩⟩
@[simp]
theorem monotone_map_iff {f : α → β} : Monotone (WithTop.map f) ↔ Monotone f :=
monotone_iff.trans <| by simp [Monotone]
alias ⟨_, _root_.Monotone.withTop_map⟩ := monotone_map_iff
theorem strictMono_iff {f : WithTop α → β} :
StrictMono f ↔ StrictMono (fun (a : α) => f a) ∧ ∀ x : α, f x < f ⊤ :=
⟨fun h => ⟨h.comp WithTop.coe_strictMono, fun _ => h (coe_lt_top _)⟩, fun h =>
WithTop.forall.2
⟨WithTop.forall.2 ⟨flip absurd (lt_irrefl _), fun _ h => (not_top_lt h).elim⟩, fun x =>
WithTop.forall.2 ⟨fun _ => h.2 x, fun _ hle => h.1 (coe_lt_coe.1 hle)⟩⟩⟩
theorem strictAnti_iff {f : WithTop α → β} :
StrictAnti f ↔ StrictAnti (fun a ↦ f a : α → β) ∧ ∀ x : α, f ⊤ < f x :=
strictMono_iff (β := βᵒᵈ)
@[simp]
theorem strictMono_map_iff {f : α → β} : StrictMono (WithTop.map f) ↔ StrictMono f :=
strictMono_iff.trans <| by simp [StrictMono, coe_lt_top]
alias ⟨_, _root_.StrictMono.withTop_map⟩ := strictMono_map_iff
theorem map_le_iff (f : α → β) (a b : WithTop α)
(mono_iff : ∀ {a b}, f a ≤ f b ↔ a ≤ b) :
a.map f ≤ b.map f ↔ a ≤ b := by
erw [← toDual_le_toDual_iff, toDual_map, toDual_map, WithBot.map_le_iff, toDual_le_toDual_iff]
simp [mono_iff]
theorem coe_untop'_le (a : WithTop α) (b : α) : a.untop' b ≤ a :=
WithBot.le_coe_unbot' (α := αᵒᵈ) a b
@[simp]
theorem coe_top_lt [OrderTop α] {x : WithTop α} : (⊤ : α) < x ↔ x = ⊤ :=
WithBot.lt_coe_bot (α := αᵒᵈ)
lemma forall_lt_iff_eq_top {x : WithTop α} : (∀ y : α, y < x) ↔ x = ⊤ :=
⟨fun h ↦ forall_ne_iff_eq_top.mp (fun x ↦ (h x).ne), fun h ↦ h ▸ fun y ↦ coe_lt_top y⟩
end Preorder
instance semilatticeInf [SemilatticeInf α] : SemilatticeInf (WithTop α) :=
{ WithTop.partialOrder with
inf := Option.liftOrGet (· ⊓ ·),
inf_le_left := @inf_le_left (WithBot αᵒᵈ)ᵒᵈ _
inf_le_right := @inf_le_right (WithBot αᵒᵈ)ᵒᵈ _
le_inf := @le_inf (WithBot αᵒᵈ)ᵒᵈ _ }
theorem coe_inf [SemilatticeInf α] (a b : α) : ((a ⊓ b : α) : WithTop α) = (a : WithTop α) ⊓ b :=
rfl
instance semilatticeSup [SemilatticeSup α] : SemilatticeSup (WithTop α) :=
{ WithTop.partialOrder with
sup := WithTop.map₂ (· ⊔ ·),
le_sup_left := @le_sup_left (WithBot αᵒᵈ)ᵒᵈ _
le_sup_right := @le_sup_right (WithBot αᵒᵈ)ᵒᵈ _
sup_le := @sup_le (WithBot αᵒᵈ)ᵒᵈ _ }
theorem coe_sup [SemilatticeSup α] (a b : α) : ((a ⊔ b : α) : WithTop α) = (a : WithTop α) ⊔ b :=
rfl
instance lattice [Lattice α] : Lattice (WithTop α) :=
{ WithTop.semilatticeSup, WithTop.semilatticeInf with }
instance distribLattice [DistribLattice α] : DistribLattice (WithTop α) :=
{ WithTop.lattice with
le_sup_inf := @le_sup_inf (WithBot αᵒᵈ)ᵒᵈ _ }
instance decidableEq [DecidableEq α] : DecidableEq (WithTop α) :=
inferInstanceAs <| DecidableEq (Option α)
instance decidableLE [LE α] [@DecidableRel α (· ≤ ·)] :
@DecidableRel (WithTop α) (· ≤ ·) := fun _ _ =>
decidable_of_decidable_of_iff toDual_le_toDual_iff
instance decidableLT [LT α] [@DecidableRel α (· < ·)] :
@DecidableRel (WithTop α) (· < ·) := fun _ _ =>
decidable_of_decidable_of_iff toDual_lt_toDual_iff
instance isTotal_le [LE α] [IsTotal α (· ≤ ·)] : IsTotal (WithTop α) (· ≤ ·) :=
⟨fun _ _ => by
simp_rw [← toDual_le_toDual_iff]
exact total_of _ _ _⟩
instance linearOrder [LinearOrder α] : LinearOrder (WithTop α) :=
Lattice.toLinearOrder _
@[simp, norm_cast]
theorem coe_min [LinearOrder α] (x y : α) : (↑(min x y) : WithTop α) = min (x : WithTop α) y :=
rfl
@[simp, norm_cast]
theorem coe_max [LinearOrder α] (x y : α) : (↑(max x y) : WithTop α) = max (x : WithTop α) y :=
rfl
instance instWellFoundedLT [LT α] [WellFoundedLT α] : WellFoundedLT (WithTop α) :=
inferInstanceAs <| WellFoundedLT (WithBot αᵒᵈ)ᵒᵈ
open OrderDual
instance instWellFoundedGT [LT α] [WellFoundedGT α] : WellFoundedGT (WithTop α) :=
inferInstanceAs <| WellFoundedGT (WithBot αᵒᵈ)ᵒᵈ
instance trichotomous.lt [Preorder α] [IsTrichotomous α (· < ·)] :
IsTrichotomous (WithTop α) (· < ·) :=
⟨fun
| (a : α), (b : α) => by simp [trichotomous]
| ⊤, (b : α) => by simp
| (a : α), ⊤ => by simp
| ⊤, ⊤ => by simp⟩
instance IsWellOrder.lt [Preorder α] [IsWellOrder α (· < ·)] : IsWellOrder (WithTop α) (· < ·) where
instance trichotomous.gt [Preorder α] [IsTrichotomous α (· > ·)] :
IsTrichotomous (WithTop α) (· > ·) :=
have : IsTrichotomous α (· < ·) := .swap _; .swap _
instance IsWellOrder.gt [Preorder α] [IsWellOrder α (· > ·)] : IsWellOrder (WithTop α) (· > ·) where
instance _root_.WithBot.trichotomous.lt [Preorder α] [h : IsTrichotomous α (· < ·)] :
IsTrichotomous (WithBot α) (· < ·) :=
@WithTop.trichotomous.gt αᵒᵈ _ h
instance _root_.WithBot.isWellOrder.lt [Preorder α] [IsWellOrder α (· < ·)] :
IsWellOrder (WithBot α) (· < ·) where
instance _root_.WithBot.trichotomous.gt [Preorder α] [h : IsTrichotomous α (· > ·)] :
IsTrichotomous (WithBot α) (· > ·) :=
@WithTop.trichotomous.lt αᵒᵈ _ h
instance _root_.WithBot.isWellOrder.gt [Preorder α] [h : IsWellOrder α (· > ·)] :
IsWellOrder (WithBot α) (· > ·) :=
@WithTop.IsWellOrder.lt αᵒᵈ _ h
instance [LT α] [DenselyOrdered α] [NoMaxOrder α] : DenselyOrdered (WithTop α) :=
OrderDual.denselyOrdered (WithBot αᵒᵈ)
theorem lt_iff_exists_coe_btwn [Preorder α] [DenselyOrdered α] [NoMaxOrder α] {a b : WithTop α} :
a < b ↔ ∃ x : α, a < ↑x ∧ ↑x < b :=
⟨fun h =>
let ⟨_, hy⟩ := exists_between h
let ⟨x, hx⟩ := lt_iff_exists_coe.1 hy.2
⟨x, hx.1 ▸ hy⟩,
fun ⟨_, hx⟩ => lt_trans hx.1 hx.2⟩
instance noBotOrder [LE α] [NoBotOrder α] [Nonempty α] : NoBotOrder (WithTop α) :=
@OrderDual.noBotOrder (WithBot αᵒᵈ) _ _
instance noMinOrder [LT α] [NoMinOrder α] [Nonempty α] : NoMinOrder (WithTop α) :=
@OrderDual.noMinOrder (WithBot αᵒᵈ) _ _
end WithTop
|
Order\Zorn.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Order.Chain
/-!
# Zorn's lemmas
This file proves several formulations of Zorn's Lemma.
## Variants
The primary statement of Zorn's lemma is `exists_maximal_of_chains_bounded`. Then it is specialized
to particular relations:
* `(≤)` with `zorn_partialOrder`
* `(⊆)` with `zorn_subset`
* `(⊇)` with `zorn_superset`
Lemma names carry modifiers:
* `₀`: Quantifies over a set, as opposed to over a type.
* `_nonempty`: Doesn't ask to prove that the empty chain is bounded and lets you give an element
that will be smaller than the maximal element found (the maximal element is no smaller than any
other element, but it can also be incomparable to some).
## How-to
This file comes across as confusing to those who haven't yet used it, so here is a detailed
walkthrough:
1. Know what relation on which type/set you're looking for. See Variants above. You can discharge
some conditions to Zorn's lemma directly using a `_nonempty` variant.
2. Write down the definition of your type/set, put a `suffices ∃ m, ∀ a, m ≺ a → a ≺ m by ...`
(or whatever you actually need) followed by an `apply some_version_of_zorn`.
3. Fill in the details. This is where you start talking about chains.
A typical proof using Zorn could look like this
```lean
lemma zorny_lemma : zorny_statement := by
let s : Set α := {x | whatever x}
suffices ∃ x ∈ s, ∀ y ∈ s, y ⊆ x → y = x by -- or with another operator xxx
proof_post_zorn
apply zorn_subset -- or another variant
rintro c hcs hc
obtain rfl | hcnemp := c.eq_empty_or_nonempty -- you might need to disjunct on c empty or not
· exact ⟨edge_case_construction,
proof_that_edge_case_construction_respects_whatever,
proof_that_edge_case_construction_contains_all_stuff_in_c⟩
· exact ⟨construction,
proof_that_construction_respects_whatever,
proof_that_construction_contains_all_stuff_in_c⟩
```
## Notes
Originally ported from Isabelle/HOL. The
[original file](https://isabelle.in.tum.de/dist/library/HOL/HOL/Zorn.html) was written by Jacques D.
Fleuriot, Tobias Nipkow, Christian Sternagel.
-/
open Set
variable {α β : Type*} {r : α → α → Prop} {c : Set α}
/-- Local notation for the relation being considered. -/
local infixl:50 " ≺ " => r
/-- **Zorn's lemma**
If every chain has an upper bound, then there exists a maximal element. -/
theorem exists_maximal_of_chains_bounded (h : ∀ c, IsChain r c → ∃ ub, ∀ a ∈ c, a ≺ ub)
(trans : ∀ {a b c}, a ≺ b → b ≺ c → a ≺ c) : ∃ m, ∀ a, m ≺ a → a ≺ m :=
have : ∃ ub, ∀ a ∈ maxChain r, a ≺ ub := h _ <| maxChain_spec.left
let ⟨ub, (hub : ∀ a ∈ maxChain r, a ≺ ub)⟩ := this
⟨ub, fun a ha =>
have : IsChain r (insert a <| maxChain r) :=
maxChain_spec.1.insert fun b hb _ => Or.inr <| trans (hub b hb) ha
hub a <| by
rw [maxChain_spec.right this (subset_insert _ _)]
exact mem_insert _ _⟩
/-- A variant of Zorn's lemma. If every nonempty chain of a nonempty type has an upper bound, then
there is a maximal element.
-/
theorem exists_maximal_of_nonempty_chains_bounded [Nonempty α]
(h : ∀ c, IsChain r c → c.Nonempty → ∃ ub, ∀ a ∈ c, a ≺ ub)
(trans : ∀ {a b c}, a ≺ b → b ≺ c → a ≺ c) : ∃ m, ∀ a, m ≺ a → a ≺ m :=
exists_maximal_of_chains_bounded
(fun c hc =>
(eq_empty_or_nonempty c).elim
(fun h => ⟨Classical.arbitrary α, fun x hx => (h ▸ hx : x ∈ (∅ : Set α)).elim⟩) (h c hc))
trans
section Preorder
variable [Preorder α]
theorem zorn_preorder (h : ∀ c : Set α, IsChain (· ≤ ·) c → BddAbove c) :
∃ m : α, ∀ a, m ≤ a → a ≤ m :=
exists_maximal_of_chains_bounded h le_trans
theorem zorn_nonempty_preorder [Nonempty α]
(h : ∀ c : Set α, IsChain (· ≤ ·) c → c.Nonempty → BddAbove c) : ∃ m : α, ∀ a, m ≤ a → a ≤ m :=
exists_maximal_of_nonempty_chains_bounded h le_trans
theorem zorn_preorder₀ (s : Set α)
(ih : ∀ c ⊆ s, IsChain (· ≤ ·) c → ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) :
∃ m ∈ s, ∀ z ∈ s, m ≤ z → z ≤ m :=
let ⟨⟨m, hms⟩, h⟩ :=
@zorn_preorder s _ fun c hc =>
let ⟨ub, hubs, hub⟩ :=
ih (Subtype.val '' c) (fun _ ⟨⟨_, hx⟩, _, h⟩ => h ▸ hx)
(by
rintro _ ⟨p, hpc, rfl⟩ _ ⟨q, hqc, rfl⟩ hpq
exact hc hpc hqc fun t => hpq (Subtype.ext_iff.1 t))
⟨⟨ub, hubs⟩, fun ⟨y, hy⟩ hc => hub _ ⟨_, hc, rfl⟩⟩
⟨m, hms, fun z hzs hmz => h ⟨z, hzs⟩ hmz⟩
theorem zorn_nonempty_preorder₀ (s : Set α)
(ih : ∀ c ⊆ s, IsChain (· ≤ ·) c → ∀ y ∈ c, ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) (x : α)
(hxs : x ∈ s) : ∃ m ∈ s, x ≤ m ∧ ∀ z ∈ s, m ≤ z → z ≤ m := by
-- Porting note: the first three lines replace the following two lines in mathlib3.
-- The mathlib3 `rcases` supports holes for proof obligations, this is not yet implemented in 4.
-- rcases zorn_preorder₀ ({ y ∈ s | x ≤ y }) fun c hcs hc => ?_ with ⟨m, ⟨hms, hxm⟩, hm⟩
-- · exact ⟨m, hms, hxm, fun z hzs hmz => hm _ ⟨hzs, hxm.trans hmz⟩ hmz⟩
have H := zorn_preorder₀ ({ y ∈ s | x ≤ y }) fun c hcs hc => ?_
· rcases H with ⟨m, ⟨hms, hxm⟩, hm⟩
exact ⟨m, hms, hxm, fun z hzs hmz => hm _ ⟨hzs, hxm.trans hmz⟩ hmz⟩
· rcases c.eq_empty_or_nonempty with (rfl | ⟨y, hy⟩)
· exact ⟨x, ⟨hxs, le_rfl⟩, fun z => False.elim⟩
· rcases ih c (fun z hz => (hcs hz).1) hc y hy with ⟨z, hzs, hz⟩
exact ⟨z, ⟨hzs, (hcs hy).2.trans <| hz _ hy⟩, hz⟩
theorem zorn_nonempty_Ici₀ (a : α)
(ih : ∀ c ⊆ Ici a, IsChain (· ≤ ·) c → ∀ y ∈ c, ∃ ub, ∀ z ∈ c, z ≤ ub)
(x : α) (hax : a ≤ x) : ∃ m, x ≤ m ∧ ∀ z, m ≤ z → z ≤ m := by
let ⟨m, _, hxm, hm⟩ := zorn_nonempty_preorder₀ (Ici a) (fun c hca hc y hy ↦ ?_) x hax
· exact ⟨m, hxm, fun z hmz => hm _ (hax.trans <| hxm.trans hmz) hmz⟩
· have ⟨ub, hub⟩ := ih c hca hc y hy; exact ⟨ub, (hca hy).trans (hub y hy), hub⟩
end Preorder
section PartialOrder
variable [PartialOrder α]
theorem zorn_partialOrder (h : ∀ c : Set α, IsChain (· ≤ ·) c → BddAbove c) :
∃ m : α, ∀ a, m ≤ a → a = m :=
let ⟨m, hm⟩ := zorn_preorder h
⟨m, fun a ha => le_antisymm (hm a ha) ha⟩
theorem zorn_nonempty_partialOrder [Nonempty α]
(h : ∀ c : Set α, IsChain (· ≤ ·) c → c.Nonempty → BddAbove c) : ∃ m : α, ∀ a, m ≤ a → a = m :=
let ⟨m, hm⟩ := zorn_nonempty_preorder h
⟨m, fun a ha => le_antisymm (hm a ha) ha⟩
theorem zorn_partialOrder₀ (s : Set α)
(ih : ∀ c ⊆ s, IsChain (· ≤ ·) c → ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) :
∃ m ∈ s, ∀ z ∈ s, m ≤ z → z = m :=
let ⟨m, hms, hm⟩ := zorn_preorder₀ s ih
⟨m, hms, fun z hzs hmz => (hm z hzs hmz).antisymm hmz⟩
theorem zorn_nonempty_partialOrder₀ (s : Set α)
(ih : ∀ c ⊆ s, IsChain (· ≤ ·) c → ∀ y ∈ c, ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) (x : α)
(hxs : x ∈ s) : ∃ m ∈ s, x ≤ m ∧ ∀ z ∈ s, m ≤ z → z = m :=
let ⟨m, hms, hxm, hm⟩ := zorn_nonempty_preorder₀ s ih x hxs
⟨m, hms, hxm, fun z hzs hmz => (hm z hzs hmz).antisymm hmz⟩
end PartialOrder
theorem zorn_subset (S : Set (Set α))
(h : ∀ c ⊆ S, IsChain (· ⊆ ·) c → ∃ ub ∈ S, ∀ s ∈ c, s ⊆ ub) :
∃ m ∈ S, ∀ a ∈ S, m ⊆ a → a = m :=
zorn_partialOrder₀ S h
theorem zorn_subset_nonempty (S : Set (Set α))
(H : ∀ c ⊆ S, IsChain (· ⊆ ·) c → c.Nonempty → ∃ ub ∈ S, ∀ s ∈ c, s ⊆ ub) (x)
(hx : x ∈ S) : ∃ m ∈ S, x ⊆ m ∧ ∀ a ∈ S, m ⊆ a → a = m :=
zorn_nonempty_partialOrder₀ _ (fun _ cS hc y yc => H _ cS hc ⟨y, yc⟩) _ hx
theorem zorn_superset (S : Set (Set α))
(h : ∀ c ⊆ S, IsChain (· ⊆ ·) c → ∃ lb ∈ S, ∀ s ∈ c, lb ⊆ s) :
∃ m ∈ S, ∀ a ∈ S, a ⊆ m → a = m :=
(@zorn_partialOrder₀ (Set α)ᵒᵈ _ S) fun c cS hc => h c cS hc.symm
theorem zorn_superset_nonempty (S : Set (Set α))
(H : ∀ c ⊆ S, IsChain (· ⊆ ·) c → c.Nonempty → ∃ lb ∈ S, ∀ s ∈ c, lb ⊆ s) (x)
(hx : x ∈ S) : ∃ m ∈ S, m ⊆ x ∧ ∀ a ∈ S, a ⊆ m → a = m :=
@zorn_nonempty_partialOrder₀ (Set α)ᵒᵈ _ S (fun _ cS hc y yc => H _ cS hc.symm ⟨y, yc⟩) _ hx
/-- Every chain is contained in a maximal chain. This generalizes Hausdorff's maximality principle.
-/
theorem IsChain.exists_maxChain (hc : IsChain r c) : ∃ M, @IsMaxChain _ r M ∧ c ⊆ M := by
-- Porting note: the first three lines replace the following two lines in mathlib3.
-- The mathlib3 `obtain` supports holes for proof obligations, this is not yet implemented in 4.
-- obtain ⟨M, ⟨_, hM₀⟩, hM₁, hM₂⟩ :=
-- zorn_subset_nonempty { s | c ⊆ s ∧ IsChain r s } _ c ⟨Subset.rfl, hc⟩
have H := zorn_subset_nonempty { s | c ⊆ s ∧ IsChain r s } ?_ c ⟨Subset.rfl, hc⟩
· obtain ⟨M, ⟨_, hM₀⟩, hM₁, hM₂⟩ := H
exact ⟨M, ⟨hM₀, fun d hd hMd => (hM₂ _ ⟨hM₁.trans hMd, hd⟩ hMd).symm⟩, hM₁⟩
rintro cs hcs₀ hcs₁ ⟨s, hs⟩
refine
⟨⋃₀cs, ⟨fun _ ha => Set.mem_sUnion_of_mem ((hcs₀ hs).left ha) hs, ?_⟩, fun _ =>
Set.subset_sUnion_of_mem⟩
rintro y ⟨sy, hsy, hysy⟩ z ⟨sz, hsz, hzsz⟩ hyz
obtain rfl | hsseq := eq_or_ne sy sz
· exact (hcs₀ hsy).right hysy hzsz hyz
cases' hcs₁ hsy hsz hsseq with h h
· exact (hcs₀ hsz).right (h hysy) hzsz hyz
· exact (hcs₀ hsy).right hysy (h hzsz) hyz
|
Order\ZornAtoms.lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Order.Zorn
import Mathlib.Order.Atoms
/-!
# Zorn lemma for (co)atoms
In this file we use Zorn's lemma to prove that a partial order is atomic if every nonempty chain
`c`, `⊥ ∉ c`, has a lower bound not equal to `⊥`. We also prove the order dual version of this
statement.
-/
open Set
/-- **Zorn's lemma**: A partial order is coatomic if every nonempty chain `c`, `⊤ ∉ c`, has an upper
bound not equal to `⊤`. -/
theorem IsCoatomic.of_isChain_bounded {α : Type*} [PartialOrder α] [OrderTop α]
(h :
∀ c : Set α,
IsChain (· ≤ ·) c → c.Nonempty → ⊤ ∉ c → ∃ x ≠ ⊤, x ∈ upperBounds c) :
IsCoatomic α := by
refine ⟨fun x => le_top.eq_or_lt.imp_right fun hx => ?_⟩
have : ∃ y ∈ Ico x ⊤, x ≤ y ∧ ∀ z ∈ Ico x ⊤, y ≤ z → z = y := by
refine zorn_nonempty_partialOrder₀ (Ico x ⊤) (fun c hxc hc y hy => ?_) x (left_mem_Ico.2 hx)
rcases h c hc ⟨y, hy⟩ fun h => (hxc h).2.ne rfl with ⟨z, hz, hcz⟩
exact ⟨z, ⟨le_trans (hxc hy).1 (hcz hy), hz.lt_top⟩, hcz⟩
rcases this with ⟨y, ⟨hxy, hy⟩, -, hy'⟩
refine ⟨y, ⟨hy.ne, fun z hyz => le_top.eq_or_lt.resolve_right fun hz => ?_⟩, hxy⟩
exact hyz.ne' (hy' z ⟨hxy.trans hyz.le, hz⟩ hyz.le)
/-- **Zorn's lemma**: A partial order is atomic if every nonempty chain `c`, `⊥ ∉ c`, has a lower
bound not equal to `⊥`. -/
theorem IsAtomic.of_isChain_bounded {α : Type*} [PartialOrder α] [OrderBot α]
(h :
∀ c : Set α,
IsChain (· ≤ ·) c → c.Nonempty → ⊥ ∉ c → ∃ x ≠ ⊥, x ∈ lowerBounds c) :
IsAtomic α :=
isCoatomic_dual_iff_isAtomic.mp <| IsCoatomic.of_isChain_bounded fun c hc => h c hc.symm
|
Order\Atoms\Finite.lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Order.Interval.Finset.Defs
import Mathlib.Order.Atoms
/-!
# Atoms, Coatoms, Simple Lattices, and Finiteness
This module contains some results on atoms and simple lattices in the finite context.
## Main results
* `Finite.to_isAtomic`, `Finite.to_isCoatomic`: Finite partial orders with bottom resp. top
are atomic resp. coatomic.
-/
variable {α β : Type*}
namespace IsSimpleOrder
section DecidableEq
/- It is important that `IsSimpleOrder` is the last type-class argument of this instance,
so that type-class inference fails quickly if it doesn't apply. -/
instance (priority := 200) {α} [DecidableEq α] [LE α] [BoundedOrder α] [IsSimpleOrder α] :
Fintype α :=
Fintype.ofEquiv Bool equivBool.symm
end DecidableEq
end IsSimpleOrder
namespace Fintype
namespace IsSimpleOrder
variable [PartialOrder α] [BoundedOrder α] [IsSimpleOrder α] [DecidableEq α]
theorem univ : (Finset.univ : Finset α) = {⊤, ⊥} := by
change Finset.map _ (Finset.univ : Finset Bool) = _
rw [Fintype.univ_bool]
simp only [Finset.map_insert, Function.Embedding.coeFn_mk, Finset.map_singleton]
rfl
theorem card : Fintype.card α = 2 :=
(Fintype.ofEquiv_card _).trans Fintype.card_bool
end IsSimpleOrder
end Fintype
namespace Bool
instance : IsSimpleOrder Bool :=
⟨fun a => by
rw [← Finset.mem_singleton, Or.comm, ← Finset.mem_insert, top_eq_true, bot_eq_false, ←
Fintype.univ_bool]
apply Finset.mem_univ⟩
end Bool
section Fintype
open Finset
-- see Note [lower instance priority]
instance (priority := 100) Finite.to_isCoatomic [PartialOrder α] [OrderTop α] [Finite α] :
IsCoatomic α := by
refine IsCoatomic.mk fun b => or_iff_not_imp_left.2 fun ht => ?_
obtain ⟨c, hc, hmax⟩ :=
Set.Finite.exists_maximal_wrt id { x : α | b ≤ x ∧ x ≠ ⊤ } (Set.toFinite _) ⟨b, le_rfl, ht⟩
refine ⟨c, ⟨hc.2, fun y hcy => ?_⟩, hc.1⟩
by_contra hyt
obtain rfl : c = y := hmax y ⟨hc.1.trans hcy.le, hyt⟩ hcy.le
exact (lt_self_iff_false _).mp hcy
-- see Note [lower instance priority]
instance (priority := 100) Finite.to_isAtomic [PartialOrder α] [OrderBot α] [Finite α] :
IsAtomic α :=
isCoatomic_dual_iff_isAtomic.mp Finite.to_isCoatomic
end Fintype
section LocallyFinite
variable [Preorder α] [LocallyFiniteOrder α]
instance : IsStronglyAtomic α where
exists_covBy_le_of_lt a b hab := by
obtain ⟨x, hxmem, hx⟩ := (LocallyFiniteOrder.finsetIoc a b).exists_minimal
⟨b, by simpa [LocallyFiniteOrder.finset_mem_Ioc]⟩
simp only [LocallyFiniteOrder.finset_mem_Ioc, and_imp] at hxmem hx
exact ⟨x, ⟨hxmem.1, fun c hac hcx ↦ hx _ hac (hcx.le.trans hxmem.2) hcx⟩, hxmem.2⟩
instance : IsStronglyCoatomic α := by
rw [← isStronglyAtomic_dual_iff_is_stronglyCoatomic]; infer_instance
end LocallyFinite
section IsStronglyAtomic
variable [PartialOrder α] {a : α}
theorem exists_covby_infinite_Ici_of_infinite_Ici [IsStronglyAtomic α]
(ha : (Set.Ici a).Infinite) (hfin : {x | a ⋖ x}.Finite) :
∃ b, a ⋖ b ∧ (Set.Ici b).Infinite := by
by_contra! h
refine ((hfin.biUnion (t := Set.Ici) (by simpa using h)).subset (fun b hb ↦ ?_)).not_infinite
(ha.diff (Set.finite_singleton a))
obtain ⟨x, hax, hxb⟩ := ((show a ≤ b from hb.1).lt_of_ne (Ne.symm hb.2)).exists_covby_le
exact Set.mem_biUnion hax hxb
theorem exists_covby_infinite_Iic_of_infinite_Iic [IsStronglyCoatomic α]
(ha : (Set.Iic a).Infinite) (hfin : {x | x ⋖ a}.Finite) :
∃ b, b ⋖ a ∧ (Set.Iic b).Infinite := by
simp_rw [← toDual_covBy_toDual_iff (α := α)] at hfin ⊢
exact exists_covby_infinite_Ici_of_infinite_Ici (α := αᵒᵈ) ha hfin
end IsStronglyAtomic
|
Order\Bounds\Basic.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Data.Set.NAry
import Mathlib.Order.Directed
/-!
# Upper / lower bounds
In this file we define:
* `upperBounds`, `lowerBounds` : the set of upper bounds (resp., lower bounds) of a set;
* `BddAbove s`, `BddBelow s` : the set `s` is bounded above (resp., below), i.e., the set of upper
(resp., lower) bounds of `s` is nonempty;
* `IsLeast s a`, `IsGreatest s a` : `a` is a least (resp., greatest) element of `s`;
for a partial order, it is unique if exists;
* `IsLUB s a`, `IsGLB s a` : `a` is a least upper bound (resp., a greatest lower bound)
of `s`; for a partial order, it is unique if exists.
We also prove various lemmas about monotonicity, behaviour under `∪`, `∩`, `insert`, and provide
formulas for `∅`, `univ`, and intervals.
-/
open Function Set
open OrderDual (toDual ofDual)
universe u v w x
variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}
section
variable [Preorder α] [Preorder β] {s t : Set α} {a b : α}
/-!
### Definitions
-/
/-- The set of upper bounds of a set. -/
def upperBounds (s : Set α) : Set α :=
{ x | ∀ ⦃a⦄, a ∈ s → a ≤ x }
/-- The set of lower bounds of a set. -/
def lowerBounds (s : Set α) : Set α :=
{ x | ∀ ⦃a⦄, a ∈ s → x ≤ a }
/-- A set is bounded above if there exists an upper bound. -/
def BddAbove (s : Set α) :=
(upperBounds s).Nonempty
/-- A set is bounded below if there exists a lower bound. -/
def BddBelow (s : Set α) :=
(lowerBounds s).Nonempty
/-- `a` is a least element of a set `s`; for a partial order, it is unique if exists. -/
def IsLeast (s : Set α) (a : α) : Prop :=
a ∈ s ∧ a ∈ lowerBounds s
/-- `a` is a greatest element of a set `s`; for a partial order, it is unique if exists. -/
def IsGreatest (s : Set α) (a : α) : Prop :=
a ∈ s ∧ a ∈ upperBounds s
/-- `a` is a least upper bound of a set `s`; for a partial order, it is unique if exists. -/
def IsLUB (s : Set α) : α → Prop :=
IsLeast (upperBounds s)
/-- `a` is a greatest lower bound of a set `s`; for a partial order, it is unique if exists. -/
def IsGLB (s : Set α) : α → Prop :=
IsGreatest (lowerBounds s)
theorem mem_upperBounds : a ∈ upperBounds s ↔ ∀ x ∈ s, x ≤ a :=
Iff.rfl
theorem mem_lowerBounds : a ∈ lowerBounds s ↔ ∀ x ∈ s, a ≤ x :=
Iff.rfl
lemma mem_upperBounds_iff_subset_Iic : a ∈ upperBounds s ↔ s ⊆ Iic a := Iff.rfl
lemma mem_lowerBounds_iff_subset_Ici : a ∈ lowerBounds s ↔ s ⊆ Ici a := Iff.rfl
theorem bddAbove_def : BddAbove s ↔ ∃ x, ∀ y ∈ s, y ≤ x :=
Iff.rfl
theorem bddBelow_def : BddBelow s ↔ ∃ x, ∀ y ∈ s, x ≤ y :=
Iff.rfl
theorem bot_mem_lowerBounds [OrderBot α] (s : Set α) : ⊥ ∈ lowerBounds s := fun _ _ => bot_le
theorem top_mem_upperBounds [OrderTop α] (s : Set α) : ⊤ ∈ upperBounds s := fun _ _ => le_top
@[simp]
theorem isLeast_bot_iff [OrderBot α] : IsLeast s ⊥ ↔ ⊥ ∈ s :=
and_iff_left <| bot_mem_lowerBounds _
@[simp]
theorem isGreatest_top_iff [OrderTop α] : IsGreatest s ⊤ ↔ ⊤ ∈ s :=
and_iff_left <| top_mem_upperBounds _
/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x`
is not greater than or equal to `y`. This version only assumes `Preorder` structure and uses
`¬(y ≤ x)`. A version for linear orders is called `not_bddAbove_iff`. -/
theorem not_bddAbove_iff' : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, ¬y ≤ x := by
simp [BddAbove, upperBounds, Set.Nonempty]
/-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` such that `x`
is not less than or equal to `y`. This version only assumes `Preorder` structure and uses
`¬(x ≤ y)`. A version for linear orders is called `not_bddBelow_iff`. -/
theorem not_bddBelow_iff' : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, ¬x ≤ y :=
@not_bddAbove_iff' αᵒᵈ _ _
/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` that is greater
than `x`. A version for preorders is called `not_bddAbove_iff'`. -/
theorem not_bddAbove_iff {α : Type*} [LinearOrder α] {s : Set α} :
¬BddAbove s ↔ ∀ x, ∃ y ∈ s, x < y := by
simp only [not_bddAbove_iff', not_le]
/-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` that is less
than `x`. A version for preorders is called `not_bddBelow_iff'`. -/
theorem not_bddBelow_iff {α : Type*} [LinearOrder α] {s : Set α} :
¬BddBelow s ↔ ∀ x, ∃ y ∈ s, y < x :=
@not_bddAbove_iff αᵒᵈ _ _
@[simp] lemma bddBelow_preimage_ofDual {s : Set α} : BddBelow (ofDual ⁻¹' s) ↔ BddAbove s := Iff.rfl
@[simp] lemma bddAbove_preimage_ofDual {s : Set α} : BddAbove (ofDual ⁻¹' s) ↔ BddBelow s := Iff.rfl
@[simp] lemma bddBelow_preimage_toDual {s : Set αᵒᵈ} :
BddBelow (toDual ⁻¹' s) ↔ BddAbove s := Iff.rfl
@[simp] lemma bddAbove_preimage_toDual {s : Set αᵒᵈ} :
BddAbove (toDual ⁻¹' s) ↔ BddBelow s := Iff.rfl
theorem BddAbove.dual (h : BddAbove s) : BddBelow (ofDual ⁻¹' s) :=
h
theorem BddBelow.dual (h : BddBelow s) : BddAbove (ofDual ⁻¹' s) :=
h
theorem IsLeast.dual (h : IsLeast s a) : IsGreatest (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsGreatest.dual (h : IsGreatest s a) : IsLeast (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsLUB.dual (h : IsLUB s a) : IsGLB (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsGLB.dual (h : IsGLB s a) : IsLUB (ofDual ⁻¹' s) (toDual a) :=
h
/-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/
abbrev IsLeast.orderBot (h : IsLeast s a) :
OrderBot s where
bot := ⟨a, h.1⟩
bot_le := Subtype.forall.2 h.2
/-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/
abbrev IsGreatest.orderTop (h : IsGreatest s a) :
OrderTop s where
top := ⟨a, h.1⟩
le_top := Subtype.forall.2 h.2
/-!
### Monotonicity
-/
theorem upperBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : upperBounds t ⊆ upperBounds s :=
fun _ hb _ h => hb <| hst h
theorem lowerBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : lowerBounds t ⊆ lowerBounds s :=
fun _ hb _ h => hb <| hst h
theorem upperBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds s → b ∈ upperBounds s :=
fun ha _ h => le_trans (ha h) hab
theorem lowerBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds s → a ∈ lowerBounds s :=
fun hb _ h => le_trans hab (hb h)
theorem upperBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :
a ∈ upperBounds t → b ∈ upperBounds s := fun ha =>
upperBounds_mono_set hst <| upperBounds_mono_mem hab ha
theorem lowerBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :
b ∈ lowerBounds t → a ∈ lowerBounds s := fun hb =>
lowerBounds_mono_set hst <| lowerBounds_mono_mem hab hb
/-- If `s ⊆ t` and `t` is bounded above, then so is `s`. -/
theorem BddAbove.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddAbove t → BddAbove s :=
Nonempty.mono <| upperBounds_mono_set h
/-- If `s ⊆ t` and `t` is bounded below, then so is `s`. -/
theorem BddBelow.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddBelow t → BddBelow s :=
Nonempty.mono <| lowerBounds_mono_set h
/-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any
set `t`, `s ⊆ t ⊆ p`. -/
theorem IsLUB.of_subset_of_superset {s t p : Set α} (hs : IsLUB s a) (hp : IsLUB p a) (hst : s ⊆ t)
(htp : t ⊆ p) : IsLUB t a :=
⟨upperBounds_mono_set htp hp.1, lowerBounds_mono_set (upperBounds_mono_set hst) hs.2⟩
/-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any
set `t`, `s ⊆ t ⊆ p`. -/
theorem IsGLB.of_subset_of_superset {s t p : Set α} (hs : IsGLB s a) (hp : IsGLB p a) (hst : s ⊆ t)
(htp : t ⊆ p) : IsGLB t a :=
hs.dual.of_subset_of_superset hp hst htp
theorem IsLeast.mono (ha : IsLeast s a) (hb : IsLeast t b) (hst : s ⊆ t) : b ≤ a :=
hb.2 (hst ha.1)
theorem IsGreatest.mono (ha : IsGreatest s a) (hb : IsGreatest t b) (hst : s ⊆ t) : a ≤ b :=
hb.2 (hst ha.1)
theorem IsLUB.mono (ha : IsLUB s a) (hb : IsLUB t b) (hst : s ⊆ t) : a ≤ b :=
IsLeast.mono hb ha <| upperBounds_mono_set hst
theorem IsGLB.mono (ha : IsGLB s a) (hb : IsGLB t b) (hst : s ⊆ t) : b ≤ a :=
IsGreatest.mono hb ha <| lowerBounds_mono_set hst
theorem subset_lowerBounds_upperBounds (s : Set α) : s ⊆ lowerBounds (upperBounds s) :=
fun _ hx _ hy => hy hx
theorem subset_upperBounds_lowerBounds (s : Set α) : s ⊆ upperBounds (lowerBounds s) :=
fun _ hx _ hy => hy hx
theorem Set.Nonempty.bddAbove_lowerBounds (hs : s.Nonempty) : BddAbove (lowerBounds s) :=
hs.mono (subset_upperBounds_lowerBounds s)
theorem Set.Nonempty.bddBelow_upperBounds (hs : s.Nonempty) : BddBelow (upperBounds s) :=
hs.mono (subset_lowerBounds_upperBounds s)
/-!
### Conversions
-/
theorem IsLeast.isGLB (h : IsLeast s a) : IsGLB s a :=
⟨h.2, fun _ hb => hb h.1⟩
theorem IsGreatest.isLUB (h : IsGreatest s a) : IsLUB s a :=
⟨h.2, fun _ hb => hb h.1⟩
theorem IsLUB.upperBounds_eq (h : IsLUB s a) : upperBounds s = Ici a :=
Set.ext fun _ => ⟨fun hb => h.2 hb, fun hb => upperBounds_mono_mem hb h.1⟩
theorem IsGLB.lowerBounds_eq (h : IsGLB s a) : lowerBounds s = Iic a :=
h.dual.upperBounds_eq
theorem IsLeast.lowerBounds_eq (h : IsLeast s a) : lowerBounds s = Iic a :=
h.isGLB.lowerBounds_eq
theorem IsGreatest.upperBounds_eq (h : IsGreatest s a) : upperBounds s = Ici a :=
h.isLUB.upperBounds_eq
theorem IsGreatest.lt_iff (h : IsGreatest s a) : a < b ↔ ∀ x ∈ s, x < b :=
⟨fun hlt _x hx => (h.2 hx).trans_lt hlt, fun h' => h' _ h.1⟩
theorem IsLeast.lt_iff (h : IsLeast s a) : b < a ↔ ∀ x ∈ s, b < x :=
h.dual.lt_iff
theorem isLUB_le_iff (h : IsLUB s a) : a ≤ b ↔ b ∈ upperBounds s := by
rw [h.upperBounds_eq]
rfl
theorem le_isGLB_iff (h : IsGLB s a) : b ≤ a ↔ b ∈ lowerBounds s := by
rw [h.lowerBounds_eq]
rfl
theorem isLUB_iff_le_iff : IsLUB s a ↔ ∀ b, a ≤ b ↔ b ∈ upperBounds s :=
⟨fun h _ => isLUB_le_iff h, fun H => ⟨(H _).1 le_rfl, fun b hb => (H b).2 hb⟩⟩
theorem isGLB_iff_le_iff : IsGLB s a ↔ ∀ b, b ≤ a ↔ b ∈ lowerBounds s :=
@isLUB_iff_le_iff αᵒᵈ _ _ _
/-- If `s` has a least upper bound, then it is bounded above. -/
theorem IsLUB.bddAbove (h : IsLUB s a) : BddAbove s :=
⟨a, h.1⟩
/-- If `s` has a greatest lower bound, then it is bounded below. -/
theorem IsGLB.bddBelow (h : IsGLB s a) : BddBelow s :=
⟨a, h.1⟩
/-- If `s` has a greatest element, then it is bounded above. -/
theorem IsGreatest.bddAbove (h : IsGreatest s a) : BddAbove s :=
⟨a, h.2⟩
/-- If `s` has a least element, then it is bounded below. -/
theorem IsLeast.bddBelow (h : IsLeast s a) : BddBelow s :=
⟨a, h.2⟩
theorem IsLeast.nonempty (h : IsLeast s a) : s.Nonempty :=
⟨a, h.1⟩
theorem IsGreatest.nonempty (h : IsGreatest s a) : s.Nonempty :=
⟨a, h.1⟩
/-!
### Union and intersection
-/
@[simp]
theorem upperBounds_union : upperBounds (s ∪ t) = upperBounds s ∩ upperBounds t :=
Subset.antisymm (fun _ hb => ⟨fun _ hx => hb (Or.inl hx), fun _ hx => hb (Or.inr hx)⟩)
fun _ hb _ hx => hx.elim (fun hs => hb.1 hs) fun ht => hb.2 ht
@[simp]
theorem lowerBounds_union : lowerBounds (s ∪ t) = lowerBounds s ∩ lowerBounds t :=
@upperBounds_union αᵒᵈ _ s t
theorem union_upperBounds_subset_upperBounds_inter :
upperBounds s ∪ upperBounds t ⊆ upperBounds (s ∩ t) :=
union_subset (upperBounds_mono_set inter_subset_left)
(upperBounds_mono_set inter_subset_right)
theorem union_lowerBounds_subset_lowerBounds_inter :
lowerBounds s ∪ lowerBounds t ⊆ lowerBounds (s ∩ t) :=
@union_upperBounds_subset_upperBounds_inter αᵒᵈ _ s t
theorem isLeast_union_iff {a : α} {s t : Set α} :
IsLeast (s ∪ t) a ↔ IsLeast s a ∧ a ∈ lowerBounds t ∨ a ∈ lowerBounds s ∧ IsLeast t a := by
simp [IsLeast, lowerBounds_union, or_and_right, and_comm (a := a ∈ t), and_assoc]
theorem isGreatest_union_iff :
IsGreatest (s ∪ t) a ↔
IsGreatest s a ∧ a ∈ upperBounds t ∨ a ∈ upperBounds s ∧ IsGreatest t a :=
@isLeast_union_iff αᵒᵈ _ a s t
/-- If `s` is bounded, then so is `s ∩ t` -/
theorem BddAbove.inter_of_left (h : BddAbove s) : BddAbove (s ∩ t) :=
h.mono inter_subset_left
/-- If `t` is bounded, then so is `s ∩ t` -/
theorem BddAbove.inter_of_right (h : BddAbove t) : BddAbove (s ∩ t) :=
h.mono inter_subset_right
/-- If `s` is bounded, then so is `s ∩ t` -/
theorem BddBelow.inter_of_left (h : BddBelow s) : BddBelow (s ∩ t) :=
h.mono inter_subset_left
/-- If `t` is bounded, then so is `s ∩ t` -/
theorem BddBelow.inter_of_right (h : BddBelow t) : BddBelow (s ∩ t) :=
h.mono inter_subset_right
/-- In a directed order, the union of bounded above sets is bounded above. -/
theorem BddAbove.union [IsDirected α (· ≤ ·)] {s t : Set α} :
BddAbove s → BddAbove t → BddAbove (s ∪ t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
obtain ⟨c, hca, hcb⟩ := exists_ge_ge a b
rw [BddAbove, upperBounds_union]
exact ⟨c, upperBounds_mono_mem hca ha, upperBounds_mono_mem hcb hb⟩
/-- In a directed order, the union of two sets is bounded above if and only if both sets are. -/
theorem bddAbove_union [IsDirected α (· ≤ ·)] {s t : Set α} :
BddAbove (s ∪ t) ↔ BddAbove s ∧ BddAbove t :=
⟨fun h => ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h =>
h.1.union h.2⟩
/-- In a codirected order, the union of bounded below sets is bounded below. -/
theorem BddBelow.union [IsDirected α (· ≥ ·)] {s t : Set α} :
BddBelow s → BddBelow t → BddBelow (s ∪ t) :=
@BddAbove.union αᵒᵈ _ _ _ _
/-- In a codirected order, the union of two sets is bounded below if and only if both sets are. -/
theorem bddBelow_union [IsDirected α (· ≥ ·)] {s t : Set α} :
BddBelow (s ∪ t) ↔ BddBelow s ∧ BddBelow t :=
@bddAbove_union αᵒᵈ _ _ _ _
/-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`,
then `a ⊔ b` is the least upper bound of `s ∪ t`. -/
theorem IsLUB.union [SemilatticeSup γ] {a b : γ} {s t : Set γ} (hs : IsLUB s a) (ht : IsLUB t b) :
IsLUB (s ∪ t) (a ⊔ b) :=
⟨fun _ h =>
h.casesOn (fun h => le_sup_of_le_left <| hs.left h) fun h => le_sup_of_le_right <| ht.left h,
fun _ hc =>
sup_le (hs.right fun _ hd => hc <| Or.inl hd) (ht.right fun _ hd => hc <| Or.inr hd)⟩
/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,
then `a ⊓ b` is the greatest lower bound of `s ∪ t`. -/
theorem IsGLB.union [SemilatticeInf γ] {a₁ a₂ : γ} {s t : Set γ} (hs : IsGLB s a₁)
(ht : IsGLB t a₂) : IsGLB (s ∪ t) (a₁ ⊓ a₂) :=
hs.dual.union ht
/-- If `a` is the least element of `s` and `b` is the least element of `t`,
then `min a b` is the least element of `s ∪ t`. -/
theorem IsLeast.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsLeast s a)
(hb : IsLeast t b) : IsLeast (s ∪ t) (min a b) :=
⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isGLB.union hb.isGLB).1⟩
/-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`,
then `max a b` is the greatest element of `s ∪ t`. -/
theorem IsGreatest.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsGreatest s a)
(hb : IsGreatest t b) : IsGreatest (s ∪ t) (max a b) :=
⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isLUB.union hb.isLUB).1⟩
theorem IsLUB.inter_Ici_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsLUB s a) (hb : b ∈ s) :
IsLUB (s ∩ Ici b) a :=
⟨fun _ hx => ha.1 hx.1, fun c hc =>
have hbc : b ≤ c := hc ⟨hb, le_rfl⟩
ha.2 fun x hx => ((le_total x b).elim fun hxb => hxb.trans hbc) fun hbx => hc ⟨hx, hbx⟩⟩
theorem IsGLB.inter_Iic_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsGLB s a) (hb : b ∈ s) :
IsGLB (s ∩ Iic b) a :=
ha.dual.inter_Ici_of_mem hb
theorem bddAbove_iff_exists_ge [SemilatticeSup γ] {s : Set γ} (x₀ : γ) :
BddAbove s ↔ ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := by
rw [bddAbove_def, exists_ge_and_iff_exists]
exact Monotone.ball fun x _ => monotone_le
theorem bddBelow_iff_exists_le [SemilatticeInf γ] {s : Set γ} (x₀ : γ) :
BddBelow s ↔ ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y :=
bddAbove_iff_exists_ge (toDual x₀)
theorem BddAbove.exists_ge [SemilatticeSup γ] {s : Set γ} (hs : BddAbove s) (x₀ : γ) :
∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x :=
(bddAbove_iff_exists_ge x₀).mp hs
theorem BddBelow.exists_le [SemilatticeInf γ] {s : Set γ} (hs : BddBelow s) (x₀ : γ) :
∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y :=
(bddBelow_iff_exists_le x₀).mp hs
/-!
### Specific sets
#### Unbounded intervals
-/
theorem isLeast_Ici : IsLeast (Ici a) a :=
⟨left_mem_Ici, fun _ => id⟩
theorem isGreatest_Iic : IsGreatest (Iic a) a :=
⟨right_mem_Iic, fun _ => id⟩
theorem isLUB_Iic : IsLUB (Iic a) a :=
isGreatest_Iic.isLUB
theorem isGLB_Ici : IsGLB (Ici a) a :=
isLeast_Ici.isGLB
theorem upperBounds_Iic : upperBounds (Iic a) = Ici a :=
isLUB_Iic.upperBounds_eq
theorem lowerBounds_Ici : lowerBounds (Ici a) = Iic a :=
isGLB_Ici.lowerBounds_eq
theorem bddAbove_Iic : BddAbove (Iic a) :=
isLUB_Iic.bddAbove
theorem bddBelow_Ici : BddBelow (Ici a) :=
isGLB_Ici.bddBelow
theorem bddAbove_Iio : BddAbove (Iio a) :=
⟨a, fun _ hx => le_of_lt hx⟩
theorem bddBelow_Ioi : BddBelow (Ioi a) :=
⟨a, fun _ hx => le_of_lt hx⟩
theorem lub_Iio_le (a : α) (hb : IsLUB (Iio a) b) : b ≤ a :=
(isLUB_le_iff hb).mpr fun _ hk => le_of_lt hk
theorem le_glb_Ioi (a : α) (hb : IsGLB (Ioi a) b) : a ≤ b :=
@lub_Iio_le αᵒᵈ _ _ a hb
theorem lub_Iio_eq_self_or_Iio_eq_Iic [PartialOrder γ] {j : γ} (i : γ) (hj : IsLUB (Iio i) j) :
j = i ∨ Iio i = Iic j := by
cases' eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i hj_lt_i
· exact Or.inl hj_eq_i
· right
exact Set.ext fun k => ⟨fun hk_lt => hj.1 hk_lt, fun hk_le_j => lt_of_le_of_lt hk_le_j hj_lt_i⟩
theorem glb_Ioi_eq_self_or_Ioi_eq_Ici [PartialOrder γ] {j : γ} (i : γ) (hj : IsGLB (Ioi i) j) :
j = i ∨ Ioi i = Ici j :=
@lub_Iio_eq_self_or_Iio_eq_Iic γᵒᵈ _ j i hj
section
variable [LinearOrder γ]
theorem exists_lub_Iio (i : γ) : ∃ j, IsLUB (Iio i) j := by
by_cases h_exists_lt : ∃ j, j ∈ upperBounds (Iio i) ∧ j < i
· obtain ⟨j, hj_ub, hj_lt_i⟩ := h_exists_lt
exact ⟨j, hj_ub, fun k hk_ub => hk_ub hj_lt_i⟩
· refine ⟨i, fun j hj => le_of_lt hj, ?_⟩
rw [mem_lowerBounds]
by_contra h
refine h_exists_lt ?_
push_neg at h
exact h
theorem exists_glb_Ioi (i : γ) : ∃ j, IsGLB (Ioi i) j :=
@exists_lub_Iio γᵒᵈ _ i
variable [DenselyOrdered γ]
theorem isLUB_Iio {a : γ} : IsLUB (Iio a) a :=
⟨fun _ hx => le_of_lt hx, fun _ hy => le_of_forall_ge_of_dense hy⟩
theorem isGLB_Ioi {a : γ} : IsGLB (Ioi a) a :=
@isLUB_Iio γᵒᵈ _ _ a
theorem upperBounds_Iio {a : γ} : upperBounds (Iio a) = Ici a :=
isLUB_Iio.upperBounds_eq
theorem lowerBounds_Ioi {a : γ} : lowerBounds (Ioi a) = Iic a :=
isGLB_Ioi.lowerBounds_eq
end
/-!
#### Singleton
-/
@[simp] theorem isGreatest_singleton : IsGreatest {a} a :=
⟨mem_singleton a, fun _ hx => le_of_eq <| eq_of_mem_singleton hx⟩
@[simp] theorem isLeast_singleton : IsLeast {a} a :=
@isGreatest_singleton αᵒᵈ _ a
@[simp] theorem isLUB_singleton : IsLUB {a} a :=
isGreatest_singleton.isLUB
@[simp] theorem isGLB_singleton : IsGLB {a} a :=
isLeast_singleton.isGLB
@[simp] lemma bddAbove_singleton : BddAbove ({a} : Set α) := isLUB_singleton.bddAbove
@[simp] lemma bddBelow_singleton : BddBelow ({a} : Set α) := isGLB_singleton.bddBelow
@[simp]
theorem upperBounds_singleton : upperBounds {a} = Ici a :=
isLUB_singleton.upperBounds_eq
@[simp]
theorem lowerBounds_singleton : lowerBounds {a} = Iic a :=
isGLB_singleton.lowerBounds_eq
/-!
#### Bounded intervals
-/
theorem bddAbove_Icc : BddAbove (Icc a b) :=
⟨b, fun _ => And.right⟩
theorem bddBelow_Icc : BddBelow (Icc a b) :=
⟨a, fun _ => And.left⟩
theorem bddAbove_Ico : BddAbove (Ico a b) :=
bddAbove_Icc.mono Ico_subset_Icc_self
theorem bddBelow_Ico : BddBelow (Ico a b) :=
bddBelow_Icc.mono Ico_subset_Icc_self
theorem bddAbove_Ioc : BddAbove (Ioc a b) :=
bddAbove_Icc.mono Ioc_subset_Icc_self
theorem bddBelow_Ioc : BddBelow (Ioc a b) :=
bddBelow_Icc.mono Ioc_subset_Icc_self
theorem bddAbove_Ioo : BddAbove (Ioo a b) :=
bddAbove_Icc.mono Ioo_subset_Icc_self
theorem bddBelow_Ioo : BddBelow (Ioo a b) :=
bddBelow_Icc.mono Ioo_subset_Icc_self
theorem isGreatest_Icc (h : a ≤ b) : IsGreatest (Icc a b) b :=
⟨right_mem_Icc.2 h, fun _ => And.right⟩
theorem isLUB_Icc (h : a ≤ b) : IsLUB (Icc a b) b :=
(isGreatest_Icc h).isLUB
theorem upperBounds_Icc (h : a ≤ b) : upperBounds (Icc a b) = Ici b :=
(isLUB_Icc h).upperBounds_eq
theorem isLeast_Icc (h : a ≤ b) : IsLeast (Icc a b) a :=
⟨left_mem_Icc.2 h, fun _ => And.left⟩
theorem isGLB_Icc (h : a ≤ b) : IsGLB (Icc a b) a :=
(isLeast_Icc h).isGLB
theorem lowerBounds_Icc (h : a ≤ b) : lowerBounds (Icc a b) = Iic a :=
(isGLB_Icc h).lowerBounds_eq
theorem isGreatest_Ioc (h : a < b) : IsGreatest (Ioc a b) b :=
⟨right_mem_Ioc.2 h, fun _ => And.right⟩
theorem isLUB_Ioc (h : a < b) : IsLUB (Ioc a b) b :=
(isGreatest_Ioc h).isLUB
theorem upperBounds_Ioc (h : a < b) : upperBounds (Ioc a b) = Ici b :=
(isLUB_Ioc h).upperBounds_eq
theorem isLeast_Ico (h : a < b) : IsLeast (Ico a b) a :=
⟨left_mem_Ico.2 h, fun _ => And.left⟩
theorem isGLB_Ico (h : a < b) : IsGLB (Ico a b) a :=
(isLeast_Ico h).isGLB
theorem lowerBounds_Ico (h : a < b) : lowerBounds (Ico a b) = Iic a :=
(isGLB_Ico h).lowerBounds_eq
section
variable [SemilatticeSup γ] [DenselyOrdered γ]
theorem isGLB_Ioo {a b : γ} (h : a < b) : IsGLB (Ioo a b) a :=
⟨fun x hx => hx.1.le, fun x hx => by
cases' eq_or_lt_of_le (le_sup_right : a ≤ x ⊔ a) with h₁ h₂
· exact h₁.symm ▸ le_sup_left
obtain ⟨y, lty, ylt⟩ := exists_between h₂
apply (not_lt_of_le (sup_le (hx ⟨lty, ylt.trans_le (sup_le _ h.le)⟩) lty.le) ylt).elim
obtain ⟨u, au, ub⟩ := exists_between h
apply (hx ⟨au, ub⟩).trans ub.le⟩
theorem lowerBounds_Ioo {a b : γ} (hab : a < b) : lowerBounds (Ioo a b) = Iic a :=
(isGLB_Ioo hab).lowerBounds_eq
theorem isGLB_Ioc {a b : γ} (hab : a < b) : IsGLB (Ioc a b) a :=
(isGLB_Ioo hab).of_subset_of_superset (isGLB_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self
theorem lowerBounds_Ioc {a b : γ} (hab : a < b) : lowerBounds (Ioc a b) = Iic a :=
(isGLB_Ioc hab).lowerBounds_eq
end
section
variable [SemilatticeInf γ] [DenselyOrdered γ]
theorem isLUB_Ioo {a b : γ} (hab : a < b) : IsLUB (Ioo a b) b := by
simpa only [dual_Ioo] using isGLB_Ioo hab.dual
theorem upperBounds_Ioo {a b : γ} (hab : a < b) : upperBounds (Ioo a b) = Ici b :=
(isLUB_Ioo hab).upperBounds_eq
theorem isLUB_Ico {a b : γ} (hab : a < b) : IsLUB (Ico a b) b := by
simpa only [dual_Ioc] using isGLB_Ioc hab.dual
theorem upperBounds_Ico {a b : γ} (hab : a < b) : upperBounds (Ico a b) = Ici b :=
(isLUB_Ico hab).upperBounds_eq
end
theorem bddBelow_iff_subset_Ici : BddBelow s ↔ ∃ a, s ⊆ Ici a :=
Iff.rfl
theorem bddAbove_iff_subset_Iic : BddAbove s ↔ ∃ a, s ⊆ Iic a :=
Iff.rfl
theorem bddBelow_bddAbove_iff_subset_Icc : BddBelow s ∧ BddAbove s ↔ ∃ a b, s ⊆ Icc a b := by
simp [Ici_inter_Iic.symm, subset_inter_iff, bddBelow_iff_subset_Ici,
bddAbove_iff_subset_Iic, exists_and_left, exists_and_right]
/-!
#### Univ
-/
@[simp] theorem isGreatest_univ_iff : IsGreatest univ a ↔ IsTop a := by
simp [IsGreatest, mem_upperBounds, IsTop]
theorem isGreatest_univ [OrderTop α] : IsGreatest (univ : Set α) ⊤ :=
isGreatest_univ_iff.2 isTop_top
@[simp]
theorem OrderTop.upperBounds_univ [PartialOrder γ] [OrderTop γ] :
upperBounds (univ : Set γ) = {⊤} := by rw [isGreatest_univ.upperBounds_eq, Ici_top]
theorem isLUB_univ [OrderTop α] : IsLUB (univ : Set α) ⊤ :=
isGreatest_univ.isLUB
@[simp]
theorem OrderBot.lowerBounds_univ [PartialOrder γ] [OrderBot γ] :
lowerBounds (univ : Set γ) = {⊥} :=
@OrderTop.upperBounds_univ γᵒᵈ _ _
@[simp] theorem isLeast_univ_iff : IsLeast univ a ↔ IsBot a :=
@isGreatest_univ_iff αᵒᵈ _ _
theorem isLeast_univ [OrderBot α] : IsLeast (univ : Set α) ⊥ :=
@isGreatest_univ αᵒᵈ _ _
theorem isGLB_univ [OrderBot α] : IsGLB (univ : Set α) ⊥ :=
isLeast_univ.isGLB
@[simp]
theorem NoMaxOrder.upperBounds_univ [NoMaxOrder α] : upperBounds (univ : Set α) = ∅ :=
eq_empty_of_subset_empty fun b hb =>
let ⟨_, hx⟩ := exists_gt b
not_le_of_lt hx (hb trivial)
@[simp]
theorem NoMinOrder.lowerBounds_univ [NoMinOrder α] : lowerBounds (univ : Set α) = ∅ :=
@NoMaxOrder.upperBounds_univ αᵒᵈ _ _
@[simp]
theorem not_bddAbove_univ [NoMaxOrder α] : ¬BddAbove (univ : Set α) := by simp [BddAbove]
@[simp]
theorem not_bddBelow_univ [NoMinOrder α] : ¬BddBelow (univ : Set α) :=
@not_bddAbove_univ αᵒᵈ _ _
/-!
#### Empty set
-/
@[simp]
theorem upperBounds_empty : upperBounds (∅ : Set α) = univ := by
simp only [upperBounds, eq_univ_iff_forall, mem_setOf_eq, forall_mem_empty, forall_true_iff]
@[simp]
theorem lowerBounds_empty : lowerBounds (∅ : Set α) = univ :=
@upperBounds_empty αᵒᵈ _
@[simp]
theorem bddAbove_empty [Nonempty α] : BddAbove (∅ : Set α) := by
simp only [BddAbove, upperBounds_empty, univ_nonempty]
@[simp]
theorem bddBelow_empty [Nonempty α] : BddBelow (∅ : Set α) := by
simp only [BddBelow, lowerBounds_empty, univ_nonempty]
@[simp] theorem isGLB_empty_iff : IsGLB ∅ a ↔ IsTop a := by
simp [IsGLB]
@[simp] theorem isLUB_empty_iff : IsLUB ∅ a ↔ IsBot a :=
@isGLB_empty_iff αᵒᵈ _ _
theorem isGLB_empty [OrderTop α] : IsGLB ∅ (⊤ : α) :=
isGLB_empty_iff.2 isTop_top
theorem isLUB_empty [OrderBot α] : IsLUB ∅ (⊥ : α) :=
@isGLB_empty αᵒᵈ _ _
theorem IsLUB.nonempty [NoMinOrder α] (hs : IsLUB s a) : s.Nonempty :=
let ⟨a', ha'⟩ := exists_lt a
nonempty_iff_ne_empty.2 fun h =>
not_le_of_lt ha' <| hs.right <| by rw [h, upperBounds_empty]; exact mem_univ _
theorem IsGLB.nonempty [NoMaxOrder α] (hs : IsGLB s a) : s.Nonempty :=
hs.dual.nonempty
theorem nonempty_of_not_bddAbove [ha : Nonempty α] (h : ¬BddAbove s) : s.Nonempty :=
(Nonempty.elim ha) fun x => (not_bddAbove_iff'.1 h x).imp fun _ ha => ha.1
theorem nonempty_of_not_bddBelow [Nonempty α] (h : ¬BddBelow s) : s.Nonempty :=
@nonempty_of_not_bddAbove αᵒᵈ _ _ _ h
/-!
#### insert
-/
/-- Adding a point to a set preserves its boundedness above. -/
@[simp]
theorem bddAbove_insert [IsDirected α (· ≤ ·)] {s : Set α} {a : α} :
BddAbove (insert a s) ↔ BddAbove s := by
simp only [insert_eq, bddAbove_union, bddAbove_singleton, true_and_iff]
protected theorem BddAbove.insert [IsDirected α (· ≤ ·)] {s : Set α} (a : α) :
BddAbove s → BddAbove (insert a s) :=
bddAbove_insert.2
/-- Adding a point to a set preserves its boundedness below. -/
@[simp]
theorem bddBelow_insert [IsDirected α (· ≥ ·)] {s : Set α} {a : α} :
BddBelow (insert a s) ↔ BddBelow s := by
simp only [insert_eq, bddBelow_union, bddBelow_singleton, true_and_iff]
protected theorem BddBelow.insert [IsDirected α (· ≥ ·)] {s : Set α} (a : α) :
BddBelow s → BddBelow (insert a s) :=
bddBelow_insert.2
protected theorem IsLUB.insert [SemilatticeSup γ] (a) {b} {s : Set γ} (hs : IsLUB s b) :
IsLUB (insert a s) (a ⊔ b) := by
rw [insert_eq]
exact isLUB_singleton.union hs
protected theorem IsGLB.insert [SemilatticeInf γ] (a) {b} {s : Set γ} (hs : IsGLB s b) :
IsGLB (insert a s) (a ⊓ b) := by
rw [insert_eq]
exact isGLB_singleton.union hs
protected theorem IsGreatest.insert [LinearOrder γ] (a) {b} {s : Set γ} (hs : IsGreatest s b) :
IsGreatest (insert a s) (max a b) := by
rw [insert_eq]
exact isGreatest_singleton.union hs
protected theorem IsLeast.insert [LinearOrder γ] (a) {b} {s : Set γ} (hs : IsLeast s b) :
IsLeast (insert a s) (min a b) := by
rw [insert_eq]
exact isLeast_singleton.union hs
@[simp]
theorem upperBounds_insert (a : α) (s : Set α) :
upperBounds (insert a s) = Ici a ∩ upperBounds s := by
rw [insert_eq, upperBounds_union, upperBounds_singleton]
@[simp]
theorem lowerBounds_insert (a : α) (s : Set α) :
lowerBounds (insert a s) = Iic a ∩ lowerBounds s := by
rw [insert_eq, lowerBounds_union, lowerBounds_singleton]
/-- When there is a global maximum, every set is bounded above. -/
@[simp]
protected theorem OrderTop.bddAbove [OrderTop α] (s : Set α) : BddAbove s :=
⟨⊤, fun a _ => OrderTop.le_top a⟩
/-- When there is a global minimum, every set is bounded below. -/
@[simp]
protected theorem OrderBot.bddBelow [OrderBot α] (s : Set α) : BddBelow s :=
⟨⊥, fun a _ => OrderBot.bot_le a⟩
/-- Sets are automatically bounded or cobounded in complete lattices. To use the same statements
in complete and conditionally complete lattices but let automation fill automatically the
boundedness proofs in complete lattices, we use the tactic `bddDefault` in the statements,
in the form `(hA : BddAbove A := by bddDefault)`. -/
macro "bddDefault" : tactic =>
`(tactic| first
| apply OrderTop.bddAbove
| apply OrderBot.bddBelow)
/-!
#### Pair
-/
theorem isLUB_pair [SemilatticeSup γ] {a b : γ} : IsLUB {a, b} (a ⊔ b) :=
isLUB_singleton.insert _
theorem isGLB_pair [SemilatticeInf γ] {a b : γ} : IsGLB {a, b} (a ⊓ b) :=
isGLB_singleton.insert _
theorem isLeast_pair [LinearOrder γ] {a b : γ} : IsLeast {a, b} (min a b) :=
isLeast_singleton.insert _
theorem isGreatest_pair [LinearOrder γ] {a b : γ} : IsGreatest {a, b} (max a b) :=
isGreatest_singleton.insert _
/-!
#### Lower/upper bounds
-/
@[simp]
theorem isLUB_lowerBounds : IsLUB (lowerBounds s) a ↔ IsGLB s a :=
⟨fun H => ⟨fun _ hx => H.2 <| subset_upperBounds_lowerBounds s hx, H.1⟩, IsGreatest.isLUB⟩
@[simp]
theorem isGLB_upperBounds : IsGLB (upperBounds s) a ↔ IsLUB s a :=
@isLUB_lowerBounds αᵒᵈ _ _ _
end
/-!
### (In)equalities with the least upper bound and the greatest lower bound
-/
section Preorder
variable [Preorder α] {s : Set α} {a b : α}
theorem lowerBounds_le_upperBounds (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) :
s.Nonempty → a ≤ b
| ⟨_, hc⟩ => le_trans (ha hc) (hb hc)
theorem isGLB_le_isLUB (ha : IsGLB s a) (hb : IsLUB s b) (hs : s.Nonempty) : a ≤ b :=
lowerBounds_le_upperBounds ha.1 hb.1 hs
theorem isLUB_lt_iff (ha : IsLUB s a) : a < b ↔ ∃ c ∈ upperBounds s, c < b :=
⟨fun hb => ⟨a, ha.1, hb⟩, fun ⟨_, hcs, hcb⟩ => lt_of_le_of_lt (ha.2 hcs) hcb⟩
theorem lt_isGLB_iff (ha : IsGLB s a) : b < a ↔ ∃ c ∈ lowerBounds s, b < c :=
isLUB_lt_iff ha.dual
theorem le_of_isLUB_le_isGLB {x y} (ha : IsGLB s a) (hb : IsLUB s b) (hab : b ≤ a) (hx : x ∈ s)
(hy : y ∈ s) : x ≤ y :=
calc
x ≤ b := hb.1 hx
_ ≤ a := hab
_ ≤ y := ha.1 hy
end Preorder
section PartialOrder
variable [PartialOrder α] {s : Set α} {a b : α}
theorem IsLeast.unique (Ha : IsLeast s a) (Hb : IsLeast s b) : a = b :=
le_antisymm (Ha.right Hb.left) (Hb.right Ha.left)
theorem IsLeast.isLeast_iff_eq (Ha : IsLeast s a) : IsLeast s b ↔ a = b :=
Iff.intro Ha.unique fun h => h ▸ Ha
theorem IsGreatest.unique (Ha : IsGreatest s a) (Hb : IsGreatest s b) : a = b :=
le_antisymm (Hb.right Ha.left) (Ha.right Hb.left)
theorem IsGreatest.isGreatest_iff_eq (Ha : IsGreatest s a) : IsGreatest s b ↔ a = b :=
Iff.intro Ha.unique fun h => h ▸ Ha
theorem IsLUB.unique (Ha : IsLUB s a) (Hb : IsLUB s b) : a = b :=
IsLeast.unique Ha Hb
theorem IsGLB.unique (Ha : IsGLB s a) (Hb : IsGLB s b) : a = b :=
IsGreatest.unique Ha Hb
theorem Set.subsingleton_of_isLUB_le_isGLB (Ha : IsGLB s a) (Hb : IsLUB s b) (hab : b ≤ a) :
s.Subsingleton := fun _ hx _ hy =>
le_antisymm (le_of_isLUB_le_isGLB Ha Hb hab hx hy) (le_of_isLUB_le_isGLB Ha Hb hab hy hx)
theorem isGLB_lt_isLUB_of_ne (Ha : IsGLB s a) (Hb : IsLUB s b) {x y} (Hx : x ∈ s) (Hy : y ∈ s)
(Hxy : x ≠ y) : a < b :=
lt_iff_le_not_le.2
⟨lowerBounds_le_upperBounds Ha.1 Hb.1 ⟨x, Hx⟩, fun hab =>
Hxy <| Set.subsingleton_of_isLUB_le_isGLB Ha Hb hab Hx Hy⟩
end PartialOrder
section LinearOrder
variable [LinearOrder α] {s : Set α} {a b : α}
theorem lt_isLUB_iff (h : IsLUB s a) : b < a ↔ ∃ c ∈ s, b < c := by
simp_rw [← not_le, isLUB_le_iff h, mem_upperBounds, not_forall, not_le, exists_prop]
theorem isGLB_lt_iff (h : IsGLB s a) : a < b ↔ ∃ c ∈ s, c < b :=
lt_isLUB_iff h.dual
theorem IsLUB.exists_between (h : IsLUB s a) (hb : b < a) : ∃ c ∈ s, b < c ∧ c ≤ a :=
let ⟨c, hcs, hbc⟩ := (lt_isLUB_iff h).1 hb
⟨c, hcs, hbc, h.1 hcs⟩
theorem IsLUB.exists_between' (h : IsLUB s a) (h' : a ∉ s) (hb : b < a) : ∃ c ∈ s, b < c ∧ c < a :=
let ⟨c, hcs, hbc, hca⟩ := h.exists_between hb
⟨c, hcs, hbc, hca.lt_of_ne fun hac => h' <| hac ▸ hcs⟩
theorem IsGLB.exists_between (h : IsGLB s a) (hb : a < b) : ∃ c ∈ s, a ≤ c ∧ c < b :=
let ⟨c, hcs, hbc⟩ := (isGLB_lt_iff h).1 hb
⟨c, hcs, h.1 hcs, hbc⟩
theorem IsGLB.exists_between' (h : IsGLB s a) (h' : a ∉ s) (hb : a < b) : ∃ c ∈ s, a < c ∧ c < b :=
let ⟨c, hcs, hac, hcb⟩ := h.exists_between hb
⟨c, hcs, hac.lt_of_ne fun hac => h' <| hac.symm ▸ hcs, hcb⟩
end LinearOrder
/-!
### Images of upper/lower bounds under monotone functions
-/
namespace MonotoneOn
variable [Preorder α] [Preorder β] {f : α → β} {s t : Set α} {a : α}
theorem mem_upperBounds_image (Hf : MonotoneOn f t) (Hst : s ⊆ t) (Has : a ∈ upperBounds s)
(Hat : a ∈ t) : f a ∈ upperBounds (f '' s) :=
forall_mem_image.2 fun _ H => Hf (Hst H) Hat (Has H)
theorem mem_upperBounds_image_self (Hf : MonotoneOn f t) :
a ∈ upperBounds t → a ∈ t → f a ∈ upperBounds (f '' t) :=
Hf.mem_upperBounds_image subset_rfl
theorem mem_lowerBounds_image (Hf : MonotoneOn f t) (Hst : s ⊆ t) (Has : a ∈ lowerBounds s)
(Hat : a ∈ t) : f a ∈ lowerBounds (f '' s) :=
forall_mem_image.2 fun _ H => Hf Hat (Hst H) (Has H)
theorem mem_lowerBounds_image_self (Hf : MonotoneOn f t) :
a ∈ lowerBounds t → a ∈ t → f a ∈ lowerBounds (f '' t) :=
Hf.mem_lowerBounds_image subset_rfl
theorem image_upperBounds_subset_upperBounds_image (Hf : MonotoneOn f t) (Hst : s ⊆ t) :
f '' (upperBounds s ∩ t) ⊆ upperBounds (f '' s) := by
rintro _ ⟨a, ha, rfl⟩
exact Hf.mem_upperBounds_image Hst ha.1 ha.2
theorem image_lowerBounds_subset_lowerBounds_image (Hf : MonotoneOn f t) (Hst : s ⊆ t) :
f '' (lowerBounds s ∩ t) ⊆ lowerBounds (f '' s) :=
Hf.dual.image_upperBounds_subset_upperBounds_image Hst
/-- The image under a monotone function on a set `t` of a subset which has an upper bound in `t`
is bounded above. -/
theorem map_bddAbove (Hf : MonotoneOn f t) (Hst : s ⊆ t) :
(upperBounds s ∩ t).Nonempty → BddAbove (f '' s) := fun ⟨C, hs, ht⟩ =>
⟨f C, Hf.mem_upperBounds_image Hst hs ht⟩
/-- The image under a monotone function on a set `t` of a subset which has a lower bound in `t`
is bounded below. -/
theorem map_bddBelow (Hf : MonotoneOn f t) (Hst : s ⊆ t) :
(lowerBounds s ∩ t).Nonempty → BddBelow (f '' s) := fun ⟨C, hs, ht⟩ =>
⟨f C, Hf.mem_lowerBounds_image Hst hs ht⟩
/-- A monotone map sends a least element of a set to a least element of its image. -/
theorem map_isLeast (Hf : MonotoneOn f t) (Ha : IsLeast t a) : IsLeast (f '' t) (f a) :=
⟨mem_image_of_mem _ Ha.1, Hf.mem_lowerBounds_image_self Ha.2 Ha.1⟩
/-- A monotone map sends a greatest element of a set to a greatest element of its image. -/
theorem map_isGreatest (Hf : MonotoneOn f t) (Ha : IsGreatest t a) : IsGreatest (f '' t) (f a) :=
⟨mem_image_of_mem _ Ha.1, Hf.mem_upperBounds_image_self Ha.2 Ha.1⟩
end MonotoneOn
namespace AntitoneOn
variable [Preorder α] [Preorder β] {f : α → β} {s t : Set α} {a : α}
theorem mem_upperBounds_image (Hf : AntitoneOn f t) (Hst : s ⊆ t) (Has : a ∈ lowerBounds s) :
a ∈ t → f a ∈ upperBounds (f '' s) :=
Hf.dual_right.mem_lowerBounds_image Hst Has
theorem mem_upperBounds_image_self (Hf : AntitoneOn f t) :
a ∈ lowerBounds t → a ∈ t → f a ∈ upperBounds (f '' t) :=
Hf.dual_right.mem_lowerBounds_image_self
theorem mem_lowerBounds_image (Hf : AntitoneOn f t) (Hst : s ⊆ t) :
a ∈ upperBounds s → a ∈ t → f a ∈ lowerBounds (f '' s) :=
Hf.dual_right.mem_upperBounds_image Hst
theorem mem_lowerBounds_image_self (Hf : AntitoneOn f t) :
a ∈ upperBounds t → a ∈ t → f a ∈ lowerBounds (f '' t) :=
Hf.dual_right.mem_upperBounds_image_self
theorem image_lowerBounds_subset_upperBounds_image (Hf : AntitoneOn f t) (Hst : s ⊆ t) :
f '' (lowerBounds s ∩ t) ⊆ upperBounds (f '' s) :=
Hf.dual_right.image_lowerBounds_subset_lowerBounds_image Hst
theorem image_upperBounds_subset_lowerBounds_image (Hf : AntitoneOn f t) (Hst : s ⊆ t) :
f '' (upperBounds s ∩ t) ⊆ lowerBounds (f '' s) :=
Hf.dual_right.image_upperBounds_subset_upperBounds_image Hst
/-- The image under an antitone function of a set which is bounded above is bounded below. -/
theorem map_bddAbove (Hf : AntitoneOn f t) (Hst : s ⊆ t) :
(upperBounds s ∩ t).Nonempty → BddBelow (f '' s) :=
Hf.dual_right.map_bddAbove Hst
/-- The image under an antitone function of a set which is bounded below is bounded above. -/
theorem map_bddBelow (Hf : AntitoneOn f t) (Hst : s ⊆ t) :
(lowerBounds s ∩ t).Nonempty → BddAbove (f '' s) :=
Hf.dual_right.map_bddBelow Hst
/-- An antitone map sends a greatest element of a set to a least element of its image. -/
theorem map_isGreatest (Hf : AntitoneOn f t) : IsGreatest t a → IsLeast (f '' t) (f a) :=
Hf.dual_right.map_isGreatest
/-- An antitone map sends a least element of a set to a greatest element of its image. -/
theorem map_isLeast (Hf : AntitoneOn f t) : IsLeast t a → IsGreatest (f '' t) (f a) :=
Hf.dual_right.map_isLeast
end AntitoneOn
namespace Monotone
variable [Preorder α] [Preorder β] {f : α → β} (Hf : Monotone f) {a : α} {s : Set α}
theorem mem_upperBounds_image (Ha : a ∈ upperBounds s) : f a ∈ upperBounds (f '' s) :=
forall_mem_image.2 fun _ H => Hf (Ha H)
theorem mem_lowerBounds_image (Ha : a ∈ lowerBounds s) : f a ∈ lowerBounds (f '' s) :=
forall_mem_image.2 fun _ H => Hf (Ha H)
theorem image_upperBounds_subset_upperBounds_image (Hf : Monotone f) :
f '' upperBounds s ⊆ upperBounds (f '' s) := by
rintro _ ⟨a, ha, rfl⟩
exact Hf.mem_upperBounds_image ha
theorem image_lowerBounds_subset_lowerBounds_image : f '' lowerBounds s ⊆ lowerBounds (f '' s) :=
Hf.dual.image_upperBounds_subset_upperBounds_image
/-- The image under a monotone function of a set which is bounded above is bounded above. See also
`BddAbove.image2`. -/
theorem map_bddAbove : BddAbove s → BddAbove (f '' s)
| ⟨C, hC⟩ => ⟨f C, Hf.mem_upperBounds_image hC⟩
/-- The image under a monotone function of a set which is bounded below is bounded below. See also
`BddBelow.image2`. -/
theorem map_bddBelow : BddBelow s → BddBelow (f '' s)
| ⟨C, hC⟩ => ⟨f C, Hf.mem_lowerBounds_image hC⟩
/-- A monotone map sends a least element of a set to a least element of its image. -/
theorem map_isLeast (Ha : IsLeast s a) : IsLeast (f '' s) (f a) :=
⟨mem_image_of_mem _ Ha.1, Hf.mem_lowerBounds_image Ha.2⟩
/-- A monotone map sends a greatest element of a set to a greatest element of its image. -/
theorem map_isGreatest (Ha : IsGreatest s a) : IsGreatest (f '' s) (f a) :=
⟨mem_image_of_mem _ Ha.1, Hf.mem_upperBounds_image Ha.2⟩
end Monotone
namespace Antitone
variable [Preorder α] [Preorder β] {f : α → β} (hf : Antitone f) {a : α} {s : Set α}
theorem mem_upperBounds_image : a ∈ lowerBounds s → f a ∈ upperBounds (f '' s) :=
hf.dual_right.mem_lowerBounds_image
theorem mem_lowerBounds_image : a ∈ upperBounds s → f a ∈ lowerBounds (f '' s) :=
hf.dual_right.mem_upperBounds_image
theorem image_lowerBounds_subset_upperBounds_image : f '' lowerBounds s ⊆ upperBounds (f '' s) :=
hf.dual_right.image_lowerBounds_subset_lowerBounds_image
theorem image_upperBounds_subset_lowerBounds_image : f '' upperBounds s ⊆ lowerBounds (f '' s) :=
hf.dual_right.image_upperBounds_subset_upperBounds_image
/-- The image under an antitone function of a set which is bounded above is bounded below. -/
theorem map_bddAbove : BddAbove s → BddBelow (f '' s) :=
hf.dual_right.map_bddAbove
/-- The image under an antitone function of a set which is bounded below is bounded above. -/
theorem map_bddBelow : BddBelow s → BddAbove (f '' s) :=
hf.dual_right.map_bddBelow
/-- An antitone map sends a greatest element of a set to a least element of its image. -/
theorem map_isGreatest : IsGreatest s a → IsLeast (f '' s) (f a) :=
hf.dual_right.map_isGreatest
/-- An antitone map sends a least element of a set to a greatest element of its image. -/
theorem map_isLeast : IsLeast s a → IsGreatest (f '' s) (f a) :=
hf.dual_right.map_isLeast
end Antitone
section Image2
variable [Preorder α] [Preorder β] [Preorder γ] {f : α → β → γ} {s : Set α} {t : Set β} {a : α}
{b : β}
section MonotoneMonotone
variable (h₀ : ∀ b, Monotone (swap f b)) (h₁ : ∀ a, Monotone (f a))
theorem mem_upperBounds_image2 (ha : a ∈ upperBounds s) (hb : b ∈ upperBounds t) :
f a b ∈ upperBounds (image2 f s t) :=
forall_image2_iff.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy
theorem mem_lowerBounds_image2 (ha : a ∈ lowerBounds s) (hb : b ∈ lowerBounds t) :
f a b ∈ lowerBounds (image2 f s t) :=
forall_image2_iff.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy
theorem image2_upperBounds_upperBounds_subset :
image2 f (upperBounds s) (upperBounds t) ⊆ upperBounds (image2 f s t) :=
image2_subset_iff.2 fun _ ha _ hb ↦ mem_upperBounds_image2 h₀ h₁ ha hb
theorem image2_lowerBounds_lowerBounds_subset :
image2 f (lowerBounds s) (lowerBounds t) ⊆ lowerBounds (image2 f s t) :=
image2_subset_iff.2 fun _ ha _ hb ↦ mem_lowerBounds_image2 h₀ h₁ ha hb
/-- See also `Monotone.map_bddAbove`. -/
protected theorem BddAbove.image2 (h₀ : ∀ b, Monotone (swap f b)) (h₁ : ∀ a, Monotone (f a)) :
BddAbove s → BddAbove t → BddAbove (image2 f s t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
exact ⟨f a b, mem_upperBounds_image2 h₀ h₁ ha hb⟩
/-- See also `Monotone.map_bddBelow`. -/
protected theorem BddBelow.image2 (h₀ : ∀ b, Monotone (swap f b)) (h₁ : ∀ a, Monotone (f a)) :
BddBelow s → BddBelow t → BddBelow (image2 f s t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
exact ⟨f a b, mem_lowerBounds_image2 h₀ h₁ ha hb⟩
protected theorem IsGreatest.image2 (ha : IsGreatest s a) (hb : IsGreatest t b) :
IsGreatest (image2 f s t) (f a b) :=
⟨mem_image2_of_mem ha.1 hb.1, mem_upperBounds_image2 h₀ h₁ ha.2 hb.2⟩
protected theorem IsLeast.image2 (ha : IsLeast s a) (hb : IsLeast t b) :
IsLeast (image2 f s t) (f a b) :=
⟨mem_image2_of_mem ha.1 hb.1, mem_lowerBounds_image2 h₀ h₁ ha.2 hb.2⟩
end MonotoneMonotone
section MonotoneAntitone
variable (h₀ : ∀ b, Monotone (swap f b)) (h₁ : ∀ a, Antitone (f a))
theorem mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds (ha : a ∈ upperBounds s)
(hb : b ∈ lowerBounds t) : f a b ∈ upperBounds (image2 f s t) :=
forall_image2_iff.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy
theorem mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds (ha : a ∈ lowerBounds s)
(hb : b ∈ upperBounds t) : f a b ∈ lowerBounds (image2 f s t) :=
forall_image2_iff.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy
theorem image2_upperBounds_lowerBounds_subset_upperBounds_image2 :
image2 f (upperBounds s) (lowerBounds t) ⊆ upperBounds (image2 f s t) :=
image2_subset_iff.2 fun _ ha _ hb ↦
mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h₀ h₁ ha hb
theorem image2_lowerBounds_upperBounds_subset_lowerBounds_image2 :
image2 f (lowerBounds s) (upperBounds t) ⊆ lowerBounds (image2 f s t) :=
image2_subset_iff.2 fun _ ha _ hb ↦
mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h₀ h₁ ha hb
theorem BddAbove.bddAbove_image2_of_bddBelow :
BddAbove s → BddBelow t → BddAbove (Set.image2 f s t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
exact ⟨f a b, mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h₀ h₁ ha hb⟩
theorem BddBelow.bddBelow_image2_of_bddAbove :
BddBelow s → BddAbove t → BddBelow (Set.image2 f s t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
exact ⟨f a b, mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h₀ h₁ ha hb⟩
theorem IsGreatest.isGreatest_image2_of_isLeast (ha : IsGreatest s a) (hb : IsLeast t b) :
IsGreatest (Set.image2 f s t) (f a b) :=
⟨mem_image2_of_mem ha.1 hb.1,
mem_upperBounds_image2_of_mem_upperBounds_of_mem_lowerBounds h₀ h₁ ha.2 hb.2⟩
theorem IsLeast.isLeast_image2_of_isGreatest (ha : IsLeast s a) (hb : IsGreatest t b) :
IsLeast (Set.image2 f s t) (f a b) :=
⟨mem_image2_of_mem ha.1 hb.1,
mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_upperBounds h₀ h₁ ha.2 hb.2⟩
end MonotoneAntitone
section AntitoneAntitone
variable (h₀ : ∀ b, Antitone (swap f b)) (h₁ : ∀ a, Antitone (f a))
theorem mem_upperBounds_image2_of_mem_lowerBounds (ha : a ∈ lowerBounds s)
(hb : b ∈ lowerBounds t) : f a b ∈ upperBounds (image2 f s t) :=
forall_image2_iff.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy
theorem mem_lowerBounds_image2_of_mem_upperBounds (ha : a ∈ upperBounds s)
(hb : b ∈ upperBounds t) : f a b ∈ lowerBounds (image2 f s t) :=
forall_image2_iff.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy
theorem image2_upperBounds_upperBounds_subset_upperBounds_image2 :
image2 f (lowerBounds s) (lowerBounds t) ⊆ upperBounds (image2 f s t) :=
image2_subset_iff.2 fun _ ha _ hb ↦
mem_upperBounds_image2_of_mem_lowerBounds h₀ h₁ ha hb
theorem image2_lowerBounds_lowerBounds_subset_lowerBounds_image2 :
image2 f (upperBounds s) (upperBounds t) ⊆ lowerBounds (image2 f s t) :=
image2_subset_iff.2 fun _ ha _ hb ↦
mem_lowerBounds_image2_of_mem_upperBounds h₀ h₁ ha hb
theorem BddBelow.image2_bddAbove : BddBelow s → BddBelow t → BddAbove (Set.image2 f s t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
exact ⟨f a b, mem_upperBounds_image2_of_mem_lowerBounds h₀ h₁ ha hb⟩
theorem BddAbove.image2_bddBelow : BddAbove s → BddAbove t → BddBelow (Set.image2 f s t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
exact ⟨f a b, mem_lowerBounds_image2_of_mem_upperBounds h₀ h₁ ha hb⟩
theorem IsLeast.isGreatest_image2 (ha : IsLeast s a) (hb : IsLeast t b) :
IsGreatest (Set.image2 f s t) (f a b) :=
⟨mem_image2_of_mem ha.1 hb.1, mem_upperBounds_image2_of_mem_lowerBounds h₀ h₁ ha.2 hb.2⟩
theorem IsGreatest.isLeast_image2 (ha : IsGreatest s a) (hb : IsGreatest t b) :
IsLeast (Set.image2 f s t) (f a b) :=
⟨mem_image2_of_mem ha.1 hb.1, mem_lowerBounds_image2_of_mem_upperBounds h₀ h₁ ha.2 hb.2⟩
end AntitoneAntitone
section AntitoneMonotone
variable (h₀ : ∀ b, Antitone (swap f b)) (h₁ : ∀ a, Monotone (f a))
theorem mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds (ha : a ∈ lowerBounds s)
(hb : b ∈ upperBounds t) : f a b ∈ upperBounds (image2 f s t) :=
forall_image2_iff.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy
theorem mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds (ha : a ∈ upperBounds s)
(hb : b ∈ lowerBounds t) : f a b ∈ lowerBounds (image2 f s t) :=
forall_image2_iff.2 fun _ hx _ hy => (h₀ _ <| ha hx).trans <| h₁ _ <| hb hy
theorem image2_lowerBounds_upperBounds_subset_upperBounds_image2 :
image2 f (lowerBounds s) (upperBounds t) ⊆ upperBounds (image2 f s t) :=
image2_subset_iff.2 fun _ ha _ hb ↦
mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h₀ h₁ ha hb
theorem image2_upperBounds_lowerBounds_subset_lowerBounds_image2 :
image2 f (upperBounds s) (lowerBounds t) ⊆ lowerBounds (image2 f s t) :=
image2_subset_iff.2 fun _ ha _ hb ↦
mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h₀ h₁ ha hb
theorem BddBelow.bddAbove_image2_of_bddAbove :
BddBelow s → BddAbove t → BddAbove (Set.image2 f s t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
exact ⟨f a b, mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h₀ h₁ ha hb⟩
theorem BddAbove.bddBelow_image2_of_bddAbove :
BddAbove s → BddBelow t → BddBelow (Set.image2 f s t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
exact ⟨f a b, mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h₀ h₁ ha hb⟩
theorem IsLeast.isGreatest_image2_of_isGreatest (ha : IsLeast s a) (hb : IsGreatest t b) :
IsGreatest (Set.image2 f s t) (f a b) :=
⟨mem_image2_of_mem ha.1 hb.1,
mem_upperBounds_image2_of_mem_upperBounds_of_mem_upperBounds h₀ h₁ ha.2 hb.2⟩
theorem IsGreatest.isLeast_image2_of_isLeast (ha : IsGreatest s a) (hb : IsLeast t b) :
IsLeast (Set.image2 f s t) (f a b) :=
⟨mem_image2_of_mem ha.1 hb.1,
mem_lowerBounds_image2_of_mem_lowerBounds_of_mem_lowerBounds h₀ h₁ ha.2 hb.2⟩
end AntitoneMonotone
end Image2
section Prod
variable {α β : Type*} [Preorder α] [Preorder β]
lemma bddAbove_prod {s : Set (α × β)} :
BddAbove s ↔ BddAbove (Prod.fst '' s) ∧ BddAbove (Prod.snd '' s) :=
⟨fun ⟨p, hp⟩ ↦ ⟨⟨p.1, forall_mem_image.2 fun _q hq ↦ (hp hq).1⟩,
⟨p.2, forall_mem_image.2 fun _q hq ↦ (hp hq).2⟩⟩,
fun ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ ↦ ⟨⟨x, y⟩, fun _p hp ↦
⟨hx <| mem_image_of_mem _ hp, hy <| mem_image_of_mem _ hp⟩⟩⟩
lemma bddBelow_prod {s : Set (α × β)} :
BddBelow s ↔ BddBelow (Prod.fst '' s) ∧ BddBelow (Prod.snd '' s) :=
bddAbove_prod (α := αᵒᵈ) (β := βᵒᵈ)
lemma bddAbove_range_prod {F : ι → α × β} :
BddAbove (range F) ↔ BddAbove (range <| Prod.fst ∘ F) ∧ BddAbove (range <| Prod.snd ∘ F) := by
simp only [bddAbove_prod, ← range_comp]
lemma bddBelow_range_prod {F : ι → α × β} :
BddBelow (range F) ↔ BddBelow (range <| Prod.fst ∘ F) ∧ BddBelow (range <| Prod.snd ∘ F) :=
bddAbove_range_prod (α := αᵒᵈ) (β := βᵒᵈ)
theorem isLUB_prod {s : Set (α × β)} (p : α × β) :
IsLUB s p ↔ IsLUB (Prod.fst '' s) p.1 ∧ IsLUB (Prod.snd '' s) p.2 := by
refine
⟨fun H =>
⟨⟨monotone_fst.mem_upperBounds_image H.1, fun a ha => ?_⟩,
⟨monotone_snd.mem_upperBounds_image H.1, fun a ha => ?_⟩⟩,
fun H => ⟨?_, ?_⟩⟩
· suffices h : (a, p.2) ∈ upperBounds s from (H.2 h).1
exact fun q hq => ⟨ha <| mem_image_of_mem _ hq, (H.1 hq).2⟩
· suffices h : (p.1, a) ∈ upperBounds s from (H.2 h).2
exact fun q hq => ⟨(H.1 hq).1, ha <| mem_image_of_mem _ hq⟩
· exact fun q hq => ⟨H.1.1 <| mem_image_of_mem _ hq, H.2.1 <| mem_image_of_mem _ hq⟩
· exact fun q hq =>
⟨H.1.2 <| monotone_fst.mem_upperBounds_image hq,
H.2.2 <| monotone_snd.mem_upperBounds_image hq⟩
theorem isGLB_prod {s : Set (α × β)} (p : α × β) :
IsGLB s p ↔ IsGLB (Prod.fst '' s) p.1 ∧ IsGLB (Prod.snd '' s) p.2 :=
@isLUB_prod αᵒᵈ βᵒᵈ _ _ _ _
end Prod
section Pi
variable {π : α → Type*} [∀ a, Preorder (π a)]
lemma bddAbove_pi {s : Set (∀ a, π a)} :
BddAbove s ↔ ∀ a, BddAbove (Function.eval a '' s) :=
⟨fun ⟨f, hf⟩ a ↦ ⟨f a, forall_mem_image.2 fun _ hg ↦ hf hg a⟩,
fun h ↦ ⟨fun a ↦ (h a).some, fun _ hg a ↦ (h a).some_mem <| mem_image_of_mem _ hg⟩⟩
lemma bddBelow_pi {s : Set (∀ a, π a)} :
BddBelow s ↔ ∀ a, BddBelow (Function.eval a '' s) :=
bddAbove_pi (π := fun a ↦ (π a)ᵒᵈ)
lemma bddAbove_range_pi {F : ι → ∀ a, π a} :
BddAbove (range F) ↔ ∀ a, BddAbove (range fun i ↦ F i a) := by
simp only [bddAbove_pi, ← range_comp]
rfl
lemma bddBelow_range_pi {F : ι → ∀ a, π a} :
BddBelow (range F) ↔ ∀ a, BddBelow (range fun i ↦ F i a) :=
bddAbove_range_pi (π := fun a ↦ (π a)ᵒᵈ)
theorem isLUB_pi {s : Set (∀ a, π a)} {f : ∀ a, π a} :
IsLUB s f ↔ ∀ a, IsLUB (Function.eval a '' s) (f a) := by
classical
refine
⟨fun H a => ⟨(Function.monotone_eval a).mem_upperBounds_image H.1, fun b hb => ?_⟩, fun H =>
⟨?_, ?_⟩⟩
· suffices h : Function.update f a b ∈ upperBounds s from Function.update_same a b f ▸ H.2 h a
exact fun g hg => le_update_iff.2 ⟨hb <| mem_image_of_mem _ hg, fun i _ => H.1 hg i⟩
· exact fun g hg a => (H a).1 (mem_image_of_mem _ hg)
· exact fun g hg a => (H a).2 ((Function.monotone_eval a).mem_upperBounds_image hg)
theorem isGLB_pi {s : Set (∀ a, π a)} {f : ∀ a, π a} :
IsGLB s f ↔ ∀ a, IsGLB (Function.eval a '' s) (f a) :=
@isLUB_pi α (fun a => (π a)ᵒᵈ) _ s f
end Pi
theorem IsGLB.of_image [Preorder α] [Preorder β] {f : α → β} (hf : ∀ {x y}, f x ≤ f y ↔ x ≤ y)
{s : Set α} {x : α} (hx : IsGLB (f '' s) (f x)) : IsGLB s x :=
⟨fun _ hy => hf.1 <| hx.1 <| mem_image_of_mem _ hy, fun _ hy =>
hf.1 <| hx.2 <| Monotone.mem_lowerBounds_image (fun _ _ => hf.2) hy⟩
theorem IsLUB.of_image [Preorder α] [Preorder β] {f : α → β} (hf : ∀ {x y}, f x ≤ f y ↔ x ≤ y)
{s : Set α} {x : α} (hx : IsLUB (f '' s) (f x)) : IsLUB s x :=
⟨fun _ hy => hf.1 <| hx.1 <| mem_image_of_mem _ hy, fun _ hy =>
hf.1 <| hx.2 <| Monotone.mem_upperBounds_image (fun _ _ => hf.2) hy⟩
lemma BddAbove.range_mono [Preorder β] {f : α → β} (g : α → β) (h : ∀ a, f a ≤ g a)
(hbdd : BddAbove (range g)) : BddAbove (range f) := by
obtain ⟨C, hC⟩ := hbdd
use C
rintro - ⟨x, rfl⟩
exact (h x).trans (hC <| mem_range_self x)
lemma BddBelow.range_mono [Preorder β] (f : α → β) {g : α → β} (h : ∀ a, f a ≤ g a)
(hbdd : BddBelow (range f)) : BddBelow (range g) :=
BddAbove.range_mono (β := βᵒᵈ) f h hbdd
lemma BddAbove.range_comp {γ : Type*} [Preorder β] [Preorder γ] {f : α → β} {g : β → γ}
(hf : BddAbove (range f)) (hg : Monotone g) : BddAbove (range (fun x => g (f x))) := by
change BddAbove (range (g ∘ f))
simpa only [Set.range_comp] using hg.map_bddAbove hf
lemma BddBelow.range_comp {γ : Type*} [Preorder β] [Preorder γ] {f : α → β} {g : β → γ}
(hf : BddBelow (range f)) (hg : Monotone g) : BddBelow (range (fun x => g (f x))) := by
change BddBelow (range (g ∘ f))
simpa only [Set.range_comp] using hg.map_bddBelow hf
section ScottContinuous
variable [Preorder α] [Preorder β] {f : α → β} {a : α}
/-- A function between preorders is said to be Scott continuous if it preserves `IsLUB` on directed
sets. It can be shown that a function is Scott continuous if and only if it is continuous wrt the
Scott topology.
The dual notion
```lean
∀ ⦃d : Set α⦄, d.Nonempty → DirectedOn (· ≥ ·) d → ∀ ⦃a⦄, IsGLB d a → IsGLB (f '' d) (f a)
```
does not appear to play a significant role in the literature, so is omitted here.
-/
def ScottContinuous (f : α → β) : Prop :=
∀ ⦃d : Set α⦄, d.Nonempty → DirectedOn (· ≤ ·) d → ∀ ⦃a⦄, IsLUB d a → IsLUB (f '' d) (f a)
protected theorem ScottContinuous.monotone (h : ScottContinuous f) : Monotone f := by
refine fun a b hab =>
(h (insert_nonempty _ _) (directedOn_pair le_refl hab) ?_).1
(mem_image_of_mem _ <| mem_insert _ _)
rw [IsLUB, upperBounds_insert, upperBounds_singleton,
inter_eq_self_of_subset_right (Ici_subset_Ici.2 hab)]
exact isLeast_Ici
end ScottContinuous
|
Order\Bounds\OrderIso.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Hom.Set
/-!
# Order isomorphisms and bounds.
-/
open Set
namespace OrderIso
variable {α β : Type*} [Preorder α] [Preorder β] (f : α ≃o β)
theorem upperBounds_image {s : Set α} : upperBounds (f '' s) = f '' upperBounds s :=
Subset.antisymm
(fun x hx =>
⟨f.symm x, fun _ hy => f.le_symm_apply.2 (hx <| mem_image_of_mem _ hy), f.apply_symm_apply x⟩)
f.monotone.image_upperBounds_subset_upperBounds_image
theorem lowerBounds_image {s : Set α} : lowerBounds (f '' s) = f '' lowerBounds s :=
@upperBounds_image αᵒᵈ βᵒᵈ _ _ f.dual _
-- Porting note: by simps were `fun _ _ => f.le_iff_le` and `fun _ _ => f.symm.le_iff_le`
@[simp]
theorem isLUB_image {s : Set α} {x : β} : IsLUB (f '' s) x ↔ IsLUB s (f.symm x) :=
⟨fun h => IsLUB.of_image (by simp) ((f.apply_symm_apply x).symm ▸ h), fun h =>
(IsLUB.of_image (by simp)) <| (f.symm_image_image s).symm ▸ h⟩
theorem isLUB_image' {s : Set α} {x : α} : IsLUB (f '' s) (f x) ↔ IsLUB s x := by
rw [isLUB_image, f.symm_apply_apply]
@[simp]
theorem isGLB_image {s : Set α} {x : β} : IsGLB (f '' s) x ↔ IsGLB s (f.symm x) :=
f.dual.isLUB_image
theorem isGLB_image' {s : Set α} {x : α} : IsGLB (f '' s) (f x) ↔ IsGLB s x :=
f.dual.isLUB_image'
@[simp]
theorem isLUB_preimage {s : Set β} {x : α} : IsLUB (f ⁻¹' s) x ↔ IsLUB s (f x) := by
rw [← f.symm_symm, ← image_eq_preimage, isLUB_image]
theorem isLUB_preimage' {s : Set β} {x : β} : IsLUB (f ⁻¹' s) (f.symm x) ↔ IsLUB s x := by
rw [isLUB_preimage, f.apply_symm_apply]
@[simp]
theorem isGLB_preimage {s : Set β} {x : α} : IsGLB (f ⁻¹' s) x ↔ IsGLB s (f x) :=
f.dual.isLUB_preimage
theorem isGLB_preimage' {s : Set β} {x : β} : IsGLB (f ⁻¹' s) (f.symm x) ↔ IsGLB s x :=
f.dual.isLUB_preimage'
end OrderIso
|
Order\Category\BddDistLat.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Category.BddLat
import Mathlib.Order.Category.DistLat
/-!
# The category of bounded distributive lattices
This defines `BddDistLat`, the category of bounded distributive lattices.
Note that this category is sometimes called [`DistLat`](https://ncatlab.org/nlab/show/DistLat) when
being a lattice is understood to entail having a bottom and a top element.
-/
universe u
open CategoryTheory
/-- The category of bounded distributive lattices with bounded lattice morphisms. -/
structure BddDistLat where
/-- The underlying distrib lattice of a bounded distributive lattice. -/
toDistLat : DistLat
[isBoundedOrder : BoundedOrder toDistLat]
namespace BddDistLat
instance : CoeSort BddDistLat Type* :=
⟨fun X => X.toDistLat⟩
instance (X : BddDistLat) : DistribLattice X :=
X.toDistLat.str
attribute [instance] BddDistLat.isBoundedOrder
/-- Construct a bundled `BddDistLat` from a `BoundedOrder` `DistribLattice`. -/
def of (α : Type*) [DistribLattice α] [BoundedOrder α] : BddDistLat :=
-- Porting note: was `⟨⟨α⟩⟩`
-- see https://github.com/leanprover-community/mathlib4/issues/4998
⟨{α := α}⟩
@[simp]
theorem coe_of (α : Type*) [DistribLattice α] [BoundedOrder α] : ↥(of α) = α :=
rfl
instance : Inhabited BddDistLat :=
⟨of PUnit⟩
/-- Turn a `BddDistLat` into a `BddLat` by forgetting it is distributive. -/
def toBddLat (X : BddDistLat) : BddLat :=
BddLat.of X
@[simp]
theorem coe_toBddLat (X : BddDistLat) : ↥X.toBddLat = ↥X :=
rfl
instance : LargeCategory.{u} BddDistLat :=
InducedCategory.category toBddLat
instance : ConcreteCategory BddDistLat :=
InducedCategory.concreteCategory toBddLat
instance hasForgetToDistLat : HasForget₂ BddDistLat DistLat where
forget₂ :=
-- Porting note: was `⟨X⟩`
-- see https://github.com/leanprover-community/mathlib4/issues/4998
{ obj := fun X => { α := X }
map := fun {X Y} => BoundedLatticeHom.toLatticeHom }
instance hasForgetToBddLat : HasForget₂ BddDistLat BddLat :=
InducedCategory.hasForget₂ toBddLat
theorem forget_bddLat_lat_eq_forget_distLat_lat :
forget₂ BddDistLat BddLat ⋙ forget₂ BddLat Lat =
forget₂ BddDistLat DistLat ⋙ forget₂ DistLat Lat :=
rfl
/-- Constructs an equivalence between bounded distributive lattices from an order isomorphism
between them. -/
@[simps]
def Iso.mk {α β : BddDistLat.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : BoundedLatticeHom α β)
inv := (e.symm : BoundedLatticeHom β α)
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
/-- `OrderDual` as a functor. -/
@[simps]
def dual : BddDistLat ⥤ BddDistLat where
obj X := of Xᵒᵈ
map {X Y} := BoundedLatticeHom.dual
/-- The equivalence between `BddDistLat` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : BddDistLat ≌ BddDistLat where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end BddDistLat
theorem bddDistLat_dual_comp_forget_to_distLat :
BddDistLat.dual ⋙ forget₂ BddDistLat DistLat =
forget₂ BddDistLat DistLat ⋙ DistLat.dual :=
rfl
|
Order\Category\BddLat.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.CategoryTheory.Adjunction.Unique
import Mathlib.Order.Category.BddOrd
import Mathlib.Order.Category.Lat
import Mathlib.Order.Category.Semilat
/-!
# The category of bounded lattices
This file defines `BddLat`, the category of bounded lattices.
In literature, this is sometimes called `Lat`, the category of lattices, because being a lattice is
understood to entail having a bottom and a top element.
-/
universe u
open CategoryTheory
/-- The category of bounded lattices with bounded lattice morphisms. -/
structure BddLat where
/-- The underlying lattice of a bounded lattice. -/
toLat : Lat
[isBoundedOrder : BoundedOrder toLat]
namespace BddLat
instance : CoeSort BddLat Type* :=
⟨fun X => X.toLat⟩
instance (X : BddLat) : Lattice X :=
X.toLat.str
attribute [instance] BddLat.isBoundedOrder
/-- Construct a bundled `BddLat` from `Lattice` + `BoundedOrder`. -/
def of (α : Type*) [Lattice α] [BoundedOrder α] : BddLat :=
-- Porting note: was `⟨⟨α⟩⟩`, see https://github.com/leanprover-community/mathlib4/issues/4998
⟨{α := α}⟩
@[simp]
theorem coe_of (α : Type*) [Lattice α] [BoundedOrder α] : ↥(of α) = α :=
rfl
instance : Inhabited BddLat :=
⟨of PUnit⟩
instance : LargeCategory.{u} BddLat where
Hom X Y := BoundedLatticeHom X Y
id X := BoundedLatticeHom.id X
comp f g := g.comp f
id_comp := BoundedLatticeHom.comp_id
comp_id := BoundedLatticeHom.id_comp
assoc _ _ _ := BoundedLatticeHom.comp_assoc _ _ _
-- Porting note: added.
instance instFunLike (X Y : BddLat) : FunLike (X ⟶ Y) X Y :=
show FunLike (BoundedLatticeHom X Y) X Y from inferInstance
instance : ConcreteCategory BddLat where
forget :=
{ obj := (↑)
map := DFunLike.coe }
forget_faithful := ⟨(DFunLike.coe_injective ·)⟩
instance hasForgetToBddOrd : HasForget₂ BddLat BddOrd where
forget₂ :=
{ obj := fun X => BddOrd.of X
map := fun {X Y} => BoundedLatticeHom.toBoundedOrderHom }
instance hasForgetToLat : HasForget₂ BddLat Lat where
forget₂ :=
-- Porting note: was `⟨X⟩`, see https://github.com/leanprover-community/mathlib4/issues/4998
{ obj := fun X => {α := X}
map := fun {X Y} => BoundedLatticeHom.toLatticeHom }
instance hasForgetToSemilatSup : HasForget₂ BddLat SemilatSupCat where
forget₂ :=
{ obj := fun X => ⟨X⟩
map := fun {X Y} => BoundedLatticeHom.toSupBotHom }
instance hasForgetToSemilatInf : HasForget₂ BddLat SemilatInfCat where
forget₂ :=
{ obj := fun X => ⟨X⟩
map := fun {X Y} => BoundedLatticeHom.toInfTopHom }
@[simp]
theorem coe_forget_to_bddOrd (X : BddLat) : ↥((forget₂ BddLat BddOrd).obj X) = ↥X :=
rfl
@[simp]
theorem coe_forget_to_lat (X : BddLat) : ↥((forget₂ BddLat Lat).obj X) = ↥X :=
rfl
@[simp]
theorem coe_forget_to_semilatSup (X : BddLat) :
↥((forget₂ BddLat SemilatSupCat).obj X) = ↥X :=
rfl
@[simp]
theorem coe_forget_to_semilatInf (X : BddLat) :
↥((forget₂ BddLat SemilatInfCat).obj X) = ↥X :=
rfl
theorem forget_lat_partOrd_eq_forget_bddOrd_partOrd :
forget₂ BddLat Lat ⋙ forget₂ Lat PartOrd =
forget₂ BddLat BddOrd ⋙ forget₂ BddOrd PartOrd :=
rfl
theorem forget_semilatSup_partOrd_eq_forget_bddOrd_partOrd :
forget₂ BddLat SemilatSupCat ⋙ forget₂ SemilatSupCat PartOrd =
forget₂ BddLat BddOrd ⋙ forget₂ BddOrd PartOrd :=
rfl
theorem forget_semilatInf_partOrd_eq_forget_bddOrd_partOrd :
forget₂ BddLat SemilatInfCat ⋙ forget₂ SemilatInfCat PartOrd =
forget₂ BddLat BddOrd ⋙ forget₂ BddOrd PartOrd :=
rfl
/-- Constructs an equivalence between bounded lattices from an order isomorphism
between them. -/
@[simps]
def Iso.mk {α β : BddLat.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : BoundedLatticeHom _ _)
inv := (e.symm : BoundedLatticeHom _ _)
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
/-- `OrderDual` as a functor. -/
@[simps]
def dual : BddLat ⥤ BddLat where
obj X := of Xᵒᵈ
map {X Y} := BoundedLatticeHom.dual
/-- The equivalence between `BddLat` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : BddLat ≌ BddLat where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end BddLat
theorem bddLat_dual_comp_forget_to_bddOrd :
BddLat.dual ⋙ forget₂ BddLat BddOrd =
forget₂ BddLat BddOrd ⋙ BddOrd.dual :=
rfl
theorem bddLat_dual_comp_forget_to_lat :
BddLat.dual ⋙ forget₂ BddLat Lat = forget₂ BddLat Lat ⋙ Lat.dual :=
rfl
theorem bddLat_dual_comp_forget_to_semilatSupCat :
BddLat.dual ⋙ forget₂ BddLat SemilatSupCat =
forget₂ BddLat SemilatInfCat ⋙ SemilatInfCat.dual :=
rfl
theorem bddLat_dual_comp_forget_to_semilatInfCat :
BddLat.dual ⋙ forget₂ BddLat SemilatInfCat =
forget₂ BddLat SemilatSupCat ⋙ SemilatSupCat.dual :=
rfl
/-- The functor that adds a bottom and a top element to a lattice. This is the free functor. -/
def latToBddLat : Lat.{u} ⥤ BddLat where
obj X := BddLat.of <| WithTop <| WithBot X
map := LatticeHom.withTopWithBot
map_id _ := LatticeHom.withTopWithBot_id
map_comp _ _ := LatticeHom.withTopWithBot_comp _ _
/-- `latToBddLat` is left adjoint to the forgetful functor, meaning it is the free
functor from `Lat` to `BddLat`. -/
def latToBddLatForgetAdjunction : latToBddLat.{u} ⊣ forget₂ BddLat Lat :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Y =>
{ toFun := fun f =>
{ toFun := f ∘ some ∘ some
map_sup' := fun a b => (congr_arg f <| by rfl).trans (f.map_sup' _ _)
map_inf' := fun a b => (congr_arg f <| by rfl).trans (f.map_inf' _ _) }
invFun := fun f => LatticeHom.withTopWithBot' f
left_inv := fun f =>
BoundedLatticeHom.ext fun a =>
match a with
| none => f.map_top'.symm
| some none => f.map_bot'.symm
| some (some a) => rfl
right_inv := fun f => LatticeHom.ext fun a => rfl }
homEquiv_naturality_left_symm := fun f g =>
BoundedLatticeHom.ext fun a =>
match a with
| none => rfl
| some none => rfl
| some (some a) => rfl
homEquiv_naturality_right := fun f g => LatticeHom.ext fun a => rfl }
/-- `latToBddLat` and `OrderDual` commute. -/
-- Porting note: the `simpNF` linter is not happy as it simplifies something that does not
-- have prettyprinting effects.
-- It seems like it is simplifying for example the first type
-- `(↑(BddLat.dualEquiv.functor.obj (latToBddLat.obj X.op.unop)).toLat)`
-- to
-- `(↑(latToBddLat.obj X).toLat)ᵒᵈ`
-- Interestingly, the linter is silent, if the proof is `sorry`-ed out...
-- see https://github.com/leanprover-community/mathlib4/issues/5049
-- @[simps!]
def latToBddLatCompDualIsoDualCompLatToBddLat :
latToBddLat.{u} ⋙ BddLat.dual ≅ Lat.dual ⋙ latToBddLat :=
Adjunction.leftAdjointUniq (latToBddLatForgetAdjunction.comp BddLat.dualEquiv.toAdjunction)
(Lat.dualEquiv.toAdjunction.comp latToBddLatForgetAdjunction)
|
Order\Category\BddOrd.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.CategoryTheory.Category.Bipointed
import Mathlib.Order.Category.PartOrd
import Mathlib.Order.Hom.Bounded
/-!
# The category of bounded orders
This defines `BddOrd`, the category of bounded orders.
-/
universe u v
open CategoryTheory
/-- The category of bounded orders with monotone functions. -/
structure BddOrd where
/-- The underlying object in the category of partial orders. -/
toPartOrd : PartOrd
[isBoundedOrder : BoundedOrder toPartOrd]
namespace BddOrd
instance : CoeSort BddOrd Type* :=
InducedCategory.hasCoeToSort toPartOrd
instance (X : BddOrd) : PartialOrder X :=
X.toPartOrd.str
attribute [instance] BddOrd.isBoundedOrder
/-- Construct a bundled `BddOrd` from a `Fintype` `PartialOrder`. -/
def of (α : Type*) [PartialOrder α] [BoundedOrder α] : BddOrd :=
-- Porting note: was ⟨⟨α⟩⟩, see https://github.com/leanprover-community/mathlib4/issues/4998
⟨{ α := α }⟩
@[simp]
theorem coe_of (α : Type*) [PartialOrder α] [BoundedOrder α] : ↥(of α) = α :=
rfl
instance : Inhabited BddOrd :=
⟨of PUnit⟩
instance largeCategory : LargeCategory.{u} BddOrd where
Hom X Y := BoundedOrderHom X Y
id X := BoundedOrderHom.id X
comp f g := g.comp f
id_comp := BoundedOrderHom.comp_id
comp_id := BoundedOrderHom.id_comp
assoc _ _ _ := BoundedOrderHom.comp_assoc _ _ _
-- Porting note: added.
-- see https://github.com/leanprover-community/mathlib4/issues/5017
instance instFunLike (X Y : BddOrd) : FunLike (X ⟶ Y) X Y :=
show FunLike (BoundedOrderHom X Y) X Y from inferInstance
instance concreteCategory : ConcreteCategory BddOrd where
forget :=
{ obj := (↥)
map := DFunLike.coe }
forget_faithful := ⟨(DFunLike.coe_injective ·)⟩
instance hasForgetToPartOrd : HasForget₂ BddOrd PartOrd where
forget₂ :=
{ obj := fun X => X.toPartOrd
map := fun {X Y} => BoundedOrderHom.toOrderHom }
instance hasForgetToBipointed : HasForget₂ BddOrd Bipointed where
forget₂ :=
{ obj := fun X => ⟨X, ⊥, ⊤⟩
map := fun f => ⟨f, f.map_bot', f.map_top'⟩ }
forget_comp := rfl
/-- `OrderDual` as a functor. -/
@[simps]
def dual : BddOrd ⥤ BddOrd where
obj X := of Xᵒᵈ
map {X Y} := BoundedOrderHom.dual
/-- Constructs an equivalence between bounded orders from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : BddOrd.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : BoundedOrderHom _ _)
inv := (e.symm : BoundedOrderHom _ _)
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
/-- The equivalence between `BddOrd` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : BddOrd ≌ BddOrd where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end BddOrd
theorem bddOrd_dual_comp_forget_to_partOrd :
BddOrd.dual ⋙ forget₂ BddOrd PartOrd =
forget₂ BddOrd PartOrd ⋙ PartOrd.dual :=
rfl
theorem bddOrd_dual_comp_forget_to_bipointed :
BddOrd.dual ⋙ forget₂ BddOrd Bipointed =
forget₂ BddOrd Bipointed ⋙ Bipointed.swap :=
rfl
|
Order\Category\BoolAlg.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Category.HeytAlg
import Mathlib.Order.Hom.CompleteLattice
/-!
# The category of boolean algebras
This defines `BoolAlg`, the category of boolean algebras.
-/
open OrderDual Opposite Set
universe u
open CategoryTheory
/-- The category of boolean algebras. -/
def BoolAlg :=
Bundled BooleanAlgebra
namespace BoolAlg
instance : CoeSort BoolAlg Type* :=
Bundled.coeSort
instance instBooleanAlgebra (X : BoolAlg) : BooleanAlgebra X :=
X.str
/-- Construct a bundled `BoolAlg` from a `BooleanAlgebra`. -/
def of (α : Type*) [BooleanAlgebra α] : BoolAlg :=
Bundled.of α
@[simp]
theorem coe_of (α : Type*) [BooleanAlgebra α] : ↥(of α) = α :=
rfl
instance : Inhabited BoolAlg :=
⟨of PUnit⟩
/-- Turn a `BoolAlg` into a `BddDistLat` by forgetting its complement operation. -/
def toBddDistLat (X : BoolAlg) : BddDistLat :=
BddDistLat.of X
@[simp]
theorem coe_toBddDistLat (X : BoolAlg) : ↥X.toBddDistLat = ↥X :=
rfl
instance : LargeCategory.{u} BoolAlg :=
InducedCategory.category toBddDistLat
instance : ConcreteCategory BoolAlg :=
InducedCategory.concreteCategory toBddDistLat
instance hasForgetToBddDistLat : HasForget₂ BoolAlg BddDistLat :=
InducedCategory.hasForget₂ toBddDistLat
section
attribute [local instance] BoundedLatticeHomClass.toBiheytingHomClass
@[simps]
instance hasForgetToHeytAlg : HasForget₂ BoolAlg HeytAlg where
forget₂ :=
{ obj := fun X => {α := X}
-- Porting note: was `fun {X Y} f => show BoundedLatticeHom X Y from f`
-- which already looks like a hack, but I don't understand why this hack works now and
-- the old one didn't
map := fun {X Y} (f : BoundedLatticeHom X Y) => show HeytingHom X Y from f }
end
/-- Constructs an equivalence between Boolean algebras from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : BoolAlg.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : BoundedLatticeHom α β)
inv := (e.symm : BoundedLatticeHom β α)
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
/-- `OrderDual` as a functor. -/
@[simps]
def dual : BoolAlg ⥤ BoolAlg where
obj X := of Xᵒᵈ
map {X Y} := BoundedLatticeHom.dual
/-- The equivalence between `BoolAlg` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : BoolAlg ≌ BoolAlg where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end BoolAlg
theorem boolAlg_dual_comp_forget_to_bddDistLat :
BoolAlg.dual ⋙ forget₂ BoolAlg BddDistLat =
forget₂ BoolAlg BddDistLat ⋙ BddDistLat.dual :=
rfl
/-- The powerset functor. `Set` as a contravariant functor. -/
@[simps]
def typeToBoolAlgOp : Type u ⥤ BoolAlgᵒᵖ where
obj X := op $ BoolAlg.of (Set X)
map {X Y} f := Quiver.Hom.op
(CompleteLatticeHom.setPreimage f : BoundedLatticeHom (Set Y) (Set X))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.