Dataset Viewer
Auto-converted to Parquet Duplicate
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) 2018 Rohan Mitta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes HΓΆlzl, Yury Kudryashov, Winston Yin -/ import Mathlib.Algebra.Group.End import Mathlib.Topology.EMetricSpace.Diam /-! # Lipschitz continuous functions A map `f : Ξ± β†’ Ξ²` between two (extended) metric spaces is called *Lipschitz continuous* with constant `K β‰₯ 0` if for all `x, y` we have `edist (f x) (f y) ≀ K * edist x y`. For a metric space, the latter inequality is equivalent to `dist (f x) (f y) ≀ K * dist x y`. There is also a version asserting this inequality only for `x` and `y` in some set `s`. Finally, `f : Ξ± β†’ Ξ²` is called *locally Lipschitz continuous* if each `x : Ξ±` has a neighbourhood on which `f` is Lipschitz continuous (with some constant). In this file we provide various ways to prove that various combinations of Lipschitz continuous functions are Lipschitz continuous. We also prove that Lipschitz continuous functions are uniformly continuous, and that locally Lipschitz functions are continuous. ## Main definitions and lemmas * `LipschitzWith K f`: states that `f` is Lipschitz with constant `K : ℝβ‰₯0` * `LipschitzOnWith K f s`: states that `f` is Lipschitz with constant `K : ℝβ‰₯0` on a set `s` * `LipschitzWith.uniformContinuous`: a Lipschitz function is uniformly continuous * `LipschitzOnWith.uniformContinuousOn`: a function which is Lipschitz on a set `s` is uniformly continuous on `s`. * `LocallyLipschitz f`: states that `f` is locally Lipschitz * `LocallyLipschitzOn f s`: states that `f` is locally Lipschitz on `s`. * `LocallyLipschitz.continuous`: a locally Lipschitz function is continuous. ## Implementation notes The parameter `K` has type `ℝβ‰₯0`. This way we avoid conjunction in the definition and have coercions both to `ℝ` and `ℝβ‰₯0∞`. Constructors whose names end with `'` take `K : ℝ` as an argument, and return `LipschitzWith (Real.toNNReal K) f`. -/ universe u v w x open Filter Function Set Topology NNReal ENNReal Bornology variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} {ΞΉ : Type x} section PseudoEMetricSpace variable [PseudoEMetricSpace Ξ±] [PseudoEMetricSpace Ξ²] {K : ℝβ‰₯0} {s t : Set Ξ±} {f : Ξ± β†’ Ξ²} /-- A function `f` is **Lipschitz continuous** with constant `K β‰₯ 0` if for all `x, y` we have `dist (f x) (f y) ≀ K * dist x y`. -/ def LipschitzWith (K : ℝβ‰₯0) (f : Ξ± β†’ Ξ²) := βˆ€ x y, edist (f x) (f y) ≀ K * edist x y /-- A function `f` is **Lipschitz continuous** with constant `K β‰₯ 0` **on `s`** if for all `x, y` in `s` we have `dist (f x) (f y) ≀ K * dist x y`. -/ def LipschitzOnWith (K : ℝβ‰₯0) (f : Ξ± β†’ Ξ²) (s : Set Ξ±) := βˆ€ ⦃x⦄, x ∈ s β†’ βˆ€ ⦃y⦄, y ∈ s β†’ edist (f x) (f y) ≀ K * edist x y /-- `f : Ξ± β†’ Ξ²` is called **locally Lipschitz continuous** iff every point `x` has a neighbourhood on which `f` is Lipschitz. -/ def LocallyLipschitz (f : Ξ± β†’ Ξ²) : Prop := βˆ€ x, βˆƒ K, βˆƒ t ∈ 𝓝 x, LipschitzOnWith K f t /-- `f : Ξ± β†’ Ξ²` is called **locally Lipschitz continuous** on `s` iff every point `x` of `s` has a neighbourhood within `s` on which `f` is Lipschitz. -/ def LocallyLipschitzOn (s : Set Ξ±) (f : Ξ± β†’ Ξ²) : Prop := βˆ€ ⦃x⦄, x ∈ s β†’ βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t /-- Every function is Lipschitz on the empty set (with any Lipschitz constant). -/ @[simp] theorem lipschitzOnWith_empty (K : ℝβ‰₯0) (f : Ξ± β†’ Ξ²) : LipschitzOnWith K f βˆ… := fun _ => False.elim @[simp] lemma locallyLipschitzOn_empty (f : Ξ± β†’ Ξ²) : LocallyLipschitzOn βˆ… f := fun _ ↦ False.elim /-- Being Lipschitz on a set is monotone w.r.t. that set. -/ theorem LipschitzOnWith.mono (hf : LipschitzOnWith K f t) (h : s βŠ† t) : LipschitzOnWith K f s := fun _x x_in _y y_in => hf (h x_in) (h y_in) lemma LocallyLipschitzOn.mono (hf : LocallyLipschitzOn t f) (h : s βŠ† t) : LocallyLipschitzOn s f := fun x hx ↦ by obtain ⟨K, u, hu, hfu⟩ := hf (h hx); exact ⟨K, u, nhdsWithin_mono _ h hu, hfu⟩ /-- `f` is Lipschitz iff it is Lipschitz on the entire space. -/ @[simp] lemma lipschitzOnWith_univ : LipschitzOnWith K f univ ↔ LipschitzWith K f := by simp [LipschitzOnWith, LipschitzWith] @[simp] lemma locallyLipschitzOn_univ : LocallyLipschitzOn univ f ↔ LocallyLipschitz f := by simp [LocallyLipschitzOn, LocallyLipschitz] protected lemma LocallyLipschitz.locallyLipschitzOn (h : LocallyLipschitz f) : LocallyLipschitzOn s f := (locallyLipschitzOn_univ.2 h).mono s.subset_univ theorem lipschitzOnWith_iff_restrict : LipschitzOnWith K f s ↔ LipschitzWith K (s.restrict f) := by simp [LipschitzOnWith, LipschitzWith] lemma lipschitzOnWith_restrict {t : Set s} : LipschitzOnWith K (s.restrict f) t ↔ LipschitzOnWith K f (s ∩ Subtype.val '' t) := by simp [LipschitzOnWith, LipschitzWith] lemma locallyLipschitzOn_iff_restrict : LocallyLipschitzOn s f ↔ LocallyLipschitz (s.restrict f) := by simp only [LocallyLipschitzOn, LocallyLipschitz, SetCoe.forall', restrict_apply, Subtype.edist_mk_mk, ← lipschitzOnWith_iff_restrict, lipschitzOnWith_restrict, nhds_subtype_eq_comap_nhdsWithin, mem_comap] congr! with x K constructor Β· rintro ⟨t, ht, hft⟩ exact ⟨_, ⟨t, ht, Subset.rfl⟩, hft.mono <| inter_subset_right.trans <| image_preimage_subset ..⟩ Β· rintro ⟨t, ⟨u, hu, hut⟩, hft⟩ exact ⟨s ∩ u, Filter.inter_mem self_mem_nhdsWithin hu, hft.mono fun x hx ↦ ⟨hx.1, ⟨x, hx.1⟩, hut hx.2, rfl⟩⟩ alias ⟨LipschitzOnWith.to_restrict, _⟩ := lipschitzOnWith_iff_restrict alias ⟨LocallyLipschitzOn.restrict, _⟩ := locallyLipschitzOn_iff_restrict lemma Set.MapsTo.lipschitzOnWith_iff_restrict {t : Set Ξ²} (h : MapsTo f s t) : LipschitzOnWith K f s ↔ LipschitzWith K (h.restrict f s t) := _root_.lipschitzOnWith_iff_restrict alias ⟨LipschitzOnWith.to_restrict_mapsTo, _⟩ := Set.MapsTo.lipschitzOnWith_iff_restrict end PseudoEMetricSpace namespace LipschitzWith open EMetric variable [PseudoEMetricSpace Ξ±] [PseudoEMetricSpace Ξ²] [PseudoEMetricSpace Ξ³] variable {K : ℝβ‰₯0} {f : Ξ± β†’ Ξ²} {x y : Ξ±} {r : ℝβ‰₯0∞} {s : Set Ξ±} protected theorem lipschitzOnWith (h : LipschitzWith K f) : LipschitzOnWith K f s := fun x _ y _ => h x y theorem edist_le_mul (h : LipschitzWith K f) (x y : Ξ±) : edist (f x) (f y) ≀ K * edist x y := h x y theorem edist_le_mul_of_le (h : LipschitzWith K f) (hr : edist x y ≀ r) : edist (f x) (f y) ≀ K * r := (h x y).trans <| mul_left_mono hr theorem edist_lt_mul_of_lt (h : LipschitzWith K f) (hK : K β‰  0) (hr : edist x y < r) : edist (f x) (f y) < K * r := (h x y).trans_lt <| (ENNReal.mul_lt_mul_left (ENNReal.coe_ne_zero.2 hK) ENNReal.coe_ne_top).2 hr theorem mapsTo_emetric_closedBall (h : LipschitzWith K f) (x : Ξ±) (r : ℝβ‰₯0∞) : MapsTo f (closedBall x r) (closedBall (f x) (K * r)) := fun _y hy => h.edist_le_mul_of_le hy theorem mapsTo_emetric_ball (h : LipschitzWith K f) (hK : K β‰  0) (x : Ξ±) (r : ℝβ‰₯0∞) : MapsTo f (ball x r) (ball (f x) (K * r)) := fun _y hy => h.edist_lt_mul_of_lt hK hy theorem edist_lt_top (hf : LipschitzWith K f) {x y : Ξ±} (h : edist x y β‰  ⊀) : edist (f x) (f y) < ⊀ := (hf x y).trans_lt <| ENNReal.mul_lt_top ENNReal.coe_lt_top h.lt_top theorem mul_edist_le (h : LipschitzWith K f) (x y : Ξ±) : (K⁻¹ : ℝβ‰₯0∞) * edist (f x) (f y) ≀ edist x y := by rw [mul_comm, ← div_eq_mul_inv] exact ENNReal.div_le_of_le_mul' (h x y) protected theorem of_edist_le (h : βˆ€ x y, edist (f x) (f y) ≀ edist x y) : LipschitzWith 1 f := fun x y => by simp only [ENNReal.coe_one, one_mul, h] protected theorem weaken (hf : LipschitzWith K f) {K' : ℝβ‰₯0} (h : K ≀ K') : LipschitzWith K' f := fun x y => le_trans (hf x y) <| mul_right_mono (ENNReal.coe_le_coe.2 h) theorem ediam_image_le (hf : LipschitzWith K f) (s : Set Ξ±) : EMetric.diam (f '' s) ≀ K * EMetric.diam s := by apply EMetric.diam_le rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ exact hf.edist_le_mul_of_le (EMetric.edist_le_diam_of_mem hx hy) theorem edist_lt_of_edist_lt_div (hf : LipschitzWith K f) {x y : Ξ±} {d : ℝβ‰₯0∞} (h : edist x y < d / K) : edist (f x) (f y) < d := calc edist (f x) (f y) ≀ K * edist x y := hf x y _ < d := ENNReal.mul_lt_of_lt_div' h /-- A Lipschitz function is uniformly continuous. -/ protected theorem uniformContinuous (hf : LipschitzWith K f) : UniformContinuous f := EMetric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅pos => ⟨Ρ / K, ENNReal.div_pos_iff.2 ⟨ne_of_gt Ξ΅pos, ENNReal.coe_ne_top⟩, hf.edist_lt_of_edist_lt_div⟩ /-- A Lipschitz function is continuous. -/ protected theorem continuous (hf : LipschitzWith K f) : Continuous f := hf.uniformContinuous.continuous /-- Constant functions are Lipschitz (with any constant). -/ protected theorem const (b : Ξ²) : LipschitzWith 0 fun _ : Ξ± => b := fun x y => by simp only [edist_self, zero_le] protected theorem const' (b : Ξ²) {K : ℝβ‰₯0} : LipschitzWith K fun _ : Ξ± => b := fun x y => by simp only [edist_self, zero_le] /-- The identity is 1-Lipschitz. -/ protected theorem id : LipschitzWith 1 (@id Ξ±) := LipschitzWith.of_edist_le fun _ _ => le_rfl /-- The inclusion of a subset is 1-Lipschitz. -/ protected theorem subtype_val (s : Set Ξ±) : LipschitzWith 1 (Subtype.val : s β†’ Ξ±) := LipschitzWith.of_edist_le fun _ _ => le_rfl theorem subtype_mk (hf : LipschitzWith K f) {p : Ξ² β†’ Prop} (hp : βˆ€ x, p (f x)) : LipschitzWith K (fun x => ⟨f x, hp x⟩ : Ξ± β†’ { y // p y }) := hf protected theorem eval {Ξ± : ΞΉ β†’ Type u} [βˆ€ i, PseudoEMetricSpace (Ξ± i)] [Fintype ΞΉ] (i : ΞΉ) : LipschitzWith 1 (Function.eval i : (βˆ€ i, Ξ± i) β†’ Ξ± i) := LipschitzWith.of_edist_le fun f g => by convert edist_le_pi_edist f g i /-- The restriction of a `K`-Lipschitz function is `K`-Lipschitz. -/ protected theorem restrict (hf : LipschitzWith K f) (s : Set Ξ±) : LipschitzWith K (s.restrict f) := fun x y => hf x y /-- The composition of Lipschitz functions is Lipschitz. -/ protected theorem comp {Kf Kg : ℝβ‰₯0} {f : Ξ² β†’ Ξ³} {g : Ξ± β†’ Ξ²} (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) : LipschitzWith (Kf * Kg) (f ∘ g) := fun x y => calc edist (f (g x)) (f (g y)) ≀ Kf * edist (g x) (g y) := hf _ _ _ ≀ Kf * (Kg * edist x y) := mul_left_mono (hg _ _) _ = (Kf * Kg : ℝβ‰₯0) * edist x y := by rw [← mul_assoc, ENNReal.coe_mul] theorem comp_lipschitzOnWith {Kf Kg : ℝβ‰₯0} {f : Ξ² β†’ Ξ³} {g : Ξ± β†’ Ξ²} {s : Set Ξ±} (hf : LipschitzWith Kf f) (hg : LipschitzOnWith Kg g s) : LipschitzOnWith (Kf * Kg) (f ∘ g) s := lipschitzOnWith_iff_restrict.mpr <| hf.comp hg.to_restrict protected theorem prod_fst : LipschitzWith 1 (@Prod.fst Ξ± Ξ²) := LipschitzWith.of_edist_le fun _ _ => le_max_left _ _ protected theorem prod_snd : LipschitzWith 1 (@Prod.snd Ξ± Ξ²) := LipschitzWith.of_edist_le fun _ _ => le_max_right _ _ /-- If `f` and `g` are Lipschitz functions, so is the induced map `f Γ— g` to the product type. -/ protected theorem prodMk {f : Ξ± β†’ Ξ²} {Kf : ℝβ‰₯0} (hf : LipschitzWith Kf f) {g : Ξ± β†’ Ξ³} {Kg : ℝβ‰₯0} (hg : LipschitzWith Kg g) : LipschitzWith (max Kf Kg) fun x => (f x, g x) := by intro x y rw [ENNReal.coe_mono.map_max, Prod.edist_eq, max_mul] exact max_le_max (hf x y) (hg x y) @[deprecated (since := "2025-03-10")] protected alias prod := LipschitzWith.prodMk protected theorem prodMk_left (a : Ξ±) : LipschitzWith 1 (Prod.mk a : Ξ² β†’ Ξ± Γ— Ξ²) := by simpa only [max_eq_right zero_le_one] using (LipschitzWith.const a).prodMk LipschitzWith.id @[deprecated (since := "2025-03-10")] protected alias prod_mk_left := LipschitzWith.prodMk_left protected theorem prodMk_right (b : Ξ²) : LipschitzWith 1 fun a : Ξ± => (a, b) := by simpa only [max_eq_left zero_le_one] using LipschitzWith.id.prodMk (LipschitzWith.const b) @[deprecated (since := "2025-03-10")] protected alias prod_mk_right := LipschitzWith.prodMk_right protected theorem uncurry {f : Ξ± β†’ Ξ² β†’ Ξ³} {KΞ± KΞ² : ℝβ‰₯0} (hΞ± : βˆ€ b, LipschitzWith KΞ± fun a => f a b) (hΞ² : βˆ€ a, LipschitzWith KΞ² (f a)) : LipschitzWith (KΞ± + KΞ²) (Function.uncurry f) := by rintro ⟨a₁, bβ‚βŸ© ⟨aβ‚‚, bβ‚‚βŸ© simp only [Function.uncurry, ENNReal.coe_add, add_mul] apply le_trans (edist_triangle _ (f aβ‚‚ b₁) _) exact add_le_add (le_trans (hΞ± _ _ _) <| mul_left_mono <| le_max_left _ _) (le_trans (hΞ² _ _ _) <| mul_left_mono <| le_max_right _ _) /-- Iterates of a Lipschitz function are Lipschitz. -/ protected theorem iterate {f : Ξ± β†’ Ξ±} (hf : LipschitzWith K f) : βˆ€ n, LipschitzWith (K ^ n) f^[n] | 0 => by simpa only [pow_zero] using LipschitzWith.id | n + 1 => by rw [pow_succ]; exact (LipschitzWith.iterate hf n).comp hf theorem edist_iterate_succ_le_geometric {f : Ξ± β†’ Ξ±} (hf : LipschitzWith K f) (x n) : edist (f^[n] x) (f^[n + 1] x) ≀ edist x (f x) * (K : ℝβ‰₯0∞) ^ n := by rw [iterate_succ, mul_comm] simpa only [ENNReal.coe_pow] using (hf.iterate n) x (f x) protected theorem mul_end {f g : Function.End Ξ±} {Kf Kg} (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) : LipschitzWith (Kf * Kg) (f * g : Function.End Ξ±) := hf.comp hg /-- The product of a list of Lipschitz continuous endomorphisms is a Lipschitz continuous endomorphism. -/ protected theorem list_prod (f : ΞΉ β†’ Function.End Ξ±) (K : ΞΉ β†’ ℝβ‰₯0) (h : βˆ€ i, LipschitzWith (K i) (f i)) : βˆ€ l : List ΞΉ, LipschitzWith (l.map K).prod (l.map f).prod | [] => by simpa using LipschitzWith.id | i::l => by simp only [List.map_cons, List.prod_cons] exact (h i).mul_end (LipschitzWith.list_prod f K h l) protected theorem pow_end {f : Function.End Ξ±} {K} (h : LipschitzWith K f) : βˆ€ n : β„•, LipschitzWith (K ^ n) (f ^ n : Function.End Ξ±) | 0 => by simpa only [pow_zero] using LipschitzWith.id | n + 1 => by rw [pow_succ, pow_succ] exact (LipschitzWith.pow_end h n).mul_end h end LipschitzWith namespace LipschitzOnWith variable [PseudoEMetricSpace Ξ±] [PseudoEMetricSpace Ξ²] [PseudoEMetricSpace Ξ³] variable {K : ℝβ‰₯0} {s : Set Ξ±} {f : Ξ± β†’ Ξ²} protected theorem uniformContinuousOn (hf : LipschitzOnWith K f s) : UniformContinuousOn f s := uniformContinuousOn_iff_restrict.mpr hf.to_restrict.uniformContinuous protected theorem continuousOn (hf : LipschitzOnWith K f s) : ContinuousOn f s := hf.uniformContinuousOn.continuousOn theorem edist_le_mul_of_le (h : LipschitzOnWith K f s) {x y : Ξ±} (hx : x ∈ s) (hy : y ∈ s) {r : ℝβ‰₯0∞} (hr : edist x y ≀ r) : edist (f x) (f y) ≀ K * r := (h hx hy).trans <| mul_left_mono hr theorem edist_lt_of_edist_lt_div (hf : LipschitzOnWith K f s) {x y : Ξ±} (hx : x ∈ s) (hy : y ∈ s) {d : ℝβ‰₯0∞} (hd : edist x y < d / K) : edist (f x) (f y) < d := hf.to_restrict.edist_lt_of_edist_lt_div <| show edist (⟨x, hx⟩ : s) ⟨y, hy⟩ < d / K from hd protected theorem comp {g : Ξ² β†’ Ξ³} {t : Set Ξ²} {Kg : ℝβ‰₯0} (hg : LipschitzOnWith Kg g t) (hf : LipschitzOnWith K f s) (hmaps : MapsTo f s t) : LipschitzOnWith (Kg * K) (g ∘ f) s := lipschitzOnWith_iff_restrict.mpr <| hg.to_restrict.comp (hf.to_restrict_mapsTo hmaps) /-- If `f` and `g` are Lipschitz on `s`, so is the induced map `f Γ— g` to the product type. -/ protected theorem prodMk {g : Ξ± β†’ Ξ³} {Kf Kg : ℝβ‰₯0} (hf : LipschitzOnWith Kf f s) (hg : LipschitzOnWith Kg g s) : LipschitzOnWith (max Kf Kg) (fun x => (f x, g x)) s := by intro _ hx _ hy rw [ENNReal.coe_mono.map_max, Prod.edist_eq, max_mul] exact max_le_max (hf hx hy) (hg hx hy) @[deprecated (since := "2025-03-10")] protected alias prod := LipschitzOnWith.prodMk
Mathlib/Topology/EMetricSpace/Lipschitz.lean
329
333
theorem ediam_image2_le (f : Ξ± β†’ Ξ² β†’ Ξ³) {K₁ Kβ‚‚ : ℝβ‰₯0} (s : Set Ξ±) (t : Set Ξ²) (hf₁ : βˆ€ b ∈ t, LipschitzOnWith K₁ (f Β· b) s) (hfβ‚‚ : βˆ€ a ∈ s, LipschitzOnWith Kβ‚‚ (f a) t) : EMetric.diam (Set.image2 f s t) ≀ ↑K₁ * EMetric.diam s + ↑Kβ‚‚ * EMetric.diam t := by
simp only [EMetric.diam_le_iff, forall_mem_image2] intro a₁ ha₁ b₁ hb₁ aβ‚‚ haβ‚‚ bβ‚‚ hbβ‚‚
/- 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. -/
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
109
118
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]
/- 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.Complex import Qq /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex 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`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (Ο€ y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : β„‚) ^ (y : β„‚)).re noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : β„‚) ^ (y : β„‚)).re := rfl theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : β„€) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : β„•) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[simp] lemma exp_one_pow (n : β„•) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≀ x) : x ^ y = 0 ↔ x = 0 ∧ y β‰  0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] @[simp] lemma rpow_eq_zero (hx : 0 ≀ x) (hy : y β‰  0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≀ x) (hy : y β‰  0) : x ^ y β‰  0 ↔ x β‰  0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * Ο€) := by rw [rpow_def, Complex.cpow_def, if_neg] Β· have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * Ο€) * Complex.I := by simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring Β· rw [Complex.ofReal_eq_zero] exact ne_of_lt hx theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≀ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * Ο€) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x β‰  0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor Β· intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 Β· subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ Β· rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ Β· rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) Β· exact zero_rpow h Β· exact rpow_zero _ theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≀ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one]
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
134
146
theorem zero_rpow_nonneg (x : ℝ) : 0 ≀ (0 : ℝ) ^ x := by
by_cases h : x = 0 <;> simp [h, zero_le_one] @[bound] theorem rpow_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : 0 ≀ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≀ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≀ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] @[bound]
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Algebra.Ring.Int.Defs import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.Cast.Order.Basic import Mathlib.Data.Nat.PSub import Mathlib.Data.Nat.Size import Mathlib.Data.Num.Bitwise /-! # Properties of the binary representation of integers -/ open Int attribute [local simp] add_assoc namespace PosNum variable {Ξ± : Type*} @[simp, norm_cast] theorem cast_one [One Ξ±] [Add Ξ±] : ((1 : PosNum) : Ξ±) = 1 := rfl @[simp] theorem cast_one' [One Ξ±] [Add Ξ±] : (PosNum.one : Ξ±) = 1 := rfl @[simp, norm_cast] theorem cast_bit0 [One Ξ±] [Add Ξ±] (n : PosNum) : (n.bit0 : Ξ±) = (n : Ξ±) + n := rfl @[simp, norm_cast] theorem cast_bit1 [One Ξ±] [Add Ξ±] (n : PosNum) : (n.bit1 : Ξ±) = ((n : Ξ±) + n) + 1 := rfl @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne Ξ±] : βˆ€ n : PosNum, ((n : β„•) : Ξ±) = n | 1 => Nat.cast_one | bit0 p => by dsimp; rw [Nat.cast_add, p.cast_to_nat] | bit1 p => by dsimp; rw [Nat.cast_add, Nat.cast_add, Nat.cast_one, p.cast_to_nat] @[norm_cast] theorem to_nat_to_int (n : PosNum) : ((n : β„•) : β„€) = n := cast_to_nat _ @[simp, norm_cast] theorem cast_to_int [AddGroupWithOne Ξ±] (n : PosNum) : ((n : β„€) : Ξ±) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] theorem succ_to_nat : βˆ€ n, (succ n : β„•) = n + 1 | 1 => rfl | bit0 _ => rfl | bit1 p => (congr_arg (fun n ↦ n + n) (succ_to_nat p)).trans <| show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1 by simp [add_left_comm] theorem one_add (n : PosNum) : 1 + n = succ n := by cases n <;> rfl theorem add_one (n : PosNum) : n + 1 = succ n := by cases n <;> rfl @[norm_cast] theorem add_to_nat : βˆ€ m n, ((m + n : PosNum) : β„•) = m + n | 1, b => by rw [one_add b, succ_to_nat, add_comm, cast_one] | a, 1 => by rw [add_one a, succ_to_nat, cast_one] | bit0 a, bit0 b => (congr_arg (fun n ↦ n + n) (add_to_nat a b)).trans <| add_add_add_comm _ _ _ _ | bit0 a, bit1 b => (congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : β„•) = a + a + (b + b + 1) by simp [add_left_comm] | bit1 a, bit0 b => (congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : β„•) = a + a + 1 + (b + b) by simp [add_comm, add_left_comm] | bit1 a, bit1 b => show (succ (a + b) + succ (a + b) : β„•) = a + a + 1 + (b + b + 1) by rw [succ_to_nat, add_to_nat a b]; simp [add_left_comm] theorem add_succ : βˆ€ m n : PosNum, m + succ n = succ (m + n) | 1, b => by simp [one_add] | bit0 a, 1 => congr_arg bit0 (add_one a) | bit1 a, 1 => congr_arg bit1 (add_one a) | bit0 _, bit0 _ => rfl | bit0 a, bit1 b => congr_arg bit0 (add_succ a b) | bit1 _, bit0 _ => rfl | bit1 a, bit1 b => congr_arg bit1 (add_succ a b) theorem bit0_of_bit0 : βˆ€ n, n + n = bit0 n | 1 => rfl | bit0 p => congr_arg bit0 (bit0_of_bit0 p) | bit1 p => show bit0 (succ (p + p)) = _ by rw [bit0_of_bit0 p, succ] theorem bit1_of_bit1 (n : PosNum) : (n + n) + 1 = bit1 n := show (n + n) + 1 = bit1 n by rw [add_one, bit0_of_bit0, succ] @[norm_cast] theorem mul_to_nat (m) : βˆ€ n, ((m * n : PosNum) : β„•) = m * n | 1 => (mul_one _).symm | bit0 p => show (↑(m * p) + ↑(m * p) : β„•) = ↑m * (p + p) by rw [mul_to_nat m p, left_distrib] | bit1 p => (add_to_nat (bit0 (m * p)) m).trans <| show (↑(m * p) + ↑(m * p) + ↑m : β„•) = ↑m * (p + p) + m by rw [mul_to_nat m p, left_distrib] theorem to_nat_pos : βˆ€ n : PosNum, 0 < (n : β„•) | 1 => Nat.zero_lt_one | bit0 p => let h := to_nat_pos p add_pos h h | bit1 _p => Nat.succ_pos _ theorem cmp_to_nat_lemma {m n : PosNum} : (m : β„•) < n β†’ (bit1 m : β„•) < bit0 n := show (m : β„•) < n β†’ (m + m + 1 + 1 : β„•) ≀ n + n by intro h; rw [Nat.add_right_comm m m 1, add_assoc]; exact Nat.add_le_add h h theorem cmp_swap (m) : βˆ€ n, (cmp m n).swap = cmp n m := by induction' m with m IH m IH <;> intro n <;> obtain - | n | n := n <;> unfold cmp <;> try { rfl } <;> rw [← IH] <;> cases cmp m n <;> rfl theorem cmp_to_nat : βˆ€ m n, (Ordering.casesOn (cmp m n) ((m : β„•) < n) (m = n) ((n : β„•) < m) : Prop) | 1, 1 => rfl | bit0 a, 1 => let h : (1 : β„•) ≀ a := to_nat_pos a Nat.add_le_add h h | bit1 a, 1 => Nat.succ_lt_succ <| to_nat_pos <| bit0 a | 1, bit0 b => let h : (1 : β„•) ≀ b := to_nat_pos b Nat.add_le_add h h | 1, bit1 b => Nat.succ_lt_succ <| to_nat_pos <| bit0 b | bit0 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this Β· exact Nat.add_lt_add this this Β· rw [this] Β· exact Nat.add_lt_add this this | bit0 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this Β· exact Nat.le_succ_of_le (Nat.add_lt_add this this) Β· rw [this] apply Nat.lt_succ_self Β· exact cmp_to_nat_lemma this | bit1 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this Β· exact cmp_to_nat_lemma this Β· rw [this] apply Nat.lt_succ_self Β· exact Nat.le_succ_of_le (Nat.add_lt_add this this) | bit1 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this Β· exact Nat.succ_lt_succ (Nat.add_lt_add this this) Β· rw [this] Β· exact Nat.succ_lt_succ (Nat.add_lt_add this this) @[norm_cast] theorem lt_to_nat {m n : PosNum} : (m : β„•) < n ↔ m < n := show (m : β„•) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] @[norm_cast] theorem le_to_nat {m n : PosNum} : (m : β„•) ≀ n ↔ m ≀ n := by rw [← not_lt]; exact not_congr lt_to_nat end PosNum namespace Num variable {Ξ± : Type*} open PosNum theorem add_zero (n : Num) : n + 0 = n := by cases n <;> rfl theorem zero_add (n : Num) : 0 + n = n := by cases n <;> rfl theorem add_one : βˆ€ n : Num, n + 1 = succ n | 0 => rfl | pos p => by cases p <;> rfl theorem add_succ : βˆ€ m n : Num, m + succ n = succ (m + n) | 0, n => by simp [zero_add] | pos p, 0 => show pos (p + 1) = succ (pos p + 0) by rw [PosNum.add_one, add_zero, succ, succ'] | pos _, pos _ => congr_arg pos (PosNum.add_succ _ _) theorem bit0_of_bit0 : βˆ€ n : Num, n + n = n.bit0 | 0 => rfl | pos p => congr_arg pos p.bit0_of_bit0 theorem bit1_of_bit1 : βˆ€ n : Num, (n + n) + 1 = n.bit1 | 0 => rfl | pos p => congr_arg pos p.bit1_of_bit1 @[simp] theorem ofNat'_zero : Num.ofNat' 0 = 0 := by simp [Num.ofNat'] theorem ofNat'_bit (b n) : ofNat' (Nat.bit b n) = cond b Num.bit1 Num.bit0 (ofNat' n) := Nat.binaryRec_eq _ _ (.inl rfl) @[simp] theorem ofNat'_one : Num.ofNat' 1 = 1 := by erw [ofNat'_bit true 0, cond, ofNat'_zero]; rfl theorem bit1_succ : βˆ€ n : Num, n.bit1.succ = n.succ.bit0 | 0 => rfl | pos _n => rfl theorem ofNat'_succ : βˆ€ {n}, ofNat' (n + 1) = ofNat' n + 1 := @(Nat.binaryRec (by simp [zero_add]) fun b n ih => by cases b Β· erw [ofNat'_bit true n, ofNat'_bit] simp only [← bit1_of_bit1, ← bit0_of_bit0, cond] Β· rw [show n.bit true + 1 = (n + 1).bit false by simp [Nat.bit, mul_add], ofNat'_bit, ofNat'_bit, ih] simp only [cond, add_one, bit1_succ]) @[simp] theorem add_ofNat' (m n) : Num.ofNat' (m + n) = Num.ofNat' m + Num.ofNat' n := by induction n Β· simp only [Nat.add_zero, ofNat'_zero, add_zero] Β· simp only [Nat.add_succ, Nat.add_zero, ofNat'_succ, add_one, add_succ, *] @[simp, norm_cast] theorem cast_zero [Zero Ξ±] [One Ξ±] [Add Ξ±] : ((0 : Num) : Ξ±) = 0 := rfl @[simp] theorem cast_zero' [Zero Ξ±] [One Ξ±] [Add Ξ±] : (Num.zero : Ξ±) = 0 := rfl @[simp, norm_cast] theorem cast_one [Zero Ξ±] [One Ξ±] [Add Ξ±] : ((1 : Num) : Ξ±) = 1 := rfl @[simp] theorem cast_pos [Zero Ξ±] [One Ξ±] [Add Ξ±] (n : PosNum) : (Num.pos n : Ξ±) = n := rfl theorem succ'_to_nat : βˆ€ n, (succ' n : β„•) = n + 1 | 0 => (Nat.zero_add _).symm | pos _p => PosNum.succ_to_nat _ theorem succ_to_nat (n) : (succ n : β„•) = n + 1 := succ'_to_nat n @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne Ξ±] : βˆ€ n : Num, ((n : β„•) : Ξ±) = n | 0 => Nat.cast_zero | pos p => p.cast_to_nat @[norm_cast] theorem add_to_nat : βˆ€ m n, ((m + n : Num) : β„•) = m + n | 0, 0 => rfl | 0, pos _q => (Nat.zero_add _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.add_to_nat _ _ @[norm_cast] theorem mul_to_nat : βˆ€ m n, ((m * n : Num) : β„•) = m * n | 0, 0 => rfl | 0, pos _q => (zero_mul _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.mul_to_nat _ _ theorem cmp_to_nat : βˆ€ m n, (Ordering.casesOn (cmp m n) ((m : β„•) < n) (m = n) ((n : β„•) < m) : Prop) | 0, 0 => rfl | 0, pos _ => to_nat_pos _ | pos _, 0 => to_nat_pos _ | pos a, pos b => by have := PosNum.cmp_to_nat a b; revert this; dsimp [cmp]; cases PosNum.cmp a b exacts [id, congr_arg pos, id] @[norm_cast] theorem lt_to_nat {m n : Num} : (m : β„•) < n ↔ m < n := show (m : β„•) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] @[norm_cast] theorem le_to_nat {m n : Num} : (m : β„•) ≀ n ↔ m ≀ n := by rw [← not_lt]; exact not_congr lt_to_nat end Num namespace PosNum @[simp] theorem of_to_nat' : βˆ€ n : PosNum, Num.ofNat' (n : β„•) = Num.pos n | 1 => by erw [@Num.ofNat'_bit true 0, Num.ofNat'_zero]; rfl | bit0 p => by simpa only [Nat.bit_false, cond_false, two_mul, of_to_nat' p] using Num.ofNat'_bit false p | bit1 p => by simpa only [Nat.bit_true, cond_true, two_mul, of_to_nat' p] using Num.ofNat'_bit true p end PosNum namespace Num @[simp, norm_cast] theorem of_to_nat' : βˆ€ n : Num, Num.ofNat' (n : β„•) = n | 0 => ofNat'_zero | pos p => p.of_to_nat' lemma toNat_injective : Function.Injective (castNum : Num β†’ β„•) := Function.LeftInverse.injective of_to_nat' @[norm_cast] theorem to_nat_inj {m n : Num} : (m : β„•) = n ↔ m = n := toNat_injective.eq_iff /-- This tactic tries to turn an (in)equality about `Num`s to one about `Nat`s by rewriting. ```lean example (n : Num) (m : Num) : n ≀ n + m := by transfer_rw exact Nat.le_add_right _ _ ``` -/ scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic| (repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat] repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero])) /-- This tactic tries to prove (in)equalities about `Num`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : Num) (m : Num) : n ≀ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp)) instance addMonoid : AddMonoid Num where add := (Β· + Β·) zero := 0 zero_add := zero_add add_zero := add_zero add_assoc := by transfer nsmul := nsmulRec instance addMonoidWithOne : AddMonoidWithOne Num := { Num.addMonoid with natCast := Num.ofNat' one := 1 natCast_zero := ofNat'_zero natCast_succ := fun _ => ofNat'_succ } instance commSemiring : CommSemiring Num where __ := Num.addMonoid __ := Num.addMonoidWithOne mul := (Β· * Β·) npow := @npowRec Num ⟨1⟩ ⟨(Β· * Β·)⟩ mul_zero _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, mul_zero] zero_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, zero_mul] mul_one _ := by rw [← to_nat_inj, mul_to_nat, cast_one, mul_one] one_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_one, one_mul] add_comm _ _ := by simp_rw [← to_nat_inj, add_to_nat, add_comm] mul_comm _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_comm] mul_assoc _ _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_assoc] left_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, mul_add] right_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, add_mul] instance partialOrder : PartialOrder Num where lt_iff_le_not_le a b := by simp only [← lt_to_nat, ← le_to_nat, lt_iff_le_not_le] le_refl := by transfer le_trans a b c := by transfer_rw; apply le_trans le_antisymm a b := by transfer_rw; apply le_antisymm instance isOrderedCancelAddMonoid : IsOrderedCancelAddMonoid Num where add_le_add_left a b h c := by revert h; transfer_rw; exact fun h => add_le_add_left h c le_of_add_le_add_left a b c := show a + b ≀ a + c β†’ b ≀ c by transfer_rw; apply le_of_add_le_add_left instance linearOrder : LinearOrder Num := { le_total := by intro a b transfer_rw apply le_total toDecidableLT := Num.decidableLT toDecidableLE := Num.decidableLE -- This is relying on an automatically generated instance name, -- generated in a `deriving` handler. -- See https://github.com/leanprover/lean4/issues/2343 toDecidableEq := instDecidableEqNum } instance isStrictOrderedRing : IsStrictOrderedRing Num := { zero_le_one := by decide mul_lt_mul_of_pos_left := by intro a b c transfer_rw apply mul_lt_mul_of_pos_left mul_lt_mul_of_pos_right := by intro a b c transfer_rw apply mul_lt_mul_of_pos_right exists_pair_ne := ⟨0, 1, by decide⟩ } @[norm_cast] theorem add_of_nat (m n) : ((m + n : β„•) : Num) = m + n := add_ofNat' _ _ @[norm_cast] theorem to_nat_to_int (n : Num) : ((n : β„•) : β„€) = n := cast_to_nat _ @[simp, norm_cast] theorem cast_to_int {Ξ±} [AddGroupWithOne Ξ±] (n : Num) : ((n : β„€) : Ξ±) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] theorem to_of_nat : βˆ€ n : β„•, ((n : Num) : β„•) = n | 0 => by rw [Nat.cast_zero, cast_zero] | n + 1 => by rw [Nat.cast_succ, add_one, succ_to_nat, to_of_nat n] @[simp, norm_cast] theorem of_natCast {Ξ±} [AddMonoidWithOne Ξ±] (n : β„•) : ((n : Num) : Ξ±) = n := by rw [← cast_to_nat, to_of_nat] @[norm_cast] theorem of_nat_inj {m n : β„•} : (m : Num) = n ↔ m = n := ⟨fun h => Function.LeftInverse.injective to_of_nat h, congr_arg _⟩ -- The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : βˆ€ n : Num, ((n : β„•) : Num) = n := of_to_nat' @[norm_cast] theorem dvd_to_nat (m n : Num) : (m : β„•) ∣ n ↔ m ∣ n := ⟨fun ⟨k, e⟩ => ⟨k, by rw [← of_to_nat n, e]; simp⟩, fun ⟨k, e⟩ => ⟨k, by simp [e, mul_to_nat]⟩⟩ end Num namespace PosNum variable {Ξ± : Type*} open Num -- The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : βˆ€ n : PosNum, ((n : β„•) : Num) = Num.pos n := of_to_nat' @[norm_cast] theorem to_nat_inj {m n : PosNum} : (m : β„•) = n ↔ m = n := ⟨fun h => Num.pos.inj <| by rw [← PosNum.of_to_nat, ← PosNum.of_to_nat, h], congr_arg _⟩ theorem pred'_to_nat : βˆ€ n, (pred' n : β„•) = Nat.pred n | 1 => rfl | bit0 n => have : Nat.succ ↑(pred' n) = ↑n := by rw [pred'_to_nat n, Nat.succ_pred_eq_of_pos (to_nat_pos n)] match (motive := βˆ€ k : Num, Nat.succ ↑k = ↑n β†’ ↑(Num.casesOn k 1 bit1 : PosNum) = Nat.pred (n + n)) pred' n, this with | 0, (h : ((1 : Num) : β„•) = n) => by rw [← to_nat_inj.1 h]; rfl | Num.pos p, (h : Nat.succ ↑p = n) => by rw [← h]; exact (Nat.succ_add p p).symm | bit1 _ => rfl @[simp] theorem pred'_succ' (n) : pred' (succ' n) = n := Num.to_nat_inj.1 <| by rw [pred'_to_nat, succ'_to_nat, Nat.add_one, Nat.pred_succ] @[simp] theorem succ'_pred' (n) : succ' (pred' n) = n := to_nat_inj.1 <| by rw [succ'_to_nat, pred'_to_nat, Nat.add_one, Nat.succ_pred_eq_of_pos (to_nat_pos _)] instance dvd : Dvd PosNum := ⟨fun m n => pos m ∣ pos n⟩ @[norm_cast] theorem dvd_to_nat {m n : PosNum} : (m : β„•) ∣ n ↔ m ∣ n := Num.dvd_to_nat (pos m) (pos n) theorem size_to_nat : βˆ€ n, (size n : β„•) = Nat.size n | 1 => Nat.size_one.symm | bit0 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit0, ← two_mul] erw [@Nat.size_bit false n] have := to_nat_pos n dsimp [Nat.bit]; omega | bit1 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit1, ← two_mul] erw [@Nat.size_bit true n] dsimp [Nat.bit]; omega theorem size_eq_natSize : βˆ€ n, (size n : β„•) = natSize n | 1 => rfl | bit0 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] | bit1 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat] theorem natSize_pos (n) : 0 < natSize n := by cases n <;> apply Nat.succ_pos /-- This tactic tries to turn an (in)equality about `PosNum`s to one about `Nat`s by rewriting. ```lean example (n : PosNum) (m : PosNum) : n ≀ n + m := by transfer_rw exact Nat.le_add_right _ _ ``` -/ scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic| (repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat] repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero])) /-- This tactic tries to prove (in)equalities about `PosNum`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : PosNum) (m : PosNum) : n ≀ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp [add_comm, add_left_comm, mul_comm, mul_left_comm])) instance addCommSemigroup : AddCommSemigroup PosNum where add := (Β· + Β·) add_assoc := by transfer add_comm := by transfer instance commMonoid : CommMonoid PosNum where mul := (Β· * Β·) one := (1 : PosNum) npow := @npowRec PosNum ⟨1⟩ ⟨(Β· * Β·)⟩ mul_assoc := by transfer one_mul := by transfer mul_one := by transfer mul_comm := by transfer instance distrib : Distrib PosNum where add := (Β· + Β·) mul := (Β· * Β·) left_distrib := by transfer; simp [mul_add] right_distrib := by transfer; simp [mul_add, mul_comm] instance linearOrder : LinearOrder PosNum where lt := (Β· < Β·) lt_iff_le_not_le := by intro a b transfer_rw apply lt_iff_le_not_le le := (Β· ≀ Β·) le_refl := by transfer le_trans := by intro a b c transfer_rw apply le_trans le_antisymm := by intro a b transfer_rw apply le_antisymm le_total := by intro a b transfer_rw apply le_total toDecidableLT := by infer_instance toDecidableLE := by infer_instance toDecidableEq := by infer_instance @[simp] theorem cast_to_num (n : PosNum) : ↑n = Num.pos n := by rw [← cast_to_nat, ← of_to_nat n] @[simp, norm_cast] theorem bit_to_nat (b n) : (bit b n : β„•) = Nat.bit b n := by cases b <;> simp [bit, two_mul] @[simp, norm_cast] theorem cast_add [AddMonoidWithOne Ξ±] (m n) : ((m + n : PosNum) : Ξ±) = m + n := by rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat] @[simp 500, norm_cast] theorem cast_succ [AddMonoidWithOne Ξ±] (n : PosNum) : (succ n : Ξ±) = n + 1 := by rw [← add_one, cast_add, cast_one] @[simp, norm_cast] theorem cast_inj [AddMonoidWithOne Ξ±] [CharZero Ξ±] {m n : PosNum} : (m : Ξ±) = n ↔ m = n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj] @[simp] theorem one_le_cast [Semiring Ξ±] [PartialOrder Ξ±] [IsStrictOrderedRing Ξ±] (n : PosNum) : (1 : Ξ±) ≀ n := by rw [← cast_to_nat, ← Nat.cast_one, Nat.cast_le (Ξ± := Ξ±)]; apply to_nat_pos @[simp] theorem cast_pos [Semiring Ξ±] [PartialOrder Ξ±] [IsStrictOrderedRing Ξ±] (n : PosNum) : 0 < (n : Ξ±) := lt_of_lt_of_le zero_lt_one (one_le_cast n) @[simp, norm_cast] theorem cast_mul [NonAssocSemiring Ξ±] (m n) : ((m * n : PosNum) : Ξ±) = m * n := by rw [← cast_to_nat, mul_to_nat, Nat.cast_mul, cast_to_nat, cast_to_nat] @[simp] theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by have := cmp_to_nat m n -- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required. revert this; cases cmp m n <;> intro this <;> simp at this ⊒ <;> try { exact this } <;> simp [show m β‰  n from fun e => by rw [e] at this;exact lt_irrefl _ this] @[simp, norm_cast] theorem cast_lt [Semiring Ξ±] [PartialOrder Ξ±] [IsStrictOrderedRing Ξ±] {m n : PosNum} : (m : Ξ±) < n ↔ m < n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_lt (Ξ± := Ξ±), lt_to_nat] @[simp, norm_cast] theorem cast_le [Semiring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {m n : PosNum} : (m : Ξ±) ≀ n ↔ m ≀ n := by rw [← not_lt]; exact not_congr cast_lt end PosNum namespace Num variable {Ξ± : Type*} open PosNum theorem bit_to_nat (b n) : (bit b n : β„•) = Nat.bit b n := by cases b <;> cases n <;> simp [bit, two_mul] <;> rfl theorem cast_succ' [AddMonoidWithOne Ξ±] (n) : (succ' n : Ξ±) = n + 1 := by rw [← PosNum.cast_to_nat, succ'_to_nat, Nat.cast_add_one, cast_to_nat] theorem cast_succ [AddMonoidWithOne Ξ±] (n) : (succ n : Ξ±) = n + 1 := cast_succ' n @[simp, norm_cast] theorem cast_add [AddMonoidWithOne Ξ±] (m n) : ((m + n : Num) : Ξ±) = m + n := by rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat] @[simp, norm_cast] theorem cast_bit0 [NonAssocSemiring Ξ±] (n : Num) : (n.bit0 : Ξ±) = 2 * (n : Ξ±) := by rw [← bit0_of_bit0, two_mul, cast_add] @[simp, norm_cast] theorem cast_bit1 [NonAssocSemiring Ξ±] (n : Num) : (n.bit1 : Ξ±) = 2 * (n : Ξ±) + 1 := by rw [← bit1_of_bit1, bit0_of_bit0, cast_add, cast_bit0]; rfl @[simp, norm_cast] theorem cast_mul [NonAssocSemiring Ξ±] : βˆ€ m n, ((m * n : Num) : Ξ±) = m * n | 0, 0 => (zero_mul _).symm | 0, pos _q => (zero_mul _).symm | pos _p, 0 => (mul_zero _).symm | pos _p, pos _q => PosNum.cast_mul _ _ theorem size_to_nat : βˆ€ n, (size n : β„•) = Nat.size n | 0 => Nat.size_zero.symm | pos p => p.size_to_nat theorem size_eq_natSize : βˆ€ n, (size n : β„•) = natSize n | 0 => rfl | pos p => p.size_eq_natSize theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat] @[simp 999] theorem ofNat'_eq : βˆ€ n, Num.ofNat' n = n := Nat.binaryRec (by simp) fun b n IH => by tauto theorem zneg_toZNum (n : Num) : -n.toZNum = n.toZNumNeg := by cases n <;> rfl theorem zneg_toZNumNeg (n : Num) : -n.toZNumNeg = n.toZNum := by cases n <;> rfl theorem toZNum_inj {m n : Num} : m.toZNum = n.toZNum ↔ m = n := ⟨fun h => by cases m <;> cases n <;> cases h <;> rfl, congr_arg _⟩ @[simp] theorem cast_toZNum [Zero Ξ±] [One Ξ±] [Add Ξ±] [Neg Ξ±] : βˆ€ n : Num, (n.toZNum : Ξ±) = n | 0 => rfl | Num.pos _p => rfl @[simp] theorem cast_toZNumNeg [SubtractionMonoid Ξ±] [One Ξ±] : βˆ€ n : Num, (n.toZNumNeg : Ξ±) = -n | 0 => neg_zero.symm | Num.pos _p => rfl @[simp] theorem add_toZNum (m n : Num) : Num.toZNum (m + n) = m.toZNum + n.toZNum := by cases m <;> cases n <;> rfl end Num namespace PosNum open Num theorem pred_to_nat {n : PosNum} (h : 1 < n) : (pred n : β„•) = Nat.pred n := by unfold pred cases e : pred' n Β· have : (1 : β„•) ≀ Nat.pred n := Nat.pred_le_pred ((@cast_lt β„• _ _ _).2 h) rw [← pred'_to_nat, e] at this exact absurd this (by decide) Β· rw [← pred'_to_nat, e] rfl theorem sub'_one (a : PosNum) : sub' a 1 = (pred' a).toZNum := by cases a <;> rfl theorem one_sub' (a : PosNum) : sub' 1 a = (pred' a).toZNumNeg := by cases a <;> rfl theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = Ordering.lt := Iff.rfl theorem le_iff_cmp {m n} : m ≀ n ↔ cmp m n β‰  Ordering.gt := not_congr <| lt_iff_cmp.trans <| by rw [← cmp_swap]; cases cmp m n <;> decide end PosNum namespace Num variable {Ξ± : Type*} open PosNum theorem pred_to_nat : βˆ€ n : Num, (pred n : β„•) = Nat.pred n | 0 => rfl | pos p => by rw [pred, PosNum.pred'_to_nat]; rfl theorem ppred_to_nat : βˆ€ n : Num, (↑) <$> ppred n = Nat.ppred n | 0 => rfl | pos p => by rw [ppred, Option.map_some, Nat.ppred_eq_some.2] rw [PosNum.pred'_to_nat, Nat.succ_pred_eq_of_pos (PosNum.to_nat_pos _)] rfl theorem cmp_swap (m n) : (cmp m n).swap = cmp n m := by cases m <;> cases n <;> try { rfl }; apply PosNum.cmp_swap
Mathlib/Data/Num/Lemmas.lean
733
734
theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by
have := cmp_to_nat m n
/- 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, Kim Morrison -/ import Mathlib.Data.List.Basic /-! # Lattice structure of lists This files prove basic properties about `List.disjoint`, `List.union`, `List.inter` and `List.bagInter`, which are defined in core Lean and `Data.List.Defs`. `l₁ βˆͺ lβ‚‚` is the list where all elements of `l₁` have been inserted in `lβ‚‚` in order. For example, `[0, 0, 1, 2, 2, 3] βˆͺ [4, 3, 3, 0] = [1, 2, 4, 3, 3, 0]` `l₁ ∩ lβ‚‚` is the list of elements of `l₁` in order which are in `lβ‚‚`. For example, `[0, 0, 1, 2, 2, 3] βˆͺ [4, 3, 3, 0] = [0, 0, 3]` `List.bagInter l₁ lβ‚‚` is the list of elements that are in both `l₁` and `lβ‚‚`, counted with multiplicity and in the order they appear in `l₁`. As opposed to `List.inter`, `List.bagInter` copes well with multiplicity. For example, `bagInter [0, 1, 2, 3, 2, 1, 0] [1, 0, 1, 4, 3] = [0, 1, 3, 1]` -/ open Nat namespace List variable {Ξ± : Type*} {l₁ lβ‚‚ : List Ξ±} {p : Ξ± β†’ Prop} {a : Ξ±} /-! ### `Disjoint` -/ section Disjoint @[symm] theorem Disjoint.symm (d : Disjoint l₁ lβ‚‚) : Disjoint lβ‚‚ l₁ := fun _ iβ‚‚ i₁ => d i₁ iβ‚‚ end Disjoint variable [DecidableEq Ξ±] /-! ### `union` -/ section Union theorem mem_union_left (h : a ∈ l₁) (lβ‚‚ : List Ξ±) : a ∈ l₁ βˆͺ lβ‚‚ := mem_union_iff.2 (Or.inl h) theorem mem_union_right (l₁ : List Ξ±) (h : a ∈ lβ‚‚) : a ∈ l₁ βˆͺ lβ‚‚ := mem_union_iff.2 (Or.inr h) theorem sublist_suffix_of_union : βˆ€ l₁ lβ‚‚ : List Ξ±, βˆƒ t, t <+ l₁ ∧ t ++ lβ‚‚ = l₁ βˆͺ lβ‚‚ | [], _ => ⟨[], by rfl, rfl⟩ | a :: l₁, lβ‚‚ => let ⟨t, s, e⟩ := sublist_suffix_of_union l₁ lβ‚‚ if h : a ∈ l₁ βˆͺ lβ‚‚ then ⟨t, sublist_cons_of_sublist _ s, by simp only [e, cons_union, insert_of_mem h]⟩ else ⟨a :: t, s.cons_cons _, by simp only [cons_append, cons_union, e, insert_of_not_mem h]⟩ theorem suffix_union_right (l₁ lβ‚‚ : List Ξ±) : lβ‚‚ <:+ l₁ βˆͺ lβ‚‚ := (sublist_suffix_of_union l₁ lβ‚‚).imp fun _ => And.right theorem union_sublist_append (l₁ lβ‚‚ : List Ξ±) : l₁ βˆͺ lβ‚‚ <+ l₁ ++ lβ‚‚ := let ⟨_, s, e⟩ := sublist_suffix_of_union l₁ lβ‚‚ e β–Έ (append_sublist_append_right _).2 s theorem forall_mem_union : (βˆ€ x ∈ l₁ βˆͺ lβ‚‚, p x) ↔ (βˆ€ x ∈ l₁, p x) ∧ βˆ€ x ∈ lβ‚‚, p x := by simp only [mem_union_iff, or_imp, forall_and] theorem forall_mem_of_forall_mem_union_left (h : βˆ€ x ∈ l₁ βˆͺ lβ‚‚, p x) : βˆ€ x ∈ l₁, p x := (forall_mem_union.1 h).1 theorem forall_mem_of_forall_mem_union_right (h : βˆ€ x ∈ l₁ βˆͺ lβ‚‚, p x) : βˆ€ x ∈ lβ‚‚, p x := (forall_mem_union.1 h).2 theorem Subset.union_eq_right {xs ys : List Ξ±} (h : xs βŠ† ys) : xs βˆͺ ys = ys := by induction xs with | nil => simp | cons x xs ih => rw [cons_union, insert_of_mem <| mem_union_right _ <| h mem_cons_self, ih <| subset_of_cons_subset h] end Union /-! ### `inter` -/ section Inter @[simp] theorem inter_nil (l : List Ξ±) : [] ∩ l = [] := rfl @[simp] theorem inter_cons_of_mem (l₁ : List Ξ±) (h : a ∈ lβ‚‚) : (a :: l₁) ∩ lβ‚‚ = a :: l₁ ∩ lβ‚‚ := by simp [Inter.inter, List.inter, h] @[simp] theorem inter_cons_of_not_mem (l₁ : List Ξ±) (h : a βˆ‰ lβ‚‚) : (a :: l₁) ∩ lβ‚‚ = l₁ ∩ lβ‚‚ := by simp [Inter.inter, List.inter, h] @[simp] theorem inter_nil' (l : List Ξ±) : l ∩ [] = [] := by induction l with | nil => rfl | cons x xs ih => by_cases x ∈ xs <;> simp [ih] theorem mem_of_mem_inter_left : a ∈ l₁ ∩ lβ‚‚ β†’ a ∈ l₁ := mem_of_mem_filter theorem mem_of_mem_inter_right (h : a ∈ l₁ ∩ lβ‚‚) : a ∈ lβ‚‚ := by simpa using of_mem_filter h theorem mem_inter_of_mem_of_mem (h₁ : a ∈ l₁) (hβ‚‚ : a ∈ lβ‚‚) : a ∈ l₁ ∩ lβ‚‚ := mem_filter_of_mem h₁ <| by simpa using hβ‚‚ theorem inter_subset_left {l₁ lβ‚‚ : List Ξ±} : l₁ ∩ lβ‚‚ βŠ† l₁ := filter_subset' _ theorem inter_subset_right {l₁ lβ‚‚ : List Ξ±} : l₁ ∩ lβ‚‚ βŠ† lβ‚‚ := fun _ => mem_of_mem_inter_right theorem subset_inter {l l₁ lβ‚‚ : List Ξ±} (h₁ : l βŠ† l₁) (hβ‚‚ : l βŠ† lβ‚‚) : l βŠ† l₁ ∩ lβ‚‚ := fun _ h => mem_inter_iff.2 ⟨h₁ h, hβ‚‚ h⟩ theorem inter_eq_nil_iff_disjoint : l₁ ∩ lβ‚‚ = [] ↔ Disjoint l₁ lβ‚‚ := by simp only [eq_nil_iff_forall_not_mem, mem_inter_iff, not_and] rfl alias ⟨_, Disjoint.inter_eq_nil⟩ := inter_eq_nil_iff_disjoint theorem forall_mem_inter_of_forall_left (h : βˆ€ x ∈ l₁, p x) (lβ‚‚ : List Ξ±) : βˆ€ x, x ∈ l₁ ∩ lβ‚‚ β†’ p x := BAll.imp_left (fun _ => mem_of_mem_inter_left) h theorem forall_mem_inter_of_forall_right (l₁ : List Ξ±) (h : βˆ€ x ∈ lβ‚‚, p x) : βˆ€ x, x ∈ l₁ ∩ lβ‚‚ β†’ p x := BAll.imp_left (fun _ => mem_of_mem_inter_right) h @[simp]
Mathlib/Data/List/Lattice.lean
147
147
theorem inter_reverse {xs ys : List Ξ±} : xs.inter ys.reverse = xs.inter ys := 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]
Mathlib/Order/Heyting/Basic.lean
388
389
theorem sdiff_le_comm : a \ b ≀ c ↔ a \ c ≀ b := by
rw [sdiff_le_iff, sdiff_le_iff']
/- 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 -/ import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Analysis.SpecialFunctions.Complex.LogDeriv import Mathlib.Analysis.Calculus.FDeriv.Extend import Mathlib.Analysis.Calculus.Deriv.Prod import Mathlib.Analysis.SpecialFunctions.Log.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv /-! # Derivatives of power function on `β„‚`, `ℝ`, `ℝβ‰₯0`, and `ℝβ‰₯0∞` We also prove differentiability and provide derivatives for the power functions `x ^ y`. -/ noncomputable section open scoped Real Topology NNReal ENNReal open Filter namespace Complex theorem hasStrictFDerivAt_cpow {p : β„‚ Γ— β„‚} (hp : p.1 ∈ slitPlane) : HasStrictFDerivAt (fun x : β„‚ Γ— β„‚ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) β€’ ContinuousLinearMap.fst β„‚ β„‚ β„‚ + (p.1 ^ p.2 * log p.1) β€’ ContinuousLinearMap.snd β„‚ β„‚ β„‚) p := by have A : p.1 β‰  0 := slitPlane_ne_zero hp have : (fun x : β„‚ Γ— β„‚ => x.1 ^ x.2) =αΆ [𝓝 p] fun x => exp (log x.1 * x.2) := ((isOpen_ne.preimage continuous_fst).eventually_mem A).mono fun p hp => cpow_def_of_ne_zero hp _ rw [cpow_sub _ _ A, cpow_one, mul_div_left_comm, mul_smul, mul_smul] refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm simpa only [cpow_def_of_ne_zero A, div_eq_mul_inv, mul_smul, add_comm, smul_add] using ((hasStrictFDerivAt_fst.clog hp).mul hasStrictFDerivAt_snd).cexp theorem hasStrictFDerivAt_cpow' {x y : β„‚} (hp : x ∈ slitPlane) : HasStrictFDerivAt (fun x : β„‚ Γ— β„‚ => x.1 ^ x.2) ((y * x ^ (y - 1)) β€’ ContinuousLinearMap.fst β„‚ β„‚ β„‚ + (x ^ y * log x) β€’ ContinuousLinearMap.snd β„‚ β„‚ β„‚) (x, y) := @hasStrictFDerivAt_cpow (x, y) hp theorem hasStrictDerivAt_const_cpow {x y : β„‚} (h : x β‰  0 ∨ y β‰  0) : HasStrictDerivAt (fun y => x ^ y) (x ^ y * log x) y := by rcases em (x = 0) with (rfl | hx) Β· replace h := h.neg_resolve_left rfl rw [log_zero, mul_zero] refine (hasStrictDerivAt_const y 0).congr_of_eventuallyEq ?_ exact (isOpen_ne.eventually_mem h).mono fun y hy => (zero_cpow hy).symm Β· simpa only [cpow_def_of_ne_zero hx, mul_one] using ((hasStrictDerivAt_id y).const_mul (log x)).cexp theorem hasFDerivAt_cpow {p : β„‚ Γ— β„‚} (hp : p.1 ∈ slitPlane) : HasFDerivAt (fun x : β„‚ Γ— β„‚ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) β€’ ContinuousLinearMap.fst β„‚ β„‚ β„‚ + (p.1 ^ p.2 * log p.1) β€’ ContinuousLinearMap.snd β„‚ β„‚ β„‚) p := (hasStrictFDerivAt_cpow hp).hasFDerivAt end Complex section fderiv open Complex variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β„‚ E] {f g : E β†’ β„‚} {f' g' : E β†’L[β„‚] β„‚} {x : E} {s : Set E} {c : β„‚} theorem HasStrictFDerivAt.cpow (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasStrictFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) β€’ f' + (f x ^ g x * Complex.log (f x)) β€’ g') x := (hasStrictFDerivAt_cpow (p := (f x, g x)) h0).comp x (hf.prodMk hg) theorem HasStrictFDerivAt.const_cpow (hf : HasStrictFDerivAt f f' x) (h0 : c β‰  0 ∨ f x β‰  0) : HasStrictFDerivAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) β€’ f') x := (hasStrictDerivAt_const_cpow h0).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.cpow (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) β€’ f' + (f x ^ g x * Complex.log (f x)) β€’ g') x := by convert (@Complex.hasFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp x (hf.prodMk hg) theorem HasFDerivAt.const_cpow (hf : HasFDerivAt f f' x) (h0 : c β‰  0 ∨ f x β‰  0) : HasFDerivAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) β€’ f') x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasFDerivAt x hf theorem HasFDerivWithinAt.cpow (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) (h0 : f x ∈ slitPlane) : HasFDerivWithinAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) β€’ f' + (f x ^ g x * Complex.log (f x)) β€’ g') s x := by convert (@Complex.hasFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp_hasFDerivWithinAt x (hf.prodMk hg) theorem HasFDerivWithinAt.const_cpow (hf : HasFDerivWithinAt f f' s x) (h0 : c β‰  0 ∨ f x β‰  0) : HasFDerivWithinAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) β€’ f') s x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasFDerivWithinAt x hf theorem DifferentiableAt.cpow (hf : DifferentiableAt β„‚ f x) (hg : DifferentiableAt β„‚ g x) (h0 : f x ∈ slitPlane) : DifferentiableAt β„‚ (fun x => f x ^ g x) x := (hf.hasFDerivAt.cpow hg.hasFDerivAt h0).differentiableAt theorem DifferentiableAt.const_cpow (hf : DifferentiableAt β„‚ f x) (h0 : c β‰  0 ∨ f x β‰  0) : DifferentiableAt β„‚ (fun x => c ^ f x) x := (hf.hasFDerivAt.const_cpow h0).differentiableAt theorem DifferentiableAt.cpow_const (hf : DifferentiableAt β„‚ f x) (h0 : f x ∈ slitPlane) : DifferentiableAt β„‚ (fun x => f x ^ c) x := hf.cpow (differentiableAt_const c) h0 theorem DifferentiableWithinAt.cpow (hf : DifferentiableWithinAt β„‚ f s x) (hg : DifferentiableWithinAt β„‚ g s x) (h0 : f x ∈ slitPlane) : DifferentiableWithinAt β„‚ (fun x => f x ^ g x) s x := (hf.hasFDerivWithinAt.cpow hg.hasFDerivWithinAt h0).differentiableWithinAt theorem DifferentiableWithinAt.const_cpow (hf : DifferentiableWithinAt β„‚ f s x) (h0 : c β‰  0 ∨ f x β‰  0) : DifferentiableWithinAt β„‚ (fun x => c ^ f x) s x := (hf.hasFDerivWithinAt.const_cpow h0).differentiableWithinAt theorem DifferentiableWithinAt.cpow_const (hf : DifferentiableWithinAt β„‚ f s x) (h0 : f x ∈ slitPlane) : DifferentiableWithinAt β„‚ (fun x => f x ^ c) s x := hf.cpow (differentiableWithinAt_const c) h0 theorem DifferentiableOn.cpow (hf : DifferentiableOn β„‚ f s) (hg : DifferentiableOn β„‚ g s) (h0 : Set.MapsTo f s slitPlane) : DifferentiableOn β„‚ (fun x ↦ f x ^ g x) s := fun x hx ↦ (hf x hx).cpow (hg x hx) (h0 hx) theorem DifferentiableOn.const_cpow (hf : DifferentiableOn β„‚ f s) (h0 : c β‰  0 ∨ βˆ€ x ∈ s, f x β‰  0) : DifferentiableOn β„‚ (fun x ↦ c ^ f x) s := fun x hx ↦ (hf x hx).const_cpow (h0.imp_right fun h ↦ h x hx) theorem DifferentiableOn.cpow_const (hf : DifferentiableOn β„‚ f s) (h0 : βˆ€ x ∈ s, f x ∈ slitPlane) : DifferentiableOn β„‚ (fun x => f x ^ c) s := hf.cpow (differentiableOn_const c) h0 theorem Differentiable.cpow (hf : Differentiable β„‚ f) (hg : Differentiable β„‚ g) (h0 : βˆ€ x, f x ∈ slitPlane) : Differentiable β„‚ (fun x ↦ f x ^ g x) := fun x ↦ (hf x).cpow (hg x) (h0 x) theorem Differentiable.const_cpow (hf : Differentiable β„‚ f) (h0 : c β‰  0 ∨ βˆ€ x, f x β‰  0) : Differentiable β„‚ (fun x ↦ c ^ f x) := fun x ↦ (hf x).const_cpow (h0.imp_right fun h ↦ h x) @[fun_prop] lemma differentiable_const_cpow_of_neZero (z : β„‚) [NeZero z] : Differentiable β„‚ fun s : β„‚ ↦ z ^ s := differentiable_id.const_cpow (.inl <| NeZero.ne z) @[fun_prop] lemma differentiableAt_const_cpow_of_neZero (z : β„‚) [NeZero z] (t : β„‚) : DifferentiableAt β„‚ (fun s : β„‚ ↦ z ^ s) t := differentiableAt_id.const_cpow (.inl <| NeZero.ne z) end fderiv section deriv open Complex variable {f g : β„‚ β†’ β„‚} {s : Set β„‚} {f' g' x c : β„‚} /-- A private lemma that rewrites the output of lemmas like `HasFDerivAt.cpow` to the form expected by lemmas like `HasDerivAt.cpow`. -/ private theorem aux : ((g x * f x ^ (g x - 1)) β€’ (1 : β„‚ β†’L[β„‚] β„‚).smulRight f' + (f x ^ g x * log (f x)) β€’ (1 : β„‚ β†’L[β„‚] β„‚).smulRight g') 1 = g x * f x ^ (g x - 1) * f' + f x ^ g x * log (f x) * g' := by simp only [Algebra.id.smul_eq_mul, one_mul, ContinuousLinearMap.one_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul'] nonrec theorem HasStrictDerivAt.cpow (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasStrictDerivAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') x := by simpa using (hf.cpow hg h0).hasStrictDerivAt theorem HasStrictDerivAt.const_cpow (hf : HasStrictDerivAt f f' x) (h : c β‰  0 ∨ f x β‰  0) : HasStrictDerivAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') x := (hasStrictDerivAt_const_cpow h).comp x hf theorem Complex.hasStrictDerivAt_cpow_const (h : x ∈ slitPlane) : HasStrictDerivAt (fun z : β„‚ => z ^ c) (c * x ^ (c - 1)) x := by simpa only [mul_zero, add_zero, mul_one] using (hasStrictDerivAt_id x).cpow (hasStrictDerivAt_const x c) h theorem HasStrictDerivAt.cpow_const (hf : HasStrictDerivAt f f' x) (h0 : f x ∈ slitPlane) : HasStrictDerivAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') x := (Complex.hasStrictDerivAt_cpow_const h0).comp x hf theorem HasDerivAt.cpow (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasDerivAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') x := by simpa only [aux] using (hf.hasFDerivAt.cpow hg h0).hasDerivAt theorem HasDerivAt.const_cpow (hf : HasDerivAt f f' x) (h0 : c β‰  0 ∨ f x β‰  0) : HasDerivAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp x hf theorem HasDerivAt.cpow_const (hf : HasDerivAt f f' x) (h0 : f x ∈ slitPlane) : HasDerivAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') x := (Complex.hasStrictDerivAt_cpow_const h0).hasDerivAt.comp x hf theorem HasDerivWithinAt.cpow (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) (h0 : f x ∈ slitPlane) : HasDerivWithinAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') s x := by simpa only [aux] using (hf.hasFDerivWithinAt.cpow hg h0).hasDerivWithinAt theorem HasDerivWithinAt.const_cpow (hf : HasDerivWithinAt f f' s x) (h0 : c β‰  0 ∨ f x β‰  0) : HasDerivWithinAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') s x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasDerivWithinAt x hf theorem HasDerivWithinAt.cpow_const (hf : HasDerivWithinAt f f' s x) (h0 : f x ∈ slitPlane) : HasDerivWithinAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') s x := (Complex.hasStrictDerivAt_cpow_const h0).hasDerivAt.comp_hasDerivWithinAt x hf /-- Although `fun x => x ^ r` for fixed `r` is *not* complex-differentiable along the negative real line, it is still real-differentiable, and the derivative is what one would formally expect. See `hasDerivAt_ofReal_cpow_const` for an alternate formulation. -/ theorem hasDerivAt_ofReal_cpow_const' {x : ℝ} (hx : x β‰  0) {r : β„‚} (hr : r β‰  -1) : HasDerivAt (fun y : ℝ => (y : β„‚) ^ (r + 1) / (r + 1)) (x ^ r) x := by rw [Ne, ← add_eq_zero_iff_eq_neg, ← Ne] at hr rcases lt_or_gt_of_ne hx.symm with (hx | hx) Β· -- easy case : `0 < x` apply HasDerivAt.comp_ofReal (e := fun y => (y : β„‚) ^ (r + 1) / (r + 1)) convert HasDerivAt.div_const (π•œ := β„‚) ?_ (r + 1) using 1 Β· exact (mul_div_cancel_rightβ‚€ _ hr).symm Β· convert HasDerivAt.cpow_const ?_ ?_ using 1 Β· rw [add_sub_cancel_right, mul_comm]; exact (mul_one _).symm Β· exact hasDerivAt_id (x : β„‚) Β· simp [hx] Β· -- harder case : `x < 0` have : βˆ€αΆ  y : ℝ in 𝓝 x, (y : β„‚) ^ (r + 1) / (r + 1) = (-y : β„‚) ^ (r + 1) * exp (Ο€ * I * (r + 1)) / (r + 1) := by refine Filter.eventually_of_mem (Iio_mem_nhds hx) fun y hy => ?_ rw [ofReal_cpow_of_nonpos (le_of_lt hy)] refine HasDerivAt.congr_of_eventuallyEq ?_ this rw [ofReal_cpow_of_nonpos (le_of_lt hx)] suffices HasDerivAt (fun y : ℝ => (-↑y) ^ (r + 1) * exp (↑π * I * (r + 1))) ((r + 1) * (-↑x) ^ r * exp (↑π * I * r)) x by convert this.div_const (r + 1) using 1 conv_rhs => rw [mul_assoc, mul_comm, mul_div_cancel_rightβ‚€ _ hr] rw [mul_add ((Ο€ : β„‚) * _), mul_one, exp_add, exp_pi_mul_I, mul_comm (_ : β„‚) (-1 : β„‚), neg_one_mul] simp_rw [mul_neg, ← neg_mul, ← ofReal_neg] suffices HasDerivAt (fun y : ℝ => (↑(-y) : β„‚) ^ (r + 1)) (-(r + 1) * ↑(-x) ^ r) x by convert this.neg.mul_const _ using 1; ring suffices HasDerivAt (fun y : ℝ => (y : β„‚) ^ (r + 1)) ((r + 1) * ↑(-x) ^ r) (-x) by convert @HasDerivAt.scomp ℝ _ β„‚ _ _ x ℝ _ _ _ _ _ _ _ _ this (hasDerivAt_neg x) using 1 rw [real_smul, ofReal_neg 1, ofReal_one]; ring suffices HasDerivAt (fun y : β„‚ => y ^ (r + 1)) ((r + 1) * ↑(-x) ^ r) ↑(-x) by exact this.comp_ofReal conv in ↑_ ^ _ => rw [(by ring : r = r + 1 - 1)] convert HasDerivAt.cpow_const ?_ ?_ using 1 Β· rw [add_sub_cancel_right, add_sub_cancel_right]; exact (mul_one _).symm Β· exact hasDerivAt_id ((-x : ℝ) : β„‚) Β· simp [hx] @[deprecated (since := "2024-12-15")] alias hasDerivAt_ofReal_cpow := hasDerivAt_ofReal_cpow_const' /-- An alternate formulation of `hasDerivAt_ofReal_cpow_const'`. -/ theorem hasDerivAt_ofReal_cpow_const {x : ℝ} (hx : x β‰  0) {r : β„‚} (hr : r β‰  0) : HasDerivAt (fun y : ℝ => (y : β„‚) ^ r) (r * x ^ (r - 1)) x := by have := HasDerivAt.const_mul r <| hasDerivAt_ofReal_cpow_const' hx (by rwa [ne_eq, sub_eq_neg_self]) simpa [sub_add_cancel, mul_div_cancelβ‚€ _ hr] using this /-- A version of `DifferentiableAt.cpow_const` for a real function. -/ theorem DifferentiableAt.ofReal_cpow_const {f : ℝ β†’ ℝ} {x : ℝ} (hf : DifferentiableAt ℝ f x) (h0 : f x β‰  0) (h1 : c β‰  0) : DifferentiableAt ℝ (fun (y : ℝ) => (f y : β„‚) ^ c) x := (hasDerivAt_ofReal_cpow_const h0 h1).differentiableAt.comp x hf theorem Complex.deriv_cpow_const (hx : x ∈ Complex.slitPlane) : deriv (fun (x : β„‚) ↦ x ^ c) x = c * x ^ (c - 1) := (hasStrictDerivAt_cpow_const hx).hasDerivAt.deriv /-- A version of `Complex.deriv_cpow_const` for a real variable. -/ theorem Complex.deriv_ofReal_cpow_const {x : ℝ} (hx : x β‰  0) (hc : c β‰  0) : deriv (fun x : ℝ ↦ (x : β„‚) ^ c) x = c * x ^ (c - 1) := (hasDerivAt_ofReal_cpow_const hx hc).deriv theorem deriv_cpow_const (hf : DifferentiableAt β„‚ f x) (hx : f x ∈ Complex.slitPlane) : deriv (fun (x : β„‚) ↦ f x ^ c) x = c * f x ^ (c - 1) * deriv f x := (hf.hasDerivAt.cpow_const hx).deriv theorem isTheta_deriv_ofReal_cpow_const_atTop {c : β„‚} (hc : c β‰  0) : deriv (fun (x : ℝ) => (x : β„‚) ^ c) =Θ[atTop] fun x => x ^ (c.re - 1) := by calc _ =αΆ [atTop] fun x : ℝ ↦ c * x ^ (c - 1) := by filter_upwards [eventually_ne_atTop 0] with x hx using by rw [deriv_ofReal_cpow_const hx hc] _ =Θ[atTop] fun x : ℝ ↦ β€–(x : β„‚) ^ (c - 1)β€– := (Asymptotics.IsTheta.of_norm_eventuallyEq EventuallyEq.rfl).const_mul_left hc _ =αΆ [atTop] fun x ↦ x ^ (c.re - 1) := by filter_upwards [eventually_gt_atTop 0] with x hx rw [norm_cpow_eq_rpow_re_of_pos hx, sub_re, one_re] theorem isBigO_deriv_ofReal_cpow_const_atTop (c : β„‚) : deriv (fun (x : ℝ) => (x : β„‚) ^ c) =O[atTop] fun x => x ^ (c.re - 1) := by obtain rfl | hc := eq_or_ne c 0 Β· simp_rw [cpow_zero, deriv_const', Asymptotics.isBigO_zero] Β· exact (isTheta_deriv_ofReal_cpow_const_atTop hc).1 end deriv namespace Real variable {x y z : ℝ} /-- `(x, y) ↦ x ^ y` is strictly differentiable at `p : ℝ Γ— ℝ` such that `0 < p.fst`. -/ theorem hasStrictFDerivAt_rpow_of_pos (p : ℝ Γ— ℝ) (hp : 0 < p.1) : HasStrictFDerivAt (fun x : ℝ Γ— ℝ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) β€’ ContinuousLinearMap.fst ℝ ℝ ℝ + (p.1 ^ p.2 * log p.1) β€’ ContinuousLinearMap.snd ℝ ℝ ℝ) p := by have : (fun x : ℝ Γ— ℝ => x.1 ^ x.2) =αΆ [𝓝 p] fun x => exp (log x.1 * x.2) := (continuousAt_fst.eventually (lt_mem_nhds hp)).mono fun p hp => rpow_def_of_pos hp _ refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm convert ((hasStrictFDerivAt_fst.log hp.ne').mul hasStrictFDerivAt_snd).exp using 1 rw [rpow_sub_one hp.ne', ← rpow_def_of_pos hp, smul_add, smul_smul, mul_div_left_comm, div_eq_mul_inv, smul_smul, smul_smul, mul_assoc, add_comm] /-- `(x, y) ↦ x ^ y` is strictly differentiable at `p : ℝ Γ— ℝ` such that `p.fst < 0`. -/ theorem hasStrictFDerivAt_rpow_of_neg (p : ℝ Γ— ℝ) (hp : p.1 < 0) : HasStrictFDerivAt (fun x : ℝ Γ— ℝ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) β€’ ContinuousLinearMap.fst ℝ ℝ ℝ + (p.1 ^ p.2 * log p.1 - exp (log p.1 * p.2) * sin (p.2 * Ο€) * Ο€) β€’ ContinuousLinearMap.snd ℝ ℝ ℝ) p := by have : (fun x : ℝ Γ— ℝ => x.1 ^ x.2) =αΆ [𝓝 p] fun x => exp (log x.1 * x.2) * cos (x.2 * Ο€) := (continuousAt_fst.eventually (gt_mem_nhds hp)).mono fun p hp => rpow_def_of_neg hp _ refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm convert ((hasStrictFDerivAt_fst.log hp.ne).mul hasStrictFDerivAt_snd).exp.mul (hasStrictFDerivAt_snd.mul_const Ο€).cos using 1 simp_rw [rpow_sub_one hp.ne, smul_add, ← add_assoc, smul_smul, ← add_smul, ← mul_assoc, mul_comm (cos _), ← rpow_def_of_neg hp] rw [div_eq_mul_inv, add_comm]; congr 2 <;> ring /-- The function `fun (x, y) => x ^ y` is infinitely smooth at `(x, y)` unless `x = 0`. -/ theorem contDiffAt_rpow_of_ne (p : ℝ Γ— ℝ) (hp : p.1 β‰  0) {n : WithTop β„•βˆž} : ContDiffAt ℝ n (fun p : ℝ Γ— ℝ => p.1 ^ p.2) p := by rcases hp.lt_or_lt with hneg | hpos exacts [(((contDiffAt_fst.log hneg.ne).mul contDiffAt_snd).exp.mul (contDiffAt_snd.mul contDiffAt_const).cos).congr_of_eventuallyEq ((continuousAt_fst.eventually (gt_mem_nhds hneg)).mono fun p hp => rpow_def_of_neg hp _), ((contDiffAt_fst.log hpos.ne').mul contDiffAt_snd).exp.congr_of_eventuallyEq ((continuousAt_fst.eventually (lt_mem_nhds hpos)).mono fun p hp => rpow_def_of_pos hp _)] theorem differentiableAt_rpow_of_ne (p : ℝ Γ— ℝ) (hp : p.1 β‰  0) : DifferentiableAt ℝ (fun p : ℝ Γ— ℝ => p.1 ^ p.2) p := (contDiffAt_rpow_of_ne p hp).differentiableAt le_rfl theorem _root_.HasStrictDerivAt.rpow {f g : ℝ β†’ ℝ} {f' g' : ℝ} (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) (h : 0 < f x) : HasStrictDerivAt (fun x => f x ^ g x) (f' * g x * f x ^ (g x - 1) + g' * f x ^ g x * Real.log (f x)) x := by convert (hasStrictFDerivAt_rpow_of_pos ((fun x => (f x, g x)) x) h).comp_hasStrictDerivAt x (hf.prodMk hg) using 1 simp [mul_assoc, mul_comm, mul_left_comm] theorem hasStrictDerivAt_rpow_const_of_ne {x : ℝ} (hx : x β‰  0) (p : ℝ) : HasStrictDerivAt (fun x => x ^ p) (p * x ^ (p - 1)) x := by rcases hx.lt_or_lt with hx | hx Β· have := (hasStrictFDerivAt_rpow_of_neg (x, p) hx).comp_hasStrictDerivAt x ((hasStrictDerivAt_id x).prodMk (hasStrictDerivAt_const x p)) convert this using 1; simp Β· simpa using (hasStrictDerivAt_id x).rpow (hasStrictDerivAt_const x p) hx theorem hasStrictDerivAt_const_rpow {a : ℝ} (ha : 0 < a) (x : ℝ) : HasStrictDerivAt (fun x => a ^ x) (a ^ x * log a) x := by simpa using (hasStrictDerivAt_const _ _).rpow (hasStrictDerivAt_id x) ha lemma differentiableAt_rpow_const_of_ne (p : ℝ) {x : ℝ} (hx : x β‰  0) : DifferentiableAt ℝ (fun x => x ^ p) x := (hasStrictDerivAt_rpow_const_of_ne hx p).differentiableAt lemma differentiableOn_rpow_const (p : ℝ) : DifferentiableOn ℝ (fun x => (x : ℝ) ^ p) {0}ᢜ := fun _ hx => (Real.differentiableAt_rpow_const_of_ne p hx).differentiableWithinAt /-- This lemma says that `fun x => a ^ x` is strictly differentiable for `a < 0`. Note that these values of `a` are outside of the "official" domain of `a ^ x`, and we may redefine `a ^ x` for negative `a` if some other definition will be more convenient. -/ theorem hasStrictDerivAt_const_rpow_of_neg {a x : ℝ} (ha : a < 0) : HasStrictDerivAt (fun x => a ^ x) (a ^ x * log a - exp (log a * x) * sin (x * Ο€) * Ο€) x := by simpa using (hasStrictFDerivAt_rpow_of_neg (a, x) ha).comp_hasStrictDerivAt x ((hasStrictDerivAt_const _ _).prodMk (hasStrictDerivAt_id _)) end Real namespace Real variable {z x y : ℝ}
Mathlib/Analysis/SpecialFunctions/Pow/Deriv.lean
396
403
theorem hasDerivAt_rpow_const {x p : ℝ} (h : x β‰  0 ∨ 1 ≀ p) : HasDerivAt (fun x => x ^ p) (p * x ^ (p - 1)) x := by
rcases ne_or_eq x 0 with (hx | rfl) Β· exact (hasStrictDerivAt_rpow_const_of_ne hx _).hasDerivAt replace h : 1 ≀ p := h.neg_resolve_left rfl apply hasDerivAt_of_hasDerivAt_of_ne fun x hx => (hasStrictDerivAt_rpow_const_of_ne hx p).hasDerivAt exacts [continuousAt_id.rpow_const (Or.inr (zero_le_one.trans h)),
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Yury Kudryashov -/ import Mathlib.Data.ENNReal.Basic /-! # Maps between real and extended non-negative real numbers This file focuses on the functions `ENNReal.toReal : ℝβ‰₯0∞ β†’ ℝ` and `ENNReal.ofReal : ℝ β†’ ℝβ‰₯0∞` which were defined in `Data.ENNReal.Basic`. It collects all the basic results of the interactions between these functions and the algebraic and lattice operations, although a few may appear in earlier files. This file provides a `positivity` extension for `ENNReal.ofReal`. # Main theorems - `trichotomy (p : ℝβ‰₯0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal`: often used for `WithLp` and `lp` - `dichotomy (p : ℝβ‰₯0∞) [Fact (1 ≀ p)] : p = ∞ ∨ 1 ≀ p.toReal`: often used for `WithLp` and `lp` - `toNNReal_iInf` through `toReal_sSup`: these declarations allow for easy conversions between indexed or set infima and suprema in `ℝ`, `ℝβ‰₯0` and `ℝβ‰₯0∞`. This is especially useful because `ℝβ‰₯0∞` is a complete lattice. -/ assert_not_exists Finset open Set NNReal ENNReal namespace ENNReal section Real variable {a b c d : ℝβ‰₯0∞} {r p q : ℝβ‰₯0}
Mathlib/Data/ENNReal/Real.lean
37
40
theorem toReal_add (ha : a β‰  ∞) (hb : b β‰  ∞) : (a + b).toReal = a.toReal + b.toReal := by
lift a to ℝβ‰₯0 using ha lift b to ℝβ‰₯0 using hb rfl
/- 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]
Mathlib/Data/List/Sublists.lean
68
72
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]
/- 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.Hull import Mathlib.LinearAlgebra.AffineSpace.Independent /-! # Simplicial complexes In this file, we define simplicial complexes in `π•œ`-modules. A simplicial complex is a collection of simplices closed by inclusion (of vertices) and intersection (of underlying sets). We model them by a downward-closed set of affine independent finite sets whose convex hulls "glue nicely", each finite set and its convex hull corresponding respectively to the vertices and the underlying set of a simplex. ## Main declarations * `SimplicialComplex π•œ E`: A simplicial complex in the `π•œ`-module `E`. * `SimplicialComplex.vertices`: The zero dimensional faces of a simplicial complex. * `SimplicialComplex.facets`: The maximal faces of a simplicial complex. ## Notation `s ∈ K` means that `s` is a face of `K`. `K ≀ L` means that the faces of `K` are faces of `L`. ## Implementation notes "glue nicely" usually means that the intersection of two faces (as sets in the ambient space) is a face. Given that we store the vertices, not the faces, this would be a bit awkward to spell. Instead, `SimplicialComplex.inter_subset_convexHull` is an equivalent condition which works on the vertices. ## TODO Simplicial complexes can be generalized to affine spaces once `ConvexHull` has been ported. -/ open Finset Set variable (π•œ E : Type*) [Ring π•œ] [PartialOrder π•œ] [AddCommGroup E] [Module π•œ E] namespace Geometry -- TODO: update to new binder order? not sure what binder order is correct for `down_closed`. /-- A simplicial complex in a `π•œ`-module is a collection of simplices which glue nicely together. Note that the textbook meaning of "glue nicely" is given in `Geometry.SimplicialComplex.disjoint_or_exists_inter_eq_convexHull`. It is mostly useless, as `Geometry.SimplicialComplex.convexHull_inter_convexHull` is enough for all purposes. -/ @[ext] structure SimplicialComplex where /-- the faces of this simplicial complex: currently, given by their spanning vertices -/ faces : Set (Finset E) /-- the empty set is not a face: hence, all faces are non-empty -/ not_empty_mem : βˆ… βˆ‰ faces /-- the vertices in each face are affine independent: this is an implementation detail -/ indep : βˆ€ {s}, s ∈ faces β†’ AffineIndependent π•œ ((↑) : s β†’ E) /-- faces are downward closed: a non-empty subset of its spanning vertices spans another face -/ down_closed : βˆ€ {s t}, s ∈ faces β†’ t βŠ† s β†’ t β‰  βˆ… β†’ t ∈ faces inter_subset_convexHull : βˆ€ {s t}, s ∈ faces β†’ t ∈ faces β†’ convexHull π•œ ↑s ∩ convexHull π•œ ↑t βŠ† convexHull π•œ (s ∩ t : Set E) namespace SimplicialComplex variable {π•œ E} variable {K : SimplicialComplex π•œ E} {s t : Finset E} {x : E} /-- A `Finset` belongs to a `SimplicialComplex` if it's a face of it. -/ instance : Membership (Finset E) (SimplicialComplex π•œ E) := ⟨fun K s => s ∈ K.faces⟩ /-- The underlying space of a simplicial complex is the union of its faces. -/ def space (K : SimplicialComplex π•œ E) : Set E := ⋃ s ∈ K.faces, convexHull π•œ (s : Set E) -- Porting note: Expanded `βˆƒ s ∈ K.faces` to get the type to match more closely with Lean 3 theorem mem_space_iff : x ∈ K.space ↔ βˆƒ s ∈ K.faces, x ∈ convexHull π•œ (s : Set E) := by simp [space] -- Porting note: Original proof was `:= subset_biUnion_of_mem hs`
Mathlib/Analysis/Convex/SimplicialComplex/Basic.lean
86
87
theorem convexHull_subset_space (hs : s ∈ K.faces) : convexHull π•œ ↑s βŠ† K.space := by
convert subset_biUnion_of_mem hs
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Basic import Mathlib.Algebra.GroupWithZero.Basic /-! # Basic Translation Lemmas Between Functions Defined for Continued Fractions ## Summary Some simple translation lemmas between the different definitions of functions defined in `Algebra.ContinuedFractions.Basic`. -/ namespace GenContFract section General /-! ### Translations Between General Access Functions Here we give some basic translations that hold by definition between the various methods that allow us to access the numerators and denominators of a continued fraction. -/ variable {Ξ± : Type*} {g : GenContFract Ξ±} {n : β„•} theorem terminatedAt_iff_s_terminatedAt : g.TerminatedAt n ↔ g.s.TerminatedAt n := by rfl theorem terminatedAt_iff_s_none : g.TerminatedAt n ↔ g.s.get? n = none := by rfl theorem partNum_none_iff_s_none : g.partNums.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partNums, s_nth_eq] theorem terminatedAt_iff_partNum_none : g.TerminatedAt n ↔ g.partNums.get? n = none := by rw [terminatedAt_iff_s_none, partNum_none_iff_s_none] theorem partDen_none_iff_s_none : g.partDens.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partDens, s_nth_eq] theorem terminatedAt_iff_partDen_none : g.TerminatedAt n ↔ g.partDens.get? n = none := by rw [terminatedAt_iff_s_none, partDen_none_iff_s_none]
Mathlib/Algebra/ContinuedFractions/Translations.lean
49
50
theorem partNum_eq_s_a {gp : Pair Ξ±} (s_nth_eq : g.s.get? n = some gp) : g.partNums.get? n = some gp.a := by
simp [partNums, s_nth_eq]
/- Copyright (c) 2021 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.Measure.Trim import Mathlib.MeasureTheory.MeasurableSpace.CountablyGenerated /-! # Almost everywhere measurable functions A function is almost everywhere measurable if it coincides almost everywhere with a measurable function. This property, called `AEMeasurable f ΞΌ`, is defined in the file `MeasureSpaceDef`. We discuss several of its properties that are analogous to properties of measurable functions. -/ open MeasureTheory MeasureTheory.Measure Filter Set Function ENNReal variable {ΞΉ Ξ± Ξ² Ξ³ Ξ΄ R : Type*} {m0 : MeasurableSpace Ξ±} [MeasurableSpace Ξ²] [MeasurableSpace Ξ³] [MeasurableSpace Ξ΄] {f g : Ξ± β†’ Ξ²} {ΞΌ Ξ½ : Measure Ξ±} section @[nontriviality, measurability] theorem Subsingleton.aemeasurable [Subsingleton Ξ±] : AEMeasurable f ΞΌ := Subsingleton.measurable.aemeasurable @[nontriviality, measurability] theorem aemeasurable_of_subsingleton_codomain [Subsingleton Ξ²] : AEMeasurable f ΞΌ := (measurable_of_subsingleton_codomain f).aemeasurable @[simp, measurability] theorem aemeasurable_zero_measure : AEMeasurable f (0 : Measure Ξ±) := by nontriviality Ξ±; inhabit Ξ± exact ⟨fun _ => f default, measurable_const, rfl⟩ @[fun_prop] theorem aemeasurable_id'' (ΞΌ : Measure Ξ±) {m : MeasurableSpace Ξ±} (hm : m ≀ m0) : @AEMeasurable Ξ± Ξ± m m0 id ΞΌ := @Measurable.aemeasurable Ξ± Ξ± m0 m id ΞΌ (measurable_id'' hm) lemma aemeasurable_of_map_neZero {ΞΌ : Measure Ξ±} {f : Ξ± β†’ Ξ²} (h : NeZero (ΞΌ.map f)) : AEMeasurable f ΞΌ := by by_contra h' simp [h'] at h namespace AEMeasurable lemma mono_ac (hf : AEMeasurable f Ξ½) (hΞΌΞ½ : ΞΌ β‰ͺ Ξ½) : AEMeasurable f ΞΌ := ⟨hf.mk f, hf.measurable_mk, hΞΌΞ½.ae_le hf.ae_eq_mk⟩ theorem mono_measure (h : AEMeasurable f ΞΌ) (h' : Ξ½ ≀ ΞΌ) : AEMeasurable f Ξ½ := mono_ac h h'.absolutelyContinuous theorem mono_set {s t} (h : s βŠ† t) (ht : AEMeasurable f (ΞΌ.restrict t)) : AEMeasurable f (ΞΌ.restrict s) := ht.mono_measure (restrict_mono h le_rfl) @[fun_prop] protected theorem mono' (h : AEMeasurable f ΞΌ) (h' : Ξ½ β‰ͺ ΞΌ) : AEMeasurable f Ξ½ := ⟨h.mk f, h.measurable_mk, h' h.ae_eq_mk⟩ theorem ae_mem_imp_eq_mk {s} (h : AEMeasurable f (ΞΌ.restrict s)) : βˆ€α΅ x βˆ‚ΞΌ, x ∈ s β†’ f x = h.mk f x := ae_imp_of_ae_restrict h.ae_eq_mk theorem ae_inf_principal_eq_mk {s} (h : AEMeasurable f (ΞΌ.restrict s)) : f =αΆ [ae ΞΌ βŠ“ π“Ÿ s] h.mk f := le_ae_restrict h.ae_eq_mk @[measurability] theorem sum_measure [Countable ΞΉ] {ΞΌ : ΞΉ β†’ Measure Ξ±} (h : βˆ€ i, AEMeasurable f (ΞΌ i)) : AEMeasurable f (sum ΞΌ) := by classical nontriviality Ξ² inhabit Ξ² set s : ΞΉ β†’ Set Ξ± := fun i => toMeasurable (ΞΌ i) { x | f x β‰  (h i).mk f x } have hsΞΌ : βˆ€ i, ΞΌ i (s i) = 0 := by intro i rw [measure_toMeasurable] exact (h i).ae_eq_mk have hsm : MeasurableSet (β‹‚ i, s i) := MeasurableSet.iInter fun i => measurableSet_toMeasurable _ _ have hs : βˆ€ i x, x βˆ‰ s i β†’ f x = (h i).mk f x := by intro i x hx contrapose! hx exact subset_toMeasurable _ _ hx set g : Ξ± β†’ Ξ² := (β‹‚ i, s i).piecewise (const Ξ± default) f refine ⟨g, measurable_of_restrict_of_restrict_compl hsm ?_ ?_, ae_sum_iff.mpr fun i => ?_⟩ Β· rw [restrict_piecewise] simp only [s, Set.restrict, const] exact measurable_const Β· rw [restrict_piecewise_compl, compl_iInter] intro t ht refine βŸ¨β‹ƒ i, (h i).mk f ⁻¹' t ∩ (s i)ᢜ, MeasurableSet.iUnion fun i ↦ (measurable_mk _ ht).inter (measurableSet_toMeasurable _ _).compl, ?_⟩ ext ⟨x, hx⟩ simp only [mem_preimage, mem_iUnion, Subtype.coe_mk, Set.restrict, mem_inter_iff, mem_compl_iff] at hx ⊒ constructor Β· rintro ⟨i, hxt, hxs⟩ rwa [hs _ _ hxs] Β· rcases hx with ⟨i, hi⟩ rw [hs _ _ hi] exact fun h => ⟨i, h, hi⟩ Β· refine measure_mono_null (fun x (hx : f x β‰  g x) => ?_) (hsΞΌ i) contrapose! hx refine (piecewise_eq_of_not_mem _ _ _ ?_).symm exact fun h => hx (mem_iInter.1 h i) @[simp] theorem _root_.aemeasurable_sum_measure_iff [Countable ΞΉ] {ΞΌ : ΞΉ β†’ Measure Ξ±} : AEMeasurable f (sum ΞΌ) ↔ βˆ€ i, AEMeasurable f (ΞΌ i) := ⟨fun h _ => h.mono_measure (le_sum _ _), sum_measure⟩ @[simp] theorem _root_.aemeasurable_add_measure_iff : AEMeasurable f (ΞΌ + Ξ½) ↔ AEMeasurable f ΞΌ ∧ AEMeasurable f Ξ½ := by rw [← sum_cond, aemeasurable_sum_measure_iff, Bool.forall_bool, and_comm] rfl @[measurability] theorem add_measure {f : Ξ± β†’ Ξ²} (hΞΌ : AEMeasurable f ΞΌ) (hΞ½ : AEMeasurable f Ξ½) : AEMeasurable f (ΞΌ + Ξ½) := aemeasurable_add_measure_iff.2 ⟨hΞΌ, hν⟩ @[measurability] protected theorem iUnion [Countable ΞΉ] {s : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, AEMeasurable f (ΞΌ.restrict (s i))) : AEMeasurable f (ΞΌ.restrict (⋃ i, s i)) := (sum_measure h).mono_measure <| restrict_iUnion_le @[simp] theorem _root_.aemeasurable_iUnion_iff [Countable ΞΉ] {s : ΞΉ β†’ Set Ξ±} : AEMeasurable f (ΞΌ.restrict (⋃ i, s i)) ↔ βˆ€ i, AEMeasurable f (ΞΌ.restrict (s i)) := ⟨fun h _ => h.mono_measure <| restrict_mono (subset_iUnion _ _) le_rfl, AEMeasurable.iUnion⟩ @[simp] theorem _root_.aemeasurable_union_iff {s t : Set Ξ±} : AEMeasurable f (ΞΌ.restrict (s βˆͺ t)) ↔ AEMeasurable f (ΞΌ.restrict s) ∧ AEMeasurable f (ΞΌ.restrict t) := by simp only [union_eq_iUnion, aemeasurable_iUnion_iff, Bool.forall_bool, cond, and_comm] @[measurability] theorem smul_measure [SMul R ℝβ‰₯0∞] [IsScalarTower R ℝβ‰₯0∞ ℝβ‰₯0∞] (h : AEMeasurable f ΞΌ) (c : R) : AEMeasurable f (c β€’ ΞΌ) := ⟨h.mk f, h.measurable_mk, ae_smul_measure h.ae_eq_mk c⟩ theorem comp_aemeasurable {f : Ξ± β†’ Ξ΄} {g : Ξ΄ β†’ Ξ²} (hg : AEMeasurable g (ΞΌ.map f)) (hf : AEMeasurable f ΞΌ) : AEMeasurable (g ∘ f) ΞΌ := ⟨hg.mk g ∘ hf.mk f, hg.measurable_mk.comp hf.measurable_mk, (ae_eq_comp hf hg.ae_eq_mk).trans (hf.ae_eq_mk.fun_comp (mk g hg))⟩ @[fun_prop] theorem comp_aemeasurable' {f : Ξ± β†’ Ξ΄} {g : Ξ΄ β†’ Ξ²} (hg : AEMeasurable g (ΞΌ.map f)) (hf : AEMeasurable f ΞΌ) : AEMeasurable (fun x ↦ g (f x)) ΞΌ := comp_aemeasurable hg hf theorem comp_measurable {f : Ξ± β†’ Ξ΄} {g : Ξ΄ β†’ Ξ²} (hg : AEMeasurable g (ΞΌ.map f)) (hf : Measurable f) : AEMeasurable (g ∘ f) ΞΌ := hg.comp_aemeasurable hf.aemeasurable theorem comp_quasiMeasurePreserving {Ξ½ : Measure Ξ΄} {f : Ξ± β†’ Ξ΄} {g : Ξ΄ β†’ Ξ²} (hg : AEMeasurable g Ξ½) (hf : QuasiMeasurePreserving f ΞΌ Ξ½) : AEMeasurable (g ∘ f) ΞΌ := (hg.mono' hf.absolutelyContinuous).comp_measurable hf.measurable theorem map_map_of_aemeasurable {g : Ξ² β†’ Ξ³} {f : Ξ± β†’ Ξ²} (hg : AEMeasurable g (Measure.map f ΞΌ)) (hf : AEMeasurable f ΞΌ) : (ΞΌ.map f).map g = ΞΌ.map (g ∘ f) := by ext1 s hs rw [map_apply_of_aemeasurable hg hs, map_applyβ‚€ hf (hg.nullMeasurable hs), map_apply_of_aemeasurable (hg.comp_aemeasurable hf) hs, preimage_comp] @[fun_prop, measurability] theorem prodMk {f : Ξ± β†’ Ξ²} {g : Ξ± β†’ Ξ³} (hf : AEMeasurable f ΞΌ) (hg : AEMeasurable g ΞΌ) : AEMeasurable (fun x => (f x, g x)) ΞΌ := ⟨fun a => (hf.mk f a, hg.mk g a), hf.measurable_mk.prodMk hg.measurable_mk, hf.ae_eq_mk.prodMk hg.ae_eq_mk⟩ @[deprecated (since := "2025-03-05")] alias prod_mk := prodMk theorem exists_ae_eq_range_subset (H : AEMeasurable f ΞΌ) {t : Set Ξ²} (ht : βˆ€α΅ x βˆ‚ΞΌ, f x ∈ t) (hβ‚€ : t.Nonempty) : βˆƒ g, Measurable g ∧ range g βŠ† t ∧ f =ᡐ[ΞΌ] g := by classical let s : Set Ξ± := toMeasurable ΞΌ { x | f x = H.mk f x ∧ f x ∈ t }ᢜ let g : Ξ± β†’ Ξ² := piecewise s (fun _ => hβ‚€.some) (H.mk f) refine ⟨g, ?_, ?_, ?_⟩ Β· exact Measurable.piecewise (measurableSet_toMeasurable _ _) measurable_const H.measurable_mk Β· rintro _ ⟨x, rfl⟩ by_cases hx : x ∈ s Β· simpa [g, hx] using hβ‚€.some_mem Β· simp only [g, hx, piecewise_eq_of_not_mem, not_false_iff] contrapose! hx apply subset_toMeasurable simp +contextual only [hx, mem_compl_iff, mem_setOf_eq, not_and, not_false_iff, imp_true_iff] Β· have A : ΞΌ (toMeasurable ΞΌ { x | f x = H.mk f x ∧ f x ∈ t }ᢜ) = 0 := by rw [measure_toMeasurable, ← compl_mem_ae_iff, compl_compl] exact H.ae_eq_mk.and ht filter_upwards [compl_mem_ae_iff.2 A] with x hx rw [mem_compl_iff] at hx simp only [s, g, hx, piecewise_eq_of_not_mem, not_false_iff] contrapose! hx apply subset_toMeasurable simp only [hx, mem_compl_iff, mem_setOf_eq, false_and, not_false_iff] theorem exists_measurable_nonneg {Ξ²} [Preorder Ξ²] [Zero Ξ²] {mΞ² : MeasurableSpace Ξ²} {f : Ξ± β†’ Ξ²} (hf : AEMeasurable f ΞΌ) (f_nn : βˆ€α΅ t βˆ‚ΞΌ, 0 ≀ f t) : βˆƒ g, Measurable g ∧ 0 ≀ g ∧ f =ᡐ[ΞΌ] g := by obtain ⟨G, hG_meas, hG_mem, hG_ae_eq⟩ := hf.exists_ae_eq_range_subset f_nn ⟨0, le_rfl⟩ exact ⟨G, hG_meas, fun x => hG_mem (mem_range_self x), hG_ae_eq⟩ theorem subtype_mk (h : AEMeasurable f ΞΌ) {s : Set Ξ²} {hfs : βˆ€ x, f x ∈ s} : AEMeasurable (codRestrict f s hfs) ΞΌ := by nontriviality Ξ±; inhabit Ξ± obtain ⟨g, g_meas, hg, fg⟩ : βˆƒ g : Ξ± β†’ Ξ², Measurable g ∧ range g βŠ† s ∧ f =ᡐ[ΞΌ] g := h.exists_ae_eq_range_subset (Eventually.of_forall hfs) ⟨_, hfs default⟩ refine ⟨codRestrict g s fun x => hg (mem_range_self _), Measurable.subtype_mk g_meas, ?_⟩ filter_upwards [fg] with x hx simpa [Subtype.ext_iff] end AEMeasurable theorem aemeasurable_const' (h : βˆ€α΅ (x) (y) βˆ‚ΞΌ, f x = f y) : AEMeasurable f ΞΌ := by rcases eq_or_ne ΞΌ 0 with (rfl | hΞΌ) Β· exact aemeasurable_zero_measure Β· haveI := ae_neBot.2 hΞΌ rcases h.exists with ⟨x, hx⟩ exact ⟨const Ξ± (f x), measurable_const, EventuallyEq.symm hx⟩ open scoped Interval in theorem aemeasurable_uIoc_iff [LinearOrder Ξ±] {f : Ξ± β†’ Ξ²} {a b : Ξ±} : (AEMeasurable f <| ΞΌ.restrict <| Ξ™ a b) ↔ (AEMeasurable f <| ΞΌ.restrict <| Ioc a b) ∧ (AEMeasurable f <| ΞΌ.restrict <| Ioc b a) := by rw [uIoc_eq_union, aemeasurable_union_iff] theorem aemeasurable_iff_measurable [ΞΌ.IsComplete] : AEMeasurable f ΞΌ ↔ Measurable f := ⟨fun h => h.nullMeasurable.measurable_of_complete, fun h => h.aemeasurable⟩ theorem MeasurableEmbedding.aemeasurable_map_iff {g : Ξ² β†’ Ξ³} (hf : MeasurableEmbedding f) : AEMeasurable g (ΞΌ.map f) ↔ AEMeasurable (g ∘ f) ΞΌ := by refine ⟨fun H => H.comp_measurable hf.measurable, ?_⟩ rintro ⟨g₁, hgm₁, heq⟩ rcases hf.exists_measurable_extend hgm₁ fun x => ⟨g x⟩ with ⟨gβ‚‚, hgmβ‚‚, rfl⟩ exact ⟨gβ‚‚, hgmβ‚‚, hf.ae_map_iff.2 heq⟩
Mathlib/MeasureTheory/Measure/AEMeasurable.lean
244
249
theorem MeasurableEmbedding.aemeasurable_comp_iff {g : Ξ² β†’ Ξ³} (hg : MeasurableEmbedding g) {ΞΌ : Measure Ξ±} : AEMeasurable (g ∘ f) ΞΌ ↔ AEMeasurable f ΞΌ := by
refine ⟨fun H => ?_, hg.measurable.comp_aemeasurable⟩ suffices AEMeasurable ((rangeSplitting g ∘ rangeFactorization g) ∘ f) μ by rwa [(rightInverse_rangeSplitting hg.injective).comp_eq_id] at this exact hg.measurable_rangeSplitting.comp_aemeasurable H.subtype_mk
/- 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.ConditionallyCompleteLattice.Basic import Mathlib.Order.Cover import Mathlib.Order.Iterate /-! # Successor and predecessor This file defines successor and predecessor orders. `succ a`, the successor of an element `a : Ξ±` is the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples include `β„•`, `β„€`, `β„•+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor order... ## Typeclasses * `SuccOrder`: Order equipped with a sensible successor function. * `PredOrder`: Order equipped with a sensible predecessor function. ## Implementation notes Maximal elements don't have a sensible successor. Thus the naΓ―ve typeclass ```lean class NaiveSuccOrder (Ξ± : Type*) [Preorder Ξ±] where (succ : Ξ± β†’ Ξ±) (succ_le_iff : βˆ€ {a b}, succ a ≀ b ↔ a < b) (lt_succ_iff : βˆ€ {a b}, a < succ b ↔ a ≀ b) ``` can't apply to an `OrderTop` because plugging in `a = b = ⊀` into either of `succ_le_iff` and `lt_succ_iff` yields `⊀ < ⊀` (or more generally `m < m` for a maximal element `m`). The solution taken here is to remove the implications `≀ β†’ <` and instead require that `a < succ a` for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of `max_of_succ_le`). The stricter condition of every element having a sensible successor can be obtained through the combination of `SuccOrder Ξ±` and `NoMaxOrder Ξ±`. -/ open Function OrderDual Set variable {Ξ± Ξ² : Type*} /-- Order equipped with a sensible successor function. -/ @[ext] class SuccOrder (Ξ± : Type*) [Preorder Ξ±] where /-- Successor function -/ succ : Ξ± β†’ Ξ± /-- Proof of basic ordering with respect to `succ` -/ le_succ : βˆ€ a, a ≀ succ a /-- Proof of interaction between `succ` and maximal element -/ max_of_succ_le {a} : succ a ≀ a β†’ IsMax a /-- Proof that `succ a` is the least element greater than `a` -/ succ_le_of_lt {a b} : a < b β†’ succ a ≀ b /-- Order equipped with a sensible predecessor function. -/ @[ext] class PredOrder (Ξ± : Type*) [Preorder Ξ±] where /-- Predecessor function -/ pred : Ξ± β†’ Ξ± /-- Proof of basic ordering with respect to `pred` -/ pred_le : βˆ€ a, pred a ≀ a /-- Proof of interaction between `pred` and minimal element -/ min_of_le_pred {a} : a ≀ pred a β†’ IsMin a /-- Proof that `pred b` is the greatest element less than `b` -/ le_pred_of_lt {a b} : a < b β†’ a ≀ pred b instance [Preorder Ξ±] [SuccOrder Ξ±] : PredOrder Ξ±α΅’α΅ˆ where pred := toDual ∘ SuccOrder.succ ∘ ofDual pred_le := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, SuccOrder.le_succ, implies_true] min_of_le_pred h := by apply SuccOrder.max_of_succ_le h le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h instance [Preorder Ξ±] [PredOrder Ξ±] : SuccOrder Ξ±α΅’α΅ˆ where succ := toDual ∘ PredOrder.pred ∘ ofDual le_succ := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, PredOrder.pred_le, implies_true] max_of_succ_le h := by apply PredOrder.min_of_le_pred h succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h section Preorder variable [Preorder Ξ±] /-- A constructor for `SuccOrder Ξ±` usable when `Ξ±` has no maximal element. -/ def SuccOrder.ofSuccLeIff (succ : Ξ± β†’ Ξ±) (hsucc_le_iff : βˆ€ {a b}, succ a ≀ b ↔ a < b) : SuccOrder Ξ± := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h } /-- A constructor for `PredOrder Ξ±` usable when `Ξ±` has no minimal element. -/ def PredOrder.ofLePredIff (pred : Ξ± β†’ Ξ±) (hle_pred_iff : βˆ€ {a b}, a ≀ pred b ↔ a < b) : PredOrder Ξ± := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h } end Preorder section LinearOrder variable [LinearOrder Ξ±] /-- A constructor for `SuccOrder Ξ±` for `Ξ±` a linear order. -/ @[simps] def SuccOrder.ofCore (succ : Ξ± β†’ Ξ±) (hn : βˆ€ {a}, Β¬IsMax a β†’ βˆ€ b, a < b ↔ succ a ≀ b) (hm : βˆ€ a, IsMax a β†’ succ a = a) : SuccOrder Ξ± := { succ succ_le_of_lt := fun {a b} => by_cases (fun h hab => (hm a h).symm β–Έ hab.le) fun h => (hn h b).mp le_succ := fun a => by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } /-- A constructor for `PredOrder Ξ±` for `Ξ±` a linear order. -/ @[simps] def PredOrder.ofCore (pred : Ξ± β†’ Ξ±) (hn : βˆ€ {a}, Β¬IsMin a β†’ βˆ€ b, b ≀ pred a ↔ b < a) (hm : βˆ€ a, IsMin a β†’ pred a = a) : PredOrder Ξ± := { pred le_pred_of_lt := fun {a b} => by_cases (fun h hab => (hm b h).symm β–Έ hab.le) fun h => (hn h a).mpr pred_le := fun a => by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } variable (Ξ±) open Classical in /-- A well-order is a `SuccOrder`. -/ noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT Ξ±] : SuccOrder Ξ± := ofCore (fun a ↦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a) (fun ha _ ↦ by rw [not_isMax_iff] at ha simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha] exact ⟨(wellFounded_lt.min_le Β· ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)⟩) fun _ ha ↦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr Β·) /-- A linear order with well-founded greater-than relation is a `PredOrder`. -/ noncomputable def PredOrder.ofLinearWellFoundedGT (Ξ±) [LinearOrder Ξ±] [WellFoundedGT Ξ±] : PredOrder Ξ± := letI := SuccOrder.ofLinearWellFoundedLT Ξ±α΅’α΅ˆ; inferInstanceAs (PredOrder Ξ±α΅’α΅ˆα΅’α΅ˆ) end LinearOrder /-! ### Successor order -/ namespace Order section Preorder variable [Preorder Ξ±] [SuccOrder Ξ±] {a b : Ξ±} /-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater than `a`. If `a` is maximal, then `succ a = a`. -/ def succ : Ξ± β†’ Ξ± := SuccOrder.succ theorem le_succ : βˆ€ a : Ξ±, a ≀ succ a := SuccOrder.le_succ theorem max_of_succ_le {a : Ξ±} : succ a ≀ a β†’ IsMax a := SuccOrder.max_of_succ_le theorem succ_le_of_lt {a b : Ξ±} : a < b β†’ succ a ≀ b := SuccOrder.succ_le_of_lt alias _root_.LT.lt.succ_le := succ_le_of_lt @[simp] theorem succ_le_iff_isMax : succ a ≀ a ↔ IsMax a := ⟨max_of_succ_le, fun h => h <| le_succ _⟩ alias ⟨_root_.IsMax.of_succ_le, _root_.IsMax.succ_le⟩ := succ_le_iff_isMax @[simp] theorem lt_succ_iff_not_isMax : a < succ a ↔ Β¬IsMax a := ⟨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_le fun h => ha <| max_of_succ_le h⟩ alias ⟨_, lt_succ_of_not_isMax⟩ := lt_succ_iff_not_isMax theorem wcovBy_succ (a : Ξ±) : a β©Ώ succ a := ⟨le_succ a, fun _ hb => (succ_le_of_lt hb).not_lt⟩ theorem covBy_succ_of_not_isMax (h : Β¬IsMax a) : a β‹– succ a := (wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h theorem lt_succ_of_le_of_not_isMax (hab : b ≀ a) (ha : Β¬IsMax a) : b < succ a := hab.trans_lt <| lt_succ_of_not_isMax ha theorem succ_le_iff_of_not_isMax (ha : Β¬IsMax a) : succ a ≀ b ↔ a < b := ⟨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_lt⟩ lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : Β¬ IsMax b) : succ a < succ b := lt_succ_of_le_of_not_isMax (succ_le_of_lt h) hb @[simp, mono, gcongr] theorem succ_le_succ (h : a ≀ b) : succ a ≀ succ b := by by_cases hb : IsMax b Β· by_cases hba : b ≀ a Β· exact (hb <| hba.trans <| le_succ _).trans (le_succ _) Β· exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le <| le_succ b) Β· rw [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h] apply lt_succ_of_le_of_not_isMax h hb theorem succ_mono : Monotone (succ : Ξ± β†’ Ξ±) := fun _ _ => succ_le_succ /-- See also `Order.succ_eq_of_covBy`. -/ lemma le_succ_of_wcovBy (h : a β©Ώ b) : b ≀ succ a := by obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le Β· by_contra hba exact h.2 (lt_succ_of_not_isMax hab.lt.not_isMax) <| hab.lt.succ_le.lt_of_not_le hba Β· exact hba.trans (le_succ _) alias _root_.WCovBy.le_succ := le_succ_of_wcovBy theorem le_succ_iterate (k : β„•) (x : Ξ±) : x ≀ succ^[k] x := id_le_iterate_of_id_le le_succ _ _ theorem isMax_iterate_succ_of_eq_of_lt {n m : β„•} (h_eq : succ^[n] a = succ^[m] a) (h_lt : n < m) : IsMax (succ^[n] a) := by refine max_of_succ_le (le_trans ?_ h_eq.symm.le) rw [← iterate_succ_apply' succ] have h_le : n + 1 ≀ m := Nat.succ_le_of_lt h_lt exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le theorem isMax_iterate_succ_of_eq_of_ne {n m : β„•} (h_eq : succ^[n] a = succ^[m] a) (h_ne : n β‰  m) : IsMax (succ^[n] a) := by rcases le_total n m with h | h Β· exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne) Β· rw [h_eq] exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm) theorem Iic_subset_Iio_succ_of_not_isMax (ha : Β¬IsMax a) : Iic a βŠ† Iio (succ a) := fun _ => (lt_succ_of_le_of_not_isMax Β· ha) theorem Ici_succ_of_not_isMax (ha : Β¬IsMax a) : Ici (succ a) = Ioi a := Set.ext fun _ => succ_le_iff_of_not_isMax ha theorem Icc_subset_Ico_succ_right_of_not_isMax (hb : Β¬IsMax b) : Icc a b βŠ† Ico a (succ b) := by rw [← Ici_inter_Iio, ← Ici_inter_Iic] gcongr intro _ h apply lt_succ_of_le_of_not_isMax h hb theorem Ioc_subset_Ioo_succ_right_of_not_isMax (hb : Β¬IsMax b) : Ioc a b βŠ† Ioo a (succ b) := by rw [← Ioi_inter_Iio, ← Ioi_inter_Iic] gcongr intro _ h apply Iic_subset_Iio_succ_of_not_isMax hb h theorem Icc_succ_left_of_not_isMax (ha : Β¬IsMax a) : Icc (succ a) b = Ioc a b := by rw [← Ici_inter_Iic, Ici_succ_of_not_isMax ha, Ioi_inter_Iic] theorem Ico_succ_left_of_not_isMax (ha : Β¬IsMax a) : Ico (succ a) b = Ioo a b := by rw [← Ici_inter_Iio, Ici_succ_of_not_isMax ha, Ioi_inter_Iio] section NoMaxOrder variable [NoMaxOrder Ξ±] theorem lt_succ (a : Ξ±) : a < succ a := lt_succ_of_not_isMax <| not_isMax a @[simp] theorem lt_succ_of_le : a ≀ b β†’ a < succ b := (lt_succ_of_le_of_not_isMax Β· <| not_isMax b) @[simp] theorem succ_le_iff : succ a ≀ b ↔ a < b := succ_le_iff_of_not_isMax <| not_isMax a @[gcongr] theorem succ_lt_succ (hab : a < b) : succ a < succ b := by simp [hab] theorem succ_strictMono : StrictMono (succ : Ξ± β†’ Ξ±) := fun _ _ => succ_lt_succ theorem covBy_succ (a : Ξ±) : a β‹– succ a := covBy_succ_of_not_isMax <| not_isMax a theorem Iic_subset_Iio_succ (a : Ξ±) : Iic a βŠ† Iio (succ a) := by simp @[simp] theorem Ici_succ (a : Ξ±) : Ici (succ a) = Ioi a := Ici_succ_of_not_isMax <| not_isMax _ @[simp] theorem Icc_subset_Ico_succ_right (a b : Ξ±) : Icc a b βŠ† Ico a (succ b) := Icc_subset_Ico_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Ioc_subset_Ioo_succ_right (a b : Ξ±) : Ioc a b βŠ† Ioo a (succ b) := Ioc_subset_Ioo_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Icc_succ_left (a b : Ξ±) : Icc (succ a) b = Ioc a b := Icc_succ_left_of_not_isMax <| not_isMax _ @[simp] theorem Ico_succ_left (a b : Ξ±) : Ico (succ a) b = Ioo a b := Ico_succ_left_of_not_isMax <| not_isMax _ end NoMaxOrder end Preorder section PartialOrder variable [PartialOrder Ξ±] [SuccOrder Ξ±] {a b : Ξ±} @[simp] theorem succ_eq_iff_isMax : succ a = a ↔ IsMax a := ⟨fun h => max_of_succ_le h.le, fun h => h.eq_of_ge <| le_succ _⟩ alias ⟨_, _root_.IsMax.succ_eq⟩ := succ_eq_iff_isMax lemma le_iff_eq_or_succ_le : a ≀ b ↔ a = b ∨ succ a ≀ b := by by_cases ha : IsMax a Β· simpa [ha.succ_eq] using le_of_eq Β· rw [succ_le_iff_of_not_isMax ha, le_iff_eq_or_lt] theorem le_le_succ_iff : a ≀ b ∧ b ≀ succ a ↔ b = a ∨ b = succ a := by refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b β‰  a => h.2.antisymm (succ_le_of_lt <| h.1.lt_of_ne <| hba.symm), ?_⟩ rintro (rfl | rfl) Β· exact ⟨le_rfl, le_succ b⟩ Β· exact ⟨le_succ a, le_rfl⟩ /-- See also `Order.le_succ_of_wcovBy`. -/ lemma succ_eq_of_covBy (h : a β‹– b) : succ a = b := (succ_le_of_lt h.lt).antisymm h.wcovBy.le_succ alias _root_.CovBy.succ_eq := succ_eq_of_covBy theorem _root_.OrderIso.map_succ [PartialOrder Ξ²] [SuccOrder Ξ²] (f : Ξ± ≃o Ξ²) (a : Ξ±) : f (succ a) = succ (f a) := by by_cases h : IsMax a Β· rw [h.succ_eq, (f.isMax_apply.2 h).succ_eq] Β· exact (f.map_covBy.2 <| covBy_succ_of_not_isMax h).succ_eq.symm section NoMaxOrder variable [NoMaxOrder Ξ±] theorem succ_eq_iff_covBy : succ a = b ↔ a β‹– b := ⟨by rintro rfl; exact covBy_succ _, CovBy.succ_eq⟩ end NoMaxOrder section OrderTop variable [OrderTop Ξ±] @[simp] theorem succ_top : succ (⊀ : Ξ±) = ⊀ := by rw [succ_eq_iff_isMax, isMax_iff_eq_top] theorem succ_le_iff_eq_top : succ a ≀ a ↔ a = ⊀ := succ_le_iff_isMax.trans isMax_iff_eq_top theorem lt_succ_iff_ne_top : a < succ a ↔ a β‰  ⊀ := lt_succ_iff_not_isMax.trans not_isMax_iff_ne_top end OrderTop section OrderBot variable [OrderBot Ξ±] [Nontrivial Ξ±] theorem bot_lt_succ (a : Ξ±) : βŠ₯ < succ a := (lt_succ_of_not_isMax not_isMax_bot).trans_le <| succ_mono bot_le theorem succ_ne_bot (a : Ξ±) : succ a β‰  βŠ₯ := (bot_lt_succ a).ne' end OrderBot end PartialOrder section LinearOrder variable [LinearOrder Ξ±] [SuccOrder Ξ±] {a b : Ξ±} theorem le_of_lt_succ {a b : Ξ±} : a < succ b β†’ a ≀ b := fun h ↦ by by_contra! nh exact (h.trans_le (succ_le_of_lt nh)).false theorem lt_succ_iff_of_not_isMax (ha : Β¬IsMax a) : b < succ a ↔ b ≀ a := ⟨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax ha⟩ theorem succ_lt_succ_iff_of_not_isMax (ha : Β¬IsMax a) (hb : Β¬IsMax b) : succ a < succ b ↔ a < b := by rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha] theorem succ_le_succ_iff_of_not_isMax (ha : Β¬IsMax a) (hb : Β¬IsMax b) : succ a ≀ succ b ↔ a ≀ b := by rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb] theorem Iio_succ_of_not_isMax (ha : Β¬IsMax a) : Iio (succ a) = Iic a := Set.ext fun _ => lt_succ_iff_of_not_isMax ha theorem Ico_succ_right_of_not_isMax (hb : Β¬IsMax b) : Ico a (succ b) = Icc a b := by rw [← Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic] theorem Ioo_succ_right_of_not_isMax (hb : Β¬IsMax b) : Ioo a (succ b) = Ioc a b := by rw [← Ioi_inter_Iio, Iio_succ_of_not_isMax hb, Ioi_inter_Iic] theorem succ_eq_succ_iff_of_not_isMax (ha : Β¬IsMax a) (hb : Β¬IsMax b) : succ a = succ b ↔ a = b := by rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_isMax ha hb, succ_lt_succ_iff_of_not_isMax ha hb] theorem le_succ_iff_eq_or_le : a ≀ succ b ↔ a = succ b ∨ a ≀ b := by by_cases hb : IsMax b Β· rw [hb.succ_eq, or_iff_right_of_imp le_of_eq] Β· rw [← lt_succ_iff_of_not_isMax hb, le_iff_eq_or_lt] theorem lt_succ_iff_eq_or_lt_of_not_isMax (hb : Β¬IsMax b) : a < succ b ↔ a = b ∨ a < b := (lt_succ_iff_of_not_isMax hb).trans le_iff_eq_or_lt
Mathlib/Order/SuccPred/Basic.lean
431
434
theorem not_isMin_succ [Nontrivial Ξ±] (a : Ξ±) : Β¬ IsMin (succ a) := by
obtain ha | ha := (le_succ a).eq_or_lt Β· exact (ha β–Έ succ_eq_iff_isMax.1 ha.symm).not_isMin Β· exact not_isMin_of_lt ha
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Patrick Massot -/ import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic import Mathlib.MeasureTheory.Measure.Real import Mathlib.Order.Filter.IndicatorFunction /-! # The dominated convergence theorem This file collects various results related to the Lebesgue dominated convergence theorem for the Bochner integral. ## Main results - `MeasureTheory.tendsto_integral_of_dominated_convergence`: the Lebesgue dominated convergence theorem for the Bochner integral - `MeasureTheory.hasSum_integral_of_dominated_convergence`: the Lebesgue dominated convergence theorem for series - `MeasureTheory.integral_tsum`, `MeasureTheory.integral_tsum_of_summable_integral_norm`: the integral and `tsum`s commute, if the norms of the functions form a summable series - `intervalIntegral.hasSum_integral_of_dominated_convergence`: the Lebesgue dominated convergence theorem for parametric interval integrals - `intervalIntegral.continuous_of_dominated_interval`: continuity of the interval integral w.r.t. a parameter - `intervalIntegral.continuous_primitive` and friends: primitives of interval integrable measurable functions are continuous -/ open MeasureTheory Metric /-! ## The Lebesgue dominated convergence theorem for the Bochner integral -/ section DominatedConvergenceTheorem open Set Filter TopologicalSpace ENNReal open scoped Topology Interval namespace MeasureTheory variable {Ξ± E G : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup G] [NormedSpace ℝ G] {m : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} /-- **Lebesgue dominated convergence theorem** provides sufficient conditions under which almost everywhere convergence of a sequence of functions implies the convergence of their integrals. We could weaken the condition `bound_integrable` to require `HasFiniteIntegral bound ΞΌ` instead (i.e. not requiring that `bound` is measurable), but in all applications proving integrability is easier. -/ theorem tendsto_integral_of_dominated_convergence {F : β„• β†’ Ξ± β†’ G} {f : Ξ± β†’ G} (bound : Ξ± β†’ ℝ) (F_measurable : βˆ€ n, AEStronglyMeasurable (F n) ΞΌ) (bound_integrable : Integrable bound ΞΌ) (h_bound : βˆ€ n, βˆ€α΅ a βˆ‚ΞΌ, β€–F n aβ€– ≀ bound a) (h_lim : βˆ€α΅ a βˆ‚ΞΌ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫ a, F n a βˆ‚ΞΌ) atTop (𝓝 <| ∫ a, f a βˆ‚ΞΌ) := by by_cases hG : CompleteSpace G Β· simp only [integral, hG, L1.integral] exact tendsto_setToFun_of_dominated_convergence (dominatedFinMeasAdditive_weightedSMul ΞΌ) bound F_measurable bound_integrable h_bound h_lim Β· simp [integral, hG] /-- Lebesgue dominated convergence theorem for filters with a countable basis -/
Mathlib/MeasureTheory/Integral/DominatedConvergence.lean
66
75
theorem tendsto_integral_filter_of_dominated_convergence {ΞΉ} {l : Filter ΞΉ} [l.IsCountablyGenerated] {F : ΞΉ β†’ Ξ± β†’ G} {f : Ξ± β†’ G} (bound : Ξ± β†’ ℝ) (hF_meas : βˆ€αΆ  n in l, AEStronglyMeasurable (F n) ΞΌ) (h_bound : βˆ€αΆ  n in l, βˆ€α΅ a βˆ‚ΞΌ, β€–F n aβ€– ≀ bound a) (bound_integrable : Integrable bound ΞΌ) (h_lim : βˆ€α΅ a βˆ‚ΞΌ, Tendsto (fun n => F n a) l (𝓝 (f a))) : Tendsto (fun n => ∫ a, F n a βˆ‚ΞΌ) l (𝓝 <| ∫ a, f a βˆ‚ΞΌ) := by
by_cases hG : CompleteSpace G Β· simp only [integral, hG, L1.integral] exact tendsto_setToFun_filter_of_dominated_convergence (dominatedFinMeasAdditive_weightedSMul ΞΌ) bound hF_meas h_bound bound_integrable h_lim Β· simp [integral, hG, tendsto_const_nhds]
/- 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.Basic import Mathlib.Algebra.ContinuedFractions.Translations import Mathlib.Algebra.Order.Floor.Ring /-! # Basic Translation Lemmas Between Structures Defined for Computing Continued Fractions ## Summary This is a collection of simple lemmas between the different structures used for the computation of continued fractions defined in `Mathlib.Algebra.ContinuedFractions.Computation.Basic`. The file consists of three sections: 1. Recurrences and inversion lemmas for `IntFractPair.stream`: these lemmas give us inversion rules and recurrences for the computation of the stream of integer and fractional parts of a value. 2. Translation lemmas for the head term: these lemmas show us that the head term of the computed continued fraction of a value `v` is `⌊vβŒ‹` and how this head term is moved along the structures used in the computation process. 3. Translation lemmas for the sequence: these lemmas show how the sequences of the involved structures (`IntFractPair.stream`, `IntFractPair.seq1`, and `GenContFract.of`) are connected, i.e. how the values are moved along the structures and the termination of one sequence implies the termination of another sequence. ## Main Theorems - `succ_nth_stream_eq_some_iff` gives as a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of non-termination. - `succ_nth_stream_eq_none_iff` gives as a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of termination. - `get?_of_eq_some_of_succ_get?_intFractPair_stream` and `get?_of_eq_some_of_get?_intFractPair_stream_fr_ne_zero` show how the entries of the sequence of the computed continued fraction can be obtained from the stream of integer and fractional parts. -/ assert_not_exists Finset namespace GenContFract open GenContFract (of) -- Fix a discrete linear ordered division ring with `floor` function and a value `v`. variable {K : Type*} [DivisionRing K] [LinearOrder K] [FloorRing K] {v : K} namespace IntFractPair /-! ### Recurrences and Inversion Lemmas for `IntFractPair.stream` Here we state some lemmas that give us inversion rules and recurrences for the computation of the stream of integer and fractional parts of a value. -/ theorem stream_zero (v : K) : IntFractPair.stream v 0 = some (IntFractPair.of v) := rfl variable {n : β„•} theorem stream_eq_none_of_fr_eq_zero {ifp_n : IntFractPair K} (stream_nth_eq : IntFractPair.stream v n = some ifp_n) (nth_fr_eq_zero : ifp_n.fr = 0) : IntFractPair.stream v (n + 1) = none := by obtain ⟨_, fr⟩ := ifp_n change fr = 0 at nth_fr_eq_zero simp [IntFractPair.stream, stream_nth_eq, nth_fr_eq_zero] /-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of termination. -/ theorem succ_nth_stream_eq_none_iff : IntFractPair.stream v (n + 1) = none ↔ IntFractPair.stream v n = none ∨ βˆƒ ifp, IntFractPair.stream v n = some ifp ∧ ifp.fr = 0 := by rw [IntFractPair.stream] cases IntFractPair.stream v n <;> simp [imp_false] /-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of non-termination. -/ theorem succ_nth_stream_eq_some_iff {ifp_succ_n : IntFractPair K} : IntFractPair.stream v (n + 1) = some ifp_succ_n ↔ βˆƒ ifp_n : IntFractPair K, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr β‰  0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n := by simp [IntFractPair.stream, ite_eq_iff, Option.bind_eq_some_iff] /-- An easier to use version of one direction of `GenContFract.IntFractPair.succ_nth_stream_eq_some_iff`. -/ theorem stream_succ_of_some {p : IntFractPair K} (h : IntFractPair.stream v n = some p) (h' : p.fr β‰  0) : IntFractPair.stream v (n + 1) = some (IntFractPair.of p.fr⁻¹) := succ_nth_stream_eq_some_iff.mpr ⟨p, h, h', rfl⟩ /-- The stream of `IntFractPair`s of an integer stops after the first term. -/ theorem stream_succ_of_int [IsStrictOrderedRing K] (a : β„€) (n : β„•) : IntFractPair.stream (a : K) (n + 1) = none := by induction n with | zero => refine IntFractPair.stream_eq_none_of_fr_eq_zero (IntFractPair.stream_zero (a : K)) ?_ simp only [IntFractPair.of, Int.fract_intCast] | succ n ih => exact IntFractPair.succ_nth_stream_eq_none_iff.mpr (Or.inl ih) theorem exists_succ_nth_stream_of_fr_zero {ifp_succ_n : IntFractPair K} (stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) (succ_nth_fr_eq_zero : ifp_succ_n.fr = 0) : βˆƒ ifp_n : IntFractPair K, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr⁻¹ = ⌊ifp_n.frβ»ΒΉβŒ‹ := by -- get the witness from `succ_nth_stream_eq_some_iff` and prove that it has the additional -- properties rcases succ_nth_stream_eq_some_iff.mp stream_succ_nth_eq with ⟨ifp_n, seq_nth_eq, _, rfl⟩ refine ⟨ifp_n, seq_nth_eq, ?_⟩ simpa only [IntFractPair.of, Int.fract, sub_eq_zero] using succ_nth_fr_eq_zero /-- A recurrence relation that expresses the `(n+1)`th term of the stream of `IntFractPair`s of `v` for non-integer `v` in terms of the `n`th term of the stream associated to the inverse of the fractional part of `v`. -/ theorem stream_succ (h : Int.fract v β‰  0) (n : β„•) : IntFractPair.stream v (n + 1) = IntFractPair.stream (Int.fract v)⁻¹ n := by induction n with | zero => have H : (IntFractPair.of v).fr = Int.fract v := by simp [IntFractPair.of] rw [stream_zero, stream_succ_of_some (stream_zero v) (ne_of_eq_of_ne H h), H] | succ n ih => rcases eq_or_ne (IntFractPair.stream (Int.fract v)⁻¹ n) none with hnone | hsome Β· rw [hnone] at ih rw [succ_nth_stream_eq_none_iff.mpr (Or.inl hnone), succ_nth_stream_eq_none_iff.mpr (Or.inl ih)] Β· obtain ⟨p, hp⟩ := Option.ne_none_iff_exists'.mp hsome rw [hp] at ih rcases eq_or_ne p.fr 0 with hz | hnz Β· rw [stream_eq_none_of_fr_eq_zero hp hz, stream_eq_none_of_fr_eq_zero ih hz] Β· rw [stream_succ_of_some hp hnz, stream_succ_of_some ih hnz] end IntFractPair section Head /-! ### Translation of the Head Term Here we state some lemmas that show us that the head term of the computed continued fraction of a value `v` is `⌊vβŒ‹` and how this head term is moved along the structures used in the computation process. -/ /-- The head term of the sequence with head of `v` is just the integer part of `v`. -/ @[simp] theorem IntFractPair.seq1_fst_eq_of : (IntFractPair.seq1 v).fst = IntFractPair.of v := rfl theorem of_h_eq_intFractPair_seq1_fst_b : (of v).h = (IntFractPair.seq1 v).fst.b := by cases aux_seq_eq : IntFractPair.seq1 v simp [of, aux_seq_eq] /-- The head term of the gcf of `v` is `⌊vβŒ‹`. -/ @[simp]
Mathlib/Algebra/ContinuedFractions/Computation/Translations.lean
163
165
theorem of_h_eq_floor : (of v).h = ⌊vβŒ‹ := by
simp [of_h_eq_intFractPair_seq1_fst_b, IntFractPair.of]
/- 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.Complex import Qq /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex 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`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (Ο€ y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : β„‚) ^ (y : β„‚)).re noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : β„‚) ^ (y : β„‚)).re := rfl theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : β„€) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : β„•) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[simp] lemma exp_one_pow (n : β„•) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≀ x) : x ^ y = 0 ↔ x = 0 ∧ y β‰  0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] @[simp] lemma rpow_eq_zero (hx : 0 ≀ x) (hy : y β‰  0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≀ x) (hy : y β‰  0) : x ^ y β‰  0 ↔ x β‰  0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * Ο€) := by rw [rpow_def, Complex.cpow_def, if_neg] Β· have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * Ο€) * Complex.I := by simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring Β· rw [Complex.ofReal_eq_zero] exact ne_of_lt hx theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≀ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * Ο€) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x β‰  0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor Β· intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 Β· subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ Β· rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ Β· rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) Β· exact zero_rpow h Β· exact rpow_zero _ theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≀ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one] theorem zero_rpow_nonneg (x : ℝ) : 0 ≀ (0 : ℝ) ^ x := by by_cases h : x = 0 <;> simp [h, zero_le_one] @[bound] theorem rpow_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : 0 ≀ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≀ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≀ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] @[bound] theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≀ |x| ^ y := by rcases le_or_lt 0 x with hx | hx Β· rw [abs_rpow_of_nonneg hx] Β· rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul, abs_of_pos (exp_pos _)] exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _) theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≀ exp (log x * y) := by refine (abs_rpow_le_abs_rpow x y).trans ?_ by_cases hx : x = 0 Β· by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one] Β· rw [rpow_def_of_pos (abs_pos.2 hx), log_abs] lemma rpow_inv_log (hxβ‚€ : 0 < x) (hx₁ : x β‰  1) : x ^ (log x)⁻¹ = exp 1 := by rw [rpow_def_of_pos hxβ‚€, mul_inv_cancelβ‚€] exact log_ne_zero.2 ⟨hxβ‚€.ne', hx₁, (hxβ‚€.trans' <| by norm_num).ne'⟩ /-- See `Real.rpow_inv_log` for the equality when `x β‰  1` is strictly positive. -/ lemma rpow_inv_log_le_exp_one : x ^ (log x)⁻¹ ≀ exp 1 := by calc _ ≀ |x ^ (log x)⁻¹| := le_abs_self _ _ ≀ |x| ^ (log x)⁻¹ := abs_rpow_le_abs_rpow .. rw [← log_abs] obtain hx | hx := (abs_nonneg x).eq_or_gt Β· simp [hx] Β· rw [rpow_def_of_pos hx] gcongr exact mul_inv_le_one theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≀ x) : β€–x ^ yβ€– = β€–xβ€– ^ y := by simp_rw [Real.norm_eq_abs] exact abs_rpow_of_nonneg hx_nonneg variable {w x y z : ℝ} theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by simp only [rpow_def_of_pos hx, mul_add, exp_add] theorem rpow_add' (hx : 0 ≀ x) (h : y + z β‰  0) : x ^ (y + z) = x ^ y * x ^ z := by rcases hx.eq_or_lt with (rfl | pos) Β· rw [zero_rpow h, zero_eq_mul] have : y β‰  0 ∨ z β‰  0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm β–Έ hz.symm β–Έ zero_add 0 exact this.imp zero_rpow zero_rpow Β· exact rpow_add pos _ _ /-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (hx : 0 ≀ x) (hw : w β‰  0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add' hx]; rwa [h] theorem rpow_add_of_nonneg (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 ≀ z) : x ^ (y + z) = x ^ y * x ^ z := by rcases hy.eq_or_lt with (rfl | hy) Β· rw [zero_add, rpow_zero, one_mul] exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz) /-- For `0 ≀ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for `x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish. The inequality is always true, though, and given in this lemma. -/ theorem le_rpow_add {x : ℝ} (hx : 0 ≀ x) (y z : ℝ) : x ^ y * x ^ z ≀ x ^ (y + z) := by rcases le_iff_eq_or_lt.1 hx with (H | pos) Β· by_cases h : y + z = 0 Β· simp only [H.symm, h, rpow_zero] calc (0 : ℝ) ^ y * 0 ^ z ≀ 1 * 1 := mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one _ = 1 := by simp Β· simp [rpow_add', ← H, h] Β· simp [rpow_add pos] theorem rpow_sum_of_pos {ΞΉ : Type*} {a : ℝ} (ha : 0 < a) (f : ΞΉ β†’ ℝ) (s : Finset ΞΉ) : (a ^ βˆ‘ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ β†’+ (Additive ℝ)) f s theorem rpow_sum_of_nonneg {ΞΉ : Type*} {a : ℝ} (ha : 0 ≀ a) {s : Finset ΞΉ} {f : ΞΉ β†’ ℝ} (h : βˆ€ x ∈ s, 0 ≀ f x) : (a ^ βˆ‘ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by induction' s using Finset.cons_induction with i s hi ihs Β· rw [sum_empty, Finset.prod_empty, rpow_zero] Β· rw [forall_mem_cons] at h rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)] theorem rpow_neg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg] theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv] theorem rpow_sub' {x : ℝ} (hx : 0 ≀ x) {y z : ℝ} (h : y - z β‰  0) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg] at h ⊒ simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv] protected theorem _root_.HasCompactSupport.rpow_const {Ξ± : Type*} [TopologicalSpace Ξ±] {f : Ξ± β†’ ℝ} (hf : HasCompactSupport f) {r : ℝ} (hr : r β‰  0) : HasCompactSupport (fun x ↦ f x ^ r) := hf.comp_left (g := (Β· ^ r)) (Real.zero_rpow hr) end Real /-! ## Comparing real and complex powers -/ namespace Complex theorem ofReal_cpow {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : ((x ^ y : ℝ) : β„‚) = (x : β„‚) ^ (y : β„‚) := by simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;> simp [Complex.ofReal_log hx] theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≀ 0) (y : β„‚) : (x : β„‚) ^ y = (-x : β„‚) ^ y * exp (Ο€ * I * y) := by rcases hx.eq_or_lt with (rfl | hlt) Β· rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*] have hne : (x : β„‚) β‰  0 := ofReal_ne_zero.mpr hlt.ne rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log, log, norm_neg, arg_ofReal_of_neg hlt, ← ofReal_neg, arg_ofReal_of_nonneg (neg_nonneg.2 hx), ofReal_zero, zero_mul, add_zero] lemma cpow_ofReal (x : β„‚) (y : ℝ) : x ^ (y : β„‚) = ↑(β€–xβ€– ^ y) * (Real.cos (arg x * y) + Real.sin (arg x * y) * I) := by rcases eq_or_ne x 0 with rfl | hx Β· simp [ofReal_cpow le_rfl] Β· rw [cpow_def_of_ne_zero hx, exp_eq_exp_re_mul_sin_add_cos, mul_comm (log x)] norm_cast rw [re_ofReal_mul, im_ofReal_mul, log_re, log_im, mul_comm y, mul_comm y, Real.exp_mul, Real.exp_log] rwa [norm_pos_iff] lemma cpow_ofReal_re (x : β„‚) (y : ℝ) : (x ^ (y : β„‚)).re = β€–xβ€– ^ y * Real.cos (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.cos] lemma cpow_ofReal_im (x : β„‚) (y : ℝ) : (x ^ (y : β„‚)).im = β€–xβ€– ^ y * Real.sin (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin] theorem norm_cpow_of_ne_zero {z : β„‚} (hz : z β‰  0) (w : β„‚) : β€–z ^ wβ€– = β€–zβ€– ^ w.re / Real.exp (arg z * im w) := by rw [cpow_def_of_ne_zero hz, norm_exp, mul_re, log_re, log_im, Real.exp_sub, Real.rpow_def_of_pos (norm_pos_iff.mpr hz)] theorem norm_cpow_of_imp {z w : β„‚} (h : z = 0 β†’ w.re = 0 β†’ w = 0) : β€–z ^ wβ€– = β€–zβ€– ^ w.re / Real.exp (arg z * im w) := by rcases ne_or_eq z 0 with (hz | rfl) <;> [exact norm_cpow_of_ne_zero hz w; rw [norm_zero]] rcases eq_or_ne w.re 0 with hw | hw Β· simp [hw, h rfl hw] Β· rw [Real.zero_rpow hw, zero_div, zero_cpow, norm_zero] exact ne_of_apply_ne re hw theorem norm_cpow_le (z w : β„‚) : β€–z ^ wβ€– ≀ β€–zβ€– ^ w.re / Real.exp (arg z * im w) := by by_cases h : z = 0 β†’ w.re = 0 β†’ w = 0 Β· exact (norm_cpow_of_imp h).le Β· push_neg at h simp [h] @[simp] theorem norm_cpow_real (x : β„‚) (y : ℝ) : β€–x ^ (y : β„‚)β€– = β€–xβ€– ^ y := by rw [norm_cpow_of_imp] <;> simp @[simp] theorem norm_cpow_inv_nat (x : β„‚) (n : β„•) : β€–x ^ (n⁻¹ : β„‚)β€– = β€–xβ€– ^ (n⁻¹ : ℝ) := by rw [← norm_cpow_real]; simp theorem norm_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : β„‚) : β€–(x : β„‚) ^ yβ€– = x ^ y.re := by rw [norm_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le, zero_mul, Real.exp_zero, div_one, Complex.norm_of_nonneg hx.le] theorem norm_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≀ x) {y : β„‚} (hy : re y β‰  0) : β€–(x : β„‚) ^ yβ€– = x ^ re y := by rw [norm_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, abs_of_nonneg] @[deprecated (since := "2025-02-17")] alias abs_cpow_of_ne_zero := norm_cpow_of_ne_zero @[deprecated (since := "2025-02-17")] alias abs_cpow_of_imp := norm_cpow_of_imp @[deprecated (since := "2025-02-17")] alias abs_cpow_le := norm_cpow_le @[deprecated (since := "2025-02-17")] alias abs_cpow_real := norm_cpow_real @[deprecated (since := "2025-02-17")] alias abs_cpow_inv_nat := norm_cpow_inv_nat @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_pos := norm_cpow_eq_rpow_re_of_pos @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_nonneg := norm_cpow_eq_rpow_re_of_nonneg open Filter in lemma norm_ofReal_cpow_eventually_eq_atTop (c : β„‚) : (fun t : ℝ ↦ β€–(t : β„‚) ^ cβ€–) =αΆ [atTop] fun t ↦ t ^ c.re := by filter_upwards [eventually_gt_atTop 0] with t ht rw [norm_cpow_eq_rpow_re_of_pos ht] lemma norm_natCast_cpow_of_re_ne_zero (n : β„•) {s : β„‚} (hs : s.re β‰  0) : β€–(n : β„‚) ^ sβ€– = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_nonneg n.cast_nonneg hs] lemma norm_natCast_cpow_of_pos {n : β„•} (hn : 0 < n) (s : β„‚) : β€–(n : β„‚) ^ sβ€– = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_pos (Nat.cast_pos.mpr hn) _] lemma norm_natCast_cpow_pos_of_pos {n : β„•} (hn : 0 < n) (s : β„‚) : 0 < β€–(n : β„‚) ^ sβ€– := (norm_natCast_cpow_of_pos hn _).symm β–Έ Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _ theorem cpow_mul_ofReal_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) (z : β„‚) : (x : β„‚) ^ (↑y * z) = (↑(x ^ y) : β„‚) ^ z := by rw [cpow_mul, ofReal_cpow hx] Β· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im, neg_lt_zero]; exact Real.pi_pos Β· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im]; exact Real.pi_pos.le end Complex /-! ### Positivity extension -/ namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: exponentiation by a real number is positive (namely 1) when the exponent is zero. The other cases are done in `evalRpow`. -/ @[positivity (_ : ℝ) ^ (0 : ℝ)] def evalRpowZero : PositivityExt where eval {u Ξ±} _ _ e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q($a ^ (0 : ℝ)) => assertInstancesCommute pure (.positive q(Real.rpow_zero_pos $a)) | _, _, _ => throwError "not Real.rpow" /-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when the base is nonnegative and positive when the base is positive. -/ @[positivity (_ : ℝ) ^ (_ : ℝ)] def evalRpow : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q($a ^ ($b : ℝ)) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(Real.rpow_pos_of_pos $pa $b)) | .nonnegative pa => pure (.nonnegative q(Real.rpow_nonneg $pa $b)) | _ => pure .none | _, _, _ => throwError "not Real.rpow" end Mathlib.Meta.Positivity /-! ## Further algebraic properties of `rpow` -/ namespace Real variable {x y z : ℝ} {n : β„•} theorem rpow_mul {x : ℝ} (hx : 0 ≀ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by rw [← Complex.ofReal_inj, Complex.ofReal_cpow (rpow_nonneg hx _), Complex.ofReal_cpow hx, Complex.ofReal_mul, Complex.cpow_mul, Complex.ofReal_cpow hx] <;> simp only [(Complex.ofReal_mul _ _).symm, (Complex.ofReal_log hx).symm, Complex.ofReal_im, neg_lt_zero, pi_pos, le_of_lt pi_pos] lemma rpow_pow_comm {x : ℝ} (hx : 0 ≀ x) (y : ℝ) (n : β„•) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_natCast, ← rpow_mul hx, mul_comm y] lemma rpow_zpow_comm {x : ℝ} (hx : 0 ≀ x) (y : ℝ) (n : β„€) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_intCast, ← rpow_mul hx, mul_comm y] lemma rpow_add_intCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„€) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_def, rpow_def, Complex.ofReal_add, Complex.cpow_add _ _ (Complex.ofReal_ne_zero.mpr hx), Complex.ofReal_intCast, Complex.cpow_intCast, ← Complex.ofReal_zpow, mul_comm, Complex.re_ofReal_mul, mul_comm] lemma rpow_add_natCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y + n) = x ^ y * x ^ n := by simpa using rpow_add_intCast hx y n lemma rpow_sub_intCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_add_intCast hx y (-n) lemma rpow_sub_natCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_sub_intCast hx y n lemma rpow_add_intCast' (hx : 0 ≀ x) {n : β„€} (h : y + n β‰  0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_intCast] lemma rpow_add_natCast' (hx : 0 ≀ x) (h : y + n β‰  0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_natCast] lemma rpow_sub_intCast' (hx : 0 ≀ x) {n : β„€} (h : y - n β‰  0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_intCast] lemma rpow_sub_natCast' (hx : 0 ≀ x) (h : y - n β‰  0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_natCast] theorem rpow_add_one {x : ℝ} (hx : x β‰  0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_natCast hx y 1 theorem rpow_sub_one {x : ℝ} (hx : x β‰  0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_natCast hx y 1 lemma rpow_add_one' (hx : 0 ≀ x) (h : y + 1 β‰  0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' hx h, rpow_one] lemma rpow_one_add' (hx : 0 ≀ x) (h : 1 + y β‰  0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' hx h, rpow_one] lemma rpow_sub_one' (hx : 0 ≀ x) (h : y - 1 β‰  0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' hx h, rpow_one] lemma rpow_one_sub' (hx : 0 ≀ x) (h : 1 - y β‰  0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' hx h, rpow_one] @[simp] theorem rpow_two (x : ℝ) : x ^ (2 : ℝ) = x ^ 2 := by rw [← rpow_natCast] simp only [Nat.cast_ofNat] theorem rpow_neg_one (x : ℝ) : x ^ (-1 : ℝ) = x⁻¹ := by suffices H : x ^ ((-1 : β„€) : ℝ) = x⁻¹ by rwa [Int.cast_neg, Int.cast_one] at H simp only [rpow_intCast, zpow_one, zpow_neg] theorem mul_rpow (hx : 0 ≀ x) (hy : 0 ≀ y) : (x * y) ^ z = x ^ z * y ^ z := by iterate 2 rw [Real.rpow_def_of_nonneg]; split_ifs with h_ifs <;> simp_all Β· rw [log_mul β€Ή_β€Ί β€Ή_β€Ί, add_mul, exp_add, rpow_def_of_pos (hy.lt_of_ne' β€Ή_β€Ί)] all_goals positivity theorem inv_rpow (hx : 0 ≀ x) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by simp only [← rpow_neg_one, ← rpow_mul hx, mul_comm] theorem div_rpow (hx : 0 ≀ x) (hy : 0 ≀ y) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := by simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy] theorem log_rpow {x : ℝ} (hx : 0 < x) (y : ℝ) : log (x ^ y) = y * log x := by apply exp_injective rw [exp_log (rpow_pos_of_pos hx y), ← exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y] theorem mul_log_eq_log_iff {x y z : ℝ} (hx : 0 < x) (hz : 0 < z) : y * log x = log z ↔ x ^ y = z := ⟨fun h ↦ log_injOn_pos (rpow_pos_of_pos hx _) hz <| log_rpow hx _ |>.trans h, by rintro rfl; rw [log_rpow hx]⟩ @[simp] lemma rpow_rpow_inv (hx : 0 ≀ x) (hy : y β‰  0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul hx, mul_inv_cancelβ‚€ hy, rpow_one] @[simp] lemma rpow_inv_rpow (hx : 0 ≀ x) (hy : y β‰  0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul hx, inv_mul_cancelβ‚€ hy, rpow_one] theorem pow_rpow_inv_natCast (hx : 0 ≀ x) (hn : n β‰  0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by have hn0 : (n : ℝ) β‰  0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, mul_inv_cancelβ‚€ hn0, rpow_one] theorem rpow_inv_natCast_pow (hx : 0 ≀ x) (hn : n β‰  0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by have hn0 : (n : ℝ) β‰  0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, inv_mul_cancelβ‚€ hn0, rpow_one] lemma rpow_natCast_mul (hx : 0 ≀ x) (n : β„•) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_natCast] lemma rpow_mul_natCast (hx : 0 ≀ x) (y : ℝ) (n : β„•) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_natCast] lemma rpow_intCast_mul (hx : 0 ≀ x) (n : β„€) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_intCast] lemma rpow_mul_intCast (hx : 0 ≀ x) (y : ℝ) (n : β„€) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_intCast] /-! Note: lemmas about `(∏ i ∈ s, f i ^ r)` such as `Real.finset_prod_rpow` are proved in `Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean` instead. -/ /-! ## Order and monotonicity -/ @[gcongr, bound] theorem rpow_lt_rpow (hx : 0 ≀ x) (hxy : x < y) (hz : 0 < z) : x ^ z < y ^ z := by rw [le_iff_eq_or_lt] at hx; rcases hx with hx | hx Β· rw [← hx, zero_rpow (ne_of_gt hz)] exact rpow_pos_of_pos (by rwa [← hx] at hxy) _ Β· rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp] exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz theorem strictMonoOn_rpow_Ici_of_exponent_pos {r : ℝ} (hr : 0 < r) : StrictMonoOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_lt_rpow ha hab hr @[gcongr, bound] theorem rpow_le_rpow {x y z : ℝ} (h : 0 ≀ x) (h₁ : x ≀ y) (hβ‚‚ : 0 ≀ z) : x ^ z ≀ y ^ z := by rcases eq_or_lt_of_le h₁ with (rfl | h₁'); Β· rfl rcases eq_or_lt_of_le hβ‚‚ with (rfl | hβ‚‚'); Β· simp exact le_of_lt (rpow_lt_rpow h h₁' hβ‚‚') theorem monotoneOn_rpow_Ici_of_exponent_nonneg {r : ℝ} (hr : 0 ≀ r) : MonotoneOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_le_rpow ha hab hr lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := by have := hx.trans hxy rw [← inv_lt_invβ‚€, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_lt_rpow ?_ hxy (neg_pos.2 hz) all_goals positivity lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≀ y) (hz : z ≀ 0) : y ^ z ≀ x ^ z := by have := hx.trans_le hxy rw [← inv_le_invβ‚€, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_le_rpow ?_ hxy (neg_nonneg.2 hz) all_goals positivity theorem rpow_lt_rpow_iff (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := ⟨lt_imp_lt_of_le_imp_le fun h => rpow_le_rpow hy h (le_of_lt hz), fun h => rpow_lt_rpow hx h hz⟩ theorem rpow_le_rpow_iff (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z ≀ y ^ z ↔ x ≀ y := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff hy hx hz lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := ⟨lt_imp_lt_of_le_imp_le fun h ↦ rpow_le_rpow_of_nonpos hx h hz.le, fun h ↦ rpow_lt_rpow_of_neg hy h hz⟩ lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≀ y ^ z ↔ y ≀ x := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff_of_neg hy hx hz lemma le_rpow_inv_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := by rw [← rpow_le_rpow_iff hx _ hz, rpow_inv_rpow] <;> positivity lemma rpow_inv_le_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := by rw [← rpow_le_rpow_iff _ hy hz, rpow_inv_rpow] <;> positivity lemma lt_rpow_inv_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := lt_iff_lt_of_le_iff_le <| rpow_inv_le_iff_of_pos hy hx hz lemma rpow_inv_lt_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := lt_iff_lt_of_le_iff_le <| le_rpow_inv_iff_of_pos hy hx hz theorem le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≀ y ^ z⁻¹ ↔ y ≀ x ^ z := by rw [← rpow_le_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := by rw [← rpow_lt_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := by rw [← rpow_lt_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≀ y ↔ y ^ z ≀ x := by rw [← rpow_le_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos (lt_trans zero_lt_one hx)] rw [exp_lt_exp]; exact mul_lt_mul_of_pos_left hyz (log_pos hx) @[gcongr] theorem rpow_le_rpow_of_exponent_le (hx : 1 ≀ x) (hyz : y ≀ z) : x ^ y ≀ x ^ z := by repeat' rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)] rw [exp_le_exp]; exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx) theorem rpow_lt_rpow_of_exponent_neg {x y z : ℝ} (hy : 0 < y) (hxy : y < x) (hz : z < 0) : x ^ z < y ^ z := by have hx : 0 < x := hy.trans hxy rw [← neg_neg z, Real.rpow_neg (le_of_lt hx) (-z), Real.rpow_neg (le_of_lt hy) (-z), inv_lt_invβ‚€ (rpow_pos_of_pos hx _) (rpow_pos_of_pos hy _)] exact Real.rpow_lt_rpow (by positivity) hxy <| neg_pos_of_neg hz theorem strictAntiOn_rpow_Ioi_of_exponent_neg {r : ℝ} (hr : r < 0) : StrictAntiOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_lt_rpow_of_exponent_neg ha hab hr theorem rpow_le_rpow_of_exponent_nonpos {x y : ℝ} (hy : 0 < y) (hxy : y ≀ x) (hz : z ≀ 0) : x ^ z ≀ y ^ z := by rcases ne_or_eq z 0 with hz_zero | rfl case inl => rcases ne_or_eq x y with hxy' | rfl case inl => exact le_of_lt <| rpow_lt_rpow_of_exponent_neg hy (Ne.lt_of_le (id (Ne.symm hxy')) hxy) (Ne.lt_of_le hz_zero hz) case inr => simp case inr => simp theorem antitoneOn_rpow_Ioi_of_exponent_nonpos {r : ℝ} (hr : r ≀ 0) : AntitoneOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_le_rpow_of_exponent_nonpos ha hab hr @[simp] theorem rpow_le_rpow_left_iff (hx : 1 < x) : x ^ y ≀ x ^ z ↔ y ≀ z := by have x_pos : 0 < x := lt_trans zero_lt_one hx rw [← log_le_log_iff (rpow_pos_of_pos x_pos y) (rpow_pos_of_pos x_pos z), log_rpow x_pos, log_rpow x_pos, mul_le_mul_right (log_pos hx)] @[simp] theorem rpow_lt_rpow_left_iff (hx : 1 < x) : x ^ y < x ^ z ↔ y < z := by rw [lt_iff_not_le, rpow_le_rpow_left_iff hx, lt_iff_not_le] theorem rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_lt_exp]; exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1)
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
636
641
theorem rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≀ 1) (hyz : z ≀ y) : x ^ y ≀ x ^ z := by
repeat' rw [rpow_def_of_pos hx0] rw [exp_le_exp]; exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1) @[simp] theorem rpow_le_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) :
/- Copyright (c) 2023 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Prod import Mathlib.Tactic.Common /-! # Lemmas about the divisibility relation in product (semi)groups -/ variable {ΞΉ G₁ Gβ‚‚ : Type*} {G : ΞΉ β†’ Type*} [Semigroup G₁] [Semigroup Gβ‚‚] [βˆ€ i, Semigroup (G i)]
Mathlib/Algebra/Divisibility/Prod.lean
16
20
theorem prod_dvd_iff {x y : G₁ Γ— Gβ‚‚} : x ∣ y ↔ x.1 ∣ y.1 ∧ x.2 ∣ y.2 := by
cases x; cases y simp only [dvd_def, Prod.exists, Prod.mk_mul_mk, Prod.mk.injEq, exists_and_left, exists_and_right, and_self, true_and]
/- Copyright (c) 2024 Ira Fesefeldt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ira Fesefeldt -/ import Mathlib.SetTheory.Ordinal.Arithmetic /-! # Ordinal Approximants for the Fixed points on complete lattices This file sets up the ordinal-indexed approximation theory of fixed points of a monotone function in a complete lattice [Cousot1979]. The proof follows loosely the one from [Echenique2005]. However, the proof given here is not constructive as we use the non-constructive axiomatization of ordinals from mathlib. It still allows an approximation scheme indexed over the ordinals. ## Main definitions * `OrdinalApprox.lfpApprox`: The ordinal-indexed approximation of the least fixed point greater or equal than an initial value of a bundled monotone function. * `OrdinalApprox.gfpApprox`: The ordinal-indexed approximation of the greatest fixed point less or equal than an initial value of a bundled monotone function. ## Main theorems * `OrdinalApprox.lfp_mem_range_lfpApprox`: The ordinal-indexed approximation of the least fixed point eventually reaches the least fixed point * `OrdinalApprox.gfp_mem_range_gfpApprox`: The ordinal-indexed approximation of the greatest fixed point eventually reaches the greatest fixed point ## References * [F. Echenique, *A short and constructive proof of Tarski’s fixed-point theorem*][Echenique2005] * [P. Cousot & R. Cousot, *Constructive Versions of Tarski's Fixed Point Theorems*][Cousot1979] ## Tags fixed point, complete lattice, monotone function, ordinals, approximation -/ namespace Cardinal universe u variable {Ξ± : Type u} variable (g : Ordinal β†’ Ξ±) open Cardinal Ordinal SuccOrder Function Set theorem not_injective_limitation_set : Β¬ InjOn g (Iio (ord <| succ #Ξ±)) := by intro h_inj have h := lift_mk_le_lift_mk_of_injective <| injOn_iff_injective.1 h_inj have mk_initialSeg_subtype : #(Iio (ord <| succ #Ξ±)) = lift.{u + 1} (succ #Ξ±) := by simpa only [coe_setOf, card_typein, card_ord] using mk_Iio_ordinal (ord <| succ #Ξ±) rw [mk_initialSeg_subtype, lift_lift, lift_le] at h exact not_le_of_lt (Order.lt_succ #Ξ±) h end Cardinal namespace OrdinalApprox universe u variable {Ξ± : Type u} variable [CompleteLattice Ξ±] (f : Ξ± β†’o Ξ±) (x : Ξ±) open Function fixedPoints Cardinal Order OrderHom set_option linter.unusedVariables false in /-- The ordinal-indexed sequence approximating the least fixed point greater than an initial value `x`. It is defined in such a way that we have `lfpApprox 0 x = x` and `lfpApprox a x = ⨆ b < a, f (lfpApprox b x)`. -/ def lfpApprox (a : Ordinal.{u}) : Ξ± := sSup ({ f (lfpApprox b) | (b : Ordinal) (h : b < a) } βˆͺ {x}) termination_by a decreasing_by exact h theorem lfpApprox_monotone : Monotone (lfpApprox f x) := by intros a b h rw [lfpApprox, lfpApprox] refine sSup_le_sSup ?h apply sup_le_sup_right simp only [exists_prop, Set.le_eq_subset, Set.setOf_subset_setOf, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚] intros a' h' use a' exact ⟨lt_of_lt_of_le h' h, rfl⟩ theorem le_lfpApprox {a : Ordinal} : x ≀ lfpApprox f x a := by rw [lfpApprox] apply le_sSup simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, true_or] theorem lfpApprox_add_one (h : x ≀ f x) (a : Ordinal) : lfpApprox f x (a+1) = f (lfpApprox f x a) := by apply le_antisymm Β· conv => left; rw [lfpApprox] apply sSup_le simp only [Ordinal.add_one_eq_succ, lt_succ_iff, exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚] apply And.intro Β· apply le_trans h apply Monotone.imp f.monotone exact le_lfpApprox f x Β· intros a' h apply f.2; apply lfpApprox_monotone; exact h Β· conv => right; rw [lfpApprox] apply le_sSup simp only [Ordinal.add_one_eq_succ, lt_succ_iff, exists_prop] rw [Set.mem_union] apply Or.inl simp only [Set.mem_setOf_eq] use a theorem lfpApprox_mono_left : Monotone (lfpApprox : (Ξ± β†’o Ξ±) β†’ _) := by intro f g h x a induction a using Ordinal.induction with | h i ih => rw [lfpApprox, lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, sSup_insert, forall_eq_or_imp, le_sup_left, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚, true_and] intro i' h_lt apply le_sup_of_le_right apply le_sSup_of_le Β· use i' Β· apply le_trans (h _) simp only [OrderHom.toFun_eq_coe] exact g.monotone (ih i' h_lt) theorem lfpApprox_mono_mid : Monotone (lfpApprox f) := by intro x₁ xβ‚‚ h a induction a using Ordinal.induction with | h i ih => rw [lfpApprox, lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, sSup_insert, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚] constructor Β· exact le_sup_of_le_left h Β· intro i' h_i' apply le_sup_of_le_right apply le_sSup_of_le Β· use i' Β· exact f.monotone (ih i' h_i') /-- The approximations of the least fixed point stabilize at a fixed point of `f` -/ theorem lfpApprox_eq_of_mem_fixedPoints {a b : Ordinal} (h_init : x ≀ f x) (h_ab : a ≀ b) (h : lfpApprox f x a ∈ fixedPoints f) : lfpApprox f x b = lfpApprox f x a := by rw [mem_fixedPoints_iff] at h induction b using Ordinal.induction with | h b IH => apply le_antisymm Β· conv => left; rw [lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚] apply And.intro (le_lfpApprox f x) intro a' ha'b by_cases haa : a' < a Β· rw [← lfpApprox_add_one f x h_init] apply lfpApprox_monotone simp only [Ordinal.add_one_eq_succ, succ_le_iff] exact haa Β· rw [IH a' ha'b (le_of_not_lt haa), h] Β· exact lfpApprox_monotone f x h_ab /-- There are distinct indices smaller than the successor of the domain's cardinality yielding the same value -/ theorem exists_lfpApprox_eq_lfpApprox : βˆƒ a < ord <| succ #Ξ±, βˆƒ b < ord <| succ #Ξ±, a β‰  b ∧ lfpApprox f x a = lfpApprox f x b := by have h_ninj := not_injective_limitation_set <| lfpApprox f x rw [Set.injOn_iff_injective, Function.not_injective_iff] at h_ninj let ⟨a, b, h_fab, h_nab⟩ := h_ninj use a.val; apply And.intro a.prop use b.val; apply And.intro b.prop apply And.intro Β· intro h_eq; rw [Subtype.coe_inj] at h_eq; exact h_nab h_eq Β· exact h_fab /-- If the sequence of ordinal-indexed approximations takes a value twice, then it actually stabilised at that value. -/ lemma lfpApprox_mem_fixedPoints_of_eq {a b c : Ordinal} (h_init : x ≀ f x) (h_ab : a < b) (h_ac : a ≀ c) (h_fab : lfpApprox f x a = lfpApprox f x b) : lfpApprox f x c ∈ fixedPoints f := by have lfpApprox_mem_fixedPoint : lfpApprox f x a ∈ fixedPoints f := by rw [mem_fixedPoints_iff, ← lfpApprox_add_one f x h_init] exact Monotone.eq_of_le_of_le (lfpApprox_monotone f x) h_fab (SuccOrder.le_succ a) (SuccOrder.succ_le_of_lt h_ab) rw [lfpApprox_eq_of_mem_fixedPoints f x h_init] Β· exact lfpApprox_mem_fixedPoint Β· exact h_ac Β· exact lfpApprox_mem_fixedPoint /-- The approximation at the index of the successor of the domain's cardinality is a fixed point -/ theorem lfpApprox_ord_mem_fixedPoint (h_init : x ≀ f x) : lfpApprox f x (ord <| succ #Ξ±) ∈ fixedPoints f := by let ⟨a, h_a, b, h_b, h_nab, h_fab⟩ := exists_lfpApprox_eq_lfpApprox f x cases le_total a b with | inl h_ab => exact lfpApprox_mem_fixedPoints_of_eq f x h_init (h_nab.lt_of_le h_ab) (le_of_lt h_a) h_fab | inr h_ba => exact lfpApprox_mem_fixedPoints_of_eq f x h_init (h_nab.symm.lt_of_le h_ba) (le_of_lt h_b) (h_fab.symm) /-- Every value of the approximation is less or equal than every fixed point of `f` greater or equal than the initial value -/
Mathlib/SetTheory/Ordinal/FixedPointApproximants.lean
209
211
theorem lfpApprox_le_of_mem_fixedPoints {a : Ξ±} (h_a : a ∈ fixedPoints f) (h_le_init : x ≀ a) (i : Ordinal) : lfpApprox f x i ≀ a := by
induction i using Ordinal.induction with
/- 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
Mathlib/Data/Complex/Basic.lean
261
261
theorem I_mul_re (z : β„‚) : (I * z).re = -z.im := by
simp
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
6