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) 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.Logic.Basic
import Mathlib.Tactic.Positivity.Basic
/-!
# Algebraic order homomorphism classes
This file defines hom classes for common properties at the intersection of order theory and algebra.
## Typeclasses
Basic typeclasses
* `NonnegHomClass`: Homs are nonnegative: `∀ f a, 0 ≤ f a`
* `SubadditiveHomClass`: Homs are subadditive: `∀ f a b, f (a + b) ≤ f a + f b`
* `SubmultiplicativeHomClass`: Homs are submultiplicative: `∀ f a b, f (a * b) ≤ f a * f b`
* `MulLEAddHomClass`: `∀ f a b, f (a * b) ≤ f a + f b`
* `NonarchimedeanHomClass`: `∀ a b, f (a + b) ≤ max (f a) (f b)`
Group norms
* `AddGroupSeminormClass`: Homs are nonnegative, subadditive, even and preserve zero.
* `GroupSeminormClass`: Homs are nonnegative, respect `f (a * b) ≤ f a + f b`, `f a⁻¹ = f a` and
preserve zero.
* `AddGroupNormClass`: Homs are seminorms such that `f x = 0 → x = 0` for all `x`.
* `GroupNormClass`: Homs are seminorms such that `f x = 0 → x = 1` for all `x`.
Ring norms
* `RingSeminormClass`: Homs are submultiplicative group norms.
* `RingNormClass`: Homs are ring seminorms that are also additive group norms.
* `MulRingSeminormClass`: Homs are ring seminorms that are multiplicative.
* `MulRingNormClass`: Homs are ring norms that are multiplicative.
## Notes
Typeclasses for seminorms are defined here while types of seminorms are defined in
`Analysis.Normed.Group.Seminorm` and `Analysis.Normed.Ring.Seminorm` because absolute values are
multiplicative ring norms but outside of this use we only consider real-valued seminorms.
## TODO
Finitary versions of the current lemmas.
-/
library_note "out-param inheritance"/--
Diamond inheritance cannot depend on `outParam`s in the following circumstances:
* there are three classes `Top`, `Middle`, `Bottom`
* all of these classes have a parameter `(α : outParam _)`
* all of these classes have an instance parameter `[Root α]` that depends on this `outParam`
* the `Root` class has two child classes: `Left` and `Right`, these are siblings in the hierarchy
* the instance `Bottom.toMiddle` takes a `[Left α]` parameter
* the instance `Middle.toTop` takes a `[Right α]` parameter
* there is a `Leaf` class that inherits from both `Left` and `Right`.
In that case, given instances `Bottom α` and `Leaf α`, Lean cannot synthesize a `Top α` instance,
even though the hypotheses of the instances `Bottom.toMiddle` and `Middle.toTop` are satisfied.
There are two workarounds:
* You could replace the bundled inheritance implemented by the instance `Middle.toTop` with
unbundled inheritance implemented by adding a `[Top α]` parameter to the `Middle` class. This is
the preferred option since it is also more compatible with Lean 4, at the cost of being more work
to implement and more verbose to use.
* You could weaken the `Bottom.toMiddle` instance by making it depend on a subclass of
`Middle.toTop`'s parameter, in this example replacing `[Left α]` with `[Leaf α]`.
-/
open Function
variable {ι F α β γ δ : Type*}
/-! ### Basics -/
/-- `NonnegHomClass F α β` states that `F` is a type of nonnegative morphisms. -/
class NonnegHomClass (F : Type*) (α β : outParam Type*) [Zero β] [LE β] [FunLike F α β] : Prop where
/-- the image of any element is non negative. -/
apply_nonneg (f : F) : ∀ a, 0 ≤ f a
/-- `SubadditiveHomClass F α β` states that `F` is a type of subadditive morphisms. -/
class SubadditiveHomClass (F : Type*) (α β : outParam Type*)
[Add α] [Add β] [LE β] [FunLike F α β] : Prop where
/-- the image of a sum is less or equal than the sum of the images. -/
map_add_le_add (f : F) : ∀ a b, f (a + b) ≤ f a + f b
/-- `SubmultiplicativeHomClass F α β` states that `F` is a type of submultiplicative morphisms. -/
@[to_additive SubadditiveHomClass]
class SubmultiplicativeHomClass (F : Type*) (α β : outParam (Type*)) [Mul α] [Mul β] [LE β]
[FunLike F α β] : Prop where
/-- the image of a product is less or equal than the product of the images. -/
map_mul_le_mul (f : F) : ∀ a b, f (a * b) ≤ f a * f b
/-- `MulLEAddHomClass F α β` states that `F` is a type of subadditive morphisms. -/
@[to_additive SubadditiveHomClass]
class MulLEAddHomClass (F : Type*) (α β : outParam Type*) [Mul α] [Add β] [LE β] [FunLike F α β] :
Prop where
/-- the image of a product is less or equal than the sum of the images. -/
map_mul_le_add (f : F) : ∀ a b, f (a * b) ≤ f a + f b
/-- `NonarchimedeanHomClass F α β` states that `F` is a type of non-archimedean morphisms. -/
class NonarchimedeanHomClass (F : Type*) (α β : outParam Type*)
[Add α] [LinearOrder β] [FunLike F α β] : Prop where
/-- the image of a sum is less or equal than the maximum of the images. -/
map_add_le_max (f : F) : ∀ a b, f (a + b) ≤ max (f a) (f b)
export NonnegHomClass (apply_nonneg)
export SubadditiveHomClass (map_add_le_add)
export SubmultiplicativeHomClass (map_mul_le_mul)
export MulLEAddHomClass (map_mul_le_add)
export NonarchimedeanHomClass (map_add_le_max)
attribute [simp] apply_nonneg
variable [FunLike F α β]
@[to_additive]
theorem le_map_mul_map_div [Group α] [CommMagma β] [LE β] [SubmultiplicativeHomClass F α β]
(f : F) (a b : α) : f a ≤ f b * f (a / b) := by
simpa only [mul_comm, div_mul_cancel] using map_mul_le_mul f (a / b) b
@[to_additive existing]
theorem le_map_add_map_div [Group α] [AddCommMagma β] [LE β] [MulLEAddHomClass F α β] (f : F)
(a b : α) : f a ≤ f b + f (a / b) := by
simpa only [add_comm, div_mul_cancel] using map_mul_le_add f (a / b) b
@[to_additive]
theorem le_map_div_mul_map_div [Group α] [Mul β] [LE β] [SubmultiplicativeHomClass F α β]
(f : F) (a b c : α) : f (a / c) ≤ f (a / b) * f (b / c) := by
simpa only [div_mul_div_cancel] using map_mul_le_mul f (a / b) (b / c)
@[to_additive existing]
theorem le_map_div_add_map_div [Group α] [Add β] [LE β] [MulLEAddHomClass F α β]
(f : F) (a b c : α) : f (a / c) ≤ f (a / b) + f (b / c) := by
simpa only [div_mul_div_cancel] using map_mul_le_add f (a / b) (b / c)
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
/-- Extension for the `positivity` tactic: nonnegative maps take nonnegative values. -/
@[positivity DFunLike.coe _ _]
def evalMap : PositivityExt where eval {_ β} _ _ e := do
let .app (.app _ f) a ← whnfR e
| throwError "not ↑f · where f is of NonnegHomClass"
let pa ← mkAppOptM ``apply_nonneg #[none, none, β, none, none, none, none, f, a]
pure (.nonnegative pa)
end Mathlib.Meta.Positivity
/-! ### Group (semi)norms -/
/-- `AddGroupSeminormClass F α` states that `F` is a type of `β`-valued seminorms on the additive
group `α`.
You should extend this class when you extend `AddGroupSeminorm`. -/
class AddGroupSeminormClass (F : Type*) (α β : outParam Type*)
[AddGroup α] [AddCommMonoid β] [PartialOrder β] [FunLike F α β] : Prop
extends SubadditiveHomClass F α β where
/-- The image of zero is zero. -/
map_zero (f : F) : f 0 = 0
/-- The map is invariant under negation of its argument. -/
map_neg_eq_map (f : F) (a : α) : f (-a) = f a
/-- `GroupSeminormClass F α` states that `F` is a type of `β`-valued seminorms on the group `α`.
You should extend this class when you extend `GroupSeminorm`. -/
@[to_additive]
class GroupSeminormClass (F : Type*) (α β : outParam Type*)
[Group α] [AddCommMonoid β] [PartialOrder β] [FunLike F α β] : Prop
extends MulLEAddHomClass F α β where
/-- The image of one is zero. -/
map_one_eq_zero (f : F) : f 1 = 0
/-- The map is invariant under inversion of its argument. -/
map_inv_eq_map (f : F) (a : α) : f a⁻¹ = f a
/-- `AddGroupNormClass F α` states that `F` is a type of `β`-valued norms on the additive group
`α`.
You should extend this class when you extend `AddGroupNorm`. -/
class AddGroupNormClass (F : Type*) (α β : outParam Type*)
[AddGroup α] [AddCommMonoid β] [PartialOrder β] [FunLike F α β] : Prop
extends AddGroupSeminormClass F α β where
/-- The argument is zero if its image under the map is zero. -/
eq_zero_of_map_eq_zero (f : F) {a : α} : f a = 0 → a = 0
/-- `GroupNormClass F α` states that `F` is a type of `β`-valued norms on the group `α`.
You should extend this class when you extend `GroupNorm`. -/
@[to_additive]
class GroupNormClass (F : Type*) (α β : outParam Type*)
[Group α] [AddCommMonoid β] [PartialOrder β] [FunLike F α β] : Prop
extends GroupSeminormClass F α β where
/-- The argument is one if its image under the map is zero. -/
eq_one_of_map_eq_zero (f : F) {a : α} : f a = 0 → a = 1
export AddGroupSeminormClass (map_neg_eq_map)
export GroupSeminormClass (map_one_eq_zero map_inv_eq_map)
export AddGroupNormClass (eq_zero_of_map_eq_zero)
export GroupNormClass (eq_one_of_map_eq_zero)
attribute [simp] map_one_eq_zero
attribute [simp] map_neg_eq_map
attribute [simp] map_inv_eq_map
attribute [to_additive] GroupSeminormClass.toMulLEAddHomClass
-- See note [lower instance priority]
instance (priority := 100) AddGroupSeminormClass.toZeroHomClass [AddGroup α]
[AddCommMonoid β] [PartialOrder β] [AddGroupSeminormClass F α β] : ZeroHomClass F α β :=
{ ‹AddGroupSeminormClass F α β› with }
section GroupSeminormClass
variable [Group α] [AddCommMonoid β] [PartialOrder β] [GroupSeminormClass F α β] (f : F) (x y : α)
@[to_additive]
theorem map_div_le_add : f (x / y) ≤ f x + f y := by
rw [div_eq_mul_inv, ← map_inv_eq_map f y]
exact map_mul_le_add _ _ _
@[to_additive]
theorem map_div_rev : f (x / y) = f (y / x) := by rw [← inv_div, map_inv_eq_map]
@[to_additive]
theorem le_map_add_map_div' : f x ≤ f y + f (y / x) := by
simpa only [add_comm, map_div_rev, div_mul_cancel] using map_mul_le_add f (x / y) y
end GroupSeminormClass
@[to_additive]
| Mathlib/Algebra/Order/Hom/Basic.lean | 241 | 243 | theorem abs_sub_map_le_div [Group α] [AddCommGroup β] [LinearOrder β] [IsOrderedAddMonoid β]
[GroupSeminormClass F α β]
(f : F) (x y : α) : |f x - f y| ≤ f (x / y) := by | |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Analysis.Convex.Side
import Mathlib.Geometry.Euclidean.Angle.Oriented.Rotation
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine
/-!
# Oriented angles.
This file defines oriented angles in Euclidean affine spaces.
## Main definitions
* `EuclideanGeometry.oangle`, with notation `∡`, is the oriented angle determined by three
points.
-/
noncomputable section
open Module Complex
open scoped Affine EuclideanGeometry Real RealInnerProductSpace ComplexConjugate
namespace EuclideanGeometry
variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)]
/-- A fixed choice of positive orientation of Euclidean space `ℝ²` -/
abbrev o := @Module.Oriented.positiveOrientation
/-- The oriented angle at `p₂` between the line segments to `p₁` and `p₃`, modulo `2 * π`. If
either of those points equals `p₂`, this is 0. See `EuclideanGeometry.angle` for the
corresponding unoriented angle definition. -/
def oangle (p₁ p₂ p₃ : P) : Real.Angle :=
o.oangle (p₁ -ᵥ p₂) (p₃ -ᵥ p₂)
@[inherit_doc] scoped notation "∡" => EuclideanGeometry.oangle
/-- Oriented angles are continuous when neither end point equals the middle point. -/
theorem continuousAt_oangle {x : P × P × P} (hx12 : x.1 ≠ x.2.1) (hx32 : x.2.2 ≠ x.2.1) :
ContinuousAt (fun y : P × P × P => ∡ y.1 y.2.1 y.2.2) x := by
unfold oangle
fun_prop (disch := simp [*])
/-- The angle ∡AAB at a point. -/
@[simp]
theorem oangle_self_left (p₁ p₂ : P) : ∡ p₁ p₁ p₂ = 0 := by simp [oangle]
/-- The angle ∡ABB at a point. -/
@[simp]
theorem oangle_self_right (p₁ p₂ : P) : ∡ p₁ p₂ p₂ = 0 := by simp [oangle]
/-- The angle ∡ABA at a point. -/
@[simp]
theorem oangle_self_left_right (p₁ p₂ : P) : ∡ p₁ p₂ p₁ = 0 :=
o.oangle_self _
/-- If the angle between three points is nonzero, the first two points are not equal. -/
| Mathlib/Geometry/Euclidean/Angle/Oriented/Affine.lean | 65 | 65 | theorem left_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₂ := by | |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.TwoDim
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic
/-!
# Oriented angles.
This file defines oriented angles in real inner product spaces.
## Main definitions
* `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation.
## Implementation notes
The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes,
angles modulo `π` are more convenient, because results are true for such angles with less
configuration dependence. Results that are only equalities modulo `π` can be represented
modulo `2 * π` as equalities of `(2 : ℤ) • θ`.
## References
* Evan Chen, Euclidean Geometry in Mathematical Olympiads.
-/
noncomputable section
open Module Complex
open scoped Real RealInnerProductSpace ComplexConjugate
namespace Orientation
attribute [local instance] Complex.finrank_real_complex_fact
variable {V V' : Type*}
variable [NormedAddCommGroup V] [NormedAddCommGroup V']
variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V']
variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2))
local notation "ω" => o.areaForm
/-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0.
See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/
def oangle (x y : V) : Real.Angle :=
Complex.arg (o.kahler x y)
/-- Oriented angles are continuous when the vectors involved are nonzero. -/
@[fun_prop]
theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) :
ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by
refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_
· exact o.kahler_ne_zero hx1 hx2
exact ((continuous_ofReal.comp continuous_inner).add
((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt
/-- If the first vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle]
/-- If the second vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle]
/-- If the two vectors passed to `oangle` are the same, the result is 0. -/
@[simp]
theorem oangle_self (x : V) : o.oangle x x = 0 := by
rw [oangle, kahler_apply_self, ← ofReal_pow]
convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π))
apply arg_ofReal_of_nonneg
positivity
/-- If the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by
rintro rfl; simp at h
/-- If the angle between two vectors is `π`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y :=
o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y :=
o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y :=
o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- Swapping the two vectors passed to `oangle` negates the angle. -/
theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by
simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle]
/-- Adding the angles between two vectors in each order results in 0. -/
@[simp]
theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by
simp [o.oangle_rev y x]
/-- Negating the first vector passed to `oangle` adds `π` to the angle. -/
theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle (-x) y = o.oangle x y + π := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the second vector passed to `oangle` adds `π` to the angle. -/
theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle x (-y) = o.oangle x y + π := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the first vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_left (x y : V) :
(2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by
by_cases hx : x = 0
· simp [hx]
· by_cases hy : y = 0
· simp [hy]
· simp [o.oangle_neg_left hx hy]
/-- Negating the second vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_right (x y : V) :
(2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by
by_cases hx : x = 0
· simp [hx]
· by_cases hy : y = 0
· simp [hy]
· simp [o.oangle_neg_right hx hy]
/-- Negating both vectors passed to `oangle` does not change the angle. -/
@[simp]
theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle]
/-- Negating the first vector produces the same angle as negating the second vector. -/
theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by
rw [← neg_neg y, oangle_neg_neg, neg_neg]
/-- The angle between the negation of a nonzero vector and that vector is `π`. -/
@[simp]
theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by
simp [oangle_neg_left, hx]
/-- The angle between a nonzero vector and its negation is `π`. -/
@[simp]
theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by
simp [oangle_neg_right, hx]
/-- Twice the angle between the negation of a vector and that vector is 0. -/
theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Twice the angle between a vector and its negation is 0. -/
theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Adding the angles between two vectors in each order, with the first vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by
rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel]
/-- Adding the angles between two vectors in each order, with the second vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by
rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_cancel]
/-- Multiplying the first vector passed to `oangle` by a positive real does not change the
angle. -/
@[simp]
theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) :
o.oangle (r • x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr]
/-- Multiplying the second vector passed to `oangle` by a positive real does not change the
angle. -/
@[simp]
theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) :
o.oangle x (r • y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr]
/-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle
as negating that vector. -/
@[simp]
theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) :
o.oangle (r • x) y = o.oangle (-x) y := by
rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)]
/-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle
as negating that vector. -/
@[simp]
theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) :
o.oangle x (r • y) = o.oangle x (-y) := by
rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)]
/-- The angle between a nonnegative multiple of a vector and that vector is 0. -/
@[simp]
theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle (r • x) x = 0 := by
rcases hr.lt_or_eq with (h | h)
· simp [h]
· simp [h.symm]
/-- The angle between a vector and a nonnegative multiple of that vector is 0. -/
@[simp]
theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle x (r • x) = 0 := by
rcases hr.lt_or_eq with (h | h)
· simp [h]
· simp [h.symm]
/-- The angle between two nonnegative multiples of the same vector is 0. -/
@[simp]
theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ r₂ : ℝ} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) :
o.oangle (r₁ • x) (r₂ • x) = 0 := by
rcases hr₁.lt_or_eq with (h | h)
· simp [h, hr₂]
· simp [h.symm]
/-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the
angle. -/
@[simp]
theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) :
(2 : ℤ) • o.oangle (r • x) y = (2 : ℤ) • o.oangle x y := by
rcases hr.lt_or_lt with (h | h) <;> simp [h]
/-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the
angle. -/
@[simp]
theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) :
(2 : ℤ) • o.oangle x (r • y) = (2 : ℤ) • o.oangle x y := by
rcases hr.lt_or_lt with (h | h) <;> simp [h]
/-- Twice the angle between a multiple of a vector and that vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_left_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle (r • x) x = 0 := by
rcases lt_or_le r 0 with (h | h) <;> simp [h]
/-- Twice the angle between a vector and a multiple of that vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_right_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle x (r • x) = 0 := by
rcases lt_or_le r 0 with (h | h) <;> simp [h]
/-- Twice the angle between two multiples of a vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_smul_self (x : V) {r₁ r₂ : ℝ} :
(2 : ℤ) • o.oangle (r₁ • x) (r₂ • x) = 0 := by by_cases h : r₁ = 0 <;> simp [h]
/-- If the spans of two vectors are equal, twice angles with those vectors on the left are
equal. -/
theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (ℝ ∙ x) = ℝ ∙ y) :
(2 : ℤ) • o.oangle x z = (2 : ℤ) • o.oangle y z := by
rw [Submodule.span_singleton_eq_span_singleton] at h
rcases h with ⟨r, rfl⟩
exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm
/-- If the spans of two vectors are equal, twice angles with those vectors on the right are
equal. -/
theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (ℝ ∙ y) = ℝ ∙ z) :
(2 : ℤ) • o.oangle x y = (2 : ℤ) • o.oangle x z := by
rw [Submodule.span_singleton_eq_span_singleton] at h
rcases h with ⟨r, rfl⟩
exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm
/-- If the spans of two pairs of vectors are equal, twice angles between those vectors are
equal. -/
theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (ℝ ∙ w) = ℝ ∙ x)
(hyz : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle w y = (2 : ℤ) • o.oangle x z := by
rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz]
/-- The oriented angle between two vectors is zero if and only if the angle with the vectors
swapped is zero. -/
theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 ↔ o.oangle y x = 0 := by
rw [oangle_rev, neg_eq_zero]
/-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/
theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 ↔ SameRay ℝ x y := by
rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero,
Complex.arg_eq_zero_iff]
simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y
/-- The oriented angle between two vectors is `π` if and only if the angle with the vectors
swapped is `π`. -/
theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = π ↔ o.oangle y x = π := by
rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi]
/-- The oriented angle between two vectors is `π` if and only they are nonzero and the first is
on the same ray as the negation of the second. -/
theorem oangle_eq_pi_iff_sameRay_neg {x y : V} :
o.oangle x y = π ↔ x ≠ 0 ∧ y ≠ 0 ∧ SameRay ℝ x (-y) := by
rw [← o.oangle_eq_zero_iff_sameRay]
constructor
· intro h
by_cases hx : x = 0; · simp [hx, Real.Angle.pi_ne_zero.symm] at h
by_cases hy : y = 0; · simp [hy, Real.Angle.pi_ne_zero.symm] at h
refine ⟨hx, hy, ?_⟩
rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi]
· rintro ⟨hx, hy, h⟩
rwa [o.oangle_neg_right hx hy, ← Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h
/-- The oriented angle between two vectors is zero or `π` if and only if those two vectors are
not linearly independent. -/
theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} :
o.oangle x y = 0 ∨ o.oangle x y = π ↔ ¬LinearIndependent ℝ ![x, y] := by
rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg,
sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent]
/-- The oriented angle between two vectors is zero or `π` if and only if the first vector is zero
or the second is a multiple of the first. -/
theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} :
o.oangle x y = 0 ∨ o.oangle x y = π ↔ x = 0 ∨ ∃ r : ℝ, y = r • x := by
rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg]
refine ⟨fun h => ?_, fun h => ?_⟩
· rcases h with (h | ⟨-, -, h⟩)
· by_cases hx : x = 0; · simp [hx]
obtain ⟨r, -, rfl⟩ := h.exists_nonneg_left hx
exact Or.inr ⟨r, rfl⟩
· by_cases hx : x = 0; · simp [hx]
obtain ⟨r, -, hy⟩ := h.exists_nonneg_left hx
refine Or.inr ⟨-r, ?_⟩
simp [hy]
· rcases h with (rfl | ⟨r, rfl⟩); · simp
by_cases hx : x = 0; · simp [hx]
rcases lt_trichotomy r 0 with (hr | hr | hr)
· rw [← neg_smul]
exact Or.inr ⟨hx, smul_ne_zero hr.ne hx,
SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)⟩
· simp [hr]
· exact Or.inl (SameRay.sameRay_pos_smul_right x hr)
/-- The oriented angle between two vectors is not zero or `π` if and only if those two vectors
are linearly independent. -/
theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} :
o.oangle x y ≠ 0 ∧ o.oangle x y ≠ π ↔ LinearIndependent ℝ ![x, y] := by
rw [← not_or, ← not_iff_not, Classical.not_not,
oangle_eq_zero_or_eq_pi_iff_not_linearIndependent]
/-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/
theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y ↔ ‖x‖ = ‖y‖ ∧ o.oangle x y = 0 := by
rw [oangle_eq_zero_iff_sameRay]
constructor
· rintro rfl
simp; rfl
· rcases eq_or_ne y 0 with (rfl | hy)
· simp
rintro ⟨h₁, h₂⟩
obtain ⟨r, hr, rfl⟩ := h₂.exists_nonneg_right hy
have : ‖y‖ ≠ 0 := by simpa using hy
obtain rfl : r = 1 := by
apply mul_right_cancel₀ this
simpa [norm_smul, abs_of_nonneg hr] using h₁
simp
/-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/
theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : x = y ↔ o.oangle x y = 0 :=
⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha =>
(o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨h, ha⟩⟩
/-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/
theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y ↔ ‖x‖ = ‖y‖ :=
⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn =>
(o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨hn, h⟩⟩
/-- Given three nonzero vectors, the angle between the first and the second plus the angle
between the second and the third equals the angle between the first and the third. -/
@[simp]
theorem oangle_add {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle x y + o.oangle y z = o.oangle x z := by
simp_rw [oangle]
rw [← Complex.arg_mul_coe_angle, o.kahler_mul y x z]
· congr 1
exact mod_cast Complex.arg_real_mul _ (by positivity : 0 < ‖y‖ ^ 2)
· exact o.kahler_ne_zero hx hy
· exact o.kahler_ne_zero hy hz
/-- Given three nonzero vectors, the angle between the second and the third plus the angle
between the first and the second equals the angle between the first and the third. -/
@[simp]
theorem oangle_add_swap {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz]
/-- Given three nonzero vectors, the angle between the first and the third minus the angle
between the first and the second equals the angle between the second and the third. -/
@[simp]
theorem oangle_sub_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle x z - o.oangle x y = o.oangle y z := by
rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz]
/-- Given three nonzero vectors, the angle between the first and the third minus the angle
between the second and the third equals the angle between the first and the second. -/
@[simp]
theorem oangle_sub_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz]
/-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/
@[simp]
theorem oangle_add_cyc3 {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle x y + o.oangle y z + o.oangle z x = 0 := by simp [hx, hy, hz]
/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first
vector in each angle negated, results in π. If the vectors add to 0, this is a version of the
sum of the angles of a triangle. -/
@[simp]
theorem oangle_add_cyc3_neg_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = π := by
rw [o.oangle_neg_left hx hy, o.oangle_neg_left hy hz, o.oangle_neg_left hz hx,
show o.oangle x y + π + (o.oangle y z + π) + (o.oangle z x + π) =
o.oangle x y + o.oangle y z + o.oangle z x + (π + π + π : Real.Angle) by abel,
o.oangle_add_cyc3 hx hy hz, Real.Angle.coe_pi_add_coe_pi, zero_add, zero_add]
/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second
vector in each angle negated, results in π. If the vectors add to 0, this is a version of the
sum of the angles of a triangle. -/
@[simp]
theorem oangle_add_cyc3_neg_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = π := by
simp_rw [← oangle_neg_left_eq_neg_right, o.oangle_add_cyc3_neg_left hx hy hz]
/-- Pons asinorum, oriented vector angle form. -/
theorem oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) :
o.oangle x (x - y) = o.oangle (y - x) y := by simp [oangle, h]
/-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented
vector angle form. -/
theorem oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x ≠ y) (h : ‖x‖ = ‖y‖) :
o.oangle y x = π - (2 : ℤ) • o.oangle (y - x) y := by
rw [two_zsmul]
nth_rw 1 [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h]
rw [eq_sub_iff_add_eq, ← oangle_neg_neg, ← add_assoc]
have hy : y ≠ 0 := by
rintro rfl
rw [norm_zero, norm_eq_zero] at h
exact hn h
have hx : x ≠ 0 := norm_ne_zero_iff.1 (h.symm ▸ norm_ne_zero_iff.2 hy)
convert o.oangle_add_cyc3_neg_right (neg_ne_zero.2 hy) hx (sub_ne_zero_of_ne hn.symm) using 1
simp
/-- The angle between two vectors, with respect to an orientation given by `Orientation.map`
with a linear isometric equivalence, equals the angle between those two vectors, transformed by
the inverse of that equivalence, with respect to the original orientation. -/
@[simp]
theorem oangle_map (x y : V') (f : V ≃ₗᵢ[ℝ] V') :
(Orientation.map (Fin 2) f.toLinearEquiv o).oangle x y = o.oangle (f.symm x) (f.symm y) := by
simp [oangle, o.kahler_map]
@[simp]
protected theorem _root_.Complex.oangle (w z : ℂ) :
Complex.orientation.oangle w z = Complex.arg (conj w * z) := by
simp [oangle, mul_comm z]
/-- The oriented angle on an oriented real inner product space of dimension 2 can be evaluated in
terms of a complex-number representation of the space. -/
theorem oangle_map_complex (f : V ≃ₗᵢ[ℝ] ℂ)
(hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : V) :
o.oangle x y = Complex.arg (conj (f x) * f y) := by
rw [← Complex.oangle, ← hf, o.oangle_map]
iterate 2 rw [LinearIsometryEquiv.symm_apply_apply]
/-- Negating the orientation negates the value of `oangle`. -/
theorem oangle_neg_orientation_eq_neg (x y : V) : (-o).oangle x y = -o.oangle x y := by
simp [oangle]
/-- The inner product of two vectors is the product of the norms and the cosine of the oriented
angle between the vectors. -/
theorem inner_eq_norm_mul_norm_mul_cos_oangle (x y : V) :
⟪x, y⟫ = ‖x‖ * ‖y‖ * Real.Angle.cos (o.oangle x y) := by
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0; · simp [hy]
rw [oangle, Real.Angle.cos_coe, Complex.cos_arg, o.norm_kahler]
· simp only [kahler_apply_apply, real_smul, add_re, ofReal_re, mul_re, I_re, ofReal_im]
field_simp
· exact o.kahler_ne_zero hx hy
/-- The cosine of the oriented angle between two nonzero vectors is the inner product divided by
the product of the norms. -/
theorem cos_oangle_eq_inner_div_norm_mul_norm {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
Real.Angle.cos (o.oangle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) := by
rw [o.inner_eq_norm_mul_norm_mul_cos_oangle]
field_simp [norm_ne_zero_iff.2 hx, norm_ne_zero_iff.2 hy]
/-- The cosine of the oriented angle between two nonzero vectors equals that of the unoriented
angle. -/
theorem cos_oangle_eq_cos_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
Real.Angle.cos (o.oangle x y) = Real.cos (InnerProductGeometry.angle x y) := by
rw [o.cos_oangle_eq_inner_div_norm_mul_norm hx hy, InnerProductGeometry.cos_angle]
/-- The oriented angle between two nonzero vectors is plus or minus the unoriented angle. -/
theorem oangle_eq_angle_or_eq_neg_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle x y = InnerProductGeometry.angle x y ∨
o.oangle x y = -InnerProductGeometry.angle x y :=
Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg.1 <| o.cos_oangle_eq_cos_angle hx hy
/-- The unoriented angle between two nonzero vectors is the absolute value of the oriented angle,
converted to a real. -/
theorem angle_eq_abs_oangle_toReal {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
InnerProductGeometry.angle x y = |(o.oangle x y).toReal| := by
have h0 := InnerProductGeometry.angle_nonneg x y
have hpi := InnerProductGeometry.angle_le_pi x y
rcases o.oangle_eq_angle_or_eq_neg_angle hx hy with (h | h)
· rw [h, eq_comm, Real.Angle.abs_toReal_coe_eq_self_iff]
exact ⟨h0, hpi⟩
· rw [h, eq_comm, Real.Angle.abs_toReal_neg_coe_eq_self_iff]
exact ⟨h0, hpi⟩
/-- If the sign of the oriented angle between two vectors is zero, either one of the vectors is
zero or the unoriented angle is 0 or π. -/
theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {x y : V}
(h : (o.oangle x y).sign = 0) :
x = 0 ∨ y = 0 ∨ InnerProductGeometry.angle x y = 0 ∨ InnerProductGeometry.angle x y = π := by
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0; · simp [hy]
rw [o.angle_eq_abs_oangle_toReal hx hy]
rw [Real.Angle.sign_eq_zero_iff] at h
rcases h with (h | h) <;> simp [h, Real.pi_pos.le]
/-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are
equal, then the oriented angles are equal (even in degenerate cases). -/
theorem oangle_eq_of_angle_eq_of_sign_eq {w x y z : V}
(h : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z)
(hs : (o.oangle w x).sign = (o.oangle y z).sign) : o.oangle w x = o.oangle y z := by
by_cases h0 : (w = 0 ∨ x = 0) ∨ y = 0 ∨ z = 0
· have hs' : (o.oangle w x).sign = 0 ∧ (o.oangle y z).sign = 0 := by
rcases h0 with ((rfl | rfl) | rfl | rfl)
· simpa using hs.symm
· simpa using hs.symm
· simpa using hs
· simpa using hs
rcases hs' with ⟨hswx, hsyz⟩
have h' : InnerProductGeometry.angle w x = π / 2 ∧ InnerProductGeometry.angle y z = π / 2 := by
rcases h0 with ((rfl | rfl) | rfl | rfl)
· simpa using h.symm
· simpa using h.symm
· simpa using h
· simpa using h
rcases h' with ⟨hwx, hyz⟩
have hpi : π / 2 ≠ π := by
intro hpi
rw [div_eq_iff, eq_comm, ← sub_eq_zero, mul_two, add_sub_cancel_right] at hpi
· exact Real.pi_pos.ne.symm hpi
· exact two_ne_zero
have h0wx : w = 0 ∨ x = 0 := by
have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hswx
simpa [hwx, Real.pi_pos.ne.symm, hpi] using h0'
have h0yz : y = 0 ∨ z = 0 := by
have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hsyz
simpa [hyz, Real.pi_pos.ne.symm, hpi] using h0'
rcases h0wx with (h0wx | h0wx) <;> rcases h0yz with (h0yz | h0yz) <;> simp [h0wx, h0yz]
· push_neg at h0
rw [Real.Angle.eq_iff_abs_toReal_eq_of_sign_eq hs]
rwa [o.angle_eq_abs_oangle_toReal h0.1.1 h0.1.2,
o.angle_eq_abs_oangle_toReal h0.2.1 h0.2.2] at h
/-- If the signs of two oriented angles between nonzero vectors are equal, the oriented angles are
equal if and only if the unoriented angles are equal. -/
theorem angle_eq_iff_oangle_eq_of_sign_eq {w x y z : V} (hw : w ≠ 0) (hx : x ≠ 0) (hy : y ≠ 0)
(hz : z ≠ 0) (hs : (o.oangle w x).sign = (o.oangle y z).sign) :
InnerProductGeometry.angle w x = InnerProductGeometry.angle y z ↔
o.oangle w x = o.oangle y z := by
refine ⟨fun h => o.oangle_eq_of_angle_eq_of_sign_eq h hs, fun h => ?_⟩
rw [o.angle_eq_abs_oangle_toReal hw hx, o.angle_eq_abs_oangle_toReal hy hz, h]
/-- The oriented angle between two vectors equals the unoriented angle if the sign is positive. -/
theorem oangle_eq_angle_of_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) :
o.oangle x y = InnerProductGeometry.angle x y := by
by_cases hx : x = 0; · exfalso; simp [hx] at h
by_cases hy : y = 0; · exfalso; simp [hy] at h
refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_right ?_
intro hxy
rw [hxy, Real.Angle.sign_neg, neg_eq_iff_eq_neg, ← SignType.neg_iff, ← not_le] at h
exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _)
(InnerProductGeometry.angle_le_pi _ _))
/-- The oriented angle between two vectors equals minus the unoriented angle if the sign is
negative. -/
theorem oangle_eq_neg_angle_of_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) :
o.oangle x y = -InnerProductGeometry.angle x y := by
by_cases hx : x = 0; · exfalso; simp [hx] at h
by_cases hy : y = 0; · exfalso; simp [hy] at h
refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_left ?_
intro hxy
rw [hxy, ← SignType.neg_iff, ← not_le] at h
exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _)
(InnerProductGeometry.angle_le_pi _ _))
/-- The oriented angle between two nonzero vectors is zero if and only if the unoriented angle
is zero. -/
theorem oangle_eq_zero_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle x y = 0 ↔ InnerProductGeometry.angle x y = 0 := by
refine ⟨fun h => ?_, fun h => ?_⟩
· simpa [o.angle_eq_abs_oangle_toReal hx hy]
· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy
rw [h] at ha
simpa using ha
/-- The oriented angle between two vectors is `π` if and only if the unoriented angle is `π`. -/
theorem oangle_eq_pi_iff_angle_eq_pi {x y : V} :
o.oangle x y = π ↔ InnerProductGeometry.angle x y = π := by
by_cases hx : x = 0
· simp [hx, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_self₀, not_or,
Real.pi_ne_zero]
by_cases hy : y = 0
· simp [hy, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_self₀, not_or,
Real.pi_ne_zero]
refine ⟨fun h => ?_, fun h => ?_⟩
· rw [o.angle_eq_abs_oangle_toReal hx hy, h]
simp [Real.pi_pos.le]
· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy
rw [h] at ha
simpa using ha
/-- One of two vectors is zero or the oriented angle between them is plus or minus `π / 2` if
and only if the inner product of those vectors is zero. -/
theorem eq_zero_or_oangle_eq_iff_inner_eq_zero {x y : V} :
x = 0 ∨ y = 0 ∨ o.oangle x y = (π / 2 : ℝ) ∨ o.oangle x y = (-π / 2 : ℝ) ↔ ⟪x, y⟫ = 0 := by
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0; · simp [hy]
rw [InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two, or_iff_right hx, or_iff_right hy]
refine ⟨fun h => ?_, fun h => ?_⟩
· rwa [o.angle_eq_abs_oangle_toReal hx hy, Real.Angle.abs_toReal_eq_pi_div_two_iff]
· convert o.oangle_eq_angle_or_eq_neg_angle hx hy using 2 <;> rw [h]
simp only [neg_div, Real.Angle.coe_neg]
/-- If the oriented angle between two vectors is `π / 2`, the inner product of those vectors
is zero. -/
theorem inner_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) :
⟪x, y⟫ = 0 :=
o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inl h
/-- If the oriented angle between two vectors is `π / 2`, the inner product of those vectors
(reversed) is zero. -/
theorem inner_rev_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) :
⟪y, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_pi_div_two h]
/-- If the oriented angle between two vectors is `-π / 2`, the inner product of those vectors
is zero. -/
theorem inner_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
⟪x, y⟫ = 0 :=
o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inr h
/-- If the oriented angle between two vectors is `-π / 2`, the inner product of those vectors
(reversed) is zero. -/
theorem inner_rev_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
⟪y, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h]
/-- Negating the first vector passed to `oangle` negates the sign of the angle. -/
@[simp]
theorem oangle_sign_neg_left (x y : V) : (o.oangle (-x) y).sign = -(o.oangle x y).sign := by
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0; · simp [hy]
rw [o.oangle_neg_left hx hy, Real.Angle.sign_add_pi]
/-- Negating the second vector passed to `oangle` negates the sign of the angle. -/
@[simp]
theorem oangle_sign_neg_right (x y : V) : (o.oangle x (-y)).sign = -(o.oangle x y).sign := by
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0; · simp [hy]
rw [o.oangle_neg_right hx hy, Real.Angle.sign_add_pi]
/-- Multiplying the first vector passed to `oangle` by a real multiplies the sign of the angle by
the sign of the real. -/
@[simp]
theorem oangle_sign_smul_left (x y : V) (r : ℝ) :
(o.oangle (r • x) y).sign = SignType.sign r * (o.oangle x y).sign := by
rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h]
/-- Multiplying the second vector passed to `oangle` by a real multiplies the sign of the angle by
the sign of the real. -/
@[simp]
| Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean | 743 | 751 | theorem oangle_sign_smul_right (x y : V) (r : ℝ) :
(o.oangle x (r • y)).sign = SignType.sign r * (o.oangle x y).sign := by | rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h]
/-- Auxiliary lemma for the proof of `oangle_sign_smul_add_right`; not intended to be used
outside of that proof. -/
theorem oangle_smul_add_right_eq_zero_or_eq_pi_iff {x y : V} (r : ℝ) :
o.oangle x (r • x + y) = 0 ∨ o.oangle x (r • x + y) = π ↔
o.oangle x y = 0 ∨ o.oangle x y = π := by |
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Floris van Doorn
-/
import Mathlib.Geometry.Manifold.IsManifold.ExtChartAt
import Mathlib.Geometry.Manifold.LocalInvariantProperties
/-!
# `C^n` functions between manifolds
We define `Cⁿ` functions between manifolds, as functions which are `Cⁿ` in charts, and prove
basic properties of these notions. Here, `n` can be finite, or `∞`, or `ω`.
## Main definitions and statements
Let `M` and `M'` be two manifolds, with respect to models with corners `I` and `I'`. Let
`f : M → M'`.
* `ContMDiffWithinAt I I' n f s x` states that the function `f` is `Cⁿ` within the set `s`
around the point `x`.
* `ContMDiffAt I I' n f x` states that the function `f` is `Cⁿ` around `x`.
* `ContMDiffOn I I' n f s` states that the function `f` is `Cⁿ` on the set `s`
* `ContMDiff I I' n f` states that the function `f` is `Cⁿ`.
We also give some basic properties of `Cⁿ` functions between manifolds, following the API of
`C^n` functions between vector spaces.
See `Basic.lean` for further basic properties of `Cⁿ` functions between manifolds,
`NormedSpace.lean` for the equivalence of manifold-smoothness to usual smoothness,
`Product.lean` for smoothness results related to the product of manifolds and
`Atlas.lean` for smoothness of atlas members and local structomorphisms.
## Implementation details
Many properties follow for free from the corresponding properties of functions in vector spaces,
as being `Cⁿ` is a local property invariant under the `Cⁿ` groupoid. We take advantage of the
general machinery developed in `LocalInvariantProperties.lean` to get these properties
automatically. For instance, the fact that being `Cⁿ` does not depend on the chart one considers
is given by `liftPropWithinAt_indep_chart`.
For this to work, the definition of `ContMDiffWithinAt` and friends has to
follow definitionally the setup of local invariant properties. Still, we recast the definition
in terms of extended charts in `contMDiffOn_iff` and `contMDiff_iff`.
-/
open Set Function Filter ChartedSpace IsManifold
open scoped Topology Manifold ContDiff
/-! ### Definition of `Cⁿ` functions between manifolds -/
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
-- Prerequisite typeclasses to say that `M` is a manifold over the pair `(E, H)`
{E : Type*}
[NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H]
{I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M]
-- Prerequisite typeclasses to say that `M'` is a manifold over the pair `(E', H')`
{E' : Type*}
[NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H']
{I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M']
-- Prerequisite typeclasses to say that `M''` is a manifold over the pair `(E'', H'')`
{E'' : Type*}
[NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H'']
{I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M'']
-- declare functions, sets, points and smoothness indices
{e : PartialHomeomorph M H}
{e' : PartialHomeomorph M' H'} {f f₁ : M → M'} {s s₁ t : Set M} {x : M} {m n : WithTop ℕ∞}
variable (I I') in
/-- Property in the model space of a model with corners of being `C^n` within at set at a point,
when read in the model vector space. This property will be lifted to manifolds to define `C^n`
functions between manifolds. -/
def ContDiffWithinAtProp (n : WithTop ℕ∞) (f : H → H') (s : Set H) (x : H) : Prop :=
ContDiffWithinAt 𝕜 n (I' ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x)
theorem contDiffWithinAtProp_self_source {f : E → H'} {s : Set E} {x : E} :
ContDiffWithinAtProp 𝓘(𝕜, E) I' n f s x ↔ ContDiffWithinAt 𝕜 n (I' ∘ f) s x := by
simp_rw [ContDiffWithinAtProp, modelWithCornersSelf_coe, range_id, inter_univ,
modelWithCornersSelf_coe_symm, CompTriple.comp_eq, preimage_id_eq, id_eq]
theorem contDiffWithinAtProp_self {f : E → E'} {s : Set E} {x : E} :
ContDiffWithinAtProp 𝓘(𝕜, E) 𝓘(𝕜, E') n f s x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAtProp_self_source
theorem contDiffWithinAtProp_self_target {f : H → E'} {s : Set H} {x : H} :
ContDiffWithinAtProp I 𝓘(𝕜, E') n f s x ↔
ContDiffWithinAt 𝕜 n (f ∘ I.symm) (I.symm ⁻¹' s ∩ range I) (I x) :=
Iff.rfl
/-- Being `Cⁿ` in the model space is a local property, invariant under `Cⁿ` maps. Therefore,
it lifts nicely to manifolds. -/
theorem contDiffWithinAt_localInvariantProp_of_le (n m : WithTop ℕ∞) (hmn : m ≤ n) :
(contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I')
(ContDiffWithinAtProp I I' m) where
is_local {s x u f} u_open xu := by
have : I.symm ⁻¹' (s ∩ u) ∩ range I = I.symm ⁻¹' s ∩ range I ∩ I.symm ⁻¹' u := by
simp only [inter_right_comm, preimage_inter]
rw [ContDiffWithinAtProp, ContDiffWithinAtProp, this]
symm
apply contDiffWithinAt_inter
have : u ∈ 𝓝 (I.symm (I x)) := by
rw [ModelWithCorners.left_inv]
exact u_open.mem_nhds xu
apply ContinuousAt.preimage_mem_nhds I.continuous_symm.continuousAt this
right_invariance' {s x f e} he hx h := by
rw [ContDiffWithinAtProp] at h ⊢
have : I x = (I ∘ e.symm ∘ I.symm) (I (e x)) := by simp only [hx, mfld_simps]
rw [this] at h
have : I (e x) ∈ I.symm ⁻¹' e.target ∩ range I := by simp only [hx, mfld_simps]
have := (mem_groupoid_of_pregroupoid.2 he).2.contDiffWithinAt this
convert (h.comp_inter _ (this.of_le hmn)).mono_of_mem_nhdsWithin _
using 1
· ext y; simp only [mfld_simps]
refine mem_nhdsWithin.mpr
⟨I.symm ⁻¹' e.target, e.open_target.preimage I.continuous_symm, by
simp_rw [mem_preimage, I.left_inv, e.mapsTo hx], ?_⟩
mfld_set_tac
congr_of_forall {s x f g} h hx hf := by
apply hf.congr
· intro y hy
simp only [mfld_simps] at hy
simp only [h, hy, mfld_simps]
· simp only [hx, mfld_simps]
left_invariance' {s x f e'} he' hs hx h := by
rw [ContDiffWithinAtProp] at h ⊢
have A : (I' ∘ f ∘ I.symm) (I x) ∈ I'.symm ⁻¹' e'.source ∩ range I' := by
simp only [hx, mfld_simps]
have := (mem_groupoid_of_pregroupoid.2 he').1.contDiffWithinAt A
convert (this.of_le hmn).comp _ h _
· ext y; simp only [mfld_simps]
· intro y hy; simp only [mfld_simps] at hy; simpa only [hy, mfld_simps] using hs hy.1
/-- Being `Cⁿ` in the model space is a local property, invariant under `C^n` maps. Therefore,
it lifts nicely to manifolds. -/
theorem contDiffWithinAt_localInvariantProp (n : WithTop ℕ∞) :
(contDiffGroupoid n I).LocalInvariantProp (contDiffGroupoid n I')
(ContDiffWithinAtProp I I' n) :=
contDiffWithinAt_localInvariantProp_of_le n n le_rfl
theorem contDiffWithinAtProp_mono_of_mem_nhdsWithin
(n : WithTop ℕ∞) ⦃s x t⦄ ⦃f : H → H'⦄ (hts : s ∈ 𝓝[t] x)
(h : ContDiffWithinAtProp I I' n f s x) : ContDiffWithinAtProp I I' n f t x := by
refine h.mono_of_mem_nhdsWithin ?_
refine inter_mem ?_ (mem_of_superset self_mem_nhdsWithin inter_subset_right)
rwa [← Filter.mem_map, ← I.image_eq, I.symm_map_nhdsWithin_image]
@[deprecated (since := "2024-10-31")]
alias contDiffWithinAtProp_mono_of_mem := contDiffWithinAtProp_mono_of_mem_nhdsWithin
theorem contDiffWithinAtProp_id (x : H) : ContDiffWithinAtProp I I n id univ x := by
simp only [ContDiffWithinAtProp, id_comp, preimage_univ, univ_inter]
have : ContDiffWithinAt 𝕜 n id (range I) (I x) := contDiff_id.contDiffAt.contDiffWithinAt
refine this.congr (fun y hy => ?_) ?_
· simp only [ModelWithCorners.right_inv I hy, mfld_simps]
· simp only [mfld_simps]
variable (I I') in
/-- A function is `n` times continuously differentiable within a set at a point in a manifold if
it is continuous and it is `n` times continuously differentiable in this set around this point, when
read in the preferred chart at this point. -/
def ContMDiffWithinAt (n : WithTop ℕ∞) (f : M → M') (s : Set M) (x : M) :=
LiftPropWithinAt (ContDiffWithinAtProp I I' n) f s x
@[deprecated (since := "2024-11-21")] alias SmoothWithinAt := ContMDiffWithinAt
variable (I I') in
/-- A function is `n` times continuously differentiable at a point in a manifold if
it is continuous and it is `n` times continuously differentiable around this point, when
read in the preferred chart at this point. -/
def ContMDiffAt (n : WithTop ℕ∞) (f : M → M') (x : M) :=
ContMDiffWithinAt I I' n f univ x
theorem contMDiffAt_iff {n : WithTop ℕ∞} {f : M → M'} {x : M} :
ContMDiffAt I I' n f x ↔
ContinuousAt f x ∧
ContDiffWithinAt 𝕜 n (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) (range I)
(extChartAt I x x) :=
liftPropAt_iff.trans <| by rw [ContDiffWithinAtProp, preimage_univ, univ_inter]; rfl
@[deprecated (since := "2024-11-21")] alias SmoothAt := ContMDiffAt
variable (I I') in
/-- A function is `n` times continuously differentiable in a set of a manifold if it is continuous
and, for any pair of points, it is `n` times continuously differentiable on this set in the charts
around these points. -/
def ContMDiffOn (n : WithTop ℕ∞) (f : M → M') (s : Set M) :=
∀ x ∈ s, ContMDiffWithinAt I I' n f s x
@[deprecated (since := "2024-11-21")] alias SmoothOn := ContMDiffOn
variable (I I') in
/-- A function is `n` times continuously differentiable in a manifold if it is continuous
and, for any pair of points, it is `n` times continuously differentiable in the charts
around these points. -/
def ContMDiff (n : WithTop ℕ∞) (f : M → M') :=
∀ x, ContMDiffAt I I' n f x
@[deprecated (since := "2024-11-21")] alias Smooth := ContMDiff
/-! ### Deducing smoothness from higher smoothness -/
theorem ContMDiffWithinAt.of_le (hf : ContMDiffWithinAt I I' n f s x) (le : m ≤ n) :
ContMDiffWithinAt I I' m f s x := by
simp only [ContMDiffWithinAt, LiftPropWithinAt] at hf ⊢
exact ⟨hf.1, hf.2.of_le (mod_cast le)⟩
theorem ContMDiffAt.of_le (hf : ContMDiffAt I I' n f x) (le : m ≤ n) : ContMDiffAt I I' m f x :=
ContMDiffWithinAt.of_le hf le
theorem ContMDiffOn.of_le (hf : ContMDiffOn I I' n f s) (le : m ≤ n) : ContMDiffOn I I' m f s :=
fun x hx => (hf x hx).of_le le
theorem ContMDiff.of_le (hf : ContMDiff I I' n f) (le : m ≤ n) : ContMDiff I I' m f := fun x =>
(hf x).of_le le
/-! ### Basic properties of `C^n` functions between manifolds -/
@[deprecated (since := "2024-11-20")] alias ContMDiff.smooth := ContMDiff.of_le
@[deprecated (since := "2024-11-20")] alias Smooth.contMDiff := ContMDiff.of_le
@[deprecated (since := "2024-11-20")] alias ContMDiffOn.smoothOn := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")] alias SmoothOn.contMDiffOn := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")] alias ContMDiffAt.smoothAt := ContMDiffAt.of_le
@[deprecated (since := "2024-11-20")] alias SmoothAt.contMDiffAt := ContMDiffOn.of_le
@[deprecated (since := "2024-11-20")]
alias ContMDiffWithinAt.smoothWithinAt := ContMDiffWithinAt.of_le
@[deprecated (since := "2024-11-20")]
alias SmoothWithinAt.contMDiffWithinAt := ContMDiffWithinAt.of_le
theorem ContMDiff.contMDiffAt (h : ContMDiff I I' n f) : ContMDiffAt I I' n f x :=
h x
@[deprecated (since := "2024-11-20")] alias Smooth.smoothAt := ContMDiff.contMDiffAt
theorem contMDiffWithinAt_univ : ContMDiffWithinAt I I' n f univ x ↔ ContMDiffAt I I' n f x :=
Iff.rfl
@[deprecated (since := "2024-11-20")] alias smoothWithinAt_univ := contMDiffWithinAt_univ
theorem contMDiffOn_univ : ContMDiffOn I I' n f univ ↔ ContMDiff I I' n f := by
simp only [ContMDiffOn, ContMDiff, contMDiffWithinAt_univ, forall_prop_of_true, mem_univ]
@[deprecated (since := "2024-11-20")] alias smoothOn_univ := contMDiffOn_univ
/-- One can reformulate being `C^n` within a set at a point as continuity within this set at this
point, and being `C^n` in the corresponding extended chart. -/
theorem contMDiffWithinAt_iff :
ContMDiffWithinAt I I' n f s x ↔
ContinuousWithinAt f s x ∧
ContDiffWithinAt 𝕜 n (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm)
((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x) := by
simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff']; rfl
/-- One can reformulate being `Cⁿ` within a set at a point as continuity within this set at this
point, and being `Cⁿ` in the corresponding extended chart. This form states regularity of `f`
written in such a way that the set is restricted to lie within the domain/codomain of the
corresponding charts.
Even though this expression is more complicated than the one in `contMDiffWithinAt_iff`, it is
a smaller set, but their germs at `extChartAt I x x` are equal. It is sometimes useful to rewrite
using this in the goal.
-/
theorem contMDiffWithinAt_iff' :
ContMDiffWithinAt I I' n f s x ↔
ContinuousWithinAt f s x ∧
ContDiffWithinAt 𝕜 n (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm)
((extChartAt I x).target ∩
(extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' (f x)).source))
(extChartAt I x x) := by
simp only [ContMDiffWithinAt, liftPropWithinAt_iff']
exact and_congr_right fun hc => contDiffWithinAt_congr_set <|
hc.extChartAt_symm_preimage_inter_range_eventuallyEq
/-- One can reformulate being `Cⁿ` within a set at a point as continuity within this set at this
point, and being `Cⁿ` in the corresponding extended chart in the target. -/
theorem contMDiffWithinAt_iff_target :
ContMDiffWithinAt I I' n f s x ↔
ContinuousWithinAt f s x ∧ ContMDiffWithinAt I 𝓘(𝕜, E') n (extChartAt I' (f x) ∘ f) s x := by
simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff', ← and_assoc]
have cont :
ContinuousWithinAt f s x ∧ ContinuousWithinAt (extChartAt I' (f x) ∘ f) s x ↔
ContinuousWithinAt f s x :=
and_iff_left_of_imp <| (continuousAt_extChartAt _).comp_continuousWithinAt
simp_rw [cont, ContDiffWithinAtProp, extChartAt, PartialHomeomorph.extend, PartialEquiv.coe_trans,
ModelWithCorners.toPartialEquiv_coe, PartialHomeomorph.coe_coe, modelWithCornersSelf_coe,
chartAt_self_eq, PartialHomeomorph.refl_apply, id_comp]
rfl
@[deprecated (since := "2024-11-20")] alias smoothWithinAt_iff := contMDiffWithinAt_iff
@[deprecated (since := "2024-11-20")]
alias smoothWithinAt_iff_target := contMDiffWithinAt_iff_target
theorem contMDiffAt_iff_target {x : M} :
ContMDiffAt I I' n f x ↔
ContinuousAt f x ∧ ContMDiffAt I 𝓘(𝕜, E') n (extChartAt I' (f x) ∘ f) x := by
rw [ContMDiffAt, ContMDiffAt, contMDiffWithinAt_iff_target, continuousWithinAt_univ]
@[deprecated (since := "2024-11-20")] alias smoothAt_iff_target := contMDiffAt_iff_target
/-- One can reformulate being `Cⁿ` within a set at a point as being `Cⁿ` in the source space when
composing with the extended chart. -/
theorem contMDiffWithinAt_iff_source :
ContMDiffWithinAt I I' n f s x ↔
ContMDiffWithinAt 𝓘(𝕜, E) I' n (f ∘ (extChartAt I x).symm)
((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x) := by
simp_rw [ContMDiffWithinAt, liftPropWithinAt_iff']
have : ContinuousWithinAt f s x
↔ ContinuousWithinAt (f ∘ ↑(extChartAt I x).symm) (↑(extChartAt I x).symm ⁻¹' s ∩ range ↑I)
(extChartAt I x x) := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· apply h.comp_of_eq
· exact (continuousAt_extChartAt_symm x).continuousWithinAt
· exact (mapsTo_preimage _ _).mono_left inter_subset_left
· exact extChartAt_to_inv x
· rw [← continuousWithinAt_inter (extChartAt_source_mem_nhds (I := I) x)]
have : ContinuousWithinAt ((f ∘ ↑(extChartAt I x).symm) ∘ ↑(extChartAt I x))
(s ∩ (extChartAt I x).source) x := by
apply h.comp (continuousAt_extChartAt x).continuousWithinAt
intro y hy
have : (chartAt H x).symm ((chartAt H x) y) = y :=
PartialHomeomorph.left_inv _ (by simpa using hy.2)
simpa [this] using hy.1
apply this.congr
· intro y hy
have : (chartAt H x).symm ((chartAt H x) y) = y :=
PartialHomeomorph.left_inv _ (by simpa using hy.2)
simp [this]
· simp
rw [← this]
simp only [ContDiffWithinAtProp, mfld_simps, preimage_comp, comp_assoc]
/-- One can reformulate being `Cⁿ` at a point as being `Cⁿ` in the source space when
composing with the extended chart. -/
theorem contMDiffAt_iff_source :
ContMDiffAt I I' n f x ↔
ContMDiffWithinAt 𝓘(𝕜, E) I' n (f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x) := by
rw [← contMDiffWithinAt_univ, contMDiffWithinAt_iff_source]
simp
section IsManifold
theorem contMDiffWithinAt_iff_source_of_mem_maximalAtlas
[IsManifold I n M] (he : e ∈ maximalAtlas I n M) (hx : x ∈ e.source) :
ContMDiffWithinAt I I' n f s x ↔
ContMDiffWithinAt 𝓘(𝕜, E) I' n (f ∘ (e.extend I).symm) ((e.extend I).symm ⁻¹' s ∩ range I)
(e.extend I x) := by
have h2x := hx; rw [← e.extend_source (I := I)] at h2x
simp_rw [ContMDiffWithinAt,
(contDiffWithinAt_localInvariantProp n).liftPropWithinAt_indep_chart_source he hx,
StructureGroupoid.liftPropWithinAt_self_source,
e.extend_symm_continuousWithinAt_comp_right_iff, contDiffWithinAtProp_self_source,
ContDiffWithinAtProp, Function.comp, e.left_inv hx, (e.extend I).left_inv h2x]
rfl
theorem contMDiffWithinAt_iff_source_of_mem_source
[IsManifold I n M] {x' : M} (hx' : x' ∈ (chartAt H x).source) :
ContMDiffWithinAt I I' n f s x' ↔
ContMDiffWithinAt 𝓘(𝕜, E) I' n (f ∘ (extChartAt I x).symm)
((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x') :=
contMDiffWithinAt_iff_source_of_mem_maximalAtlas (chart_mem_maximalAtlas x) hx'
theorem contMDiffAt_iff_source_of_mem_source
[IsManifold I n M] {x' : M} (hx' : x' ∈ (chartAt H x).source) :
ContMDiffAt I I' n f x' ↔
ContMDiffWithinAt 𝓘(𝕜, E) I' n (f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x') := by
simp_rw [ContMDiffAt, contMDiffWithinAt_iff_source_of_mem_source hx', preimage_univ, univ_inter]
| Mathlib/Geometry/Manifold/ContMDiff/Defs.lean | 377 | 380 | theorem contMDiffWithinAt_iff_target_of_mem_source
[IsManifold I' n M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) :
ContMDiffWithinAt I I' n f s x ↔
ContinuousWithinAt f s x ∧ ContMDiffWithinAt I 𝓘(𝕜, E') n (extChartAt I' y ∘ f) s x := by | |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell
-/
import Mathlib.Data.Nat.Factorial.Basic
import Mathlib.Order.Monotone.Defs
/-!
# Binomial coefficients
This file defines binomial coefficients and proves simple lemmas (i.e. those not
requiring more imports).
For the lemma that `n.choose k` counts the `k`-element-subsets of an `n`-element set,
see `Fintype.card_powersetCard` in `Mathlib.Data.Finset.Powerset`.
## Main definition and results
* `Nat.choose`: binomial coefficients, defined inductively
* `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)`
* `Nat.choose_symm`: symmetry of binomial coefficients
* `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k`
* `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2`
* `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending
factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements
for the ascending factorial.
* `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations.
The fact that this is indeed the correct counting function for multisets is proved in
`Sym.card_sym_eq_multichoose` in `Data.Sym.Card`.
* `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`.
This is central to the "stars and bars" technique in informal mathematics, where we switch between
counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements
("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail.
## Tags
binomial coefficient, combination, multicombination, stars and bars
-/
open Nat
namespace Nat
/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial
coefficients. For the fact that this is the number of `k`-element-subsets of an `n`-element
set, see `Fintype.card_powersetCard`. -/
def choose : ℕ → ℕ → ℕ
| _, 0 => 1
| 0, _ + 1 => 0
| n + 1, k + 1 => choose n k + choose n (k + 1)
@[simp]
theorem choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n <;> rfl
@[simp]
theorem choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 :=
rfl
theorem choose_succ_succ (n k : ℕ) : choose (succ n) (succ k) = choose n k + choose n (succ k) :=
rfl
theorem choose_succ_succ' (n k : ℕ) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) :=
rfl
theorem choose_succ_left (n k : ℕ) (hk : 0 < k) :
choose (n + 1) k = choose n (k - 1) + choose n k := by
obtain ⟨l, rfl⟩ : ∃ l, k = l + 1 := Nat.exists_eq_add_of_le' hk
rfl
theorem choose_succ_right (n k : ℕ) (hn : 0 < n) :
choose n (k + 1) = choose (n - 1) k + choose (n - 1) (k + 1) := by
obtain ⟨l, rfl⟩ : ∃ l, n = l + 1 := Nat.exists_eq_add_of_le' hn
rfl
theorem choose_eq_choose_pred_add {n k : ℕ} (hn : 0 < n) (hk : 0 < k) :
choose n k = choose (n - 1) (k - 1) + choose (n - 1) k := by
obtain ⟨l, rfl⟩ : ∃ l, k = l + 1 := Nat.exists_eq_add_of_le' hk
rw [choose_succ_right _ _ hn, Nat.add_one_sub_one]
theorem choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0
| _, 0, hk => absurd hk (Nat.not_lt_zero _)
| 0, _ + 1, _ => choose_zero_succ _
| n + 1, k + 1, hk => by
have hnk : n < k := lt_of_succ_lt_succ hk
have hnk1 : n < k + 1 := lt_of_succ_lt hk
rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1]
@[simp]
theorem choose_self (n : ℕ) : choose n n = 1 := by
induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)]
@[simp]
theorem choose_succ_self (n : ℕ) : choose n (succ n) = 0 :=
choose_eq_zero_of_lt (lt_succ_self _)
@[simp]
lemma choose_one_right (n : ℕ) : choose n 1 = n := by induction n <;> simp [*, choose, Nat.add_comm]
-- The `n+1`-st triangle number is `n` more than the `n`-th triangle number
theorem triangle_succ (n : ℕ) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by
rw [← add_mul_div_left, Nat.mul_comm 2 n, ← Nat.mul_add, Nat.add_sub_cancel, Nat.mul_comm]
cases n <;> rfl; apply zero_lt_succ
/-- `choose n 2` is the `n`-th triangle number. -/
theorem choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 := by
induction' n with n ih
· simp
· rw [triangle_succ n, choose, ih]
simp [Nat.add_comm]
theorem choose_pos : ∀ {n k}, k ≤ n → 0 < choose n k
| 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk]; decide
| n + 1, 0, _ => by simp
| _ + 1, _ + 1, hk => Nat.add_pos_left (choose_pos (le_of_succ_le_succ hk)) _
theorem choose_eq_zero_iff {n k : ℕ} : n.choose k = 0 ↔ n < k :=
⟨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt⟩
theorem succ_mul_choose_eq : ∀ n k, succ n * choose n k = choose (succ n) (succ k) * succ k
| 0, 0 => by decide
| 0, k + 1 => by simp [choose]
| n + 1, 0 => by simp [choose, mul_succ, Nat.add_comm]
| n + 1, k + 1 => by
rw [choose_succ_succ (succ n) (succ k), Nat.add_mul, ← succ_mul_choose_eq n, mul_succ, ←
succ_mul_choose_eq n, Nat.add_right_comm, ← Nat.mul_add, ← choose_succ_succ, ← succ_mul]
theorem choose_mul_factorial_mul_factorial : ∀ {n k}, k ≤ n → choose n k * k ! * (n - k)! = n !
| 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk]
| n + 1, 0, _ => by simp
| n + 1, succ k, hk => by
rcases lt_or_eq_of_le hk with hk₁ | hk₁
· have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by
rw [← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have h₁ : (n - k)! = (n - k) * (n - k.succ)! := by
rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ]
have h₂ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by
rw [← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have h₃ : k * n ! ≤ n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk)
rw [choose_succ_succ, Nat.add_mul, Nat.add_mul, succ_sub_succ, h, h₁, h₂, Nat.add_mul,
Nat.mul_sub_right_distrib, factorial_succ, ← Nat.add_sub_assoc h₃, Nat.add_assoc,
← Nat.add_mul, Nat.add_sub_cancel_left, Nat.add_comm]
· rw [hk₁]; simp [hk₁, Nat.mul_comm, choose, Nat.sub_self]
theorem choose_mul {n k s : ℕ} (hkn : k ≤ n) (hsk : s ≤ k) :
n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) :=
have h : 0 < (n - k)! * (k - s)! * s ! := by apply_rules [factorial_pos, Nat.mul_pos]
Nat.mul_right_cancel h <|
calc
n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) =
n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! := by
rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc _ s !, Nat.mul_assoc,
Nat.mul_comm (n - k)!, Nat.mul_comm s !]
_ = n ! := by
rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn]
_ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by
rw [choose_mul_factorial_mul_factorial (Nat.sub_le_sub_right hkn _),
choose_mul_factorial_mul_factorial (hsk.trans hkn)]
_ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by
rw [Nat.sub_sub_sub_cancel_right hsk, Nat.mul_assoc, Nat.mul_left_comm s !, Nat.mul_assoc,
Nat.mul_comm (k - s)!, Nat.mul_comm s !, Nat.mul_right_comm, ← Nat.mul_assoc]
theorem choose_eq_factorial_div_factorial {n k : ℕ} (hk : k ≤ n) :
choose n k = n ! / (k ! * (n - k)!) := by
rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]
exact (mul_div_left _ (Nat.mul_pos (factorial_pos _) (factorial_pos _))).symm
theorem add_choose (i j : ℕ) : (i + j).choose j = (i + j)! / (i ! * j !) := by
rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), Nat.add_sub_cancel_right,
Nat.mul_comm]
theorem add_choose_mul_factorial_mul_factorial (i j : ℕ) :
(i + j).choose j * i ! * j ! = (i + j)! := by
rw [← choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), Nat.add_sub_cancel_right,
Nat.mul_right_comm]
theorem factorial_mul_factorial_dvd_factorial {n k : ℕ} (hk : k ≤ n) : k ! * (n - k)! ∣ n ! := by
rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]; exact Nat.dvd_mul_left _ _
theorem factorial_mul_factorial_dvd_factorial_add (i j : ℕ) : i ! * j ! ∣ (i + j)! := by
suffices i ! * (i + j - i) ! ∣ (i + j)! by
rwa [Nat.add_sub_cancel_left i j] at this
exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _)
@[simp]
theorem choose_symm {n k : ℕ} (hk : k ≤ n) : choose n (n - k) = choose n k := by
rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _),
Nat.sub_sub_self hk, Nat.mul_comm]
| Mathlib/Data/Nat/Choose/Basic.lean | 192 | 194 | theorem choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by | suffices choose n (n - b) = choose n b by
rw [h, Nat.add_sub_cancel_right] at this; rwa [h] |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl, Yury Kudryashov, Patrick Massot
-/
import Mathlib.Algebra.GeomSum
import Mathlib.Order.Filter.AtTopBot.Archimedean
import Mathlib.Order.Iterate
import Mathlib.Topology.Algebra.Algebra
import Mathlib.Topology.Algebra.InfiniteSum.Real
import Mathlib.Topology.Instances.EReal.Lemmas
/-!
# A collection of specific limit computations
This file, by design, is independent of `NormedSpace` in the import hierarchy. It contains
important specific limit computations in metric spaces, in ordered rings/fields, and in specific
instances of these such as `ℝ`, `ℝ≥0` and `ℝ≥0∞`.
-/
assert_not_exists Basis NormedSpace
noncomputable section
open Set Function Filter Finset Metric Topology Nat uniformity NNReal ENNReal
variable {α : Type*} {β : Type*} {ι : Type*}
theorem tendsto_inverse_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹) atTop (𝓝 0) :=
tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop
theorem tendsto_const_div_atTop_nhds_zero_nat (C : ℝ) :
Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by
simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_atTop_nhds_zero_nat
theorem tendsto_one_div_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ 1/(n : ℝ)) atTop (𝓝 0) :=
tendsto_const_div_atTop_nhds_zero_nat 1
theorem NNReal.tendsto_inverse_atTop_nhds_zero_nat :
Tendsto (fun n : ℕ ↦ (n : ℝ≥0)⁻¹) atTop (𝓝 0) := by
rw [← NNReal.tendsto_coe]
exact _root_.tendsto_inverse_atTop_nhds_zero_nat
theorem NNReal.tendsto_const_div_atTop_nhds_zero_nat (C : ℝ≥0) :
Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by
simpa using tendsto_const_nhds.mul NNReal.tendsto_inverse_atTop_nhds_zero_nat
theorem EReal.tendsto_const_div_atTop_nhds_zero_nat {C : EReal} (h : C ≠ ⊥) (h' : C ≠ ⊤) :
Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by
have : (fun n : ℕ ↦ C / n) = fun n : ℕ ↦ ((C.toReal / n : ℝ) : EReal) := by
ext n
nth_rw 1 [← coe_toReal h' h, ← coe_coe_eq_natCast n, ← coe_div C.toReal n]
rw [this, ← coe_zero, tendsto_coe]
exact _root_.tendsto_const_div_atTop_nhds_zero_nat C.toReal
theorem tendsto_one_div_add_atTop_nhds_zero_nat :
Tendsto (fun n : ℕ ↦ 1 / ((n : ℝ) + 1)) atTop (𝓝 0) :=
suffices Tendsto (fun n : ℕ ↦ 1 / (↑(n + 1) : ℝ)) atTop (𝓝 0) by simpa
(tendsto_add_atTop_iff_nat 1).2 (_root_.tendsto_const_div_atTop_nhds_zero_nat 1)
theorem NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat (𝕜 : Type*) [Semiring 𝕜]
[Algebra ℝ≥0 𝕜] [TopologicalSpace 𝕜] [ContinuousSMul ℝ≥0 𝕜] :
Tendsto (algebraMap ℝ≥0 𝕜 ∘ fun n : ℕ ↦ (n : ℝ≥0)⁻¹) atTop (𝓝 0) := by
convert (continuous_algebraMap ℝ≥0 𝕜).continuousAt.tendsto.comp
tendsto_inverse_atTop_nhds_zero_nat
rw [map_zero]
theorem tendsto_algebraMap_inverse_atTop_nhds_zero_nat (𝕜 : Type*) [Semiring 𝕜] [Algebra ℝ 𝕜]
[TopologicalSpace 𝕜] [ContinuousSMul ℝ 𝕜] :
Tendsto (algebraMap ℝ 𝕜 ∘ fun n : ℕ ↦ (n : ℝ)⁻¹) atTop (𝓝 0) :=
NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat 𝕜
/-- The limit of `n / (n + x)` is 1, for any constant `x` (valid in `ℝ` or any topological division
algebra over `ℝ`, e.g., `ℂ`).
TODO: introduce a typeclass saying that `1 / n` tends to 0 at top, making it possible to get this
statement simultaneously on `ℚ`, `ℝ` and `ℂ`. -/
theorem tendsto_natCast_div_add_atTop {𝕜 : Type*} [DivisionRing 𝕜] [TopologicalSpace 𝕜]
[CharZero 𝕜] [Algebra ℝ 𝕜] [ContinuousSMul ℝ 𝕜] [IsTopologicalDivisionRing 𝕜] (x : 𝕜) :
Tendsto (fun n : ℕ ↦ (n : 𝕜) / (n + x)) atTop (𝓝 1) := by
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (Eventually.of_forall fun n hn ↦ _)) _
· exact fun n : ℕ ↦ 1 / (1 + x / n)
· field_simp [Nat.cast_ne_zero.mpr hn]
· have : 𝓝 (1 : 𝕜) = 𝓝 (1 / (1 + x * (0 : 𝕜))) := by
rw [mul_zero, add_zero, div_one]
rw [this]
refine tendsto_const_nhds.div (tendsto_const_nhds.add ?_) (by simp)
simp_rw [div_eq_mul_inv]
refine tendsto_const_nhds.mul ?_
have := ((continuous_algebraMap ℝ 𝕜).tendsto _).comp tendsto_inverse_atTop_nhds_zero_nat
rw [map_zero, Filter.tendsto_atTop'] at this
refine Iff.mpr tendsto_atTop' ?_
intros
simp_all only [comp_apply, map_inv₀, map_natCast]
/-- For any positive `m : ℕ`, `((n % m : ℕ) : ℝ) / (n : ℝ)` tends to `0` as `n` tends to `∞`. -/
theorem tendsto_mod_div_atTop_nhds_zero_nat {m : ℕ} (hm : 0 < m) :
Tendsto (fun n : ℕ => ((n % m : ℕ) : ℝ) / (n : ℝ)) atTop (𝓝 0) := by
have h0 : ∀ᶠ n : ℕ in atTop, 0 ≤ (fun n : ℕ => ((n % m : ℕ) : ℝ)) n := by aesop
exact tendsto_bdd_div_atTop_nhds_zero h0
(.of_forall (fun n ↦ cast_le.mpr (mod_lt n hm).le)) tendsto_natCast_atTop_atTop
theorem Filter.EventuallyEq.div_mul_cancel {α G : Type*} [GroupWithZero G] {f g : α → G}
{l : Filter α} (hg : Tendsto g l (𝓟 {0}ᶜ)) : (fun x ↦ f x / g x * g x) =ᶠ[l] fun x ↦ f x := by
filter_upwards [hg.le_comap <| preimage_mem_comap (m := g) (mem_principal_self {0}ᶜ)] with x hx
aesop
/-- If `g` tends to `∞`, then eventually for all `x` we have `(f x / g x) * g x = f x`. -/
theorem Filter.EventuallyEq.div_mul_cancel_atTop {α K : Type*}
[Semifield K] [LinearOrder K] [IsStrictOrderedRing K]
{f g : α → K} {l : Filter α} (hg : Tendsto g l atTop) :
(fun x ↦ f x / g x * g x) =ᶠ[l] fun x ↦ f x :=
div_mul_cancel <| hg.mono_right <| le_principal_iff.mpr <|
mem_of_superset (Ioi_mem_atTop 0) <| by simp
/-- If when `x` tends to `∞`, `g` tends to `∞` and `f x / g x` tends to a positive
constant, then `f` tends to `∞`. -/
theorem Tendsto.num {α K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K]
[TopologicalSpace K] [OrderTopology K]
{f g : α → K} {l : Filter α} (hg : Tendsto g l atTop) {a : K} (ha : 0 < a)
(hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) :
Tendsto f l atTop :=
(hlim.pos_mul_atTop ha hg).congr' (EventuallyEq.div_mul_cancel_atTop hg)
/-- If when `x` tends to `∞`, `g` tends to `∞` and `f x / g x` tends to a positive
constant, then `f` tends to `∞`. -/
theorem Tendsto.den {α K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K]
[TopologicalSpace K] [OrderTopology K]
[ContinuousInv K] {f g : α → K} {l : Filter α} (hf : Tendsto f l atTop) {a : K} (ha : 0 < a)
(hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) :
Tendsto g l atTop :=
have hlim' : Tendsto (fun x => g x / f x) l (𝓝 a⁻¹) := by
simp_rw [← inv_div (f _)]
exact Filter.Tendsto.inv (f := fun x => f x / g x) hlim
(hlim'.pos_mul_atTop (inv_pos_of_pos ha) hf).congr' (.div_mul_cancel_atTop hf)
/-- If when `x` tends to `∞`, `f x / g x` tends to a positive constant, then `f` tends to `∞` if
and only if `g` tends to `∞`. -/
theorem Tendsto.num_atTop_iff_den_atTop {α K : Type*}
[Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K]
[OrderTopology K] [ContinuousInv K] {f g : α → K} {l : Filter α} {a : K} (ha : 0 < a)
(hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) :
Tendsto f l atTop ↔ Tendsto g l atTop :=
⟨fun hf ↦ Tendsto.den hf ha hlim, fun hg ↦ Tendsto.num hg ha hlim⟩
/-! ### Powers -/
theorem tendsto_add_one_pow_atTop_atTop_of_pos
[Semiring α] [LinearOrder α] [IsStrictOrderedRing α] [Archimedean α] {r : α}
(h : 0 < r) : Tendsto (fun n : ℕ ↦ (r + 1) ^ n) atTop atTop :=
tendsto_atTop_atTop_of_monotone' (pow_right_mono₀ <| le_add_of_nonneg_left h.le) <|
not_bddAbove_iff.2 fun _ ↦ Set.exists_range_iff.2 <| add_one_pow_unbounded_of_pos _ h
theorem tendsto_pow_atTop_atTop_of_one_lt
[Ring α] [LinearOrder α] [IsStrictOrderedRing α] [Archimedean α] {r : α}
(h : 1 < r) : Tendsto (fun n : ℕ ↦ r ^ n) atTop atTop :=
sub_add_cancel r 1 ▸ tendsto_add_one_pow_atTop_atTop_of_pos (sub_pos.2 h)
theorem Nat.tendsto_pow_atTop_atTop_of_one_lt {m : ℕ} (h : 1 < m) :
Tendsto (fun n : ℕ ↦ m ^ n) atTop atTop :=
tsub_add_cancel_of_le (le_of_lt h) ▸ tendsto_add_one_pow_atTop_atTop_of_pos (tsub_pos_of_lt h)
theorem tendsto_pow_atTop_nhds_zero_of_lt_one {𝕜 : Type*}
[Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [Archimedean 𝕜]
[TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} (h₁ : 0 ≤ r) (h₂ : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) :=
h₁.eq_or_lt.elim
(fun hr ↦ (tendsto_add_atTop_iff_nat 1).mp <| by
simp [_root_.pow_succ, ← hr, tendsto_const_nhds])
(fun hr ↦
have := (one_lt_inv₀ hr).2 h₂ |> tendsto_pow_atTop_atTop_of_one_lt
(tendsto_inv_atTop_zero.comp this).congr fun n ↦ by simp)
@[simp] theorem tendsto_pow_atTop_nhds_zero_iff {𝕜 : Type*}
[Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [Archimedean 𝕜]
[TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) ↔ |r| < 1 := by
rw [tendsto_zero_iff_abs_tendsto_zero]
refine ⟨fun h ↦ by_contra (fun hr_le ↦ ?_), fun h ↦ ?_⟩
· by_cases hr : 1 = |r|
· replace h : Tendsto (fun n : ℕ ↦ |r|^n) atTop (𝓝 0) := by simpa only [← abs_pow, h]
simp only [hr.symm, one_pow] at h
exact zero_ne_one <| tendsto_nhds_unique h tendsto_const_nhds
· apply @not_tendsto_nhds_of_tendsto_atTop 𝕜 ℕ _ _ _ _ atTop _ (fun n ↦ |r| ^ n) _ 0 _
· refine (pow_right_strictMono₀ <| lt_of_le_of_ne (le_of_not_lt hr_le)
hr).monotone.tendsto_atTop_atTop (fun b ↦ ?_)
obtain ⟨n, hn⟩ := (pow_unbounded_of_one_lt b (lt_of_le_of_ne (le_of_not_lt hr_le) hr))
exact ⟨n, le_of_lt hn⟩
· simpa only [← abs_pow]
· simpa only [← abs_pow] using (tendsto_pow_atTop_nhds_zero_of_lt_one (abs_nonneg r)) h
theorem tendsto_pow_atTop_nhdsWithin_zero_of_lt_one {𝕜 : Type*}
[Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜]
[Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} (h₁ : 0 < r) (h₂ : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝[>] 0) :=
tendsto_inf.2
⟨tendsto_pow_atTop_nhds_zero_of_lt_one h₁.le h₂,
tendsto_principal.2 <| Eventually.of_forall fun _ ↦ pow_pos h₁ _⟩
theorem uniformity_basis_dist_pow_of_lt_one {α : Type*} [PseudoMetricSpace α] {r : ℝ} (h₀ : 0 < r)
(h₁ : r < 1) :
(uniformity α).HasBasis (fun _ : ℕ ↦ True) fun k ↦ { p : α × α | dist p.1 p.2 < r ^ k } :=
Metric.mk_uniformity_basis (fun _ _ ↦ pow_pos h₀ _) fun _ ε0 ↦
(exists_pow_lt_of_lt_one ε0 h₁).imp fun _ hk ↦ ⟨trivial, hk.le⟩
theorem geom_lt {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n)
(h : ∀ k < n, c * u k < u (k + 1)) : c ^ n * u 0 < u n := by
apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn _ _ h
· simp
· simp [_root_.pow_succ', mul_assoc, le_refl]
theorem geom_le {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, c * u k ≤ u (k + 1)) :
c ^ n * u 0 ≤ u n := by
apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h <;>
simp [_root_.pow_succ', mul_assoc, le_refl]
theorem lt_geom {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n)
(h : ∀ k < n, u (k + 1) < c * u k) : u n < c ^ n * u 0 := by
apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_lt_of_le hn _ h _
· simp
· simp [_root_.pow_succ', mul_assoc, le_refl]
theorem le_geom {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, u (k + 1) ≤ c * u k) :
u n ≤ c ^ n * u 0 := by
apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ h _ <;>
simp [_root_.pow_succ', mul_assoc, le_refl]
/-- If a sequence `v` of real numbers satisfies `k * v n ≤ v (n+1)` with `1 < k`,
then it goes to +∞. -/
theorem tendsto_atTop_of_geom_le {v : ℕ → ℝ} {c : ℝ} (h₀ : 0 < v 0) (hc : 1 < c)
(hu : ∀ n, c * v n ≤ v (n + 1)) : Tendsto v atTop atTop :=
(tendsto_atTop_mono fun n ↦ geom_le (zero_le_one.trans hc.le) n fun k _ ↦ hu k) <|
(tendsto_pow_atTop_atTop_of_one_lt hc).atTop_mul_const h₀
theorem NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝ≥0} (hr : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) :=
NNReal.tendsto_coe.1 <| by
simp only [NNReal.coe_pow, NNReal.coe_zero,
_root_.tendsto_pow_atTop_nhds_zero_of_lt_one r.coe_nonneg hr]
@[simp]
protected theorem NNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝ≥0} :
Tendsto (fun n : ℕ => r ^ n) atTop (𝓝 0) ↔ r < 1 :=
⟨fun h => by simpa [coe_pow, coe_zero, abs_eq, coe_lt_one, val_eq_coe] using
tendsto_pow_atTop_nhds_zero_iff.mp <| tendsto_coe.mpr h, tendsto_pow_atTop_nhds_zero_of_lt_one⟩
theorem ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝ≥0∞} (hr : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) := by
rcases ENNReal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩
rw [← ENNReal.coe_zero]
norm_cast at *
apply NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one hr
@[simp]
protected theorem ENNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝ≥0∞} :
Tendsto (fun n : ℕ => r ^ n) atTop (𝓝 0) ↔ r < 1 := by
refine ⟨fun h ↦ ?_, tendsto_pow_atTop_nhds_zero_of_lt_one⟩
lift r to NNReal
· refine fun hr ↦ top_ne_zero (tendsto_nhds_unique (EventuallyEq.tendsto ?_) (hr ▸ h))
exact eventually_atTop.mpr ⟨1, fun _ hn ↦ pow_eq_top_iff.mpr ⟨rfl, Nat.pos_iff_ne_zero.mp hn⟩⟩
rw [← coe_zero] at h
norm_cast at h ⊢
exact NNReal.tendsto_pow_atTop_nhds_zero_iff.mp h
@[simp]
protected theorem ENNReal.tendsto_pow_atTop_nhds_top_iff {r : ℝ≥0∞} :
Tendsto (fun n ↦ r^n) atTop (𝓝 ∞) ↔ 1 < r := by
refine ⟨?_, ?_⟩
· contrapose!
intro r_le_one h_tends
specialize h_tends (Ioi_mem_nhds one_lt_top)
simp only [Filter.mem_map, mem_atTop_sets, ge_iff_le, Set.mem_preimage, Set.mem_Ioi] at h_tends
obtain ⟨n, hn⟩ := h_tends
exact lt_irrefl _ <| lt_of_lt_of_le (hn n le_rfl) <| pow_le_one₀ (zero_le _) r_le_one
· intro r_gt_one
have obs := @Tendsto.inv ℝ≥0∞ ℕ _ _ _ (fun n ↦ (r⁻¹)^n) atTop 0
simp only [ENNReal.tendsto_pow_atTop_nhds_zero_iff, inv_zero] at obs
simpa [← ENNReal.inv_pow] using obs <| ENNReal.inv_lt_one.mpr r_gt_one
lemma ENNReal.eq_zero_of_le_mul_pow {x r : ℝ≥0∞} {ε : ℝ≥0} (hr : r < 1)
(h : ∀ n : ℕ, x ≤ ε * r ^ n) : x = 0 := by
rw [← nonpos_iff_eq_zero]
refine ge_of_tendsto' (f := fun (n : ℕ) ↦ ε * r ^ n) (x := atTop) ?_ h
rw [← mul_zero (M₀ := ℝ≥0∞) (a := ε)]
exact Tendsto.const_mul (tendsto_pow_atTop_nhds_zero_of_lt_one hr) (Or.inr coe_ne_top)
/-! ### Geometric series -/
section Geometric
theorem hasSum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
HasSum (fun n : ℕ ↦ r ^ n) (1 - r)⁻¹ :=
have : r ≠ 1 := ne_of_lt h₂
have : Tendsto (fun n ↦ (r ^ n - 1) * (r - 1)⁻¹) atTop (𝓝 ((0 - 1) * (r - 1)⁻¹)) :=
((tendsto_pow_atTop_nhds_zero_of_lt_one h₁ h₂).sub tendsto_const_nhds).mul tendsto_const_nhds
(hasSum_iff_tendsto_nat_of_nonneg (pow_nonneg h₁) _).mpr <| by
simp_all [neg_inv, geom_sum_eq, div_eq_mul_inv]
theorem summable_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
Summable fun n : ℕ ↦ r ^ n :=
⟨_, hasSum_geometric_of_lt_one h₁ h₂⟩
theorem tsum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ :=
(hasSum_geometric_of_lt_one h₁ h₂).tsum_eq
theorem hasSum_geometric_two : HasSum (fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n) 2 := by
convert hasSum_geometric_of_lt_one _ _ <;> norm_num
theorem summable_geometric_two : Summable fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n :=
⟨_, hasSum_geometric_two⟩
theorem summable_geometric_two_encode {ι : Type*} [Encodable ι] :
Summable fun i : ι ↦ (1 / 2 : ℝ) ^ Encodable.encode i :=
summable_geometric_two.comp_injective Encodable.encode_injective
theorem tsum_geometric_two : (∑' n : ℕ, ((1 : ℝ) / 2) ^ n) = 2 :=
hasSum_geometric_two.tsum_eq
theorem sum_geometric_two_le (n : ℕ) : (∑ i ∈ range n, (1 / (2 : ℝ)) ^ i) ≤ 2 := by
have : ∀ i, 0 ≤ (1 / (2 : ℝ)) ^ i := by
intro i
apply pow_nonneg
norm_num
convert summable_geometric_two.sum_le_tsum (range n) (fun i _ ↦ this i)
exact tsum_geometric_two.symm
| Mathlib/Analysis/SpecificLimits/Basic.lean | 329 | 335 | theorem tsum_geometric_inv_two : (∑' n : ℕ, (2 : ℝ)⁻¹ ^ n) = 2 :=
(inv_eq_one_div (2 : ℝ)).symm ▸ tsum_geometric_two
/-- The sum of `2⁻¹ ^ i` for `n ≤ i` equals `2 * 2⁻¹ ^ n`. -/
theorem tsum_geometric_inv_two_ge (n : ℕ) :
(∑' i, ite (n ≤ i) ((2 : ℝ)⁻¹ ^ i) 0) = 2 * 2⁻¹ ^ n := by | have A : Summable fun i : ℕ ↦ ite (n ≤ i) ((2⁻¹ : ℝ) ^ i) 0 := by |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Finset.Card
import Mathlib.Data.Fintype.Basic
/-!
# Cardinalities of finite types
This file defines the cardinality `Fintype.card α` as the number of elements in `(univ : Finset α)`.
We also include some elementary results on the values of `Fintype.card` on specific types.
## Main declarations
* `Fintype.card α`: Cardinality of a fintype. Equal to `Finset.univ.card`.
* `Finite.surjective_of_injective`: an injective function from a finite type to
itself is also surjective.
-/
assert_not_exists Monoid
open Function
universe u v
variable {α β γ : Type*}
open Finset Function
namespace Fintype
/-- `card α` is the number of elements in `α`, defined when `α` is a fintype. -/
def card (α) [Fintype α] : ℕ :=
(@univ α _).card
theorem subtype_card {p : α → Prop} (s : Finset α) (H : ∀ x : α, x ∈ s ↔ p x) :
@card { x // p x } (Fintype.subtype s H) = #s :=
Multiset.card_pmap _ _ _
theorem card_of_subtype {p : α → Prop} (s : Finset α) (H : ∀ x : α, x ∈ s ↔ p x)
[Fintype { x // p x }] : card { x // p x } = #s := by
rw [← subtype_card s H]
congr!
@[simp]
theorem card_ofFinset {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) :
@Fintype.card p (ofFinset s H) = #s :=
Fintype.subtype_card s H
theorem card_of_finset' {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) [Fintype p] :
Fintype.card p = #s := by rw [← card_ofFinset s H]; congr!
end Fintype
namespace Fintype
theorem ofEquiv_card [Fintype α] (f : α ≃ β) : @card β (ofEquiv α f) = card α :=
Multiset.card_map _ _
theorem card_congr {α β} [Fintype α] [Fintype β] (f : α ≃ β) : card α = card β := by
rw [← ofEquiv_card f]; congr!
@[congr]
theorem card_congr' {α β} [Fintype α] [Fintype β] (h : α = β) : card α = card β :=
card_congr (by rw [h])
/-- Note: this lemma is specifically about `Fintype.ofSubsingleton`. For a statement about
arbitrary `Fintype` instances, use either `Fintype.card_le_one_iff_subsingleton` or
`Fintype.card_unique`. -/
theorem card_ofSubsingleton (a : α) [Subsingleton α] : @Fintype.card _ (ofSubsingleton a) = 1 :=
rfl
@[simp]
theorem card_unique [Unique α] [h : Fintype α] : Fintype.card α = 1 :=
Subsingleton.elim (ofSubsingleton default) h ▸ card_ofSubsingleton _
/-- Note: this lemma is specifically about `Fintype.ofIsEmpty`. For a statement about
arbitrary `Fintype` instances, use `Fintype.card_eq_zero`. -/
theorem card_ofIsEmpty [IsEmpty α] : @Fintype.card α Fintype.ofIsEmpty = 0 :=
rfl
end Fintype
namespace Set
variable {s t : Set α}
-- We use an arbitrary `[Fintype s]` instance here,
-- not necessarily coming from a `[Fintype α]`.
@[simp]
theorem toFinset_card {α : Type*} (s : Set α) [Fintype s] : s.toFinset.card = Fintype.card s :=
Multiset.card_map Subtype.val Finset.univ.val
end Set
@[simp]
theorem Finset.card_univ [Fintype α] : #(univ : Finset α) = Fintype.card α := rfl
theorem Finset.eq_univ_of_card [Fintype α] (s : Finset α) (hs : #s = Fintype.card α) :
s = univ :=
eq_of_subset_of_card_le (subset_univ _) <| by rw [hs, Finset.card_univ]
theorem Finset.card_eq_iff_eq_univ [Fintype α] (s : Finset α) : #s = Fintype.card α ↔ s = univ :=
⟨s.eq_univ_of_card, by
rintro rfl
exact Finset.card_univ⟩
theorem Finset.card_le_univ [Fintype α] (s : Finset α) : #s ≤ Fintype.card α :=
card_le_card (subset_univ s)
theorem Finset.card_lt_univ_of_not_mem [Fintype α] {s : Finset α} {x : α} (hx : x ∉ s) :
#s < Fintype.card α :=
card_lt_card ⟨subset_univ s, not_forall.2 ⟨x, fun hx' => hx (hx' <| mem_univ x)⟩⟩
theorem Finset.card_lt_iff_ne_univ [Fintype α] (s : Finset α) :
#s < Fintype.card α ↔ s ≠ Finset.univ :=
s.card_le_univ.lt_iff_ne.trans (not_congr s.card_eq_iff_eq_univ)
theorem Finset.card_compl_lt_iff_nonempty [Fintype α] [DecidableEq α] (s : Finset α) :
#sᶜ < Fintype.card α ↔ s.Nonempty :=
sᶜ.card_lt_iff_ne_univ.trans s.compl_ne_univ_iff_nonempty
theorem Finset.card_univ_diff [DecidableEq α] [Fintype α] (s : Finset α) :
#(univ \ s) = Fintype.card α - #s :=
Finset.card_sdiff (subset_univ s)
theorem Finset.card_compl [DecidableEq α] [Fintype α] (s : Finset α) : #sᶜ = Fintype.card α - #s :=
Finset.card_univ_diff s
@[simp]
theorem Finset.card_add_card_compl [DecidableEq α] [Fintype α] (s : Finset α) :
#s + #sᶜ = Fintype.card α := by
rw [Finset.card_compl, ← Nat.add_sub_assoc (card_le_univ s), Nat.add_sub_cancel_left]
@[simp]
theorem Finset.card_compl_add_card [DecidableEq α] [Fintype α] (s : Finset α) :
#sᶜ + #s = Fintype.card α := by
rw [Nat.add_comm, card_add_card_compl]
theorem Fintype.card_compl_set [Fintype α] (s : Set α) [Fintype s] [Fintype (↥sᶜ : Sort _)] :
Fintype.card (↥sᶜ : Sort _) = Fintype.card α - Fintype.card s := by
classical rw [← Set.toFinset_card, ← Set.toFinset_card, ← Finset.card_compl, Set.toFinset_compl]
theorem Fintype.card_subtype_eq (y : α) [Fintype { x // x = y }] :
Fintype.card { x // x = y } = 1 :=
Fintype.card_unique
theorem Fintype.card_subtype_eq' (y : α) [Fintype { x // y = x }] :
Fintype.card { x // y = x } = 1 :=
Fintype.card_unique
theorem Fintype.card_empty : Fintype.card Empty = 0 :=
rfl
theorem Fintype.card_pempty : Fintype.card PEmpty = 0 :=
rfl
theorem Fintype.card_unit : Fintype.card Unit = 1 :=
rfl
@[simp]
theorem Fintype.card_punit : Fintype.card PUnit = 1 :=
rfl
@[simp]
theorem Fintype.card_bool : Fintype.card Bool = 2 :=
rfl
@[simp]
theorem Fintype.card_ulift (α : Type*) [Fintype α] : Fintype.card (ULift α) = Fintype.card α :=
Fintype.ofEquiv_card _
@[simp]
theorem Fintype.card_plift (α : Type*) [Fintype α] : Fintype.card (PLift α) = Fintype.card α :=
Fintype.ofEquiv_card _
@[simp]
theorem Fintype.card_orderDual (α : Type*) [Fintype α] : Fintype.card αᵒᵈ = Fintype.card α :=
rfl
@[simp]
theorem Fintype.card_lex (α : Type*) [Fintype α] : Fintype.card (Lex α) = Fintype.card α :=
rfl
-- Note: The extra hypothesis `h` is there so that the rewrite lemma applies,
-- no matter what instance of `Fintype (Set.univ : Set α)` is used.
@[simp]
theorem Fintype.card_setUniv [Fintype α] {h : Fintype (Set.univ : Set α)} :
Fintype.card (Set.univ : Set α) = Fintype.card α := by
apply Fintype.card_of_finset'
simp
@[simp]
theorem Fintype.card_subtype_true [Fintype α] {h : Fintype {_a : α // True}} :
@Fintype.card {_a // True} h = Fintype.card α := by
apply Fintype.card_of_subtype
simp
/-- Given that `α ⊕ β` is a fintype, `α` is also a fintype. This is non-computable as it uses
that `Sum.inl` is an injection, but there's no clear inverse if `α` is empty. -/
noncomputable def Fintype.sumLeft {α β} [Fintype (α ⊕ β)] : Fintype α :=
Fintype.ofInjective (Sum.inl : α → α ⊕ β) Sum.inl_injective
/-- Given that `α ⊕ β` is a fintype, `β` is also a fintype. This is non-computable as it uses
that `Sum.inr` is an injection, but there's no clear inverse if `β` is empty. -/
noncomputable def Fintype.sumRight {α β} [Fintype (α ⊕ β)] : Fintype β :=
Fintype.ofInjective (Sum.inr : β → α ⊕ β) Sum.inr_injective
theorem Finite.exists_univ_list (α) [Finite α] : ∃ l : List α, l.Nodup ∧ ∀ x : α, x ∈ l := by
cases nonempty_fintype α
obtain ⟨l, e⟩ := Quotient.exists_rep (@univ α _).1
have := And.intro (@univ α _).2 (@mem_univ_val α _)
exact ⟨_, by rwa [← e] at this⟩
theorem List.Nodup.length_le_card {α : Type*} [Fintype α] {l : List α} (h : l.Nodup) :
l.length ≤ Fintype.card α := by
classical exact List.toFinset_card_of_nodup h ▸ l.toFinset.card_le_univ
namespace Fintype
variable [Fintype α] [Fintype β]
theorem card_le_of_injective (f : α → β) (hf : Function.Injective f) : card α ≤ card β :=
Finset.card_le_card_of_injOn f (fun _ _ => Finset.mem_univ _) fun _ _ _ _ h => hf h
theorem card_le_of_embedding (f : α ↪ β) : card α ≤ card β :=
card_le_of_injective f f.2
theorem card_lt_of_injective_of_not_mem (f : α → β) (h : Function.Injective f) {b : β}
(w : b ∉ Set.range f) : card α < card β :=
calc
card α = (univ.map ⟨f, h⟩).card := (card_map _).symm
_ < card β :=
Finset.card_lt_univ_of_not_mem (x := b) <| by
rwa [← mem_coe, coe_map, coe_univ, Set.image_univ]
theorem card_lt_of_injective_not_surjective (f : α → β) (h : Function.Injective f)
(h' : ¬Function.Surjective f) : card α < card β :=
let ⟨_y, hy⟩ := not_forall.1 h'
card_lt_of_injective_of_not_mem f h hy
theorem card_le_of_surjective (f : α → β) (h : Function.Surjective f) : card β ≤ card α :=
card_le_of_injective _ (Function.injective_surjInv h)
theorem card_range_le {α β : Type*} (f : α → β) [Fintype α] [Fintype (Set.range f)] :
Fintype.card (Set.range f) ≤ Fintype.card α :=
Fintype.card_le_of_surjective (fun a => ⟨f a, by simp⟩) fun ⟨_, a, ha⟩ => ⟨a, by simpa using ha⟩
theorem card_range {α β F : Type*} [FunLike F α β] [EmbeddingLike F α β] (f : F) [Fintype α]
[Fintype (Set.range f)] : Fintype.card (Set.range f) = Fintype.card α :=
Eq.symm <| Fintype.card_congr <| Equiv.ofInjective _ <| EmbeddingLike.injective f
theorem card_eq_zero_iff : card α = 0 ↔ IsEmpty α := by
rw [card, Finset.card_eq_zero, univ_eq_empty_iff]
@[simp] theorem card_eq_zero [IsEmpty α] : card α = 0 :=
card_eq_zero_iff.2 ‹_›
alias card_of_isEmpty := card_eq_zero
/-- A `Fintype` with cardinality zero is equivalent to `Empty`. -/
def cardEqZeroEquivEquivEmpty : card α = 0 ≃ (α ≃ Empty) :=
(Equiv.ofIff card_eq_zero_iff).trans (Equiv.equivEmptyEquiv α).symm
theorem card_pos_iff : 0 < card α ↔ Nonempty α :=
Nat.pos_iff_ne_zero.trans <| not_iff_comm.mp <| not_nonempty_iff.trans card_eq_zero_iff.symm
theorem card_pos [h : Nonempty α] : 0 < card α :=
card_pos_iff.mpr h
@[simp]
theorem card_ne_zero [Nonempty α] : card α ≠ 0 :=
_root_.ne_of_gt card_pos
instance [Nonempty α] : NeZero (card α) := ⟨card_ne_zero⟩
theorem existsUnique_iff_card_one {α} [Fintype α] (p : α → Prop) [DecidablePred p] :
(∃! a : α, p a) ↔ #{x | p x} = 1 := by
rw [Finset.card_eq_one]
refine exists_congr fun x => ?_
simp only [forall_true_left, Subset.antisymm_iff, subset_singleton_iff', singleton_subset_iff,
true_and, and_comm, mem_univ, mem_filter]
@[deprecated (since := "2024-12-17")] alias exists_unique_iff_card_one := existsUnique_iff_card_one
nonrec theorem two_lt_card_iff : 2 < card α ↔ ∃ a b c : α, a ≠ b ∧ a ≠ c ∧ b ≠ c := by
simp_rw [← Finset.card_univ, two_lt_card_iff, mem_univ, true_and]
theorem card_of_bijective {f : α → β} (hf : Bijective f) : card α = card β :=
card_congr (Equiv.ofBijective f hf)
end Fintype
namespace Finite
variable [Finite α]
| Mathlib/Data/Fintype/Card.lean | 301 | 303 | theorem surjective_of_injective {f : α → α} (hinj : Injective f) : Surjective f := by | intro x
have := Classical.propDecidable |
/-
Copyright (c) 2022 Bolton Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Data.Int.Log
/-!
# Real logarithm base `b`
In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We
define this as the division of the natural logarithms of the argument and the base, so that we have
a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and
`logb (-b) x = logb b x`.
We prove some basic properties of this function and its relation to `rpow`.
## Tags
logarithm, continuity
-/
open Set Filter Function
open Topology
noncomputable section
namespace Real
variable {b x y : ℝ}
/-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to
be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/
@[pp_nodot]
noncomputable def logb (b x : ℝ) : ℝ :=
log x / log b
theorem log_div_log : log x / log b = logb b x :=
rfl
@[simp]
theorem logb_zero : logb b 0 = 0 := by simp [logb]
@[simp]
| Mathlib/Analysis/SpecialFunctions/Log/Base.lean | 49 | 49 | theorem logb_one : logb b 1 = 0 := by | simp [logb] |
/-
Copyright (c) 2023 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.SetTheory.Cardinal.Finite
import Mathlib.Data.Set.Finite.Powerset
/-!
# Noncomputable Set Cardinality
We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`.
The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and
are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen
as an API for the same function in the special case where the type is a coercion of a `Set`,
allowing for smoother interactions with the `Set` API.
`Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even
though it takes values in a less convenient type. It is probably the right choice in settings where
one is concerned with the cardinalities of sets that may or may not be infinite.
`Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to
make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the
obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'.
When working with sets that are finite by virtue of their definition, then `Finset.card` probably
makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`,
where every set is automatically finite. In this setting, we use default arguments and a simple
tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems.
## Main Definitions
* `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if
`s` is infinite.
* `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite.
If `s` is Infinite, then `Set.ncard s = 0`.
* `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with
`Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance.
## Implementation Notes
The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations
instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the
`Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API
for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard`
in the future.
Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We
provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`,
where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite`
type.
Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other
in the context of the theorem, in which case we only include the ones that are needed, and derive
the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require
finiteness arguments; they are true by coincidence due to junk values.
-/
namespace Set
variable {α β : Type*} {s t : Set α}
/-- The cardinality of a set as a term in `ℕ∞` -/
noncomputable def encard (s : Set α) : ℕ∞ := ENat.card s
@[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by
rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)]
theorem encard_univ (α : Type*) :
encard (univ : Set α) = ENat.card α := by
rw [encard, ENat.card_congr (Equiv.Set.univ α)]
theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by
have := h.fintype
rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card]
theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by
have h := toFinite s
rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset]
@[simp] theorem toENat_cardinalMk (s : Set α) : (Cardinal.mk s).toENat = s.encard := rfl
theorem toENat_cardinalMk_subtype (P : α → Prop) :
(Cardinal.mk {x // P x}).toENat = {x | P x}.encard :=
rfl
@[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by
simp [encard_eq_coe_toFinset_card]
@[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) :
encard (s : Set α) = s.card := by
rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp
@[simp] theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
have := h.to_subtype
rw [encard, ENat.card_eq_top_of_infinite]
@[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by
rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem]
@[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by
rw [encard_eq_zero]
theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by
rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero]
theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty]
@[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, encard_ne_zero]
protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos
@[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by
rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
classical
simp [encard, ENat.card_congr (Equiv.Set.union h)]
theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
induction s, h using Set.Finite.induction_on with
| empty => simp
| insert hat _ ht' =>
rw [encard_insert_of_not_mem hat]
exact lt_tsub_iff_right.1 ht'
theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard :=
(ENat.coe_toNat h.encard_lt_top.ne).symm
theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n :=
⟨_, h.encard_eq_coe⟩
@[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite :=
⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩
@[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff
theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by
simp
theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _)
theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite :=
finite_of_encard_le_coe h.le
theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k :=
⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩,
fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩
@[simp]
theorem encard_prod : (s ×ˢ t).encard = s.encard * t.encard := by
simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)]
section Lattice
theorem encard_le_encard (h : s ⊆ t) : s.encard ≤ t.encard := by
rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
@[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard
theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) :=
fun _ _ ↦ encard_le_encard
theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h]
@[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero]
theorem encard_diff_add_encard_inter (s t : Set α) :
(s \ t).encard + (s ∩ t).encard = s.encard := by
rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left),
diff_union_inter]
theorem encard_union_add_encard_inter (s t : Set α) :
(s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by
rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm,
encard_diff_add_encard_inter]
theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) :
s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_right_inj h.encard_lt_top.ne]
theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) :
s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_le_add_iff_right h.encard_lt_top.ne]
theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) :
s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_lt_add_iff_right h.encard_lt_top.ne]
theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by
rw [← encard_union_add_encard_inter]; exact le_self_add
theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by
rw [← encard_lt_top_iff, ← encard_lt_top_iff, h]
theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) :
s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff]
theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite)
(h : t.encard ≤ s.encard) : t.Finite :=
encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top)
lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
s = t := by
rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts
rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff
exact hst.antisymm hdiff
theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s ⊆ t)
(hts : t.encard ≤ s.encard) : s = t :=
(hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts
theorem Finite.encard_lt_encard (hs : s.Finite) (h : s ⊂ t) : s.encard < t.encard :=
(encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le)
theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) :=
fun _ _ h ↦ (toFinite _).encard_lt_encard h
theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self]
theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard :=
(encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm
theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by
rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard
theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by
rw [← encard_union_eq disjoint_compl_right, union_compl_self]
end Lattice
section InsertErase
variable {a b : α}
theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
rw [← encard_singleton x]; exact encard_le_encard inter_subset_left
theorem encard_diff_singleton_add_one (h : a ∈ s) :
(s \ {a}).encard + 1 = s.encard := by
rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h]
theorem encard_diff_singleton_of_mem (h : a ∈ s) :
(s \ {a}).encard = s.encard - 1 := by
rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top,
tsub_add_cancel_of_le (self_le_add_left _ _)]
theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) :
s.encard - 1 ≤ (s \ {x}).encard := by
rw [← encard_singleton x]; apply tsub_encard_le_encard_diff
theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by
rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb]
simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true]
theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by
rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb]
theorem encard_eq_add_one_iff {k : ℕ∞} :
s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩
rw [← WithTop.add_right_inj WithTop.one_ne_top, ← h,
encard_diff_singleton_add_one ha]
rintro ⟨a, t, h, rfl, rfl⟩
rw [encard_insert_of_not_mem h]
/-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended
for well-founded induction on the value of `encard`. -/
theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) :
s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by
refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦
(s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq)))
rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)]
exact WithTop.add_lt_add_left hfin.diff.encard_lt_top.ne zero_lt_one
end InsertErase
section SmallSets
theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two,
WithTop.add_right_inj WithTop.one_ne_top, encard_singleton]
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le (by simpa) (by simp [h])).symm⟩
theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by
rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero,
encard_eq_one]
theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by
rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty]
refine ⟨fun h a b has hbs ↦ ?_,
fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩
obtain ⟨x, rfl⟩ := h ⟨_, has⟩
rw [(has : a = x), (hbs : b = x)]
theorem encard_le_one_iff_subsingleton : s.encard ≤ 1 ↔ s.Subsingleton := by
rw [encard_le_one_iff, Set.Subsingleton]
tauto
theorem one_lt_encard_iff_nontrivial : 1 < s.encard ↔ s.Nontrivial := by
rw [← not_iff_not, not_lt, Set.not_nontrivial_iff, ← encard_le_one_iff_subsingleton]
theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by
rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop
theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by
by_contra! h'
obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h
apply hne
rw [h' b hb, h' b' hb']
theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl),
← one_add_one_eq_two, WithTop.add_right_inj (WithTop.one_ne_top), encard_eq_one] at h
obtain ⟨y, h⟩ := h
refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩
rw [← h, insert_diff_singleton, insert_eq_of_mem hx]
theorem encard_eq_three {α : Type u_1} {s : Set α} :
encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩
· obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton,
encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1),
WithTop.add_right_inj WithTop.one_ne_top, encard_eq_two] at h
obtain ⟨y, z, hne, hs⟩ := h
refine ⟨x, y, z, ?_, ?_, hne, ?_⟩
· rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl
· rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl
rw [← hs, insert_diff_singleton, insert_eq_of_mem hx]
rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop
theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by
convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1
· rw [Finset.coe_range, Iio_def]
rw [Finset.card_range]
end SmallSets
theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t)
(hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by
rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_inj hs.encard_lt_top.ne,
encard_eq_one] at hst
obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union]
theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
revert hk
refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_
· obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
simp only [Nat.cast_succ] at *
have hne : t₀ ≠ s := by
rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩
simp only [top_le_iff, encard_eq_top_iff]
exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩
theorem exists_superset_subset_encard_eq {k : ℕ∞}
(hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
obtain (hs | hs) := eq_or_ne s.encard ⊤
· rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
obtain ⟨k, rfl⟩ := exists_add_of_le hsk
obtain ⟨k', hk'⟩ := exists_add_of_le hkt
have hk : k ≤ encard (t \ s) := by
rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt
exact WithTop.le_of_add_le_add_right hs hkt
obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk
refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩
rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)]
section Function
variable {s : Set α} {t : Set β} {f : α → β}
theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by
rw [encard, ENat.card_image_of_injOn h, encard]
theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by
rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, ENat.card_congr e]
theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) :
(f '' s).encard = s.encard :=
hf.injOn.encard_image
theorem _root_.Function.Embedding.encard_le (e : s ↪ t) : s.encard ≤ t.encard := by
rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image]
exact encard_mono (by simp)
theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by
obtain (h | h) := isEmpty_or_nonempty α
· rw [s.eq_empty_of_isEmpty]; simp
rw [← (f.invFunOn_injOn_image s).encard_image]
apply encard_le_encard
exact f.invFunOn_image_image_subset s
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
InjOn f s := by
obtain (h' | hne) := isEmpty_or_nonempty α
· rw [s.eq_empty_of_isEmpty]; simp
rw [← (f.invFunOn_injOn_image s).encard_image] at h
rw [injOn_iff_invFunOn_image_image_eq_self]
exact hs.eq_of_subset_of_encard_le' (f.invFunOn_image_image_subset s) h.symm.le
theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆ range f) :
(f ⁻¹' t).encard = t.encard := by
rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht]
lemma encard_preimage_of_bijective (hf : f.Bijective) (t : Set β) : (f ⁻¹' t).encard = t.encard :=
encard_preimage_of_injective_subset_range hf.injective (by simp [hf.surjective.range_eq])
theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) :
s.encard ≤ t.encard := by
rw [← f_inj.encard_image]; apply encard_le_encard; rintro _ ⟨x, hx, rfl⟩; exact hf hx
theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite)
(hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by
classical
obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt
· simp
· exact (encard_ne_top_iff.mpr hs h).elim
obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle)
have hle' : (s \ {a}).encard ≤ (t \ {b}).encard := by
rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top,
encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt]
obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le hs.diff hle'
simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s
use Function.update f₀ a b
rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)]
simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def,
mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp,
mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt]
refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩
· rintro x hx; split_ifs with h
· assumption
· exact (hf₀s x hx h).1
exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_of_ne])
termination_by encard s
theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) :
∃ (f : α → β), BijOn f s t := by
obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f
convert hinj.bijOn_image
rw [(hs.image f).eq_of_subset_of_encard_le (image_subset_iff.mpr hf)
(h.symm.trans hinj.encard_image.symm).le]
end Function
section ncard
open Nat
/-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite`
term. -/
syntax "toFinite_tac" : tactic
macro_rules
| `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite)
/-- A tactic useful for transferring proofs for `encard` to their corresponding `card` statements -/
syntax "to_encard_tac" : tactic
macro_rules
| `(tactic| to_encard_tac) => `(tactic|
simp only [← Nat.cast_le (α := ℕ∞), ← Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one])
/-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/
noncomputable def ncard (s : Set α) : ℕ := ENat.toNat s.encard
theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl
theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by
rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not]
lemma ncard_le_encard (s : Set α) : s.ncard ≤ s.encard := ENat.coe_toNat_le_self _
theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
obtain (h | h) := s.finite_or_infinite
· have := h.fintype
rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card,
toFinite_toFinset, toFinset_card, ENat.toNat_coe]
have := infinite_coe_iff.2 h
rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top]
theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) :
s.ncard = hs.toFinset.card := by
rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype,
@Finite.card_toFinset _ _ hs.fintype hs]
theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] :
s.ncard = s.toFinset.card := by
simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card]
lemma cast_ncard {s : Set α} (hs : s.Finite) :
(s.ncard : Cardinal) = Cardinal.mk s := @Nat.cast_card _ hs
theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by
rw [encard_le_coe_iff, and_congr_right_iff]
exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by rwa [ncard_def, hn₀, ENat.toNat_coe],
fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩
theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by
rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype]
@[gcongr]
theorem ncard_le_ncard (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
s.ncard ≤ t.ncard := by
rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq]
exact encard_mono hst
theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ ncard_le_ncard
@[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) :
s.ncard = 0 ↔ s = ∅ := by
rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero]
@[simp, norm_cast] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by
rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset]
theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
rcases finite_or_infinite α with h | h
· have hft := Fintype.ofFinite α
rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card]
rw [Nat.card_eq_zero_of_infinite, Infinite.ncard]
exact infinite_univ
@[simp] theorem ncard_empty (α : Type*) : (∅ : Set α).ncard = 0 := by
rw [ncard_eq_zero]
theorem ncard_pos (hs : s.Finite := by toFinite_tac) : 0 < s.ncard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, Ne, ncard_eq_zero hs, nonempty_iff_ne_empty]
protected alias ⟨_, Nonempty.ncard_pos⟩ := ncard_pos
theorem ncard_ne_zero_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : s.ncard ≠ 0 :=
((ncard_pos hs).mpr ⟨a, h⟩).ne.symm
theorem finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite :=
s.finite_or_infinite.elim id fun h ↦ (hs h.ncard).elim
theorem finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite :=
finite_of_ncard_ne_zero hs.ne.symm
theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by
rw [nonempty_iff_ne_empty]; rintro rfl; simp at hs
@[simp] theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by
simp [ncard]
theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by
rw [← Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one]
apply encard_singleton_inter
@[simp]
theorem ncard_prod : (s ×ˢ t).ncard = s.ncard * t.ncard := by
simp [ncard, ENat.toNat_mul]
@[simp]
theorem ncard_powerset (s : Set α) (hs : s.Finite := by toFinite_tac) :
(𝒫 s).ncard = 2 ^ s.ncard := by
have h := Cardinal.mk_powerset s
rw [← cast_ncard hs.powerset, ← cast_ncard hs] at h
norm_cast at h
section InsertErase
@[simp] theorem ncard_insert_of_not_mem {a : α} (h : a ∉ s) (hs : s.Finite := by toFinite_tac) :
(insert a s).ncard = s.ncard + 1 := by
rw [← Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one,
hs.cast_ncard_eq, encard_insert_of_not_mem h]
theorem ncard_insert_of_mem {a : α} (h : a ∈ s) : ncard (insert a s) = s.ncard := by
rw [insert_eq_of_mem h]
theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by
obtain hs | hs := s.finite_or_infinite
· to_encard_tac; rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]; apply encard_insert_le
rw [(hs.mono (subset_insert a s)).ncard]
exact Nat.zero_le _
theorem ncard_insert_eq_ite {a : α} [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) :
ncard (insert a s) = if a ∈ s then s.ncard else s.ncard + 1 := by
by_cases h : a ∈ s
· rw [ncard_insert_of_mem h, if_pos h]
· rw [ncard_insert_of_not_mem h hs, if_neg h]
theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by
classical
refine
s.finite_or_infinite.elim (fun h ↦ ?_) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _))
rw [ncard_insert_eq_ite h]; split_ifs <;> simp
@[simp] theorem ncard_pair {a b : α} (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by
rw [ncard_insert_of_not_mem, ncard_singleton]; simpa
@[simp] theorem ncard_diff_singleton_add_one {a : α} (h : a ∈ s)
(hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard + 1 = s.ncard := by
to_encard_tac; rw [hs.cast_ncard_eq, hs.diff.cast_ncard_eq,
encard_diff_singleton_add_one h]
@[simp] theorem ncard_diff_singleton_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
(s \ {a}).ncard = s.ncard - 1 :=
eq_tsub_of_add_eq (ncard_diff_singleton_add_one h hs)
theorem ncard_diff_singleton_lt_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) :
(s \ {a}).ncard < s.ncard := by
rw [← ncard_diff_singleton_add_one h hs]; apply lt_add_one
theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by
obtain hs | hs := s.finite_or_infinite
· apply ncard_le_ncard diff_subset hs
convert zero_le (α := ℕ) _
exact (hs.diff (by simp : Set.Finite {a})).ncard
theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by
rcases s.finite_or_infinite with hs | hs
· by_cases h : a ∈ s
· rw [ncard_diff_singleton_of_mem h hs]
rw [diff_singleton_eq_self h]
apply Nat.pred_le
convert Nat.zero_le _
rw [hs.ncard]
theorem ncard_exchange {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard :=
congr_arg ENat.toNat <| encard_exchange ha hb
theorem ncard_exchange' {a b : α} (ha : a ∉ s) (hb : b ∈ s) :
(insert a s \ {b}).ncard = s.ncard := by
rw [← ncard_exchange ha hb, ← singleton_union, ← singleton_union, union_diff_distrib,
@diff_singleton_eq_self _ b {a} fun h ↦ ha (by rwa [← mem_singleton_iff.mp h])]
lemma odd_card_insert_iff {a : α} (ha : a ∉ s) (hs : s.Finite := by toFinite_tac) :
Odd (insert a s).ncard ↔ Even s.ncard := by
rw [ncard_insert_of_not_mem ha hs, Nat.odd_add]
simp only [Nat.odd_add, ← Nat.not_even_iff_odd, Nat.not_even_one, iff_false, Decidable.not_not]
lemma even_card_insert_iff {a : α} (ha : a ∉ s) (hs : s.Finite := by toFinite_tac) :
Even (insert a s).ncard ↔ Odd s.ncard := by
rw [ncard_insert_of_not_mem ha hs, Nat.even_add_one, Nat.not_even_iff_odd]
end InsertErase
variable {f : α → β}
theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by
to_encard_tac; rw [hs.cast_ncard_eq, (hs.image _).cast_ncard_eq]; apply encard_image_le
theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard :=
congr_arg ENat.toNat <| H.encard_image
theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard) (hs : s.Finite := by toFinite_tac) :
Set.InjOn f s := by
rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, (hs.image _).cast_ncard_eq] at h
exact hs.injOn_of_encard_image_eq h
theorem ncard_image_iff (hs : s.Finite := by toFinite_tac) :
(f '' s).ncard = s.ncard ↔ Set.InjOn f s :=
⟨fun h ↦ injOn_of_ncard_image_eq h hs, ncard_image_of_injOn⟩
theorem ncard_image_of_injective (s : Set α) (H : f.Injective) : (f '' s).ncard = s.ncard :=
ncard_image_of_injOn fun _ _ _ _ h ↦ H h
theorem ncard_preimage_of_injective_subset_range {s : Set β} (H : f.Injective)
(hs : s ⊆ Set.range f) :
(f ⁻¹' s).ncard = s.ncard := by
rw [← ncard_image_of_injective _ H, image_preimage_eq_iff.mpr hs]
theorem fiber_ncard_ne_zero_iff_mem_image {y : β} (hs : s.Finite := by toFinite_tac) :
{ x ∈ s | f x = y }.ncard ≠ 0 ↔ y ∈ f '' s := by
refine ⟨nonempty_of_ncard_ne_zero, ?_⟩
rintro ⟨z, hz, rfl⟩
exact @ncard_ne_zero_of_mem _ ({ x ∈ s | f x = f z }) z (mem_sep hz rfl)
(hs.subset (sep_subset _ _))
@[simp] theorem ncard_map (f : α ↪ β) : (f '' s).ncard = s.ncard :=
ncard_image_of_injective _ f.inj'
@[simp] theorem ncard_subtype (P : α → Prop) (s : Set α) :
{ x : Subtype P | (x : α) ∈ s }.ncard = (s ∩ setOf P).ncard := by
convert (ncard_image_of_injective _ (@Subtype.coe_injective _ P)).symm
ext x
simp [← and_assoc, exists_eq_right]
theorem ncard_inter_le_ncard_left (s t : Set α) (hs : s.Finite := by toFinite_tac) :
(s ∩ t).ncard ≤ s.ncard :=
ncard_le_ncard inter_subset_left hs
theorem ncard_inter_le_ncard_right (s t : Set α) (ht : t.Finite := by toFinite_tac) :
(s ∩ t).ncard ≤ t.ncard :=
ncard_le_ncard inter_subset_right ht
theorem eq_of_subset_of_ncard_le (h : s ⊆ t) (h' : t.ncard ≤ s.ncard)
(ht : t.Finite := by toFinite_tac) : s = t :=
ht.eq_of_subset_of_encard_le' h
(by rwa [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq] at h')
theorem subset_iff_eq_of_ncard_le (h : t.ncard ≤ s.ncard) (ht : t.Finite := by toFinite_tac) :
s ⊆ t ↔ s = t :=
⟨fun hst ↦ eq_of_subset_of_ncard_le hst h ht, Eq.subset'⟩
theorem map_eq_of_subset {f : α ↪ α} (h : f '' s ⊆ s) (hs : s.Finite := by toFinite_tac) :
f '' s = s :=
eq_of_subset_of_ncard_le h (ncard_map _).ge hs
theorem sep_of_ncard_eq {a : α} {P : α → Prop} (h : { x ∈ s | P x }.ncard = s.ncard) (ha : a ∈ s)
(hs : s.Finite := by toFinite_tac) : P a :=
sep_eq_self_iff_mem_true.mp (eq_of_subset_of_ncard_le (by simp) h.symm.le hs) _ ha
theorem ncard_lt_ncard (h : s ⊂ t) (ht : t.Finite := by toFinite_tac) :
s.ncard < t.ncard := by
rw [← Nat.cast_lt (α := ℕ∞), ht.cast_ncard_eq, (ht.subset h.subset).cast_ncard_eq]
exact (ht.subset h.subset).encard_lt_encard h
theorem ncard_strictMono [Finite α] : @StrictMono (Set α) _ _ _ ncard :=
fun _ _ h ↦ ncard_lt_ncard h
theorem ncard_eq_of_bijective {n : ℕ} (f : ∀ i, i < n → α)
(hf : ∀ a ∈ s, ∃ i, ∃ h : i < n, f i h = a) (hf' : ∀ (i) (h : i < n), f i h ∈ s)
(f_inj : ∀ (i j) (hi : i < n) (hj : j < n), f i hi = f j hj → i = j) : s.ncard = n := by
let f' : Fin n → α := fun i ↦ f i.val i.is_lt
suffices himage : s = f' '' Set.univ by
rw [← Fintype.card_fin n, ← Nat.card_eq_fintype_card, ← Set.ncard_univ, himage]
exact ncard_image_of_injOn <| fun i _hi j _hj h ↦ Fin.ext <| f_inj i.val j.val i.is_lt j.is_lt h
ext x
simp only [image_univ, mem_range]
refine ⟨fun hx ↦ ?_, fun ⟨⟨i, hi⟩, hx⟩ ↦ hx ▸ hf' i hi⟩
obtain ⟨i, hi, rfl⟩ := hf x hx
use ⟨i, hi⟩
theorem ncard_congr {t : Set β} (f : ∀ a ∈ s, β) (h₁ : ∀ a ha, f a ha ∈ t)
(h₂ : ∀ a b ha hb, f a ha = f b hb → a = b) (h₃ : ∀ b ∈ t, ∃ a ha, f a ha = b) :
s.ncard = t.ncard := by
set f' : s → t := fun x ↦ ⟨f x.1 x.2, h₁ _ _⟩
have hbij : f'.Bijective := by
constructor
· rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy
simp only [f', Subtype.mk.injEq] at hxy ⊢
exact h₂ _ _ hx hy hxy
rintro ⟨y, hy⟩
obtain ⟨a, ha, rfl⟩ := h₃ y hy
simp only [Subtype.mk.injEq, Subtype.exists]
exact ⟨_, ha, rfl⟩
simp_rw [← Nat.card_coe_set_eq]
exact Nat.card_congr (Equiv.ofBijective f' hbij)
theorem ncard_le_ncard_of_injOn {t : Set β} (f : α → β) (hf : ∀ a ∈ s, f a ∈ t) (f_inj : InjOn f s)
(ht : t.Finite := by toFinite_tac) :
s.ncard ≤ t.ncard := by
have hle := encard_le_encard_of_injOn hf f_inj
to_encard_tac; rwa [ht.cast_ncard_eq, (ht.finite_of_encard_le hle).cast_ncard_eq]
theorem exists_ne_map_eq_of_ncard_lt_of_maps_to {t : Set β} (hc : t.ncard < s.ncard) {f : α → β}
(hf : ∀ a ∈ s, f a ∈ t) (ht : t.Finite := by toFinite_tac) :
∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ f x = f y := by
by_contra h'
simp only [Ne, exists_prop, not_exists, not_and, not_imp_not] at h'
exact (ncard_le_ncard_of_injOn f hf h' ht).not_lt hc
theorem le_ncard_of_inj_on_range {n : ℕ} (f : ℕ → α) (hf : ∀ i < n, f i ∈ s)
(f_inj : ∀ i < n, ∀ j < n, f i = f j → i = j) (hs : s.Finite := by toFinite_tac) :
n ≤ s.ncard := by
rw [ncard_eq_toFinset_card _ hs]
apply Finset.le_card_of_inj_on_range <;> simpa
theorem surj_on_of_inj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
(hinj : ∀ a₁ a₂ ha₁ ha₂, f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂) (hst : t.ncard ≤ s.ncard)
(ht : t.Finite := by toFinite_tac) :
∀ b ∈ t, ∃ a ha, b = f a ha := by
intro b hb
set f' : s → t := fun x ↦ ⟨f x.1 x.2, hf _ _⟩
have finj : f'.Injective := by
rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy
simp only [f', Subtype.mk.injEq] at hxy ⊢
apply hinj _ _ hx hy hxy
have hft := ht.fintype
have hft' := Fintype.ofInjective f' finj
set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h)
convert @Finset.surj_on_of_inj_on_of_card_le _ _ _ t.toFinset f'' _ _ _ _ (by simpa) using 1
· simp [f'']
· simp [f'', hf]
· intros a₁ a₂ ha₁ ha₂ h
rw [mem_toFinset] at ha₁ ha₂
exact hinj _ _ ha₁ ha₂ h
rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card']
theorem inj_on_of_surj_on_of_ncard_le {t : Set β} (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
(hsurj : ∀ b ∈ t, ∃ a ha, f a ha = b) (hst : s.ncard ≤ t.ncard) ⦃a₁⦄ (ha₁ : a₁ ∈ s) ⦃a₂⦄
(ha₂ : a₂ ∈ s) (ha₁a₂ : f a₁ ha₁ = f a₂ ha₂) (hs : s.Finite := by toFinite_tac) :
a₁ = a₂ := by
classical
set f' : s → t := fun x ↦ ⟨f x.1 x.2, hf _ _⟩
have hsurj : f'.Surjective := by
rintro ⟨y, hy⟩
obtain ⟨a, ha, rfl⟩ := hsurj y hy
simp only [Subtype.mk.injEq, Subtype.exists]
exact ⟨_, ha, rfl⟩
haveI := hs.fintype
haveI := Fintype.ofSurjective _ hsurj
set f'' : ∀ a, a ∈ s.toFinset → β := fun a h ↦ f a (by simpa using h)
exact
@Finset.inj_on_of_surj_on_of_card_le _ _ _ t.toFinset f''
(fun a ha ↦ by { rw [mem_toFinset] at ha ⊢; exact hf a ha }) (by simpa)
(by { rwa [← ncard_eq_toFinset_card', ← ncard_eq_toFinset_card'] }) a₁
(by simpa) a₂ (by simpa) (by simpa)
@[simp] theorem ncard_coe {α : Type*} (s : Set α) :
Set.ncard (Set.univ : Set (Set.Elem s)) = s.ncard :=
Set.ncard_congr (fun a ha ↦ ↑a) (fun a ha ↦ a.prop) (by simp) (by simp)
@[simp] lemma ncard_graphOn (s : Set α) (f : α → β) : (s.graphOn f).ncard = s.ncard := by
rw [← ncard_image_of_injOn fst_injOn_graph, image_fst_graphOn]
section Lattice
theorem ncard_union_add_ncard_inter (s t : Set α) (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) : (s ∪ t).ncard + (s ∩ t).ncard = s.ncard + t.ncard := by
to_encard_tac; rw [hs.cast_ncard_eq, ht.cast_ncard_eq, (hs.union ht).cast_ncard_eq,
(hs.subset inter_subset_left).cast_ncard_eq, encard_union_add_encard_inter]
theorem ncard_inter_add_ncard_union (s t : Set α) (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) : (s ∩ t).ncard + (s ∪ t).ncard = s.ncard + t.ncard := by
rw [add_comm, ncard_union_add_ncard_inter _ _ hs ht]
theorem ncard_union_le (s t : Set α) : (s ∪ t).ncard ≤ s.ncard + t.ncard := by
obtain (h | h) := (s ∪ t).finite_or_infinite
· to_encard_tac
rw [h.cast_ncard_eq, (h.subset subset_union_left).cast_ncard_eq,
(h.subset subset_union_right).cast_ncard_eq]
apply encard_union_le
rw [h.ncard]
apply zero_le
theorem ncard_union_eq (h : Disjoint s t) (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) : (s ∪ t).ncard = s.ncard + t.ncard := by
to_encard_tac
rw [hs.cast_ncard_eq, ht.cast_ncard_eq, (hs.union ht).cast_ncard_eq, encard_union_eq h]
theorem ncard_diff_add_ncard_of_subset (h : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
(t \ s).ncard + s.ncard = t.ncard := by
to_encard_tac
rw [ht.cast_ncard_eq, (ht.subset h).cast_ncard_eq, ht.diff.cast_ncard_eq,
encard_diff_add_encard_of_subset h]
theorem ncard_diff (hst : s ⊆ t) (hs : s.Finite := by toFinite_tac) :
(t \ s).ncard = t.ncard - s.ncard := by
obtain ht | ht := t.finite_or_infinite
· rw [← ncard_diff_add_ncard_of_subset hst ht, add_tsub_cancel_right]
· rw [ht.ncard, Nat.zero_sub, (ht.diff hs).ncard]
lemma cast_ncard_sdiff {R : Type*} [AddGroupWithOne R] (hst : s ⊆ t) (ht : t.Finite) :
((t \ s).ncard : R) = t.ncard - s.ncard := by
rw [ncard_diff hst (ht.subset hst), Nat.cast_sub (ncard_le_ncard hst ht)]
theorem ncard_le_ncard_diff_add_ncard (s t : Set α) (ht : t.Finite := by toFinite_tac) :
s.ncard ≤ (s \ t).ncard + t.ncard := by
rcases s.finite_or_infinite with hs | hs
· to_encard_tac
rw [ht.cast_ncard_eq, hs.cast_ncard_eq, hs.diff.cast_ncard_eq]
apply encard_le_encard_diff_add_encard
convert Nat.zero_le _
rw [hs.ncard]
theorem le_ncard_diff (s t : Set α) (hs : s.Finite := by toFinite_tac) :
t.ncard - s.ncard ≤ (t \ s).ncard :=
tsub_le_iff_left.mpr (by rw [add_comm]; apply ncard_le_ncard_diff_add_ncard _ _ hs)
theorem ncard_diff_add_ncard (s t : Set α) (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) :
(s \ t).ncard + t.ncard = (s ∪ t).ncard := by
rw [← ncard_union_eq disjoint_sdiff_left hs.diff ht, diff_union_self]
theorem diff_nonempty_of_ncard_lt_ncard (h : s.ncard < t.ncard) (hs : s.Finite := by toFinite_tac) :
(t \ s).Nonempty := by
rw [Set.nonempty_iff_ne_empty, Ne, diff_eq_empty]
exact fun h' ↦ h.not_le (ncard_le_ncard h' hs)
theorem exists_mem_not_mem_of_ncard_lt_ncard (h : s.ncard < t.ncard)
(hs : s.Finite := by toFinite_tac) : ∃ e, e ∈ t ∧ e ∉ s :=
diff_nonempty_of_ncard_lt_ncard h hs
@[simp] theorem ncard_inter_add_ncard_diff_eq_ncard (s t : Set α)
(hs : s.Finite := by toFinite_tac) : (s ∩ t).ncard + (s \ t).ncard = s.ncard := by
rw [← ncard_union_eq (disjoint_of_subset_left inter_subset_right disjoint_sdiff_right)
(hs.inter_of_left _) hs.diff, union_comm, diff_union_inter]
theorem ncard_eq_ncard_iff_ncard_diff_eq_ncard_diff (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) : s.ncard = t.ncard ↔ (s \ t).ncard = (t \ s).ncard := by
rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht,
inter_comm, add_right_inj]
theorem ncard_le_ncard_iff_ncard_diff_le_ncard_diff (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) : s.ncard ≤ t.ncard ↔ (s \ t).ncard ≤ (t \ s).ncard := by
rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht,
inter_comm, add_le_add_iff_left]
theorem ncard_lt_ncard_iff_ncard_diff_lt_ncard_diff (hs : s.Finite := by toFinite_tac)
(ht : t.Finite := by toFinite_tac) : s.ncard < t.ncard ↔ (s \ t).ncard < (t \ s).ncard := by
rw [← ncard_inter_add_ncard_diff_eq_ncard s t hs, ← ncard_inter_add_ncard_diff_eq_ncard t s ht,
inter_comm, add_lt_add_iff_left]
theorem ncard_add_ncard_compl (s : Set α) (hs : s.Finite := by toFinite_tac)
(hsc : sᶜ.Finite := by toFinite_tac) : s.ncard + sᶜ.ncard = Nat.card α := by
rw [← ncard_univ, ← ncard_union_eq (@disjoint_compl_right _ _ s) hs hsc, union_compl_self]
theorem eq_univ_iff_ncard [Finite α] (s : Set α) :
s = univ ↔ ncard s = Nat.card α := by
rw [← compl_empty_iff, ← ncard_eq_zero, ← ncard_add_ncard_compl s, left_eq_add]
lemma even_ncard_compl_iff [Finite α] (heven : Even (Nat.card α)) (s : Set α) :
Even sᶜ.ncard ↔ Even s.ncard := by
simp [compl_eq_univ_diff, ncard_diff (subset_univ _ : s ⊆ Set.univ),
Nat.even_sub (ncard_le_ncard (subset_univ _ : s ⊆ Set.univ)),
(ncard_univ _).symm ▸ heven]
lemma odd_ncard_compl_iff [Finite α] (heven : Even (Nat.card α)) (s : Set α) :
Odd sᶜ.ncard ↔ Odd s.ncard := by
rw [← Nat.not_even_iff_odd, even_ncard_compl_iff heven, Nat.not_even_iff_odd]
end Lattice
/-- Given a subset `s` of a set `t`, of sizes at most and at least `n` respectively, there exists a
set `u` of size `n` which is both a superset of `s` and a subset of `t`. -/
lemma exists_subsuperset_card_eq {n : ℕ} (hst : s ⊆ t) (hsn : s.ncard ≤ n) (hnt : n ≤ t.ncard) :
∃ u, s ⊆ u ∧ u ⊆ t ∧ u.ncard = n := by
obtain ht | ht := t.infinite_or_finite
· rw [ht.ncard, Nat.le_zero, ← ht.ncard] at hnt
exact ⟨t, hst, Subset.rfl, hnt.symm⟩
lift s to Finset α using ht.subset hst
lift t to Finset α using ht
obtain ⟨u, hsu, hut, hu⟩ := Finset.exists_subsuperset_card_eq (mod_cast hst) (by simpa using hsn)
(mod_cast hnt)
exact ⟨u, mod_cast hsu, mod_cast hut, mod_cast hu⟩
/-- We can shrink a set to any smaller size. -/
lemma exists_subset_card_eq {n : ℕ} (hns : n ≤ s.ncard) : ∃ t ⊆ s, t.ncard = n := by
simpa using exists_subsuperset_card_eq s.empty_subset (by simp) hns
theorem Infinite.exists_subset_ncard_eq {s : Set α} (hs : s.Infinite) (k : ℕ) :
∃ t, t ⊆ s ∧ t.Finite ∧ t.ncard = k := by
have := hs.to_subtype
obtain ⟨t', -, rfl⟩ := @Infinite.exists_subset_card_eq s univ infinite_univ k
refine ⟨Subtype.val '' (t' : Set s), by simp, Finite.image _ (by simp), ?_⟩
rw [ncard_image_of_injective _ Subtype.coe_injective]
simp
theorem Infinite.exists_superset_ncard_eq {s t : Set α} (ht : t.Infinite) (hst : s ⊆ t)
(hs : s.Finite) {k : ℕ} (hsk : s.ncard ≤ k) : ∃ s', s ⊆ s' ∧ s' ⊆ t ∧ s'.ncard = k := by
obtain ⟨s₁, hs₁, hs₁fin, hs₁card⟩ := (ht.diff hs).exists_subset_ncard_eq (k - s.ncard)
refine ⟨s ∪ s₁, subset_union_left, union_subset hst (hs₁.trans diff_subset), ?_⟩
rwa [ncard_union_eq (disjoint_of_subset_right hs₁ disjoint_sdiff_right) hs hs₁fin, hs₁card,
add_tsub_cancel_of_le]
theorem exists_subset_or_subset_of_two_mul_lt_ncard {n : ℕ} (hst : 2 * n < (s ∪ t).ncard) :
∃ r : Set α, n < r.ncard ∧ (r ⊆ s ∨ r ⊆ t) := by
classical
have hu := finite_of_ncard_ne_zero ((Nat.zero_le _).trans_lt hst).ne.symm
rw [ncard_eq_toFinset_card _ hu,
Finite.toFinset_union (hu.subset subset_union_left)
(hu.subset subset_union_right)] at hst
obtain ⟨r', hnr', hr'⟩ := Finset.exists_subset_or_subset_of_two_mul_lt_card hst
exact ⟨r', by simpa, by simpa using hr'⟩
/-! ### Explicit description of a set from its cardinality -/
@[simp] theorem ncard_eq_one : s.ncard = 1 ↔ ∃ a, s = {a} := by
refine ⟨fun h ↦ ?_, by rintro ⟨a, rfl⟩; rw [ncard_singleton]⟩
have hft := (finite_of_ncard_ne_zero (ne_zero_of_eq_one h)).fintype
simp_rw [ncard_eq_toFinset_card', @Finset.card_eq_one _ (toFinset s)] at h
refine h.imp fun a ha ↦ ?_
simp_rw [Set.ext_iff, mem_singleton_iff]
simp only [Finset.ext_iff, mem_toFinset, Finset.mem_singleton] at ha
exact ha
theorem exists_eq_insert_iff_ncard (hs : s.Finite := by toFinite_tac) :
(∃ a ∉ s, insert a s = t) ↔ s ⊆ t ∧ s.ncard + 1 = t.ncard := by
classical
rcases t.finite_or_infinite with ht | ht
· rw [ncard_eq_toFinset_card _ hs, ncard_eq_toFinset_card _ ht,
← @Finite.toFinset_subset_toFinset _ _ _ hs ht, ← Finset.exists_eq_insert_iff]
convert Iff.rfl using 2; simp only [Finite.mem_toFinset]
ext x
simp [Finset.ext_iff, Set.ext_iff]
simp only [ht.ncard, exists_prop, add_eq_zero, and_false, iff_false, not_exists, not_and,
reduceCtorEq]
rintro x - rfl
exact ht (hs.insert x)
theorem ncard_le_one (hs : s.Finite := by toFinite_tac) :
s.ncard ≤ 1 ↔ ∀ a ∈ s, ∀ b ∈ s, a = b := by
simp_rw [ncard_eq_toFinset_card _ hs, Finset.card_le_one, Finite.mem_toFinset]
@[simp] theorem ncard_le_one_iff_subsingleton [Finite s] :
s.ncard ≤ 1 ↔ s.Subsingleton :=
ncard_le_one <| inferInstanceAs (Finite s)
theorem ncard_le_one_iff (hs : s.Finite := by toFinite_tac) :
s.ncard ≤ 1 ↔ ∀ {a b}, a ∈ s → b ∈ s → a = b := by
rw [ncard_le_one hs]
tauto
theorem ncard_le_one_iff_eq (hs : s.Finite := by toFinite_tac) :
s.ncard ≤ 1 ↔ s = ∅ ∨ ∃ a, s = {a} := by
obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty
· exact iff_of_true (by simp) (Or.inl rfl)
rw [ncard_le_one_iff hs]
refine ⟨fun h ↦ Or.inr ⟨x, (singleton_subset_iff.mpr hx).antisymm' fun y hy ↦ h hy hx⟩, ?_⟩
rintro (rfl | ⟨a, rfl⟩)
· exact (not_mem_empty _ hx).elim
simp_rw [mem_singleton_iff] at hx ⊢; subst hx
simp only [forall_eq_apply_imp_iff, imp_self, implies_true]
| Mathlib/Data/Set/Card.lean | 1,042 | 1,051 | theorem ncard_le_one_iff_subset_singleton [Nonempty α]
(hs : s.Finite := by | toFinite_tac) :
s.ncard ≤ 1 ↔ ∃ x : α, s ⊆ {x} := by
simp_rw [ncard_eq_toFinset_card _ hs, Finset.card_le_one_iff_subset_singleton,
Finite.toFinset_subset, Finset.coe_singleton]
/-- A `Set` of a subsingleton type has cardinality at most one. -/
theorem ncard_le_one_of_subsingleton [Subsingleton α] (s : Set α) : s.ncard ≤ 1 := by
rw [ncard_eq_toFinset_card]
exact Finset.card_le_one_of_subsingleton _ |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Pi
import Mathlib.MeasureTheory.Constructions.BorelSpace.Order
/-!
# Simple functions
A function `f` from a measurable space to any type is called *simple*, if every preimage `f ⁻¹' {x}`
is measurable, and the range is finite. In this file, we define simple functions and establish their
basic properties; and we construct a sequence of simple functions approximating an arbitrary Borel
measurable function `f : α → ℝ≥0∞`.
The theorem `Measurable.ennreal_induction` shows that in order to prove something for an arbitrary
measurable function into `ℝ≥0∞`, it is sufficient to show that the property holds for (multiples of)
characteristic functions and is closed under addition and supremum of increasing sequences of
functions.
-/
noncomputable section
open Set hiding restrict restrict_apply
open Filter ENNReal
open Function (support)
open Topology NNReal ENNReal MeasureTheory
namespace MeasureTheory
variable {α β γ δ : Type*}
/-- A function `f` from a measurable space to any type is called *simple*,
if every preimage `f ⁻¹' {x}` is measurable, and the range is finite. This structure bundles
a function with these properties. -/
structure SimpleFunc.{u, v} (α : Type u) [MeasurableSpace α] (β : Type v) where
/-- The underlying function -/
toFun : α → β
measurableSet_fiber' : ∀ x, MeasurableSet (toFun ⁻¹' {x})
finite_range' : (Set.range toFun).Finite
local infixr:25 " →ₛ " => SimpleFunc
namespace SimpleFunc
section Measurable
variable [MeasurableSpace α]
instance instFunLike : FunLike (α →ₛ β) α β where
coe := toFun
coe_injective' | ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl
theorem coe_injective ⦃f g : α →ₛ β⦄ (H : (f : α → β) = g) : f = g := DFunLike.ext' H
@[ext]
theorem ext {f g : α →ₛ β} (H : ∀ a, f a = g a) : f = g := DFunLike.ext _ _ H
theorem finite_range (f : α →ₛ β) : (Set.range f).Finite :=
f.finite_range'
theorem measurableSet_fiber (f : α →ₛ β) (x : β) : MeasurableSet (f ⁻¹' {x}) :=
f.measurableSet_fiber' x
@[simp] theorem coe_mk (f : α → β) (h h') : ⇑(mk f h h') = f := rfl
theorem apply_mk (f : α → β) (h h') (x : α) : SimpleFunc.mk f h h' x = f x :=
rfl
/-- Simple function defined on a finite type. -/
def ofFinite [Finite α] [MeasurableSingletonClass α] (f : α → β) : α →ₛ β where
toFun := f
measurableSet_fiber' x := (toFinite (f ⁻¹' {x})).measurableSet
finite_range' := Set.finite_range f
/-- Simple function defined on the empty type. -/
def ofIsEmpty [IsEmpty α] : α →ₛ β := ofFinite isEmptyElim
/-- Range of a simple function `α →ₛ β` as a `Finset β`. -/
protected def range (f : α →ₛ β) : Finset β :=
f.finite_range.toFinset
@[simp]
theorem mem_range {f : α →ₛ β} {b} : b ∈ f.range ↔ b ∈ range f :=
Finite.mem_toFinset _
theorem mem_range_self (f : α →ₛ β) (x : α) : f x ∈ f.range :=
mem_range.2 ⟨x, rfl⟩
@[simp]
theorem coe_range (f : α →ₛ β) : (↑f.range : Set β) = Set.range f :=
f.finite_range.coe_toFinset
theorem mem_range_of_measure_ne_zero {f : α →ₛ β} {x : β} {μ : Measure α} (H : μ (f ⁻¹' {x}) ≠ 0) :
x ∈ f.range :=
let ⟨a, ha⟩ := nonempty_of_measure_ne_zero H
mem_range.2 ⟨a, ha⟩
theorem forall_mem_range {f : α →ₛ β} {p : β → Prop} : (∀ y ∈ f.range, p y) ↔ ∀ x, p (f x) := by
simp only [mem_range, Set.forall_mem_range]
theorem exists_range_iff {f : α →ₛ β} {p : β → Prop} : (∃ y ∈ f.range, p y) ↔ ∃ x, p (f x) := by
simpa only [mem_range, exists_prop] using Set.exists_range_iff
theorem preimage_eq_empty_iff (f : α →ₛ β) (b : β) : f ⁻¹' {b} = ∅ ↔ b ∉ f.range :=
preimage_singleton_eq_empty.trans <| not_congr mem_range.symm
theorem exists_forall_le [Nonempty β] [Preorder β] [IsDirected β (· ≤ ·)] (f : α →ₛ β) :
∃ C, ∀ x, f x ≤ C :=
f.range.exists_le.imp fun _ => forall_mem_range.1
/-- Constant function as a `SimpleFunc`. -/
def const (α) {β} [MeasurableSpace α] (b : β) : α →ₛ β :=
⟨fun _ => b, fun _ => MeasurableSet.const _, finite_range_const⟩
instance instInhabited [Inhabited β] : Inhabited (α →ₛ β) :=
⟨const _ default⟩
theorem const_apply (a : α) (b : β) : (const α b) a = b :=
rfl
@[simp]
theorem coe_const (b : β) : ⇑(const α b) = Function.const α b :=
rfl
@[simp]
theorem range_const (α) [MeasurableSpace α] [Nonempty α] (b : β) : (const α b).range = {b} :=
Finset.coe_injective <| by simp +unfoldPartialApp [Function.const]
theorem range_const_subset (α) [MeasurableSpace α] (b : β) : (const α b).range ⊆ {b} :=
Finset.coe_subset.1 <| by simp
theorem simpleFunc_bot {α} (f : @SimpleFunc α ⊥ β) [Nonempty β] : ∃ c, ∀ x, f x = c := by
have hf_meas := @SimpleFunc.measurableSet_fiber α _ ⊥ f
simp_rw [MeasurableSpace.measurableSet_bot_iff] at hf_meas
exact (exists_eq_const_of_preimage_singleton hf_meas).imp fun c hc ↦ congr_fun hc
theorem simpleFunc_bot' {α} [Nonempty β] (f : @SimpleFunc α ⊥ β) :
∃ c, f = @SimpleFunc.const α _ ⊥ c :=
letI : MeasurableSpace α := ⊥; (simpleFunc_bot f).imp fun _ ↦ ext
theorem measurableSet_cut (r : α → β → Prop) (f : α →ₛ β) (h : ∀ b, MeasurableSet { a | r a b }) :
MeasurableSet { a | r a (f a) } := by
have : { a | r a (f a) } = ⋃ b ∈ range f, { a | r a b } ∩ f ⁻¹' {b} := by
ext a
suffices r a (f a) ↔ ∃ i, r a (f i) ∧ f a = f i by simpa
exact ⟨fun h => ⟨a, ⟨h, rfl⟩⟩, fun ⟨a', ⟨h', e⟩⟩ => e.symm ▸ h'⟩
rw [this]
exact
MeasurableSet.biUnion f.finite_range.countable fun b _ =>
MeasurableSet.inter (h b) (f.measurableSet_fiber _)
@[measurability]
theorem measurableSet_preimage (f : α →ₛ β) (s) : MeasurableSet (f ⁻¹' s) :=
measurableSet_cut (fun _ b => b ∈ s) f fun b => MeasurableSet.const (b ∈ s)
/-- A simple function is measurable -/
@[measurability, fun_prop]
protected theorem measurable [MeasurableSpace β] (f : α →ₛ β) : Measurable f := fun s _ =>
measurableSet_preimage f s
@[measurability]
protected theorem aemeasurable [MeasurableSpace β] {μ : Measure α} (f : α →ₛ β) :
AEMeasurable f μ :=
f.measurable.aemeasurable
protected theorem sum_measure_preimage_singleton (f : α →ₛ β) {μ : Measure α} (s : Finset β) :
(∑ y ∈ s, μ (f ⁻¹' {y})) = μ (f ⁻¹' ↑s) :=
sum_measure_preimage_singleton _ fun _ _ => f.measurableSet_fiber _
theorem sum_range_measure_preimage_singleton (f : α →ₛ β) (μ : Measure α) :
(∑ y ∈ f.range, μ (f ⁻¹' {y})) = μ univ := by
rw [f.sum_measure_preimage_singleton, coe_range, preimage_range]
open scoped Classical in
/-- If-then-else as a `SimpleFunc`. -/
def piecewise (s : Set α) (hs : MeasurableSet s) (f g : α →ₛ β) : α →ₛ β :=
⟨s.piecewise f g, fun _ =>
letI : MeasurableSpace β := ⊤
f.measurable.piecewise hs g.measurable trivial,
(f.finite_range.union g.finite_range).subset range_ite_subset⟩
open scoped Classical in
@[simp]
theorem coe_piecewise {s : Set α} (hs : MeasurableSet s) (f g : α →ₛ β) :
⇑(piecewise s hs f g) = s.piecewise f g :=
rfl
open scoped Classical in
theorem piecewise_apply {s : Set α} (hs : MeasurableSet s) (f g : α →ₛ β) (a) :
piecewise s hs f g a = if a ∈ s then f a else g a :=
rfl
open scoped Classical in
@[simp]
theorem piecewise_compl {s : Set α} (hs : MeasurableSet sᶜ) (f g : α →ₛ β) :
piecewise sᶜ hs f g = piecewise s hs.of_compl g f :=
coe_injective <| by simp [hs]
@[simp]
theorem piecewise_univ (f g : α →ₛ β) : piecewise univ MeasurableSet.univ f g = f :=
coe_injective <| by simp
@[simp]
theorem piecewise_empty (f g : α →ₛ β) : piecewise ∅ MeasurableSet.empty f g = g :=
coe_injective <| by simp
open scoped Classical in
@[simp]
theorem piecewise_same (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) :
piecewise s hs f f = f :=
coe_injective <| Set.piecewise_same _ _
theorem support_indicator [Zero β] {s : Set α} (hs : MeasurableSet s) (f : α →ₛ β) :
Function.support (f.piecewise s hs (SimpleFunc.const α 0)) = s ∩ Function.support f :=
Set.support_indicator
open scoped Classical in
theorem range_indicator {s : Set α} (hs : MeasurableSet s) (hs_nonempty : s.Nonempty)
(hs_ne_univ : s ≠ univ) (x y : β) :
(piecewise s hs (const α x) (const α y)).range = {x, y} := by
simp only [← Finset.coe_inj, coe_range, coe_piecewise, range_piecewise, coe_const,
Finset.coe_insert, Finset.coe_singleton, hs_nonempty.image_const,
(nonempty_compl.2 hs_ne_univ).image_const, singleton_union, Function.const]
theorem measurable_bind [MeasurableSpace γ] (f : α →ₛ β) (g : β → α → γ)
(hg : ∀ b, Measurable (g b)) : Measurable fun a => g (f a) a := fun s hs =>
f.measurableSet_cut (fun a b => g b a ∈ s) fun b => hg b hs
/-- If `f : α →ₛ β` is a simple function and `g : β → α →ₛ γ` is a family of simple functions,
then `f.bind g` binds the first argument of `g` to `f`. In other words, `f.bind g a = g (f a) a`. -/
def bind (f : α →ₛ β) (g : β → α →ₛ γ) : α →ₛ γ :=
⟨fun a => g (f a) a, fun c =>
f.measurableSet_cut (fun a b => g b a = c) fun b => (g b).measurableSet_preimage {c},
(f.finite_range.biUnion fun b _ => (g b).finite_range).subset <| by
rintro _ ⟨a, rfl⟩; simp⟩
@[simp]
theorem bind_apply (f : α →ₛ β) (g : β → α →ₛ γ) (a) : f.bind g a = g (f a) a :=
rfl
/-- Given a function `g : β → γ` and a simple function `f : α →ₛ β`, `f.map g` return the simple
function `g ∘ f : α →ₛ γ` -/
def map (g : β → γ) (f : α →ₛ β) : α →ₛ γ :=
bind f (const α ∘ g)
theorem map_apply (g : β → γ) (f : α →ₛ β) (a) : f.map g a = g (f a) :=
rfl
theorem map_map (g : β → γ) (h : γ → δ) (f : α →ₛ β) : (f.map g).map h = f.map (h ∘ g) :=
rfl
@[simp]
theorem coe_map (g : β → γ) (f : α →ₛ β) : (f.map g : α → γ) = g ∘ f :=
rfl
@[simp]
theorem range_map [DecidableEq γ] (g : β → γ) (f : α →ₛ β) : (f.map g).range = f.range.image g :=
Finset.coe_injective <| by simp only [coe_range, coe_map, Finset.coe_image, range_comp]
@[simp]
theorem map_const (g : β → γ) (b : β) : (const α b).map g = const α (g b) :=
rfl
open scoped Classical in
theorem map_preimage (f : α →ₛ β) (g : β → γ) (s : Set γ) :
f.map g ⁻¹' s = f ⁻¹' ↑{b ∈ f.range | g b ∈ s} := by
simp only [coe_range, sep_mem_eq, coe_map, Finset.coe_filter,
← mem_preimage, inter_comm, preimage_inter_range, ← Finset.mem_coe]
exact preimage_comp
open scoped Classical in
theorem map_preimage_singleton (f : α →ₛ β) (g : β → γ) (c : γ) :
f.map g ⁻¹' {c} = f ⁻¹' ↑{b ∈ f.range | g b = c} :=
map_preimage _ _ _
/-- Composition of a `SimpleFun` and a measurable function is a `SimpleFunc`. -/
def comp [MeasurableSpace β] (f : β →ₛ γ) (g : α → β) (hgm : Measurable g) : α →ₛ γ where
toFun := f ∘ g
finite_range' := f.finite_range.subset <| Set.range_comp_subset_range _ _
measurableSet_fiber' z := hgm (f.measurableSet_fiber z)
@[simp]
theorem coe_comp [MeasurableSpace β] (f : β →ₛ γ) {g : α → β} (hgm : Measurable g) :
⇑(f.comp g hgm) = f ∘ g :=
rfl
theorem range_comp_subset_range [MeasurableSpace β] (f : β →ₛ γ) {g : α → β} (hgm : Measurable g) :
(f.comp g hgm).range ⊆ f.range :=
Finset.coe_subset.1 <| by simp only [coe_range, coe_comp, Set.range_comp_subset_range]
/-- Extend a `SimpleFunc` along a measurable embedding: `f₁.extend g hg f₂` is the function
`F : β →ₛ γ` such that `F ∘ g = f₁` and `F y = f₂ y` whenever `y ∉ range g`. -/
def extend [MeasurableSpace β] (f₁ : α →ₛ γ) (g : α → β) (hg : MeasurableEmbedding g)
(f₂ : β →ₛ γ) : β →ₛ γ where
toFun := Function.extend g f₁ f₂
finite_range' :=
(f₁.finite_range.union <| f₂.finite_range.subset (image_subset_range _ _)).subset
(range_extend_subset _ _ _)
measurableSet_fiber' := by
letI : MeasurableSpace γ := ⊤; haveI : MeasurableSingletonClass γ := ⟨fun _ => trivial⟩
exact fun x => hg.measurable_extend f₁.measurable f₂.measurable (measurableSet_singleton _)
@[simp]
theorem extend_apply [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g)
(f₂ : β →ₛ γ) (x : α) : (f₁.extend g hg f₂) (g x) = f₁ x :=
hg.injective.extend_apply _ _ _
@[simp]
theorem extend_apply' [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g)
(f₂ : β →ₛ γ) {y : β} (h : ¬∃ x, g x = y) : (f₁.extend g hg f₂) y = f₂ y :=
Function.extend_apply' _ _ _ h
@[simp]
theorem extend_comp_eq' [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g)
(f₂ : β →ₛ γ) : f₁.extend g hg f₂ ∘ g = f₁ :=
funext fun _ => extend_apply _ _ _ _
@[simp]
theorem extend_comp_eq [MeasurableSpace β] (f₁ : α →ₛ γ) {g : α → β} (hg : MeasurableEmbedding g)
(f₂ : β →ₛ γ) : (f₁.extend g hg f₂).comp g hg.measurable = f₁ :=
coe_injective <| extend_comp_eq' _ hg _
/-- If `f` is a simple function taking values in `β → γ` and `g` is another simple function
with the same domain and codomain `β`, then `f.seq g = f a (g a)`. -/
def seq (f : α →ₛ β → γ) (g : α →ₛ β) : α →ₛ γ :=
f.bind fun f => g.map f
@[simp]
theorem seq_apply (f : α →ₛ β → γ) (g : α →ₛ β) (a : α) : f.seq g a = f a (g a) :=
rfl
/-- Combine two simple functions `f : α →ₛ β` and `g : α →ₛ β`
into `fun a => (f a, g a)`. -/
def pair (f : α →ₛ β) (g : α →ₛ γ) : α →ₛ β × γ :=
(f.map Prod.mk).seq g
@[simp]
theorem pair_apply (f : α →ₛ β) (g : α →ₛ γ) (a) : pair f g a = (f a, g a) :=
rfl
theorem pair_preimage (f : α →ₛ β) (g : α →ₛ γ) (s : Set β) (t : Set γ) :
pair f g ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t :=
rfl
-- A special form of `pair_preimage`
theorem pair_preimage_singleton (f : α →ₛ β) (g : α →ₛ γ) (b : β) (c : γ) :
pair f g ⁻¹' {(b, c)} = f ⁻¹' {b} ∩ g ⁻¹' {c} := by
rw [← singleton_prod_singleton]
exact pair_preimage _ _ _ _
@[simp] theorem map_fst_pair (f : α →ₛ β) (g : α →ₛ γ) : (f.pair g).map Prod.fst = f := rfl
@[simp] theorem map_snd_pair (f : α →ₛ β) (g : α →ₛ γ) : (f.pair g).map Prod.snd = g := rfl
@[simp]
theorem bind_const (f : α →ₛ β) : f.bind (const α) = f := by ext; simp
@[to_additive]
instance instOne [One β] : One (α →ₛ β) :=
⟨const α 1⟩
@[to_additive]
instance instMul [Mul β] : Mul (α →ₛ β) :=
⟨fun f g => (f.map (· * ·)).seq g⟩
@[to_additive]
instance instDiv [Div β] : Div (α →ₛ β) :=
⟨fun f g => (f.map (· / ·)).seq g⟩
@[to_additive]
instance instInv [Inv β] : Inv (α →ₛ β) :=
⟨fun f => f.map Inv.inv⟩
instance instSup [Max β] : Max (α →ₛ β) :=
⟨fun f g => (f.map (· ⊔ ·)).seq g⟩
instance instInf [Min β] : Min (α →ₛ β) :=
⟨fun f g => (f.map (· ⊓ ·)).seq g⟩
instance instLE [LE β] : LE (α →ₛ β) :=
⟨fun f g => ∀ a, f a ≤ g a⟩
@[to_additive (attr := simp)]
theorem const_one [One β] : const α (1 : β) = 1 :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_one [One β] : ⇑(1 : α →ₛ β) = 1 :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_mul [Mul β] (f g : α →ₛ β) : ⇑(f * g) = ⇑f * ⇑g :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_inv [Inv β] (f : α →ₛ β) : ⇑(f⁻¹) = (⇑f)⁻¹ :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_div [Div β] (f g : α →ₛ β) : ⇑(f / g) = ⇑f / ⇑g :=
rfl
@[simp, norm_cast]
theorem coe_le [LE β] {f g : α →ₛ β} : (f : α → β) ≤ g ↔ f ≤ g :=
Iff.rfl
@[simp, norm_cast]
theorem coe_sup [Max β] (f g : α →ₛ β) : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g :=
rfl
@[simp, norm_cast]
theorem coe_inf [Min β] (f g : α →ₛ β) : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g :=
rfl
@[to_additive]
theorem mul_apply [Mul β] (f g : α →ₛ β) (a : α) : (f * g) a = f a * g a :=
rfl
@[to_additive]
theorem div_apply [Div β] (f g : α →ₛ β) (x : α) : (f / g) x = f x / g x :=
rfl
@[to_additive]
theorem inv_apply [Inv β] (f : α →ₛ β) (x : α) : f⁻¹ x = (f x)⁻¹ :=
rfl
theorem sup_apply [Max β] (f g : α →ₛ β) (a : α) : (f ⊔ g) a = f a ⊔ g a :=
rfl
theorem inf_apply [Min β] (f g : α →ₛ β) (a : α) : (f ⊓ g) a = f a ⊓ g a :=
rfl
@[to_additive (attr := simp)]
theorem range_one [Nonempty α] [One β] : (1 : α →ₛ β).range = {1} :=
Finset.ext fun x => by simp [eq_comm]
@[simp]
theorem range_eq_empty_of_isEmpty {β} [hα : IsEmpty α] (f : α →ₛ β) : f.range = ∅ := by
rw [← Finset.not_nonempty_iff_eq_empty]
by_contra h
obtain ⟨y, hy_mem⟩ := h
rw [SimpleFunc.mem_range, Set.mem_range] at hy_mem
obtain ⟨x, hxy⟩ := hy_mem
rw [isEmpty_iff] at hα
exact hα x
theorem eq_zero_of_mem_range_zero [Zero β] : ∀ {y : β}, y ∈ (0 : α →ₛ β).range → y = 0 :=
@(forall_mem_range.2 fun _ => rfl)
@[to_additive]
theorem mul_eq_map₂ [Mul β] (f g : α →ₛ β) : f * g = (pair f g).map fun p : β × β => p.1 * p.2 :=
rfl
theorem sup_eq_map₂ [Max β] (f g : α →ₛ β) : f ⊔ g = (pair f g).map fun p : β × β => p.1 ⊔ p.2 :=
rfl
@[to_additive]
theorem const_mul_eq_map [Mul β] (f : α →ₛ β) (b : β) : const α b * f = f.map fun a => b * a :=
rfl
@[to_additive]
theorem map_mul [Mul β] [Mul γ] {g : β → γ} (hg : ∀ x y, g (x * y) = g x * g y) (f₁ f₂ : α →ₛ β) :
(f₁ * f₂).map g = f₁.map g * f₂.map g :=
ext fun _ => hg _ _
variable {K : Type*}
@[to_additive]
instance instSMul [SMul K β] : SMul K (α →ₛ β) :=
⟨fun k f => f.map (k • ·)⟩
@[to_additive (attr := simp)]
theorem coe_smul [SMul K β] (c : K) (f : α →ₛ β) : ⇑(c • f) = c • ⇑f :=
rfl
@[to_additive (attr := simp)]
theorem smul_apply [SMul K β] (k : K) (f : α →ₛ β) (a : α) : (k • f) a = k • f a :=
rfl
instance hasNatSMul [AddMonoid β] : SMul ℕ (α →ₛ β) := inferInstance
@[to_additive existing hasNatSMul]
instance hasNatPow [Monoid β] : Pow (α →ₛ β) ℕ :=
⟨fun f n => f.map (· ^ n)⟩
@[simp]
theorem coe_pow [Monoid β] (f : α →ₛ β) (n : ℕ) : ⇑(f ^ n) = (⇑f) ^ n :=
rfl
theorem pow_apply [Monoid β] (n : ℕ) (f : α →ₛ β) (a : α) : (f ^ n) a = f a ^ n :=
rfl
instance hasIntPow [DivInvMonoid β] : Pow (α →ₛ β) ℤ :=
⟨fun f n => f.map (· ^ n)⟩
@[simp]
theorem coe_zpow [DivInvMonoid β] (f : α →ₛ β) (z : ℤ) : ⇑(f ^ z) = (⇑f) ^ z :=
rfl
theorem zpow_apply [DivInvMonoid β] (z : ℤ) (f : α →ₛ β) (a : α) : (f ^ z) a = f a ^ z :=
rfl
-- TODO: work out how to generate these instances with `to_additive`, which gets confused by the
-- argument order swap between `coe_smul` and `coe_pow`.
section Additive
instance instAddMonoid [AddMonoid β] : AddMonoid (α →ₛ β) :=
Function.Injective.addMonoid (fun f => show α → β from f) coe_injective coe_zero coe_add
fun _ _ => coe_smul _ _
instance instAddCommMonoid [AddCommMonoid β] : AddCommMonoid (α →ₛ β) :=
Function.Injective.addCommMonoid (fun f => show α → β from f) coe_injective coe_zero coe_add
fun _ _ => coe_smul _ _
instance instAddGroup [AddGroup β] : AddGroup (α →ₛ β) :=
Function.Injective.addGroup (fun f => show α → β from f) coe_injective coe_zero coe_add coe_neg
coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _
instance instAddCommGroup [AddCommGroup β] : AddCommGroup (α →ₛ β) :=
Function.Injective.addCommGroup (fun f => show α → β from f) coe_injective coe_zero coe_add
coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _
end Additive
@[to_additive existing]
instance instMonoid [Monoid β] : Monoid (α →ₛ β) :=
Function.Injective.monoid (fun f => show α → β from f) coe_injective coe_one coe_mul coe_pow
@[to_additive existing]
instance instCommMonoid [CommMonoid β] : CommMonoid (α →ₛ β) :=
Function.Injective.commMonoid (fun f => show α → β from f) coe_injective coe_one coe_mul coe_pow
@[to_additive existing]
instance instGroup [Group β] : Group (α →ₛ β) :=
Function.Injective.group (fun f => show α → β from f) coe_injective coe_one coe_mul coe_inv
coe_div coe_pow coe_zpow
@[to_additive existing]
instance instCommGroup [CommGroup β] : CommGroup (α →ₛ β) :=
Function.Injective.commGroup (fun f => show α → β from f) coe_injective coe_one coe_mul coe_inv
coe_div coe_pow coe_zpow
instance instModule [Semiring K] [AddCommMonoid β] [Module K β] : Module K (α →ₛ β) :=
Function.Injective.module K ⟨⟨fun f => show α → β from f, coe_zero⟩, coe_add⟩
coe_injective coe_smul
theorem smul_eq_map [SMul K β] (k : K) (f : α →ₛ β) : k • f = f.map (k • ·) :=
rfl
section Preorder
variable [Preorder β] {s : Set α} {f f₁ f₂ g g₁ g₂ : α →ₛ β} {hs : MeasurableSet s}
instance instPreorder : Preorder (α →ₛ β) := Preorder.lift (⇑)
@[norm_cast] lemma coe_le_coe : ⇑f ≤ g ↔ f ≤ g := .rfl
@[simp, norm_cast] lemma coe_lt_coe : ⇑f < g ↔ f < g := .rfl
@[simp] lemma mk_le_mk {f g : α → β} {hf hg hf' hg'} : mk f hf hf' ≤ mk g hg hg' ↔ f ≤ g := Iff.rfl
@[simp] lemma mk_lt_mk {f g : α → β} {hf hg hf' hg'} : mk f hf hf' < mk g hg hg' ↔ f < g := Iff.rfl
@[gcongr] protected alias ⟨_, GCongr.mk_le_mk⟩ := mk_le_mk
@[gcongr] protected alias ⟨_, GCongr.mk_lt_mk⟩ := mk_lt_mk
@[gcongr] protected alias ⟨_, GCongr.coe_le_coe⟩ := coe_le_coe
@[gcongr] protected alias ⟨_, GCongr.coe_lt_coe⟩ := coe_lt_coe
open scoped Classical in
@[gcongr]
lemma piecewise_mono (hf : ∀ a ∈ s, f₁ a ≤ f₂ a) (hg : ∀ a ∉ s, g₁ a ≤ g₂ a) :
piecewise s hs f₁ g₁ ≤ piecewise s hs f₂ g₂ := Set.piecewise_mono hf hg
end Preorder
instance instPartialOrder [PartialOrder β] : PartialOrder (α →ₛ β) :=
{ SimpleFunc.instPreorder with
le_antisymm := fun _f _g hfg hgf => ext fun a => le_antisymm (hfg a) (hgf a) }
instance instOrderBot [LE β] [OrderBot β] : OrderBot (α →ₛ β) where
bot := const α ⊥
bot_le _ _ := bot_le
instance instOrderTop [LE β] [OrderTop β] : OrderTop (α →ₛ β) where
top := const α ⊤
le_top _ _ := le_top
@[to_additive]
instance [CommMonoid β] [PartialOrder β] [IsOrderedMonoid β] :
IsOrderedMonoid (α →ₛ β) where
mul_le_mul_left _ _ h _ _ := mul_le_mul_left' (h _) _
instance instSemilatticeInf [SemilatticeInf β] : SemilatticeInf (α →ₛ β) :=
{ SimpleFunc.instPartialOrder with
inf := (· ⊓ ·)
inf_le_left := fun _ _ _ => inf_le_left
inf_le_right := fun _ _ _ => inf_le_right
le_inf := fun _f _g _h hfh hgh a => le_inf (hfh a) (hgh a) }
instance instSemilatticeSup [SemilatticeSup β] : SemilatticeSup (α →ₛ β) :=
{ SimpleFunc.instPartialOrder with
sup := (· ⊔ ·)
le_sup_left := fun _ _ _ => le_sup_left
le_sup_right := fun _ _ _ => le_sup_right
sup_le := fun _f _g _h hfh hgh a => sup_le (hfh a) (hgh a) }
instance instLattice [Lattice β] : Lattice (α →ₛ β) :=
{ SimpleFunc.instSemilatticeSup, SimpleFunc.instSemilatticeInf with }
instance instBoundedOrder [LE β] [BoundedOrder β] : BoundedOrder (α →ₛ β) :=
{ SimpleFunc.instOrderBot, SimpleFunc.instOrderTop with }
theorem finset_sup_apply [SemilatticeSup β] [OrderBot β] {f : γ → α →ₛ β} (s : Finset γ) (a : α) :
s.sup f a = s.sup fun c => f c a := by
classical
refine Finset.induction_on s rfl ?_
intro a s _ ih
rw [Finset.sup_insert, Finset.sup_insert, sup_apply, ih]
section Restrict
variable [Zero β]
open scoped Classical in
/-- Restrict a simple function `f : α →ₛ β` to a set `s`. If `s` is measurable,
then `f.restrict s a = if a ∈ s then f a else 0`, otherwise `f.restrict s = const α 0`. -/
def restrict (f : α →ₛ β) (s : Set α) : α →ₛ β :=
if hs : MeasurableSet s then piecewise s hs f 0 else 0
theorem restrict_of_not_measurable {f : α →ₛ β} {s : Set α} (hs : ¬MeasurableSet s) :
restrict f s = 0 :=
dif_neg hs
@[simp]
theorem coe_restrict (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) :
⇑(restrict f s) = indicator s f := by
classical
rw [restrict, dif_pos hs, coe_piecewise, coe_zero, piecewise_eq_indicator]
@[simp]
theorem restrict_univ (f : α →ₛ β) : restrict f univ = f := by simp [restrict]
@[simp]
theorem restrict_empty (f : α →ₛ β) : restrict f ∅ = 0 := by simp [restrict]
open scoped Classical in
theorem map_restrict_of_zero [Zero γ] {g : β → γ} (hg : g 0 = 0) (f : α →ₛ β) (s : Set α) :
(f.restrict s).map g = (f.map g).restrict s :=
ext fun x =>
if hs : MeasurableSet s then by simp [hs, Set.indicator_comp_of_zero hg]
else by simp [restrict_of_not_measurable hs, hg]
theorem map_coe_ennreal_restrict (f : α →ₛ ℝ≥0) (s : Set α) :
(f.restrict s).map ((↑) : ℝ≥0 → ℝ≥0∞) = (f.map (↑)).restrict s :=
map_restrict_of_zero ENNReal.coe_zero _ _
theorem map_coe_nnreal_restrict (f : α →ₛ ℝ≥0) (s : Set α) :
(f.restrict s).map ((↑) : ℝ≥0 → ℝ) = (f.map (↑)).restrict s :=
map_restrict_of_zero NNReal.coe_zero _ _
theorem restrict_apply (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) (a) :
restrict f s a = indicator s f a := by simp only [f.coe_restrict hs]
theorem restrict_preimage (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) {t : Set β}
(ht : (0 : β) ∉ t) : restrict f s ⁻¹' t = s ∩ f ⁻¹' t := by
simp [hs, indicator_preimage_of_not_mem _ _ ht, inter_comm]
theorem restrict_preimage_singleton (f : α →ₛ β) {s : Set α} (hs : MeasurableSet s) {r : β}
(hr : r ≠ 0) : restrict f s ⁻¹' {r} = s ∩ f ⁻¹' {r} :=
f.restrict_preimage hs hr.symm
theorem mem_restrict_range {r : β} {s : Set α} {f : α →ₛ β} (hs : MeasurableSet s) :
r ∈ (restrict f s).range ↔ r = 0 ∧ s ≠ univ ∨ r ∈ f '' s := by
rw [← Finset.mem_coe, coe_range, coe_restrict _ hs, mem_range_indicator]
open scoped Classical in
theorem mem_image_of_mem_range_restrict {r : β} {s : Set α} {f : α →ₛ β}
(hr : r ∈ (restrict f s).range) (h0 : r ≠ 0) : r ∈ f '' s :=
if hs : MeasurableSet s then by simpa [mem_restrict_range hs, h0, -mem_range] using hr
else by
rw [restrict_of_not_measurable hs] at hr
exact (h0 <| eq_zero_of_mem_range_zero hr).elim
open scoped Classical in
@[gcongr, mono]
theorem restrict_mono [Preorder β] (s : Set α) {f g : α →ₛ β} (H : f ≤ g) :
f.restrict s ≤ g.restrict s :=
if hs : MeasurableSet s then fun x => by
simp only [coe_restrict _ hs, indicator_le_indicator (H x)]
else by simp only [restrict_of_not_measurable hs, le_refl]
end Restrict
section Approx
section
variable [SemilatticeSup β] [OrderBot β] [Zero β]
/-- Fix a sequence `i : ℕ → β`. Given a function `α → β`, its `n`-th approximation
by simple functions is defined so that in case `β = ℝ≥0∞` it sends each `a` to the supremum
of the set `{i k | k ≤ n ∧ i k ≤ f a}`, see `approx_apply` and `iSup_approx_apply` for details. -/
def approx (i : ℕ → β) (f : α → β) (n : ℕ) : α →ₛ β :=
(Finset.range n).sup fun k => restrict (const α (i k)) { a : α | i k ≤ f a }
open scoped Classical in
theorem approx_apply [TopologicalSpace β] [OrderClosedTopology β] [MeasurableSpace β]
[OpensMeasurableSpace β] {i : ℕ → β} {f : α → β} {n : ℕ} (a : α) (hf : Measurable f) :
(approx i f n : α →ₛ β) a = (Finset.range n).sup fun k => if i k ≤ f a then i k else 0 := by
dsimp only [approx]
rw [finset_sup_apply]
congr
funext k
rw [restrict_apply]
· simp only [coe_const, mem_setOf_eq, indicator_apply, Function.const_apply]
· exact hf measurableSet_Ici
theorem monotone_approx (i : ℕ → β) (f : α → β) : Monotone (approx i f) := fun _ _ h =>
Finset.sup_mono <| Finset.range_subset.2 h
theorem approx_comp [TopologicalSpace β] [OrderClosedTopology β] [MeasurableSpace β]
[OpensMeasurableSpace β] [MeasurableSpace γ] {i : ℕ → β} {f : γ → β} {g : α → γ} {n : ℕ} (a : α)
(hf : Measurable f) (hg : Measurable g) :
(approx i (f ∘ g) n : α →ₛ β) a = (approx i f n : γ →ₛ β) (g a) := by
rw [approx_apply _ hf, approx_apply _ (hf.comp hg), Function.comp_apply]
end
theorem iSup_approx_apply [TopologicalSpace β] [CompleteLattice β] [OrderClosedTopology β] [Zero β]
[MeasurableSpace β] [OpensMeasurableSpace β] (i : ℕ → β) (f : α → β) (a : α) (hf : Measurable f)
(h_zero : (0 : β) = ⊥) : ⨆ n, (approx i f n : α →ₛ β) a = ⨆ (k) (_ : i k ≤ f a), i k := by
refine le_antisymm (iSup_le fun n => ?_) (iSup_le fun k => iSup_le fun hk => ?_)
· rw [approx_apply a hf, h_zero]
refine Finset.sup_le fun k _ => ?_
split_ifs with h
· exact le_iSup_of_le k (le_iSup (fun _ : i k ≤ f a => i k) h)
· exact bot_le
· refine le_iSup_of_le (k + 1) ?_
rw [approx_apply a hf]
have : k ∈ Finset.range (k + 1) := Finset.mem_range.2 (Nat.lt_succ_self _)
refine le_trans (le_of_eq ?_) (Finset.le_sup this)
rw [if_pos hk]
end Approx
section EApprox
variable {f : α → ℝ≥0∞}
/-- A sequence of `ℝ≥0∞`s such that its range is the set of non-negative rational numbers. -/
def ennrealRatEmbed (n : ℕ) : ℝ≥0∞ :=
ENNReal.ofReal ((Encodable.decode (α := ℚ) n).getD (0 : ℚ))
theorem ennrealRatEmbed_encode (q : ℚ) :
ennrealRatEmbed (Encodable.encode q) = Real.toNNReal q := by
rw [ennrealRatEmbed, Encodable.encodek]; rfl
/-- Approximate a function `α → ℝ≥0∞` by a sequence of simple functions. -/
def eapprox : (α → ℝ≥0∞) → ℕ → α →ₛ ℝ≥0∞ :=
approx ennrealRatEmbed
theorem eapprox_lt_top (f : α → ℝ≥0∞) (n : ℕ) (a : α) : eapprox f n a < ∞ := by
simp only [eapprox, approx, finset_sup_apply, Finset.mem_range, ENNReal.bot_eq_zero, restrict]
rw [Finset.sup_lt_iff (α := ℝ≥0∞) WithTop.top_pos]
intro b _
split_ifs
· simp only [coe_zero, coe_piecewise, piecewise_eq_indicator, coe_const]
calc
{ a : α | ennrealRatEmbed b ≤ f a }.indicator (fun _ => ennrealRatEmbed b) a ≤
ennrealRatEmbed b :=
indicator_le_self _ _ a
_ < ⊤ := ENNReal.coe_lt_top
· exact WithTop.top_pos
@[mono]
theorem monotone_eapprox (f : α → ℝ≥0∞) : Monotone (eapprox f) :=
monotone_approx _ f
@[gcongr]
lemma eapprox_mono {m n : ℕ} (hmn : m ≤ n) : eapprox f m ≤ eapprox f n := monotone_eapprox _ hmn
lemma iSup_eapprox_apply (hf : Measurable f) (a : α) : ⨆ n, (eapprox f n : α →ₛ ℝ≥0∞) a = f a := by
rw [eapprox, iSup_approx_apply ennrealRatEmbed f a hf rfl]
refine le_antisymm (iSup_le fun i => iSup_le fun hi => hi) (le_of_not_gt ?_)
intro h
rcases ENNReal.lt_iff_exists_rat_btwn.1 h with ⟨q, _, lt_q, q_lt⟩
have :
(Real.toNNReal q : ℝ≥0∞) ≤ ⨆ (k : ℕ) (_ : ennrealRatEmbed k ≤ f a), ennrealRatEmbed k := by
refine le_iSup_of_le (Encodable.encode q) ?_
rw [ennrealRatEmbed_encode q]
exact le_iSup_of_le (le_of_lt q_lt) le_rfl
exact lt_irrefl _ (lt_of_le_of_lt this lt_q)
lemma iSup_coe_eapprox (hf : Measurable f) : ⨆ n, ⇑(eapprox f n) = f := by
simpa [funext_iff] using iSup_eapprox_apply hf
theorem eapprox_comp [MeasurableSpace γ] {f : γ → ℝ≥0∞} {g : α → γ} {n : ℕ} (hf : Measurable f)
(hg : Measurable g) : (eapprox (f ∘ g) n : α → ℝ≥0∞) = (eapprox f n : γ →ₛ ℝ≥0∞) ∘ g :=
funext fun a => approx_comp a hf hg
lemma tendsto_eapprox {f : α → ℝ≥0∞} (hf_meas : Measurable f) (a : α) :
Tendsto (fun n ↦ eapprox f n a) atTop (𝓝 (f a)) := by
nth_rw 2 [← iSup_coe_eapprox hf_meas]
rw [iSup_apply]
exact tendsto_atTop_iSup fun _ _ hnm ↦ monotone_eapprox f hnm a
/-- Approximate a function `α → ℝ≥0∞` by a series of simple functions taking their values
in `ℝ≥0`. -/
def eapproxDiff (f : α → ℝ≥0∞) : ℕ → α →ₛ ℝ≥0
| 0 => (eapprox f 0).map ENNReal.toNNReal
| n + 1 => (eapprox f (n + 1) - eapprox f n).map ENNReal.toNNReal
theorem sum_eapproxDiff (f : α → ℝ≥0∞) (n : ℕ) (a : α) :
(∑ k ∈ Finset.range (n + 1), (eapproxDiff f k a : ℝ≥0∞)) = eapprox f n a := by
induction' n with n IH
· simp only [Nat.zero_add, Finset.sum_singleton, Finset.range_one]
rfl
· rw [Finset.sum_range_succ, IH, eapproxDiff, coe_map, Function.comp_apply,
coe_sub, Pi.sub_apply, ENNReal.coe_toNNReal,
add_tsub_cancel_of_le (monotone_eapprox f (Nat.le_succ _) _)]
apply (lt_of_le_of_lt _ (eapprox_lt_top f (n + 1) a)).ne
rw [tsub_le_iff_right]
exact le_self_add
theorem tsum_eapproxDiff (f : α → ℝ≥0∞) (hf : Measurable f) (a : α) :
(∑' n, (eapproxDiff f n a : ℝ≥0∞)) = f a := by
simp_rw [ENNReal.tsum_eq_iSup_nat' (tendsto_add_atTop_nat 1), sum_eapproxDiff,
iSup_eapprox_apply hf a]
end EApprox
end Measurable
section Measure
variable {m : MeasurableSpace α} {μ ν : Measure α}
/-- Integral of a simple function whose codomain is `ℝ≥0∞`. -/
def lintegral {_m : MeasurableSpace α} (f : α →ₛ ℝ≥0∞) (μ : Measure α) : ℝ≥0∞ :=
∑ x ∈ f.range, x * μ (f ⁻¹' {x})
theorem lintegral_eq_of_subset (f : α →ₛ ℝ≥0∞) {s : Finset ℝ≥0∞}
(hs : ∀ x, f x ≠ 0 → μ (f ⁻¹' {f x}) ≠ 0 → f x ∈ s) :
f.lintegral μ = ∑ x ∈ s, x * μ (f ⁻¹' {x}) := by
refine Finset.sum_bij_ne_zero (fun r _ _ => r) ?_ ?_ ?_ ?_
· simpa only [forall_mem_range, mul_ne_zero_iff, and_imp]
· intros
assumption
· intro b _ hb
refine ⟨b, ?_, hb, rfl⟩
rw [mem_range, ← preimage_singleton_nonempty]
exact nonempty_of_measure_ne_zero (mul_ne_zero_iff.1 hb).2
· intros
rfl
theorem lintegral_eq_of_subset' (f : α →ₛ ℝ≥0∞) {s : Finset ℝ≥0∞} (hs : f.range \ {0} ⊆ s) :
f.lintegral μ = ∑ x ∈ s, x * μ (f ⁻¹' {x}) :=
f.lintegral_eq_of_subset fun x hfx _ =>
hs <| Finset.mem_sdiff.2 ⟨f.mem_range_self x, mt Finset.mem_singleton.1 hfx⟩
/-- Calculate the integral of `(g ∘ f)`, where `g : β → ℝ≥0∞` and `f : α →ₛ β`. -/
theorem map_lintegral (g : β → ℝ≥0∞) (f : α →ₛ β) :
(f.map g).lintegral μ = ∑ x ∈ f.range, g x * μ (f ⁻¹' {x}) := by
simp only [lintegral, range_map]
refine Finset.sum_image' _ fun b hb => ?_
rcases mem_range.1 hb with ⟨a, rfl⟩
rw [map_preimage_singleton, ← f.sum_measure_preimage_singleton, Finset.mul_sum]
refine Finset.sum_congr ?_ ?_
· congr
· intro x
simp only [Finset.mem_filter]
rintro ⟨_, h⟩
rw [h]
theorem add_lintegral (f g : α →ₛ ℝ≥0∞) : (f + g).lintegral μ = f.lintegral μ + g.lintegral μ :=
calc
(f + g).lintegral μ =
∑ x ∈ (pair f g).range, (x.1 * μ (pair f g ⁻¹' {x}) + x.2 * μ (pair f g ⁻¹' {x})) := by
rw [add_eq_map₂, map_lintegral]; exact Finset.sum_congr rfl fun a _ => add_mul _ _ _
_ = (∑ x ∈ (pair f g).range, x.1 * μ (pair f g ⁻¹' {x})) +
∑ x ∈ (pair f g).range, x.2 * μ (pair f g ⁻¹' {x}) := by
rw [Finset.sum_add_distrib]
_ = ((pair f g).map Prod.fst).lintegral μ + ((pair f g).map Prod.snd).lintegral μ := by
rw [map_lintegral, map_lintegral]
_ = lintegral f μ + lintegral g μ := rfl
theorem const_mul_lintegral (f : α →ₛ ℝ≥0∞) (x : ℝ≥0∞) :
(const α x * f).lintegral μ = x * f.lintegral μ :=
calc
(f.map fun a => x * a).lintegral μ = ∑ r ∈ f.range, x * r * μ (f ⁻¹' {r}) := map_lintegral _ _
_ = x * ∑ r ∈ f.range, r * μ (f ⁻¹' {r}) := by simp_rw [Finset.mul_sum, mul_assoc]
/-- Integral of a simple function `α →ₛ ℝ≥0∞` as a bilinear map. -/
def lintegralₗ {m : MeasurableSpace α} : (α →ₛ ℝ≥0∞) →ₗ[ℝ≥0∞] Measure α →ₗ[ℝ≥0∞] ℝ≥0∞ where
toFun f :=
{ toFun := lintegral f
map_add' := by simp [lintegral, mul_add, Finset.sum_add_distrib]
map_smul' := fun c μ => by
simp [lintegral, mul_left_comm _ c, Finset.mul_sum, Measure.smul_apply c] }
map_add' f g := LinearMap.ext fun _ => add_lintegral f g
map_smul' c f := LinearMap.ext fun _ => const_mul_lintegral f c
@[simp]
theorem zero_lintegral : (0 : α →ₛ ℝ≥0∞).lintegral μ = 0 :=
LinearMap.ext_iff.1 lintegralₗ.map_zero μ
theorem lintegral_add {ν} (f : α →ₛ ℝ≥0∞) : f.lintegral (μ + ν) = f.lintegral μ + f.lintegral ν :=
(lintegralₗ f).map_add μ ν
theorem lintegral_smul {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
(f : α →ₛ ℝ≥0∞) (c : R) : f.lintegral (c • μ) = c • f.lintegral μ := by
simpa only [smul_one_smul] using (lintegralₗ f).map_smul (c • 1) μ
@[simp]
theorem lintegral_zero [MeasurableSpace α] (f : α →ₛ ℝ≥0∞) : f.lintegral 0 = 0 :=
(lintegralₗ f).map_zero
theorem lintegral_finset_sum {ι} (f : α →ₛ ℝ≥0∞) (μ : ι → Measure α) (s : Finset ι) :
f.lintegral (∑ i ∈ s, μ i) = ∑ i ∈ s, f.lintegral (μ i) :=
map_sum (lintegralₗ f) ..
theorem lintegral_sum {m : MeasurableSpace α} {ι} (f : α →ₛ ℝ≥0∞) (μ : ι → Measure α) :
f.lintegral (Measure.sum μ) = ∑' i, f.lintegral (μ i) := by
simp only [lintegral, Measure.sum_apply, f.measurableSet_preimage, ← Finset.tsum_subtype, ←
ENNReal.tsum_mul_left]
apply ENNReal.tsum_comm
open scoped Classical in
theorem restrict_lintegral (f : α →ₛ ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) :
(restrict f s).lintegral μ = ∑ r ∈ f.range, r * μ (f ⁻¹' {r} ∩ s) :=
calc
(restrict f s).lintegral μ = ∑ r ∈ f.range, r * μ (restrict f s ⁻¹' {r}) :=
lintegral_eq_of_subset _ fun x hx =>
if hxs : x ∈ s then fun _ => by
simp only [f.restrict_apply hs, indicator_of_mem hxs, mem_range_self]
else False.elim <| hx <| by simp [*]
_ = ∑ r ∈ f.range, r * μ (f ⁻¹' {r} ∩ s) :=
Finset.sum_congr rfl <|
forall_mem_range.2 fun b =>
if hb : f b = 0 then by simp only [hb, zero_mul]
else by rw [restrict_preimage_singleton _ hs hb, inter_comm]
theorem lintegral_restrict {m : MeasurableSpace α} (f : α →ₛ ℝ≥0∞) (s : Set α) (μ : Measure α) :
f.lintegral (μ.restrict s) = ∑ y ∈ f.range, y * μ (f ⁻¹' {y} ∩ s) := by
simp only [lintegral, Measure.restrict_apply, f.measurableSet_preimage]
theorem restrict_lintegral_eq_lintegral_restrict (f : α →ₛ ℝ≥0∞) {s : Set α}
(hs : MeasurableSet s) : (restrict f s).lintegral μ = f.lintegral (μ.restrict s) := by
rw [f.restrict_lintegral hs, lintegral_restrict]
theorem lintegral_restrict_iUnion_of_directed {ι : Type*} [Countable ι]
(f : α →ₛ ℝ≥0∞) {s : ι → Set α} (hd : Directed (· ⊆ ·) s) (μ : Measure α) :
f.lintegral (μ.restrict (⋃ i, s i)) = ⨆ i, f.lintegral (μ.restrict (s i)) := by
simp only [lintegral, Measure.restrict_iUnion_apply_eq_iSup hd (measurableSet_preimage ..),
ENNReal.mul_iSup]
refine finsetSum_iSup fun i j ↦ (hd i j).imp fun k ⟨hik, hjk⟩ ↦ fun a ↦ ?_
-- TODO https://github.com/leanprover-community/mathlib4/pull/14739 make `gcongr` close this goal
constructor <;> · gcongr; refine Measure.restrict_mono ?_ le_rfl _; assumption
theorem const_lintegral (c : ℝ≥0∞) : (const α c).lintegral μ = c * μ univ := by
rw [lintegral]
cases isEmpty_or_nonempty α
· simp [μ.eq_zero_of_isEmpty]
· simp only [range_const, coe_const, Finset.sum_singleton]
unfold Function.const; rw [preimage_const_of_mem (mem_singleton c)]
| Mathlib/MeasureTheory/Function/SimpleFunc.lean | 969 | 981 | theorem const_lintegral_restrict (c : ℝ≥0∞) (s : Set α) :
(const α c).lintegral (μ.restrict s) = c * μ s := by | rw [const_lintegral, Measure.restrict_apply MeasurableSet.univ, univ_inter]
theorem restrict_const_lintegral (c : ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) :
((const α c).restrict s).lintegral μ = c * μ s := by
rw [restrict_lintegral_eq_lintegral_restrict _ hs, const_lintegral_restrict]
@[gcongr]
theorem lintegral_mono_fun {f g : α →ₛ ℝ≥0∞} (h : f ≤ g) : f.lintegral μ ≤ g.lintegral μ := by
refine Monotone.of_left_le_map_sup (f := (lintegral · μ)) (fun f g ↦ ?_) h
calc
f.lintegral μ = ((pair f g).map Prod.fst).lintegral μ := by rw [map_fst_pair] |
/-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Data.Finsupp.Defs
/-!
# Locus of unequal values of finitely supported functions
Let `α N` be two Types, assume that `N` has a `0` and let `f g : α →₀ N` be finitely supported
functions.
## Main definition
* `Finsupp.neLocus f g : Finset α`, the finite subset of `α` where `f` and `g` differ.
In the case in which `N` is an additive group, `Finsupp.neLocus f g` coincides with
`Finsupp.support (f - g)`.
-/
variable {α M N P : Type*}
namespace Finsupp
variable [DecidableEq α]
section NHasZero
variable [DecidableEq N] [Zero N] (f g : α →₀ N)
/-- Given two finitely supported functions `f g : α →₀ N`, `Finsupp.neLocus f g` is the `Finset`
where `f` and `g` differ. This generalizes `(f - g).support` to situations without subtraction. -/
def neLocus (f g : α →₀ N) : Finset α :=
(f.support ∪ g.support).filter fun x => f x ≠ g x
@[simp]
theorem mem_neLocus {f g : α →₀ N} {a : α} : a ∈ f.neLocus g ↔ f a ≠ g a := by
simpa only [neLocus, Finset.mem_filter, Finset.mem_union, mem_support_iff,
and_iff_right_iff_imp] using Ne.ne_or_ne _
theorem not_mem_neLocus {f g : α →₀ N} {a : α} : a ∉ f.neLocus g ↔ f a = g a :=
mem_neLocus.not.trans not_ne_iff
@[simp]
theorem coe_neLocus : ↑(f.neLocus g) = { x | f x ≠ g x } := by
ext
exact mem_neLocus
@[simp]
theorem neLocus_eq_empty {f g : α →₀ N} : f.neLocus g = ∅ ↔ f = g :=
⟨fun h =>
ext fun a => not_not.mp (mem_neLocus.not.mp (Finset.eq_empty_iff_forall_not_mem.mp h a)),
fun h => h ▸ by simp only [neLocus, Ne, eq_self_iff_true, not_true, Finset.filter_False]⟩
@[simp]
theorem nonempty_neLocus_iff {f g : α →₀ N} : (f.neLocus g).Nonempty ↔ f ≠ g :=
Finset.nonempty_iff_ne_empty.trans neLocus_eq_empty.not
theorem neLocus_comm : f.neLocus g = g.neLocus f := by
simp_rw [neLocus, Finset.union_comm, ne_comm]
@[simp]
theorem neLocus_zero_right : f.neLocus 0 = f.support := by
ext
rw [mem_neLocus, mem_support_iff, coe_zero, Pi.zero_apply]
@[simp]
theorem neLocus_zero_left : (0 : α →₀ N).neLocus f = f.support :=
(neLocus_comm _ _).trans (neLocus_zero_right _)
end NHasZero
section NeLocusAndMaps
theorem subset_mapRange_neLocus [DecidableEq N] [Zero N] [DecidableEq M] [Zero M] (f g : α →₀ N)
{F : N → M} (F0 : F 0 = 0) : (f.mapRange F F0).neLocus (g.mapRange F F0) ⊆ f.neLocus g :=
fun x => by simpa only [mem_neLocus, mapRange_apply, not_imp_not] using congr_arg F
theorem zipWith_neLocus_eq_left [DecidableEq N] [Zero M] [DecidableEq P] [Zero P] [Zero N]
{F : M → N → P} (F0 : F 0 0 = 0) (f : α →₀ M) (g₁ g₂ : α →₀ N)
(hF : ∀ f, Function.Injective fun g => F f g) :
(zipWith F F0 f g₁).neLocus (zipWith F F0 f g₂) = g₁.neLocus g₂ := by
ext
simpa only [mem_neLocus] using (hF _).ne_iff
theorem zipWith_neLocus_eq_right [DecidableEq M] [Zero M] [DecidableEq P] [Zero P] [Zero N]
{F : M → N → P} (F0 : F 0 0 = 0) (f₁ f₂ : α →₀ M) (g : α →₀ N)
(hF : ∀ g, Function.Injective fun f => F f g) :
(zipWith F F0 f₁ g).neLocus (zipWith F F0 f₂ g) = f₁.neLocus f₂ := by
ext
simpa only [mem_neLocus] using (hF _).ne_iff
theorem mapRange_neLocus_eq [DecidableEq N] [DecidableEq M] [Zero M] [Zero N] (f g : α →₀ N)
{F : N → M} (F0 : F 0 = 0) (hF : Function.Injective F) :
(f.mapRange F F0).neLocus (g.mapRange F F0) = f.neLocus g := by
ext
simpa only [mem_neLocus] using hF.ne_iff
end NeLocusAndMaps
variable [DecidableEq N]
@[simp]
theorem neLocus_add_left [AddLeftCancelMonoid N] (f g h : α →₀ N) :
(f + g).neLocus (f + h) = g.neLocus h :=
zipWith_neLocus_eq_left _ _ _ _ add_right_injective
@[simp]
theorem neLocus_add_right [AddRightCancelMonoid N] (f g h : α →₀ N) :
(f + h).neLocus (g + h) = f.neLocus g :=
zipWith_neLocus_eq_right _ _ _ _ add_left_injective
section AddGroup
variable [AddGroup N] (f f₁ f₂ g g₁ g₂ : α →₀ N)
@[simp]
theorem neLocus_neg_neg : neLocus (-f) (-g) = f.neLocus g :=
mapRange_neLocus_eq _ _ neg_zero neg_injective
theorem neLocus_neg : neLocus (-f) g = f.neLocus (-g) := by rw [← neLocus_neg_neg, neg_neg]
theorem neLocus_eq_support_sub : f.neLocus g = (f - g).support := by
rw [← neLocus_add_right _ _ (-g), add_neg_cancel, neLocus_zero_right, sub_eq_add_neg]
@[simp]
theorem neLocus_sub_left : neLocus (f - g₁) (f - g₂) = neLocus g₁ g₂ := by
simp only [sub_eq_add_neg, neLocus_add_left, neLocus_neg_neg]
@[simp]
theorem neLocus_sub_right : neLocus (f₁ - g) (f₂ - g) = neLocus f₁ f₂ := by
simpa only [sub_eq_add_neg] using neLocus_add_right _ _ _
@[simp]
theorem neLocus_self_add_right : neLocus f (f + g) = g.support := by
rw [← neLocus_zero_left, ← neLocus_add_left f 0 g, add_zero]
@[simp]
theorem neLocus_self_add_left : neLocus (f + g) f = g.support := by
rw [neLocus_comm, neLocus_self_add_right]
@[simp]
theorem neLocus_self_sub_right : neLocus f (f - g) = g.support := by
rw [sub_eq_add_neg, neLocus_self_add_right, support_neg]
@[simp]
| Mathlib/Data/Finsupp/NeLocus.lean | 149 | 150 | theorem neLocus_self_sub_left : neLocus (f - g) f = g.support := by | rw [neLocus_comm, neLocus_self_sub_right] |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.Tactic.FieldSimp
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.Basis
/-!
# Determinant of families of vectors
This file defines the determinant of an endomorphism, and of a family of vectors
with respect to some basis. For the determinant of a matrix, see the file
`LinearAlgebra.Matrix.Determinant`.
## Main definitions
In the list below, and in all this file, `R` is a commutative ring (semiring
is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite
types used for indexing.
* `Basis.det`: the determinant of a family of vectors with respect to a basis,
as a multilinear map
* `LinearMap.det`: the determinant of an endomorphism `f : End R M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
* `LinearEquiv.det`: the determinant of an isomorphism `f : M ≃ₗ[R] M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
## Tags
basis, det, determinant
-/
noncomputable section
open Matrix LinearMap Submodule Set Function
universe u v w
variable {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable {M' : Type*} [AddCommGroup M'] [Module R M']
variable {ι : Type*} [DecidableEq ι] [Fintype ι]
variable (e : Basis ι R M)
section Conjugate
variable {A : Type*} [CommRing A]
variable {m n : Type*}
/-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/
def equivOfPiLEquivPi {R : Type*} [Finite m] [Finite n] [CommRing R] [Nontrivial R]
(e : (m → R) ≃ₗ[R] n → R) : m ≃ n :=
Basis.indexEquiv (Basis.ofEquivFun e.symm) (Pi.basisFun _ _)
namespace Matrix
variable [Fintype m] [Fintype n]
/-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to
equivalence of types. -/
def indexEquivOfInv [Nontrivial A] [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : m ≃ n :=
equivOfPiLEquivPi (toLin'OfInv hMM' hM'M)
theorem det_comm [DecidableEq n] (M N : Matrix n n A) : det (M * N) = det (N * M) := by
rw [det_mul, det_mul, mul_comm]
/-- If there exists a two-sided inverse `M'` for `M` (indexed differently),
then `det (N * M) = det (M * N)`. -/
theorem det_comm' [DecidableEq m] [DecidableEq n] {M : Matrix n m A} {N : Matrix m n A}
{M' : Matrix m n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N) = det (N * M) := by
nontriviality A
-- Although `m` and `n` are different a priori, we will show they have the same cardinality.
-- This turns the problem into one for square matrices, which is easy.
let e := indexEquivOfInv hMM' hM'M
rw [← det_submatrix_equiv_self e, ← submatrix_mul_equiv _ _ _ (Equiv.refl n) _, det_comm,
submatrix_mul_equiv, Equiv.coe_refl, submatrix_id_id]
/-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M * N * M') = det N`.
See `Matrix.det_conj` and `Matrix.det_conj'` for the case when `M' = M⁻¹` or vice versa. -/
theorem det_conj_of_mul_eq_one [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} {N : Matrix n n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) :
det (M * N * M') = det N := by
rw [← det_comm' hM'M hMM', ← Matrix.mul_assoc, hM'M, Matrix.one_mul]
end Matrix
end Conjugate
namespace LinearMap
/-! ### Determinant of a linear map -/
variable {A : Type*} [CommRing A] [Module A M]
variable {κ : Type*} [Fintype κ]
/-- The determinant of `LinearMap.toMatrix` does not depend on the choice of basis. -/
theorem det_toMatrix_eq_det_toMatrix [DecidableEq κ] (b : Basis ι A M) (c : Basis κ A M)
(f : M →ₗ[A] M) : det (LinearMap.toMatrix b b f) = det (LinearMap.toMatrix c c f) := by
rw [← linearMap_toMatrix_mul_basis_toMatrix c b c, ← basis_toMatrix_mul_linearMap_toMatrix b c b,
Matrix.det_conj_of_mul_eq_one] <;>
rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self]
/-- The determinant of an endomorphism given a basis.
See `LinearMap.det` for a version that populates the basis non-computably.
Although the `Trunc (Basis ι A M)` parameter makes it slightly more convenient to switch bases,
there is no good way to generalize over universe parameters, so we can't fully state in `detAux`'s
type that it does not depend on the choice of basis. Instead you can use the `detAux_def''` lemma,
or avoid mentioning a basis at all using `LinearMap.det`.
-/
irreducible_def detAux : Trunc (Basis ι A M) → (M →ₗ[A] M) →* A :=
Trunc.lift
(fun b : Basis ι A M => detMonoidHom.comp (toMatrixAlgEquiv b : (M →ₗ[A] M) →* Matrix ι ι A))
fun b c => MonoidHom.ext <| det_toMatrix_eq_det_toMatrix b c
/-- Unfold lemma for `detAux`.
See also `detAux_def''` which allows you to vary the basis.
-/
theorem detAux_def' (b : Basis ι A M) (f : M →ₗ[A] M) :
LinearMap.detAux (Trunc.mk b) f = Matrix.det (LinearMap.toMatrix b b f) := by
rw [detAux]
rfl
theorem detAux_def'' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (tb : Trunc <| Basis ι A M)
(b' : Basis ι' A M) (f : M →ₗ[A] M) :
LinearMap.detAux tb f = Matrix.det (LinearMap.toMatrix b' b' f) := by
induction tb using Trunc.induction_on with
| h b => rw [detAux_def', det_toMatrix_eq_det_toMatrix b b']
@[simp]
theorem detAux_id (b : Trunc <| Basis ι A M) : LinearMap.detAux b LinearMap.id = 1 :=
(LinearMap.detAux b).map_one
@[simp]
theorem detAux_comp (b : Trunc <| Basis ι A M) (f g : M →ₗ[A] M) :
LinearMap.detAux b (f.comp g) = LinearMap.detAux b f * LinearMap.detAux b g :=
(LinearMap.detAux b).map_mul f g
section
open scoped Classical in
-- Discourage the elaborator from unfolding `det` and producing a huge term by marking it
-- as irreducible.
/-- The determinant of an endomorphism independent of basis.
If there is no finite basis on `M`, the result is `1` instead.
-/
protected irreducible_def det : (M →ₗ[A] M) →* A :=
if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1
open scoped Classical in
theorem coe_det [DecidableEq M] :
⇑(LinearMap.det : (M →ₗ[A] M) →* A) =
if H : ∃ s : Finset M, Nonempty (Basis s A M) then
LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1 := by
ext
rw [LinearMap.det_def]
split_ifs
· congr -- use the correct `DecidableEq` instance
rfl
end
-- Auxiliary lemma, the `simp` normal form goes in the other direction
-- (using `LinearMap.det_toMatrix`)
theorem det_eq_det_toMatrix_of_finset [DecidableEq M] {s : Finset M} (b : Basis s A M)
(f : M →ₗ[A] M) : LinearMap.det f = Matrix.det (LinearMap.toMatrix b b f) := by
have : ∃ s : Finset M, Nonempty (Basis s A M) := ⟨s, ⟨b⟩⟩
rw [LinearMap.coe_det, dif_pos, detAux_def'' _ b] <;> assumption
@[simp]
theorem det_toMatrix (b : Basis ι A M) (f : M →ₗ[A] M) :
Matrix.det (toMatrix b b f) = LinearMap.det f := by
haveI := Classical.decEq M
rw [det_eq_det_toMatrix_of_finset b.reindexFinsetRange,
det_toMatrix_eq_det_toMatrix b b.reindexFinsetRange]
@[simp]
theorem det_toMatrix' {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → A) →ₗ[A] ι → A) :
Matrix.det (LinearMap.toMatrix' f) = LinearMap.det f := by simp [← toMatrix_eq_toMatrix']
@[simp]
theorem det_toLin (b : Basis ι R M) (f : Matrix ι ι R) :
LinearMap.det (Matrix.toLin b b f) = f.det := by
rw [← LinearMap.det_toMatrix b, LinearMap.toMatrix_toLin]
@[simp]
theorem det_toLin' (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin' f) = Matrix.det f := by
simp only [← toLin_eq_toLin', det_toLin]
/-- To show `P (LinearMap.det f)` it suffices to consider `P (Matrix.det (toMatrix _ _ f))` and
`P 1`. -/
@[elab_as_elim]
theorem det_cases [DecidableEq M] {P : A → Prop} (f : M →ₗ[A] M)
(hb : ∀ (s : Finset M) (b : Basis s A M), P (Matrix.det (toMatrix b b f))) (h1 : P 1) :
P (LinearMap.det f) := by
classical
if H : ∃ s : Finset M, Nonempty (Basis s A M) then
obtain ⟨s, ⟨b⟩⟩ := H
rw [← det_toMatrix b]
exact hb s b
else
rwa [LinearMap.det_def, dif_neg H]
@[simp]
theorem det_comp (f g : M →ₗ[A] M) :
LinearMap.det (f.comp g) = LinearMap.det f * LinearMap.det g :=
LinearMap.det.map_mul f g
@[simp]
theorem det_id : LinearMap.det (LinearMap.id : M →ₗ[A] M) = 1 :=
LinearMap.det.map_one
/-- Multiplying a map by a scalar `c` multiplies its determinant by `c ^ dim M`. -/
@[simp]
theorem det_smul [Module.Free A M] (c : A) (f : M →ₗ[A] M) :
LinearMap.det (c • f) = c ^ Module.finrank A M * LinearMap.det f := by
nontriviality A
by_cases H : ∃ s : Finset M, Nonempty (Basis s A M)
· have : Module.Finite A M := by
rcases H with ⟨s, ⟨hs⟩⟩
exact Module.Finite.of_basis hs
simp only [← det_toMatrix (Module.finBasis A M), LinearEquiv.map_smul,
Fintype.card_fin, Matrix.det_smul]
· classical
have : Module.finrank A M = 0 := finrank_eq_zero_of_not_exists_basis H
simp [coe_det, H, this]
theorem det_zero' {ι : Type*} [Finite ι] [Nonempty ι] (b : Basis ι A M) :
LinearMap.det (0 : M →ₗ[A] M) = 0 := by
haveI := Classical.decEq ι
cases nonempty_fintype ι
rwa [← det_toMatrix b, LinearEquiv.map_zero, det_zero]
/-- In a finite-dimensional vector space, the zero map has determinant `1` in dimension `0`,
and `0` otherwise. We give a formula that also works in infinite dimension, where we define
the determinant to be `1`. -/
@[simp]
theorem det_zero [Module.Free A M] :
LinearMap.det (0 : M →ₗ[A] M) = (0 : A) ^ Module.finrank A M := by
simp only [← zero_smul A (1 : M →ₗ[A] M), det_smul, mul_one, MonoidHom.map_one]
theorem det_eq_one_of_not_module_finite (h : ¬Module.Finite R M) (f : M →ₗ[R] M) : f.det = 1 := by
rw [LinearMap.det, dif_neg, MonoidHom.one_apply]
exact fun ⟨_, ⟨b⟩⟩ ↦ h (Module.Finite.of_basis b)
theorem det_eq_one_of_subsingleton [Subsingleton M] (f : M →ₗ[R] M) :
LinearMap.det (f : M →ₗ[R] M) = 1 := by
have b : Basis (Fin 0) R M := Basis.empty M
rw [← f.det_toMatrix b]
exact Matrix.det_isEmpty
theorem det_eq_one_of_finrank_eq_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M]
[Module 𝕜 M] (h : Module.finrank 𝕜 M = 0) (f : M →ₗ[𝕜] M) :
LinearMap.det (f : M →ₗ[𝕜] M) = 1 := by
classical
refine @LinearMap.det_cases M _ 𝕜 _ _ _ (fun t => t = 1) f ?_ rfl
intro s b
have : IsEmpty s := by
rw [← Fintype.card_eq_zero_iff]
exact (Module.finrank_eq_card_basis b).symm.trans h
exact Matrix.det_isEmpty
/-- Conjugating a linear map by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj {N : Type*} [AddCommGroup N] [Module A N] (f : M →ₗ[A] M) (e : M ≃ₗ[A] N) :
LinearMap.det ((e : M →ₗ[A] N) ∘ₗ f ∘ₗ (e.symm : N →ₗ[A] M)) = LinearMap.det f := by
classical
by_cases H : ∃ s : Finset M, Nonempty (Basis s A M)
· rcases H with ⟨s, ⟨b⟩⟩
rw [← det_toMatrix b f, ← det_toMatrix (b.map e), toMatrix_comp (b.map e) b (b.map e),
toMatrix_comp (b.map e) b b, ← Matrix.mul_assoc, Matrix.det_conj_of_mul_eq_one]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.symm_trans_self, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.self_trans_symm, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· have H' : ¬∃ t : Finset N, Nonempty (Basis t A N) := by
contrapose! H
rcases H with ⟨s, ⟨b⟩⟩
exact ⟨_, ⟨(b.map e.symm).reindexFinsetRange⟩⟩
simp only [coe_det, H, H', MonoidHom.one_apply, dif_neg, not_false_eq_true]
/-- If a linear map is invertible, so is its determinant. -/
theorem isUnit_det {A : Type*} [CommRing A] [Module A M] (f : M →ₗ[A] M) (hf : IsUnit f) :
IsUnit (LinearMap.det f) := by
obtain ⟨g, hg⟩ : ∃ g, f.comp g = 1 := hf.exists_right_inv
have : LinearMap.det f * LinearMap.det g = 1 := by
simp only [← LinearMap.det_comp, hg, MonoidHom.map_one]
exact isUnit_of_mul_eq_one _ _ this
/-- If a linear map has determinant different from `1`, then the space is finite-dimensional. -/
theorem finiteDimensional_of_det_ne_one {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M →ₗ[𝕜] M)
(hf : LinearMap.det f ≠ 1) : FiniteDimensional 𝕜 M := by
by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M)
· rcases H with ⟨s, ⟨hs⟩⟩
exact FiniteDimensional.of_fintype_basis hs
· classical simp [LinearMap.coe_det, H] at hf
/-- If the determinant of a map vanishes, then the map is not onto. -/
theorem range_lt_top_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : LinearMap.range f < ⊤ := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [lt_top_iff_ne_top, Classical.not_not, ← isUnit_iff_range_eq_top] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
/-- If the determinant of a map vanishes, then the map is not injective. -/
theorem bot_lt_ker_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : ⊥ < LinearMap.ker f := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [bot_lt_iff_ne_bot, Classical.not_not, ← isUnit_iff_ker_eq_bot] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
/-- When the function is over the base ring, the determinant is the evaluation at `1`. -/
@[simp] lemma det_ring (f : R →ₗ[R] R) : f.det = f 1 := by
simp [← det_toMatrix (Basis.singleton Unit R)]
lemma det_mulLeft (a : R) : (mulLeft R a).det = a := by simp
lemma det_mulRight (a : R) : (mulRight R a).det = a := by simp
theorem det_prodMap [Module.Free R M] [Module.Free R M'] [Module.Finite R M] [Module.Finite R M']
(f : Module.End R M) (f' : Module.End R M') :
(prodMap f f').det = f.det * f'.det := by
let b := Module.Free.chooseBasis R M
let b' := Module.Free.chooseBasis R M'
rw [← det_toMatrix (b.prod b'), ← det_toMatrix b, ← det_toMatrix b', toMatrix_prodMap,
det_fromBlocks_zero₂₁, det_toMatrix]
omit [DecidableEq ι] in
theorem det_pi [Module.Free R M] [Module.Finite R M] (f : ι → M →ₗ[R] M) :
(LinearMap.pi (fun i ↦ (f i).comp (LinearMap.proj i))).det = ∏ i, (f i).det := by
classical
let b := Module.Free.chooseBasis R M
let B := (Pi.basis (fun _ : ι ↦ b)).reindex <|
(Equiv.sigmaEquivProd _ _).trans (Equiv.prodComm _ _)
simp_rw [← LinearMap.det_toMatrix B, ← LinearMap.det_toMatrix b]
have : ((LinearMap.toMatrix B B) (LinearMap.pi fun i ↦ f i ∘ₗ LinearMap.proj i)) =
Matrix.blockDiagonal (fun i ↦ LinearMap.toMatrix b b (f i)) := by
ext ⟨i₁, i₂⟩ ⟨j₁, j₂⟩
unfold B
simp_rw [LinearMap.toMatrix_apply', Matrix.blockDiagonal_apply, Basis.coe_reindex,
Function.comp_apply, Basis.repr_reindex_apply, Equiv.symm_trans_apply, Equiv.prodComm_symm,
Equiv.prodComm_apply, Equiv.sigmaEquivProd_symm_apply, Prod.swap_prod_mk, Pi.basis_apply,
Pi.basis_repr, LinearMap.pi_apply, LinearMap.coe_comp, Function.comp_apply,
LinearMap.toMatrix_apply', LinearMap.coe_proj, Function.eval, Pi.single_apply]
split_ifs with h
· rw [h]
· simp only [map_zero, Finsupp.coe_zero, Pi.zero_apply]
rw [this, Matrix.det_blockDiagonal]
end LinearMap
namespace LinearEquiv
/-- On a `LinearEquiv`, the domain of `LinearMap.det` can be promoted to `Rˣ`. -/
protected def det : (M ≃ₗ[R] M) →* Rˣ :=
(Units.map (LinearMap.det : (M →ₗ[R] M) →* R)).comp
(LinearMap.GeneralLinearGroup.generalLinearEquiv R M).symm.toMonoidHom
@[simp]
theorem coe_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f) = LinearMap.det (f : M →ₗ[R] M) :=
rfl
@[simp]
theorem coe_inv_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f)⁻¹ = LinearMap.det (f.symm : M →ₗ[R] M) :=
rfl
@[simp]
theorem det_refl : LinearEquiv.det (LinearEquiv.refl R M) = 1 :=
Units.ext <| LinearMap.det_id
@[simp]
theorem det_trans (f g : M ≃ₗ[R] M) :
LinearEquiv.det (f.trans g) = LinearEquiv.det g * LinearEquiv.det f :=
map_mul _ g f
@[simp]
theorem det_symm (f : M ≃ₗ[R] M) : LinearEquiv.det f.symm = LinearEquiv.det f⁻¹ :=
map_inv _ f
/-- Conjugating a linear equiv by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj (f : M ≃ₗ[R] M) (e : M ≃ₗ[R] M') :
LinearEquiv.det ((e.symm.trans f).trans e) = LinearEquiv.det f := by
rw [← Units.eq_iff, coe_det, coe_det, ← comp_coe, ← comp_coe, LinearMap.det_conj]
attribute [irreducible] LinearEquiv.det
end LinearEquiv
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_mul_det_symm {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f : M →ₗ[A] M) * LinearMap.det (f.symm : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_symm_mul_det {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f.symm : M →ₗ[A] M) * LinearMap.det (f : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
-- Cannot be stated using `LinearMap.det` because `f` is not an endomorphism.
theorem LinearEquiv.isUnit_det (f : M ≃ₗ[R] M') (v : Basis ι R M) (v' : Basis ι R M') :
IsUnit (LinearMap.toMatrix v v' f).det := by
apply isUnit_det_of_left_inverse
simpa using (LinearMap.toMatrix_comp v v' v f.symm f).symm
/-- Specialization of `LinearEquiv.isUnit_det` -/
theorem LinearEquiv.isUnit_det' {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
IsUnit (LinearMap.det (f : M →ₗ[A] M)) :=
isUnit_of_mul_eq_one _ _ f.det_mul_det_symm
/-- The determinant of `f.symm` is the inverse of that of `f` when `f` is a linear equiv. -/
theorem LinearEquiv.det_coe_symm {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M ≃ₗ[𝕜] M) :
LinearMap.det (f.symm : M →ₗ[𝕜] M) = (LinearMap.det (f : M →ₗ[𝕜] M))⁻¹ := by
field_simp [IsUnit.ne_zero f.isUnit_det']
/-- Builds a linear equivalence from a linear map whose determinant in some bases is a unit. -/
@[simps]
def LinearEquiv.ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) : M ≃ₗ[R] M' where
toFun := f
map_add' := f.map_add
map_smul' := f.map_smul
invFun := toLin v' v (toMatrix v v' f)⁻¹
left_inv x :=
calc toLin v' v (toMatrix v v' f)⁻¹ (f x)
_ = toLin v v ((toMatrix v v' f)⁻¹ * toMatrix v v' f) x := by
rw [toLin_mul v v' v, toLin_toMatrix, LinearMap.comp_apply]
_ = x := by simp [h]
right_inv x :=
calc f (toLin v' v (toMatrix v v' f)⁻¹ x)
_ = toLin v' v' (toMatrix v v' f * (toMatrix v v' f)⁻¹) x := by
rw [toLin_mul v' v v', LinearMap.comp_apply, toLin_toMatrix v v']
_ = x := by simp [h]
@[simp]
theorem LinearEquiv.coe_ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) :
(LinearEquiv.ofIsUnitDet h : M →ₗ[R] M') = f := by
ext x
rfl
/-- Builds a linear equivalence from a linear map on a finite-dimensional vector space whose
determinant is nonzero. -/
abbrev LinearMap.equivOfDetNeZero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M]
[FiniteDimensional 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 0) : M ≃ₗ[𝕜] M :=
have : IsUnit (LinearMap.toMatrix (Module.finBasis 𝕜 M)
(Module.finBasis 𝕜 M) f).det := by
rw [LinearMap.det_toMatrix]
exact isUnit_iff_ne_zero.2 hf
LinearEquiv.ofIsUnitDet this
theorem LinearMap.associated_det_of_eq_comp (e : M ≃ₗ[R] M) (f f' : M →ₗ[R] M)
(h : ∀ x, f x = f' (e x)) : Associated (LinearMap.det f) (LinearMap.det f') := by
suffices Associated (LinearMap.det (f' ∘ₗ ↑e)) (LinearMap.det f') by
convert this using 2
ext x
exact h x
rw [← mul_one (LinearMap.det f'), LinearMap.det_comp]
exact Associated.mul_left _ (associated_one_iff_isUnit.mpr e.isUnit_det')
theorem LinearMap.associated_det_comp_equiv {N : Type*} [AddCommGroup N] [Module R N]
(f : N →ₗ[R] M) (e e' : M ≃ₗ[R] N) :
Associated (LinearMap.det (f ∘ₗ ↑e)) (LinearMap.det (f ∘ₗ ↑e')) := by
refine LinearMap.associated_det_of_eq_comp (e.trans e'.symm) _ _ ?_
intro x
simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, LinearEquiv.trans_apply,
LinearEquiv.apply_symm_apply]
/-- The determinant of a family of vectors with respect to some basis, as an alternating
multilinear map. -/
nonrec def Basis.det : M [⋀^ι]→ₗ[R] R where
toMultilinearMap :=
MultilinearMap.mk' (fun v ↦ det (e.toMatrix v))
(fun v i x y ↦ by
simp only [e.toMatrix_update, map_add, Finsupp.coe_add, det_updateCol_add])
(fun u i c x ↦ by
simp only [e.toMatrix_update, Algebra.id.smul_eq_mul, LinearEquiv.map_smul]
apply det_updateCol_smul)
map_eq_zero_of_eq' := by
intro v i j h hij
dsimp
rw [← Function.update_eq_self i v, h, ← det_transpose, e.toMatrix_update, ← updateRow_transpose,
← e.toMatrix_transpose_apply]
apply det_zero_of_row_eq hij
rw [updateRow_ne hij.symm, updateRow_self]
theorem Basis.det_apply (v : ι → M) : e.det v = Matrix.det (e.toMatrix v) :=
rfl
theorem Basis.det_self : e.det e = 1 := by simp [e.det_apply]
@[simp]
theorem Basis.det_isEmpty [IsEmpty ι] : e.det = AlternatingMap.constOfIsEmpty R M ι 1 := by
ext v
exact Matrix.det_isEmpty
/-- `Basis.det` is not the zero map. -/
theorem Basis.det_ne_zero [Nontrivial R] : e.det ≠ 0 := fun h => by simpa [h] using e.det_self
theorem Basis.smul_det {G} [Group G] [DistribMulAction G M] [SMulCommClass G R M]
(g : G) (v : ι → M) :
(g • e).det v = e.det (g⁻¹ • v) := by
simp_rw [det_apply, toMatrix_smul_left]
theorem is_basis_iff_det {v : ι → M} :
LinearIndependent R v ∧ span R (Set.range v) = ⊤ ↔ IsUnit (e.det v) := by
constructor
· rintro ⟨hli, hspan⟩
set v' := Basis.mk hli hspan.ge
rw [e.det_apply]
convert LinearEquiv.isUnit_det (LinearEquiv.refl R M) v' e using 2
ext i j
simp [v']
· intro h
rw [Basis.det_apply, Basis.toMatrix_eq_toMatrix_constr] at h
set v' := Basis.map e (LinearEquiv.ofIsUnitDet h) with v'_def
have : ⇑v' = v := by
ext i
rw [v'_def, Basis.map_apply, LinearEquiv.ofIsUnitDet_apply, e.constr_basis]
rw [← this]
exact ⟨v'.linearIndependent, v'.span_eq⟩
theorem Basis.isUnit_det (e' : Basis ι R M) : IsUnit (e.det e') :=
(is_basis_iff_det e).mp ⟨e'.linearIndependent, e'.span_eq⟩
/-- Any alternating map to `R` where `ι` has the cardinality of a basis equals the determinant
map with respect to that basis, multiplied by the value of that alternating map on that basis. -/
theorem AlternatingMap.eq_smul_basis_det (f : M [⋀^ι]→ₗ[R] R) : f = f e • e.det := by
refine Basis.ext_alternating e fun i h => ?_
let σ : Equiv.Perm ι := Equiv.ofBijective i (Finite.injective_iff_bijective.1 h)
change f (e ∘ σ) = (f e • e.det) (e ∘ σ)
simp [AlternatingMap.map_perm, Basis.det_self]
@[simp]
theorem AlternatingMap.map_basis_eq_zero_iff {ι : Type*} [Finite ι] (e : Basis ι R M)
(f : M [⋀^ι]→ₗ[R] R) : f e = 0 ↔ f = 0 :=
⟨fun h => by
cases nonempty_fintype ι
letI := Classical.decEq ι
simpa [h] using f.eq_smul_basis_det e,
fun h => h.symm ▸ AlternatingMap.zero_apply _⟩
theorem AlternatingMap.map_basis_ne_zero_iff {ι : Type*} [Finite ι] (e : Basis ι R M)
(f : M [⋀^ι]→ₗ[R] R) : f e ≠ 0 ↔ f ≠ 0 :=
not_congr <| f.map_basis_eq_zero_iff e
variable {A : Type*} [CommRing A] [Module A M]
@[simp]
theorem Basis.det_comp (e : Basis ι A M) (f : M →ₗ[A] M) (v : ι → M) :
e.det (f ∘ v) = (LinearMap.det f) * e.det v := by
rw [Basis.det_apply, Basis.det_apply, ← f.det_toMatrix e, ← Matrix.det_mul,
e.toMatrix_eq_toMatrix_constr (f ∘ v), e.toMatrix_eq_toMatrix_constr v, ← toMatrix_comp,
e.constr_comp]
@[simp]
theorem Basis.det_comp_basis [Module A M'] (b : Basis ι A M) (b' : Basis ι A M') (f : M →ₗ[A] M') :
b'.det (f ∘ b) = LinearMap.det (f ∘ₗ (b'.equiv b (Equiv.refl ι) : M' →ₗ[A] M)) := by
rw [Basis.det_apply, ← LinearMap.det_toMatrix b', LinearMap.toMatrix_comp _ b, Matrix.det_mul,
LinearMap.toMatrix_basis_equiv, Matrix.det_one, mul_one]
congr 1; ext i j
rw [Basis.toMatrix_apply, LinearMap.toMatrix_apply, Function.comp_apply]
@[simp]
theorem Basis.det_basis (b : Basis ι A M) (b' : Basis ι A M) :
LinearMap.det (b'.equiv b (Equiv.refl ι)).toLinearMap = b'.det b :=
(b.det_comp_basis b' (LinearMap.id)).symm
theorem Basis.det_inv (b : Basis ι A M) (b' : Basis ι A M) :
(b.isUnit_det b').unit⁻¹ = b'.det b := by
rw [← Units.mul_eq_one_iff_inv_eq, IsUnit.unit_spec, ← Basis.det_basis, ← Basis.det_basis]
exact LinearEquiv.det_mul_det_symm _
theorem Basis.det_reindex {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M) (v : ι' → M)
(e : ι ≃ ι') : (b.reindex e).det v = b.det (v ∘ e) := by
rw [Basis.det_apply, Basis.toMatrix_reindex', det_reindexAlgEquiv, Basis.det_apply]
theorem Basis.det_reindex' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M)
(e : ι ≃ ι') : (b.reindex e).det = b.det.domDomCongr e :=
AlternatingMap.ext fun _ => Basis.det_reindex _ _ _
theorem Basis.det_reindex_symm {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M)
(v : ι → M) (e : ι' ≃ ι) : (b.reindex e.symm).det (v ∘ e) = b.det v := by
rw [Basis.det_reindex, Function.comp_assoc, e.self_comp_symm, Function.comp_id]
@[simp]
theorem Basis.det_map (b : Basis ι R M) (f : M ≃ₗ[R] M') (v : ι → M') :
(b.map f).det v = b.det (f.symm ∘ v) := by
rw [Basis.det_apply, Basis.toMatrix_map, Basis.det_apply]
theorem Basis.det_map' (b : Basis ι R M) (f : M ≃ₗ[R] M') :
(b.map f).det = b.det.compLinearMap f.symm :=
AlternatingMap.ext <| b.det_map f
@[simp]
theorem Pi.basisFun_det : (Pi.basisFun R ι).det = Matrix.detRowAlternating := by
ext M
rw [Basis.det_apply, Basis.coePiBasisFun.toMatrix_eq_transpose, det_transpose]
theorem Pi.basisFun_det_apply (v : ι → ι → R) :
(Pi.basisFun R ι).det v = (Matrix.of v).det := by
rw [Pi.basisFun_det]
rfl
/-- If we fix a background basis `e`, then for any other basis `v`, we can characterise the
coordinates provided by `v` in terms of determinants relative to `e`. -/
theorem Basis.det_smul_mk_coord_eq_det_update {v : ι → M} (hli : LinearIndependent R v)
(hsp : ⊤ ≤ span R (range v)) (i : ι) :
e.det v • (Basis.mk hli hsp).coord i = e.det.toMultilinearMap.toLinearMap v i := by
apply (Basis.mk hli hsp).ext
intro k
rcases eq_or_ne k i with (rfl | hik) <;>
simp only [Algebra.id.smul_eq_mul, Basis.coe_mk, LinearMap.smul_apply, LinearMap.coe_mk,
MultilinearMap.toLinearMap_apply]
· rw [Basis.mk_coord_apply_eq, mul_one, update_eq_self]
congr
· rw [Basis.mk_coord_apply_ne hik, mul_zero, eq_comm]
exact e.det.map_eq_zero_of_eq _ (by simp [hik, Function.update_apply]) hik
/-- If a basis is multiplied columnwise by scalars `w : ι → Rˣ`, then the determinant with respect
to this basis is multiplied by the product of the inverse of these scalars. -/
| Mathlib/LinearAlgebra/Determinant.lean | 643 | 654 | theorem Basis.det_unitsSMul (e : Basis ι R M) (w : ι → Rˣ) :
(e.unitsSMul w).det = (↑(∏ i, w i)⁻¹ : R) • e.det := by | ext f
change
(Matrix.det fun i j => (e.unitsSMul w).repr (f j) i) =
(↑(∏ i, w i)⁻¹ : R) • Matrix.det fun i j => e.repr (f j) i
simp only [e.repr_unitsSMul]
convert Matrix.det_mul_column (fun i => (↑(w i)⁻¹ : R)) fun i j => e.repr (f j) i
simp [← Finset.prod_inv_distrib]
/-- The determinant of a basis constructed by `unitsSMul` is the product of the given units. -/
@[simp] |
/-
Copyright (c) 2021 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.Algebra.Group.Subgroup.Pointwise
import Mathlib.GroupTheory.Coset.Basic
/-!
# Double cosets
This file defines double cosets for two subgroups `H K` of a group `G` and the quotient of `G` by
the double coset relation, i.e. `H \ G / K`. We also prove that `G` can be written as a disjoint
union of the double cosets and that if one of `H` or `K` is the trivial group (i.e. `⊥` ) then
this is the usual left or right quotient of a group by a subgroup.
## Main definitions
* `rel`: The double coset relation defined by two subgroups `H K` of `G`.
* `Doset.quotient`: The quotient of `G` by the double coset relation, i.e, `H \ G / K`.
-/
assert_not_exists MonoidWithZero
variable {G : Type*} [Group G] {α : Type*} [Mul α]
open MulOpposite
open scoped Pointwise
namespace Doset
/-- The double coset as an element of `Set α` corresponding to `s a t` -/
def doset (a : α) (s t : Set α) : Set α :=
s * {a} * t
lemma doset_eq_image2 (a : α) (s t : Set α) : doset a s t = Set.image2 (· * a * ·) s t := by
simp_rw [doset, Set.mul_singleton, ← Set.image2_mul, Set.image2_image_left]
theorem mem_doset {s t : Set α} {a b : α} : b ∈ doset a s t ↔ ∃ x ∈ s, ∃ y ∈ t, b = x * a * y := by
simp only [doset_eq_image2, Set.mem_image2, eq_comm]
theorem mem_doset_self (H K : Subgroup G) (a : G) : a ∈ doset a H K :=
mem_doset.mpr ⟨1, H.one_mem, 1, K.one_mem, (one_mul a).symm.trans (mul_one (1 * a)).symm⟩
theorem doset_eq_of_mem {H K : Subgroup G} {a b : G} (hb : b ∈ doset a H K) :
doset b H K = doset a H K := by
obtain ⟨h, hh, k, hk, rfl⟩ := mem_doset.1 hb
rw [doset, doset, ← Set.singleton_mul_singleton, ← Set.singleton_mul_singleton, mul_assoc,
mul_assoc, Subgroup.singleton_mul_subgroup hk, ← mul_assoc, ← mul_assoc,
Subgroup.subgroup_mul_singleton hh]
| Mathlib/GroupTheory/DoubleCoset.lean | 52 | 57 | theorem mem_doset_of_not_disjoint {H K : Subgroup G} {a b : G}
(h : ¬Disjoint (doset a H K) (doset b H K)) : b ∈ doset a H K := by | rw [Set.not_disjoint_iff] at h
simp only [mem_doset] at *
obtain ⟨x, ⟨l, hl, r, hr, hrx⟩, y, hy, ⟨r', hr', rfl⟩⟩ := h
refine ⟨y⁻¹ * l, H.mul_mem (H.inv_mem hy) hl, r * r'⁻¹, K.mul_mem hr (K.inv_mem hr'), ?_⟩ |
/-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Yury Kudryashov
-/
import Mathlib.Topology.Algebra.Module.Equiv
import Mathlib.Topology.Algebra.Module.UniformConvergence
import Mathlib.Topology.Algebra.SeparationQuotient.Section
import Mathlib.Topology.Hom.ContinuousEvalConst
/-!
# Strong topologies on the space of continuous linear maps
In this file, we define the strong topologies on `E →L[𝕜] F` associated with a family
`𝔖 : Set (Set E)` to be the topology of uniform convergence on the elements of `𝔖` (also called
the topology of `𝔖`-convergence).
The lemma `UniformOnFun.continuousSMul_of_image_bounded` tells us that this is a
vector space topology if the continuous linear image of any element of `𝔖` is bounded (in the sense
of `Bornology.IsVonNBounded`).
We then declare an instance for the case where `𝔖` is exactly the set of all bounded subsets of
`E`, giving us the so-called "topology of uniform convergence on bounded sets" (or "topology of
bounded convergence"), which coincides with the operator norm topology in the case of
`NormedSpace`s.
Other useful examples include the weak-* topology (when `𝔖` is the set of finite sets or the set
of singletons) and the topology of compact convergence (when `𝔖` is the set of relatively compact
sets).
## Main definitions
* `UniformConvergenceCLM` is a type synonym for `E →SL[σ] F` equipped with the `𝔖`-topology.
* `UniformConvergenceCLM.instTopologicalSpace` is the topology mentioned above for an arbitrary `𝔖`.
* `ContinuousLinearMap.topologicalSpace` is the topology of bounded convergence. This is
declared as an instance.
## Main statements
* `UniformConvergenceCLM.instIsTopologicalAddGroup` and
`UniformConvergenceCLM.instContinuousSMul` show that the strong topology
makes `E →L[𝕜] F` a topological vector space, with the assumptions on `𝔖` mentioned above.
* `ContinuousLinearMap.topologicalAddGroup` and
`ContinuousLinearMap.continuousSMul` register these facts as instances for the special
case of bounded convergence.
## References
* [N. Bourbaki, *Topological Vector Spaces*][bourbaki1987]
## TODO
* Add convergence on compact subsets
## Tags
uniform convergence, bounded convergence
-/
open Bornology Filter Function Set Topology
open scoped UniformConvergence Uniformity
section General
/-! ### 𝔖-Topologies -/
variable {𝕜₁ 𝕜₂ : Type*} [NormedField 𝕜₁] [NormedField 𝕜₂] (σ : 𝕜₁ →+* 𝕜₂) {E F : Type*}
[AddCommGroup E] [Module 𝕜₁ E] [TopologicalSpace E]
[AddCommGroup F] [Module 𝕜₂ F]
variable (F)
/-- Given `E` and `F` two topological vector spaces and `𝔖 : Set (Set E)`, then
`UniformConvergenceCLM σ F 𝔖` is a type synonym of `E →SL[σ] F` equipped with the "topology of
uniform convergence on the elements of `𝔖`".
If the continuous linear image of any element of `𝔖` is bounded, this makes `E →SL[σ] F` a
topological vector space. -/
@[nolint unusedArguments]
def UniformConvergenceCLM [TopologicalSpace F] (_ : Set (Set E)) := E →SL[σ] F
namespace UniformConvergenceCLM
instance instFunLike [TopologicalSpace F] (𝔖 : Set (Set E)) :
FunLike (UniformConvergenceCLM σ F 𝔖) E F :=
ContinuousLinearMap.funLike
instance instContinuousSemilinearMapClass [TopologicalSpace F] (𝔖 : Set (Set E)) :
ContinuousSemilinearMapClass (UniformConvergenceCLM σ F 𝔖) σ E F :=
ContinuousLinearMap.continuousSemilinearMapClass
instance instTopologicalSpace [TopologicalSpace F] [IsTopologicalAddGroup F] (𝔖 : Set (Set E)) :
TopologicalSpace (UniformConvergenceCLM σ F 𝔖) :=
(@UniformOnFun.topologicalSpace E F (IsTopologicalAddGroup.toUniformSpace F) 𝔖).induced
(DFunLike.coe : (UniformConvergenceCLM σ F 𝔖) → (E →ᵤ[𝔖] F))
theorem topologicalSpace_eq [UniformSpace F] [IsUniformAddGroup F] (𝔖 : Set (Set E)) :
instTopologicalSpace σ F 𝔖 = TopologicalSpace.induced (UniformOnFun.ofFun 𝔖 ∘ DFunLike.coe)
(UniformOnFun.topologicalSpace E F 𝔖) := by
rw [instTopologicalSpace]
congr
exact IsUniformAddGroup.toUniformSpace_eq
/-- The uniform structure associated with `ContinuousLinearMap.strongTopology`. We make sure
that this has nice definitional properties. -/
instance instUniformSpace [UniformSpace F] [IsUniformAddGroup F]
(𝔖 : Set (Set E)) : UniformSpace (UniformConvergenceCLM σ F 𝔖) :=
UniformSpace.replaceTopology
((UniformOnFun.uniformSpace E F 𝔖).comap (UniformOnFun.ofFun 𝔖 ∘ DFunLike.coe))
(by rw [UniformConvergenceCLM.instTopologicalSpace, IsUniformAddGroup.toUniformSpace_eq]; rfl)
theorem uniformSpace_eq [UniformSpace F] [IsUniformAddGroup F] (𝔖 : Set (Set E)) :
instUniformSpace σ F 𝔖 =
UniformSpace.comap (UniformOnFun.ofFun 𝔖 ∘ DFunLike.coe)
(UniformOnFun.uniformSpace E F 𝔖) := by
rw [instUniformSpace, UniformSpace.replaceTopology_eq]
@[simp]
theorem uniformity_toTopologicalSpace_eq [UniformSpace F] [IsUniformAddGroup F] (𝔖 : Set (Set E)) :
(UniformConvergenceCLM.instUniformSpace σ F 𝔖).toTopologicalSpace =
UniformConvergenceCLM.instTopologicalSpace σ F 𝔖 :=
rfl
theorem isUniformInducing_coeFn [UniformSpace F] [IsUniformAddGroup F] (𝔖 : Set (Set E)) :
IsUniformInducing (α := UniformConvergenceCLM σ F 𝔖) (UniformOnFun.ofFun 𝔖 ∘ DFunLike.coe) :=
⟨rfl⟩
theorem isUniformEmbedding_coeFn [UniformSpace F] [IsUniformAddGroup F] (𝔖 : Set (Set E)) :
IsUniformEmbedding (α := UniformConvergenceCLM σ F 𝔖) (UniformOnFun.ofFun 𝔖 ∘ DFunLike.coe) :=
⟨isUniformInducing_coeFn .., DFunLike.coe_injective⟩
theorem isEmbedding_coeFn [UniformSpace F] [IsUniformAddGroup F] (𝔖 : Set (Set E)) :
IsEmbedding (X := UniformConvergenceCLM σ F 𝔖) (Y := E →ᵤ[𝔖] F)
(UniformOnFun.ofFun 𝔖 ∘ DFunLike.coe) :=
IsUniformEmbedding.isEmbedding (isUniformEmbedding_coeFn _ _ _)
@[deprecated (since := "2024-10-26")]
alias embedding_coeFn := isEmbedding_coeFn
instance instAddCommGroup [TopologicalSpace F] [IsTopologicalAddGroup F] (𝔖 : Set (Set E)) :
AddCommGroup (UniformConvergenceCLM σ F 𝔖) := ContinuousLinearMap.addCommGroup
@[simp]
theorem coe_zero [TopologicalSpace F] [IsTopologicalAddGroup F] (𝔖 : Set (Set E)) :
⇑(0 : UniformConvergenceCLM σ F 𝔖) = 0 :=
rfl
instance instIsUniformAddGroup [UniformSpace F] [IsUniformAddGroup F] (𝔖 : Set (Set E)) :
IsUniformAddGroup (UniformConvergenceCLM σ F 𝔖) := by
let φ : (UniformConvergenceCLM σ F 𝔖) →+ E →ᵤ[𝔖] F :=
⟨⟨(DFunLike.coe : (UniformConvergenceCLM σ F 𝔖) → E →ᵤ[𝔖] F), rfl⟩, fun _ _ => rfl⟩
exact (isUniformEmbedding_coeFn _ _ _).isUniformAddGroup φ
instance instIsTopologicalAddGroup [TopologicalSpace F] [IsTopologicalAddGroup F]
(𝔖 : Set (Set E)) : IsTopologicalAddGroup (UniformConvergenceCLM σ F 𝔖) := by
letI : UniformSpace F := IsTopologicalAddGroup.toUniformSpace F
haveI : IsUniformAddGroup F := isUniformAddGroup_of_addCommGroup
infer_instance
theorem continuousEvalConst [TopologicalSpace F] [IsTopologicalAddGroup F]
(𝔖 : Set (Set E)) (h𝔖 : ⋃₀ 𝔖 = Set.univ) :
ContinuousEvalConst (UniformConvergenceCLM σ F 𝔖) E F where
continuous_eval_const x := by
letI : UniformSpace F := IsTopologicalAddGroup.toUniformSpace F
haveI : IsUniformAddGroup F := isUniformAddGroup_of_addCommGroup
exact (UniformOnFun.uniformContinuous_eval h𝔖 x).continuous.comp
(isEmbedding_coeFn σ F 𝔖).continuous
| Mathlib/Topology/Algebra/Module/StrongTopology.lean | 168 | 177 | theorem t2Space [TopologicalSpace F] [IsTopologicalAddGroup F] [T2Space F]
(𝔖 : Set (Set E)) (h𝔖 : ⋃₀ 𝔖 = univ) : T2Space (UniformConvergenceCLM σ F 𝔖) := by | letI : UniformSpace F := IsTopologicalAddGroup.toUniformSpace F
haveI : IsUniformAddGroup F := isUniformAddGroup_of_addCommGroup
haveI : T2Space (E →ᵤ[𝔖] F) := UniformOnFun.t2Space_of_covering h𝔖
exact (isEmbedding_coeFn σ F 𝔖).t2Space
instance instDistribMulAction (M : Type*) [Monoid M] [DistribMulAction M F] [SMulCommClass 𝕜₂ M F]
[TopologicalSpace F] [IsTopologicalAddGroup F] [ContinuousConstSMul M F] (𝔖 : Set (Set E)) :
DistribMulAction M (UniformConvergenceCLM σ F 𝔖) := ContinuousLinearMap.distribMulAction |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine
import Mathlib.Geometry.Euclidean.Angle.Unoriented.RightAngle
/-!
# Oriented angles in right-angled triangles.
This file proves basic geometrical results about distances and oriented angles in (possibly
degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces.
-/
noncomputable section
open scoped EuclideanGeometry
open scoped Real
open scoped RealInnerProductSpace
namespace Orientation
open Module
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V]
variable [hd2 : Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2))
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arccos (‖y‖ / ‖x + y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arcsin (‖x‖ / ‖x + y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h) (o.left_ne_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arctan (‖x‖ / ‖y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle x (x + y)) = ‖x‖ / ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle (x + y) y) = ‖y‖ / ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).cos_oangle_add_right_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle x (x + y)) = ‖y‖ / ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle (x + y) y) = ‖x‖ / ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).sin_oangle_add_right_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle x (x + y)) = ‖y‖ / ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle (x + y) y) = ‖x‖ / ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).tan_oangle_add_right_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) * ‖x + y‖ = ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) * ‖x + y‖ = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
theorem sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) * ‖x + y‖ = ‖y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
theorem sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) * ‖x + y‖ = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side. -/
theorem tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) * ‖x‖ = ‖y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side. -/
theorem tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) * ‖y‖ = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse. -/
theorem norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle x (x + y)) = ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.norm_div_cos_angle_add_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse. -/
theorem norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle (x + y) y) = ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse. -/
theorem norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle x (x + y)) = ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.norm_div_sin_angle_add_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse. -/
theorem norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle (x + y) y) = ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side. -/
theorem norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.tan (o.oangle x (x + y)) = ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.norm_div_tan_angle_add_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side. -/
theorem norm_div_tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.tan (o.oangle (x + y) y) = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/
theorem oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle y (y - x) = Real.arccos (‖y‖ / ‖y - x‖) := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_sub_eq_arccos_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/
theorem oangle_sub_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x - y) x = Real.arccos (‖x‖ / ‖x - y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/
theorem oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle y (y - x) = Real.arcsin (‖x‖ / ‖y - x‖) := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_sub_eq_arcsin_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/
theorem oangle_sub_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x - y) x = Real.arcsin (‖y‖ / ‖x - y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/
theorem oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle y (y - x) = Real.arctan (‖x‖ / ‖y‖) := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_sub_eq_arctan_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (o.right_ne_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/
theorem oangle_sub_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x - y) x = Real.arctan (‖y‖ / ‖x‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle y (y - x)) = ‖y‖ / ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle (x - y) x) = ‖x‖ / ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).cos_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle y (y - x)) = ‖x‖ / ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle (x - y) x) = ‖y‖ / ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).sin_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle y (y - x)) = ‖x‖ / ‖y‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle (x - y) x) = ‖y‖ / ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).tan_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side, version subtracting vectors. -/
theorem cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle y (y - x)) * ‖y - x‖ = ‖y‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_sub_mul_norm_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side, version subtracting vectors. -/
theorem cos_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x - y) x) * ‖x - y‖ = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side, version subtracting vectors. -/
theorem sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle y (y - x)) * ‖y - x‖ = ‖x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_sub_mul_norm_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side, version subtracting vectors. -/
theorem sin_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x - y) x) * ‖x - y‖ = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side, version subtracting vectors. -/
theorem tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle y (y - x)) * ‖y‖ = ‖x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_sub_mul_norm_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side, version subtracting vectors. -/
theorem tan_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x - y) x) * ‖x‖ = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle y (y - x)) = ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.norm_div_cos_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle (x - y) x) = ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle y (y - x)) = ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.norm_div_sin_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle (x - y) x) = ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side, version subtracting vectors. -/
theorem norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.tan (o.oangle y (y - x)) = ‖y‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.norm_div_tan_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side, version subtracting vectors. -/
theorem norm_div_tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.tan (o.oangle (x - y) x) = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple
of a rotation of another by `π / 2`. -/
theorem oangle_add_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
o.oangle x (x + r • o.rotation (π / 2 : ℝ) x) = Real.arctan r := by
rcases lt_trichotomy r 0 with (hr | rfl | hr)
· have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = -(π / 2 : ℝ) := by
rw [o.oangle_smul_right_of_neg _ _ hr, o.oangle_neg_right h, o.oangle_rotation_self_right h, ←
sub_eq_zero, add_comm, sub_neg_eq_add, ← Real.Angle.coe_add, ← Real.Angle.coe_add,
add_assoc, add_halves, ← two_mul, Real.Angle.coe_two_pi]
simpa using h
-- Porting note: if the type is not given in `neg_neg` then Lean "forgets" about the instance
-- `Neg (Orientation ℝ V (Fin 2))`
rw [← neg_inj, ← oangle_neg_orientation_eq_neg, @neg_neg Real.Angle] at ha
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj, oangle_rev,
(-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul,
LinearIsometryEquiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one,
Real.norm_eq_abs, abs_of_neg hr, Real.arctan_neg, Real.Angle.coe_neg, neg_neg]
· rw [zero_smul, add_zero, oangle_self, Real.arctan_zero, Real.Angle.coe_zero]
· have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = (π / 2 : ℝ) := by
rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right h]
rw [o.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul,
LinearIsometryEquiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one,
Real.norm_eq_abs, abs_of_pos hr]
/-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple
of a rotation of another by `π / 2`. -/
theorem oangle_add_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
o.oangle (x + r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x)
= Real.arctan r⁻¹ := by
by_cases hr : r = 0; · simp [hr]
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj, ←
neg_neg ((π / 2 : ℝ) : Real.Angle), ← rotation_neg_orientation_eq_neg, add_comm]
have hx : x = r⁻¹ • (-o).rotation (π / 2 : ℝ) (r • (-o).rotation (-(π / 2 : ℝ)) x) := by simp [hr]
nth_rw 3 [hx]
refine (-o).oangle_add_right_smul_rotation_pi_div_two ?_ _
simp [hr, h]
/-- The tangent of an angle in a right-angled triangle, where one side is a multiple of a
rotation of another by `π / 2`. -/
theorem tan_oangle_add_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
Real.Angle.tan (o.oangle x (x + r • o.rotation (π / 2 : ℝ) x)) = r := by
rw [o.oangle_add_right_smul_rotation_pi_div_two h, Real.Angle.tan_coe, Real.tan_arctan]
/-- The tangent of an angle in a right-angled triangle, where one side is a multiple of a
rotation of another by `π / 2`. -/
theorem tan_oangle_add_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
Real.Angle.tan (o.oangle (x + r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x)) =
r⁻¹ := by
rw [o.oangle_add_left_smul_rotation_pi_div_two h, Real.Angle.tan_coe, Real.tan_arctan]
/-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple
of a rotation of another by `π / 2`, version subtracting vectors. -/
theorem oangle_sub_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
o.oangle (r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x - x)
= Real.arctan r⁻¹ := by
by_cases hr : r = 0; · simp [hr]
have hx : -x = r⁻¹ • o.rotation (π / 2 : ℝ) (r • o.rotation (π / 2 : ℝ) x) := by
simp [hr, ← Real.Angle.coe_add]
rw [sub_eq_add_neg, hx, o.oangle_add_right_smul_rotation_pi_div_two]
simpa [hr] using h
/-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple
of a rotation of another by `π / 2`, version subtracting vectors. -/
theorem oangle_sub_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
o.oangle (x - r • o.rotation (π / 2 : ℝ) x) x = Real.arctan r := by
by_cases hr : r = 0; · simp [hr]
have hx : x = r⁻¹ • o.rotation (π / 2 : ℝ) (-(r • o.rotation (π / 2 : ℝ) x)) := by
simp [hr, ← Real.Angle.coe_add]
rw [sub_eq_add_neg, add_comm]
nth_rw 3 [hx]
nth_rw 2 [hx]
rw [o.oangle_add_left_smul_rotation_pi_div_two, inv_inv]
simpa [hr] using h
end Orientation
namespace EuclideanGeometry
open Module
variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)]
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_right_eq_arccos_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∡ p₂ p₃ p₁ = Real.arccos (dist p₃ p₂ / dist p₁ p₃) := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs,
angle_eq_arccos_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_left_eq_arccos_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∡ p₃ p₁ p₂ = Real.arccos (dist p₁ p₂ / dist p₁ p₃) := by
have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm,
angle_eq_arccos_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h),
dist_comm p₁ p₃]
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_right_eq_arcsin_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∡ p₂ p₃ p₁ = Real.arcsin (dist p₁ p₂ / dist p₁ p₃) := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs,
angle_eq_arcsin_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)
(Or.inl (left_ne_of_oangle_eq_pi_div_two h))]
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_left_eq_arcsin_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∡ p₃ p₁ p₂ = Real.arcsin (dist p₃ p₂ / dist p₁ p₃) := by
have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm,
angle_eq_arcsin_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)
(Or.inr (left_ne_of_oangle_eq_pi_div_two h)),
dist_comm p₁ p₃]
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_right_eq_arctan_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∡ p₂ p₃ p₁ = Real.arctan (dist p₁ p₂ / dist p₃ p₂) := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs,
angle_eq_arctan_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)
(right_ne_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_left_eq_arctan_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∡ p₃ p₁ p₂ = Real.arctan (dist p₃ p₂ / dist p₁ p₂) := by
have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm,
angle_eq_arctan_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)
(left_ne_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
Real.Angle.cos (∡ p₂ p₃ p₁) = dist p₃ p₂ / dist p₁ p₃ := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
cos_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
Real.Angle.cos (∡ p₃ p₁ p₂) = dist p₁ p₂ / dist p₁ p₃ := by
have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.cos_coe,
cos_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h),
dist_comm p₁ p₃]
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
Real.Angle.sin (∡ p₂ p₃ p₁) = dist p₁ p₂ / dist p₁ p₃ := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
sin_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)
(Or.inl (left_ne_of_oangle_eq_pi_div_two h))]
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
Real.Angle.sin (∡ p₃ p₁ p₂) = dist p₃ p₂ / dist p₁ p₃ := by
have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.sin_coe,
sin_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)
(Or.inr (left_ne_of_oangle_eq_pi_div_two h)),
dist_comm p₁ p₃]
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
Real.Angle.tan (∡ p₂ p₃ p₁) = dist p₁ p₂ / dist p₃ p₂ := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
tan_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)]
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
Real.Angle.tan (∡ p₃ p₁ p₂) = dist p₃ p₂ / dist p₁ p₂ := by
have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.tan_coe,
tan_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_right_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P}
(h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.cos (∡ p₂ p₃ p₁) * dist p₁ p₃ = dist p₃ p₂ := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
cos_angle_mul_dist_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_left_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P}
(h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.cos (∡ p₃ p₁ p₂) * dist p₁ p₃ = dist p₁ p₂ := by
have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.cos_coe, dist_comm p₁ p₃,
cos_angle_mul_dist_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)]
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
theorem sin_oangle_right_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P}
(h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.sin (∡ p₂ p₃ p₁) * dist p₁ p₃ = dist p₁ p₂ := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
sin_angle_mul_dist_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)]
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
theorem sin_oangle_left_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P}
(h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.sin (∡ p₃ p₁ p₂) * dist p₁ p₃ = dist p₃ p₂ := by
have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.sin_coe, dist_comm p₁ p₃,
sin_angle_mul_dist_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)]
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side. -/
theorem tan_oangle_right_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P}
(h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.tan (∡ p₂ p₃ p₁) * dist p₃ p₂ = dist p₁ p₂ := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
tan_angle_mul_dist_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)
(Or.inr (right_ne_of_oangle_eq_pi_div_two h))]
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side. -/
theorem tan_oangle_left_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P}
(h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.tan (∡ p₃ p₁ p₂) * dist p₁ p₂ = dist p₃ p₂ := by
have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.tan_coe,
tan_angle_mul_dist_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)
(Or.inr (left_ne_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse. -/
theorem dist_div_cos_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P}
(h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₃ p₂ / Real.Angle.cos (∡ p₂ p₃ p₁) = dist p₁ p₃ := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
dist_div_cos_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)
(Or.inr (right_ne_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse. -/
| Mathlib/Geometry/Euclidean/Angle/Oriented/RightAngle.lean | 682 | 686 | theorem dist_div_cos_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P}
(h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : dist p₁ p₂ / Real.Angle.cos (∡ p₃ p₁ p₂) = dist p₁ p₃ := by | have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.cos_coe, dist_comm p₁ p₃,
dist_div_cos_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) |
/-
Copyright (c) 2020 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.Algebra.Group.Conj
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Algebra.Group.Subgroup.Ker
/-!
# Basic results on subgroups
We prove basic results on the definitions of subgroups. The bundled subgroups use bundled monoid
homomorphisms.
Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration.
## Main definitions
Notation used here:
- `G N` are `Group`s
- `A` is an `AddGroup`
- `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A`
- `x` is an element of type `G` or type `A`
- `f g : N →* G` are group homomorphisms
- `s k` are sets of elements of type `G`
Definitions in the file:
* `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K`
is a subgroup of `G × N`
## Implementation notes
Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a subgroup's underlying set.
## Tags
subgroup, subgroups
-/
assert_not_exists OrderedAddCommMonoid Multiset Ring
open Function
open scoped Int
variable {G G' G'' : Type*} [Group G] [Group G'] [Group G'']
variable {A : Type*} [AddGroup A]
section SubgroupClass
variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S}
variable [SetLike S G] [SubgroupClass S G]
@[to_additive]
theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H :=
inv_div b a ▸ inv_mem_iff
end SubgroupClass
namespace Subgroup
variable (H K : Subgroup G)
@[to_additive]
protected theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H :=
div_mem_comm_iff
variable {k : Set G}
open Set
variable {N : Type*} [Group N] {P : Type*} [Group P]
/-- Given `Subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/
@[to_additive prod
"Given `AddSubgroup`s `H`, `K` of `AddGroup`s `A`, `B` respectively, `H × K`
as an `AddSubgroup` of `A × B`."]
def prod (H : Subgroup G) (K : Subgroup N) : Subgroup (G × N) :=
{ Submonoid.prod H.toSubmonoid K.toSubmonoid with
inv_mem' := fun hx => ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩ }
@[to_additive coe_prod]
theorem coe_prod (H : Subgroup G) (K : Subgroup N) :
(H.prod K : Set (G × N)) = (H : Set G) ×ˢ (K : Set N) :=
rfl
@[to_additive mem_prod]
theorem mem_prod {H : Subgroup G} {K : Subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K :=
Iff.rfl
open scoped Relator in
@[to_additive prod_mono]
theorem prod_mono : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) (@prod G _ N _) (@prod G _ N _) :=
fun _s _s' hs _t _t' ht => Set.prod_mono hs ht
@[to_additive prod_mono_right]
theorem prod_mono_right (K : Subgroup G) : Monotone fun t : Subgroup N => K.prod t :=
prod_mono (le_refl K)
@[to_additive prod_mono_left]
theorem prod_mono_left (H : Subgroup N) : Monotone fun K : Subgroup G => K.prod H := fun _ _ hs =>
prod_mono hs (le_refl H)
@[to_additive prod_top]
theorem prod_top (K : Subgroup G) : K.prod (⊤ : Subgroup N) = K.comap (MonoidHom.fst G N) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_fst]
@[to_additive top_prod]
theorem top_prod (H : Subgroup N) : (⊤ : Subgroup G).prod H = H.comap (MonoidHom.snd G N) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_snd]
@[to_additive (attr := simp) top_prod_top]
theorem top_prod_top : (⊤ : Subgroup G).prod (⊤ : Subgroup N) = ⊤ :=
(top_prod _).trans <| comap_top _
@[to_additive (attr := simp) bot_prod_bot]
theorem bot_prod_bot : (⊥ : Subgroup G).prod (⊥ : Subgroup N) = ⊥ :=
SetLike.coe_injective <| by simp [coe_prod]
@[deprecated (since := "2025-03-11")]
alias _root_.AddSubgroup.bot_sum_bot := AddSubgroup.bot_prod_bot
@[to_additive le_prod_iff]
theorem le_prod_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} :
J ≤ H.prod K ↔ map (MonoidHom.fst G N) J ≤ H ∧ map (MonoidHom.snd G N) J ≤ K := by
simpa only [← Subgroup.toSubmonoid_le] using Submonoid.le_prod_iff
@[to_additive prod_le_iff]
theorem prod_le_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} :
H.prod K ≤ J ↔ map (MonoidHom.inl G N) H ≤ J ∧ map (MonoidHom.inr G N) K ≤ J := by
simpa only [← Subgroup.toSubmonoid_le] using Submonoid.prod_le_iff
@[to_additive (attr := simp) prod_eq_bot_iff]
theorem prod_eq_bot_iff {H : Subgroup G} {K : Subgroup N} : H.prod K = ⊥ ↔ H = ⊥ ∧ K = ⊥ := by
simpa only [← Subgroup.toSubmonoid_inj] using Submonoid.prod_eq_bot_iff
@[to_additive closure_prod]
theorem closure_prod {s : Set G} {t : Set N} (hs : 1 ∈ s) (ht : 1 ∈ t) :
closure (s ×ˢ t) = (closure s).prod (closure t) :=
le_antisymm
(closure_le _ |>.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, subset_closure⟩)
(prod_le_iff.2 ⟨
map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _x hx => subset_closure ⟨hx, ht⟩,
map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _y hy => subset_closure ⟨hs, hy⟩⟩)
/-- Product of subgroups is isomorphic to their product as groups. -/
@[to_additive prodEquiv
"Product of additive subgroups is isomorphic to their product
as additive groups"]
def prodEquiv (H : Subgroup G) (K : Subgroup N) : H.prod K ≃* H × K :=
{ Equiv.Set.prod (H : Set G) (K : Set N) with map_mul' := fun _ _ => rfl }
section Pi
variable {η : Type*} {f : η → Type*}
-- defined here and not in Algebra.Group.Submonoid.Operations to have access to Algebra.Group.Pi
/-- A version of `Set.pi` for submonoids. Given an index set `I` and a family of submodules
`s : Π i, Submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Π i, f i` such that
`f i` belongs to `Pi I s` whenever `i ∈ I`. -/
@[to_additive "A version of `Set.pi` for `AddSubmonoid`s. Given an index set `I` and a family
of submodules `s : Π i, AddSubmonoid f i`, `pi I s` is the `AddSubmonoid` of dependent functions
`f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."]
def _root_.Submonoid.pi [∀ i, MulOneClass (f i)] (I : Set η) (s : ∀ i, Submonoid (f i)) :
Submonoid (∀ i, f i) where
carrier := I.pi fun i => (s i).carrier
one_mem' i _ := (s i).one_mem
mul_mem' hp hq i hI := (s i).mul_mem (hp i hI) (hq i hI)
variable [∀ i, Group (f i)]
/-- A version of `Set.pi` for subgroups. Given an index set `I` and a family of submodules
`s : Π i, Subgroup f i`, `pi I s` is the subgroup of dependent functions `f : Π i, f i` such that
`f i` belongs to `pi I s` whenever `i ∈ I`. -/
@[to_additive
"A version of `Set.pi` for `AddSubgroup`s. Given an index set `I` and a family
of submodules `s : Π i, AddSubgroup f i`, `pi I s` is the `AddSubgroup` of dependent functions
`f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."]
def pi (I : Set η) (H : ∀ i, Subgroup (f i)) : Subgroup (∀ i, f i) :=
{ Submonoid.pi I fun i => (H i).toSubmonoid with
inv_mem' := fun hp i hI => (H i).inv_mem (hp i hI) }
@[to_additive]
theorem coe_pi (I : Set η) (H : ∀ i, Subgroup (f i)) :
(pi I H : Set (∀ i, f i)) = Set.pi I fun i => (H i : Set (f i)) :=
rfl
@[to_additive]
theorem mem_pi (I : Set η) {H : ∀ i, Subgroup (f i)} {p : ∀ i, f i} :
p ∈ pi I H ↔ ∀ i : η, i ∈ I → p i ∈ H i :=
Iff.rfl
@[to_additive]
theorem pi_top (I : Set η) : (pi I fun i => (⊤ : Subgroup (f i))) = ⊤ :=
ext fun x => by simp [mem_pi]
@[to_additive]
theorem pi_empty (H : ∀ i, Subgroup (f i)) : pi ∅ H = ⊤ :=
ext fun x => by simp [mem_pi]
@[to_additive]
theorem pi_bot : (pi Set.univ fun i => (⊥ : Subgroup (f i))) = ⊥ :=
(eq_bot_iff_forall _).mpr fun p hp => by
simp only [mem_pi, mem_bot] at *
ext j
exact hp j trivial
@[to_additive]
theorem le_pi_iff {I : Set η} {H : ∀ i, Subgroup (f i)} {J : Subgroup (∀ i, f i)} :
J ≤ pi I H ↔ ∀ i : η, i ∈ I → map (Pi.evalMonoidHom f i) J ≤ H i := by
constructor
· intro h i hi
rintro _ ⟨x, hx, rfl⟩
exact (h hx) _ hi
· intro h x hx i hi
exact h i hi ⟨_, hx, rfl⟩
@[to_additive (attr := simp)]
theorem mulSingle_mem_pi [DecidableEq η] {I : Set η} {H : ∀ i, Subgroup (f i)} (i : η) (x : f i) :
Pi.mulSingle i x ∈ pi I H ↔ i ∈ I → x ∈ H i := by
constructor
· intro h hi
simpa using h i hi
· intro h j hj
by_cases heq : j = i
· subst heq
simpa using h hj
· simp [heq, one_mem]
@[to_additive]
theorem pi_eq_bot_iff (H : ∀ i, Subgroup (f i)) : pi Set.univ H = ⊥ ↔ ∀ i, H i = ⊥ := by
classical
simp only [eq_bot_iff_forall]
constructor
· intro h i x hx
have : MonoidHom.mulSingle f i x = 1 :=
h (MonoidHom.mulSingle f i x) ((mulSingle_mem_pi i x).mpr fun _ => hx)
simpa using congr_fun this i
· exact fun h x hx => funext fun i => h _ _ (hx i trivial)
end Pi
end Subgroup
namespace Subgroup
variable {H K : Subgroup G}
variable (H)
/-- A subgroup is characteristic if it is fixed by all automorphisms.
Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/
structure Characteristic : Prop where
/-- `H` is fixed by all automorphisms -/
fixed : ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H
attribute [class] Characteristic
instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal :=
⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (MulAut.conj b)) a).mpr ha⟩
end Subgroup
namespace AddSubgroup
variable (H : AddSubgroup A)
/-- An `AddSubgroup` is characteristic if it is fixed by all automorphisms.
Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/
structure Characteristic : Prop where
/-- `H` is fixed by all automorphisms -/
fixed : ∀ ϕ : A ≃+ A, H.comap ϕ.toAddMonoidHom = H
attribute [to_additive] Subgroup.Characteristic
attribute [class] Characteristic
instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal :=
⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (AddAut.conj b)) a).mpr ha⟩
end AddSubgroup
namespace Subgroup
variable {H K : Subgroup G}
@[to_additive]
theorem characteristic_iff_comap_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H :=
⟨Characteristic.fixed, Characteristic.mk⟩
@[to_additive]
theorem characteristic_iff_comap_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom ≤ H :=
characteristic_iff_comap_eq.trans
⟨fun h ϕ => le_of_eq (h ϕ), fun h ϕ =>
le_antisymm (h ϕ) fun g hg => h ϕ.symm ((congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mpr hg)⟩
@[to_additive]
theorem characteristic_iff_le_comap : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.comap ϕ.toMonoidHom :=
characteristic_iff_comap_eq.trans
⟨fun h ϕ => ge_of_eq (h ϕ), fun h ϕ =>
le_antisymm (fun g hg => (congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mp (h ϕ.symm hg)) (h ϕ)⟩
@[to_additive]
theorem characteristic_iff_map_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom = H := by
simp_rw [map_equiv_eq_comap_symm']
exact characteristic_iff_comap_eq.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩
@[to_additive]
theorem characteristic_iff_map_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom ≤ H := by
simp_rw [map_equiv_eq_comap_symm']
exact characteristic_iff_comap_le.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩
@[to_additive]
theorem characteristic_iff_le_map : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.map ϕ.toMonoidHom := by
simp_rw [map_equiv_eq_comap_symm']
exact characteristic_iff_le_comap.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩
@[to_additive]
instance botCharacteristic : Characteristic (⊥ : Subgroup G) :=
characteristic_iff_le_map.mpr fun _ϕ => bot_le
@[to_additive]
instance topCharacteristic : Characteristic (⊤ : Subgroup G) :=
characteristic_iff_map_le.mpr fun _ϕ => le_top
variable (H)
section Normalizer
variable {H}
@[to_additive]
theorem normalizer_eq_top_iff : H.normalizer = ⊤ ↔ H.Normal :=
eq_top_iff.trans
⟨fun h => ⟨fun a ha b => (h (mem_top b) a).mp ha⟩, fun h a _ha b =>
⟨fun hb => h.conj_mem b hb a, fun hb => by rwa [h.mem_comm_iff, inv_mul_cancel_left] at hb⟩⟩
variable (H) in
@[to_additive]
theorem normalizer_eq_top [h : H.Normal] : H.normalizer = ⊤ :=
normalizer_eq_top_iff.mpr h
variable {N : Type*} [Group N]
/-- The preimage of the normalizer is contained in the normalizer of the preimage. -/
@[to_additive "The preimage of the normalizer is contained in the normalizer of the preimage."]
theorem le_normalizer_comap (f : N →* G) :
H.normalizer.comap f ≤ (H.comap f).normalizer := fun x => by
simp only [mem_normalizer_iff, mem_comap]
intro h n
simp [h (f n)]
/-- The image of the normalizer is contained in the normalizer of the image. -/
@[to_additive "The image of the normalizer is contained in the normalizer of the image."]
theorem le_normalizer_map (f : G →* N) : H.normalizer.map f ≤ (H.map f).normalizer := fun _ => by
simp only [and_imp, exists_prop, mem_map, exists_imp, mem_normalizer_iff]
rintro x hx rfl n
constructor
· rintro ⟨y, hy, rfl⟩
use x * y * x⁻¹, (hx y).1 hy
simp
· rintro ⟨y, hyH, hy⟩
use x⁻¹ * y * x
rw [hx]
simp [hy, hyH, mul_assoc]
@[to_additive]
theorem comap_normalizer_eq_of_le_range {f : N →* G} (h : H ≤ f.range) :
comap f H.normalizer = (comap f H).normalizer := by
apply le_antisymm (le_normalizer_comap f)
rw [← map_le_iff_le_comap]
apply (le_normalizer_map f).trans
rw [map_comap_eq_self h]
@[to_additive]
theorem subgroupOf_normalizer_eq {H N : Subgroup G} (h : H ≤ N) :
H.normalizer.subgroupOf N = (H.subgroupOf N).normalizer :=
comap_normalizer_eq_of_le_range (h.trans_eq N.range_subtype.symm)
@[to_additive]
theorem normal_subgroupOf_iff_le_normalizer (h : H ≤ K) :
(H.subgroupOf K).Normal ↔ K ≤ H.normalizer := by
rw [← subgroupOf_eq_top, subgroupOf_normalizer_eq h, normalizer_eq_top_iff]
@[to_additive]
theorem normal_subgroupOf_iff_le_normalizer_inf :
(H.subgroupOf K).Normal ↔ K ≤ (H ⊓ K).normalizer :=
inf_subgroupOf_right H K ▸ normal_subgroupOf_iff_le_normalizer inf_le_right
@[to_additive]
instance (priority := 100) normal_in_normalizer : (H.subgroupOf H.normalizer).Normal :=
(normal_subgroupOf_iff_le_normalizer H.le_normalizer).mpr le_rfl
@[to_additive]
theorem le_normalizer_of_normal_subgroupOf [hK : (H.subgroupOf K).Normal] (HK : H ≤ K) :
K ≤ H.normalizer :=
(normal_subgroupOf_iff_le_normalizer HK).mp hK
@[to_additive]
theorem subset_normalizer_of_normal {S : Set G} [hH : H.Normal] : S ⊆ H.normalizer :=
(@normalizer_eq_top _ _ H hH) ▸ le_top
@[to_additive]
theorem le_normalizer_of_normal [H.Normal] : K ≤ H.normalizer := subset_normalizer_of_normal
@[to_additive]
theorem inf_normalizer_le_normalizer_inf : H.normalizer ⊓ K.normalizer ≤ (H ⊓ K).normalizer :=
fun _ h g ↦ and_congr (h.1 g) (h.2 g)
variable (G) in
/-- Every proper subgroup `H` of `G` is a proper normal subgroup of the normalizer of `H` in `G`. -/
def _root_.NormalizerCondition :=
∀ H : Subgroup G, H < ⊤ → H < normalizer H
/-- Alternative phrasing of the normalizer condition: Only the full group is self-normalizing.
This may be easier to work with, as it avoids inequalities and negations. -/
theorem _root_.normalizerCondition_iff_only_full_group_self_normalizing :
NormalizerCondition G ↔ ∀ H : Subgroup G, H.normalizer = H → H = ⊤ := by
apply forall_congr'; intro H
simp only [lt_iff_le_and_ne, le_normalizer, le_top, Ne]
tauto
variable (H)
end Normalizer
end Subgroup
namespace Group
variable {s : Set G}
/-- Given a set `s`, `conjugatesOfSet s` is the set of all conjugates of
the elements of `s`. -/
def conjugatesOfSet (s : Set G) : Set G :=
⋃ a ∈ s, conjugatesOf a
theorem mem_conjugatesOfSet_iff {x : G} : x ∈ conjugatesOfSet s ↔ ∃ a ∈ s, IsConj a x := by
rw [conjugatesOfSet, Set.mem_iUnion₂]
simp only [conjugatesOf, isConj_iff, Set.mem_setOf_eq, exists_prop]
theorem subset_conjugatesOfSet : s ⊆ conjugatesOfSet s := fun (x : G) (h : x ∈ s) =>
mem_conjugatesOfSet_iff.2 ⟨x, h, IsConj.refl _⟩
theorem conjugatesOfSet_mono {s t : Set G} (h : s ⊆ t) : conjugatesOfSet s ⊆ conjugatesOfSet t :=
Set.biUnion_subset_biUnion_left h
theorem conjugates_subset_normal {N : Subgroup G} [tn : N.Normal] {a : G} (h : a ∈ N) :
conjugatesOf a ⊆ N := by
rintro a hc
obtain ⟨c, rfl⟩ := isConj_iff.1 hc
exact tn.conj_mem a h c
theorem conjugatesOfSet_subset {s : Set G} {N : Subgroup G} [N.Normal] (h : s ⊆ N) :
conjugatesOfSet s ⊆ N :=
Set.iUnion₂_subset fun _x H => conjugates_subset_normal (h H)
/-- The set of conjugates of `s` is closed under conjugation. -/
theorem conj_mem_conjugatesOfSet {x c : G} :
x ∈ conjugatesOfSet s → c * x * c⁻¹ ∈ conjugatesOfSet s := fun H => by
rcases mem_conjugatesOfSet_iff.1 H with ⟨a, h₁, h₂⟩
exact mem_conjugatesOfSet_iff.2 ⟨a, h₁, h₂.trans (isConj_iff.2 ⟨c, rfl⟩)⟩
end Group
namespace Subgroup
open Group
variable {s : Set G}
/-- The normal closure of a set `s` is the subgroup closure of all the conjugates of
elements of `s`. It is the smallest normal subgroup containing `s`. -/
def normalClosure (s : Set G) : Subgroup G :=
closure (conjugatesOfSet s)
theorem conjugatesOfSet_subset_normalClosure : conjugatesOfSet s ⊆ normalClosure s :=
subset_closure
theorem subset_normalClosure : s ⊆ normalClosure s :=
Set.Subset.trans subset_conjugatesOfSet conjugatesOfSet_subset_normalClosure
theorem le_normalClosure {H : Subgroup G} : H ≤ normalClosure ↑H := fun _ h =>
subset_normalClosure h
/-- The normal closure of `s` is a normal subgroup. -/
instance normalClosure_normal : (normalClosure s).Normal :=
⟨fun n h g => by
refine Subgroup.closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_)
(fun x _ ihx => ?_) h
· exact conjugatesOfSet_subset_normalClosure (conj_mem_conjugatesOfSet hx)
· simpa using (normalClosure s).one_mem
· rw [← conj_mul]
exact mul_mem ihx ihy
· rw [← conj_inv]
exact inv_mem ihx⟩
/-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/
theorem normalClosure_le_normal {N : Subgroup G} [N.Normal] (h : s ⊆ N) : normalClosure s ≤ N := by
intro a w
refine closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_) (fun x _ ihx => ?_) w
· exact conjugatesOfSet_subset h hx
· exact one_mem _
· exact mul_mem ihx ihy
· exact inv_mem ihx
theorem normalClosure_subset_iff {N : Subgroup G} [N.Normal] : s ⊆ N ↔ normalClosure s ≤ N :=
⟨normalClosure_le_normal, Set.Subset.trans subset_normalClosure⟩
@[gcongr]
theorem normalClosure_mono {s t : Set G} (h : s ⊆ t) : normalClosure s ≤ normalClosure t :=
normalClosure_le_normal (Set.Subset.trans h subset_normalClosure)
theorem normalClosure_eq_iInf :
normalClosure s = ⨅ (N : Subgroup G) (_ : Normal N) (_ : s ⊆ N), N :=
le_antisymm (le_iInf fun _ => le_iInf fun _ => le_iInf normalClosure_le_normal)
(iInf_le_of_le (normalClosure s)
(iInf_le_of_le (by infer_instance) (iInf_le_of_le subset_normalClosure le_rfl)))
@[simp]
theorem normalClosure_eq_self (H : Subgroup G) [H.Normal] : normalClosure ↑H = H :=
le_antisymm (normalClosure_le_normal rfl.subset) le_normalClosure
theorem normalClosure_idempotent : normalClosure ↑(normalClosure s) = normalClosure s :=
normalClosure_eq_self _
theorem closure_le_normalClosure {s : Set G} : closure s ≤ normalClosure s := by
simp only [subset_normalClosure, closure_le]
@[simp]
theorem normalClosure_closure_eq_normalClosure {s : Set G} :
normalClosure ↑(closure s) = normalClosure s :=
le_antisymm (normalClosure_le_normal closure_le_normalClosure) (normalClosure_mono subset_closure)
/-- The normal core of a subgroup `H` is the largest normal subgroup of `G` contained in `H`,
as shown by `Subgroup.normalCore_eq_iSup`. -/
def normalCore (H : Subgroup G) : Subgroup G where
carrier := { a : G | ∀ b : G, b * a * b⁻¹ ∈ H }
one_mem' a := by rw [mul_one, mul_inv_cancel]; exact H.one_mem
inv_mem' {_} h b := (congr_arg (· ∈ H) conj_inv).mp (H.inv_mem (h b))
mul_mem' {_ _} ha hb c := (congr_arg (· ∈ H) conj_mul).mp (H.mul_mem (ha c) (hb c))
theorem normalCore_le (H : Subgroup G) : H.normalCore ≤ H := fun a h => by
rw [← mul_one a, ← inv_one, ← one_mul a]
exact h 1
instance normalCore_normal (H : Subgroup G) : H.normalCore.Normal :=
⟨fun a h b c => by
rw [mul_assoc, mul_assoc, ← mul_inv_rev, ← mul_assoc, ← mul_assoc]; exact h (c * b)⟩
theorem normal_le_normalCore {H : Subgroup G} {N : Subgroup G} [hN : N.Normal] :
N ≤ H.normalCore ↔ N ≤ H :=
⟨ge_trans H.normalCore_le, fun h_le n hn g => h_le (hN.conj_mem n hn g)⟩
theorem normalCore_mono {H K : Subgroup G} (h : H ≤ K) : H.normalCore ≤ K.normalCore :=
normal_le_normalCore.mpr (H.normalCore_le.trans h)
theorem normalCore_eq_iSup (H : Subgroup G) :
H.normalCore = ⨆ (N : Subgroup G) (_ : Normal N) (_ : N ≤ H), N :=
le_antisymm
(le_iSup_of_le H.normalCore
(le_iSup_of_le H.normalCore_normal (le_iSup_of_le H.normalCore_le le_rfl)))
(iSup_le fun _ => iSup_le fun _ => iSup_le normal_le_normalCore.mpr)
@[simp]
theorem normalCore_eq_self (H : Subgroup G) [H.Normal] : H.normalCore = H :=
le_antisymm H.normalCore_le (normal_le_normalCore.mpr le_rfl)
theorem normalCore_idempotent (H : Subgroup G) : H.normalCore.normalCore = H.normalCore :=
H.normalCore.normalCore_eq_self
end Subgroup
namespace MonoidHom
variable {N : Type*} {P : Type*} [Group N] [Group P] (K : Subgroup G)
open Subgroup
section Ker
variable {M : Type*} [MulOneClass M]
@[to_additive prodMap_comap_prod]
theorem prodMap_comap_prod {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N)
(g : G' →* N') (S : Subgroup N) (S' : Subgroup N') :
(S.prod S').comap (prodMap f g) = (S.comap f).prod (S'.comap g) :=
SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _
@[deprecated (since := "2025-03-11")]
alias _root_.AddMonoidHom.sumMap_comap_sum := AddMonoidHom.prodMap_comap_prod
@[to_additive ker_prodMap]
theorem ker_prodMap {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N) (g : G' →* N') :
(prodMap f g).ker = f.ker.prod g.ker := by
rw [← comap_bot, ← comap_bot, ← comap_bot, ← prodMap_comap_prod, bot_prod_bot]
@[deprecated (since := "2025-03-11")]
alias _root_.AddMonoidHom.ker_sumMap := AddMonoidHom.ker_prodMap
@[to_additive (attr := simp)]
lemma ker_fst : ker (fst G G') = .prod ⊥ ⊤ := SetLike.ext fun _ => (iff_of_eq (and_true _)).symm
@[to_additive (attr := simp)]
lemma ker_snd : ker (snd G G') = .prod ⊤ ⊥ := SetLike.ext fun _ => (iff_of_eq (true_and _)).symm
end Ker
end MonoidHom
namespace Subgroup
variable {N : Type*} [Group N] (H : Subgroup G)
@[to_additive]
theorem Normal.map {H : Subgroup G} (h : H.Normal) (f : G →* N) (hf : Function.Surjective f) :
(H.map f).Normal := by
rw [← normalizer_eq_top_iff, ← top_le_iff, ← f.range_eq_top_of_surjective hf, f.range_eq_map,
← H.normalizer_eq_top]
exact le_normalizer_map _
end Subgroup
namespace Subgroup
open MonoidHom
variable {N : Type*} [Group N] (f : G →* N)
/-- The preimage of the normalizer is equal to the normalizer of the preimage of a surjective
function. -/
@[to_additive
"The preimage of the normalizer is equal to the normalizer of the preimage of
a surjective function."]
theorem comap_normalizer_eq_of_surjective (H : Subgroup G) {f : N →* G}
(hf : Function.Surjective f) : H.normalizer.comap f = (H.comap f).normalizer :=
comap_normalizer_eq_of_le_range fun x _ ↦ hf x
@[deprecated (since := "2025-03-13")]
alias comap_normalizer_eq_of_injective_of_le_range := comap_normalizer_eq_of_le_range
@[deprecated (since := "2025-03-13")]
alias _root_.AddSubgroup.comap_normalizer_eq_of_injective_of_le_range :=
AddSubgroup.comap_normalizer_eq_of_le_range
/-- The image of the normalizer is equal to the normalizer of the image of an isomorphism. -/
@[to_additive
"The image of the normalizer is equal to the normalizer of the image of an
isomorphism."]
theorem map_equiv_normalizer_eq (H : Subgroup G) (f : G ≃* N) :
H.normalizer.map f.toMonoidHom = (H.map f.toMonoidHom).normalizer := by
ext x
simp only [mem_normalizer_iff, mem_map_equiv]
rw [f.toEquiv.forall_congr]
intro
simp
/-- The image of the normalizer is equal to the normalizer of the image of a bijective
function. -/
@[to_additive
"The image of the normalizer is equal to the normalizer of the image of a bijective
function."]
theorem map_normalizer_eq_of_bijective (H : Subgroup G) {f : G →* N} (hf : Function.Bijective f) :
H.normalizer.map f = (H.map f).normalizer :=
map_equiv_normalizer_eq H (MulEquiv.ofBijective f hf)
end Subgroup
namespace MonoidHom
variable {G₁ G₂ G₃ : Type*} [Group G₁] [Group G₂] [Group G₃]
variable (f : G₁ →* G₂) (f_inv : G₂ → G₁)
/-- Auxiliary definition used to define `liftOfRightInverse` -/
@[to_additive "Auxiliary definition used to define `liftOfRightInverse`"]
def liftOfRightInverseAux (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) :
G₂ →* G₃ where
toFun b := g (f_inv b)
map_one' := hg (hf 1)
map_mul' := by
intro x y
rw [← g.map_mul, ← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker]
apply hg
rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one, f.map_mul]
simp only [hf _]
@[to_additive (attr := simp)]
theorem liftOfRightInverseAux_comp_apply (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃)
(hg : f.ker ≤ g.ker) (x : G₁) : (f.liftOfRightInverseAux f_inv hf g hg) (f x) = g x := by
dsimp [liftOfRightInverseAux]
rw [← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker]
apply hg
rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one]
simp only [hf _]
/-- `liftOfRightInverse f hf g hg` is the unique group homomorphism `φ`
* such that `φ.comp f = g` (`MonoidHom.liftOfRightInverse_comp`),
* where `f : G₁ →+* G₂` has a RightInverse `f_inv` (`hf`),
* and `g : G₂ →+* G₃` satisfies `hg : f.ker ≤ g.ker`.
See `MonoidHom.eq_liftOfRightInverse` for the uniqueness lemma.
```
G₁.
| \
f | \ g
| \
v \⌟
G₂----> G₃
∃!φ
```
-/
@[to_additive
"`liftOfRightInverse f f_inv hf g hg` is the unique additive group homomorphism `φ`
* such that `φ.comp f = g` (`AddMonoidHom.liftOfRightInverse_comp`),
* where `f : G₁ →+ G₂` has a RightInverse `f_inv` (`hf`),
* and `g : G₂ →+ G₃` satisfies `hg : f.ker ≤ g.ker`.
See `AddMonoidHom.eq_liftOfRightInverse` for the uniqueness lemma.
```
G₁.
| \\
f | \\ g
| \\
v \\⌟
G₂----> G₃
∃!φ
```"]
def liftOfRightInverse (hf : Function.RightInverse f_inv f) :
{ g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) where
toFun g := f.liftOfRightInverseAux f_inv hf g.1 g.2
invFun φ := ⟨φ.comp f, fun x hx ↦ mem_ker.mpr <| by simp [mem_ker.mp hx]⟩
left_inv g := by
ext
simp only [comp_apply, liftOfRightInverseAux_comp_apply, Subtype.coe_mk]
right_inv φ := by
ext b
simp [liftOfRightInverseAux, hf b]
/-- A non-computable version of `MonoidHom.liftOfRightInverse` for when no computable right
inverse is available, that uses `Function.surjInv`. -/
@[to_additive (attr := simp)
"A non-computable version of `AddMonoidHom.liftOfRightInverse` for when no
computable right inverse is available."]
noncomputable abbrev liftOfSurjective (hf : Function.Surjective f) :
{ g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) :=
f.liftOfRightInverse (Function.surjInv hf) (Function.rightInverse_surjInv hf)
@[to_additive (attr := simp)]
theorem liftOfRightInverse_comp_apply (hf : Function.RightInverse f_inv f)
(g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) (x : G₁) :
(f.liftOfRightInverse f_inv hf g) (f x) = g.1 x :=
f.liftOfRightInverseAux_comp_apply f_inv hf g.1 g.2 x
@[to_additive (attr := simp)]
theorem liftOfRightInverse_comp (hf : Function.RightInverse f_inv f)
(g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) : (f.liftOfRightInverse f_inv hf g).comp f = g :=
MonoidHom.ext <| f.liftOfRightInverse_comp_apply f_inv hf g
@[to_additive]
theorem eq_liftOfRightInverse (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃)
(hg : f.ker ≤ g.ker) (h : G₂ →* G₃) (hh : h.comp f = g) :
h = f.liftOfRightInverse f_inv hf ⟨g, hg⟩ := by
simp_rw [← hh]
exact ((f.liftOfRightInverse f_inv hf).apply_symm_apply _).symm
end MonoidHom
variable {N : Type*} [Group N]
namespace Subgroup
-- Here `H.Normal` is an explicit argument so we can use dot notation with `comap`.
@[to_additive]
theorem Normal.comap {H : Subgroup N} (hH : H.Normal) (f : G →* N) : (H.comap f).Normal :=
⟨fun _ => by simp +contextual [Subgroup.mem_comap, hH.conj_mem]⟩
@[to_additive]
instance (priority := 100) normal_comap {H : Subgroup N} [nH : H.Normal] (f : G →* N) :
(H.comap f).Normal :=
nH.comap _
-- Here `H.Normal` is an explicit argument so we can use dot notation with `subgroupOf`.
@[to_additive]
theorem Normal.subgroupOf {H : Subgroup G} (hH : H.Normal) (K : Subgroup G) :
(H.subgroupOf K).Normal :=
hH.comap _
@[to_additive]
instance (priority := 100) normal_subgroupOf {H N : Subgroup G} [N.Normal] :
(N.subgroupOf H).Normal :=
Subgroup.normal_comap _
theorem map_normalClosure (s : Set G) (f : G →* N) (hf : Surjective f) :
(normalClosure s).map f = normalClosure (f '' s) := by
have : Normal (map f (normalClosure s)) := Normal.map inferInstance f hf
apply le_antisymm
· simp [map_le_iff_le_comap, normalClosure_le_normal, coe_comap,
← Set.image_subset_iff, subset_normalClosure]
· exact normalClosure_le_normal (Set.image_subset f subset_normalClosure)
theorem comap_normalClosure (s : Set N) (f : G ≃* N) :
normalClosure (f ⁻¹' s) = (normalClosure s).comap f := by
have := Set.preimage_equiv_eq_image_symm s f.toEquiv
simp_all [comap_equiv_eq_map_symm, map_normalClosure s (f.symm : N →* G) f.symm.surjective]
lemma Normal.of_map_injective {G H : Type*} [Group G] [Group H] {φ : G →* H}
(hφ : Function.Injective φ) {L : Subgroup G} (n : (L.map φ).Normal) : L.Normal :=
L.comap_map_eq_self_of_injective hφ ▸ n.comap φ
theorem Normal.of_map_subtype {K : Subgroup G} {L : Subgroup K}
(n : (Subgroup.map K.subtype L).Normal) : L.Normal :=
n.of_map_injective K.subtype_injective
end Subgroup
namespace Subgroup
section SubgroupNormal
@[to_additive]
theorem normal_subgroupOf_iff {H K : Subgroup G} (hHK : H ≤ K) :
(H.subgroupOf K).Normal ↔ ∀ h k, h ∈ H → k ∈ K → k * h * k⁻¹ ∈ H :=
⟨fun hN h k hH hK => hN.conj_mem ⟨h, hHK hH⟩ hH ⟨k, hK⟩, fun hN =>
{ conj_mem := fun h hm k => hN h.1 k.1 hm k.2 }⟩
@[to_additive prod_addSubgroupOf_prod_normal]
instance prod_subgroupOf_prod_normal {H₁ K₁ : Subgroup G} {H₂ K₂ : Subgroup N}
[h₁ : (H₁.subgroupOf K₁).Normal] [h₂ : (H₂.subgroupOf K₂).Normal] :
((H₁.prod H₂).subgroupOf (K₁.prod K₂)).Normal where
conj_mem n hgHK g :=
⟨h₁.conj_mem ⟨(n : G × N).fst, (mem_prod.mp n.2).1⟩ hgHK.1
⟨(g : G × N).fst, (mem_prod.mp g.2).1⟩,
h₂.conj_mem ⟨(n : G × N).snd, (mem_prod.mp n.2).2⟩ hgHK.2
⟨(g : G × N).snd, (mem_prod.mp g.2).2⟩⟩
@[deprecated (since := "2025-03-11")]
alias _root_.AddSubgroup.sum_addSubgroupOf_sum_normal := AddSubgroup.prod_addSubgroupOf_prod_normal
@[to_additive prod_normal]
instance prod_normal (H : Subgroup G) (K : Subgroup N) [hH : H.Normal] [hK : K.Normal] :
(H.prod K).Normal where
conj_mem n hg g :=
⟨hH.conj_mem n.fst (Subgroup.mem_prod.mp hg).1 g.fst,
hK.conj_mem n.snd (Subgroup.mem_prod.mp hg).2 g.snd⟩
@[deprecated (since := "2025-03-11")]
alias _root_.AddSubgroup.sum_normal := AddSubgroup.prod_normal
@[to_additive]
theorem inf_subgroupOf_inf_normal_of_right (A B' B : Subgroup G)
[hN : (B'.subgroupOf B).Normal] : ((A ⊓ B').subgroupOf (A ⊓ B)).Normal := by
rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢
rw [inf_inf_inf_comm, inf_idem]
exact le_trans (inf_le_inf A.le_normalizer hN) (inf_normalizer_le_normalizer_inf)
@[to_additive]
theorem inf_subgroupOf_inf_normal_of_left {A' A : Subgroup G} (B : Subgroup G)
[hN : (A'.subgroupOf A).Normal] : ((A' ⊓ B).subgroupOf (A ⊓ B)).Normal := by
rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢
rw [inf_inf_inf_comm, inf_idem]
exact le_trans (inf_le_inf hN B.le_normalizer) (inf_normalizer_le_normalizer_inf)
@[to_additive]
instance normal_inf_normal (H K : Subgroup G) [hH : H.Normal] [hK : K.Normal] : (H ⊓ K).Normal :=
⟨fun n hmem g => ⟨hH.conj_mem n hmem.1 g, hK.conj_mem n hmem.2 g⟩⟩
@[to_additive]
theorem normal_iInf_normal {ι : Type*} {a : ι → Subgroup G}
(norm : ∀ i : ι, (a i).Normal) : (iInf a).Normal := by
constructor
intro g g_in_iInf h
rw [Subgroup.mem_iInf] at g_in_iInf ⊢
intro i
exact (norm i).conj_mem g (g_in_iInf i) h
@[to_additive]
theorem SubgroupNormal.mem_comm {H K : Subgroup G} (hK : H ≤ K) [hN : (H.subgroupOf K).Normal]
{a b : G} (hb : b ∈ K) (h : a * b ∈ H) : b * a ∈ H := by
have := (normal_subgroupOf_iff hK).mp hN (a * b) b h hb
rwa [mul_assoc, mul_assoc, mul_inv_cancel, mul_one] at this
/-- Elements of disjoint, normal subgroups commute. -/
@[to_additive "Elements of disjoint, normal subgroups commute."]
| Mathlib/Algebra/Group/Subgroup/Basic.lean | 894 | 900 | theorem commute_of_normal_of_disjoint (H₁ H₂ : Subgroup G) (hH₁ : H₁.Normal) (hH₂ : H₂.Normal)
(hdis : Disjoint H₁ H₂) (x y : G) (hx : x ∈ H₁) (hy : y ∈ H₂) : Commute x y := by | suffices x * y * x⁻¹ * y⁻¹ = 1 by
show x * y = y * x
· rw [mul_assoc, mul_eq_one_iff_eq_inv] at this
simpa
apply hdis.le_bot |
/-
Copyright (c) 2024 Miyahara Kō. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Miyahara Kō
-/
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Data.List.Defs
import Mathlib.Data.Set.Function
/-!
# iterate
Proves various lemmas about `List.iterate`.
-/
variable {α : Type*}
namespace List
@[simp]
theorem length_iterate (f : α → α) (a : α) (n : ℕ) : length (iterate f a n) = n := by
induction n generalizing a <;> simp [*]
@[simp]
| Mathlib/Data/List/Iterate.lean | 25 | 26 | theorem iterate_eq_nil {f : α → α} {a : α} {n : ℕ} : iterate f a n = [] ↔ n = 0 := by | rw [← length_eq_zero_iff, length_iterate] |
/-
Copyright (c) 2020 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa, Alex Meiburg
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.Algebra.Polynomial.Degree.Monomial
/-!
# Erase the leading term of a univariate polynomial
## Definition
* `eraseLead f`: the polynomial `f - leading term of f`
`eraseLead` serves as reduction step in an induction, shaving off one monomial from a polynomial.
The definition is set up so that it does not mention subtraction in the definition,
and thus works for polynomials over semirings as well as rings.
-/
noncomputable section
open Polynomial
open Polynomial Finset
namespace Polynomial
variable {R : Type*} [Semiring R] {f : R[X]}
/-- `eraseLead f` for a polynomial `f` is the polynomial obtained by
subtracting from `f` the leading term of `f`. -/
def eraseLead (f : R[X]) : R[X] :=
Polynomial.erase f.natDegree f
section EraseLead
theorem eraseLead_support (f : R[X]) : f.eraseLead.support = f.support.erase f.natDegree := by
simp only [eraseLead, support_erase]
theorem eraseLead_coeff (i : ℕ) :
f.eraseLead.coeff i = if i = f.natDegree then 0 else f.coeff i := by
simp only [eraseLead, coeff_erase]
@[simp]
theorem eraseLead_coeff_natDegree : f.eraseLead.coeff f.natDegree = 0 := by simp [eraseLead_coeff]
theorem eraseLead_coeff_of_ne (i : ℕ) (hi : i ≠ f.natDegree) : f.eraseLead.coeff i = f.coeff i := by
simp [eraseLead_coeff, hi]
@[simp]
theorem eraseLead_zero : eraseLead (0 : R[X]) = 0 := by simp only [eraseLead, erase_zero]
@[simp]
theorem eraseLead_add_monomial_natDegree_leadingCoeff (f : R[X]) :
f.eraseLead + monomial f.natDegree f.leadingCoeff = f :=
(add_comm _ _).trans (f.monomial_add_erase _)
@[simp]
theorem eraseLead_add_C_mul_X_pow (f : R[X]) :
f.eraseLead + C f.leadingCoeff * X ^ f.natDegree = f := by
rw [C_mul_X_pow_eq_monomial, eraseLead_add_monomial_natDegree_leadingCoeff]
@[simp]
theorem self_sub_monomial_natDegree_leadingCoeff {R : Type*} [Ring R] (f : R[X]) :
f - monomial f.natDegree f.leadingCoeff = f.eraseLead :=
(eq_sub_iff_add_eq.mpr (eraseLead_add_monomial_natDegree_leadingCoeff f)).symm
@[simp]
theorem self_sub_C_mul_X_pow {R : Type*} [Ring R] (f : R[X]) :
f - C f.leadingCoeff * X ^ f.natDegree = f.eraseLead := by
rw [C_mul_X_pow_eq_monomial, self_sub_monomial_natDegree_leadingCoeff]
theorem eraseLead_ne_zero (f0 : 2 ≤ #f.support) : eraseLead f ≠ 0 := by
rw [Ne, ← card_support_eq_zero, eraseLead_support]
exact
(zero_lt_one.trans_le <| (tsub_le_tsub_right f0 1).trans Finset.pred_card_le_card_erase).ne.symm
theorem lt_natDegree_of_mem_eraseLead_support {a : ℕ} (h : a ∈ (eraseLead f).support) :
a < f.natDegree := by
rw [eraseLead_support, mem_erase] at h
exact (le_natDegree_of_mem_supp a h.2).lt_of_ne h.1
theorem ne_natDegree_of_mem_eraseLead_support {a : ℕ} (h : a ∈ (eraseLead f).support) :
a ≠ f.natDegree :=
(lt_natDegree_of_mem_eraseLead_support h).ne
theorem natDegree_not_mem_eraseLead_support : f.natDegree ∉ (eraseLead f).support := fun h =>
ne_natDegree_of_mem_eraseLead_support h rfl
theorem eraseLead_support_card_lt (h : f ≠ 0) : #(eraseLead f).support < #f.support := by
rw [eraseLead_support]
exact card_lt_card (erase_ssubset <| natDegree_mem_support_of_nonzero h)
theorem card_support_eraseLead_add_one (h : f ≠ 0) : #f.eraseLead.support + 1 = #f.support := by
set c := #f.support with hc
cases h₁ : c
case zero =>
by_contra
exact h (card_support_eq_zero.mp h₁)
case succ =>
rw [eraseLead_support, card_erase_of_mem (natDegree_mem_support_of_nonzero h), ← hc, h₁]
rfl
@[simp]
theorem card_support_eraseLead : #f.eraseLead.support = #f.support - 1 := by
by_cases hf : f = 0
· rw [hf, eraseLead_zero, support_zero, card_empty]
· rw [← card_support_eraseLead_add_one hf, add_tsub_cancel_right]
theorem card_support_eraseLead' {c : ℕ} (fc : #f.support = c + 1) :
#f.eraseLead.support = c := by
rw [card_support_eraseLead, fc, add_tsub_cancel_right]
theorem card_support_eq_one_of_eraseLead_eq_zero (h₀ : f ≠ 0) (h₁ : f.eraseLead = 0) :
#f.support = 1 :=
(card_support_eq_zero.mpr h₁ ▸ card_support_eraseLead_add_one h₀).symm
theorem card_support_le_one_of_eraseLead_eq_zero (h : f.eraseLead = 0) : #f.support ≤ 1 := by
by_cases hpz : f = 0
case pos => simp [hpz]
case neg => exact le_of_eq (card_support_eq_one_of_eraseLead_eq_zero hpz h)
@[simp]
theorem eraseLead_monomial (i : ℕ) (r : R) : eraseLead (monomial i r) = 0 := by
classical
by_cases hr : r = 0
· subst r
simp only [monomial_zero_right, eraseLead_zero]
· rw [eraseLead, natDegree_monomial, if_neg hr, erase_monomial]
@[simp]
theorem eraseLead_C (r : R) : eraseLead (C r) = 0 :=
eraseLead_monomial _ _
@[simp]
theorem eraseLead_X : eraseLead (X : R[X]) = 0 :=
eraseLead_monomial _ _
@[simp]
theorem eraseLead_X_pow (n : ℕ) : eraseLead (X ^ n : R[X]) = 0 := by
rw [X_pow_eq_monomial, eraseLead_monomial]
@[simp]
theorem eraseLead_C_mul_X_pow (r : R) (n : ℕ) : eraseLead (C r * X ^ n) = 0 := by
rw [C_mul_X_pow_eq_monomial, eraseLead_monomial]
@[simp] lemma eraseLead_C_mul_X (r : R) : eraseLead (C r * X) = 0 := by
simpa using eraseLead_C_mul_X_pow _ 1
theorem eraseLead_add_of_degree_lt_left {p q : R[X]} (pq : q.degree < p.degree) :
(p + q).eraseLead = p.eraseLead + q := by
ext n
by_cases nd : n = p.natDegree
· rw [nd, eraseLead_coeff, if_pos (natDegree_add_eq_left_of_degree_lt pq).symm]
simpa using (coeff_eq_zero_of_degree_lt (lt_of_lt_of_le pq degree_le_natDegree)).symm
· rw [eraseLead_coeff, coeff_add, coeff_add, eraseLead_coeff, if_neg, if_neg nd]
rintro rfl
exact nd (natDegree_add_eq_left_of_degree_lt pq)
theorem eraseLead_add_of_natDegree_lt_left {p q : R[X]} (pq : q.natDegree < p.natDegree) :
(p + q).eraseLead = p.eraseLead + q :=
eraseLead_add_of_degree_lt_left (degree_lt_degree pq)
theorem eraseLead_add_of_degree_lt_right {p q : R[X]} (pq : p.degree < q.degree) :
(p + q).eraseLead = p + q.eraseLead := by
ext n
by_cases nd : n = q.natDegree
· rw [nd, eraseLead_coeff, if_pos (natDegree_add_eq_right_of_degree_lt pq).symm]
simpa using (coeff_eq_zero_of_degree_lt (lt_of_lt_of_le pq degree_le_natDegree)).symm
· rw [eraseLead_coeff, coeff_add, coeff_add, eraseLead_coeff, if_neg, if_neg nd]
rintro rfl
exact nd (natDegree_add_eq_right_of_degree_lt pq)
theorem eraseLead_add_of_natDegree_lt_right {p q : R[X]} (pq : p.natDegree < q.natDegree) :
(p + q).eraseLead = p + q.eraseLead :=
eraseLead_add_of_degree_lt_right (degree_lt_degree pq)
theorem eraseLead_degree_le : (eraseLead f).degree ≤ f.degree :=
f.degree_erase_le _
theorem degree_eraseLead_lt (hf : f ≠ 0) : (eraseLead f).degree < f.degree :=
f.degree_erase_lt hf
theorem eraseLead_natDegree_le_aux : (eraseLead f).natDegree ≤ f.natDegree :=
natDegree_le_natDegree eraseLead_degree_le
theorem eraseLead_natDegree_lt (f0 : 2 ≤ #f.support) : (eraseLead f).natDegree < f.natDegree :=
lt_of_le_of_ne eraseLead_natDegree_le_aux <|
ne_natDegree_of_mem_eraseLead_support <|
natDegree_mem_support_of_nonzero <| eraseLead_ne_zero f0
theorem natDegree_pos_of_eraseLead_ne_zero (h : f.eraseLead ≠ 0) : 0 < f.natDegree := by
by_contra h₂
rw [eq_C_of_natDegree_eq_zero (Nat.eq_zero_of_not_pos h₂)] at h
simp at h
theorem eraseLead_natDegree_lt_or_eraseLead_eq_zero (f : R[X]) :
(eraseLead f).natDegree < f.natDegree ∨ f.eraseLead = 0 := by
by_cases h : #f.support ≤ 1
· right
rw [← C_mul_X_pow_eq_self h]
simp
· left
apply eraseLead_natDegree_lt (lt_of_not_ge h)
theorem eraseLead_natDegree_le (f : R[X]) : (eraseLead f).natDegree ≤ f.natDegree - 1 := by
rcases f.eraseLead_natDegree_lt_or_eraseLead_eq_zero with (h | h)
· exact Nat.le_sub_one_of_lt h
· simp only [h, natDegree_zero, zero_le]
lemma natDegree_eraseLead (h : f.nextCoeff ≠ 0) : f.eraseLead.natDegree = f.natDegree - 1 := by
have := natDegree_pos_of_nextCoeff_ne_zero h
refine f.eraseLead_natDegree_le.antisymm <| le_natDegree_of_ne_zero ?_
rwa [eraseLead_coeff_of_ne _ (tsub_lt_self _ _).ne, ← nextCoeff_of_natDegree_pos]
all_goals positivity
lemma natDegree_eraseLead_add_one (h : f.nextCoeff ≠ 0) :
f.eraseLead.natDegree + 1 = f.natDegree := by
rw [natDegree_eraseLead h, tsub_add_cancel_of_le]
exact natDegree_pos_of_nextCoeff_ne_zero h
theorem natDegree_eraseLead_le_of_nextCoeff_eq_zero (h : f.nextCoeff = 0) :
f.eraseLead.natDegree ≤ f.natDegree - 2 := by
refine natDegree_le_pred (n := f.natDegree - 1) (eraseLead_natDegree_le f) ?_
rw [nextCoeff_eq_zero, natDegree_eq_zero] at h
obtain ⟨a, rfl⟩ | ⟨hf, h⟩ := h
· simp
rw [eraseLead_coeff_of_ne _ (tsub_lt_self hf zero_lt_one).ne, ← nextCoeff_of_natDegree_pos hf]
simp [nextCoeff_eq_zero, h, eq_zero_or_pos]
lemma two_le_natDegree_of_nextCoeff_eraseLead (hlead : f.eraseLead ≠ 0)
(hnext : f.nextCoeff = 0) : 2 ≤ f.natDegree := by
contrapose! hlead
rw [Nat.lt_succ_iff, Nat.le_one_iff_eq_zero_or_eq_one, natDegree_eq_zero, natDegree_eq_one]
at hlead
obtain ⟨a, rfl⟩ | ⟨a, ha, b, rfl⟩ := hlead
· simp
· rw [nextCoeff_C_mul_X_add_C ha] at hnext
subst b
simp
| Mathlib/Algebra/Polynomial/EraseLead.lean | 245 | 248 | theorem leadingCoeff_eraseLead_eq_nextCoeff (h : f.nextCoeff ≠ 0) :
f.eraseLead.leadingCoeff = f.nextCoeff := by | have := natDegree_pos_of_nextCoeff_ne_zero h
rw [leadingCoeff, nextCoeff, natDegree_eraseLead h, if_neg, |
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.RingTheory.MvPowerSeries.Basic
import Mathlib.Tactic.MoveAdd
import Mathlib.Algebra.MvPolynomial.Equiv
import Mathlib.RingTheory.Ideal.Basic
/-!
# Formal power series (in one variable)
This file defines (univariate) formal power series
and develops the basic properties of these objects.
A formal power series is to a polynomial like an infinite sum is to a finite sum.
Formal power series in one variable are defined from multivariate
power series as `PowerSeries R := MvPowerSeries Unit R`.
The file sets up the (semi)ring structure on univariate power series.
We provide the natural inclusion from polynomials to formal power series.
Additional results can be found in:
* `Mathlib.RingTheory.PowerSeries.Trunc`, truncation of power series;
* `Mathlib.RingTheory.PowerSeries.Inverse`, about inverses of power series,
and the fact that power series over a local ring form a local ring;
* `Mathlib.RingTheory.PowerSeries.Order`, the order of a power series at 0,
and application to the fact that power series over an integral domain
form an integral domain.
## Implementation notes
Because of its definition,
`PowerSeries R := MvPowerSeries Unit R`.
a lot of proofs and properties from the multivariate case
can be ported to the single variable case.
However, it means that formal power series are indexed by `Unit →₀ ℕ`,
which is of course canonically isomorphic to `ℕ`.
We then build some glue to treat formal power series as if they were indexed by `ℕ`.
Occasionally this leads to proofs that are uglier than expected.
-/
noncomputable section
open Finset (antidiagonal mem_antidiagonal)
/-- Formal power series over a coefficient type `R` -/
abbrev PowerSeries (R : Type*) :=
MvPowerSeries Unit R
namespace PowerSeries
open Finsupp (single)
variable {R : Type*}
section
-- Porting note: not available in Lean 4
-- local reducible PowerSeries
/--
`R⟦X⟧` is notation for `PowerSeries R`,
the semiring of formal power series in one variable over a semiring `R`.
-/
scoped notation:9000 R "⟦X⟧" => PowerSeries R
instance [Inhabited R] : Inhabited R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Zero R] : Zero R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddMonoid R] : AddMonoid R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddGroup R] : AddGroup R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddCommMonoid R] : AddCommMonoid R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddCommGroup R] : AddCommGroup R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Semiring R] : Semiring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [CommSemiring R] : CommSemiring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Ring R] : Ring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [CommRing R] : CommRing R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Nontrivial R] : Nontrivial R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R A⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S]
[IsScalarTower R S A] : IsScalarTower R S A⟦X⟧ :=
Pi.isScalarTower
instance {A} [Semiring A] [CommSemiring R] [Algebra R A] : Algebra R A⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
end
section Semiring
variable (R) [Semiring R]
/-- The `n`th coefficient of a formal power series. -/
def coeff (n : ℕ) : R⟦X⟧ →ₗ[R] R :=
MvPowerSeries.coeff R (single () n)
/-- The `n`th monomial with coefficient `a` as formal power series. -/
def monomial (n : ℕ) : R →ₗ[R] R⟦X⟧ :=
MvPowerSeries.monomial R (single () n)
variable {R}
theorem coeff_def {s : Unit →₀ ℕ} {n : ℕ} (h : s () = n) : coeff R n = MvPowerSeries.coeff R s := by
rw [coeff, ← h, ← Finsupp.unique_single s]
/-- Two formal power series are equal if all their coefficients are equal. -/
@[ext]
theorem ext {φ ψ : R⟦X⟧} (h : ∀ n, coeff R n φ = coeff R n ψ) : φ = ψ :=
MvPowerSeries.ext fun n => by
rw [← coeff_def]
· apply h
rfl
@[simp]
theorem forall_coeff_eq_zero (φ : R⟦X⟧) : (∀ n, coeff R n φ = 0) ↔ φ = 0 :=
⟨fun h => ext h, fun h => by simp [h]⟩
/-- Two formal power series are equal if all their coefficients are equal. -/
add_decl_doc PowerSeries.ext_iff
instance [Subsingleton R] : Subsingleton R⟦X⟧ := by
simp only [subsingleton_iff, PowerSeries.ext_iff]
subsingleton
/-- Constructor for formal power series. -/
def mk {R} (f : ℕ → R) : R⟦X⟧ := fun s => f (s ())
@[simp]
theorem coeff_mk (n : ℕ) (f : ℕ → R) : coeff R n (mk f) = f n :=
congr_arg f Finsupp.single_eq_same
theorem coeff_monomial (m n : ℕ) (a : R) : coeff R m (monomial R n a) = if m = n then a else 0 :=
calc
coeff R m (monomial R n a) = _ := MvPowerSeries.coeff_monomial _ _ _
_ = if m = n then a else 0 := by simp only [Finsupp.unique_single_eq_iff]
theorem monomial_eq_mk (n : ℕ) (a : R) : monomial R n a = mk fun m => if m = n then a else 0 :=
ext fun m => by rw [coeff_monomial, coeff_mk]
@[simp]
theorem coeff_monomial_same (n : ℕ) (a : R) : coeff R n (monomial R n a) = a :=
MvPowerSeries.coeff_monomial_same _ _
@[simp]
theorem coeff_comp_monomial (n : ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id :=
LinearMap.ext <| coeff_monomial_same n
variable (R)
/-- The constant coefficient of a formal power series. -/
def constantCoeff : R⟦X⟧ →+* R :=
MvPowerSeries.constantCoeff Unit R
/-- The constant formal power series. -/
def C : R →+* R⟦X⟧ :=
MvPowerSeries.C Unit R
@[simp] lemma algebraMap_eq {R : Type*} [CommSemiring R] : algebraMap R R⟦X⟧ = C R := rfl
variable {R}
/-- The variable of the formal power series ring. -/
def X : R⟦X⟧ :=
MvPowerSeries.X ()
theorem commute_X (φ : R⟦X⟧) : Commute φ X :=
MvPowerSeries.commute_X _ _
theorem X_mul {φ : R⟦X⟧} : X * φ = φ * X :=
MvPowerSeries.X_mul
theorem commute_X_pow (φ : R⟦X⟧) (n : ℕ) : Commute φ (X ^ n) :=
MvPowerSeries.commute_X_pow _ _ _
theorem X_pow_mul {φ : R⟦X⟧} {n : ℕ} : X ^ n * φ = φ * X ^ n :=
MvPowerSeries.X_pow_mul
@[simp]
theorem coeff_zero_eq_constantCoeff : ⇑(coeff R 0) = constantCoeff R := by
rw [coeff, Finsupp.single_zero]
rfl
theorem coeff_zero_eq_constantCoeff_apply (φ : R⟦X⟧) : coeff R 0 φ = constantCoeff R φ := by
rw [coeff_zero_eq_constantCoeff]
@[simp]
theorem monomial_zero_eq_C : ⇑(monomial R 0) = C R := by
-- This used to be `rw`, but we need `rw; rfl` after https://github.com/leanprover/lean4/pull/2644
rw [monomial, Finsupp.single_zero, MvPowerSeries.monomial_zero_eq_C]
rfl
theorem monomial_zero_eq_C_apply (a : R) : monomial R 0 a = C R a := by simp
theorem coeff_C (n : ℕ) (a : R) : coeff R n (C R a : R⟦X⟧) = if n = 0 then a else 0 := by
rw [← monomial_zero_eq_C_apply, coeff_monomial]
@[simp]
theorem coeff_zero_C (a : R) : coeff R 0 (C R a) = a := by
rw [coeff_C, if_pos rfl]
theorem coeff_ne_zero_C {a : R} {n : ℕ} (h : n ≠ 0) : coeff R n (C R a) = 0 := by
rw [coeff_C, if_neg h]
@[simp]
theorem coeff_succ_C {a : R} {n : ℕ} : coeff R (n + 1) (C R a) = 0 :=
coeff_ne_zero_C n.succ_ne_zero
theorem C_injective : Function.Injective (C R) := by
intro a b H
simp_rw [PowerSeries.ext_iff] at H
simpa only [coeff_zero_C] using H 0
protected theorem subsingleton_iff : Subsingleton R⟦X⟧ ↔ Subsingleton R := by
refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩
rw [subsingleton_iff] at h ⊢
exact fun a b ↦ C_injective (h (C R a) (C R b))
theorem X_eq : (X : R⟦X⟧) = monomial R 1 1 :=
rfl
theorem coeff_X (n : ℕ) : coeff R n (X : R⟦X⟧) = if n = 1 then 1 else 0 := by
rw [X_eq, coeff_monomial]
@[simp]
theorem coeff_zero_X : coeff R 0 (X : R⟦X⟧) = 0 := by
rw [coeff, Finsupp.single_zero, X, MvPowerSeries.coeff_zero_X]
@[simp]
theorem coeff_one_X : coeff R 1 (X : R⟦X⟧) = 1 := by rw [coeff_X, if_pos rfl]
@[simp]
theorem X_ne_zero [Nontrivial R] : (X : R⟦X⟧) ≠ 0 := fun H => by
simpa only [coeff_one_X, one_ne_zero, map_zero] using congr_arg (coeff R 1) H
theorem X_pow_eq (n : ℕ) : (X : R⟦X⟧) ^ n = monomial R n 1 :=
MvPowerSeries.X_pow_eq _ n
theorem coeff_X_pow (m n : ℕ) : coeff R m ((X : R⟦X⟧) ^ n) = if m = n then 1 else 0 := by
rw [X_pow_eq, coeff_monomial]
@[simp]
theorem coeff_X_pow_self (n : ℕ) : coeff R n ((X : R⟦X⟧) ^ n) = 1 := by
rw [coeff_X_pow, if_pos rfl]
@[simp]
theorem coeff_one (n : ℕ) : coeff R n (1 : R⟦X⟧) = if n = 0 then 1 else 0 :=
coeff_C n 1
theorem coeff_zero_one : coeff R 0 (1 : R⟦X⟧) = 1 :=
coeff_zero_C 1
theorem coeff_mul (n : ℕ) (φ ψ : R⟦X⟧) :
coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by
-- `rw` can't see that `PowerSeries = MvPowerSeries Unit`, so use `.trans`
refine (MvPowerSeries.coeff_mul _ φ ψ).trans ?_
rw [Finsupp.antidiagonal_single, Finset.sum_map]
rfl
@[simp]
theorem coeff_mul_C (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (φ * C R a) = coeff R n φ * a :=
MvPowerSeries.coeff_mul_C _ φ a
@[simp]
theorem coeff_C_mul (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (C R a * φ) = a * coeff R n φ :=
MvPowerSeries.coeff_C_mul _ φ a
@[simp]
theorem coeff_smul {S : Type*} [Semiring S] [Module R S] (n : ℕ) (φ : PowerSeries S) (a : R) :
coeff S n (a • φ) = a • coeff S n φ :=
rfl
@[simp]
theorem constantCoeff_smul {S : Type*} [Semiring S] [Module R S] (φ : PowerSeries S) (a : R) :
constantCoeff S (a • φ) = a • constantCoeff S φ :=
rfl
theorem smul_eq_C_mul (f : R⟦X⟧) (a : R) : a • f = C R a * f := by
ext
simp
@[simp]
theorem coeff_succ_mul_X (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (φ * X) = coeff R n φ := by
simp only [coeff, Finsupp.single_add]
convert φ.coeff_add_mul_monomial (single () n) (single () 1) _
rw [mul_one]
@[simp]
theorem coeff_succ_X_mul (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (X * φ) = coeff R n φ := by
simp only [coeff, Finsupp.single_add, add_comm n 1]
convert φ.coeff_add_monomial_mul (single () 1) (single () n) _
rw [one_mul]
theorem mul_X_cancel {φ ψ : R⟦X⟧} (h : φ * X = ψ * X) : φ = ψ := by
rw [PowerSeries.ext_iff] at h ⊢
intro n
simpa using h (n + 1)
theorem mul_X_injective : Function.Injective (· * X : R⟦X⟧ → R⟦X⟧) :=
fun _ _ ↦ mul_X_cancel
theorem mul_X_inj {φ ψ : R⟦X⟧} : φ * X = ψ * X ↔ φ = ψ :=
mul_X_injective.eq_iff
theorem X_mul_cancel {φ ψ : R⟦X⟧} (h : X * φ = X * ψ) : φ = ψ := by
rw [PowerSeries.ext_iff] at h ⊢
intro n
simpa using h (n + 1)
theorem X_mul_injective : Function.Injective (X * · : R⟦X⟧ → R⟦X⟧) :=
fun _ _ ↦ X_mul_cancel
theorem X_mul_inj {φ ψ : R⟦X⟧} : X * φ = X * ψ ↔ φ = ψ :=
X_mul_injective.eq_iff
@[simp]
theorem constantCoeff_C (a : R) : constantCoeff R (C R a) = a :=
rfl
@[simp]
theorem constantCoeff_comp_C : (constantCoeff R).comp (C R) = RingHom.id R :=
rfl
@[simp]
theorem constantCoeff_zero : constantCoeff R 0 = 0 :=
rfl
@[simp]
theorem constantCoeff_one : constantCoeff R 1 = 1 :=
rfl
@[simp]
theorem constantCoeff_X : constantCoeff R X = 0 :=
MvPowerSeries.coeff_zero_X _
@[simp]
theorem constantCoeff_mk {f : ℕ → R} : constantCoeff R (mk f) = f 0 := rfl
theorem coeff_zero_mul_X (φ : R⟦X⟧) : coeff R 0 (φ * X) = 0 := by simp
theorem coeff_zero_X_mul (φ : R⟦X⟧) : coeff R 0 (X * φ) = 0 := by simp
theorem constantCoeff_surj : Function.Surjective (constantCoeff R) :=
fun r => ⟨(C R) r, constantCoeff_C r⟩
-- The following section duplicates the API of `Data.Polynomial.Coeff` and should attempt to keep
-- up to date with that
section
theorem coeff_C_mul_X_pow (x : R) (k n : ℕ) :
coeff R n (C R x * X ^ k : R⟦X⟧) = if n = k then x else 0 := by
simp [X_pow_eq, coeff_monomial]
@[simp]
theorem coeff_mul_X_pow (p : R⟦X⟧) (n d : ℕ) :
coeff R (d + n) (p * X ^ n) = coeff R d p := by
rw [coeff_mul, Finset.sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one]
· rintro ⟨i, j⟩ h1 h2
rw [coeff_X_pow, if_neg, mul_zero]
rintro rfl
apply h2
rw [mem_antidiagonal, add_right_cancel_iff] at h1
subst h1
rfl
· exact fun h1 => (h1 (mem_antidiagonal.2 rfl)).elim
@[simp]
theorem coeff_X_pow_mul (p : R⟦X⟧) (n d : ℕ) :
coeff R (d + n) (X ^ n * p) = coeff R d p := by
rw [coeff_mul, Finset.sum_eq_single (n, d), coeff_X_pow, if_pos rfl, one_mul]
· rintro ⟨i, j⟩ h1 h2
rw [coeff_X_pow, if_neg, zero_mul]
rintro rfl
apply h2
rw [mem_antidiagonal, add_comm, add_right_cancel_iff] at h1
subst h1
rfl
· rw [add_comm]
exact fun h1 => (h1 (mem_antidiagonal.2 rfl)).elim
theorem mul_X_pow_cancel {k : ℕ} {φ ψ : R⟦X⟧} (h : φ * X ^ k = ψ * X ^ k) :
φ = ψ := by
rw [PowerSeries.ext_iff] at h ⊢
intro n
simpa using h (n + k)
theorem mul_X_pow_injective {k : ℕ} : Function.Injective (· * X ^ k : R⟦X⟧ → R⟦X⟧) :=
fun _ _ ↦ mul_X_pow_cancel
theorem mul_X_pow_inj {k : ℕ} {φ ψ : R⟦X⟧} :
φ * X ^ k = ψ * X ^ k ↔ φ = ψ :=
mul_X_pow_injective.eq_iff
| Mathlib/RingTheory/PowerSeries/Basic.lean | 438 | 448 | theorem X_pow_mul_cancel {k : ℕ} {φ ψ : R⟦X⟧} (h : X ^ k * φ = X ^ k * ψ) :
φ = ψ := by | rw [PowerSeries.ext_iff] at h ⊢
intro n
simpa using h (n + k)
theorem X_pow_mul_injective {k : ℕ} : Function.Injective (X ^ k * · : R⟦X⟧ → R⟦X⟧) :=
fun _ _ ↦ X_pow_mul_cancel
theorem X_pow_mul_inj {k : ℕ} {φ ψ : R⟦X⟧} :
X ^ k * φ = X ^ k * ψ ↔ φ = ψ := |
/-
Copyright (c) 2024 Mitchell Lee. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mitchell Lee
-/
import Mathlib.Data.ZMod.Basic
import Mathlib.GroupTheory.Coxeter.Basic
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Zify
/-!
# The length function, reduced words, and descents
Throughout this file, `B` is a type and `M : CoxeterMatrix B` is a Coxeter matrix.
`cs : CoxeterSystem M W` is a Coxeter system; that is, `W` is a group, and `cs` holds the data
of a group isomorphism `W ≃* M.group`, where `M.group` refers to the quotient of the free group on
`B` by the Coxeter relations given by the matrix `M`. See `Mathlib/GroupTheory/Coxeter/Basic.lean`
for more details.
Given any element $w \in W$, its *length* (`CoxeterSystem.length`), denoted $\ell(w)$, is the
minimum number $\ell$ such that $w$ can be written as a product of a sequence of $\ell$ simple
reflections:
$$w = s_{i_1} \cdots s_{i_\ell}.$$
We prove for all $w_1, w_2 \in W$ that $\ell (w_1 w_2) \leq \ell (w_1) + \ell (w_2)$
and that $\ell (w_1 w_2)$ has the same parity as $\ell (w_1) + \ell (w_2)$.
We define a *reduced word* (`CoxeterSystem.IsReduced`) for an element $w \in W$ to be a way of
writing $w$ as a product of exactly $\ell(w)$ simple reflections. Every element of $W$ has a reduced
word.
We say that $i \in B$ is a *left descent* (`CoxeterSystem.IsLeftDescent`) of $w \in W$ if
$\ell(s_i w) < \ell(w)$. We show that if $i$ is a left descent of $w$, then
$\ell(s_i w) + 1 = \ell(w)$. On the other hand, if $i$ is not a left descent of $w$, then
$\ell(s_i w) = \ell(w) + 1$. We similarly define right descents (`CoxeterSystem.IsRightDescent`) and
prove analogous results.
## Main definitions
* `cs.length`
* `cs.IsReduced`
* `cs.IsLeftDescent`
* `cs.IsRightDescent`
## References
* [A. Björner and F. Brenti, *Combinatorics of Coxeter Groups*](bjorner2005)
-/
assert_not_exists TwoSidedIdeal
namespace CoxeterSystem
open List Matrix Function
variable {B : Type*}
variable {W : Type*} [Group W]
variable {M : CoxeterMatrix B} (cs : CoxeterSystem M W)
local prefix:100 "s" => cs.simple
local prefix:100 "π" => cs.wordProd
/-! ### Length -/
private theorem exists_word_with_prod (w : W) : ∃ n ω, ω.length = n ∧ π ω = w := by
rcases cs.wordProd_surjective w with ⟨ω, rfl⟩
use ω.length, ω
open scoped Classical in
/-- The length of `w`; i.e., the minimum number of simple reflections that
must be multiplied to form `w`. -/
noncomputable def length (w : W) : ℕ := Nat.find (cs.exists_word_with_prod w)
local prefix:100 "ℓ" => cs.length
theorem exists_reduced_word (w : W) : ∃ ω, ω.length = ℓ w ∧ w = π ω := by
classical
have := Nat.find_spec (cs.exists_word_with_prod w)
tauto
open scoped Classical in
theorem length_wordProd_le (ω : List B) : ℓ (π ω) ≤ ω.length :=
Nat.find_min' (cs.exists_word_with_prod (π ω)) ⟨ω, by tauto⟩
@[simp] theorem length_one : ℓ (1 : W) = 0 := Nat.eq_zero_of_le_zero (cs.length_wordProd_le [])
@[simp]
theorem length_eq_zero_iff {w : W} : ℓ w = 0 ↔ w = 1 := by
constructor
· intro h
rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
have : ω = [] := eq_nil_of_length_eq_zero (hω.trans h)
rw [this, wordProd_nil]
· rintro rfl
exact cs.length_one
@[simp]
theorem length_inv (w : W) : ℓ (w⁻¹) = ℓ w := by
apply Nat.le_antisymm
· rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
have := cs.length_wordProd_le (List.reverse ω)
rwa [wordProd_reverse, length_reverse, hω] at this
· rcases cs.exists_reduced_word w⁻¹ with ⟨ω, hω, h'ω⟩
have := cs.length_wordProd_le (List.reverse ω)
rwa [wordProd_reverse, length_reverse, ← h'ω, hω, inv_inv] at this
theorem length_mul_le (w₁ w₂ : W) :
ℓ (w₁ * w₂) ≤ ℓ w₁ + ℓ w₂ := by
rcases cs.exists_reduced_word w₁ with ⟨ω₁, hω₁, rfl⟩
rcases cs.exists_reduced_word w₂ with ⟨ω₂, hω₂, rfl⟩
have := cs.length_wordProd_le (ω₁ ++ ω₂)
simpa [hω₁, hω₂, wordProd_append] using this
theorem length_mul_ge_length_sub_length (w₁ w₂ : W) :
ℓ w₁ - ℓ w₂ ≤ ℓ (w₁ * w₂) := by
simpa [Nat.sub_le_of_le_add] using cs.length_mul_le (w₁ * w₂) w₂⁻¹
theorem length_mul_ge_length_sub_length' (w₁ w₂ : W) :
ℓ w₂ - ℓ w₁ ≤ ℓ (w₁ * w₂) := by
simpa [Nat.sub_le_of_le_add, add_comm] using cs.length_mul_le w₁⁻¹ (w₁ * w₂)
theorem length_mul_ge_max (w₁ w₂ : W) :
max (ℓ w₁ - ℓ w₂) (ℓ w₂ - ℓ w₁) ≤ ℓ (w₁ * w₂) :=
max_le_iff.mpr ⟨length_mul_ge_length_sub_length _ _ _, length_mul_ge_length_sub_length' _ _ _⟩
/-- The homomorphism that sends each element `w : W` to the parity of the length of `w`.
(See `lengthParity_eq_ofAdd_length`.) -/
def lengthParity : W →* Multiplicative (ZMod 2) := cs.lift ⟨fun _ ↦ Multiplicative.ofAdd 1, by
simp_rw [CoxeterMatrix.IsLiftable, ← ofAdd_add, (by decide : (1 + 1 : ZMod 2) = 0)]
simp⟩
theorem lengthParity_simple (i : B) :
cs.lengthParity (s i) = Multiplicative.ofAdd 1 := cs.lift_apply_simple _ _
theorem lengthParity_comp_simple :
cs.lengthParity ∘ cs.simple = fun _ ↦ Multiplicative.ofAdd 1 := funext cs.lengthParity_simple
theorem lengthParity_eq_ofAdd_length (w : W) :
cs.lengthParity w = Multiplicative.ofAdd (↑(ℓ w)) := by
rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
rw [← hω, wordProd, map_list_prod, List.map_map, lengthParity_comp_simple, map_const',
prod_replicate, ← ofAdd_nsmul, nsmul_one]
theorem length_mul_mod_two (w₁ w₂ : W) : ℓ (w₁ * w₂) % 2 = (ℓ w₁ + ℓ w₂) % 2 := by
rw [← ZMod.natCast_eq_natCast_iff', Nat.cast_add]
simpa only [lengthParity_eq_ofAdd_length, ofAdd_add] using map_mul cs.lengthParity w₁ w₂
@[simp]
theorem length_simple (i : B) : ℓ (s i) = 1 := by
apply Nat.le_antisymm
· simpa using cs.length_wordProd_le [i]
· by_contra! length_lt_one
have : cs.lengthParity (s i) = Multiplicative.ofAdd 0 := by
rw [lengthParity_eq_ofAdd_length, Nat.lt_one_iff.mp length_lt_one, Nat.cast_zero]
have : Multiplicative.ofAdd (0 : ZMod 2) = Multiplicative.ofAdd 1 :=
this.symm.trans (cs.lengthParity_simple i)
contradiction
theorem length_eq_one_iff {w : W} : ℓ w = 1 ↔ ∃ i : B, w = s i := by
constructor
· intro h
rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
rcases List.length_eq_one_iff.mp (hω.trans h) with ⟨i, rfl⟩
exact ⟨i, cs.wordProd_singleton i⟩
· rintro ⟨i, rfl⟩
exact cs.length_simple i
theorem length_mul_simple_ne (w : W) (i : B) : ℓ (w * s i) ≠ ℓ w := by
intro eq
have length_mod_two := cs.length_mul_mod_two w (s i)
rw [eq, length_simple] at length_mod_two
rcases Nat.mod_two_eq_zero_or_one (ℓ w) with even | odd
· rw [even, Nat.succ_mod_two_eq_one_iff.mpr even] at length_mod_two
contradiction
· rw [odd, Nat.succ_mod_two_eq_zero_iff.mpr odd] at length_mod_two
contradiction
theorem length_simple_mul_ne (w : W) (i : B) : ℓ (s i * w) ≠ ℓ w := by
convert cs.length_mul_simple_ne w⁻¹ i using 1
· convert cs.length_inv ?_ using 2
simp
· simp
theorem length_mul_simple (w : W) (i : B) :
ℓ (w * s i) = ℓ w + 1 ∨ ℓ (w * s i) + 1 = ℓ w := by
rcases Nat.lt_or_gt_of_ne (cs.length_mul_simple_ne w i) with lt | gt
· -- lt : ℓ (w * s i) < ℓ w
right
have length_ge := cs.length_mul_ge_length_sub_length w (s i)
simp only [length_simple, tsub_le_iff_right] at length_ge
-- length_ge : ℓ w ≤ ℓ (w * s i) + 1
omega
· -- gt : ℓ w < ℓ (w * s i)
left
have length_le := cs.length_mul_le w (s i)
simp only [length_simple] at length_le
-- length_le : ℓ (w * s i) ≤ ℓ w + 1
omega
theorem length_simple_mul (w : W) (i : B) :
ℓ (s i * w) = ℓ w + 1 ∨ ℓ (s i * w) + 1 = ℓ w := by
have := cs.length_mul_simple w⁻¹ i
rwa [(by simp : w⁻¹ * (s i) = ((s i) * w)⁻¹), length_inv, length_inv] at this
/-! ### Reduced words -/
/-- The proposition that `ω` is reduced; that is, it has minimal length among all words that
represent the same element of `W`. -/
def IsReduced (ω : List B) : Prop := ℓ (π ω) = ω.length
@[simp]
theorem isReduced_reverse_iff (ω : List B) : cs.IsReduced (ω.reverse) ↔ cs.IsReduced ω := by
simp [IsReduced]
theorem IsReduced.reverse {cs : CoxeterSystem M W} {ω : List B}
(hω : cs.IsReduced ω) : cs.IsReduced (ω.reverse) :=
(cs.isReduced_reverse_iff ω).mpr hω
theorem exists_reduced_word' (w : W) : ∃ ω : List B, cs.IsReduced ω ∧ w = π ω := by
rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
use ω
tauto
private theorem isReduced_take_and_drop {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) :
cs.IsReduced (ω.take j) ∧ cs.IsReduced (ω.drop j) := by
have h₁ : ℓ (π (ω.take j)) ≤ (ω.take j).length := cs.length_wordProd_le (ω.take j)
have h₂ : ℓ (π (ω.drop j)) ≤ (ω.drop j).length := cs.length_wordProd_le (ω.drop j)
have h₃ := calc
(ω.take j).length + (ω.drop j).length
_ = ω.length := by rw [← List.length_append, ω.take_append_drop j]
_ = ℓ (π ω) := hω.symm
_ = ℓ (π (ω.take j) * π (ω.drop j)) := by rw [← cs.wordProd_append, ω.take_append_drop j]
_ ≤ ℓ (π (ω.take j)) + ℓ (π (ω.drop j)) := cs.length_mul_le _ _
unfold IsReduced
omega
theorem IsReduced.take {cs : CoxeterSystem M W} {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) :
cs.IsReduced (ω.take j) :=
(isReduced_take_and_drop _ hω _).1
theorem IsReduced.drop {cs : CoxeterSystem M W} {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) :
cs.IsReduced (ω.drop j) :=
(isReduced_take_and_drop _ hω _).2
theorem not_isReduced_alternatingWord (i i' : B) {m : ℕ} (hM : M i i' ≠ 0) (hm : m > M i i') :
¬cs.IsReduced (alternatingWord i i' m) := by
induction' hm with m _ ih
· -- Base case; m = M i i' + 1
suffices h : ℓ (π (alternatingWord i i' (M i i' + 1))) < M i i' + 1 by
unfold IsReduced
rw [Nat.succ_eq_add_one, length_alternatingWord]
omega
have : M i i' + 1 ≤ M i i' * 2 := by linarith [Nat.one_le_iff_ne_zero.mpr hM]
rw [cs.prod_alternatingWord_eq_prod_alternatingWord_sub i i' _ this]
have : M i i' * 2 - (M i i' + 1) = M i i' - 1 := by omega
rw [this]
calc
ℓ (π (alternatingWord i' i (M i i' - 1)))
_ ≤ (alternatingWord i' i (M i i' - 1)).length := cs.length_wordProd_le _
_ = M i i' - 1 := length_alternatingWord _ _ _
_ ≤ M i i' := Nat.sub_le _ _
_ < M i i' + 1 := Nat.lt_succ_self _
· -- Inductive step
contrapose! ih
rw [alternatingWord_succ'] at ih
apply IsReduced.drop (j := 1) at ih
simpa using ih
/-! ### Descents -/
/-- The proposition that `i` is a left descent of `w`; that is, $\ell(s_i w) < \ell(w)$. -/
def IsLeftDescent (w : W) (i : B) : Prop := ℓ (s i * w) < ℓ w
/-- The proposition that `i` is a right descent of `w`; that is, $\ell(w s_i) < \ell(w)$. -/
def IsRightDescent (w : W) (i : B) : Prop := ℓ (w * s i) < ℓ w
theorem not_isLeftDescent_one (i : B) : ¬cs.IsLeftDescent 1 i := by simp [IsLeftDescent]
theorem not_isRightDescent_one (i : B) : ¬cs.IsRightDescent 1 i := by simp [IsRightDescent]
theorem isLeftDescent_inv_iff {w : W} {i : B} :
cs.IsLeftDescent w⁻¹ i ↔ cs.IsRightDescent w i := by
unfold IsLeftDescent IsRightDescent
nth_rw 1 [← length_inv]
simp
theorem isRightDescent_inv_iff {w : W} {i : B} :
cs.IsRightDescent w⁻¹ i ↔ cs.IsLeftDescent w i := by
simpa using (cs.isLeftDescent_inv_iff (w := w⁻¹)).symm
theorem exists_leftDescent_of_ne_one {w : W} (hw : w ≠ 1) : ∃ i : B, cs.IsLeftDescent w i := by
rcases cs.exists_reduced_word w with ⟨ω, h, rfl⟩
have h₁ : ω ≠ [] := by rintro rfl; simp at hw
rcases List.exists_cons_of_ne_nil h₁ with ⟨i, ω', rfl⟩
use i
rw [IsLeftDescent, ← h, wordProd_cons, simple_mul_simple_cancel_left]
calc
ℓ (π ω') ≤ ω'.length := cs.length_wordProd_le ω'
_ < (i :: ω').length := by simp
theorem exists_rightDescent_of_ne_one {w : W} (hw : w ≠ 1) : ∃ i : B, cs.IsRightDescent w i := by
simp only [← isLeftDescent_inv_iff]
apply exists_leftDescent_of_ne_one
simpa
theorem isLeftDescent_iff {w : W} {i : B} :
cs.IsLeftDescent w i ↔ ℓ (s i * w) + 1 = ℓ w := by
unfold IsLeftDescent
constructor
· intro _
exact (cs.length_simple_mul w i).resolve_left (by omega)
· omega
| Mathlib/GroupTheory/Coxeter/Length.lean | 314 | 321 | theorem not_isLeftDescent_iff {w : W} {i : B} :
¬cs.IsLeftDescent w i ↔ ℓ (s i * w) = ℓ w + 1 := by | unfold IsLeftDescent
constructor
· intro _
exact (cs.length_simple_mul w i).resolve_right (by omega)
· omega |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Fin.Fin2
import Mathlib.Data.PFun
import Mathlib.Data.Vector3
import Mathlib.NumberTheory.PellMatiyasevic
/-!
# Diophantine functions and Matiyasevic's theorem
Hilbert's tenth problem asked whether there exists an algorithm which for a given integer polynomial
determines whether this polynomial has integer solutions. It was answered in the negative in 1970,
the final step being completed by Matiyasevic who showed that the power function is Diophantine.
Here a function is called Diophantine if its graph is Diophantine as a set. A subset `S ⊆ ℕ ^ α` in
turn is called Diophantine if there exists an integer polynomial on `α ⊕ β` such that `v ∈ S` iff
there exists `t : ℕ^β` with `p (v, t) = 0`.
## Main definitions
* `IsPoly`: a predicate stating that a function is a multivariate integer polynomial.
* `Poly`: the type of multivariate integer polynomial functions.
* `Dioph`: a predicate stating that a set is Diophantine, i.e. a set `S ⊆ ℕ^α` is
Diophantine if there exists a polynomial on `α ⊕ β` such that `v ∈ S` iff there
exists `t : ℕ^β` with `p (v, t) = 0`.
* `DiophFn`: a predicate on a function stating that it is Diophantine in the sense that its graph
is Diophantine as a set.
## Main statements
* `pell_dioph` states that solutions to Pell's equation form a Diophantine set.
* `pow_dioph` states that the power function is Diophantine, a version of Matiyasevic's theorem.
## References
* [M. Carneiro, _A Lean formalization of Matiyasevic's theorem_][carneiro2018matiyasevic]
* [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916]
## Tags
Matiyasevic's theorem, Hilbert's tenth problem
## TODO
* Finish the solution of Hilbert's tenth problem.
* Connect `Poly` to `MvPolynomial`
-/
open Fin2 Function Nat Sum
local infixr:67 " ::ₒ " => Option.elim'
local infixr:65 " ⊗ " => Sum.elim
universe u
/-!
### Multivariate integer polynomials
Note that this duplicates `MvPolynomial`.
-/
section Polynomials
variable {α β : Type*}
/-- A predicate asserting that a function is a multivariate integer polynomial.
(We are being a bit lazy here by allowing many representations for multiplication,
rather than only allowing monomials and addition, but the definition is equivalent
and this is easier to use.) -/
inductive IsPoly : ((α → ℕ) → ℤ) → Prop
| proj : ∀ i, IsPoly fun x : α → ℕ => x i
| const : ∀ n : ℤ, IsPoly fun _ : α → ℕ => n
| sub : ∀ {f g : (α → ℕ) → ℤ}, IsPoly f → IsPoly g → IsPoly fun x => f x - g x
| mul : ∀ {f g : (α → ℕ) → ℤ}, IsPoly f → IsPoly g → IsPoly fun x => f x * g x
theorem IsPoly.neg {f : (α → ℕ) → ℤ} : IsPoly f → IsPoly (-f) := by
rw [← zero_sub]; exact (IsPoly.const 0).sub
| Mathlib/NumberTheory/Dioph.lean | 85 | 86 | theorem IsPoly.add {f g : (α → ℕ) → ℤ} (hf : IsPoly f) (hg : IsPoly g) : IsPoly (f + g) := by | rw [← sub_neg_eq_add]; exact hf.sub hg.neg |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Order.Iterate
import Mathlib.Order.SemiconjSup
import Mathlib.Topology.Order.MonotoneContinuity
import Mathlib.Algebra.CharP.Defs
/-!
# Translation number of a monotone real map that commutes with `x ↦ x + 1`
Let `f : ℝ → ℝ` be a monotone map such that `f (x + 1) = f x + 1` for all `x`. Then the limit
$$
\tau(f)=\lim_{n\to\infty}{f^n(x)-x}{n}
$$
exists and does not depend on `x`. This number is called the *translation number* of `f`.
Different authors use different notation for this number: `τ`, `ρ`, `rot`, etc
In this file we define a structure `CircleDeg1Lift` for bundled maps with these properties, define
translation number of `f : CircleDeg1Lift`, prove some estimates relating `f^n(x)-x` to `τ(f)`. In
case of a continuous map `f` we also prove that `f` admits a point `x` such that `f^n(x)=x+m` if and
only if `τ(f)=m/n`.
Maps of this type naturally appear as lifts of orientation preserving circle homeomorphisms. More
precisely, let `f` be an orientation preserving homeomorphism of the circle $S^1=ℝ/ℤ$, and
consider a real number `a` such that
`⟦a⟧ = f 0`, where `⟦⟧` means the natural projection `ℝ → ℝ/ℤ`. Then there exists a unique
continuous function `F : ℝ → ℝ` such that `F 0 = a` and `⟦F x⟧ = f ⟦x⟧` for all `x` (this fact is
not formalized yet). This function is strictly monotone, continuous, and satisfies
`F (x + 1) = F x + 1`. The number `⟦τ F⟧ : ℝ / ℤ` is called the *rotation number* of `f`.
It does not depend on the choice of `a`.
## Main definitions
* `CircleDeg1Lift`: a monotone map `f : ℝ → ℝ` such that `f (x + 1) = f x + 1` for all `x`;
the type `CircleDeg1Lift` is equipped with `Lattice` and `Monoid` structures; the
multiplication is given by composition: `(f * g) x = f (g x)`.
* `CircleDeg1Lift.translationNumber`: translation number of `f : CircleDeg1Lift`.
## Main statements
We prove the following properties of `CircleDeg1Lift.translationNumber`.
* `CircleDeg1Lift.translationNumber_eq_of_dist_bounded`: if the distance between `(f^n) 0`
and `(g^n) 0` is bounded from above uniformly in `n : ℕ`, then `f` and `g` have equal
translation numbers.
* `CircleDeg1Lift.translationNumber_eq_of_semiconjBy`: if two `CircleDeg1Lift` maps `f`, `g`
are semiconjugate by a `CircleDeg1Lift` map, then `τ f = τ g`.
* `CircleDeg1Lift.translationNumber_units_inv`: if `f` is an invertible `CircleDeg1Lift` map
(equivalently, `f` is a lift of an orientation-preserving circle homeomorphism), then
the translation number of `f⁻¹` is the negative of the translation number of `f`.
* `CircleDeg1Lift.translationNumber_mul_of_commute`: if `f` and `g` commute, then
`τ (f * g) = τ f + τ g`.
* `CircleDeg1Lift.translationNumber_eq_rat_iff`: the translation number of `f` is equal to
a rational number `m / n` if and only if `(f^n) x = x + m` for some `x`.
* `CircleDeg1Lift.semiconj_of_bijective_of_translationNumber_eq`: if `f` and `g` are two
bijective `CircleDeg1Lift` maps and their translation numbers are equal, then these
maps are semiconjugate to each other.
* `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`: let `f₁` and `f₂` be
two actions of a group `G` on the circle by degree 1 maps (formally, `f₁` and `f₂` are two
homomorphisms from `G →* CircleDeg1Lift`). If the translation numbers of `f₁ g` and `f₂ g` are
equal to each other for all `g : G`, then these two actions are semiconjugate by some
`F : CircleDeg1Lift`. This is a version of Proposition 5.4 from [Étienne Ghys, Groupes
d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes].
## Notation
We use a local notation `τ` for the translation number of `f : CircleDeg1Lift`.
## Implementation notes
We define the translation number of `f : CircleDeg1Lift` to be the limit of the sequence
`(f ^ (2 ^ n)) 0 / (2 ^ n)`, then prove that `((f ^ n) x - x) / n` tends to this number for any `x`.
This way it is much easier to prove that the limit exists and basic properties of the limit.
We define translation number for a wider class of maps `f : ℝ → ℝ` instead of lifts of orientation
preserving circle homeomorphisms for two reasons:
* non-strictly monotone circle self-maps with discontinuities naturally appear as Poincaré maps
for some flows on the two-torus (e.g., one can take a constant flow and glue in a few Cherry
cells);
* definition and some basic properties still work for this class.
## References
* [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes]
## TODO
Here are some short-term goals.
* Introduce a structure or a typeclass for lifts of circle homeomorphisms. We use
`Units CircleDeg1Lift` for now, but it's better to have a dedicated type (or a typeclass?).
* Prove that the `SemiconjBy` relation on circle homeomorphisms is an equivalence relation.
* Introduce `ConditionallyCompleteLattice` structure, use it in the proof of
`CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`.
* Prove that the orbits of the irrational rotation are dense in the circle. Deduce that a
homeomorphism with an irrational rotation is semiconjugate to the corresponding irrational
translation by a continuous `CircleDeg1Lift`.
## Tags
circle homeomorphism, rotation number
-/
open Filter Set Int Topology
open Function hiding Commute
/-!
### Definition and monoid structure
-/
/-- A lift of a monotone degree one map `S¹ → S¹`. -/
structure CircleDeg1Lift : Type extends ℝ →o ℝ where
map_add_one' : ∀ x, toFun (x + 1) = toFun x + 1
namespace CircleDeg1Lift
instance : FunLike CircleDeg1Lift ℝ ℝ where
coe f := f.toFun
coe_injective' | ⟨⟨_, _⟩, _⟩, ⟨⟨_, _⟩, _⟩, rfl => rfl
instance : OrderHomClass CircleDeg1Lift ℝ ℝ where
map_rel f _ _ h := f.monotone' h
@[simp] theorem coe_mk (f h) : ⇑(mk f h) = f := rfl
variable (f g : CircleDeg1Lift)
@[simp] theorem coe_toOrderHom : ⇑f.toOrderHom = f := rfl
protected theorem monotone : Monotone f := f.monotone'
@[mono] theorem mono {x y} (h : x ≤ y) : f x ≤ f y := f.monotone h
theorem strictMono_iff_injective : StrictMono f ↔ Injective f :=
f.monotone.strictMono_iff_injective
@[simp]
theorem map_add_one : ∀ x, f (x + 1) = f x + 1 :=
f.map_add_one'
@[simp]
theorem map_one_add (x : ℝ) : f (1 + x) = 1 + f x := by rw [add_comm, map_add_one, add_comm 1]
@[ext]
theorem ext ⦃f g : CircleDeg1Lift⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
instance : Monoid CircleDeg1Lift where
mul f g :=
{ toOrderHom := f.1.comp g.1
map_add_one' := fun x => by simp [map_add_one] }
one := ⟨.id, fun _ => rfl⟩
mul_one _ := rfl
one_mul _ := rfl
mul_assoc _ _ _ := DFunLike.coe_injective rfl
instance : Inhabited CircleDeg1Lift := ⟨1⟩
@[simp]
theorem coe_mul : ⇑(f * g) = f ∘ g :=
rfl
theorem mul_apply (x) : (f * g) x = f (g x) :=
rfl
@[simp]
theorem coe_one : ⇑(1 : CircleDeg1Lift) = id :=
rfl
instance unitsHasCoeToFun : CoeFun CircleDeg1Liftˣ fun _ => ℝ → ℝ :=
⟨fun f => ⇑(f : CircleDeg1Lift)⟩
@[simp]
theorem units_inv_apply_apply (f : CircleDeg1Liftˣ) (x : ℝ) :
(f⁻¹ : CircleDeg1Liftˣ) (f x) = x := by simp only [← mul_apply, f.inv_mul, coe_one, id]
@[simp]
theorem units_apply_inv_apply (f : CircleDeg1Liftˣ) (x : ℝ) :
f ((f⁻¹ : CircleDeg1Liftˣ) x) = x := by simp only [← mul_apply, f.mul_inv, coe_one, id]
/-- If a lift of a circle map is bijective, then it is an order automorphism of the line. -/
def toOrderIso : CircleDeg1Liftˣ →* ℝ ≃o ℝ where
toFun f :=
{ toFun := f
invFun := ⇑f⁻¹
left_inv := units_inv_apply_apply f
right_inv := units_apply_inv_apply f
map_rel_iff' := ⟨fun h => by simpa using mono (↑f⁻¹) h, mono f⟩ }
map_one' := rfl
map_mul' _ _ := rfl
@[simp]
theorem coe_toOrderIso (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f) = f :=
rfl
@[simp]
theorem coe_toOrderIso_symm (f : CircleDeg1Liftˣ) :
⇑(toOrderIso f).symm = (f⁻¹ : CircleDeg1Liftˣ) :=
rfl
@[simp]
theorem coe_toOrderIso_inv (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f)⁻¹ = (f⁻¹ : CircleDeg1Liftˣ) :=
rfl
theorem isUnit_iff_bijective {f : CircleDeg1Lift} : IsUnit f ↔ Bijective f :=
⟨fun ⟨u, h⟩ => h ▸ (toOrderIso u).bijective, fun h =>
Units.isUnit
{ val := f
inv :=
{ toFun := (Equiv.ofBijective f h).symm
monotone' := fun x y hxy =>
(f.strictMono_iff_injective.2 h.1).le_iff_le.1
(by simp only [Equiv.ofBijective_apply_symm_apply f h, hxy])
map_add_one' := fun x =>
h.1 <| by simp only [Equiv.ofBijective_apply_symm_apply f, f.map_add_one] }
val_inv := ext <| Equiv.ofBijective_apply_symm_apply f h
inv_val := ext <| Equiv.ofBijective_symm_apply_apply f h }⟩
theorem coe_pow : ∀ n : ℕ, ⇑(f ^ n) = f^[n]
| 0 => rfl
| n + 1 => by
ext x
simp [coe_pow n, pow_succ]
theorem semiconjBy_iff_semiconj {f g₁ g₂ : CircleDeg1Lift} :
SemiconjBy f g₁ g₂ ↔ Semiconj f g₁ g₂ :=
CircleDeg1Lift.ext_iff
theorem commute_iff_commute {f g : CircleDeg1Lift} : Commute f g ↔ Function.Commute f g :=
CircleDeg1Lift.ext_iff
/-!
### Translate by a constant
-/
/-- The map `y ↦ x + y` as a `CircleDeg1Lift`. More precisely, we define a homomorphism from
`Multiplicative ℝ` to `CircleDeg1Liftˣ`, so the translation by `x` is
`translation (Multiplicative.ofAdd x)`. -/
def translate : Multiplicative ℝ →* CircleDeg1Liftˣ := MonoidHom.toHomUnits <|
{ toFun := fun x =>
⟨⟨fun y => x.toAdd + y, fun _ _ h => add_le_add_left h _⟩, fun _ =>
(add_assoc _ _ _).symm⟩
map_one' := ext <| zero_add
map_mul' := fun _ _ => ext <| add_assoc _ _ }
@[simp]
theorem translate_apply (x y : ℝ) : translate (Multiplicative.ofAdd x) y = x + y :=
rfl
@[simp]
theorem translate_inv_apply (x y : ℝ) : (translate <| Multiplicative.ofAdd x)⁻¹ y = -x + y :=
rfl
@[simp]
theorem translate_zpow (x : ℝ) (n : ℤ) :
translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := by
simp only [← zsmul_eq_mul, ofAdd_zsmul, MonoidHom.map_zpow]
@[simp]
theorem translate_pow (x : ℝ) (n : ℕ) :
translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) :=
translate_zpow x n
@[simp]
theorem translate_iterate (x : ℝ) (n : ℕ) :
(translate (Multiplicative.ofAdd x))^[n] = translate (Multiplicative.ofAdd <| ↑n * x) := by
rw [← coe_pow, ← Units.val_pow_eq_pow_val, translate_pow]
/-!
### Commutativity with integer translations
In this section we prove that `f` commutes with translations by an integer number.
First we formulate these statements (for a natural or an integer number,
addition on the left or on the right, addition or subtraction) using `Function.Commute`,
then reformulate as `simp` lemmas `map_int_add` etc.
-/
theorem commute_nat_add (n : ℕ) : Function.Commute f (n + ·) := by
simpa only [nsmul_one, add_left_iterate] using Function.Commute.iterate_right f.map_one_add n
theorem commute_add_nat (n : ℕ) : Function.Commute f (· + n) := by
simp only [add_comm _ (n : ℝ), f.commute_nat_add n]
theorem commute_sub_nat (n : ℕ) : Function.Commute f (· - n) := by
simpa only [sub_eq_add_neg] using
(f.commute_add_nat n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv
theorem commute_add_int : ∀ n : ℤ, Function.Commute f (· + n)
| (n : ℕ) => f.commute_add_nat n
| -[n+1] => by simpa [sub_eq_add_neg] using f.commute_sub_nat (n + 1)
theorem commute_int_add (n : ℤ) : Function.Commute f (n + ·) := by
simpa only [add_comm _ (n : ℝ)] using f.commute_add_int n
theorem commute_sub_int (n : ℤ) : Function.Commute f (· - n) := by
simpa only [sub_eq_add_neg] using
(f.commute_add_int n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv
@[simp]
theorem map_int_add (m : ℤ) (x : ℝ) : f (m + x) = m + f x :=
f.commute_int_add m x
@[simp]
theorem map_add_int (x : ℝ) (m : ℤ) : f (x + m) = f x + m :=
f.commute_add_int m x
@[simp]
theorem map_sub_int (x : ℝ) (n : ℤ) : f (x - n) = f x - n :=
f.commute_sub_int n x
@[simp]
theorem map_add_nat (x : ℝ) (n : ℕ) : f (x + n) = f x + n :=
f.map_add_int x n
@[simp]
theorem map_nat_add (n : ℕ) (x : ℝ) : f (n + x) = n + f x :=
f.map_int_add n x
@[simp]
theorem map_sub_nat (x : ℝ) (n : ℕ) : f (x - n) = f x - n :=
f.map_sub_int x n
theorem map_int_of_map_zero (n : ℤ) : f n = f 0 + n := by rw [← f.map_add_int, zero_add]
@[simp]
theorem map_fract_sub_fract_eq (x : ℝ) : f (fract x) - fract x = f x - x := by
rw [Int.fract, f.map_sub_int, sub_sub_sub_cancel_right]
/-!
### Pointwise order on circle maps
-/
/-- Monotone circle maps form a lattice with respect to the pointwise order -/
noncomputable instance : Lattice CircleDeg1Lift where
sup f g :=
{ toFun := fun x => max (f x) (g x)
monotone' := fun _ _ h => max_le_max (f.mono h) (g.mono h)
-- TODO: generalize to `Monotone.max`
map_add_one' := fun x => by simp [max_add_add_right] }
le f g := ∀ x, f x ≤ g x
le_refl f x := le_refl (f x)
le_trans _ _ _ h₁₂ h₂₃ x := le_trans (h₁₂ x) (h₂₃ x)
le_antisymm _ _ h₁₂ h₂₁ := ext fun x => le_antisymm (h₁₂ x) (h₂₁ x)
le_sup_left f g x := le_max_left (f x) (g x)
le_sup_right f g x := le_max_right (f x) (g x)
sup_le _ _ _ h₁ h₂ x := max_le (h₁ x) (h₂ x)
inf f g :=
{ toFun := fun x => min (f x) (g x)
monotone' := fun _ _ h => min_le_min (f.mono h) (g.mono h)
map_add_one' := fun x => by simp [min_add_add_right] }
inf_le_left f g x := min_le_left (f x) (g x)
inf_le_right f g x := min_le_right (f x) (g x)
le_inf _ _ _ h₂ h₃ x := le_min (h₂ x) (h₃ x)
@[simp]
theorem sup_apply (x : ℝ) : (f ⊔ g) x = max (f x) (g x) :=
rfl
@[simp]
theorem inf_apply (x : ℝ) : (f ⊓ g) x = min (f x) (g x) :=
rfl
theorem iterate_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f^[n] := fun f _ h =>
f.monotone.iterate_le_of_le h _
theorem iterate_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f^[n] ≤ g^[n] :=
iterate_monotone n h
theorem pow_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f ^ n ≤ g ^ n := fun x => by
simp only [coe_pow, iterate_mono h n x]
theorem pow_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f ^ n := fun _ _ h => pow_mono h n
/-!
### Estimates on `(f * g) 0`
We prove the estimates `f 0 + ⌊g 0⌋ ≤ f (g 0) ≤ f 0 + ⌈g 0⌉` and some corollaries with added/removed
floors and ceils.
We also prove that for two semiconjugate maps `g₁`, `g₂`, the distance between `g₁ 0` and `g₂ 0`
is less than two.
-/
theorem map_le_of_map_zero (x : ℝ) : f x ≤ f 0 + ⌈x⌉ :=
calc
f x ≤ f ⌈x⌉ := f.monotone <| le_ceil _
_ = f 0 + ⌈x⌉ := f.map_int_of_map_zero _
theorem map_map_zero_le : f (g 0) ≤ f 0 + ⌈g 0⌉ :=
f.map_le_of_map_zero (g 0)
theorem floor_map_map_zero_le : ⌊f (g 0)⌋ ≤ ⌊f 0⌋ + ⌈g 0⌉ :=
calc
⌊f (g 0)⌋ ≤ ⌊f 0 + ⌈g 0⌉⌋ := floor_mono <| f.map_map_zero_le g
_ = ⌊f 0⌋ + ⌈g 0⌉ := floor_add_intCast _ _
theorem ceil_map_map_zero_le : ⌈f (g 0)⌉ ≤ ⌈f 0⌉ + ⌈g 0⌉ :=
calc
⌈f (g 0)⌉ ≤ ⌈f 0 + ⌈g 0⌉⌉ := ceil_mono <| f.map_map_zero_le g
_ = ⌈f 0⌉ + ⌈g 0⌉ := ceil_add_intCast _ _
theorem map_map_zero_lt : f (g 0) < f 0 + g 0 + 1 :=
calc
f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_map_zero_le g
_ < f 0 + (g 0 + 1) := add_lt_add_left (ceil_lt_add_one _) _
_ = f 0 + g 0 + 1 := (add_assoc _ _ _).symm
theorem le_map_of_map_zero (x : ℝ) : f 0 + ⌊x⌋ ≤ f x :=
calc
f 0 + ⌊x⌋ = f ⌊x⌋ := (f.map_int_of_map_zero _).symm
_ ≤ f x := f.monotone <| floor_le _
theorem le_map_map_zero : f 0 + ⌊g 0⌋ ≤ f (g 0) :=
f.le_map_of_map_zero (g 0)
theorem le_floor_map_map_zero : ⌊f 0⌋ + ⌊g 0⌋ ≤ ⌊f (g 0)⌋ :=
calc
⌊f 0⌋ + ⌊g 0⌋ = ⌊f 0 + ⌊g 0⌋⌋ := (floor_add_intCast _ _).symm
_ ≤ ⌊f (g 0)⌋ := floor_mono <| f.le_map_map_zero g
theorem le_ceil_map_map_zero : ⌈f 0⌉ + ⌊g 0⌋ ≤ ⌈(f * g) 0⌉ :=
calc
⌈f 0⌉ + ⌊g 0⌋ = ⌈f 0 + ⌊g 0⌋⌉ := (ceil_add_intCast _ _).symm
_ ≤ ⌈f (g 0)⌉ := ceil_mono <| f.le_map_map_zero g
theorem lt_map_map_zero : f 0 + g 0 - 1 < f (g 0) :=
calc
f 0 + g 0 - 1 = f 0 + (g 0 - 1) := add_sub_assoc _ _ _
_ < f 0 + ⌊g 0⌋ := add_lt_add_left (sub_one_lt_floor _) _
_ ≤ f (g 0) := f.le_map_map_zero g
theorem dist_map_map_zero_lt : dist (f 0 + g 0) (f (g 0)) < 1 := by
rw [dist_comm, Real.dist_eq, abs_lt, lt_sub_iff_add_lt', sub_lt_iff_lt_add', ← sub_eq_add_neg]
exact ⟨f.lt_map_map_zero g, f.map_map_zero_lt g⟩
theorem dist_map_zero_lt_of_semiconj {f g₁ g₂ : CircleDeg1Lift} (h : Function.Semiconj f g₁ g₂) :
dist (g₁ 0) (g₂ 0) < 2 :=
calc
dist (g₁ 0) (g₂ 0) ≤ dist (g₁ 0) (f (g₁ 0) - f 0) + dist _ (g₂ 0) := dist_triangle _ _ _
_ = dist (f 0 + g₁ 0) (f (g₁ 0)) + dist (g₂ 0 + f 0) (g₂ (f 0)) := by
simp only [h.eq, Real.dist_eq, sub_sub, add_comm (f 0), sub_sub_eq_add_sub,
abs_sub_comm (g₂ (f 0))]
_ < 1 + 1 := add_lt_add (f.dist_map_map_zero_lt g₁) (g₂.dist_map_map_zero_lt f)
_ = 2 := one_add_one_eq_two
theorem dist_map_zero_lt_of_semiconjBy {f g₁ g₂ : CircleDeg1Lift} (h : SemiconjBy f g₁ g₂) :
dist (g₁ 0) (g₂ 0) < 2 :=
dist_map_zero_lt_of_semiconj <| semiconjBy_iff_semiconj.1 h
/-!
### Limits at infinities and continuity
-/
protected theorem tendsto_atBot : Tendsto f atBot atBot :=
tendsto_atBot_mono f.map_le_of_map_zero <| tendsto_atBot_add_const_left _ _ <|
(tendsto_atBot_mono fun x => (ceil_lt_add_one x).le) <|
tendsto_atBot_add_const_right _ _ tendsto_id
protected theorem tendsto_atTop : Tendsto f atTop atTop :=
tendsto_atTop_mono f.le_map_of_map_zero <| tendsto_atTop_add_const_left _ _ <|
(tendsto_atTop_mono fun x => (sub_one_lt_floor x).le) <| by
simpa [sub_eq_add_neg] using tendsto_atTop_add_const_right _ _ tendsto_id
theorem continuous_iff_surjective : Continuous f ↔ Function.Surjective f :=
⟨fun h => h.surjective f.tendsto_atTop f.tendsto_atBot, f.monotone.continuous_of_surjective⟩
/-!
### Estimates on `(f^n) x`
If we know that `f x` is `≤`/`<`/`≥`/`>`/`=` to `x + m`, then we have a similar estimate on
`f^[n] x` and `x + n * m`.
For `≤`, `≥`, and `=` we formulate both `of` (implication) and `iff` versions because implications
work for `n = 0`. For `<` and `>` we formulate only `iff` versions.
-/
theorem iterate_le_of_map_le_add_int {x : ℝ} {m : ℤ} (h : f x ≤ x + m) (n : ℕ) :
f^[n] x ≤ x + n * m := by
simpa only [nsmul_eq_mul, add_right_iterate] using
(f.commute_add_int m).iterate_le_of_map_le f.monotone (monotone_id.add_const (m : ℝ)) h n
theorem le_iterate_of_add_int_le_map {x : ℝ} {m : ℤ} (h : x + m ≤ f x) (n : ℕ) :
x + n * m ≤ f^[n] x := by
simpa only [nsmul_eq_mul, add_right_iterate] using
(f.commute_add_int m).symm.iterate_le_of_map_le (monotone_id.add_const (m : ℝ)) f.monotone h n
theorem iterate_eq_of_map_eq_add_int {x : ℝ} {m : ℤ} (h : f x = x + m) (n : ℕ) :
f^[n] x = x + n * m := by
simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_eq_of_map_eq n h
theorem iterate_pos_le_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) :
f^[n] x ≤ x + n * m ↔ f x ≤ x + m := by
simpa only [nsmul_eq_mul, add_right_iterate] using
(f.commute_add_int m).iterate_pos_le_iff_map_le f.monotone (strictMono_id.add_const (m : ℝ)) hn
theorem iterate_pos_lt_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) :
f^[n] x < x + n * m ↔ f x < x + m := by
simpa only [nsmul_eq_mul, add_right_iterate] using
(f.commute_add_int m).iterate_pos_lt_iff_map_lt f.monotone (strictMono_id.add_const (m : ℝ)) hn
| Mathlib/Dynamics/Circle/RotationNumber/TranslationNumber.lean | 518 | 520 | theorem iterate_pos_eq_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) :
f^[n] x = x + n * m ↔ f x = x + m := by | simpa only [nsmul_eq_mul, add_right_iterate] using |
/-
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, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Complex
/-!
# The `arctan` function.
Inequalities, identities and `Real.tan` as a `PartialHomeomorph` between `(-(π / 2), π / 2)`
and the whole line.
The result of `arctan x + arctan y` is given by `arctan_add`, `arctan_add_eq_add_pi` or
`arctan_add_eq_sub_pi` depending on whether `x * y < 1` and `0 < x`. As an application of
`arctan_add` we give four Machin-like formulas (linear combinations of arctangents equal to
`π / 4 = arctan 1`), including John Machin's original one at
`four_mul_arctan_inv_5_sub_arctan_inv_239`.
-/
noncomputable section
namespace Real
open Set Filter
open scoped Topology Real
theorem tan_add {x y : ℝ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) ∨
(∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y = (2 * l + 1) * π / 2) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := by
simpa only [← Complex.ofReal_inj, Complex.ofReal_sub, Complex.ofReal_add, Complex.ofReal_div,
Complex.ofReal_mul, Complex.ofReal_tan] using
@Complex.tan_add (x : ℂ) (y : ℂ) (by convert h <;> norm_cast)
theorem tan_add' {x y : ℝ}
(h : (∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
tan_add (Or.inl h)
theorem tan_two_mul {x : ℝ} : tan (2 * x) = 2 * tan x / (1 - tan x ^ 2) := by
have := @Complex.tan_two_mul x
norm_cast at *
theorem tan_int_mul_pi_div_two (n : ℤ) : tan (n * π / 2) = 0 :=
tan_eq_zero_iff.mpr (by use n)
theorem continuousOn_tan : ContinuousOn tan {x | cos x ≠ 0} := by
suffices ContinuousOn (fun x => sin x / cos x) {x | cos x ≠ 0} by
have h_eq : (fun x => sin x / cos x) = tan := by ext1 x; rw [tan_eq_sin_div_cos]
rwa [h_eq] at this
exact continuousOn_sin.div continuousOn_cos fun x => id
@[continuity]
theorem continuous_tan : Continuous fun x : {x | cos x ≠ 0} => tan x :=
continuousOn_iff_continuous_restrict.1 continuousOn_tan
theorem continuousOn_tan_Ioo : ContinuousOn tan (Ioo (-(π / 2)) (π / 2)) := by
refine ContinuousOn.mono continuousOn_tan fun x => ?_
simp only [and_imp, mem_Ioo, mem_setOf_eq, Ne]
rw [cos_eq_zero_iff]
rintro hx_gt hx_lt ⟨r, hxr_eq⟩
rcases le_or_lt 0 r with h | h
· rw [lt_iff_not_ge] at hx_lt
refine hx_lt ?_
rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, mul_le_mul_right (half_pos pi_pos)]
simp [h]
· rw [lt_iff_not_ge] at hx_gt
refine hx_gt ?_
rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, neg_mul_eq_neg_mul,
mul_le_mul_right (half_pos pi_pos)]
have hr_le : r ≤ -1 := by rwa [Int.lt_iff_add_one_le, ← le_neg_iff_add_nonpos_right] at h
rw [← le_sub_iff_add_le, mul_comm, ← le_div_iff₀]
· norm_num
rw [← Int.cast_one, ← Int.cast_neg]; norm_cast
· exact zero_lt_two
theorem surjOn_tan : SurjOn tan (Ioo (-(π / 2)) (π / 2)) univ :=
have := neg_lt_self pi_div_two_pos
continuousOn_tan_Ioo.surjOn_of_tendsto (nonempty_Ioo.2 this)
(by rw [tendsto_comp_coe_Ioo_atBot this]; exact tendsto_tan_neg_pi_div_two)
(by rw [tendsto_comp_coe_Ioo_atTop this]; exact tendsto_tan_pi_div_two)
theorem tan_surjective : Function.Surjective tan := fun _ => surjOn_tan.subset_range trivial
theorem image_tan_Ioo : tan '' Ioo (-(π / 2)) (π / 2) = univ :=
univ_subset_iff.1 surjOn_tan
/-- `Real.tan` as an `OrderIso` between `(-(π / 2), π / 2)` and `ℝ`. -/
def tanOrderIso : Ioo (-(π / 2)) (π / 2) ≃o ℝ :=
(strictMonoOn_tan.orderIso _ _).trans <|
(OrderIso.setCongr _ _ image_tan_Ioo).trans OrderIso.Set.univ
/-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and
`arctan x < π / 2` -/
@[pp_nodot]
noncomputable def arctan (x : ℝ) : ℝ :=
tanOrderIso.symm x
@[simp]
theorem tan_arctan (x : ℝ) : tan (arctan x) = x :=
tanOrderIso.apply_symm_apply x
theorem arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(π / 2)) (π / 2) :=
Subtype.coe_prop _
@[simp]
theorem range_arctan : range arctan = Ioo (-(π / 2)) (π / 2) :=
((EquivLike.surjective _).range_comp _).trans Subtype.range_coe
theorem arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x :=
Subtype.ext_iff.1 <| tanOrderIso.symm_apply_apply ⟨x, hx₁, hx₂⟩
theorem cos_arctan_pos (x : ℝ) : 0 < cos (arctan x) :=
cos_pos_of_mem_Ioo <| arctan_mem_Ioo x
theorem cos_sq_arctan (x : ℝ) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) := by
rw_mod_cast [one_div, ← inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan]
theorem sin_arctan (x : ℝ) : sin (arctan x) = x / √(1 + x ^ 2) := by
rw_mod_cast [← tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
theorem cos_arctan (x : ℝ) : cos (arctan x) = 1 / √(1 + x ^ 2) := by
rw_mod_cast [one_div, ← inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
theorem arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 :=
(arctan_mem_Ioo x).2
theorem neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x :=
(arctan_mem_Ioo x).1
theorem arctan_eq_arcsin (x : ℝ) : arctan x = arcsin (x / √(1 + x ^ 2)) :=
Eq.symm <| arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo <| arctan_mem_Ioo x)
theorem arcsin_eq_arctan {x : ℝ} (h : x ∈ Ioo (-(1 : ℝ)) 1) :
arcsin x = arctan (x / √(1 - x ^ 2)) := by
rw_mod_cast [arctan_eq_arcsin, div_pow, sq_sqrt, one_add_div, div_div, ← sqrt_mul,
mul_div_cancel₀, sub_add_cancel, sqrt_one, div_one] <;> simp at h <;> nlinarith [h.1, h.2]
@[simp]
theorem arctan_zero : arctan 0 = 0 := by simp [arctan_eq_arcsin]
@[mono]
theorem arctan_strictMono : StrictMono arctan := tanOrderIso.symm.strictMono
@[gcongr]
lemma arctan_lt_arctan {x y : ℝ} (hxy : x < y) : arctan x < arctan y := arctan_strictMono hxy
@[gcongr]
lemma arctan_le_arctan {x y : ℝ} (hxy : x ≤ y) : arctan x ≤ arctan y :=
arctan_strictMono.monotone hxy
theorem arctan_injective : arctan.Injective := arctan_strictMono.injective
@[simp]
theorem arctan_eq_zero_iff {x : ℝ} : arctan x = 0 ↔ x = 0 :=
.trans (by rw [arctan_zero]) arctan_injective.eq_iff
theorem tendsto_arctan_atTop : Tendsto arctan atTop (𝓝[<] (π / 2)) :=
tendsto_Ioo_atTop.mp tanOrderIso.symm.tendsto_atTop
theorem tendsto_arctan_atBot : Tendsto arctan atBot (𝓝[>] (-(π / 2))) :=
tendsto_Ioo_atBot.mp tanOrderIso.symm.tendsto_atBot
theorem arctan_eq_of_tan_eq {x y : ℝ} (h : tan x = y) (hx : x ∈ Ioo (-(π / 2)) (π / 2)) :
arctan y = x :=
injOn_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h])
@[simp]
theorem arctan_one : arctan 1 = π / 4 :=
arctan_eq_of_tan_eq tan_pi_div_four <| by constructor <;> linarith [pi_pos]
@[simp]
theorem arctan_neg (x : ℝ) : arctan (-x) = -arctan x := by simp [arctan_eq_arcsin, neg_div]
theorem arctan_eq_arccos {x : ℝ} (h : 0 ≤ x) : arctan x = arccos (√(1 + x ^ 2))⁻¹ := by
rw [arctan_eq_arcsin, arccos_eq_arcsin]; swap; · exact inv_nonneg.2 (sqrt_nonneg _)
congr 1
rw_mod_cast [← sqrt_inv, sq_sqrt, ← one_div, one_sub_div, add_sub_cancel_left, sqrt_div,
sqrt_sq h]
all_goals positivity
-- The junk values for `arccos` and `sqrt` make this true even for `1 < x`.
theorem arccos_eq_arctan {x : ℝ} (h : 0 < x) : arccos x = arctan (√(1 - x ^ 2) / x) := by
rw [arccos, eq_comm]
refine arctan_eq_of_tan_eq ?_ ⟨?_, ?_⟩
· rw_mod_cast [tan_pi_div_two_sub, tan_arcsin, inv_div]
· linarith only [arcsin_le_pi_div_two x, pi_pos]
· linarith only [arcsin_pos.2 h]
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Arctan.lean | 193 | 194 | theorem arctan_inv_of_pos {x : ℝ} (h : 0 < x) : arctan x⁻¹ = π / 2 - arctan x := by | rw [← arctan_tan (x := _ - _), tan_pi_div_two_sub, tan_arctan] |
/-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.MeasureTheory.Group.GeometryOfNumbers
import Mathlib.MeasureTheory.Measure.Lebesgue.VolumeOfBalls
import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.Basic
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
/-!
# Convex Bodies
The file contains the definitions of several convex bodies lying in the mixed space `ℝ^r₁ × ℂ^r₂`
associated to a number field of signature `K` and proves several existence theorems by applying
*Minkowski Convex Body Theorem* to those.
## Main definitions and results
* `NumberField.mixedEmbedding.convexBodyLT`: The set of points `x` such that `‖x w‖ < f w` for all
infinite places `w` with `f : InfinitePlace K → ℝ≥0`.
* `NumberField.mixedEmbedding.convexBodySum`: The set of points `x` such that
`∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B`
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_lt`: Let `I` be a fractional ideal of `K`.
Assume that `f` is such that `minkowskiBound K I < volume (convexBodyLT K f)`, then there exists a
nonzero algebraic number `a` in `I` such that `w a < f w` for all infinite places `w`.
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_of_norm_le`: Let `I` be a fractional ideal
of `K`. Assume that `B` is such that `minkowskiBound K I < volume (convexBodySum K B)` (see
`convexBodySum_volume` for the computation of this volume), then there exists a nonzero algebraic
number `a` in `I` such that `|Norm a| < (B / d) ^ d` where `d` is the degree of `K`.
## Tags
number field, infinite places
-/
variable (K : Type*) [Field K]
namespace NumberField.mixedEmbedding
open NumberField NumberField.InfinitePlace Module
section convexBodyLT
open Metric NNReal
variable (f : InfinitePlace K → ℝ≥0)
/-- The convex body defined by `f`: the set of points `x : E` such that `‖x w‖ < f w` for all
infinite places `w`. -/
abbrev convexBodyLT : Set (mixedSpace K) :=
(Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } => ball 0 (f w))) ×ˢ
(Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } => ball 0 (f w)))
theorem convexBodyLT_mem {x : K} :
mixedEmbedding K x ∈ (convexBodyLT K f) ↔ ∀ w : InfinitePlace K, w x < f w := by
simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ,
forall_true_left, mem_ball_zero_iff, Pi.ringHom_apply, ← Complex.norm_real,
embedding_of_isReal_apply, Subtype.forall, ← forall₂_or_left, ← not_isReal_iff_isComplex, em,
forall_true_left, norm_embedding_eq]
theorem convexBodyLT_neg_mem (x : mixedSpace K) (hx : x ∈ (convexBodyLT K f)) :
-x ∈ (convexBodyLT K f) := by
simp only [Set.mem_prod, Prod.fst_neg, Set.mem_pi, Set.mem_univ, Pi.neg_apply,
mem_ball_zero_iff, norm_neg, Real.norm_eq_abs, forall_true_left, Subtype.forall,
Prod.snd_neg] at hx ⊢
exact hx
theorem convexBodyLT_convex : Convex ℝ (convexBodyLT K f) :=
Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => convex_ball _ _))
open Fintype MeasureTheory MeasureTheory.Measure ENNReal
variable [NumberField K]
/-- The fudge factor that appears in the formula for the volume of `convexBodyLT`. -/
noncomputable abbrev convexBodyLTFactor : ℝ≥0 :=
(2 : ℝ≥0) ^ nrRealPlaces K * NNReal.pi ^ nrComplexPlaces K
theorem convexBodyLTFactor_ne_zero : convexBodyLTFactor K ≠ 0 :=
mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero)
theorem one_le_convexBodyLTFactor : 1 ≤ convexBodyLTFactor K :=
one_le_mul (one_le_pow₀ one_le_two) (one_le_pow₀ (one_le_two.trans Real.two_le_pi))
open scoped Classical in
/-- The volume of `(ConvexBodyLt K f)` where `convexBodyLT K f` is the set of points `x`
such that `‖x w‖ < f w` for all infinite places `w`. -/
theorem convexBodyLT_volume :
volume (convexBodyLT K f) = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by
calc
_ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) *
∏ x : {w // InfinitePlace.IsComplex w}, ENNReal.ofReal (f x.val) ^ 2 * NNReal.pi := by
simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball, Complex.volume_ball]
_ = ((2 : ℝ≥0) ^ nrRealPlaces K
* (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val)))
* ((∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) *
NNReal.pi ^ nrComplexPlaces K) := by
simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const,
Finset.card_univ, ofReal_ofNat, ofReal_coe_nnreal, coe_ofNat]
_ = (convexBodyLTFactor K) * ((∏ x : {w // InfinitePlace.IsReal w}, .ofReal (f x.val)) *
(∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2)) := by
simp_rw [convexBodyLTFactor, coe_mul, ENNReal.coe_pow]
ring
_ = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by
simp_rw [prod_eq_prod_mul_prod, coe_mul, coe_finset_prod, mult_isReal, mult_isComplex,
pow_one, ENNReal.coe_pow, ofReal_coe_nnreal]
variable {f}
/-- This is a technical result: quite often, we want to impose conditions at all infinite places
but one and choose the value at the remaining place so that we can apply
`exists_ne_zero_mem_ringOfIntegers_lt`. -/
theorem adjust_f {w₁ : InfinitePlace K} (B : ℝ≥0) (hf : ∀ w, w ≠ w₁ → f w ≠ 0) :
∃ g : InfinitePlace K → ℝ≥0, (∀ w, w ≠ w₁ → g w = f w) ∧ ∏ w, (g w) ^ mult w = B := by
classical
let S := ∏ w ∈ Finset.univ.erase w₁, (f w) ^ mult w
refine ⟨Function.update f w₁ ((B * S⁻¹) ^ (mult w₁ : ℝ)⁻¹), ?_, ?_⟩
· exact fun w hw => Function.update_of_ne hw _ f
· rw [← Finset.mul_prod_erase Finset.univ _ (Finset.mem_univ w₁), Function.update_self,
Finset.prod_congr rfl fun w hw => by rw [Function.update_of_ne (Finset.ne_of_mem_erase hw)],
← NNReal.rpow_natCast, ← NNReal.rpow_mul, inv_mul_cancel₀, NNReal.rpow_one, mul_assoc,
inv_mul_cancel₀, mul_one]
· rw [Finset.prod_ne_zero_iff]
exact fun w hw => pow_ne_zero _ (hf w (Finset.ne_of_mem_erase hw))
· rw [mult]; split_ifs <;> norm_num
end convexBodyLT
section convexBodyLT'
open Metric ENNReal NNReal
variable (f : InfinitePlace K → ℝ≥0) (w₀ : {w : InfinitePlace K // IsComplex w})
open scoped Classical in
/-- A version of `convexBodyLT` with an additional condition at a fixed complex place. This is
needed to ensure the element constructed is not real, see for example
`exists_primitive_element_lt_of_isComplex`.
-/
abbrev convexBodyLT' : Set (mixedSpace K) :=
(Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } ↦ ball 0 (f w))) ×ˢ
(Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } ↦
if w = w₀ then {x | |x.re| < 1 ∧ |x.im| < (f w : ℝ) ^ 2} else ball 0 (f w)))
theorem convexBodyLT'_mem {x : K} :
mixedEmbedding K x ∈ convexBodyLT' K f w₀ ↔
(∀ w : InfinitePlace K, w ≠ w₀ → w x < f w) ∧
|(w₀.val.embedding x).re| < 1 ∧ |(w₀.val.embedding x).im| < (f w₀ : ℝ) ^ 2 := by
simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ,
forall_true_left, Pi.ringHom_apply, mem_ball_zero_iff, ← Complex.norm_real,
embedding_of_isReal_apply, norm_embedding_eq, Subtype.forall]
refine ⟨fun ⟨h₁, h₂⟩ ↦ ⟨fun w h_ne ↦ ?_, ?_⟩, fun ⟨h₁, h₂⟩ ↦ ⟨fun w hw ↦ ?_, fun w hw ↦ ?_⟩⟩
· by_cases hw : IsReal w
· exact norm_embedding_eq w _ ▸ h₁ w hw
· specialize h₂ w (not_isReal_iff_isComplex.mp hw)
rw [apply_ite (w.embedding x ∈ ·), Set.mem_setOf_eq,
mem_ball_zero_iff, norm_embedding_eq] at h₂
rwa [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)] at h₂
· simpa [if_true] using h₂ w₀.val w₀.prop
· exact h₁ w (ne_of_isReal_isComplex hw w₀.prop)
· by_cases h_ne : w = w₀
· simpa [h_ne]
· rw [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)]
rw [mem_ball_zero_iff, norm_embedding_eq]
exact h₁ w h_ne
theorem convexBodyLT'_neg_mem (x : mixedSpace K) (hx : x ∈ convexBodyLT' K f w₀) :
-x ∈ convexBodyLT' K f w₀ := by
simp only [Set.mem_prod, Set.mem_pi, Set.mem_univ, mem_ball, dist_zero_right, Real.norm_eq_abs,
true_implies, Subtype.forall, Prod.fst_neg, Pi.neg_apply, norm_neg, Prod.snd_neg] at hx ⊢
convert hx using 3
split_ifs <;> simp
theorem convexBodyLT'_convex : Convex ℝ (convexBodyLT' K f w₀) := by
refine Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => ?_))
split_ifs
· simp_rw [abs_lt]
refine Convex.inter ((convex_halfSpace_re_gt _).inter (convex_halfSpace_re_lt _))
((convex_halfSpace_im_gt _).inter (convex_halfSpace_im_lt _))
· exact convex_ball _ _
open MeasureTheory MeasureTheory.Measure
variable [NumberField K]
/-- The fudge factor that appears in the formula for the volume of `convexBodyLT'`. -/
noncomputable abbrev convexBodyLT'Factor : ℝ≥0 :=
(2 : ℝ≥0) ^ (nrRealPlaces K + 2) * NNReal.pi ^ (nrComplexPlaces K - 1)
theorem convexBodyLT'Factor_ne_zero : convexBodyLT'Factor K ≠ 0 :=
mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero)
theorem one_le_convexBodyLT'Factor : 1 ≤ convexBodyLT'Factor K :=
one_le_mul (one_le_pow₀ one_le_two) (one_le_pow₀ (one_le_two.trans Real.two_le_pi))
open scoped Classical in
theorem convexBodyLT'_volume :
volume (convexBodyLT' K f w₀) = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by
have vol_box : ∀ B : ℝ≥0, volume {x : ℂ | |x.re| < 1 ∧ |x.im| < B^2} = 4*B^2 := by
intro B
rw [← (Complex.volume_preserving_equiv_real_prod.symm).measure_preimage]
· simp_rw [Set.preimage_setOf_eq, Complex.measurableEquivRealProd_symm_apply]
rw [show {a : ℝ × ℝ | |a.1| < 1 ∧ |a.2| < B ^ 2} =
Set.Ioo (-1 : ℝ) (1 : ℝ) ×ˢ Set.Ioo (- (B : ℝ) ^ 2) ((B : ℝ) ^ 2) by
ext; simp_rw [Set.mem_setOf_eq, Set.mem_prod, Set.mem_Ioo, abs_lt]]
simp_rw [volume_eq_prod, prod_prod, Real.volume_Ioo, sub_neg_eq_add, one_add_one_eq_two,
← two_mul, ofReal_mul zero_le_two, ofReal_pow (coe_nonneg B), ofReal_ofNat,
ofReal_coe_nnreal, ← mul_assoc, show (2 : ℝ≥0∞) * 2 = 4 by norm_num]
· refine (MeasurableSet.inter ?_ ?_).nullMeasurableSet
· exact measurableSet_lt (measurable_norm.comp Complex.measurable_re) measurable_const
· exact measurableSet_lt (measurable_norm.comp Complex.measurable_im) measurable_const
calc
_ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) *
((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2 * pi) *
(4 * (f w₀) ^ 2)) := by
simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball]
rw [← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀)]
congr 2
· refine Finset.prod_congr rfl (fun w' hw' ↦ ?_)
rw [if_neg (Finset.ne_of_mem_erase hw'), Complex.volume_ball]
· simpa only [ite_true] using vol_box (f w₀)
_ = ((2 : ℝ≥0) ^ nrRealPlaces K *
(∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))) *
((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2) *
↑pi ^ (nrComplexPlaces K - 1) * (4 * (f w₀) ^ 2)) := by
simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const,
Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, ofReal_ofNat,
ofReal_coe_nnreal, coe_ofNat]
_ = convexBodyLT'Factor K * (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))
* (∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) := by
rw [show (4 : ℝ≥0∞) = (2 : ℝ≥0) ^ 2 by norm_num, convexBodyLT'Factor, pow_add,
← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀), ofReal_coe_nnreal]
simp_rw [coe_mul, ENNReal.coe_pow]
ring
_ = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by
simp_rw [prod_eq_prod_mul_prod, coe_mul, coe_finset_prod, mult_isReal, mult_isComplex,
pow_one, ENNReal.coe_pow, ofReal_coe_nnreal, mul_assoc]
end convexBodyLT'
section convexBodySum
open ENNReal MeasureTheory Fintype
open scoped Real NNReal
variable [NumberField K] (B : ℝ)
variable {K}
/-- The function that sends `x : mixedSpace K` to `∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖`. It defines a
norm and it used to define `convexBodySum`. -/
noncomputable abbrev convexBodySumFun (x : mixedSpace K) : ℝ := ∑ w, mult w * normAtPlace w x
theorem convexBodySumFun_apply (x : mixedSpace K) :
convexBodySumFun x = ∑ w, mult w * normAtPlace w x := rfl
open scoped Classical in
theorem convexBodySumFun_apply' (x : mixedSpace K) :
convexBodySumFun x = ∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖ := by
simp_rw [convexBodySumFun_apply, sum_eq_sum_add_sum, mult_isReal, mult_isComplex,
Nat.cast_one, one_mul, Nat.cast_ofNat, normAtPlace_apply_of_isReal (Subtype.prop _),
normAtPlace_apply_of_isComplex (Subtype.prop _), Finset.mul_sum]
theorem convexBodySumFun_nonneg (x : mixedSpace K) :
0 ≤ convexBodySumFun x :=
Finset.sum_nonneg (fun _ _ => mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _))
theorem convexBodySumFun_neg (x : mixedSpace K) :
convexBodySumFun (- x) = convexBodySumFun x := by
simp_rw [convexBodySumFun, normAtPlace_neg]
theorem convexBodySumFun_add_le (x y : mixedSpace K) :
convexBodySumFun (x + y) ≤ convexBodySumFun x + convexBodySumFun y := by
simp_rw [convexBodySumFun, ← Finset.sum_add_distrib, ← mul_add]
exact Finset.sum_le_sum
fun _ _ ↦ mul_le_mul_of_nonneg_left (normAtPlace_add_le _ x y) (Nat.cast_pos.mpr mult_pos).le
theorem convexBodySumFun_smul (c : ℝ) (x : mixedSpace K) :
convexBodySumFun (c • x) = |c| * convexBodySumFun x := by
simp_rw [convexBodySumFun, normAtPlace_smul, ← mul_assoc, mul_comm, Finset.mul_sum, mul_assoc]
| Mathlib/NumberTheory/NumberField/CanonicalEmbedding/ConvexBody.lean | 286 | 296 | theorem convexBodySumFun_eq_zero_iff (x : mixedSpace K) :
convexBodySumFun x = 0 ↔ x = 0 := by | rw [← forall_normAtPlace_eq_zero_iff, convexBodySumFun, Finset.sum_eq_zero_iff_of_nonneg
fun _ _ ↦ mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _)]
conv =>
enter [1, w, hw]
rw [mul_left_mem_nonZeroDivisors_eq_zero_iff
(mem_nonZeroDivisors_iff_ne_zero.mpr <| Nat.cast_ne_zero.mpr mult_ne_zero)]
simp_rw [Finset.mem_univ, true_implies]
open scoped Classical in |
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol
/-!
# A `norm_num` extension for Jacobi and Legendre symbols
We extend the `norm_num` tactic so that it can be used to provably compute
the value of the Jacobi symbol `J(a | b)` or the Legendre symbol `legendreSym p a` when
the arguments are numerals.
## Implementation notes
We use the Law of Quadratic Reciprocity for the Jacobi symbol to compute the value of `J(a | b)`
efficiently, roughly comparable in effort with the euclidean algorithm for the computation
of the gcd of `a` and `b`. More precisely, the computation is done in the following steps.
* Use `J(a | 0) = 1` (an artifact of the definition) and `J(a | 1) = 1` to deal
with corner cases.
* Use `J(a | b) = J(a % b | b)` to reduce to the case that `a` is a natural number.
We define a version of the Jacobi symbol restricted to natural numbers for use in
the following steps; see `NormNum.jacobiSymNat`. (But we'll continue to write `J(a | b)`
in this description.)
* Remove powers of two from `b`. This is done via `J(2a | 2b) = 0` and
`J(2a+1 | 2b) = J(2a+1 | b)` (another artifact of the definition).
* Now `0 ≤ a < b` and `b` is odd. If `b = 1`, then the value is `1`.
If `a = 0` (and `b > 1`), then the value is `0`. Otherwise, we remove powers of two from `a`
via `J(4a | b) = J(a | b)` and `J(2a | b) = ±J(a | b)`, where the sign is determined
by the residue class of `b` mod 8, to reduce to `a` odd.
* Once `a` is odd, we use Quadratic Reciprocity (QR) in the form
`J(a | b) = ±J(b % a | a)`, where the sign is determined by the residue classes
of `a` and `b` mod 4. We are then back in the previous case.
We provide customized versions of these results for the various reduction steps,
where we encode the residue classes mod 2, mod 4, or mod 8 by using hypotheses like
`a % n = b`. In this way, the only divisions we have to compute and prove
are the ones occurring in the use of QR above.
-/
section Lemmas
namespace Mathlib.Meta.NormNum
/-- The Jacobi symbol restricted to natural numbers in both arguments. -/
def jacobiSymNat (a b : ℕ) : ℤ :=
jacobiSym a b
/-!
### API Lemmas
We repeat part of the API for `jacobiSym` with `NormNum.jacobiSymNat` and without implicit
arguments, in a form that is suitable for constructing proofs in `norm_num`.
-/
/-- Base cases: `b = 0`, `b = 1`, `a = 0`, `a = 1`. -/
theorem jacobiSymNat.zero_right (a : ℕ) : jacobiSymNat a 0 = 1 := by
rw [jacobiSymNat, jacobiSym.zero_right]
theorem jacobiSymNat.one_right (a : ℕ) : jacobiSymNat a 1 = 1 := by
rw [jacobiSymNat, jacobiSym.one_right]
theorem jacobiSymNat.zero_left (b : ℕ) (hb : Nat.beq (b / 2) 0 = false) : jacobiSymNat 0 b = 0 := by
rw [jacobiSymNat, Nat.cast_zero, jacobiSym.zero_left ?_]
calc
1 < 2 * 1 := by decide
_ ≤ 2 * (b / 2) :=
Nat.mul_le_mul_left _ (Nat.succ_le.mpr (Nat.pos_of_ne_zero (Nat.ne_of_beq_eq_false hb)))
_ ≤ b := Nat.mul_div_le b 2
theorem jacobiSymNat.one_left (b : ℕ) : jacobiSymNat 1 b = 1 := by
rw [jacobiSymNat, Nat.cast_one, jacobiSym.one_left]
/-- Turn a Legendre symbol into a Jacobi symbol. -/
theorem LegendreSym.to_jacobiSym (p : ℕ) (pp : Fact p.Prime) (a r : ℤ)
(hr : IsInt (jacobiSym a p) r) : IsInt (legendreSym p a) r := by
rwa [@jacobiSym.legendreSym.to_jacobiSym p pp a]
/-- The value depends only on the residue class of `a` mod `b`. -/
theorem JacobiSym.mod_left (a : ℤ) (b ab' : ℕ) (ab r b' : ℤ) (hb' : (b : ℤ) = b')
(hab : a % b' = ab) (h : (ab' : ℤ) = ab) (hr : jacobiSymNat ab' b = r) : jacobiSym a b = r := by
rw [← hr, jacobiSymNat, jacobiSym.mod_left, hb', hab, ← h]
theorem jacobiSymNat.mod_left (a b ab : ℕ) (r : ℤ) (hab : a % b = ab) (hr : jacobiSymNat ab b = r) :
jacobiSymNat a b = r := by
rw [← hr, jacobiSymNat, jacobiSymNat, _root_.jacobiSym.mod_left a b, ← hab]; rfl
/-- The symbol vanishes when both entries are even (and `b / 2 ≠ 0`). -/
theorem jacobiSymNat.even_even (a b : ℕ) (hb₀ : Nat.beq (b / 2) 0 = false) (ha : a % 2 = 0)
(hb₁ : b % 2 = 0) : jacobiSymNat a b = 0 := by
refine jacobiSym.eq_zero_iff.mpr
⟨ne_of_gt ((Nat.pos_of_ne_zero (Nat.ne_of_beq_eq_false hb₀)).trans_le (Nat.div_le_self b 2)),
fun hf => ?_⟩
have h : 2 ∣ a.gcd b := Nat.dvd_gcd (Nat.dvd_of_mod_eq_zero ha) (Nat.dvd_of_mod_eq_zero hb₁)
change 2 ∣ (a : ℤ).gcd b at h
rw [hf, ← even_iff_two_dvd] at h
exact Nat.not_even_one h
/-- When `a` is odd and `b` is even, we can replace `b` by `b / 2`. -/
theorem jacobiSymNat.odd_even (a b c : ℕ) (r : ℤ) (ha : a % 2 = 1) (hb : b % 2 = 0) (hc : b / 2 = c)
(hr : jacobiSymNat a c = r) : jacobiSymNat a b = r := by
have ha' : legendreSym 2 a = 1 := by
simp only [legendreSym.mod 2 a, Int.ofNat_mod_ofNat, ha]
decide
rcases eq_or_ne c 0 with (rfl | hc')
· rw [← hr, Nat.eq_zero_of_dvd_of_div_eq_zero (Nat.dvd_of_mod_eq_zero hb) hc]
· haveI : NeZero c := ⟨hc'⟩
-- for `jacobiSym.mul_right`
rwa [← Nat.mod_add_div b 2, hb, hc, Nat.zero_add, jacobiSymNat, jacobiSym.mul_right,
← jacobiSym.legendreSym.to_jacobiSym, ha', one_mul]
/-- If `a` is divisible by `4` and `b` is odd, then we can remove the factor `4` from `a`. -/
theorem jacobiSymNat.double_even (a b c : ℕ) (r : ℤ) (ha : a % 4 = 0) (hb : b % 2 = 1)
(hc : a / 4 = c) (hr : jacobiSymNat c b = r) : jacobiSymNat a b = r := by
simp only [jacobiSymNat, ← hr, ← hc, Int.natCast_ediv, Nat.cast_ofNat]
exact (jacobiSym.div_four_left (mod_cast ha) hb).symm
/-- If `a` is even and `b` is odd, then we can remove a factor `2` from `a`,
but we may have to change the sign, depending on `b % 8`.
We give one version for each of the four odd residue classes mod `8`. -/
theorem jacobiSymNat.even_odd₁ (a b c : ℕ) (r : ℤ) (ha : a % 2 = 0) (hb : b % 8 = 1)
(hc : a / 2 = c) (hr : jacobiSymNat c b = r) : jacobiSymNat a b = r := by
simp only [jacobiSymNat, ← hr, ← hc, Int.natCast_ediv, Nat.cast_ofNat]
rw [← jacobiSym.even_odd (mod_cast ha), if_neg (by simp [hb])]
rw [← Nat.mod_mod_of_dvd, hb]; norm_num
| Mathlib/Tactic/NormNum/LegendreSymbol.lean | 135 | 138 | theorem jacobiSymNat.even_odd₇ (a b c : ℕ) (r : ℤ) (ha : a % 2 = 0) (hb : b % 8 = 7)
(hc : a / 2 = c) (hr : jacobiSymNat c b = r) : jacobiSymNat a b = r := by | simp only [jacobiSymNat, ← hr, ← hc, Int.natCast_ediv, Nat.cast_ofNat]
rw [← jacobiSym.even_odd (mod_cast ha), if_neg (by simp [hb])] |
/-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import Mathlib.Analysis.NormedSpace.IndicatorFunction
import Mathlib.Data.Fintype.Order
import Mathlib.MeasureTheory.Function.AEEqFun
import Mathlib.MeasureTheory.Function.LpSeminorm.Defs
import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic
import Mathlib.MeasureTheory.Integral.Lebesgue.Countable
import Mathlib.MeasureTheory.Integral.Lebesgue.Sub
/-!
# Basic theorems about ℒp space
-/
noncomputable section
open TopologicalSpace MeasureTheory Filter
open scoped NNReal ENNReal Topology ComplexConjugate
variable {α ε ε' E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α}
[NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] [ENorm ε] [ENorm ε']
namespace MeasureTheory
section Lp
section Top
theorem MemLp.eLpNorm_lt_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) :
eLpNorm f p μ < ∞ :=
hfp.2
@[deprecated (since := "2025-02-21")]
alias Memℒp.eLpNorm_lt_top := MemLp.eLpNorm_lt_top
theorem MemLp.eLpNorm_ne_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) :
eLpNorm f p μ ≠ ∞ :=
ne_of_lt hfp.2
@[deprecated (since := "2025-02-21")]
alias Memℒp.eLpNorm_ne_top := MemLp.eLpNorm_ne_top
theorem lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top {f : α → ε} (hq0_lt : 0 < q)
(hfq : eLpNorm' f q μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ q ∂μ < ∞ := by
rw [lintegral_rpow_enorm_eq_rpow_eLpNorm' hq0_lt]
exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq)
@[deprecated (since := "2025-01-17")]
alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm'_lt_top' :=
lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top
theorem lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) (hfp : eLpNorm f p μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ p.toReal ∂μ < ∞ := by
apply lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top
· exact ENNReal.toReal_pos hp_ne_zero hp_ne_top
· simpa [eLpNorm_eq_eLpNorm' hp_ne_zero hp_ne_top] using hfp
@[deprecated (since := "2025-01-17")]
alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm_lt_top :=
lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top
theorem eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) : eLpNorm f p μ < ∞ ↔ ∫⁻ a, (‖f a‖ₑ) ^ p.toReal ∂μ < ∞ :=
⟨lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_ne_zero hp_ne_top, by
intro h
have hp' := ENNReal.toReal_pos hp_ne_zero hp_ne_top
have : 0 < 1 / p.toReal := div_pos zero_lt_one hp'
simpa [eLpNorm_eq_lintegral_rpow_enorm hp_ne_zero hp_ne_top] using
ENNReal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)⟩
@[deprecated (since := "2025-02-04")] alias
eLpNorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top := eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top
end Top
section Zero
@[simp]
theorem eLpNorm'_exponent_zero {f : α → ε} : eLpNorm' f 0 μ = 1 := by
rw [eLpNorm', div_zero, ENNReal.rpow_zero]
@[simp]
theorem eLpNorm_exponent_zero {f : α → ε} : eLpNorm f 0 μ = 0 := by simp [eLpNorm]
@[simp]
| Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean | 90 | 91 | theorem memLp_zero_iff_aestronglyMeasurable [TopologicalSpace ε] {f : α → ε} :
MemLp f 0 μ ↔ AEStronglyMeasurable f μ := by | simp [MemLp, eLpNorm_exponent_zero] |
/-
Copyright (c) 2020 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky, Anthony DeRossi
-/
import Mathlib.Data.List.Basic
/-!
# Properties of `List.reduceOption`
In this file we prove basic lemmas about `List.reduceOption`.
-/
namespace List
variable {α β : Type*}
@[simp]
| Mathlib/Data/List/ReduceOption.lean | 19 | 21 | theorem reduceOption_cons_of_some (x : α) (l : List (Option α)) :
reduceOption (some x :: l) = x :: l.reduceOption := by | simp only [reduceOption, filterMap, id, eq_self_iff_true, and_self_iff] |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.MonoidAlgebra.Degree
import Mathlib.Algebra.Order.Ring.WithTop
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Data.Nat.Cast.WithTop
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.SuccPred.WithBot
/-!
# Degree of univariate polynomials
## Main definitions
* `Polynomial.degree`: the degree of a polynomial, where `0` has degree `⊥`
* `Polynomial.natDegree`: the degree of a polynomial, where `0` has degree `0`
* `Polynomial.leadingCoeff`: the leading coefficient of a polynomial
* `Polynomial.Monic`: a polynomial is monic if its leading coefficient is 0
* `Polynomial.nextCoeff`: the next coefficient after the leading coefficient
## Main results
* `Polynomial.degree_eq_natDegree`: the degree and natDegree coincide for nonzero polynomials
-/
noncomputable section
open Finsupp Finset
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.
`degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise
`degree 0 = ⊥`. -/
def degree (p : R[X]) : WithBot ℕ :=
p.support.max
/-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/
def natDegree (p : R[X]) : ℕ :=
(degree p).unbotD 0
/-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`. -/
def leadingCoeff (p : R[X]) : R :=
coeff p (natDegree p)
/-- a polynomial is `Monic` if its leading coefficient is 1 -/
def Monic (p : R[X]) :=
leadingCoeff p = (1 : R)
theorem Monic.def : Monic p ↔ leadingCoeff p = 1 :=
Iff.rfl
instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance
@[simp]
theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 :=
hp
theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 :=
hp
@[simp]
theorem degree_zero : degree (0 : R[X]) = ⊥ :=
rfl
@[simp]
theorem natDegree_zero : natDegree (0 : R[X]) = 0 :=
rfl
@[simp]
theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p :=
rfl
@[simp]
theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 :=
⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩
theorem degree_ne_bot : degree p ≠ ⊥ ↔ p ≠ 0 := degree_eq_bot.not
theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by
let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp))
have hn : degree p = some n := Classical.not_not.1 hn
rw [natDegree, hn]; rfl
theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :
p.degree = n ↔ p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe
theorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) :
p.degree = n ↔ p.natDegree = n := by
obtain rfl|h := eq_or_ne p 0
· simp [hn.ne]
· exact degree_eq_iff_natDegree_eq h
theorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : ℕ} (h : degree p = n) : natDegree p = n := by
rw [natDegree, h, Nat.cast_withBot, WithBot.unbotD_coe]
theorem degree_ne_of_natDegree_ne {n : ℕ} : p.natDegree ≠ n → degree p ≠ n :=
mt natDegree_eq_of_degree_eq_some
@[simp]
theorem degree_le_natDegree : degree p ≤ natDegree p :=
WithBot.giUnbotDBot.gc.le_u_l _
theorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) :
natDegree p = natDegree q := by unfold natDegree; rw [h]
theorem le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : WithBot ℕ) ≤ degree p := by
rw [Nat.cast_withBot]
exact Finset.le_sup (mem_support_iff.2 h)
theorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support ⊆ g.support) :
f.degree ≤ g.degree :=
Finset.sup_mono h
theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree q := by
by_cases hp : p = 0
· rw [hp, degree_zero]
exact bot_le
· rw [degree_eq_natDegree hp]
exact le_degree_of_ne_zero h
theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n :=
WithBot.unbotD_le_iff (fun _ ↦ bot_le)
theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n :=
WithBot.unbotD_lt_iff (absurd · (degree_eq_bot.not.mpr hp))
alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le
theorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) :
p.natDegree ≤ q.natDegree :=
WithBot.giUnbotDBot.gc.monotone_l hpq
@[simp]
theorem degree_C (ha : a ≠ 0) : degree (C a) = (0 : WithBot ℕ) := by
rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton,
WithBot.coe_zero]
theorem degree_C_le : degree (C a) ≤ 0 := by
by_cases h : a = 0
· rw [h, C_0]
exact bot_le
· rw [degree_C h]
theorem degree_C_lt : degree (C a) < 1 :=
degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one
theorem degree_one_le : degree (1 : R[X]) ≤ (0 : WithBot ℕ) := by rw [← C_1]; exact degree_C_le
@[simp]
theorem natDegree_C (a : R) : natDegree (C a) = 0 := by
by_cases ha : a = 0
· have : C a = 0 := by rw [ha, C_0]
rw [natDegree, degree_eq_bot.2 this, WithBot.unbotD_bot]
· rw [natDegree, degree_C ha, WithBot.unbotD_zero]
@[simp]
theorem natDegree_one : natDegree (1 : R[X]) = 0 :=
natDegree_C 1
@[simp]
theorem natDegree_natCast (n : ℕ) : natDegree (n : R[X]) = 0 := by
simp only [← C_eq_natCast, natDegree_C]
@[simp]
theorem natDegree_ofNat (n : ℕ) [Nat.AtLeastTwo n] :
natDegree (ofNat(n) : R[X]) = 0 :=
natDegree_natCast _
theorem degree_natCast_le (n : ℕ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp)
@[simp]
theorem degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n := by
rw [degree, support_monomial n ha, max_singleton, Nat.cast_withBot]
@[simp]
theorem degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by
rw [C_mul_X_pow_eq_monomial, degree_monomial n ha]
theorem degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 := by
simpa only [pow_one] using degree_C_mul_X_pow 1 ha
theorem degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n :=
letI := Classical.decEq R
if h : a = 0 then by rw [h, (monomial n).map_zero, degree_zero]; exact bot_le
else le_of_eq (degree_monomial n h)
theorem degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n := by
rw [C_mul_X_pow_eq_monomial]
apply degree_monomial_le
theorem degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 := by
simpa only [pow_one] using degree_C_mul_X_pow_le 1 a
@[simp]
theorem natDegree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : natDegree (C a * X ^ n) = n :=
natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha)
@[simp]
theorem natDegree_C_mul_X (a : R) (ha : a ≠ 0) : natDegree (C a * X) = 1 := by
simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha
@[simp]
theorem natDegree_monomial [DecidableEq R] (i : ℕ) (r : R) :
natDegree (monomial i r) = if r = 0 then 0 else i := by
split_ifs with hr
· simp [hr]
· rw [← C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr]
theorem natDegree_monomial_le (a : R) {m : ℕ} : (monomial m a).natDegree ≤ m := by
classical
rw [Polynomial.natDegree_monomial]
split_ifs
exacts [Nat.zero_le _, le_rfl]
theorem natDegree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) : (monomial i r).natDegree = i :=
letI := Classical.decEq R
Eq.trans (natDegree_monomial _ _) (if_neg r0)
theorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n ≠ 0 := fun h =>
mem_support_iff.mp (mem_of_max hn) h
theorem degree_X_pow_le (n : ℕ) : degree (X ^ n : R[X]) ≤ n := by
simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R)
theorem degree_X_le : degree (X : R[X]) ≤ 1 :=
degree_monomial_le _ _
theorem natDegree_X_le : (X : R[X]).natDegree ≤ 1 :=
natDegree_le_of_degree_le degree_X_le
theorem withBotSucc_degree_eq_natDegree_add_one (h : p ≠ 0) : p.degree.succ = p.natDegree + 1 := by
rw [degree_eq_natDegree h]
exact WithBot.succ_coe p.natDegree
end Semiring
section NonzeroSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]}
@[simp]
theorem degree_one : degree (1 : R[X]) = (0 : WithBot ℕ) :=
degree_C one_ne_zero
@[simp]
theorem degree_X : degree (X : R[X]) = 1 :=
degree_monomial _ one_ne_zero
@[simp]
theorem natDegree_X : (X : R[X]).natDegree = 1 :=
natDegree_eq_of_degree_eq_some degree_X
end NonzeroSemiring
section Ring
variable [Ring R]
@[simp]
theorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg]
theorem degree_neg_le_of_le {a : WithBot ℕ} {p : R[X]} (hp : degree p ≤ a) : degree (-p) ≤ a :=
p.degree_neg.le.trans hp
@[simp]
theorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree]
theorem natDegree_neg_le_of_le {p : R[X]} (hp : natDegree p ≤ m) : natDegree (-p) ≤ m :=
(natDegree_neg p).le.trans hp
@[simp]
| Mathlib/Algebra/Polynomial/Degree/Definitions.lean | 286 | 286 | theorem natDegree_intCast (n : ℤ) : natDegree (n : R[X]) = 0 := by | |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen, Antoine Labelle
-/
import Mathlib.LinearAlgebra.Contraction
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
import Mathlib.RingTheory.Finiteness.Prod
import Mathlib.RingTheory.TensorProduct.Finite
import Mathlib.RingTheory.TensorProduct.Free
/-!
# Trace of a linear map
This file defines the trace of a linear map.
See also `LinearAlgebra/Matrix/Trace.lean` for the trace of a matrix.
## Tags
linear_map, trace, diagonal
-/
noncomputable section
universe u v w
namespace LinearMap
open scoped Matrix
open Module TensorProduct
section
variable (R : Type u) [CommSemiring R] {M : Type v} [AddCommMonoid M] [Module R M]
variable {ι : Type w} [DecidableEq ι] [Fintype ι]
variable {κ : Type*} [DecidableEq κ] [Fintype κ]
variable (b : Basis ι R M) (c : Basis κ R M)
/-- The trace of an endomorphism given a basis. -/
def traceAux : (M →ₗ[R] M) →ₗ[R] R :=
Matrix.traceLinearMap ι R R ∘ₗ ↑(LinearMap.toMatrix b b)
-- Can't be `simp` because it would cause a loop.
theorem traceAux_def (b : Basis ι R M) (f : M →ₗ[R] M) :
traceAux R b f = Matrix.trace (LinearMap.toMatrix b b f) :=
rfl
theorem traceAux_eq : traceAux R b = traceAux R c :=
LinearMap.ext fun f =>
calc
Matrix.trace (LinearMap.toMatrix b b f) =
Matrix.trace (LinearMap.toMatrix b b ((LinearMap.id.comp f).comp LinearMap.id)) := by
rw [LinearMap.id_comp, LinearMap.comp_id]
_ = Matrix.trace (LinearMap.toMatrix c b LinearMap.id * LinearMap.toMatrix c c f *
LinearMap.toMatrix b c LinearMap.id) := by
rw [LinearMap.toMatrix_comp _ c, LinearMap.toMatrix_comp _ c]
_ = Matrix.trace (LinearMap.toMatrix c c f * LinearMap.toMatrix b c LinearMap.id *
LinearMap.toMatrix c b LinearMap.id) := by
rw [Matrix.mul_assoc, Matrix.trace_mul_comm]
_ = Matrix.trace (LinearMap.toMatrix c c ((f.comp LinearMap.id).comp LinearMap.id)) := by
rw [LinearMap.toMatrix_comp _ b, LinearMap.toMatrix_comp _ c]
_ = Matrix.trace (LinearMap.toMatrix c c f) := by rw [LinearMap.comp_id, LinearMap.comp_id]
variable (M) in
open Classical in
/-- Trace of an endomorphism independent of basis. -/
def trace : (M →ₗ[R] M) →ₗ[R] R :=
if H : ∃ s : Finset M, Nonempty (Basis s R M) then traceAux R H.choose_spec.some else 0
open Classical in
/-- Auxiliary lemma for `trace_eq_matrix_trace`. -/
theorem trace_eq_matrix_trace_of_finset {s : Finset M} (b : Basis s R M) (f : M →ₗ[R] M) :
trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by
have : ∃ s : Finset M, Nonempty (Basis s R M) := ⟨s, ⟨b⟩⟩
rw [trace, dif_pos this, ← traceAux_def]
congr 1
apply traceAux_eq
theorem trace_eq_matrix_trace (f : M →ₗ[R] M) :
trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by
classical
rw [trace_eq_matrix_trace_of_finset R b.reindexFinsetRange, ← traceAux_def, ← traceAux_def,
traceAux_eq R b b.reindexFinsetRange]
theorem trace_mul_comm (f g : M →ₗ[R] M) : trace R M (f * g) = trace R M (g * f) := by
classical
by_cases H : ∃ s : Finset M, Nonempty (Basis s R M)
· let ⟨s, ⟨b⟩⟩ := H
simp_rw [trace_eq_matrix_trace R b, LinearMap.toMatrix_mul]
apply Matrix.trace_mul_comm
· rw [trace, dif_neg H, LinearMap.zero_apply, LinearMap.zero_apply]
lemma trace_mul_cycle (f g h : M →ₗ[R] M) :
trace R M (f * g * h) = trace R M (h * f * g) := by
rw [LinearMap.trace_mul_comm, ← mul_assoc]
lemma trace_mul_cycle' (f g h : M →ₗ[R] M) :
trace R M (f * (g * h)) = trace R M (h * (f * g)) := by
rw [← mul_assoc, LinearMap.trace_mul_comm]
/-- The trace of an endomorphism is invariant under conjugation -/
@[simp]
theorem trace_conj (g : M →ₗ[R] M) (f : (M →ₗ[R] M)ˣ) :
trace R M (↑f * g * ↑f⁻¹) = trace R M g := by
rw [trace_mul_comm]
simp
@[simp]
lemma trace_lie {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (f g : Module.End R M) :
trace R M ⁅f, g⁆ = 0 := by
rw [Ring.lie_def, map_sub, trace_mul_comm]
exact sub_self _
end
section
variable {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M]
variable (N P : Type*) [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P]
variable {ι : Type*}
/-- The trace of a linear map correspond to the contraction pairing under the isomorphism
`End(M) ≃ M* ⊗ M` -/
theorem trace_eq_contract_of_basis [Finite ι] (b : Basis ι R M) :
LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M := by
classical
cases nonempty_fintype ι
apply Basis.ext (Basis.tensorProduct (Basis.dualBasis b) b)
rintro ⟨i, j⟩
simp only [Function.comp_apply, Basis.tensorProduct_apply, Basis.coe_dualBasis, coe_comp]
rw [trace_eq_matrix_trace R b, toMatrix_dualTensorHom]
by_cases hij : i = j
· rw [hij]
simp
rw [Matrix.StdBasisMatrix.trace_zero j i (1 : R) hij]
simp [Finsupp.single_eq_pi_single, hij]
/-- The trace of a linear map corresponds to the contraction pairing under the isomorphism
`End(M) ≃ M* ⊗ M`. -/
theorem trace_eq_contract_of_basis' [Fintype ι] [DecidableEq ι] (b : Basis ι R M) :
LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquivOfBasis b).symm.toLinearMap := by
simp [LinearEquiv.eq_comp_toLinearMap_symm, trace_eq_contract_of_basis b]
section
variable (R M)
variable [Module.Free R M] [Module.Finite R M] [Module.Free R N] [Module.Finite R N]
/-- When `M` is finite free, the trace of a linear map corresponds to the contraction pairing under
the isomorphism `End(M) ≃ M* ⊗ M`. -/
@[simp]
theorem trace_eq_contract : LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M :=
trace_eq_contract_of_basis (Module.Free.chooseBasis R M)
@[simp]
theorem trace_eq_contract_apply (x : Module.Dual R M ⊗[R] M) :
(LinearMap.trace R M) ((dualTensorHom R M M) x) = contractLeft R M x := by
rw [← comp_apply, trace_eq_contract]
/-- When `M` is finite free, the trace of a linear map corresponds to the contraction pairing under
the isomorphism `End(M) ≃ M* ⊗ M`. -/
theorem trace_eq_contract' :
LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquiv R M M).symm.toLinearMap :=
trace_eq_contract_of_basis' (Module.Free.chooseBasis R M)
/-- The trace of the identity endomorphism is the dimension of the free module. -/
@[simp]
theorem trace_one : trace R M 1 = (finrank R M : R) := by
cases subsingleton_or_nontrivial R
· simp [eq_iff_true_of_subsingleton]
have b := Module.Free.chooseBasis R M
rw [trace_eq_matrix_trace R b, toMatrix_one, finrank_eq_card_chooseBasisIndex]
simp
/-- The trace of the identity endomorphism is the dimension of the free module. -/
@[simp]
theorem trace_id : trace R M id = (finrank R M : R) := by rw [← Module.End.one_eq_id, trace_one]
@[simp]
theorem trace_transpose : trace R (Module.Dual R M) ∘ₗ Module.Dual.transpose = trace R M := by
let e := dualTensorHomEquiv R M M
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext f m; simp [e]
theorem trace_prodMap :
trace R (M × N) ∘ₗ prodMapLinear R M N M N R =
(coprod id id : R × R →ₗ[R] R) ∘ₗ prodMap (trace R M) (trace R N) := by
let e := (dualTensorHomEquiv R M M).prodCongr (dualTensorHomEquiv R N N)
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext
· simp only [dualTensorHomEquiv, LinearEquiv.coe_prodCongr,
dualTensorHomEquivOfBasis_toLinearMap, AlgebraTensorModule.curry_apply, restrictScalars_comp,
curry_apply, coe_comp, coe_restrictScalars, coe_inl, Function.comp_apply, prodMap_apply,
map_zero, prodMapLinear_apply, dualTensorHom_prodMap_zero, trace_eq_contract_apply,
contractLeft_apply, coe_fst, coprod_apply, id_coe, id_eq, add_zero, e]
· simp only [dualTensorHomEquiv, LinearEquiv.coe_prodCongr,
dualTensorHomEquivOfBasis_toLinearMap, AlgebraTensorModule.curry_apply, restrictScalars_comp,
curry_apply, coe_comp, coe_restrictScalars, coe_inr, Function.comp_apply, prodMap_apply,
map_zero, prodMapLinear_apply, zero_prodMap_dualTensorHom, trace_eq_contract_apply,
contractLeft_apply, coe_snd, coprod_apply, id_coe, id_eq, zero_add, e]
variable {R M N P}
theorem trace_prodMap' (f : M →ₗ[R] M) (g : N →ₗ[R] N) :
trace R (M × N) (prodMap f g) = trace R M f + trace R N g := by
have h := LinearMap.ext_iff.1 (trace_prodMap R M N) (f, g)
simp only [coe_comp, Function.comp_apply, prodMap_apply, coprod_apply, id_coe, id,
prodMapLinear_apply] at h
exact h
variable (R M N P)
open TensorProduct Function
theorem trace_tensorProduct : compr₂ (mapBilinear R M N M N) (trace R (M ⊗ N)) =
compl₁₂ (lsmul R R : R →ₗ[R] R →ₗ[R] R) (trace R M) (trace R N) := by
apply
(compl₁₂_inj (show Surjective (dualTensorHom R M M) from (dualTensorHomEquiv R M M).surjective)
(show Surjective (dualTensorHom R N N) from (dualTensorHomEquiv R N N).surjective)).1
ext f m g n
simp only [AlgebraTensorModule.curry_apply, toFun_eq_coe, TensorProduct.curry_apply,
coe_restrictScalars, compl₁₂_apply, compr₂_apply, mapBilinear_apply,
trace_eq_contract_apply, contractLeft_apply, lsmul_apply, Algebra.id.smul_eq_mul,
map_dualTensorHom, dualDistrib_apply]
theorem trace_comp_comm :
compr₂ (llcomp R M N M) (trace R M) = compr₂ (llcomp R N M N).flip (trace R N) := by
apply
(compl₁₂_inj (show Surjective (dualTensorHom R N M) from (dualTensorHomEquiv R N M).surjective)
(show Surjective (dualTensorHom R M N) from (dualTensorHomEquiv R M N).surjective)).1
ext g m f n
simp only [AlgebraTensorModule.curry_apply, TensorProduct.curry_apply,
coe_restrictScalars, compl₁₂_apply, compr₂_apply, flip_apply, llcomp_apply',
comp_dualTensorHom, LinearMapClass.map_smul, trace_eq_contract_apply,
contractLeft_apply, smul_eq_mul, mul_comm]
variable {R M N P}
@[simp]
theorem trace_transpose' (f : M →ₗ[R] M) :
trace R _ (Module.Dual.transpose (R := R) f) = trace R M f := by
rw [← comp_apply, trace_transpose]
theorem trace_tensorProduct' (f : M →ₗ[R] M) (g : N →ₗ[R] N) :
trace R (M ⊗ N) (map f g) = trace R M f * trace R N g := by
have h := LinearMap.ext_iff.1 (LinearMap.ext_iff.1 (trace_tensorProduct R M N) f) g
simp only [compr₂_apply, mapBilinear_apply, compl₁₂_apply, lsmul_apply,
Algebra.id.smul_eq_mul] at h
exact h
theorem trace_comp_comm' (f : M →ₗ[R] N) (g : N →ₗ[R] M) :
trace R M (g ∘ₗ f) = trace R N (f ∘ₗ g) := by
have h := LinearMap.ext_iff.1 (LinearMap.ext_iff.1 (trace_comp_comm R M N) g) f
simp only [llcomp_apply', compr₂_apply, flip_apply] at h
exact h
end
variable {N P}
variable [Module.Free R N] [Module.Finite R N] [Module.Free R P] [Module.Finite R P] in
lemma trace_comp_cycle (f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : P →ₗ[R] M) :
trace R P (g ∘ₗ f ∘ₗ h) = trace R N (f ∘ₗ h ∘ₗ g) := by
rw [trace_comp_comm', comp_assoc]
variable [Module.Free R M] [Module.Finite R M] [Module.Free R P] [Module.Finite R P] in
lemma trace_comp_cycle' (f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : P →ₗ[R] M) :
trace R P ((g ∘ₗ f) ∘ₗ h) = trace R M ((h ∘ₗ g) ∘ₗ f) := by
rw [trace_comp_comm', ← comp_assoc]
@[simp]
theorem trace_conj' (f : M →ₗ[R] M) (e : M ≃ₗ[R] N) : trace R N (e.conj f) = trace R M f := by
classical
by_cases hM : ∃ s : Finset M, Nonempty (Basis s R M)
· obtain ⟨s, ⟨b⟩⟩ := hM
haveI := Module.Finite.of_basis b
haveI := (Module.free_def R M).mpr ⟨_, ⟨b⟩⟩
haveI := Module.Finite.of_basis (b.map e)
haveI := (Module.free_def R N).mpr ⟨_, ⟨(b.map e).reindex (e.toEquiv.image _)⟩⟩
rw [e.conj_apply, trace_comp_comm', ← comp_assoc, LinearEquiv.comp_coe,
LinearEquiv.self_trans_symm, LinearEquiv.refl_toLinearMap, id_comp]
· rw [trace, trace, dif_neg hM, dif_neg ?_, zero_apply, zero_apply]
rintro ⟨s, ⟨b⟩⟩
exact hM ⟨s.image e.symm, ⟨(b.map e.symm).reindex
((e.symm.toEquiv.image s).trans (Equiv.setCongr Finset.coe_image.symm))⟩⟩
| Mathlib/LinearAlgebra/Trace.lean | 289 | 291 | theorem IsProj.trace {p : Submodule R M} {f : M →ₗ[R] M} (h : IsProj p f) [Module.Free R p]
[Module.Finite R p] [Module.Free R (ker f)] [Module.Finite R (ker f)] :
trace R M f = (finrank R p : R) := by | |
/-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.JapaneseBracket
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Group.Integral
import Mathlib.MeasureTheory.Integral.IntegralEqImproper
import Mathlib.MeasureTheory.Measure.Lebesgue.Integral
/-!
# Evaluation of specific improper integrals
This file contains some integrability results, and evaluations of integrals, over `ℝ` or over
half-infinite intervals in `ℝ`.
These lemmas are stated in terms of either `Iic` or `Ioi` (neglecting `Iio` and `Ici`) to match
mathlib's conventions for integrals over finite intervals (see `intervalIntegral`).
## See also
- `Mathlib.Analysis.SpecialFunctions.Integrals` -- integrals over finite intervals
- `Mathlib.Analysis.SpecialFunctions.Gaussian` -- integral of `exp (-x ^ 2)`
- `Mathlib.Analysis.SpecialFunctions.JapaneseBracket`-- integrability of `(1+‖x‖)^(-r)`.
-/
open Real Set Filter MeasureTheory intervalIntegral
open scoped Topology
theorem integrableOn_exp_Iic (c : ℝ) : IntegrableOn exp (Iic c) := by
refine
integrableOn_Iic_of_intervalIntegral_norm_bounded (exp c) c
(fun y => intervalIntegrable_exp.1) tendsto_id
(eventually_of_mem (Iic_mem_atBot 0) fun y _ => ?_)
simp_rw [norm_of_nonneg (exp_pos _).le, integral_exp, sub_le_self_iff]
exact (exp_pos _).le
theorem integrableOn_exp_neg_Ioi (c : ℝ) : IntegrableOn (fun (x : ℝ) => exp (-x)) (Ioi c) :=
integrableOn_Ici_iff_integrableOn_Ioi.mp (integrableOn_exp_Iic (-c)).comp_neg_Ici
theorem integral_exp_Iic (c : ℝ) : ∫ x : ℝ in Iic c, exp x = exp c := by
refine
tendsto_nhds_unique
(intervalIntegral_tendsto_integral_Iic _ (integrableOn_exp_Iic _) tendsto_id) ?_
simp_rw [integral_exp, show 𝓝 (exp c) = 𝓝 (exp c - 0) by rw [sub_zero]]
exact tendsto_exp_atBot.const_sub _
theorem integral_exp_Iic_zero : ∫ x : ℝ in Iic 0, exp x = 1 :=
exp_zero ▸ integral_exp_Iic 0
theorem integral_exp_neg_Ioi (c : ℝ) : (∫ x : ℝ in Ioi c, exp (-x)) = exp (-c) := by
simpa only [integral_comp_neg_Ioi] using integral_exp_Iic (-c)
theorem integral_exp_neg_Ioi_zero : (∫ x : ℝ in Ioi 0, exp (-x)) = 1 := by
simpa only [neg_zero, exp_zero] using integral_exp_neg_Ioi 0
theorem integrableOn_exp_mul_complex_Ioi {a : ℂ} (ha : a.re < 0) (c : ℝ) :
IntegrableOn (fun x : ℝ => Complex.exp (a * x)) (Ioi c) := by
refine (integrable_norm_iff ?_).mp ?_
· apply Continuous.aestronglyMeasurable
fun_prop
· simpa [Complex.norm_exp] using
(integrableOn_Ioi_comp_mul_left_iff (fun x => exp (-x)) c (a := -a.re) (by simpa)).mpr <|
integrableOn_exp_neg_Ioi _
theorem integrableOn_exp_mul_complex_Iic {a : ℂ} (ha : 0 < a.re) (c : ℝ) :
IntegrableOn (fun x : ℝ => Complex.exp (a * x)) (Iic c) := by
simpa using integrableOn_Iic_iff_integrableOn_Iio.mpr
(integrableOn_exp_mul_complex_Ioi (a := -a) (by simpa) (-c)).comp_neg_Iio
theorem integrableOn_exp_mul_Ioi {a : ℝ} (ha : a < 0) (c : ℝ) :
IntegrableOn (fun x : ℝ => Real.exp (a * x)) (Ioi c) := by
have := Integrable.norm <| integrableOn_exp_mul_complex_Ioi (a := a) (by simpa using ha) c
simpa [Complex.norm_exp] using this
theorem integrableOn_exp_mul_Iic {a : ℝ} (ha : 0 < a) (c : ℝ) :
IntegrableOn (fun x : ℝ => Real.exp (a * x)) (Iic c) := by
have := Integrable.norm <| integrableOn_exp_mul_complex_Iic (a := a) (by simpa using ha) c
simpa [Complex.norm_exp] using this
theorem integral_exp_mul_complex_Ioi {a : ℂ} (ha : a.re < 0) (c : ℝ) :
∫ x : ℝ in Set.Ioi c, Complex.exp (a * x) = - Complex.exp (a * c) / a := by
refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Ioi c
(integrableOn_exp_mul_complex_Ioi ha c) tendsto_id) ?_
simp_rw [integral_exp_mul_complex (c := a) (by aesop), id_eq]
suffices Tendsto (fun x : ℝ ↦ Complex.exp (a * x)) atTop (𝓝 0) by
simpa using this.sub_const _ |>.div_const _
simpa [Complex.tendsto_exp_nhds_zero_iff] using tendsto_const_nhds.neg_mul_atTop ha tendsto_id
theorem integral_exp_mul_complex_Iic {a : ℂ} (ha : 0 < a.re) (c : ℝ) :
∫ x : ℝ in Set.Iic c, Complex.exp (a * x) = Complex.exp (a * c) / a := by
simpa [neg_mul, ← mul_neg, ← Complex.ofReal_neg,
integral_comp_neg_Ioi (f := fun x : ℝ ↦ Complex.exp (a * x))]
using integral_exp_mul_complex_Ioi (a := -a) (by simpa) (-c)
theorem integral_exp_mul_Ioi {a : ℝ} (ha : a < 0) (c : ℝ) :
∫ x : ℝ in Set.Ioi c, Real.exp (a * x) = - Real.exp (a * c) / a := by
simp_rw [Real.exp, ← RCLike.re_to_complex, Complex.ofReal_mul]
rw [integral_re, integral_exp_mul_complex_Ioi (by simpa using ha), RCLike.re_to_complex,
RCLike.re_to_complex, Complex.div_ofReal_re, Complex.neg_re]
exact integrableOn_exp_mul_complex_Ioi (by simpa using ha) _
| Mathlib/Analysis/SpecialFunctions/ImproperIntegrals.lean | 106 | 116 | theorem integral_exp_mul_Iic {a : ℝ} (ha : 0 < a) (c : ℝ) :
∫ x : ℝ in Set.Iic c, Real.exp (a * x) = Real.exp (a * c) / a := by | simpa [neg_mul, ← mul_neg, integral_comp_neg_Ioi (f := fun x : ℝ ↦ Real.exp (a * x))]
using integral_exp_mul_Ioi (a := -a) (by simpa) (-c)
/-- If `0 < c`, then `(fun t : ℝ ↦ t ^ a)` is integrable on `(c, ∞)` for all `a < -1`. -/
theorem integrableOn_Ioi_rpow_of_lt {a : ℝ} (ha : a < -1) {c : ℝ} (hc : 0 < c) :
IntegrableOn (fun t : ℝ => t ^ a) (Ioi c) := by
have hd : ∀ x ∈ Ici c, HasDerivAt (fun t => t ^ (a + 1) / (a + 1)) (x ^ a) x := by
intro x hx
convert (hasDerivAt_rpow_const (Or.inl (hc.trans_le hx).ne')).div_const _ using 1 |
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Manuel Candales
-/
import Mathlib.Analysis.InnerProductSpace.Subspace
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse
/-!
# Angles between vectors
This file defines unoriented angles in real inner product spaces.
## Main definitions
* `InnerProductGeometry.angle` is the undirected angle between two vectors.
## TODO
Prove the triangle inequality for the angle.
-/
assert_not_exists HasFDerivAt ConformalAt
noncomputable section
open Real Set
open Real
open RealInnerProductSpace
namespace InnerProductGeometry
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] {x y : V}
/-- The undirected angle between two vectors. If either vector is 0,
this is π/2. See `Orientation.oangle` for the corresponding oriented angle
definition. -/
def angle (x y : V) : ℝ :=
Real.arccos (⟪x, y⟫ / (‖x‖ * ‖y‖))
theorem continuousAt_angle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) :
ContinuousAt (fun y : V × V => angle y.1 y.2) x := by
unfold angle
fun_prop (disch := simp [*])
theorem angle_smul_smul {c : ℝ} (hc : c ≠ 0) (x y : V) : angle (c • x) (c • y) = angle x y := by
have : c * c ≠ 0 := mul_ne_zero hc hc
rw [angle, angle, real_inner_smul_left, inner_smul_right, norm_smul, norm_smul, Real.norm_eq_abs,
mul_mul_mul_comm _ ‖x‖, abs_mul_abs_self, ← mul_assoc c c, mul_div_mul_left _ _ this]
@[simp]
theorem _root_.LinearIsometry.angle_map {E F : Type*} [NormedAddCommGroup E] [NormedAddCommGroup F]
[InnerProductSpace ℝ E] [InnerProductSpace ℝ F] (f : E →ₗᵢ[ℝ] F) (u v : E) :
angle (f u) (f v) = angle u v := by
rw [angle, angle, f.inner_map_map, f.norm_map, f.norm_map]
@[simp, norm_cast]
theorem _root_.Submodule.angle_coe {s : Submodule ℝ V} (x y : s) :
angle (x : V) (y : V) = angle x y :=
s.subtypeₗᵢ.angle_map x y
/-- The cosine of the angle between two vectors. -/
theorem cos_angle (x y : V) : Real.cos (angle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) :=
Real.cos_arccos (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1
(abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2
/-- The angle between two vectors does not depend on their order. -/
theorem angle_comm (x y : V) : angle x y = angle y x := by
unfold angle
rw [real_inner_comm, mul_comm]
/-- The angle between the negation of two vectors. -/
@[simp]
theorem angle_neg_neg (x y : V) : angle (-x) (-y) = angle x y := by
unfold angle
rw [inner_neg_neg, norm_neg, norm_neg]
/-- The angle between two vectors is nonnegative. -/
theorem angle_nonneg (x y : V) : 0 ≤ angle x y :=
Real.arccos_nonneg _
/-- The angle between two vectors is at most π. -/
theorem angle_le_pi (x y : V) : angle x y ≤ π :=
Real.arccos_le_pi _
/-- The sine of the angle between two vectors is nonnegative. -/
theorem sin_angle_nonneg (x y : V) : 0 ≤ sin (angle x y) :=
sin_nonneg_of_nonneg_of_le_pi (angle_nonneg x y) (angle_le_pi x y)
/-- The angle between a vector and the negation of another vector. -/
theorem angle_neg_right (x y : V) : angle x (-y) = π - angle x y := by
unfold angle
rw [← Real.arccos_neg, norm_neg, inner_neg_right, neg_div]
/-- The angle between the negation of a vector and another vector. -/
theorem angle_neg_left (x y : V) : angle (-x) y = π - angle x y := by
rw [← angle_neg_neg, neg_neg, angle_neg_right]
proof_wanted angle_triangle (x y z : V) : angle x z ≤ angle x y + angle y z
/-- The angle between the zero vector and a vector. -/
@[simp]
| Mathlib/Geometry/Euclidean/Angle/Unoriented/Basic.lean | 106 | 108 | theorem angle_zero_left (x : V) : angle 0 x = π / 2 := by | unfold angle
rw [inner_zero_left, zero_div, Real.arccos_zero] |
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.UniformSpace.Cauchy
/-!
# Uniform convergence
A sequence of functions `Fₙ` (with values in a metric space) converges uniformly on a set `s` to a
function `f` if, for all `ε > 0`, for all large enough `n`, one has for all `y ∈ s` the inequality
`dist (f y, Fₙ y) < ε`. Under uniform convergence, many properties of the `Fₙ` pass to the limit,
most notably continuity. We prove this in the file, defining the notion of uniform convergence
in the more general setting of uniform spaces, and with respect to an arbitrary indexing set
endowed with a filter (instead of just `ℕ` with `atTop`).
## Main results
Let `α` be a topological space, `β` a uniform space, `Fₙ` and `f` be functions from `α` to `β`
(where the index `n` belongs to an indexing type `ι` endowed with a filter `p`).
* `TendstoUniformlyOn F f p s`: the fact that `Fₙ` converges uniformly to `f` on `s`. This means
that, for any entourage `u` of the diagonal, for large enough `n` (with respect to `p`), one has
`(f y, Fₙ y) ∈ u` for all `y ∈ s`.
* `TendstoUniformly F f p`: same notion with `s = univ`.
* `TendstoUniformlyOn.continuousOn`: a uniform limit on a set of functions which are continuous
on this set is itself continuous on this set.
* `TendstoUniformly.continuous`: a uniform limit of continuous functions is continuous.
* `TendstoUniformlyOn.tendsto_comp`: If `Fₙ` tends uniformly to `f` on a set `s`, and `gₙ` tends
to `x` within `s`, then `Fₙ gₙ` tends to `f x` if `f` is continuous at `x` within `s`.
* `TendstoUniformly.tendsto_comp`: If `Fₙ` tends uniformly to `f`, and `gₙ` tends to `x`, then
`Fₙ gₙ` tends to `f x`.
Finally, we introduce the notion of a uniform Cauchy sequence, which is to uniform
convergence what a Cauchy sequence is to the usual notion of convergence.
## Implementation notes
We derive most of our initial results from an auxiliary definition `TendstoUniformlyOnFilter`.
This definition in and of itself can sometimes be useful, e.g., when studying the local behavior
of the `Fₙ` near a point, which would typically look like `TendstoUniformlyOnFilter F f p (𝓝 x)`.
Still, while this may be the "correct" definition (see
`tendstoUniformlyOn_iff_tendstoUniformlyOnFilter`), it is somewhat unwieldy to work with in
practice. Thus, we provide the more traditional definition in `TendstoUniformlyOn`.
## Tags
Uniform limit, uniform convergence, tends uniformly to
-/
noncomputable section
open Topology Uniformity Filter Set Uniform
variable {α β γ ι : Type*} [UniformSpace β]
variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} {p' : Filter α}
/-!
### Different notions of uniform convergence
We define uniform convergence, on a set or in the whole space.
-/
/-- A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f`
with respect to the filter `p` if, for any entourage of the diagonal `u`, one has
`p ×ˢ p'`-eventually `(f x, Fₙ x) ∈ u`. -/
def TendstoUniformlyOnFilter (F : ι → α → β) (f : α → β) (p : Filter ι) (p' : Filter α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n : ι × α in p ×ˢ p', (f n.snd, F n.fst n.snd) ∈ u
/--
A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ p'` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `p'`.
-/
theorem tendstoUniformlyOnFilter_iff_tendsto :
TendstoUniformlyOnFilter F f p p' ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ p') (𝓤 β) :=
Iff.rfl
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` with
respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x ∈ s`. -/
def TendstoUniformlyOn (F : ι → α → β) (f : α → β) (p : Filter ι) (s : Set α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, x ∈ s → (f x, F n x) ∈ u
theorem tendstoUniformlyOn_iff_tendstoUniformlyOnFilter :
TendstoUniformlyOn F f p s ↔ TendstoUniformlyOnFilter F f p (𝓟 s) := by
simp only [TendstoUniformlyOn, TendstoUniformlyOnFilter]
apply forall₂_congr
simp_rw [eventually_prod_principal_iff]
simp
alias ⟨TendstoUniformlyOn.tendstoUniformlyOnFilter, TendstoUniformlyOnFilter.tendstoUniformlyOn⟩ :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ 𝓟 s` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `s`.
-/
theorem tendstoUniformlyOn_iff_tendsto :
TendstoUniformlyOn F f p s ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ 𝓟 s) (𝓤 β) := by
simp [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` with respect to a
filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x`. -/
def TendstoUniformly (F : ι → α → β) (f : α → β) (p : Filter ι) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, (f x, F n x) ∈ u
theorem tendstoUniformlyOn_univ : TendstoUniformlyOn F f p univ ↔ TendstoUniformly F f p := by
simp [TendstoUniformlyOn, TendstoUniformly]
theorem tendstoUniformly_iff_tendstoUniformlyOnFilter :
TendstoUniformly F f p ↔ TendstoUniformlyOnFilter F f p ⊤ := by
rw [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, principal_univ]
theorem TendstoUniformly.tendstoUniformlyOnFilter (h : TendstoUniformly F f p) :
TendstoUniformlyOnFilter F f p ⊤ := by rwa [← tendstoUniformly_iff_tendstoUniformlyOnFilter]
theorem tendstoUniformlyOn_iff_tendstoUniformly_comp_coe :
TendstoUniformlyOn F f p s ↔ TendstoUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p :=
forall₂_congr fun u _ => by simp
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ ⊤` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit.
-/
theorem tendstoUniformly_iff_tendsto :
TendstoUniformly F f p ↔ Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ ⊤) (𝓤 β) := by
simp [tendstoUniformly_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
/-- Uniform convergence implies pointwise convergence. -/
theorem TendstoUniformlyOnFilter.tendsto_at (h : TendstoUniformlyOnFilter F f p p')
(hx : 𝓟 {x} ≤ p') : Tendsto (fun n => F n x) p <| 𝓝 (f x) := by
refine Uniform.tendsto_nhds_right.mpr fun u hu => mem_map.mpr ?_
filter_upwards [(h u hu).curry]
intro i h
simpa using h.filter_mono hx
/-- Uniform convergence implies pointwise convergence. -/
theorem TendstoUniformlyOn.tendsto_at (h : TendstoUniformlyOn F f p s) (hx : x ∈ s) :
Tendsto (fun n => F n x) p <| 𝓝 (f x) :=
h.tendstoUniformlyOnFilter.tendsto_at
(le_principal_iff.mpr <| mem_principal.mpr <| singleton_subset_iff.mpr <| hx)
/-- Uniform convergence implies pointwise convergence. -/
theorem TendstoUniformly.tendsto_at (h : TendstoUniformly F f p) (x : α) :
Tendsto (fun n => F n x) p <| 𝓝 (f x) :=
h.tendstoUniformlyOnFilter.tendsto_at le_top
theorem TendstoUniformlyOnFilter.mono_left {p'' : Filter ι} (h : TendstoUniformlyOnFilter F f p p')
(hp : p'' ≤ p) : TendstoUniformlyOnFilter F f p'' p' := fun u hu =>
(h u hu).filter_mono (p'.prod_mono_left hp)
theorem TendstoUniformlyOnFilter.mono_right {p'' : Filter α} (h : TendstoUniformlyOnFilter F f p p')
(hp : p'' ≤ p') : TendstoUniformlyOnFilter F f p p'' := fun u hu =>
(h u hu).filter_mono (p.prod_mono_right hp)
theorem TendstoUniformlyOn.mono (h : TendstoUniformlyOn F f p s) (h' : s' ⊆ s) :
TendstoUniformlyOn F f p s' :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr
(h.tendstoUniformlyOnFilter.mono_right (le_principal_iff.mpr <| mem_principal.mpr h'))
theorem TendstoUniformlyOnFilter.congr {F' : ι → α → β} (hf : TendstoUniformlyOnFilter F f p p')
(hff' : ∀ᶠ n : ι × α in p ×ˢ p', F n.fst n.snd = F' n.fst n.snd) :
TendstoUniformlyOnFilter F' f p p' := by
refine fun u hu => ((hf u hu).and hff').mono fun n h => ?_
rw [← h.right]
exact h.left
theorem TendstoUniformlyOn.congr {F' : ι → α → β} (hf : TendstoUniformlyOn F f p s)
(hff' : ∀ᶠ n in p, Set.EqOn (F n) (F' n) s) : TendstoUniformlyOn F' f p s := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at hf ⊢
refine hf.congr ?_
rw [eventually_iff] at hff' ⊢
simp only [Set.EqOn] at hff'
simp only [mem_prod_principal, hff', mem_setOf_eq]
lemma tendstoUniformly_congr {F' : ι → α → β} (hF : F =ᶠ[p] F') :
TendstoUniformly F f p ↔ TendstoUniformly F' f p := by
simp_rw [← tendstoUniformlyOn_univ] at *
have HF := EventuallyEq.exists_mem hF
exact ⟨fun h => h.congr (by aesop), fun h => h.congr (by simp_rw [eqOn_comm]; aesop)⟩
theorem TendstoUniformlyOn.congr_right {g : α → β} (hf : TendstoUniformlyOn F f p s)
(hfg : EqOn f g s) : TendstoUniformlyOn F g p s := fun u hu => by
filter_upwards [hf u hu] with i hi a ha using hfg ha ▸ hi a ha
protected theorem TendstoUniformly.tendstoUniformlyOn (h : TendstoUniformly F f p) :
TendstoUniformlyOn F f p s :=
(tendstoUniformlyOn_univ.2 h).mono (subset_univ s)
/-- Composing on the right by a function preserves uniform convergence on a filter -/
theorem TendstoUniformlyOnFilter.comp (h : TendstoUniformlyOnFilter F f p p') (g : γ → α) :
TendstoUniformlyOnFilter (fun n => F n ∘ g) (f ∘ g) p (p'.comap g) := by
rw [tendstoUniformlyOnFilter_iff_tendsto] at h ⊢
exact h.comp (tendsto_id.prodMap tendsto_comap)
/-- Composing on the right by a function preserves uniform convergence on a set -/
theorem TendstoUniformlyOn.comp (h : TendstoUniformlyOn F f p s) (g : γ → α) :
TendstoUniformlyOn (fun n => F n ∘ g) (f ∘ g) p (g ⁻¹' s) := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h ⊢
simpa [TendstoUniformlyOn, comap_principal] using TendstoUniformlyOnFilter.comp h g
/-- Composing on the right by a function preserves uniform convergence -/
theorem TendstoUniformly.comp (h : TendstoUniformly F f p) (g : γ → α) :
TendstoUniformly (fun n => F n ∘ g) (f ∘ g) p := by
rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] at h ⊢
simpa [principal_univ, comap_principal] using h.comp g
/-- Composing on the left by a uniformly continuous function preserves
uniform convergence on a filter -/
theorem UniformContinuous.comp_tendstoUniformlyOnFilter [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformlyOnFilter F f p p') :
TendstoUniformlyOnFilter (fun i => g ∘ F i) (g ∘ f) p p' := fun _u hu => h _ (hg hu)
/-- Composing on the left by a uniformly continuous function preserves
uniform convergence on a set -/
theorem UniformContinuous.comp_tendstoUniformlyOn [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformlyOn F f p s) :
TendstoUniformlyOn (fun i => g ∘ F i) (g ∘ f) p s := fun _u hu => h _ (hg hu)
/-- Composing on the left by a uniformly continuous function preserves uniform convergence -/
theorem UniformContinuous.comp_tendstoUniformly [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformly F f p) :
TendstoUniformly (fun i => g ∘ F i) (g ∘ f) p := fun _u hu => h _ (hg hu)
theorem TendstoUniformlyOnFilter.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {q : Filter ι'} {q' : Filter α'} (h : TendstoUniformlyOnFilter F f p p')
(h' : TendstoUniformlyOnFilter F' f' q q') :
TendstoUniformlyOnFilter (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ q)
(p' ×ˢ q') := by
rw [tendstoUniformlyOnFilter_iff_tendsto] at h h' ⊢
rw [uniformity_prod_eq_comap_prod, tendsto_comap_iff, ← map_swap4_prod, tendsto_map'_iff]
simpa using h.prodMap h'
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOnFilter.prod_map := TendstoUniformlyOnFilter.prodMap
theorem TendstoUniformlyOn.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {p' : Filter ι'} {s' : Set α'} (h : TendstoUniformlyOn F f p s)
(h' : TendstoUniformlyOn F' f' p' s') :
TendstoUniformlyOn (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p')
(s ×ˢ s') := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h h' ⊢
simpa only [prod_principal_principal] using h.prodMap h'
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOn.prod_map := TendstoUniformlyOn.prodMap
theorem TendstoUniformly.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :
TendstoUniformly (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p') := by
rw [← tendstoUniformlyOn_univ, ← univ_prod_univ] at *
exact h.prodMap h'
@[deprecated (since := "2025-03-10")]
alias TendstoUniformly.prod_map := TendstoUniformly.prodMap
theorem TendstoUniformlyOnFilter.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'}
{f' : α → β'} {q : Filter ι'} (h : TendstoUniformlyOnFilter F f p p')
(h' : TendstoUniformlyOnFilter F' f' q p') :
TendstoUniformlyOnFilter (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))
(p ×ˢ q) p' :=
fun u hu => ((h.prodMap h') u hu).diag_of_prod_right
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOnFilter.prod := TendstoUniformlyOnFilter.prodMk
protected theorem TendstoUniformlyOn.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'}
{f' : α → β'} {p' : Filter ι'} (h : TendstoUniformlyOn F f p s)
(h' : TendstoUniformlyOn F' f' p' s) :
TendstoUniformlyOn (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ×ˢ p')
s :=
(congr_arg _ s.inter_self).mp ((h.prodMap h').comp fun a => (a, a))
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOn.prod := TendstoUniformlyOn.prodMk
theorem TendstoUniformly.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'}
{p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :
TendstoUniformly (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ×ˢ p') :=
(h.prodMap h').comp fun a => (a, a)
@[deprecated (since := "2025-03-10")]
alias TendstoUniformly.prod := TendstoUniformly.prodMk
/-- Uniform convergence on a filter `p'` to a constant function is equivalent to convergence in
`p ×ˢ p'`. -/
theorem tendsto_prod_filter_iff {c : β} :
Tendsto (↿F) (p ×ˢ p') (𝓝 c) ↔ TendstoUniformlyOnFilter F (fun _ => c) p p' := by
simp_rw [nhds_eq_comap_uniformity, tendsto_comap_iff]
rfl
/-- Uniform convergence on a set `s` to a constant function is equivalent to convergence in
`p ×ˢ 𝓟 s`. -/
theorem tendsto_prod_principal_iff {c : β} :
Tendsto (↿F) (p ×ˢ 𝓟 s) (𝓝 c) ↔ TendstoUniformlyOn F (fun _ => c) p s := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter]
exact tendsto_prod_filter_iff
/-- Uniform convergence to a constant function is equivalent to convergence in `p ×ˢ ⊤`. -/
theorem tendsto_prod_top_iff {c : β} :
Tendsto (↿F) (p ×ˢ ⊤) (𝓝 c) ↔ TendstoUniformly F (fun _ => c) p := by
rw [tendstoUniformly_iff_tendstoUniformlyOnFilter]
exact tendsto_prod_filter_iff
/-- Uniform convergence on the empty set is vacuously true -/
theorem tendstoUniformlyOn_empty : TendstoUniformlyOn F f p ∅ := fun u _ => by simp
/-- Uniform convergence on a singleton is equivalent to regular convergence -/
theorem tendstoUniformlyOn_singleton_iff_tendsto :
TendstoUniformlyOn F f p {x} ↔ Tendsto (fun n : ι => F n x) p (𝓝 (f x)) := by
simp_rw [tendstoUniformlyOn_iff_tendsto, Uniform.tendsto_nhds_right, tendsto_def]
exact forall₂_congr fun u _ => by simp [mem_prod_principal, preimage]
/-- If a sequence `g` converges to some `b`, then the sequence of constant functions
`fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/
theorem Filter.Tendsto.tendstoUniformlyOnFilter_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b))
(p' : Filter α) :
TendstoUniformlyOnFilter (fun n : ι => fun _ : α => g n) (fun _ : α => b) p p' := by
simpa only [nhds_eq_comap_uniformity, tendsto_comap_iff] using hg.comp (tendsto_fst (g := p'))
/-- If a sequence `g` converges to some `b`, then the sequence of constant functions
`fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/
theorem Filter.Tendsto.tendstoUniformlyOn_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b))
(s : Set α) : TendstoUniformlyOn (fun n : ι => fun _ : α => g n) (fun _ : α => b) p s :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (hg.tendstoUniformlyOnFilter_const (𝓟 s))
theorem UniformContinuousOn.tendstoUniformlyOn [UniformSpace α] [UniformSpace γ] {U : Set α}
{V : Set β} {F : α → β → γ} (hF : UniformContinuousOn (↿F) (U ×ˢ V)) (hU : x ∈ U) :
TendstoUniformlyOn F (F x) (𝓝[U] x) V := by
set φ := fun q : α × β => ((x, q.2), q)
rw [tendstoUniformlyOn_iff_tendsto]
change Tendsto (Prod.map (↿F) ↿F ∘ φ) (𝓝[U] x ×ˢ 𝓟 V) (𝓤 γ)
simp only [nhdsWithin, Filter.prod_eq_inf, comap_inf, inf_assoc, comap_principal, inf_principal]
refine hF.comp (Tendsto.inf ?_ <| tendsto_principal_principal.2 fun x hx => ⟨⟨hU, hx.2⟩, hx⟩)
simp only [uniformity_prod_eq_comap_prod, tendsto_comap_iff, (· ∘ ·),
nhds_eq_comap_uniformity, comap_comap]
exact tendsto_comap.prodMk (tendsto_diag_uniformity _ _)
theorem UniformContinuousOn.tendstoUniformly [UniformSpace α] [UniformSpace γ] {U : Set α}
(hU : U ∈ 𝓝 x) {F : α → β → γ} (hF : UniformContinuousOn (↿F) (U ×ˢ (univ : Set β))) :
TendstoUniformly F (F x) (𝓝 x) := by
simpa only [tendstoUniformlyOn_univ, nhdsWithin_eq_nhds.2 hU]
using hF.tendstoUniformlyOn (mem_of_mem_nhds hU)
theorem UniformContinuous₂.tendstoUniformly [UniformSpace α] [UniformSpace γ] {f : α → β → γ}
(h : UniformContinuous₂ f) : TendstoUniformly f (f x) (𝓝 x) :=
UniformContinuousOn.tendstoUniformly univ_mem <| by rwa [univ_prod_univ, uniformContinuousOn_univ]
/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are
uniformly bounded -/
def UniformCauchySeqOnFilter (F : ι → α → β) (p : Filter ι) (p' : Filter α) : Prop :=
∀ u ∈ 𝓤 β, ∀ᶠ m : (ι × ι) × α in (p ×ˢ p) ×ˢ p', (F m.fst.fst m.snd, F m.fst.snd m.snd) ∈ u
/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are
uniformly bounded -/
def UniformCauchySeqOn (F : ι → α → β) (p : Filter ι) (s : Set α) : Prop :=
∀ u ∈ 𝓤 β, ∀ᶠ m : ι × ι in p ×ˢ p, ∀ x : α, x ∈ s → (F m.fst x, F m.snd x) ∈ u
theorem uniformCauchySeqOn_iff_uniformCauchySeqOnFilter :
UniformCauchySeqOn F p s ↔ UniformCauchySeqOnFilter F p (𝓟 s) := by
simp only [UniformCauchySeqOn, UniformCauchySeqOnFilter]
refine forall₂_congr fun u hu => ?_
rw [eventually_prod_principal_iff]
| Mathlib/Topology/UniformSpace/UniformConvergence.lean | 370 | 381 | theorem UniformCauchySeqOn.uniformCauchySeqOnFilter (hF : UniformCauchySeqOn F p s) :
UniformCauchySeqOnFilter F p (𝓟 s) := by | rwa [← uniformCauchySeqOn_iff_uniformCauchySeqOnFilter]
/-- A sequence that converges uniformly is also uniformly Cauchy -/
theorem TendstoUniformlyOnFilter.uniformCauchySeqOnFilter (hF : TendstoUniformlyOnFilter F f p p') :
UniformCauchySeqOnFilter F p p' := by
intro u hu
rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩
have := tendsto_swap4_prod.eventually ((hF t ht).prod_mk (hF t ht))
apply this.diag_of_prod_right.mono
simp only [and_imp, Prod.forall]
intro n1 n2 x hl hr |
/-
Copyright (c) 2021 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Thomas Murrills
-/
import Mathlib.Algebra.GroupWithZero.Invertible
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.Nat.Cast.Basic
import Mathlib.Data.Nat.Cast.Commute
import Mathlib.Tactic.NormNum.Core
import Mathlib.Tactic.HaveI
import Mathlib.Tactic.ClearExclamation
/-!
## `norm_num` basic plugins
This file adds `norm_num` plugins for
* constructors and constants
* `Nat.cast`, `Int.cast`, and `mkRat`
* `+`, `-`, `*`, and `/`
* `Nat.succ`, `Nat.sub`, `Nat.mod`, and `Nat.div`.
See other files in this directory for many more plugins.
-/
universe u
namespace Mathlib
open Lean
open Meta
namespace Meta.NormNum
open Qq
theorem IsInt.raw_refl (n : ℤ) : IsInt n n := ⟨rfl⟩
/-! # Constructors and constants -/
theorem isNat_zero (α) [AddMonoidWithOne α] : IsNat (Zero.zero : α) (nat_lit 0) :=
⟨Nat.cast_zero.symm⟩
/-- The `norm_num` extension which identifies the expression `Zero.zero`, returning `0`. -/
@[norm_num Zero.zero] def evalZero : NormNumExt where eval {u α} e := do
let sα ← inferAddMonoidWithOne α
match e with
| ~q(Zero.zero) => return .isNat sα (mkRawNatLit 0) q(isNat_zero $α)
theorem isNat_one (α) [AddMonoidWithOne α] : IsNat (One.one : α) (nat_lit 1) := ⟨Nat.cast_one.symm⟩
/-- The `norm_num` extension which identifies the expression `One.one`, returning `1`. -/
@[norm_num One.one] def evalOne : NormNumExt where eval {u α} e := do
let sα ← inferAddMonoidWithOne α
match e with
| ~q(One.one) => return .isNat sα (mkRawNatLit 1) q(isNat_one $α)
theorem isNat_ofNat (α : Type u) [AddMonoidWithOne α] {a : α} {n : ℕ}
(h : n = a) : IsNat a n := ⟨h.symm⟩
/-- The `norm_num` extension which identifies an expression `OfNat.ofNat n`, returning `n`. -/
@[norm_num OfNat.ofNat _] def evalOfNat : NormNumExt where eval {u α} e := do
let sα ← inferAddMonoidWithOne α
match e with
| ~q(@OfNat.ofNat _ $n $oα) =>
let n : Q(ℕ) ← whnf n
guard n.isRawNatLit
let ⟨a, (pa : Q($n = $e))⟩ ← mkOfNat α sα n
guard <|← isDefEq a e
return .isNat sα n q(isNat_ofNat $α $pa)
theorem isNat_intOfNat : {n n' : ℕ} → IsNat n n' → IsNat (Int.ofNat n) n'
| _, _, ⟨rfl⟩ => ⟨rfl⟩
/-- The `norm_num` extension which identifies the constructor application `Int.ofNat n` such that
`norm_num` successfully recognizes `n`, returning `n`. -/
@[norm_num Int.ofNat _] def evalIntOfNat : NormNumExt where eval {u α} e := do
let .app (.const ``Int.ofNat _) (n : Q(ℕ)) ← whnfR e | failure
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q Int := ⟨⟩
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
let sℤ : Q(AddMonoidWithOne ℤ) := q(instAddMonoidWithOne)
let ⟨n', p⟩ ← deriveNat n sℕ
haveI' x : $e =Q Int.ofNat $n := ⟨⟩
return .isNat sℤ n' q(isNat_intOfNat $p)
theorem isNat_natAbs_pos : {n : ℤ} → {a : ℕ} → IsNat n a → IsNat n.natAbs a
| _, _, ⟨rfl⟩ => ⟨rfl⟩
theorem isNat_natAbs_neg : {n : ℤ} → {a : ℕ} → IsInt n (.negOfNat a) → IsNat n.natAbs a
| _, _, ⟨rfl⟩ => ⟨by simp⟩
/-- The `norm_num` extension which identifies the expression `Int.natAbs n` such that
`norm_num` successfully recognizes `n`. -/
@[norm_num Int.natAbs (_ : ℤ)] def evalIntNatAbs : NormNumExt where eval {u α} e := do
let .app (.const ``Int.natAbs _) (x : Q(ℤ)) ← whnfR e | failure
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℕ := ⟨⟩
haveI' : $e =Q Int.natAbs $x := ⟨⟩
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
match ← derive (u := .zero) x with
| .isNat _ a p => assumeInstancesCommute; return .isNat sℕ a q(isNat_natAbs_pos $p)
| .isNegNat _ a p => assumeInstancesCommute; return .isNat sℕ a q(isNat_natAbs_neg $p)
| _ => failure
/-! # Casts -/
theorem isNat_natCast {R} [AddMonoidWithOne R] (n m : ℕ) :
IsNat n m → IsNat (n : R) m := by rintro ⟨⟨⟩⟩; exact ⟨rfl⟩
/-- The `norm_num` extension which identifies an expression `Nat.cast n`, returning `n`. -/
@[norm_num Nat.cast _, NatCast.natCast _] def evalNatCast : NormNumExt where eval {u α} e := do
let sα ← inferAddMonoidWithOne α
let .app n (a : Q(ℕ)) ← whnfR e | failure
guard <|← withNewMCtxDepth <| isDefEq n q(Nat.cast (R := $α))
let ⟨na, pa⟩ ← deriveNat a q(instAddMonoidWithOneNat)
haveI' : $e =Q $a := ⟨⟩
return .isNat sα na q(isNat_natCast $a $na $pa)
theorem isNat_intCast {R} [Ring R] (n : ℤ) (m : ℕ) :
IsNat n m → IsNat (n : R) m := by rintro ⟨⟨⟩⟩; exact ⟨by simp⟩
| Mathlib/Tactic/NormNum/Basic.lean | 119 | 120 | theorem isintCast {R} [Ring R] (n m : ℤ) :
IsInt n m → IsInt (n : R) m := by | rintro ⟨⟨⟩⟩; exact ⟨rfl⟩ |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Moritz Doll
-/
import Mathlib.Algebra.GroupWithZero.Action.Opposite
import Mathlib.LinearAlgebra.Finsupp.VectorSpace
import Mathlib.LinearAlgebra.Matrix.Basis
import Mathlib.LinearAlgebra.Matrix.Nondegenerate
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv
import Mathlib.LinearAlgebra.SesquilinearForm
import Mathlib.LinearAlgebra.Basis.Bilinear
/-!
# Sesquilinear form
This file defines the conversion between sesquilinear maps and matrices.
## Main definitions
* `Matrix.toLinearMap₂` given a basis define a bilinear map
* `Matrix.toLinearMap₂'` define the bilinear map on `n → R`
* `LinearMap.toMatrix₂`: calculate the matrix coefficients of a bilinear map
* `LinearMap.toMatrix₂'`: calculate the matrix coefficients of a bilinear map on `n → R`
## TODO
At the moment this is quite a literal port from `Matrix.BilinearForm`. Everything should be
generalized to fully semibilinear forms.
## Tags
Sesquilinear form, Sesquilinear map, matrix, basis
-/
variable {R R₁ S₁ R₂ S₂ M₁ M₂ M₁' M₂' N₂ n m n' m' ι : Type*}
open Finset LinearMap Matrix
open Matrix
open scoped RightActions
section AuxToLinearMap
variable [Semiring R₁] [Semiring S₁] [Semiring R₂] [Semiring S₂] [AddCommMonoid N₂]
[Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₂ S₁ N₂]
variable [Fintype n] [Fintype m]
variable (σ₁ : R₁ →+* S₁) (σ₂ : R₂ →+* S₂)
/-- The map from `Matrix n n R` to bilinear maps on `n → R`.
This is an auxiliary definition for the equivalence `Matrix.toLinearMap₂'`. -/
def Matrix.toLinearMap₂'Aux (f : Matrix n m N₂) : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂ :=
-- porting note: we don't seem to have `∑ i j` as valid notation yet
mk₂'ₛₗ σ₁ σ₂ (fun (v : n → R₁) (w : m → R₂) => ∑ i, ∑ j, σ₂ (w j) • σ₁ (v i) • f i j)
(fun _ _ _ => by simp only [Pi.add_apply, map_add, smul_add, sum_add_distrib, add_smul])
(fun c v w => by
simp only [Pi.smul_apply, smul_sum, smul_eq_mul, σ₁.map_mul, ← smul_comm _ (σ₁ c),
MulAction.mul_smul])
(fun _ _ _ => by simp only [Pi.add_apply, map_add, add_smul, smul_add, sum_add_distrib])
(fun _ v w => by
simp only [Pi.smul_apply, smul_eq_mul, map_mul, MulAction.mul_smul, smul_sum])
variable [DecidableEq n] [DecidableEq m]
theorem Matrix.toLinearMap₂'Aux_single (f : Matrix n m N₂) (i : n) (j : m) :
f.toLinearMap₂'Aux σ₁ σ₂ (Pi.single i 1) (Pi.single j 1) = f i j := by
rw [Matrix.toLinearMap₂'Aux, mk₂'ₛₗ_apply]
have : (∑ i', ∑ j', (if i = i' then (1 : S₁) else (0 : S₁)) •
(if j = j' then (1 : S₂) else (0 : S₂)) • f i' j') =
f i j := by
simp_rw [← Finset.smul_sum]
simp only [op_smul_eq_smul, ite_smul, one_smul, zero_smul, sum_ite_eq, mem_univ, ↓reduceIte]
rw [← this]
exact Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by aesop
end AuxToLinearMap
section AuxToMatrix
section CommSemiring
variable [CommSemiring R] [Semiring R₁] [Semiring S₁] [Semiring R₂] [Semiring S₂]
variable [AddCommMonoid M₁] [Module R₁ M₁] [AddCommMonoid M₂] [Module R₂ M₂] [AddCommMonoid N₂]
[Module R N₂] [Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₁ R N₂] [SMulCommClass S₂ R N₂]
[SMulCommClass S₂ S₁ N₂]
variable {σ₁ : R₁ →+* S₁} {σ₂ : R₂ →+* S₂}
variable (R)
/-- The linear map from sesquilinear maps to `Matrix n m N₂` given an `n`-indexed basis for `M₁`
and an `m`-indexed basis for `M₂`.
This is an auxiliary definition for the equivalence `Matrix.toLinearMapₛₗ₂'`. -/
def LinearMap.toMatrix₂Aux (b₁ : n → M₁) (b₂ : m → M₂) :
(M₁ →ₛₗ[σ₁] M₂ →ₛₗ[σ₂] N₂) →ₗ[R] Matrix n m N₂ where
toFun f := of fun i j => f (b₁ i) (b₂ j)
map_add' _f _g := rfl
map_smul' _f _g := rfl
@[simp]
theorem LinearMap.toMatrix₂Aux_apply (f : M₁ →ₛₗ[σ₁] M₂ →ₛₗ[σ₂] N₂) (b₁ : n → M₁) (b₂ : m → M₂)
(i : n) (j : m) : LinearMap.toMatrix₂Aux R b₁ b₂ f i j = f (b₁ i) (b₂ j) :=
rfl
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
theorem LinearMap.toLinearMap₂'Aux_toMatrix₂Aux (f : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) :
Matrix.toLinearMap₂'Aux σ₁ σ₂
(LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) f) =
f := by
refine ext_basis (Pi.basisFun R₁ n) (Pi.basisFun R₂ m) fun i j => ?_
simp_rw [Pi.basisFun_apply, Matrix.toLinearMap₂'Aux_single, LinearMap.toMatrix₂Aux_apply]
theorem Matrix.toMatrix₂Aux_toLinearMap₂'Aux (f : Matrix n m N₂) :
LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1)
(fun j => Pi.single j 1) (f.toLinearMap₂'Aux σ₁ σ₂) =
f := by
ext i j
simp_rw [LinearMap.toMatrix₂Aux_apply, Matrix.toLinearMap₂'Aux_single]
end CommSemiring
end AuxToMatrix
section ToMatrix'
/-! ### Bilinear maps over `n → R`
This section deals with the conversion between matrices and sesquilinear maps on `n → R`.
-/
variable [CommSemiring R] [AddCommMonoid N₂] [Module R N₂] [Semiring R₁] [Semiring R₂]
[Semiring S₁] [Semiring S₂] [Module S₁ N₂] [Module S₂ N₂]
[SMulCommClass S₁ R N₂] [SMulCommClass S₂ R N₂] [SMulCommClass S₂ S₁ N₂]
variable {σ₁ : R₁ →+* S₁} {σ₂ : R₂ →+* S₂}
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
variable (R)
/-- The linear equivalence between sesquilinear maps and `n × m` matrices -/
def LinearMap.toMatrixₛₗ₂' : ((n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) ≃ₗ[R] Matrix n m N₂ :=
{ LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) with
toFun := LinearMap.toMatrix₂Aux R _ _
invFun := Matrix.toLinearMap₂'Aux σ₁ σ₂
left_inv := LinearMap.toLinearMap₂'Aux_toMatrix₂Aux R
right_inv := Matrix.toMatrix₂Aux_toLinearMap₂'Aux R }
/-- The linear equivalence between bilinear maps and `n × m` matrices -/
def LinearMap.toMatrix₂' : ((n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) ≃ₗ[R] Matrix n m N₂ :=
LinearMap.toMatrixₛₗ₂' R
variable (σ₁ σ₂)
/-- The linear equivalence between `n × n` matrices and sesquilinear maps on `n → R` -/
def Matrix.toLinearMapₛₗ₂' : Matrix n m N₂ ≃ₗ[R] (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂ :=
(LinearMap.toMatrixₛₗ₂' R).symm
/-- The linear equivalence between `n × n` matrices and bilinear maps on `n → R` -/
def Matrix.toLinearMap₂' : Matrix n m N₂ ≃ₗ[R] (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂ :=
(LinearMap.toMatrix₂' R).symm
variable {R}
theorem Matrix.toLinearMapₛₗ₂'_aux_eq (M : Matrix n m N₂) :
Matrix.toLinearMap₂'Aux σ₁ σ₂ M = Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M :=
rfl
theorem Matrix.toLinearMapₛₗ₂'_apply (M : Matrix n m N₂) (x : n → R₁) (y : m → R₂) :
-- porting note: we don't seem to have `∑ i j` as valid notation yet
Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M x y = ∑ i, ∑ j, σ₁ (x i) • σ₂ (y j) • M i j := by
rw [toLinearMapₛₗ₂', toMatrixₛₗ₂', LinearEquiv.coe_symm_mk, toLinearMap₂'Aux, mk₂'ₛₗ_apply]
apply Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by
rw [smul_comm]
theorem Matrix.toLinearMap₂'_apply (M : Matrix n m N₂) (x : n → S₁) (y : m → S₂) :
-- porting note: we don't seem to have `∑ i j` as valid notation yet
Matrix.toLinearMap₂' R M x y = ∑ i, ∑ j, x i • y j • M i j :=
Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by
rw [RingHom.id_apply, RingHom.id_apply, smul_comm]
theorem Matrix.toLinearMap₂'_apply' {T : Type*} [CommSemiring T] (M : Matrix n m T) (v : n → T)
(w : m → T) : Matrix.toLinearMap₂' T M v w = dotProduct v (M *ᵥ w) := by
simp_rw [Matrix.toLinearMap₂'_apply, dotProduct, Matrix.mulVec, dotProduct]
refine Finset.sum_congr rfl fun _ _ => ?_
rw [Finset.mul_sum]
refine Finset.sum_congr rfl fun _ _ => ?_
rw [smul_eq_mul, smul_eq_mul, mul_comm (w _), ← mul_assoc]
@[simp]
theorem Matrix.toLinearMapₛₗ₂'_single (M : Matrix n m N₂) (i : n) (j : m) :
Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M (Pi.single i 1) (Pi.single j 1) = M i j :=
Matrix.toLinearMap₂'Aux_single σ₁ σ₂ M i j
@[simp]
theorem Matrix.toLinearMap₂'_single (M : Matrix n m N₂) (i : n) (j : m) :
Matrix.toLinearMap₂' R M (Pi.single i 1) (Pi.single j 1) = M i j :=
Matrix.toLinearMap₂'Aux_single _ _ M i j
@[simp]
theorem LinearMap.toMatrixₛₗ₂'_symm :
((LinearMap.toMatrixₛₗ₂' R).symm : Matrix n m N₂ ≃ₗ[R] _) = Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ :=
rfl
@[simp]
theorem Matrix.toLinearMapₛₗ₂'_symm :
((Matrix.toLinearMapₛₗ₂' R σ₁ σ₂).symm : _ ≃ₗ[R] Matrix n m N₂) = LinearMap.toMatrixₛₗ₂' R :=
(LinearMap.toMatrixₛₗ₂' R).symm_symm
@[simp]
theorem Matrix.toLinearMapₛₗ₂'_toMatrix' (B : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) :
Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ (LinearMap.toMatrixₛₗ₂' R B) = B :=
(Matrix.toLinearMapₛₗ₂' R σ₁ σ₂).apply_symm_apply B
@[simp]
theorem Matrix.toLinearMap₂'_toMatrix' (B : (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) :
Matrix.toLinearMap₂' R (LinearMap.toMatrix₂' R B) = B :=
(Matrix.toLinearMap₂' R).apply_symm_apply B
@[simp]
theorem LinearMap.toMatrix'_toLinearMapₛₗ₂' (M : Matrix n m N₂) :
LinearMap.toMatrixₛₗ₂' R (Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M) = M :=
(LinearMap.toMatrixₛₗ₂' R).apply_symm_apply M
@[simp]
theorem LinearMap.toMatrix'_toLinearMap₂' (M : Matrix n m N₂) :
LinearMap.toMatrix₂' R (Matrix.toLinearMap₂' R (S₁ := S₁) (S₂ := S₂) M) = M :=
(LinearMap.toMatrixₛₗ₂' R).apply_symm_apply M
@[simp]
theorem LinearMap.toMatrixₛₗ₂'_apply (B : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) (i : n) (j : m) :
LinearMap.toMatrixₛₗ₂' R B i j = B (Pi.single i 1) (Pi.single j 1) :=
rfl
@[simp]
theorem LinearMap.toMatrix₂'_apply (B : (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) (i : n) (j : m) :
LinearMap.toMatrix₂' R B i j = B (Pi.single i 1) (Pi.single j 1) :=
rfl
end ToMatrix'
section CommToMatrix'
-- TODO: Introduce matrix multiplication by matrices of scalars
variable {R : Type*} [CommSemiring R]
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
variable [Fintype n'] [Fintype m']
variable [DecidableEq n'] [DecidableEq m']
@[simp]
theorem LinearMap.toMatrix₂'_compl₁₂ (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (l : (n' → R) →ₗ[R] n → R)
(r : (m' → R) →ₗ[R] m → R) :
toMatrix₂' R (B.compl₁₂ l r) = (toMatrix' l)ᵀ * toMatrix₂' R B * toMatrix' r := by
ext i j
simp only [LinearMap.toMatrix₂'_apply, LinearMap.compl₁₂_apply, transpose_apply, Matrix.mul_apply,
LinearMap.toMatrix', LinearEquiv.coe_mk, sum_mul]
rw [sum_comm]
conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul (Pi.basisFun R n) (Pi.basisFun R m) (l _) (r _)]
rw [Finsupp.sum_fintype]
· apply sum_congr rfl
rintro i' -
rw [Finsupp.sum_fintype]
· apply sum_congr rfl
rintro j' -
simp only [smul_eq_mul, Pi.basisFun_repr, mul_assoc, mul_comm, mul_left_comm,
Pi.basisFun_apply, of_apply]
· intros
simp only [zero_smul, smul_zero]
· intros
simp only [zero_smul, Finsupp.sum_zero]
theorem LinearMap.toMatrix₂'_comp (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (f : (n' → R) →ₗ[R] n → R) :
toMatrix₂' R (B.comp f) = (toMatrix' f)ᵀ * toMatrix₂' R B := by
rw [← LinearMap.compl₂_id (B.comp f), ← LinearMap.compl₁₂]
simp
theorem LinearMap.toMatrix₂'_compl₂ (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (f : (m' → R) →ₗ[R] m → R) :
toMatrix₂' R (B.compl₂ f) = toMatrix₂' R B * toMatrix' f := by
rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂]
simp
theorem LinearMap.mul_toMatrix₂'_mul (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix n' n R)
(N : Matrix m m' R) :
M * toMatrix₂' R B * N = toMatrix₂' R (B.compl₁₂ (toLin' Mᵀ) (toLin' N)) := by
simp
theorem LinearMap.mul_toMatrix' (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix n' n R) :
M * toMatrix₂' R B = toMatrix₂' R (B.comp <| toLin' Mᵀ) := by
simp only [B.toMatrix₂'_comp, transpose_transpose, toMatrix'_toLin']
theorem LinearMap.toMatrix₂'_mul (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix m m' R) :
toMatrix₂' R B * M = toMatrix₂' R (B.compl₂ <| toLin' M) := by
simp only [B.toMatrix₂'_compl₂, toMatrix'_toLin']
theorem Matrix.toLinearMap₂'_comp (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) :
LinearMap.compl₁₂ (Matrix.toLinearMap₂' R M) (toLin' P) (toLin' Q) =
toLinearMap₂' R (Pᵀ * M * Q) :=
(LinearMap.toMatrix₂' R).injective (by simp)
end CommToMatrix'
section ToMatrix
/-! ### Bilinear maps over arbitrary vector spaces
This section deals with the conversion between matrices and bilinear maps on
a module with a fixed basis.
-/
variable [CommSemiring R]
variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] [AddCommMonoid N₂]
[Module R N₂]
variable [DecidableEq n] [Fintype n]
variable [DecidableEq m] [Fintype m]
section
variable (b₁ : Basis n R M₁) (b₂ : Basis m R M₂)
/-- `LinearMap.toMatrix₂ b₁ b₂` is the equivalence between `R`-bilinear maps on `M` and
`n`-by-`m` matrices with entries in `R`, if `b₁` and `b₂` are `R`-bases for `M₁` and `M₂`,
respectively. -/
noncomputable def LinearMap.toMatrix₂ : (M₁ →ₗ[R] M₂ →ₗ[R] N₂) ≃ₗ[R] Matrix n m N₂ :=
(b₁.equivFun.arrowCongr (b₂.equivFun.arrowCongr (LinearEquiv.refl R N₂))).trans
(LinearMap.toMatrix₂' R)
/-- `Matrix.toLinearMap₂ b₁ b₂` is the equivalence between `R`-bilinear maps on `M` and
`n`-by-`m` matrices with entries in `R`, if `b₁` and `b₂` are `R`-bases for `M₁` and `M₂`,
respectively; this is the reverse direction of `LinearMap.toMatrix₂ b₁ b₂`. -/
noncomputable def Matrix.toLinearMap₂ : Matrix n m N₂ ≃ₗ[R] M₁ →ₗ[R] M₂ →ₗ[R] N₂ :=
(LinearMap.toMatrix₂ b₁ b₂).symm
-- We make this and not `LinearMap.toMatrix₂` a `simp` lemma to avoid timeouts
@[simp]
theorem LinearMap.toMatrix₂_apply (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) (i : n) (j : m) :
LinearMap.toMatrix₂ b₁ b₂ B i j = B (b₁ i) (b₂ j) := by
simp only [toMatrix₂, LinearEquiv.trans_apply, toMatrix₂'_apply, LinearEquiv.arrowCongr_apply,
Basis.equivFun_symm_apply, Pi.single_apply, ite_smul, one_smul, zero_smul, sum_ite_eq',
mem_univ, ↓reduceIte, LinearEquiv.refl_apply]
@[simp]
theorem Matrix.toLinearMap₂_apply (M : Matrix n m N₂) (x : M₁) (y : M₂) :
Matrix.toLinearMap₂ b₁ b₂ M x y = ∑ i, ∑ j, b₁.repr x i • b₂.repr y j • M i j :=
Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ =>
smul_algebra_smul_comm ((RingHom.id R) ((Basis.equivFun b₁) x _))
((RingHom.id R) ((Basis.equivFun b₂) y _)) (M _ _)
-- Not a `simp` lemma since `LinearMap.toMatrix₂` needs an extra argument
theorem LinearMap.toMatrix₂Aux_eq (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) :
LinearMap.toMatrix₂Aux R b₁ b₂ B = LinearMap.toMatrix₂ b₁ b₂ B :=
Matrix.ext fun i j => by rw [LinearMap.toMatrix₂_apply, LinearMap.toMatrix₂Aux_apply]
@[simp]
theorem LinearMap.toMatrix₂_symm :
(LinearMap.toMatrix₂ b₁ b₂).symm = Matrix.toLinearMap₂ (N₂ := N₂) b₁ b₂ :=
rfl
@[simp]
theorem Matrix.toLinearMap₂_symm :
(Matrix.toLinearMap₂ b₁ b₂).symm = LinearMap.toMatrix₂ (N₂ := N₂) b₁ b₂ :=
(LinearMap.toMatrix₂ b₁ b₂).symm_symm
theorem Matrix.toLinearMap₂_basisFun :
Matrix.toLinearMap₂ (Pi.basisFun R n) (Pi.basisFun R m) =
Matrix.toLinearMap₂' R (N₂ := N₂) := by
ext M
simp only [coe_comp, coe_single, Function.comp_apply, toLinearMap₂_apply, Pi.basisFun_repr,
toLinearMap₂'_apply]
theorem LinearMap.toMatrix₂_basisFun :
LinearMap.toMatrix₂ (Pi.basisFun R n) (Pi.basisFun R m) =
LinearMap.toMatrix₂' R (N₂ := N₂) := by
ext B
rw [LinearMap.toMatrix₂_apply, LinearMap.toMatrix₂'_apply, Pi.basisFun_apply, Pi.basisFun_apply]
@[simp]
theorem Matrix.toLinearMap₂_toMatrix₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) :
Matrix.toLinearMap₂ b₁ b₂ (LinearMap.toMatrix₂ b₁ b₂ B) = B :=
(Matrix.toLinearMap₂ b₁ b₂).apply_symm_apply B
@[simp]
theorem LinearMap.toMatrix₂_toLinearMap₂ (M : Matrix n m N₂) :
LinearMap.toMatrix₂ b₁ b₂ (Matrix.toLinearMap₂ b₁ b₂ M) = M :=
(LinearMap.toMatrix₂ b₁ b₂).apply_symm_apply M
variable (b₁ : Basis n R M₁) (b₂ : Basis m R M₂)
variable [AddCommMonoid M₁'] [Module R M₁']
variable [AddCommMonoid M₂'] [Module R M₂']
variable (b₁' : Basis n' R M₁')
variable (b₂' : Basis m' R M₂')
variable [Fintype n'] [Fintype m']
variable [DecidableEq n'] [DecidableEq m']
-- Cannot be a `simp` lemma because `b₁` and `b₂` must be inferred.
theorem LinearMap.toMatrix₂_compl₁₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (l : M₁' →ₗ[R] M₁)
(r : M₂' →ₗ[R] M₂) :
LinearMap.toMatrix₂ b₁' b₂' (B.compl₁₂ l r) =
(toMatrix b₁' b₁ l)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B * toMatrix b₂' b₂ r := by
ext i j
simp only [LinearMap.toMatrix₂_apply, compl₁₂_apply, transpose_apply, Matrix.mul_apply,
LinearMap.toMatrix_apply, LinearEquiv.coe_mk, sum_mul]
rw [sum_comm]
conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul b₁ b₂]
rw [Finsupp.sum_fintype]
· apply sum_congr rfl
rintro i' -
rw [Finsupp.sum_fintype]
· apply sum_congr rfl
rintro j' -
simp only [smul_eq_mul, LinearMap.toMatrix_apply, Basis.equivFun_apply, mul_assoc, mul_comm,
mul_left_comm]
· intros
simp only [zero_smul, smul_zero]
· intros
simp only [zero_smul, Finsupp.sum_zero]
theorem LinearMap.toMatrix₂_comp (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (f : M₁' →ₗ[R] M₁) :
LinearMap.toMatrix₂ b₁' b₂ (B.comp f) =
(toMatrix b₁' b₁ f)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B := by
rw [← LinearMap.compl₂_id (B.comp f), ← LinearMap.compl₁₂, LinearMap.toMatrix₂_compl₁₂ b₁ b₂]
simp
theorem LinearMap.toMatrix₂_compl₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (f : M₂' →ₗ[R] M₂) :
LinearMap.toMatrix₂ b₁ b₂' (B.compl₂ f) =
LinearMap.toMatrix₂ b₁ b₂ B * toMatrix b₂' b₂ f := by
rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂, LinearMap.toMatrix₂_compl₁₂ b₁ b₂]
simp
@[simp]
theorem LinearMap.toMatrix₂_mul_basis_toMatrix (c₁ : Basis n' R M₁) (c₂ : Basis m' R M₂)
(B : M₁ →ₗ[R] M₂ →ₗ[R] R) :
(b₁.toMatrix c₁)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B * b₂.toMatrix c₂ =
LinearMap.toMatrix₂ c₁ c₂ B := by
simp_rw [← LinearMap.toMatrix_id_eq_basis_toMatrix]
rw [← LinearMap.toMatrix₂_compl₁₂, LinearMap.compl₁₂_id_id]
theorem LinearMap.mul_toMatrix₂_mul (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix n' n R)
(N : Matrix m m' R) :
M * LinearMap.toMatrix₂ b₁ b₂ B * N =
LinearMap.toMatrix₂ b₁' b₂' (B.compl₁₂ (toLin b₁' b₁ Mᵀ) (toLin b₂' b₂ N)) := by
simp_rw [LinearMap.toMatrix₂_compl₁₂ b₁ b₂, toMatrix_toLin, transpose_transpose]
theorem LinearMap.mul_toMatrix₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix n' n R) :
M * LinearMap.toMatrix₂ b₁ b₂ B =
LinearMap.toMatrix₂ b₁' b₂ (B.comp (toLin b₁' b₁ Mᵀ)) := by
rw [LinearMap.toMatrix₂_comp b₁, toMatrix_toLin, transpose_transpose]
theorem LinearMap.toMatrix₂_mul (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix m m' R) :
LinearMap.toMatrix₂ b₁ b₂ B * M =
LinearMap.toMatrix₂ b₁ b₂' (B.compl₂ (toLin b₂' b₂ M)) := by
rw [LinearMap.toMatrix₂_compl₂ b₁ b₂, toMatrix_toLin]
theorem Matrix.toLinearMap₂_compl₁₂ (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) :
(Matrix.toLinearMap₂ b₁ b₂ M).compl₁₂ (toLin b₁' b₁ P) (toLin b₂' b₂ Q) =
Matrix.toLinearMap₂ b₁' b₂' (Pᵀ * M * Q) :=
(LinearMap.toMatrix₂ b₁' b₂').injective
(by
simp only [LinearMap.toMatrix₂_compl₁₂ b₁ b₂, LinearMap.toMatrix₂_toLinearMap₂,
toMatrix_toLin])
end
end ToMatrix
/-! ### Adjoint pairs -/
section MatrixAdjoints
open Matrix
variable [CommRing R]
variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂]
variable [Fintype n] [Fintype n']
variable (b₁ : Basis n R M₁) (b₂ : Basis n' R M₂)
variable (J J₂ : Matrix n n R) (J' : Matrix n' n' R)
variable (A : Matrix n' n R) (A' : Matrix n n' R)
variable (A₁ A₂ : Matrix n n R)
/-- The condition for the matrices `A`, `A'` to be an adjoint pair with respect to the square
matrices `J`, `J₃`. -/
def Matrix.IsAdjointPair :=
Aᵀ * J' = J * A'
/-- The condition for a square matrix `A` to be self-adjoint with respect to the square matrix
`J`. -/
def Matrix.IsSelfAdjoint :=
Matrix.IsAdjointPair J J A₁ A₁
/-- The condition for a square matrix `A` to be skew-adjoint with respect to the square matrix
`J`. -/
def Matrix.IsSkewAdjoint :=
Matrix.IsAdjointPair J J A₁ (-A₁)
variable [DecidableEq n] [DecidableEq n']
@[simp]
theorem isAdjointPair_toLinearMap₂' :
LinearMap.IsAdjointPair (Matrix.toLinearMap₂' R J) (Matrix.toLinearMap₂' R J')
(Matrix.toLin' A) (Matrix.toLin' A') ↔
Matrix.IsAdjointPair J J' A A' := by
rw [isAdjointPair_iff_comp_eq_compl₂]
have h :
∀ B B' : (n → R) →ₗ[R] (n' → R) →ₗ[R] R,
B = B' ↔ LinearMap.toMatrix₂' R B = LinearMap.toMatrix₂' R B' := by
intro B B'
constructor <;> intro h
· rw [h]
· exact (LinearMap.toMatrix₂' R).injective h
simp_rw [h, LinearMap.toMatrix₂'_comp, LinearMap.toMatrix₂'_compl₂,
LinearMap.toMatrix'_toLin', LinearMap.toMatrix'_toLinearMap₂']
rfl
@[simp]
theorem isAdjointPair_toLinearMap₂ :
LinearMap.IsAdjointPair (Matrix.toLinearMap₂ b₁ b₁ J)
(Matrix.toLinearMap₂ b₂ b₂ J') (Matrix.toLin b₁ b₂ A) (Matrix.toLin b₂ b₁ A') ↔
Matrix.IsAdjointPair J J' A A' := by
rw [isAdjointPair_iff_comp_eq_compl₂]
have h :
∀ B B' : M₁ →ₗ[R] M₂ →ₗ[R] R,
B = B' ↔ LinearMap.toMatrix₂ b₁ b₂ B = LinearMap.toMatrix₂ b₁ b₂ B' := by
intro B B'
constructor <;> intro h
· rw [h]
· exact (LinearMap.toMatrix₂ b₁ b₂).injective h
simp_rw [h, LinearMap.toMatrix₂_comp b₂ b₂, LinearMap.toMatrix₂_compl₂ b₁ b₁,
LinearMap.toMatrix_toLin, LinearMap.toMatrix₂_toLinearMap₂]
rfl
theorem Matrix.isAdjointPair_equiv (P : Matrix n n R) (h : IsUnit P) :
(Pᵀ * J * P).IsAdjointPair (Pᵀ * J * P) A₁ A₂ ↔
J.IsAdjointPair J (P * A₁ * P⁻¹) (P * A₂ * P⁻¹) := by
have h' : IsUnit P.det := P.isUnit_iff_isUnit_det.mp h
let u := P.nonsingInvUnit h'
let v := Pᵀ.nonsingInvUnit (P.isUnit_det_transpose h')
let x := A₁ᵀ * Pᵀ * J
let y := J * P * A₂
suffices x * u = v * y ↔ v⁻¹ * x = y * u⁻¹ by
dsimp only [Matrix.IsAdjointPair]
simp only [Matrix.transpose_mul]
simp only [← mul_assoc, P.transpose_nonsing_inv]
convert this using 2
· rw [mul_assoc, mul_assoc, ← mul_assoc J]
rfl
· rw [mul_assoc, mul_assoc, ← mul_assoc _ _ J]
rfl
rw [Units.eq_mul_inv_iff_mul_eq]
conv_rhs => rw [mul_assoc]
rw [v.inv_mul_eq_iff_eq_mul]
/-- The submodule of pair-self-adjoint matrices with respect to bilinear forms corresponding to
given matrices `J`, `J₂`. -/
def pairSelfAdjointMatricesSubmodule : Submodule R (Matrix n n R) :=
(isPairSelfAdjointSubmodule (Matrix.toLinearMap₂' R J)
(Matrix.toLinearMap₂' R J₂)).map
((LinearMap.toMatrix' : ((n → R) →ₗ[R] n → R) ≃ₗ[R] Matrix n n R) :
((n → R) →ₗ[R] n → R) →ₗ[R] Matrix n n R)
@[simp]
theorem mem_pairSelfAdjointMatricesSubmodule :
A₁ ∈ pairSelfAdjointMatricesSubmodule J J₂ ↔ Matrix.IsAdjointPair J J₂ A₁ A₁ := by
simp only [pairSelfAdjointMatricesSubmodule, LinearEquiv.coe_coe, LinearMap.toMatrix'_apply,
Submodule.mem_map, mem_isPairSelfAdjointSubmodule]
constructor
· rintro ⟨f, hf, hA⟩
have hf' : f = toLin' A₁ := by rw [← hA, Matrix.toLin'_toMatrix']
rw [hf'] at hf
rw [← isAdjointPair_toLinearMap₂']
exact hf
· intro h
refine ⟨toLin' A₁, ?_, LinearMap.toMatrix'_toLin' _⟩
exact (isAdjointPair_toLinearMap₂' _ _ _ _).mpr h
/-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def selfAdjointMatricesSubmodule : Submodule R (Matrix n n R) :=
pairSelfAdjointMatricesSubmodule J J
@[simp]
theorem mem_selfAdjointMatricesSubmodule :
A₁ ∈ selfAdjointMatricesSubmodule J ↔ J.IsSelfAdjoint A₁ := by
erw [mem_pairSelfAdjointMatricesSubmodule]
rfl
/-- The submodule of skew-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def skewAdjointMatricesSubmodule : Submodule R (Matrix n n R) :=
pairSelfAdjointMatricesSubmodule (-J) J
@[simp]
theorem mem_skewAdjointMatricesSubmodule :
A₁ ∈ skewAdjointMatricesSubmodule J ↔ J.IsSkewAdjoint A₁ := by
erw [mem_pairSelfAdjointMatricesSubmodule]
simp [Matrix.IsSkewAdjoint, Matrix.IsAdjointPair]
end MatrixAdjoints
namespace LinearMap
/-! ### Nondegenerate bilinear forms -/
section Det
open Matrix
variable [CommRing R₁] [AddCommMonoid M₁] [Module R₁ M₁]
variable [DecidableEq ι] [Fintype ι]
theorem _root_.Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂
{M : Matrix ι ι R₁} (b : Basis ι R₁ M₁) :
(Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔
(Matrix.toLinearMap₂ b b M).SeparatingLeft :=
(separatingLeft_congr_iff b.equivFun.symm b.equivFun.symm).symm
-- Lemmas transferring nondegeneracy between a matrix and its associated bilinear form
theorem _root_.Matrix.Nondegenerate.toLinearMap₂' {M : Matrix ι ι R₁} (h : M.Nondegenerate) :
(Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) := fun x hx =>
h.eq_zero_of_ortho fun y => by simpa only [toLinearMap₂'_apply'] using hx y
@[simp]
theorem _root_.Matrix.separatingLeft_toLinearMap₂'_iff {M : Matrix ι ι R₁} :
(Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔ M.Nondegenerate :=
⟨fun h v hv => h v fun w => (M.toLinearMap₂'_apply' _ _).trans <| hv w,
Matrix.Nondegenerate.toLinearMap₂'⟩
theorem _root_.Matrix.Nondegenerate.toLinearMap₂ {M : Matrix ι ι R₁} (h : M.Nondegenerate)
(b : Basis ι R₁ M₁) : (toLinearMap₂ b b M).SeparatingLeft :=
(Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂ b).mp h.toLinearMap₂'
@[simp]
theorem _root_.Matrix.separatingLeft_toLinearMap₂_iff {M : Matrix ι ι R₁} (b : Basis ι R₁ M₁) :
(toLinearMap₂ b b M).SeparatingLeft ↔ M.Nondegenerate := by
rw [← Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂,
Matrix.separatingLeft_toLinearMap₂'_iff]
-- Lemmas transferring nondegeneracy between a bilinear form and its associated matrix
@[simp]
theorem nondegenerate_toMatrix₂'_iff {B : (ι → R₁) →ₗ[R₁] (ι → R₁) →ₗ[R₁] R₁} :
(LinearMap.toMatrix₂' R₁ B).Nondegenerate ↔ B.SeparatingLeft :=
Matrix.separatingLeft_toLinearMap₂'_iff.symm.trans <|
(Matrix.toLinearMap₂'_toMatrix' (R := R₁) B).symm ▸ Iff.rfl
theorem SeparatingLeft.toMatrix₂' {B : (ι → R₁) →ₗ[R₁] (ι → R₁) →ₗ[R₁] R₁} (h : B.SeparatingLeft) :
(LinearMap.toMatrix₂' R₁ B).Nondegenerate :=
nondegenerate_toMatrix₂'_iff.mpr h
@[simp]
theorem nondegenerate_toMatrix_iff {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (b : Basis ι R₁ M₁) :
(toMatrix₂ b b B).Nondegenerate ↔ B.SeparatingLeft :=
(Matrix.separatingLeft_toLinearMap₂_iff b).symm.trans <|
(Matrix.toLinearMap₂_toMatrix₂ b b B).symm ▸ Iff.rfl
theorem SeparatingLeft.toMatrix₂ {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (h : B.SeparatingLeft)
(b : Basis ι R₁ M₁) : (toMatrix₂ b b B).Nondegenerate :=
(nondegenerate_toMatrix_iff b).mpr h
-- Some shorthands for combining the above with `Matrix.nondegenerate_of_det_ne_zero`
variable [IsDomain R₁]
theorem separatingLeft_toLinearMap₂'_iff_det_ne_zero {M : Matrix ι ι R₁} :
(Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔ M.det ≠ 0 := by
rw [Matrix.separatingLeft_toLinearMap₂'_iff, Matrix.nondegenerate_iff_det_ne_zero]
theorem separatingLeft_toLinearMap₂'_of_det_ne_zero' (M : Matrix ι ι R₁) (h : M.det ≠ 0) :
(Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) :=
separatingLeft_toLinearMap₂'_iff_det_ne_zero.mpr h
| Mathlib/LinearAlgebra/Matrix/SesquilinearForm.lean | 678 | 681 | theorem separatingLeft_iff_det_ne_zero {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (b : Basis ι R₁ M₁) :
B.SeparatingLeft ↔ (toMatrix₂ b b B).det ≠ 0 := by | rw [← Matrix.nondegenerate_iff_det_ne_zero, nondegenerate_toMatrix_iff] |
/-
Copyright (c) 2021 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Ines Wright, Joachim Breitner
-/
import Mathlib.GroupTheory.Solvable
import Mathlib.GroupTheory.Sylow
import Mathlib.Algebra.Group.Subgroup.Order
import Mathlib.GroupTheory.Commutator.Finite
/-!
# Nilpotent groups
An API for nilpotent groups, that is, groups for which the upper central series
reaches `⊤`.
## Main definitions
Recall that if `H K : Subgroup G` then `⁅H, K⁆ : Subgroup G` is the subgroup of `G` generated
by the commutators `hkh⁻¹k⁻¹`. Recall also Lean's conventions that `⊤` denotes the
subgroup `G` of `G`, and `⊥` denotes the trivial subgroup `{1}`.
* `upperCentralSeries G : ℕ → Subgroup G` : the upper central series of a group `G`.
This is an increasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊥` and
`H (n + 1) / H n` is the centre of `G / H n`.
* `lowerCentralSeries G : ℕ → Subgroup G` : the lower central series of a group `G`.
This is a decreasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊤` and
`H (n + 1) = ⁅H n, G⁆`.
* `IsNilpotent` : A group G is nilpotent if its upper central series reaches `⊤`, or
equivalently if its lower central series reaches `⊥`.
* `Group.nilpotencyClass` : the length of the upper central series of a nilpotent group.
* `IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop` and
* `IsDescendingCentralSeries (H : ℕ → Subgroup G) : Prop` : Note that in the literature
a "central series" for a group is usually defined to be a *finite* sequence of normal subgroups
`H 0`, `H 1`, ..., starting at `⊤`, finishing at `⊥`, and with each `H n / H (n + 1)`
central in `G / H (n + 1)`. In this formalisation it is convenient to have two weaker predicates
on an infinite sequence of subgroups `H n` of `G`: we say a sequence is a *descending central
series* if it starts at `G` and `⁅H n, ⊤⁆ ⊆ H (n + 1)` for all `n`. Note that this series
may not terminate at `⊥`, and the `H i` need not be normal. Similarly a sequence is an
*ascending central series* if `H 0 = ⊥` and `⁅H (n + 1), ⊤⁆ ⊆ H n` for all `n`, again with no
requirement that the series reaches `⊤` or that the `H i` are normal.
## Main theorems
`G` is *defined* to be nilpotent if the upper central series reaches `⊤`.
* `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central
series reaches `⊤`.
* `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central
series reaches `⊥`.
* `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `⊥`.
* The `Group.nilpotencyClass` can likewise be obtained from these equivalent
definitions, see `least_ascending_central_series_length_eq_nilpotencyClass`,
`least_descending_central_series_length_eq_nilpotencyClass` and
`lowerCentralSeries_length_eq_nilpotencyClass`.
* If `G` is nilpotent, then so are its subgroups, images, quotients and preimages.
Binary and finite products of nilpotent groups are nilpotent.
Infinite products are nilpotent if their nilpotent class is bounded.
Corresponding lemmas about the `Group.nilpotencyClass` are provided.
* The `Group.nilpotencyClass` of `G ⧸ center G` is given explicitly, and an induction principle
is derived from that.
* `IsNilpotent.to_isSolvable`: If `G` is nilpotent, it is solvable.
## Warning
A "central series" is usually defined to be a finite sequence of normal subgroups going
from `⊥` to `⊤` with the property that each subquotient is contained within the centre of
the associated quotient of `G`. This means that if `G` is not nilpotent, then
none of what we have called `upperCentralSeries G`, `lowerCentralSeries G` or
the sequences satisfying `IsAscendingCentralSeries` or `IsDescendingCentralSeries`
are actually central series. Note that the fact that the upper and lower central series
are not central series if `G` is not nilpotent is a standard abuse of notation.
-/
open Subgroup
section WithGroup
variable {G : Type*} [Group G] (H : Subgroup G) [Normal H]
/-- If `H` is a normal subgroup of `G`, then the set `{x : G | ∀ y : G, x*y*x⁻¹*y⁻¹ ∈ H}`
is a subgroup of `G` (because it is the preimage in `G` of the centre of the
quotient group `G/H`.)
-/
def upperCentralSeriesStep : Subgroup G where
carrier := { x : G | ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ H }
one_mem' y := by simp [Subgroup.one_mem]
mul_mem' {a b} ha hb y := by
convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1
group
inv_mem' {x} hx y := by
specialize hx y⁻¹
rw [mul_assoc, inv_inv] at hx ⊢
exact Subgroup.Normal.mem_comm inferInstance hx
theorem mem_upperCentralSeriesStep (x : G) :
x ∈ upperCentralSeriesStep H ↔ ∀ y, x * y * x⁻¹ * y⁻¹ ∈ H := Iff.rfl
open QuotientGroup
/-- The proof that `upperCentralSeriesStep H` is the preimage of the centre of `G/H` under
the canonical surjection. -/
theorem upperCentralSeriesStep_eq_comap_center :
upperCentralSeriesStep H = Subgroup.comap (mk' H) (center (G ⧸ H)) := by
ext
rw [mem_comap, mem_center_iff, forall_mk]
apply forall_congr'
intro y
rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem,
div_eq_mul_inv, mul_inv_rev, mul_assoc]
instance : Normal (upperCentralSeriesStep H) := by
rw [upperCentralSeriesStep_eq_comap_center]
infer_instance
variable (G)
/-- An auxiliary type-theoretic definition defining both the upper central series of
a group, and a proof that it is normal, all in one go. -/
def upperCentralSeriesAux : ℕ → Σ'H : Subgroup G, Normal H
| 0 => ⟨⊥, inferInstance⟩
| n + 1 =>
let un := upperCentralSeriesAux n
let _un_normal := un.2
⟨upperCentralSeriesStep un.1, inferInstance⟩
/-- `upperCentralSeries G n` is the `n`th term in the upper central series of `G`. -/
def upperCentralSeries (n : ℕ) : Subgroup G :=
(upperCentralSeriesAux G n).1
instance upperCentralSeries_normal (n : ℕ) : Normal (upperCentralSeries G n) :=
(upperCentralSeriesAux G n).2
@[simp]
theorem upperCentralSeries_zero : upperCentralSeries G 0 = ⊥ := rfl
@[simp]
theorem upperCentralSeries_one : upperCentralSeries G 1 = center G := by
ext
simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep,
Subgroup.mem_center_iff, mem_mk, mem_bot, Set.mem_setOf_eq]
exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm]
variable {G}
/-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such
that `⁅x,G⁆ ⊆ H n`. -/
theorem mem_upperCentralSeries_succ_iff {n : ℕ} {x : G} :
x ∈ upperCentralSeries G (n + 1) ↔ ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n :=
Iff.rfl
@[simp] lemma comap_upperCentralSeries {H : Type*} [Group H] (e : H ≃* G) :
∀ n, (upperCentralSeries G n).comap e = upperCentralSeries H n
| 0 => by simpa [MonoidHom.ker_eq_bot_iff] using e.injective
| n + 1 => by
ext
simp [mem_upperCentralSeries_succ_iff, ← comap_upperCentralSeries e n,
← e.toEquiv.forall_congr_right]
namespace Group
variable (G) in
-- `IsNilpotent` is already defined in the root namespace (for elements of rings).
-- TODO: Rename it to `IsNilpotentElement`?
/-- A group `G` is nilpotent if its upper central series is eventually `G`. -/
@[mk_iff]
class IsNilpotent (G : Type*) [Group G] : Prop where
nilpotent' : ∃ n : ℕ, upperCentralSeries G n = ⊤
lemma IsNilpotent.nilpotent (G : Type*) [Group G] [IsNilpotent G] :
∃ n : ℕ, upperCentralSeries G n = ⊤ := Group.IsNilpotent.nilpotent'
lemma isNilpotent_congr {H : Type*} [Group H] (e : G ≃* H) : IsNilpotent G ↔ IsNilpotent H := by
simp_rw [isNilpotent_iff]
refine exists_congr fun n ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· simp [← Subgroup.comap_top e.symm.toMonoidHom, ← h]
· simp [← Subgroup.comap_top e.toMonoidHom, ← h]
@[simp] lemma isNilpotent_top : IsNilpotent (⊤ : Subgroup G) ↔ IsNilpotent G :=
isNilpotent_congr Subgroup.topEquiv
variable (G) in
/-- A group `G` is virtually nilpotent if it has a nilpotent cofinite subgroup `N`. -/
def IsVirtuallyNilpotent : Prop := ∃ N : Subgroup G, IsNilpotent N ∧ FiniteIndex N
lemma IsNilpotent.isVirtuallyNilpotent (hG : IsNilpotent G) : IsVirtuallyNilpotent G :=
⟨⊤, by simpa, inferInstance⟩
end Group
open Group
/-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and
`⁅H (n + 1), G⁆ ⊆ H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/
def IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop :=
H 0 = ⊥ ∧ ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H n
/-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and
`⁅H n, G⁆ ⊆ H (n + 1)` for all `n`. Note that we do not require that `H n = {1}` for some `n`. -/
def IsDescendingCentralSeries (H : ℕ → Subgroup G) :=
H 0 = ⊤ ∧ ∀ (x : G) (n : ℕ), x ∈ H n → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H (n + 1)
/-- Any ascending central series for a group is bounded above by the upper central series. -/
theorem ascending_central_series_le_upper (H : ℕ → Subgroup G) (hH : IsAscendingCentralSeries H) :
∀ n : ℕ, H n ≤ upperCentralSeries G n
| 0 => hH.1.symm ▸ le_refl ⊥
| n + 1 => by
intro x hx
rw [mem_upperCentralSeries_succ_iff]
exact fun y => ascending_central_series_le_upper H hH n (hH.2 x n hx y)
variable (G)
/-- The upper central series of a group is an ascending central series. -/
theorem upperCentralSeries_isAscendingCentralSeries :
IsAscendingCentralSeries (upperCentralSeries G) :=
⟨rfl, fun _x _n h => h⟩
theorem upperCentralSeries_mono : Monotone (upperCentralSeries G) := by
refine monotone_nat_of_le_succ ?_
intro n x hx y
rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹]
exact mul_mem hx (Normal.conj_mem (upperCentralSeries_normal G n) x⁻¹ (inv_mem hx) y)
/-- A group `G` is nilpotent iff there exists an ascending central series which reaches `G` in
finitely many steps. -/
theorem nilpotent_iff_finite_ascending_central_series :
IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsAscendingCentralSeries H ∧ H n = ⊤ := by
constructor
· rintro ⟨n, nH⟩
exact ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩
· rintro ⟨n, H, hH, hn⟩
use n
rw [eq_top_iff, ← hn]
exact ascending_central_series_le_upper H hH n
theorem is_descending_rev_series_of_is_ascending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊤)
(hasc : IsAscendingCentralSeries H) : IsDescendingCentralSeries fun m : ℕ => H (n - m) := by
obtain ⟨h0, hH⟩ := hasc
refine ⟨hn, fun x m hx g => ?_⟩
dsimp at hx
by_cases hm : n ≤ m
· rw [tsub_eq_zero_of_le hm, h0, Subgroup.mem_bot] at hx
subst hx
rw [show (1 : G) * g * (1⁻¹ : G) * g⁻¹ = 1 by group]
exact Subgroup.one_mem _
· push_neg at hm
apply hH
convert hx using 1
rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right]
@[deprecated (since := "2024-12-25")]
alias is_decending_rev_series_of_is_ascending := is_descending_rev_series_of_is_ascending
theorem is_ascending_rev_series_of_is_descending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊥)
(hdesc : IsDescendingCentralSeries H) : IsAscendingCentralSeries fun m : ℕ => H (n - m) := by
obtain ⟨h0, hH⟩ := hdesc
refine ⟨hn, fun x m hx g => ?_⟩
dsimp only at hx ⊢
by_cases hm : n ≤ m
· have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm
rw [hnm, h0]
exact mem_top _
· push_neg at hm
convert hH x _ hx g using 1
rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right]
/-- A group `G` is nilpotent iff there exists a descending central series which reaches the
trivial group in a finite time. -/
theorem nilpotent_iff_finite_descending_central_series :
IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsDescendingCentralSeries H ∧ H n = ⊥ := by
rw [nilpotent_iff_finite_ascending_central_series]
constructor
· rintro ⟨n, H, hH, hn⟩
refine ⟨n, fun m => H (n - m), is_descending_rev_series_of_is_ascending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
· rintro ⟨n, H, hH, hn⟩
refine ⟨n, fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
/-- The lower central series of a group `G` is a sequence `H n` of subgroups of `G`, defined
by `H 0` is all of `G` and for `n≥1`, `H (n + 1) = ⁅H n, G⁆` -/
def lowerCentralSeries (G : Type*) [Group G] : ℕ → Subgroup G
| 0 => ⊤
| n + 1 => ⁅lowerCentralSeries G n, ⊤⁆
variable {G}
@[simp]
theorem lowerCentralSeries_zero : lowerCentralSeries G 0 = ⊤ := rfl
@[simp]
theorem lowerCentralSeries_one : lowerCentralSeries G 1 = commutator G := rfl
theorem mem_lowerCentralSeries_succ_iff (n : ℕ) (q : G) :
q ∈ lowerCentralSeries G (n + 1) ↔
q ∈ closure { x | ∃ p ∈ lowerCentralSeries G n,
∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := Iff.rfl
theorem lowerCentralSeries_succ (n : ℕ) :
lowerCentralSeries G (n + 1) =
closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } :=
rfl
instance lowerCentralSeries_normal (n : ℕ) : Normal (lowerCentralSeries G n) := by
induction' n with d hd
· exact (⊤ : Subgroup G).normal_of_characteristic
· exact @Subgroup.commutator_normal _ _ (lowerCentralSeries G d) ⊤ hd _
theorem lowerCentralSeries_antitone : Antitone (lowerCentralSeries G) := by
refine antitone_nat_of_succ_le fun n x hx => ?_
simp only [mem_lowerCentralSeries_succ_iff, exists_prop, mem_top, exists_true_left,
true_and] at hx
refine
closure_induction ?_ (Subgroup.one_mem _) (fun _ _ _ _ ↦ mul_mem) (fun _ _ ↦ inv_mem) hx
rintro y ⟨z, hz, a, ha⟩
rw [← ha, mul_assoc, mul_assoc, ← mul_assoc a z⁻¹ a⁻¹]
exact mul_mem hz (Normal.conj_mem (lowerCentralSeries_normal n) z⁻¹ (inv_mem hz) a)
/-- The lower central series of a group is a descending central series. -/
theorem lowerCentralSeries_isDescendingCentralSeries :
IsDescendingCentralSeries (lowerCentralSeries G) := by
constructor
· rfl
intro x n hxn g
exact commutator_mem_commutator hxn (mem_top g)
/-- Any descending central series for a group is bounded below by the lower central series. -/
theorem descending_central_series_ge_lower (H : ℕ → Subgroup G) (hH : IsDescendingCentralSeries H) :
∀ n : ℕ, lowerCentralSeries G n ≤ H n
| 0 => hH.1.symm ▸ le_refl ⊤
| n + 1 => commutator_le.mpr fun x hx q _ =>
hH.2 x n (descending_central_series_ge_lower H hH n hx) q
/-- A group is nilpotent if and only if its lower central series eventually reaches
the trivial subgroup. -/
theorem nilpotent_iff_lowerCentralSeries : IsNilpotent G ↔ ∃ n, lowerCentralSeries G n = ⊥ := by
rw [nilpotent_iff_finite_descending_central_series]
constructor
· rintro ⟨n, H, ⟨h0, hs⟩, hn⟩
use n
rw [eq_bot_iff, ← hn]
exact descending_central_series_ge_lower H ⟨h0, hs⟩ n
· rintro ⟨n, hn⟩
exact ⟨n, lowerCentralSeries G, lowerCentralSeries_isDescendingCentralSeries, hn⟩
section Classical
variable [hG : IsNilpotent G]
variable (G) in
open scoped Classical in
/-- The nilpotency class of a nilpotent group is the smallest natural `n` such that
the `n`'th term of the upper central series is `G`. -/
noncomputable def Group.nilpotencyClass : ℕ := Nat.find (IsNilpotent.nilpotent G)
open scoped Classical in
@[simp]
theorem upperCentralSeries_nilpotencyClass : upperCentralSeries G (Group.nilpotencyClass G) = ⊤ :=
Nat.find_spec (IsNilpotent.nilpotent G)
theorem upperCentralSeries_eq_top_iff_nilpotencyClass_le {n : ℕ} :
upperCentralSeries G n = ⊤ ↔ Group.nilpotencyClass G ≤ n := by
classical
constructor
· intro h
exact Nat.find_le h
· intro h
rw [eq_top_iff, ← upperCentralSeries_nilpotencyClass]
exact upperCentralSeries_mono _ h
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which an ascending
central series reaches `G` in its `n`'th term. -/
theorem least_ascending_central_series_length_eq_nilpotencyClass :
Nat.find ((nilpotent_iff_finite_ascending_central_series G).mp hG) =
Group.nilpotencyClass G := by
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· intro n hn
exact ⟨upperCentralSeries G, upperCentralSeries_isAscendingCentralSeries G, hn⟩
· rintro n ⟨H, ⟨hH, hn⟩⟩
rw [← top_le_iff, ← hn]
exact ascending_central_series_le_upper H hH n
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which the descending
central series reaches `⊥` in its `n`'th term. -/
theorem least_descending_central_series_length_eq_nilpotencyClass :
Nat.find ((nilpotent_iff_finite_descending_central_series G).mp hG) =
Group.nilpotencyClass G := by
rw [← least_ascending_central_series_length_eq_nilpotencyClass]
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· rintro n ⟨H, ⟨hH, hn⟩⟩
refine ⟨fun m => H (n - m), is_descending_rev_series_of_is_ascending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
· rintro n ⟨H, ⟨hH, hn⟩⟩
refine ⟨fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the length of the lower central series. -/
theorem lowerCentralSeries_length_eq_nilpotencyClass :
Nat.find (nilpotent_iff_lowerCentralSeries.mp hG) = Group.nilpotencyClass (G := G) := by
rw [← least_descending_central_series_length_eq_nilpotencyClass]
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· rintro n ⟨H, ⟨hH, hn⟩⟩
rw [← le_bot_iff, ← hn]
exact descending_central_series_ge_lower H hH n
· rintro n h
exact ⟨lowerCentralSeries G, ⟨lowerCentralSeries_isDescendingCentralSeries, h⟩⟩
@[simp]
theorem lowerCentralSeries_nilpotencyClass :
lowerCentralSeries G (Group.nilpotencyClass G) = ⊥ := by
classical
rw [← lowerCentralSeries_length_eq_nilpotencyClass]
exact Nat.find_spec (nilpotent_iff_lowerCentralSeries.mp hG)
theorem lowerCentralSeries_eq_bot_iff_nilpotencyClass_le {n : ℕ} :
lowerCentralSeries G n = ⊥ ↔ Group.nilpotencyClass G ≤ n := by
classical
constructor
· intro h
rw [← lowerCentralSeries_length_eq_nilpotencyClass]
exact Nat.find_le h
· intro h
rw [eq_bot_iff, ← lowerCentralSeries_nilpotencyClass]
exact lowerCentralSeries_antitone h
end Classical
theorem lowerCentralSeries_map_subtype_le (H : Subgroup G) (n : ℕ) :
(lowerCentralSeries H n).map H.subtype ≤ lowerCentralSeries G n := by
induction' n with d hd
· simp
· rw [lowerCentralSeries_succ, lowerCentralSeries_succ, MonoidHom.map_closure]
apply Subgroup.closure_mono
rintro x1 ⟨x2, ⟨x3, hx3, x4, _hx4, rfl⟩, rfl⟩
exact ⟨x3, hd (mem_map.mpr ⟨x3, hx3, rfl⟩), x4, by simp⟩
/-- A subgroup of a nilpotent group is nilpotent -/
instance Subgroup.isNilpotent (H : Subgroup G) [hG : IsNilpotent G] : IsNilpotent H := by
rw [nilpotent_iff_lowerCentralSeries] at *
rcases hG with ⟨n, hG⟩
use n
have := lowerCentralSeries_map_subtype_le H n
simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this
exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩)
/-- The nilpotency class of a subgroup is less or equal to the nilpotency class of the group -/
theorem Subgroup.nilpotencyClass_le (H : Subgroup G) [hG : IsNilpotent G] :
Group.nilpotencyClass H ≤ Group.nilpotencyClass G := by
repeat rw [← lowerCentralSeries_length_eq_nilpotencyClass]
classical apply Nat.find_mono
intro n hG
have := lowerCentralSeries_map_subtype_le H n
simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this
exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩)
instance (priority := 100) Group.isNilpotent_of_subsingleton [Subsingleton G] : IsNilpotent G :=
nilpotent_iff_lowerCentralSeries.2 ⟨0, Subsingleton.elim ⊤ ⊥⟩
theorem upperCentralSeries.map {H : Type*} [Group H] {f : G →* H} (h : Function.Surjective f)
(n : ℕ) : Subgroup.map f (upperCentralSeries G n) ≤ upperCentralSeries H n := by
induction' n with d hd
· simp
· rintro _ ⟨x, hx : x ∈ upperCentralSeries G d.succ, rfl⟩ y'
rcases h y' with ⟨y, rfl⟩
simpa using hd (mem_map_of_mem f (hx y))
theorem lowerCentralSeries.map {H : Type*} [Group H] (f : G →* H) (n : ℕ) :
Subgroup.map f (lowerCentralSeries G n) ≤ lowerCentralSeries H n := by
induction' n with d hd
· simp
· rintro a ⟨x, hx : x ∈ lowerCentralSeries G d.succ, rfl⟩
refine closure_induction (hx := hx) ?_ (by simp [f.map_one, Subgroup.one_mem _])
(fun y z _ _ hy hz => by simp [MonoidHom.map_mul, Subgroup.mul_mem _ hy hz]) (fun y _ hy => by
rw [f.map_inv]; exact Subgroup.inv_mem _ hy)
rintro a ⟨y, hy, z, ⟨-, rfl⟩⟩
apply mem_closure.mpr
exact fun K hK => hK ⟨f y, hd (mem_map_of_mem f hy), by simp [commutatorElement_def]⟩
theorem lowerCentralSeries_succ_eq_bot {n : ℕ} (h : lowerCentralSeries G n ≤ center G) :
lowerCentralSeries G (n + 1) = ⊥ := by
rw [lowerCentralSeries_succ, closure_eq_bot_iff, Set.subset_singleton_iff]
rintro x ⟨y, hy1, z, ⟨⟩, rfl⟩
rw [mul_assoc, ← mul_inv_rev, mul_inv_eq_one, eq_comm]
exact mem_center_iff.mp (h hy1) z
/-- The preimage of a nilpotent group is nilpotent if the kernel of the homomorphism is contained
in the center -/
| Mathlib/GroupTheory/Nilpotent.lean | 504 | 509 | theorem isNilpotent_of_ker_le_center {H : Type*} [Group H] (f : G →* H) (hf1 : f.ker ≤ center G)
(hH : IsNilpotent H) : IsNilpotent G := by | rw [nilpotent_iff_lowerCentralSeries] at *
rcases hH with ⟨n, hn⟩
use n + 1
refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1) |
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.Complex.Basic
import Mathlib.Analysis.InnerProductSpace.Defs
import Mathlib.GroupTheory.MonoidLocalization.Basic
/-!
# Properties of inner product spaces
This file proves many basic properties of inner product spaces (real or complex).
## Main results
- `inner_mul_inner_self_le`: the Cauchy-Schwartz inequality (one of many variants).
- `norm_inner_eq_norm_iff`: the equality criteion in the Cauchy-Schwartz inequality (also in many
variants).
- `inner_eq_sum_norm_sq_div_four`: the polarization identity.
## Tags
inner product space, Hilbert space, norm
-/
noncomputable section
open RCLike Real Filter Topology ComplexConjugate Finsupp
open LinearMap (BilinForm)
variable {𝕜 E F : Type*} [RCLike 𝕜]
section BasicProperties_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local postfix:90 "†" => starRingEnd _
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_conj_symm (x y : E) : ⟪y, x⟫† = ⟪x, y⟫ :=
InnerProductSpace.conj_inner_symm _ _
theorem real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ :=
@inner_conj_symm ℝ _ _ _ _ x y
theorem inner_eq_zero_symm {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 := by
rw [← inner_conj_symm]
exact star_eq_zero
@[simp]
theorem inner_self_im (x : E) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub]; simp
theorem inner_add_left (x y z : E) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ :=
InnerProductSpace.add_left _ _ _
theorem inner_add_right (x y z : E) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by
rw [← inner_conj_symm, inner_add_left, RingHom.map_add]
simp only [inner_conj_symm]
theorem inner_re_symm (x y : E) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re]
theorem inner_im_symm (x y : E) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im]
section Algebra
variable {𝕝 : Type*} [CommSemiring 𝕝] [StarRing 𝕝] [Algebra 𝕝 𝕜] [Module 𝕝 E]
[IsScalarTower 𝕝 𝕜 E] [StarModule 𝕝 𝕜]
/-- See `inner_smul_left` for the common special when `𝕜 = 𝕝`. -/
lemma inner_smul_left_eq_star_smul (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r† • ⟪x, y⟫ := by
rw [← algebraMap_smul 𝕜 r, InnerProductSpace.smul_left, starRingEnd_apply, starRingEnd_apply,
← algebraMap_star_comm, ← smul_eq_mul, algebraMap_smul]
/-- Special case of `inner_smul_left_eq_star_smul` when the acting ring has a trivial star
(eg `ℕ`, `ℤ`, `ℚ≥0`, `ℚ`, `ℝ`). -/
lemma inner_smul_left_eq_smul [TrivialStar 𝕝] (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_left_eq_star_smul, starRingEnd_apply, star_trivial]
/-- See `inner_smul_right` for the common special when `𝕜 = 𝕝`. -/
lemma inner_smul_right_eq_smul (x y : E) (r : 𝕝) : ⟪x, r • y⟫ = r • ⟪x, y⟫ := by
rw [← inner_conj_symm, inner_smul_left_eq_star_smul, starRingEnd_apply, starRingEnd_apply,
star_smul, star_star, ← starRingEnd_apply, inner_conj_symm]
end Algebra
/-- See `inner_smul_left_eq_star_smul` for the case of a general algebra action. -/
theorem inner_smul_left (x y : E) (r : 𝕜) : ⟪r • x, y⟫ = r† * ⟪x, y⟫ :=
inner_smul_left_eq_star_smul ..
theorem real_inner_smul_left (x y : F) (r : ℝ) : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ :=
inner_smul_left _ _ _
theorem inner_smul_real_left (x y : E) (r : ℝ) : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_left, conj_ofReal, Algebra.smul_def]
/-- See `inner_smul_right_eq_smul` for the case of a general algebra action. -/
theorem inner_smul_right (x y : E) (r : 𝕜) : ⟪x, r • y⟫ = r * ⟪x, y⟫ :=
inner_smul_right_eq_smul ..
theorem real_inner_smul_right (x y : F) (r : ℝ) : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ :=
inner_smul_right _ _ _
theorem inner_smul_real_right (x y : E) (r : ℝ) : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_right, Algebra.smul_def]
/-- The inner product as a sesquilinear form.
Note that in the case `𝕜 = ℝ` this is a bilinear form. -/
@[simps!]
def sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 :=
LinearMap.mk₂'ₛₗ (RingHom.id 𝕜) (starRingEnd _) (fun x y => ⟪y, x⟫)
(fun _x _y _z => inner_add_right _ _ _) (fun _r _x _y => inner_smul_right _ _ _)
(fun _x _y _z => inner_add_left _ _ _) fun _r _x _y => inner_smul_left _ _ _
/-- The real inner product as a bilinear form.
Note that unlike `sesqFormOfInner`, this does not reverse the order of the arguments. -/
@[simps!]
def bilinFormOfRealInner : BilinForm ℝ F := sesqFormOfInner.flip
/-- An inner product with a sum on the left. -/
theorem sum_inner {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) :
⟪∑ i ∈ s, f i, x⟫ = ∑ i ∈ s, ⟪f i, x⟫ :=
map_sum (sesqFormOfInner (𝕜 := 𝕜) (E := E) x) _ _
/-- An inner product with a sum on the right. -/
theorem inner_sum {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) :
⟪x, ∑ i ∈ s, f i⟫ = ∑ i ∈ s, ⟪x, f i⟫ :=
map_sum (LinearMap.flip sesqFormOfInner x) _ _
/-- An inner product with a sum on the left, `Finsupp` version. -/
protected theorem Finsupp.sum_inner {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪l.sum fun (i : ι) (a : 𝕜) => a • v i, x⟫ = l.sum fun (i : ι) (a : 𝕜) => conj a • ⟪v i, x⟫ := by
convert sum_inner (𝕜 := 𝕜) l.support (fun a => l a • v a) x
simp only [inner_smul_left, Finsupp.sum, smul_eq_mul]
/-- An inner product with a sum on the right, `Finsupp` version. -/
protected theorem Finsupp.inner_sum {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪x, l.sum fun (i : ι) (a : 𝕜) => a • v i⟫ = l.sum fun (i : ι) (a : 𝕜) => a • ⟪x, v i⟫ := by
convert inner_sum (𝕜 := 𝕜) l.support (fun a => l a • v a) x
simp only [inner_smul_right, Finsupp.sum, smul_eq_mul]
protected theorem DFinsupp.sum_inner {ι : Type*} [DecidableEq ι] {α : ι → Type*}
[∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)
(l : Π₀ i, α i) (x : E) : ⟪l.sum f, x⟫ = l.sum fun i a => ⟪f i a, x⟫ := by
simp +contextual only [DFinsupp.sum, sum_inner, smul_eq_mul]
protected theorem DFinsupp.inner_sum {ι : Type*} [DecidableEq ι] {α : ι → Type*}
[∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)
(l : Π₀ i, α i) (x : E) : ⟪x, l.sum f⟫ = l.sum fun i a => ⟪x, f i a⟫ := by
simp +contextual only [DFinsupp.sum, inner_sum, smul_eq_mul]
@[simp]
theorem inner_zero_left (x : E) : ⟪0, x⟫ = 0 := by
rw [← zero_smul 𝕜 (0 : E), inner_smul_left, RingHom.map_zero, zero_mul]
theorem inner_re_zero_left (x : E) : re ⟪0, x⟫ = 0 := by
simp only [inner_zero_left, AddMonoidHom.map_zero]
@[simp]
theorem inner_zero_right (x : E) : ⟪x, 0⟫ = 0 := by
rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero]
theorem inner_re_zero_right (x : E) : re ⟪x, 0⟫ = 0 := by
simp only [inner_zero_right, AddMonoidHom.map_zero]
theorem inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ :=
PreInnerProductSpace.toCore.re_inner_nonneg x
theorem real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ :=
@inner_self_nonneg ℝ F _ _ _ x
@[simp]
theorem inner_self_ofReal_re (x : E) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=
((RCLike.is_real_TFAE (⟪x, x⟫ : 𝕜)).out 2 3).2 (inner_self_im (𝕜 := 𝕜) x)
theorem inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (‖x‖ : 𝕜) ^ 2 := by
rw [← inner_self_ofReal_re, ← norm_sq_eq_re_inner, ofReal_pow]
theorem inner_self_re_eq_norm (x : E) : re ⟪x, x⟫ = ‖⟪x, x⟫‖ := by
conv_rhs => rw [← inner_self_ofReal_re]
symm
exact norm_of_nonneg inner_self_nonneg
theorem inner_self_ofReal_norm (x : E) : (‖⟪x, x⟫‖ : 𝕜) = ⟪x, x⟫ := by
rw [← inner_self_re_eq_norm]
exact inner_self_ofReal_re _
theorem real_inner_self_abs (x : F) : |⟪x, x⟫_ℝ| = ⟪x, x⟫_ℝ :=
@inner_self_ofReal_norm ℝ F _ _ _ x
theorem norm_inner_symm (x y : E) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj]
@[simp]
theorem inner_neg_left (x y : E) : ⟪-x, y⟫ = -⟪x, y⟫ := by
rw [← neg_one_smul 𝕜 x, inner_smul_left]
simp
@[simp]
theorem inner_neg_right (x y : E) : ⟪x, -y⟫ = -⟪x, y⟫ := by
rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm]
theorem inner_neg_neg (x y : E) : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp
theorem inner_self_conj (x : E) : ⟪x, x⟫† = ⟪x, x⟫ := inner_conj_symm _ _
theorem inner_sub_left (x y z : E) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by
simp [sub_eq_add_neg, inner_add_left]
theorem inner_sub_right (x y z : E) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by
simp [sub_eq_add_neg, inner_add_right]
theorem inner_mul_symm_re_eq_norm (x y : E) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by
rw [← inner_conj_symm, mul_comm]
exact re_eq_norm_of_mul_conj (inner y x)
/-- Expand `⟪x + y, x + y⟫` -/
theorem inner_add_add_self (x y : E) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by
simp only [inner_add_left, inner_add_right]; ring
/-- Expand `⟪x + y, x + y⟫_ℝ` -/
theorem real_inner_add_add_self (x y : F) :
⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl
simp only [inner_add_add_self, this, add_left_inj]
ring
-- Expand `⟪x - y, x - y⟫`
theorem inner_sub_sub_self (x y : E) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by
simp only [inner_sub_left, inner_sub_right]; ring
/-- Expand `⟪x - y, x - y⟫_ℝ` -/
theorem real_inner_sub_sub_self (x y : F) :
⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl
simp only [inner_sub_sub_self, this, add_left_inj]
ring
/-- Parallelogram law -/
theorem parallelogram_law {x y : E} : ⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) := by
simp only [inner_add_add_self, inner_sub_sub_self]
ring
/-- **Cauchy–Schwarz inequality**. -/
theorem inner_mul_inner_self_le (x y : E) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ :=
letI cd : PreInnerProductSpace.Core 𝕜 E := PreInnerProductSpace.toCore
InnerProductSpace.Core.inner_mul_inner_self_le x y
/-- Cauchy–Schwarz inequality for real inner products. -/
theorem real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ :=
calc
⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ‖⟪x, y⟫_ℝ‖ * ‖⟪y, x⟫_ℝ‖ := by
rw [real_inner_comm y, ← norm_mul]
exact le_abs_self _
_ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := @inner_mul_inner_self_le ℝ _ _ _ _ x y
end BasicProperties_Seminormed
section BasicProperties
variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [NormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 := by
rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero]
theorem inner_self_ne_zero {x : E} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 :=
inner_self_eq_zero.not
variable (𝕜)
theorem ext_inner_left {x y : E} (h : ∀ v, ⟪v, x⟫ = ⟪v, y⟫) : x = y := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)]
| Mathlib/Analysis/InnerProductSpace/Basic.lean | 291 | 292 | theorem ext_inner_right {x y : E} (h : ∀ v, ⟪x, v⟫ = ⟪y, v⟫) : x = y := by | rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)] |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Justus Springer
-/
import Mathlib.Geometry.RingedSpace.LocallyRingedSpace
import Mathlib.AlgebraicGeometry.StructureSheaf
import Mathlib.RingTheory.Localization.LocalizationLocalization
import Mathlib.Topology.Sheaves.SheafCondition.Sites
import Mathlib.Topology.Sheaves.Functors
import Mathlib.Algebra.Module.LocalizedModule.Basic
/-!
# $Spec$ as a functor to locally ringed spaces.
We define the functor $Spec$ from commutative rings to locally ringed spaces.
## Implementation notes
We define $Spec$ in three consecutive steps, each with more structure than the last:
1. `Spec.toTop`, valued in the category of topological spaces,
2. `Spec.toSheafedSpace`, valued in the category of sheafed spaces and
3. `Spec.toLocallyRingedSpace`, valued in the category of locally ringed spaces.
Additionally, we provide `Spec.toPresheafedSpace` as a composition of `Spec.toSheafedSpace` with
a forgetful functor.
## Related results
The adjunction `Γ ⊣ Spec` is constructed in `Mathlib/AlgebraicGeometry/GammaSpecAdjunction.lean`.
-/
-- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737
noncomputable section
universe u v
namespace AlgebraicGeometry
open Opposite
open CategoryTheory
open StructureSheaf
open Spec (structureSheaf)
/-- The spectrum of a commutative ring, as a topological space.
-/
def Spec.topObj (R : CommRingCat.{u}) : TopCat :=
TopCat.of (PrimeSpectrum R)
@[simp] theorem Spec.topObj_forget {R} : ToType (Spec.topObj R) = PrimeSpectrum R :=
rfl
/-- The induced map of a ring homomorphism on the ring spectra, as a morphism of topological spaces.
-/
def Spec.topMap {R S : CommRingCat.{u}} (f : R ⟶ S) : Spec.topObj S ⟶ Spec.topObj R :=
TopCat.ofHom (PrimeSpectrum.comap f.hom)
@[simp]
theorem Spec.topMap_id (R : CommRingCat.{u}) : Spec.topMap (𝟙 R) = 𝟙 (Spec.topObj R) :=
rfl
@[simp]
theorem Spec.topMap_comp {R S T : CommRingCat.{u}} (f : R ⟶ S) (g : S ⟶ T) :
Spec.topMap (f ≫ g) = Spec.topMap g ≫ Spec.topMap f :=
rfl
-- Porting note: `simps!` generate some garbage lemmas, so choose manually,
-- if more is needed, add them here
/-- The spectrum, as a contravariant functor from commutative rings to topological spaces.
-/
@[simps!]
def Spec.toTop : CommRingCat.{u}ᵒᵖ ⥤ TopCat where
obj R := Spec.topObj (unop R)
map {_ _} f := Spec.topMap f.unop
/-- The spectrum of a commutative ring, as a `SheafedSpace`.
-/
@[simps]
def Spec.sheafedSpaceObj (R : CommRingCat.{u}) : SheafedSpace CommRingCat where
carrier := Spec.topObj R
presheaf := (structureSheaf R).1
IsSheaf := (structureSheaf R).2
/-- The induced map of a ring homomorphism on the ring spectra, as a morphism of sheafed spaces.
-/
@[simps base c_app]
def Spec.sheafedSpaceMap {R S : CommRingCat.{u}} (f : R ⟶ S) :
Spec.sheafedSpaceObj S ⟶ Spec.sheafedSpaceObj R where
base := Spec.topMap f
c :=
{ app := fun U => CommRingCat.ofHom <|
comap f.hom (unop U) ((TopologicalSpace.Opens.map (Spec.topMap f)).obj (unop U)) fun _ => id
naturality := fun {_ _} _ => by ext; rfl }
@[simp]
theorem Spec.sheafedSpaceMap_id {R : CommRingCat.{u}} :
Spec.sheafedSpaceMap (𝟙 R) = 𝟙 (Spec.sheafedSpaceObj R) :=
AlgebraicGeometry.PresheafedSpace.Hom.ext _ _ (Spec.topMap_id R) <| by
ext
dsimp
rw [comap_id (by simp)]
simp
rfl
theorem Spec.sheafedSpaceMap_comp {R S T : CommRingCat.{u}} (f : R ⟶ S) (g : S ⟶ T) :
Spec.sheafedSpaceMap (f ≫ g) = Spec.sheafedSpaceMap g ≫ Spec.sheafedSpaceMap f :=
AlgebraicGeometry.PresheafedSpace.Hom.ext _ _ (Spec.topMap_comp f g) <| by
ext
-- Porting note: was one liner
-- `dsimp, rw category_theory.functor.map_id, rw category.comp_id, erw comap_comp f g, refl`
rw [NatTrans.comp_app, sheafedSpaceMap_c_app, whiskerRight_app, eqToHom_refl]
erw [(sheafedSpaceObj T).presheaf.map_id]
dsimp only [CommRingCat.hom_comp, RingHom.coe_comp, Function.comp_apply]
rw [comap_comp]
rfl
/-- Spec, as a contravariant functor from commutative rings to sheafed spaces.
-/
@[simps]
def Spec.toSheafedSpace : CommRingCat.{u}ᵒᵖ ⥤ SheafedSpace CommRingCat where
obj R := Spec.sheafedSpaceObj (unop R)
map f := Spec.sheafedSpaceMap f.unop
map_comp f g := by simp [Spec.sheafedSpaceMap_comp]
/-- Spec, as a contravariant functor from commutative rings to presheafed spaces.
-/
def Spec.toPresheafedSpace : CommRingCat.{u}ᵒᵖ ⥤ PresheafedSpace CommRingCat :=
Spec.toSheafedSpace ⋙ SheafedSpace.forgetToPresheafedSpace
@[simp]
theorem Spec.toPresheafedSpace_obj (R : CommRingCat.{u}ᵒᵖ) :
Spec.toPresheafedSpace.obj R = (Spec.sheafedSpaceObj (unop R)).toPresheafedSpace :=
rfl
theorem Spec.toPresheafedSpace_obj_op (R : CommRingCat.{u}) :
Spec.toPresheafedSpace.obj (op R) = (Spec.sheafedSpaceObj R).toPresheafedSpace :=
rfl
@[simp]
theorem Spec.toPresheafedSpace_map (R S : CommRingCat.{u}ᵒᵖ) (f : R ⟶ S) :
Spec.toPresheafedSpace.map f = Spec.sheafedSpaceMap f.unop :=
rfl
theorem Spec.toPresheafedSpace_map_op (R S : CommRingCat.{u}) (f : R ⟶ S) :
Spec.toPresheafedSpace.map f.op = Spec.sheafedSpaceMap f :=
rfl
theorem Spec.basicOpen_hom_ext {X : RingedSpace.{u}} {R : CommRingCat.{u}}
{α β : X ⟶ Spec.sheafedSpaceObj R} (w : α.base = β.base)
(h : ∀ r : R,
let U := PrimeSpectrum.basicOpen r
(toOpen R U ≫ α.c.app (op U)) ≫ X.presheaf.map (eqToHom (by rw [w])) =
toOpen R U ≫ β.c.app (op U)) :
α = β := by
ext : 1
· exact w
· apply
((TopCat.Sheaf.pushforward _ β.base).obj X.sheaf).hom_ext _ PrimeSpectrum.isBasis_basic_opens
intro r
apply (StructureSheaf.to_basicOpen_epi R r).1
simpa using h r
-- Porting note: `simps!` generate some garbage lemmas, so choose manually,
-- if more is needed, add them here
/-- The spectrum of a commutative ring, as a `LocallyRingedSpace`.
-/
@[simps! toSheafedSpace presheaf]
def Spec.locallyRingedSpaceObj (R : CommRingCat.{u}) : LocallyRingedSpace :=
{ Spec.sheafedSpaceObj R with
isLocalRing := fun x =>
RingEquiv.isLocalRing (A := Localization.AtPrime x.asIdeal)
(Iso.commRingCatIsoToRingEquiv <| stalkIso R x).symm }
lemma Spec.locallyRingedSpaceObj_sheaf (R : CommRingCat.{u}) :
(Spec.locallyRingedSpaceObj R).sheaf = structureSheaf R := rfl
lemma Spec.locallyRingedSpaceObj_sheaf' (R : Type u) [CommRing R] :
(Spec.locallyRingedSpaceObj <| CommRingCat.of R).sheaf = structureSheaf R := rfl
lemma Spec.locallyRingedSpaceObj_presheaf_map (R : CommRingCat.{u}) {U V} (i : U ⟶ V) :
(Spec.locallyRingedSpaceObj R).presheaf.map i =
(structureSheaf R).1.map i := rfl
lemma Spec.locallyRingedSpaceObj_presheaf' (R : Type u) [CommRing R] :
(Spec.locallyRingedSpaceObj <| CommRingCat.of R).presheaf = (structureSheaf R).1 := rfl
lemma Spec.locallyRingedSpaceObj_presheaf_map' (R : Type u) [CommRing R] {U V} (i : U ⟶ V) :
(Spec.locallyRingedSpaceObj <| CommRingCat.of R).presheaf.map i =
(structureSheaf R).1.map i := rfl
@[elementwise]
theorem stalkMap_toStalk {R S : CommRingCat.{u}} (f : R ⟶ S) (p : PrimeSpectrum S) :
toStalk R (PrimeSpectrum.comap f.hom p) ≫ (Spec.sheafedSpaceMap f).stalkMap p =
f ≫ toStalk S p := by
rw [← toOpen_germ S ⊤ p trivial, ← toOpen_germ R ⊤ (PrimeSpectrum.comap f.hom p) trivial,
Category.assoc]
erw [PresheafedSpace.stalkMap_germ (Spec.sheafedSpaceMap f) ⊤ p trivial]
rw [Spec.sheafedSpaceMap_c_app]
erw [toOpen_comp_comap_assoc]
rfl
/-- Under the isomorphisms `stalkIso`, the map `stalkMap (Spec.sheafedSpaceMap f) p` corresponds
to the induced local ring homomorphism `Localization.localRingHom`.
-/
@[elementwise]
theorem localRingHom_comp_stalkIso {R S : CommRingCat.{u}} (f : R ⟶ S) (p : PrimeSpectrum S) :
(stalkIso R (PrimeSpectrum.comap f.hom p)).hom ≫
(CommRingCat.ofHom (Localization.localRingHom (PrimeSpectrum.comap f.hom p).asIdeal p.asIdeal
f.hom rfl)) ≫
(stalkIso S p).inv =
(Spec.sheafedSpaceMap f).stalkMap p :=
(stalkIso R (PrimeSpectrum.comap f.hom p)).eq_inv_comp.mp <|
(stalkIso S p).comp_inv_eq.mpr <| CommRingCat.hom_ext <|
Localization.localRingHom_unique _ _ _ (PrimeSpectrum.comap_asIdeal _ _) fun x => by
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 and https://github.com/leanprover-community/mathlib4/pull/8386
rw [stalkIso_hom, stalkIso_inv, CommRingCat.comp_apply, CommRingCat.comp_apply,
localizationToStalk_of, stalkMap_toStalk_apply f p x]
erw [stalkToFiberRingHom_toStalk]
rfl
/-- Version of `localRingHom_comp_stalkIso_apply` using `CommRingCat.Hom.hom` -/
theorem localRingHom_comp_stalkIso_apply' {R S : CommRingCat.{u}} (f : R ⟶ S) (p : PrimeSpectrum S)
(x) :
(stalkIso S p).inv ((Localization.localRingHom (PrimeSpectrum.comap f.hom p).asIdeal p.asIdeal
f.hom rfl) ((stalkIso R (PrimeSpectrum.comap f.hom p)).hom x)) =
(Spec.sheafedSpaceMap f).stalkMap p x :=
localRingHom_comp_stalkIso_apply _ _ _
/--
The induced map of a ring homomorphism on the prime spectra, as a morphism of locally ringed spaces.
-/
@[simps toShHom]
def Spec.locallyRingedSpaceMap {R S : CommRingCat.{u}} (f : R ⟶ S) :
Spec.locallyRingedSpaceObj S ⟶ Spec.locallyRingedSpaceObj R :=
LocallyRingedSpace.Hom.mk (Spec.sheafedSpaceMap f) fun p =>
IsLocalHom.mk fun a ha => by
-- Here, we are showing that the map on prime spectra induced by `f` is really a morphism of
-- *locally* ringed spaces, i.e. that the induced map on the stalks is a local ring
-- homomorphism.
#adaptation_note /-- nightly-2024-04-01
It's this `erw` that is blowing up. The implicit arguments differ significantly. -/
erw [← localRingHom_comp_stalkIso_apply' f p a] at ha
have : IsLocalHom (stalkIso (↑S) p).inv.hom := isLocalHom_of_isIso _
replace ha := (isUnit_map_iff (stalkIso S p).inv.hom _).mp ha
replace ha := IsLocalHom.map_nonunit
((stalkIso R ((PrimeSpectrum.comap f.hom) p)).hom a) ha
convert RingHom.isUnit_map (stalkIso R (PrimeSpectrum.comap f.hom p)).inv.hom ha
rw [← CommRingCat.comp_apply, Iso.hom_inv_id, CommRingCat.id_apply]
@[simp]
theorem Spec.locallyRingedSpaceMap_id (R : CommRingCat.{u}) :
Spec.locallyRingedSpaceMap (𝟙 R) = 𝟙 (Spec.locallyRingedSpaceObj R) :=
LocallyRingedSpace.Hom.ext' <| by
rw [Spec.locallyRingedSpaceMap_toShHom, Spec.sheafedSpaceMap_id]; rfl
theorem Spec.locallyRingedSpaceMap_comp {R S T : CommRingCat.{u}} (f : R ⟶ S) (g : S ⟶ T) :
Spec.locallyRingedSpaceMap (f ≫ g) =
Spec.locallyRingedSpaceMap g ≫ Spec.locallyRingedSpaceMap f :=
LocallyRingedSpace.Hom.ext' <| by
rw [Spec.locallyRingedSpaceMap_toShHom, Spec.sheafedSpaceMap_comp]; rfl
/-- Spec, as a contravariant functor from commutative rings to locally ringed spaces.
-/
@[simps]
def Spec.toLocallyRingedSpace : CommRingCat.{u}ᵒᵖ ⥤ LocallyRingedSpace where
obj R := Spec.locallyRingedSpaceObj (unop R)
map f := Spec.locallyRingedSpaceMap f.unop
map_id R := by dsimp; rw [Spec.locallyRingedSpaceMap_id]
map_comp f g := by dsimp; rw [Spec.locallyRingedSpaceMap_comp]
section SpecΓ
open AlgebraicGeometry.LocallyRingedSpace
/-- The counit morphism `R ⟶ Γ(Spec R)` given by `AlgebraicGeometry.StructureSheaf.toOpen`. -/
def toSpecΓ (R : CommRingCat.{u}) : R ⟶ Γ.obj (op (Spec.toLocallyRingedSpace.obj (op R))) :=
StructureSheaf.toOpen R ⊤
instance isIso_toSpecΓ (R : CommRingCat.{u}) : IsIso (toSpecΓ R) := by
cases R; apply StructureSheaf.isIso_to_global
@[reassoc]
| Mathlib/AlgebraicGeometry/Spec.lean | 292 | 295 | theorem Spec_Γ_naturality {R S : CommRingCat.{u}} (f : R ⟶ S) :
f ≫ toSpecΓ S = toSpecΓ R ≫ Γ.map (Spec.toLocallyRingedSpace.map f.op).op := by | -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` failed to pick up one of the three lemmas
ext : 2 |
/-
Copyright (c) 2024 Sophie Morel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sophie Morel
-/
import Mathlib.Analysis.NormedSpace.PiTensorProduct.ProjectiveSeminorm
import Mathlib.LinearAlgebra.Isomorphisms
/-!
# Injective seminorm on the tensor of a finite family of normed spaces.
Let `𝕜` be a nontrivially normed field and `E` be a family of normed `𝕜`-vector spaces `Eᵢ`,
indexed by a finite type `ι`. We define a seminorm on `⨂[𝕜] i, Eᵢ`, which we call the
"injective seminorm". It is chosen to satisfy the following property: for every
normed `𝕜`-vector space `F`, the linear equivalence
`MultilinearMap 𝕜 E F ≃ₗ[𝕜] (⨂[𝕜] i, Eᵢ) →ₗ[𝕜] F`
expressing the universal property of the tensor product induces an isometric linear equivalence
`ContinuousMultilinearMap 𝕜 E F ≃ₗᵢ[𝕜] (⨂[𝕜] i, Eᵢ) →L[𝕜] F`.
The idea is the following: Every normed `𝕜`-vector space `F` defines a linear map
from `⨂[𝕜] i, Eᵢ` to `ContinuousMultilinearMap 𝕜 E F →ₗ[𝕜] F`, which sends `x` to the map
`f ↦ f.lift x`. Thanks to `PiTensorProduct.norm_eval_le_projectiveSeminorm`, this map lands in
`ContinuousMultilinearMap 𝕜 E F →L[𝕜] F`. As this last space has a natural operator (semi)norm,
we get an induced seminorm on `⨂[𝕜] i, Eᵢ`, which, by
`PiTensorProduct.norm_eval_le_projectiveSeminorm`, is bounded above by the projective seminorm
`PiTensorProduct.projectiveSeminorm`. We then take the `sup` of these seminorms as `F` varies;
as this family of seminorms is bounded, its `sup` has good properties.
In fact, we cannot take the `sup` over all normed spaces `F` because of set-theoretical issues,
so we only take spaces `F` in the same universe as `⨂[𝕜] i, Eᵢ`. We prove in
`norm_eval_le_injectiveSeminorm` that this gives the same result, because every multilinear map
from `E = Πᵢ Eᵢ` to `F` factors though a normed vector space in the same universe as
`⨂[𝕜] i, Eᵢ`.
We then prove the universal property and the functoriality of `⨂[𝕜] i, Eᵢ` as a normed vector
space.
## Main definitions
* `PiTensorProduct.toDualContinuousMultilinearMap`: The `𝕜`-linear map from
`⨂[𝕜] i, Eᵢ` to `ContinuousMultilinearMap 𝕜 E F →L[𝕜] F` sending `x` to the map
`f ↦ f x`.
* `PiTensorProduct.injectiveSeminorm`: The injective seminorm on `⨂[𝕜] i, Eᵢ`.
* `PiTensorProduct.liftEquiv`: The bijection between `ContinuousMultilinearMap 𝕜 E F`
and `(⨂[𝕜] i, Eᵢ) →L[𝕜] F`, as a continuous linear equivalence.
* `PiTensorProduct.liftIsometry`: The bijection between `ContinuousMultilinearMap 𝕜 E F`
and `(⨂[𝕜] i, Eᵢ) →L[𝕜] F`, as an isometric linear equivalence.
* `PiTensorProduct.tprodL`: The canonical continuous multilinear map from `E = Πᵢ Eᵢ`
to `⨂[𝕜] i, Eᵢ`.
* `PiTensorProduct.mapL`: The continuous linear map from `⨂[𝕜] i, Eᵢ` to `⨂[𝕜] i, E'ᵢ`
induced by a family of continuous linear maps `Eᵢ →L[𝕜] E'ᵢ`.
* `PiTensorProduct.mapLMultilinear`: The continuous multilinear map from
`Πᵢ (Eᵢ →L[𝕜] E'ᵢ)` to `(⨂[𝕜] i, Eᵢ) →L[𝕜] (⨂[𝕜] i, E'ᵢ)` sending a family
`f` to `PiTensorProduct.mapL f`.
## Main results
* `PiTensorProduct.norm_eval_le_injectiveSeminorm`: The main property of the injective seminorm
on `⨂[𝕜] i, Eᵢ`: for every `x` in `⨂[𝕜] i, Eᵢ` and every continuous multilinear map `f` from
`E = Πᵢ Eᵢ` to a normed space `F`, we have `‖f.lift x‖ ≤ ‖f‖ * injectiveSeminorm x `.
* `PiTensorProduct.mapL_opNorm`: If `f` is a family of continuous linear maps
`fᵢ : Eᵢ →L[𝕜] Fᵢ`, then `‖PiTensorProduct.mapL f‖ ≤ ∏ i, ‖fᵢ‖`.
* `PiTensorProduct.mapLMultilinear_opNorm` : If `F` is a normed vecteor space, then
`‖mapLMultilinear 𝕜 E F‖ ≤ 1`.
## TODO
* If all `Eᵢ` are separated and satisfy `SeparatingDual`, then the seminorm on
`⨂[𝕜] i, Eᵢ` is a norm. This uses the construction of a basis of the `PiTensorProduct`, hence
depends on PR https://github.com/leanprover-community/mathlib4/pull/11156. It should probably go in a separate file.
* Adapt the remaining functoriality constructions/properties from `PiTensorProduct`.
-/
universe uι u𝕜 uE uF
variable {ι : Type uι} [Fintype ι]
variable {𝕜 : Type u𝕜} [NontriviallyNormedField 𝕜]
variable {E : ι → Type uE} [∀ i, SeminormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)]
variable {F : Type uF} [SeminormedAddCommGroup F] [NormedSpace 𝕜 F]
open scoped TensorProduct
namespace PiTensorProduct
section seminorm
variable (F) in
/-- The linear map from `⨂[𝕜] i, Eᵢ` to `ContinuousMultilinearMap 𝕜 E F →L[𝕜] F` sending
`x` in `⨂[𝕜] i, Eᵢ` to the map `f ↦ f.lift x`.
-/
@[simps!]
noncomputable def toDualContinuousMultilinearMap : (⨂[𝕜] i, E i) →ₗ[𝕜]
ContinuousMultilinearMap 𝕜 E F →L[𝕜] F where
toFun x := LinearMap.mkContinuous
((LinearMap.flip (lift (R := 𝕜) (s := E) (E := F)).toLinearMap x) ∘ₗ
ContinuousMultilinearMap.toMultilinearMapLinear)
(projectiveSeminorm x)
(fun _ ↦ by simp only [LinearMap.coe_comp, Function.comp_apply,
ContinuousMultilinearMap.toMultilinearMapLinear_apply, LinearMap.flip_apply,
LinearEquiv.coe_coe]
exact norm_eval_le_projectiveSeminorm _ _ _)
map_add' x y := by
ext _
simp only [map_add, LinearMap.mkContinuous_apply, LinearMap.coe_comp, Function.comp_apply,
ContinuousMultilinearMap.toMultilinearMapLinear_apply, LinearMap.add_apply,
LinearMap.flip_apply, LinearEquiv.coe_coe, ContinuousLinearMap.add_apply]
map_smul' a x := by
ext _
simp only [map_smul, LinearMap.mkContinuous_apply, LinearMap.coe_comp, Function.comp_apply,
ContinuousMultilinearMap.toMultilinearMapLinear_apply, LinearMap.smul_apply,
LinearMap.flip_apply, LinearEquiv.coe_coe, RingHom.id_apply, ContinuousLinearMap.coe_smul',
Pi.smul_apply]
theorem toDualContinuousMultilinearMap_le_projectiveSeminorm (x : ⨂[𝕜] i, E i) :
‖toDualContinuousMultilinearMap F x‖ ≤ projectiveSeminorm x := by
simp only [toDualContinuousMultilinearMap, LinearMap.coe_mk, AddHom.coe_mk]
apply LinearMap.mkContinuous_norm_le _ (apply_nonneg _ _)
/-- The injective seminorm on `⨂[𝕜] i, Eᵢ`. Morally, it sends `x` in `⨂[𝕜] i, Eᵢ` to the
`sup` of the operator norms of the `PiTensorProduct.toDualContinuousMultilinearMap F x`, for all
normed vector spaces `F`. In fact, we only take in the same universe as `⨂[𝕜] i, Eᵢ`, and then
prove in `PiTensorProduct.norm_eval_le_injectiveSeminorm` that this gives the same result.
-/
noncomputable irreducible_def injectiveSeminorm : Seminorm 𝕜 (⨂[𝕜] i, E i) :=
sSup {p | ∃ (G : Type (max uι u𝕜 uE)) (_ : SeminormedAddCommGroup G)
(_ : NormedSpace 𝕜 G), p = Seminorm.comp (normSeminorm 𝕜 (ContinuousMultilinearMap 𝕜 E G →L[𝕜] G))
(toDualContinuousMultilinearMap G (𝕜 := 𝕜) (E := E))}
lemma dualSeminorms_bounded : BddAbove {p | ∃ (G : Type (max uι u𝕜 uE))
(_ : SeminormedAddCommGroup G) (_ : NormedSpace 𝕜 G),
p = Seminorm.comp (normSeminorm 𝕜 (ContinuousMultilinearMap 𝕜 E G →L[𝕜] G))
(toDualContinuousMultilinearMap G (𝕜 := 𝕜) (E := E))} := by
existsi projectiveSeminorm
rw [mem_upperBounds]
simp only [Set.mem_setOf_eq, forall_exists_index]
intro p G _ _ hp
rw [hp]
intro x
simp only [Seminorm.comp_apply, coe_normSeminorm]
exact toDualContinuousMultilinearMap_le_projectiveSeminorm _
theorem injectiveSeminorm_apply (x : ⨂[𝕜] i, E i) :
injectiveSeminorm x = ⨆ p : {p | ∃ (G : Type (max uι u𝕜 uE))
(_ : SeminormedAddCommGroup G) (_ : NormedSpace 𝕜 G), p = Seminorm.comp (normSeminorm 𝕜
(ContinuousMultilinearMap 𝕜 E G →L[𝕜] G))
(toDualContinuousMultilinearMap G (𝕜 := 𝕜) (E := E))}, p.1 x := by
simpa only [injectiveSeminorm, Set.coe_setOf, Set.mem_setOf_eq]
using Seminorm.sSup_apply dualSeminorms_bounded
| Mathlib/Analysis/NormedSpace/PiTensorProduct/InjectiveSeminorm.lean | 152 | 202 | theorem norm_eval_le_injectiveSeminorm (f : ContinuousMultilinearMap 𝕜 E F) (x : ⨂[𝕜] i, E i) :
‖lift f.toMultilinearMap x‖ ≤ ‖f‖ * injectiveSeminorm x := by | /- If `F` were in `Type (max uι u𝕜 uE)` (which is the type of `⨂[𝕜] i, E i`), then the
property that we want to prove would hold by definition of `injectiveSeminorm`. This is
not necessarily true, but we will show that there exists a normed vector space `G` in
`Type (max uι u𝕜 uE)` and an injective isometry from `G` to `F` such that `f` factors
through a continuous multilinear map `f'` from `E = Π i, E i` to `G`, to which we can apply
the definition of `injectiveSeminorm`. The desired inequality for `f` then follows
immediately.
The idea is very simple: the multilinear map `f` corresponds by `PiTensorProduct.lift`
to a linear map from `⨂[𝕜] i, E i` to `F`, say `l`. We want to take `G` to be the image of
`l`, with the norm induced from that of `F`; to make sure that we are in the correct universe,
it is actually more convenient to take `G` equal to the coimage of `l` (i.e. the quotient
of `⨂[𝕜] i, E i` by the kernel of `l`), which is canonically isomorphic to its image by
`LinearMap.quotKerEquivRange`. -/
set G := (⨂[𝕜] i, E i) ⧸ LinearMap.ker (lift f.toMultilinearMap)
set G' := LinearMap.range (lift f.toMultilinearMap)
set e := LinearMap.quotKerEquivRange (lift f.toMultilinearMap)
letI := SeminormedAddCommGroup.induced G G' e
letI := NormedSpace.induced 𝕜 G G' e
set f'₀ := lift.symm (e.symm.toLinearMap ∘ₗ LinearMap.rangeRestrict (lift f.toMultilinearMap))
have hf'₀ : ∀ (x : Π (i : ι), E i), ‖f'₀ x‖ ≤ ‖f‖ * ∏ i, ‖x i‖ := fun x ↦ by
change ‖e (f'₀ x)‖ ≤ _
simp only [lift_symm, LinearMap.compMultilinearMap_apply, LinearMap.coe_comp,
LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.apply_symm_apply, Submodule.coe_norm,
LinearMap.codRestrict_apply, lift.tprod, ContinuousMultilinearMap.coe_coe, e, f'₀]
exact f.le_opNorm x
set f' := MultilinearMap.mkContinuous f'₀ ‖f‖ hf'₀
have hnorm : ‖f'‖ ≤ ‖f‖ := (f'.opNorm_le_iff (norm_nonneg f)).mpr hf'₀
have heq : e (lift f'.toMultilinearMap x) = lift f.toMultilinearMap x := by
induction x using PiTensorProduct.induction_on with
| smul_tprod =>
simp only [lift_symm, map_smul, lift.tprod, ContinuousMultilinearMap.coe_coe,
MultilinearMap.coe_mkContinuous, LinearMap.compMultilinearMap_apply, LinearMap.coe_comp,
LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.apply_symm_apply, SetLike.val_smul,
LinearMap.codRestrict_apply, f', f'₀]
| add _ _ hx hy => simp only [map_add, Submodule.coe_add, hx, hy]
suffices h : ‖lift f'.toMultilinearMap x‖ ≤ ‖f'‖ * injectiveSeminorm x by
change ‖(e (lift f'.toMultilinearMap x)).1‖ ≤ _ at h
rw [heq] at h
exact le_trans h (mul_le_mul_of_nonneg_right hnorm (apply_nonneg _ _))
have hle : Seminorm.comp (normSeminorm 𝕜 (ContinuousMultilinearMap 𝕜 E G →L[𝕜] G))
(toDualContinuousMultilinearMap G (𝕜 := 𝕜) (E := E)) ≤ injectiveSeminorm := by
simp only [injectiveSeminorm]
refine le_csSup dualSeminorms_bounded ?_
rw [Set.mem_setOf]
existsi G, inferInstance, inferInstance
rfl
refine le_trans ?_ (mul_le_mul_of_nonneg_left (hle x) (norm_nonneg f'))
simp only [Seminorm.comp_apply, coe_normSeminorm, ← toDualContinuousMultilinearMap_apply_apply]
rw [mul_comm] |
/-
Copyright (c) 2021 Henry Swanson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henry Swanson
-/
import Mathlib.Dynamics.FixedPoints.Basic
import Mathlib.GroupTheory.Perm.Option
import Mathlib.Logic.Equiv.Defs
import Mathlib.Logic.Equiv.Option
import Mathlib.Tactic.ApplyFun
/-!
# Derangements on types
In this file we define `derangements α`, the set of derangements on a type `α`.
We also define some equivalences involving various subtypes of `Perm α` and `derangements α`:
* `derangementsOptionEquivSigmaAtMostOneFixedPoint`: An equivalence between
`derangements (Option α)` and the sigma-type `Σ a : α, {f : Perm α // fixed_points f ⊆ a}`.
* `derangementsRecursionEquiv`: An equivalence between `derangements (Option α)` and the
sigma-type `Σ a : α, (derangements (({a}ᶜ : Set α) : Type*) ⊕ derangements α)` which is later
used to inductively count the number of derangements.
In order to prove the above, we also prove some results about the effect of `Equiv.removeNone`
on derangements: `RemoveNone.fiber_none` and `RemoveNone.fiber_some`.
-/
open Equiv Function
/-- A permutation is a derangement if it has no fixed points. -/
def derangements (α : Type*) : Set (Perm α) :=
{ f : Perm α | ∀ x : α, f x ≠ x }
variable {α β : Type*}
theorem mem_derangements_iff_fixedPoints_eq_empty {f : Perm α} :
f ∈ derangements α ↔ fixedPoints f = ∅ :=
Set.eq_empty_iff_forall_not_mem.symm
/-- If `α` is equivalent to `β`, then `derangements α` is equivalent to `derangements β`. -/
def Equiv.derangementsCongr (e : α ≃ β) : derangements α ≃ derangements β :=
e.permCongr.subtypeEquiv fun {f} => e.forall_congr <| by
intro b; simp only [ne_eq, permCongr_apply, symm_apply_apply, EmbeddingLike.apply_eq_iff_eq]
namespace derangements
/-- Derangements on a subtype are equivalent to permutations on the original type where points are
fixed iff they are not in the subtype. -/
protected def subtypeEquiv (p : α → Prop) [DecidablePred p] :
derangements (Subtype p) ≃ { f : Perm α // ∀ a, ¬p a ↔ a ∈ fixedPoints f } :=
calc
derangements (Subtype p) ≃ { f : { f : Perm α // ∀ a, ¬p a → a ∈ fixedPoints f } //
∀ a, a ∈ fixedPoints f → ¬p a } := by
refine (Perm.subtypeEquivSubtypePerm p).subtypeEquiv fun f => ⟨fun hf a hfa ha => ?_, ?_⟩
· refine hf ⟨a, ha⟩ (Subtype.ext ?_)
simp_rw [mem_fixedPoints, IsFixedPt, Perm.subtypeEquivSubtypePerm,
Equiv.coe_fn_mk, Perm.ofSubtype_apply_of_mem _ ha] at hfa
assumption
rintro hf ⟨a, ha⟩ hfa
refine hf _ ?_ ha
simp only [Perm.subtypeEquivSubtypePerm_apply_coe, mem_fixedPoints]
dsimp [IsFixedPt]
simp_rw [Perm.ofSubtype_apply_of_mem _ ha, hfa]
_ ≃ { f : Perm α // ∃ _h : ∀ a, ¬p a → a ∈ fixedPoints f, ∀ a, a ∈ fixedPoints f → ¬p a } :=
subtypeSubtypeEquivSubtypeExists _ _
_ ≃ { f : Perm α // ∀ a, ¬p a ↔ a ∈ fixedPoints f } :=
subtypeEquivRight fun f => by
simp_rw [exists_prop, ← forall_and, ← iff_iff_implies_and_implies]
universe u
/-- The set of permutations that fix either `a` or nothing is equivalent to the sum of:
- derangements on `α`
- derangements on `α` minus `a`. -/
def atMostOneFixedPointEquivSum_derangements [DecidableEq α] (a : α) :
{ f : Perm α // fixedPoints f ⊆ {a} } ≃ (derangements ({a}ᶜ : Set α)) ⊕ (derangements α) :=
calc
{ f : Perm α // fixedPoints f ⊆ {a} } ≃
{ f : { f : Perm α // fixedPoints f ⊆ {a} } // a ∈ fixedPoints f } ⊕
{ f : { f : Perm α // fixedPoints f ⊆ {a} } // a ∉ fixedPoints f } :=
(Equiv.sumCompl _).symm
_ ≃ { f : Perm α // fixedPoints f ⊆ {a} ∧ a ∈ fixedPoints f } ⊕
{ f : Perm α // fixedPoints f ⊆ {a} ∧ a ∉ fixedPoints f } := by
-- Porting note: `subtypeSubtypeEquivSubtypeInter` no longer works with placeholder `_`s.
refine Equiv.sumCongr ?_ ?_
· exact subtypeSubtypeEquivSubtypeInter
(fun x : Perm α => fixedPoints x ⊆ {a})
(a ∈ fixedPoints ·)
· exact subtypeSubtypeEquivSubtypeInter
(fun x : Perm α => fixedPoints x ⊆ {a})
(¬a ∈ fixedPoints ·)
_ ≃ { f : Perm α // fixedPoints f = {a} } ⊕ { f : Perm α // fixedPoints f = ∅ } := by
refine Equiv.sumCongr (subtypeEquivRight fun f => ?_) (subtypeEquivRight fun f => ?_)
· rw [Set.eq_singleton_iff_unique_mem, and_comm]
rfl
· rw [Set.eq_empty_iff_forall_not_mem]
exact ⟨fun h x hx => h.2 (h.1 hx ▸ hx), fun h => ⟨fun x hx => (h _ hx).elim, h _⟩⟩
_ ≃ derangements ({a}ᶜ : Set α) ⊕ derangements α := by
refine
Equiv.sumCongr ((derangements.subtypeEquiv _).trans <|
subtypeEquivRight fun x => ?_).symm
(subtypeEquivRight fun f => mem_derangements_iff_fixedPoints_eq_empty.symm)
rw [eq_comm, Set.ext_iff]
simp_rw [Set.mem_compl_iff, Classical.not_not]
namespace Equiv
variable [DecidableEq α]
/-- The set of permutations `f` such that the preimage of `(a, f)` under
`Equiv.Perm.decomposeOption` is a derangement. -/
def RemoveNone.fiber (a : Option α) : Set (Perm α) :=
{ f : Perm α | (a, f) ∈ Equiv.Perm.decomposeOption '' derangements (Option α) }
theorem RemoveNone.mem_fiber (a : Option α) (f : Perm α) :
f ∈ RemoveNone.fiber a ↔
∃ F : Perm (Option α), F ∈ derangements (Option α) ∧ F none = a ∧ removeNone F = f := by
simp [RemoveNone.fiber, derangements]
theorem RemoveNone.fiber_none : RemoveNone.fiber (@none α) = ∅ := by
rw [Set.eq_empty_iff_forall_not_mem]
intro f hyp
rw [RemoveNone.mem_fiber] at hyp
rcases hyp with ⟨F, F_derangement, F_none, _⟩
exact F_derangement none F_none
/-- For any `a : α`, the fiber over `some a` is the set of permutations
where `a` is the only possible fixed point. -/
| Mathlib/Combinatorics/Derangements/Basic.lean | 129 | 134 | theorem RemoveNone.fiber_some (a : α) :
RemoveNone.fiber (some a) = { f : Perm α | fixedPoints f ⊆ {a} } := by | ext f
constructor
· rw [RemoveNone.mem_fiber]
rintro ⟨F, F_derangement, F_none, rfl⟩ x x_fixed |
/-
Copyright (c) 2023 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Geißer, Michael Stoll
-/
import Mathlib.Data.ZMod.Basic
import Mathlib.NumberTheory.DiophantineApproximation.Basic
import Mathlib.NumberTheory.Zsqrtd.Basic
import Mathlib.Tactic.Qify
/-!
# Pell's Equation
*Pell's Equation* is the equation $x^2 - d y^2 = 1$, where $d$ is a positive integer
that is not a square, and one is interested in solutions in integers $x$ and $y$.
In this file, we aim at providing all of the essential theory of Pell's Equation for general $d$
(as opposed to the contents of `NumberTheory.PellMatiyasevic`, which is specific to the case
$d = a^2 - 1$ for some $a > 1$).
We begin by defining a type `Pell.Solution₁ d` for solutions of the equation,
show that it has a natural structure as an abelian group, and prove some basic
properties.
We then prove the following
**Theorem.** Let $d$ be a positive integer that is not a square. Then the equation
$x^2 - d y^2 = 1$ has a nontrivial (i.e., with $y \ne 0$) solution in integers.
See `Pell.exists_of_not_isSquare` and `Pell.Solution₁.exists_nontrivial_of_not_isSquare`.
We then define the *fundamental solution* to be the solution
with smallest $x$ among all solutions satisfying $x > 1$ and $y > 0$.
We show that every solution is a power (in the sense of the group structure mentioned above)
of the fundamental solution up to a (common) sign,
see `Pell.IsFundamental.eq_zpow_or_neg_zpow`, and that a (positive) solution has this property
if and only if it is fundamental, see `Pell.pos_generator_iff_fundamental`.
## References
* [K. Ireland, M. Rosen, *A classical introduction to modern number theory*
(Section 17.5)][IrelandRosen1990]
## Tags
Pell's equation
## TODO
* Extend to `x ^ 2 - d * y ^ 2 = -1` and further generalizations.
* Connect solutions to the continued fraction expansion of `√d`.
-/
namespace Pell
/-!
### Group structure of the solution set
We define a structure of a commutative multiplicative group with distributive negation
on the set of all solutions to the Pell equation `x^2 - d*y^2 = 1`.
The type of such solutions is `Pell.Solution₁ d`. It corresponds to a pair of integers `x` and `y`
and a proof that `(x, y)` is indeed a solution.
The multiplication is given by `(x, y) * (x', y') = (x*y' + d*y*y', x*y' + y*x')`.
This is obtained by mapping `(x, y)` to `x + y*√d` and multiplying the results.
In fact, we define `Pell.Solution₁ d` to be `↥(unitary (ℤ√d))` and transport
the "commutative group with distributive negation" structure from `↥(unitary (ℤ√d))`.
We then set up an API for `Pell.Solution₁ d`.
-/
open CharZero Zsqrtd
/-- An element of `ℤ√d` has norm one (i.e., `a.re^2 - d*a.im^2 = 1`) if and only if
it is contained in the submonoid of unitary elements.
TODO: merge this result with `Pell.isPell_iff_mem_unitary`. -/
theorem is_pell_solution_iff_mem_unitary {d : ℤ} {a : ℤ√d} :
a.re ^ 2 - d * a.im ^ 2 = 1 ↔ a ∈ unitary (ℤ√d) := by
rw [← norm_eq_one_iff_mem_unitary, norm_def, sq, sq, ← mul_assoc]
-- We use `solution₁ d` to allow for a more general structure `solution d m` that
-- encodes solutions to `x^2 - d*y^2 = m` to be added later.
/-- `Pell.Solution₁ d` is the type of solutions to the Pell equation `x^2 - d*y^2 = 1`.
We define this in terms of elements of `ℤ√d` of norm one.
-/
def Solution₁ (d : ℤ) : Type :=
↥(unitary (ℤ√d))
namespace Solution₁
variable {d : ℤ}
instance instCommGroup : CommGroup (Solution₁ d) :=
inferInstanceAs (CommGroup (unitary (ℤ√d)))
instance instHasDistribNeg : HasDistribNeg (Solution₁ d) :=
inferInstanceAs (HasDistribNeg (unitary (ℤ√d)))
instance instInhabited : Inhabited (Solution₁ d) :=
inferInstanceAs (Inhabited (unitary (ℤ√d)))
instance : Coe (Solution₁ d) (ℤ√d) where coe := Subtype.val
/-- The `x` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/
protected def x (a : Solution₁ d) : ℤ :=
(a : ℤ√d).re
/-- The `y` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/
protected def y (a : Solution₁ d) : ℤ :=
(a : ℤ√d).im
/-- The proof that `a` is a solution to the Pell equation `x^2 - d*y^2 = 1` -/
theorem prop (a : Solution₁ d) : a.x ^ 2 - d * a.y ^ 2 = 1 :=
is_pell_solution_iff_mem_unitary.mpr a.property
/-- An alternative form of the equation, suitable for rewriting `x^2`. -/
theorem prop_x (a : Solution₁ d) : a.x ^ 2 = 1 + d * a.y ^ 2 := by rw [← a.prop]; ring
/-- An alternative form of the equation, suitable for rewriting `d * y^2`. -/
theorem prop_y (a : Solution₁ d) : d * a.y ^ 2 = a.x ^ 2 - 1 := by rw [← a.prop]; ring
/-- Two solutions are equal if their `x` and `y` components are equal. -/
@[ext]
theorem ext {a b : Solution₁ d} (hx : a.x = b.x) (hy : a.y = b.y) : a = b :=
Subtype.ext <| Zsqrtd.ext hx hy
/-- Construct a solution from `x`, `y` and a proof that the equation is satisfied. -/
def mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : Solution₁ d where
val := ⟨x, y⟩
property := is_pell_solution_iff_mem_unitary.mp prop
@[simp]
theorem x_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).x = x :=
rfl
@[simp]
theorem y_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).y = y :=
rfl
@[simp]
theorem coe_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (↑(mk x y prop) : ℤ√d) = ⟨x, y⟩ :=
Zsqrtd.ext (x_mk x y prop) (y_mk x y prop)
@[simp]
theorem x_one : (1 : Solution₁ d).x = 1 :=
rfl
@[simp]
theorem y_one : (1 : Solution₁ d).y = 0 :=
rfl
@[simp]
theorem x_mul (a b : Solution₁ d) : (a * b).x = a.x * b.x + d * (a.y * b.y) := by
rw [← mul_assoc]
rfl
@[simp]
theorem y_mul (a b : Solution₁ d) : (a * b).y = a.x * b.y + a.y * b.x :=
rfl
@[simp]
theorem x_inv (a : Solution₁ d) : a⁻¹.x = a.x :=
rfl
@[simp]
theorem y_inv (a : Solution₁ d) : a⁻¹.y = -a.y :=
rfl
@[simp]
theorem x_neg (a : Solution₁ d) : (-a).x = -a.x :=
rfl
@[simp]
theorem y_neg (a : Solution₁ d) : (-a).y = -a.y :=
rfl
/-- When `d` is negative, then `x` or `y` must be zero in a solution. -/
theorem eq_zero_of_d_neg (h₀ : d < 0) (a : Solution₁ d) : a.x = 0 ∨ a.y = 0 := by
have h := a.prop
contrapose! h
have h1 := sq_pos_of_ne_zero h.1
have h2 := sq_pos_of_ne_zero h.2
nlinarith
/-- A solution has `x ≠ 0`. -/
theorem x_ne_zero (h₀ : 0 ≤ d) (a : Solution₁ d) : a.x ≠ 0 := by
intro hx
have h : 0 ≤ d * a.y ^ 2 := mul_nonneg h₀ (sq_nonneg _)
rw [a.prop_y, hx, sq, zero_mul, zero_sub] at h
exact not_le.mpr (neg_one_lt_zero : (-1 : ℤ) < 0) h
/-- A solution with `x > 1` must have `y ≠ 0`. -/
theorem y_ne_zero_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : a.y ≠ 0 := by
intro hy
have prop := a.prop
rw [hy, sq (0 : ℤ), zero_mul, mul_zero, sub_zero] at prop
exact lt_irrefl _ (((one_lt_sq_iff₀ <| zero_le_one.trans ha.le).mpr ha).trans_eq prop)
/-- If a solution has `x > 1`, then `d` is positive. -/
theorem d_pos_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : 0 < d := by
refine pos_of_mul_pos_left ?_ (sq_nonneg a.y)
rw [a.prop_y, sub_pos]
exact one_lt_pow₀ ha two_ne_zero
/-- If a solution has `x > 1`, then `d` is not a square. -/
theorem d_nonsquare_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : ¬IsSquare d := by
have hp := a.prop
rintro ⟨b, rfl⟩
simp_rw [← sq, ← mul_pow, sq_sub_sq, Int.mul_eq_one_iff_eq_one_or_neg_one] at hp
omega
/-- A solution with `x = 1` is trivial. -/
theorem eq_one_of_x_eq_one (h₀ : d ≠ 0) {a : Solution₁ d} (ha : a.x = 1) : a = 1 := by
have prop := a.prop_y
rw [ha, one_pow, sub_self, mul_eq_zero, or_iff_right h₀, sq_eq_zero_iff] at prop
exact ext ha prop
/-- A solution is `1` or `-1` if and only if `y = 0`. -/
theorem eq_one_or_neg_one_iff_y_eq_zero {a : Solution₁ d} : a = 1 ∨ a = -1 ↔ a.y = 0 := by
refine ⟨fun H => H.elim (fun h => by simp [h]) fun h => by simp [h], fun H => ?_⟩
have prop := a.prop
rw [H, sq (0 : ℤ), mul_zero, mul_zero, sub_zero, sq_eq_one_iff] at prop
exact prop.imp (fun h => ext h H) fun h => ext h H
/-- The set of solutions with `x > 0` is closed under multiplication. -/
theorem x_mul_pos {a b : Solution₁ d} (ha : 0 < a.x) (hb : 0 < b.x) : 0 < (a * b).x := by
simp only [x_mul]
refine neg_lt_iff_pos_add'.mp (abs_lt.mp ?_).1
rw [← abs_of_pos ha, ← abs_of_pos hb, ← abs_mul, ← sq_lt_sq, mul_pow a.x, a.prop_x, b.prop_x, ←
sub_pos]
ring_nf
rcases le_or_lt 0 d with h | h
· positivity
· rw [(eq_zero_of_d_neg h a).resolve_left ha.ne', (eq_zero_of_d_neg h b).resolve_left hb.ne']
simp
/-- The set of solutions with `x` and `y` positive is closed under multiplication. -/
theorem y_mul_pos {a b : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (hbx : 0 < b.x)
(hby : 0 < b.y) : 0 < (a * b).y := by
simp only [y_mul]
positivity
/-- If `(x, y)` is a solution with `x` positive, then all its powers with natural exponents
have positive `x`. -/
theorem x_pow_pos {a : Solution₁ d} (hax : 0 < a.x) (n : ℕ) : 0 < (a ^ n).x := by
induction n with
| zero => simp only [pow_zero, x_one, zero_lt_one]
| succ n ih => rw [pow_succ]; exact x_mul_pos ih hax
/-- If `(x, y)` is a solution with `x` and `y` positive, then all its powers with positive
natural exponents have positive `y`. -/
| Mathlib/NumberTheory/Pell.lean | 256 | 260 | theorem y_pow_succ_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (n : ℕ) :
0 < (a ^ n.succ).y := by | induction n with
| zero => simp only [pow_one, hay]
| succ n ih => rw [pow_succ']; exact y_mul_pos hax hay (x_pow_pos hax _) ih |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kevin Buzzard
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.RingTheory.PowerSeries.Inverse
import Mathlib.RingTheory.PowerSeries.WellKnown
/-!
# Bernoulli numbers
The Bernoulli numbers are a sequence of rational numbers that frequently show up in
number theory.
## Mathematical overview
The Bernoulli numbers $(B_0, B_1, B_2, \ldots)=(1, -1/2, 1/6, 0, -1/30, \ldots)$ are
a sequence of rational numbers. They show up in the formula for the sums of $k$th
powers. They are related to the Taylor series expansions of $x/\tan(x)$ and
of $\coth(x)$, and also show up in the values that the Riemann Zeta function
takes both at both negative and positive integers (and hence in the
theory of modular forms). For example, if $1 \leq n$ then
$$\zeta(2n)=\sum_{t\geq1}t^{-2n}=(-1)^{n+1}\frac{(2\pi)^{2n}B_{2n}}{2(2n)!}.$$
This result is formalised in Lean: `riemannZeta_two_mul_nat`.
The Bernoulli numbers can be formally defined using the power series
$$\sum B_n\frac{t^n}{n!}=\frac{t}{1-e^{-t}}$$
although that happens to not be the definition in mathlib (this is an *implementation
detail* and need not concern the mathematician).
Note that $B_1=-1/2$, meaning that we are using the $B_n^-$ of
[from Wikipedia](https://en.wikipedia.org/wiki/Bernoulli_number).
## Implementation detail
The Bernoulli numbers are defined using well-founded induction, by the formula
$$B_n=1-\sum_{k\lt n}\frac{\binom{n}{k}}{n-k+1}B_k.$$
This formula is true for all $n$ and in particular $B_0=1$. Note that this is the definition
for positive Bernoulli numbers, which we call `bernoulli'`. The negative Bernoulli numbers are
then defined as `bernoulli := (-1)^n * bernoulli'`.
## Main theorems
`sum_bernoulli : ∑ k ∈ Finset.range n, (n.choose k : ℚ) * bernoulli k = if n = 1 then 1 else 0`
-/
open Nat Finset Finset.Nat PowerSeries
variable (A : Type*) [CommRing A] [Algebra ℚ A]
/-! ### Definitions -/
/-- The Bernoulli numbers:
the $n$-th Bernoulli number $B_n$ is defined recursively via
$$B_n = 1 - \sum_{k < n} \binom{n}{k}\frac{B_k}{n+1-k}$$ -/
def bernoulli' : ℕ → ℚ :=
WellFounded.fix Nat.lt_wfRel.wf fun n bernoulli' =>
1 - ∑ k : Fin n, n.choose k / (n - k + 1) * bernoulli' k k.2
theorem bernoulli'_def' (n : ℕ) :
bernoulli' n = 1 - ∑ k : Fin n, n.choose k / (n - k + 1) * bernoulli' k :=
WellFounded.fix_eq _ _ _
theorem bernoulli'_def (n : ℕ) :
bernoulli' n = 1 - ∑ k ∈ range n, n.choose k / (n - k + 1) * bernoulli' k := by
rw [bernoulli'_def', ← Fin.sum_univ_eq_sum_range]
theorem bernoulli'_spec (n : ℕ) :
(∑ k ∈ range n.succ, (n.choose (n - k) : ℚ) / (n - k + 1) * bernoulli' k) = 1 := by
rw [sum_range_succ_comm, bernoulli'_def n, tsub_self, choose_zero_right, sub_self, zero_add,
div_one, cast_one, one_mul, sub_add, ← sum_sub_distrib, ← sub_eq_zero, sub_sub_cancel_left,
neg_eq_zero]
exact Finset.sum_eq_zero (fun x hx => by rw [choose_symm (le_of_lt (mem_range.1 hx)), sub_self])
theorem bernoulli'_spec' (n : ℕ) :
(∑ k ∈ antidiagonal n, ((k.1 + k.2).choose k.2 : ℚ) / (k.2 + 1) * bernoulli' k.1) = 1 := by
refine ((sum_antidiagonal_eq_sum_range_succ_mk _ n).trans ?_).trans (bernoulli'_spec n)
refine sum_congr rfl fun x hx => ?_
simp only [add_tsub_cancel_of_le, mem_range_succ_iff.mp hx, cast_sub]
/-! ### Examples -/
section Examples
@[simp]
theorem bernoulli'_zero : bernoulli' 0 = 1 := by
rw [bernoulli'_def]
norm_num
@[simp]
theorem bernoulli'_one : bernoulli' 1 = 1 / 2 := by
rw [bernoulli'_def]
norm_num
@[simp]
theorem bernoulli'_two : bernoulli' 2 = 1 / 6 := by
rw [bernoulli'_def]
norm_num [sum_range_succ, sum_range_succ, sum_range_zero]
@[simp]
theorem bernoulli'_three : bernoulli' 3 = 0 := by
rw [bernoulli'_def]
norm_num [sum_range_succ, sum_range_succ, sum_range_zero]
@[simp]
theorem bernoulli'_four : bernoulli' 4 = -1 / 30 := by
have : Nat.choose 4 2 = 6 := by decide -- shrug
rw [bernoulli'_def]
norm_num [sum_range_succ, sum_range_succ, sum_range_zero, this]
end Examples
@[simp]
theorem sum_bernoulli' (n : ℕ) : (∑ k ∈ range n, (n.choose k : ℚ) * bernoulli' k) = n := by
cases n with | zero => simp | succ n =>
suffices
((n + 1 : ℚ) * ∑ k ∈ range n, ↑(n.choose k) / (n - k + 1) * bernoulli' k) =
∑ x ∈ range n, ↑(n.succ.choose x) * bernoulli' x by
rw_mod_cast [sum_range_succ, bernoulli'_def, ← this, choose_succ_self_right]
ring
simp_rw [mul_sum, ← mul_assoc]
refine sum_congr rfl fun k hk => ?_
congr
have : ((n - k : ℕ) : ℚ) + 1 ≠ 0 := by norm_cast
field_simp [← cast_sub (mem_range.1 hk).le, mul_comm]
rw_mod_cast [tsub_add_eq_add_tsub (mem_range.1 hk).le, choose_mul_succ_eq]
/-- The exponential generating function for the Bernoulli numbers `bernoulli' n`. -/
def bernoulli'PowerSeries :=
mk fun n => algebraMap ℚ A (bernoulli' n / n !)
theorem bernoulli'PowerSeries_mul_exp_sub_one :
bernoulli'PowerSeries A * (exp A - 1) = X * exp A := by
ext n
-- constant coefficient is a special case
cases n with | zero => simp | succ n =>
rw [bernoulli'PowerSeries, coeff_mul, mul_comm X, sum_antidiagonal_succ']
suffices (∑ p ∈ antidiagonal n,
bernoulli' p.1 / p.1! * ((p.2 + 1) * p.2! : ℚ)⁻¹) = (n ! : ℚ)⁻¹ by
simpa [map_sum, Nat.factorial] using congr_arg (algebraMap ℚ A) this
apply eq_inv_of_mul_eq_one_left
rw [sum_mul]
convert bernoulli'_spec' n using 1
apply sum_congr rfl
simp_rw [mem_antidiagonal]
rintro ⟨i, j⟩ rfl
have := factorial_mul_factorial_dvd_factorial_add i j
field_simp [mul_comm _ (bernoulli' i), mul_assoc, add_choose]
norm_cast
simp [mul_comm (j + 1)]
/-- Odd Bernoulli numbers (greater than 1) are zero. -/
theorem bernoulli'_odd_eq_zero {n : ℕ} (h_odd : Odd n) (hlt : 1 < n) : bernoulli' n = 0 := by
let B := mk fun n => bernoulli' n / (n ! : ℚ)
suffices (B - evalNegHom B) * (exp ℚ - 1) = X * (exp ℚ - 1) by
rcases mul_eq_mul_right_iff.mp this with h | h <;>
simp only [PowerSeries.ext_iff, evalNegHom, coeff_X] at h
· apply eq_zero_of_neg_eq
specialize h n
split_ifs at h <;> simp_all [B, h_odd.neg_one_pow, factorial_ne_zero]
· simpa +decide [Nat.factorial] using h 1
have h : B * (exp ℚ - 1) = X * exp ℚ := by
simpa [bernoulli'PowerSeries] using bernoulli'PowerSeries_mul_exp_sub_one ℚ
rw [sub_mul, h, mul_sub X, sub_right_inj, ← neg_sub, mul_neg, neg_eq_iff_eq_neg]
suffices evalNegHom (B * (exp ℚ - 1)) * exp ℚ = evalNegHom (X * exp ℚ) * exp ℚ by
simpa [mul_assoc, sub_mul, mul_comm (evalNegHom (exp ℚ)), exp_mul_exp_neg_eq_one]
congr
/-- The Bernoulli numbers are defined to be `bernoulli'` with a parity sign. -/
def bernoulli (n : ℕ) : ℚ :=
(-1) ^ n * bernoulli' n
theorem bernoulli'_eq_bernoulli (n : ℕ) : bernoulli' n = (-1) ^ n * bernoulli n := by
simp [bernoulli, ← mul_assoc, ← sq, ← pow_mul, mul_comm n 2]
@[simp]
theorem bernoulli_zero : bernoulli 0 = 1 := by simp [bernoulli]
@[simp]
theorem bernoulli_one : bernoulli 1 = -1 / 2 := by norm_num [bernoulli]
theorem bernoulli_eq_bernoulli'_of_ne_one {n : ℕ} (hn : n ≠ 1) : bernoulli n = bernoulli' n := by
by_cases h0 : n = 0; · simp [h0]
rw [bernoulli, neg_one_pow_eq_pow_mod_two]
rcases mod_two_eq_zero_or_one n with h | h
· simp [h]
· simp [bernoulli'_odd_eq_zero (odd_iff.mpr h) (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, hn⟩)]
@[simp]
theorem sum_bernoulli (n : ℕ) :
(∑ k ∈ range n, (n.choose k : ℚ) * bernoulli k) = if n = 1 then 1 else 0 := by
cases n with | zero => simp | succ n =>
cases n with | zero => rw [sum_range_one]; simp | succ n =>
suffices (∑ i ∈ range n, ↑((n + 2).choose (i + 2)) * bernoulli (i + 2)) = n / 2 by
simp only [this, sum_range_succ', cast_succ, bernoulli_one, bernoulli_zero, choose_one_right,
mul_one, choose_zero_right, cast_zero, if_false, zero_add, succ_succ_ne_one]
ring
have f := sum_bernoulli' n.succ.succ
simp_rw [sum_range_succ', cast_succ, ← eq_sub_iff_add_eq] at f
refine Eq.trans ?_ (Eq.trans f ?_)
· congr
funext x
rw [bernoulli_eq_bernoulli'_of_ne_one (succ_ne_zero x ∘ succ.inj)]
· simp only [one_div, mul_one, bernoulli'_zero, cast_one, choose_zero_right, add_sub_cancel_right,
zero_add, choose_one_right, cast_succ, cast_add, cast_one, bernoulli'_one, one_div]
ring
| Mathlib/NumberTheory/Bernoulli.lean | 216 | 221 | theorem bernoulli_spec' (n : ℕ) :
(∑ k ∈ antidiagonal n, ((k.1 + k.2).choose k.2 : ℚ) / (k.2 + 1) * bernoulli k.1) =
if n = 0 then 1 else 0 := by | cases n with | zero => simp | succ n =>
rw [if_neg (succ_ne_zero _)]
-- algebra facts |
/-
Copyright (c) 2022 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Data.List.Induction
import Mathlib.Data.List.TakeWhile
/-!
# Dropping or taking from lists on the right
Taking or removing element from the tail end of a list
## Main definitions
- `rdrop n`: drop `n : ℕ` elements from the tail
- `rtake n`: take `n : ℕ` elements from the tail
- `rdropWhile p`: remove all the elements from the tail of a list until it finds the first element
for which `p : α → Bool` returns false. This element and everything before is returned.
- `rtakeWhile p`: Returns the longest terminal segment of a list for which `p : α → Bool` returns
true.
## Implementation detail
The two predicate-based methods operate by performing the regular "from-left" operation on
`List.reverse`, followed by another `List.reverse`, so they are not the most performant.
The other two rely on `List.length l` so they still traverse the list twice. One could construct
another function that takes a `L : ℕ` and use `L - n`. Under a proof condition that
`L = l.length`, the function would do the right thing.
-/
-- Make sure we don't import algebra
assert_not_exists Monoid
variable {α : Type*} (p : α → Bool) (l : List α) (n : ℕ)
namespace List
/-- Drop `n` elements from the tail end of a list. -/
def rdrop : List α :=
l.take (l.length - n)
@[simp]
theorem rdrop_nil : rdrop ([] : List α) n = [] := by simp [rdrop]
@[simp]
theorem rdrop_zero : rdrop l 0 = l := by simp [rdrop]
| Mathlib/Data/List/DropRight.lean | 51 | 51 | theorem rdrop_eq_reverse_drop_reverse : l.rdrop n = reverse (l.reverse.drop n) := by | |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Complex
/-!
# The `arctan` function.
Inequalities, identities and `Real.tan` as a `PartialHomeomorph` between `(-(π / 2), π / 2)`
and the whole line.
The result of `arctan x + arctan y` is given by `arctan_add`, `arctan_add_eq_add_pi` or
`arctan_add_eq_sub_pi` depending on whether `x * y < 1` and `0 < x`. As an application of
`arctan_add` we give four Machin-like formulas (linear combinations of arctangents equal to
`π / 4 = arctan 1`), including John Machin's original one at
`four_mul_arctan_inv_5_sub_arctan_inv_239`.
-/
noncomputable section
namespace Real
open Set Filter
open scoped Topology Real
theorem tan_add {x y : ℝ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) ∨
(∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y = (2 * l + 1) * π / 2) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := by
simpa only [← Complex.ofReal_inj, Complex.ofReal_sub, Complex.ofReal_add, Complex.ofReal_div,
Complex.ofReal_mul, Complex.ofReal_tan] using
@Complex.tan_add (x : ℂ) (y : ℂ) (by convert h <;> norm_cast)
theorem tan_add' {x y : ℝ}
(h : (∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
tan_add (Or.inl h)
theorem tan_two_mul {x : ℝ} : tan (2 * x) = 2 * tan x / (1 - tan x ^ 2) := by
have := @Complex.tan_two_mul x
norm_cast at *
theorem tan_int_mul_pi_div_two (n : ℤ) : tan (n * π / 2) = 0 :=
tan_eq_zero_iff.mpr (by use n)
theorem continuousOn_tan : ContinuousOn tan {x | cos x ≠ 0} := by
suffices ContinuousOn (fun x => sin x / cos x) {x | cos x ≠ 0} by
have h_eq : (fun x => sin x / cos x) = tan := by ext1 x; rw [tan_eq_sin_div_cos]
rwa [h_eq] at this
exact continuousOn_sin.div continuousOn_cos fun x => id
@[continuity]
theorem continuous_tan : Continuous fun x : {x | cos x ≠ 0} => tan x :=
continuousOn_iff_continuous_restrict.1 continuousOn_tan
theorem continuousOn_tan_Ioo : ContinuousOn tan (Ioo (-(π / 2)) (π / 2)) := by
refine ContinuousOn.mono continuousOn_tan fun x => ?_
simp only [and_imp, mem_Ioo, mem_setOf_eq, Ne]
rw [cos_eq_zero_iff]
rintro hx_gt hx_lt ⟨r, hxr_eq⟩
rcases le_or_lt 0 r with h | h
· rw [lt_iff_not_ge] at hx_lt
refine hx_lt ?_
rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, mul_le_mul_right (half_pos pi_pos)]
simp [h]
· rw [lt_iff_not_ge] at hx_gt
refine hx_gt ?_
rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, neg_mul_eq_neg_mul,
mul_le_mul_right (half_pos pi_pos)]
have hr_le : r ≤ -1 := by rwa [Int.lt_iff_add_one_le, ← le_neg_iff_add_nonpos_right] at h
rw [← le_sub_iff_add_le, mul_comm, ← le_div_iff₀]
· norm_num
rw [← Int.cast_one, ← Int.cast_neg]; norm_cast
· exact zero_lt_two
theorem surjOn_tan : SurjOn tan (Ioo (-(π / 2)) (π / 2)) univ :=
have := neg_lt_self pi_div_two_pos
continuousOn_tan_Ioo.surjOn_of_tendsto (nonempty_Ioo.2 this)
(by rw [tendsto_comp_coe_Ioo_atBot this]; exact tendsto_tan_neg_pi_div_two)
(by rw [tendsto_comp_coe_Ioo_atTop this]; exact tendsto_tan_pi_div_two)
theorem tan_surjective : Function.Surjective tan := fun _ => surjOn_tan.subset_range trivial
theorem image_tan_Ioo : tan '' Ioo (-(π / 2)) (π / 2) = univ :=
univ_subset_iff.1 surjOn_tan
/-- `Real.tan` as an `OrderIso` between `(-(π / 2), π / 2)` and `ℝ`. -/
def tanOrderIso : Ioo (-(π / 2)) (π / 2) ≃o ℝ :=
(strictMonoOn_tan.orderIso _ _).trans <|
(OrderIso.setCongr _ _ image_tan_Ioo).trans OrderIso.Set.univ
/-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and
`arctan x < π / 2` -/
@[pp_nodot]
noncomputable def arctan (x : ℝ) : ℝ :=
tanOrderIso.symm x
@[simp]
theorem tan_arctan (x : ℝ) : tan (arctan x) = x :=
tanOrderIso.apply_symm_apply x
theorem arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(π / 2)) (π / 2) :=
Subtype.coe_prop _
@[simp]
theorem range_arctan : range arctan = Ioo (-(π / 2)) (π / 2) :=
((EquivLike.surjective _).range_comp _).trans Subtype.range_coe
theorem arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x :=
Subtype.ext_iff.1 <| tanOrderIso.symm_apply_apply ⟨x, hx₁, hx₂⟩
theorem cos_arctan_pos (x : ℝ) : 0 < cos (arctan x) :=
cos_pos_of_mem_Ioo <| arctan_mem_Ioo x
theorem cos_sq_arctan (x : ℝ) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) := by
rw_mod_cast [one_div, ← inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan]
theorem sin_arctan (x : ℝ) : sin (arctan x) = x / √(1 + x ^ 2) := by
rw_mod_cast [← tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
theorem cos_arctan (x : ℝ) : cos (arctan x) = 1 / √(1 + x ^ 2) := by
rw_mod_cast [one_div, ← inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
theorem arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 :=
(arctan_mem_Ioo x).2
theorem neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x :=
(arctan_mem_Ioo x).1
theorem arctan_eq_arcsin (x : ℝ) : arctan x = arcsin (x / √(1 + x ^ 2)) :=
Eq.symm <| arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo <| arctan_mem_Ioo x)
theorem arcsin_eq_arctan {x : ℝ} (h : x ∈ Ioo (-(1 : ℝ)) 1) :
arcsin x = arctan (x / √(1 - x ^ 2)) := by
rw_mod_cast [arctan_eq_arcsin, div_pow, sq_sqrt, one_add_div, div_div, ← sqrt_mul,
mul_div_cancel₀, sub_add_cancel, sqrt_one, div_one] <;> simp at h <;> nlinarith [h.1, h.2]
@[simp]
theorem arctan_zero : arctan 0 = 0 := by simp [arctan_eq_arcsin]
@[mono]
theorem arctan_strictMono : StrictMono arctan := tanOrderIso.symm.strictMono
@[gcongr]
lemma arctan_lt_arctan {x y : ℝ} (hxy : x < y) : arctan x < arctan y := arctan_strictMono hxy
@[gcongr]
lemma arctan_le_arctan {x y : ℝ} (hxy : x ≤ y) : arctan x ≤ arctan y :=
arctan_strictMono.monotone hxy
theorem arctan_injective : arctan.Injective := arctan_strictMono.injective
@[simp]
theorem arctan_eq_zero_iff {x : ℝ} : arctan x = 0 ↔ x = 0 :=
.trans (by rw [arctan_zero]) arctan_injective.eq_iff
theorem tendsto_arctan_atTop : Tendsto arctan atTop (𝓝[<] (π / 2)) :=
tendsto_Ioo_atTop.mp tanOrderIso.symm.tendsto_atTop
theorem tendsto_arctan_atBot : Tendsto arctan atBot (𝓝[>] (-(π / 2))) :=
tendsto_Ioo_atBot.mp tanOrderIso.symm.tendsto_atBot
theorem arctan_eq_of_tan_eq {x y : ℝ} (h : tan x = y) (hx : x ∈ Ioo (-(π / 2)) (π / 2)) :
arctan y = x :=
injOn_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h])
@[simp]
theorem arctan_one : arctan 1 = π / 4 :=
arctan_eq_of_tan_eq tan_pi_div_four <| by constructor <;> linarith [pi_pos]
@[simp]
theorem arctan_neg (x : ℝ) : arctan (-x) = -arctan x := by simp [arctan_eq_arcsin, neg_div]
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Arctan.lean | 178 | 179 | theorem arctan_eq_arccos {x : ℝ} (h : 0 ≤ x) : arctan x = arccos (√(1 + x ^ 2))⁻¹ := by | rw [arctan_eq_arcsin, arccos_eq_arcsin]; swap; · exact inv_nonneg.2 (sqrt_nonneg _) |
/-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.Constructions
/-!
# Neighborhoods and continuity relative to a subset
This file develops API on the relative versions
* `nhdsWithin` of `nhds`
* `ContinuousOn` of `Continuous`
* `ContinuousWithinAt` of `ContinuousAt`
related to continuity, which are defined in previous definition files.
Their basic properties studied in this file include the relationships between
these restricted notions and the corresponding notions for the subtype
equipped with the subspace topology.
## Notation
* `𝓝 x`: the filter of neighborhoods of a point `x`;
* `𝓟 s`: the principal filter of a set `s`;
* `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`.
-/
open Set Filter Function Topology Filter
variable {α β γ δ : Type*}
variable [TopologicalSpace α]
/-!
## Properties of the neighborhood-within filter
-/
@[simp]
theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a :=
bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl
@[simp]
theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x :=
Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x }
theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x :=
eventually_inf_principal
theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} :
(∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s :=
frequently_inf_principal.trans <| by simp only [and_comm]
theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} :
z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by
simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff]
@[simp]
theorem eventually_eventually_nhdsWithin {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by
refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩
simp only [eventually_nhdsWithin_iff] at h ⊢
exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs
@[simp]
theorem eventually_mem_nhdsWithin_iff {x : α} {s t : Set α} :
(∀ᶠ x' in 𝓝[s] x, t ∈ 𝓝[s] x') ↔ t ∈ 𝓝[s] x :=
eventually_eventually_nhdsWithin
theorem nhdsWithin_eq (a : α) (s : Set α) :
𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) :=
((nhds_basis_opens a).inf_principal s).eq_biInf
@[simp] lemma nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by
rw [nhdsWithin, principal_univ, inf_top_eq]
theorem nhdsWithin_hasBasis {ι : Sort*} {p : ι → Prop} {s : ι → Set α} {a : α}
(h : (𝓝 a).HasBasis p s) (t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t :=
h.inf_principal t
theorem nhdsWithin_basis_open (a : α) (t : Set α) :
(𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t :=
nhdsWithin_hasBasis (nhds_basis_opens a) t
theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} :
t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by
simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff
theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} :
t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t :=
(nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff
theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) :
s \ t ∈ 𝓝[tᶜ] x :=
diff_mem_inf_principal_compl hs t
theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) :
s \ t' ∈ 𝓝[t \ t'] x := by
rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc]
exact inter_mem_inf hs (mem_principal_self _)
| Mathlib/Topology/ContinuousOn.lean | 104 | 107 | theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) :
t ∈ 𝓝 a := by | rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩
exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw |
/-
Copyright (c) 2024 Sophie Morel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sophie Morel
-/
import Mathlib.Analysis.NormedSpace.PiTensorProduct.ProjectiveSeminorm
import Mathlib.LinearAlgebra.Isomorphisms
/-!
# Injective seminorm on the tensor of a finite family of normed spaces.
Let `𝕜` be a nontrivially normed field and `E` be a family of normed `𝕜`-vector spaces `Eᵢ`,
indexed by a finite type `ι`. We define a seminorm on `⨂[𝕜] i, Eᵢ`, which we call the
"injective seminorm". It is chosen to satisfy the following property: for every
normed `𝕜`-vector space `F`, the linear equivalence
`MultilinearMap 𝕜 E F ≃ₗ[𝕜] (⨂[𝕜] i, Eᵢ) →ₗ[𝕜] F`
expressing the universal property of the tensor product induces an isometric linear equivalence
`ContinuousMultilinearMap 𝕜 E F ≃ₗᵢ[𝕜] (⨂[𝕜] i, Eᵢ) →L[𝕜] F`.
The idea is the following: Every normed `𝕜`-vector space `F` defines a linear map
from `⨂[𝕜] i, Eᵢ` to `ContinuousMultilinearMap 𝕜 E F →ₗ[𝕜] F`, which sends `x` to the map
`f ↦ f.lift x`. Thanks to `PiTensorProduct.norm_eval_le_projectiveSeminorm`, this map lands in
`ContinuousMultilinearMap 𝕜 E F →L[𝕜] F`. As this last space has a natural operator (semi)norm,
we get an induced seminorm on `⨂[𝕜] i, Eᵢ`, which, by
`PiTensorProduct.norm_eval_le_projectiveSeminorm`, is bounded above by the projective seminorm
`PiTensorProduct.projectiveSeminorm`. We then take the `sup` of these seminorms as `F` varies;
as this family of seminorms is bounded, its `sup` has good properties.
In fact, we cannot take the `sup` over all normed spaces `F` because of set-theoretical issues,
so we only take spaces `F` in the same universe as `⨂[𝕜] i, Eᵢ`. We prove in
`norm_eval_le_injectiveSeminorm` that this gives the same result, because every multilinear map
from `E = Πᵢ Eᵢ` to `F` factors though a normed vector space in the same universe as
`⨂[𝕜] i, Eᵢ`.
We then prove the universal property and the functoriality of `⨂[𝕜] i, Eᵢ` as a normed vector
space.
## Main definitions
* `PiTensorProduct.toDualContinuousMultilinearMap`: The `𝕜`-linear map from
`⨂[𝕜] i, Eᵢ` to `ContinuousMultilinearMap 𝕜 E F →L[𝕜] F` sending `x` to the map
`f ↦ f x`.
* `PiTensorProduct.injectiveSeminorm`: The injective seminorm on `⨂[𝕜] i, Eᵢ`.
* `PiTensorProduct.liftEquiv`: The bijection between `ContinuousMultilinearMap 𝕜 E F`
and `(⨂[𝕜] i, Eᵢ) →L[𝕜] F`, as a continuous linear equivalence.
* `PiTensorProduct.liftIsometry`: The bijection between `ContinuousMultilinearMap 𝕜 E F`
and `(⨂[𝕜] i, Eᵢ) →L[𝕜] F`, as an isometric linear equivalence.
* `PiTensorProduct.tprodL`: The canonical continuous multilinear map from `E = Πᵢ Eᵢ`
to `⨂[𝕜] i, Eᵢ`.
* `PiTensorProduct.mapL`: The continuous linear map from `⨂[𝕜] i, Eᵢ` to `⨂[𝕜] i, E'ᵢ`
induced by a family of continuous linear maps `Eᵢ →L[𝕜] E'ᵢ`.
* `PiTensorProduct.mapLMultilinear`: The continuous multilinear map from
`Πᵢ (Eᵢ →L[𝕜] E'ᵢ)` to `(⨂[𝕜] i, Eᵢ) →L[𝕜] (⨂[𝕜] i, E'ᵢ)` sending a family
`f` to `PiTensorProduct.mapL f`.
## Main results
* `PiTensorProduct.norm_eval_le_injectiveSeminorm`: The main property of the injective seminorm
on `⨂[𝕜] i, Eᵢ`: for every `x` in `⨂[𝕜] i, Eᵢ` and every continuous multilinear map `f` from
`E = Πᵢ Eᵢ` to a normed space `F`, we have `‖f.lift x‖ ≤ ‖f‖ * injectiveSeminorm x `.
* `PiTensorProduct.mapL_opNorm`: If `f` is a family of continuous linear maps
`fᵢ : Eᵢ →L[𝕜] Fᵢ`, then `‖PiTensorProduct.mapL f‖ ≤ ∏ i, ‖fᵢ‖`.
* `PiTensorProduct.mapLMultilinear_opNorm` : If `F` is a normed vecteor space, then
`‖mapLMultilinear 𝕜 E F‖ ≤ 1`.
## TODO
* If all `Eᵢ` are separated and satisfy `SeparatingDual`, then the seminorm on
`⨂[𝕜] i, Eᵢ` is a norm. This uses the construction of a basis of the `PiTensorProduct`, hence
depends on PR https://github.com/leanprover-community/mathlib4/pull/11156. It should probably go in a separate file.
* Adapt the remaining functoriality constructions/properties from `PiTensorProduct`.
-/
universe uι u𝕜 uE uF
variable {ι : Type uι} [Fintype ι]
variable {𝕜 : Type u𝕜} [NontriviallyNormedField 𝕜]
variable {E : ι → Type uE} [∀ i, SeminormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)]
variable {F : Type uF} [SeminormedAddCommGroup F] [NormedSpace 𝕜 F]
open scoped TensorProduct
namespace PiTensorProduct
section seminorm
variable (F) in
/-- The linear map from `⨂[𝕜] i, Eᵢ` to `ContinuousMultilinearMap 𝕜 E F →L[𝕜] F` sending
`x` in `⨂[𝕜] i, Eᵢ` to the map `f ↦ f.lift x`.
-/
@[simps!]
noncomputable def toDualContinuousMultilinearMap : (⨂[𝕜] i, E i) →ₗ[𝕜]
ContinuousMultilinearMap 𝕜 E F →L[𝕜] F where
toFun x := LinearMap.mkContinuous
((LinearMap.flip (lift (R := 𝕜) (s := E) (E := F)).toLinearMap x) ∘ₗ
ContinuousMultilinearMap.toMultilinearMapLinear)
(projectiveSeminorm x)
(fun _ ↦ by simp only [LinearMap.coe_comp, Function.comp_apply,
ContinuousMultilinearMap.toMultilinearMapLinear_apply, LinearMap.flip_apply,
LinearEquiv.coe_coe]
exact norm_eval_le_projectiveSeminorm _ _ _)
map_add' x y := by
ext _
simp only [map_add, LinearMap.mkContinuous_apply, LinearMap.coe_comp, Function.comp_apply,
ContinuousMultilinearMap.toMultilinearMapLinear_apply, LinearMap.add_apply,
LinearMap.flip_apply, LinearEquiv.coe_coe, ContinuousLinearMap.add_apply]
map_smul' a x := by
ext _
simp only [map_smul, LinearMap.mkContinuous_apply, LinearMap.coe_comp, Function.comp_apply,
ContinuousMultilinearMap.toMultilinearMapLinear_apply, LinearMap.smul_apply,
LinearMap.flip_apply, LinearEquiv.coe_coe, RingHom.id_apply, ContinuousLinearMap.coe_smul',
Pi.smul_apply]
theorem toDualContinuousMultilinearMap_le_projectiveSeminorm (x : ⨂[𝕜] i, E i) :
‖toDualContinuousMultilinearMap F x‖ ≤ projectiveSeminorm x := by
simp only [toDualContinuousMultilinearMap, LinearMap.coe_mk, AddHom.coe_mk]
apply LinearMap.mkContinuous_norm_le _ (apply_nonneg _ _)
/-- The injective seminorm on `⨂[𝕜] i, Eᵢ`. Morally, it sends `x` in `⨂[𝕜] i, Eᵢ` to the
`sup` of the operator norms of the `PiTensorProduct.toDualContinuousMultilinearMap F x`, for all
normed vector spaces `F`. In fact, we only take in the same universe as `⨂[𝕜] i, Eᵢ`, and then
prove in `PiTensorProduct.norm_eval_le_injectiveSeminorm` that this gives the same result.
-/
noncomputable irreducible_def injectiveSeminorm : Seminorm 𝕜 (⨂[𝕜] i, E i) :=
sSup {p | ∃ (G : Type (max uι u𝕜 uE)) (_ : SeminormedAddCommGroup G)
(_ : NormedSpace 𝕜 G), p = Seminorm.comp (normSeminorm 𝕜 (ContinuousMultilinearMap 𝕜 E G →L[𝕜] G))
(toDualContinuousMultilinearMap G (𝕜 := 𝕜) (E := E))}
lemma dualSeminorms_bounded : BddAbove {p | ∃ (G : Type (max uι u𝕜 uE))
(_ : SeminormedAddCommGroup G) (_ : NormedSpace 𝕜 G),
p = Seminorm.comp (normSeminorm 𝕜 (ContinuousMultilinearMap 𝕜 E G →L[𝕜] G))
(toDualContinuousMultilinearMap G (𝕜 := 𝕜) (E := E))} := by
existsi projectiveSeminorm
rw [mem_upperBounds]
simp only [Set.mem_setOf_eq, forall_exists_index]
intro p G _ _ hp
rw [hp]
intro x
simp only [Seminorm.comp_apply, coe_normSeminorm]
exact toDualContinuousMultilinearMap_le_projectiveSeminorm _
theorem injectiveSeminorm_apply (x : ⨂[𝕜] i, E i) :
injectiveSeminorm x = ⨆ p : {p | ∃ (G : Type (max uι u𝕜 uE))
(_ : SeminormedAddCommGroup G) (_ : NormedSpace 𝕜 G), p = Seminorm.comp (normSeminorm 𝕜
(ContinuousMultilinearMap 𝕜 E G →L[𝕜] G))
(toDualContinuousMultilinearMap G (𝕜 := 𝕜) (E := E))}, p.1 x := by
simpa only [injectiveSeminorm, Set.coe_setOf, Set.mem_setOf_eq]
using Seminorm.sSup_apply dualSeminorms_bounded
theorem norm_eval_le_injectiveSeminorm (f : ContinuousMultilinearMap 𝕜 E F) (x : ⨂[𝕜] i, E i) :
‖lift f.toMultilinearMap x‖ ≤ ‖f‖ * injectiveSeminorm x := by
/- If `F` were in `Type (max uι u𝕜 uE)` (which is the type of `⨂[𝕜] i, E i`), then the
property that we want to prove would hold by definition of `injectiveSeminorm`. This is
not necessarily true, but we will show that there exists a normed vector space `G` in
`Type (max uι u𝕜 uE)` and an injective isometry from `G` to `F` such that `f` factors
through a continuous multilinear map `f'` from `E = Π i, E i` to `G`, to which we can apply
the definition of `injectiveSeminorm`. The desired inequality for `f` then follows
immediately.
The idea is very simple: the multilinear map `f` corresponds by `PiTensorProduct.lift`
to a linear map from `⨂[𝕜] i, E i` to `F`, say `l`. We want to take `G` to be the image of
`l`, with the norm induced from that of `F`; to make sure that we are in the correct universe,
it is actually more convenient to take `G` equal to the coimage of `l` (i.e. the quotient
of `⨂[𝕜] i, E i` by the kernel of `l`), which is canonically isomorphic to its image by
`LinearMap.quotKerEquivRange`. -/
set G := (⨂[𝕜] i, E i) ⧸ LinearMap.ker (lift f.toMultilinearMap)
set G' := LinearMap.range (lift f.toMultilinearMap)
set e := LinearMap.quotKerEquivRange (lift f.toMultilinearMap)
letI := SeminormedAddCommGroup.induced G G' e
letI := NormedSpace.induced 𝕜 G G' e
set f'₀ := lift.symm (e.symm.toLinearMap ∘ₗ LinearMap.rangeRestrict (lift f.toMultilinearMap))
have hf'₀ : ∀ (x : Π (i : ι), E i), ‖f'₀ x‖ ≤ ‖f‖ * ∏ i, ‖x i‖ := fun x ↦ by
change ‖e (f'₀ x)‖ ≤ _
simp only [lift_symm, LinearMap.compMultilinearMap_apply, LinearMap.coe_comp,
LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.apply_symm_apply, Submodule.coe_norm,
LinearMap.codRestrict_apply, lift.tprod, ContinuousMultilinearMap.coe_coe, e, f'₀]
exact f.le_opNorm x
set f' := MultilinearMap.mkContinuous f'₀ ‖f‖ hf'₀
have hnorm : ‖f'‖ ≤ ‖f‖ := (f'.opNorm_le_iff (norm_nonneg f)).mpr hf'₀
have heq : e (lift f'.toMultilinearMap x) = lift f.toMultilinearMap x := by
induction x using PiTensorProduct.induction_on with
| smul_tprod =>
simp only [lift_symm, map_smul, lift.tprod, ContinuousMultilinearMap.coe_coe,
MultilinearMap.coe_mkContinuous, LinearMap.compMultilinearMap_apply, LinearMap.coe_comp,
LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.apply_symm_apply, SetLike.val_smul,
LinearMap.codRestrict_apply, f', f'₀]
| add _ _ hx hy => simp only [map_add, Submodule.coe_add, hx, hy]
suffices h : ‖lift f'.toMultilinearMap x‖ ≤ ‖f'‖ * injectiveSeminorm x by
change ‖(e (lift f'.toMultilinearMap x)).1‖ ≤ _ at h
rw [heq] at h
exact le_trans h (mul_le_mul_of_nonneg_right hnorm (apply_nonneg _ _))
have hle : Seminorm.comp (normSeminorm 𝕜 (ContinuousMultilinearMap 𝕜 E G →L[𝕜] G))
(toDualContinuousMultilinearMap G (𝕜 := 𝕜) (E := E)) ≤ injectiveSeminorm := by
simp only [injectiveSeminorm]
refine le_csSup dualSeminorms_bounded ?_
rw [Set.mem_setOf]
existsi G, inferInstance, inferInstance
rfl
refine le_trans ?_ (mul_le_mul_of_nonneg_left (hle x) (norm_nonneg f'))
simp only [Seminorm.comp_apply, coe_normSeminorm, ← toDualContinuousMultilinearMap_apply_apply]
rw [mul_comm]
exact ContinuousLinearMap.le_opNorm _ _
theorem injectiveSeminorm_le_projectiveSeminorm :
injectiveSeminorm (𝕜 := 𝕜) (E := E) ≤ projectiveSeminorm := by
rw [injectiveSeminorm]
refine csSup_le ?_ ?_
· existsi 0
simp only [Set.mem_setOf_eq]
existsi PUnit, inferInstance, inferInstance
ext x
simp only [Seminorm.zero_apply, Seminorm.comp_apply, coe_normSeminorm]
rw [Subsingleton.elim (toDualContinuousMultilinearMap PUnit x) 0, norm_zero]
· intro p hp
simp only [Set.mem_setOf_eq] at hp
obtain ⟨G, _, _, h⟩ := hp
rw [h]; intro x; simp only [Seminorm.comp_apply, coe_normSeminorm]
exact toDualContinuousMultilinearMap_le_projectiveSeminorm _
theorem injectiveSeminorm_tprod_le (m : Π (i : ι), E i) :
injectiveSeminorm (⨂ₜ[𝕜] i, m i) ≤ ∏ i, ‖m i‖ :=
le_trans (injectiveSeminorm_le_projectiveSeminorm _) (projectiveSeminorm_tprod_le m)
noncomputable instance : SeminormedAddCommGroup (⨂[𝕜] i, E i) :=
AddGroupSeminorm.toSeminormedAddCommGroup injectiveSeminorm.toAddGroupSeminorm
noncomputable instance : NormedSpace 𝕜 (⨂[𝕜] i, E i) where
norm_smul_le a x := by
change injectiveSeminorm.toFun (a • x) ≤ _
rw [injectiveSeminorm.smul']
rfl
variable (𝕜 E F)
/-- The linear equivalence between `ContinuousMultilinearMap 𝕜 E F` and `(⨂[𝕜] i, Eᵢ) →L[𝕜] F`
induced by `PiTensorProduct.lift`, for every normed space `F`.
-/
@[simps]
noncomputable def liftEquiv : ContinuousMultilinearMap 𝕜 E F ≃ₗ[𝕜] (⨂[𝕜] i, E i) →L[𝕜] F where
toFun f := LinearMap.mkContinuous (lift f.toMultilinearMap) ‖f‖
(fun x ↦ norm_eval_le_injectiveSeminorm f x)
map_add' f g := by ext _; simp only [ContinuousMultilinearMap.toMultilinearMap_add, map_add,
LinearMap.mkContinuous_apply, LinearMap.add_apply, ContinuousLinearMap.add_apply]
map_smul' a f := by ext _; simp only [ContinuousMultilinearMap.toMultilinearMap_smul, map_smul,
LinearMap.mkContinuous_apply, LinearMap.smul_apply, RingHom.id_apply,
ContinuousLinearMap.coe_smul', Pi.smul_apply]
invFun l := MultilinearMap.mkContinuous (lift.symm l.toLinearMap) ‖l‖ (fun x ↦ by
simp only [lift_symm, LinearMap.compMultilinearMap_apply, ContinuousLinearMap.coe_coe]
refine le_trans (ContinuousLinearMap.le_opNorm _ _) (mul_le_mul_of_nonneg_left ?_
(norm_nonneg l))
exact injectiveSeminorm_tprod_le x)
left_inv f := by ext x; simp only [LinearMap.mkContinuous_coe, LinearEquiv.symm_apply_apply,
MultilinearMap.coe_mkContinuous, ContinuousMultilinearMap.coe_coe]
right_inv l := by
rw [← ContinuousLinearMap.coe_inj]
apply PiTensorProduct.ext; ext m
simp only [lift_symm, LinearMap.mkContinuous_coe, LinearMap.compMultilinearMap_apply,
lift.tprod, ContinuousMultilinearMap.coe_coe, MultilinearMap.coe_mkContinuous,
ContinuousLinearMap.coe_coe]
/-- For a normed space `F`, we have constructed in `PiTensorProduct.liftEquiv` the canonical
linear equivalence between `ContinuousMultilinearMap 𝕜 E F` and `(⨂[𝕜] i, Eᵢ) →L[𝕜] F`
(induced by `PiTensorProduct.lift`). Here we give the upgrade of this equivalence to
an isometric linear equivalence; in particular, it is a continuous linear equivalence.
-/
noncomputable def liftIsometry : ContinuousMultilinearMap 𝕜 E F ≃ₗᵢ[𝕜] (⨂[𝕜] i, E i) →L[𝕜] F :=
{ liftEquiv 𝕜 E F with
norm_map' := by
intro f
refine le_antisymm ?_ ?_
· simp only [liftEquiv, lift_symm, LinearEquiv.coe_mk]
exact LinearMap.mkContinuous_norm_le _ (norm_nonneg f) _
· conv_lhs => rw [← (liftEquiv 𝕜 E F).left_inv f]
simp only [liftEquiv, lift_symm, AddHom.toFun_eq_coe, AddHom.coe_mk,
LinearEquiv.invFun_eq_symm, LinearEquiv.coe_symm_mk, LinearMap.mkContinuous_coe,
LinearEquiv.coe_mk]
exact MultilinearMap.mkContinuous_norm_le _ (norm_nonneg _) _ }
variable {𝕜 E F}
@[simp]
| Mathlib/Analysis/NormedSpace/PiTensorProduct/InjectiveSeminorm.lean | 283 | 286 | theorem liftIsometry_apply_apply (f : ContinuousMultilinearMap 𝕜 E F) (x : ⨂[𝕜] i, E i) :
liftIsometry 𝕜 E F f x = lift f.toMultilinearMap x := by | simp only [liftIsometry, LinearIsometryEquiv.coe_mk, liftEquiv_apply,
LinearMap.mkContinuous_apply] |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Algebra.ModEq
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Ring.Periodic
import Mathlib.Data.Int.SuccPred
import Mathlib.Order.Circular
/-!
# Reducing to an interval modulo its length
This file defines operations that reduce a number (in an `Archimedean`
`LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that
interval.
## Main definitions
* `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ico a (a + p)`.
* `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`.
* `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ioc a (a + p)`.
* `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`.
-/
assert_not_exists TwoSidedIdeal
noncomputable section
section LinearOrderedAddCommGroup
variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [hα : Archimedean α]
{p : α} (hp : 0 < p)
{a b c : α} {n : ℤ}
section
include hp
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/
def toIcoDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose
theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1
theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) :
toIcoDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/
def toIocDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose
theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1
theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) :
toIocDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm
/-- Reduce `b` to the interval `Ico a (a + p)`. -/
def toIcoMod (a b : α) : α :=
b - toIcoDiv hp a b • p
/-- Reduce `b` to the interval `Ioc a (a + p)`. -/
def toIocMod (a b : α) : α :=
b - toIocDiv hp a b • p
theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) :=
sub_toIcoDiv_zsmul_mem_Ico hp a b
theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by
convert toIcoMod_mem_Ico hp 0 b
exact (zero_add p).symm
theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) :=
sub_toIocDiv_zsmul_mem_Ioc hp a b
theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1
theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1
theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2
theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2
@[simp]
theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b :=
rfl
@[simp]
theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b :=
rfl
@[simp]
theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by
rw [toIcoMod, neg_sub]
@[simp]
theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by
rw [toIocMod, neg_sub]
@[simp]
theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel]
@[simp]
theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel]
@[simp]
theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by
rw [toIcoMod, sub_add_cancel]
@[simp]
theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by
rw [toIocMod, sub_add_cancel]
@[simp]
theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by
rw [add_comm, toIcoMod_add_toIcoDiv_zsmul]
@[simp]
theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by
rw [add_comm, toIocMod_add_toIocDiv_zsmul]
theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod]
theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod]
@[simp]
theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
@[simp]
theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
@[simp]
theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩
theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩
theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by
refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by
refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by
rw [add_comm, toIcoDiv_add_zsmul, add_comm]
/-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/
@[simp]
theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by
rw [add_comm, toIocDiv_add_zsmul, add_comm]
/-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/
@[simp]
theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1
@[simp]
theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1
@[simp]
theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1
@[simp]
theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1
@[simp]
theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by
rw [add_comm, toIcoDiv_add_right]
@[simp]
theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by
rw [add_comm, toIcoDiv_add_right']
@[simp]
theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by
rw [add_comm, toIocDiv_add_right]
@[simp]
theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by
rw [add_comm, toIocDiv_add_right']
@[simp]
theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1
@[simp]
theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1
@[simp]
theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1
@[simp]
theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1
theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) :
toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by
apply toIcoDiv_eq_of_sub_zsmul_mem_Ico
rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm]
exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b
theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) :
toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm]
exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b
theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : α) :
toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by
rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg]
theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : α) :
toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by
rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg]
theorem toIcoDiv_neg (a b : α) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by
suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by
rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this
rw [← neg_eq_iff_eq_neg, eq_comm]
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b)
rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho
rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc
refine ⟨ho, hc.trans_eq ?_⟩
rw [neg_add, neg_add_cancel_right]
theorem toIcoDiv_neg' (a b : α) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b)
theorem toIocDiv_neg (a b : α) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by
rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right]
theorem toIocDiv_neg' (a b : α) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b)
@[simp]
theorem toIcoMod_add_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b + m • p) = toIcoMod hp a b := by
rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul]
abel
@[simp]
theorem toIcoMod_add_zsmul' (a b : α) (m : ℤ) :
toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p := by
simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIocMod_add_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b + m • p) = toIocMod hp a b := by
rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul]
abel
@[simp]
theorem toIocMod_add_zsmul' (a b : α) (m : ℤ) :
toIocMod hp (a + m • p) b = toIocMod hp a b + m • p := by
simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIcoMod_zsmul_add (a b : α) (m : ℤ) : toIcoMod hp a (m • p + b) = toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul]
@[simp]
theorem toIcoMod_zsmul_add' (a b : α) (m : ℤ) :
toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul', add_comm]
@[simp]
theorem toIocMod_zsmul_add (a b : α) (m : ℤ) : toIocMod hp a (m • p + b) = toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul]
@[simp]
theorem toIocMod_zsmul_add' (a b : α) (m : ℤ) :
toIocMod hp (m • p + a) b = m • p + toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul', add_comm]
@[simp]
| Mathlib/Algebra/Order/ToIntervalMod.lean | 377 | 379 | theorem toIcoMod_sub_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b - m • p) = toIcoMod hp a b := by | rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul] |
/-
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, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Group.Bounded
import Mathlib.Analysis.Normed.Group.Uniform
import Mathlib.Topology.MetricSpace.Thickening
/-!
# Properties of pointwise addition of sets in normed groups
We explore the relationships between pointwise addition of sets in normed groups, and the norm.
Notably, we show that the sum of bounded sets remain bounded.
-/
open Metric Set Pointwise Topology
variable {E : Type*}
section SeminormedGroup
variable [SeminormedGroup E] {s t : Set E}
-- note: we can't use `LipschitzOnWith.isBounded_image2` here without adding `[IsIsometricSMul E E]`
@[to_additive]
theorem Bornology.IsBounded.mul (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s * t) := by
obtain ⟨Rs, hRs⟩ : ∃ R, ∀ x ∈ s, ‖x‖ ≤ R := hs.exists_norm_le'
obtain ⟨Rt, hRt⟩ : ∃ R, ∀ x ∈ t, ‖x‖ ≤ R := ht.exists_norm_le'
refine isBounded_iff_forall_norm_le'.2 ⟨Rs + Rt, ?_⟩
rintro z ⟨x, hx, y, hy, rfl⟩
exact norm_mul_le_of_le' (hRs x hx) (hRt y hy)
@[to_additive]
theorem Bornology.IsBounded.of_mul (hst : IsBounded (s * t)) : IsBounded s ∨ IsBounded t :=
AntilipschitzWith.isBounded_of_image2_left _ (fun x => (isometry_mul_right x).antilipschitz) hst
@[to_additive]
theorem Bornology.IsBounded.inv : IsBounded s → IsBounded s⁻¹ := by
simp_rw [isBounded_iff_forall_norm_le', ← image_inv_eq_inv, forall_mem_image, norm_inv']
exact id
@[to_additive]
theorem Bornology.IsBounded.div (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s / t) :=
div_eq_mul_inv s t ▸ hs.mul ht.inv
end SeminormedGroup
section SeminormedCommGroup
variable [SeminormedCommGroup E] {δ : ℝ} {s : Set E} {x y : E}
section EMetric
open EMetric
@[to_additive (attr := simp)]
theorem infEdist_inv_inv (x : E) (s : Set E) : infEdist x⁻¹ s⁻¹ = infEdist x s := by
rw [← image_inv_eq_inv, infEdist_image isometry_inv]
@[to_additive]
theorem infEdist_inv (x : E) (s : Set E) : infEdist x⁻¹ s = infEdist x s⁻¹ := by
rw [← infEdist_inv_inv, inv_inv]
@[to_additive]
theorem ediam_mul_le (x y : Set E) : EMetric.diam (x * y) ≤ EMetric.diam x + EMetric.diam y :=
(LipschitzOnWith.ediam_image2_le (· * ·) _ _
(fun _ _ => (isometry_mul_right _).lipschitz.lipschitzOnWith) fun _ _ =>
(isometry_mul_left _).lipschitz.lipschitzOnWith).trans_eq <|
by simp only [ENNReal.coe_one, one_mul]
end EMetric
variable (δ s x y)
@[to_additive (attr := simp)]
theorem inv_thickening : (thickening δ s)⁻¹ = thickening δ s⁻¹ := by
simp_rw [thickening, ← infEdist_inv]
rfl
@[to_additive (attr := simp)]
theorem inv_cthickening : (cthickening δ s)⁻¹ = cthickening δ s⁻¹ := by
simp_rw [cthickening, ← infEdist_inv]
rfl
@[to_additive (attr := simp)]
theorem inv_ball : (ball x δ)⁻¹ = ball x⁻¹ δ := (IsometryEquiv.inv E).preimage_ball x δ
@[to_additive (attr := simp)]
theorem inv_closedBall : (closedBall x δ)⁻¹ = closedBall x⁻¹ δ :=
(IsometryEquiv.inv E).preimage_closedBall x δ
@[to_additive]
theorem singleton_mul_ball : {x} * ball y δ = ball (x * y) δ := by
simp only [preimage_mul_ball, image_mul_left, singleton_mul, div_inv_eq_mul, mul_comm y x]
@[to_additive]
theorem singleton_div_ball : {x} / ball y δ = ball (x / y) δ := by
simp_rw [div_eq_mul_inv, inv_ball, singleton_mul_ball]
@[to_additive]
theorem ball_mul_singleton : ball x δ * {y} = ball (x * y) δ := by
rw [mul_comm, singleton_mul_ball, mul_comm y]
@[to_additive]
theorem ball_div_singleton : ball x δ / {y} = ball (x / y) δ := by
simp_rw [div_eq_mul_inv, inv_singleton, ball_mul_singleton]
@[to_additive]
theorem singleton_mul_ball_one : {x} * ball 1 δ = ball x δ := by simp
@[to_additive]
theorem singleton_div_ball_one : {x} / ball 1 δ = ball x δ := by
rw [singleton_div_ball, div_one]
@[to_additive]
theorem ball_one_mul_singleton : ball 1 δ * {x} = ball x δ := by simp [ball_mul_singleton]
@[to_additive]
theorem ball_one_div_singleton : ball 1 δ / {x} = ball x⁻¹ δ := by
rw [ball_div_singleton, one_div]
@[to_additive]
theorem smul_ball_one : x • ball (1 : E) δ = ball x δ := by
rw [smul_ball, smul_eq_mul, mul_one]
@[to_additive (attr := simp 1100)]
theorem singleton_mul_closedBall : {x} * closedBall y δ = closedBall (x * y) δ := by
simp_rw [singleton_mul, ← smul_eq_mul, image_smul, smul_closedBall]
@[to_additive (attr := simp 1100)]
theorem singleton_div_closedBall : {x} / closedBall y δ = closedBall (x / y) δ := by
simp_rw [div_eq_mul_inv, inv_closedBall, singleton_mul_closedBall]
@[to_additive (attr := simp 1100)]
theorem closedBall_mul_singleton : closedBall x δ * {y} = closedBall (x * y) δ := by
simp [mul_comm _ {y}, mul_comm y]
@[to_additive (attr := simp 1100)]
theorem closedBall_div_singleton : closedBall x δ / {y} = closedBall (x / y) δ := by
simp [div_eq_mul_inv]
@[to_additive]
theorem singleton_mul_closedBall_one : {x} * closedBall 1 δ = closedBall x δ := by simp
@[to_additive]
| Mathlib/Analysis/Normed/Group/Pointwise.lean | 149 | 150 | theorem singleton_div_closedBall_one : {x} / closedBall 1 δ = closedBall x δ := by | rw [singleton_div_closedBall, div_one] |
/-
Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Bryan Gin-ge Chen, Yaël Dillies
-/
import Mathlib.Order.BooleanAlgebra
import Mathlib.Logic.Equiv.Basic
/-!
# Symmetric difference and bi-implication
This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras.
## Examples
Some examples are
* The symmetric difference of two sets is the set of elements that are in either but not both.
* The symmetric difference on propositions is `Xor'`.
* The symmetric difference on `Bool` is `Bool.xor`.
* The equivalence of propositions. Two propositions are equivalent if they imply each other.
* The symmetric difference translates to addition when considering a Boolean algebra as a Boolean
ring.
## Main declarations
* `symmDiff`: The symmetric difference operator, defined as `(a \ b) ⊔ (b \ a)`
* `bihimp`: The bi-implication operator, defined as `(b ⇨ a) ⊓ (a ⇨ b)`
In generalized Boolean algebras, the symmetric difference operator is:
* `symmDiff_comm`: commutative, and
* `symmDiff_assoc`: associative.
## Notations
* `a ∆ b`: `symmDiff a b`
* `a ⇔ b`: `bihimp a b`
## References
The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A
Proof from the Book" by John McCuan:
* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>
## Tags
boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication,
Heyting
-/
assert_not_exists RelIso
open Function OrderDual
variable {ι α β : Type*} {π : ι → Type*}
/-- The symmetric difference operator on a type with `⊔` and `\` is `(A \ B) ⊔ (B \ A)`. -/
def symmDiff [Max α] [SDiff α] (a b : α) : α :=
a \ b ⊔ b \ a
/-- The Heyting bi-implication is `(b ⇨ a) ⊓ (a ⇨ b)`. This generalizes equivalence of
propositions. -/
def bihimp [Min α] [HImp α] (a b : α) : α :=
(b ⇨ a) ⊓ (a ⇨ b)
/-- Notation for symmDiff -/
scoped[symmDiff] infixl:100 " ∆ " => symmDiff
/-- Notation for bihimp -/
scoped[symmDiff] infixl:100 " ⇔ " => bihimp
open scoped symmDiff
theorem symmDiff_def [Max α] [SDiff α] (a b : α) : a ∆ b = a \ b ⊔ b \ a :=
rfl
theorem bihimp_def [Min α] [HImp α] (a b : α) : a ⇔ b = (b ⇨ a) ⊓ (a ⇨ b) :=
rfl
theorem symmDiff_eq_Xor' (p q : Prop) : p ∆ q = Xor' p q :=
rfl
@[simp]
theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) :=
iff_iff_implies_and_implies.symm.trans Iff.comm
@[simp]
theorem Bool.symmDiff_eq_xor : ∀ p q : Bool, p ∆ q = xor p q := by decide
section GeneralizedCoheytingAlgebra
variable [GeneralizedCoheytingAlgebra α] (a b c : α)
@[simp]
theorem toDual_symmDiff : toDual (a ∆ b) = toDual a ⇔ toDual b :=
rfl
@[simp]
theorem ofDual_bihimp (a b : αᵒᵈ) : ofDual (a ⇔ b) = ofDual a ∆ ofDual b :=
rfl
theorem symmDiff_comm : a ∆ b = b ∆ a := by simp only [symmDiff, sup_comm]
instance symmDiff_isCommutative : Std.Commutative (α := α) (· ∆ ·) :=
⟨symmDiff_comm⟩
@[simp]
theorem symmDiff_self : a ∆ a = ⊥ := by rw [symmDiff, sup_idem, sdiff_self]
@[simp]
theorem symmDiff_bot : a ∆ ⊥ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq]
@[simp]
theorem bot_symmDiff : ⊥ ∆ a = a := by rw [symmDiff_comm, symmDiff_bot]
@[simp]
theorem symmDiff_eq_bot {a b : α} : a ∆ b = ⊥ ↔ a = b := by
simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff]
theorem symmDiff_of_le {a b : α} (h : a ≤ b) : a ∆ b = b \ a := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq]
theorem symmDiff_of_ge {a b : α} (h : b ≤ a) : a ∆ b = a \ b := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq]
theorem symmDiff_le {a b c : α} (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ∆ b ≤ c :=
sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb
theorem symmDiff_le_iff {a b c : α} : a ∆ b ≤ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := by
simp_rw [symmDiff, sup_le_iff, sdiff_le_iff]
@[simp]
theorem symmDiff_le_sup {a b : α} : a ∆ b ≤ a ⊔ b :=
sup_le_sup sdiff_le sdiff_le
theorem symmDiff_eq_sup_sdiff_inf : a ∆ b = (a ⊔ b) \ (a ⊓ b) := by simp [sup_sdiff, symmDiff]
theorem Disjoint.symmDiff_eq_sup {a b : α} (h : Disjoint a b) : a ∆ b = a ⊔ b := by
rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right]
theorem symmDiff_sdiff : a ∆ b \ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) := by
rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left]
@[simp]
theorem symmDiff_sdiff_inf : a ∆ b \ (a ⊓ b) = a ∆ b := by
rw [symmDiff_sdiff]
simp [symmDiff]
@[simp]
theorem symmDiff_sdiff_eq_sup : a ∆ (b \ a) = a ⊔ b := by
rw [symmDiff, sdiff_idem]
exact
le_antisymm (sup_le_sup sdiff_le sdiff_le)
(sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup)
@[simp]
| Mathlib/Order/SymmDiff.lean | 158 | 158 | theorem sdiff_symmDiff_eq_sup : (a \ b) ∆ b = a ⊔ b := by | |
/-
Copyright (c) 2022 Antoine Labelle, Rémi Bottinelli. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Labelle, Rémi Bottinelli
-/
import Mathlib.Combinatorics.Quiver.Basic
import Mathlib.Combinatorics.Quiver.Path
/-!
# Rewriting arrows and paths along vertex equalities
This files defines `Hom.cast` and `Path.cast` (and associated lemmas) in order to allow
rewriting arrows and paths along equalities of their endpoints.
-/
universe v v₁ v₂ u u₁ u₂
variable {U : Type*} [Quiver.{u + 1} U]
namespace Quiver
/-!
### Rewriting arrows along equalities of vertices
-/
/-- Change the endpoints of an arrow using equalities. -/
def Hom.cast {u v u' v' : U} (hu : u = u') (hv : v = v') (e : u ⟶ v) : u' ⟶ v' :=
Eq.ndrec (motive := (· ⟶ v')) (Eq.ndrec e hv) hu
theorem Hom.cast_eq_cast {u v u' v' : U} (hu : u = u') (hv : v = v') (e : u ⟶ v) :
e.cast hu hv = _root_.cast (by {rw [hu, hv]}) e := by
subst_vars
rfl
@[simp]
theorem Hom.cast_rfl_rfl {u v : U} (e : u ⟶ v) : e.cast rfl rfl = e :=
rfl
@[simp]
theorem Hom.cast_cast {u v u' v' u'' v'' : U} (e : u ⟶ v) (hu : u = u') (hv : v = v')
(hu' : u' = u'') (hv' : v' = v'') :
(e.cast hu hv).cast hu' hv' = e.cast (hu.trans hu') (hv.trans hv') := by
subst_vars
rfl
theorem Hom.cast_heq {u v u' v' : U} (hu : u = u') (hv : v = v') (e : u ⟶ v) :
HEq (e.cast hu hv) e := by
subst_vars
rfl
theorem Hom.cast_eq_iff_heq {u v u' v' : U} (hu : u = u') (hv : v = v') (e : u ⟶ v) (e' : u' ⟶ v') :
e.cast hu hv = e' ↔ HEq e e' := by
rw [Hom.cast_eq_cast]
exact _root_.cast_eq_iff_heq
theorem Hom.eq_cast_iff_heq {u v u' v' : U} (hu : u = u') (hv : v = v') (e : u ⟶ v) (e' : u' ⟶ v') :
e' = e.cast hu hv ↔ HEq e' e := by
rw [eq_comm, Hom.cast_eq_iff_heq]
exact ⟨HEq.symm, HEq.symm⟩
/-!
### Rewriting paths along equalities of vertices
-/
open Path
/-- Change the endpoints of a path using equalities. -/
def Path.cast {u v u' v' : U} (hu : u = u') (hv : v = v') (p : Path u v) : Path u' v' :=
Eq.ndrec (motive := (Path · v')) (Eq.ndrec p hv) hu
theorem Path.cast_eq_cast {u v u' v' : U} (hu : u = u') (hv : v = v') (p : Path u v) :
p.cast hu hv = _root_.cast (by rw [hu, hv]) p := by
subst_vars
rfl
@[simp]
theorem Path.cast_rfl_rfl {u v : U} (p : Path u v) : p.cast rfl rfl = p :=
rfl
@[simp]
theorem Path.cast_cast {u v u' v' u'' v'' : U} (p : Path u v) (hu : u = u') (hv : v = v')
(hu' : u' = u'') (hv' : v' = v'') :
(p.cast hu hv).cast hu' hv' = p.cast (hu.trans hu') (hv.trans hv') := by
subst_vars
rfl
@[simp]
theorem Path.cast_nil {u u' : U} (hu : u = u') : (Path.nil : Path u u).cast hu hu = Path.nil := by
subst_vars
rfl
theorem Path.cast_heq {u v u' v' : U} (hu : u = u') (hv : v = v') (p : Path u v) :
HEq (p.cast hu hv) p := by
rw [Path.cast_eq_cast]
exact _root_.cast_heq _ _
theorem Path.cast_eq_iff_heq {u v u' v' : U} (hu : u = u') (hv : v = v') (p : Path u v)
(p' : Path u' v') : p.cast hu hv = p' ↔ HEq p p' := by
rw [Path.cast_eq_cast]
exact _root_.cast_eq_iff_heq
theorem Path.eq_cast_iff_heq {u v u' v' : U} (hu : u = u') (hv : v = v') (p : Path u v)
(p' : Path u' v') : p' = p.cast hu hv ↔ HEq p' p :=
⟨fun h => ((p.cast_eq_iff_heq hu hv p').1 h.symm).symm, fun h =>
((p.cast_eq_iff_heq hu hv p').2 h.symm).symm⟩
theorem Path.cast_cons {u v w u' w' : U} (p : Path u v) (e : v ⟶ w) (hu : u = u') (hw : w = w') :
(p.cons e).cast hu hw = (p.cast hu rfl).cons (e.cast rfl hw) := by
subst_vars
rfl
| Mathlib/Combinatorics/Quiver/Cast.lean | 118 | 121 | theorem cast_eq_of_cons_eq_cons {u v v' w : U} {p : Path u v} {p' : Path u v'} {e : v ⟶ w}
{e' : v' ⟶ w} (h : p.cons e = p'.cons e') : p.cast rfl (obj_eq_of_cons_eq_cons h) = p' := by | rw [Path.cast_eq_iff_heq]
exact heq_of_cons_eq_cons h |
/-
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)]
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]
@[simp]
theorem Prod.mk_dvd_mk {x₁ y₁ : G₁} {x₂ y₂ : G₂} :
(x₁, x₂) ∣ (y₁, y₂) ↔ x₁ ∣ y₁ ∧ x₂ ∣ y₂ :=
prod_dvd_iff
instance [DecompositionMonoid G₁] [DecompositionMonoid G₂] : DecompositionMonoid (G₁ × G₂) where
primal a b c h := by
simp_rw [prod_dvd_iff] at h ⊢
obtain ⟨a₁, a₁', h₁, h₁', eq₁⟩ := DecompositionMonoid.primal a.1 h.1
obtain ⟨a₂, a₂', h₂, h₂', eq₂⟩ := DecompositionMonoid.primal a.2 h.2
-- aesop works here
exact ⟨(a₁, a₂), (a₁', a₂'), ⟨h₁, h₂⟩, ⟨h₁', h₂'⟩, Prod.ext eq₁ eq₂⟩
| Mathlib/Algebra/Divisibility/Prod.lean | 35 | 36 | theorem pi_dvd_iff {x y : ∀ i, G i} : x ∣ y ↔ ∀ i, x i ∣ y i := by | simp_rw [dvd_def, funext_iff, Classical.skolem]; rfl |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Analytic.Within
import Mathlib.Analysis.Calculus.FDeriv.Analytic
import Mathlib.Analysis.Calculus.ContDiff.FTaylorSeries
/-!
# Higher differentiability
A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous.
By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or,
equivalently, if it is `C^1` and its derivative is `C^{n-1}`.
It is `C^∞` if it is `C^n` for all n.
Finally, it is `C^ω` if it is analytic (as well as all its derivative, which is automatic if the
space is complete).
We formalize these notions with predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and
`ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set
and on the whole space respectively.
To avoid the issue of choice when choosing a derivative in sets where the derivative is not
necessarily unique, `ContDiffOn` is not defined directly in terms of the
regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the
existence of a nice sequence of derivatives, expressed with a predicate
`HasFTaylorSeriesUpToOn` defined in the file `FTaylorSeries`.
We prove basic properties of these notions.
## Main definitions and results
Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`.
* `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to
rank `n`.
* `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`.
* `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`.
* `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`.
In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the
properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space,
`ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f`
for `m ≤ n`.
## Implementation notes
The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more
complicated than the naive definitions one would guess from the intuition over the real or complex
numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity
in general. In the usual situations, they coincide with the usual definitions.
### Definition of `C^n` functions in domains
One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this
is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are
continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n`
functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a
function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`.
This definition still has the problem that a function which is locally `C^n` would not need to
be `C^n`, as different choices of sequences of derivatives around different points might possibly
not be glued together to give a globally defined sequence of derivatives. (Note that this issue
can not happen over reals, thanks to partition of unity, but the behavior over a general field is
not so clear, and we want a definition for general fields). Also, there are locality
problems for the order parameter: one could image a function which, for each `n`, has a nice
sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore
not be glued to give rise to an infinite sequence of derivatives. This would give a function
which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions
in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`.
The resulting definition is slightly more complicated to work with (in fact not so much), but it
gives rise to completely satisfactory theorems.
For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)`
for each natural `m` is by definition `C^∞` at `0`.
There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can
require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x`
within `s`. However, this does not imply continuity or differentiability within `s` of the function
at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on
a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file).
## Notations
We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with
values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives.
In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞`, and `⊤ : WithTop ℕ∞` with `ω`. To
avoid ambiguities with the two tops, the theorems name use either `infty` or `omega`.
These notations are scoped in `ContDiff`.
## Tags
derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series
-/
noncomputable section
open Set Fin Filter Function
open scoped NNReal Topology ContDiff
universe u uE uF uG uX
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG}
[NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X]
{s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : WithTop ℕ∞}
{p : E → FormalMultilinearSeries 𝕜 E F}
/-! ### Smooth functions within a set around a point -/
variable (𝕜) in
/-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if
it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`.
For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may
depend on the finite order we consider).
For `n = ω`, we require the function to be analytic within `s` at `x`. The precise definition we
give (all the derivatives should be analytic) is more involved to work around issues when the space
is not complete, but it is equivalent when the space is complete.
For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not
better, is `C^∞` at `0` within `univ`.
-/
def ContDiffWithinAt (n : WithTop ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop :=
match n with
| ω => ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F,
HasFTaylorSeriesUpToOn ω f p u ∧ ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u
| (n : ℕ∞) => ∀ m : ℕ, m ≤ n → ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u
lemma HasFTaylorSeriesUpToOn.analyticOn
(hf : HasFTaylorSeriesUpToOn ω f p s) (h : AnalyticOn 𝕜 (fun x ↦ p x 0) s) :
AnalyticOn 𝕜 f s := by
have : AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryFin0 𝕜 E F) (p x 0)) s :=
(LinearIsometryEquiv.analyticOnNhd _ _ ).comp_analyticOn
h (Set.mapsTo_univ _ _)
exact this.congr (fun y hy ↦ (hf.zero_eq _ hy).symm)
lemma ContDiffWithinAt.analyticOn (h : ContDiffWithinAt 𝕜 ω f s x) :
∃ u ∈ 𝓝[insert x s] x, AnalyticOn 𝕜 f u := by
obtain ⟨u, hu, p, hp, h'p⟩ := h
exact ⟨u, hu, hp.analyticOn (h'p 0)⟩
lemma ContDiffWithinAt.analyticWithinAt (h : ContDiffWithinAt 𝕜 ω f s x) :
AnalyticWithinAt 𝕜 f s x := by
obtain ⟨u, hu, hf⟩ := h.analyticOn
have xu : x ∈ u := mem_of_mem_nhdsWithin (by simp) hu
exact (hf x xu).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu)
theorem contDiffWithinAt_omega_iff_analyticWithinAt [CompleteSpace F] :
ContDiffWithinAt 𝕜 ω f s x ↔ AnalyticWithinAt 𝕜 f s x := by
refine ⟨fun h ↦ h.analyticWithinAt, fun h ↦ ?_⟩
obtain ⟨u, hu, p, hp, h'p⟩ := h.exists_hasFTaylorSeriesUpToOn ω
exact ⟨u, hu, p, hp.of_le le_top, fun i ↦ h'p i⟩
theorem contDiffWithinAt_nat {n : ℕ} :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u :=
⟨fun H => H n le_rfl, fun ⟨u, hu, p, hp⟩ _m hm => ⟨u, hu, p, hp.of_le (mod_cast hm)⟩⟩
/-- When `n` is either a natural number or `ω`, one can characterize the property of being `C^n`
as the existence of a neighborhood on which there is a Taylor series up to order `n`,
requiring in addition that its terms are analytic in the `ω` case. -/
lemma contDiffWithinAt_iff_of_ne_infty (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u ∧
(n = ω → ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u) := by
match n with
| ω => simp [ContDiffWithinAt]
| ∞ => simp at hn
| (n : ℕ) => simp [contDiffWithinAt_nat]
theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≤ n) :
ContDiffWithinAt 𝕜 m f s x := by
match n with
| ω => match m with
| ω => exact h
| (m : ℕ∞) =>
intro k _
obtain ⟨u, hu, p, hp, -⟩ := h
exact ⟨u, hu, p, hp.of_le le_top⟩
| (n : ℕ∞) => match m with
| ω => simp at hmn
| (m : ℕ∞) => exact fun k hk ↦ h k (le_trans hk (mod_cast hmn))
/-- In a complete space, a function which is analytic within a set at a point is also `C^ω` there.
Note that the same statement for `AnalyticOn` does not require completeness, see
`AnalyticOn.contDiffOn`. -/
theorem AnalyticWithinAt.contDiffWithinAt [CompleteSpace F] (h : AnalyticWithinAt 𝕜 f s x) :
ContDiffWithinAt 𝕜 n f s x :=
(contDiffWithinAt_omega_iff_analyticWithinAt.2 h).of_le le_top
theorem contDiffWithinAt_iff_forall_nat_le {n : ℕ∞} :
ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffWithinAt 𝕜 m f s x :=
⟨fun H _ hm => H.of_le (mod_cast hm), fun H m hm => H m hm _ le_rfl⟩
theorem contDiffWithinAt_infty :
ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top]
@[deprecated (since := "2024-11-25")] alias contDiffWithinAt_top := contDiffWithinAt_infty
theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) :
ContinuousWithinAt f s x := by
have := h.of_le (zero_le _)
simp only [ContDiffWithinAt, nonpos_iff_eq_zero, Nat.cast_eq_zero,
mem_pure, forall_eq, CharP.cast_eq_zero] at this
rcases this with ⟨u, hu, p, H⟩
rw [mem_nhdsWithin_insert] at hu
exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem_nhdsWithin hu.2
theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := by
match n with
| ω =>
obtain ⟨u, hu, p, H, H'⟩ := h
exact ⟨{x ∈ u | f₁ x = f x}, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p,
(H.mono (sep_subset _ _)).congr fun _ ↦ And.right,
fun i ↦ (H' i).mono (sep_subset _ _)⟩
| (n : ℕ∞) =>
intro m hm
let ⟨u, hu, p, H⟩ := h m hm
exact ⟨{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p,
(H.mono (sep_subset _ _)).congr fun _ ↦ And.right⟩
theorem Filter.EventuallyEq.congr_contDiffWithinAt (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq h₁.symm hx.symm, fun H ↦ H.congr_of_eventuallyEq h₁ hx⟩
theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁)
(mem_of_mem_nhdsWithin (mem_insert x s) h₁ :)
theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_insert (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq_insert h₁.symm, fun H ↦ H.congr_of_eventuallyEq_insert h₁⟩
theorem ContDiffWithinAt.congr_of_eventuallyEq_of_mem (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx
theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_mem (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s):
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq_of_mem h₁.symm hx, fun H ↦ H.congr_of_eventuallyEq_of_mem h₁ hx⟩
theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y)
(hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx
theorem contDiffWithinAt_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun h' ↦ h'.congr (fun x hx ↦ (h₁ x hx).symm) hx.symm, fun h' ↦ h'.congr h₁ hx⟩
theorem ContDiffWithinAt.congr_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y)
(hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr h₁ (h₁ _ hx)
theorem contDiffWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr h₁ (h₁ x hx)
theorem ContDiffWithinAt.congr_of_insert (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _))
theorem contDiffWithinAt_congr_of_insert (h₁ : ∀ y ∈ insert x s, f₁ y = f y) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _))
theorem ContDiffWithinAt.mono_of_mem_nhdsWithin (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E}
(hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by
match n with
| ω =>
obtain ⟨u, hu, p, H, H'⟩ := h
exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H, H'⟩
| (n : ℕ∞) =>
intro m hm
rcases h m hm with ⟨u, hu, p, H⟩
exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩
@[deprecated (since := "2024-10-30")]
alias ContDiffWithinAt.mono_of_mem := ContDiffWithinAt.mono_of_mem_nhdsWithin
theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) :
ContDiffWithinAt 𝕜 n f t x :=
h.mono_of_mem_nhdsWithin <| Filter.mem_of_superset self_mem_nhdsWithin hst
theorem ContDiffWithinAt.congr_mono
(h : ContDiffWithinAt 𝕜 n f s x) (h' : EqOn f₁ f s₁) (h₁ : s₁ ⊆ s) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s₁ x :=
(h.mono h₁).congr h' hx
theorem ContDiffWithinAt.congr_set (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E}
(hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f t x := by
rw [← nhdsWithin_eq_iff_eventuallyEq] at hst
apply h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin
@[deprecated (since := "2024-10-23")]
alias ContDiffWithinAt.congr_nhds := ContDiffWithinAt.congr_set
theorem contDiffWithinAt_congr_set {t : Set E} (hst : s =ᶠ[𝓝 x] t) :
ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x :=
⟨fun h => h.congr_set hst, fun h => h.congr_set hst.symm⟩
@[deprecated (since := "2024-10-23")]
alias contDiffWithinAt_congr_nhds := contDiffWithinAt_congr_set
theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) :
ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr_set (mem_nhdsWithin_iff_eventuallyEq.1 h).symm
theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) :
ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h)
theorem contDiffWithinAt_insert_self :
ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by
match n with
| ω => simp [ContDiffWithinAt]
| (n : ℕ∞) => simp_rw [ContDiffWithinAt, insert_idem]
theorem contDiffWithinAt_insert {y : E} :
ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by
rcases eq_or_ne x y with (rfl | hx)
· exact contDiffWithinAt_insert_self
refine ⟨fun h ↦ h.mono (subset_insert _ _), fun h ↦ ?_⟩
apply h.mono_of_mem_nhdsWithin
simp [nhdsWithin_insert_of_ne hx, self_mem_nhdsWithin]
alias ⟨ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert
protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) :
ContDiffWithinAt 𝕜 n f (insert x s) x :=
h.insert'
theorem contDiffWithinAt_diff_singleton {y : E} :
ContDiffWithinAt 𝕜 n f (s \ {y}) x ↔ ContDiffWithinAt 𝕜 n f s x := by
rw [← contDiffWithinAt_insert, insert_diff_singleton, contDiffWithinAt_insert]
/-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable
within this set at this point. -/
theorem ContDiffWithinAt.differentiableWithinAt' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) :
DifferentiableWithinAt 𝕜 f (insert x s) x := by
rcases contDiffWithinAt_nat.1 (h.of_le hn) with ⟨u, hu, p, H⟩
rcases mem_nhdsWithin.1 hu with ⟨t, t_open, xt, tu⟩
rw [inter_comm] at tu
exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 <|
((H.mono tu).differentiableOn le_rfl) x ⟨mem_insert x s, xt⟩
theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) :
DifferentiableWithinAt 𝕜 f s x :=
(h.differentiableWithinAt' hn).mono (subset_insert x s)
/-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`
(and moreover the function is analytic when `n = ω`). -/
theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧
∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by
have h'n : n + 1 ≠ ∞ := by simpa using hn
constructor
· intro h
rcases (contDiffWithinAt_iff_of_ne_infty h'n).1 h with ⟨u, hu, p, Hp, H'p⟩
refine ⟨u, hu, ?_, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1),
fun y hy => Hp.hasFDerivWithinAt le_add_self hy, ?_⟩
· rintro rfl
exact Hp.analyticOn (H'p rfl 0)
apply (contDiffWithinAt_iff_of_ne_infty hn).2
refine ⟨u, ?_, fun y : E => (p y).shift, ?_⟩
· convert @self_mem_nhdsWithin _ _ x u
have : x ∈ insert x s := by simp
exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu)
· rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp
refine ⟨Hp.2.2, ?_⟩
rintro rfl i
change AnalyticOn 𝕜
(fun x ↦ (continuousMultilinearCurryRightEquiv' 𝕜 i E F) (p x (i + 1))) u
apply (LinearIsometryEquiv.analyticOnNhd _ _).comp_analyticOn
?_ (Set.mapsTo_univ _ _)
exact H'p rfl _
· rintro ⟨u, hu, hf, f', f'_eq_deriv, Hf'⟩
rw [contDiffWithinAt_iff_of_ne_infty h'n]
rcases (contDiffWithinAt_iff_of_ne_infty hn).1 Hf' with ⟨v, hv, p', Hp', p'_an⟩
refine ⟨v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_, ?_⟩
· apply Filter.inter_mem _ hu
apply nhdsWithin_le_of_mem hu
exact nhdsWithin_mono _ (subset_insert x u) hv
· rw [hasFTaylorSeriesUpToOn_succ_iff_right]
refine ⟨fun y _ => rfl, fun y hy => ?_, ?_⟩
· change
HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z))
(FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y
rw [← Function.comp_def _ f, LinearIsometryEquiv.comp_hasFDerivWithinAt_iff']
convert (f'_eq_deriv y hy.2).mono inter_subset_right
rw [← Hp'.zero_eq y hy.1]
ext z
change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) =
((p' y 0) 0) z
congr
norm_num [eq_iff_true_of_subsingleton]
· convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1
· ext x y
change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y
rw [init_snoc]
· ext x k v y
change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y))
(@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y
rw [snoc_last, init_snoc]
· intro h i
simp only [WithTop.add_eq_top, WithTop.one_ne_top, or_false] at h
match i with
| 0 =>
simp only [FormalMultilinearSeries.unshift]
apply AnalyticOnNhd.comp_analyticOn _ ((hf h).mono inter_subset_right)
(Set.mapsTo_univ _ _)
exact LinearIsometryEquiv.analyticOnNhd _ _
| i + 1 =>
simp only [FormalMultilinearSeries.unshift, Nat.succ_eq_add_one]
apply AnalyticOnNhd.comp_analyticOn _ ((p'_an h i).mono inter_subset_left)
(Set.mapsTo_univ _ _)
exact LinearIsometryEquiv.analyticOnNhd _ _
/-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives
are taken within the same set. -/
theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 (n + 1) f s x ↔
∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ (n = ω → AnalyticOn 𝕜 f u) ∧
∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by
refine ⟨fun hf => ?_, ?_⟩
· obtain ⟨u, hu, f_an, f', huf', hf'⟩ := (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).mp hf
obtain ⟨w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu
rw [inter_comm] at hwu
refine ⟨insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, ?_, f',
fun y hy => ?_, ?_⟩
· intro h
apply (f_an h).mono hwu
· refine ((huf' y <| hwu hy).mono hwu).mono_of_mem_nhdsWithin ?_
refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _))
exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2)
· exact hf'.mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu)
· rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt hn,
insert_eq_of_mem (mem_insert _ _)]
rintro ⟨u, hu, hus, f_an, f', huf', hf'⟩
exact ⟨u, hu, f_an, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩
/-! ### Smooth functions within a set -/
variable (𝕜) in
/-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it
admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`.
For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may
depend on the finite order we consider).
-/
def ContDiffOn (n : WithTop ℕ∞) (f : E → F) (s : Set E) : Prop :=
∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x
theorem HasFTaylorSeriesUpToOn.contDiffOn {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F}
(hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by
intro x hx m hm
use s
simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and]
exact ⟨f', hf.of_le (mod_cast hm)⟩
theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) :
ContDiffWithinAt 𝕜 n f s x :=
h x hx
theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) : ContDiffOn 𝕜 m f s := fun x hx =>
(h x hx).of_le hmn
theorem ContDiffWithinAt.contDiffOn' (hm : m ≤ n) (h' : m = ∞ → n = ω)
(h : ContDiffWithinAt 𝕜 n f s x) :
∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by
rcases eq_or_ne n ω with rfl | hn
· obtain ⟨t, ht, p, hp, h'p⟩ := h
rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩
rw [inter_comm] at hut
refine ⟨u, huo, hxu, ?_⟩
suffices ContDiffOn 𝕜 ω f (insert x s ∩ u) from this.of_le le_top
intro y hy
refine ⟨insert x s ∩ u, ?_, p, hp.mono hut, fun i ↦ (h'p i).mono hut⟩
simp only [insert_eq_of_mem, hy, self_mem_nhdsWithin]
· match m with
| ω => simp [hn] at hm
| ∞ => exact (hn (h' rfl)).elim
| (m : ℕ) =>
rcases contDiffWithinAt_nat.1 (h.of_le hm) with ⟨t, ht, p, hp⟩
rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩
rw [inter_comm] at hut
exact ⟨u, huo, hxu, (hp.mono hut).contDiffOn⟩
theorem ContDiffWithinAt.contDiffOn (hm : m ≤ n) (h' : m = ∞ → n = ω)
(h : ContDiffWithinAt 𝕜 n f s x) :
∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := by
obtain ⟨_u, uo, xu, h⟩ := h.contDiffOn' hm h'
exact ⟨_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩
theorem ContDiffOn.analyticOn (h : ContDiffOn 𝕜 ω f s) : AnalyticOn 𝕜 f s :=
fun x hx ↦ (h x hx).analyticWithinAt
/-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on
a neighborhood of this point. -/
theorem contDiffWithinAt_iff_contDiffOn_nhds (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ContDiffOn 𝕜 n f u := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, h'u⟩
exact ⟨u, hu, h'u.2⟩
· rcases h with ⟨u, u_mem, hu⟩
have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert x s) u_mem
exact (hu x this).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert x s) u_mem)
protected theorem ContDiffWithinAt.eventually (h : ContDiffWithinAt 𝕜 n f s x) (hn : n ≠ ∞) :
∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by
rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, _, hd⟩
have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u :=
(eventually_eventually_nhdsWithin.2 hu).and hu
refine this.mono fun y hy => (hd y hy.2).mono_of_mem_nhdsWithin ?_
exact nhdsWithin_mono y (subset_insert _ _) hy.1
theorem ContDiffOn.of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s :=
h.of_le le_self_add
theorem ContDiffOn.one_of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s :=
h.of_le le_add_self
theorem contDiffOn_iff_forall_nat_le {n : ℕ∞} :
ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffOn 𝕜 m f s :=
⟨fun H _ hm => H.of_le (mod_cast hm), fun H x hx m hm => H m hm x hx m le_rfl⟩
theorem contDiffOn_infty : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s :=
contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true]
@[deprecated (since := "2024-11-27")] alias contDiffOn_top := contDiffOn_infty
@[deprecated (since := "2024-11-27")]
alias contDiffOn_infty_iff_contDiffOn_omega := contDiffOn_infty
theorem contDiffOn_all_iff_nat :
(∀ (n : ℕ∞), ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by
refine ⟨fun H n => H n, ?_⟩
rintro H (_ | n)
exacts [contDiffOn_infty.2 H, H n]
theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx =>
(h x hx).continuousWithinAt
theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) :
ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx)
theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s :=
⟨fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩
theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t :=
fun x hx => (h x (hst hx)).mono hst
theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) :
ContDiffOn 𝕜 n f₁ s₁ :=
(hf.mono hs).congr h₁
/-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/
theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≤ n) :
DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn
/-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/
theorem contDiffOn_of_locally_contDiffOn
(h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by
intro x xs
rcases h x xs with ⟨u, u_open, xu, hu⟩
apply (contDiffWithinAt_inter _).1 (hu x ⟨xs, xu⟩)
exact IsOpen.mem_nhds u_open xu
/-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/
theorem contDiffOn_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) :
ContDiffOn 𝕜 (n + 1) f s ↔
∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by
constructor
· intro h x hx
rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).1 (h x hx) with
⟨u, hu, f_an, f', hf', Hf'⟩
rcases Hf'.contDiffOn le_rfl (by simp [hn]) with ⟨v, vu, v'u, hv⟩
rw [insert_eq_of_mem hx] at hu ⊢
have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
rw [insert_eq_of_mem xu] at vu v'u
exact ⟨v, nhdsWithin_le_of_mem hu vu, fun h ↦ (f_an h).mono v'u, f',
fun y hy ↦ (hf' y (v'u hy)).mono v'u, hv⟩
· intro h x hx
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn]
rcases h x hx with ⟨u, u_nhbd, f_an, f', hu, hf'⟩
have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd
exact ⟨u, u_nhbd, f_an, f', hu, hf' x this⟩
/-! ### Iterated derivative within a set -/
@[simp]
theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by
refine ⟨fun H => H.continuousOn, fun H => fun x hx m hm ↦ ?_⟩
have : (m : WithTop ℕ∞) = 0 := le_antisymm (mod_cast hm) bot_le
rw [this]
refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩
rw [hasFTaylorSeriesUpToOn_zero_iff]
exact ⟨by rwa [insert_eq_of_mem hx], fun x _ => by simp [ftaylorSeriesWithin]⟩
theorem contDiffWithinAt_zero (hx : x ∈ s) :
ContDiffWithinAt 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, ContinuousOn f (s ∩ u) := by
constructor
· intro h
obtain ⟨u, H, p, hp⟩ := h 0 le_rfl
refine ⟨u, ?_, ?_⟩
· simpa [hx] using H
· simp only [Nat.cast_zero, hasFTaylorSeriesUpToOn_zero_iff] at hp
exact hp.1.mono inter_subset_right
· rintro ⟨u, H, hu⟩
rw [← contDiffWithinAt_inter' H]
have h' : x ∈ s ∩ u := ⟨hx, mem_of_mem_nhdsWithin hx H⟩
exact (contDiffOn_zero.mpr hu).contDiffWithinAt h'
/-- When a function is `C^n` in a set `s` of unique differentiability, it admits
`ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/
protected theorem ContDiffOn.ftaylorSeriesWithin
(h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) :
HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin 𝕜 f s) s := by
constructor
· intro x _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro m hm x hx
have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hm
rcases (h x hx).of_le this _ le_rfl with ⟨u, hu, p, Hp⟩
rw [insert_eq_of_mem hx] at hu
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [inter_comm] at ho
have : p x m.succ = ftaylorSeriesWithin 𝕜 f s x m.succ := by
change p x m.succ = iteratedFDerivWithin 𝕜 m.succ f s x
rw [← iteratedFDerivWithin_inter_open o_open xo]
exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hx, xo⟩
rw [← this, ← hasFDerivWithinAt_inter (IsOpen.mem_nhds o_open xo)]
have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by
rintro y ⟨hy, yo⟩
change p y m = iteratedFDerivWithin 𝕜 m f s y
rw [← iteratedFDerivWithin_inter_open o_open yo]
exact
(Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn (mod_cast Nat.le_succ m)
(hs.inter o_open) ⟨hy, yo⟩
exact
((Hp.mono ho).fderivWithin m (mod_cast lt_add_one m) x ⟨hx, xo⟩).congr
(fun y hy => (A y hy).symm) (A x ⟨hx, xo⟩).symm
· intro m hm
apply continuousOn_of_locally_continuousOn
intro x hx
rcases (h x hx).of_le hm _ le_rfl with ⟨u, hu, p, Hp⟩
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [insert_eq_of_mem hx] at ho
rw [inter_comm] at ho
refine ⟨o, o_open, xo, ?_⟩
have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by
rintro y ⟨hy, yo⟩
change p y m = iteratedFDerivWithin 𝕜 m f s y
rw [← iteratedFDerivWithin_inter_open o_open yo]
exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hy, yo⟩
exact ((Hp.mono ho).cont m le_rfl).congr fun y hy => (A y hy).symm
theorem iteratedFDerivWithin_subset {n : ℕ} (st : s ⊆ t) (hs : UniqueDiffOn 𝕜 s)
(ht : UniqueDiffOn 𝕜 t) (h : ContDiffOn 𝕜 n f t) (hx : x ∈ s) :
iteratedFDerivWithin 𝕜 n f s x = iteratedFDerivWithin 𝕜 n f t x :=
(((h.ftaylorSeriesWithin ht).mono st).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl hs hx).symm
theorem ContDiffWithinAt.eventually_hasFTaylorSeriesUpToOn {f : E → F} {s : Set E} {a : E}
(h : ContDiffWithinAt 𝕜 n f s a) (hs : UniqueDiffOn 𝕜 s) (ha : a ∈ s) {m : ℕ} (hm : m ≤ n) :
∀ᶠ t in (𝓝[s] a).smallSets, HasFTaylorSeriesUpToOn m f (ftaylorSeriesWithin 𝕜 f s) t := by
rcases h.contDiffOn' hm (by simp) with ⟨U, hUo, haU, hfU⟩
have : ∀ᶠ t in (𝓝[s] a).smallSets, t ⊆ s ∩ U := by
rw [eventually_smallSets_subset]
exact inter_mem_nhdsWithin _ <| hUo.mem_nhds haU
refine this.mono fun t ht ↦ .mono ?_ ht
rw [insert_eq_of_mem ha] at hfU
refine (hfU.ftaylorSeriesWithin (hs.inter hUo)).congr_series fun k hk x hx ↦ ?_
exact iteratedFDerivWithin_inter_open hUo hx.2
/-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its
successive derivatives are also analytic. This does not require completeness of the space. See
also `AnalyticOn.contDiffOn_of_completeSpace`. -/
theorem AnalyticOn.contDiffOn (h : AnalyticOn 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 ω f s from this.of_le le_top
rcases h.exists_hasFTaylorSeriesUpToOn hs with ⟨p, hp⟩
intro x hx
refine ⟨s, ?_, p, hp⟩
rw [insert_eq_of_mem hx]
exact self_mem_nhdsWithin
/-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its
successive derivatives are also analytic. This does not require completeness of the space. See
also `AnalyticOnNhd.contDiffOn_of_completeSpace`. -/
theorem AnalyticOnNhd.contDiffOn (h : AnalyticOnNhd 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn hs
/-- An analytic function is automatically `C^ω` in a complete space -/
theorem AnalyticOn.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOn 𝕜 f s) :
ContDiffOn 𝕜 n f s :=
fun x hx ↦ (h x hx).contDiffWithinAt
/-- An analytic function is automatically `C^ω` in a complete space -/
theorem AnalyticOnNhd.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOnNhd 𝕜 f s) :
ContDiffOn 𝕜 n f s :=
h.analyticOn.contDiffOn_of_completeSpace
theorem contDiffOn_of_continuousOn_differentiableOn {n : ℕ∞}
(Hcont : ∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s)
(Hdiff : ∀ m : ℕ, m < n →
DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s) :
ContDiffOn 𝕜 n f s := by
intro x hx m hm
rw [insert_eq_of_mem hx]
refine ⟨s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩
constructor
· intro y _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro k hk y hy
convert (Hdiff k (lt_of_lt_of_le (mod_cast hk) (mod_cast hm)) y hy).hasFDerivWithinAt
· intro k hk
exact Hcont k (le_trans (mod_cast hk) (mod_cast hm))
theorem contDiffOn_of_differentiableOn {n : ℕ∞}
(h : ∀ m : ℕ, m ≤ n → DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) :
ContDiffOn 𝕜 n f s :=
contDiffOn_of_continuousOn_differentiableOn (fun m hm => (h m hm).continuousOn) fun m hm =>
h m (le_of_lt hm)
theorem contDiffOn_of_analyticOn_iteratedFDerivWithin
(h : ∀ m, AnalyticOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) :
ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 ω f s from this.of_le le_top
intro x hx
refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_, ?_⟩
· rw [insert_eq_of_mem hx]
constructor
· intro y _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro k _ y hy
exact ((h k).differentiableOn y hy).hasFDerivWithinAt
· intro k _
exact (h k).continuousOn
· intro i
rw [insert_eq_of_mem hx]
exact h i
theorem contDiffOn_omega_iff_analyticOn (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 ω f s ↔ AnalyticOn 𝕜 f s :=
⟨fun h m ↦ h.analyticOn m, fun h ↦ h.contDiffOn hs⟩
theorem ContDiffOn.continuousOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s)
(hmn : m ≤ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedFDerivWithin 𝕜 m f s) s :=
((h.of_le hmn).ftaylorSeriesWithin hs).cont m le_rfl
theorem ContDiffOn.differentiableOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s)
(hmn : m < n) (hs : UniqueDiffOn 𝕜 s) :
DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s := by
intro x hx
have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hmn
apply (((h.of_le this).ftaylorSeriesWithin hs).fderivWithin m ?_ x hx).differentiableWithinAt
exact_mod_cast lt_add_one m
theorem ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin {m : ℕ}
(h : ContDiffWithinAt 𝕜 n f s x) (hmn : m < n) (hs : UniqueDiffOn 𝕜 (insert x s)) :
DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f s) s x := by
have : (m + 1 : WithTop ℕ∞) ≠ ∞ := Ne.symm (ne_of_beq_false rfl)
rcases h.contDiffOn' (ENat.add_one_natCast_le_withTop_of_lt hmn) (by simp [this])
with ⟨u, uo, xu, hu⟩
set t := insert x s ∩ u
have A : t =ᶠ[𝓝[≠] x] s := by
simp only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter']
rw [← inter_assoc, nhdsWithin_inter_of_mem', ← diff_eq_compl_inter, insert_diff_of_mem,
diff_eq_compl_inter]
exacts [rfl, mem_nhdsWithin_of_mem_nhds (uo.mem_nhds xu)]
have B : iteratedFDerivWithin 𝕜 m f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 m f t :=
iteratedFDerivWithin_eventually_congr_set' _ A.symm _
have C : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f t) t x :=
hu.differentiableOn_iteratedFDerivWithin (Nat.cast_lt.2 m.lt_succ_self) (hs.inter uo) x
⟨mem_insert _ _, xu⟩
rw [differentiableWithinAt_congr_set' _ A] at C
exact C.congr_of_eventuallyEq (B.filter_mono inf_le_left) B.self_of_nhds
theorem contDiffOn_iff_continuousOn_differentiableOn {n : ℕ∞} (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s ↔
(∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧
∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s :=
⟨fun h => ⟨fun _m hm => h.continuousOn_iteratedFDerivWithin (mod_cast hm) hs,
fun _m hm => h.differentiableOn_iteratedFDerivWithin (mod_cast hm) hs⟩,
fun h => contDiffOn_of_continuousOn_differentiableOn h.1 h.2⟩
theorem contDiffOn_nat_iff_continuousOn_differentiableOn {n : ℕ} (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s ↔
(∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧
∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := by
rw [← WithTop.coe_natCast, contDiffOn_iff_continuousOn_differentiableOn hs]
simp
theorem contDiffOn_succ_of_fderivWithin (hf : DifferentiableOn 𝕜 f s)
(h' : n = ω → AnalyticOn 𝕜 f s)
(h : ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 (n + 1) f s := by
rcases eq_or_ne n ∞ with rfl | hn
· rw [ENat.coe_top_add_one, contDiffOn_infty]
intro m x hx
apply ContDiffWithinAt.of_le _ (show (m : WithTop ℕ∞) ≤ m + 1 from le_self_add)
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt (by simp),
insert_eq_of_mem hx]
exact ⟨s, self_mem_nhdsWithin, (by simp), fderivWithin 𝕜 f s,
fun y hy => (hf y hy).hasFDerivWithinAt, (h x hx).of_le (mod_cast le_top)⟩
· intro x hx
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn,
insert_eq_of_mem hx]
exact ⟨s, self_mem_nhdsWithin, h', fderivWithin 𝕜 f s,
fun y hy => (hf y hy).hasFDerivWithinAt, h x hx⟩
theorem contDiffOn_of_analyticOn_of_fderivWithin (hf : AnalyticOn 𝕜 f s)
(h : ContDiffOn 𝕜 ω (fun y ↦ fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 (ω + 1) f s from this.of_le le_top
exact contDiffOn_succ_of_fderivWithin hf.differentiableOn (fun _ ↦ hf) h
/-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is
differentiable there, and its derivative (expressed with `fderivWithin`) is `C^n`. -/
theorem contDiffOn_succ_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 (n + 1) f s ↔
DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧
ContDiffOn 𝕜 n (fderivWithin 𝕜 f s) s := by
refine ⟨fun H => ?_, fun h => contDiffOn_succ_of_fderivWithin h.1 h.2.1 h.2.2⟩
refine ⟨H.differentiableOn le_add_self, ?_, fun x hx => ?_⟩
· rintro rfl
exact H.analyticOn
have A (m : ℕ) (hm : m ≤ n) : ContDiffWithinAt 𝕜 m (fun y => fderivWithin 𝕜 f s y) s x := by
rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt (n := m) (ne_of_beq_false rfl)).1
(H.of_le (add_le_add_right hm 1) x hx) with ⟨u, hu, -, f', hff', hf'⟩
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [inter_comm, insert_eq_of_mem hx] at ho
have := hf'.mono ho
rw [contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds o_open xo))] at this
apply this.congr_of_eventuallyEq_of_mem _ hx
have : o ∩ s ∈ 𝓝[s] x := mem_nhdsWithin.2 ⟨o, o_open, xo, Subset.refl _⟩
rw [inter_comm] at this
refine Filter.eventuallyEq_of_mem this fun y hy => ?_
have A : fderivWithin 𝕜 f (s ∩ o) y = f' y :=
((hff' y (ho hy)).mono ho).fderivWithin (hs.inter o_open y hy)
rwa [fderivWithin_inter (o_open.mem_nhds hy.2)] at A
match n with
| ω => exact (H.analyticOn.fderivWithin hs).contDiffOn hs (n := ω) x hx
| ∞ => exact contDiffWithinAt_infty.2 (fun m ↦ A m (mod_cast le_top))
| (n : ℕ) => exact A n le_rfl
theorem contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 (n + 1) f s ↔ (n = ω → AnalyticOn 𝕜 f s) ∧
∃ f' : E → E →L[𝕜] F, ContDiffOn 𝕜 n f' s ∧ ∀ x, x ∈ s → HasFDerivWithinAt f (f' x) s x := by
rw [contDiffOn_succ_iff_fderivWithin hs]
refine ⟨fun h => ⟨h.2.1, fderivWithin 𝕜 f s, h.2.2,
fun x hx => (h.1 x hx).hasFDerivWithinAt⟩, fun ⟨f_an, h⟩ => ?_⟩
rcases h with ⟨f', h1, h2⟩
refine ⟨fun x hx => (h2 x hx).differentiableWithinAt, f_an, fun x hx => ?_⟩
exact (h1 x hx).congr_of_mem (fun y hy => (h2 y hy).fderivWithin (hs y hy)) hx
@[deprecated (since := "2024-11-27")]
alias contDiffOn_succ_iff_hasFDerivWithin := contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn
theorem contDiffOn_infty_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderivWithin 𝕜 f s) s := by
rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderivWithin hs]
simp
@[deprecated (since := "2024-11-27")]
alias contDiffOn_top_iff_fderivWithin := contDiffOn_infty_iff_fderivWithin
/-- A function is `C^(n + 1)` on an open domain if and only if it is
differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/
theorem contDiffOn_succ_iff_fderiv_of_isOpen (hs : IsOpen s) :
ContDiffOn 𝕜 (n + 1) f s ↔
DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧
ContDiffOn 𝕜 n (fderiv 𝕜 f) s := by
rw [contDiffOn_succ_iff_fderivWithin hs.uniqueDiffOn,
contDiffOn_congr fun x hx ↦ fderivWithin_of_isOpen hs hx]
theorem contDiffOn_infty_iff_fderiv_of_isOpen (hs : IsOpen s) :
ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderiv 𝕜 f) s := by
rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderiv_of_isOpen hs]
simp
@[deprecated (since := "2024-11-27")]
alias contDiffOn_top_iff_fderiv_of_isOpen := contDiffOn_infty_iff_fderiv_of_isOpen
protected theorem ContDiffOn.fderivWithin (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s)
(hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fderivWithin 𝕜 f s) s :=
((contDiffOn_succ_iff_fderivWithin hs).1 (hf.of_le hmn)).2.2
theorem ContDiffOn.fderiv_of_isOpen (hf : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hmn : m + 1 ≤ n) :
ContDiffOn 𝕜 m (fderiv 𝕜 f) s :=
(hf.fderivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (fderivWithin_of_isOpen hs hx).symm
theorem ContDiffOn.continuousOn_fderivWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s)
(hn : 1 ≤ n) : ContinuousOn (fderivWithin 𝕜 f s) s :=
((contDiffOn_succ_iff_fderivWithin hs).1
(h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn
theorem ContDiffOn.continuousOn_fderiv_of_isOpen (h : ContDiffOn 𝕜 n f s) (hs : IsOpen s)
(hn : 1 ≤ n) : ContinuousOn (fderiv 𝕜 f) s :=
((contDiffOn_succ_iff_fderiv_of_isOpen hs).1
(h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn
/-! ### Smooth functions at a point -/
variable (𝕜) in
/-- A function is continuously differentiable up to `n` at a point `x` if, for any integer `k ≤ n`,
there is a neighborhood of `x` where `f` admits derivatives up to order `n`, which are continuous.
-/
def ContDiffAt (n : WithTop ℕ∞) (f : E → F) (x : E) : Prop :=
ContDiffWithinAt 𝕜 n f univ x
theorem contDiffWithinAt_univ : ContDiffWithinAt 𝕜 n f univ x ↔ ContDiffAt 𝕜 n f x :=
Iff.rfl
theorem contDiffAt_infty : ContDiffAt 𝕜 ∞ f x ↔ ∀ n : ℕ, ContDiffAt 𝕜 n f x := by
simp [← contDiffWithinAt_univ, contDiffWithinAt_infty]
@[deprecated (since := "2024-11-27")] alias contDiffAt_top := contDiffAt_infty
theorem ContDiffAt.contDiffWithinAt (h : ContDiffAt 𝕜 n f x) : ContDiffWithinAt 𝕜 n f s x :=
h.mono (subset_univ _)
theorem ContDiffWithinAt.contDiffAt (h : ContDiffWithinAt 𝕜 n f s x) (hx : s ∈ 𝓝 x) :
ContDiffAt 𝕜 n f x := by rwa [ContDiffAt, ← contDiffWithinAt_inter hx, univ_inter]
theorem contDiffWithinAt_iff_contDiffAt (h : s ∈ 𝓝 x) :
ContDiffWithinAt 𝕜 n f s x ↔ ContDiffAt 𝕜 n f x := by
rw [← univ_inter s, contDiffWithinAt_inter h, contDiffWithinAt_univ]
theorem IsOpen.contDiffOn_iff (hs : IsOpen s) :
ContDiffOn 𝕜 n f s ↔ ∀ ⦃a⦄, a ∈ s → ContDiffAt 𝕜 n f a :=
forall₂_congr fun _ => contDiffWithinAt_iff_contDiffAt ∘ hs.mem_nhds
theorem ContDiffOn.contDiffAt (h : ContDiffOn 𝕜 n f s) (hx : s ∈ 𝓝 x) :
ContDiffAt 𝕜 n f x :=
(h _ (mem_of_mem_nhds hx)).contDiffAt hx
theorem ContDiffAt.congr_of_eventuallyEq (h : ContDiffAt 𝕜 n f x) (hg : f₁ =ᶠ[𝓝 x] f) :
ContDiffAt 𝕜 n f₁ x :=
h.congr_of_eventuallyEq_of_mem (by rwa [nhdsWithin_univ]) (mem_univ x)
theorem ContDiffAt.of_le (h : ContDiffAt 𝕜 n f x) (hmn : m ≤ n) : ContDiffAt 𝕜 m f x :=
ContDiffWithinAt.of_le h hmn
theorem ContDiffAt.continuousAt (h : ContDiffAt 𝕜 n f x) : ContinuousAt f x := by
simpa [continuousWithinAt_univ] using h.continuousWithinAt
theorem ContDiffAt.analyticAt (h : ContDiffAt 𝕜 ω f x) : AnalyticAt 𝕜 f x := by
rw [← contDiffWithinAt_univ] at h
rw [← analyticWithinAt_univ]
exact h.analyticWithinAt
/-- In a complete space, a function which is analytic at a point is also `C^ω` there.
Note that the same statement for `AnalyticOn` does not require completeness, see
`AnalyticOn.contDiffOn`. -/
theorem AnalyticAt.contDiffAt [CompleteSpace F] (h : AnalyticAt 𝕜 f x) :
ContDiffAt 𝕜 n f x := by
rw [← contDiffWithinAt_univ]
rw [← analyticWithinAt_univ] at h
exact h.contDiffWithinAt
@[simp]
theorem contDiffWithinAt_compl_self :
ContDiffWithinAt 𝕜 n f {x}ᶜ x ↔ ContDiffAt 𝕜 n f x := by
rw [compl_eq_univ_diff, contDiffWithinAt_diff_singleton, contDiffWithinAt_univ]
/-- If a function is `C^n` with `n ≥ 1` at a point, then it is differentiable there. -/
theorem ContDiffAt.differentiableAt (h : ContDiffAt 𝕜 n f x) (hn : 1 ≤ n) :
DifferentiableAt 𝕜 f x := by
simpa [hn, differentiableWithinAt_univ] using h.differentiableWithinAt
nonrec lemma ContDiffAt.contDiffOn (h : ContDiffAt 𝕜 n f x) (hm : m ≤ n) (h' : m = ∞ → n = ω):
∃ u ∈ 𝓝 x, ContDiffOn 𝕜 m f u := by
simpa [nhdsWithin_univ] using h.contDiffOn hm h'
/-- A function is `C^(n + 1)` at a point iff locally, it has a derivative which is `C^n`. -/
theorem contDiffAt_succ_iff_hasFDerivAt {n : ℕ} :
ContDiffAt 𝕜 (n + 1) f x ↔ ∃ f' : E → E →L[𝕜] F,
(∃ u ∈ 𝓝 x, ∀ x ∈ u, HasFDerivAt f (f' x) x) ∧ ContDiffAt 𝕜 n f' x := by
rw [← contDiffWithinAt_univ, contDiffWithinAt_succ_iff_hasFDerivWithinAt (by simp)]
simp only [nhdsWithin_univ, exists_prop, mem_univ, insert_eq_of_mem]
constructor
· rintro ⟨u, H, -, f', h_fderiv, h_cont_diff⟩
rcases mem_nhds_iff.mp H with ⟨t, htu, ht, hxt⟩
refine ⟨f', ⟨t, ?_⟩, h_cont_diff.contDiffAt H⟩
refine ⟨mem_nhds_iff.mpr ⟨t, Subset.rfl, ht, hxt⟩, ?_⟩
intro y hyt
refine (h_fderiv y (htu hyt)).hasFDerivAt ?_
exact mem_nhds_iff.mpr ⟨t, htu, ht, hyt⟩
· rintro ⟨f', ⟨u, H, h_fderiv⟩, h_cont_diff⟩
refine ⟨u, H, by simp, f', fun x hxu ↦ ?_, h_cont_diff.contDiffWithinAt⟩
exact (h_fderiv x hxu).hasFDerivWithinAt
protected theorem ContDiffAt.eventually (h : ContDiffAt 𝕜 n f x) (h' : n ≠ ∞) :
∀ᶠ y in 𝓝 x, ContDiffAt 𝕜 n f y := by
simpa [nhdsWithin_univ] using ContDiffWithinAt.eventually h h'
theorem iteratedFDerivWithin_eq_iteratedFDeriv {n : ℕ}
(hs : UniqueDiffOn 𝕜 s) (h : ContDiffAt 𝕜 n f x) (hx : x ∈ s) :
iteratedFDerivWithin 𝕜 n f s x = iteratedFDeriv 𝕜 n f x := by
rw [← iteratedFDerivWithin_univ]
rcases h.contDiffOn' le_rfl (by simp) with ⟨u, u_open, xu, hu⟩
rw [← iteratedFDerivWithin_inter_open u_open xu,
← iteratedFDerivWithin_inter_open u_open xu (s := univ)]
apply iteratedFDerivWithin_subset
· exact inter_subset_inter_left _ (subset_univ _)
· exact hs.inter u_open
· apply uniqueDiffOn_univ.inter u_open
· simpa using hu
· exact ⟨hx, xu⟩
/-! ### Smooth functions -/
variable (𝕜) in
/-- A function is continuously differentiable up to `n` if it admits derivatives up to
order `n`, which are continuous. Contrary to the case of definitions in domains (where derivatives
might not be unique) we do not need to localize the definition in space or time.
-/
def ContDiff (n : WithTop ℕ∞) (f : E → F) : Prop :=
match n with
| ω => ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpTo ⊤ f p
∧ ∀ i, AnalyticOnNhd 𝕜 (fun x ↦ p x i) univ
| (n : ℕ∞) => ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpTo n f p
/-- If `f` has a Taylor series up to `n`, then it is `C^n`. -/
theorem HasFTaylorSeriesUpTo.contDiff {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F}
(hf : HasFTaylorSeriesUpTo n f f') : ContDiff 𝕜 n f :=
⟨f', hf⟩
theorem contDiffOn_univ : ContDiffOn 𝕜 n f univ ↔ ContDiff 𝕜 n f := by
match n with
| ω =>
constructor
· intro H
use ftaylorSeriesWithin 𝕜 f univ
rw [← hasFTaylorSeriesUpToOn_univ_iff]
refine ⟨H.ftaylorSeriesWithin uniqueDiffOn_univ, fun i ↦ ?_⟩
rw [← analyticOn_univ]
exact H.analyticOn.iteratedFDerivWithin uniqueDiffOn_univ _
· rintro ⟨p, hp, h'p⟩ x _
exact ⟨univ, Filter.univ_sets _, p, (hp.hasFTaylorSeriesUpToOn univ).of_le le_top,
fun i ↦ (h'p i).analyticOn⟩
| (n : ℕ∞) =>
constructor
· intro H
use ftaylorSeriesWithin 𝕜 f univ
rw [← hasFTaylorSeriesUpToOn_univ_iff]
exact H.ftaylorSeriesWithin uniqueDiffOn_univ
· rintro ⟨p, hp⟩ x _ m hm
exact ⟨univ, Filter.univ_sets _, p,
(hp.hasFTaylorSeriesUpToOn univ).of_le (mod_cast hm)⟩
theorem contDiff_iff_contDiffAt : ContDiff 𝕜 n f ↔ ∀ x, ContDiffAt 𝕜 n f x := by
simp [← contDiffOn_univ, ContDiffOn, ContDiffAt]
theorem ContDiff.contDiffAt (h : ContDiff 𝕜 n f) : ContDiffAt 𝕜 n f x :=
contDiff_iff_contDiffAt.1 h x
theorem ContDiff.contDiffWithinAt (h : ContDiff 𝕜 n f) : ContDiffWithinAt 𝕜 n f s x :=
h.contDiffAt.contDiffWithinAt
theorem contDiff_infty : ContDiff 𝕜 ∞ f ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by
simp [contDiffOn_univ.symm, contDiffOn_infty]
@[deprecated (since := "2024-11-25")] alias contDiff_top := contDiff_infty
@[deprecated (since := "2024-11-25")] alias contDiff_infty_iff_contDiff_omega := contDiff_infty
theorem contDiff_all_iff_nat : (∀ n : ℕ∞, ContDiff 𝕜 n f) ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by
simp only [← contDiffOn_univ, contDiffOn_all_iff_nat]
theorem ContDiff.contDiffOn (h : ContDiff 𝕜 n f) : ContDiffOn 𝕜 n f s :=
(contDiffOn_univ.2 h).mono (subset_univ _)
@[simp]
theorem contDiff_zero : ContDiff 𝕜 0 f ↔ Continuous f := by
rw [← contDiffOn_univ, continuous_iff_continuousOn_univ]
exact contDiffOn_zero
theorem contDiffAt_zero : ContDiffAt 𝕜 0 f x ↔ ∃ u ∈ 𝓝 x, ContinuousOn f u := by
rw [← contDiffWithinAt_univ]; simp [contDiffWithinAt_zero, nhdsWithin_univ]
theorem contDiffAt_one_iff :
ContDiffAt 𝕜 1 f x ↔
∃ f' : E → E →L[𝕜] F, ∃ u ∈ 𝓝 x, ContinuousOn f' u ∧ ∀ x ∈ u, HasFDerivAt f (f' x) x := by
rw [show (1 : WithTop ℕ∞) = (0 : ℕ) + 1 from rfl]
simp_rw [contDiffAt_succ_iff_hasFDerivAt, show ((0 : ℕ) : WithTop ℕ∞) = 0 from rfl,
contDiffAt_zero, exists_mem_and_iff antitone_bforall antitone_continuousOn, and_comm]
theorem ContDiff.of_le (h : ContDiff 𝕜 n f) (hmn : m ≤ n) : ContDiff 𝕜 m f :=
contDiffOn_univ.1 <| (contDiffOn_univ.2 h).of_le hmn
theorem ContDiff.of_succ (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 n f :=
h.of_le le_self_add
theorem ContDiff.one_of_succ (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 1 f := by
apply h.of_le le_add_self
theorem ContDiff.continuous (h : ContDiff 𝕜 n f) : Continuous f :=
contDiff_zero.1 (h.of_le bot_le)
/-- If a function is `C^n` with `n ≥ 1`, then it is differentiable. -/
theorem ContDiff.differentiable (h : ContDiff 𝕜 n f) (hn : 1 ≤ n) : Differentiable 𝕜 f :=
differentiableOn_univ.1 <| (contDiffOn_univ.2 h).differentiableOn hn
theorem contDiff_iff_forall_nat_le {n : ℕ∞} :
ContDiff 𝕜 n f ↔ ∀ m : ℕ, ↑m ≤ n → ContDiff 𝕜 m f := by
simp_rw [← contDiffOn_univ]; exact contDiffOn_iff_forall_nat_le
/-- A function is `C^(n+1)` iff it has a `C^n` derivative. -/
theorem contDiff_succ_iff_hasFDerivAt {n : ℕ} :
ContDiff 𝕜 (n + 1) f ↔
∃ f' : E → E →L[𝕜] F, ContDiff 𝕜 n f' ∧ ∀ x, HasFDerivAt f (f' x) x := by
simp only [← contDiffOn_univ, ← hasFDerivWithinAt_univ, Set.mem_univ, forall_true_left,
contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn uniqueDiffOn_univ,
WithTop.natCast_ne_top, analyticOn_univ, false_implies, true_and]
theorem contDiff_one_iff_hasFDerivAt : ContDiff 𝕜 1 f ↔
∃ f' : E → E →L[𝕜] F, Continuous f' ∧ ∀ x, HasFDerivAt f (f' x) x := by
convert contDiff_succ_iff_hasFDerivAt using 4; simp
theorem AnalyticOn.contDiff (hf : AnalyticOn 𝕜 f univ) : ContDiff 𝕜 n f := by
rw [← contDiffOn_univ]
exact hf.contDiffOn (n := n) uniqueDiffOn_univ
theorem AnalyticOnNhd.contDiff (hf : AnalyticOnNhd 𝕜 f univ) : ContDiff 𝕜 n f :=
hf.analyticOn.contDiff
theorem ContDiff.analyticOnNhd (h : ContDiff 𝕜 ω f) : AnalyticOnNhd 𝕜 f s := by
rw [← contDiffOn_univ] at h
have := h.analyticOn
rw [analyticOn_univ] at this
exact this.mono (subset_univ _)
theorem contDiff_omega_iff_analyticOnNhd :
ContDiff 𝕜 ω f ↔ AnalyticOnNhd 𝕜 f univ :=
⟨fun h ↦ h.analyticOnNhd, fun h ↦ h.contDiff⟩
/-! ### Iterated derivative -/
/-- When a function is `C^n`, it admits `ftaylorSeries 𝕜 f` as a Taylor series up
to order `n` in `s`. -/
theorem ContDiff.ftaylorSeries (hf : ContDiff 𝕜 n f) :
HasFTaylorSeriesUpTo n f (ftaylorSeries 𝕜 f) := by
simp only [← contDiffOn_univ, ← hasFTaylorSeriesUpToOn_univ_iff, ← ftaylorSeriesWithin_univ]
at hf ⊢
exact ContDiffOn.ftaylorSeriesWithin hf uniqueDiffOn_univ
/-- For `n : ℕ∞`, a function is `C^n` iff it admits `ftaylorSeries 𝕜 f`
as a Taylor series up to order `n`. -/
| Mathlib/Analysis/Calculus/ContDiff/Defs.lean | 1,160 | 1,176 | theorem contDiff_iff_ftaylorSeries {n : ℕ∞} :
ContDiff 𝕜 n f ↔ HasFTaylorSeriesUpTo n f (ftaylorSeries 𝕜 f) := by | constructor
· rw [← contDiffOn_univ, ← hasFTaylorSeriesUpToOn_univ_iff, ← ftaylorSeriesWithin_univ]
exact fun h ↦ ContDiffOn.ftaylorSeriesWithin h uniqueDiffOn_univ
· exact fun h ↦ ⟨ftaylorSeries 𝕜 f, h⟩
theorem contDiff_iff_continuous_differentiable {n : ℕ∞} :
ContDiff 𝕜 n f ↔
(∀ m : ℕ, m ≤ n → Continuous fun x => iteratedFDeriv 𝕜 m f x) ∧
∀ m : ℕ, m < n → Differentiable 𝕜 fun x => iteratedFDeriv 𝕜 m f x := by
simp [contDiffOn_univ.symm, continuous_iff_continuousOn_univ, differentiableOn_univ.symm,
iteratedFDerivWithin_univ, contDiffOn_iff_continuousOn_differentiableOn uniqueDiffOn_univ]
theorem contDiff_nat_iff_continuous_differentiable {n : ℕ} :
ContDiff 𝕜 n f ↔
(∀ m : ℕ, m ≤ n → Continuous fun x => iteratedFDeriv 𝕜 m f x) ∧ |
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Yaël Dillies
-/
import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap
/-!
# Integral average of a function
In this file we define `MeasureTheory.average μ f` (notation: `⨍ x, f x ∂μ`) to be the average
value of `f` with respect to measure `μ`. It is defined as `∫ x, f x ∂((μ univ)⁻¹ • μ)`, so it
is equal to zero if `f` is not integrable or if `μ` is an infinite measure. If `μ` is a probability
measure, then the average of any function is equal to its integral.
For the average on a set, we use `⨍ x in s, f x ∂μ` (notation for `⨍ x, f x ∂(μ.restrict s)`). For
average w.r.t. the volume, one can omit `∂volume`.
Both have a version for the Lebesgue integral rather than Bochner.
We prove several version of the first moment method: An integrable function is below/above its
average on a set of positive measure:
* `measure_le_setLAverage_pos` for the Lebesgue integral
* `measure_le_setAverage_pos` for the Bochner integral
## Implementation notes
The average is defined as an integral over `(μ univ)⁻¹ • μ` so that all theorems about Bochner
integrals work for the average without modifications. For theorems that require integrability of a
function, we provide a convenience lemma `MeasureTheory.Integrable.to_average`.
## Tags
integral, center mass, average value
-/
open ENNReal MeasureTheory MeasureTheory.Measure Metric Set Filter TopologicalSpace Function
open scoped Topology ENNReal Convex
variable {α E F : Type*} {m0 : MeasurableSpace α} [NormedAddCommGroup E] [NormedSpace ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {μ ν : Measure α}
{s t : Set α}
/-!
### Average value of a function w.r.t. a measure
The (Bochner, Lebesgue) average value of a function `f` w.r.t. a measure `μ` (notation:
`⨍ x, f x ∂μ`, `⨍⁻ x, f x ∂μ`) is defined as the (Bochner, Lebesgue) integral divided by the total
measure, so it is equal to zero if `μ` is an infinite measure, and (typically) equal to infinity if
`f` is not integrable. If `μ` is a probability measure, then the average of any function is equal to
its integral.
-/
namespace MeasureTheory
section ENNReal
variable (μ) {f g : α → ℝ≥0∞}
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`, denoted `⨍⁻ x, f x ∂μ`.
It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If
`μ` is a probability measure, then the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
noncomputable def laverage (f : α → ℝ≥0∞) := ∫⁻ x, f x ∂(μ univ)⁻¹ • μ
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`.
It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If
`μ` is a probability measure, then the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => laverage μ r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure.
It is equal to `(volume univ)⁻¹ * ∫⁻ x, f x`, so it takes value zero if the space has infinite
measure. In a probability space, the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x`, defined as `⨍⁻ x, f x ∂(volume.restrict s)`. -/
notation3 "⨍⁻ "(...)", "r:60:(scoped f => laverage volume f) => r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ` on a set `s`.
It is equal to `(μ s)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `s` has infinite measure. If `s`
has measure `1`, then the average of any function is equal to its integral.
For the average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => laverage (Measure.restrict μ s) r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure on a set `s`.
It is equal to `(volume s)⁻¹ * ∫⁻ x, f x`, so it takes value zero if `s` has infinite measure. If
`s` has measure `1`, then the average of any function is equal to its integral. -/
notation3 (prettyPrint := false)
"⨍⁻ "(...)" in "s", "r:60:(scoped f => laverage Measure.restrict volume s f) => r
@[simp]
theorem laverage_zero : ⨍⁻ _x, (0 : ℝ≥0∞) ∂μ = 0 := by rw [laverage, lintegral_zero]
@[simp]
theorem laverage_zero_measure (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂(0 : Measure α) = 0 := by simp [laverage]
theorem laverage_eq' (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂(μ univ)⁻¹ • μ := rfl
theorem laverage_eq (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = (∫⁻ x, f x ∂μ) / μ univ := by
rw [laverage_eq', lintegral_smul_measure, ENNReal.div_eq_inv_mul, smul_eq_mul]
theorem laverage_eq_lintegral [IsProbabilityMeasure μ] (f : α → ℝ≥0∞) :
⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [laverage, measure_univ, inv_one, one_smul]
@[simp]
theorem measure_mul_laverage [IsFiniteMeasure μ] (f : α → ℝ≥0∞) :
μ univ * ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by
rcases eq_or_ne μ 0 with hμ | hμ
· rw [hμ, lintegral_zero_measure, laverage_zero_measure, mul_zero]
· rw [laverage_eq, ENNReal.mul_div_cancel (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)]
| Mathlib/MeasureTheory/Integral/Average.lean | 122 | 123 | theorem setLAverage_eq (f : α → ℝ≥0∞) (s : Set α) :
⨍⁻ x in s, f x ∂μ = (∫⁻ x in s, f x ∂μ) / μ s := by | rw [laverage_eq, restrict_apply_univ] |
/-
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, Kexing Ying
-/
import Mathlib.Topology.Semicontinuous
import Mathlib.MeasureTheory.Function.AEMeasurableSequence
import Mathlib.MeasureTheory.Order.Lattice
import Mathlib.Topology.Order.Lattice
import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic
/-!
# Borel sigma algebras on spaces with orders
## Main statements
* `borel_eq_generateFrom_Ixx` (where Ixx is one of {Iio, Ioi, Iic, Ici, Ico, Ioc}):
The Borel sigma algebra of a linear order topology is generated by intervals of the given kind.
* `Dense.borel_eq_generateFrom_Ico_mem`, `Dense.borel_eq_generateFrom_Ioc_mem`:
The Borel sigma algebra of a dense linear order topology is generated by intervals of a given
kind, with endpoints from dense subsets.
* `ext_of_Ico`, `ext_of_Ioc`:
A locally finite Borel measure on a second countable conditionally complete linear order is
characterized by the measures of intervals of the given kind.
* `ext_of_Iic`, `ext_of_Ici`:
A finite Borel measure on a second countable linear order is characterized by the measures of
intervals of the given kind.
* `UpperSemicontinuous.measurable`, `LowerSemicontinuous.measurable`:
Semicontinuous functions are measurable.
* `Measurable.iSup`, `Measurable.iInf`, `Measurable.sSup`, `Measurable.sInf`:
Countable supremums and infimums of measurable functions to conditionally complete linear orders
are measurable.
* `Measurable.liminf`, `Measurable.limsup`:
Countable liminfs and limsups of measurable functions to conditionally complete linear orders
are measurable.
-/
open Set Filter MeasureTheory MeasurableSpace TopologicalSpace
open scoped Topology NNReal ENNReal MeasureTheory
universe u v w x y
variable {α β γ δ : Type*} {ι : Sort y} {s t u : Set α}
section OrderTopology
variable (α)
variable [TopologicalSpace α] [SecondCountableTopology α] [LinearOrder α] [OrderTopology α]
theorem borel_eq_generateFrom_Iio : borel α = .generateFrom (range Iio) := by
refine le_antisymm ?_ (generateFrom_le ?_)
· rw [borel_eq_generateFrom_of_subbasis (@OrderTopology.topology_eq_generate_intervals α _ _ _)]
letI : MeasurableSpace α := MeasurableSpace.generateFrom (range Iio)
have H : ∀ a : α, MeasurableSet (Iio a) := fun a => GenerateMeasurable.basic _ ⟨_, rfl⟩
refine generateFrom_le ?_
rintro _ ⟨a, rfl | rfl⟩
· rcases em (∃ b, a ⋖ b) with ⟨b, hb⟩ | hcovBy
· rw [hb.Ioi_eq, ← compl_Iio]
exact (H _).compl
· rcases isOpen_biUnion_countable (Ioi a) Ioi fun _ _ ↦ isOpen_Ioi with ⟨t, hat, htc, htU⟩
have : Ioi a = ⋃ b ∈ t, Ici b := by
refine Subset.antisymm ?_ <| iUnion₂_subset fun b hb ↦ Ici_subset_Ioi.2 (hat hb)
refine Subset.trans ?_ <| iUnion₂_mono fun _ _ ↦ Ioi_subset_Ici_self
simpa [CovBy, htU, subset_def] using hcovBy
simp only [this, ← compl_Iio]
exact .biUnion htc <| fun _ _ ↦ (H _).compl
· apply H
· rw [forall_mem_range]
intro a
exact GenerateMeasurable.basic _ isOpen_Iio
theorem borel_eq_generateFrom_Ioi : borel α = .generateFrom (range Ioi) :=
@borel_eq_generateFrom_Iio αᵒᵈ _ (by infer_instance : SecondCountableTopology α) _ _
theorem borel_eq_generateFrom_Iic :
borel α = MeasurableSpace.generateFrom (range Iic) := by
rw [borel_eq_generateFrom_Ioi]
refine le_antisymm ?_ ?_
· refine MeasurableSpace.generateFrom_le fun t ht => ?_
obtain ⟨u, rfl⟩ := ht
rw [← compl_Iic]
exact (MeasurableSpace.measurableSet_generateFrom (mem_range.mpr ⟨u, rfl⟩)).compl
· refine MeasurableSpace.generateFrom_le fun t ht => ?_
obtain ⟨u, rfl⟩ := ht
rw [← compl_Ioi]
exact (MeasurableSpace.measurableSet_generateFrom (mem_range.mpr ⟨u, rfl⟩)).compl
theorem borel_eq_generateFrom_Ici : borel α = MeasurableSpace.generateFrom (range Ici) :=
@borel_eq_generateFrom_Iic αᵒᵈ _ _ _ _
end OrderTopology
section Orders
variable [TopologicalSpace α] {mα : MeasurableSpace α} [OpensMeasurableSpace α]
variable {mδ : MeasurableSpace δ}
section Preorder
variable [Preorder α] [OrderClosedTopology α] {a b x : α} {μ : Measure α}
@[simp, measurability]
theorem measurableSet_Ici : MeasurableSet (Ici a) :=
isClosed_Ici.measurableSet
theorem nullMeasurableSet_Ici : NullMeasurableSet (Ici a) μ :=
measurableSet_Ici.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Iic : MeasurableSet (Iic a) :=
isClosed_Iic.measurableSet
theorem nullMeasurableSet_Iic : NullMeasurableSet (Iic a) μ :=
measurableSet_Iic.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Icc : MeasurableSet (Icc a b) :=
isClosed_Icc.measurableSet
theorem nullMeasurableSet_Icc : NullMeasurableSet (Icc a b) μ :=
measurableSet_Icc.nullMeasurableSet
instance nhdsWithin_Ici_isMeasurablyGenerated : (𝓝[Ici b] a).IsMeasurablyGenerated :=
measurableSet_Ici.nhdsWithin_isMeasurablyGenerated _
instance nhdsWithin_Iic_isMeasurablyGenerated : (𝓝[Iic b] a).IsMeasurablyGenerated :=
measurableSet_Iic.nhdsWithin_isMeasurablyGenerated _
instance nhdsWithin_Icc_isMeasurablyGenerated : IsMeasurablyGenerated (𝓝[Icc a b] x) := by
rw [← Ici_inter_Iic, nhdsWithin_inter]
infer_instance
instance atTop_isMeasurablyGenerated : (Filter.atTop : Filter α).IsMeasurablyGenerated :=
@Filter.iInf_isMeasurablyGenerated _ _ _ _ fun a =>
(measurableSet_Ici : MeasurableSet (Ici a)).principal_isMeasurablyGenerated
instance atBot_isMeasurablyGenerated : (Filter.atBot : Filter α).IsMeasurablyGenerated :=
@Filter.iInf_isMeasurablyGenerated _ _ _ _ fun a =>
(measurableSet_Iic : MeasurableSet (Iic a)).principal_isMeasurablyGenerated
instance [R1Space α] : IsMeasurablyGenerated (cocompact α) where
exists_measurable_subset := by
intro _ hs
obtain ⟨t, ht, hts⟩ := mem_cocompact.mp hs
exact ⟨(closure t)ᶜ, ht.closure.compl_mem_cocompact, isClosed_closure.measurableSet.compl,
(compl_subset_compl.2 subset_closure).trans hts⟩
end Preorder
section PartialOrder
variable [PartialOrder α] [OrderClosedTopology α] [SecondCountableTopology α] {a b : α}
@[measurability]
theorem measurableSet_le' : MeasurableSet { p : α × α | p.1 ≤ p.2 } :=
OrderClosedTopology.isClosed_le'.measurableSet
@[measurability]
theorem measurableSet_le {f g : δ → α} (hf : Measurable f) (hg : Measurable g) :
MeasurableSet { a | f a ≤ g a } :=
hf.prodMk hg measurableSet_le'
end PartialOrder
section LinearOrder
variable [LinearOrder α] [OrderClosedTopology α] {a b x : α} {μ : Measure α}
-- we open this locale only here to avoid issues with list being treated as intervals above
open Interval
@[simp, measurability]
theorem measurableSet_Iio : MeasurableSet (Iio a) :=
isOpen_Iio.measurableSet
theorem nullMeasurableSet_Iio : NullMeasurableSet (Iio a) μ :=
measurableSet_Iio.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Ioi : MeasurableSet (Ioi a) :=
isOpen_Ioi.measurableSet
theorem nullMeasurableSet_Ioi : NullMeasurableSet (Ioi a) μ :=
measurableSet_Ioi.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Ioo : MeasurableSet (Ioo a b) :=
isOpen_Ioo.measurableSet
theorem nullMeasurableSet_Ioo : NullMeasurableSet (Ioo a b) μ :=
measurableSet_Ioo.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Ioc : MeasurableSet (Ioc a b) :=
measurableSet_Ioi.inter measurableSet_Iic
theorem nullMeasurableSet_Ioc : NullMeasurableSet (Ioc a b) μ :=
measurableSet_Ioc.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Ico : MeasurableSet (Ico a b) :=
measurableSet_Ici.inter measurableSet_Iio
theorem nullMeasurableSet_Ico : NullMeasurableSet (Ico a b) μ :=
measurableSet_Ico.nullMeasurableSet
instance nhdsWithin_Ioi_isMeasurablyGenerated : (𝓝[Ioi b] a).IsMeasurablyGenerated :=
measurableSet_Ioi.nhdsWithin_isMeasurablyGenerated _
instance nhdsWithin_Iio_isMeasurablyGenerated : (𝓝[Iio b] a).IsMeasurablyGenerated :=
measurableSet_Iio.nhdsWithin_isMeasurablyGenerated _
instance nhdsWithin_uIcc_isMeasurablyGenerated : IsMeasurablyGenerated (𝓝[[[a, b]]] x) :=
nhdsWithin_Icc_isMeasurablyGenerated
@[measurability]
theorem measurableSet_lt' [SecondCountableTopology α] : MeasurableSet { p : α × α | p.1 < p.2 } :=
(isOpen_lt continuous_fst continuous_snd).measurableSet
@[measurability]
theorem measurableSet_lt [SecondCountableTopology α] {f g : δ → α} (hf : Measurable f)
(hg : Measurable g) : MeasurableSet { a | f a < g a } :=
hf.prodMk hg measurableSet_lt'
theorem nullMeasurableSet_lt [SecondCountableTopology α] {μ : Measure δ} {f g : δ → α}
(hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : NullMeasurableSet { a | f a < g a } μ :=
(hf.prodMk hg).nullMeasurable measurableSet_lt'
theorem nullMeasurableSet_lt' [SecondCountableTopology α] {μ : Measure (α × α)} :
NullMeasurableSet { p : α × α | p.1 < p.2 } μ :=
measurableSet_lt'.nullMeasurableSet
theorem nullMeasurableSet_le [SecondCountableTopology α] {μ : Measure δ}
{f g : δ → α} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
NullMeasurableSet { a | f a ≤ g a } μ :=
(hf.prodMk hg).nullMeasurable measurableSet_le'
theorem Set.OrdConnected.measurableSet (h : OrdConnected s) : MeasurableSet s := by
let u := ⋃ (x ∈ s) (y ∈ s), Ioo x y
have huopen : IsOpen u := isOpen_biUnion fun _ _ => isOpen_biUnion fun _ _ => isOpen_Ioo
have humeas : MeasurableSet u := huopen.measurableSet
have hfinite : (s \ u).Finite := s.finite_diff_iUnion_Ioo
have : u ⊆ s := iUnion₂_subset fun x hx => iUnion₂_subset fun y hy =>
Ioo_subset_Icc_self.trans (h.out hx hy)
rw [← union_diff_cancel this]
exact humeas.union hfinite.measurableSet
theorem IsPreconnected.measurableSet (h : IsPreconnected s) : MeasurableSet s :=
h.ordConnected.measurableSet
theorem generateFrom_Ico_mem_le_borel {α : Type*} [TopologicalSpace α] [LinearOrder α]
[OrderClosedTopology α] (s t : Set α) :
MeasurableSpace.generateFrom { S | ∃ l ∈ s, ∃ u ∈ t, l < u ∧ Ico l u = S }
≤ borel α := by
apply generateFrom_le
borelize α
rintro _ ⟨a, -, b, -, -, rfl⟩
exact measurableSet_Ico
theorem Dense.borel_eq_generateFrom_Ico_mem_aux {α : Type*} [TopologicalSpace α] [LinearOrder α]
[OrderTopology α] [SecondCountableTopology α] {s : Set α} (hd : Dense s)
(hbot : ∀ x, IsBot x → x ∈ s) (hIoo : ∀ x y : α, x < y → Ioo x y = ∅ → y ∈ s) :
borel α = .generateFrom { S : Set α | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ico l u = S } := by
set S : Set (Set α) := { S | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ico l u = S }
refine le_antisymm ?_ (generateFrom_Ico_mem_le_borel _ _)
letI : MeasurableSpace α := generateFrom S
rw [borel_eq_generateFrom_Iio]
refine generateFrom_le (forall_mem_range.2 fun a => ?_)
rcases hd.exists_countable_dense_subset_bot_top with ⟨t, hts, hc, htd, htb, -⟩
by_cases ha : ∀ b < a, (Ioo b a).Nonempty
· convert_to MeasurableSet (⋃ (l ∈ t) (u ∈ t) (_ : l < u) (_ : u ≤ a), Ico l u)
· ext y
simp only [mem_iUnion, mem_Iio, mem_Ico]
constructor
· intro hy
rcases htd.exists_le' (fun b hb => htb _ hb (hbot b hb)) y with ⟨l, hlt, hly⟩
rcases htd.exists_mem_open isOpen_Ioo (ha y hy) with ⟨u, hut, hyu, hua⟩
exact ⟨l, hlt, u, hut, hly.trans_lt hyu, hua.le, hly, hyu⟩
· rintro ⟨l, -, u, -, -, hua, -, hyu⟩
exact hyu.trans_le hua
· refine MeasurableSet.biUnion hc fun a ha => MeasurableSet.biUnion hc fun b hb => ?_
refine MeasurableSet.iUnion fun hab => MeasurableSet.iUnion fun _ => ?_
exact .basic _ ⟨a, hts ha, b, hts hb, hab, mem_singleton _⟩
· simp only [not_forall, not_nonempty_iff_eq_empty] at ha
replace ha : a ∈ s := hIoo ha.choose a ha.choose_spec.fst ha.choose_spec.snd
convert_to MeasurableSet (⋃ (l ∈ t) (_ : l < a), Ico l a)
· symm
simp only [← Ici_inter_Iio, ← iUnion_inter, inter_eq_right, subset_def, mem_iUnion,
mem_Ici, mem_Iio]
intro x hx
rcases htd.exists_le' (fun b hb => htb _ hb (hbot b hb)) x with ⟨z, hzt, hzx⟩
exact ⟨z, hzt, hzx.trans_lt hx, hzx⟩
· refine .biUnion hc fun x hx => MeasurableSet.iUnion fun hlt => ?_
exact .basic _ ⟨x, hts hx, a, ha, hlt, mem_singleton _⟩
theorem Dense.borel_eq_generateFrom_Ico_mem {α : Type*} [TopologicalSpace α] [LinearOrder α]
[OrderTopology α] [SecondCountableTopology α] [DenselyOrdered α] [NoMinOrder α] {s : Set α}
(hd : Dense s) :
borel α = .generateFrom { S : Set α | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ico l u = S } :=
hd.borel_eq_generateFrom_Ico_mem_aux (by simp) fun _ _ hxy H =>
((nonempty_Ioo.2 hxy).ne_empty H).elim
| Mathlib/MeasureTheory/Constructions/BorelSpace/Order.lean | 305 | 310 | theorem borel_eq_generateFrom_Ico (α : Type*) [TopologicalSpace α] [SecondCountableTopology α]
[LinearOrder α] [OrderTopology α] :
borel α = .generateFrom { S : Set α | ∃ (l u : α), l < u ∧ Ico l u = S } := by | simpa only [exists_prop, mem_univ, true_and] using
(@dense_univ α _).borel_eq_generateFrom_Ico_mem_aux (fun _ _ => mem_univ _) fun _ _ _ _ =>
mem_univ _ |
/-
Copyright (c) 2019 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Regular.Basic
import Mathlib.GroupTheory.MonoidLocalization.Basic
import Mathlib.LinearAlgebra.Matrix.MvPolynomial
import Mathlib.LinearAlgebra.Matrix.Polynomial
import Mathlib.RingTheory.Polynomial.Basic
/-!
# Cramer's rule and adjugate matrices
The adjugate matrix is the transpose of the cofactor matrix.
It is calculated with Cramer's rule, which we introduce first.
The vectors returned by Cramer's rule are given by the linear map `cramer`,
which sends a matrix `A` and vector `b` to the vector consisting of the
determinant of replacing the `i`th column of `A` with `b` at index `i`
(written as `(A.update_column i b).det`).
Using Cramer's rule, we can compute for each matrix `A` the matrix `adjugate A`.
The entries of the adjugate are the minors of `A`.
Instead of defining a minor by deleting row `i` and column `j` of `A`, we
replace the `i`th row of `A` with the `j`th basis vector; the resulting matrix
has the same determinant but more importantly equals Cramer's rule applied
to `A` and the `j`th basis vector, simplifying the subsequent proofs.
We prove the adjugate behaves like `det A • A⁻¹`.
## Main definitions
* `Matrix.cramer A b`: the vector output by Cramer's rule on `A` and `b`.
* `Matrix.adjugate A`: the adjugate (or classical adjoint) of the matrix `A`.
## References
* https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix
## Tags
cramer, cramer's rule, adjugate
-/
namespace Matrix
universe u v w
variable {m : Type u} {n : Type v} {α : Type w}
variable [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m] [CommRing α]
open Matrix Polynomial Equiv Equiv.Perm Finset
section Cramer
/-!
### `cramer` section
Introduce the linear map `cramer` with values defined by `cramerMap`.
After defining `cramerMap` and showing it is linear,
we will restrict our proofs to using `cramer`.
-/
variable (A : Matrix n n α) (b : n → α)
/-- `cramerMap A b i` is the determinant of the matrix `A` with column `i` replaced with `b`,
and thus `cramerMap A b` is the vector output by Cramer's rule on `A` and `b`.
If `A * x = b` has a unique solution in `x`, `cramerMap A` sends the vector `b` to `A.det • x`.
Otherwise, the outcome of `cramerMap` is well-defined but not necessarily useful.
-/
def cramerMap (i : n) : α :=
(A.updateCol i b).det
theorem cramerMap_is_linear (i : n) : IsLinearMap α fun b => cramerMap A b i :=
{ map_add := det_updateCol_add _ _
map_smul := det_updateCol_smul _ _ }
theorem cramer_is_linear : IsLinearMap α (cramerMap A) := by
constructor <;> intros <;> ext i
· apply (cramerMap_is_linear A i).1
· apply (cramerMap_is_linear A i).2
/-- `cramer A b i` is the determinant of the matrix `A` with column `i` replaced with `b`,
and thus `cramer A b` is the vector output by Cramer's rule on `A` and `b`.
If `A * x = b` has a unique solution in `x`, `cramer A` sends the vector `b` to `A.det • x`.
Otherwise, the outcome of `cramer` is well-defined but not necessarily useful.
-/
def cramer (A : Matrix n n α) : (n → α) →ₗ[α] (n → α) :=
IsLinearMap.mk' (cramerMap A) (cramer_is_linear A)
theorem cramer_apply (i : n) : cramer A b i = (A.updateCol i b).det :=
rfl
theorem cramer_transpose_apply (i : n) : cramer Aᵀ b i = (A.updateRow i b).det := by
rw [cramer_apply, updateCol_transpose, det_transpose]
theorem cramer_transpose_row_self (i : n) : Aᵀ.cramer (A i) = Pi.single i A.det := by
ext j
rw [cramer_apply, Pi.single_apply]
split_ifs with h
· -- i = j: this entry should be `A.det`
subst h
simp only [updateCol_transpose, det_transpose, updateRow_eq_self]
· -- i ≠ j: this entry should be 0
rw [updateCol_transpose, det_transpose]
apply det_zero_of_row_eq h
rw [updateRow_self, updateRow_ne (Ne.symm h)]
theorem cramer_row_self (i : n) (h : ∀ j, b j = A j i) : A.cramer b = Pi.single i A.det := by
rw [← transpose_transpose A, det_transpose]
convert cramer_transpose_row_self Aᵀ i
exact funext h
@[simp]
theorem cramer_one : cramer (1 : Matrix n n α) = 1 := by
ext i j
convert congr_fun (cramer_row_self (1 : Matrix n n α) (Pi.single i 1) i _) j
· simp
· intro j
rw [Matrix.one_eq_pi_single, Pi.single_comm]
theorem cramer_smul (r : α) (A : Matrix n n α) :
cramer (r • A) = r ^ (Fintype.card n - 1) • cramer A :=
LinearMap.ext fun _ => funext fun _ => det_updateCol_smul_left _ _ _ _
@[simp]
theorem cramer_subsingleton_apply [Subsingleton n] (A : Matrix n n α) (b : n → α) (i : n) :
cramer A b i = b i := by rw [cramer_apply, det_eq_elem_of_subsingleton _ i, updateCol_self]
theorem cramer_zero [Nontrivial n] : cramer (0 : Matrix n n α) = 0 := by
ext i j
obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j
apply det_eq_zero_of_column_eq_zero j'
intro j''
simp [updateCol_ne hj']
/-- Use linearity of `cramer` to take it out of a summation. -/
theorem sum_cramer {β} (s : Finset β) (f : β → n → α) :
(∑ x ∈ s, cramer A (f x)) = cramer A (∑ x ∈ s, f x) :=
(map_sum (cramer A) ..).symm
/-- Use linearity of `cramer` and vector evaluation to take `cramer A _ i` out of a summation. -/
theorem sum_cramer_apply {β} (s : Finset β) (f : n → β → α) (i : n) :
(∑ x ∈ s, cramer A (fun j => f j x) i) = cramer A (fun j : n => ∑ x ∈ s, f j x) i :=
calc
(∑ x ∈ s, cramer A (fun j => f j x) i) = (∑ x ∈ s, cramer A fun j => f j x) i :=
(Finset.sum_apply i s _).symm
_ = cramer A (fun j : n => ∑ x ∈ s, f j x) i := by
rw [sum_cramer, cramer_apply, cramer_apply]
simp only [updateCol]
congr with j
congr
apply Finset.sum_apply
theorem cramer_submatrix_equiv (A : Matrix m m α) (e : n ≃ m) (b : n → α) :
cramer (A.submatrix e e) b = cramer A (b ∘ e.symm) ∘ e := by
ext i
simp_rw [Function.comp_apply, cramer_apply, updateCol_submatrix_equiv,
det_submatrix_equiv_self e, Function.comp_def]
theorem cramer_reindex (e : m ≃ n) (A : Matrix m m α) (b : n → α) :
cramer (reindex e e A) b = cramer A (b ∘ e) ∘ e.symm :=
cramer_submatrix_equiv _ _ _
end Cramer
section Adjugate
/-!
### `adjugate` section
Define the `adjugate` matrix and a few equations.
These will hold for any matrix over a commutative ring.
-/
/-- The adjugate matrix is the transpose of the cofactor matrix.
Typically, the cofactor matrix is defined by taking minors,
i.e. the determinant of the matrix with a row and column removed.
However, the proof of `mul_adjugate` becomes a lot easier if we use the
matrix replacing a column with a basis vector, since it allows us to use
facts about the `cramer` map.
-/
def adjugate (A : Matrix n n α) : Matrix n n α :=
of fun i => cramer Aᵀ (Pi.single i 1)
theorem adjugate_def (A : Matrix n n α) : adjugate A = of fun i => cramer Aᵀ (Pi.single i 1) :=
rfl
theorem adjugate_apply (A : Matrix n n α) (i j : n) :
adjugate A i j = (A.updateRow j (Pi.single i 1)).det := by
rw [adjugate_def, of_apply, cramer_apply, updateCol_transpose, det_transpose]
theorem adjugate_transpose (A : Matrix n n α) : (adjugate A)ᵀ = adjugate Aᵀ := by
ext i j
rw [transpose_apply, adjugate_apply, adjugate_apply, updateRow_transpose, det_transpose]
rw [det_apply', det_apply']
apply Finset.sum_congr rfl
intro σ _
congr 1
by_cases h : i = σ j
· -- Everything except `(i , j)` (= `(σ j , j)`) is given by A, and the rest is a single `1`.
congr
ext j'
subst h
have : σ j' = σ j ↔ j' = j := σ.injective.eq_iff
rw [updateRow_apply, updateCol_apply]
simp_rw [this]
rw [← dite_eq_ite, ← dite_eq_ite]
congr 1 with rfl
rw [Pi.single_eq_same, Pi.single_eq_same]
· -- Otherwise, we need to show that there is a `0` somewhere in the product.
have : (∏ j' : n, updateCol A j (Pi.single i 1) (σ j') j') = 0 := by
apply prod_eq_zero (mem_univ j)
rw [updateCol_self, Pi.single_eq_of_ne' h]
rw [this]
apply prod_eq_zero (mem_univ (σ⁻¹ i))
erw [apply_symm_apply σ i, updateRow_self]
apply Pi.single_eq_of_ne
intro h'
exact h ((symm_apply_eq σ).mp h')
@[simp]
theorem adjugate_submatrix_equiv_self (e : n ≃ m) (A : Matrix m m α) :
adjugate (A.submatrix e e) = (adjugate A).submatrix e e := by
ext i j
have : (fun j ↦ Pi.single i 1 <| e.symm j) = Pi.single (e i) 1 :=
Function.update_comp_equiv (0 : n → α) e.symm i 1
rw [adjugate_apply, submatrix_apply, adjugate_apply, ← det_submatrix_equiv_self e,
updateRow_submatrix_equiv, this]
theorem adjugate_reindex (e : m ≃ n) (A : Matrix m m α) :
adjugate (reindex e e A) = reindex e e (adjugate A) :=
adjugate_submatrix_equiv_self _ _
/-- Since the map `b ↦ cramer A b` is linear in `b`, it must be multiplication by some matrix. This
matrix is `A.adjugate`. -/
theorem cramer_eq_adjugate_mulVec (A : Matrix n n α) (b : n → α) :
cramer A b = A.adjugate *ᵥ b := by
nth_rw 2 [← A.transpose_transpose]
rw [← adjugate_transpose, adjugate_def]
have : b = ∑ i, b i • (Pi.single i 1 : n → α) := by
refine (pi_eq_sum_univ b).trans ?_
congr with j
simp [Pi.single_apply, eq_comm]
conv_lhs =>
rw [this]
ext k
simp [mulVec, dotProduct, mul_comm]
theorem mul_adjugate_apply (A : Matrix n n α) (i j k) :
A i k * adjugate A k j = cramer Aᵀ (Pi.single k (A i k)) j := by
rw [← smul_eq_mul, adjugate, of_apply, ← Pi.smul_apply, ← LinearMap.map_smul, ← Pi.single_smul',
smul_eq_mul, mul_one]
theorem mul_adjugate (A : Matrix n n α) : A * adjugate A = A.det • (1 : Matrix n n α) := by
ext i j
rw [mul_apply, Pi.smul_apply, Pi.smul_apply, one_apply, smul_eq_mul, mul_boole]
simp [mul_adjugate_apply, sum_cramer_apply, cramer_transpose_row_self, Pi.single_apply, eq_comm]
theorem adjugate_mul (A : Matrix n n α) : adjugate A * A = A.det • (1 : Matrix n n α) :=
calc
adjugate A * A = (Aᵀ * adjugate Aᵀ)ᵀ := by
rw [← adjugate_transpose, ← transpose_mul, transpose_transpose]
_ = _ := by rw [mul_adjugate Aᵀ, det_transpose, transpose_smul, transpose_one]
theorem adjugate_smul (r : α) (A : Matrix n n α) :
adjugate (r • A) = r ^ (Fintype.card n - 1) • adjugate A := by
rw [adjugate, adjugate, transpose_smul, cramer_smul]
rfl
/-- A stronger form of **Cramer's rule** that allows us to solve some instances of `A * x = b` even
if the determinant is not a unit. A sufficient (but still not necessary) condition is that `A.det`
divides `b`. -/
@[simp]
theorem mulVec_cramer (A : Matrix n n α) (b : n → α) : A *ᵥ cramer A b = A.det • b := by
rw [cramer_eq_adjugate_mulVec, mulVec_mulVec, mul_adjugate, smul_mulVec_assoc, one_mulVec]
theorem adjugate_subsingleton [Subsingleton n] (A : Matrix n n α) : adjugate A = 1 := by
ext i j
simp [Subsingleton.elim i j, adjugate_apply, det_eq_elem_of_subsingleton _ i, one_apply]
theorem adjugate_eq_one_of_card_eq_one {A : Matrix n n α} (h : Fintype.card n = 1) :
adjugate A = 1 :=
haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le
adjugate_subsingleton _
@[simp]
theorem adjugate_zero [Nontrivial n] : adjugate (0 : Matrix n n α) = 0 := by
ext i j
obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j
apply det_eq_zero_of_column_eq_zero j'
intro j''
simp [updateCol_ne hj']
@[simp]
theorem adjugate_one : adjugate (1 : Matrix n n α) = 1 := by
ext
simp [adjugate_def, Matrix.one_apply, Pi.single_apply, eq_comm]
@[simp]
theorem adjugate_diagonal (v : n → α) :
adjugate (diagonal v) = diagonal fun i => ∏ j ∈ Finset.univ.erase i, v j := by
ext i j
simp only [adjugate_def, cramer_apply, diagonal_transpose, of_apply]
obtain rfl | hij := eq_or_ne i j
· rw [diagonal_apply_eq, diagonal_updateCol_single, det_diagonal,
prod_update_of_mem (Finset.mem_univ _), sdiff_singleton_eq_erase, one_mul]
· rw [diagonal_apply_ne _ hij]
refine det_eq_zero_of_row_eq_zero j fun k => ?_
obtain rfl | hjk := eq_or_ne k j
· rw [updateCol_self, Pi.single_eq_of_ne' hij]
· rw [updateCol_ne hjk, diagonal_apply_ne' _ hjk]
theorem _root_.RingHom.map_adjugate {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S)
(M : Matrix n n R) : f.mapMatrix M.adjugate = Matrix.adjugate (f.mapMatrix M) := by
ext i k
have : Pi.single i (1 : S) = f ∘ Pi.single i 1 := by
rw [← f.map_one]
exact Pi.single_op (fun _ => f) (fun _ => f.map_zero) i (1 : R)
rw [adjugate_apply, RingHom.mapMatrix_apply, map_apply, RingHom.mapMatrix_apply, this, ←
map_updateRow, ← RingHom.mapMatrix_apply, ← RingHom.map_det, ← adjugate_apply]
theorem _root_.AlgHom.map_adjugate {R A B : Type*} [CommSemiring R] [CommRing A] [CommRing B]
[Algebra R A] [Algebra R B] (f : A →ₐ[R] B) (M : Matrix n n A) :
f.mapMatrix M.adjugate = Matrix.adjugate (f.mapMatrix M) :=
f.toRingHom.map_adjugate _
theorem det_adjugate (A : Matrix n n α) : (adjugate A).det = A.det ^ (Fintype.card n - 1) := by
-- get rid of the `- 1`
rcases (Fintype.card n).eq_zero_or_pos with h_card | h_card
· haveI : IsEmpty n := Fintype.card_eq_zero_iff.mp h_card
rw [h_card, Nat.zero_sub, pow_zero, adjugate_subsingleton, det_one]
replace h_card := tsub_add_cancel_of_le h_card.nat_succ_le
-- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring
-- where `A'.det` is non-zero.
let A' := mvPolynomialX n n ℤ
suffices A'.adjugate.det = A'.det ^ (Fintype.card n - 1) by
rw [← mvPolynomialX_mapMatrix_aeval ℤ A, ← AlgHom.map_adjugate, ← AlgHom.map_det, ←
AlgHom.map_det, ← map_pow, this]
apply mul_left_cancel₀ (show A'.det ≠ 0 from det_mvPolynomialX_ne_zero n ℤ)
calc
A'.det * A'.adjugate.det = (A' * adjugate A').det := (det_mul _ _).symm
_ = A'.det ^ Fintype.card n := by rw [mul_adjugate, det_smul, det_one, mul_one]
_ = A'.det * A'.det ^ (Fintype.card n - 1) := by rw [← pow_succ', h_card]
@[simp]
theorem adjugate_fin_zero (A : Matrix (Fin 0) (Fin 0) α) : adjugate A = 0 :=
Subsingleton.elim _ _
@[simp]
theorem adjugate_fin_one (A : Matrix (Fin 1) (Fin 1) α) : adjugate A = 1 :=
adjugate_subsingleton A
theorem adjugate_fin_succ_eq_det_submatrix {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) α) (i j) :
adjugate A i j = (-1) ^ (j + i : ℕ) * det (A.submatrix j.succAbove i.succAbove) := by
simp_rw [adjugate_apply, det_succ_row _ j, updateRow_self, submatrix_updateRow_succAbove]
rw [Fintype.sum_eq_single i fun h hjk => ?_, Pi.single_eq_same, mul_one]
rw [Pi.single_eq_of_ne hjk, mul_zero, zero_mul]
theorem adjugate_fin_two (A : Matrix (Fin 2) (Fin 2) α) :
adjugate A = !![A 1 1, -A 0 1; -A 1 0, A 0 0] := by
ext i j
rw [adjugate_fin_succ_eq_det_submatrix]
fin_cases i <;> fin_cases j <;> simp
@[simp]
theorem adjugate_fin_two_of (a b c d : α) : adjugate !![a, b; c, d] = !![d, -b; -c, a] :=
adjugate_fin_two _
theorem adjugate_fin_three (A : Matrix (Fin 3) (Fin 3) α) :
adjugate A =
!![A 1 1 * A 2 2 - A 1 2 * A 2 1,
-(A 0 1 * A 2 2) + A 0 2 * A 2 1,
A 0 1 * A 1 2 - A 0 2 * A 1 1;
-(A 1 0 * A 2 2) + A 1 2 * A 2 0,
A 0 0 * A 2 2 - A 0 2 * A 2 0,
-(A 0 0 * A 1 2) + A 0 2 * A 1 0;
A 1 0 * A 2 1 - A 1 1 * A 2 0,
-(A 0 0 * A 2 1) + A 0 1 * A 2 0,
A 0 0 * A 1 1 - A 0 1 * A 1 0] := by
ext i j
rw [adjugate_fin_succ_eq_det_submatrix, det_fin_two]
fin_cases i <;> fin_cases j <;> simp [updateRow, Fin.succAbove, Fin.lt_def] <;> ring
@[simp]
theorem adjugate_fin_three_of (a b c d e f g h i : α) :
adjugate !![a, b, c; d, e, f; g, h, i] =
!![ e * i - f * h, -(b * i) + c * h, b * f - c * e;
-(d * i) + f * g, a * i - c * g, -(a * f) + c * d;
d * h - e * g, -(a * h) + b * g, a * e - b * d] :=
adjugate_fin_three _
theorem det_eq_sum_mul_adjugate_row (A : Matrix n n α) (i : n) :
det A = ∑ j : n, A i j * adjugate A j i := by
haveI : Nonempty n := ⟨i⟩
obtain ⟨n', hn'⟩ := Nat.exists_eq_succ_of_ne_zero (Fintype.card_ne_zero : Fintype.card n ≠ 0)
obtain ⟨e⟩ := Fintype.truncEquivFinOfCardEq hn'
let A' := reindex e e A
suffices det A' = ∑ j : Fin n'.succ, A' (e i) j * adjugate A' j (e i) by
simp_rw [A', det_reindex_self, adjugate_reindex, reindex_apply, submatrix_apply, ← e.sum_comp,
Equiv.symm_apply_apply] at this
exact this
rw [det_succ_row A' (e i)]
simp_rw [mul_assoc, mul_left_comm _ (A' _ _), ← adjugate_fin_succ_eq_det_submatrix]
theorem det_eq_sum_mul_adjugate_col (A : Matrix n n α) (j : n) :
det A = ∑ i : n, A i j * adjugate A j i := by
simpa only [det_transpose, ← adjugate_transpose] using det_eq_sum_mul_adjugate_row Aᵀ j
theorem adjugate_conjTranspose [StarRing α] (A : Matrix n n α) : A.adjugateᴴ = adjugate Aᴴ := by
dsimp only [conjTranspose]
have : Aᵀ.adjugate.map star = adjugate (Aᵀ.map star) := (starRingEnd α).map_adjugate Aᵀ
rw [A.adjugate_transpose, this]
theorem isRegular_of_isLeftRegular_det {A : Matrix n n α} (hA : IsLeftRegular A.det) :
IsRegular A := by
constructor
· intro B C h
refine hA.matrix ?_
simp only at h ⊢
rw [← Matrix.one_mul B, ← Matrix.one_mul C, ← Matrix.smul_mul, ← Matrix.smul_mul, ←
adjugate_mul, Matrix.mul_assoc, Matrix.mul_assoc, h]
· intro B C (h : B * A = C * A)
refine hA.matrix ?_
simp only
rw [← Matrix.mul_one B, ← Matrix.mul_one C, ← Matrix.mul_smul, ← Matrix.mul_smul, ←
mul_adjugate, ← Matrix.mul_assoc, ← Matrix.mul_assoc, h]
theorem adjugate_mul_distrib_aux (A B : Matrix n n α) (hA : IsLeftRegular A.det)
(hB : IsLeftRegular B.det) : adjugate (A * B) = adjugate B * adjugate A := by
have hAB : IsLeftRegular (A * B).det := by
rw [det_mul]
exact hA.mul hB
refine (isRegular_of_isLeftRegular_det hAB).left ?_
simp only
rw [mul_adjugate, Matrix.mul_assoc, ← Matrix.mul_assoc B, mul_adjugate,
smul_mul, Matrix.one_mul, mul_smul, mul_adjugate, smul_smul, mul_comm, ← det_mul]
/-- Proof follows from "The trace Cayley-Hamilton theorem" by Darij Grinberg, Section 5.3
-/
theorem adjugate_mul_distrib (A B : Matrix n n α) : adjugate (A * B) = adjugate B * adjugate A := by
let g : Matrix n n α → Matrix n n α[X] := fun M =>
M.map Polynomial.C + (Polynomial.X : α[X]) • (1 : Matrix n n α[X])
let f' : Matrix n n α[X] →+* Matrix n n α := (Polynomial.evalRingHom 0).mapMatrix
have f'_inv : ∀ M, f' (g M) = M := by
intro
ext
simp [f', g]
have f'_adj : ∀ M : Matrix n n α, f' (adjugate (g M)) = adjugate M := by
intro
rw [RingHom.map_adjugate, f'_inv]
have f'_g_mul : ∀ M N : Matrix n n α, f' (g M * g N) = M * N := by
intros M N
rw [RingHom.map_mul, f'_inv, f'_inv]
have hu : ∀ M : Matrix n n α, IsRegular (g M).det := by
intro M
refine Polynomial.Monic.isRegular ?_
simp only [g, Polynomial.Monic.def, ← Polynomial.leadingCoeff_det_X_one_add_C M, add_comm]
rw [← f'_adj, ← f'_adj, ← f'_adj, ← f'.map_mul, ←
adjugate_mul_distrib_aux _ _ (hu A).left (hu B).left, RingHom.map_adjugate,
RingHom.map_adjugate, f'_inv, f'_g_mul]
@[simp]
| Mathlib/LinearAlgebra/Matrix/Adjugate.lean | 468 | 480 | theorem adjugate_pow (A : Matrix n n α) (k : ℕ) : adjugate (A ^ k) = adjugate A ^ k := by | induction k with
| zero => simp
| succ k IH => rw [pow_succ', adjugate_mul_distrib, IH, pow_succ]
theorem det_smul_adjugate_adjugate (A : Matrix n n α) :
det A • adjugate (adjugate A) = det A ^ (Fintype.card n - 1) • A := by
have : A * (A.adjugate * A.adjugate.adjugate) =
A * (A.det ^ (Fintype.card n - 1) • (1 : Matrix n n α)) := by
rw [← adjugate_mul_distrib, adjugate_mul, adjugate_smul, adjugate_one]
rwa [← Matrix.mul_assoc, mul_adjugate, Matrix.mul_smul, Matrix.mul_one, Matrix.smul_mul,
Matrix.one_mul] at this |
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.GCDMonoid.Finset
import Mathlib.Algebra.Polynomial.CancelLeads
import Mathlib.Algebra.Polynomial.EraseLead
import Mathlib.Algebra.Polynomial.FieldDivision
/-!
# GCD structures on polynomials
Definitions and basic results about polynomials over GCD domains, particularly their contents
and primitive polynomials.
## Main Definitions
Let `p : R[X]`.
- `p.content` is the `gcd` of the coefficients of `p`.
- `p.IsPrimitive` indicates that `p.content = 1`.
## Main Results
- `Polynomial.content_mul`:
If `p q : R[X]`, then `(p * q).content = p.content * q.content`.
- `Polynomial.NormalizedGcdMonoid`:
The polynomial ring of a GCD domain is itself a GCD domain.
## Note
This has nothing to do with minimal polynomials of primitive elements in finite fields.
-/
namespace Polynomial
section Primitive
variable {R : Type*} [CommSemiring R]
/-- A polynomial is primitive when the only constant polynomials dividing it are units.
Note: This has nothing to do with minimal polynomials of primitive elements in finite fields. -/
def IsPrimitive (p : R[X]) : Prop :=
∀ r : R, C r ∣ p → IsUnit r
theorem isPrimitive_iff_isUnit_of_C_dvd {p : R[X]} : p.IsPrimitive ↔ ∀ r : R, C r ∣ p → IsUnit r :=
Iff.rfl
@[simp]
theorem isPrimitive_one : IsPrimitive (1 : R[X]) := fun _ h =>
isUnit_C.mp (isUnit_of_dvd_one h)
theorem Monic.isPrimitive {p : R[X]} (hp : p.Monic) : p.IsPrimitive := by
rintro r ⟨q, h⟩
exact isUnit_of_mul_eq_one r (q.coeff p.natDegree) (by rwa [← coeff_C_mul, ← h])
theorem IsPrimitive.ne_zero [Nontrivial R] {p : R[X]} (hp : p.IsPrimitive) : p ≠ 0 := by
rintro rfl
exact (hp 0 (dvd_zero (C 0))).ne_zero rfl
theorem isPrimitive_of_dvd {p q : R[X]} (hp : IsPrimitive p) (hq : q ∣ p) : IsPrimitive q :=
fun a ha => isPrimitive_iff_isUnit_of_C_dvd.mp hp a (dvd_trans ha hq)
/-- An irreducible nonconstant polynomial over a domain is primitive. -/
theorem _root_.Irreducible.isPrimitive [NoZeroDivisors R]
{p : Polynomial R} (hp : Irreducible p) (hp' : p.natDegree ≠ 0) : p.IsPrimitive := by
rintro r ⟨q, hq⟩
suffices ¬IsUnit q by simpa using ((hp.2 hq).resolve_right this).map Polynomial.constantCoeff
intro H
have hr : r ≠ 0 := by rintro rfl; simp_all
obtain ⟨s, hs, rfl⟩ := Polynomial.isUnit_iff.mp H
simp [hq, Polynomial.natDegree_C_mul hr] at hp'
end Primitive
variable {R : Type*} [CommRing R] [IsDomain R]
section NormalizedGCDMonoid
variable [NormalizedGCDMonoid R]
/-- `p.content` is the `gcd` of the coefficients of `p`. -/
def content (p : R[X]) : R :=
p.support.gcd p.coeff
theorem content_dvd_coeff {p : R[X]} (n : ℕ) : p.content ∣ p.coeff n := by
by_cases h : n ∈ p.support
· apply Finset.gcd_dvd h
rw [mem_support_iff, Classical.not_not] at h
rw [h]
apply dvd_zero
@[simp]
theorem content_C {r : R} : (C r).content = normalize r := by
rw [content]
by_cases h0 : r = 0
· simp [h0]
have h : (C r).support = {0} := support_monomial _ h0
simp [h]
@[simp]
| Mathlib/RingTheory/Polynomial/Content.lean | 102 | 102 | theorem content_zero : content (0 : R[X]) = 0 := by | rw [← C_0, content_C, normalize_zero] |
/-
Copyright (c) 2020 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo
-/
import Mathlib.Logic.Function.Iterate
import Mathlib.Topology.Algebra.Monoid
import Mathlib.Topology.Algebra.Group.Defs
/-!
# Flows and invariant sets
This file defines a flow on a topological space `α` by a topological
monoid `τ` as a continuous monoid-action of `τ` on `α`. Anticipating the
cases where `τ` is one of `ℕ`, `ℤ`, `ℝ⁺`, or `ℝ`, we use additive
notation for the monoids, though the definition does not require
commutativity.
A subset `s` of `α` is invariant under a family of maps `ϕₜ : α → α`
if `ϕₜ s ⊆ s` for all `t`. In many cases `ϕ` will be a flow on
`α`. For the cases where `ϕ` is a flow by an ordered (additive,
commutative) monoid, we additionally define forward invariance, where
`t` ranges over those elements which are nonnegative.
Additionally, we define such constructions as the restriction of a
flow onto an invariant subset, and the time-reversal of a flow by a
group.
-/
open Set Function Filter
/-!
### Invariant sets
-/
section Invariant
variable {τ : Type*} {α : Type*}
/-- A set `s ⊆ α` is invariant under `ϕ : τ → α → α` if
`ϕ t s ⊆ s` for all `t` in `τ`. -/
def IsInvariant (ϕ : τ → α → α) (s : Set α) : Prop :=
∀ t, MapsTo (ϕ t) s s
variable (ϕ : τ → α → α) (s : Set α)
theorem isInvariant_iff_image : IsInvariant ϕ s ↔ ∀ t, ϕ t '' s ⊆ s := by
simp_rw [IsInvariant, mapsTo']
/-- A set `s ⊆ α` is forward-invariant under `ϕ : τ → α → α` if
`ϕ t s ⊆ s` for all `t ≥ 0`. -/
def IsFwInvariant [Preorder τ] [Zero τ] (ϕ : τ → α → α) (s : Set α) : Prop :=
∀ ⦃t⦄, 0 ≤ t → MapsTo (ϕ t) s s
theorem IsInvariant.isFwInvariant [Preorder τ] [Zero τ] {ϕ : τ → α → α} {s : Set α}
(h : IsInvariant ϕ s) : IsFwInvariant ϕ s := fun t _ht => h t
/-- If `τ` is a `CanonicallyOrderedAdd` monoid (e.g., `ℕ` or `ℝ≥0`), then the notions
`IsFwInvariant` and `IsInvariant` are equivalent. -/
theorem IsFwInvariant.isInvariant [AddMonoid τ] [PartialOrder τ] [CanonicallyOrderedAdd τ]
{ϕ : τ → α → α} {s : Set α}
(h : IsFwInvariant ϕ s) : IsInvariant ϕ s := fun t => h (zero_le t)
/-- If `τ` is a `CanonicallyOrderedAdd` monoid (e.g., `ℕ` or `ℝ≥0`), then the notions
`IsFwInvariant` and `IsInvariant` are equivalent. -/
theorem isFwInvariant_iff_isInvariant [AddMonoid τ] [PartialOrder τ] [CanonicallyOrderedAdd τ]
{ϕ : τ → α → α} {s : Set α} :
IsFwInvariant ϕ s ↔ IsInvariant ϕ s :=
⟨IsFwInvariant.isInvariant, IsInvariant.isFwInvariant⟩
end Invariant
/-!
### Flows
-/
/-- A flow on a topological space `α` by an additive topological
monoid `τ` is a continuous monoid action of `τ` on `α`. -/
structure Flow (τ : Type*) [TopologicalSpace τ] [AddMonoid τ] [ContinuousAdd τ] (α : Type*)
[TopologicalSpace α] where
/-- The map `τ → α → α` underlying a flow of `τ` on `α`. -/
toFun : τ → α → α
cont' : Continuous (uncurry toFun)
map_add' : ∀ t₁ t₂ x, toFun (t₁ + t₂) x = toFun t₁ (toFun t₂ x)
map_zero' : ∀ x, toFun 0 x = x
namespace Flow
variable {τ : Type*} [AddMonoid τ] [TopologicalSpace τ] [ContinuousAdd τ]
{α : Type*} [TopologicalSpace α] (ϕ : Flow τ α)
instance : Inhabited (Flow τ α) :=
⟨{ toFun := fun _ x => x
cont' := continuous_snd
map_add' := fun _ _ _ => rfl
map_zero' := fun _ => rfl }⟩
instance : CoeFun (Flow τ α) fun _ => τ → α → α := ⟨Flow.toFun⟩
@[ext]
theorem ext : ∀ {ϕ₁ ϕ₂ : Flow τ α}, (∀ t x, ϕ₁ t x = ϕ₂ t x) → ϕ₁ = ϕ₂
| ⟨f₁, _, _, _⟩, ⟨f₂, _, _, _⟩, h => by
congr
funext
exact h _ _
@[continuity, fun_prop]
protected theorem continuous {β : Type*} [TopologicalSpace β] {t : β → τ} (ht : Continuous t)
{f : β → α} (hf : Continuous f) : Continuous fun x => ϕ (t x) (f x) :=
ϕ.cont'.comp (ht.prodMk hf)
alias _root_.Continuous.flow := Flow.continuous
theorem map_add (t₁ t₂ : τ) (x : α) : ϕ (t₁ + t₂) x = ϕ t₁ (ϕ t₂ x) := ϕ.map_add' _ _ _
@[simp]
theorem map_zero : ϕ 0 = id := funext ϕ.map_zero'
theorem map_zero_apply (x : α) : ϕ 0 x = x := ϕ.map_zero' x
/-- Iterations of a continuous function from a topological space `α`
to itself defines a semiflow by `ℕ` on `α`. -/
def fromIter {g : α → α} (h : Continuous g) : Flow ℕ α where
toFun n x := g^[n] x
cont' := continuous_prod_of_discrete_left.mpr (Continuous.iterate h)
map_add' := iterate_add_apply _
map_zero' _x := rfl
/-- Restriction of a flow onto an invariant set. -/
def restrict {s : Set α} (h : IsInvariant ϕ s) : Flow τ (↥s) where
toFun t := (h t).restrict _ _ _
cont' := (ϕ.continuous continuous_fst continuous_subtype_val.snd').subtype_mk _
map_add' _ _ _ := Subtype.ext (map_add _ _ _ _)
map_zero' _ := Subtype.ext (map_zero_apply _ _)
end Flow
namespace Flow
variable {τ : Type*} [AddCommGroup τ] [TopologicalSpace τ] [IsTopologicalAddGroup τ]
{α : Type*} [TopologicalSpace α] (ϕ : Flow τ α)
theorem isInvariant_iff_image_eq (s : Set α) : IsInvariant ϕ s ↔ ∀ t, ϕ t '' s = s :=
(isInvariant_iff_image _ _).trans
(Iff.intro
(fun h t => Subset.antisymm (h t) fun _ hx => ⟨_, h (-t) ⟨_, hx, rfl⟩, by simp [← map_add]⟩)
fun h t => by rw [h t])
/-- The time-reversal of a flow `ϕ` by a (commutative, additive) group
is defined `ϕ.reverse t x = ϕ (-t) x`. -/
def reverse : Flow τ α where
toFun t := ϕ (-t)
cont' := ϕ.continuous continuous_fst.neg continuous_snd
map_add' _ _ _ := by rw [neg_add, map_add]
map_zero' _ := by rw [neg_zero, map_zero_apply]
@[continuity, fun_prop]
| Mathlib/Dynamics/Flow.lean | 158 | 162 | theorem continuous_toFun (t : τ) : Continuous (ϕ.toFun t) := by | fun_prop
/-- The map `ϕ t` as a homeomorphism. -/
def toHomeomorph (t : τ) : (α ≃ₜ α) where |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.SetTheory.Ordinal.Exponential
import Mathlib.SetTheory.Ordinal.Family
/-!
# Cantor Normal Form
The Cantor normal form of an ordinal is generally defined as its base `ω` expansion, with its
non-zero exponents in decreasing order. Here, we more generally define a base `b` expansion
`Ordinal.CNF` in this manner, which is well-behaved for any `b ≥ 2`.
# Implementation notes
We implement `Ordinal.CNF` as an association list, where keys are exponents and values are
coefficients. This is because this structure intrinsically reflects two key properties of the Cantor
normal form:
- It is ordered.
- It has finitely many entries.
# Todo
- Add API for the coefficients of the Cantor normal form.
- Prove the basic results relating the CNF to the arithmetic operations on ordinals.
-/
noncomputable section
universe u
open List
namespace Ordinal
/-- Inducts on the base `b` expansion of an ordinal. -/
@[elab_as_elim]
noncomputable def CNFRec (b : Ordinal) {C : Ordinal → Sort*} (H0 : C 0)
(H : ∀ o, o ≠ 0 → C (o % b ^ log b o) → C o) (o : Ordinal) : C o :=
if h : o = 0 then h ▸ H0 else H o h (CNFRec b H0 H (o % b ^ log b o))
termination_by o
decreasing_by exact mod_opow_log_lt_self b h
@[simp]
theorem CNFRec_zero {C : Ordinal → Sort*} (b : Ordinal) (H0 : C 0)
(H : ∀ o, o ≠ 0 → C (o % b ^ log b o) → C o) : CNFRec b H0 H 0 = H0 := by
rw [CNFRec, dif_pos rfl]
theorem CNFRec_pos (b : Ordinal) {o : Ordinal} {C : Ordinal → Sort*} (ho : o ≠ 0) (H0 : C 0)
(H : ∀ o, o ≠ 0 → C (o % b ^ log b o) → C o) :
CNFRec b H0 H o = H o ho (@CNFRec b C H0 H _) := by
rw [CNFRec, dif_neg]
/-- The Cantor normal form of an ordinal `o` is the list of coefficients and exponents in the
base-`b` expansion of `o`.
We special-case `CNF 0 o = CNF 1 o = [(0, o)]` for `o ≠ 0`.
`CNF b (b ^ u₁ * v₁ + b ^ u₂ * v₂) = [(u₁, v₁), (u₂, v₂)]` -/
@[pp_nodot]
def CNF (b o : Ordinal) : List (Ordinal × Ordinal) :=
CNFRec b [] (fun o _ IH ↦ (log b o, o / b ^ log b o)::IH) o
@[simp]
theorem CNF_zero (b : Ordinal) : CNF b 0 = [] :=
CNFRec_zero b _ _
/-- Recursive definition for the Cantor normal form. -/
theorem CNF_ne_zero {b o : Ordinal} (ho : o ≠ 0) :
CNF b o = (log b o, o / b ^ log b o)::CNF b (o % b ^ log b o) :=
CNFRec_pos b ho _ _
theorem zero_CNF {o : Ordinal} (ho : o ≠ 0) : CNF 0 o = [(0, o)] := by simp [CNF_ne_zero ho]
theorem one_CNF {o : Ordinal} (ho : o ≠ 0) : CNF 1 o = [(0, o)] := by simp [CNF_ne_zero ho]
theorem CNF_of_le_one {b o : Ordinal} (hb : b ≤ 1) (ho : o ≠ 0) : CNF b o = [(0, o)] := by
rcases le_one_iff.1 hb with (rfl | rfl)
exacts [zero_CNF ho, one_CNF ho]
theorem CNF_of_lt {b o : Ordinal} (ho : o ≠ 0) (hb : o < b) : CNF b o = [(0, o)] := by
rw [CNF_ne_zero ho, log_eq_zero hb, opow_zero, div_one, mod_one, CNF_zero]
/-- Evaluating the Cantor normal form of an ordinal returns the ordinal. -/
theorem CNF_foldr (b o : Ordinal) : (CNF b o).foldr (fun p r ↦ b ^ p.1 * p.2 + r) 0 = o := by
refine CNFRec b ?_ ?_ o
· rw [CNF_zero, foldr_nil]
· intro o ho IH
rw [CNF_ne_zero ho, foldr_cons, IH, div_add_mod]
/-- Every exponent in the Cantor normal form `CNF b o` is less or equal to `log b o`. -/
theorem CNF_fst_le_log {b o : Ordinal.{u}} {x : Ordinal × Ordinal} :
x ∈ CNF b o → x.1 ≤ log b o := by
refine CNFRec b ?_ (fun o ho H ↦ ?_) o
· simp
· rw [CNF_ne_zero ho, mem_cons]
rintro (rfl | h)
· rfl
· exact (H h).trans (log_mono_right _ (mod_opow_log_lt_self b ho).le)
/-- Every coefficient in a Cantor normal form is positive. -/
theorem CNF_lt_snd {b o : Ordinal.{u}} {x : Ordinal × Ordinal} : x ∈ CNF b o → 0 < x.2 := by
refine CNFRec b (by simp) (fun o ho IH ↦ ?_) o
rw [CNF_ne_zero ho]
rintro (h | ⟨_, h⟩)
· exact div_opow_log_pos b ho
· exact IH h
/-- Every coefficient in the Cantor normal form `CNF b o` is less than `b`. -/
| Mathlib/SetTheory/Ordinal/CantorNormalForm.lean | 114 | 116 | theorem CNF_snd_lt {b o : Ordinal.{u}} (hb : 1 < b) {x : Ordinal × Ordinal} :
x ∈ CNF b o → x.2 < b := by | refine CNFRec b ?_ (fun o ho IH ↦ ?_) o |
/-
Copyright (c) 2020 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Algebra.BigOperators.NatAntidiagonal
import Mathlib.Algebra.Polynomial.Reverse
/-!
# "Mirror" of a univariate polynomial
In this file we define `Polynomial.mirror`, a variant of `Polynomial.reverse`. The difference
between `reverse` and `mirror` is that `reverse` will decrease the degree if the polynomial is
divisible by `X`.
## Main definitions
- `Polynomial.mirror`
## Main results
- `Polynomial.mirror_mul_of_domain`: `mirror` preserves multiplication.
- `Polynomial.irreducible_of_mirror`: an irreducibility criterion involving `mirror`
-/
namespace Polynomial
section Semiring
variable {R : Type*} [Semiring R] (p q : R[X])
/-- mirror of a polynomial: reverses the coefficients while preserving `Polynomial.natDegree` -/
noncomputable def mirror :=
p.reverse * X ^ p.natTrailingDegree
@[simp]
theorem mirror_zero : (0 : R[X]).mirror = 0 := by simp [mirror]
theorem mirror_monomial (n : ℕ) (a : R) : (monomial n a).mirror = monomial n a := by
classical
by_cases ha : a = 0
· rw [ha, monomial_zero_right, mirror_zero]
· rw [mirror, reverse, natDegree_monomial n a, if_neg ha, natTrailingDegree_monomial ha, ←
C_mul_X_pow_eq_monomial, reflect_C_mul_X_pow, revAt_le (le_refl n), tsub_self, pow_zero,
mul_one]
theorem mirror_C (a : R) : (C a).mirror = C a :=
mirror_monomial 0 a
theorem mirror_X : X.mirror = (X : R[X]) :=
mirror_monomial 1 (1 : R)
theorem mirror_natDegree : p.mirror.natDegree = p.natDegree := by
by_cases hp : p = 0
· rw [hp, mirror_zero]
nontriviality R
rw [mirror, natDegree_mul', reverse_natDegree, natDegree_X_pow,
tsub_add_cancel_of_le p.natTrailingDegree_le_natDegree]
rwa [leadingCoeff_X_pow, mul_one, reverse_leadingCoeff, Ne, trailingCoeff_eq_zero]
theorem mirror_natTrailingDegree : p.mirror.natTrailingDegree = p.natTrailingDegree := by
by_cases hp : p = 0
· rw [hp, mirror_zero]
· rw [mirror, natTrailingDegree_mul_X_pow ((mt reverse_eq_zero.mp) hp),
natTrailingDegree_reverse, zero_add]
theorem coeff_mirror (n : ℕ) :
p.mirror.coeff n = p.coeff (revAt (p.natDegree + p.natTrailingDegree) n) := by
by_cases h2 : p.natDegree < n
· rw [coeff_eq_zero_of_natDegree_lt (by rwa [mirror_natDegree])]
by_cases h1 : n ≤ p.natDegree + p.natTrailingDegree
· rw [revAt_le h1, coeff_eq_zero_of_lt_natTrailingDegree]
exact (tsub_lt_iff_left h1).mpr (Nat.add_lt_add_right h2 _)
· rw [← revAtFun_eq, revAtFun, if_neg h1, coeff_eq_zero_of_natDegree_lt h2]
rw [not_lt] at h2
rw [revAt_le (h2.trans (Nat.le_add_right _ _))]
by_cases h3 : p.natTrailingDegree ≤ n
· rw [← tsub_add_eq_add_tsub h2, ← tsub_tsub_assoc h2 h3, mirror, coeff_mul_X_pow', if_pos h3,
coeff_reverse, revAt_le (tsub_le_self.trans h2)]
rw [not_le] at h3
rw [coeff_eq_zero_of_natDegree_lt (lt_tsub_iff_right.mpr (Nat.add_lt_add_left h3 _))]
exact coeff_eq_zero_of_lt_natTrailingDegree (by rwa [mirror_natTrailingDegree])
--TODO: Extract `Finset.sum_range_rev_at` lemma.
theorem mirror_eval_one : p.mirror.eval 1 = p.eval 1 := by
simp_rw [eval_eq_sum_range, one_pow, mul_one, mirror_natDegree]
refine Finset.sum_bij_ne_zero ?_ ?_ ?_ ?_ ?_
· exact fun n _ _ => revAt (p.natDegree + p.natTrailingDegree) n
· intro n hn hp
rw [Finset.mem_range_succ_iff] at *
rw [revAt_le (hn.trans (Nat.le_add_right _ _))]
rw [tsub_le_iff_tsub_le, add_comm, add_tsub_cancel_right, ← mirror_natTrailingDegree]
exact natTrailingDegree_le_of_ne_zero hp
· exact fun n₁ _ _ _ _ _ h => by rw [← @revAt_invol _ n₁, h, revAt_invol]
· intro n hn hp
use revAt (p.natDegree + p.natTrailingDegree) n
refine ⟨?_, ?_, revAt_invol⟩
· rw [Finset.mem_range_succ_iff] at *
rw [revAt_le (hn.trans (Nat.le_add_right _ _))]
rw [tsub_le_iff_tsub_le, add_comm, add_tsub_cancel_right]
exact natTrailingDegree_le_of_ne_zero hp
· change p.mirror.coeff _ ≠ 0
rwa [coeff_mirror, revAt_invol]
· exact fun n _ _ => p.coeff_mirror n
theorem mirror_mirror : p.mirror.mirror = p :=
Polynomial.ext fun n => by
rw [coeff_mirror, coeff_mirror, mirror_natDegree, mirror_natTrailingDegree, revAt_invol]
variable {p q}
theorem mirror_involutive : Function.Involutive (mirror : R[X] → R[X]) :=
mirror_mirror
theorem mirror_eq_iff : p.mirror = q ↔ p = q.mirror :=
mirror_involutive.eq_iff
@[simp]
theorem mirror_inj : p.mirror = q.mirror ↔ p = q :=
mirror_involutive.injective.eq_iff
@[simp]
theorem mirror_eq_zero : p.mirror = 0 ↔ p = 0 :=
⟨fun h => by rw [← p.mirror_mirror, h, mirror_zero], fun h => by rw [h, mirror_zero]⟩
variable (p q)
@[simp]
theorem mirror_trailingCoeff : p.mirror.trailingCoeff = p.leadingCoeff := by
rw [leadingCoeff, trailingCoeff, mirror_natTrailingDegree, coeff_mirror,
revAt_le (Nat.le_add_left _ _), add_tsub_cancel_right]
@[simp]
theorem mirror_leadingCoeff : p.mirror.leadingCoeff = p.trailingCoeff := by
rw [← p.mirror_mirror, mirror_trailingCoeff, p.mirror_mirror]
theorem coeff_mul_mirror :
(p * p.mirror).coeff (p.natDegree + p.natTrailingDegree) = p.sum fun _ => (· ^ 2) := by
rw [coeff_mul, Finset.Nat.sum_antidiagonal_eq_sum_range_succ_mk]
refine
(Finset.sum_congr rfl fun n hn => ?_).trans
(p.sum_eq_of_subset (fun _ ↦ (· ^ 2)) (fun _ ↦ zero_pow two_ne_zero) fun n hn ↦
Finset.mem_range_succ_iff.mpr
((le_natDegree_of_mem_supp n hn).trans (Nat.le_add_right _ _))).symm
rw [coeff_mirror, ← revAt_le (Finset.mem_range_succ_iff.mp hn), revAt_invol, ← sq]
variable [NoZeroDivisors R]
| Mathlib/Algebra/Polynomial/Mirror.lean | 151 | 153 | theorem natDegree_mul_mirror : (p * p.mirror).natDegree = 2 * p.natDegree := by | by_cases hp : p = 0
· rw [hp, zero_mul, natDegree_zero, mul_zero] |
/-
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
| Mathlib/Analysis/SpecialFunctions/Pow/Deriv.lean | 206 | 209 | 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 |
/-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Algebra.Bilinear
import Mathlib.Algebra.Algebra.Opposite
import Mathlib.Algebra.Group.Pointwise.Finset.Basic
import Mathlib.Algebra.Group.Pointwise.Set.BigOperators
import Mathlib.Algebra.Module.Submodule.Pointwise
import Mathlib.Algebra.Ring.NonZeroDivisors
import Mathlib.Algebra.Ring.Submonoid.Pointwise
import Mathlib.Data.Set.Semiring
import Mathlib.GroupTheory.GroupAction.SubMulAction.Pointwise
/-!
# Multiplication and division of submodules of an algebra.
An interface for multiplication and division of sub-R-modules of an R-algebra A is developed.
## Main definitions
Let `R` be a commutative ring (or semiring) and let `A` be an `R`-algebra.
* `1 : Submodule R A` : the R-submodule R of the R-algebra A
* `Mul (Submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be
the smallest submodule containing all the products `m * n`.
* `Div (Submodule R A)` : `I / J` is defined to be the submodule consisting of all `a : A` such
that `a • J ⊆ I`
It is proved that `Submodule R A` is a semiring, and also an algebra over `Set A`.
Additionally, in the `Pointwise` locale we promote `Submodule.pointwiseDistribMulAction` to a
`MulSemiringAction` as `Submodule.pointwiseMulSemiringAction`.
When `R` is not necessarily commutative, and `A` is merely a `R`-module with a ring structure
such that `IsScalarTower R A A` holds (equivalent to the data of a ring homomorphism `R →+* A`
by `ringHomEquivModuleIsScalarTower`), we can still define `1 : Submodule R A` and
`Mul (Submodule R A)`, but `1` is only a left identity, not necessarily a right one.
## Tags
multiplication of submodules, division of submodules, submodule semiring
-/
universe uι u v
open Algebra Set MulOpposite
open Pointwise
namespace SubMulAction
variable {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]
theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : SubMulAction R A) :=
⟨r, (algebraMap_eq_smul_one r).symm⟩
theorem mem_one' {x : A} : x ∈ (1 : SubMulAction R A) ↔ ∃ y, algebraMap R A y = x :=
exists_congr fun r => by rw [algebraMap_eq_smul_one]
end SubMulAction
namespace Submodule
section Module
variable {R : Type u} [Semiring R] {A : Type v} [Semiring A] [Module R A]
-- TODO: Why is this in a file about `Algebra`?
-- TODO: potentially change this back to `LinearMap.range (Algebra.linearMap R A)`
-- once a version of `Algebra` without the `commutes'` field is introduced.
-- See issue https://github.com/leanprover-community/mathlib4/issues/18110.
/-- `1 : Submodule R A` is the submodule `R ∙ 1` of `A`.
-/
instance one : One (Submodule R A) :=
⟨LinearMap.range (LinearMap.toSpanSingleton R A 1)⟩
theorem one_eq_span : (1 : Submodule R A) = R ∙ 1 :=
(LinearMap.span_singleton_eq_range _ _ _).symm
theorem le_one_toAddSubmonoid : 1 ≤ (1 : Submodule R A).toAddSubmonoid := by
rintro x ⟨n, rfl⟩
exact ⟨n, show (n : R) • (1 : A) = n by rw [Nat.cast_smul_eq_nsmul, nsmul_one]⟩
@[simp]
theorem toSubMulAction_one : (1 : Submodule R A).toSubMulAction = 1 :=
SetLike.ext fun _ ↦ by rw [one_eq_span, SubMulAction.mem_one]; exact mem_span_singleton
theorem one_eq_span_one_set : (1 : Submodule R A) = span R 1 :=
one_eq_span
@[simp]
theorem one_le {P : Submodule R A} : (1 : Submodule R A) ≤ P ↔ (1 : A) ∈ P := by
simp [one_eq_span]
variable {M : Type*} [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M]
instance : SMul (Submodule R A) (Submodule R M) where
smul A' M' :=
{ __ := A'.toAddSubmonoid • M'.toAddSubmonoid
smul_mem' := fun r m hm ↦ AddSubmonoid.smul_induction_on hm
(fun a ha m hm ↦ by rw [← smul_assoc]; exact AddSubmonoid.smul_mem_smul (A'.smul_mem r ha) hm)
fun m₁ m₂ h₁ h₂ ↦ by rw [smul_add]; exact (A'.1 • M'.1).add_mem h₁ h₂ }
section
variable {I J : Submodule R A} {N P : Submodule R M}
theorem smul_toAddSubmonoid : (I • N).toAddSubmonoid = I.toAddSubmonoid • N.toAddSubmonoid := rfl
theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N :=
AddSubmonoid.smul_mem_smul hr hn
theorem smul_le : I • N ≤ P ↔ ∀ r ∈ I, ∀ n ∈ N, r • n ∈ P :=
AddSubmonoid.smul_le
@[simp, norm_cast]
lemma coe_set_smul : (I : Set A) • N = I • N :=
set_smul_eq_of_le _ _ _
(fun _ _ hr hx ↦ smul_mem_smul hr hx)
(smul_le.mpr fun _ hr _ hx ↦ mem_set_smul_of_mem_mem hr hx)
@[elab_as_elim]
theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N) (smul : ∀ r ∈ I, ∀ n ∈ N, p (r • n))
(add : ∀ x y, p x → p y → p (x + y)) : p x :=
AddSubmonoid.smul_induction_on H smul add
/-- Dependent version of `Submodule.smul_induction_on`. -/
@[elab_as_elim]
theorem smul_induction_on' {x : M} (hx : x ∈ I • N) {p : ∀ x, x ∈ I • N → Prop}
(smul : ∀ (r : A) (hr : r ∈ I) (n : M) (hn : n ∈ N), p (r • n) (smul_mem_smul hr hn))
(add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (add_mem ‹_› ‹_›)) : p x hx := by
refine Exists.elim ?_ fun (h : x ∈ I • N) (H : p x h) ↦ H
exact smul_induction_on hx (fun a ha x hx ↦ ⟨_, smul _ ha _ hx⟩)
fun x y ⟨_, hx⟩ ⟨_, hy⟩ ↦ ⟨_, add _ _ _ _ hx hy⟩
theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P :=
AddSubmonoid.smul_le_smul hij hnp
theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N :=
smul_mono h le_rfl
instance : CovariantClass (Submodule R A) (Submodule R M) HSMul.hSMul LE.le :=
⟨fun _ _ => smul_mono le_rfl⟩
variable (I J N P)
@[simp]
theorem smul_bot : I • (⊥ : Submodule R M) = ⊥ :=
toAddSubmonoid_injective <| AddSubmonoid.addSubmonoid_smul_bot _
@[simp]
theorem bot_smul : (⊥ : Submodule R A) • N = ⊥ :=
le_bot_iff.mp <| smul_le.mpr <| by rintro _ rfl _ _; rw [zero_smul]; exact zero_mem _
theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P :=
toAddSubmonoid_injective <| by
simp only [smul_toAddSubmonoid, sup_toAddSubmonoid, AddSubmonoid.addSubmonoid_smul_sup]
theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N :=
le_antisymm (smul_le.mpr fun mn hmn p hp ↦ by
obtain ⟨m, hm, n, hn, rfl⟩ := mem_sup.mp hmn
rw [add_smul]; exact add_mem_sup (smul_mem_smul hm hp) <| smul_mem_smul hn hp)
(sup_le (smul_mono_left le_sup_left) <| smul_mono_left le_sup_right)
protected theorem smul_assoc {B} [Semiring B] [Module R B] [Module A B] [Module B M]
[IsScalarTower R A B] [IsScalarTower R B M] [IsScalarTower A B M]
(I : Submodule R A) (J : Submodule R B) (N : Submodule R M) :
(I • J) • N = I • J • N :=
le_antisymm
(smul_le.2 fun _ hrsij t htn ↦ smul_induction_on hrsij
(fun r hr s hs ↦ smul_assoc r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn))
fun x y ↦ (add_smul x y t).symm ▸ add_mem)
(smul_le.2 fun r hr _ hsn ↦ smul_induction_on hsn
(fun j hj n hn ↦ (smul_assoc r j n).symm ▸ smul_mem_smul (smul_mem_smul hr hj) hn)
fun m₁ m₂ ↦ (smul_add r m₁ m₂) ▸ add_mem)
theorem smul_iSup {ι : Sort*} {I : Submodule R A} {t : ι → Submodule R M} :
I • (⨆ i, t i)= ⨆ i, I • t i :=
toAddSubmonoid_injective <| by
simp only [smul_toAddSubmonoid, iSup_toAddSubmonoid, AddSubmonoid.smul_iSup]
theorem iSup_smul {ι : Sort*} {t : ι → Submodule R A} {N : Submodule R M} :
(⨆ i, t i) • N = ⨆ i, t i • N :=
le_antisymm (smul_le.mpr fun t ht s hs ↦ iSup_induction _ (motive := (· • s ∈ _)) ht
(fun i t ht ↦ mem_iSup_of_mem i <| smul_mem_smul ht hs)
(by simp_rw [zero_smul]; apply zero_mem) fun x y ↦ by simp_rw [add_smul]; apply add_mem)
(iSup_le fun i ↦ Submodule.smul_mono_left <| le_iSup _ i)
protected theorem one_smul : (1 : Submodule R A) • N = N := by
refine le_antisymm (smul_le.mpr fun r hr m hm ↦ ?_) fun m hm ↦ ?_
· obtain ⟨r, rfl⟩ := hr
rw [LinearMap.toSpanSingleton_apply, smul_one_smul]; exact N.smul_mem r hm
· rw [← one_smul A m]; exact smul_mem_smul (one_le.mp le_rfl) hm
theorem smul_subset_smul : (↑I : Set A) • (↑N : Set M) ⊆ (↑(I • N) : Set M) :=
AddSubmonoid.smul_subset_smul
end
variable [IsScalarTower R A A]
/-- Multiplication of sub-R-modules of an R-module A that is also a semiring. The submodule `M * N`
consists of finite sums of elements `m * n` for `m ∈ M` and `n ∈ N`. -/
instance mul : Mul (Submodule R A) where
mul := (· • ·)
variable (S T : Set A) {M N P Q : Submodule R A} {m n : A}
theorem mul_mem_mul (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N :=
smul_mem_smul hm hn
theorem mul_le : M * N ≤ P ↔ ∀ m ∈ M, ∀ n ∈ N, m * n ∈ P :=
smul_le
theorem mul_toAddSubmonoid (M N : Submodule R A) :
(M * N).toAddSubmonoid = M.toAddSubmonoid * N.toAddSubmonoid := rfl
@[elab_as_elim]
protected theorem mul_induction_on {C : A → Prop} {r : A} (hr : r ∈ M * N)
(hm : ∀ m ∈ M, ∀ n ∈ N, C (m * n)) (ha : ∀ x y, C x → C y → C (x + y)) : C r :=
smul_induction_on hr hm ha
/-- A dependent version of `mul_induction_on`. -/
@[elab_as_elim]
protected theorem mul_induction_on' {C : ∀ r, r ∈ M * N → Prop}
(mem_mul_mem : ∀ m (hm : m ∈ M) n (hn : n ∈ N), C (m * n) (mul_mem_mul hm hn))
(add : ∀ x hx y hy, C x hx → C y hy → C (x + y) (add_mem hx hy)) {r : A} (hr : r ∈ M * N) :
C r hr :=
smul_induction_on' hr mem_mul_mem add
variable (M)
@[simp]
theorem mul_bot : M * ⊥ = ⊥ :=
smul_bot _
@[simp]
theorem bot_mul : ⊥ * M = ⊥ :=
bot_smul _
protected theorem one_mul : (1 : Submodule R A) * M = M :=
Submodule.one_smul _
variable {M}
@[mono]
theorem mul_le_mul (hmp : M ≤ P) (hnq : N ≤ Q) : M * N ≤ P * Q :=
smul_mono hmp hnq
theorem mul_le_mul_left (h : M ≤ N) : M * P ≤ N * P :=
smul_mono_left h
theorem mul_le_mul_right (h : N ≤ P) : M * N ≤ M * P :=
smul_mono_right _ h
theorem mul_comm_of_commute (h : ∀ m ∈ M, ∀ n ∈ N, Commute m n) : M * N = N * M :=
toAddSubmonoid_injective <| AddSubmonoid.mul_comm_of_commute h
variable (M N P)
theorem mul_sup : M * (N ⊔ P) = M * N ⊔ M * P :=
smul_sup _ _ _
theorem sup_mul : (M ⊔ N) * P = M * P ⊔ N * P :=
sup_smul _ _ _
theorem mul_subset_mul : (↑M : Set A) * (↑N : Set A) ⊆ (↑(M * N) : Set A) :=
smul_subset_smul _ _
lemma restrictScalars_mul {A B C} [Semiring A] [Semiring B] [Semiring C]
[SMul A B] [Module A C] [Module B C] [IsScalarTower A C C] [IsScalarTower B C C]
[IsScalarTower A B C] {I J : Submodule B C} :
(I * J).restrictScalars A = I.restrictScalars A * J.restrictScalars A :=
rfl
variable {ι : Sort uι}
theorem iSup_mul (s : ι → Submodule R A) (t : Submodule R A) : (⨆ i, s i) * t = ⨆ i, s i * t :=
iSup_smul
theorem mul_iSup (t : Submodule R A) (s : ι → Submodule R A) : (t * ⨆ i, s i) = ⨆ i, t * s i :=
smul_iSup
/-- Sub-`R`-modules of an `R`-module form an idempotent semiring. -/
instance : NonUnitalSemiring (Submodule R A) where
__ := toAddSubmonoid_injective.semigroup _ mul_toAddSubmonoid
zero_mul := bot_mul
mul_zero := mul_bot
left_distrib := mul_sup
right_distrib := sup_mul
instance : Pow (Submodule R A) ℕ where
pow s n := npowRec n s
theorem pow_eq_npowRec {n : ℕ} : M ^ n = npowRec n M := rfl
protected theorem pow_zero : M ^ 0 = 1 := rfl
protected theorem pow_succ {n : ℕ} : M ^ (n + 1) = M ^ n * M := rfl
protected theorem pow_add {m n : ℕ} (h : n ≠ 0) : M ^ (m + n) = M ^ m * M ^ n :=
npowRec_add m n h _ M.one_mul
protected theorem pow_one : M ^ 1 = M := by
rw [Submodule.pow_succ, Submodule.pow_zero, Submodule.one_mul]
/-- `Submodule.pow_succ` with the right hand side commuted. -/
protected theorem pow_succ' {n : ℕ} (h : n ≠ 0) : M ^ (n + 1) = M * M ^ n := by
rw [add_comm, M.pow_add h, Submodule.pow_one]
theorem pow_toAddSubmonoid {n : ℕ} (h : n ≠ 0) : (M ^ n).toAddSubmonoid = M.toAddSubmonoid ^ n := by
induction n with
| zero => exact (h rfl).elim
| succ n ih =>
rw [Submodule.pow_succ, pow_succ, mul_toAddSubmonoid]
cases n with
| zero => rw [Submodule.pow_zero, pow_zero, one_mul, ← mul_toAddSubmonoid, Submodule.one_mul]
| succ n => rw [ih n.succ_ne_zero]
theorem le_pow_toAddSubmonoid {n : ℕ} : M.toAddSubmonoid ^ n ≤ (M ^ n).toAddSubmonoid := by
obtain rfl | hn := Decidable.eq_or_ne n 0
· rw [Submodule.pow_zero, pow_zero]
exact le_one_toAddSubmonoid
· exact (pow_toAddSubmonoid M hn).ge
theorem pow_subset_pow {n : ℕ} : (↑M : Set A) ^ n ⊆ ↑(M ^ n : Submodule R A) :=
trans AddSubmonoid.pow_subset_pow (le_pow_toAddSubmonoid M)
theorem pow_mem_pow {x : A} (hx : x ∈ M) (n : ℕ) : x ^ n ∈ M ^ n :=
pow_subset_pow _ <| Set.pow_mem_pow hx
lemma restrictScalars_pow {A B C : Type*} [Semiring A] [Semiring B]
[Semiring C] [SMul A B] [Module A C] [Module B C]
[IsScalarTower A C C] [IsScalarTower B C C] [IsScalarTower A B C]
{I : Submodule B C} :
∀ {n : ℕ}, (hn : n ≠ 0) → (I ^ n).restrictScalars A = I.restrictScalars A ^ n
| 1, _ => by simp [Submodule.pow_one]
| n + 2, _ => by
simp [Submodule.pow_succ (n := n + 1), restrictScalars_mul, restrictScalars_pow n.succ_ne_zero]
end Module
variable {ι : Sort uι}
variable {R : Type u} [CommSemiring R]
section AlgebraSemiring
variable {A : Type v} [Semiring A] [Algebra R A]
variable (S T : Set A) {M N P Q : Submodule R A} {m n : A}
theorem one_eq_range : (1 : Submodule R A) = LinearMap.range (Algebra.linearMap R A) := by
rw [one_eq_span, LinearMap.span_singleton_eq_range,
LinearMap.toSpanSingleton_eq_algebra_linearMap]
theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : Submodule R A) := by
simp [one_eq_range]
@[simp]
theorem mem_one {x : A} : x ∈ (1 : Submodule R A) ↔ ∃ y, algebraMap R A y = x := by
simp [one_eq_range]
protected theorem map_one {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') :
map f.toLinearMap (1 : Submodule R A) = 1 := by
ext
simp
@[simp]
theorem map_op_one :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R A) = 1 := by
ext x
induction x
simp
@[simp]
theorem comap_op_one :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R Aᵐᵒᵖ) = 1 := by
ext
simp
@[simp]
theorem map_unop_one :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R Aᵐᵒᵖ) = 1 := by
rw [← comap_equiv_eq_map_symm, comap_op_one]
@[simp]
theorem comap_unop_one :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R A) = 1 := by
rw [← map_equiv_eq_comap_symm, map_op_one]
theorem mul_eq_map₂ : M * N = map₂ (LinearMap.mul R A) M N :=
le_antisymm (mul_le.mpr fun _m hm _n ↦ apply_mem_map₂ _ hm)
(map₂_le.mpr fun _m hm _n ↦ mul_mem_mul hm)
variable (R M N)
theorem span_mul_span : span R S * span R T = span R (S * T) := by
rw [mul_eq_map₂]; apply map₂_span_span
lemma mul_def : M * N = span R (M * N : Set A) := by simp [← span_mul_span]
variable {R} (P Q)
protected theorem mul_one : M * 1 = M := by
conv_lhs => rw [one_eq_span, ← span_eq M]
rw [span_mul_span]
simp
protected theorem map_mul {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') :
map f.toLinearMap (M * N) = map f.toLinearMap M * map f.toLinearMap N :=
calc
map f.toLinearMap (M * N) = ⨆ i : M, (N.map (LinearMap.mul R A i)).map f.toLinearMap := by
rw [mul_eq_map₂]; apply map_iSup
_ = map f.toLinearMap M * map f.toLinearMap N := by
rw [mul_eq_map₂]
apply congr_arg sSup
ext S
constructor <;> rintro ⟨y, hy⟩
· use ⟨f y, mem_map.mpr ⟨y.1, y.2, rfl⟩⟩
refine Eq.trans ?_ hy
ext
simp
· obtain ⟨y', hy', fy_eq⟩ := mem_map.mp y.2
use ⟨y', hy'⟩
refine Eq.trans ?_ hy
rw [f.toLinearMap_apply] at fy_eq
ext
simp [fy_eq]
theorem map_op_mul :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) =
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N *
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by
apply le_antisymm
· simp_rw [map_le_iff_le_comap]
refine mul_le.2 fun m hm n hn => ?_
rw [mem_comap, map_equiv_eq_comap_symm, map_equiv_eq_comap_symm]
show op n * op m ∈ _
exact mul_mem_mul hn hm
· refine mul_le.2 (MulOpposite.rec' fun m hm => MulOpposite.rec' fun n hn => ?_)
rw [Submodule.mem_map_equiv] at hm hn ⊢
exact mul_mem_mul hn hm
theorem comap_unop_mul :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) =
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N *
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M := by
simp_rw [← map_equiv_eq_comap_symm, map_op_mul]
theorem map_unop_mul (M N : Submodule R Aᵐᵒᵖ) :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) =
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N *
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M :=
have : Function.Injective (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) :=
LinearEquiv.injective _
map_injective_of_injective this <| by
rw [← map_comp, map_op_mul, ← map_comp, ← map_comp, LinearEquiv.comp_coe,
LinearEquiv.symm_trans_self, LinearEquiv.refl_toLinearMap, map_id, map_id, map_id]
| Mathlib/Algebra/Algebra/Operations.lean | 462 | 466 | theorem comap_op_mul (M N : Submodule R Aᵐᵒᵖ) :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) =
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N *
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by | simp_rw [comap_equiv_eq_map_symm, map_unop_mul] |
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Julian Kuelshammer
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Group.Commute.Basic
import Mathlib.Algebra.Group.Pointwise.Set.Finite
import Mathlib.Algebra.Group.Subgroup.Finite
import Mathlib.Algebra.Module.NatInt
import Mathlib.Algebra.Order.Group.Action
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Data.Int.ModEq
import Mathlib.Dynamics.PeriodicPts.Lemmas
import Mathlib.GroupTheory.Index
import Mathlib.NumberTheory.Divisors
import Mathlib.Order.Interval.Set.Infinite
/-!
# Order of an element
This file defines the order of an element of a finite group. For a finite group `G` the order of
`x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`.
## Main definitions
* `IsOfFinOrder` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite
order.
* `IsOfFinAddOrder` is the additive analogue of `IsOfFinOrder`.
* `orderOf x` defines the order of an element `x` of a monoid `G`, by convention its value is `0`
if `x` has infinite order.
* `addOrderOf` is the additive analogue of `orderOf`.
## Tags
order of an element
-/
assert_not_exists Field
open Function Fintype Nat Pointwise Subgroup Submonoid
open scoped Finset
variable {G H A α β : Type*}
section Monoid
variable [Monoid G] {a b x y : G} {n m : ℕ}
section IsOfFinOrder
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed
@[to_additive]
theorem isPeriodicPt_mul_iff_pow_eq_one (x : G) : IsPeriodicPt (x * ·) n 1 ↔ x ^ n = 1 := by
rw [IsPeriodicPt, IsFixedPt, mul_left_iterate]; beta_reduce; rw [mul_one]
/-- `IsOfFinOrder` is a predicate on an element `x` of a monoid to be of finite order, i.e. there
exists `n ≥ 1` such that `x ^ n = 1`. -/
@[to_additive "`IsOfFinAddOrder` is a predicate on an element `a` of an
additive monoid to be of finite order, i.e. there exists `n ≥ 1` such that `n • a = 0`."]
def IsOfFinOrder (x : G) : Prop :=
(1 : G) ∈ periodicPts (x * ·)
theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) ↔ IsOfFinOrder x :=
Iff.rfl
theorem isOfFinOrder_ofAdd_iff {α : Type*} [AddMonoid α] {x : α} :
IsOfFinOrder (Multiplicative.ofAdd x) ↔ IsOfFinAddOrder x := Iff.rfl
@[to_additive]
theorem isOfFinOrder_iff_pow_eq_one : IsOfFinOrder x ↔ ∃ n, 0 < n ∧ x ^ n = 1 := by
simp [IsOfFinOrder, mem_periodicPts, isPeriodicPt_mul_iff_pow_eq_one]
@[to_additive] alias ⟨IsOfFinOrder.exists_pow_eq_one, _⟩ := isOfFinOrder_iff_pow_eq_one
@[to_additive]
lemma isOfFinOrder_iff_zpow_eq_one {G} [DivisionMonoid G] {x : G} :
IsOfFinOrder x ↔ ∃ (n : ℤ), n ≠ 0 ∧ x ^ n = 1 := by
rw [isOfFinOrder_iff_pow_eq_one]
refine ⟨fun ⟨n, hn, hn'⟩ ↦ ⟨n, Int.natCast_ne_zero_iff_pos.mpr hn, zpow_natCast x n ▸ hn'⟩,
fun ⟨n, hn, hn'⟩ ↦ ⟨n.natAbs, Int.natAbs_pos.mpr hn, ?_⟩⟩
rcases (Int.natAbs_eq_iff (a := n)).mp rfl with h | h
· rwa [h, zpow_natCast] at hn'
· rwa [h, zpow_neg, inv_eq_one, zpow_natCast] at hn'
/-- See also `injective_pow_iff_not_isOfFinOrder`. -/
@[to_additive "See also `injective_nsmul_iff_not_isOfFinAddOrder`."]
theorem not_isOfFinOrder_of_injective_pow {x : G} (h : Injective fun n : ℕ => x ^ n) :
¬IsOfFinOrder x := by
simp_rw [isOfFinOrder_iff_pow_eq_one, not_exists, not_and]
intro n hn_pos hnx
rw [← pow_zero x] at hnx
rw [h hnx] at hn_pos
exact irrefl 0 hn_pos
/-- 1 is of finite order in any monoid. -/
@[to_additive (attr := simp) "0 is of finite order in any additive monoid."]
theorem IsOfFinOrder.one : IsOfFinOrder (1 : G) :=
isOfFinOrder_iff_pow_eq_one.mpr ⟨1, Nat.one_pos, one_pow 1⟩
@[to_additive]
lemma IsOfFinOrder.pow {n : ℕ} : IsOfFinOrder a → IsOfFinOrder (a ^ n) := by
simp_rw [isOfFinOrder_iff_pow_eq_one]
rintro ⟨m, hm, ha⟩
exact ⟨m, hm, by simp [pow_right_comm _ n, ha]⟩
@[to_additive]
lemma IsOfFinOrder.of_pow {n : ℕ} (h : IsOfFinOrder (a ^ n)) (hn : n ≠ 0) : IsOfFinOrder a := by
rw [isOfFinOrder_iff_pow_eq_one] at *
rcases h with ⟨m, hm, ha⟩
exact ⟨n * m, mul_pos hn.bot_lt hm, by rwa [pow_mul]⟩
@[to_additive (attr := simp)]
lemma isOfFinOrder_pow {n : ℕ} : IsOfFinOrder (a ^ n) ↔ IsOfFinOrder a ∨ n = 0 := by
rcases Decidable.eq_or_ne n 0 with rfl | hn
· simp
· exact ⟨fun h ↦ .inl <| h.of_pow hn, fun h ↦ (h.resolve_right hn).pow⟩
/-- Elements of finite order are of finite order in submonoids. -/
@[to_additive "Elements of finite order are of finite order in submonoids."]
theorem Submonoid.isOfFinOrder_coe {H : Submonoid G} {x : H} :
IsOfFinOrder (x : G) ↔ IsOfFinOrder x := by
rw [isOfFinOrder_iff_pow_eq_one, isOfFinOrder_iff_pow_eq_one]
norm_cast
theorem IsConj.isOfFinOrder (h : IsConj x y) : IsOfFinOrder x → IsOfFinOrder y := by
simp_rw [isOfFinOrder_iff_pow_eq_one]
rintro ⟨n, n_gt_0, eq'⟩
exact ⟨n, n_gt_0, by rw [← isConj_one_right, ← eq']; exact h.pow n⟩
/-- The image of an element of finite order has finite order. -/
@[to_additive "The image of an element of finite additive order has finite additive order."]
theorem MonoidHom.isOfFinOrder [Monoid H] (f : G →* H) {x : G} (h : IsOfFinOrder x) :
IsOfFinOrder <| f x :=
isOfFinOrder_iff_pow_eq_one.mpr <| by
obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one
exact ⟨n, npos, by rw [← f.map_pow, hn, f.map_one]⟩
/-- If a direct product has finite order then so does each component. -/
@[to_additive "If a direct product has finite additive order then so does each component."]
theorem IsOfFinOrder.apply {η : Type*} {Gs : η → Type*} [∀ i, Monoid (Gs i)] {x : ∀ i, Gs i}
(h : IsOfFinOrder x) : ∀ i, IsOfFinOrder (x i) := by
obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one
exact fun _ => isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, (congr_fun hn.symm _).symm⟩
/-- The submonoid generated by an element is a group if that element has finite order. -/
@[to_additive "The additive submonoid generated by an element is
an additive group if that element has finite order."]
noncomputable abbrev IsOfFinOrder.groupPowers (hx : IsOfFinOrder x) :
Group (Submonoid.powers x) := by
obtain ⟨hpos, hx⟩ := hx.exists_pow_eq_one.choose_spec
exact Submonoid.groupPowers hpos hx
end IsOfFinOrder
/-- `orderOf x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists.
Otherwise, i.e. if `x` is of infinite order, then `orderOf x` is `0` by convention. -/
@[to_additive
"`addOrderOf a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it
exists. Otherwise, i.e. if `a` is of infinite order, then `addOrderOf a` is `0` by convention."]
noncomputable def orderOf (x : G) : ℕ :=
minimalPeriod (x * ·) 1
@[simp]
theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x :=
rfl
@[simp]
lemma orderOf_ofAdd_eq_addOrderOf {α : Type*} [AddMonoid α] (a : α) :
orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl
@[to_additive]
protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x :=
minimalPeriod_pos_of_mem_periodicPts h
@[to_additive addOrderOf_nsmul_eq_zero]
theorem pow_orderOf_eq_one (x : G) : x ^ orderOf x = 1 := by
convert Eq.trans _ (isPeriodicPt_minimalPeriod (x * ·) 1)
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed in the middle of the rewrite
rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one]
@[to_additive]
theorem orderOf_eq_zero (h : ¬IsOfFinOrder x) : orderOf x = 0 := by
rwa [orderOf, minimalPeriod, dif_neg]
@[to_additive]
theorem orderOf_eq_zero_iff : orderOf x = 0 ↔ ¬IsOfFinOrder x :=
⟨fun h H ↦ H.orderOf_pos.ne' h, orderOf_eq_zero⟩
@[to_additive]
theorem orderOf_eq_zero_iff' : orderOf x = 0 ↔ ∀ n : ℕ, 0 < n → x ^ n ≠ 1 := by
simp_rw [orderOf_eq_zero_iff, isOfFinOrder_iff_pow_eq_one, not_exists, not_and]
@[to_additive]
theorem orderOf_eq_iff {n} (h : 0 < n) :
orderOf x = n ↔ x ^ n = 1 ∧ ∀ m, m < n → 0 < m → x ^ m ≠ 1 := by
simp_rw [Ne, ← isPeriodicPt_mul_iff_pow_eq_one, orderOf, minimalPeriod]
split_ifs with h1
· classical
rw [find_eq_iff]
simp only [h, true_and]
push_neg
rfl
· rw [iff_false_left h.ne]
rintro ⟨h', -⟩
exact h1 ⟨n, h, h'⟩
/-- A group element has finite order iff its order is positive. -/
@[to_additive
"A group element has finite additive order iff its order is positive."]
theorem orderOf_pos_iff : 0 < orderOf x ↔ IsOfFinOrder x := by
rw [iff_not_comm.mp orderOf_eq_zero_iff, pos_iff_ne_zero]
@[to_additive]
theorem IsOfFinOrder.mono [Monoid β] {y : β} (hx : IsOfFinOrder x) (h : orderOf y ∣ orderOf x) :
IsOfFinOrder y := by rw [← orderOf_pos_iff] at hx ⊢; exact Nat.pos_of_dvd_of_pos h hx
@[to_additive]
theorem pow_ne_one_of_lt_orderOf (n0 : n ≠ 0) (h : n < orderOf x) : x ^ n ≠ 1 := fun j =>
not_isPeriodicPt_of_pos_of_lt_minimalPeriod n0 h ((isPeriodicPt_mul_iff_pow_eq_one x).mpr j)
@[to_additive]
theorem orderOf_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : orderOf x ≤ n :=
IsPeriodicPt.minimalPeriod_le hn (by rwa [isPeriodicPt_mul_iff_pow_eq_one])
@[to_additive (attr := simp)]
theorem orderOf_one : orderOf (1 : G) = 1 := by
rw [orderOf, ← minimalPeriod_id (x := (1 : G)), ← one_mul_eq_id]
@[to_additive (attr := simp) AddMonoid.addOrderOf_eq_one_iff]
theorem orderOf_eq_one_iff : orderOf x = 1 ↔ x = 1 := by
rw [orderOf, minimalPeriod_eq_one_iff_isFixedPt, IsFixedPt, mul_one]
@[to_additive (attr := simp) mod_addOrderOf_nsmul]
lemma pow_mod_orderOf (x : G) (n : ℕ) : x ^ (n % orderOf x) = x ^ n :=
calc
x ^ (n % orderOf x) = x ^ (n % orderOf x + orderOf x * (n / orderOf x)) := by
simp [pow_add, pow_mul, pow_orderOf_eq_one]
_ = x ^ n := by rw [Nat.mod_add_div]
@[to_additive]
theorem orderOf_dvd_of_pow_eq_one (h : x ^ n = 1) : orderOf x ∣ n :=
IsPeriodicPt.minimalPeriod_dvd ((isPeriodicPt_mul_iff_pow_eq_one _).mpr h)
@[to_additive]
theorem orderOf_dvd_iff_pow_eq_one {n : ℕ} : orderOf x ∣ n ↔ x ^ n = 1 :=
⟨fun h => by rw [← pow_mod_orderOf, Nat.mod_eq_zero_of_dvd h, _root_.pow_zero],
orderOf_dvd_of_pow_eq_one⟩
@[to_additive addOrderOf_smul_dvd]
theorem orderOf_pow_dvd (n : ℕ) : orderOf (x ^ n) ∣ orderOf x := by
rw [orderOf_dvd_iff_pow_eq_one, pow_right_comm, pow_orderOf_eq_one, one_pow]
@[to_additive]
lemma pow_injOn_Iio_orderOf : (Set.Iio <| orderOf x).InjOn (x ^ ·) := by
simpa only [mul_left_iterate, mul_one]
using iterate_injOn_Iio_minimalPeriod (f := (x * ·)) (x := 1)
@[to_additive]
protected lemma IsOfFinOrder.mem_powers_iff_mem_range_orderOf [DecidableEq G]
(hx : IsOfFinOrder x) :
y ∈ Submonoid.powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) :=
Finset.mem_range_iff_mem_finset_range_of_mod_eq' hx.orderOf_pos <| pow_mod_orderOf _
@[to_additive]
protected lemma IsOfFinOrder.powers_eq_image_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) :
(Submonoid.powers x : Set G) = (Finset.range (orderOf x)).image (x ^ ·) :=
Set.ext fun _ ↦ hx.mem_powers_iff_mem_range_orderOf
@[to_additive]
theorem pow_eq_one_iff_modEq : x ^ n = 1 ↔ n ≡ 0 [MOD orderOf x] := by
rw [modEq_zero_iff_dvd, orderOf_dvd_iff_pow_eq_one]
@[to_additive]
theorem orderOf_map_dvd {H : Type*} [Monoid H] (ψ : G →* H) (x : G) :
orderOf (ψ x) ∣ orderOf x := by
apply orderOf_dvd_of_pow_eq_one
rw [← map_pow, pow_orderOf_eq_one]
apply map_one
@[to_additive]
theorem exists_pow_eq_self_of_coprime (h : n.Coprime (orderOf x)) : ∃ m : ℕ, (x ^ n) ^ m = x := by
by_cases h0 : orderOf x = 0
· rw [h0, coprime_zero_right] at h
exact ⟨1, by rw [h, pow_one, pow_one]⟩
by_cases h1 : orderOf x = 1
· exact ⟨0, by rw [orderOf_eq_one_iff.mp h1, one_pow, one_pow]⟩
obtain ⟨m, h⟩ := exists_mul_emod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩)
exact ⟨m, by rw [← pow_mul, ← pow_mod_orderOf, h, pow_one]⟩
/-- If `x^n = 1`, but `x^(n/p) ≠ 1` for all prime factors `p` of `n`,
then `x` has order `n` in `G`. -/
@[to_additive addOrderOf_eq_of_nsmul_and_div_prime_nsmul "If `n * x = 0`, but `n/p * x ≠ 0` for
all prime factors `p` of `n`, then `x` has order `n` in `G`."]
theorem orderOf_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x ^ n = 1)
(hd : ∀ p : ℕ, p.Prime → p ∣ n → x ^ (n / p) ≠ 1) : orderOf x = n := by
-- Let `a` be `n/(orderOf x)`, and show `a = 1`
obtain ⟨a, ha⟩ := exists_eq_mul_right_of_dvd (orderOf_dvd_of_pow_eq_one hx)
suffices a = 1 by simp [this, ha]
-- Assume `a` is not one...
by_contra h
have a_min_fac_dvd_p_sub_one : a.minFac ∣ n := by
obtain ⟨b, hb⟩ : ∃ b : ℕ, a = b * a.minFac := exists_eq_mul_left_of_dvd a.minFac_dvd
rw [hb, ← mul_assoc] at ha
exact Dvd.intro_left (orderOf x * b) ha.symm
-- Use the minimum prime factor of `a` as `p`.
refine hd a.minFac (Nat.minFac_prime h) a_min_fac_dvd_p_sub_one ?_
rw [← orderOf_dvd_iff_pow_eq_one, Nat.dvd_div_iff_mul_dvd a_min_fac_dvd_p_sub_one, ha, mul_comm,
Nat.mul_dvd_mul_iff_left (IsOfFinOrder.orderOf_pos _)]
· exact Nat.minFac_dvd a
· rw [isOfFinOrder_iff_pow_eq_one]
exact Exists.intro n (id ⟨hn, hx⟩)
@[to_additive]
theorem orderOf_eq_orderOf_iff {H : Type*} [Monoid H] {y : H} :
orderOf x = orderOf y ↔ ∀ n : ℕ, x ^ n = 1 ↔ y ^ n = 1 := by
simp_rw [← isPeriodicPt_mul_iff_pow_eq_one, ← minimalPeriod_eq_minimalPeriod_iff, orderOf]
/-- An injective homomorphism of monoids preserves orders of elements. -/
@[to_additive "An injective homomorphism of additive monoids preserves orders of elements."]
theorem orderOf_injective {H : Type*} [Monoid H] (f : G →* H) (hf : Function.Injective f) (x : G) :
orderOf (f x) = orderOf x := by
simp_rw [orderOf_eq_orderOf_iff, ← f.map_pow, ← f.map_one, hf.eq_iff, forall_const]
/-- A multiplicative equivalence preserves orders of elements. -/
@[to_additive (attr := simp) "An additive equivalence preserves orders of elements."]
lemma MulEquiv.orderOf_eq {H : Type*} [Monoid H] (e : G ≃* H) (x : G) :
orderOf (e x) = orderOf x :=
orderOf_injective e.toMonoidHom e.injective x
@[to_additive]
theorem Function.Injective.isOfFinOrder_iff [Monoid H] {f : G →* H} (hf : Injective f) :
IsOfFinOrder (f x) ↔ IsOfFinOrder x := by
rw [← orderOf_pos_iff, orderOf_injective f hf x, ← orderOf_pos_iff]
@[to_additive (attr := norm_cast, simp)]
theorem orderOf_submonoid {H : Submonoid G} (y : H) : orderOf (y : G) = orderOf y :=
orderOf_injective H.subtype Subtype.coe_injective y
@[to_additive]
theorem orderOf_units {y : Gˣ} : orderOf (y : G) = orderOf y :=
orderOf_injective (Units.coeHom G) Units.ext y
/-- If the order of `x` is finite, then `x` is a unit with inverse `x ^ (orderOf x - 1)`. -/
@[to_additive (attr := simps) "If the additive order of `x` is finite, then `x` is an additive
unit with inverse `(addOrderOf x - 1) • x`. "]
noncomputable def IsOfFinOrder.unit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : Mˣ :=
⟨x, x ^ (orderOf x - 1),
by rw [← _root_.pow_succ', tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one],
by rw [← _root_.pow_succ, tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one]⟩
@[to_additive]
lemma IsOfFinOrder.isUnit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : IsUnit x := ⟨hx.unit, rfl⟩
variable (x)
@[to_additive]
theorem orderOf_pow' (h : n ≠ 0) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by
unfold orderOf
rw [← minimalPeriod_iterate_eq_div_gcd h, mul_left_iterate]
@[to_additive]
lemma orderOf_pow_of_dvd {x : G} {n : ℕ} (hn : n ≠ 0) (dvd : n ∣ orderOf x) :
orderOf (x ^ n) = orderOf x / n := by rw [orderOf_pow' _ hn, Nat.gcd_eq_right dvd]
@[to_additive]
lemma orderOf_pow_orderOf_div {x : G} {n : ℕ} (hx : orderOf x ≠ 0) (hn : n ∣ orderOf x) :
orderOf (x ^ (orderOf x / n)) = n := by
rw [orderOf_pow_of_dvd _ (Nat.div_dvd_of_dvd hn), Nat.div_div_self hn hx]
rw [← Nat.div_mul_cancel hn] at hx; exact left_ne_zero_of_mul hx
variable (n)
@[to_additive]
protected lemma IsOfFinOrder.orderOf_pow (h : IsOfFinOrder x) :
orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by
unfold orderOf
rw [← minimalPeriod_iterate_eq_div_gcd' h, mul_left_iterate]
@[to_additive]
lemma Nat.Coprime.orderOf_pow (h : (orderOf y).Coprime m) : orderOf (y ^ m) = orderOf y := by
by_cases hg : IsOfFinOrder y
· rw [hg.orderOf_pow y m , h.gcd_eq_one, Nat.div_one]
· rw [m.coprime_zero_left.1 (orderOf_eq_zero hg ▸ h), pow_one]
@[to_additive]
lemma IsOfFinOrder.natCard_powers_le_orderOf (ha : IsOfFinOrder a) :
Nat.card (powers a : Set G) ≤ orderOf a := by
classical
simpa [ha.powers_eq_image_range_orderOf, Finset.card_range, Nat.Iio_eq_range]
using Finset.card_image_le (s := Finset.range (orderOf a))
@[to_additive]
lemma IsOfFinOrder.finite_powers (ha : IsOfFinOrder a) : (powers a : Set G).Finite := by
classical rw [ha.powers_eq_image_range_orderOf]; exact Finset.finite_toSet _
namespace Commute
variable {x}
@[to_additive]
theorem orderOf_mul_dvd_lcm (h : Commute x y) :
orderOf (x * y) ∣ Nat.lcm (orderOf x) (orderOf y) := by
rw [orderOf, ← comp_mul_left]
exact Function.Commute.minimalPeriod_of_comp_dvd_lcm h.function_commute_mul_left
@[to_additive]
theorem orderOf_dvd_lcm_mul (h : Commute x y):
orderOf y ∣ Nat.lcm (orderOf x) (orderOf (x * y)) := by
by_cases h0 : orderOf x = 0
· rw [h0, lcm_zero_left]
apply dvd_zero
conv_lhs =>
rw [← one_mul y, ← pow_orderOf_eq_one x, ← succ_pred_eq_of_pos (Nat.pos_of_ne_zero h0),
_root_.pow_succ, mul_assoc]
exact
(((Commute.refl x).mul_right h).pow_left _).orderOf_mul_dvd_lcm.trans
(lcm_dvd_iff.2 ⟨(orderOf_pow_dvd _).trans (dvd_lcm_left _ _), dvd_lcm_right _ _⟩)
@[to_additive addOrderOf_add_dvd_mul_addOrderOf]
theorem orderOf_mul_dvd_mul_orderOf (h : Commute x y):
orderOf (x * y) ∣ orderOf x * orderOf y :=
dvd_trans h.orderOf_mul_dvd_lcm (lcm_dvd_mul _ _)
@[to_additive addOrderOf_add_eq_mul_addOrderOf_of_coprime]
theorem orderOf_mul_eq_mul_orderOf_of_coprime (h : Commute x y)
(hco : (orderOf x).Coprime (orderOf y)) : orderOf (x * y) = orderOf x * orderOf y := by
rw [orderOf, ← comp_mul_left]
exact h.function_commute_mul_left.minimalPeriod_of_comp_eq_mul_of_coprime hco
/-- Commuting elements of finite order are closed under multiplication. -/
@[to_additive "Commuting elements of finite additive order are closed under addition."]
theorem isOfFinOrder_mul (h : Commute x y) (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) :
IsOfFinOrder (x * y) :=
orderOf_pos_iff.mp <|
pos_of_dvd_of_pos h.orderOf_mul_dvd_mul_orderOf <| mul_pos hx.orderOf_pos hy.orderOf_pos
/-- If each prime factor of `orderOf x` has higher multiplicity in `orderOf y`, and `x` commutes
with `y`, then `x * y` has the same order as `y`. -/
@[to_additive addOrderOf_add_eq_right_of_forall_prime_mul_dvd
"If each prime factor of
`addOrderOf x` has higher multiplicity in `addOrderOf y`, and `x` commutes with `y`,
then `x + y` has the same order as `y`."]
theorem orderOf_mul_eq_right_of_forall_prime_mul_dvd (h : Commute x y) (hy : IsOfFinOrder y)
(hdvd : ∀ p : ℕ, p.Prime → p ∣ orderOf x → p * orderOf x ∣ orderOf y) :
orderOf (x * y) = orderOf y := by
have hoy := hy.orderOf_pos
have hxy := dvd_of_forall_prime_mul_dvd hdvd
apply orderOf_eq_of_pow_and_pow_div_prime hoy <;> simp only [Ne, ← orderOf_dvd_iff_pow_eq_one]
· exact h.orderOf_mul_dvd_lcm.trans (lcm_dvd hxy dvd_rfl)
refine fun p hp hpy hd => hp.ne_one ?_
rw [← Nat.dvd_one, ← mul_dvd_mul_iff_right hoy.ne', one_mul, ← dvd_div_iff_mul_dvd hpy]
refine (orderOf_dvd_lcm_mul h).trans (lcm_dvd ((dvd_div_iff_mul_dvd hpy).2 ?_) hd)
by_cases h : p ∣ orderOf x
exacts [hdvd p hp h, (hp.coprime_iff_not_dvd.2 h).mul_dvd_of_dvd_of_dvd hpy hxy]
end Commute
section PPrime
variable {x n} {p : ℕ} [hp : Fact p.Prime]
@[to_additive]
theorem orderOf_eq_prime_iff : orderOf x = p ↔ x ^ p = 1 ∧ x ≠ 1 := by
rw [orderOf, minimalPeriod_eq_prime_iff, isPeriodicPt_mul_iff_pow_eq_one, IsFixedPt, mul_one]
/-- The backward direction of `orderOf_eq_prime_iff`. -/
@[to_additive "The backward direction of `addOrderOf_eq_prime_iff`."]
theorem orderOf_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : orderOf x = p :=
orderOf_eq_prime_iff.mpr ⟨hg, hg1⟩
@[to_additive addOrderOf_eq_prime_pow]
theorem orderOf_eq_prime_pow (hnot : ¬x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) :
orderOf x = p ^ (n + 1) := by
apply minimalPeriod_eq_prime_pow <;> rwa [isPeriodicPt_mul_iff_pow_eq_one]
@[to_additive exists_addOrderOf_eq_prime_pow_iff]
theorem exists_orderOf_eq_prime_pow_iff :
(∃ k : ℕ, orderOf x = p ^ k) ↔ ∃ m : ℕ, x ^ (p : ℕ) ^ m = 1 :=
⟨fun ⟨k, hk⟩ => ⟨k, by rw [← hk, pow_orderOf_eq_one]⟩, fun ⟨_, hm⟩ => by
obtain ⟨k, _, hk⟩ := (Nat.dvd_prime_pow hp.elim).mp (orderOf_dvd_of_pow_eq_one hm)
exact ⟨k, hk⟩⟩
end PPrime
/-- The equivalence between `Fin (orderOf x)` and `Submonoid.powers x`, sending `i` to `x ^ i` -/
@[to_additive "The equivalence between `Fin (addOrderOf a)` and
`AddSubmonoid.multiples a`, sending `i` to `i • a`"]
noncomputable def finEquivPowers {x : G} (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ powers x :=
Equiv.ofBijective (fun n ↦ ⟨x ^ (n : ℕ), ⟨n, rfl⟩⟩) ⟨fun ⟨_, h₁⟩ ⟨_, h₂⟩ ij ↦
Fin.ext (pow_injOn_Iio_orderOf h₁ h₂ (Subtype.mk_eq_mk.1 ij)), fun ⟨_, i, rfl⟩ ↦
⟨⟨i % orderOf x, mod_lt _ hx.orderOf_pos⟩, Subtype.eq <| pow_mod_orderOf _ _⟩⟩
@[to_additive (attr := simp)]
lemma finEquivPowers_apply {x : G} (hx : IsOfFinOrder x) {n : Fin (orderOf x)} :
finEquivPowers hx n = ⟨x ^ (n : ℕ), n, rfl⟩ := rfl
@[to_additive (attr := simp)]
lemma finEquivPowers_symm_apply {x : G} (hx : IsOfFinOrder x) (n : ℕ) :
(finEquivPowers hx).symm ⟨x ^ n, _, rfl⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by
rw [Equiv.symm_apply_eq, finEquivPowers_apply, Subtype.mk_eq_mk, ← pow_mod_orderOf, Fin.val_mk]
variable {x n} (hx : IsOfFinOrder x)
include hx
@[to_additive]
theorem IsOfFinOrder.pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by
wlog hmn : m ≤ n generalizing m n
· rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)]
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn
rw [pow_add, (hx.isUnit.pow _).mul_eq_left, pow_eq_one_iff_modEq]
exact ⟨fun h ↦ Nat.ModEq.add_left _ h, fun h ↦ Nat.ModEq.add_left_cancel' _ h⟩
@[to_additive]
lemma IsOfFinOrder.pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x :=
hx.pow_eq_pow_iff_modEq
end Monoid
section CancelMonoid
variable [LeftCancelMonoid G] {x y : G} {a : G} {m n : ℕ}
@[to_additive]
theorem pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by
wlog hmn : m ≤ n generalizing m n
· rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)]
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn
rw [← mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modEq]
exact ⟨fun h => Nat.ModEq.add_left _ h, fun h => Nat.ModEq.add_left_cancel' _ h⟩
@[to_additive (attr := simp)]
lemma injective_pow_iff_not_isOfFinOrder : Injective (fun n : ℕ ↦ x ^ n) ↔ ¬IsOfFinOrder x := by
refine ⟨fun h => not_isOfFinOrder_of_injective_pow h, fun h n m hnm => ?_⟩
rwa [pow_eq_pow_iff_modEq, orderOf_eq_zero_iff.mpr h, modEq_zero_iff] at hnm
@[to_additive]
lemma pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := pow_eq_pow_iff_modEq
@[to_additive]
theorem pow_inj_iff_of_orderOf_eq_zero (h : orderOf x = 0) {n m : ℕ} : x ^ n = x ^ m ↔ n = m := by
rw [pow_eq_pow_iff_modEq, h, modEq_zero_iff]
@[to_additive]
theorem infinite_not_isOfFinOrder {x : G} (h : ¬IsOfFinOrder x) :
{ y : G | ¬IsOfFinOrder y }.Infinite := by
let s := { n | 0 < n }.image fun n : ℕ => x ^ n
have hs : s ⊆ { y : G | ¬IsOfFinOrder y } := by
rintro - ⟨n, hn : 0 < n, rfl⟩ (contra : IsOfFinOrder (x ^ n))
apply h
rw [isOfFinOrder_iff_pow_eq_one] at contra ⊢
obtain ⟨m, hm, hm'⟩ := contra
exact ⟨n * m, mul_pos hn hm, by rwa [pow_mul]⟩
suffices s.Infinite by exact this.mono hs
contrapose! h
have : ¬Injective fun n : ℕ => x ^ n := by
have := Set.not_injOn_infinite_finite_image (Set.Ioi_infinite 0) (Set.not_infinite.mp h)
contrapose! this
exact Set.injOn_of_injective this
rwa [injective_pow_iff_not_isOfFinOrder, Classical.not_not] at this
@[to_additive (attr := simp)]
lemma finite_powers : (powers a : Set G).Finite ↔ IsOfFinOrder a := by
refine ⟨fun h ↦ ?_, IsOfFinOrder.finite_powers⟩
obtain ⟨m, n, hmn, ha⟩ := h.exists_lt_map_eq_of_forall_mem (f := fun n : ℕ ↦ a ^ n)
(fun n ↦ by simp [mem_powers_iff])
refine isOfFinOrder_iff_pow_eq_one.2 ⟨n - m, tsub_pos_iff_lt.2 hmn, ?_⟩
rw [← mul_left_cancel_iff (a := a ^ m), ← pow_add, add_tsub_cancel_of_le hmn.le, ha, mul_one]
@[to_additive (attr := simp)]
lemma infinite_powers : (powers a : Set G).Infinite ↔ ¬ IsOfFinOrder a := finite_powers.not
/-- See also `orderOf_eq_card_powers`. -/
@[to_additive "See also `addOrder_eq_card_multiples`."]
lemma Nat.card_submonoidPowers : Nat.card (powers a) = orderOf a := by
classical
by_cases ha : IsOfFinOrder a
· exact (Nat.card_congr (finEquivPowers ha).symm).trans <| by simp
· have := (infinite_powers.2 ha).to_subtype
rw [orderOf_eq_zero ha, Nat.card_eq_zero_of_infinite]
end CancelMonoid
section Group
variable [Group G] {x y : G} {i : ℤ}
/-- Inverses of elements of finite order have finite order. -/
@[to_additive (attr := simp) "Inverses of elements of finite additive order
have finite additive order."]
| Mathlib/GroupTheory/OrderOfElement.lean | 586 | 601 | theorem isOfFinOrder_inv_iff {x : G} : IsOfFinOrder x⁻¹ ↔ IsOfFinOrder x := by | simp [isOfFinOrder_iff_pow_eq_one]
@[to_additive] alias ⟨IsOfFinOrder.of_inv, IsOfFinOrder.inv⟩ := isOfFinOrder_inv_iff
@[to_additive]
theorem orderOf_dvd_iff_zpow_eq_one : (orderOf x : ℤ) ∣ i ↔ x ^ i = 1 := by
rcases Int.eq_nat_or_neg i with ⟨i, rfl | rfl⟩
· rw [Int.natCast_dvd_natCast, orderOf_dvd_iff_pow_eq_one, zpow_natCast]
· rw [dvd_neg, Int.natCast_dvd_natCast, zpow_neg, inv_eq_one, zpow_natCast,
orderOf_dvd_iff_pow_eq_one]
@[to_additive (attr := simp)]
theorem orderOf_inv (x : G) : orderOf x⁻¹ = orderOf x := by simp [orderOf_eq_orderOf_iff]
@[to_additive] |
/-
Copyright (c) 2023 Scott Carnahan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Carnahan
-/
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.Nat.Cast.Basic
import Mathlib.Algebra.Group.Prod
/-!
# Typeclasses for power-associative structures
In this file we define power-associativity for algebraic structures with a multiplication operation.
The class is a Prop-valued mixin named `NatPowAssoc`.
## Results
- `npow_add` a defining property: `x ^ (k + n) = x ^ k * x ^ n`
- `npow_one` a defining property: `x ^ 1 = x`
- `npow_assoc` strictly positive powers of an element have associative multiplication.
- `npow_comm` `x ^ m * x ^ n = x ^ n * x ^ m` for strictly positive `m` and `n`.
- `npow_mul` `x ^ (m * n) = (x ^ m) ^ n` for strictly positive `m` and `n`.
- `npow_eq_pow` monoid exponentiation coincides with semigroup exponentiation.
## Instances
We also produce the following instances:
- `NatPowAssoc` for Monoids, Pi types and products.
## TODO
* to_additive?
-/
assert_not_exists DenselyOrdered
variable {M : Type*}
/-- A mixin for power-associative multiplication. -/
class NatPowAssoc (M : Type*) [MulOneClass M] [Pow M ℕ] : Prop where
/-- Multiplication is power-associative. -/
protected npow_add : ∀ (k n : ℕ) (x : M), x ^ (k + n) = x ^ k * x ^ n
/-- Exponent zero is one. -/
protected npow_zero : ∀ (x : M), x ^ 0 = 1
/-- Exponent one is identity. -/
protected npow_one : ∀ (x : M), x ^ 1 = x
section MulOneClass
variable [MulOneClass M] [Pow M ℕ] [NatPowAssoc M]
theorem npow_add (k n : ℕ) (x : M) : x ^ (k + n) = x ^ k * x ^ n :=
NatPowAssoc.npow_add k n x
@[simp]
theorem npow_zero (x : M) : x ^ 0 = 1 :=
NatPowAssoc.npow_zero x
@[simp]
theorem npow_one (x : M) : x ^ 1 = x :=
NatPowAssoc.npow_one x
theorem npow_mul_assoc (k m n : ℕ) (x : M) :
(x ^ k * x ^ m) * x ^ n = x ^ k * (x ^ m * x ^ n) := by
simp only [← npow_add, add_assoc]
theorem npow_mul_comm (m n : ℕ) (x : M) :
x ^ m * x ^ n = x ^ n * x ^ m := by simp only [← npow_add, add_comm]
theorem npow_mul (x : M) (m n : ℕ) : x ^ (m * n) = (x ^ m) ^ n := by
induction n with
| zero => rw [npow_zero, Nat.mul_zero, npow_zero]
| succ n ih => rw [mul_add, npow_add, ih, mul_one, npow_add, npow_one]
theorem npow_mul' (x : M) (m n : ℕ) : x ^ (m * n) = (x ^ n) ^ m := by
rw [mul_comm]
exact npow_mul x n m
end MulOneClass
section Neg
theorem neg_npow_assoc {R : Type*} [NonAssocRing R] [Pow R ℕ] [NatPowAssoc R] (a b : R) (k : ℕ) :
(-1)^k * a * b = (-1)^k * (a * b) := by
induction k with
| zero => simp only [npow_zero, one_mul]
| succ k ih =>
rw [npow_add, npow_one, ← neg_mul_comm, mul_one]
simp only [neg_mul, ih]
end Neg
instance Pi.instNatPowAssoc {ι : Type*} {α : ι → Type*} [∀ i, MulOneClass <| α i] [∀ i, Pow (α i) ℕ]
[∀ i, NatPowAssoc <| α i] : NatPowAssoc (∀ i, α i) where
npow_add _ _ _ := by ext; simp [npow_add]
npow_zero _ := by ext; simp
npow_one _ := by ext; simp
instance Prod.instNatPowAssoc {N : Type*} [MulOneClass M] [Pow M ℕ] [NatPowAssoc M] [MulOneClass N]
[Pow N ℕ] [NatPowAssoc N] : NatPowAssoc (M × N) where
npow_add _ _ _ := by ext <;> simp [npow_add]
npow_zero _ := by ext <;> simp
npow_one _ := by ext <;> simp
section Monoid
variable [Monoid M]
instance Monoid.PowAssoc : NatPowAssoc M where
npow_add _ _ _ := pow_add _ _ _
npow_zero _ := pow_zero _
npow_one _ := pow_one _
@[simp, norm_cast]
| Mathlib/Algebra/Group/NatPowAssoc.lean | 117 | 121 | theorem Nat.cast_npow (R : Type*) [NonAssocSemiring R] [Pow R ℕ] [NatPowAssoc R] (n m : ℕ) :
(↑(n ^ m) : R) = (↑n : R) ^ m := by | induction m with
| zero => simp only [pow_zero, Nat.cast_one, npow_zero]
| succ m ih => rw [npow_add, npow_add, Nat.cast_mul, ih, npow_one, npow_one] |
/-
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
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Norm
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential Function
This file contains the definitions of the real and complex exponential function.
## Main definitions
* `Complex.exp`: The complex exponential function, defined via its Taylor series
* `Real.exp`: The real exponential function, defined as the real part of the complex exponential
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
theorem isCauSeq_norm_exp (z : ℂ) :
IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ :=
let ⟨n, hn⟩ := exists_nat_gt ‖z‖
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn
IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by
rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul,
← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div,
norm_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_norm_exp z).of_abv
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
@[pp_nodot]
def exp' (z : ℂ) : CauSeq ℂ (‖·‖) :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
/-- The complex exponential function, defined via its Taylor series -/
@[pp_nodot]
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
@[pp_nodot]
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε
rcases j with - | j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel₀ h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y)
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp z.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
@[simp]
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
end Complex
namespace Real
open Complex
variable (x y : ℝ)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
/-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ :=
{ toFun := fun x => exp x.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℝ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℝ) expMonoidHom f s
lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
@[simp]
nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h =>
exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all
nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ :=
ofReal_injective <| by simp [exp_neg]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x :=
calc
∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by
refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re]
lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x :=
calc
x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n)
_ ≤ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x :=
calc
1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ ≤ exp x := sum_le_exp_of_nonneg hx 3
private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx]
@[bound]
theorem exp_pos (x : ℝ) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by
rw [← neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
@[bound]
lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : ℝ) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [← sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
@[gcongr]
theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
@[gcongr, bound]
theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y :=
exp_strictMono.lt_iff_lt
@[simp]
theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y :=
exp_strictMono.le_iff_le
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
@[simp]
theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y :=
exp_injective.eq_iff
@[simp]
| Mathlib/Data/Complex/Exponential.lean | 319 | 323 | theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 :=
exp_injective.eq_iff' exp_zero
@[simp]
theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by | rw [← exp_zero, exp_lt_exp] |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.TwoDim
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic
/-!
# Oriented angles.
This file defines oriented angles in real inner product spaces.
## Main definitions
* `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation.
## Implementation notes
The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes,
angles modulo `π` are more convenient, because results are true for such angles with less
configuration dependence. Results that are only equalities modulo `π` can be represented
modulo `2 * π` as equalities of `(2 : ℤ) • θ`.
## References
* Evan Chen, Euclidean Geometry in Mathematical Olympiads.
-/
noncomputable section
open Module Complex
open scoped Real RealInnerProductSpace ComplexConjugate
namespace Orientation
attribute [local instance] Complex.finrank_real_complex_fact
variable {V V' : Type*}
variable [NormedAddCommGroup V] [NormedAddCommGroup V']
variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V']
variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2))
local notation "ω" => o.areaForm
/-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0.
See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/
def oangle (x y : V) : Real.Angle :=
Complex.arg (o.kahler x y)
/-- Oriented angles are continuous when the vectors involved are nonzero. -/
@[fun_prop]
theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) :
ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by
refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_
· exact o.kahler_ne_zero hx1 hx2
exact ((continuous_ofReal.comp continuous_inner).add
((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt
/-- If the first vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle]
/-- If the second vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle]
/-- If the two vectors passed to `oangle` are the same, the result is 0. -/
@[simp]
theorem oangle_self (x : V) : o.oangle x x = 0 := by
rw [oangle, kahler_apply_self, ← ofReal_pow]
convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π))
apply arg_ofReal_of_nonneg
positivity
/-- If the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by
rintro rfl; simp at h
/-- If the angle between two vectors is `π`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y :=
o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y :=
o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y :=
o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- Swapping the two vectors passed to `oangle` negates the angle. -/
theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by
simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle]
/-- Adding the angles between two vectors in each order results in 0. -/
@[simp]
theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by
simp [o.oangle_rev y x]
/-- Negating the first vector passed to `oangle` adds `π` to the angle. -/
theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle (-x) y = o.oangle x y + π := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the second vector passed to `oangle` adds `π` to the angle. -/
theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle x (-y) = o.oangle x y + π := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the first vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_left (x y : V) :
(2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by
by_cases hx : x = 0
· simp [hx]
· by_cases hy : y = 0
· simp [hy]
· simp [o.oangle_neg_left hx hy]
/-- Negating the second vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_right (x y : V) :
(2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by
by_cases hx : x = 0
· simp [hx]
· by_cases hy : y = 0
· simp [hy]
· simp [o.oangle_neg_right hx hy]
/-- Negating both vectors passed to `oangle` does not change the angle. -/
@[simp]
theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle]
/-- Negating the first vector produces the same angle as negating the second vector. -/
theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by
rw [← neg_neg y, oangle_neg_neg, neg_neg]
/-- The angle between the negation of a nonzero vector and that vector is `π`. -/
@[simp]
theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by
simp [oangle_neg_left, hx]
/-- The angle between a nonzero vector and its negation is `π`. -/
@[simp]
theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by
simp [oangle_neg_right, hx]
/-- Twice the angle between the negation of a vector and that vector is 0. -/
theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Twice the angle between a vector and its negation is 0. -/
theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Adding the angles between two vectors in each order, with the first vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by
rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel]
/-- Adding the angles between two vectors in each order, with the second vector in each angle
negated, results in 0. -/
@[simp]
| Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean | 243 | 243 | theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by | |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Chris Hughes, Floris van Doorn, Yaël Dillies
-/
import Mathlib.Data.Nat.Basic
import Mathlib.Tactic.GCongr.CoreAttrs
import Mathlib.Tactic.Common
import Mathlib.Tactic.Monotonicity.Attr
/-!
# Factorial and variants
This file defines the factorial, along with the ascending and descending variants.
For the proof that the factorial of `n` counts the permutations of an `n`-element set,
see `Fintype.card_perm`.
## Main declarations
* `Nat.factorial`: The factorial.
* `Nat.ascFactorial`: The ascending factorial. It is the product of natural numbers from `n` to
`n + k - 1`.
* `Nat.descFactorial`: The descending factorial. It is the product of natural numbers from
`n - k + 1` to `n`.
-/
namespace Nat
/-- `Nat.factorial n` is the factorial of `n`. -/
def factorial : ℕ → ℕ
| 0 => 1
| succ n => succ n * factorial n
/-- factorial notation `(n)!` for `Nat.factorial n`.
In Lean, names can end with exclamation marks (e.g. `List.get!`), so you cannot write
`n!` in Lean, but must write `(n)!` or `n !` instead. The former is preferred, since
Lean can confuse the `!` in `n !` as the (prefix) boolean negation operation in some
cases.
For numerals the parentheses are not required, so e.g. `0!` or `1!` work fine.
Todo: replace occurrences of `n !` with `(n)!` in Mathlib. -/
scoped notation:10000 n "!" => Nat.factorial n
section Factorial
variable {m n : ℕ}
@[simp] theorem factorial_zero : 0! = 1 :=
rfl
theorem factorial_succ (n : ℕ) : (n + 1)! = (n + 1) * n ! :=
rfl
@[simp] theorem factorial_one : 1! = 1 :=
rfl
@[simp] theorem factorial_two : 2! = 2 :=
rfl
theorem mul_factorial_pred (hn : n ≠ 0) : n * (n - 1)! = n ! :=
Nat.sub_add_cancel (one_le_iff_ne_zero.mpr hn) ▸ rfl
theorem factorial_pos : ∀ n, 0 < n !
| 0 => Nat.zero_lt_one
| succ n => Nat.mul_pos (succ_pos _) (factorial_pos n)
theorem factorial_ne_zero (n : ℕ) : n ! ≠ 0 :=
ne_of_gt (factorial_pos _)
theorem factorial_dvd_factorial {m n} (h : m ≤ n) : m ! ∣ n ! := by
induction h with
| refl => exact Nat.dvd_refl _
| step _ ih => exact Nat.dvd_trans ih (Nat.dvd_mul_left _ _)
theorem dvd_factorial : ∀ {m n}, 0 < m → m ≤ n → m ∣ n !
| succ _, _, _, h => Nat.dvd_trans (Nat.dvd_mul_right _ _) (factorial_dvd_factorial h)
@[mono, gcongr]
theorem factorial_le {m n} (h : m ≤ n) : m ! ≤ n ! :=
le_of_dvd (factorial_pos _) (factorial_dvd_factorial h)
theorem factorial_mul_pow_le_factorial : ∀ {m n : ℕ}, m ! * (m + 1) ^ n ≤ (m + n)!
| m, 0 => by simp
| m, n + 1 => by
rw [← Nat.add_assoc, factorial_succ, Nat.mul_comm (_ + 1), Nat.pow_succ, ← Nat.mul_assoc]
exact Nat.mul_le_mul factorial_mul_pow_le_factorial (succ_le_succ (le_add_right _ _))
theorem factorial_lt (hn : 0 < n) : n ! < m ! ↔ n < m := by
refine ⟨fun h => not_le.mp fun hmn => Nat.not_le_of_lt h (factorial_le hmn), fun h => ?_⟩
have : ∀ {n}, 0 < n → n ! < (n + 1)! := by
intro k hk
rw [factorial_succ, succ_mul, Nat.lt_add_left_iff_pos]
exact Nat.mul_pos hk k.factorial_pos
induction h generalizing hn with
| refl => exact this hn
| step hnk ih => exact lt_trans (ih hn) <| this <| lt_trans hn <| lt_of_succ_le hnk
@[gcongr]
lemma factorial_lt_of_lt {m n : ℕ} (hn : 0 < n) (h : n < m) : n ! < m ! := (factorial_lt hn).mpr h
@[simp] lemma one_lt_factorial : 1 < n ! ↔ 1 < n := factorial_lt Nat.one_pos
@[simp]
theorem factorial_eq_one : n ! = 1 ↔ n ≤ 1 := by
constructor
· intro h
rw [← not_lt, ← one_lt_factorial, h]
apply lt_irrefl
· rintro (_|_|_) <;> rfl
theorem factorial_inj (hn : 1 < n) : n ! = m ! ↔ n = m := by
refine ⟨fun h => ?_, congr_arg _⟩
obtain hnm | rfl | hnm := lt_trichotomy n m
· rw [← factorial_lt <| lt_of_succ_lt hn, h] at hnm
cases lt_irrefl _ hnm
· rfl
rw [← one_lt_factorial, h, one_lt_factorial] at hn
rw [← factorial_lt <| lt_of_succ_lt hn, h] at hnm
cases lt_irrefl _ hnm
theorem factorial_inj' (h : 1 < n ∨ 1 < m) : n ! = m ! ↔ n = m := by
obtain hn|hm := h
· exact factorial_inj hn
· rw [eq_comm, factorial_inj hm, eq_comm]
theorem self_le_factorial : ∀ n : ℕ, n ≤ n !
| 0 => Nat.zero_le _
| k + 1 => Nat.le_mul_of_pos_right _ (Nat.one_le_of_lt k.factorial_pos)
theorem lt_factorial_self {n : ℕ} (hi : 3 ≤ n) : n < n ! := by
have : 0 < n := by omega
have hn : 1 < pred n := le_pred_of_lt (succ_le_iff.mp hi)
rw [← succ_pred_eq_of_pos ‹0 < n›, factorial_succ]
exact (Nat.lt_mul_iff_one_lt_right (pred n).succ_pos).2
((Nat.lt_of_lt_of_le hn (self_le_factorial _)))
theorem add_factorial_succ_lt_factorial_add_succ {i : ℕ} (n : ℕ) (hi : 2 ≤ i) :
i + (n + 1)! < (i + n + 1)! := by
rw [factorial_succ (i + _), Nat.add_mul, Nat.one_mul]
have := (i + n).self_le_factorial
refine Nat.add_lt_add_of_lt_of_le (Nat.lt_of_le_of_lt ?_ ((Nat.lt_mul_iff_one_lt_right ?_).2 ?_))
(factorial_le ?_) <;> omega
theorem add_factorial_lt_factorial_add {i n : ℕ} (hi : 2 ≤ i) (hn : 1 ≤ n) :
i + n ! < (i + n)! := by
cases hn
· rw [factorial_one]
exact lt_factorial_self (succ_le_succ hi)
exact add_factorial_succ_lt_factorial_add_succ _ hi
theorem add_factorial_succ_le_factorial_add_succ (i : ℕ) (n : ℕ) :
i + (n + 1)! ≤ (i + (n + 1))! := by
cases (le_or_lt (2 : ℕ) i)
· rw [← Nat.add_assoc]
apply Nat.le_of_lt
apply add_factorial_succ_lt_factorial_add_succ
assumption
· match i with
| 0 => simp
| 1 =>
rw [← Nat.add_assoc, factorial_succ (1 + n), Nat.add_mul, Nat.one_mul, Nat.add_comm 1 n,
Nat.add_le_add_iff_right]
exact Nat.mul_pos n.succ_pos n.succ.factorial_pos
| succ (succ n) => contradiction
theorem add_factorial_le_factorial_add (i : ℕ) {n : ℕ} (n1 : 1 ≤ n) : i + n ! ≤ (i + n)! := by
rcases n1 with - | @h
· exact self_le_factorial _
exact add_factorial_succ_le_factorial_add_succ i h
theorem factorial_mul_pow_sub_le_factorial {n m : ℕ} (hnm : n ≤ m) : n ! * n ^ (m - n) ≤ m ! := by
calc
_ ≤ n ! * (n + 1) ^ (m - n) := Nat.mul_le_mul_left _ (Nat.pow_le_pow_left n.le_succ _)
_ ≤ _ := by simpa [hnm] using @Nat.factorial_mul_pow_le_factorial n (m - n)
lemma factorial_le_pow : ∀ n, n ! ≤ n ^ n
| 0 => le_refl _
| n + 1 =>
calc
_ ≤ (n + 1) * n ^ n := Nat.mul_le_mul_left _ n.factorial_le_pow
_ ≤ (n + 1) * (n + 1) ^ n := Nat.mul_le_mul_left _ (Nat.pow_le_pow_left n.le_succ _)
_ = _ := by rw [pow_succ']
end Factorial
/-! ### Ascending and descending factorials -/
section AscFactorial
/-- `n.ascFactorial k = n (n + 1) ⋯ (n + k - 1)`. This is closely related to `ascPochhammer`, but
much less general. -/
def ascFactorial (n : ℕ) : ℕ → ℕ
| 0 => 1
| k + 1 => (n + k) * ascFactorial n k
@[simp]
theorem ascFactorial_zero (n : ℕ) : n.ascFactorial 0 = 1 :=
rfl
theorem ascFactorial_succ {n k : ℕ} : n.ascFactorial k.succ = (n + k) * n.ascFactorial k :=
rfl
theorem zero_ascFactorial : ∀ (k : ℕ), (0 : ℕ).ascFactorial k.succ = 0
| 0 => by
rw [ascFactorial_succ, ascFactorial_zero, Nat.zero_add, Nat.zero_mul]
| (k+1) => by
rw [ascFactorial_succ, zero_ascFactorial k, Nat.mul_zero]
@[simp]
theorem one_ascFactorial : ∀ (k : ℕ), (1 : ℕ).ascFactorial k = k.factorial
| 0 => ascFactorial_zero 1
| (k+1) => by
rw [ascFactorial_succ, one_ascFactorial k, Nat.add_comm, factorial_succ]
theorem succ_ascFactorial (n : ℕ) :
∀ k, n * n.succ.ascFactorial k = (n + k) * n.ascFactorial k
| 0 => by rw [Nat.add_zero, ascFactorial_zero, ascFactorial_zero]
| k + 1 => by rw [ascFactorial, Nat.mul_left_comm, succ_ascFactorial n k, ascFactorial, succ_add,
← Nat.add_assoc]
/-- `(n + 1).ascFactorial k = (n + k) ! / n !` but without ℕ-division. See
`Nat.ascFactorial_eq_div` for the version with ℕ-division. -/
theorem factorial_mul_ascFactorial (n : ℕ) : ∀ k, n ! * (n + 1).ascFactorial k = (n + k)!
| 0 => by rw [ascFactorial_zero, Nat.add_zero, Nat.mul_one]
| k + 1 => by
rw [ascFactorial_succ, ← Nat.add_assoc, factorial_succ, Nat.mul_comm (n + 1 + k),
← Nat.mul_assoc, factorial_mul_ascFactorial n k, Nat.mul_comm, Nat.add_right_comm]
/-- `n.ascFactorial k = (n + k - 1)! / (n - 1)!` for `n > 0` but without ℕ-division. See
`Nat.ascFactorial_eq_div` for the version with ℕ-division. Consider using
`factorial_mul_ascFactorial` to avoid complications of ℕ-subtraction. -/
theorem factorial_mul_ascFactorial' (n k : ℕ) (h : 0 < n) :
(n - 1) ! * n.ascFactorial k = (n + k - 1)! := by
rw [Nat.sub_add_comm h, Nat.sub_one]
nth_rw 2 [Nat.eq_add_of_sub_eq h rfl]
rw [Nat.sub_one, factorial_mul_ascFactorial]
theorem ascFactorial_mul_ascFactorial (n l k : ℕ) :
n.ascFactorial l * (n + l).ascFactorial k = n.ascFactorial (l + k) := by
cases n with
| zero =>
cases l
· simp only [ascFactorial_zero, Nat.add_zero, Nat.one_mul, Nat.zero_add]
· simp only [Nat.add_right_comm, zero_ascFactorial, Nat.zero_add, Nat.zero_mul]
| succ n' =>
apply Nat.mul_left_cancel (factorial_pos n')
simp only [Nat.add_assoc, ← Nat.mul_assoc, factorial_mul_ascFactorial]
rw [Nat.add_comm 1 l, ← Nat.add_assoc, factorial_mul_ascFactorial, Nat.add_assoc]
/-- Avoid in favor of `Nat.factorial_mul_ascFactorial` if you can. ℕ-division isn't worth it. -/
theorem ascFactorial_eq_div (n k : ℕ) : (n + 1).ascFactorial k = (n + k)! / n ! :=
Nat.eq_div_of_mul_eq_right n.factorial_ne_zero (factorial_mul_ascFactorial _ _)
/-- Avoid in favor of `Nat.factorial_mul_ascFactorial'` if you can. ℕ-division isn't worth it. -/
theorem ascFactorial_eq_div' (n k : ℕ) (h : 0 < n) :
n.ascFactorial k = (n + k - 1)! / (n - 1) ! :=
Nat.eq_div_of_mul_eq_right (n - 1).factorial_ne_zero (factorial_mul_ascFactorial' _ _ h)
theorem ascFactorial_of_sub {n k : ℕ} :
(n - k) * (n - k + 1).ascFactorial k = (n - k).ascFactorial (k + 1) := by
rw [succ_ascFactorial, ascFactorial_succ]
theorem pow_succ_le_ascFactorial (n : ℕ) : ∀ k : ℕ, n ^ k ≤ n.ascFactorial k
| 0 => by rw [ascFactorial_zero, Nat.pow_zero]
| k + 1 => by
rw [Nat.pow_succ, Nat.mul_comm, ascFactorial_succ, ← succ_ascFactorial]
exact Nat.mul_le_mul (Nat.le_refl n)
(Nat.le_trans (Nat.pow_le_pow_left (le_succ n) k) (pow_succ_le_ascFactorial n.succ k))
| Mathlib/Data/Nat/Factorial/Basic.lean | 272 | 274 | theorem pow_lt_ascFactorial' (n k : ℕ) : (n + 1) ^ (k + 2) < (n + 1).ascFactorial (k + 2) := by | rw [Nat.pow_succ, ascFactorial, Nat.mul_comm]
exact Nat.mul_lt_mul_of_lt_of_le' (Nat.lt_add_of_pos_right k.succ_pos) |
/-
Copyright (c) 2022 Rémy Degenne, Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Kexing Ying
-/
import Mathlib.MeasureTheory.Function.Egorov
import Mathlib.MeasureTheory.Function.LpSpace.Complete
/-!
# Convergence in measure
We define convergence in measure which is one of the many notions of convergence in probability.
A sequence of functions `f` is said to converge in measure to some function `g`
if for all `ε > 0`, the measure of the set `{x | ε ≤ dist (f i x) (g x)}` tends to 0 as `i`
converges along some given filter `l`.
Convergence in measure is most notably used in the formulation of the weak law of large numbers
and is also useful in theorems such as the Vitali convergence theorem. This file provides some
basic lemmas for working with convergence in measure and establishes some relations between
convergence in measure and other notions of convergence.
## Main definitions
* `MeasureTheory.TendstoInMeasure (μ : Measure α) (f : ι → α → E) (g : α → E)`: `f` converges
in `μ`-measure to `g`.
## Main results
* `MeasureTheory.tendstoInMeasure_of_tendsto_ae`: convergence almost everywhere in a finite
measure space implies convergence in measure.
* `MeasureTheory.TendstoInMeasure.exists_seq_tendsto_ae`: if `f` is a sequence of functions
which converges in measure to `g`, then `f` has a subsequence which convergence almost
everywhere to `g`.
* `MeasureTheory.exists_seq_tendstoInMeasure_atTop_iff`: for a sequence of functions `f`,
convergence in measure is equivalent to the fact that every subsequence has another subsequence
that converges almost surely.
* `MeasureTheory.tendstoInMeasure_of_tendsto_eLpNorm`: convergence in Lp implies convergence
in measure.
-/
open TopologicalSpace Filter
open scoped NNReal ENNReal MeasureTheory Topology
namespace MeasureTheory
variable {α ι κ E : Type*} {m : MeasurableSpace α} {μ : Measure α}
/-- A sequence of functions `f` is said to converge in measure to some function `g` if for all
`ε > 0`, the measure of the set `{x | ε ≤ dist (f i x) (g x)}` tends to 0 as `i` converges along
some given filter `l`. -/
def TendstoInMeasure [Dist E] {_ : MeasurableSpace α} (μ : Measure α) (f : ι → α → E) (l : Filter ι)
(g : α → E) : Prop :=
∀ ε, 0 < ε → Tendsto (fun i => μ { x | ε ≤ dist (f i x) (g x) }) l (𝓝 0)
theorem tendstoInMeasure_iff_norm [SeminormedAddCommGroup E] {l : Filter ι} {f : ι → α → E}
{g : α → E} :
TendstoInMeasure μ f l g ↔
∀ ε, 0 < ε → Tendsto (fun i => μ { x | ε ≤ ‖f i x - g x‖ }) l (𝓝 0) := by
simp_rw [TendstoInMeasure, dist_eq_norm]
theorem tendstoInMeasure_iff_tendsto_toNNReal [Dist E] [IsFiniteMeasure μ]
{f : ι → α → E} {l : Filter ι} {g : α → E} :
TendstoInMeasure μ f l g ↔
∀ ε, 0 < ε → Tendsto (fun i => (μ { x | ε ≤ dist (f i x) (g x) }).toNNReal) l (𝓝 0) := by
have hfin ε i : μ { x | ε ≤ dist (f i x) (g x) } ≠ ⊤ :=
measure_ne_top μ {x | ε ≤ dist (f i x) (g x)}
refine ⟨fun h ε hε ↦ ?_, fun h ε hε ↦ ?_⟩
· have hf : (fun i => (μ { x | ε ≤ dist (f i x) (g x) }).toNNReal) =
ENNReal.toNNReal ∘ (fun i => (μ { x | ε ≤ dist (f i x) (g x) })) := rfl
rw [hf, ENNReal.tendsto_toNNReal_iff' (hfin ε)]
exact h ε hε
· rw [← ENNReal.tendsto_toNNReal_iff ENNReal.zero_ne_top (hfin ε)]
exact h ε hε
lemma TendstoInMeasure.mono [Dist E] {f : ι → α → E} {g : α → E} {u v : Filter ι} (huv : v ≤ u)
(hg : TendstoInMeasure μ f u g) : TendstoInMeasure μ f v g :=
fun ε hε => (hg ε hε).mono_left huv
lemma TendstoInMeasure.comp [Dist E] {f : ι → α → E} {g : α → E} {u : Filter ι}
{v : Filter κ} {ns : κ → ι} (hg : TendstoInMeasure μ f u g) (hns : Tendsto ns v u) :
TendstoInMeasure μ (f ∘ ns) v g := fun ε hε ↦ (hg ε hε).comp hns
namespace TendstoInMeasure
variable [Dist E] {l : Filter ι} {f f' : ι → α → E} {g g' : α → E}
protected theorem congr' (h_left : ∀ᶠ i in l, f i =ᵐ[μ] f' i) (h_right : g =ᵐ[μ] g')
(h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f' l g' := by
intro ε hε
suffices
(fun i => μ { x | ε ≤ dist (f' i x) (g' x) }) =ᶠ[l] fun i => μ { x | ε ≤ dist (f i x) (g x) } by
rw [tendsto_congr' this]
exact h_tendsto ε hε
filter_upwards [h_left] with i h_ae_eq
refine measure_congr ?_
filter_upwards [h_ae_eq, h_right] with x hxf hxg
rw [eq_iff_iff]
change ε ≤ dist (f' i x) (g' x) ↔ ε ≤ dist (f i x) (g x)
rw [hxg, hxf]
protected theorem congr (h_left : ∀ i, f i =ᵐ[μ] f' i) (h_right : g =ᵐ[μ] g')
(h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f' l g' :=
TendstoInMeasure.congr' (Eventually.of_forall h_left) h_right h_tendsto
theorem congr_left (h : ∀ i, f i =ᵐ[μ] f' i) (h_tendsto : TendstoInMeasure μ f l g) :
TendstoInMeasure μ f' l g :=
h_tendsto.congr h EventuallyEq.rfl
theorem congr_right (h : g =ᵐ[μ] g') (h_tendsto : TendstoInMeasure μ f l g) :
TendstoInMeasure μ f l g' :=
h_tendsto.congr (fun _ => EventuallyEq.rfl) h
end TendstoInMeasure
section ExistsSeqTendstoAe
variable [MetricSpace E]
variable {f : ℕ → α → E} {g : α → E}
/-- Auxiliary lemma for `tendstoInMeasure_of_tendsto_ae`. -/
theorem tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable [IsFiniteMeasure μ]
(hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g)
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : TendstoInMeasure μ f atTop g := by
refine fun ε hε => ENNReal.tendsto_atTop_zero.mpr fun δ hδ => ?_
by_cases hδi : δ = ∞
· simp only [hδi, imp_true_iff, le_top, exists_const]
lift δ to ℝ≥0 using hδi
rw [gt_iff_lt, ENNReal.coe_pos, ← NNReal.coe_pos] at hδ
obtain ⟨t, _, ht, hunif⟩ := tendstoUniformlyOn_of_ae_tendsto' hf hg hfg hδ
rw [ENNReal.ofReal_coe_nnreal] at ht
rw [Metric.tendstoUniformlyOn_iff] at hunif
obtain ⟨N, hN⟩ := eventually_atTop.1 (hunif ε hε)
refine ⟨N, fun n hn => ?_⟩
suffices { x : α | ε ≤ dist (f n x) (g x) } ⊆ t from (measure_mono this).trans ht
rw [← Set.compl_subset_compl]
intro x hx
rw [Set.mem_compl_iff, Set.nmem_setOf_iff, dist_comm, not_le]
exact hN n hn x hx
/-- Convergence a.e. implies convergence in measure in a finite measure space. -/
| Mathlib/MeasureTheory/Function/ConvergenceInMeasure.lean | 143 | 147 | theorem tendstoInMeasure_of_tendsto_ae [IsFiniteMeasure μ] (hf : ∀ n, AEStronglyMeasurable (f n) μ)
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : TendstoInMeasure μ f atTop g := by | have hg : AEStronglyMeasurable g μ := aestronglyMeasurable_of_tendsto_ae _ hf hfg
refine TendstoInMeasure.congr (fun i => (hf i).ae_eq_mk.symm) hg.ae_eq_mk.symm ?_
refine tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable |
/-
Copyright (c) 2022 Vincent Beffara. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Vincent Beffara, Stefan Kebekus
-/
import Mathlib.Analysis.Analytic.Constructions
import Mathlib.Analysis.Calculus.DSlope
import Mathlib.Analysis.Calculus.FDeriv.Analytic
import Mathlib.Analysis.Analytic.Uniqueness
import Mathlib.Order.Filter.EventuallyConst
import Mathlib.Topology.Perfect
/-!
# Principle of isolated zeros
This file proves the fact that the zeros of a non-constant analytic function of one variable are
isolated. It also introduces a little bit of API in the `HasFPowerSeriesAt` namespace that is useful
in this setup.
## Main results
* `AnalyticAt.eventually_eq_zero_or_eventually_ne_zero` is the main statement that if a function is
analytic at `z₀`, then either it is identically zero in a neighborhood of `z₀`, or it does not
vanish in a punctured neighborhood of `z₀`.
* `AnalyticOnNhd.eqOn_of_preconnected_of_frequently_eq` is the identity theorem for analytic
functions: if a function `f` is analytic on a connected set `U` and is zero on a set with an
accumulation point in `U` then `f` is identically `0` on `U`.
## Applications
* Vanishing of products of analytic functions, `eq_zero_or_eq_zero_of_smul_eq_zero`: If `f, g` are
analytic on a neighbourhood of the preconnected open set `U`, and `f • g = 0` on `U`, then either
`f = 0` on `U` or `g = 0` on `U`.
* Preimages of codiscrete sets, `AnalyticOnNhd.preimage_mem_codiscreteWithin`: if `f` is analytic
on a neighbourhood of `U` and not locally constant, then the preimage of any subset codiscrete
within `f '' U` is codiscrete within `U`.
-/
open Filter Function Nat FormalMultilinearSeries EMetric Set
open scoped Topology
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {s : E} {p q : FormalMultilinearSeries 𝕜 𝕜 E} {f g : 𝕜 → E} {n : ℕ} {z z₀ : 𝕜}
namespace HasSum
variable {a : ℕ → E}
theorem hasSum_at_zero (a : ℕ → E) : HasSum (fun n => (0 : 𝕜) ^ n • a n) (a 0) := by
convert hasSum_single (α := E) 0 fun b h ↦ _ <;> simp [*]
theorem exists_hasSum_smul_of_apply_eq_zero (hs : HasSum (fun m => z ^ m • a m) s)
(ha : ∀ k < n, a k = 0) : ∃ t : E, z ^ n • t = s ∧ HasSum (fun m => z ^ m • a (m + n)) t := by
obtain rfl | hn := n.eq_zero_or_pos
· simpa
by_cases h : z = 0
· have : s = 0 := hs.unique (by simpa [ha 0 hn, h] using hasSum_at_zero a)
exact ⟨a n, by simp [h, hn.ne', this], by simpa [h] using hasSum_at_zero fun m => a (m + n)⟩
· refine ⟨(z ^ n)⁻¹ • s, by field_simp [smul_smul], ?_⟩
have h1 : ∑ i ∈ Finset.range n, z ^ i • a i = 0 :=
Finset.sum_eq_zero fun k hk => by simp [ha k (Finset.mem_range.mp hk)]
have h2 : HasSum (fun m => z ^ (m + n) • a (m + n)) s := by
simpa [h1] using (hasSum_nat_add_iff' n).mpr hs
convert h2.const_smul (z⁻¹ ^ n) using 1
· field_simp [pow_add, smul_smul]
· simp only [inv_pow]
end HasSum
namespace HasFPowerSeriesAt
theorem has_fpower_series_dslope_fslope (hp : HasFPowerSeriesAt f p z₀) :
HasFPowerSeriesAt (dslope f z₀) p.fslope z₀ := by
have hpd : deriv f z₀ = p.coeff 1 := hp.deriv
have hp0 : p.coeff 0 = f z₀ := hp.coeff_zero 1
simp only [hasFPowerSeriesAt_iff, apply_eq_pow_smul_coeff, coeff_fslope] at hp ⊢
refine hp.mono fun x hx => ?_
by_cases h : x = 0
· convert hasSum_single (α := E) 0 _ <;> intros <;> simp [*]
· have hxx : ∀ n : ℕ, x⁻¹ * x ^ (n + 1) = x ^ n := fun n => by field_simp [h, _root_.pow_succ]
suffices HasSum (fun n => x⁻¹ • x ^ (n + 1) • p.coeff (n + 1)) (x⁻¹ • (f (z₀ + x) - f z₀)) by
simpa [dslope, slope, h, smul_smul, hxx] using this
simpa [hp0] using ((hasSum_nat_add_iff' 1).mpr hx).const_smul x⁻¹
theorem has_fpower_series_iterate_dslope_fslope (n : ℕ) (hp : HasFPowerSeriesAt f p z₀) :
HasFPowerSeriesAt ((swap dslope z₀)^[n] f) (fslope^[n] p) z₀ := by
induction n generalizing f p with
| zero => exact hp
| succ n ih => simpa using ih (has_fpower_series_dslope_fslope hp)
theorem iterate_dslope_fslope_ne_zero (hp : HasFPowerSeriesAt f p z₀) (h : p ≠ 0) :
(swap dslope z₀)^[p.order] f z₀ ≠ 0 := by
rw [← coeff_zero (has_fpower_series_iterate_dslope_fslope p.order hp) 1]
simpa [coeff_eq_zero] using apply_order_ne_zero h
theorem eq_pow_order_mul_iterate_dslope (hp : HasFPowerSeriesAt f p z₀) :
∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ p.order • (swap dslope z₀)^[p.order] f z := by
have hq := hasFPowerSeriesAt_iff'.mp (has_fpower_series_iterate_dslope_fslope p.order hp)
filter_upwards [hq, hasFPowerSeriesAt_iff'.mp hp] with x hx1 hx2
have : ∀ k < p.order, p.coeff k = 0 := fun k hk => by
simpa [coeff_eq_zero] using apply_eq_zero_of_lt_order hk
obtain ⟨s, hs1, hs2⟩ := HasSum.exists_hasSum_smul_of_apply_eq_zero hx2 this
convert hs1.symm
simp only [coeff_iterate_fslope] at hx1
exact hx1.unique hs2
| Mathlib/Analysis/Analytic/IsolatedZeros.lean | 108 | 113 | theorem locally_ne_zero (hp : HasFPowerSeriesAt f p z₀) (h : p ≠ 0) : ∀ᶠ z in 𝓝[≠] z₀, f z ≠ 0 := by | rw [eventually_nhdsWithin_iff]
have h2 := (has_fpower_series_iterate_dslope_fslope p.order hp).continuousAt
have h3 := h2.eventually_ne (iterate_dslope_fslope_ne_zero hp h)
filter_upwards [eq_pow_order_mul_iterate_dslope hp, h3] with z e1 e2 e3
simpa [e1, e2, e3] using pow_ne_zero p.order (sub_ne_zero.mpr e3) |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.OuterMeasure.Operations
import Mathlib.Analysis.SpecificLimits.Basic
/-!
# Outer measures from functions
Given an arbitrary function `m : Set α → ℝ≥0∞` that sends `∅` to `0` we can define an outer
measure on `α` that on `s` is defined to be the infimum of `∑ᵢ, m (sᵢ)` for all collections of sets
`sᵢ` that cover `s`. This is the unique maximal outer measure that is at most the given function.
Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that
for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space.
## Main definitions and statements
* `OuterMeasure.boundedBy` is the greatest outer measure that is at most the given function.
If you know that the given function sends `∅` to `0`, then `OuterMeasure.ofFunction` is a
special case.
* `sInf_eq_boundedBy_sInfGen` is a characterization of the infimum of outer measures.
## References
* <https://en.wikipedia.org/wiki/Outer_measure>
* <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion>
## Tags
outer measure, Carathéodory-measurable, Carathéodory's criterion
-/
assert_not_exists Basis
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
namespace OuterMeasure
section OfFunction
variable {α : Type*}
/-- Given any function `m` assigning measures to sets satisfying `m ∅ = 0`, there is
a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : Set α`. -/
protected def ofFunction (m : Set α → ℝ≥0∞) (m_empty : m ∅ = 0) : OuterMeasure α :=
let μ s := ⨅ (f : ℕ → Set α) (_ : s ⊆ ⋃ i, f i), ∑' i, m (f i)
{ measureOf := μ
empty :=
le_antisymm
((iInf_le_of_le fun _ => ∅) <| iInf_le_of_le (empty_subset _) <| by simp [m_empty])
(zero_le _)
mono := fun {_ _} hs => iInf_mono fun _ => iInf_mono' fun hb => ⟨hs.trans hb, le_rfl⟩
iUnion_nat := fun s _ =>
ENNReal.le_of_forall_pos_le_add <| by
intro ε hε (hb : (∑' i, μ (s i)) < ∞)
rcases ENNReal.exists_pos_sum_of_countable (ENNReal.coe_pos.2 hε).ne' ℕ with ⟨ε', hε', hl⟩
refine le_trans ?_ (add_le_add_left (le_of_lt hl) _)
rw [← ENNReal.tsum_add]
choose f hf using
show ∀ i, ∃ f : ℕ → Set α, (s i ⊆ ⋃ i, f i) ∧ (∑' i, m (f i)) < μ (s i) + ε' i by
intro i
have : μ (s i) < μ (s i) + ε' i :=
ENNReal.lt_add_right (ne_top_of_le_ne_top hb.ne <| ENNReal.le_tsum _)
(by simpa using (hε' i).ne')
rcases iInf_lt_iff.mp this with ⟨t, ht⟩
exists t
contrapose! ht
exact le_iInf ht
refine le_trans ?_ (ENNReal.tsum_le_tsum fun i => le_of_lt (hf i).2)
rw [← ENNReal.tsum_prod, ← Nat.pairEquiv.symm.tsum_eq]
refine iInf_le_of_le _ (iInf_le _ ?_)
apply iUnion_subset
intro i
apply Subset.trans (hf i).1
apply iUnion_subset
simp only [Nat.pairEquiv_symm_apply]
rw [iUnion_unpair]
intro j
apply subset_iUnion₂ i }
variable (m : Set α → ℝ≥0∞) (m_empty : m ∅ = 0)
/-- `ofFunction` of a set `s` is the infimum of `∑ᵢ, m (tᵢ)` for all collections of sets
`tᵢ` that cover `s`. -/
theorem ofFunction_apply (s : Set α) :
OuterMeasure.ofFunction m m_empty s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, m (t n) :=
rfl
/-- `ofFunction` of a set `s` is the infimum of `∑ᵢ, m (tᵢ)` for all collections of sets
`tᵢ` that cover `s`, with all `tᵢ` satisfying a predicate `P` such that `m` is infinite for sets
that don't satisfy `P`.
This is similar to `ofFunction_apply`, except that the sets `tᵢ` satisfy `P`.
The hypothesis `m_top` applies in particular to a function of the form `extend m'`. -/
theorem ofFunction_eq_iInf_mem {P : Set α → Prop} (m_top : ∀ s, ¬ P s → m s = ∞) (s : Set α) :
OuterMeasure.ofFunction m m_empty s =
⨅ (t : ℕ → Set α) (_ : ∀ i, P (t i)) (_ : s ⊆ ⋃ i, t i), ∑' i, m (t i) := by
rw [OuterMeasure.ofFunction_apply]
apply le_antisymm
· exact le_iInf fun t ↦ le_iInf fun _ ↦ le_iInf fun h ↦ iInf₂_le _ (by exact h)
· simp_rw [le_iInf_iff]
refine fun t ht_subset ↦ iInf_le_of_le t ?_
by_cases ht : ∀ i, P (t i)
· exact iInf_le_of_le ht (iInf_le_of_le ht_subset le_rfl)
· simp only [ht, not_false_eq_true, iInf_neg, top_le_iff]
push_neg at ht
obtain ⟨i, hti_not_mem⟩ := ht
have hfi_top : m (t i) = ∞ := m_top _ hti_not_mem
exact ENNReal.tsum_eq_top_of_eq_top ⟨i, hfi_top⟩
variable {m m_empty}
theorem ofFunction_le (s : Set α) : OuterMeasure.ofFunction m m_empty s ≤ m s :=
let f : ℕ → Set α := fun i => Nat.casesOn i s fun _ => ∅
iInf_le_of_le f <|
iInf_le_of_le (subset_iUnion f 0) <|
le_of_eq <| tsum_eq_single 0 <| by
rintro (_ | i)
· simp
· simp [f, m_empty]
theorem ofFunction_eq (s : Set α) (m_mono : ∀ ⦃t : Set α⦄, s ⊆ t → m s ≤ m t)
(m_subadd : ∀ s : ℕ → Set α, m (⋃ i, s i) ≤ ∑' i, m (s i)) :
OuterMeasure.ofFunction m m_empty s = m s :=
le_antisymm (ofFunction_le s) <|
le_iInf fun f => le_iInf fun hf => le_trans (m_mono hf) (m_subadd f)
theorem le_ofFunction {μ : OuterMeasure α} :
μ ≤ OuterMeasure.ofFunction m m_empty ↔ ∀ s, μ s ≤ m s :=
⟨fun H s => le_trans (H s) (ofFunction_le s), fun H _ =>
le_iInf fun f =>
le_iInf fun hs =>
le_trans (μ.mono hs) <| le_trans (measure_iUnion_le f) <| ENNReal.tsum_le_tsum fun _ => H _⟩
theorem isGreatest_ofFunction :
IsGreatest { μ : OuterMeasure α | ∀ s, μ s ≤ m s } (OuterMeasure.ofFunction m m_empty) :=
⟨fun _ => ofFunction_le _, fun _ => le_ofFunction.2⟩
theorem ofFunction_eq_sSup : OuterMeasure.ofFunction m m_empty = sSup { μ | ∀ s, μ s ≤ m s } :=
(@isGreatest_ofFunction α m m_empty).isLUB.sSup_eq.symm
/-- If `m u = ∞` for any set `u` that has nonempty intersection both with `s` and `t`, then
`μ (s ∪ t) = μ s + μ t`, where `μ = MeasureTheory.OuterMeasure.ofFunction m m_empty`.
E.g., if `α` is an (e)metric space and `m u = ∞` on any set of diameter `≥ r`, then this lemma
implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s`
and `y ∈ t`. -/
theorem ofFunction_union_of_top_of_nonempty_inter {s t : Set α}
(h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → m u = ∞) :
OuterMeasure.ofFunction m m_empty (s ∪ t) =
OuterMeasure.ofFunction m m_empty s + OuterMeasure.ofFunction m m_empty t := by
refine le_antisymm (measure_union_le _ _) (le_iInf₂ fun f hf ↦ ?_)
set μ := OuterMeasure.ofFunction m m_empty
rcases Classical.em (∃ i, (s ∩ f i).Nonempty ∧ (t ∩ f i).Nonempty) with (⟨i, hs, ht⟩ | he)
· calc
μ s + μ t ≤ ∞ := le_top
_ = m (f i) := (h (f i) hs ht).symm
_ ≤ ∑' i, m (f i) := ENNReal.le_tsum i
set I := fun s => { i : ℕ | (s ∩ f i).Nonempty }
have hd : Disjoint (I s) (I t) := disjoint_iff_inf_le.mpr fun i hi => he ⟨i, hi⟩
have hI : ∀ u ⊆ s ∪ t, μ u ≤ ∑' i : I u, μ (f i) := fun u hu =>
calc
μ u ≤ μ (⋃ i : I u, f i) :=
μ.mono fun x hx =>
let ⟨i, hi⟩ := mem_iUnion.1 (hf (hu hx))
mem_iUnion.2 ⟨⟨i, ⟨x, hx, hi⟩⟩, hi⟩
_ ≤ ∑' i : I u, μ (f i) := measure_iUnion_le _
calc
μ s + μ t ≤ (∑' i : I s, μ (f i)) + ∑' i : I t, μ (f i) :=
add_le_add (hI _ subset_union_left) (hI _ subset_union_right)
_ = ∑' i : ↑(I s ∪ I t), μ (f i) :=
(ENNReal.summable.tsum_union_disjoint (f := fun i => μ (f i)) hd ENNReal.summable).symm
_ ≤ ∑' i, μ (f i) :=
(ENNReal.summable.tsum_le_tsum_of_inj (↑) Subtype.coe_injective (fun _ _ => zero_le _)
(fun _ => le_rfl) ENNReal.summable)
_ ≤ ∑' i, m (f i) := ENNReal.tsum_le_tsum fun i => ofFunction_le _
theorem comap_ofFunction {β} (f : β → α) (h : Monotone m ∨ Surjective f) :
comap f (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun s => m (f '' s)) (by simp; simp [m_empty]) := by
refine le_antisymm (le_ofFunction.2 fun s => ?_) fun s => ?_
· rw [comap_apply]
apply ofFunction_le
· rw [comap_apply, ofFunction_apply, ofFunction_apply]
refine iInf_mono' fun t => ⟨fun k => f ⁻¹' t k, ?_⟩
refine iInf_mono' fun ht => ?_
rw [Set.image_subset_iff, preimage_iUnion] at ht
refine ⟨ht, ENNReal.tsum_le_tsum fun n => ?_⟩
rcases h with hl | hr
exacts [hl (image_preimage_subset _ _), (congr_arg m (hr.image_preimage (t n))).le]
theorem map_ofFunction_le {β} (f : α → β) :
map f (OuterMeasure.ofFunction m m_empty) ≤
OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty :=
le_ofFunction.2 fun s => by
rw [map_apply]
apply ofFunction_le
theorem map_ofFunction {β} {f : α → β} (hf : Injective f) :
map f (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty := by
refine (map_ofFunction_le _).antisymm fun s => ?_
simp only [ofFunction_apply, map_apply, le_iInf_iff]
intro t ht
refine iInf_le_of_le (fun n => (range f)ᶜ ∪ f '' t n) (iInf_le_of_le ?_ ?_)
· rw [← union_iUnion, ← inter_subset, ← image_preimage_eq_inter_range, ← image_iUnion]
exact image_subset _ ht
· refine ENNReal.tsum_le_tsum fun n => le_of_eq ?_
simp [hf.preimage_image]
-- TODO (kmill): change `m (t ∩ s)` to `m (s ∩ t)`
theorem restrict_ofFunction (s : Set α) (hm : Monotone m) :
restrict s (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun t => m (t ∩ s)) (by simp; simp [m_empty]) := by
rw [restrict]
simp only [inter_comm _ s, LinearMap.comp_apply]
rw [comap_ofFunction _ (Or.inl hm)]
simp only [map_ofFunction Subtype.coe_injective, Subtype.image_preimage_coe]
theorem smul_ofFunction {c : ℝ≥0∞} (hc : c ≠ ∞) : c • OuterMeasure.ofFunction m m_empty =
OuterMeasure.ofFunction (c • m) (by simp [m_empty]) := by
ext1 s
haveI : Nonempty { t : ℕ → Set α // s ⊆ ⋃ i, t i } := ⟨⟨fun _ => s, subset_iUnion (fun _ => s) 0⟩⟩
simp only [smul_apply, ofFunction_apply, ENNReal.tsum_mul_left, Pi.smul_apply, smul_eq_mul,
iInf_subtype']
rw [ENNReal.mul_iInf fun h => (hc h).elim]
end OfFunction
section BoundedBy
variable {α : Type*} (m : Set α → ℝ≥0∞)
/-- Given any function `m` assigning measures to sets, there is a unique maximal outer measure `μ`
satisfying `μ s ≤ m s` for all `s : Set α`. This is the same as `OuterMeasure.ofFunction`,
except that it doesn't require `m ∅ = 0`. -/
def boundedBy : OuterMeasure α :=
OuterMeasure.ofFunction (fun s => ⨆ _ : s.Nonempty, m s) (by simp [Set.not_nonempty_empty])
variable {m}
theorem boundedBy_le (s : Set α) : boundedBy m s ≤ m s :=
(ofFunction_le _).trans iSup_const_le
| Mathlib/MeasureTheory/OuterMeasure/OfFunction.lean | 254 | 257 | theorem boundedBy_eq_ofFunction (m_empty : m ∅ = 0) (s : Set α) :
boundedBy m s = OuterMeasure.ofFunction m m_empty s := by | have : (fun s : Set α => ⨆ _ : s.Nonempty, m s) = m := by
ext1 t |
/-
Copyright (c) 2024 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.Algebra.Module.Submodule.Ker
/-!
# Iterate maps and comaps of submodules
Some preliminary work for establishing the strong rank condition for noetherian rings.
Given two linear maps `f i : N →ₗ[R] M` and a submodule `K : Submodule R N`, we can define
`LinearMap.iterateMapComap f i n K : Submodule R N` to be `f⁻¹(i(⋯(f⁻¹(i(K)))))` (`n` times).
If `f(K) ≤ i(K)`, then this sequence is non-decreasing (`LinearMap.iterateMapComap_le_succ`).
On the other hand, if `f` is surjective, `i` is injective, and there exists some `m` such that
`LinearMap.iterateMapComap f i m K = LinearMap.iterateMapComap f i (m + 1) K`,
then for any `n`,
`LinearMap.iterateMapComap f i n K = LinearMap.iterateMapComap f i (n + 1) K`.
In particular, by taking `n = 0`, the kernel of `f` is contained in `K`
(`LinearMap.ker_le_of_iterateMapComap_eq_succ`),
which is a consequence of `LinearMap.ker_le_comap`.
As a special case, if one can take `K` to be zero,
then `f` is injective. This is the key result for establishing the strong rank condition
for noetherian rings.
The construction here is adapted from the proof in Djoković's paper
*Epimorphisms of modules which must be isomorphisms* [djokovic1973].
-/
open Function Submodule
namespace LinearMap
variable {R N M : Type*} [Semiring R] [AddCommMonoid N] [Module R N]
[AddCommMonoid M] [Module R M] (f i : N →ₗ[R] M)
/-- The `LinearMap.iterateMapComap f i n K : Submodule R N` is
`f⁻¹(i(⋯(f⁻¹(i(K)))))` (`n` times). -/
def iterateMapComap (n : ℕ) := (fun K : Submodule R N ↦ (K.map i).comap f)^[n]
/-- If `f(K) ≤ i(K)`, then `LinearMap.iterateMapComap` is not decreasing. -/
theorem iterateMapComap_le_succ (K : Submodule R N) (h : K.map f ≤ K.map i) (n : ℕ) :
f.iterateMapComap i n K ≤ f.iterateMapComap i (n + 1) K := by
nth_rw 2 [iterateMapComap]
rw [iterate_succ', Function.comp_apply, ← iterateMapComap, ← map_le_iff_le_comap]
induction n with
| zero => exact h
| succ n ih =>
simp_rw [iterateMapComap, iterate_succ', Function.comp_apply]
calc
_ ≤ (f.iterateMapComap i n K).map i := map_comap_le _ _
_ ≤ (((f.iterateMapComap i n K).map f).comap f).map i := map_mono (le_comap_map _ _)
_ ≤ _ := map_mono (comap_mono ih)
/-- If `f` is surjective, `i` is injective, and there exists some `m` such that
`LinearMap.iterateMapComap f i m K = LinearMap.iterateMapComap f i (m + 1) K`,
then for any `n`,
`LinearMap.iterateMapComap f i n K = LinearMap.iterateMapComap f i (n + 1) K`.
In particular, by taking `n = 0`, the kernel of `f` is contained in `K`
(`LinearMap.ker_le_of_iterateMapComap_eq_succ`),
which is a consequence of `LinearMap.ker_le_comap`. -/
theorem iterateMapComap_eq_succ (K : Submodule R N)
(m : ℕ) (heq : f.iterateMapComap i m K = f.iterateMapComap i (m + 1) K)
(hf : Surjective f) (hi : Injective i) (n : ℕ) :
f.iterateMapComap i n K = f.iterateMapComap i (n + 1) K := by
induction n with
| zero =>
contrapose! heq
induction m with
| zero => exact heq
| succ m ih =>
rw [iterateMapComap, iterateMapComap, iterate_succ', iterate_succ']
exact fun H ↦ ih (map_injective_of_injective hi (comap_injective_of_surjective hf H))
| succ n ih =>
rw [iterateMapComap, iterateMapComap, iterate_succ', iterate_succ',
Function.comp_apply, Function.comp_apply, ← iterateMapComap, ← iterateMapComap, ih]
/-- If `f` is surjective, `i` is injective, and there exists some `m` such that
`LinearMap.iterateMapComap f i m K = LinearMap.iterateMapComap f i (m + 1) K`,
then the kernel of `f` is contained in `K`.
This is a corollary of `LinearMap.iterateMapComap_eq_succ` and `LinearMap.ker_le_comap`.
As a special case, if one can take `K` to be zero,
then `f` is injective. This is the key result for establishing the strong rank condition
for noetherian rings. -/
| Mathlib/Algebra/Module/Submodule/IterateMapComap.lean | 88 | 92 | theorem ker_le_of_iterateMapComap_eq_succ (K : Submodule R N)
(m : ℕ) (heq : f.iterateMapComap i m K = f.iterateMapComap i (m + 1) K)
(hf : Surjective f) (hi : Injective i) : LinearMap.ker f ≤ K := by | rw [show K = _ from f.iterateMapComap_eq_succ i K m heq hf hi 0]
exact f.ker_le_comap |
/-
Copyright (c) 2024 Mitchell Lee. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mitchell Lee
-/
import Mathlib.Data.ZMod.Basic
import Mathlib.GroupTheory.Coxeter.Basic
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Zify
/-!
# The length function, reduced words, and descents
Throughout this file, `B` is a type and `M : CoxeterMatrix B` is a Coxeter matrix.
`cs : CoxeterSystem M W` is a Coxeter system; that is, `W` is a group, and `cs` holds the data
of a group isomorphism `W ≃* M.group`, where `M.group` refers to the quotient of the free group on
`B` by the Coxeter relations given by the matrix `M`. See `Mathlib/GroupTheory/Coxeter/Basic.lean`
for more details.
Given any element $w \in W$, its *length* (`CoxeterSystem.length`), denoted $\ell(w)$, is the
minimum number $\ell$ such that $w$ can be written as a product of a sequence of $\ell$ simple
reflections:
$$w = s_{i_1} \cdots s_{i_\ell}.$$
We prove for all $w_1, w_2 \in W$ that $\ell (w_1 w_2) \leq \ell (w_1) + \ell (w_2)$
and that $\ell (w_1 w_2)$ has the same parity as $\ell (w_1) + \ell (w_2)$.
We define a *reduced word* (`CoxeterSystem.IsReduced`) for an element $w \in W$ to be a way of
writing $w$ as a product of exactly $\ell(w)$ simple reflections. Every element of $W$ has a reduced
word.
We say that $i \in B$ is a *left descent* (`CoxeterSystem.IsLeftDescent`) of $w \in W$ if
$\ell(s_i w) < \ell(w)$. We show that if $i$ is a left descent of $w$, then
$\ell(s_i w) + 1 = \ell(w)$. On the other hand, if $i$ is not a left descent of $w$, then
$\ell(s_i w) = \ell(w) + 1$. We similarly define right descents (`CoxeterSystem.IsRightDescent`) and
prove analogous results.
## Main definitions
* `cs.length`
* `cs.IsReduced`
* `cs.IsLeftDescent`
* `cs.IsRightDescent`
## References
* [A. Björner and F. Brenti, *Combinatorics of Coxeter Groups*](bjorner2005)
-/
assert_not_exists TwoSidedIdeal
namespace CoxeterSystem
open List Matrix Function
variable {B : Type*}
variable {W : Type*} [Group W]
variable {M : CoxeterMatrix B} (cs : CoxeterSystem M W)
local prefix:100 "s" => cs.simple
local prefix:100 "π" => cs.wordProd
/-! ### Length -/
private theorem exists_word_with_prod (w : W) : ∃ n ω, ω.length = n ∧ π ω = w := by
rcases cs.wordProd_surjective w with ⟨ω, rfl⟩
use ω.length, ω
open scoped Classical in
/-- The length of `w`; i.e., the minimum number of simple reflections that
must be multiplied to form `w`. -/
noncomputable def length (w : W) : ℕ := Nat.find (cs.exists_word_with_prod w)
local prefix:100 "ℓ" => cs.length
theorem exists_reduced_word (w : W) : ∃ ω, ω.length = ℓ w ∧ w = π ω := by
classical
have := Nat.find_spec (cs.exists_word_with_prod w)
tauto
open scoped Classical in
theorem length_wordProd_le (ω : List B) : ℓ (π ω) ≤ ω.length :=
Nat.find_min' (cs.exists_word_with_prod (π ω)) ⟨ω, by tauto⟩
@[simp] theorem length_one : ℓ (1 : W) = 0 := Nat.eq_zero_of_le_zero (cs.length_wordProd_le [])
@[simp]
theorem length_eq_zero_iff {w : W} : ℓ w = 0 ↔ w = 1 := by
constructor
· intro h
rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
have : ω = [] := eq_nil_of_length_eq_zero (hω.trans h)
rw [this, wordProd_nil]
· rintro rfl
exact cs.length_one
@[simp]
theorem length_inv (w : W) : ℓ (w⁻¹) = ℓ w := by
apply Nat.le_antisymm
· rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
have := cs.length_wordProd_le (List.reverse ω)
rwa [wordProd_reverse, length_reverse, hω] at this
· rcases cs.exists_reduced_word w⁻¹ with ⟨ω, hω, h'ω⟩
have := cs.length_wordProd_le (List.reverse ω)
rwa [wordProd_reverse, length_reverse, ← h'ω, hω, inv_inv] at this
theorem length_mul_le (w₁ w₂ : W) :
ℓ (w₁ * w₂) ≤ ℓ w₁ + ℓ w₂ := by
rcases cs.exists_reduced_word w₁ with ⟨ω₁, hω₁, rfl⟩
rcases cs.exists_reduced_word w₂ with ⟨ω₂, hω₂, rfl⟩
have := cs.length_wordProd_le (ω₁ ++ ω₂)
simpa [hω₁, hω₂, wordProd_append] using this
theorem length_mul_ge_length_sub_length (w₁ w₂ : W) :
ℓ w₁ - ℓ w₂ ≤ ℓ (w₁ * w₂) := by
simpa [Nat.sub_le_of_le_add] using cs.length_mul_le (w₁ * w₂) w₂⁻¹
theorem length_mul_ge_length_sub_length' (w₁ w₂ : W) :
ℓ w₂ - ℓ w₁ ≤ ℓ (w₁ * w₂) := by
simpa [Nat.sub_le_of_le_add, add_comm] using cs.length_mul_le w₁⁻¹ (w₁ * w₂)
theorem length_mul_ge_max (w₁ w₂ : W) :
max (ℓ w₁ - ℓ w₂) (ℓ w₂ - ℓ w₁) ≤ ℓ (w₁ * w₂) :=
max_le_iff.mpr ⟨length_mul_ge_length_sub_length _ _ _, length_mul_ge_length_sub_length' _ _ _⟩
/-- The homomorphism that sends each element `w : W` to the parity of the length of `w`.
(See `lengthParity_eq_ofAdd_length`.) -/
def lengthParity : W →* Multiplicative (ZMod 2) := cs.lift ⟨fun _ ↦ Multiplicative.ofAdd 1, by
simp_rw [CoxeterMatrix.IsLiftable, ← ofAdd_add, (by decide : (1 + 1 : ZMod 2) = 0)]
simp⟩
theorem lengthParity_simple (i : B) :
cs.lengthParity (s i) = Multiplicative.ofAdd 1 := cs.lift_apply_simple _ _
theorem lengthParity_comp_simple :
cs.lengthParity ∘ cs.simple = fun _ ↦ Multiplicative.ofAdd 1 := funext cs.lengthParity_simple
theorem lengthParity_eq_ofAdd_length (w : W) :
cs.lengthParity w = Multiplicative.ofAdd (↑(ℓ w)) := by
rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
rw [← hω, wordProd, map_list_prod, List.map_map, lengthParity_comp_simple, map_const',
prod_replicate, ← ofAdd_nsmul, nsmul_one]
theorem length_mul_mod_two (w₁ w₂ : W) : ℓ (w₁ * w₂) % 2 = (ℓ w₁ + ℓ w₂) % 2 := by
rw [← ZMod.natCast_eq_natCast_iff', Nat.cast_add]
simpa only [lengthParity_eq_ofAdd_length, ofAdd_add] using map_mul cs.lengthParity w₁ w₂
@[simp]
theorem length_simple (i : B) : ℓ (s i) = 1 := by
apply Nat.le_antisymm
· simpa using cs.length_wordProd_le [i]
· by_contra! length_lt_one
have : cs.lengthParity (s i) = Multiplicative.ofAdd 0 := by
rw [lengthParity_eq_ofAdd_length, Nat.lt_one_iff.mp length_lt_one, Nat.cast_zero]
have : Multiplicative.ofAdd (0 : ZMod 2) = Multiplicative.ofAdd 1 :=
this.symm.trans (cs.lengthParity_simple i)
contradiction
theorem length_eq_one_iff {w : W} : ℓ w = 1 ↔ ∃ i : B, w = s i := by
constructor
· intro h
rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
rcases List.length_eq_one_iff.mp (hω.trans h) with ⟨i, rfl⟩
exact ⟨i, cs.wordProd_singleton i⟩
· rintro ⟨i, rfl⟩
exact cs.length_simple i
theorem length_mul_simple_ne (w : W) (i : B) : ℓ (w * s i) ≠ ℓ w := by
intro eq
have length_mod_two := cs.length_mul_mod_two w (s i)
rw [eq, length_simple] at length_mod_two
rcases Nat.mod_two_eq_zero_or_one (ℓ w) with even | odd
· rw [even, Nat.succ_mod_two_eq_one_iff.mpr even] at length_mod_two
contradiction
· rw [odd, Nat.succ_mod_two_eq_zero_iff.mpr odd] at length_mod_two
contradiction
theorem length_simple_mul_ne (w : W) (i : B) : ℓ (s i * w) ≠ ℓ w := by
convert cs.length_mul_simple_ne w⁻¹ i using 1
· convert cs.length_inv ?_ using 2
simp
· simp
theorem length_mul_simple (w : W) (i : B) :
ℓ (w * s i) = ℓ w + 1 ∨ ℓ (w * s i) + 1 = ℓ w := by
rcases Nat.lt_or_gt_of_ne (cs.length_mul_simple_ne w i) with lt | gt
· -- lt : ℓ (w * s i) < ℓ w
right
have length_ge := cs.length_mul_ge_length_sub_length w (s i)
simp only [length_simple, tsub_le_iff_right] at length_ge
-- length_ge : ℓ w ≤ ℓ (w * s i) + 1
omega
· -- gt : ℓ w < ℓ (w * s i)
left
have length_le := cs.length_mul_le w (s i)
simp only [length_simple] at length_le
-- length_le : ℓ (w * s i) ≤ ℓ w + 1
omega
theorem length_simple_mul (w : W) (i : B) :
ℓ (s i * w) = ℓ w + 1 ∨ ℓ (s i * w) + 1 = ℓ w := by
have := cs.length_mul_simple w⁻¹ i
rwa [(by simp : w⁻¹ * (s i) = ((s i) * w)⁻¹), length_inv, length_inv] at this
/-! ### Reduced words -/
/-- The proposition that `ω` is reduced; that is, it has minimal length among all words that
represent the same element of `W`. -/
def IsReduced (ω : List B) : Prop := ℓ (π ω) = ω.length
@[simp]
theorem isReduced_reverse_iff (ω : List B) : cs.IsReduced (ω.reverse) ↔ cs.IsReduced ω := by
simp [IsReduced]
theorem IsReduced.reverse {cs : CoxeterSystem M W} {ω : List B}
(hω : cs.IsReduced ω) : cs.IsReduced (ω.reverse) :=
(cs.isReduced_reverse_iff ω).mpr hω
theorem exists_reduced_word' (w : W) : ∃ ω : List B, cs.IsReduced ω ∧ w = π ω := by
rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
use ω
tauto
private theorem isReduced_take_and_drop {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) :
cs.IsReduced (ω.take j) ∧ cs.IsReduced (ω.drop j) := by
have h₁ : ℓ (π (ω.take j)) ≤ (ω.take j).length := cs.length_wordProd_le (ω.take j)
have h₂ : ℓ (π (ω.drop j)) ≤ (ω.drop j).length := cs.length_wordProd_le (ω.drop j)
have h₃ := calc
(ω.take j).length + (ω.drop j).length
_ = ω.length := by rw [← List.length_append, ω.take_append_drop j]
_ = ℓ (π ω) := hω.symm
_ = ℓ (π (ω.take j) * π (ω.drop j)) := by rw [← cs.wordProd_append, ω.take_append_drop j]
_ ≤ ℓ (π (ω.take j)) + ℓ (π (ω.drop j)) := cs.length_mul_le _ _
unfold IsReduced
omega
theorem IsReduced.take {cs : CoxeterSystem M W} {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) :
cs.IsReduced (ω.take j) :=
(isReduced_take_and_drop _ hω _).1
theorem IsReduced.drop {cs : CoxeterSystem M W} {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) :
cs.IsReduced (ω.drop j) :=
(isReduced_take_and_drop _ hω _).2
theorem not_isReduced_alternatingWord (i i' : B) {m : ℕ} (hM : M i i' ≠ 0) (hm : m > M i i') :
¬cs.IsReduced (alternatingWord i i' m) := by
induction' hm with m _ ih
· -- Base case; m = M i i' + 1
suffices h : ℓ (π (alternatingWord i i' (M i i' + 1))) < M i i' + 1 by
unfold IsReduced
rw [Nat.succ_eq_add_one, length_alternatingWord]
omega
have : M i i' + 1 ≤ M i i' * 2 := by linarith [Nat.one_le_iff_ne_zero.mpr hM]
rw [cs.prod_alternatingWord_eq_prod_alternatingWord_sub i i' _ this]
have : M i i' * 2 - (M i i' + 1) = M i i' - 1 := by omega
rw [this]
calc
ℓ (π (alternatingWord i' i (M i i' - 1)))
_ ≤ (alternatingWord i' i (M i i' - 1)).length := cs.length_wordProd_le _
_ = M i i' - 1 := length_alternatingWord _ _ _
_ ≤ M i i' := Nat.sub_le _ _
_ < M i i' + 1 := Nat.lt_succ_self _
· -- Inductive step
contrapose! ih
rw [alternatingWord_succ'] at ih
apply IsReduced.drop (j := 1) at ih
simpa using ih
/-! ### Descents -/
/-- The proposition that `i` is a left descent of `w`; that is, $\ell(s_i w) < \ell(w)$. -/
def IsLeftDescent (w : W) (i : B) : Prop := ℓ (s i * w) < ℓ w
/-- The proposition that `i` is a right descent of `w`; that is, $\ell(w s_i) < \ell(w)$. -/
def IsRightDescent (w : W) (i : B) : Prop := ℓ (w * s i) < ℓ w
| Mathlib/GroupTheory/Coxeter/Length.lean | 277 | 279 | theorem not_isLeftDescent_one (i : B) : ¬cs.IsLeftDescent 1 i := by | simp [IsLeftDescent]
theorem not_isRightDescent_one (i : B) : ¬cs.IsRightDescent 1 i := by simp [IsRightDescent] |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Shing Tak Lam, Mario Carneiro
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Algebra.BigOperators.Ring.List
import Mathlib.Data.Int.ModEq
import Mathlib.Data.Nat.Bits
import Mathlib.Data.Nat.Log
import Mathlib.Data.List.Palindrome
import Mathlib.Tactic.IntervalCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
/-!
# Digits of a natural number
This provides a basic API for extracting the digits of a natural number in a given base,
and reconstructing numbers from their digits.
We also prove some divisibility tests based on digits, in particular completing
Theorem #85 from https://www.cs.ru.nl/~freek/100/.
Also included is a bound on the length of `Nat.toDigits` from core.
## TODO
A basic `norm_digits` tactic for proving goals of the form `Nat.digits a b = l` where `a` and `b`
are numerals is not yet ported.
-/
namespace Nat
variable {n : ℕ}
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux0 : ℕ → List ℕ
| 0 => []
| n + 1 => [n + 1]
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux1 (n : ℕ) : List ℕ :=
List.replicate n 1
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux (b : ℕ) (h : 2 ≤ b) : ℕ → List ℕ
| 0 => []
| n + 1 =>
((n + 1) % b) :: digitsAux b h ((n + 1) / b)
decreasing_by exact Nat.div_lt_self (Nat.succ_pos _) h
@[simp]
theorem digitsAux_zero (b : ℕ) (h : 2 ≤ b) : digitsAux b h 0 = [] := by rw [digitsAux]
theorem digitsAux_def (b : ℕ) (h : 2 ≤ b) (n : ℕ) (w : 0 < n) :
digitsAux b h n = (n % b) :: digitsAux b h (n / b) := by
cases n
· cases w
· rw [digitsAux]
/-- `digits b n` gives the digits, in little-endian order,
of a natural number `n` in a specified base `b`.
In any base, we have `ofDigits b L = L.foldr (fun x y ↦ x + b * y) 0`.
* For any `2 ≤ b`, we have `l < b` for any `l ∈ digits b n`,
and the last digit is not zero.
This uniquely specifies the behaviour of `digits b`.
* For `b = 1`, we define `digits 1 n = List.replicate n 1`.
* For `b = 0`, we define `digits 0 n = [n]`, except `digits 0 0 = []`.
Note this differs from the existing `Nat.toDigits` in core, which is used for printing numerals.
In particular, `Nat.toDigits b 0 = ['0']`, while `digits b 0 = []`.
-/
def digits : ℕ → ℕ → List ℕ
| 0 => digitsAux0
| 1 => digitsAux1
| b + 2 => digitsAux (b + 2) (by norm_num)
@[simp]
theorem digits_zero (b : ℕ) : digits b 0 = [] := by
rcases b with (_ | ⟨_ | ⟨_⟩⟩) <;> simp [digits, digitsAux0, digitsAux1]
theorem digits_zero_zero : digits 0 0 = [] :=
rfl
@[simp]
theorem digits_zero_succ (n : ℕ) : digits 0 n.succ = [n + 1] :=
rfl
theorem digits_zero_succ' : ∀ {n : ℕ}, n ≠ 0 → digits 0 n = [n]
| 0, h => (h rfl).elim
| _ + 1, _ => rfl
@[simp]
theorem digits_one (n : ℕ) : digits 1 n = List.replicate n 1 :=
rfl
-- no `@[simp]`: dsimp can prove this
theorem digits_one_succ (n : ℕ) : digits 1 (n + 1) = 1 :: digits 1 n :=
rfl
theorem digits_add_two_add_one (b n : ℕ) :
digits (b + 2) (n + 1) = ((n + 1) % (b + 2)) :: digits (b + 2) ((n + 1) / (b + 2)) := by
simp [digits, digitsAux_def]
@[simp]
lemma digits_of_two_le_of_pos {b : ℕ} (hb : 2 ≤ b) (hn : 0 < n) :
Nat.digits b n = n % b :: Nat.digits b (n / b) := by
rw [Nat.eq_add_of_sub_eq hb rfl, Nat.eq_add_of_sub_eq hn rfl, Nat.digits_add_two_add_one]
theorem digits_def' :
∀ {b : ℕ} (_ : 1 < b) {n : ℕ} (_ : 0 < n), digits b n = (n % b) :: digits b (n / b)
| 0, h => absurd h (by decide)
| 1, h => absurd h (by decide)
| b + 2, _ => digitsAux_def _ (by simp) _
@[simp]
theorem digits_of_lt (b x : ℕ) (hx : x ≠ 0) (hxb : x < b) : digits b x = [x] := by
rcases exists_eq_succ_of_ne_zero hx with ⟨x, rfl⟩
rcases Nat.exists_eq_add_of_le' ((Nat.le_add_left 1 x).trans_lt hxb) with ⟨b, rfl⟩
rw [digits_add_two_add_one, div_eq_of_lt hxb, digits_zero, mod_eq_of_lt hxb]
theorem digits_add (b : ℕ) (h : 1 < b) (x y : ℕ) (hxb : x < b) (hxy : x ≠ 0 ∨ y ≠ 0) :
digits b (x + b * y) = x :: digits b y := by
rcases Nat.exists_eq_add_of_le' h with ⟨b, rfl : _ = _ + 2⟩
cases y
· simp [hxb, hxy.resolve_right (absurd rfl)]
dsimp [digits]
rw [digitsAux_def]
· congr
· simp [Nat.add_mod, mod_eq_of_lt hxb]
· simp [add_mul_div_left, div_eq_of_lt hxb]
· apply Nat.succ_pos
-- If we had a function converting a list into a polynomial,
-- and appropriate lemmas about that function,
-- we could rewrite this in terms of that.
/-- `ofDigits b L` takes a list `L` of natural numbers, and interprets them
as a number in semiring, as the little-endian digits in base `b`.
-/
def ofDigits {α : Type*} [Semiring α] (b : α) : List ℕ → α
| [] => 0
| h :: t => h + b * ofDigits b t
theorem ofDigits_eq_foldr {α : Type*} [Semiring α] (b : α) (L : List ℕ) :
ofDigits b L = List.foldr (fun x y => ↑x + b * y) 0 L := by
induction' L with d L ih
· rfl
· dsimp [ofDigits]
rw [ih]
theorem ofDigits_eq_sum_mapIdx_aux (b : ℕ) (l : List ℕ) :
(l.zipWith ((fun a i : ℕ => a * b ^ (i + 1))) (List.range l.length)).sum =
b * (l.zipWith (fun a i => a * b ^ i) (List.range l.length)).sum := by
suffices
l.zipWith (fun a i : ℕ => a * b ^ (i + 1)) (List.range l.length) =
l.zipWith (fun a i=> b * (a * b ^ i)) (List.range l.length)
by simp [this]
congr; ext; simp [pow_succ]; ring
theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) :
ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by
rw [List.mapIdx_eq_zipIdx_map, List.zipIdx_eq_zip_range', List.map_zip_eq_zipWith,
ofDigits_eq_foldr, ← List.range_eq_range']
induction' L with hd tl hl
· simp
· simpa [List.range_succ_eq_map, List.zipWith_map_right, ofDigits_eq_sum_mapIdx_aux] using
Or.inl hl
@[simp]
theorem ofDigits_nil {b : ℕ} : ofDigits b [] = 0 := rfl
@[simp]
theorem ofDigits_singleton {b n : ℕ} : ofDigits b [n] = n := by simp [ofDigits]
@[simp]
theorem ofDigits_one_cons {α : Type*} [Semiring α] (h : ℕ) (L : List ℕ) :
ofDigits (1 : α) (h :: L) = h + ofDigits 1 L := by simp [ofDigits]
theorem ofDigits_cons {b hd} {tl : List ℕ} :
ofDigits b (hd :: tl) = hd + b * ofDigits b tl := rfl
theorem ofDigits_append {b : ℕ} {l1 l2 : List ℕ} :
ofDigits b (l1 ++ l2) = ofDigits b l1 + b ^ l1.length * ofDigits b l2 := by
induction' l1 with hd tl IH
· simp [ofDigits]
· rw [ofDigits, List.cons_append, ofDigits, IH, List.length_cons, pow_succ']
ring
@[norm_cast]
theorem coe_ofDigits (α : Type*) [Semiring α] (b : ℕ) (L : List ℕ) :
((ofDigits b L : ℕ) : α) = ofDigits (b : α) L := by
induction' L with d L ih
· simp [ofDigits]
· dsimp [ofDigits]; push_cast; rw [ih]
@[norm_cast]
| Mathlib/Data/Nat/Digits.lean | 199 | 199 | theorem coe_int_ofDigits (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : ℤ) = ofDigits (b : ℤ) L := by | |
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.Complex.Basic
import Mathlib.Analysis.InnerProductSpace.Defs
import Mathlib.GroupTheory.MonoidLocalization.Basic
/-!
# Properties of inner product spaces
This file proves many basic properties of inner product spaces (real or complex).
## Main results
- `inner_mul_inner_self_le`: the Cauchy-Schwartz inequality (one of many variants).
- `norm_inner_eq_norm_iff`: the equality criteion in the Cauchy-Schwartz inequality (also in many
variants).
- `inner_eq_sum_norm_sq_div_four`: the polarization identity.
## Tags
inner product space, Hilbert space, norm
-/
noncomputable section
open RCLike Real Filter Topology ComplexConjugate Finsupp
open LinearMap (BilinForm)
variable {𝕜 E F : Type*} [RCLike 𝕜]
section BasicProperties_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local postfix:90 "†" => starRingEnd _
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_conj_symm (x y : E) : ⟪y, x⟫† = ⟪x, y⟫ :=
InnerProductSpace.conj_inner_symm _ _
theorem real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ :=
@inner_conj_symm ℝ _ _ _ _ x y
theorem inner_eq_zero_symm {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 := by
rw [← inner_conj_symm]
exact star_eq_zero
@[simp]
theorem inner_self_im (x : E) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub]; simp
theorem inner_add_left (x y z : E) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ :=
InnerProductSpace.add_left _ _ _
theorem inner_add_right (x y z : E) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by
rw [← inner_conj_symm, inner_add_left, RingHom.map_add]
simp only [inner_conj_symm]
theorem inner_re_symm (x y : E) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re]
theorem inner_im_symm (x y : E) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im]
section Algebra
variable {𝕝 : Type*} [CommSemiring 𝕝] [StarRing 𝕝] [Algebra 𝕝 𝕜] [Module 𝕝 E]
[IsScalarTower 𝕝 𝕜 E] [StarModule 𝕝 𝕜]
/-- See `inner_smul_left` for the common special when `𝕜 = 𝕝`. -/
lemma inner_smul_left_eq_star_smul (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r† • ⟪x, y⟫ := by
rw [← algebraMap_smul 𝕜 r, InnerProductSpace.smul_left, starRingEnd_apply, starRingEnd_apply,
← algebraMap_star_comm, ← smul_eq_mul, algebraMap_smul]
/-- Special case of `inner_smul_left_eq_star_smul` when the acting ring has a trivial star
(eg `ℕ`, `ℤ`, `ℚ≥0`, `ℚ`, `ℝ`). -/
lemma inner_smul_left_eq_smul [TrivialStar 𝕝] (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_left_eq_star_smul, starRingEnd_apply, star_trivial]
/-- See `inner_smul_right` for the common special when `𝕜 = 𝕝`. -/
lemma inner_smul_right_eq_smul (x y : E) (r : 𝕝) : ⟪x, r • y⟫ = r • ⟪x, y⟫ := by
rw [← inner_conj_symm, inner_smul_left_eq_star_smul, starRingEnd_apply, starRingEnd_apply,
star_smul, star_star, ← starRingEnd_apply, inner_conj_symm]
end Algebra
/-- See `inner_smul_left_eq_star_smul` for the case of a general algebra action. -/
theorem inner_smul_left (x y : E) (r : 𝕜) : ⟪r • x, y⟫ = r† * ⟪x, y⟫ :=
inner_smul_left_eq_star_smul ..
theorem real_inner_smul_left (x y : F) (r : ℝ) : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ :=
inner_smul_left _ _ _
theorem inner_smul_real_left (x y : E) (r : ℝ) : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_left, conj_ofReal, Algebra.smul_def]
/-- See `inner_smul_right_eq_smul` for the case of a general algebra action. -/
theorem inner_smul_right (x y : E) (r : 𝕜) : ⟪x, r • y⟫ = r * ⟪x, y⟫ :=
inner_smul_right_eq_smul ..
theorem real_inner_smul_right (x y : F) (r : ℝ) : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ :=
inner_smul_right _ _ _
theorem inner_smul_real_right (x y : E) (r : ℝ) : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_right, Algebra.smul_def]
/-- The inner product as a sesquilinear form.
Note that in the case `𝕜 = ℝ` this is a bilinear form. -/
@[simps!]
def sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 :=
LinearMap.mk₂'ₛₗ (RingHom.id 𝕜) (starRingEnd _) (fun x y => ⟪y, x⟫)
(fun _x _y _z => inner_add_right _ _ _) (fun _r _x _y => inner_smul_right _ _ _)
(fun _x _y _z => inner_add_left _ _ _) fun _r _x _y => inner_smul_left _ _ _
/-- The real inner product as a bilinear form.
Note that unlike `sesqFormOfInner`, this does not reverse the order of the arguments. -/
@[simps!]
def bilinFormOfRealInner : BilinForm ℝ F := sesqFormOfInner.flip
/-- An inner product with a sum on the left. -/
theorem sum_inner {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) :
⟪∑ i ∈ s, f i, x⟫ = ∑ i ∈ s, ⟪f i, x⟫ :=
map_sum (sesqFormOfInner (𝕜 := 𝕜) (E := E) x) _ _
/-- An inner product with a sum on the right. -/
theorem inner_sum {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) :
⟪x, ∑ i ∈ s, f i⟫ = ∑ i ∈ s, ⟪x, f i⟫ :=
map_sum (LinearMap.flip sesqFormOfInner x) _ _
/-- An inner product with a sum on the left, `Finsupp` version. -/
protected theorem Finsupp.sum_inner {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪l.sum fun (i : ι) (a : 𝕜) => a • v i, x⟫ = l.sum fun (i : ι) (a : 𝕜) => conj a • ⟪v i, x⟫ := by
convert sum_inner (𝕜 := 𝕜) l.support (fun a => l a • v a) x
simp only [inner_smul_left, Finsupp.sum, smul_eq_mul]
/-- An inner product with a sum on the right, `Finsupp` version. -/
protected theorem Finsupp.inner_sum {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪x, l.sum fun (i : ι) (a : 𝕜) => a • v i⟫ = l.sum fun (i : ι) (a : 𝕜) => a • ⟪x, v i⟫ := by
convert inner_sum (𝕜 := 𝕜) l.support (fun a => l a • v a) x
simp only [inner_smul_right, Finsupp.sum, smul_eq_mul]
protected theorem DFinsupp.sum_inner {ι : Type*} [DecidableEq ι] {α : ι → Type*}
[∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)
(l : Π₀ i, α i) (x : E) : ⟪l.sum f, x⟫ = l.sum fun i a => ⟪f i a, x⟫ := by
simp +contextual only [DFinsupp.sum, sum_inner, smul_eq_mul]
protected theorem DFinsupp.inner_sum {ι : Type*} [DecidableEq ι] {α : ι → Type*}
[∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)
(l : Π₀ i, α i) (x : E) : ⟪x, l.sum f⟫ = l.sum fun i a => ⟪x, f i a⟫ := by
simp +contextual only [DFinsupp.sum, inner_sum, smul_eq_mul]
@[simp]
theorem inner_zero_left (x : E) : ⟪0, x⟫ = 0 := by
rw [← zero_smul 𝕜 (0 : E), inner_smul_left, RingHom.map_zero, zero_mul]
theorem inner_re_zero_left (x : E) : re ⟪0, x⟫ = 0 := by
simp only [inner_zero_left, AddMonoidHom.map_zero]
@[simp]
theorem inner_zero_right (x : E) : ⟪x, 0⟫ = 0 := by
rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero]
theorem inner_re_zero_right (x : E) : re ⟪x, 0⟫ = 0 := by
simp only [inner_zero_right, AddMonoidHom.map_zero]
theorem inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ :=
PreInnerProductSpace.toCore.re_inner_nonneg x
theorem real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ :=
@inner_self_nonneg ℝ F _ _ _ x
@[simp]
theorem inner_self_ofReal_re (x : E) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=
((RCLike.is_real_TFAE (⟪x, x⟫ : 𝕜)).out 2 3).2 (inner_self_im (𝕜 := 𝕜) x)
theorem inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (‖x‖ : 𝕜) ^ 2 := by
rw [← inner_self_ofReal_re, ← norm_sq_eq_re_inner, ofReal_pow]
theorem inner_self_re_eq_norm (x : E) : re ⟪x, x⟫ = ‖⟪x, x⟫‖ := by
conv_rhs => rw [← inner_self_ofReal_re]
symm
exact norm_of_nonneg inner_self_nonneg
theorem inner_self_ofReal_norm (x : E) : (‖⟪x, x⟫‖ : 𝕜) = ⟪x, x⟫ := by
rw [← inner_self_re_eq_norm]
exact inner_self_ofReal_re _
theorem real_inner_self_abs (x : F) : |⟪x, x⟫_ℝ| = ⟪x, x⟫_ℝ :=
@inner_self_ofReal_norm ℝ F _ _ _ x
theorem norm_inner_symm (x y : E) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj]
@[simp]
theorem inner_neg_left (x y : E) : ⟪-x, y⟫ = -⟪x, y⟫ := by
rw [← neg_one_smul 𝕜 x, inner_smul_left]
simp
@[simp]
theorem inner_neg_right (x y : E) : ⟪x, -y⟫ = -⟪x, y⟫ := by
rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm]
theorem inner_neg_neg (x y : E) : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp
theorem inner_self_conj (x : E) : ⟪x, x⟫† = ⟪x, x⟫ := inner_conj_symm _ _
theorem inner_sub_left (x y z : E) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by
simp [sub_eq_add_neg, inner_add_left]
theorem inner_sub_right (x y z : E) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by
simp [sub_eq_add_neg, inner_add_right]
theorem inner_mul_symm_re_eq_norm (x y : E) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by
rw [← inner_conj_symm, mul_comm]
exact re_eq_norm_of_mul_conj (inner y x)
/-- Expand `⟪x + y, x + y⟫` -/
theorem inner_add_add_self (x y : E) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by
simp only [inner_add_left, inner_add_right]; ring
/-- Expand `⟪x + y, x + y⟫_ℝ` -/
theorem real_inner_add_add_self (x y : F) :
⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl
simp only [inner_add_add_self, this, add_left_inj]
ring
-- Expand `⟪x - y, x - y⟫`
theorem inner_sub_sub_self (x y : E) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by
simp only [inner_sub_left, inner_sub_right]; ring
/-- Expand `⟪x - y, x - y⟫_ℝ` -/
theorem real_inner_sub_sub_self (x y : F) :
⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl
simp only [inner_sub_sub_self, this, add_left_inj]
ring
/-- Parallelogram law -/
theorem parallelogram_law {x y : E} : ⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) := by
simp only [inner_add_add_self, inner_sub_sub_self]
ring
/-- **Cauchy–Schwarz inequality**. -/
theorem inner_mul_inner_self_le (x y : E) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ :=
letI cd : PreInnerProductSpace.Core 𝕜 E := PreInnerProductSpace.toCore
InnerProductSpace.Core.inner_mul_inner_self_le x y
/-- Cauchy–Schwarz inequality for real inner products. -/
theorem real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ :=
calc
⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ‖⟪x, y⟫_ℝ‖ * ‖⟪y, x⟫_ℝ‖ := by
rw [real_inner_comm y, ← norm_mul]
exact le_abs_self _
_ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := @inner_mul_inner_self_le ℝ _ _ _ _ x y
end BasicProperties_Seminormed
section BasicProperties
variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [NormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 := by
rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero]
theorem inner_self_ne_zero {x : E} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 :=
inner_self_eq_zero.not
variable (𝕜)
theorem ext_inner_left {x y : E} (h : ∀ v, ⟪v, x⟫ = ⟪v, y⟫) : x = y := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)]
theorem ext_inner_right {x y : E} (h : ∀ v, ⟪x, v⟫ = ⟪y, v⟫) : x = y := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)]
variable {𝕜}
@[simp]
theorem re_inner_self_nonpos {x : E} : re ⟪x, x⟫ ≤ 0 ↔ x = 0 := by
rw [← norm_sq_eq_re_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero]
@[simp]
lemma re_inner_self_pos {x : E} : 0 < re ⟪x, x⟫ ↔ x ≠ 0 := by
simpa [-re_inner_self_nonpos] using re_inner_self_nonpos (𝕜 := 𝕜) (x := x).not
@[deprecated (since := "2025-04-22")] alias inner_self_nonpos := re_inner_self_nonpos
@[deprecated (since := "2025-04-22")] alias inner_self_pos := re_inner_self_pos
open scoped InnerProductSpace in
theorem real_inner_self_nonpos {x : F} : ⟪x, x⟫_ℝ ≤ 0 ↔ x = 0 := re_inner_self_nonpos (𝕜 := ℝ)
open scoped InnerProductSpace in
theorem real_inner_self_pos {x : F} : 0 < ⟪x, x⟫_ℝ ↔ x ≠ 0 := re_inner_self_pos (𝕜 := ℝ)
/-- A family of vectors is linearly independent if they are nonzero
and orthogonal. -/
theorem linearIndependent_of_ne_zero_of_inner_eq_zero {ι : Type*} {v : ι → E} (hz : ∀ i, v i ≠ 0)
(ho : Pairwise fun i j => ⟪v i, v j⟫ = 0) : LinearIndependent 𝕜 v := by
rw [linearIndependent_iff']
intro s g hg i hi
have h' : g i * inner (v i) (v i) = inner (v i) (∑ j ∈ s, g j • v j) := by
rw [inner_sum]
symm
convert Finset.sum_eq_single (M := 𝕜) i ?_ ?_
· rw [inner_smul_right]
· intro j _hj hji
rw [inner_smul_right, ho hji.symm, mul_zero]
· exact fun h => False.elim (h hi)
simpa [hg, hz] using h'
end BasicProperties
section Norm_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local notation "IK" => @RCLike.I 𝕜 _
theorem norm_eq_sqrt_re_inner (x : E) : ‖x‖ = √(re ⟪x, x⟫) :=
calc
‖x‖ = √(‖x‖ ^ 2) := (sqrt_sq (norm_nonneg _)).symm
_ = √(re ⟪x, x⟫) := congr_arg _ (norm_sq_eq_re_inner _)
@[deprecated (since := "2025-04-22")] alias norm_eq_sqrt_inner := norm_eq_sqrt_re_inner
theorem norm_eq_sqrt_real_inner (x : F) : ‖x‖ = √⟪x, x⟫_ℝ :=
@norm_eq_sqrt_re_inner ℝ _ _ _ _ x
theorem inner_self_eq_norm_mul_norm (x : E) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by
rw [@norm_eq_sqrt_re_inner 𝕜, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫),
sqrt_mul_self inner_self_nonneg]
theorem inner_self_eq_norm_sq (x : E) : re ⟪x, x⟫ = ‖x‖ ^ 2 := by
rw [pow_two, inner_self_eq_norm_mul_norm]
theorem real_inner_self_eq_norm_mul_norm (x : F) : ⟪x, x⟫_ℝ = ‖x‖ * ‖x‖ := by
have h := @inner_self_eq_norm_mul_norm ℝ F _ _ _ x
simpa using h
theorem real_inner_self_eq_norm_sq (x : F) : ⟪x, x⟫_ℝ = ‖x‖ ^ 2 := by
rw [pow_two, real_inner_self_eq_norm_mul_norm]
/-- Expand the square -/
theorem norm_add_sq (x y : E) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by
repeat' rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜]
rw [inner_add_add_self, two_mul]
simp only [add_assoc, add_left_inj, add_right_inj, AddMonoidHom.map_add]
rw [← inner_conj_symm, conj_re]
alias norm_add_pow_two := norm_add_sq
/-- Expand the square -/
theorem norm_add_sq_real (x y : F) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 := by
have h := @norm_add_sq ℝ _ _ _ _ x y
simpa using h
alias norm_add_pow_two_real := norm_add_sq_real
/-- Expand the square -/
theorem norm_add_mul_self (x y : E) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by
repeat' rw [← sq (M := ℝ)]
exact norm_add_sq _ _
/-- Expand the square -/
theorem norm_add_mul_self_real (x y : F) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by
have h := @norm_add_mul_self ℝ _ _ _ _ x y
simpa using h
/-- Expand the square -/
theorem norm_sub_sq (x y : E) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by
rw [sub_eq_add_neg, @norm_add_sq 𝕜 _ _ _ _ x (-y), norm_neg, inner_neg_right, map_neg, mul_neg,
sub_eq_add_neg]
alias norm_sub_pow_two := norm_sub_sq
/-- Expand the square -/
theorem norm_sub_sq_real (x y : F) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 :=
@norm_sub_sq ℝ _ _ _ _ _ _
alias norm_sub_pow_two_real := norm_sub_sq_real
/-- Expand the square -/
theorem norm_sub_mul_self (x y : E) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by
repeat' rw [← sq (M := ℝ)]
exact norm_sub_sq _ _
/-- Expand the square -/
theorem norm_sub_mul_self_real (x y : F) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by
have h := @norm_sub_mul_self ℝ _ _ _ _ x y
simpa using h
/-- Cauchy–Schwarz inequality with norm -/
theorem norm_inner_le_norm (x y : E) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := by
rw [norm_eq_sqrt_re_inner (𝕜 := 𝕜) x, norm_eq_sqrt_re_inner (𝕜 := 𝕜) y]
letI : PreInnerProductSpace.Core 𝕜 E := PreInnerProductSpace.toCore
exact InnerProductSpace.Core.norm_inner_le_norm x y
theorem nnnorm_inner_le_nnnorm (x y : E) : ‖⟪x, y⟫‖₊ ≤ ‖x‖₊ * ‖y‖₊ :=
norm_inner_le_norm x y
theorem re_inner_le_norm (x y : E) : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ :=
le_trans (re_le_norm (inner x y)) (norm_inner_le_norm x y)
/-- Cauchy–Schwarz inequality with norm -/
theorem abs_real_inner_le_norm (x y : F) : |⟪x, y⟫_ℝ| ≤ ‖x‖ * ‖y‖ :=
(Real.norm_eq_abs _).ge.trans (norm_inner_le_norm x y)
/-- Cauchy–Schwarz inequality with norm -/
theorem real_inner_le_norm (x y : F) : ⟪x, y⟫_ℝ ≤ ‖x‖ * ‖y‖ :=
le_trans (le_abs_self _) (abs_real_inner_le_norm _ _)
lemma inner_eq_zero_of_left {x : E} (y : E) (h : ‖x‖ = 0) : ⟪x, y⟫_𝕜 = 0 := by
rw [← norm_eq_zero]
refine le_antisymm ?_ (by positivity)
exact norm_inner_le_norm _ _ |>.trans <| by simp [h]
lemma inner_eq_zero_of_right (x : E) {y : E} (h : ‖y‖ = 0) : ⟪x, y⟫_𝕜 = 0 := by
rw [inner_eq_zero_symm, inner_eq_zero_of_left _ h]
variable (𝕜)
include 𝕜 in
theorem parallelogram_law_with_norm (x y : E) :
‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) := by
simp only [← @inner_self_eq_norm_mul_norm 𝕜]
rw [← re.map_add, parallelogram_law, two_mul, two_mul]
simp only [re.map_add]
include 𝕜 in
theorem parallelogram_law_with_nnnorm (x y : E) :
‖x + y‖₊ * ‖x + y‖₊ + ‖x - y‖₊ * ‖x - y‖₊ = 2 * (‖x‖₊ * ‖x‖₊ + ‖y‖₊ * ‖y‖₊) :=
Subtype.ext <| parallelogram_law_with_norm 𝕜 x y
variable {𝕜}
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) :
re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 := by
rw [@norm_add_mul_self 𝕜]
ring
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) :
re ⟪x, y⟫ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 := by
rw [@norm_sub_mul_self 𝕜]
ring
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) :
re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x - y‖ * ‖x - y‖) / 4 := by
rw [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜]
ring
/-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/
theorem im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four (x y : E) :
im ⟪x, y⟫ = (‖x - IK • y‖ * ‖x - IK • y‖ - ‖x + IK • y‖ * ‖x + IK • y‖) / 4 := by
simp only [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜, inner_smul_right, I_mul_re]
ring
/-- Polarization identity: The inner product, in terms of the norm. -/
theorem inner_eq_sum_norm_sq_div_four (x y : E) :
⟪x, y⟫ = ((‖x + y‖ : 𝕜) ^ 2 - (‖x - y‖ : 𝕜) ^ 2 +
((‖x - IK • y‖ : 𝕜) ^ 2 - (‖x + IK • y‖ : 𝕜) ^ 2) * IK) / 4 := by
rw [← re_add_im ⟪x, y⟫, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four,
im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four]
push_cast
simp only [sq, ← mul_div_right_comm, ← add_div]
/-- Polarization identity: The real inner product, in terms of the norm. -/
theorem real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) :
⟪x, y⟫_ℝ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 :=
re_to_real.symm.trans <|
re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y
/-- Polarization identity: The real inner product, in terms of the norm. -/
theorem real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) :
⟪x, y⟫_ℝ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 :=
re_to_real.symm.trans <|
re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y
/-- Pythagorean theorem, if-and-only-if vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 := by
rw [@norm_add_mul_self ℝ, add_right_cancel_iff, add_eq_left, mul_eq_zero]
norm_num
/-- Pythagorean theorem, if-and-if vector inner product form using square roots. -/
theorem norm_add_eq_sqrt_iff_real_inner_eq_zero {x y : F} :
‖x + y‖ = √(‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by
rw [← norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq,
eq_comm] <;> positivity
/-- Pythagorean theorem, vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : ⟪x, y⟫ = 0) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := by
rw [@norm_add_mul_self 𝕜, add_right_cancel_iff, add_eq_left, mul_eq_zero]
apply Or.inr
simp only [h, zero_re']
/-- Pythagorean theorem, vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=
(norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h
/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector
inner product form. -/
theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 := by
rw [@norm_sub_mul_self ℝ, add_right_cancel_iff, sub_eq_add_neg, add_eq_left, neg_eq_zero,
mul_eq_zero]
norm_num
/-- Pythagorean theorem, subtracting vectors, if-and-if vector inner product form using square
roots. -/
theorem norm_sub_eq_sqrt_iff_real_inner_eq_zero {x y : F} :
‖x - y‖ = √(‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by
rw [← norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq,
eq_comm] <;> positivity
/-- Pythagorean theorem, subtracting vectors, vector inner product
form. -/
theorem norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=
(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h
/-- The sum and difference of two vectors are orthogonal if and only
if they have the same norm. -/
| Mathlib/Analysis/InnerProductSpace/Basic.lean | 555 | 556 | theorem real_inner_add_sub_eq_zero_iff (x y : F) : ⟪x + y, x - y⟫_ℝ = 0 ↔ ‖x‖ = ‖y‖ := by | conv_rhs => rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] |
/-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals
import Mathlib.Analysis.Calculus.ParametricIntegral
import Mathlib.MeasureTheory.Measure.Haar.NormedSpace
/-! # The Mellin transform
We define the Mellin transform of a locally integrable function on `Ioi 0`, and show it is
differentiable in a suitable vertical strip.
## Main statements
- `mellin` : the Mellin transform `∫ (t : ℝ) in Ioi 0, t ^ (s - 1) • f t`,
where `s` is a complex number.
- `HasMellin`: shorthand asserting that the Mellin transform exists and has a given value
(analogous to `HasSum`).
- `mellin_differentiableAt_of_isBigO_rpow` : if `f` is `O(x ^ (-a))` at infinity, and
`O(x ^ (-b))` at 0, then `mellin f` is holomorphic on the domain `b < re s < a`.
-/
open MeasureTheory Set Filter Asymptotics TopologicalSpace
open Real
open Complex hiding exp log abs_of_nonneg
open scoped Topology
noncomputable section
section Defs
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E]
/-- Predicate on `f` and `s` asserting that the Mellin integral is well-defined. -/
def MellinConvergent (f : ℝ → E) (s : ℂ) : Prop :=
IntegrableOn (fun t : ℝ => (t : ℂ) ^ (s - 1) • f t) (Ioi 0)
theorem MellinConvergent.const_smul {f : ℝ → E} {s : ℂ} (hf : MellinConvergent f s) {𝕜 : Type*}
[NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℂ 𝕜 E] (c : 𝕜) :
MellinConvergent (fun t => c • f t) s := by
simpa only [MellinConvergent, smul_comm] using hf.smul c
theorem MellinConvergent.cpow_smul {f : ℝ → E} {s a : ℂ} :
MellinConvergent (fun t => (t : ℂ) ^ a • f t) s ↔ MellinConvergent f (s + a) := by
refine integrableOn_congr_fun (fun t ht => ?_) measurableSet_Ioi
simp_rw [← sub_add_eq_add_sub, cpow_add _ _ (ofReal_ne_zero.2 <| ne_of_gt ht), mul_smul]
nonrec theorem MellinConvergent.div_const {f : ℝ → ℂ} {s : ℂ} (hf : MellinConvergent f s) (a : ℂ) :
MellinConvergent (fun t => f t / a) s := by
simpa only [MellinConvergent, smul_eq_mul, ← mul_div_assoc] using hf.div_const a
theorem MellinConvergent.comp_mul_left {f : ℝ → E} {s : ℂ} {a : ℝ} (ha : 0 < a) :
MellinConvergent (fun t => f (a * t)) s ↔ MellinConvergent f s := by
have := integrableOn_Ioi_comp_mul_left_iff (fun t : ℝ => (t : ℂ) ^ (s - 1) • f t) 0 ha
rw [mul_zero] at this
have h1 : EqOn (fun t : ℝ => (↑(a * t) : ℂ) ^ (s - 1) • f (a * t))
((a : ℂ) ^ (s - 1) • fun t : ℝ => (t : ℂ) ^ (s - 1) • f (a * t)) (Ioi 0) := fun t ht ↦ by
simp only [ofReal_mul, mul_cpow_ofReal_nonneg ha.le (le_of_lt ht), mul_smul, Pi.smul_apply]
have h2 : (a : ℂ) ^ (s - 1) ≠ 0 := by
rw [Ne, cpow_eq_zero_iff, not_and_or, ofReal_eq_zero]
exact Or.inl ha.ne'
rw [MellinConvergent, MellinConvergent, ← this, integrableOn_congr_fun h1 measurableSet_Ioi,
IntegrableOn, IntegrableOn, integrable_smul_iff h2]
theorem MellinConvergent.comp_rpow {f : ℝ → E} {s : ℂ} {a : ℝ} (ha : a ≠ 0) :
MellinConvergent (fun t => f (t ^ a)) s ↔ MellinConvergent f (s / a) := by
refine Iff.trans ?_ (integrableOn_Ioi_comp_rpow_iff' _ ha)
rw [MellinConvergent]
refine integrableOn_congr_fun (fun t ht => ?_) measurableSet_Ioi
dsimp only [Pi.smul_apply]
rw [← Complex.coe_smul (t ^ (a - 1)), ← mul_smul, ← cpow_mul_ofReal_nonneg (le_of_lt ht),
ofReal_cpow (le_of_lt ht), ← cpow_add _ _ (ofReal_ne_zero.mpr (ne_of_gt ht)), ofReal_sub,
ofReal_one, mul_sub, mul_div_cancel₀ _ (ofReal_ne_zero.mpr ha), mul_one, add_comm, ←
add_sub_assoc, sub_add_cancel]
/-- A function `f` is `VerticalIntegrable` at `σ` if `y ↦ f(σ + yi)` is integrable. -/
def Complex.VerticalIntegrable (f : ℂ → E) (σ : ℝ) (μ : Measure ℝ := by volume_tac) : Prop :=
Integrable (fun (y : ℝ) ↦ f (σ + y * I)) μ
/-- The Mellin transform of a function `f` (for a complex exponent `s`), defined as the integral of
`t ^ (s - 1) • f` over `Ioi 0`. -/
def mellin (f : ℝ → E) (s : ℂ) : E :=
∫ t : ℝ in Ioi 0, (t : ℂ) ^ (s - 1) • f t
/-- The Mellin inverse transform of a function `f`, defined as `1 / (2π)` times
the integral of `y ↦ x ^ -(σ + yi) • f (σ + yi)`. -/
def mellinInv (σ : ℝ) (f : ℂ → E) (x : ℝ) : E :=
(1 / (2 * π)) • ∫ y : ℝ, (x : ℂ) ^ (-(σ + y * I)) • f (σ + y * I)
-- next few lemmas don't require convergence of the Mellin transform (they are just 0 = 0 otherwise)
theorem mellin_cpow_smul (f : ℝ → E) (s a : ℂ) :
mellin (fun t => (t : ℂ) ^ a • f t) s = mellin f (s + a) := by
refine setIntegral_congr_fun measurableSet_Ioi fun t ht => ?_
simp_rw [← sub_add_eq_add_sub, cpow_add _ _ (ofReal_ne_zero.2 <| ne_of_gt ht), mul_smul]
theorem mellin_const_smul (f : ℝ → E) (s : ℂ) {𝕜 : Type*} [NontriviallyNormedField 𝕜]
[NormedSpace 𝕜 E] [SMulCommClass ℂ 𝕜 E] (c : 𝕜) :
mellin (fun t => c • f t) s = c • mellin f s := by simp only [mellin, smul_comm, integral_smul]
| Mathlib/Analysis/MellinTransform.lean | 106 | 109 | theorem mellin_div_const (f : ℝ → ℂ) (s a : ℂ) : mellin (fun t => f t / a) s = mellin f s / a := by | simp_rw [mellin, smul_eq_mul, ← mul_div_assoc, integral_div]
theorem mellin_comp_rpow (f : ℝ → E) (s : ℂ) (a : ℝ) : |
/-
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, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Dynamics.Ergodic.MeasurePreserving
import Mathlib.LinearAlgebra.Determinant
import Mathlib.LinearAlgebra.Matrix.Diagonal
import Mathlib.LinearAlgebra.Matrix.Transvection
import Mathlib.MeasureTheory.Group.LIntegral
import Mathlib.MeasureTheory.Integral.Marginal
import Mathlib.MeasureTheory.Measure.Stieltjes
import Mathlib.MeasureTheory.Measure.Haar.OfBasis
/-!
# Lebesgue measure on the real line and on `ℝⁿ`
We show that the Lebesgue measure on the real line (constructed as a particular case of additive
Haar measure on inner product spaces) coincides with the Stieltjes measure associated
to the function `x ↦ x`. We deduce properties of this measure on `ℝ`, and then of the product
Lebesgue measure on `ℝⁿ`. In particular, we prove that they are translation invariant.
We show that, on `ℝⁿ`, a linear map acts on Lebesgue measure by rescaling it through the absolute
value of its determinant, in `Real.map_linearMap_volume_pi_eq_smul_volume_pi`.
More properties of the Lebesgue measure are deduced from this in
`Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean`, where they are proved more generally for any
additive Haar measure on a finite-dimensional real vector space.
-/
assert_not_exists MeasureTheory.integral
noncomputable section
open Set Filter MeasureTheory MeasureTheory.Measure TopologicalSpace
open ENNReal (ofReal)
open scoped ENNReal NNReal Topology
/-!
### Definition of the Lebesgue measure and lengths of intervals
-/
namespace Real
variable {ι : Type*} [Fintype ι]
/-- The volume on the real line (as a particular case of the volume on a finite-dimensional
inner product space) coincides with the Stieltjes measure coming from the identity function. -/
theorem volume_eq_stieltjes_id : (volume : Measure ℝ) = StieltjesFunction.id.measure := by
haveI : IsAddLeftInvariant StieltjesFunction.id.measure :=
⟨fun a =>
Eq.symm <|
Real.measure_ext_Ioo_rat fun p q => by
simp only [Measure.map_apply (measurable_const_add a) measurableSet_Ioo,
sub_sub_sub_cancel_right, StieltjesFunction.measure_Ioo, StieltjesFunction.id_leftLim,
StieltjesFunction.id_apply, id, preimage_const_add_Ioo]⟩
have A : StieltjesFunction.id.measure (stdOrthonormalBasis ℝ ℝ).toBasis.parallelepiped = 1 := by
change StieltjesFunction.id.measure (parallelepiped (stdOrthonormalBasis ℝ ℝ)) = 1
rcases parallelepiped_orthonormalBasis_one_dim (stdOrthonormalBasis ℝ ℝ) with (H | H) <;>
simp only [H, StieltjesFunction.measure_Icc, StieltjesFunction.id_apply, id, tsub_zero,
StieltjesFunction.id_leftLim, sub_neg_eq_add, zero_add, ENNReal.ofReal_one]
conv_rhs =>
rw [addHaarMeasure_unique StieltjesFunction.id.measure
(stdOrthonormalBasis ℝ ℝ).toBasis.parallelepiped, A]
simp only [volume, Basis.addHaar, one_smul]
theorem volume_val (s) : volume s = StieltjesFunction.id.measure s := by
simp [volume_eq_stieltjes_id]
@[simp]
theorem volume_Ico {a b : ℝ} : volume (Ico a b) = ofReal (b - a) := by simp [volume_val]
@[simp]
theorem volume_real_Ico {a b : ℝ} : volume.real (Ico a b) = max (b - a) 0 := by
simp [measureReal_def, ENNReal.toReal_ofReal']
theorem volume_real_Ico_of_le {a b : ℝ} (hab : a ≤ b) : volume.real (Ico a b) = b - a := by
simp [hab]
@[simp]
theorem volume_Icc {a b : ℝ} : volume (Icc a b) = ofReal (b - a) := by simp [volume_val]
@[simp]
theorem volume_real_Icc {a b : ℝ} : volume.real (Icc a b) = max (b - a) 0 := by
simp [measureReal_def, ENNReal.toReal_ofReal']
theorem volume_real_Icc_of_le {a b : ℝ} (hab : a ≤ b) : volume.real (Icc a b) = b - a := by
simp [hab]
@[simp]
theorem volume_Ioo {a b : ℝ} : volume (Ioo a b) = ofReal (b - a) := by simp [volume_val]
@[simp]
theorem volume_real_Ioo {a b : ℝ} : volume.real (Ioo a b) = max (b - a) 0 := by
simp [measureReal_def, ENNReal.toReal_ofReal']
theorem volume_real_Ioo_of_le {a b : ℝ} (hab : a ≤ b) : volume.real (Ioo a b) = b - a := by
simp [hab]
@[simp]
theorem volume_Ioc {a b : ℝ} : volume (Ioc a b) = ofReal (b - a) := by simp [volume_val]
@[simp]
| Mathlib/MeasureTheory/Measure/Lebesgue/Basic.lean | 108 | 109 | theorem volume_real_Ioc {a b : ℝ} : volume.real (Ioc a b) = max (b - a) 0 := by | simp [measureReal_def, ENNReal.toReal_ofReal'] |
/-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll, Anatole Dedecker
-/
import Mathlib.Analysis.LocallyConvex.Bounded
import Mathlib.Analysis.Seminorm
import Mathlib.Data.Real.Sqrt
import Mathlib.Topology.Algebra.Equicontinuity
import Mathlib.Topology.MetricSpace.Equicontinuity
import Mathlib.Topology.Algebra.FilterBasis
import Mathlib.Topology.Algebra.Module.LocallyConvex
/-!
# Topology induced by a family of seminorms
## Main definitions
* `SeminormFamily.basisSets`: The set of open seminorm balls for a family of seminorms.
* `SeminormFamily.moduleFilterBasis`: A module filter basis formed by the open balls.
* `Seminorm.IsBounded`: A linear map `f : E →ₗ[𝕜] F` is bounded iff every seminorm in `F` can be
bounded by a finite number of seminorms in `E`.
## Main statements
* `WithSeminorms.toLocallyConvexSpace`: A space equipped with a family of seminorms is locally
convex.
* `WithSeminorms.firstCountable`: A space is first countable if it's topology is induced by a
countable family of seminorms.
## Continuity of semilinear maps
If `E` and `F` are topological vector space with the topology induced by a family of seminorms, then
we have a direct method to prove that a linear map is continuous:
* `Seminorm.continuous_from_bounded`: A bounded linear map `f : E →ₗ[𝕜] F` is continuous.
If the topology of a space `E` is induced by a family of seminorms, then we can characterize von
Neumann boundedness in terms of that seminorm family. Together with
`LinearMap.continuous_of_locally_bounded` this gives general criterion for continuity.
* `WithSeminorms.isVonNBounded_iff_finset_seminorm_bounded`
* `WithSeminorms.isVonNBounded_iff_seminorm_bounded`
* `WithSeminorms.image_isVonNBounded_iff_finset_seminorm_bounded`
* `WithSeminorms.image_isVonNBounded_iff_seminorm_bounded`
## Tags
seminorm, locally convex
-/
open NormedField Set Seminorm TopologicalSpace Filter List
open NNReal Pointwise Topology Uniformity
variable {𝕜 𝕜₂ 𝕝 𝕝₂ E F G ι ι' : Type*}
section FilterBasis
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E]
variable (𝕜 E ι)
/-- An abbreviation for indexed families of seminorms. This is mainly to allow for dot-notation. -/
abbrev SeminormFamily :=
ι → Seminorm 𝕜 E
variable {𝕜 E ι}
namespace SeminormFamily
/-- The sets of a filter basis for the neighborhood filter of 0. -/
def basisSets (p : SeminormFamily 𝕜 E ι) : Set (Set E) :=
⋃ (s : Finset ι) (r) (_ : 0 < r), singleton (ball (s.sup p) (0 : E) r)
variable (p : SeminormFamily 𝕜 E ι)
theorem basisSets_iff {U : Set E} :
U ∈ p.basisSets ↔ ∃ (i : Finset ι) (r : ℝ), 0 < r ∧ U = ball (i.sup p) 0 r := by
simp only [basisSets, mem_iUnion, exists_prop, mem_singleton_iff]
theorem basisSets_mem (i : Finset ι) {r : ℝ} (hr : 0 < r) : (i.sup p).ball 0 r ∈ p.basisSets :=
(basisSets_iff _).mpr ⟨i, _, hr, rfl⟩
theorem basisSets_singleton_mem (i : ι) {r : ℝ} (hr : 0 < r) : (p i).ball 0 r ∈ p.basisSets :=
(basisSets_iff _).mpr ⟨{i}, _, hr, by rw [Finset.sup_singleton]⟩
theorem basisSets_nonempty [Nonempty ι] : p.basisSets.Nonempty := by
let i := Classical.arbitrary ι
refine nonempty_def.mpr ⟨(p i).ball 0 1, ?_⟩
exact p.basisSets_singleton_mem i zero_lt_one
theorem basisSets_intersect (U V : Set E) (hU : U ∈ p.basisSets) (hV : V ∈ p.basisSets) :
∃ z ∈ p.basisSets, z ⊆ U ∩ V := by
classical
rcases p.basisSets_iff.mp hU with ⟨s, r₁, hr₁, hU⟩
rcases p.basisSets_iff.mp hV with ⟨t, r₂, hr₂, hV⟩
use ((s ∪ t).sup p).ball 0 (min r₁ r₂)
refine ⟨p.basisSets_mem (s ∪ t) (lt_min_iff.mpr ⟨hr₁, hr₂⟩), ?_⟩
rw [hU, hV, ball_finset_sup_eq_iInter _ _ _ (lt_min_iff.mpr ⟨hr₁, hr₂⟩),
ball_finset_sup_eq_iInter _ _ _ hr₁, ball_finset_sup_eq_iInter _ _ _ hr₂]
exact
Set.subset_inter
(Set.iInter₂_mono' fun i hi =>
⟨i, Finset.subset_union_left hi, ball_mono <| min_le_left _ _⟩)
(Set.iInter₂_mono' fun i hi =>
⟨i, Finset.subset_union_right hi, ball_mono <| min_le_right _ _⟩)
theorem basisSets_zero (U) (hU : U ∈ p.basisSets) : (0 : E) ∈ U := by
rcases p.basisSets_iff.mp hU with ⟨ι', r, hr, hU⟩
rw [hU, mem_ball_zero, map_zero]
exact hr
theorem basisSets_add (U) (hU : U ∈ p.basisSets) :
∃ V ∈ p.basisSets, V + V ⊆ U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
use (s.sup p).ball 0 (r / 2)
refine ⟨p.basisSets_mem s (div_pos hr zero_lt_two), ?_⟩
refine Set.Subset.trans (ball_add_ball_subset (s.sup p) (r / 2) (r / 2) 0 0) ?_
rw [hU, add_zero, add_halves]
theorem basisSets_neg (U) (hU' : U ∈ p.basisSets) :
∃ V ∈ p.basisSets, V ⊆ (fun x : E => -x) ⁻¹' U := by
rcases p.basisSets_iff.mp hU' with ⟨s, r, _, hU⟩
rw [hU, neg_preimage, neg_ball (s.sup p), neg_zero]
exact ⟨U, hU', Eq.subset hU⟩
/-- The `addGroupFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/
protected def addGroupFilterBasis [Nonempty ι] : AddGroupFilterBasis E :=
addGroupFilterBasisOfComm p.basisSets p.basisSets_nonempty p.basisSets_intersect p.basisSets_zero
p.basisSets_add p.basisSets_neg
theorem basisSets_smul_right (v : E) (U : Set E) (hU : U ∈ p.basisSets) :
∀ᶠ x : 𝕜 in 𝓝 0, x • v ∈ U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
rw [hU, Filter.eventually_iff]
simp_rw [(s.sup p).mem_ball_zero, map_smul_eq_mul]
by_cases h : 0 < (s.sup p) v
· simp_rw [(lt_div_iff₀ h).symm]
rw [← _root_.ball_zero_eq]
exact Metric.ball_mem_nhds 0 (div_pos hr h)
simp_rw [le_antisymm (not_lt.mp h) (apply_nonneg _ v), mul_zero, hr]
exact IsOpen.mem_nhds isOpen_univ (mem_univ 0)
variable [Nonempty ι]
theorem basisSets_smul (U) (hU : U ∈ p.basisSets) :
∃ V ∈ 𝓝 (0 : 𝕜), ∃ W ∈ p.addGroupFilterBasis.sets, V • W ⊆ U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
refine ⟨Metric.ball 0 √r, Metric.ball_mem_nhds 0 (Real.sqrt_pos.mpr hr), ?_⟩
refine ⟨(s.sup p).ball 0 √r, p.basisSets_mem s (Real.sqrt_pos.mpr hr), ?_⟩
refine Set.Subset.trans (ball_smul_ball (s.sup p) √r √r) ?_
rw [hU, Real.mul_self_sqrt (le_of_lt hr)]
theorem basisSets_smul_left (x : 𝕜) (U : Set E) (hU : U ∈ p.basisSets) :
∃ V ∈ p.addGroupFilterBasis.sets, V ⊆ (fun y : E => x • y) ⁻¹' U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
rw [hU]
by_cases h : x ≠ 0
· rw [(s.sup p).smul_ball_preimage 0 r x h, smul_zero]
use (s.sup p).ball 0 (r / ‖x‖)
exact ⟨p.basisSets_mem s (div_pos hr (norm_pos_iff.mpr h)), Subset.rfl⟩
refine ⟨(s.sup p).ball 0 r, p.basisSets_mem s hr, ?_⟩
simp only [not_ne_iff.mp h, Set.subset_def, mem_ball_zero, hr, mem_univ, map_zero, imp_true_iff,
preimage_const_of_mem, zero_smul]
/-- The `moduleFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/
protected def moduleFilterBasis : ModuleFilterBasis 𝕜 E where
toAddGroupFilterBasis := p.addGroupFilterBasis
smul' := p.basisSets_smul _
smul_left' := p.basisSets_smul_left
smul_right' := p.basisSets_smul_right
theorem filter_eq_iInf (p : SeminormFamily 𝕜 E ι) :
p.moduleFilterBasis.toFilterBasis.filter = ⨅ i, (𝓝 0).comap (p i) := by
refine le_antisymm (le_iInf fun i => ?_) ?_
· rw [p.moduleFilterBasis.toFilterBasis.hasBasis.le_basis_iff
(Metric.nhds_basis_ball.comap _)]
intro ε hε
refine ⟨(p i).ball 0 ε, ?_, ?_⟩
· rw [← (Finset.sup_singleton : _ = p i)]
exact p.basisSets_mem {i} hε
· rw [id, (p i).ball_zero_eq_preimage_ball]
· rw [p.moduleFilterBasis.toFilterBasis.hasBasis.ge_iff]
rintro U (hU : U ∈ p.basisSets)
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, rfl⟩
rw [id, Seminorm.ball_finset_sup_eq_iInter _ _ _ hr, s.iInter_mem_sets]
exact fun i _ =>
Filter.mem_iInf_of_mem i
⟨Metric.ball 0 r, Metric.ball_mem_nhds 0 hr,
Eq.subset (p i).ball_zero_eq_preimage_ball.symm⟩
/-- If a family of seminorms is continuous, then their basis sets are neighborhoods of zero. -/
lemma basisSets_mem_nhds {𝕜 E ι : Type*} [NormedField 𝕜]
[AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] (p : SeminormFamily 𝕜 E ι)
(hp : ∀ i, Continuous (p i)) (U : Set E) (hU : U ∈ p.basisSets) : U ∈ 𝓝 (0 : E) := by
obtain ⟨s, r, hr, rfl⟩ := p.basisSets_iff.mp hU
clear hU
refine Seminorm.ball_mem_nhds ?_ hr
classical
induction s using Finset.induction_on
case empty => simpa using continuous_zero
case insert a s _ hs =>
simp only [Finset.sup_insert, coe_sup]
exact Continuous.max (hp a) hs
end SeminormFamily
end FilterBasis
section Bounded
namespace Seminorm
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E]
variable [NormedField 𝕜₂] [AddCommGroup F] [Module 𝕜₂ F]
variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂]
-- Todo: This should be phrased entirely in terms of the von Neumann bornology.
/-- The proposition that a linear map is bounded between spaces with families of seminorms. -/
def IsBounded (p : ι → Seminorm 𝕜 E) (q : ι' → Seminorm 𝕜₂ F) (f : E →ₛₗ[σ₁₂] F) : Prop :=
∀ i, ∃ s : Finset ι, ∃ C : ℝ≥0, (q i).comp f ≤ C • s.sup p
theorem isBounded_const (ι' : Type*) [Nonempty ι'] {p : ι → Seminorm 𝕜 E} {q : Seminorm 𝕜₂ F}
(f : E →ₛₗ[σ₁₂] F) :
IsBounded p (fun _ : ι' => q) f ↔ ∃ (s : Finset ι) (C : ℝ≥0), q.comp f ≤ C • s.sup p := by
simp only [IsBounded, forall_const]
theorem const_isBounded (ι : Type*) [Nonempty ι] {p : Seminorm 𝕜 E} {q : ι' → Seminorm 𝕜₂ F}
(f : E →ₛₗ[σ₁₂] F) : IsBounded (fun _ : ι => p) q f ↔ ∀ i, ∃ C : ℝ≥0, (q i).comp f ≤ C • p := by
constructor <;> intro h i
· rcases h i with ⟨s, C, h⟩
exact ⟨C, le_trans h (smul_le_smul (Finset.sup_le fun _ _ => le_rfl) le_rfl)⟩
use {Classical.arbitrary ι}
simp only [h, Finset.sup_singleton]
theorem isBounded_sup {p : ι → Seminorm 𝕜 E} {q : ι' → Seminorm 𝕜₂ F} {f : E →ₛₗ[σ₁₂] F}
(hf : IsBounded p q f) (s' : Finset ι') :
∃ (C : ℝ≥0) (s : Finset ι), (s'.sup q).comp f ≤ C • s.sup p := by
classical
obtain rfl | _ := s'.eq_empty_or_nonempty
· exact ⟨1, ∅, by simp [Seminorm.bot_eq_zero]⟩
choose fₛ fC hf using hf
use s'.card • s'.sup fC, Finset.biUnion s' fₛ
have hs : ∀ i : ι', i ∈ s' → (q i).comp f ≤ s'.sup fC • (Finset.biUnion s' fₛ).sup p := by
intro i hi
refine (hf i).trans (smul_le_smul ?_ (Finset.le_sup hi))
exact Finset.sup_mono (Finset.subset_biUnion_of_mem fₛ hi)
refine (comp_mono f (finset_sup_le_sum q s')).trans ?_
simp_rw [← pullback_apply, map_sum, pullback_apply]
refine (Finset.sum_le_sum hs).trans ?_
rw [Finset.sum_const, smul_assoc]
end Seminorm
end Bounded
section Topology
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [Nonempty ι]
/-- The proposition that the topology of `E` is induced by a family of seminorms `p`. -/
structure WithSeminorms (p : SeminormFamily 𝕜 E ι) [topology : TopologicalSpace E] : Prop where
topology_eq_withSeminorms : topology = p.moduleFilterBasis.topology
theorem WithSeminorms.withSeminorms_eq {p : SeminormFamily 𝕜 E ι} [t : TopologicalSpace E]
(hp : WithSeminorms p) : t = p.moduleFilterBasis.topology :=
hp.1
variable [TopologicalSpace E]
variable {p : SeminormFamily 𝕜 E ι}
theorem WithSeminorms.topologicalAddGroup (hp : WithSeminorms p) : IsTopologicalAddGroup E := by
rw [hp.withSeminorms_eq]
exact AddGroupFilterBasis.isTopologicalAddGroup _
theorem WithSeminorms.continuousSMul (hp : WithSeminorms p) : ContinuousSMul 𝕜 E := by
rw [hp.withSeminorms_eq]
exact ModuleFilterBasis.continuousSMul _
theorem WithSeminorms.hasBasis (hp : WithSeminorms p) :
(𝓝 (0 : E)).HasBasis (fun s : Set E => s ∈ p.basisSets) id := by
rw [congr_fun (congr_arg (@nhds E) hp.1) 0]
exact AddGroupFilterBasis.nhds_zero_hasBasis _
theorem WithSeminorms.hasBasis_zero_ball (hp : WithSeminorms p) :
(𝓝 (0 : E)).HasBasis
(fun sr : Finset ι × ℝ => 0 < sr.2) fun sr => (sr.1.sup p).ball 0 sr.2 := by
refine ⟨fun V => ?_⟩
simp only [hp.hasBasis.mem_iff, SeminormFamily.basisSets_iff, Prod.exists]
constructor
· rintro ⟨-, ⟨s, r, hr, rfl⟩, hV⟩
exact ⟨s, r, hr, hV⟩
· rintro ⟨s, r, hr, hV⟩
exact ⟨_, ⟨s, r, hr, rfl⟩, hV⟩
theorem WithSeminorms.hasBasis_ball (hp : WithSeminorms p) {x : E} :
(𝓝 (x : E)).HasBasis
(fun sr : Finset ι × ℝ => 0 < sr.2) fun sr => (sr.1.sup p).ball x sr.2 := by
have : IsTopologicalAddGroup E := hp.topologicalAddGroup
rw [← map_add_left_nhds_zero]
convert hp.hasBasis_zero_ball.map (x + ·) using 1
ext sr : 1
-- Porting note: extra type ascriptions needed on `0`
have : (sr.fst.sup p).ball (x +ᵥ (0 : E)) sr.snd = x +ᵥ (sr.fst.sup p).ball 0 sr.snd :=
Eq.symm (Seminorm.vadd_ball (sr.fst.sup p))
rwa [vadd_eq_add, add_zero] at this
/-- The `x`-neighbourhoods of a space whose topology is induced by a family of seminorms
are exactly the sets which contain seminorm balls around `x`. -/
theorem WithSeminorms.mem_nhds_iff (hp : WithSeminorms p) (x : E) (U : Set E) :
U ∈ 𝓝 x ↔ ∃ s : Finset ι, ∃ r > 0, (s.sup p).ball x r ⊆ U := by
rw [hp.hasBasis_ball.mem_iff, Prod.exists]
/-- The open sets of a space whose topology is induced by a family of seminorms
are exactly the sets which contain seminorm balls around all of their points. -/
theorem WithSeminorms.isOpen_iff_mem_balls (hp : WithSeminorms p) (U : Set E) :
IsOpen U ↔ ∀ x ∈ U, ∃ s : Finset ι, ∃ r > 0, (s.sup p).ball x r ⊆ U := by
simp_rw [← WithSeminorms.mem_nhds_iff hp _ U, isOpen_iff_mem_nhds]
/- Note that through the following lemmas, one also immediately has that separating families
of seminorms induce T₂ and T₃ topologies by `IsTopologicalAddGroup.t2Space`
and `IsTopologicalAddGroup.t3Space` -/
/-- A separating family of seminorms induces a T₁ topology. -/
theorem WithSeminorms.T1_of_separating (hp : WithSeminorms p)
(h : ∀ x, x ≠ 0 → ∃ i, p i x ≠ 0) : T1Space E := by
have := hp.topologicalAddGroup
refine IsTopologicalAddGroup.t1Space _ ?_
rw [← isOpen_compl_iff, hp.isOpen_iff_mem_balls]
rintro x (hx : x ≠ 0)
obtain ⟨i, pi_nonzero⟩ := h x hx
refine ⟨{i}, p i x, by positivity, subset_compl_singleton_iff.mpr ?_⟩
rw [Finset.sup_singleton, mem_ball, zero_sub, map_neg_eq_map, not_lt]
/-- A family of seminorms inducing a T₁ topology is separating. -/
theorem WithSeminorms.separating_of_T1 [T1Space E] (hp : WithSeminorms p) (x : E) (hx : x ≠ 0) :
∃ i, p i x ≠ 0 := by
have := ((t1Space_TFAE E).out 0 9).mp (inferInstanceAs <| T1Space E)
by_contra! h
refine hx (this ?_)
rw [hp.hasBasis_zero_ball.specializes_iff]
rintro ⟨s, r⟩ (hr : 0 < r)
simp only [ball_finset_sup_eq_iInter _ _ _ hr, mem_iInter₂, mem_ball_zero, h, hr, forall_true_iff]
/-- A family of seminorms is separating iff it induces a T₁ topology. -/
theorem WithSeminorms.separating_iff_T1 (hp : WithSeminorms p) :
(∀ x, x ≠ 0 → ∃ i, p i x ≠ 0) ↔ T1Space E := by
refine ⟨WithSeminorms.T1_of_separating hp, ?_⟩
intro
exact WithSeminorms.separating_of_T1 hp
end Topology
section Tendsto
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [Nonempty ι] [TopologicalSpace E]
variable {p : SeminormFamily 𝕜 E ι}
/-- Convergence along filters for `WithSeminorms`.
Variant with `Finset.sup`. -/
theorem WithSeminorms.tendsto_nhds' (hp : WithSeminorms p) (u : F → E) {f : Filter F} (y₀ : E) :
Filter.Tendsto u f (𝓝 y₀) ↔
∀ (s : Finset ι) (ε), 0 < ε → ∀ᶠ x in f, s.sup p (u x - y₀) < ε := by
simp [hp.hasBasis_ball.tendsto_right_iff]
/-- Convergence along filters for `WithSeminorms`. -/
theorem WithSeminorms.tendsto_nhds (hp : WithSeminorms p) (u : F → E) {f : Filter F} (y₀ : E) :
Filter.Tendsto u f (𝓝 y₀) ↔ ∀ i ε, 0 < ε → ∀ᶠ x in f, p i (u x - y₀) < ε := by
rw [hp.tendsto_nhds' u y₀]
exact
⟨fun h i => by simpa only [Finset.sup_singleton] using h {i}, fun h s ε hε =>
(s.eventually_all.2 fun i _ => h i ε hε).mono fun _ => finset_sup_apply_lt hε⟩
variable [SemilatticeSup F] [Nonempty F]
/-- Limit `→ ∞` for `WithSeminorms`. -/
theorem WithSeminorms.tendsto_nhds_atTop (hp : WithSeminorms p) (u : F → E) (y₀ : E) :
Filter.Tendsto u Filter.atTop (𝓝 y₀) ↔
∀ i ε, 0 < ε → ∃ x₀, ∀ x, x₀ ≤ x → p i (u x - y₀) < ε := by
rw [hp.tendsto_nhds u y₀]
exact forall₃_congr fun _ _ _ => Filter.eventually_atTop
end Tendsto
section IsTopologicalAddGroup
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E]
variable [Nonempty ι]
section TopologicalSpace
variable [t : TopologicalSpace E]
theorem SeminormFamily.withSeminorms_of_nhds [IsTopologicalAddGroup E] (p : SeminormFamily 𝕜 E ι)
(h : 𝓝 (0 : E) = p.moduleFilterBasis.toFilterBasis.filter) : WithSeminorms p := by
refine
⟨IsTopologicalAddGroup.ext inferInstance p.addGroupFilterBasis.isTopologicalAddGroup ?_⟩
rw [AddGroupFilterBasis.nhds_zero_eq]
exact h
theorem SeminormFamily.withSeminorms_of_hasBasis [IsTopologicalAddGroup E]
(p : SeminormFamily 𝕜 E ι) (h : (𝓝 (0 : E)).HasBasis (fun s : Set E => s ∈ p.basisSets) id) :
WithSeminorms p :=
p.withSeminorms_of_nhds <|
Filter.HasBasis.eq_of_same_basis h p.addGroupFilterBasis.toFilterBasis.hasBasis
theorem SeminormFamily.withSeminorms_iff_nhds_eq_iInf [IsTopologicalAddGroup E]
(p : SeminormFamily 𝕜 E ι) : WithSeminorms p ↔ (𝓝 (0 : E)) = ⨅ i, (𝓝 0).comap (p i) := by
rw [← p.filter_eq_iInf]
refine ⟨fun h => ?_, p.withSeminorms_of_nhds⟩
rw [h.topology_eq_withSeminorms]
exact AddGroupFilterBasis.nhds_zero_eq _
/-- The topology induced by a family of seminorms is exactly the infimum of the ones induced by
each seminorm individually. We express this as a characterization of `WithSeminorms p`. -/
theorem SeminormFamily.withSeminorms_iff_topologicalSpace_eq_iInf [IsTopologicalAddGroup E]
(p : SeminormFamily 𝕜 E ι) :
WithSeminorms p ↔
t = ⨅ i, (p i).toSeminormedAddCommGroup.toUniformSpace.toTopologicalSpace := by
rw [p.withSeminorms_iff_nhds_eq_iInf,
IsTopologicalAddGroup.ext_iff inferInstance (topologicalAddGroup_iInf fun i => inferInstance),
nhds_iInf]
congrm _ = ⨅ i, ?_
exact @comap_norm_nhds_zero _ (p i).toSeminormedAddGroup
theorem WithSeminorms.continuous_seminorm {p : SeminormFamily 𝕜 E ι} (hp : WithSeminorms p)
(i : ι) : Continuous (p i) := by
have := hp.topologicalAddGroup
rw [p.withSeminorms_iff_topologicalSpace_eq_iInf.mp hp]
exact continuous_iInf_dom (@continuous_norm _ (p i).toSeminormedAddGroup)
end TopologicalSpace
/-- The uniform structure induced by a family of seminorms is exactly the infimum of the ones
induced by each seminorm individually. We express this as a characterization of
`WithSeminorms p`. -/
theorem SeminormFamily.withSeminorms_iff_uniformSpace_eq_iInf [u : UniformSpace E]
[IsUniformAddGroup E] (p : SeminormFamily 𝕜 E ι) :
WithSeminorms p ↔ u = ⨅ i, (p i).toSeminormedAddCommGroup.toUniformSpace := by
rw [p.withSeminorms_iff_nhds_eq_iInf,
IsUniformAddGroup.ext_iff inferInstance (isUniformAddGroup_iInf fun i => inferInstance),
UniformSpace.toTopologicalSpace_iInf, nhds_iInf]
congrm _ = ⨅ i, ?_
exact @comap_norm_nhds_zero _ (p i).toAddGroupSeminorm.toSeminormedAddGroup
end IsTopologicalAddGroup
section NormedSpace
/-- The topology of a `NormedSpace 𝕜 E` is induced by the seminorm `normSeminorm 𝕜 E`. -/
| Mathlib/Analysis/LocallyConvex/WithSeminorms.lean | 451 | 455 | theorem norm_withSeminorms (𝕜 E) [NormedField 𝕜] [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] :
WithSeminorms fun _ : Fin 1 => normSeminorm 𝕜 E := by | let p : SeminormFamily 𝕜 E (Fin 1) := fun _ => normSeminorm 𝕜 E
refine
⟨SeminormedAddCommGroup.toIsTopologicalAddGroup.ext |
/-
Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Bryan Gin-ge Chen, Yaël Dillies
-/
import Mathlib.Order.BooleanAlgebra
import Mathlib.Logic.Equiv.Basic
/-!
# Symmetric difference and bi-implication
This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras.
## Examples
Some examples are
* The symmetric difference of two sets is the set of elements that are in either but not both.
* The symmetric difference on propositions is `Xor'`.
* The symmetric difference on `Bool` is `Bool.xor`.
* The equivalence of propositions. Two propositions are equivalent if they imply each other.
* The symmetric difference translates to addition when considering a Boolean algebra as a Boolean
ring.
## Main declarations
* `symmDiff`: The symmetric difference operator, defined as `(a \ b) ⊔ (b \ a)`
* `bihimp`: The bi-implication operator, defined as `(b ⇨ a) ⊓ (a ⇨ b)`
In generalized Boolean algebras, the symmetric difference operator is:
* `symmDiff_comm`: commutative, and
* `symmDiff_assoc`: associative.
## Notations
* `a ∆ b`: `symmDiff a b`
* `a ⇔ b`: `bihimp a b`
## References
The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A
Proof from the Book" by John McCuan:
* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>
## Tags
boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication,
Heyting
-/
assert_not_exists RelIso
open Function OrderDual
variable {ι α β : Type*} {π : ι → Type*}
/-- The symmetric difference operator on a type with `⊔` and `\` is `(A \ B) ⊔ (B \ A)`. -/
def symmDiff [Max α] [SDiff α] (a b : α) : α :=
a \ b ⊔ b \ a
/-- The Heyting bi-implication is `(b ⇨ a) ⊓ (a ⇨ b)`. This generalizes equivalence of
propositions. -/
def bihimp [Min α] [HImp α] (a b : α) : α :=
(b ⇨ a) ⊓ (a ⇨ b)
/-- Notation for symmDiff -/
scoped[symmDiff] infixl:100 " ∆ " => symmDiff
/-- Notation for bihimp -/
scoped[symmDiff] infixl:100 " ⇔ " => bihimp
open scoped symmDiff
theorem symmDiff_def [Max α] [SDiff α] (a b : α) : a ∆ b = a \ b ⊔ b \ a :=
rfl
theorem bihimp_def [Min α] [HImp α] (a b : α) : a ⇔ b = (b ⇨ a) ⊓ (a ⇨ b) :=
rfl
theorem symmDiff_eq_Xor' (p q : Prop) : p ∆ q = Xor' p q :=
rfl
@[simp]
theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) :=
iff_iff_implies_and_implies.symm.trans Iff.comm
@[simp]
theorem Bool.symmDiff_eq_xor : ∀ p q : Bool, p ∆ q = xor p q := by decide
section GeneralizedCoheytingAlgebra
variable [GeneralizedCoheytingAlgebra α] (a b c : α)
@[simp]
theorem toDual_symmDiff : toDual (a ∆ b) = toDual a ⇔ toDual b :=
rfl
@[simp]
theorem ofDual_bihimp (a b : αᵒᵈ) : ofDual (a ⇔ b) = ofDual a ∆ ofDual b :=
rfl
theorem symmDiff_comm : a ∆ b = b ∆ a := by simp only [symmDiff, sup_comm]
instance symmDiff_isCommutative : Std.Commutative (α := α) (· ∆ ·) :=
⟨symmDiff_comm⟩
@[simp]
theorem symmDiff_self : a ∆ a = ⊥ := by rw [symmDiff, sup_idem, sdiff_self]
@[simp]
theorem symmDiff_bot : a ∆ ⊥ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq]
@[simp]
theorem bot_symmDiff : ⊥ ∆ a = a := by rw [symmDiff_comm, symmDiff_bot]
@[simp]
theorem symmDiff_eq_bot {a b : α} : a ∆ b = ⊥ ↔ a = b := by
simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff]
theorem symmDiff_of_le {a b : α} (h : a ≤ b) : a ∆ b = b \ a := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq]
theorem symmDiff_of_ge {a b : α} (h : b ≤ a) : a ∆ b = a \ b := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq]
theorem symmDiff_le {a b c : α} (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ∆ b ≤ c :=
sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb
theorem symmDiff_le_iff {a b c : α} : a ∆ b ≤ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := by
simp_rw [symmDiff, sup_le_iff, sdiff_le_iff]
@[simp]
theorem symmDiff_le_sup {a b : α} : a ∆ b ≤ a ⊔ b :=
sup_le_sup sdiff_le sdiff_le
theorem symmDiff_eq_sup_sdiff_inf : a ∆ b = (a ⊔ b) \ (a ⊓ b) := by simp [sup_sdiff, symmDiff]
theorem Disjoint.symmDiff_eq_sup {a b : α} (h : Disjoint a b) : a ∆ b = a ⊔ b := by
rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right]
theorem symmDiff_sdiff : a ∆ b \ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) := by
rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left]
@[simp]
theorem symmDiff_sdiff_inf : a ∆ b \ (a ⊓ b) = a ∆ b := by
rw [symmDiff_sdiff]
simp [symmDiff]
@[simp]
theorem symmDiff_sdiff_eq_sup : a ∆ (b \ a) = a ⊔ b := by
rw [symmDiff, sdiff_idem]
exact
le_antisymm (sup_le_sup sdiff_le sdiff_le)
(sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup)
@[simp]
theorem sdiff_symmDiff_eq_sup : (a \ b) ∆ b = a ⊔ b := by
rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm]
@[simp]
theorem symmDiff_sup_inf : a ∆ b ⊔ a ⊓ b = a ⊔ b := by
refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_
rw [sup_inf_left, symmDiff]
refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right)
· rw [sup_right_comm]
exact le_sup_of_le_left le_sdiff_sup
· rw [sup_assoc]
exact le_sup_of_le_right le_sdiff_sup
@[simp]
theorem inf_sup_symmDiff : a ⊓ b ⊔ a ∆ b = a ⊔ b := by rw [sup_comm, symmDiff_sup_inf]
@[simp]
theorem symmDiff_symmDiff_inf : a ∆ b ∆ (a ⊓ b) = a ⊔ b := by
rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf]
@[simp]
theorem inf_symmDiff_symmDiff : (a ⊓ b) ∆ (a ∆ b) = a ⊔ b := by
rw [symmDiff_comm, symmDiff_symmDiff_inf]
theorem symmDiff_triangle : a ∆ c ≤ a ∆ b ⊔ b ∆ c := by
refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_
rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff]
theorem le_symmDiff_sup_right (a b : α) : a ≤ (a ∆ b) ⊔ b := by
convert symmDiff_triangle a b ⊥ <;> rw [symmDiff_bot]
theorem le_symmDiff_sup_left (a b : α) : b ≤ (a ∆ b) ⊔ a :=
symmDiff_comm a b ▸ le_symmDiff_sup_right ..
end GeneralizedCoheytingAlgebra
section GeneralizedHeytingAlgebra
variable [GeneralizedHeytingAlgebra α] (a b c : α)
@[simp]
theorem toDual_bihimp : toDual (a ⇔ b) = toDual a ∆ toDual b :=
rfl
@[simp]
theorem ofDual_symmDiff (a b : αᵒᵈ) : ofDual (a ∆ b) = ofDual a ⇔ ofDual b :=
rfl
theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(· ⇔ ·), inf_comm]
instance bihimp_isCommutative : Std.Commutative (α := α) (· ⇔ ·) :=
⟨bihimp_comm⟩
@[simp]
theorem bihimp_self : a ⇔ a = ⊤ := by rw [bihimp, inf_idem, himp_self]
@[simp]
theorem bihimp_top : a ⇔ ⊤ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq]
@[simp]
theorem top_bihimp : ⊤ ⇔ a = a := by rw [bihimp_comm, bihimp_top]
@[simp]
theorem bihimp_eq_top {a b : α} : a ⇔ b = ⊤ ↔ a = b :=
@symmDiff_eq_bot αᵒᵈ _ _ _
theorem bihimp_of_le {a b : α} (h : a ≤ b) : a ⇔ b = b ⇨ a := by
rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq]
theorem bihimp_of_ge {a b : α} (h : b ≤ a) : a ⇔ b = a ⇨ b := by
rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq]
theorem le_bihimp {a b c : α} (hb : a ⊓ b ≤ c) (hc : a ⊓ c ≤ b) : a ≤ b ⇔ c :=
le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb
theorem le_bihimp_iff {a b c : α} : a ≤ b ⇔ c ↔ a ⊓ b ≤ c ∧ a ⊓ c ≤ b := by
simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm]
@[simp]
theorem inf_le_bihimp {a b : α} : a ⊓ b ≤ a ⇔ b :=
inf_le_inf le_himp le_himp
theorem bihimp_eq_inf_himp_inf : a ⇔ b = a ⊔ b ⇨ a ⊓ b := by simp [himp_inf_distrib, bihimp]
theorem Codisjoint.bihimp_eq_inf {a b : α} (h : Codisjoint a b) : a ⇔ b = a ⊓ b := by
rw [bihimp, h.himp_eq_left, h.himp_eq_right]
theorem himp_bihimp : a ⇨ b ⇔ c = (a ⊓ c ⇨ b) ⊓ (a ⊓ b ⇨ c) := by
rw [bihimp, himp_inf_distrib, himp_himp, himp_himp]
@[simp]
theorem sup_himp_bihimp : a ⊔ b ⇨ a ⇔ b = a ⇔ b := by
rw [himp_bihimp]
simp [bihimp]
@[simp]
theorem bihimp_himp_eq_inf : a ⇔ (a ⇨ b) = a ⊓ b :=
@symmDiff_sdiff_eq_sup αᵒᵈ _ _ _
@[simp]
theorem himp_bihimp_eq_inf : (b ⇨ a) ⇔ b = a ⊓ b :=
@sdiff_symmDiff_eq_sup αᵒᵈ _ _ _
@[simp]
theorem bihimp_inf_sup : a ⇔ b ⊓ (a ⊔ b) = a ⊓ b :=
@symmDiff_sup_inf αᵒᵈ _ _ _
@[simp]
theorem sup_inf_bihimp : (a ⊔ b) ⊓ a ⇔ b = a ⊓ b :=
@inf_sup_symmDiff αᵒᵈ _ _ _
@[simp]
theorem bihimp_bihimp_sup : a ⇔ b ⇔ (a ⊔ b) = a ⊓ b :=
@symmDiff_symmDiff_inf αᵒᵈ _ _ _
@[simp]
theorem sup_bihimp_bihimp : (a ⊔ b) ⇔ (a ⇔ b) = a ⊓ b :=
@inf_symmDiff_symmDiff αᵒᵈ _ _ _
theorem bihimp_triangle : a ⇔ b ⊓ b ⇔ c ≤ a ⇔ c :=
@symmDiff_triangle αᵒᵈ _ _ _ _
end GeneralizedHeytingAlgebra
section CoheytingAlgebra
variable [CoheytingAlgebra α] (a : α)
@[simp]
theorem symmDiff_top' : a ∆ ⊤ = ¬a := by simp [symmDiff]
@[simp]
theorem top_symmDiff' : ⊤ ∆ a = ¬a := by simp [symmDiff]
@[simp]
theorem hnot_symmDiff_self : (¬a) ∆ a = ⊤ := by
rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self]
exact Codisjoint.top_le codisjoint_hnot_left
@[simp]
theorem symmDiff_hnot_self : a ∆ (¬a) = ⊤ := by rw [symmDiff_comm, hnot_symmDiff_self]
theorem IsCompl.symmDiff_eq_top {a b : α} (h : IsCompl a b) : a ∆ b = ⊤ := by
rw [h.eq_hnot, hnot_symmDiff_self]
end CoheytingAlgebra
section HeytingAlgebra
variable [HeytingAlgebra α] (a : α)
@[simp]
theorem bihimp_bot : a ⇔ ⊥ = aᶜ := by simp [bihimp]
@[simp]
theorem bot_bihimp : ⊥ ⇔ a = aᶜ := by simp [bihimp]
@[simp]
theorem compl_bihimp_self : aᶜ ⇔ a = ⊥ :=
@hnot_symmDiff_self αᵒᵈ _ _
@[simp]
theorem bihimp_hnot_self : a ⇔ aᶜ = ⊥ :=
@symmDiff_hnot_self αᵒᵈ _ _
theorem IsCompl.bihimp_eq_bot {a b : α} (h : IsCompl a b) : a ⇔ b = ⊥ := by
rw [h.eq_compl, compl_bihimp_self]
end HeytingAlgebra
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra α] (a b c d : α)
@[simp]
theorem sup_sdiff_symmDiff : (a ⊔ b) \ a ∆ b = a ⊓ b :=
sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf])
theorem disjoint_symmDiff_inf : Disjoint (a ∆ b) (a ⊓ b) := by
rw [symmDiff_eq_sup_sdiff_inf]
exact disjoint_sdiff_self_left
theorem inf_symmDiff_distrib_left : a ⊓ b ∆ c = (a ⊓ b) ∆ (a ⊓ c) := by
rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left,
symmDiff_eq_sup_sdiff_inf]
theorem inf_symmDiff_distrib_right : a ∆ b ⊓ c = (a ⊓ c) ∆ (b ⊓ c) := by
simp_rw [inf_comm _ c, inf_symmDiff_distrib_left]
theorem sdiff_symmDiff : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ a ⊓ c \ b := by
simp only [(· ∆ ·), sdiff_sdiff_sup_sdiff']
theorem sdiff_symmDiff' : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ (a ⊔ b) := by
rw [sdiff_symmDiff, sdiff_sup]
@[simp]
theorem symmDiff_sdiff_left : a ∆ b \ a = b \ a := by
rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq]
@[simp]
theorem symmDiff_sdiff_right : a ∆ b \ b = a \ b := by rw [symmDiff_comm, symmDiff_sdiff_left]
@[simp]
theorem sdiff_symmDiff_left : a \ a ∆ b = a ⊓ b := by simp [sdiff_symmDiff]
@[simp]
theorem sdiff_symmDiff_right : b \ a ∆ b = a ⊓ b := by
rw [symmDiff_comm, inf_comm, sdiff_symmDiff_left]
theorem symmDiff_eq_sup : a ∆ b = a ⊔ b ↔ Disjoint a b := by
refine ⟨fun h => ?_, Disjoint.symmDiff_eq_sup⟩
rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h
exact h.of_disjoint_inf_of_le le_sup_left
@[simp]
theorem le_symmDiff_iff_left : a ≤ a ∆ b ↔ Disjoint a b := by
refine ⟨fun h => ?_, fun h => h.symmDiff_eq_sup.symm ▸ le_sup_left⟩
rw [symmDiff_eq_sup_sdiff_inf] at h
exact disjoint_iff_inf_le.mpr (le_sdiff_right.1 <| inf_le_of_left_le h).le
@[simp]
theorem le_symmDiff_iff_right : b ≤ a ∆ b ↔ Disjoint a b := by
rw [symmDiff_comm, le_symmDiff_iff_left, disjoint_comm]
theorem symmDiff_symmDiff_left :
a ∆ b ∆ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c :=
calc
a ∆ b ∆ c = a ∆ b \ c ⊔ c \ a ∆ b := symmDiff_def _ _
_ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ (c \ (a ⊔ b) ⊔ c ⊓ a ⊓ b) := by
{ rw [sdiff_symmDiff', sup_comm (c ⊓ a ⊓ b), symmDiff_sdiff] }
_ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := by ac_rfl
theorem symmDiff_symmDiff_right :
a ∆ (b ∆ c) = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c :=
calc
a ∆ (b ∆ c) = a \ b ∆ c ⊔ b ∆ c \ a := symmDiff_def _ _
_ = a \ (b ⊔ c) ⊔ a ⊓ b ⊓ c ⊔ (b \ (c ⊔ a) ⊔ c \ (b ⊔ a)) := by
{ rw [sdiff_symmDiff', sup_comm (a ⊓ b ⊓ c), symmDiff_sdiff] }
_ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := by ac_rfl
theorem symmDiff_assoc : a ∆ b ∆ c = a ∆ (b ∆ c) := by
rw [symmDiff_symmDiff_left, symmDiff_symmDiff_right]
instance symmDiff_isAssociative : Std.Associative (α := α) (· ∆ ·) :=
⟨symmDiff_assoc⟩
theorem symmDiff_left_comm : a ∆ (b ∆ c) = b ∆ (a ∆ c) := by
simp_rw [← symmDiff_assoc, symmDiff_comm]
theorem symmDiff_right_comm : a ∆ b ∆ c = a ∆ c ∆ b := by simp_rw [symmDiff_assoc, symmDiff_comm]
theorem symmDiff_symmDiff_symmDiff_comm : a ∆ b ∆ (c ∆ d) = a ∆ c ∆ (b ∆ d) := by
simp_rw [symmDiff_assoc, symmDiff_left_comm]
@[simp]
theorem symmDiff_symmDiff_cancel_left : a ∆ (a ∆ b) = b := by simp [← symmDiff_assoc]
@[simp]
theorem symmDiff_symmDiff_cancel_right : b ∆ a ∆ a = b := by simp [symmDiff_assoc]
@[simp]
theorem symmDiff_symmDiff_self' : a ∆ b ∆ a = b := by
rw [symmDiff_comm, symmDiff_symmDiff_cancel_left]
theorem symmDiff_left_involutive (a : α) : Involutive (· ∆ a) :=
symmDiff_symmDiff_cancel_right _
theorem symmDiff_right_involutive (a : α) : Involutive (a ∆ ·) :=
symmDiff_symmDiff_cancel_left _
theorem symmDiff_left_injective (a : α) : Injective (· ∆ a) :=
Function.Involutive.injective (symmDiff_left_involutive a)
theorem symmDiff_right_injective (a : α) : Injective (a ∆ ·) :=
Function.Involutive.injective (symmDiff_right_involutive _)
theorem symmDiff_left_surjective (a : α) : Surjective (· ∆ a) :=
Function.Involutive.surjective (symmDiff_left_involutive _)
theorem symmDiff_right_surjective (a : α) : Surjective (a ∆ ·) :=
Function.Involutive.surjective (symmDiff_right_involutive _)
variable {a b c}
@[simp]
theorem symmDiff_left_inj : a ∆ b = c ∆ b ↔ a = c :=
(symmDiff_left_injective _).eq_iff
@[simp]
theorem symmDiff_right_inj : a ∆ b = a ∆ c ↔ b = c :=
(symmDiff_right_injective _).eq_iff
@[simp]
theorem symmDiff_eq_left : a ∆ b = a ↔ b = ⊥ :=
calc
a ∆ b = a ↔ a ∆ b = a ∆ ⊥ := by rw [symmDiff_bot]
_ ↔ b = ⊥ := by rw [symmDiff_right_inj]
@[simp]
| Mathlib/Order/SymmDiff.lean | 457 | 458 | theorem symmDiff_eq_right : a ∆ b = b ↔ a = ⊥ := by | rw [symmDiff_comm, symmDiff_eq_left] |
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Order.Interval.Set.OrdConnected
import Mathlib.Data.Set.Lattice.Image
/-!
# Order connected components of a set
In this file we define `Set.ordConnectedComponent s x` to be the set of `y` such that
`Set.uIcc x y ⊆ s` and prove some basic facts about this definition. At the moment of writing,
this construction is used only to prove that any linear order with order topology is a T₅ space,
so we only add API needed for this lemma.
-/
open Interval Function OrderDual
namespace Set
variable {α : Type*} [LinearOrder α] {s t : Set α} {x y z : α}
/-- Order-connected component of a point `x` in a set `s`. It is defined as the set of `y` such that
`Set.uIcc x y ⊆ s`. Note that it is empty if and only if `x ∉ s`. -/
def ordConnectedComponent (s : Set α) (x : α) : Set α :=
{ y | [[x, y]] ⊆ s }
theorem mem_ordConnectedComponent : y ∈ ordConnectedComponent s x ↔ [[x, y]] ⊆ s :=
Iff.rfl
theorem dual_ordConnectedComponent :
ordConnectedComponent (ofDual ⁻¹' s) (toDual x) = ofDual ⁻¹' ordConnectedComponent s x :=
ext <| (Surjective.forall toDual.surjective).2 fun x => by simp [mem_ordConnectedComponent]
theorem ordConnectedComponent_subset : ordConnectedComponent s x ⊆ s := fun _ hy =>
hy right_mem_uIcc
theorem subset_ordConnectedComponent {t} [h : OrdConnected s] (hs : x ∈ s) (ht : s ⊆ t) :
s ⊆ ordConnectedComponent t x := fun _ hy => (h.uIcc_subset hs hy).trans ht
@[simp]
theorem self_mem_ordConnectedComponent : x ∈ ordConnectedComponent s x ↔ x ∈ s := by
rw [mem_ordConnectedComponent, uIcc_self, singleton_subset_iff]
@[simp]
theorem nonempty_ordConnectedComponent : (ordConnectedComponent s x).Nonempty ↔ x ∈ s :=
⟨fun ⟨_, hy⟩ => hy <| left_mem_uIcc, fun h => ⟨x, self_mem_ordConnectedComponent.2 h⟩⟩
@[simp]
theorem ordConnectedComponent_eq_empty : ordConnectedComponent s x = ∅ ↔ x ∉ s := by
rw [← not_nonempty_iff_eq_empty, nonempty_ordConnectedComponent]
@[simp]
theorem ordConnectedComponent_empty : ordConnectedComponent ∅ x = ∅ :=
ordConnectedComponent_eq_empty.2 (not_mem_empty x)
@[simp]
theorem ordConnectedComponent_univ : ordConnectedComponent univ x = univ := by
simp [ordConnectedComponent]
| Mathlib/Order/Interval/Set/OrdConnectedComponent.lean | 63 | 64 | theorem ordConnectedComponent_inter (s t : Set α) (x : α) :
ordConnectedComponent (s ∩ t) x = ordConnectedComponent s x ∩ ordConnectedComponent t x := by | |
/-
Copyright (c) 2014 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Bounds.OrderIso
import Mathlib.Tactic.Positivity.Core
/-!
# Lemmas about linear ordered (semi)fields
-/
open Function OrderDual
variable {ι α β : Type*}
section LinearOrderedSemifield
variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a b c d e : α} {m n : ℤ}
/-!
### Relating two divisions.
-/
@[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b := div_le_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := div_lt_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")]
theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b :=
div_lt_div_iff_of_pos_left ha hb hc
@[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")]
theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b :=
div_le_div_iff_of_pos_left ha hb hc
@[deprecated div_lt_div_iff₀ (since := "2024-11-12")]
theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b :=
div_lt_div_iff₀ b0 d0
@[deprecated div_le_div_iff₀ (since := "2024-11-12")]
theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b :=
div_le_div_iff₀ b0 d0
@[deprecated div_le_div₀ (since := "2024-11-12")]
theorem div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d :=
div_le_div₀ hc hac hd hbd
@[deprecated div_lt_div₀ (since := "2024-11-12")]
theorem div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d :=
div_lt_div₀ hac hbd c0 d0
@[deprecated div_lt_div₀' (since := "2024-11-12")]
| Mathlib/Algebra/Order/Field/Basic.lean | 61 | 73 | theorem div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d :=
div_lt_div₀' hac hbd c0 d0
/-!
### Relating one division and involving `1`
-/
@[bound]
theorem div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a := by | simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb
@[bound] |
/-
Copyright (c) 2023 Josha Dekker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Josha Dekker
-/
import Mathlib.Topology.Bases
import Mathlib.Order.Filter.CountableInter
import Mathlib.Topology.Compactness.SigmaCompact
/-!
# Lindelöf sets and Lindelöf spaces
## Main definitions
We define the following properties for sets in a topological space:
* `IsLindelof s`: Two definitions are possible here. The more standard definition is that
every open cover that contains `s` contains a countable subcover. We choose for the equivalent
definition where we require that every nontrivial filter on `s` with the countable intersection
property has a clusterpoint. Equivalence is established in `isLindelof_iff_countable_subcover`.
* `LindelofSpace X`: `X` is Lindelöf if it is Lindelöf as a set.
* `NonLindelofSpace`: a space that is not a Lindëlof space, e.g. the Long Line.
## Main results
* `isLindelof_iff_countable_subcover`: A set is Lindelöf iff every open cover has a
countable subcover.
## Implementation details
* This API is mainly based on the API for IsCompact and follows notation and style as much
as possible.
-/
open Set Filter Topology TopologicalSpace
universe u v
variable {X : Type u} {Y : Type v} {ι : Type*}
variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X}
section Lindelof
/-- A set `s` is Lindelöf if every nontrivial filter `f` with the countable intersection
property that contains `s`, has a clusterpoint in `s`. The filter-free definition is given by
`isLindelof_iff_countable_subcover`. -/
def IsLindelof (s : Set X) :=
∀ ⦃f⦄ [NeBot f] [CountableInterFilter f], f ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x f
/-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection
property if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/
theorem IsLindelof.compl_mem_sets (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f]
(hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) : sᶜ ∈ f := by
contrapose! hf
simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢
exact hs inf_le_right
/-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection
property if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/
theorem IsLindelof.compl_mem_sets_of_nhdsWithin (hs : IsLindelof s) {f : Filter X}
[CountableInterFilter f] (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by
refine hs.compl_mem_sets fun x hx ↦ ?_
rw [← disjoint_principal_right, disjoint_right_comm, (basis_sets _).disjoint_iff_left]
exact hf x hx
/-- If `p : Set X → Prop` is stable under restriction and union, and each point `x`
of a Lindelöf set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/
@[elab_as_elim]
theorem IsLindelof.induction_on (hs : IsLindelof s) {p : Set X → Prop}
(hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s)
(hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, p s) → p (⋃₀ S))
(hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by
let f : Filter X := ofCountableUnion p hcountable_union (fun t ht _ hsub ↦ hmono hsub ht)
have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds)
rwa [← compl_compl s]
/-- The intersection of a Lindelöf set and a closed set is a Lindelöf set. -/
theorem IsLindelof.inter_right (hs : IsLindelof s) (ht : IsClosed t) : IsLindelof (s ∩ t) := by
intro f hnf _ hstf
rw [← inf_principal, le_inf_iff] at hstf
obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs hstf.1
have hxt : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono hstf.2
exact ⟨x, ⟨hsx, hxt⟩, hx⟩
/-- The intersection of a closed set and a Lindelöf set is a Lindelöf set. -/
theorem IsLindelof.inter_left (ht : IsLindelof t) (hs : IsClosed s) : IsLindelof (s ∩ t) :=
inter_comm t s ▸ ht.inter_right hs
/-- The set difference of a Lindelöf set and an open set is a Lindelöf set. -/
theorem IsLindelof.diff (hs : IsLindelof s) (ht : IsOpen t) : IsLindelof (s \ t) :=
hs.inter_right (isClosed_compl_iff.mpr ht)
/-- A closed subset of a Lindelöf set is a Lindelöf set. -/
theorem IsLindelof.of_isClosed_subset (hs : IsLindelof s) (ht : IsClosed t) (h : t ⊆ s) :
IsLindelof t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht
/-- A continuous image of a Lindelöf set is a Lindelöf set. -/
theorem IsLindelof.image_of_continuousOn {f : X → Y} (hs : IsLindelof s) (hf : ContinuousOn f s) :
IsLindelof (f '' s) := by
intro l lne _ ls
have : NeBot (l.comap f ⊓ 𝓟 s) :=
comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls)
obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this _ inf_le_right
haveI := hx.neBot
use f x, mem_image_of_mem f hxs
have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by
convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1
rw [nhdsWithin]
ac_rfl
exact this.neBot
/-- A continuous image of a Lindelöf set is a Lindelöf set within the codomain. -/
theorem IsLindelof.image {f : X → Y} (hs : IsLindelof s) (hf : Continuous f) :
IsLindelof (f '' s) := hs.image_of_continuousOn hf.continuousOn
/-- A filter with the countable intersection property that is finer than the principal filter on
a Lindelöf set `s` contains any open set that contains all clusterpoints of `s`. -/
theorem IsLindelof.adherence_nhdset {f : Filter X} [CountableInterFilter f] (hs : IsLindelof s)
(hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f :=
(eq_or_neBot _).casesOn mem_of_eq_bot fun _ ↦
let ⟨x, hx, hfx⟩ := @hs (f ⊓ 𝓟 tᶜ) _ _ <| inf_le_of_left_le hf₂
have : x ∈ t := ht₂ x hx hfx.of_inf_left
have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (ht₁.mem_nhds this)
have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this
have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne
absurd A this
/-- For every open cover of a Lindelöf set, there exists a countable subcover. -/
theorem IsLindelof.elim_countable_subcover {ι : Type v} (hs : IsLindelof s) (U : ι → Set X)
(hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) :
∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i) := by
have hmono : ∀ ⦃s t : Set X⦄, s ⊆ t → (∃ r : Set ι, r.Countable ∧ t ⊆ ⋃ i ∈ r, U i)
→ (∃ r : Set ι, r.Countable ∧ s ⊆ ⋃ i ∈ r, U i) := by
intro _ _ hst ⟨r, ⟨hrcountable, hsub⟩⟩
exact ⟨r, hrcountable, Subset.trans hst hsub⟩
have hcountable_union : ∀ (S : Set (Set X)), S.Countable
→ (∀ s ∈ S, ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i))
→ ∃ r : Set ι, r.Countable ∧ (⋃₀ S ⊆ ⋃ i ∈ r, U i) := by
intro S hS hsr
choose! r hr using hsr
refine ⟨⋃ s ∈ S, r s, hS.biUnion_iff.mpr (fun s hs ↦ (hr s hs).1), ?_⟩
refine sUnion_subset ?h.right.h
simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and']
exact fun i is x hx ↦ mem_biUnion is ((hr i is).2 hx)
have h_nhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∃ r : Set ι, r.Countable ∧ (t ⊆ ⋃ i ∈ r, U i) := by
intro x hx
let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx)
refine ⟨U i, mem_nhdsWithin_of_mem_nhds ((hUo i).mem_nhds hi), {i}, by simp, ?_⟩
simp only [mem_singleton_iff, iUnion_iUnion_eq_left]
exact Subset.refl _
exact hs.induction_on hmono hcountable_union h_nhds
theorem IsLindelof.elim_nhds_subcover' (hs : IsLindelof s) (U : ∀ x ∈ s, Set X)
(hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) :
∃ t : Set s, t.Countable ∧ s ⊆ ⋃ x ∈ t, U (x : s) x.2 := by
have := hs.elim_countable_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior)
fun x hx ↦
mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩
rcases this with ⟨r, ⟨hr, hs⟩⟩
use r, hr
apply Subset.trans hs
apply iUnion₂_subset
intro i hi
apply Subset.trans interior_subset
exact subset_iUnion_of_subset i (subset_iUnion_of_subset hi (Subset.refl _))
theorem IsLindelof.elim_nhds_subcover (hs : IsLindelof s) (U : X → Set X)
(hU : ∀ x ∈ s, U x ∈ 𝓝 x) :
∃ t : Set X, t.Countable ∧ (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := by
let ⟨t, ⟨htc, htsub⟩⟩ := hs.elim_nhds_subcover' (fun x _ ↦ U x) hU
refine ⟨↑t, Countable.image htc Subtype.val, ?_⟩
constructor
· intro _
simp only [mem_image, Subtype.exists, exists_and_right, exists_eq_right, forall_exists_index]
tauto
· have : ⋃ x ∈ t, U ↑x = ⋃ x ∈ Subtype.val '' t, U x := biUnion_image.symm
rwa [← this]
/-- For every nonempty open cover of a Lindelöf set, there exists a subcover indexed by ℕ. -/
theorem IsLindelof.indexed_countable_subcover {ι : Type v} [Nonempty ι]
(hs : IsLindelof s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) :
∃ f : ℕ → ι, s ⊆ ⋃ n, U (f n) := by
obtain ⟨c, ⟨c_count, c_cov⟩⟩ := hs.elim_countable_subcover U hUo hsU
rcases c.eq_empty_or_nonempty with rfl | c_nonempty
· simp only [mem_empty_iff_false, iUnion_of_empty, iUnion_empty] at c_cov
simp only [subset_eq_empty c_cov rfl, empty_subset, exists_const]
obtain ⟨f, f_surj⟩ := (Set.countable_iff_exists_surjective c_nonempty).mp c_count
refine ⟨fun x ↦ f x, c_cov.trans <| iUnion₂_subset_iff.mpr (?_ : ∀ i ∈ c, U i ⊆ ⋃ n, U (f n))⟩
intro x hx
obtain ⟨n, hn⟩ := f_surj ⟨x, hx⟩
exact subset_iUnion_of_subset n <| subset_of_eq (by rw [hn])
/-- The neighborhood filter of a Lindelöf set is disjoint with a filter `l` with the countable
intersection property if and only if the neighborhood filter of each point of this set
is disjoint with `l`. -/
theorem IsLindelof.disjoint_nhdsSet_left {l : Filter X} [CountableInterFilter l]
(hs : IsLindelof s) :
Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by
refine ⟨fun h x hx ↦ h.mono_left <| nhds_le_nhdsSet hx, fun H ↦ ?_⟩
choose! U hxU hUl using fun x hx ↦ (nhds_basis_opens x).disjoint_iff_left.1 (H x hx)
choose hxU hUo using hxU
rcases hs.elim_nhds_subcover U fun x hx ↦ (hUo x hx).mem_nhds (hxU x hx) with ⟨t, htc, hts, hst⟩
refine (hasBasis_nhdsSet _).disjoint_iff_left.2
⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx ↦ hUo x (hts x hx), hst⟩, ?_⟩
rw [compl_iUnion₂]
exact (countable_bInter_mem htc).mpr (fun i hi ↦ hUl _ (hts _ hi))
/-- A filter `l` with the countable intersection property is disjoint with the neighborhood
filter of a Lindelöf set if and only if it is disjoint with the neighborhood filter of each point
of this set. -/
theorem IsLindelof.disjoint_nhdsSet_right {l : Filter X} [CountableInterFilter l]
(hs : IsLindelof s) : Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by
simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left
/-- For every family of closed sets whose intersection avoids a Lindelö set,
there exists a countable subfamily whose intersection avoids this Lindelöf set. -/
theorem IsLindelof.elim_countable_subfamily_closed {ι : Type v} (hs : IsLindelof s)
(t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) :
∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅ := by
let U := tᶜ
have hUo : ∀ i, IsOpen (U i) := by simp only [U, Pi.compl_apply, isOpen_compl_iff]; exact htc
have hsU : s ⊆ ⋃ i, U i := by
simp only [U, Pi.compl_apply]
rw [← compl_iInter]
apply disjoint_compl_left_iff_subset.mp
simp only [compl_iInter, compl_iUnion, compl_compl]
apply Disjoint.symm
exact disjoint_iff_inter_eq_empty.mpr hst
rcases hs.elim_countable_subcover U hUo hsU with ⟨u, ⟨hucount, husub⟩⟩
use u, hucount
rw [← disjoint_compl_left_iff_subset] at husub
simp only [U, Pi.compl_apply, compl_iUnion, compl_compl] at husub
exact disjoint_iff_inter_eq_empty.mp (Disjoint.symm husub)
/-- To show that a Lindelöf set intersects the intersection of a family of closed sets,
it is sufficient to show that it intersects every countable subfamily. -/
theorem IsLindelof.inter_iInter_nonempty {ι : Type v} (hs : IsLindelof s) (t : ι → Set X)
(htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i).Nonempty) :
(s ∩ ⋂ i, t i).Nonempty := by
contrapose! hst
rcases hs.elim_countable_subfamily_closed t htc hst with ⟨u, ⟨_, husub⟩⟩
exact ⟨u, fun _ ↦ husub⟩
/-- For every open cover of a Lindelöf set, there exists a countable subcover. -/
theorem IsLindelof.elim_countable_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsLindelof s)
(hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) :
∃ b', b' ⊆ b ∧ Set.Countable b' ∧ s ⊆ ⋃ i ∈ b', c i := by
simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂
rcases hs.elim_countable_subcover (fun i ↦ c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩
refine ⟨Subtype.val '' d, by simp, Countable.image hd.1 Subtype.val, ?_⟩
rw [biUnion_image]
exact hd.2
/-- A set `s` is Lindelöf if for every open cover of `s`, there exists a countable subcover. -/
theorem isLindelof_of_countable_subcover
(h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) →
∃ t : Set ι, t.Countable ∧ s ⊆ ⋃ i ∈ t, U i) :
IsLindelof s := fun f hf hfs ↦ by
contrapose! h
simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall',
(nhds_basis_opens _).disjoint_iff_left] at h
choose fsub U hU hUf using h
refine ⟨s, U, fun x ↦ (hU x).2, fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1 ⟩, ?_⟩
intro t ht h
have uinf := f.sets_of_superset (le_principal_iff.1 fsub) h
have uninf : ⋂ i ∈ t, (U i)ᶜ ∈ f := (countable_bInter_mem ht).mpr (fun _ _ ↦ hUf _)
rw [← compl_iUnion₂] at uninf
have uninf := compl_not_mem uninf
simp only [compl_compl] at uninf
contradiction
/-- A set `s` is Lindelöf if for every family of closed sets whose intersection avoids `s`,
there exists a countable subfamily whose intersection avoids `s`. -/
theorem isLindelof_of_countable_subfamily_closed
(h :
∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ →
∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅) :
IsLindelof s :=
isLindelof_of_countable_subcover fun U hUo hsU ↦ by
rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU
rcases h (fun i ↦ (U i)ᶜ) (fun i ↦ (hUo _).isClosed_compl) hsU with ⟨t, ht⟩
refine ⟨t, ?_⟩
rwa [← disjoint_compl_right_iff_subset, compl_iUnion₂, disjoint_iff]
/-- A set `s` is Lindelöf if and only if
for every open cover of `s`, there exists a countable subcover. -/
theorem isLindelof_iff_countable_subcover :
IsLindelof s ↔ ∀ {ι : Type u} (U : ι → Set X),
(∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Set ι, t.Countable ∧ s ⊆ ⋃ i ∈ t, U i :=
⟨fun hs ↦ hs.elim_countable_subcover, isLindelof_of_countable_subcover⟩
/-- A set `s` is Lindelöf if and only if
for every family of closed sets whose intersection avoids `s`,
there exists a countable subfamily whose intersection avoids `s`. -/
theorem isLindelof_iff_countable_subfamily_closed :
IsLindelof s ↔ ∀ {ι : Type u} (t : ι → Set X),
(∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅
→ ∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅ :=
⟨fun hs ↦ hs.elim_countable_subfamily_closed, isLindelof_of_countable_subfamily_closed⟩
/-- The empty set is a Lindelof set. -/
@[simp]
theorem isLindelof_empty : IsLindelof (∅ : Set X) := fun _f hnf _ hsf ↦
Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf
/-- A singleton set is a Lindelof set. -/
@[simp]
theorem isLindelof_singleton {x : X} : IsLindelof ({x} : Set X) := fun _ hf _ hfa ↦
⟨x, rfl, ClusterPt.of_le_nhds'
(hfa.trans <| by simpa only [principal_singleton] using pure_le_nhds x) hf⟩
theorem Set.Subsingleton.isLindelof (hs : s.Subsingleton) : IsLindelof s :=
Subsingleton.induction_on hs isLindelof_empty fun _ ↦ isLindelof_singleton
theorem Set.Countable.isLindelof_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Countable)
(hf : ∀ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := by
apply isLindelof_of_countable_subcover
intro i U hU hUcover
have hiU : ∀ i ∈ s, f i ⊆ ⋃ i, U i :=
fun _ is ↦ _root_.subset_trans (subset_biUnion_of_mem is) hUcover
have iSets := fun i is ↦ (hf i is).elim_countable_subcover U hU (hiU i is)
choose! r hr using iSets
use ⋃ i ∈ s, r i
constructor
· refine (Countable.biUnion_iff hs).mpr ?h.left.a
exact fun s hs ↦ (hr s hs).1
· refine iUnion₂_subset ?h.right.h
intro i is
simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and']
intro x hx
exact mem_biUnion is ((hr i is).2 hx)
theorem Set.Finite.isLindelof_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Finite)
(hf : ∀ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) :=
Set.Countable.isLindelof_biUnion (countable hs) hf
theorem Finset.isLindelof_biUnion (s : Finset ι) {f : ι → Set X} (hf : ∀ i ∈ s, IsLindelof (f i)) :
IsLindelof (⋃ i ∈ s, f i) :=
s.finite_toSet.isLindelof_biUnion hf
theorem isLindelof_accumulate {K : ℕ → Set X} (hK : ∀ n, IsLindelof (K n)) (n : ℕ) :
IsLindelof (Accumulate K n) :=
(finite_le_nat n).isLindelof_biUnion fun k _ => hK k
theorem Set.Countable.isLindelof_sUnion {S : Set (Set X)} (hf : S.Countable)
(hc : ∀ s ∈ S, IsLindelof s) : IsLindelof (⋃₀ S) := by
rw [sUnion_eq_biUnion]; exact hf.isLindelof_biUnion hc
theorem Set.Finite.isLindelof_sUnion {S : Set (Set X)} (hf : S.Finite)
(hc : ∀ s ∈ S, IsLindelof s) : IsLindelof (⋃₀ S) := by
rw [sUnion_eq_biUnion]; exact hf.isLindelof_biUnion hc
theorem isLindelof_iUnion {ι : Sort*} {f : ι → Set X} [Countable ι] (h : ∀ i, IsLindelof (f i)) :
IsLindelof (⋃ i, f i) := (countable_range f).isLindelof_sUnion <| forall_mem_range.2 h
theorem Set.Countable.isLindelof (hs : s.Countable) : IsLindelof s :=
biUnion_of_singleton s ▸ hs.isLindelof_biUnion fun _ _ => isLindelof_singleton
theorem Set.Finite.isLindelof (hs : s.Finite) : IsLindelof s :=
biUnion_of_singleton s ▸ hs.isLindelof_biUnion fun _ _ => isLindelof_singleton
theorem IsLindelof.countable_of_discrete [DiscreteTopology X] (hs : IsLindelof s) :
s.Countable := by
have : ∀ x : X, ({x} : Set X) ∈ 𝓝 x := by simp [nhds_discrete]
rcases hs.elim_nhds_subcover (fun x => {x}) fun x _ => this x with ⟨t, ht, _, hssubt⟩
rw [biUnion_of_singleton] at hssubt
exact ht.mono hssubt
theorem isLindelof_iff_countable [DiscreteTopology X] : IsLindelof s ↔ s.Countable :=
⟨fun h => h.countable_of_discrete, fun h => h.isLindelof⟩
theorem IsLindelof.union (hs : IsLindelof s) (ht : IsLindelof t) : IsLindelof (s ∪ t) := by
rw [union_eq_iUnion]; exact isLindelof_iUnion fun b => by cases b <;> assumption
protected theorem IsLindelof.insert (hs : IsLindelof s) (a) : IsLindelof (insert a s) :=
isLindelof_singleton.union hs
/-- If `X` has a basis consisting of compact opens, then an open set in `X` is compact open iff
it is a finite union of some elements in the basis -/
theorem isLindelof_open_iff_eq_countable_iUnion_of_isTopologicalBasis (b : ι → Set X)
(hb : IsTopologicalBasis (Set.range b)) (hb' : ∀ i, IsLindelof (b i)) (U : Set X) :
IsLindelof U ∧ IsOpen U ↔ ∃ s : Set ι, s.Countable ∧ U = ⋃ i ∈ s, b i := by
constructor
· rintro ⟨h₁, h₂⟩
obtain ⟨Y, f, rfl, hf⟩ := hb.open_eq_iUnion h₂
choose f' hf' using hf
have : b ∘ f' = f := funext hf'
subst this
obtain ⟨t, ht⟩ :=
h₁.elim_countable_subcover (b ∘ f') (fun i => hb.isOpen (Set.mem_range_self _)) Subset.rfl
refine ⟨t.image f', Countable.image (ht.1) f', le_antisymm ?_ ?_⟩
· refine Set.Subset.trans ht.2 ?_
simp only [Set.iUnion_subset_iff]
intro i hi
rw [← Set.iUnion_subtype (fun x : ι => x ∈ t.image f') fun i => b i.1]
exact Set.subset_iUnion (fun i : t.image f' => b i) ⟨_, mem_image_of_mem _ hi⟩
· apply Set.iUnion₂_subset
rintro i hi
obtain ⟨j, -, rfl⟩ := (mem_image ..).mp hi
exact Set.subset_iUnion (b ∘ f') j
· rintro ⟨s, hs, rfl⟩
constructor
· exact hs.isLindelof_biUnion fun i _ => hb' i
· exact isOpen_biUnion fun i _ => hb.isOpen (Set.mem_range_self _)
/-- `Filter.coLindelof` is the filter generated by complements to Lindelöf sets. -/
def Filter.coLindelof (X : Type*) [TopologicalSpace X] : Filter X :=
--`Filter.coLindelof` is the filter generated by complements to Lindelöf sets.
⨅ (s : Set X) (_ : IsLindelof s), 𝓟 sᶜ
theorem hasBasis_coLindelof : (coLindelof X).HasBasis IsLindelof compl :=
hasBasis_biInf_principal'
(fun s hs t ht =>
⟨s ∪ t, hs.union ht, compl_subset_compl.2 subset_union_left,
compl_subset_compl.2 subset_union_right⟩)
⟨∅, isLindelof_empty⟩
theorem mem_coLindelof : s ∈ coLindelof X ↔ ∃ t, IsLindelof t ∧ tᶜ ⊆ s :=
hasBasis_coLindelof.mem_iff
theorem mem_coLindelof' : s ∈ coLindelof X ↔ ∃ t, IsLindelof t ∧ sᶜ ⊆ t :=
mem_coLindelof.trans <| exists_congr fun _ => and_congr_right fun _ => compl_subset_comm
theorem _root_.IsLindelof.compl_mem_coLindelof (hs : IsLindelof s) : sᶜ ∈ coLindelof X :=
hasBasis_coLindelof.mem_of_mem hs
theorem coLindelof_le_cofinite : coLindelof X ≤ cofinite := fun s hs =>
compl_compl s ▸ hs.isLindelof.compl_mem_coLindelof
theorem Tendsto.isLindelof_insert_range_of_coLindelof {f : X → Y} {y}
(hf : Tendsto f (coLindelof X) (𝓝 y)) (hfc : Continuous f) :
IsLindelof (insert y (range f)) := by
intro l hne _ hle
by_cases hy : ClusterPt y l
· exact ⟨y, Or.inl rfl, hy⟩
simp only [clusterPt_iff_nonempty, not_forall, ← not_disjoint_iff_nonempty_inter, not_not] at hy
rcases hy with ⟨s, hsy, t, htl, hd⟩
rcases mem_coLindelof.1 (hf hsy) with ⟨K, hKc, hKs⟩
have : f '' K ∈ l := by
filter_upwards [htl, le_principal_iff.1 hle] with y hyt hyf
rcases hyf with (rfl | ⟨x, rfl⟩)
exacts [(hd.le_bot ⟨mem_of_mem_nhds hsy, hyt⟩).elim,
mem_image_of_mem _ (not_not.1 fun hxK => hd.le_bot ⟨hKs hxK, hyt⟩)]
rcases hKc.image hfc (le_principal_iff.2 this) with ⟨y, hy, hyl⟩
exact ⟨y, Or.inr <| image_subset_range _ _ hy, hyl⟩
/-- `Filter.coclosedLindelof` is the filter generated by complements to closed Lindelof sets. -/
def Filter.coclosedLindelof (X : Type*) [TopologicalSpace X] : Filter X :=
-- `Filter.coclosedLindelof` is the filter generated by complements to closed Lindelof sets.
⨅ (s : Set X) (_ : IsClosed s) (_ : IsLindelof s), 𝓟 sᶜ
theorem hasBasis_coclosedLindelof :
(Filter.coclosedLindelof X).HasBasis (fun s => IsClosed s ∧ IsLindelof s) compl := by
simp only [Filter.coclosedLindelof, iInf_and']
refine hasBasis_biInf_principal' ?_ ⟨∅, isClosed_empty, isLindelof_empty⟩
rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩
exact ⟨s ∪ t, ⟨⟨hs₁.union ht₁, hs₂.union ht₂⟩, compl_subset_compl.2 subset_union_left,
compl_subset_compl.2 subset_union_right⟩⟩
theorem mem_coclosedLindelof : s ∈ coclosedLindelof X ↔
∃ t, IsClosed t ∧ IsLindelof t ∧ tᶜ ⊆ s := by
simp only [hasBasis_coclosedLindelof.mem_iff, and_assoc]
theorem mem_coclosed_Lindelof' : s ∈ coclosedLindelof X ↔
∃ t, IsClosed t ∧ IsLindelof t ∧ sᶜ ⊆ t := by
simp only [mem_coclosedLindelof, compl_subset_comm]
theorem coLindelof_le_coclosedLindelof : coLindelof X ≤ coclosedLindelof X :=
iInf_mono fun _ => le_iInf fun _ => le_rfl
theorem IsLindeof.compl_mem_coclosedLindelof_of_isClosed (hs : IsLindelof s) (hs' : IsClosed s) :
sᶜ ∈ Filter.coclosedLindelof X :=
hasBasis_coclosedLindelof.mem_of_mem ⟨hs', hs⟩
/-- X is a Lindelöf space iff every open cover has a countable subcover. -/
class LindelofSpace (X : Type*) [TopologicalSpace X] : Prop where
/-- In a Lindelöf space, `Set.univ` is a Lindelöf set. -/
isLindelof_univ : IsLindelof (univ : Set X)
instance (priority := 10) Subsingleton.lindelofSpace [Subsingleton X] : LindelofSpace X :=
⟨subsingleton_univ.isLindelof⟩
theorem isLindelof_univ_iff : IsLindelof (univ : Set X) ↔ LindelofSpace X :=
⟨fun h => ⟨h⟩, fun h => h.1⟩
theorem isLindelof_univ [h : LindelofSpace X] : IsLindelof (univ : Set X) :=
h.isLindelof_univ
theorem cluster_point_of_Lindelof [LindelofSpace X] (f : Filter X) [NeBot f]
[CountableInterFilter f] : ∃ x, ClusterPt x f := by
simpa using isLindelof_univ (show f ≤ 𝓟 univ by simp)
theorem LindelofSpace.elim_nhds_subcover [LindelofSpace X] (U : X → Set X) (hU : ∀ x, U x ∈ 𝓝 x) :
∃ t : Set X, t.Countable ∧ ⋃ x ∈ t, U x = univ := by
obtain ⟨t, tc, -, s⟩ := IsLindelof.elim_nhds_subcover isLindelof_univ U fun x _ => hU x
use t, tc
apply top_unique s
theorem lindelofSpace_of_countable_subfamily_closed
(h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → ⋂ i, t i = ∅ →
∃ u : Set ι, u.Countable ∧ ⋂ i ∈ u, t i = ∅) :
LindelofSpace X where
isLindelof_univ := isLindelof_of_countable_subfamily_closed fun t => by simpa using h t
theorem IsClosed.isLindelof [LindelofSpace X] (h : IsClosed s) : IsLindelof s :=
isLindelof_univ.of_isClosed_subset h (subset_univ _)
/-- A compact set `s` is Lindelöf. -/
theorem IsCompact.isLindelof (hs : IsCompact s) :
IsLindelof s := by tauto
/-- A σ-compact set `s` is Lindelöf -/
theorem IsSigmaCompact.isLindelof (hs : IsSigmaCompact s) :
IsLindelof s := by
rw [IsSigmaCompact] at hs
rcases hs with ⟨K, ⟨hc, huniv⟩⟩
rw [← huniv]
have hl : ∀ n, IsLindelof (K n) := fun n ↦ IsCompact.isLindelof (hc n)
exact isLindelof_iUnion hl
/-- A compact space `X` is Lindelöf. -/
instance (priority := 100) [CompactSpace X] : LindelofSpace X :=
{ isLindelof_univ := isCompact_univ.isLindelof}
/-- A sigma-compact space `X` is Lindelöf. -/
instance (priority := 100) [SigmaCompactSpace X] : LindelofSpace X :=
{ isLindelof_univ := isSigmaCompact_univ.isLindelof}
/-- `X` is a non-Lindelöf topological space if it is not a Lindelöf space. -/
class NonLindelofSpace (X : Type*) [TopologicalSpace X] : Prop where
/-- In a non-Lindelöf space, `Set.univ` is not a Lindelöf set. -/
nonLindelof_univ : ¬IsLindelof (univ : Set X)
lemma nonLindelof_univ (X : Type*) [TopologicalSpace X] [NonLindelofSpace X] :
¬IsLindelof (univ : Set X) :=
NonLindelofSpace.nonLindelof_univ
theorem IsLindelof.ne_univ [NonLindelofSpace X] (hs : IsLindelof s) : s ≠ univ := fun h ↦
nonLindelof_univ X (h ▸ hs)
instance [NonLindelofSpace X] : NeBot (Filter.coLindelof X) := by
refine hasBasis_coLindelof.neBot_iff.2 fun {s} hs => ?_
contrapose hs
rw [not_nonempty_iff_eq_empty, compl_empty_iff] at hs
rw [hs]
exact nonLindelof_univ X
@[simp]
theorem Filter.coLindelof_eq_bot [LindelofSpace X] : Filter.coLindelof X = ⊥ :=
hasBasis_coLindelof.eq_bot_iff.mpr ⟨Set.univ, isLindelof_univ, Set.compl_univ⟩
instance [NonLindelofSpace X] : NeBot (Filter.coclosedLindelof X) :=
neBot_of_le coLindelof_le_coclosedLindelof
theorem nonLindelofSpace_of_neBot (_ : NeBot (Filter.coLindelof X)) : NonLindelofSpace X :=
⟨fun h' => (Filter.nonempty_of_mem h'.compl_mem_coLindelof).ne_empty compl_univ⟩
theorem Filter.coLindelof_neBot_iff : NeBot (Filter.coLindelof X) ↔ NonLindelofSpace X :=
⟨nonLindelofSpace_of_neBot, fun _ => inferInstance⟩
theorem not_LindelofSpace_iff : ¬LindelofSpace X ↔ NonLindelofSpace X :=
⟨fun h₁ => ⟨fun h₂ => h₁ ⟨h₂⟩⟩, fun ⟨h₁⟩ ⟨h₂⟩ => h₁ h₂⟩
/-- A compact space `X` is Lindelöf. -/
instance (priority := 100) [CompactSpace X] : LindelofSpace X :=
{ isLindelof_univ := isCompact_univ.isLindelof}
theorem countable_of_Lindelof_of_discrete [LindelofSpace X] [DiscreteTopology X] : Countable X :=
countable_univ_iff.mp isLindelof_univ.countable_of_discrete
theorem countable_cover_nhds_interior [LindelofSpace X] {U : X → Set X} (hU : ∀ x, U x ∈ 𝓝 x) :
∃ t : Set X, t.Countable ∧ ⋃ x ∈ t, interior (U x) = univ :=
let ⟨t, ht⟩ := isLindelof_univ.elim_countable_subcover (fun x => interior (U x))
(fun _ => isOpen_interior) fun x _ => mem_iUnion.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩
⟨t, ⟨ht.1, univ_subset_iff.1 ht.2⟩⟩
theorem countable_cover_nhds [LindelofSpace X] {U : X → Set X} (hU : ∀ x, U x ∈ 𝓝 x) :
∃ t : Set X, t.Countable ∧ ⋃ x ∈ t, U x = univ :=
let ⟨t, ht⟩ := countable_cover_nhds_interior hU
⟨t, ⟨ht.1, univ_subset_iff.1 <| ht.2.symm.subset.trans <|
iUnion₂_mono fun _ _ => interior_subset⟩⟩
/-- The comap of the coLindelöf filter on `Y` by a continuous function `f : X → Y` is less than or
equal to the coLindelöf filter on `X`.
This is a reformulation of the fact that images of Lindelöf sets are Lindelöf. -/
theorem Filter.comap_coLindelof_le {f : X → Y} (hf : Continuous f) :
(Filter.coLindelof Y).comap f ≤ Filter.coLindelof X := by
rw [(hasBasis_coLindelof.comap f).le_basis_iff hasBasis_coLindelof]
intro t ht
refine ⟨f '' t, ht.image hf, ?_⟩
simpa using t.subset_preimage_image f
theorem isLindelof_range [LindelofSpace X] {f : X → Y} (hf : Continuous f) :
IsLindelof (range f) := by rw [← image_univ]; exact isLindelof_univ.image hf
theorem isLindelof_diagonal [LindelofSpace X] : IsLindelof (diagonal X) :=
@range_diag X ▸ isLindelof_range (continuous_id.prodMk continuous_id)
/-- If `f : X → Y` is an inducing map, the image `f '' s` of a set `s` is Lindelöf
if and only if `s` is compact. -/
| Mathlib/Topology/Compactness/Lindelof.lean | 604 | 609 | theorem Topology.IsInducing.isLindelof_iff {f : X → Y} (hf : IsInducing f) :
IsLindelof s ↔ IsLindelof (f '' s) := by | refine ⟨fun hs => hs.image hf.continuous, fun hs F F_ne_bot _ F_le => ?_⟩
obtain ⟨_, ⟨x, x_in : x ∈ s, rfl⟩, hx : ClusterPt (f x) (map f F)⟩ :=
hs ((map_mono F_le).trans_eq map_principal)
exact ⟨x, x_in, hf.mapClusterPt_iff.1 hx⟩ |
/-
Copyright (c) 2023 Richard M. Hill. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Richard M. Hill
-/
import Mathlib.RingTheory.PowerSeries.Trunc
import Mathlib.RingTheory.PowerSeries.Inverse
import Mathlib.RingTheory.Derivation.Basic
/-!
# Definitions
In this file we define an operation `derivative` (formal differentiation)
on the ring of formal power series in one variable (over an arbitrary commutative semiring).
Under suitable assumptions, we prove that two power series are equal if their derivatives
are equal and their constant terms are equal. This will give us a simple tool for proving
power series identities. For example, one can easily prove the power series identity
$\exp ( \log (1+X)) = 1+X$ by differentiating twice.
## Main Definition
- `PowerSeries.derivative R : Derivation R R⟦X⟧ R⟦X⟧` the formal derivative operation.
This is abbreviated `d⁄dX R`.
-/
namespace PowerSeries
open Polynomial Derivation Nat
section CommutativeSemiring
variable {R} [CommSemiring R]
/--
The formal derivative of a power series in one variable.
This is defined here as a function, but will be packaged as a
derivation `derivative` on `R⟦X⟧`.
-/
noncomputable def derivativeFun (f : R⟦X⟧) : R⟦X⟧ := mk fun n ↦ coeff R (n + 1) f * (n + 1)
theorem coeff_derivativeFun (f : R⟦X⟧) (n : ℕ) :
coeff R n f.derivativeFun = coeff R (n + 1) f * (n + 1) := by
rw [derivativeFun, coeff_mk]
theorem derivativeFun_coe (f : R[X]) : (f : R⟦X⟧).derivativeFun = derivative f := by
ext
rw [coeff_derivativeFun, coeff_coe, coeff_coe, coeff_derivative]
theorem derivativeFun_add (f g : R⟦X⟧) :
derivativeFun (f + g) = derivativeFun f + derivativeFun g := by
ext
rw [coeff_derivativeFun, map_add, map_add, coeff_derivativeFun,
coeff_derivativeFun, add_mul]
theorem derivativeFun_C (r : R) : derivativeFun (C R r) = 0 := by
ext n
-- Note that `map_zero` didn't get picked up, apparently due to a missing `FunLike.coe`
rw [coeff_derivativeFun, coeff_succ_C, zero_mul, (coeff R n).map_zero]
theorem trunc_derivativeFun (f : R⟦X⟧) (n : ℕ) :
trunc n f.derivativeFun = derivative (trunc (n + 1) f) := by
ext d
rw [coeff_trunc]
split_ifs with h
· have : d + 1 < n + 1 := succ_lt_succ_iff.2 h
rw [coeff_derivativeFun, coeff_derivative, coeff_trunc, if_pos this]
· have : ¬d + 1 < n + 1 := by rwa [succ_lt_succ_iff]
rw [coeff_derivative, coeff_trunc, if_neg this, zero_mul]
--A special case of `derivativeFun_mul`, used in its proof.
private theorem derivativeFun_coe_mul_coe (f g : R[X]) : derivativeFun (f * g : R⟦X⟧) =
f * derivative g + g * derivative f := by
rw [← coe_mul, derivativeFun_coe, derivative_mul,
add_comm, mul_comm _ g, ← coe_mul, ← coe_mul, Polynomial.coe_add]
/-- **Leibniz rule for formal power series**. -/
theorem derivativeFun_mul (f g : R⟦X⟧) :
derivativeFun (f * g) = f • g.derivativeFun + g • f.derivativeFun := by
ext n
have h₁ : n < n + 1 := lt_succ_self n
have h₂ : n < n + 1 + 1 := Nat.lt_add_right _ h₁
rw [coeff_derivativeFun, map_add, coeff_mul_eq_coeff_trunc_mul_trunc _ _ (lt_succ_self _),
smul_eq_mul, smul_eq_mul, coeff_mul_eq_coeff_trunc_mul_trunc₂ g f.derivativeFun h₂ h₁,
coeff_mul_eq_coeff_trunc_mul_trunc₂ f g.derivativeFun h₂ h₁, trunc_derivativeFun,
trunc_derivativeFun, ← map_add, ← derivativeFun_coe_mul_coe, coeff_derivativeFun]
theorem derivativeFun_one : derivativeFun (1 : R⟦X⟧) = 0 := by
rw [← map_one (C R), derivativeFun_C (1 : R)]
theorem derivativeFun_smul (r : R) (f : R⟦X⟧) : derivativeFun (r • f) = r • derivativeFun f := by
rw [smul_eq_C_mul, smul_eq_C_mul, derivativeFun_mul, derivativeFun_C, smul_zero, add_zero,
smul_eq_mul]
variable (R)
/-- The formal derivative of a formal power series -/
noncomputable def derivative : Derivation R R⟦X⟧ R⟦X⟧ where
toFun := derivativeFun
map_add' := derivativeFun_add
map_smul' := derivativeFun_smul
map_one_eq_zero' := derivativeFun_one
leibniz' := derivativeFun_mul
/-- Abbreviation of `PowerSeries.derivative`, the formal derivative on `R⟦X⟧` -/
scoped notation "d⁄dX" => derivative
variable {R}
@[simp] theorem derivative_C (r : R) : d⁄dX R (C R r) = 0 := derivativeFun_C r
theorem coeff_derivative (f : R⟦X⟧) (n : ℕ) :
coeff R n (d⁄dX R f) = coeff R (n + 1) f * (n + 1) := coeff_derivativeFun f n
theorem derivative_coe (f : R[X]) : d⁄dX R f = Polynomial.derivative f := derivativeFun_coe f
@[simp] theorem derivative_X : d⁄dX R (X : R⟦X⟧) = 1 := by
ext
rw [coeff_derivative, coeff_one, coeff_X, boole_mul]
simp_rw [add_eq_right]
split_ifs with h
· rw [h, cast_zero, zero_add]
· rfl
theorem trunc_derivative (f : R⟦X⟧) (n : ℕ) :
trunc n (d⁄dX R f) = Polynomial.derivative (trunc (n + 1) f) :=
trunc_derivativeFun ..
| Mathlib/RingTheory/PowerSeries/Derivative.lean | 127 | 133 | theorem trunc_derivative' (f : R⟦X⟧) (n : ℕ) :
trunc (n-1) (d⁄dX R f) = Polynomial.derivative (trunc n f) := by | cases n with
| zero =>
simp
| succ n =>
rw [succ_sub_one, trunc_derivative] |
/-
Copyright (c) 2023 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.SetTheory.Cardinal.Finite
import Mathlib.Data.Set.Finite.Powerset
/-!
# Noncomputable Set Cardinality
We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`.
The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and
are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen
as an API for the same function in the special case where the type is a coercion of a `Set`,
allowing for smoother interactions with the `Set` API.
`Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even
though it takes values in a less convenient type. It is probably the right choice in settings where
one is concerned with the cardinalities of sets that may or may not be infinite.
`Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to
make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the
obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'.
When working with sets that are finite by virtue of their definition, then `Finset.card` probably
makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`,
where every set is automatically finite. In this setting, we use default arguments and a simple
tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems.
## Main Definitions
* `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if
`s` is infinite.
* `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite.
If `s` is Infinite, then `Set.ncard s = 0`.
* `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with
`Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance.
## Implementation Notes
The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations
instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the
`Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API
for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard`
in the future.
Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We
provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`,
where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite`
type.
Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other
in the context of the theorem, in which case we only include the ones that are needed, and derive
the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require
finiteness arguments; they are true by coincidence due to junk values.
-/
namespace Set
variable {α β : Type*} {s t : Set α}
/-- The cardinality of a set as a term in `ℕ∞` -/
noncomputable def encard (s : Set α) : ℕ∞ := ENat.card s
@[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by
rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)]
theorem encard_univ (α : Type*) :
encard (univ : Set α) = ENat.card α := by
rw [encard, ENat.card_congr (Equiv.Set.univ α)]
theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by
have := h.fintype
rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card]
theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by
have h := toFinite s
rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset]
@[simp] theorem toENat_cardinalMk (s : Set α) : (Cardinal.mk s).toENat = s.encard := rfl
theorem toENat_cardinalMk_subtype (P : α → Prop) :
(Cardinal.mk {x // P x}).toENat = {x | P x}.encard :=
rfl
@[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by
simp [encard_eq_coe_toFinset_card]
@[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) :
encard (s : Set α) = s.card := by
rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp
@[simp] theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
have := h.to_subtype
rw [encard, ENat.card_eq_top_of_infinite]
@[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by
rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem]
@[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by
rw [encard_eq_zero]
theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by
rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero]
theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty]
@[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, encard_ne_zero]
protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos
@[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by
rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
classical
simp [encard, ENat.card_congr (Equiv.Set.union h)]
theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
induction s, h using Set.Finite.induction_on with
| empty => simp
| insert hat _ ht' =>
rw [encard_insert_of_not_mem hat]
exact lt_tsub_iff_right.1 ht'
theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard :=
(ENat.coe_toNat h.encard_lt_top.ne).symm
theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n :=
⟨_, h.encard_eq_coe⟩
@[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite :=
⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩
@[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff
theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by
simp
theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _)
theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite :=
finite_of_encard_le_coe h.le
theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k :=
⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩,
fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩
@[simp]
theorem encard_prod : (s ×ˢ t).encard = s.encard * t.encard := by
simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)]
section Lattice
theorem encard_le_encard (h : s ⊆ t) : s.encard ≤ t.encard := by
rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
@[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard
theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) :=
fun _ _ ↦ encard_le_encard
theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h]
@[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero]
theorem encard_diff_add_encard_inter (s t : Set α) :
(s \ t).encard + (s ∩ t).encard = s.encard := by
rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left),
diff_union_inter]
theorem encard_union_add_encard_inter (s t : Set α) :
(s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by
rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm,
encard_diff_add_encard_inter]
theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) :
s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_right_inj h.encard_lt_top.ne]
theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) :
s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_le_add_iff_right h.encard_lt_top.ne]
theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) :
s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_lt_add_iff_right h.encard_lt_top.ne]
theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by
rw [← encard_union_add_encard_inter]; exact le_self_add
theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by
rw [← encard_lt_top_iff, ← encard_lt_top_iff, h]
theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) :
s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff]
theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite)
(h : t.encard ≤ s.encard) : t.Finite :=
encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top)
lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
s = t := by
rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts
rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff
exact hst.antisymm hdiff
theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s ⊆ t)
(hts : t.encard ≤ s.encard) : s = t :=
(hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts
theorem Finite.encard_lt_encard (hs : s.Finite) (h : s ⊂ t) : s.encard < t.encard :=
(encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le)
theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) :=
fun _ _ h ↦ (toFinite _).encard_lt_encard h
theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self]
theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard :=
(encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm
theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by
rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard
theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by
rw [← encard_union_eq disjoint_compl_right, union_compl_self]
end Lattice
section InsertErase
variable {a b : α}
theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
rw [← encard_singleton x]; exact encard_le_encard inter_subset_left
theorem encard_diff_singleton_add_one (h : a ∈ s) :
(s \ {a}).encard + 1 = s.encard := by
rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h]
theorem encard_diff_singleton_of_mem (h : a ∈ s) :
(s \ {a}).encard = s.encard - 1 := by
rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top,
tsub_add_cancel_of_le (self_le_add_left _ _)]
theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) :
s.encard - 1 ≤ (s \ {x}).encard := by
rw [← encard_singleton x]; apply tsub_encard_le_encard_diff
theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by
rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb]
simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true]
theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by
rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb]
theorem encard_eq_add_one_iff {k : ℕ∞} :
s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩
rw [← WithTop.add_right_inj WithTop.one_ne_top, ← h,
encard_diff_singleton_add_one ha]
rintro ⟨a, t, h, rfl, rfl⟩
rw [encard_insert_of_not_mem h]
/-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended
for well-founded induction on the value of `encard`. -/
theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) :
s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by
refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦
(s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq)))
rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)]
exact WithTop.add_lt_add_left hfin.diff.encard_lt_top.ne zero_lt_one
end InsertErase
section SmallSets
theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two,
WithTop.add_right_inj WithTop.one_ne_top, encard_singleton]
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le (by simpa) (by simp [h])).symm⟩
theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by
rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero,
encard_eq_one]
theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by
rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty]
refine ⟨fun h a b has hbs ↦ ?_,
fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩
obtain ⟨x, rfl⟩ := h ⟨_, has⟩
rw [(has : a = x), (hbs : b = x)]
theorem encard_le_one_iff_subsingleton : s.encard ≤ 1 ↔ s.Subsingleton := by
rw [encard_le_one_iff, Set.Subsingleton]
tauto
theorem one_lt_encard_iff_nontrivial : 1 < s.encard ↔ s.Nontrivial := by
rw [← not_iff_not, not_lt, Set.not_nontrivial_iff, ← encard_le_one_iff_subsingleton]
theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by
rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop
theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by
by_contra! h'
obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h
apply hne
rw [h' b hb, h' b' hb']
theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl),
← one_add_one_eq_two, WithTop.add_right_inj (WithTop.one_ne_top), encard_eq_one] at h
obtain ⟨y, h⟩ := h
refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩
rw [← h, insert_diff_singleton, insert_eq_of_mem hx]
theorem encard_eq_three {α : Type u_1} {s : Set α} :
encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩
· obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton,
encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1),
WithTop.add_right_inj WithTop.one_ne_top, encard_eq_two] at h
obtain ⟨y, z, hne, hs⟩ := h
refine ⟨x, y, z, ?_, ?_, hne, ?_⟩
· rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl
· rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl
rw [← hs, insert_diff_singleton, insert_eq_of_mem hx]
rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop
theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by
convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1
· rw [Finset.coe_range, Iio_def]
rw [Finset.card_range]
end SmallSets
theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t)
(hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by
rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_inj hs.encard_lt_top.ne,
encard_eq_one] at hst
obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union]
theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
revert hk
refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_
· obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
simp only [Nat.cast_succ] at *
have hne : t₀ ≠ s := by
rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩
simp only [top_le_iff, encard_eq_top_iff]
exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩
theorem exists_superset_subset_encard_eq {k : ℕ∞}
(hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
obtain (hs | hs) := eq_or_ne s.encard ⊤
· rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
obtain ⟨k, rfl⟩ := exists_add_of_le hsk
obtain ⟨k', hk'⟩ := exists_add_of_le hkt
have hk : k ≤ encard (t \ s) := by
rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt
exact WithTop.le_of_add_le_add_right hs hkt
obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk
refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩
rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)]
section Function
variable {s : Set α} {t : Set β} {f : α → β}
| Mathlib/Data/Set/Card.lean | 402 | 408 | theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by | rw [encard, ENat.card_image_of_injOn h, encard]
theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by
rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, ENat.card_congr e]
theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) : |
/-
Copyright (c) 2021 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Regular.Basic
import Mathlib.GroupTheory.GroupAction.Hom
/-!
# Action of regular elements on a module
We introduce `M`-regular elements, in the context of an `R`-module `M`. The corresponding
predicate is called `IsSMulRegular`.
There are very limited typeclass assumptions on `R` and `M`, but the "mathematical" case of interest
is a commutative ring `R` acting on a module `M`. Since the properties are "multiplicative", there
is no actual requirement of having an addition, but there is a zero in both `R` and `M`.
SMultiplications involving `0` are, of course, all trivial.
The defining property is that an element `a ∈ R` is `M`-regular if the smultiplication map
`M → M`, defined by `m ↦ a • m`, is injective.
This property is the direct generalization to modules of the property `IsLeftRegular` defined in
`Algebra/Regular`. Lemma `isLeftRegular_iff` shows that indeed the two notions
coincide.
-/
variable {R S : Type*} (M : Type*) {a b : R} {s : S}
/-- An `M`-regular element is an element `c` such that multiplication on the left by `c` is an
injective map `M → M`. -/
def IsSMulRegular [SMul R M] (c : R) :=
Function.Injective ((c • ·) : M → M)
theorem IsLeftRegular.isSMulRegular [Mul R] {c : R} (h : IsLeftRegular c) : IsSMulRegular R c :=
h
/-- Left-regular multiplication on `R` is equivalent to `R`-regularity of `R` itself. -/
theorem isLeftRegular_iff [Mul R] {a : R} : IsLeftRegular a ↔ IsSMulRegular R a :=
Iff.rfl
theorem IsRightRegular.isSMulRegular [Mul R] {c : R} (h : IsRightRegular c) :
IsSMulRegular R (MulOpposite.op c) :=
h
/-- Right-regular multiplication on `R` is equivalent to `Rᵐᵒᵖ`-regularity of `R` itself. -/
theorem isRightRegular_iff [Mul R] {a : R} :
IsRightRegular a ↔ IsSMulRegular R (MulOpposite.op a) :=
Iff.rfl
namespace IsSMulRegular
variable {M}
section SMul
variable [SMul R M] [SMul R S] [SMul S M] [IsScalarTower R S M]
/-- The product of `M`-regular elements is `M`-regular. -/
theorem smul (ra : IsSMulRegular M a) (rs : IsSMulRegular M s) : IsSMulRegular M (a • s) :=
fun _ _ ab => rs (ra ((smul_assoc _ _ _).symm.trans (ab.trans (smul_assoc _ _ _))))
/-- If an element `b` becomes `M`-regular after multiplying it on the left by an `M`-regular
element, then `b` is `M`-regular. -/
theorem of_smul (a : R) (ab : IsSMulRegular M (a • s)) : IsSMulRegular M s :=
@Function.Injective.of_comp _ _ _ (fun m : M => a • m) _ fun c d cd => by
dsimp only [Function.comp_def] at cd
rw [← smul_assoc, ← smul_assoc] at cd
exact ab cd
/-- An element is `M`-regular if and only if multiplying it on the left by an `M`-regular element
is `M`-regular. -/
@[simp]
theorem smul_iff (b : S) (ha : IsSMulRegular M a) : IsSMulRegular M (a • b) ↔ IsSMulRegular M b :=
⟨of_smul _, ha.smul⟩
theorem isLeftRegular [Mul R] {a : R} (h : IsSMulRegular R a) : IsLeftRegular a :=
h
theorem isRightRegular [Mul R] {a : R} (h : IsSMulRegular R (MulOpposite.op a)) :
IsRightRegular a :=
h
theorem mul [Mul R] [IsScalarTower R R M] (ra : IsSMulRegular M a) (rb : IsSMulRegular M b) :
IsSMulRegular M (a * b) :=
ra.smul rb
theorem of_mul [Mul R] [IsScalarTower R R M] (ab : IsSMulRegular M (a * b)) :
IsSMulRegular M b := by
rw [← smul_eq_mul] at ab
exact ab.of_smul _
@[simp]
theorem mul_iff_right [Mul R] [IsScalarTower R R M] (ha : IsSMulRegular M a) :
IsSMulRegular M (a * b) ↔ IsSMulRegular M b :=
⟨of_mul, ha.mul⟩
/-- Two elements `a` and `b` are `M`-regular if and only if both products `a * b` and `b * a`
are `M`-regular. -/
theorem mul_and_mul_iff [Mul R] [IsScalarTower R R M] :
IsSMulRegular M (a * b) ∧ IsSMulRegular M (b * a) ↔ IsSMulRegular M a ∧ IsSMulRegular M b := by
refine ⟨?_, ?_⟩
· rintro ⟨ab, ba⟩
exact ⟨ba.of_mul, ab.of_mul⟩
· rintro ⟨ha, hb⟩
exact ⟨ha.mul hb, hb.mul ha⟩
lemma of_injective {N F} [SMul R N] [FunLike F M N] [MulActionHomClass F R M N]
(f : F) {r : R} (h1 : Function.Injective f) (h2 : IsSMulRegular N r) :
IsSMulRegular M r := fun x y h3 => h1 <| h2 <|
(map_smulₛₗ f r x).symm.trans ((congrArg f h3).trans (map_smulₛₗ f r y))
end SMul
section Monoid
variable [Monoid R] [MulAction R M]
variable (M)
/-- One is always `M`-regular. -/
@[simp]
theorem one : IsSMulRegular M (1 : R) := fun a b ab => by
dsimp only [Function.comp_def] at ab
rw [one_smul, one_smul] at ab
assumption
variable {M}
/-- An element of `R` admitting a left inverse is `M`-regular. -/
theorem of_mul_eq_one (h : a * b = 1) : IsSMulRegular M b :=
of_mul (a := a) (by rw [h]; exact one M)
/-- Any power of an `M`-regular element is `M`-regular. -/
theorem pow (n : ℕ) (ra : IsSMulRegular M a) : IsSMulRegular M (a ^ n) := by
induction n with
| zero => rw [pow_zero]; simp only [one]
| succ n hn =>
rw [pow_succ']
exact (ra.smul_iff (a ^ n)).mpr hn
/-- An element `a` is `M`-regular if and only if a positive power of `a` is `M`-regular. -/
theorem pow_iff {n : ℕ} (n0 : 0 < n) : IsSMulRegular M (a ^ n) ↔ IsSMulRegular M a := by
refine ⟨?_, pow n⟩
rw [← Nat.succ_pred_eq_of_pos n0, pow_succ, ← smul_eq_mul]
exact of_smul _
end Monoid
section MonoidSMul
variable [Monoid S] [SMul R M] [SMul R S] [MulAction S M] [IsScalarTower R S M]
/-- An element of `S` admitting a left inverse in `R` is `M`-regular. -/
theorem of_smul_eq_one (h : a • s = 1) : IsSMulRegular M s :=
of_smul a
(by
rw [h]
exact one M)
end MonoidSMul
section MonoidWithZero
variable [MonoidWithZero R] [Zero M] [MulActionWithZero R M]
/-- The element `0` is `M`-regular if and only if `M` is trivial. -/
protected theorem subsingleton (h : IsSMulRegular M (0 : R)) : Subsingleton M :=
⟨fun a b => h (by dsimp only [Function.comp_def]; repeat' rw [MulActionWithZero.zero_smul])⟩
/-- The element `0` is `M`-regular if and only if `M` is trivial. -/
theorem zero_iff_subsingleton : IsSMulRegular M (0 : R) ↔ Subsingleton M :=
⟨fun h => h.subsingleton, fun H a b _ => @Subsingleton.elim _ H a b⟩
/-- The `0` element is not `M`-regular, on a non-trivial module. -/
theorem not_zero_iff : ¬IsSMulRegular M (0 : R) ↔ Nontrivial M := by
rw [nontrivial_iff, not_iff_comm, zero_iff_subsingleton, subsingleton_iff]
push_neg
exact Iff.rfl
/-- The element `0` is `M`-regular when `M` is trivial. -/
theorem zero [sM : Subsingleton M] : IsSMulRegular M (0 : R) :=
zero_iff_subsingleton.mpr sM
/-- The `0` element is not `M`-regular, on a non-trivial module. -/
theorem not_zero [nM : Nontrivial M] : ¬IsSMulRegular M (0 : R) :=
not_zero_iff.mpr nM
end MonoidWithZero
section CommSemigroup
variable [CommSemigroup R] [SMul R M] [IsScalarTower R R M]
/-- A product is `M`-regular if and only if the factors are. -/
theorem mul_iff : IsSMulRegular M (a * b) ↔ IsSMulRegular M a ∧ IsSMulRegular M b := by
rw [← mul_and_mul_iff]
exact ⟨fun ab => ⟨ab, by rwa [mul_comm]⟩, fun rab => rab.1⟩
end CommSemigroup
end IsSMulRegular
section Group
variable {G : Type*} [Group G]
/-- An element of a group acting on a Type is regular. This relies on the availability
of the inverse given by groups, since there is no `LeftCancelSMul` typeclass. -/
theorem isSMulRegular_of_group [MulAction G R] (g : G) : IsSMulRegular R g := by
intro x y h
convert congr_arg (g⁻¹ • ·) h using 1 <;> simp [← smul_assoc]
end Group
section Units
variable [Monoid R] [MulAction R M]
/-- Any element in `Rˣ` is `M`-regular. -/
theorem Units.isSMulRegular (a : Rˣ) : IsSMulRegular M (a : R) :=
IsSMulRegular.of_mul_eq_one a.inv_val
/-- A unit is `M`-regular. -/
| Mathlib/Algebra/Regular/SMul.lean | 225 | 227 | theorem IsUnit.isSMulRegular (ua : IsUnit a) : IsSMulRegular M a := by | rcases ua with ⟨a, rfl⟩
exact a.isSMulRegular M |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Aurélien Saue, Anne Baanen
-/
import Mathlib.Tactic.NormNum.Inv
import Mathlib.Tactic.NormNum.Pow
import Mathlib.Util.AtomM
/-!
# `ring` tactic
A tactic for solving equations in commutative (semi)rings,
where the exponents can also contain variables.
Based on <http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf> .
More precisely, expressions of the following form are supported:
- constants (non-negative integers)
- variables
- coefficients (any rational number, embedded into the (semi)ring)
- addition of expressions
- multiplication of expressions (`a * b`)
- scalar multiplication of expressions (`n • a`; the multiplier must have type `ℕ`)
- exponentiation of expressions (the exponent must have type `ℕ`)
- subtraction and negation of expressions (if the base is a full ring)
The extension to exponents means that something like `2 * 2^n * b = b * 2^(n+1)` can be proved,
even though it is not strictly speaking an equation in the language of commutative rings.
## Implementation notes
The basic approach to prove equalities is to normalise both sides and check for equality.
The normalisation is guided by building a value in the type `ExSum` at the meta level,
together with a proof (at the base level) that the original value is equal to
the normalised version.
The outline of the file:
- Define a mutual inductive family of types `ExSum`, `ExProd`, `ExBase`,
which can represent expressions with `+`, `*`, `^` and rational numerals.
The mutual induction ensures that associativity and distributivity are applied,
by restricting which kinds of subexpressions appear as arguments to the various operators.
- Represent addition, multiplication and exponentiation in the `ExSum` type,
thus allowing us to map expressions to `ExSum` (the `eval` function drives this).
We apply associativity and distributivity of the operators here (helped by `Ex*` types)
and commutativity as well (by sorting the subterms; unfortunately not helped by anything).
Any expression not of the above formats is treated as an atom (the same as a variable).
There are some details we glossed over which make the plan more complicated:
- The order on atoms is not initially obvious.
We construct a list containing them in order of initial appearance in the expression,
then use the index into the list as a key to order on.
- For `pow`, the exponent must be a natural number, while the base can be any semiring `α`.
We swap out operations for the base ring `α` with those for the exponent ring `ℕ`
as soon as we deal with exponents.
## Caveats and future work
The normalized form of an expression is the one that is useful for the tactic,
but not as nice to read. To remedy this, the user-facing normalization calls `ringNFCore`.
Subtraction cancels out identical terms, but division does not.
That is: `a - a = 0 := by ring` solves the goal,
but `a / a := 1 by ring` doesn't.
Note that `0 / 0` is generally defined to be `0`,
so division cancelling out is not true in general.
Multiplication of powers can be simplified a little bit further:
`2 ^ n * 2 ^ n = 4 ^ n := by ring` could be implemented
in a similar way that `2 * a + 2 * a = 4 * a := by ring` already works.
This feature wasn't needed yet, so it's not implemented yet.
## Tags
ring, semiring, exponent, power
-/
assert_not_exists OrderedAddCommMonoid
namespace Mathlib.Tactic
namespace Ring
open Mathlib.Meta Qq NormNum Lean.Meta AtomM
attribute [local instance] monadLiftOptionMetaM
open Lean (MetaM Expr mkRawNatLit)
/-- A shortcut instance for `CommSemiring ℕ` used by ring. -/
def instCommSemiringNat : CommSemiring ℕ := inferInstance
/--
A typed expression of type `CommSemiring ℕ` used when we are working on
ring subexpressions of type `ℕ`.
-/
def sℕ : Q(CommSemiring ℕ) := q(instCommSemiringNat)
mutual
/-- The base `e` of a normalized exponent expression. -/
inductive ExBase : ∀ {u : Lean.Level} {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type
/--
An atomic expression `e` with id `id`.
Atomic expressions are those which `ring` cannot parse any further.
For instance, `a + (a % b)` has `a` and `(a % b)` as atoms.
The `ring1` tactic does not normalize the subexpressions in atoms, but `ring_nf` does.
Atoms in fact represent equivalence classes of expressions, modulo definitional equality.
The field `index : ℕ` should be a unique number for each class,
while `value : expr` contains a representative of this class.
The function `resolve_atom` determines the appropriate atom for a given expression.
-/
| atom {sα} {e} (id : ℕ) : ExBase sα e
/-- A sum of monomials. -/
| sum {sα} {e} (_ : ExSum sα e) : ExBase sα e
/--
A monomial, which is a product of powers of `ExBase` expressions,
terminated by a (nonzero) constant coefficient.
-/
inductive ExProd : ∀ {u : Lean.Level} {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type
/-- A coefficient `value`, which must not be `0`. `e` is a raw rat cast.
If `value` is not an integer, then `hyp` should be a proof of `(value.den : α) ≠ 0`. -/
| const {sα} {e} (value : ℚ) (hyp : Option Expr := none) : ExProd sα e
/-- A product `x ^ e * b` is a monomial if `b` is a monomial. Here `x` is an `ExBase`
and `e` is an `ExProd` representing a monomial expression in `ℕ` (it is a monomial instead of
a polynomial because we eagerly normalize `x ^ (a + b) = x ^ a * x ^ b`.) -/
| mul {u : Lean.Level} {α : Q(Type u)} {sα} {x : Q($α)} {e : Q(ℕ)} {b : Q($α)} :
ExBase sα x → ExProd sℕ e → ExProd sα b → ExProd sα q($x ^ $e * $b)
/-- A polynomial expression, which is a sum of monomials. -/
inductive ExSum : ∀ {u : Lean.Level} {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type
/-- Zero is a polynomial. `e` is the expression `0`. -/
| zero {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} : ExSum sα q(0 : $α)
/-- A sum `a + b` is a polynomial if `a` is a monomial and `b` is another polynomial. -/
| add {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExProd sα a → ExSum sα b → ExSum sα q($a + $b)
end
mutual -- partial only to speed up compilation
/-- Equality test for expressions. This is not a `BEq` instance because it is heterogeneous. -/
partial def ExBase.eq
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExBase sα a → ExBase sα b → Bool
| .atom i, .atom j => i == j
| .sum a, .sum b => a.eq b
| _, _ => false
@[inherit_doc ExBase.eq]
partial def ExProd.eq
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExProd sα a → ExProd sα b → Bool
| .const i _, .const j _ => i == j
| .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => a₁.eq b₁ && a₂.eq b₂ && a₃.eq b₃
| _, _ => false
@[inherit_doc ExBase.eq]
partial def ExSum.eq
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExSum sα a → ExSum sα b → Bool
| .zero, .zero => true
| .add a₁ a₂, .add b₁ b₂ => a₁.eq b₁ && a₂.eq b₂
| _, _ => false
end
mutual -- partial only to speed up compilation
/--
A total order on normalized expressions.
This is not an `Ord` instance because it is heterogeneous.
-/
partial def ExBase.cmp
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExBase sα a → ExBase sα b → Ordering
| .atom i, .atom j => compare i j
| .sum a, .sum b => a.cmp b
| .atom .., .sum .. => .lt
| .sum .., .atom .. => .gt
@[inherit_doc ExBase.cmp]
partial def ExProd.cmp
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExProd sα a → ExProd sα b → Ordering
| .const i _, .const j _ => compare i j
| .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => (a₁.cmp b₁).then (a₂.cmp b₂) |>.then (a₃.cmp b₃)
| .const _ _, .mul .. => .lt
| .mul .., .const _ _ => .gt
@[inherit_doc ExBase.cmp]
partial def ExSum.cmp
{u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} :
ExSum sα a → ExSum sα b → Ordering
| .zero, .zero => .eq
| .add a₁ a₂, .add b₁ b₂ => (a₁.cmp b₁).then (a₂.cmp b₂)
| .zero, .add .. => .lt
| .add .., .zero => .gt
end
variable {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)}
instance : Inhabited (Σ e, (ExBase sα) e) := ⟨default, .atom 0⟩
instance : Inhabited (Σ e, (ExSum sα) e) := ⟨_, .zero⟩
instance : Inhabited (Σ e, (ExProd sα) e) := ⟨default, .const 0 none⟩
mutual
/-- Converts `ExBase sα` to `ExBase sβ`, assuming `sα` and `sβ` are defeq. -/
partial def ExBase.cast
{v : Lean.Level} {β : Q(Type v)} {sβ : Q(CommSemiring $β)} {a : Q($α)} :
ExBase sα a → Σ a, ExBase sβ a
| .atom i => ⟨a, .atom i⟩
| .sum a => let ⟨_, vb⟩ := a.cast; ⟨_, .sum vb⟩
/-- Converts `ExProd sα` to `ExProd sβ`, assuming `sα` and `sβ` are defeq. -/
partial def ExProd.cast
{v : Lean.Level} {β : Q(Type v)} {sβ : Q(CommSemiring $β)} {a : Q($α)} :
ExProd sα a → Σ a, ExProd sβ a
| .const i h => ⟨a, .const i h⟩
| .mul a₁ a₂ a₃ => ⟨_, .mul a₁.cast.2 a₂ a₃.cast.2⟩
/-- Converts `ExSum sα` to `ExSum sβ`, assuming `sα` and `sβ` are defeq. -/
partial def ExSum.cast
{v : Lean.Level} {β : Q(Type v)} {sβ : Q(CommSemiring $β)} {a : Q($α)} :
ExSum sα a → Σ a, ExSum sβ a
| .zero => ⟨_, .zero⟩
| .add a₁ a₂ => ⟨_, .add a₁.cast.2 a₂.cast.2⟩
end
variable {u : Lean.Level}
/--
The result of evaluating an (unnormalized) expression `e` into the type family `E`
(one of `ExSum`, `ExProd`, `ExBase`) is a (normalized) element `e'`
and a representation `E e'` for it, and a proof of `e = e'`.
-/
structure Result {α : Q(Type u)} (E : Q($α) → Type) (e : Q($α)) where
/-- The normalized result. -/
expr : Q($α)
/-- The data associated to the normalization. -/
val : E expr
/-- A proof that the original expression is equal to the normalized result. -/
proof : Q($e = $expr)
instance {α : Q(Type u)} {E : Q($α) → Type} {e : Q($α)} [Inhabited (Σ e, E e)] :
Inhabited (Result E e) :=
let ⟨e', v⟩ : Σ e, E e := default; ⟨e', v, default⟩
variable {α : Q(Type u)} (sα : Q(CommSemiring $α)) {R : Type*} [CommSemiring R]
/--
Constructs the expression corresponding to `.const n`.
(The `.const` constructor does not check that the expression is correct.)
-/
def ExProd.mkNat (n : ℕ) : (e : Q($α)) × ExProd sα e :=
let lit : Q(ℕ) := mkRawNatLit n
⟨q(($lit).rawCast : $α), .const n none⟩
/--
Constructs the expression corresponding to `.const (-n)`.
(The `.const` constructor does not check that the expression is correct.)
-/
def ExProd.mkNegNat (_ : Q(Ring $α)) (n : ℕ) : (e : Q($α)) × ExProd sα e :=
let lit : Q(ℕ) := mkRawNatLit n
⟨q((Int.negOfNat $lit).rawCast : $α), .const (-n) none⟩
/--
Constructs the expression corresponding to `.const q h` for `q = n / d`
and `h` a proof that `(d : α) ≠ 0`.
(The `.const` constructor does not check that the expression is correct.)
-/
def ExProd.mkRat (_ : Q(DivisionRing $α)) (q : ℚ) (n : Q(ℤ)) (d : Q(ℕ)) (h : Expr) :
(e : Q($α)) × ExProd sα e :=
⟨q(Rat.rawCast $n $d : $α), .const q h⟩
section
/-- Embed an exponent (an `ExBase, ExProd` pair) as an `ExProd` by multiplying by 1. -/
def ExBase.toProd {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a : Q($α)} {b : Q(ℕ)}
(va : ExBase sα a) (vb : ExProd sℕ b) :
ExProd sα q($a ^ $b * (nat_lit 1).rawCast) := .mul va vb (.const 1 none)
/-- Embed `ExProd` in `ExSum` by adding 0. -/
def ExProd.toSum {sα : Q(CommSemiring $α)} {e : Q($α)} (v : ExProd sα e) : ExSum sα q($e + 0) :=
.add v .zero
/-- Get the leading coefficient of an `ExProd`. -/
def ExProd.coeff {sα : Q(CommSemiring $α)} {e : Q($α)} : ExProd sα e → ℚ
| .const q _ => q
| .mul _ _ v => v.coeff
end
/--
Two monomials are said to "overlap" if they differ by a constant factor, in which case the
constants just add. When this happens, the constant may be either zero (if the monomials cancel)
or nonzero (if they add up); the zero case is handled specially.
-/
inductive Overlap (e : Q($α)) where
/-- The expression `e` (the sum of monomials) is equal to `0`. -/
| zero (_ : Q(IsNat $e (nat_lit 0)))
/-- The expression `e` (the sum of monomials) is equal to another monomial
(with nonzero leading coefficient). -/
| nonzero (_ : Result (ExProd sα) e)
variable {a a' a₁ a₂ a₃ b b' b₁ b₂ b₃ c c₁ c₂ : R}
theorem add_overlap_pf (x : R) (e) (pq_pf : a + b = c) :
x ^ e * a + x ^ e * b = x ^ e * c := by subst_vars; simp [mul_add]
theorem add_overlap_pf_zero (x : R) (e) :
IsNat (a + b) (nat_lit 0) → IsNat (x ^ e * a + x ^ e * b) (nat_lit 0)
| ⟨h⟩ => ⟨by simp [h, ← mul_add]⟩
-- TODO: decide if this is a good idea globally in
-- https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/.60MonadLift.20Option.20.28OptionT.20m.29.60/near/469097834
private local instance {m} [Pure m] : MonadLift Option (OptionT m) where
monadLift f := .mk <| pure f
/--
Given monomials `va, vb`, attempts to add them together to get another monomial.
If the monomials are not compatible, returns `none`.
For example, `xy + 2xy = 3xy` is a `.nonzero` overlap, while `xy + xz` returns `none`
and `xy + -xy = 0` is a `.zero` overlap.
-/
def evalAddOverlap {a b : Q($α)} (va : ExProd sα a) (vb : ExProd sα b) :
OptionT Lean.Core.CoreM (Overlap sα q($a + $b)) := do
Lean.Core.checkSystem decl_name%.toString
match va, vb with
| .const za ha, .const zb hb => do
let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb
let res ← NormNum.evalAdd.core q($a + $b) q(HAdd.hAdd) a b ra rb
match res with
| .isNat _ (.lit (.natVal 0)) p => pure <| .zero p
| rc =>
let ⟨zc, hc⟩ ← rc.toRatNZ
let ⟨c, pc⟩ := rc.toRawEq
pure <| .nonzero ⟨c, .const zc hc, pc⟩
| .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .mul vb₁ vb₂ vb₃ => do
guard (va₁.eq vb₁ && va₂.eq vb₂)
match ← evalAddOverlap va₃ vb₃ with
| .zero p => pure <| .zero (q(add_overlap_pf_zero $a₁ $a₂ $p) : Expr)
| .nonzero ⟨_, vc, p⟩ =>
pure <| .nonzero ⟨_, .mul va₁ va₂ vc, (q(add_overlap_pf $a₁ $a₂ $p) : Expr)⟩
| _, _ => OptionT.fail
theorem add_pf_zero_add (b : R) : 0 + b = b := by simp
theorem add_pf_add_zero (a : R) : a + 0 = a := by simp
theorem add_pf_add_overlap
(_ : a₁ + b₁ = c₁) (_ : a₂ + b₂ = c₂) : (a₁ + a₂ : R) + (b₁ + b₂) = c₁ + c₂ := by
subst_vars; simp [add_assoc, add_left_comm]
theorem add_pf_add_overlap_zero
(h : IsNat (a₁ + b₁) (nat_lit 0)) (h₄ : a₂ + b₂ = c) : (a₁ + a₂ : R) + (b₁ + b₂) = c := by
subst_vars; rw [add_add_add_comm, h.1, Nat.cast_zero, add_pf_zero_add]
theorem add_pf_add_lt (a₁ : R) (_ : a₂ + b = c) : (a₁ + a₂) + b = a₁ + c := by simp [*, add_assoc]
theorem add_pf_add_gt (b₁ : R) (_ : a + b₂ = c) : a + (b₁ + b₂) = b₁ + c := by
subst_vars; simp [add_left_comm]
/-- Adds two polynomials `va, vb` together to get a normalized result polynomial.
* `0 + b = b`
* `a + 0 = a`
* `a * x + a * y = a * (x + y)` (for `x`, `y` coefficients; uses `evalAddOverlap`)
* `(a₁ + a₂) + (b₁ + b₂) = a₁ + (a₂ + (b₁ + b₂))` (if `a₁.lt b₁`)
* `(a₁ + a₂) + (b₁ + b₂) = b₁ + ((a₁ + a₂) + b₂)` (if not `a₁.lt b₁`)
-/
partial def evalAdd {a b : Q($α)} (va : ExSum sα a) (vb : ExSum sα b) :
Lean.Core.CoreM <| Result (ExSum sα) q($a + $b) := do
Lean.Core.checkSystem decl_name%.toString
match va, vb with
| .zero, vb => return ⟨b, vb, q(add_pf_zero_add $b)⟩
| va, .zero => return ⟨a, va, q(add_pf_add_zero $a)⟩
| .add (a := a₁) (b := _a₂) va₁ va₂, .add (a := b₁) (b := _b₂) vb₁ vb₂ =>
match ← (evalAddOverlap sα va₁ vb₁).run with
| some (.nonzero ⟨_, vc₁, pc₁⟩) =>
let ⟨_, vc₂, pc₂⟩ ← evalAdd va₂ vb₂
return ⟨_, .add vc₁ vc₂, q(add_pf_add_overlap $pc₁ $pc₂)⟩
| some (.zero pc₁) =>
let ⟨c₂, vc₂, pc₂⟩ ← evalAdd va₂ vb₂
return ⟨c₂, vc₂, q(add_pf_add_overlap_zero $pc₁ $pc₂)⟩
| none =>
if let .lt := va₁.cmp vb₁ then
let ⟨_c, vc, (pc : Q($_a₂ + ($b₁ + $_b₂) = $_c))⟩ ← evalAdd va₂ vb
return ⟨_, .add va₁ vc, q(add_pf_add_lt $a₁ $pc)⟩
else
let ⟨_c, vc, (pc : Q($a₁ + $_a₂ + $_b₂ = $_c))⟩ ← evalAdd va vb₂
return ⟨_, .add vb₁ vc, q(add_pf_add_gt $b₁ $pc)⟩
theorem one_mul (a : R) : (nat_lit 1).rawCast * a = a := by simp [Nat.rawCast]
theorem mul_one (a : R) : a * (nat_lit 1).rawCast = a := by simp [Nat.rawCast]
theorem mul_pf_left (a₁ : R) (a₂) (_ : a₃ * b = c) :
(a₁ ^ a₂ * a₃ : R) * b = a₁ ^ a₂ * c := by
subst_vars; rw [mul_assoc]
theorem mul_pf_right (b₁ : R) (b₂) (_ : a * b₃ = c) :
a * (b₁ ^ b₂ * b₃) = b₁ ^ b₂ * c := by
subst_vars; rw [mul_left_comm]
theorem mul_pp_pf_overlap {ea eb e : ℕ} (x : R) (_ : ea + eb = e) (_ : a₂ * b₂ = c) :
(x ^ ea * a₂ : R) * (x ^ eb * b₂) = x ^ e * c := by
subst_vars; simp [pow_add, mul_mul_mul_comm]
/-- Multiplies two monomials `va, vb` together to get a normalized result monomial.
* `x * y = (x * y)` (for `x`, `y` coefficients)
* `x * (b₁ * b₂) = b₁ * (b₂ * x)` (for `x` coefficient)
* `(a₁ * a₂) * y = a₁ * (a₂ * y)` (for `y` coefficient)
* `(x ^ ea * a₂) * (x ^ eb * b₂) = x ^ (ea + eb) * (a₂ * b₂)`
(if `ea` and `eb` are identical except coefficient)
* `(a₁ * a₂) * (b₁ * b₂) = a₁ * (a₂ * (b₁ * b₂))` (if `a₁.lt b₁`)
* `(a₁ * a₂) * (b₁ * b₂) = b₁ * ((a₁ * a₂) * b₂)` (if not `a₁.lt b₁`)
-/
partial def evalMulProd {a b : Q($α)} (va : ExProd sα a) (vb : ExProd sα b) :
Lean.Core.CoreM <| Result (ExProd sα) q($a * $b) := do
Lean.Core.checkSystem decl_name%.toString
match va, vb with
| .const za ha, .const zb hb =>
if za = 1 then
return ⟨b, .const zb hb, (q(one_mul $b) : Expr)⟩
else if zb = 1 then
return ⟨a, .const za ha, (q(mul_one $a) : Expr)⟩
else
let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb
let rc := (NormNum.evalMul.core q($a * $b) q(HMul.hMul) _ _
q(CommSemiring.toSemiring) ra rb).get!
let ⟨zc, hc⟩ := rc.toRatNZ.get!
let ⟨c, pc⟩ := rc.toRawEq
return ⟨c, .const zc hc, pc⟩
| .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .const _ _ =>
let ⟨_, vc, pc⟩ ← evalMulProd va₃ vb
return ⟨_, .mul va₁ va₂ vc, (q(mul_pf_left $a₁ $a₂ $pc) : Expr)⟩
| .const _ _, .mul (x := b₁) (e := b₂) vb₁ vb₂ vb₃ =>
let ⟨_, vc, pc⟩ ← evalMulProd va vb₃
return ⟨_, .mul vb₁ vb₂ vc, (q(mul_pf_right $b₁ $b₂ $pc) : Expr)⟩
| .mul (x := xa) (e := ea) vxa vea va₂, .mul (x := xb) (e := eb) vxb veb vb₂ => do
if vxa.eq vxb then
if let some (.nonzero ⟨_, ve, pe⟩) ← (evalAddOverlap sℕ vea veb).run then
let ⟨_, vc, pc⟩ ← evalMulProd va₂ vb₂
return ⟨_, .mul vxa ve vc, (q(mul_pp_pf_overlap $xa $pe $pc) : Expr)⟩
if let .lt := (vxa.cmp vxb).then (vea.cmp veb) then
let ⟨_, vc, pc⟩ ← evalMulProd va₂ vb
return ⟨_, .mul vxa vea vc, (q(mul_pf_left $xa $ea $pc) : Expr)⟩
else
let ⟨_, vc, pc⟩ ← evalMulProd va vb₂
return ⟨_, .mul vxb veb vc, (q(mul_pf_right $xb $eb $pc) : Expr)⟩
| Mathlib/Tactic/Ring/Basic.lean | 453 | 454 | theorem mul_zero (a : R) : a * 0 = 0 := by | simp |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro
-/
import Mathlib.Algebra.MvPolynomial.Eval
/-!
# Renaming variables of polynomials
This file establishes the `rename` operation on multivariate polynomials,
which modifies the set of variables.
## Main declarations
* `MvPolynomial.rename`
* `MvPolynomial.renameEquiv`
## Notation
As in other polynomial files, we typically use the notation:
+ `σ τ α : Type*` (indexing the variables)
+ `R S : Type*` `[CommSemiring R]` `[CommSemiring S]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s`
+ `r : R` elements of the coefficient ring
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ α`
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
variable {σ τ α R S : Type*} [CommSemiring R] [CommSemiring S]
namespace MvPolynomial
section Rename
/-- Rename all the variables in a multivariable polynomial. -/
def rename (f : σ → τ) : MvPolynomial σ R →ₐ[R] MvPolynomial τ R :=
aeval (X ∘ f)
theorem rename_C (f : σ → τ) (r : R) : rename f (C r) = C r :=
eval₂_C _ _ _
@[simp]
theorem rename_X (f : σ → τ) (i : σ) : rename f (X i : MvPolynomial σ R) = X (f i) :=
eval₂_X _ _ _
theorem map_rename (f : R →+* S) (g : σ → τ) (p : MvPolynomial σ R) :
map f (rename g p) = rename g (map f p) := by
apply MvPolynomial.induction_on p
(fun a => by simp only [map_C, rename_C])
(fun p q hp hq => by simp only [hp, hq, map_add]) fun p n hp => by
simp only [hp, rename_X, map_X, map_mul]
lemma map_comp_rename (f : R →+* S) (g : σ → τ) :
(map f).comp (rename g).toRingHom = (rename g).toRingHom.comp (map f) :=
RingHom.ext fun p ↦ map_rename f g p
@[simp]
theorem rename_rename (f : σ → τ) (g : τ → α) (p : MvPolynomial σ R) :
rename g (rename f p) = rename (g ∘ f) p :=
show rename g (eval₂ C (X ∘ f) p) = _ by
simp only [rename, aeval_eq_eval₂Hom]
-- Porting note: the Lean 3 proof of this was very fragile and included a nonterminal `simp`.
-- Hopefully this is less prone to breaking
rw [eval₂_comp_left (eval₂Hom (algebraMap R (MvPolynomial α R)) (X ∘ g)) C (X ∘ f) p]
simp only [comp_def, eval₂Hom_X']
refine eval₂Hom_congr ?_ rfl rfl
ext1; simp only [comp_apply, RingHom.coe_comp, eval₂Hom_C]
lemma rename_comp_rename (f : σ → τ) (g : τ → α) :
(rename (R := R) g).comp (rename f) = rename (g ∘ f) :=
AlgHom.ext fun p ↦ rename_rename f g p
@[simp]
theorem rename_id : rename id = AlgHom.id R (MvPolynomial σ R) :=
AlgHom.ext fun p ↦ eval₂_eta p
lemma rename_id_apply (p : MvPolynomial σ R) : rename id p = p := by
simp
theorem rename_monomial (f : σ → τ) (d : σ →₀ ℕ) (r : R) :
rename f (monomial d r) = monomial (d.mapDomain f) r := by
rw [rename, aeval_monomial, monomial_eq (s := Finsupp.mapDomain f d),
Finsupp.prod_mapDomain_index]
· rfl
· exact fun n => pow_zero _
· exact fun n i₁ i₂ => pow_add _ _ _
theorem rename_eq (f : σ → τ) (p : MvPolynomial σ R) :
rename f p = Finsupp.mapDomain (Finsupp.mapDomain f) p := by
simp only [rename, aeval_def, eval₂, Finsupp.mapDomain, algebraMap_eq, comp_apply,
X_pow_eq_monomial, ← monomial_finsupp_sum_index]
rfl
theorem rename_injective (f : σ → τ) (hf : Function.Injective f) :
Function.Injective (rename f : MvPolynomial σ R → MvPolynomial τ R) := by
have :
(rename f : MvPolynomial σ R → MvPolynomial τ R) = Finsupp.mapDomain (Finsupp.mapDomain f) :=
funext (rename_eq f)
rw [this]
exact Finsupp.mapDomain_injective (Finsupp.mapDomain_injective hf)
theorem rename_leftInverse {f : σ → τ} {g : τ → σ} (hf : Function.LeftInverse f g) :
Function.LeftInverse (rename f : MvPolynomial σ R → MvPolynomial τ R) (rename g) := by
intro x
simp [hf.comp_eq_id]
theorem rename_rightInverse {f : σ → τ} {g : τ → σ} (hf : Function.RightInverse f g) :
Function.RightInverse (rename f : MvPolynomial σ R → MvPolynomial τ R) (rename g) :=
rename_leftInverse hf
theorem rename_surjective (f : σ → τ) (hf : Function.Surjective f) :
Function.Surjective (rename f : MvPolynomial σ R → MvPolynomial τ R) :=
let ⟨_, hf⟩ := hf.hasRightInverse; rename_rightInverse hf |>.surjective
section
variable {f : σ → τ} (hf : Function.Injective f)
open Classical in
/-- Given a function between sets of variables `f : σ → τ` that is injective with proof `hf`,
`MvPolynomial.killCompl hf` is the `AlgHom` from `R[τ]` to `R[σ]` that is left inverse to
`rename f : R[σ] → R[τ]` and sends the variables in the complement of the range of `f` to `0`. -/
def killCompl : MvPolynomial τ R →ₐ[R] MvPolynomial σ R :=
aeval fun i => if h : i ∈ Set.range f then X <| (Equiv.ofInjective f hf).symm ⟨i, h⟩ else 0
theorem killCompl_C (r : R) : killCompl hf (C r) = C r := algHom_C _ _
theorem killCompl_comp_rename : (killCompl hf).comp (rename f) = AlgHom.id R _ :=
algHom_ext fun i => by
dsimp
rw [rename, killCompl, aeval_X, comp_apply, aeval_X, dif_pos, Equiv.ofInjective_symm_apply]
@[simp]
theorem killCompl_rename_app (p : MvPolynomial σ R) : killCompl hf (rename f p) = p :=
AlgHom.congr_fun (killCompl_comp_rename hf) p
end
section
variable (R)
/-- `MvPolynomial.rename e` is an equivalence when `e` is. -/
@[simps apply]
def renameEquiv (f : σ ≃ τ) : MvPolynomial σ R ≃ₐ[R] MvPolynomial τ R :=
{ rename f with
toFun := rename f
invFun := rename f.symm
left_inv := fun p => by rw [rename_rename, f.symm_comp_self, rename_id_apply]
right_inv := fun p => by rw [rename_rename, f.self_comp_symm, rename_id_apply] }
@[simp]
theorem renameEquiv_refl : renameEquiv R (Equiv.refl σ) = AlgEquiv.refl :=
AlgEquiv.ext (by simp)
@[simp]
theorem renameEquiv_symm (f : σ ≃ τ) : (renameEquiv R f).symm = renameEquiv R f.symm :=
rfl
@[simp]
theorem renameEquiv_trans (e : σ ≃ τ) (f : τ ≃ α) :
(renameEquiv R e).trans (renameEquiv R f) = renameEquiv R (e.trans f) :=
AlgEquiv.ext (rename_rename e f)
end
section
variable (f : R →+* S) (k : σ → τ) (g : τ → S) (p : MvPolynomial σ R)
theorem eval₂_rename : (rename k p).eval₂ f g = p.eval₂ f (g ∘ k) := by
apply MvPolynomial.induction_on p <;>
· intros
simp [*]
theorem eval_rename (g : τ → R) (p : MvPolynomial σ R) : eval g (rename k p) = eval (g ∘ k) p :=
eval₂_rename _ _ _ _
theorem eval₂Hom_rename : eval₂Hom f g (rename k p) = eval₂Hom f (g ∘ k) p :=
eval₂_rename _ _ _ _
theorem aeval_rename [Algebra R S] : aeval g (rename k p) = aeval (g ∘ k) p :=
eval₂Hom_rename _ _ _ _
lemma aeval_comp_rename [Algebra R S] :
(aeval (R := R) g).comp (rename k) = MvPolynomial.aeval (g ∘ k) :=
AlgHom.ext fun p ↦ aeval_rename k g p
theorem rename_eval₂ (g : τ → MvPolynomial σ R) :
rename k (p.eval₂ C (g ∘ k)) = (rename k p).eval₂ C (rename k ∘ g) := by
apply MvPolynomial.induction_on p <;>
· intros
simp [*]
theorem rename_prod_mk_eval₂ (j : τ) (g : σ → MvPolynomial σ R) :
rename (Prod.mk j) (p.eval₂ C g) = p.eval₂ C fun x => rename (Prod.mk j) (g x) := by
apply MvPolynomial.induction_on p <;>
· intros
simp [*]
theorem eval₂_rename_prod_mk (g : σ × τ → S) (i : σ) (p : MvPolynomial τ R) :
(rename (Prod.mk i) p).eval₂ f g = eval₂ f (fun j => g (i, j)) p := by
apply MvPolynomial.induction_on p <;>
· intros
simp [*]
theorem eval_rename_prod_mk (g : σ × τ → R) (i : σ) (p : MvPolynomial τ R) :
eval g (rename (Prod.mk i) p) = eval (fun j => g (i, j)) p :=
eval₂_rename_prod_mk (RingHom.id _) _ _ _
end
/-- Every polynomial is a polynomial in finitely many variables. -/
| Mathlib/Algebra/MvPolynomial/Rename.lean | 228 | 247 | theorem exists_finset_rename (p : MvPolynomial σ R) :
∃ (s : Finset σ) (q : MvPolynomial { x // x ∈ s } R), p = rename (↑) q := by | classical
apply induction_on p
· intro r
exact ⟨∅, C r, by rw [rename_C]⟩
· rintro p q ⟨s, p, rfl⟩ ⟨t, q, rfl⟩
refine ⟨s ∪ t, ⟨?_, ?_⟩⟩
· refine rename (Subtype.map id ?_) p + rename (Subtype.map id ?_) q <;>
simp +contextual only [id, true_or, or_true,
Finset.mem_union, forall_true_iff]
· simp only [rename_rename, map_add]
rfl
· rintro p n ⟨s, p, rfl⟩
refine ⟨insert n s, ⟨?_, ?_⟩⟩
· refine rename (Subtype.map id ?_) p * X ⟨n, s.mem_insert_self n⟩
simp +contextual only [id, or_true, Finset.mem_insert, forall_true_iff]
· simp only [rename_rename, rename_X, Subtype.coe_mk, map_mul]
rfl |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen
-/
import Mathlib.GroupTheory.Submonoid.Inverses
import Mathlib.RingTheory.FiniteType
import Mathlib.RingTheory.Localization.Defs
/-!
# Submonoid of inverses
## Main definitions
* `IsLocalization.invSubmonoid M S` is the submonoid of `S = M⁻¹R` consisting of inverses of
each element `x ∈ M`
## Implementation notes
See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview.
## Tags
localization, ring localization, commutative ring localization, characteristic predicate,
commutative ring, field of fractions
-/
variable {R : Type*} [CommRing R] (M : Submonoid R) (S : Type*) [CommRing S]
variable [Algebra R S]
open Function
namespace IsLocalization
section InvSubmonoid
/-- The submonoid of `S = M⁻¹R` consisting of `{ 1 / x | x ∈ M }`. -/
def invSubmonoid : Submonoid S :=
(M.map (algebraMap R S)).leftInv
variable [IsLocalization M S]
theorem submonoid_map_le_is_unit : M.map (algebraMap R S) ≤ IsUnit.submonoid S := by
rintro _ ⟨a, ha, rfl⟩
exact IsLocalization.map_units S ⟨_, ha⟩
/-- There is an equivalence of monoids between the image of `M` and `invSubmonoid`. -/
noncomputable abbrev equivInvSubmonoid : M.map (algebraMap R S) ≃* invSubmonoid M S :=
((M.map (algebraMap R S)).leftInvEquiv (submonoid_map_le_is_unit M S)).symm
/-- There is a canonical map from `M` to `invSubmonoid` sending `x` to `1 / x`. -/
noncomputable def toInvSubmonoid : M →* invSubmonoid M S :=
(equivInvSubmonoid M S).toMonoidHom.comp ((algebraMap R S : R →* S).submonoidMap M)
theorem toInvSubmonoid_surjective : Function.Surjective (toInvSubmonoid M S) :=
Function.Surjective.comp (β := M.map (algebraMap R S))
(Equiv.surjective (equivInvSubmonoid _ _).toEquiv) (MonoidHom.submonoidMap_surjective _ _)
@[simp]
theorem toInvSubmonoid_mul (m : M) : (toInvSubmonoid M S m : S) * algebraMap R S m = 1 :=
Submonoid.leftInvEquiv_symm_mul _ (submonoid_map_le_is_unit _ _) _
@[simp]
theorem mul_toInvSubmonoid (m : M) : algebraMap R S m * (toInvSubmonoid M S m : S) = 1 :=
Submonoid.mul_leftInvEquiv_symm _ (submonoid_map_le_is_unit _ _) ⟨_, _⟩
@[simp]
theorem smul_toInvSubmonoid (m : M) : m • (toInvSubmonoid M S m : S) = 1 := by
convert mul_toInvSubmonoid M S m
ext
rw [← Algebra.smul_def]
rfl
variable {S}
-- Porting note: `surj'` was taken, so use `surj''` instead
| Mathlib/RingTheory/Localization/InvSubmonoid.lean | 77 | 81 | theorem surj'' (z : S) : ∃ (r : R) (m : M), z = r • (toInvSubmonoid M S m : S) := by | rcases IsLocalization.surj M z with ⟨⟨r, m⟩, e : z * _ = algebraMap R S r⟩
refine ⟨r, m, ?_⟩
rw [Algebra.smul_def, ← e, mul_assoc]
simp |
/-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andreas Swerdlow
-/
import Mathlib.LinearAlgebra.Basis.Basic
import Mathlib.LinearAlgebra.BilinearMap
import Mathlib.LinearAlgebra.LinearIndependent.Lemmas
/-!
# Sesquilinear maps
This files provides properties about sesquilinear maps and forms. The maps considered are of the
form `M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M`, where `I₁ : R₁ →+* R` and `I₂ : R₂ →+* R` are ring homomorphisms and
`M₁` is a module over `R₁`, `M₂` is a module over `R₂` and `M` is a module over `R`.
Sesquilinear forms are the special case that `M₁ = M₂`, `M = R₁ = R₂ = R`, and `I₁ = RingHom.id R`.
Taking additionally `I₂ = RingHom.id R`, then one obtains bilinear forms.
Sesquilinear maps are a special case of the bilinear maps defined in `BilinearMap.lean` and `many`
basic lemmas about construction and elementary calculations are found there.
## Main declarations
* `IsOrtho`: states that two vectors are orthogonal with respect to a sesquilinear map
* `IsSymm`, `IsAlt`: states that a sesquilinear form is symmetric and alternating, respectively
* `orthogonalBilin`: provides the orthogonal complement with respect to sesquilinear form
## References
* <https://en.wikipedia.org/wiki/Sesquilinear_form#Over_arbitrary_rings>
## Tags
Sesquilinear form, Sesquilinear map,
-/
variable {R R₁ R₂ R₃ M M₁ M₂ M₃ Mₗ₁ Mₗ₁' Mₗ₂ Mₗ₂' K K₁ K₂ V V₁ V₂ n : Type*}
namespace LinearMap
/-! ### Orthogonal vectors -/
section CommRing
-- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps
variable [CommSemiring R] [CommSemiring R₁] [AddCommMonoid M₁] [Module R₁ M₁] [CommSemiring R₂]
[AddCommMonoid M₂] [Module R₂ M₂] [AddCommMonoid M] [Module R M]
{I₁ : R₁ →+* R} {I₂ : R₂ →+* R} {I₁' : R₁ →+* R}
/-- The proposition that two elements of a sesquilinear map space are orthogonal -/
def IsOrtho (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x : M₁) (y : M₂) : Prop :=
B x y = 0
theorem isOrtho_def {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} {x y} : B.IsOrtho x y ↔ B x y = 0 :=
Iff.rfl
theorem isOrtho_zero_left (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x) : IsOrtho B (0 : M₁) x := by
dsimp only [IsOrtho]
rw [map_zero B, zero_apply]
theorem isOrtho_zero_right (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x) : IsOrtho B x (0 : M₂) :=
map_zero (B x)
theorem isOrtho_flip {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M} {x y} : B.IsOrtho x y ↔ B.flip.IsOrtho y x := by
simp_rw [isOrtho_def, flip_apply]
open scoped Function in -- required for scoped `on` notation
/-- A set of vectors `v` is orthogonal with respect to some bilinear map `B` if and only
if for all `i ≠ j`, `B (v i) (v j) = 0`. For orthogonality between two elements, use
`BilinForm.isOrtho` -/
def IsOrthoᵢ (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M) (v : n → M₁) : Prop :=
Pairwise (B.IsOrtho on v)
theorem isOrthoᵢ_def {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M} {v : n → M₁} :
B.IsOrthoᵢ v ↔ ∀ i j : n, i ≠ j → B (v i) (v j) = 0 :=
Iff.rfl
theorem isOrthoᵢ_flip (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M) {v : n → M₁} :
B.IsOrthoᵢ v ↔ B.flip.IsOrthoᵢ v := by
simp_rw [isOrthoᵢ_def]
constructor <;> exact fun h i j hij ↦ h j i hij.symm
end CommRing
section Field
variable [Field K] [AddCommGroup V] [Module K V] [Field K₁] [AddCommGroup V₁] [Module K₁ V₁]
[Field K₂] [AddCommGroup V₂] [Module K₂ V₂]
{I₁ : K₁ →+* K} {I₂ : K₂ →+* K} {I₁' : K₁ →+* K} {J₁ : K →+* K} {J₂ : K →+* K}
-- todo: this also holds for [CommRing R] [IsDomain R] when J₁ is invertible
theorem ortho_smul_left {B : V₁ →ₛₗ[I₁] V₂ →ₛₗ[I₂] V} {x y} {a : K₁} (ha : a ≠ 0) :
IsOrtho B x y ↔ IsOrtho B (a • x) y := by
dsimp only [IsOrtho]
constructor <;> intro H
· rw [map_smulₛₗ₂, H, smul_zero]
· rw [map_smulₛₗ₂, smul_eq_zero] at H
rcases H with H | H
· rw [map_eq_zero I₁] at H
trivial
· exact H
-- todo: this also holds for [CommRing R] [IsDomain R] when J₂ is invertible
theorem ortho_smul_right {B : V₁ →ₛₗ[I₁] V₂ →ₛₗ[I₂] V} {x y} {a : K₂} {ha : a ≠ 0} :
IsOrtho B x y ↔ IsOrtho B x (a • y) := by
dsimp only [IsOrtho]
constructor <;> intro H
· rw [map_smulₛₗ, H, smul_zero]
· rw [map_smulₛₗ, smul_eq_zero] at H
rcases H with H | H
· simp only [map_eq_zero] at H
exfalso
exact ha H
· exact H
/-- A set of orthogonal vectors `v` with respect to some sesquilinear map `B` is linearly
independent if for all `i`, `B (v i) (v i) ≠ 0`. -/
theorem linearIndependent_of_isOrthoᵢ {B : V₁ →ₛₗ[I₁] V₁ →ₛₗ[I₁'] V} {v : n → V₁}
(hv₁ : B.IsOrthoᵢ v) (hv₂ : ∀ i, ¬B.IsOrtho (v i) (v i)) : LinearIndependent K₁ v := by
classical
rw [linearIndependent_iff']
intro s w hs i hi
have : B (s.sum fun i : n ↦ w i • v i) (v i) = 0 := by rw [hs, map_zero, zero_apply]
have hsum : (s.sum fun j : n ↦ I₁ (w j) • B (v j) (v i)) = I₁ (w i) • B (v i) (v i) := by
apply Finset.sum_eq_single_of_mem i hi
intro j _hj hij
rw [isOrthoᵢ_def.1 hv₁ _ _ hij, smul_zero]
simp_rw [B.map_sum₂, map_smulₛₗ₂, hsum] at this
apply (map_eq_zero I₁).mp
exact (smul_eq_zero.mp this).elim _root_.id (hv₂ i · |>.elim)
end Field
/-! ### Reflexive bilinear maps -/
section Reflexive
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁]
[Module R₁ M₁] {I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M}
/-- The proposition that a sesquilinear map is reflexive -/
def IsRefl (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M) : Prop :=
∀ x y, B x y = 0 → B y x = 0
namespace IsRefl
section
variable (H : B.IsRefl)
include H
theorem eq_zero : ∀ {x y}, B x y = 0 → B y x = 0 := fun {x y} ↦ H x y
theorem eq_iff {x y} : B x y = 0 ↔ B y x = 0 := ⟨H x y, H y x⟩
theorem ortho_comm {x y} : IsOrtho B x y ↔ IsOrtho B y x :=
⟨eq_zero H, eq_zero H⟩
theorem domRestrict (p : Submodule R₁ M₁) : (B.domRestrict₁₂ p p).IsRefl :=
fun _ _ ↦ by
simp_rw [domRestrict₁₂_apply]
exact H _ _
end
@[simp]
theorem flip_isRefl_iff : B.flip.IsRefl ↔ B.IsRefl :=
⟨fun h x y H ↦ h y x ((B.flip_apply _ _).trans H), fun h x y ↦ h y x⟩
theorem ker_flip_eq_bot (H : B.IsRefl) (h : LinearMap.ker B = ⊥) : LinearMap.ker B.flip = ⊥ := by
refine ker_eq_bot'.mpr fun _ hx ↦ ker_eq_bot'.mp h _ ?_
ext
exact H _ _ (LinearMap.congr_fun hx _)
theorem ker_eq_bot_iff_ker_flip_eq_bot (H : B.IsRefl) :
LinearMap.ker B = ⊥ ↔ LinearMap.ker B.flip = ⊥ := by
refine ⟨ker_flip_eq_bot H, fun h ↦ ?_⟩
exact (congr_arg _ B.flip_flip.symm).trans (ker_flip_eq_bot (flip_isRefl_iff.mpr H) h)
end IsRefl
end Reflexive
/-! ### Symmetric bilinear forms -/
section Symmetric
variable [CommSemiring R] [AddCommMonoid M] [Module R M] {I : R →+* R} {B : M →ₛₗ[I] M →ₗ[R] R}
/-- The proposition that a sesquilinear form is symmetric -/
def IsSymm (B : M →ₛₗ[I] M →ₗ[R] R) : Prop :=
∀ x y, I (B x y) = B y x
namespace IsSymm
protected theorem eq (H : B.IsSymm) (x y) : I (B x y) = B y x :=
H x y
theorem isRefl (H : B.IsSymm) : B.IsRefl := fun x y H1 ↦ by
rw [← H.eq]
simp [H1]
theorem ortho_comm (H : B.IsSymm) {x y} : IsOrtho B x y ↔ IsOrtho B y x :=
H.isRefl.ortho_comm
theorem domRestrict (H : B.IsSymm) (p : Submodule R M) : (B.domRestrict₁₂ p p).IsSymm :=
fun _ _ ↦ by
simp_rw [domRestrict₁₂_apply]
exact H _ _
end IsSymm
@[simp]
theorem isSymm_zero : (0 : M →ₛₗ[I] M →ₗ[R] R).IsSymm := fun _ _ => map_zero _
theorem BilinMap.isSymm_iff_eq_flip {N : Type*} [AddCommMonoid N] [Module R N]
{B : LinearMap.BilinMap R M N} : (∀ x y, B x y = B y x) ↔ B = B.flip := by
simp [LinearMap.ext_iff₂]
theorem isSymm_iff_eq_flip {B : LinearMap.BilinForm R M} : B.IsSymm ↔ B = B.flip :=
BilinMap.isSymm_iff_eq_flip
end Symmetric
/-! ### Alternating bilinear maps -/
section Alternating
section CommSemiring
section AddCommMonoid
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁]
[Module R₁ M₁] {I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {I : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M}
/-- The proposition that a sesquilinear map is alternating -/
def IsAlt (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M) : Prop :=
∀ x, B x x = 0
variable (H : B.IsAlt)
include H
theorem IsAlt.self_eq_zero (x : M₁) : B x x = 0 :=
H x
theorem IsAlt.eq_of_add_add_eq_zero [IsCancelAdd M] {a b c : M₁} (hAdd : a + b + c = 0) :
B a b = B b c := by
have : B a a + B a b + B a c = B a c + B b c + B c c := by
simp_rw [← map_add, ← map_add₂, hAdd, map_zero, LinearMap.zero_apply]
rw [H, H, zero_add, add_zero, add_comm] at this
exact add_left_cancel this
end AddCommMonoid
section AddCommGroup
namespace IsAlt
variable [CommSemiring R] [AddCommGroup M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁]
[Module R₁ M₁] {I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {I : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M}
theorem neg (H : B.IsAlt) (x y : M₁) : -B x y = B y x := by
have H1 : B (y + x) (y + x) = 0 := self_eq_zero H (y + x)
simp? [map_add, self_eq_zero H] at H1 says
simp only [map_add, add_apply, self_eq_zero H, zero_add, add_zero] at H1
rw [add_eq_zero_iff_neg_eq] at H1
exact H1
theorem isRefl (H : B.IsAlt) : B.IsRefl := by
intro x y h
rw [← neg H, h, neg_zero]
theorem ortho_comm (H : B.IsAlt) {x y} : IsOrtho B x y ↔ IsOrtho B y x :=
H.isRefl.ortho_comm
end IsAlt
end AddCommGroup
end CommSemiring
section Semiring
variable [CommRing R] [AddCommGroup M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁]
[Module R₁ M₁] {I : R₁ →+* R}
theorem isAlt_iff_eq_neg_flip [NoZeroDivisors R] [CharZero R] {B : M₁ →ₛₗ[I] M₁ →ₛₗ[I] R} :
B.IsAlt ↔ B = -B.flip := by
constructor <;> intro h
· ext
simp_rw [neg_apply, flip_apply]
exact (h.neg _ _).symm
intro x
let h' := congr_fun₂ h x x
simp only [neg_apply, flip_apply, ← add_eq_zero_iff_eq_neg] at h'
exact add_self_eq_zero.mp h'
end Semiring
end Alternating
end LinearMap
namespace Submodule
/-! ### The orthogonal complement -/
variable [CommRing R] [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁] [AddCommGroup M] [Module R M]
{I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M}
/-- The orthogonal complement of a submodule `N` with respect to some bilinear map is the set of
elements `x` which are orthogonal to all elements of `N`; i.e., for all `y` in `N`, `B x y = 0`.
Note that for general (neither symmetric nor antisymmetric) bilinear maps this definition has a
chirality; in addition to this "left" orthogonal complement one could define a "right" orthogonal
complement for which, for all `y` in `N`, `B y x = 0`. This variant definition is not currently
provided in mathlib. -/
def orthogonalBilin (N : Submodule R₁ M₁) (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M) : Submodule R₁ M₁ where
carrier := { m | ∀ n ∈ N, B.IsOrtho n m }
zero_mem' x _ := B.isOrtho_zero_right x
add_mem' hx hy n hn := by
rw [LinearMap.IsOrtho, map_add, show B n _ = 0 from hx n hn, show B n _ = 0 from hy n hn,
zero_add]
smul_mem' c x hx n hn := by
rw [LinearMap.IsOrtho, LinearMap.map_smulₛₗ, show B n x = 0 from hx n hn, smul_zero]
variable {N L : Submodule R₁ M₁}
@[simp]
theorem mem_orthogonalBilin_iff {m : M₁} : m ∈ N.orthogonalBilin B ↔ ∀ n ∈ N, B.IsOrtho n m :=
Iff.rfl
theorem orthogonalBilin_le (h : N ≤ L) : L.orthogonalBilin B ≤ N.orthogonalBilin B :=
fun _ hn l hl ↦ hn l (h hl)
theorem le_orthogonalBilin_orthogonalBilin (b : B.IsRefl) :
N ≤ (N.orthogonalBilin B).orthogonalBilin B := fun n hn _m hm ↦ b _ _ (hm n hn)
end Submodule
namespace LinearMap
section Orthogonal
variable [Field K] [AddCommGroup V] [Module K V] [Field K₁] [AddCommGroup V₁] [Module K₁ V₁]
[AddCommGroup V₂] [Module K V₂] {J : K →+* K} {J₁ : K₁ →+* K} {J₁' : K₁ →+* K}
-- ↓ This lemma only applies in fields as we require `a * b = 0 → a = 0 ∨ b = 0`
theorem span_singleton_inf_orthogonal_eq_bot (B : V₁ →ₛₗ[J₁] V₁ →ₛₗ[J₁'] V₂) (x : V₁)
(hx : ¬B.IsOrtho x x) : (K₁ ∙ x) ⊓ Submodule.orthogonalBilin (K₁ ∙ x) B = ⊥ := by
rw [← Finset.coe_singleton]
refine eq_bot_iff.2 fun y h ↦ ?_
obtain ⟨μ, -, rfl⟩ := Submodule.mem_span_finset.1 h.1
replace h := h.2 x (by simp [Submodule.mem_span] : x ∈ Submodule.span K₁ ({x} : Finset V₁))
rw [Finset.sum_singleton] at h ⊢
suffices hμzero : μ x = 0 by rw [hμzero, zero_smul, Submodule.mem_bot]
rw [isOrtho_def, map_smulₛₗ] at h
exact Or.elim (smul_eq_zero.mp h)
(fun y ↦ by simpa using y)
(fun hfalse ↦ False.elim <| hx hfalse)
-- ↓ This lemma only applies in fields since we use the `mul_eq_zero`
theorem orthogonal_span_singleton_eq_to_lin_ker {B : V →ₗ[K] V →ₛₗ[J] V₂} (x : V) :
Submodule.orthogonalBilin (K ∙ x) B = LinearMap.ker (B x) := by
ext y
simp_rw [Submodule.mem_orthogonalBilin_iff, LinearMap.mem_ker, Submodule.mem_span_singleton]
constructor
· exact fun h ↦ h x ⟨1, one_smul _ _⟩
· rintro h _ ⟨z, rfl⟩
rw [isOrtho_def, map_smulₛₗ₂, smul_eq_zero]
exact Or.intro_right _ h
-- todo: Generalize this to sesquilinear maps
theorem span_singleton_sup_orthogonal_eq_top {B : V →ₗ[K] V →ₗ[K] K} {x : V} (hx : ¬B.IsOrtho x x) :
(K ∙ x) ⊔ Submodule.orthogonalBilin (N := K ∙ x) (B := B) = ⊤ := by
rw [orthogonal_span_singleton_eq_to_lin_ker]
exact (B x).span_singleton_sup_ker_eq_top hx
-- todo: Generalize this to sesquilinear maps
/-- Given a bilinear form `B` and some `x` such that `B x x ≠ 0`, the span of the singleton of `x`
is complement to its orthogonal complement. -/
theorem isCompl_span_singleton_orthogonal {B : V →ₗ[K] V →ₗ[K] K} {x : V} (hx : ¬B.IsOrtho x x) :
IsCompl (K ∙ x) (Submodule.orthogonalBilin (N := K ∙ x) (B := B)) :=
{ disjoint := disjoint_iff.2 <| span_singleton_inf_orthogonal_eq_bot B x hx
codisjoint := codisjoint_iff.2 <| span_singleton_sup_orthogonal_eq_top hx }
end Orthogonal
/-! ### Adjoint pairs -/
section AdjointPair
section AddCommMonoid
variable [CommSemiring R]
variable [AddCommMonoid M] [Module R M]
variable [AddCommMonoid M₁] [Module R M₁]
variable [AddCommMonoid M₂] [Module R M₂]
variable [AddCommMonoid M₃] [Module R M₃]
variable {I : R →+* R}
variable {B F : M →ₗ[R] M →ₛₗ[I] M₃} {B' : M₁ →ₗ[R] M₁ →ₛₗ[I] M₃} {B'' : M₂ →ₗ[R] M₂ →ₛₗ[I] M₃}
variable {f f' : M →ₗ[R] M₁} {g g' : M₁ →ₗ[R] M}
variable (B B' f g)
/-- Given a pair of modules equipped with bilinear maps, this is the condition for a pair of
maps between them to be mutually adjoint. -/
def IsAdjointPair (f : M → M₁) (g : M₁ → M) :=
∀ x y, B' (f x) y = B x (g y)
variable {B B' f g}
theorem isAdjointPair_iff_comp_eq_compl₂ : IsAdjointPair B B' f g ↔ B'.comp f = B.compl₂ g := by
constructor <;> intro h
· ext x y
rw [comp_apply, compl₂_apply]
exact h x y
· intro _ _
rw [← compl₂_apply, ← comp_apply, h]
theorem isAdjointPair_zero : IsAdjointPair B B' 0 0 := fun _ _ ↦ by
simp only [Pi.zero_apply, map_zero, zero_apply]
theorem isAdjointPair_id : IsAdjointPair B B (_root_.id : M → M) (_root_.id : M → M) :=
fun _ _ ↦ rfl
theorem isAdjointPair_one : IsAdjointPair B B (1 : Module.End R M) (1 : Module.End R M) :=
isAdjointPair_id
theorem IsAdjointPair.add {f f' : M → M₁} {g g' : M₁ → M} (h : IsAdjointPair B B' f g)
(h' : IsAdjointPair B B' f' g') :
IsAdjointPair B B' (f + f') (g + g') := fun x _ ↦ by
rw [Pi.add_apply, Pi.add_apply, B'.map_add₂, (B x).map_add, h, h']
theorem IsAdjointPair.comp {f : M → M₁} {g : M₁ → M} {f' : M₁ → M₂} {g' : M₂ → M₁}
(h : IsAdjointPair B B' f g) (h' : IsAdjointPair B' B'' f' g') :
IsAdjointPair B B'' (f' ∘ f) (g ∘ g') := fun _ _ ↦ by
rw [Function.comp_def, Function.comp_def, h', h]
theorem IsAdjointPair.mul {f g f' g' : Module.End R M} (h : IsAdjointPair B B f g)
(h' : IsAdjointPair B B f' g') : IsAdjointPair B B (f * f') (g' * g) :=
h'.comp h
end AddCommMonoid
section AddCommGroup
variable [CommRing R]
variable [AddCommGroup M] [Module R M]
variable [AddCommGroup M₁] [Module R M₁]
variable [AddCommGroup M₂] [Module R M₂]
variable {B F : M →ₗ[R] M →ₗ[R] M₂} {B' : M₁ →ₗ[R] M₁ →ₗ[R] M₂}
variable {f f' : M → M₁} {g g' : M₁ → M}
theorem IsAdjointPair.sub (h : IsAdjointPair B B' f g) (h' : IsAdjointPair B B' f' g') :
IsAdjointPair B B' (f - f') (g - g') := fun x _ ↦ by
rw [Pi.sub_apply, Pi.sub_apply, B'.map_sub₂, (B x).map_sub, h, h']
theorem IsAdjointPair.smul (c : R) (h : IsAdjointPair B B' f g) :
IsAdjointPair B B' (c • f) (c • g) := fun _ _ ↦ by
simp [h _]
end AddCommGroup
section OrthogonalMap
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
(B : LinearMap.BilinForm R M) (f : M → M)
/-- A linear transformation `f` is orthogonal with respect to a bilinear form `B` if `B` is
bi-invariant with respect to `f`. -/
def IsOrthogonal : Prop :=
∀ x y, B (f x) (f y) = B x y
variable {B f}
@[simp]
lemma _root_.LinearEquiv.isAdjointPair_symm_iff {f : M ≃ M} :
LinearMap.IsAdjointPair B B f f.symm ↔ B.IsOrthogonal f :=
⟨fun hf x y ↦ by simpa using hf x (f y), fun hf x y ↦ by simpa using hf x (f.symm y)⟩
lemma isOrthogonal_of_forall_apply_same {F : Type*} [FunLike F M M] [LinearMapClass F R M M]
(f : F) (h : IsLeftRegular (2 : R)) (hB : B.IsSymm) (hf : ∀ x, B (f x) (f x) = B x x) :
B.IsOrthogonal f := by
intro x y
suffices 2 * B (f x) (f y) = 2 * B x y from h this
have := hf (x + y)
simp only [map_add, LinearMap.add_apply, hf x, hf y, show B y x = B x y from hB.eq y x] at this
rw [show B (f y) (f x) = B (f x) (f y) from hB.eq (f y) (f x)] at this
simp only [add_assoc, add_right_inj] at this
simp only [← add_assoc, add_left_inj] at this
simpa only [← two_mul] using this
end OrthogonalMap
end AdjointPair
/-! ### Self-adjoint pairs -/
section SelfadjointPair
section AddCommMonoid
variable [CommSemiring R]
variable [AddCommMonoid M] [Module R M]
variable [AddCommMonoid M₁] [Module R M₁]
variable {I : R →+* R}
variable (B F : M →ₗ[R] M →ₛₗ[I] M₁)
/-- The condition for an endomorphism to be "self-adjoint" with respect to a pair of bilinear maps
on the underlying module. In the case that these two maps are identical, this is the usual concept
of self adjointness. In the case that one of the maps is the negation of the other, this is the
usual concept of skew adjointness. -/
def IsPairSelfAdjoint (f : M → M) :=
IsAdjointPair B F f f
/-- An endomorphism of a module is self-adjoint with respect to a bilinear map if it serves as an
adjoint for itself. -/
protected def IsSelfAdjoint (f : M → M) :=
IsAdjointPair B B f f
end AddCommMonoid
section AddCommGroup
variable [CommRing R]
variable [AddCommGroup M] [Module R M] [AddCommGroup M₁] [Module R M₁]
variable [AddCommGroup M₂] [Module R M₂] (B F : M →ₗ[R] M →ₗ[R] M₂)
/-- The set of pair-self-adjoint endomorphisms are a submodule of the type of all endomorphisms. -/
def isPairSelfAdjointSubmodule : Submodule R (Module.End R M) where
carrier := { f | IsPairSelfAdjoint B F f }
zero_mem' := isAdjointPair_zero
add_mem' hf hg := hf.add hg
smul_mem' c _ h := h.smul c
/-- An endomorphism of a module is skew-adjoint with respect to a bilinear map if its negation
serves as an adjoint. -/
def IsSkewAdjoint (f : M → M) :=
IsAdjointPair B B f (-f)
/-- The set of self-adjoint endomorphisms of a module with bilinear map is a submodule. (In fact
it is a Jordan subalgebra.) -/
def selfAdjointSubmodule :=
isPairSelfAdjointSubmodule B B
/-- The set of skew-adjoint endomorphisms of a module with bilinear map is a submodule. (In fact
it is a Lie subalgebra.) -/
def skewAdjointSubmodule :=
isPairSelfAdjointSubmodule (-B) B
variable {B F}
@[simp]
theorem mem_isPairSelfAdjointSubmodule (f : Module.End R M) :
f ∈ isPairSelfAdjointSubmodule B F ↔ IsPairSelfAdjoint B F f :=
Iff.rfl
theorem isPairSelfAdjoint_equiv (e : M₁ ≃ₗ[R] M) (f : Module.End R M) :
IsPairSelfAdjoint B F f ↔
IsPairSelfAdjoint (B.compl₁₂ e e) (F.compl₁₂ e e) (e.symm.conj f) := by
have hₗ :
(F.compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M)).comp (e.symm.conj f) =
(F.comp f).compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M) := by
ext
simp only [LinearEquiv.symm_conj_apply, coe_comp, LinearEquiv.coe_coe, compl₁₂_apply,
LinearEquiv.apply_symm_apply, Function.comp_apply]
have hᵣ :
(B.compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M)).compl₂ (e.symm.conj f) =
(B.compl₂ f).compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M) := by
ext
simp only [LinearEquiv.symm_conj_apply, compl₂_apply, coe_comp, LinearEquiv.coe_coe,
compl₁₂_apply, LinearEquiv.apply_symm_apply, Function.comp_apply]
have he : Function.Surjective (⇑(↑e : M₁ →ₗ[R] M) : M₁ → M) := e.surjective
simp_rw [IsPairSelfAdjoint, isAdjointPair_iff_comp_eq_compl₂, hₗ, hᵣ, compl₁₂_inj he he]
theorem isSkewAdjoint_iff_neg_self_adjoint (f : M → M) :
B.IsSkewAdjoint f ↔ IsAdjointPair (-B) B f f :=
show (∀ x y, B (f x) y = B x ((-f) y)) ↔ ∀ x y, B (f x) y = (-B) x (f y) by simp
@[simp]
theorem mem_selfAdjointSubmodule (f : Module.End R M) :
f ∈ B.selfAdjointSubmodule ↔ B.IsSelfAdjoint f :=
Iff.rfl
@[simp]
theorem mem_skewAdjointSubmodule (f : Module.End R M) :
f ∈ B.skewAdjointSubmodule ↔ B.IsSkewAdjoint f := by
rw [isSkewAdjoint_iff_neg_self_adjoint]
exact Iff.rfl
end AddCommGroup
end SelfadjointPair
/-! ### Nondegenerate bilinear maps -/
section Nondegenerate
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁]
[Module R₁ M₁] [CommSemiring R₂] [AddCommMonoid M₂] [Module R₂ M₂]
{I₁ : R₁ →+* R} {I₂ : R₂ →+* R} {I₁' : R₁ →+* R}
/-- A bilinear map is called left-separating if
the only element that is left-orthogonal to every other element is `0`; i.e.,
for every nonzero `x` in `M₁`, there exists `y` in `M₂` with `B x y ≠ 0`. -/
def SeparatingLeft (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) : Prop :=
∀ x : M₁, (∀ y : M₂, B x y = 0) → x = 0
variable (M₁ M₂ I₁ I₂)
/-- In a non-trivial module, zero is not non-degenerate. -/
theorem not_separatingLeft_zero [Nontrivial M₁] : ¬(0 : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M).SeparatingLeft :=
let ⟨m, hm⟩ := exists_ne (0 : M₁)
fun h ↦ hm (h m fun _n ↦ rfl)
variable {M₁ M₂ I₁ I₂}
theorem SeparatingLeft.ne_zero [Nontrivial M₁] {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M}
(h : B.SeparatingLeft) : B ≠ 0 := fun h0 ↦ not_separatingLeft_zero M₁ M₂ I₁ I₂ <| h0 ▸ h
section Linear
variable [AddCommMonoid Mₗ₁] [AddCommMonoid Mₗ₂] [AddCommMonoid Mₗ₁'] [AddCommMonoid Mₗ₂']
variable [Module R Mₗ₁] [Module R Mₗ₂] [Module R Mₗ₁'] [Module R Mₗ₂']
variable {B : Mₗ₁ →ₗ[R] Mₗ₂ →ₗ[R] M} (e₁ : Mₗ₁ ≃ₗ[R] Mₗ₁') (e₂ : Mₗ₂ ≃ₗ[R] Mₗ₂')
theorem SeparatingLeft.congr (h : B.SeparatingLeft) :
(e₁.arrowCongr (e₂.arrowCongr (LinearEquiv.refl R M)) B).SeparatingLeft := by
intro x hx
rw [← e₁.symm.map_eq_zero_iff]
refine h (e₁.symm x) fun y ↦ ?_
specialize hx (e₂ y)
simp only [LinearEquiv.arrowCongr_apply, LinearEquiv.symm_apply_apply,
LinearEquiv.map_eq_zero_iff] at hx
exact hx
@[simp]
theorem separatingLeft_congr_iff :
(e₁.arrowCongr (e₂.arrowCongr (LinearEquiv.refl R M)) B).SeparatingLeft ↔ B.SeparatingLeft :=
⟨fun h ↦ by
convert h.congr e₁.symm e₂.symm
ext x y
simp,
SeparatingLeft.congr e₁ e₂⟩
end Linear
/-- A bilinear map is called right-separating if
the only element that is right-orthogonal to every other element is `0`; i.e.,
for every nonzero `y` in `M₂`, there exists `x` in `M₁` with `B x y ≠ 0`. -/
def SeparatingRight (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) : Prop :=
∀ y : M₂, (∀ x : M₁, B x y = 0) → y = 0
/-- A bilinear map is called non-degenerate if it is left-separating and right-separating. -/
def Nondegenerate (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) : Prop :=
SeparatingLeft B ∧ SeparatingRight B
@[simp]
theorem flip_separatingRight {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.flip.SeparatingRight ↔ B.SeparatingLeft :=
⟨fun hB x hy ↦ hB x hy, fun hB x hy ↦ hB x hy⟩
@[simp]
theorem flip_separatingLeft {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.flip.SeparatingLeft ↔ SeparatingRight B := by rw [← flip_separatingRight, flip_flip]
@[simp]
theorem flip_nondegenerate {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} : B.flip.Nondegenerate ↔ B.Nondegenerate :=
Iff.trans and_comm (and_congr flip_separatingRight flip_separatingLeft)
theorem separatingLeft_iff_linear_nontrivial {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.SeparatingLeft ↔ ∀ x : M₁, B x = 0 → x = 0 := by
constructor <;> intro h x hB
· simpa only [hB, zero_apply, eq_self_iff_true, forall_const] using h x
have h' : B x = 0 := by
ext
rw [zero_apply]
exact hB _
exact h x h'
theorem separatingRight_iff_linear_flip_nontrivial {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.SeparatingRight ↔ ∀ y : M₂, B.flip y = 0 → y = 0 := by
rw [← flip_separatingLeft, separatingLeft_iff_linear_nontrivial]
/-- A bilinear map is left-separating if and only if it has a trivial kernel. -/
theorem separatingLeft_iff_ker_eq_bot {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.SeparatingLeft ↔ LinearMap.ker B = ⊥ :=
Iff.trans separatingLeft_iff_linear_nontrivial LinearMap.ker_eq_bot'.symm
/-- A bilinear map is right-separating if and only if its flip has a trivial kernel. -/
| Mathlib/LinearAlgebra/SesquilinearForm.lean | 699 | 700 | theorem separatingRight_iff_flip_ker_eq_bot {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} :
B.SeparatingRight ↔ LinearMap.ker B.flip = ⊥ := by | |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Order.ConditionallyCompleteLattice.Group
import Mathlib.Topology.MetricSpace.Isometry
/-!
# Metric space gluing
Gluing two metric spaces along a common subset. Formally, we are given
```
Φ
Z ---> X
|
|Ψ
v
Y
```
where `hΦ : Isometry Φ` and `hΨ : Isometry Ψ`.
We want to complete the square by a space `GlueSpacescan hΦ hΨ` and two isometries
`toGlueL hΦ hΨ` and `toGlueR hΦ hΨ` that make the square commute.
We start by defining a predistance on the disjoint union `X ⊕ Y`, for which
points `Φ p` and `Ψ p` are at distance 0. The (quotient) metric space associated
to this predistance is the desired space.
This is an instance of a more general construction, where `Φ` and `Ψ` do not have to be isometries,
but the distances in the image almost coincide, up to `2ε` say. Then one can almost glue the two
spaces so that the images of a point under `Φ` and `Ψ` are `ε`-close. If `ε > 0`, this yields a
metric space structure on `X ⊕ Y`, without the need to take a quotient. In particular,
this gives a natural metric space structure on `X ⊕ Y`, where the basepoints
are at distance 1, say, and the distances between other points are obtained by going through the two
basepoints.
(We also register the same metric space structure on a general disjoint union `Σ i, E i`).
We also define the inductive limit of metric spaces. Given
```
f 0 f 1 f 2 f 3
X 0 -----> X 1 -----> X 2 -----> X 3 -----> ...
```
where the `X n` are metric spaces and `f n` isometric embeddings, we define the inductive
limit of the `X n`, also known as the increasing union of the `X n` in this context, if we
identify `X n` and `X (n+1)` through `f n`. This is a metric space in which all `X n` embed
isometrically and in a way compatible with `f n`.
-/
noncomputable section
universe u v w
open Function Set Uniformity Topology
namespace Metric
section ApproxGluing
variable {X : Type u} {Y : Type v} {Z : Type w}
variable [MetricSpace X] [MetricSpace Y] {Φ : Z → X} {Ψ : Z → Y} {ε : ℝ}
/-- Define a predistance on `X ⊕ Y`, for which `Φ p` and `Ψ p` are at distance `ε` -/
def glueDist (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) : X ⊕ Y → X ⊕ Y → ℝ
| .inl x, .inl y => dist x y
| .inr x, .inr y => dist x y
| .inl x, .inr y => (⨅ p, dist x (Φ p) + dist y (Ψ p)) + ε
| .inr x, .inl y => (⨅ p, dist y (Φ p) + dist x (Ψ p)) + ε
private theorem glueDist_self (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) : ∀ x, glueDist Φ Ψ ε x x = 0
| .inl _ => dist_self _
| .inr _ => dist_self _
theorem glueDist_glued_points [Nonempty Z] (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (p : Z) :
glueDist Φ Ψ ε (.inl (Φ p)) (.inr (Ψ p)) = ε := by
have : ⨅ q, dist (Φ p) (Φ q) + dist (Ψ p) (Ψ q) = 0 := by
have A : ∀ q, 0 ≤ dist (Φ p) (Φ q) + dist (Ψ p) (Ψ q) := fun _ =>
add_nonneg dist_nonneg dist_nonneg
refine le_antisymm ?_ (le_ciInf A)
have : 0 = dist (Φ p) (Φ p) + dist (Ψ p) (Ψ p) := by simp
rw [this]
exact ciInf_le ⟨0, forall_mem_range.2 A⟩ p
simp only [glueDist, this, zero_add]
private theorem glueDist_comm (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) :
∀ x y, glueDist Φ Ψ ε x y = glueDist Φ Ψ ε y x
| .inl _, .inl _ => dist_comm _ _
| .inr _, .inr _ => dist_comm _ _
| .inl _, .inr _ => rfl
| .inr _, .inl _ => rfl
theorem glueDist_swap (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) :
∀ x y, glueDist Ψ Φ ε x.swap y.swap = glueDist Φ Ψ ε x y
| .inl _, .inl _ => rfl
| .inr _, .inr _ => rfl
| .inl _, .inr _ => by simp only [glueDist, Sum.swap_inl, Sum.swap_inr, dist_comm, add_comm]
| .inr _, .inl _ => by simp only [glueDist, Sum.swap_inl, Sum.swap_inr, dist_comm, add_comm]
theorem le_glueDist_inl_inr (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x y) :
ε ≤ glueDist Φ Ψ ε (.inl x) (.inr y) :=
le_add_of_nonneg_left <| Real.iInf_nonneg fun _ => add_nonneg dist_nonneg dist_nonneg
theorem le_glueDist_inr_inl (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x y) :
ε ≤ glueDist Φ Ψ ε (.inr x) (.inl y) := by
rw [glueDist_comm]; apply le_glueDist_inl_inr
section
variable [Nonempty Z]
private theorem glueDist_triangle_inl_inr_inr (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x : X) (y z : Y) :
glueDist Φ Ψ ε (.inl x) (.inr z) ≤
glueDist Φ Ψ ε (.inl x) (.inr y) + glueDist Φ Ψ ε (.inr y) (.inr z) := by
simp only [glueDist]
rw [add_right_comm, add_le_add_iff_right]
refine le_ciInf_add fun p => ciInf_le_of_le ⟨0, ?_⟩ p ?_
· exact forall_mem_range.2 fun _ => add_nonneg dist_nonneg dist_nonneg
· linarith [dist_triangle_left z (Ψ p) y]
private theorem glueDist_triangle_inl_inr_inl (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ)
(H : ∀ p q, |dist (Φ p) (Φ q) - dist (Ψ p) (Ψ q)| ≤ 2 * ε) (x : X) (y : Y) (z : X) :
glueDist Φ Ψ ε (.inl x) (.inl z) ≤
glueDist Φ Ψ ε (.inl x) (.inr y) + glueDist Φ Ψ ε (.inr y) (.inl z) := by
simp_rw [glueDist, add_add_add_comm _ ε, add_assoc]
refine le_ciInf_add fun p => ?_
rw [add_left_comm, add_assoc, ← two_mul]
refine le_ciInf_add fun q => ?_
rw [dist_comm z]
linarith [dist_triangle4 x (Φ p) (Φ q) z, dist_triangle_left (Ψ p) (Ψ q) y, (abs_le.1 (H p q)).2]
private theorem glueDist_triangle (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ)
(H : ∀ p q, |dist (Φ p) (Φ q) - dist (Ψ p) (Ψ q)| ≤ 2 * ε) :
∀ x y z, glueDist Φ Ψ ε x z ≤ glueDist Φ Ψ ε x y + glueDist Φ Ψ ε y z
| .inl _, .inl _, .inl _ => dist_triangle _ _ _
| .inr _, .inr _, .inr _ => dist_triangle _ _ _
| .inr x, .inl y, .inl z => by
simp only [← glueDist_swap Φ]
apply glueDist_triangle_inl_inr_inr
| .inr x, .inr y, .inl z => by
simpa only [glueDist_comm, add_comm] using glueDist_triangle_inl_inr_inr _ _ _ z y x
| .inl x, .inl y, .inr z => by
simpa only [← glueDist_swap Φ, glueDist_comm, add_comm, Sum.swap_inl, Sum.swap_inr]
using glueDist_triangle_inl_inr_inr Ψ Φ ε z y x
| .inl _, .inr _, .inr _ => glueDist_triangle_inl_inr_inr ..
| .inl x, .inr y, .inl z => glueDist_triangle_inl_inr_inl Φ Ψ ε H x y z
| .inr x, .inl y, .inr z => by
simp only [← glueDist_swap Φ]
apply glueDist_triangle_inl_inr_inl
simpa only [abs_sub_comm]
end
private theorem eq_of_glueDist_eq_zero (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (ε0 : 0 < ε) :
∀ p q : X ⊕ Y, glueDist Φ Ψ ε p q = 0 → p = q
| .inl x, .inl y, h => by rw [eq_of_dist_eq_zero h]
| .inl x, .inr y, h => by exfalso; linarith [le_glueDist_inl_inr Φ Ψ ε x y]
| .inr x, .inl y, h => by exfalso; linarith [le_glueDist_inr_inl Φ Ψ ε x y]
| .inr x, .inr y, h => by rw [eq_of_dist_eq_zero h]
| Mathlib/Topology/MetricSpace/Gluing.lean | 159 | 171 | theorem Sum.mem_uniformity_iff_glueDist (hε : 0 < ε) (s : Set ((X ⊕ Y) × (X ⊕ Y))) :
s ∈ 𝓤 (X ⊕ Y) ↔ ∃ δ > 0, ∀ a b, glueDist Φ Ψ ε a b < δ → (a, b) ∈ s := by | simp only [Sum.uniformity, Filter.mem_sup, Filter.mem_map, mem_uniformity_dist, mem_preimage]
constructor
· rintro ⟨⟨δX, δX0, hX⟩, δY, δY0, hY⟩
refine ⟨min (min δX δY) ε, lt_min (lt_min δX0 δY0) hε, ?_⟩
rintro (a | a) (b | b) h <;> simp only [lt_min_iff] at h
· exact hX h.1.1
· exact absurd h.2 (le_glueDist_inl_inr _ _ _ _ _).not_lt
· exact absurd h.2 (le_glueDist_inr_inl _ _ _ _ _).not_lt
· exact hY h.1.2
· rintro ⟨ε, ε0, H⟩
constructor <;> exact ⟨ε, ε0, fun _ _ h => H _ _ h⟩ |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.Module.End
import Mathlib.Algebra.Ring.Prod
import Mathlib.Data.Fintype.Units
import Mathlib.GroupTheory.GroupAction.SubMulAction
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.Tactic.FinCases
/-!
# Integers mod `n`
Definition of the integers mod n, and the field structure on the integers mod p.
## Definitions
* `ZMod n`, which is for integers modulo a nat `n : ℕ`
* `val a` is defined as a natural number:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
* A coercion `cast` is defined from `ZMod n` into any ring.
This is a ring hom if the ring has characteristic dividing `n`
-/
assert_not_exists Field Submodule TwoSidedIdeal
open Function ZMod
namespace ZMod
/-- For non-zero `n : ℕ`, the ring `Fin n` is equivalent to `ZMod n`. -/
def finEquiv : ∀ (n : ℕ) [NeZero n], Fin n ≃+* ZMod n
| 0, h => (h.ne _ rfl).elim
| _ + 1, _ => .refl _
instance charZero : CharZero (ZMod 0) := inferInstanceAs (CharZero ℤ)
/-- `val a` is a natural number defined as:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
See `ZMod.valMinAbs` for a variant that takes values in the integers.
-/
def val : ∀ {n : ℕ}, ZMod n → ℕ
| 0 => Int.natAbs
| n + 1 => ((↑) : Fin (n + 1) → ℕ)
theorem val_lt {n : ℕ} [NeZero n] (a : ZMod n) : a.val < n := by
cases n
· cases NeZero.ne 0 rfl
exact Fin.is_lt a
theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n :=
a.val_lt.le
@[simp]
theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0
| 0 => rfl
| _ + 1 => rfl
@[simp]
theorem val_one' : (1 : ZMod 0).val = 1 :=
rfl
@[simp]
theorem val_neg' {n : ZMod 0} : (-n).val = n.val :=
Int.natAbs_neg n
@[simp]
theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val :=
Int.natAbs_mul m n
@[simp]
theorem val_natCast (n a : ℕ) : (a : ZMod n).val = a % n := by
cases n
· rw [Nat.mod_zero]
exact Int.natAbs_natCast a
· apply Fin.val_natCast
lemma val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by
rwa [val_natCast, Nat.mod_eq_of_lt]
lemma val_ofNat (n a : ℕ) [a.AtLeastTwo] : (ofNat(a) : ZMod n).val = ofNat(a) % n := val_natCast ..
lemma val_ofNat_of_lt {n a : ℕ} [a.AtLeastTwo] (han : a < n) : (ofNat(a) : ZMod n).val = ofNat(a) :=
val_natCast_of_lt han
theorem val_unit' {n : ZMod 0} : IsUnit n ↔ n.val = 1 := by
simp only [val]
rw [Int.isUnit_iff, Int.natAbs_eq_iff, Nat.cast_one]
lemma eq_one_of_isUnit_natCast {n : ℕ} (h : IsUnit (n : ZMod 0)) : n = 1 := by
rw [← Nat.mod_zero n, ← val_natCast, val_unit'.mp h]
instance charP (n : ℕ) : CharP (ZMod n) n where
cast_eq_zero_iff := by
intro k
rcases n with - | n
· simp [zero_dvd_iff, Int.natCast_eq_zero]
· exact Fin.natCast_eq_zero
@[simp]
theorem addOrderOf_one (n : ℕ) : addOrderOf (1 : ZMod n) = n :=
CharP.eq _ (CharP.addOrderOf_one _) (ZMod.charP n)
/-- This lemma works in the case in which `ZMod n` is not infinite, i.e. `n ≠ 0`. The version
where `a ≠ 0` is `addOrderOf_coe'`. -/
@[simp]
theorem addOrderOf_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
rcases a with - | a
· simp only [Nat.cast_zero, addOrderOf_zero, Nat.gcd_zero_right,
Nat.pos_of_ne_zero n0, Nat.div_self]
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a.succ_ne_zero, ZMod.addOrderOf_one]
/-- This lemma works in the case in which `a ≠ 0`. The version where
`ZMod n` is not infinite, i.e. `n ≠ 0`, is `addOrderOf_coe`. -/
@[simp]
theorem addOrderOf_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a0, ZMod.addOrderOf_one]
/-- We have that `ringChar (ZMod n) = n`. -/
theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by
rw [ringChar.eq_iff]
exact ZMod.charP n
theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 :=
CharP.cast_eq_zero (ZMod n) n
@[simp]
theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1)) = 0 := by
rw [← Nat.cast_add_one, natCast_self (n + 1)]
section UniversalProperty
variable {n : ℕ} {R : Type*}
section
variable [AddGroupWithOne R]
/-- Cast an integer modulo `n` to another semiring.
This function is a morphism if the characteristic of `R` divides `n`.
See `ZMod.castHom` for a bundled version. -/
def cast : ∀ {n : ℕ}, ZMod n → R
| 0 => Int.cast
| _ + 1 => fun i => i.val
@[simp]
theorem cast_zero : (cast (0 : ZMod n) : R) = 0 := by
delta ZMod.cast
cases n
· exact Int.cast_zero
· simp
theorem cast_eq_val [NeZero n] (a : ZMod n) : (cast a : R) = a.val := by
cases n
· cases NeZero.ne 0 rfl
rfl
variable {S : Type*} [AddGroupWithOne S]
@[simp]
theorem _root_.Prod.fst_zmod_cast (a : ZMod n) : (cast a : R × S).fst = cast a := by
cases n
· rfl
· simp [ZMod.cast]
@[simp]
theorem _root_.Prod.snd_zmod_cast (a : ZMod n) : (cast a : R × S).snd = cast a := by
cases n
· rfl
· simp [ZMod.cast]
end
/-- So-named because the coercion is `Nat.cast` into `ZMod`. For `Nat.cast` into an arbitrary ring,
see `ZMod.natCast_val`. -/
theorem natCast_zmod_val {n : ℕ} [NeZero n] (a : ZMod n) : (a.val : ZMod n) = a := by
cases n
· cases NeZero.ne 0 rfl
· apply Fin.cast_val_eq_self
theorem natCast_rightInverse [NeZero n] : Function.RightInverse val ((↑) : ℕ → ZMod n) :=
natCast_zmod_val
theorem natCast_zmod_surjective [NeZero n] : Function.Surjective ((↑) : ℕ → ZMod n) :=
natCast_rightInverse.surjective
/-- So-named because the outer coercion is `Int.cast` into `ZMod`. For `Int.cast` into an arbitrary
ring, see `ZMod.intCast_cast`. -/
@[norm_cast]
theorem intCast_zmod_cast (a : ZMod n) : ((cast a : ℤ) : ZMod n) = a := by
cases n
· simp [ZMod.cast, ZMod]
· dsimp [ZMod.cast]
rw [Int.cast_natCast, natCast_zmod_val]
theorem intCast_rightInverse : Function.RightInverse (cast : ZMod n → ℤ) ((↑) : ℤ → ZMod n) :=
intCast_zmod_cast
theorem intCast_surjective : Function.Surjective ((↑) : ℤ → ZMod n) :=
intCast_rightInverse.surjective
lemma «forall» {P : ZMod n → Prop} : (∀ x, P x) ↔ ∀ x : ℤ, P x := intCast_surjective.forall
lemma «exists» {P : ZMod n → Prop} : (∃ x, P x) ↔ ∃ x : ℤ, P x := intCast_surjective.exists
theorem cast_id : ∀ (n) (i : ZMod n), (ZMod.cast i : ZMod n) = i
| 0, _ => Int.cast_id
| _ + 1, i => natCast_zmod_val i
@[simp]
theorem cast_id' : (ZMod.cast : ZMod n → ZMod n) = id :=
funext (cast_id n)
variable (R) [Ring R]
/-- The coercions are respectively `Nat.cast` and `ZMod.cast`. -/
@[simp]
theorem natCast_comp_val [NeZero n] : ((↑) : ℕ → R) ∘ (val : ZMod n → ℕ) = cast := by
cases n
· cases NeZero.ne 0 rfl
rfl
/-- The coercions are respectively `Int.cast`, `ZMod.cast`, and `ZMod.cast`. -/
@[simp]
theorem intCast_comp_cast : ((↑) : ℤ → R) ∘ (cast : ZMod n → ℤ) = cast := by
cases n
· exact congr_arg (Int.cast ∘ ·) ZMod.cast_id'
· ext
simp [ZMod, ZMod.cast]
variable {R}
@[simp]
theorem natCast_val [NeZero n] (i : ZMod n) : (i.val : R) = cast i :=
congr_fun (natCast_comp_val R) i
@[simp]
theorem intCast_cast (i : ZMod n) : ((cast i : ℤ) : R) = cast i :=
congr_fun (intCast_comp_cast R) i
theorem cast_add_eq_ite {n : ℕ} (a b : ZMod n) :
(cast (a + b) : ℤ) =
if (n : ℤ) ≤ cast a + cast b then (cast a + cast b - n : ℤ) else cast a + cast b := by
rcases n with - | n
· simp; rfl
change Fin (n + 1) at a b
change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _
simp only [Fin.val_add_eq_ite, Int.natCast_succ, Int.ofNat_le]
norm_cast
split_ifs with h
· rw [Nat.cast_sub h]
congr
· rfl
section CharDvd
/-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/
variable {m : ℕ} [CharP R m]
@[simp]
theorem cast_one (h : m ∣ n) : (cast (1 : ZMod n) : R) = 1 := by
rcases n with - | n
· exact Int.cast_one
show ((1 % (n + 1) : ℕ) : R) = 1
cases n
· rw [Nat.dvd_one] at h
subst m
subsingleton [CharP.CharOne.subsingleton]
rw [Nat.mod_eq_of_lt]
· exact Nat.cast_one
exact Nat.lt_of_sub_eq_succ rfl
theorem cast_add (h : m ∣ n) (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := by
cases n
· apply Int.cast_add
symm
dsimp [ZMod, ZMod.cast, ZMod.val]
rw [← Nat.cast_add, Fin.val_add, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
theorem cast_mul (h : m ∣ n) (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := by
cases n
· apply Int.cast_mul
symm
dsimp [ZMod, ZMod.cast, ZMod.val]
rw [← Nat.cast_mul, Fin.val_mul, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
/-- The canonical ring homomorphism from `ZMod n` to a ring of characteristic dividing `n`.
See also `ZMod.lift` for a generalized version working in `AddGroup`s.
-/
def castHom (h : m ∣ n) (R : Type*) [Ring R] [CharP R m] : ZMod n →+* R where
toFun := cast
map_zero' := cast_zero
map_one' := cast_one h
map_add' := cast_add h
map_mul' := cast_mul h
@[simp]
theorem castHom_apply {h : m ∣ n} (i : ZMod n) : castHom h R i = cast i :=
rfl
@[simp]
theorem cast_sub (h : m ∣ n) (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
(castHom h R).map_sub a b
@[simp]
theorem cast_neg (h : m ∣ n) (a : ZMod n) : (cast (-a : ZMod n) : R) = -(cast a) :=
(castHom h R).map_neg a
@[simp]
theorem cast_pow (h : m ∣ n) (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a) ^ k :=
(castHom h R).map_pow a k
@[simp, norm_cast]
theorem cast_natCast (h : m ∣ n) (k : ℕ) : (cast (k : ZMod n) : R) = k :=
map_natCast (castHom h R) k
@[simp, norm_cast]
theorem cast_intCast (h : m ∣ n) (k : ℤ) : (cast (k : ZMod n) : R) = k :=
map_intCast (castHom h R) k
end CharDvd
section CharEq
/-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/
variable [CharP R n]
@[simp]
theorem cast_one' : (cast (1 : ZMod n) : R) = 1 :=
cast_one dvd_rfl
@[simp]
theorem cast_add' (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b :=
cast_add dvd_rfl a b
@[simp]
theorem cast_mul' (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b :=
cast_mul dvd_rfl a b
@[simp]
theorem cast_sub' (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
cast_sub dvd_rfl a b
@[simp]
theorem cast_pow' (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a : R) ^ k :=
cast_pow dvd_rfl a k
@[simp, norm_cast]
theorem cast_natCast' (k : ℕ) : (cast (k : ZMod n) : R) = k :=
cast_natCast dvd_rfl k
@[simp, norm_cast]
theorem cast_intCast' (k : ℤ) : (cast (k : ZMod n) : R) = k :=
cast_intCast dvd_rfl k
variable (R)
theorem castHom_injective : Function.Injective (ZMod.castHom (dvd_refl n) R) := by
rw [injective_iff_map_eq_zero]
intro x
obtain ⟨k, rfl⟩ := ZMod.intCast_surjective x
rw [map_intCast, CharP.intCast_eq_zero_iff R n, CharP.intCast_eq_zero_iff (ZMod n) n]
exact id
theorem castHom_bijective [Fintype R] (h : Fintype.card R = n) :
Function.Bijective (ZMod.castHom (dvd_refl n) R) := by
haveI : NeZero n :=
⟨by
intro hn
rw [hn] at h
exact (Fintype.card_eq_zero_iff.mp h).elim' 0⟩
rw [Fintype.bijective_iff_injective_and_card, ZMod.card, h, eq_self_iff_true, and_true]
apply ZMod.castHom_injective
/-- The unique ring isomorphism between `ZMod n` and a ring `R`
of characteristic `n` and cardinality `n`. -/
noncomputable def ringEquiv [Fintype R] (h : Fintype.card R = n) : ZMod n ≃+* R :=
RingEquiv.ofBijective _ (ZMod.castHom_bijective R h)
/-- The unique ring isomorphism between `ZMod p` and a ring `R` of cardinality a prime `p`.
If you need any property of this isomorphism, first of all use `ringEquivOfPrime_eq_ringEquiv`
below (after `have : CharP R p := ...`) and deduce it by the results about `ZMod.ringEquiv`. -/
noncomputable def ringEquivOfPrime [Fintype R] {p : ℕ} (hp : p.Prime) (hR : Fintype.card R = p) :
ZMod p ≃+* R :=
have : Nontrivial R := Fintype.one_lt_card_iff_nontrivial.1 (hR ▸ hp.one_lt)
-- The following line exists as `charP_of_card_eq_prime` in `Mathlib.Algebra.CharP.CharAndCard`.
have : CharP R p := (CharP.charP_iff_prime_eq_zero hp).2 (hR ▸ Nat.cast_card_eq_zero R)
ZMod.ringEquiv R hR
@[simp]
lemma ringEquivOfPrime_eq_ringEquiv [Fintype R] {p : ℕ} [CharP R p] (hp : p.Prime)
(hR : Fintype.card R = p) : ringEquivOfPrime R hp hR = ringEquiv R hR := rfl
/-- The identity between `ZMod m` and `ZMod n` when `m = n`, as a ring isomorphism. -/
def ringEquivCongr {m n : ℕ} (h : m = n) : ZMod m ≃+* ZMod n := by
rcases m with - | m <;> rcases n with - | n
· exact RingEquiv.refl _
· exfalso
exact n.succ_ne_zero h.symm
· exfalso
exact m.succ_ne_zero h
· exact
{ finCongr h with
map_mul' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.coe_mul, Fin.coe_mul, Fin.coe_cast, Fin.coe_cast, ← h]
map_add' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.val_add, Fin.val_add, Fin.coe_cast, Fin.coe_cast, ← h] }
@[simp] lemma ringEquivCongr_refl (a : ℕ) : ringEquivCongr (rfl : a = a) = .refl _ := by
cases a <;> rfl
lemma ringEquivCongr_refl_apply {a : ℕ} (x : ZMod a) : ringEquivCongr rfl x = x := by
rw [ringEquivCongr_refl]
rfl
lemma ringEquivCongr_symm {a b : ℕ} (hab : a = b) :
(ringEquivCongr hab).symm = ringEquivCongr hab.symm := by
subst hab
cases a <;> rfl
lemma ringEquivCongr_trans {a b c : ℕ} (hab : a = b) (hbc : b = c) :
(ringEquivCongr hab).trans (ringEquivCongr hbc) = ringEquivCongr (hab.trans hbc) := by
subst hab hbc
cases a <;> rfl
lemma ringEquivCongr_ringEquivCongr_apply {a b c : ℕ} (hab : a = b) (hbc : b = c) (x : ZMod a) :
ringEquivCongr hbc (ringEquivCongr hab x) = ringEquivCongr (hab.trans hbc) x := by
rw [← ringEquivCongr_trans hab hbc]
rfl
lemma ringEquivCongr_val {a b : ℕ} (h : a = b) (x : ZMod a) :
ZMod.val ((ZMod.ringEquivCongr h) x) = ZMod.val x := by
subst h
cases a <;> rfl
lemma ringEquivCongr_intCast {a b : ℕ} (h : a = b) (z : ℤ) :
ZMod.ringEquivCongr h z = z := by
subst h
cases a <;> rfl
end CharEq
end UniversalProperty
variable {m n : ℕ}
@[simp]
theorem val_eq_zero : ∀ {n : ℕ} (a : ZMod n), a.val = 0 ↔ a = 0
| 0, _ => Int.natAbs_eq_zero
| n + 1, a => by
rw [Fin.ext_iff]
exact Iff.rfl
theorem intCast_eq_intCast_iff (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [ZMOD c] :=
CharP.intCast_eq_intCast (ZMod c) c
theorem intCast_eq_intCast_iff' (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.intCast_eq_intCast_iff a b c
theorem val_intCast {n : ℕ} (a : ℤ) [NeZero n] : ↑(a : ZMod n).val = a % n := by
have hle : (0 : ℤ) ≤ ↑(a : ZMod n).val := Int.natCast_nonneg _
have hlt : ↑(a : ZMod n).val < (n : ℤ) := Int.ofNat_lt.mpr (ZMod.val_lt a)
refine (Int.emod_eq_of_lt hle hlt).symm.trans ?_
rw [← ZMod.intCast_eq_intCast_iff', Int.cast_natCast, ZMod.natCast_val, ZMod.cast_id]
theorem natCast_eq_natCast_iff (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [MOD c] := by
simpa [Int.natCast_modEq_iff] using ZMod.intCast_eq_intCast_iff a b c
theorem natCast_eq_natCast_iff' (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.natCast_eq_natCast_iff a b c
theorem intCast_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : ZMod b) = 0 ↔ (b : ℤ) ∣ a := by
rw [← Int.cast_zero, ZMod.intCast_eq_intCast_iff, Int.modEq_zero_iff_dvd]
theorem intCast_eq_intCast_iff_dvd_sub (a b : ℤ) (c : ℕ) : (a : ZMod c) = ↑b ↔ ↑c ∣ b - a := by
rw [ZMod.intCast_eq_intCast_iff, Int.modEq_iff_dvd]
theorem natCast_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : ZMod b) = 0 ↔ b ∣ a := by
rw [← Nat.cast_zero, ZMod.natCast_eq_natCast_iff, Nat.modEq_zero_iff_dvd]
theorem coe_intCast (a : ℤ) : cast (a : ZMod n) = a % n := by
cases n
· rw [Int.ofNat_zero, Int.emod_zero, Int.cast_id]; rfl
· rw [← val_intCast, val]; rfl
lemma intCast_cast_add (x y : ZMod n) : (cast (x + y) : ℤ) = (cast x + cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_add, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_mul (x y : ZMod n) : (cast (x * y) : ℤ) = cast x * cast y % n := by
rw [← ZMod.coe_intCast, Int.cast_mul, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_sub (x y : ZMod n) : (cast (x - y) : ℤ) = (cast x - cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_sub, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_neg (x : ZMod n) : (cast (-x) : ℤ) = -cast x % n := by
rw [← ZMod.coe_intCast, Int.cast_neg, ZMod.intCast_zmod_cast]
@[simp]
theorem val_neg_one (n : ℕ) : (-1 : ZMod n.succ).val = n := by
dsimp [val, Fin.coe_neg]
cases n
· simp [Nat.mod_one]
· dsimp [ZMod, ZMod.cast]
rw [Fin.coe_neg_one]
/-- `-1 : ZMod n` lifts to `n - 1 : R`. This avoids the characteristic assumption in `cast_neg`. -/
theorem cast_neg_one {R : Type*} [Ring R] (n : ℕ) : cast (-1 : ZMod n) = (n - 1 : R) := by
rcases n with - | n
· dsimp [ZMod, ZMod.cast]; simp
· rw [← natCast_val, val_neg_one, Nat.cast_succ, add_sub_cancel_right]
theorem cast_sub_one {R : Type*} [Ring R] {n : ℕ} (k : ZMod n) :
(cast (k - 1 : ZMod n) : R) = (if k = 0 then (n : R) else cast k) - 1 := by
split_ifs with hk
· rw [hk, zero_sub, ZMod.cast_neg_one]
· cases n
· dsimp [ZMod, ZMod.cast]
rw [Int.cast_sub, Int.cast_one]
· dsimp [ZMod, ZMod.cast, ZMod.val]
rw [Fin.coe_sub_one, if_neg]
· rw [Nat.cast_sub, Nat.cast_one]
rwa [Fin.ext_iff, Fin.val_zero, ← Ne, ← Nat.one_le_iff_ne_zero] at hk
· exact hk
theorem natCast_eq_iff (p : ℕ) (n : ℕ) (z : ZMod p) [NeZero p] :
↑n = z ↔ ∃ k, n = z.val + p * k := by
constructor
· rintro rfl
refine ⟨n / p, ?_⟩
rw [val_natCast, Nat.mod_add_div]
· rintro ⟨k, rfl⟩
rw [Nat.cast_add, natCast_zmod_val, Nat.cast_mul, natCast_self, zero_mul,
add_zero]
theorem intCast_eq_iff (p : ℕ) (n : ℤ) (z : ZMod p) [NeZero p] :
↑n = z ↔ ∃ k, n = z.val + p * k := by
constructor
· rintro rfl
refine ⟨n / p, ?_⟩
rw [val_intCast, Int.emod_add_ediv]
· rintro ⟨k, rfl⟩
rw [Int.cast_add, Int.cast_mul, Int.cast_natCast, Int.cast_natCast, natCast_val,
ZMod.natCast_self, zero_mul, add_zero, cast_id]
@[push_cast, simp]
theorem intCast_mod (a : ℤ) (b : ℕ) : ((a % b : ℤ) : ZMod b) = (a : ZMod b) := by
rw [ZMod.intCast_eq_intCast_iff]
apply Int.mod_modEq
theorem ker_intCastAddHom (n : ℕ) :
(Int.castAddHom (ZMod n)).ker = AddSubgroup.zmultiples (n : ℤ) := by
ext
rw [Int.mem_zmultiples_iff, AddMonoidHom.mem_ker, Int.coe_castAddHom,
intCast_zmod_eq_zero_iff_dvd]
theorem cast_injective_of_le {m n : ℕ} [nzm : NeZero m] (h : m ≤ n) :
Function.Injective (@cast (ZMod n) _ m) := by
cases m with
| zero => cases nzm; simp_all
| succ m =>
rintro ⟨x, hx⟩ ⟨y, hy⟩ f
simp only [cast, val, natCast_eq_natCast_iff',
Nat.mod_eq_of_lt (hx.trans_le h), Nat.mod_eq_of_lt (hy.trans_le h)] at f
apply Fin.ext
exact f
theorem cast_zmod_eq_zero_iff_of_le {m n : ℕ} [NeZero m] (h : m ≤ n) (a : ZMod m) :
(cast a : ZMod n) = 0 ↔ a = 0 := by
rw [← ZMod.cast_zero (n := m)]
exact Injective.eq_iff' (cast_injective_of_le h) rfl
@[simp]
theorem natCast_toNat (p : ℕ) : ∀ {z : ℤ} (_h : 0 ≤ z), (z.toNat : ZMod p) = z
| (n : ℕ), _h => by simp only [Int.cast_natCast, Int.toNat_natCast]
| Int.negSucc n, h => by simp at h
theorem val_injective (n : ℕ) [NeZero n] : Function.Injective (val : ZMod n → ℕ) := by
cases n
· cases NeZero.ne 0 rfl
intro a b h
dsimp [ZMod]
ext
exact h
theorem val_one_eq_one_mod (n : ℕ) : (1 : ZMod n).val = 1 % n := by
rw [← Nat.cast_one, val_natCast]
theorem val_two_eq_two_mod (n : ℕ) : (2 : ZMod n).val = 2 % n := by
rw [← Nat.cast_two, val_natCast]
theorem val_one (n : ℕ) [Fact (1 < n)] : (1 : ZMod n).val = 1 := by
rw [val_one_eq_one_mod]
exact Nat.mod_eq_of_lt Fact.out
lemma val_one'' : ∀ {n}, n ≠ 1 → (1 : ZMod n).val = 1
| 0, _ => rfl
| 1, hn => by cases hn rfl
| n + 2, _ =>
haveI : Fact (1 < n + 2) := ⟨by simp⟩
ZMod.val_one _
theorem val_add {n : ℕ} [NeZero n] (a b : ZMod n) : (a + b).val = (a.val + b.val) % n := by
cases n
· cases NeZero.ne 0 rfl
· apply Fin.val_add
theorem val_add_of_lt {n : ℕ} {a b : ZMod n} (h : a.val + b.val < n) :
(a + b).val = a.val + b.val := by
have : NeZero n := by constructor; rintro rfl; simp at h
rw [ZMod.val_add, Nat.mod_eq_of_lt h]
| Mathlib/Data/ZMod/Basic.lean | 636 | 641 | theorem val_add_val_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) :
a.val + b.val = (a + b).val + n := by | rw [val_add, Nat.add_mod_add_of_le_add_mod, Nat.mod_eq_of_lt (val_lt _),
Nat.mod_eq_of_lt (val_lt _)]
rwa [Nat.mod_eq_of_lt (val_lt _), Nat.mod_eq_of_lt (val_lt _)] |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Eric Wieser
-/
import Mathlib.Data.Finset.Sym
import Mathlib.LinearAlgebra.BilinearMap
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.SesquilinearForm
import Mathlib.LinearAlgebra.Matrix.Symmetric
/-!
# Quadratic maps
This file defines quadratic maps on an `R`-module `M`, taking values in an `R`-module `N`.
An `N`-valued quadratic map on a module `M` over a commutative ring `R` is a map `Q : M → N` such
that:
* `QuadraticMap.map_smul`: `Q (a • x) = (a * a) • Q x`
* `QuadraticMap.polar_add_left`, `QuadraticMap.polar_add_right`,
`QuadraticMap.polar_smul_left`, `QuadraticMap.polar_smul_right`:
the map `QuadraticMap.polar Q := fun x y ↦ Q (x + y) - Q x - Q y` is bilinear.
This notion generalizes to commutative semirings using the approach in [izhakian2016][] which
requires that there be a (possibly non-unique) companion bilinear map `B` such that
`∀ x y, Q (x + y) = Q x + Q y + B x y`. Over a ring, this `B` is precisely `QuadraticMap.polar Q`.
To build a `QuadraticMap` from the `polar` axioms, use `QuadraticMap.ofPolar`.
Quadratic maps come with a scalar multiplication, `(a • Q) x = a • Q x`,
and composition with linear maps `f`, `Q.comp f x = Q (f x)`.
## Main definitions
* `QuadraticMap.ofPolar`: a more familiar constructor that works on rings
* `QuadraticMap.associated`: associated bilinear map
* `QuadraticMap.PosDef`: positive definite quadratic maps
* `QuadraticMap.Anisotropic`: anisotropic quadratic maps
* `QuadraticMap.discr`: discriminant of a quadratic map
* `QuadraticMap.IsOrtho`: orthogonality of vectors with respect to a quadratic map.
## Main statements
* `QuadraticMap.associated_left_inverse`,
* `QuadraticMap.associated_rightInverse`: in a commutative ring where 2 has
an inverse, there is a correspondence between quadratic maps and symmetric
bilinear forms
* `LinearMap.BilinForm.exists_orthogonal_basis`: There exists an orthogonal basis with
respect to any nondegenerate, symmetric bilinear map `B`.
## Notation
In this file, the variable `R` is used when a `CommSemiring` structure is available.
The variable `S` is used when `R` itself has a `•` action.
## Implementation notes
While the definition and many results make sense if we drop commutativity assumptions,
the correct definition of a quadratic maps in the noncommutative setting would require
substantial refactors from the current version, such that $Q(rm) = rQ(m)r^*$ for some
suitable conjugation $r^*$.
The [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Quadratic.20Maps/near/395529867)
has some further discussion.
## References
* https://en.wikipedia.org/wiki/Quadratic_form
* https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms
## Tags
quadratic map, homogeneous polynomial, quadratic polynomial
-/
universe u v w
variable {S T : Type*}
variable {R : Type*} {M N P A : Type*}
open LinearMap (BilinMap BilinForm)
section Polar
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
namespace QuadraticMap
/-- Up to a factor 2, `Q.polar` is the associated bilinear map for a quadratic map `Q`.
Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization
-/
def polar (f : M → N) (x y : M) :=
f (x + y) - f x - f y
protected theorem map_add (f : M → N) (x y : M) :
f (x + y) = f x + f y + polar f x y := by
rw [polar]
abel
theorem polar_add (f g : M → N) (x y : M) : polar (f + g) x y = polar f x y + polar g x y := by
simp only [polar, Pi.add_apply]
abel
theorem polar_neg (f : M → N) (x y : M) : polar (-f) x y = -polar f x y := by
simp only [polar, Pi.neg_apply, sub_eq_add_neg, neg_add]
theorem polar_smul [Monoid S] [DistribMulAction S N] (f : M → N) (s : S) (x y : M) :
polar (s • f) x y = s • polar f x y := by simp only [polar, Pi.smul_apply, smul_sub]
theorem polar_comm (f : M → N) (x y : M) : polar f x y = polar f y x := by
rw [polar, polar, add_comm, sub_sub, sub_sub, add_comm (f x) (f y)]
/-- Auxiliary lemma to express bilinearity of `QuadraticMap.polar` without subtraction. -/
theorem polar_add_left_iff {f : M → N} {x x' y : M} :
polar f (x + x') y = polar f x y + polar f x' y ↔
f (x + x' + y) + (f x + f x' + f y) = f (x + x') + f (x' + y) + f (y + x) := by
simp only [← add_assoc]
simp only [polar, sub_eq_iff_eq_add, eq_sub_iff_add_eq, sub_add_eq_add_sub, add_sub]
simp only [add_right_comm _ (f y) _, add_right_comm _ (f x') (f x)]
rw [add_comm y x, add_right_comm _ _ (f (x + y)), add_comm _ (f (x + y)),
add_right_comm (f (x + y)), add_left_inj]
theorem polar_comp {F : Type*} [AddCommGroup S] [FunLike F N S] [AddMonoidHomClass F N S]
(f : M → N) (g : F) (x y : M) :
polar (g ∘ f) x y = g (polar f x y) := by
simp only [polar, Pi.smul_apply, Function.comp_apply, map_sub]
/-- `QuadraticMap.polar` as a function from `Sym2`. -/
def polarSym2 (f : M → N) : Sym2 M → N :=
Sym2.lift ⟨polar f, polar_comm _⟩
@[simp]
lemma polarSym2_sym2Mk (f : M → N) (xy : M × M) : polarSym2 f (.mk xy) = polar f xy.1 xy.2 := rfl
end QuadraticMap
end Polar
/-- A quadratic map on a module.
For a more familiar constructor when `R` is a ring, see `QuadraticMap.ofPolar`. -/
structure QuadraticMap (R : Type u) (M : Type v) (N : Type w) [CommSemiring R] [AddCommMonoid M]
[Module R M] [AddCommMonoid N] [Module R N] where
toFun : M → N
toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = (a * a) • toFun x
exists_companion' : ∃ B : BilinMap R M N, ∀ x y, toFun (x + y) = toFun x + toFun y + B x y
section QuadraticForm
variable (R : Type u) (M : Type v) [CommSemiring R] [AddCommMonoid M] [Module R M]
/-- A quadratic form on a module. -/
abbrev QuadraticForm : Type _ := QuadraticMap R M R
end QuadraticForm
namespace QuadraticMap
section DFunLike
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
variable {Q Q' : QuadraticMap R M N}
instance instFunLike : FunLike (QuadraticMap R M N) M N where
coe := toFun
coe_injective' x y h := by cases x; cases y; congr
variable (Q)
/-- The `simp` normal form for a quadratic map is `DFunLike.coe`, not `toFun`. -/
@[simp]
theorem toFun_eq_coe : Q.toFun = ⇑Q :=
rfl
-- this must come after the coe_to_fun definition
initialize_simps_projections QuadraticMap (toFun → apply)
variable {Q}
@[ext]
theorem ext (H : ∀ x : M, Q x = Q' x) : Q = Q' :=
DFunLike.ext _ _ H
theorem congr_fun (h : Q = Q') (x : M) : Q x = Q' x :=
DFunLike.congr_fun h _
/-- Copy of a `QuadraticMap` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : QuadraticMap R M N where
toFun := Q'
toFun_smul := h.symm ▸ Q.toFun_smul
exists_companion' := h.symm ▸ Q.exists_companion'
@[simp]
theorem coe_copy (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : ⇑(Q.copy Q' h) = Q' :=
rfl
theorem copy_eq (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : Q.copy Q' h = Q :=
DFunLike.ext' h
end DFunLike
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
variable (Q : QuadraticMap R M N)
protected theorem map_smul (a : R) (x : M) : Q (a • x) = (a * a) • Q x :=
Q.toFun_smul a x
theorem exists_companion : ∃ B : BilinMap R M N, ∀ x y, Q (x + y) = Q x + Q y + B x y :=
Q.exists_companion'
theorem map_add_add_add_map (x y z : M) :
Q (x + y + z) + (Q x + Q y + Q z) = Q (x + y) + Q (y + z) + Q (z + x) := by
obtain ⟨B, h⟩ := Q.exists_companion
rw [add_comm z x]
simp only [h, LinearMap.map_add₂]
abel
theorem map_add_self (x : M) : Q (x + x) = 4 • Q x := by
rw [← two_smul R x, Q.map_smul, ← Nat.cast_smul_eq_nsmul R]
norm_num
-- not @[simp] because it is superseded by `ZeroHomClass.map_zero`
protected theorem map_zero : Q 0 = 0 := by
rw [← @zero_smul R _ _ _ _ (0 : M), Q.map_smul, zero_mul, zero_smul]
instance zeroHomClass : ZeroHomClass (QuadraticMap R M N) M N :=
{ QuadraticMap.instFunLike (R := R) (M := M) (N := N) with map_zero := QuadraticMap.map_zero }
theorem map_smul_of_tower [CommSemiring S] [Algebra S R] [SMul S M] [IsScalarTower S R M]
[Module S N] [IsScalarTower S R N] (a : S)
(x : M) : Q (a • x) = (a * a) • Q x := by
rw [← IsScalarTower.algebraMap_smul R a x, Q.map_smul, ← RingHom.map_mul, algebraMap_smul]
end CommSemiring
section CommRing
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
variable [Module R M] [Module R N] (Q : QuadraticMap R M N)
@[simp]
protected theorem map_neg (x : M) : Q (-x) = Q x := by
rw [← @neg_one_smul R _ _ _ _ x, Q.map_smul, neg_one_mul, neg_neg, one_smul]
protected theorem map_sub (x y : M) : Q (x - y) = Q (y - x) := by rw [← neg_sub, Q.map_neg]
@[simp]
theorem polar_zero_left (y : M) : polar Q 0 y = 0 := by
simp only [polar, zero_add, QuadraticMap.map_zero, sub_zero, sub_self]
@[simp]
theorem polar_add_left (x x' y : M) : polar Q (x + x') y = polar Q x y + polar Q x' y :=
polar_add_left_iff.mpr <| Q.map_add_add_add_map x x' y
@[simp]
theorem polar_smul_left (a : R) (x y : M) : polar Q (a • x) y = a • polar Q x y := by
obtain ⟨B, h⟩ := Q.exists_companion
simp_rw [polar, h, Q.map_smul, LinearMap.map_smul₂, sub_sub, add_sub_cancel_left]
@[simp]
theorem polar_neg_left (x y : M) : polar Q (-x) y = -polar Q x y := by
rw [← neg_one_smul R x, polar_smul_left, neg_one_smul]
@[simp]
theorem polar_sub_left (x x' y : M) : polar Q (x - x') y = polar Q x y - polar Q x' y := by
rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_left, polar_neg_left]
@[simp]
theorem polar_zero_right (y : M) : polar Q y 0 = 0 := by
simp only [add_zero, polar, QuadraticMap.map_zero, sub_self]
@[simp]
theorem polar_add_right (x y y' : M) : polar Q x (y + y') = polar Q x y + polar Q x y' := by
rw [polar_comm Q x, polar_comm Q x, polar_comm Q x, polar_add_left]
@[simp]
theorem polar_smul_right (a : R) (x y : M) : polar Q x (a • y) = a • polar Q x y := by
rw [polar_comm Q x, polar_comm Q x, polar_smul_left]
@[simp]
theorem polar_neg_right (x y : M) : polar Q x (-y) = -polar Q x y := by
rw [← neg_one_smul R y, polar_smul_right, neg_one_smul]
@[simp]
| Mathlib/LinearAlgebra/QuadraticForm/Basic.lean | 291 | 292 | theorem polar_sub_right (x y y' : M) : polar Q x (y - y') = polar Q x y - polar Q x y' := by | rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_right, polar_neg_right] |
/-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Calculus.InverseFunctionTheorem.ApproximatesLinearOn
import Mathlib.Analysis.Normed.Module.FiniteDimension
/-!
# A lemma about `ApproximatesLinearOn` that needs `FiniteDimensional`
In this file we prove that in a real vector space,
a function `f` that approximates a linear equivalence on a subset `s`
can be extended to a homeomorphism of the whole space.
This used to be the only lemma in `Mathlib/Analysis/Calculus/Inverse`
depending on `FiniteDimensional`, so it was moved to a new file when the original file got split.
-/
open Set
open scoped NNReal
namespace ApproximatesLinearOn
/-- In a real vector space, a function `f` that approximates a linear equivalence on a subset `s`
can be extended to a homeomorphism of the whole space. -/
| Mathlib/Analysis/Calculus/InverseFunctionTheorem/FiniteDimensional.lean | 27 | 47 | theorem exists_homeomorph_extension {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
{F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [FiniteDimensional ℝ F] {s : Set E}
{f : E → F} {f' : E ≃L[ℝ] F} {c : ℝ≥0} (hf : ApproximatesLinearOn f (f' : E →L[ℝ] F) s c)
(hc : Subsingleton E ∨ lipschitzExtensionConstant F * c < ‖(f'.symm : F →L[ℝ] E)‖₊⁻¹) :
∃ g : E ≃ₜ F, EqOn f g s := by | -- the difference `f - f'` is Lipschitz on `s`. It can be extended to a Lipschitz function `u`
-- on the whole space, with a slightly worse Lipschitz constant. Then `f' + u` will be the
-- desired homeomorphism.
obtain ⟨u, hu, uf⟩ :
∃ u : E → F, LipschitzWith (lipschitzExtensionConstant F * c) u ∧ EqOn (f - ⇑f') u s :=
hf.lipschitzOnWith.extend_finite_dimension
let g : E → F := fun x => f' x + u x
have fg : EqOn f g s := fun x hx => by simp_rw [g, ← uf hx, Pi.sub_apply, add_sub_cancel]
have hg : ApproximatesLinearOn g (f' : E →L[ℝ] F) univ (lipschitzExtensionConstant F * c) := by
apply LipschitzOnWith.approximatesLinearOn
rw [lipschitzOnWith_univ]
convert hu
ext x
simp only [g, add_sub_cancel_left, ContinuousLinearEquiv.coe_coe, Pi.sub_apply]
haveI : FiniteDimensional ℝ E := f'.symm.finiteDimensional
exact ⟨hg.toHomeomorph g hc, fg⟩ |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.Ring.Rat
import Mathlib.Algebra.Ring.Int.Parity
import Mathlib.Data.PNat.Defs
/-!
# Further lemmas for the Rational Numbers
-/
namespace Rat
theorem num_dvd (a) {b : ℤ} (b0 : b ≠ 0) : (a /. b).num ∣ a := by
rcases e : a /. b with ⟨n, d, h, c⟩
rw [Rat.mk'_eq_divInt, divInt_eq_iff b0 (mod_cast h)] at e
refine Int.natAbs_dvd.1 <| Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <|
c.dvd_of_dvd_mul_right ?_
have := congr_arg Int.natAbs e
simp only [Int.natAbs_mul, Int.natAbs_natCast] at this; simp [this]
theorem den_dvd (a b : ℤ) : ((a /. b).den : ℤ) ∣ b := by
by_cases b0 : b = 0; · simp [b0]
rcases e : a /. b with ⟨n, d, h, c⟩
rw [mk'_eq_divInt, divInt_eq_iff b0 (ne_of_gt (Int.natCast_pos.2 (Nat.pos_of_ne_zero h)))] at e
refine Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <| c.symm.dvd_of_dvd_mul_left ?_
rw [← Int.natAbs_mul, ← Int.natCast_dvd_natCast, Int.dvd_natAbs, ← e]; simp
theorem num_den_mk {q : ℚ} {n d : ℤ} (hd : d ≠ 0) (qdf : q = n /. d) :
∃ c : ℤ, n = c * q.num ∧ d = c * q.den := by
obtain rfl | hn := eq_or_ne n 0
· simp [qdf]
have : q.num * d = n * ↑q.den := by
refine (divInt_eq_iff ?_ hd).mp ?_
· exact Int.natCast_ne_zero.mpr (Rat.den_nz _)
· rwa [num_divInt_den]
have hqdn : q.num ∣ n := by
rw [qdf]
exact Rat.num_dvd _ hd
refine ⟨n / q.num, ?_, ?_⟩
· rw [Int.ediv_mul_cancel hqdn]
· refine Int.eq_mul_div_of_mul_eq_mul_of_dvd_left ?_ hqdn this
rw [qdf]
exact Rat.num_ne_zero.2 ((divInt_ne_zero hd).mpr hn)
theorem num_mk (n d : ℤ) : (n /. d).num = d.sign * n / n.gcd d := by
have (m : ℕ) : Int.natAbs (m + 1) = m + 1 := by
rw [← Nat.cast_one, ← Nat.cast_add, Int.natAbs_cast]
rcases d with ((_ | _) | _) <;>
rw [← Int.tdiv_eq_ediv_of_dvd] <;>
simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd,
Int.zero_ediv, Int.ofNat_dvd_left, Nat.gcd_dvd_left, this]
theorem den_mk (n d : ℤ) : (n /. d).den = if d = 0 then 1 else d.natAbs / n.gcd d := by
have (m : ℕ) : Int.natAbs (m + 1) = m + 1 := by
rw [← Nat.cast_one, ← Nat.cast_add, Int.natAbs_cast]
rcases d with ((_ | _) | _) <;>
simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd,
if_neg (Nat.cast_add_one_ne_zero _), this]
theorem add_den_dvd_lcm (q₁ q₂ : ℚ) : (q₁ + q₂).den ∣ q₁.den.lcm q₂.den := by
rw [add_def, normalize_eq, Nat.div_dvd_iff_dvd_mul (Nat.gcd_dvd_right _ _)
(Nat.gcd_ne_zero_right (by simp)), ← Nat.gcd_mul_lcm,
mul_dvd_mul_iff_right (Nat.lcm_ne_zero (by simp) (by simp)), Nat.dvd_gcd_iff]
refine ⟨?_, dvd_mul_right _ _⟩
rw [← Int.natCast_dvd_natCast, Int.dvd_natAbs]
apply Int.dvd_add
<;> apply dvd_mul_of_dvd_right <;> rw [Int.natCast_dvd_natCast]
<;> [exact Nat.gcd_dvd_right _ _; exact Nat.gcd_dvd_left _ _]
theorem add_den_dvd (q₁ q₂ : ℚ) : (q₁ + q₂).den ∣ q₁.den * q₂.den := by
rw [add_def, normalize_eq]
apply Nat.div_dvd_of_dvd
apply Nat.gcd_dvd_right
theorem mul_den_dvd (q₁ q₂ : ℚ) : (q₁ * q₂).den ∣ q₁.den * q₂.den := by
rw [mul_def, normalize_eq]
apply Nat.div_dvd_of_dvd
apply Nat.gcd_dvd_right
theorem mul_num (q₁ q₂ : ℚ) :
(q₁ * q₂).num = q₁.num * q₂.num / Nat.gcd (q₁.num * q₂.num).natAbs (q₁.den * q₂.den) := by
rw [mul_def, normalize_eq]
theorem mul_den (q₁ q₂ : ℚ) :
(q₁ * q₂).den =
q₁.den * q₂.den / Nat.gcd (q₁.num * q₂.num).natAbs (q₁.den * q₂.den) := by
rw [mul_def, normalize_eq]
theorem mul_self_num (q : ℚ) : (q * q).num = q.num * q.num := by
rw [mul_num, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Int.ofNat_one, Int.ediv_one]
exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced)
theorem mul_self_den (q : ℚ) : (q * q).den = q.den * q.den := by
rw [Rat.mul_den, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Nat.div_one]
exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced)
theorem add_num_den (q r : ℚ) :
q + r = (q.num * r.den + q.den * r.num : ℤ) /. (↑q.den * ↑r.den : ℤ) := by
have hqd : (q.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.2 q.den_pos
have hrd : (r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.2 r.den_pos
conv_lhs => rw [← num_divInt_den q, ← num_divInt_den r, divInt_add_divInt _ _ hqd hrd]
rw [mul_comm r.num q.den]
theorem isSquare_iff {q : ℚ} : IsSquare q ↔ IsSquare q.num ∧ IsSquare q.den := by
constructor
· rintro ⟨qr, rfl⟩
rw [Rat.mul_self_num, mul_self_den]
simp only [IsSquare.mul_self, and_self]
· rintro ⟨⟨nr, hnr⟩, ⟨dr, hdr⟩⟩
refine ⟨nr / dr, ?_⟩
rw [div_mul_div_comm, ← Int.cast_mul, ← Nat.cast_mul, ← hnr, ← hdr, num_div_den]
@[norm_cast, simp]
theorem isSquare_natCast_iff {n : ℕ} : IsSquare (n : ℚ) ↔ IsSquare n := by
simp_rw [isSquare_iff, num_natCast, den_natCast, IsSquare.one, and_true, Int.isSquare_natCast_iff]
@[norm_cast, simp]
theorem isSquare_intCast_iff {z : ℤ} : IsSquare (z : ℚ) ↔ IsSquare z := by
simp_rw [isSquare_iff, intCast_num, intCast_den, IsSquare.one, and_true]
@[simp]
theorem isSquare_ofNat_iff {n : ℕ} :
IsSquare (ofNat(n) : ℚ) ↔ IsSquare (OfNat.ofNat n : ℕ) :=
isSquare_natCast_iff
section Casts
theorem exists_eq_mul_div_num_and_eq_mul_div_den (n : ℤ) {d : ℤ} (d_ne_zero : d ≠ 0) :
∃ c : ℤ, n = c * ((n : ℚ) / d).num ∧ (d : ℤ) = c * ((n : ℚ) / d).den :=
haveI : (n : ℚ) / d = Rat.divInt n d := by rw [← Rat.divInt_eq_div]
Rat.num_den_mk d_ne_zero this
theorem mul_num_den' (q r : ℚ) :
(q * r).num * q.den * r.den = q.num * r.num * (q * r).den := by
let s := q.num * r.num /. (q.den * r.den : ℤ)
have hs : (q.den * r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.mpr (Nat.mul_pos q.pos r.pos)
obtain ⟨c, ⟨c_mul_num, c_mul_den⟩⟩ :=
exists_eq_mul_div_num_and_eq_mul_div_den (q.num * r.num) hs
rw [c_mul_num, mul_assoc, mul_comm]
nth_rw 1 [c_mul_den]
rw [Int.mul_assoc, Int.mul_assoc, mul_eq_mul_left_iff, or_iff_not_imp_right]
intro
have h : _ = s := divInt_mul_divInt q.num r.num (mod_cast q.den_ne_zero) (mod_cast r.den_ne_zero)
rw [num_divInt_den, num_divInt_den] at h
rw [h, mul_comm, ← Rat.eq_iff_mul_eq_mul, ← divInt_eq_div]
| Mathlib/Data/Rat/Lemmas.lean | 154 | 166 | theorem add_num_den' (q r : ℚ) :
(q + r).num * q.den * r.den = (q.num * r.den + r.num * q.den) * (q + r).den := by | let s := divInt (q.num * r.den + r.num * q.den) (q.den * r.den : ℤ)
have hs : (q.den * r.den : ℤ) ≠ 0 := Int.natCast_ne_zero_iff_pos.mpr (Nat.mul_pos q.pos r.pos)
obtain ⟨c, ⟨c_mul_num, c_mul_den⟩⟩ :=
exists_eq_mul_div_num_and_eq_mul_div_den (q.num * r.den + r.num * q.den) hs
rw [c_mul_num, mul_assoc, mul_comm]
nth_rw 1 [c_mul_den]
repeat rw [Int.mul_assoc]
apply mul_eq_mul_left_iff.2
rw [or_iff_not_imp_right]
intro
have h : _ = s := divInt_add_divInt q.num r.num (mod_cast q.den_ne_zero) (mod_cast r.den_ne_zero) |
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Neil Strickland
-/
import Mathlib.Data.Nat.Prime.Defs
import Mathlib.Data.PNat.Basic
/-!
# Primality and GCD on pnat
This file extends the theory of `ℕ+` with `gcd`, `lcm` and `Prime` functions, analogous to those on
`Nat`.
-/
namespace Nat.Primes
/-- The canonical map from `Nat.Primes` to `ℕ+` -/
@[coe] def toPNat : Nat.Primes → ℕ+ :=
fun p => ⟨(p : ℕ), p.property.pos⟩
instance coePNat : Coe Nat.Primes ℕ+ :=
⟨toPNat⟩
@[norm_cast]
theorem coe_pnat_nat (p : Nat.Primes) : ((p : ℕ+) : ℕ) = p :=
rfl
theorem coe_pnat_injective : Function.Injective ((↑) : Nat.Primes → ℕ+) := fun p q h =>
Subtype.ext (by injection h)
@[norm_cast]
theorem coe_pnat_inj (p q : Nat.Primes) : (p : ℕ+) = (q : ℕ+) ↔ p = q :=
coe_pnat_injective.eq_iff
end Nat.Primes
namespace PNat
open Nat
/-- The greatest common divisor (gcd) of two positive natural numbers,
viewed as positive natural number. -/
def gcd (n m : ℕ+) : ℕ+ :=
⟨Nat.gcd (n : ℕ) (m : ℕ), Nat.gcd_pos_of_pos_left (m : ℕ) n.pos⟩
/-- The least common multiple (lcm) of two positive natural numbers,
viewed as positive natural number. -/
def lcm (n m : ℕ+) : ℕ+ :=
⟨Nat.lcm (n : ℕ) (m : ℕ), by
let h := mul_pos n.pos m.pos
rw [← gcd_mul_lcm (n : ℕ) (m : ℕ), mul_comm] at h
exact pos_of_dvd_of_pos (Dvd.intro (Nat.gcd (n : ℕ) (m : ℕ)) rfl) h⟩
@[simp, norm_cast]
theorem gcd_coe (n m : ℕ+) : (gcd n m : ℕ) = Nat.gcd n m :=
rfl
@[simp, norm_cast]
theorem lcm_coe (n m : ℕ+) : (lcm n m : ℕ) = Nat.lcm n m :=
rfl
theorem gcd_dvd_left (n m : ℕ+) : gcd n m ∣ n :=
dvd_iff.2 (Nat.gcd_dvd_left (n : ℕ) (m : ℕ))
theorem gcd_dvd_right (n m : ℕ+) : gcd n m ∣ m :=
dvd_iff.2 (Nat.gcd_dvd_right (n : ℕ) (m : ℕ))
theorem dvd_gcd {m n k : ℕ+} (hm : k ∣ m) (hn : k ∣ n) : k ∣ gcd m n :=
dvd_iff.2 (Nat.dvd_gcd (dvd_iff.1 hm) (dvd_iff.1 hn))
theorem dvd_lcm_left (n m : ℕ+) : n ∣ lcm n m :=
dvd_iff.2 (Nat.dvd_lcm_left (n : ℕ) (m : ℕ))
theorem dvd_lcm_right (n m : ℕ+) : m ∣ lcm n m :=
dvd_iff.2 (Nat.dvd_lcm_right (n : ℕ) (m : ℕ))
theorem lcm_dvd {m n k : ℕ+} (hm : m ∣ k) (hn : n ∣ k) : lcm m n ∣ k :=
dvd_iff.2 (@Nat.lcm_dvd (m : ℕ) (n : ℕ) (k : ℕ) (dvd_iff.1 hm) (dvd_iff.1 hn))
theorem gcd_mul_lcm (n m : ℕ+) : gcd n m * lcm n m = n * m :=
Subtype.eq (Nat.gcd_mul_lcm (n : ℕ) (m : ℕ))
theorem eq_one_of_lt_two {n : ℕ+} : n < 2 → n = 1 := by
intro h; apply le_antisymm; swap
· apply PNat.one_le
· exact PNat.lt_add_one_iff.1 h
section Prime
/-! ### Prime numbers -/
/-- Primality predicate for `ℕ+`, defined in terms of `Nat.Prime`. -/
def Prime (p : ℕ+) : Prop :=
(p : ℕ).Prime
theorem Prime.one_lt {p : ℕ+} : p.Prime → 1 < p :=
Nat.Prime.one_lt
theorem prime_two : (2 : ℕ+).Prime :=
Nat.prime_two
instance {p : ℕ+} [h : Fact p.Prime] : Fact (p : ℕ).Prime := h
instance fact_prime_two : Fact (2 : ℕ+).Prime :=
⟨prime_two⟩
theorem prime_three : (3 : ℕ+).Prime :=
Nat.prime_three
instance fact_prime_three : Fact (3 : ℕ+).Prime :=
⟨prime_three⟩
theorem prime_five : (5 : ℕ+).Prime :=
Nat.prime_five
instance fact_prime_five : Fact (5 : ℕ+).Prime :=
⟨prime_five⟩
theorem dvd_prime {p m : ℕ+} (pp : p.Prime) : m ∣ p ↔ m = 1 ∨ m = p := by
rw [PNat.dvd_iff]
rw [Nat.dvd_prime pp]
simp
theorem Prime.ne_one {p : ℕ+} : p.Prime → p ≠ 1 := by
intro pp
intro contra
apply Nat.Prime.ne_one pp
rw [PNat.coe_eq_one_iff]
apply contra
@[simp]
theorem not_prime_one : ¬(1 : ℕ+).Prime :=
Nat.not_prime_one
theorem Prime.not_dvd_one {p : ℕ+} : p.Prime → ¬p ∣ 1 := fun pp : p.Prime => by
rw [dvd_iff]
apply Nat.Prime.not_dvd_one pp
theorem exists_prime_and_dvd {n : ℕ+} (hn : n ≠ 1) : ∃ p : ℕ+, p.Prime ∧ p ∣ n := by
obtain ⟨p, hp⟩ := Nat.exists_prime_and_dvd (mt coe_eq_one_iff.mp hn)
exists (⟨p, Nat.Prime.pos hp.left⟩ : ℕ+); rw [dvd_iff]; apply hp
end Prime
section Coprime
/-! ### Coprime numbers and gcd -/
/-- Two pnats are coprime if their gcd is 1. -/
def Coprime (m n : ℕ+) : Prop :=
m.gcd n = 1
@[simp, norm_cast]
theorem coprime_coe {m n : ℕ+} : Nat.Coprime ↑m ↑n ↔ m.Coprime n := by
unfold Nat.Coprime Coprime
rw [← coe_inj]
simp
theorem Coprime.mul {k m n : ℕ+} : m.Coprime k → n.Coprime k → (m * n).Coprime k := by
repeat rw [← coprime_coe]
rw [mul_coe]
apply Nat.Coprime.mul
theorem Coprime.mul_right {k m n : ℕ+} : k.Coprime m → k.Coprime n → k.Coprime (m * n) := by
repeat rw [← coprime_coe]
rw [mul_coe]
apply Nat.Coprime.mul_right
theorem gcd_comm {m n : ℕ+} : m.gcd n = n.gcd m := by
apply eq
simp only [gcd_coe]
apply Nat.gcd_comm
theorem gcd_eq_left_iff_dvd {m n : ℕ+} : m.gcd n = m ↔ m ∣ n := by
rw [dvd_iff, ← Nat.gcd_eq_left_iff_dvd, ← coe_inj]
simp
theorem gcd_eq_right_iff_dvd {m n : ℕ+} : n.gcd m = m ↔ m ∣ n := by
rw [gcd_comm]
apply gcd_eq_left_iff_dvd
theorem Coprime.gcd_mul_left_cancel (m : ℕ+) {n k : ℕ+} :
k.Coprime n → (k * m).gcd n = m.gcd n := by
intro h; apply eq; simp only [gcd_coe, mul_coe]
apply Nat.Coprime.gcd_mul_left_cancel; simpa
theorem Coprime.gcd_mul_right_cancel (m : ℕ+) {n k : ℕ+} :
k.Coprime n → (m * k).gcd n = m.gcd n := by rw [mul_comm]; apply Coprime.gcd_mul_left_cancel
theorem Coprime.gcd_mul_left_cancel_right (m : ℕ+) {n k : ℕ+} :
k.Coprime m → m.gcd (k * n) = m.gcd n := by
intro h; iterate 2 rw [gcd_comm]; symm
apply Coprime.gcd_mul_left_cancel _ h
theorem Coprime.gcd_mul_right_cancel_right (m : ℕ+) {n k : ℕ+} :
k.Coprime m → m.gcd (n * k) = m.gcd n := by
rw [mul_comm]
apply Coprime.gcd_mul_left_cancel_right
@[simp]
theorem one_gcd {n : ℕ+} : gcd 1 n = 1 := by
rw [gcd_eq_left_iff_dvd]
apply one_dvd
@[simp]
| Mathlib/Data/PNat/Prime.lean | 210 | 214 | theorem gcd_one {n : ℕ+} : gcd n 1 = 1 := by | rw [gcd_comm]
apply one_gcd
@[symm] |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.CharP.Two
import Mathlib.Data.Nat.Cast.Field
import Mathlib.Data.Nat.Factorization.Basic
import Mathlib.Data.Nat.Factorization.Induction
import Mathlib.Data.Nat.Periodic
/-!
# Euler's totient function
This file defines [Euler's totient function](https://en.wikipedia.org/wiki/Euler's_totient_function)
`Nat.totient n` which counts the number of naturals less than `n` that are coprime with `n`.
We prove the divisor sum formula, namely that `n` equals `φ` summed over the divisors of `n`. See
`sum_totient`. We also prove two lemmas to help compute totients, namely `totient_mul` and
`totient_prime_pow`.
-/
assert_not_exists Algebra LinearMap
open Finset
namespace Nat
/-- Euler's totient function. This counts the number of naturals strictly less than `n` which are
coprime with `n`. -/
def totient (n : ℕ) : ℕ := #{a ∈ range n | n.Coprime a}
@[inherit_doc]
scoped notation "φ" => Nat.totient
@[simp]
theorem totient_zero : φ 0 = 0 :=
rfl
@[simp]
theorem totient_one : φ 1 = 1 := rfl
theorem totient_eq_card_coprime (n : ℕ) : φ n = #{a ∈ range n | n.Coprime a} := rfl
/-- A characterisation of `Nat.totient` that avoids `Finset`. -/
theorem totient_eq_card_lt_and_coprime (n : ℕ) : φ n = Nat.card { m | m < n ∧ n.Coprime m } := by
let e : { m | m < n ∧ n.Coprime m } ≃ {x ∈ range n | n.Coprime x} :=
{ toFun := fun m => ⟨m, by simpa only [Finset.mem_filter, Finset.mem_range] using m.property⟩
invFun := fun m => ⟨m, by simpa only [Finset.mem_filter, Finset.mem_range] using m.property⟩
left_inv := fun m => by simp only [Subtype.coe_mk, Subtype.coe_eta]
right_inv := fun m => by simp only [Subtype.coe_mk, Subtype.coe_eta] }
rw [totient_eq_card_coprime, card_congr e, card_eq_fintype_card, Fintype.card_coe]
theorem totient_le (n : ℕ) : φ n ≤ n :=
((range n).card_filter_le _).trans_eq (card_range n)
theorem totient_lt (n : ℕ) (hn : 1 < n) : φ n < n :=
(card_lt_card (filter_ssubset.2 ⟨0, by simp [hn.ne', pos_of_gt hn]⟩)).trans_eq (card_range n)
@[simp]
theorem totient_eq_zero : ∀ {n : ℕ}, φ n = 0 ↔ n = 0
| 0 => by decide
| n + 1 =>
suffices ∃ x < n + 1, (n + 1).gcd x = 1 by simpa [totient, filter_eq_empty_iff]
⟨1 % (n + 1), mod_lt _ n.succ_pos, by rw [gcd_comm, ← gcd_rec, gcd_one_right]⟩
@[simp] theorem totient_pos {n : ℕ} : 0 < φ n ↔ 0 < n := by simp [pos_iff_ne_zero]
instance neZero_totient {n : ℕ} [NeZero n] : NeZero n.totient :=
⟨(totient_pos.mpr <| NeZero.pos n).ne'⟩
theorem filter_coprime_Ico_eq_totient (a n : ℕ) :
#{x ∈ Ico n (n + a) | a.Coprime x} = totient a := by
rw [totient, filter_Ico_card_eq_of_periodic, count_eq_card_filter_range]
exact periodic_coprime a
theorem Ico_filter_coprime_le {a : ℕ} (k n : ℕ) (a_pos : 0 < a) :
#{x ∈ Ico k (k + n) | a.Coprime x} ≤ totient a * (n / a + 1) := by
conv_lhs => rw [← Nat.mod_add_div n a]
induction' n / a with i ih
· rw [← filter_coprime_Ico_eq_totient a k]
simp only [add_zero, mul_one, mul_zero, le_of_lt (mod_lt n a_pos), zero_add]
gcongr
exact le_of_lt (mod_lt n a_pos)
simp only [mul_succ]
simp_rw [← add_assoc] at ih ⊢
calc
#{x ∈ Ico k (k + n % a + a * i + a) | a.Coprime x}
≤ #{x ∈ Ico k (k + n % a + a * i) ∪
Ico (k + n % a + a * i) (k + n % a + a * i + a) | a.Coprime x} := by
gcongr
apply Ico_subset_Ico_union_Ico
_ ≤ #{x ∈ Ico k (k + n % a + a * i) | a.Coprime x} + a.totient := by
rw [filter_union, ← filter_coprime_Ico_eq_totient a (k + n % a + a * i)]
apply card_union_le
_ ≤ a.totient * i + a.totient + a.totient := add_le_add_right ih (totient a)
open ZMod
/-- Note this takes an explicit `Fintype ((ZMod n)ˣ)` argument to avoid trouble with instance
diamonds. -/
@[simp]
theorem _root_.ZMod.card_units_eq_totient (n : ℕ) [NeZero n] [Fintype (ZMod n)ˣ] :
Fintype.card (ZMod n)ˣ = φ n :=
calc
Fintype.card (ZMod n)ˣ = Fintype.card { x : ZMod n // x.val.Coprime n } :=
Fintype.card_congr ZMod.unitsEquivCoprime
_ = φ n := by
obtain ⟨m, rfl⟩ : ∃ m, n = m + 1 := exists_eq_succ_of_ne_zero NeZero.out
simp only [totient, Finset.card_eq_sum_ones, Fintype.card_subtype, Finset.sum_filter, ←
Fin.sum_univ_eq_sum_range, @Nat.coprime_comm (m + 1)]
rfl
theorem totient_even {n : ℕ} (hn : 2 < n) : Even n.totient := by
haveI : Fact (1 < n) := ⟨one_lt_two.trans hn⟩
haveI : NeZero n := NeZero.of_gt hn
suffices 2 = orderOf (-1 : (ZMod n)ˣ) by
rw [← ZMod.card_units_eq_totient, even_iff_two_dvd, this]
exact orderOf_dvd_card
rw [← orderOf_units, Units.coe_neg_one, orderOf_neg_one, ringChar.eq (ZMod n) n, if_neg hn.ne']
theorem totient_mul {m n : ℕ} (h : m.Coprime n) : φ (m * n) = φ m * φ n :=
if hmn0 : m * n = 0 then by
rcases Nat.mul_eq_zero.1 hmn0 with h | h <;>
simp only [totient_zero, mul_zero, zero_mul, h]
else by
haveI : NeZero (m * n) := ⟨hmn0⟩
haveI : NeZero m := ⟨left_ne_zero_of_mul hmn0⟩
haveI : NeZero n := ⟨right_ne_zero_of_mul hmn0⟩
simp only [← ZMod.card_units_eq_totient]
rw [Fintype.card_congr (Units.mapEquiv (ZMod.chineseRemainder h).toMulEquiv).toEquiv,
Fintype.card_congr (@MulEquiv.prodUnits (ZMod m) (ZMod n) _ _).toEquiv, Fintype.card_prod]
/-- For `d ∣ n`, the totient of `n/d` equals the number of values `k < n` such that `gcd n k = d` -/
| Mathlib/Data/Nat/Totient.lean | 134 | 144 | theorem totient_div_of_dvd {n d : ℕ} (hnd : d ∣ n) :
φ (n / d) = #{k ∈ range n | n.gcd k = d} := by | rcases d.eq_zero_or_pos with (rfl | hd0); · simp [eq_zero_of_zero_dvd hnd]
rcases hnd with ⟨x, rfl⟩
rw [Nat.mul_div_cancel_left x hd0]
apply Finset.card_bij fun k _ => d * k
· simp only [mem_filter, mem_range, and_imp, Coprime]
refine fun a ha1 ha2 => ⟨(mul_lt_mul_left hd0).2 ha1, ?_⟩
rw [gcd_mul_left, ha2, mul_one]
· simp [hd0.ne']
· simp only [mem_filter, mem_range, exists_prop, and_imp] |
/-
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.Algebra.Order.Ring.Int
import Mathlib.Data.Nat.SuccPred
/-!
# Successors and predecessors of integers
In this file, we show that `ℤ` is both an archimedean `SuccOrder` and an archimedean `PredOrder`.
-/
open Function Order
namespace Int
-- so that Lean reads `Int.succ` through `SuccOrder.succ`
@[instance] abbrev instSuccOrder : SuccOrder ℤ :=
{ SuccOrder.ofSuccLeIff succ fun {_ _} => Iff.rfl with succ := succ }
instance instSuccAddOrder : SuccAddOrder ℤ := ⟨fun _ => rfl⟩
-- so that Lean reads `Int.pred` through `PredOrder.pred`
@[instance] abbrev instPredOrder : PredOrder ℤ where
pred := pred
pred_le _ := (sub_one_lt_of_le le_rfl).le
min_of_le_pred ha := ((sub_one_lt_of_le le_rfl).not_le ha).elim
le_pred_of_lt {_ _} := le_sub_one_of_lt
instance instPredSubOrder : PredSubOrder ℤ := ⟨fun _ => rfl⟩
@[simp]
theorem succ_eq_succ : Order.succ = succ :=
rfl
@[simp]
theorem pred_eq_pred : Order.pred = pred :=
rfl
instance : IsSuccArchimedean ℤ :=
⟨fun {a b} h =>
⟨(b - a).toNat, by rw [succ_iterate, toNat_sub_of_le h, ← add_sub_assoc, add_sub_cancel_left]⟩⟩
instance : IsPredArchimedean ℤ :=
⟨fun {a b} h =>
⟨(b - a).toNat, by rw [pred_iterate, toNat_sub_of_le h, sub_sub_cancel]⟩⟩
/-! ### Covering relation -/
@[simp, norm_cast]
| Mathlib/Data/Int/SuccPred.lean | 55 | 59 | theorem natCast_covBy {a b : ℕ} : (a : ℤ) ⋖ b ↔ a ⋖ b := by | rw [Order.covBy_iff_add_one_eq, Order.covBy_iff_add_one_eq]
exact Int.natCast_inj
end Int |
/-
Copyright (c) 2022 Wrenna Robson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wrenna Robson
-/
import Mathlib.Topology.MetricSpace.Basic
/-!
# Infimum separation
This file defines the extended infimum separation of a set. This is approximately dual to the
diameter of a set, but where the extended diameter of a set is the supremum of the extended distance
between elements of the set, the extended infimum separation is the infimum of the (extended)
distance between *distinct* elements in the set.
We also define the infimum separation as the cast of the extended infimum separation to the reals.
This is the infimum of the distance between distinct elements of the set when in a pseudometric
space.
All lemmas and definitions are in the `Set` namespace to give access to dot notation.
## Main definitions
* `Set.einfsep`: Extended infimum separation of a set.
* `Set.infsep`: Infimum separation of a set (when in a pseudometric space).
-/
variable {α β : Type*}
namespace Set
section Einfsep
open ENNReal
open Function
/-- The "extended infimum separation" of a set with an edist function. -/
noncomputable def einfsep [EDist α] (s : Set α) : ℝ≥0∞ :=
⨅ (x ∈ s) (y ∈ s) (_ : x ≠ y), edist x y
section EDist
variable [EDist α] {x y : α} {s t : Set α}
theorem le_einfsep_iff {d} :
d ≤ s.einfsep ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y := by
simp_rw [einfsep, le_iInf_iff]
theorem einfsep_zero : s.einfsep = 0 ↔ ∀ C > 0, ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < C := by
simp_rw [einfsep, ← _root_.bot_eq_zero, iInf_eq_bot, iInf_lt_iff, exists_prop]
theorem einfsep_pos : 0 < s.einfsep ↔ ∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := by
rw [pos_iff_ne_zero, Ne, einfsep_zero]
simp only [not_forall, not_exists, not_lt, exists_prop, not_and]
theorem einfsep_top :
s.einfsep = ∞ ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → edist x y = ∞ := by
simp_rw [einfsep, iInf_eq_top]
theorem einfsep_lt_top :
s.einfsep < ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < ∞ := by
simp_rw [einfsep, iInf_lt_iff, exists_prop]
theorem einfsep_ne_top :
s.einfsep ≠ ∞ ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y ≠ ∞ := by
simp_rw [← lt_top_iff_ne_top, einfsep_lt_top]
theorem einfsep_lt_iff {d} :
s.einfsep < d ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ edist x y < d := by
simp_rw [einfsep, iInf_lt_iff, exists_prop]
theorem nontrivial_of_einfsep_lt_top (hs : s.einfsep < ∞) : s.Nontrivial := by
rcases einfsep_lt_top.1 hs with ⟨_, hx, _, hy, hxy, _⟩
exact ⟨_, hx, _, hy, hxy⟩
theorem nontrivial_of_einfsep_ne_top (hs : s.einfsep ≠ ∞) : s.Nontrivial :=
nontrivial_of_einfsep_lt_top (lt_top_iff_ne_top.mpr hs)
theorem Subsingleton.einfsep (hs : s.Subsingleton) : s.einfsep = ∞ := by
rw [einfsep_top]
exact fun _ hx _ hy hxy => (hxy <| hs hx hy).elim
theorem le_einfsep_image_iff {d} {f : β → α} {s : Set β} : d ≤ einfsep (f '' s)
↔ ∀ x ∈ s, ∀ y ∈ s, f x ≠ f y → d ≤ edist (f x) (f y) := by
simp_rw [le_einfsep_iff, forall_mem_image]
theorem le_edist_of_le_einfsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)
(hd : d ≤ s.einfsep) : d ≤ edist x y :=
le_einfsep_iff.1 hd x hx y hy hxy
theorem einfsep_le_edist_of_mem {x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y) :
s.einfsep ≤ edist x y :=
le_edist_of_le_einfsep hx hy hxy le_rfl
theorem einfsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)
(hxy' : edist x y ≤ d) : s.einfsep ≤ d :=
le_trans (einfsep_le_edist_of_mem hx hy hxy) hxy'
theorem le_einfsep {d} (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y) : d ≤ s.einfsep :=
le_einfsep_iff.2 h
@[simp]
theorem einfsep_empty : (∅ : Set α).einfsep = ∞ :=
subsingleton_empty.einfsep
@[simp]
theorem einfsep_singleton : ({x} : Set α).einfsep = ∞ :=
subsingleton_singleton.einfsep
theorem einfsep_iUnion_mem_option {ι : Type*} (o : Option ι) (s : ι → Set α) :
(⋃ i ∈ o, s i).einfsep = ⨅ i ∈ o, (s i).einfsep := by cases o <;> simp
theorem einfsep_anti (hst : s ⊆ t) : t.einfsep ≤ s.einfsep :=
le_einfsep fun _x hx _y hy => einfsep_le_edist_of_mem (hst hx) (hst hy)
theorem einfsep_insert_le : (insert x s).einfsep ≤ ⨅ (y ∈ s) (_ : x ≠ y), edist x y := by
simp_rw [le_iInf_iff]
exact fun _ hy hxy => einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ hy) hxy
theorem le_einfsep_pair : edist x y ⊓ edist y x ≤ ({x, y} : Set α).einfsep := by
simp_rw [le_einfsep_iff, inf_le_iff, mem_insert_iff, mem_singleton_iff]
rintro a (rfl | rfl) b (rfl | rfl) hab <;> (try simp only [le_refl, true_or, or_true]) <;>
contradiction
theorem einfsep_pair_le_left (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist x y :=
einfsep_le_edist_of_mem (mem_insert _ _) (mem_insert_of_mem _ (mem_singleton _)) hxy
theorem einfsep_pair_le_right (hxy : x ≠ y) : ({x, y} : Set α).einfsep ≤ edist y x := by
rw [pair_comm]; exact einfsep_pair_le_left hxy.symm
theorem einfsep_pair_eq_inf (hxy : x ≠ y) : ({x, y} : Set α).einfsep = edist x y ⊓ edist y x :=
le_antisymm (le_inf (einfsep_pair_le_left hxy) (einfsep_pair_le_right hxy)) le_einfsep_pair
theorem einfsep_eq_iInf : s.einfsep = ⨅ d : s.offDiag, (uncurry edist) (d : α × α) := by
refine eq_of_forall_le_iff fun _ => ?_
simp_rw [le_einfsep_iff, le_iInf_iff, imp_forall_iff, SetCoe.forall, mem_offDiag,
Prod.forall, uncurry_apply_pair, and_imp]
theorem einfsep_of_fintype [DecidableEq α] [Fintype s] :
s.einfsep = s.offDiag.toFinset.inf (uncurry edist) := by
refine eq_of_forall_le_iff fun _ => ?_
simp_rw [le_einfsep_iff, imp_forall_iff, Finset.le_inf_iff, mem_toFinset, mem_offDiag,
Prod.forall, uncurry_apply_pair, and_imp]
theorem Finite.einfsep (hs : s.Finite) : s.einfsep = hs.offDiag.toFinset.inf (uncurry edist) := by
refine eq_of_forall_le_iff fun _ => ?_
simp_rw [le_einfsep_iff, imp_forall_iff, Finset.le_inf_iff, Finite.mem_toFinset, mem_offDiag,
Prod.forall, uncurry_apply_pair, and_imp]
theorem Finset.coe_einfsep [DecidableEq α] {s : Finset α} :
(s : Set α).einfsep = s.offDiag.inf (uncurry edist) := by
simp_rw [einfsep_of_fintype, ← Finset.coe_offDiag, Finset.toFinset_coe]
theorem Nontrivial.einfsep_exists_of_finite [Finite s] (hs : s.Nontrivial) :
∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.einfsep = edist x y := by
classical
cases nonempty_fintype s
simp_rw [einfsep_of_fintype]
rcases Finset.exists_mem_eq_inf s.offDiag.toFinset (by simpa) (uncurry edist) with ⟨w, hxy, hed⟩
simp_rw [mem_toFinset] at hxy
exact ⟨w.fst, hxy.1, w.snd, hxy.2.1, hxy.2.2, hed⟩
theorem Finite.einfsep_exists_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) :
∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ s.einfsep = edist x y :=
letI := hsf.fintype
hs.einfsep_exists_of_finite
end EDist
section PseudoEMetricSpace
variable [PseudoEMetricSpace α] {x y z : α} {s : Set α}
| Mathlib/Topology/MetricSpace/Infsep.lean | 176 | 179 | theorem einfsep_pair (hxy : x ≠ y) : ({x, y} : Set α).einfsep = edist x y := by | nth_rw 1 [← min_self (edist x y)]
convert einfsep_pair_eq_inf hxy using 2
rw [edist_comm] |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker, Andrew Yang, Yuyang Zhao
-/
import Mathlib.Algebra.Polynomial.Monic
import Mathlib.RingTheory.Polynomial.ScaleRoots
/-!
# Theory of monic polynomials
We define `integralNormalization`, which relate arbitrary polynomials to monic ones.
-/
open Polynomial
namespace Polynomial
universe u v y
variable {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y}
section IntegralNormalization
section Semiring
variable [Semiring R]
/-- If `p : R[X]` is a nonzero polynomial with root `z`, `integralNormalization p` is
a monic polynomial with root `leadingCoeff f * z`.
Moreover, `integralNormalization 0 = 0`.
-/
noncomputable def integralNormalization (p : R[X]) : R[X] :=
p.sum fun i a ↦
monomial i (if p.degree = i then 1 else a * p.leadingCoeff ^ (p.natDegree - 1 - i))
@[simp]
theorem integralNormalization_zero : integralNormalization (0 : R[X]) = 0 := by
simp [integralNormalization]
@[simp]
theorem integralNormalization_C {x : R} (hx : x ≠ 0) : integralNormalization (C x) = 1 := by
simp [integralNormalization, sum_def, support_C hx, degree_C hx]
variable {p : R[X]}
theorem integralNormalization_coeff {i : ℕ} :
(integralNormalization p).coeff i =
if p.degree = i then 1 else coeff p i * p.leadingCoeff ^ (p.natDegree - 1 - i) := by
have : p.coeff i = 0 → p.degree ≠ i := fun hc hd => coeff_ne_zero_of_eq_degree hd hc
simp +contextual [sum_def, integralNormalization, coeff_monomial, this,
mem_support_iff]
theorem support_integralNormalization_subset :
(integralNormalization p).support ⊆ p.support := by
intro
simp +contextual [sum_def, integralNormalization, coeff_monomial, mem_support_iff]
@[deprecated (since := "2024-11-30")]
alias integralNormalization_support := support_integralNormalization_subset
theorem integralNormalization_coeff_degree {i : ℕ} (hi : p.degree = i) :
(integralNormalization p).coeff i = 1 := by rw [integralNormalization_coeff, if_pos hi]
theorem integralNormalization_coeff_natDegree (hp : p ≠ 0) :
(integralNormalization p).coeff (natDegree p) = 1 :=
integralNormalization_coeff_degree (degree_eq_natDegree hp)
| Mathlib/RingTheory/Polynomial/IntegralNormalization.lean | 71 | 73 | theorem integralNormalization_coeff_degree_ne {i : ℕ} (hi : p.degree ≠ i) :
coeff (integralNormalization p) i = coeff p i * p.leadingCoeff ^ (p.natDegree - 1 - i) := by | rw [integralNormalization_coeff, if_neg hi] |
/-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.Algebra.Module.ZLattice.Basic
import Mathlib.Analysis.InnerProductSpace.ProdL2
import Mathlib.MeasureTheory.Measure.Haar.Unique
import Mathlib.NumberTheory.NumberField.FractionalIdeal
import Mathlib.NumberTheory.NumberField.Units.Basic
/-!
# Canonical embedding of a number field
The canonical embedding of a number field `K` of degree `n` is the ring homomorphism
`K →+* ℂ^n` that sends `x ∈ K` to `(φ_₁(x),...,φ_n(x))` where the `φ_i`'s are the complex
embeddings of `K`. Note that we do not choose an ordering of the embeddings, but instead map `K`
into the type `(K →+* ℂ) → ℂ` of `ℂ`-vectors indexed by the complex embeddings.
## Main definitions and results
* `NumberField.canonicalEmbedding`: the ring homomorphism `K →+* ((K →+* ℂ) → ℂ)` defined by
sending `x : K` to the vector `(φ x)` indexed by `φ : K →+* ℂ`.
* `NumberField.canonicalEmbedding.integerLattice.inter_ball_finite`: the intersection of the
image of the ring of integers by the canonical embedding and any ball centered at `0` of finite
radius is finite.
* `NumberField.mixedEmbedding`: the ring homomorphism from `K` to the mixed space
`K →+* ({ w // IsReal w } → ℝ) × ({ w // IsComplex w } → ℂ)` that sends `x ∈ K` to `(φ_w x)_w`
where `φ_w` is the embedding associated to the infinite place `w`. In particular, if `w` is real
then `φ_w : K →+* ℝ` and, if `w` is complex, `φ_w` is an arbitrary choice between the two complex
embeddings defining the place `w`.
## Tags
number field, infinite places
-/
variable (K : Type*) [Field K]
namespace NumberField.canonicalEmbedding
/-- The canonical embedding of a number field `K` of degree `n` into `ℂ^n`. -/
def _root_.NumberField.canonicalEmbedding : K →+* ((K →+* ℂ) → ℂ) := Pi.ringHom fun φ => φ
theorem _root_.NumberField.canonicalEmbedding_injective [NumberField K] :
Function.Injective (NumberField.canonicalEmbedding K) := RingHom.injective _
variable {K}
@[simp]
theorem apply_at (φ : K →+* ℂ) (x : K) : (NumberField.canonicalEmbedding K x) φ = φ x := rfl
open scoped ComplexConjugate
/-- The image of `canonicalEmbedding` lives in the `ℝ`-submodule of the `x ∈ ((K →+* ℂ) → ℂ)` such
that `conj x_φ = x_(conj φ)` for all `∀ φ : K →+* ℂ`. -/
theorem conj_apply {x : ((K →+* ℂ) → ℂ)} (φ : K →+* ℂ)
(hx : x ∈ Submodule.span ℝ (Set.range (canonicalEmbedding K))) :
conj (x φ) = x (ComplexEmbedding.conjugate φ) := by
refine Submodule.span_induction ?_ ?_ (fun _ _ _ _ hx hy => ?_) (fun a _ _ hx => ?_) hx
· rintro _ ⟨x, rfl⟩
rw [apply_at, apply_at, ComplexEmbedding.conjugate_coe_eq]
· rw [Pi.zero_apply, Pi.zero_apply, map_zero]
· rw [Pi.add_apply, Pi.add_apply, map_add, hx, hy]
· rw [Pi.smul_apply, Complex.real_smul, map_mul, Complex.conj_ofReal]
exact congrArg ((a : ℂ) * ·) hx
theorem nnnorm_eq [NumberField K] (x : K) :
‖canonicalEmbedding K x‖₊ = Finset.univ.sup (fun φ : K →+* ℂ => ‖φ x‖₊) := by
simp_rw [Pi.nnnorm_def, apply_at]
theorem norm_le_iff [NumberField K] (x : K) (r : ℝ) :
‖canonicalEmbedding K x‖ ≤ r ↔ ∀ φ : K →+* ℂ, ‖φ x‖ ≤ r := by
obtain hr | hr := lt_or_le r 0
· obtain ⟨φ⟩ := (inferInstance : Nonempty (K →+* ℂ))
refine iff_of_false ?_ ?_
· exact (hr.trans_le (norm_nonneg _)).not_le
· exact fun h => hr.not_le (le_trans (norm_nonneg _) (h φ))
· lift r to NNReal using hr
simp_rw [← coe_nnnorm, nnnorm_eq, NNReal.coe_le_coe, Finset.sup_le_iff, Finset.mem_univ,
forall_true_left]
variable (K)
/-- The image of `𝓞 K` as a subring of `ℂ^n`. -/
def integerLattice : Subring ((K →+* ℂ) → ℂ) :=
(RingHom.range (algebraMap (𝓞 K) K)).map (canonicalEmbedding K)
theorem integerLattice.inter_ball_finite [NumberField K] (r : ℝ) :
((integerLattice K : Set ((K →+* ℂ) → ℂ)) ∩ Metric.closedBall 0 r).Finite := by
obtain hr | _ := lt_or_le r 0
· simp [Metric.closedBall_eq_empty.2 hr]
· have heq : ∀ x, canonicalEmbedding K x ∈ Metric.closedBall 0 r ↔
∀ φ : K →+* ℂ, ‖φ x‖ ≤ r := by
intro x; rw [← norm_le_iff, mem_closedBall_zero_iff]
convert (Embeddings.finite_of_norm_le K ℂ r).image (canonicalEmbedding K)
ext; constructor
· rintro ⟨⟨_, ⟨x, rfl⟩, rfl⟩, hx⟩
exact ⟨x, ⟨SetLike.coe_mem x, fun φ => (heq _).mp hx φ⟩, rfl⟩
· rintro ⟨x, ⟨hx1, hx2⟩, rfl⟩
exact ⟨⟨x, ⟨⟨x, hx1⟩, rfl⟩, rfl⟩, (heq x).mpr hx2⟩
open Module Fintype Module
/-- A `ℂ`-basis of `ℂ^n` that is also a `ℤ`-basis of the `integerLattice`. -/
noncomputable def latticeBasis [NumberField K] :
Basis (Free.ChooseBasisIndex ℤ (𝓞 K)) ℂ ((K →+* ℂ) → ℂ) := by
classical
-- Let `B` be the canonical basis of `(K →+* ℂ) → ℂ`. We prove that the determinant of
-- the image by `canonicalEmbedding` of the integral basis of `K` is nonzero. This
-- will imply the result.
let B := Pi.basisFun ℂ (K →+* ℂ)
let e : (K →+* ℂ) ≃ Free.ChooseBasisIndex ℤ (𝓞 K) :=
equivOfCardEq ((Embeddings.card K ℂ).trans (finrank_eq_card_basis (integralBasis K)))
let M := B.toMatrix (fun i => canonicalEmbedding K (integralBasis K (e i)))
suffices M.det ≠ 0 by
rw [← isUnit_iff_ne_zero, ← Basis.det_apply, ← is_basis_iff_det] at this
exact (basisOfPiSpaceOfLinearIndependent this.1).reindex e
-- In order to prove that the determinant is nonzero, we show that it is equal to the
-- square of the discriminant of the integral basis and thus it is not zero
let N := Algebra.embeddingsMatrixReindex ℚ ℂ (fun i => integralBasis K (e i))
RingHom.equivRatAlgHom
rw [show M = N.transpose by { ext : 2; rfl }]
rw [Matrix.det_transpose, ← pow_ne_zero_iff two_ne_zero]
convert (map_ne_zero_iff _ (algebraMap ℚ ℂ).injective).mpr
(Algebra.discr_not_zero_of_basis ℚ (integralBasis K))
rw [← Algebra.discr_reindex ℚ (integralBasis K) e.symm]
exact (Algebra.discr_eq_det_embeddingsMatrixReindex_pow_two ℚ ℂ
(fun i => integralBasis K (e i)) RingHom.equivRatAlgHom).symm
@[simp]
theorem latticeBasis_apply [NumberField K] (i : Free.ChooseBasisIndex ℤ (𝓞 K)) :
latticeBasis K i = (canonicalEmbedding K) (integralBasis K i) := by
simp [latticeBasis, integralBasis_apply, coe_basisOfPiSpaceOfLinearIndependent,
Function.comp_apply, Equiv.apply_symm_apply]
| Mathlib/NumberTheory/NumberField/CanonicalEmbedding/Basic.lean | 139 | 142 | theorem mem_span_latticeBasis [NumberField K] {x : (K →+* ℂ) → ℂ} :
x ∈ Submodule.span ℤ (Set.range (latticeBasis K)) ↔
x ∈ ((canonicalEmbedding K).comp (algebraMap (𝓞 K) K)).range := by | rw [show Set.range (latticeBasis K) = |
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Ideal
/-!
# Ideal operations for Lie algebras
Given a Lie module `M` over a Lie algebra `L`, there is a natural action of the Lie ideals of `L`
on the Lie submodules of `M`. In the special case that `M = L` with the adjoint action, this
provides a pairing of Lie ideals which is especially important. For example, it can be used to
define solvability / nilpotency of a Lie algebra via the derived / lower-central series.
## Main definitions
* `LieSubmodule.hasBracket`
* `LieSubmodule.lieIdeal_oper_eq_linear_span`
* `LieIdeal.map_bracket_le`
* `LieIdeal.comap_bracket_le`
## Notation
Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M` and a Lie
ideal `I ⊆ L`, we introduce the notation `⁅I, N⁆` for the Lie submodule of `M` corresponding to
the action defined in this file.
## Tags
lie algebra, ideal operation
-/
universe u v w w₁ w₂
namespace LieSubmodule
variable {R : Type u} {L : Type v} {M : Type w} {M₂ : Type w₁}
variable [CommRing R] [LieRing L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M]
variable [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂]
variable (N N' : LieSubmodule R L M) (N₂ : LieSubmodule R L M₂)
variable (f : M →ₗ⁅R,L⁆ M₂)
section LieIdealOperations
theorem map_comap_le : map f (comap f N₂) ≤ N₂ :=
(N₂ : Set M₂).image_preimage_subset f
theorem map_comap_eq (hf : N₂ ≤ f.range) : map f (comap f N₂) = N₂ := by
rw [SetLike.ext'_iff]
exact Set.image_preimage_eq_of_subset hf
theorem le_comap_map : N ≤ comap f (map f N) :=
(N : Set M).subset_preimage_image f
theorem comap_map_eq (hf : f.ker = ⊥) : comap f (map f N) = N := by
rw [SetLike.ext'_iff]
exact (N : Set M).preimage_image_eq (f.ker_eq_bot.mp hf)
@[simp]
theorem map_comap_incl : map N.incl (comap N.incl N') = N ⊓ N' := by
rw [← toSubmodule_inj]
exact (N : Submodule R M).map_comap_subtype N'
variable [LieAlgebra R L] [LieModule R L M₂] (I J : LieIdeal R L)
/-- Given a Lie module `M` over a Lie algebra `L`, the set of Lie ideals of `L` acts on the set
of submodules of `M`. -/
instance hasBracket : Bracket (LieIdeal R L) (LieSubmodule R L M) :=
⟨fun I N => lieSpan R L { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) }⟩
theorem lieIdeal_oper_eq_span :
⁅I, N⁆ = lieSpan R L { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) } :=
rfl
/-- See also `LieSubmodule.lieIdeal_oper_eq_linear_span'` and
`LieSubmodule.lieIdeal_oper_eq_tensor_map_range`. -/
theorem lieIdeal_oper_eq_linear_span [LieModule R L M] :
(↑⁅I, N⁆ : Submodule R M) = Submodule.span R { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) } := by
apply le_antisymm
· let s := { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) }
have aux : ∀ (y : L), ∀ m' ∈ Submodule.span R s, ⁅y, m'⁆ ∈ Submodule.span R s := by
intro y m' hm'
refine Submodule.span_induction (R := R) (M := M) (s := s)
(p := fun m' _ ↦ ⁅y, m'⁆ ∈ Submodule.span R s) ?_ ?_ ?_ ?_ hm'
· rintro m'' ⟨x, n, hm''⟩; rw [← hm'', leibniz_lie]
refine Submodule.add_mem _ ?_ ?_ <;> apply Submodule.subset_span
· use ⟨⁅y, ↑x⁆, I.lie_mem x.property⟩, n
· use x, ⟨⁅y, ↑n⁆, N.lie_mem n.property⟩
· simp only [lie_zero, Submodule.zero_mem]
· intro m₁ m₂ _ _ hm₁ hm₂; rw [lie_add]; exact Submodule.add_mem _ hm₁ hm₂
· intro t m'' _ hm''; rw [lie_smul]; exact Submodule.smul_mem _ t hm''
change _ ≤ ({ Submodule.span R s with lie_mem := fun hm' => aux _ _ hm' } : LieSubmodule R L M)
rw [lieIdeal_oper_eq_span, lieSpan_le]
exact Submodule.subset_span
· rw [lieIdeal_oper_eq_span]; apply submodule_span_le_lieSpan
theorem lieIdeal_oper_eq_linear_span' [LieModule R L M] :
(↑⁅I, N⁆ : Submodule R M) = Submodule.span R { ⁅x, n⁆ | (x ∈ I) (n ∈ N) } := by
rw [lieIdeal_oper_eq_linear_span]
congr
ext m
constructor
· rintro ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩
exact ⟨x, hx, n, hn, rfl⟩
· rintro ⟨x, hx, n, hn, rfl⟩
exact ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩
| Mathlib/Algebra/Lie/IdealOperations.lean | 111 | 116 | theorem lie_le_iff : ⁅I, N⁆ ≤ N' ↔ ∀ x ∈ I, ∀ m ∈ N, ⁅x, m⁆ ∈ N' := by | rw [lieIdeal_oper_eq_span, LieSubmodule.lieSpan_le]
refine ⟨fun h x hx m hm => h ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩, ?_⟩
rintro h _ ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩
exact h x hx m hm |
/-
Copyright (c) 2022 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Idempotents.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.CategoryTheory.Equivalence
/-!
# The Karoubi envelope of a category
In this file, we define the Karoubi envelope `Karoubi C` of a category `C`.
## Main constructions and definitions
- `Karoubi C` is the Karoubi envelope of a category `C`: it is an idempotent
complete category. It is also preadditive when `C` is preadditive.
- `toKaroubi C : C ⥤ Karoubi C` is a fully faithful functor, which is an equivalence
(`toKaroubiIsEquivalence`) when `C` is idempotent complete.
-/
noncomputable section
open CategoryTheory.Category CategoryTheory.Preadditive CategoryTheory.Limits
namespace CategoryTheory
variable (C : Type*) [Category C]
namespace Idempotents
/-- In a preadditive category `C`, when an object `X` decomposes as `X ≅ P ⨿ Q`, one may
consider `P` as a direct factor of `X` and up to unique isomorphism, it is determined by the
obvious idempotent `X ⟶ P ⟶ X` which is the projection onto `P` with kernel `Q`. More generally,
one may define a formal direct factor of an object `X : C` : it consists of an idempotent
`p : X ⟶ X` which is thought as the "formal image" of `p`. The type `Karoubi C` shall be the
type of the objects of the karoubi envelope of `C`. It makes sense for any category `C`. -/
structure Karoubi where
/-- an object of the underlying category -/
X : C
/-- an endomorphism of the object -/
p : X ⟶ X
/-- the condition that the given endomorphism is an idempotent -/
idem : p ≫ p = p := by aesop_cat
namespace Karoubi
variable {C}
attribute [reassoc (attr := simp)] idem
@[ext (iff := false)]
theorem ext {P Q : Karoubi C} (h_X : P.X = Q.X) (h_p : P.p ≫ eqToHom h_X = eqToHom h_X ≫ Q.p) :
P = Q := by
cases P
cases Q
dsimp at h_X h_p
subst h_X
simpa only [mk.injEq, heq_eq_eq, true_and, eqToHom_refl, comp_id, id_comp] using h_p
/-- A morphism `P ⟶ Q` in the category `Karoubi C` is a morphism in the underlying category
`C` which satisfies a relation, which in the preadditive case, expresses that it induces a
map between the corresponding "formal direct factors" and that it vanishes on the complement
formal direct factor. -/
@[ext]
structure Hom (P Q : Karoubi C) where
/-- a morphism between the underlying objects -/
f : P.X ⟶ Q.X
/-- compatibility of the given morphism with the given idempotents -/
comm : f = P.p ≫ f ≫ Q.p := by aesop_cat
instance [Preadditive C] (P Q : Karoubi C) : Inhabited (Hom P Q) :=
⟨⟨0, by rw [zero_comp, comp_zero]⟩⟩
@[reassoc (attr := simp)]
theorem p_comp {P Q : Karoubi C} (f : Hom P Q) : P.p ≫ f.f = f.f := by rw [f.comm, ← assoc, P.idem]
@[reassoc (attr := simp)]
theorem comp_p {P Q : Karoubi C} (f : Hom P Q) : f.f ≫ Q.p = f.f := by
rw [f.comm, assoc, assoc, Q.idem]
@[reassoc]
theorem p_comm {P Q : Karoubi C} (f : Hom P Q) : P.p ≫ f.f = f.f ≫ Q.p := by rw [p_comp, comp_p]
theorem comp_proof {P Q R : Karoubi C} (g : Hom Q R) (f : Hom P Q) :
f.f ≫ g.f = P.p ≫ (f.f ≫ g.f) ≫ R.p := by rw [assoc, comp_p, ← assoc, p_comp]
/-- The category structure on the karoubi envelope of a category. -/
instance : Category (Karoubi C) where
Hom := Karoubi.Hom
id P := ⟨P.p, by repeat' rw [P.idem]⟩
comp f g := ⟨f.f ≫ g.f, Karoubi.comp_proof g f⟩
@[simp]
| Mathlib/CategoryTheory/Idempotents/Karoubi.lean | 97 | 98 | theorem hom_ext_iff {P Q : Karoubi C} {f g : P ⟶ Q} : f = g ↔ f.f = g.f := by | constructor |
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Data.Set.Prod
/-!
# N-ary images of sets
This file defines `Set.image2`, the binary image of sets.
This is mostly useful to define pointwise operations and `Set.seq`.
## Notes
This file is very similar to `Data.Finset.NAry`, to `Order.Filter.NAry`, and to
`Data.Option.NAry`. Please keep them in sync.
-/
open Function
namespace Set
variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*} {f f' : α → β → γ}
variable {s s' : Set α} {t t' : Set β} {u : Set γ} {v : Set δ} {a : α} {b : β}
theorem mem_image2_iff (hf : Injective2 f) : f a b ∈ image2 f s t ↔ a ∈ s ∧ b ∈ t :=
⟨by
rintro ⟨a', ha', b', hb', h⟩
rcases hf h with ⟨rfl, rfl⟩
exact ⟨ha', hb'⟩, fun ⟨ha, hb⟩ => mem_image2_of_mem ha hb⟩
/-- image2 is monotone with respect to `⊆`. -/
@[gcongr]
theorem image2_subset (hs : s ⊆ s') (ht : t ⊆ t') : image2 f s t ⊆ image2 f s' t' := by
rintro _ ⟨a, ha, b, hb, rfl⟩
exact mem_image2_of_mem (hs ha) (ht hb)
@[gcongr]
theorem image2_subset_left (ht : t ⊆ t') : image2 f s t ⊆ image2 f s t' :=
image2_subset Subset.rfl ht
@[gcongr]
theorem image2_subset_right (hs : s ⊆ s') : image2 f s t ⊆ image2 f s' t :=
image2_subset hs Subset.rfl
theorem image_subset_image2_left (hb : b ∈ t) : (fun a => f a b) '' s ⊆ image2 f s t :=
forall_mem_image.2 fun _ ha => mem_image2_of_mem ha hb
theorem image_subset_image2_right (ha : a ∈ s) : f a '' t ⊆ image2 f s t :=
forall_mem_image.2 fun _ => mem_image2_of_mem ha
lemma forall_mem_image2 {p : γ → Prop} :
(∀ z ∈ image2 f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by aesop
lemma exists_mem_image2 {p : γ → Prop} :
(∃ z ∈ image2 f s t, p z) ↔ ∃ x ∈ s, ∃ y ∈ t, p (f x y) := by aesop
@[deprecated (since := "2024-11-23")] alias forall_image2_iff := forall_mem_image2
@[simp]
theorem image2_subset_iff {u : Set γ} : image2 f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u :=
forall_mem_image2
theorem image2_subset_iff_left : image2 f s t ⊆ u ↔ ∀ a ∈ s, (fun b => f a b) '' t ⊆ u := by
simp_rw [image2_subset_iff, image_subset_iff, subset_def, mem_preimage]
theorem image2_subset_iff_right : image2 f s t ⊆ u ↔ ∀ b ∈ t, (fun a => f a b) '' s ⊆ u := by
simp_rw [image2_subset_iff, image_subset_iff, subset_def, mem_preimage, @forall₂_swap α]
variable (f)
@[simp]
lemma image_prod : (fun x : α × β ↦ f x.1 x.2) '' s ×ˢ t = image2 f s t :=
ext fun _ ↦ by simp [and_assoc]
@[simp] lemma image_uncurry_prod (s : Set α) (t : Set β) : uncurry f '' s ×ˢ t = image2 f s t :=
image_prod _
@[simp] lemma image2_mk_eq_prod : image2 Prod.mk s t = s ×ˢ t := ext <| by simp
@[simp]
lemma image2_curry (f : α × β → γ) (s : Set α) (t : Set β) :
image2 (fun a b ↦ f (a, b)) s t = f '' s ×ˢ t := by
simp [← image_uncurry_prod, uncurry]
theorem image2_swap (s : Set α) (t : Set β) : image2 f s t = image2 (fun a b => f b a) t s := by
ext
constructor <;> rintro ⟨a, ha, b, hb, rfl⟩ <;> exact ⟨b, hb, a, ha, rfl⟩
variable {f}
theorem image2_union_left : image2 f (s ∪ s') t = image2 f s t ∪ image2 f s' t := by
simp_rw [← image_prod, union_prod, image_union]
theorem image2_union_right : image2 f s (t ∪ t') = image2 f s t ∪ image2 f s t' := by
rw [← image2_swap, image2_union_left, image2_swap f, image2_swap f]
lemma image2_inter_left (hf : Injective2 f) :
image2 f (s ∩ s') t = image2 f s t ∩ image2 f s' t := by
simp_rw [← image_uncurry_prod, inter_prod, image_inter hf.uncurry]
lemma image2_inter_right (hf : Injective2 f) :
image2 f s (t ∩ t') = image2 f s t ∩ image2 f s t' := by
simp_rw [← image_uncurry_prod, prod_inter, image_inter hf.uncurry]
@[simp]
theorem image2_empty_left : image2 f ∅ t = ∅ :=
ext <| by simp
@[simp]
theorem image2_empty_right : image2 f s ∅ = ∅ :=
ext <| by simp
theorem Nonempty.image2 : s.Nonempty → t.Nonempty → (image2 f s t).Nonempty :=
fun ⟨_, ha⟩ ⟨_, hb⟩ => ⟨_, mem_image2_of_mem ha hb⟩
@[simp]
theorem image2_nonempty_iff : (image2 f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
⟨fun ⟨_, a, ha, b, hb, _⟩ => ⟨⟨a, ha⟩, b, hb⟩, fun h => h.1.image2 h.2⟩
theorem Nonempty.of_image2_left (h : (Set.image2 f s t).Nonempty) : s.Nonempty :=
(image2_nonempty_iff.1 h).1
theorem Nonempty.of_image2_right (h : (Set.image2 f s t).Nonempty) : t.Nonempty :=
(image2_nonempty_iff.1 h).2
@[simp]
theorem image2_eq_empty_iff : image2 f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by
rw [← not_nonempty_iff_eq_empty, image2_nonempty_iff, not_and_or]
simp [not_nonempty_iff_eq_empty]
theorem Subsingleton.image2 (hs : s.Subsingleton) (ht : t.Subsingleton) (f : α → β → γ) :
(image2 f s t).Subsingleton := by
rw [← image_prod]
apply (hs.prod ht).image
theorem image2_inter_subset_left : image2 f (s ∩ s') t ⊆ image2 f s t ∩ image2 f s' t :=
Monotone.map_inf_le (fun _ _ ↦ image2_subset_right) s s'
theorem image2_inter_subset_right : image2 f s (t ∩ t') ⊆ image2 f s t ∩ image2 f s t' :=
Monotone.map_inf_le (fun _ _ ↦ image2_subset_left) t t'
@[simp]
theorem image2_singleton_left : image2 f {a} t = f a '' t :=
ext fun x => by simp
@[simp]
theorem image2_singleton_right : image2 f s {b} = (fun a => f a b) '' s :=
ext fun x => by simp
theorem image2_singleton : image2 f {a} {b} = {f a b} := by simp
@[simp]
| Mathlib/Data/Set/NAry.lean | 154 | 157 | theorem image2_insert_left : image2 f (insert a s) t = (fun b => f a b) '' t ∪ image2 f s t := by | rw [insert_eq, image2_union_left, image2_singleton_left]
@[simp] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.