Context
stringlengths
295
65.3k
file_name
stringlengths
21
74
start
int64
14
1.41k
end
int64
20
1.41k
theorem
stringlengths
27
1.42k
proof
stringlengths
0
4.57k
/- Copyright (c) 2017 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Mario Carneiro -/ import Mathlib.Algebra.Ring.CharZero import Mathlib.Algebra.Star.Basic import Mathlib.Data.Real.Basic import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Tactic.Ring /-! # The complex numbers The complex numbers are modelled as ℝ^2 in the obvious way and it is shown that they form a field of characteristic zero. The result that the complex numbers are algebraically closed, see `FieldTheory.AlgebraicClosure`. -/ assert_not_exists Multiset Algebra open Set Function /-! ### Definition and basic arithmetic -/ /-- Complex numbers consist of two `Real`s: a real part `re` and an imaginary part `im`. -/ structure Complex : Type where /-- The real part of a complex number. -/ re : ℝ /-- The imaginary part of a complex number. -/ im : ℝ @[inherit_doc] notation "ℂ" => Complex namespace Complex open ComplexConjugate noncomputable instance : DecidableEq ℂ := Classical.decEq _ /-- The equivalence between the complex numbers and `ℝ × ℝ`. -/ @[simps apply] def equivRealProd : ℂ ≃ ℝ × ℝ where toFun z := ⟨z.re, z.im⟩ invFun p := ⟨p.1, p.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl @[simp] theorem eta : ∀ z : ℂ, Complex.mk z.re z.im = z | ⟨_, _⟩ => rfl -- We only mark this lemma with `ext` *locally* to avoid it applying whenever terms of `ℂ` appear. theorem ext : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w | ⟨_, _⟩, ⟨_, _⟩, rfl, rfl => rfl attribute [local ext] Complex.ext lemma «forall» {p : ℂ → Prop} : (∀ x, p x) ↔ ∀ a b, p ⟨a, b⟩ := by aesop lemma «exists» {p : ℂ → Prop} : (∃ x, p x) ↔ ∃ a b, p ⟨a, b⟩ := by aesop theorem re_surjective : Surjective re := fun x => ⟨⟨x, 0⟩, rfl⟩ theorem im_surjective : Surjective im := fun y => ⟨⟨0, y⟩, rfl⟩ @[simp] theorem range_re : range re = univ := re_surjective.range_eq @[simp] theorem range_im : range im = univ := im_surjective.range_eq /-- The natural inclusion of the real numbers into the complex numbers. -/ @[coe] def ofReal (r : ℝ) : ℂ := ⟨r, 0⟩ instance : Coe ℝ ℂ := ⟨ofReal⟩ @[simp, norm_cast] theorem ofReal_re (r : ℝ) : Complex.re (r : ℂ) = r := rfl @[simp, norm_cast] theorem ofReal_im (r : ℝ) : (r : ℂ).im = 0 := rfl theorem ofReal_def (r : ℝ) : (r : ℂ) = ⟨r, 0⟩ := rfl @[simp, norm_cast] theorem ofReal_inj {z w : ℝ} : (z : ℂ) = w ↔ z = w := ⟨congrArg re, by apply congrArg⟩ theorem ofReal_injective : Function.Injective ((↑) : ℝ → ℂ) := fun _ _ => congrArg re instance canLift : CanLift ℂ ℝ (↑) fun z => z.im = 0 where prf z hz := ⟨z.re, ext rfl hz.symm⟩ /-- The product of a set on the real axis and a set on the imaginary axis of the complex plane, denoted by `s ×ℂ t`. -/ def reProdIm (s t : Set ℝ) : Set ℂ := re ⁻¹' s ∩ im ⁻¹' t @[deprecated (since := "2024-12-03")] protected alias Set.reProdIm := reProdIm @[inherit_doc] infixl:72 " ×ℂ " => reProdIm theorem mem_reProdIm {z : ℂ} {s t : Set ℝ} : z ∈ s ×ℂ t ↔ z.re ∈ s ∧ z.im ∈ t := Iff.rfl instance : Zero ℂ := ⟨(0 : ℝ)⟩ instance : Inhabited ℂ := ⟨0⟩ @[simp] theorem zero_re : (0 : ℂ).re = 0 := rfl @[simp] theorem zero_im : (0 : ℂ).im = 0 := rfl @[simp, norm_cast] theorem ofReal_zero : ((0 : ℝ) : ℂ) = 0 := rfl @[simp] theorem ofReal_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 := ofReal_inj theorem ofReal_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 := not_congr ofReal_eq_zero instance : One ℂ := ⟨(1 : ℝ)⟩ @[simp] theorem one_re : (1 : ℂ).re = 1 := rfl @[simp] theorem one_im : (1 : ℂ).im = 0 := rfl @[simp, norm_cast] theorem ofReal_one : ((1 : ℝ) : ℂ) = 1 := rfl @[simp] theorem ofReal_eq_one {z : ℝ} : (z : ℂ) = 1 ↔ z = 1 := ofReal_inj theorem ofReal_ne_one {z : ℝ} : (z : ℂ) ≠ 1 ↔ z ≠ 1 := not_congr ofReal_eq_one instance : Add ℂ := ⟨fun z w => ⟨z.re + w.re, z.im + w.im⟩⟩ @[simp] theorem add_re (z w : ℂ) : (z + w).re = z.re + w.re := rfl @[simp] theorem add_im (z w : ℂ) : (z + w).im = z.im + w.im := rfl -- replaced by `re_ofNat` -- replaced by `im_ofNat` @[simp, norm_cast] theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s := Complex.ext_iff.2 <| by simp [ofReal] -- replaced by `Complex.ofReal_ofNat` instance : Neg ℂ := ⟨fun z => ⟨-z.re, -z.im⟩⟩ @[simp] theorem neg_re (z : ℂ) : (-z).re = -z.re := rfl @[simp] theorem neg_im (z : ℂ) : (-z).im = -z.im := rfl @[simp, norm_cast] theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := Complex.ext_iff.2 <| by simp [ofReal] instance : Sub ℂ := ⟨fun z w => ⟨z.re - w.re, z.im - w.im⟩⟩ instance : Mul ℂ := ⟨fun z w => ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩ @[simp] theorem mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im := rfl @[simp] theorem mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re := rfl @[simp, norm_cast] theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s := Complex.ext_iff.2 <| by simp [ofReal] theorem re_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).re = r * z.re := by simp [ofReal] theorem im_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).im = r * z.im := by simp [ofReal] lemma re_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).re = z.re * r := by simp [ofReal] lemma im_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).im = z.im * r := by simp [ofReal] theorem ofReal_mul' (r : ℝ) (z : ℂ) : ↑r * z = ⟨r * z.re, r * z.im⟩ := ext (re_ofReal_mul _ _) (im_ofReal_mul _ _) /-! ### The imaginary unit, `I` -/ /-- The imaginary unit. -/ def I : ℂ := ⟨0, 1⟩ @[simp] theorem I_re : I.re = 0 := rfl @[simp] theorem I_im : I.im = 1 := rfl @[simp] theorem I_mul_I : I * I = -1 := Complex.ext_iff.2 <| by simp theorem I_mul (z : ℂ) : I * z = ⟨-z.im, z.re⟩ := Complex.ext_iff.2 <| by simp @[simp] lemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm theorem mk_eq_add_mul_I (a b : ℝ) : Complex.mk a b = a + b * I := Complex.ext_iff.2 <| by simp [ofReal] @[simp] theorem re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z := Complex.ext_iff.2 <| by simp [ofReal] theorem mul_I_re (z : ℂ) : (z * I).re = -z.im := by simp theorem mul_I_im (z : ℂ) : (z * I).im = z.re := by simp theorem I_mul_re (z : ℂ) : (I * z).re = -z.im := by simp theorem I_mul_im (z : ℂ) : (I * z).im = z.re := by simp @[simp] theorem equivRealProd_symm_apply (p : ℝ × ℝ) : equivRealProd.symm p = p.1 + p.2 * I := by ext <;> simp [Complex.equivRealProd, ofReal] /-- The natural `AddEquiv` from `ℂ` to `ℝ × ℝ`. -/ @[simps! +simpRhs apply symm_apply_re symm_apply_im] def equivRealProdAddHom : ℂ ≃+ ℝ × ℝ := { equivRealProd with map_add' := by simp } theorem equivRealProdAddHom_symm_apply (p : ℝ × ℝ) : equivRealProdAddHom.symm p = p.1 + p.2 * I := equivRealProd_symm_apply p /-! ### Commutative ring instance and lemmas -/ /- We use a nonstandard formula for the `ℕ` and `ℤ` actions to make sure there is no diamond from the other actions they inherit through the `ℝ`-action on `ℂ` and action transitivity defined in `Data.Complex.Module`. -/ instance : Nontrivial ℂ := domain_nontrivial re rfl rfl namespace SMul -- The useless `0` multiplication in `smul` is to make sure that -- `RestrictScalars.module ℝ ℂ ℂ = Complex.module` definitionally. -- instance made scoped to avoid situations like instance synthesis -- of `SMul ℂ ℂ` trying to proceed via `SMul ℂ ℝ`. /-- Scalar multiplication by `R` on `ℝ` extends to `ℂ`. This is used here and in `Matlib.Data.Complex.Module` to transfer instances from `ℝ` to `ℂ`, but is not needed outside, so we make it scoped. -/ scoped instance instSMulRealComplex {R : Type*} [SMul R ℝ] : SMul R ℂ where smul r x := ⟨r • x.re - 0 * x.im, r • x.im + 0 * x.re⟩ end SMul open scoped SMul section SMul variable {R : Type*} [SMul R ℝ] theorem smul_re (r : R) (z : ℂ) : (r • z).re = r • z.re := by simp [(· • ·), SMul.smul] theorem smul_im (r : R) (z : ℂ) : (r • z).im = r • z.im := by simp [(· • ·), SMul.smul] @[simp] theorem real_smul {x : ℝ} {z : ℂ} : x • z = x * z := rfl end SMul instance addCommGroup : AddCommGroup ℂ := { zero := (0 : ℂ) add := (· + ·) neg := Neg.neg sub := Sub.sub nsmul := fun n z => n • z zsmul := fun n z => n • z zsmul_zero' := by intros; ext <;> simp [smul_re, smul_im] nsmul_zero := by intros; ext <;> simp [smul_re, smul_im] nsmul_succ := by intros; ext <;> simp [smul_re, smul_im] <;> ring zsmul_succ' := by intros; ext <;> simp [smul_re, smul_im] <;> ring zsmul_neg' := by intros; ext <;> simp [smul_re, smul_im] <;> ring add_assoc := by intros; ext <;> simp <;> ring zero_add := by intros; ext <;> simp add_zero := by intros; ext <;> simp add_comm := by intros; ext <;> simp <;> ring neg_add_cancel := by intros; ext <;> simp } instance addGroupWithOne : AddGroupWithOne ℂ := { Complex.addCommGroup with natCast := fun n => ⟨n, 0⟩ natCast_zero := by ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_zero] natCast_succ := fun _ => by ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_succ] intCast := fun n => ⟨n, 0⟩ intCast_ofNat := fun _ => by ext <;> rfl intCast_negSucc := fun n => by ext · simp [AddGroupWithOne.intCast_negSucc] show -(1 : ℝ) + (-n) = -(↑(n + 1)) simp [Nat.cast_add, add_comm] · simp [AddGroupWithOne.intCast_negSucc] show im ⟨n, 0⟩ = 0 rfl one := 1 } instance commRing : CommRing ℂ := { addGroupWithOne with mul := (· * ·) npow := @npowRec _ ⟨(1 : ℂ)⟩ ⟨(· * ·)⟩ add_comm := by intros; ext <;> simp <;> ring left_distrib := by intros; ext <;> simp [mul_re, mul_im] <;> ring right_distrib := by intros; ext <;> simp [mul_re, mul_im] <;> ring zero_mul := by intros; ext <;> simp mul_zero := by intros; ext <;> simp mul_assoc := by intros; ext <;> simp <;> ring one_mul := by intros; ext <;> simp mul_one := by intros; ext <;> simp mul_comm := by intros; ext <;> simp <;> ring } /-- This shortcut instance ensures we do not find `Ring` via the noncomputable `Complex.field` instance. -/ instance : Ring ℂ := by infer_instance /-- This shortcut instance ensures we do not find `CommSemiring` via the noncomputable `Complex.field` instance. -/ instance : CommSemiring ℂ := inferInstance /-- This shortcut instance ensures we do not find `Semiring` via the noncomputable `Complex.field` instance. -/ instance : Semiring ℂ := inferInstance /-- The "real part" map, considered as an additive group homomorphism. -/ def reAddGroupHom : ℂ →+ ℝ where toFun := re map_zero' := zero_re map_add' := add_re @[simp] theorem coe_reAddGroupHom : (reAddGroupHom : ℂ → ℝ) = re := rfl /-- The "imaginary part" map, considered as an additive group homomorphism. -/ def imAddGroupHom : ℂ →+ ℝ where toFun := im map_zero' := zero_im map_add' := add_im @[simp] theorem coe_imAddGroupHom : (imAddGroupHom : ℂ → ℝ) = im := rfl /-! ### Cast lemmas -/ instance instNNRatCast : NNRatCast ℂ where nnratCast q := ofReal q instance instRatCast : RatCast ℂ where ratCast q := ofReal q @[simp, norm_cast] lemma ofReal_ofNat (n : ℕ) [n.AtLeastTwo] : ofReal ofNat(n) = ofNat(n) := rfl @[simp, norm_cast] lemma ofReal_natCast (n : ℕ) : ofReal n = n := rfl @[simp, norm_cast] lemma ofReal_intCast (n : ℤ) : ofReal n = n := rfl @[simp, norm_cast] lemma ofReal_nnratCast (q : ℚ≥0) : ofReal q = q := rfl @[simp, norm_cast] lemma ofReal_ratCast (q : ℚ) : ofReal q = q := rfl @[simp] lemma re_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℂ).re = ofNat(n) := rfl @[simp] lemma im_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℂ).im = 0 := rfl @[simp, norm_cast] lemma natCast_re (n : ℕ) : (n : ℂ).re = n := rfl @[simp, norm_cast] lemma natCast_im (n : ℕ) : (n : ℂ).im = 0 := rfl @[simp, norm_cast] lemma intCast_re (n : ℤ) : (n : ℂ).re = n := rfl @[simp, norm_cast] lemma intCast_im (n : ℤ) : (n : ℂ).im = 0 := rfl @[simp, norm_cast] lemma re_nnratCast (q : ℚ≥0) : (q : ℂ).re = q := rfl @[simp, norm_cast] lemma im_nnratCast (q : ℚ≥0) : (q : ℂ).im = 0 := rfl @[simp, norm_cast] lemma ratCast_re (q : ℚ) : (q : ℂ).re = q := rfl @[simp, norm_cast] lemma ratCast_im (q : ℚ) : (q : ℂ).im = 0 := rfl lemma re_nsmul (n : ℕ) (z : ℂ) : (n • z).re = n • z.re := smul_re .. lemma im_nsmul (n : ℕ) (z : ℂ) : (n • z).im = n • z.im := smul_im .. lemma re_zsmul (n : ℤ) (z : ℂ) : (n • z).re = n • z.re := smul_re .. lemma im_zsmul (n : ℤ) (z : ℂ) : (n • z).im = n • z.im := smul_im .. @[simp] lemma re_nnqsmul (q : ℚ≥0) (z : ℂ) : (q • z).re = q • z.re := smul_re .. @[simp] lemma im_nnqsmul (q : ℚ≥0) (z : ℂ) : (q • z).im = q • z.im := smul_im .. @[simp] lemma re_qsmul (q : ℚ) (z : ℂ) : (q • z).re = q • z.re := smul_re .. @[simp] lemma im_qsmul (q : ℚ) (z : ℂ) : (q • z).im = q • z.im := smul_im .. @[norm_cast] lemma ofReal_nsmul (n : ℕ) (r : ℝ) : ↑(n • r) = n • (r : ℂ) := by simp @[norm_cast] lemma ofReal_zsmul (n : ℤ) (r : ℝ) : ↑(n • r) = n • (r : ℂ) := by simp /-! ### Complex conjugation -/ /-- This defines the complex conjugate as the `star` operation of the `StarRing ℂ`. It is recommended to use the ring endomorphism version `starRingEnd`, available under the notation `conj` in the locale `ComplexConjugate`. -/ instance : StarRing ℂ where star z := ⟨z.re, -z.im⟩ star_involutive x := by simp only [eta, neg_neg] star_mul a b := by ext <;> simp [add_comm] <;> ring star_add a b := by ext <;> simp [add_comm] @[simp] theorem conj_re (z : ℂ) : (conj z).re = z.re := rfl @[simp] theorem conj_im (z : ℂ) : (conj z).im = -z.im := rfl @[simp] theorem conj_ofReal (r : ℝ) : conj (r : ℂ) = r := Complex.ext_iff.2 <| by simp [star] @[simp] theorem conj_I : conj I = -I := Complex.ext_iff.2 <| by simp theorem conj_natCast (n : ℕ) : conj (n : ℂ) = n := map_natCast _ _ theorem conj_ofNat (n : ℕ) [n.AtLeastTwo] : conj (ofNat(n) : ℂ) = ofNat(n) := map_ofNat _ _ theorem conj_neg_I : conj (-I) = I := by simp theorem conj_eq_iff_real {z : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r := ⟨fun h => ⟨z.re, ext rfl <| eq_zero_of_neg_eq (congr_arg im h)⟩, fun ⟨h, e⟩ => by rw [e, conj_ofReal]⟩ theorem conj_eq_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z := conj_eq_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp [ofReal], fun h => ⟨_, h.symm⟩⟩ theorem conj_eq_iff_im {z : ℂ} : conj z = z ↔ z.im = 0 := ⟨fun h => add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)), fun h => ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))⟩ @[simp] theorem star_def : (Star.star : ℂ → ℂ) = conj := rfl /-! ### Norm squared -/ /-- The norm squared function. -/ @[pp_nodot] def normSq : ℂ →*₀ ℝ where toFun z := z.re * z.re + z.im * z.im map_zero' := by simp map_one' := by simp map_mul' z w := by dsimp ring theorem normSq_apply (z : ℂ) : normSq z = z.re * z.re + z.im * z.im := rfl @[simp] theorem normSq_ofReal (r : ℝ) : normSq r = r * r := by simp [normSq, ofReal] @[simp] theorem normSq_natCast (n : ℕ) : normSq n = n * n := normSq_ofReal _ @[simp] theorem normSq_intCast (z : ℤ) : normSq z = z * z := normSq_ofReal _ @[simp] theorem normSq_ratCast (q : ℚ) : normSq q = q * q := normSq_ofReal _ @[simp] theorem normSq_ofNat (n : ℕ) [n.AtLeastTwo] : normSq (ofNat(n) : ℂ) = ofNat(n) * ofNat(n) := normSq_natCast _ @[simp] theorem normSq_mk (x y : ℝ) : normSq ⟨x, y⟩ = x * x + y * y := rfl theorem normSq_add_mul_I (x y : ℝ) : normSq (x + y * I) = x ^ 2 + y ^ 2 := by rw [← mk_eq_add_mul_I, normSq_mk, sq, sq] theorem normSq_eq_conj_mul_self {z : ℂ} : (normSq z : ℂ) = conj z * z := by ext <;> simp [normSq, mul_comm, ofReal] theorem normSq_zero : normSq 0 = 0 := by simp theorem normSq_one : normSq 1 = 1 := by simp @[simp] theorem normSq_I : normSq I = 1 := by simp [normSq] theorem normSq_nonneg (z : ℂ) : 0 ≤ normSq z := add_nonneg (mul_self_nonneg _) (mul_self_nonneg _) theorem normSq_eq_zero {z : ℂ} : normSq z = 0 ↔ z = 0 := ⟨fun h => ext (eq_zero_of_mul_self_add_mul_self_eq_zero h) (eq_zero_of_mul_self_add_mul_self_eq_zero <| (add_comm _ _).trans h), fun h => h.symm ▸ normSq_zero⟩ @[simp] theorem normSq_pos {z : ℂ} : 0 < normSq z ↔ z ≠ 0 := (normSq_nonneg z).lt_iff_ne.trans <| not_congr (eq_comm.trans normSq_eq_zero) @[simp] theorem normSq_neg (z : ℂ) : normSq (-z) = normSq z := by simp [normSq] @[simp] theorem normSq_conj (z : ℂ) : normSq (conj z) = normSq z := by simp [normSq] theorem normSq_mul (z w : ℂ) : normSq (z * w) = normSq z * normSq w := normSq.map_mul z w theorem normSq_add (z w : ℂ) : normSq (z + w) = normSq z + normSq w + 2 * (z * conj w).re := by dsimp [normSq]; ring theorem re_sq_le_normSq (z : ℂ) : z.re * z.re ≤ normSq z := le_add_of_nonneg_right (mul_self_nonneg _) theorem im_sq_le_normSq (z : ℂ) : z.im * z.im ≤ normSq z := le_add_of_nonneg_left (mul_self_nonneg _) theorem mul_conj (z : ℂ) : z * conj z = normSq z := Complex.ext_iff.2 <| by simp [normSq, mul_comm, sub_eq_neg_add, add_comm, ofReal] theorem add_conj (z : ℂ) : z + conj z = (2 * z.re : ℝ) := Complex.ext_iff.2 <| by simp [two_mul, ofReal] /-- The coercion `ℝ → ℂ` as a `RingHom`. -/ def ofRealHom : ℝ →+* ℂ where toFun x := (x : ℂ) map_one' := ofReal_one map_zero' := ofReal_zero map_mul' := ofReal_mul map_add' := ofReal_add @[simp] lemma ofRealHom_eq_coe (r : ℝ) : ofRealHom r = r := rfl variable {α : Type*} @[simp] lemma ofReal_comp_add (f g : α → ℝ) : ofReal ∘ (f + g) = ofReal ∘ f + ofReal ∘ g := map_comp_add ofRealHom .. @[simp] lemma ofReal_comp_sub (f g : α → ℝ) : ofReal ∘ (f - g) = ofReal ∘ f - ofReal ∘ g := map_comp_sub ofRealHom .. @[simp] lemma ofReal_comp_neg (f : α → ℝ) : ofReal ∘ (-f) = -(ofReal ∘ f) := map_comp_neg ofRealHom _ lemma ofReal_comp_nsmul (n : ℕ) (f : α → ℝ) : ofReal ∘ (n • f) = n • (ofReal ∘ f) := map_comp_nsmul ofRealHom .. lemma ofReal_comp_zsmul (n : ℤ) (f : α → ℝ) : ofReal ∘ (n • f) = n • (ofReal ∘ f) := map_comp_zsmul ofRealHom .. @[simp] lemma ofReal_comp_mul (f g : α → ℝ) : ofReal ∘ (f * g) = ofReal ∘ f * ofReal ∘ g := map_comp_mul ofRealHom .. @[simp] lemma ofReal_comp_pow (f : α → ℝ) (n : ℕ) : ofReal ∘ (f ^ n) = (ofReal ∘ f) ^ n := map_comp_pow ofRealHom .. @[simp]
Mathlib/Data/Complex/Basic.lean
608
609
theorem I_sq : I ^ 2 = -1 := by
rw [sq, I_mul_I]
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Data.Complex.Norm /-! # The partial order on the complex numbers This order is defined by `z ≤ w ↔ z.re ≤ w.re ∧ z.im = w.im`. This is a natural order on `ℂ` because, as is well-known, there does not exist an order on `ℂ` making it into a `LinearOrderedField`. However, the order described above is the canonical order stemming from the structure of `ℂ` as a ⋆-ring (i.e., it becomes a `StarOrderedRing`). Moreover, with this order `ℂ` is a `StrictOrderedCommRing` and the coercion `(↑) : ℝ → ℂ` is an order embedding. This file only provides `Complex.partialOrder` and lemmas about it. Further structural classes are provided by `Mathlib/Data/RCLike/Basic.lean` as * `RCLike.toStrictOrderedCommRing` * `RCLike.toStarOrderedRing` * `RCLike.toOrderedSMul` These are all only available with `open scoped ComplexOrder`. -/ namespace Complex /-- We put a partial order on ℂ so that `z ≤ w` exactly if `w - z` is real and nonnegative. Complex numbers with different imaginary parts are incomparable. -/ protected def partialOrder : PartialOrder ℂ where le z w := z.re ≤ w.re ∧ z.im = w.im lt z w := z.re < w.re ∧ z.im = w.im lt_iff_le_not_le z w := by rw [lt_iff_le_not_le] tauto le_refl _ := ⟨le_rfl, rfl⟩ le_trans _ _ _ h₁ h₂ := ⟨h₁.1.trans h₂.1, h₁.2.trans h₂.2⟩ le_antisymm _ _ h₁ h₂ := ext (h₁.1.antisymm h₂.1) h₁.2 namespace _root_.ComplexOrder scoped[ComplexOrder] attribute [instance] Complex.partialOrder end _root_.ComplexOrder open ComplexOrder theorem le_def {z w : ℂ} : z ≤ w ↔ z.re ≤ w.re ∧ z.im = w.im := Iff.rfl theorem lt_def {z w : ℂ} : z < w ↔ z.re < w.re ∧ z.im = w.im := Iff.rfl theorem nonneg_iff {z : ℂ} : 0 ≤ z ↔ 0 ≤ z.re ∧ 0 = z.im := le_def theorem pos_iff {z : ℂ} : 0 < z ↔ 0 < z.re ∧ 0 = z.im := lt_def theorem nonpos_iff {z : ℂ} : z ≤ 0 ↔ z.re ≤ 0 ∧ z.im = 0 := le_def theorem neg_iff {z : ℂ} : z < 0 ↔ z.re < 0 ∧ z.im = 0 := lt_def @[simp, norm_cast] theorem real_le_real {x y : ℝ} : (x : ℂ) ≤ (y : ℂ) ↔ x ≤ y := by simp [le_def, ofReal] @[simp, norm_cast] theorem real_lt_real {x y : ℝ} : (x : ℂ) < (y : ℂ) ↔ x < y := by simp [lt_def, ofReal] @[simp, norm_cast] theorem zero_le_real {x : ℝ} : (0 : ℂ) ≤ (x : ℂ) ↔ 0 ≤ x := real_le_real @[simp, norm_cast] theorem zero_lt_real {x : ℝ} : (0 : ℂ) < (x : ℂ) ↔ 0 < x := real_lt_real theorem not_le_iff {z w : ℂ} : ¬z ≤ w ↔ w.re < z.re ∨ z.im ≠ w.im := by rw [le_def, not_and_or, not_le]
Mathlib/Data/Complex/Order.lean
87
88
theorem not_lt_iff {z w : ℂ} : ¬z < w ↔ w.re ≤ z.re ∨ z.im ≠ w.im := by
rw [lt_def, not_and_or, not_lt]
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Idempotents.Basic import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Equivalence /-! # The Karoubi envelope of a category In this file, we define the Karoubi envelope `Karoubi C` of a category `C`. ## Main constructions and definitions - `Karoubi C` is the Karoubi envelope of a category `C`: it is an idempotent complete category. It is also preadditive when `C` is preadditive. - `toKaroubi C : C ⥤ Karoubi C` is a fully faithful functor, which is an equivalence (`toKaroubiIsEquivalence`) when `C` is idempotent complete. -/ noncomputable section open CategoryTheory.Category CategoryTheory.Preadditive CategoryTheory.Limits namespace CategoryTheory variable (C : Type*) [Category C] namespace Idempotents /-- In a preadditive category `C`, when an object `X` decomposes as `X ≅ P ⨿ Q`, one may consider `P` as a direct factor of `X` and up to unique isomorphism, it is determined by the obvious idempotent `X ⟶ P ⟶ X` which is the projection onto `P` with kernel `Q`. More generally, one may define a formal direct factor of an object `X : C` : it consists of an idempotent `p : X ⟶ X` which is thought as the "formal image" of `p`. The type `Karoubi C` shall be the type of the objects of the karoubi envelope of `C`. It makes sense for any category `C`. -/ structure Karoubi where /-- an object of the underlying category -/ X : C /-- an endomorphism of the object -/ p : X ⟶ X /-- the condition that the given endomorphism is an idempotent -/ idem : p ≫ p = p := by aesop_cat namespace Karoubi variable {C} attribute [reassoc (attr := simp)] idem @[ext (iff := false)] theorem ext {P Q : Karoubi C} (h_X : P.X = Q.X) (h_p : P.p ≫ eqToHom h_X = eqToHom h_X ≫ Q.p) : P = Q := by cases P cases Q dsimp at h_X h_p subst h_X simpa only [mk.injEq, heq_eq_eq, true_and, eqToHom_refl, comp_id, id_comp] using h_p /-- A morphism `P ⟶ Q` in the category `Karoubi C` is a morphism in the underlying category `C` which satisfies a relation, which in the preadditive case, expresses that it induces a map between the corresponding "formal direct factors" and that it vanishes on the complement formal direct factor. -/ @[ext] structure Hom (P Q : Karoubi C) where /-- a morphism between the underlying objects -/ f : P.X ⟶ Q.X /-- compatibility of the given morphism with the given idempotents -/ comm : f = P.p ≫ f ≫ Q.p := by aesop_cat instance [Preadditive C] (P Q : Karoubi C) : Inhabited (Hom P Q) := ⟨⟨0, by rw [zero_comp, comp_zero]⟩⟩ @[reassoc (attr := simp)] theorem p_comp {P Q : Karoubi C} (f : Hom P Q) : P.p ≫ f.f = f.f := by rw [f.comm, ← assoc, P.idem] @[reassoc (attr := simp)] theorem comp_p {P Q : Karoubi C} (f : Hom P Q) : f.f ≫ Q.p = f.f := by rw [f.comm, assoc, assoc, Q.idem] @[reassoc]
Mathlib/CategoryTheory/Idempotents/Karoubi.lean
85
85
theorem p_comm {P Q : Karoubi C} (f : Hom P Q) : P.p ≫ f.f = f.f ≫ Q.p := by
rw [p_comp, comp_p]
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Group.NatPowAssoc import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Algebra.Ring.Opposite import Mathlib.Tactic.Abel import Mathlib.Algebra.Ring.Regular /-! # Partial sums of geometric series This file determines the values of the geometric series $\sum_{i=0}^{n-1} x^i$ and $\sum_{i=0}^{n-1} x^i y^{n-1-i}$ and variants thereof. We also provide some bounds on the "geometric" sum of `a/b^i` where `a b : ℕ`. ## Main statements * `geom_sum_Ico` proves that $\sum_{i=m}^{n-1} x^i=\frac{x^n-x^m}{x-1}$ in a division ring. * `geom_sum₂_Ico` proves that $\sum_{i=m}^{n-1} x^iy^{n - 1 - i}=\frac{x^n-y^{n-m}x^m}{x-y}$ in a field. Several variants are recorded, generalising in particular to the case of a noncommutative ring in which `x` and `y` commute. Even versions not using division or subtraction, valid in each semiring, are recorded. -/ variable {R K : Type*} open Finset MulOpposite section Semiring variable [Semiring R] theorem geom_sum_succ {x : R} {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i = (x * ∑ i ∈ range n, x ^ i) + 1 := by simp only [mul_sum, ← pow_succ', sum_range_succ', pow_zero] theorem geom_sum_succ' {x : R} {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i = x ^ n + ∑ i ∈ range n, x ^ i := (sum_range_succ _ _).trans (add_comm _ _) theorem geom_sum_zero (x : R) : ∑ i ∈ range 0, x ^ i = 0 := rfl theorem geom_sum_one (x : R) : ∑ i ∈ range 1, x ^ i = 1 := by simp [geom_sum_succ'] @[simp] theorem geom_sum_two {x : R} : ∑ i ∈ range 2, x ^ i = x + 1 := by simp [geom_sum_succ'] @[simp] theorem zero_geom_sum : ∀ {n}, ∑ i ∈ range n, (0 : R) ^ i = if n = 0 then 0 else 1 | 0 => by simp | 1 => by simp | n + 2 => by rw [geom_sum_succ'] simp [zero_geom_sum] theorem one_geom_sum (n : ℕ) : ∑ i ∈ range n, (1 : R) ^ i = n := by simp theorem op_geom_sum (x : R) (n : ℕ) : op (∑ i ∈ range n, x ^ i) = ∑ i ∈ range n, op x ^ i := by simp @[simp] theorem op_geom_sum₂ (x y : R) (n : ℕ) : ∑ i ∈ range n, op y ^ (n - 1 - i) * op x ^ i = ∑ i ∈ range n, op y ^ i * op x ^ (n - 1 - i) := by rw [← sum_range_reflect] refine sum_congr rfl fun j j_in => ?_ rw [mem_range, Nat.lt_iff_add_one_le] at j_in congr apply tsub_tsub_cancel_of_le exact le_tsub_of_add_le_right j_in theorem geom_sum₂_with_one (x : R) (n : ℕ) : ∑ i ∈ range n, x ^ i * 1 ^ (n - 1 - i) = ∑ i ∈ range n, x ^ i := sum_congr rfl fun i _ => by rw [one_pow, mul_one] /-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/ protected theorem Commute.geom_sum₂_mul_add {x y : R} (h : Commute x y) (n : ℕ) : (∑ i ∈ range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := by let f : ℕ → ℕ → R := fun m i : ℕ => (x + y) ^ i * y ^ (m - 1 - i) change (∑ i ∈ range n, (f n) i) * x + y ^ n = (x + y) ^ n induction n with | zero => rw [range_zero, sum_empty, zero_mul, zero_add, pow_zero, pow_zero] | succ n ih => have f_last : f (n + 1) n = (x + y) ^ n := by dsimp only [f] rw [← tsub_add_eq_tsub_tsub, Nat.add_comm, tsub_self, pow_zero, mul_one] have f_succ : ∀ i, i ∈ range n → f (n + 1) i = y * f n i := fun i hi => by dsimp only [f] have : Commute y ((x + y) ^ i) := (h.symm.add_right (Commute.refl y)).pow_right i rw [← mul_assoc, this.eq, mul_assoc, ← pow_succ' y (n - 1 - i), add_tsub_cancel_right, ← tsub_add_eq_tsub_tsub, add_comm 1 i] have : i + 1 + (n - (i + 1)) = n := add_tsub_cancel_of_le (mem_range.mp hi) rw [add_comm (i + 1)] at this rw [← this, add_tsub_cancel_right, add_comm i 1, ← add_assoc, add_tsub_cancel_right] rw [pow_succ' (x + y), add_mul, sum_range_succ_comm, add_mul, f_last, add_assoc, (((Commute.refl x).add_right h).pow_right n).eq, sum_congr rfl f_succ, ← mul_sum, pow_succ' y, mul_assoc, ← mul_add y, ih] end Semiring @[simp] theorem neg_one_geom_sum [Ring R] {n : ℕ} : ∑ i ∈ range n, (-1 : R) ^ i = if Even n then 0 else 1 := by induction n with | zero => simp | succ k hk => simp only [geom_sum_succ', Nat.even_add_one, hk] split_ifs with h · rw [h.neg_one_pow, add_zero] · rw [(Nat.not_even_iff_odd.1 h).neg_one_pow, neg_add_cancel] theorem geom_sum₂_self {R : Type*} [Semiring R] (x : R) (n : ℕ) : ∑ i ∈ range n, x ^ i * x ^ (n - 1 - i) = n * x ^ (n - 1) := calc ∑ i ∈ Finset.range n, x ^ i * x ^ (n - 1 - i) = ∑ i ∈ Finset.range n, x ^ (i + (n - 1 - i)) := by simp_rw [← pow_add] _ = ∑ _i ∈ Finset.range n, x ^ (n - 1) := Finset.sum_congr rfl fun _ hi => congr_arg _ <| add_tsub_cancel_of_le <| Nat.le_sub_one_of_lt <| Finset.mem_range.1 hi _ = #(range n) • x ^ (n - 1) := sum_const _ _ = n * x ^ (n - 1) := by rw [Finset.card_range, nsmul_eq_mul] /-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/ theorem geom_sum₂_mul_add [CommSemiring R] (x y : R) (n : ℕ) : (∑ i ∈ range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := (Commute.all x y).geom_sum₂_mul_add n theorem geom_sum_mul_add [Semiring R] (x : R) (n : ℕ) : (∑ i ∈ range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n := by have := (Commute.one_right x).geom_sum₂_mul_add n rw [one_pow, geom_sum₂_with_one] at this exact this protected theorem Commute.geom_sum₂_mul [Ring R] {x y : R} (h : Commute x y) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := by have := (h.sub_left (Commute.refl y)).geom_sum₂_mul_add n rw [sub_add_cancel] at this rw [← this, add_sub_cancel_right] theorem Commute.mul_neg_geom_sum₂ [Ring R] {x y : R} (h : Commute x y) (n : ℕ) : ((y - x) * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) = y ^ n - x ^ n := by apply op_injective simp only [op_mul, op_sub, op_geom_sum₂, op_pow] simp [(Commute.op h.symm).geom_sum₂_mul n] theorem Commute.mul_geom_sum₂ [Ring R] {x y : R} (h : Commute x y) (n : ℕ) : ((x - y) * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) = x ^ n - y ^ n := by rw [← neg_sub (y ^ n), ← h.mul_neg_geom_sum₂, ← neg_mul, neg_sub] theorem geom_sum₂_mul [CommRing R] (x y : R) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := (Commute.all x y).geom_sum₂_mul n
Mathlib/Algebra/GeomSum.lean
162
166
theorem geom_sum₂_mul_of_ge [CommSemiring R] [PartialOrder R] [AddLeftReflectLE R] [AddLeftMono R] [ExistsAddOfLE R] [Sub R] [OrderedSub R] {x y : R} (hxy : y ≤ x) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := by
apply eq_tsub_of_add_eq simpa only [tsub_add_cancel_of_le hxy] using geom_sum₂_mul_add (x - y) y n
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kenny Lau, Kim Morrison, Alex Keizer -/ import Mathlib.Data.List.OfFn import Batteries.Data.List.Perm import Mathlib.Data.List.Nodup /-! # Lists of elements of `Fin n` This file develops some results on `finRange n`. -/ assert_not_exists Monoid universe u namespace List variable {α : Type u} theorem finRange_eq_pmap_range (n : ℕ) : finRange n = (range n).pmap Fin.mk (by simp) := by apply List.ext_getElem <;> simp [finRange] @[simp] theorem mem_finRange {n : ℕ} (a : Fin n) : a ∈ finRange n := by rw [finRange_eq_pmap_range] exact mem_pmap.2 ⟨a.1, mem_range.2 a.2, by cases a rfl⟩ theorem nodup_finRange (n : ℕ) : (finRange n).Nodup := by rw [finRange_eq_pmap_range] exact (Pairwise.pmap nodup_range _) fun _ _ _ _ => @Fin.ne_of_val_ne _ ⟨_, _⟩ ⟨_, _⟩ @[simp] theorem finRange_eq_nil {n : ℕ} : finRange n = [] ↔ n = 0 := by rw [← length_eq_zero_iff, length_finRange]
Mathlib/Data/List/FinRange.lean
44
47
theorem pairwise_lt_finRange (n : ℕ) : Pairwise (· < ·) (finRange n) := by
rw [finRange_eq_pmap_range] exact List.pairwise_lt_range.pmap (by simp) (by simp)
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Manuel Candales -/ import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic import Mathlib.Analysis.Normed.Affine.Isometry /-! # Angles between points This file defines unoriented angles in Euclidean affine spaces. ## Main definitions * `EuclideanGeometry.angle`, with notation `∠`, is the undirected angle determined by three points. ## TODO Prove the triangle inequality for the angle. -/ noncomputable section open Real RealInnerProductSpace namespace EuclideanGeometry open InnerProductGeometry variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] {p p₀ : P} /-- The undirected angle at `p₂` between the line segments to `p₁` and `p₃`. If either of those points equals `p₂`, this is π/2. Use `open scoped EuclideanGeometry` to access the `∠ p₁ p₂ p₃` notation. -/ nonrec def angle (p₁ p₂ p₃ : P) : ℝ := angle (p₁ -ᵥ p₂ : V) (p₃ -ᵥ p₂) @[inherit_doc] scoped notation "∠" => EuclideanGeometry.angle theorem continuousAt_angle {x : P × P × P} (hx12 : x.1 ≠ x.2.1) (hx32 : x.2.2 ≠ x.2.1) : ContinuousAt (fun y : P × P × P => ∠ y.1 y.2.1 y.2.2) x := by let f : P × P × P → V × V := fun y => (y.1 -ᵥ y.2.1, y.2.2 -ᵥ y.2.1) have hf1 : (f x).1 ≠ 0 := by simp [f, hx12] have hf2 : (f x).2 ≠ 0 := by simp [f, hx32] exact (InnerProductGeometry.continuousAt_angle hf1 hf2).comp (by fun_prop) @[simp] theorem _root_.AffineIsometry.angle_map {V₂ P₂ : Type*} [NormedAddCommGroup V₂] [InnerProductSpace ℝ V₂] [MetricSpace P₂] [NormedAddTorsor V₂ P₂] (f : P →ᵃⁱ[ℝ] P₂) (p₁ p₂ p₃ : P) : ∠ (f p₁) (f p₂) (f p₃) = ∠ p₁ p₂ p₃ := by simp_rw [angle, ← AffineIsometry.map_vsub, LinearIsometry.angle_map] @[simp, norm_cast] theorem _root_.AffineSubspace.angle_coe {s : AffineSubspace ℝ P} (p₁ p₂ p₃ : s) : haveI : Nonempty s := ⟨p₁⟩ ∠ (p₁ : P) (p₂ : P) (p₃ : P) = ∠ p₁ p₂ p₃ := haveI : Nonempty s := ⟨p₁⟩ s.subtypeₐᵢ.angle_map p₁ p₂ p₃ /-- Angles are translation invariant -/ @[simp] theorem angle_const_vadd (v : V) (p₁ p₂ p₃ : P) : ∠ (v +ᵥ p₁) (v +ᵥ p₂) (v +ᵥ p₃) = ∠ p₁ p₂ p₃ := (AffineIsometryEquiv.constVAdd ℝ P v).toAffineIsometry.angle_map _ _ _ /-- Angles are translation invariant -/ @[simp] theorem angle_vadd_const (v₁ v₂ v₃ : V) (p : P) : ∠ (v₁ +ᵥ p) (v₂ +ᵥ p) (v₃ +ᵥ p) = ∠ v₁ v₂ v₃ := (AffineIsometryEquiv.vaddConst ℝ p).toAffineIsometry.angle_map _ _ _ /-- Angles are translation invariant -/ @[simp] theorem angle_const_vsub (p p₁ p₂ p₃ : P) : ∠ (p -ᵥ p₁) (p -ᵥ p₂) (p -ᵥ p₃) = ∠ p₁ p₂ p₃ := (AffineIsometryEquiv.constVSub ℝ p).toAffineIsometry.angle_map _ _ _ /-- Angles are translation invariant -/ @[simp] theorem angle_vsub_const (p₁ p₂ p₃ p : P) : ∠ (p₁ -ᵥ p) (p₂ -ᵥ p) (p₃ -ᵥ p) = ∠ p₁ p₂ p₃ := (AffineIsometryEquiv.vaddConst ℝ p).symm.toAffineIsometry.angle_map _ _ _ /-- Angles in a vector space are translation invariant -/ @[simp] theorem angle_add_const (v₁ v₂ v₃ : V) (v : V) : ∠ (v₁ + v) (v₂ + v) (v₃ + v) = ∠ v₁ v₂ v₃ := angle_vadd_const _ _ _ _ /-- Angles in a vector space are translation invariant -/ @[simp] theorem angle_const_add (v : V) (v₁ v₂ v₃ : V) : ∠ (v + v₁) (v + v₂) (v + v₃) = ∠ v₁ v₂ v₃ := angle_const_vadd _ _ _ _ /-- Angles in a vector space are translation invariant -/ @[simp] theorem angle_sub_const (v₁ v₂ v₃ : V) (v : V) : ∠ (v₁ - v) (v₂ - v) (v₃ - v) = ∠ v₁ v₂ v₃ := by simpa only [vsub_eq_sub] using angle_vsub_const v₁ v₂ v₃ v /-- Angles in a vector space are invariant to inversion -/ @[simp] theorem angle_const_sub (v : V) (v₁ v₂ v₃ : V) : ∠ (v - v₁) (v - v₂) (v - v₃) = ∠ v₁ v₂ v₃ := by simpa only [vsub_eq_sub] using angle_const_vsub v v₁ v₂ v₃ /-- Angles in a vector space are invariant to inversion -/ @[simp] theorem angle_neg (v₁ v₂ v₃ : V) : ∠ (-v₁) (-v₂) (-v₃) = ∠ v₁ v₂ v₃ := by simpa only [zero_sub] using angle_const_sub 0 v₁ v₂ v₃ /-- The angle at a point does not depend on the order of the other two points. -/ nonrec theorem angle_comm (p₁ p₂ p₃ : P) : ∠ p₁ p₂ p₃ = ∠ p₃ p₂ p₁ := angle_comm _ _ /-- The angle at a point is nonnegative. -/ nonrec theorem angle_nonneg (p₁ p₂ p₃ : P) : 0 ≤ ∠ p₁ p₂ p₃ := angle_nonneg _ _ /-- The angle at a point is at most π. -/ nonrec theorem angle_le_pi (p₁ p₂ p₃ : P) : ∠ p₁ p₂ p₃ ≤ π := angle_le_pi _ _ /-- The angle ∠AAB at a point is always `π / 2`. -/ @[simp] lemma angle_self_left (p₀ p : P) : ∠ p₀ p₀ p = π / 2 := by unfold angle rw [vsub_self] exact angle_zero_left _ /-- The angle ∠ABB at a point is always `π / 2`. -/ @[simp] lemma angle_self_right (p₀ p : P) : ∠ p p₀ p₀ = π / 2 := by rw [angle_comm, angle_self_left] /-- The angle ∠ABA at a point is `0`, unless `A = B`. -/ theorem angle_self_of_ne (h : p ≠ p₀) : ∠ p p₀ p = 0 := angle_self <| vsub_ne_zero.2 h /-- If the angle ∠ABC at a point is π, the angle ∠BAC is 0. -/ theorem angle_eq_zero_of_angle_eq_pi_left {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : ∠ p₂ p₁ p₃ = 0 := by unfold angle at h rw [angle_eq_pi_iff] at h rcases h with ⟨hp₁p₂, ⟨r, ⟨hr, hpr⟩⟩⟩ unfold angle rw [angle_eq_zero_iff] rw [← neg_vsub_eq_vsub_rev, neg_ne_zero] at hp₁p₂ use hp₁p₂, -r + 1, add_pos (neg_pos_of_neg hr) zero_lt_one rw [add_smul, ← neg_vsub_eq_vsub_rev p₁ p₂, smul_neg] simp [← hpr] /-- If the angle ∠ABC at a point is π, the angle ∠BCA is 0. -/ theorem angle_eq_zero_of_angle_eq_pi_right {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : ∠ p₂ p₃ p₁ = 0 := by rw [angle_comm] at h exact angle_eq_zero_of_angle_eq_pi_left h /-- If ∠BCD = π, then ∠ABC = ∠ABD. -/ theorem angle_eq_angle_of_angle_eq_pi (p₁ : P) {p₂ p₃ p₄ : P} (h : ∠ p₂ p₃ p₄ = π) : ∠ p₁ p₂ p₃ = ∠ p₁ p₂ p₄ := by unfold angle at * rcases angle_eq_pi_iff.1 h with ⟨_, ⟨r, ⟨hr, hpr⟩⟩⟩ rw [eq_comm] convert angle_smul_right_of_pos (p₁ -ᵥ p₂) (p₃ -ᵥ p₂) (add_pos (neg_pos_of_neg hr) zero_lt_one) rw [add_smul, ← neg_vsub_eq_vsub_rev p₂ p₃, smul_neg, neg_smul, ← hpr] simp /-- If ∠BCD = π, then ∠ACB + ∠ACD = π. -/ nonrec theorem angle_add_angle_eq_pi_of_angle_eq_pi (p₁ : P) {p₂ p₃ p₄ : P} (h : ∠ p₂ p₃ p₄ = π) : ∠ p₁ p₃ p₂ + ∠ p₁ p₃ p₄ = π := by unfold angle at h rw [angle_comm p₁ p₃ p₂, angle_comm p₁ p₃ p₄] unfold angle exact angle_add_angle_eq_pi_of_angle_eq_pi _ h /-- **Vertical Angles Theorem**: angles opposite each other, formed by two intersecting straight lines, are equal. -/ theorem angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi {p₁ p₂ p₃ p₄ p₅ : P} (hapc : ∠ p₁ p₅ p₃ = π) (hbpd : ∠ p₂ p₅ p₄ = π) : ∠ p₁ p₅ p₂ = ∠ p₃ p₅ p₄ := by linarith [angle_add_angle_eq_pi_of_angle_eq_pi p₁ hbpd, angle_comm p₄ p₅ p₁, angle_add_angle_eq_pi_of_angle_eq_pi p₄ hapc, angle_comm p₄ p₅ p₃] /-- If ∠ABC = π then dist A B ≠ 0. -/ theorem left_dist_ne_zero_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : dist p₁ p₂ ≠ 0 := by by_contra heq rw [dist_eq_zero] at heq rw [heq, angle_self_left] at h exact Real.pi_ne_zero (by linarith) /-- If ∠ABC = π then dist C B ≠ 0. -/ theorem right_dist_ne_zero_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : dist p₃ p₂ ≠ 0 := left_dist_ne_zero_of_angle_eq_pi <| (angle_comm _ _ _).trans h /-- If ∠ABC = π, then (dist A C) = (dist A B) + (dist B C). -/ theorem dist_eq_add_dist_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : dist p₁ p₃ = dist p₁ p₂ + dist p₃ p₂ := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_add_norm_of_angle_eq_pi h /-- If A ≠ B and C ≠ B then ∠ABC = π if and only if (dist A C) = (dist A B) + (dist B C). -/ theorem dist_eq_add_dist_iff_angle_eq_pi {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₃p₂ : p₃ ≠ p₂) : dist p₁ p₃ = dist p₁ p₂ + dist p₃ p₂ ↔ ∠ p₁ p₂ p₃ = π := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_add_norm_iff_angle_eq_pi (fun he => hp₁p₂ (vsub_eq_zero_iff_eq.1 he)) fun he => hp₃p₂ (vsub_eq_zero_iff_eq.1 he) /-- If ∠ABC = 0, then (dist A C) = abs ((dist A B) - (dist B C)). -/ theorem dist_eq_abs_sub_dist_of_angle_eq_zero {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = 0) : dist p₁ p₃ = |dist p₁ p₂ - dist p₃ p₂| := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_abs_sub_norm_of_angle_eq_zero h /-- If A ≠ B and C ≠ B then ∠ABC = 0 if and only if (dist A C) = abs ((dist A B) - (dist B C)). -/
Mathlib/Geometry/Euclidean/Angle/Unoriented/Affine.lean
213
217
theorem dist_eq_abs_sub_dist_iff_angle_eq_zero {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₃p₂ : p₃ ≠ p₂) : dist p₁ p₃ = |dist p₁ p₂ - dist p₃ p₂| ↔ ∠ p₁ p₂ p₃ = 0 := by
rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_abs_sub_norm_iff_angle_eq_zero (fun he => hp₁p₂ (vsub_eq_zero_iff_eq.1 he))
/- Copyright (c) 2021 Vladimir Goryachev. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Vladimir Goryachev, Kyle Miller, Kim Morrison, Eric Rodriguez -/ import Mathlib.Algebra.Group.Nat.Range import Mathlib.Data.Set.Finite.Basic /-! # Counting on ℕ This file defines the `count` function, which gives, for any predicate on the natural numbers, "how many numbers under `k` satisfy this predicate?". We then prove several expected lemmas about `count`, relating it to the cardinality of other objects, and helping to evaluate it for specific `k`. -/ assert_not_imported Mathlib.Dynamics.FixedPoints.Basic assert_not_exists Ring open Finset namespace Nat variable (p : ℕ → Prop) section Count variable [DecidablePred p] /-- Count the number of naturals `k < n` satisfying `p k`. -/ def count (n : ℕ) : ℕ := (List.range n).countP p @[simp] theorem count_zero : count p 0 = 0 := by rw [count, List.range_zero, List.countP, List.countP.go] /-- A fintype instance for the set relevant to `Nat.count`. Locally an instance in locale `count` -/ def CountSet.fintype (n : ℕ) : Fintype { i // i < n ∧ p i } := by apply Fintype.ofFinset {x ∈ range n | p x} intro x rw [mem_filter, mem_range] rfl scoped[Count] attribute [instance] Nat.CountSet.fintype open Count theorem count_eq_card_filter_range (n : ℕ) : count p n = #{x ∈ range n | p x} := by rw [count, List.countP_eq_length_filter] rfl /-- `count p n` can be expressed as the cardinality of `{k // k < n ∧ p k}`. -/ theorem count_eq_card_fintype (n : ℕ) : count p n = Fintype.card { k : ℕ // k < n ∧ p k } := by rw [count_eq_card_filter_range, ← Fintype.card_ofFinset, ← CountSet.fintype] rfl theorem count_le {n : ℕ} : count p n ≤ n := by rw [count_eq_card_filter_range] exact (card_filter_le _ _).trans_eq (card_range _) theorem count_succ (n : ℕ) : count p (n + 1) = count p n + if p n then 1 else 0 := by split_ifs with h <;> simp [count, List.range_succ, h] @[mono] theorem count_monotone : Monotone (count p) := monotone_nat_of_le_succ fun n ↦ by by_cases h : p n <;> simp [count_succ, h] theorem count_add (a b : ℕ) : count p (a + b) = count p a + count (fun k ↦ p (a + k)) b := by have : Disjoint {x ∈ range a | p x} {x ∈ (range b).map <| addLeftEmbedding a | p x} := by apply disjoint_filter_filter rw [Finset.disjoint_left] simp_rw [mem_map, mem_range, addLeftEmbedding_apply] rintro x hx ⟨c, _, rfl⟩ exact (Nat.le_add_right _ _).not_lt hx simp_rw [count_eq_card_filter_range, range_add, filter_union, card_union_of_disjoint this, filter_map, addLeftEmbedding, card_map] rfl theorem count_add' (a b : ℕ) : count p (a + b) = count (fun k ↦ p (k + b)) a + count p b := by rw [add_comm, count_add, add_comm] simp_rw [add_comm b]
Mathlib/Data/Nat/Count.lean
86
88
theorem count_one : count p 1 = if p 0 then 1 else 0 := by
simp [count_succ] theorem count_succ' (n : ℕ) :
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Nat.Choose.Basic import Mathlib.Data.List.FinRange import Mathlib.Data.List.Perm.Basic import Mathlib.Data.List.Lex import Mathlib.Data.List.Induction /-! # sublists `List.Sublists` gives a list of all (not necessarily contiguous) sublists of a list. This file contains basic results on this function. -/ universe u v w variable {α : Type u} {β : Type v} {γ : Type w} open Nat namespace List /-! ### sublists -/ @[simp] theorem sublists'_nil : sublists' (@nil α) = [[]] := rfl @[simp] theorem sublists'_singleton (a : α) : sublists' [a] = [[], [a]] := rfl /-- Auxiliary helper definition for `sublists'` -/ def sublists'Aux (a : α) (r₁ r₂ : List (List α)) : List (List α) := r₁.foldl (init := r₂) fun r l => r ++ [a :: l] theorem sublists'Aux_eq_array_foldl (a : α) : ∀ (r₁ r₂ : List (List α)), sublists'Aux a r₁ r₂ = ((r₁.toArray).foldl (init := r₂.toArray) (fun r l => r.push (a :: l))).toList := by intro r₁ r₂ rw [sublists'Aux, Array.foldl_toList] have := List.foldl_hom Array.toList (g₁ := fun r l => r.push (a :: l)) (g₂ := fun r l => r ++ [a :: l]) (l := r₁) (init := r₂.toArray) (by simp) simpa using this theorem sublists'_eq_sublists'Aux (l : List α) : sublists' l = l.foldr (fun a r => sublists'Aux a r r) [[]] := by simp only [sublists', sublists'Aux_eq_array_foldl] rw [← List.foldr_hom Array.toList] · intros _ _; congr theorem sublists'Aux_eq_map (a : α) (r₁ : List (List α)) : ∀ (r₂ : List (List α)), sublists'Aux a r₁ r₂ = r₂ ++ map (cons a) r₁ := List.reverseRecOn r₁ (fun _ => by simp [sublists'Aux]) fun r₁ l ih r₂ => by rw [map_append, map_singleton, ← append_assoc, ← ih, sublists'Aux, foldl_append, foldl] simp [sublists'Aux] @[simp 900] theorem sublists'_cons (a : α) (l : List α) : sublists' (a :: l) = sublists' l ++ map (cons a) (sublists' l) := by simp [sublists'_eq_sublists'Aux, foldr_cons, sublists'Aux_eq_map] @[simp] theorem mem_sublists' {s t : List α} : s ∈ sublists' t ↔ s <+ t := by induction' t with a t IH generalizing s · simp only [sublists'_nil, mem_singleton] exact ⟨fun h => by rw [h], eq_nil_of_sublist_nil⟩ simp only [sublists'_cons, mem_append, IH, mem_map] constructor <;> intro h · rcases h with (h | ⟨s, h, rfl⟩) · exact sublist_cons_of_sublist _ h · exact h.cons_cons _ · obtain - | ⟨-, h⟩ | ⟨-, h⟩ := h · exact Or.inl h · exact Or.inr ⟨_, h, rfl⟩ @[simp] theorem length_sublists' : ∀ l : List α, length (sublists' l) = 2 ^ length l | [] => rfl | a :: l => by simp +arith only [sublists'_cons, length_append, length_sublists' l, length_map, length, Nat.pow_succ'] @[simp] theorem sublists_nil : sublists (@nil α) = [[]] := rfl @[simp] theorem sublists_singleton (a : α) : sublists [a] = [[], [a]] := rfl /-- Auxiliary helper function for `sublists` -/ def sublistsAux (a : α) (r : List (List α)) : List (List α) := r.foldl (init := []) fun r l => r ++ [l, a :: l] theorem sublistsAux_eq_array_foldl : sublistsAux = fun (a : α) (r : List (List α)) => (r.toArray.foldl (init := #[]) fun r l => (r.push l).push (a :: l)).toList := by funext a r simp only [sublistsAux, Array.foldl_toList, Array.mkEmpty] have := foldl_hom Array.toList (g₁ := fun r l => (r.push l).push (a :: l)) (g₂ := fun r l => r ++ [l, a :: l]) (l := r) (init := #[]) (by simp) simpa using this theorem sublistsAux_eq_flatMap : sublistsAux = fun (a : α) (r : List (List α)) => r.flatMap fun l => [l, a :: l] := funext fun a => funext fun r => List.reverseRecOn r (by simp [sublistsAux]) (fun r l ih => by rw [flatMap_append, ← ih, flatMap_singleton, sublistsAux, foldl_append] simp [sublistsAux]) @[csimp] theorem sublists_eq_sublistsFast : @sublists = @sublistsFast := by ext α l : 2 trans l.foldr sublistsAux [[]] · rw [sublistsAux_eq_flatMap, sublists] · simp only [sublistsFast, sublistsAux_eq_array_foldl, Array.foldr_toList] rw [← foldr_hom Array.toList] · intros _ _; congr theorem sublists_append (l₁ l₂ : List α) : sublists (l₁ ++ l₂) = (sublists l₂) >>= (fun x => (sublists l₁).map (· ++ x)) := by simp only [sublists, foldr_append] induction l₁ with | nil => simp | cons a l₁ ih => rw [foldr_cons, ih] simp [List.flatMap, flatten_flatten, Function.comp_def] theorem sublists_cons (a : α) (l : List α) : sublists (a :: l) = sublists l >>= (fun x => [x, a :: x]) := show sublists ([a] ++ l) = _ by rw [sublists_append] simp only [sublists_singleton, map_cons, bind_eq_flatMap, nil_append, cons_append, map_nil] @[simp] theorem sublists_concat (l : List α) (a : α) : sublists (l ++ [a]) = sublists l ++ map (fun x => x ++ [a]) (sublists l) := by rw [sublists_append, sublists_singleton, bind_eq_flatMap, flatMap_cons, flatMap_cons, flatMap_nil, map_id'' append_nil, append_nil] theorem sublists_reverse (l : List α) : sublists (reverse l) = map reverse (sublists' l) := by induction' l with hd tl ih <;> [rfl; simp only [reverse_cons, sublists_append, sublists'_cons, map_append, ih, sublists_singleton, map_eq_map, bind_eq_flatMap, map_map, flatMap_cons, append_nil, flatMap_nil, Function.comp_def]] theorem sublists_eq_sublists' (l : List α) : sublists l = map reverse (sublists' (reverse l)) := by rw [← sublists_reverse, reverse_reverse] theorem sublists'_reverse (l : List α) : sublists' (reverse l) = map reverse (sublists l) := by simp only [sublists_eq_sublists', map_map, map_id'' reverse_reverse, Function.comp_def] theorem sublists'_eq_sublists (l : List α) : sublists' l = map reverse (sublists (reverse l)) := by rw [← sublists'_reverse, reverse_reverse] @[simp] theorem mem_sublists {s t : List α} : s ∈ sublists t ↔ s <+ t := by rw [← reverse_sublist, ← mem_sublists', sublists'_reverse, mem_map_of_injective reverse_injective] @[simp]
Mathlib/Data/List/Sublists.lean
169
173
theorem length_sublists (l : List α) : length (sublists l) = 2 ^ length l := by
simp only [sublists_eq_sublists', length_map, length_sublists', length_reverse] theorem map_pure_sublist_sublists (l : List α) : map pure l <+ sublists l := by induction' l using reverseRecOn with l a ih <;> simp only [map, map_append, sublists_concat]
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Wrenna Robson -/ import Mathlib.Algebra.BigOperators.Group.Finset.Pi import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.LinearAlgebra.Vandermonde import Mathlib.RingTheory.Polynomial.Basic /-! # Lagrange interpolation ## Main definitions * In everything that follows, `s : Finset ι` is a finite set of indexes, with `v : ι → F` an indexing of the field over some type. We call the image of v on s the interpolation nodes, though strictly unique nodes are only defined when v is injective on s. * `Lagrange.basisDivisor x y`, with `x y : F`. These are the normalised irreducible factors of the Lagrange basis polynomials. They evaluate to `1` at `x` and `0` at `y` when `x` and `y` are distinct. * `Lagrange.basis v i` with `i : ι`: the Lagrange basis polynomial that evaluates to `1` at `v i` and `0` at `v j` for `i ≠ j`. * `Lagrange.interpolate v r` where `r : ι → F` is a function from the fintype to the field: the Lagrange interpolant that evaluates to `r i` at `x i` for all `i : ι`. The `r i` are the _values_ associated with the _nodes_`x i`. -/ open Polynomial section PolynomialDetermination namespace Polynomial variable {R : Type*} [CommRing R] [IsDomain R] {f g : R[X]} section Finset open Function Fintype open scoped Finset variable (s : Finset R) theorem eq_zero_of_degree_lt_of_eval_finset_eq_zero (degree_f_lt : f.degree < #s) (eval_f : ∀ x ∈ s, f.eval x = 0) : f = 0 := by rw [← mem_degreeLT] at degree_f_lt simp_rw [eval_eq_sum_degreeLTEquiv degree_f_lt] at eval_f rw [← degreeLTEquiv_eq_zero_iff_eq_zero degree_f_lt] exact Matrix.eq_zero_of_forall_index_sum_mul_pow_eq_zero (Injective.comp (Embedding.subtype _).inj' (equivFinOfCardEq (card_coe _)).symm.injective) fun _ => eval_f _ (Finset.coe_mem _) theorem eq_of_degree_sub_lt_of_eval_finset_eq (degree_fg_lt : (f - g).degree < #s) (eval_fg : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rw [← sub_eq_zero] refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_fg_lt ?_ simp_rw [eval_sub, sub_eq_zero] exact eval_fg theorem eq_of_degrees_lt_of_eval_finset_eq (degree_f_lt : f.degree < #s) (degree_g_lt : g.degree < #s) (eval_fg : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rw [← mem_degreeLT] at degree_f_lt degree_g_lt refine eq_of_degree_sub_lt_of_eval_finset_eq _ ?_ eval_fg rw [← mem_degreeLT]; exact Submodule.sub_mem _ degree_f_lt degree_g_lt /-- Two polynomials, with the same degree and leading coefficient, which have the same evaluation on a set of distinct values with cardinality equal to the degree, are equal. -/ theorem eq_of_degree_le_of_eval_finset_eq (h_deg_le : f.degree ≤ #s) (h_deg_eq : f.degree = g.degree) (hlc : f.leadingCoeff = g.leadingCoeff) (h_eval : ∀ x ∈ s, f.eval x = g.eval x) : f = g := by rcases eq_or_ne f 0 with rfl | hf · rwa [degree_zero, eq_comm, degree_eq_bot, eq_comm] at h_deg_eq · exact eq_of_degree_sub_lt_of_eval_finset_eq s (lt_of_lt_of_le (degree_sub_lt h_deg_eq hf hlc) h_deg_le) h_eval end Finset section Indexed open Finset variable {ι : Type*} {v : ι → R} (s : Finset ι) theorem eq_zero_of_degree_lt_of_eval_index_eq_zero (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) (eval_f : ∀ i ∈ s, f.eval (v i) = 0) : f = 0 := by classical rw [← card_image_of_injOn hvs] at degree_f_lt refine eq_zero_of_degree_lt_of_eval_finset_eq_zero _ degree_f_lt ?_ intro x hx rcases mem_image.mp hx with ⟨_, hj, rfl⟩ exact eval_f _ hj theorem eq_of_degree_sub_lt_of_eval_index_eq (hvs : Set.InjOn v s) (degree_fg_lt : (f - g).degree < #s) (eval_fg : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by rw [← sub_eq_zero] refine eq_zero_of_degree_lt_of_eval_index_eq_zero _ hvs degree_fg_lt ?_ simp_rw [eval_sub, sub_eq_zero] exact eval_fg theorem eq_of_degrees_lt_of_eval_index_eq (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) (degree_g_lt : g.degree < #s) (eval_fg : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by refine eq_of_degree_sub_lt_of_eval_index_eq _ hvs ?_ eval_fg rw [← mem_degreeLT] at degree_f_lt degree_g_lt ⊢ exact Submodule.sub_mem _ degree_f_lt degree_g_lt theorem eq_of_degree_le_of_eval_index_eq (hvs : Set.InjOn v s) (h_deg_le : f.degree ≤ #s) (h_deg_eq : f.degree = g.degree) (hlc : f.leadingCoeff = g.leadingCoeff) (h_eval : ∀ i ∈ s, f.eval (v i) = g.eval (v i)) : f = g := by rcases eq_or_ne f 0 with rfl | hf · rwa [degree_zero, eq_comm, degree_eq_bot, eq_comm] at h_deg_eq · exact eq_of_degree_sub_lt_of_eval_index_eq s hvs (lt_of_lt_of_le (degree_sub_lt h_deg_eq hf hlc) h_deg_le) h_eval end Indexed end Polynomial end PolynomialDetermination noncomputable section namespace Lagrange open Polynomial section BasisDivisor variable {F : Type*} [Field F] variable {x y : F} /-- `basisDivisor x y` is the unique linear or constant polynomial such that when evaluated at `x` it gives `1` and `y` it gives `0` (where when `x = y` it is identically `0`). Such polynomials are the building blocks for the Lagrange interpolants. -/ def basisDivisor (x y : F) : F[X] := C (x - y)⁻¹ * (X - C y) theorem basisDivisor_self : basisDivisor x x = 0 := by simp only [basisDivisor, sub_self, inv_zero, map_zero, zero_mul] theorem basisDivisor_inj (hxy : basisDivisor x y = 0) : x = y := by simp_rw [basisDivisor, mul_eq_zero, X_sub_C_ne_zero, or_false, C_eq_zero, inv_eq_zero, sub_eq_zero] at hxy exact hxy @[simp] theorem basisDivisor_eq_zero_iff : basisDivisor x y = 0 ↔ x = y := ⟨basisDivisor_inj, fun H => H ▸ basisDivisor_self⟩ theorem basisDivisor_ne_zero_iff : basisDivisor x y ≠ 0 ↔ x ≠ y := by rw [Ne, basisDivisor_eq_zero_iff] theorem degree_basisDivisor_of_ne (hxy : x ≠ y) : (basisDivisor x y).degree = 1 := by rw [basisDivisor, degree_mul, degree_X_sub_C, degree_C, zero_add] exact inv_ne_zero (sub_ne_zero_of_ne hxy) @[simp] theorem degree_basisDivisor_self : (basisDivisor x x).degree = ⊥ := by rw [basisDivisor_self, degree_zero] theorem natDegree_basisDivisor_self : (basisDivisor x x).natDegree = 0 := by rw [basisDivisor_self, natDegree_zero] theorem natDegree_basisDivisor_of_ne (hxy : x ≠ y) : (basisDivisor x y).natDegree = 1 := natDegree_eq_of_degree_eq_some (degree_basisDivisor_of_ne hxy) @[simp] theorem eval_basisDivisor_right : eval y (basisDivisor x y) = 0 := by simp only [basisDivisor, eval_mul, eval_C, eval_sub, eval_X, sub_self, mul_zero] theorem eval_basisDivisor_left_of_ne (hxy : x ≠ y) : eval x (basisDivisor x y) = 1 := by simp only [basisDivisor, eval_mul, eval_C, eval_sub, eval_X] exact inv_mul_cancel₀ (sub_ne_zero_of_ne hxy) end BasisDivisor section Basis variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι] variable {s : Finset ι} {v : ι → F} {i j : ι} open Finset /-- Lagrange basis polynomials indexed by `s : Finset ι`, defined at nodes `v i` for a map `v : ι → F`. For `i, j ∈ s`, `basis s v i` evaluates to 0 at `v j` for `i ≠ j`. When `v` is injective on `s`, `basis s v i` evaluates to 1 at `v i`. -/ protected def basis (s : Finset ι) (v : ι → F) (i : ι) : F[X] := ∏ j ∈ s.erase i, basisDivisor (v i) (v j) @[simp] theorem basis_empty : Lagrange.basis ∅ v i = 1 := rfl @[simp] theorem basis_singleton (i : ι) : Lagrange.basis {i} v i = 1 := by rw [Lagrange.basis, erase_singleton, prod_empty] @[simp] theorem basis_pair_left (hij : i ≠ j) : Lagrange.basis {i, j} v i = basisDivisor (v i) (v j) := by simp only [Lagrange.basis, hij, erase_insert_eq_erase, erase_eq_of_not_mem, mem_singleton, not_false_iff, prod_singleton] @[simp] theorem basis_pair_right (hij : i ≠ j) : Lagrange.basis {i, j} v j = basisDivisor (v j) (v i) := by rw [pair_comm] exact basis_pair_left hij.symm theorem basis_ne_zero (hvs : Set.InjOn v s) (hi : i ∈ s) : Lagrange.basis s v i ≠ 0 := by simp_rw [Lagrange.basis, prod_ne_zero_iff, Ne, mem_erase] rintro j ⟨hij, hj⟩ rw [basisDivisor_eq_zero_iff, hvs.eq_iff hi hj] exact hij.symm @[simp] theorem eval_basis_self (hvs : Set.InjOn v s) (hi : i ∈ s) : (Lagrange.basis s v i).eval (v i) = 1 := by rw [Lagrange.basis, eval_prod] refine prod_eq_one fun j H => ?_ rw [eval_basisDivisor_left_of_ne] rcases mem_erase.mp H with ⟨hij, hj⟩ exact mt (hvs hi hj) hij.symm @[simp] theorem eval_basis_of_ne (hij : i ≠ j) (hj : j ∈ s) : (Lagrange.basis s v i).eval (v j) = 0 := by simp_rw [Lagrange.basis, eval_prod, prod_eq_zero_iff] exact ⟨j, ⟨mem_erase.mpr ⟨hij.symm, hj⟩, eval_basisDivisor_right⟩⟩ @[simp] theorem natDegree_basis (hvs : Set.InjOn v s) (hi : i ∈ s) : (Lagrange.basis s v i).natDegree = #s - 1 := by have H : ∀ j, j ∈ s.erase i → basisDivisor (v i) (v j) ≠ 0 := by simp_rw [Ne, mem_erase, basisDivisor_eq_zero_iff] exact fun j ⟨hij₁, hj⟩ hij₂ => hij₁ (hvs hj hi hij₂.symm) rw [← card_erase_of_mem hi, card_eq_sum_ones] convert natDegree_prod _ _ H using 1 refine sum_congr rfl fun j hj => (natDegree_basisDivisor_of_ne ?_).symm rw [Ne, ← basisDivisor_eq_zero_iff] exact H _ hj theorem degree_basis (hvs : Set.InjOn v s) (hi : i ∈ s) : (Lagrange.basis s v i).degree = ↑(#s - 1) := by rw [degree_eq_natDegree (basis_ne_zero hvs hi), natDegree_basis hvs hi] theorem sum_basis (hvs : Set.InjOn v s) (hs : s.Nonempty) : ∑ j ∈ s, Lagrange.basis s v j = 1 := by refine eq_of_degrees_lt_of_eval_index_eq s hvs (lt_of_le_of_lt (degree_sum_le _ _) ?_) ?_ ?_ · rw [Nat.cast_withBot, Finset.sup_lt_iff (WithBot.bot_lt_coe #s)] intro i hi rw [degree_basis hvs hi, Nat.cast_withBot, WithBot.coe_lt_coe] exact Nat.pred_lt (card_ne_zero_of_mem hi) · rw [degree_one, ← WithBot.coe_zero, Nat.cast_withBot, WithBot.coe_lt_coe] exact Nonempty.card_pos hs · intro i hi rw [eval_finset_sum, eval_one, ← add_sum_erase _ _ hi, eval_basis_self hvs hi, add_eq_left] refine sum_eq_zero fun j hj => ?_ rcases mem_erase.mp hj with ⟨hij, _⟩ rw [eval_basis_of_ne hij hi] theorem basisDivisor_add_symm {x y : F} (hxy : x ≠ y) : basisDivisor x y + basisDivisor y x = 1 := by classical rw [← sum_basis Function.injective_id.injOn ⟨x, mem_insert_self _ {y}⟩, sum_insert (not_mem_singleton.mpr hxy), sum_singleton, basis_pair_left hxy, basis_pair_right hxy, id, id] end Basis section Interpolate variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι] variable {s t : Finset ι} {i j : ι} {v : ι → F} (r r' : ι → F) open Finset /-- Lagrange interpolation: given a finset `s : Finset ι`, a nodal map `v : ι → F` injective on `s` and a value function `r : ι → F`, `interpolate s v r` is the unique polynomial of degree `< #s` that takes value `r i` on `v i` for all `i` in `s`. -/ @[simps] def interpolate (s : Finset ι) (v : ι → F) : (ι → F) →ₗ[F] F[X] where toFun r := ∑ i ∈ s, C (r i) * Lagrange.basis s v i map_add' f g := by simp_rw [← Finset.sum_add_distrib] have h : (fun x => C (f x) * Lagrange.basis s v x + C (g x) * Lagrange.basis s v x) = (fun x => C ((f + g) x) * Lagrange.basis s v x) := by simp_rw [← add_mul, ← C_add, Pi.add_apply] rw [h] map_smul' c f := by simp_rw [Finset.smul_sum, C_mul', smul_smul, Pi.smul_apply, RingHom.id_apply, smul_eq_mul] theorem interpolate_empty : interpolate ∅ v r = 0 := by rw [interpolate_apply, sum_empty] theorem interpolate_singleton : interpolate {i} v r = C (r i) := by rw [interpolate_apply, sum_singleton, basis_singleton, mul_one] theorem interpolate_one (hvs : Set.InjOn v s) (hs : s.Nonempty) : interpolate s v 1 = 1 := by simp_rw [interpolate_apply, Pi.one_apply, map_one, one_mul] exact sum_basis hvs hs theorem eval_interpolate_at_node (hvs : Set.InjOn v s) (hi : i ∈ s) : eval (v i) (interpolate s v r) = r i := by rw [interpolate_apply, eval_finset_sum, ← add_sum_erase _ _ hi] simp_rw [eval_mul, eval_C, eval_basis_self hvs hi, mul_one, add_eq_left] refine sum_eq_zero fun j H => ?_ rw [eval_basis_of_ne (mem_erase.mp H).1 hi, mul_zero] theorem degree_interpolate_le (hvs : Set.InjOn v s) : (interpolate s v r).degree ≤ ↑(#s - 1) := by refine (degree_sum_le _ _).trans ?_ rw [Finset.sup_le_iff] intro i hi rw [degree_mul, degree_basis hvs hi] by_cases hr : r i = 0 · simpa only [hr, map_zero, degree_zero, WithBot.bot_add] using bot_le · rw [degree_C hr, zero_add] theorem degree_interpolate_lt (hvs : Set.InjOn v s) : (interpolate s v r).degree < #s := by rw [Nat.cast_withBot] rcases eq_empty_or_nonempty s with (rfl | h) · rw [interpolate_empty, degree_zero, card_empty] exact WithBot.bot_lt_coe _ · refine lt_of_le_of_lt (degree_interpolate_le _ hvs) ?_ rw [Nat.cast_withBot, WithBot.coe_lt_coe] exact Nat.sub_lt (Nonempty.card_pos h) zero_lt_one theorem degree_interpolate_erase_lt (hvs : Set.InjOn v s) (hi : i ∈ s) : (interpolate (s.erase i) v r).degree < ↑(#s - 1) := by rw [← Finset.card_erase_of_mem hi] exact degree_interpolate_lt _ (Set.InjOn.mono (coe_subset.mpr (erase_subset _ _)) hvs) theorem values_eq_on_of_interpolate_eq (hvs : Set.InjOn v s) (hrr' : interpolate s v r = interpolate s v r') : ∀ i ∈ s, r i = r' i := fun _ hi => by rw [← eval_interpolate_at_node r hvs hi, hrr', eval_interpolate_at_node r' hvs hi] theorem interpolate_eq_of_values_eq_on (hrr' : ∀ i ∈ s, r i = r' i) : interpolate s v r = interpolate s v r' := sum_congr rfl fun i hi => by rw [hrr' _ hi] theorem interpolate_eq_iff_values_eq_on (hvs : Set.InjOn v s) : interpolate s v r = interpolate s v r' ↔ ∀ i ∈ s, r i = r' i := ⟨values_eq_on_of_interpolate_eq _ _ hvs, interpolate_eq_of_values_eq_on _ _⟩ theorem eq_interpolate {f : F[X]} (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) : f = interpolate s v fun i => f.eval (v i) := eq_of_degrees_lt_of_eval_index_eq _ hvs degree_f_lt (degree_interpolate_lt _ hvs) fun _ hi => (eval_interpolate_at_node (fun x ↦ eval (v x) f) hvs hi).symm theorem eq_interpolate_of_eval_eq {f : F[X]} (hvs : Set.InjOn v s) (degree_f_lt : f.degree < #s) (eval_f : ∀ i ∈ s, f.eval (v i) = r i) : f = interpolate s v r := by rw [eq_interpolate hvs degree_f_lt] exact interpolate_eq_of_values_eq_on _ _ eval_f /-- This is the characteristic property of the interpolation: the interpolation is the unique polynomial of `degree < Fintype.card ι` which takes the value of the `r i` on the `v i`. -/ theorem eq_interpolate_iff {f : F[X]} (hvs : Set.InjOn v s) : (f.degree < #s ∧ ∀ i ∈ s, eval (v i) f = r i) ↔ f = interpolate s v r := by constructor <;> intro h · exact eq_interpolate_of_eval_eq _ hvs h.1 h.2 · rw [h] exact ⟨degree_interpolate_lt _ hvs, fun _ hi => eval_interpolate_at_node _ hvs hi⟩ /-- Lagrange interpolation induces isomorphism between functions from `s` and polynomials of degree less than `Fintype.card ι`. -/ def funEquivDegreeLT (hvs : Set.InjOn v s) : degreeLT F #s ≃ₗ[F] s → F where toFun f i := f.1.eval (v i) map_add' _ _ := funext fun _ => eval_add map_smul' c f := funext <| by simp invFun r := ⟨interpolate s v fun x => if hx : x ∈ s then r ⟨x, hx⟩ else 0, mem_degreeLT.2 <| degree_interpolate_lt _ hvs⟩ left_inv := by rintro ⟨f, hf⟩ simp only [Subtype.mk_eq_mk, Subtype.coe_mk, dite_eq_ite] rw [mem_degreeLT] at hf conv => rhs; rw [eq_interpolate hvs hf] exact interpolate_eq_of_values_eq_on _ _ fun _ hi => if_pos hi right_inv := by intro f ext ⟨i, hi⟩ simp only [Subtype.coe_mk, eval_interpolate_at_node _ hvs hi] exact dif_pos hi theorem interpolate_eq_sum_interpolate_insert_sdiff (hvt : Set.InjOn v t) (hs : s.Nonempty) (hst : s ⊆ t) : interpolate t v r = ∑ i ∈ s, interpolate (insert i (t \ s)) v r * Lagrange.basis s v i := by symm refine eq_interpolate_of_eval_eq _ hvt (lt_of_le_of_lt (degree_sum_le _ _) ?_) fun i hi => ?_ · simp_rw [Nat.cast_withBot, Finset.sup_lt_iff (WithBot.bot_lt_coe #t), degree_mul] intro i hi have hs : 1 ≤ #s := Nonempty.card_pos ⟨_, hi⟩ have hst' : #s ≤ #t := card_le_card hst have H : #t = 1 + (#t - #s) + (#s - 1) := by rw [add_assoc, tsub_add_tsub_cancel hst' hs, ← add_tsub_assoc_of_le (hs.trans hst'), Nat.succ_add_sub_one, zero_add] rw [degree_basis (Set.InjOn.mono hst hvt) hi, H, WithBot.coe_add, Nat.cast_withBot, WithBot.add_lt_add_iff_right (@WithBot.coe_ne_bot _ (#s - 1))] convert degree_interpolate_lt _ (hvt.mono (coe_subset.mpr (insert_subset_iff.mpr ⟨hst hi, sdiff_subset⟩))) rw [card_insert_of_not_mem (not_mem_sdiff_of_mem_right hi), card_sdiff hst, add_comm] · simp_rw [eval_finset_sum, eval_mul] by_cases hi' : i ∈ s · rw [← add_sum_erase _ _ hi', eval_basis_self (hvt.mono hst) hi', eval_interpolate_at_node _ (hvt.mono (coe_subset.mpr (insert_subset_iff.mpr ⟨hi, sdiff_subset⟩))) (mem_insert_self _ _), mul_one, add_eq_left] refine sum_eq_zero fun j hj => ?_ rcases mem_erase.mp hj with ⟨hij, _⟩ rw [eval_basis_of_ne hij hi', mul_zero] · have H : (∑ j ∈ s, eval (v i) (Lagrange.basis s v j)) = 1 := by rw [← eval_finset_sum, sum_basis (hvt.mono hst) hs, eval_one] rw [← mul_one (r i), ← H, mul_sum] refine sum_congr rfl fun j hj => ?_ congr exact eval_interpolate_at_node _ (hvt.mono (insert_subset_iff.mpr ⟨hst hj, sdiff_subset⟩)) (mem_insert.mpr (Or.inr (mem_sdiff.mpr ⟨hi, hi'⟩))) theorem interpolate_eq_add_interpolate_erase (hvs : Set.InjOn v s) (hi : i ∈ s) (hj : j ∈ s) (hij : i ≠ j) : interpolate s v r = interpolate (s.erase j) v r * basisDivisor (v i) (v j) + interpolate (s.erase i) v r * basisDivisor (v j) (v i) := by rw [interpolate_eq_sum_interpolate_insert_sdiff _ hvs ⟨i, mem_insert_self i {j}⟩ _, sum_insert (not_mem_singleton.mpr hij), sum_singleton, basis_pair_left hij, basis_pair_right hij, sdiff_insert_insert_of_mem_of_not_mem hi (not_mem_singleton.mpr hij), sdiff_singleton_eq_erase, pair_comm, sdiff_insert_insert_of_mem_of_not_mem hj (not_mem_singleton.mpr hij.symm), sdiff_singleton_eq_erase] exact insert_subset_iff.mpr ⟨hi, singleton_subset_iff.mpr hj⟩ end Interpolate section Nodal variable {R : Type*} [CommRing R] {ι : Type*} variable {s : Finset ι} {v : ι → R} open Finset Polynomial /-- `nodal s v` is the unique monic polynomial whose roots are the nodes defined by `v` and `s`. That is, the roots of `nodal s v` are exactly the image of `v` on `s`, with appropriate multiplicity. We can use `nodal` to define the barycentric forms of the evaluated interpolant. -/ def nodal (s : Finset ι) (v : ι → R) : R[X] := ∏ i ∈ s, (X - C (v i)) theorem nodal_eq (s : Finset ι) (v : ι → R) : nodal s v = ∏ i ∈ s, (X - C (v i)) := rfl @[simp] theorem nodal_empty : nodal ∅ v = 1 := by rfl @[simp] theorem natDegree_nodal [Nontrivial R] : (nodal s v).natDegree = #s := by simp_rw [nodal, natDegree_prod_of_monic (h := fun i _ => monic_X_sub_C (v i)), natDegree_X_sub_C, sum_const, smul_eq_mul, mul_one] theorem nodal_ne_zero [Nontrivial R] : nodal s v ≠ 0 := by rcases s.eq_empty_or_nonempty with (rfl | h) · exact one_ne_zero · apply ne_zero_of_natDegree_gt (n := 0) simp only [natDegree_nodal, h.card_pos] @[simp] theorem degree_nodal [Nontrivial R] : (nodal s v).degree = #s := by simp_rw [degree_eq_natDegree nodal_ne_zero, natDegree_nodal] theorem nodal_monic : (nodal s v).Monic := monic_prod_of_monic s (fun i ↦ X - C (v i)) fun i _ ↦ monic_X_sub_C (v i) theorem eval_nodal {x : R} : (nodal s v).eval x = ∏ i ∈ s, (x - v i) := by simp_rw [nodal, eval_prod, eval_sub, eval_X, eval_C] theorem eval_nodal_at_node {i : ι} (hi : i ∈ s) : eval (v i) (nodal s v) = 0 := by rw [eval_nodal] exact s.prod_eq_zero hi (sub_self (v i)) theorem eval_nodal_not_at_node [Nontrivial R] [NoZeroDivisors R] {x : R} (hx : ∀ i ∈ s, x ≠ v i) : eval x (nodal s v) ≠ 0 := by simp_rw [nodal, eval_prod, prod_ne_zero_iff, eval_sub, eval_X, eval_C, sub_ne_zero] exact hx theorem nodal_eq_mul_nodal_erase [DecidableEq ι] {i : ι} (hi : i ∈ s) : nodal s v = (X - C (v i)) * nodal (s.erase i) v := by simp_rw [nodal, Finset.mul_prod_erase _ (fun x => X - C (v x)) hi] theorem X_sub_C_dvd_nodal (v : ι → R) {i : ι} (hi : i ∈ s) : X - C (v i) ∣ nodal s v := by classical exact ⟨nodal (s.erase i) v, nodal_eq_mul_nodal_erase hi⟩ theorem nodal_insert_eq_nodal [DecidableEq ι] {i : ι} (hi : i ∉ s) : nodal (insert i s) v = (X - C (v i)) * nodal s v := by simp_rw [nodal, prod_insert hi] theorem derivative_nodal [DecidableEq ι] : derivative (nodal s v) = ∑ i ∈ s, nodal (s.erase i) v := by refine s.induction_on ?_ fun i t hit IH => ?_ · rw [nodal_empty, derivative_one, sum_empty] · rw [nodal_insert_eq_nodal hit, derivative_mul, IH, derivative_sub, derivative_X, derivative_C, sub_zero, one_mul, sum_insert hit, mul_sum, erase_insert hit, add_right_inj] refine sum_congr rfl fun j hjt => ?_ rw [t.erase_insert_of_ne (ne_of_mem_of_not_mem hjt hit).symm, nodal_insert_eq_nodal (mem_of_mem_erase.mt hit)] theorem eval_nodal_derivative_eval_node_eq [DecidableEq ι] {i : ι} (hi : i ∈ s) : eval (v i) (derivative (nodal s v)) = eval (v i) (nodal (s.erase i) v) := by rw [derivative_nodal, eval_finset_sum, ← add_sum_erase _ _ hi, add_eq_left] exact sum_eq_zero fun j hj => (eval_nodal_at_node (mem_erase.mpr ⟨(mem_erase.mp hj).1.symm, hi⟩)) /-- The vanishing polynomial on a multiplicative subgroup is of the form X ^ n - 1. -/ @[simp] theorem nodal_subgroup_eq_X_pow_card_sub_one [IsDomain R] (G : Subgroup Rˣ) [Fintype G] : nodal (G : Set Rˣ).toFinset ((↑) : Rˣ → R) = X ^ (Fintype.card G) - 1 := by have h : degree (1 : R[X]) < degree ((X : R[X]) ^ Fintype.card G) := by simp [Fintype.card_pos] apply eq_of_degree_le_of_eval_index_eq (v := ((↑) : Rˣ → R)) (G : Set Rˣ).toFinset · exact Set.injOn_of_injective Units.ext · simp · rw [degree_sub_eq_left_of_degree_lt h, degree_nodal, Set.toFinset_card, degree_pow, degree_X, nsmul_eq_mul, mul_one, Nat.cast_inj] exact rfl · rw [nodal_monic, leadingCoeff_sub_of_degree_lt h, monic_X_pow] · intros i hi rw [eval_nodal_at_node hi] replace hi : i ∈ G := by simpa using hi obtain ⟨g, rfl⟩ : ∃ g : G, g.val = i := ⟨⟨i, hi⟩, rfl⟩ simp [← Units.val_pow_eq_pow_val, ← Subgroup.coe_pow G] end Nodal section NodalWeight variable {F : Type*} [Field F] {ι : Type*} [DecidableEq ι] variable {s : Finset ι} {v : ι → F} {i : ι} open Finset /-- This defines the nodal weight for a given set of node indexes and node mapping function `v`. -/ def nodalWeight (s : Finset ι) (v : ι → F) (i : ι) := ∏ j ∈ s.erase i, (v i - v j)⁻¹ theorem nodalWeight_eq_eval_nodal_erase_inv : nodalWeight s v i = (eval (v i) (nodal (s.erase i) v))⁻¹ := by rw [eval_nodal, nodalWeight, prod_inv_distrib] theorem nodal_erase_eq_nodal_div (hi : i ∈ s) : nodal (s.erase i) v = nodal s v / (X - C (v i)) := by rw [nodal_eq_mul_nodal_erase hi, mul_div_cancel_left₀] exact X_sub_C_ne_zero _ theorem nodalWeight_eq_eval_nodal_derative (hi : i ∈ s) : nodalWeight s v i = (eval (v i) (Polynomial.derivative (nodal s v)))⁻¹ := by rw [eval_nodal_derivative_eval_node_eq hi, nodalWeight_eq_eval_nodal_erase_inv]
Mathlib/LinearAlgebra/Lagrange.lean
569
571
theorem nodalWeight_ne_zero (hvs : Set.InjOn v s) (hi : i ∈ s) : nodalWeight s v i ≠ 0 := by
rw [nodalWeight, prod_ne_zero_iff] intro j hj
/- Copyright (c) 2020 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Analysis.Asymptotics.Theta /-! # Asymptotic equivalence In this file, we define the relation `IsEquivalent l u v`, which means that `u-v` is little o of `v` along the filter `l`. Unlike `Is(Little|Big)O` relations, this one requires `u` and `v` to have the same codomain `β`. While the definition only requires `β` to be a `NormedAddCommGroup`, most interesting properties require it to be a `NormedField`. ## Notations We introduce the notation `u ~[l] v := IsEquivalent l u v`, which you can use by opening the `Asymptotics` locale. ## Main results If `β` is a `NormedAddCommGroup` : - `_ ~[l] _` is an equivalence relation - Equivalent statements for `u ~[l] const _ c` : - If `c ≠ 0`, this is true iff `Tendsto u l (𝓝 c)` (see `isEquivalent_const_iff_tendsto`) - For `c = 0`, this is true iff `u =ᶠ[l] 0` (see `isEquivalent_zero_iff_eventually_zero`) If `β` is a `NormedField` : - Alternative characterization of the relation (see `isEquivalent_iff_exists_eq_mul`) : `u ~[l] v ↔ ∃ (φ : α → β) (hφ : Tendsto φ l (𝓝 1)), u =ᶠ[l] φ * v` - Provided some non-vanishing hypothesis, this can be seen as `u ~[l] v ↔ Tendsto (u/v) l (𝓝 1)` (see `isEquivalent_iff_tendsto_one`) - For any constant `c`, `u ~[l] v` implies `Tendsto u l (𝓝 c) ↔ Tendsto v l (𝓝 c)` (see `IsEquivalent.tendsto_nhds_iff`) - `*` and `/` are compatible with `_ ~[l] _` (see `IsEquivalent.mul` and `IsEquivalent.div`) If `β` is a `NormedLinearOrderedField` : - If `u ~[l] v`, we have `Tendsto u l atTop ↔ Tendsto v l atTop` (see `IsEquivalent.tendsto_atTop_iff`) ## Implementation Notes Note that `IsEquivalent` takes the parameters `(l : Filter α) (u v : α → β)` in that order. This is to enable `calc` support, as `calc` requires that the last two explicit arguments are `u v`. -/ namespace Asymptotics open Filter Function open Topology section NormedAddCommGroup variable {α β : Type*} [NormedAddCommGroup β] /-- Two functions `u` and `v` are said to be asymptotically equivalent along a filter `l` (denoted as `u ~[l] v` in the `Asymptotics` namespace) when `u x - v x = o(v x)` as `x` converges along `l`. -/ def IsEquivalent (l : Filter α) (u v : α → β) := (u - v) =o[l] v @[inherit_doc] scoped notation:50 u " ~[" l:50 "] " v:50 => Asymptotics.IsEquivalent l u v variable {u v w : α → β} {l : Filter α} theorem IsEquivalent.isLittleO (h : u ~[l] v) : (u - v) =o[l] v := h nonrec theorem IsEquivalent.isBigO (h : u ~[l] v) : u =O[l] v := (IsBigO.congr_of_sub h.isBigO.symm).mp (isBigO_refl _ _) theorem IsEquivalent.isBigO_symm (h : u ~[l] v) : v =O[l] u := by convert h.isLittleO.right_isBigO_add simp theorem IsEquivalent.isTheta (h : u ~[l] v) : u =Θ[l] v := ⟨h.isBigO, h.isBigO_symm⟩ theorem IsEquivalent.isTheta_symm (h : u ~[l] v) : v =Θ[l] u := ⟨h.isBigO_symm, h.isBigO⟩ @[refl] theorem IsEquivalent.refl : u ~[l] u := by rw [IsEquivalent, sub_self] exact isLittleO_zero _ _ @[symm] theorem IsEquivalent.symm (h : u ~[l] v) : v ~[l] u := (h.isLittleO.trans_isBigO h.isBigO_symm).symm @[trans] theorem IsEquivalent.trans {l : Filter α} {u v w : α → β} (huv : u ~[l] v) (hvw : v ~[l] w) : u ~[l] w := (huv.isLittleO.trans_isBigO hvw.isBigO).triangle hvw.isLittleO theorem IsEquivalent.congr_left {u v w : α → β} {l : Filter α} (huv : u ~[l] v) (huw : u =ᶠ[l] w) : w ~[l] v := huv.congr' (huw.sub (EventuallyEq.refl _ _)) (EventuallyEq.refl _ _) theorem IsEquivalent.congr_right {u v w : α → β} {l : Filter α} (huv : u ~[l] v) (hvw : v =ᶠ[l] w) : u ~[l] w := (huv.symm.congr_left hvw).symm theorem isEquivalent_zero_iff_eventually_zero : u ~[l] 0 ↔ u =ᶠ[l] 0 := by rw [IsEquivalent, sub_zero] exact isLittleO_zero_right_iff theorem isEquivalent_zero_iff_isBigO_zero : u ~[l] 0 ↔ u =O[l] (0 : α → β) := by refine ⟨IsEquivalent.isBigO, fun h ↦ ?_⟩ rw [isEquivalent_zero_iff_eventually_zero, eventuallyEq_iff_exists_mem] exact ⟨{ x : α | u x = 0 }, isBigO_zero_right_iff.mp h, fun x hx ↦ hx⟩ theorem isEquivalent_const_iff_tendsto {c : β} (h : c ≠ 0) : u ~[l] const _ c ↔ Tendsto u l (𝓝 c) := by simp +unfoldPartialApp only [IsEquivalent, const, isLittleO_const_iff h] constructor <;> intro h · have := h.sub (tendsto_const_nhds (x := -c)) simp only [Pi.sub_apply, sub_neg_eq_add, sub_add_cancel, zero_add] at this exact this · have := h.sub (tendsto_const_nhds (x := c)) rwa [sub_self] at this
Mathlib/Analysis/Asymptotics/AsymptoticEquivalent.lean
133
136
theorem IsEquivalent.tendsto_const {c : β} (hu : u ~[l] const _ c) : Tendsto u l (𝓝 c) := by
rcases em <| c = 0 with rfl | h · exact (tendsto_congr' <| isEquivalent_zero_iff_eventually_zero.mp hu).mpr tendsto_const_nhds · exact (isEquivalent_const_iff_tendsto h).mp hu
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Mathlib.Data.List.Lemmas import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Data.List.Count import Mathlib.Data.List.Duplicate import Mathlib.Data.List.InsertIdx import Mathlib.Data.List.Induction import Batteries.Data.List.Perm import Mathlib.Data.List.Perm.Basic /-! # Permutations of a list In this file we prove properties about `List.Permutations`, a list of all permutations of a list. It is defined in `Data.List.Defs`. ## Order of the permutations Designed for performance, the order in which the permutations appear in `List.Permutations` is rather intricate and not very amenable to induction. That's why we also provide `List.Permutations'` as a less efficient but more straightforward way of listing permutations. ### `List.Permutations` TODO. In the meantime, you can try decrypting the docstrings. ### `List.Permutations'` The list of partitions is built by recursion. The permutations of `[]` are `[[]]`. Then, the permutations of `a :: l` are obtained by taking all permutations of `l` in order and adding `a` in all positions. Hence, to build `[0, 1, 2, 3].permutations'`, it does * `[[]]` * `[[3]]` * `[[2, 3], [3, 2]]]` * `[[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]` * `[[0, 1, 2, 3], [1, 0, 2, 3], [1, 2, 0, 3], [1, 2, 3, 0],` `[0, 2, 1, 3], [2, 0, 1, 3], [2, 1, 0, 3], [2, 1, 3, 0],` `[0, 2, 3, 1], [2, 0, 3, 1], [2, 3, 0, 1], [2, 3, 1, 0],` `[0, 1, 3, 2], [1, 0, 3, 2], [1, 3, 0, 2], [1, 3, 2, 0],` `[0, 3, 1, 2], [3, 0, 1, 2], [3, 1, 0, 2], [3, 1, 2, 0],` `[0, 3, 2, 1], [3, 0, 2, 1], [3, 2, 0, 1], [3, 2, 1, 0]]` -/ -- Make sure we don't import algebra assert_not_exists Monoid open Nat Function variable {α β : Type*} namespace List theorem permutationsAux2_fst (t : α) (ts : List α) (r : List β) : ∀ (ys : List α) (f : List α → β), (permutationsAux2 t ts r ys f).1 = ys ++ ts | [], _ => rfl | y :: ys, f => by simp [permutationsAux2, permutationsAux2_fst t _ _ ys] @[simp] theorem permutationsAux2_snd_nil (t : α) (ts : List α) (r : List β) (f : List α → β) : (permutationsAux2 t ts r [] f).2 = r := rfl @[simp] theorem permutationsAux2_snd_cons (t : α) (ts : List α) (r : List β) (y : α) (ys : List α) (f : List α → β) : (permutationsAux2 t ts r (y :: ys) f).2 = f (t :: y :: ys ++ ts) :: (permutationsAux2 t ts r ys fun x : List α => f (y :: x)).2 := by simp [permutationsAux2, permutationsAux2_fst t _ _ ys] /-- The `r` argument to `permutationsAux2` is the same as appending. -/ theorem permutationsAux2_append (t : α) (ts : List α) (r : List β) (ys : List α) (f : List α → β) : (permutationsAux2 t ts nil ys f).2 ++ r = (permutationsAux2 t ts r ys f).2 := by induction ys generalizing f <;> simp [*] /-- The `ts` argument to `permutationsAux2` can be folded into the `f` argument. -/ theorem permutationsAux2_comp_append {t : α} {ts ys : List α} {r : List β} (f : List α → β) : ((permutationsAux2 t [] r ys) fun x => f (x ++ ts)).2 = (permutationsAux2 t ts r ys f).2 := by induction' ys with ys_hd _ ys_ih generalizing f · simp · simp [ys_ih fun xs => f (ys_hd :: xs)] theorem map_permutationsAux2' {α' β'} (g : α → α') (g' : β → β') (t : α) (ts ys : List α) (r : List β) (f : List α → β) (f' : List α' → β') (H : ∀ a, g' (f a) = f' (map g a)) : map g' (permutationsAux2 t ts r ys f).2 = (permutationsAux2 (g t) (map g ts) (map g' r) (map g ys) f').2 := by induction' ys with ys_hd _ ys_ih generalizing f f' · simp · simp only [map, permutationsAux2_snd_cons, cons_append, cons.injEq] rw [ys_ih] · refine ⟨?_, rfl⟩ simp only [← map_cons, ← map_append]; apply H · intro a; apply H /-- The `f` argument to `permutationsAux2` when `r = []` can be eliminated. -/ theorem map_permutationsAux2 (t : α) (ts : List α) (ys : List α) (f : List α → β) : (permutationsAux2 t ts [] ys id).2.map f = (permutationsAux2 t ts [] ys f).2 := by rw [map_permutationsAux2' id, map_id, map_id] · rfl simp /-- An expository lemma to show how all of `ts`, `r`, and `f` can be eliminated from `permutationsAux2`. `(permutationsAux2 t [] [] ys id).2`, which appears on the RHS, is a list whose elements are produced by inserting `t` into every non-terminal position of `ys` in order. As an example: ```lean #eval permutationsAux2 1 [] [] [2, 3, 4] id -- [[1, 2, 3, 4], [2, 1, 3, 4], [2, 3, 1, 4]] ``` -/ theorem permutationsAux2_snd_eq (t : α) (ts : List α) (r : List β) (ys : List α) (f : List α → β) : (permutationsAux2 t ts r ys f).2 = ((permutationsAux2 t [] [] ys id).2.map fun x => f (x ++ ts)) ++ r := by rw [← permutationsAux2_append, map_permutationsAux2, permutationsAux2_comp_append] theorem map_map_permutationsAux2 {α'} (g : α → α') (t : α) (ts ys : List α) : map (map g) (permutationsAux2 t ts [] ys id).2 = (permutationsAux2 (g t) (map g ts) [] (map g ys) id).2 := map_permutationsAux2' _ _ _ _ _ _ _ _ fun _ => rfl theorem map_map_permutations'Aux (f : α → β) (t : α) (ts : List α) : map (map f) (permutations'Aux t ts) = permutations'Aux (f t) (map f ts) := by induction' ts with a ts ih · rfl · simp only [permutations'Aux, map_cons, map_map, ← ih, cons.injEq, true_and, Function.comp_def] theorem permutations'Aux_eq_permutationsAux2 (t : α) (ts : List α) : permutations'Aux t ts = (permutationsAux2 t [] [ts ++ [t]] ts id).2 := by induction' ts with a ts ih; · rfl simp only [permutations'Aux, ih, cons_append, permutationsAux2_snd_cons, append_nil, id_eq, cons.injEq, true_and] simp +singlePass only [← permutationsAux2_append] simp [map_permutationsAux2] theorem mem_permutationsAux2 {t : α} {ts : List α} {ys : List α} {l l' : List α} : l' ∈ (permutationsAux2 t ts [] ys (l ++ ·)).2 ↔ ∃ l₁ l₂, l₂ ≠ [] ∧ ys = l₁ ++ l₂ ∧ l' = l ++ l₁ ++ t :: l₂ ++ ts := by induction' ys with y ys ih generalizing l · simp +contextual rw [permutationsAux2_snd_cons, show (fun x : List α => l ++ y :: x) = (l ++ [y] ++ ·) by funext _; simp, mem_cons, ih] constructor · rintro (rfl | ⟨l₁, l₂, l0, rfl, rfl⟩) · exact ⟨[], y :: ys, by simp⟩ · exact ⟨y :: l₁, l₂, l0, by simp⟩ · rintro ⟨_ | ⟨y', l₁⟩, l₂, l0, ye, rfl⟩ · simp [ye] · simp only [cons_append] at ye rcases ye with ⟨rfl, rfl⟩ exact Or.inr ⟨l₁, l₂, l0, by simp⟩ theorem mem_permutationsAux2' {t : α} {ts : List α} {ys : List α} {l : List α} : l ∈ (permutationsAux2 t ts [] ys id).2 ↔ ∃ l₁ l₂, l₂ ≠ [] ∧ ys = l₁ ++ l₂ ∧ l = l₁ ++ t :: l₂ ++ ts := by rw [show @id (List α) = ([] ++ ·) by funext _; rfl]; apply mem_permutationsAux2 theorem length_permutationsAux2 (t : α) (ts : List α) (ys : List α) (f : List α → β) : length (permutationsAux2 t ts [] ys f).2 = length ys := by induction ys generalizing f <;> simp [*] theorem foldr_permutationsAux2 (t : α) (ts : List α) (r L : List (List α)) : foldr (fun y r => (permutationsAux2 t ts r y id).2) r L = (L.flatMap fun y => (permutationsAux2 t ts [] y id).2) ++ r := by induction' L with l L ih · rfl · simp_rw [foldr_cons, ih, flatMap_cons, append_assoc, permutationsAux2_append] theorem mem_foldr_permutationsAux2 {t : α} {ts : List α} {r L : List (List α)} {l' : List α} : l' ∈ foldr (fun y r => (permutationsAux2 t ts r y id).2) r L ↔ l' ∈ r ∨ ∃ l₁ l₂, l₁ ++ l₂ ∈ L ∧ l₂ ≠ [] ∧ l' = l₁ ++ t :: l₂ ++ ts := by have : (∃ a : List α, a ∈ L ∧ ∃ l₁ l₂ : List α, ¬l₂ = nil ∧ a = l₁ ++ l₂ ∧ l' = l₁ ++ t :: (l₂ ++ ts)) ↔ ∃ l₁ l₂ : List α, ¬l₂ = nil ∧ l₁ ++ l₂ ∈ L ∧ l' = l₁ ++ t :: (l₂ ++ ts) := ⟨fun ⟨_, aL, l₁, l₂, l0, e, h⟩ => ⟨l₁, l₂, l0, e ▸ aL, h⟩, fun ⟨l₁, l₂, l0, aL, h⟩ => ⟨_, aL, l₁, l₂, l0, rfl, h⟩⟩ rw [foldr_permutationsAux2] simp only [mem_permutationsAux2', ← this, or_comm, and_left_comm, mem_append, mem_flatMap, append_assoc, cons_append, exists_prop] theorem length_foldr_permutationsAux2 (t : α) (ts : List α) (r L : List (List α)) : length (foldr (fun y r => (permutationsAux2 t ts r y id).2) r L) = (map length L).sum + length r := by simp [foldr_permutationsAux2, Function.comp_def, length_permutationsAux2, length_flatMap] theorem length_foldr_permutationsAux2' (t : α) (ts : List α) (r L : List (List α)) (n) (H : ∀ l ∈ L, length l = n) : length (foldr (fun y r => (permutationsAux2 t ts r y id).2) r L) = n * length L + length r := by rw [length_foldr_permutationsAux2, (_ : (map length L).sum = n * length L)] induction' L with l L ih · simp have sum_map : (map length L).sum = n * length L := ih fun l m => H l (mem_cons_of_mem _ m) have length_l : length l = n := H _ mem_cons_self simp [sum_map, length_l, Nat.mul_add, Nat.add_comm, mul_succ] @[simp] theorem permutationsAux_nil (is : List α) : permutationsAux [] is = [] := by rw [permutationsAux, permutationsAux.rec] @[simp] theorem permutationsAux_cons (t : α) (ts is : List α) : permutationsAux (t :: ts) is = foldr (fun y r => (permutationsAux2 t ts r y id).2) (permutationsAux ts (t :: is)) (permutations is) := by rw [permutationsAux, permutationsAux.rec]; rfl @[simp] theorem permutations_nil : permutations ([] : List α) = [[]] := by rw [permutations, permutationsAux_nil] theorem map_permutationsAux (f : α → β) : ∀ ts is : List α, map (map f) (permutationsAux ts is) = permutationsAux (map f ts) (map f is) := by refine permutationsAux.rec (by simp) ?_ introv IH1 IH2; rw [map] at IH2 simp only [foldr_permutationsAux2, map_append, map, map_map_permutationsAux2, permutations, flatMap_map, IH1, append_assoc, permutationsAux_cons, flatMap_cons, ← IH2, map_flatMap] theorem map_permutations (f : α → β) (ts : List α) : map (map f) (permutations ts) = permutations (map f ts) := by rw [permutations, permutations, map, map_permutationsAux, map] theorem map_permutations' (f : α → β) (ts : List α) : map (map f) (permutations' ts) = permutations' (map f ts) := by induction' ts with t ts ih <;> [rfl; simp [← ih, map_flatMap, ← map_map_permutations'Aux, flatMap_map]] theorem permutationsAux_append (is is' ts : List α) : permutationsAux (is ++ ts) is' = (permutationsAux is is').map (· ++ ts) ++ permutationsAux ts (is.reverse ++ is') := by induction' is with t is ih generalizing is'; · simp simp only [foldr_permutationsAux2, ih, map_flatMap, cons_append, permutationsAux_cons, map_append, reverse_cons, append_assoc, singleton_append] congr 2 funext _ rw [map_permutationsAux2] simp +singlePass only [← permutationsAux2_comp_append] simp only [id, append_assoc]
Mathlib/Data/List/Permutation.lean
244
246
theorem permutations_append (is ts : List α) : permutations (is ++ ts) = (permutations is).map (· ++ ts) ++ permutationsAux ts is.reverse := by
simp [permutations, permutationsAux_append]
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.MeasureTheory.Measure.FiniteMeasure import Mathlib.MeasureTheory.Integral.Average import Mathlib.MeasureTheory.Measure.Prod /-! # Probability measures This file defines the type of probability measures on a given measurable space. When the underlying space has a topology and the measurable space structure (sigma algebra) is finer than the Borel sigma algebra, then the type of probability measures is equipped with the topology of convergence in distribution (weak convergence of measures). The topology of convergence in distribution is the coarsest topology w.r.t. which for every bounded continuous `ℝ≥0`-valued random variable `X`, the expected value of `X` depends continuously on the choice of probability measure. This is a special case of the topology of weak convergence of finite measures. ## Main definitions The main definitions are * the type `MeasureTheory.ProbabilityMeasure Ω` with the topology of convergence in distribution (a.k.a. convergence in law, weak convergence of measures); * `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`: Interpret a probability measure as a finite measure; * `MeasureTheory.FiniteMeasure.normalize`: Normalize a finite measure to a probability measure (returns junk for the zero measure). * `MeasureTheory.ProbabilityMeasure.map`: The push-forward `f* μ` of a probability measure `μ` on `Ω` along a measurable function `f : Ω → Ω'`. ## Main results * `MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of probability measures is characterized by the convergence of expected values of all bounded continuous random variables. This shows that the chosen definition of topology coincides with the common textbook definition of convergence in distribution, i.e., weak convergence of measures. A similar characterization by the convergence of expected values (in the `MeasureTheory.lintegral` sense) of all bounded continuous nonnegative random variables is `MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto`. * `MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`: The convergence of finite measures to a nonzero limit is characterized by the convergence of the probability-normalized versions and of the total masses. * `MeasureTheory.ProbabilityMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the push-forward of probability measures `f* : ProbabilityMeasure Ω → ProbabilityMeasure Ω'` is continuous. * `MeasureTheory.ProbabilityMeasure.t2Space`: The topology of convergence in distribution is Hausdorff on Borel spaces where indicators of closed sets have continuous decreasing approximating sequences (in particular on any pseudo-metrizable spaces). TODO: * Probability measures form a convex space. ## Implementation notes The topology of convergence in distribution on `MeasureTheory.ProbabilityMeasure Ω` is inherited weak convergence of finite measures via the mapping `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. Like `MeasureTheory.FiniteMeasure Ω`, the implementation of `MeasureTheory.ProbabilityMeasure Ω` is directly as a subtype of `MeasureTheory.Measure Ω`, and the coercion to a function is the composition `ENNReal.toNNReal` and the coercion to function of `MeasureTheory.Measure Ω`. ## References * [Billingsley, *Convergence of probability measures*][billingsley1999] ## Tags convergence in distribution, convergence in law, weak convergence of measures, probability measure -/ noncomputable section open Set Filter BoundedContinuousFunction Topology open scoped ENNReal NNReal namespace MeasureTheory section ProbabilityMeasure /-! ### Probability measures In this section we define the type of probability measures on a measurable space `Ω`, denoted by `MeasureTheory.ProbabilityMeasure Ω`. If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.ProbabilityMeasure Ω` is equipped with the topology of weak convergence of measures. Since every probability measure is a finite measure, this is implemented as the induced topology from the mapping `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. -/ /-- Probability measures are defined as the subtype of measures that have the property of being probability measures (i.e., their total mass is one). -/ def ProbabilityMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ := { μ : Measure Ω // IsProbabilityMeasure μ } namespace ProbabilityMeasure variable {Ω : Type*} [MeasurableSpace Ω] instance [Inhabited Ω] : Inhabited (ProbabilityMeasure Ω) := ⟨⟨Measure.dirac default, Measure.dirac.isProbabilityMeasure⟩⟩ /-- Coercion from `MeasureTheory.ProbabilityMeasure Ω` to `MeasureTheory.Measure Ω`. -/ @[coe] def toMeasure : ProbabilityMeasure Ω → Measure Ω := Subtype.val /-- A probability measure can be interpreted as a measure. -/ instance : Coe (ProbabilityMeasure Ω) (MeasureTheory.Measure Ω) := { coe := toMeasure } instance (μ : ProbabilityMeasure Ω) : IsProbabilityMeasure (μ : Measure Ω) := μ.prop @[simp, norm_cast] lemma coe_mk (μ : Measure Ω) (hμ) : toMeasure ⟨μ, hμ⟩ = μ := rfl @[simp] theorem val_eq_to_measure (ν : ProbabilityMeasure Ω) : ν.val = (ν : Measure Ω) := rfl theorem toMeasure_injective : Function.Injective ((↑) : ProbabilityMeasure Ω → Measure Ω) := Subtype.coe_injective instance instFunLike : FunLike (ProbabilityMeasure Ω) (Set Ω) ℝ≥0 where coe μ s := ((μ : Measure Ω) s).toNNReal coe_injective' μ ν h := toMeasure_injective <| Measure.ext fun s _ ↦ by simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s lemma coeFn_def (μ : ProbabilityMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl lemma coeFn_mk (μ : Measure Ω) (hμ) : DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl @[simp, norm_cast] lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) : DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl @[simp, norm_cast] theorem coeFn_univ (ν : ProbabilityMeasure Ω) : ν univ = 1 := congr_arg ENNReal.toNNReal ν.prop.measure_univ theorem coeFn_univ_ne_zero (ν : ProbabilityMeasure Ω) : ν univ ≠ 0 := by simp only [coeFn_univ, Ne, one_ne_zero, not_false_iff] /-- A probability measure can be interpreted as a finite measure. -/ def toFiniteMeasure (μ : ProbabilityMeasure Ω) : FiniteMeasure Ω := ⟨μ, inferInstance⟩ @[simp] lemma coeFn_toFiniteMeasure (μ : ProbabilityMeasure Ω) : ⇑μ.toFiniteMeasure = μ := rfl lemma toFiniteMeasure_apply (μ : ProbabilityMeasure Ω) (s : Set Ω) : μ.toFiniteMeasure s = μ s := rfl @[simp] theorem toMeasure_comp_toFiniteMeasure_eq_toMeasure (ν : ProbabilityMeasure Ω) : (ν.toFiniteMeasure : Measure Ω) = (ν : Measure Ω) := rfl @[simp] theorem coeFn_comp_toFiniteMeasure_eq_coeFn (ν : ProbabilityMeasure Ω) : (ν.toFiniteMeasure : Set Ω → ℝ≥0) = (ν : Set Ω → ℝ≥0) := rfl @[simp] theorem toFiniteMeasure_apply_eq_apply (ν : ProbabilityMeasure Ω) (s : Set Ω) : ν.toFiniteMeasure s = ν s := rfl @[simp] theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : ProbabilityMeasure Ω) (s : Set Ω) : (ν s : ℝ≥0∞) = (ν : Measure Ω) s := by rw [← coeFn_comp_toFiniteMeasure_eq_coeFn, FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure, toMeasure_comp_toFiniteMeasure_eq_toMeasure] @[simp] theorem null_iff_toMeasure_null (ν : ProbabilityMeasure Ω) (s : Set Ω) : ν s = 0 ↔ (ν : Measure Ω) s = 0 := ⟨fun h ↦ by rw [← ennreal_coeFn_eq_coeFn_toMeasure, h, ENNReal.coe_zero], fun h ↦ congrArg ENNReal.toNNReal h⟩ theorem apply_mono (μ : ProbabilityMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by rw [← coeFn_comp_toFiniteMeasure_eq_coeFn] exact MeasureTheory.FiniteMeasure.apply_mono _ h /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the limit of the measures of the partial unions. -/ protected lemma tendsto_measure_iUnion_accumulate {ι : Type*} [Preorder ι] [IsCountablyGenerated (atTop : Filter ι)] {μ : ProbabilityMeasure Ω} {f : ι → Set Ω} : Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by simpa [← ennreal_coeFn_eq_coeFn_toMeasure, ENNReal.tendsto_coe] using tendsto_measure_iUnion_accumulate (μ := μ.toMeasure) @[simp] theorem apply_le_one (μ : ProbabilityMeasure Ω) (s : Set Ω) : μ s ≤ 1 := by simpa using apply_mono μ (subset_univ s) theorem nonempty (μ : ProbabilityMeasure Ω) : Nonempty Ω := by by_contra maybe_empty have zero : (μ : Measure Ω) univ = 0 := by rw [univ_eq_empty_iff.mpr (not_nonempty_iff.mp maybe_empty), measure_empty] rw [measure_univ] at zero exact zero_ne_one zero.symm @[ext] theorem eq_of_forall_toMeasure_apply_eq (μ ν : ProbabilityMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by apply toMeasure_injective ext1 s s_mble exact h s s_mble theorem eq_of_forall_apply_eq (μ ν : ProbabilityMeasure Ω) (h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by ext1 s s_mble simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble) @[simp] theorem mass_toFiniteMeasure (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.mass = 1 := μ.coeFn_univ theorem toFiniteMeasure_nonzero (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure ≠ 0 := by simp [← FiniteMeasure.mass_nonzero_iff] /-- The type of probability measures is a measurable space when equipped with the Giry monad. -/ instance : MeasurableSpace (ProbabilityMeasure Ω) := Subtype.instMeasurableSpace lemma measurableSet_isProbabilityMeasure : MeasurableSet { μ : Measure Ω | IsProbabilityMeasure μ } := by suffices { μ : Measure Ω | IsProbabilityMeasure μ } = (fun μ => μ univ) ⁻¹' {1} by rw [this] exact Measure.measurable_coe MeasurableSet.univ (measurableSet_singleton 1) ext _ apply isProbabilityMeasure_iff /-- The monoidal product is a measurable function from the product of probability spaces over `α` and `β` into the type of probability spaces over `α × β`. Lemma 4.1 of [A synthetic approach to Markov kernels, conditional independence and theorems on sufficient statistics][fritz2020]. -/ theorem measurable_prod {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] : Measurable (fun (μ : ProbabilityMeasure α × ProbabilityMeasure β) ↦ μ.1.toMeasure.prod μ.2.toMeasure) := by apply Measurable.measure_of_isPiSystem_of_isProbabilityMeasure generateFrom_prod.symm isPiSystem_prod _ simp only [mem_image2, mem_setOf_eq, forall_exists_index, and_imp] intros _ u Hu v Hv Heq simp_rw [← Heq, Measure.prod_prod] apply Measurable.mul · exact (Measure.measurable_coe Hu).comp (measurable_subtype_coe.comp measurable_fst) · exact (Measure.measurable_coe Hv).comp (measurable_subtype_coe.comp measurable_snd) section convergence_in_distribution variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω] theorem testAgainstNN_lipschitz (μ : ProbabilityMeasure Ω) : LipschitzWith 1 fun f : Ω →ᵇ ℝ≥0 ↦ μ.toFiniteMeasure.testAgainstNN f := μ.mass_toFiniteMeasure ▸ μ.toFiniteMeasure.testAgainstNN_lipschitz /-- The topology of weak convergence on `MeasureTheory.ProbabilityMeasure Ω`. This is inherited (induced) from the topology of weak convergence of finite measures via the inclusion `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. -/ instance : TopologicalSpace (ProbabilityMeasure Ω) := TopologicalSpace.induced toFiniteMeasure inferInstance theorem toFiniteMeasure_continuous : Continuous (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) := continuous_induced_dom /-- Probability measures yield elements of the `WeakDual` of bounded continuous nonnegative functions via `MeasureTheory.FiniteMeasure.testAgainstNN`, i.e., integration. -/ def toWeakDualBCNN : ProbabilityMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) := FiniteMeasure.toWeakDualBCNN ∘ toFiniteMeasure @[simp] theorem coe_toWeakDualBCNN (μ : ProbabilityMeasure Ω) : ⇑μ.toWeakDualBCNN = μ.toFiniteMeasure.testAgainstNN := rfl @[simp] theorem toWeakDualBCNN_apply (μ : ProbabilityMeasure Ω) (f : Ω →ᵇ ℝ≥0) : μ.toWeakDualBCNN f = (∫⁻ ω, f ω ∂(μ : Measure Ω)).toNNReal := rfl theorem toWeakDualBCNN_continuous : Continuous fun μ : ProbabilityMeasure Ω ↦ μ.toWeakDualBCNN := FiniteMeasure.toWeakDualBCNN_continuous.comp toFiniteMeasure_continuous /- Integration of (nonnegative bounded continuous) test functions against Borel probability measures depends continuously on the measure. -/ theorem continuous_testAgainstNN_eval (f : Ω →ᵇ ℝ≥0) : Continuous fun μ : ProbabilityMeasure Ω ↦ μ.toFiniteMeasure.testAgainstNN f := (FiniteMeasure.continuous_testAgainstNN_eval f).comp toFiniteMeasure_continuous -- The canonical mapping from probability measures to finite measures is an embedding. theorem toFiniteMeasure_isEmbedding (Ω : Type*) [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω] : IsEmbedding (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) where eq_induced := rfl injective _μ _ν h := Subtype.eq <| congr_arg FiniteMeasure.toMeasure h @[deprecated (since := "2024-10-26")] alias toFiniteMeasure_embedding := toFiniteMeasure_isEmbedding theorem tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds {δ : Type*} (F : Filter δ) {μs : δ → ProbabilityMeasure Ω} {μ₀ : ProbabilityMeasure Ω} : Tendsto μs F (𝓝 μ₀) ↔ Tendsto (toFiniteMeasure ∘ μs) F (𝓝 μ₀.toFiniteMeasure) := (toFiniteMeasure_isEmbedding Ω).tendsto_nhds_iff /-- A characterization of weak convergence of probability measures by the condition that the integrals of every continuous bounded nonnegative function converge to the integral of the function against the limit measure. -/
Mathlib/MeasureTheory/Measure/ProbabilityMeasure.lean
305
311
theorem tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} : Tendsto μs F (𝓝 μ) ↔ ∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i ↦ ∫⁻ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫⁻ ω, f ω ∂(μ : Measure Ω))) := by
rw [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds] exact FiniteMeasure.tendsto_iff_forall_lintegral_tendsto
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Manuel Candales -/ import Mathlib.Analysis.InnerProductSpace.Subspace import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse /-! # Angles between vectors This file defines unoriented angles in real inner product spaces. ## Main definitions * `InnerProductGeometry.angle` is the undirected angle between two vectors. ## TODO Prove the triangle inequality for the angle. -/ assert_not_exists HasFDerivAt ConformalAt noncomputable section open Real Set open Real open RealInnerProductSpace namespace InnerProductGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] {x y : V} /-- The undirected angle between two vectors. If either vector is 0, this is π/2. See `Orientation.oangle` for the corresponding oriented angle definition. -/ def angle (x y : V) : ℝ := Real.arccos (⟪x, y⟫ / (‖x‖ * ‖y‖)) theorem continuousAt_angle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => angle y.1 y.2) x := by unfold angle fun_prop (disch := simp [*])
Mathlib/Geometry/Euclidean/Angle/Unoriented/Basic.lean
49
54
theorem angle_smul_smul {c : ℝ} (hc : c ≠ 0) (x y : V) : angle (c • x) (c • y) = angle x y := by
have : c * c ≠ 0 := mul_ne_zero hc hc rw [angle, angle, real_inner_smul_left, inner_smul_right, norm_smul, norm_smul, Real.norm_eq_abs, mul_mul_mul_comm _ ‖x‖, abs_mul_abs_self, ← mul_assoc c c, mul_div_mul_left _ _ this] @[simp]
/- Copyright (c) 2023 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.Analysis.Calculus.FDeriv.Pi import Mathlib.Analysis.Calculus.Deriv.Basic /-! # One-dimensional derivatives on pi-types. -/ variable {𝕜 ι : Type*} [DecidableEq ι] [Fintype ι] [NontriviallyNormedField 𝕜]
Mathlib/Analysis/Calculus/Deriv/Pi.lean
15
22
theorem hasDerivAt_update (x : ι → 𝕜) (i : ι) (y : 𝕜) : HasDerivAt (Function.update x i) (Pi.single i (1 : 𝕜)) y := by
convert (hasFDerivAt_update x y).hasDerivAt ext z j rw [Pi.single, Function.update_apply] split_ifs with h · simp [h] · simp [Pi.single_eq_of_ne h]
/- Copyright (c) 2020 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Computation.Approximations import Mathlib.Algebra.ContinuedFractions.Computation.CorrectnessTerminating import Mathlib.Data.Rat.Floor /-! # Termination of Continued Fraction Computations (`GenContFract.of`) ## Summary We show that the continued fraction for a value `v`, as defined in `Mathlib.Algebra.ContinuedFractions.Basic`, terminates if and only if `v` corresponds to a rational number, that is `↑v = q` for some `q : ℚ`. ## Main Theorems - `GenContFract.coe_of_rat_eq` shows that `GenContFract.of v = GenContFract.of q` for `v : α` given that `↑v = q` and `q : ℚ`. - `GenContFract.terminates_iff_rat` shows that `GenContFract.of v` terminates if and only if `↑v = q` for some `q : ℚ`. ## Tags rational, continued fraction, termination -/ namespace GenContFract open GenContFract (of) variable {K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [FloorRing K] /- We will have to constantly coerce along our structures in the following proofs using their provided map functions. -/ attribute [local simp] Pair.map IntFractPair.mapFr section RatOfTerminates /-! ### Terminating Continued Fractions Are Rational We want to show that the computation of a continued fraction `GenContFract.of v` terminates if and only if `v ∈ ℚ`. In this section, we show the implication from left to right. We first show that every finite convergent corresponds to a rational number `q` and then use the finite correctness proof (`of_correctness_of_terminates`) of `GenContFract.of` to show that `v = ↑q`. -/ variable (v : K) (n : ℕ) nonrec theorem exists_gcf_pair_rat_eq_of_nth_contsAux : ∃ conts : Pair ℚ, (of v).contsAux n = (conts.map (↑) : Pair K) := Nat.strong_induction_on n (by clear n let g := of v intro n IH rcases n with (_ | _ | n) -- n = 0 · suffices ∃ gp : Pair ℚ, Pair.mk (1 : K) 0 = gp.map (↑) by simpa [contsAux] use Pair.mk 1 0 simp -- n = 1 · suffices ∃ conts : Pair ℚ, Pair.mk g.h 1 = conts.map (↑) by simpa [contsAux] use Pair.mk ⌊v⌋ 1 simp [g] -- 2 ≤ n · obtain ⟨pred_conts, pred_conts_eq⟩ := IH (n + 1) <| lt_add_one (n + 1) -- invoke the IH rcases s_ppred_nth_eq : g.s.get? n with gp_n | gp_n -- option.none · use pred_conts have : g.contsAux (n + 2) = g.contsAux (n + 1) := contsAux_stable_of_terminated (n + 1).le_succ s_ppred_nth_eq simp only [g, this, pred_conts_eq] -- option.some · -- invoke the IH a second time obtain ⟨ppred_conts, ppred_conts_eq⟩ := IH n <| lt_of_le_of_lt n.le_succ <| lt_add_one <| n + 1 obtain ⟨a_eq_one, z, b_eq_z⟩ : gp_n.a = 1 ∧ ∃ z : ℤ, gp_n.b = (z : K) := of_partNum_eq_one_and_exists_int_partDen_eq s_ppred_nth_eq -- finally, unfold the recurrence to obtain the required rational value. simp only [g, a_eq_one, b_eq_z, contsAux_recurrence s_ppred_nth_eq ppred_conts_eq pred_conts_eq] use nextConts 1 (z : ℚ) ppred_conts pred_conts cases ppred_conts; cases pred_conts simp [nextConts, nextNum, nextDen]) theorem exists_gcf_pair_rat_eq_nth_conts : ∃ conts : Pair ℚ, (of v).conts n = (conts.map (↑) : Pair K) := by rw [nth_cont_eq_succ_nth_contAux]; exact exists_gcf_pair_rat_eq_of_nth_contsAux v <| n + 1
Mathlib/Algebra/ContinuedFractions/Computation/TerminatesIffRat.lean
101
103
theorem exists_rat_eq_nth_num : ∃ q : ℚ, (of v).nums n = (q : K) := by
rcases exists_gcf_pair_rat_eq_nth_conts v n with ⟨⟨a, _⟩, nth_cont_eq⟩ use a
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Analysis.Normed.Module.Convex /-! # Sides of affine subspaces This file defines notions of two points being on the same or opposite sides of an affine subspace. ## Main definitions * `s.WSameSide x y`: The points `x` and `y` are weakly on the same side of the affine subspace `s`. * `s.SSameSide x y`: The points `x` and `y` are strictly on the same side of the affine subspace `s`. * `s.WOppSide x y`: The points `x` and `y` are weakly on opposite sides of the affine subspace `s`. * `s.SOppSide x y`: The points `x` and `y` are strictly on opposite sides of the affine subspace `s`. -/ variable {R V V' P P' : Type*} open AffineEquiv AffineMap namespace AffineSubspace section StrictOrderedCommRing variable [CommRing R] [PartialOrder R] [IsStrictOrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The points `x` and `y` are weakly on the same side of `s`. -/ def WSameSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (y -ᵥ p₂) /-- The points `x` and `y` are strictly on the same side of `s`. -/ def SSameSide (s : AffineSubspace R P) (x y : P) : Prop := s.WSameSide x y ∧ x ∉ s ∧ y ∉ s /-- The points `x` and `y` are weakly on opposite sides of `s`. -/ def WOppSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) /-- The points `x` and `y` are strictly on opposite sides of `s`. -/ def SOppSide (s : AffineSubspace R P) (x y : P) : Prop := s.WOppSide x y ∧ x ∉ s ∧ y ∉ s theorem WSameSide.map {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) (f : P →ᵃ[R] P') : (s.map f).WSameSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WSameSide (f x) (f y) ↔ s.WSameSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h theorem _root_.Function.Injective.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).SSameSide (f x) (f y) ↔ s.SSameSide x y := by simp_rw [SSameSide, hf.wSameSide_map_iff, mem_map_iff_mem_of_injective hf] @[simp] theorem _root_.AffineEquiv.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).WSameSide (f x) (f y) ↔ s.WSameSide x y := (show Function.Injective f.toAffineMap from f.injective).wSameSide_map_iff @[simp] theorem _root_.AffineEquiv.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).SSameSide (f x) (f y) ↔ s.SSameSide x y := (show Function.Injective f.toAffineMap from f.injective).sSameSide_map_iff theorem WOppSide.map {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) (f : P →ᵃ[R] P') : (s.map f).WOppSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WOppSide (f x) (f y) ↔ s.WOppSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h theorem _root_.Function.Injective.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).SOppSide (f x) (f y) ↔ s.SOppSide x y := by simp_rw [SOppSide, hf.wOppSide_map_iff, mem_map_iff_mem_of_injective hf] @[simp] theorem _root_.AffineEquiv.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).WOppSide (f x) (f y) ↔ s.WOppSide x y := (show Function.Injective f.toAffineMap from f.injective).wOppSide_map_iff @[simp] theorem _root_.AffineEquiv.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).SOppSide (f x) (f y) ↔ s.SOppSide x y := (show Function.Injective f.toAffineMap from f.injective).sOppSide_map_iff theorem WSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ theorem SSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ theorem WOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ theorem SOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ theorem SSameSide.wSameSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : s.WSameSide x y := h.1 theorem SSameSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : x ∉ s := h.2.1 theorem SSameSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : y ∉ s := h.2.2 theorem SOppSide.wOppSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : s.WOppSide x y := h.1 theorem SOppSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : x ∉ s := h.2.1 theorem SOppSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : y ∉ s := h.2.2 theorem wSameSide_comm {s : AffineSubspace R P} {x y : P} : s.WSameSide x y ↔ s.WSameSide y x := ⟨fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩, fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩⟩ alias ⟨WSameSide.symm, _⟩ := wSameSide_comm theorem sSameSide_comm {s : AffineSubspace R P} {x y : P} : s.SSameSide x y ↔ s.SSameSide y x := by rw [SSameSide, SSameSide, wSameSide_comm, and_comm (b := x ∉ s)] alias ⟨SSameSide.symm, _⟩ := sSameSide_comm theorem wOppSide_comm {s : AffineSubspace R P} {x y : P} : s.WOppSide x y ↔ s.WOppSide y x := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] alias ⟨WOppSide.symm, _⟩ := wOppSide_comm theorem sOppSide_comm {s : AffineSubspace R P} {x y : P} : s.SOppSide x y ↔ s.SOppSide y x := by rw [SOppSide, SOppSide, wOppSide_comm, and_comm (b := x ∉ s)] alias ⟨SOppSide.symm, _⟩ := sOppSide_comm theorem not_wSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WSameSide x y := fun ⟨_, h, _⟩ => h.elim theorem not_sSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).SSameSide x y := fun h => not_wSameSide_bot x y h.wSameSide theorem not_wOppSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WOppSide x y := fun ⟨_, h, _⟩ => h.elim theorem not_sOppSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).SOppSide x y := fun h => not_wOppSide_bot x y h.wOppSide @[simp] theorem wSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.WSameSide x x ↔ (s : Set P).Nonempty := ⟨fun h => h.nonempty, fun ⟨p, hp⟩ => ⟨p, hp, p, hp, SameRay.rfl⟩⟩ theorem sSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.SSameSide x x ↔ (s : Set P).Nonempty ∧ x ∉ s := ⟨fun ⟨h, hx, _⟩ => ⟨wSameSide_self_iff.1 h, hx⟩, fun ⟨h, hx⟩ => ⟨wSameSide_self_iff.2 h, hx, hx⟩⟩ theorem wSameSide_of_left_mem {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WSameSide x y := by refine ⟨x, hx, x, hx, ?_⟩ rw [vsub_self] apply SameRay.zero_left theorem wSameSide_of_right_mem {s : AffineSubspace R P} (x : P) {y : P} (hy : y ∈ s) : s.WSameSide x y := (wSameSide_of_left_mem x hy).symm theorem wOppSide_of_left_mem {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WOppSide x y := by refine ⟨x, hx, x, hx, ?_⟩ rw [vsub_self] apply SameRay.zero_left theorem wOppSide_of_right_mem {s : AffineSubspace R P} (x : P) {y : P} (hy : y ∈ s) : s.WOppSide x y := (wOppSide_of_left_mem x hy).symm theorem wSameSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WSameSide (v +ᵥ x) y ↔ s.WSameSide x y := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨-v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) hp₁, p₂, hp₂, ?_⟩ rwa [vsub_vadd_eq_vsub_sub, sub_neg_eq_add, add_comm, ← vadd_vsub_assoc] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction hv hp₁, p₂, hp₂, ?_⟩ rwa [vadd_vsub_vadd_cancel_left] theorem wSameSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WSameSide x (v +ᵥ y) ↔ s.WSameSide x y := by rw [wSameSide_comm, wSameSide_vadd_left_iff hv, wSameSide_comm] theorem sSameSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SSameSide (v +ᵥ x) y ↔ s.SSameSide x y := by rw [SSameSide, SSameSide, wSameSide_vadd_left_iff hv, vadd_mem_iff_mem_of_mem_direction hv] theorem sSameSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SSameSide x (v +ᵥ y) ↔ s.SSameSide x y := by rw [sSameSide_comm, sSameSide_vadd_left_iff hv, sSameSide_comm] theorem wOppSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WOppSide (v +ᵥ x) y ↔ s.WOppSide x y := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨-v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) hp₁, p₂, hp₂, ?_⟩ rwa [vsub_vadd_eq_vsub_sub, sub_neg_eq_add, add_comm, ← vadd_vsub_assoc] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction hv hp₁, p₂, hp₂, ?_⟩ rwa [vadd_vsub_vadd_cancel_left] theorem wOppSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WOppSide x (v +ᵥ y) ↔ s.WOppSide x y := by rw [wOppSide_comm, wOppSide_vadd_left_iff hv, wOppSide_comm] theorem sOppSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SOppSide (v +ᵥ x) y ↔ s.SOppSide x y := by rw [SOppSide, SOppSide, wOppSide_vadd_left_iff hv, vadd_mem_iff_mem_of_mem_direction hv] theorem sOppSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SOppSide x (v +ᵥ y) ↔ s.SOppSide x y := by rw [sOppSide_comm, sOppSide_vadd_left_iff hv, sOppSide_comm] theorem wSameSide_smul_vsub_vadd_left {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rw [vadd_vsub] exact SameRay.sameRay_nonneg_smul_left _ ht theorem wSameSide_smul_vsub_vadd_right {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (wSameSide_smul_vsub_vadd_left x hp₁ hp₂ ht).symm theorem wSameSide_lineMap_left {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide (lineMap x y t) y := wSameSide_smul_vsub_vadd_left y h h ht theorem wSameSide_lineMap_right {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide y (lineMap x y t) := (wSameSide_lineMap_left y h ht).symm theorem wOppSide_smul_vsub_vadd_left {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rw [vadd_vsub, ← neg_neg t, neg_smul, ← smul_neg, neg_vsub_eq_vsub_rev] exact SameRay.sameRay_nonneg_smul_left _ (neg_nonneg.2 ht) theorem wOppSide_smul_vsub_vadd_right {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (wOppSide_smul_vsub_vadd_left x hp₁ hp₂ ht).symm theorem wOppSide_lineMap_left {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide (lineMap x y t) y := wOppSide_smul_vsub_vadd_left y h h ht theorem wOppSide_lineMap_right {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide y (lineMap x y t) := (wOppSide_lineMap_left y h ht).symm theorem _root_.Wbtw.wSameSide₂₃ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hx : x ∈ s) : s.WSameSide y z := by rcases h with ⟨t, ⟨ht0, -⟩, rfl⟩ exact wSameSide_lineMap_left z hx ht0 theorem _root_.Wbtw.wSameSide₃₂ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hx : x ∈ s) : s.WSameSide z y := (h.wSameSide₂₃ hx).symm theorem _root_.Wbtw.wSameSide₁₂ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hz : z ∈ s) : s.WSameSide x y := h.symm.wSameSide₃₂ hz theorem _root_.Wbtw.wSameSide₂₁ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hz : z ∈ s) : s.WSameSide y x := h.symm.wSameSide₂₃ hz theorem _root_.Wbtw.wOppSide₁₃ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hy : y ∈ s) : s.WOppSide x z := by rcases h with ⟨t, ⟨ht0, ht1⟩, rfl⟩ refine ⟨_, hy, _, hy, ?_⟩ rcases ht1.lt_or_eq with (ht1' | rfl); swap · rw [lineMap_apply_one]; simp rcases ht0.lt_or_eq with (ht0' | rfl); swap · rw [lineMap_apply_zero]; simp refine Or.inr (Or.inr ⟨1 - t, t, sub_pos.2 ht1', ht0', ?_⟩) rw [lineMap_apply, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← neg_vsub_eq_vsub_rev z, vsub_self] module theorem _root_.Wbtw.wOppSide₃₁ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hy : y ∈ s) : s.WOppSide z x := h.symm.wOppSide₁₃ hy end StrictOrderedCommRing section LinearOrderedField variable [Field R] [LinearOrder R] [IsStrictOrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] @[simp] theorem wOppSide_self_iff {s : AffineSubspace R P} {x : P} : s.WOppSide x x ↔ x ∈ s := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ obtain ⟨a, -, -, -, -, h₁, -⟩ := h.exists_eq_smul_add rw [add_comm, vsub_add_vsub_cancel, ← eq_vadd_iff_vsub_eq] at h₁ rw [h₁] exact s.smul_vsub_vadd_mem a hp₂ hp₁ hp₁ · exact fun h => ⟨x, h, x, h, SameRay.rfl⟩ theorem not_sOppSide_self (s : AffineSubspace R P) (x : P) : ¬s.SOppSide x x := by rw [SOppSide] simp theorem wSameSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.WSameSide x y ↔ x ∈ s ∨ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by constructor · rintro ⟨p₁', hp₁', p₂', hp₂', h0 | h0 | ⟨r₁, r₂, hr₁, hr₂, hr⟩⟩ · rw [vsub_eq_zero_iff_eq] at h0 rw [h0] exact Or.inl hp₁' · refine Or.inr ⟨p₂', hp₂', ?_⟩ rw [h0] exact SameRay.zero_right _ · refine Or.inr ⟨(r₁ / r₂) • (p₁ -ᵥ p₁') +ᵥ p₂', s.smul_vsub_vadd_mem _ h hp₁' hp₂', Or.inr (Or.inr ⟨r₁, r₂, hr₁, hr₂, ?_⟩)⟩ rw [vsub_vadd_eq_vsub_sub, smul_sub, ← hr, smul_smul, mul_div_cancel₀ _ hr₂.ne.symm, ← smul_sub, vsub_sub_vsub_cancel_right] · rintro (h' | ⟨h₁, h₂, h₃⟩) · exact wSameSide_of_left_mem y h' · exact ⟨p₁, h, h₁, h₂, h₃⟩ theorem wSameSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.WSameSide x y ↔ y ∈ s ∨ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [wSameSide_comm, wSameSide_iff_exists_left h] simp_rw [SameRay.sameRay_comm] theorem sSameSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.SSameSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [SSameSide, and_comm, wSameSide_iff_exists_left h, and_assoc, and_congr_right_iff] intro hx rw [or_iff_right hx] theorem sSameSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.SSameSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [sSameSide_comm, sSameSide_iff_exists_left h, ← and_assoc, and_comm (a := y ∉ s), and_assoc] simp_rw [SameRay.sameRay_comm] theorem wOppSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.WOppSide x y ↔ x ∈ s ∨ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by constructor · rintro ⟨p₁', hp₁', p₂', hp₂', h0 | h0 | ⟨r₁, r₂, hr₁, hr₂, hr⟩⟩ · rw [vsub_eq_zero_iff_eq] at h0 rw [h0] exact Or.inl hp₁' · refine Or.inr ⟨p₂', hp₂', ?_⟩ rw [h0] exact SameRay.zero_right _ · refine Or.inr ⟨(-r₁ / r₂) • (p₁ -ᵥ p₁') +ᵥ p₂', s.smul_vsub_vadd_mem _ h hp₁' hp₂', Or.inr (Or.inr ⟨r₁, r₂, hr₁, hr₂, ?_⟩)⟩ rw [vadd_vsub_assoc, ← vsub_sub_vsub_cancel_right x p₁ p₁'] linear_combination (norm := match_scalars <;> field_simp) hr ring · rintro (h' | ⟨h₁, h₂, h₃⟩) · exact wOppSide_of_left_mem y h' · exact ⟨p₁, h, h₁, h₂, h₃⟩ theorem wOppSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.WOppSide x y ↔ y ∈ s ∨ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by rw [wOppSide_comm, wOppSide_iff_exists_left h] constructor · rintro (hy | ⟨p, hp, hr⟩) · exact Or.inl hy refine Or.inr ⟨p, hp, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] · rintro (hy | ⟨p, hp, hr⟩) · exact Or.inl hy refine Or.inr ⟨p, hp, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev]
Mathlib/Analysis/Convex/Side.lean
431
433
theorem sOppSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.SOppSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by
rw [SOppSide, and_comm, wOppSide_iff_exists_left h, and_assoc, and_congr_right_iff]
/- Copyright (c) 2024 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.Cyclotomic.PrimitiveRoots import Mathlib.NumberTheory.NumberField.Embeddings /-! # Cyclotomic extensions of `ℚ` are totally complex number fields. We prove that cyclotomic extensions of `ℚ` are totally complex, meaning that `NrRealPlaces K = 0` if `IsCyclotomicExtension {n} ℚ K` and `2 < n`. ## Main results * `nrRealPlaces_eq_zero`: If `K` is a `n`-th cyclotomic extension of `ℚ`, where `2 < n`, then there are no real places of `K`. -/ universe u namespace IsCyclotomicExtension.Rat open NumberField InfinitePlace Module Complex Nat Polynomial variable {n : ℕ+} (K : Type u) [Field K] [CharZero K] /-- If `K` is a `n`-th cyclotomic extension of `ℚ`, where `2 < n`, then there are no real places of `K`. -/ theorem nrRealPlaces_eq_zero [IsCyclotomicExtension {n} ℚ K] (hn : 2 < n) : haveI := IsCyclotomicExtension.numberField {n} ℚ K nrRealPlaces K = 0 := by have := IsCyclotomicExtension.numberField {n} ℚ K apply (IsCyclotomicExtension.zeta_spec n ℚ K).nrRealPlaces_eq_zero_of_two_lt hn variable (n) /-- If `K` is a `n`-th cyclotomic extension of `ℚ`, then there are `φ n / n` complex places of `K`. Note that this uses `1 / 2 = 0` in the cases `n = 1, 2`. -/
Mathlib/NumberTheory/Cyclotomic/Embeddings.lean
41
60
theorem nrComplexPlaces_eq_totient_div_two [h : IsCyclotomicExtension {n} ℚ K] : haveI := IsCyclotomicExtension.numberField {n} ℚ K nrComplexPlaces K = φ n / 2 := by
have := IsCyclotomicExtension.numberField {n} ℚ K by_cases hn : 2 < n · obtain ⟨k, hk : φ n = k + k⟩ := totient_even hn have key := card_add_two_mul_card_eq_rank K rw [nrRealPlaces_eq_zero K hn, zero_add, IsCyclotomicExtension.finrank (n := n) K (cyclotomic.irreducible_rat n.pos), hk, ← two_mul, Nat.mul_right_inj (by norm_num)] at key simp [hk, key, ← two_mul] · have : φ n = 1 := by by_cases h1 : 1 < n.1 · convert totient_two exact (eq_of_le_of_not_lt (succ_le_of_lt h1) hn).symm · convert totient_one rw [← PNat.one_coe, PNat.coe_inj] exact eq_of_le_of_not_lt (not_lt.mp h1) (PNat.not_lt_one _) rw [this] apply nrComplexPlaces_eq_zero_of_finrank_eq_one rw [IsCyclotomicExtension.finrank K (cyclotomic.irreducible_rat n.pos), this]
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Nat.Find import Mathlib.Data.Stream.Init import Mathlib.Tactic.Common /-! # Coinductive formalization of unbounded computations. This file provides a `Computation` type where `Computation α` is the type of unbounded computations returning `α`. -/ open Function universe u v w /- coinductive Computation (α : Type u) : Type u | pure : α → Computation α | think : Computation α → Computation α -/ /-- `Computation α` is the type of unbounded computations returning `α`. An element of `Computation α` is an infinite sequence of `Option α` such that if `f n = some a` for some `n` then it is constantly `some a` after that. -/ def Computation (α : Type u) : Type u := { f : Stream' (Option α) // ∀ ⦃n a⦄, f n = some a → f (n + 1) = some a } namespace Computation variable {α : Type u} {β : Type v} {γ : Type w} -- constructors /-- `pure a` is the computation that immediately terminates with result `a`. -/ def pure (a : α) : Computation α := ⟨Stream'.const (some a), fun _ _ => id⟩ instance : CoeTC α (Computation α) := ⟨pure⟩ -- note [use has_coe_t] /-- `think c` is the computation that delays for one "tick" and then performs computation `c`. -/ def think (c : Computation α) : Computation α := ⟨Stream'.cons none c.1, fun n a h => by rcases n with - | n · contradiction · exact c.2 h⟩ /-- `thinkN c n` is the computation that delays for `n` ticks and then performs computation `c`. -/ def thinkN (c : Computation α) : ℕ → Computation α | 0 => c | n + 1 => think (thinkN c n) -- check for immediate result /-- `head c` is the first step of computation, either `some a` if `c = pure a` or `none` if `c = think c'`. -/ def head (c : Computation α) : Option α := c.1.head -- one step of computation /-- `tail c` is the remainder of computation, either `c` if `c = pure a` or `c'` if `c = think c'`. -/ def tail (c : Computation α) : Computation α := ⟨c.1.tail, fun _ _ h => c.2 h⟩ /-- `empty α` is the computation that never returns, an infinite sequence of `think`s. -/ def empty (α) : Computation α := ⟨Stream'.const none, fun _ _ => id⟩ instance : Inhabited (Computation α) := ⟨empty _⟩ /-- `runFor c n` evaluates `c` for `n` steps and returns the result, or `none` if it did not terminate after `n` steps. -/ def runFor : Computation α → ℕ → Option α := Subtype.val /-- `destruct c` is the destructor for `Computation α` as a coinductive type. It returns `inl a` if `c = pure a` and `inr c'` if `c = think c'`. -/ def destruct (c : Computation α) : α ⊕ (Computation α) := match c.1 0 with | none => Sum.inr (tail c) | some a => Sum.inl a /-- `run c` is an unsound meta function that runs `c` to completion, possibly resulting in an infinite loop in the VM. -/ unsafe def run : Computation α → α | c => match destruct c with | Sum.inl a => a | Sum.inr ca => run ca theorem destruct_eq_pure {s : Computation α} {a : α} : destruct s = Sum.inl a → s = pure a := by dsimp [destruct] induction' f0 : s.1 0 with _ <;> intro h · contradiction · apply Subtype.eq funext n induction' n with n IH · injection h with h' rwa [h'] at f0 · exact s.2 IH theorem destruct_eq_think {s : Computation α} {s'} : destruct s = Sum.inr s' → s = think s' := by dsimp [destruct] induction' f0 : s.1 0 with a' <;> intro h · injection h with h' rw [← h'] obtain ⟨f, al⟩ := s apply Subtype.eq dsimp [think, tail] rw [← f0] exact (Stream'.eta f).symm · contradiction @[simp] theorem destruct_pure (a : α) : destruct (pure a) = Sum.inl a := rfl @[simp] theorem destruct_think : ∀ s : Computation α, destruct (think s) = Sum.inr s | ⟨_, _⟩ => rfl @[simp] theorem destruct_empty : destruct (empty α) = Sum.inr (empty α) := rfl @[simp] theorem head_pure (a : α) : head (pure a) = some a := rfl @[simp] theorem head_think (s : Computation α) : head (think s) = none := rfl @[simp] theorem head_empty : head (empty α) = none := rfl @[simp] theorem tail_pure (a : α) : tail (pure a) = pure a := rfl @[simp] theorem tail_think (s : Computation α) : tail (think s) = s := by obtain ⟨f, al⟩ := s; apply Subtype.eq; dsimp [tail, think] @[simp] theorem tail_empty : tail (empty α) = empty α := rfl theorem think_empty : empty α = think (empty α) := destruct_eq_think destruct_empty /-- Recursion principle for computations, compare with `List.recOn`. -/ def recOn {C : Computation α → Sort v} (s : Computation α) (h1 : ∀ a, C (pure a)) (h2 : ∀ s, C (think s)) : C s := match H : destruct s with | Sum.inl v => by rw [destruct_eq_pure H] apply h1 | Sum.inr v => match v with | ⟨a, s'⟩ => by rw [destruct_eq_think H] apply h2 /-- Corecursor constructor for `corec` -/ def Corec.f (f : β → α ⊕ β) : α ⊕ β → Option α × (α ⊕ β) | Sum.inl a => (some a, Sum.inl a) | Sum.inr b => (match f b with | Sum.inl a => some a | Sum.inr _ => none, f b) /-- `corec f b` is the corecursor for `Computation α` as a coinductive type. If `f b = inl a` then `corec f b = pure a`, and if `f b = inl b'` then `corec f b = think (corec f b')`. -/ def corec (f : β → α ⊕ β) (b : β) : Computation α := by refine ⟨Stream'.corec' (Corec.f f) (Sum.inr b), fun n a' h => ?_⟩ rw [Stream'.corec'_eq] change Stream'.corec' (Corec.f f) (Corec.f f (Sum.inr b)).2 n = some a' revert h; generalize Sum.inr b = o; revert o induction' n with n IH <;> intro o · change (Corec.f f o).1 = some a' → (Corec.f f (Corec.f f o).2).1 = some a' rcases o with _ | b <;> intro h · exact h unfold Corec.f at *; split <;> simp_all · rw [Stream'.corec'_eq (Corec.f f) (Corec.f f o).2, Stream'.corec'_eq (Corec.f f) o] exact IH (Corec.f f o).2 /-- left map of `⊕` -/ def lmap (f : α → β) : α ⊕ γ → β ⊕ γ | Sum.inl a => Sum.inl (f a) | Sum.inr b => Sum.inr b /-- right map of `⊕` -/ def rmap (f : β → γ) : α ⊕ β → α ⊕ γ | Sum.inl a => Sum.inl a | Sum.inr b => Sum.inr (f b) attribute [simp] lmap rmap @[simp] theorem corec_eq (f : β → α ⊕ β) (b : β) : destruct (corec f b) = rmap (corec f) (f b) := by dsimp [corec, destruct] rw [show Stream'.corec' (Corec.f f) (Sum.inr b) 0 = Sum.rec Option.some (fun _ ↦ none) (f b) by dsimp [Corec.f, Stream'.corec', Stream'.corec, Stream'.map, Stream'.get, Stream'.iterate] match (f b) with | Sum.inl x => rfl | Sum.inr x => rfl ] induction' h : f b with a b'; · rfl dsimp [Corec.f, destruct] apply congr_arg; apply Subtype.eq dsimp [corec, tail] rw [Stream'.corec'_eq, Stream'.tail_cons] dsimp [Corec.f]; rw [h] section Bisim variable (R : Computation α → Computation α → Prop) /-- bisimilarity relation -/ local infixl:50 " ~ " => R /-- Bisimilarity over a sum of `Computation`s -/ def BisimO : α ⊕ (Computation α) → α ⊕ (Computation α) → Prop | Sum.inl a, Sum.inl a' => a = a' | Sum.inr s, Sum.inr s' => R s s' | _, _ => False attribute [simp] BisimO attribute [nolint simpNF] BisimO.eq_3 /-- Attribute expressing bisimilarity over two `Computation`s -/ def IsBisimulation := ∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → BisimO R (destruct s₁) (destruct s₂) -- If two computations are bisimilar, then they are equal theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ := by apply Subtype.eq apply Stream'.eq_of_bisim fun x y => ∃ s s' : Computation α, s.1 = x ∧ s'.1 = y ∧ R s s' · dsimp [Stream'.IsBisimulation] intro t₁ t₂ e match t₁, t₂, e with | _, _, ⟨s, s', rfl, rfl, r⟩ => suffices head s = head s' ∧ R (tail s) (tail s') from And.imp id (fun r => ⟨tail s, tail s', by cases s; rfl, by cases s'; rfl, r⟩) this have h := bisim r; revert r h apply recOn s _ _ <;> intro r' <;> apply recOn s' _ _ <;> intro a' r h · constructor <;> dsimp at h · rw [h] · rw [h] at r rw [tail_pure, tail_pure,h] assumption · rw [destruct_pure, destruct_think] at h exact False.elim h · rw [destruct_pure, destruct_think] at h exact False.elim h · simp_all · exact ⟨s₁, s₂, rfl, rfl, r⟩ end Bisim -- It's more of a stretch to use ∈ for this relation, but it -- asserts that the computation limits to the given value. /-- Assertion that a `Computation` limits to a given value -/ protected def Mem (s : Computation α) (a : α) := some a ∈ s.1 instance : Membership α (Computation α) := ⟨Computation.Mem⟩ theorem le_stable (s : Computation α) {a m n} (h : m ≤ n) : s.1 m = some a → s.1 n = some a := by obtain ⟨f, al⟩ := s induction' h with n _ IH exacts [id, fun h2 => al (IH h2)] theorem mem_unique {s : Computation α} {a b : α} : a ∈ s → b ∈ s → a = b | ⟨m, ha⟩, ⟨n, hb⟩ => by injection (le_stable s (le_max_left m n) ha.symm).symm.trans (le_stable s (le_max_right m n) hb.symm) theorem Mem.left_unique : Relator.LeftUnique ((· ∈ ·) : α → Computation α → Prop) := fun _ _ _ => mem_unique /-- `Terminates s` asserts that the computation `s` eventually terminates with some value. -/ class Terminates (s : Computation α) : Prop where /-- assertion that there is some term `a` such that the `Computation` terminates -/ term : ∃ a, a ∈ s theorem terminates_iff (s : Computation α) : Terminates s ↔ ∃ a, a ∈ s := ⟨fun h => h.1, Terminates.mk⟩ theorem terminates_of_mem {s : Computation α} {a : α} (h : a ∈ s) : Terminates s := ⟨⟨a, h⟩⟩ theorem terminates_def (s : Computation α) : Terminates s ↔ ∃ n, (s.1 n).isSome := ⟨fun ⟨⟨a, n, h⟩⟩ => ⟨n, by dsimp [Stream'.get] at h rw [← h] exact rfl⟩, fun ⟨n, h⟩ => ⟨⟨Option.get _ h, n, (Option.eq_some_of_isSome h).symm⟩⟩⟩ theorem ret_mem (a : α) : a ∈ pure a := Exists.intro 0 rfl theorem eq_of_pure_mem {a a' : α} (h : a' ∈ pure a) : a' = a := mem_unique h (ret_mem _) @[simp] theorem mem_pure_iff (a b : α) : a ∈ pure b ↔ a = b := ⟨eq_of_pure_mem, fun h => h ▸ ret_mem _⟩ instance ret_terminates (a : α) : Terminates (pure a) := terminates_of_mem (ret_mem _) theorem think_mem {s : Computation α} {a} : a ∈ s → a ∈ think s | ⟨n, h⟩ => ⟨n + 1, h⟩ instance think_terminates (s : Computation α) : ∀ [Terminates s], Terminates (think s) | ⟨⟨a, n, h⟩⟩ => ⟨⟨a, n + 1, h⟩⟩ theorem of_think_mem {s : Computation α} {a} : a ∈ think s → a ∈ s | ⟨n, h⟩ => by rcases n with - | n' · contradiction · exact ⟨n', h⟩ theorem of_think_terminates {s : Computation α} : Terminates (think s) → Terminates s | ⟨⟨a, h⟩⟩ => ⟨⟨a, of_think_mem h⟩⟩ theorem not_mem_empty (a : α) : a ∉ empty α := fun ⟨n, h⟩ => by contradiction theorem not_terminates_empty : ¬Terminates (empty α) := fun ⟨⟨a, h⟩⟩ => not_mem_empty a h theorem eq_empty_of_not_terminates {s} (H : ¬Terminates s) : s = empty α := by apply Subtype.eq; funext n induction' h : s.val n with _; · rfl refine absurd ?_ H; exact ⟨⟨_, _, h.symm⟩⟩ theorem thinkN_mem {s : Computation α} {a} : ∀ n, a ∈ thinkN s n ↔ a ∈ s | 0 => Iff.rfl | n + 1 => Iff.trans ⟨of_think_mem, think_mem⟩ (thinkN_mem n) instance thinkN_terminates (s : Computation α) : ∀ [Terminates s] (n), Terminates (thinkN s n) | ⟨⟨a, h⟩⟩, n => ⟨⟨a, (thinkN_mem n).2 h⟩⟩ theorem of_thinkN_terminates (s : Computation α) (n) : Terminates (thinkN s n) → Terminates s | ⟨⟨a, h⟩⟩ => ⟨⟨a, (thinkN_mem _).1 h⟩⟩ /-- `Promises s a`, or `s ~> a`, asserts that although the computation `s` may not terminate, if it does, then the result is `a`. -/ def Promises (s : Computation α) (a : α) : Prop := ∀ ⦃a'⦄, a' ∈ s → a = a' /-- `Promises s a`, or `s ~> a`, asserts that although the computation `s` may not terminate, if it does, then the result is `a`. -/ scoped infixl:50 " ~> " => Promises theorem mem_promises {s : Computation α} {a : α} : a ∈ s → s ~> a := fun h _ => mem_unique h theorem empty_promises (a : α) : empty α ~> a := fun _ h => absurd h (not_mem_empty _) section get variable (s : Computation α) [h : Terminates s] /-- `length s` gets the number of steps of a terminating computation -/ def length : ℕ := Nat.find ((terminates_def _).1 h) /-- `get s` returns the result of a terminating computation -/ def get : α := Option.get _ (Nat.find_spec <| (terminates_def _).1 h) theorem get_mem : get s ∈ s := Exists.intro (length s) (Option.eq_some_of_isSome _).symm theorem get_eq_of_mem {a} : a ∈ s → get s = a := mem_unique (get_mem _) theorem mem_of_get_eq {a} : get s = a → a ∈ s := by intro h; rw [← h]; apply get_mem @[simp] theorem get_think : get (think s) = get s := get_eq_of_mem _ <| let ⟨n, h⟩ := get_mem s ⟨n + 1, h⟩ @[simp] theorem get_thinkN (n) : get (thinkN s n) = get s := get_eq_of_mem _ <| (thinkN_mem _).2 (get_mem _) theorem get_promises : s ~> get s := fun _ => get_eq_of_mem _ theorem mem_of_promises {a} (p : s ~> a) : a ∈ s := by obtain ⟨h⟩ := h obtain ⟨a', h⟩ := h rw [p h] exact h theorem get_eq_of_promises {a} : s ~> a → get s = a := get_eq_of_mem _ ∘ mem_of_promises _ end get /-- `Results s a n` completely characterizes a terminating computation: it asserts that `s` terminates after exactly `n` steps, with result `a`. -/ def Results (s : Computation α) (a : α) (n : ℕ) := ∃ h : a ∈ s, @length _ s (terminates_of_mem h) = n theorem results_of_terminates (s : Computation α) [_T : Terminates s] : Results s (get s) (length s) := ⟨get_mem _, rfl⟩ theorem results_of_terminates' (s : Computation α) [T : Terminates s] {a} (h : a ∈ s) : Results s a (length s) := by rw [← get_eq_of_mem _ h]; apply results_of_terminates theorem Results.mem {s : Computation α} {a n} : Results s a n → a ∈ s | ⟨m, _⟩ => m theorem Results.terminates {s : Computation α} {a n} (h : Results s a n) : Terminates s := terminates_of_mem h.mem theorem Results.length {s : Computation α} {a n} [_T : Terminates s] : Results s a n → length s = n | ⟨_, h⟩ => h theorem Results.val_unique {s : Computation α} {a b m n} (h1 : Results s a m) (h2 : Results s b n) : a = b := mem_unique h1.mem h2.mem theorem Results.len_unique {s : Computation α} {a b m n} (h1 : Results s a m) (h2 : Results s b n) : m = n := by haveI := h1.terminates; haveI := h2.terminates; rw [← h1.length, h2.length] theorem exists_results_of_mem {s : Computation α} {a} (h : a ∈ s) : ∃ n, Results s a n := haveI := terminates_of_mem h ⟨_, results_of_terminates' s h⟩ @[simp] theorem get_pure (a : α) : get (pure a) = a := get_eq_of_mem _ ⟨0, rfl⟩ @[simp] theorem length_pure (a : α) : length (pure a) = 0 := let h := Computation.ret_terminates a Nat.eq_zero_of_le_zero <| Nat.find_min' ((terminates_def (pure a)).1 h) rfl theorem results_pure (a : α) : Results (pure a) a 0 := ⟨ret_mem a, length_pure _⟩ @[simp] theorem length_think (s : Computation α) [h : Terminates s] : length (think s) = length s + 1 := by apply le_antisymm · exact Nat.find_min' _ (Nat.find_spec ((terminates_def _).1 h)) · have : (Option.isSome ((think s).val (length (think s))) : Prop) := Nat.find_spec ((terminates_def _).1 s.think_terminates) revert this; rcases length (think s) with - | n <;> intro this · simp [think, Stream'.cons] at this · apply Nat.succ_le_succ apply Nat.find_min' apply this theorem results_think {s : Computation α} {a n} (h : Results s a n) : Results (think s) a (n + 1) := haveI := h.terminates ⟨think_mem h.mem, by rw [length_think, h.length]⟩ theorem of_results_think {s : Computation α} {a n} (h : Results (think s) a n) : ∃ m, Results s a m ∧ n = m + 1 := by haveI := of_think_terminates h.terminates have := results_of_terminates' _ (of_think_mem h.mem) exact ⟨_, this, Results.len_unique h (results_think this)⟩ @[simp] theorem results_think_iff {s : Computation α} {a n} : Results (think s) a (n + 1) ↔ Results s a n := ⟨fun h => by let ⟨n', r, e⟩ := of_results_think h injection e with h'; rwa [h'], results_think⟩ theorem results_thinkN {s : Computation α} {a m} : ∀ n, Results s a m → Results (thinkN s n) a (m + n) | 0, h => h | n + 1, h => results_think (results_thinkN n h) theorem results_thinkN_pure (a : α) (n) : Results (thinkN (pure a) n) a n := by have := results_thinkN n (results_pure a); rwa [Nat.zero_add] at this @[simp] theorem length_thinkN (s : Computation α) [_h : Terminates s] (n) : length (thinkN s n) = length s + n := (results_thinkN n (results_of_terminates _)).length theorem eq_thinkN {s : Computation α} {a n} (h : Results s a n) : s = thinkN (pure a) n := by revert s induction n with | zero => _ | succ n IH => _ <;> (intro s; apply recOn s (fun a' => _) fun s => _) <;> intro a h · rw [← eq_of_pure_mem h.mem] rfl · obtain ⟨n, h⟩ := of_results_think h cases h contradiction · have := h.len_unique (results_pure _) contradiction · rw [IH (results_think_iff.1 h)] rfl theorem eq_thinkN' (s : Computation α) [_h : Terminates s] : s = thinkN (pure (get s)) (length s) := eq_thinkN (results_of_terminates _) /-- Recursor based on membership -/ def memRecOn {C : Computation α → Sort v} {a s} (M : a ∈ s) (h1 : C (pure a)) (h2 : ∀ s, C s → C (think s)) : C s := by haveI T := terminates_of_mem M rw [eq_thinkN' s, get_eq_of_mem s M] generalize length s = n induction' n with n IH; exacts [h1, h2 _ IH] /-- Recursor based on assertion of `Terminates` -/ def terminatesRecOn {C : Computation α → Sort v} (s) [Terminates s] (h1 : ∀ a, C (pure a)) (h2 : ∀ s, C s → C (think s)) : C s := memRecOn (get_mem s) (h1 _) h2 /-- Map a function on the result of a computation. -/ def map (f : α → β) : Computation α → Computation β | ⟨s, al⟩ => ⟨s.map fun o => Option.casesOn o none (some ∘ f), fun n b => by dsimp [Stream'.map, Stream'.get] induction' e : s n with a <;> intro h · contradiction · rw [al e]; exact h⟩ /-- bind over a `Sum` of `Computation` -/ def Bind.g : β ⊕ Computation β → β ⊕ (Computation α ⊕ Computation β) | Sum.inl b => Sum.inl b | Sum.inr cb' => Sum.inr <| Sum.inr cb' /-- bind over a function mapping `α` to a `Computation` -/ def Bind.f (f : α → Computation β) : Computation α ⊕ Computation β → β ⊕ (Computation α ⊕ Computation β) | Sum.inl ca => match destruct ca with | Sum.inl a => Bind.g <| destruct (f a) | Sum.inr ca' => Sum.inr <| Sum.inl ca' | Sum.inr cb => Bind.g <| destruct cb /-- Compose two computations into a monadic `bind` operation. -/ def bind (c : Computation α) (f : α → Computation β) : Computation β := corec (Bind.f f) (Sum.inl c) instance : Bind Computation := ⟨@bind⟩ theorem has_bind_eq_bind {β} (c : Computation α) (f : α → Computation β) : c >>= f = bind c f := rfl /-- Flatten a computation of computations into a single computation. -/ def join (c : Computation (Computation α)) : Computation α := c >>= id @[simp] theorem map_pure (f : α → β) (a) : map f (pure a) = pure (f a) := rfl @[simp] theorem map_think (f : α → β) : ∀ s, map f (think s) = think (map f s) | ⟨s, al⟩ => by apply Subtype.eq; dsimp [think, map]; rw [Stream'.map_cons] @[simp] theorem destruct_map (f : α → β) (s) : destruct (map f s) = lmap f (rmap (map f) (destruct s)) := by apply s.recOn <;> intro <;> simp @[simp] theorem map_id : ∀ s : Computation α, map id s = s | ⟨f, al⟩ => by apply Subtype.eq; simp only [map, comp_apply, id_eq] have e : @Option.rec α (fun _ => Option α) none some = id := by ext ⟨⟩ <;> rfl have h : ((fun x : Option α => x) = id) := rfl simp [e, h, Stream'.map_id] theorem map_comp (f : α → β) (g : β → γ) : ∀ s : Computation α, map (g ∘ f) s = map g (map f s) | ⟨s, al⟩ => by apply Subtype.eq; dsimp [map] apply congr_arg fun f : _ → Option γ => Stream'.map f s ext ⟨⟩ <;> rfl @[simp] theorem ret_bind (a) (f : α → Computation β) : bind (pure a) f = f a := by apply eq_of_bisim fun c₁ c₂ => c₁ = bind (pure a) f ∧ c₂ = f a ∨ c₁ = corec (Bind.f f) (Sum.inr c₂) · intro c₁ c₂ h match c₁, c₂, h with | _, _, Or.inl ⟨rfl, rfl⟩ => simp only [BisimO, bind, Bind.f, corec_eq, rmap, destruct_pure] rcases destruct (f a) with b | cb <;> simp [Bind.g] | _, c, Or.inr rfl => simp only [BisimO, Bind.f, corec_eq, rmap] rcases destruct c with b | cb <;> simp [Bind.g] · simp @[simp] theorem think_bind (c) (f : α → Computation β) : bind (think c) f = think (bind c f) := destruct_eq_think <| by simp [bind, Bind.f] @[simp] theorem bind_pure (f : α → β) (s) : bind s (pure ∘ f) = map f s := by apply eq_of_bisim fun c₁ c₂ => c₁ = c₂ ∨ ∃ s, c₁ = bind s (pure ∘ f) ∧ c₂ = map f s · intro c₁ c₂ h match c₁, c₂, h with | _, c₂, Or.inl (Eq.refl _) => rcases destruct c₂ with b | cb <;> simp | _, _, Or.inr ⟨s, rfl, rfl⟩ => apply recOn s <;> intro s · simp · simpa using Or.inr ⟨s, rfl, rfl⟩ · exact Or.inr ⟨s, rfl, rfl⟩ @[simp] theorem bind_pure' (s : Computation α) : bind s pure = s := by simpa using bind_pure id s @[simp] theorem bind_assoc (s : Computation α) (f : α → Computation β) (g : β → Computation γ) : bind (bind s f) g = bind s fun x : α => bind (f x) g := by apply eq_of_bisim fun c₁ c₂ => c₁ = c₂ ∨ ∃ s, c₁ = bind (bind s f) g ∧ c₂ = bind s fun x : α => bind (f x) g · intro c₁ c₂ h match c₁, c₂, h with | _, c₂, Or.inl (Eq.refl _) => rcases destruct c₂ with b | cb <;> simp | _, _, Or.inr ⟨s, rfl, rfl⟩ => apply recOn s <;> intro s · simp only [BisimO, ret_bind]; generalize f s = fs apply recOn fs <;> intro t <;> simp · rcases destruct (g t) with b | cb <;> simp · simpa [BisimO] using Or.inr ⟨s, rfl, rfl⟩ · exact Or.inr ⟨s, rfl, rfl⟩ theorem results_bind {s : Computation α} {f : α → Computation β} {a b m n} (h1 : Results s a m) (h2 : Results (f a) b n) : Results (bind s f) b (n + m) := by have := h1.mem; revert m apply memRecOn this _ fun s IH => _ · intro _ h1 rw [ret_bind] rw [h1.len_unique (results_pure _)] exact h2 · intro _ h3 _ h1 rw [think_bind] obtain ⟨m', h⟩ := of_results_think h1 obtain ⟨h1, e⟩ := h rw [e] exact results_think (h3 h1) theorem mem_bind {s : Computation α} {f : α → Computation β} {a b} (h1 : a ∈ s) (h2 : b ∈ f a) : b ∈ bind s f := let ⟨_, h1⟩ := exists_results_of_mem h1 let ⟨_, h2⟩ := exists_results_of_mem h2 (results_bind h1 h2).mem instance terminates_bind (s : Computation α) (f : α → Computation β) [Terminates s] [Terminates (f (get s))] : Terminates (bind s f) := terminates_of_mem (mem_bind (get_mem s) (get_mem (f (get s)))) @[simp] theorem get_bind (s : Computation α) (f : α → Computation β) [Terminates s] [Terminates (f (get s))] : get (bind s f) = get (f (get s)) := get_eq_of_mem _ (mem_bind (get_mem s) (get_mem (f (get s)))) @[simp] theorem length_bind (s : Computation α) (f : α → Computation β) [_T1 : Terminates s] [_T2 : Terminates (f (get s))] : length (bind s f) = length (f (get s)) + length s := (results_of_terminates _).len_unique <| results_bind (results_of_terminates _) (results_of_terminates _) theorem of_results_bind {s : Computation α} {f : α → Computation β} {b k} : Results (bind s f) b k → ∃ a m n, Results s a m ∧ Results (f a) b n ∧ k = n + m := by induction k generalizing s with | zero => _ | succ n IH => _ <;> apply recOn s (fun a => _) fun s' => _ <;> intro e h · simp only [ret_bind] at h exact ⟨e, _, _, results_pure _, h, rfl⟩ · have := congr_arg head (eq_thinkN h) contradiction · simp only [ret_bind] at h exact ⟨e, _, n + 1, results_pure _, h, rfl⟩ · simp only [think_bind, results_think_iff] at h let ⟨a, m, n', h1, h2, e'⟩ := IH h rw [e'] exact ⟨a, m.succ, n', results_think h1, h2, rfl⟩ theorem exists_of_mem_bind {s : Computation α} {f : α → Computation β} {b} (h : b ∈ bind s f) : ∃ a ∈ s, b ∈ f a := let ⟨_, h⟩ := exists_results_of_mem h let ⟨a, _, _, h1, h2, _⟩ := of_results_bind h ⟨a, h1.mem, h2.mem⟩ theorem bind_promises {s : Computation α} {f : α → Computation β} {a b} (h1 : s ~> a) (h2 : f a ~> b) : bind s f ~> b := fun b' bB => by rcases exists_of_mem_bind bB with ⟨a', a's, ba'⟩ rw [← h1 a's] at ba'; exact h2 ba' instance monad : Monad Computation where map := @map pure := @pure bind := @bind instance : LawfulMonad Computation := LawfulMonad.mk' (id_map := @map_id) (bind_pure_comp := @bind_pure) (pure_bind := @ret_bind) (bind_assoc := @bind_assoc) theorem has_map_eq_map {β} (f : α → β) (c : Computation α) : f <$> c = map f c := rfl @[simp] theorem pure_def (a) : (return a : Computation α) = pure a := rfl @[simp] theorem map_pure' {α β} : ∀ (f : α → β) (a), f <$> pure a = pure (f a) := map_pure @[simp]
Mathlib/Data/Seq/Computation.lean
735
743
theorem map_think' {α β} : ∀ (f : α → β) (s), f <$> think s = think (f <$> s) := map_think theorem mem_map (f : α → β) {a} {s : Computation α} (m : a ∈ s) : f a ∈ map f s := by
rw [← bind_pure]; apply mem_bind m; apply ret_mem theorem exists_of_mem_map {f : α → β} {b : β} {s : Computation α} (h : b ∈ map f s) : ∃ a, a ∈ s ∧ f a = b := by rw [← bind_pure] at h
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Data.Nat.Factorization.Defs import Mathlib.Analysis.NormedSpace.Real import Mathlib.Data.Rat.Cast.CharZero /-! # Real logarithm In this file we define `Real.log` to be the logarithm of a real number. As usual, we extend it from its domain `(0, +∞)` to a globally defined function. We choose to do it so that `log 0 = 0` and `log (-x) = log x`. We prove some basic properties of this function and show that it is continuous. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {x y : ℝ} /-- The real logarithm function, equal to the inverse of the exponential for `x > 0`, to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to `(-∞, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and the derivative of `log` is `1/x` away from `0`. -/ @[pp_nodot] noncomputable def log (x : ℝ) : ℝ := if hx : x = 0 then 0 else expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩ theorem log_of_ne_zero (hx : x ≠ 0) : log x = expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩ := dif_neg hx theorem log_of_pos (hx : 0 < x) : log x = expOrderIso.symm ⟨x, hx⟩ := by rw [log_of_ne_zero hx.ne'] congr exact abs_of_pos hx theorem exp_log_eq_abs (hx : x ≠ 0) : exp (log x) = |x| := by rw [log_of_ne_zero hx, ← coe_expOrderIso_apply, OrderIso.apply_symm_apply, Subtype.coe_mk] theorem exp_log (hx : 0 < x) : exp (log x) = x := by rw [exp_log_eq_abs hx.ne'] exact abs_of_pos hx theorem exp_log_of_neg (hx : x < 0) : exp (log x) = -x := by rw [exp_log_eq_abs (ne_of_lt hx)] exact abs_of_neg hx theorem le_exp_log (x : ℝ) : x ≤ exp (log x) := by by_cases h_zero : x = 0 · rw [h_zero, log, dif_pos rfl, exp_zero] exact zero_le_one · rw [exp_log_eq_abs h_zero] exact le_abs_self _ @[simp] theorem log_exp (x : ℝ) : log (exp x) = x := exp_injective <| exp_log (exp_pos x) theorem exp_one_mul_le_exp {x : ℝ} : exp 1 * x ≤ exp x := by by_cases hx0 : x ≤ 0 · apply le_trans (mul_nonpos_of_nonneg_of_nonpos (exp_pos 1).le hx0) (exp_nonneg x) · have h := add_one_le_exp (log x) rwa [← exp_le_exp, exp_add, exp_log (lt_of_not_le hx0), mul_comm] at h theorem two_mul_le_exp {x : ℝ} : 2 * x ≤ exp x := by by_cases hx0 : x < 0 · exact le_trans (mul_nonpos_of_nonneg_of_nonpos (by simp only [Nat.ofNat_nonneg]) hx0.le) (exp_nonneg x) · apply le_trans (mul_le_mul_of_nonneg_right _ (le_of_not_lt hx0)) exp_one_mul_le_exp have := Real.add_one_le_exp 1 rwa [one_add_one_eq_two] at this theorem surjOn_log : SurjOn log (Ioi 0) univ := fun x _ => ⟨exp x, exp_pos x, log_exp x⟩ theorem log_surjective : Surjective log := fun x => ⟨exp x, log_exp x⟩ @[simp] theorem range_log : range log = univ := log_surjective.range_eq @[simp] theorem log_zero : log 0 = 0 := dif_pos rfl @[simp] theorem log_one : log 1 = 0 := exp_injective <| by rw [exp_log zero_lt_one, exp_zero] /-- This holds true for all `x : ℝ` because of the junk values `0 / 0 = 0` and `log 0 = 0`. -/ @[simp] lemma log_div_self (x : ℝ) : log (x / x) = 0 := by obtain rfl | hx := eq_or_ne x 0 <;> simp [*] @[simp] theorem log_abs (x : ℝ) : log |x| = log x := by by_cases h : x = 0 · simp [h] · rw [← exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs] @[simp] theorem log_neg_eq_log (x : ℝ) : log (-x) = log x := by rw [← log_abs x, ← log_abs (-x), abs_neg] theorem sinh_log {x : ℝ} (hx : 0 < x) : sinh (log x) = (x - x⁻¹) / 2 := by rw [sinh_eq, exp_neg, exp_log hx] theorem cosh_log {x : ℝ} (hx : 0 < x) : cosh (log x) = (x + x⁻¹) / 2 := by rw [cosh_eq, exp_neg, exp_log hx] theorem surjOn_log' : SurjOn log (Iio 0) univ := fun x _ => ⟨-exp x, neg_lt_zero.2 <| exp_pos x, by rw [log_neg_eq_log, log_exp]⟩ theorem log_mul (hx : x ≠ 0) (hy : y ≠ 0) : log (x * y) = log x + log y := exp_injective <| by rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul] theorem log_div (hx : x ≠ 0) (hy : y ≠ 0) : log (x / y) = log x - log y := exp_injective <| by rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div] @[simp] theorem log_inv (x : ℝ) : log x⁻¹ = -log x := by by_cases hx : x = 0; · simp [hx] rw [← exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv] theorem log_le_log_iff (h : 0 < x) (h₁ : 0 < y) : log x ≤ log y ↔ x ≤ y := by rw [← exp_le_exp, exp_log h, exp_log h₁] @[gcongr, bound] lemma log_le_log (hx : 0 < x) (hxy : x ≤ y) : log x ≤ log y := (log_le_log_iff hx (hx.trans_le hxy)).2 hxy @[gcongr, bound] theorem log_lt_log (hx : 0 < x) (h : x < y) : log x < log y := by rwa [← exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)] theorem log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y ↔ x < y := by rw [← exp_lt_exp, exp_log hx, exp_log hy] theorem log_le_iff_le_exp (hx : 0 < x) : log x ≤ y ↔ x ≤ exp y := by rw [← exp_le_exp, exp_log hx] theorem log_lt_iff_lt_exp (hx : 0 < x) : log x < y ↔ x < exp y := by rw [← exp_lt_exp, exp_log hx] theorem le_log_iff_exp_le (hy : 0 < y) : x ≤ log y ↔ exp x ≤ y := by rw [← exp_le_exp, exp_log hy] theorem lt_log_iff_exp_lt (hy : 0 < y) : x < log y ↔ exp x < y := by rw [← exp_lt_exp, exp_log hy] theorem log_pos_iff (hx : 0 ≤ x) : 0 < log x ↔ 1 < x := by rcases hx.eq_or_lt with (rfl | hx) · simp [le_refl, zero_le_one] rw [← log_one] exact log_lt_log_iff zero_lt_one hx @[bound] theorem log_pos (hx : 1 < x) : 0 < log x := (log_pos_iff (lt_trans zero_lt_one hx).le).2 hx theorem log_pos_of_lt_neg_one (hx : x < -1) : 0 < log x := by rw [← neg_neg x, log_neg_eq_log] have : 1 < -x := by linarith exact log_pos this theorem log_neg_iff (h : 0 < x) : log x < 0 ↔ x < 1 := by rw [← log_one] exact log_lt_log_iff h zero_lt_one @[bound] theorem log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 := (log_neg_iff h0).2 h1 theorem log_neg_of_lt_zero (h0 : x < 0) (h1 : -1 < x) : log x < 0 := by rw [← neg_neg x, log_neg_eq_log] have h0' : 0 < -x := by linarith have h1' : -x < 1 := by linarith exact log_neg h0' h1' theorem log_nonneg_iff (hx : 0 < x) : 0 ≤ log x ↔ 1 ≤ x := by rw [← not_lt, log_neg_iff hx, not_lt] @[bound] theorem log_nonneg (hx : 1 ≤ x) : 0 ≤ log x := (log_nonneg_iff (zero_lt_one.trans_le hx)).2 hx theorem log_nonpos_iff (hx : 0 ≤ x) : log x ≤ 0 ↔ x ≤ 1 := by rcases hx.eq_or_lt with (rfl | hx) · simp [le_refl, zero_le_one] rw [← not_lt, log_pos_iff hx.le, not_lt] @[deprecated (since := "2025-01-16")] alias log_nonpos_iff' := log_nonpos_iff @[bound] theorem log_nonpos (hx : 0 ≤ x) (h'x : x ≤ 1) : log x ≤ 0 := (log_nonpos_iff hx).2 h'x theorem log_natCast_nonneg (n : ℕ) : 0 ≤ log n := by if hn : n = 0 then simp [hn] else have : (1 : ℝ) ≤ n := mod_cast Nat.one_le_of_lt <| Nat.pos_of_ne_zero hn exact log_nonneg this theorem log_neg_natCast_nonneg (n : ℕ) : 0 ≤ log (-n) := by rw [← log_neg_eq_log, neg_neg] exact log_natCast_nonneg _ theorem log_intCast_nonneg (n : ℤ) : 0 ≤ log n := by cases lt_trichotomy 0 n with | inl hn => have : (1 : ℝ) ≤ n := mod_cast hn exact log_nonneg this | inr hn => cases hn with | inl hn => simp [hn.symm] | inr hn => have : (1 : ℝ) ≤ -n := by rw [← neg_zero, ← lt_neg] at hn; exact mod_cast hn rw [← log_neg_eq_log] exact log_nonneg this theorem strictMonoOn_log : StrictMonoOn log (Set.Ioi 0) := fun _ hx _ _ hxy => log_lt_log hx hxy theorem strictAntiOn_log : StrictAntiOn log (Set.Iio 0) := by rintro x (hx : x < 0) y (hy : y < 0) hxy rw [← log_abs y, ← log_abs x] refine log_lt_log (abs_pos.2 hy.ne) ?_ rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff] theorem log_injOn_pos : Set.InjOn log (Set.Ioi 0) := strictMonoOn_log.injOn theorem log_lt_sub_one_of_pos (hx1 : 0 < x) (hx2 : x ≠ 1) : log x < x - 1 := by have h : log x ≠ 0 := by rwa [← log_one, log_injOn_pos.ne_iff hx1] exact mem_Ioi.mpr zero_lt_one linarith [add_one_lt_exp h, exp_log hx1] theorem eq_one_of_pos_of_log_eq_zero {x : ℝ} (h₁ : 0 < x) (h₂ : log x = 0) : x = 1 := log_injOn_pos (Set.mem_Ioi.2 h₁) (Set.mem_Ioi.2 zero_lt_one) (h₂.trans Real.log_one.symm) theorem log_ne_zero_of_pos_of_ne_one {x : ℝ} (hx_pos : 0 < x) (hx : x ≠ 1) : log x ≠ 0 := mt (eq_one_of_pos_of_log_eq_zero hx_pos) hx @[simp] theorem log_eq_zero {x : ℝ} : log x = 0 ↔ x = 0 ∨ x = 1 ∨ x = -1 := by constructor · intro h rcases lt_trichotomy x 0 with (x_lt_zero | rfl | x_gt_zero) · refine Or.inr (Or.inr (neg_eq_iff_eq_neg.mp ?_)) rw [← log_neg_eq_log x] at h exact eq_one_of_pos_of_log_eq_zero (neg_pos.mpr x_lt_zero) h · exact Or.inl rfl · exact Or.inr (Or.inl (eq_one_of_pos_of_log_eq_zero x_gt_zero h)) · rintro (rfl | rfl | rfl) <;> simp only [log_one, log_zero, log_neg_eq_log] theorem log_ne_zero {x : ℝ} : log x ≠ 0 ↔ x ≠ 0 ∧ x ≠ 1 ∧ x ≠ -1 := by simpa only [not_or] using log_eq_zero.not @[simp] theorem log_pow (x : ℝ) (n : ℕ) : log (x ^ n) = n * log x := by induction n with | zero => simp | succ n ih => rcases eq_or_ne x 0 with (rfl | hx) · simp · rw [pow_succ, log_mul (pow_ne_zero _ hx) hx, ih, Nat.cast_succ, add_mul, one_mul] @[simp] theorem log_zpow (x : ℝ) (n : ℤ) : log (x ^ n) = n * log x := by cases n · rw [Int.ofNat_eq_coe, zpow_natCast, log_pow, Int.cast_natCast] · rw [zpow_negSucc, log_inv, log_pow, Int.cast_negSucc, Nat.cast_add_one, neg_mul_eq_neg_mul] theorem log_sqrt {x : ℝ} (hx : 0 ≤ x) : log (√x) = log x / 2 := by rw [eq_div_iff, mul_comm, ← Nat.cast_two, ← log_pow, sq_sqrt hx] exact two_ne_zero theorem log_le_sub_one_of_pos {x : ℝ} (hx : 0 < x) : log x ≤ x - 1 := by rw [le_sub_iff_add_le] convert add_one_le_exp (log x) rw [exp_log hx] lemma one_sub_inv_le_log_of_pos (hx : 0 < x) : 1 - x⁻¹ ≤ log x := by simpa [add_comm] using log_le_sub_one_of_pos (inv_pos.2 hx) /-- See `Real.log_le_sub_one_of_pos` for the stronger version when `x ≠ 0`. -/ lemma log_le_self (hx : 0 ≤ x) : log x ≤ x := by obtain rfl | hx := hx.eq_or_lt · simp · exact (log_le_sub_one_of_pos hx).trans (by linarith) /-- See `Real.one_sub_inv_le_log_of_pos` for the stronger version when `x ≠ 0`. -/ lemma neg_inv_le_log (hx : 0 ≤ x) : -x⁻¹ ≤ log x := by rw [neg_le, ← log_inv]; exact log_le_self <| inv_nonneg.2 hx /-- Bound for `|log x * x|` in the interval `(0, 1]`. -/ theorem abs_log_mul_self_lt (x : ℝ) (h1 : 0 < x) (h2 : x ≤ 1) : |log x * x| < 1 := by have : 0 < 1 / x := by simpa only [one_div, inv_pos] using h1 replace := log_le_sub_one_of_pos this replace : log (1 / x) < 1 / x := by linarith rw [log_div one_ne_zero h1.ne', log_one, zero_sub, lt_div_iff₀ h1] at this have aux : 0 ≤ -log x * x := by refine mul_nonneg ?_ h1.le rw [← log_inv] apply log_nonneg rw [← le_inv_comm₀ h1 zero_lt_one, inv_one] exact h2 rw [← abs_of_nonneg aux, neg_mul, abs_neg] at this exact this /-- The real logarithm function tends to `+∞` at `+∞`. -/ theorem tendsto_log_atTop : Tendsto log atTop atTop := tendsto_comp_exp_atTop.1 <| by simpa only [log_exp] using tendsto_id lemma tendsto_log_nhdsGT_zero : Tendsto log (𝓝[>] 0) atBot := by simpa [← tendsto_comp_exp_atBot] using tendsto_id @[deprecated (since := "2025-03-18")] alias tendsto_log_nhdsWithin_zero_right := tendsto_log_nhdsGT_zero theorem tendsto_log_nhdsNE_zero : Tendsto log (𝓝[≠] 0) atBot := by simpa [comp_def] using tendsto_log_nhdsGT_zero.comp tendsto_abs_nhdsNE_zero @[deprecated (since := "2025-03-18")] alias tendsto_log_nhdsWithin_zero := tendsto_log_nhdsNE_zero lemma tendsto_log_nhdsLT_zero : Tendsto log (𝓝[<] 0) atBot := tendsto_log_nhdsNE_zero.mono_left <| nhdsWithin_mono _ fun _ h ↦ ne_of_lt h @[deprecated (since := "2025-03-18")] alias tendsto_log_nhdsWithin_zero_left := tendsto_log_nhdsLT_zero
Mathlib/Analysis/SpecialFunctions/Log/Basic.lean
343
344
theorem continuousOn_log : ContinuousOn log {0}ᶜ := by
simp +unfoldPartialApp only [continuousOn_iff_continuous_restrict,
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Topology import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.Seminorm import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.RCLike.Basic /-! # The Minkowski functional This file defines the Minkowski functional, aka gauge. The Minkowski functional of a set `s` is the function which associates each point to how much you need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This induces the equivalence of seminorms and locally convex topological vector spaces. ## Main declarations For a real vector space, * `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such that `x ∈ r • s`. * `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and absorbent. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags Minkowski functional, gauge -/ open NormedField Set open scoped Pointwise Topology NNReal noncomputable section variable {𝕜 E : Type*} section AddCommGroup variable [AddCommGroup E] [Module ℝ E] /-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/ def gauge (s : Set E) (x : E) : ℝ := sInf { r : ℝ | 0 < r ∧ x ∈ r • s } variable {s t : Set E} {x : E} {a : ℝ} theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) := rfl /-- An alternative definition of the gauge using scalar multiplication on the element rather than on the set. -/ theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by congrm sInf {r | ?_} exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _ private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } := ⟨0, fun _ hr => hr.1.le⟩ /-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty, which is useful for proving many properties about the gauge. -/ theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) : { r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty := let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos ⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩ theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ => csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩ theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) : ∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h exact ⟨b, hb, hba, hx⟩ /-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s` but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/ @[simp] theorem gauge_zero : gauge s 0 = 0 := by rw [gauge_def'] by_cases h : (0 : E) ∈ s · simp only [smul_zero, sep_true, h, csInf_Ioi] · simp only [smul_zero, sep_false, h, Real.sInf_empty] @[simp] theorem gauge_zero' : gauge (0 : Set E) = 0 := by ext x rw [gauge_def'] obtain rfl | hx := eq_or_ne x 0 · simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero] · simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero] convert Real.sInf_empty exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx @[simp] theorem gauge_empty : gauge (∅ : Set E) = 0 := by ext simp only [gauge_def', Real.sInf_empty, mem_empty_iff_false, Pi.zero_apply, sep_false] theorem gauge_of_subset_zero (h : s ⊆ 0) : gauge s = 0 := by obtain rfl | rfl := subset_singleton_iff_eq.1 h exacts [gauge_empty, gauge_zero'] /-- The gauge is always nonnegative. -/ theorem gauge_nonneg (x : E) : 0 ≤ gauge s x := Real.sInf_nonneg fun _ hx => hx.1.le theorem gauge_neg (symmetric : ∀ x ∈ s, -x ∈ s) (x : E) : gauge s (-x) = gauge s x := by have : ∀ x, -x ∈ s ↔ x ∈ s := fun x => ⟨fun h => by simpa using symmetric _ h, symmetric x⟩ simp_rw [gauge_def', smul_neg, this] theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by simp_rw [gauge_def', smul_neg, neg_mem_neg] theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by rw [← gauge_neg_set_neg, neg_neg] theorem gauge_le_of_mem (ha : 0 ≤ a) (hx : x ∈ a • s) : gauge s x ≤ a := by obtain rfl | ha' := ha.eq_or_lt · rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero] · exact csInf_le gauge_set_bddBelow ⟨ha', hx⟩ theorem gauge_le_eq (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : Absorbent ℝ s) (ha : 0 ≤ a) : { x | gauge s x ≤ a } = ⋂ (r : ℝ) (_ : a < r), r • s := by ext x simp_rw [Set.mem_iInter, Set.mem_setOf_eq] refine ⟨fun h r hr => ?_, fun h => le_of_forall_pos_lt_add fun ε hε => ?_⟩ · have hr' := ha.trans_lt hr rw [mem_smul_set_iff_inv_smul_mem₀ hr'.ne'] obtain ⟨δ, δ_pos, hδr, hδ⟩ := exists_lt_of_gauge_lt hs₂ (h.trans_lt hr) suffices (r⁻¹ * δ) • δ⁻¹ • x ∈ s by rwa [smul_smul, mul_inv_cancel_right₀ δ_pos.ne'] at this rw [mem_smul_set_iff_inv_smul_mem₀ δ_pos.ne'] at hδ refine hs₁.smul_mem_of_zero_mem hs₀ hδ ⟨by positivity, ?_⟩ rw [inv_mul_le_iff₀ hr', mul_one] exact hδr.le · have hε' := (lt_add_iff_pos_right a).2 (half_pos hε) exact (gauge_le_of_mem (ha.trans hε'.le) <| h _ hε').trans_lt (add_lt_add_left (half_lt_self hε) _) theorem gauge_lt_eq' (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ (r : ℝ) (_ : 0 < r) (_ : r < a), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ theorem gauge_lt_eq (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ r ∈ Set.Ioo 0 (a : ℝ), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop, mem_Ioo, and_assoc] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ theorem mem_openSegment_of_gauge_lt_one (absorbs : Absorbent ℝ s) (hgauge : gauge s x < 1) : ∃ y ∈ s, x ∈ openSegment ℝ 0 y := by rcases exists_lt_of_gauge_lt absorbs hgauge with ⟨r, hr₀, hr₁, y, hy, rfl⟩ refine ⟨y, hy, 1 - r, r, ?_⟩ simp [*] theorem gauge_lt_one_subset_self (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) : { x | gauge s x < 1 } ⊆ s := fun _x hx ↦ let ⟨_y, hys, hx⟩ := mem_openSegment_of_gauge_lt_one absorbs hx hs.openSegment_subset h₀ hys hx theorem gauge_le_one_of_mem {x : E} (hx : x ∈ s) : gauge s x ≤ 1 := gauge_le_of_mem zero_le_one <| by rwa [one_smul] /-- Gauge is subadditive. -/ theorem gauge_add_le (hs : Convex ℝ s) (absorbs : Absorbent ℝ s) (x y : E) : gauge s (x + y) ≤ gauge s x + gauge s y := by refine le_of_forall_pos_lt_add fun ε hε => ?_ obtain ⟨a, ha, ha', x, hx, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s x) (half_pos hε)) obtain ⟨b, hb, hb', y, hy, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s y) (half_pos hε)) calc gauge s (a • x + b • y) ≤ a + b := gauge_le_of_mem (by positivity) <| by rw [hs.add_smul ha.le hb.le] exact add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) _ < gauge s (a • x) + gauge s (b • y) + ε := by linarith theorem self_subset_gauge_le_one : s ⊆ { x | gauge s x ≤ 1 } := fun _ => gauge_le_one_of_mem theorem Convex.gauge_le (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) (a : ℝ) : Convex ℝ { x | gauge s x ≤ a } := by by_cases ha : 0 ≤ a · rw [gauge_le_eq hs h₀ absorbs ha] exact convex_iInter fun i => convex_iInter fun _ => hs.smul _ · convert convex_empty (𝕜 := ℝ) exact eq_empty_iff_forall_not_mem.2 fun x hx => ha <| (gauge_nonneg _).trans hx theorem Balanced.starConvex (hs : Balanced ℝ s) : StarConvex ℝ 0 s := starConvex_zero_iff.2 fun _ hx a ha₀ ha₁ => hs _ (by rwa [Real.norm_of_nonneg ha₀]) (smul_mem_smul_set hx) theorem le_gauge_of_not_mem (hs₀ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ a • s) : a ≤ gauge s x := by rw [starConvex_zero_iff] at hs₀ obtain ⟨r, hr, h⟩ := hs₂.exists_pos refine le_csInf ⟨r, hr, singleton_subset_iff.1 <| h _ (Real.norm_of_nonneg hr.le).ge⟩ ?_ rintro b ⟨hb, x, hx', rfl⟩ refine not_lt.1 fun hba => hx ?_ have ha := hb.trans hba refine ⟨(a⁻¹ * b) • x, hs₀ hx' (by positivity) ?_, ?_⟩ · rw [← div_eq_inv_mul] exact div_le_one_of_le₀ hba.le ha.le · dsimp only rw [← mul_smul, mul_inv_cancel_left₀ ha.ne'] theorem one_le_gauge_of_not_mem (hs₁ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ s) : 1 ≤ gauge s x := le_gauge_of_not_mem hs₁ hs₂ <| by rwa [one_smul] section LinearOrderedField variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] [MulActionWithZero α ℝ] [OrderedSMul α ℝ] theorem gauge_smul_of_nonneg [MulActionWithZero α E] [IsScalarTower α ℝ (Set E)] {s : Set E} {a : α} (ha : 0 ≤ a) (x : E) : gauge s (a • x) = a • gauge s x := by obtain rfl | ha' := ha.eq_or_lt · rw [zero_smul, gauge_zero, zero_smul] rw [gauge_def', gauge_def', ← Real.sInf_smul_of_nonneg ha] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, hx⟩ simp_rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos (inv_pos.2 ha') hr refine ⟨a⁻¹ • r, ⟨this, ?_⟩, smul_inv_smul₀ ha'.ne' _⟩ rwa [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc, mem_smul_set_iff_inv_smul_mem₀ (inv_ne_zero ha'.ne'), inv_inv] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos ha' hr refine ⟨this, ?_⟩ rw [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc] exact smul_mem_smul_set hx theorem gauge_smul_left_of_nonneg [MulActionWithZero α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} {a : α} (ha : 0 ≤ a) : gauge (a • s) = a⁻¹ • gauge s := by obtain rfl | ha' := ha.eq_or_lt · rw [inv_zero, zero_smul, gauge_of_subset_zero (zero_smul_set_subset _)] ext x rw [gauge_def', Pi.smul_apply, gauge_def', ← Real.sInf_smul_of_nonneg (inv_nonneg.2 ha)] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, y, hy, h⟩ simp_rw [mem_Ioi] at hr ⊢ refine ⟨a • r, ⟨smul_pos ha' hr, ?_⟩, inv_smul_smul₀ ha'.ne' _⟩ rwa [smul_inv₀, smul_assoc, ← h, inv_smul_smul₀ ha'.ne'] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ refine ⟨smul_pos (inv_pos.2 ha') hr, r⁻¹ • x, hx, ?_⟩ rw [smul_inv₀, smul_assoc, inv_inv] theorem gauge_smul_left [Module α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} (symmetric : ∀ x ∈ s, -x ∈ s) (a : α) : gauge (a • s) = |a|⁻¹ • gauge s := by rw [← gauge_smul_left_of_nonneg (abs_nonneg a)] obtain h | h := abs_choice a · rw [h] · rw [h, Set.neg_smul_set, ← Set.smul_set_neg] -- Porting note: was congr apply congr_arg apply congr_arg ext y refine ⟨symmetric _, fun hy => ?_⟩ rw [← neg_neg y] exact symmetric _ hy end LinearOrderedField section RCLike variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E] theorem gauge_norm_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (‖r‖ • x) = gauge s (r • x) := by unfold gauge congr with θ rw [@RCLike.real_smul_eq_coe_smul 𝕜] refine and_congr_right fun hθ => (hs.smul _).smul_mem_iff ?_ rw [RCLike.norm_ofReal, abs_norm] /-- If `s` is balanced, then the Minkowski functional is ℂ-homogeneous. -/ theorem gauge_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (r • x) = ‖r‖ * gauge s x := by rw [← smul_eq_mul, ← gauge_smul_of_nonneg (norm_nonneg r), gauge_norm_smul hs] end RCLike open Filter section TopologicalSpace variable [TopologicalSpace E] theorem comap_gauge_nhds_zero_le (ha : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : comap (gauge s) (𝓝 0) ≤ 𝓝 0 := fun u hu ↦ by rcases (hb hu).exists_pos with ⟨r, hr₀, hr⟩ filter_upwards [preimage_mem_comap (gt_mem_nhds (inv_pos.2 hr₀))] with x (hx : gauge s x < r⁻¹) rcases exists_lt_of_gauge_lt ha hx with ⟨c, hc₀, hcr, y, hy, rfl⟩ have hrc := (lt_inv_comm₀ hr₀ hc₀).2 hcr rcases hr c⁻¹ (hrc.le.trans (le_abs_self _)) hy with ⟨z, hz, rfl⟩ simpa only [smul_inv_smul₀ hc₀.ne'] variable [T1Space E]
Mathlib/Analysis/Convex/Gauge.lean
325
331
theorem gauge_eq_zero (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : gauge s x = 0 ↔ x = 0 := by
refine ⟨fun h₀ ↦ by_contra fun (hne : x ≠ 0) ↦ ?_, fun h ↦ h.symm ▸ gauge_zero⟩ have : {x}ᶜ ∈ comap (gauge s) (𝓝 0) := comap_gauge_nhds_zero_le hs hb (isOpen_compl_singleton.mem_nhds hne.symm) rcases ((nhds_basis_zero_abs_lt _).comap _).mem_iff.1 this with ⟨r, hr₀, hr⟩ exact hr (by simpa [h₀]) rfl
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker, Anne Baanen -/ import Mathlib.Algebra.BigOperators.Finsupp.Basic import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.GroupWithZero.Associated /-! # Products of associated, prime, and irreducible elements. This file contains some theorems relating definitions in `Algebra.Associated` and products of multisets, finsets, and finsupps. -/ assert_not_exists Field variable {α β γ δ : Type*} -- the same local notation used in `Algebra.Associated` local infixl:50 " ~ᵤ " => Associated namespace Prime variable [CommMonoidWithZero α] {p : α} theorem exists_mem_multiset_dvd (hp : Prime p) {s : Multiset α} : p ∣ s.prod → ∃ a ∈ s, p ∣ a := Multiset.induction_on s (fun h => (hp.not_dvd_one h).elim) fun a s ih h => have : p ∣ a * s.prod := by simpa using h match hp.dvd_or_dvd this with | Or.inl h => ⟨a, Multiset.mem_cons_self a s, h⟩ | Or.inr h => let ⟨a, has, h⟩ := ih h ⟨a, Multiset.mem_cons_of_mem has, h⟩ theorem exists_mem_multiset_map_dvd (hp : Prime p) {s : Multiset β} {f : β → α} : p ∣ (s.map f).prod → ∃ a ∈ s, p ∣ f a := fun h => by simpa only [exists_prop, Multiset.mem_map, exists_exists_and_eq_and] using hp.exists_mem_multiset_dvd h theorem exists_mem_finset_dvd (hp : Prime p) {s : Finset β} {f : β → α} : p ∣ s.prod f → ∃ i ∈ s, p ∣ f i := hp.exists_mem_multiset_map_dvd end Prime theorem Prod.associated_iff {M N : Type*} [Monoid M] [Monoid N] {x z : M × N} : x ~ᵤ z ↔ x.1 ~ᵤ z.1 ∧ x.2 ~ᵤ z.2 := ⟨fun ⟨u, hu⟩ => ⟨⟨(MulEquiv.prodUnits.toFun u).1, (Prod.eq_iff_fst_eq_snd_eq.1 hu).1⟩, ⟨(MulEquiv.prodUnits.toFun u).2, (Prod.eq_iff_fst_eq_snd_eq.1 hu).2⟩⟩, fun ⟨⟨u₁, h₁⟩, ⟨u₂, h₂⟩⟩ => ⟨MulEquiv.prodUnits.invFun (u₁, u₂), Prod.eq_iff_fst_eq_snd_eq.2 ⟨h₁, h₂⟩⟩⟩ theorem Associated.prod {M : Type*} [CommMonoid M] {ι : Type*} (s : Finset ι) (f : ι → M) (g : ι → M) (h : ∀ i, i ∈ s → (f i) ~ᵤ (g i)) : (∏ i ∈ s, f i) ~ᵤ (∏ i ∈ s, g i) := by induction s using Finset.induction with | empty => simp only [Finset.prod_empty] rfl | insert j s hjs IH => classical convert_to (∏ i ∈ insert j s, f i) ~ᵤ (∏ i ∈ insert j s, g i) rw [Finset.prod_insert hjs, Finset.prod_insert hjs] exact Associated.mul_mul (h j (Finset.mem_insert_self j s)) (IH (fun i hi ↦ h i (Finset.mem_insert_of_mem hi))) theorem exists_associated_mem_of_dvd_prod [CancelCommMonoidWithZero α] {p : α} (hp : Prime p) {s : Multiset α} : (∀ r ∈ s, Prime r) → p ∣ s.prod → ∃ q ∈ s, p ~ᵤ q := Multiset.induction_on s (by simp [mt isUnit_iff_dvd_one.2 hp.not_unit]) fun a s ih hs hps => by rw [Multiset.prod_cons] at hps rcases hp.dvd_or_dvd hps with h | h · have hap := hs a (Multiset.mem_cons.2 (Or.inl rfl)) exact ⟨a, Multiset.mem_cons_self a _, hp.associated_of_dvd hap h⟩ · rcases ih (fun r hr => hs _ (Multiset.mem_cons.2 (Or.inr hr))) h with ⟨q, hq₁, hq₂⟩ exact ⟨q, Multiset.mem_cons.2 (Or.inr hq₁), hq₂⟩ open Submonoid in /-- Let x, y ∈ α. If x * y can be written as a product of units and prime elements, then x can be written as a product of units and prime elements. -/ theorem divisor_closure_eq_closure [CancelCommMonoidWithZero α] (x y : α) (hxy : x * y ∈ closure { r : α | IsUnit r ∨ Prime r}) : x ∈ closure { r : α | IsUnit r ∨ Prime r} := by obtain ⟨m, hm, hprod⟩ := exists_multiset_of_mem_closure hxy induction m using Multiset.induction generalizing x y with | empty => apply subset_closure simp only [Set.mem_setOf] simp only [Multiset.prod_zero] at hprod left; exact isUnit_of_mul_eq_one _ _ hprod.symm | cons c s hind => simp only [Multiset.mem_cons, forall_eq_or_imp, Set.mem_setOf] at hm simp only [Multiset.prod_cons] at hprod simp only [Set.mem_setOf_eq] at hind obtain ⟨ha₁ | ha₂, hs⟩ := hm · rcases ha₁.exists_right_inv with ⟨k, hk⟩ refine hind x (y*k) ?_ hs ?_ · simp only [← mul_assoc, ← hprod, ← Multiset.prod_cons, mul_comm] refine multiset_prod_mem _ _ (Multiset.forall_mem_cons.2 ⟨subset_closure (Set.mem_def.2 ?_), Multiset.forall_mem_cons.2 ⟨subset_closure (Set.mem_def.2 ?_), (fun t ht => subset_closure (hs t ht))⟩⟩) · left; exact isUnit_of_mul_eq_one_right _ _ hk · left; exact ha₁ · rw [← mul_one s.prod, ← hk, ← mul_assoc, ← mul_assoc, mul_eq_mul_right_iff, mul_comm] left; exact hprod · rcases ha₂.dvd_mul.1 (Dvd.intro _ hprod) with ⟨c, hc⟩ | ⟨c, hc⟩ · rw [hc]; rw [hc, mul_assoc] at hprod refine Submonoid.mul_mem _ (subset_closure (Set.mem_def.2 ?_)) (hind _ _ ?_ hs (mul_left_cancel₀ ha₂.ne_zero hprod)) · right; exact ha₂ rw [← mul_left_cancel₀ ha₂.ne_zero hprod] exact multiset_prod_mem _ _ (fun t ht => subset_closure (hs t ht)) rw [hc, mul_comm x _, mul_assoc, mul_comm c _] at hprod refine hind x c ?_ hs (mul_left_cancel₀ ha₂.ne_zero hprod) rw [← mul_left_cancel₀ ha₂.ne_zero hprod] exact multiset_prod_mem _ _ (fun t ht => subset_closure (hs t ht)) theorem Multiset.prod_primes_dvd [CancelCommMonoidWithZero α] [∀ a : α, DecidablePred (Associated a)] {s : Multiset α} (n : α) (h : ∀ a ∈ s, Prime a) (div : ∀ a ∈ s, a ∣ n) (uniq : ∀ a, s.countP (Associated a) ≤ 1) : s.prod ∣ n := by induction s using Multiset.induction_on generalizing n with | empty => simp only [Multiset.prod_zero, one_dvd] | cons a s induct => rw [Multiset.prod_cons] obtain ⟨k, rfl⟩ : a ∣ n := div a (Multiset.mem_cons_self a s) apply mul_dvd_mul_left a refine induct _ (fun a ha => h a (Multiset.mem_cons_of_mem ha)) (fun b b_in_s => ?_) fun a => (Multiset.countP_le_of_le _ (Multiset.le_cons_self _ _)).trans (uniq a) have b_div_n := div b (Multiset.mem_cons_of_mem b_in_s) have a_prime := h a (Multiset.mem_cons_self a s) have b_prime := h b (Multiset.mem_cons_of_mem b_in_s) refine (b_prime.dvd_or_dvd b_div_n).resolve_left fun b_div_a => ?_ have assoc := b_prime.associated_of_dvd a_prime b_div_a have := uniq a rw [Multiset.countP_cons_of_pos _ (Associated.refl _), Nat.succ_le_succ_iff, ← not_lt, Multiset.countP_pos] at this exact this ⟨b, b_in_s, assoc.symm⟩ theorem Finset.prod_primes_dvd [CancelCommMonoidWithZero α] [Subsingleton αˣ] {s : Finset α} (n : α) (h : ∀ a ∈ s, Prime a) (div : ∀ a ∈ s, a ∣ n) : (∏ p ∈ s, p) ∣ n := by classical exact Multiset.prod_primes_dvd n (by simpa only [Multiset.map_id', Finset.mem_def] using h) (by simpa only [Multiset.map_id', Finset.mem_def] using div) (by simp only [Multiset.map_id', associated_eq_eq, Multiset.countP_eq_card_filter, ← s.val.count_eq_card_filter_eq, ← Multiset.nodup_iff_count_le_one, s.nodup]) namespace Associates section CommMonoid variable [CommMonoid α] theorem prod_mk {p : Multiset α} : (p.map Associates.mk).prod = Associates.mk p.prod := Multiset.induction_on p (by simp) fun a s ih => by simp [ih, Associates.mk_mul_mk]
Mathlib/Algebra/BigOperators/Associated.lean
159
168
theorem finset_prod_mk {p : Finset β} {f : β → α} : (∏ i ∈ p, Associates.mk (f i)) = Associates.mk (∏ i ∈ p, f i) := by
rw [Finset.prod_eq_multiset_prod, ← Function.comp_def, ← Multiset.map_map, prod_mk, ← Finset.prod_eq_multiset_prod] theorem rel_associated_iff_map_eq_map {p q : Multiset α} : Multiset.Rel Associated p q ↔ p.map Associates.mk = q.map Associates.mk := by rw [← Multiset.rel_eq, Multiset.rel_map] simp only [mk_eq_mk_iff_associated]
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Geometry.Manifold.MFDeriv.FDeriv /-! # Differentiability of specific functions In this file, we establish differentiability results for - continuous linear maps and continuous linear equivalences - the identity - constant functions - products - arithmetic operations (such as addition and scalar multiplication). -/ noncomputable section open scoped Manifold open Bundle Set Topology section SpecificFunctions /-! ### Differentiability of specific functions -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] -- declare a charted space `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] -- declare a charted space `M'` over the pair `(E', H')`. {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] -- declare a charted space `M''` over the pair `(E'', H'')`. {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] -- declare a charted space `N` over the pair `(F, G)`. {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [TopologicalSpace G] {J : ModelWithCorners 𝕜 F G} {N : Type*} [TopologicalSpace N] [ChartedSpace G N] -- declare a charted space `N'` over the pair `(F', G')`. {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {G' : Type*} [TopologicalSpace G'] {J' : ModelWithCorners 𝕜 F' G'} {N' : Type*} [TopologicalSpace N'] [ChartedSpace G' N'] -- F₁, F₂, F₃, F₄ are normed spaces {F₁ : Type*} [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] {F₂ : Type*} [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] {F₃ : Type*} [NormedAddCommGroup F₃] [NormedSpace 𝕜 F₃] {F₄ : Type*} [NormedAddCommGroup F₄] [NormedSpace 𝕜 F₄] namespace ContinuousLinearMap variable (f : E →L[𝕜] E') {s : Set E} {x : E} protected theorem hasMFDerivWithinAt : HasMFDerivWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x f := f.hasFDerivWithinAt.hasMFDerivWithinAt protected theorem hasMFDerivAt : HasMFDerivAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x f := f.hasFDerivAt.hasMFDerivAt protected theorem mdifferentiableWithinAt : MDifferentiableWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x := f.differentiableWithinAt.mdifferentiableWithinAt protected theorem mdifferentiableOn : MDifferentiableOn 𝓘(𝕜, E) 𝓘(𝕜, E') f s := f.differentiableOn.mdifferentiableOn protected theorem mdifferentiableAt : MDifferentiableAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x := f.differentiableAt.mdifferentiableAt protected theorem mdifferentiable : MDifferentiable 𝓘(𝕜, E) 𝓘(𝕜, E') f := f.differentiable.mdifferentiable theorem mfderiv_eq : mfderiv 𝓘(𝕜, E) 𝓘(𝕜, E') f x = f := f.hasMFDerivAt.mfderiv theorem mfderivWithin_eq (hs : UniqueMDiffWithinAt 𝓘(𝕜, E) s x) : mfderivWithin 𝓘(𝕜, E) 𝓘(𝕜, E') f s x = f := f.hasMFDerivWithinAt.mfderivWithin hs end ContinuousLinearMap namespace ContinuousLinearEquiv variable (f : E ≃L[𝕜] E') {s : Set E} {x : E} protected theorem hasMFDerivWithinAt : HasMFDerivWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x (f : E →L[𝕜] E') := f.hasFDerivWithinAt.hasMFDerivWithinAt protected theorem hasMFDerivAt : HasMFDerivAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x (f : E →L[𝕜] E') := f.hasFDerivAt.hasMFDerivAt protected theorem mdifferentiableWithinAt : MDifferentiableWithinAt 𝓘(𝕜, E) 𝓘(𝕜, E') f s x := f.differentiableWithinAt.mdifferentiableWithinAt protected theorem mdifferentiableOn : MDifferentiableOn 𝓘(𝕜, E) 𝓘(𝕜, E') f s := f.differentiableOn.mdifferentiableOn protected theorem mdifferentiableAt : MDifferentiableAt 𝓘(𝕜, E) 𝓘(𝕜, E') f x := f.differentiableAt.mdifferentiableAt protected theorem mdifferentiable : MDifferentiable 𝓘(𝕜, E) 𝓘(𝕜, E') f := f.differentiable.mdifferentiable theorem mfderiv_eq : mfderiv 𝓘(𝕜, E) 𝓘(𝕜, E') f x = (f : E →L[𝕜] E') := f.hasMFDerivAt.mfderiv theorem mfderivWithin_eq (hs : UniqueMDiffWithinAt 𝓘(𝕜, E) s x) : mfderivWithin 𝓘(𝕜, E) 𝓘(𝕜, E') f s x = (f : E →L[𝕜] E') := f.hasMFDerivWithinAt.mfderivWithin hs end ContinuousLinearEquiv variable {s : Set M} {x : M} section id /-! #### Identity -/ theorem hasMFDerivAt_id (x : M) : HasMFDerivAt I I (@id M) x (ContinuousLinearMap.id 𝕜 (TangentSpace I x)) := by refine ⟨continuousAt_id, ?_⟩ have : ∀ᶠ y in 𝓝[range I] (extChartAt I x) x, (extChartAt I x ∘ (extChartAt I x).symm) y = y := by apply Filter.mem_of_superset (extChartAt_target_mem_nhdsWithin x) mfld_set_tac apply HasFDerivWithinAt.congr_of_eventuallyEq (hasFDerivWithinAt_id _ _) this simp only [mfld_simps] theorem hasMFDerivWithinAt_id (s : Set M) (x : M) : HasMFDerivWithinAt I I (@id M) s x (ContinuousLinearMap.id 𝕜 (TangentSpace I x)) := (hasMFDerivAt_id x).hasMFDerivWithinAt theorem mdifferentiableAt_id : MDifferentiableAt I I (@id M) x := (hasMFDerivAt_id x).mdifferentiableAt theorem mdifferentiableWithinAt_id : MDifferentiableWithinAt I I (@id M) s x := mdifferentiableAt_id.mdifferentiableWithinAt theorem mdifferentiable_id : MDifferentiable I I (@id M) := fun _ => mdifferentiableAt_id theorem mdifferentiableOn_id : MDifferentiableOn I I (@id M) s := mdifferentiable_id.mdifferentiableOn @[simp, mfld_simps] theorem mfderiv_id : mfderiv I I (@id M) x = ContinuousLinearMap.id 𝕜 (TangentSpace I x) := HasMFDerivAt.mfderiv (hasMFDerivAt_id x) theorem mfderivWithin_id (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I (@id M) s x = ContinuousLinearMap.id 𝕜 (TangentSpace I x) := by rw [MDifferentiable.mfderivWithin mdifferentiableAt_id hxs] exact mfderiv_id @[simp, mfld_simps]
Mathlib/Geometry/Manifold/MFDeriv/SpecificFunctions.lean
157
160
theorem tangentMap_id : tangentMap I I (id : M → M) = id := by
ext1 ⟨x, v⟩; simp [tangentMap] theorem tangentMapWithin_id {p : TangentBundle I M} (hs : UniqueMDiffWithinAt I s p.proj) : tangentMapWithin I I (id : M → M) s p = p := by
/- Copyright (c) 2021 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots import Mathlib.Tactic.ByContra import Mathlib.Topology.Algebra.Polynomial import Mathlib.NumberTheory.Padics.PadicVal.Basic import Mathlib.Analysis.Complex.Arg /-! # Evaluating cyclotomic polynomials This file states some results about evaluating cyclotomic polynomials in various different ways. ## Main definitions * `Polynomial.eval(₂)_one_cyclotomic_prime(_pow)`: `eval 1 (cyclotomic p^k R) = p`. * `Polynomial.eval_one_cyclotomic_not_prime_pow`: Otherwise, `eval 1 (cyclotomic n R) = 1`. * `Polynomial.cyclotomic_pos` : `∀ x, 0 < eval x (cyclotomic n R)` if `2 < n`. -/ namespace Polynomial open Finset Nat @[simp] theorem eval_one_cyclotomic_prime {R : Type*} [CommRing R] {p : ℕ} [hn : Fact p.Prime] : eval 1 (cyclotomic p R) = p := by simp only [cyclotomic_prime, eval_X, one_pow, Finset.sum_const, eval_pow, eval_finset_sum, Finset.card_range, smul_one_eq_cast] theorem eval₂_one_cyclotomic_prime {R S : Type*} [CommRing R] [Semiring S] (f : R →+* S) {p : ℕ} [Fact p.Prime] : eval₂ f 1 (cyclotomic p R) = p := by simp @[simp] theorem eval_one_cyclotomic_prime_pow {R : Type*} [CommRing R] {p : ℕ} (k : ℕ) [hn : Fact p.Prime] : eval 1 (cyclotomic (p ^ (k + 1)) R) = p := by simp only [cyclotomic_prime_pow_eq_geom_sum hn.out, eval_X, one_pow, Finset.sum_const, eval_pow, eval_finset_sum, Finset.card_range, smul_one_eq_cast]
Mathlib/RingTheory/Polynomial/Cyclotomic/Eval.lean
41
44
theorem eval₂_one_cyclotomic_prime_pow {R S : Type*} [CommRing R] [Semiring S] (f : R →+* S) {p : ℕ} (k : ℕ) [Fact p.Prime] : eval₂ f 1 (cyclotomic (p ^ (k + 1)) R) = p := by
simp private theorem cyclotomic_neg_one_pos {n : ℕ} (hn : 2 < n) {R}
/- Copyright (c) 2024 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.Cyclotomic.PrimitiveRoots import Mathlib.NumberTheory.NumberField.Embeddings /-! # Cyclotomic extensions of `ℚ` are totally complex number fields. We prove that cyclotomic extensions of `ℚ` are totally complex, meaning that `NrRealPlaces K = 0` if `IsCyclotomicExtension {n} ℚ K` and `2 < n`. ## Main results * `nrRealPlaces_eq_zero`: If `K` is a `n`-th cyclotomic extension of `ℚ`, where `2 < n`, then there are no real places of `K`. -/ universe u namespace IsCyclotomicExtension.Rat open NumberField InfinitePlace Module Complex Nat Polynomial variable {n : ℕ+} (K : Type u) [Field K] [CharZero K] /-- If `K` is a `n`-th cyclotomic extension of `ℚ`, where `2 < n`, then there are no real places of `K`. -/
Mathlib/NumberTheory/Cyclotomic/Embeddings.lean
30
35
theorem nrRealPlaces_eq_zero [IsCyclotomicExtension {n} ℚ K] (hn : 2 < n) : haveI := IsCyclotomicExtension.numberField {n} ℚ K nrRealPlaces K = 0 := by
have := IsCyclotomicExtension.numberField {n} ℚ K apply (IsCyclotomicExtension.zeta_spec n ℚ K).nrRealPlaces_eq_zero_of_two_lt hn
/- 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, Devon Tuma -/ import Mathlib.Probability.ProbabilityMassFunction.Monad import Mathlib.Control.ULiftable /-! # Specific Constructions of Probability Mass Functions This file gives a number of different `PMF` constructions for common probability distributions. `map` and `seq` allow pushing a `PMF α` along a function `f : α → β` (or distribution of functions `f : PMF (α → β)`) to get a `PMF β`. `ofFinset` and `ofFintype` simplify the construction of a `PMF α` from a function `f : α → ℝ≥0∞`, by allowing the "sum equals 1" constraint to be in terms of `Finset.sum` instead of `tsum`. `normalize` constructs a `PMF α` by normalizing a function `f : α → ℝ≥0∞` by its sum, and `filter` uses this to filter the support of a `PMF` and re-normalize the new distribution. `bernoulli` represents the bernoulli distribution on `Bool`. -/ universe u v namespace PMF noncomputable section variable {α β γ : Type*} open NNReal ENNReal Finset MeasureTheory section Map /-- The functorial action of a function on a `PMF`. -/ def map (f : α → β) (p : PMF α) : PMF β := bind p (pure ∘ f) variable (f : α → β) (p : PMF α) (b : β) theorem monad_map_eq_map {α β : Type u} (f : α → β) (p : PMF α) : f <$> p = p.map f := rfl open scoped Classical in @[simp] theorem map_apply : (map f p) b = ∑' a, if b = f a then p a else 0 := by simp [map] @[simp] theorem support_map : (map f p).support = f '' p.support := Set.ext fun b => by simp [map, @eq_comm β b] theorem mem_support_map_iff : b ∈ (map f p).support ↔ ∃ a ∈ p.support, f a = b := by simp theorem bind_pure_comp : bind p (pure ∘ f) = map f p := rfl theorem map_id : map id p = p := bind_pure _ theorem map_comp (g : β → γ) : (p.map f).map g = p.map (g ∘ f) := by simp [map, Function.comp_def] theorem pure_map (a : α) : (pure a).map f = pure (f a) := pure_bind _ _ theorem map_bind (q : α → PMF β) (f : β → γ) : (p.bind q).map f = p.bind fun a => (q a).map f := bind_bind _ _ _ @[simp] theorem bind_map (p : PMF α) (f : α → β) (q : β → PMF γ) : (p.map f).bind q = p.bind (q ∘ f) := (bind_bind _ _ _).trans (congr_arg _ (funext fun _ => pure_bind _ _)) @[simp] theorem map_const : p.map (Function.const α b) = pure b := by simp only [map, Function.comp_def, bind_const, Function.const] section Measure variable (s : Set β) @[simp] theorem toOuterMeasure_map_apply : (p.map f).toOuterMeasure s = p.toOuterMeasure (f ⁻¹' s) := by simp [map, Set.indicator, toOuterMeasure_apply p (f ⁻¹' s)] rfl variable {mα : MeasurableSpace α} {mβ : MeasurableSpace β} @[simp] theorem toMeasure_map_apply (hf : Measurable f) (hs : MeasurableSet s) : (p.map f).toMeasure s = p.toMeasure (f ⁻¹' s) := by rw [toMeasure_apply_eq_toOuterMeasure_apply _ s hs, toMeasure_apply_eq_toOuterMeasure_apply _ (f ⁻¹' s) (measurableSet_preimage hf hs)] exact toOuterMeasure_map_apply f p s @[simp] lemma toMeasure_map (p : PMF α) (hf : Measurable f) : p.toMeasure.map f = (p.map f).toMeasure := by ext s hs : 1; rw [PMF.toMeasure_map_apply _ _ _ hf hs, Measure.map_apply hf hs] end Measure end Map section Seq /-- The monadic sequencing operation for `PMF`. -/ def seq (q : PMF (α → β)) (p : PMF α) : PMF β := q.bind fun m => p.bind fun a => pure (m a) variable (q : PMF (α → β)) (p : PMF α) (b : β) theorem monad_seq_eq_seq {α β : Type u} (q : PMF (α → β)) (p : PMF α) : q <*> p = q.seq p := rfl open scoped Classical in @[simp] theorem seq_apply : (seq q p) b = ∑' (f : α → β) (a : α), if b = f a then q f * p a else 0 := by simp only [seq, mul_boole, bind_apply, pure_apply] refine tsum_congr fun f => ENNReal.tsum_mul_left.symm.trans (tsum_congr fun a => ?_) simpa only [mul_zero] using mul_ite (b = f a) (q f) (p a) 0 @[simp] theorem support_seq : (seq q p).support = ⋃ f ∈ q.support, f '' p.support := Set.ext fun b => by simp [-mem_support_iff, seq, @eq_comm β b] theorem mem_support_seq_iff : b ∈ (seq q p).support ↔ ∃ f ∈ q.support, b ∈ f '' p.support := by simp end Seq instance : LawfulFunctor PMF where map_const := rfl id_map := bind_pure comp_map _ _ _ := (map_comp _ _ _).symm instance : LawfulMonad PMF := LawfulMonad.mk' (bind_pure_comp := fun _ _ => rfl) (id_map := id_map) (pure_bind := pure_bind) (bind_assoc := bind_bind) /-- This instance allows `do` notation for `PMF` to be used across universes, for instance as ```lean4 example {R : Type u} [Ring R] (x : PMF ℕ) : PMF R := do let ⟨n⟩ ← ULiftable.up x pure n ``` where `x` is in universe `0`, but the return value is in universe `u`. -/ instance : ULiftable PMF.{u} PMF.{v} where congr e := { toFun := map e, invFun := map e.symm left_inv := fun a => by simp [map_comp, map_id] right_inv := fun a => by simp [map_comp, map_id] } section OfFinset /-- Given a finset `s` and a function `f : α → ℝ≥0∞` with sum `1` on `s`, such that `f a = 0` for `a ∉ s`, we get a `PMF`. -/ def ofFinset (f : α → ℝ≥0∞) (s : Finset α) (h : ∑ a ∈ s, f a = 1) (h' : ∀ (a) (_ : a ∉ s), f a = 0) : PMF α := ⟨f, h ▸ hasSum_sum_of_ne_finset_zero h'⟩ variable {f : α → ℝ≥0∞} {s : Finset α} (h : ∑ a ∈ s, f a = 1) (h' : ∀ (a) (_ : a ∉ s), f a = 0) @[simp] theorem ofFinset_apply (a : α) : ofFinset f s h h' a = f a := rfl @[simp] theorem support_ofFinset : (ofFinset f s h h').support = ↑s ∩ Function.support f := Set.ext fun a => by simpa [mem_support_iff] using mt (h' a)
Mathlib/Probability/ProbabilityMassFunction/Constructions.lean
172
173
theorem mem_support_ofFinset_iff (a : α) : a ∈ (ofFinset f s h h').support ↔ a ∈ s ∧ f a ≠ 0 := by
simp
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot -/ import Mathlib.Data.Set.Image import Mathlib.Data.SProd /-! # Sets in product and pi types This file proves basic properties of product of sets in `α × β` and in `Π i, α i`, and of the diagonal of a type. ## Main declarations This file contains basic results on the following notions, which are defined in `Set.Operations`. * `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have `s.prod t : Set (α × β)`. Denoted by `s ×ˢ t`. * `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`. * `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal. * `Set.pi`: Arbitrary product of sets. -/ open Function namespace Set /-! ### Cartesian binary product of sets -/ section Prod variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β} theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) : (s ×ˢ t).Subsingleton := fun _x hx _y hy ↦ Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2) noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] : DecidablePred (· ∈ s ×ˢ t) := fun x => inferInstanceAs (Decidable (x.1 ∈ s ∧ x.2 ∈ t)) @[gcongr] theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ := fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩ @[gcongr] theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t := prod_mono hs Subset.rfl @[gcongr] theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ := prod_mono Subset.rfl ht @[simp] theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ := ⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩ @[simp] theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ := and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P := ⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩ theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) := prod_subset_iff theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by simp [and_assoc] @[simp] theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by ext exact iff_of_eq (and_false _) @[simp] theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by ext exact iff_of_eq (false_and _) @[simp, mfld_simps] theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by ext exact iff_of_eq (true_and _) theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq] theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq] @[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by simp [eq_univ_iff_forall, forall_and] theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] @[simp] theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by ext ⟨c, d⟩; simp @[simp] theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by ext ⟨x, y⟩ simp [or_and_right] @[simp] theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by ext ⟨x, y⟩ simp [and_or_left] theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by ext ⟨x, y⟩ simp only [← and_and_right, mem_inter_iff, mem_prod] theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by ext ⟨x, y⟩ simp only [← and_and_left, mem_inter_iff, mem_prod] @[mfld_simps] theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by ext ⟨x, y⟩ simp [and_assoc, and_left_comm] lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) : (s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by ext p simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and] constructor <;> intro h · by_cases fst_in_s : p.fst ∈ s · exact Or.inr (h fst_in_s) · exact Or.inl fst_in_s · intro fst_in_s simpa only [fst_in_s, not_true, false_or] using h @[simp] theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right α, ← @forall_or_left β, ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)] theorem Disjoint.set_prod_left (hs : Disjoint s₁ s₂) (t₁ t₂ : Set β) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨ha₂, _⟩ => disjoint_left.1 hs ha₁ ha₂ theorem Disjoint.set_prod_right (ht : Disjoint t₁ t₂) (s₁ s₂ : Set α) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hb₁⟩ ⟨_, hb₂⟩ => disjoint_left.1 ht hb₁ hb₂ theorem prodMap_image_prod (f : α → β) (g : γ → δ) (s : Set α) (t : Set γ) : (Prod.map f g) '' (s ×ˢ t) = (f '' s) ×ˢ (g '' t) := by ext aesop theorem insert_prod : insert a s ×ˢ t = Prod.mk a '' t ∪ s ×ˢ t := by simp only [insert_eq, union_prod, singleton_prod] theorem prod_insert : s ×ˢ insert b t = (fun a => (a, b)) '' s ∪ s ×ˢ t := by simp only [insert_eq, prod_union, prod_singleton] theorem prod_preimage_eq {f : γ → α} {g : δ → β} : (f ⁻¹' s) ×ˢ (g ⁻¹' t) = (fun p : γ × δ => (f p.1, g p.2)) ⁻¹' s ×ˢ t := rfl theorem prod_preimage_left {f : γ → α} : (f ⁻¹' s) ×ˢ t = (fun p : γ × β => (f p.1, p.2)) ⁻¹' s ×ˢ t := rfl theorem prod_preimage_right {g : δ → β} : s ×ˢ (g ⁻¹' t) = (fun p : α × δ => (p.1, g p.2)) ⁻¹' s ×ˢ t := rfl theorem preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : Set β) (t : Set δ) : Prod.map f g ⁻¹' s ×ˢ t = (f ⁻¹' s) ×ˢ (g ⁻¹' t) := rfl theorem mk_preimage_prod (f : γ → α) (g : γ → β) : (fun x => (f x, g x)) ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t := rfl @[simp] theorem mk_preimage_prod_left (hb : b ∈ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = s := by ext a simp [hb] @[simp] theorem mk_preimage_prod_right (ha : a ∈ s) : Prod.mk a ⁻¹' s ×ˢ t = t := by ext b simp [ha] @[simp] theorem mk_preimage_prod_left_eq_empty (hb : b ∉ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = ∅ := by ext a simp [hb] @[simp] theorem mk_preimage_prod_right_eq_empty (ha : a ∉ s) : Prod.mk a ⁻¹' s ×ˢ t = ∅ := by ext b simp [ha] theorem mk_preimage_prod_left_eq_if [DecidablePred (· ∈ t)] : (fun a => (a, b)) ⁻¹' s ×ˢ t = if b ∈ t then s else ∅ := by split_ifs with h <;> simp [h] theorem mk_preimage_prod_right_eq_if [DecidablePred (· ∈ s)] : Prod.mk a ⁻¹' s ×ˢ t = if a ∈ s then t else ∅ := by split_ifs with h <;> simp [h] theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (· ∈ t)] (f : γ → α) : (fun a => (f a, b)) ⁻¹' s ×ˢ t = if b ∈ t then f ⁻¹' s else ∅ := by rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage] theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (· ∈ s)] (g : δ → β) : (fun b => (a, g b)) ⁻¹' s ×ˢ t = if a ∈ s then g ⁻¹' t else ∅ := by rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage] @[simp] theorem preimage_swap_prod (s : Set α) (t : Set β) : Prod.swap ⁻¹' s ×ˢ t = t ×ˢ s := by ext ⟨x, y⟩ simp [and_comm] @[simp] theorem image_swap_prod (s : Set α) (t : Set β) : Prod.swap '' s ×ˢ t = t ×ˢ s := by rw [image_swap_eq_preimage_swap, preimage_swap_prod] theorem mapsTo_swap_prod (s : Set α) (t : Set β) : MapsTo Prod.swap (s ×ˢ t) (t ×ˢ s) := fun _ ⟨hx, hy⟩ ↦ ⟨hy, hx⟩ theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} : (m₁ '' s) ×ˢ (m₂ '' t) = (fun p : α × β => (m₁ p.1, m₂ p.2)) '' s ×ˢ t := ext <| by simp [-exists_and_right, exists_and_right.symm, and_left_comm, and_assoc, and_comm] theorem prod_range_range_eq {m₁ : α → γ} {m₂ : β → δ} : range m₁ ×ˢ range m₂ = range fun p : α × β => (m₁ p.1, m₂ p.2) := ext <| by simp [range] @[simp, mfld_simps] theorem range_prodMap {m₁ : α → γ} {m₂ : β → δ} : range (Prod.map m₁ m₂) = range m₁ ×ˢ range m₂ := prod_range_range_eq.symm @[deprecated (since := "2025-04-10")] alias range_prod_map := range_prodMap theorem prod_range_univ_eq {m₁ : α → γ} : range m₁ ×ˢ (univ : Set β) = range fun p : α × β => (m₁ p.1, p.2) := ext <| by simp [range] theorem prod_univ_range_eq {m₂ : β → δ} : (univ : Set α) ×ˢ range m₂ = range fun p : α × β => (p.1, m₂ p.2) := ext <| by simp [range] theorem range_pair_subset (f : α → β) (g : α → γ) : (range fun x => (f x, g x)) ⊆ range f ×ˢ range g := by have : (fun x => (f x, g x)) = Prod.map f g ∘ fun x => (x, x) := funext fun x => rfl rw [this, ← range_prodMap] apply range_comp_subset_range theorem Nonempty.prod : s.Nonempty → t.Nonempty → (s ×ˢ t).Nonempty := fun ⟨x, hx⟩ ⟨y, hy⟩ => ⟨(x, y), ⟨hx, hy⟩⟩ theorem Nonempty.fst : (s ×ˢ t).Nonempty → s.Nonempty := fun ⟨x, hx⟩ => ⟨x.1, hx.1⟩ theorem Nonempty.snd : (s ×ˢ t).Nonempty → t.Nonempty := fun ⟨x, hx⟩ => ⟨x.2, hx.2⟩ @[simp] theorem prod_nonempty_iff : (s ×ˢ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prod h.2⟩ @[simp] theorem prod_eq_empty_iff : s ×ˢ t = ∅ ↔ s = ∅ ∨ t = ∅ := by simp only [not_nonempty_iff_eq_empty.symm, prod_nonempty_iff, not_and_or] theorem prod_sub_preimage_iff {W : Set γ} {f : α × β → γ} : s ×ˢ t ⊆ f ⁻¹' W ↔ ∀ a b, a ∈ s → b ∈ t → f (a, b) ∈ W := by simp [subset_def] theorem image_prodMk_subset_prod {f : α → β} {g : α → γ} {s : Set α} : (fun x => (f x, g x)) '' s ⊆ (f '' s) ×ˢ (g '' s) := by rintro _ ⟨x, hx, rfl⟩ exact mk_mem_prod (mem_image_of_mem f hx) (mem_image_of_mem g hx) @[deprecated (since := "2025-02-22")] alias image_prod_mk_subset_prod := image_prodMk_subset_prod theorem image_prodMk_subset_prod_left (hb : b ∈ t) : (fun a => (a, b)) '' s ⊆ s ×ˢ t := by rintro _ ⟨a, ha, rfl⟩ exact ⟨ha, hb⟩ @[deprecated (since := "2025-02-22")] alias image_prod_mk_subset_prod_left := image_prodMk_subset_prod_left theorem image_prodMk_subset_prod_right (ha : a ∈ s) : Prod.mk a '' t ⊆ s ×ˢ t := by rintro _ ⟨b, hb, rfl⟩ exact ⟨ha, hb⟩ @[deprecated (since := "2025-02-22")] alias image_prod_mk_subset_prod_right := image_prodMk_subset_prod_right theorem prod_subset_preimage_fst (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.fst ⁻¹' s := inter_subset_left theorem fst_image_prod_subset (s : Set α) (t : Set β) : Prod.fst '' s ×ˢ t ⊆ s := image_subset_iff.2 <| prod_subset_preimage_fst s t theorem fst_image_prod (s : Set β) {t : Set α} (ht : t.Nonempty) : Prod.fst '' s ×ˢ t = s := (fst_image_prod_subset _ _).antisymm fun y hy => let ⟨x, hx⟩ := ht ⟨(y, x), ⟨hy, hx⟩, rfl⟩ lemma mapsTo_fst_prod {s : Set α} {t : Set β} : MapsTo Prod.fst (s ×ˢ t) s := fun _ hx ↦ (mem_prod.1 hx).1 theorem prod_subset_preimage_snd (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.snd ⁻¹' t := inter_subset_right theorem snd_image_prod_subset (s : Set α) (t : Set β) : Prod.snd '' s ×ˢ t ⊆ t := image_subset_iff.2 <| prod_subset_preimage_snd s t theorem snd_image_prod {s : Set α} (hs : s.Nonempty) (t : Set β) : Prod.snd '' s ×ˢ t = t := (snd_image_prod_subset _ _).antisymm fun y y_in => let ⟨x, x_in⟩ := hs ⟨(x, y), ⟨x_in, y_in⟩, rfl⟩ lemma mapsTo_snd_prod {s : Set α} {t : Set β} : MapsTo Prod.snd (s ×ˢ t) t := fun _ hx ↦ (mem_prod.1 hx).2 theorem prod_diff_prod : s ×ˢ t \ s₁ ×ˢ t₁ = s ×ˢ (t \ t₁) ∪ (s \ s₁) ×ˢ t := by ext x by_cases h₁ : x.1 ∈ s₁ <;> by_cases h₂ : x.2 ∈ t₁ <;> simp [*] /-- A product set is included in a product set if and only factors are included, or a factor of the first set is empty. -/ theorem prod_subset_prod_iff : s ×ˢ t ⊆ s₁ ×ˢ t₁ ↔ s ⊆ s₁ ∧ t ⊆ t₁ ∨ s = ∅ ∨ t = ∅ := by rcases (s ×ˢ t).eq_empty_or_nonempty with h | h · simp [h, prod_eq_empty_iff.1 h] have st : s.Nonempty ∧ t.Nonempty := by rwa [prod_nonempty_iff] at h refine ⟨fun H => Or.inl ⟨?_, ?_⟩, ?_⟩ · have := image_subset (Prod.fst : α × β → α) H rwa [fst_image_prod _ st.2, fst_image_prod _ (h.mono H).snd] at this · have := image_subset (Prod.snd : α × β → β) H rwa [snd_image_prod st.1, snd_image_prod (h.mono H).fst] at this · intro H simp only [st.1.ne_empty, st.2.ne_empty, or_false] at H exact prod_mono H.1 H.2 theorem prod_eq_prod_iff_of_nonempty (h : (s ×ˢ t).Nonempty) : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ := by constructor · intro heq have h₁ : (s₁ ×ˢ t₁ : Set _).Nonempty := by rwa [← heq] rw [prod_nonempty_iff] at h h₁ rw [← fst_image_prod s h.2, ← fst_image_prod s₁ h₁.2, heq, eq_self_iff_true, true_and, ← snd_image_prod h.1 t, ← snd_image_prod h₁.1 t₁, heq] · rintro ⟨rfl, rfl⟩ rfl theorem prod_eq_prod_iff : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ ∨ (s = ∅ ∨ t = ∅) ∧ (s₁ = ∅ ∨ t₁ = ∅) := by symm rcases eq_empty_or_nonempty (s ×ˢ t) with h | h · simp_rw [h, @eq_comm _ ∅, prod_eq_empty_iff, prod_eq_empty_iff.mp h, true_and, or_iff_right_iff_imp] rintro ⟨rfl, rfl⟩ exact prod_eq_empty_iff.mp h rw [prod_eq_prod_iff_of_nonempty h] rw [nonempty_iff_ne_empty, Ne, prod_eq_empty_iff] at h simp_rw [h, false_and, or_false] @[simp] theorem prod_eq_iff_eq (ht : t.Nonempty) : s ×ˢ t = s₁ ×ˢ t ↔ s = s₁ := by simp_rw [prod_eq_prod_iff, ht.ne_empty, and_true, or_iff_left_iff_imp, or_false] rintro ⟨rfl, rfl⟩ rfl theorem subset_prod {s : Set (α × β)} : s ⊆ (Prod.fst '' s) ×ˢ (Prod.snd '' s) := fun _ hp ↦ mem_prod.2 ⟨mem_image_of_mem _ hp, mem_image_of_mem _ hp⟩ section Mono variable [Preorder α] {f : α → Set β} {g : α → Set γ} theorem _root_.Monotone.set_prod (hf : Monotone f) (hg : Monotone g) : Monotone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) theorem _root_.Antitone.set_prod (hf : Antitone f) (hg : Antitone g) : Antitone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) theorem _root_.MonotoneOn.set_prod (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) theorem _root_.AntitoneOn.set_prod (hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) end Mono end Prod /-! ### Diagonal In this section we prove some lemmas about the diagonal set `{p | p.1 = p.2}` and the diagonal map `fun x ↦ (x, x)`. -/ section Diagonal variable {α : Type*} {s t : Set α} lemma diagonal_nonempty [Nonempty α] : (diagonal α).Nonempty := Nonempty.elim ‹_› fun x => ⟨_, mem_diagonal x⟩ instance decidableMemDiagonal [h : DecidableEq α] (x : α × α) : Decidable (x ∈ diagonal α) := h x.1 x.2 theorem preimage_coe_coe_diagonal (s : Set α) : Prod.map (fun x : s => (x : α)) (fun x : s => (x : α)) ⁻¹' diagonal α = diagonal s := by ext ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ simp [Set.diagonal] @[simp] theorem range_diag : (range fun x => (x, x)) = diagonal α := by ext ⟨x, y⟩ simp [diagonal, eq_comm] theorem diagonal_subset_iff {s} : diagonal α ⊆ s ↔ ∀ x, (x, x) ∈ s := by rw [← range_diag, range_subset_iff] @[simp] theorem prod_subset_compl_diagonal_iff_disjoint : s ×ˢ t ⊆ (diagonal α)ᶜ ↔ Disjoint s t := prod_subset_iff.trans disjoint_iff_forall_ne.symm @[simp] theorem diag_preimage_prod (s t : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ t = s ∩ t := rfl theorem diag_preimage_prod_self (s : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ s = s := inter_self s theorem diag_image (s : Set α) : (fun x => (x, x)) '' s = diagonal α ∩ s ×ˢ s := by rw [← range_diag, ← image_preimage_eq_range_inter, diag_preimage_prod_self] theorem diagonal_eq_univ_iff : diagonal α = univ ↔ Subsingleton α := by simp only [subsingleton_iff, eq_univ_iff_forall, Prod.forall, mem_diagonal_iff] theorem diagonal_eq_univ [Subsingleton α] : diagonal α = univ := diagonal_eq_univ_iff.2 ‹_› end Diagonal /-- A function is `Function.const α a` for some `a` if and only if `∀ x y, f x = f y`. -/ theorem range_const_eq_diagonal {α β : Type*} [hβ : Nonempty β] : range (const α) = {f : α → β | ∀ x y, f x = f y} := by refine (range_eq_iff _ _).mpr ⟨fun _ _ _ ↦ rfl, fun f hf ↦ ?_⟩ rcases isEmpty_or_nonempty α with h|⟨⟨a⟩⟩ · exact hβ.elim fun b ↦ ⟨b, Subsingleton.elim _ _⟩ · exact ⟨f a, funext fun x ↦ hf _ _⟩ end Set section Pullback open Set variable {X Y Z} /-- The fiber product $X \times_Y Z$. -/ abbrev Function.Pullback (f : X → Y) (g : Z → Y) := {p : X × Z // f p.1 = g p.2} /-- The fiber product $X \times_Y X$. -/ abbrev Function.PullbackSelf (f : X → Y) := f.Pullback f /-- The projection from the fiber product to the first factor. -/ def Function.Pullback.fst {f : X → Y} {g : Z → Y} (p : f.Pullback g) : X := p.val.1 /-- The projection from the fiber product to the second factor. -/ def Function.Pullback.snd {f : X → Y} {g : Z → Y} (p : f.Pullback g) : Z := p.val.2 open Function.Pullback in lemma Function.pullback_comm_sq (f : X → Y) (g : Z → Y) : f ∘ @fst X Y Z f g = g ∘ @snd X Y Z f g := funext fun p ↦ p.2 /-- The diagonal map $\Delta: X \to X \times_Y X$. -/ @[simps] def toPullbackDiag (f : X → Y) (x : X) : f.Pullback f := ⟨(x, x), rfl⟩ /-- The diagonal $\Delta(X) \subseteq X \times_Y X$. -/ def Function.pullbackDiagonal (f : X → Y) : Set (f.Pullback f) := {p | p.fst = p.snd} /-- Three functions between the three pairs of spaces $X_i, Y_i, Z_i$ that are compatible induce a function $X_1 \times_{Y_1} Z_1 \to X_2 \times_{Y_2} Z_2$. -/ def Function.mapPullback {X₁ X₂ Y₁ Y₂ Z₁ Z₂} {f₁ : X₁ → Y₁} {g₁ : Z₁ → Y₁} {f₂ : X₂ → Y₂} {g₂ : Z₂ → Y₂} (mapX : X₁ → X₂) (mapY : Y₁ → Y₂) (mapZ : Z₁ → Z₂) (commX : f₂ ∘ mapX = mapY ∘ f₁) (commZ : g₂ ∘ mapZ = mapY ∘ g₁) (p : f₁.Pullback g₁) : f₂.Pullback g₂ := ⟨(mapX p.fst, mapZ p.snd), (congr_fun commX _).trans <| (congr_arg mapY p.2).trans <| congr_fun commZ.symm _⟩ open Function.Pullback in /-- The projection $(X \times_Y Z) \times_Z (X \times_Y Z) \to X \times_Y X$. -/ def Function.PullbackSelf.map_fst {f : X → Y} {g : Z → Y} : (@snd X Y Z f g).PullbackSelf → f.PullbackSelf := mapPullback fst g fst (pullback_comm_sq f g) (pullback_comm_sq f g) open Function.Pullback in /-- The projection $(X \times_Y Z) \times_X (X \times_Y Z) \to Z \times_Y Z$. -/ def Function.PullbackSelf.map_snd {f : X → Y} {g : Z → Y} : (@fst X Y Z f g).PullbackSelf → g.PullbackSelf := mapPullback snd f snd (pullback_comm_sq f g).symm (pullback_comm_sq f g).symm open Function.PullbackSelf Function.Pullback theorem preimage_map_fst_pullbackDiagonal {f : X → Y} {g : Z → Y} : @map_fst X Y Z f g ⁻¹' pullbackDiagonal f = pullbackDiagonal (@snd X Y Z f g) := by ext ⟨⟨p₁, p₂⟩, he⟩ simp_rw [pullbackDiagonal, mem_setOf, Subtype.ext_iff, Prod.ext_iff] exact (and_iff_left he).symm theorem Function.Injective.preimage_pullbackDiagonal {f : X → Y} {g : Z → X} (inj : g.Injective) : mapPullback g id g (by rfl) (by rfl) ⁻¹' pullbackDiagonal f = pullbackDiagonal (f ∘ g) := ext fun _ ↦ inj.eq_iff theorem image_toPullbackDiag (f : X → Y) (s : Set X) : toPullbackDiag f '' s = pullbackDiagonal f ∩ Subtype.val ⁻¹' s ×ˢ s := by ext x constructor · rintro ⟨x, hx, rfl⟩ exact ⟨rfl, hx, hx⟩ · obtain ⟨⟨x, y⟩, h⟩ := x rintro ⟨rfl : x = y, h2x⟩ exact mem_image_of_mem _ h2x.1 theorem range_toPullbackDiag (f : X → Y) : range (toPullbackDiag f) = pullbackDiagonal f := by rw [← image_univ, image_toPullbackDiag, univ_prod_univ, preimage_univ, inter_univ] theorem injective_toPullbackDiag (f : X → Y) : (toPullbackDiag f).Injective := fun _ _ h ↦ congr_arg Prod.fst (congr_arg Subtype.val h) end Pullback namespace Set section OffDiag variable {α : Type*} {s t : Set α} {a : α} theorem offDiag_mono : Monotone (offDiag : Set α → Set (α × α)) := fun _ _ h _ => And.imp (@h _) <| And.imp_left <| @h _ @[simp] theorem offDiag_nonempty : s.offDiag.Nonempty ↔ s.Nontrivial := by simp [offDiag, Set.Nonempty, Set.Nontrivial] @[simp] theorem offDiag_eq_empty : s.offDiag = ∅ ↔ s.Subsingleton := by rw [← not_nonempty_iff_eq_empty, ← not_nontrivial_iff, offDiag_nonempty.not] alias ⟨_, Nontrivial.offDiag_nonempty⟩ := offDiag_nonempty alias ⟨_, Subsingleton.offDiag_eq_empty⟩ := offDiag_nonempty variable (s t) theorem offDiag_subset_prod : s.offDiag ⊆ s ×ˢ s := fun _ hx => ⟨hx.1, hx.2.1⟩ theorem offDiag_eq_sep_prod : s.offDiag = { x ∈ s ×ˢ s | x.1 ≠ x.2 } := ext fun _ => and_assoc.symm @[simp] theorem offDiag_empty : (∅ : Set α).offDiag = ∅ := by simp @[simp] theorem offDiag_singleton (a : α) : ({a} : Set α).offDiag = ∅ := by simp @[simp] theorem offDiag_univ : (univ : Set α).offDiag = (diagonal α)ᶜ := ext <| by simp @[simp] theorem prod_sdiff_diagonal : s ×ˢ s \ diagonal α = s.offDiag := ext fun _ => and_assoc @[simp] theorem disjoint_diagonal_offDiag : Disjoint (diagonal α) s.offDiag := disjoint_left.mpr fun _ hd ho => ho.2.2 hd theorem offDiag_inter : (s ∩ t).offDiag = s.offDiag ∩ t.offDiag := ext fun x => by simp only [mem_offDiag, mem_inter_iff] tauto variable {s t} theorem offDiag_union (h : Disjoint s t) : (s ∪ t).offDiag = s.offDiag ∪ t.offDiag ∪ s ×ˢ t ∪ t ×ˢ s := by ext x simp only [mem_offDiag, mem_union, ne_eq, mem_prod] constructor · rintro ⟨h0|h0, h1|h1, h2⟩ <;> simp [h0, h1, h2] · rintro (((⟨h0, h1, h2⟩|⟨h0, h1, h2⟩)|⟨h0, h1⟩)|⟨h0, h1⟩) <;> simp [*] · rintro h3 rw [h3] at h0 exact Set.disjoint_left.mp h h0 h1 · rintro h3 rw [h3] at h0 exact (Set.disjoint_right.mp h h0 h1).elim theorem offDiag_insert (ha : a ∉ s) : (insert a s).offDiag = s.offDiag ∪ {a} ×ˢ s ∪ s ×ˢ {a} := by rw [insert_eq, union_comm, offDiag_union, offDiag_singleton, union_empty, union_right_comm] rw [disjoint_left] rintro b hb (rfl : b = a) exact ha hb end OffDiag /-! ### Cartesian set-indexed product of sets -/ section Pi variable {ι : Type*} {α β : ι → Type*} {s s₁ s₂ : Set ι} {t t₁ t₂ : ∀ i, Set (α i)} {i : ι} @[simp] theorem empty_pi (s : ∀ i, Set (α i)) : pi ∅ s = univ := by ext simp [pi] theorem subsingleton_univ_pi (ht : ∀ i, (t i).Subsingleton) : (univ.pi t).Subsingleton := fun _f hf _g hg ↦ funext fun i ↦ (ht i) (hf _ <| mem_univ _) (hg _ <| mem_univ _) @[simp] theorem pi_univ (s : Set ι) : (pi s fun i => (univ : Set (α i))) = univ := eq_univ_of_forall fun _ _ _ => mem_univ _ @[simp] theorem pi_univ_ite (s : Set ι) [DecidablePred (· ∈ s)] (t : ∀ i, Set (α i)) : (pi univ fun i => if i ∈ s then t i else univ) = s.pi t := by ext; simp_rw [Set.mem_pi]; apply forall_congr'; intro i; split_ifs with h <;> simp [h] theorem pi_mono (h : ∀ i ∈ s, t₁ i ⊆ t₂ i) : pi s t₁ ⊆ pi s t₂ := fun _ hx i hi => h i hi <| hx i hi theorem pi_inter_distrib : (s.pi fun i => t i ∩ t₁ i) = s.pi t ∩ s.pi t₁ := ext fun x => by simp only [forall_and, mem_pi, mem_inter_iff] theorem pi_congr (h : s₁ = s₂) (h' : ∀ i ∈ s₁, t₁ i = t₂ i) : s₁.pi t₁ = s₂.pi t₂ := h ▸ ext fun _ => forall₂_congr fun i hi => h' i hi ▸ Iff.rfl theorem pi_eq_empty (hs : i ∈ s) (ht : t i = ∅) : s.pi t = ∅ := by ext f simp only [mem_empty_iff_false, not_forall, iff_false, mem_pi, Classical.not_imp] exact ⟨i, hs, by simp [ht]⟩ theorem univ_pi_eq_empty (ht : t i = ∅) : pi univ t = ∅ := pi_eq_empty (mem_univ i) ht theorem pi_nonempty_iff : (s.pi t).Nonempty ↔ ∀ i, ∃ x, i ∈ s → x ∈ t i := by simp [Classical.skolem, Set.Nonempty] theorem univ_pi_nonempty_iff : (pi univ t).Nonempty ↔ ∀ i, (t i).Nonempty := by simp [Classical.skolem, Set.Nonempty] theorem pi_eq_empty_iff : s.pi t = ∅ ↔ ∃ i, IsEmpty (α i) ∨ i ∈ s ∧ t i = ∅ := by rw [← not_nonempty_iff_eq_empty, pi_nonempty_iff] push_neg refine exists_congr fun i => ?_ cases isEmpty_or_nonempty (α i) <;> simp [*, forall_and, eq_empty_iff_forall_not_mem] @[simp] theorem univ_pi_eq_empty_iff : pi univ t = ∅ ↔ ∃ i, t i = ∅ := by simp [← not_nonempty_iff_eq_empty, univ_pi_nonempty_iff] @[simp] theorem univ_pi_empty [h : Nonempty ι] : pi univ (fun _ => ∅ : ∀ i, Set (α i)) = ∅ := univ_pi_eq_empty_iff.2 <| h.elim fun x => ⟨x, rfl⟩ @[simp] theorem disjoint_univ_pi : Disjoint (pi univ t₁) (pi univ t₂) ↔ ∃ i, Disjoint (t₁ i) (t₂ i) := by simp only [disjoint_iff_inter_eq_empty, ← pi_inter_distrib, univ_pi_eq_empty_iff] theorem Disjoint.set_pi (hi : i ∈ s) (ht : Disjoint (t₁ i) (t₂ i)) : Disjoint (s.pi t₁) (s.pi t₂) := disjoint_left.2 fun _ h₁ h₂ => disjoint_left.1 ht (h₁ _ hi) (h₂ _ hi) theorem uniqueElim_preimage [Unique ι] (t : ∀ i, Set (α i)) : uniqueElim ⁻¹' pi univ t = t (default : ι) := by ext; simp [Unique.forall_iff] section Nonempty variable [∀ i, Nonempty (α i)] theorem pi_eq_empty_iff' : s.pi t = ∅ ↔ ∃ i ∈ s, t i = ∅ := by simp [pi_eq_empty_iff] @[simp] theorem disjoint_pi : Disjoint (s.pi t₁) (s.pi t₂) ↔ ∃ i ∈ s, Disjoint (t₁ i) (t₂ i) := by simp only [disjoint_iff_inter_eq_empty, ← pi_inter_distrib, pi_eq_empty_iff'] end Nonempty @[simp] theorem insert_pi (i : ι) (s : Set ι) (t : ∀ i, Set (α i)) : pi (insert i s) t = eval i ⁻¹' t i ∩ pi s t := by ext simp [pi, or_imp, forall_and] @[simp] theorem singleton_pi (i : ι) (t : ∀ i, Set (α i)) : pi {i} t = eval i ⁻¹' t i := by ext simp [pi] theorem singleton_pi' (i : ι) (t : ∀ i, Set (α i)) : pi {i} t = { x | x i ∈ t i } := singleton_pi i t theorem univ_pi_singleton (f : ∀ i, α i) : (pi univ fun i => {f i}) = ({f} : Set (∀ i, α i)) := ext fun g => by simp [funext_iff] theorem preimage_pi (s : Set ι) (t : ∀ i, Set (β i)) (f : ∀ i, α i → β i) : (fun (g : ∀ i, α i) i => f _ (g i)) ⁻¹' s.pi t = s.pi fun i => f i ⁻¹' t i := rfl theorem pi_if {p : ι → Prop} [h : DecidablePred p] (s : Set ι) (t₁ t₂ : ∀ i, Set (α i)) : (pi s fun i => if p i then t₁ i else t₂ i) = pi ({ i ∈ s | p i }) t₁ ∩ pi ({ i ∈ s | ¬p i }) t₂ := by ext f refine ⟨fun h => ?_, ?_⟩ · constructor <;> · rintro i ⟨his, hpi⟩ simpa [*] using h i · rintro ⟨ht₁, ht₂⟩ i his by_cases p i <;> simp_all theorem union_pi : (s₁ ∪ s₂).pi t = s₁.pi t ∩ s₂.pi t := by simp [pi, or_imp, forall_and, setOf_and] theorem union_pi_inter (ht₁ : ∀ i ∉ s₁, t₁ i = univ) (ht₂ : ∀ i ∉ s₂, t₂ i = univ) : (s₁ ∪ s₂).pi (fun i ↦ t₁ i ∩ t₂ i) = s₁.pi t₁ ∩ s₂.pi t₂ := by ext x simp only [mem_pi, mem_union, mem_inter_iff] refine ⟨fun h ↦ ⟨fun i his₁ ↦ (h i (Or.inl his₁)).1, fun i his₂ ↦ (h i (Or.inr his₂)).2⟩, fun h i hi ↦ ?_⟩ rcases hi with hi | hi · by_cases hi2 : i ∈ s₂ · exact ⟨h.1 i hi, h.2 i hi2⟩ · refine ⟨h.1 i hi, ?_⟩ rw [ht₂ i hi2] exact mem_univ _ · by_cases hi1 : i ∈ s₁ · exact ⟨h.1 i hi1, h.2 i hi⟩ · refine ⟨?_, h.2 i hi⟩ rw [ht₁ i hi1] exact mem_univ _ @[simp] theorem pi_inter_compl (s : Set ι) : pi s t ∩ pi sᶜ t = pi univ t := by rw [← union_pi, union_compl_self] theorem pi_update_of_not_mem [DecidableEq ι] (hi : i ∉ s) (f : ∀ j, α j) (a : α i) (t : ∀ j, α j → Set (β j)) : (s.pi fun j => t j (update f i a j)) = s.pi fun j => t j (f j) := (pi_congr rfl) fun j hj => by rw [update_of_ne] exact fun h => hi (h ▸ hj) theorem pi_update_of_mem [DecidableEq ι] (hi : i ∈ s) (f : ∀ j, α j) (a : α i) (t : ∀ j, α j → Set (β j)) : (s.pi fun j => t j (update f i a j)) = { x | x i ∈ t i a } ∩ (s \ {i}).pi fun j => t j (f j) := calc (s.pi fun j => t j (update f i a j)) = ({i} ∪ s \ {i}).pi fun j => t j (update f i a j) := by rw [union_diff_self, union_eq_self_of_subset_left (singleton_subset_iff.2 hi)] _ = { x | x i ∈ t i a } ∩ (s \ {i}).pi fun j => t j (f j) := by rw [union_pi, singleton_pi', update_self, pi_update_of_not_mem]; simp theorem univ_pi_update [DecidableEq ι] {β : ι → Type*} (i : ι) (f : ∀ j, α j) (a : α i) (t : ∀ j, α j → Set (β j)) : (pi univ fun j => t j (update f i a j)) = { x | x i ∈ t i a } ∩ pi {i}ᶜ fun j => t j (f j) := by rw [compl_eq_univ_diff, ← pi_update_of_mem (mem_univ _)] theorem univ_pi_update_univ [DecidableEq ι] (i : ι) (s : Set (α i)) : pi univ (update (fun j : ι => (univ : Set (α j))) i s) = eval i ⁻¹' s := by rw [univ_pi_update i (fun j => (univ : Set (α j))) s fun j t => t, pi_univ, inter_univ, preimage] theorem eval_image_pi_subset (hs : i ∈ s) : eval i '' s.pi t ⊆ t i := image_subset_iff.2 fun _ hf => hf i hs theorem eval_image_univ_pi_subset : eval i '' pi univ t ⊆ t i := eval_image_pi_subset (mem_univ i) theorem subset_eval_image_pi (ht : (s.pi t).Nonempty) (i : ι) : t i ⊆ eval i '' s.pi t := by classical obtain ⟨f, hf⟩ := ht refine fun y hy => ⟨update f i y, fun j hj => ?_, update_self ..⟩ obtain rfl | hji := eq_or_ne j i <;> simp [*, hf _ hj] theorem eval_image_pi (hs : i ∈ s) (ht : (s.pi t).Nonempty) : eval i '' s.pi t = t i := (eval_image_pi_subset hs).antisymm (subset_eval_image_pi ht i) lemma eval_image_pi_of_not_mem [Decidable (s.pi t).Nonempty] (hi : i ∉ s) : eval i '' s.pi t = if (s.pi t).Nonempty then univ else ∅ := by classical ext xᵢ simp only [eval, mem_image, mem_pi, Set.Nonempty, mem_ite_empty_right, mem_univ, and_true] constructor · rintro ⟨x, hx, rfl⟩ exact ⟨x, hx⟩ · rintro ⟨x, hx⟩ refine ⟨Function.update x i xᵢ, ?_⟩ simpa (config := { contextual := true }) [(ne_of_mem_of_not_mem · hi)] @[simp] theorem eval_image_univ_pi (ht : (pi univ t).Nonempty) : (fun f : ∀ i, α i => f i) '' pi univ t = t i := eval_image_pi (mem_univ i) ht theorem piMap_mapsTo_pi {I : Set ι} {f : ∀ i, α i → β i} {s : ∀ i, Set (α i)} {t : ∀ i, Set (β i)} (h : ∀ i ∈ I, MapsTo (f i) (s i) (t i)) : MapsTo (Pi.map f) (I.pi s) (I.pi t) := fun _x hx i hi => h i hi (hx i hi) theorem piMap_image_pi_subset {f : ∀ i, α i → β i} (t : ∀ i, Set (α i)) : Pi.map f '' s.pi t ⊆ s.pi fun i ↦ f i '' t i := image_subset_iff.2 <| piMap_mapsTo_pi fun _ _ => mapsTo_image _ _ theorem piMap_image_pi {f : ∀ i, α i → β i} (hf : ∀ i ∉ s, Surjective (f i)) (t : ∀ i, Set (α i)) : Pi.map f '' s.pi t = s.pi fun i ↦ f i '' t i := by refine Subset.antisymm (piMap_image_pi_subset _) fun b hb => ?_ have (i : ι) : ∃ a, f i a = b i ∧ (i ∈ s → a ∈ t i) := by if hi : i ∈ s then exact (hb i hi).imp fun a ⟨hat, hab⟩ ↦ ⟨hab, fun _ ↦ hat⟩ else exact (hf i hi (b i)).imp fun a ha ↦ ⟨ha, (absurd · hi)⟩ choose a hab hat using this exact ⟨a, hat, funext hab⟩ theorem piMap_image_univ_pi (f : ∀ i, α i → β i) (t : ∀ i, Set (α i)) : Pi.map f '' univ.pi t = univ.pi fun i ↦ f i '' t i := piMap_image_pi (by simp) t @[simp] theorem range_piMap (f : ∀ i, α i → β i) : range (Pi.map f) = pi univ fun i ↦ range (f i) := by simp only [← image_univ, ← piMap_image_univ_pi, pi_univ] theorem pi_subset_pi_iff : pi s t₁ ⊆ pi s t₂ ↔ (∀ i ∈ s, t₁ i ⊆ t₂ i) ∨ pi s t₁ = ∅ := by refine ⟨fun h => or_iff_not_imp_right.2 ?_, fun h => h.elim pi_mono fun h' => h'.symm ▸ empty_subset _⟩ rw [← Ne, ← nonempty_iff_ne_empty] intro hne i hi simpa only [eval_image_pi hi hne, eval_image_pi hi (hne.mono h)] using image_subset (fun f : ∀ i, α i => f i) h theorem univ_pi_subset_univ_pi_iff : pi univ t₁ ⊆ pi univ t₂ ↔ (∀ i, t₁ i ⊆ t₂ i) ∨ ∃ i, t₁ i = ∅ := by simp [pi_subset_pi_iff] theorem eval_preimage [DecidableEq ι] {s : Set (α i)} : eval i ⁻¹' s = pi univ (update (fun _ => univ) i s) := by ext x simp [@forall_update_iff _ (fun i => Set (α i)) _ _ _ _ fun i' y => x i' ∈ y] theorem eval_preimage' [DecidableEq ι] {s : Set (α i)} : eval i ⁻¹' s = pi {i} (update (fun _ => univ) i s) := by ext simp theorem update_preimage_pi [DecidableEq ι] {f : ∀ i, α i} (hi : i ∈ s) (hf : ∀ j ∈ s, j ≠ i → f j ∈ t j) : update f i ⁻¹' s.pi t = t i := by ext x refine ⟨fun h => ?_, fun hx j hj => ?_⟩ · convert h i hi simp · obtain rfl | h := eq_or_ne j i · simpa · rw [update_of_ne h] exact hf j hj h theorem update_image [DecidableEq ι] (x : (i : ι) → β i) (i : ι) (s : Set (β i)) : update x i '' s = Set.univ.pi (update (fun j ↦ {x j}) i s) := by ext y simp only [mem_image, update_eq_iff, ne_eq, and_left_comm (a := _ ∈ s), exists_eq_left, mem_pi, mem_univ, true_implies] rw [forall_update_iff (p := fun x s => y x ∈ s)] simp [eq_comm] theorem update_preimage_univ_pi [DecidableEq ι] {f : ∀ i, α i} (hf : ∀ j ≠ i, f j ∈ t j) : update f i ⁻¹' pi univ t = t i := update_preimage_pi (mem_univ i) fun j _ => hf j theorem subset_pi_eval_image (s : Set ι) (u : Set (∀ i, α i)) : u ⊆ pi s fun i => eval i '' u := fun f hf _ _ => ⟨f, hf, rfl⟩
Mathlib/Data/Set/Prod.lean
889
892
theorem univ_pi_ite (s : Set ι) [DecidablePred (· ∈ s)] (t : ∀ i, Set (α i)) : (pi univ fun i => if i ∈ s then t i else univ) = s.pi t := by
ext simp_rw [mem_univ_pi]
/- 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, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Order.Minimal import Mathlib.Order.Zorn import Mathlib.Topology.ContinuousOn /-! # Irreducibility in topological spaces ## Main definitions * `IrreducibleSpace`: a typeclass applying to topological spaces, stating that the space is nonempty and does not admit a nontrivial pair of disjoint opens. * `IsIrreducible`: for a nonempty set in a topological space, the property that the set is an irreducible space in the subspace topology. ## On the definition of irreducible and connected sets/spaces In informal mathematics, irreducible spaces are assumed to be nonempty. We formalise the predicate without that assumption as `IsPreirreducible`. In other words, the only difference is whether the empty space counts as irreducible. There are good reasons to consider the empty space to be “too simple to be simple” See also https://ncatlab.org/nlab/show/too+simple+to+be+simple, and in particular https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions. -/ open Set Topology variable {X : Type*} {Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} section Preirreducible /-- A preirreducible set `s` is one where there is no non-trivial pair of disjoint opens on `s`. -/ def IsPreirreducible (s : Set X) : Prop := ∀ u v : Set X, IsOpen u → IsOpen v → (s ∩ u).Nonempty → (s ∩ v).Nonempty → (s ∩ (u ∩ v)).Nonempty /-- An irreducible set `s` is one that is nonempty and where there is no non-trivial pair of disjoint opens on `s`. -/ def IsIrreducible (s : Set X) : Prop := s.Nonempty ∧ IsPreirreducible s theorem IsIrreducible.nonempty (h : IsIrreducible s) : s.Nonempty := h.1 theorem IsIrreducible.isPreirreducible (h : IsIrreducible s) : IsPreirreducible s := h.2 theorem isPreirreducible_empty : IsPreirreducible (∅ : Set X) := fun _ _ _ _ _ ⟨_, h1, _⟩ => h1.elim theorem Set.Subsingleton.isPreirreducible (hs : s.Subsingleton) : IsPreirreducible s := fun _u _v _ _ ⟨_x, hxs, hxu⟩ ⟨y, hys, hyv⟩ => ⟨y, hys, hs hxs hys ▸ hxu, hyv⟩ theorem isPreirreducible_singleton {x} : IsPreirreducible ({x} : Set X) := subsingleton_singleton.isPreirreducible theorem isIrreducible_singleton {x} : IsIrreducible ({x} : Set X) := ⟨singleton_nonempty x, isPreirreducible_singleton⟩ theorem isPreirreducible_iff_closure : IsPreirreducible (closure s) ↔ IsPreirreducible s := forall₄_congr fun u v hu hv => by iterate 3 rw [closure_inter_open_nonempty_iff] exacts [hu.inter hv, hv, hu] theorem isIrreducible_iff_closure : IsIrreducible (closure s) ↔ IsIrreducible s := and_congr closure_nonempty_iff isPreirreducible_iff_closure protected alias ⟨_, IsPreirreducible.closure⟩ := isPreirreducible_iff_closure protected alias ⟨_, IsIrreducible.closure⟩ := isIrreducible_iff_closure theorem exists_preirreducible (s : Set X) (H : IsPreirreducible s) : ∃ t : Set X, IsPreirreducible t ∧ s ⊆ t ∧ ∀ u, IsPreirreducible u → t ⊆ u → u = t := let ⟨m, hsm, hm⟩ := zorn_subset_nonempty { t : Set X | IsPreirreducible t } (fun c hc hcc _ => ⟨⋃₀ c, fun u v hu hv ⟨y, hy, hyu⟩ ⟨x, hx, hxv⟩ => let ⟨p, hpc, hyp⟩ := mem_sUnion.1 hy let ⟨q, hqc, hxq⟩ := mem_sUnion.1 hx Or.casesOn (hcc.total hpc hqc) (fun hpq : p ⊆ q => let ⟨x, hxp, hxuv⟩ := hc hqc u v hu hv ⟨y, hpq hyp, hyu⟩ ⟨x, hxq, hxv⟩ ⟨x, mem_sUnion_of_mem hxp hqc, hxuv⟩) fun hqp : q ⊆ p => let ⟨x, hxp, hxuv⟩ := hc hpc u v hu hv ⟨y, hyp, hyu⟩ ⟨x, hqp hxq, hxv⟩ ⟨x, mem_sUnion_of_mem hxp hpc, hxuv⟩, fun _ hxc => subset_sUnion_of_mem hxc⟩) s H ⟨m, hm.prop, hsm, fun _u hu hmu => (hm.eq_of_subset hu hmu).symm⟩ /-- The set of irreducible components of a topological space. -/ def irreducibleComponents (X : Type*) [TopologicalSpace X] : Set (Set X) := {s | Maximal IsIrreducible s} theorem isClosed_of_mem_irreducibleComponents (s) (H : s ∈ irreducibleComponents X) : IsClosed s := by rw [← closure_eq_iff_isClosed, eq_comm] exact subset_closure.antisymm (H.2 H.1.closure subset_closure) theorem irreducibleComponents_eq_maximals_closed (X : Type*) [TopologicalSpace X] : irreducibleComponents X = { s | Maximal (fun x ↦ IsClosed x ∧ IsIrreducible x) s} := by ext s constructor · intro H exact ⟨⟨isClosed_of_mem_irreducibleComponents _ H, H.1⟩, fun x h e => H.2 h.2 e⟩ · intro H refine ⟨H.1.2, fun x h e => ?_⟩ have : closure x ≤ s := H.2 ⟨isClosed_closure, h.closure⟩ (e.trans subset_closure) exact le_trans subset_closure this /-- A maximal irreducible set that contains a given point. -/ def irreducibleComponent (x : X) : Set X := Classical.choose (exists_preirreducible {x} isPreirreducible_singleton) theorem irreducibleComponent_property (x : X) : IsPreirreducible (irreducibleComponent x) ∧ {x} ⊆ irreducibleComponent x ∧ ∀ u, IsPreirreducible u → irreducibleComponent x ⊆ u → u = irreducibleComponent x := Classical.choose_spec (exists_preirreducible {x} isPreirreducible_singleton) theorem mem_irreducibleComponent {x : X} : x ∈ irreducibleComponent x := singleton_subset_iff.1 (irreducibleComponent_property x).2.1 theorem isIrreducible_irreducibleComponent {x : X} : IsIrreducible (irreducibleComponent x) := ⟨⟨x, mem_irreducibleComponent⟩, (irreducibleComponent_property x).1⟩ theorem eq_irreducibleComponent {x : X} : IsPreirreducible s → irreducibleComponent x ⊆ s → s = irreducibleComponent x := (irreducibleComponent_property x).2.2 _ theorem irreducibleComponent_mem_irreducibleComponents (x : X) : irreducibleComponent x ∈ irreducibleComponents X := ⟨isIrreducible_irreducibleComponent, fun _ h₁ h₂ => (eq_irreducibleComponent h₁.2 h₂).le⟩ theorem isClosed_irreducibleComponent {x : X} : IsClosed (irreducibleComponent x) := isClosed_of_mem_irreducibleComponents _ (irreducibleComponent_mem_irreducibleComponents x) /-- A preirreducible space is one where there is no non-trivial pair of disjoint opens. -/ class PreirreducibleSpace (X : Type*) [TopologicalSpace X] : Prop where /-- In a preirreducible space, `Set.univ` is a preirreducible set. -/ isPreirreducible_univ : IsPreirreducible (univ : Set X) /-- An irreducible space is one that is nonempty and where there is no non-trivial pair of disjoint opens. -/ class IrreducibleSpace (X : Type*) [TopologicalSpace X] : Prop extends PreirreducibleSpace X where toNonempty : Nonempty X -- see Note [lower instance priority] attribute [instance 50] IrreducibleSpace.toNonempty theorem IrreducibleSpace.isIrreducible_univ (X : Type*) [TopologicalSpace X] [IrreducibleSpace X] : IsIrreducible (univ : Set X) := ⟨univ_nonempty, PreirreducibleSpace.isPreirreducible_univ⟩ theorem irreducibleSpace_def (X : Type*) [TopologicalSpace X] : IrreducibleSpace X ↔ IsIrreducible (⊤ : Set X) := ⟨@IrreducibleSpace.isIrreducible_univ X _, fun h => haveI : PreirreducibleSpace X := ⟨h.2⟩ ⟨⟨h.1.some⟩⟩⟩ theorem nonempty_preirreducible_inter [PreirreducibleSpace X] : IsOpen s → IsOpen t → s.Nonempty → t.Nonempty → (s ∩ t).Nonempty := by simpa only [univ_inter, univ_subset_iff] using @PreirreducibleSpace.isPreirreducible_univ X _ _ s t /-- In a (pre)irreducible space, a nonempty open set is dense. -/ protected theorem IsOpen.dense [PreirreducibleSpace X] (ho : IsOpen s) (hne : s.Nonempty) : Dense s := dense_iff_inter_open.2 fun _t hto htne => nonempty_preirreducible_inter hto ho htne hne theorem IsPreirreducible.image (H : IsPreirreducible s) (f : X → Y) (hf : ContinuousOn f s) : IsPreirreducible (f '' s) := by rintro u v hu hv ⟨_, ⟨⟨x, hx, rfl⟩, hxu⟩⟩ ⟨_, ⟨⟨y, hy, rfl⟩, hyv⟩⟩ rw [← mem_preimage] at hxu hyv rcases continuousOn_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩ rcases continuousOn_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩ have := H u' v' hu' hv' rw [inter_comm s u', ← u'_eq] at this rw [inter_comm s v', ← v'_eq] at this rcases this ⟨x, hxu, hx⟩ ⟨y, hyv, hy⟩ with ⟨x, hxs, hxu', hxv'⟩ refine ⟨f x, mem_image_of_mem f hxs, ?_, ?_⟩ all_goals rw [← mem_preimage] apply mem_of_mem_inter_left show x ∈ _ ∩ s simp [*] theorem IsIrreducible.image (H : IsIrreducible s) (f : X → Y) (hf : ContinuousOn f s) : IsIrreducible (f '' s) := ⟨H.nonempty.image _, H.isPreirreducible.image f hf⟩ theorem Subtype.preirreducibleSpace (h : IsPreirreducible s) : PreirreducibleSpace s where isPreirreducible_univ := by rintro _ _ ⟨u, hu, rfl⟩ ⟨v, hv, rfl⟩ ⟨⟨x, hxs⟩, -, hxu⟩ ⟨⟨y, hys⟩, -, hyv⟩ rcases h u v hu hv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ with ⟨x, hxs, ⟨hxu, hxv⟩⟩ exact ⟨⟨x, hxs⟩, ⟨Set.mem_univ _, ⟨hxu, hxv⟩⟩⟩
Mathlib/Topology/Irreducible.lean
202
217
theorem Subtype.irreducibleSpace (h : IsIrreducible s) : IrreducibleSpace s where isPreirreducible_univ := (Subtype.preirreducibleSpace h.isPreirreducible).isPreirreducible_univ toNonempty := h.nonempty.to_subtype /-- An infinite type with cofinite topology is an irreducible topological space. -/ instance (priority := 100) {X} [Infinite X] : IrreducibleSpace (CofiniteTopology X) where isPreirreducible_univ u v := by
haveI : Infinite (CofiniteTopology X) := ‹_› simp only [CofiniteTopology.isOpen_iff, univ_inter] intro hu hv hu' hv' simpa only [compl_union, compl_compl] using ((hu hu').union (hv hv')).infinite_compl.nonempty toNonempty := (inferInstance : Nonempty X) theorem irreducibleComponents_eq_singleton [IrreducibleSpace X] : irreducibleComponents X = {univ} :=
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real /-! # Power function on `ℝ≥0` and `ℝ≥0∞` We construct the power functions `x ^ y` where * `x` is a nonnegative real number and `y` is a real number; * `x` is a number from `[0, +∞]` (a.k.a. `ℝ≥0∞`) and `y` is a real number. We also prove basic properties of these functions. -/ noncomputable section open Real NNReal ENNReal ComplexConjugate Finset Function Set namespace NNReal variable {x : ℝ≥0} {w y z : ℝ} /-- The nonnegative real power function `x^y`, defined for `x : ℝ≥0` and `y : ℝ` as the restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/ noncomputable def rpow (x : ℝ≥0) (y : ℝ) : ℝ≥0 := ⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩ noncomputable instance : Pow ℝ≥0 ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝ≥0) (y : ℝ) : rpow x y = x ^ y := rfl @[simp, norm_cast] theorem coe_rpow (x : ℝ≥0) (y : ℝ) : ((x ^ y : ℝ≥0) : ℝ) = (x : ℝ) ^ y := rfl @[simp] theorem rpow_zero (x : ℝ≥0) : x ^ (0 : ℝ) = 1 := NNReal.eq <| Real.rpow_zero _ @[simp] theorem rpow_eq_zero_iff {x : ℝ≥0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero] exact Real.rpow_eq_zero_iff_of_nonneg x.2 lemma rpow_eq_zero (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [hy] @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ≥0) ^ x = 0 := NNReal.eq <| Real.zero_rpow h @[simp] theorem rpow_one (x : ℝ≥0) : x ^ (1 : ℝ) = x := NNReal.eq <| Real.rpow_one _ lemma rpow_neg (x : ℝ≥0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := NNReal.eq <| Real.rpow_neg x.2 _ @[simp, norm_cast] lemma rpow_natCast (x : ℝ≥0) (n : ℕ) : x ^ (n : ℝ) = x ^ n := NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n @[simp, norm_cast] lemma rpow_intCast (x : ℝ≥0) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast, Int.cast_negSucc, rpow_neg, zpow_negSucc] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ≥0) ^ x = 1 := NNReal.eq <| Real.one_rpow _ theorem rpow_add {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) _ _ theorem rpow_add' (h : y + z ≠ 0) (x : ℝ≥0) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add' x.2 h lemma rpow_add_intCast (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_intCast (mod_cast hx) _ _ lemma rpow_add_natCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_natCast (mod_cast hx) _ _ lemma rpow_sub_intCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_intCast (mod_cast hx) _ _ lemma rpow_sub_natCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_natCast (mod_cast hx) _ _ lemma rpow_add_intCast' {n : ℤ} (h : y + n ≠ 0) (x : ℝ≥0) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_intCast' (mod_cast x.2) h lemma rpow_add_natCast' {n : ℕ} (h : y + n ≠ 0) (x : ℝ≥0) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_natCast' (mod_cast x.2) h lemma rpow_sub_intCast' {n : ℤ} (h : y - n ≠ 0) (x : ℝ≥0) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_intCast' (mod_cast x.2) h lemma rpow_sub_natCast' {n : ℕ} (h : y - n ≠ 0) (x : ℝ≥0) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_natCast' (mod_cast x.2) h lemma rpow_add_one (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_natCast hx y 1 lemma rpow_sub_one (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_natCast hx y 1 lemma rpow_add_one' (h : y + 1 ≠ 0) (x : ℝ≥0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' h, rpow_one] lemma rpow_one_add' (h : 1 + y ≠ 0) (x : ℝ≥0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' h, rpow_one] theorem rpow_add_of_nonneg (x : ℝ≥0) {y z : ℝ} (hy : 0 ≤ y) (hz : 0 ≤ z) : x ^ (y + z) = x ^ y * x ^ z := by ext; exact Real.rpow_add_of_nonneg x.2 hy hz /-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (x : ℝ≥0) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add']; rwa [h] theorem rpow_mul (x : ℝ≥0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := NNReal.eq <| Real.rpow_mul x.2 y z lemma rpow_natCast_mul (x : ℝ≥0) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_natCast] lemma rpow_mul_natCast (x : ℝ≥0) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_natCast] lemma rpow_intCast_mul (x : ℝ≥0) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_intCast] lemma rpow_mul_intCast (x : ℝ≥0) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_intCast] theorem rpow_neg_one (x : ℝ≥0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] theorem rpow_sub {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) y z theorem rpow_sub' (h : y - z ≠ 0) (x : ℝ≥0) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub' x.2 h lemma rpow_sub_one' (h : y - 1 ≠ 0) (x : ℝ≥0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' h, rpow_one] lemma rpow_one_sub' (h : 1 - y ≠ 0) (x : ℝ≥0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' h, rpow_one] theorem rpow_inv_rpow_self {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ (1 / y) = x := by field_simp [← rpow_mul] theorem rpow_self_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ (1 / y)) ^ y = x := by field_simp [← rpow_mul] theorem inv_rpow (x : ℝ≥0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := NNReal.eq <| Real.inv_rpow x.2 y theorem div_rpow (x y : ℝ≥0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := NNReal.eq <| Real.div_rpow x.2 y.2 z theorem sqrt_eq_rpow (x : ℝ≥0) : sqrt x = x ^ (1 / (2 : ℝ)) := by refine NNReal.eq ?_ push_cast exact Real.sqrt_eq_rpow x.1 @[simp] lemma rpow_ofNat (x : ℝ≥0) (n : ℕ) [n.AtLeastTwo] : x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n : ℕ) := rpow_natCast x n theorem rpow_two (x : ℝ≥0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 theorem mul_rpow {x y : ℝ≥0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z := NNReal.eq <| Real.mul_rpow x.2 y.2 /-- `rpow` as a `MonoidHom` -/ @[simps] def rpowMonoidHom (r : ℝ) : ℝ≥0 →* ℝ≥0 where toFun := (· ^ r) map_one' := one_rpow _ map_mul' _x _y := mul_rpow /-- `rpow` variant of `List.prod_map_pow` for `ℝ≥0` -/ theorem list_prod_map_rpow (l : List ℝ≥0) (r : ℝ) : (l.map (· ^ r)).prod = l.prod ^ r := l.prod_hom (rpowMonoidHom r) theorem list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ≥0) (r : ℝ) : (l.map (f · ^ r)).prod = (l.map f).prod ^ r := by rw [← list_prod_map_rpow, List.map_map]; rfl /-- `rpow` version of `Multiset.prod_map_pow` for `ℝ≥0`. -/ lemma multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ≥0) (r : ℝ) : (s.map (f · ^ r)).prod = (s.map f).prod ^ r := s.prod_hom' (rpowMonoidHom r) _ /-- `rpow` version of `Finset.prod_pow` for `ℝ≥0`. -/ lemma finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := multiset_prod_map_rpow _ _ _ -- note: these don't really belong here, but they're much easier to prove in terms of the above section Real /-- `rpow` version of `List.prod_map_pow` for `Real`. -/ theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : ∀ x ∈ l, (0 : ℝ) ≤ x) (r : ℝ) : (l.map (· ^ r)).prod = l.prod ^ r := by lift l to List ℝ≥0 using hl have := congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.list_prod_map_rpow l r) push_cast at this rw [List.map_map] at this ⊢ exact mod_cast this theorem _root_.Real.list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ) (hl : ∀ i ∈ l, (0 : ℝ) ≤ f i) (r : ℝ) : (l.map (f · ^ r)).prod = (l.map f).prod ^ r := by rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map] · rfl simpa using hl /-- `rpow` version of `Multiset.prod_map_pow`. -/ theorem _root_.Real.multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, (0 : ℝ) ≤ f i) (r : ℝ) : (s.map (f · ^ r)).prod = (s.map f).prod ^ r := by induction' s using Quotient.inductionOn with l simpa using Real.list_prod_map_rpow' l f hs r /-- `rpow` version of `Finset.prod_pow`. -/ theorem _root_.Real.finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, 0 ≤ f i) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := Real.multiset_prod_map_rpow s.val f hs r end Real @[gcongr] theorem rpow_le_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := Real.rpow_le_rpow x.2 h₁ h₂ @[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z := Real.rpow_lt_rpow x.2 h₁ h₂ theorem rpow_lt_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := Real.rpow_lt_rpow_iff x.2 y.2 hz theorem rpow_le_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := Real.rpow_le_rpow_iff x.2 y.2 hz theorem le_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne'] theorem rpow_inv_le_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne'] theorem lt_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^z < y := by simp only [← not_le, rpow_inv_le_iff hz] theorem rpow_inv_lt_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by simp only [← not_le, le_rpow_inv_iff hz] section variable {y : ℝ≥0} lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := Real.rpow_lt_rpow_of_neg hx hxy hz lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z := Real.rpow_le_rpow_of_nonpos hx hxy hz lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := Real.rpow_lt_rpow_iff_of_neg hx hy hz lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x := Real.rpow_le_rpow_iff_of_neg hx hy hz lemma le_rpow_inv_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := Real.le_rpow_inv_iff_of_pos x.2 hy hz lemma rpow_inv_le_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := Real.rpow_inv_le_iff_of_pos x.2 hy hz lemma lt_rpow_inv_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x < y ^ z⁻¹ ↔ x ^ z < y := Real.lt_rpow_inv_iff_of_pos x.2 hy hz lemma rpow_inv_lt_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ^ z⁻¹ < y ↔ x < y ^ z := Real.rpow_inv_lt_iff_of_pos x.2 hy hz lemma le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z := Real.le_rpow_inv_iff_of_neg hx hy hz lemma lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := Real.lt_rpow_inv_iff_of_neg hx hy hz lemma rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := Real.rpow_inv_lt_iff_of_neg hx hy hz lemma rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x := Real.rpow_inv_le_iff_of_neg hx hy hz end @[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_lt hx hyz @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := Real.rpow_le_rpow_of_exponent_le hx hyz theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := Real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz theorem rpow_pos {p : ℝ} {x : ℝ≥0} (hx_pos : 0 < x) : 0 < x ^ p := by have rpow_pos_of_nonneg : ∀ {p : ℝ}, 0 < p → 0 < x ^ p := by intro p hp_pos rw [← zero_rpow hp_pos.ne'] exact rpow_lt_rpow hx_pos hp_pos rcases lt_trichotomy (0 : ℝ) p with (hp_pos | rfl | hp_neg) · exact rpow_pos_of_nonneg hp_pos · simp only [zero_lt_one, rpow_zero] · rw [← neg_neg p, rpow_neg, inv_pos] exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg) theorem rpow_lt_one {x : ℝ≥0} {z : ℝ} (hx1 : x < 1) (hz : 0 < z) : x ^ z < 1 := Real.rpow_lt_one (coe_nonneg x) hx1 hz theorem rpow_le_one {x : ℝ≥0} {z : ℝ} (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := Real.rpow_le_one x.2 hx2 hz theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := Real.rpow_lt_one_of_one_lt_of_neg hx hz theorem rpow_le_one_of_one_le_of_nonpos {x : ℝ≥0} {z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 := Real.rpow_le_one_of_one_le_of_nonpos hx hz theorem one_lt_rpow {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := Real.one_lt_rpow hx hz theorem one_le_rpow {x : ℝ≥0} {z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x ^ z := Real.one_le_rpow h h₁ theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1) (hz : z ≤ 0) : 1 ≤ x ^ z := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz theorem rpow_le_self_of_le_one {x : ℝ≥0} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x)) · have : z ≠ 0 := by linarith simp [this] nth_rw 2 [← NNReal.rpow_one x] exact NNReal.rpow_le_rpow_of_exponent_ge h hx h_one_le theorem rpow_left_injective {x : ℝ} (hx : x ≠ 0) : Function.Injective fun y : ℝ≥0 => y ^ x := fun y z hyz => by simpa only [rpow_inv_rpow_self hx] using congr_arg (fun y => y ^ (1 / x)) hyz theorem rpow_eq_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z = y ^ z ↔ x = y := (rpow_left_injective hz).eq_iff theorem rpow_left_surjective {x : ℝ} (hx : x ≠ 0) : Function.Surjective fun y : ℝ≥0 => y ^ x := fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, inv_mul_cancel₀ hx, rpow_one]⟩ theorem rpow_left_bijective {x : ℝ} (hx : x ≠ 0) : Function.Bijective fun y : ℝ≥0 => y ^ x := ⟨rpow_left_injective hx, rpow_left_surjective hx⟩ theorem eq_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x = y ^ z⁻¹ ↔ x ^ z = y := by rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz] theorem rpow_inv_eq_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z⁻¹ = y ↔ x = y ^ z := by rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz] @[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul, mul_inv_cancel₀ hy, rpow_one] @[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul, inv_mul_cancel₀ hy, rpow_one] theorem pow_rpow_inv_natCast (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by rw [← NNReal.coe_inj, coe_rpow, NNReal.coe_pow] exact Real.pow_rpow_inv_natCast x.2 hn theorem rpow_inv_natCast_pow (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by rw [← NNReal.coe_inj, NNReal.coe_pow, coe_rpow] exact Real.rpow_inv_natCast_pow x.2 hn theorem _root_.Real.toNNReal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) : Real.toNNReal (x ^ y) = Real.toNNReal x ^ y := by nth_rw 1 [← Real.coe_toNNReal x hx] rw [← NNReal.coe_rpow, Real.toNNReal_coe] theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0 => x ^ z := fun x y hxy => by simp only [NNReal.rpow_lt_rpow hxy h, coe_lt_coe] theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0 => x ^ z := h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone /-- Bundles `fun x : ℝ≥0 => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝ≥0 => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0 ≃o ℝ≥0 := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] theorem orderIsoRpow_symm_eq (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div]; rfl theorem _root_.Real.nnnorm_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) : ‖x ^ y‖₊ = ‖x‖₊ ^ y := by ext; exact Real.norm_rpow_of_nonneg hx end NNReal namespace ENNReal /-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝ≥0∞` and `y : ℝ` as the restriction of the real power function if `0 < x < ⊤`, and with the natural values for `0` and `⊤` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊤` for `x < 0`, and `⊤ ^ x = 1 / 0 ^ x`). -/ noncomputable def rpow : ℝ≥0∞ → ℝ → ℝ≥0∞ | some x, y => if x = 0 ∧ y < 0 then ⊤ else (x ^ y : ℝ≥0) | none, y => if 0 < y then ⊤ else if y = 0 then 1 else 0 noncomputable instance : Pow ℝ≥0∞ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝ≥0∞) (y : ℝ) : rpow x y = x ^ y := rfl @[simp] theorem rpow_zero {x : ℝ≥0∞} : x ^ (0 : ℝ) = 1 := by cases x <;> · dsimp only [(· ^ ·), Pow.pow, rpow] simp [lt_irrefl] theorem top_rpow_def (y : ℝ) : (⊤ : ℝ≥0∞) ^ y = if 0 < y then ⊤ else if y = 0 then 1 else 0 := rfl @[simp] theorem top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊤ : ℝ≥0∞) ^ y = ⊤ := by simp [top_rpow_def, h] @[simp] theorem top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊤ : ℝ≥0∞) ^ y = 0 := by simp [top_rpow_def, asymm h, ne_of_lt h] @[simp] theorem zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝ≥0∞) ^ y = 0 := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(· ^ ·), rpow, Pow.pow] simp [h, asymm h, ne_of_gt h] @[simp] theorem zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝ≥0∞) ^ y = ⊤ := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(· ^ ·), rpow, Pow.pow] simp [h, ne_of_gt h] theorem zero_rpow_def (y : ℝ) : (0 : ℝ≥0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊤ := by rcases lt_trichotomy (0 : ℝ) y with (H | rfl | H) · simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl] · simp [lt_irrefl] · simp [H, asymm H, ne_of_lt, zero_rpow_of_neg] @[simp] theorem zero_rpow_mul_self (y : ℝ) : (0 : ℝ≥0∞) ^ y * (0 : ℝ≥0∞) ^ y = (0 : ℝ≥0∞) ^ y := by rw [zero_rpow_def] split_ifs exacts [zero_mul _, one_mul _, top_mul_top] @[norm_cast] theorem coe_rpow_of_ne_zero {x : ℝ≥0} (h : x ≠ 0) (y : ℝ) : (↑(x ^ y) : ℝ≥0∞) = x ^ y := by rw [← ENNReal.some_eq_coe] dsimp only [(· ^ ·), Pow.pow, rpow] simp [h] @[norm_cast] theorem coe_rpow_of_nonneg (x : ℝ≥0) {y : ℝ} (h : 0 ≤ y) : ↑(x ^ y) = (x : ℝ≥0∞) ^ y := by by_cases hx : x = 0 · rcases le_iff_eq_or_lt.1 h with (H | H) · simp [hx, H.symm] · simp [hx, zero_rpow_of_pos H, NNReal.zero_rpow (ne_of_gt H)] · exact coe_rpow_of_ne_zero hx _ theorem coe_rpow_def (x : ℝ≥0) (y : ℝ) : (x : ℝ≥0∞) ^ y = if x = 0 ∧ y < 0 then ⊤ else ↑(x ^ y) := rfl theorem rpow_ofNNReal {M : ℝ≥0} {P : ℝ} (hP : 0 ≤ P) : (M : ℝ≥0∞) ^ P = ↑(M ^ P) := by rw [ENNReal.coe_rpow_of_nonneg _ hP, ← ENNReal.rpow_eq_pow] @[simp] theorem rpow_one (x : ℝ≥0∞) : x ^ (1 : ℝ) = x := by cases x · exact dif_pos zero_lt_one · change ite _ _ _ = _ simp only [NNReal.rpow_one, some_eq_coe, ite_eq_right_iff, top_ne_coe, and_imp] exact fun _ => zero_le_one.not_lt @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ≥0∞) ^ x = 1 := by rw [← coe_one, ← coe_rpow_of_ne_zero one_ne_zero] simp @[simp] theorem rpow_eq_zero_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ 0 < y ∨ x = ⊤ ∧ y < 0 := by cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] | coe x => by_cases h : x = 0 · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] · simp [← coe_rpow_of_ne_zero h, h] lemma rpow_eq_zero_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = 0 ↔ x = 0 := by simp [hy, hy.not_lt] @[simp] theorem rpow_eq_top_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = ⊤ ↔ x = 0 ∧ y < 0 ∨ x = ⊤ ∧ 0 < y := by cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] | coe x => by_cases h : x = 0 · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] · simp [← coe_rpow_of_ne_zero h, h] theorem rpow_eq_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = ⊤ ↔ x = ⊤ := by simp [rpow_eq_top_iff, hy, asymm hy] lemma rpow_lt_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y < ∞ ↔ x < ∞ := by simp only [lt_top_iff_ne_top, Ne, rpow_eq_top_iff_of_pos hy] theorem rpow_eq_top_of_nonneg (x : ℝ≥0∞) {y : ℝ} (hy0 : 0 ≤ y) : x ^ y = ⊤ → x = ⊤ := by rw [ENNReal.rpow_eq_top_iff] rintro (h|h) · exfalso rw [lt_iff_not_ge] at h exact h.right hy0 · exact h.left theorem rpow_ne_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y ≠ ⊤ := mt (ENNReal.rpow_eq_top_of_nonneg x hy0) h theorem rpow_lt_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y < ⊤ := lt_top_iff_ne_top.mpr (ENNReal.rpow_ne_top_of_nonneg hy0 h) theorem rpow_add {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y + z) = x ^ y * x ^ z := by cases x with | top => exact (h'x rfl).elim | coe x => have : x ≠ 0 := fun h => by simp [h] at hx simp [← coe_rpow_of_ne_zero this, NNReal.rpow_add this] theorem rpow_add_of_nonneg {x : ℝ≥0∞} (y z : ℝ) (hy : 0 ≤ y) (hz : 0 ≤ z) : x ^ (y + z) = x ^ y * x ^ z := by induction x using recTopCoe · rcases hy.eq_or_lt with rfl|hy · rw [rpow_zero, one_mul, zero_add] rcases hz.eq_or_lt with rfl|hz · rw [rpow_zero, mul_one, add_zero] simp [top_rpow_of_pos, hy, hz, add_pos hy hz] simp [← coe_rpow_of_nonneg, hy, hz, add_nonneg hy hz, NNReal.rpow_add_of_nonneg _ hy hz] theorem rpow_neg (x : ℝ≥0∞) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;> simp [top_rpow_of_pos, top_rpow_of_neg, H, neg_pos.mpr] | coe x => by_cases h : x = 0 · rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, zero_rpow_of_pos, zero_rpow_of_neg, H, neg_pos.mpr] · have A : x ^ y ≠ 0 := by simp [h] simp [← coe_rpow_of_ne_zero h, ← coe_inv A, NNReal.rpow_neg] theorem rpow_sub {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y - z) = x ^ y / x ^ z := by rw [sub_eq_add_neg, rpow_add _ _ hx h'x, rpow_neg, div_eq_mul_inv] theorem rpow_neg_one (x : ℝ≥0∞) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] theorem rpow_mul (x : ℝ≥0∞) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by cases x with | top => rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] | coe x => by_cases h : x = 0 · rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [h, Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] · have : x ^ y ≠ 0 := by simp [h] simp [← coe_rpow_of_ne_zero, h, this, NNReal.rpow_mul] @[simp, norm_cast] theorem rpow_natCast (x : ℝ≥0∞) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by cases x · cases n <;> simp [top_rpow_of_pos (Nat.cast_add_one_pos _), top_pow (Nat.succ_ne_zero _)] · simp [← coe_rpow_of_nonneg _ (Nat.cast_nonneg n)] @[simp] lemma rpow_ofNat (x : ℝ≥0∞) (n : ℕ) [n.AtLeastTwo] : x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n) := rpow_natCast x n @[simp, norm_cast] lemma rpow_intCast (x : ℝ≥0∞) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast, Int.cast_negSucc, rpow_neg, zpow_negSucc] theorem rpow_two (x : ℝ≥0∞) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 theorem mul_rpow_eq_ite (x y : ℝ≥0∞) (z : ℝ) : (x * y) ^ z = if (x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0) ∧ z < 0 then ⊤ else x ^ z * y ^ z := by rcases eq_or_ne z 0 with (rfl | hz); · simp replace hz := hz.lt_or_lt wlog hxy : x ≤ y · convert this y x z hz (le_of_not_le hxy) using 2 <;> simp only [mul_comm, and_comm, or_comm] rcases eq_or_ne x 0 with (rfl | hx0) · induction y <;> rcases hz with hz | hz <;> simp [*, hz.not_lt] rcases eq_or_ne y 0 with (rfl | hy0) · exact (hx0 (bot_unique hxy)).elim induction x · rcases hz with hz | hz <;> simp [hz, top_unique hxy] induction y · rw [ne_eq, coe_eq_zero] at hx0 rcases hz with hz | hz <;> simp [*] simp only [*, if_false] norm_cast at * rw [← coe_rpow_of_ne_zero (mul_ne_zero hx0 hy0), NNReal.mul_rpow] norm_cast theorem mul_rpow_of_ne_top {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) (z : ℝ) : (x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite] @[norm_cast] theorem coe_mul_rpow (x y : ℝ≥0) (z : ℝ) : ((x : ℝ≥0∞) * y) ^ z = (x : ℝ≥0∞) ^ z * (y : ℝ≥0∞) ^ z := mul_rpow_of_ne_top coe_ne_top coe_ne_top z theorem prod_coe_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) : ∏ i ∈ s, (f i : ℝ≥0∞) ^ r = ((∏ i ∈ s, f i : ℝ≥0) : ℝ≥0∞) ^ r := by classical induction s using Finset.induction with | empty => simp | insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← coe_mul_rpow, coe_mul] theorem mul_rpow_of_ne_zero {x y : ℝ≥0∞} (hx : x ≠ 0) (hy : y ≠ 0) (z : ℝ) : (x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite] theorem mul_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x * y) ^ z = x ^ z * y ^ z := by simp [hz.not_lt, mul_rpow_eq_ite] theorem prod_rpow_of_ne_top {ι} {s : Finset ι} {f : ι → ℝ≥0∞} (hf : ∀ i ∈ s, f i ≠ ∞) (r : ℝ) : ∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by classical induction s using Finset.induction with | empty => simp | insert i s hi ih => have h2f : ∀ i ∈ s, f i ≠ ∞ := fun i hi ↦ hf i <| mem_insert_of_mem hi rw [prod_insert hi, prod_insert hi, ih h2f, ← mul_rpow_of_ne_top <| hf i <| mem_insert_self ..] apply prod_ne_top h2f theorem prod_rpow_of_nonneg {ι} {s : Finset ι} {f : ι → ℝ≥0∞} {r : ℝ} (hr : 0 ≤ r) : ∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by classical induction s using Finset.induction with | empty => simp | insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← mul_rpow_of_nonneg _ _ hr] theorem inv_rpow (x : ℝ≥0∞) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by rcases eq_or_ne y 0 with (rfl | hy); · simp only [rpow_zero, inv_one] replace hy := hy.lt_or_lt rcases eq_or_ne x 0 with (rfl | h0); · cases hy <;> simp [*] rcases eq_or_ne x ⊤ with (rfl | h_top); · cases hy <;> simp [*] apply ENNReal.eq_inv_of_mul_eq_one_left rw [← mul_rpow_of_ne_zero (ENNReal.inv_ne_zero.2 h_top) h0, ENNReal.inv_mul_cancel h0 h_top, one_rpow] theorem div_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x / y) ^ z = x ^ z / y ^ z := by rw [div_eq_mul_inv, mul_rpow_of_nonneg _ _ hz, inv_rpow, div_eq_mul_inv] theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0∞ => x ^ z := by intro x y hxy lift x to ℝ≥0 using ne_top_of_lt hxy rcases eq_or_ne y ∞ with (rfl | hy) · simp only [top_rpow_of_pos h, ← coe_rpow_of_nonneg _ h.le, coe_lt_top] · lift y to ℝ≥0 using hy simp only [← coe_rpow_of_nonneg _ h.le, NNReal.rpow_lt_rpow (coe_lt_coe.1 hxy) h, coe_lt_coe] theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0∞ => x ^ z := h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone /-- Bundles `fun x : ℝ≥0∞ => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝ≥0∞ => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0∞ ≃o ℝ≥0∞ := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] theorem orderIsoRpow_symm_apply (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div] rfl @[gcongr] theorem rpow_le_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := monotone_rpow_of_nonneg h₂ h₁ @[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z := strictMono_rpow_of_pos h₂ h₁ theorem rpow_le_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := (strictMono_rpow_of_pos hz).le_iff_le theorem rpow_lt_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := (strictMono_rpow_of_pos hz).lt_iff_lt theorem le_rpow_inv_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by nth_rw 1 [← rpow_one x] nth_rw 1 [← @mul_inv_cancel₀ _ _ z hz.ne'] rw [rpow_mul, @rpow_le_rpow_iff _ _ z⁻¹ (by simp [hz])] theorem rpow_inv_lt_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by simp only [← not_le, le_rpow_inv_iff hz] theorem lt_rpow_inv_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := by nth_rw 1 [← rpow_one x] nth_rw 1 [← @mul_inv_cancel₀ _ _ z (ne_of_lt hz).symm] rw [rpow_mul, @rpow_lt_rpow_iff _ _ z⁻¹ (by simp [hz])] theorem rpow_inv_le_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by nth_rw 1 [← ENNReal.rpow_one y] nth_rw 1 [← @mul_inv_cancel₀ _ _ z hz.ne.symm] rw [ENNReal.rpow_mul, ENNReal.rpow_le_rpow_iff (inv_pos.2 hz)] theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0∞} {y z : ℝ} (hx : 1 < x) (hx' : x ≠ ⊤) (hyz : y < z) : x ^ y < x ^ z := by lift x to ℝ≥0 using hx' rw [one_lt_coe_iff] at hx simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)), NNReal.rpow_lt_rpow_of_exponent_lt hx hyz] @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0∞} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := by cases x · rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, top_rpow_of_neg, top_rpow_of_pos, le_refl] <;> linarith · simp only [one_le_coe_iff, some_eq_coe] at hx simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)), NNReal.rpow_le_rpow_of_exponent_le hx hyz] theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0∞} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx1 le_top) simp only [coe_lt_one_iff, coe_pos] at hx0 hx1 simp [← coe_rpow_of_ne_zero (ne_of_gt hx0), NNReal.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz] theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0∞} {y z : ℝ} (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := by lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx1 coe_lt_top) by_cases h : x = 0 · rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, h, zero_rpow_of_neg, zero_rpow_of_pos, le_refl] <;> linarith · rw [coe_le_one_iff] at hx1 simp [← coe_rpow_of_ne_zero h, NNReal.rpow_le_rpow_of_exponent_ge (bot_lt_iff_ne_bot.mpr h) hx1 hyz] theorem rpow_le_self_of_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by nth_rw 2 [← ENNReal.rpow_one x] exact ENNReal.rpow_le_rpow_of_exponent_ge hx h_one_le theorem le_rpow_self_of_one_le {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (h_one_le : 1 ≤ z) : x ≤ x ^ z := by nth_rw 1 [← ENNReal.rpow_one x] exact ENNReal.rpow_le_rpow_of_exponent_le hx h_one_le theorem rpow_pos_of_nonneg {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hp_nonneg : 0 ≤ p) : 0 < x ^ p := by by_cases hp_zero : p = 0 · simp [hp_zero, zero_lt_one] · rw [← Ne] at hp_zero have hp_pos := lt_of_le_of_ne hp_nonneg hp_zero.symm rw [← zero_rpow_of_pos hp_pos] exact rpow_lt_rpow hx_pos hp_pos theorem rpow_pos {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hx_ne_top : x ≠ ⊤) : 0 < x ^ p := by rcases lt_or_le 0 p with hp_pos | hp_nonpos · exact rpow_pos_of_nonneg hx_pos (le_of_lt hp_pos) · rw [← neg_neg p, rpow_neg, ENNReal.inv_pos] exact rpow_ne_top_of_nonneg (Right.nonneg_neg_iff.mpr hp_nonpos) hx_ne_top
Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean
821
824
theorem rpow_lt_one {x : ℝ≥0∞} {z : ℝ} (hx : x < 1) (hz : 0 < z) : x ^ z < 1 := by
lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx le_top) simp only [coe_lt_one_iff] at hx simp [← coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.rpow_lt_one hx hz]
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Edward Ayers -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.Data.Set.BooleanAlgebra /-! # Theory of sieves - For an object `X` of a category `C`, a `Sieve X` is a set of morphisms to `X` which is closed under left-composition. - The complete lattice structure on sieves is given, as well as the Galois insertion given by downward-closing. - A `Sieve X` (functorially) induces a presheaf on `C` together with a monomorphism to the yoneda embedding of `X`. ## Tags sieve, pullback -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory open Category Limits variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D) variable {X Y Z : C} (f : Y ⟶ X) /-- A set of arrows all with codomain `X`. -/ def Presieve (X : C) := ∀ ⦃Y⦄, Set (Y ⟶ X)-- deriving CompleteLattice instance : CompleteLattice (Presieve X) := by dsimp [Presieve] infer_instance namespace Presieve noncomputable instance : Inhabited (Presieve X) := ⟨⊤⟩ /-- The full subcategory of the over category `C/X` consisting of arrows which belong to a presieve on `X`. -/ abbrev category {X : C} (P : Presieve X) := ObjectProperty.FullSubcategory fun f : Over X => P f.hom /-- Construct an object of `P.category`. -/ abbrev categoryMk {X : C} (P : Presieve X) {Y : C} (f : Y ⟶ X) (hf : P f) : P.category := ⟨Over.mk f, hf⟩ /-- Given a sieve `S` on `X : C`, its associated diagram `S.diagram` is defined to be the natural functor from the full subcategory of the over category `C/X` consisting of arrows in `S` to `C`. -/ abbrev diagram (S : Presieve X) : S.category ⥤ C := ObjectProperty.ι _ ⋙ Over.forget X /-- Given a sieve `S` on `X : C`, its associated cocone `S.cocone` is defined to be the natural cocone over the diagram defined above with cocone point `X`. -/ abbrev cocone (S : Presieve X) : Cocone S.diagram := (Over.forgetCocone X).whisker (ObjectProperty.ι _) /-- Given a set of arrows `S` all with codomain `X`, and a set of arrows with codomain `Y` for each `f : Y ⟶ X` in `S`, produce a set of arrows with codomain `X`: `{ g ≫ f | (f : Y ⟶ X) ∈ S, (g : Z ⟶ Y) ∈ R f }`. -/ def bind (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y) : Presieve X := fun Z h => ∃ (Y : C) (g : Z ⟶ Y) (f : Y ⟶ X) (H : S f), R H g ∧ g ≫ f = h /-- Structure which contains the data and properties for a morphism `h` satisfying `Presieve.bind S R h`. -/ structure BindStruct (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y) {Z : C} (h : Z ⟶ X) where /-- the intermediate object -/ Y : C /-- a morphism in the family of presieves `R` -/ g : Z ⟶ Y /-- a morphism in the presieve `S` -/ f : Y ⟶ X hf : S f hg : R hf g fac : g ≫ f = h attribute [reassoc (attr := simp)] BindStruct.fac /-- If a morphism `h` satisfies `Presieve.bind S R h`, this is a choice of a structure in `BindStruct S R h`. -/ noncomputable def bind.bindStruct {S : Presieve X} {R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {Z : C} {h : Z ⟶ X} (H : bind S R h) : BindStruct S R h := Nonempty.some (by obtain ⟨Y, g, f, hf, hg, fac⟩ := H exact ⟨{ hf := hf, hg := hg, fac := fac, .. }⟩) lemma BindStruct.bind {S : Presieve X} {R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {Z : C} {h : Z ⟶ X} (b : BindStruct S R h) : bind S R h := ⟨b.Y, b.g, b.f, b.hf, b.hg, b.fac⟩ @[simp] theorem bind_comp {S : Presieve X} {R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {g : Z ⟶ Y} (h₁ : S f) (h₂ : R h₁ g) : bind S R (g ≫ f) := ⟨_, _, _, h₁, h₂, rfl⟩ -- Porting note: it seems the definition of `Presieve` must be unfolded in order to define -- this inductive type, it was thus renamed `singleton'` -- Note we can't make this into `HasSingleton` because of the out-param. /-- The singleton presieve. -/ inductive singleton' : ⦃Y : C⦄ → (Y ⟶ X) → Prop | mk : singleton' f /-- The singleton presieve. -/ def singleton : Presieve X := singleton' f lemma singleton.mk {f : Y ⟶ X} : singleton f f := singleton'.mk @[simp] theorem singleton_eq_iff_domain (f g : Y ⟶ X) : singleton f g ↔ f = g := by constructor · rintro ⟨a, rfl⟩ rfl · rintro rfl apply singleton.mk theorem singleton_self : singleton f f := singleton.mk /-- Pullback a set of arrows with given codomain along a fixed map, by taking the pullback in the category. This is not the same as the arrow set of `Sieve.pullback`, but there is a relation between them in `pullbackArrows_comm`. -/ inductive pullbackArrows [HasPullbacks C] (R : Presieve X) : Presieve Y | mk (Z : C) (h : Z ⟶ X) : R h → pullbackArrows _ (pullback.snd h f) theorem pullback_singleton [HasPullbacks C] (g : Z ⟶ X) : pullbackArrows f (singleton g) = singleton (pullback.snd g f) := by funext W ext h constructor · rintro ⟨W, _, _, _⟩ exact singleton.mk · rintro ⟨_⟩ exact pullbackArrows.mk Z g singleton.mk /-- Construct the presieve given by the family of arrows indexed by `ι`. -/ inductive ofArrows {ι : Type*} (Y : ι → C) (f : ∀ i, Y i ⟶ X) : Presieve X | mk (i : ι) : ofArrows _ _ (f i) theorem ofArrows_pUnit : (ofArrows _ fun _ : PUnit => f) = singleton f := by funext Y ext g constructor · rintro ⟨_⟩ apply singleton.mk · rintro ⟨_⟩ exact ofArrows.mk PUnit.unit theorem ofArrows_pullback [HasPullbacks C] {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X) : (ofArrows (fun i => pullback (g i) f) fun _ => pullback.snd _ _) = pullbackArrows f (ofArrows Z g) := by funext T ext h constructor · rintro ⟨hk⟩ exact pullbackArrows.mk _ _ (ofArrows.mk hk) · rintro ⟨W, k, ⟨_⟩⟩ apply ofArrows.mk theorem ofArrows_bind {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X) (j : ∀ ⦃Y⦄ (f : Y ⟶ X), ofArrows Z g f → Type*) (W : ∀ ⦃Y⦄ (f : Y ⟶ X) (H), j f H → C) (k : ∀ ⦃Y⦄ (f : Y ⟶ X) (H i), W f H i ⟶ Y) : ((ofArrows Z g).bind fun _ f H => ofArrows (W f H) (k f H)) = ofArrows (fun i : Σi, j _ (ofArrows.mk i) => W (g i.1) _ i.2) fun ij => k (g ij.1) _ ij.2 ≫ g ij.1 := by funext Y ext f constructor · rintro ⟨_, _, _, ⟨i⟩, ⟨i'⟩, rfl⟩ exact ofArrows.mk (Sigma.mk _ _) · rintro ⟨i⟩ exact bind_comp _ (ofArrows.mk _) (ofArrows.mk _) theorem ofArrows_surj {ι : Type*} {Y : ι → C} (f : ∀ i, Y i ⟶ X) {Z : C} (g : Z ⟶ X) (hg : ofArrows Y f g) : ∃ (i : ι) (h : Y i = Z), g = eqToHom h.symm ≫ f i := by obtain ⟨i⟩ := hg exact ⟨i, rfl, by simp only [eqToHom_refl, id_comp]⟩ /-- Given a presieve on `F(X)`, we can define a presieve on `X` by taking the preimage via `F`. -/ def functorPullback (R : Presieve (F.obj X)) : Presieve X := fun _ f => R (F.map f) @[simp] theorem functorPullback_mem (R : Presieve (F.obj X)) {Y} (f : Y ⟶ X) : R.functorPullback F f ↔ R (F.map f) := Iff.rfl @[simp] theorem functorPullback_id (R : Presieve X) : R.functorPullback (𝟭 _) = R := rfl /-- Given a presieve `R` on `X`, the predicate `R.hasPullbacks` means that for all arrows `f` and `g` in `R`, the pullback of `f` and `g` exists. -/ class hasPullbacks (R : Presieve X) : Prop where /-- For all arrows `f` and `g` in `R`, the pullback of `f` and `g` exists. -/ has_pullbacks : ∀ {Y Z} {f : Y ⟶ X} (_ : R f) {g : Z ⟶ X} (_ : R g), HasPullback f g instance (R : Presieve X) [HasPullbacks C] : R.hasPullbacks := ⟨fun _ _ ↦ inferInstance⟩ instance {α : Type v₂} {X : α → C} {B : C} (π : (a : α) → X a ⟶ B) [(Presieve.ofArrows X π).hasPullbacks] (a b : α) : HasPullback (π a) (π b) := Presieve.hasPullbacks.has_pullbacks (Presieve.ofArrows.mk _) (Presieve.ofArrows.mk _) section FunctorPushforward variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E) /-- Given a presieve on `X`, we can define a presieve on `F(X)` (which is actually a sieve) by taking the sieve generated by the image via `F`. -/ def functorPushforward (S : Presieve X) : Presieve (F.obj X) := fun Y f => ∃ (Z : C) (g : Z ⟶ X) (h : Y ⟶ F.obj Z), S g ∧ f = h ≫ F.map g /-- An auxiliary definition in order to fix the choice of the preimages between various definitions. -/ structure FunctorPushforwardStructure (S : Presieve X) {Y} (f : Y ⟶ F.obj X) where /-- an object in the source category -/ preobj : C /-- a map in the source category which has to be in the presieve -/ premap : preobj ⟶ X /-- the morphism which appear in the factorisation -/ lift : Y ⟶ F.obj preobj /-- the condition that `premap` is in the presieve -/ cover : S premap /-- the factorisation of the morphism -/ fac : f = lift ≫ F.map premap /-- The fixed choice of a preimage. -/ noncomputable def getFunctorPushforwardStructure {F : C ⥤ D} {S : Presieve X} {Y : D} {f : Y ⟶ F.obj X} (h : S.functorPushforward F f) : FunctorPushforwardStructure F S f := by choose Z f' g h₁ h using h exact ⟨Z, f', g, h₁, h⟩
Mathlib/CategoryTheory/Sites/Sieves.lean
246
254
theorem functorPushforward_comp (R : Presieve X) : R.functorPushforward (F ⋙ G) = (R.functorPushforward F).functorPushforward G := by
funext x ext f constructor · rintro ⟨X, f₁, g₁, h₁, rfl⟩ exact ⟨F.obj X, F.map f₁, g₁, ⟨X, f₁, 𝟙 _, h₁, by simp⟩, rfl⟩ · rintro ⟨X, f₁, g₁, ⟨X', f₂, g₂, h₁, rfl⟩, rfl⟩ exact ⟨X', f₂, g₁ ≫ G.map g₂, h₁, by simp⟩
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.CharP.Frobenius import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.RingTheory.Polynomial.Basic /-! # Expand a polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`. ## Main definitions * `Polynomial.expand R p f`: expand the polynomial `f` with coefficients in a commutative semiring `R` by a factor of p, so `expand R p (∑ aₙ xⁿ)` is `∑ aₙ xⁿᵖ`. * `Polynomial.contract p f`: the opposite of `expand`, so it sends `∑ aₙ xⁿᵖ` to `∑ aₙ xⁿ`. -/ universe u v w open Polynomial open Finset namespace Polynomial section CommSemiring variable (R : Type u) [CommSemiring R] {S : Type v} [CommSemiring S] (p q : ℕ) /-- Expand the polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`. -/ noncomputable def expand : R[X] →ₐ[R] R[X] := { (eval₂RingHom C (X ^ p) : R[X] →+* R[X]) with commutes' := fun _ => eval₂_C _ _ } theorem coe_expand : (expand R p : R[X] → R[X]) = eval₂ C (X ^ p) := rfl variable {R} theorem expand_eq_comp_X_pow {f : R[X]} : expand R p f = f.comp (X ^ p) := rfl theorem expand_eq_sum {f : R[X]} : expand R p f = f.sum fun e a => C a * (X ^ p) ^ e := by simp [expand, eval₂] @[simp] theorem expand_C (r : R) : expand R p (C r) = C r := eval₂_C _ _ @[simp] theorem expand_X : expand R p X = X ^ p := eval₂_X _ _ @[simp] theorem expand_monomial (r : R) : expand R p (monomial q r) = monomial (q * p) r := by simp_rw [← smul_X_eq_monomial, map_smul, map_pow, expand_X, mul_comm, pow_mul] theorem expand_expand (f : R[X]) : expand R p (expand R q f) = expand R (p * q) f := Polynomial.induction_on f (fun r => by simp_rw [expand_C]) (fun f g ihf ihg => by simp_rw [map_add, ihf, ihg]) fun n r _ => by simp_rw [map_mul, expand_C, map_pow, expand_X, map_pow, expand_X, pow_mul] theorem expand_mul (f : R[X]) : expand R (p * q) f = expand R p (expand R q f) := (expand_expand p q f).symm @[simp] theorem expand_zero (f : R[X]) : expand R 0 f = C (eval 1 f) := by simp [expand] @[simp] theorem expand_one (f : R[X]) : expand R 1 f = f := Polynomial.induction_on f (fun r => by rw [expand_C]) (fun f g ihf ihg => by rw [map_add, ihf, ihg]) fun n r _ => by rw [map_mul, expand_C, map_pow, expand_X, pow_one] theorem expand_pow (f : R[X]) : expand R (p ^ q) f = (expand R p)^[q] f := Nat.recOn q (by rw [pow_zero, expand_one, Function.iterate_zero, id]) fun n ih => by rw [Function.iterate_succ_apply', pow_succ', expand_mul, ih] theorem derivative_expand (f : R[X]) : Polynomial.derivative (expand R p f) = expand R p (Polynomial.derivative f) * (p * (X ^ (p - 1) : R[X])) := by rw [coe_expand, derivative_eval₂_C, derivative_pow, C_eq_natCast, derivative_X, mul_one] theorem coeff_expand {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) : (expand R p f).coeff n = if p ∣ n then f.coeff (n / p) else 0 := by simp only [expand_eq_sum] simp_rw [coeff_sum, ← pow_mul, C_mul_X_pow_eq_monomial, coeff_monomial, sum] split_ifs with h · rw [Finset.sum_eq_single (n / p), Nat.mul_div_cancel' h, if_pos rfl] · intro b _ hb2 rw [if_neg] intro hb3 apply hb2 rw [← hb3, Nat.mul_div_cancel_left b hp] · intro hn rw [not_mem_support_iff.1 hn] split_ifs <;> rfl · rw [Finset.sum_eq_zero] intro k _ rw [if_neg] exact fun hkn => h ⟨k, hkn.symm⟩ @[simp] theorem coeff_expand_mul {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) : (expand R p f).coeff (n * p) = f.coeff n := by rw [coeff_expand hp, if_pos (dvd_mul_left _ _), Nat.mul_div_cancel _ hp] @[simp] theorem coeff_expand_mul' {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) : (expand R p f).coeff (p * n) = f.coeff n := by rw [mul_comm, coeff_expand_mul hp] /-- Expansion is injective. -/ theorem expand_injective {n : ℕ} (hn : 0 < n) : Function.Injective (expand R n) := fun g g' H => ext fun k => by rw [← coeff_expand_mul hn, H, coeff_expand_mul hn] theorem expand_inj {p : ℕ} (hp : 0 < p) {f g : R[X]} : expand R p f = expand R p g ↔ f = g := (expand_injective hp).eq_iff theorem expand_eq_zero {p : ℕ} (hp : 0 < p) {f : R[X]} : expand R p f = 0 ↔ f = 0 := (expand_injective hp).eq_iff' (map_zero _) theorem expand_ne_zero {p : ℕ} (hp : 0 < p) {f : R[X]} : expand R p f ≠ 0 ↔ f ≠ 0 := (expand_eq_zero hp).not
Mathlib/Algebra/Polynomial/Expand.lean
127
128
theorem expand_eq_C {p : ℕ} (hp : 0 < p) {f : R[X]} {r : R} : expand R p f = C r ↔ f = C r := by
rw [← expand_C, expand_inj hp, expand_C]
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Order.Iterate import Mathlib.Order.SemiconjSup import Mathlib.Topology.Order.MonotoneContinuity import Mathlib.Algebra.CharP.Defs /-! # Translation number of a monotone real map that commutes with `x ↦ x + 1` Let `f : ℝ → ℝ` be a monotone map such that `f (x + 1) = f x + 1` for all `x`. Then the limit $$ \tau(f)=\lim_{n\to\infty}{f^n(x)-x}{n} $$ exists and does not depend on `x`. This number is called the *translation number* of `f`. Different authors use different notation for this number: `τ`, `ρ`, `rot`, etc In this file we define a structure `CircleDeg1Lift` for bundled maps with these properties, define translation number of `f : CircleDeg1Lift`, prove some estimates relating `f^n(x)-x` to `τ(f)`. In case of a continuous map `f` we also prove that `f` admits a point `x` such that `f^n(x)=x+m` if and only if `τ(f)=m/n`. Maps of this type naturally appear as lifts of orientation preserving circle homeomorphisms. More precisely, let `f` be an orientation preserving homeomorphism of the circle $S^1=ℝ/ℤ$, and consider a real number `a` such that `⟦a⟧ = f 0`, where `⟦⟧` means the natural projection `ℝ → ℝ/ℤ`. Then there exists a unique continuous function `F : ℝ → ℝ` such that `F 0 = a` and `⟦F x⟧ = f ⟦x⟧` for all `x` (this fact is not formalized yet). This function is strictly monotone, continuous, and satisfies `F (x + 1) = F x + 1`. The number `⟦τ F⟧ : ℝ / ℤ` is called the *rotation number* of `f`. It does not depend on the choice of `a`. ## Main definitions * `CircleDeg1Lift`: a monotone map `f : ℝ → ℝ` such that `f (x + 1) = f x + 1` for all `x`; the type `CircleDeg1Lift` is equipped with `Lattice` and `Monoid` structures; the multiplication is given by composition: `(f * g) x = f (g x)`. * `CircleDeg1Lift.translationNumber`: translation number of `f : CircleDeg1Lift`. ## Main statements We prove the following properties of `CircleDeg1Lift.translationNumber`. * `CircleDeg1Lift.translationNumber_eq_of_dist_bounded`: if the distance between `(f^n) 0` and `(g^n) 0` is bounded from above uniformly in `n : ℕ`, then `f` and `g` have equal translation numbers. * `CircleDeg1Lift.translationNumber_eq_of_semiconjBy`: if two `CircleDeg1Lift` maps `f`, `g` are semiconjugate by a `CircleDeg1Lift` map, then `τ f = τ g`. * `CircleDeg1Lift.translationNumber_units_inv`: if `f` is an invertible `CircleDeg1Lift` map (equivalently, `f` is a lift of an orientation-preserving circle homeomorphism), then the translation number of `f⁻¹` is the negative of the translation number of `f`. * `CircleDeg1Lift.translationNumber_mul_of_commute`: if `f` and `g` commute, then `τ (f * g) = τ f + τ g`. * `CircleDeg1Lift.translationNumber_eq_rat_iff`: the translation number of `f` is equal to a rational number `m / n` if and only if `(f^n) x = x + m` for some `x`. * `CircleDeg1Lift.semiconj_of_bijective_of_translationNumber_eq`: if `f` and `g` are two bijective `CircleDeg1Lift` maps and their translation numbers are equal, then these maps are semiconjugate to each other. * `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`: let `f₁` and `f₂` be two actions of a group `G` on the circle by degree 1 maps (formally, `f₁` and `f₂` are two homomorphisms from `G →* CircleDeg1Lift`). If the translation numbers of `f₁ g` and `f₂ g` are equal to each other for all `g : G`, then these two actions are semiconjugate by some `F : CircleDeg1Lift`. This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes]. ## Notation We use a local notation `τ` for the translation number of `f : CircleDeg1Lift`. ## Implementation notes We define the translation number of `f : CircleDeg1Lift` to be the limit of the sequence `(f ^ (2 ^ n)) 0 / (2 ^ n)`, then prove that `((f ^ n) x - x) / n` tends to this number for any `x`. This way it is much easier to prove that the limit exists and basic properties of the limit. We define translation number for a wider class of maps `f : ℝ → ℝ` instead of lifts of orientation preserving circle homeomorphisms for two reasons: * non-strictly monotone circle self-maps with discontinuities naturally appear as Poincaré maps for some flows on the two-torus (e.g., one can take a constant flow and glue in a few Cherry cells); * definition and some basic properties still work for this class. ## References * [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes] ## TODO Here are some short-term goals. * Introduce a structure or a typeclass for lifts of circle homeomorphisms. We use `Units CircleDeg1Lift` for now, but it's better to have a dedicated type (or a typeclass?). * Prove that the `SemiconjBy` relation on circle homeomorphisms is an equivalence relation. * Introduce `ConditionallyCompleteLattice` structure, use it in the proof of `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`. * Prove that the orbits of the irrational rotation are dense in the circle. Deduce that a homeomorphism with an irrational rotation is semiconjugate to the corresponding irrational translation by a continuous `CircleDeg1Lift`. ## Tags circle homeomorphism, rotation number -/ open Filter Set Int Topology open Function hiding Commute /-! ### Definition and monoid structure -/ /-- A lift of a monotone degree one map `S¹ → S¹`. -/ structure CircleDeg1Lift : Type extends ℝ →o ℝ where map_add_one' : ∀ x, toFun (x + 1) = toFun x + 1 namespace CircleDeg1Lift instance : FunLike CircleDeg1Lift ℝ ℝ where coe f := f.toFun coe_injective' | ⟨⟨_, _⟩, _⟩, ⟨⟨_, _⟩, _⟩, rfl => rfl instance : OrderHomClass CircleDeg1Lift ℝ ℝ where map_rel f _ _ h := f.monotone' h @[simp] theorem coe_mk (f h) : ⇑(mk f h) = f := rfl variable (f g : CircleDeg1Lift) @[simp] theorem coe_toOrderHom : ⇑f.toOrderHom = f := rfl protected theorem monotone : Monotone f := f.monotone' @[mono] theorem mono {x y} (h : x ≤ y) : f x ≤ f y := f.monotone h theorem strictMono_iff_injective : StrictMono f ↔ Injective f := f.monotone.strictMono_iff_injective @[simp] theorem map_add_one : ∀ x, f (x + 1) = f x + 1 := f.map_add_one' @[simp] theorem map_one_add (x : ℝ) : f (1 + x) = 1 + f x := by rw [add_comm, map_add_one, add_comm 1] @[ext] theorem ext ⦃f g : CircleDeg1Lift⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h instance : Monoid CircleDeg1Lift where mul f g := { toOrderHom := f.1.comp g.1 map_add_one' := fun x => by simp [map_add_one] } one := ⟨.id, fun _ => rfl⟩ mul_one _ := rfl one_mul _ := rfl mul_assoc _ _ _ := DFunLike.coe_injective rfl instance : Inhabited CircleDeg1Lift := ⟨1⟩ @[simp] theorem coe_mul : ⇑(f * g) = f ∘ g := rfl theorem mul_apply (x) : (f * g) x = f (g x) := rfl @[simp] theorem coe_one : ⇑(1 : CircleDeg1Lift) = id := rfl instance unitsHasCoeToFun : CoeFun CircleDeg1Liftˣ fun _ => ℝ → ℝ := ⟨fun f => ⇑(f : CircleDeg1Lift)⟩ @[simp] theorem units_inv_apply_apply (f : CircleDeg1Liftˣ) (x : ℝ) : (f⁻¹ : CircleDeg1Liftˣ) (f x) = x := by simp only [← mul_apply, f.inv_mul, coe_one, id] @[simp] theorem units_apply_inv_apply (f : CircleDeg1Liftˣ) (x : ℝ) : f ((f⁻¹ : CircleDeg1Liftˣ) x) = x := by simp only [← mul_apply, f.mul_inv, coe_one, id] /-- If a lift of a circle map is bijective, then it is an order automorphism of the line. -/ def toOrderIso : CircleDeg1Liftˣ →* ℝ ≃o ℝ where toFun f := { toFun := f invFun := ⇑f⁻¹ left_inv := units_inv_apply_apply f right_inv := units_apply_inv_apply f map_rel_iff' := ⟨fun h => by simpa using mono (↑f⁻¹) h, mono f⟩ } map_one' := rfl map_mul' _ _ := rfl @[simp] theorem coe_toOrderIso (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f) = f := rfl @[simp] theorem coe_toOrderIso_symm (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f).symm = (f⁻¹ : CircleDeg1Liftˣ) := rfl @[simp] theorem coe_toOrderIso_inv (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f)⁻¹ = (f⁻¹ : CircleDeg1Liftˣ) := rfl theorem isUnit_iff_bijective {f : CircleDeg1Lift} : IsUnit f ↔ Bijective f := ⟨fun ⟨u, h⟩ => h ▸ (toOrderIso u).bijective, fun h => Units.isUnit { val := f inv := { toFun := (Equiv.ofBijective f h).symm monotone' := fun x y hxy => (f.strictMono_iff_injective.2 h.1).le_iff_le.1 (by simp only [Equiv.ofBijective_apply_symm_apply f h, hxy]) map_add_one' := fun x => h.1 <| by simp only [Equiv.ofBijective_apply_symm_apply f, f.map_add_one] } val_inv := ext <| Equiv.ofBijective_apply_symm_apply f h inv_val := ext <| Equiv.ofBijective_symm_apply_apply f h }⟩ theorem coe_pow : ∀ n : ℕ, ⇑(f ^ n) = f^[n] | 0 => rfl | n + 1 => by ext x simp [coe_pow n, pow_succ] theorem semiconjBy_iff_semiconj {f g₁ g₂ : CircleDeg1Lift} : SemiconjBy f g₁ g₂ ↔ Semiconj f g₁ g₂ := CircleDeg1Lift.ext_iff theorem commute_iff_commute {f g : CircleDeg1Lift} : Commute f g ↔ Function.Commute f g := CircleDeg1Lift.ext_iff /-! ### Translate by a constant -/ /-- The map `y ↦ x + y` as a `CircleDeg1Lift`. More precisely, we define a homomorphism from `Multiplicative ℝ` to `CircleDeg1Liftˣ`, so the translation by `x` is `translation (Multiplicative.ofAdd x)`. -/ def translate : Multiplicative ℝ →* CircleDeg1Liftˣ := MonoidHom.toHomUnits <| { toFun := fun x => ⟨⟨fun y => x.toAdd + y, fun _ _ h => add_le_add_left h _⟩, fun _ => (add_assoc _ _ _).symm⟩ map_one' := ext <| zero_add map_mul' := fun _ _ => ext <| add_assoc _ _ } @[simp] theorem translate_apply (x y : ℝ) : translate (Multiplicative.ofAdd x) y = x + y := rfl @[simp] theorem translate_inv_apply (x y : ℝ) : (translate <| Multiplicative.ofAdd x)⁻¹ y = -x + y := rfl @[simp] theorem translate_zpow (x : ℝ) (n : ℤ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := by simp only [← zsmul_eq_mul, ofAdd_zsmul, MonoidHom.map_zpow] @[simp] theorem translate_pow (x : ℝ) (n : ℕ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := translate_zpow x n @[simp] theorem translate_iterate (x : ℝ) (n : ℕ) : (translate (Multiplicative.ofAdd x))^[n] = translate (Multiplicative.ofAdd <| ↑n * x) := by rw [← coe_pow, ← Units.val_pow_eq_pow_val, translate_pow] /-! ### Commutativity with integer translations In this section we prove that `f` commutes with translations by an integer number. First we formulate these statements (for a natural or an integer number, addition on the left or on the right, addition or subtraction) using `Function.Commute`, then reformulate as `simp` lemmas `map_int_add` etc. -/ theorem commute_nat_add (n : ℕ) : Function.Commute f (n + ·) := by simpa only [nsmul_one, add_left_iterate] using Function.Commute.iterate_right f.map_one_add n theorem commute_add_nat (n : ℕ) : Function.Commute f (· + n) := by simp only [add_comm _ (n : ℝ), f.commute_nat_add n] theorem commute_sub_nat (n : ℕ) : Function.Commute f (· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_nat n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv theorem commute_add_int : ∀ n : ℤ, Function.Commute f (· + n) | (n : ℕ) => f.commute_add_nat n | -[n+1] => by simpa [sub_eq_add_neg] using f.commute_sub_nat (n + 1) theorem commute_int_add (n : ℤ) : Function.Commute f (n + ·) := by simpa only [add_comm _ (n : ℝ)] using f.commute_add_int n theorem commute_sub_int (n : ℤ) : Function.Commute f (· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_int n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv @[simp] theorem map_int_add (m : ℤ) (x : ℝ) : f (m + x) = m + f x := f.commute_int_add m x @[simp] theorem map_add_int (x : ℝ) (m : ℤ) : f (x + m) = f x + m := f.commute_add_int m x @[simp] theorem map_sub_int (x : ℝ) (n : ℤ) : f (x - n) = f x - n := f.commute_sub_int n x @[simp] theorem map_add_nat (x : ℝ) (n : ℕ) : f (x + n) = f x + n := f.map_add_int x n @[simp] theorem map_nat_add (n : ℕ) (x : ℝ) : f (n + x) = n + f x := f.map_int_add n x @[simp] theorem map_sub_nat (x : ℝ) (n : ℕ) : f (x - n) = f x - n := f.map_sub_int x n theorem map_int_of_map_zero (n : ℤ) : f n = f 0 + n := by rw [← f.map_add_int, zero_add] @[simp] theorem map_fract_sub_fract_eq (x : ℝ) : f (fract x) - fract x = f x - x := by rw [Int.fract, f.map_sub_int, sub_sub_sub_cancel_right] /-! ### Pointwise order on circle maps -/ /-- Monotone circle maps form a lattice with respect to the pointwise order -/ noncomputable instance : Lattice CircleDeg1Lift where sup f g := { toFun := fun x => max (f x) (g x) monotone' := fun _ _ h => max_le_max (f.mono h) (g.mono h) -- TODO: generalize to `Monotone.max` map_add_one' := fun x => by simp [max_add_add_right] } le f g := ∀ x, f x ≤ g x le_refl f x := le_refl (f x) le_trans _ _ _ h₁₂ h₂₃ x := le_trans (h₁₂ x) (h₂₃ x) le_antisymm _ _ h₁₂ h₂₁ := ext fun x => le_antisymm (h₁₂ x) (h₂₁ x) le_sup_left f g x := le_max_left (f x) (g x) le_sup_right f g x := le_max_right (f x) (g x) sup_le _ _ _ h₁ h₂ x := max_le (h₁ x) (h₂ x) inf f g := { toFun := fun x => min (f x) (g x) monotone' := fun _ _ h => min_le_min (f.mono h) (g.mono h) map_add_one' := fun x => by simp [min_add_add_right] } inf_le_left f g x := min_le_left (f x) (g x) inf_le_right f g x := min_le_right (f x) (g x) le_inf _ _ _ h₂ h₃ x := le_min (h₂ x) (h₃ x) @[simp] theorem sup_apply (x : ℝ) : (f ⊔ g) x = max (f x) (g x) := rfl @[simp] theorem inf_apply (x : ℝ) : (f ⊓ g) x = min (f x) (g x) := rfl theorem iterate_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f^[n] := fun f _ h => f.monotone.iterate_le_of_le h _ theorem iterate_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f^[n] ≤ g^[n] := iterate_monotone n h theorem pow_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f ^ n ≤ g ^ n := fun x => by simp only [coe_pow, iterate_mono h n x] theorem pow_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f ^ n := fun _ _ h => pow_mono h n /-! ### Estimates on `(f * g) 0` We prove the estimates `f 0 + ⌊g 0⌋ ≤ f (g 0) ≤ f 0 + ⌈g 0⌉` and some corollaries with added/removed floors and ceils. We also prove that for two semiconjugate maps `g₁`, `g₂`, the distance between `g₁ 0` and `g₂ 0` is less than two. -/ theorem map_le_of_map_zero (x : ℝ) : f x ≤ f 0 + ⌈x⌉ := calc f x ≤ f ⌈x⌉ := f.monotone <| le_ceil _ _ = f 0 + ⌈x⌉ := f.map_int_of_map_zero _ theorem map_map_zero_le : f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_le_of_map_zero (g 0) theorem floor_map_map_zero_le : ⌊f (g 0)⌋ ≤ ⌊f 0⌋ + ⌈g 0⌉ := calc ⌊f (g 0)⌋ ≤ ⌊f 0 + ⌈g 0⌉⌋ := floor_mono <| f.map_map_zero_le g _ = ⌊f 0⌋ + ⌈g 0⌉ := floor_add_intCast _ _ theorem ceil_map_map_zero_le : ⌈f (g 0)⌉ ≤ ⌈f 0⌉ + ⌈g 0⌉ := calc ⌈f (g 0)⌉ ≤ ⌈f 0 + ⌈g 0⌉⌉ := ceil_mono <| f.map_map_zero_le g _ = ⌈f 0⌉ + ⌈g 0⌉ := ceil_add_intCast _ _ theorem map_map_zero_lt : f (g 0) < f 0 + g 0 + 1 := calc f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_map_zero_le g _ < f 0 + (g 0 + 1) := add_lt_add_left (ceil_lt_add_one _) _ _ = f 0 + g 0 + 1 := (add_assoc _ _ _).symm theorem le_map_of_map_zero (x : ℝ) : f 0 + ⌊x⌋ ≤ f x := calc f 0 + ⌊x⌋ = f ⌊x⌋ := (f.map_int_of_map_zero _).symm _ ≤ f x := f.monotone <| floor_le _ theorem le_map_map_zero : f 0 + ⌊g 0⌋ ≤ f (g 0) := f.le_map_of_map_zero (g 0) theorem le_floor_map_map_zero : ⌊f 0⌋ + ⌊g 0⌋ ≤ ⌊f (g 0)⌋ := calc ⌊f 0⌋ + ⌊g 0⌋ = ⌊f 0 + ⌊g 0⌋⌋ := (floor_add_intCast _ _).symm _ ≤ ⌊f (g 0)⌋ := floor_mono <| f.le_map_map_zero g theorem le_ceil_map_map_zero : ⌈f 0⌉ + ⌊g 0⌋ ≤ ⌈(f * g) 0⌉ := calc ⌈f 0⌉ + ⌊g 0⌋ = ⌈f 0 + ⌊g 0⌋⌉ := (ceil_add_intCast _ _).symm _ ≤ ⌈f (g 0)⌉ := ceil_mono <| f.le_map_map_zero g theorem lt_map_map_zero : f 0 + g 0 - 1 < f (g 0) := calc f 0 + g 0 - 1 = f 0 + (g 0 - 1) := add_sub_assoc _ _ _ _ < f 0 + ⌊g 0⌋ := add_lt_add_left (sub_one_lt_floor _) _ _ ≤ f (g 0) := f.le_map_map_zero g theorem dist_map_map_zero_lt : dist (f 0 + g 0) (f (g 0)) < 1 := by rw [dist_comm, Real.dist_eq, abs_lt, lt_sub_iff_add_lt', sub_lt_iff_lt_add', ← sub_eq_add_neg] exact ⟨f.lt_map_map_zero g, f.map_map_zero_lt g⟩ theorem dist_map_zero_lt_of_semiconj {f g₁ g₂ : CircleDeg1Lift} (h : Function.Semiconj f g₁ g₂) : dist (g₁ 0) (g₂ 0) < 2 := calc dist (g₁ 0) (g₂ 0) ≤ dist (g₁ 0) (f (g₁ 0) - f 0) + dist _ (g₂ 0) := dist_triangle _ _ _ _ = dist (f 0 + g₁ 0) (f (g₁ 0)) + dist (g₂ 0 + f 0) (g₂ (f 0)) := by simp only [h.eq, Real.dist_eq, sub_sub, add_comm (f 0), sub_sub_eq_add_sub, abs_sub_comm (g₂ (f 0))] _ < 1 + 1 := add_lt_add (f.dist_map_map_zero_lt g₁) (g₂.dist_map_map_zero_lt f) _ = 2 := one_add_one_eq_two theorem dist_map_zero_lt_of_semiconjBy {f g₁ g₂ : CircleDeg1Lift} (h : SemiconjBy f g₁ g₂) : dist (g₁ 0) (g₂ 0) < 2 := dist_map_zero_lt_of_semiconj <| semiconjBy_iff_semiconj.1 h /-! ### Limits at infinities and continuity -/ protected theorem tendsto_atBot : Tendsto f atBot atBot := tendsto_atBot_mono f.map_le_of_map_zero <| tendsto_atBot_add_const_left _ _ <| (tendsto_atBot_mono fun x => (ceil_lt_add_one x).le) <| tendsto_atBot_add_const_right _ _ tendsto_id protected theorem tendsto_atTop : Tendsto f atTop atTop := tendsto_atTop_mono f.le_map_of_map_zero <| tendsto_atTop_add_const_left _ _ <| (tendsto_atTop_mono fun x => (sub_one_lt_floor x).le) <| by simpa [sub_eq_add_neg] using tendsto_atTop_add_const_right _ _ tendsto_id theorem continuous_iff_surjective : Continuous f ↔ Function.Surjective f := ⟨fun h => h.surjective f.tendsto_atTop f.tendsto_atBot, f.monotone.continuous_of_surjective⟩ /-! ### Estimates on `(f^n) x` If we know that `f x` is `≤`/`<`/`≥`/`>`/`=` to `x + m`, then we have a similar estimate on `f^[n] x` and `x + n * m`. For `≤`, `≥`, and `=` we formulate both `of` (implication) and `iff` versions because implications work for `n = 0`. For `<` and `>` we formulate only `iff` versions. -/ theorem iterate_le_of_map_le_add_int {x : ℝ} {m : ℤ} (h : f x ≤ x + m) (n : ℕ) : f^[n] x ≤ x + n * m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_le_of_map_le f.monotone (monotone_id.add_const (m : ℝ)) h n theorem le_iterate_of_add_int_le_map {x : ℝ} {m : ℤ} (h : x + m ≤ f x) (n : ℕ) : x + n * m ≤ f^[n] x := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).symm.iterate_le_of_map_le (monotone_id.add_const (m : ℝ)) f.monotone h n theorem iterate_eq_of_map_eq_add_int {x : ℝ} {m : ℤ} (h : f x = x + m) (n : ℕ) : f^[n] x = x + n * m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_eq_of_map_eq n h theorem iterate_pos_le_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x ≤ x + n * m ↔ f x ≤ x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_le_iff_map_le f.monotone (strictMono_id.add_const (m : ℝ)) hn theorem iterate_pos_lt_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x < x + n * m ↔ f x < x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_lt_iff_map_lt f.monotone (strictMono_id.add_const (m : ℝ)) hn theorem iterate_pos_eq_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x = x + n * m ↔ f x = x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_eq_iff_map_eq f.monotone (strictMono_id.add_const (m : ℝ)) hn theorem le_iterate_pos_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : x + n * m ≤ f^[n] x ↔ x + m ≤ f x := by simpa only [not_lt] using not_congr (f.iterate_pos_lt_iff hn) theorem lt_iterate_pos_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : x + n * m < f^[n] x ↔ x + m < f x := by simpa only [not_le] using not_congr (f.iterate_pos_le_iff hn) theorem mul_floor_map_zero_le_floor_iterate_zero (n : ℕ) : ↑n * ⌊f 0⌋ ≤ ⌊f^[n] 0⌋ := by rw [le_floor, Int.cast_mul, Int.cast_natCast, ← zero_add ((n : ℝ) * _)] apply le_iterate_of_add_int_le_map simp [floor_le] /-! ### Definition of translation number -/ noncomputable section /-- An auxiliary sequence used to define the translation number. -/ def transnumAuxSeq (n : ℕ) : ℝ := (f ^ (2 ^ n : ℕ)) 0 / 2 ^ n /-- The translation number of a `CircleDeg1Lift`, $τ(f)=\lim_{n→∞}\frac{f^n(x)-x}{n}$. We use an auxiliary sequence `\frac{f^{2^n}(0)}{2^n}` to define `τ(f)` because some proofs are simpler this way. -/ def translationNumber : ℝ := limUnder atTop f.transnumAuxSeq end -- TODO: choose two different symbols for `CircleDeg1Lift.translationNumber` and the future -- `circle_mono_homeo.rotation_number`, then make them `localized notation`s local notation "τ" => translationNumber theorem transnumAuxSeq_def : f.transnumAuxSeq = fun n : ℕ => (f ^ (2 ^ n : ℕ)) 0 / 2 ^ n := rfl theorem translationNumber_eq_of_tendsto_aux {τ' : ℝ} (h : Tendsto f.transnumAuxSeq atTop (𝓝 τ')) : τ f = τ' := h.limUnder_eq theorem translationNumber_eq_of_tendsto₀ {τ' : ℝ} (h : Tendsto (fun n : ℕ => f^[n] 0 / n) atTop (𝓝 τ')) : τ f = τ' := f.translationNumber_eq_of_tendsto_aux <| by simpa [Function.comp_def, transnumAuxSeq_def, coe_pow] using h.comp (Nat.tendsto_pow_atTop_atTop_of_one_lt one_lt_two) theorem translationNumber_eq_of_tendsto₀' {τ' : ℝ} (h : Tendsto (fun n : ℕ => f^[n + 1] 0 / (n + 1)) atTop (𝓝 τ')) : τ f = τ' := f.translationNumber_eq_of_tendsto₀ <| (tendsto_add_atTop_iff_nat 1).1 (mod_cast h) theorem transnumAuxSeq_zero : f.transnumAuxSeq 0 = f 0 := by simp [transnumAuxSeq] theorem transnumAuxSeq_dist_lt (n : ℕ) : dist (f.transnumAuxSeq n) (f.transnumAuxSeq (n + 1)) < 1 / 2 / 2 ^ n := by have : 0 < (2 ^ (n + 1) : ℝ) := pow_pos zero_lt_two _ rw [div_div, ← pow_succ', ← abs_of_pos this] calc _ = dist ((f ^ 2 ^ n) 0 + (f ^ 2 ^ n) 0) ((f ^ 2 ^ n) ((f ^ 2 ^ n) 0)) / |2 ^ (n + 1)| := by simp_rw [transnumAuxSeq, Real.dist_eq] rw [← abs_div, sub_div, pow_succ, pow_succ', ← two_mul, mul_div_mul_left _ _ (two_ne_zero' ℝ), pow_mul, sq, mul_apply] _ < _ := by gcongr; exact (f ^ 2 ^ n).dist_map_map_zero_lt (f ^ 2 ^ n) theorem tendsto_translationNumber_aux : Tendsto f.transnumAuxSeq atTop (𝓝 <| τ f) := (cauchySeq_of_le_geometric_two fun n => le_of_lt <| f.transnumAuxSeq_dist_lt n).tendsto_limUnder theorem dist_map_zero_translationNumber_le : dist (f 0) (τ f) ≤ 1 := f.transnumAuxSeq_zero ▸ dist_le_of_le_geometric_two_of_tendsto₀ (fun n => le_of_lt <| f.transnumAuxSeq_dist_lt n) f.tendsto_translationNumber_aux theorem tendsto_translationNumber_of_dist_bounded_aux (x : ℕ → ℝ) (C : ℝ) (H : ∀ n : ℕ, dist ((f ^ n) 0) (x n) ≤ C) : Tendsto (fun n : ℕ => x (2 ^ n) / 2 ^ n) atTop (𝓝 <| τ f) := by apply f.tendsto_translationNumber_aux.congr_dist (squeeze_zero (fun _ => dist_nonneg) _ _) · exact fun n => C / 2 ^ n · intro n have : 0 < (2 ^ n : ℝ) := pow_pos zero_lt_two _ convert (div_le_div_iff_of_pos_right this).2 (H (2 ^ n)) using 1 rw [transnumAuxSeq, Real.dist_eq, ← sub_div, abs_div, abs_of_pos this, Real.dist_eq] · exact mul_zero C ▸ tendsto_const_nhds.mul <| tendsto_inv_atTop_zero.comp <| tendsto_pow_atTop_atTop_of_one_lt one_lt_two theorem translationNumber_eq_of_dist_bounded {f g : CircleDeg1Lift} (C : ℝ) (H : ∀ n : ℕ, dist ((f ^ n) 0) ((g ^ n) 0) ≤ C) : τ f = τ g := Eq.symm <| g.translationNumber_eq_of_tendsto_aux <| f.tendsto_translationNumber_of_dist_bounded_aux (fun n ↦ (g ^ n) 0) C H @[simp] theorem translationNumber_one : τ 1 = 0 := translationNumber_eq_of_tendsto₀ _ <| by simp [tendsto_const_nhds] theorem translationNumber_eq_of_semiconjBy {f g₁ g₂ : CircleDeg1Lift} (H : SemiconjBy f g₁ g₂) : τ g₁ = τ g₂ := translationNumber_eq_of_dist_bounded 2 fun n => le_of_lt <| dist_map_zero_lt_of_semiconjBy <| H.pow_right n theorem translationNumber_eq_of_semiconj {f g₁ g₂ : CircleDeg1Lift} (H : Function.Semiconj f g₁ g₂) : τ g₁ = τ g₂ := translationNumber_eq_of_semiconjBy <| semiconjBy_iff_semiconj.2 H theorem translationNumber_mul_of_commute {f g : CircleDeg1Lift} (h : Commute f g) : τ (f * g) = τ f + τ g := by refine tendsto_nhds_unique ?_ (f.tendsto_translationNumber_aux.add g.tendsto_translationNumber_aux) simp only [transnumAuxSeq, ← add_div] refine (f * g).tendsto_translationNumber_of_dist_bounded_aux (fun n ↦ (f ^ n) 0 + (g ^ n) 0) 1 fun n ↦ ?_ rw [h.mul_pow, dist_comm] exact le_of_lt ((f ^ n).dist_map_map_zero_lt (g ^ n)) @[simp] theorem translationNumber_units_inv (f : CircleDeg1Liftˣ) : τ ↑f⁻¹ = -τ f := eq_neg_iff_add_eq_zero.2 <| by simp [← translationNumber_mul_of_commute (Commute.refl _).units_inv_left] @[simp] theorem translationNumber_pow : ∀ n : ℕ, τ (f ^ n) = n * τ f | 0 => by simp | n + 1 => by rw [pow_succ, translationNumber_mul_of_commute (Commute.pow_self f n), translationNumber_pow n, Nat.cast_add_one, add_mul, one_mul] @[simp] theorem translationNumber_zpow (f : CircleDeg1Liftˣ) : ∀ n : ℤ, τ (f ^ n : Units _) = n * τ f | (n : ℕ) => by simp [translationNumber_pow f n] | -[n+1] => by simp; ring @[simp] theorem translationNumber_conj_eq (f : CircleDeg1Liftˣ) (g : CircleDeg1Lift) : τ (↑f * g * ↑f⁻¹) = τ g := (translationNumber_eq_of_semiconjBy (f.mk_semiconjBy g)).symm @[simp] theorem translationNumber_conj_eq' (f : CircleDeg1Liftˣ) (g : CircleDeg1Lift) : τ (↑f⁻¹ * g * f) = τ g := translationNumber_conj_eq f⁻¹ g theorem dist_pow_map_zero_mul_translationNumber_le (n : ℕ) : dist ((f ^ n) 0) (n * f.translationNumber) ≤ 1 := f.translationNumber_pow n ▸ (f ^ n).dist_map_zero_translationNumber_le theorem tendsto_translation_number₀' : Tendsto (fun n : ℕ => (f ^ (n + 1) : CircleDeg1Lift) 0 / ((n : ℝ) + 1)) atTop (𝓝 <| τ f) := by refine tendsto_iff_dist_tendsto_zero.2 <| squeeze_zero (fun _ => dist_nonneg) (fun n => ?_) ((tendsto_const_div_atTop_nhds_zero_nat 1).comp (tendsto_add_atTop_nat 1)) dsimp have : (0 : ℝ) < n + 1 := n.cast_add_one_pos rw [Real.dist_eq, div_sub' (ne_of_gt this), abs_div, ← Real.dist_eq, abs_of_pos this, Nat.cast_add_one, div_le_div_iff_of_pos_right this, ← Nat.cast_add_one] apply dist_pow_map_zero_mul_translationNumber_le theorem tendsto_translation_number₀ : Tendsto (fun n : ℕ => (f ^ n) 0 / n) atTop (𝓝 <| τ f) := (tendsto_add_atTop_iff_nat 1).1 (mod_cast f.tendsto_translation_number₀') /-- For any `x : ℝ` the sequence $\frac{f^n(x)-x}{n}$ tends to the translation number of `f`. In particular, this limit does not depend on `x`. -/ theorem tendsto_translationNumber (x : ℝ) : Tendsto (fun n : ℕ => ((f ^ n) x - x) / n) atTop (𝓝 <| τ f) := by rw [← translationNumber_conj_eq' (translate <| Multiplicative.ofAdd x)] refine (tendsto_translation_number₀ _).congr fun n ↦ ?_ simp [sub_eq_neg_add, Units.conj_pow'] theorem tendsto_translation_number' (x : ℝ) : Tendsto (fun n : ℕ => ((f ^ (n + 1) : CircleDeg1Lift) x - x) / (n + 1)) atTop (𝓝 <| τ f) := mod_cast (tendsto_add_atTop_iff_nat 1).2 (f.tendsto_translationNumber x) theorem translationNumber_mono : Monotone τ := fun f g h => le_of_tendsto_of_tendsto' f.tendsto_translation_number₀ g.tendsto_translation_number₀ fun n => by gcongr; exact pow_mono h _ _ theorem translationNumber_translate (x : ℝ) : τ (translate <| Multiplicative.ofAdd x) = x := translationNumber_eq_of_tendsto₀' _ <| by simp only [translate_iterate, translate_apply, add_zero, Nat.cast_succ, mul_div_cancel_left₀ (M₀ := ℝ) _ (Nat.cast_add_one_ne_zero _), tendsto_const_nhds] theorem translationNumber_le_of_le_add {z : ℝ} (hz : ∀ x, f x ≤ x + z) : τ f ≤ z := translationNumber_translate z ▸ translationNumber_mono fun x => (hz x).trans_eq (add_comm _ _) theorem le_translationNumber_of_add_le {z : ℝ} (hz : ∀ x, x + z ≤ f x) : z ≤ τ f := translationNumber_translate z ▸ translationNumber_mono fun x => (add_comm _ _).trans_le (hz x) theorem translationNumber_le_of_le_add_int {x : ℝ} {m : ℤ} (h : f x ≤ x + m) : τ f ≤ m := le_of_tendsto' (f.tendsto_translation_number' x) fun n => (div_le_iff₀' (n.cast_add_one_pos : (0 : ℝ) < _)).mpr <| sub_le_iff_le_add'.2 <| (coe_pow f (n + 1)).symm ▸ @Nat.cast_add_one ℝ _ n ▸ f.iterate_le_of_map_le_add_int h (n + 1) theorem translationNumber_le_of_le_add_nat {x : ℝ} {m : ℕ} (h : f x ≤ x + m) : τ f ≤ m := @translationNumber_le_of_le_add_int f x m h theorem le_translationNumber_of_add_int_le {x : ℝ} {m : ℤ} (h : x + m ≤ f x) : ↑m ≤ τ f := ge_of_tendsto' (f.tendsto_translation_number' x) fun n => (le_div_iff₀ (n.cast_add_one_pos : (0 : ℝ) < _)).mpr <| le_sub_iff_add_le'.2 <| by simp only [coe_pow, mul_comm (m : ℝ), ← Nat.cast_add_one, f.le_iterate_of_add_int_le_map h] theorem le_translationNumber_of_add_nat_le {x : ℝ} {m : ℕ} (h : x + m ≤ f x) : ↑m ≤ τ f := @le_translationNumber_of_add_int_le f x m h /-- If `f x - x` is an integer number `m` for some point `x`, then `τ f = m`. On the circle this means that a map with a fixed point has rotation number zero. -/ theorem translationNumber_of_eq_add_int {x : ℝ} {m : ℤ} (h : f x = x + m) : τ f = m := le_antisymm (translationNumber_le_of_le_add_int f <| le_of_eq h) (le_translationNumber_of_add_int_le f <| le_of_eq h.symm) theorem floor_sub_le_translationNumber (x : ℝ) : ↑⌊f x - x⌋ ≤ τ f := le_translationNumber_of_add_int_le f <| le_sub_iff_add_le'.1 (floor_le <| f x - x) theorem translationNumber_le_ceil_sub (x : ℝ) : τ f ≤ ⌈f x - x⌉ := translationNumber_le_of_le_add_int f <| sub_le_iff_le_add'.1 (le_ceil <| f x - x) theorem map_lt_of_translationNumber_lt_int {n : ℤ} (h : τ f < n) (x : ℝ) : f x < x + n := not_le.1 <| mt f.le_translationNumber_of_add_int_le <| not_le.2 h theorem map_lt_of_translationNumber_lt_nat {n : ℕ} (h : τ f < n) (x : ℝ) : f x < x + n := @map_lt_of_translationNumber_lt_int f n h x
Mathlib/Dynamics/Circle/RotationNumber/TranslationNumber.lean
743
747
theorem map_lt_add_floor_translationNumber_add_one (x : ℝ) : f x < x + ⌊τ f⌋ + 1 := by
rw [add_assoc] norm_cast refine map_lt_of_translationNumber_lt_int _ ?_ _ push_cast
/- Copyright (c) 2024 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker, Devon Tuma, Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Density import Mathlib.Probability.ConditionalProbability import Mathlib.Probability.ProbabilityMassFunction.Constructions /-! # Uniform distributions and probability mass functions This file defines two related notions of uniform distributions, which will be unified in the future. # Uniform distributions Defines the uniform distribution for any set with finite measure. ## Main definitions * `IsUniform X s ℙ μ` : A random variable `X` has uniform distribution on `s` under `ℙ` if the push-forward measure agrees with the rescaled restricted measure `μ`. # Uniform probability mass functions This file defines a number of uniform `PMF` distributions from various inputs, uniformly drawing from the corresponding object. ## Main definitions `PMF.uniformOfFinset` gives each element in the set equal probability, with `0` probability for elements not in the set. `PMF.uniformOfFintype` gives all elements equal probability, equal to the inverse of the size of the `Fintype`. `PMF.ofMultiset` draws randomly from the given `Multiset`, treating duplicate values as distinct. Each probability is given by the count of the element divided by the size of the `Multiset` ## TODO * Refactor the `PMF` definitions to come from a `uniformMeasure` on a `Finset`/`Fintype`/`Multiset`. -/ open scoped Finset MeasureTheory NNReal ENNReal -- TODO: We can't `open ProbabilityTheory` without opening the `ProbabilityTheory` locale :( open TopologicalSpace MeasureTheory.Measure PMF noncomputable section namespace MeasureTheory variable {E : Type*} [MeasurableSpace E] {μ : Measure E} namespace pdf variable {Ω : Type*} variable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} /-- A random variable `X` has uniform distribution on `s` if its push-forward measure is `(μ s)⁻¹ • μ.restrict s`. -/ def IsUniform (X : Ω → E) (s : Set E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) := map X ℙ = ProbabilityTheory.cond μ s namespace IsUniform theorem aemeasurable {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : AEMeasurable X ℙ := by dsimp [IsUniform, ProbabilityTheory.cond] at hu by_contra h rw [map_of_not_aemeasurable h] at hu apply zero_ne_one' ℝ≥0∞ calc 0 = (0 : Measure E) Set.univ := rfl _ = _ := by rw [hu, smul_apply, restrict_apply MeasurableSet.univ, Set.univ_inter, smul_eq_mul, ENNReal.inv_mul_cancel hns hnt] theorem absolutelyContinuous {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : map X ℙ ≪ μ := by rw [hu]; exact ProbabilityTheory.cond_absolutelyContinuous theorem measure_preimage {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) {A : Set E} (hA : MeasurableSet A) : ℙ (X ⁻¹' A) = μ (s ∩ A) / μ s := by rwa [← map_apply_of_aemeasurable (hu.aemeasurable hns hnt) hA, hu, ProbabilityTheory.cond_apply', ENNReal.div_eq_inv_mul] theorem isProbabilityMeasure {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : IsProbabilityMeasure ℙ := ⟨by have : X ⁻¹' Set.univ = Set.univ := Set.preimage_univ rw [← this, hu.measure_preimage hns hnt MeasurableSet.univ, Set.inter_univ, ENNReal.div_self hns hnt]⟩ theorem toMeasurable_iff {X : Ω → E} {s : Set E} : IsUniform X (toMeasurable μ s) ℙ μ ↔ IsUniform X s ℙ μ := by unfold IsUniform rw [ProbabilityTheory.cond_toMeasurable_eq] protected theorem toMeasurable {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : IsUniform X (toMeasurable μ s) ℙ μ := by unfold IsUniform at * rwa [ProbabilityTheory.cond_toMeasurable_eq] theorem hasPDF {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by let t := toMeasurable μ s apply hasPDF_of_map_eq_withDensity (hu.aemeasurable hns hnt) (t.indicator ((μ t)⁻¹ • 1)) <| (measurable_one.aemeasurable.const_smul (μ t)⁻¹).indicator (measurableSet_toMeasurable μ s) rw [hu, withDensity_indicator (measurableSet_toMeasurable μ s), withDensity_smul _ measurable_one, withDensity_one, restrict_toMeasurable hnt, measure_toMeasurable, ProbabilityTheory.cond] theorem pdf_eq_zero_of_measure_eq_zero_or_top {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) (hμs : μ s = 0 ∨ μ s = ∞) : pdf X ℙ μ =ᵐ[μ] 0 := by rcases hμs with H|H · simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_zero, restrict_eq_zero.mpr H, smul_zero] at hu simp [pdf, hu] · simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_top, zero_smul] at hu simp [pdf, hu] theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hu : IsUniform X s ℙ μ) : pdf X ℙ μ =ᵐ[μ] s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) := by by_cases hnt : μ s = ∞ · simp [pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inr hnt), hnt] by_cases hns : μ s = 0 · filter_upwards [measure_zero_iff_ae_nmem.mp hns, pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inl hns)] with x hx h'x simp [hx, h'x, hns] have : HasPDF X ℙ μ := hasPDF hns hnt hu have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu apply (eq_of_map_eq_withDensity _ _).mp · rw [hu, withDensity_indicator hms, withDensity_smul _ measurable_one, withDensity_one, ProbabilityTheory.cond] · exact (measurable_one.aemeasurable.const_smul (μ s)⁻¹).indicator hms theorem pdf_toReal_ae_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hX : IsUniform X s ℙ μ) : (fun x => (pdf X ℙ μ x).toReal) =ᵐ[μ] fun x => (s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x).toReal := Filter.EventuallyEq.fun_comp (pdf_eq hms hX) ENNReal.toReal variable {X : Ω → ℝ} {s : Set ℝ} theorem mul_pdf_integrable (hcs : IsCompact s) (huX : IsUniform X s ℙ) : Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by by_cases hnt : volume s = 0 ∨ volume s = ∞ · have I : Integrable (fun x ↦ x * ENNReal.toReal (0)) := by simp apply I.congr filter_upwards [pdf_eq_zero_of_measure_eq_zero_or_top huX hnt] with x hx simp [hx] simp only [not_or] at hnt have : IsProbabilityMeasure ℙ := isProbabilityMeasure hnt.1 hnt.2 huX constructor · exact aestronglyMeasurable_id.mul (measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable refine hasFiniteIntegral_mul (pdf_eq hcs.measurableSet huX) ?_ set ind := (volume s)⁻¹ • (1 : ℝ → ℝ≥0∞) have : ∀ x, ‖x‖ₑ * s.indicator ind x = s.indicator (fun x => ‖x‖ₑ * ind x) x := fun x => (s.indicator_mul_right (fun x => ↑‖x‖₊) ind).symm simp only [ind, this, lintegral_indicator hcs.measurableSet, mul_one, Algebra.id.smul_eq_mul, Pi.one_apply, Pi.smul_apply] rw [lintegral_mul_const _ measurable_enorm] exact ENNReal.mul_ne_top (setLIntegral_lt_top_of_isCompact hnt.2 hcs continuous_nnnorm).ne (ENNReal.inv_lt_top.2 (pos_iff_ne_zero.mpr hnt.1)).ne /-- A real uniform random variable `X` with support `s` has expectation `(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/ theorem integral_eq (huX : IsUniform X s ℙ) : ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by rw [← smul_eq_mul, ← integral_smul_measure] dsimp only [IsUniform, ProbabilityTheory.cond] at huX rw [← huX] by_cases hX : AEMeasurable X ℙ · exact (integral_map hX aestronglyMeasurable_id).symm · rw [map_of_not_aemeasurable hX, integral_zero_measure, integral_non_aestronglyMeasurable] rwa [aestronglyMeasurable_iff_aemeasurable] end IsUniform variable {X : Ω → E} lemma IsUniform.cond {s : Set E} : IsUniform (id : E → E) s (ProbabilityTheory.cond μ s) μ := by unfold IsUniform rw [Measure.map_id] /-- The density of the uniform measure on a set with respect to itself. This allows us to abstract away the choice of random variable and probability space. -/ def uniformPDF (s : Set E) (x : E) (μ : Measure E := by volume_tac) : ℝ≥0∞ := s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x /-- Check that indeed any uniform random variable has the uniformPDF. -/ lemma uniformPDF_eq_pdf {s : Set E} (hs : MeasurableSet s) (hu : pdf.IsUniform X s ℙ μ) : (fun x ↦ uniformPDF s x μ) =ᵐ[μ] pdf X ℙ μ := by unfold uniformPDF exact Filter.EventuallyEq.trans (pdf.IsUniform.pdf_eq hs hu).symm (ae_eq_refl _) open scoped Classical in /-- Alternative way of writing the uniformPDF. -/ lemma uniformPDF_ite {s : Set E} {x : E} : uniformPDF s x μ = if x ∈ s then (μ s)⁻¹ else 0 := by unfold uniformPDF unfold Set.indicator simp only [Pi.smul_apply, Pi.one_apply, smul_eq_mul, mul_one] end pdf end MeasureTheory namespace PMF variable {α : Type*} open scoped NNReal ENNReal section UniformOfFinset /-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/ def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by classical refine ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s ?_ ?_ · simp only [Finset.sum_ite_mem, Finset.inter_self, Finset.sum_const, nsmul_eq_mul] have : (s.card : ℝ≥0∞) ≠ 0 := by simpa only [Ne, Nat.cast_eq_zero, Finset.card_eq_zero] using Finset.nonempty_iff_ne_empty.1 hs exact ENNReal.mul_inv_cancel this <| ENNReal.natCast_ne_top s.card · exact fun x hx => by simp only [hx, if_false] variable {s : Finset α} (hs : s.Nonempty) {a : α} open scoped Classical in @[simp] theorem uniformOfFinset_apply (a : α) : uniformOfFinset s hs a = if a ∈ s then (s.card : ℝ≥0∞)⁻¹ else 0 := rfl theorem uniformOfFinset_apply_of_mem (ha : a ∈ s) : uniformOfFinset s hs a = (s.card : ℝ≥0∞)⁻¹ := by simp [ha] theorem uniformOfFinset_apply_of_not_mem (ha : a ∉ s) : uniformOfFinset s hs a = 0 := by simp [ha] @[simp] theorem support_uniformOfFinset : (uniformOfFinset s hs).support = s := Set.ext (by let ⟨a, ha⟩ := hs simp [mem_support_iff, Finset.ne_empty_of_mem ha]) theorem mem_support_uniformOfFinset_iff (a : α) : a ∈ (uniformOfFinset s hs).support ↔ a ∈ s := by simp section Measure variable (t : Set α) open scoped Classical in @[simp] theorem toOuterMeasure_uniformOfFinset_apply : (uniformOfFinset s hs).toOuterMeasure t = #{x ∈ s | x ∈ t} / #s := calc (uniformOfFinset s hs).toOuterMeasure t = ∑' x, if x ∈ t then uniformOfFinset s hs x else 0 := toOuterMeasure_apply (uniformOfFinset s hs) t _ = ∑' x, if x ∈ s ∧ x ∈ t then (#s : ℝ≥0∞)⁻¹ else 0 := tsum_congr fun x => by simp_rw [uniformOfFinset_apply, ← ite_and, and_comm] _ = ∑ x ∈ s with x ∈ t, if x ∈ s ∧ x ∈ t then (#s : ℝ≥0∞)⁻¹ else 0 := tsum_eq_sum fun _ hx => if_neg fun h => hx (Finset.mem_filter.2 h) _ = ∑ x ∈ s with x ∈ t, (#s : ℝ≥0∞)⁻¹ := Finset.sum_congr rfl fun x hx => by have this : x ∈ s ∧ x ∈ t := by simpa using hx simp only [this, and_self_iff, if_true] _ = #{x ∈ s | x ∈ t} / #s := by simp only [div_eq_mul_inv, Finset.sum_const, nsmul_eq_mul] open scoped Classical in @[simp] theorem toMeasure_uniformOfFinset_apply [MeasurableSpace α] (ht : MeasurableSet t) : (uniformOfFinset s hs).toMeasure t = #{x ∈ s | x ∈ t} / #s := (toMeasure_apply_eq_toOuterMeasure_apply _ t ht).trans (toOuterMeasure_uniformOfFinset_apply hs t) end Measure end UniformOfFinset section UniformOfFintype /-- The uniform pmf taking the same uniform value on all of the fintype `α` -/ def uniformOfFintype (α : Type*) [Fintype α] [Nonempty α] : PMF α := uniformOfFinset Finset.univ Finset.univ_nonempty variable [Fintype α] [Nonempty α] @[simp] theorem uniformOfFintype_apply (a : α) : uniformOfFintype α a = (Fintype.card α : ℝ≥0∞)⁻¹ := by simp [uniformOfFintype, Finset.mem_univ, if_true, uniformOfFinset_apply] @[simp] theorem support_uniformOfFintype (α : Type*) [Fintype α] [Nonempty α] : (uniformOfFintype α).support = ⊤ := Set.ext fun x => by simp [mem_support_iff] theorem mem_support_uniformOfFintype (a : α) : a ∈ (uniformOfFintype α).support := by simp section Measure variable (s : Set α)
Mathlib/Probability/Distributions/Uniform.lean
305
306
theorem toOuterMeasure_uniformOfFintype_apply [Fintype s] : (uniformOfFintype α).toOuterMeasure s = Fintype.card s / Fintype.card α := by
/- Copyright (c) 2020 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.GroupTheory.Complement /-! # Semidirect product This file defines semidirect products of groups, and the canonical maps in and out of the semidirect product. The semidirect product of `N` and `G` given a hom `φ` from `G` to the automorphism group of `N` is the product of sets with the group `⟨n₁, g₁⟩ * ⟨n₂, g₂⟩ = ⟨n₁ * φ g₁ n₂, g₁ * g₂⟩` ## Key definitions There are two homs into the semidirect product `inl : N →* N ⋊[φ] G` and `inr : G →* N ⋊[φ] G`, and `lift` can be used to define maps `N ⋊[φ] G →* H` out of the semidirect product given maps `fn : N →* H` and `fg : G →* H` that satisfy the condition `∀ n g, fn (φ g n) = fg g * fn n * fg g⁻¹` ## Notation This file introduces the global notation `N ⋊[φ] G` for `SemidirectProduct N G φ` ## Tags group, semidirect product -/ open Subgroup variable (N : Type*) (G : Type*) {H : Type*} [Group N] [Group G] [Group H] -- Don't generate sizeOf and injectivity lemmas, which the `simpNF` linter will complain about. set_option genSizeOfSpec false in set_option genInjectivity false in /-- The semidirect product of groups `N` and `G`, given a map `φ` from `G` to the automorphism group of `N`. It the product of sets with the group operation `⟨n₁, g₁⟩ * ⟨n₂, g₂⟩ = ⟨n₁ * φ g₁ n₂, g₁ * g₂⟩` -/ @[ext] structure SemidirectProduct (φ : G →* MulAut N) where /-- The element of N -/ left : N /-- The element of G -/ right : G deriving DecidableEq -- Porting note: unknown attribute -- attribute [pp_using_anonymous_constructor] SemidirectProduct @[inherit_doc] notation:35 N " ⋊[" φ:35 "] " G:35 => SemidirectProduct N G φ namespace SemidirectProduct variable {N G} variable {φ : G →* MulAut N} instance : Mul (SemidirectProduct N G φ) where mul a b := ⟨a.1 * φ a.2 b.1, a.2 * b.2⟩ lemma mul_def (a b : SemidirectProduct N G φ) : a * b = ⟨a.1 * φ a.2 b.1, a.2 * b.2⟩ := rfl @[simp] theorem mul_left (a b : N ⋊[φ] G) : (a * b).left = a.left * φ a.right b.left := rfl @[simp] theorem mul_right (a b : N ⋊[φ] G) : (a * b).right = a.right * b.right := rfl instance : One (SemidirectProduct N G φ) where one := ⟨1, 1⟩ @[simp] theorem one_left : (1 : N ⋊[φ] G).left = 1 := rfl @[simp] theorem one_right : (1 : N ⋊[φ] G).right = 1 := rfl instance : Inv (SemidirectProduct N G φ) where inv x := ⟨φ x.2⁻¹ x.1⁻¹, x.2⁻¹⟩ @[simp] theorem inv_left (a : N ⋊[φ] G) : a⁻¹.left = φ a.right⁻¹ a.left⁻¹ := rfl @[simp] theorem inv_right (a : N ⋊[φ] G) : a⁻¹.right = a.right⁻¹ := rfl instance : Group (N ⋊[φ] G) where mul_assoc a b c := SemidirectProduct.ext (by simp [mul_assoc]) (by simp [mul_assoc]) one_mul a := SemidirectProduct.ext (by simp) (one_mul a.2) mul_one a := SemidirectProduct.ext (by simp) (mul_one _) inv_mul_cancel a := SemidirectProduct.ext (by simp) (by simp) instance : Inhabited (N ⋊[φ] G) := ⟨1⟩ /-- The canonical map `N →* N ⋊[φ] G` sending `n` to `⟨n, 1⟩` -/ def inl : N →* N ⋊[φ] G where toFun n := ⟨n, 1⟩ map_one' := rfl map_mul' := by intros; ext <;> simp only [mul_left, map_one, MulAut.one_apply, mul_right, mul_one] @[simp] theorem left_inl (n : N) : (inl n : N ⋊[φ] G).left = n := rfl @[simp] theorem right_inl (n : N) : (inl n : N ⋊[φ] G).right = 1 := rfl theorem inl_injective : Function.Injective (inl : N → N ⋊[φ] G) := Function.injective_iff_hasLeftInverse.2 ⟨left, left_inl⟩ @[simp] theorem inl_inj {n₁ n₂ : N} : (inl n₁ : N ⋊[φ] G) = inl n₂ ↔ n₁ = n₂ := inl_injective.eq_iff /-- The canonical map `G →* N ⋊[φ] G` sending `g` to `⟨1, g⟩` -/ def inr : G →* N ⋊[φ] G where toFun g := ⟨1, g⟩ map_one' := rfl map_mul' := by intros; ext <;> simp @[simp] theorem left_inr (g : G) : (inr g : N ⋊[φ] G).left = 1 := rfl @[simp] theorem right_inr (g : G) : (inr g : N ⋊[φ] G).right = g := rfl theorem inr_injective : Function.Injective (inr : G → N ⋊[φ] G) := Function.injective_iff_hasLeftInverse.2 ⟨right, right_inr⟩ @[simp] theorem inr_inj {g₁ g₂ : G} : (inr g₁ : N ⋊[φ] G) = inr g₂ ↔ g₁ = g₂ := inr_injective.eq_iff theorem inl_aut (g : G) (n : N) : (inl (φ g n) : N ⋊[φ] G) = inr g * inl n * inr g⁻¹ := by ext <;> simp theorem inl_aut_inv (g : G) (n : N) : (inl ((φ g)⁻¹ n) : N ⋊[φ] G) = inr g⁻¹ * inl n * inr g := by rw [← MonoidHom.map_inv, inl_aut, inv_inv] @[simp] theorem mk_eq_inl_mul_inr (g : G) (n : N) : (⟨n, g⟩ : N ⋊[φ] G) = inl n * inr g := by ext <;> simp @[simp] theorem inl_left_mul_inr_right (x : N ⋊[φ] G) : inl x.left * inr x.right = x := by ext <;> simp /-- The canonical projection map `N ⋊[φ] G →* G`, as a group hom. -/ def rightHom : N ⋊[φ] G →* G where toFun := SemidirectProduct.right map_one' := rfl map_mul' _ _ := rfl @[simp] theorem rightHom_eq_right : (rightHom : N ⋊[φ] G → G) = right := rfl @[simp] theorem rightHom_comp_inl : (rightHom : N ⋊[φ] G →* G).comp inl = 1 := by ext; simp [rightHom] @[simp] theorem rightHom_comp_inr : (rightHom : N ⋊[φ] G →* G).comp inr = MonoidHom.id _ := by ext; simp [rightHom] @[simp] theorem rightHom_inl (n : N) : rightHom (inl n : N ⋊[φ] G) = 1 := by simp [rightHom] @[simp] theorem rightHom_inr (g : G) : rightHom (inr g : N ⋊[φ] G) = g := by simp [rightHom] theorem rightHom_surjective : Function.Surjective (rightHom : N ⋊[φ] G → G) := Function.surjective_iff_hasRightInverse.2 ⟨inr, rightHom_inr⟩ theorem range_inl_eq_ker_rightHom : (inl : N →* N ⋊[φ] G).range = rightHom.ker := le_antisymm (fun _ ↦ by simp +contextual [MonoidHom.mem_ker, eq_comm]) fun x hx ↦ ⟨x.left, by ext <;> simp_all [MonoidHom.mem_ker]⟩ /-- The bijection between the semidirect product and the product. -/ @[simps] def equivProd : N ⋊[φ] G ≃ N × G where toFun x := ⟨x.1, x.2⟩ invFun x := ⟨x.1, x.2⟩ left_inv _ := rfl right_inv _ := rfl /-- The group isomorphism between a semidirect product with respect to the trivial map and the product. -/ @[simps (config := { rhsMd := .default })] def mulEquivProd : N ⋊[1] G ≃* N × G := { equivProd with map_mul' _ _ := rfl } section lift variable (fn : N →* H) (fg : G →* H) (h : ∀ g, fn.comp (φ g).toMonoidHom = (MulAut.conj (fg g)).toMonoidHom.comp fn) /-- Define a group hom `N ⋊[φ] G →* H`, by defining maps `N →* H` and `G →* H` -/ def lift : N ⋊[φ] G →* H where toFun a := fn a.1 * fg a.2 map_one' := by simp map_mul' a b := by have := fun n g ↦ DFunLike.ext_iff.1 (h n) g simp only [MulAut.conj_apply, MonoidHom.comp_apply, MulEquiv.coe_toMonoidHom] at this simp only [mul_left, mul_right, map_mul, this, mul_assoc, inv_mul_cancel_left] @[simp]
Mathlib/GroupTheory/SemidirectProduct.lean
205
207
theorem lift_inl (n : N) : lift fn fg h (inl n) = fn n := by
simp [lift] @[simp]
/- Copyright (c) 2020 Paul van Wamelen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul van Wamelen -/ import Mathlib.Data.Int.NatPrime import Mathlib.Data.ZMod.Basic import Mathlib.RingTheory.Int.Basic import Mathlib.Tactic.FieldSimp /-! # Pythagorean Triples The main result is the classification of Pythagorean triples. The final result is for general Pythagorean triples. It follows from the more interesting relatively prime case. We use the "rational parametrization of the circle" method for the proof. The parametrization maps the point `(x / z, y / z)` to the slope of the line through `(-1 , 0)` and `(x / z, y / z)`. This quickly shows that `(x / z, y / z) = (2 * m * n / (m ^ 2 + n ^ 2), (m ^ 2 - n ^ 2) / (m ^ 2 + n ^ 2))` where `m / n` is the slope. In order to identify numerators and denominators we now need results showing that these are coprime. This is easy except for the prime 2. In order to deal with that we have to analyze the parity of `x`, `y`, `m` and `n` and eliminate all the impossible cases. This takes up the bulk of the proof below. -/ assert_not_exists TwoSidedIdeal theorem sq_ne_two_fin_zmod_four (z : ZMod 4) : z * z ≠ 2 := by change Fin 4 at z fin_cases z <;> decide theorem Int.sq_ne_two_mod_four (z : ℤ) : z * z % 4 ≠ 2 := by suffices ¬z * z % (4 : ℕ) = 2 % (4 : ℕ) by exact this rw [← ZMod.intCast_eq_intCast_iff'] simpa using sq_ne_two_fin_zmod_four _ noncomputable section /-- Three integers `x`, `y`, and `z` form a Pythagorean triple if `x * x + y * y = z * z`. -/ def PythagoreanTriple (x y z : ℤ) : Prop := x * x + y * y = z * z /-- Pythagorean triples are interchangeable, i.e `x * x + y * y = y * y + x * x = z * z`. This comes from additive commutativity. -/ theorem pythagoreanTriple_comm {x y z : ℤ} : PythagoreanTriple x y z ↔ PythagoreanTriple y x z := by delta PythagoreanTriple rw [add_comm] /-- The zeroth Pythagorean triple is all zeros. -/ theorem PythagoreanTriple.zero : PythagoreanTriple 0 0 0 := by simp only [PythagoreanTriple, zero_mul, zero_add] namespace PythagoreanTriple variable {x y z : ℤ} theorem eq (h : PythagoreanTriple x y z) : x * x + y * y = z * z := h @[symm] theorem symm (h : PythagoreanTriple x y z) : PythagoreanTriple y x z := by rwa [pythagoreanTriple_comm] /-- A triple is still a triple if you multiply `x`, `y` and `z` by a constant `k`. -/ theorem mul (h : PythagoreanTriple x y z) (k : ℤ) : PythagoreanTriple (k * x) (k * y) (k * z) := calc k * x * (k * x) + k * y * (k * y) = k ^ 2 * (x * x + y * y) := by ring _ = k ^ 2 * (z * z) := by rw [h.eq] _ = k * z * (k * z) := by ring /-- `(k*x, k*y, k*z)` is a Pythagorean triple if and only if `(x, y, z)` is also a triple. -/ theorem mul_iff (k : ℤ) (hk : k ≠ 0) : PythagoreanTriple (k * x) (k * y) (k * z) ↔ PythagoreanTriple x y z := by refine ⟨?_, fun h => h.mul k⟩ simp only [PythagoreanTriple] intro h rw [← mul_left_inj' (mul_ne_zero hk hk)] convert h using 1 <;> ring /-- A Pythagorean triple `x, y, z` is “classified” if there exist integers `k, m, n` such that either * `x = k * (m ^ 2 - n ^ 2)` and `y = k * (2 * m * n)`, or * `x = k * (2 * m * n)` and `y = k * (m ^ 2 - n ^ 2)`. -/ @[nolint unusedArguments] def IsClassified (_ : PythagoreanTriple x y z) := ∃ k m n : ℤ, (x = k * (m ^ 2 - n ^ 2) ∧ y = k * (2 * m * n) ∨ x = k * (2 * m * n) ∧ y = k * (m ^ 2 - n ^ 2)) ∧ Int.gcd m n = 1 /-- A primitive Pythagorean triple `x, y, z` is a Pythagorean triple with `x` and `y` coprime. Such a triple is “primitively classified” if there exist coprime integers `m, n` such that either * `x = m ^ 2 - n ^ 2` and `y = 2 * m * n`, or * `x = 2 * m * n` and `y = m ^ 2 - n ^ 2`. -/ @[nolint unusedArguments] def IsPrimitiveClassified (_ : PythagoreanTriple x y z) := ∃ m n : ℤ, (x = m ^ 2 - n ^ 2 ∧ y = 2 * m * n ∨ x = 2 * m * n ∧ y = m ^ 2 - n ^ 2) ∧ Int.gcd m n = 1 ∧ (m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) variable (h : PythagoreanTriple x y z) include h theorem mul_isClassified (k : ℤ) (hc : h.IsClassified) : (h.mul k).IsClassified := by obtain ⟨l, m, n, ⟨⟨rfl, rfl⟩ | ⟨rfl, rfl⟩, co⟩⟩ := hc · use k * l, m, n apply And.intro _ co left constructor <;> ring · use k * l, m, n apply And.intro _ co right constructor <;> ring theorem even_odd_of_coprime (hc : Int.gcd x y = 1) : x % 2 = 0 ∧ y % 2 = 1 ∨ x % 2 = 1 ∧ y % 2 = 0 := by rcases Int.emod_two_eq_zero_or_one x with hx | hx <;> rcases Int.emod_two_eq_zero_or_one y with hy | hy -- x even, y even · exfalso apply Nat.not_coprime_of_dvd_of_dvd (by decide : 1 < 2) _ _ hc · apply Int.natCast_dvd.1 apply Int.dvd_of_emod_eq_zero hx · apply Int.natCast_dvd.1 apply Int.dvd_of_emod_eq_zero hy -- x even, y odd · left exact ⟨hx, hy⟩ -- x odd, y even · right exact ⟨hx, hy⟩ -- x odd, y odd · exfalso obtain ⟨x0, y0, rfl, rfl⟩ : ∃ x0 y0, x = x0 * 2 + 1 ∧ y = y0 * 2 + 1 := by obtain ⟨x0, hx2⟩ := exists_eq_mul_left_of_dvd (Int.dvd_self_sub_of_emod_eq hx) obtain ⟨y0, hy2⟩ := exists_eq_mul_left_of_dvd (Int.dvd_self_sub_of_emod_eq hy) rw [sub_eq_iff_eq_add] at hx2 hy2 exact ⟨x0, y0, hx2, hy2⟩ apply Int.sq_ne_two_mod_four z rw [show z * z = 4 * (x0 * x0 + x0 + y0 * y0 + y0) + 2 by rw [← h.eq] ring] simp only [Int.add_emod, Int.mul_emod_right, zero_add] decide theorem gcd_dvd : (Int.gcd x y : ℤ) ∣ z := by by_cases h0 : Int.gcd x y = 0 · have hx : x = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_left h0 have hy : y = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_right h0 have hz : z = 0 := by simpa only [PythagoreanTriple, hx, hy, add_zero, zero_eq_mul, mul_zero, or_self_iff] using h simp only [hz, dvd_zero] obtain ⟨k, x0, y0, _, h2, rfl, rfl⟩ : ∃ (k : ℕ) (x0 y0 : _), 0 < k ∧ Int.gcd x0 y0 = 1 ∧ x = x0 * k ∧ y = y0 * k := Int.exists_gcd_one' (Nat.pos_of_ne_zero h0) rw [Int.gcd_mul_right, h2, Int.natAbs_natCast, one_mul] rw [← Int.pow_dvd_pow_iff two_ne_zero, sq z, ← h.eq] rw [(by ring : x0 * k * (x0 * k) + y0 * k * (y0 * k) = (k : ℤ) ^ 2 * (x0 * x0 + y0 * y0))] exact dvd_mul_right _ _ theorem normalize : PythagoreanTriple (x / Int.gcd x y) (y / Int.gcd x y) (z / Int.gcd x y) := by by_cases h0 : Int.gcd x y = 0 · have hx : x = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_left h0 have hy : y = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_right h0 have hz : z = 0 := by simpa only [PythagoreanTriple, hx, hy, add_zero, zero_eq_mul, mul_zero, or_self_iff] using h simp only [hx, hy, hz] exact zero rcases h.gcd_dvd with ⟨z0, rfl⟩ obtain ⟨k, x0, y0, k0, h2, rfl, rfl⟩ : ∃ (k : ℕ) (x0 y0 : _), 0 < k ∧ Int.gcd x0 y0 = 1 ∧ x = x0 * k ∧ y = y0 * k := Int.exists_gcd_one' (Nat.pos_of_ne_zero h0) have hk : (k : ℤ) ≠ 0 := by norm_cast rwa [pos_iff_ne_zero] at k0 rw [Int.gcd_mul_right, h2, Int.natAbs_natCast, one_mul] at h ⊢ rw [mul_comm x0, mul_comm y0, mul_iff k hk] at h rwa [Int.mul_ediv_cancel _ hk, Int.mul_ediv_cancel _ hk, Int.mul_ediv_cancel_left _ hk] theorem isClassified_of_isPrimitiveClassified (hp : h.IsPrimitiveClassified) : h.IsClassified := by obtain ⟨m, n, H⟩ := hp use 1, m, n omega theorem isClassified_of_normalize_isPrimitiveClassified (hc : h.normalize.IsPrimitiveClassified) : h.IsClassified := by convert h.normalize.mul_isClassified (Int.gcd x y) (isClassified_of_isPrimitiveClassified h.normalize hc) <;> rw [Int.mul_ediv_cancel'] · exact Int.gcd_dvd_left · exact Int.gcd_dvd_right · exact h.gcd_dvd theorem ne_zero_of_coprime (hc : Int.gcd x y = 1) : z ≠ 0 := by suffices 0 < z * z by rintro rfl norm_num at this rw [← h.eq, ← sq, ← sq] have hc' : Int.gcd x y ≠ 0 := by rw [hc] exact one_ne_zero rcases Int.ne_zero_of_gcd hc' with hxz | hyz · apply lt_add_of_pos_of_le (sq_pos_of_ne_zero hxz) (sq_nonneg y) · apply lt_add_of_le_of_pos (sq_nonneg x) (sq_pos_of_ne_zero hyz)
Mathlib/NumberTheory/PythagoreanTriples.lean
218
225
theorem isPrimitiveClassified_of_coprime_of_zero_left (hc : Int.gcd x y = 1) (hx : x = 0) : h.IsPrimitiveClassified := by
subst x change Nat.gcd 0 (Int.natAbs y) = 1 at hc rw [Nat.gcd_zero_left (Int.natAbs y)] at hc rcases Int.natAbs_eq y with hy | hy · use 1, 0 rw [hy, hc, Int.gcd_zero_right]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes, angles modulo `π` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `π` can be represented modulo `2 * π` as equalities of `(2 : ℤ) • θ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open Module Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "ω" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) /-- Oriented angles are continuous when the vectors involved are nonzero. -/ @[fun_prop] theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ · exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] /-- If the second vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle] /-- If the two vectors passed to `oangle` are the same, the result is 0. -/ @[simp] theorem oangle_self (x : V) : o.oangle x x = 0 := by rw [oangle, kahler_apply_self, ← ofReal_pow] convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π)) apply arg_ofReal_of_nonneg positivity /-- If the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by rintro rfl; simp at h /-- If the angle between two vectors is `π`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y := o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- Swapping the two vectors passed to `oangle` negates the angle. -/ theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle] /-- Adding the angles between two vectors in each order results in 0. -/ @[simp] theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by simp [o.oangle_rev y x] /-- Negating the first vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle (-x) y = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the second vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x (-y) = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the first vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_left (x y : V) : (2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_left hx hy] /-- Negating the second vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_right (x y : V) : (2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_right hx hy] /-- Negating both vectors passed to `oangle` does not change the angle. -/ @[simp] theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle] /-- Negating the first vector produces the same angle as negating the second vector. -/ theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by rw [← neg_neg y, oangle_neg_neg, neg_neg] /-- The angle between the negation of a nonzero vector and that vector is `π`. -/ @[simp] theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by simp [oangle_neg_left, hx] /-- The angle between a nonzero vector and its negation is `π`. -/ @[simp] theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by simp [oangle_neg_right, hx] /-- Twice the angle between the negation of a vector and that vector is 0. -/ theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Twice the angle between a vector and its negation is 0. -/ theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Adding the angles between two vectors in each order, with the first vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel] /-- Adding the angles between two vectors in each order, with the second vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_cancel] /-- Multiplying the first vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle (r • x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the second vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle x (r • y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle (r • x) y = o.oangle (-x) y := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)] /-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle x (r • y) = o.oangle x (-y) := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)] /-- The angle between a nonnegative multiple of a vector and that vector is 0. -/ @[simp] theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle (r • x) x = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] /-- The angle between a vector and a nonnegative multiple of that vector is 0. -/ @[simp] theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle x (r • x) = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] /-- The angle between two nonnegative multiples of the same vector is 0. -/ @[simp] theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ r₂ : ℝ} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) : o.oangle (r₁ • x) (r₂ • x) = 0 := by rcases hr₁.lt_or_eq with (h | h) · simp [h, hr₂] · simp [h.symm] /-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle (r • x) y = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] /-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle x (r • y) = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] /-- Twice the angle between a multiple of a vector and that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_left_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle (r • x) x = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] /-- Twice the angle between a vector and a multiple of that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_right_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle x (r • x) = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] /-- Twice the angle between two multiples of a vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_smul_self (x : V) {r₁ r₂ : ℝ} : (2 : ℤ) • o.oangle (r₁ • x) (r₂ • x) = 0 := by by_cases h : r₁ = 0 <;> simp [h] /-- If the spans of two vectors are equal, twice angles with those vectors on the left are equal. -/ theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (ℝ ∙ x) = ℝ ∙ y) : (2 : ℤ) • o.oangle x z = (2 : ℤ) • o.oangle y z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm /-- If the spans of two vectors are equal, twice angles with those vectors on the right are equal. -/ theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle x y = (2 : ℤ) • o.oangle x z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm /-- If the spans of two pairs of vectors are equal, twice angles between those vectors are equal. -/ theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (ℝ ∙ w) = ℝ ∙ x) (hyz : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle w y = (2 : ℤ) • o.oangle x z := by rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz] /-- The oriented angle between two vectors is zero if and only if the angle with the vectors swapped is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 ↔ o.oangle y x = 0 := by rw [oangle_rev, neg_eq_zero] /-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/ theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 ↔ SameRay ℝ x y := by rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero, Complex.arg_eq_zero_iff] simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y /-- The oriented angle between two vectors is `π` if and only if the angle with the vectors swapped is `π`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = π ↔ o.oangle y x = π := by rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi] /-- The oriented angle between two vectors is `π` if and only they are nonzero and the first is on the same ray as the negation of the second. -/ theorem oangle_eq_pi_iff_sameRay_neg {x y : V} : o.oangle x y = π ↔ x ≠ 0 ∧ y ≠ 0 ∧ SameRay ℝ x (-y) := by rw [← o.oangle_eq_zero_iff_sameRay] constructor · intro h by_cases hx : x = 0; · simp [hx, Real.Angle.pi_ne_zero.symm] at h by_cases hy : y = 0; · simp [hy, Real.Angle.pi_ne_zero.symm] at h refine ⟨hx, hy, ?_⟩ rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi] · rintro ⟨hx, hy, h⟩ rwa [o.oangle_neg_right hx hy, ← Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h /-- The oriented angle between two vectors is zero or `π` if and only if those two vectors are not linearly independent. -/ theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ ¬LinearIndependent ℝ ![x, y] := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg, sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent] /-- The oriented angle between two vectors is zero or `π` if and only if the first vector is zero or the second is a multiple of the first. -/ theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ x = 0 ∨ ∃ r : ℝ, y = r • x := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with (h | ⟨-, -, h⟩) · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, rfl⟩ := h.exists_nonneg_left hx exact Or.inr ⟨r, rfl⟩ · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, hy⟩ := h.exists_nonneg_left hx refine Or.inr ⟨-r, ?_⟩ simp [hy] · rcases h with (rfl | ⟨r, rfl⟩); · simp by_cases hx : x = 0; · simp [hx] rcases lt_trichotomy r 0 with (hr | hr | hr) · rw [← neg_smul] exact Or.inr ⟨hx, smul_ne_zero hr.ne hx, SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)⟩ · simp [hr] · exact Or.inl (SameRay.sameRay_pos_smul_right x hr) /-- The oriented angle between two vectors is not zero or `π` if and only if those two vectors are linearly independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} : o.oangle x y ≠ 0 ∧ o.oangle x y ≠ π ↔ LinearIndependent ℝ ![x, y] := by rw [← not_or, ← not_iff_not, Classical.not_not, oangle_eq_zero_or_eq_pi_iff_not_linearIndependent] /-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/ theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y ↔ ‖x‖ = ‖y‖ ∧ o.oangle x y = 0 := by rw [oangle_eq_zero_iff_sameRay] constructor · rintro rfl simp; rfl · rcases eq_or_ne y 0 with (rfl | hy) · simp rintro ⟨h₁, h₂⟩ obtain ⟨r, hr, rfl⟩ := h₂.exists_nonneg_right hy have : ‖y‖ ≠ 0 := by simpa using hy obtain rfl : r = 1 := by apply mul_right_cancel₀ this simpa [norm_smul, abs_of_nonneg hr] using h₁ simp /-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/ theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : x = y ↔ o.oangle x y = 0 := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨h, ha⟩⟩ /-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/ theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y ↔ ‖x‖ = ‖y‖ := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨hn, h⟩⟩ /-- Given three nonzero vectors, the angle between the first and the second plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z = o.oangle x z := by simp_rw [oangle] rw [← Complex.arg_mul_coe_angle, o.kahler_mul y x z] · congr 1 exact mod_cast Complex.arg_real_mul _ (by positivity : 0 < ‖y‖ ^ 2) · exact o.kahler_ne_zero hx hy · exact o.kahler_ne_zero hy hz /-- Given three nonzero vectors, the angle between the second and the third plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz] /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle x y = o.oangle y z := by rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz] /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz] /-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/ @[simp]
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
471
474
theorem oangle_add_cyc3 {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z + o.oangle z x = 0 := by
simp [hx, hy, hz] /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first
/- Copyright (c) 2021 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Algebra.Spectrum.Basic import Mathlib.FieldTheory.IsAlgClosed.Basic /-! # Spectrum mapping theorem This file develops proves the spectral mapping theorem for polynomials over algebraically closed fields. In particular, if `a` is an element of a `𝕜`-algebra `A` where `𝕜` is a field, and `p : 𝕜[X]` is a polynomial, then the spectrum of `Polynomial.aeval a p` contains the image of the spectrum of `a` under `(fun k ↦ Polynomial.eval k p)`. When `𝕜` is algebraically closed, these are in fact equal (assuming either that the spectrum of `a` is nonempty or the polynomial has positive degree), which is the **spectral mapping theorem**. In addition, this file contains the fact that every element of a finite dimensional nontrivial algebra over an algebraically closed field has nonempty spectrum. In particular, this is used in `Module.End.exists_eigenvalue` to show that every linear map from a vector space to itself has an eigenvalue. ## Main statements * `spectrum.subset_polynomial_aeval`, `spectrum.map_polynomial_aeval_of_degree_pos`, `spectrum.map_polynomial_aeval_of_nonempty`: variations on the **spectral mapping theorem**. * `spectrum.nonempty_of_isAlgClosed_of_finiteDimensional`: the spectrum is nonempty for any element of a nontrivial finite dimensional algebra over an algebraically closed field. ## Notations * `σ a` : `spectrum R a` of `a : A` -/ namespace spectrum open Set Polynomial open scoped Pointwise Polynomial universe u v section ScalarRing variable {R : Type u} {A : Type v} variable [CommRing R] [Ring A] [Algebra R A] local notation "σ" => spectrum R local notation "↑ₐ" => algebraMap R A theorem exists_mem_of_not_isUnit_aeval_prod [IsDomain R] {p : R[X]} {a : A} (h : ¬IsUnit (aeval a (Multiset.map (fun x : R => X - C x) p.roots).prod)) : ∃ k : R, k ∈ σ a ∧ eval k p = 0 := by rw [← Multiset.prod_toList, map_list_prod] at h replace h := mt List.prod_isUnit h simp only [not_forall, exists_prop, aeval_C, Multiset.mem_toList, List.mem_map, aeval_X, exists_exists_and_eq_and, Multiset.mem_map, map_sub] at h rcases h with ⟨r, r_mem, r_nu⟩ exact ⟨r, by rwa [mem_iff, ← IsUnit.sub_iff], (mem_roots'.1 r_mem).2⟩ end ScalarRing section ScalarField variable {𝕜 : Type u} {A : Type v} variable [Field 𝕜] [Ring A] [Algebra 𝕜 A] local notation "σ" => spectrum 𝕜 local notation "↑ₐ" => algebraMap 𝕜 A open Polynomial /-- Half of the spectral mapping theorem for polynomials. We prove it separately because it holds over any field, whereas `spectrum.map_polynomial_aeval_of_degree_pos` and `spectrum.map_polynomial_aeval_of_nonempty` need the field to be algebraically closed. -/ theorem subset_polynomial_aeval (a : A) (p : 𝕜[X]) : (eval · p) '' σ a ⊆ σ (aeval a p) := by rintro _ ⟨k, hk, rfl⟩ let q := C (eval k p) - p have hroot : IsRoot q k := by simp only [q, eval_C, eval_sub, sub_self, IsRoot.def] rw [← mul_div_eq_iff_isRoot, ← neg_mul_neg, neg_sub] at hroot have aeval_q_eq : ↑ₐ (eval k p) - aeval a p = aeval a q := by simp only [q, aeval_C, map_sub, sub_left_inj] rw [mem_iff, aeval_q_eq, ← hroot, aeval_mul] have hcomm := (Commute.all (C k - X) (-(q / (X - C k)))).map (aeval a : 𝕜[X] →ₐ[𝕜] A) apply mt fun h => (hcomm.isUnit_mul_iff.mp h).1 simpa only [aeval_X, aeval_C, map_sub] using hk /-- The *spectral mapping theorem* for polynomials. Note: the assumption `degree p > 0` is necessary in case `σ a = ∅`, for then the left-hand side is `∅` and the right-hand side, assuming `[Nontrivial A]`, is `{k}` where `p = Polynomial.C k`. -/ theorem map_polynomial_aeval_of_degree_pos [IsAlgClosed 𝕜] (a : A) (p : 𝕜[X]) (hdeg : 0 < degree p) : σ (aeval a p) = (eval · p) '' σ a := by -- handle the easy direction via `spectrum.subset_polynomial_aeval` refine Set.eq_of_subset_of_subset (fun k hk => ?_) (subset_polynomial_aeval a p) -- write `C k - p` product of linear factors and a constant; show `C k - p ≠ 0`. have hprod := eq_prod_roots_of_splits_id (IsAlgClosed.splits (C k - p)) have h_ne : C k - p ≠ 0 := ne_zero_of_degree_gt <| by rwa [degree_sub_eq_right_of_degree_lt (lt_of_le_of_lt degree_C_le hdeg)] have lead_ne := leadingCoeff_ne_zero.mpr h_ne have lead_unit := (Units.map ↑ₐ.toMonoidHom (Units.mk0 _ lead_ne)).isUnit /- leading coefficient is a unit so product of linear factors is not a unit; apply `exists_mem_of_not_is_unit_aeval_prod`. -/ have p_a_eq : aeval a (C k - p) = ↑ₐ k - aeval a p := by simp only [aeval_C, map_sub, sub_left_inj] rw [mem_iff, ← p_a_eq, hprod, aeval_mul, ((Commute.all _ _).map (aeval a : 𝕜[X] →ₐ[𝕜] A)).isUnit_mul_iff, aeval_C] at hk replace hk := exists_mem_of_not_isUnit_aeval_prod (not_and.mp hk lead_unit) rcases hk with ⟨r, r_mem, r_ev⟩ exact ⟨r, r_mem, symm (by simpa [eval_sub, eval_C, sub_eq_zero] using r_ev)⟩ /-- In this version of the spectral mapping theorem, we assume the spectrum is nonempty instead of assuming the degree of the polynomial is positive. -/ theorem map_polynomial_aeval_of_nonempty [IsAlgClosed 𝕜] (a : A) (p : 𝕜[X]) (hnon : (σ a).Nonempty) : σ (aeval a p) = (fun k => eval k p) '' σ a := by nontriviality A refine Or.elim (le_or_gt (degree p) 0) (fun h => ?_) (map_polynomial_aeval_of_degree_pos a p) rw [eq_C_of_degree_le_zero h] simp only [Set.image_congr, eval_C, aeval_C, scalar_eq, Set.Nonempty.image_const hnon] /-- A specialization of `spectrum.subset_polynomial_aeval` to monic monomials for convenience. -/ theorem pow_image_subset (a : A) (n : ℕ) : (fun x => x ^ n) '' σ a ⊆ σ (a ^ n) := by simpa only [eval_pow, eval_X, aeval_X_pow] using subset_polynomial_aeval a (X ^ n : 𝕜[X]) /-- A specialization of `spectrum.map_polynomial_aeval_of_nonempty` to monic monomials for convenience. -/ theorem map_pow_of_pos [IsAlgClosed 𝕜] (a : A) {n : ℕ} (hn : 0 < n) : σ (a ^ n) = (· ^ n) '' σ a := by simpa only [aeval_X_pow, eval_pow, eval_X] using map_polynomial_aeval_of_degree_pos a (X ^ n : 𝕜[X]) (by rwa [degree_X_pow, Nat.cast_pos]) /-- A specialization of `spectrum.map_polynomial_aeval_of_nonempty` to monic monomials for convenience. -/ theorem map_pow_of_nonempty [IsAlgClosed 𝕜] {a : A} (ha : (σ a).Nonempty) (n : ℕ) : σ (a ^ n) = (· ^ n) '' σ a := by simpa only [aeval_X_pow, eval_pow, eval_X] using map_polynomial_aeval_of_nonempty a (X ^ n) ha variable (𝕜) -- We will use this both to show eigenvalues exist, and to prove Schur's lemma. /-- Every element `a` in a nontrivial finite-dimensional algebra `A` over an algebraically closed field `𝕜` has non-empty spectrum. -/
Mathlib/FieldTheory/IsAlgClosed/Spectrum.lean
143
145
theorem nonempty_of_isAlgClosed_of_finiteDimensional [IsAlgClosed 𝕜] [Nontrivial A] [I : FiniteDimensional 𝕜 A] (a : A) : (σ a).Nonempty := by
obtain ⟨p, ⟨h_mon, h_eval_p⟩⟩ := isIntegral_of_noetherian (IsNoetherian.iff_fg.2 I) a
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Peter Pfaffelhuber, Yaël Dillies, Kin Yau James Wong -/ import Mathlib.MeasureTheory.MeasurableSpace.Constructions import Mathlib.MeasureTheory.PiSystem import Mathlib.Topology.Constructions /-! # π-systems of cylinders and square cylinders The instance `MeasurableSpace.pi` on `∀ i, α i`, where each `α i` has a `MeasurableSpace` `m i`, is defined as `⨆ i, (m i).comap (fun a => a i)`. That is, a function `g : β → ∀ i, α i` is measurable iff for all `i`, the function `b ↦ g b i` is measurable. We define two π-systems generating `MeasurableSpace.pi`, cylinders and square cylinders. ## Main definitions Given a finite set `s` of indices, a cylinder is the product of a set of `∀ i : s, α i` and of `univ` on the other indices. A square cylinder is a cylinder for which the set on `∀ i : s, α i` is a product set. * `cylinder s S`: cylinder with base set `S : Set (∀ i : s, α i)` where `s` is a `Finset` * `squareCylinders C` with `C : ∀ i, Set (Set (α i))`: set of all square cylinders such that for all `i` in the finset defining the box, the projection to `α i` belongs to `C i`. The main application of this is with `C i = {s : Set (α i) | MeasurableSet s}`. * `measurableCylinders`: set of all cylinders with measurable base sets. * `cylinderEvents Δ`: The σ-algebra of cylinder events on `Δ`. It is the smallest σ-algebra making the projections on the `i`-th coordinate continuous for all `i ∈ Δ`. ## Main statements * `generateFrom_squareCylinders`: square cylinders formed from measurable sets generate the product σ-algebra * `generateFrom_measurableCylinders`: cylinders formed from measurable sets generate the product σ-algebra -/ open Function Set namespace MeasureTheory variable {ι : Type _} {α : ι → Type _} section squareCylinders /-- Given a finite set `s` of indices, a square cylinder is the product of a set `S` of `∀ i : s, α i` and of `univ` on the other indices. The set `S` is a product of sets `t i` such that for all `i : s`, `t i ∈ C i`. `squareCylinders` is the set of all such squareCylinders. -/ def squareCylinders (C : ∀ i, Set (Set (α i))) : Set (Set (∀ i, α i)) := {S | ∃ s : Finset ι, ∃ t ∈ univ.pi C, S = (s : Set ι).pi t} theorem squareCylinders_eq_iUnion_image (C : ∀ i, Set (Set (α i))) : squareCylinders C = ⋃ s : Finset ι, (fun t ↦ (s : Set ι).pi t) '' univ.pi C := by ext1 f simp only [squareCylinders, mem_iUnion, mem_image, mem_univ_pi, exists_prop, mem_setOf_eq, eq_comm (a := f)] theorem isPiSystem_squareCylinders {C : ∀ i, Set (Set (α i))} (hC : ∀ i, IsPiSystem (C i)) (hC_univ : ∀ i, univ ∈ C i) : IsPiSystem (squareCylinders C) := by rintro S₁ ⟨s₁, t₁, h₁, rfl⟩ S₂ ⟨s₂, t₂, h₂, rfl⟩ hst_nonempty classical let t₁' := s₁.piecewise t₁ (fun i ↦ univ) let t₂' := s₂.piecewise t₂ (fun i ↦ univ) have h1 : ∀ i ∈ (s₁ : Set ι), t₁ i = t₁' i := fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm have h1' : ∀ i ∉ (s₁ : Set ι), t₁' i = univ := fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi have h2 : ∀ i ∈ (s₂ : Set ι), t₂ i = t₂' i := fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm have h2' : ∀ i ∉ (s₂ : Set ι), t₂' i = univ := fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, ← union_pi_inter h1' h2'] refine ⟨s₁ ∪ s₂, fun i ↦ t₁' i ∩ t₂' i, ?_, ?_⟩ · rw [mem_univ_pi] intro i have : (t₁' i ∩ t₂' i).Nonempty := by obtain ⟨f, hf⟩ := hst_nonempty rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, mem_inter_iff, mem_pi, mem_pi] at hf refine ⟨f i, ⟨?_, ?_⟩⟩ · by_cases hi₁ : i ∈ s₁ · exact hf.1 i hi₁ · rw [h1' i hi₁] exact mem_univ _ · by_cases hi₂ : i ∈ s₂ · exact hf.2 i hi₂ · rw [h2' i hi₂] exact mem_univ _ refine hC i _ ?_ _ ?_ this · by_cases hi₁ : i ∈ s₁ · rw [← h1 i hi₁] exact h₁ i (mem_univ _) · rw [h1' i hi₁] exact hC_univ i · by_cases hi₂ : i ∈ s₂ · rw [← h2 i hi₂] exact h₂ i (mem_univ _) · rw [h2' i hi₂] exact hC_univ i · rw [Finset.coe_union] theorem comap_eval_le_generateFrom_squareCylinders_singleton (α : ι → Type*) [m : ∀ i, MeasurableSpace (α i)] (i : ι) : MeasurableSpace.comap (Function.eval i) (m i) ≤ MeasurableSpace.generateFrom ((fun t ↦ ({i} : Set ι).pi t) '' univ.pi fun i ↦ {s : Set (α i) | MeasurableSet s}) := by simp only [Function.eval, singleton_pi] rw [MeasurableSpace.comap_eq_generateFrom] refine MeasurableSpace.generateFrom_mono fun S ↦ ?_ simp only [mem_setOf_eq, mem_image, mem_univ_pi, forall_exists_index, and_imp] intro t ht h classical refine ⟨fun j ↦ if hji : j = i then by convert t else univ, fun j ↦ ?_, ?_⟩ · by_cases hji : j = i · simp only [hji, eq_self_iff_true, eq_mpr_eq_cast, dif_pos] convert ht simp only [id_eq, cast_heq] · simp only [hji, not_false_iff, dif_neg, MeasurableSet.univ] · simp only [id_eq, eq_mpr_eq_cast, ← h] ext1 x simp only [singleton_pi, Function.eval, cast_eq, dite_eq_ite, ite_true, mem_preimage] /-- The square cylinders formed from measurable sets generate the product σ-algebra. -/ theorem generateFrom_squareCylinders [∀ i, MeasurableSpace (α i)] : MeasurableSpace.generateFrom (squareCylinders fun i ↦ {s : Set (α i) | MeasurableSet s}) = MeasurableSpace.pi := by apply le_antisymm · rw [MeasurableSpace.generateFrom_le_iff] rintro S ⟨s, t, h, rfl⟩ simp only [mem_univ_pi, mem_setOf_eq] at h exact MeasurableSet.pi (Finset.countable_toSet _) (fun i _ ↦ h i) · refine iSup_le fun i ↦ ?_ refine (comap_eval_le_generateFrom_squareCylinders_singleton α i).trans ?_ refine MeasurableSpace.generateFrom_mono ?_ rw [← Finset.coe_singleton, squareCylinders_eq_iUnion_image] exact subset_iUnion (fun (s : Finset ι) ↦ (fun t : ∀ i, Set (α i) ↦ (s : Set ι).pi t) '' univ.pi (fun i ↦ setOf MeasurableSet)) ({i} : Finset ι) end squareCylinders section cylinder /-- Given a finite set `s` of indices, a cylinder is the preimage of a set `S` of `∀ i : s, α i` by the projection from `∀ i, α i` to `∀ i : s, α i`. -/ def cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) : Set (∀ i, α i) := s.restrict ⁻¹' S @[simp] theorem mem_cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) (f : ∀ i, α i) : f ∈ cylinder s S ↔ s.restrict f ∈ S := mem_preimage @[simp] theorem cylinder_empty (s : Finset ι) : cylinder s (∅ : Set (∀ i : s, α i)) = ∅ := by rw [cylinder, preimage_empty] @[simp] theorem cylinder_univ (s : Finset ι) : cylinder s (univ : Set (∀ i : s, α i)) = univ := by rw [cylinder, preimage_univ] @[simp] theorem cylinder_eq_empty_iff [h_nonempty : Nonempty (∀ i, α i)] (s : Finset ι) (S : Set (∀ i : s, α i)) : cylinder s S = ∅ ↔ S = ∅ := by refine ⟨fun h ↦ ?_, fun h ↦ by (rw [h]; exact cylinder_empty _)⟩ by_contra hS rw [← Ne, ← nonempty_iff_ne_empty] at hS let f := hS.some have hf : f ∈ S := hS.choose_spec classical let f' : ∀ i, α i := fun i ↦ if hi : i ∈ s then f ⟨i, hi⟩ else h_nonempty.some i have hf' : f' ∈ cylinder s S := by rw [mem_cylinder] simpa only [Finset.restrict_def, Finset.coe_mem, dif_pos, f'] rw [h] at hf' exact not_mem_empty _ hf' theorem inter_cylinder (s₁ s₂ : Finset ι) (S₁ : Set (∀ i : s₁, α i)) (S₂ : Set (∀ i : s₂, α i)) [DecidableEq ι] : cylinder s₁ S₁ ∩ cylinder s₂ S₂ = cylinder (s₁ ∪ s₂) (Finset.restrict₂ Finset.subset_union_left ⁻¹' S₁ ∩ Finset.restrict₂ Finset.subset_union_right ⁻¹' S₂) := by ext1 f; simp only [mem_inter_iff, mem_cylinder, mem_setOf_eq]; rfl theorem inter_cylinder_same (s : Finset ι) (S₁ : Set (∀ i : s, α i)) (S₂ : Set (∀ i : s, α i)) : cylinder s S₁ ∩ cylinder s S₂ = cylinder s (S₁ ∩ S₂) := by classical rw [inter_cylinder]; rfl theorem union_cylinder (s₁ s₂ : Finset ι) (S₁ : Set (∀ i : s₁, α i)) (S₂ : Set (∀ i : s₂, α i)) [DecidableEq ι] : cylinder s₁ S₁ ∪ cylinder s₂ S₂ = cylinder (s₁ ∪ s₂) (Finset.restrict₂ Finset.subset_union_left ⁻¹' S₁ ∪ Finset.restrict₂ Finset.subset_union_right ⁻¹' S₂) := by ext1 f; simp only [mem_union, mem_cylinder, mem_setOf_eq]; rfl theorem union_cylinder_same (s : Finset ι) (S₁ : Set (∀ i : s, α i)) (S₂ : Set (∀ i : s, α i)) : cylinder s S₁ ∪ cylinder s S₂ = cylinder s (S₁ ∪ S₂) := by classical rw [union_cylinder]; rfl theorem compl_cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) : (cylinder s S)ᶜ = cylinder s (Sᶜ) := by ext1 f; simp only [mem_compl_iff, mem_cylinder] theorem diff_cylinder_same (s : Finset ι) (S T : Set (∀ i : s, α i)) : cylinder s S \ cylinder s T = cylinder s (S \ T) := by ext1 f; simp only [mem_diff, mem_cylinder] theorem eq_of_cylinder_eq_of_subset [h_nonempty : Nonempty (∀ i, α i)] {I J : Finset ι} {S : Set (∀ i : I, α i)} {T : Set (∀ i : J, α i)} (h_eq : cylinder I S = cylinder J T) (hJI : J ⊆ I) : S = Finset.restrict₂ hJI ⁻¹' T := by rw [Set.ext_iff] at h_eq simp only [mem_cylinder] at h_eq ext1 f simp only [mem_preimage] classical specialize h_eq fun i ↦ if hi : i ∈ I then f ⟨i, hi⟩ else h_nonempty.some i have h_mem : ∀ j : J, ↑j ∈ I := fun j ↦ hJI j.prop simpa only [Finset.restrict_def, Finset.coe_mem, dite_true, h_mem] using h_eq theorem cylinder_eq_cylinder_union [DecidableEq ι] (I : Finset ι) (S : Set (∀ i : I, α i)) (J : Finset ι) : cylinder I S = cylinder (I ∪ J) (Finset.restrict₂ Finset.subset_union_left ⁻¹' S) := by ext1 f; simp only [mem_cylinder, Finset.restrict_def, Finset.restrict₂_def, mem_preimage]
Mathlib/MeasureTheory/Constructions/Cylinders.lean
237
244
theorem disjoint_cylinder_iff [Nonempty (∀ i, α i)] {s t : Finset ι} {S : Set (∀ i : s, α i)} {T : Set (∀ i : t, α i)} [DecidableEq ι] : Disjoint (cylinder s S) (cylinder t T) ↔ Disjoint (Finset.restrict₂ Finset.subset_union_left ⁻¹' S) (Finset.restrict₂ Finset.subset_union_right ⁻¹' T) := by
simp_rw [Set.disjoint_iff, subset_empty_iff, inter_cylinder, cylinder_eq_empty_iff]
/- 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, Johan Commelin, Mario Carneiro -/ import Mathlib.Algebra.MonoidAlgebra.Degree import Mathlib.Algebra.MvPolynomial.Rename /-! # Degrees of polynomials This file establishes many results about the degree of a multivariate polynomial. The *degree set* of a polynomial $P \in R[X]$ is a `Multiset` containing, for each $x$ in the variable set, $n$ copies of $x$, where $n$ is the maximum number of copies of $x$ appearing in a monomial of $P$. ## Main declarations * `MvPolynomial.degrees p` : the multiset of variables representing the union of the multisets corresponding to each non-zero monomial in `p`. For example if `7 ≠ 0` in `R` and `p = x²y+7y³` then `degrees p = {x, x, y, y, y}` * `MvPolynomial.degreeOf n p : ℕ` : the total degree of `p` with respect to the variable `n`. For example if `p = x⁴y+yz` then `degreeOf y p = 1`. * `MvPolynomial.totalDegree p : ℕ` : the max of the sizes of the multisets `s` whose monomials `X^s` occur in `p`. For example if `p = x⁴y+yz` then `totalDegree p = 5`. ## Notation As in other polynomial files, we typically use the notation: + `σ τ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `r : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra universe u v w variable {R : Type u} {S : Type v} namespace MvPolynomial variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section CommSemiring variable [CommSemiring R] {p q : MvPolynomial σ R} section Degrees /-! ### `degrees` -/ /-- The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset. (For example, `degrees (x^2 * y + y^3)` would be `{x, x, y, y, y}`.) -/ def degrees (p : MvPolynomial σ R) : Multiset σ := letI := Classical.decEq σ p.support.sup fun s : σ →₀ ℕ => toMultiset s theorem degrees_def [DecidableEq σ] (p : MvPolynomial σ R) : p.degrees = p.support.sup fun s : σ →₀ ℕ => Finsupp.toMultiset s := by rw [degrees]; convert rfl theorem degrees_monomial (s : σ →₀ ℕ) (a : R) : degrees (monomial s a) ≤ toMultiset s := by classical refine (supDegree_single s a).trans_le ?_ split_ifs exacts [bot_le, le_rfl] theorem degrees_monomial_eq (s : σ →₀ ℕ) (a : R) (ha : a ≠ 0) : degrees (monomial s a) = toMultiset s := by classical exact (supDegree_single s a).trans (if_neg ha) theorem degrees_C (a : R) : degrees (C a : MvPolynomial σ R) = 0 := Multiset.le_zero.1 <| degrees_monomial _ _ theorem degrees_X' (n : σ) : degrees (X n : MvPolynomial σ R) ≤ {n} := le_trans (degrees_monomial _ _) <| le_of_eq <| toMultiset_single _ _ @[simp] theorem degrees_X [Nontrivial R] (n : σ) : degrees (X n : MvPolynomial σ R) = {n} := (degrees_monomial_eq _ (1 : R) one_ne_zero).trans (toMultiset_single _ _) @[simp] theorem degrees_zero : degrees (0 : MvPolynomial σ R) = 0 := by rw [← C_0] exact degrees_C 0 @[simp] theorem degrees_one : degrees (1 : MvPolynomial σ R) = 0 := degrees_C 1 theorem degrees_add_le [DecidableEq σ] {p q : MvPolynomial σ R} : (p + q).degrees ≤ p.degrees ⊔ q.degrees := by simp_rw [degrees_def]; exact supDegree_add_le theorem degrees_sum_le {ι : Type*} [DecidableEq σ] (s : Finset ι) (f : ι → MvPolynomial σ R) : (∑ i ∈ s, f i).degrees ≤ s.sup fun i => (f i).degrees := by simp_rw [degrees_def]; exact supDegree_sum_le theorem degrees_mul_le {p q : MvPolynomial σ R} : (p * q).degrees ≤ p.degrees + q.degrees := by classical simp_rw [degrees_def] exact supDegree_mul_le (map_add _) theorem degrees_prod_le {ι : Type*} {s : Finset ι} {f : ι → MvPolynomial σ R} : (∏ i ∈ s, f i).degrees ≤ ∑ i ∈ s, (f i).degrees := by classical exact supDegree_prod_le (map_zero _) (map_add _) theorem degrees_pow_le {p : MvPolynomial σ R} {n : ℕ} : (p ^ n).degrees ≤ n • p.degrees := by simpa using degrees_prod_le (s := .range n) (f := fun _ ↦ p) @[deprecated (since := "2024-12-28")] alias degrees_add := degrees_add_le @[deprecated (since := "2024-12-28")] alias degrees_sum := degrees_sum_le @[deprecated (since := "2024-12-28")] alias degrees_mul := degrees_mul_le @[deprecated (since := "2024-12-28")] alias degrees_prod := degrees_prod_le @[deprecated (since := "2024-12-28")] alias degrees_pow := degrees_pow_le theorem mem_degrees {p : MvPolynomial σ R} {i : σ} : i ∈ p.degrees ↔ ∃ d, p.coeff d ≠ 0 ∧ i ∈ d.support := by classical simp only [degrees_def, Multiset.mem_sup, ← mem_support_iff, Finsupp.mem_toMultiset, exists_prop]
Mathlib/Algebra/MvPolynomial/Degrees.lean
144
146
theorem le_degrees_add_left (h : Disjoint p.degrees q.degrees) : p.degrees ≤ (p + q).degrees := by
classical apply Finset.sup_le
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Kexing Ying, Eric Wieser -/ import Mathlib.Data.Finset.Sym import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.SesquilinearForm import Mathlib.LinearAlgebra.Matrix.Symmetric /-! # Quadratic maps This file defines quadratic maps on an `R`-module `M`, taking values in an `R`-module `N`. An `N`-valued quadratic map on a module `M` over a commutative ring `R` is a map `Q : M → N` such that: * `QuadraticMap.map_smul`: `Q (a • x) = (a * a) • Q x` * `QuadraticMap.polar_add_left`, `QuadraticMap.polar_add_right`, `QuadraticMap.polar_smul_left`, `QuadraticMap.polar_smul_right`: the map `QuadraticMap.polar Q := fun x y ↦ Q (x + y) - Q x - Q y` is bilinear. This notion generalizes to commutative semirings using the approach in [izhakian2016][] which requires that there be a (possibly non-unique) companion bilinear map `B` such that `∀ x y, Q (x + y) = Q x + Q y + B x y`. Over a ring, this `B` is precisely `QuadraticMap.polar Q`. To build a `QuadraticMap` from the `polar` axioms, use `QuadraticMap.ofPolar`. Quadratic maps come with a scalar multiplication, `(a • Q) x = a • Q x`, and composition with linear maps `f`, `Q.comp f x = Q (f x)`. ## Main definitions * `QuadraticMap.ofPolar`: a more familiar constructor that works on rings * `QuadraticMap.associated`: associated bilinear map * `QuadraticMap.PosDef`: positive definite quadratic maps * `QuadraticMap.Anisotropic`: anisotropic quadratic maps * `QuadraticMap.discr`: discriminant of a quadratic map * `QuadraticMap.IsOrtho`: orthogonality of vectors with respect to a quadratic map. ## Main statements * `QuadraticMap.associated_left_inverse`, * `QuadraticMap.associated_rightInverse`: in a commutative ring where 2 has an inverse, there is a correspondence between quadratic maps and symmetric bilinear forms * `LinearMap.BilinForm.exists_orthogonal_basis`: There exists an orthogonal basis with respect to any nondegenerate, symmetric bilinear map `B`. ## Notation In this file, the variable `R` is used when a `CommSemiring` structure is available. The variable `S` is used when `R` itself has a `•` action. ## Implementation notes While the definition and many results make sense if we drop commutativity assumptions, the correct definition of a quadratic maps in the noncommutative setting would require substantial refactors from the current version, such that $Q(rm) = rQ(m)r^*$ for some suitable conjugation $r^*$. The [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Quadratic.20Maps/near/395529867) has some further discussion. ## References * https://en.wikipedia.org/wiki/Quadratic_form * https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms ## Tags quadratic map, homogeneous polynomial, quadratic polynomial -/ universe u v w variable {S T : Type*} variable {R : Type*} {M N P A : Type*} open LinearMap (BilinMap BilinForm) section Polar variable [CommRing R] [AddCommGroup M] [AddCommGroup N] namespace QuadraticMap /-- Up to a factor 2, `Q.polar` is the associated bilinear map for a quadratic map `Q`. Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization -/ def polar (f : M → N) (x y : M) := f (x + y) - f x - f y protected theorem map_add (f : M → N) (x y : M) : f (x + y) = f x + f y + polar f x y := by rw [polar] abel theorem polar_add (f g : M → N) (x y : M) : polar (f + g) x y = polar f x y + polar g x y := by simp only [polar, Pi.add_apply] abel
Mathlib/LinearAlgebra/QuadraticForm/Basic.lean
107
108
theorem polar_neg (f : M → N) (x y : M) : polar (-f) x y = -polar f x y := by
simp only [polar, Pi.neg_apply, sub_eq_add_neg, neg_add]
/- Copyright (c) 2023 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Topology.Bases import Mathlib.Order.Filter.CountableInter import Mathlib.Topology.Compactness.SigmaCompact /-! # Lindelöf sets and Lindelöf spaces ## Main definitions We define the following properties for sets in a topological space: * `IsLindelof s`: Two definitions are possible here. The more standard definition is that every open cover that contains `s` contains a countable subcover. We choose for the equivalent definition where we require that every nontrivial filter on `s` with the countable intersection property has a clusterpoint. Equivalence is established in `isLindelof_iff_countable_subcover`. * `LindelofSpace X`: `X` is Lindelöf if it is Lindelöf as a set. * `NonLindelofSpace`: a space that is not a Lindëlof space, e.g. the Long Line. ## Main results * `isLindelof_iff_countable_subcover`: A set is Lindelöf iff every open cover has a countable subcover. ## Implementation details * This API is mainly based on the API for IsCompact and follows notation and style as much as possible. -/ open Set Filter Topology TopologicalSpace universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} section Lindelof /-- A set `s` is Lindelöf if every nontrivial filter `f` with the countable intersection property that contains `s`, has a clusterpoint in `s`. The filter-free definition is given by `isLindelof_iff_countable_subcover`. -/ def IsLindelof (s : Set X) := ∀ ⦃f⦄ [NeBot f] [CountableInterFilter f], f ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x f /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/ theorem IsLindelof.compl_mem_sets (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) : sᶜ ∈ f := by contrapose! hf simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢ exact hs inf_le_right /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ theorem IsLindelof.compl_mem_sets_of_nhdsWithin (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by refine hs.compl_mem_sets fun x hx ↦ ?_ rw [← disjoint_principal_right, disjoint_right_comm, (basis_sets _).disjoint_iff_left] exact hf x hx /-- If `p : Set X → Prop` is stable under restriction and union, and each point `x` of a Lindelöf set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsLindelof.induction_on (hs : IsLindelof s) {p : Set X → Prop} (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, p s) → p (⋃₀ S)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := ofCountableUnion p hcountable_union (fun t ht _ hsub ↦ hmono hsub ht) have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] /-- The intersection of a Lindelöf set and a closed set is a Lindelöf set. -/ theorem IsLindelof.inter_right (hs : IsLindelof s) (ht : IsClosed t) : IsLindelof (s ∩ t) := by intro f hnf _ hstf rw [← inf_principal, le_inf_iff] at hstf obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs hstf.1 have hxt : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono hstf.2 exact ⟨x, ⟨hsx, hxt⟩, hx⟩ /-- The intersection of a closed set and a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.inter_left (ht : IsLindelof t) (hs : IsClosed s) : IsLindelof (s ∩ t) := inter_comm t s ▸ ht.inter_right hs /-- The set difference of a Lindelöf set and an open set is a Lindelöf set. -/ theorem IsLindelof.diff (hs : IsLindelof s) (ht : IsOpen t) : IsLindelof (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) /-- A closed subset of a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.of_isClosed_subset (hs : IsLindelof s) (ht : IsClosed t) (h : t ⊆ s) : IsLindelof t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht /-- A continuous image of a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.image_of_continuousOn {f : X → Y} (hs : IsLindelof s) (hf : ContinuousOn f s) : IsLindelof (f '' s) := by intro l lne _ ls have : NeBot (l.comap f ⊓ 𝓟 s) := comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls) obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this _ inf_le_right haveI := hx.neBot use f x, mem_image_of_mem f hxs have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1 rw [nhdsWithin] ac_rfl exact this.neBot /-- A continuous image of a Lindelöf set is a Lindelöf set within the codomain. -/ theorem IsLindelof.image {f : X → Y} (hs : IsLindelof s) (hf : Continuous f) : IsLindelof (f '' s) := hs.image_of_continuousOn hf.continuousOn /-- A filter with the countable intersection property that is finer than the principal filter on a Lindelöf set `s` contains any open set that contains all clusterpoints of `s`. -/ theorem IsLindelof.adherence_nhdset {f : Filter X} [CountableInterFilter f] (hs : IsLindelof s) (hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f := (eq_or_neBot _).casesOn mem_of_eq_bot fun _ ↦ let ⟨x, hx, hfx⟩ := @hs (f ⊓ 𝓟 tᶜ) _ _ <| inf_le_of_left_le hf₂ have : x ∈ t := ht₂ x hx hfx.of_inf_left have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (ht₁.mem_nhds this) have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne absurd A this /-- For every open cover of a Lindelöf set, there exists a countable subcover. -/ theorem IsLindelof.elim_countable_subcover {ι : Type v} (hs : IsLindelof s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i) := by have hmono : ∀ ⦃s t : Set X⦄, s ⊆ t → (∃ r : Set ι, r.Countable ∧ t ⊆ ⋃ i ∈ r, U i) → (∃ r : Set ι, r.Countable ∧ s ⊆ ⋃ i ∈ r, U i) := by intro _ _ hst ⟨r, ⟨hrcountable, hsub⟩⟩ exact ⟨r, hrcountable, Subset.trans hst hsub⟩ have hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i)) → ∃ r : Set ι, r.Countable ∧ (⋃₀ S ⊆ ⋃ i ∈ r, U i) := by intro S hS hsr choose! r hr using hsr refine ⟨⋃ s ∈ S, r s, hS.biUnion_iff.mpr (fun s hs ↦ (hr s hs).1), ?_⟩ refine sUnion_subset ?h.right.h simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and'] exact fun i is x hx ↦ mem_biUnion is ((hr i is).2 hx) have h_nhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∃ r : Set ι, r.Countable ∧ (t ⊆ ⋃ i ∈ r, U i) := by intro x hx let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) refine ⟨U i, mem_nhdsWithin_of_mem_nhds ((hUo i).mem_nhds hi), {i}, by simp, ?_⟩ simp only [mem_singleton_iff, iUnion_iUnion_eq_left] exact Subset.refl _ exact hs.induction_on hmono hcountable_union h_nhds theorem IsLindelof.elim_nhds_subcover' (hs : IsLindelof s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Set s, t.Countable ∧ s ⊆ ⋃ x ∈ t, U (x : s) x.2 := by have := hs.elim_countable_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior) fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ rcases this with ⟨r, ⟨hr, hs⟩⟩ use r, hr apply Subset.trans hs apply iUnion₂_subset intro i hi apply Subset.trans interior_subset exact subset_iUnion_of_subset i (subset_iUnion_of_subset hi (Subset.refl _)) theorem IsLindelof.elim_nhds_subcover (hs : IsLindelof s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Set X, t.Countable ∧ (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := by let ⟨t, ⟨htc, htsub⟩⟩ := hs.elim_nhds_subcover' (fun x _ ↦ U x) hU refine ⟨↑t, Countable.image htc Subtype.val, ?_⟩ constructor · intro _ simp only [mem_image, Subtype.exists, exists_and_right, exists_eq_right, forall_exists_index] tauto · have : ⋃ x ∈ t, U ↑x = ⋃ x ∈ Subtype.val '' t, U x := biUnion_image.symm rwa [← this] /-- For every nonempty open cover of a Lindelöf set, there exists a subcover indexed by ℕ. -/ theorem IsLindelof.indexed_countable_subcover {ι : Type v} [Nonempty ι] (hs : IsLindelof s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ f : ℕ → ι, s ⊆ ⋃ n, U (f n) := by obtain ⟨c, ⟨c_count, c_cov⟩⟩ := hs.elim_countable_subcover U hUo hsU rcases c.eq_empty_or_nonempty with rfl | c_nonempty · simp only [mem_empty_iff_false, iUnion_of_empty, iUnion_empty] at c_cov simp only [subset_eq_empty c_cov rfl, empty_subset, exists_const] obtain ⟨f, f_surj⟩ := (Set.countable_iff_exists_surjective c_nonempty).mp c_count refine ⟨fun x ↦ f x, c_cov.trans <| iUnion₂_subset_iff.mpr (?_ : ∀ i ∈ c, U i ⊆ ⋃ n, U (f n))⟩ intro x hx obtain ⟨n, hn⟩ := f_surj ⟨x, hx⟩ exact subset_iUnion_of_subset n <| subset_of_eq (by rw [hn]) /-- The neighborhood filter of a Lindelöf set is disjoint with a filter `l` with the countable intersection property if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/
Mathlib/Topology/Compactness/Lindelof.lean
196
206
theorem IsLindelof.disjoint_nhdsSet_left {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by
refine ⟨fun h x hx ↦ h.mono_left <| nhds_le_nhdsSet hx, fun H ↦ ?_⟩ choose! U hxU hUl using fun x hx ↦ (nhds_basis_opens x).disjoint_iff_left.1 (H x hx) choose hxU hUo using hxU rcases hs.elim_nhds_subcover U fun x hx ↦ (hUo x hx).mem_nhds (hxU x hx) with ⟨t, htc, hts, hst⟩ refine (hasBasis_nhdsSet _).disjoint_iff_left.2 ⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx ↦ hUo x (hts x hx), hst⟩, ?_⟩ rw [compl_iUnion₂] exact (countable_bInter_mem htc).mpr (fun i hi ↦ hUl _ (hts _ hi))
/- 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.Analysis.Complex.Basic import Mathlib.Topology.FiberBundle.IsHomeomorphicTrivialBundle /-! # Closure, interior, and frontier of preimages under `re` and `im` In this fact we use the fact that `ℂ` is naturally homeomorphic to `ℝ × ℝ` to deduce some topological properties of `Complex.re` and `Complex.im`. ## Main statements Each statement about `Complex.re` listed below has a counterpart about `Complex.im`. * `Complex.isHomeomorphicTrivialFiberBundle_re`: `Complex.re` turns `ℂ` into a trivial topological fiber bundle over `ℝ`; * `Complex.isOpenMap_re`, `Complex.isQuotientMap_re`: in particular, `Complex.re` is an open map and is a quotient map; * `Complex.interior_preimage_re`, `Complex.closure_preimage_re`, `Complex.frontier_preimage_re`: formulas for `interior (Complex.re ⁻¹' s)` etc; * `Complex.interior_setOf_re_le` etc: particular cases of the above formulas in the cases when `s` is one of the infinite intervals `Set.Ioi a`, `Set.Ici a`, `Set.Iio a`, and `Set.Iic a`, formulated as `interior {z : ℂ | z.re ≤ a} = {z | z.re < a}` etc. ## Tags complex, real part, imaginary part, closure, interior, frontier -/ open Set Topology noncomputable section namespace Complex /-- `Complex.re` turns `ℂ` into a trivial topological fiber bundle over `ℝ`. -/ theorem isHomeomorphicTrivialFiberBundle_re : IsHomeomorphicTrivialFiberBundle ℝ re := ⟨equivRealProdCLM.toHomeomorph, fun _ => rfl⟩ /-- `Complex.im` turns `ℂ` into a trivial topological fiber bundle over `ℝ`. -/ theorem isHomeomorphicTrivialFiberBundle_im : IsHomeomorphicTrivialFiberBundle ℝ im := ⟨equivRealProdCLM.toHomeomorph.trans (Homeomorph.prodComm ℝ ℝ), fun _ => rfl⟩ theorem isOpenMap_re : IsOpenMap re := isHomeomorphicTrivialFiberBundle_re.isOpenMap_proj theorem isOpenMap_im : IsOpenMap im := isHomeomorphicTrivialFiberBundle_im.isOpenMap_proj theorem isQuotientMap_re : IsQuotientMap re := isHomeomorphicTrivialFiberBundle_re.isQuotientMap_proj @[deprecated (since := "2024-10-22")] alias quotientMap_re := isQuotientMap_re theorem isQuotientMap_im : IsQuotientMap im := isHomeomorphicTrivialFiberBundle_im.isQuotientMap_proj @[deprecated (since := "2024-10-22")] alias quotientMap_im := isQuotientMap_im theorem interior_preimage_re (s : Set ℝ) : interior (re ⁻¹' s) = re ⁻¹' interior s := (isOpenMap_re.preimage_interior_eq_interior_preimage continuous_re _).symm theorem interior_preimage_im (s : Set ℝ) : interior (im ⁻¹' s) = im ⁻¹' interior s := (isOpenMap_im.preimage_interior_eq_interior_preimage continuous_im _).symm theorem closure_preimage_re (s : Set ℝ) : closure (re ⁻¹' s) = re ⁻¹' closure s := (isOpenMap_re.preimage_closure_eq_closure_preimage continuous_re _).symm theorem closure_preimage_im (s : Set ℝ) : closure (im ⁻¹' s) = im ⁻¹' closure s := (isOpenMap_im.preimage_closure_eq_closure_preimage continuous_im _).symm theorem frontier_preimage_re (s : Set ℝ) : frontier (re ⁻¹' s) = re ⁻¹' frontier s := (isOpenMap_re.preimage_frontier_eq_frontier_preimage continuous_re _).symm theorem frontier_preimage_im (s : Set ℝ) : frontier (im ⁻¹' s) = im ⁻¹' frontier s := (isOpenMap_im.preimage_frontier_eq_frontier_preimage continuous_im _).symm @[simp] theorem interior_setOf_re_le (a : ℝ) : interior { z : ℂ | z.re ≤ a } = { z | z.re < a } := by simpa only [interior_Iic] using interior_preimage_re (Iic a) @[simp] theorem interior_setOf_im_le (a : ℝ) : interior { z : ℂ | z.im ≤ a } = { z | z.im < a } := by simpa only [interior_Iic] using interior_preimage_im (Iic a) @[simp] theorem interior_setOf_le_re (a : ℝ) : interior { z : ℂ | a ≤ z.re } = { z | a < z.re } := by simpa only [interior_Ici] using interior_preimage_re (Ici a) @[simp] theorem interior_setOf_le_im (a : ℝ) : interior { z : ℂ | a ≤ z.im } = { z | a < z.im } := by simpa only [interior_Ici] using interior_preimage_im (Ici a) @[simp] theorem closure_setOf_re_lt (a : ℝ) : closure { z : ℂ | z.re < a } = { z | z.re ≤ a } := by simpa only [closure_Iio] using closure_preimage_re (Iio a) @[simp] theorem closure_setOf_im_lt (a : ℝ) : closure { z : ℂ | z.im < a } = { z | z.im ≤ a } := by simpa only [closure_Iio] using closure_preimage_im (Iio a) @[simp] theorem closure_setOf_lt_re (a : ℝ) : closure { z : ℂ | a < z.re } = { z | a ≤ z.re } := by simpa only [closure_Ioi] using closure_preimage_re (Ioi a) @[simp] theorem closure_setOf_lt_im (a : ℝ) : closure { z : ℂ | a < z.im } = { z | a ≤ z.im } := by simpa only [closure_Ioi] using closure_preimage_im (Ioi a) @[simp] theorem frontier_setOf_re_le (a : ℝ) : frontier { z : ℂ | z.re ≤ a } = { z | z.re = a } := by simpa only [frontier_Iic] using frontier_preimage_re (Iic a) @[simp] theorem frontier_setOf_im_le (a : ℝ) : frontier { z : ℂ | z.im ≤ a } = { z | z.im = a } := by simpa only [frontier_Iic] using frontier_preimage_im (Iic a) @[simp] theorem frontier_setOf_le_re (a : ℝ) : frontier { z : ℂ | a ≤ z.re } = { z | z.re = a } := by simpa only [frontier_Ici] using frontier_preimage_re (Ici a) @[simp] theorem frontier_setOf_le_im (a : ℝ) : frontier { z : ℂ | a ≤ z.im } = { z | z.im = a } := by simpa only [frontier_Ici] using frontier_preimage_im (Ici a) @[simp] theorem frontier_setOf_re_lt (a : ℝ) : frontier { z : ℂ | z.re < a } = { z | z.re = a } := by simpa only [frontier_Iio] using frontier_preimage_re (Iio a) @[simp] theorem frontier_setOf_im_lt (a : ℝ) : frontier { z : ℂ | z.im < a } = { z | z.im = a } := by simpa only [frontier_Iio] using frontier_preimage_im (Iio a) @[simp] theorem frontier_setOf_lt_re (a : ℝ) : frontier { z : ℂ | a < z.re } = { z | z.re = a } := by simpa only [frontier_Ioi] using frontier_preimage_re (Ioi a) @[simp] theorem frontier_setOf_lt_im (a : ℝ) : frontier { z : ℂ | a < z.im } = { z | z.im = a } := by simpa only [frontier_Ioi] using frontier_preimage_im (Ioi a) theorem closure_reProdIm (s t : Set ℝ) : closure (s ×ℂ t) = closure s ×ℂ closure t := by simpa only [← preimage_eq_preimage equivRealProdCLM.symm.toHomeomorph.surjective, equivRealProdCLM.symm.toHomeomorph.preimage_closure] using @closure_prod_eq _ _ _ _ s t theorem interior_reProdIm (s t : Set ℝ) : interior (s ×ℂ t) = interior s ×ℂ interior t := by rw [reProdIm, reProdIm, interior_inter, interior_preimage_re, interior_preimage_im] theorem frontier_reProdIm (s t : Set ℝ) : frontier (s ×ℂ t) = closure s ×ℂ frontier t ∪ frontier s ×ℂ closure t := by simpa only [← preimage_eq_preimage equivRealProdCLM.symm.toHomeomorph.surjective, equivRealProdCLM.symm.toHomeomorph.preimage_frontier] using frontier_prod_eq s t theorem frontier_setOf_le_re_and_le_im (a b : ℝ) : frontier { z | a ≤ re z ∧ b ≤ im z } = { z | a ≤ re z ∧ im z = b ∨ re z = a ∧ b ≤ im z } := by simpa only [closure_Ici, frontier_Ici] using frontier_reProdIm (Ici a) (Ici b)
Mathlib/Analysis/Complex/ReImTopology.lean
164
165
theorem frontier_setOf_le_re_and_im_le (a b : ℝ) : frontier { z | a ≤ re z ∧ im z ≤ b } = { z | a ≤ re z ∧ im z = b ∨ re z = a ∧ im z ≤ b } := by
/- 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.ConditionallyCompleteLattice.Indexed import Mathlib.Order.Filter.IsBounded 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 ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] {s : Set α} {u : β → α} /-- 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 lemma limsSup_principal_eq_csSup (h : BddAbove s) (hs : s.Nonempty) : limsSup (𝓟 s) = sSup s := by simp only [limsSup, eventually_principal]; exact csInf_upperBounds_eq_csSup h hs lemma limsInf_principal_eq_csSup (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s := limsSup_principal_eq_csSup (α := αᵒᵈ) h hs lemma limsup_top_eq_ciSup [Nonempty β] (hu : BddAbove (range u)) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_csSup hu (range_nonempty _), sSup_range] lemma liminf_top_eq_ciInf [Nonempty β] (hu : BddBelow (range u)) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_csSup hu (range_nonempty _), sInf_range] 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 @[simp] theorem liminf_nat_add (f : ℕ → α) (k : ℕ) : liminf (fun i => f (i + k)) atTop = liminf f atTop := by rw [← Function.comp_def, liminf, liminf, ← map_map, map_add_atTop_eq_nat] @[simp] 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 simpa [eq_univ_iff_forall] using fun b hb => top_unique <| hb _ @[simp] theorem limsInf_top : limsInf (⊤ : Filter α) = ⊥ := bot_unique <| sSup_le <| by simpa [eq_univ_iff_forall] using 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] lemma limsSup_principal_eq_sSup (s : Set α) : limsSup (𝓟 s) = sSup s := by simpa only [limsSup, eventually_principal] using sInf_upperBounds_eq_csSup s lemma limsInf_principal_eq_sInf (s : Set α) : limsInf (𝓟 s) = sInf s := by simpa only [limsInf, eventually_principal] using sSup_lowerBounds_eq_sInf s @[simp] lemma limsup_top_eq_iSup (u : β → α) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_sSup, sSup_range] @[simp] lemma liminf_top_eq_iInf (u : β → α) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_sInf, sInf_range] 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) /-- 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 _ 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 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 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`. -/ 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`. -/ 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] theorem _root_.OrderIso.apply_bliminf [CompleteLattice γ] (e : α ≃o γ) : e (bliminf u f p) = bliminf (e ∘ u) f p := e.dual.apply_blimsup 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] 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 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, comp_def, 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, comp_def, 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] /-- 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] 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 section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] /-- If `Filter.limsup u atTop ≤ x`, then for all `ε > 0`, eventually we have `u b < x + ε`. -/ theorem eventually_lt_add_pos_of_limsup_le [Preorder β] [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : β → α} (hu_bdd : IsBoundedUnder LE.le atTop u) (hu : Filter.limsup u atTop ≤ x) (hε : 0 < ε) : ∀ᶠ b : β in atTop, u b < x + ε := eventually_lt_of_limsup_lt (lt_of_le_of_lt hu (lt_add_of_pos_right x hε)) hu_bdd /-- If `x ≤ Filter.liminf u atTop`, then for all `ε < 0`, eventually we have `x + ε < u b`. -/ theorem eventually_add_neg_lt_of_le_liminf [Preorder β] [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : β → α} (hu_bdd : IsBoundedUnder GE.ge atTop u) (hu : x ≤ Filter.liminf u atTop) (hε : ε < 0) : ∀ᶠ b : β in atTop, x + ε < u b := eventually_lt_of_lt_liminf (lt_of_lt_of_le (add_lt_of_neg_right x hε) hu) hu_bdd /-- If `Filter.limsup u atTop ≤ x`, then for all `ε > 0`, there exists a positive natural number `n` such that `u n < x + ε`. -/ theorem exists_lt_of_limsup_le [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : ℕ → α} (hu_bdd : IsBoundedUnder LE.le atTop u) (hu : Filter.limsup u atTop ≤ x) (hε : 0 < ε) : ∃ n : PNat, u n < x + ε := by have h : ∀ᶠ n : ℕ in atTop, u n < x + ε := eventually_lt_add_pos_of_limsup_le hu_bdd hu hε simp only [eventually_atTop] at h obtain ⟨n, hn⟩ := h exact ⟨⟨n + 1, Nat.succ_pos _⟩, hn (n + 1) (Nat.le_succ _)⟩ /-- If `x ≤ Filter.liminf u atTop`, then for all `ε < 0`, there exists a positive natural number `n` such that ` x + ε < u n`. -/ theorem exists_lt_of_le_liminf [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : ℕ → α} (hu_bdd : IsBoundedUnder GE.ge atTop u) (hu : x ≤ Filter.liminf u atTop) (hε : ε < 0) : ∃ n : PNat, x + ε < u n := by have h : ∀ᶠ n : ℕ in atTop, x + ε < u n := eventually_add_neg_lt_of_le_liminf hu_bdd hu hε simp only [eventually_atTop] at h obtain ⟨n, hn⟩ := h exact ⟨⟨n + 1, Nat.succ_pos _⟩, hn (n + 1) (Nat.le_succ _)⟩ end ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder β] {f : Filter α} {u : α → β} theorem le_limsup_of_frequently_le {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 {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 {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 {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 {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 (h.trans_lt 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 (limsup_le_of_le h₁ ((h z x_z).mono (fun _ ↦ le_of_lt))).trans_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)) /- A version of `limsup_le_iff` with large inequalities in densely ordered spaces.-/ lemma limsup_le_iff' [DenselyOrdered β] {x : β} (h₁ : IsCoboundedUnder (· ≤ ·) f u := by isBoundedDefault) (h₂ : IsBoundedUnder (· ≤ ·) f 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 (h.trans_lt h') h₂).mono fun _ ↦ le_of_lt, ?_⟩ rw [← forall_lt_iff_le'] intro h y x_y obtain ⟨z, x_z, z_y⟩ := exists_between x_y exact (limsup_le_of_le h₁ (h z x_z)).trans_lt z_y theorem le_limsup_iff {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₁ (h'.trans_le 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 obtain ⟨z, y_z, z_x⟩ := h' y y_x exact y_z.trans_le (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)) /- A version of `le_limsup_iff` with large inequalities in densely ordered spaces.-/ lemma le_limsup_iff' [DenselyOrdered β] {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₁ (h'.trans_le h)).mono fun _ ↦ le_of_lt, ?_⟩ rw [← forall_lt_iff_le] intro h y y_x obtain ⟨z, y_z, z_x⟩ := exists_between y_x exact y_z.trans_le (le_limsup_of_frequently_le (h z z_x) h₂) theorem le_liminf_iff {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₂ /- A version of `le_liminf_iff` with large inequalities in densely ordered spaces.-/ theorem le_liminf_iff' [DenselyOrdered β] {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 {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₂ /- A version of `liminf_le_iff` with large inequalities in densely ordered spaces.-/
Mathlib/Order/LiminfLimsup.lean
911
921
theorem liminf_le_iff' [DenselyOrdered β] {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₂ lemma liminf_le_limsup_of_frequently_le {v : α → β} (h : ∃ᶠ x in f, u x ≤ v x) (h₁ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : liminf u f ≤ limsup v f := by rcases f.eq_or_neBot with rfl | _ · exact (frequently_bot h).rec
/- Copyright (c) 2021 Hunter Monroe. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hunter Monroe, Kyle Miller, Alena Gusakov -/ import Mathlib.Combinatorics.SimpleGraph.DeleteEdges import Mathlib.Data.Fintype.Powerset /-! # Subgraphs of a simple graph A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the endpoints of each edge are present in the vertex subset. The edge subset is formalized as a sub-relation of the adjacency relation of the simple graph. ## Main definitions * `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`. * `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their `SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions. * `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`. (In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.) * `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and `Subgraph.IsInduced` for whether a subgraph is an induced subgraph. * Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`. * `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it into a member of the larger graph's `SimpleGraph.Subgraph` type. * Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs (`Subgraph.map`). ## Implementation notes * Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to this kind of subobject. ## TODO * Images of graph homomorphisms as subgraphs. -/ universe u v namespace SimpleGraph /-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice. Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then `Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/ @[ext] structure Subgraph {V : Type u} (G : SimpleGraph V) where /-- Vertices of the subgraph -/ verts : Set V /-- Edges of the subgraph -/ Adj : V → V → Prop adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously` initialize_simps_projections SimpleGraph.Subgraph (Adj → adj) variable {ι : Sort*} {V : Type u} {W : Type v} /-- The one-vertex subgraph. -/ @[simps] protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where verts := {v} Adj := ⊥ adj_sub := False.elim edge_vert := False.elim symm _ _ := False.elim /-- The one-edge subgraph. -/ @[simps] def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where verts := {v, w} Adj a b := s(v, w) = s(a, b) adj_sub h := by rw [← G.mem_edgeSet, ← h] exact hvw edge_vert {a b} h := by apply_fun fun e ↦ a ∈ e at h simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h exact h namespace Subgraph variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V} protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj := fun v h ↦ G.loopless v (G'.adj_sub h) theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v := ⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩ @[symm] theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u := G'.symm h protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u := G'.symm h protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v := H.adj_sub h protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts := H.edge_vert h protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts := h.symm.fst_mem protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v := h.adj_sub.ne theorem adj_congr_of_sym2 {H : G.Subgraph} {u v w x : V} (h2 : s(u, v) = s(w, x)) : H.Adj u v ↔ H.Adj w x := by simp only [Sym2.eq, Sym2.rel_iff', Prod.mk.injEq, Prod.swap_prod_mk] at h2 rcases h2 with hl | hr · rw [hl.1, hl.2] · rw [hr.1, hr.2, Subgraph.adj_comm] /-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/ @[simps] protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where Adj v w := G'.Adj v w symm _ _ h := G'.symm h loopless v h := loopless G v (G'.adj_sub h) @[simp] theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v := G'.adj_sub h -- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`. protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) : H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h instance (G : SimpleGraph V) (H : Subgraph G) [DecidableRel H.Adj] : DecidableRel H.coe.Adj := fun a b ↦ ‹DecidableRel H.Adj› _ _ /-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/ def IsSpanning (G' : Subgraph G) : Prop := ∀ v : V, v ∈ G'.verts theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ := Set.eq_univ_iff_forall.symm protected alias ⟨IsSpanning.verts_eq_univ, _⟩ := isSpanning_iff /-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning subgraph, then `G'.spanningCoe` yields an isomorphic graph. In general, this adds in all vertices from `V` as isolated vertices. -/ @[simps] protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where Adj := G'.Adj symm := G'.symm loopless v hv := G.loopless v (G'.adj_sub hv) @[simp] theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) : G.Adj u v := G'.adj_sub h lemma spanningCoe_le (G' : G.Subgraph) : G'.spanningCoe ≤ G := fun _ _ ↦ G'.3 theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by simp [Subgraph.spanningCoe] lemma mem_of_adj_spanningCoe {v w : V} {s : Set V} (G : SimpleGraph s) (hadj : G.spanningCoe.Adj v w) : v ∈ s := by aesop @[simp] lemma spanningCoe_subgraphOfAdj {v w : V} (hadj : G.Adj v w) : (G.subgraphOfAdj hadj).spanningCoe = fromEdgeSet {s(v, w)} := by ext v w aesop /-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/ @[simps] def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe where toFun v := ⟨v, h v⟩ invFun v := v left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl /-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if they are adjacent in `G`. -/ def IsInduced (G' : Subgraph G) : Prop := ∀ ⦃v⦄, v ∈ G'.verts → ∀ ⦃w⦄, w ∈ G'.verts → G.Adj v w → G'.Adj v w @[simp] protected lemma IsInduced.adj {G' : G.Subgraph} (hG' : G'.IsInduced) {a b : G'.verts} : G'.Adj a b ↔ G.Adj a b := ⟨coe_adj_sub _ _ _, hG' a.2 b.2⟩ /-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/ def support (H : Subgraph G) : Set V := Rel.dom H.Adj theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts := fun _ ⟨_, h⟩ ↦ H.edge_vert h /-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/ def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w} theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v := fun _ ↦ G'.adj_sub theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts := fun _ h ↦ G'.edge_vert (adj_symm G' h) @[simp] theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl /-- A subgraph as a graph has equivalent neighbor sets. -/ def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v where toFun w := ⟨w, w.2⟩ invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩ left_inv _ := rfl right_inv _ := rfl /-- The edge set of `G'` consists of a subset of edges of `G`. -/ def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet := Sym2.ind (fun _ _ ↦ G'.adj_sub) @[simp] protected lemma mem_edgeSet {G' : Subgraph G} {v w : V} : s(v, w) ∈ G'.edgeSet ↔ G'.Adj v w := .rfl @[simp] lemma edgeSet_coe {G' : G.Subgraph} : G'.coe.edgeSet = Sym2.map (↑) ⁻¹' G'.edgeSet := by ext e; induction e using Sym2.ind; simp lemma image_coe_edgeSet_coe (G' : G.Subgraph) : Sym2.map (↑) '' G'.coe.edgeSet = G'.edgeSet := by rw [edgeSet_coe, Set.image_preimage_eq_iff] rintro e he induction e using Sym2.ind with | h a b => rw [Subgraph.mem_edgeSet] at he exact ⟨s(⟨a, edge_vert _ he⟩, ⟨b, edge_vert _ he.symm⟩), Sym2.map_pair_eq ..⟩ theorem mem_verts_of_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet) (hv : v ∈ e) : v ∈ G'.verts := by induction e rcases Sym2.mem_iff.mp hv with (rfl | rfl) · exact G'.edge_vert he · exact G'.edge_vert (G'.symm he) /-- The `incidenceSet` is the set of edges incident to a given vertex. -/ def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e} theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G.incidenceSet v := fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩ theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet := fun _ h ↦ h.1 /-- Give a vertex as an element of the subgraph's vertex type. -/ abbrev vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩ /-- Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities. See Note [range copy pattern]. -/ def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts) (adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where verts := V'' Adj := adj' adj_sub := hadj.symm ▸ G'.adj_sub edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert symm := hadj.symm ▸ G'.symm theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts) (adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' := Subgraph.ext hV hadj /-- The union of two subgraphs. -/ instance : Max G.Subgraph where max G₁ G₂ := { verts := G₁.verts ∪ G₂.verts Adj := G₁.Adj ⊔ G₂.Adj adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm } /-- The intersection of two subgraphs. -/ instance : Min G.Subgraph where min G₁ G₂ := { verts := G₁.verts ∩ G₂.verts Adj := G₁.Adj ⊓ G₂.Adj adj_sub := fun hab => G₁.adj_sub hab.1 edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm } /-- The `top` subgraph is `G` as a subgraph of itself. -/ instance : Top G.Subgraph where top := { verts := Set.univ Adj := G.Adj adj_sub := id edge_vert := @fun v _ _ => Set.mem_univ v symm := G.symm } /-- The `bot` subgraph is the subgraph with no vertices or edges. -/ instance : Bot G.Subgraph where bot := { verts := ∅ Adj := ⊥ adj_sub := False.elim edge_vert := False.elim symm := fun _ _ => id } instance : SupSet G.Subgraph where sSup s := { verts := ⋃ G' ∈ s, verts G' Adj := fun a b => ∃ G' ∈ s, Adj G' a b adj_sub := by rintro a b ⟨G', -, hab⟩ exact G'.adj_sub hab edge_vert := by rintro a b ⟨G', hG', hab⟩ exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab) symm := fun a b h => by simpa [adj_comm] using h } instance : InfSet G.Subgraph where sInf s := { verts := ⋂ G' ∈ s, verts G' Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b adj_sub := And.right edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG' symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm } @[simp] theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b := Iff.rfl @[simp] theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b := Iff.rfl @[simp] theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b := Iff.rfl @[simp] theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b := not_false @[simp] theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts := rfl @[simp] theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts := rfl @[simp] theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ := rfl @[simp] theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ := rfl @[simp] theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b := Iff.rfl @[simp] theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b := Iff.rfl @[simp] theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by simp [iSup] @[simp] theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by simp [iInf] theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) : (sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b := sInf_adj.trans <| and_iff_left_of_imp <| by obtain ⟨G', hG'⟩ := hs exact fun h => G'.adj_sub (h _ hG') theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)] simp @[simp] theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' := rfl @[simp] theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' := rfl @[simp] theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup] @[simp] theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf] @[simp] lemma coe_bot : (⊥ : G.Subgraph).coe = ⊥ := rfl @[simp] lemma IsInduced.top : (⊤ : G.Subgraph).IsInduced := fun _ _ _ _ ↦ id /-- The graph isomorphism between the top element of `G.subgraph` and `G`. -/ def topIso : (⊤ : G.Subgraph).coe ≃g G where toFun := (↑) invFun a := ⟨a, Set.mem_univ _⟩ left_inv _ := Subtype.eta .. right_inv _ := rfl map_rel_iff' := .rfl theorem verts_spanningCoe_injective : (fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by intro G₁ G₂ h rw [Prod.ext_iff] at h exact Subgraph.ext h.1 (spanningCoe_inj.1 h.2) /-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and `∀ a b, G₁.adj a b → G₂.adj a b`. -/ instance distribLattice : DistribLattice G.Subgraph := { show DistribLattice G.Subgraph from verts_spanningCoe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl with le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w } instance : BoundedOrder (Subgraph G) where top := ⊤ bot := ⊥ le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩ bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩ /-- Note that subgraphs do not form a Boolean algebra, because of `verts`. -/ def completelyDistribLatticeMinimalAxioms : CompletelyDistribLattice.MinimalAxioms G.Subgraph := { Subgraph.distribLattice with le := (· ≤ ·) sup := (· ⊔ ·) inf := (· ⊓ ·) top := ⊤ bot := ⊥ le_top := fun G' => ⟨Set.subset_univ _, fun _ _ => G'.adj_sub⟩ bot_le := fun _ => ⟨Set.empty_subset _, fun _ _ => False.elim⟩ sSup := sSup -- Porting note: needed `apply` here to modify elaboration; previously the term itself was fine. le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun _ _ hab => ⟨G', hG', hab⟩⟩ sSup_le := fun s G' hG' => ⟨Set.iUnion₂_subset fun _ hH => (hG' _ hH).1, by rintro a b ⟨H, hH, hab⟩ exact (hG' _ hH).2 hab⟩ sInf := sInf sInf_le := fun _ G' hG' => ⟨Set.iInter₂_subset G' hG', fun _ _ hab => hab.1 hG'⟩ le_sInf := fun _ G' hG' => ⟨Set.subset_iInter₂ fun _ hH => (hG' _ hH).1, fun _ _ hab => ⟨fun _ hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩ iInf_iSup_eq := fun f => Subgraph.ext (by simpa using iInf_iSup_eq) (by ext; simp [Classical.skolem]) } instance : CompletelyDistribLattice G.Subgraph := .ofMinimalAxioms completelyDistribLatticeMinimalAxioms @[gcongr] lemma verts_mono {H H' : G.Subgraph} (h : H ≤ H') : H.verts ⊆ H'.verts := h.1 lemma verts_monotone : Monotone (verts : G.Subgraph → Set V) := fun _ _ h ↦ h.1 @[simps] instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩ @[simp] theorem neighborSet_sup {H H' : G.Subgraph} (v : V) : (H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl @[simp] theorem neighborSet_inf {H H' : G.Subgraph} (v : V) : (H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl @[simp] theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl @[simp] theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl @[simp] theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) : (sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by ext simp @[simp] theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) : (sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by ext simp @[simp] theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) : (⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup] @[simp] theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) : (⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf] @[simp] theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl @[simp] theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ := Set.ext <| Sym2.ind (by simp) @[simp] theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet := Set.ext <| Sym2.ind (by simp) @[simp] theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet := Set.ext <| Sym2.ind (by simp) @[simp]
Mathlib/Combinatorics/SimpleGraph/Subgraph.lean
533
534
theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by
ext e
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Subobject.Limits /-! # Image-to-kernel comparison maps Whenever `f : A ⟶ B` and `g : B ⟶ C` satisfy `w : f ≫ g = 0`, we have `image_le_kernel f g w : imageSubobject f ≤ kernelSubobject g` (assuming the appropriate images and kernels exist). `imageToKernel f g w` is the corresponding morphism between objects in `C`. -/ universe v u w open CategoryTheory CategoryTheory.Limits variable {ι : Type*} variable {V : Type u} [Category.{v} V] [HasZeroMorphisms V] noncomputable section section variable {A B C : V} (f : A ⟶ B) [HasImage f] (g : B ⟶ C) [HasKernel g] theorem image_le_kernel (w : f ≫ g = 0) : imageSubobject f ≤ kernelSubobject g := imageSubobject_le_mk _ _ (kernel.lift _ _ w) (by simp) /-- The canonical morphism `imageSubobject f ⟶ kernelSubobject g` when `f ≫ g = 0`. -/ def imageToKernel (w : f ≫ g = 0) : (imageSubobject f : V) ⟶ (kernelSubobject g : V) := Subobject.ofLE _ _ (image_le_kernel _ _ w) instance (w : f ≫ g = 0) : Mono (imageToKernel f g w) := by dsimp only [imageToKernel] infer_instance /-- Prefer `imageToKernel`. -/ @[simp] theorem subobject_ofLE_as_imageToKernel (w : f ≫ g = 0) (h) : Subobject.ofLE (imageSubobject f) (kernelSubobject g) h = imageToKernel f g w := rfl attribute [local instance] HasForget.instFunLike -- Porting note: removed elementwise attribute which does not seem to be helpful here -- a more suitable lemma is added below @[reassoc (attr := simp)] theorem imageToKernel_arrow (w : f ≫ g = 0) : imageToKernel f g w ≫ (kernelSubobject g).arrow = (imageSubobject f).arrow := by simp [imageToKernel] @[simp] lemma imageToKernel_arrow_apply {FV : V → V → Type*} {CV : V → Type*} [∀ X Y, FunLike (FV X Y) (CV X) (CV Y)] [ConcreteCategory V FV] (w : f ≫ g = 0) (x : ToType (Subobject.underlying.obj (imageSubobject f))) : (kernelSubobject g).arrow (imageToKernel f g w x) = (imageSubobject f).arrow x := by rw [← ConcreteCategory.comp_apply, imageToKernel_arrow] -- This is less useful as a `simp` lemma than it initially appears, -- as it "loses" the information the morphism factors through the image. theorem factorThruImageSubobject_comp_imageToKernel (w : f ≫ g = 0) : factorThruImageSubobject f ≫ imageToKernel f g w = factorThruKernelSubobject g f w := by ext simp end section variable {A B C : V} (f : A ⟶ B) (g : B ⟶ C) @[simp] theorem imageToKernel_zero_left [HasKernels V] [HasZeroObject V] {w} : imageToKernel (0 : A ⟶ B) g w = 0 := by ext simp theorem imageToKernel_zero_right [HasImages V] {w} : imageToKernel f (0 : B ⟶ C) w = (imageSubobject f).arrow ≫ inv (kernelSubobject (0 : B ⟶ C)).arrow := by ext simp section variable [HasKernels V] [HasImages V] theorem imageToKernel_comp_right {D : V} (h : C ⟶ D) (w : f ≫ g = 0) : imageToKernel f (g ≫ h) (by simp [reassoc_of% w]) = imageToKernel f g w ≫ Subobject.ofLE _ _ (kernelSubobject_comp_le g h) := by ext simp theorem imageToKernel_comp_left {Z : V} (h : Z ⟶ A) (w : f ≫ g = 0) : imageToKernel (h ≫ f) g (by simp [w]) = Subobject.ofLE _ _ (imageSubobject_comp_le h f) ≫ imageToKernel f g w := by ext simp @[simp] theorem imageToKernel_comp_mono {D : V} (h : C ⟶ D) [Mono h] (w) : imageToKernel f (g ≫ h) w = imageToKernel f g ((cancel_mono h).mp (by simpa using w : (f ≫ g) ≫ h = 0 ≫ h)) ≫ (Subobject.isoOfEq _ _ (kernelSubobject_comp_mono g h)).inv := by ext simp @[simp] theorem imageToKernel_epi_comp {Z : V} (h : Z ⟶ A) [Epi h] (w) : imageToKernel (h ≫ f) g w = Subobject.ofLE _ _ (imageSubobject_comp_le h f) ≫ imageToKernel f g ((cancel_epi h).mp (by simpa using w : h ≫ f ≫ g = h ≫ 0)) := by ext simp end @[simp]
Mathlib/Algebra/Homology/ImageToKernel.lean
127
132
theorem imageToKernel_comp_hom_inv_comp [HasEqualizers V] [HasImages V] {Z : V} {i : B ≅ Z} (w) : imageToKernel (f ≫ i.hom) (i.inv ≫ g) w = (imageSubobjectCompIso _ _).hom ≫ imageToKernel f g (by simpa using w) ≫ (kernelSubobjectIsoComp i.inv g).inv := by
ext simp
/- 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`. ## 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
Mathlib/Order/Directed.lean
58
60
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]
/- Copyright (c) 2023 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Topology.Bases import Mathlib.Order.Filter.CountableInter import Mathlib.Topology.Compactness.SigmaCompact /-! # Lindelöf sets and Lindelöf spaces ## Main definitions We define the following properties for sets in a topological space: * `IsLindelof s`: Two definitions are possible here. The more standard definition is that every open cover that contains `s` contains a countable subcover. We choose for the equivalent definition where we require that every nontrivial filter on `s` with the countable intersection property has a clusterpoint. Equivalence is established in `isLindelof_iff_countable_subcover`. * `LindelofSpace X`: `X` is Lindelöf if it is Lindelöf as a set. * `NonLindelofSpace`: a space that is not a Lindëlof space, e.g. the Long Line. ## Main results * `isLindelof_iff_countable_subcover`: A set is Lindelöf iff every open cover has a countable subcover. ## Implementation details * This API is mainly based on the API for IsCompact and follows notation and style as much as possible. -/ open Set Filter Topology TopologicalSpace universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} section Lindelof /-- A set `s` is Lindelöf if every nontrivial filter `f` with the countable intersection property that contains `s`, has a clusterpoint in `s`. The filter-free definition is given by `isLindelof_iff_countable_subcover`. -/ def IsLindelof (s : Set X) := ∀ ⦃f⦄ [NeBot f] [CountableInterFilter f], f ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x f /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/ theorem IsLindelof.compl_mem_sets (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) : sᶜ ∈ f := by contrapose! hf simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢ exact hs inf_le_right /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ theorem IsLindelof.compl_mem_sets_of_nhdsWithin (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by refine hs.compl_mem_sets fun x hx ↦ ?_ rw [← disjoint_principal_right, disjoint_right_comm, (basis_sets _).disjoint_iff_left] exact hf x hx /-- If `p : Set X → Prop` is stable under restriction and union, and each point `x` of a Lindelöf set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsLindelof.induction_on (hs : IsLindelof s) {p : Set X → Prop} (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, p s) → p (⋃₀ S)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := ofCountableUnion p hcountable_union (fun t ht _ hsub ↦ hmono hsub ht) have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] /-- The intersection of a Lindelöf set and a closed set is a Lindelöf set. -/ theorem IsLindelof.inter_right (hs : IsLindelof s) (ht : IsClosed t) : IsLindelof (s ∩ t) := by intro f hnf _ hstf rw [← inf_principal, le_inf_iff] at hstf obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs hstf.1 have hxt : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono hstf.2 exact ⟨x, ⟨hsx, hxt⟩, hx⟩ /-- The intersection of a closed set and a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.inter_left (ht : IsLindelof t) (hs : IsClosed s) : IsLindelof (s ∩ t) := inter_comm t s ▸ ht.inter_right hs /-- The set difference of a Lindelöf set and an open set is a Lindelöf set. -/ theorem IsLindelof.diff (hs : IsLindelof s) (ht : IsOpen t) : IsLindelof (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) /-- A closed subset of a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.of_isClosed_subset (hs : IsLindelof s) (ht : IsClosed t) (h : t ⊆ s) : IsLindelof t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht /-- A continuous image of a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.image_of_continuousOn {f : X → Y} (hs : IsLindelof s) (hf : ContinuousOn f s) : IsLindelof (f '' s) := by intro l lne _ ls have : NeBot (l.comap f ⊓ 𝓟 s) := comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls) obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this _ inf_le_right haveI := hx.neBot use f x, mem_image_of_mem f hxs have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1 rw [nhdsWithin] ac_rfl exact this.neBot /-- A continuous image of a Lindelöf set is a Lindelöf set within the codomain. -/ theorem IsLindelof.image {f : X → Y} (hs : IsLindelof s) (hf : Continuous f) : IsLindelof (f '' s) := hs.image_of_continuousOn hf.continuousOn /-- A filter with the countable intersection property that is finer than the principal filter on a Lindelöf set `s` contains any open set that contains all clusterpoints of `s`. -/ theorem IsLindelof.adherence_nhdset {f : Filter X} [CountableInterFilter f] (hs : IsLindelof s) (hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f := (eq_or_neBot _).casesOn mem_of_eq_bot fun _ ↦ let ⟨x, hx, hfx⟩ := @hs (f ⊓ 𝓟 tᶜ) _ _ <| inf_le_of_left_le hf₂ have : x ∈ t := ht₂ x hx hfx.of_inf_left have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (ht₁.mem_nhds this) have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne absurd A this /-- For every open cover of a Lindelöf set, there exists a countable subcover. -/ theorem IsLindelof.elim_countable_subcover {ι : Type v} (hs : IsLindelof s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i) := by have hmono : ∀ ⦃s t : Set X⦄, s ⊆ t → (∃ r : Set ι, r.Countable ∧ t ⊆ ⋃ i ∈ r, U i) → (∃ r : Set ι, r.Countable ∧ s ⊆ ⋃ i ∈ r, U i) := by intro _ _ hst ⟨r, ⟨hrcountable, hsub⟩⟩ exact ⟨r, hrcountable, Subset.trans hst hsub⟩ have hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i)) → ∃ r : Set ι, r.Countable ∧ (⋃₀ S ⊆ ⋃ i ∈ r, U i) := by intro S hS hsr choose! r hr using hsr refine ⟨⋃ s ∈ S, r s, hS.biUnion_iff.mpr (fun s hs ↦ (hr s hs).1), ?_⟩ refine sUnion_subset ?h.right.h simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and'] exact fun i is x hx ↦ mem_biUnion is ((hr i is).2 hx) have h_nhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∃ r : Set ι, r.Countable ∧ (t ⊆ ⋃ i ∈ r, U i) := by intro x hx let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) refine ⟨U i, mem_nhdsWithin_of_mem_nhds ((hUo i).mem_nhds hi), {i}, by simp, ?_⟩ simp only [mem_singleton_iff, iUnion_iUnion_eq_left] exact Subset.refl _ exact hs.induction_on hmono hcountable_union h_nhds theorem IsLindelof.elim_nhds_subcover' (hs : IsLindelof s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Set s, t.Countable ∧ s ⊆ ⋃ x ∈ t, U (x : s) x.2 := by have := hs.elim_countable_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior) fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ rcases this with ⟨r, ⟨hr, hs⟩⟩ use r, hr apply Subset.trans hs apply iUnion₂_subset intro i hi apply Subset.trans interior_subset exact subset_iUnion_of_subset i (subset_iUnion_of_subset hi (Subset.refl _)) theorem IsLindelof.elim_nhds_subcover (hs : IsLindelof s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Set X, t.Countable ∧ (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := by let ⟨t, ⟨htc, htsub⟩⟩ := hs.elim_nhds_subcover' (fun x _ ↦ U x) hU refine ⟨↑t, Countable.image htc Subtype.val, ?_⟩ constructor · intro _ simp only [mem_image, Subtype.exists, exists_and_right, exists_eq_right, forall_exists_index] tauto · have : ⋃ x ∈ t, U ↑x = ⋃ x ∈ Subtype.val '' t, U x := biUnion_image.symm rwa [← this] /-- For every nonempty open cover of a Lindelöf set, there exists a subcover indexed by ℕ. -/ theorem IsLindelof.indexed_countable_subcover {ι : Type v} [Nonempty ι] (hs : IsLindelof s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ f : ℕ → ι, s ⊆ ⋃ n, U (f n) := by obtain ⟨c, ⟨c_count, c_cov⟩⟩ := hs.elim_countable_subcover U hUo hsU rcases c.eq_empty_or_nonempty with rfl | c_nonempty · simp only [mem_empty_iff_false, iUnion_of_empty, iUnion_empty] at c_cov simp only [subset_eq_empty c_cov rfl, empty_subset, exists_const] obtain ⟨f, f_surj⟩ := (Set.countable_iff_exists_surjective c_nonempty).mp c_count refine ⟨fun x ↦ f x, c_cov.trans <| iUnion₂_subset_iff.mpr (?_ : ∀ i ∈ c, U i ⊆ ⋃ n, U (f n))⟩ intro x hx obtain ⟨n, hn⟩ := f_surj ⟨x, hx⟩ exact subset_iUnion_of_subset n <| subset_of_eq (by rw [hn]) /-- The neighborhood filter of a Lindelöf set is disjoint with a filter `l` with the countable intersection property if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/ theorem IsLindelof.disjoint_nhdsSet_left {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by refine ⟨fun h x hx ↦ h.mono_left <| nhds_le_nhdsSet hx, fun H ↦ ?_⟩ choose! U hxU hUl using fun x hx ↦ (nhds_basis_opens x).disjoint_iff_left.1 (H x hx) choose hxU hUo using hxU rcases hs.elim_nhds_subcover U fun x hx ↦ (hUo x hx).mem_nhds (hxU x hx) with ⟨t, htc, hts, hst⟩ refine (hasBasis_nhdsSet _).disjoint_iff_left.2 ⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx ↦ hUo x (hts x hx), hst⟩, ?_⟩ rw [compl_iUnion₂] exact (countable_bInter_mem htc).mpr (fun i hi ↦ hUl _ (hts _ hi)) /-- A filter `l` with the countable intersection property is disjoint with the neighborhood filter of a Lindelöf set if and only if it is disjoint with the neighborhood filter of each point of this set. -/ theorem IsLindelof.disjoint_nhdsSet_right {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left /-- For every family of closed sets whose intersection avoids a Lindelö set, there exists a countable subfamily whose intersection avoids this Lindelöf set. -/ theorem IsLindelof.elim_countable_subfamily_closed {ι : Type v} (hs : IsLindelof s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) : ∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅ := by let U := tᶜ have hUo : ∀ i, IsOpen (U i) := by simp only [U, Pi.compl_apply, isOpen_compl_iff]; exact htc have hsU : s ⊆ ⋃ i, U i := by simp only [U, Pi.compl_apply] rw [← compl_iInter] apply disjoint_compl_left_iff_subset.mp simp only [compl_iInter, compl_iUnion, compl_compl] apply Disjoint.symm exact disjoint_iff_inter_eq_empty.mpr hst rcases hs.elim_countable_subcover U hUo hsU with ⟨u, ⟨hucount, husub⟩⟩ use u, hucount rw [← disjoint_compl_left_iff_subset] at husub simp only [U, Pi.compl_apply, compl_iUnion, compl_compl] at husub exact disjoint_iff_inter_eq_empty.mp (Disjoint.symm husub) /-- To show that a Lindelöf set intersects the intersection of a family of closed sets, it is sufficient to show that it intersects every countable subfamily. -/ theorem IsLindelof.inter_iInter_nonempty {ι : Type v} (hs : IsLindelof s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i).Nonempty) : (s ∩ ⋂ i, t i).Nonempty := by contrapose! hst rcases hs.elim_countable_subfamily_closed t htc hst with ⟨u, ⟨_, husub⟩⟩ exact ⟨u, fun _ ↦ husub⟩ /-- For every open cover of a Lindelöf set, there exists a countable subcover. -/ theorem IsLindelof.elim_countable_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsLindelof s) (hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) : ∃ b', b' ⊆ b ∧ Set.Countable b' ∧ s ⊆ ⋃ i ∈ b', c i := by simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂ rcases hs.elim_countable_subcover (fun i ↦ c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩ refine ⟨Subtype.val '' d, by simp, Countable.image hd.1 Subtype.val, ?_⟩ rw [biUnion_image] exact hd.2 /-- A set `s` is Lindelöf if for every open cover of `s`, there exists a countable subcover. -/ theorem isLindelof_of_countable_subcover (h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Set ι, t.Countable ∧ s ⊆ ⋃ i ∈ t, U i) : IsLindelof s := fun f hf hfs ↦ by contrapose! h simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall', (nhds_basis_opens _).disjoint_iff_left] at h choose fsub U hU hUf using h refine ⟨s, U, fun x ↦ (hU x).2, fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1 ⟩, ?_⟩ intro t ht h have uinf := f.sets_of_superset (le_principal_iff.1 fsub) h have uninf : ⋂ i ∈ t, (U i)ᶜ ∈ f := (countable_bInter_mem ht).mpr (fun _ _ ↦ hUf _) rw [← compl_iUnion₂] at uninf have uninf := compl_not_mem uninf simp only [compl_compl] at uninf contradiction /-- A set `s` is Lindelöf if for every family of closed sets whose intersection avoids `s`, there exists a countable subfamily whose intersection avoids `s`. -/ theorem isLindelof_of_countable_subfamily_closed (h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅) : IsLindelof s := isLindelof_of_countable_subcover fun U hUo hsU ↦ by rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU rcases h (fun i ↦ (U i)ᶜ) (fun i ↦ (hUo _).isClosed_compl) hsU with ⟨t, ht⟩ refine ⟨t, ?_⟩ rwa [← disjoint_compl_right_iff_subset, compl_iUnion₂, disjoint_iff] /-- A set `s` is Lindelöf if and only if for every open cover of `s`, there exists a countable subcover. -/ theorem isLindelof_iff_countable_subcover : IsLindelof s ↔ ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Set ι, t.Countable ∧ s ⊆ ⋃ i ∈ t, U i := ⟨fun hs ↦ hs.elim_countable_subcover, isLindelof_of_countable_subcover⟩ /-- A set `s` is Lindelöf if and only if for every family of closed sets whose intersection avoids `s`, there exists a countable subfamily whose intersection avoids `s`. -/ theorem isLindelof_iff_countable_subfamily_closed : IsLindelof s ↔ ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅ := ⟨fun hs ↦ hs.elim_countable_subfamily_closed, isLindelof_of_countable_subfamily_closed⟩ /-- The empty set is a Lindelof set. -/ @[simp] theorem isLindelof_empty : IsLindelof (∅ : Set X) := fun _f hnf _ hsf ↦ Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf /-- A singleton set is a Lindelof set. -/ @[simp] theorem isLindelof_singleton {x : X} : IsLindelof ({x} : Set X) := fun _ hf _ hfa ↦ ⟨x, rfl, ClusterPt.of_le_nhds' (hfa.trans <| by simpa only [principal_singleton] using pure_le_nhds x) hf⟩ theorem Set.Subsingleton.isLindelof (hs : s.Subsingleton) : IsLindelof s := Subsingleton.induction_on hs isLindelof_empty fun _ ↦ isLindelof_singleton theorem Set.Countable.isLindelof_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Countable) (hf : ∀ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := by apply isLindelof_of_countable_subcover intro i U hU hUcover have hiU : ∀ i ∈ s, f i ⊆ ⋃ i, U i := fun _ is ↦ _root_.subset_trans (subset_biUnion_of_mem is) hUcover have iSets := fun i is ↦ (hf i is).elim_countable_subcover U hU (hiU i is) choose! r hr using iSets use ⋃ i ∈ s, r i constructor · refine (Countable.biUnion_iff hs).mpr ?h.left.a exact fun s hs ↦ (hr s hs).1 · refine iUnion₂_subset ?h.right.h intro i is simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and'] intro x hx exact mem_biUnion is ((hr i is).2 hx) theorem Set.Finite.isLindelof_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Finite) (hf : ∀ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := Set.Countable.isLindelof_biUnion (countable hs) hf theorem Finset.isLindelof_biUnion (s : Finset ι) {f : ι → Set X} (hf : ∀ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := s.finite_toSet.isLindelof_biUnion hf theorem isLindelof_accumulate {K : ℕ → Set X} (hK : ∀ n, IsLindelof (K n)) (n : ℕ) : IsLindelof (Accumulate K n) := (finite_le_nat n).isLindelof_biUnion fun k _ => hK k theorem Set.Countable.isLindelof_sUnion {S : Set (Set X)} (hf : S.Countable) (hc : ∀ s ∈ S, IsLindelof s) : IsLindelof (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isLindelof_biUnion hc theorem Set.Finite.isLindelof_sUnion {S : Set (Set X)} (hf : S.Finite) (hc : ∀ s ∈ S, IsLindelof s) : IsLindelof (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isLindelof_biUnion hc theorem isLindelof_iUnion {ι : Sort*} {f : ι → Set X} [Countable ι] (h : ∀ i, IsLindelof (f i)) : IsLindelof (⋃ i, f i) := (countable_range f).isLindelof_sUnion <| forall_mem_range.2 h theorem Set.Countable.isLindelof (hs : s.Countable) : IsLindelof s := biUnion_of_singleton s ▸ hs.isLindelof_biUnion fun _ _ => isLindelof_singleton theorem Set.Finite.isLindelof (hs : s.Finite) : IsLindelof s := biUnion_of_singleton s ▸ hs.isLindelof_biUnion fun _ _ => isLindelof_singleton theorem IsLindelof.countable_of_discrete [DiscreteTopology X] (hs : IsLindelof s) : s.Countable := by have : ∀ x : X, ({x} : Set X) ∈ 𝓝 x := by simp [nhds_discrete] rcases hs.elim_nhds_subcover (fun x => {x}) fun x _ => this x with ⟨t, ht, _, hssubt⟩ rw [biUnion_of_singleton] at hssubt exact ht.mono hssubt theorem isLindelof_iff_countable [DiscreteTopology X] : IsLindelof s ↔ s.Countable := ⟨fun h => h.countable_of_discrete, fun h => h.isLindelof⟩ theorem IsLindelof.union (hs : IsLindelof s) (ht : IsLindelof t) : IsLindelof (s ∪ t) := by rw [union_eq_iUnion]; exact isLindelof_iUnion fun b => by cases b <;> assumption protected theorem IsLindelof.insert (hs : IsLindelof s) (a) : IsLindelof (insert a s) := isLindelof_singleton.union hs /-- If `X` has a basis consisting of compact opens, then an open set in `X` is compact open iff it is a finite union of some elements in the basis -/
Mathlib/Topology/Compactness/Lindelof.lean
382
406
theorem isLindelof_open_iff_eq_countable_iUnion_of_isTopologicalBasis (b : ι → Set X) (hb : IsTopologicalBasis (Set.range b)) (hb' : ∀ i, IsLindelof (b i)) (U : Set X) : IsLindelof U ∧ IsOpen U ↔ ∃ s : Set ι, s.Countable ∧ U = ⋃ i ∈ s, b i := by
constructor · rintro ⟨h₁, h₂⟩ obtain ⟨Y, f, rfl, hf⟩ := hb.open_eq_iUnion h₂ choose f' hf' using hf have : b ∘ f' = f := funext hf' subst this obtain ⟨t, ht⟩ := h₁.elim_countable_subcover (b ∘ f') (fun i => hb.isOpen (Set.mem_range_self _)) Subset.rfl refine ⟨t.image f', Countable.image (ht.1) f', le_antisymm ?_ ?_⟩ · refine Set.Subset.trans ht.2 ?_ simp only [Set.iUnion_subset_iff] intro i hi rw [← Set.iUnion_subtype (fun x : ι => x ∈ t.image f') fun i => b i.1] exact Set.subset_iUnion (fun i : t.image f' => b i) ⟨_, mem_image_of_mem _ hi⟩ · apply Set.iUnion₂_subset rintro i hi obtain ⟨j, -, rfl⟩ := (mem_image ..).mp hi exact Set.subset_iUnion (b ∘ f') j · rintro ⟨s, hs, rfl⟩ constructor · exact hs.isLindelof_biUnion fun i _ => hb' i · exact isOpen_biUnion fun i _ => hb.isOpen (Set.mem_range_self _)
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Ring.InjSurj import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Ring.Hom.Defs /-! # Units in semirings and rings -/ universe u v w x variable {α : Type u} {β : Type v} {R : Type x} open Function namespace Units section HasDistribNeg variable [Monoid α] [HasDistribNeg α] /-- Each element of the group of units of a ring has an additive inverse. -/ instance : Neg αˣ := ⟨fun u => ⟨-↑u, -↑u⁻¹, by simp, by simp⟩⟩ /-- Representing an element of a ring's unit group as an element of the ring commutes with mapping this element to its additive inverse. -/ @[simp, norm_cast] protected theorem val_neg (u : αˣ) : (↑(-u) : α) = -u := rfl @[simp, norm_cast] protected theorem coe_neg_one : ((-1 : αˣ) : α) = -1 := rfl instance : HasDistribNeg αˣ := Units.ext.hasDistribNeg _ Units.val_neg Units.val_mul @[field_simps] theorem neg_divp (a : α) (u : αˣ) : -(a /ₚ u) = -a /ₚ u := by simp only [divp, neg_mul] end HasDistribNeg section Ring variable [Ring α] -- Needs to have higher simp priority than divp_add_divp. 1000 is the default priority. @[field_simps 1010] theorem divp_add_divp_same (a b : α) (u : αˣ) : a /ₚ u + b /ₚ u = (a + b) /ₚ u := by simp only [divp, add_mul] -- Needs to have higher simp priority than divp_sub_divp. 1000 is the default priority. @[field_simps 1010] theorem divp_sub_divp_same (a b : α) (u : αˣ) : a /ₚ u - b /ₚ u = (a - b) /ₚ u := by rw [sub_eq_add_neg, sub_eq_add_neg, neg_divp, divp_add_divp_same] @[field_simps] theorem add_divp (a b : α) (u : αˣ) : a + b /ₚ u = (a * u + b) /ₚ u := by simp only [divp, add_mul, Units.mul_inv_cancel_right] @[field_simps] theorem sub_divp (a b : α) (u : αˣ) : a - b /ₚ u = (a * u - b) /ₚ u := by simp only [divp, sub_mul, Units.mul_inv_cancel_right] @[field_simps] theorem divp_add (a b : α) (u : αˣ) : a /ₚ u + b = (a + b * u) /ₚ u := by simp only [divp, add_mul, Units.mul_inv_cancel_right] @[field_simps]
Mathlib/Algebra/Ring/Units.lean
77
78
theorem divp_sub (a b : α) (u : αˣ) : a /ₚ u - b = (a - b * u) /ₚ u := by
simp only [divp, sub_mul, sub_right_inj]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.Convex.Segment import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.FieldSimp /-! # Betweenness in affine spaces This file defines notions of a point in an affine space being between two given points. ## Main definitions * `affineSegment R x y`: The segment of points weakly between `x` and `y`. * `Wbtw R x y z`: The point `y` is weakly between `x` and `z`. * `Sbtw R x y z`: The point `y` is strictly between `x` and `z`. -/ variable (R : Type*) {V V' P P' : Type*} open AffineEquiv AffineMap section OrderedRing /-- The segment of points weakly between `x` and `y`. When convexity is refactored to support abstract affine combination spaces, this will no longer need to be a separate definition from `segment`. However, lemmas involving `+ᵥ` or `-ᵥ` will still be relevant after such a refactoring, as distinct from versions involving `+` or `-` in a module. -/ def affineSegment [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V] [AddTorsor V P] (x y : P) := lineMap x y '' Set.Icc (0 : R) 1 variable [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] variable {R} in @[simp] theorem affineSegment_image (f : P →ᵃ[R] P') (x y : P) : f '' affineSegment R x y = affineSegment R (f x) (f y) := by rw [affineSegment, affineSegment, Set.image_image, ← comp_lineMap] rfl @[simp] theorem affineSegment_const_vadd_image (x y : P) (v : V) : (v +ᵥ ·) '' affineSegment R x y = affineSegment R (v +ᵥ x) (v +ᵥ y) := affineSegment_image (AffineEquiv.constVAdd R P v : P →ᵃ[R] P) x y @[simp] theorem affineSegment_vadd_const_image (x y : V) (p : P) : (· +ᵥ p) '' affineSegment R x y = affineSegment R (x +ᵥ p) (y +ᵥ p) := affineSegment_image (AffineEquiv.vaddConst R p : V →ᵃ[R] P) x y @[simp] theorem affineSegment_const_vsub_image (x y p : P) : (p -ᵥ ·) '' affineSegment R x y = affineSegment R (p -ᵥ x) (p -ᵥ y) := affineSegment_image (AffineEquiv.constVSub R p : P →ᵃ[R] V) x y @[simp] theorem affineSegment_vsub_const_image (x y p : P) : (· -ᵥ p) '' affineSegment R x y = affineSegment R (x -ᵥ p) (y -ᵥ p) := affineSegment_image ((AffineEquiv.vaddConst R p).symm : P →ᵃ[R] V) x y variable {R} @[simp] theorem mem_const_vadd_affineSegment {x y z : P} (v : V) : v +ᵥ z ∈ affineSegment R (v +ᵥ x) (v +ᵥ y) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_const_vadd_image, (AddAction.injective v).mem_set_image] @[simp] theorem mem_vadd_const_affineSegment {x y z : V} (p : P) : z +ᵥ p ∈ affineSegment R (x +ᵥ p) (y +ᵥ p) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_vadd_const_image, (vadd_right_injective p).mem_set_image] @[simp] theorem mem_const_vsub_affineSegment {x y z : P} (p : P) : p -ᵥ z ∈ affineSegment R (p -ᵥ x) (p -ᵥ y) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_const_vsub_image, (vsub_right_injective p).mem_set_image] @[simp] theorem mem_vsub_const_affineSegment {x y z : P} (p : P) : z -ᵥ p ∈ affineSegment R (x -ᵥ p) (y -ᵥ p) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_vsub_const_image, (vsub_left_injective p).mem_set_image] variable (R) section OrderedRing variable [IsOrderedRing R] theorem affineSegment_eq_segment (x y : V) : affineSegment R x y = segment R x y := by rw [segment_eq_image_lineMap, affineSegment] theorem affineSegment_comm (x y : P) : affineSegment R x y = affineSegment R y x := by refine Set.ext fun z => ?_ constructor <;> · rintro ⟨t, ht, hxy⟩ refine ⟨1 - t, ?_, ?_⟩ · rwa [Set.sub_mem_Icc_iff_right, sub_self, sub_zero] · rwa [lineMap_apply_one_sub] theorem left_mem_affineSegment (x y : P) : x ∈ affineSegment R x y := ⟨0, Set.left_mem_Icc.2 zero_le_one, lineMap_apply_zero _ _⟩ theorem right_mem_affineSegment (x y : P) : y ∈ affineSegment R x y := ⟨1, Set.right_mem_Icc.2 zero_le_one, lineMap_apply_one _ _⟩ @[simp] theorem affineSegment_same (x : P) : affineSegment R x x = {x} := by simp_rw [affineSegment, lineMap_same, AffineMap.coe_const, Function.const, (Set.nonempty_Icc.mpr zero_le_one).image_const] end OrderedRing /-- The point `y` is weakly between `x` and `z`. -/ def Wbtw (x y z : P) : Prop := y ∈ affineSegment R x z /-- The point `y` is strictly between `x` and `z`. -/ def Sbtw (x y z : P) : Prop := Wbtw R x y z ∧ y ≠ x ∧ y ≠ z variable {R} section OrderedRing variable [IsOrderedRing R] lemma mem_segment_iff_wbtw {x y z : V} : y ∈ segment R x z ↔ Wbtw R x y z := by rw [Wbtw, affineSegment_eq_segment] alias ⟨_, Wbtw.mem_segment⟩ := mem_segment_iff_wbtw lemma Convex.mem_of_wbtw {p₀ p₁ p₂ : V} {s : Set V} (hs : Convex R s) (h₀₁₂ : Wbtw R p₀ p₁ p₂) (h₀ : p₀ ∈ s) (h₂ : p₂ ∈ s) : p₁ ∈ s := hs.segment_subset h₀ h₂ h₀₁₂.mem_segment theorem wbtw_comm {x y z : P} : Wbtw R x y z ↔ Wbtw R z y x := by rw [Wbtw, Wbtw, affineSegment_comm] alias ⟨Wbtw.symm, _⟩ := wbtw_comm theorem sbtw_comm {x y z : P} : Sbtw R x y z ↔ Sbtw R z y x := by rw [Sbtw, Sbtw, wbtw_comm, ← and_assoc, ← and_assoc, and_right_comm] alias ⟨Sbtw.symm, _⟩ := sbtw_comm end OrderedRing lemma AffineSubspace.mem_of_wbtw {s : AffineSubspace R P} {x y z : P} (hxyz : Wbtw R x y z) (hx : x ∈ s) (hz : z ∈ s) : y ∈ s := by obtain ⟨ε, -, rfl⟩ := hxyz; exact lineMap_mem _ hx hz theorem Wbtw.map {x y z : P} (h : Wbtw R x y z) (f : P →ᵃ[R] P') : Wbtw R (f x) (f y) (f z) := by rw [Wbtw, ← affineSegment_image] exact Set.mem_image_of_mem _ h theorem Function.Injective.wbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by refine ⟨fun h => ?_, fun h => h.map _⟩ rwa [Wbtw, ← affineSegment_image, hf.mem_set_image] at h theorem Function.Injective.sbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by simp_rw [Sbtw, hf.wbtw_map_iff, hf.ne_iff] @[simp] theorem AffineEquiv.wbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') : Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by have : Function.Injective f.toAffineMap := f.injective -- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing. apply this.wbtw_map_iff @[simp] theorem AffineEquiv.sbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') : Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by have : Function.Injective f.toAffineMap := f.injective -- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing. apply this.sbtw_map_iff @[simp] theorem wbtw_const_vadd_iff {x y z : P} (v : V) : Wbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Wbtw R x y z := mem_const_vadd_affineSegment _ @[simp] theorem wbtw_vadd_const_iff {x y z : V} (p : P) : Wbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Wbtw R x y z := mem_vadd_const_affineSegment _ @[simp] theorem wbtw_const_vsub_iff {x y z : P} (p : P) : Wbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Wbtw R x y z := mem_const_vsub_affineSegment _ @[simp] theorem wbtw_vsub_const_iff {x y z : P} (p : P) : Wbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Wbtw R x y z := mem_vsub_const_affineSegment _ @[simp] theorem sbtw_const_vadd_iff {x y z : P} (v : V) : Sbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_const_vadd_iff, (AddAction.injective v).ne_iff, (AddAction.injective v).ne_iff] @[simp] theorem sbtw_vadd_const_iff {x y z : V} (p : P) : Sbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_vadd_const_iff, (vadd_right_injective p).ne_iff, (vadd_right_injective p).ne_iff] @[simp]
Mathlib/Analysis/Convex/Between.lean
219
222
theorem sbtw_const_vsub_iff {x y z : P} (p : P) : Sbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_const_vsub_iff, (vsub_right_injective p).ne_iff, (vsub_right_injective p).ne_iff]
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Order.Interval.Set.IsoIoo import Mathlib.Topology.ContinuousMap.Bounded.Normed import Mathlib.Topology.UrysohnsBounded /-! # Tietze extension theorem In this file we prove a few version of the Tietze extension theorem. The theorem says that a continuous function `s → ℝ` defined on a closed set in a normal topological space `Y` can be extended to a continuous function on the whole space. Moreover, if all values of the original function belong to some (finite or infinite, open or closed) interval, then the extension can be chosen so that it takes values in the same interval. In particular, if the original function is a bounded function, then there exists a bounded extension of the same norm. The proof mostly follows <https://ncatlab.org/nlab/show/Tietze+extension+theorem>. We patch a small gap in the proof for unbounded functions, see `exists_extension_forall_exists_le_ge_of_isClosedEmbedding`. In addition we provide a class `TietzeExtension` encoding the idea that a topological space satisfies the Tietze extension theorem. This allows us to get a version of the Tietze extension theorem that simultaneously applies to `ℝ`, `ℝ × ℝ`, `ℂ`, `ι → ℝ`, `ℝ≥0` et cetera. At some point in the future, it may be desirable to provide instead a more general approach via *absolute retracts*, but the current implementation covers the most common use cases easily. ## Implementation notes We first prove the theorems for a closed embedding `e : X → Y` of a topological space into a normal topological space, then specialize them to the case `X = s : Set Y`, `e = (↑)`. ## Tags Tietze extension theorem, Urysohn's lemma, normal topological space -/ open Topology /-! ### The `TietzeExtension` class -/ section TietzeExtensionClass universe u u₁ u₂ v w -- TODO: define *absolute retracts* and then prove they satisfy Tietze extension. -- Then make instances of that instead and remove this class. /-- A class encoding the concept that a space satisfies the Tietze extension property. -/ class TietzeExtension (Y : Type v) [TopologicalSpace Y] : Prop where exists_restrict_eq' {X : Type u} [TopologicalSpace X] [NormalSpace X] (s : Set X) (hs : IsClosed s) (f : C(s, Y)) : ∃ (g : C(X, Y)), g.restrict s = f variable {X₁ : Type u₁} [TopologicalSpace X₁] variable {X : Type u} [TopologicalSpace X] [NormalSpace X] {s : Set X} variable {e : X₁ → X} variable {Y : Type v} [TopologicalSpace Y] [TietzeExtension.{u, v} Y] /-- **Tietze extension theorem** for `TietzeExtension` spaces, a version for a closed set. Let `s` be a closed set in a normal topological space `X`. Let `f` be a continuous function on `s` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g.restrict s = f`. -/ theorem ContinuousMap.exists_restrict_eq (hs : IsClosed s) (f : C(s, Y)) : ∃ (g : C(X, Y)), g.restrict s = f := TietzeExtension.exists_restrict_eq' s hs f /-- **Tietze extension theorem** for `TietzeExtension` spaces. Let `e` be a closed embedding of a nonempty topological space `X₁` into a normal topological space `X`. Let `f` be a continuous function on `X₁` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g ∘ e = f`. -/ theorem ContinuousMap.exists_extension (he : IsClosedEmbedding e) (f : C(X₁, Y)) : ∃ (g : C(X, Y)), g.comp ⟨e, he.continuous⟩ = f := by let e' : X₁ ≃ₜ Set.range e := he.isEmbedding.toHomeomorph obtain ⟨g, hg⟩ := (f.comp e'.symm).exists_restrict_eq he.isClosed_range exact ⟨g, by ext x; simpa using congr($(hg) ⟨e' x, x, rfl⟩)⟩ /-- **Tietze extension theorem** for `TietzeExtension` spaces. Let `e` be a closed embedding of a nonempty topological space `X₁` into a normal topological space `X`. Let `f` be a continuous function on `X₁` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g ∘ e = f`. This version is provided for convenience and backwards compatibility. Here the composition is phrased in terms of bare functions. -/ theorem ContinuousMap.exists_extension' (he : IsClosedEmbedding e) (f : C(X₁, Y)) : ∃ (g : C(X, Y)), g ∘ e = f := f.exists_extension he |>.imp fun g hg ↦ by ext x; congrm($(hg) x) /-- This theorem is not intended to be used directly because it is rare for a set alone to satisfy `[TietzeExtension t]`. For example, `Metric.ball` in `ℝ` only satisfies it when the radius is strictly positive, so finding this as an instance will fail. Instead, it is intended to be used as a constructor for theorems about sets which *do* satisfy `[TietzeExtension t]` under some hypotheses. -/ theorem ContinuousMap.exists_forall_mem_restrict_eq (hs : IsClosed s) {Y : Type v} [TopologicalSpace Y] (f : C(s, Y)) {t : Set Y} (hf : ∀ x, f x ∈ t) [ht : TietzeExtension.{u, v} t] : ∃ (g : C(X, Y)), (∀ x, g x ∈ t) ∧ g.restrict s = f := by obtain ⟨g, hg⟩ := mk _ (map_continuous f |>.codRestrict hf) |>.exists_restrict_eq hs exact ⟨comp ⟨Subtype.val, by continuity⟩ g, by simp, by ext x; congrm(($(hg) x : Y))⟩ /-- This theorem is not intended to be used directly because it is rare for a set alone to satisfy `[TietzeExtension t]`. For example, `Metric.ball` in `ℝ` only satisfies it when the radius is strictly positive, so finding this as an instance will fail. Instead, it is intended to be used as a constructor for theorems about sets which *do* satisfy `[TietzeExtension t]` under some hypotheses. -/ theorem ContinuousMap.exists_extension_forall_mem (he : IsClosedEmbedding e) {Y : Type v} [TopologicalSpace Y] (f : C(X₁, Y)) {t : Set Y} (hf : ∀ x, f x ∈ t) [ht : TietzeExtension.{u, v} t] : ∃ (g : C(X, Y)), (∀ x, g x ∈ t) ∧ g.comp ⟨e, he.continuous⟩ = f := by obtain ⟨g, hg⟩ := mk _ (map_continuous f |>.codRestrict hf) |>.exists_extension he exact ⟨comp ⟨Subtype.val, by continuity⟩ g, by simp, by ext x; congrm(($(hg) x : Y))⟩ instance Pi.instTietzeExtension {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)] [∀ i, TietzeExtension.{u} (Y i)] : TietzeExtension.{u} (∀ i, Y i) where exists_restrict_eq' s hs f := by obtain ⟨g', hg'⟩ := Classical.skolem.mp <| fun i ↦ ContinuousMap.exists_restrict_eq hs (ContinuousMap.piEquiv _ _ |>.symm f i) exact ⟨ContinuousMap.piEquiv _ _ g', by ext x i; congrm($(hg' i) x)⟩ instance Prod.instTietzeExtension {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TietzeExtension.{u, v} Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] : TietzeExtension.{u, max w v} (Y × Z) where exists_restrict_eq' s hs f := by obtain ⟨g₁, hg₁⟩ := (ContinuousMap.fst.comp f).exists_restrict_eq hs obtain ⟨g₂, hg₂⟩ := (ContinuousMap.snd.comp f).exists_restrict_eq hs exact ⟨g₁.prodMk g₂, by ext1 x; congrm(($(hg₁) x), $(hg₂) x)⟩ instance Unique.instTietzeExtension {Y : Type v} [TopologicalSpace Y] [Nonempty Y] [Subsingleton Y] : TietzeExtension.{u, v} Y where exists_restrict_eq' _ _ f := ‹Nonempty Y›.elim fun y ↦ ⟨.const _ y, by ext; subsingleton⟩ /-- Any retract of a `TietzeExtension` space is one itself. -/ theorem TietzeExtension.of_retract {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] (ι : C(Y, Z)) (r : C(Z, Y)) (h : r.comp ι = .id Y) : TietzeExtension.{u, v} Y where exists_restrict_eq' s hs f := by obtain ⟨g, hg⟩ := (ι.comp f).exists_restrict_eq hs use r.comp g ext1 x have := congr(r.comp $(hg)) rw [← r.comp_assoc ι, h, f.id_comp] at this congrm($this x) /-- Any homeomorphism from a `TietzeExtension` space is one itself. -/ theorem TietzeExtension.of_homeo {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] (e : Y ≃ₜ Z) : TietzeExtension.{u, v} Y := .of_retract (e : C(Y, Z)) (e.symm : C(Z, Y)) <| by simp end TietzeExtensionClass /-! The Tietze extension theorem for `ℝ`. -/ variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [NormalSpace Y] open Metric Set Filter open BoundedContinuousFunction Topology noncomputable section namespace BoundedContinuousFunction /-- One step in the proof of the Tietze extension theorem. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the norm `‖g‖ ≤ ‖f‖ / 3` such that the distance between `g ∘ e` and `f` is at most `(2 / 3) * ‖f‖`. -/ theorem tietze_extension_step (f : X →ᵇ ℝ) (e : C(X, Y)) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, ‖g‖ ≤ ‖f‖ / 3 ∧ dist (g.compContinuous e) f ≤ 2 / 3 * ‖f‖ := by have h3 : (0 : ℝ) < 3 := by norm_num1 have h23 : 0 < (2 / 3 : ℝ) := by norm_num1 -- In the trivial case `f = 0`, we take `g = 0` rcases eq_or_ne f 0 with (rfl | hf) · use 0 simp replace hf : 0 < ‖f‖ := norm_pos_iff.2 hf /- Otherwise, the closed sets `e '' (f ⁻¹' (Iic (-‖f‖ / 3)))` and `e '' (f ⁻¹' (Ici (‖f‖ / 3)))` are disjoint, hence by Urysohn's lemma there exists a function `g` that is equal to `-‖f‖ / 3` on the former set and is equal to `‖f‖ / 3` on the latter set. This function `g` satisfies the assertions of the lemma. -/ have hf3 : -‖f‖ / 3 < ‖f‖ / 3 := (div_lt_div_iff_of_pos_right h3).2 (Left.neg_lt_self hf) have hc₁ : IsClosed (e '' (f ⁻¹' Iic (-‖f‖ / 3))) := he.isClosedMap _ (isClosed_Iic.preimage f.continuous) have hc₂ : IsClosed (e '' (f ⁻¹' Ici (‖f‖ / 3))) := he.isClosedMap _ (isClosed_Ici.preimage f.continuous) have hd : Disjoint (e '' (f ⁻¹' Iic (-‖f‖ / 3))) (e '' (f ⁻¹' Ici (‖f‖ / 3))) := by refine disjoint_image_of_injective he.injective (Disjoint.preimage _ ?_) rwa [Iic_disjoint_Ici, not_le] rcases exists_bounded_mem_Icc_of_closed_of_le hc₁ hc₂ hd hf3.le with ⟨g, hg₁, hg₂, hgf⟩ refine ⟨g, ?_, ?_⟩ · refine (norm_le <| div_nonneg hf.le h3.le).mpr fun y => ?_ simpa [abs_le, neg_div] using hgf y · refine (dist_le <| mul_nonneg h23.le hf.le).mpr fun x => ?_ have hfx : -‖f‖ ≤ f x ∧ f x ≤ ‖f‖ := by simpa only [Real.norm_eq_abs, abs_le] using f.norm_coe_le_norm x rcases le_total (f x) (-‖f‖ / 3) with hle₁ | hle₁ · calc |g (e x) - f x| = -‖f‖ / 3 - f x := by rw [hg₁ (mem_image_of_mem _ hle₁), Function.const_apply, abs_of_nonneg (sub_nonneg.2 hle₁)] _ ≤ 2 / 3 * ‖f‖ := by linarith · rcases le_total (f x) (‖f‖ / 3) with hle₂ | hle₂ · simp only [neg_div] at * calc dist (g (e x)) (f x) ≤ |g (e x)| + |f x| := dist_le_norm_add_norm _ _ _ ≤ ‖f‖ / 3 + ‖f‖ / 3 := (add_le_add (abs_le.2 <| hgf _) (abs_le.2 ⟨hle₁, hle₂⟩)) _ = 2 / 3 * ‖f‖ := by linarith · calc |g (e x) - f x| = f x - ‖f‖ / 3 := by rw [hg₂ (mem_image_of_mem _ hle₂), abs_sub_comm, Function.const_apply, abs_of_nonneg (sub_nonneg.2 hle₂)] _ ≤ 2 / 3 * ‖f‖ := by linarith /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version with a closed embedding and bundled composition. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the same norm such that `g ∘ e = f`. -/
Mathlib/Topology/TietzeExtension.lean
220
262
theorem exists_extension_norm_eq_of_isClosedEmbedding' (f : X →ᵇ ℝ) (e : C(X, Y)) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, ‖g‖ = ‖f‖ ∧ g.compContinuous e = f := by
/- For the proof, we iterate `tietze_extension_step`. Each time we apply it to the difference between the previous approximation and `f`. -/ choose F hF_norm hF_dist using fun f : X →ᵇ ℝ => tietze_extension_step f e he set g : ℕ → Y →ᵇ ℝ := fun n => (fun g => g + F (f - g.compContinuous e))^[n] 0 have g0 : g 0 = 0 := rfl have g_succ : ∀ n, g (n + 1) = g n + F (f - (g n).compContinuous e) := fun n => Function.iterate_succ_apply' _ _ _ have hgf : ∀ n, dist ((g n).compContinuous e) f ≤ (2 / 3) ^ n * ‖f‖ := by intro n induction n with | zero => simp [g0] | succ n ihn => rw [g_succ n, add_compContinuous, ← dist_sub_right, add_sub_cancel_left, pow_succ', mul_assoc] refine (hF_dist _).trans (mul_le_mul_of_nonneg_left ?_ (by norm_num1)) rwa [← dist_eq_norm'] have hg_dist : ∀ n, dist (g n) (g (n + 1)) ≤ 1 / 3 * ‖f‖ * (2 / 3) ^ n := by intro n calc dist (g n) (g (n + 1)) = ‖F (f - (g n).compContinuous e)‖ := by rw [g_succ, dist_eq_norm', add_sub_cancel_left] _ ≤ ‖f - (g n).compContinuous e‖ / 3 := hF_norm _ _ = 1 / 3 * dist ((g n).compContinuous e) f := by rw [dist_eq_norm', one_div, div_eq_inv_mul] _ ≤ 1 / 3 * ((2 / 3) ^ n * ‖f‖) := mul_le_mul_of_nonneg_left (hgf n) (by norm_num1) _ = 1 / 3 * ‖f‖ * (2 / 3) ^ n := by ac_rfl have hg_cau : CauchySeq g := cauchySeq_of_le_geometric _ _ (by norm_num1) hg_dist have : Tendsto (fun n => (g n).compContinuous e) atTop (𝓝 <| (limUnder atTop g).compContinuous e) := ((continuous_compContinuous e).tendsto _).comp hg_cau.tendsto_limUnder have hge : (limUnder atTop g).compContinuous e = f := by refine tendsto_nhds_unique this (tendsto_iff_dist_tendsto_zero.2 ?_) refine squeeze_zero (fun _ => dist_nonneg) hgf ?_ rw [← zero_mul ‖f‖] refine (tendsto_pow_atTop_nhds_zero_of_lt_one ?_ ?_).mul tendsto_const_nhds <;> norm_num1 refine ⟨limUnder atTop g, le_antisymm ?_ ?_, hge⟩ · rw [← dist_zero_left, ← g0] refine (dist_le_of_le_geometric_of_tendsto₀ _ _ (by norm_num1) hg_dist hg_cau.tendsto_limUnder).trans_eq ?_ field_simp [show (3 - 2 : ℝ) = 1 by norm_num1] · rw [← hge]
/- 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.Tactic.ApplyFun import Mathlib.Topology.Separation.Regular import Mathlib.Topology.UniformSpace.Basic /-! # Hausdorff properties of uniform spaces. Separation quotient. Two points of a topological space are called `Inseparable`, if their neighborhoods filter are equal. Equivalently, `Inseparable x y` means that any open set that contains `x` must contain `y` and vice versa. In a uniform space, points `x` and `y` are inseparable if and only if `(x, y)` belongs to all entourages, see `inseparable_iff_ker_uniformity`. A uniform space is a regular topological space, hence separation axioms `T0Space`, `T1Space`, `T2Space`, and `T3Space` are equivalent for uniform spaces, and Lean typeclass search can automatically convert from one assumption to another. We say that a uniform space is *separated*, if it satisfies these axioms. If you need an `Iff` statement (e.g., to rewrite), then see `R1Space.t0Space_iff_t2Space` and `RegularSpace.t0Space_iff_t3Space`. In this file we prove several facts that relate `Inseparable` and `Specializes` to the uniformity filter. Most of them are simple corollaries of `Filter.HasBasis.inseparable_iff_uniformity` for different filter bases of `𝓤 α`. Then we study the Kolmogorov quotient `SeparationQuotient X` of a uniform space. For a general topological space, this quotient is defined as the quotient by `Inseparable` equivalence relation. It is the maximal T₀ quotient of a topological space. In case of a uniform space, we equip this quotient with a `UniformSpace` structure that agrees with the quotient topology. We also prove that the quotient map induces uniformity on the original space. Finally, we turn `SeparationQuotient` into a functor (not in terms of `CategoryTheory.Functor` to avoid extra imports) by defining `SeparationQuotient.lift'` and `SeparationQuotient.map` operations. ## Main definitions * `SeparationQuotient.instUniformSpace`: uniform space structure on `SeparationQuotient α`, where `α` is a uniform space; * `SeparationQuotient.lift'`: given a map `f : α → β` from a uniform space to a separated uniform space, lift it to a map `SeparationQuotient α → β`; if the original map is not uniformly continuous, then returns a constant map. * `SeparationQuotient.map`: given a map `f : α → β` between uniform spaces, returns a map `SeparationQuotient α → SeparationQuotient β`. If the original map is not uniformly continuous, then returns a constant map. Otherwise, `SeparationQuotient.map f (SeparationQuotient.mk x) = SeparationQuotient.mk (f x)`. ## Main results * `SeparationQuotient.uniformity_eq`: the uniformity filter on `SeparationQuotient α` is the push forward of the uniformity filter on `α`. * `SeparationQuotient.comap_mk_uniformity`: the quotient map `α → SeparationQuotient α` induces uniform space structure on the original space. * `SeparationQuotient.uniformContinuous_lift'`: factoring a uniformly continuous map through the separation quotient gives a uniformly continuous map. * `SeparationQuotient.uniformContinuous_map`: maps induced between separation quotients are uniformly continuous. ## Implementation notes This files used to contain definitions of `separationRel α` and `UniformSpace.SeparationQuotient α`. These definitions were equal (but not definitionally equal) to `{x : α × α | Inseparable x.1 x.2}` and `SeparationQuotient α`, respectively, and were added to the library before their geneeralizations to topological spaces. In https://github.com/leanprover-community/mathlib4/pull/10644, we migrated from these definitions to more general `Inseparable` and `SeparationQuotient`. ## TODO Definitions `SeparationQuotient.lift'` and `SeparationQuotient.map` rely on `UniformSpace` structures in the domain and in the codomain. We should generalize them to topological spaces. This generalization will drop `UniformContinuous` assumptions in some lemmas, and add these assumptions in other lemmas, so it was not done in https://github.com/leanprover-community/mathlib4/pull/10644 to keep it reasonably sized. ## Keywords uniform space, separated space, Hausdorff space, separation quotient -/ open Filter Set Function Topology Uniformity UniformSpace noncomputable section universe u v w variable {α : Type u} {β : Type v} {γ : Type w} variable [UniformSpace α] [UniformSpace β] [UniformSpace γ] /-! ### Separated uniform spaces -/ instance (priority := 100) UniformSpace.to_regularSpace : RegularSpace α := .of_hasBasis (fun _ ↦ nhds_basis_uniformity' uniformity_hasBasis_closed) fun a _V hV ↦ isClosed_ball a hV.2 theorem Filter.HasBasis.specializes_iff_uniformity {ι : Sort*} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {x y : α} : x ⤳ y ↔ ∀ i, p i → (x, y) ∈ s i := (nhds_basis_uniformity h).specializes_iff theorem Filter.HasBasis.inseparable_iff_uniformity {ι : Sort*} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {x y : α} : Inseparable x y ↔ ∀ i, p i → (x, y) ∈ s i := specializes_iff_inseparable.symm.trans h.specializes_iff_uniformity theorem inseparable_iff_ker_uniformity {x y : α} : Inseparable x y ↔ (x, y) ∈ (𝓤 α).ker := (𝓤 α).basis_sets.inseparable_iff_uniformity protected theorem Inseparable.nhds_le_uniformity {x y : α} (h : Inseparable x y) : 𝓝 (x, y) ≤ 𝓤 α := by rw [h.prod rfl] apply nhds_le_uniformity theorem inseparable_iff_clusterPt_uniformity {x y : α} : Inseparable x y ↔ ClusterPt (x, y) (𝓤 α) := by refine ⟨fun h ↦ .of_nhds_le h.nhds_le_uniformity, fun h ↦ ?_⟩ simp_rw [uniformity_hasBasis_closed.inseparable_iff_uniformity, isClosed_iff_clusterPt] exact fun U ⟨hU, hUc⟩ ↦ hUc _ <| h.mono <| le_principal_iff.2 hU theorem t0Space_iff_uniformity : T0Space α ↔ ∀ x y, (∀ r ∈ 𝓤 α, (x, y) ∈ r) → x = y := by simp only [t0Space_iff_inseparable, inseparable_iff_ker_uniformity, mem_ker, id]
Mathlib/Topology/UniformSpace/Separation.lean
142
146
theorem t0Space_iff_uniformity' : T0Space α ↔ Pairwise fun x y ↦ ∃ r ∈ 𝓤 α, (x, y) ∉ r := by
simp [t0Space_iff_not_inseparable, inseparable_iff_ker_uniformity] theorem t0Space_iff_ker_uniformity : T0Space α ↔ (𝓤 α).ker = diagonal α := by
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Data.Set.Function import Mathlib.Logic.Equiv.Defs import Mathlib.Tactic.Says /-! # Equivalences and sets In this file we provide lemmas linking equivalences to sets. Some notable definitions are: * `Equiv.ofInjective`: an injective function is (noncomputably) equivalent to its range. * `Equiv.setCongr`: two equal sets are equivalent as types. * `Equiv.Set.union`: a disjoint union of sets is equivalent to their `Sum`. This file is separate from `Equiv/Basic` such that we do not require the full lattice structure on sets before defining what an equivalence is. -/ open Function Set universe u v w z variable {α : Sort u} {β : Sort v} {γ : Sort w} namespace EquivLike @[simp] theorem range_eq_univ {α : Type*} {β : Type*} {E : Type*} [EquivLike E α β] (e : E) : range e = univ := eq_univ_of_forall (EquivLike.toEquiv e).surjective end EquivLike namespace Equiv theorem range_eq_univ {α : Type*} {β : Type*} (e : α ≃ β) : range e = univ := EquivLike.range_eq_univ e protected theorem image_eq_preimage {α β} (e : α ≃ β) (s : Set α) : e '' s = e.symm ⁻¹' s := Set.ext fun _ => mem_image_iff_of_inverse e.left_inv e.right_inv @[simp 1001] theorem _root_.Set.mem_image_equiv {α β} {S : Set α} {f : α ≃ β} {x : β} : x ∈ f '' S ↔ f.symm x ∈ S := Set.ext_iff.mp (f.image_eq_preimage S) x /-- Alias for `Equiv.image_eq_preimage` -/ theorem _root_.Set.image_equiv_eq_preimage_symm {α β} (S : Set α) (f : α ≃ β) : f '' S = f.symm ⁻¹' S := f.image_eq_preimage S /-- Alias for `Equiv.image_eq_preimage` -/ theorem _root_.Set.preimage_equiv_eq_image_symm {α β} (S : Set α) (f : β ≃ α) : f ⁻¹' S = f.symm '' S := (f.symm.image_eq_preimage S).symm -- Increased priority so this fires before `image_subset_iff` @[simp high] protected theorem symm_image_subset {α β} (e : α ≃ β) (s : Set α) (t : Set β) : e.symm '' t ⊆ s ↔ t ⊆ e '' s := by rw [image_subset_iff, e.image_eq_preimage] -- Increased priority so this fires before `image_subset_iff` @[simp high] protected theorem subset_symm_image {α β} (e : α ≃ β) (s : Set α) (t : Set β) : s ⊆ e.symm '' t ↔ e '' s ⊆ t := calc s ⊆ e.symm '' t ↔ e.symm.symm '' s ⊆ t := by rw [e.symm.symm_image_subset] _ ↔ e '' s ⊆ t := by rw [e.symm_symm] @[simp] theorem symm_image_image {α β} (e : α ≃ β) (s : Set α) : e.symm '' (e '' s) = s := e.leftInverse_symm.image_image s theorem eq_image_iff_symm_image_eq {α β} (e : α ≃ β) (s : Set α) (t : Set β) : t = e '' s ↔ e.symm '' t = s := (e.symm.injective.image_injective.eq_iff' (e.symm_image_image s)).symm @[simp] theorem image_symm_image {α β} (e : α ≃ β) (s : Set β) : e '' (e.symm '' s) = s := e.symm.symm_image_image s @[simp] theorem image_preimage {α β} (e : α ≃ β) (s : Set β) : e '' (e ⁻¹' s) = s := e.surjective.image_preimage s @[simp] theorem preimage_image {α β} (e : α ≃ β) (s : Set α) : e ⁻¹' (e '' s) = s := e.injective.preimage_image s protected theorem image_compl {α β} (f : Equiv α β) (s : Set α) : f '' sᶜ = (f '' s)ᶜ := image_compl_eq f.bijective @[simp] theorem symm_preimage_preimage {α β} (e : α ≃ β) (s : Set β) : e.symm ⁻¹' (e ⁻¹' s) = s := e.rightInverse_symm.preimage_preimage s @[simp] theorem preimage_symm_preimage {α β} (e : α ≃ β) (s : Set α) : e ⁻¹' (e.symm ⁻¹' s) = s := e.leftInverse_symm.preimage_preimage s theorem preimage_subset {α β} (e : α ≃ β) (s t : Set β) : e ⁻¹' s ⊆ e ⁻¹' t ↔ s ⊆ t := e.surjective.preimage_subset_preimage_iff theorem image_subset {α β} (e : α ≃ β) (s t : Set α) : e '' s ⊆ e '' t ↔ s ⊆ t := image_subset_image_iff e.injective @[simp] theorem image_eq_iff_eq {α β} (e : α ≃ β) (s t : Set α) : e '' s = e '' t ↔ s = t := image_eq_image e.injective theorem preimage_eq_iff_eq_image {α β} (e : α ≃ β) (s t) : e ⁻¹' s = t ↔ s = e '' t := Set.preimage_eq_iff_eq_image e.bijective theorem eq_preimage_iff_image_eq {α β} (e : α ≃ β) (s t) : s = e ⁻¹' t ↔ e '' s = t := Set.eq_preimage_iff_image_eq e.bijective lemma setOf_apply_symm_eq_image_setOf {α β} (e : α ≃ β) (p : α → Prop) : {b | p (e.symm b)} = e '' {a | p a} := by rw [Equiv.image_eq_preimage, preimage_setOf_eq] @[simp] theorem prod_assoc_preimage {α β γ} {s : Set α} {t : Set β} {u : Set γ} : Equiv.prodAssoc α β γ ⁻¹' s ×ˢ t ×ˢ u = (s ×ˢ t) ×ˢ u := by ext simp [and_assoc] @[simp] theorem prod_assoc_symm_preimage {α β γ} {s : Set α} {t : Set β} {u : Set γ} : (Equiv.prodAssoc α β γ).symm ⁻¹' (s ×ˢ t) ×ˢ u = s ×ˢ t ×ˢ u := by ext simp [and_assoc] -- `@[simp]` doesn't like these lemmas, as it uses `Set.image_congr'` to turn `Equiv.prodAssoc` -- into a lambda expression and then unfold it.
Mathlib/Logic/Equiv/Set.lean
143
145
theorem prod_assoc_image {α β γ} {s : Set α} {t : Set β} {u : Set γ} : Equiv.prodAssoc α β γ '' (s ×ˢ t) ×ˢ u = s ×ˢ t ×ˢ u := by
simpa only [Equiv.image_eq_preimage] using prod_assoc_symm_preimage
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Dynamics.FixedPoints.Basic import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Birkhoff sums In this file we define `birkhoffSum f g n x` to be the sum `∑ k ∈ Finset.range n, g (f^[k] x)`. This sum (more precisely, the corresponding average `n⁻¹ • birkhoffSum f g n x`) appears in various ergodic theorems saying that these averages converge to the "space average" `⨍ x, g x ∂μ` in some sense. See also `birkhoffAverage` defined in `Dynamics/BirkhoffSum/Average`. -/ open Finset Function section AddCommMonoid variable {α M : Type*} [AddCommMonoid M] /-- The sum of values of `g` on the first `n` points of the orbit of `x` under `f`. -/ def birkhoffSum (f : α → α) (g : α → M) (n : ℕ) (x : α) : M := ∑ k ∈ range n, g (f^[k] x) theorem birkhoffSum_zero (f : α → α) (g : α → M) (x : α) : birkhoffSum f g 0 x = 0 := sum_range_zero _ @[simp] theorem birkhoffSum_zero' (f : α → α) (g : α → M) : birkhoffSum f g 0 = 0 := funext <| birkhoffSum_zero _ _ theorem birkhoffSum_one (f : α → α) (g : α → M) (x : α) : birkhoffSum f g 1 x = g x := sum_range_one _ @[simp] theorem birkhoffSum_one' (f : α → α) (g : α → M) : birkhoffSum f g 1 = g := funext <| birkhoffSum_one f g theorem birkhoffSum_succ (f : α → α) (g : α → M) (n : ℕ) (x : α) : birkhoffSum f g (n + 1) x = birkhoffSum f g n x + g (f^[n] x) := sum_range_succ _ _ theorem birkhoffSum_succ' (f : α → α) (g : α → M) (n : ℕ) (x : α) : birkhoffSum f g (n + 1) x = g x + birkhoffSum f g n (f x) := (sum_range_succ' _ _).trans (add_comm _ _) theorem birkhoffSum_add (f : α → α) (g : α → M) (m n : ℕ) (x : α) : birkhoffSum f g (m + n) x = birkhoffSum f g m x + birkhoffSum f g n (f^[m] x) := by simp_rw [birkhoffSum, sum_range_add, add_comm m, iterate_add_apply]
Mathlib/Dynamics/BirkhoffSum/Basic.lean
55
57
theorem Function.IsFixedPt.birkhoffSum_eq {f : α → α} {x : α} (h : IsFixedPt f x) (g : α → M) (n : ℕ) : birkhoffSum f g n x = n • g x := by
simp [birkhoffSum, (h.iterate _).eq]
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Ken Lee, Chris Hughes -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Data.Fintype.Basic import Mathlib.Data.Int.GCD import Mathlib.RingTheory.Coprime.Basic /-! # Additional lemmas about elements of a ring satisfying `IsCoprime` and elements of a monoid satisfying `IsRelPrime` These lemmas are in a separate file to the definition of `IsCoprime` or `IsRelPrime` as they require more imports. Notably, this includes lemmas about `Finset.prod` as this requires importing BigOperators, and lemmas about `Pow` since these are easiest to prove via `Finset.prod`. -/ universe u v open scoped Function -- required for scoped `on` notation section IsCoprime variable {R : Type u} {I : Type v} [CommSemiring R] {x y z : R} {s : I → R} {t : Finset I} section theorem Int.isCoprime_iff_gcd_eq_one {m n : ℤ} : IsCoprime m n ↔ Int.gcd m n = 1 := by constructor · rintro ⟨a, b, h⟩ refine Nat.dvd_one.mp (Int.gcd_dvd_iff.mpr ⟨a, b, ?_⟩) rwa [mul_comm m, mul_comm n, eq_comm] · rw [← Int.ofNat_inj, IsCoprime, Int.gcd_eq_gcd_ab, mul_comm m, mul_comm n, Nat.cast_one] intro h exact ⟨_, _, h⟩ theorem Nat.isCoprime_iff_coprime {m n : ℕ} : IsCoprime (m : ℤ) n ↔ Nat.Coprime m n := by rw [Int.isCoprime_iff_gcd_eq_one, Int.gcd_natCast_natCast] alias ⟨IsCoprime.nat_coprime, Nat.Coprime.isCoprime⟩ := Nat.isCoprime_iff_coprime theorem Nat.Coprime.cast {R : Type*} [CommRing R] {a b : ℕ} (h : Nat.Coprime a b) : IsCoprime (a : R) (b : R) := by rw [← isCoprime_iff_coprime] at h rw [← Int.cast_natCast a, ← Int.cast_natCast b] exact IsCoprime.intCast h theorem ne_zero_or_ne_zero_of_nat_coprime {A : Type u} [CommRing A] [Nontrivial A] {a b : ℕ} (h : Nat.Coprime a b) : (a : A) ≠ 0 ∨ (b : A) ≠ 0 := IsCoprime.ne_zero_or_ne_zero (R := A) <| by simpa only [map_natCast] using IsCoprime.map (Nat.Coprime.isCoprime h) (Int.castRingHom A) theorem IsCoprime.prod_left : (∀ i ∈ t, IsCoprime (s i) x) → IsCoprime (∏ i ∈ t, s i) x := by classical refine Finset.induction_on t (fun _ ↦ isCoprime_one_left) fun b t hbt ih H ↦ ?_ rw [Finset.prod_insert hbt] rw [Finset.forall_mem_insert] at H exact H.1.mul_left (ih H.2) theorem IsCoprime.prod_right : (∀ i ∈ t, IsCoprime x (s i)) → IsCoprime x (∏ i ∈ t, s i) := by simpa only [isCoprime_comm] using IsCoprime.prod_left (R := R) theorem IsCoprime.prod_left_iff : IsCoprime (∏ i ∈ t, s i) x ↔ ∀ i ∈ t, IsCoprime (s i) x := by classical refine Finset.induction_on t (iff_of_true isCoprime_one_left fun _ ↦ by simp) fun b t hbt ih ↦ ?_ rw [Finset.prod_insert hbt, IsCoprime.mul_left_iff, ih, Finset.forall_mem_insert] theorem IsCoprime.prod_right_iff : IsCoprime x (∏ i ∈ t, s i) ↔ ∀ i ∈ t, IsCoprime x (s i) := by simpa only [isCoprime_comm] using IsCoprime.prod_left_iff (R := R) theorem IsCoprime.of_prod_left (H1 : IsCoprime (∏ i ∈ t, s i) x) (i : I) (hit : i ∈ t) : IsCoprime (s i) x := IsCoprime.prod_left_iff.1 H1 i hit theorem IsCoprime.of_prod_right (H1 : IsCoprime x (∏ i ∈ t, s i)) (i : I) (hit : i ∈ t) : IsCoprime x (s i) := IsCoprime.prod_right_iff.1 H1 i hit -- Porting note: removed names of things due to linter, but they seem helpful theorem Finset.prod_dvd_of_coprime : (t : Set I).Pairwise (IsCoprime on s) → (∀ i ∈ t, s i ∣ z) → (∏ x ∈ t, s x) ∣ z := by classical exact Finset.induction_on t (fun _ _ ↦ one_dvd z) (by intro a r har ih Hs Hs1 rw [Finset.prod_insert har] have aux1 : a ∈ (↑(insert a r) : Set I) := Finset.mem_insert_self a r refine (IsCoprime.prod_right fun i hir ↦ Hs aux1 (Finset.mem_insert_of_mem hir) <| by rintro rfl exact har hir).mul_dvd (Hs1 a aux1) (ih (Hs.mono ?_) fun i hi ↦ Hs1 i <| Finset.mem_insert_of_mem hi) simp only [Finset.coe_insert, Set.subset_insert]) theorem Fintype.prod_dvd_of_coprime [Fintype I] (Hs : Pairwise (IsCoprime on s)) (Hs1 : ∀ i, s i ∣ z) : (∏ x, s x) ∣ z := Finset.prod_dvd_of_coprime (Hs.set_pairwise _) fun i _ ↦ Hs1 i end open Finset theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) : (∃ μ : I → R, (∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j) = 1) ↔ Pairwise (IsCoprime on fun i : t ↦ s i) := by induction h using Finset.Nonempty.cons_induction with | singleton => simp [exists_apply_eq, Pairwise, Function.onFun] | cons a t hat h ih => rw [pairwise_cons'] have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by rw [mem_sdiff, mem_singleton] exact ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩ constructor · rintro ⟨μ, hμ⟩ rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ refine ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩ · rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ← @if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ rw [← hμ, sum_congr rfl] intro x hx dsimp -- Porting note: terms were showing as sort of `HAdd.hadd` instead of `+` -- this whole proof pretty much breaks and has to be rewritten from scratch rw [add_mul] congr 1 · by_cases hx : x = h.choose · rw [hx, Pi.single_eq_same, Pi.single_eq_same] · rw [Pi.single_eq_of_ne hx, Pi.single_eq_of_ne hx, zero_mul] · rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _, mul_comm] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] · have : IsCoprime (s b) (s a) := ⟨μ a * ∏ i ∈ t \ {b}, s i, ∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j, ?_⟩ · exact ⟨this.symm, this⟩ rw [mul_assoc, ← prod_eq_prod_diff_singleton_mul hb, sum_mul, ← hμ, sum_congr rfl] intro x hx rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] · rintro ⟨hs, Hb⟩ obtain ⟨μ, hμ⟩ := ih.mpr hs obtain ⟨u, v, huv⟩ := IsCoprime.prod_left fun b hb ↦ (Hb b hb).right use fun i ↦ if i = a then u else v * μ i have hμ' : (∑ i ∈ t, v * ((μ i * ∏ j ∈ t \ {i}, s j) * s a)) = v * s a := by rw [← mul_sum, ← sum_mul, hμ, one_mul] rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] simp only [↓reduceIte, ite_mul] rw [← huv, ← hμ', sum_congr rfl] intro x hx rw [mul_assoc, if_neg fun ha : x = a ↦ hat (ha.casesOn hx)] rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] theorem exists_sum_eq_one_iff_pairwise_coprime' [Fintype I] [Nonempty I] [DecidableEq I] : (∃ μ : I → R, (∑ i : I, μ i * ∏ j ∈ {i}ᶜ, s j) = 1) ↔ Pairwise (IsCoprime on s) := by convert exists_sum_eq_one_iff_pairwise_coprime Finset.univ_nonempty (s := s) using 1 simp only [Function.onFun, pairwise_subtype_iff_pairwise_finset', coe_univ, Set.pairwise_univ] theorem pairwise_coprime_iff_coprime_prod [DecidableEq I] : Pairwise (IsCoprime on fun i : t ↦ s i) ↔ ∀ i ∈ t, IsCoprime (s i) (∏ j ∈ t \ {i}, s j) := by refine ⟨fun hp i hi ↦ IsCoprime.prod_right_iff.mpr fun j hj ↦ ?_, fun hp ↦ ?_⟩ · rw [Finset.mem_sdiff, Finset.mem_singleton] at hj obtain ⟨hj, ji⟩ := hj refine @hp ⟨i, hi⟩ ⟨j, hj⟩ fun h ↦ ji (congrArg Subtype.val h).symm -- Porting note: is there a better way compared to the old `congr_arg coe h`? · rintro ⟨i, hi⟩ ⟨j, hj⟩ h apply IsCoprime.prod_right_iff.mp (hp i hi) exact Finset.mem_sdiff.mpr ⟨hj, fun f ↦ h <| Subtype.ext (Finset.mem_singleton.mp f).symm⟩ variable {m n : ℕ} theorem IsCoprime.pow_left (H : IsCoprime x y) : IsCoprime (x ^ m) y := by rw [← Finset.card_range m, ← Finset.prod_const] exact IsCoprime.prod_left fun _ _ ↦ H theorem IsCoprime.pow_right (H : IsCoprime x y) : IsCoprime x (y ^ n) := by rw [← Finset.card_range n, ← Finset.prod_const] exact IsCoprime.prod_right fun _ _ ↦ H theorem IsCoprime.pow (H : IsCoprime x y) : IsCoprime (x ^ m) (y ^ n) := H.pow_left.pow_right theorem IsCoprime.pow_left_iff (hm : 0 < m) : IsCoprime (x ^ m) y ↔ IsCoprime x y := by refine ⟨fun h ↦ ?_, IsCoprime.pow_left⟩ rw [← Finset.card_range m, ← Finset.prod_const] at h exact h.of_prod_left 0 (Finset.mem_range.mpr hm) theorem IsCoprime.pow_right_iff (hm : 0 < m) : IsCoprime x (y ^ m) ↔ IsCoprime x y := isCoprime_comm.trans <| (IsCoprime.pow_left_iff hm).trans <| isCoprime_comm theorem IsCoprime.pow_iff (hm : 0 < m) (hn : 0 < n) : IsCoprime (x ^ m) (y ^ n) ↔ IsCoprime x y := (IsCoprime.pow_left_iff hm).trans <| IsCoprime.pow_right_iff hn end IsCoprime section RelPrime variable {α I} [CommMonoid α] [DecompositionMonoid α] {x y z : α} {s : I → α} {t : Finset I}
Mathlib/RingTheory/Coprime/Lemmas.lean
213
216
theorem IsRelPrime.prod_left : (∀ i ∈ t, IsRelPrime (s i) x) → IsRelPrime (∏ i ∈ t, s i) x := by
classical refine Finset.induction_on t (fun _ ↦ isRelPrime_one_left) fun b t hbt ih H ↦ ?_ rw [Finset.prod_insert hbt]
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Yaël Dillies -/ import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap /-! # Integral average of a function In this file we define `MeasureTheory.average μ f` (notation: `⨍ x, f x ∂μ`) to be the average value of `f` with respect to measure `μ`. It is defined as `∫ x, f x ∂((μ univ)⁻¹ • μ)`, so it is equal to zero if `f` is not integrable or if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, we use `⨍ x in s, f x ∂μ` (notation for `⨍ x, f x ∂(μ.restrict s)`). For average w.r.t. the volume, one can omit `∂volume`. Both have a version for the Lebesgue integral rather than Bochner. We prove several version of the first moment method: An integrable function is below/above its average on a set of positive measure: * `measure_le_setLAverage_pos` for the Lebesgue integral * `measure_le_setAverage_pos` for the Bochner integral ## Implementation notes The average is defined as an integral over `(μ univ)⁻¹ • μ` so that all theorems about Bochner integrals work for the average without modifications. For theorems that require integrability of a function, we provide a convenience lemma `MeasureTheory.Integrable.to_average`. ## Tags integral, center mass, average value -/ open ENNReal MeasureTheory MeasureTheory.Measure Metric Set Filter TopologicalSpace Function open scoped Topology ENNReal Convex variable {α E F : Type*} {m0 : MeasurableSpace α} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {μ ν : Measure α} {s t : Set α} /-! ### Average value of a function w.r.t. a measure The (Bochner, Lebesgue) average value of a function `f` w.r.t. a measure `μ` (notation: `⨍ x, f x ∂μ`, `⨍⁻ x, f x ∂μ`) is defined as the (Bochner, Lebesgue) integral divided by the total measure, so it is equal to zero if `μ` is an infinite measure, and (typically) equal to infinity if `f` is not integrable. If `μ` is a probability measure, then the average of any function is equal to its integral. -/ namespace MeasureTheory section ENNReal variable (μ) {f g : α → ℝ≥0∞} /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`, denoted `⨍⁻ x, f x ∂μ`. It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the average w.r.t. the volume, one can omit `∂volume`. -/ noncomputable def laverage (f : α → ℝ≥0∞) := ∫⁻ x, f x ∂(μ univ)⁻¹ • μ /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`. It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the average w.r.t. the volume, one can omit `∂volume`. -/ notation3 "⨍⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => laverage μ r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure. It is equal to `(volume univ)⁻¹ * ∫⁻ x, f x`, so it takes value zero if the space has infinite measure. In a probability space, the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x`, defined as `⨍⁻ x, f x ∂(volume.restrict s)`. -/ notation3 "⨍⁻ "(...)", "r:60:(scoped f => laverage volume f) => r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ` on a set `s`. It is equal to `(μ s)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. For the average w.r.t. the volume, one can omit `∂volume`. -/ notation3 "⨍⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => laverage (Measure.restrict μ s) r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure on a set `s`. It is equal to `(volume s)⁻¹ * ∫⁻ x, f x`, so it takes value zero if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. -/ notation3 (prettyPrint := false) "⨍⁻ "(...)" in "s", "r:60:(scoped f => laverage Measure.restrict volume s f) => r @[simp] theorem laverage_zero : ⨍⁻ _x, (0 : ℝ≥0∞) ∂μ = 0 := by rw [laverage, lintegral_zero] @[simp] theorem laverage_zero_measure (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂(0 : Measure α) = 0 := by simp [laverage] theorem laverage_eq' (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂(μ univ)⁻¹ • μ := rfl theorem laverage_eq (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = (∫⁻ x, f x ∂μ) / μ univ := by rw [laverage_eq', lintegral_smul_measure, ENNReal.div_eq_inv_mul, smul_eq_mul] theorem laverage_eq_lintegral [IsProbabilityMeasure μ] (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [laverage, measure_univ, inv_one, one_smul] @[simp] theorem measure_mul_laverage [IsFiniteMeasure μ] (f : α → ℝ≥0∞) : μ univ * ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rcases eq_or_ne μ 0 with hμ | hμ · rw [hμ, lintegral_zero_measure, laverage_zero_measure, mul_zero] · rw [laverage_eq, ENNReal.mul_div_cancel (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)] theorem setLAverage_eq (f : α → ℝ≥0∞) (s : Set α) : ⨍⁻ x in s, f x ∂μ = (∫⁻ x in s, f x ∂μ) / μ s := by rw [laverage_eq, restrict_apply_univ] @[deprecated (since := "2025-04-22")] alias setLaverage_eq := setLAverage_eq theorem setLAverage_eq' (f : α → ℝ≥0∞) (s : Set α) : ⨍⁻ x in s, f x ∂μ = ∫⁻ x, f x ∂(μ s)⁻¹ • μ.restrict s := by simp only [laverage_eq', restrict_apply_univ] @[deprecated (since := "2025-04-22")] alias setLaverage_eq' := setLAverage_eq' variable {μ} theorem laverage_congr {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ⨍⁻ x, f x ∂μ = ⨍⁻ x, g x ∂μ := by simp only [laverage_eq, lintegral_congr_ae h] theorem setLAverage_congr (h : s =ᵐ[μ] t) : ⨍⁻ x in s, f x ∂μ = ⨍⁻ x in t, f x ∂μ := by simp only [setLAverage_eq, setLIntegral_congr h, measure_congr h] @[deprecated (since := "2025-04-22")] alias setLaverage_congr := setLAverage_congr theorem setLAverage_congr_fun (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ⨍⁻ x in s, f x ∂μ = ⨍⁻ x in s, g x ∂μ := by simp only [laverage_eq, setLIntegral_congr_fun hs h] @[deprecated (since := "2025-04-22")] alias setLaverage_congr_fun := setLAverage_congr_fun
Mathlib/MeasureTheory/Integral/Average.lean
149
150
theorem laverage_lt_top (hf : ∫⁻ x, f x ∂μ ≠ ∞) : ⨍⁻ x, f x ∂μ < ∞ := by
obtain rfl | hμ := eq_or_ne μ 0
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.SetTheory.Cardinal.Finite import Mathlib.Data.Set.Finite.Powerset /-! # Noncomputable Set Cardinality We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`. The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen as an API for the same function in the special case where the type is a coercion of a `Set`, allowing for smoother interactions with the `Set` API. `Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even though it takes values in a less convenient type. It is probably the right choice in settings where one is concerned with the cardinalities of sets that may or may not be infinite. `Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'. When working with sets that are finite by virtue of their definition, then `Finset.card` probably makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`, where every set is automatically finite. In this setting, we use default arguments and a simple tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems. ## Main Definitions * `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if `s` is infinite. * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite. If `s` is Infinite, then `Set.ncard s = 0`. * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with `Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance. ## Implementation Notes The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the `Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard` in the future. Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`, where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite` type. Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other in the context of the theorem, in which case we only include the ones that are needed, and derive the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require finiteness arguments; they are true by coincidence due to junk values. -/ namespace Set variable {α β : Type*} {s t : Set α} /-- The cardinality of a set as a term in `ℕ∞` -/ noncomputable def encard (s : Set α) : ℕ∞ := ENat.card s @[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)] theorem encard_univ (α : Type*) : encard (univ : Set α) = ENat.card α := by rw [encard, ENat.card_congr (Equiv.Set.univ α)] theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by have := h.fintype rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card] theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by have h := toFinite s rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset] @[simp] theorem toENat_cardinalMk (s : Set α) : (Cardinal.mk s).toENat = s.encard := rfl theorem toENat_cardinalMk_subtype (P : α → Prop) : (Cardinal.mk {x // P x}).toENat = {x | P x}.encard := rfl @[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by simp [encard_eq_coe_toFinset_card] @[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp @[simp] theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by have := h.to_subtype rw [encard, ENat.card_eq_top_of_infinite] @[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem] @[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by rw [encard_eq_zero] theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero] theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty] @[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by rw [pos_iff_ne_zero, encard_ne_zero] protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos @[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one] theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by classical simp [encard, ENat.card_congr (Equiv.Set.union h)] theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by rw [← union_singleton, encard_union_eq (by simpa), encard_singleton] theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by induction s, h using Set.Finite.induction_on with | empty => simp | insert hat _ ht' => rw [encard_insert_of_not_mem hat] exact lt_tsub_iff_right.1 ht' theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard := (ENat.coe_toNat h.encard_lt_top.ne).symm theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n := ⟨_, h.encard_eq_coe⟩ @[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite := ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩ @[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite] alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by simp theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _) theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite := finite_of_encard_le_coe h.le theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k := ⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩, fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩ @[simp] theorem encard_prod : (s ×ˢ t).encard = s.encard * t.encard := by simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)] section Lattice theorem encard_le_encard (h : s ⊆ t) : s.encard ≤ t.encard := by rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add @[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) := fun _ _ ↦ encard_le_encard theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h] @[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero] theorem encard_diff_add_encard_inter (s t : Set α) : (s \ t).encard + (s ∩ t).encard = s.encard := by rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left), diff_union_inter] theorem encard_union_add_encard_inter (s t : Set α) : (s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm, encard_diff_add_encard_inter] theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) : s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_right_inj h.encard_lt_top.ne] theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) : s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_le_add_iff_right h.encard_lt_top.ne] theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) : s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_lt_add_iff_right h.encard_lt_top.ne] theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by rw [← encard_union_add_encard_inter]; exact le_self_add theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by rw [← encard_lt_top_iff, ← encard_lt_top_iff, h] theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) : s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff] theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite) (h : t.encard ≤ s.encard) : t.Finite := encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top) lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := by rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff exact hst.antisymm hdiff theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := (hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts theorem Finite.encard_lt_encard (hs : s.Finite) (h : s ⊂ t) : s.encard < t.encard := (encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le) theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) := fun _ _ h ↦ (toFinite _).encard_lt_encard h theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self] theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard := (encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by rw [← encard_union_eq disjoint_compl_right, union_compl_self] end Lattice section InsertErase variable {a b : α} theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by rw [← union_singleton, ← encard_singleton x]; apply encard_union_le theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by rw [← encard_singleton x]; exact encard_le_encard inter_subset_left theorem encard_diff_singleton_add_one (h : a ∈ s) : (s \ {a}).encard + 1 = s.encard := by rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h] theorem encard_diff_singleton_of_mem (h : a ∈ s) : (s \ {a}).encard = s.encard - 1 := by rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top, tsub_add_cancel_of_le (self_le_add_left _ _)] theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) : s.encard - 1 ≤ (s \ {x}).encard := by rw [← encard_singleton x]; apply tsub_encard_le_encard_diff theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb] simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true] theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb] theorem encard_eq_add_one_iff {k : ℕ∞} : s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by refine ⟨fun h ↦ ?_, ?_⟩ · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h]) refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩ rw [← WithTop.add_right_inj WithTop.one_ne_top, ← h, encard_diff_singleton_add_one ha] rintro ⟨a, t, h, rfl, rfl⟩ rw [encard_insert_of_not_mem h] /-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended for well-founded induction on the value of `encard`. -/ theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) : s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦ (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq))) rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)] exact WithTop.add_lt_add_left hfin.diff.encard_lt_top.ne zero_lt_one end InsertErase section SmallSets theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two, WithTop.add_right_inj WithTop.one_ne_top, encard_singleton] theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le (by simpa) (by simp [h])).symm⟩ theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero, encard_eq_one] theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty] refine ⟨fun h a b has hbs ↦ ?_, fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩ obtain ⟨x, rfl⟩ := h ⟨_, has⟩ rw [(has : a = x), (hbs : b = x)] theorem encard_le_one_iff_subsingleton : s.encard ≤ 1 ↔ s.Subsingleton := by rw [encard_le_one_iff, Set.Subsingleton] tauto theorem one_lt_encard_iff_nontrivial : 1 < s.encard ↔ s.Nontrivial := by rw [← not_iff_not, not_lt, Set.not_nontrivial_iff, ← encard_le_one_iff_subsingleton] theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by by_contra! h' obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h apply hne rw [h' b hb, h' b' hb'] theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), ← one_add_one_eq_two, WithTop.add_right_inj (WithTop.one_ne_top), encard_eq_one] at h obtain ⟨y, h⟩ := h refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩ rw [← h, insert_diff_singleton, insert_eq_of_mem hx] theorem encard_eq_three {α : Type u_1} {s : Set α} : encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩ · obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1), WithTop.add_right_inj WithTop.one_ne_top, encard_eq_two] at h obtain ⟨y, z, hne, hs⟩ := h refine ⟨x, y, z, ?_, ?_, hne, ?_⟩ · rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl · rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl rw [← hs, insert_diff_singleton, insert_eq_of_mem hx] rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1 · rw [Finset.coe_range, Iio_def] rw [Finset.card_range] end SmallSets theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t) (hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_inj hs.encard_lt_top.ne, encard_eq_one] at hst obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union] theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by revert hk refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_ · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle) simp only [Nat.cast_succ] at * have hne : t₀ ≠ s := by rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne) exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩ simp only [top_le_iff, encard_eq_top_iff] exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩ theorem exists_superset_subset_encard_eq {k : ℕ∞} (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) : ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by obtain (hs | hs) := eq_or_ne s.encard ⊤ · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩ obtain ⟨k, rfl⟩ := exists_add_of_le hsk obtain ⟨k', hk'⟩ := exists_add_of_le hkt have hk : k ≤ encard (t \ s) := by rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt exact WithTop.le_of_add_le_add_right hs hkt obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩ rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)] section Function variable {s : Set α} {t : Set β} {f : α → β} theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by rw [encard, ENat.card_image_of_injOn h, encard] theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, ENat.card_congr e] theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) : (f '' s).encard = s.encard := hf.injOn.encard_image theorem _root_.Function.Embedding.encard_le (e : s ↪ t) : s.encard ≤ t.encard := by rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image] exact encard_mono (by simp) theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by obtain (h | h) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] apply encard_le_encard exact f.invFunOn_image_image_subset s theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) : InjOn f s := by obtain (h' | hne) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] at h rw [injOn_iff_invFunOn_image_image_eq_self] exact hs.eq_of_subset_of_encard_le' (f.invFunOn_image_image_subset s) h.symm.le theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆ range f) : (f ⁻¹' t).encard = t.encard := by rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht] lemma encard_preimage_of_bijective (hf : f.Bijective) (t : Set β) : (f ⁻¹' t).encard = t.encard := encard_preimage_of_injective_subset_range hf.injective (by simp [hf.surjective.range_eq]) theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) : s.encard ≤ t.encard := by rw [← f_inj.encard_image]; apply encard_le_encard; rintro _ ⟨x, hx, rfl⟩; exact hf hx theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite) (hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by classical obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt · simp · exact (encard_ne_top_iff.mpr hs h).elim obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle) have hle' : (s \ {a}).encard ≤ (t \ {b}).encard := by rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top, encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt] obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le hs.diff hle' simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s use Function.update f₀ a b rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)] simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def, mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp, mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt] refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩ · rintro x hx; split_ifs with h · assumption · exact (hf₀s x hx h).1 exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_of_ne]) termination_by encard s theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) : ∃ (f : α → β), BijOn f s t := by obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f convert hinj.bijOn_image rw [(hs.image f).eq_of_subset_of_encard_le (image_subset_iff.mpr hf) (h.symm.trans hinj.encard_image.symm).le] end Function section ncard open Nat /-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite` term. -/ syntax "toFinite_tac" : tactic macro_rules | `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite) /-- A tactic useful for transferring proofs for `encard` to their corresponding `card` statements -/ syntax "to_encard_tac" : tactic macro_rules | `(tactic| to_encard_tac) => `(tactic| simp only [← Nat.cast_le (α := ℕ∞), ← Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one]) /-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/ noncomputable def ncard (s : Set α) : ℕ := ENat.toNat s.encard theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not] lemma ncard_le_encard (s : Set α) : s.ncard ≤ s.encard := ENat.coe_toNat_le_self _ theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by obtain (h | h) := s.finite_or_infinite · have := h.fintype rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card, toFinite_toFinset, toFinset_card, ENat.toNat_coe] have := infinite_coe_iff.2 h rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top] theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) : s.ncard = hs.toFinset.card := by rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype, @Finite.card_toFinset _ _ hs.fintype hs] theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] : s.ncard = s.toFinset.card := by simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card] lemma cast_ncard {s : Set α} (hs : s.Finite) : (s.ncard : Cardinal) = Cardinal.mk s := @Nat.cast_card _ hs theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by rw [encard_le_coe_iff, and_congr_right_iff] exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by rwa [ncard_def, hn₀, ENat.toNat_coe], fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩ theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype] @[gcongr] theorem ncard_le_ncard (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) : s.ncard ≤ t.ncard := by rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq] exact encard_mono hst theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ ncard_le_ncard @[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) : s.ncard = 0 ↔ s = ∅ := by rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero] @[simp, norm_cast] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset] theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by rcases finite_or_infinite α with h | h · have hft := Fintype.ofFinite α rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card] rw [Nat.card_eq_zero_of_infinite, Infinite.ncard] exact infinite_univ @[simp] theorem ncard_empty (α : Type*) : (∅ : Set α).ncard = 0 := by rw [ncard_eq_zero] theorem ncard_pos (hs : s.Finite := by toFinite_tac) : 0 < s.ncard ↔ s.Nonempty := by rw [pos_iff_ne_zero, Ne, ncard_eq_zero hs, nonempty_iff_ne_empty] protected alias ⟨_, Nonempty.ncard_pos⟩ := ncard_pos theorem ncard_ne_zero_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : s.ncard ≠ 0 := ((ncard_pos hs).mpr ⟨a, h⟩).ne.symm theorem finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite := s.finite_or_infinite.elim id fun h ↦ (hs h.ncard).elim theorem finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite := finite_of_ncard_ne_zero hs.ne.symm theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; simp at hs @[simp] theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by simp [ncard] theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by rw [← Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one] apply encard_singleton_inter @[simp] theorem ncard_prod : (s ×ˢ t).ncard = s.ncard * t.ncard := by simp [ncard, ENat.toNat_mul] @[simp] theorem ncard_powerset (s : Set α) (hs : s.Finite := by toFinite_tac) : (𝒫 s).ncard = 2 ^ s.ncard := by have h := Cardinal.mk_powerset s rw [← cast_ncard hs.powerset, ← cast_ncard hs] at h norm_cast at h section InsertErase @[simp] theorem ncard_insert_of_not_mem {a : α} (h : a ∉ s) (hs : s.Finite := by toFinite_tac) : (insert a s).ncard = s.ncard + 1 := by rw [← Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one, hs.cast_ncard_eq, encard_insert_of_not_mem h] theorem ncard_insert_of_mem {a : α} (h : a ∈ s) : ncard (insert a s) = s.ncard := by rw [insert_eq_of_mem h] theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by obtain hs | hs := s.finite_or_infinite · to_encard_tac; rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]; apply encard_insert_le rw [(hs.mono (subset_insert a s)).ncard] exact Nat.zero_le _ theorem ncard_insert_eq_ite {a : α} [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) : ncard (insert a s) = if a ∈ s then s.ncard else s.ncard + 1 := by by_cases h : a ∈ s · rw [ncard_insert_of_mem h, if_pos h] · rw [ncard_insert_of_not_mem h hs, if_neg h] theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by classical refine s.finite_or_infinite.elim (fun h ↦ ?_) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _)) rw [ncard_insert_eq_ite h]; split_ifs <;> simp @[simp] theorem ncard_pair {a b : α} (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by rw [ncard_insert_of_not_mem, ncard_singleton]; simpa @[simp] theorem ncard_diff_singleton_add_one {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard + 1 = s.ncard := by to_encard_tac; rw [hs.cast_ncard_eq, hs.diff.cast_ncard_eq, encard_diff_singleton_add_one h] @[simp] theorem ncard_diff_singleton_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard = s.ncard - 1 := eq_tsub_of_add_eq (ncard_diff_singleton_add_one h hs) theorem ncard_diff_singleton_lt_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard < s.ncard := by rw [← ncard_diff_singleton_add_one h hs]; apply lt_add_one theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by obtain hs | hs := s.finite_or_infinite · apply ncard_le_ncard diff_subset hs convert zero_le (α := ℕ) _ exact (hs.diff (by simp : Set.Finite {a})).ncard theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by rcases s.finite_or_infinite with hs | hs · by_cases h : a ∈ s · rw [ncard_diff_singleton_of_mem h hs] rw [diff_singleton_eq_self h] apply Nat.pred_le convert Nat.zero_le _ rw [hs.ncard] theorem ncard_exchange {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard := congr_arg ENat.toNat <| encard_exchange ha hb theorem ncard_exchange' {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).ncard = s.ncard := by rw [← ncard_exchange ha hb, ← singleton_union, ← singleton_union, union_diff_distrib, @diff_singleton_eq_self _ b {a} fun h ↦ ha (by rwa [← mem_singleton_iff.mp h])] lemma odd_card_insert_iff {a : α} (ha : a ∉ s) (hs : s.Finite := by toFinite_tac) : Odd (insert a s).ncard ↔ Even s.ncard := by rw [ncard_insert_of_not_mem ha hs, Nat.odd_add] simp only [Nat.odd_add, ← Nat.not_even_iff_odd, Nat.not_even_one, iff_false, Decidable.not_not] lemma even_card_insert_iff {a : α} (ha : a ∉ s) (hs : s.Finite := by toFinite_tac) : Even (insert a s).ncard ↔ Odd s.ncard := by rw [ncard_insert_of_not_mem ha hs, Nat.even_add_one, Nat.not_even_iff_odd] end InsertErase variable {f : α → β} theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by to_encard_tac; rw [hs.cast_ncard_eq, (hs.image _).cast_ncard_eq]; apply encard_image_le theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard := congr_arg ENat.toNat <| H.encard_image theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard) (hs : s.Finite := by toFinite_tac) : Set.InjOn f s := by rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, (hs.image _).cast_ncard_eq] at h exact hs.injOn_of_encard_image_eq h theorem ncard_image_iff (hs : s.Finite := by toFinite_tac) : (f '' s).ncard = s.ncard ↔ Set.InjOn f s := ⟨fun h ↦ injOn_of_ncard_image_eq h hs, ncard_image_of_injOn⟩ theorem ncard_image_of_injective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard := ncard_image_of_injOn fun _ _ _ _ h ↦ H h
Mathlib/Data/Set/Card.lean
693
697
theorem ncard_preimage_of_injective_subset_range {s : Set β} (H : f.Injective) (hs : s ⊆ Set.range f) : (f ⁻¹' s).ncard = s.ncard := by
rw [← ncard_image_of_injective _ H, image_preimage_eq_iff.mpr hs]
/- Copyright (c) 2022 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Devon Tuma -/ import Mathlib.Data.Vector.Basic /-! # Theorems about membership of elements in vectors This file contains theorems for membership in a `v.toList` for a vector `v`. Having the length available in the type allows some of the lemmas to be simpler and more general than the original version for lists. In particular we can avoid some assumptions about types being `Inhabited`, and make more general statements about `head` and `tail`. -/ namespace List namespace Vector variable {α β : Type*} {n : ℕ} (a a' : α) @[simp] theorem get_mem (i : Fin n) (v : Vector α n) : v.get i ∈ v.toList := List.get_mem _ _ theorem mem_iff_get (v : Vector α n) : a ∈ v.toList ↔ ∃ i, v.get i = a := by simp only [List.mem_iff_get, Fin.exists_iff, Vector.get_eq_get_toList] exact ⟨fun ⟨i, hi, h⟩ => ⟨i, by rwa [toList_length] at hi, h⟩, fun ⟨i, hi, h⟩ => ⟨i, by rwa [toList_length], h⟩⟩ theorem not_mem_nil : a ∉ (Vector.nil : Vector α 0).toList := by unfold Vector.nil dsimp simp
Mathlib/Data/Vector/Mem.lean
38
41
theorem not_mem_zero (v : Vector α 0) : a ∉ v.toList := (Vector.eq_nil v).symm ▸ not_mem_nil a theorem mem_cons_iff (v : Vector α n) : a' ∈ (a ::ᵥ v).toList ↔ a' = a ∨ a' ∈ v.toList := by
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.NNReal /-! # Limits and asymptotics of power functions at `+∞` This file contains results about the limiting behaviour of power functions at `+∞`. For convenience some results on asymptotics as `x → 0` (those which are not just continuity statements) are also located here. -/ noncomputable section open Real Topology NNReal ENNReal Filter ComplexConjugate Finset Set /-! ## Limits at `+∞` -/ section Limits open Real Filter /-- The function `x ^ y` tends to `+∞` at `+∞` for any positive real `y`. -/ theorem tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ y) atTop atTop := by rw [(atTop_basis' 0).tendsto_right_iff] intro b hb filter_upwards [eventually_ge_atTop 0, eventually_ge_atTop (b ^ (1 / y))] with x hx₀ hx simpa (disch := positivity) [Real.rpow_inv_le_iff_of_pos] using hx /-- The function `x ^ (-y)` tends to `0` at `+∞` for any positive real `y`. -/ theorem tendsto_rpow_neg_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ (-y)) atTop (𝓝 0) := Tendsto.congr' (eventuallyEq_of_mem (Ioi_mem_atTop 0) fun _ hx => (rpow_neg (le_of_lt hx) y).symm) (tendsto_rpow_atTop hy).inv_tendsto_atTop open Asymptotics in lemma tendsto_rpow_atTop_of_base_lt_one (b : ℝ) (hb₀ : -1 < b) (hb₁ : b < 1) : Tendsto (b ^ · : ℝ → ℝ) atTop (𝓝 (0 : ℝ)) := by rcases lt_trichotomy b 0 with hb|rfl|hb case inl => -- b < 0 simp_rw [Real.rpow_def_of_nonpos hb.le, hb.ne, ite_false] rw [← isLittleO_const_iff (c := (1 : ℝ)) one_ne_zero, (one_mul (1 : ℝ)).symm] refine IsLittleO.mul_isBigO ?exp ?cos case exp => rw [isLittleO_const_iff one_ne_zero] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id rw [← log_neg_eq_log, log_neg_iff (by linarith)] linarith case cos => rw [isBigO_iff] exact ⟨1, Eventually.of_forall fun x => by simp [Real.abs_cos_le_one]⟩ case inr.inl => -- b = 0 refine Tendsto.mono_right ?_ (Iff.mpr pure_le_nhds_iff rfl) rw [tendsto_pure] filter_upwards [eventually_ne_atTop 0] with _ hx simp [hx] case inr.inr => -- b > 0 simp_rw [Real.rpow_def_of_pos hb] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id exact (log_neg_iff hb).mpr hb₁ lemma tendsto_rpow_atTop_of_base_gt_one (b : ℝ) (hb : 1 < b) : Tendsto (b ^ · : ℝ → ℝ) atBot (𝓝 (0 : ℝ)) := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_pos ?_).mpr tendsto_id exact (log_pos_iff (by positivity)).mpr <| by aesop lemma tendsto_rpow_atBot_of_base_lt_one (b : ℝ) (hb₀ : 0 < b) (hb₁ : b < 1) : Tendsto (b ^ · : ℝ → ℝ) atBot atTop := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atTop.comp <| (tendsto_const_mul_atTop_iff_neg <| tendsto_id (α := ℝ)).mpr ?_ exact (log_neg_iff hb₀).mpr hb₁ lemma tendsto_rpow_atBot_of_base_gt_one (b : ℝ) (hb : 1 < b) : Tendsto (b ^ · : ℝ → ℝ) atBot (𝓝 0) := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_iff_pos <| tendsto_id (α := ℝ)).mpr ?_ exact (log_pos_iff (by positivity)).mpr <| by aesop /-- The function `x ^ (a / (b * x + c))` tends to `1` at `+∞`, for any real numbers `a`, `b`, and `c` such that `b` is nonzero. -/ theorem tendsto_rpow_div_mul_add (a b c : ℝ) (hb : 0 ≠ b) : Tendsto (fun x => x ^ (a / (b * x + c))) atTop (𝓝 1) := by refine Tendsto.congr' ?_ ((tendsto_exp_nhds_zero_nhds_one.comp (by simpa only [mul_zero, pow_one] using (tendsto_const_nhds (x := a)).mul (tendsto_div_pow_mul_exp_add_atTop b c 1 hb))).comp tendsto_log_atTop) apply eventuallyEq_of_mem (Ioi_mem_atTop (0 : ℝ)) intro x hx simp only [Set.mem_Ioi, Function.comp_apply] at hx ⊢ rw [exp_log hx, ← exp_log (rpow_pos_of_pos hx (a / (b * x + c))), log_rpow hx (a / (b * x + c))] field_simp /-- The function `x ^ (1 / x)` tends to `1` at `+∞`. -/ theorem tendsto_rpow_div : Tendsto (fun x => x ^ ((1 : ℝ) / x)) atTop (𝓝 1) := by convert tendsto_rpow_div_mul_add (1 : ℝ) _ (0 : ℝ) zero_ne_one ring /-- The function `x ^ (-1 / x)` tends to `1` at `+∞`. -/ theorem tendsto_rpow_neg_div : Tendsto (fun x => x ^ (-(1 : ℝ) / x)) atTop (𝓝 1) := by convert tendsto_rpow_div_mul_add (-(1 : ℝ)) _ (0 : ℝ) zero_ne_one ring /-- The function `exp(x) / x ^ s` tends to `+∞` at `+∞`, for any real number `s`. -/ theorem tendsto_exp_div_rpow_atTop (s : ℝ) : Tendsto (fun x : ℝ => exp x / x ^ s) atTop atTop := by obtain ⟨n, hn⟩ := archimedean_iff_nat_lt.1 Real.instArchimedean s refine tendsto_atTop_mono' _ ?_ (tendsto_exp_div_pow_atTop n) filter_upwards [eventually_gt_atTop (0 : ℝ), eventually_ge_atTop (1 : ℝ)] with x hx₀ hx₁ gcongr simpa using rpow_le_rpow_of_exponent_le hx₁ hn.le /-- The function `exp (b * x) / x ^ s` tends to `+∞` at `+∞`, for any real `s` and `b > 0`. -/ theorem tendsto_exp_mul_div_rpow_atTop (s : ℝ) (b : ℝ) (hb : 0 < b) : Tendsto (fun x : ℝ => exp (b * x) / x ^ s) atTop atTop := by refine ((tendsto_rpow_atTop hb).comp (tendsto_exp_div_rpow_atTop (s / b))).congr' ?_ filter_upwards [eventually_ge_atTop (0 : ℝ)] with x hx₀ simp [Real.div_rpow, (exp_pos x).le, rpow_nonneg, ← Real.rpow_mul, ← exp_mul, mul_comm x, hb.ne', *] /-- The function `x ^ s * exp (-b * x)` tends to `0` at `+∞`, for any real `s` and `b > 0`. -/ theorem tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (s : ℝ) (b : ℝ) (hb : 0 < b) : Tendsto (fun x : ℝ => x ^ s * exp (-b * x)) atTop (𝓝 0) := by refine (tendsto_exp_mul_div_rpow_atTop s b hb).inv_tendsto_atTop.congr' ?_ filter_upwards with x using by simp [exp_neg, inv_div, div_eq_mul_inv _ (exp _)] nonrec theorem NNReal.tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ≥0 => x ^ y) atTop atTop := by rw [Filter.tendsto_atTop_atTop] intro b obtain ⟨c, hc⟩ := tendsto_atTop_atTop.mp (tendsto_rpow_atTop hy) b use c.toNNReal intro a ha exact mod_cast hc a (Real.toNNReal_le_iff_le_coe.mp ha) theorem ENNReal.tendsto_rpow_at_top {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ≥0∞ => x ^ y) (𝓝 ⊤) (𝓝 ⊤) := by rw [ENNReal.tendsto_nhds_top_iff_nnreal] intro x obtain ⟨c, _, hc⟩ := (atTop_basis_Ioi.tendsto_iff atTop_basis_Ioi).mp (NNReal.tendsto_rpow_atTop hy) x trivial have hc' : Set.Ioi ↑c ∈ 𝓝 (⊤ : ℝ≥0∞) := Ioi_mem_nhds ENNReal.coe_lt_top filter_upwards [hc'] with a ha by_cases ha' : a = ⊤ · simp [ha', hy] lift a to ℝ≥0 using ha' simp only [Set.mem_Ioi, coe_lt_coe] at ha hc rw [← ENNReal.coe_rpow_of_nonneg _ hy.le] exact mod_cast hc a ha end Limits /-! ## Asymptotic results: `IsBigO`, `IsLittleO` and `IsTheta` -/ namespace Complex section variable {α : Type*} {l : Filter α} {f g : α → ℂ} open Asymptotics theorem isTheta_exp_arg_mul_im (hl : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|) : (fun x => Real.exp (arg (f x) * im (g x))) =Θ[l] fun _ => (1 : ℝ) := by rcases hl with ⟨b, hb⟩ refine Real.isTheta_exp_comp_one.2 ⟨π * b, ?_⟩ rw [eventually_map] at hb ⊢ refine hb.mono fun x hx => ?_ rw [abs_mul] exact mul_le_mul (abs_arg_le_pi _) hx (abs_nonneg _) Real.pi_pos.le theorem isBigO_cpow_rpow (hl : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|) : (fun x => f x ^ g x) =O[l] fun x => ‖f x‖ ^ (g x).re := calc (fun x => f x ^ g x) =O[l] (show α → ℝ from fun x => ‖f x‖ ^ (g x).re / Real.exp (arg (f x) * im (g x))) := isBigO_of_le _ fun _ => (norm_cpow_le _ _).trans (le_abs_self _) _ =Θ[l] (show α → ℝ from fun x => ‖f x‖ ^ (g x).re / (1 : ℝ)) := ((isTheta_refl _ _).div (isTheta_exp_arg_mul_im hl)) _ =ᶠ[l] (show α → ℝ from fun x => ‖f x‖ ^ (g x).re) := by simp only [ofReal_one, div_one, EventuallyEq.rfl] theorem isTheta_cpow_rpow (hl_im : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|) (hl : ∀ᶠ x in l, f x = 0 → re (g x) = 0 → g x = 0) : (fun x => f x ^ g x) =Θ[l] fun x => ‖f x‖ ^ (g x).re := calc (fun x => f x ^ g x) =Θ[l] (fun x => ‖f x‖ ^ (g x).re / Real.exp (arg (f x) * im (g x))) := .of_norm_eventuallyEq <| hl.mono fun _ => norm_cpow_of_imp _ =Θ[l] fun x => ‖f x‖ ^ (g x).re / (1 : ℝ) := (isTheta_refl _ _).div (isTheta_exp_arg_mul_im hl_im) _ =ᶠ[l] (fun x => ‖f x‖ ^ (g x).re) := by simp only [ofReal_one, div_one, EventuallyEq.rfl] theorem isTheta_cpow_const_rpow {b : ℂ} (hl : b.re = 0 → b ≠ 0 → ∀ᶠ x in l, f x ≠ 0) : (fun x => f x ^ b) =Θ[l] fun x => ‖f x‖ ^ b.re := isTheta_cpow_rpow isBoundedUnder_const <| by simpa only [eventually_imp_distrib_right, not_imp_not, Imp.swap (a := b.re = 0)] using hl end end Complex open Real namespace Asymptotics variable {α : Type*} {r c : ℝ} {l : Filter α} {f g : α → ℝ} theorem IsBigOWith.rpow (h : IsBigOWith c l f g) (hc : 0 ≤ c) (hr : 0 ≤ r) (hg : 0 ≤ᶠ[l] g) : IsBigOWith (c ^ r) l (fun x => f x ^ r) fun x => g x ^ r := by apply IsBigOWith.of_bound filter_upwards [hg, h.bound] with x hgx hx calc |f x ^ r| ≤ |f x| ^ r := abs_rpow_le_abs_rpow _ _ _ ≤ (c * |g x|) ^ r := rpow_le_rpow (abs_nonneg _) hx hr _ = c ^ r * |g x ^ r| := by rw [mul_rpow hc (abs_nonneg _), abs_rpow_of_nonneg hgx] theorem IsBigO.rpow (hr : 0 ≤ r) (hg : 0 ≤ᶠ[l] g) (h : f =O[l] g) : (fun x => f x ^ r) =O[l] fun x => g x ^ r := let ⟨_, hc, h'⟩ := h.exists_nonneg (h'.rpow hc hr hg).isBigO theorem IsTheta.rpow (hr : 0 ≤ r) (hf : 0 ≤ᶠ[l] f) (hg : 0 ≤ᶠ[l] g) (h : f =Θ[l] g) : (fun x => f x ^ r) =Θ[l] fun x => g x ^ r := ⟨h.1.rpow hr hg, h.2.rpow hr hf⟩ theorem IsLittleO.rpow (hr : 0 < r) (hg : 0 ≤ᶠ[l] g) (h : f =o[l] g) : (fun x => f x ^ r) =o[l] fun x => g x ^ r := by refine .of_isBigOWith fun c hc ↦ ?_ rw [← rpow_inv_rpow hc.le hr.ne'] refine (h.forall_isBigOWith ?_).rpow ?_ ?_ hg <;> positivity protected lemma IsBigO.sqrt (hfg : f =O[l] g) (hg : 0 ≤ᶠ[l] g) : (Real.sqrt <| f ·) =O[l] (Real.sqrt <| g ·) := by simpa [Real.sqrt_eq_rpow] using hfg.rpow one_half_pos.le hg protected lemma IsLittleO.sqrt (hfg : f =o[l] g) (hg : 0 ≤ᶠ[l] g) : (Real.sqrt <| f ·) =o[l] (Real.sqrt <| g ·) := by simpa [Real.sqrt_eq_rpow] using hfg.rpow one_half_pos hg protected lemma IsTheta.sqrt (hfg : f =Θ[l] g) (hf : 0 ≤ᶠ[l] f) (hg : 0 ≤ᶠ[l] g) : (Real.sqrt <| f ·) =Θ[l] (Real.sqrt <| g ·) := ⟨hfg.1.sqrt hg, hfg.2.sqrt hf⟩ theorem isBigO_atTop_natCast_rpow_of_tendsto_div_rpow {𝕜 : Type*} [RCLike 𝕜] {g : ℕ → 𝕜} {a : 𝕜} {r : ℝ} (hlim : Tendsto (fun n ↦ g n / (n ^ r : ℝ)) atTop (𝓝 a)) : g =O[atTop] fun n ↦ (n : ℝ) ^ r := by refine (isBigO_of_div_tendsto_nhds ?_ ‖a‖ ?_).of_norm_left · filter_upwards [eventually_ne_atTop 0] with _ h simp [Real.rpow_eq_zero_iff_of_nonneg, h] · exact hlim.norm.congr fun n ↦ by simp [abs_of_nonneg, show 0 ≤ (n : ℝ) ^ r by positivity] variable {E : Type*} [SeminormedRing E] (a b c : ℝ) theorem IsBigO.mul_atTop_rpow_of_isBigO_rpow {f g : ℝ → E} (hf : f =O[atTop] fun t ↦ (t : ℝ) ^ a) (hg : g =O[atTop] fun t ↦ (t : ℝ) ^ b) (h : a + b ≤ c) : (f * g) =O[atTop] fun t ↦ (t : ℝ) ^ c := by refine (hf.mul hg).trans (Eventually.isBigO ?_) filter_upwards [eventually_ge_atTop 1] with t ht rw [← Real.rpow_add (zero_lt_one.trans_le ht), Real.norm_of_nonneg (Real.rpow_nonneg (zero_le_one.trans ht) (a + b))] exact Real.rpow_le_rpow_of_exponent_le ht h theorem IsBigO.mul_atTop_rpow_natCast_of_isBigO_rpow {f g : ℕ → E} (hf : f =O[atTop] fun n ↦ (n : ℝ) ^ a) (hg : g =O[atTop] fun n ↦ (n : ℝ) ^ b) (h : a + b ≤ c) : (f * g) =O[atTop] fun n ↦ (n : ℝ) ^ c := by refine (hf.mul hg).trans (Eventually.isBigO ?_) filter_upwards [eventually_ge_atTop 1] with t ht replace ht : 1 ≤ (t : ℝ) := Nat.one_le_cast.mpr ht rw [← Real.rpow_add (zero_lt_one.trans_le ht), Real.norm_of_nonneg (Real.rpow_nonneg (zero_le_one.trans ht) (a + b))] exact Real.rpow_le_rpow_of_exponent_le ht h end Asymptotics open Asymptotics /-- `x ^ s = o(exp(b * x))` as `x → ∞` for any real `s` and positive `b`. -/ theorem isLittleO_rpow_exp_pos_mul_atTop (s : ℝ) {b : ℝ} (hb : 0 < b) : (fun x : ℝ => x ^ s) =o[atTop] fun x => exp (b * x) := isLittleO_of_tendsto (fun _ h => absurd h (exp_pos _).ne') <| by simpa only [div_eq_mul_inv, exp_neg, neg_mul] using tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero s b hb /-- `x ^ k = o(exp(b * x))` as `x → ∞` for any integer `k` and positive `b`. -/
Mathlib/Analysis/SpecialFunctions/Pow/Asymptotics.lean
303
307
theorem isLittleO_zpow_exp_pos_mul_atTop (k : ℤ) {b : ℝ} (hb : 0 < b) : (fun x : ℝ => x ^ k) =o[atTop] fun x => exp (b * x) := by
simpa only [Real.rpow_intCast] using isLittleO_rpow_exp_pos_mul_atTop k hb /-- `x ^ k = o(exp(b * x))` as `x → ∞` for any natural `k` and positive `b`. -/
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Algebra.Ring.Int.Defs import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.Size import Batteries.Data.Int /-! # Bitwise operations on integers Possibly only of archaeological significance. ## Recursors * `Int.bitCasesOn`: Parity disjunction. Something is true/defined on `ℤ` if it's true/defined for even and for odd values. -/ namespace Int /-- `div2 n = n/2` -/ def div2 : ℤ → ℤ | (n : ℕ) => n.div2 | -[n +1] => negSucc n.div2 /-- `bodd n` returns `true` if `n` is odd -/ def bodd : ℤ → Bool | (n : ℕ) => n.bodd | -[n +1] => not (n.bodd) /-- `bit b` appends the digit `b` to the binary representation of its integer input. -/ def bit (b : Bool) : ℤ → ℤ := cond b (2 * · + 1) (2 * ·) /-- `Int.natBitwise` is an auxiliary definition for `Int.bitwise`. -/ def natBitwise (f : Bool → Bool → Bool) (m n : ℕ) : ℤ := cond (f false false) -[ Nat.bitwise (fun x y => not (f x y)) m n +1] (Nat.bitwise f m n) /-- `Int.bitwise` applies the function `f` to pairs of bits in the same position in the binary representations of its inputs. -/ def bitwise (f : Bool → Bool → Bool) : ℤ → ℤ → ℤ | (m : ℕ), (n : ℕ) => natBitwise f m n | (m : ℕ), -[n +1] => natBitwise (fun x y => f x (not y)) m n | -[m +1], (n : ℕ) => natBitwise (fun x y => f (not x) y) m n | -[m +1], -[n +1] => natBitwise (fun x y => f (not x) (not y)) m n /-- `lnot` flips all the bits in the binary representation of its input -/ def lnot : ℤ → ℤ | (m : ℕ) => -[m +1] | -[m +1] => m /-- `lor` takes two integers and returns their bitwise `or` -/ def lor : ℤ → ℤ → ℤ | (m : ℕ), (n : ℕ) => m ||| n | (m : ℕ), -[n +1] => -[Nat.ldiff n m +1] | -[m +1], (n : ℕ) => -[Nat.ldiff m n +1] | -[m +1], -[n +1] => -[m &&& n +1] /-- `land` takes two integers and returns their bitwise `and` -/ def land : ℤ → ℤ → ℤ | (m : ℕ), (n : ℕ) => m &&& n | (m : ℕ), -[n +1] => Nat.ldiff m n | -[m +1], (n : ℕ) => Nat.ldiff n m | -[m +1], -[n +1] => -[m ||| n +1] /-- `ldiff a b` performs bitwise set difference. For each corresponding pair of bits taken as booleans, say `aᵢ` and `bᵢ`, it applies the boolean operation `aᵢ ∧ bᵢ` to obtain the `iᵗʰ` bit of the result. -/ def ldiff : ℤ → ℤ → ℤ | (m : ℕ), (n : ℕ) => Nat.ldiff m n | (m : ℕ), -[n +1] => m &&& n | -[m +1], (n : ℕ) => -[m ||| n +1] | -[m +1], -[n +1] => Nat.ldiff n m /-- `xor` computes the bitwise `xor` of two natural numbers -/ protected def xor : ℤ → ℤ → ℤ | (m : ℕ), (n : ℕ) => (m ^^^ n) | (m : ℕ), -[n +1] => -[(m ^^^ n) +1] | -[m +1], (n : ℕ) => -[(m ^^^ n) +1] | -[m +1], -[n +1] => (m ^^^ n) /-- `m <<< n` produces an integer whose binary representation is obtained by left-shifting the binary representation of `m` by `n` places -/ instance : ShiftLeft ℤ where shiftLeft | (m : ℕ), (n : ℕ) => Nat.shiftLeft' false m n | (m : ℕ), -[n +1] => m >>> (Nat.succ n) | -[m +1], (n : ℕ) => -[Nat.shiftLeft' true m n +1] | -[m +1], -[n +1] => -[m >>> (Nat.succ n) +1] /-- `m >>> n` produces an integer whose binary representation is obtained by right-shifting the binary representation of `m` by `n` places -/ instance : ShiftRight ℤ where shiftRight m n := m <<< (-n) /-! ### bitwise ops -/ @[simp] theorem bodd_zero : bodd 0 = false := rfl @[simp] theorem bodd_one : bodd 1 = true := rfl theorem bodd_two : bodd 2 = false := rfl @[simp, norm_cast] theorem bodd_coe (n : ℕ) : Int.bodd n = Nat.bodd n := rfl @[simp] theorem bodd_subNatNat (m n : ℕ) : bodd (subNatNat m n) = xor m.bodd n.bodd := by apply subNatNat_elim m n fun m n i => bodd i = xor m.bodd n.bodd <;> intros i j <;> simp only [Int.bodd, Int.bodd_coe, Nat.bodd_add] <;> cases Nat.bodd i <;> simp @[simp] theorem bodd_negOfNat (n : ℕ) : bodd (negOfNat n) = n.bodd := by cases n <;> simp +decide rfl @[simp] theorem bodd_neg (n : ℤ) : bodd (-n) = bodd n := by cases n <;> simp only [← negOfNat_eq, bodd_negOfNat, neg_negSucc] <;> simp [bodd] @[simp] theorem bodd_add (m n : ℤ) : bodd (m + n) = xor (bodd m) (bodd n) := by rcases m with m | m <;> rcases n with n | n <;> simp only [ofNat_eq_coe, ofNat_add_negSucc, negSucc_add_ofNat, negSucc_add_negSucc, bodd_subNatNat, ← Nat.cast_add] <;> simp [bodd, Bool.xor_comm] @[simp] theorem bodd_mul (m n : ℤ) : bodd (m * n) = (bodd m && bodd n) := by rcases m with m | m <;> rcases n with n | n <;> simp only [ofNat_eq_coe, ofNat_mul_negSucc, negSucc_mul_ofNat, ofNat_mul_ofNat, negSucc_mul_negSucc] <;> simp only [negSucc_eq, ← Int.natCast_succ, bodd_neg, bodd_coe, Nat.bodd_mul] theorem bodd_add_div2 : ∀ n, cond (bodd n) 1 0 + 2 * div2 n = n | (n : ℕ) => by rw [show (cond (bodd n) 1 0 : ℤ) = (cond (bodd n) 1 0 : ℕ) by cases bodd n <;> rfl] exact congr_arg ofNat n.bodd_add_div2 | -[n+1] => by refine Eq.trans ?_ (congr_arg negSucc n.bodd_add_div2) dsimp [bodd]; cases Nat.bodd n <;> dsimp [cond, not, div2, Int.mul] · change -[2 * Nat.div2 n+1] = _ rw [zero_add] · rw [zero_add, add_comm] rfl
Mathlib/Data/Int/Bitwise.lean
159
167
theorem div2_val : ∀ n, div2 n = n / 2 | (n : ℕ) => congr_arg ofNat n.div2_val | -[n+1] => congr_arg negSucc n.div2_val theorem bit_val (b n) : bit b n = 2 * n + cond b 1 0 := by
cases b · apply (add_zero _).symm · rfl
/- Copyright (c) 2022 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky, Floris van Doorn -/ import Mathlib.Data.Nat.Find import Mathlib.Data.PNat.Basic /-! # Explicit least witnesses to existentials on positive natural numbers Implemented via calling out to `Nat.find`. -/ namespace PNat variable {p q : ℕ+ → Prop} [DecidablePred p] [DecidablePred q] (h : ∃ n, p n) instance decidablePredExistsNat : DecidablePred fun n' : ℕ => ∃ (n : ℕ+) (_ : n' = n), p n := fun n' => decidable_of_iff' (∃ h : 0 < n', p ⟨n', h⟩) <| Subtype.exists.trans <| by simp_rw [mk_coe, @exists_comm (_ < _) (_ = _), exists_prop, exists_eq_left'] /-- The `PNat` version of `Nat.findX` -/ protected def findX : { n // p n ∧ ∀ m : ℕ+, m < n → ¬p m } := by have : ∃ (n' : ℕ) (n : ℕ+) (_ : n' = n), p n := Exists.elim h fun n hn => ⟨n, n, rfl, hn⟩ have n := Nat.findX this refine ⟨⟨n, ?_⟩, ?_, fun m hm pm => ?_⟩ · obtain ⟨n', hn', -⟩ := n.prop.1 rw [hn'] exact n'.prop · obtain ⟨n', hn', pn'⟩ := n.prop.1 simpa [hn', Subtype.coe_eta] using pn' · exact n.prop.2 m hm ⟨m, rfl, pm⟩ /-- If `p` is a (decidable) predicate on `ℕ+` and `hp : ∃ (n : ℕ+), p n` is a proof that there exists some positive natural number satisfying `p`, then `PNat.find hp` is the smallest positive natural number satisfying `p`. Note that `PNat.find` is protected, meaning that you can't just write `find`, even if the `PNat` namespace is open. The API for `PNat.find` is: * `PNat.find_spec` is the proof that `PNat.find hp` satisfies `p`. * `PNat.find_min` is the proof that if `m < PNat.find hp` then `m` does not satisfy `p`. * `PNat.find_min'` is the proof that if `m` does satisfy `p` then `PNat.find hp ≤ m`. -/ protected def find : ℕ+ := PNat.findX h protected theorem find_spec : p (PNat.find h) := (PNat.findX h).prop.left protected theorem find_min : ∀ {m : ℕ+}, m < PNat.find h → ¬p m := @(PNat.findX h).prop.right protected theorem find_min' {m : ℕ+} (hm : p m) : PNat.find h ≤ m := le_of_not_lt fun l => PNat.find_min h l hm variable {n m : ℕ+} theorem find_eq_iff : PNat.find h = m ↔ p m ∧ ∀ n < m, ¬p n := by constructor · rintro rfl exact ⟨PNat.find_spec h, fun _ => PNat.find_min h⟩ · rintro ⟨hm, hlt⟩ exact le_antisymm (PNat.find_min' h hm) (not_lt.1 <| imp_not_comm.1 (hlt _) <| PNat.find_spec h) @[simp] theorem find_lt_iff (n : ℕ+) : PNat.find h < n ↔ ∃ m < n, p m := ⟨fun h2 => ⟨PNat.find h, h2, PNat.find_spec h⟩, fun ⟨_, hmn, hm⟩ => (PNat.find_min' h hm).trans_lt hmn⟩ @[simp] theorem find_le_iff (n : ℕ+) : PNat.find h ≤ n ↔ ∃ m ≤ n, p m := by simp only [exists_prop, ← lt_add_one_iff, find_lt_iff] @[simp] theorem le_find_iff (n : ℕ+) : n ≤ PNat.find h ↔ ∀ m < n, ¬p m := by simp only [← not_lt, find_lt_iff, not_exists, not_and] @[simp] theorem lt_find_iff (n : ℕ+) : n < PNat.find h ↔ ∀ m ≤ n, ¬p m := by simp only [← add_one_le_iff, le_find_iff, add_le_add_iff_right] @[simp] theorem find_eq_one : PNat.find h = 1 ↔ p 1 := by simp [find_eq_iff]
Mathlib/Data/PNat/Find.lean
91
92
theorem one_le_find : 1 < PNat.find h ↔ ¬p 1 := by
simp
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.BigOperators.Group.Finset.Indicator import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.Tactic.FinCases /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := by ext x fin_cases x <;> simp variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ι : Type*} (s : Finset ι) variable {ι₂ : Type*} (s₂ : Finset ι₂) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ι → P) (b : P) : (ι → k) →ₗ[k] V := ∑ i ∈ s, (LinearMap.proj i : (ι → k) →ₗ[k] k).smulRight (p i -ᵥ b) @[simp] theorem weightedVSubOfPoint_apply (w : ι → k) (p : ι → P) (b : P) : s.weightedVSubOfPoint p b w = ∑ i ∈ s, w i • (p i -ᵥ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ι → k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (∑ i ∈ s, w i) • (p -ᵥ b) := by rw [weightedVSubOfPoint_apply, sum_smul] lemma weightedVSubOfPoint_vadd (s : Finset ι) (w : ι → k) (p : ι → P) (b : P) (v : V) : s.weightedVSubOfPoint (v +ᵥ p) b w = s.weightedVSubOfPoint p (-v +ᵥ b) w := by simp [vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, add_comm] lemma weightedVSubOfPoint_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] (s : Finset ι) (w : ι → k) (p : ι → V) (b : V) (a : G) : s.weightedVSubOfPoint (a • p) b w = a • s.weightedVSubOfPoint p (a⁻¹ • b) w := by simp [smul_sum, smul_sub, smul_comm a (w _)] /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint p₂ b w₂ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ι → P) (j : ι) (w₁ w₂ : ι → k) (hw : ∀ i, i ≠ j → w₁ i = w₂ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) w₂ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h · simp [h] · simp [hw i h] /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/ theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p b₂ w := by apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul] /-- The weighted sum, added to the base point, is independent of the base point when the sum of the weights is 1. -/ theorem weightedVSubOfPoint_vadd_eq_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w +ᵥ b₁ = s.weightedVSubOfPoint p b₂ w +ᵥ b₂ := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← @vsub_eq_zero_iff_eq V, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← add_sub_assoc, add_comm, add_sub_assoc, ← sum_sub_distrib] conv_lhs => congr · skip · congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, one_smul, vsub_add_vsub_cancel, vsub_self] /-- The weighted sum is unaffected by removing the base point, if present, from the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_erase [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (s.erase i).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_erase rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by adding the base point, whether or not present, to the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_insert [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (insert i s).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_insert_zero rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSubOfPoint_indicator_subset (w : ι → k) (p : ι → P) (b : P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint p b (Set.indicator (↑s₁) w) := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] exact Eq.symm <| sum_indicator_subset_of_eq_zero w (fun i wi => wi • (p i -ᵥ b : V)) h fun i => zero_smul k _ /-- A weighted sum, over the image of an embedding, equals a weighted sum with the same points and weights over the original `Finset`. -/ theorem weightedVSubOfPoint_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) (b : P) : (s₂.map e).weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint (p ∘ e) b (w ∘ e) := by simp_rw [weightedVSubOfPoint_apply] exact Finset.sum_map _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSubOfPoint` expressions. -/ theorem sum_smul_vsub_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ p₂ : ι → P) (b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSubOfPoint p₁ b w - s.weightedVSubOfPoint p₂ b w := by simp_rw [weightedVSubOfPoint_apply, ← sum_sub_distrib, ← smul_sub, vsub_sub_vsub_cancel_right] /-- A weighted sum of pairwise subtractions, where the point on the right is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_vsub_const_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ : ι → P) (p₂ b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSubOfPoint p₁ b w - (∑ i ∈ s, w i) • (p₂ -ᵥ b) := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum of pairwise subtractions, where the point on the left is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_const_vsub_eq_sub_weightedVSubOfPoint (w : ι → k) (p₂ : ι → P) (p₁ b : P) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = (∑ i ∈ s, w i) • (p₁ -ᵥ b) - s.weightedVSubOfPoint p₂ b w := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w + s₂.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, sum_sdiff h] /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w - s₂.weightedVSubOfPoint p b (-w) = s.weightedVSubOfPoint p b w := by rw [map_neg, sub_neg_eq_add, s.weightedVSubOfPoint_sdiff h] /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSubOfPoint_subtype_eq_filter (w : ι → k) (p : ι → P) (b : P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSubOfPoint (fun i => p i) b fun i => w i) = {x ∈ s | pred x}.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_subtype_eq_sum_filter] /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSubOfPoint_filter_of_ne (w : ι → k) (p : ι → P) (b : P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, sum_filter_of_ne] intro i hi hne refine h i hi ?_ intro hw simp [hw] at hne /-- A constant multiplier of the weights in `weightedVSubOfPoint` may be moved outside the sum. -/ theorem weightedVSubOfPoint_const_smul (w : ι → k) (p : ι → P) (b : P) (c : k) : s.weightedVSubOfPoint p b (c • w) = c • s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, smul_sum, Pi.smul_apply, smul_smul, smul_eq_mul] /-- A weighted sum of the results of subtracting a default base point from the given points, as a linear map on the weights. This is intended to be used when the sum of the weights is 0; that condition is specified as a hypothesis on those lemmas that require it. -/ def weightedVSub (p : ι → P) : (ι → k) →ₗ[k] V := s.weightedVSubOfPoint p (Classical.choice S.nonempty) /-- Applying `weightedVSub` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `weightedVSub` would involve selecting a preferred base point with `weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero` and then using `weightedVSubOfPoint_apply`. -/ theorem weightedVSub_apply (w : ι → k) (p : ι → P) : s.weightedVSub p w = ∑ i ∈ s, w i • (p i -ᵥ Classical.choice S.nonempty) := by simp [weightedVSub, LinearMap.sum_apply] /-- `weightedVSub` gives the sum of the results of subtracting any base point, when the sum of the weights is 0. -/ theorem weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b : P) : s.weightedVSub p w = s.weightedVSubOfPoint p b w := s.weightedVSubOfPoint_eq_of_sum_eq_zero w p h _ _ /-- The value of `weightedVSub`, where the given points are equal and the sum of the weights is 0. -/ @[simp] theorem weightedVSub_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 0) : s.weightedVSub (fun _ => p) w = 0 := by rw [weightedVSub, weightedVSubOfPoint_apply_const, h, zero_smul] /-- The `weightedVSub` for an empty set is 0. -/ @[simp] theorem weightedVSub_empty (w : ι → k) (p : ι → P) : (∅ : Finset ι).weightedVSub p w = (0 : V) := by simp [weightedVSub_apply] lemma weightedVSub_vadd {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → P) (v : V) : s.weightedVSub (v +ᵥ p) w = s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_vadd, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] lemma weightedVSub_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → V) (a : G) : s.weightedVSub (a • p) w = a • s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_smul, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] /-- `weightedVSub` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSub_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.weightedVSub p₁ w₁ = s.weightedVSub p₂ w₂ := s.weightedVSubOfPoint_congr hw hp _ /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSub_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSub p w = s₂.weightedVSub p (Set.indicator (↑s₁) w) := weightedVSubOfPoint_indicator_subset _ _ _ h /-- A weighted subtraction, over the image of an embedding, equals a weighted subtraction with the same points and weights over the original `Finset`. -/ theorem weightedVSub_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).weightedVSub p w = s₂.weightedVSub (p ∘ e) (w ∘ e) := s₂.weightedVSubOfPoint_map _ _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSub` expressions. -/ theorem sum_smul_vsub_eq_weightedVSub_sub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSub p₁ w - s.weightedVSub p₂ w := s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 0. -/ theorem sum_smul_vsub_const_eq_weightedVSub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSub p₁ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, sub_zero] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 0. -/ theorem sum_smul_const_vsub_eq_neg_weightedVSub (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = -s.weightedVSub p₂ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, zero_sub] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSub_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w + s₂.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff h _ _ _ /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSub_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w - s₂.weightedVSub p (-w) = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff_sub h _ _ _ /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSub_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSub (fun i => p i) fun i => w i) = {x ∈ s | pred x}.weightedVSub p w := s.weightedVSubOfPoint_subtype_eq_filter _ _ _ _ /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSub_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_filter_of_ne _ _ _ h /-- A constant multiplier of the weights in `weightedVSub_of` may be moved outside the sum. -/ theorem weightedVSub_const_smul (w : ι → k) (p : ι → P) (c : k) : s.weightedVSub p (c • w) = c • s.weightedVSub p w := s.weightedVSubOfPoint_const_smul _ _ _ _ instance : AffineSpace (ι → k) (ι → k) := Pi.instAddTorsor variable (k) /-- A weighted sum of the results of subtracting a default base point from the given points, added to that base point, as an affine map on the weights. This is intended to be used when the sum of the weights is 1, in which case it is an affine combination (barycenter) of the points with the given weights; that condition is specified as a hypothesis on those lemmas that require it. -/ def affineCombination (p : ι → P) : (ι → k) →ᵃ[k] P where toFun w := s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty linear := s.weightedVSub p map_vadd' w₁ w₂ := by simp_rw [vadd_vadd, weightedVSub, vadd_eq_add, LinearMap.map_add] /-- The linear map corresponding to `affineCombination` is `weightedVSub`. -/ @[simp] theorem affineCombination_linear (p : ι → P) : (s.affineCombination k p).linear = s.weightedVSub p := rfl variable {k} /-- Applying `affineCombination` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `affineCombination` would involve selecting a preferred base point with `affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one` and then using `weightedVSubOfPoint_apply`. -/ theorem affineCombination_apply (w : ι → k) (p : ι → P) : (s.affineCombination k p) w = s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty := rfl /-- The value of `affineCombination`, where the given points are equal. -/ @[simp] theorem affineCombination_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 1) : s.affineCombination k (fun _ => p) w = p := by rw [affineCombination_apply, s.weightedVSubOfPoint_apply_const, h, one_smul, vsub_vadd] /-- `affineCombination` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem affineCombination_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.affineCombination k p₁ w₁ = s.affineCombination k p₂ w₂ := by simp_rw [affineCombination_apply, s.weightedVSubOfPoint_congr hw hp] /-- `affineCombination` gives the sum with any base point, when the sum of the weights is 1. -/ theorem affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b : P) : s.affineCombination k p w = s.weightedVSubOfPoint p b w +ᵥ b := s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w p h _ _ /-- Adding a `weightedVSub` to an `affineCombination`. -/ theorem weightedVSub_vadd_affineCombination (w₁ w₂ : ι → k) (p : ι → P) : s.weightedVSub p w₁ +ᵥ s.affineCombination k p w₂ = s.affineCombination k p (w₁ + w₂) := by rw [← vadd_eq_add, AffineMap.map_vadd, affineCombination_linear] /-- Subtracting two `affineCombination`s. -/ theorem affineCombination_vsub (w₁ w₂ : ι → k) (p : ι → P) : s.affineCombination k p w₁ -ᵥ s.affineCombination k p w₂ = s.weightedVSub p (w₁ - w₂) := by rw [← AffineMap.linearMap_vsub, affineCombination_linear, vsub_eq_sub] theorem attach_affineCombination_of_injective [DecidableEq P] (s : Finset P) (w : P → k) (f : s → P) (hf : Function.Injective f) : s.attach.affineCombination k f (w ∘ f) = (image f univ).affineCombination k id w := by simp only [affineCombination, weightedVSubOfPoint_apply, id, vadd_right_cancel_iff, Function.comp_apply, AffineMap.coe_mk] let g₁ : s → V := fun i => w (f i) • (f i -ᵥ Classical.choice S.nonempty) let g₂ : P → V := fun i => w i • (i -ᵥ Classical.choice S.nonempty) change univ.sum g₁ = (image f univ).sum g₂ have hgf : g₁ = g₂ ∘ f := by ext simp [g₁, g₂] rw [hgf, sum_image] · simp only [g₁, g₂,Function.comp_apply] · exact fun _ _ _ _ hxy => hf hxy theorem attach_affineCombination_coe (s : Finset P) (w : P → k) : s.attach.affineCombination k ((↑) : s → P) (w ∘ (↑)) = s.affineCombination k id w := by classical rw [attach_affineCombination_of_injective s w ((↑) : s → P) Subtype.coe_injective, univ_eq_attach, attach_image_val] /-- Viewing a module as an affine space modelled on itself, a `weightedVSub` is just a linear combination. -/ @[simp] theorem weightedVSub_eq_linear_combination {ι} (s : Finset ι) {w : ι → k} {p : ι → V} (hw : s.sum w = 0) : s.weightedVSub p w = ∑ i ∈ s, w i • p i := by simp [s.weightedVSub_apply, vsub_eq_sub, smul_sub, ← Finset.sum_smul, hw] /-- Viewing a module as an affine space modelled on itself, affine combinations are just linear combinations. -/ @[simp] theorem affineCombination_eq_linear_combination (s : Finset ι) (p : ι → V) (w : ι → k) (hw : ∑ i ∈ s, w i = 1) : s.affineCombination k p w = ∑ i ∈ s, w i • p i := by simp [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw 0] /-- An `affineCombination` equals a point if that point is in the set and has weight 1 and the other points in the set have weight 0. -/ @[simp] theorem affineCombination_of_eq_one_of_eq_zero (w : ι → k) (p : ι → P) {i : ι} (his : i ∈ s) (hwi : w i = 1) (hw0 : ∀ i2 ∈ s, i2 ≠ i → w i2 = 0) : s.affineCombination k p w = p i := by have h1 : ∑ i ∈ s, w i = 1 := hwi ▸ sum_eq_single i hw0 fun h => False.elim (h his) rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h1 (p i), weightedVSubOfPoint_apply] convert zero_vadd V (p i) refine sum_eq_zero ?_ intro i2 hi2 by_cases h : i2 = i · simp [h] · simp [hw0 i2 hi2 h] /-- An affine combination is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem affineCombination_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.affineCombination k p w = s₂.affineCombination k p (Set.indicator (↑s₁) w) := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_indicator_subset _ _ _ h] /-- An affine combination, over the image of an embedding, equals an affine combination with the same points and weights over the original `Finset`. -/
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
464
466
theorem affineCombination_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).affineCombination k p w = s₂.affineCombination k (p ∘ e) (w ∘ e) := by
simp_rw [affineCombination_apply, weightedVSubOfPoint_map]
/- 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, Mario Carneiro -/ import Mathlib.Data.Set.Countable import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Tactic.FunProp.Attr import Mathlib.Tactic.Measurability /-! # Measurable spaces and measurable functions This file defines measurable spaces and measurable functions. A measurable space is a set equipped with a σ-algebra, a collection of subsets closed under complementation and countable union. A function between measurable spaces is measurable if the preimage of each measurable subset is measurable. σ-algebras on a fixed set `α` form a complete lattice. Here we order σ-algebras by writing `m₁ ≤ m₂` if every set which is `m₁`-measurable is also `m₂`-measurable (that is, `m₁` is a subset of `m₂`). In particular, any collection of subsets of `α` generates a smallest σ-algebra which contains all of them. ## References * <https://en.wikipedia.org/wiki/Measurable_space> * <https://en.wikipedia.org/wiki/Sigma-algebra> * <https://en.wikipedia.org/wiki/Dynkin_system> ## Tags measurable space, σ-algebra, measurable function -/ assert_not_exists Covariant MonoidWithZero open Set Encodable Function Equiv variable {α β γ δ δ' : Type*} {ι : Sort*} {s t u : Set α} /-- A measurable space is a space equipped with a σ-algebra. -/ @[class] structure MeasurableSpace (α : Type*) where /-- Predicate saying that a given set is measurable. Use `MeasurableSet` in the root namespace instead. -/ MeasurableSet' : Set α → Prop /-- The empty set is a measurable set. Use `MeasurableSet.empty` instead. -/ measurableSet_empty : MeasurableSet' ∅ /-- The complement of a measurable set is a measurable set. Use `MeasurableSet.compl` instead. -/ measurableSet_compl : ∀ s, MeasurableSet' s → MeasurableSet' sᶜ /-- The union of a sequence of measurable sets is a measurable set. Use a more general `MeasurableSet.iUnion` instead. -/ measurableSet_iUnion : ∀ f : ℕ → Set α, (∀ i, MeasurableSet' (f i)) → MeasurableSet' (⋃ i, f i) instance [h : MeasurableSpace α] : MeasurableSpace αᵒᵈ := h /-- `MeasurableSet s` means that `s` is measurable (in the ambient measure space on `α`) -/ def MeasurableSet [MeasurableSpace α] (s : Set α) : Prop := ‹MeasurableSpace α›.MeasurableSet' s /-- Notation for `MeasurableSet` with respect to a non-standard σ-algebra. -/ scoped[MeasureTheory] notation "MeasurableSet[" m "]" => @MeasurableSet _ m open MeasureTheory section open scoped symmDiff @[simp, measurability] theorem MeasurableSet.empty [MeasurableSpace α] : MeasurableSet (∅ : Set α) := MeasurableSpace.measurableSet_empty _ variable {m : MeasurableSpace α} @[measurability] protected theorem MeasurableSet.compl : MeasurableSet s → MeasurableSet sᶜ := MeasurableSpace.measurableSet_compl _ s protected theorem MeasurableSet.of_compl (h : MeasurableSet sᶜ) : MeasurableSet s := compl_compl s ▸ h.compl @[simp] theorem MeasurableSet.compl_iff : MeasurableSet sᶜ ↔ MeasurableSet s := ⟨.of_compl, .compl⟩ @[simp, measurability] protected theorem MeasurableSet.univ : MeasurableSet (univ : Set α) := .of_compl <| by simp @[nontriviality, measurability] theorem Subsingleton.measurableSet [Subsingleton α] {s : Set α} : MeasurableSet s := Subsingleton.set_cases MeasurableSet.empty MeasurableSet.univ s theorem MeasurableSet.congr {s t : Set α} (hs : MeasurableSet s) (h : s = t) : MeasurableSet t := by rwa [← h] @[measurability] protected theorem MeasurableSet.iUnion [Countable ι] ⦃f : ι → Set α⦄ (h : ∀ b, MeasurableSet (f b)) : MeasurableSet (⋃ b, f b) := by cases isEmpty_or_nonempty ι · simp · rcases exists_surjective_nat ι with ⟨e, he⟩ rw [← iUnion_congr_of_surjective _ he (fun _ => rfl)] exact m.measurableSet_iUnion _ fun _ => h _ protected theorem MeasurableSet.biUnion {f : β → Set α} {s : Set β} (hs : s.Countable) (h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋃ b ∈ s, f b) := by rw [biUnion_eq_iUnion] have := hs.to_subtype exact MeasurableSet.iUnion (by simpa using h) theorem Set.Finite.measurableSet_biUnion {f : β → Set α} {s : Set β} (hs : s.Finite) (h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋃ b ∈ s, f b) := .biUnion hs.countable h theorem Finset.measurableSet_biUnion {f : β → Set α} (s : Finset β) (h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋃ b ∈ s, f b) := s.finite_toSet.measurableSet_biUnion h protected theorem MeasurableSet.sUnion {s : Set (Set α)} (hs : s.Countable) (h : ∀ t ∈ s, MeasurableSet t) : MeasurableSet (⋃₀ s) := by rw [sUnion_eq_biUnion] exact .biUnion hs h theorem Set.Finite.measurableSet_sUnion {s : Set (Set α)} (hs : s.Finite) (h : ∀ t ∈ s, MeasurableSet t) : MeasurableSet (⋃₀ s) := MeasurableSet.sUnion hs.countable h @[measurability] theorem MeasurableSet.iInter [Countable ι] {f : ι → Set α} (h : ∀ b, MeasurableSet (f b)) : MeasurableSet (⋂ b, f b) := .of_compl <| by rw [compl_iInter]; exact .iUnion fun b => (h b).compl theorem MeasurableSet.biInter {f : β → Set α} {s : Set β} (hs : s.Countable) (h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋂ b ∈ s, f b) := .of_compl <| by rw [compl_iInter₂]; exact .biUnion hs fun b hb => (h b hb).compl theorem Set.Finite.measurableSet_biInter {f : β → Set α} {s : Set β} (hs : s.Finite) (h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋂ b ∈ s, f b) := .biInter hs.countable h theorem Finset.measurableSet_biInter {f : β → Set α} (s : Finset β) (h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋂ b ∈ s, f b) := s.finite_toSet.measurableSet_biInter h theorem MeasurableSet.sInter {s : Set (Set α)} (hs : s.Countable) (h : ∀ t ∈ s, MeasurableSet t) : MeasurableSet (⋂₀ s) := by rw [sInter_eq_biInter] exact MeasurableSet.biInter hs h theorem Set.Finite.measurableSet_sInter {s : Set (Set α)} (hs : s.Finite) (h : ∀ t ∈ s, MeasurableSet t) : MeasurableSet (⋂₀ s) := MeasurableSet.sInter hs.countable h @[simp, measurability] protected theorem MeasurableSet.union {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁) (h₂ : MeasurableSet s₂) : MeasurableSet (s₁ ∪ s₂) := by rw [union_eq_iUnion] exact .iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩) @[simp, measurability] protected theorem MeasurableSet.inter {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁) (h₂ : MeasurableSet s₂) : MeasurableSet (s₁ ∩ s₂) := by rw [inter_eq_compl_compl_union_compl] exact (h₁.compl.union h₂.compl).compl @[simp, measurability] protected theorem MeasurableSet.diff {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁) (h₂ : MeasurableSet s₂) : MeasurableSet (s₁ \ s₂) := h₁.inter h₂.compl @[simp, measurability] protected lemma MeasurableSet.himp {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁) (h₂ : MeasurableSet s₂) : MeasurableSet (s₁ ⇨ s₂) := by rw [himp_eq]; exact h₂.union h₁.compl @[simp, measurability] protected theorem MeasurableSet.symmDiff {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁) (h₂ : MeasurableSet s₂) : MeasurableSet (s₁ ∆ s₂) := (h₁.diff h₂).union (h₂.diff h₁) @[simp, measurability] protected lemma MeasurableSet.bihimp {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁) (h₂ : MeasurableSet s₂) : MeasurableSet (s₁ ⇔ s₂) := (h₂.himp h₁).inter (h₁.himp h₂) @[simp, measurability] protected theorem MeasurableSet.ite {t s₁ s₂ : Set α} (ht : MeasurableSet t) (h₁ : MeasurableSet s₁) (h₂ : MeasurableSet s₂) : MeasurableSet (t.ite s₁ s₂) := (h₁.inter ht).union (h₂.diff ht) open Classical in theorem MeasurableSet.ite' {s t : Set α} {p : Prop} (hs : p → MeasurableSet s) (ht : ¬p → MeasurableSet t) : MeasurableSet (ite p s t) := by split_ifs with h exacts [hs h, ht h] @[simp, measurability] protected theorem MeasurableSet.cond {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁) (h₂ : MeasurableSet s₂) {i : Bool} : MeasurableSet (cond i s₁ s₂) := by cases i exacts [h₂, h₁] protected theorem MeasurableSet.const (p : Prop) : MeasurableSet { _a : α | p } := by by_cases p <;> simp [*] /-- Every set has a measurable superset. Declare this as local instance as needed. -/ theorem nonempty_measurable_superset (s : Set α) : Nonempty { t // s ⊆ t ∧ MeasurableSet t } := ⟨⟨univ, subset_univ s, MeasurableSet.univ⟩⟩ end theorem MeasurableSpace.measurableSet_injective : Injective (@MeasurableSet α) | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, _ => by congr @[ext] theorem MeasurableSpace.ext {m₁ m₂ : MeasurableSpace α} (h : ∀ s : Set α, MeasurableSet[m₁] s ↔ MeasurableSet[m₂] s) : m₁ = m₂ := measurableSet_injective <| funext fun s => propext (h s) /-- A typeclass mixin for `MeasurableSpace`s such that each singleton is measurable. -/ class MeasurableSingletonClass (α : Type*) [MeasurableSpace α] : Prop where /-- A singleton is a measurable set. -/ measurableSet_singleton : ∀ x, MeasurableSet ({x} : Set α) export MeasurableSingletonClass (measurableSet_singleton) @[simp] lemma MeasurableSet.singleton [MeasurableSpace α] [MeasurableSingletonClass α] (a : α) : MeasurableSet {a} := measurableSet_singleton a section MeasurableSingletonClass variable [MeasurableSpace α] [MeasurableSingletonClass α] @[measurability] theorem measurableSet_eq {a : α} : MeasurableSet { x | x = a } := .singleton a @[measurability] protected theorem MeasurableSet.insert {s : Set α} (hs : MeasurableSet s) (a : α) : MeasurableSet (insert a s) := .union (.singleton a) hs @[simp]
Mathlib/MeasureTheory/MeasurableSpace/Defs.lean
247
248
theorem measurableSet_insert {a : α} {s : Set α} : MeasurableSet (insert a s) ↔ MeasurableSet s := by
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Yury Kudryashov -/ import Mathlib.Topology.Algebra.Module.Equiv import Mathlib.Topology.Algebra.Module.UniformConvergence import Mathlib.Topology.Algebra.SeparationQuotient.Section import Mathlib.Topology.Hom.ContinuousEvalConst /-! # Strong topologies on the space of continuous linear maps In this file, we define the strong topologies on `E →L[𝕜] F` associated with a family `𝔖 : Set (Set E)` to be the topology of uniform convergence on the elements of `𝔖` (also called the topology of `𝔖`-convergence). The lemma `UniformOnFun.continuousSMul_of_image_bounded` tells us that this is a vector space topology if the continuous linear image of any element of `𝔖` is bounded (in the sense of `Bornology.IsVonNBounded`). We then declare an instance for the case where `𝔖` is exactly the set of all bounded subsets of `E`, giving us the so-called "topology of uniform convergence on bounded sets" (or "topology of bounded convergence"), which coincides with the operator norm topology in the case of `NormedSpace`s. Other useful examples include the weak-* topology (when `𝔖` is the set of finite sets or the set of singletons) and the topology of compact convergence (when `𝔖` is the set of relatively compact sets). ## Main definitions * `UniformConvergenceCLM` is a type synonym for `E →SL[σ] F` equipped with the `𝔖`-topology. * `UniformConvergenceCLM.instTopologicalSpace` is the topology mentioned above for an arbitrary `𝔖`. * `ContinuousLinearMap.topologicalSpace` is the topology of bounded convergence. This is declared as an instance. ## Main statements * `UniformConvergenceCLM.instIsTopologicalAddGroup` and `UniformConvergenceCLM.instContinuousSMul` show that the strong topology makes `E →L[𝕜] F` a topological vector space, with the assumptions on `𝔖` mentioned above. * `ContinuousLinearMap.topologicalAddGroup` and `ContinuousLinearMap.continuousSMul` register these facts as instances for the special case of bounded convergence. ## References * [N. Bourbaki, *Topological Vector Spaces*][bourbaki1987] ## TODO * Add convergence on compact subsets ## Tags uniform convergence, bounded convergence -/ open Bornology Filter Function Set Topology open scoped UniformConvergence Uniformity section General /-! ### 𝔖-Topologies -/ variable {𝕜₁ 𝕜₂ : Type*} [NormedField 𝕜₁] [NormedField 𝕜₂] (σ : 𝕜₁ →+* 𝕜₂) {E F : Type*} [AddCommGroup E] [Module 𝕜₁ E] [TopologicalSpace E] [AddCommGroup F] [Module 𝕜₂ F] variable (F) /-- Given `E` and `F` two topological vector spaces and `𝔖 : Set (Set E)`, then `UniformConvergenceCLM σ F 𝔖` is a type synonym of `E →SL[σ] F` equipped with the "topology of uniform convergence on the elements of `𝔖`". If the continuous linear image of any element of `𝔖` is bounded, this makes `E →SL[σ] F` a topological vector space. -/ @[nolint unusedArguments] def UniformConvergenceCLM [TopologicalSpace F] (_ : Set (Set E)) := E →SL[σ] F namespace UniformConvergenceCLM instance instFunLike [TopologicalSpace F] (𝔖 : Set (Set E)) : FunLike (UniformConvergenceCLM σ F 𝔖) E F := ContinuousLinearMap.funLike instance instContinuousSemilinearMapClass [TopologicalSpace F] (𝔖 : Set (Set E)) : ContinuousSemilinearMapClass (UniformConvergenceCLM σ F 𝔖) σ E F := ContinuousLinearMap.continuousSemilinearMapClass instance instTopologicalSpace [TopologicalSpace F] [IsTopologicalAddGroup F] (𝔖 : Set (Set E)) : TopologicalSpace (UniformConvergenceCLM σ F 𝔖) := (@UniformOnFun.topologicalSpace E F (IsTopologicalAddGroup.toUniformSpace F) 𝔖).induced (DFunLike.coe : (UniformConvergenceCLM σ F 𝔖) → (E →ᵤ[𝔖] F))
Mathlib/Topology/Algebra/Module/StrongTopology.lean
96
101
theorem topologicalSpace_eq [UniformSpace F] [IsUniformAddGroup F] (𝔖 : Set (Set E)) : instTopologicalSpace σ F 𝔖 = TopologicalSpace.induced (UniformOnFun.ofFun 𝔖 ∘ DFunLike.coe) (UniformOnFun.topologicalSpace E F 𝔖) := by
rw [instTopologicalSpace] congr exact IsUniformAddGroup.toUniformSpace_eq
/- 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 Batteries.Tactic.Init import Mathlib.Logic.Function.Defs /-! # Binary map of options This file defines the binary map of `Option`. This is mostly useful to define pointwise operations on intervals. ## Main declarations * `Option.map₂`: Binary map of options. ## Notes This file is very similar to the n-ary section of `Mathlib.Data.Set.Basic`, to `Mathlib.Data.Finset.NAry` and to `Mathlib.Order.Filter.NAry`. Please keep them in sync. We do not define `Option.map₃` as its only purpose so far would be to prove properties of `Option.map₂` and casing already fulfills this task. -/ universe u open Function namespace Option variable {α β γ δ : Type*} {f : α → β → γ} {a : Option α} {b : Option β} {c : Option γ} /-- The image of a binary function `f : α → β → γ` as a function `Option α → Option β → Option γ`. Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/ def map₂ (f : α → β → γ) (a : Option α) (b : Option β) : Option γ := a.bind fun a => b.map <| f a /-- `Option.map₂` in terms of monadic operations. Note that this can't be taken as the definition because of the lack of universe polymorphism. -/ theorem map₂_def {α β γ : Type u} (f : α → β → γ) (a : Option α) (b : Option β) : map₂ f a b = f <$> a <*> b := by cases a <;> rfl @[simp] theorem map₂_some_some (f : α → β → γ) (a : α) (b : β) : map₂ f (some a) (some b) = f a b := rfl theorem map₂_coe_coe (f : α → β → γ) (a : α) (b : β) : map₂ f a b = f a b := rfl @[simp] theorem map₂_none_left (f : α → β → γ) (b : Option β) : map₂ f none b = none := rfl @[simp] theorem map₂_none_right (f : α → β → γ) (a : Option α) : map₂ f a none = none := by cases a <;> rfl @[simp] theorem map₂_coe_left (f : α → β → γ) (a : α) (b : Option β) : map₂ f a b = b.map fun b => f a b := rfl -- Porting note: This proof was `rfl` in Lean3, but now is not. @[simp] theorem map₂_coe_right (f : α → β → γ) (a : Option α) (b : β) : map₂ f a b = a.map fun a => f a b := by cases a <;> rfl theorem mem_map₂_iff {c : γ} : c ∈ map₂ f a b ↔ ∃ a' b', a' ∈ a ∧ b' ∈ b ∧ f a' b' = c := by simp [map₂, bind_eq_some] /-- `simp`-normal form of `mem_map₂_iff`. -/ @[simp] theorem map₂_eq_some_iff {c : γ} : map₂ f a b = some c ↔ ∃ a' b', a' ∈ a ∧ b' ∈ b ∧ f a' b' = c := by simp [map₂, bind_eq_some] @[simp] theorem map₂_eq_none_iff : map₂ f a b = none ↔ a = none ∨ b = none := by cases a <;> cases b <;> simp theorem map₂_swap (f : α → β → γ) (a : Option α) (b : Option β) : map₂ f a b = map₂ (fun a b => f b a) b a := by cases a <;> cases b <;> rfl theorem map_map₂ (f : α → β → γ) (g : γ → δ) : (map₂ f a b).map g = map₂ (fun a b => g (f a b)) a b := by cases a <;> cases b <;> rfl theorem map₂_map_left (f : γ → β → δ) (g : α → γ) : map₂ f (a.map g) b = map₂ (fun a b => f (g a) b) a b := by cases a <;> rfl theorem map₂_map_right (f : α → γ → δ) (g : β → γ) : map₂ f a (b.map g) = map₂ (fun a b => f a (g b)) a b := by cases b <;> rfl @[simp] theorem map₂_curry (f : α × β → γ) (a : Option α) (b : Option β) : map₂ (curry f) a b = Option.map f (map₂ Prod.mk a b) := (map_map₂ _ _).symm @[simp] theorem map_uncurry (f : α → β → γ) (x : Option (α × β)) : x.map (uncurry f) = map₂ f (x.map Prod.fst) (x.map Prod.snd) := by cases x <;> rfl /-! ### Algebraic replacement rules A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations to the associativity, commutativity, distributivity, ... of `Option.map₂` of those operations. The proof pattern is `map₂_lemma operation_lemma`. For example, `map₂_comm mul_comm` proves that `map₂ (*) a b = map₂ (*) g f` in a `CommSemigroup`. -/ variable {α' β' δ' ε ε' : Type*} theorem map₂_assoc {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'} (h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) : map₂ f (map₂ g a b) c = map₂ f' a (map₂ g' b c) := by cases a <;> cases b <;> cases c <;> simp [h_assoc] theorem map₂_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : map₂ f a b = map₂ g b a := by cases a <;> cases b <;> simp [h_comm] theorem map₂_left_comm {f : α → δ → ε} {g : β → γ → δ} {f' : α → γ → δ'} {g' : β → δ' → ε} (h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) : map₂ f a (map₂ g b c) = map₂ g' b (map₂ f' a c) := by cases a <;> cases b <;> cases c <;> simp [h_left_comm] theorem map₂_right_comm {f : δ → γ → ε} {g : α → β → δ} {f' : α → γ → δ'} {g' : δ' → β → ε} (h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) : map₂ f (map₂ g a b) c = map₂ g' (map₂ f' a c) b := by cases a <;> cases b <;> cases c <;> simp [h_right_comm] theorem map_map₂_distrib {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'} (h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) : (map₂ f a b).map g = map₂ f' (a.map g₁) (b.map g₂) := by cases a <;> cases b <;> simp [h_distrib] /-! The following symmetric restatement are needed because unification has a hard time figuring all the functions if you symmetrize on the spot. This is also how the other n-ary APIs do it. -/ /-- Symmetric statement to `Option.map₂_map_left_comm`. -/
Mathlib/Data/Option/NAry.lean
140
143
theorem map_map₂_distrib_left {g : γ → δ} {f' : α' → β → δ} {g' : α → α'} (h_distrib : ∀ a b, g (f a b) = f' (g' a) b) : (map₂ f a b).map g = map₂ f' (a.map g') b := by
cases a <;> cases b <;> simp [h_distrib]
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.SetTheory.Cardinal.Finite /-! # Cardinality of finite types The cardinality of a finite type `α` is given by `Nat.card α`. This function has the "junk value" of `0` for infinite types, but to ensure the function has valid output, one just needs to know that it's possible to produce a `Finite` instance for the type. (Note: we could have defined a `Finite.card` that required you to supply a `Finite` instance, but (a) the function would be `noncomputable` anyway so there is no need to supply the instance and (b) the function would have a more complicated dependent type that easily leads to "motive not type correct" errors.) ## Implementation notes Theorems about `Nat.card` are sometimes incidentally true for both finite and infinite types. If removing a finiteness constraint results in no loss in legibility, we remove it. We generally put such theorems into the `SetTheory.Cardinal.Finite` module. -/ assert_not_exists Field noncomputable section variable {α β γ : Type*} /-- There is (noncomputably) an equivalence between a finite type `α` and `Fin (Nat.card α)`. -/ def Finite.equivFin (α : Type*) [Finite α] : α ≃ Fin (Nat.card α) := by have := (Finite.exists_equiv_fin α).choose_spec.some rwa [Nat.card_eq_of_equiv_fin this] /-- Similar to `Finite.equivFin` but with control over the term used for the cardinality. -/ def Finite.equivFinOfCardEq [Finite α] {n : ℕ} (h : Nat.card α = n) : α ≃ Fin n := by subst h apply Finite.equivFin open scoped Classical in theorem Nat.card_eq (α : Type*) : Nat.card α = if _ : Finite α then @Fintype.card α (Fintype.ofFinite α) else 0 := by cases finite_or_infinite α · letI := Fintype.ofFinite α simp only [this, *, Nat.card_eq_fintype_card, dif_pos] · simp only [*, card_eq_zero_of_infinite, not_finite_iff_infinite.mpr, dite_false] theorem Finite.card_pos_iff [Finite α] : 0 < Nat.card α ↔ Nonempty α := by haveI := Fintype.ofFinite α rw [Nat.card_eq_fintype_card, Fintype.card_pos_iff] theorem Finite.card_pos [Finite α] [h : Nonempty α] : 0 < Nat.card α := Finite.card_pos_iff.mpr h namespace Finite @[deprecated (since := "2025-02-21")] alias cast_card_eq_mk := Nat.cast_card theorem card_eq [Finite α] [Finite β] : Nat.card α = Nat.card β ↔ Nonempty (α ≃ β) := by haveI := Fintype.ofFinite α haveI := Fintype.ofFinite β simp only [Nat.card_eq_fintype_card, Fintype.card_eq] theorem card_le_one_iff_subsingleton [Finite α] : Nat.card α ≤ 1 ↔ Subsingleton α := by haveI := Fintype.ofFinite α simp only [Nat.card_eq_fintype_card, Fintype.card_le_one_iff_subsingleton]
Mathlib/Data/Finite/Card.lean
72
75
theorem one_lt_card_iff_nontrivial [Finite α] : 1 < Nat.card α ↔ Nontrivial α := by
haveI := Fintype.ofFinite α simp only [Nat.card_eq_fintype_card, Fintype.one_lt_card_iff_nontrivial]
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.LinearAlgebra.Basis.Submodule import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.LinearAlgebra.Matrix.ToLin /-! # Bases and matrices This file defines the map `Basis.toMatrix` that sends a family of vectors to the matrix of their coordinates with respect to some basis. ## Main definitions * `Basis.toMatrix e v` is the matrix whose `i, j`th entry is `e.repr (v j) i` * `basis.toMatrixEquiv` is `Basis.toMatrix` bundled as a linear equiv ## Main results * `LinearMap.toMatrix_id_eq_basis_toMatrix`: `LinearMap.toMatrix b c id` is equal to `Basis.toMatrix b c` * `Basis.toMatrix_mul_toMatrix`: multiplying `Basis.toMatrix` with another `Basis.toMatrix` gives a `Basis.toMatrix` ## Tags matrix, basis -/ noncomputable section open LinearMap Matrix Set Submodule open Matrix section BasisToMatrix variable {ι ι' κ κ' : Type*} variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {R₂ M₂ : Type*} [CommRing R₂] [AddCommGroup M₂] [Module R₂ M₂] open Function Matrix /-- From a basis `e : ι → M` and a family of vectors `v : ι' → M`, make the matrix whose columns are the vectors `v i` written in the basis `e`. -/ def Basis.toMatrix (e : Basis ι R M) (v : ι' → M) : Matrix ι ι' R := fun i j => e.repr (v j) i variable (e : Basis ι R M) (v : ι' → M) (i : ι) (j : ι') namespace Basis theorem toMatrix_apply : e.toMatrix v i j = e.repr (v j) i := rfl theorem toMatrix_transpose_apply : (e.toMatrix v)ᵀ j = e.repr (v j) := funext fun _ => rfl theorem toMatrix_eq_toMatrix_constr [Fintype ι] [DecidableEq ι] (v : ι → M) : e.toMatrix v = LinearMap.toMatrix e e (e.constr ℕ v) := by ext rw [Basis.toMatrix_apply, LinearMap.toMatrix_apply, Basis.constr_basis] -- TODO (maybe) Adjust the definition of `Basis.toMatrix` to eliminate the transpose. theorem coePiBasisFun.toMatrix_eq_transpose [Finite ι] : ((Pi.basisFun R ι).toMatrix : Matrix ι ι R → Matrix ι ι R) = Matrix.transpose := by ext M i j rfl @[simp] theorem toMatrix_self [DecidableEq ι] : e.toMatrix e = 1 := by unfold Basis.toMatrix ext i j simp [Basis.equivFun, Matrix.one_apply, Finsupp.single_apply, eq_comm] theorem toMatrix_update [DecidableEq ι'] (x : M) : e.toMatrix (Function.update v j x) = Matrix.updateCol (e.toMatrix v) j (e.repr x) := by ext i' k rw [Basis.toMatrix, Matrix.updateCol_apply, e.toMatrix_apply] split_ifs with h · rw [h, update_self j x v] · rw [update_of_ne h] /-- The basis constructed by `unitsSMul` has vectors given by a diagonal matrix. -/ @[simp] theorem toMatrix_unitsSMul [DecidableEq ι] (e : Basis ι R₂ M₂) (w : ι → R₂ˣ) : e.toMatrix (e.unitsSMul w) = diagonal ((↑) ∘ w) := by ext i j by_cases h : i = j · simp [h, toMatrix_apply, unitsSMul_apply, Units.smul_def] · simp [h, toMatrix_apply, unitsSMul_apply, Units.smul_def, Ne.symm h] /-- The basis constructed by `isUnitSMul` has vectors given by a diagonal matrix. -/ @[simp] theorem toMatrix_isUnitSMul [DecidableEq ι] (e : Basis ι R₂ M₂) {w : ι → R₂} (hw : ∀ i, IsUnit (w i)) : e.toMatrix (e.isUnitSMul hw) = diagonal w := e.toMatrix_unitsSMul _ theorem toMatrix_smul_left {G} [Group G] [DistribMulAction G M] [SMulCommClass G R M] (g : G) : (g • e).toMatrix v = e.toMatrix (g⁻¹ • v) := rfl @[simp] theorem sum_toMatrix_smul_self [Fintype ι] : ∑ i : ι, e.toMatrix v i j • e i = v j := by simp_rw [e.toMatrix_apply, e.sum_repr] theorem toMatrix_smul {R₁ S : Type*} [CommSemiring R₁] [Semiring S] [Algebra R₁ S] [Fintype ι] [DecidableEq ι] (x : S) (b : Basis ι R₁ S) (w : ι → S) : (b.toMatrix (x • w)) = (Algebra.leftMulMatrix b x) * (b.toMatrix w) := by ext rw [Basis.toMatrix_apply, Pi.smul_apply, smul_eq_mul, ← Algebra.leftMulMatrix_mulVec_repr] rfl theorem toMatrix_map_vecMul {S : Type*} [Semiring S] [Algebra R S] [Fintype ι] (b : Basis ι R S) (v : ι' → S) : b ᵥ* ((b.toMatrix v).map <| algebraMap R S) = v := by ext i simp_rw [vecMul, dotProduct, Matrix.map_apply, ← Algebra.commutes, ← Algebra.smul_def, sum_toMatrix_smul_self] @[simp] theorem toLin_toMatrix [Finite ι] [Fintype ι'] [DecidableEq ι'] (v : Basis ι' R M) : Matrix.toLin v e (e.toMatrix v) = LinearMap.id := v.ext fun i => by cases nonempty_fintype ι; rw [toLin_self, id_apply, e.sum_toMatrix_smul_self] /-- From a basis `e : ι → M`, build a linear equivalence between families of vectors `v : ι → M`, and matrices, making the matrix whose columns are the vectors `v i` written in the basis `e`. -/ def toMatrixEquiv [Fintype ι] (e : Basis ι R M) : (ι → M) ≃ₗ[R] Matrix ι ι R where toFun := e.toMatrix map_add' v w := by ext i j rw [Matrix.add_apply, e.toMatrix_apply, Pi.add_apply, LinearEquiv.map_add] rfl map_smul' := by intro c v ext i j dsimp only [] rw [e.toMatrix_apply, Pi.smul_apply, LinearEquiv.map_smul] rfl invFun m j := ∑ i, m i j • e i left_inv := by intro v ext j exact e.sum_toMatrix_smul_self v j right_inv := by intro m ext k l simp only [e.toMatrix_apply, ← e.equivFun_apply, ← e.equivFun_symm_apply, LinearEquiv.apply_symm_apply] variable (R₂) in theorem restrictScalars_toMatrix [Fintype ι] [DecidableEq ι] {S : Type*} [CommRing S] [Nontrivial S] [Algebra R₂ S] [Module S M₂] [IsScalarTower R₂ S M₂] [NoZeroSMulDivisors R₂ S] (b : Basis ι S M₂) (v : ι → span R₂ (Set.range b)) : (algebraMap R₂ S).mapMatrix ((b.restrictScalars R₂).toMatrix v) = b.toMatrix (fun i ↦ (v i : M₂)) := by ext rw [RingHom.mapMatrix_apply, Matrix.map_apply, Basis.toMatrix_apply, Basis.restrictScalars_repr_apply, Basis.toMatrix_apply] end Basis section MulLinearMapToMatrix variable {N : Type*} [AddCommMonoid N] [Module R N] variable (b : Basis ι R M) (b' : Basis ι' R M) (c : Basis κ R N) (c' : Basis κ' R N) variable (f : M →ₗ[R] N) open LinearMap section Fintype /-- A generalization of `LinearMap.toMatrix_id`. -/ @[simp] theorem LinearMap.toMatrix_id_eq_basis_toMatrix [Fintype ι] [DecidableEq ι] [Finite ι'] : LinearMap.toMatrix b b' id = b'.toMatrix b := by ext i apply LinearMap.toMatrix_apply variable [Fintype ι'] @[simp] theorem basis_toMatrix_mul_linearMap_toMatrix [Finite κ] [Fintype κ'] [DecidableEq ι'] : c.toMatrix c' * LinearMap.toMatrix b' c' f = LinearMap.toMatrix b' c f := (Matrix.toLin b' c).injective <| by haveI := Classical.decEq κ' rw [toLin_toMatrix, toLin_mul b' c' c, toLin_toMatrix, c.toLin_toMatrix, LinearMap.id_comp] theorem basis_toMatrix_mul [Fintype κ] [Finite ι] [DecidableEq κ] (b₁ : Basis ι R M) (b₂ : Basis ι' R M) (b₃ : Basis κ R N) (A : Matrix ι' κ R) : b₁.toMatrix b₂ * A = LinearMap.toMatrix b₃ b₁ (toLin b₃ b₂ A) := by have := basis_toMatrix_mul_linearMap_toMatrix b₃ b₁ b₂ (Matrix.toLin b₃ b₂ A) rwa [LinearMap.toMatrix_toLin] at this variable [Finite κ] [Fintype ι] @[simp] theorem linearMap_toMatrix_mul_basis_toMatrix [Finite κ'] [DecidableEq ι] [DecidableEq ι'] : LinearMap.toMatrix b' c' f * b'.toMatrix b = LinearMap.toMatrix b c' f := (Matrix.toLin b c').injective <| by rw [toLin_toMatrix, toLin_mul b b' c', toLin_toMatrix, b'.toLin_toMatrix, LinearMap.comp_id]
Mathlib/LinearAlgebra/Matrix/Basis.lean
204
208
theorem basis_toMatrix_mul_linearMap_toMatrix_mul_basis_toMatrix [Fintype κ'] [DecidableEq ι] [DecidableEq ι'] : c.toMatrix c' * LinearMap.toMatrix b' c' f * b'.toMatrix b = LinearMap.toMatrix b c f := by
cases nonempty_fintype κ rw [basis_toMatrix_mul_linearMap_toMatrix, linearMap_toMatrix_mul_basis_toMatrix]
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Algebra.Polynomial.Splits import Mathlib.Tactic.IntervalCases /-! # Cubics and discriminants This file defines cubic polynomials over a semiring and their discriminants over a splitting field. ## Main definitions * `Cubic`: the structure representing a cubic polynomial. * `Cubic.disc`: the discriminant of a cubic polynomial. ## Main statements * `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if the cubic has no duplicate roots. ## References * https://en.wikipedia.org/wiki/Cubic_equation * https://en.wikipedia.org/wiki/Discriminant ## Tags cubic, discriminant, polynomial, root -/ noncomputable section /-- The structure representing a cubic polynomial. -/ @[ext] structure Cubic (R : Type*) where /-- The degree-3 coefficient -/ a : R /-- The degree-2 coefficient -/ b : R /-- The degree-1 coefficient -/ c : R /-- The degree-0 coefficient -/ d : R namespace Cubic open Polynomial variable {R S F K : Type*} instance [Inhabited R] : Inhabited (Cubic R) := ⟨⟨default, default, default, default⟩⟩ instance [Zero R] : Zero (Cubic R) := ⟨⟨0, 0, 0, 0⟩⟩ section Basic variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R] /-- Convert a cubic polynomial to a polynomial. -/ def toPoly (P : Cubic R) : R[X] := C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} : C w * (X - C x) * (X - C y) * (X - C z) = toPoly ⟨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)⟩ := by simp only [toPoly, C_neg, C_add, C_mul] ring1 theorem prod_X_sub_C_eq [CommRing S] {x y z : S} : (X - C x) * (X - C y) * (X - C z) = toPoly ⟨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)⟩ := by rw [← one_mul <| X - C x, ← C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul] /-! ### Coefficients -/ section Coeff private theorem coeffs : (∀ n > 3, P.toPoly.coeff n = 0) ∧ P.toPoly.coeff 3 = P.a ∧ P.toPoly.coeff 2 = P.b ∧ P.toPoly.coeff 1 = P.c ∧ P.toPoly.coeff 0 = P.d := by simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow] norm_num intro n hn repeat' rw [if_neg] any_goals omega repeat' rw [zero_add] @[simp] theorem coeff_eq_zero {n : ℕ} (hn : 3 < n) : P.toPoly.coeff n = 0 := coeffs.1 n hn @[simp] theorem coeff_eq_a : P.toPoly.coeff 3 = P.a := coeffs.2.1 @[simp] theorem coeff_eq_b : P.toPoly.coeff 2 = P.b := coeffs.2.2.1 @[simp] theorem coeff_eq_c : P.toPoly.coeff 1 = P.c := coeffs.2.2.2.1 @[simp] theorem coeff_eq_d : P.toPoly.coeff 0 = P.d := coeffs.2.2.2.2 theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a] theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [← coeff_eq_b, h, coeff_eq_b] theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [← coeff_eq_c, h, coeff_eq_c] theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [← coeff_eq_d, h, coeff_eq_d] theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly ↔ P = Q := ⟨fun h ↦ Cubic.ext (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPoly⟩ theorem of_a_eq_zero (ha : P.a = 0) : P.toPoly = C P.b * X ^ 2 + C P.c * X + C P.d := by rw [toPoly, ha, C_0, zero_mul, zero_add] theorem of_a_eq_zero' : toPoly ⟨0, b, c, d⟩ = C b * X ^ 2 + C c * X + C d := of_a_eq_zero rfl theorem of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly = C P.c * X + C P.d := by rw [of_a_eq_zero ha, hb, C_0, zero_mul, zero_add] theorem of_b_eq_zero' : toPoly ⟨0, 0, c, d⟩ = C c * X + C d := of_b_eq_zero rfl rfl
Mathlib/Algebra/CubicDiscriminant.lean
137
138
theorem of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly = C P.d := by
rw [of_b_eq_zero ha hb, hc, C_0, zero_mul, zero_add]
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.LinearAlgebra.CliffordAlgebra.Grading import Mathlib.Algebra.Module.Opposite /-! # Conjugations This file defines the grade reversal and grade involution functions on multivectors, `reverse` and `involute`. Together, these operations compose to form the "Clifford conjugate", hence the name of this file. https://en.wikipedia.org/wiki/Clifford_algebra#Antiautomorphisms ## Main definitions * `CliffordAlgebra.involute`: the grade involution, negating each basis vector * `CliffordAlgebra.reverse`: the grade reversion, reversing the order of a product of vectors ## Main statements * `CliffordAlgebra.involute_involutive` * `CliffordAlgebra.reverse_involutive` * `CliffordAlgebra.reverse_involute_commute` * `CliffordAlgebra.involute_mem_evenOdd_iff` * `CliffordAlgebra.reverse_mem_evenOdd_iff` -/ variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable {Q : QuadraticForm R M} namespace CliffordAlgebra section Involute /-- Grade involution, inverting the sign of each basis vector. -/ def involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q := CliffordAlgebra.lift Q ⟨-ι Q, fun m => by simp⟩ @[simp] theorem involute_ι (m : M) : involute (ι Q m) = -ι Q m := lift_ι_apply _ _ m @[simp] theorem involute_comp_involute : involute.comp involute = AlgHom.id R (CliffordAlgebra Q) := by ext; simp theorem involute_involutive : Function.Involutive (involute : _ → CliffordAlgebra Q) := AlgHom.congr_fun involute_comp_involute @[simp] theorem involute_involute : ∀ a : CliffordAlgebra Q, involute (involute a) = a := involute_involutive /-- `CliffordAlgebra.involute` as an `AlgEquiv`. -/ @[simps!] def involuteEquiv : CliffordAlgebra Q ≃ₐ[R] CliffordAlgebra Q := AlgEquiv.ofAlgHom involute involute (AlgHom.ext <| involute_involute) (AlgHom.ext <| involute_involute) end Involute section Reverse open MulOpposite /-- `CliffordAlgebra.reverse` as an `AlgHom` to the opposite algebra -/ def reverseOp : CliffordAlgebra Q →ₐ[R] (CliffordAlgebra Q)ᵐᵒᵖ := CliffordAlgebra.lift Q ⟨(MulOpposite.opLinearEquiv R).toLinearMap ∘ₗ ι Q, fun m => unop_injective <| by simp⟩ @[simp] theorem reverseOp_ι (m : M) : reverseOp (ι Q m) = op (ι Q m) := lift_ι_apply _ _ _ /-- `CliffordAlgebra.reverseEquiv` as an `AlgEquiv` to the opposite algebra -/ @[simps! apply] def reverseOpEquiv : CliffordAlgebra Q ≃ₐ[R] (CliffordAlgebra Q)ᵐᵒᵖ := AlgEquiv.ofAlgHom reverseOp (AlgHom.opComm reverseOp) (AlgHom.unop.injective <| hom_ext <| LinearMap.ext fun _ => by simp) (hom_ext <| LinearMap.ext fun _ => by simp) @[simp] theorem reverseOpEquiv_opComm : AlgEquiv.opComm (reverseOpEquiv (Q := Q)) = reverseOpEquiv.symm := rfl /-- Grade reversion, inverting the multiplication order of basis vectors. Also called *transpose* in some literature. -/ def reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q := (opLinearEquiv R).symm.toLinearMap.comp reverseOp.toLinearMap @[simp] theorem unop_reverseOp (x : CliffordAlgebra Q) : (reverseOp x).unop = reverse x := rfl @[simp] theorem op_reverse (x : CliffordAlgebra Q) : op (reverse x) = reverseOp x := rfl @[simp] theorem reverse_ι (m : M) : reverse (ι Q m) = ι Q m := by simp [reverse] @[simp] theorem reverse.commutes (r : R) : reverse (algebraMap R (CliffordAlgebra Q) r) = algebraMap R _ r := op_injective <| reverseOp.commutes r @[simp] protected theorem reverse.map_one : reverse (1 : CliffordAlgebra Q) = 1 := op_injective (map_one reverseOp) @[simp] protected theorem reverse.map_mul (a b : CliffordAlgebra Q) : reverse (a * b) = reverse b * reverse a := op_injective (map_mul reverseOp a b) @[simp] theorem reverse_involutive : Function.Involutive (reverse (Q := Q)) := AlgHom.congr_fun reverseOpEquiv.symm_comp @[simp] theorem reverse_comp_reverse : reverse.comp reverse = (LinearMap.id : _ →ₗ[R] CliffordAlgebra Q) := LinearMap.ext reverse_involutive @[simp] theorem reverse_reverse : ∀ a : CliffordAlgebra Q, reverse (reverse a) = a := reverse_involutive /-- `CliffordAlgebra.reverse` as a `LinearEquiv`. -/ @[simps!] def reverseEquiv : CliffordAlgebra Q ≃ₗ[R] CliffordAlgebra Q := LinearEquiv.ofInvolutive reverse reverse_involutive theorem reverse_comp_involute : reverse.comp involute.toLinearMap = (involute.toLinearMap.comp reverse : _ →ₗ[R] CliffordAlgebra Q) := by ext x simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply] induction x using CliffordAlgebra.induction with | algebraMap => simp | ι => simp | mul a b ha hb => simp only [ha, hb, reverse.map_mul, map_mul] | add a b ha hb => simp only [ha, hb, reverse.map_add, map_add] /-- `CliffordAlgebra.reverse` and `CliffordAlgebra.involute` commute. Note that the composition is sometimes referred to as the "clifford conjugate". -/ theorem reverse_involute_commute : Function.Commute (reverse (Q := Q)) involute := LinearMap.congr_fun reverse_comp_involute theorem reverse_involute : ∀ a : CliffordAlgebra Q, reverse (involute a) = involute (reverse a) := reverse_involute_commute end Reverse /-! ### Statements about conjugations of products of lists -/ section List /-- Taking the reverse of the product a list of $n$ vectors lifted via `ι` is equivalent to taking the product of the reverse of that list. -/ theorem reverse_prod_map_ι : ∀ l : List M, reverse (l.map <| ι Q).prod = (l.map <| ι Q).reverse.prod | [] => by simp | x::xs => by simp [reverse_prod_map_ι xs] /-- Taking the involute of the product a list of $n$ vectors lifted via `ι` is equivalent to premultiplying by ${-1}^n$. -/ theorem involute_prod_map_ι : ∀ l : List M, involute (l.map <| ι Q).prod = (-1 : R) ^ l.length • (l.map <| ι Q).prod | [] => by simp | x::xs => by simp [pow_succ, involute_prod_map_ι xs] end List /-! ### Statements about `Submodule.map` and `Submodule.comap` -/ section Submodule variable (Q) section Involute theorem submodule_map_involute_eq_comap (p : Submodule R (CliffordAlgebra Q)) : p.map (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap = p.comap (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap := Submodule.map_equiv_eq_comap_symm involuteEquiv.toLinearEquiv _ @[simp] theorem ι_range_map_involute : (LinearMap.range (ι Q)).map (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap = LinearMap.range (ι Q) := (ι_range_map_lift _ _).trans (LinearMap.range_neg _) @[simp] theorem ι_range_comap_involute : (LinearMap.range (ι Q)).comap (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap = LinearMap.range (ι Q) := by rw [← submodule_map_involute_eq_comap, ι_range_map_involute] @[simp] theorem evenOdd_map_involute (n : ZMod 2) : (evenOdd Q n).map (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap = evenOdd Q n := by simp_rw [evenOdd, Submodule.map_iSup, Submodule.map_pow, ι_range_map_involute] @[simp] theorem evenOdd_comap_involute (n : ZMod 2) : (evenOdd Q n).comap (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap = evenOdd Q n := by rw [← submodule_map_involute_eq_comap, evenOdd_map_involute] end Involute section Reverse theorem submodule_map_reverse_eq_comap (p : Submodule R (CliffordAlgebra Q)) : p.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = p.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) := Submodule.map_equiv_eq_comap_symm (reverseEquiv : _ ≃ₗ[R] _) _ @[simp] theorem ι_range_map_reverse : (LinearMap.range (ι Q)).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = LinearMap.range (ι Q) := by rw [reverse, reverseOp, Submodule.map_comp, ι_range_map_lift, LinearMap.range_comp, ← Submodule.map_comp] exact Submodule.map_id _ @[simp] theorem ι_range_comap_reverse : (LinearMap.range (ι Q)).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = LinearMap.range (ι Q) := by rw [← submodule_map_reverse_eq_comap, ι_range_map_reverse] /-- Like `Submodule.map_mul`, but with the multiplication reversed. -/ theorem submodule_map_mul_reverse (p q : Submodule R (CliffordAlgebra Q)) : (p * q).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = q.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) * p.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) := by simp_rw [reverse, Submodule.map_comp, Submodule.map_mul, Submodule.map_unop_mul] theorem submodule_comap_mul_reverse (p q : Submodule R (CliffordAlgebra Q)) : (p * q).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = q.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) * p.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) := by simp_rw [← submodule_map_reverse_eq_comap, submodule_map_mul_reverse] /-- Like `Submodule.map_pow` -/ theorem submodule_map_pow_reverse (p : Submodule R (CliffordAlgebra Q)) (n : ℕ) : (p ^ n).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = p.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) ^ n := by simp_rw [reverse, Submodule.map_comp, Submodule.map_pow, Submodule.map_unop_pow] theorem submodule_comap_pow_reverse (p : Submodule R (CliffordAlgebra Q)) (n : ℕ) : (p ^ n).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = p.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) ^ n := by simp_rw [← submodule_map_reverse_eq_comap, submodule_map_pow_reverse] @[simp] theorem evenOdd_map_reverse (n : ZMod 2) : (evenOdd Q n).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = evenOdd Q n := by simp_rw [evenOdd, Submodule.map_iSup, submodule_map_pow_reverse, ι_range_map_reverse] @[simp] theorem evenOdd_comap_reverse (n : ZMod 2) : (evenOdd Q n).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = evenOdd Q n := by rw [← submodule_map_reverse_eq_comap, evenOdd_map_reverse] end Reverse @[simp] theorem involute_mem_evenOdd_iff {x : CliffordAlgebra Q} {n : ZMod 2} : involute x ∈ evenOdd Q n ↔ x ∈ evenOdd Q n := SetLike.ext_iff.mp (evenOdd_comap_involute Q n) x @[simp] theorem reverse_mem_evenOdd_iff {x : CliffordAlgebra Q} {n : ZMod 2} : reverse x ∈ evenOdd Q n ↔ x ∈ evenOdd Q n := SetLike.ext_iff.mp (evenOdd_comap_reverse Q n) x end Submodule /-! ### Related properties of the even and odd submodules TODO: show that these are `iff`s when `Invertible (2 : R)`. -/ theorem involute_eq_of_mem_even {x : CliffordAlgebra Q} (h : x ∈ evenOdd Q 0) : involute x = x := by induction x, h using even_induction with | algebraMap r => exact AlgHom.commutes _ _ | add x y _hx _hy ihx ihy => rw [map_add, ihx, ihy] | ι_mul_ι_mul m₁ m₂ x _hx ihx => rw [map_mul, map_mul, involute_ι, involute_ι, ihx, neg_mul_neg]
Mathlib/LinearAlgebra/CliffordAlgebra/Conjugation.lean
308
310
theorem involute_eq_of_mem_odd {x : CliffordAlgebra Q} (h : x ∈ evenOdd Q 1) : involute x = -x := by
induction x, h using odd_induction with | ι m => exact involute_ι _
/- Copyright (c) 2014 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Jeremy Avigad -/ import Mathlib.Algebra.Order.Group.Nat import Mathlib.Algebra.Order.Ring.Canonical /-! # Distance function on ℕ This file defines a simple distance function on naturals from truncated subtraction. -/ namespace Nat /-- Distance (absolute value of difference) between natural numbers. -/ def dist (n m : ℕ) := n - m + (m - n) theorem dist_comm (n m : ℕ) : dist n m = dist m n := by simp [dist, add_comm] @[simp] theorem dist_self (n : ℕ) : dist n n = 0 := by simp [dist, tsub_self] theorem eq_of_dist_eq_zero {n m : ℕ} (h : dist n m = 0) : n = m := have : n - m = 0 := Nat.eq_zero_of_add_eq_zero_right h have : n ≤ m := tsub_eq_zero_iff_le.mp this have : m - n = 0 := Nat.eq_zero_of_add_eq_zero_left h have : m ≤ n := tsub_eq_zero_iff_le.mp this le_antisymm ‹n ≤ m› ‹m ≤ n› theorem dist_eq_zero {n m : ℕ} (h : n = m) : dist n m = 0 := by rw [h, dist_self] theorem dist_eq_sub_of_le {n m : ℕ} (h : n ≤ m) : dist n m = m - n := by rw [dist, tsub_eq_zero_iff_le.mpr h, zero_add] theorem dist_eq_sub_of_le_right {n m : ℕ} (h : m ≤ n) : dist n m = n - m := by rw [dist_comm]; apply dist_eq_sub_of_le h theorem dist_tri_left (n m : ℕ) : m ≤ dist n m + n := le_trans le_tsub_add (add_le_add_right (Nat.le_add_left _ _) _) theorem dist_tri_right (n m : ℕ) : m ≤ n + dist n m := by rw [add_comm]; apply dist_tri_left theorem dist_tri_left' (n m : ℕ) : n ≤ dist n m + m := by rw [dist_comm]; apply dist_tri_left theorem dist_tri_right' (n m : ℕ) : n ≤ m + dist n m := by rw [dist_comm]; apply dist_tri_right theorem dist_zero_right (n : ℕ) : dist n 0 = n := Eq.trans (dist_eq_sub_of_le_right (zero_le n)) (tsub_zero n) theorem dist_zero_left (n : ℕ) : dist 0 n = n := Eq.trans (dist_eq_sub_of_le (zero_le n)) (tsub_zero n) theorem dist_add_add_right (n k m : ℕ) : dist (n + k) (m + k) = dist n m := calc dist (n + k) (m + k) = n + k - (m + k) + (m + k - (n + k)) := rfl _ = n - m + (m + k - (n + k)) := by rw [@add_tsub_add_eq_tsub_right] _ = n - m + (m - n) := by rw [@add_tsub_add_eq_tsub_right] theorem dist_add_add_left (k n m : ℕ) : dist (k + n) (k + m) = dist n m := by rw [add_comm k n, add_comm k m]; apply dist_add_add_right theorem dist_eq_intro {n m k l : ℕ} (h : n + m = k + l) : dist n k = dist l m := calc dist n k = dist (n + m) (k + m) := by rw [dist_add_add_right] _ = dist (k + l) (k + m) := by rw [h] _ = dist l m := by rw [dist_add_add_left] theorem dist.triangle_inequality (n m k : ℕ) : dist n k ≤ dist n m + dist m k := by have : dist n m + dist m k = n - m + (m - k) + (k - m + (m - n)) := by simp [dist, add_comm, add_left_comm, add_assoc] rw [this, dist] exact add_le_add tsub_le_tsub_add_tsub tsub_le_tsub_add_tsub theorem dist_mul_right (n k m : ℕ) : dist (n * k) (m * k) = dist n m * k := by rw [dist, dist, right_distrib, tsub_mul n, tsub_mul m] theorem dist_mul_left (k n m : ℕ) : dist (k * n) (k * m) = k * dist n m := by rw [mul_comm k n, mul_comm k m, dist_mul_right, mul_comm] theorem dist_eq_max_sub_min {i j : ℕ} : dist i j = (max i j) - min i j := Or.elim (lt_or_ge i j) (by intro h; rw [max_eq_right_of_lt h, min_eq_left_of_lt h, dist_eq_sub_of_le (Nat.le_of_lt h)]) (by intro h; rw [max_eq_left h, min_eq_right h, dist_eq_sub_of_le_right h]) theorem dist_succ_succ {i j : Nat} : dist (succ i) (succ j) = dist i j := by simp [dist, succ_sub_succ]
Mathlib/Data/Nat/Dist.lean
92
96
theorem dist_pos_of_ne {i j : Nat} (h : i ≠ j) : 0 < dist i j := by
cases h.lt_or_lt with | inl h => rw [dist_eq_sub_of_le h.le]; apply tsub_pos_of_lt h | inr h => rw [dist_eq_sub_of_le_right h.le]; apply tsub_pos_of_lt h
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FDeriv.Linear import Mathlib.Analysis.Calculus.FDeriv.Comp /-! # Additive operations on derivatives For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of * sum of finitely many functions * multiplication of a function by a scalar constant * negative of a function * subtraction of two functions -/ open Filter Asymptotics ContinuousLinearMap noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f g : E → F} variable {f' g' : E →L[𝕜] F} variable {x : E} variable {s : Set E} variable {L : Filter E} section ConstSMul variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] /-! ### Derivative of a function multiplied by a constant -/ @[fun_prop] theorem HasStrictFDerivAt.const_smul (h : HasStrictFDerivAt f f' x) (c : R) : HasStrictFDerivAt (fun x => c • f x) (c • f') x := (c • (1 : F →L[𝕜] F)).hasStrictFDerivAt.comp x h theorem HasFDerivAtFilter.const_smul (h : HasFDerivAtFilter f f' x L) (c : R) : HasFDerivAtFilter (fun x => c • f x) (c • f') x L := (c • (1 : F →L[𝕜] F)).hasFDerivAtFilter.comp x h tendsto_map @[fun_prop] nonrec theorem HasFDerivWithinAt.const_smul (h : HasFDerivWithinAt f f' s x) (c : R) : HasFDerivWithinAt (fun x => c • f x) (c • f') s x := h.const_smul c @[fun_prop] nonrec theorem HasFDerivAt.const_smul (h : HasFDerivAt f f' x) (c : R) : HasFDerivAt (fun x => c • f x) (c • f') x := h.const_smul c @[fun_prop] theorem DifferentiableWithinAt.const_smul (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : DifferentiableWithinAt 𝕜 (fun y => c • f y) s x := (h.hasFDerivWithinAt.const_smul c).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.const_smul (h : DifferentiableAt 𝕜 f x) (c : R) : DifferentiableAt 𝕜 (fun y => c • f y) x := (h.hasFDerivAt.const_smul c).differentiableAt @[fun_prop] theorem DifferentiableOn.const_smul (h : DifferentiableOn 𝕜 f s) (c : R) : DifferentiableOn 𝕜 (fun y => c • f y) s := fun x hx => (h x hx).const_smul c @[fun_prop] theorem Differentiable.const_smul (h : Differentiable 𝕜 f) (c : R) : Differentiable 𝕜 fun y => c • f y := fun x => (h x).const_smul c theorem fderivWithin_const_smul (hxs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : fderivWithin 𝕜 (fun y => c • f y) s x = c • fderivWithin 𝕜 f s x := (h.hasFDerivWithinAt.const_smul c).fderivWithin hxs /-- Version of `fderivWithin_const_smul` written with `c • f` instead of `fun y ↦ c • f y`. -/ theorem fderivWithin_const_smul' (hxs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : fderivWithin 𝕜 (c • f) s x = c • fderivWithin 𝕜 f s x := fderivWithin_const_smul hxs h c theorem fderiv_const_smul (h : DifferentiableAt 𝕜 f x) (c : R) : fderiv 𝕜 (fun y => c • f y) x = c • fderiv 𝕜 f x := (h.hasFDerivAt.const_smul c).fderiv /-- Version of `fderiv_const_smul` written with `c • f` instead of `fun y ↦ c • f y`. -/ theorem fderiv_const_smul' (h : DifferentiableAt 𝕜 f x) (c : R) : fderiv 𝕜 (c • f) x = c • fderiv 𝕜 f x := (h.hasFDerivAt.const_smul c).fderiv end ConstSMul section Add /-! ### Derivative of the sum of two functions -/ @[fun_prop] nonrec theorem HasStrictFDerivAt.add (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun y => f y + g y) (f' + g') x := .of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun y => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel theorem HasFDerivAtFilter.add (hf : HasFDerivAtFilter f f' x L) (hg : HasFDerivAtFilter g g' x L) : HasFDerivAtFilter (fun y => f y + g y) (f' + g') x L := .of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun _ => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel @[fun_prop] nonrec theorem HasFDerivWithinAt.add (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun y => f y + g y) (f' + g') s x := hf.add hg @[fun_prop] nonrec theorem HasFDerivAt.add (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun x => f x + g x) (f' + g') x := hf.add hg @[fun_prop] theorem DifferentiableWithinAt.add (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : DifferentiableWithinAt 𝕜 (fun y => f y + g y) s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y + g y) x := (hf.hasFDerivAt.add hg.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.add (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y + g y) s := fun x hx => (hf x hx).add (hg x hx) @[simp, fun_prop] theorem Differentiable.add (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) : Differentiable 𝕜 fun y => f y + g y := fun x => (hf x).add (hg x) theorem fderivWithin_add (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (fun y => f y + g y) s x = fderivWithin 𝕜 f s x + fderivWithin 𝕜 g s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).fderivWithin hxs /-- Version of `fderivWithin_add` where the function is written as `f + g` instead of `fun y ↦ f y + g y`. -/ theorem fderivWithin_add' (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (f + g) s x = fderivWithin 𝕜 f s x + fderivWithin 𝕜 g s x := fderivWithin_add hxs hf hg theorem fderiv_add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (fun y => f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 g x := (hf.hasFDerivAt.add hg.hasFDerivAt).fderiv /-- Version of `fderiv_add` where the function is written as `f + g` instead of `fun y ↦ f y + g y`. -/ theorem fderiv_add' (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (f + g) x = fderiv 𝕜 f x + fderiv 𝕜 g x := fderiv_add hf hg @[simp] theorem hasFDerivAtFilter_add_const_iff (c : F) : HasFDerivAtFilter (f · + c) f' x L ↔ HasFDerivAtFilter f f' x L := by simp [hasFDerivAtFilter_iff_isLittleOTVS] alias ⟨_, HasFDerivAtFilter.add_const⟩ := hasFDerivAtFilter_add_const_iff @[simp] theorem hasStrictFDerivAt_add_const_iff (c : F) : HasStrictFDerivAt (f · + c) f' x ↔ HasStrictFDerivAt f f' x := by simp [hasStrictFDerivAt_iff_isLittleO] @[fun_prop] alias ⟨_, HasStrictFDerivAt.add_const⟩ := hasStrictFDerivAt_add_const_iff @[simp] theorem hasFDerivWithinAt_add_const_iff (c : F) : HasFDerivWithinAt (f · + c) f' s x ↔ HasFDerivWithinAt f f' s x := hasFDerivAtFilter_add_const_iff c @[fun_prop] alias ⟨_, HasFDerivWithinAt.add_const⟩ := hasFDerivWithinAt_add_const_iff @[simp] theorem hasFDerivAt_add_const_iff (c : F) : HasFDerivAt (f · + c) f' x ↔ HasFDerivAt f f' x := hasFDerivAtFilter_add_const_iff c @[fun_prop] alias ⟨_, HasFDerivAt.add_const⟩ := hasFDerivAt_add_const_iff @[simp] theorem differentiableWithinAt_add_const_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => f y + c) s x ↔ DifferentiableWithinAt 𝕜 f s x := exists_congr fun _ ↦ hasFDerivWithinAt_add_const_iff c @[fun_prop] alias ⟨_, DifferentiableWithinAt.add_const⟩ := differentiableWithinAt_add_const_iff @[simp] theorem differentiableAt_add_const_iff (c : F) : DifferentiableAt 𝕜 (fun y => f y + c) x ↔ DifferentiableAt 𝕜 f x := exists_congr fun _ ↦ hasFDerivAt_add_const_iff c @[fun_prop] alias ⟨_, DifferentiableAt.add_const⟩ := differentiableAt_add_const_iff @[simp] theorem differentiableOn_add_const_iff (c : F) : DifferentiableOn 𝕜 (fun y => f y + c) s ↔ DifferentiableOn 𝕜 f s := forall₂_congr fun _ _ ↦ differentiableWithinAt_add_const_iff c @[fun_prop] alias ⟨_, DifferentiableOn.add_const⟩ := differentiableOn_add_const_iff @[simp] theorem differentiable_add_const_iff (c : F) : (Differentiable 𝕜 fun y => f y + c) ↔ Differentiable 𝕜 f := forall_congr' fun _ ↦ differentiableAt_add_const_iff c @[fun_prop] alias ⟨_, Differentiable.add_const⟩ := differentiable_add_const_iff @[simp] theorem fderivWithin_add_const (c : F) : fderivWithin 𝕜 (fun y => f y + c) s x = fderivWithin 𝕜 f s x := by classical simp [fderivWithin] @[simp] theorem fderiv_add_const (c : F) : fderiv 𝕜 (fun y => f y + c) x = fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_add_const] @[simp] theorem hasFDerivAtFilter_const_add_iff (c : F) : HasFDerivAtFilter (c + f ·) f' x L ↔ HasFDerivAtFilter f f' x L := by simpa only [add_comm] using hasFDerivAtFilter_add_const_iff c alias ⟨_, HasFDerivAtFilter.const_add⟩ := hasFDerivAtFilter_const_add_iff @[simp] theorem hasStrictFDerivAt_const_add_iff (c : F) : HasStrictFDerivAt (c + f ·) f' x ↔ HasStrictFDerivAt f f' x := by simpa only [add_comm] using hasStrictFDerivAt_add_const_iff c @[fun_prop] alias ⟨_, HasStrictFDerivAt.const_add⟩ := hasStrictFDerivAt_const_add_iff @[simp] theorem hasFDerivWithinAt_const_add_iff (c : F) : HasFDerivWithinAt (c + f ·) f' s x ↔ HasFDerivWithinAt f f' s x := hasFDerivAtFilter_const_add_iff c @[fun_prop] alias ⟨_, HasFDerivWithinAt.const_add⟩ := hasFDerivWithinAt_const_add_iff @[simp] theorem hasFDerivAt_const_add_iff (c : F) : HasFDerivAt (c + f ·) f' x ↔ HasFDerivAt f f' x := hasFDerivAtFilter_const_add_iff c @[fun_prop] alias ⟨_, HasFDerivAt.const_add⟩ := hasFDerivAt_const_add_iff @[simp] theorem differentiableWithinAt_const_add_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => c + f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := exists_congr fun _ ↦ hasFDerivWithinAt_const_add_iff c @[fun_prop] alias ⟨_, DifferentiableWithinAt.const_add⟩ := differentiableWithinAt_const_add_iff @[simp] theorem differentiableAt_const_add_iff (c : F) : DifferentiableAt 𝕜 (fun y => c + f y) x ↔ DifferentiableAt 𝕜 f x := exists_congr fun _ ↦ hasFDerivAt_const_add_iff c @[fun_prop] alias ⟨_, DifferentiableAt.const_add⟩ := differentiableAt_const_add_iff @[simp] theorem differentiableOn_const_add_iff (c : F) : DifferentiableOn 𝕜 (fun y => c + f y) s ↔ DifferentiableOn 𝕜 f s := forall₂_congr fun _ _ ↦ differentiableWithinAt_const_add_iff c @[fun_prop] alias ⟨_, DifferentiableOn.const_add⟩ := differentiableOn_const_add_iff @[simp] theorem differentiable_const_add_iff (c : F) : (Differentiable 𝕜 fun y => c + f y) ↔ Differentiable 𝕜 f := forall_congr' fun _ ↦ differentiableAt_const_add_iff c @[fun_prop] alias ⟨_, Differentiable.const_add⟩ := differentiable_const_add_iff @[simp] theorem fderivWithin_const_add (c : F) : fderivWithin 𝕜 (fun y => c + f y) s x = fderivWithin 𝕜 f s x := by simpa only [add_comm] using fderivWithin_add_const c @[simp] theorem fderiv_const_add (c : F) : fderiv 𝕜 (fun y => c + f y) x = fderiv 𝕜 f x := by simp only [add_comm c, fderiv_add_const] end Add section Sum /-! ### Derivative of a finite sum of functions -/ variable {ι : Type*} {u : Finset ι} {A : ι → E → F} {A' : ι → E →L[𝕜] F} @[fun_prop] theorem HasStrictFDerivAt.sum (h : ∀ i ∈ u, HasStrictFDerivAt (A i) (A' i) x) : HasStrictFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := by simp only [hasStrictFDerivAt_iff_isLittleO] at * convert IsLittleO.sum h simp [Finset.sum_sub_distrib, ContinuousLinearMap.sum_apply] theorem HasFDerivAtFilter.sum (h : ∀ i ∈ u, HasFDerivAtFilter (A i) (A' i) x L) : HasFDerivAtFilter (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x L := by simp only [hasFDerivAtFilter_iff_isLittleO] at * convert IsLittleO.sum h simp [ContinuousLinearMap.sum_apply] @[fun_prop] theorem HasFDerivWithinAt.sum (h : ∀ i ∈ u, HasFDerivWithinAt (A i) (A' i) s x) : HasFDerivWithinAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) s x := HasFDerivAtFilter.sum h @[fun_prop] theorem HasFDerivAt.sum (h : ∀ i ∈ u, HasFDerivAt (A i) (A' i) x) : HasFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := HasFDerivAtFilter.sum h @[fun_prop] theorem DifferentiableWithinAt.sum (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : DifferentiableWithinAt 𝕜 (fun y => ∑ i ∈ u, A i y) s x := HasFDerivWithinAt.differentiableWithinAt <| HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt @[simp, fun_prop] theorem DifferentiableAt.sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : DifferentiableAt 𝕜 (fun y => ∑ i ∈ u, A i y) x := HasFDerivAt.differentiableAt <| HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt @[fun_prop] theorem DifferentiableOn.sum (h : ∀ i ∈ u, DifferentiableOn 𝕜 (A i) s) : DifferentiableOn 𝕜 (fun y => ∑ i ∈ u, A i y) s := fun x hx => DifferentiableWithinAt.sum fun i hi => h i hi x hx @[simp, fun_prop] theorem Differentiable.sum (h : ∀ i ∈ u, Differentiable 𝕜 (A i)) : Differentiable 𝕜 fun y => ∑ i ∈ u, A i y := fun x => DifferentiableAt.sum fun i hi => h i hi x theorem fderivWithin_sum (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : fderivWithin 𝕜 (fun y => ∑ i ∈ u, A i y) s x = ∑ i ∈ u, fderivWithin 𝕜 (A i) s x := (HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt).fderivWithin hxs theorem fderiv_sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : fderiv 𝕜 (fun y => ∑ i ∈ u, A i y) x = ∑ i ∈ u, fderiv 𝕜 (A i) x := (HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt).fderiv end Sum section Neg /-! ### Derivative of the negative of a function -/ @[fun_prop] theorem HasStrictFDerivAt.neg (h : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => -f x) (-f') x := (-1 : F →L[𝕜] F).hasStrictFDerivAt.comp x h theorem HasFDerivAtFilter.neg (h : HasFDerivAtFilter f f' x L) : HasFDerivAtFilter (fun x => -f x) (-f') x L := (-1 : F →L[𝕜] F).hasFDerivAtFilter.comp x h tendsto_map @[fun_prop] nonrec theorem HasFDerivWithinAt.neg (h : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => -f x) (-f') s x := h.neg @[fun_prop] nonrec theorem HasFDerivAt.neg (h : HasFDerivAt f f' x) : HasFDerivAt (fun x => -f x) (-f') x := h.neg @[fun_prop] theorem DifferentiableWithinAt.neg (h : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (fun y => -f y) s x := h.hasFDerivWithinAt.neg.differentiableWithinAt @[simp] theorem differentiableWithinAt_neg_iff : DifferentiableWithinAt 𝕜 (fun y => -f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem DifferentiableAt.neg (h : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => -f y) x := h.hasFDerivAt.neg.differentiableAt @[simp] theorem differentiableAt_neg_iff : DifferentiableAt 𝕜 (fun y => -f y) x ↔ DifferentiableAt 𝕜 f x := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem DifferentiableOn.neg (h : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => -f y) s := fun x hx => (h x hx).neg @[simp] theorem differentiableOn_neg_iff : DifferentiableOn 𝕜 (fun y => -f y) s ↔ DifferentiableOn 𝕜 f s := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem Differentiable.neg (h : Differentiable 𝕜 f) : Differentiable 𝕜 fun y => -f y := fun x => (h x).neg @[simp] theorem differentiable_neg_iff : (Differentiable 𝕜 fun y => -f y) ↔ Differentiable 𝕜 f := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ theorem fderivWithin_neg (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun y => -f y) s x = -fderivWithin 𝕜 f s x := by classical by_cases h : DifferentiableWithinAt 𝕜 f s x · exact h.hasFDerivWithinAt.neg.fderivWithin hxs · rw [fderivWithin_zero_of_not_differentiableWithinAt h, fderivWithin_zero_of_not_differentiableWithinAt, neg_zero] simpa /-- Version of `fderivWithin_neg` where the function is written `-f` instead of `fun y ↦ - f y`. -/ theorem fderivWithin_neg' (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (-f) s x = -fderivWithin 𝕜 f s x := fderivWithin_neg hxs @[simp] theorem fderiv_neg : fderiv 𝕜 (fun y => -f y) x = -fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_neg uniqueDiffWithinAt_univ] /-- Version of `fderiv_neg` where the function is written `-f` instead of `fun y ↦ - f y`. -/ theorem fderiv_neg' : fderiv 𝕜 (-f) x = -fderiv 𝕜 f x := fderiv_neg end Neg section Sub /-! ### Derivative of the difference of two functions -/ @[fun_prop] theorem HasStrictFDerivAt.sub (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun x => f x - g x) (f' - g') x := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem HasFDerivAtFilter.sub (hf : HasFDerivAtFilter f f' x L) (hg : HasFDerivAtFilter g g' x L) : HasFDerivAtFilter (fun x => f x - g x) (f' - g') x L := by simpa only [sub_eq_add_neg] using hf.add hg.neg @[fun_prop] nonrec theorem HasFDerivWithinAt.sub (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun x => f x - g x) (f' - g') s x := hf.sub hg @[fun_prop] nonrec theorem HasFDerivAt.sub (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun x => f x - g x) (f' - g') x := hf.sub hg @[fun_prop] theorem DifferentiableWithinAt.sub (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : DifferentiableWithinAt 𝕜 (fun y => f y - g y) s x := (hf.hasFDerivWithinAt.sub hg.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.sub (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y - g y) x := (hf.hasFDerivAt.sub hg.hasFDerivAt).differentiableAt @[simp] lemma DifferentiableAt.add_iff_left (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y + g y) x ↔ DifferentiableAt 𝕜 f x := by refine ⟨fun h ↦ ?_, fun hf ↦ hf.add hg⟩ simpa only [add_sub_cancel_right] using h.sub hg @[simp] lemma DifferentiableAt.add_iff_right (hg : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => f y + g y) x ↔ DifferentiableAt 𝕜 g x := by simp only [add_comm (f _), hg.add_iff_left] @[simp] lemma DifferentiableAt.sub_iff_left (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y - g y) x ↔ DifferentiableAt 𝕜 f x := by simp only [sub_eq_add_neg, differentiableAt_neg_iff, hg, add_iff_left] @[simp] lemma DifferentiableAt.sub_iff_right (hg : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => f y - g y) x ↔ DifferentiableAt 𝕜 g x := by simp only [sub_eq_add_neg, hg, add_iff_right, differentiableAt_neg_iff] @[fun_prop] theorem DifferentiableOn.sub (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y - g y) s := fun x hx => (hf x hx).sub (hg x hx) @[simp] lemma DifferentiableOn.add_iff_left (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y + g y) s ↔ DifferentiableOn 𝕜 f s := by refine ⟨fun h ↦ ?_, fun hf ↦ hf.add hg⟩ simpa only [add_sub_cancel_right] using h.sub hg @[simp] lemma DifferentiableOn.add_iff_right (hg : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => f y + g y) s ↔ DifferentiableOn 𝕜 g s := by simp only [add_comm (f _), hg.add_iff_left] @[simp] lemma DifferentiableOn.sub_iff_left (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y - g y) s ↔ DifferentiableOn 𝕜 f s := by simp only [sub_eq_add_neg, differentiableOn_neg_iff, hg, add_iff_left] @[simp] lemma DifferentiableOn.sub_iff_right (hg : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => f y - g y) s ↔ DifferentiableOn 𝕜 g s := by simp only [sub_eq_add_neg, differentiableOn_neg_iff, hg, add_iff_right] @[simp, fun_prop] theorem Differentiable.sub (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) : Differentiable 𝕜 fun y => f y - g y := fun x => (hf x).sub (hg x) @[simp] lemma Differentiable.add_iff_left (hg : Differentiable 𝕜 g) : Differentiable 𝕜 (fun y => f y + g y) ↔ Differentiable 𝕜 f := by refine ⟨fun h ↦ ?_, fun hf ↦ hf.add hg⟩ simpa only [add_sub_cancel_right] using h.sub hg @[simp] lemma Differentiable.add_iff_right (hg : Differentiable 𝕜 f) : Differentiable 𝕜 (fun y => f y + g y) ↔ Differentiable 𝕜 g := by simp only [add_comm (f _), hg.add_iff_left] @[simp] lemma Differentiable.sub_iff_left (hg : Differentiable 𝕜 g) : Differentiable 𝕜 (fun y => f y - g y) ↔ Differentiable 𝕜 f := by simp only [sub_eq_add_neg, differentiable_neg_iff, hg, add_iff_left] @[simp] lemma Differentiable.sub_iff_right (hg : Differentiable 𝕜 f) : Differentiable 𝕜 (fun y => f y - g y) ↔ Differentiable 𝕜 g := by simp only [sub_eq_add_neg, differentiable_neg_iff, hg, add_iff_right] theorem fderivWithin_sub (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (fun y => f y - g y) s x = fderivWithin 𝕜 f s x - fderivWithin 𝕜 g s x := (hf.hasFDerivWithinAt.sub hg.hasFDerivWithinAt).fderivWithin hxs /-- Version of `fderivWithin_sub` where the function is written as `f - g` instead of `fun y ↦ f y - g y`. -/ theorem fderivWithin_sub' (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (f - g) s x = fderivWithin 𝕜 f s x - fderivWithin 𝕜 g s x := fderivWithin_sub hxs hf hg theorem fderiv_sub (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (fun y => f y - g y) x = fderiv 𝕜 f x - fderiv 𝕜 g x := (hf.hasFDerivAt.sub hg.hasFDerivAt).fderiv /-- Version of `fderiv_sub` where the function is written as `f - g` instead of `fun y ↦ f y - g y`. -/ theorem fderiv_sub' (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (f - g) x = fderiv 𝕜 f x - fderiv 𝕜 g x := fderiv_sub hf hg @[simp] theorem hasFDerivAtFilter_sub_const_iff (c : F) : HasFDerivAtFilter (f · - c) f' x L ↔ HasFDerivAtFilter f f' x L := by simp only [sub_eq_add_neg, hasFDerivAtFilter_add_const_iff] alias ⟨_, HasFDerivAtFilter.sub_const⟩ := hasFDerivAtFilter_sub_const_iff @[simp]
Mathlib/Analysis/Calculus/FDeriv/Add.lean
593
595
theorem hasStrictFDerivAt_sub_const_iff (c : F) : HasStrictFDerivAt (f · - c) f' x ↔ HasStrictFDerivAt f f' x := by
simp only [sub_eq_add_neg, hasStrictFDerivAt_add_const_iff]
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Ken Lee, Chris Hughes -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Data.Fintype.Basic import Mathlib.Data.Int.GCD import Mathlib.RingTheory.Coprime.Basic /-! # Additional lemmas about elements of a ring satisfying `IsCoprime` and elements of a monoid satisfying `IsRelPrime` These lemmas are in a separate file to the definition of `IsCoprime` or `IsRelPrime` as they require more imports. Notably, this includes lemmas about `Finset.prod` as this requires importing BigOperators, and lemmas about `Pow` since these are easiest to prove via `Finset.prod`. -/ universe u v open scoped Function -- required for scoped `on` notation section IsCoprime variable {R : Type u} {I : Type v} [CommSemiring R] {x y z : R} {s : I → R} {t : Finset I} section theorem Int.isCoprime_iff_gcd_eq_one {m n : ℤ} : IsCoprime m n ↔ Int.gcd m n = 1 := by constructor · rintro ⟨a, b, h⟩ refine Nat.dvd_one.mp (Int.gcd_dvd_iff.mpr ⟨a, b, ?_⟩) rwa [mul_comm m, mul_comm n, eq_comm] · rw [← Int.ofNat_inj, IsCoprime, Int.gcd_eq_gcd_ab, mul_comm m, mul_comm n, Nat.cast_one] intro h exact ⟨_, _, h⟩ theorem Nat.isCoprime_iff_coprime {m n : ℕ} : IsCoprime (m : ℤ) n ↔ Nat.Coprime m n := by rw [Int.isCoprime_iff_gcd_eq_one, Int.gcd_natCast_natCast] alias ⟨IsCoprime.nat_coprime, Nat.Coprime.isCoprime⟩ := Nat.isCoprime_iff_coprime theorem Nat.Coprime.cast {R : Type*} [CommRing R] {a b : ℕ} (h : Nat.Coprime a b) : IsCoprime (a : R) (b : R) := by rw [← isCoprime_iff_coprime] at h rw [← Int.cast_natCast a, ← Int.cast_natCast b] exact IsCoprime.intCast h theorem ne_zero_or_ne_zero_of_nat_coprime {A : Type u} [CommRing A] [Nontrivial A] {a b : ℕ} (h : Nat.Coprime a b) : (a : A) ≠ 0 ∨ (b : A) ≠ 0 := IsCoprime.ne_zero_or_ne_zero (R := A) <| by simpa only [map_natCast] using IsCoprime.map (Nat.Coprime.isCoprime h) (Int.castRingHom A) theorem IsCoprime.prod_left : (∀ i ∈ t, IsCoprime (s i) x) → IsCoprime (∏ i ∈ t, s i) x := by classical refine Finset.induction_on t (fun _ ↦ isCoprime_one_left) fun b t hbt ih H ↦ ?_ rw [Finset.prod_insert hbt] rw [Finset.forall_mem_insert] at H exact H.1.mul_left (ih H.2) theorem IsCoprime.prod_right : (∀ i ∈ t, IsCoprime x (s i)) → IsCoprime x (∏ i ∈ t, s i) := by simpa only [isCoprime_comm] using IsCoprime.prod_left (R := R) theorem IsCoprime.prod_left_iff : IsCoprime (∏ i ∈ t, s i) x ↔ ∀ i ∈ t, IsCoprime (s i) x := by classical refine Finset.induction_on t (iff_of_true isCoprime_one_left fun _ ↦ by simp) fun b t hbt ih ↦ ?_ rw [Finset.prod_insert hbt, IsCoprime.mul_left_iff, ih, Finset.forall_mem_insert] theorem IsCoprime.prod_right_iff : IsCoprime x (∏ i ∈ t, s i) ↔ ∀ i ∈ t, IsCoprime x (s i) := by simpa only [isCoprime_comm] using IsCoprime.prod_left_iff (R := R) theorem IsCoprime.of_prod_left (H1 : IsCoprime (∏ i ∈ t, s i) x) (i : I) (hit : i ∈ t) : IsCoprime (s i) x := IsCoprime.prod_left_iff.1 H1 i hit theorem IsCoprime.of_prod_right (H1 : IsCoprime x (∏ i ∈ t, s i)) (i : I) (hit : i ∈ t) : IsCoprime x (s i) := IsCoprime.prod_right_iff.1 H1 i hit -- Porting note: removed names of things due to linter, but they seem helpful theorem Finset.prod_dvd_of_coprime : (t : Set I).Pairwise (IsCoprime on s) → (∀ i ∈ t, s i ∣ z) → (∏ x ∈ t, s x) ∣ z := by classical exact Finset.induction_on t (fun _ _ ↦ one_dvd z) (by intro a r har ih Hs Hs1 rw [Finset.prod_insert har] have aux1 : a ∈ (↑(insert a r) : Set I) := Finset.mem_insert_self a r refine (IsCoprime.prod_right fun i hir ↦ Hs aux1 (Finset.mem_insert_of_mem hir) <| by rintro rfl exact har hir).mul_dvd (Hs1 a aux1) (ih (Hs.mono ?_) fun i hi ↦ Hs1 i <| Finset.mem_insert_of_mem hi) simp only [Finset.coe_insert, Set.subset_insert]) theorem Fintype.prod_dvd_of_coprime [Fintype I] (Hs : Pairwise (IsCoprime on s)) (Hs1 : ∀ i, s i ∣ z) : (∏ x, s x) ∣ z := Finset.prod_dvd_of_coprime (Hs.set_pairwise _) fun i _ ↦ Hs1 i end open Finset theorem exists_sum_eq_one_iff_pairwise_coprime [DecidableEq I] (h : t.Nonempty) : (∃ μ : I → R, (∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j) = 1) ↔ Pairwise (IsCoprime on fun i : t ↦ s i) := by induction h using Finset.Nonempty.cons_induction with | singleton => simp [exists_apply_eq, Pairwise, Function.onFun] | cons a t hat h ih => rw [pairwise_cons'] have mem : ∀ x ∈ t, a ∈ insert a t \ {x} := fun x hx ↦ by rw [mem_sdiff, mem_singleton] exact ⟨mem_insert_self _ _, fun ha ↦ hat (ha ▸ hx)⟩ constructor · rintro ⟨μ, hμ⟩ rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] at hμ refine ⟨ih.mp ⟨Pi.single h.choose (μ a * s h.choose) + μ * fun _ ↦ s a, ?_⟩, fun b hb ↦ ?_⟩ · rw [prod_eq_mul_prod_diff_singleton h.choose_spec, ← mul_assoc, ← @if_pos _ _ h.choose_spec R (_ * _) 0, ← sum_pi_single', ← sum_add_distrib] at hμ rw [← hμ, sum_congr rfl] intro x hx dsimp -- Porting note: terms were showing as sort of `HAdd.hadd` instead of `+` -- this whole proof pretty much breaks and has to be rewritten from scratch rw [add_mul] congr 1 · by_cases hx : x = h.choose · rw [hx, Pi.single_eq_same, Pi.single_eq_same] · rw [Pi.single_eq_of_ne hx, Pi.single_eq_of_ne hx, zero_mul] · rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _, mul_comm] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] · have : IsCoprime (s b) (s a) := ⟨μ a * ∏ i ∈ t \ {b}, s i, ∑ i ∈ t, μ i * ∏ j ∈ t \ {i}, s j, ?_⟩ · exact ⟨this.symm, this⟩ rw [mul_assoc, ← prod_eq_prod_diff_singleton_mul hb, sum_mul, ← hμ, sum_congr rfl] intro x hx rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] · rintro ⟨hs, Hb⟩ obtain ⟨μ, hμ⟩ := ih.mpr hs obtain ⟨u, v, huv⟩ := IsCoprime.prod_left fun b hb ↦ (Hb b hb).right use fun i ↦ if i = a then u else v * μ i have hμ' : (∑ i ∈ t, v * ((μ i * ∏ j ∈ t \ {i}, s j) * s a)) = v * s a := by rw [← mul_sum, ← sum_mul, hμ, one_mul] rw [sum_cons, cons_eq_insert, sdiff_singleton_eq_erase, erase_insert hat] simp only [↓reduceIte, ite_mul] rw [← huv, ← hμ', sum_congr rfl] intro x hx rw [mul_assoc, if_neg fun ha : x = a ↦ hat (ha.casesOn hx)] rw [mul_assoc] congr rw [prod_eq_prod_diff_singleton_mul (mem x hx) _] congr 2 rw [sdiff_sdiff_comm, sdiff_singleton_eq_erase a, erase_insert hat] theorem exists_sum_eq_one_iff_pairwise_coprime' [Fintype I] [Nonempty I] [DecidableEq I] : (∃ μ : I → R, (∑ i : I, μ i * ∏ j ∈ {i}ᶜ, s j) = 1) ↔ Pairwise (IsCoprime on s) := by convert exists_sum_eq_one_iff_pairwise_coprime Finset.univ_nonempty (s := s) using 1 simp only [Function.onFun, pairwise_subtype_iff_pairwise_finset', coe_univ, Set.pairwise_univ] theorem pairwise_coprime_iff_coprime_prod [DecidableEq I] : Pairwise (IsCoprime on fun i : t ↦ s i) ↔ ∀ i ∈ t, IsCoprime (s i) (∏ j ∈ t \ {i}, s j) := by refine ⟨fun hp i hi ↦ IsCoprime.prod_right_iff.mpr fun j hj ↦ ?_, fun hp ↦ ?_⟩ · rw [Finset.mem_sdiff, Finset.mem_singleton] at hj obtain ⟨hj, ji⟩ := hj refine @hp ⟨i, hi⟩ ⟨j, hj⟩ fun h ↦ ji (congrArg Subtype.val h).symm -- Porting note: is there a better way compared to the old `congr_arg coe h`? · rintro ⟨i, hi⟩ ⟨j, hj⟩ h apply IsCoprime.prod_right_iff.mp (hp i hi) exact Finset.mem_sdiff.mpr ⟨hj, fun f ↦ h <| Subtype.ext (Finset.mem_singleton.mp f).symm⟩ variable {m n : ℕ} theorem IsCoprime.pow_left (H : IsCoprime x y) : IsCoprime (x ^ m) y := by rw [← Finset.card_range m, ← Finset.prod_const] exact IsCoprime.prod_left fun _ _ ↦ H theorem IsCoprime.pow_right (H : IsCoprime x y) : IsCoprime x (y ^ n) := by rw [← Finset.card_range n, ← Finset.prod_const] exact IsCoprime.prod_right fun _ _ ↦ H theorem IsCoprime.pow (H : IsCoprime x y) : IsCoprime (x ^ m) (y ^ n) := H.pow_left.pow_right theorem IsCoprime.pow_left_iff (hm : 0 < m) : IsCoprime (x ^ m) y ↔ IsCoprime x y := by refine ⟨fun h ↦ ?_, IsCoprime.pow_left⟩ rw [← Finset.card_range m, ← Finset.prod_const] at h exact h.of_prod_left 0 (Finset.mem_range.mpr hm) theorem IsCoprime.pow_right_iff (hm : 0 < m) : IsCoprime x (y ^ m) ↔ IsCoprime x y := isCoprime_comm.trans <| (IsCoprime.pow_left_iff hm).trans <| isCoprime_comm theorem IsCoprime.pow_iff (hm : 0 < m) (hn : 0 < n) : IsCoprime (x ^ m) (y ^ n) ↔ IsCoprime x y := (IsCoprime.pow_left_iff hm).trans <| IsCoprime.pow_right_iff hn end IsCoprime section RelPrime variable {α I} [CommMonoid α] [DecompositionMonoid α] {x y z : α} {s : I → α} {t : Finset I} theorem IsRelPrime.prod_left : (∀ i ∈ t, IsRelPrime (s i) x) → IsRelPrime (∏ i ∈ t, s i) x := by classical refine Finset.induction_on t (fun _ ↦ isRelPrime_one_left) fun b t hbt ih H ↦ ?_ rw [Finset.prod_insert hbt] rw [Finset.forall_mem_insert] at H exact H.1.mul_left (ih H.2) theorem IsRelPrime.prod_right : (∀ i ∈ t, IsRelPrime x (s i)) → IsRelPrime x (∏ i ∈ t, s i) := by simpa only [isRelPrime_comm] using IsRelPrime.prod_left (α := α) theorem IsRelPrime.prod_left_iff : IsRelPrime (∏ i ∈ t, s i) x ↔ ∀ i ∈ t, IsRelPrime (s i) x := by classical refine Finset.induction_on t (iff_of_true isRelPrime_one_left fun _ ↦ by simp) fun b t hbt ih ↦ ?_ rw [Finset.prod_insert hbt, IsRelPrime.mul_left_iff, ih, Finset.forall_mem_insert] theorem IsRelPrime.prod_right_iff : IsRelPrime x (∏ i ∈ t, s i) ↔ ∀ i ∈ t, IsRelPrime x (s i) := by simpa only [isRelPrime_comm] using IsRelPrime.prod_left_iff (α := α) theorem IsRelPrime.of_prod_left (H1 : IsRelPrime (∏ i ∈ t, s i) x) (i : I) (hit : i ∈ t) : IsRelPrime (s i) x := IsRelPrime.prod_left_iff.1 H1 i hit theorem IsRelPrime.of_prod_right (H1 : IsRelPrime x (∏ i ∈ t, s i)) (i : I) (hit : i ∈ t) : IsRelPrime x (s i) := IsRelPrime.prod_right_iff.1 H1 i hit theorem Finset.prod_dvd_of_isRelPrime : (t : Set I).Pairwise (IsRelPrime on s) → (∀ i ∈ t, s i ∣ z) → (∏ x ∈ t, s x) ∣ z := by classical exact Finset.induction_on t (fun _ _ ↦ one_dvd z) (by intro a r har ih Hs Hs1 rw [Finset.prod_insert har] have aux1 : a ∈ (↑(insert a r) : Set I) := Finset.mem_insert_self a r refine (IsRelPrime.prod_right fun i hir ↦ Hs aux1 (Finset.mem_insert_of_mem hir) <| by rintro rfl exact har hir).mul_dvd (Hs1 a aux1) (ih (Hs.mono ?_) fun i hi ↦ Hs1 i <| Finset.mem_insert_of_mem hi) simp only [Finset.coe_insert, Set.subset_insert]) theorem Fintype.prod_dvd_of_isRelPrime [Fintype I] (Hs : Pairwise (IsRelPrime on s)) (Hs1 : ∀ i, s i ∣ z) : (∏ x, s x) ∣ z := Finset.prod_dvd_of_isRelPrime (Hs.set_pairwise _) fun i _ ↦ Hs1 i theorem pairwise_isRelPrime_iff_isRelPrime_prod [DecidableEq I] : Pairwise (IsRelPrime on fun i : t ↦ s i) ↔ ∀ i ∈ t, IsRelPrime (s i) (∏ j ∈ t \ {i}, s j) := by refine ⟨fun hp i hi ↦ IsRelPrime.prod_right_iff.mpr fun j hj ↦ ?_, fun hp ↦ ?_⟩ · rw [Finset.mem_sdiff, Finset.mem_singleton] at hj obtain ⟨hj, ji⟩ := hj exact @hp ⟨i, hi⟩ ⟨j, hj⟩ fun h ↦ ji (congrArg Subtype.val h).symm · rintro ⟨i, hi⟩ ⟨j, hj⟩ h apply IsRelPrime.prod_right_iff.mp (hp i hi) exact Finset.mem_sdiff.mpr ⟨hj, fun f ↦ h <| Subtype.ext (Finset.mem_singleton.mp f).symm⟩ namespace IsRelPrime variable {m n : ℕ} theorem pow_left (H : IsRelPrime x y) : IsRelPrime (x ^ m) y := by rw [← Finset.card_range m, ← Finset.prod_const] exact IsRelPrime.prod_left fun _ _ ↦ H theorem pow_right (H : IsRelPrime x y) : IsRelPrime x (y ^ n) := by rw [← Finset.card_range n, ← Finset.prod_const] exact IsRelPrime.prod_right fun _ _ ↦ H
Mathlib/RingTheory/Coprime/Lemmas.lean
281
289
theorem pow (H : IsRelPrime x y) : IsRelPrime (x ^ m) (y ^ n) := H.pow_left.pow_right theorem pow_left_iff (hm : 0 < m) : IsRelPrime (x ^ m) y ↔ IsRelPrime x y := by
refine ⟨fun h ↦ ?_, IsRelPrime.pow_left⟩ rw [← Finset.card_range m, ← Finset.prod_const] at h exact h.of_prod_left 0 (Finset.mem_range.mpr hm) theorem pow_right_iff (hm : 0 < m) : IsRelPrime x (y ^ m) ↔ IsRelPrime x y :=
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Moritz Doll -/ import Mathlib.LinearAlgebra.Prod /-! # Partially defined linear maps A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. We define a `SemilatticeInf` with `OrderBot` instance on this, and define three operations: * `mkSpanSingleton` defines a partial linear map defined on the span of a singleton. * `sup` takes two partial linear maps `f`, `g` that agree on the intersection of their domains, and returns the unique partial linear map on `f.domain ⊔ g.domain` that extends both `f` and `g`. * `sSup` takes a `DirectedOn (· ≤ ·)` set of partial linear maps, and returns the unique partial linear map on the `sSup` of their domains that extends all these maps. Moreover, we define * `LinearPMap.graph` is the graph of the partial linear map viewed as a submodule of `E × F`. Partially defined maps are currently used in `Mathlib` to prove Hahn-Banach theorem and its variations. Namely, `LinearPMap.sSup` implies that every chain of `LinearPMap`s is bounded above. They are also the basis for the theory of unbounded operators. -/ universe u v w /-- A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. -/ structure LinearPMap (R : Type u) [Ring R] (E : Type v) [AddCommGroup E] [Module R E] (F : Type w) [AddCommGroup F] [Module R F] where domain : Submodule R E toFun : domain →ₗ[R] F @[inherit_doc] notation:25 E " →ₗ.[" R:25 "] " F:0 => LinearPMap R E F variable {R : Type*} [Ring R] {E : Type*} [AddCommGroup E] [Module R E] {F : Type*} [AddCommGroup F] [Module R F] {G : Type*} [AddCommGroup G] [Module R G] namespace LinearPMap open Submodule @[coe] def toFun' (f : E →ₗ.[R] F) : f.domain → F := f.toFun instance : CoeFun (E →ₗ.[R] F) fun f : E →ₗ.[R] F => f.domain → F := ⟨toFun'⟩ @[simp] theorem toFun_eq_coe (f : E →ₗ.[R] F) (x : f.domain) : f.toFun x = f x := rfl @[ext (iff := false)] theorem ext {f g : E →ₗ.[R] F} (h : f.domain = g.domain) (h' : ∀ ⦃x : E⦄ ⦃hf : x ∈ f.domain⦄ ⦃hg : x ∈ g.domain⦄, f ⟨x, hf⟩ = g ⟨x, hg⟩) : f = g := by rcases f with ⟨f_dom, f⟩ rcases g with ⟨g_dom, g⟩ obtain rfl : f_dom = g_dom := h congr apply LinearMap.ext intro x apply h' /-- A dependent version of `ext`. -/ theorem dExt {f g : E →ₗ.[R] F} (h : f.domain = g.domain) (h' : ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y) : f = g := ext h fun _ _ _ ↦ h' rfl @[simp] theorem map_zero (f : E →ₗ.[R] F) : f 0 = 0 := f.toFun.map_zero theorem ext_iff {f g : E →ₗ.[R] F} : f = g ↔ f.domain = g.domain ∧ ∀ ⦃x : E⦄ ⦃hf : x ∈ f.domain⦄ ⦃hg : x ∈ g.domain⦄, f ⟨x, hf⟩ = g ⟨x, hg⟩ := ⟨by rintro rfl; simp, fun ⟨deq, feq⟩ ↦ ext deq feq⟩ theorem dExt_iff {f g : E →ₗ.[R] F} : f = g ↔ ∃ _domain_eq : f.domain = g.domain, ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y := ⟨fun EQ => EQ ▸ ⟨rfl, fun x y h => by congr exact mod_cast h⟩, fun ⟨deq, feq⟩ => dExt deq feq⟩ theorem ext' {s : Submodule R E} {f g : s →ₗ[R] F} (h : f = g) : mk s f = mk s g := h ▸ rfl theorem map_add (f : E →ₗ.[R] F) (x y : f.domain) : f (x + y) = f x + f y := f.toFun.map_add x y theorem map_neg (f : E →ₗ.[R] F) (x : f.domain) : f (-x) = -f x := f.toFun.map_neg x theorem map_sub (f : E →ₗ.[R] F) (x y : f.domain) : f (x - y) = f x - f y := f.toFun.map_sub x y theorem map_smul (f : E →ₗ.[R] F) (c : R) (x : f.domain) : f (c • x) = c • f x := f.toFun.map_smul c x @[simp] theorem mk_apply (p : Submodule R E) (f : p →ₗ[R] F) (x : p) : mk p f x = f x := rfl /-- The unique `LinearPMap` on `R ∙ x` that sends `x` to `y`. This version works for modules over rings, and requires a proof of `∀ c, c • x = 0 → c • y = 0`. -/ noncomputable def mkSpanSingleton' (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : E →ₗ.[R] F where domain := R ∙ x toFun := have H : ∀ c₁ c₂ : R, c₁ • x = c₂ • x → c₁ • y = c₂ • y := by intro c₁ c₂ h rw [← sub_eq_zero, ← sub_smul] at h ⊢ exact H _ h { toFun z := Classical.choose (mem_span_singleton.1 z.prop) • y map_add' y z := by rw [← add_smul, H] have (w : R ∙ x) := Classical.choose_spec (mem_span_singleton.1 w.prop) simp only [add_smul, sub_smul, this, ← coe_add] map_smul' c z := by rw [smul_smul, H] have (w : R ∙ x) := Classical.choose_spec (mem_span_singleton.1 w.prop) simp only [mul_smul, this] apply coe_smul } @[simp] theorem domain_mkSpanSingleton (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : (mkSpanSingleton' x y H).domain = R ∙ x := rfl @[simp] theorem mkSpanSingleton'_apply (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (c : R) (h) : mkSpanSingleton' x y H ⟨c • x, h⟩ = c • y := by dsimp [mkSpanSingleton'] rw [← sub_eq_zero, ← sub_smul] apply H simp only [sub_smul, one_smul, sub_eq_zero] apply Classical.choose_spec (mem_span_singleton.1 h) @[simp] theorem mkSpanSingleton'_apply_self (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (h) : mkSpanSingleton' x y H ⟨x, h⟩ = y := by conv_rhs => rw [← one_smul R y] rw [← mkSpanSingleton'_apply x y H 1 ?_] · congr rw [one_smul] · rwa [one_smul] /-- The unique `LinearPMap` on `span R {x}` that sends a non-zero vector `x` to `y`. This version works for modules over division rings. -/ noncomputable abbrev mkSpanSingleton {K E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E] [AddCommGroup F] [Module K F] (x : E) (y : F) (hx : x ≠ 0) : E →ₗ.[K] F := mkSpanSingleton' x y fun c hc => (smul_eq_zero.1 hc).elim (fun hc => by rw [hc, zero_smul]) fun hx' => absurd hx' hx theorem mkSpanSingleton_apply (K : Type*) {E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E] [AddCommGroup F] [Module K F] {x : E} (hx : x ≠ 0) (y : F) : mkSpanSingleton x y hx ⟨x, (Submodule.mem_span_singleton_self x : x ∈ Submodule.span K {x})⟩ = y := LinearPMap.mkSpanSingleton'_apply_self _ _ _ _ /-- Projection to the first coordinate as a `LinearPMap` -/ protected def fst (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] E where domain := p.prod p' toFun := (LinearMap.fst R E F).comp (p.prod p').subtype @[simp] theorem fst_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') : LinearPMap.fst p p' x = (x : E × F).1 := rfl /-- Projection to the second coordinate as a `LinearPMap` -/ protected def snd (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] F where domain := p.prod p' toFun := (LinearMap.snd R E F).comp (p.prod p').subtype @[simp] theorem snd_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') : LinearPMap.snd p p' x = (x : E × F).2 := rfl instance le : LE (E →ₗ.[R] F) := ⟨fun f g => f.domain ≤ g.domain ∧ ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y⟩ theorem apply_comp_inclusion {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) : T x = S (Submodule.inclusion h.1 x) := h.2 rfl theorem exists_of_le {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) : ∃ y : S.domain, (x : E) = y ∧ T x = S y := ⟨⟨x.1, h.1 x.2⟩, ⟨rfl, h.2 rfl⟩⟩ theorem eq_of_le_of_domain_eq {f g : E →ₗ.[R] F} (hle : f ≤ g) (heq : f.domain = g.domain) : f = g := dExt heq hle.2 /-- Given two partial linear maps `f`, `g`, the set of points `x` such that both `f` and `g` are defined at `x` and `f x = g x` form a submodule. -/ def eqLocus (f g : E →ₗ.[R] F) : Submodule R E where carrier := { x | ∃ (hf : x ∈ f.domain) (hg : x ∈ g.domain), f ⟨x, hf⟩ = g ⟨x, hg⟩ } zero_mem' := ⟨zero_mem _, zero_mem _, f.map_zero.trans g.map_zero.symm⟩ add_mem' {x y} := fun ⟨hfx, hgx, hx⟩ ⟨hfy, hgy, hy⟩ ↦ ⟨add_mem hfx hfy, add_mem hgx hgy, by simp_all [← AddMemClass.mk_add_mk, f.map_add, g.map_add]⟩ smul_mem' c x := fun ⟨hfx, hgx, hx⟩ ↦ ⟨smul_mem _ c hfx, smul_mem _ c hgx, by have {f : E →ₗ.[R] F} (hfx) : (⟨c • x, smul_mem _ c hfx⟩ : f.domain) = c • ⟨x, hfx⟩ := by simp rw [this hfx, this hgx, f.map_smul, g.map_smul, hx]⟩ instance bot : Bot (E →ₗ.[R] F) := ⟨⟨⊥, 0⟩⟩ instance inhabited : Inhabited (E →ₗ.[R] F) := ⟨⊥⟩ instance semilatticeInf : SemilatticeInf (E →ₗ.[R] F) where le := (· ≤ ·) le_refl f := ⟨le_refl f.domain, fun _ _ h => Subtype.eq h ▸ rfl⟩ le_trans := fun _ _ _ ⟨fg_le, fg_eq⟩ ⟨gh_le, gh_eq⟩ => ⟨le_trans fg_le gh_le, fun x _ hxz => have hxy : (x : E) = inclusion fg_le x := rfl (fg_eq hxy).trans (gh_eq <| hxy.symm.trans hxz)⟩ le_antisymm _ _ fg gf := eq_of_le_of_domain_eq fg (le_antisymm fg.1 gf.1) inf f g := ⟨f.eqLocus g, f.toFun.comp <| inclusion fun _x hx => hx.fst⟩ le_inf := by intro f g h ⟨fg_le, fg_eq⟩ ⟨fh_le, fh_eq⟩ exact ⟨fun x hx => ⟨fg_le hx, fh_le hx, (fg_eq (x := ⟨x, hx⟩) rfl).symm.trans (fh_eq rfl)⟩, fun x ⟨y, yg, hy⟩ h => fg_eq h⟩ inf_le_left f _ := ⟨fun _ hx => hx.fst, fun _ _ h => congr_arg f <| Subtype.eq <| h⟩ inf_le_right _ g := ⟨fun _ hx => hx.snd.fst, fun ⟨_, _, _, hx⟩ _ h => hx.trans <| congr_arg g <| Subtype.eq <| h⟩ instance orderBot : OrderBot (E →ₗ.[R] F) where bot := ⊥ bot_le f := ⟨bot_le, fun x y h => by have hx : x = 0 := Subtype.eq ((mem_bot R).1 x.2) have hy : y = 0 := Subtype.eq (h.symm.trans (congr_arg _ hx)) rw [hx, hy, map_zero, map_zero]⟩ theorem le_of_eqLocus_ge {f g : E →ₗ.[R] F} (H : f.domain ≤ f.eqLocus g) : f ≤ g := suffices f ≤ f ⊓ g from le_trans this inf_le_right ⟨H, fun _x _y hxy => ((inf_le_left : f ⊓ g ≤ f).2 hxy.symm).symm⟩ theorem domain_mono : StrictMono (@domain R _ E _ _ F _ _) := fun _f _g hlt => lt_of_le_of_ne hlt.1.1 fun heq => ne_of_lt hlt <| eq_of_le_of_domain_eq (le_of_lt hlt) heq private theorem sup_aux (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : ∃ fg : ↥(f.domain ⊔ g.domain) →ₗ[R] F, ∀ (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)), (x : E) + y = ↑z → fg z = f x + g y := by choose x hx y hy hxy using fun z : ↥(f.domain ⊔ g.domain) => mem_sup.1 z.prop set fg := fun z => f ⟨x z, hx z⟩ + g ⟨y z, hy z⟩ have fg_eq : ∀ (x' : f.domain) (y' : g.domain) (z' : ↥(f.domain ⊔ g.domain)) (_H : (x' : E) + y' = z'), fg z' = f x' + g y' := by intro x' y' z' H dsimp [fg] rw [add_comm, ← sub_eq_sub_iff_add_eq_add, eq_comm, ← map_sub, ← map_sub] apply h simp only [← eq_sub_iff_add_eq] at hxy simp only [AddSubgroupClass.coe_sub, coe_mk, coe_mk, hxy, ← sub_add, ← sub_sub, sub_self, zero_sub, ← H] apply neg_add_eq_sub use { toFun := fg, map_add' := ?_, map_smul' := ?_ }, fg_eq · rintro ⟨z₁, hz₁⟩ ⟨z₂, hz₂⟩ rw [← add_assoc, add_right_comm (f _), ← map_add, add_assoc, ← map_add] apply fg_eq simp only [coe_add, coe_mk, ← add_assoc] rw [add_right_comm (x _), hxy, add_assoc, hxy, coe_mk, coe_mk] · intro c z rw [smul_add, ← map_smul, ← map_smul] apply fg_eq simp only [coe_smul, coe_mk, ← smul_add, hxy, RingHom.id_apply] /-- Given two partial linear maps that agree on the intersection of their domains, `f.sup g h` is the unique partial linear map on `f.domain ⊔ g.domain` that agrees with `f` and `g`. -/ protected noncomputable def sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : E →ₗ.[R] F := ⟨_, Classical.choose (sup_aux f g h)⟩ @[simp] theorem domain_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : (f.sup g h).domain = f.domain ⊔ g.domain := rfl theorem sup_apply {f g : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)) (hz : (↑x : E) + ↑y = ↑z) : f.sup g H z = f x + g y := Classical.choose_spec (sup_aux f g H) x y z hz protected theorem left_le_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : f ≤ f.sup g h := by refine ⟨le_sup_left, fun z₁ z₂ hz => ?_⟩ rw [← add_zero (f _), ← g.map_zero] refine (sup_apply h _ _ _ ?_).symm simpa protected theorem right_le_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : g ≤ f.sup g h := by refine ⟨le_sup_right, fun z₁ z₂ hz => ?_⟩ rw [← zero_add (g _), ← f.map_zero] refine (sup_apply h _ _ _ ?_).symm simpa protected theorem sup_le {f g h : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (fh : f ≤ h) (gh : g ≤ h) : f.sup g H ≤ h := have Hf : f ≤ f.sup g H ⊓ h := le_inf (f.left_le_sup g H) fh have Hg : g ≤ f.sup g H ⊓ h := le_inf (f.right_le_sup g H) gh le_of_eqLocus_ge <| sup_le Hf.1 Hg.1 /-- Hypothesis for `LinearPMap.sup` holds, if `f.domain` is disjoint with `g.domain`. -/ theorem sup_h_of_disjoint (f g : E →ₗ.[R] F) (h : Disjoint f.domain g.domain) (x : f.domain) (y : g.domain) (hxy : (x : E) = y) : f x = g y := by rw [disjoint_def] at h have hy : y = 0 := Subtype.eq (h y (hxy ▸ x.2) y.2) have hx : x = 0 := Subtype.eq (hxy.trans <| congr_arg _ hy) simp [*] /-! ### Algebraic operations -/ section Zero instance instZero : Zero (E →ₗ.[R] F) := ⟨⊤, 0⟩ @[simp] theorem zero_domain : (0 : E →ₗ.[R] F).domain = ⊤ := rfl @[simp] theorem zero_apply (x : (⊤ : Submodule R E)) : (0 : E →ₗ.[R] F) x = 0 := rfl end Zero section SMul variable {M N : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F] variable [Monoid N] [DistribMulAction N F] [SMulCommClass R N F] instance instSMul : SMul M (E →ₗ.[R] F) := ⟨fun a f => { domain := f.domain toFun := a • f.toFun }⟩ @[simp] theorem smul_domain (a : M) (f : E →ₗ.[R] F) : (a • f).domain = f.domain := rfl theorem smul_apply (a : M) (f : E →ₗ.[R] F) (x : (a • f).domain) : (a • f) x = a • f x := rfl @[simp] theorem coe_smul (a : M) (f : E →ₗ.[R] F) : ⇑(a • f) = a • ⇑f := rfl instance instSMulCommClass [SMulCommClass M N F] : SMulCommClass M N (E →ₗ.[R] F) := ⟨fun a b f => ext' <| smul_comm a b f.toFun⟩ instance instIsScalarTower [SMul M N] [IsScalarTower M N F] : IsScalarTower M N (E →ₗ.[R] F) := ⟨fun a b f => ext' <| smul_assoc a b f.toFun⟩ instance instMulAction : MulAction M (E →ₗ.[R] F) where smul := (· • ·) one_smul := fun ⟨_s, f⟩ => ext' <| one_smul M f mul_smul a b f := ext' <| mul_smul a b f.toFun end SMul instance instNeg : Neg (E →ₗ.[R] F) := ⟨fun f => ⟨f.domain, -f.toFun⟩⟩ @[simp] theorem neg_domain (f : E →ₗ.[R] F) : (-f).domain = f.domain := rfl @[simp] theorem neg_apply (f : E →ₗ.[R] F) (x) : (-f) x = -f x := rfl instance instInvolutiveNeg : InvolutiveNeg (E →ₗ.[R] F) := ⟨fun f => by ext x y hxy · rfl · simp only [neg_apply, neg_neg]⟩ section Add instance instAdd : Add (E →ₗ.[R] F) := ⟨fun f g => { domain := f.domain ⊓ g.domain toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _)) + g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩ theorem add_domain (f g : E →ₗ.[R] F) : (f + g).domain = f.domain ⊓ g.domain := rfl theorem add_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) : (f + g) x = f ⟨x, x.prop.1⟩ + g ⟨x, x.prop.2⟩ := rfl instance instAddSemigroup : AddSemigroup (E →ₗ.[R] F) := ⟨fun f g h => by ext x y hxy · simp only [add_domain, inf_assoc] · simp only [add_apply, hxy, add_assoc]⟩ instance instAddZeroClass : AddZeroClass (E →ₗ.[R] F) := ⟨fun f => by ext x y hxy · simp [add_domain] · simp only [add_apply, hxy, zero_apply, zero_add], fun f => by ext x y hxy · simp [add_domain] · simp only [add_apply, hxy, zero_apply, add_zero]⟩ instance instAddMonoid : AddMonoid (E →ₗ.[R] F) where zero_add f := by simp add_zero := by simp nsmul := nsmulRec instance instAddCommMonoid : AddCommMonoid (E →ₗ.[R] F) := ⟨fun f g => by ext x y hxy · simp only [add_domain, inf_comm] · simp only [add_apply, hxy, add_comm]⟩ end Add section VAdd instance instVAdd : VAdd (E →ₗ[R] F) (E →ₗ.[R] F) := ⟨fun f g => { domain := g.domain toFun := f.comp g.domain.subtype + g.toFun }⟩ @[simp] theorem vadd_domain (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : (f +ᵥ g).domain = g.domain := rfl theorem vadd_apply (f : E →ₗ[R] F) (g : E →ₗ.[R] F) (x : (f +ᵥ g).domain) : (f +ᵥ g) x = f x + g x := rfl @[simp] theorem coe_vadd (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : ⇑(f +ᵥ g) = ⇑(f.comp g.domain.subtype) + ⇑g := rfl instance instAddAction : AddAction (E →ₗ[R] F) (E →ₗ.[R] F) where vadd := (· +ᵥ ·) zero_vadd := fun ⟨_s, _f⟩ => ext' <| zero_add _ add_vadd := fun _f₁ _f₂ ⟨_s, _g⟩ => ext' <| LinearMap.ext fun _x => add_assoc _ _ _ end VAdd section Sub instance instSub : Sub (E →ₗ.[R] F) := ⟨fun f g => { domain := f.domain ⊓ g.domain toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _)) - g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩ theorem sub_domain (f g : E →ₗ.[R] F) : (f - g).domain = f.domain ⊓ g.domain := rfl theorem sub_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) : (f - g) x = f ⟨x, x.prop.1⟩ - g ⟨x, x.prop.2⟩ := rfl instance instSubtractionCommMonoid : SubtractionCommMonoid (E →ₗ.[R] F) where add_comm := add_comm sub_eq_add_neg f g := by ext x _ h · rfl simp [sub_apply, add_apply, neg_apply, ← sub_eq_add_neg, h] neg_neg := neg_neg neg_add_rev f g := by ext x _ h · simp [add_domain, sub_domain, neg_domain, And.comm] simp [sub_apply, add_apply, neg_apply, ← sub_eq_add_neg, h] neg_eq_of_add f g h' := by ext x hf hg · have : (0 : E →ₗ.[R] F).domain = ⊤ := zero_domain simp only [← h', add_domain, inf_eq_top_iff] at this rw [neg_domain, this.1, this.2] simp only [neg_domain, neg_apply, neg_eq_iff_add_eq_zero] rw [ext_iff] at h' rcases h' with ⟨hdom, h'⟩ rw [zero_domain] at hdom simp only [hdom, neg_domain, zero_domain, mem_top, zero_apply, forall_true_left] at h' apply h' zsmul := zsmulRec end Sub section variable {K : Type*} [DivisionRing K] [Module K E] [Module K F] /-- Extend a `LinearPMap` to `f.domain ⊔ K ∙ x`. -/ noncomputable def supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) : E →ₗ.[K] F := f.sup (mkSpanSingleton x y fun h₀ => hx <| h₀.symm ▸ f.domain.zero_mem) <| sup_h_of_disjoint _ _ <| by simpa [disjoint_span_singleton] using fun h ↦ False.elim <| hx h @[simp] theorem domain_supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) : (f.supSpanSingleton x y hx).domain = f.domain ⊔ K ∙ x := rfl @[simp] theorem supSpanSingleton_apply_mk (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) (x' : E) (hx' : x' ∈ f.domain) (c : K) : f.supSpanSingleton x y hx ⟨x' + c • x, mem_sup.2 ⟨x', hx', _, mem_span_singleton.2 ⟨c, rfl⟩, rfl⟩⟩ = f ⟨x', hx'⟩ + c • y := by unfold supSpanSingleton rw [sup_apply _ ⟨x', hx'⟩ ⟨c • x, _⟩, mkSpanSingleton'_apply] · exact mem_span_singleton.2 ⟨c, rfl⟩ · rfl end private theorem sSup_aux (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) : ∃ f : ↥(sSup (domain '' c)) →ₗ[R] F, (⟨_, f⟩ : E →ₗ.[R] F) ∈ upperBounds c := by rcases c.eq_empty_or_nonempty with ceq | cne · subst c simp have hdir : DirectedOn (· ≤ ·) (domain '' c) := directedOn_image.2 (hc.mono @(domain_mono.monotone)) have P : ∀ x : ↥(sSup (domain '' c)), { p : c // (x : E) ∈ p.val.domain } := by rintro x apply Classical.indefiniteDescription have := (mem_sSup_of_directed (cne.image _) hdir).1 x.2 rwa [Set.exists_mem_image, ← bex_def, SetCoe.exists'] at this set f : ↥(sSup (domain '' c)) → F := fun x => (P x).val.val ⟨x, (P x).property⟩ have f_eq : ∀ (p : c) (x : ↥(sSup (domain '' c))) (y : p.1.1) (_hxy : (x : E) = y), f x = p.1 y := by intro p x y hxy rcases hc (P x).1.1 (P x).1.2 p.1 p.2 with ⟨q, _hqc, ⟨hxq1, hxq2⟩, ⟨hpq1, hpq2⟩⟩ exact (hxq2 (y := ⟨y, hpq1 y.2⟩) hxy).trans (hpq2 rfl).symm use { toFun := f, map_add' := ?_, map_smul' := ?_ }, ?_ · intro x y rcases hc (P x).1.1 (P x).1.2 (P y).1.1 (P y).1.2 with ⟨p, hpc, hpx, hpy⟩ set x' := inclusion hpx.1 ⟨x, (P x).2⟩ set y' := inclusion hpy.1 ⟨y, (P y).2⟩ rw [f_eq ⟨p, hpc⟩ x x' rfl, f_eq ⟨p, hpc⟩ y y' rfl, f_eq ⟨p, hpc⟩ (x + y) (x' + y') rfl, map_add] · intro c x simp only [RingHom.id_apply] rw [f_eq (P x).1 (c • x) (c • ⟨x, (P x).2⟩) rfl, ← map_smul] · intro p hpc refine ⟨le_sSup <| Set.mem_image_of_mem domain hpc, fun x y hxy => Eq.symm ?_⟩ exact f_eq ⟨p, hpc⟩ _ _ hxy.symm protected noncomputable def sSup (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) : E →ₗ.[R] F := ⟨_, Classical.choose <| sSup_aux c hc⟩ protected theorem le_sSup {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {f : E →ₗ.[R] F} (hf : f ∈ c) : f ≤ LinearPMap.sSup c hc := Classical.choose_spec (sSup_aux c hc) hf protected theorem sSup_le {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {g : E →ₗ.[R] F} (hg : ∀ f ∈ c, f ≤ g) : LinearPMap.sSup c hc ≤ g := le_of_eqLocus_ge <| sSup_le fun _ ⟨f, hf, Eq⟩ => Eq ▸ have : f ≤ LinearPMap.sSup c hc ⊓ g := le_inf (LinearPMap.le_sSup _ hf) (hg f hf) this.1 protected theorem sSup_apply {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {l : E →ₗ.[R] F} (hl : l ∈ c) (x : l.domain) : (LinearPMap.sSup c hc) ⟨x, (LinearPMap.le_sSup hc hl).1 x.2⟩ = l x := by symm apply (Classical.choose_spec (sSup_aux c hc) hl).2 rfl end LinearPMap namespace LinearMap /-- Restrict a linear map to a submodule, reinterpreting the result as a `LinearPMap`. -/ def toPMap (f : E →ₗ[R] F) (p : Submodule R E) : E →ₗ.[R] F := ⟨p, f.comp p.subtype⟩ @[simp] theorem toPMap_apply (f : E →ₗ[R] F) (p : Submodule R E) (x : p) : f.toPMap p x = f x := rfl @[simp] theorem toPMap_domain (f : E →ₗ[R] F) (p : Submodule R E) : (f.toPMap p).domain = p := rfl /-- Compose a linear map with a `LinearPMap` -/ def compPMap (g : F →ₗ[R] G) (f : E →ₗ.[R] F) : E →ₗ.[R] G where domain := f.domain toFun := g.comp f.toFun @[simp] theorem compPMap_apply (g : F →ₗ[R] G) (f : E →ₗ.[R] F) (x) : g.compPMap f x = g (f x) := rfl end LinearMap namespace LinearPMap /-- Restrict codomain of a `LinearPMap` -/ def codRestrict (f : E →ₗ.[R] F) (p : Submodule R F) (H : ∀ x, f x ∈ p) : E →ₗ.[R] p where domain := f.domain toFun := f.toFun.codRestrict p H /-- Compose two `LinearPMap`s -/ def comp (g : F →ₗ.[R] G) (f : E →ₗ.[R] F) (H : ∀ x : f.domain, f x ∈ g.domain) : E →ₗ.[R] G := g.toFun.compPMap <| f.codRestrict _ H /-- `f.coprod g` is the partially defined linear map defined on `f.domain × g.domain`, and sending `p` to `f p.1 + g p.2`. -/ def coprod (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) : E × F →ₗ.[R] G where domain := f.domain.prod g.domain toFun := -- Porting note: This is just -- `(f.comp (LinearPMap.fst f.domain g.domain) fun x => x.2.1).toFun +` -- ` (g.comp (LinearPMap.snd f.domain g.domain) fun x => x.2.2).toFun`, HAdd.hAdd (α := f.domain.prod g.domain →ₗ[R] G) (β := f.domain.prod g.domain →ₗ[R] G) (f.comp (LinearPMap.fst f.domain g.domain) fun x => x.2.1).toFun (g.comp (LinearPMap.snd f.domain g.domain) fun x => x.2.2).toFun @[simp] theorem coprod_apply (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) (x) : f.coprod g x = f ⟨(x : E × F).1, x.2.1⟩ + g ⟨(x : E × F).2, x.2.2⟩ := rfl /-- Restrict a partially defined linear map to a submodule of `E` contained in `f.domain`. -/ def domRestrict (f : E →ₗ.[R] F) (S : Submodule R E) : E →ₗ.[R] F := ⟨S ⊓ f.domain, f.toFun.comp (Submodule.inclusion (by simp))⟩ @[simp] theorem domRestrict_domain (f : E →ₗ.[R] F) {S : Submodule R E} : (f.domRestrict S).domain = S ⊓ f.domain := rfl theorem domRestrict_apply {f : E →ₗ.[R] F} {S : Submodule R E} ⦃x : ↥(S ⊓ f.domain)⦄ ⦃y : f.domain⦄ (h : (x : E) = y) : f.domRestrict S x = f y := by have : Submodule.inclusion (by simp) x = y := by ext simp [h] rw [← this] exact LinearPMap.mk_apply _ _ _ theorem domRestrict_le {f : E →ₗ.[R] F} {S : Submodule R E} : f.domRestrict S ≤ f := ⟨by simp, fun _ _ hxy => domRestrict_apply hxy⟩ /-! ### Graph -/ section Graph /-- The graph of a `LinearPMap` viewed as a submodule on `E × F`. -/ def graph (f : E →ₗ.[R] F) : Submodule R (E × F) := f.toFun.graph.map (f.domain.subtype.prodMap (LinearMap.id : F →ₗ[R] F)) theorem mem_graph_iff' (f : E →ₗ.[R] F) {x : E × F} : x ∈ f.graph ↔ ∃ y : f.domain, (↑y, f y) = x := by simp [graph] @[simp] theorem mem_graph_iff (f : E →ₗ.[R] F) {x : E × F} : x ∈ f.graph ↔ ∃ y : f.domain, (↑y : E) = x.1 ∧ f y = x.2 := by cases x simp_rw [mem_graph_iff', Prod.mk_inj] /-- The tuple `(x, f x)` is contained in the graph of `f`. -/ theorem mem_graph (f : E →ₗ.[R] F) (x : domain f) : ((x : E), f x) ∈ f.graph := by simp theorem graph_map_fst_eq_domain (f : E →ₗ.[R] F) : f.graph.map (LinearMap.fst R E F) = f.domain := by ext x simp only [Submodule.mem_map, mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left, LinearMap.fst_apply, Prod.exists, exists_and_right, exists_eq_right] constructor <;> intro h · rcases h with ⟨x, hx, _⟩ exact hx · use f ⟨x, h⟩ simp only [h, exists_const] theorem graph_map_snd_eq_range (f : E →ₗ.[R] F) : f.graph.map (LinearMap.snd R E F) = LinearMap.range f.toFun := by ext; simp variable {M : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F] (y : M) /-- The graph of `z • f` as a pushforward. -/ theorem smul_graph (f : E →ₗ.[R] F) (z : M) : (z • f).graph = f.graph.map ((LinearMap.id : E →ₗ[R] E).prodMap (z • (LinearMap.id : F →ₗ[R] F))) := by ext ⟨x_fst, x_snd⟩ constructor <;> intro h · rw [mem_graph_iff] at h rcases h with ⟨y, hy, h⟩ rw [LinearPMap.smul_apply] at h rw [Submodule.mem_map] simp only [mem_graph_iff, LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.smul_apply, Prod.mk_inj, Prod.exists, exists_exists_and_eq_and] use x_fst, y, hy rw [Submodule.mem_map] at h rcases h with ⟨x', hx', h⟩ cases x' simp only [LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.smul_apply, Prod.mk_inj] at h rw [mem_graph_iff] at hx' ⊢ rcases hx' with ⟨y, hy, hx'⟩ use y rw [← h.1, ← h.2] simp [hy, hx'] /-- The graph of `-f` as a pushforward. -/ theorem neg_graph (f : E →ₗ.[R] F) : (-f).graph = f.graph.map ((LinearMap.id : E →ₗ[R] E).prodMap (-(LinearMap.id : F →ₗ[R] F))) := by ext ⟨x_fst, x_snd⟩ constructor <;> intro h · rw [mem_graph_iff] at h rcases h with ⟨y, hy, h⟩ rw [LinearPMap.neg_apply] at h rw [Submodule.mem_map] simp only [mem_graph_iff, LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.neg_apply, Prod.mk_inj, Prod.exists, exists_exists_and_eq_and] use x_fst, y, hy rw [Submodule.mem_map] at h rcases h with ⟨x', hx', h⟩ cases x' simp only [LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.neg_apply, Prod.mk_inj] at h rw [mem_graph_iff] at hx' ⊢ rcases hx' with ⟨y, hy, hx'⟩ use y rw [← h.1, ← h.2] simp [hy, hx'] theorem mem_graph_snd_inj (f : E →ₗ.[R] F) {x y : E} {x' y' : F} (hx : (x, x') ∈ f.graph) (hy : (y, y') ∈ f.graph) (hxy : x = y) : x' = y' := by rw [mem_graph_iff] at hx hy rcases hx with ⟨x'', hx1, hx2⟩ rcases hy with ⟨y'', hy1, hy2⟩ simp only at hx1 hx2 hy1 hy2 rw [← hx1, ← hy1, SetLike.coe_eq_coe] at hxy rw [← hx2, ← hy2, hxy] theorem mem_graph_snd_inj' (f : E →ₗ.[R] F) {x y : E × F} (hx : x ∈ f.graph) (hy : y ∈ f.graph) (hxy : x.1 = y.1) : x.2 = y.2 := by cases x cases y exact f.mem_graph_snd_inj hx hy hxy /-- The property that `f 0 = 0` in terms of the graph. -/ theorem graph_fst_eq_zero_snd (f : E →ₗ.[R] F) {x : E} {x' : F} (h : (x, x') ∈ f.graph) (hx : x = 0) : x' = 0 := f.mem_graph_snd_inj h f.graph.zero_mem hx
Mathlib/LinearAlgebra/LinearPMap.lean
772
775
theorem mem_domain_iff {f : E →ₗ.[R] F} {x : E} : x ∈ f.domain ↔ ∃ y : F, (x, y) ∈ f.graph := by
constructor <;> intro h · use f ⟨x, h⟩ exact f.mem_graph ⟨x, h⟩
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Measure.Decomposition.Exhaustion import Mathlib.MeasureTheory.Measure.Prod /-! # Measure with a given density with respect to another measure For a measure `μ` on `α` and a function `f : α → ℝ≥0∞`, we define a new measure `μ.withDensity f`. On a measurable set `s`, that measure has value `∫⁻ a in s, f a ∂μ`. An important result about `withDensity` is the Radon-Nikodym theorem. It states that, given measures `μ, ν`, if `HaveLebesgueDecomposition μ ν` then `μ` is absolutely continuous with respect to `ν` if and only if there exists a measurable function `f : α → ℝ≥0∞` such that `μ = ν.withDensity f`. See `MeasureTheory.Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq`. -/ open Set hiding restrict restrict_apply open Filter ENNReal NNReal MeasureTheory.Measure namespace MeasureTheory variable {α : Type*} {m0 : MeasurableSpace α} {μ : Measure α} /-- Given a measure `μ : Measure α` and a function `f : α → ℝ≥0∞`, `μ.withDensity f` is the measure such that for a measurable set `s` we have `μ.withDensity f s = ∫⁻ a in s, f a ∂μ`. -/ noncomputable def Measure.withDensity {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : Measure α := Measure.ofMeasurable (fun s _ => ∫⁻ a in s, f a ∂μ) (by simp) fun _ hs hd => lintegral_iUnion hs hd _ @[simp] theorem withDensity_apply (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := Measure.ofMeasurable_apply s hs theorem withDensity_apply_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂μ ≤ μ.withDensity f s := by let t := toMeasurable (μ.withDensity f) s calc ∫⁻ a in s, f a ∂μ ≤ ∫⁻ a in t, f a ∂μ := lintegral_mono_set (subset_toMeasurable (withDensity μ f) s) _ = μ.withDensity f t := (withDensity_apply f (measurableSet_toMeasurable (withDensity μ f) s)).symm _ = μ.withDensity f s := measure_toMeasurable s /-! In the next theorem, the s-finiteness assumption is necessary. Here is a counterexample without this assumption. Let `α` be an uncountable space, let `x₀` be some fixed point, and consider the σ-algebra made of those sets which are countable and do not contain `x₀`, and of their complements. This is the σ-algebra generated by the sets `{x}` for `x ≠ x₀`. Define a measure equal to `+∞` on nonempty sets. Let `s = {x₀}` and `f` the indicator of `sᶜ`. Then * `∫⁻ a in s, f a ∂μ = 0`. Indeed, consider a simple function `g ≤ f`. It vanishes on `s`. Then `∫⁻ a in s, g a ∂μ = 0`. Taking the supremum over `g` gives the claim. * `μ.withDensity f s = +∞`. Indeed, this is the infimum of `μ.withDensity f t` over measurable sets `t` containing `s`. As `s` is not measurable, such a set `t` contains a point `x ≠ x₀`. Then `μ.withDensity f t ≥ μ.withDensity f {x} = ∫⁻ a in {x}, f a ∂μ = μ {x} = +∞`. One checks that `μ.withDensity f = μ`, while `μ.restrict s` gives zero mass to sets not containing `x₀`, and infinite mass to those that contain it. -/ theorem withDensity_apply' [SFinite μ] (f : α → ℝ≥0∞) (s : Set α) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := by apply le_antisymm ?_ (withDensity_apply_le f s) let t := toMeasurable μ s calc μ.withDensity f s ≤ μ.withDensity f t := measure_mono (subset_toMeasurable μ s) _ = ∫⁻ a in t, f a ∂μ := withDensity_apply f (measurableSet_toMeasurable μ s) _ = ∫⁻ a in s, f a ∂μ := by congr 1; exact restrict_toMeasurable_of_sFinite s @[simp] lemma withDensity_zero_left (f : α → ℝ≥0∞) : (0 : Measure α).withDensity f = 0 := by ext s hs rw [withDensity_apply _ hs] simp theorem withDensity_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : μ.withDensity f = μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] exact lintegral_congr_ae (ae_restrict_of_ae h) lemma withDensity_mono {f g : α → ℝ≥0∞} (hfg : f ≤ᵐ[μ] g) : μ.withDensity f ≤ μ.withDensity g := by refine le_iff.2 fun s hs ↦ ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] refine setLIntegral_mono_ae' hs ?_ filter_upwards [hfg] with x h_le using fun _ ↦ h_le theorem withDensity_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.add_apply, withDensity_apply _ hs, withDensity_apply _ hs, ← lintegral_add_left hf] simp only [Pi.add_apply] theorem withDensity_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by simpa only [add_comm] using withDensity_add_left hg f theorem withDensity_add_measure {m : MeasurableSpace α} (μ ν : Measure α) (f : α → ℝ≥0∞) : (μ + ν).withDensity f = μ.withDensity f + ν.withDensity f := by ext1 s hs simp only [withDensity_apply f hs, restrict_add, lintegral_add_measure, Measure.add_apply] theorem withDensity_sum {ι : Type*} {m : MeasurableSpace α} (μ : ι → Measure α) (f : α → ℝ≥0∞) : (sum μ).withDensity f = sum fun n => (μ n).withDensity f := by ext1 s hs simp_rw [sum_apply _ hs, withDensity_apply f hs, restrict_sum μ hs, lintegral_sum_measure] theorem withDensity_smul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul r hf] simp only [Pi.smul_apply, smul_eq_mul] theorem withDensity_smul' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul' r f hr] simp only [Pi.smul_apply, smul_eq_mul] theorem withDensity_smul_measure (r : ℝ≥0∞) (f : α → ℝ≥0∞) : (r • μ).withDensity f = r • μ.withDensity f := by ext s hs simp [withDensity_apply, hs] theorem isFiniteMeasure_withDensity {f : α → ℝ≥0∞} (hf : ∫⁻ a, f a ∂μ ≠ ∞) : IsFiniteMeasure (μ.withDensity f) := { measure_univ_lt_top := by rwa [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ, lt_top_iff_ne_top] } theorem withDensity_absolutelyContinuous {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : μ.withDensity f ≪ μ := by refine AbsolutelyContinuous.mk fun s hs₁ hs₂ => ?_ rw [withDensity_apply _ hs₁] exact setLIntegral_measure_zero _ _ hs₂ @[simp] theorem withDensity_zero : μ.withDensity 0 = 0 := by ext1 s hs simp [withDensity_apply _ hs] @[simp] theorem withDensity_one : μ.withDensity 1 = μ := by ext1 s hs simp [withDensity_apply _ hs] @[simp] theorem withDensity_const (c : ℝ≥0∞) : μ.withDensity (fun _ ↦ c) = c • μ := by ext1 s hs simp [withDensity_apply _ hs] theorem withDensity_tsum {ι : Type*} [Countable ι] {f : ι → α → ℝ≥0∞} (h : ∀ i, Measurable (f i)) : μ.withDensity (∑' n, f n) = sum fun n => μ.withDensity (f n) := by ext1 s hs simp_rw [sum_apply _ hs, withDensity_apply _ hs] change ∫⁻ x in s, (∑' n, f n) x ∂μ = ∑' i, ∫⁻ x, f i x ∂μ.restrict s rw [← lintegral_tsum fun i => (h i).aemeasurable] exact lintegral_congr fun x => tsum_apply (Pi.summable.2 fun _ => ENNReal.summable) theorem withDensity_indicator {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : μ.withDensity (s.indicator f) = (μ.restrict s).withDensity f := by ext1 t ht rw [withDensity_apply _ ht, lintegral_indicator hs, restrict_comm hs, ← withDensity_apply _ ht] theorem withDensity_indicator_one {s : Set α} (hs : MeasurableSet s) : μ.withDensity (s.indicator 1) = μ.restrict s := by rw [withDensity_indicator hs, withDensity_one] theorem withDensity_ofReal_mutuallySingular {f : α → ℝ} (hf : Measurable f) : (μ.withDensity fun x => ENNReal.ofReal <| f x) ⟂ₘ μ.withDensity fun x => ENNReal.ofReal <| -f x := by set S : Set α := { x | f x < 0 } have hS : MeasurableSet S := measurableSet_lt hf measurable_const refine ⟨S, hS, ?_, ?_⟩ · rw [withDensity_apply _ hS, lintegral_eq_zero_iff hf.ennreal_ofReal, EventuallyEq] exact (ae_restrict_mem hS).mono fun x hx => ENNReal.ofReal_eq_zero.2 (le_of_lt hx) · rw [withDensity_apply _ hS.compl, lintegral_eq_zero_iff hf.neg.ennreal_ofReal, EventuallyEq] exact (ae_restrict_mem hS.compl).mono fun x hx => ENNReal.ofReal_eq_zero.2 (not_lt.1 <| mt neg_pos.1 hx) theorem restrict_withDensity {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : (μ.withDensity f).restrict s = (μ.restrict s).withDensity f := by ext1 t ht rw [restrict_apply ht, withDensity_apply _ ht, withDensity_apply _ (ht.inter hs), restrict_restrict ht] theorem restrict_withDensity' [SFinite μ] (s : Set α) (f : α → ℝ≥0∞) : (μ.withDensity f).restrict s = (μ.restrict s).withDensity f := by ext1 t ht rw [restrict_apply ht, withDensity_apply _ ht, withDensity_apply' _ (t ∩ s), restrict_restrict ht] lemma trim_withDensity {m m0 : MeasurableSpace α} {μ : Measure α} (hm : m ≤ m0) {f : α → ℝ≥0∞} (hf : Measurable[m] f) : (μ.withDensity f).trim hm = (μ.trim hm).withDensity f := by refine @Measure.ext _ m _ _ (fun s hs ↦ ?_) rw [withDensity_apply _ hs, restrict_trim _ _ hs, lintegral_trim _ hf, trim_measurableSet_eq _ hs, withDensity_apply _ (hm s hs)] lemma Measure.MutuallySingular.withDensity {ν : Measure α} {f : α → ℝ≥0∞} (h : μ ⟂ₘ ν) : μ.withDensity f ⟂ₘ ν := MutuallySingular.mono_ac h (withDensity_absolutelyContinuous _ _) AbsolutelyContinuous.rfl @[simp] theorem withDensity_eq_zero_iff {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : μ.withDensity f = 0 ↔ f =ᵐ[μ] 0 := by rw [← measure_univ_eq_zero, withDensity_apply _ .univ, restrict_univ, lintegral_eq_zero_iff' hf] alias ⟨withDensity_eq_zero, _⟩ := withDensity_eq_zero_iff theorem withDensity_apply_eq_zero' {f : α → ℝ≥0∞} {s : Set α} (hf : AEMeasurable f μ) : μ.withDensity f s = 0 ↔ μ ({ x | f x ≠ 0 } ∩ s) = 0 := by constructor · intro hs let t := toMeasurable (μ.withDensity f) s apply measure_mono_null (inter_subset_inter_right _ (subset_toMeasurable (μ.withDensity f) s)) have A : μ.withDensity f t = 0 := by rw [measure_toMeasurable, hs] rw [withDensity_apply f (measurableSet_toMeasurable _ s), lintegral_eq_zero_iff' (AEMeasurable.restrict hf), EventuallyEq, ae_restrict_iff'₀, ae_iff] at A swap · simp only [measurableSet_toMeasurable, MeasurableSet.nullMeasurableSet] simp only [Pi.zero_apply, mem_setOf_eq, Filter.mem_mk] at A convert A using 2 ext x simp only [and_comm, exists_prop, mem_inter_iff, mem_setOf_eq, mem_compl_iff, not_forall] · intro hs let t := toMeasurable μ ({ x | f x ≠ 0 } ∩ s) have A : s ⊆ t ∪ { x | f x = 0 } := by intro x hx rcases eq_or_ne (f x) 0 with (fx | fx) · simp only [fx, mem_union, mem_setOf_eq, eq_self_iff_true, or_true] · left apply subset_toMeasurable _ _ exact ⟨fx, hx⟩ apply measure_mono_null A (measure_union_null _ _) · apply withDensity_absolutelyContinuous rwa [measure_toMeasurable] rcases hf with ⟨g, hg, hfg⟩ have t : {x | f x = 0} =ᵐ[μ.withDensity f] {x | g x = 0} := by apply withDensity_absolutelyContinuous filter_upwards [hfg] with a ha rw [eq_iff_iff] exact ⟨fun h ↦ by rw [h] at ha; exact ha.symm, fun h ↦ by rw [h] at ha; exact ha⟩ rw [measure_congr t, withDensity_congr_ae hfg] have M : MeasurableSet { x : α | g x = 0 } := hg (measurableSet_singleton _) rw [withDensity_apply _ M, lintegral_eq_zero_iff hg] filter_upwards [ae_restrict_mem M] simp only [imp_self, Pi.zero_apply, imp_true_iff] theorem withDensity_apply_eq_zero {f : α → ℝ≥0∞} {s : Set α} (hf : Measurable f) : μ.withDensity f s = 0 ↔ μ ({ x | f x ≠ 0 } ∩ s) = 0 := withDensity_apply_eq_zero' <| hf.aemeasurable theorem ae_withDensity_iff' {p : α → Prop} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ, f x ≠ 0 → p x := by rw [ae_iff, ae_iff, withDensity_apply_eq_zero' hf, iff_iff_eq] congr ext x simp only [exists_prop, mem_inter_iff, mem_setOf_eq, not_forall] theorem ae_withDensity_iff {p : α → Prop} {f : α → ℝ≥0∞} (hf : Measurable f) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ, f x ≠ 0 → p x := ae_withDensity_iff' <| hf.aemeasurable theorem ae_withDensity_iff_ae_restrict' {p : α → Prop} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ.restrict { x | f x ≠ 0 }, p x := by rw [ae_withDensity_iff' hf, ae_restrict_iff'₀] · simp only [mem_setOf] · rcases hf with ⟨g, hg, hfg⟩ have nonneg_eq_ae : {x | g x ≠ 0} =ᵐ[μ] {x | f x ≠ 0} := by filter_upwards [hfg] with a ha simp only [eq_iff_iff] exact ⟨fun (h : g a ≠ 0) ↦ by rwa [← ha] at h, fun (h : f a ≠ 0) ↦ by rwa [ha] at h⟩ exact NullMeasurableSet.congr (MeasurableSet.nullMeasurableSet <| hg (measurableSet_singleton _)).compl nonneg_eq_ae theorem ae_withDensity_iff_ae_restrict {p : α → Prop} {f : α → ℝ≥0∞} (hf : Measurable f) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ.restrict { x | f x ≠ 0 }, p x := ae_withDensity_iff_ae_restrict' <| hf.aemeasurable theorem aemeasurable_withDensity_ennreal_iff' {f : α → ℝ≥0} (hf : AEMeasurable f μ) {g : α → ℝ≥0∞} : AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔ AEMeasurable (fun x => (f x : ℝ≥0∞) * g x) μ := by have t : ∃ f', Measurable f' ∧ f =ᵐ[μ] f' := hf rcases t with ⟨f', hf'_m, hf'_ae⟩ constructor · rintro ⟨g', g'meas, hg'⟩ have A : MeasurableSet {x | f' x ≠ 0} := hf'_m (measurableSet_singleton _).compl refine ⟨fun x => f' x * g' x, hf'_m.coe_nnreal_ennreal.smul g'meas, ?_⟩ apply ae_of_ae_restrict_of_ae_restrict_compl { x | f' x ≠ 0 } · rw [EventuallyEq, ae_withDensity_iff' hf.coe_nnreal_ennreal] at hg' rw [ae_restrict_iff' A] filter_upwards [hg', hf'_ae] with a ha h'a h_a_nonneg have : (f' a : ℝ≥0∞) ≠ 0 := by simpa only [Ne, ENNReal.coe_eq_zero] using h_a_nonneg rw [← h'a] at this ⊢ rw [ha this] · rw [ae_restrict_iff' A.compl] filter_upwards [hf'_ae] with a ha ha_null have ha_null : f' a = 0 := Function.nmem_support.mp ha_null rw [ha_null] at ha ⊢ rw [ha] simp only [ENNReal.coe_zero, zero_mul] · rintro ⟨g', g'meas, hg'⟩ refine ⟨fun x => ((f' x)⁻¹ : ℝ≥0∞) * g' x, hf'_m.coe_nnreal_ennreal.inv.smul g'meas, ?_⟩ rw [EventuallyEq, ae_withDensity_iff' hf.coe_nnreal_ennreal] filter_upwards [hg', hf'_ae] with a hfga hff'a h'a rw [hff'a] at hfga h'a rw [← hfga, ← mul_assoc, ENNReal.inv_mul_cancel h'a ENNReal.coe_ne_top, one_mul] theorem aemeasurable_withDensity_ennreal_iff {f : α → ℝ≥0} (hf : Measurable f) {g : α → ℝ≥0∞} : AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔ AEMeasurable (fun x => (f x : ℝ≥0∞) * g x) μ := aemeasurable_withDensity_ennreal_iff' <| hf.aemeasurable open MeasureTheory.SimpleFunc /-- This is Exercise 1.2.1 from [tao2010]. It allows you to express integration of a measurable function with respect to `(μ.withDensity f)` as an integral with respect to `μ`, called the base measure. `μ` is often the Lebesgue measure, and in this circumstance `f` is the probability density function, and `(μ.withDensity f)` represents any continuous random variable as a probability measure, such as the uniform distribution between 0 and 1, the Gaussian distribution, the exponential distribution, the Beta distribution, or the Cauchy distribution (see Section 2.4 of [wasserman2004]). Thus, this method shows how to one can calculate expectations, variances, and other moments as a function of the probability density function. -/ theorem lintegral_withDensity_eq_lintegral_mul (μ : Measure α) {f : α → ℝ≥0∞} (h_mf : Measurable f) : ∀ {g : α → ℝ≥0∞}, Measurable g → ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by apply Measurable.ennreal_induction · intro c s h_ms simp [*, mul_comm _ c, ← indicator_mul_right] · intro g h _ h_mea_g _ h_ind_g h_ind_h simp [mul_add, *, Measurable.mul] · intro g h_mea_g h_mono_g h_ind have : Monotone fun n a => f a * g n a := fun m n hmn x => mul_le_mul_left' (h_mono_g hmn x) _ simp [lintegral_iSup, ENNReal.mul_iSup, h_mf.mul (h_mea_g _), *] theorem setLIntegral_withDensity_eq_setLIntegral_mul (μ : Measure α) {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) {s : Set α} (hs : MeasurableSet s) : ∫⁻ x in s, g x ∂μ.withDensity f = ∫⁻ x in s, (f * g) x ∂μ := by rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul _ hf hg] /-- The Lebesgue integral of `g` with respect to the measure `μ.withDensity f` coincides with the integral of `f * g`. This version assumes that `g` is almost everywhere measurable. For a version without conditions on `g` but requiring that `f` is almost everywhere finite, see `lintegral_withDensity_eq_lintegral_mul_non_measurable` -/ theorem lintegral_withDensity_eq_lintegral_mul₀' {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g (μ.withDensity f)) : ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by let f' := hf.mk f have : μ.withDensity f = μ.withDensity f' := withDensity_congr_ae hf.ae_eq_mk rw [this] at hg ⊢ let g' := hg.mk g calc ∫⁻ a, g a ∂μ.withDensity f' = ∫⁻ a, g' a ∂μ.withDensity f' := lintegral_congr_ae hg.ae_eq_mk _ = ∫⁻ a, (f' * g') a ∂μ := (lintegral_withDensity_eq_lintegral_mul _ hf.measurable_mk hg.measurable_mk) _ = ∫⁻ a, (f' * g) a ∂μ := by apply lintegral_congr_ae apply ae_of_ae_restrict_of_ae_restrict_compl { x | f' x ≠ 0 } · have Z := hg.ae_eq_mk rw [EventuallyEq, ae_withDensity_iff_ae_restrict hf.measurable_mk] at Z filter_upwards [Z] intro x hx simp only [g', hx, Pi.mul_apply] · have M : MeasurableSet { x : α | f' x ≠ 0 }ᶜ := (hf.measurable_mk (measurableSet_singleton 0).compl).compl filter_upwards [ae_restrict_mem M] intro x hx simp only [Classical.not_not, mem_setOf_eq, mem_compl_iff] at hx simp only [hx, zero_mul, Pi.mul_apply] _ = ∫⁻ a : α, (f * g) a ∂μ := by apply lintegral_congr_ae filter_upwards [hf.ae_eq_mk] intro x hx simp only [f', hx, Pi.mul_apply] lemma setLIntegral_withDensity_eq_lintegral_mul₀' {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g (μ.withDensity f)) {s : Set α} (hs : MeasurableSet s) : ∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul₀' hf.restrict] rw [← restrict_withDensity hs] exact hg.restrict theorem lintegral_withDensity_eq_lintegral_mul₀ {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ) : ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := lintegral_withDensity_eq_lintegral_mul₀' hf (hg.mono' (withDensity_absolutelyContinuous μ f)) lemma setLIntegral_withDensity_eq_lintegral_mul₀ {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ) {s : Set α} (hs : MeasurableSet s) : ∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := setLIntegral_withDensity_eq_lintegral_mul₀' hf (hg.mono' (MeasureTheory.withDensity_absolutelyContinuous μ f)) hs theorem lintegral_withDensity_le_lintegral_mul (μ : Measure α) {f : α → ℝ≥0∞} (f_meas : Measurable f) (g : α → ℝ≥0∞) : (∫⁻ a, g a ∂μ.withDensity f) ≤ ∫⁻ a, (f * g) a ∂μ := by rw [← iSup_lintegral_measurable_le_eq_lintegral, ← iSup_lintegral_measurable_le_eq_lintegral] refine iSup₂_le fun i i_meas => iSup_le fun hi => ?_ have A : f * i ≤ f * g := fun x => mul_le_mul_left' (hi x) _ refine le_iSup₂_of_le (f * i) (f_meas.mul i_meas) ?_ exact le_iSup_of_le A (le_of_eq (lintegral_withDensity_eq_lintegral_mul _ f_meas i_meas)) theorem lintegral_withDensity_eq_lintegral_mul_non_measurable (μ : Measure α) {f : α → ℝ≥0∞} (f_meas : Measurable f) (hf : ∀ᵐ x ∂μ, f x < ∞) (g : α → ℝ≥0∞) : ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by refine le_antisymm (lintegral_withDensity_le_lintegral_mul μ f_meas g) ?_ rw [← iSup_lintegral_measurable_le_eq_lintegral, ← iSup_lintegral_measurable_le_eq_lintegral] refine iSup₂_le fun i i_meas => iSup_le fun hi => ?_ have A : (fun x => (f x)⁻¹ * i x) ≤ g := by intro x dsimp rw [mul_comm, ← div_eq_mul_inv] exact div_le_of_le_mul' (hi x) refine le_iSup_of_le (fun x => (f x)⁻¹ * i x) (le_iSup_of_le (f_meas.inv.mul i_meas) ?_) refine le_iSup_of_le A ?_ rw [lintegral_withDensity_eq_lintegral_mul _ f_meas (f_meas.inv.mul i_meas)] apply lintegral_mono_ae filter_upwards [hf] intro x h'x rcases eq_or_ne (f x) 0 with (hx | hx) · have := hi x simp only [hx, zero_mul, Pi.mul_apply, nonpos_iff_eq_zero] at this simp [this] · apply le_of_eq _ dsimp rw [← mul_assoc, ENNReal.mul_inv_cancel hx h'x.ne, one_mul] theorem setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable (μ : Measure α) {f : α → ℝ≥0∞} (f_meas : Measurable f) (g : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) (hf : ∀ᵐ x ∂μ.restrict s, f x < ∞) : ∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul_non_measurable _ f_meas hf] theorem lintegral_withDensity_eq_lintegral_mul_non_measurable₀ (μ : Measure α) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (h'f : ∀ᵐ x ∂μ, f x < ∞) (g : α → ℝ≥0∞) : ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by let f' := hf.mk f calc ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, g a ∂μ.withDensity f' := by rw [withDensity_congr_ae hf.ae_eq_mk] _ = ∫⁻ a, (f' * g) a ∂μ := by apply lintegral_withDensity_eq_lintegral_mul_non_measurable _ hf.measurable_mk filter_upwards [h'f, hf.ae_eq_mk] intro x hx h'x rwa [← h'x] _ = ∫⁻ a, (f * g) a ∂μ := by apply lintegral_congr_ae filter_upwards [hf.ae_eq_mk] intro x hx simp only [f', hx, Pi.mul_apply] theorem setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀ (μ : Measure α) {f : α → ℝ≥0∞} {s : Set α} (hf : AEMeasurable f (μ.restrict s)) (g : α → ℝ≥0∞) (hs : MeasurableSet s) (h'f : ∀ᵐ x ∂μ.restrict s, f x < ∞) : ∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul_non_measurable₀ _ hf h'f] theorem setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀' (μ : Measure α) [SFinite μ] {f : α → ℝ≥0∞} (s : Set α) (hf : AEMeasurable f (μ.restrict s)) (g : α → ℝ≥0∞) (h'f : ∀ᵐ x ∂μ.restrict s, f x < ∞) : ∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by rw [restrict_withDensity' s, lintegral_withDensity_eq_lintegral_mul_non_measurable₀ _ hf h'f] theorem withDensity_mul₀ {μ : Measure α} {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : μ.withDensity (f * g) = (μ.withDensity f).withDensity g := by ext1 s hs rw [withDensity_apply _ hs, withDensity_apply _ hs, restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul₀ hf.restrict hg.restrict] theorem withDensity_mul (μ : Measure α) {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) : μ.withDensity (f * g) = (μ.withDensity f).withDensity g := withDensity_mul₀ hf.aemeasurable hg.aemeasurable lemma withDensity_inv_same_le {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : (μ.withDensity f).withDensity f⁻¹ ≤ μ := by change (μ.withDensity f).withDensity (fun x ↦ (f x)⁻¹) ≤ μ rw [← withDensity_mul₀ hf hf.inv] suffices (f * fun x ↦ (f x)⁻¹) ≤ᵐ[μ] 1 by refine (withDensity_mono this).trans ?_ rw [withDensity_one] filter_upwards with x simp only [Pi.mul_apply, Pi.one_apply] by_cases hx_top : f x = ∞ · simp only [hx_top, ENNReal.inv_top, mul_zero, zero_le] by_cases hx_zero : f x = 0 · simp only [hx_zero, ENNReal.inv_zero, zero_mul, zero_le] rw [ENNReal.mul_inv_cancel hx_zero hx_top] lemma withDensity_inv_same₀ {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_ne_zero : ∀ᵐ x ∂μ, f x ≠ 0) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) : (μ.withDensity f).withDensity (fun x ↦ (f x)⁻¹) = μ := by rw [← withDensity_mul₀ hf hf.inv] suffices (f * fun x ↦ (f x)⁻¹) =ᵐ[μ] 1 by rw [withDensity_congr_ae this, withDensity_one] filter_upwards [hf_ne_zero, hf_ne_top] with x hf_ne_zero hf_ne_top simp only [Pi.mul_apply] rw [ENNReal.mul_inv_cancel hf_ne_zero hf_ne_top, Pi.one_apply] lemma withDensity_inv_same {μ : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hf_ne_zero : ∀ᵐ x ∂μ, f x ≠ 0) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) : (μ.withDensity f).withDensity (fun x ↦ (f x)⁻¹) = μ := withDensity_inv_same₀ hf.aemeasurable hf_ne_zero hf_ne_top /-- If `f` is almost everywhere positive, then `μ ≪ μ.withDensity f`. See also `withDensity_absolutelyContinuous` for the reverse direction, which always holds. -/ lemma withDensity_absolutelyContinuous' {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_ne_zero : ∀ᵐ x ∂μ, f x ≠ 0) : μ ≪ μ.withDensity f := by refine Measure.AbsolutelyContinuous.mk (fun s hs hμs ↦ ?_) rw [withDensity_apply _ hs, lintegral_eq_zero_iff' hf.restrict, ae_eq_restrict_iff_indicator_ae_eq hs, Set.indicator_zero', Filter.EventuallyEq, ae_iff] at hμs simp only [ae_iff, ne_eq, not_not] at hf_ne_zero simp only [Pi.zero_apply, Set.indicator_apply_eq_zero, not_forall, exists_prop] at hμs have hle : s ⊆ {a | a ∈ s ∧ ¬f a = 0} ∪ {a | f a = 0} := fun x hx ↦ or_iff_not_imp_right.mpr <| fun hnx ↦ ⟨hx, hnx⟩ exact measure_mono_null hle <| nonpos_iff_eq_zero.1 <| le_trans (measure_union_le _ _) <| hμs.symm ▸ zero_add _ |>.symm ▸ hf_ne_zero.le theorem withDensity_ae_eq {β : Type} {f g : α → β} {d : α → ℝ≥0∞} (hd : AEMeasurable d μ) (h_ae_nonneg : ∀ᵐ x ∂μ, d x ≠ 0) : f =ᵐ[μ.withDensity d] g ↔ f =ᵐ[μ] g := Iff.intro (fun h ↦ Measure.AbsolutelyContinuous.ae_eq (withDensity_absolutelyContinuous' hd h_ae_nonneg) h) (fun h ↦ Measure.AbsolutelyContinuous.ae_eq (withDensity_absolutelyContinuous μ d) h) /-- If `μ` is a σ-finite measure, then so is `μ.withDensity fun x ↦ f x` for any `ℝ≥0`-valued function `f`. -/ protected instance SigmaFinite.withDensity [SigmaFinite μ] (f : α → ℝ≥0) : SigmaFinite (μ.withDensity (fun x ↦ f x)) := by refine ⟨⟨⟨fun n ↦ spanningSets μ n ∩ f ⁻¹' (Iic n), fun _ ↦ trivial, fun n ↦ ?_, ?_⟩⟩⟩ · rw [withDensity_apply'] apply setLIntegral_lt_top_of_bddAbove · exact ((measure_mono inter_subset_left).trans_lt (measure_spanningSets_lt_top μ n)).ne · exact ⟨n, forall_mem_image.2 fun x hx ↦ hx.2⟩ · rw [iUnion_eq_univ_iff] refine fun x ↦ ⟨max (spanningSetsIndex μ x) ⌈f x⌉₊, ?_, ?_⟩ · exact mem_spanningSets_of_index_le _ _ (le_max_left ..) · simp [Nat.le_ceil] lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞} (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) : SigmaFinite (μ.withDensity f) := by have : f =ᵐ[μ] fun x ↦ (f x).toNNReal := hf_ne_top.mono fun x hx ↦ (ENNReal.coe_toNNReal hx).symm rw [withDensity_congr_ae this] infer_instance lemma SigmaFinite.withDensity_of_ne_top' [SigmaFinite μ] {f : α → ℝ≥0∞} (hf_ne_top : ∀ x, f x ≠ ∞) : SigmaFinite (μ.withDensity f) := SigmaFinite.withDensity_of_ne_top <| ae_of_all _ hf_ne_top instance SigmaFinite.withDensity_ofReal [SigmaFinite μ] (f : α → ℝ) : SigmaFinite (μ.withDensity (fun x ↦ ENNReal.ofReal (f x))) := .withDensity _ section SFinite variable (μ) in theorem exists_measurable_le_withDensity_eq [SFinite μ] (f : α → ℝ≥0∞) : ∃ g, Measurable g ∧ g ≤ f ∧ μ.withDensity g = μ.withDensity f := by obtain ⟨g, hgm, hgf, hint⟩ := exists_measurable_le_forall_setLIntegral_eq μ f use g, hgm, hgf ext s hs simp only [hint, withDensity_apply _ hs] /-- If `μ` is an `s`-finite measure, then so is `μ.withDensity f`. -/ instance Measure.withDensity.instSFinite [SFinite μ] {f : α → ℝ≥0∞} : SFinite (μ.withDensity f) := by wlog hfm : Measurable f generalizing f · rcases exists_measurable_le_withDensity_eq μ f with ⟨g, hgm, -, h⟩ exact h ▸ this hgm wlog hμ : IsFiniteMeasure μ generalizing μ · rw [← sum_sfiniteSeq μ, withDensity_sum] have (n : ℕ) : SFinite ((sfiniteSeq μ n).withDensity f) := this inferInstance infer_instance set s := {x | f x = ∞} have hs : MeasurableSet s := hfm (measurableSet_singleton _) have key := calc μ.withDensity f = μ.withDensity (sᶜ.indicator f) + μ.withDensity (s.indicator f) := by simp (disch := measurability) [withDensity_indicator, ← restrict_withDensity] _ = μ.withDensity (sᶜ.indicator f) + .sum fun _ : ℕ ↦ μ.withDensity (s.indicator 1) := by rw [← withDensity_tsum (by measurability)] congr 2 with x rw [ENNReal.tsum_apply] if hx : x ∈ s then simpa [hx, ENNReal.tsum_const_eq_top_of_ne_zero] else simp [hx] have : SigmaFinite (μ.withDensity (sᶜ.indicator f)) := by refine SigmaFinite.withDensity_of_ne_top <| ae_of_all _ fun x hx ↦ ?_ simp [indicator_apply, ite_eq_iff, s] at hx have : SigmaFinite (μ.withDensity (s.indicator 1)) := by rw [withDensity_indicator hs] exact SigmaFinite.withDensity 1 rw [key] infer_instance instance [SFinite μ] (c : ℝ≥0∞) : SFinite (c • μ) := by rw [← withDensity_const] infer_instance /-- If `μ ≪ ν` and `ν` is s-finite, then `μ` is s-finite. -/ theorem sFinite_of_absolutelyContinuous {ν : Measure α} [SFinite ν] (hμν : μ ≪ ν) : SFinite μ := by rw [← Measure.restrict_add_restrict_compl (μ := μ) measurableSet_sigmaFiniteSetWRT, restrict_compl_sigmaFiniteSetWRT hμν] infer_instance end SFinite section Prod variable {β : Type*} {mβ : MeasurableSpace β} {ν : Measure β} [SFinite ν] theorem prod_withDensity_left₀ {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : (μ.withDensity f).prod ν = (μ.prod ν).withDensity (fun z ↦ f z.1) := by refine ext_of_lintegral _ fun φ hφ ↦ ?_ rw [lintegral_prod _ hφ.aemeasurable, lintegral_withDensity_eq_lintegral_mul₀ hf, lintegral_withDensity_eq_lintegral_mul₀ _ hφ.aemeasurable, lintegral_prod] · refine lintegral_congr (fun x ↦ ?_) rw [Pi.mul_apply, ← lintegral_const_mul'' _ (by fun_prop)] simp all_goals fun_prop (disch := intro _ hs; simp [hs]) theorem prod_withDensity_left {f : α → ℝ≥0∞} (hf : Measurable f) : (μ.withDensity f).prod ν = (μ.prod ν).withDensity (fun z ↦ f z.1) := prod_withDensity_left₀ hf.aemeasurable
Mathlib/MeasureTheory/Measure/WithDensity.lean
651
658
theorem prod_withDensity_right₀ {g : β → ℝ≥0∞} (hg : AEMeasurable g ν) : μ.prod (ν.withDensity g) = (μ.prod ν).withDensity (fun z ↦ g z.2) := by
refine ext_of_lintegral _ fun φ hφ ↦ ?_ rw [lintegral_prod _ hφ.aemeasurable, lintegral_withDensity_eq_lintegral_mul₀ _ hφ.aemeasurable, lintegral_prod] · refine lintegral_congr (fun x ↦ ?_) rw [lintegral_withDensity_eq_lintegral_mul₀ hg (by fun_prop)] simp
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Yury Kudryashov -/ import Mathlib.Data.Set.Lattice.Image import Mathlib.Order.Interval.Set.LinearOrder /-! # Extra lemmas about intervals This file contains lemmas about intervals that cannot be included into `Order.Interval.Set.Basic` because this would create an `import` cycle. Namely, lemmas in this file can use definitions from `Data.Set.Lattice`, including `Disjoint`. We consider various intersections and unions of half infinite intervals. -/ universe u v w variable {ι : Sort u} {α : Type v} {β : Type w} open Set open OrderDual (toDual) namespace Set section Preorder variable [Preorder α] {a b c : α} @[simp] theorem Iic_disjoint_Ioi (h : a ≤ b) : Disjoint (Iic a) (Ioi b) := disjoint_left.mpr fun _ ha hb => (h.trans_lt hb).not_le ha @[simp] theorem Iio_disjoint_Ici (h : a ≤ b) : Disjoint (Iio a) (Ici b) := disjoint_left.mpr fun _ ha hb => (h.trans_lt' ha).not_le hb @[simp] theorem Iic_disjoint_Ioc (h : a ≤ b) : Disjoint (Iic a) (Ioc b c) := (Iic_disjoint_Ioi h).mono le_rfl Ioc_subset_Ioi_self @[simp] theorem Ioc_disjoint_Ioc_of_le {d : α} (h : b ≤ c) : Disjoint (Ioc a b) (Ioc c d) := (Iic_disjoint_Ioc h).mono Ioc_subset_Iic_self le_rfl @[deprecated Ioc_disjoint_Ioc_of_le (since := "2025-03-04")] theorem Ioc_disjoint_Ioc_same : Disjoint (Ioc a b) (Ioc b c) := (Iic_disjoint_Ioc le_rfl).mono Ioc_subset_Iic_self le_rfl @[simp] theorem Ico_disjoint_Ico_same : Disjoint (Ico a b) (Ico b c) := disjoint_left.mpr fun _ hab hbc => hab.2.not_le hbc.1 @[simp] theorem Ici_disjoint_Iic : Disjoint (Ici a) (Iic b) ↔ ¬a ≤ b := by rw [Set.disjoint_iff_inter_eq_empty, Ici_inter_Iic, Icc_eq_empty_iff] @[simp] theorem Iic_disjoint_Ici : Disjoint (Iic a) (Ici b) ↔ ¬b ≤ a := disjoint_comm.trans Ici_disjoint_Iic @[simp] theorem Ioc_disjoint_Ioi (h : b ≤ c) : Disjoint (Ioc a b) (Ioi c) := disjoint_left.mpr (fun _ hx hy ↦ (hx.2.trans h).not_lt hy) theorem Ioc_disjoint_Ioi_same : Disjoint (Ioc a b) (Ioi b) := Ioc_disjoint_Ioi le_rfl @[simp] theorem iUnion_Iic : ⋃ a : α, Iic a = univ := iUnion_eq_univ_iff.2 fun x => ⟨x, right_mem_Iic⟩ @[simp] theorem iUnion_Ici : ⋃ a : α, Ici a = univ := iUnion_eq_univ_iff.2 fun x => ⟨x, left_mem_Ici⟩ @[simp] theorem iUnion_Icc_right (a : α) : ⋃ b, Icc a b = Ici a := by simp only [← Ici_inter_Iic, ← inter_iUnion, iUnion_Iic, inter_univ] @[simp] theorem iUnion_Ioc_right (a : α) : ⋃ b, Ioc a b = Ioi a := by simp only [← Ioi_inter_Iic, ← inter_iUnion, iUnion_Iic, inter_univ] @[simp] theorem iUnion_Icc_left (b : α) : ⋃ a, Icc a b = Iic b := by simp only [← Ici_inter_Iic, ← iUnion_inter, iUnion_Ici, univ_inter] @[simp] theorem iUnion_Ico_left (b : α) : ⋃ a, Ico a b = Iio b := by simp only [← Ici_inter_Iio, ← iUnion_inter, iUnion_Ici, univ_inter] @[simp] theorem iUnion_Iio [NoMaxOrder α] : ⋃ a : α, Iio a = univ := iUnion_eq_univ_iff.2 exists_gt @[simp] theorem iUnion_Ioi [NoMinOrder α] : ⋃ a : α, Ioi a = univ := iUnion_eq_univ_iff.2 exists_lt @[simp] theorem iUnion_Ico_right [NoMaxOrder α] (a : α) : ⋃ b, Ico a b = Ici a := by simp only [← Ici_inter_Iio, ← inter_iUnion, iUnion_Iio, inter_univ] @[simp] theorem iUnion_Ioo_right [NoMaxOrder α] (a : α) : ⋃ b, Ioo a b = Ioi a := by simp only [← Ioi_inter_Iio, ← inter_iUnion, iUnion_Iio, inter_univ] @[simp] theorem iUnion_Ioc_left [NoMinOrder α] (b : α) : ⋃ a, Ioc a b = Iic b := by simp only [← Ioi_inter_Iic, ← iUnion_inter, iUnion_Ioi, univ_inter] @[simp] theorem iUnion_Ioo_left [NoMinOrder α] (b : α) : ⋃ a, Ioo a b = Iio b := by simp only [← Ioi_inter_Iio, ← iUnion_inter, iUnion_Ioi, univ_inter] end Preorder section LinearOrder variable [LinearOrder α] {a₁ a₂ b₁ b₂ : α} @[simp] theorem Ico_disjoint_Ico : Disjoint (Ico a₁ a₂) (Ico b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by simp_rw [Set.disjoint_iff_inter_eq_empty, Ico_inter_Ico, Ico_eq_empty_iff, not_lt] @[simp] theorem Ioc_disjoint_Ioc : Disjoint (Ioc a₁ a₂) (Ioc b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by have h : _ ↔ min (toDual a₁) (toDual b₁) ≤ max (toDual a₂) (toDual b₂) := Ico_disjoint_Ico simpa only [Ico_toDual] using h @[simp] theorem Ioo_disjoint_Ioo [DenselyOrdered α] : Disjoint (Set.Ioo a₁ a₂) (Set.Ioo b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by simp_rw [Set.disjoint_iff_inter_eq_empty, Ioo_inter_Ioo, Ioo_eq_empty_iff, not_lt] /-- If two half-open intervals are disjoint and the endpoint of one lies in the other, then it must be equal to the endpoint of the other. -/
Mathlib/Order/Interval/Set/Disjoint.lean
143
145
theorem eq_of_Ico_disjoint {x₁ x₂ y₁ y₂ : α} (h : Disjoint (Ico x₁ x₂) (Ico y₁ y₂)) (hx : x₁ < x₂) (h2 : x₂ ∈ Ico y₁ y₂) : y₁ = x₂ := by
rw [Ico_disjoint_Ico, min_eq_left (le_of_lt h2.2), le_max_iff] at h
/- Copyright (c) 2021 Vladimir Goryachev. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Vladimir Goryachev, Kyle Miller, Kim Morrison, Eric Rodriguez -/ import Mathlib.Algebra.Group.Nat.Range import Mathlib.Data.Set.Finite.Basic /-! # Counting on ℕ This file defines the `count` function, which gives, for any predicate on the natural numbers, "how many numbers under `k` satisfy this predicate?". We then prove several expected lemmas about `count`, relating it to the cardinality of other objects, and helping to evaluate it for specific `k`. -/ assert_not_imported Mathlib.Dynamics.FixedPoints.Basic assert_not_exists Ring open Finset namespace Nat variable (p : ℕ → Prop) section Count variable [DecidablePred p] /-- Count the number of naturals `k < n` satisfying `p k`. -/ def count (n : ℕ) : ℕ := (List.range n).countP p @[simp] theorem count_zero : count p 0 = 0 := by rw [count, List.range_zero, List.countP, List.countP.go] /-- A fintype instance for the set relevant to `Nat.count`. Locally an instance in locale `count` -/ def CountSet.fintype (n : ℕ) : Fintype { i // i < n ∧ p i } := by apply Fintype.ofFinset {x ∈ range n | p x} intro x rw [mem_filter, mem_range] rfl scoped[Count] attribute [instance] Nat.CountSet.fintype open Count theorem count_eq_card_filter_range (n : ℕ) : count p n = #{x ∈ range n | p x} := by rw [count, List.countP_eq_length_filter] rfl /-- `count p n` can be expressed as the cardinality of `{k // k < n ∧ p k}`. -/ theorem count_eq_card_fintype (n : ℕ) : count p n = Fintype.card { k : ℕ // k < n ∧ p k } := by rw [count_eq_card_filter_range, ← Fintype.card_ofFinset, ← CountSet.fintype] rfl theorem count_le {n : ℕ} : count p n ≤ n := by rw [count_eq_card_filter_range] exact (card_filter_le _ _).trans_eq (card_range _) theorem count_succ (n : ℕ) : count p (n + 1) = count p n + if p n then 1 else 0 := by split_ifs with h <;> simp [count, List.range_succ, h] @[mono] theorem count_monotone : Monotone (count p) := monotone_nat_of_le_succ fun n ↦ by by_cases h : p n <;> simp [count_succ, h] theorem count_add (a b : ℕ) : count p (a + b) = count p a + count (fun k ↦ p (a + k)) b := by have : Disjoint {x ∈ range a | p x} {x ∈ (range b).map <| addLeftEmbedding a | p x} := by apply disjoint_filter_filter rw [Finset.disjoint_left] simp_rw [mem_map, mem_range, addLeftEmbedding_apply] rintro x hx ⟨c, _, rfl⟩ exact (Nat.le_add_right _ _).not_lt hx simp_rw [count_eq_card_filter_range, range_add, filter_union, card_union_of_disjoint this, filter_map, addLeftEmbedding, card_map] rfl theorem count_add' (a b : ℕ) : count p (a + b) = count (fun k ↦ p (k + b)) a + count p b := by rw [add_comm, count_add, add_comm] simp_rw [add_comm b] theorem count_one : count p 1 = if p 0 then 1 else 0 := by simp [count_succ] theorem count_succ' (n : ℕ) : count p (n + 1) = count (fun k ↦ p (k + 1)) n + if p 0 then 1 else 0 := by rw [count_add', count_one] variable {p} @[simp] theorem count_lt_count_succ_iff {n : ℕ} : count p n < count p (n + 1) ↔ p n := by by_cases h : p n <;> simp [count_succ, h] theorem count_succ_eq_succ_count_iff {n : ℕ} : count p (n + 1) = count p n + 1 ↔ p n := by by_cases h : p n <;> simp [h, count_succ] theorem count_succ_eq_count_iff {n : ℕ} : count p (n + 1) = count p n ↔ ¬p n := by by_cases h : p n <;> simp [h, count_succ] alias ⟨_, count_succ_eq_succ_count⟩ := count_succ_eq_succ_count_iff alias ⟨_, count_succ_eq_count⟩ := count_succ_eq_count_iff theorem lt_of_count_lt_count {a b : ℕ} (h : count p a < count p b) : a < b := (count_monotone p).reflect_lt h theorem count_strict_mono {m n : ℕ} (hm : p m) (hmn : m < n) : count p m < count p n := (count_lt_count_succ_iff.2 hm).trans_le <| count_monotone _ (Nat.succ_le_iff.2 hmn) theorem count_injective {m n : ℕ} (hm : p m) (hn : p n) (heq : count p m = count p n) : m = n := by by_contra! h : m ≠ n wlog hmn : m < n · exact this hn hm heq.symm h.symm (h.lt_or_lt.resolve_left hmn) · simpa [heq] using count_strict_mono hm hmn
Mathlib/Data/Nat/Count.lean
120
122
theorem count_le_card (hp : (setOf p).Finite) (n : ℕ) : count p n ≤ #hp.toFinset := by
rw [count_eq_card_filter_range] exact Finset.card_mono fun x hx ↦ hp.mem_toFinset.2 (mem_filter.1 hx).2
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FDeriv.Linear import Mathlib.Analysis.Calculus.FDeriv.Comp /-! # Additive operations on derivatives For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of * sum of finitely many functions * multiplication of a function by a scalar constant * negative of a function * subtraction of two functions -/ open Filter Asymptotics ContinuousLinearMap noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f g : E → F} variable {f' g' : E →L[𝕜] F} variable {x : E} variable {s : Set E} variable {L : Filter E} section ConstSMul variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] /-! ### Derivative of a function multiplied by a constant -/ @[fun_prop] theorem HasStrictFDerivAt.const_smul (h : HasStrictFDerivAt f f' x) (c : R) : HasStrictFDerivAt (fun x => c • f x) (c • f') x := (c • (1 : F →L[𝕜] F)).hasStrictFDerivAt.comp x h theorem HasFDerivAtFilter.const_smul (h : HasFDerivAtFilter f f' x L) (c : R) : HasFDerivAtFilter (fun x => c • f x) (c • f') x L := (c • (1 : F →L[𝕜] F)).hasFDerivAtFilter.comp x h tendsto_map @[fun_prop] nonrec theorem HasFDerivWithinAt.const_smul (h : HasFDerivWithinAt f f' s x) (c : R) : HasFDerivWithinAt (fun x => c • f x) (c • f') s x := h.const_smul c @[fun_prop] nonrec theorem HasFDerivAt.const_smul (h : HasFDerivAt f f' x) (c : R) : HasFDerivAt (fun x => c • f x) (c • f') x := h.const_smul c @[fun_prop] theorem DifferentiableWithinAt.const_smul (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : DifferentiableWithinAt 𝕜 (fun y => c • f y) s x := (h.hasFDerivWithinAt.const_smul c).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.const_smul (h : DifferentiableAt 𝕜 f x) (c : R) : DifferentiableAt 𝕜 (fun y => c • f y) x := (h.hasFDerivAt.const_smul c).differentiableAt @[fun_prop] theorem DifferentiableOn.const_smul (h : DifferentiableOn 𝕜 f s) (c : R) : DifferentiableOn 𝕜 (fun y => c • f y) s := fun x hx => (h x hx).const_smul c @[fun_prop] theorem Differentiable.const_smul (h : Differentiable 𝕜 f) (c : R) : Differentiable 𝕜 fun y => c • f y := fun x => (h x).const_smul c theorem fderivWithin_const_smul (hxs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : fderivWithin 𝕜 (fun y => c • f y) s x = c • fderivWithin 𝕜 f s x := (h.hasFDerivWithinAt.const_smul c).fderivWithin hxs /-- Version of `fderivWithin_const_smul` written with `c • f` instead of `fun y ↦ c • f y`. -/ theorem fderivWithin_const_smul' (hxs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : fderivWithin 𝕜 (c • f) s x = c • fderivWithin 𝕜 f s x := fderivWithin_const_smul hxs h c theorem fderiv_const_smul (h : DifferentiableAt 𝕜 f x) (c : R) : fderiv 𝕜 (fun y => c • f y) x = c • fderiv 𝕜 f x := (h.hasFDerivAt.const_smul c).fderiv /-- Version of `fderiv_const_smul` written with `c • f` instead of `fun y ↦ c • f y`. -/ theorem fderiv_const_smul' (h : DifferentiableAt 𝕜 f x) (c : R) : fderiv 𝕜 (c • f) x = c • fderiv 𝕜 f x := (h.hasFDerivAt.const_smul c).fderiv end ConstSMul section Add /-! ### Derivative of the sum of two functions -/ @[fun_prop] nonrec theorem HasStrictFDerivAt.add (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun y => f y + g y) (f' + g') x := .of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun y => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel theorem HasFDerivAtFilter.add (hf : HasFDerivAtFilter f f' x L) (hg : HasFDerivAtFilter g g' x L) : HasFDerivAtFilter (fun y => f y + g y) (f' + g') x L := .of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun _ => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel @[fun_prop] nonrec theorem HasFDerivWithinAt.add (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun y => f y + g y) (f' + g') s x := hf.add hg @[fun_prop] nonrec theorem HasFDerivAt.add (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun x => f x + g x) (f' + g') x := hf.add hg @[fun_prop] theorem DifferentiableWithinAt.add (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : DifferentiableWithinAt 𝕜 (fun y => f y + g y) s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y + g y) x := (hf.hasFDerivAt.add hg.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.add (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y + g y) s := fun x hx => (hf x hx).add (hg x hx) @[simp, fun_prop] theorem Differentiable.add (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) : Differentiable 𝕜 fun y => f y + g y := fun x => (hf x).add (hg x) theorem fderivWithin_add (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (fun y => f y + g y) s x = fderivWithin 𝕜 f s x + fderivWithin 𝕜 g s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).fderivWithin hxs /-- Version of `fderivWithin_add` where the function is written as `f + g` instead of `fun y ↦ f y + g y`. -/ theorem fderivWithin_add' (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (f + g) s x = fderivWithin 𝕜 f s x + fderivWithin 𝕜 g s x := fderivWithin_add hxs hf hg theorem fderiv_add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (fun y => f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 g x := (hf.hasFDerivAt.add hg.hasFDerivAt).fderiv /-- Version of `fderiv_add` where the function is written as `f + g` instead of `fun y ↦ f y + g y`. -/ theorem fderiv_add' (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (f + g) x = fderiv 𝕜 f x + fderiv 𝕜 g x := fderiv_add hf hg @[simp] theorem hasFDerivAtFilter_add_const_iff (c : F) : HasFDerivAtFilter (f · + c) f' x L ↔ HasFDerivAtFilter f f' x L := by simp [hasFDerivAtFilter_iff_isLittleOTVS] alias ⟨_, HasFDerivAtFilter.add_const⟩ := hasFDerivAtFilter_add_const_iff @[simp] theorem hasStrictFDerivAt_add_const_iff (c : F) : HasStrictFDerivAt (f · + c) f' x ↔ HasStrictFDerivAt f f' x := by simp [hasStrictFDerivAt_iff_isLittleO] @[fun_prop] alias ⟨_, HasStrictFDerivAt.add_const⟩ := hasStrictFDerivAt_add_const_iff @[simp] theorem hasFDerivWithinAt_add_const_iff (c : F) : HasFDerivWithinAt (f · + c) f' s x ↔ HasFDerivWithinAt f f' s x := hasFDerivAtFilter_add_const_iff c @[fun_prop] alias ⟨_, HasFDerivWithinAt.add_const⟩ := hasFDerivWithinAt_add_const_iff @[simp] theorem hasFDerivAt_add_const_iff (c : F) : HasFDerivAt (f · + c) f' x ↔ HasFDerivAt f f' x := hasFDerivAtFilter_add_const_iff c @[fun_prop] alias ⟨_, HasFDerivAt.add_const⟩ := hasFDerivAt_add_const_iff @[simp] theorem differentiableWithinAt_add_const_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => f y + c) s x ↔ DifferentiableWithinAt 𝕜 f s x := exists_congr fun _ ↦ hasFDerivWithinAt_add_const_iff c @[fun_prop] alias ⟨_, DifferentiableWithinAt.add_const⟩ := differentiableWithinAt_add_const_iff @[simp] theorem differentiableAt_add_const_iff (c : F) : DifferentiableAt 𝕜 (fun y => f y + c) x ↔ DifferentiableAt 𝕜 f x := exists_congr fun _ ↦ hasFDerivAt_add_const_iff c @[fun_prop] alias ⟨_, DifferentiableAt.add_const⟩ := differentiableAt_add_const_iff @[simp] theorem differentiableOn_add_const_iff (c : F) : DifferentiableOn 𝕜 (fun y => f y + c) s ↔ DifferentiableOn 𝕜 f s := forall₂_congr fun _ _ ↦ differentiableWithinAt_add_const_iff c @[fun_prop] alias ⟨_, DifferentiableOn.add_const⟩ := differentiableOn_add_const_iff @[simp] theorem differentiable_add_const_iff (c : F) : (Differentiable 𝕜 fun y => f y + c) ↔ Differentiable 𝕜 f := forall_congr' fun _ ↦ differentiableAt_add_const_iff c @[fun_prop] alias ⟨_, Differentiable.add_const⟩ := differentiable_add_const_iff @[simp] theorem fderivWithin_add_const (c : F) : fderivWithin 𝕜 (fun y => f y + c) s x = fderivWithin 𝕜 f s x := by classical simp [fderivWithin] @[simp] theorem fderiv_add_const (c : F) : fderiv 𝕜 (fun y => f y + c) x = fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_add_const] @[simp] theorem hasFDerivAtFilter_const_add_iff (c : F) : HasFDerivAtFilter (c + f ·) f' x L ↔ HasFDerivAtFilter f f' x L := by simpa only [add_comm] using hasFDerivAtFilter_add_const_iff c alias ⟨_, HasFDerivAtFilter.const_add⟩ := hasFDerivAtFilter_const_add_iff @[simp] theorem hasStrictFDerivAt_const_add_iff (c : F) : HasStrictFDerivAt (c + f ·) f' x ↔ HasStrictFDerivAt f f' x := by simpa only [add_comm] using hasStrictFDerivAt_add_const_iff c @[fun_prop] alias ⟨_, HasStrictFDerivAt.const_add⟩ := hasStrictFDerivAt_const_add_iff @[simp] theorem hasFDerivWithinAt_const_add_iff (c : F) : HasFDerivWithinAt (c + f ·) f' s x ↔ HasFDerivWithinAt f f' s x := hasFDerivAtFilter_const_add_iff c @[fun_prop] alias ⟨_, HasFDerivWithinAt.const_add⟩ := hasFDerivWithinAt_const_add_iff @[simp] theorem hasFDerivAt_const_add_iff (c : F) : HasFDerivAt (c + f ·) f' x ↔ HasFDerivAt f f' x := hasFDerivAtFilter_const_add_iff c @[fun_prop] alias ⟨_, HasFDerivAt.const_add⟩ := hasFDerivAt_const_add_iff @[simp] theorem differentiableWithinAt_const_add_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => c + f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := exists_congr fun _ ↦ hasFDerivWithinAt_const_add_iff c @[fun_prop] alias ⟨_, DifferentiableWithinAt.const_add⟩ := differentiableWithinAt_const_add_iff @[simp] theorem differentiableAt_const_add_iff (c : F) : DifferentiableAt 𝕜 (fun y => c + f y) x ↔ DifferentiableAt 𝕜 f x := exists_congr fun _ ↦ hasFDerivAt_const_add_iff c @[fun_prop] alias ⟨_, DifferentiableAt.const_add⟩ := differentiableAt_const_add_iff @[simp] theorem differentiableOn_const_add_iff (c : F) : DifferentiableOn 𝕜 (fun y => c + f y) s ↔ DifferentiableOn 𝕜 f s := forall₂_congr fun _ _ ↦ differentiableWithinAt_const_add_iff c @[fun_prop] alias ⟨_, DifferentiableOn.const_add⟩ := differentiableOn_const_add_iff @[simp] theorem differentiable_const_add_iff (c : F) : (Differentiable 𝕜 fun y => c + f y) ↔ Differentiable 𝕜 f := forall_congr' fun _ ↦ differentiableAt_const_add_iff c @[fun_prop] alias ⟨_, Differentiable.const_add⟩ := differentiable_const_add_iff @[simp] theorem fderivWithin_const_add (c : F) : fderivWithin 𝕜 (fun y => c + f y) s x = fderivWithin 𝕜 f s x := by simpa only [add_comm] using fderivWithin_add_const c @[simp] theorem fderiv_const_add (c : F) : fderiv 𝕜 (fun y => c + f y) x = fderiv 𝕜 f x := by simp only [add_comm c, fderiv_add_const] end Add section Sum /-! ### Derivative of a finite sum of functions -/ variable {ι : Type*} {u : Finset ι} {A : ι → E → F} {A' : ι → E →L[𝕜] F} @[fun_prop] theorem HasStrictFDerivAt.sum (h : ∀ i ∈ u, HasStrictFDerivAt (A i) (A' i) x) : HasStrictFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := by simp only [hasStrictFDerivAt_iff_isLittleO] at * convert IsLittleO.sum h simp [Finset.sum_sub_distrib, ContinuousLinearMap.sum_apply] theorem HasFDerivAtFilter.sum (h : ∀ i ∈ u, HasFDerivAtFilter (A i) (A' i) x L) : HasFDerivAtFilter (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x L := by simp only [hasFDerivAtFilter_iff_isLittleO] at * convert IsLittleO.sum h simp [ContinuousLinearMap.sum_apply] @[fun_prop] theorem HasFDerivWithinAt.sum (h : ∀ i ∈ u, HasFDerivWithinAt (A i) (A' i) s x) : HasFDerivWithinAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) s x := HasFDerivAtFilter.sum h @[fun_prop] theorem HasFDerivAt.sum (h : ∀ i ∈ u, HasFDerivAt (A i) (A' i) x) : HasFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := HasFDerivAtFilter.sum h @[fun_prop] theorem DifferentiableWithinAt.sum (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : DifferentiableWithinAt 𝕜 (fun y => ∑ i ∈ u, A i y) s x := HasFDerivWithinAt.differentiableWithinAt <| HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt @[simp, fun_prop] theorem DifferentiableAt.sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : DifferentiableAt 𝕜 (fun y => ∑ i ∈ u, A i y) x := HasFDerivAt.differentiableAt <| HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt @[fun_prop] theorem DifferentiableOn.sum (h : ∀ i ∈ u, DifferentiableOn 𝕜 (A i) s) : DifferentiableOn 𝕜 (fun y => ∑ i ∈ u, A i y) s := fun x hx => DifferentiableWithinAt.sum fun i hi => h i hi x hx @[simp, fun_prop] theorem Differentiable.sum (h : ∀ i ∈ u, Differentiable 𝕜 (A i)) : Differentiable 𝕜 fun y => ∑ i ∈ u, A i y := fun x => DifferentiableAt.sum fun i hi => h i hi x theorem fderivWithin_sum (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : fderivWithin 𝕜 (fun y => ∑ i ∈ u, A i y) s x = ∑ i ∈ u, fderivWithin 𝕜 (A i) s x := (HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt).fderivWithin hxs theorem fderiv_sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : fderiv 𝕜 (fun y => ∑ i ∈ u, A i y) x = ∑ i ∈ u, fderiv 𝕜 (A i) x := (HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt).fderiv end Sum section Neg /-! ### Derivative of the negative of a function -/ @[fun_prop] theorem HasStrictFDerivAt.neg (h : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => -f x) (-f') x := (-1 : F →L[𝕜] F).hasStrictFDerivAt.comp x h theorem HasFDerivAtFilter.neg (h : HasFDerivAtFilter f f' x L) : HasFDerivAtFilter (fun x => -f x) (-f') x L := (-1 : F →L[𝕜] F).hasFDerivAtFilter.comp x h tendsto_map @[fun_prop] nonrec theorem HasFDerivWithinAt.neg (h : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => -f x) (-f') s x := h.neg @[fun_prop] nonrec theorem HasFDerivAt.neg (h : HasFDerivAt f f' x) : HasFDerivAt (fun x => -f x) (-f') x := h.neg @[fun_prop] theorem DifferentiableWithinAt.neg (h : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (fun y => -f y) s x := h.hasFDerivWithinAt.neg.differentiableWithinAt @[simp] theorem differentiableWithinAt_neg_iff : DifferentiableWithinAt 𝕜 (fun y => -f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem DifferentiableAt.neg (h : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => -f y) x := h.hasFDerivAt.neg.differentiableAt @[simp] theorem differentiableAt_neg_iff : DifferentiableAt 𝕜 (fun y => -f y) x ↔ DifferentiableAt 𝕜 f x := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem DifferentiableOn.neg (h : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => -f y) s := fun x hx => (h x hx).neg @[simp] theorem differentiableOn_neg_iff : DifferentiableOn 𝕜 (fun y => -f y) s ↔ DifferentiableOn 𝕜 f s := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem Differentiable.neg (h : Differentiable 𝕜 f) : Differentiable 𝕜 fun y => -f y := fun x => (h x).neg @[simp] theorem differentiable_neg_iff : (Differentiable 𝕜 fun y => -f y) ↔ Differentiable 𝕜 f := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ theorem fderivWithin_neg (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun y => -f y) s x = -fderivWithin 𝕜 f s x := by classical by_cases h : DifferentiableWithinAt 𝕜 f s x · exact h.hasFDerivWithinAt.neg.fderivWithin hxs · rw [fderivWithin_zero_of_not_differentiableWithinAt h, fderivWithin_zero_of_not_differentiableWithinAt, neg_zero] simpa /-- Version of `fderivWithin_neg` where the function is written `-f` instead of `fun y ↦ - f y`. -/ theorem fderivWithin_neg' (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (-f) s x = -fderivWithin 𝕜 f s x := fderivWithin_neg hxs @[simp] theorem fderiv_neg : fderiv 𝕜 (fun y => -f y) x = -fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_neg uniqueDiffWithinAt_univ] /-- Version of `fderiv_neg` where the function is written `-f` instead of `fun y ↦ - f y`. -/ theorem fderiv_neg' : fderiv 𝕜 (-f) x = -fderiv 𝕜 f x := fderiv_neg end Neg section Sub /-! ### Derivative of the difference of two functions -/ @[fun_prop]
Mathlib/Analysis/Calculus/FDeriv/Add.lean
464
465
theorem HasStrictFDerivAt.sub (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun x => f x - g x) (f' - g') x := by
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Julian Kuelshammer -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Algebra.Group.Pointwise.Set.Finite import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Order.Group.Action import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Data.Int.ModEq import Mathlib.Dynamics.PeriodicPts.Lemmas import Mathlib.GroupTheory.Index import Mathlib.NumberTheory.Divisors import Mathlib.Order.Interval.Set.Infinite /-! # Order of an element This file defines the order of an element of a finite group. For a finite group `G` the order of `x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`. ## Main definitions * `IsOfFinOrder` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite order. * `IsOfFinAddOrder` is the additive analogue of `IsOfFinOrder`. * `orderOf x` defines the order of an element `x` of a monoid `G`, by convention its value is `0` if `x` has infinite order. * `addOrderOf` is the additive analogue of `orderOf`. ## Tags order of an element -/ assert_not_exists Field open Function Fintype Nat Pointwise Subgroup Submonoid open scoped Finset variable {G H A α β : Type*} section Monoid variable [Monoid G] {a b x y : G} {n m : ℕ} section IsOfFinOrder -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed @[to_additive] theorem isPeriodicPt_mul_iff_pow_eq_one (x : G) : IsPeriodicPt (x * ·) n 1 ↔ x ^ n = 1 := by rw [IsPeriodicPt, IsFixedPt, mul_left_iterate]; beta_reduce; rw [mul_one] /-- `IsOfFinOrder` is a predicate on an element `x` of a monoid to be of finite order, i.e. there exists `n ≥ 1` such that `x ^ n = 1`. -/ @[to_additive "`IsOfFinAddOrder` is a predicate on an element `a` of an additive monoid to be of finite order, i.e. there exists `n ≥ 1` such that `n • a = 0`."] def IsOfFinOrder (x : G) : Prop := (1 : G) ∈ periodicPts (x * ·) theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) ↔ IsOfFinOrder x := Iff.rfl theorem isOfFinOrder_ofAdd_iff {α : Type*} [AddMonoid α] {x : α} : IsOfFinOrder (Multiplicative.ofAdd x) ↔ IsOfFinAddOrder x := Iff.rfl @[to_additive] theorem isOfFinOrder_iff_pow_eq_one : IsOfFinOrder x ↔ ∃ n, 0 < n ∧ x ^ n = 1 := by simp [IsOfFinOrder, mem_periodicPts, isPeriodicPt_mul_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.exists_pow_eq_one, _⟩ := isOfFinOrder_iff_pow_eq_one @[to_additive] lemma isOfFinOrder_iff_zpow_eq_one {G} [DivisionMonoid G] {x : G} : IsOfFinOrder x ↔ ∃ (n : ℤ), n ≠ 0 ∧ x ^ n = 1 := by rw [isOfFinOrder_iff_pow_eq_one] refine ⟨fun ⟨n, hn, hn'⟩ ↦ ⟨n, Int.natCast_ne_zero_iff_pos.mpr hn, zpow_natCast x n ▸ hn'⟩, fun ⟨n, hn, hn'⟩ ↦ ⟨n.natAbs, Int.natAbs_pos.mpr hn, ?_⟩⟩ rcases (Int.natAbs_eq_iff (a := n)).mp rfl with h | h · rwa [h, zpow_natCast] at hn' · rwa [h, zpow_neg, inv_eq_one, zpow_natCast] at hn' /-- See also `injective_pow_iff_not_isOfFinOrder`. -/ @[to_additive "See also `injective_nsmul_iff_not_isOfFinAddOrder`."] theorem not_isOfFinOrder_of_injective_pow {x : G} (h : Injective fun n : ℕ => x ^ n) : ¬IsOfFinOrder x := by simp_rw [isOfFinOrder_iff_pow_eq_one, not_exists, not_and] intro n hn_pos hnx rw [← pow_zero x] at hnx rw [h hnx] at hn_pos exact irrefl 0 hn_pos /-- 1 is of finite order in any monoid. -/ @[to_additive (attr := simp) "0 is of finite order in any additive monoid."] theorem IsOfFinOrder.one : IsOfFinOrder (1 : G) := isOfFinOrder_iff_pow_eq_one.mpr ⟨1, Nat.one_pos, one_pow 1⟩ @[to_additive] lemma IsOfFinOrder.pow {n : ℕ} : IsOfFinOrder a → IsOfFinOrder (a ^ n) := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨m, hm, ha⟩ exact ⟨m, hm, by simp [pow_right_comm _ n, ha]⟩ @[to_additive] lemma IsOfFinOrder.of_pow {n : ℕ} (h : IsOfFinOrder (a ^ n)) (hn : n ≠ 0) : IsOfFinOrder a := by rw [isOfFinOrder_iff_pow_eq_one] at * rcases h with ⟨m, hm, ha⟩ exact ⟨n * m, mul_pos hn.bot_lt hm, by rwa [pow_mul]⟩ @[to_additive (attr := simp)] lemma isOfFinOrder_pow {n : ℕ} : IsOfFinOrder (a ^ n) ↔ IsOfFinOrder a ∨ n = 0 := by rcases Decidable.eq_or_ne n 0 with rfl | hn · simp · exact ⟨fun h ↦ .inl <| h.of_pow hn, fun h ↦ (h.resolve_right hn).pow⟩ /-- Elements of finite order are of finite order in submonoids. -/ @[to_additive "Elements of finite order are of finite order in submonoids."] theorem Submonoid.isOfFinOrder_coe {H : Submonoid G} {x : H} : IsOfFinOrder (x : G) ↔ IsOfFinOrder x := by rw [isOfFinOrder_iff_pow_eq_one, isOfFinOrder_iff_pow_eq_one] norm_cast theorem IsConj.isOfFinOrder (h : IsConj x y) : IsOfFinOrder x → IsOfFinOrder y := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨n, n_gt_0, eq'⟩ exact ⟨n, n_gt_0, by rw [← isConj_one_right, ← eq']; exact h.pow n⟩ /-- The image of an element of finite order has finite order. -/ @[to_additive "The image of an element of finite additive order has finite additive order."] theorem MonoidHom.isOfFinOrder [Monoid H] (f : G →* H) {x : G} (h : IsOfFinOrder x) : IsOfFinOrder <| f x := isOfFinOrder_iff_pow_eq_one.mpr <| by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact ⟨n, npos, by rw [← f.map_pow, hn, f.map_one]⟩ /-- If a direct product has finite order then so does each component. -/ @[to_additive "If a direct product has finite additive order then so does each component."] theorem IsOfFinOrder.apply {η : Type*} {Gs : η → Type*} [∀ i, Monoid (Gs i)] {x : ∀ i, Gs i} (h : IsOfFinOrder x) : ∀ i, IsOfFinOrder (x i) := by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact fun _ => isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, (congr_fun hn.symm _).symm⟩ /-- The submonoid generated by an element is a group if that element has finite order. -/ @[to_additive "The additive submonoid generated by an element is an additive group if that element has finite order."] noncomputable abbrev IsOfFinOrder.groupPowers (hx : IsOfFinOrder x) : Group (Submonoid.powers x) := by obtain ⟨hpos, hx⟩ := hx.exists_pow_eq_one.choose_spec exact Submonoid.groupPowers hpos hx end IsOfFinOrder /-- `orderOf x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists. Otherwise, i.e. if `x` is of infinite order, then `orderOf x` is `0` by convention. -/ @[to_additive "`addOrderOf a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it exists. Otherwise, i.e. if `a` is of infinite order, then `addOrderOf a` is `0` by convention."] noncomputable def orderOf (x : G) : ℕ := minimalPeriod (x * ·) 1 @[simp] theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x := rfl @[simp] lemma orderOf_ofAdd_eq_addOrderOf {α : Type*} [AddMonoid α] (a : α) : orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl @[to_additive] protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x := minimalPeriod_pos_of_mem_periodicPts h @[to_additive addOrderOf_nsmul_eq_zero] theorem pow_orderOf_eq_one (x : G) : x ^ orderOf x = 1 := by convert Eq.trans _ (isPeriodicPt_minimalPeriod (x * ·) 1) -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed in the middle of the rewrite rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one] @[to_additive] theorem orderOf_eq_zero (h : ¬IsOfFinOrder x) : orderOf x = 0 := by rwa [orderOf, minimalPeriod, dif_neg] @[to_additive] theorem orderOf_eq_zero_iff : orderOf x = 0 ↔ ¬IsOfFinOrder x := ⟨fun h H ↦ H.orderOf_pos.ne' h, orderOf_eq_zero⟩ @[to_additive] theorem orderOf_eq_zero_iff' : orderOf x = 0 ↔ ∀ n : ℕ, 0 < n → x ^ n ≠ 1 := by simp_rw [orderOf_eq_zero_iff, isOfFinOrder_iff_pow_eq_one, not_exists, not_and] @[to_additive] theorem orderOf_eq_iff {n} (h : 0 < n) : orderOf x = n ↔ x ^ n = 1 ∧ ∀ m, m < n → 0 < m → x ^ m ≠ 1 := by simp_rw [Ne, ← isPeriodicPt_mul_iff_pow_eq_one, orderOf, minimalPeriod] split_ifs with h1 · classical rw [find_eq_iff] simp only [h, true_and] push_neg rfl · rw [iff_false_left h.ne] rintro ⟨h', -⟩ exact h1 ⟨n, h, h'⟩ /-- A group element has finite order iff its order is positive. -/ @[to_additive "A group element has finite additive order iff its order is positive."] theorem orderOf_pos_iff : 0 < orderOf x ↔ IsOfFinOrder x := by rw [iff_not_comm.mp orderOf_eq_zero_iff, pos_iff_ne_zero] @[to_additive] theorem IsOfFinOrder.mono [Monoid β] {y : β} (hx : IsOfFinOrder x) (h : orderOf y ∣ orderOf x) : IsOfFinOrder y := by rw [← orderOf_pos_iff] at hx ⊢; exact Nat.pos_of_dvd_of_pos h hx @[to_additive] theorem pow_ne_one_of_lt_orderOf (n0 : n ≠ 0) (h : n < orderOf x) : x ^ n ≠ 1 := fun j => not_isPeriodicPt_of_pos_of_lt_minimalPeriod n0 h ((isPeriodicPt_mul_iff_pow_eq_one x).mpr j) @[to_additive] theorem orderOf_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : orderOf x ≤ n := IsPeriodicPt.minimalPeriod_le hn (by rwa [isPeriodicPt_mul_iff_pow_eq_one]) @[to_additive (attr := simp)] theorem orderOf_one : orderOf (1 : G) = 1 := by rw [orderOf, ← minimalPeriod_id (x := (1 : G)), ← one_mul_eq_id] @[to_additive (attr := simp) AddMonoid.addOrderOf_eq_one_iff] theorem orderOf_eq_one_iff : orderOf x = 1 ↔ x = 1 := by rw [orderOf, minimalPeriod_eq_one_iff_isFixedPt, IsFixedPt, mul_one] @[to_additive (attr := simp) mod_addOrderOf_nsmul] lemma pow_mod_orderOf (x : G) (n : ℕ) : x ^ (n % orderOf x) = x ^ n := calc x ^ (n % orderOf x) = x ^ (n % orderOf x + orderOf x * (n / orderOf x)) := by simp [pow_add, pow_mul, pow_orderOf_eq_one] _ = x ^ n := by rw [Nat.mod_add_div] @[to_additive] theorem orderOf_dvd_of_pow_eq_one (h : x ^ n = 1) : orderOf x ∣ n := IsPeriodicPt.minimalPeriod_dvd ((isPeriodicPt_mul_iff_pow_eq_one _).mpr h) @[to_additive] theorem orderOf_dvd_iff_pow_eq_one {n : ℕ} : orderOf x ∣ n ↔ x ^ n = 1 := ⟨fun h => by rw [← pow_mod_orderOf, Nat.mod_eq_zero_of_dvd h, _root_.pow_zero], orderOf_dvd_of_pow_eq_one⟩ @[to_additive addOrderOf_smul_dvd] theorem orderOf_pow_dvd (n : ℕ) : orderOf (x ^ n) ∣ orderOf x := by rw [orderOf_dvd_iff_pow_eq_one, pow_right_comm, pow_orderOf_eq_one, one_pow] @[to_additive] lemma pow_injOn_Iio_orderOf : (Set.Iio <| orderOf x).InjOn (x ^ ·) := by simpa only [mul_left_iterate, mul_one] using iterate_injOn_Iio_minimalPeriod (f := (x * ·)) (x := 1) @[to_additive] protected lemma IsOfFinOrder.mem_powers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ Submonoid.powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := Finset.mem_range_iff_mem_finset_range_of_mod_eq' hx.orderOf_pos <| pow_mod_orderOf _ @[to_additive] protected lemma IsOfFinOrder.powers_eq_image_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : (Submonoid.powers x : Set G) = (Finset.range (orderOf x)).image (x ^ ·) := Set.ext fun _ ↦ hx.mem_powers_iff_mem_range_orderOf @[to_additive] theorem pow_eq_one_iff_modEq : x ^ n = 1 ↔ n ≡ 0 [MOD orderOf x] := by rw [modEq_zero_iff_dvd, orderOf_dvd_iff_pow_eq_one] @[to_additive] theorem orderOf_map_dvd {H : Type*} [Monoid H] (ψ : G →* H) (x : G) : orderOf (ψ x) ∣ orderOf x := by apply orderOf_dvd_of_pow_eq_one rw [← map_pow, pow_orderOf_eq_one] apply map_one @[to_additive]
Mathlib/GroupTheory/OrderOfElement.lean
279
280
theorem exists_pow_eq_self_of_coprime (h : n.Coprime (orderOf x)) : ∃ m : ℕ, (x ^ n) ^ m = x := by
by_cases h0 : orderOf x = 0
/- Copyright (c) 2023 Scott Carnahan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Carnahan -/ import Mathlib.Algebra.Group.NatPowAssoc import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Eval.SMul /-! # Scalar-multiple polynomial evaluation This file defines polynomial evaluation via scalar multiplication. Our polynomials have coefficients in a semiring `R`, and we evaluate at a weak form of `R`-algebra, namely an additive commutative monoid with an action of `R` and a notion of natural number power. This is a generalization of `Algebra.Polynomial.Eval`. ## Main definitions * `Polynomial.smeval`: function for evaluating a polynomial with coefficients in a `Semiring` `R` at an element `x` of an `AddCommMonoid` `S` that has natural number powers and an `R`-action. * `smeval.linearMap`: the `smeval` function as an `R`-linear map, when `S` is an `R`-module. * `smeval.algebraMap`: the `smeval` function as an `R`-algebra map, when `S` is an `R`-algebra. ## Main results * `smeval_monomial`: monomials evaluate as we expect. * `smeval_add`, `smeval_smul`: linearity of evaluation, given an `R`-module. * `smeval_mul`, `smeval_comp`: multiplicativity of evaluation, given power-associativity. * `eval₂_smulOneHom_eq_smeval`, `leval_eq_smeval.linearMap`, `aeval_eq_smeval`, etc.: comparisons ## TODO * `smeval_neg` and `smeval_intCast` for `R` a ring and `S` an `AddCommGroup`. * Nonunital evaluation for polynomials with vanishing constant term for `Pow S ℕ+` (different file?) -/ namespace Polynomial section MulActionWithZero variable {R : Type*} [Semiring R] (r : R) (p : R[X]) {S : Type*} [AddCommMonoid S] [Pow S ℕ] [MulActionWithZero R S] (x : S) /-- Scalar multiplication together with taking a natural number power. -/ def smul_pow : ℕ → R → S := fun n r => r • x^n /-- Evaluate a polynomial `p` in the scalar semiring `R` at an element `x` in the target `S` using scalar multiple `R`-action. -/ irreducible_def smeval : S := p.sum (smul_pow x) theorem smeval_eq_sum : p.smeval x = p.sum (smul_pow x) := by rw [smeval_def] @[simp] theorem smeval_C : (C r).smeval x = r • x ^ 0 := by simp only [smeval_eq_sum, smul_pow, zero_smul, sum_C_index] @[simp] theorem smeval_monomial (n : ℕ) : (monomial n r).smeval x = r • x ^ n := by simp only [smeval_eq_sum, smul_pow, zero_smul, sum_monomial_index] theorem eval_eq_smeval : p.eval r = p.smeval r := by rw [eval_eq_sum, smeval_eq_sum] rfl theorem eval₂_smulOneHom_eq_smeval (R : Type*) [Semiring R] {S : Type*} [Semiring S] [Module R S] [IsScalarTower R S S] (p : R[X]) (x : S) : p.eval₂ RingHom.smulOneHom x = p.smeval x := by rw [smeval_eq_sum, eval₂_eq_sum] congr 1 with e a simp only [RingHom.smulOneHom_apply, smul_one_mul, smul_pow] variable (R) @[simp] theorem smeval_zero : (0 : R[X]).smeval x = 0 := by simp only [smeval_eq_sum, smul_pow, sum_zero_index] @[simp]
Mathlib/Algebra/Polynomial/Smeval.lean
83
85
theorem smeval_one : (1 : R[X]).smeval x = 1 • x ^ 0 := by
rw [← C_1, smeval_C] simp only [Nat.cast_one, one_smul]
/- 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, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Order.Filter.Interval import Mathlib.Order.Interval.Set.Pi import Mathlib.Tactic.TFAE import Mathlib.Tactic.NormNum import Mathlib.Topology.Order.LeftRight import Mathlib.Topology.Order.OrderClosed /-! # Theory of topology on ordered spaces ## Main definitions The order topology on an ordered space is the topology generated by all open intervals (or equivalently by those of the form `(-∞, a)` and `(b, +∞)`). We define it as `Preorder.topology α`. However, we do *not* register it as an instance (as many existing ordered types already have topologies, which would be equal but not definitionally equal to `Preorder.topology α`). Instead, we introduce a class `OrderTopology α` (which is a `Prop`, also known as a mixin) saying that on the type `α` having already a topological space structure and a preorder structure, the topological structure is equal to the order topology. We prove many basic properties of such topologies. ## Main statements This file contains the proofs of the following facts. For exact requirements (`OrderClosedTopology` vs `OrderTopology`, `Preorder` vs `PartialOrder` vs `LinearOrder` etc) see their statements. * `exists_Ioc_subset_of_mem_nhds`, `exists_Ico_subset_of_mem_nhds` : if `x < y`, then any neighborhood of `x` includes an interval `[x, z)` for some `z ∈ (x, y]`, and any neighborhood of `y` includes an interval `(z, y]` for some `z ∈ [x, y)`. * `tendsto_of_tendsto_of_tendsto_of_le_of_le` : theorem known as squeeze theorem, sandwich theorem, theorem of Carabinieri, and two policemen (and a drunk) theorem; if `g` and `h` both converge to `a`, and eventually `g x ≤ f x ≤ h x`, then `f` converges to `a`. ## Implementation notes We do _not_ register the order topology as an instance on a preorder (or even on a linear order). Indeed, on many such spaces, a topology has already been constructed in a different way (think of the discrete spaces `ℕ` or `ℤ`, or `ℝ` that could inherit a topology as the completion of `ℚ`), and is in general not defeq to the one generated by the intervals. We make it available as a definition `Preorder.topology α` though, that can be registered as an instance when necessary, or for specific types. -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) universe u v w variable {α : Type u} {β : Type v} {γ : Type w} -- TODO: define `Preorder.topology` before `OrderTopology` and reuse the def /-- The order topology on an ordered type is the topology generated by open intervals. We register it on a preorder, but it is mostly interesting in linear orders, where it is also order-closed. We define it as a mixin. If you want to introduce the order topology on a preorder, use `Preorder.topology`. -/ class OrderTopology (α : Type*) [t : TopologicalSpace α] [Preorder α] : Prop where /-- The topology is generated by open intervals `Set.Ioi _` and `Set.Iio _`. -/ topology_eq_generate_intervals : t = generateFrom { s | ∃ a, s = Ioi a ∨ s = Iio a } /-- (Order) topology on a partial order `α` generated by the subbase of open intervals `(a, ∞) = { x ∣ a < x }, (-∞ , b) = {x ∣ x < b}` for all `a, b` in `α`. We do not register it as an instance as many ordered sets are already endowed with the same topology, most often in a non-defeq way though. Register as a local instance when necessary. -/ def Preorder.topology (α : Type*) [Preorder α] : TopologicalSpace α := generateFrom { s : Set α | ∃ a : α, s = { b : α | a < b } ∨ s = { b : α | b < a } } section OrderTopology section Preorder variable [TopologicalSpace α] [Preorder α] instance [t : OrderTopology α] : OrderTopology αᵒᵈ := ⟨by convert OrderTopology.topology_eq_generate_intervals (α := α) using 6 apply or_comm⟩ theorem isOpen_iff_generate_intervals [t : OrderTopology α] {s : Set α} : IsOpen s ↔ GenerateOpen { s | ∃ a, s = Ioi a ∨ s = Iio a } s := by rw [t.topology_eq_generate_intervals]; rfl theorem isOpen_lt' [OrderTopology α] (a : α) : IsOpen { b : α | a < b } := isOpen_iff_generate_intervals.2 <| .basic _ ⟨a, .inl rfl⟩ theorem isOpen_gt' [OrderTopology α] (a : α) : IsOpen { b : α | b < a } := isOpen_iff_generate_intervals.2 <| .basic _ ⟨a, .inr rfl⟩ theorem lt_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a < x := (isOpen_lt' _).mem_nhds h theorem le_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a ≤ x := (lt_mem_nhds h).mono fun _ => le_of_lt theorem gt_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x < b := (isOpen_gt' _).mem_nhds h theorem ge_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x ≤ b := (gt_mem_nhds h).mono fun _ => le_of_lt theorem nhds_eq_order [OrderTopology α] (a : α) : 𝓝 a = (⨅ b ∈ Iio a, 𝓟 (Ioi b)) ⊓ ⨅ b ∈ Ioi a, 𝓟 (Iio b) := by rw [OrderTopology.topology_eq_generate_intervals (α := α), nhds_generateFrom] simp_rw [mem_setOf_eq, @and_comm (a ∈ _), exists_or, or_and_right, iInf_or, iInf_and, iInf_exists, iInf_inf_eq, iInf_comm (ι := Set α), iInf_iInf_eq_left, mem_Ioi, mem_Iio] theorem tendsto_order [OrderTopology α] {f : β → α} {a : α} {x : Filter β} : Tendsto f x (𝓝 a) ↔ (∀ a' < a, ∀ᶠ b in x, a' < f b) ∧ ∀ a' > a, ∀ᶠ b in x, f b < a' := by simp only [nhds_eq_order a, tendsto_inf, tendsto_iInf, tendsto_principal]; rfl instance tendstoIccClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Icc (𝓝 a) (𝓝 a) := by simp only [nhds_eq_order, iInf_subtype'] refine ((hasBasis_iInf_principal_finite _).inf (hasBasis_iInf_principal_finite _)).tendstoIxxClass fun s _ => ?_ refine ((ordConnected_biInter ?_).inter (ordConnected_biInter ?_)).out <;> intro _ _ exacts [ordConnected_Ioi, ordConnected_Iio] instance tendstoIcoClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Ico (𝓝 a) (𝓝 a) := tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self instance tendstoIocClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Ioc (𝓝 a) (𝓝 a) := tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self instance tendstoIooClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Ioo (𝓝 a) (𝓝 a) := tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Icc_self /-- **Squeeze theorem** (also known as **sandwich theorem**). This version assumes that inequalities hold eventually for the filter. -/ theorem tendsto_of_tendsto_of_tendsto_of_le_of_le' [OrderTopology α] {f g h : β → α} {b : Filter β} {a : α} (hg : Tendsto g b (𝓝 a)) (hh : Tendsto h b (𝓝 a)) (hgf : ∀ᶠ b in b, g b ≤ f b) (hfh : ∀ᶠ b in b, f b ≤ h b) : Tendsto f b (𝓝 a) := (hg.Icc hh).of_smallSets <| hgf.and hfh alias Filter.Tendsto.squeeze' := tendsto_of_tendsto_of_tendsto_of_le_of_le' /-- **Squeeze theorem** (also known as **sandwich theorem**). This version assumes that inequalities hold everywhere. -/ theorem tendsto_of_tendsto_of_tendsto_of_le_of_le [OrderTopology α] {f g h : β → α} {b : Filter β} {a : α} (hg : Tendsto g b (𝓝 a)) (hh : Tendsto h b (𝓝 a)) (hgf : g ≤ f) (hfh : f ≤ h) : Tendsto f b (𝓝 a) := tendsto_of_tendsto_of_tendsto_of_le_of_le' hg hh (Eventually.of_forall hgf) (Eventually.of_forall hfh) alias Filter.Tendsto.squeeze := tendsto_of_tendsto_of_tendsto_of_le_of_le theorem nhds_order_unbounded [OrderTopology α] {a : α} (hu : ∃ u, a < u) (hl : ∃ l, l < a) : 𝓝 a = ⨅ (l) (_ : l < a) (u) (_ : a < u), 𝓟 (Ioo l u) := by simp only [nhds_eq_order, ← inf_biInf, ← biInf_inf, *, ← inf_principal, ← Ioi_inter_Iio]; rfl theorem tendsto_order_unbounded [OrderTopology α] {f : β → α} {a : α} {x : Filter β} (hu : ∃ u, a < u) (hl : ∃ l, l < a) (h : ∀ l u, l < a → a < u → ∀ᶠ b in x, l < f b ∧ f b < u) : Tendsto f x (𝓝 a) := by simp only [nhds_order_unbounded hu hl, tendsto_iInf, tendsto_principal] exact fun l hl u => h l u hl end Preorder instance tendstoIxxNhdsWithin {α : Type*} [TopologicalSpace α] (a : α) {s t : Set α} {Ixx} [TendstoIxxClass Ixx (𝓝 a) (𝓝 a)] [TendstoIxxClass Ixx (𝓟 s) (𝓟 t)] : TendstoIxxClass Ixx (𝓝[s] a) (𝓝[t] a) := Filter.tendstoIxxClass_inf instance tendstoIccClassNhdsPi {ι : Type*} {α : ι → Type*} [∀ i, Preorder (α i)] [∀ i, TopologicalSpace (α i)] [∀ i, OrderTopology (α i)] (f : ∀ i, α i) : TendstoIxxClass Icc (𝓝 f) (𝓝 f) := by constructor conv in (𝓝 f).smallSets => rw [nhds_pi, Filter.pi] simp only [smallSets_iInf, smallSets_comap_eq_comap_image, tendsto_iInf, tendsto_comap_iff] intro i have : Tendsto (fun g : ∀ i, α i => g i) (𝓝 f) (𝓝 (f i)) := (continuous_apply i).tendsto f refine (this.comp tendsto_fst).Icc (this.comp tendsto_snd) |>.smallSets_mono ?_ filter_upwards [] using fun ⟨f, g⟩ ↦ image_subset_iff.mpr fun p hp ↦ ⟨hp.1 i, hp.2 i⟩ theorem induced_topology_le_preorder [Preorder α] [Preorder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : ∀ {x y}, f x < f y ↔ x < y) : induced f ‹TopologicalSpace β› ≤ Preorder.topology α := by let _ := Preorder.topology α; have : OrderTopology α := ⟨rfl⟩ refine le_of_nhds_le_nhds fun x => ?_ simp only [nhds_eq_order, nhds_induced, comap_inf, comap_iInf, comap_principal, Ioi, Iio, ← hf] refine inf_le_inf (le_iInf₂ fun a ha => ?_) (le_iInf₂ fun a ha => ?_) exacts [iInf₂_le (f a) ha, iInf₂_le (f a) ha] theorem induced_topology_eq_preorder [Preorder α] [Preorder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : ∀ {x y}, f x < f y ↔ x < y) (H₁ : ∀ {a b x}, b < f a → ¬(b < f x) → ∃ y, y < a ∧ b ≤ f y) (H₂ : ∀ {a b x}, f a < b → ¬(f x < b) → ∃ y, a < y ∧ f y ≤ b) : induced f ‹TopologicalSpace β› = Preorder.topology α := by let _ := Preorder.topology α; have : OrderTopology α := ⟨rfl⟩ refine le_antisymm (induced_topology_le_preorder hf) ?_ refine le_of_nhds_le_nhds fun a => ?_ simp only [nhds_eq_order, nhds_induced, comap_inf, comap_iInf, comap_principal] refine inf_le_inf (le_iInf₂ fun b hb => ?_) (le_iInf₂ fun b hb => ?_) · rcases em (∃ x, ¬(b < f x)) with (⟨x, hx⟩ | hb) · rcases H₁ hb hx with ⟨y, hya, hyb⟩ exact iInf₂_le_of_le y hya (principal_mono.2 fun z hz => hyb.trans_lt (hf.2 hz)) · push_neg at hb exact le_principal_iff.2 (univ_mem' hb) · rcases em (∃ x, ¬(f x < b)) with (⟨x, hx⟩ | hb) · rcases H₂ hb hx with ⟨y, hya, hyb⟩ exact iInf₂_le_of_le y hya (principal_mono.2 fun z hz => (hf.2 hz).trans_le hyb) · push_neg at hb exact le_principal_iff.2 (univ_mem' hb) theorem induced_orderTopology' {α : Type u} {β : Type v} [Preorder α] [ta : TopologicalSpace β] [Preorder β] [OrderTopology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H₁ : ∀ {a x}, x < f a → ∃ b < a, x ≤ f b) (H₂ : ∀ {a x}, f a < x → ∃ b > a, f b ≤ x) : @OrderTopology _ (induced f ta) _ := let _ := induced f ta ⟨induced_topology_eq_preorder hf (fun h _ => H₁ h) (fun h _ => H₂ h)⟩ theorem induced_orderTopology {α : Type u} {β : Type v} [Preorder α] [ta : TopologicalSpace β] [Preorder β] [OrderTopology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) : @OrderTopology _ (induced f ta) _ := induced_orderTopology' f (hf) (fun xa => let ⟨b, xb, ba⟩ := H xa; ⟨b, hf.1 ba, le_of_lt xb⟩) fun ax => let ⟨b, ab, bx⟩ := H ax; ⟨b, hf.1 ab, le_of_lt bx⟩ /-- The topology induced by a strictly monotone function with order-connected range is the preorder topology. -/ nonrec theorem StrictMono.induced_topology_eq_preorder {α β : Type*} [LinearOrder α] [LinearOrder β] [t : TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : StrictMono f) (hc : OrdConnected (range f)) : t.induced f = Preorder.topology α := by refine induced_topology_eq_preorder hf.lt_iff_lt (fun h₁ h₂ => ?_) fun h₁ h₂ => ?_ · rcases hc.out (mem_range_self _) (mem_range_self _) ⟨not_lt.1 h₂, h₁.le⟩ with ⟨y, rfl⟩ exact ⟨y, hf.lt_iff_lt.1 h₁, le_rfl⟩ · rcases hc.out (mem_range_self _) (mem_range_self _) ⟨h₁.le, not_lt.1 h₂⟩ with ⟨y, rfl⟩ exact ⟨y, hf.lt_iff_lt.1 h₁, le_rfl⟩ /-- A strictly monotone function between linear orders with order topology is a topological embedding provided that the range of `f` is order-connected. -/ theorem StrictMono.isEmbedding_of_ordConnected {α β : Type*} [LinearOrder α] [LinearOrder β] [TopologicalSpace α] [h : OrderTopology α] [TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : StrictMono f) (hc : OrdConnected (range f)) : IsEmbedding f := ⟨⟨h.1.trans <| Eq.symm <| hf.induced_topology_eq_preorder hc⟩, hf.injective⟩ @[deprecated (since := "2024-10-26")] alias StrictMono.embedding_of_ordConnected := StrictMono.isEmbedding_of_ordConnected /-- On a `Set.OrdConnected` subset of a linear order, the order topology for the restriction of the order is the same as the restriction to the subset of the order topology. -/ instance orderTopology_of_ordConnected {α : Type u} [TopologicalSpace α] [LinearOrder α] [OrderTopology α] {t : Set α} [ht : OrdConnected t] : OrderTopology t := ⟨(Subtype.strictMono_coe t).induced_topology_eq_preorder <| by rwa [← @Subtype.range_val _ t] at ht⟩ theorem nhdsGE_eq_iInf_inf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] (a : α) : 𝓝[≥] a = (⨅ (u) (_ : a < u), 𝓟 (Iio u)) ⊓ 𝓟 (Ici a) := by rw [nhdsWithin, nhds_eq_order] refine le_antisymm (inf_le_inf_right _ inf_le_right) (le_inf (le_inf ?_ inf_le_left) inf_le_right) exact inf_le_right.trans (le_iInf₂ fun l hl => principal_mono.2 <| Ici_subset_Ioi.2 hl) @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_eq'' := nhdsGE_eq_iInf_inf_principal theorem nhdsLE_eq_iInf_inf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] (a : α) : 𝓝[≤] a = (⨅ l < a, 𝓟 (Ioi l)) ⊓ 𝓟 (Iic a) := nhdsGE_eq_iInf_inf_principal (toDual a) @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_eq'' := nhdsLE_eq_iInf_inf_principal theorem nhdsGE_eq_iInf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] {a : α} (ha : ∃ u, a < u) : 𝓝[≥] a = ⨅ (u) (_ : a < u), 𝓟 (Ico a u) := by simp only [nhdsGE_eq_iInf_inf_principal, biInf_inf ha, inf_principal, Iio_inter_Ici] @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_eq' := nhdsGE_eq_iInf_principal theorem nhdsLE_eq_iInf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] {a : α} (ha : ∃ l, l < a) : 𝓝[≤] a = ⨅ l < a, 𝓟 (Ioc l a) := by simp only [nhdsLE_eq_iInf_inf_principal, biInf_inf ha, inf_principal, Ioi_inter_Iic] @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_eq' := nhdsLE_eq_iInf_principal theorem nhdsGE_basis_of_exists_gt [TopologicalSpace α] [LinearOrder α] [OrderTopology α] {a : α} (ha : ∃ u, a < u) : (𝓝[≥] a).HasBasis (fun u => a < u) fun u => Ico a u := (nhdsGE_eq_iInf_principal ha).symm ▸ hasBasis_biInf_principal (fun b hb c hc => ⟨min b c, lt_min hb hc, Ico_subset_Ico_right (min_le_left _ _), Ico_subset_Ico_right (min_le_right _ _)⟩) ha @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_basis' := nhdsGE_basis_of_exists_gt theorem nhdsLE_basis_of_exists_lt [TopologicalSpace α] [LinearOrder α] [OrderTopology α] {a : α} (ha : ∃ l, l < a) : (𝓝[≤] a).HasBasis (fun l => l < a) fun l => Ioc l a := by convert nhdsGE_basis_of_exists_gt (α := αᵒᵈ) ha using 2 exact Ico_toDual.symm @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_basis' := nhdsLE_basis_of_exists_lt theorem nhdsGE_basis [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [NoMaxOrder α] (a : α) : (𝓝[≥] a).HasBasis (fun u => a < u) fun u => Ico a u := nhdsGE_basis_of_exists_gt (exists_gt a) @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_basis := nhdsGE_basis theorem nhdsLE_basis [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [NoMinOrder α] (a : α) : (𝓝[≤] a).HasBasis (fun l => l < a) fun l => Ioc l a := nhdsLE_basis_of_exists_lt (exists_lt a) @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_basis := nhdsLE_basis theorem nhds_top_order [TopologicalSpace α] [Preorder α] [OrderTop α] [OrderTopology α] : 𝓝 (⊤ : α) = ⨅ (l) (_ : l < ⊤), 𝓟 (Ioi l) := by simp [nhds_eq_order (⊤ : α)] theorem nhds_bot_order [TopologicalSpace α] [Preorder α] [OrderBot α] [OrderTopology α] : 𝓝 (⊥ : α) = ⨅ (l) (_ : ⊥ < l), 𝓟 (Iio l) := by simp [nhds_eq_order (⊥ : α)] theorem nhds_top_basis [TopologicalSpace α] [LinearOrder α] [OrderTop α] [OrderTopology α] [Nontrivial α] : (𝓝 ⊤).HasBasis (fun a : α => a < ⊤) fun a : α => Ioi a := by have : ∃ x : α, x < ⊤ := (exists_ne ⊤).imp fun x hx => hx.lt_top simpa only [Iic_top, nhdsWithin_univ, Ioc_top] using nhdsLE_basis_of_exists_lt this theorem nhds_bot_basis [TopologicalSpace α] [LinearOrder α] [OrderBot α] [OrderTopology α] [Nontrivial α] : (𝓝 ⊥).HasBasis (fun a : α => ⊥ < a) fun a : α => Iio a := nhds_top_basis (α := αᵒᵈ) theorem nhds_top_basis_Ici [TopologicalSpace α] [LinearOrder α] [OrderTop α] [OrderTopology α] [Nontrivial α] [DenselyOrdered α] : (𝓝 ⊤).HasBasis (fun a : α => a < ⊤) Ici := nhds_top_basis.to_hasBasis (fun _a ha => let ⟨b, hab, hb⟩ := exists_between ha; ⟨b, hb, Ici_subset_Ioi.mpr hab⟩) fun a ha => ⟨a, ha, Ioi_subset_Ici_self⟩ theorem nhds_bot_basis_Iic [TopologicalSpace α] [LinearOrder α] [OrderBot α] [OrderTopology α] [Nontrivial α] [DenselyOrdered α] : (𝓝 ⊥).HasBasis (fun a : α => ⊥ < a) Iic := nhds_top_basis_Ici (α := αᵒᵈ) theorem tendsto_nhds_top_mono [TopologicalSpace β] [Preorder β] [OrderTop β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊤)) (hg : f ≤ᶠ[l] g) : Tendsto g l (𝓝 ⊤) := by simp only [nhds_top_order, tendsto_iInf, tendsto_principal] at hf ⊢ intro x hx filter_upwards [hf x hx, hg] with _ using lt_of_lt_of_le theorem tendsto_nhds_bot_mono [TopologicalSpace β] [Preorder β] [OrderBot β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊥)) (hg : g ≤ᶠ[l] f) : Tendsto g l (𝓝 ⊥) := tendsto_nhds_top_mono (β := βᵒᵈ) hf hg theorem tendsto_nhds_top_mono' [TopologicalSpace β] [Preorder β] [OrderTop β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊤)) (hg : f ≤ g) : Tendsto g l (𝓝 ⊤) := tendsto_nhds_top_mono hf (Eventually.of_forall hg) theorem tendsto_nhds_bot_mono' [TopologicalSpace β] [Preorder β] [OrderBot β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊥)) (hg : g ≤ f) : Tendsto g l (𝓝 ⊥) := tendsto_nhds_bot_mono hf (Eventually.of_forall hg) section LinearOrder variable [TopologicalSpace α] [LinearOrder α] section OrderTopology theorem order_separated [OrderTopology α] {a₁ a₂ : α} (h : a₁ < a₂) : ∃ u v : Set α, IsOpen u ∧ IsOpen v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ ∀ b₁ ∈ u, ∀ b₂ ∈ v, b₁ < b₂ := let ⟨x, hx, y, hy, h⟩ := h.exists_disjoint_Iio_Ioi ⟨Iio x, Ioi y, isOpen_gt' _, isOpen_lt' _, hx, hy, h⟩ -- see Note [lower instance priority] instance (priority := 100) OrderTopology.to_orderClosedTopology [OrderTopology α] : OrderClosedTopology α where isClosed_le' := isOpen_compl_iff.1 <| isOpen_prod_iff.mpr fun a₁ a₂ (h : ¬a₁ ≤ a₂) => have h : a₂ < a₁ := lt_of_not_ge h let ⟨u, v, hu, hv, ha₁, ha₂, h⟩ := order_separated h ⟨v, u, hv, hu, ha₂, ha₁, fun ⟨b₁, b₂⟩ ⟨h₁, h₂⟩ => not_le_of_gt <| h b₂ h₂ b₁ h₁⟩ theorem exists_Ioc_subset_of_mem_nhds [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) (h : ∃ l, l < a) : ∃ l < a, Ioc l a ⊆ s := (nhdsLE_basis_of_exists_lt h).mem_iff.mp (nhdsWithin_le_nhds hs) theorem exists_Ioc_subset_of_mem_nhds' [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) {l : α} (hl : l < a) : ∃ l' ∈ Ico l a, Ioc l' a ⊆ s := let ⟨l', hl'a, hl's⟩ := exists_Ioc_subset_of_mem_nhds hs ⟨l, hl⟩ ⟨max l l', ⟨le_max_left _ _, max_lt hl hl'a⟩, (Ioc_subset_Ioc_left <| le_max_right _ _).trans hl's⟩ theorem exists_Ico_subset_of_mem_nhds' [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) {u : α} (hu : a < u) : ∃ u' ∈ Ioc a u, Ico a u' ⊆ s := by simpa only [OrderDual.exists, exists_prop, Ico_toDual, Ioc_toDual] using exists_Ioc_subset_of_mem_nhds' (show ofDual ⁻¹' s ∈ 𝓝 (toDual a) from hs) hu.dual theorem exists_Ico_subset_of_mem_nhds [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) (h : ∃ u, a < u) : ∃ u, a < u ∧ Ico a u ⊆ s := let ⟨_l', hl'⟩ := h let ⟨l, hl⟩ := exists_Ico_subset_of_mem_nhds' hs hl' ⟨l, hl.1.1, hl.2⟩ theorem exists_Icc_mem_subset_of_mem_nhdsGE [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝[≥] a) : ∃ b, a ≤ b ∧ Icc a b ∈ 𝓝[≥] a ∧ Icc a b ⊆ s := by rcases (em (IsMax a)).imp_right not_isMax_iff.mp with (ha | ha) · use a simpa [ha.Ici_eq] using hs · rcases(nhdsGE_basis_of_exists_gt ha).mem_iff.mp hs with ⟨b, hab, hbs⟩ rcases eq_empty_or_nonempty (Ioo a b) with (H | ⟨c, hac, hcb⟩) · have : Ico a b = Icc a a := by rw [← Icc_union_Ioo_eq_Ico le_rfl hab, H, union_empty] exact ⟨a, le_rfl, this ▸ ⟨Ico_mem_nhdsGE hab, hbs⟩⟩ · refine ⟨c, hac.le, Icc_mem_nhdsGE hac, ?_⟩ exact (Icc_subset_Ico_right hcb).trans hbs @[deprecated (since := "2024-12-22")] alias exists_Icc_mem_subset_of_mem_nhdsWithin_Ici := exists_Icc_mem_subset_of_mem_nhdsGE
Mathlib/Topology/Order/Basic.lean
407
410
theorem exists_Icc_mem_subset_of_mem_nhdsLE [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝[≤] a) : ∃ b ≤ a, Icc b a ∈ 𝓝[≤] a ∧ Icc b a ⊆ s := by
simpa only [Icc_toDual, toDual.surjective.exists] using exists_Icc_mem_subset_of_mem_nhdsGE (α := αᵒᵈ) (a := toDual a) hs
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Morenikeji Neri -/ import Mathlib.Algebra.EuclideanDomain.Basic import Mathlib.Algebra.EuclideanDomain.Field import Mathlib.Algebra.GCDMonoid.Basic import Mathlib.RingTheory.Ideal.Maps import Mathlib.RingTheory.Ideal.Nonunits import Mathlib.RingTheory.Noetherian.UniqueFactorizationDomain /-! # Principal ideal rings, principal ideal domains, and Bézout rings A principal ideal ring (PIR) is a ring in which all left ideals are principal. A principal ideal domain (PID) is an integral domain which is a principal ideal ring. The definition of `IsPrincipalIdealRing` can be found in `Mathlib.RingTheory.Ideal.Span`. # Main definitions Note that for principal ideal domains, one should use `[IsDomain R] [IsPrincipalIdealRing R]`. There is no explicit definition of a PID. Theorems about PID's are in the `PrincipalIdealRing` namespace. - `IsBezout`: the predicate saying that every finitely generated left ideal is principal. - `generator`: a generator of a principal ideal (or more generally submodule) - `to_uniqueFactorizationMonoid`: a PID is a unique factorization domain # Main results - `Ideal.IsPrime.to_maximal_ideal`: a non-zero prime ideal in a PID is maximal. - `EuclideanDomain.to_principal_ideal_domain` : a Euclidean domain is a PID. - `IsBezout.nonemptyGCDMonoid`: Every Bézout domain is a GCD domain. -/ universe u v variable {R : Type u} {M : Type v} open Set Function open Submodule section variable [Semiring R] [AddCommGroup M] [Module R M] instance bot_isPrincipal : (⊥ : Submodule R M).IsPrincipal := ⟨⟨0, by simp⟩⟩ instance top_isPrincipal : (⊤ : Submodule R R).IsPrincipal := ⟨⟨1, Ideal.span_singleton_one.symm⟩⟩ variable (R) /-- A Bézout ring is a ring whose finitely generated ideals are principal. -/ class IsBezout : Prop where /-- Any finitely generated ideal is principal. -/ isPrincipal_of_FG : ∀ I : Ideal R, I.FG → I.IsPrincipal instance (priority := 100) IsBezout.of_isPrincipalIdealRing [IsPrincipalIdealRing R] : IsBezout R := ⟨fun I _ => IsPrincipalIdealRing.principal I⟩ instance (priority := 100) DivisionRing.isPrincipalIdealRing (K : Type u) [DivisionRing K] : IsPrincipalIdealRing K where principal S := by rcases Ideal.eq_bot_or_top S with (rfl | rfl) · apply bot_isPrincipal · apply top_isPrincipal end namespace Submodule.IsPrincipal variable [AddCommMonoid M] section Semiring variable [Semiring R] [Module R M] /-- `generator I`, if `I` is a principal submodule, is an `x ∈ M` such that `span R {x} = I` -/ noncomputable def generator (S : Submodule R M) [S.IsPrincipal] : M := Classical.choose (principal S) theorem span_singleton_generator (S : Submodule R M) [S.IsPrincipal] : span R {generator S} = S := Eq.symm (Classical.choose_spec (principal S)) @[simp] theorem _root_.Ideal.span_singleton_generator (I : Ideal R) [I.IsPrincipal] : Ideal.span ({generator I} : Set R) = I := Eq.symm (Classical.choose_spec (principal I)) @[simp] theorem generator_mem (S : Submodule R M) [S.IsPrincipal] : generator S ∈ S := by have : generator S ∈ span R {generator S} := subset_span (mem_singleton _) convert this exact span_singleton_generator S |>.symm theorem mem_iff_eq_smul_generator (S : Submodule R M) [S.IsPrincipal] {x : M} : x ∈ S ↔ ∃ s : R, x = s • generator S := by simp_rw [@eq_comm _ x, ← mem_span_singleton, span_singleton_generator] theorem eq_bot_iff_generator_eq_zero (S : Submodule R M) [S.IsPrincipal] : S = ⊥ ↔ generator S = 0 := by rw [← @span_singleton_eq_bot R M, span_singleton_generator] protected lemma fg {S : Submodule R M} (h : S.IsPrincipal) : S.FG := ⟨{h.generator}, by simp only [Finset.coe_singleton, span_singleton_generator]⟩ -- See note [lower instance priority] instance (priority := 100) _root_.PrincipalIdealRing.isNoetherianRing [IsPrincipalIdealRing R] : IsNoetherianRing R where noetherian S := (IsPrincipalIdealRing.principal S).fg -- See note [lower instance priority] instance (priority := 100) _root_.IsPrincipalIdealRing.of_isNoetherianRing_of_isBezout [IsNoetherianRing R] [IsBezout R] : IsPrincipalIdealRing R where principal S := IsBezout.isPrincipal_of_FG S (IsNoetherian.noetherian S) end Semiring section CommRing variable [CommRing R] [Module R M]
Mathlib/RingTheory/PrincipalIdealDomain.lean
129
130
theorem associated_generator_span_self [IsPrincipalIdealRing R] [IsDomain R] (r : R) : Associated (generator <| Ideal.span {r}) r := by
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.Tactic.FieldSimp import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.Basis /-! # Determinant of families of vectors This file defines the determinant of an endomorphism, and of a family of vectors with respect to some basis. For the determinant of a matrix, see the file `LinearAlgebra.Matrix.Determinant`. ## Main definitions In the list below, and in all this file, `R` is a commutative ring (semiring is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite types used for indexing. * `Basis.det`: the determinant of a family of vectors with respect to a basis, as a multilinear map * `LinearMap.det`: the determinant of an endomorphism `f : End R M` as a multiplicative homomorphism (if `M` does not have a finite `R`-basis, the result is `1` instead) * `LinearEquiv.det`: the determinant of an isomorphism `f : M ≃ₗ[R] M` as a multiplicative homomorphism (if `M` does not have a finite `R`-basis, the result is `1` instead) ## Tags basis, det, determinant -/ noncomputable section open Matrix LinearMap Submodule Set Function universe u v w variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable {M' : Type*} [AddCommGroup M'] [Module R M'] variable {ι : Type*} [DecidableEq ι] [Fintype ι] variable (e : Basis ι R M) section Conjugate variable {A : Type*} [CommRing A] variable {m n : Type*} /-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/ def equivOfPiLEquivPi {R : Type*} [Finite m] [Finite n] [CommRing R] [Nontrivial R] (e : (m → R) ≃ₗ[R] n → R) : m ≃ n := Basis.indexEquiv (Basis.ofEquivFun e.symm) (Pi.basisFun _ _) namespace Matrix variable [Fintype m] [Fintype n] /-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to equivalence of types. -/ def indexEquivOfInv [Nontrivial A] [DecidableEq m] [DecidableEq n] {M : Matrix m n A} {M' : Matrix n m A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : m ≃ n := equivOfPiLEquivPi (toLin'OfInv hMM' hM'M) theorem det_comm [DecidableEq n] (M N : Matrix n n A) : det (M * N) = det (N * M) := by rw [det_mul, det_mul, mul_comm] /-- If there exists a two-sided inverse `M'` for `M` (indexed differently), then `det (N * M) = det (M * N)`. -/ theorem det_comm' [DecidableEq m] [DecidableEq n] {M : Matrix n m A} {N : Matrix m n A} {M' : Matrix m n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N) = det (N * M) := by nontriviality A -- Although `m` and `n` are different a priori, we will show they have the same cardinality. -- This turns the problem into one for square matrices, which is easy. let e := indexEquivOfInv hMM' hM'M rw [← det_submatrix_equiv_self e, ← submatrix_mul_equiv _ _ _ (Equiv.refl n) _, det_comm, submatrix_mul_equiv, Equiv.coe_refl, submatrix_id_id] /-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M * N * M') = det N`. See `Matrix.det_conj` and `Matrix.det_conj'` for the case when `M' = M⁻¹` or vice versa. -/ theorem det_conj_of_mul_eq_one [DecidableEq m] [DecidableEq n] {M : Matrix m n A} {M' : Matrix n m A} {N : Matrix n n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N * M') = det N := by rw [← det_comm' hM'M hMM', ← Matrix.mul_assoc, hM'M, Matrix.one_mul] end Matrix end Conjugate namespace LinearMap /-! ### Determinant of a linear map -/ variable {A : Type*} [CommRing A] [Module A M] variable {κ : Type*} [Fintype κ] /-- The determinant of `LinearMap.toMatrix` does not depend on the choice of basis. -/ theorem det_toMatrix_eq_det_toMatrix [DecidableEq κ] (b : Basis ι A M) (c : Basis κ A M) (f : M →ₗ[A] M) : det (LinearMap.toMatrix b b f) = det (LinearMap.toMatrix c c f) := by rw [← linearMap_toMatrix_mul_basis_toMatrix c b c, ← basis_toMatrix_mul_linearMap_toMatrix b c b, Matrix.det_conj_of_mul_eq_one] <;> rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self] /-- The determinant of an endomorphism given a basis. See `LinearMap.det` for a version that populates the basis non-computably. Although the `Trunc (Basis ι A M)` parameter makes it slightly more convenient to switch bases, there is no good way to generalize over universe parameters, so we can't fully state in `detAux`'s type that it does not depend on the choice of basis. Instead you can use the `detAux_def''` lemma, or avoid mentioning a basis at all using `LinearMap.det`. -/ irreducible_def detAux : Trunc (Basis ι A M) → (M →ₗ[A] M) →* A := Trunc.lift (fun b : Basis ι A M => detMonoidHom.comp (toMatrixAlgEquiv b : (M →ₗ[A] M) →* Matrix ι ι A)) fun b c => MonoidHom.ext <| det_toMatrix_eq_det_toMatrix b c /-- Unfold lemma for `detAux`. See also `detAux_def''` which allows you to vary the basis. -/ theorem detAux_def' (b : Basis ι A M) (f : M →ₗ[A] M) : LinearMap.detAux (Trunc.mk b) f = Matrix.det (LinearMap.toMatrix b b f) := by rw [detAux] rfl theorem detAux_def'' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (tb : Trunc <| Basis ι A M) (b' : Basis ι' A M) (f : M →ₗ[A] M) : LinearMap.detAux tb f = Matrix.det (LinearMap.toMatrix b' b' f) := by induction tb using Trunc.induction_on with | h b => rw [detAux_def', det_toMatrix_eq_det_toMatrix b b'] @[simp] theorem detAux_id (b : Trunc <| Basis ι A M) : LinearMap.detAux b LinearMap.id = 1 := (LinearMap.detAux b).map_one @[simp] theorem detAux_comp (b : Trunc <| Basis ι A M) (f g : M →ₗ[A] M) : LinearMap.detAux b (f.comp g) = LinearMap.detAux b f * LinearMap.detAux b g := (LinearMap.detAux b).map_mul f g section open scoped Classical in -- Discourage the elaborator from unfolding `det` and producing a huge term by marking it -- as irreducible. /-- The determinant of an endomorphism independent of basis. If there is no finite basis on `M`, the result is `1` instead. -/ protected irreducible_def det : (M →ₗ[A] M) →* A := if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some) else 1 open scoped Classical in theorem coe_det [DecidableEq M] : ⇑(LinearMap.det : (M →ₗ[A] M) →* A) = if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some) else 1 := by ext rw [LinearMap.det_def] split_ifs · congr -- use the correct `DecidableEq` instance rfl end -- Auxiliary lemma, the `simp` normal form goes in the other direction -- (using `LinearMap.det_toMatrix`) theorem det_eq_det_toMatrix_of_finset [DecidableEq M] {s : Finset M} (b : Basis s A M) (f : M →ₗ[A] M) : LinearMap.det f = Matrix.det (LinearMap.toMatrix b b f) := by have : ∃ s : Finset M, Nonempty (Basis s A M) := ⟨s, ⟨b⟩⟩ rw [LinearMap.coe_det, dif_pos, detAux_def'' _ b] <;> assumption @[simp] theorem det_toMatrix (b : Basis ι A M) (f : M →ₗ[A] M) : Matrix.det (toMatrix b b f) = LinearMap.det f := by haveI := Classical.decEq M rw [det_eq_det_toMatrix_of_finset b.reindexFinsetRange, det_toMatrix_eq_det_toMatrix b b.reindexFinsetRange] @[simp] theorem det_toMatrix' {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → A) →ₗ[A] ι → A) : Matrix.det (LinearMap.toMatrix' f) = LinearMap.det f := by simp [← toMatrix_eq_toMatrix'] @[simp] theorem det_toLin (b : Basis ι R M) (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin b b f) = f.det := by rw [← LinearMap.det_toMatrix b, LinearMap.toMatrix_toLin] @[simp] theorem det_toLin' (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin' f) = Matrix.det f := by simp only [← toLin_eq_toLin', det_toLin] /-- To show `P (LinearMap.det f)` it suffices to consider `P (Matrix.det (toMatrix _ _ f))` and `P 1`. -/ @[elab_as_elim] theorem det_cases [DecidableEq M] {P : A → Prop} (f : M →ₗ[A] M) (hb : ∀ (s : Finset M) (b : Basis s A M), P (Matrix.det (toMatrix b b f))) (h1 : P 1) : P (LinearMap.det f) := by classical if H : ∃ s : Finset M, Nonempty (Basis s A M) then obtain ⟨s, ⟨b⟩⟩ := H rw [← det_toMatrix b] exact hb s b else rwa [LinearMap.det_def, dif_neg H] @[simp] theorem det_comp (f g : M →ₗ[A] M) : LinearMap.det (f.comp g) = LinearMap.det f * LinearMap.det g := LinearMap.det.map_mul f g @[simp] theorem det_id : LinearMap.det (LinearMap.id : M →ₗ[A] M) = 1 := LinearMap.det.map_one /-- Multiplying a map by a scalar `c` multiplies its determinant by `c ^ dim M`. -/ @[simp] theorem det_smul [Module.Free A M] (c : A) (f : M →ₗ[A] M) : LinearMap.det (c • f) = c ^ Module.finrank A M * LinearMap.det f := by nontriviality A by_cases H : ∃ s : Finset M, Nonempty (Basis s A M) · have : Module.Finite A M := by rcases H with ⟨s, ⟨hs⟩⟩ exact Module.Finite.of_basis hs simp only [← det_toMatrix (Module.finBasis A M), LinearEquiv.map_smul, Fintype.card_fin, Matrix.det_smul] · classical have : Module.finrank A M = 0 := finrank_eq_zero_of_not_exists_basis H simp [coe_det, H, this] theorem det_zero' {ι : Type*} [Finite ι] [Nonempty ι] (b : Basis ι A M) : LinearMap.det (0 : M →ₗ[A] M) = 0 := by haveI := Classical.decEq ι cases nonempty_fintype ι rwa [← det_toMatrix b, LinearEquiv.map_zero, det_zero] /-- In a finite-dimensional vector space, the zero map has determinant `1` in dimension `0`, and `0` otherwise. We give a formula that also works in infinite dimension, where we define the determinant to be `1`. -/ @[simp] theorem det_zero [Module.Free A M] : LinearMap.det (0 : M →ₗ[A] M) = (0 : A) ^ Module.finrank A M := by simp only [← zero_smul A (1 : M →ₗ[A] M), det_smul, mul_one, MonoidHom.map_one] theorem det_eq_one_of_not_module_finite (h : ¬Module.Finite R M) (f : M →ₗ[R] M) : f.det = 1 := by rw [LinearMap.det, dif_neg, MonoidHom.one_apply] exact fun ⟨_, ⟨b⟩⟩ ↦ h (Module.Finite.of_basis b) theorem det_eq_one_of_subsingleton [Subsingleton M] (f : M →ₗ[R] M) : LinearMap.det (f : M →ₗ[R] M) = 1 := by have b : Basis (Fin 0) R M := Basis.empty M rw [← f.det_toMatrix b] exact Matrix.det_isEmpty theorem det_eq_one_of_finrank_eq_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] (h : Module.finrank 𝕜 M = 0) (f : M →ₗ[𝕜] M) : LinearMap.det (f : M →ₗ[𝕜] M) = 1 := by classical refine @LinearMap.det_cases M _ 𝕜 _ _ _ (fun t => t = 1) f ?_ rfl intro s b have : IsEmpty s := by rw [← Fintype.card_eq_zero_iff] exact (Module.finrank_eq_card_basis b).symm.trans h exact Matrix.det_isEmpty /-- Conjugating a linear map by a linear equiv does not change its determinant. -/ @[simp] theorem det_conj {N : Type*} [AddCommGroup N] [Module A N] (f : M →ₗ[A] M) (e : M ≃ₗ[A] N) : LinearMap.det ((e : M →ₗ[A] N) ∘ₗ f ∘ₗ (e.symm : N →ₗ[A] M)) = LinearMap.det f := by classical by_cases H : ∃ s : Finset M, Nonempty (Basis s A M) · rcases H with ⟨s, ⟨b⟩⟩ rw [← det_toMatrix b f, ← det_toMatrix (b.map e), toMatrix_comp (b.map e) b (b.map e), toMatrix_comp (b.map e) b b, ← Matrix.mul_assoc, Matrix.det_conj_of_mul_eq_one] · rw [← toMatrix_comp, LinearEquiv.comp_coe, e.symm_trans_self, LinearEquiv.refl_toLinearMap, toMatrix_id] · rw [← toMatrix_comp, LinearEquiv.comp_coe, e.self_trans_symm, LinearEquiv.refl_toLinearMap, toMatrix_id] · have H' : ¬∃ t : Finset N, Nonempty (Basis t A N) := by contrapose! H rcases H with ⟨s, ⟨b⟩⟩ exact ⟨_, ⟨(b.map e.symm).reindexFinsetRange⟩⟩ simp only [coe_det, H, H', MonoidHom.one_apply, dif_neg, not_false_eq_true] /-- If a linear map is invertible, so is its determinant. -/ theorem isUnit_det {A : Type*} [CommRing A] [Module A M] (f : M →ₗ[A] M) (hf : IsUnit f) : IsUnit (LinearMap.det f) := by obtain ⟨g, hg⟩ : ∃ g, f.comp g = 1 := hf.exists_right_inv have : LinearMap.det f * LinearMap.det g = 1 := by simp only [← LinearMap.det_comp, hg, MonoidHom.map_one] exact isUnit_of_mul_eq_one _ _ this /-- If a linear map has determinant different from `1`, then the space is finite-dimensional. -/ theorem finiteDimensional_of_det_ne_one {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 1) : FiniteDimensional 𝕜 M := by by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M) · rcases H with ⟨s, ⟨hs⟩⟩ exact FiniteDimensional.of_fintype_basis hs · classical simp [LinearMap.coe_det, H] at hf /-- If the determinant of a map vanishes, then the map is not onto. -/ theorem range_lt_top_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M} (hf : LinearMap.det f = 0) : LinearMap.range f < ⊤ := by have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf] contrapose hf simp only [lt_top_iff_ne_top, Classical.not_not, ← isUnit_iff_range_eq_top] at hf exact isUnit_iff_ne_zero.1 (f.isUnit_det hf) /-- If the determinant of a map vanishes, then the map is not injective. -/ theorem bot_lt_ker_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M} (hf : LinearMap.det f = 0) : ⊥ < LinearMap.ker f := by have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf] contrapose hf simp only [bot_lt_iff_ne_bot, Classical.not_not, ← isUnit_iff_ker_eq_bot] at hf exact isUnit_iff_ne_zero.1 (f.isUnit_det hf) /-- When the function is over the base ring, the determinant is the evaluation at `1`. -/ @[simp] lemma det_ring (f : R →ₗ[R] R) : f.det = f 1 := by simp [← det_toMatrix (Basis.singleton Unit R)] lemma det_mulLeft (a : R) : (mulLeft R a).det = a := by simp lemma det_mulRight (a : R) : (mulRight R a).det = a := by simp theorem det_prodMap [Module.Free R M] [Module.Free R M'] [Module.Finite R M] [Module.Finite R M'] (f : Module.End R M) (f' : Module.End R M') : (prodMap f f').det = f.det * f'.det := by let b := Module.Free.chooseBasis R M let b' := Module.Free.chooseBasis R M' rw [← det_toMatrix (b.prod b'), ← det_toMatrix b, ← det_toMatrix b', toMatrix_prodMap, det_fromBlocks_zero₂₁, det_toMatrix] omit [DecidableEq ι] in theorem det_pi [Module.Free R M] [Module.Finite R M] (f : ι → M →ₗ[R] M) : (LinearMap.pi (fun i ↦ (f i).comp (LinearMap.proj i))).det = ∏ i, (f i).det := by classical let b := Module.Free.chooseBasis R M let B := (Pi.basis (fun _ : ι ↦ b)).reindex <| (Equiv.sigmaEquivProd _ _).trans (Equiv.prodComm _ _) simp_rw [← LinearMap.det_toMatrix B, ← LinearMap.det_toMatrix b] have : ((LinearMap.toMatrix B B) (LinearMap.pi fun i ↦ f i ∘ₗ LinearMap.proj i)) = Matrix.blockDiagonal (fun i ↦ LinearMap.toMatrix b b (f i)) := by ext ⟨i₁, i₂⟩ ⟨j₁, j₂⟩ unfold B simp_rw [LinearMap.toMatrix_apply', Matrix.blockDiagonal_apply, Basis.coe_reindex, Function.comp_apply, Basis.repr_reindex_apply, Equiv.symm_trans_apply, Equiv.prodComm_symm, Equiv.prodComm_apply, Equiv.sigmaEquivProd_symm_apply, Prod.swap_prod_mk, Pi.basis_apply, Pi.basis_repr, LinearMap.pi_apply, LinearMap.coe_comp, Function.comp_apply, LinearMap.toMatrix_apply', LinearMap.coe_proj, Function.eval, Pi.single_apply] split_ifs with h · rw [h] · simp only [map_zero, Finsupp.coe_zero, Pi.zero_apply] rw [this, Matrix.det_blockDiagonal] end LinearMap namespace LinearEquiv /-- On a `LinearEquiv`, the domain of `LinearMap.det` can be promoted to `Rˣ`. -/ protected def det : (M ≃ₗ[R] M) →* Rˣ := (Units.map (LinearMap.det : (M →ₗ[R] M) →* R)).comp (LinearMap.GeneralLinearGroup.generalLinearEquiv R M).symm.toMonoidHom @[simp] theorem coe_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f) = LinearMap.det (f : M →ₗ[R] M) := rfl @[simp] theorem coe_inv_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f)⁻¹ = LinearMap.det (f.symm : M →ₗ[R] M) := rfl @[simp] theorem det_refl : LinearEquiv.det (LinearEquiv.refl R M) = 1 := Units.ext <| LinearMap.det_id @[simp] theorem det_trans (f g : M ≃ₗ[R] M) : LinearEquiv.det (f.trans g) = LinearEquiv.det g * LinearEquiv.det f := map_mul _ g f @[simp] theorem det_symm (f : M ≃ₗ[R] M) : LinearEquiv.det f.symm = LinearEquiv.det f⁻¹ := map_inv _ f /-- Conjugating a linear equiv by a linear equiv does not change its determinant. -/ @[simp] theorem det_conj (f : M ≃ₗ[R] M) (e : M ≃ₗ[R] M') : LinearEquiv.det ((e.symm.trans f).trans e) = LinearEquiv.det f := by rw [← Units.eq_iff, coe_det, coe_det, ← comp_coe, ← comp_coe, LinearMap.det_conj] attribute [irreducible] LinearEquiv.det end LinearEquiv /-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/ @[simp]
Mathlib/LinearAlgebra/Determinant.lean
411
413
theorem LinearEquiv.det_mul_det_symm {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) : LinearMap.det (f : M →ₗ[A] M) * LinearMap.det (f.symm : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudryashov -/ import Mathlib.Analysis.Convex.Combination import Mathlib.Analysis.Convex.Strict import Mathlib.Topology.Algebra.Affine import Mathlib.Topology.Algebra.Module.Basic import Mathlib.Topology.Connected.PathConnected import Mathlib.Topology.MetricSpace.ProperSpace.Real /-! # Topological properties of convex sets We prove the following facts: * `Convex.interior` : interior of a convex set is convex; * `Convex.closure` : closure of a convex set is convex; * `closedConvexHull_closure_eq_closedConvexHull` : the closed convex hull of the closure of a set is equal to the closed convex hull of the set; * `Set.Finite.isCompact_convexHull` : convex hull of a finite set is compact; * `Set.Finite.isClosed_convexHull` : convex hull of a finite set is closed. -/ assert_not_exists Norm open Metric Bornology Set Pointwise Convex variable {ι 𝕜 E : Type*} namespace Real variable {s : Set ℝ} {r ε : ℝ} lemma closedBall_eq_segment (hε : 0 ≤ ε) : closedBall r ε = segment ℝ (r - ε) (r + ε) := by rw [closedBall_eq_Icc, segment_eq_Icc ((sub_le_self _ hε).trans <| le_add_of_nonneg_right hε)] lemma ball_eq_openSegment (hε : 0 < ε) : ball r ε = openSegment ℝ (r - ε) (r + ε) := by rw [ball_eq_Ioo, openSegment_eq_Ioo ((sub_lt_self _ hε).trans <| lt_add_of_pos_right _ hε)] theorem convex_iff_isPreconnected : Convex ℝ s ↔ IsPreconnected s := convex_iff_ordConnected.trans isPreconnected_iff_ordConnected.symm end Real alias ⟨_, IsPreconnected.convex⟩ := Real.convex_iff_isPreconnected /-! ### Standard simplex -/ section stdSimplex variable [Fintype ι] /-- Every vector in `stdSimplex 𝕜 ι` has `max`-norm at most `1`. -/ theorem stdSimplex_subset_closedBall : stdSimplex ℝ ι ⊆ Metric.closedBall 0 1 := fun f hf ↦ by rw [Metric.mem_closedBall, dist_pi_le_iff zero_le_one] intro x rw [Pi.zero_apply, Real.dist_0_eq_abs, abs_of_nonneg <| hf.1 x] exact (mem_Icc_of_mem_stdSimplex hf x).2 variable (ι) /-- `stdSimplex ℝ ι` is bounded. -/ theorem bounded_stdSimplex : IsBounded (stdSimplex ℝ ι) := (Metric.isBounded_iff_subset_closedBall 0).2 ⟨1, stdSimplex_subset_closedBall⟩ /-- `stdSimplex ℝ ι` is closed. -/ theorem isClosed_stdSimplex : IsClosed (stdSimplex ℝ ι) := (stdSimplex_eq_inter ℝ ι).symm ▸ IsClosed.inter (isClosed_iInter fun i => isClosed_le continuous_const (continuous_apply i)) (isClosed_eq (continuous_finset_sum _ fun x _ => continuous_apply x) continuous_const) /-- `stdSimplex ℝ ι` is compact. -/ theorem isCompact_stdSimplex : IsCompact (stdSimplex ℝ ι) := Metric.isCompact_iff_isClosed_bounded.2 ⟨isClosed_stdSimplex ι, bounded_stdSimplex ι⟩ instance stdSimplex.instCompactSpace_coe : CompactSpace ↥(stdSimplex ℝ ι) := isCompact_iff_compactSpace.mp <| isCompact_stdSimplex _ /-- The standard one-dimensional simplex in `ℝ² = Fin 2 → ℝ` is homeomorphic to the unit interval. -/ @[simps! -fullyApplied] def stdSimplexHomeomorphUnitInterval : stdSimplex ℝ (Fin 2) ≃ₜ unitInterval where toEquiv := stdSimplexEquivIcc ℝ continuous_toFun := .subtype_mk ((continuous_apply 0).comp continuous_subtype_val) _ continuous_invFun := by apply Continuous.subtype_mk exact (continuous_pi <| Fin.forall_fin_two.2 ⟨continuous_subtype_val, continuous_const.sub continuous_subtype_val⟩) end stdSimplex /-! ### Topological vector spaces -/ section TopologicalSpace variable [Ring 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [DenselyOrdered 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] [AddCommGroup E] [TopologicalSpace E] [ContinuousAdd E] [Module 𝕜 E] [ContinuousSMul 𝕜 E] {x y : E} theorem segment_subset_closure_openSegment : [x -[𝕜] y] ⊆ closure (openSegment 𝕜 x y) := by rw [segment_eq_image, openSegment_eq_image, ← closure_Ioo (zero_ne_one' 𝕜)] exact image_closure_subset_closure_image (by fun_prop) end TopologicalSpace section PseudoMetricSpace variable [Ring 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [DenselyOrdered 𝕜] [PseudoMetricSpace 𝕜] [OrderTopology 𝕜] [ProperSpace 𝕜] [CompactIccSpace 𝕜] [AddCommGroup E] [TopologicalSpace E] [T2Space E] [ContinuousAdd E] [Module 𝕜 E] [ContinuousSMul 𝕜 E] @[simp] theorem closure_openSegment (x y : E) : closure (openSegment 𝕜 x y) = [x -[𝕜] y] := by rw [segment_eq_image, openSegment_eq_image, ← closure_Ioo (zero_ne_one' 𝕜)] exact (image_closure_of_isCompact (isBounded_Ioo _ _).isCompact_closure <| Continuous.continuousOn <| by fun_prop).symm end PseudoMetricSpace section ContinuousConstSMul variable [Field 𝕜] [LinearOrder 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] /-- If `s` is a convex set, then `a • interior s + b • closure s ⊆ interior s` for all `0 < a`, `0 ≤ b`, `a + b = 1`. See also `Convex.combo_interior_self_subset_interior` for a weaker version. -/ theorem Convex.combo_interior_closure_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • interior s + b • closure s ⊆ interior s := interior_smul₀ ha.ne' s ▸ calc interior (a • s) + b • closure s ⊆ interior (a • s) + closure (b • s) := add_subset_add Subset.rfl (smul_closure_subset b s) _ = interior (a • s) + b • s := by rw [isOpen_interior.add_closure (b • s)] _ ⊆ interior (a • s + b • s) := subset_interior_add_left _ ⊆ interior s := interior_mono <| hs.set_combo_subset ha.le hb hab /-- If `s` is a convex set, then `a • interior s + b • s ⊆ interior s` for all `0 < a`, `0 ≤ b`, `a + b = 1`. See also `Convex.combo_interior_closure_subset_interior` for a stronger version. -/ theorem Convex.combo_interior_self_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • interior s + b • s ⊆ interior s := calc a • interior s + b • s ⊆ a • interior s + b • closure s := add_subset_add Subset.rfl <| image_subset _ subset_closure _ ⊆ interior s := hs.combo_interior_closure_subset_interior ha hb hab /-- If `s` is a convex set, then `a • closure s + b • interior s ⊆ interior s` for all `0 ≤ a`, `0 < b`, `a + b = 1`. See also `Convex.combo_self_interior_subset_interior` for a weaker version. -/ theorem Convex.combo_closure_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • closure s + b • interior s ⊆ interior s := by rw [add_comm] exact hs.combo_interior_closure_subset_interior hb ha (add_comm a b ▸ hab) /-- If `s` is a convex set, then `a • s + b • interior s ⊆ interior s` for all `0 ≤ a`, `0 < b`, `a + b = 1`. See also `Convex.combo_closure_interior_subset_interior` for a stronger version. -/ theorem Convex.combo_self_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • s + b • interior s ⊆ interior s := by rw [add_comm] exact hs.combo_interior_self_subset_interior hb ha (add_comm a b ▸ hab) theorem Convex.combo_interior_closure_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ closure s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_interior_closure_subset_interior ha hb hab <| add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) theorem Convex.combo_interior_self_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_interior_closure_mem_interior hx (subset_closure hy) ha hb hab theorem Convex.combo_closure_interior_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : y ∈ interior s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_closure_interior_subset_interior ha hb hab <| add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) theorem Convex.combo_self_interior_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ interior s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_closure_interior_mem_interior (subset_closure hx) hy ha hb hab theorem Convex.openSegment_interior_closure_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ closure s) : openSegment 𝕜 x y ⊆ interior s := by rintro _ ⟨a, b, ha, hb, hab, rfl⟩ exact hs.combo_interior_closure_mem_interior hx hy ha hb.le hab theorem Convex.openSegment_interior_self_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ s) : openSegment 𝕜 x y ⊆ interior s := hs.openSegment_interior_closure_subset_interior hx (subset_closure hy) theorem Convex.openSegment_closure_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : y ∈ interior s) : openSegment 𝕜 x y ⊆ interior s := by rintro _ ⟨a, b, ha, hb, hab, rfl⟩ exact hs.combo_closure_interior_mem_interior hx hy ha.le hb hab theorem Convex.openSegment_self_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ interior s) : openSegment 𝕜 x y ⊆ interior s := hs.openSegment_closure_interior_subset_interior (subset_closure hx) hy section variable [AddRightMono 𝕜] /-- If `x ∈ closure s` and `y ∈ interior s`, then the segment `(x, y]` is included in `interior s`. -/ theorem Convex.add_smul_sub_mem_interior' {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • (y - x) ∈ interior s := by simpa only [sub_smul, smul_sub, one_smul, add_sub, add_comm] using hs.combo_interior_closure_mem_interior hy hx ht.1 (sub_nonneg.mpr ht.2) (add_sub_cancel _ _) /-- If `x ∈ s` and `y ∈ interior s`, then the segment `(x, y]` is included in `interior s`. -/ theorem Convex.add_smul_sub_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • (y - x) ∈ interior s := hs.add_smul_sub_mem_interior' (subset_closure hx) hy ht /-- If `x ∈ closure s` and `x + y ∈ interior s`, then `x + t y ∈ interior s` for `t ∈ (0, 1]`. -/ theorem Convex.add_smul_mem_interior' {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : x + y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • y ∈ interior s := by simpa only [add_sub_cancel_left] using hs.add_smul_sub_mem_interior' hx hy ht /-- If `x ∈ s` and `x + y ∈ interior s`, then `x + t y ∈ interior s` for `t ∈ (0, 1]`. -/ theorem Convex.add_smul_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : x + y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • y ∈ interior s := hs.add_smul_mem_interior' (subset_closure hx) hy ht end /-- In a topological vector space, the interior of a convex set is convex. -/ protected theorem Convex.interior [ZeroLEOneClass 𝕜] {s : Set E} (hs : Convex 𝕜 s) : Convex 𝕜 (interior s) := convex_iff_openSegment_subset.mpr fun _ hx _ hy => hs.openSegment_closure_interior_subset_interior (interior_subset_closure hx) hy /-- In a topological vector space, the closure of a convex set is convex. -/ protected theorem Convex.closure {s : Set E} (hs : Convex 𝕜 s) : Convex 𝕜 (closure s) := fun x hx y hy a b ha hb hab => let f : E → E → E := fun x' y' => a • x' + b • y' have hf : Continuous (Function.uncurry f) := (continuous_fst.const_smul _).add (continuous_snd.const_smul _) show f x y ∈ closure s from map_mem_closure₂ hf hx hy fun _ hx' _ hy' => hs hx' hy' ha hb hab open AffineMap variable [IsStrictOrderedRing 𝕜] /-- A convex set `s` is strictly convex provided that for any two distinct points of `s \ interior s`, the line passing through these points has nonempty intersection with `interior s`. -/ protected theorem Convex.strictConvex' {s : Set E} (hs : Convex 𝕜 s) (h : (s \ interior s).Pairwise fun x y => ∃ c : 𝕜, lineMap x y c ∈ interior s) : StrictConvex 𝕜 s := by refine strictConvex_iff_openSegment_subset.2 ?_ intro x hx y hy hne by_cases hx' : x ∈ interior s · exact hs.openSegment_interior_self_subset_interior hx' hy by_cases hy' : y ∈ interior s · exact hs.openSegment_self_interior_subset_interior hx hy' rcases h ⟨hx, hx'⟩ ⟨hy, hy'⟩ hne with ⟨c, hc⟩ refine (openSegment_subset_union x y ⟨c, rfl⟩).trans (insert_subset_iff.2 ⟨hc, union_subset ?_ ?_⟩) exacts [hs.openSegment_self_interior_subset_interior hx hc, hs.openSegment_interior_self_subset_interior hc hy] /-- A convex set `s` is strictly convex provided that for any two distinct points `x`, `y` of `s \ interior s`, the segment with endpoints `x`, `y` has nonempty intersection with `interior s`. -/ protected theorem Convex.strictConvex {s : Set E} (hs : Convex 𝕜 s) (h : (s \ interior s).Pairwise fun x y => ([x -[𝕜] y] \ frontier s).Nonempty) : StrictConvex 𝕜 s := by refine hs.strictConvex' <| h.imp_on fun x hx y hy _ => ?_ simp only [segment_eq_image_lineMap, ← self_diff_frontier] rintro ⟨_, ⟨⟨c, hc, rfl⟩, hcs⟩⟩ refine ⟨c, hs.segment_subset hx.1 hy.1 ?_, hcs⟩ exact (segment_eq_image_lineMap 𝕜 x y).symm ▸ mem_image_of_mem _ hc end ContinuousConstSMul section ContinuousSMul variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [IsTopologicalAddGroup E] [TopologicalSpace 𝕜] [OrderTopology 𝕜] [ContinuousSMul 𝕜 E] theorem Convex.closure_interior_eq_closure_of_nonempty_interior {s : Set E} (hs : Convex 𝕜 s) (hs' : (interior s).Nonempty) : closure (interior s) = closure s := subset_antisymm (closure_mono interior_subset) fun _ h ↦ closure_mono (hs.openSegment_interior_closure_subset_interior hs'.choose_spec h) (segment_subset_closure_openSegment (right_mem_segment ..))
Mathlib/Analysis/Convex/Topology.lean
296
301
theorem Convex.interior_closure_eq_interior_of_nonempty_interior {s : Set E} (hs : Convex 𝕜 s) (hs' : (interior s).Nonempty) : interior (closure s) = interior s := by
refine subset_antisymm ?_ (interior_mono subset_closure) intro y hy rcases hs' with ⟨x, hx⟩ have h := AffineMap.lineMap_apply_one (k := 𝕜) x y
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Analytic.Within import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Calculus.ContDiff.FTaylorSeries /-! # Higher differentiability A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous. By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or, equivalently, if it is `C^1` and its derivative is `C^{n-1}`. It is `C^∞` if it is `C^n` for all n. Finally, it is `C^ω` if it is analytic (as well as all its derivative, which is automatic if the space is complete). We formalize these notions with predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and `ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set and on the whole space respectively. To avoid the issue of choice when choosing a derivative in sets where the derivative is not necessarily unique, `ContDiffOn` is not defined directly in terms of the regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the existence of a nice sequence of derivatives, expressed with a predicate `HasFTaylorSeriesUpToOn` defined in the file `FTaylorSeries`. We prove basic properties of these notions. ## Main definitions and results Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`. * `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to rank `n`. * `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`. * `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`. * `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`. In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space, `ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f` for `m ≤ n`. ## Implementation notes The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more complicated than the naive definitions one would guess from the intuition over the real or complex numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity in general. In the usual situations, they coincide with the usual definitions. ### Definition of `C^n` functions in domains One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n` functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`. This definition still has the problem that a function which is locally `C^n` would not need to be `C^n`, as different choices of sequences of derivatives around different points might possibly not be glued together to give a globally defined sequence of derivatives. (Note that this issue can not happen over reals, thanks to partition of unity, but the behavior over a general field is not so clear, and we want a definition for general fields). Also, there are locality problems for the order parameter: one could image a function which, for each `n`, has a nice sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore not be glued to give rise to an infinite sequence of derivatives. This would give a function which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`. The resulting definition is slightly more complicated to work with (in fact not so much), but it gives rise to completely satisfactory theorems. For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)` for each natural `m` is by definition `C^∞` at `0`. There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x` within `s`. However, this does not imply continuity or differentiability within `s` of the function at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file). ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞`, and `⊤ : WithTop ℕ∞` with `ω`. To avoid ambiguities with the two tops, the theorems name use either `infty` or `omega`. These notations are scoped in `ContDiff`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open Set Fin Filter Function open scoped NNReal Topology ContDiff universe u uE uF uG uX variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : WithTop ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Smooth functions within a set around a point -/ variable (𝕜) in /-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). For `n = ω`, we require the function to be analytic within `s` at `x`. The precise definition we give (all the derivatives should be analytic) is more involved to work around issues when the space is not complete, but it is equivalent when the space is complete. For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not better, is `C^∞` at `0` within `univ`. -/ def ContDiffWithinAt (n : WithTop ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop := match n with | ω => ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn ω f p u ∧ ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u | (n : ℕ∞) => ∀ m : ℕ, m ≤ n → ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u lemma HasFTaylorSeriesUpToOn.analyticOn (hf : HasFTaylorSeriesUpToOn ω f p s) (h : AnalyticOn 𝕜 (fun x ↦ p x 0) s) : AnalyticOn 𝕜 f s := by have : AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryFin0 𝕜 E F) (p x 0)) s := (LinearIsometryEquiv.analyticOnNhd _ _ ).comp_analyticOn h (Set.mapsTo_univ _ _) exact this.congr (fun y hy ↦ (hf.zero_eq _ hy).symm) lemma ContDiffWithinAt.analyticOn (h : ContDiffWithinAt 𝕜 ω f s x) : ∃ u ∈ 𝓝[insert x s] x, AnalyticOn 𝕜 f u := by obtain ⟨u, hu, p, hp, h'p⟩ := h exact ⟨u, hu, hp.analyticOn (h'p 0)⟩ lemma ContDiffWithinAt.analyticWithinAt (h : ContDiffWithinAt 𝕜 ω f s x) : AnalyticWithinAt 𝕜 f s x := by obtain ⟨u, hu, hf⟩ := h.analyticOn have xu : x ∈ u := mem_of_mem_nhdsWithin (by simp) hu exact (hf x xu).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu) theorem contDiffWithinAt_omega_iff_analyticWithinAt [CompleteSpace F] : ContDiffWithinAt 𝕜 ω f s x ↔ AnalyticWithinAt 𝕜 f s x := by refine ⟨fun h ↦ h.analyticWithinAt, fun h ↦ ?_⟩ obtain ⟨u, hu, p, hp, h'p⟩ := h.exists_hasFTaylorSeriesUpToOn ω exact ⟨u, hu, p, hp.of_le le_top, fun i ↦ h'p i⟩ theorem contDiffWithinAt_nat {n : ℕ} : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u := ⟨fun H => H n le_rfl, fun ⟨u, hu, p, hp⟩ _m hm => ⟨u, hu, p, hp.of_le (mod_cast hm)⟩⟩ /-- When `n` is either a natural number or `ω`, one can characterize the property of being `C^n` as the existence of a neighborhood on which there is a Taylor series up to order `n`, requiring in addition that its terms are analytic in the `ω` case. -/ lemma contDiffWithinAt_iff_of_ne_infty (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u ∧ (n = ω → ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u) := by match n with | ω => simp [ContDiffWithinAt] | ∞ => simp at hn | (n : ℕ) => simp [contDiffWithinAt_nat] theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≤ n) : ContDiffWithinAt 𝕜 m f s x := by match n with | ω => match m with | ω => exact h | (m : ℕ∞) => intro k _ obtain ⟨u, hu, p, hp, -⟩ := h exact ⟨u, hu, p, hp.of_le le_top⟩ | (n : ℕ∞) => match m with | ω => simp at hmn | (m : ℕ∞) => exact fun k hk ↦ h k (le_trans hk (mod_cast hmn)) /-- In a complete space, a function which is analytic within a set at a point is also `C^ω` there. Note that the same statement for `AnalyticOn` does not require completeness, see `AnalyticOn.contDiffOn`. -/ theorem AnalyticWithinAt.contDiffWithinAt [CompleteSpace F] (h : AnalyticWithinAt 𝕜 f s x) : ContDiffWithinAt 𝕜 n f s x := (contDiffWithinAt_omega_iff_analyticWithinAt.2 h).of_le le_top theorem contDiffWithinAt_iff_forall_nat_le {n : ℕ∞} : ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffWithinAt 𝕜 m f s x := ⟨fun H _ hm => H.of_le (mod_cast hm), fun H m hm => H m hm _ le_rfl⟩ theorem contDiffWithinAt_infty : ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top] @[deprecated (since := "2024-11-25")] alias contDiffWithinAt_top := contDiffWithinAt_infty theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) : ContinuousWithinAt f s x := by have := h.of_le (zero_le _) simp only [ContDiffWithinAt, nonpos_iff_eq_zero, Nat.cast_eq_zero, mem_pure, forall_eq, CharP.cast_eq_zero] at this rcases this with ⟨u, hu, p, H⟩ rw [mem_nhdsWithin_insert] at hu exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem_nhdsWithin hu.2 theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := by match n with | ω => obtain ⟨u, hu, p, H, H'⟩ := h exact ⟨{x ∈ u | f₁ x = f x}, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ ↦ And.right, fun i ↦ (H' i).mono (sep_subset _ _)⟩ | (n : ℕ∞) => intro m hm let ⟨u, hu, p, H⟩ := h m hm exact ⟨{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ ↦ And.right⟩ theorem Filter.EventuallyEq.congr_contDiffWithinAt (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq h₁.symm hx.symm, fun H ↦ H.congr_of_eventuallyEq h₁ hx⟩ theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁) (mem_of_mem_nhdsWithin (mem_insert x s) h₁ :) theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_insert (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq_insert h₁.symm, fun H ↦ H.congr_of_eventuallyEq_insert h₁⟩ theorem ContDiffWithinAt.congr_of_eventuallyEq_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_mem (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s): ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq_of_mem h₁.symm hx, fun H ↦ H.congr_of_eventuallyEq_of_mem h₁ hx⟩ theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx theorem contDiffWithinAt_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun h' ↦ h'.congr (fun x hx ↦ (h₁ x hx).symm) hx.symm, fun h' ↦ h'.congr h₁ hx⟩ theorem ContDiffWithinAt.congr_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr h₁ (h₁ _ hx) theorem contDiffWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr h₁ (h₁ x hx) theorem ContDiffWithinAt.congr_of_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem contDiffWithinAt_congr_of_insert (h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem ContDiffWithinAt.mono_of_mem_nhdsWithin (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by match n with | ω => obtain ⟨u, hu, p, H, H'⟩ := h exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H, H'⟩ | (n : ℕ∞) => intro m hm rcases h m hm with ⟨u, hu, p, H⟩ exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩ @[deprecated (since := "2024-10-30")] alias ContDiffWithinAt.mono_of_mem := ContDiffWithinAt.mono_of_mem_nhdsWithin theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) : ContDiffWithinAt 𝕜 n f t x := h.mono_of_mem_nhdsWithin <| Filter.mem_of_superset self_mem_nhdsWithin hst theorem ContDiffWithinAt.congr_mono (h : ContDiffWithinAt 𝕜 n f s x) (h' : EqOn f₁ f s₁) (h₁ : s₁ ⊆ s) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s₁ x := (h.mono h₁).congr h' hx theorem ContDiffWithinAt.congr_set (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f t x := by rw [← nhdsWithin_eq_iff_eventuallyEq] at hst apply h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin @[deprecated (since := "2024-10-23")] alias ContDiffWithinAt.congr_nhds := ContDiffWithinAt.congr_set theorem contDiffWithinAt_congr_set {t : Set E} (hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x := ⟨fun h => h.congr_set hst, fun h => h.congr_set hst.symm⟩ @[deprecated (since := "2024-10-23")] alias contDiffWithinAt_congr_nhds := contDiffWithinAt_congr_set theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr_set (mem_nhdsWithin_iff_eventuallyEq.1 h).symm theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h) theorem contDiffWithinAt_insert_self : ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by match n with | ω => simp [ContDiffWithinAt] | (n : ℕ∞) => simp_rw [ContDiffWithinAt, insert_idem] theorem contDiffWithinAt_insert {y : E} : ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by rcases eq_or_ne x y with (rfl | hx) · exact contDiffWithinAt_insert_self refine ⟨fun h ↦ h.mono (subset_insert _ _), fun h ↦ ?_⟩ apply h.mono_of_mem_nhdsWithin simp [nhdsWithin_insert_of_ne hx, self_mem_nhdsWithin] alias ⟨ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n f (insert x s) x := h.insert' theorem contDiffWithinAt_diff_singleton {y : E} : ContDiffWithinAt 𝕜 n f (s \ {y}) x ↔ ContDiffWithinAt 𝕜 n f s x := by rw [← contDiffWithinAt_insert, insert_diff_singleton, contDiffWithinAt_insert] /-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable within this set at this point. -/ theorem ContDiffWithinAt.differentiableWithinAt' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f (insert x s) x := by rcases contDiffWithinAt_nat.1 (h.of_le hn) with ⟨u, hu, p, H⟩ rcases mem_nhdsWithin.1 hu with ⟨t, t_open, xt, tu⟩ rw [inter_comm] at tu exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 <| ((H.mono tu).differentiableOn le_rfl) x ⟨mem_insert x s, xt⟩ theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f s x := (h.differentiableWithinAt' hn).mono (subset_insert x s) /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n` (and moreover the function is analytic when `n = ω`). -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by have h'n : n + 1 ≠ ∞ := by simpa using hn constructor · intro h rcases (contDiffWithinAt_iff_of_ne_infty h'n).1 h with ⟨u, hu, p, Hp, H'p⟩ refine ⟨u, hu, ?_, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1), fun y hy => Hp.hasFDerivWithinAt le_add_self hy, ?_⟩ · rintro rfl exact Hp.analyticOn (H'p rfl 0) apply (contDiffWithinAt_iff_of_ne_infty hn).2 refine ⟨u, ?_, fun y : E => (p y).shift, ?_⟩ · convert @self_mem_nhdsWithin _ _ x u have : x ∈ insert x s := by simp exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu) · rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp refine ⟨Hp.2.2, ?_⟩ rintro rfl i change AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryRightEquiv' 𝕜 i E F) (p x (i + 1))) u apply (LinearIsometryEquiv.analyticOnNhd _ _).comp_analyticOn ?_ (Set.mapsTo_univ _ _) exact H'p rfl _ · rintro ⟨u, hu, hf, f', f'_eq_deriv, Hf'⟩ rw [contDiffWithinAt_iff_of_ne_infty h'n] rcases (contDiffWithinAt_iff_of_ne_infty hn).1 Hf' with ⟨v, hv, p', Hp', p'_an⟩ refine ⟨v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_, ?_⟩ · apply Filter.inter_mem _ hu apply nhdsWithin_le_of_mem hu exact nhdsWithin_mono _ (subset_insert x u) hv · rw [hasFTaylorSeriesUpToOn_succ_iff_right] refine ⟨fun y _ => rfl, fun y hy => ?_, ?_⟩ · change HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z)) (FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y rw [← Function.comp_def _ f, LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] convert (f'_eq_deriv y hy.2).mono inter_subset_right rw [← Hp'.zero_eq y hy.1] ext z change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) = ((p' y 0) 0) z congr norm_num [eq_iff_true_of_subsingleton] · convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1 · ext x y change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y rw [init_snoc] · ext x k v y change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y)) (@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y rw [snoc_last, init_snoc] · intro h i simp only [WithTop.add_eq_top, WithTop.one_ne_top, or_false] at h match i with | 0 => simp only [FormalMultilinearSeries.unshift] apply AnalyticOnNhd.comp_analyticOn _ ((hf h).mono inter_subset_right) (Set.mapsTo_univ _ _) exact LinearIsometryEquiv.analyticOnNhd _ _ | i + 1 => simp only [FormalMultilinearSeries.unshift, Nat.succ_eq_add_one] apply AnalyticOnNhd.comp_analyticOn _ ((p'_an h i).mono inter_subset_left) (Set.mapsTo_univ _ _) exact LinearIsometryEquiv.analyticOnNhd _ _ /-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives are taken within the same set. -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by refine ⟨fun hf => ?_, ?_⟩ · obtain ⟨u, hu, f_an, f', huf', hf'⟩ := (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).mp hf obtain ⟨w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu rw [inter_comm] at hwu refine ⟨insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, ?_, f', fun y hy => ?_, ?_⟩ · intro h apply (f_an h).mono hwu · refine ((huf' y <| hwu hy).mono hwu).mono_of_mem_nhdsWithin ?_ refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _)) exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2) · exact hf'.mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu) · rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt hn, insert_eq_of_mem (mem_insert _ _)] rintro ⟨u, hu, hus, f_an, f', huf', hf'⟩ exact ⟨u, hu, f_an, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩ /-! ### Smooth functions within a set -/ variable (𝕜) in /-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). -/ def ContDiffOn (n : WithTop ℕ∞) (f : E → F) (s : Set E) : Prop := ∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x theorem HasFTaylorSeriesUpToOn.contDiffOn {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by intro x hx m hm use s simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and] exact ⟨f', hf.of_le (mod_cast hm)⟩ theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f s x := h x hx theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) : ContDiffOn 𝕜 m f s := fun x hx => (h x hx).of_le hmn theorem ContDiffWithinAt.contDiffOn' (hm : m ≤ n) (h' : m = ∞ → n = ω) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by rcases eq_or_ne n ω with rfl | hn · obtain ⟨t, ht, p, hp, h'p⟩ := h rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut refine ⟨u, huo, hxu, ?_⟩ suffices ContDiffOn 𝕜 ω f (insert x s ∩ u) from this.of_le le_top intro y hy refine ⟨insert x s ∩ u, ?_, p, hp.mono hut, fun i ↦ (h'p i).mono hut⟩ simp only [insert_eq_of_mem, hy, self_mem_nhdsWithin] · match m with | ω => simp [hn] at hm | ∞ => exact (hn (h' rfl)).elim | (m : ℕ) => rcases contDiffWithinAt_nat.1 (h.of_le hm) with ⟨t, ht, p, hp⟩ rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut exact ⟨u, huo, hxu, (hp.mono hut).contDiffOn⟩ theorem ContDiffWithinAt.contDiffOn (hm : m ≤ n) (h' : m = ∞ → n = ω) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := by obtain ⟨_u, uo, xu, h⟩ := h.contDiffOn' hm h' exact ⟨_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩ theorem ContDiffOn.analyticOn (h : ContDiffOn 𝕜 ω f s) : AnalyticOn 𝕜 f s := fun x hx ↦ (h x hx).analyticWithinAt /-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on a neighborhood of this point. -/ theorem contDiffWithinAt_iff_contDiffOn_nhds (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ContDiffOn 𝕜 n f u := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, h'u⟩ exact ⟨u, hu, h'u.2⟩ · rcases h with ⟨u, u_mem, hu⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert x s) u_mem exact (hu x this).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert x s) u_mem) protected theorem ContDiffWithinAt.eventually (h : ContDiffWithinAt 𝕜 n f s x) (hn : n ≠ ∞) : ∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, _, hd⟩ have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u := (eventually_eventually_nhdsWithin.2 hu).and hu refine this.mono fun y hy => (hd y hy.2).mono_of_mem_nhdsWithin ?_ exact nhdsWithin_mono y (subset_insert _ _) hy.1 theorem ContDiffOn.of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s := h.of_le le_self_add theorem ContDiffOn.one_of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s := h.of_le le_add_self theorem contDiffOn_iff_forall_nat_le {n : ℕ∞} : ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffOn 𝕜 m f s := ⟨fun H _ hm => H.of_le (mod_cast hm), fun H x hx m hm => H m hm x hx m le_rfl⟩ theorem contDiffOn_infty : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true] @[deprecated (since := "2024-11-27")] alias contDiffOn_top := contDiffOn_infty @[deprecated (since := "2024-11-27")] alias contDiffOn_infty_iff_contDiffOn_omega := contDiffOn_infty theorem contDiffOn_all_iff_nat : (∀ (n : ℕ∞), ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by refine ⟨fun H n => H n, ?_⟩ rintro H (_ | n) exacts [contDiffOn_infty.2 H, H n] theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx) theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s := ⟨fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩ theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t := fun x hx => (h x (hst hx)).mono hst
Mathlib/Analysis/Calculus/ContDiff/Defs.lean
559
605
theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) : ContDiffOn 𝕜 n f₁ s₁ := (hf.mono hs).congr h₁ /-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/ theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≤ n) : DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn /-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/ theorem contDiffOn_of_locally_contDiffOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by
intro x xs rcases h x xs with ⟨u, u_open, xu, hu⟩ apply (contDiffWithinAt_inter _).1 (hu x ⟨xs, xu⟩) exact IsOpen.mem_nhds u_open xu /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem contDiffOn_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) : ContDiffOn 𝕜 (n + 1) f s ↔ ∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by constructor · intro h x hx rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).1 (h x hx) with ⟨u, hu, f_an, f', hf', Hf'⟩ rcases Hf'.contDiffOn le_rfl (by simp [hn]) with ⟨v, vu, v'u, hv⟩ rw [insert_eq_of_mem hx] at hu ⊢ have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu rw [insert_eq_of_mem xu] at vu v'u exact ⟨v, nhdsWithin_le_of_mem hu vu, fun h ↦ (f_an h).mono v'u, f', fun y hy ↦ (hf' y (v'u hy)).mono v'u, hv⟩ · intro h x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn] rcases h x hx with ⟨u, u_nhbd, f_an, f', hu, hf'⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd exact ⟨u, u_nhbd, f_an, f', hu, hf' x this⟩ /-! ### Iterated derivative within a set -/ @[simp] theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by refine ⟨fun H => H.continuousOn, fun H => fun x hx m hm ↦ ?_⟩ have : (m : WithTop ℕ∞) = 0 := le_antisymm (mod_cast hm) bot_le rw [this] refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ rw [hasFTaylorSeriesUpToOn_zero_iff]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Sean Leather -/ import Batteries.Data.List.Perm import Mathlib.Data.List.Pairwise import Mathlib.Data.List.Nodup import Mathlib.Data.List.Lookmap import Mathlib.Data.Sigma.Basic /-! # Utilities for lists of sigmas This file includes several ways of interacting with `List (Sigma β)`, treated as a key-value store. If `α : Type*` and `β : α → Type*`, then we regard `s : Sigma β` as having key `s.1 : α` and value `s.2 : β s.1`. Hence, `List (Sigma β)` behaves like a key-value store. ## Main Definitions - `List.keys` extracts the list of keys. - `List.NodupKeys` determines if the store has duplicate keys. - `List.lookup`/`lookup_all` accesses the value(s) of a particular key. - `List.kreplace` replaces the first value with a given key by a given value. - `List.kerase` removes a value. - `List.kinsert` inserts a value. - `List.kunion` computes the union of two stores. - `List.kextract` returns a value with a given key and the rest of the values. -/ universe u u' v v' namespace List variable {α : Type u} {α' : Type u'} {β : α → Type v} {β' : α' → Type v'} {l l₁ l₂ : List (Sigma β)} /-! ### `keys` -/ /-- List of keys from a list of key-value pairs -/ def keys : List (Sigma β) → List α := map Sigma.fst @[simp] theorem keys_nil : @keys α β [] = [] := rfl @[simp] theorem keys_cons {s} {l : List (Sigma β)} : (s :: l).keys = s.1 :: l.keys := rfl theorem mem_keys_of_mem {s : Sigma β} {l : List (Sigma β)} : s ∈ l → s.1 ∈ l.keys := mem_map_of_mem theorem exists_of_mem_keys {a} {l : List (Sigma β)} (h : a ∈ l.keys) : ∃ b : β a, Sigma.mk a b ∈ l := let ⟨⟨_, b'⟩, m, e⟩ := exists_of_mem_map h Eq.recOn e (Exists.intro b' m) theorem mem_keys {a} {l : List (Sigma β)} : a ∈ l.keys ↔ ∃ b : β a, Sigma.mk a b ∈ l := ⟨exists_of_mem_keys, fun ⟨_, h⟩ => mem_keys_of_mem h⟩ theorem not_mem_keys {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ b : β a, Sigma.mk a b ∉ l := (not_congr mem_keys).trans not_exists theorem ne_key {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ s : Sigma β, s ∈ l → a ≠ s.1 := Iff.intro (fun h₁ s h₂ e => absurd (mem_keys_of_mem h₂) (by rwa [e] at h₁)) fun f h₁ => let ⟨_, h₂⟩ := exists_of_mem_keys h₁ f _ h₂ rfl @[deprecated (since := "2025-04-27")] alias not_eq_key := ne_key /-! ### `NodupKeys` -/ /-- Determines whether the store uses a key several times. -/ def NodupKeys (l : List (Sigma β)) : Prop := l.keys.Nodup theorem nodupKeys_iff_pairwise {l} : NodupKeys l ↔ Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l := pairwise_map theorem NodupKeys.pairwise_ne {l} (h : NodupKeys l) : Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l := nodupKeys_iff_pairwise.1 h @[simp] theorem nodupKeys_nil : @NodupKeys α β [] := Pairwise.nil @[simp] theorem nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} : NodupKeys (s :: l) ↔ s.1 ∉ l.keys ∧ NodupKeys l := by simp [keys, NodupKeys] theorem not_mem_keys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) : s.1 ∉ l.keys := (nodupKeys_cons.1 h).1 theorem nodupKeys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) : NodupKeys l := (nodupKeys_cons.1 h).2 theorem NodupKeys.eq_of_fst_eq {l : List (Sigma β)} (nd : NodupKeys l) {s s' : Sigma β} (h : s ∈ l) (h' : s' ∈ l) : s.1 = s'.1 → s = s' := @Pairwise.forall_of_forall _ (fun s s' : Sigma β => s.1 = s'.1 → s = s') _ (fun _ _ H h => (H h.symm).symm) (fun _ _ _ => rfl) ((nodupKeys_iff_pairwise.1 nd).imp fun h h' => (h h').elim) _ h _ h' theorem NodupKeys.eq_of_mk_mem {a : α} {b b' : β a} {l : List (Sigma β)} (nd : NodupKeys l) (h : Sigma.mk a b ∈ l) (h' : Sigma.mk a b' ∈ l) : b = b' := by cases nd.eq_of_fst_eq h h' rfl; rfl theorem nodupKeys_singleton (s : Sigma β) : NodupKeys [s] := nodup_singleton _ theorem NodupKeys.sublist {l₁ l₂ : List (Sigma β)} (h : l₁ <+ l₂) : NodupKeys l₂ → NodupKeys l₁ := Nodup.sublist <| h.map _ protected theorem NodupKeys.nodup {l : List (Sigma β)} : NodupKeys l → Nodup l := Nodup.of_map _ theorem perm_nodupKeys {l₁ l₂ : List (Sigma β)} (h : l₁ ~ l₂) : NodupKeys l₁ ↔ NodupKeys l₂ := (h.map _).nodup_iff theorem nodupKeys_flatten {L : List (List (Sigma β))} : NodupKeys (flatten L) ↔ (∀ l ∈ L, NodupKeys l) ∧ Pairwise Disjoint (L.map keys) := by rw [nodupKeys_iff_pairwise, pairwise_flatten, pairwise_map] refine and_congr (forall₂_congr fun l _ => by simp [nodupKeys_iff_pairwise]) ?_ apply iff_of_eq; congr! with (l₁ l₂) simp [keys, disjoint_iff_ne, Sigma.forall] theorem nodup_zipIdx_map_snd (l : List α) : (l.zipIdx.map Prod.snd).Nodup := by simp [List.nodup_range'] @[deprecated (since := "2025-01-28")] alias nodup_enum_map_fst := nodup_zipIdx_map_snd theorem mem_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.Nodup) (nd₁ : l₁.Nodup) (h : ∀ x, x ∈ l₀ ↔ x ∈ l₁) : l₀ ~ l₁ := (perm_ext_iff_of_nodup nd₀ nd₁).2 h variable [DecidableEq α] [DecidableEq α'] /-! ### `dlookup` -/ /-- `dlookup a l` is the first value in `l` corresponding to the key `a`, or `none` if no such element exists. -/ def dlookup (a : α) : List (Sigma β) → Option (β a) | [] => none | ⟨a', b⟩ :: l => if h : a' = a then some (Eq.recOn h b) else dlookup a l @[simp] theorem dlookup_nil (a : α) : dlookup a [] = @none (β a) := rfl @[simp] theorem dlookup_cons_eq (l) (a : α) (b : β a) : dlookup a (⟨a, b⟩ :: l) = some b := dif_pos rfl @[simp] theorem dlookup_cons_ne (l) {a} : ∀ s : Sigma β, a ≠ s.1 → dlookup a (s :: l) = dlookup a l | ⟨_, _⟩, h => dif_neg h.symm theorem dlookup_isSome {a : α} : ∀ {l : List (Sigma β)}, (dlookup a l).isSome ↔ a ∈ l.keys | [] => by simp | ⟨a', b⟩ :: l => by by_cases h : a = a' · subst a' simp · simp [h, dlookup_isSome] theorem dlookup_eq_none {a : α} {l : List (Sigma β)} : dlookup a l = none ↔ a ∉ l.keys := by simp [← dlookup_isSome, Option.isNone_iff_eq_none] theorem of_mem_dlookup {a : α} {b : β a} : ∀ {l : List (Sigma β)}, b ∈ dlookup a l → Sigma.mk a b ∈ l | ⟨a', b'⟩ :: l, H => by by_cases h : a = a' · subst a' simp? at H says simp only [dlookup_cons_eq, Option.mem_def, Option.some.injEq] at H simp [H] · simp only [ne_eq, h, not_false_iff, dlookup_cons_ne] at H simp [of_mem_dlookup H] theorem mem_dlookup {a} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) (h : Sigma.mk a b ∈ l) : b ∈ dlookup a l := by obtain ⟨b', h'⟩ := Option.isSome_iff_exists.mp (dlookup_isSome.mpr (mem_keys_of_mem h)) cases nd.eq_of_mk_mem h (of_mem_dlookup h') exact h' theorem map_dlookup_eq_find (a : α) : ∀ l : List (Sigma β), (dlookup a l).map (Sigma.mk a) = find? (fun s => a = s.1) l | [] => rfl | ⟨a', b'⟩ :: l => by by_cases h : a = a' · subst a' simp · simpa [h] using map_dlookup_eq_find a l theorem mem_dlookup_iff {a : α} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) : b ∈ dlookup a l ↔ Sigma.mk a b ∈ l := ⟨of_mem_dlookup, mem_dlookup nd⟩ theorem perm_dlookup (a : α) {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys) (p : l₁ ~ l₂) : dlookup a l₁ = dlookup a l₂ := by ext b; simp only [mem_dlookup_iff nd₁, mem_dlookup_iff nd₂]; exact p.mem_iff theorem lookup_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.NodupKeys) (nd₁ : l₁.NodupKeys) (h : ∀ x y, y ∈ l₀.dlookup x ↔ y ∈ l₁.dlookup x) : l₀ ~ l₁ := mem_ext nd₀.nodup nd₁.nodup fun ⟨a, b⟩ => by rw [← mem_dlookup_iff, ← mem_dlookup_iff, h] <;> assumption theorem dlookup_map (l : List (Sigma β)) {f : α → α'} (hf : Function.Injective f) (g : ∀ a, β a → β' (f a)) (a : α) : (l.map fun x => ⟨f x.1, g _ x.2⟩).dlookup (f a) = (l.dlookup a).map (g a) := by induction' l with b l IH · rw [map_nil, dlookup_nil, dlookup_nil, Option.map_none'] · rw [map_cons] obtain rfl | h := eq_or_ne a b.1 · rw [dlookup_cons_eq, dlookup_cons_eq, Option.map_some'] · rw [dlookup_cons_ne _ _ h, dlookup_cons_ne _ _ (fun he => h <| hf he), IH] theorem dlookup_map₁ {β : Type v} (l : List (Σ _ : α, β)) {f : α → α'} (hf : Function.Injective f) (a : α) : (l.map fun x => ⟨f x.1, x.2⟩ : List (Σ _ : α', β)).dlookup (f a) = l.dlookup a := by rw [dlookup_map (β' := fun _ => β) l hf (fun _ x => x) a, Option.map_id'] theorem dlookup_map₂ {γ δ : α → Type*} {l : List (Σ a, γ a)} {f : ∀ a, γ a → δ a} (a : α) : (l.map fun x => ⟨x.1, f _ x.2⟩ : List (Σ a, δ a)).dlookup a = (l.dlookup a).map (f a) := dlookup_map l Function.injective_id _ _ /-! ### `lookupAll` -/ /-- `lookup_all a l` is the list of all values in `l` corresponding to the key `a`. -/ def lookupAll (a : α) : List (Sigma β) → List (β a) | [] => [] | ⟨a', b⟩ :: l => if h : a' = a then Eq.recOn h b :: lookupAll a l else lookupAll a l @[simp] theorem lookupAll_nil (a : α) : lookupAll a [] = @nil (β a) := rfl @[simp] theorem lookupAll_cons_eq (l) (a : α) (b : β a) : lookupAll a (⟨a, b⟩ :: l) = b :: lookupAll a l := dif_pos rfl @[simp] theorem lookupAll_cons_ne (l) {a} : ∀ s : Sigma β, a ≠ s.1 → lookupAll a (s :: l) = lookupAll a l | ⟨_, _⟩, h => dif_neg h.symm theorem lookupAll_eq_nil {a : α} : ∀ {l : List (Sigma β)}, lookupAll a l = [] ↔ ∀ b : β a, Sigma.mk a b ∉ l | [] => by simp | ⟨a', b⟩ :: l => by by_cases h : a = a' · subst a' simp only [lookupAll_cons_eq, mem_cons, Sigma.mk.inj_iff, heq_eq_eq, true_and, not_or, false_iff, not_forall, not_and, not_not, reduceCtorEq] use b simp · simp [h, lookupAll_eq_nil] theorem head?_lookupAll (a : α) : ∀ l : List (Sigma β), head? (lookupAll a l) = dlookup a l | [] => by simp | ⟨a', b⟩ :: l => by by_cases h : a = a' · subst h; simp · rw [lookupAll_cons_ne, dlookup_cons_ne, head?_lookupAll a l] <;> assumption theorem mem_lookupAll {a : α} {b : β a} : ∀ {l : List (Sigma β)}, b ∈ lookupAll a l ↔ Sigma.mk a b ∈ l | [] => by simp | ⟨a', b'⟩ :: l => by by_cases h : a = a' · subst h simp [*, mem_lookupAll] · simp [*, mem_lookupAll] theorem lookupAll_sublist (a : α) : ∀ l : List (Sigma β), (lookupAll a l).map (Sigma.mk a) <+ l | [] => by simp | ⟨a', b'⟩ :: l => by by_cases h : a = a' · subst h simp only [ne_eq, not_true, lookupAll_cons_eq, List.map] exact (lookupAll_sublist a l).cons₂ _ · simp only [ne_eq, h, not_false_iff, lookupAll_cons_ne] exact (lookupAll_sublist a l).cons _ theorem lookupAll_length_le_one (a : α) {l : List (Sigma β)} (h : l.NodupKeys) : length (lookupAll a l) ≤ 1 := by have := Nodup.sublist ((lookupAll_sublist a l).map _) h rw [map_map] at this rwa [← nodup_replicate, ← map_const] theorem lookupAll_eq_dlookup (a : α) {l : List (Sigma β)} (h : l.NodupKeys) : lookupAll a l = (dlookup a l).toList := by rw [← head?_lookupAll] have h1 := lookupAll_length_le_one a h; revert h1 rcases lookupAll a l with (_ | ⟨b, _ | ⟨c, l⟩⟩) <;> intro h1 <;> try rfl exact absurd h1 (by simp) theorem lookupAll_nodup (a : α) {l : List (Sigma β)} (h : l.NodupKeys) : (lookupAll a l).Nodup := by (rw [lookupAll_eq_dlookup a h]; apply Option.toList_nodup) theorem perm_lookupAll (a : α) {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys) (p : l₁ ~ l₂) : lookupAll a l₁ = lookupAll a l₂ := by simp [lookupAll_eq_dlookup, nd₁, nd₂, perm_dlookup a nd₁ nd₂ p]
Mathlib/Data/List/Sigma.lean
311
315
theorem dlookup_append (l₁ l₂ : List (Sigma β)) (a : α) : (l₁ ++ l₂).dlookup a = (l₁.dlookup a).or (l₂.dlookup a) := by
induction l₁ with | nil => rfl | cons x l₁ IH =>
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Integral.Bochner.Basic import Mathlib.MeasureTheory.Group.Measure /-! # Bochner Integration on Groups We develop properties of integrals with a group as domain. This file contains properties about integrability and Bochner integration. -/ namespace MeasureTheory open Measure TopologicalSpace open scoped ENNReal variable {𝕜 M α G E F : Type*} [MeasurableSpace G] variable [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] variable {μ : Measure G} {f : G → E} {g : G} section MeasurableInv variable [Group G] [MeasurableInv G] @[to_additive] theorem Integrable.comp_inv [IsInvInvariant μ] {f : G → F} (hf : Integrable f μ) : Integrable (fun t => f t⁻¹) μ := (hf.mono_measure (map_inv_eq_self μ).le).comp_measurable measurable_inv @[to_additive] theorem integral_inv_eq_self (f : G → E) (μ : Measure G) [IsInvInvariant μ] : ∫ x, f x⁻¹ ∂μ = ∫ x, f x ∂μ := by have h : MeasurableEmbedding fun x : G => x⁻¹ := (MeasurableEquiv.inv G).measurableEmbedding rw [← h.integral_map, map_inv_eq_self] @[to_additive] theorem IntegrableOn.comp_inv [IsInvInvariant μ] {f : G → F} {s : Set G} (hf : IntegrableOn f s μ) : IntegrableOn (fun x => f x⁻¹) s⁻¹ μ := by apply (integrable_map_equiv (MeasurableEquiv.inv G) f).mp have : s⁻¹ = MeasurableEquiv.inv G ⁻¹' s := by simp rw [this, ← MeasurableEquiv.restrict_map] simpa using hf end MeasurableInv section MeasurableInvOrder variable [PartialOrder G] [CommGroup G] [IsOrderedMonoid G] [MeasurableInv G] variable [IsInvInvariant μ] @[to_additive] theorem IntegrableOn.comp_inv_Iic {c : G} {f : G → F} (hf : IntegrableOn f (Set.Ici c⁻¹) μ) : IntegrableOn (fun x => f x⁻¹) (Set.Iic c) μ := by simpa using hf.comp_inv @[to_additive] theorem IntegrableOn.comp_inv_Ici {c : G} {f : G → F} (hf : IntegrableOn f (Set.Iic c⁻¹) μ) : IntegrableOn (fun x => f x⁻¹) (Set.Ici c) μ := by simpa using hf.comp_inv @[to_additive] theorem IntegrableOn.comp_inv_Iio {c : G} {f : G → F} (hf : IntegrableOn f (Set.Ioi c⁻¹) μ) : IntegrableOn (fun x => f x⁻¹) (Set.Iio c) μ := by simpa using hf.comp_inv @[to_additive] theorem IntegrableOn.comp_inv_Ioi {c : G} {f : G → F} (hf : IntegrableOn f (Set.Iio c⁻¹) μ) : IntegrableOn (fun x => f x⁻¹) (Set.Ioi c) μ := by simpa using hf.comp_inv end MeasurableInvOrder section MeasurableMul variable [Group G] [MeasurableMul G] /-- Translating a function by left-multiplication does not change its integral with respect to a left-invariant measure. -/ @[to_additive "Translating a function by left-addition does not change its integral with respect to a left-invariant measure."] theorem integral_mul_left_eq_self [IsMulLeftInvariant μ] (f : G → E) (g : G) : (∫ x, f (g * x) ∂μ) = ∫ x, f x ∂μ := by have h_mul : MeasurableEmbedding fun x => g * x := (MeasurableEquiv.mulLeft g).measurableEmbedding rw [← h_mul.integral_map, map_mul_left_eq_self] /-- Translating a function by right-multiplication does not change its integral with respect to a right-invariant measure. -/ @[to_additive "Translating a function by right-addition does not change its integral with respect to a right-invariant measure."] theorem integral_mul_right_eq_self [IsMulRightInvariant μ] (f : G → E) (g : G) : (∫ x, f (x * g) ∂μ) = ∫ x, f x ∂μ := by have h_mul : MeasurableEmbedding fun x => x * g := (MeasurableEquiv.mulRight g).measurableEmbedding rw [← h_mul.integral_map, map_mul_right_eq_self] @[to_additive] theorem integral_div_right_eq_self [IsMulRightInvariant μ] (f : G → E) (g : G) : (∫ x, f (x / g) ∂μ) = ∫ x, f x ∂μ := by simp_rw [div_eq_mul_inv, integral_mul_right_eq_self f g⁻¹] /-- If some left-translate of a function negates it, then the integral of the function with respect to a left-invariant measure is 0. -/ @[to_additive "If some left-translate of a function negates it, then the integral of the function with respect to a left-invariant measure is 0."] theorem integral_eq_zero_of_mul_left_eq_neg [IsMulLeftInvariant μ] (hf' : ∀ x, f (g * x) = -f x) : ∫ x, f x ∂μ = 0 := by simp_rw [← self_eq_neg ℝ E, ← integral_neg, ← hf', integral_mul_left_eq_self] /-- If some right-translate of a function negates it, then the integral of the function with respect to a right-invariant measure is 0. -/ @[to_additive "If some right-translate of a function negates it, then the integral of the function with respect to a right-invariant measure is 0."] theorem integral_eq_zero_of_mul_right_eq_neg [IsMulRightInvariant μ] (hf' : ∀ x, f (x * g) = -f x) : ∫ x, f x ∂μ = 0 := by simp_rw [← self_eq_neg ℝ E, ← integral_neg, ← hf', integral_mul_right_eq_self] @[to_additive] theorem Integrable.comp_mul_left {f : G → F} [IsMulLeftInvariant μ] (hf : Integrable f μ) (g : G) : Integrable (fun t => f (g * t)) μ := (hf.mono_measure (map_mul_left_eq_self μ g).le).comp_measurable <| measurable_const_mul g @[to_additive] theorem Integrable.comp_mul_right {f : G → F} [IsMulRightInvariant μ] (hf : Integrable f μ) (g : G) : Integrable (fun t => f (t * g)) μ := (hf.mono_measure (map_mul_right_eq_self μ g).le).comp_measurable <| measurable_mul_const g @[to_additive] theorem Integrable.comp_div_right {f : G → F} [IsMulRightInvariant μ] (hf : Integrable f μ) (g : G) : Integrable (fun t => f (t / g)) μ := by simp_rw [div_eq_mul_inv] exact hf.comp_mul_right g⁻¹ variable [MeasurableInv G] @[to_additive] theorem Integrable.comp_div_left {f : G → F} [IsInvInvariant μ] [IsMulLeftInvariant μ] (hf : Integrable f μ) (g : G) : Integrable (fun t => f (g / t)) μ := ((measurePreserving_div_left μ g).integrable_comp hf.aestronglyMeasurable).mpr hf @[to_additive]
Mathlib/MeasureTheory/Group/Integral.lean
150
154
theorem integrable_comp_div_left (f : G → F) [IsInvInvariant μ] [IsMulLeftInvariant μ] (g : G) : Integrable (fun t => f (g / t)) μ ↔ Integrable f μ := by
refine ⟨fun h => ?_, fun h => h.comp_div_left g⟩ convert h.comp_inv.comp_mul_left g⁻¹ simp_rw [div_inv_eq_mul, mul_inv_cancel_left]
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Data.NNReal.Basic import Mathlib.Topology.Algebra.Support import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.Order.Real /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 /-- Auxiliary class, endowing a type `α` with a function `enorm : α → ℝ≥0∞` with notation `‖x‖ₑ`. -/ @[notation_class] class ENorm (E : Type*) where /-- the `ℝ≥0∞`-valued norm function. -/ enorm : E → ℝ≥0∞ export Norm (norm) export NNNorm (nnnorm) export ENorm (enorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e @[inherit_doc] notation "‖" e "‖ₑ" => enorm e section ENorm variable {E : Type*} [NNNorm E] {x : E} {r : ℝ≥0} instance NNNorm.toENorm : ENorm E where enorm := (‖·‖₊ : E → ℝ≥0∞) lemma enorm_eq_nnnorm (x : E) : ‖x‖ₑ = ‖x‖₊ := rfl @[simp] lemma toNNReal_enorm (x : E) : ‖x‖ₑ.toNNReal = ‖x‖₊ := rfl @[simp, norm_cast] lemma coe_le_enorm : r ≤ ‖x‖ₑ ↔ r ≤ ‖x‖₊ := by simp [enorm] @[simp, norm_cast] lemma enorm_le_coe : ‖x‖ₑ ≤ r ↔ ‖x‖₊ ≤ r := by simp [enorm] @[simp, norm_cast] lemma coe_lt_enorm : r < ‖x‖ₑ ↔ r < ‖x‖₊ := by simp [enorm] @[simp, norm_cast] lemma enorm_lt_coe : ‖x‖ₑ < r ↔ ‖x‖₊ < r := by simp [enorm] @[simp] lemma enorm_ne_top : ‖x‖ₑ ≠ ∞ := by simp [enorm] @[simp] lemma enorm_lt_top : ‖x‖ₑ < ∞ := by simp [enorm] end ENorm /-- A type `E` equipped with a continuous map `‖·‖ₑ : E → ℝ≥0∞` NB. We do not demand that the topology is somehow defined by the enorm: for ℝ≥0∞ (the motivating example behind this definition), this is not true. -/ class ContinuousENorm (E : Type*) [TopologicalSpace E] extends ENorm E where continuous_enorm : Continuous enorm /-- An enormed monoid is an additive monoid endowed with a continuous enorm. -/ class ENormedAddMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, AddMonoid E where enorm_eq_zero : ∀ x : E, ‖x‖ₑ = 0 ↔ x = 0 protected enorm_add_le : ∀ x y : E, ‖x + y‖ₑ ≤ ‖x‖ₑ + ‖y‖ₑ /-- An enormed monoid is a monoid endowed with a continuous enorm. -/ @[to_additive] class ENormedMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, Monoid E where enorm_eq_zero : ∀ x : E, ‖x‖ₑ = 0 ↔ x = 1 enorm_mul_le : ∀ x y : E, ‖x * y‖ₑ ≤ ‖x‖ₑ + ‖y‖ₑ /-- An enormed commutative monoid is an additive commutative monoid endowed with a continuous enorm. We don't have `ENormedAddCommMonoid` extend `EMetricSpace`, since the canonical instance `ℝ≥0∞` is not an `EMetricSpace`. This is because `ℝ≥0∞` carries the order topology, which is distinct from the topology coming from `edist`. -/ class ENormedAddCommMonoid (E : Type*) [TopologicalSpace E] extends ENormedAddMonoid E, AddCommMonoid E where /-- An enormed commutative monoid is a commutative monoid endowed with a continuous enorm. -/ @[to_additive] class ENormedCommMonoid (E : Type*) [TopologicalSpace E] extends ENormedMonoid E, CommMonoid E where /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] abbrev NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] abbrev NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive "Construct a seminormed group from a translation-invariant distance."] abbrev SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_inv_cancel y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_inv_cancel y] using h₂ _ _ _ -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive "Construct a normed group from a translation-invariant distance."] abbrev NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq _ _ := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b c : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] alias dist_eq_norm := dist_eq_norm_sub alias dist_eq_norm' := dist_eq_norm_sub' @[to_additive of_forall_le_norm] lemma DiscreteTopology.of_forall_le_norm' (hpos : 0 < r) (hr : ∀ x : E, x ≠ 1 → r ≤ ‖x‖) : DiscreteTopology E := .of_forall_le_dist hpos fun x y hne ↦ by simp only [dist_eq_norm_div] exact hr _ (div_ne_one.2 hne) @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] @[to_additive]
Mathlib/Analysis/Normed/Group/Basic.lean
407
412
theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by
rw [Metric.inseparable_iff, dist_one_right] @[to_additive] lemma dist_one_left (a : E) : dist 1 a = ‖a‖ := by rw [dist_comm, dist_one_right]
/- 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, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.Comap import Mathlib.MeasureTheory.Measure.QuasiMeasurePreserving /-! # Restricting a measure to a subset or a subtype Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as the restriction of `μ` to `s` (still as a measure on `α`). We investigate how this notion interacts with usual operations on measures (sum, pushforward, pullback), and on sets (inclusion, union, Union). We also study the relationship between the restriction of a measure to a subtype (given by the pullback under `Subtype.val`) and the restriction to a set as above. -/ open scoped ENNReal NNReal Topology open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function variable {R α β δ γ ι : Type*} namespace MeasureTheory variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-! ### Restricting a measure -/ /-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/ noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α := liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc] exact le_toOuterMeasure_caratheodory _ _ hs' _ /-- Restrict a measure `μ` to a set `s`. -/ noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α := restrictₗ s μ @[simp] theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) : restrictₗ s μ = μ.restrict s := rfl /-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a restrict on measures and the RHS has a restrict on outer measures. -/ theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) : (μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk, toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed] theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply, coe_toOuterMeasure] /-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s` be measurable instead of `t` exists as `Measure.restrict_apply'`. -/ @[simp] theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) := restrict_apply₀ ht.nullMeasurableSet /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s') (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩) _ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s') _ = ν.restrict s' t := (restrict_apply ht).symm /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ @[mono, gcongr] theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := restrict_mono' (ae_of_all _ hs) hμν @[gcongr] theorem restrict_mono_measure {_ : MeasurableSpace α} {μ ν : Measure α} (h : μ ≤ ν) (s : Set α) : μ.restrict s ≤ ν.restrict s := restrict_mono subset_rfl h @[gcongr] theorem restrict_mono_set {_ : MeasurableSpace α} (μ : Measure α) {s t : Set α} (h : s ⊆ t) : μ.restrict s ≤ μ.restrict t := restrict_mono h le_rfl theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t := restrict_mono' h (le_refl μ) theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t := le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le) /-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of `Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/ @[simp] theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by rw [← toOuterMeasure_apply, Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs, OuterMeasure.restrict_apply s t _, toOuterMeasure_apply] theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by rw [← restrict_congr_set hs.toMeasurable_ae_eq, restrict_apply' (measurableSet_toMeasurable _ _), measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)] theorem restrict_le_self : μ.restrict s ≤ μ := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ t := measure_mono inter_subset_left variable (μ) theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s := (le_iff'.1 restrict_le_self s).antisymm <| calc μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) := measure_mono (subset_inter (subset_toMeasurable _ _) h) _ = μ.restrict t s := by rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable] @[simp] theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s := restrict_eq_self μ Subset.rfl variable {μ} theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by rw [restrict_apply MeasurableSet.univ, Set.univ_inter] theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t := calc μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm _ ≤ μ.restrict s t := measure_mono inter_subset_left theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t := Measure.le_iff'.1 restrict_le_self _ theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s := ((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm ((restrict_apply_self μ s).symm.trans_le <| measure_mono h) @[simp] theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) : (μ + ν).restrict s = μ.restrict s + ν.restrict s := (restrictₗ s).map_add μ ν @[simp] theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 := (restrictₗ s).map_zero @[simp] theorem restrict_smul {_m0 : MeasurableSpace α} {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) (μ : Measure α) (s : Set α) : (c • μ).restrict s = c • μ.restrict s := by simpa only [smul_one_smul] using (restrictₗ s).map_smul (c • 1) μ theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [Set.inter_assoc, restrict_apply hu, restrict_apply₀ (hu.nullMeasurableSet.inter hs)] @[simp] theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀ hs.nullMeasurableSet theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by ext1 u hu rw [restrict_apply hu, restrict_apply hu, restrict_eq_self] exact inter_subset_right.trans h theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc] theorem restrict_restrict' (ht : MeasurableSet t) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀' ht.nullMeasurableSet theorem restrict_comm (hs : MeasurableSet s) : (μ.restrict t).restrict s = (μ.restrict s).restrict t := by rw [restrict_restrict hs, restrict_restrict' hs, inter_comm] theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply ht] theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 := nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _) theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply' hs] @[simp] theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by rw [← measure_univ_eq_zero, restrict_apply_univ] /-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/ instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) := ⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩ theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 := restrict_eq_zero.2 h @[simp] theorem restrict_empty : μ.restrict ∅ = 0 := restrict_zero_set measure_empty @[simp] theorem restrict_univ : μ.restrict univ = μ := ext fun s hs => by simp [hs]
Mathlib/MeasureTheory/Measure/Restrict.lean
221
222
theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) : μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by
/- Copyright (c) 2024 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.MeasureTheory.Integral.PeakFunction import Mathlib.Analysis.SpecialFunctions.Gaussian.FourierTransform /-! # Fourier inversion formula In a finite-dimensional real inner product space, we show the Fourier inversion formula, i.e., `𝓕⁻ (𝓕 f) v = f v` if `f` and `𝓕 f` are integrable, and `f` is continuous at `v`. This is proved in `MeasureTheory.Integrable.fourier_inversion`. See also `Continuous.fourier_inversion` giving `𝓕⁻ (𝓕 f) = f` under an additional continuity assumption for `f`. We use the following proof. A naïve computation gives `𝓕⁻ (𝓕 f) v = ∫_w exp (2 I π ⟪w, v⟫) 𝓕 f (w) dw = ∫_w exp (2 I π ⟪w, v⟫) ∫_x, exp (-2 I π ⟪w, x⟫) f x dx) dw = ∫_x (∫_ w, exp (2 I π ⟪w, v - x⟫ dw) f x dx ` However, the Fubini step does not make sense for lack of integrability, and the middle integral `∫_ w, exp (2 I π ⟪w, v - x⟫ dw` (which one would like to be a Dirac at `v - x`) is not defined. To gain integrability, one multiplies with a Gaussian function `exp (-c⁻¹ ‖w‖^2)`, with a large (but finite) `c`. As this function converges pointwise to `1` when `c → ∞`, we get `∫_w exp (2 I π ⟪w, v⟫) 𝓕 f (w) dw = lim_c ∫_w exp (-c⁻¹ ‖w‖^2 + 2 I π ⟪w, v⟫) 𝓕 f (w) dw`. One can perform Fubini on the right hand side for fixed `c`, writing the integral as `∫_x (∫_w exp (-c⁻¹‖w‖^2 + 2 I π ⟪w, v - x⟫ dw)) f x dx`. The middle factor is the Fourier transform of a more and more flat function (converging to the constant `1`), hence it becomes more and more concentrated, around the point `v`. (Morally, it converges to the Dirac at `v`). Moreover, it has integral one. Therefore, multiplying by `f` and integrating, one gets a term converging to `f v` as `c → ∞`. Since it also converges to `𝓕⁻ (𝓕 f) v`, this proves the result. To check the concentration property of the middle factor and the fact that it has integral one, we rely on the explicit computation of the Fourier transform of Gaussians. -/ open Filter MeasureTheory Complex Module Metric Real Bornology open scoped Topology FourierTransform RealInnerProductSpace Complex variable {V E : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MeasurableSpace V] [BorelSpace V] [FiniteDimensional ℝ V] [NormedAddCommGroup E] [NormedSpace ℂ E] {f : V → E} namespace Real lemma tendsto_integral_cexp_sq_smul (hf : Integrable f) : Tendsto (fun (c : ℝ) ↦ (∫ v : V, cexp (- c⁻¹ * ‖v‖^2) • f v)) atTop (𝓝 (∫ v : V, f v)) := by apply tendsto_integral_filter_of_dominated_convergence _ _ _ hf.norm · filter_upwards with v nth_rewrite 2 [show f v = cexp (- (0 : ℝ) * ‖v‖^2) • f v by simp] apply (Tendsto.cexp _).smul_const exact tendsto_inv_atTop_zero.ofReal.neg.mul_const _ · filter_upwards with c using AEStronglyMeasurable.smul (Continuous.aestronglyMeasurable (by fun_prop)) hf.1 · filter_upwards [Ici_mem_atTop (0 : ℝ)] with c (hc : 0 ≤ c) filter_upwards with v simp only [ofReal_inv, neg_mul, norm_smul] norm_cast conv_rhs => rw [← one_mul (‖f v‖)] gcongr simp only [norm_eq_abs, abs_exp, exp_le_one_iff, Left.neg_nonpos_iff] positivity variable [CompleteSpace E] lemma tendsto_integral_gaussian_smul (hf : Integrable f) (h'f : Integrable (𝓕 f)) (v : V) : Tendsto (fun (c : ℝ) ↦ ∫ w : V, ((π * c) ^ (finrank ℝ V / 2 : ℂ) * cexp (-π ^ 2 * c * ‖v - w‖ ^ 2)) • f w) atTop (𝓝 (𝓕⁻ (𝓕 f) v)) := by have A : Tendsto (fun (c : ℝ) ↦ (∫ w : V, cexp (- c⁻¹ * ‖w‖^2 + 2 * π * I * ⟪v, w⟫) • (𝓕 f) w)) atTop (𝓝 (𝓕⁻ (𝓕 f) v)) := by have : Integrable (fun w ↦ 𝐞 ⟪w, v⟫ • (𝓕 f) w) := by have B : Continuous fun p : V × V => (- innerₗ V) p.1 p.2 := continuous_inner.neg simpa using (VectorFourier.fourierIntegral_convergent_iff Real.continuous_fourierChar B v).2 h'f convert tendsto_integral_cexp_sq_smul this using 4 with c w · rw [Submonoid.smul_def, Real.fourierChar_apply, smul_smul, ← Complex.exp_add, real_inner_comm] congr 3 simp only [ofReal_mul, ofReal_ofNat] ring · simp [fourierIntegralInv_eq] have B : Tendsto (fun (c : ℝ) ↦ (∫ w : V, 𝓕 (fun w ↦ cexp (- c⁻¹ * ‖w‖^2 + 2 * π * I * ⟪v, w⟫)) w • f w)) atTop (𝓝 (𝓕⁻ (𝓕 f) v)) := by apply A.congr' filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c) have J : Integrable (fun w ↦ cexp (- c⁻¹ * ‖w‖^2 + 2 * π * I * ⟪v, w⟫)) := GaussianFourier.integrable_cexp_neg_mul_sq_norm_add (by simpa) _ _ simpa using (VectorFourier.integral_fourierIntegral_smul_eq_flip (L := innerₗ V) Real.continuous_fourierChar continuous_inner J hf).symm apply B.congr' filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c) congr with w rw [fourierIntegral_gaussian_innerProductSpace' (by simpa)] congr · simp · simp; ring lemma tendsto_integral_gaussian_smul' (hf : Integrable f) {v : V} (h'f : ContinuousAt f v) : Tendsto (fun (c : ℝ) ↦ ∫ w : V, ((π * c : ℂ) ^ (finrank ℝ V / 2 : ℂ) * cexp (-π ^ 2 * c * ‖v - w‖ ^ 2)) • f w) atTop (𝓝 (f v)) := by let φ : V → ℝ := fun w ↦ π ^ (finrank ℝ V / 2 : ℝ) * Real.exp (-π^2 * ‖w‖^2) have A : Tendsto (fun (c : ℝ) ↦ ∫ w : V, (c ^ finrank ℝ V * φ (c • (v - w))) • f w) atTop (𝓝 (f v)) := by apply tendsto_integral_comp_smul_smul_of_integrable' · exact fun x ↦ by positivity · rw [integral_const_mul, GaussianFourier.integral_rexp_neg_mul_sq_norm (by positivity)] nth_rewrite 2 [← pow_one π] rw [← rpow_natCast, ← rpow_natCast, ← rpow_sub pi_pos, ← rpow_mul pi_nonneg, ← rpow_add pi_pos] ring_nf exact rpow_zero _ · have A : Tendsto (fun (w : V) ↦ π^2 * ‖w‖^2) (cobounded V) atTop := by rw [tendsto_const_mul_atTop_of_pos (by positivity)] apply (tendsto_pow_atTop two_ne_zero).comp tendsto_norm_cobounded_atTop have B := tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (finrank ℝ V / 2) 1 zero_lt_one |>.comp A |>.const_mul (π ^ (-finrank ℝ V / 2 : ℝ)) rw [mul_zero] at B convert B using 2 with x simp only [neg_mul, one_mul, Function.comp_apply, ← mul_assoc, ← rpow_natCast, φ] congr 1 rw [mul_rpow (by positivity) (by positivity), ← rpow_mul pi_nonneg, ← rpow_mul (norm_nonneg _), ← mul_assoc, ← rpow_add pi_pos, mul_comm] congr <;> ring · exact hf · exact h'f have B : Tendsto (fun (c : ℝ) ↦ ∫ w : V, ((c^(1/2 : ℝ)) ^ finrank ℝ V * φ ((c^(1/2 : ℝ)) • (v - w))) • f w) atTop (𝓝 (f v)) := A.comp (tendsto_rpow_atTop (by norm_num)) apply B.congr' filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c) congr with w rw [← coe_smul] congr rw [ofReal_mul, ofReal_mul, ofReal_exp, ← mul_assoc] congr · rw [mul_cpow_ofReal_nonneg pi_nonneg hc.le, ← rpow_natCast, ← rpow_mul hc.le, mul_comm, ofReal_cpow pi_nonneg, ofReal_cpow hc.le] simp [div_eq_inv_mul] · norm_cast simp only [one_div, norm_smul, Real.norm_eq_abs, mul_pow, sq_abs, neg_mul, neg_inj, ← rpow_natCast, ← rpow_mul hc.le, mul_assoc] norm_num end Real variable [CompleteSpace E] /-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product space is integrable, and its Fourier transform `𝓕 f` is also integrable, then `𝓕⁻ (𝓕 f) = f` at continuity points of `f`. -/ theorem MeasureTheory.Integrable.fourier_inversion (hf : Integrable f) (h'f : Integrable (𝓕 f)) {v : V} (hv : ContinuousAt f v) : 𝓕⁻ (𝓕 f) v = f v := tendsto_nhds_unique (Real.tendsto_integral_gaussian_smul hf h'f v) (Real.tendsto_integral_gaussian_smul' hf hv) /-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product space is continuous, integrable, and its Fourier transform `𝓕 f` is also integrable, then `𝓕⁻ (𝓕 f) = f`. -/ theorem Continuous.fourier_inversion (h : Continuous f) (hf : Integrable f) (h'f : Integrable (𝓕 f)) : 𝓕⁻ (𝓕 f) = f := by ext v exact hf.fourier_inversion h'f h.continuousAt /-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product space is integrable, and its Fourier transform `𝓕 f` is also integrable, then `𝓕 (𝓕⁻ f) = f` at continuity points of `f`. -/
Mathlib/Analysis/Fourier/Inversion.lean
177
181
theorem MeasureTheory.Integrable.fourier_inversion_inv (hf : Integrable f) (h'f : Integrable (𝓕 f)) {v : V} (hv : ContinuousAt f v) : 𝓕 (𝓕⁻ f) v = f v := by
rw [fourierIntegralInv_comm] exact fourier_inversion hf h'f hv
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Field.IsField import Mathlib.Algebra.Polynomial.Inductions import Mathlib.Algebra.Polynomial.Monic import Mathlib.Algebra.Ring.Regular import Mathlib.RingTheory.Multiplicity import Mathlib.Data.Nat.Lattice /-! # Division of univariate polynomials The main defs are `divByMonic` and `modByMonic`. The compatibility between these is given by `modByMonic_add_div`. We also define `rootMultiplicity`. -/ noncomputable section open Polynomial open Finset namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : ℕ} section Semiring variable [Semiring R] theorem X_dvd_iff {f : R[X]} : X ∣ f ↔ f.coeff 0 = 0 := ⟨fun ⟨g, hfg⟩ => by rw [hfg, coeff_X_mul_zero], fun hf => ⟨f.divX, by rw [← add_zero (X * f.divX), ← C_0, ← hf, X_mul_divX_add]⟩⟩ theorem X_pow_dvd_iff {f : R[X]} {n : ℕ} : X ^ n ∣ f ↔ ∀ d < n, f.coeff d = 0 := ⟨fun ⟨g, hgf⟩ d hd => by simp only [hgf, coeff_X_pow_mul', ite_eq_right_iff, not_le_of_lt hd, IsEmpty.forall_iff], fun hd => by induction n with | zero => simp [pow_zero, one_dvd] | succ n hn => obtain ⟨g, hgf⟩ := hn fun d : ℕ => fun H : d < n => hd _ (Nat.lt_succ_of_lt H) have := coeff_X_pow_mul g n 0 rw [zero_add, ← hgf, hd n (Nat.lt_succ_self n)] at this obtain ⟨k, hgk⟩ := Polynomial.X_dvd_iff.mpr this.symm use k rwa [pow_succ, mul_assoc, ← hgk]⟩ variable {p q : R[X]} theorem finiteMultiplicity_of_degree_pos_of_monic (hp : (0 : WithBot ℕ) < degree p) (hmp : Monic p) (hq : q ≠ 0) : FiniteMultiplicity p q := have zn0 : (0 : R) ≠ 1 := haveI := Nontrivial.of_polynomial_ne hq zero_ne_one ⟨natDegree q, fun ⟨r, hr⟩ => by have hp0 : p ≠ 0 := fun hp0 => by simp [hp0] at hp have hr0 : r ≠ 0 := fun hr0 => by subst hr0; simp [hq] at hr have hpn1 : leadingCoeff p ^ (natDegree q + 1) = 1 := by simp [show _ = _ from hmp] have hpn0' : leadingCoeff p ^ (natDegree q + 1) ≠ 0 := hpn1.symm ▸ zn0.symm have hpnr0 : leadingCoeff (p ^ (natDegree q + 1)) * leadingCoeff r ≠ 0 := by simp only [leadingCoeff_pow' hpn0', leadingCoeff_eq_zero, hpn1, one_pow, one_mul, Ne, hr0, not_false_eq_true] have hnp : 0 < natDegree p := Nat.cast_lt.1 <| by rw [← degree_eq_natDegree hp0]; exact hp have := congr_arg natDegree hr rw [natDegree_mul' hpnr0, natDegree_pow' hpn0', add_mul, add_assoc] at this exact ne_of_lt (lt_add_of_le_of_pos (le_mul_of_one_le_right (Nat.zero_le _) hnp) (add_pos_of_pos_of_nonneg (by rwa [one_mul]) (Nat.zero_le _))) this⟩ @[deprecated (since := "2024-11-30")] alias multiplicity_finite_of_degree_pos_of_monic := finiteMultiplicity_of_degree_pos_of_monic end Semiring section Ring variable [Ring R] {p q : R[X]} theorem div_wf_lemma (h : degree q ≤ degree p ∧ p ≠ 0) (hq : Monic q) : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p := have hp : leadingCoeff p ≠ 0 := mt leadingCoeff_eq_zero.1 h.2 have hq0 : q ≠ 0 := hq.ne_zero_of_polynomial_ne h.2 have hlt : natDegree q ≤ natDegree p := (Nat.cast_le (α := WithBot ℕ)).1 (by rw [← degree_eq_natDegree h.2, ← degree_eq_natDegree hq0]; exact h.1) degree_sub_lt (by rw [hq.degree_mul_comm, hq.degree_mul, degree_C_mul_X_pow _ hp, degree_eq_natDegree h.2, degree_eq_natDegree hq0, ← Nat.cast_add, tsub_add_cancel_of_le hlt]) h.2 (by rw [leadingCoeff_monic_mul hq, leadingCoeff_mul_X_pow, leadingCoeff_C]) /-- See `divByMonic`. -/ noncomputable def divModByMonicAux : ∀ (_p : R[X]) {q : R[X]}, Monic q → R[X] × R[X] | p, q, hq => letI := Classical.decEq R if h : degree q ≤ degree p ∧ p ≠ 0 then let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree q) have _wf := div_wf_lemma h hq let dm := divModByMonicAux (p - q * z) hq ⟨z + dm.1, dm.2⟩ else ⟨0, p⟩ termination_by p => p /-- `divByMonic`, denoted as `p /ₘ q`, gives the quotient of `p` by a monic polynomial `q`. -/ def divByMonic (p q : R[X]) : R[X] := letI := Classical.decEq R if hq : Monic q then (divModByMonicAux p hq).1 else 0 /-- `modByMonic`, denoted as `p %ₘ q`, gives the remainder of `p` by a monic polynomial `q`. -/ def modByMonic (p q : R[X]) : R[X] := letI := Classical.decEq R if hq : Monic q then (divModByMonicAux p hq).2 else p @[inherit_doc] infixl:70 " /ₘ " => divByMonic @[inherit_doc] infixl:70 " %ₘ " => modByMonic theorem degree_modByMonic_lt [Nontrivial R] : ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), degree (p %ₘ q) < degree q | p, q, hq => letI := Classical.decEq R if h : degree q ≤ degree p ∧ p ≠ 0 then by have _wf := div_wf_lemma ⟨h.1, h.2⟩ hq have := degree_modByMonic_lt (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq unfold modByMonic at this ⊢ unfold divModByMonicAux dsimp rw [dif_pos hq] at this ⊢ rw [if_pos h] exact this else Or.casesOn (not_and_or.1 h) (by unfold modByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h] exact lt_of_not_ge) (by intro hp unfold modByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h, Classical.not_not.1 hp] exact lt_of_le_of_ne bot_le (Ne.symm (mt degree_eq_bot.1 hq.ne_zero))) termination_by p => p theorem natDegree_modByMonic_lt (p : R[X]) {q : R[X]} (hmq : Monic q) (hq : q ≠ 1) : natDegree (p %ₘ q) < q.natDegree := by by_cases hpq : p %ₘ q = 0 · rw [hpq, natDegree_zero, Nat.pos_iff_ne_zero] contrapose! hq exact eq_one_of_monic_natDegree_zero hmq hq · haveI := Nontrivial.of_polynomial_ne hpq exact natDegree_lt_natDegree hpq (degree_modByMonic_lt p hmq) @[simp] theorem zero_modByMonic (p : R[X]) : 0 %ₘ p = 0 := by classical unfold modByMonic divModByMonicAux dsimp by_cases hp : Monic p · rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.snd_zero] · rw [dif_neg hp] @[simp] theorem zero_divByMonic (p : R[X]) : 0 /ₘ p = 0 := by classical unfold divByMonic divModByMonicAux dsimp by_cases hp : Monic p · rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.fst_zero] · rw [dif_neg hp] @[simp] theorem modByMonic_zero (p : R[X]) : p %ₘ 0 = p := letI := Classical.decEq R if h : Monic (0 : R[X]) then by haveI := monic_zero_iff_subsingleton.mp h simp [eq_iff_true_of_subsingleton] else by unfold modByMonic divModByMonicAux; rw [dif_neg h] @[simp] theorem divByMonic_zero (p : R[X]) : p /ₘ 0 = 0 := letI := Classical.decEq R if h : Monic (0 : R[X]) then by haveI := monic_zero_iff_subsingleton.mp h simp [eq_iff_true_of_subsingleton] else by unfold divByMonic divModByMonicAux; rw [dif_neg h] theorem divByMonic_eq_of_not_monic (p : R[X]) (hq : ¬Monic q) : p /ₘ q = 0 := dif_neg hq theorem modByMonic_eq_of_not_monic (p : R[X]) (hq : ¬Monic q) : p %ₘ q = p := dif_neg hq theorem modByMonic_eq_self_iff [Nontrivial R] (hq : Monic q) : p %ₘ q = p ↔ degree p < degree q := ⟨fun h => h ▸ degree_modByMonic_lt _ hq, fun h => by classical have : ¬degree q ≤ degree p := not_le_of_gt h unfold modByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]⟩ theorem degree_modByMonic_le (p : R[X]) {q : R[X]} (hq : Monic q) : degree (p %ₘ q) ≤ degree q := by nontriviality R exact (degree_modByMonic_lt _ hq).le theorem degree_modByMonic_le_left : degree (p %ₘ q) ≤ degree p := by nontriviality R by_cases hq : q.Monic · cases lt_or_ge (degree p) (degree q) · rw [(modByMonic_eq_self_iff hq).mpr ‹_›] · exact (degree_modByMonic_le p hq).trans ‹_› · rw [modByMonic_eq_of_not_monic p hq] theorem natDegree_modByMonic_le (p : Polynomial R) {g : Polynomial R} (hg : g.Monic) : natDegree (p %ₘ g) ≤ g.natDegree := natDegree_le_natDegree (degree_modByMonic_le p hg) theorem natDegree_modByMonic_le_left : natDegree (p %ₘ q) ≤ natDegree p := natDegree_le_natDegree degree_modByMonic_le_left theorem X_dvd_sub_C : X ∣ p - C (p.coeff 0) := by simp [X_dvd_iff, coeff_C] theorem modByMonic_eq_sub_mul_div : ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q) | p, q, hq => letI := Classical.decEq R if h : degree q ≤ degree p ∧ p ≠ 0 then by have _wf := div_wf_lemma h hq have ih := modByMonic_eq_sub_mul_div (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq unfold modByMonic divByMonic divModByMonicAux dsimp rw [dif_pos hq, if_pos h] rw [modByMonic, dif_pos hq] at ih refine ih.trans ?_ unfold divByMonic rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub] else by unfold modByMonic divByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, mul_zero, sub_zero] termination_by p => p theorem modByMonic_add_div (p : R[X]) {q : R[X]} (hq : Monic q) : p %ₘ q + q * (p /ₘ q) = p := eq_sub_iff_add_eq.1 (modByMonic_eq_sub_mul_div p hq) theorem divByMonic_eq_zero_iff [Nontrivial R] (hq : Monic q) : p /ₘ q = 0 ↔ degree p < degree q := ⟨fun h => by have := modByMonic_add_div p hq rwa [h, mul_zero, add_zero, modByMonic_eq_self_iff hq] at this, fun h => by classical have : ¬degree q ≤ degree p := not_le_of_gt h unfold divByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]⟩ theorem degree_add_divByMonic (hq : Monic q) (h : degree q ≤ degree p) : degree q + degree (p /ₘ q) = degree p := by nontriviality R have hdiv0 : p /ₘ q ≠ 0 := by rwa [Ne, divByMonic_eq_zero_iff hq, not_lt] have hlc : leadingCoeff q * leadingCoeff (p /ₘ q) ≠ 0 := by rwa [Monic.def.1 hq, one_mul, Ne, leadingCoeff_eq_zero] have hmod : degree (p %ₘ q) < degree (q * (p /ₘ q)) := calc degree (p %ₘ q) < degree q := degree_modByMonic_lt _ hq _ ≤ _ := by rw [degree_mul' hlc, degree_eq_natDegree hq.ne_zero, degree_eq_natDegree hdiv0, ← Nat.cast_add, Nat.cast_le] exact Nat.le_add_right _ _ calc degree q + degree (p /ₘ q) = degree (q * (p /ₘ q)) := Eq.symm (degree_mul' hlc) _ = degree (p %ₘ q + q * (p /ₘ q)) := (degree_add_eq_right_of_degree_lt hmod).symm _ = _ := congr_arg _ (modByMonic_add_div _ hq) theorem degree_divByMonic_le (p q : R[X]) : degree (p /ₘ q) ≤ degree p := letI := Classical.decEq R if hp0 : p = 0 then by simp only [hp0, zero_divByMonic, le_refl] else if hq : Monic q then if h : degree q ≤ degree p then by haveI := Nontrivial.of_polynomial_ne hp0 rw [← degree_add_divByMonic hq h, degree_eq_natDegree hq.ne_zero, degree_eq_natDegree (mt (divByMonic_eq_zero_iff hq).1 (not_lt.2 h))] exact WithBot.coe_le_coe.2 (Nat.le_add_left _ _) else by unfold divByMonic divModByMonicAux simp [dif_pos hq, h, if_false, degree_zero, bot_le] else (divByMonic_eq_of_not_monic p hq).symm ▸ bot_le theorem degree_divByMonic_lt (p : R[X]) {q : R[X]} (hq : Monic q) (hp0 : p ≠ 0) (h0q : 0 < degree q) : degree (p /ₘ q) < degree p := if hpq : degree p < degree q then by haveI := Nontrivial.of_polynomial_ne hp0 rw [(divByMonic_eq_zero_iff hq).2 hpq, degree_eq_natDegree hp0] exact WithBot.bot_lt_coe _ else by haveI := Nontrivial.of_polynomial_ne hp0 rw [← degree_add_divByMonic hq (not_lt.1 hpq), degree_eq_natDegree hq.ne_zero, degree_eq_natDegree (mt (divByMonic_eq_zero_iff hq).1 hpq)] exact Nat.cast_lt.2 (Nat.lt_add_of_pos_left (Nat.cast_lt.1 <| by simpa [degree_eq_natDegree hq.ne_zero] using h0q)) theorem natDegree_divByMonic (f : R[X]) {g : R[X]} (hg : g.Monic) : natDegree (f /ₘ g) = natDegree f - natDegree g := by nontriviality R by_cases hfg : f /ₘ g = 0 · rw [hfg, natDegree_zero] rw [divByMonic_eq_zero_iff hg] at hfg rw [tsub_eq_zero_iff_le.mpr (natDegree_le_natDegree <| le_of_lt hfg)] have hgf := hfg rw [divByMonic_eq_zero_iff hg] at hgf push_neg at hgf have := degree_add_divByMonic hg hgf have hf : f ≠ 0 := by intro hf apply hfg rw [hf, zero_divByMonic] rw [degree_eq_natDegree hf, degree_eq_natDegree hg.ne_zero, degree_eq_natDegree hfg, ← Nat.cast_add, Nat.cast_inj] at this rw [← this, add_tsub_cancel_left] theorem div_modByMonic_unique {f g} (q r : R[X]) (hg : Monic g) (h : r + g * q = f ∧ degree r < degree g) : f /ₘ g = q ∧ f %ₘ g = r := by nontriviality R have h₁ : r - f %ₘ g = -g * (q - f /ₘ g) := eq_of_sub_eq_zero (by rw [← sub_eq_zero_of_eq (h.1.trans (modByMonic_add_div f hg).symm)] simp [mul_add, mul_comm, sub_eq_add_neg, add_comm, add_left_comm, add_assoc]) have h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g)) := by simp [h₁] have h₄ : degree (r - f %ₘ g) < degree g := calc degree (r - f %ₘ g) ≤ max (degree r) (degree (f %ₘ g)) := degree_sub_le _ _ _ < degree g := max_lt_iff.2 ⟨h.2, degree_modByMonic_lt _ hg⟩ have h₅ : q - f /ₘ g = 0 := _root_.by_contradiction fun hqf => not_le_of_gt h₄ <| calc degree g ≤ degree g + degree (q - f /ₘ g) := by rw [degree_eq_natDegree hg.ne_zero, degree_eq_natDegree hqf] norm_cast exact Nat.le_add_right _ _ _ = degree (r - f %ₘ g) := by rw [h₂, degree_mul']; simpa [Monic.def.1 hg] exact ⟨Eq.symm <| eq_of_sub_eq_zero h₅, Eq.symm <| eq_of_sub_eq_zero <| by simpa [h₅] using h₁⟩ theorem map_mod_divByMonic [Ring S] (f : R →+* S) (hq : Monic q) : (p /ₘ q).map f = p.map f /ₘ q.map f ∧ (p %ₘ q).map f = p.map f %ₘ q.map f := by nontriviality S haveI : Nontrivial R := f.domain_nontrivial have : map f p /ₘ map f q = map f (p /ₘ q) ∧ map f p %ₘ map f q = map f (p %ₘ q) := div_modByMonic_unique ((p /ₘ q).map f) _ (hq.map f) ⟨Eq.symm <| by rw [← Polynomial.map_mul, ← Polynomial.map_add, modByMonic_add_div _ hq], calc _ ≤ degree (p %ₘ q) := degree_map_le _ < degree q := degree_modByMonic_lt _ hq _ = _ := Eq.symm <| degree_map_eq_of_leadingCoeff_ne_zero _ (by rw [Monic.def.1 hq, f.map_one]; exact one_ne_zero)⟩ exact ⟨this.1.symm, this.2.symm⟩ theorem map_divByMonic [Ring S] (f : R →+* S) (hq : Monic q) : (p /ₘ q).map f = p.map f /ₘ q.map f := (map_mod_divByMonic f hq).1 theorem map_modByMonic [Ring S] (f : R →+* S) (hq : Monic q) : (p %ₘ q).map f = p.map f %ₘ q.map f := (map_mod_divByMonic f hq).2 theorem modByMonic_eq_zero_iff_dvd (hq : Monic q) : p %ₘ q = 0 ↔ q ∣ p := ⟨fun h => by rw [← modByMonic_add_div p hq, h, zero_add]; exact dvd_mul_right _ _, fun h => by nontriviality R obtain ⟨r, hr⟩ := exists_eq_mul_right_of_dvd h by_contra hpq0 have hmod : p %ₘ q = q * (r - p /ₘ q) := by rw [modByMonic_eq_sub_mul_div _ hq, mul_sub, ← hr] have : degree (q * (r - p /ₘ q)) < degree q := hmod ▸ degree_modByMonic_lt _ hq have hrpq0 : leadingCoeff (r - p /ₘ q) ≠ 0 := fun h => hpq0 <| leadingCoeff_eq_zero.1 (by rw [hmod, leadingCoeff_eq_zero.1 h, mul_zero, leadingCoeff_zero]) have hlc : leadingCoeff q * leadingCoeff (r - p /ₘ q) ≠ 0 := by rwa [Monic.def.1 hq, one_mul] rw [degree_mul' hlc, degree_eq_natDegree hq.ne_zero, degree_eq_natDegree (mt leadingCoeff_eq_zero.2 hrpq0)] at this exact not_lt_of_ge (Nat.le_add_right _ _) (WithBot.coe_lt_coe.1 this)⟩ /-- See `Polynomial.mul_self_modByMonic` for the other multiplication order. That version, unlike this one, requires commutativity. -/ @[simp] lemma self_mul_modByMonic (hq : q.Monic) : (q * p) %ₘ q = 0 := by rw [modByMonic_eq_zero_iff_dvd hq] exact dvd_mul_right q p theorem map_dvd_map [Ring S] (f : R →+* S) (hf : Function.Injective f) {x y : R[X]} (hx : x.Monic) : x.map f ∣ y.map f ↔ x ∣ y := by rw [← modByMonic_eq_zero_iff_dvd hx, ← modByMonic_eq_zero_iff_dvd (hx.map f), ← map_modByMonic f hx] exact ⟨fun H => map_injective f hf <| by rw [H, Polynomial.map_zero], fun H => by rw [H, Polynomial.map_zero]⟩ @[simp] theorem modByMonic_one (p : R[X]) : p %ₘ 1 = 0 := (modByMonic_eq_zero_iff_dvd (by convert monic_one (R := R))).2 (one_dvd _) @[simp] theorem divByMonic_one (p : R[X]) : p /ₘ 1 = p := by conv_rhs => rw [← modByMonic_add_div p monic_one]; simp
Mathlib/Algebra/Polynomial/Div.lean
424
430
theorem sum_modByMonic_coeff (hq : q.Monic) {n : ℕ} (hn : q.degree ≤ n) : (∑ i : Fin n, monomial i ((p %ₘ q).coeff i)) = p %ₘ q := by
nontriviality R exact (sum_fin (fun i c => monomial i c) (by simp) ((degree_modByMonic_lt _ hq).trans_le hn)).trans (sum_monomial_eq _)
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.List.Sublists import Mathlib.Data.List.Zip import Mathlib.Data.Multiset.Bind import Mathlib.Data.Multiset.Range /-! # The powerset of a multiset -/ namespace Multiset open List variable {α : Type*} /-! ### powerset -/ -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: Write a more efficient version /-- A helper function for the powerset of a multiset. Given a list `l`, returns a list of sublists of `l` as multisets. -/ def powersetAux (l : List α) : List (Multiset α) := (sublists l).map (↑) theorem powersetAux_eq_map_coe {l : List α} : powersetAux l = (sublists l).map (↑) := rfl @[simp] theorem mem_powersetAux {l : List α} {s} : s ∈ powersetAux l ↔ s ≤ ↑l := Quotient.inductionOn s <| by simp [powersetAux_eq_map_coe, Subperm, and_comm] /-- Helper function for the powerset of a multiset. Given a list `l`, returns a list of sublists of `l` (using `sublists'`), as multisets. -/ def powersetAux' (l : List α) : List (Multiset α) := (sublists' l).map (↑) theorem powersetAux_perm_powersetAux' {l : List α} : powersetAux l ~ powersetAux' l := by rw [powersetAux_eq_map_coe]; exact (sublists_perm_sublists' _).map _ @[simp] theorem powersetAux'_nil : powersetAux' (@nil α) = [0] := rfl @[simp] theorem powersetAux'_cons (a : α) (l : List α) : powersetAux' (a :: l) = powersetAux' l ++ List.map (cons a) (powersetAux' l) := by simp [powersetAux'] theorem powerset_aux'_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : powersetAux' l₁ ~ powersetAux' l₂ := by induction p with | nil => simp | cons _ _ IH => simp only [powersetAux'_cons] exact IH.append (IH.map _) | swap a b => simp only [powersetAux'_cons, map_append, List.map_map, append_assoc] apply Perm.append_left rw [← append_assoc, ← append_assoc, (by funext s; simp [cons_swap] : cons b ∘ cons a = cons a ∘ cons b)] exact perm_append_comm.append_right _ | trans _ _ IH₁ IH₂ => exact IH₁.trans IH₂ theorem powersetAux_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : powersetAux l₁ ~ powersetAux l₂ := powersetAux_perm_powersetAux'.trans <| (powerset_aux'_perm p).trans powersetAux_perm_powersetAux'.symm --Porting note (https://github.com/leanprover-community/mathlib4/issues/11083): slightly slower implementation due to `map ofList` /-- The power set of a multiset. -/ def powerset (s : Multiset α) : Multiset (Multiset α) := Quot.liftOn s (fun l => (powersetAux l : Multiset (Multiset α))) (fun _ _ h => Quot.sound (powersetAux_perm h)) theorem powerset_coe (l : List α) : @powerset α l = ((sublists l).map (↑) : List (Multiset α)) := congr_arg ((↑) : List (Multiset α) → Multiset (Multiset α)) powersetAux_eq_map_coe @[simp] theorem powerset_coe' (l : List α) : @powerset α l = ((sublists' l).map (↑) : List (Multiset α)) := Quot.sound powersetAux_perm_powersetAux' @[simp] theorem powerset_zero : @powerset α 0 = {0} := rfl @[simp] theorem powerset_cons (a : α) (s) : powerset (a ::ₘ s) = powerset s + map (cons a) (powerset s) := Quotient.inductionOn s fun l => by simp [Function.comp_def] @[simp] theorem mem_powerset {s t : Multiset α} : s ∈ powerset t ↔ s ≤ t := Quotient.inductionOn₂ s t <| by simp [Subperm, and_comm] theorem map_single_le_powerset (s : Multiset α) : s.map singleton ≤ powerset s := Quotient.inductionOn s fun l => by simp only [powerset_coe, quot_mk_to_coe, coe_le, map_coe] show l.map (((↑) : List α → Multiset α) ∘ pure) <+~ (sublists l).map (↑) rw [← List.map_map] exact ((map_pure_sublist_sublists _).map _).subperm @[simp] theorem card_powerset (s : Multiset α) : card (powerset s) = 2 ^ card s := Quotient.inductionOn s <| by simp theorem revzip_powersetAux {l : List α} ⦃x⦄ (h : x ∈ revzip (powersetAux l)) : x.1 + x.2 = ↑l := by rw [revzip, powersetAux_eq_map_coe, ← map_reverse, zip_map, ← revzip, List.mem_map] at h simp only [Prod.map_apply, Prod.exists] at h rcases h with ⟨l₁, l₂, h, rfl, rfl⟩ exact Quot.sound (revzip_sublists _ _ _ h) theorem revzip_powersetAux' {l : List α} ⦃x⦄ (h : x ∈ revzip (powersetAux' l)) : x.1 + x.2 = ↑l := by rw [revzip, powersetAux', ← map_reverse, zip_map, ← revzip, List.mem_map] at h simp only [Prod.map_apply, Prod.exists] at h rcases h with ⟨l₁, l₂, h, rfl, rfl⟩ exact Quot.sound (revzip_sublists' _ _ _ h) theorem revzip_powersetAux_lemma {α : Type*} [DecidableEq α] (l : List α) {l' : List (Multiset α)} (H : ∀ ⦃x : _ × _⦄, x ∈ revzip l' → x.1 + x.2 = ↑l) : revzip l' = l'.map fun x => (x, (l : Multiset α) - x) := by have : Forall₂ (fun (p : Multiset α × Multiset α) (s : Multiset α) => p = (s, ↑l - s)) (revzip l') ((revzip l').map Prod.fst) := by rw [forall₂_map_right_iff, forall₂_same] rintro ⟨s, t⟩ h dsimp rw [← H h, add_tsub_cancel_left] rw [← forall₂_eq_eq_eq, forall₂_map_right_iff] simpa using this theorem revzip_powersetAux_perm_aux' {l : List α} : revzip (powersetAux l) ~ revzip (powersetAux' l) := by haveI := Classical.decEq α rw [revzip_powersetAux_lemma l revzip_powersetAux, revzip_powersetAux_lemma l revzip_powersetAux'] exact powersetAux_perm_powersetAux'.map _ theorem revzip_powersetAux_perm {l₁ l₂ : List α} (p : l₁ ~ l₂) : revzip (powersetAux l₁) ~ revzip (powersetAux l₂) := by haveI := Classical.decEq α simp only [fun l : List α => revzip_powersetAux_lemma l revzip_powersetAux, coe_eq_coe.2 p] exact (powersetAux_perm p).map _ /-! ### powersetCard -/ /-- Helper function for `powersetCard`. Given a list `l`, `powersetCardAux n l` is the list of sublists of length `n`, as multisets. -/ def powersetCardAux (n : ℕ) (l : List α) : List (Multiset α) := sublistsLenAux n l (↑) []
Mathlib/Data/Multiset/Powerset.lean
154
158
theorem powersetCardAux_eq_map_coe {n} {l : List α} : powersetCardAux n l = (sublistsLen n l).map (↑) := by
rw [powersetCardAux, sublistsLenAux_eq, append_nil] @[simp]
/- 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.Finset.Card import Mathlib.Data.Finset.Lattice.Fold /-! # Down-compressions This file defines down-compression. Down-compressing `𝒜 : Finset (Finset α)` along `a : α` means removing `a` from the elements of `𝒜`, when the resulting set is not already in `𝒜`. ## Main declarations * `Finset.nonMemberSubfamily`: `𝒜.nonMemberSubfamily a` is the subfamily of sets not containing `a`. * `Finset.memberSubfamily`: `𝒜.memberSubfamily a` is the image of the subfamily of sets containing `a` under removing `a`. * `Down.compression`: Down-compression. ## Notation `𝓓 a 𝒜` is notation for `Down.compress a 𝒜` in locale `SetFamily`. ## References * https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf ## Tags compression, down-compression -/ variable {α : Type*} [DecidableEq α] {𝒜 : Finset (Finset α)} {s : Finset α} {a : α} namespace Finset /-- Elements of `𝒜` that do not contain `a`. -/ def nonMemberSubfamily (a : α) (𝒜 : Finset (Finset α)) : Finset (Finset α) := {s ∈ 𝒜 | a ∉ s} /-- Image of the elements of `𝒜` which contain `a` under removing `a`. Finsets that do not contain `a` such that `insert a s ∈ 𝒜`. -/ def memberSubfamily (a : α) (𝒜 : Finset (Finset α)) : Finset (Finset α) := {s ∈ 𝒜 | a ∈ s}.image fun s => erase s a @[simp] theorem mem_nonMemberSubfamily : s ∈ 𝒜.nonMemberSubfamily a ↔ s ∈ 𝒜 ∧ a ∉ s := by simp [nonMemberSubfamily] @[simp]
Mathlib/Combinatorics/SetFamily/Compression/Down.lean
56
57
theorem mem_memberSubfamily : s ∈ 𝒜.memberSubfamily a ↔ insert a s ∈ 𝒜 ∧ a ∉ s := by
simp_rw [memberSubfamily, mem_image, mem_filter]
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Julian Kuelshammer -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Algebra.Group.Pointwise.Set.Finite import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Order.Group.Action import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Data.Int.ModEq import Mathlib.Dynamics.PeriodicPts.Lemmas import Mathlib.GroupTheory.Index import Mathlib.NumberTheory.Divisors import Mathlib.Order.Interval.Set.Infinite /-! # Order of an element This file defines the order of an element of a finite group. For a finite group `G` the order of `x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`. ## Main definitions * `IsOfFinOrder` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite order. * `IsOfFinAddOrder` is the additive analogue of `IsOfFinOrder`. * `orderOf x` defines the order of an element `x` of a monoid `G`, by convention its value is `0` if `x` has infinite order. * `addOrderOf` is the additive analogue of `orderOf`. ## Tags order of an element -/ assert_not_exists Field open Function Fintype Nat Pointwise Subgroup Submonoid open scoped Finset variable {G H A α β : Type*} section Monoid variable [Monoid G] {a b x y : G} {n m : ℕ} section IsOfFinOrder -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed @[to_additive] theorem isPeriodicPt_mul_iff_pow_eq_one (x : G) : IsPeriodicPt (x * ·) n 1 ↔ x ^ n = 1 := by rw [IsPeriodicPt, IsFixedPt, mul_left_iterate]; beta_reduce; rw [mul_one] /-- `IsOfFinOrder` is a predicate on an element `x` of a monoid to be of finite order, i.e. there exists `n ≥ 1` such that `x ^ n = 1`. -/ @[to_additive "`IsOfFinAddOrder` is a predicate on an element `a` of an additive monoid to be of finite order, i.e. there exists `n ≥ 1` such that `n • a = 0`."] def IsOfFinOrder (x : G) : Prop := (1 : G) ∈ periodicPts (x * ·) theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) ↔ IsOfFinOrder x := Iff.rfl theorem isOfFinOrder_ofAdd_iff {α : Type*} [AddMonoid α] {x : α} : IsOfFinOrder (Multiplicative.ofAdd x) ↔ IsOfFinAddOrder x := Iff.rfl @[to_additive] theorem isOfFinOrder_iff_pow_eq_one : IsOfFinOrder x ↔ ∃ n, 0 < n ∧ x ^ n = 1 := by simp [IsOfFinOrder, mem_periodicPts, isPeriodicPt_mul_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.exists_pow_eq_one, _⟩ := isOfFinOrder_iff_pow_eq_one @[to_additive] lemma isOfFinOrder_iff_zpow_eq_one {G} [DivisionMonoid G] {x : G} : IsOfFinOrder x ↔ ∃ (n : ℤ), n ≠ 0 ∧ x ^ n = 1 := by rw [isOfFinOrder_iff_pow_eq_one] refine ⟨fun ⟨n, hn, hn'⟩ ↦ ⟨n, Int.natCast_ne_zero_iff_pos.mpr hn, zpow_natCast x n ▸ hn'⟩, fun ⟨n, hn, hn'⟩ ↦ ⟨n.natAbs, Int.natAbs_pos.mpr hn, ?_⟩⟩ rcases (Int.natAbs_eq_iff (a := n)).mp rfl with h | h · rwa [h, zpow_natCast] at hn' · rwa [h, zpow_neg, inv_eq_one, zpow_natCast] at hn' /-- See also `injective_pow_iff_not_isOfFinOrder`. -/ @[to_additive "See also `injective_nsmul_iff_not_isOfFinAddOrder`."] theorem not_isOfFinOrder_of_injective_pow {x : G} (h : Injective fun n : ℕ => x ^ n) : ¬IsOfFinOrder x := by simp_rw [isOfFinOrder_iff_pow_eq_one, not_exists, not_and] intro n hn_pos hnx rw [← pow_zero x] at hnx rw [h hnx] at hn_pos exact irrefl 0 hn_pos /-- 1 is of finite order in any monoid. -/ @[to_additive (attr := simp) "0 is of finite order in any additive monoid."] theorem IsOfFinOrder.one : IsOfFinOrder (1 : G) := isOfFinOrder_iff_pow_eq_one.mpr ⟨1, Nat.one_pos, one_pow 1⟩ @[to_additive] lemma IsOfFinOrder.pow {n : ℕ} : IsOfFinOrder a → IsOfFinOrder (a ^ n) := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨m, hm, ha⟩ exact ⟨m, hm, by simp [pow_right_comm _ n, ha]⟩ @[to_additive] lemma IsOfFinOrder.of_pow {n : ℕ} (h : IsOfFinOrder (a ^ n)) (hn : n ≠ 0) : IsOfFinOrder a := by rw [isOfFinOrder_iff_pow_eq_one] at * rcases h with ⟨m, hm, ha⟩ exact ⟨n * m, mul_pos hn.bot_lt hm, by rwa [pow_mul]⟩ @[to_additive (attr := simp)] lemma isOfFinOrder_pow {n : ℕ} : IsOfFinOrder (a ^ n) ↔ IsOfFinOrder a ∨ n = 0 := by rcases Decidable.eq_or_ne n 0 with rfl | hn · simp · exact ⟨fun h ↦ .inl <| h.of_pow hn, fun h ↦ (h.resolve_right hn).pow⟩ /-- Elements of finite order are of finite order in submonoids. -/ @[to_additive "Elements of finite order are of finite order in submonoids."] theorem Submonoid.isOfFinOrder_coe {H : Submonoid G} {x : H} : IsOfFinOrder (x : G) ↔ IsOfFinOrder x := by rw [isOfFinOrder_iff_pow_eq_one, isOfFinOrder_iff_pow_eq_one] norm_cast theorem IsConj.isOfFinOrder (h : IsConj x y) : IsOfFinOrder x → IsOfFinOrder y := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨n, n_gt_0, eq'⟩ exact ⟨n, n_gt_0, by rw [← isConj_one_right, ← eq']; exact h.pow n⟩ /-- The image of an element of finite order has finite order. -/ @[to_additive "The image of an element of finite additive order has finite additive order."] theorem MonoidHom.isOfFinOrder [Monoid H] (f : G →* H) {x : G} (h : IsOfFinOrder x) : IsOfFinOrder <| f x := isOfFinOrder_iff_pow_eq_one.mpr <| by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact ⟨n, npos, by rw [← f.map_pow, hn, f.map_one]⟩ /-- If a direct product has finite order then so does each component. -/ @[to_additive "If a direct product has finite additive order then so does each component."] theorem IsOfFinOrder.apply {η : Type*} {Gs : η → Type*} [∀ i, Monoid (Gs i)] {x : ∀ i, Gs i} (h : IsOfFinOrder x) : ∀ i, IsOfFinOrder (x i) := by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact fun _ => isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, (congr_fun hn.symm _).symm⟩ /-- The submonoid generated by an element is a group if that element has finite order. -/ @[to_additive "The additive submonoid generated by an element is an additive group if that element has finite order."] noncomputable abbrev IsOfFinOrder.groupPowers (hx : IsOfFinOrder x) : Group (Submonoid.powers x) := by obtain ⟨hpos, hx⟩ := hx.exists_pow_eq_one.choose_spec exact Submonoid.groupPowers hpos hx end IsOfFinOrder /-- `orderOf x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists. Otherwise, i.e. if `x` is of infinite order, then `orderOf x` is `0` by convention. -/ @[to_additive "`addOrderOf a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it exists. Otherwise, i.e. if `a` is of infinite order, then `addOrderOf a` is `0` by convention."] noncomputable def orderOf (x : G) : ℕ := minimalPeriod (x * ·) 1 @[simp] theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x := rfl @[simp] lemma orderOf_ofAdd_eq_addOrderOf {α : Type*} [AddMonoid α] (a : α) : orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl @[to_additive] protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x := minimalPeriod_pos_of_mem_periodicPts h @[to_additive addOrderOf_nsmul_eq_zero] theorem pow_orderOf_eq_one (x : G) : x ^ orderOf x = 1 := by convert Eq.trans _ (isPeriodicPt_minimalPeriod (x * ·) 1) -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed in the middle of the rewrite rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one] @[to_additive] theorem orderOf_eq_zero (h : ¬IsOfFinOrder x) : orderOf x = 0 := by rwa [orderOf, minimalPeriod, dif_neg] @[to_additive] theorem orderOf_eq_zero_iff : orderOf x = 0 ↔ ¬IsOfFinOrder x := ⟨fun h H ↦ H.orderOf_pos.ne' h, orderOf_eq_zero⟩ @[to_additive] theorem orderOf_eq_zero_iff' : orderOf x = 0 ↔ ∀ n : ℕ, 0 < n → x ^ n ≠ 1 := by simp_rw [orderOf_eq_zero_iff, isOfFinOrder_iff_pow_eq_one, not_exists, not_and] @[to_additive] theorem orderOf_eq_iff {n} (h : 0 < n) : orderOf x = n ↔ x ^ n = 1 ∧ ∀ m, m < n → 0 < m → x ^ m ≠ 1 := by simp_rw [Ne, ← isPeriodicPt_mul_iff_pow_eq_one, orderOf, minimalPeriod] split_ifs with h1 · classical rw [find_eq_iff] simp only [h, true_and] push_neg rfl · rw [iff_false_left h.ne] rintro ⟨h', -⟩ exact h1 ⟨n, h, h'⟩ /-- A group element has finite order iff its order is positive. -/ @[to_additive "A group element has finite additive order iff its order is positive."] theorem orderOf_pos_iff : 0 < orderOf x ↔ IsOfFinOrder x := by rw [iff_not_comm.mp orderOf_eq_zero_iff, pos_iff_ne_zero] @[to_additive] theorem IsOfFinOrder.mono [Monoid β] {y : β} (hx : IsOfFinOrder x) (h : orderOf y ∣ orderOf x) : IsOfFinOrder y := by rw [← orderOf_pos_iff] at hx ⊢; exact Nat.pos_of_dvd_of_pos h hx @[to_additive] theorem pow_ne_one_of_lt_orderOf (n0 : n ≠ 0) (h : n < orderOf x) : x ^ n ≠ 1 := fun j => not_isPeriodicPt_of_pos_of_lt_minimalPeriod n0 h ((isPeriodicPt_mul_iff_pow_eq_one x).mpr j) @[to_additive] theorem orderOf_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : orderOf x ≤ n := IsPeriodicPt.minimalPeriod_le hn (by rwa [isPeriodicPt_mul_iff_pow_eq_one]) @[to_additive (attr := simp)] theorem orderOf_one : orderOf (1 : G) = 1 := by rw [orderOf, ← minimalPeriod_id (x := (1 : G)), ← one_mul_eq_id] @[to_additive (attr := simp) AddMonoid.addOrderOf_eq_one_iff] theorem orderOf_eq_one_iff : orderOf x = 1 ↔ x = 1 := by rw [orderOf, minimalPeriod_eq_one_iff_isFixedPt, IsFixedPt, mul_one] @[to_additive (attr := simp) mod_addOrderOf_nsmul] lemma pow_mod_orderOf (x : G) (n : ℕ) : x ^ (n % orderOf x) = x ^ n := calc x ^ (n % orderOf x) = x ^ (n % orderOf x + orderOf x * (n / orderOf x)) := by simp [pow_add, pow_mul, pow_orderOf_eq_one] _ = x ^ n := by rw [Nat.mod_add_div] @[to_additive] theorem orderOf_dvd_of_pow_eq_one (h : x ^ n = 1) : orderOf x ∣ n := IsPeriodicPt.minimalPeriod_dvd ((isPeriodicPt_mul_iff_pow_eq_one _).mpr h) @[to_additive] theorem orderOf_dvd_iff_pow_eq_one {n : ℕ} : orderOf x ∣ n ↔ x ^ n = 1 := ⟨fun h => by rw [← pow_mod_orderOf, Nat.mod_eq_zero_of_dvd h, _root_.pow_zero], orderOf_dvd_of_pow_eq_one⟩ @[to_additive addOrderOf_smul_dvd] theorem orderOf_pow_dvd (n : ℕ) : orderOf (x ^ n) ∣ orderOf x := by rw [orderOf_dvd_iff_pow_eq_one, pow_right_comm, pow_orderOf_eq_one, one_pow] @[to_additive] lemma pow_injOn_Iio_orderOf : (Set.Iio <| orderOf x).InjOn (x ^ ·) := by simpa only [mul_left_iterate, mul_one] using iterate_injOn_Iio_minimalPeriod (f := (x * ·)) (x := 1) @[to_additive] protected lemma IsOfFinOrder.mem_powers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ Submonoid.powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := Finset.mem_range_iff_mem_finset_range_of_mod_eq' hx.orderOf_pos <| pow_mod_orderOf _ @[to_additive] protected lemma IsOfFinOrder.powers_eq_image_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : (Submonoid.powers x : Set G) = (Finset.range (orderOf x)).image (x ^ ·) := Set.ext fun _ ↦ hx.mem_powers_iff_mem_range_orderOf @[to_additive] theorem pow_eq_one_iff_modEq : x ^ n = 1 ↔ n ≡ 0 [MOD orderOf x] := by rw [modEq_zero_iff_dvd, orderOf_dvd_iff_pow_eq_one] @[to_additive] theorem orderOf_map_dvd {H : Type*} [Monoid H] (ψ : G →* H) (x : G) : orderOf (ψ x) ∣ orderOf x := by apply orderOf_dvd_of_pow_eq_one rw [← map_pow, pow_orderOf_eq_one] apply map_one @[to_additive] theorem exists_pow_eq_self_of_coprime (h : n.Coprime (orderOf x)) : ∃ m : ℕ, (x ^ n) ^ m = x := by by_cases h0 : orderOf x = 0 · rw [h0, coprime_zero_right] at h exact ⟨1, by rw [h, pow_one, pow_one]⟩ by_cases h1 : orderOf x = 1 · exact ⟨0, by rw [orderOf_eq_one_iff.mp h1, one_pow, one_pow]⟩ obtain ⟨m, h⟩ := exists_mul_emod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩) exact ⟨m, by rw [← pow_mul, ← pow_mod_orderOf, h, pow_one]⟩ /-- If `x^n = 1`, but `x^(n/p) ≠ 1` for all prime factors `p` of `n`, then `x` has order `n` in `G`. -/ @[to_additive addOrderOf_eq_of_nsmul_and_div_prime_nsmul "If `n * x = 0`, but `n/p * x ≠ 0` for all prime factors `p` of `n`, then `x` has order `n` in `G`."] theorem orderOf_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x ^ n = 1) (hd : ∀ p : ℕ, p.Prime → p ∣ n → x ^ (n / p) ≠ 1) : orderOf x = n := by -- Let `a` be `n/(orderOf x)`, and show `a = 1` obtain ⟨a, ha⟩ := exists_eq_mul_right_of_dvd (orderOf_dvd_of_pow_eq_one hx) suffices a = 1 by simp [this, ha] -- Assume `a` is not one... by_contra h have a_min_fac_dvd_p_sub_one : a.minFac ∣ n := by obtain ⟨b, hb⟩ : ∃ b : ℕ, a = b * a.minFac := exists_eq_mul_left_of_dvd a.minFac_dvd rw [hb, ← mul_assoc] at ha exact Dvd.intro_left (orderOf x * b) ha.symm -- Use the minimum prime factor of `a` as `p`. refine hd a.minFac (Nat.minFac_prime h) a_min_fac_dvd_p_sub_one ?_ rw [← orderOf_dvd_iff_pow_eq_one, Nat.dvd_div_iff_mul_dvd a_min_fac_dvd_p_sub_one, ha, mul_comm, Nat.mul_dvd_mul_iff_left (IsOfFinOrder.orderOf_pos _)] · exact Nat.minFac_dvd a · rw [isOfFinOrder_iff_pow_eq_one] exact Exists.intro n (id ⟨hn, hx⟩) @[to_additive] theorem orderOf_eq_orderOf_iff {H : Type*} [Monoid H] {y : H} : orderOf x = orderOf y ↔ ∀ n : ℕ, x ^ n = 1 ↔ y ^ n = 1 := by simp_rw [← isPeriodicPt_mul_iff_pow_eq_one, ← minimalPeriod_eq_minimalPeriod_iff, orderOf] /-- An injective homomorphism of monoids preserves orders of elements. -/ @[to_additive "An injective homomorphism of additive monoids preserves orders of elements."] theorem orderOf_injective {H : Type*} [Monoid H] (f : G →* H) (hf : Function.Injective f) (x : G) : orderOf (f x) = orderOf x := by simp_rw [orderOf_eq_orderOf_iff, ← f.map_pow, ← f.map_one, hf.eq_iff, forall_const] /-- A multiplicative equivalence preserves orders of elements. -/ @[to_additive (attr := simp) "An additive equivalence preserves orders of elements."] lemma MulEquiv.orderOf_eq {H : Type*} [Monoid H] (e : G ≃* H) (x : G) : orderOf (e x) = orderOf x := orderOf_injective e.toMonoidHom e.injective x @[to_additive] theorem Function.Injective.isOfFinOrder_iff [Monoid H] {f : G →* H} (hf : Injective f) : IsOfFinOrder (f x) ↔ IsOfFinOrder x := by rw [← orderOf_pos_iff, orderOf_injective f hf x, ← orderOf_pos_iff] @[to_additive (attr := norm_cast, simp)] theorem orderOf_submonoid {H : Submonoid G} (y : H) : orderOf (y : G) = orderOf y := orderOf_injective H.subtype Subtype.coe_injective y @[to_additive] theorem orderOf_units {y : Gˣ} : orderOf (y : G) = orderOf y := orderOf_injective (Units.coeHom G) Units.ext y /-- If the order of `x` is finite, then `x` is a unit with inverse `x ^ (orderOf x - 1)`. -/ @[to_additive (attr := simps) "If the additive order of `x` is finite, then `x` is an additive unit with inverse `(addOrderOf x - 1) • x`. "] noncomputable def IsOfFinOrder.unit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : Mˣ := ⟨x, x ^ (orderOf x - 1), by rw [← _root_.pow_succ', tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one], by rw [← _root_.pow_succ, tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one]⟩ @[to_additive] lemma IsOfFinOrder.isUnit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : IsUnit x := ⟨hx.unit, rfl⟩ variable (x) @[to_additive] theorem orderOf_pow' (h : n ≠ 0) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd h, mul_left_iterate] @[to_additive] lemma orderOf_pow_of_dvd {x : G} {n : ℕ} (hn : n ≠ 0) (dvd : n ∣ orderOf x) : orderOf (x ^ n) = orderOf x / n := by rw [orderOf_pow' _ hn, Nat.gcd_eq_right dvd] @[to_additive] lemma orderOf_pow_orderOf_div {x : G} {n : ℕ} (hx : orderOf x ≠ 0) (hn : n ∣ orderOf x) : orderOf (x ^ (orderOf x / n)) = n := by rw [orderOf_pow_of_dvd _ (Nat.div_dvd_of_dvd hn), Nat.div_div_self hn hx] rw [← Nat.div_mul_cancel hn] at hx; exact left_ne_zero_of_mul hx variable (n) @[to_additive] protected lemma IsOfFinOrder.orderOf_pow (h : IsOfFinOrder x) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd' h, mul_left_iterate] @[to_additive] lemma Nat.Coprime.orderOf_pow (h : (orderOf y).Coprime m) : orderOf (y ^ m) = orderOf y := by by_cases hg : IsOfFinOrder y · rw [hg.orderOf_pow y m , h.gcd_eq_one, Nat.div_one] · rw [m.coprime_zero_left.1 (orderOf_eq_zero hg ▸ h), pow_one] @[to_additive] lemma IsOfFinOrder.natCard_powers_le_orderOf (ha : IsOfFinOrder a) : Nat.card (powers a : Set G) ≤ orderOf a := by classical simpa [ha.powers_eq_image_range_orderOf, Finset.card_range, Nat.Iio_eq_range] using Finset.card_image_le (s := Finset.range (orderOf a)) @[to_additive] lemma IsOfFinOrder.finite_powers (ha : IsOfFinOrder a) : (powers a : Set G).Finite := by classical rw [ha.powers_eq_image_range_orderOf]; exact Finset.finite_toSet _ namespace Commute variable {x} @[to_additive] theorem orderOf_mul_dvd_lcm (h : Commute x y) : orderOf (x * y) ∣ Nat.lcm (orderOf x) (orderOf y) := by rw [orderOf, ← comp_mul_left] exact Function.Commute.minimalPeriod_of_comp_dvd_lcm h.function_commute_mul_left @[to_additive] theorem orderOf_dvd_lcm_mul (h : Commute x y): orderOf y ∣ Nat.lcm (orderOf x) (orderOf (x * y)) := by by_cases h0 : orderOf x = 0 · rw [h0, lcm_zero_left] apply dvd_zero conv_lhs => rw [← one_mul y, ← pow_orderOf_eq_one x, ← succ_pred_eq_of_pos (Nat.pos_of_ne_zero h0), _root_.pow_succ, mul_assoc] exact (((Commute.refl x).mul_right h).pow_left _).orderOf_mul_dvd_lcm.trans (lcm_dvd_iff.2 ⟨(orderOf_pow_dvd _).trans (dvd_lcm_left _ _), dvd_lcm_right _ _⟩) @[to_additive addOrderOf_add_dvd_mul_addOrderOf] theorem orderOf_mul_dvd_mul_orderOf (h : Commute x y): orderOf (x * y) ∣ orderOf x * orderOf y := dvd_trans h.orderOf_mul_dvd_lcm (lcm_dvd_mul _ _) @[to_additive addOrderOf_add_eq_mul_addOrderOf_of_coprime] theorem orderOf_mul_eq_mul_orderOf_of_coprime (h : Commute x y) (hco : (orderOf x).Coprime (orderOf y)) : orderOf (x * y) = orderOf x * orderOf y := by rw [orderOf, ← comp_mul_left] exact h.function_commute_mul_left.minimalPeriod_of_comp_eq_mul_of_coprime hco /-- Commuting elements of finite order are closed under multiplication. -/ @[to_additive "Commuting elements of finite additive order are closed under addition."] theorem isOfFinOrder_mul (h : Commute x y) (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := orderOf_pos_iff.mp <| pos_of_dvd_of_pos h.orderOf_mul_dvd_mul_orderOf <| mul_pos hx.orderOf_pos hy.orderOf_pos /-- If each prime factor of `orderOf x` has higher multiplicity in `orderOf y`, and `x` commutes with `y`, then `x * y` has the same order as `y`. -/ @[to_additive addOrderOf_add_eq_right_of_forall_prime_mul_dvd "If each prime factor of `addOrderOf x` has higher multiplicity in `addOrderOf y`, and `x` commutes with `y`, then `x + y` has the same order as `y`."] theorem orderOf_mul_eq_right_of_forall_prime_mul_dvd (h : Commute x y) (hy : IsOfFinOrder y) (hdvd : ∀ p : ℕ, p.Prime → p ∣ orderOf x → p * orderOf x ∣ orderOf y) : orderOf (x * y) = orderOf y := by have hoy := hy.orderOf_pos have hxy := dvd_of_forall_prime_mul_dvd hdvd apply orderOf_eq_of_pow_and_pow_div_prime hoy <;> simp only [Ne, ← orderOf_dvd_iff_pow_eq_one] · exact h.orderOf_mul_dvd_lcm.trans (lcm_dvd hxy dvd_rfl) refine fun p hp hpy hd => hp.ne_one ?_ rw [← Nat.dvd_one, ← mul_dvd_mul_iff_right hoy.ne', one_mul, ← dvd_div_iff_mul_dvd hpy] refine (orderOf_dvd_lcm_mul h).trans (lcm_dvd ((dvd_div_iff_mul_dvd hpy).2 ?_) hd) by_cases h : p ∣ orderOf x exacts [hdvd p hp h, (hp.coprime_iff_not_dvd.2 h).mul_dvd_of_dvd_of_dvd hpy hxy] end Commute section PPrime variable {x n} {p : ℕ} [hp : Fact p.Prime] @[to_additive] theorem orderOf_eq_prime_iff : orderOf x = p ↔ x ^ p = 1 ∧ x ≠ 1 := by rw [orderOf, minimalPeriod_eq_prime_iff, isPeriodicPt_mul_iff_pow_eq_one, IsFixedPt, mul_one] /-- The backward direction of `orderOf_eq_prime_iff`. -/ @[to_additive "The backward direction of `addOrderOf_eq_prime_iff`."] theorem orderOf_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : orderOf x = p := orderOf_eq_prime_iff.mpr ⟨hg, hg1⟩ @[to_additive addOrderOf_eq_prime_pow] theorem orderOf_eq_prime_pow (hnot : ¬x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) : orderOf x = p ^ (n + 1) := by apply minimalPeriod_eq_prime_pow <;> rwa [isPeriodicPt_mul_iff_pow_eq_one] @[to_additive exists_addOrderOf_eq_prime_pow_iff] theorem exists_orderOf_eq_prime_pow_iff : (∃ k : ℕ, orderOf x = p ^ k) ↔ ∃ m : ℕ, x ^ (p : ℕ) ^ m = 1 := ⟨fun ⟨k, hk⟩ => ⟨k, by rw [← hk, pow_orderOf_eq_one]⟩, fun ⟨_, hm⟩ => by obtain ⟨k, _, hk⟩ := (Nat.dvd_prime_pow hp.elim).mp (orderOf_dvd_of_pow_eq_one hm) exact ⟨k, hk⟩⟩ end PPrime /-- The equivalence between `Fin (orderOf x)` and `Submonoid.powers x`, sending `i` to `x ^ i` -/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `AddSubmonoid.multiples a`, sending `i` to `i • a`"] noncomputable def finEquivPowers {x : G} (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ powers x := Equiv.ofBijective (fun n ↦ ⟨x ^ (n : ℕ), ⟨n, rfl⟩⟩) ⟨fun ⟨_, h₁⟩ ⟨_, h₂⟩ ij ↦ Fin.ext (pow_injOn_Iio_orderOf h₁ h₂ (Subtype.mk_eq_mk.1 ij)), fun ⟨_, i, rfl⟩ ↦ ⟨⟨i % orderOf x, mod_lt _ hx.orderOf_pos⟩, Subtype.eq <| pow_mod_orderOf _ _⟩⟩ @[to_additive (attr := simp)] lemma finEquivPowers_apply {x : G} (hx : IsOfFinOrder x) {n : Fin (orderOf x)} : finEquivPowers hx n = ⟨x ^ (n : ℕ), n, rfl⟩ := rfl @[to_additive (attr := simp)] lemma finEquivPowers_symm_apply {x : G} (hx : IsOfFinOrder x) (n : ℕ) : (finEquivPowers hx).symm ⟨x ^ n, _, rfl⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [Equiv.symm_apply_eq, finEquivPowers_apply, Subtype.mk_eq_mk, ← pow_mod_orderOf, Fin.val_mk] variable {x n} (hx : IsOfFinOrder x) include hx @[to_additive] theorem IsOfFinOrder.pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≤ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [pow_add, (hx.isUnit.pow _).mul_eq_left, pow_eq_one_iff_modEq] exact ⟨fun h ↦ Nat.ModEq.add_left _ h, fun h ↦ Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive] lemma IsOfFinOrder.pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := hx.pow_eq_pow_iff_modEq end Monoid section CancelMonoid variable [LeftCancelMonoid G] {x y : G} {a : G} {m n : ℕ} @[to_additive] theorem pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≤ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [← mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modEq] exact ⟨fun h => Nat.ModEq.add_left _ h, fun h => Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive (attr := simp)] lemma injective_pow_iff_not_isOfFinOrder : Injective (fun n : ℕ ↦ x ^ n) ↔ ¬IsOfFinOrder x := by refine ⟨fun h => not_isOfFinOrder_of_injective_pow h, fun h n m hnm => ?_⟩ rwa [pow_eq_pow_iff_modEq, orderOf_eq_zero_iff.mpr h, modEq_zero_iff] at hnm @[to_additive] lemma pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := pow_eq_pow_iff_modEq @[to_additive] theorem pow_inj_iff_of_orderOf_eq_zero (h : orderOf x = 0) {n m : ℕ} : x ^ n = x ^ m ↔ n = m := by rw [pow_eq_pow_iff_modEq, h, modEq_zero_iff] @[to_additive] theorem infinite_not_isOfFinOrder {x : G} (h : ¬IsOfFinOrder x) : { y : G | ¬IsOfFinOrder y }.Infinite := by let s := { n | 0 < n }.image fun n : ℕ => x ^ n have hs : s ⊆ { y : G | ¬IsOfFinOrder y } := by rintro - ⟨n, hn : 0 < n, rfl⟩ (contra : IsOfFinOrder (x ^ n)) apply h rw [isOfFinOrder_iff_pow_eq_one] at contra ⊢ obtain ⟨m, hm, hm'⟩ := contra exact ⟨n * m, mul_pos hn hm, by rwa [pow_mul]⟩ suffices s.Infinite by exact this.mono hs contrapose! h have : ¬Injective fun n : ℕ => x ^ n := by have := Set.not_injOn_infinite_finite_image (Set.Ioi_infinite 0) (Set.not_infinite.mp h) contrapose! this exact Set.injOn_of_injective this rwa [injective_pow_iff_not_isOfFinOrder, Classical.not_not] at this @[to_additive (attr := simp)] lemma finite_powers : (powers a : Set G).Finite ↔ IsOfFinOrder a := by refine ⟨fun h ↦ ?_, IsOfFinOrder.finite_powers⟩ obtain ⟨m, n, hmn, ha⟩ := h.exists_lt_map_eq_of_forall_mem (f := fun n : ℕ ↦ a ^ n) (fun n ↦ by simp [mem_powers_iff]) refine isOfFinOrder_iff_pow_eq_one.2 ⟨n - m, tsub_pos_iff_lt.2 hmn, ?_⟩ rw [← mul_left_cancel_iff (a := a ^ m), ← pow_add, add_tsub_cancel_of_le hmn.le, ha, mul_one] @[to_additive (attr := simp)] lemma infinite_powers : (powers a : Set G).Infinite ↔ ¬ IsOfFinOrder a := finite_powers.not /-- See also `orderOf_eq_card_powers`. -/ @[to_additive "See also `addOrder_eq_card_multiples`."] lemma Nat.card_submonoidPowers : Nat.card (powers a) = orderOf a := by classical by_cases ha : IsOfFinOrder a · exact (Nat.card_congr (finEquivPowers ha).symm).trans <| by simp · have := (infinite_powers.2 ha).to_subtype rw [orderOf_eq_zero ha, Nat.card_eq_zero_of_infinite] end CancelMonoid section Group variable [Group G] {x y : G} {i : ℤ} /-- Inverses of elements of finite order have finite order. -/ @[to_additive (attr := simp) "Inverses of elements of finite additive order have finite additive order."] theorem isOfFinOrder_inv_iff {x : G} : IsOfFinOrder x⁻¹ ↔ IsOfFinOrder x := by simp [isOfFinOrder_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.of_inv, IsOfFinOrder.inv⟩ := isOfFinOrder_inv_iff @[to_additive] theorem orderOf_dvd_iff_zpow_eq_one : (orderOf x : ℤ) ∣ i ↔ x ^ i = 1 := by rcases Int.eq_nat_or_neg i with ⟨i, rfl | rfl⟩ · rw [Int.natCast_dvd_natCast, orderOf_dvd_iff_pow_eq_one, zpow_natCast] · rw [dvd_neg, Int.natCast_dvd_natCast, zpow_neg, inv_eq_one, zpow_natCast, orderOf_dvd_iff_pow_eq_one] @[to_additive (attr := simp)] theorem orderOf_inv (x : G) : orderOf x⁻¹ = orderOf x := by simp [orderOf_eq_orderOf_iff] @[to_additive] theorem orderOf_dvd_sub_iff_zpow_eq_zpow {a b : ℤ} : (orderOf x : ℤ) ∣ a - b ↔ x ^ a = x ^ b := by rw [orderOf_dvd_iff_zpow_eq_one, zpow_sub, mul_inv_eq_one] namespace Subgroup variable {H : Subgroup G} @[to_additive (attr := norm_cast)] lemma orderOf_coe (a : H) : orderOf (a : G) = orderOf a := orderOf_injective H.subtype Subtype.coe_injective _ @[to_additive (attr := simp)] lemma orderOf_mk (a : G) (ha) : orderOf (⟨a, ha⟩ : H) = orderOf a := (orderOf_coe _).symm end Subgroup @[to_additive mod_addOrderOf_zsmul] lemma zpow_mod_orderOf (x : G) (z : ℤ) : x ^ (z % (orderOf x : ℤ)) = x ^ z := calc x ^ (z % (orderOf x : ℤ)) = x ^ (z % orderOf x + orderOf x * (z / orderOf x) : ℤ) := by simp [zpow_add, zpow_mul, pow_orderOf_eq_one] _ = x ^ z := by rw [Int.emod_add_ediv] @[to_additive (attr := simp) zsmul_smul_addOrderOf] theorem zpow_pow_orderOf : (x ^ i) ^ orderOf x = 1 := by by_cases h : IsOfFinOrder x · rw [← zpow_natCast, ← zpow_mul, mul_comm, zpow_mul, zpow_natCast, pow_orderOf_eq_one, one_zpow] · rw [orderOf_eq_zero h, _root_.pow_zero] @[to_additive] theorem IsOfFinOrder.zpow (h : IsOfFinOrder x) {i : ℤ} : IsOfFinOrder (x ^ i) := isOfFinOrder_iff_pow_eq_one.mpr ⟨orderOf x, h.orderOf_pos, zpow_pow_orderOf⟩ @[to_additive] theorem IsOfFinOrder.of_mem_zpowers (h : IsOfFinOrder x) (h' : y ∈ Subgroup.zpowers x) : IsOfFinOrder y := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h' exact h.zpow @[to_additive]
Mathlib/GroupTheory/OrderOfElement.lean
641
648
theorem orderOf_dvd_of_mem_zpowers (h : y ∈ Subgroup.zpowers x) : orderOf y ∣ orderOf x := by
obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h rw [orderOf_dvd_iff_pow_eq_one] exact zpow_pow_orderOf theorem smul_eq_self_of_mem_zpowers {α : Type*} [MulAction G α] (hx : x ∈ Subgroup.zpowers y) {a : α} (hs : y • a = a) : x • a = a := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp hx
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attach import Mathlib.Data.Finset.Disjoint import Mathlib.Data.Finset.Erase import Mathlib.Data.Finset.Filter import Mathlib.Data.Finset.Range import Mathlib.Data.Finset.SDiff import Mathlib.Data.Multiset.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Defs import Mathlib.Data.Set.SymmDiff /-! # Basic lemmas on finite sets This file contains lemmas on the interaction of various definitions on the `Finset` type. For an explanation of `Finset` design decisions, please see `Mathlib/Data/Finset/Defs.lean`. ## Main declarations ### Main definitions * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Equivalences between finsets * The `Mathlib/Logic/Equiv/Defs.lean` file describes a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen Multiset.powerset CompleteLattice Monoid open Multiset Subtype Function universe u variable {α : Type*} {β : Type*} {γ : Type*} namespace Finset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-02-07")] theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Finset α} (hx : x ∈ s) : SizeOf.sizeOf x < SizeOf.sizeOf s := by cases s dsimp [SizeOf.sizeOf, SizeOf.sizeOf, Multiset.sizeOf] rw [Nat.add_comm] refine lt_trans ?_ (Nat.lt_succ_self _) exact Multiset.sizeOf_lt_sizeOf_of_mem hx /-! ### Lattice structure -/ section Lattice variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α} /-! #### union -/ @[simp] theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t := ext fun a => by simp @[simp] theorem disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := by simp only [disjoint_left, mem_union, or_imp, forall_and] @[simp] theorem disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := by simp only [disjoint_right, mem_union, or_imp, forall_and] /-! #### inter -/ theorem not_disjoint_iff_nonempty_inter : ¬Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff.trans <| by simp [Finset.Nonempty] alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter theorem disjoint_or_nonempty_inter (s t : Finset α) : Disjoint s t ∨ (s ∩ t).Nonempty := by rw [← not_disjoint_iff_nonempty_inter] exact em _ omit [DecidableEq α] in theorem disjoint_of_subset_iff_left_eq_empty (h : s ⊆ t) : Disjoint s t ↔ s = ∅ := disjoint_of_le_iff_left_eq_bot h lemma pairwiseDisjoint_iff {ι : Type*} {s : Set ι} {f : ι → Finset α} : s.PairwiseDisjoint f ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → (f i ∩ f j).Nonempty → i = j := by simp [Set.PairwiseDisjoint, Set.Pairwise, Function.onFun, not_imp_comm (a := _ = _), not_disjoint_iff_nonempty_inter] end Lattice instance isDirected_le : IsDirected (Finset α) (· ≤ ·) := by classical infer_instance instance isDirected_subset : IsDirected (Finset α) (· ⊆ ·) := isDirected_le /-! ### erase -/ section Erase variable [DecidableEq α] {s t u v : Finset α} {a b : α} @[simp] theorem erase_empty (a : α) : erase ∅ a = ∅ := rfl protected lemma Nontrivial.erase_nonempty (hs : s.Nontrivial) : (s.erase a).Nonempty := (hs.exists_ne a).imp <| by aesop @[simp] lemma erase_nonempty (ha : a ∈ s) : (s.erase a).Nonempty ↔ s.Nontrivial := by simp only [Finset.Nonempty, mem_erase, and_comm (b := _ ∈ _)] refine ⟨?_, fun hs ↦ hs.exists_ne a⟩ rintro ⟨b, hb, hba⟩ exact ⟨_, hb, _, ha, hba⟩ @[simp] theorem erase_singleton (a : α) : ({a} : Finset α).erase a = ∅ := by ext x simp @[simp] theorem erase_insert_eq_erase (s : Finset α) (a : α) : (insert a s).erase a = s.erase a := ext fun x => by simp +contextual only [mem_erase, mem_insert, and_congr_right_iff, false_or, iff_self, imp_true_iff] theorem erase_insert {a : α} {s : Finset α} (h : a ∉ s) : erase (insert a s) a = s := by rw [erase_insert_eq_erase, erase_eq_of_not_mem h] theorem erase_insert_of_ne {a b : α} {s : Finset α} (h : a ≠ b) : erase (insert a s) b = insert a (erase s b) := ext fun x => by have : x ≠ b ∧ x = a ↔ x = a := and_iff_right_of_imp fun hx => hx.symm ▸ h simp only [mem_erase, mem_insert, and_or_left, this] theorem erase_cons_of_ne {a b : α} {s : Finset α} (ha : a ∉ s) (hb : a ≠ b) : erase (cons a s ha) b = cons a (erase s b) fun h => ha <| erase_subset _ _ h := by simp only [cons_eq_insert, erase_insert_of_ne hb] @[simp] theorem insert_erase (h : a ∈ s) : insert a (erase s a) = s := ext fun x => by simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and] apply or_iff_right_of_imp rintro rfl exact h lemma erase_eq_iff_eq_insert (hs : a ∈ s) (ht : a ∉ t) : erase s a = t ↔ s = insert a t := by aesop lemma insert_erase_invOn : Set.InvOn (insert a) (fun s ↦ erase s a) {s : Finset α | a ∈ s} {s : Finset α | a ∉ s} := ⟨fun _s ↦ insert_erase, fun _s ↦ erase_insert⟩ theorem erase_ssubset {a : α} {s : Finset α} (h : a ∈ s) : s.erase a ⊂ s := calc s.erase a ⊂ insert a (s.erase a) := ssubset_insert <| not_mem_erase _ _ _ = _ := insert_erase h theorem ssubset_iff_exists_subset_erase {s t : Finset α} : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t.erase a := by refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_subset_of_ssubset h <| erase_ssubset ha⟩ obtain ⟨a, ht, hs⟩ := not_subset.1 h.2 exact ⟨a, ht, subset_erase.2 ⟨h.1, hs⟩⟩ theorem erase_ssubset_insert (s : Finset α) (a : α) : s.erase a ⊂ insert a s := ssubset_iff_exists_subset_erase.2 ⟨a, mem_insert_self _ _, erase_subset_erase _ <| subset_insert _ _⟩ theorem erase_cons {s : Finset α} {a : α} (h : a ∉ s) : (s.cons a h).erase a = s := by rw [cons_eq_insert, erase_insert_eq_erase, erase_eq_of_not_mem h] theorem subset_insert_iff {a : α} {s t : Finset α} : s ⊆ insert a t ↔ erase s a ⊆ t := by simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp] exact forall_congr' fun x => forall_swap theorem erase_insert_subset (a : α) (s : Finset α) : erase (insert a s) a ⊆ s := subset_insert_iff.1 <| Subset.rfl theorem insert_erase_subset (a : α) (s : Finset α) : s ⊆ insert a (erase s a) := subset_insert_iff.2 <| Subset.rfl theorem subset_insert_iff_of_not_mem (h : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := by rw [subset_insert_iff, erase_eq_of_not_mem h] theorem erase_subset_iff_of_mem (h : a ∈ t) : s.erase a ⊆ t ↔ s ⊆ t := by rw [← subset_insert_iff, insert_eq_of_mem h] theorem erase_injOn' (a : α) : { s : Finset α | a ∈ s }.InjOn fun s => erase s a := fun s hs t ht (h : s.erase a = _) => by rw [← insert_erase hs, ← insert_erase ht, h] end Erase lemma Nontrivial.exists_cons_eq {s : Finset α} (hs : s.Nontrivial) : ∃ t a ha b hb hab, (cons b t hb).cons a (mem_cons.not.2 <| not_or_intro hab ha) = s := by classical obtain ⟨a, ha, b, hb, hab⟩ := hs have : b ∈ s.erase a := mem_erase.2 ⟨hab.symm, hb⟩ refine ⟨(s.erase a).erase b, a, ?_, b, ?_, ?_, ?_⟩ <;> simp [insert_erase this, insert_erase ha, *] /-! ### sdiff -/ section Sdiff variable [DecidableEq α] {s t u v : Finset α} {a b : α} lemma erase_sdiff_erase (hab : a ≠ b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by ext; aesop -- TODO: Do we want to delete this lemma and `Finset.disjUnion_singleton`, -- or instead add `Finset.union_singleton`/`Finset.singleton_union`? theorem sdiff_singleton_eq_erase (a : α) (s : Finset α) : s \ {a} = erase s a := by ext rw [mem_erase, mem_sdiff, mem_singleton, and_comm] -- This lemma matches `Finset.insert_eq` in functionality. theorem erase_eq (s : Finset α) (a : α) : s.erase a = s \ {a} := (sdiff_singleton_eq_erase _ _).symm theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by simp_rw [erase_eq, disjoint_sdiff_comm] lemma disjoint_insert_erase (ha : a ∉ t) : Disjoint (s.erase a) (insert a t) ↔ Disjoint s t := by rw [disjoint_erase_comm, erase_insert ha] lemma disjoint_erase_insert (ha : a ∉ s) : Disjoint (insert a s) (t.erase a) ↔ Disjoint s t := by rw [← disjoint_erase_comm, erase_insert ha] theorem disjoint_of_erase_left (ha : a ∉ t) (hst : Disjoint (s.erase a) t) : Disjoint s t := by rw [← erase_insert ha, ← disjoint_erase_comm, disjoint_insert_right] exact ⟨not_mem_erase _ _, hst⟩ theorem disjoint_of_erase_right (ha : a ∉ s) (hst : Disjoint s (t.erase a)) : Disjoint s t := by rw [← erase_insert ha, disjoint_erase_comm, disjoint_insert_left] exact ⟨not_mem_erase _ _, hst⟩ theorem inter_erase (a : α) (s t : Finset α) : s ∩ t.erase a = (s ∩ t).erase a := by simp only [erase_eq, inter_sdiff_assoc] @[simp] theorem erase_inter (a : α) (s t : Finset α) : s.erase a ∩ t = (s ∩ t).erase a := by simpa only [inter_comm t] using inter_erase a t s theorem erase_sdiff_comm (s t : Finset α) (a : α) : s.erase a \ t = (s \ t).erase a := by simp_rw [erase_eq, sdiff_right_comm] theorem erase_inter_comm (s t : Finset α) (a : α) : s.erase a ∩ t = s ∩ t.erase a := by rw [erase_inter, inter_erase] theorem erase_union_distrib (s t : Finset α) (a : α) : (s ∪ t).erase a = s.erase a ∪ t.erase a := by simp_rw [erase_eq, union_sdiff_distrib] theorem insert_inter_distrib (s t : Finset α) (a : α) : insert a (s ∩ t) = insert a s ∩ insert a t := by simp_rw [insert_eq, union_inter_distrib_left] theorem erase_sdiff_distrib (s t : Finset α) (a : α) : (s \ t).erase a = s.erase a \ t.erase a := by simp_rw [erase_eq, sdiff_sdiff, sup_sdiff_eq_sup le_rfl, sup_comm] theorem erase_union_of_mem (ha : a ∈ t) (s : Finset α) : s.erase a ∪ t = s ∪ t := by rw [← insert_erase (mem_union_right s ha), erase_union_distrib, ← union_insert, insert_erase ha] theorem union_erase_of_mem (ha : a ∈ s) (t : Finset α) : s ∪ t.erase a = s ∪ t := by rw [← insert_erase (mem_union_left t ha), erase_union_distrib, ← insert_union, insert_erase ha] theorem sdiff_union_erase_cancel (hts : t ⊆ s) (ha : a ∈ t) : s \ t ∪ t.erase a = s.erase a := by simp_rw [erase_eq, sdiff_union_sdiff_cancel hts (singleton_subset_iff.2 ha)] theorem sdiff_insert (s t : Finset α) (x : α) : s \ insert x t = (s \ t).erase x := by simp_rw [← sdiff_singleton_eq_erase, insert_eq, sdiff_sdiff_left', sdiff_union_distrib, inter_comm] theorem sdiff_insert_insert_of_mem_of_not_mem {s t : Finset α} {x : α} (hxs : x ∈ s) (hxt : x ∉ t) : insert x (s \ insert x t) = s \ t := by rw [sdiff_insert, insert_erase (mem_sdiff.mpr ⟨hxs, hxt⟩)] theorem sdiff_erase (h : a ∈ s) : s \ t.erase a = insert a (s \ t) := by rw [← sdiff_singleton_eq_erase, sdiff_sdiff_eq_sdiff_union (singleton_subset_iff.2 h), insert_eq, union_comm] theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by rw [sdiff_erase ha, Finset.sdiff_self, insert_empty_eq] theorem erase_eq_empty_iff (s : Finset α) (a : α) : s.erase a = ∅ ↔ s = ∅ ∨ s = {a} := by rw [← sdiff_singleton_eq_erase, sdiff_eq_empty_iff_subset, subset_singleton_iff] --TODO@Yaël: Kill lemmas duplicate with `BooleanAlgebra` theorem sdiff_disjoint : Disjoint (t \ s) s := disjoint_left.2 fun _a ha => (mem_sdiff.1 ha).2 theorem disjoint_sdiff : Disjoint s (t \ s) := sdiff_disjoint.symm theorem disjoint_sdiff_inter (s t : Finset α) : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right sdiff_disjoint end Sdiff /-! ### attach -/ @[simp] theorem attach_empty : attach (∅ : Finset α) = ∅ := rfl @[simp] theorem attach_nonempty_iff {s : Finset α} : s.attach.Nonempty ↔ s.Nonempty := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] protected alias ⟨_, Nonempty.attach⟩ := attach_nonempty_iff @[simp] theorem attach_eq_empty_iff {s : Finset α} : s.attach = ∅ ↔ s = ∅ := by simp [eq_empty_iff_forall_not_mem] /-! ### filter -/ section Filter variable (p q : α → Prop) [DecidablePred p] [DecidablePred q] {s t : Finset α} theorem filter_singleton (a : α) : filter p {a} = if p a then {a} else ∅ := by classical ext x simp only [mem_singleton, forall_eq, mem_filter] split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] theorem filter_cons_of_pos (a : α) (s : Finset α) (ha : a ∉ s) (hp : p a) : filter p (cons a s ha) = cons a (filter p s) ((mem_of_mem_filter _).mt ha) := eq_of_veq <| Multiset.filter_cons_of_pos s.val hp theorem filter_cons_of_neg (a : α) (s : Finset α) (ha : a ∉ s) (hp : ¬p a) : filter p (cons a s ha) = filter p s := eq_of_veq <| Multiset.filter_cons_of_neg s.val hp theorem disjoint_filter {s : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] : Disjoint (s.filter p) (s.filter q) ↔ ∀ x ∈ s, p x → ¬q x := by constructor <;> simp +contextual [disjoint_left] theorem disjoint_filter_filter' (s t : Finset α) {p q : α → Prop} [DecidablePred p] [DecidablePred q] (h : Disjoint p q) : Disjoint (s.filter p) (t.filter q) := by simp_rw [disjoint_left, mem_filter] rintro a ⟨_, hp⟩ ⟨_, hq⟩ rw [Pi.disjoint_iff] at h simpa [hp, hq] using h a theorem disjoint_filter_filter_neg (s t : Finset α) (p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] : Disjoint (s.filter p) (t.filter fun a => ¬p a) := disjoint_filter_filter' s t disjoint_compl_right theorem filter_disj_union (s : Finset α) (t : Finset α) (h : Disjoint s t) : filter p (disjUnion s t h) = (filter p s).disjUnion (filter p t) (disjoint_filter_filter h) := eq_of_veq <| Multiset.filter_add _ _ _ theorem filter_cons {a : α} (s : Finset α) (ha : a ∉ s) : filter p (cons a s ha) = if p a then cons a (filter p s) ((mem_of_mem_filter _).mt ha) else filter p s := by split_ifs with h · rw [filter_cons_of_pos _ _ _ ha h] · rw [filter_cons_of_neg _ _ _ ha h] section variable [DecidableEq α] theorem filter_union (s₁ s₂ : Finset α) : (s₁ ∪ s₂).filter p = s₁.filter p ∪ s₂.filter p := ext fun _ => by simp only [mem_filter, mem_union, or_and_right] theorem filter_union_right (s : Finset α) : s.filter p ∪ s.filter q = s.filter fun x => p x ∨ q x := ext fun x => by simp [mem_filter, mem_union, ← and_or_left] theorem filter_mem_eq_inter {s t : Finset α} [∀ i, Decidable (i ∈ t)] : (s.filter fun i => i ∈ t) = s ∩ t := ext fun i => by simp [mem_filter, mem_inter] theorem filter_inter_distrib (s t : Finset α) : (s ∩ t).filter p = s.filter p ∩ t.filter p := by ext simp [mem_filter, mem_inter, and_assoc] theorem filter_inter (s t : Finset α) : filter p s ∩ t = filter p (s ∩ t) := by ext simp only [mem_inter, mem_filter, and_right_comm] theorem inter_filter (s t : Finset α) : s ∩ filter p t = filter p (s ∩ t) := by rw [inter_comm, filter_inter, inter_comm] theorem filter_insert (a : α) (s : Finset α) : filter p (insert a s) = if p a then insert a (filter p s) else filter p s := by ext x split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] theorem filter_erase (a : α) (s : Finset α) : filter p (erase s a) = erase (filter p s) a := by ext x simp only [and_assoc, mem_filter, iff_self, mem_erase] theorem filter_or (s : Finset α) : (s.filter fun a => p a ∨ q a) = s.filter p ∪ s.filter q := ext fun _ => by simp [mem_filter, mem_union, and_or_left] theorem filter_and (s : Finset α) : (s.filter fun a => p a ∧ q a) = s.filter p ∩ s.filter q := ext fun _ => by simp [mem_filter, mem_inter, and_comm, and_left_comm, and_self_iff, and_assoc] theorem filter_not (s : Finset α) : (s.filter fun a => ¬p a) = s \ s.filter p := ext fun a => by simp only [Bool.decide_coe, Bool.not_eq_true', mem_filter, and_comm, mem_sdiff, not_and_or, Bool.not_eq_true, and_or_left, and_not_self, or_false] lemma filter_and_not (s : Finset α) (p q : α → Prop) [DecidablePred p] [DecidablePred q] : s.filter (fun a ↦ p a ∧ ¬ q a) = s.filter p \ s.filter q := by rw [filter_and, filter_not, ← inter_sdiff_assoc, inter_eq_left.2 (filter_subset _ _)] theorem sdiff_eq_filter (s₁ s₂ : Finset α) : s₁ \ s₂ = filter (· ∉ s₂) s₁ := ext fun _ => by simp [mem_sdiff, mem_filter] theorem subset_union_elim {s : Finset α} {t₁ t₂ : Set α} (h : ↑s ⊆ t₁ ∪ t₂) : ∃ s₁ s₂ : Finset α, s₁ ∪ s₂ = s ∧ ↑s₁ ⊆ t₁ ∧ ↑s₂ ⊆ t₂ \ t₁ := by classical refine ⟨s.filter (· ∈ t₁), s.filter (· ∉ t₁), ?_, ?_, ?_⟩ · simp [filter_union_right, em] · intro x simp · intro x simp only [not_not, coe_filter, Set.mem_setOf_eq, Set.mem_diff, and_imp] intro hx hx₂ exact ⟨Or.resolve_left (h hx) hx₂, hx₂⟩ -- This is not a good simp lemma, as it would prevent `Finset.mem_filter` from firing -- on, e.g. `x ∈ s.filter (Eq b)`. /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq'` with the equality the other way. -/ theorem filter_eq [DecidableEq β] (s : Finset β) (b : β) : s.filter (Eq b) = ite (b ∈ s) {b} ∅ := by split_ifs with h · ext simp only [mem_filter, mem_singleton, decide_eq_true_eq] refine ⟨fun h => h.2.symm, ?_⟩ rintro rfl exact ⟨h, rfl⟩ · ext simp only [mem_filter, not_and, iff_false, not_mem_empty, decide_eq_true_eq] rintro m rfl exact h m /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq` with the equality the other way. -/ theorem filter_eq' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a = b) = ite (b ∈ s) {b} ∅ := _root_.trans (filter_congr fun _ _ => by simp_rw [@eq_comm _ b]) (filter_eq s b) theorem filter_ne [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => b ≠ a) = s.erase b := by ext simp only [mem_filter, mem_erase, Ne, decide_not, Bool.not_eq_true', decide_eq_false_iff_not] tauto theorem filter_ne' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a ≠ b) = s.erase b := _root_.trans (filter_congr fun _ _ => by simp_rw [@ne_comm _ b]) (filter_ne s b) theorem filter_union_filter_of_codisjoint (s : Finset α) (h : Codisjoint p q) : s.filter p ∪ s.filter q = s := (filter_or _ _ _).symm.trans <| filter_true_of_mem fun x _ => h.top_le x trivial theorem filter_union_filter_neg_eq [∀ x, Decidable (¬p x)] (s : Finset α) : (s.filter p ∪ s.filter fun a => ¬p a) = s := filter_union_filter_of_codisjoint _ _ _ <| @codisjoint_hnot_right _ _ p end end Filter /-! ### range -/ section Range open Nat variable {n m l : ℕ} @[simp] theorem range_filter_eq {n m : ℕ} : (range n).filter (· = m) = if m < n then {m} else ∅ := by convert filter_eq (range n) m using 2 · ext rw [eq_comm] · simp end Range end Finset /-! ### dedup on list and multiset -/ namespace Multiset variable [DecidableEq α] {s t : Multiset α} @[simp] theorem toFinset_add (s t : Multiset α) : toFinset (s + t) = toFinset s ∪ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_inter (s t : Multiset α) : toFinset (s ∩ t) = toFinset s ∩ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_union (s t : Multiset α) : (s ∪ t).toFinset = s.toFinset ∪ t.toFinset := by ext; simp @[simp] theorem toFinset_eq_empty {m : Multiset α} : m.toFinset = ∅ ↔ m = 0 := Finset.val_inj.symm.trans Multiset.dedup_eq_zero @[simp] theorem toFinset_nonempty : s.toFinset.Nonempty ↔ s ≠ 0 := by simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty] @[aesop safe apply (rule_sets := [finsetNonempty])] protected alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty @[simp] theorem toFinset_filter (s : Multiset α) (p : α → Prop) [DecidablePred p] : Multiset.toFinset (s.filter p) = s.toFinset.filter p := by ext; simp end Multiset namespace List variable [DecidableEq α] {l l' : List α} {a : α} {f : α → β} {s : Finset α} {t : Set β} {t' : Finset β} @[simp] theorem toFinset_union (l l' : List α) : (l ∪ l').toFinset = l.toFinset ∪ l'.toFinset := by ext simp @[simp] theorem toFinset_inter (l l' : List α) : (l ∩ l').toFinset = l.toFinset ∩ l'.toFinset := by ext simp @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty_iff @[simp] theorem toFinset_filter (s : List α) (p : α → Bool) : (s.filter p).toFinset = s.toFinset.filter (p ·) := by ext; simp [List.mem_filter] end List namespace Finset section ToList @[simp] theorem toList_eq_nil {s : Finset α} : s.toList = [] ↔ s = ∅ := Multiset.toList_eq_nil.trans val_eq_zero
Mathlib/Data/Finset/Basic.lean
581
583
theorem empty_toList {s : Finset α} : s.toList.isEmpty ↔ s = ∅ := by
simp @[simp]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker, Andrew Yang, Yuyang Zhao -/ import Mathlib.Algebra.Polynomial.Monic import Mathlib.RingTheory.Polynomial.ScaleRoots /-! # Theory of monic polynomials We define `integralNormalization`, which relate arbitrary polynomials to monic ones. -/ open Polynomial namespace Polynomial universe u v y variable {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y} section IntegralNormalization section Semiring variable [Semiring R] /-- If `p : R[X]` is a nonzero polynomial with root `z`, `integralNormalization p` is a monic polynomial with root `leadingCoeff f * z`. Moreover, `integralNormalization 0 = 0`. -/ noncomputable def integralNormalization (p : R[X]) : R[X] := p.sum fun i a ↦ monomial i (if p.degree = i then 1 else a * p.leadingCoeff ^ (p.natDegree - 1 - i)) @[simp] theorem integralNormalization_zero : integralNormalization (0 : R[X]) = 0 := by simp [integralNormalization] @[simp]
Mathlib/RingTheory/Polynomial/IntegralNormalization.lean
44
45
theorem integralNormalization_C {x : R} (hx : x ≠ 0) : integralNormalization (C x) = 1 := by
simp [integralNormalization, sum_def, support_C hx, degree_C hx]
/- Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.InnerProductSpace.Convex import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Combinatorics.Additive.AP.Three.Defs import Mathlib.Combinatorics.Pigeonhole import Mathlib.Data.Complex.ExponentialBounds /-! # Behrend's bound on Roth numbers This file proves Behrend's lower bound on Roth numbers. This says that we can find a subset of `{1, ..., n}` of size `n / exp (O (sqrt (log n)))` which does not contain arithmetic progressions of length `3`. The idea is that the sphere (in the `n` dimensional Euclidean space) doesn't contain arithmetic progressions (literally) because the corresponding ball is strictly convex. Thus we can take integer points on that sphere and map them onto `ℕ` in a way that preserves arithmetic progressions (`Behrend.map`). ## Main declarations * `Behrend.sphere`: The intersection of the Euclidean sphere with the positive integer quadrant. This is the set that we will map on `ℕ`. * `Behrend.map`: Given a natural number `d`, `Behrend.map d : ℕⁿ → ℕ` reads off the coordinates as digits in base `d`. * `Behrend.card_sphere_le_rothNumberNat`: Implicit lower bound on Roth numbers in terms of `Behrend.sphere`. * `Behrend.roth_lower_bound`: Behrend's explicit lower bound on Roth numbers. ## References * [Bryan Gillespie, *Behrend’s Construction*] (http://www.epsilonsmall.com/resources/behrends-construction/behrend.pdf) * Behrend, F. A., "On sets of integers which contain no three terms in arithmetical progression" * [Wikipedia, *Salem-Spencer set*](https://en.wikipedia.org/wiki/Salem–Spencer_set) ## Tags 3AP-free, Salem-Spencer, Behrend construction, arithmetic progression, sphere, strictly convex -/ assert_not_exists IsConformalMap Conformal open Nat hiding log open Finset Metric Real open scoped Pointwise /-- The frontier of a closed strictly convex set only contains trivial arithmetic progressions. The idea is that an arithmetic progression is contained on a line and the frontier of a strictly convex set does not contain lines. -/ lemma threeAPFree_frontier {𝕜 E : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [TopologicalSpace E] [AddCommMonoid E] [Module 𝕜 E] {s : Set E} (hs₀ : IsClosed s) (hs₁ : StrictConvex 𝕜 s) : ThreeAPFree (frontier s) := by intro a ha b hb c hc habc obtain rfl : (1 / 2 : 𝕜) • a + (1 / 2 : 𝕜) • c = b := by rwa [← smul_add, one_div, inv_smul_eq_iff₀ (show (2 : 𝕜) ≠ 0 by norm_num), two_smul] have := hs₁.eq (hs₀.frontier_subset ha) (hs₀.frontier_subset hc) one_half_pos one_half_pos (add_halves _) hb.2 simp [this, ← add_smul] ring_nf simp lemma threeAPFree_sphere {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [StrictConvexSpace ℝ E] (x : E) (r : ℝ) : ThreeAPFree (sphere x r) := by obtain rfl | hr := eq_or_ne r 0 · rw [sphere_zero] exact threeAPFree_singleton _ · convert threeAPFree_frontier isClosed_closedBall (strictConvex_closedBall ℝ x r) exact (frontier_closedBall _ hr).symm namespace Behrend variable {n d k N : ℕ} {x : Fin n → ℕ} /-! ### Turning the sphere into 3AP-free set We define `Behrend.sphere`, the intersection of the $L^2$ sphere with the positive quadrant of integer points. Because the $L^2$ closed ball is strictly convex, the $L^2$ sphere and `Behrend.sphere` are 3AP-free (`threeAPFree_sphere`). Then we can turn this set in `Fin n → ℕ` into a set in `ℕ` using `Behrend.map`, which preserves `ThreeAPFree` because it is an additive monoid homomorphism. -/ /-- The box `{0, ..., d - 1}^n` as a `Finset`. -/ def box (n d : ℕ) : Finset (Fin n → ℕ) := Fintype.piFinset fun _ => range d theorem mem_box : x ∈ box n d ↔ ∀ i, x i < d := by simp only [box, Fintype.mem_piFinset, mem_range] @[simp] theorem card_box : #(box n d) = d ^ n := by simp [box] @[simp] theorem box_zero : box (n + 1) 0 = ∅ := by simp [box] /-- The intersection of the sphere of radius `√k` with the integer points in the positive quadrant. -/ def sphere (n d k : ℕ) : Finset (Fin n → ℕ) := {x ∈ box n d | ∑ i, x i ^ 2 = k} theorem sphere_zero_subset : sphere n d 0 ⊆ 0 := fun x => by simp [sphere, funext_iff] @[simp] theorem sphere_zero_right (n k : ℕ) : sphere (n + 1) 0 k = ∅ := by simp [sphere] theorem sphere_subset_box : sphere n d k ⊆ box n d := filter_subset _ _ theorem norm_of_mem_sphere {x : Fin n → ℕ} (hx : x ∈ sphere n d k) : ‖(WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)‖ = √↑k := by rw [EuclideanSpace.norm_eq] dsimp simp_rw [abs_cast, ← cast_pow, ← cast_sum, (mem_filter.1 hx).2] theorem sphere_subset_preimage_metric_sphere : (sphere n d k : Set (Fin n → ℕ)) ⊆ (fun x : Fin n → ℕ => (WithLp.equiv 2 _).symm ((↑) ∘ x : Fin n → ℝ)) ⁻¹' Metric.sphere (0 : PiLp 2 fun _ : Fin n => ℝ) (√↑k) := fun x hx => by rw [Set.mem_preimage, mem_sphere_zero_iff_norm, norm_of_mem_sphere hx] /-- The map that appears in Behrend's bound on Roth numbers. -/ @[simps] def map (d : ℕ) : (Fin n → ℕ) →+ ℕ where toFun a := ∑ i, a i * d ^ (i : ℕ) map_zero' := by simp_rw [Pi.zero_apply, zero_mul, sum_const_zero] map_add' a b := by simp_rw [Pi.add_apply, add_mul, sum_add_distrib] theorem map_zero (d : ℕ) (a : Fin 0 → ℕ) : map d a = 0 := by simp [map] theorem map_succ (a : Fin (n + 1) → ℕ) : map d a = a 0 + (∑ x : Fin n, a x.succ * d ^ (x : ℕ)) * d := by simp [map, Fin.sum_univ_succ, _root_.pow_succ, ← mul_assoc, ← sum_mul] theorem map_succ' (a : Fin (n + 1) → ℕ) : map d a = a 0 + map d (a ∘ Fin.succ) * d := map_succ _ theorem map_monotone (d : ℕ) : Monotone (map d : (Fin n → ℕ) → ℕ) := fun x y h => by dsimp; exact sum_le_sum fun i _ => Nat.mul_le_mul_right _ <| h i theorem map_mod (a : Fin n.succ → ℕ) : map d a % d = a 0 % d := by rw [map_succ, Nat.add_mul_mod_self_right] theorem map_eq_iff {x₁ x₂ : Fin n.succ → ℕ} (hx₁ : ∀ i, x₁ i < d) (hx₂ : ∀ i, x₂ i < d) : map d x₁ = map d x₂ ↔ x₁ 0 = x₂ 0 ∧ map d (x₁ ∘ Fin.succ) = map d (x₂ ∘ Fin.succ) := by refine ⟨fun h => ?_, fun h => by rw [map_succ', map_succ', h.1, h.2]⟩ have : x₁ 0 = x₂ 0 := by rw [← mod_eq_of_lt (hx₁ _), ← map_mod, ← mod_eq_of_lt (hx₂ _), ← map_mod, h] rw [map_succ, map_succ, this, add_right_inj, mul_eq_mul_right_iff] at h exact ⟨this, h.resolve_right (pos_of_gt (hx₁ 0)).ne'⟩ theorem map_injOn : {x : Fin n → ℕ | ∀ i, x i < d}.InjOn (map d) := by intro x₁ hx₁ x₂ hx₂ h induction n with | zero => simp [eq_iff_true_of_subsingleton] | succ n ih => ext i have x := (map_eq_iff hx₁ hx₂).1 h exact Fin.cases x.1 (congr_fun <| ih (fun _ => hx₁ _) (fun _ => hx₂ _) x.2) i theorem map_le_of_mem_box (hx : x ∈ box n d) : map (2 * d - 1) x ≤ ∑ i : Fin n, (d - 1) * (2 * d - 1) ^ (i : ℕ) := map_monotone (2 * d - 1) fun _ => Nat.le_sub_one_of_lt <| mem_box.1 hx _ nonrec theorem threeAPFree_sphere : ThreeAPFree (sphere n d k : Set (Fin n → ℕ)) := by set f : (Fin n → ℕ) →+ EuclideanSpace ℝ (Fin n) := { toFun := fun f => ((↑) : ℕ → ℝ) ∘ f map_zero' := funext fun _ => cast_zero map_add' := fun _ _ => funext fun _ => cast_add _ _ } refine ThreeAPFree.of_image (AddMonoidHomClass.isAddFreimanHom f (Set.mapsTo_image _ _)) cast_injective.comp_left.injOn (Set.subset_univ _) ?_ refine (threeAPFree_sphere 0 (√↑k)).mono (Set.image_subset_iff.2 fun x => ?_) rw [Set.mem_preimage, mem_sphere_zero_iff_norm] exact norm_of_mem_sphere theorem threeAPFree_image_sphere : ThreeAPFree ((sphere n d k).image (map (2 * d - 1)) : Set ℕ) := by rw [coe_image] apply ThreeAPFree.image' (α := Fin n → ℕ) (β := ℕ) (s := sphere n d k) (map (2 * d - 1)) (map_injOn.mono _) threeAPFree_sphere rw [Set.add_subset_iff] rintro a ha b hb i have hai := mem_box.1 (sphere_subset_box ha) i have hbi := mem_box.1 (sphere_subset_box hb) i rw [lt_tsub_iff_right, ← succ_le_iff, two_mul] exact (add_add_add_comm _ _ 1 1).trans_le (_root_.add_le_add hai hbi)
Mathlib/Combinatorics/Additive/AP/Three/Behrend.lean
193
202
theorem sum_sq_le_of_mem_box (hx : x ∈ box n d) : ∑ i : Fin n, x i ^ 2 ≤ n * (d - 1) ^ 2 := by
rw [mem_box] at hx have : ∀ i, x i ^ 2 ≤ (d - 1) ^ 2 := fun i => Nat.pow_le_pow_left (Nat.le_sub_one_of_lt (hx i)) _ exact (sum_le_card_nsmul univ _ _ fun i _ => this i).trans (by rw [card_fin, smul_eq_mul]) theorem sum_eq : (∑ i : Fin n, d * (2 * d + 1) ^ (i : ℕ)) = ((2 * d + 1) ^ n - 1) / 2 := by refine (Nat.div_eq_of_eq_mul_left zero_lt_two ?_).symm rw [← sum_range fun i => d * (2 * d + 1) ^ (i : ℕ), ← mul_sum, mul_right_comm, mul_comm d, ← geom_sum_mul_add, add_tsub_cancel_right, mul_comm]
/- Copyright (c) 2021 Yuma Mizuno. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuma Mizuno -/ import Mathlib.CategoryTheory.NatIso /-! # Bicategories In this file we define typeclass for bicategories. A bicategory `B` consists of * objects `a : B`, * 1-morphisms `f : a ⟶ b` between objects `a b : B`, and * 2-morphisms `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` between objects `a b : B`. We use `u`, `v`, and `w` as the universe variables for objects, 1-morphisms, and 2-morphisms, respectively. A typeclass for bicategories extends `CategoryTheory.CategoryStruct` typeclass. This means that we have * a composition `f ≫ g : a ⟶ c` for each 1-morphisms `f : a ⟶ b` and `g : b ⟶ c`, and * an identity `𝟙 a : a ⟶ a` for each object `a : B`. For each object `a b : B`, the collection of 1-morphisms `a ⟶ b` has a category structure. The 2-morphisms in the bicategory are implemented as the morphisms in this family of categories. The composition of 1-morphisms is in fact an object part of a functor `(a ⟶ b) ⥤ (b ⟶ c) ⥤ (a ⟶ c)`. The definition of bicategories in this file does not require this functor directly. Instead, it requires the whiskering functions. For a 1-morphism `f : a ⟶ b` and a 2-morphism `η : g ⟶ h` between 1-morphisms `g h : b ⟶ c`, there is a 2-morphism `whiskerLeft f η : f ≫ g ⟶ f ≫ h`. Similarly, for a 2-morphism `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` and a 1-morphism `f : b ⟶ c`, there is a 2-morphism `whiskerRight η h : f ≫ h ⟶ g ≫ h`. These satisfy the exchange law `whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ`, which is required as an axiom in the definition here. -/ namespace CategoryTheory universe w v u open Category Iso -- intended to be used with explicit universe parameters /-- In a bicategory, we can compose the 1-morphisms `f : a ⟶ b` and `g : b ⟶ c` to obtain a 1-morphism `f ≫ g : a ⟶ c`. This composition does not need to be strictly associative, but there is a specified associator, `α_ f g h : (f ≫ g) ≫ h ≅ f ≫ (g ≫ h)`. There is an identity 1-morphism `𝟙 a : a ⟶ a`, with specified left and right unitor isomorphisms `λ_ f : 𝟙 a ≫ f ≅ f` and `ρ_ f : f ≫ 𝟙 a ≅ f`. These associators and unitors satisfy the pentagon and triangle equations. See https://ncatlab.org/nlab/show/bicategory. -/ @[nolint checkUnivs] class Bicategory (B : Type u) extends CategoryStruct.{v} B where /-- The category structure on the collection of 1-morphisms -/ homCategory : ∀ a b : B, Category.{w} (a ⟶ b) := by infer_instance /-- Left whiskering for morphisms -/ whiskerLeft {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) : f ≫ g ⟶ f ≫ h /-- Right whiskering for morphisms -/ whiskerRight {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) : f ≫ h ⟶ g ≫ h /-- The associator isomorphism: `(f ≫ g) ≫ h ≅ f ≫ g ≫ h` -/ associator {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (f ≫ g) ≫ h ≅ f ≫ g ≫ h /-- The left unitor: `𝟙 a ≫ f ≅ f` -/ leftUnitor {a b : B} (f : a ⟶ b) : 𝟙 a ≫ f ≅ f /-- The right unitor: `f ≫ 𝟙 b ≅ f` -/ rightUnitor {a b : B} (f : a ⟶ b) : f ≫ 𝟙 b ≅ f -- axioms for left whiskering: whiskerLeft_id : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerLeft f (𝟙 g) = 𝟙 (f ≫ g) := by aesop_cat whiskerLeft_comp : ∀ {a b c} (f : a ⟶ b) {g h i : b ⟶ c} (η : g ⟶ h) (θ : h ⟶ i), whiskerLeft f (η ≫ θ) = whiskerLeft f η ≫ whiskerLeft f θ := by aesop_cat id_whiskerLeft : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerLeft (𝟙 a) η = (leftUnitor f).hom ≫ η ≫ (leftUnitor g).inv := by aesop_cat comp_whiskerLeft : ∀ {a b c d} (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h'), whiskerLeft (f ≫ g) η = (associator f g h).hom ≫ whiskerLeft f (whiskerLeft g η) ≫ (associator f g h').inv := by aesop_cat -- axioms for right whiskering: id_whiskerRight : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerRight (𝟙 f) g = 𝟙 (f ≫ g) := by aesop_cat comp_whiskerRight : ∀ {a b c} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h) (i : b ⟶ c), whiskerRight (η ≫ θ) i = whiskerRight η i ≫ whiskerRight θ i := by aesop_cat whiskerRight_id : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerRight η (𝟙 b) = (rightUnitor f).hom ≫ η ≫ (rightUnitor g).inv := by aesop_cat whiskerRight_comp : ∀ {a b c d} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d), whiskerRight η (g ≫ h) = (associator f g h).inv ≫ whiskerRight (whiskerRight η g) h ≫ (associator f' g h).hom := by aesop_cat -- associativity of whiskerings: whisker_assoc : ∀ {a b c d} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d), whiskerRight (whiskerLeft f η) h = (associator f g h).hom ≫ whiskerLeft f (whiskerRight η h) ≫ (associator f g' h).inv := by aesop_cat -- exchange law of left and right whiskerings: whisker_exchange : ∀ {a b c} {f g : a ⟶ b} {h i : b ⟶ c} (η : f ⟶ g) (θ : h ⟶ i), whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ := by aesop_cat -- pentagon identity: pentagon : ∀ {a b c d e} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e), whiskerRight (associator f g h).hom i ≫ (associator f (g ≫ h) i).hom ≫ whiskerLeft f (associator g h i).hom = (associator (f ≫ g) h i).hom ≫ (associator f g (h ≫ i)).hom := by aesop_cat -- triangle identity: triangle : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), (associator f (𝟙 b) g).hom ≫ whiskerLeft f (leftUnitor g).hom = whiskerRight (rightUnitor f).hom g := by aesop_cat namespace Bicategory @[inherit_doc] scoped infixr:81 " ◁ " => Bicategory.whiskerLeft @[inherit_doc] scoped infixl:81 " ▷ " => Bicategory.whiskerRight @[inherit_doc] scoped notation "α_" => Bicategory.associator @[inherit_doc] scoped notation "λ_" => Bicategory.leftUnitor @[inherit_doc] scoped notation "ρ_" => Bicategory.rightUnitor /-! ### Simp-normal form for 2-morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any 2-morphisms into simp-normal form defined below. Rewriting into simp-normal form is also useful when applying (forthcoming) `coherence` tactic. The simp-normal form of 2-morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of 2-morphisms like `η₁ ≫ η₂ ≫ η₃ ≫ η₄ ≫ η₅` such that each `ηᵢ` is either a structural 2-morphisms (2-morphisms made up only of identities, associators, unitors) or non-structural 2-morphisms, and 2. each non-structural 2-morphism in the composition is of the form `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅`, where each `fᵢ` is a 1-morphism that is not the identity or a composite and `η` is a non-structural 2-morphisms that is also not the identity or a composite. Note that `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅` is actually `f₁ ◁ (f₂ ◁ (f₃ ◁ ((η ▷ f₄) ▷ f₅)))`. -/ attribute [instance] homCategory attribute [reassoc] whiskerLeft_comp id_whiskerLeft comp_whiskerLeft comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc whisker_exchange attribute [reassoc (attr := simp)] pentagon triangle /- The following simp attributes are put in order to rewrite any 2-morphisms into normal forms. There are associators and unitors in the RHS in the several simp lemmas here (e.g. `id_whiskerLeft`), which at first glance look more complicated than the LHS, but they will be eventually reduced by the pentagon or the triangle identities, and more generally, (forthcoming) `coherence` tactic. -/ attribute [simp] whiskerLeft_id whiskerLeft_comp id_whiskerLeft comp_whiskerLeft id_whiskerRight comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc variable {B : Type u} [Bicategory.{w, v} B] {a b c d e : B} @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.hom ≫ f ◁ η.inv = 𝟙 (f ≫ g) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.hom ▷ h ≫ η.inv ▷ h = 𝟙 (f ≫ h) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.inv ≫ f ◁ η.hom = 𝟙 (f ≫ h) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.inv ▷ h ≫ η.hom ▷ h = 𝟙 (g ≫ h) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] /-- The left whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps] def whiskerLeftIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ≫ g ≅ f ≫ h where hom := f ◁ η.hom inv := f ◁ η.inv instance whiskerLeft_isIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : IsIso (f ◁ η) := (whiskerLeftIso f (asIso η)).isIso_hom @[simp] theorem inv_whiskerLeft (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : inv (f ◁ η) = f ◁ inv η := by apply IsIso.inv_eq_of_hom_inv_id simp only [← whiskerLeft_comp, whiskerLeft_id, IsIso.hom_inv_id] /-- The right whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps!] def whiskerRightIso {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : f ≫ h ≅ g ≫ h where hom := η.hom ▷ h inv := η.inv ▷ h instance whiskerRight_isIso {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : IsIso (η ▷ h) := (whiskerRightIso (asIso η) h).isIso_hom @[simp] theorem inv_whiskerRight {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : inv (η ▷ h) = inv η ▷ h := by apply IsIso.inv_eq_of_hom_inv_id simp only [← comp_whiskerRight, id_whiskerRight, IsIso.hom_inv_id] @[reassoc (attr := simp)] theorem pentagon_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i = (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom = f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv := by rw [← cancel_epi (f ◁ (α_ g h i).inv), ← cancel_mono (α_ (f ≫ g) h i).inv] simp @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom = (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv = (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i := by simp [← cancel_epi (f ◁ (α_ g h i).inv)] @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv = (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv = (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i := by rw [← cancel_epi (α_ f g (h ≫ i)).inv, ← cancel_mono ((α_ f g h).inv ▷ i)] simp @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv = (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom = (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom := by simp [← cancel_epi ((α_ f g h).hom ▷ i)] @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i = f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv := eq_of_inv_eq_inv (by simp) theorem triangle_assoc_comp_left (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).hom ≫ f ◁ (λ_ g).hom = (ρ_ f).hom ▷ g := triangle f g @[reassoc (attr := simp)] theorem triangle_assoc_comp_right (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).inv ≫ (ρ_ f).hom ▷ g = f ◁ (λ_ g).hom := by rw [← triangle, inv_hom_id_assoc] @[reassoc (attr := simp)] theorem triangle_assoc_comp_right_inv (f : a ⟶ b) (g : b ⟶ c) : (ρ_ f).inv ▷ g ≫ (α_ f (𝟙 b) g).hom = f ◁ (λ_ g).inv := by simp [← cancel_mono (f ◁ (λ_ g).hom)] @[reassoc (attr := simp)] theorem triangle_assoc_comp_left_inv (f : a ⟶ b) (g : b ⟶ c) : f ◁ (λ_ g).inv ≫ (α_ f (𝟙 b) g).inv = (ρ_ f).inv ▷ g := by simp [← cancel_mono ((ρ_ f).hom ▷ g)] @[reassoc]
Mathlib/CategoryTheory/Bicategory/Basic.lean
296
299
theorem associator_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ g ▷ h ≫ (α_ f' g h).hom = (α_ f g h).hom ≫ η ▷ (g ≫ h) := by
simp @[reassoc]
/- Copyright (c) 2024 Emilie Burgun. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Emilie Burgun -/ import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Dynamics.PeriodicPts.Defs import Mathlib.GroupTheory.GroupAction.Defs /-! # Properties of `fixedPoints` and `fixedBy` This module contains some useful properties of `MulAction.fixedPoints` and `MulAction.fixedBy` that don't directly belong to `Mathlib.GroupTheory.GroupAction.Basic`. ## Main theorems * `MulAction.fixedBy_mul`: `fixedBy α (g * h) ⊆ fixedBy α g ∪ fixedBy α h` * `MulAction.fixedBy_conj` and `MulAction.smul_fixedBy`: the pointwise group action of `h` on `fixedBy α g` is equal to the `fixedBy` set of the conjugation of `h` with `g` (`fixedBy α (h * g * h⁻¹)`). * `MulAction.set_mem_fixedBy_of_movedBy_subset` shows that if a set `s` is a superset of `(fixedBy α g)ᶜ`, then the group action of `g` cannot send elements of `s` outside of `s`. This is expressed as `s ∈ fixedBy (Set α) g`, and `MulAction.set_mem_fixedBy_iff` allows one to convert the relationship back to `g • x ∈ s ↔ x ∈ s`. * `MulAction.not_commute_of_disjoint_smul_movedBy` allows one to prove that `g` and `h` do not commute from the disjointness of the `(fixedBy α g)ᶜ` set and `h • (fixedBy α g)ᶜ`, which is a property used in the proof of Rubin's theorem. The theorems above are also available for `AddAction`. ## Pointwise group action and `fixedBy (Set α) g` Since `fixedBy α g = { x | g • x = x }` by definition, properties about the pointwise action of a set `s : Set α` can be expressed using `fixedBy (Set α) g`. To properly use theorems using `fixedBy (Set α) g`, you should `open Pointwise` in your file. `s ∈ fixedBy (Set α) g` means that `g • s = s`, which is equivalent to say that `∀ x, g • x ∈ s ↔ x ∈ s` (the translation can be done using `MulAction.set_mem_fixedBy_iff`). `s ∈ fixedBy (Set α) g` is a weaker statement than `s ⊆ fixedBy α g`: the latter requires that all points in `s` are fixed by `g`, whereas the former only requires that `g • x ∈ s`. -/ namespace MulAction open Pointwise variable {α : Type*} variable {G : Type*} [Group G] [MulAction G α] variable {M : Type*} [Monoid M] [MulAction M α] section FixedPoints variable (α) in /-- In a multiplicative group action, the points fixed by `g` are also fixed by `g⁻¹` -/ @[to_additive (attr := simp) "In an additive group action, the points fixed by `g` are also fixed by `g⁻¹`"] theorem fixedBy_inv (g : G) : fixedBy α g⁻¹ = fixedBy α g := by ext rw [mem_fixedBy, mem_fixedBy, inv_smul_eq_iff, eq_comm] @[to_additive] theorem smul_mem_fixedBy_iff_mem_fixedBy {a : α} {g : G} : g • a ∈ fixedBy α g ↔ a ∈ fixedBy α g := by rw [mem_fixedBy, smul_left_cancel_iff] rfl @[to_additive] theorem smul_inv_mem_fixedBy_iff_mem_fixedBy {a : α} {g : G} : g⁻¹ • a ∈ fixedBy α g ↔ a ∈ fixedBy α g := by rw [← fixedBy_inv, smul_mem_fixedBy_iff_mem_fixedBy, fixedBy_inv] @[to_additive minimalPeriod_eq_one_iff_fixedBy] theorem minimalPeriod_eq_one_iff_fixedBy {a : α} {g : G} : Function.minimalPeriod (fun x => g • x) a = 1 ↔ a ∈ fixedBy α g := Function.minimalPeriod_eq_one_iff_isFixedPt variable (α) in @[to_additive]
Mathlib/GroupTheory/GroupAction/FixedPoints.lean
82
87
theorem fixedBy_subset_fixedBy_zpow (g : G) (j : ℤ) : fixedBy α g ⊆ fixedBy α (g ^ j) := by
intro a a_in_fixedBy rw [mem_fixedBy, zpow_smul_eq_iff_minimalPeriod_dvd, minimalPeriod_eq_one_iff_fixedBy.mpr a_in_fixedBy, Int.natCast_one] exact one_dvd j
/- 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, Yury Kudryashov -/ import Mathlib.Data.Finset.Fin import Mathlib.Order.Interval.Finset.Nat import Mathlib.Order.Interval.Set.Fin /-! # Finite intervals in `Fin n` This file proves that `Fin n` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as Finsets and Fintypes. -/ assert_not_exists MonoidWithZero open Finset Function namespace Fin variable (n : ℕ) /-! ### Locally finite order etc instances -/ instance instLocallyFiniteOrder (n : ℕ) : LocallyFiniteOrder (Fin n) where finsetIcc a b := attachFin (Icc a b) fun x hx ↦ (mem_Icc.mp hx).2.trans_lt b.2 finsetIco a b := attachFin (Ico a b) fun x hx ↦ (mem_Ico.mp hx).2.trans b.2 finsetIoc a b := attachFin (Ioc a b) fun x hx ↦ (mem_Ioc.mp hx).2.trans_lt b.2 finsetIoo a b := attachFin (Ioo a b) fun x hx ↦ (mem_Ioo.mp hx).2.trans b.2 finset_mem_Icc a b := by simp finset_mem_Ico a b := by simp finset_mem_Ioc a b := by simp finset_mem_Ioo a b := by simp instance instLocallyFiniteOrderBot : ∀ n, LocallyFiniteOrderBot (Fin n) | 0 => IsEmpty.toLocallyFiniteOrderBot | _ + 1 => inferInstance instance instLocallyFiniteOrderTop : ∀ n, LocallyFiniteOrderTop (Fin n) | 0 => IsEmpty.toLocallyFiniteOrderTop | _ + 1 => inferInstance variable {n} variable {m : ℕ} (a b : Fin n) @[simp] theorem attachFin_Icc : attachFin (Icc a b) (fun _x hx ↦ (mem_Icc.mp hx).2.trans_lt b.2) = Icc a b := rfl @[simp] theorem attachFin_Ico : attachFin (Ico a b) (fun _x hx ↦ (mem_Ico.mp hx).2.trans b.2) = Ico a b := rfl @[simp] theorem attachFin_Ioc : attachFin (Ioc a b) (fun _x hx ↦ (mem_Ioc.mp hx).2.trans_lt b.2) = Ioc a b := rfl @[simp] theorem attachFin_Ioo : attachFin (Ioo a b) (fun _x hx ↦ (mem_Ioo.mp hx).2.trans b.2) = Ioo a b := rfl @[simp] theorem attachFin_uIcc : attachFin (uIcc a b) (fun _x hx ↦ (mem_Icc.mp hx).2.trans_lt (max a b).2) = uIcc a b := rfl @[simp] theorem attachFin_Ico_eq_Ici : attachFin (Ico a n) (fun _x hx ↦ (mem_Ico.mp hx).2) = Ici a := by ext; simp @[simp] theorem attachFin_Ioo_eq_Ioi : attachFin (Ioo a n) (fun _x hx ↦ (mem_Ioo.mp hx).2) = Ioi a := by ext; simp @[simp] theorem attachFin_Iic : attachFin (Iic a) (fun _x hx ↦ (mem_Iic.mp hx).trans_lt a.2) = Iic a := by ext; simp @[simp] theorem attachFin_Iio : attachFin (Iio a) (fun _x hx ↦ (mem_Iio.mp hx).trans a.2) = Iio a := by ext; simp section deprecated set_option linter.deprecated false in @[deprecated attachFin_Icc (since := "2025-04-06")] theorem Icc_eq_finset_subtype : Icc a b = (Icc (a : ℕ) b).fin n := attachFin_eq_fin _ set_option linter.deprecated false in @[deprecated attachFin_Ico (since := "2025-04-06")] theorem Ico_eq_finset_subtype : Ico a b = (Ico (a : ℕ) b).fin n := attachFin_eq_fin _ set_option linter.deprecated false in @[deprecated attachFin_Ioc (since := "2025-04-06")] theorem Ioc_eq_finset_subtype : Ioc a b = (Ioc (a : ℕ) b).fin n := attachFin_eq_fin _ set_option linter.deprecated false in @[deprecated attachFin_Ioo (since := "2025-04-06")] theorem Ioo_eq_finset_subtype : Ioo a b = (Ioo (a : ℕ) b).fin n := attachFin_eq_fin _ set_option linter.deprecated false in @[deprecated attachFin_uIcc (since := "2025-04-06")] theorem uIcc_eq_finset_subtype : uIcc a b = (uIcc (a : ℕ) b).fin n := Icc_eq_finset_subtype _ _ set_option linter.deprecated false in @[deprecated attachFin_Ico_eq_Ici (since := "2025-04-06")] theorem Ici_eq_finset_subtype : Ici a = (Ico (a : ℕ) n).fin n := by ext; simp set_option linter.deprecated false in @[deprecated attachFin_Ioo_eq_Ioi (since := "2025-04-06")] theorem Ioi_eq_finset_subtype : Ioi a = (Ioo (a : ℕ) n).fin n := by ext; simp set_option linter.deprecated false in @[deprecated attachFin_Iic (since := "2025-04-06")] theorem Iic_eq_finset_subtype : Iic b = (Iic (b : ℕ)).fin n := by ext; simp set_option linter.deprecated false in @[deprecated attachFin_Iio (since := "2025-04-06")] theorem Iio_eq_finset_subtype : Iio b = (Iio (b : ℕ)).fin n := by ext; simp end deprecated section val /-! ### Images under `Fin.val` -/ @[simp] theorem finsetImage_val_Icc : (Icc a b).image val = Icc (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_Ico : (Ico a b).image val = Ico (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_Ioc : (Ioc a b).image val = Ioc (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_Ioo : (Ioo a b).image val = Ioo (a : ℕ) b := image_val_attachFin _ @[simp] theorem finsetImage_val_uIcc : (uIcc a b).image val = uIcc (a : ℕ) b := finsetImage_val_Icc _ _ @[simp] theorem finsetImage_val_Ici : (Ici a).image val = Ico (a : ℕ) n := by simp [← coe_inj] @[simp]
Mathlib/Order/Interval/Finset/Fin.lean
161
163
theorem finsetImage_val_Ioi : (Ioi a).image val = Ioo (a : ℕ) n := by
simp [← coe_inj] @[simp]
/- 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.Order.Interval.Finset.Nat import Mathlib.Data.PNat.Defs /-! # Finite intervals of positive naturals This file proves that `ℕ+` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as finsets and fintypes. -/ open Finset Function PNat namespace PNat variable (a b : ℕ+) instance instLocallyFiniteOrder : LocallyFiniteOrder ℕ+ := Subtype.instLocallyFiniteOrder _ theorem Icc_eq_finset_subtype : Icc a b = (Icc (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl theorem Ico_eq_finset_subtype : Ico a b = (Ico (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl theorem Ioc_eq_finset_subtype : Ioc a b = (Ioc (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl theorem Ioo_eq_finset_subtype : Ioo a b = (Ioo (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl theorem uIcc_eq_finset_subtype : uIcc a b = (uIcc (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl theorem map_subtype_embedding_Icc : (Icc a b).map (Embedding.subtype _) = Icc ↑a ↑b := Finset.map_subtype_embedding_Icc _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx theorem map_subtype_embedding_Ico : (Ico a b).map (Embedding.subtype _) = Ico ↑a ↑b := Finset.map_subtype_embedding_Ico _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx theorem map_subtype_embedding_Ioc : (Ioc a b).map (Embedding.subtype _) = Ioc ↑a ↑b := Finset.map_subtype_embedding_Ioc _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx theorem map_subtype_embedding_Ioo : (Ioo a b).map (Embedding.subtype _) = Ioo ↑a ↑b := Finset.map_subtype_embedding_Ioo _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx theorem map_subtype_embedding_uIcc : (uIcc a b).map (Embedding.subtype _) = uIcc ↑a ↑b := map_subtype_embedding_Icc _ _ @[simp] theorem card_Icc : #(Icc a b) = b + 1 - a := by rw [← Nat.card_Icc, ← map_subtype_embedding_Icc, card_map] @[simp] theorem card_Ico : #(Ico a b) = b - a := by rw [← Nat.card_Ico, ← map_subtype_embedding_Ico, card_map] @[simp] theorem card_Ioc : #(Ioc a b) = b - a := by rw [← Nat.card_Ioc, ← map_subtype_embedding_Ioc, card_map] @[simp]
Mathlib/Data/PNat/Interval.lean
67
72
theorem card_Ioo : #(Ioo a b) = b - a - 1 := by
rw [← Nat.card_Ioo, ← map_subtype_embedding_Ioo, card_map] @[simp] theorem card_uIcc : #(uIcc a b) = (b - a : ℤ).natAbs + 1 := by rw [← Nat.card_uIcc, ← map_subtype_embedding_uIcc, card_map]
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Thomas Read, Andrew Yang, Dagur Asgeirsson, Joël Riou -/ import Mathlib.CategoryTheory.Adjunction.Mates /-! # Uniqueness of adjoints This file shows that adjoints are unique up to natural isomorphism. ## Main results * `Adjunction.leftAdjointUniq` : If `F` and `F'` are both left adjoint to `G`, then they are naturally isomorphic. * `Adjunction.rightAdjointUniq` : If `G` and `G'` are both right adjoint to `F`, then they are naturally isomorphic. -/ open CategoryTheory variable {C D : Type*} [Category C] [Category D] namespace CategoryTheory.Adjunction attribute [local simp] homEquiv_unit homEquiv_counit /-- If `F` and `F'` are both left adjoint to `G`, then they are naturally isomorphic. -/ def leftAdjointUniq {F F' : C ⥤ D} {G : D ⥤ C} (adj1 : F ⊣ G) (adj2 : F' ⊣ G) : F ≅ F' := ((conjugateIsoEquiv adj1 adj2).symm (Iso.refl G)).symm theorem homEquiv_leftAdjointUniq_hom_app {F F' : C ⥤ D} {G : D ⥤ C} (adj1 : F ⊣ G) (adj2 : F' ⊣ G) (x : C) : adj1.homEquiv _ _ ((leftAdjointUniq adj1 adj2).hom.app x) = adj2.unit.app x := by simp [leftAdjointUniq] @[reassoc (attr := simp)] theorem unit_leftAdjointUniq_hom {F F' : C ⥤ D} {G : D ⥤ C} (adj1 : F ⊣ G) (adj2 : F' ⊣ G) : adj1.unit ≫ whiskerRight (leftAdjointUniq adj1 adj2).hom G = adj2.unit := by ext x rw [NatTrans.comp_app, ← homEquiv_leftAdjointUniq_hom_app adj1 adj2] simp [← G.map_comp] @[reassoc (attr := simp)] theorem unit_leftAdjointUniq_hom_app {F F' : C ⥤ D} {G : D ⥤ C} (adj1 : F ⊣ G) (adj2 : F' ⊣ G) (x : C) : adj1.unit.app x ≫ G.map ((leftAdjointUniq adj1 adj2).hom.app x) = adj2.unit.app x := by rw [← unit_leftAdjointUniq_hom adj1 adj2]; rfl @[reassoc (attr := simp)] theorem leftAdjointUniq_hom_counit {F F' : C ⥤ D} {G : D ⥤ C} (adj1 : F ⊣ G) (adj2 : F' ⊣ G) : whiskerLeft G (leftAdjointUniq adj1 adj2).hom ≫ adj2.counit = adj1.counit := by ext x simp only [Functor.comp_obj, Functor.id_obj, leftAdjointUniq, Iso.symm_hom, conjugateIsoEquiv_symm_apply_inv, Iso.refl_inv, NatTrans.comp_app, whiskerLeft_app, conjugateEquiv_symm_apply_app, NatTrans.id_app, Functor.map_id, Category.id_comp, Category.assoc] rw [← adj1.counit_naturality, ← Category.assoc, ← F.map_comp] simp @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Adjunction/Unique.lean
64
66
theorem leftAdjointUniq_hom_app_counit {F F' : C ⥤ D} {G : D ⥤ C} (adj1 : F ⊣ G) (adj2 : F' ⊣ G) (x : D) : (leftAdjointUniq adj1 adj2).hom.app (G.obj x) ≫ adj2.counit.app x = adj1.counit.app x := by
/- 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.PropInstances import Mathlib.Order.GaloisConnection.Defs /-! # Heyting algebras This file defines Heyting, co-Heyting and bi-Heyting algebras. A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that `a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`. Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬` such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`. Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras. From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas boolean algebras model classical logic. Heyting algebras are the order theoretic equivalent of cartesian-closed categories. ## Main declarations * `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation). * `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement). * `HeytingAlgebra`: Heyting algebra. * `CoheytingAlgebra`: Co-Heyting algebra. * `BiheytingAlgebra`: bi-Heyting algebra. ## References * [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3] ## Tags Heyting, Brouwer, algebra, implication, negation, intuitionistic -/ assert_not_exists RelIso open Function OrderDual universe u variable {ι α β : Type*} /-! ### Notation -/ section variable (α β) instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) := ⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩ instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) := ⟨fun a => (¬a.1, ¬a.2)⟩ instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) := ⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩ instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) := ⟨fun a => (a.1ᶜ, a.2ᶜ)⟩ end @[simp] theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 := rfl @[simp] theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 := rfl @[simp] theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 := rfl @[simp] theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 := rfl @[simp] theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 := rfl @[simp] theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 := rfl @[simp] theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ := rfl @[simp] theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ := rfl namespace Pi variable {π : ι → Type*} instance [∀ i, HImp (π i)] : HImp (∀ i, π i) := ⟨fun a b i => a i ⇨ b i⟩ instance [∀ i, HNot (π i)] : HNot (∀ i, π i) := ⟨fun a i => ¬a i⟩ theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i := rfl theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i := rfl @[simp] theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i := rfl @[simp] theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i := rfl end Pi /-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. This generalizes `HeytingAlgebra` by not requiring a bottom element. -/ class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where /-- `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)` -/ le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c /-- A generalized co-Heyting algebra is a lattice with an additional binary difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`. This generalizes `CoheytingAlgebra` by not requiring a top element. -/ class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where /-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. -/ class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where /-- `aᶜ` is defined as `a ⇨ ⊥` -/ himp_bot (a : α) : a ⇨ ⊥ = aᶜ /-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`. -/ class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a /-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/ class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where /-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a -- See note [lower instance priority] attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot -- See note [lower instance priority] instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α := { bot_le := ‹HeytingAlgebra α›.bot_le } -- See note [lower instance priority] instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α := { ‹CoheytingAlgebra α› with } -- See note [lower instance priority] instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] : CoheytingAlgebra α := { ‹BiheytingAlgebra α› with } -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/ abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α) (le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with himp, compl := fun a => himp a ⊥, le_himp_iff, himp_bot := fun _ => rfl } -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/ abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α) (le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where himp := (compl · ⊔ ·) compl := compl le_himp_iff := le_himp_iff himp_bot _ := sup_bot_eq _ -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/ abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α) (sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with sdiff, hnot := fun a => sdiff ⊤ a, sdiff_le_iff, top_sdiff := fun _ => rfl } -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/ abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α) (sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where sdiff a b := a ⊓ hnot b hnot := hnot sdiff_le_iff := sdiff_le_iff top_sdiff _ := top_inf_eq _ /-! In this section, we'll give interpretations of these results in the Heyting algebra model of intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and", `⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are the same in this logic. See also `Prop.heytingAlgebra`. -/ section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] {a b c d : α} /-- `p → q → r ↔ p ∧ q → r` -/ @[simp] theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c := GeneralizedHeytingAlgebra.le_himp_iff _ _ _ /-- `p → q → r ↔ q ∧ p → r` -/ theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm] /-- `p → q → r ↔ q → p → r` -/ theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff'] /-- `p → q → p` -/ theorem le_himp : a ≤ b ⇨ a := le_himp_iff.2 inf_le_left /-- `p → p → q ↔ p → q` -/ theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem] /-- `p → p` -/ @[simp] theorem himp_self : a ⇨ a = ⊤ := top_le_iff.1 <| le_himp_iff.2 inf_le_right /-- `(p → q) ∧ p → q` -/ theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b := le_himp_iff.1 le_rfl /-- `p ∧ (p → q) → q` -/ theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff] /-- `p ∧ (p → q) ↔ p ∧ q` -/ @[simp] theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b := le_antisymm (le_inf inf_le_left <| by rw [inf_comm, ← le_himp_iff]) <| inf_le_inf_left _ le_himp /-- `(p → q) ∧ p ↔ q ∧ p` -/ @[simp] theorem himp_inf_self (a b : α) : (a ⇨ b) ⊓ a = b ⊓ a := by rw [inf_comm, inf_himp, inf_comm] /-- The **deduction theorem** in the Heyting algebra model of intuitionistic logic: an implication holds iff the conclusion follows from the hypothesis. -/ @[simp] theorem himp_eq_top_iff : a ⇨ b = ⊤ ↔ a ≤ b := by rw [← top_le_iff, le_himp_iff, top_inf_eq] /-- `p → true`, `true → p ↔ p` -/ @[simp] theorem himp_top : a ⇨ ⊤ = ⊤ := himp_eq_top_iff.2 le_top @[simp] theorem top_himp : ⊤ ⇨ a = a := eq_of_forall_le_iff fun b => by rw [le_himp_iff, inf_top_eq] /-- `p → q → r ↔ p ∧ q → r` -/ theorem himp_himp (a b c : α) : a ⇨ b ⇨ c = a ⊓ b ⇨ c := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, inf_assoc] /-- `(q → r) → (p → q) → q → r` -/ theorem himp_le_himp_himp_himp : b ⇨ c ≤ (a ⇨ b) ⇨ a ⇨ c := by rw [le_himp_iff, le_himp_iff, inf_assoc, himp_inf_self, ← inf_assoc, himp_inf_self, inf_assoc] exact inf_le_left @[simp] theorem himp_inf_himp_inf_le : (b ⇨ c) ⊓ (a ⇨ b) ⊓ a ≤ c := by simpa using @himp_le_himp_himp_himp /-- `p → q → r ↔ q → p → r` -/ theorem himp_left_comm (a b c : α) : a ⇨ b ⇨ c = b ⇨ a ⇨ c := by simp_rw [himp_himp, inf_comm] @[simp] theorem himp_idem : b ⇨ b ⇨ a = b ⇨ a := by rw [himp_himp, inf_idem] theorem himp_inf_distrib (a b c : α) : a ⇨ b ⊓ c = (a ⇨ b) ⊓ (a ⇨ c) := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, le_inf_iff, le_himp_iff] theorem sup_himp_distrib (a b c : α) : a ⊔ b ⇨ c = (a ⇨ c) ⊓ (b ⇨ c) := eq_of_forall_le_iff fun d => by rw [le_inf_iff, le_himp_comm, sup_le_iff] simp_rw [le_himp_comm] theorem himp_le_himp_left (h : a ≤ b) : c ⇨ a ≤ c ⇨ b := le_himp_iff.2 <| himp_inf_le.trans h theorem himp_le_himp_right (h : a ≤ b) : b ⇨ c ≤ a ⇨ c := le_himp_iff.2 <| (inf_le_inf_left _ h).trans himp_inf_le theorem himp_le_himp (hab : a ≤ b) (hcd : c ≤ d) : b ⇨ c ≤ a ⇨ d := (himp_le_himp_right hab).trans <| himp_le_himp_left hcd @[simp] theorem sup_himp_self_left (a b : α) : a ⊔ b ⇨ a = b ⇨ a := by rw [sup_himp_distrib, himp_self, top_inf_eq] @[simp] theorem sup_himp_self_right (a b : α) : a ⊔ b ⇨ b = a ⇨ b := by rw [sup_himp_distrib, himp_self, inf_top_eq] theorem Codisjoint.himp_eq_right (h : Codisjoint a b) : b ⇨ a = a := by conv_rhs => rw [← @top_himp _ _ a] rw [← h.eq_top, sup_himp_self_left] theorem Codisjoint.himp_eq_left (h : Codisjoint a b) : a ⇨ b = b := h.symm.himp_eq_right theorem Codisjoint.himp_inf_cancel_right (h : Codisjoint a b) : a ⇨ a ⊓ b = b := by rw [himp_inf_distrib, himp_self, top_inf_eq, h.himp_eq_left] theorem Codisjoint.himp_inf_cancel_left (h : Codisjoint a b) : b ⇨ a ⊓ b = a := by rw [himp_inf_distrib, himp_self, inf_top_eq, h.himp_eq_right] /-- See `himp_le` for a stronger version in Boolean algebras. -/ theorem Codisjoint.himp_le_of_right_le (hac : Codisjoint a c) (hba : b ≤ a) : c ⇨ b ≤ a := (himp_le_himp_left hba).trans_eq hac.himp_eq_right theorem le_himp_himp : a ≤ (a ⇨ b) ⇨ b := le_himp_iff.2 inf_himp_le @[simp] lemma himp_eq_himp_iff : b ⇨ a = a ⇨ b ↔ a = b := by simp [le_antisymm_iff] lemma himp_ne_himp_iff : b ⇨ a ≠ a ⇨ b ↔ a ≠ b := himp_eq_himp_iff.not theorem himp_triangle (a b c : α) : (a ⇨ b) ⊓ (b ⇨ c) ≤ a ⇨ c := by rw [le_himp_iff, inf_right_comm, ← le_himp_iff] exact himp_inf_le.trans le_himp_himp theorem himp_inf_himp_cancel (hba : b ≤ a) (hcb : c ≤ b) : (a ⇨ b) ⊓ (b ⇨ c) = a ⇨ c := (himp_triangle _ _ _).antisymm <| le_inf (himp_le_himp_left hcb) (himp_le_himp_right hba) theorem gc_inf_himp : GaloisConnection (a ⊓ ·) (a ⇨ ·) := fun _ _ ↦ Iff.symm le_himp_iff' -- See note [lower instance priority] instance (priority := 100) GeneralizedHeytingAlgebra.toDistribLattice : DistribLattice α := DistribLattice.ofInfSupLe fun a b c => by simp_rw [inf_comm a, ← le_himp_iff, sup_le_iff, le_himp_iff, ← sup_le_iff]; rfl instance OrderDual.instGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra αᵒᵈ where sdiff a b := toDual (ofDual b ⇨ ofDual a) sdiff_le_iff a b c := by rw [sup_comm]; exact le_himp_iff instance Prod.instGeneralizedHeytingAlgebra [GeneralizedHeytingAlgebra β] : GeneralizedHeytingAlgebra (α × β) where le_himp_iff _ _ _ := and_congr le_himp_iff le_himp_iff instance Pi.instGeneralizedHeytingAlgebra {α : ι → Type*} [∀ i, GeneralizedHeytingAlgebra (α i)] : GeneralizedHeytingAlgebra (∀ i, α i) where le_himp_iff i := by simp [le_def] end GeneralizedHeytingAlgebra section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra α] {a b c d : α} @[simp] theorem sdiff_le_iff : a \ b ≤ c ↔ a ≤ b ⊔ c := GeneralizedCoheytingAlgebra.sdiff_le_iff _ _ _ theorem sdiff_le_iff' : a \ b ≤ c ↔ a ≤ c ⊔ b := by rw [sdiff_le_iff, sup_comm] theorem sdiff_le_comm : a \ b ≤ c ↔ a \ c ≤ b := by rw [sdiff_le_iff, sdiff_le_iff'] theorem sdiff_le : a \ b ≤ a := sdiff_le_iff.2 le_sup_right theorem Disjoint.disjoint_sdiff_left (h : Disjoint a b) : Disjoint (a \ c) b := h.mono_left sdiff_le theorem Disjoint.disjoint_sdiff_right (h : Disjoint a b) : Disjoint a (b \ c) := h.mono_right sdiff_le theorem sdiff_le_iff_left : a \ b ≤ b ↔ a ≤ b := by rw [sdiff_le_iff, sup_idem] @[simp] theorem sdiff_self : a \ a = ⊥ := le_bot_iff.1 <| sdiff_le_iff.2 le_sup_left theorem le_sup_sdiff : a ≤ b ⊔ a \ b := sdiff_le_iff.1 le_rfl theorem le_sdiff_sup : a ≤ a \ b ⊔ b := by rw [sup_comm, ← sdiff_le_iff] theorem sup_sdiff_left : a ⊔ a \ b = a := sup_of_le_left sdiff_le theorem sup_sdiff_right : a \ b ⊔ a = a := sup_of_le_right sdiff_le theorem inf_sdiff_left : a \ b ⊓ a = a \ b := inf_of_le_left sdiff_le theorem inf_sdiff_right : a ⊓ a \ b = a \ b := inf_of_le_right sdiff_le @[simp] theorem sup_sdiff_self (a b : α) : a ⊔ b \ a = a ⊔ b := le_antisymm (sup_le_sup_left sdiff_le _) (sup_le le_sup_left le_sup_sdiff) @[simp] theorem sdiff_sup_self (a b : α) : b \ a ⊔ a = b ⊔ a := by rw [sup_comm, sup_sdiff_self, sup_comm] alias sup_sdiff_self_left := sdiff_sup_self alias sup_sdiff_self_right := sup_sdiff_self theorem sup_sdiff_eq_sup (h : c ≤ a) : a ⊔ b \ c = a ⊔ b := sup_congr_left (sdiff_le.trans le_sup_right) <| le_sup_sdiff.trans <| sup_le_sup_right h _ -- cf. `Set.union_diff_cancel'` theorem sup_sdiff_cancel' (hab : a ≤ b) (hbc : b ≤ c) : b ⊔ c \ a = c := by rw [sup_sdiff_eq_sup hab, sup_of_le_right hbc] theorem sup_sdiff_cancel_right (h : a ≤ b) : a ⊔ b \ a = b := sup_sdiff_cancel' le_rfl h theorem sdiff_sup_cancel (h : b ≤ a) : a \ b ⊔ b = a := by rw [sup_comm, sup_sdiff_cancel_right h] theorem sup_le_of_le_sdiff_left (h : b ≤ c \ a) (hac : a ≤ c) : a ⊔ b ≤ c := sup_le hac <| h.trans sdiff_le theorem sup_le_of_le_sdiff_right (h : a ≤ c \ b) (hbc : b ≤ c) : a ⊔ b ≤ c := sup_le (h.trans sdiff_le) hbc @[simp] theorem sdiff_eq_bot_iff : a \ b = ⊥ ↔ a ≤ b := by rw [← le_bot_iff, sdiff_le_iff, sup_bot_eq] @[simp] theorem sdiff_bot : a \ ⊥ = a := eq_of_forall_ge_iff fun b => by rw [sdiff_le_iff, bot_sup_eq] @[simp] theorem bot_sdiff : ⊥ \ a = ⊥ := sdiff_eq_bot_iff.2 bot_le theorem sdiff_sdiff_sdiff_le_sdiff : (a \ b) \ (a \ c) ≤ c \ b := by rw [sdiff_le_iff, sdiff_le_iff, sup_left_comm, sup_sdiff_self, sup_left_comm, sdiff_sup_self, sup_left_comm] exact le_sup_left @[simp] theorem le_sup_sdiff_sup_sdiff : a ≤ b ⊔ (a \ c ⊔ c \ b) := by simpa using @sdiff_sdiff_sdiff_le_sdiff theorem sdiff_sdiff (a b c : α) : (a \ b) \ c = a \ (b ⊔ c) := eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_assoc] theorem sdiff_sdiff_left : (a \ b) \ c = a \ (b ⊔ c) := sdiff_sdiff _ _ _ theorem sdiff_right_comm (a b c : α) : (a \ b) \ c = (a \ c) \ b := by simp_rw [sdiff_sdiff, sup_comm] theorem sdiff_sdiff_comm : (a \ b) \ c = (a \ c) \ b := sdiff_right_comm _ _ _ @[simp] theorem sdiff_idem : (a \ b) \ b = a \ b := by rw [sdiff_sdiff_left, sup_idem] @[simp] theorem sdiff_sdiff_self : (a \ b) \ a = ⊥ := by rw [sdiff_sdiff_comm, sdiff_self, bot_sdiff] theorem sup_sdiff_distrib (a b c : α) : (a ⊔ b) \ c = a \ c ⊔ b \ c := eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_le_iff, sdiff_le_iff] theorem sdiff_inf_distrib (a b c : α) : a \ (b ⊓ c) = a \ b ⊔ a \ c := eq_of_forall_ge_iff fun d => by rw [sup_le_iff, sdiff_le_comm, le_inf_iff] simp_rw [sdiff_le_comm] theorem sup_sdiff : (a ⊔ b) \ c = a \ c ⊔ b \ c := sup_sdiff_distrib _ _ _ @[simp] theorem sup_sdiff_right_self : (a ⊔ b) \ b = a \ b := by rw [sup_sdiff, sdiff_self, sup_bot_eq] @[simp] theorem sup_sdiff_left_self : (a ⊔ b) \ a = b \ a := by rw [sup_comm, sup_sdiff_right_self] @[gcongr] theorem sdiff_le_sdiff_right (h : a ≤ b) : a \ c ≤ b \ c := sdiff_le_iff.2 <| h.trans <| le_sup_sdiff @[gcongr] theorem sdiff_le_sdiff_left (h : a ≤ b) : c \ b ≤ c \ a := sdiff_le_iff.2 <| le_sup_sdiff.trans <| sup_le_sup_right h _ @[gcongr] theorem sdiff_le_sdiff (hab : a ≤ b) (hcd : c ≤ d) : a \ d ≤ b \ c := (sdiff_le_sdiff_right hab).trans <| sdiff_le_sdiff_left hcd -- cf. `IsCompl.inf_sup` theorem sdiff_inf : a \ (b ⊓ c) = a \ b ⊔ a \ c := sdiff_inf_distrib _ _ _ @[simp] theorem sdiff_inf_self_left (a b : α) : a \ (a ⊓ b) = a \ b := by rw [sdiff_inf, sdiff_self, bot_sup_eq] @[simp] theorem sdiff_inf_self_right (a b : α) : b \ (a ⊓ b) = b \ a := by rw [sdiff_inf, sdiff_self, sup_bot_eq] theorem Disjoint.sdiff_eq_left (h : Disjoint a b) : a \ b = a := by conv_rhs => rw [← @sdiff_bot _ _ a] rw [← h.eq_bot, sdiff_inf_self_left] theorem Disjoint.sdiff_eq_right (h : Disjoint a b) : b \ a = b := h.symm.sdiff_eq_left theorem Disjoint.sup_sdiff_cancel_left (h : Disjoint a b) : (a ⊔ b) \ a = b := by rw [sup_sdiff, sdiff_self, bot_sup_eq, h.sdiff_eq_right] theorem Disjoint.sup_sdiff_cancel_right (h : Disjoint a b) : (a ⊔ b) \ b = a := by rw [sup_sdiff, sdiff_self, sup_bot_eq, h.sdiff_eq_left] /-- See `le_sdiff` for a stronger version in generalised Boolean algebras. -/ theorem Disjoint.le_sdiff_of_le_left (hac : Disjoint a c) (hab : a ≤ b) : a ≤ b \ c := hac.sdiff_eq_left.ge.trans <| sdiff_le_sdiff_right hab theorem sdiff_sdiff_le : a \ (a \ b) ≤ b := sdiff_le_iff.2 le_sdiff_sup @[simp] lemma sdiff_eq_sdiff_iff : a \ b = b \ a ↔ a = b := by simp [le_antisymm_iff] lemma sdiff_ne_sdiff_iff : a \ b ≠ b \ a ↔ a ≠ b := sdiff_eq_sdiff_iff.not theorem sdiff_triangle (a b c : α) : a \ c ≤ a \ b ⊔ b \ c := by rw [sdiff_le_iff, sup_left_comm, ← sdiff_le_iff] exact sdiff_sdiff_le.trans le_sup_sdiff theorem sdiff_sup_sdiff_cancel (hba : b ≤ a) (hcb : c ≤ b) : a \ b ⊔ b \ c = a \ c := (sdiff_triangle _ _ _).antisymm' <| sup_le (sdiff_le_sdiff_left hcb) (sdiff_le_sdiff_right hba) /-- a version of `sdiff_sup_sdiff_cancel` with more general hypotheses. -/ theorem sdiff_sup_sdiff_cancel' (hinf : a ⊓ c ≤ b) (hsup : b ≤ a ⊔ c) : a \ b ⊔ b \ c = a \ c := by refine (sdiff_triangle ..).antisymm' <| sup_le ?_ <| by simpa [sup_comm] rw [← sdiff_inf_self_left (b := c)] exact sdiff_le_sdiff_left hinf theorem sdiff_le_sdiff_of_sup_le_sup_left (h : c ⊔ a ≤ c ⊔ b) : a \ c ≤ b \ c := by rw [← sup_sdiff_left_self, ← @sup_sdiff_left_self _ _ _ b] exact sdiff_le_sdiff_right h theorem sdiff_le_sdiff_of_sup_le_sup_right (h : a ⊔ c ≤ b ⊔ c) : a \ c ≤ b \ c := by rw [← sup_sdiff_right_self, ← @sup_sdiff_right_self _ _ b] exact sdiff_le_sdiff_right h @[simp] theorem inf_sdiff_sup_left : a \ c ⊓ (a ⊔ b) = a \ c := inf_of_le_left <| sdiff_le.trans le_sup_left @[simp] theorem inf_sdiff_sup_right : a \ c ⊓ (b ⊔ a) = a \ c := inf_of_le_left <| sdiff_le.trans le_sup_right theorem gc_sdiff_sup : GaloisConnection (· \ a) (a ⊔ ·) := fun _ _ ↦ sdiff_le_iff -- See note [lower instance priority] instance (priority := 100) GeneralizedCoheytingAlgebra.toDistribLattice : DistribLattice α := { ‹GeneralizedCoheytingAlgebra α› with le_sup_inf := fun a b c => by simp_rw [← sdiff_le_iff, le_inf_iff, sdiff_le_iff, ← le_inf_iff]; rfl } instance OrderDual.instGeneralizedHeytingAlgebra : GeneralizedHeytingAlgebra αᵒᵈ where himp := fun a b => toDual (ofDual b \ ofDual a) le_himp_iff := fun a b c => by rw [inf_comm]; exact sdiff_le_iff instance Prod.instGeneralizedCoheytingAlgebra [GeneralizedCoheytingAlgebra β] : GeneralizedCoheytingAlgebra (α × β) where sdiff_le_iff _ _ _ := and_congr sdiff_le_iff sdiff_le_iff instance Pi.instGeneralizedCoheytingAlgebra {α : ι → Type*} [∀ i, GeneralizedCoheytingAlgebra (α i)] : GeneralizedCoheytingAlgebra (∀ i, α i) where sdiff_le_iff i := by simp [le_def] end GeneralizedCoheytingAlgebra section HeytingAlgebra variable [HeytingAlgebra α] {a b : α} @[simp] theorem himp_bot (a : α) : a ⇨ ⊥ = aᶜ := HeytingAlgebra.himp_bot _ @[simp] theorem bot_himp (a : α) : ⊥ ⇨ a = ⊤ := himp_eq_top_iff.2 bot_le theorem compl_sup_distrib (a b : α) : (a ⊔ b)ᶜ = aᶜ ⊓ bᶜ := by simp_rw [← himp_bot, sup_himp_distrib] @[simp] theorem compl_sup : (a ⊔ b)ᶜ = aᶜ ⊓ bᶜ := compl_sup_distrib _ _ theorem compl_le_himp : aᶜ ≤ a ⇨ b := (himp_bot _).ge.trans <| himp_le_himp_left bot_le theorem compl_sup_le_himp : aᶜ ⊔ b ≤ a ⇨ b := sup_le compl_le_himp le_himp theorem sup_compl_le_himp : b ⊔ aᶜ ≤ a ⇨ b := sup_le le_himp compl_le_himp -- `p → ¬ p ↔ ¬ p` @[simp] theorem himp_compl (a : α) : a ⇨ aᶜ = aᶜ := by rw [← himp_bot, himp_himp, inf_idem] -- `p → ¬ q ↔ q → ¬ p` theorem himp_compl_comm (a b : α) : a ⇨ bᶜ = b ⇨ aᶜ := by simp_rw [← himp_bot, himp_left_comm]
Mathlib/Order/Heyting/Basic.lean
641
642
theorem le_compl_iff_disjoint_right : a ≤ bᶜ ↔ Disjoint a b := by
rw [← himp_bot, le_himp_iff, disjoint_iff_inf_le]