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