Context stringlengths 227 76.5k | target stringlengths 0 11.6k | file_name stringlengths 21 79 | start int64 14 3.67k | end int64 16 3.69k |
|---|---|---|---|---|
/-
Copyright (c) 2015 Nathaniel Thomas. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.GroupWithZero.Action.Defs
import Mathlib.Algebra.Ring.Defs
/-!
# Modules over a ring
In this file we define
* `Module R M` : an additive commutative monoid `M` is a `Module` over a
`Semiring R` if for `r : R` and `x : M` their "scalar multiplication" `r • x : M` is defined, and
the operation `•` satisfies some natural associativity and distributivity axioms similar to those
on a ring.
## Implementation notes
In typical mathematical usage, our definition of `Module` corresponds to "semimodule", and the
word "module" is reserved for `Module R M` where `R` is a `Ring` and `M` an `AddCommGroup`.
If `R` is a `Field` and `M` an `AddCommGroup`, `M` would be called an `R`-vector space.
Since those assumptions can be made by changing the typeclasses applied to `R` and `M`,
without changing the axioms in `Module`, mathlib calls everything a `Module`.
In older versions of mathlib3, we had separate abbreviations for semimodules and vector spaces.
This caused inference issues in some cases, while not providing any real advantages, so we decided
to use a canonical `Module` typeclass throughout.
## Tags
semimodule, module, vector space
-/
assert_not_exists Field Invertible Pi.single_smul₀ RingHom Set.indicator Multiset Units
open Function Set
universe u v
variable {R S M M₂ : Type*}
/-- A module is a generalization of vector spaces to a scalar semiring.
It consists of a scalar semiring `R` and an additive monoid of "vectors" `M`,
connected by a "scalar multiplication" operation `r • x : M`
(where `r : R` and `x : M`) with some natural associativity and
distributivity axioms similar to those on a ring. -/
@[ext]
class Module (R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] extends
DistribMulAction R M where
/-- Scalar multiplication distributes over addition from the right. -/
protected add_smul : ∀ (r s : R) (x : M), (r + s) • x = r • x + s • x
/-- Scalar multiplication by zero gives zero. -/
protected zero_smul : ∀ x : M, (0 : R) • x = 0
section AddCommMonoid
variable [Semiring R] [AddCommMonoid M] [Module R M] (r s : R) (x : M)
-- see Note [lower instance priority]
/-- A module over a semiring automatically inherits a `MulActionWithZero` structure. -/
instance (priority := 100) Module.toMulActionWithZero
{R M} {_ : Semiring R} {_ : AddCommMonoid M} [Module R M] : MulActionWithZero R M :=
{ (inferInstance : MulAction R M) with
smul_zero := smul_zero
zero_smul := Module.zero_smul }
theorem add_smul : (r + s) • x = r • x + s • x :=
Module.add_smul r s x
theorem Convex.combo_self {a b : R} (h : a + b = 1) (x : M) : a • x + b • x = x := by
rw [← add_smul, h, one_smul]
variable (R)
theorem two_smul : (2 : R) • x = x + x := by rw [← one_add_one_eq_two, add_smul, one_smul]
/-- Pullback a `Module` structure along an injective additive monoid homomorphism.
See note [reducible non-instances]. -/
protected abbrev Function.Injective.module [AddCommMonoid M₂] [SMul R M₂] (f : M₂ →+ M)
(hf : Injective f) (smul : ∀ (c : R) (x), f (c • x) = c • f x) : Module R M₂ :=
{ hf.distribMulAction f smul with
add_smul := fun c₁ c₂ x => hf <| by simp only [smul, f.map_add, add_smul]
zero_smul := fun x => hf <| by simp only [smul, zero_smul, f.map_zero] }
/-- Pushforward a `Module` structure along a surjective additive monoid homomorphism.
See note [reducible non-instances]. -/
protected abbrev Function.Surjective.module [AddCommMonoid M₂] [SMul R M₂] (f : M →+ M₂)
(hf : Surjective f) (smul : ∀ (c : R) (x), f (c • x) = c • f x) : Module R M₂ :=
{ toDistribMulAction := hf.distribMulAction f smul
add_smul := fun c₁ c₂ x => by
rcases hf x with ⟨x, rfl⟩
simp only [add_smul, ← smul, ← f.map_add]
zero_smul := fun x => by
rcases hf x with ⟨x, rfl⟩
rw [← f.map_zero, ← smul, zero_smul] }
variable {R}
theorem Module.eq_zero_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : x = 0 := by
rw [← one_smul R x, ← zero_eq_one, zero_smul]
@[simp]
theorem smul_add_one_sub_smul {R : Type*} [Ring R] [Module R M] {r : R} {m : M} :
r • m + (1 - r) • m = m := by rw [← add_smul, add_sub_cancel, one_smul]
end AddCommMonoid
section AddCommGroup
variable [Semiring R] [AddCommGroup M]
theorem Convex.combo_eq_smul_sub_add [Module R M] {x y : M} {a b : R} (h : a + b = 1) :
a • x + b • y = b • (y - x) + x :=
calc
a • x + b • y = b • y - b • x + (a • x + b • x) := by rw [sub_add_add_cancel, add_comm]
_ = b • (y - x) + x := by rw [smul_sub, Convex.combo_self h]
end AddCommGroup
-- We'll later use this to show `Module ℕ M` and `Module ℤ M` are subsingletons.
/-- A variant of `Module.ext` that's convenient for term-mode. -/
theorem Module.ext' {R : Type*} [Semiring R] {M : Type*} [AddCommMonoid M] (P Q : Module R M)
(w : ∀ (r : R) (m : M), (haveI := P; r • m) = (haveI := Q; r • m)) :
P = Q := by
ext
exact w _ _
section Module
variable [Ring R] [AddCommGroup M] [Module R M] (r : R) (x : M)
@[simp]
theorem neg_smul : -r • x = -(r • x) :=
eq_neg_of_add_eq_zero_left <| by rw [← add_smul, neg_add_cancel, zero_smul]
theorem neg_smul_neg : -r • -x = r • x := by rw [neg_smul, smul_neg, neg_neg]
variable (R)
theorem neg_one_smul (x : M) : (-1 : R) • x = -x := by simp
variable {R}
theorem sub_smul (r s : R) (y : M) : (r - s) • y = r • y - s • y := by
simp [add_smul, sub_eq_add_neg]
end Module
/-- A module over a `Subsingleton` semiring is a `Subsingleton`. We cannot register this
as an instance because Lean has no way to guess `R`. -/
protected theorem Module.subsingleton (R M : Type*) [MonoidWithZero R] [Subsingleton R] [Zero M]
[MulActionWithZero R M] : Subsingleton M :=
MulActionWithZero.subsingleton R M
/-- A semiring is `Nontrivial` provided that there exists a nontrivial module over this semiring. -/
protected theorem Module.nontrivial (R M : Type*) [MonoidWithZero R] [Nontrivial M] [Zero M]
[MulActionWithZero R M] : Nontrivial R :=
MulActionWithZero.nontrivial R M
-- see Note [lower instance priority]
instance (priority := 910) Semiring.toModule [Semiring R] : Module R R where
smul_add := mul_add
add_smul := add_mul
zero_smul := zero_mul
smul_zero := mul_zero
instance [NonUnitalNonAssocSemiring R] : DistribSMul R R where
smul_add := left_distrib
| Mathlib/Algebra/Module/Defs.lean | 274 | 275 | |
/-
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, Patrick Massot
-/
import Mathlib.Algebra.Group.TypeTags.Basic
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Finset.Piecewise
import Mathlib.Order.Filter.Cofinite
import Mathlib.Order.Filter.Curry
import Mathlib.Topology.Constructions.SumProd
import Mathlib.Topology.NhdsSet
/-!
# Constructions of new topological spaces from old ones
This file constructs pi types, subtypes and quotients of topological spaces
and sets up their basic theory, such as criteria for maps into or out of these
constructions to be continuous; descriptions of the open sets, neighborhood filters,
and generators of these constructions; and their behavior with respect to embeddings
and other specific classes of maps.
## Implementation note
The constructed topologies are defined using induced and coinduced topologies
along with the complete lattice structure on topologies. Their universal properties
(for example, a map `X → Y × Z` is continuous if and only if both projections
`X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of
continuity. With more work we can also extract descriptions of the open sets,
neighborhood filters and so on.
## Tags
product, subspace, quotient space
-/
noncomputable section
open Topology TopologicalSpace Set Filter Function
open scoped Set.Notation
universe u v u' v'
variable {X : Type u} {Y : Type v} {Z W ε ζ : Type*}
section Constructions
instance {r : X → X → Prop} [t : TopologicalSpace X] : TopologicalSpace (Quot r) :=
coinduced (Quot.mk r) t
instance instTopologicalSpaceQuotient {s : Setoid X} [t : TopologicalSpace X] :
TopologicalSpace (Quotient s) :=
coinduced Quotient.mk' t
instance instTopologicalSpaceSigma {ι : Type*} {X : ι → Type v} [t₂ : ∀ i, TopologicalSpace (X i)] :
TopologicalSpace (Sigma X) :=
⨆ i, coinduced (Sigma.mk i) (t₂ i)
instance Pi.topologicalSpace {ι : Type*} {Y : ι → Type v} [t₂ : (i : ι) → TopologicalSpace (Y i)] :
TopologicalSpace ((i : ι) → Y i) :=
⨅ i, induced (fun f => f i) (t₂ i)
instance ULift.topologicalSpace [t : TopologicalSpace X] : TopologicalSpace (ULift.{v, u} X) :=
t.induced ULift.down
/-!
### `Additive`, `Multiplicative`
The topology on those type synonyms is inherited without change.
-/
section
variable [TopologicalSpace X]
open Additive Multiplicative
instance : TopologicalSpace (Additive X) := ‹TopologicalSpace X›
instance : TopologicalSpace (Multiplicative X) := ‹TopologicalSpace X›
instance [DiscreteTopology X] : DiscreteTopology (Additive X) := ‹DiscreteTopology X›
instance [DiscreteTopology X] : DiscreteTopology (Multiplicative X) := ‹DiscreteTopology X›
theorem continuous_ofMul : Continuous (ofMul : X → Additive X) := continuous_id
theorem continuous_toMul : Continuous (toMul : Additive X → X) := continuous_id
theorem continuous_ofAdd : Continuous (ofAdd : X → Multiplicative X) := continuous_id
theorem continuous_toAdd : Continuous (toAdd : Multiplicative X → X) := continuous_id
theorem isOpenMap_ofMul : IsOpenMap (ofMul : X → Additive X) := IsOpenMap.id
theorem isOpenMap_toMul : IsOpenMap (toMul : Additive X → X) := IsOpenMap.id
theorem isOpenMap_ofAdd : IsOpenMap (ofAdd : X → Multiplicative X) := IsOpenMap.id
theorem isOpenMap_toAdd : IsOpenMap (toAdd : Multiplicative X → X) := IsOpenMap.id
theorem isClosedMap_ofMul : IsClosedMap (ofMul : X → Additive X) := IsClosedMap.id
theorem isClosedMap_toMul : IsClosedMap (toMul : Additive X → X) := IsClosedMap.id
theorem isClosedMap_ofAdd : IsClosedMap (ofAdd : X → Multiplicative X) := IsClosedMap.id
theorem isClosedMap_toAdd : IsClosedMap (toAdd : Multiplicative X → X) := IsClosedMap.id
theorem nhds_ofMul (x : X) : 𝓝 (ofMul x) = map ofMul (𝓝 x) := rfl
theorem nhds_ofAdd (x : X) : 𝓝 (ofAdd x) = map ofAdd (𝓝 x) := rfl
theorem nhds_toMul (x : Additive X) : 𝓝 x.toMul = map toMul (𝓝 x) := rfl
theorem nhds_toAdd (x : Multiplicative X) : 𝓝 x.toAdd = map toAdd (𝓝 x) := rfl
end
/-!
### Order dual
The topology on this type synonym is inherited without change.
-/
section
variable [TopologicalSpace X]
open OrderDual
instance OrderDual.instTopologicalSpace : TopologicalSpace Xᵒᵈ := ‹_›
instance OrderDual.instDiscreteTopology [DiscreteTopology X] : DiscreteTopology Xᵒᵈ := ‹_›
theorem continuous_toDual : Continuous (toDual : X → Xᵒᵈ) := continuous_id
theorem continuous_ofDual : Continuous (ofDual : Xᵒᵈ → X) := continuous_id
theorem isOpenMap_toDual : IsOpenMap (toDual : X → Xᵒᵈ) := IsOpenMap.id
theorem isOpenMap_ofDual : IsOpenMap (ofDual : Xᵒᵈ → X) := IsOpenMap.id
theorem isClosedMap_toDual : IsClosedMap (toDual : X → Xᵒᵈ) := IsClosedMap.id
theorem isClosedMap_ofDual : IsClosedMap (ofDual : Xᵒᵈ → X) := IsClosedMap.id
theorem nhds_toDual (x : X) : 𝓝 (toDual x) = map toDual (𝓝 x) := rfl
theorem nhds_ofDual (x : X) : 𝓝 (ofDual x) = map ofDual (𝓝 x) := rfl
variable [Preorder X] {x : X}
instance OrderDual.instNeBotNhdsWithinIoi [(𝓝[<] x).NeBot] : (𝓝[>] toDual x).NeBot := ‹_›
instance OrderDual.instNeBotNhdsWithinIio [(𝓝[>] x).NeBot] : (𝓝[<] toDual x).NeBot := ‹_›
end
theorem Quotient.preimage_mem_nhds [TopologicalSpace X] [s : Setoid X] {V : Set <| Quotient s}
{x : X} (hs : V ∈ 𝓝 (Quotient.mk' x)) : Quotient.mk' ⁻¹' V ∈ 𝓝 x :=
preimage_nhds_coinduced hs
/-- The image of a dense set under `Quotient.mk'` is a dense set. -/
theorem Dense.quotient [Setoid X] [TopologicalSpace X] {s : Set X} (H : Dense s) :
Dense (Quotient.mk' '' s) :=
Quotient.mk''_surjective.denseRange.dense_image continuous_coinduced_rng H
/-- The composition of `Quotient.mk'` and a function with dense range has dense range. -/
theorem DenseRange.quotient [Setoid X] [TopologicalSpace X] {f : Y → X} (hf : DenseRange f) :
DenseRange (Quotient.mk' ∘ f) :=
Quotient.mk''_surjective.denseRange.comp hf continuous_coinduced_rng
theorem continuous_map_of_le {α : Type*} [TopologicalSpace α]
{s t : Setoid α} (h : s ≤ t) : Continuous (Setoid.map_of_le h) :=
continuous_coinduced_rng
theorem continuous_map_sInf {α : Type*} [TopologicalSpace α]
{S : Set (Setoid α)} {s : Setoid α} (h : s ∈ S) : Continuous (Setoid.map_sInf h) :=
continuous_coinduced_rng
instance {p : X → Prop} [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (Subtype p) :=
⟨bot_unique fun s _ => ⟨(↑) '' s, isOpen_discrete _, preimage_image_eq _ Subtype.val_injective⟩⟩
instance Sum.discreteTopology [TopologicalSpace X] [TopologicalSpace Y] [h : DiscreteTopology X]
[hY : DiscreteTopology Y] : DiscreteTopology (X ⊕ Y) :=
⟨sup_eq_bot_iff.2 <| by simp [h.eq_bot, hY.eq_bot]⟩
instance Sigma.discreteTopology {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)]
[h : ∀ i, DiscreteTopology (Y i)] : DiscreteTopology (Sigma Y) :=
⟨iSup_eq_bot.2 fun _ => by simp only [(h _).eq_bot, coinduced_bot]⟩
@[simp] lemma comap_nhdsWithin_range {α β} [TopologicalSpace β] (f : α → β) (y : β) :
comap f (𝓝[range f] y) = comap f (𝓝 y) := comap_inf_principal_range
section Top
variable [TopologicalSpace X]
/-
The 𝓝 filter and the subspace topology.
-/
theorem mem_nhds_subtype (s : Set X) (x : { x // x ∈ s }) (t : Set { x // x ∈ s }) :
t ∈ 𝓝 x ↔ ∃ u ∈ 𝓝 (x : X), Subtype.val ⁻¹' u ⊆ t :=
mem_nhds_induced _ x t
theorem nhds_subtype (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝 (x : X)) :=
nhds_induced _ x
lemma nhds_subtype_eq_comap_nhdsWithin (s : Set X) (x : { x // x ∈ s }) :
𝓝 x = comap (↑) (𝓝[s] (x : X)) := by
rw [nhds_subtype, ← comap_nhdsWithin_range, Subtype.range_val]
theorem nhdsWithin_subtype_eq_bot_iff {s t : Set X} {x : s} :
𝓝[((↑) : s → X) ⁻¹' t] x = ⊥ ↔ 𝓝[t] (x : X) ⊓ 𝓟 s = ⊥ := by
rw [inf_principal_eq_bot_iff_comap, nhdsWithin, nhdsWithin, comap_inf, comap_principal,
nhds_induced]
theorem nhds_ne_subtype_eq_bot_iff {S : Set X} {x : S} :
𝓝[≠] x = ⊥ ↔ 𝓝[≠] (x : X) ⊓ 𝓟 S = ⊥ := by
rw [← nhdsWithin_subtype_eq_bot_iff, preimage_compl, ← image_singleton,
Subtype.coe_injective.preimage_image]
theorem nhds_ne_subtype_neBot_iff {S : Set X} {x : S} :
(𝓝[≠] x).NeBot ↔ (𝓝[≠] (x : X) ⊓ 𝓟 S).NeBot := by
rw [neBot_iff, neBot_iff, not_iff_not, nhds_ne_subtype_eq_bot_iff]
theorem discreteTopology_subtype_iff {S : Set X} :
DiscreteTopology S ↔ ∀ x ∈ S, 𝓝[≠] x ⊓ 𝓟 S = ⊥ := by
simp_rw [discreteTopology_iff_nhds_ne, SetCoe.forall', nhds_ne_subtype_eq_bot_iff]
end Top
/-- A type synonym equipped with the topology whose open sets are the empty set and the sets with
finite complements. -/
def CofiniteTopology (X : Type*) := X
namespace CofiniteTopology
/-- The identity equivalence between `` and `CofiniteTopology `. -/
def of : X ≃ CofiniteTopology X :=
Equiv.refl X
instance [Inhabited X] : Inhabited (CofiniteTopology X) where default := of default
instance : TopologicalSpace (CofiniteTopology X) where
IsOpen s := s.Nonempty → Set.Finite sᶜ
isOpen_univ := by simp
isOpen_inter s t := by
rintro hs ht ⟨x, hxs, hxt⟩
rw [compl_inter]
exact (hs ⟨x, hxs⟩).union (ht ⟨x, hxt⟩)
isOpen_sUnion := by
rintro s h ⟨x, t, hts, hzt⟩
rw [compl_sUnion]
exact Finite.sInter (mem_image_of_mem _ hts) (h t hts ⟨x, hzt⟩)
theorem isOpen_iff {s : Set (CofiniteTopology X)} : IsOpen s ↔ s.Nonempty → sᶜ.Finite :=
Iff.rfl
theorem isOpen_iff' {s : Set (CofiniteTopology X)} : IsOpen s ↔ s = ∅ ∨ sᶜ.Finite := by
simp only [isOpen_iff, nonempty_iff_ne_empty, or_iff_not_imp_left]
theorem isClosed_iff {s : Set (CofiniteTopology X)} : IsClosed s ↔ s = univ ∨ s.Finite := by
simp only [← isOpen_compl_iff, isOpen_iff', compl_compl, compl_empty_iff]
theorem nhds_eq (x : CofiniteTopology X) : 𝓝 x = pure x ⊔ cofinite := by
ext U
rw [mem_nhds_iff]
constructor
· rintro ⟨V, hVU, V_op, haV⟩
exact mem_sup.mpr ⟨hVU haV, mem_of_superset (V_op ⟨_, haV⟩) hVU⟩
· rintro ⟨hU : x ∈ U, hU' : Uᶜ.Finite⟩
exact ⟨U, Subset.rfl, fun _ => hU', hU⟩
theorem mem_nhds_iff {x : CofiniteTopology X} {s : Set (CofiniteTopology X)} :
s ∈ 𝓝 x ↔ x ∈ s ∧ sᶜ.Finite := by simp [nhds_eq]
end CofiniteTopology
end Constructions
section Prod
variable [TopologicalSpace X] [TopologicalSpace Y]
theorem MapClusterPt.curry_prodMap {α β : Type*}
{f : α → X} {g : β → Y} {la : Filter α} {lb : Filter β} {x : X} {y : Y}
(hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) :
MapClusterPt (x, y) (la.curry lb) (.map f g) := by
rw [mapClusterPt_iff_frequently] at hf hg
rw [((𝓝 x).basis_sets.prod_nhds (𝓝 y).basis_sets).mapClusterPt_iff_frequently]
rintro ⟨s, t⟩ ⟨hs, ht⟩
rw [frequently_curry_iff]
exact (hf s hs).mono fun x hx ↦ (hg t ht).mono fun y hy ↦ ⟨hx, hy⟩
theorem MapClusterPt.prodMap {α β : Type*}
{f : α → X} {g : β → Y} {la : Filter α} {lb : Filter β} {x : X} {y : Y}
(hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) :
MapClusterPt (x, y) (la ×ˢ lb) (.map f g) :=
(hf.curry_prodMap hg).mono <| map_mono curry_le_prod
end Prod
section Bool
lemma continuous_bool_rng [TopologicalSpace X] {f : X → Bool} (b : Bool) :
Continuous f ↔ IsClopen (f ⁻¹' {b}) := by
rw [continuous_discrete_rng, Bool.forall_bool' b, IsClopen, ← isOpen_compl_iff, ← preimage_compl,
Bool.compl_singleton, and_comm]
end Bool
section Subtype
variable [TopologicalSpace X] [TopologicalSpace Y] {p : X → Prop}
lemma Topology.IsInducing.subtypeVal {t : Set Y} : IsInducing ((↑) : t → Y) := ⟨rfl⟩
@[deprecated (since := "2024-10-28")] alias inducing_subtype_val := IsInducing.subtypeVal
lemma Topology.IsInducing.of_codRestrict {f : X → Y} {t : Set Y} (ht : ∀ x, f x ∈ t)
(h : IsInducing (t.codRestrict f ht)) : IsInducing f := subtypeVal.comp h
@[deprecated (since := "2024-10-28")] alias Inducing.of_codRestrict := IsInducing.of_codRestrict
lemma Topology.IsEmbedding.subtypeVal : IsEmbedding ((↑) : Subtype p → X) :=
⟨.subtypeVal, Subtype.coe_injective⟩
@[deprecated (since := "2024-10-26")] alias embedding_subtype_val := IsEmbedding.subtypeVal
theorem Topology.IsClosedEmbedding.subtypeVal (h : IsClosed {a | p a}) :
IsClosedEmbedding ((↑) : Subtype p → X) :=
⟨.subtypeVal, by rwa [Subtype.range_coe_subtype]⟩
@[continuity, fun_prop]
theorem continuous_subtype_val : Continuous (@Subtype.val X p) :=
continuous_induced_dom
theorem Continuous.subtype_val {f : Y → Subtype p} (hf : Continuous f) :
Continuous fun x => (f x : X) :=
continuous_subtype_val.comp hf
theorem IsOpen.isOpenEmbedding_subtypeVal {s : Set X} (hs : IsOpen s) :
IsOpenEmbedding ((↑) : s → X) :=
⟨.subtypeVal, (@Subtype.range_coe _ s).symm ▸ hs⟩
theorem IsOpen.isOpenMap_subtype_val {s : Set X} (hs : IsOpen s) : IsOpenMap ((↑) : s → X) :=
hs.isOpenEmbedding_subtypeVal.isOpenMap
theorem IsOpenMap.restrict {f : X → Y} (hf : IsOpenMap f) {s : Set X} (hs : IsOpen s) :
IsOpenMap (s.restrict f) :=
hf.comp hs.isOpenMap_subtype_val
lemma IsClosed.isClosedEmbedding_subtypeVal {s : Set X} (hs : IsClosed s) :
IsClosedEmbedding ((↑) : s → X) := .subtypeVal hs
theorem IsClosed.isClosedMap_subtype_val {s : Set X} (hs : IsClosed s) :
IsClosedMap ((↑) : s → X) :=
hs.isClosedEmbedding_subtypeVal.isClosedMap
@[continuity, fun_prop]
theorem Continuous.subtype_mk {f : Y → X} (h : Continuous f) (hp : ∀ x, p (f x)) :
Continuous fun x => (⟨f x, hp x⟩ : Subtype p) :=
continuous_induced_rng.2 h
theorem Continuous.subtype_map {f : X → Y} (h : Continuous f) {q : Y → Prop}
(hpq : ∀ x, p x → q (f x)) : Continuous (Subtype.map f hpq) :=
(h.comp continuous_subtype_val).subtype_mk _
theorem continuous_inclusion {s t : Set X} (h : s ⊆ t) : Continuous (inclusion h) :=
continuous_id.subtype_map h
theorem continuousAt_subtype_val {p : X → Prop} {x : Subtype p} :
ContinuousAt ((↑) : Subtype p → X) x :=
continuous_subtype_val.continuousAt
theorem Subtype.dense_iff {s : Set X} {t : Set s} : Dense t ↔ s ⊆ closure ((↑) '' t) := by
rw [IsInducing.subtypeVal.dense_iff, SetCoe.forall]
rfl
theorem map_nhds_subtype_val {s : Set X} (x : s) : map ((↑) : s → X) (𝓝 x) = 𝓝[s] ↑x := by
rw [IsInducing.subtypeVal.map_nhds_eq, Subtype.range_val]
theorem map_nhds_subtype_coe_eq_nhds {x : X} (hx : p x) (h : ∀ᶠ x in 𝓝 x, p x) :
map ((↑) : Subtype p → X) (𝓝 ⟨x, hx⟩) = 𝓝 x :=
map_nhds_induced_of_mem <| by rw [Subtype.range_val]; exact h
theorem nhds_subtype_eq_comap {x : X} {h : p x} : 𝓝 (⟨x, h⟩ : Subtype p) = comap (↑) (𝓝 x) :=
nhds_induced _ _
theorem tendsto_subtype_rng {Y : Type*} {p : X → Prop} {l : Filter Y} {f : Y → Subtype p} :
∀ {x : Subtype p}, Tendsto f l (𝓝 x) ↔ Tendsto (fun x => (f x : X)) l (𝓝 (x : X))
| ⟨a, ha⟩ => by rw [nhds_subtype_eq_comap, tendsto_comap_iff]; rfl
theorem closure_subtype {x : { a // p a }} {s : Set { a // p a }} :
x ∈ closure s ↔ (x : X) ∈ closure (((↑) : _ → X) '' s) :=
closure_induced
@[simp]
theorem continuousAt_codRestrict_iff {f : X → Y} {t : Set Y} (h1 : ∀ x, f x ∈ t) {x : X} :
ContinuousAt (codRestrict f t h1) x ↔ ContinuousAt f x :=
IsInducing.subtypeVal.continuousAt_iff
alias ⟨_, ContinuousAt.codRestrict⟩ := continuousAt_codRestrict_iff
theorem ContinuousAt.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t) {x : s}
(h2 : ContinuousAt f x) : ContinuousAt (h1.restrict f s t) x :=
(h2.comp continuousAt_subtype_val).codRestrict _
theorem ContinuousAt.restrictPreimage {f : X → Y} {s : Set Y} {x : f ⁻¹' s} (h : ContinuousAt f x) :
ContinuousAt (s.restrictPreimage f) x :=
h.restrict _
@[continuity, fun_prop]
theorem Continuous.codRestrict {f : X → Y} {s : Set Y} (hf : Continuous f) (hs : ∀ a, f a ∈ s) :
Continuous (s.codRestrict f hs) :=
hf.subtype_mk hs
@[continuity, fun_prop]
theorem Continuous.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t)
(h2 : Continuous f) : Continuous (h1.restrict f s t) :=
(h2.comp continuous_subtype_val).codRestrict _
@[continuity, fun_prop]
theorem Continuous.restrictPreimage {f : X → Y} {s : Set Y} (h : Continuous f) :
Continuous (s.restrictPreimage f) :=
h.restrict _
lemma Topology.IsEmbedding.restrict {f : X → Y}
(hf : IsEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) :
IsEmbedding H.restrict :=
.of_comp (hf.continuous.restrict H) continuous_subtype_val (hf.comp .subtypeVal)
lemma Topology.IsOpenEmbedding.restrict {f : X → Y}
(hf : IsOpenEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) (hs : IsOpen s) :
IsOpenEmbedding H.restrict :=
⟨hf.isEmbedding.restrict H, (by
rw [MapsTo.range_restrict]
exact continuous_subtype_val.1 _ (hf.isOpenMap _ hs))⟩
theorem Topology.IsInducing.codRestrict {e : X → Y} (he : IsInducing e) {s : Set Y}
(hs : ∀ x, e x ∈ s) : IsInducing (codRestrict e s hs) :=
he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val
@[deprecated (since := "2024-10-28")] alias Inducing.codRestrict := IsInducing.codRestrict
protected lemma Topology.IsEmbedding.codRestrict {e : X → Y} (he : IsEmbedding e) (s : Set Y)
(hs : ∀ x, e x ∈ s) : IsEmbedding (codRestrict e s hs) :=
he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val
@[deprecated (since := "2024-10-26")]
alias Embedding.codRestrict := IsEmbedding.codRestrict
variable {s t : Set X}
protected lemma Topology.IsEmbedding.inclusion (h : s ⊆ t) :
IsEmbedding (inclusion h) := IsEmbedding.subtypeVal.codRestrict _ _
protected lemma Topology.IsOpenEmbedding.inclusion (hst : s ⊆ t) (hs : IsOpen (t ↓∩ s)) :
IsOpenEmbedding (inclusion hst) where
toIsEmbedding := .inclusion _
isOpen_range := by rwa [range_inclusion]
protected lemma Topology.IsClosedEmbedding.inclusion (hst : s ⊆ t) (hs : IsClosed (t ↓∩ s)) :
IsClosedEmbedding (inclusion hst) where
toIsEmbedding := .inclusion _
isClosed_range := by rwa [range_inclusion]
@[deprecated (since := "2024-10-26")]
alias embedding_inclusion := IsEmbedding.inclusion
/-- Let `s, t ⊆ X` be two subsets of a topological space `X`. If `t ⊆ s` and the topology induced
by `X`on `s` is discrete, then also the topology induces on `t` is discrete. -/
theorem DiscreteTopology.of_subset {X : Type*} [TopologicalSpace X] {s t : Set X}
(_ : DiscreteTopology s) (ts : t ⊆ s) : DiscreteTopology t :=
(IsEmbedding.inclusion ts).discreteTopology
/-- Let `s` be a discrete subset of a topological space. Then the preimage of `s` by
a continuous injective map is also discrete. -/
theorem DiscreteTopology.preimage_of_continuous_injective {X Y : Type*} [TopologicalSpace X]
[TopologicalSpace Y] (s : Set Y) [DiscreteTopology s] {f : X → Y} (hc : Continuous f)
(hinj : Function.Injective f) : DiscreteTopology (f ⁻¹' s) :=
DiscreteTopology.of_continuous_injective (β := s) (Continuous.restrict
(by exact fun _ x ↦ x) hc) ((MapsTo.restrict_inj _).mpr hinj.injOn)
/-- If `f : X → Y` is a quotient map,
then its restriction to the preimage of an open set is a quotient map too. -/
theorem Topology.IsQuotientMap.restrictPreimage_isOpen {f : X → Y} (hf : IsQuotientMap f)
{s : Set Y} (hs : IsOpen s) : IsQuotientMap (s.restrictPreimage f) := by
refine isQuotientMap_iff.2 ⟨hf.surjective.restrictPreimage _, fun U ↦ ?_⟩
rw [hs.isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen, ← hf.isOpen_preimage,
(hs.preimage hf.continuous).isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen,
image_val_preimage_restrictPreimage]
@[deprecated (since := "2024-10-22")]
alias QuotientMap.restrictPreimage_isOpen := IsQuotientMap.restrictPreimage_isOpen
open scoped Set.Notation in
lemma isClosed_preimage_val {s t : Set X} : IsClosed (s ↓∩ t) ↔ s ∩ closure (s ∩ t) ⊆ t := by
rw [← closure_eq_iff_isClosed, IsEmbedding.subtypeVal.closure_eq_preimage_closure_image,
← Subtype.val_injective.image_injective.eq_iff, Subtype.image_preimage_coe,
Subtype.image_preimage_coe, subset_antisymm_iff, and_iff_left, Set.subset_inter_iff,
and_iff_right]
exacts [Set.inter_subset_left, Set.subset_inter Set.inter_subset_left subset_closure]
theorem frontier_inter_open_inter {s t : Set X} (ht : IsOpen t) :
frontier (s ∩ t) ∩ t = frontier s ∩ t := by
simp only [Set.inter_comm _ t, ← Subtype.preimage_coe_eq_preimage_coe_iff,
ht.isOpenMap_subtype_val.preimage_frontier_eq_frontier_preimage continuous_subtype_val,
Subtype.preimage_coe_self_inter]
section SetNotation
open scoped Set.Notation
lemma IsOpen.preimage_val {s t : Set X} (ht : IsOpen t) : IsOpen (s ↓∩ t) :=
ht.preimage continuous_subtype_val
lemma IsClosed.preimage_val {s t : Set X} (ht : IsClosed t) : IsClosed (s ↓∩ t) :=
ht.preimage continuous_subtype_val
@[simp] lemma IsOpen.inter_preimage_val_iff {s t : Set X} (hs : IsOpen s) :
IsOpen (s ↓∩ t) ↔ IsOpen (s ∩ t) :=
⟨fun h ↦ by simpa using hs.isOpenMap_subtype_val _ h,
fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm ▸ h.preimage_val⟩
@[simp] lemma IsClosed.inter_preimage_val_iff {s t : Set X} (hs : IsClosed s) :
IsClosed (s ↓∩ t) ↔ IsClosed (s ∩ t) :=
⟨fun h ↦ by simpa using hs.isClosedMap_subtype_val _ h,
fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm ▸ h.preimage_val⟩
end SetNotation
end Subtype
section Quotient
variable [TopologicalSpace X] [TopologicalSpace Y]
variable {r : X → X → Prop} {s : Setoid X}
theorem isQuotientMap_quot_mk : IsQuotientMap (@Quot.mk X r) :=
⟨Quot.exists_rep, rfl⟩
@[deprecated (since := "2024-10-22")]
alias quotientMap_quot_mk := isQuotientMap_quot_mk
@[continuity, fun_prop]
theorem continuous_quot_mk : Continuous (@Quot.mk X r) :=
continuous_coinduced_rng
@[continuity, fun_prop]
theorem continuous_quot_lift {f : X → Y} (hr : ∀ a b, r a b → f a = f b) (h : Continuous f) :
Continuous (Quot.lift f hr : Quot r → Y) :=
continuous_coinduced_dom.2 h
theorem isQuotientMap_quotient_mk' : IsQuotientMap (@Quotient.mk' X s) :=
isQuotientMap_quot_mk
@[deprecated (since := "2024-10-22")]
alias quotientMap_quotient_mk' := isQuotientMap_quotient_mk'
theorem continuous_quotient_mk' : Continuous (@Quotient.mk' X s) :=
continuous_coinduced_rng
theorem Continuous.quotient_lift {f : X → Y} (h : Continuous f) (hs : ∀ a b, a ≈ b → f a = f b) :
Continuous (Quotient.lift f hs : Quotient s → Y) :=
continuous_coinduced_dom.2 h
theorem Continuous.quotient_liftOn' {f : X → Y} (h : Continuous f)
(hs : ∀ a b, s a b → f a = f b) :
Continuous (fun x => Quotient.liftOn' x f hs : Quotient s → Y) :=
h.quotient_lift hs
open scoped Relator in
@[continuity, fun_prop]
theorem Continuous.quotient_map' {t : Setoid Y} {f : X → Y} (hf : Continuous f)
(H : (s.r ⇒ t.r) f f) : Continuous (Quotient.map' f H) :=
(continuous_quotient_mk'.comp hf).quotient_lift _
end Quotient
section Pi
variable {ι : Type*} {π : ι → Type*} {κ : Type*} [TopologicalSpace X]
[T : ∀ i, TopologicalSpace (π i)] {f : X → ∀ i : ι, π i}
theorem continuous_pi_iff : Continuous f ↔ ∀ i, Continuous fun a => f a i := by
simp only [continuous_iInf_rng, continuous_induced_rng, comp_def]
@[continuity, fun_prop]
theorem continuous_pi (h : ∀ i, Continuous fun a => f a i) : Continuous f :=
continuous_pi_iff.2 h
@[continuity, fun_prop]
theorem continuous_apply (i : ι) : Continuous fun p : ∀ i, π i => p i :=
continuous_iInf_dom continuous_induced_dom
@[continuity]
theorem continuous_apply_apply {ρ : κ → ι → Type*} [∀ j i, TopologicalSpace (ρ j i)] (j : κ)
(i : ι) : Continuous fun p : ∀ j, ∀ i, ρ j i => p j i :=
(continuous_apply i).comp (continuous_apply j)
theorem continuousAt_apply (i : ι) (x : ∀ i, π i) : ContinuousAt (fun p : ∀ i, π i => p i) x :=
(continuous_apply i).continuousAt
theorem Filter.Tendsto.apply_nhds {l : Filter Y} {f : Y → ∀ i, π i} {x : ∀ i, π i}
(h : Tendsto f l (𝓝 x)) (i : ι) : Tendsto (fun a => f a i) l (𝓝 <| x i) :=
(continuousAt_apply i _).tendsto.comp h
@[fun_prop]
protected theorem Continuous.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)]
{f : ∀ i, π i → Y i} (hf : ∀ i, Continuous (f i)) : Continuous (Pi.map f) :=
continuous_pi fun i ↦ (hf i).comp (continuous_apply i)
theorem nhds_pi {a : ∀ i, π i} : 𝓝 a = pi fun i => 𝓝 (a i) := by
simp only [nhds_iInf, nhds_induced, Filter.pi]
protected theorem IsOpenMap.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f : ∀ i, π i → Y i}
(hfo : ∀ i, IsOpenMap (f i)) (hsurj : ∀ᶠ i in cofinite, Surjective (f i)) :
IsOpenMap (Pi.map f) := by
refine IsOpenMap.of_nhds_le fun x ↦ ?_
rw [nhds_pi, nhds_pi, map_piMap_pi hsurj]
exact Filter.pi_mono fun i ↦ (hfo i).nhds_le _
protected theorem IsOpenQuotientMap.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)]
{f : ∀ i, π i → Y i} (hf : ∀ i, IsOpenQuotientMap (f i)) : IsOpenQuotientMap (Pi.map f) :=
⟨.piMap fun i ↦ (hf i).1, .piMap fun i ↦ (hf i).2, .piMap (fun i ↦ (hf i).3) <|
.of_forall fun i ↦ (hf i).1⟩
theorem tendsto_pi_nhds {f : Y → ∀ i, π i} {g : ∀ i, π i} {u : Filter Y} :
Tendsto f u (𝓝 g) ↔ ∀ x, Tendsto (fun i => f i x) u (𝓝 (g x)) := by
rw [nhds_pi, Filter.tendsto_pi]
theorem continuousAt_pi {f : X → ∀ i, π i} {x : X} :
ContinuousAt f x ↔ ∀ i, ContinuousAt (fun y => f y i) x :=
tendsto_pi_nhds
@[fun_prop]
theorem continuousAt_pi' {f : X → ∀ i, π i} {x : X} (hf : ∀ i, ContinuousAt (fun y => f y i) x) :
ContinuousAt f x :=
continuousAt_pi.2 hf
@[fun_prop]
protected theorem ContinuousAt.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)]
{f : ∀ i, π i → Y i} {x : ∀ i, π i} (hf : ∀ i, ContinuousAt (f i) (x i)) :
ContinuousAt (Pi.map f) x :=
continuousAt_pi.2 fun i ↦ (hf i).comp (continuousAt_apply i x)
theorem Pi.continuous_precomp' {ι' : Type*} (φ : ι' → ι) :
Continuous (fun (f : (∀ i, π i)) (j : ι') ↦ f (φ j)) :=
continuous_pi fun j ↦ continuous_apply (φ j)
theorem Pi.continuous_precomp {ι' : Type*} (φ : ι' → ι) :
Continuous (· ∘ φ : (ι → X) → (ι' → X)) :=
Pi.continuous_precomp' φ
theorem Pi.continuous_postcomp' {X : ι → Type*} [∀ i, TopologicalSpace (X i)]
{g : ∀ i, π i → X i} (hg : ∀ i, Continuous (g i)) :
Continuous (fun (f : (∀ i, π i)) (i : ι) ↦ g i (f i)) :=
continuous_pi fun i ↦ (hg i).comp <| continuous_apply i
theorem Pi.continuous_postcomp [TopologicalSpace Y] {g : X → Y} (hg : Continuous g) :
Continuous (g ∘ · : (ι → X) → (ι → Y)) :=
Pi.continuous_postcomp' fun _ ↦ hg
lemma Pi.induced_precomp' {ι' : Type*} (φ : ι' → ι) :
induced (fun (f : (∀ i, π i)) (j : ι') ↦ f (φ j)) Pi.topologicalSpace =
⨅ i', induced (eval (φ i')) (T (φ i')) := by
simp [Pi.topologicalSpace, induced_iInf, induced_compose, comp_def]
lemma Pi.induced_precomp [TopologicalSpace Y] {ι' : Type*} (φ : ι' → ι) :
induced (· ∘ φ) Pi.topologicalSpace =
⨅ i', induced (eval (φ i')) ‹TopologicalSpace Y› :=
induced_precomp' φ
@[continuity, fun_prop]
lemma Pi.continuous_restrict (S : Set ι) :
Continuous (S.restrict : (∀ i : ι, π i) → (∀ i : S, π i)) :=
Pi.continuous_precomp' ((↑) : S → ι)
@[continuity, fun_prop]
lemma Pi.continuous_restrict₂ {s t : Set ι} (hst : s ⊆ t) : Continuous (restrict₂ (π := π) hst) :=
continuous_pi fun _ ↦ continuous_apply _
@[continuity, fun_prop]
theorem Finset.continuous_restrict (s : Finset ι) : Continuous (s.restrict (π := π)) :=
continuous_pi fun _ ↦ continuous_apply _
@[continuity, fun_prop]
theorem Finset.continuous_restrict₂ {s t : Finset ι} (hst : s ⊆ t) :
Continuous (Finset.restrict₂ (π := π) hst) :=
continuous_pi fun _ ↦ continuous_apply _
variable [TopologicalSpace Z]
@[continuity, fun_prop]
theorem Pi.continuous_restrict_apply (s : Set X) {f : X → Z} (hf : Continuous f) :
Continuous (s.restrict f) := hf.comp continuous_subtype_val
@[continuity, fun_prop]
theorem Pi.continuous_restrict₂_apply {s t : Set X} (hst : s ⊆ t)
{f : t → Z} (hf : Continuous f) :
Continuous (restrict₂ (π := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst)
@[continuity, fun_prop]
theorem Finset.continuous_restrict_apply (s : Finset X) {f : X → Z} (hf : Continuous f) :
Continuous (s.restrict f) := hf.comp continuous_subtype_val
@[continuity, fun_prop]
theorem Finset.continuous_restrict₂_apply {s t : Finset X} (hst : s ⊆ t)
{f : t → Z} (hf : Continuous f) :
Continuous (restrict₂ (π := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst)
lemma Pi.induced_restrict (S : Set ι) :
induced (S.restrict) Pi.topologicalSpace =
⨅ i ∈ S, induced (eval i) (T i) := by
simp +unfoldPartialApp [← iInf_subtype'', ← induced_precomp' ((↑) : S → ι),
restrict]
lemma Pi.induced_restrict_sUnion (𝔖 : Set (Set ι)) :
induced (⋃₀ 𝔖).restrict (Pi.topologicalSpace (Y := fun i : (⋃₀ 𝔖) ↦ π i)) =
⨅ S ∈ 𝔖, induced S.restrict Pi.topologicalSpace := by
simp_rw [Pi.induced_restrict, iInf_sUnion]
theorem Filter.Tendsto.update [DecidableEq ι] {l : Filter Y} {f : Y → ∀ i, π i} {x : ∀ i, π i}
(hf : Tendsto f l (𝓝 x)) (i : ι) {g : Y → π i} {xi : π i} (hg : Tendsto g l (𝓝 xi)) :
Tendsto (fun a => update (f a) i (g a)) l (𝓝 <| update x i xi) :=
tendsto_pi_nhds.2 fun j => by rcases eq_or_ne j i with (rfl | hj) <;> simp [*, hf.apply_nhds]
theorem ContinuousAt.update [DecidableEq ι] {x : X} (hf : ContinuousAt f x) (i : ι) {g : X → π i}
(hg : ContinuousAt g x) : ContinuousAt (fun a => update (f a) i (g a)) x :=
hf.tendsto.update i hg
theorem Continuous.update [DecidableEq ι] (hf : Continuous f) (i : ι) {g : X → π i}
(hg : Continuous g) : Continuous fun a => update (f a) i (g a) :=
continuous_iff_continuousAt.2 fun _ => hf.continuousAt.update i hg.continuousAt
/-- `Function.update f i x` is continuous in `(f, x)`. -/
@[continuity, fun_prop]
theorem continuous_update [DecidableEq ι] (i : ι) :
Continuous fun f : (∀ j, π j) × π i => update f.1 i f.2 :=
continuous_fst.update i continuous_snd
/-- `Pi.mulSingle i x` is continuous in `x`. -/
@[to_additive (attr := continuity) "`Pi.single i x` is continuous in `x`."]
theorem continuous_mulSingle [∀ i, One (π i)] [DecidableEq ι] (i : ι) :
Continuous fun x => (Pi.mulSingle i x : ∀ i, π i) :=
continuous_const.update _ continuous_id
section Fin
variable {n : ℕ} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)]
theorem Filter.Tendsto.finCons
{f : Y → π 0} {g : Y → ∀ j : Fin n, π j.succ} {l : Filter Y} {x : π 0} {y : ∀ j, π (Fin.succ j)}
(hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) :
Tendsto (fun a => Fin.cons (f a) (g a)) l (𝓝 <| Fin.cons x y) :=
tendsto_pi_nhds.2 fun j => Fin.cases (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j
theorem ContinuousAt.finCons {f : X → π 0} {g : X → ∀ j : Fin n, π (Fin.succ j)} {x : X}
(hf : ContinuousAt f x) (hg : ContinuousAt g x) :
ContinuousAt (fun a => Fin.cons (f a) (g a)) x :=
hf.tendsto.finCons hg
theorem Continuous.finCons {f : X → π 0} {g : X → ∀ j : Fin n, π (Fin.succ j)}
(hf : Continuous f) (hg : Continuous g) : Continuous fun a => Fin.cons (f a) (g a) :=
continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finCons hg.continuousAt
theorem Filter.Tendsto.matrixVecCons
{f : Y → Z} {g : Y → Fin n → Z} {l : Filter Y} {x : Z} {y : Fin n → Z}
(hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) :
Tendsto (fun a => Matrix.vecCons (f a) (g a)) l (𝓝 <| Matrix.vecCons x y) :=
hf.finCons hg
theorem ContinuousAt.matrixVecCons
{f : X → Z} {g : X → Fin n → Z} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) :
ContinuousAt (fun a => Matrix.vecCons (f a) (g a)) x :=
hf.finCons hg
theorem Continuous.matrixVecCons
{f : X → Z} {g : X → Fin n → Z} (hf : Continuous f) (hg : Continuous g) :
Continuous fun a => Matrix.vecCons (f a) (g a) :=
hf.finCons hg
theorem Filter.Tendsto.finSnoc
{f : Y → ∀ j : Fin n, π j.castSucc} {g : Y → π (Fin.last _)}
{l : Filter Y} {x : ∀ j, π (Fin.castSucc j)} {y : π (Fin.last _)}
(hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) :
Tendsto (fun a => Fin.snoc (f a) (g a)) l (𝓝 <| Fin.snoc x y) :=
tendsto_pi_nhds.2 fun j => Fin.lastCases (by simpa) (by simpa using tendsto_pi_nhds.1 hf) j
theorem ContinuousAt.finSnoc {f : X → ∀ j : Fin n, π j.castSucc} {g : X → π (Fin.last _)} {x : X}
(hf : ContinuousAt f x) (hg : ContinuousAt g x) :
ContinuousAt (fun a => Fin.snoc (f a) (g a)) x :=
hf.tendsto.finSnoc hg
theorem Continuous.finSnoc {f : X → ∀ j : Fin n, π j.castSucc} {g : X → π (Fin.last _)}
(hf : Continuous f) (hg : Continuous g) : Continuous fun a => Fin.snoc (f a) (g a) :=
continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finSnoc hg.continuousAt
theorem Filter.Tendsto.finInsertNth
(i : Fin (n + 1)) {f : Y → π i} {g : Y → ∀ j : Fin n, π (i.succAbove j)} {l : Filter Y}
{x : π i} {y : ∀ j, π (i.succAbove j)} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) :
Tendsto (fun a => i.insertNth (f a) (g a)) l (𝓝 <| i.insertNth x y) :=
tendsto_pi_nhds.2 fun j => Fin.succAboveCases i (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j
@[deprecated (since := "2025-01-02")]
alias Filter.Tendsto.fin_insertNth := Filter.Tendsto.finInsertNth
theorem ContinuousAt.finInsertNth
(i : Fin (n + 1)) {f : X → π i} {g : X → ∀ j : Fin n, π (i.succAbove j)} {x : X}
(hf : ContinuousAt f x) (hg : ContinuousAt g x) :
ContinuousAt (fun a => i.insertNth (f a) (g a)) x :=
hf.tendsto.finInsertNth i hg
@[deprecated (since := "2025-01-02")]
alias ContinuousAt.fin_insertNth := ContinuousAt.finInsertNth
theorem Continuous.finInsertNth
(i : Fin (n + 1)) {f : X → π i} {g : X → ∀ j : Fin n, π (i.succAbove j)}
(hf : Continuous f) (hg : Continuous g) : Continuous fun a => i.insertNth (f a) (g a) :=
continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finInsertNth i hg.continuousAt
@[deprecated (since := "2025-01-02")]
alias Continuous.fin_insertNth := Continuous.finInsertNth
theorem Filter.Tendsto.finInit {f : Y → ∀ j : Fin (n + 1), π j} {l : Filter Y} {x : ∀ j, π j}
(hg : Tendsto f l (𝓝 x)) : Tendsto (fun a ↦ Fin.init (f a)) l (𝓝 <| Fin.init x) :=
tendsto_pi_nhds.2 fun j ↦ apply_nhds hg j.castSucc
@[fun_prop]
theorem ContinuousAt.finInit {f : X → ∀ j : Fin (n + 1), π j} {x : X}
(hf : ContinuousAt f x) : ContinuousAt (fun a ↦ Fin.init (f a)) x :=
hf.tendsto.finInit
@[fun_prop]
theorem Continuous.finInit {f : X → ∀ j : Fin (n + 1), π j} (hf : Continuous f) :
Continuous fun a ↦ Fin.init (f a) :=
continuous_iff_continuousAt.2 fun _ ↦ hf.continuousAt.finInit
theorem Filter.Tendsto.finTail {f : Y → ∀ j : Fin (n + 1), π j} {l : Filter Y} {x : ∀ j, π j}
(hg : Tendsto f l (𝓝 x)) : Tendsto (fun a ↦ Fin.tail (f a)) l (𝓝 <| Fin.tail x) :=
tendsto_pi_nhds.2 fun j ↦ apply_nhds hg j.succ
@[fun_prop]
theorem ContinuousAt.finTail {f : X → ∀ j : Fin (n + 1), π j} {x : X}
(hf : ContinuousAt f x) : ContinuousAt (fun a ↦ Fin.tail (f a)) x :=
hf.tendsto.finTail
@[fun_prop]
theorem Continuous.finTail {f : X → ∀ j : Fin (n + 1), π j} (hf : Continuous f) :
Continuous fun a ↦ Fin.tail (f a) :=
continuous_iff_continuousAt.2 fun _ ↦ hf.continuousAt.finTail
end Fin
theorem isOpen_set_pi {i : Set ι} {s : ∀ a, Set (π a)} (hi : i.Finite)
(hs : ∀ a ∈ i, IsOpen (s a)) : IsOpen (pi i s) := by
rw [pi_def]; exact hi.isOpen_biInter fun a ha => (hs _ ha).preimage (continuous_apply _)
theorem isOpen_pi_iff {s : Set (∀ a, π a)} :
IsOpen s ↔
∀ f, f ∈ s → ∃ (I : Finset ι) (u : ∀ a, Set (π a)),
(∀ a, a ∈ I → IsOpen (u a) ∧ f a ∈ u a) ∧ (I : Set ι).pi u ⊆ s := by
rw [isOpen_iff_nhds]
simp_rw [le_principal_iff, nhds_pi, Filter.mem_pi', mem_nhds_iff]
refine forall₂_congr fun a _ => ⟨?_, ?_⟩
· rintro ⟨I, t, ⟨h1, h2⟩⟩
refine ⟨I, fun a => eval a '' (I : Set ι).pi fun a => (h1 a).choose, fun i hi => ?_, ?_⟩
· simp_rw [eval_image_pi (Finset.mem_coe.mpr hi)
(pi_nonempty_iff.mpr fun i => ⟨_, fun _ => (h1 i).choose_spec.2.2⟩)]
exact (h1 i).choose_spec.2
· exact Subset.trans
(pi_mono fun i hi => (eval_image_pi_subset hi).trans (h1 i).choose_spec.1) h2
· rintro ⟨I, t, ⟨h1, h2⟩⟩
classical
refine ⟨I, fun a => ite (a ∈ I) (t a) univ, fun i => ?_, ?_⟩
· by_cases hi : i ∈ I
· use t i
simp_rw [if_pos hi]
exact ⟨Subset.rfl, (h1 i) hi⟩
· use univ
simp_rw [if_neg hi]
exact ⟨Subset.rfl, isOpen_univ, mem_univ _⟩
· rw [← univ_pi_ite]
simp only [← ite_and, ← Finset.mem_coe, and_self_iff, univ_pi_ite, h2]
theorem isOpen_pi_iff' [Finite ι] {s : Set (∀ a, π a)} :
IsOpen s ↔
∀ f, f ∈ s → ∃ u : ∀ a, Set (π a), (∀ a, IsOpen (u a) ∧ f a ∈ u a) ∧ univ.pi u ⊆ s := by
cases nonempty_fintype ι
rw [isOpen_iff_nhds]
simp_rw [le_principal_iff, nhds_pi, Filter.mem_pi', mem_nhds_iff]
refine forall₂_congr fun a _ => ⟨?_, ?_⟩
· rintro ⟨I, t, ⟨h1, h2⟩⟩
refine
⟨fun i => (h1 i).choose,
⟨fun i => (h1 i).choose_spec.2,
(pi_mono fun i _ => (h1 i).choose_spec.1).trans (Subset.trans ?_ h2)⟩⟩
rw [← pi_inter_compl (I : Set ι)]
exact inter_subset_left
· exact fun ⟨u, ⟨h1, _⟩⟩ =>
⟨Finset.univ, u, ⟨fun i => ⟨u i, ⟨rfl.subset, h1 i⟩⟩, by rwa [Finset.coe_univ]⟩⟩
theorem isClosed_set_pi {i : Set ι} {s : ∀ a, Set (π a)} (hs : ∀ a ∈ i, IsClosed (s a)) :
IsClosed (pi i s) := by
rw [pi_def]; exact isClosed_biInter fun a ha => (hs _ ha).preimage (continuous_apply _)
theorem mem_nhds_of_pi_mem_nhds {I : Set ι} {s : ∀ i, Set (π i)} (a : ∀ i, π i) (hs : I.pi s ∈ 𝓝 a)
{i : ι} (hi : i ∈ I) : s i ∈ 𝓝 (a i) := by
rw [nhds_pi] at hs; exact mem_of_pi_mem_pi hs hi
theorem set_pi_mem_nhds {i : Set ι} {s : ∀ a, Set (π a)} {x : ∀ a, π a} (hi : i.Finite)
(hs : ∀ a ∈ i, s a ∈ 𝓝 (x a)) : pi i s ∈ 𝓝 x := by
rw [pi_def, biInter_mem hi]
exact fun a ha => (continuous_apply a).continuousAt (hs a ha)
theorem set_pi_mem_nhds_iff {I : Set ι} (hI : I.Finite) {s : ∀ i, Set (π i)} (a : ∀ i, π i) :
I.pi s ∈ 𝓝 a ↔ ∀ i : ι, i ∈ I → s i ∈ 𝓝 (a i) := by
rw [nhds_pi, pi_mem_pi_iff hI]
theorem interior_pi_set {I : Set ι} (hI : I.Finite) {s : ∀ i, Set (π i)} :
interior (pi I s) = I.pi fun i => interior (s i) := by
ext a
simp only [Set.mem_pi, mem_interior_iff_mem_nhds, set_pi_mem_nhds_iff hI]
theorem exists_finset_piecewise_mem_of_mem_nhds [DecidableEq ι] {s : Set (∀ a, π a)} {x : ∀ a, π a}
(hs : s ∈ 𝓝 x) (y : ∀ a, π a) : ∃ I : Finset ι, I.piecewise x y ∈ s := by
simp only [nhds_pi, Filter.mem_pi'] at hs
rcases hs with ⟨I, t, htx, hts⟩
refine ⟨I, hts fun i hi => ?_⟩
simpa [Finset.mem_coe.1 hi] using mem_of_mem_nhds (htx i)
theorem pi_generateFrom_eq {π : ι → Type*} {g : ∀ a, Set (Set (π a))} :
(@Pi.topologicalSpace ι π fun a => generateFrom (g a)) =
generateFrom
{ t | ∃ (s : ∀ a, Set (π a)) (i : Finset ι), (∀ a ∈ i, s a ∈ g a) ∧ t = pi (↑i) s } := by
refine le_antisymm ?_ ?_
· apply le_generateFrom
rintro _ ⟨s, i, hi, rfl⟩
letI := fun a => generateFrom (g a)
exact isOpen_set_pi i.finite_toSet (fun a ha => GenerateOpen.basic _ (hi a ha))
· classical
refine le_iInf fun i => coinduced_le_iff_le_induced.1 <| le_generateFrom fun s hs => ?_
refine GenerateOpen.basic _ ⟨update (fun i => univ) i s, {i}, ?_⟩
simp [hs]
theorem pi_eq_generateFrom :
Pi.topologicalSpace =
generateFrom
{ g | ∃ (s : ∀ a, Set (π a)) (i : Finset ι), (∀ a ∈ i, IsOpen (s a)) ∧ g = pi (↑i) s } :=
calc Pi.topologicalSpace
_ = @Pi.topologicalSpace ι π fun _ => generateFrom { s | IsOpen s } := by
simp only [generateFrom_setOf_isOpen]
_ = _ := pi_generateFrom_eq
theorem pi_generateFrom_eq_finite {π : ι → Type*} {g : ∀ a, Set (Set (π a))} [Finite ι]
(hg : ∀ a, ⋃₀ g a = univ) :
(@Pi.topologicalSpace ι π fun a => generateFrom (g a)) =
generateFrom { t | ∃ s : ∀ a, Set (π a), (∀ a, s a ∈ g a) ∧ t = pi univ s } := by
cases nonempty_fintype ι
rw [pi_generateFrom_eq]
refine le_antisymm (generateFrom_anti ?_) (le_generateFrom ?_)
· exact fun s ⟨t, ht, Eq⟩ => ⟨t, Finset.univ, by simp [ht, Eq]⟩
· rintro s ⟨t, i, ht, rfl⟩
letI := generateFrom { t | ∃ s : ∀ a, Set (π a), (∀ a, s a ∈ g a) ∧ t = pi univ s }
refine isOpen_iff_forall_mem_open.2 fun f hf => ?_
choose c hcg hfc using fun a => sUnion_eq_univ_iff.1 (hg a) (f a)
refine ⟨pi i t ∩ pi ((↑i)ᶜ : Set ι) c, inter_subset_left, ?_, ⟨hf, fun a _ => hfc a⟩⟩
classical
rw [← univ_pi_piecewise]
refine GenerateOpen.basic _ ⟨_, fun a => ?_, rfl⟩
by_cases a ∈ i <;> simp [*]
theorem induced_to_pi {X : Type*} (f : X → ∀ i, π i) :
induced f Pi.topologicalSpace = ⨅ i, induced (f · i) inferInstance := by
simp_rw [Pi.topologicalSpace, induced_iInf, induced_compose, Function.comp_def]
/-- Suppose `π i` is a family of topological spaces indexed by `i : ι`, and `X` is a type
endowed with a family of maps `f i : X → π i` for every `i : ι`, hence inducing a
map `g : X → Π i, π i`. This lemma shows that infimum of the topologies on `X` induced by
the `f i` as `i : ι` varies is simply the topology on `X` induced by `g : X → Π i, π i`
where `Π i, π i` is endowed with the usual product topology. -/
theorem inducing_iInf_to_pi {X : Type*} (f : ∀ i, X → π i) :
@IsInducing X (∀ i, π i) (⨅ i, induced (f i) inferInstance) _ fun x i => f i x :=
letI := ⨅ i, induced (f i) inferInstance; ⟨(induced_to_pi _).symm⟩
variable [Finite ι] [∀ i, DiscreteTopology (π i)]
/-- A finite product of discrete spaces is discrete. -/
instance Pi.discreteTopology : DiscreteTopology (∀ i, π i) :=
singletons_open_iff_discrete.mp fun x => by
rw [← univ_pi_singleton]
exact isOpen_set_pi finite_univ fun i _ => (isOpen_discrete {x i})
end Pi
section Sigma
variable {ι κ : Type*} {σ : ι → Type*} {τ : κ → Type*} [∀ i, TopologicalSpace (σ i)]
[∀ k, TopologicalSpace (τ k)] [TopologicalSpace X]
@[continuity, fun_prop]
theorem continuous_sigmaMk {i : ι} : Continuous (@Sigma.mk ι σ i) :=
continuous_iSup_rng continuous_coinduced_rng
theorem isOpen_sigma_iff {s : Set (Sigma σ)} : IsOpen s ↔ ∀ i, IsOpen (Sigma.mk i ⁻¹' s) := by
rw [isOpen_iSup_iff]
rfl
theorem isClosed_sigma_iff {s : Set (Sigma σ)} : IsClosed s ↔ ∀ i, IsClosed (Sigma.mk i ⁻¹' s) := by
simp only [← isOpen_compl_iff, isOpen_sigma_iff, preimage_compl]
theorem isOpenMap_sigmaMk {i : ι} : IsOpenMap (@Sigma.mk ι σ i) := by
intro s hs
rw [isOpen_sigma_iff]
intro j
rcases eq_or_ne j i with (rfl | hne)
· rwa [preimage_image_eq _ sigma_mk_injective]
· rw [preimage_image_sigmaMk_of_ne hne]
exact isOpen_empty
theorem isOpen_range_sigmaMk {i : ι} : IsOpen (range (@Sigma.mk ι σ i)) :=
isOpenMap_sigmaMk.isOpen_range
theorem isClosedMap_sigmaMk {i : ι} : IsClosedMap (@Sigma.mk ι σ i) := by
intro s hs
rw [isClosed_sigma_iff]
intro j
rcases eq_or_ne j i with (rfl | hne)
· rwa [preimage_image_eq _ sigma_mk_injective]
· rw [preimage_image_sigmaMk_of_ne hne]
exact isClosed_empty
theorem isClosed_range_sigmaMk {i : ι} : IsClosed (range (@Sigma.mk ι σ i)) :=
isClosedMap_sigmaMk.isClosed_range
lemma Topology.IsOpenEmbedding.sigmaMk {i : ι} : IsOpenEmbedding (@Sigma.mk ι σ i) :=
.of_continuous_injective_isOpenMap continuous_sigmaMk sigma_mk_injective isOpenMap_sigmaMk
@[deprecated (since := "2024-10-30")] alias isOpenEmbedding_sigmaMk := IsOpenEmbedding.sigmaMk
lemma Topology.IsClosedEmbedding.sigmaMk {i : ι} : IsClosedEmbedding (@Sigma.mk ι σ i) :=
.of_continuous_injective_isClosedMap continuous_sigmaMk sigma_mk_injective isClosedMap_sigmaMk
@[deprecated (since := "2024-10-30")] alias isClosedEmbedding_sigmaMk := IsClosedEmbedding.sigmaMk
lemma Topology.IsEmbedding.sigmaMk {i : ι} : IsEmbedding (@Sigma.mk ι σ i) :=
IsClosedEmbedding.sigmaMk.1
@[deprecated (since := "2024-10-26")]
alias embedding_sigmaMk := IsEmbedding.sigmaMk
theorem Sigma.nhds_mk (i : ι) (x : σ i) : 𝓝 (⟨i, x⟩ : Sigma σ) = Filter.map (Sigma.mk i) (𝓝 x) :=
(IsOpenEmbedding.sigmaMk.map_nhds_eq x).symm
theorem Sigma.nhds_eq (x : Sigma σ) : 𝓝 x = Filter.map (Sigma.mk x.1) (𝓝 x.2) := by
cases x
apply Sigma.nhds_mk
theorem comap_sigmaMk_nhds (i : ι) (x : σ i) : comap (Sigma.mk i) (𝓝 ⟨i, x⟩) = 𝓝 x :=
(IsEmbedding.sigmaMk.nhds_eq_comap _).symm
theorem isOpen_sigma_fst_preimage (s : Set ι) : IsOpen (Sigma.fst ⁻¹' s : Set (Σ a, σ a)) := by
rw [← biUnion_of_singleton s, preimage_iUnion₂]
simp only [← range_sigmaMk]
exact isOpen_biUnion fun _ _ => isOpen_range_sigmaMk
/-- A map out of a sum type is continuous iff its restriction to each summand is. -/
@[simp]
theorem continuous_sigma_iff {f : Sigma σ → X} :
Continuous f ↔ ∀ i, Continuous fun a => f ⟨i, a⟩ := by
delta instTopologicalSpaceSigma
rw [continuous_iSup_dom]
exact forall_congr' fun _ => continuous_coinduced_dom
/-- A map out of a sum type is continuous if its restriction to each summand is. -/
@[continuity, fun_prop]
theorem continuous_sigma {f : Sigma σ → X} (hf : ∀ i, Continuous fun a => f ⟨i, a⟩) :
Continuous f :=
continuous_sigma_iff.2 hf
/-- A map defined on a sigma type (a.k.a. the disjoint union of an indexed family of topological
spaces) is inducing iff its restriction to each component is inducing and each the image of each
component under `f` can be separated from the images of all other components by an open set. -/
theorem inducing_sigma {f : Sigma σ → X} :
IsInducing f ↔ (∀ i, IsInducing (f ∘ Sigma.mk i)) ∧
(∀ i, ∃ U, IsOpen U ∧ ∀ x, f x ∈ U ↔ x.1 = i) := by
refine ⟨fun h ↦ ⟨fun i ↦ h.comp IsEmbedding.sigmaMk.1, fun i ↦ ?_⟩, ?_⟩
· rcases h.isOpen_iff.1 (isOpen_range_sigmaMk (i := i)) with ⟨U, hUo, hU⟩
refine ⟨U, hUo, ?_⟩
simpa [Set.ext_iff] using hU
· refine fun ⟨h₁, h₂⟩ ↦ isInducing_iff_nhds.2 fun ⟨i, x⟩ ↦ ?_
rw [Sigma.nhds_mk, (h₁ i).nhds_eq_comap, comp_apply, ← comap_comap, map_comap_of_mem]
rcases h₂ i with ⟨U, hUo, hU⟩
filter_upwards [preimage_mem_comap <| hUo.mem_nhds <| (hU _).2 rfl] with y hy
simpa [hU] using hy
@[simp 1100]
theorem continuous_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} :
Continuous (Sigma.map f₁ f₂) ↔ ∀ i, Continuous (f₂ i) :=
continuous_sigma_iff.trans <| by
simp only [Sigma.map, IsEmbedding.sigmaMk.continuous_iff, comp_def]
@[continuity, fun_prop]
theorem Continuous.sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (hf : ∀ i, Continuous (f₂ i)) :
Continuous (Sigma.map f₁ f₂) :=
continuous_sigma_map.2 hf
theorem isOpenMap_sigma {f : Sigma σ → X} : IsOpenMap f ↔ ∀ i, IsOpenMap fun a => f ⟨i, a⟩ := by
simp only [isOpenMap_iff_nhds_le, Sigma.forall, Sigma.nhds_eq, map_map, comp_def]
theorem isOpenMap_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} :
IsOpenMap (Sigma.map f₁ f₂) ↔ ∀ i, IsOpenMap (f₂ i) :=
isOpenMap_sigma.trans <|
forall_congr' fun i => (@IsOpenEmbedding.sigmaMk _ _ _ (f₁ i)).isOpenMap_iff.symm
lemma Topology.isInducing_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)}
(h₁ : Injective f₁) : IsInducing (Sigma.map f₁ f₂) ↔ ∀ i, IsInducing (f₂ i) := by
simp only [isInducing_iff_nhds, Sigma.forall, Sigma.nhds_mk, Sigma.map_mk,
← map_sigma_mk_comap h₁, map_inj sigma_mk_injective]
@[deprecated (since := "2024-10-28")] alias inducing_sigma_map := isInducing_sigmaMap
lemma Topology.isEmbedding_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)}
(h : Injective f₁) : IsEmbedding (Sigma.map f₁ f₂) ↔ ∀ i, IsEmbedding (f₂ i) := by
simp only [isEmbedding_iff, Injective.sigma_map, isInducing_sigmaMap h, forall_and,
h.sigma_map_iff]
@[deprecated (since := "2024-10-26")]
alias embedding_sigma_map := isEmbedding_sigmaMap
lemma Topology.isOpenEmbedding_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (h : Injective f₁) :
IsOpenEmbedding (Sigma.map f₁ f₂) ↔ ∀ i, IsOpenEmbedding (f₂ i) := by
simp only [isOpenEmbedding_iff_isEmbedding_isOpenMap, isOpenMap_sigma_map, isEmbedding_sigmaMap h,
forall_and]
@[deprecated (since := "2024-10-30")] alias isOpenEmbedding_sigma_map := isOpenEmbedding_sigmaMap
end Sigma
section ULift
theorem ULift.isOpen_iff [TopologicalSpace X] {s : Set (ULift.{v} X)} :
IsOpen s ↔ IsOpen (ULift.up ⁻¹' s) := by
rw [ULift.topologicalSpace, ← Equiv.ulift_apply, ← Equiv.ulift.coinduced_symm, ← isOpen_coinduced]
theorem ULift.isClosed_iff [TopologicalSpace X] {s : Set (ULift.{v} X)} :
IsClosed s ↔ IsClosed (ULift.up ⁻¹' s) := by
rw [← isOpen_compl_iff, ← isOpen_compl_iff, isOpen_iff, preimage_compl]
@[continuity, fun_prop]
theorem continuous_uliftDown [TopologicalSpace X] : Continuous (ULift.down : ULift.{v, u} X → X) :=
continuous_induced_dom
@[continuity, fun_prop]
theorem continuous_uliftUp [TopologicalSpace X] : Continuous (ULift.up : X → ULift.{v, u} X) :=
continuous_induced_rng.2 continuous_id
@[deprecated (since := "2025-02-10")] alias continuous_uLift_down := continuous_uliftDown
@[deprecated (since := "2025-02-10")] alias continuous_uLift_up := continuous_uliftUp
@[continuity, fun_prop]
theorem continuous_uliftMap [TopologicalSpace X] [TopologicalSpace Y]
(f : X → Y) (hf : Continuous f) :
Continuous (ULift.map f : ULift.{u'} X → ULift.{v'} Y) := by
change Continuous (ULift.up ∘ f ∘ ULift.down)
fun_prop
lemma Topology.IsEmbedding.uliftDown [TopologicalSpace X] :
IsEmbedding (ULift.down : ULift.{v, u} X → X) := ⟨⟨rfl⟩, ULift.down_injective⟩
@[deprecated (since := "2024-10-26")]
alias embedding_uLift_down := IsEmbedding.uliftDown
lemma Topology.IsClosedEmbedding.uliftDown [TopologicalSpace X] :
IsClosedEmbedding (ULift.down : ULift.{v, u} X → X) :=
⟨.uliftDown, by simp only [ULift.down_surjective.range_eq, isClosed_univ]⟩
@[deprecated (since := "2024-10-30")]
alias ULift.isClosedEmbedding_down := IsClosedEmbedding.uliftDown
instance [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (ULift X) :=
IsEmbedding.uliftDown.discreteTopology
end ULift
section Monad
variable [TopologicalSpace X] {s : Set X} {t : Set s}
theorem IsOpen.trans (ht : IsOpen t) (hs : IsOpen s) : IsOpen (t : Set X) := by
rcases isOpen_induced_iff.mp ht with ⟨s', hs', rfl⟩
rw [Subtype.image_preimage_coe]
exact hs.inter hs'
theorem IsClosed.trans (ht : IsClosed t) (hs : IsClosed s) : IsClosed (t : Set X) := by
rcases isClosed_induced_iff.mp ht with ⟨s', hs', rfl⟩
rw [Subtype.image_preimage_coe]
exact hs.inter hs'
end Monad
section NhdsSet
variable [TopologicalSpace X] [TopologicalSpace Y]
{s : Set X} {t : Set Y}
/-- The product of a neighborhood of `s` and a neighborhood of `t` is a neighborhood of `s ×ˢ t`,
formulated in terms of a filter inequality. -/
theorem nhdsSet_prod_le (s : Set X) (t : Set Y) : 𝓝ˢ (s ×ˢ t) ≤ 𝓝ˢ s ×ˢ 𝓝ˢ t :=
((hasBasis_nhdsSet _).prod (hasBasis_nhdsSet _)).ge_iff.2 fun (_u, _v) ⟨⟨huo, hsu⟩, hvo, htv⟩ ↦
(huo.prod hvo).mem_nhdsSet.2 <| prod_mono hsu htv
theorem Filter.eventually_nhdsSet_prod_iff {p : X × Y → Prop} :
(∀ᶠ q in 𝓝ˢ (s ×ˢ t), p q) ↔
∀ x ∈ s, ∀ y ∈ t,
∃ px : X → Prop, (∀ᶠ x' in 𝓝 x, px x') ∧ ∃ py : Y → Prop, (∀ᶠ y' in 𝓝 y, py y') ∧
∀ {x : X}, px x → ∀ {y : Y}, py y → p (x, y) := by
simp_rw [eventually_nhdsSet_iff_forall, forall_prod_set, nhds_prod_eq, eventually_prod_iff]
theorem Filter.Eventually.prod_nhdsSet {p : X × Y → Prop} {px : X → Prop} {py : Y → Prop}
(hp : ∀ {x : X}, px x → ∀ {y : Y}, py y → p (x, y)) (hs : ∀ᶠ x in 𝓝ˢ s, px x)
(ht : ∀ᶠ y in 𝓝ˢ t, py y) : ∀ᶠ q in 𝓝ˢ (s ×ˢ t), p q :=
nhdsSet_prod_le _ _ (mem_of_superset (prod_mem_prod hs ht) fun _ ⟨hx, hy⟩ ↦ hp hx hy)
end NhdsSet
| Mathlib/Topology/Constructions.lean | 1,371 | 1,374 | |
/-
Copyright (c) 2019 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Yury Kudryashov, Yaël Dillies
-/
import Mathlib.Algebra.Order.Invertible
import Mathlib.Algebra.Order.Module.OrderedSMul
import Mathlib.LinearAlgebra.AffineSpace.Midpoint
import Mathlib.LinearAlgebra.LinearIndependent.Lemmas
import Mathlib.LinearAlgebra.Ray
import Mathlib.Tactic.GCongr
/-!
# Segments in vector spaces
In a 𝕜-vector space, we define the following objects and properties.
* `segment 𝕜 x y`: Closed segment joining `x` and `y`.
* `openSegment 𝕜 x y`: Open segment joining `x` and `y`.
## Notations
We provide the following notation:
* `[x -[𝕜] y] = segment 𝕜 x y` in locale `Convex`
## TODO
Generalize all this file to affine spaces.
Should we rename `segment` and `openSegment` to `convex.Icc` and `convex.Ioo`? Should we also
define `clopenSegment`/`convex.Ico`/`convex.Ioc`?
-/
variable {𝕜 E F G ι : Type*} {M : ι → Type*}
open Function Set
open Pointwise Convex
section OrderedSemiring
variable [Semiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E]
section SMul
variable (𝕜) [SMul 𝕜 E] {s : Set E} {x y : E}
/-- Segments in a vector space. -/
def segment (x y : E) : Set E :=
{ z : E | ∃ a b : 𝕜, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a • x + b • y = z }
/-- Open segment in a vector space. Note that `openSegment 𝕜 x x = {x}` instead of being `∅` when
the base semiring has some element between `0` and `1`.
Denoted as `[x -[𝕜] y]` within the `Convex` namespace. -/
def openSegment (x y : E) : Set E :=
{ z : E | ∃ a b : 𝕜, 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a • x + b • y = z }
@[inherit_doc] scoped[Convex] notation (priority := high) "[" x " -[" 𝕜 "] " y "]" => segment 𝕜 x y
theorem segment_eq_image₂ (x y : E) :
[x -[𝕜] y] =
(fun p : 𝕜 × 𝕜 => p.1 • x + p.2 • y) '' { p | 0 ≤ p.1 ∧ 0 ≤ p.2 ∧ p.1 + p.2 = 1 } := by
simp only [segment, image, Prod.exists, mem_setOf_eq, exists_prop, and_assoc]
theorem openSegment_eq_image₂ (x y : E) :
openSegment 𝕜 x y =
(fun p : 𝕜 × 𝕜 => p.1 • x + p.2 • y) '' { p | 0 < p.1 ∧ 0 < p.2 ∧ p.1 + p.2 = 1 } := by
simp only [openSegment, image, Prod.exists, mem_setOf_eq, exists_prop, and_assoc]
theorem segment_symm (x y : E) : [x -[𝕜] y] = [y -[𝕜] x] :=
Set.ext fun _ =>
⟨fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩,
fun ⟨a, b, ha, hb, hab, H⟩ =>
⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩
theorem openSegment_symm (x y : E) : openSegment 𝕜 x y = openSegment 𝕜 y x :=
Set.ext fun _ =>
⟨fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩,
fun ⟨a, b, ha, hb, hab, H⟩ =>
⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩
theorem openSegment_subset_segment (x y : E) : openSegment 𝕜 x y ⊆ [x -[𝕜] y] :=
fun _ ⟨a, b, ha, hb, hab, hz⟩ => ⟨a, b, ha.le, hb.le, hab, hz⟩
theorem segment_subset_iff :
[x -[𝕜] y] ⊆ s ↔ ∀ a b : 𝕜, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s :=
⟨fun H a b ha hb hab => H ⟨a, b, ha, hb, hab, rfl⟩, fun H _ ⟨a, b, ha, hb, hab, hz⟩ =>
hz ▸ H a b ha hb hab⟩
theorem openSegment_subset_iff :
openSegment 𝕜 x y ⊆ s ↔ ∀ a b : 𝕜, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s :=
⟨fun H a b ha hb hab => H ⟨a, b, ha, hb, hab, rfl⟩, fun H _ ⟨a, b, ha, hb, hab, hz⟩ =>
hz ▸ H a b ha hb hab⟩
end SMul
open Convex
section MulActionWithZero
variable (𝕜)
variable [ZeroLEOneClass 𝕜] [MulActionWithZero 𝕜 E]
theorem left_mem_segment (x y : E) : x ∈ [x -[𝕜] y] :=
⟨1, 0, zero_le_one, le_refl 0, add_zero 1, by rw [zero_smul, one_smul, add_zero]⟩
theorem right_mem_segment (x y : E) : y ∈ [x -[𝕜] y] :=
segment_symm 𝕜 y x ▸ left_mem_segment 𝕜 y x
end MulActionWithZero
section Module
variable (𝕜)
variable [ZeroLEOneClass 𝕜] [Module 𝕜 E] {s : Set E} {x y z : E}
@[simp]
theorem segment_same (x : E) : [x -[𝕜] x] = {x} :=
Set.ext fun z =>
⟨fun ⟨a, b, _, _, hab, hz⟩ => by
simpa only [(add_smul _ _ _).symm, mem_singleton_iff, hab, one_smul, eq_comm] using hz,
fun h => mem_singleton_iff.1 h ▸ left_mem_segment 𝕜 z z⟩
theorem insert_endpoints_openSegment (x y : E) :
insert x (insert y (openSegment 𝕜 x y)) = [x -[𝕜] y] := by
simp only [subset_antisymm_iff, insert_subset_iff, left_mem_segment, right_mem_segment,
openSegment_subset_segment, true_and]
rintro z ⟨a, b, ha, hb, hab, rfl⟩
refine hb.eq_or_gt.imp ?_ fun hb' => ha.eq_or_gt.imp ?_ fun ha' => ?_
· rintro rfl
rw [← add_zero a, hab, one_smul, zero_smul, add_zero]
· rintro rfl
rw [← zero_add b, hab, one_smul, zero_smul, zero_add]
· exact ⟨a, b, ha', hb', hab, rfl⟩
variable {𝕜}
theorem mem_openSegment_of_ne_left_right (hx : x ≠ z) (hy : y ≠ z) (hz : z ∈ [x -[𝕜] y]) :
z ∈ openSegment 𝕜 x y := by
rw [← insert_endpoints_openSegment] at hz
exact (hz.resolve_left hx.symm).resolve_left hy.symm
theorem openSegment_subset_iff_segment_subset (hx : x ∈ s) (hy : y ∈ s) :
openSegment 𝕜 x y ⊆ s ↔ [x -[𝕜] y] ⊆ s := by
simp only [← insert_endpoints_openSegment, insert_subset_iff, *, true_and]
end Module
end OrderedSemiring
open Convex
section OrderedRing
variable (𝕜) [Ring 𝕜] [PartialOrder 𝕜] [AddRightMono 𝕜]
[AddCommGroup E] [AddCommGroup F] [AddCommGroup G] [Module 𝕜 E] [Module 𝕜 F]
section DenselyOrdered
variable [ZeroLEOneClass 𝕜] [Nontrivial 𝕜] [DenselyOrdered 𝕜]
@[simp]
theorem openSegment_same (x : E) : openSegment 𝕜 x x = {x} :=
Set.ext fun z =>
⟨fun ⟨a, b, _, _, hab, hz⟩ => by
simpa only [← add_smul, mem_singleton_iff, hab, one_smul, eq_comm] using hz,
fun h : z = x => by
obtain ⟨a, ha₀, ha₁⟩ := DenselyOrdered.dense (0 : 𝕜) 1 zero_lt_one
refine ⟨a, 1 - a, ha₀, sub_pos_of_lt ha₁, add_sub_cancel _ _, ?_⟩
rw [← add_smul, add_sub_cancel, one_smul, h]⟩
end DenselyOrdered
theorem segment_eq_image (x y : E) :
[x -[𝕜] y] = (fun θ : 𝕜 => (1 - θ) • x + θ • y) '' Icc (0 : 𝕜) 1 :=
Set.ext fun _ =>
⟨fun ⟨a, b, ha, hb, hab, hz⟩ =>
⟨b, ⟨hb, hab ▸ le_add_of_nonneg_left ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel_right]⟩,
fun ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩ => ⟨1 - θ, θ, sub_nonneg.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩
theorem openSegment_eq_image (x y : E) :
openSegment 𝕜 x y = (fun θ : 𝕜 => (1 - θ) • x + θ • y) '' Ioo (0 : 𝕜) 1 :=
Set.ext fun _ =>
⟨fun ⟨a, b, ha, hb, hab, hz⟩ =>
⟨b, ⟨hb, hab ▸ lt_add_of_pos_left _ ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel_right]⟩,
fun ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩ => ⟨1 - θ, θ, sub_pos.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩
theorem segment_eq_image' (x y : E) :
[x -[𝕜] y] = (fun θ : 𝕜 => x + θ • (y - x)) '' Icc (0 : 𝕜) 1 := by
convert segment_eq_image 𝕜 x y using 2
simp only [smul_sub, sub_smul, one_smul]
abel
theorem openSegment_eq_image' (x y : E) :
openSegment 𝕜 x y = (fun θ : 𝕜 => x + θ • (y - x)) '' Ioo (0 : 𝕜) 1 := by
convert openSegment_eq_image 𝕜 x y using 2
simp only [smul_sub, sub_smul, one_smul]
abel
theorem segment_eq_image_lineMap (x y : E) : [x -[𝕜] y] =
AffineMap.lineMap x y '' Icc (0 : 𝕜) 1 := by
convert segment_eq_image 𝕜 x y using 2
exact AffineMap.lineMap_apply_module _ _ _
theorem openSegment_eq_image_lineMap (x y : E) :
openSegment 𝕜 x y = AffineMap.lineMap x y '' Ioo (0 : 𝕜) 1 := by
convert openSegment_eq_image 𝕜 x y using 2
exact AffineMap.lineMap_apply_module _ _ _
@[simp]
theorem image_segment (f : E →ᵃ[𝕜] F) (a b : E) : f '' [a -[𝕜] b] = [f a -[𝕜] f b] :=
Set.ext fun x => by
simp_rw [segment_eq_image_lineMap, mem_image, exists_exists_and_eq_and, AffineMap.apply_lineMap]
@[simp]
theorem image_openSegment (f : E →ᵃ[𝕜] F) (a b : E) :
f '' openSegment 𝕜 a b = openSegment 𝕜 (f a) (f b) :=
Set.ext fun x => by
simp_rw [openSegment_eq_image_lineMap, mem_image, exists_exists_and_eq_and,
AffineMap.apply_lineMap]
@[simp]
theorem vadd_segment [AddTorsor G E] [VAddCommClass G E E] (a : G) (b c : E) :
a +ᵥ [b -[𝕜] c] = [a +ᵥ b -[𝕜] a +ᵥ c] :=
image_segment 𝕜 ⟨_, LinearMap.id, fun _ _ => vadd_comm _ _ _⟩ b c
@[simp]
theorem vadd_openSegment [AddTorsor G E] [VAddCommClass G E E] (a : G) (b c : E) :
a +ᵥ openSegment 𝕜 b c = openSegment 𝕜 (a +ᵥ b) (a +ᵥ c) :=
image_openSegment 𝕜 ⟨_, LinearMap.id, fun _ _ => vadd_comm _ _ _⟩ b c
@[simp]
theorem mem_segment_translate (a : E) {x b c} : a + x ∈ [a + b -[𝕜] a + c] ↔ x ∈ [b -[𝕜] c] := by
simp_rw [← vadd_eq_add, ← vadd_segment, vadd_mem_vadd_set_iff]
@[simp]
theorem mem_openSegment_translate (a : E) {x b c : E} :
a + x ∈ openSegment 𝕜 (a + b) (a + c) ↔ x ∈ openSegment 𝕜 b c := by
simp_rw [← vadd_eq_add, ← vadd_openSegment, vadd_mem_vadd_set_iff]
theorem segment_translate_preimage (a b c : E) :
(fun x => a + x) ⁻¹' [a + b -[𝕜] a + c] = [b -[𝕜] c] :=
Set.ext fun _ => mem_segment_translate 𝕜 a
theorem openSegment_translate_preimage (a b c : E) :
(fun x => a + x) ⁻¹' openSegment 𝕜 (a + b) (a + c) = openSegment 𝕜 b c :=
Set.ext fun _ => mem_openSegment_translate 𝕜 a
theorem segment_translate_image (a b c : E) : (fun x => a + x) '' [b -[𝕜] c] = [a + b -[𝕜] a + c] :=
segment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ <| add_left_surjective a
theorem openSegment_translate_image (a b c : E) :
(fun x => a + x) '' openSegment 𝕜 b c = openSegment 𝕜 (a + b) (a + c) :=
openSegment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ <| add_left_surjective a
lemma segment_inter_subset_endpoint_of_linearIndependent_sub
{c x y : E} (h : LinearIndependent 𝕜 ![x - c, y - c]) :
[c -[𝕜] x] ∩ [c -[𝕜] y] ⊆ {c} := by
intro z ⟨hzt, hzs⟩
rw [segment_eq_image, mem_image] at hzt hzs
rcases hzt with ⟨p, ⟨p0, p1⟩, rfl⟩
rcases hzs with ⟨q, ⟨q0, q1⟩, H⟩
have Hx : x = (x - c) + c := by abel
have Hy : y = (y - c) + c := by abel
rw [Hx, Hy, smul_add, smul_add] at H
have : c + q • (y - c) = c + p • (x - c) := by
convert H using 1 <;> simp [sub_smul]
obtain ⟨rfl, rfl⟩ : p = 0 ∧ q = 0 := h.eq_zero_of_pair' ((add_right_inj c).1 this).symm
simp
lemma segment_inter_eq_endpoint_of_linearIndependent_sub [ZeroLEOneClass 𝕜]
{c x y : E} (h : LinearIndependent 𝕜 ![x - c, y - c]) :
[c -[𝕜] x] ∩ [c -[𝕜] y] = {c} := by
refine (segment_inter_subset_endpoint_of_linearIndependent_sub 𝕜 h).antisymm ?_
simp [singleton_subset_iff, left_mem_segment]
end OrderedRing
theorem sameRay_of_mem_segment [CommRing 𝕜] [PartialOrder 𝕜] [IsStrictOrderedRing 𝕜]
[AddCommGroup E] [Module 𝕜 E] {x y z : E}
(h : x ∈ [y -[𝕜] z]) : SameRay 𝕜 (x - y) (z - x) := by
rw [segment_eq_image'] at h
rcases h with ⟨θ, ⟨hθ₀, hθ₁⟩, rfl⟩
simpa only [add_sub_cancel_left, ← sub_sub, sub_smul, one_smul] using
(SameRay.sameRay_nonneg_smul_left (z - y) hθ₀).nonneg_smul_right (sub_nonneg.2 hθ₁)
lemma segment_inter_eq_endpoint_of_linearIndependent_of_ne
[CommRing 𝕜] [PartialOrder 𝕜] [IsOrderedRing 𝕜] [NoZeroDivisors 𝕜]
[AddCommGroup E] [Module 𝕜 E]
{x y : E} (h : LinearIndependent 𝕜 ![x, y]) {s t : 𝕜} (hs : s ≠ t) (c : E) :
[c + x -[𝕜] c + t • y] ∩ [c + x -[𝕜] c + s • y] = {c + x} := by
apply segment_inter_eq_endpoint_of_linearIndependent_sub
simp only [add_sub_add_left_eq_sub]
suffices H : LinearIndependent 𝕜 ![(-1 : 𝕜) • x + t • y, (-1 : 𝕜) • x + s • y] by
convert H using 1; simp only [neg_smul, one_smul]; abel_nf
nontriviality 𝕜
rw [LinearIndependent.pair_add_smul_add_smul_iff]
aesop
section LinearOrderedRing
variable [Ring 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y : E}
theorem midpoint_mem_segment [Invertible (2 : 𝕜)] (x y : E) : midpoint 𝕜 x y ∈ [x -[𝕜] y] := by
rw [segment_eq_image_lineMap]
exact ⟨⅟ 2, ⟨invOf_nonneg.mpr zero_le_two, invOf_le_one one_le_two⟩, rfl⟩
theorem mem_segment_sub_add [Invertible (2 : 𝕜)] (x y : E) : x ∈ [x - y -[𝕜] x + y] := by
convert midpoint_mem_segment (𝕜 := 𝕜) (x - y) (x + y)
rw [midpoint_sub_add]
theorem mem_segment_add_sub [Invertible (2 : 𝕜)] (x y : E) : x ∈ [x + y -[𝕜] x - y] := by
convert midpoint_mem_segment (𝕜 := 𝕜) (x + y) (x - y)
rw [midpoint_add_sub]
@[simp]
theorem left_mem_openSegment_iff [DenselyOrdered 𝕜] [NoZeroSMulDivisors 𝕜 E] :
x ∈ openSegment 𝕜 x y ↔ x = y := by
constructor
· rintro ⟨a, b, _, hb, hab, hx⟩
refine smul_right_injective _ hb.ne' ((add_right_inj (a • x)).1 ?_)
rw [hx, ← add_smul, hab, one_smul]
· rintro rfl
rw [openSegment_same]
exact mem_singleton _
@[simp]
theorem right_mem_openSegment_iff [DenselyOrdered 𝕜] [NoZeroSMulDivisors 𝕜 E] :
y ∈ openSegment 𝕜 x y ↔ x = y := by rw [openSegment_symm, left_mem_openSegment_iff, eq_comm]
end LinearOrderedRing
section LinearOrderedSemifield
variable [Semifield 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E]
{x y z : E}
theorem mem_segment_iff_div :
x ∈ [y -[𝕜] z] ↔
∃ a b : 𝕜, 0 ≤ a ∧ 0 ≤ b ∧ 0 < a + b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x := by
constructor
· rintro ⟨a, b, ha, hb, hab, rfl⟩
use a, b, ha, hb
simp [*]
· rintro ⟨a, b, ha, hb, hab, rfl⟩
refine ⟨a / (a + b), b / (a + b), by positivity, by positivity, ?_, rfl⟩
rw [← add_div, div_self hab.ne']
theorem mem_openSegment_iff_div : x ∈ openSegment 𝕜 y z ↔
∃ a b : 𝕜, 0 < a ∧ 0 < b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x := by
constructor
· rintro ⟨a, b, ha, hb, hab, rfl⟩
use a, b, ha, hb
rw [hab, div_one, div_one]
· rintro ⟨a, b, ha, hb, rfl⟩
have hab : 0 < a + b := add_pos' ha hb
refine ⟨a / (a + b), b / (a + b), by positivity, by positivity, ?_, rfl⟩
rw [← add_div, div_self hab.ne']
end LinearOrderedSemifield
section LinearOrderedField
variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y z : E}
theorem mem_segment_iff_sameRay : x ∈ [y -[𝕜] z] ↔ SameRay 𝕜 (x - y) (z - x) := by
refine ⟨sameRay_of_mem_segment, fun h => ?_⟩
rcases h.exists_eq_smul_add with ⟨a, b, ha, hb, hab, hxy, hzx⟩
rw [add_comm, sub_add_sub_cancel] at hxy hzx
rw [← mem_segment_translate _ (-x), neg_add_cancel]
refine ⟨b, a, hb, ha, add_comm a b ▸ hab, ?_⟩
rw [← sub_eq_neg_add, ← neg_sub, hxy, ← sub_eq_neg_add, hzx, smul_neg, smul_comm, neg_add_cancel]
open AffineMap
/-- If `z = lineMap x y c` is a point on the line passing through `x` and `y`, then the open
segment `openSegment 𝕜 x y` is included in the union of the open segments `openSegment 𝕜 x z`,
`openSegment 𝕜 z y`, and the point `z`. Informally, `(x, y) ⊆ {z} ∪ (x, z) ∪ (z, y)`. -/
theorem openSegment_subset_union (x y : E) {z : E} (hz : z ∈ range (lineMap x y : 𝕜 → E)) :
openSegment 𝕜 x y ⊆ insert z (openSegment 𝕜 x z ∪ openSegment 𝕜 z y) := by
rcases hz with ⟨c, rfl⟩
simp only [openSegment_eq_image_lineMap, ← mapsTo']
rintro a ⟨h₀, h₁⟩
rcases lt_trichotomy a c with (hac | rfl | hca)
· right
left
have hc : 0 < c := h₀.trans hac
refine ⟨a / c, ⟨div_pos h₀ hc, (div_lt_one hc).2 hac⟩, ?_⟩
simp only [← homothety_eq_lineMap, ← homothety_mul_apply, div_mul_cancel₀ _ hc.ne']
· left
rfl
· right
right
have hc : 0 < 1 - c := sub_pos.2 (hca.trans h₁)
simp only [← lineMap_apply_one_sub y]
refine
⟨(a - c) / (1 - c), ⟨div_pos (sub_pos.2 hca) hc, (div_lt_one hc).2 <| sub_lt_sub_right h₁ _⟩,
?_⟩
simp only [← homothety_eq_lineMap, ← homothety_mul_apply, sub_mul, one_mul,
div_mul_cancel₀ _ hc.ne', sub_sub_sub_cancel_right]
end LinearOrderedField
/-!
#### Segments in an ordered space
Relates `segment`, `openSegment` and `Set.Icc`, `Set.Ico`, `Set.Ioc`, `Set.Ioo`
-/
section OrderedSemiring
variable [Semiring 𝕜] [PartialOrder 𝕜]
section OrderedAddCommMonoid
variable [AddCommMonoid E] [PartialOrder E] [IsOrderedAddMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E]
{x y : E}
theorem segment_subset_Icc (h : x ≤ y) : [x -[𝕜] y] ⊆ Icc x y := by
rintro z ⟨a, b, ha, hb, hab, rfl⟩
constructor
· calc
x = a • x + b • x := (Convex.combo_self hab _).symm
_ ≤ a • x + b • y := by gcongr
· calc
a • x + b • y ≤ a • y + b • y := by gcongr
_ = y := Convex.combo_self hab _
end OrderedAddCommMonoid
section OrderedCancelAddCommMonoid
variable [AddCommMonoid E] [PartialOrder E] [IsOrderedCancelAddMonoid E]
[Module 𝕜 E] [OrderedSMul 𝕜 E] {x y : E}
theorem openSegment_subset_Ioo (h : x < y) : openSegment 𝕜 x y ⊆ Ioo x y := by
rintro z ⟨a, b, ha, hb, hab, rfl⟩
constructor
· calc
x = a • x + b • x := (Convex.combo_self hab _).symm
_ < a • x + b • y := by gcongr
· calc
a • x + b • y < a • y + b • y := by gcongr
_ = y := Convex.combo_self hab _
end OrderedCancelAddCommMonoid
section LinearOrderedAddCommMonoid
variable [AddCommMonoid E] [LinearOrder E] [IsOrderedAddMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E]
{a b : 𝕜}
theorem segment_subset_uIcc (x y : E) : [x -[𝕜] y] ⊆ uIcc x y := by
rcases le_total x y with h | h
· rw [uIcc_of_le h]
exact segment_subset_Icc h
· rw [uIcc_of_ge h, segment_symm]
exact segment_subset_Icc h
theorem Convex.min_le_combo (x y : E) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :
min x y ≤ a • x + b • y :=
(segment_subset_uIcc x y ⟨_, _, ha, hb, hab, rfl⟩).1
theorem Convex.combo_le_max (x y : E) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :
a • x + b • y ≤ max x y :=
(segment_subset_uIcc x y ⟨_, _, ha, hb, hab, rfl⟩).2
end LinearOrderedAddCommMonoid
end OrderedSemiring
section LinearOrderedField
variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] {x y z : 𝕜}
theorem Icc_subset_segment : Icc x y ⊆ [x -[𝕜] y] := by
rintro z ⟨hxz, hyz⟩
obtain rfl | h := (hxz.trans hyz).eq_or_lt
· rw [segment_same]
exact hyz.antisymm hxz
rw [← sub_nonneg] at hxz hyz
rw [← sub_pos] at h
refine ⟨(y - z) / (y - x), (z - x) / (y - x), div_nonneg hyz h.le, div_nonneg hxz h.le, ?_, ?_⟩
· rw [← add_div, sub_add_sub_cancel, div_self h.ne']
· rw [smul_eq_mul, smul_eq_mul, ← mul_div_right_comm, ← mul_div_right_comm, ← add_div,
div_eq_iff h.ne', add_comm, sub_mul, sub_mul, mul_comm x, sub_add_sub_cancel, mul_sub]
@[simp]
theorem segment_eq_Icc (h : x ≤ y) : [x -[𝕜] y] = Icc x y :=
(segment_subset_Icc h).antisymm Icc_subset_segment
theorem Ioo_subset_openSegment : Ioo x y ⊆ openSegment 𝕜 x y := fun _ hz =>
mem_openSegment_of_ne_left_right hz.1.ne hz.2.ne' <| Icc_subset_segment <| Ioo_subset_Icc_self hz
@[simp]
theorem openSegment_eq_Ioo (h : x < y) : openSegment 𝕜 x y = Ioo x y :=
(openSegment_subset_Ioo h).antisymm Ioo_subset_openSegment
theorem segment_eq_Icc' (x y : 𝕜) : [x -[𝕜] y] = Icc (min x y) (max x y) := by
rcases le_total x y with h | h
· rw [segment_eq_Icc h, max_eq_right h, min_eq_left h]
· rw [segment_symm, segment_eq_Icc h, max_eq_left h, min_eq_right h]
theorem openSegment_eq_Ioo' (hxy : x ≠ y) : openSegment 𝕜 x y = Ioo (min x y) (max x y) := by
rcases hxy.lt_or_lt with h | h
· rw [openSegment_eq_Ioo h, max_eq_right h.le, min_eq_left h.le]
· rw [openSegment_symm, openSegment_eq_Ioo h, max_eq_left h.le, min_eq_right h.le]
theorem segment_eq_uIcc (x y : 𝕜) : [x -[𝕜] y] = uIcc x y :=
segment_eq_Icc' _ _
/-- A point is in an `Icc` iff it can be expressed as a convex combination of the endpoints. -/
theorem Convex.mem_Icc (h : x ≤ y) :
z ∈ Icc x y ↔ ∃ a b, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z := by
simp only [← segment_eq_Icc h, segment, mem_setOf_eq, smul_eq_mul, exists_and_left]
/-- A point is in an `Ioo` iff it can be expressed as a strict convex combination of the endpoints.
-/
theorem Convex.mem_Ioo (h : x < y) :
z ∈ Ioo x y ↔ ∃ a b, 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z := by
simp only [← openSegment_eq_Ioo h, openSegment, smul_eq_mul, exists_and_left, mem_setOf_eq]
/-- A point is in an `Ioc` iff it can be expressed as a semistrict convex combination of the
endpoints. -/
theorem Convex.mem_Ioc (h : x < y) :
z ∈ Ioc x y ↔ ∃ a b, 0 ≤ a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z := by
refine ⟨fun hz => ?_, ?_⟩
· obtain ⟨a, b, ha, hb, hab, rfl⟩ := (Convex.mem_Icc h.le).1 (Ioc_subset_Icc_self hz)
obtain rfl | hb' := hb.eq_or_lt
· rw [add_zero] at hab
rw [hab, one_mul, zero_mul, add_zero] at hz
exact (hz.1.ne rfl).elim
· exact ⟨a, b, ha, hb', hab, rfl⟩
· rintro ⟨a, b, ha, hb, hab, rfl⟩
obtain rfl | ha' := ha.eq_or_lt
· rw [zero_add] at hab
rwa [hab, one_mul, zero_mul, zero_add, right_mem_Ioc]
· exact Ioo_subset_Ioc_self ((Convex.mem_Ioo h).2 ⟨a, b, ha', hb, hab, rfl⟩)
/-- A point is in an `Ico` iff it can be expressed as a semistrict convex combination of the
endpoints. -/
theorem Convex.mem_Ico (h : x < y) :
| z ∈ Ico x y ↔ ∃ a b, 0 < a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z := by
refine ⟨fun hz => ?_, ?_⟩
· obtain ⟨a, b, ha, hb, hab, rfl⟩ := (Convex.mem_Icc h.le).1 (Ico_subset_Icc_self hz)
obtain rfl | ha' := ha.eq_or_lt
| Mathlib/Analysis/Convex/Segment.lean | 544 | 547 |
/-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Order.ToIntervalMod
import Mathlib.Algebra.Ring.AddAut
import Mathlib.Data.Nat.Totient
import Mathlib.GroupTheory.Divisible
import Mathlib.Topology.Connected.PathConnected
import Mathlib.Topology.IsLocalHomeomorph
import Mathlib.Topology.Instances.ZMultiples
/-!
# The additive circle
We define the additive circle `AddCircle p` as the quotient `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜`.
See also `Circle` and `Real.angle`. For the normed group structure on `AddCircle`, see
`AddCircle.NormedAddCommGroup` in a later file.
## Main definitions and results:
* `AddCircle`: the additive circle `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜`
* `UnitAddCircle`: the special case `ℝ ⧸ ℤ`
* `AddCircle.equivAddCircle`: the rescaling equivalence `AddCircle p ≃+ AddCircle q`
* `AddCircle.equivIco`: the natural equivalence `AddCircle p ≃ Ico a (a + p)`
* `AddCircle.addOrderOf_div_of_gcd_eq_one`: rational points have finite order
* `AddCircle.exists_gcd_eq_one_of_isOfFinAddOrder`: finite-order points are rational
* `AddCircle.homeoIccQuot`: the natural topological equivalence between `AddCircle p` and
`Icc a (a + p)` with its endpoints identified.
* `AddCircle.liftIco_continuous`: if `f : ℝ → B` is continuous, and `f a = f (a + p)` for
some `a`, then there is a continuous function `AddCircle p → B` which agrees with `f` on
`Icc a (a + p)`.
## Implementation notes:
Although the most important case is `𝕜 = ℝ` we wish to support other types of scalars, such as
the rational circle `AddCircle (1 : ℚ)`, and so we set things up more generally.
## TODO
* Link with periodicity
* Lie group structure
* Exponential equivalence to `Circle`
-/
noncomputable section
open AddCommGroup Set Function AddSubgroup TopologicalSpace
open Topology
variable {𝕜 B : Type*}
section Continuity
variable [AddCommGroup 𝕜] [LinearOrder 𝕜] [IsOrderedAddMonoid 𝕜] [Archimedean 𝕜]
[TopologicalSpace 𝕜] [OrderTopology 𝕜]
{p : 𝕜} (hp : 0 < p) (a x : 𝕜)
| theorem continuous_right_toIcoMod : ContinuousWithinAt (toIcoMod hp a) (Ici x) x := by
intro s h
rw [Filter.mem_map, mem_nhdsWithin_iff_exists_mem_nhds_inter]
haveI : Nontrivial 𝕜 := ⟨⟨0, p, hp.ne⟩⟩
simp_rw [mem_nhds_iff_exists_Ioo_subset] at h ⊢
obtain ⟨l, u, hxI, hIs⟩ := h
let d := toIcoDiv hp a x • p
have hd := toIcoMod_mem_Ico hp a x
simp_rw [subset_def, mem_inter_iff]
refine ⟨_, ⟨l + d, min (a + p) u + d, ?_, fun x => id⟩, fun y => ?_⟩ <;>
simp_rw [← sub_mem_Ioo_iff_left, mem_Ioo, lt_min_iff]
· exact ⟨hxI.1, hd.2, hxI.2⟩
· rintro ⟨h, h'⟩
apply hIs
rw [← toIcoMod_sub_zsmul, (toIcoMod_eq_self _).2]
exacts [⟨h.1, h.2.2⟩, ⟨hd.1.trans (sub_le_sub_right h' _), h.2.1⟩]
| Mathlib/Topology/Instances/AddCircle.lean | 64 | 79 |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Functor.Const
import Mathlib.Order.Fin.Basic
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.SuppressCompilation
/-!
# Composable arrows
If `C` is a category, the type of `n`-simplices in the nerve of `C` identifies
to the type of functors `Fin (n + 1) ⥤ C`, which can be thought as families of `n` composable
arrows in `C`. In this file, we introduce and study this category `ComposableArrows C n`
of `n` composable arrows in `C`.
If `F : ComposableArrows C n`, we define `F.left` as the leftmost object, `F.right` as the
rightmost object, and `F.hom : F.left ⟶ F.right` is the canonical map.
The most significant definition in this file is the constructor
`F.precomp f : ComposableArrows C (n + 1)` for `F : ComposableArrows C n` and `f : X ⟶ F.left`:
"it shifts `F` towards the right and inserts `f` on the left". This `precomp` has
good definitional properties.
In the namespace `CategoryTheory.ComposableArrows`, we provide constructors
like `mk₁ f`, `mk₂ f g`, `mk₃ f g h` for `ComposableArrows C n` for small `n`.
TODO (@joelriou):
* redefine `Arrow C` as `ComposableArrow C 1`?
* construct some elements in `ComposableArrows m (Fin (n + 1))` for small `n`
the precomposition with which shall induce functors
`ComposableArrows C n ⥤ ComposableArrows C m` which correspond to simplicial operations
(specifically faces) with good definitional properties (this might be necessary for
up to `n = 7` in order to formalize spectral sequences following Verdier)
-/
/-!
New `simprocs` that run even in `dsimp` have caused breakages in this file.
(e.g. `dsimp` can now simplify `2 + 3` to `5`)
For now, we just turn off simprocs in this file.
We'll soon provide finer grained options here, e.g. to turn off simprocs only in `dsimp`, etc.
*However*, hopefully it is possible to refactor the material here so that no backwards compatibility
`set_option`s are required at all
-/
set_option simprocs false
namespace CategoryTheory
open Category
variable (C : Type*) [Category C]
/-- `ComposableArrows C n` is the type of functors `Fin (n + 1) ⥤ C`. -/
abbrev ComposableArrows (n : ℕ) := Fin (n + 1) ⥤ C
namespace ComposableArrows
variable {C} {n m : ℕ}
variable (F G : ComposableArrows C n)
/-- A wrapper for `omega` which prefaces it with some quick and useful attempts -/
macro "valid" : tactic =>
`(tactic| first | assumption | apply zero_le | apply le_rfl | transitivity <;> assumption | omega)
/-- The `i`th object (with `i : ℕ` such that `i ≤ n`) of `F : ComposableArrows C n`. -/
@[simp]
abbrev obj' (i : ℕ) (hi : i ≤ n := by valid) : C := F.obj ⟨i, by omega⟩
/-- The map `F.obj' i ⟶ F.obj' j` when `F : ComposableArrows C n`, and `i` and `j`
are natural numbers such that `i ≤ j ≤ n`. -/
@[simp]
abbrev map' (i j : ℕ) (hij : i ≤ j := by valid) (hjn : j ≤ n := by valid) :
F.obj ⟨i, by omega⟩ ⟶ F.obj ⟨j, by omega⟩ := F.map (homOfLE (by
simp only [Fin.mk_le_mk]
valid))
lemma map'_self (i : ℕ) (hi : i ≤ n := by valid) :
F.map' i i = 𝟙 _ := F.map_id _
lemma map'_comp (i j k : ℕ) (hij : i ≤ j := by valid)
(hjk : j ≤ k := by valid) (hk : k ≤ n := by valid) :
F.map' i k = F.map' i j ≫ F.map' j k :=
F.map_comp _ _
/-- The leftmost object of `F : ComposableArrows C n`. -/
abbrev left := obj' F 0
/-- The rightmost object of `F : ComposableArrows C n`. -/
abbrev right := obj' F n
/-- The canonical map `F.left ⟶ F.right` for `F : ComposableArrows C n`. -/
abbrev hom : F.left ⟶ F.right := map' F 0 n
variable {F G}
/-- The map `F.obj' i ⟶ G.obj' i` induced on `i`th objects by a morphism `F ⟶ G`
in `ComposableArrows C n` when `i` is a natural number such that `i ≤ n`. -/
@[simp]
abbrev app' (φ : F ⟶ G) (i : ℕ) (hi : i ≤ n := by valid) :
F.obj' i ⟶ G.obj' i := φ.app _
@[reassoc]
lemma naturality' (φ : F ⟶ G) (i j : ℕ) (hij : i ≤ j := by valid)
(hj : j ≤ n := by valid) :
F.map' i j ≫ app' φ j = app' φ i ≫ G.map' i j :=
φ.naturality _
/-- Constructor for `ComposableArrows C 0`. -/
@[simps!]
def mk₀ (X : C) : ComposableArrows C 0 := (Functor.const (Fin 1)).obj X
namespace Mk₁
variable (X₀ X₁ : C)
/-- The map which sends `0 : Fin 2` to `X₀` and `1` to `X₁`. -/
@[simp]
def obj : Fin 2 → C
| ⟨0, _⟩ => X₀
| ⟨1, _⟩ => X₁
variable {X₀ X₁}
variable (f : X₀ ⟶ X₁)
/-- The obvious map `obj X₀ X₁ i ⟶ obj X₀ X₁ j` whenever `i j : Fin 2` satisfy `i ≤ j`. -/
@[simp]
def map : ∀ (i j : Fin 2) (_ : i ≤ j), obj X₀ X₁ i ⟶ obj X₀ X₁ j
| ⟨0, _⟩, ⟨0, _⟩, _ => 𝟙 _
| ⟨0, _⟩, ⟨1, _⟩, _ => f
| ⟨1, _⟩, ⟨1, _⟩, _ => 𝟙 _
lemma map_id (i : Fin 2) : map f i i (by simp) = 𝟙 _ :=
match i with
| 0 => rfl
| 1 => rfl
lemma map_comp {i j k : Fin 2} (hij : i ≤ j) (hjk : j ≤ k) :
map f i k (hij.trans hjk) = map f i j hij ≫ map f j k hjk := by
obtain rfl | rfl : i = j ∨ j = k := by omega
· rw [map_id, id_comp]
· rw [map_id, comp_id]
end Mk₁
/-- Constructor for `ComposableArrows C 1`. -/
@[simps]
def mk₁ {X₀ X₁ : C} (f : X₀ ⟶ X₁) : ComposableArrows C 1 where
obj := Mk₁.obj X₀ X₁
map g := Mk₁.map f _ _ (leOfHom g)
map_id := Mk₁.map_id f
map_comp g g' := Mk₁.map_comp f (leOfHom g) (leOfHom g')
/-- Constructor for morphisms `F ⟶ G` in `ComposableArrows C n` which takes as inputs
a family of morphisms `F.obj i ⟶ G.obj i` and the naturality condition only for the
maps in `Fin (n + 1)` given by inequalities of the form `i ≤ i + 1`. -/
@[simps]
def homMk {F G : ComposableArrows C n} (app : ∀ i, F.obj i ⟶ G.obj i)
(w : ∀ (i : ℕ) (hi : i < n), F.map' i (i + 1) ≫ app _ = app _ ≫ G.map' i (i + 1)) :
F ⟶ G where
app := app
naturality := by
suffices ∀ (k i j : ℕ) (hj : i + k = j) (hj' : j ≤ n),
F.map' i j ≫ app _ = app _ ≫ G.map' i j by
rintro ⟨i, hi⟩ ⟨j, hj⟩ hij
have hij' := leOfHom hij
simp only [Fin.mk_le_mk] at hij'
obtain ⟨k, hk⟩ := Nat.le.dest hij'
exact this k i j hk (by valid)
intro k
induction' k with k hk
· intro i j hj hj'
simp only [add_zero] at hj
obtain rfl := hj
rw [F.map'_self i, G.map'_self i, id_comp, comp_id]
· intro i j hj hj'
rw [← add_assoc] at hj
subst hj
rw [F.map'_comp i (i + k) (i + k + 1), G.map'_comp i (i + k) (i + k + 1), assoc,
w (i + k) (by valid), reassoc_of% (hk i (i + k) rfl (by valid))]
/-- Constructor for isomorphisms `F ≅ G` in `ComposableArrows C n` which takes as inputs
a family of isomorphisms `F.obj i ≅ G.obj i` and the naturality condition only for the
maps in `Fin (n + 1)` given by inequalities of the form `i ≤ i + 1`. -/
@[simps]
def isoMk {F G : ComposableArrows C n} (app : ∀ i, F.obj i ≅ G.obj i)
(w : ∀ (i : ℕ) (hi : i < n),
F.map' i (i + 1) ≫ (app _).hom = (app _).hom ≫ G.map' i (i + 1)) :
F ≅ G where
hom := homMk (fun i => (app i).hom) w
inv := homMk (fun i => (app i).inv) (fun i hi => by
dsimp only
rw [← cancel_epi ((app _).hom), ← reassoc_of% (w i hi), Iso.hom_inv_id, comp_id,
Iso.hom_inv_id_assoc])
lemma ext {F G : ComposableArrows C n} (h : ∀ i, F.obj i = G.obj i)
(w : ∀ (i : ℕ) (hi : i < n), F.map' i (i + 1) =
eqToHom (h _) ≫ G.map' i (i + 1) ≫ eqToHom (h _).symm) : F = G :=
Functor.ext_of_iso
(isoMk (fun i => eqToIso (h i)) (fun i hi => by simp [w i hi])) h (fun _ => rfl)
/-- Constructor for morphisms in `ComposableArrows C 0`. -/
@[simps!]
def homMk₀ {F G : ComposableArrows C 0} (f : F.obj' 0 ⟶ G.obj' 0) : F ⟶ G :=
homMk (fun i => match i with
| ⟨0, _⟩ => f) (fun i hi => by simp at hi)
@[ext]
lemma hom_ext₀ {F G : ComposableArrows C 0} {φ φ' : F ⟶ G}
(h : app' φ 0 = app' φ' 0) :
φ = φ' := by
ext i
fin_cases i
exact h
/-- Constructor for isomorphisms in `ComposableArrows C 0`. -/
@[simps!]
def isoMk₀ {F G : ComposableArrows C 0} (e : F.obj' 0 ≅ G.obj' 0) : F ≅ G where
hom := homMk₀ e.hom
inv := homMk₀ e.inv
lemma ext₀ {F G : ComposableArrows C 0} (h : F.obj' 0 = G.obj 0) : F = G :=
ext (fun i => match i with
| ⟨0, _⟩ => h) (fun i hi => by simp at hi)
lemma mk₀_surjective (F : ComposableArrows C 0) : ∃ (X : C), F = mk₀ X :=
⟨F.obj' 0, ext₀ rfl⟩
/-- Constructor for morphisms in `ComposableArrows C 1`. -/
@[simps!]
def homMk₁ {F G : ComposableArrows C 1}
(left : F.obj' 0 ⟶ G.obj' 0) (right : F.obj' 1 ⟶ G.obj' 1)
(w : F.map' 0 1 ≫ right = left ≫ G.map' 0 1 := by aesop_cat) :
F ⟶ G :=
homMk (fun i => match i with
| ⟨0, _⟩ => left
| ⟨1, _⟩ => right) (by
intro i hi
obtain rfl : i = 0 := by simpa using hi
exact w)
@[ext]
lemma hom_ext₁ {F G : ComposableArrows C 1} {φ φ' : F ⟶ G}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) :
φ = φ' := by
ext i
match i with
| 0 => exact h₀
| 1 => exact h₁
/-- Constructor for isomorphisms in `ComposableArrows C 1`. -/
@[simps!]
def isoMk₁ {F G : ComposableArrows C 1}
(left : F.obj' 0 ≅ G.obj' 0) (right : F.obj' 1 ≅ G.obj' 1)
(w : F.map' 0 1 ≫ right.hom = left.hom ≫ G.map' 0 1 := by aesop_cat) :
F ≅ G where
hom := homMk₁ left.hom right.hom w
inv := homMk₁ left.inv right.inv (by
rw [← cancel_mono right.hom, assoc, assoc, w, right.inv_hom_id, left.inv_hom_id_assoc]
apply comp_id)
lemma map'_eq_hom₁ (F : ComposableArrows C 1) : F.map' 0 1 = F.hom := rfl
lemma ext₁ {F G : ComposableArrows C 1}
(left : F.left = G.left) (right : F.right = G.right)
(w : F.hom = eqToHom left ≫ G.hom ≫ eqToHom right.symm) : F = G :=
Functor.ext_of_iso (isoMk₁ (eqToIso left) (eqToIso right) (by simp [map'_eq_hom₁, w]))
(fun i => by fin_cases i <;> assumption)
(fun i => by fin_cases i <;> rfl)
lemma mk₁_surjective (X : ComposableArrows C 1) : ∃ (X₀ X₁ : C) (f : X₀ ⟶ X₁), X = mk₁ f :=
⟨_, _, X.map' 0 1, ext₁ rfl rfl (by simp)⟩
variable (F)
namespace Precomp
variable (X : C)
/-- The map `Fin (n + 1 + 1) → C` which "shifts" `F.obj'` to the right and inserts `X` in
the zeroth position. -/
def obj : Fin (n + 1 + 1) → C
| ⟨0, _⟩ => X
| ⟨i + 1, hi⟩ => F.obj' i
@[simp]
lemma obj_zero : obj F X 0 = X := rfl
@[simp]
lemma obj_one : obj F X 1 = F.obj' 0 := rfl
@[simp]
lemma obj_succ (i : ℕ) (hi : i + 1 < n + 1 + 1) : obj F X ⟨i + 1, hi⟩ = F.obj' i := rfl
variable {X} (f : X ⟶ F.left)
/-- Auxiliary definition for the action on maps of the functor `F.precomp f`.
It sends `0 ≤ 1` to `f` and `i + 1 ≤ j + 1` to `F.map' i j`. -/
def map : ∀ (i j : Fin (n + 1 + 1)) (_ : i ≤ j), obj F X i ⟶ obj F X j
| ⟨0, _⟩, ⟨0, _⟩, _ => 𝟙 X
| ⟨0, _⟩, ⟨1, _⟩, _ => f
| ⟨0, _⟩, ⟨j + 2, hj⟩, _ => f ≫ F.map' 0 (j + 1)
| ⟨i + 1, hi⟩, ⟨j + 1, hj⟩, hij => F.map' i j (by simpa using hij)
@[simp]
lemma map_zero_zero : map F f 0 0 (by simp) = 𝟙 X := rfl
@[simp]
lemma map_one_one : map F f 1 1 (by simp) = F.map (𝟙 _) := rfl
@[simp]
lemma map_zero_one : map F f 0 1 (by simp) = f := rfl
@[simp]
lemma map_zero_one' : map F f 0 ⟨0 + 1, by simp⟩ (by simp) = f := rfl
@[simp]
lemma map_zero_succ_succ (j : ℕ) (hj : j + 2 < n + 1 + 1) :
map F f 0 ⟨j + 2, hj⟩ (by simp) = f ≫ F.map' 0 (j+1) := rfl
@[simp]
lemma map_succ_succ (i j : ℕ) (hi : i + 1 < n + 1 + 1) (hj : j + 1 < n + 1 + 1)
(hij : i + 1 ≤ j + 1) :
map F f ⟨i + 1, hi⟩ ⟨j + 1, hj⟩ hij = F.map' i j := rfl
@[simp]
lemma map_one_succ (j : ℕ) (hj : j + 1 < n + 1 + 1) :
map F f 1 ⟨j + 1, hj⟩ (by simp [Fin.le_def]) = F.map' 0 j := rfl
lemma map_id (i : Fin (n + 1 + 1)) : map F f i i (by simp) = 𝟙 _ := by
obtain ⟨_|_, hi⟩ := i <;> simp
lemma map_comp {i j k : Fin (n + 1 + 1)} (hij : i ≤ j) (hjk : j ≤ k) :
map F f i k (hij.trans hjk) = map F f i j hij ≫ map F f j k hjk := by
obtain ⟨i, hi⟩ := i
obtain ⟨j, hj⟩ := j
obtain ⟨k, hk⟩ := k
cases i
· obtain _ | _ | j := j
· dsimp
rw [id_comp]
· obtain _ | _ | k := k
· simp [Nat.succ.injEq] at hjk
· simp
· rfl
· obtain _ | _ | k := k
· simp [Fin.ext_iff] at hjk
· simp [Fin.le_def] at hjk
omega
· dsimp
rw [assoc, ← F.map_comp, homOfLE_comp]
· obtain _ | j := j
· simp [Fin.ext_iff] at hij
· obtain _ | k := k
· simp [Fin.ext_iff] at hjk
· dsimp
rw [← F.map_comp, homOfLE_comp]
end Precomp
/-- "Precomposition" of `F : ComposableArrows C n` by a morphism `f : X ⟶ F.left`. -/
@[simps]
def precomp {X : C} (f : X ⟶ F.left) : ComposableArrows C (n + 1) where
obj := Precomp.obj F X
map g := Precomp.map F f _ _ (leOfHom g)
map_id := Precomp.map_id F f
map_comp g g' := Precomp.map_comp F f (leOfHom g) (leOfHom g')
/-- Constructor for `ComposableArrows C 2`. -/
@[simp]
def mk₂ {X₀ X₁ X₂ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) : ComposableArrows C 2 :=
(mk₁ g).precomp f
/-- Constructor for `ComposableArrows C 3`. -/
@[simp]
def mk₃ {X₀ X₁ X₂ X₃ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃) : ComposableArrows C 3 :=
(mk₂ g h).precomp f
/-- Constructor for `ComposableArrows C 4`. -/
@[simp]
def mk₄ {X₀ X₁ X₂ X₃ X₄ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃) (i : X₃ ⟶ X₄) :
ComposableArrows C 4 :=
(mk₃ g h i).precomp f
/-- Constructor for `ComposableArrows C 5`. -/
@[simp]
def mk₅ {X₀ X₁ X₂ X₃ X₄ X₅ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃)
(i : X₃ ⟶ X₄) (j : X₄ ⟶ X₅) :
ComposableArrows C 5 :=
(mk₄ g h i j).precomp f
section
variable {X₀ X₁ X₂ X₃ X₄ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃) (i : X₃ ⟶ X₄)
/-! These examples are meant to test the good definitional properties of `precomp`,
and that `dsimp` can see through. -/
example : map' (mk₂ f g) 0 1 = f := by dsimp
example : map' (mk₂ f g) 1 2 = g := by dsimp
example : map' (mk₂ f g) 0 2 = f ≫ g := by dsimp
example : (mk₂ f g).hom = f ≫ g := by dsimp
example : map' (mk₂ f g) 0 0 = 𝟙 _ := by dsimp
example : map' (mk₂ f g) 1 1 = 𝟙 _ := by dsimp
example : map' (mk₂ f g) 2 2 = 𝟙 _ := by dsimp
example : map' (mk₃ f g h) 0 1 = f := by dsimp
example : map' (mk₃ f g h) 1 2 = g := by dsimp
example : map' (mk₃ f g h) 2 3 = h := by dsimp
example : map' (mk₃ f g h) 0 3 = f ≫ g ≫ h := by dsimp
example : (mk₃ f g h).hom = f ≫ g ≫ h := by dsimp
example : map' (mk₃ f g h) 0 2 = f ≫ g := by dsimp
example : map' (mk₃ f g h) 1 3 = g ≫ h := by dsimp
end
/-- The map `ComposableArrows C m → ComposableArrows C n` obtained by precomposition with
a functor `Fin (n + 1) ⥤ Fin (m + 1)`. -/
@[simps!]
def whiskerLeft (F : ComposableArrows C m) (Φ : Fin (n + 1) ⥤ Fin (m + 1)) :
ComposableArrows C n := Φ ⋙ F
/-- The functor `ComposableArrows C m ⥤ ComposableArrows C n` obtained by precomposition with
a functor `Fin (n + 1) ⥤ Fin (m + 1)`. -/
@[simps!]
def whiskerLeftFunctor (Φ : Fin (n + 1) ⥤ Fin (m + 1)) :
ComposableArrows C m ⥤ ComposableArrows C n where
obj F := F.whiskerLeft Φ
map f := CategoryTheory.whiskerLeft Φ f
/-- The functor `Fin n ⥤ Fin (n + 1)` which sends `i` to `i.succ`. -/
@[simps]
def _root_.Fin.succFunctor (n : ℕ) : Fin n ⥤ Fin (n + 1) where
obj i := i.succ
map {_ _} hij := homOfLE (Fin.succ_le_succ_iff.2 (leOfHom hij))
/-- The functor `ComposableArrows C (n + 1) ⥤ ComposableArrows C n` which forgets
the first arrow. -/
@[simps!]
def δ₀Functor : ComposableArrows C (n + 1) ⥤ ComposableArrows C n :=
whiskerLeftFunctor (Fin.succFunctor (n + 1))
/-- The `ComposableArrows C n` obtained by forgetting the first arrow. -/
abbrev δ₀ (F : ComposableArrows C (n + 1)) := δ₀Functor.obj F
@[simp]
lemma precomp_δ₀ {X : C} (f : X ⟶ F.left) : (F.precomp f).δ₀ = F := rfl
/-- The functor `Fin n ⥤ Fin (n + 1)` which sends `i` to `i.castSucc`. -/
@[simps]
def _root_.Fin.castSuccFunctor (n : ℕ) : Fin n ⥤ Fin (n + 1) where
obj i := i.castSucc
map hij := hij
/-- The functor `ComposableArrows C (n + 1) ⥤ ComposableArrows C n` which forgets
the last arrow. -/
@[simps!]
def δlastFunctor : ComposableArrows C (n + 1) ⥤ ComposableArrows C n :=
whiskerLeftFunctor (Fin.castSuccFunctor (n + 1))
/-- The `ComposableArrows C n` obtained by forgetting the first arrow. -/
abbrev δlast (F : ComposableArrows C (n + 1)) := δlastFunctor.obj F
section
variable {F G : ComposableArrows C (n + 1)}
/-- Inductive construction of morphisms in `ComposableArrows C (n + 1)`: in order to construct
a morphism `F ⟶ G`, it suffices to provide `α : F.obj' 0 ⟶ G.obj' 0` and `β : F.δ₀ ⟶ G.δ₀`
such that `F.map' 0 1 ≫ app' β 0 = α ≫ G.map' 0 1`. -/
def homMkSucc (α : F.obj' 0 ⟶ G.obj' 0) (β : F.δ₀ ⟶ G.δ₀)
(w : F.map' 0 1 ≫ app' β 0 = α ≫ G.map' 0 1) : F ⟶ G :=
homMk
(fun i => match i with
| ⟨0, _⟩ => α
| ⟨i + 1, hi⟩ => app' β i)
(fun i hi => by
obtain _ | i := i
· exact w
· exact naturality' β i (i + 1))
variable (α : F.obj' 0 ⟶ G.obj' 0) (β : F.δ₀ ⟶ G.δ₀)
(w : F.map' 0 1 ≫ app' β 0 = α ≫ G.map' 0 1)
@[simp]
lemma homMkSucc_app_zero : (homMkSucc α β w).app 0 = α := rfl
@[simp]
lemma homMkSucc_app_succ (i : ℕ) (hi : i + 1 < n + 1 + 1) :
(homMkSucc α β w).app ⟨i + 1, hi⟩ = app' β i := rfl
end
lemma hom_ext_succ {F G : ComposableArrows C (n + 1)} {f g : F ⟶ G}
(h₀ : app' f 0 = app' g 0) (h₁ : δ₀Functor.map f = δ₀Functor.map g) : f = g := by
ext ⟨i, hi⟩
obtain _ | i := i
· exact h₀
· exact congr_app h₁ ⟨i, by valid⟩
/-- Inductive construction of isomorphisms in `ComposableArrows C (n + 1)`: in order to
construct an isomorphism `F ≅ G`, it suffices to provide `α : F.obj' 0 ≅ G.obj' 0` and
`β : F.δ₀ ≅ G.δ₀` such that `F.map' 0 1 ≫ app' β.hom 0 = α.hom ≫ G.map' 0 1`. -/
@[simps]
def isoMkSucc {F G : ComposableArrows C (n + 1)} (α : F.obj' 0 ≅ G.obj' 0)
(β : F.δ₀ ≅ G.δ₀) (w : F.map' 0 1 ≫ app' β.hom 0 = α.hom ≫ G.map' 0 1) : F ≅ G where
hom := homMkSucc α.hom β.hom w
inv := homMkSucc α.inv β.inv (by
rw [← cancel_epi α.hom, ← reassoc_of% w, α.hom_inv_id_assoc, β.hom_inv_id_app]
dsimp
rw [comp_id])
hom_inv_id := by
apply hom_ext_succ
· simp
· ext ⟨i, hi⟩
simp
inv_hom_id := by
apply hom_ext_succ
· simp
· ext ⟨i, hi⟩
simp
lemma ext_succ {F G : ComposableArrows C (n + 1)} (h₀ : F.obj' 0 = G.obj' 0)
(h : F.δ₀ = G.δ₀) (w : F.map' 0 1 = eqToHom h₀ ≫ G.map' 0 1 ≫
eqToHom (Functor.congr_obj h.symm 0)) : F = G := by
have : ∀ i, F.obj i = G.obj i := by
intro ⟨i, hi⟩
rcases i with - | i
· exact h₀
· exact Functor.congr_obj h ⟨i, by valid⟩
exact Functor.ext_of_iso (isoMkSucc (eqToIso h₀) (eqToIso h) (by
rw [w]
dsimp [app']
rw [eqToHom_app, assoc, assoc, eqToHom_trans, eqToHom_refl, comp_id])) this
(by rintro ⟨_|_, hi⟩ <;> simp)
lemma precomp_surjective (F : ComposableArrows C (n + 1)) :
∃ (F₀ : ComposableArrows C n) (X₀ : C) (f₀ : X₀ ⟶ F₀.left), F = F₀.precomp f₀ :=
⟨F.δ₀, _, F.map' 0 1, ext_succ rfl (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 2}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
/-- Constructor for morphisms in `ComposableArrows C 2`. -/
def homMk₂ : f ⟶ g := homMkSucc app₀ (homMk₁ app₁ app₂ w₁) w₀
@[simp]
lemma homMk₂_app_zero : (homMk₂ app₀ app₁ app₂ w₀ w₁).app 0 = app₀ := rfl
@[simp]
lemma homMk₂_app_one : (homMk₂ app₀ app₁ app₂ w₀ w₁).app 1 = app₁ := rfl
@[simp]
lemma homMk₂_app_two : (homMk₂ app₀ app₁ app₂ w₀ w₁).app ⟨2, by valid⟩ = app₂ := rfl
end
@[ext]
lemma hom_ext₂ {f g : ComposableArrows C 2} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₁ h₁ h₂)
/-- Constructor for isomorphisms in `ComposableArrows C 2`. -/
@[simps]
def isoMk₂ {f g : ComposableArrows C 2}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2) : f ≅ g where
hom := homMk₂ app₀.hom app₁.hom app₂.hom w₀ w₁
inv := homMk₂ app₀.inv app₁.inv app₂.inv
(by rw [← cancel_epi app₀.hom, ← reassoc_of% w₀, app₁.hom_inv_id,
comp_id, app₀.hom_inv_id_assoc])
(by rw [← cancel_epi app₁.hom, ← reassoc_of% w₁, app₂.hom_inv_id,
comp_id, app₁.hom_inv_id_assoc])
lemma ext₂ {f g : ComposableArrows C 2}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm) : f = g :=
ext_succ h₀ (ext₁ h₁ h₂ w₁) w₀
lemma mk₂_surjective (X : ComposableArrows C 2) :
∃ (X₀ X₁ X₂ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂), X = mk₂ f₀ f₁ :=
⟨_, _, _, X.map' 0 1, X.map' 1 2, ext₂ rfl rfl rfl (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 3}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(app₃ : f.obj' 3 ⟶ g.obj' 3)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃ = app₂ ≫ g.map' 2 3)
/-- Constructor for morphisms in `ComposableArrows C 3`. -/
def homMk₃ : f ⟶ g := homMkSucc app₀ (homMk₂ app₁ app₂ app₃ w₁ w₂) w₀
@[simp]
lemma homMk₃_app_zero : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app 0 = app₀ := rfl
@[simp]
lemma homMk₃_app_one : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app 1 = app₁ := rfl
@[simp]
lemma homMk₃_app_two : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app ⟨2, by valid⟩ = app₂ :=
rfl
@[simp]
lemma homMk₃_app_three : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app ⟨3, by valid⟩ = app₃ :=
rfl
end
@[ext]
lemma hom_ext₃ {f g : ComposableArrows C 3} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2)
(h₃ : app' φ 3 = app' φ' 3) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₂ h₁ h₂ h₃)
/-- Constructor for isomorphisms in `ComposableArrows C 3`. -/
@[simps]
def isoMk₃ {f g : ComposableArrows C 3}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(app₃ : f.obj' 3 ≅ g.obj' 3)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃.hom = app₂.hom ≫ g.map' 2 3) : f ≅ g where
hom := homMk₃ app₀.hom app₁.hom app₂.hom app₃.hom w₀ w₁ w₂
inv := homMk₃ app₀.inv app₁.inv app₂.inv app₃.inv
(by rw [← cancel_epi app₀.hom, ← reassoc_of% w₀, app₁.hom_inv_id,
comp_id, app₀.hom_inv_id_assoc])
(by rw [← cancel_epi app₁.hom, ← reassoc_of% w₁, app₂.hom_inv_id,
comp_id, app₁.hom_inv_id_assoc])
(by rw [← cancel_epi app₂.hom, ← reassoc_of% w₂, app₃.hom_inv_id,
comp_id, app₂.hom_inv_id_assoc])
lemma ext₃ {f g : ComposableArrows C 3}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(h₃ : f.obj' 3 = g.obj' 3)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm)
(w₂ : f.map' 2 3 = eqToHom h₂ ≫ g.map' 2 3 ≫ eqToHom h₃.symm) : f = g :=
ext_succ h₀ (ext₂ h₁ h₂ h₃ w₁ w₂) w₀
lemma mk₃_surjective (X : ComposableArrows C 3) :
∃ (X₀ X₁ X₂ X₃ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃), X = mk₃ f₀ f₁ f₂ :=
⟨_, _, _, _, X.map' 0 1, X.map' 1 2, X.map' 2 3,
ext₃ rfl rfl rfl rfl (by simp) (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 4}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(app₃ : f.obj' 3 ⟶ g.obj' 3) (app₄ : f.obj' 4 ⟶ g.obj' 4)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃ = app₂ ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄ = app₃ ≫ g.map' 3 4)
/-- Constructor for morphisms in `ComposableArrows C 4`. -/
def homMk₄ : f ⟶ g := homMkSucc app₀ (homMk₃ app₁ app₂ app₃ app₄ w₁ w₂ w₃) w₀
@[simp]
lemma homMk₄_app_zero : (homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app 0 = app₀ := rfl
@[simp]
lemma homMk₄_app_one : (homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app 1 = app₁ := rfl
@[simp]
lemma homMk₄_app_two :
(homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app ⟨2, by valid⟩ = app₂ := rfl
@[simp]
lemma homMk₄_app_three :
(homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app ⟨3, by valid⟩ = app₃ := rfl
@[simp]
lemma homMk₄_app_four :
(homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app ⟨4, by valid⟩ = app₄ := rfl
end
@[ext]
lemma hom_ext₄ {f g : ComposableArrows C 4} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2)
(h₃ : app' φ 3 = app' φ' 3) (h₄ : app' φ 4 = app' φ' 4) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₃ h₁ h₂ h₃ h₄)
lemma map'_inv_eq_inv_map' {n m : ℕ} (h : n+1 ≤ m) {f g : ComposableArrows C m}
(app : f.obj' n ≅ g.obj' n) (app' : f.obj' (n+1) ≅ g.obj' (n+1))
(w : f.map' n (n+1) ≫ app'.hom = app.hom ≫ g.map' n (n+1)) :
map' g n (n+1) ≫ app'.inv = app.inv ≫ map' f n (n+1) := by
rw [← cancel_epi app.hom, ← reassoc_of% w, app'.hom_inv_id, comp_id, app.hom_inv_id_assoc]
/-- Constructor for isomorphisms in `ComposableArrows C 4`. -/
@[simps]
def isoMk₄ {f g : ComposableArrows C 4}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(app₃ : f.obj' 3 ≅ g.obj' 3) (app₄ : f.obj' 4 ≅ g.obj' 4)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃.hom = app₂.hom ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄.hom = app₃.hom ≫ g.map' 3 4) :
f ≅ g where
hom := homMk₄ app₀.hom app₁.hom app₂.hom app₃.hom app₄.hom w₀ w₁ w₂ w₃
inv := homMk₄ app₀.inv app₁.inv app₂.inv app₃.inv app₄.inv
(by rw [map'_inv_eq_inv_map' (by valid) app₀ app₁ w₀])
(by rw [map'_inv_eq_inv_map' (by valid) app₁ app₂ w₁])
(by rw [map'_inv_eq_inv_map' (by valid) app₂ app₃ w₂])
(by rw [map'_inv_eq_inv_map' (by valid) app₃ app₄ w₃])
lemma ext₄ {f g : ComposableArrows C 4}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(h₃ : f.obj' 3 = g.obj' 3) (h₄ : f.obj' 4 = g.obj' 4)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm)
(w₂ : f.map' 2 3 = eqToHom h₂ ≫ g.map' 2 3 ≫ eqToHom h₃.symm)
(w₃ : f.map' 3 4 = eqToHom h₃ ≫ g.map' 3 4 ≫ eqToHom h₄.symm) :
f = g :=
ext_succ h₀ (ext₃ h₁ h₂ h₃ h₄ w₁ w₂ w₃) w₀
lemma mk₄_surjective (X : ComposableArrows C 4) :
∃ (X₀ X₁ X₂ X₃ X₄ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃) (f₃ : X₃ ⟶ X₄),
X = mk₄ f₀ f₁ f₂ f₃ :=
⟨_, _, _, _, _, X.map' 0 1, X.map' 1 2, X.map' 2 3, X.map' 3 4,
ext₄ rfl rfl rfl rfl rfl (by simp) (by simp) (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 5}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(app₃ : f.obj' 3 ⟶ g.obj' 3) (app₄ : f.obj' 4 ⟶ g.obj' 4) (app₅ : f.obj' 5 ⟶ g.obj' 5)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃ = app₂ ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄ = app₃ ≫ g.map' 3 4)
(w₄ : f.map' 4 5 ≫ app₅ = app₄ ≫ g.map' 4 5)
/-- Constructor for morphisms in `ComposableArrows C 5`. -/
def homMk₅ : f ⟶ g := homMkSucc app₀ (homMk₄ app₁ app₂ app₃ app₄ app₅ w₁ w₂ w₃ w₄) w₀
@[simp]
lemma homMk₅_app_zero : (homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app 0 = app₀ := rfl
@[simp]
lemma homMk₅_app_one : (homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app 1 = app₁ := rfl
@[simp]
lemma homMk₅_app_two :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨2, by valid⟩ = app₂ := rfl
@[simp]
lemma homMk₅_app_three :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨3, by valid⟩ = app₃ := rfl
@[simp]
lemma homMk₅_app_four :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨4, by valid⟩ = app₄ := rfl
@[simp]
lemma homMk₅_app_five :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨5, by valid⟩ = app₅ := rfl
end
@[ext]
lemma hom_ext₅ {f g : ComposableArrows C 5} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2)
(h₃ : app' φ 3 = app' φ' 3) (h₄ : app' φ 4 = app' φ' 4) (h₅ : app' φ 5 = app' φ' 5) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₄ h₁ h₂ h₃ h₄ h₅)
/-- Constructor for isomorphisms in `ComposableArrows C 5`. -/
@[simps]
def isoMk₅ {f g : ComposableArrows C 5}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(app₃ : f.obj' 3 ≅ g.obj' 3) (app₄ : f.obj' 4 ≅ g.obj' 4) (app₅ : f.obj' 5 ≅ g.obj' 5)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃.hom = app₂.hom ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄.hom = app₃.hom ≫ g.map' 3 4)
(w₄ : f.map' 4 5 ≫ app₅.hom = app₄.hom ≫ g.map' 4 5) :
f ≅ g where
hom := homMk₅ app₀.hom app₁.hom app₂.hom app₃.hom app₄.hom app₅.hom w₀ w₁ w₂ w₃ w₄
inv := homMk₅ app₀.inv app₁.inv app₂.inv app₃.inv app₄.inv app₅.inv
(by rw [map'_inv_eq_inv_map' (by valid) app₀ app₁ w₀])
(by rw [map'_inv_eq_inv_map' (by valid) app₁ app₂ w₁])
(by rw [map'_inv_eq_inv_map' (by valid) app₂ app₃ w₂])
(by rw [map'_inv_eq_inv_map' (by valid) app₃ app₄ w₃])
(by rw [map'_inv_eq_inv_map' (by valid) app₄ app₅ w₄])
lemma ext₅ {f g : ComposableArrows C 5}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(h₃ : f.obj' 3 = g.obj' 3) (h₄ : f.obj' 4 = g.obj' 4) (h₅ : f.obj' 5 = g.obj' 5)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm)
(w₂ : f.map' 2 3 = eqToHom h₂ ≫ g.map' 2 3 ≫ eqToHom h₃.symm)
(w₃ : f.map' 3 4 = eqToHom h₃ ≫ g.map' 3 4 ≫ eqToHom h₄.symm)
(w₄ : f.map' 4 5 = eqToHom h₄ ≫ g.map' 4 5 ≫ eqToHom h₅.symm) :
f = g :=
ext_succ h₀ (ext₄ h₁ h₂ h₃ h₄ h₅ w₁ w₂ w₃ w₄) w₀
lemma mk₅_surjective (X : ComposableArrows C 5) :
∃ (X₀ X₁ X₂ X₃ X₄ X₅ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃)
(f₃ : X₃ ⟶ X₄) (f₄ : X₄ ⟶ X₅), X = mk₅ f₀ f₁ f₂ f₃ f₄ :=
⟨_, _, _, _, _, _, X.map' 0 1, X.map' 1 2, X.map' 2 3, X.map' 3 4, X.map' 4 5,
ext₅ rfl rfl rfl rfl rfl rfl (by simp) (by simp) (by simp) (by simp) (by simp)⟩
/-- The `i`th arrow of `F : ComposableArrows C n`. -/
def arrow (i : ℕ) (hi : i < n := by valid) :
ComposableArrows C 1 := mk₁ (F.map' i (i + 1))
section mkOfObjOfMapSucc
variable (obj : Fin (n + 1) → C) (mapSucc : ∀ (i : Fin n), obj i.castSucc ⟶ obj i.succ)
lemma mkOfObjOfMapSucc_exists : ∃ (F : ComposableArrows C n) (e : ∀ i, F.obj i ≅ obj i),
∀ (i : ℕ) (hi : i < n), mapSucc ⟨i, hi⟩ =
(e ⟨i, _⟩).inv ≫ F.map' i (i + 1) ≫ (e ⟨i + 1, _⟩).hom := by
revert obj mapSucc
induction' n with n hn
· intro obj _
exact ⟨mk₀ (obj 0), fun 0 => Iso.refl _, fun i hi => by simp at hi⟩
· intro obj mapSucc
obtain ⟨F, e, h⟩ := hn (fun i => obj i.succ) (fun i => mapSucc i.succ)
refine ⟨F.precomp (mapSucc 0 ≫ (e 0).inv), fun i => match i with
| 0 => Iso.refl _
| ⟨i + 1, hi⟩ => e _, fun i hi => ?_⟩
obtain _ | i := i
· simp only [← Fin.mk_zero]
simp
· exact h i (by valid)
/-- Given `obj : Fin (n + 1) → C` and `mapSucc i : obj i.castSucc ⟶ obj i.succ`
for all `i : Fin n`, this is `F : ComposableArrows C n` such that `F.obj i` is
definitionally equal to `obj i` and such that `F.map' i (i + 1) = mapSucc ⟨i, hi⟩`. -/
noncomputable def mkOfObjOfMapSucc : ComposableArrows C n :=
(mkOfObjOfMapSucc_exists obj mapSucc).choose.copyObj obj
(mkOfObjOfMapSucc_exists obj mapSucc).choose_spec.choose
@[simp]
lemma mkOfObjOfMapSucc_obj (i : Fin (n + 1)) :
(mkOfObjOfMapSucc obj mapSucc).obj i = obj i := rfl
lemma mkOfObjOfMapSucc_map_succ (i : ℕ) (hi : i < n := by valid) :
(mkOfObjOfMapSucc obj mapSucc).map' i (i + 1) = mapSucc ⟨i, hi⟩ :=
((mkOfObjOfMapSucc_exists obj mapSucc).choose_spec.choose_spec i hi).symm
lemma mkOfObjOfMapSucc_arrow (i : ℕ) (hi : i < n := by valid) :
(mkOfObjOfMapSucc obj mapSucc).arrow i = mk₁ (mapSucc ⟨i, hi⟩) :=
ext₁ rfl rfl (by simpa using mkOfObjOfMapSucc_map_succ obj mapSucc i hi)
end mkOfObjOfMapSucc
suppress_compilation in
variable (C n) in
/-- The equivalence `(ComposableArrows C n)ᵒᵖ ≌ ComposableArrows Cᵒᵖ n` obtained
by reversing the arrows. -/
@[simps!]
def opEquivalence : (ComposableArrows C n)ᵒᵖ ≌ ComposableArrows Cᵒᵖ n :=
((orderDualEquivalence (Fin (n + 1))).symm.trans
Fin.revOrderIso.equivalence).symm.congrLeft.op.trans
| (Functor.leftOpRightOpEquiv (Fin (n + 1)) C)
end ComposableArrows
| Mathlib/CategoryTheory/ComposableArrows.lean | 883 | 885 |
/-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Analysis.Convex.Topology
import Mathlib.Analysis.NormedSpace.Pointwise
import Mathlib.Analysis.Seminorm
import Mathlib.Analysis.LocallyConvex.Bounded
import Mathlib.Analysis.RCLike.Basic
/-!
# The Minkowski functional
This file defines the Minkowski functional, aka gauge.
The Minkowski functional of a set `s` is the function which associates each point to how much you
need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is
a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This
induces the equivalence of seminorms and locally convex topological vector spaces.
## Main declarations
For a real vector space,
* `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such
that `x ∈ r • s`.
* `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and
absorbent.
## References
* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]
## Tags
Minkowski functional, gauge
-/
open NormedField Set
open scoped Pointwise Topology NNReal
noncomputable section
variable {𝕜 E : Type*}
section AddCommGroup
variable [AddCommGroup E] [Module ℝ E]
/-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional
which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/
def gauge (s : Set E) (x : E) : ℝ :=
sInf { r : ℝ | 0 < r ∧ x ∈ r • s }
variable {s t : Set E} {x : E} {a : ℝ}
theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) :=
rfl
/-- An alternative definition of the gauge using scalar multiplication on the element rather than on
the set. -/
theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by
congrm sInf {r | ?_}
exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _
private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } :=
⟨0, fun _ hr => hr.1.le⟩
/-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty,
which is useful for proving many properties about the gauge. -/
theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) :
{ r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty :=
let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos
⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩
theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ =>
csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩
theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) :
∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by
obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h
exact ⟨b, hb, hba, hx⟩
/-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s`
but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/
@[simp]
theorem gauge_zero : gauge s 0 = 0 := by
rw [gauge_def']
by_cases h : (0 : E) ∈ s
· simp only [smul_zero, sep_true, h, csInf_Ioi]
· simp only [smul_zero, sep_false, h, Real.sInf_empty]
@[simp]
theorem gauge_zero' : gauge (0 : Set E) = 0 := by
ext x
rw [gauge_def']
obtain rfl | hx := eq_or_ne x 0
· simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero]
· simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero]
convert Real.sInf_empty
exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx
@[simp]
theorem gauge_empty : gauge (∅ : Set E) = 0 := by
ext
simp only [gauge_def', Real.sInf_empty, mem_empty_iff_false, Pi.zero_apply, sep_false]
theorem gauge_of_subset_zero (h : s ⊆ 0) : gauge s = 0 := by
obtain rfl | rfl := subset_singleton_iff_eq.1 h
exacts [gauge_empty, gauge_zero']
/-- The gauge is always nonnegative. -/
theorem gauge_nonneg (x : E) : 0 ≤ gauge s x :=
Real.sInf_nonneg fun _ hx => hx.1.le
theorem gauge_neg (symmetric : ∀ x ∈ s, -x ∈ s) (x : E) : gauge s (-x) = gauge s x := by
have : ∀ x, -x ∈ s ↔ x ∈ s := fun x => ⟨fun h => by simpa using symmetric _ h, symmetric x⟩
simp_rw [gauge_def', smul_neg, this]
theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by
simp_rw [gauge_def', smul_neg, neg_mem_neg]
theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by
rw [← gauge_neg_set_neg, neg_neg]
theorem gauge_le_of_mem (ha : 0 ≤ a) (hx : x ∈ a • s) : gauge s x ≤ a := by
obtain rfl | ha' := ha.eq_or_lt
· rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero]
· exact csInf_le gauge_set_bddBelow ⟨ha', hx⟩
theorem gauge_le_eq (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : Absorbent ℝ s) (ha : 0 ≤ a) :
{ x | gauge s x ≤ a } = ⋂ (r : ℝ) (_ : a < r), r • s := by
ext x
simp_rw [Set.mem_iInter, Set.mem_setOf_eq]
refine ⟨fun h r hr => ?_, fun h => le_of_forall_pos_lt_add fun ε hε => ?_⟩
· have hr' := ha.trans_lt hr
rw [mem_smul_set_iff_inv_smul_mem₀ hr'.ne']
obtain ⟨δ, δ_pos, hδr, hδ⟩ := exists_lt_of_gauge_lt hs₂ (h.trans_lt hr)
suffices (r⁻¹ * δ) • δ⁻¹ • x ∈ s by rwa [smul_smul, mul_inv_cancel_right₀ δ_pos.ne'] at this
rw [mem_smul_set_iff_inv_smul_mem₀ δ_pos.ne'] at hδ
refine hs₁.smul_mem_of_zero_mem hs₀ hδ ⟨by positivity, ?_⟩
rw [inv_mul_le_iff₀ hr', mul_one]
exact hδr.le
· have hε' := (lt_add_iff_pos_right a).2 (half_pos hε)
exact
(gauge_le_of_mem (ha.trans hε'.le) <| h _ hε').trans_lt (add_lt_add_left (half_lt_self hε) _)
theorem gauge_lt_eq' (absorbs : Absorbent ℝ s) (a : ℝ) :
{ x | gauge s x < a } = ⋃ (r : ℝ) (_ : 0 < r) (_ : r < a), r • s := by
ext
simp_rw [mem_setOf, mem_iUnion, exists_prop]
exact
⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ =>
(gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩
theorem gauge_lt_eq (absorbs : Absorbent ℝ s) (a : ℝ) :
{ x | gauge s x < a } = ⋃ r ∈ Set.Ioo 0 (a : ℝ), r • s := by
ext
simp_rw [mem_setOf, mem_iUnion, exists_prop, mem_Ioo, and_assoc]
exact
⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ =>
(gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩
theorem mem_openSegment_of_gauge_lt_one (absorbs : Absorbent ℝ s) (hgauge : gauge s x < 1) :
∃ y ∈ s, x ∈ openSegment ℝ 0 y := by
rcases exists_lt_of_gauge_lt absorbs hgauge with ⟨r, hr₀, hr₁, y, hy, rfl⟩
refine ⟨y, hy, 1 - r, r, ?_⟩
simp [*]
theorem gauge_lt_one_subset_self (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) :
{ x | gauge s x < 1 } ⊆ s := fun _x hx ↦
let ⟨_y, hys, hx⟩ := mem_openSegment_of_gauge_lt_one absorbs hx
hs.openSegment_subset h₀ hys hx
theorem gauge_le_one_of_mem {x : E} (hx : x ∈ s) : gauge s x ≤ 1 :=
gauge_le_of_mem zero_le_one <| by rwa [one_smul]
/-- Gauge is subadditive. -/
theorem gauge_add_le (hs : Convex ℝ s) (absorbs : Absorbent ℝ s) (x y : E) :
gauge s (x + y) ≤ gauge s x + gauge s y := by
refine le_of_forall_pos_lt_add fun ε hε => ?_
obtain ⟨a, ha, ha', x, hx, rfl⟩ :=
exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s x) (half_pos hε))
obtain ⟨b, hb, hb', y, hy, rfl⟩ :=
exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s y) (half_pos hε))
calc
gauge s (a • x + b • y) ≤ a + b := gauge_le_of_mem (by positivity) <| by
rw [hs.add_smul ha.le hb.le]
exact add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy)
_ < gauge s (a • x) + gauge s (b • y) + ε := by linarith
theorem self_subset_gauge_le_one : s ⊆ { x | gauge s x ≤ 1 } := fun _ => gauge_le_one_of_mem
theorem Convex.gauge_le (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) (a : ℝ) :
Convex ℝ { x | gauge s x ≤ a } := by
by_cases ha : 0 ≤ a
· rw [gauge_le_eq hs h₀ absorbs ha]
exact convex_iInter fun i => convex_iInter fun _ => hs.smul _
· convert convex_empty (𝕜 := ℝ)
exact eq_empty_iff_forall_not_mem.2 fun x hx => ha <| (gauge_nonneg _).trans hx
theorem Balanced.starConvex (hs : Balanced ℝ s) : StarConvex ℝ 0 s :=
starConvex_zero_iff.2 fun _ hx a ha₀ ha₁ =>
hs _ (by rwa [Real.norm_of_nonneg ha₀]) (smul_mem_smul_set hx)
theorem le_gauge_of_not_mem (hs₀ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ a • s) :
a ≤ gauge s x := by
rw [starConvex_zero_iff] at hs₀
obtain ⟨r, hr, h⟩ := hs₂.exists_pos
refine le_csInf ⟨r, hr, singleton_subset_iff.1 <| h _ (Real.norm_of_nonneg hr.le).ge⟩ ?_
rintro b ⟨hb, x, hx', rfl⟩
refine not_lt.1 fun hba => hx ?_
have ha := hb.trans hba
refine ⟨(a⁻¹ * b) • x, hs₀ hx' (by positivity) ?_, ?_⟩
· rw [← div_eq_inv_mul]
exact div_le_one_of_le₀ hba.le ha.le
· dsimp only
rw [← mul_smul, mul_inv_cancel_left₀ ha.ne']
theorem one_le_gauge_of_not_mem (hs₁ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ s) :
1 ≤ gauge s x :=
le_gauge_of_not_mem hs₁ hs₂ <| by rwa [one_smul]
section LinearOrderedField
variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
[MulActionWithZero α ℝ] [OrderedSMul α ℝ]
theorem gauge_smul_of_nonneg [MulActionWithZero α E] [IsScalarTower α ℝ (Set E)] {s : Set E} {a : α}
(ha : 0 ≤ a) (x : E) : gauge s (a • x) = a • gauge s x := by
obtain rfl | ha' := ha.eq_or_lt
· rw [zero_smul, gauge_zero, zero_smul]
rw [gauge_def', gauge_def', ← Real.sInf_smul_of_nonneg ha]
congr 1
ext r
simp_rw [Set.mem_smul_set, Set.mem_sep_iff]
constructor
· rintro ⟨hr, hx⟩
simp_rw [mem_Ioi] at hr ⊢
rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx
have := smul_pos (inv_pos.2 ha') hr
refine ⟨a⁻¹ • r, ⟨this, ?_⟩, smul_inv_smul₀ ha'.ne' _⟩
rwa [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc,
mem_smul_set_iff_inv_smul_mem₀ (inv_ne_zero ha'.ne'), inv_inv]
· rintro ⟨r, ⟨hr, hx⟩, rfl⟩
rw [mem_Ioi] at hr ⊢
rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx
have := smul_pos ha' hr
refine ⟨this, ?_⟩
rw [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc]
exact smul_mem_smul_set hx
theorem gauge_smul_left_of_nonneg [MulActionWithZero α E] [SMulCommClass α ℝ ℝ]
[IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} {a : α} (ha : 0 ≤ a) :
gauge (a • s) = a⁻¹ • gauge s := by
obtain rfl | ha' := ha.eq_or_lt
· rw [inv_zero, zero_smul, gauge_of_subset_zero (zero_smul_set_subset _)]
ext x
rw [gauge_def', Pi.smul_apply, gauge_def', ← Real.sInf_smul_of_nonneg (inv_nonneg.2 ha)]
congr 1
ext r
simp_rw [Set.mem_smul_set, Set.mem_sep_iff]
constructor
· rintro ⟨hr, y, hy, h⟩
simp_rw [mem_Ioi] at hr ⊢
refine ⟨a • r, ⟨smul_pos ha' hr, ?_⟩, inv_smul_smul₀ ha'.ne' _⟩
rwa [smul_inv₀, smul_assoc, ← h, inv_smul_smul₀ ha'.ne']
· rintro ⟨r, ⟨hr, hx⟩, rfl⟩
rw [mem_Ioi] at hr ⊢
refine ⟨smul_pos (inv_pos.2 ha') hr, r⁻¹ • x, hx, ?_⟩
rw [smul_inv₀, smul_assoc, inv_inv]
theorem gauge_smul_left [Module α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ]
[IsScalarTower α ℝ E] {s : Set E} (symmetric : ∀ x ∈ s, -x ∈ s) (a : α) :
gauge (a • s) = |a|⁻¹ • gauge s := by
rw [← gauge_smul_left_of_nonneg (abs_nonneg a)]
obtain h | h := abs_choice a
· rw [h]
· rw [h, Set.neg_smul_set, ← Set.smul_set_neg]
-- Porting note: was congr
apply congr_arg
apply congr_arg
ext y
refine ⟨symmetric _, fun hy => ?_⟩
rw [← neg_neg y]
exact symmetric _ hy
end LinearOrderedField
section RCLike
variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E]
theorem gauge_norm_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) :
gauge s (‖r‖ • x) = gauge s (r • x) := by
unfold gauge
congr with θ
rw [@RCLike.real_smul_eq_coe_smul 𝕜]
refine and_congr_right fun hθ => (hs.smul _).smul_mem_iff ?_
rw [RCLike.norm_ofReal, abs_norm]
/-- If `s` is balanced, then the Minkowski functional is ℂ-homogeneous. -/
theorem gauge_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (r • x) = ‖r‖ * gauge s x := by
rw [← smul_eq_mul, ← gauge_smul_of_nonneg (norm_nonneg r), gauge_norm_smul hs]
end RCLike
open Filter
section TopologicalSpace
variable [TopologicalSpace E]
theorem comap_gauge_nhds_zero_le (ha : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) :
comap (gauge s) (𝓝 0) ≤ 𝓝 0 := fun u hu ↦ by
rcases (hb hu).exists_pos with ⟨r, hr₀, hr⟩
filter_upwards [preimage_mem_comap (gt_mem_nhds (inv_pos.2 hr₀))] with x (hx : gauge s x < r⁻¹)
rcases exists_lt_of_gauge_lt ha hx with ⟨c, hc₀, hcr, y, hy, rfl⟩
have hrc := (lt_inv_comm₀ hr₀ hc₀).2 hcr
rcases hr c⁻¹ (hrc.le.trans (le_abs_self _)) hy with ⟨z, hz, rfl⟩
simpa only [smul_inv_smul₀ hc₀.ne']
variable [T1Space E]
theorem gauge_eq_zero (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) :
gauge s x = 0 ↔ x = 0 := by
refine ⟨fun h₀ ↦ by_contra fun (hne : x ≠ 0) ↦ ?_, fun h ↦ h.symm ▸ gauge_zero⟩
have : {x}ᶜ ∈ comap (gauge s) (𝓝 0) :=
comap_gauge_nhds_zero_le hs hb (isOpen_compl_singleton.mem_nhds hne.symm)
rcases ((nhds_basis_zero_abs_lt _).comap _).mem_iff.1 this with ⟨r, hr₀, hr⟩
exact hr (by simpa [h₀]) rfl
theorem gauge_pos (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) :
0 < gauge s x ↔ x ≠ 0 := by
simp only [(gauge_nonneg _).gt_iff_ne, Ne, gauge_eq_zero hs hb]
end TopologicalSpace
section ContinuousSMul
variable [TopologicalSpace E] [ContinuousSMul ℝ E]
open Filter in
theorem interior_subset_gauge_lt_one (s : Set E) : interior s ⊆ { x | gauge s x < 1 } := by
intro x hx
have H₁ : Tendsto (fun r : ℝ ↦ r⁻¹ • x) (𝓝[<] 1) (𝓝 ((1 : ℝ)⁻¹ • x)) :=
((tendsto_id.inv₀ one_ne_zero).smul tendsto_const_nhds).mono_left inf_le_left
rw [inv_one, one_smul] at H₁
have H₂ : ∀ᶠ r in 𝓝[<] (1 : ℝ), x ∈ r • s ∧ 0 < r ∧ r < 1 := by
filter_upwards [H₁ (mem_interior_iff_mem_nhds.1 hx), Ioo_mem_nhdsLT one_pos] with r h₁ h₂
exact ⟨(mem_smul_set_iff_inv_smul_mem₀ h₂.1.ne' _ _).2 h₁, h₂⟩
rcases H₂.exists with ⟨r, hxr, hr₀, hr₁⟩
exact (gauge_le_of_mem hr₀.le hxr).trans_lt hr₁
theorem gauge_lt_one_eq_self_of_isOpen (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : IsOpen s) :
{ x | gauge s x < 1 } = s := by
refine (gauge_lt_one_subset_self hs₁ ‹_› <| absorbent_nhds_zero <| hs₂.mem_nhds hs₀).antisymm ?_
convert interior_subset_gauge_lt_one s
exact hs₂.interior_eq.symm
theorem gauge_lt_one_of_mem_of_isOpen (hs₂ : IsOpen s) {x : E} (hx : x ∈ s) :
gauge s x < 1 :=
interior_subset_gauge_lt_one s <| by rwa [hs₂.interior_eq]
theorem gauge_lt_of_mem_smul (x : E) (ε : ℝ) (hε : 0 < ε) (hs₂ : IsOpen s) (hx : x ∈ ε • s) :
gauge s x < ε := by
have : ε⁻¹ • x ∈ s := by rwa [← mem_smul_set_iff_inv_smul_mem₀ hε.ne']
have h_gauge_lt := gauge_lt_one_of_mem_of_isOpen hs₂ this
rwa [gauge_smul_of_nonneg (inv_nonneg.2 hε.le), smul_eq_mul, inv_mul_lt_iff₀ hε, mul_one]
at h_gauge_lt
theorem mem_closure_of_gauge_le_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s)
(h : gauge s x ≤ 1) : x ∈ closure s := by
have : ∀ᶠ r : ℝ in 𝓝[<] 1, r • x ∈ s := by
filter_upwards [Ico_mem_nhdsLT one_pos] with r ⟨hr₀, hr₁⟩
apply gauge_lt_one_subset_self hc hs₀ ha
rw [mem_setOf_eq, gauge_smul_of_nonneg hr₀]
exact mul_lt_one_of_nonneg_of_lt_one_left hr₀ hr₁ h
refine mem_closure_of_tendsto ?_ this
exact Filter.Tendsto.mono_left (Continuous.tendsto' (by fun_prop) _ _ (one_smul _ _))
inf_le_left
theorem mem_frontier_of_gauge_eq_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s)
(h : gauge s x = 1) : x ∈ frontier s :=
⟨mem_closure_of_gauge_le_one hc hs₀ ha h.le, fun h' ↦
(interior_subset_gauge_lt_one s h').out.ne h⟩
theorem tendsto_gauge_nhds_zero_nhdsGE (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝[≥] 0) := by
refine nhdsGE_basis_Icc.tendsto_right_iff.2 fun ε hε ↦ ?_
rw [← set_smul_mem_nhds_zero_iff hε.ne'] at hs
filter_upwards [hs] with x hx
exact ⟨gauge_nonneg _, gauge_le_of_mem hε.le hx⟩
@[deprecated (since := "2025-03-02")]
alias tendsto_gauge_nhds_zero' := tendsto_gauge_nhds_zero_nhdsGE
theorem tendsto_gauge_nhds_zero (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝 0) :=
(tendsto_gauge_nhds_zero_nhdsGE hs).mono_right inf_le_left
/-- If `s` is a neighborhood of the origin, then `gauge s` is continuous at the origin.
See also `continuousAt_gauge`. -/
theorem continuousAt_gauge_zero (hs : s ∈ 𝓝 0) : ContinuousAt (gauge s) 0 := by
rw [ContinuousAt, gauge_zero]
exact tendsto_gauge_nhds_zero hs
theorem comap_gauge_nhds_zero (hb : Bornology.IsVonNBounded ℝ s) (h₀ : s ∈ 𝓝 0) :
comap (gauge s) (𝓝 0) = 𝓝 0 :=
(comap_gauge_nhds_zero_le (absorbent_nhds_zero h₀) hb).antisymm
(tendsto_gauge_nhds_zero h₀).le_comap
end ContinuousSMul
section TopologicalVectorSpace
open Filter
variable [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E]
/-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s`
is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see
`Convex.lipschitz_gauge`. -/
theorem continuousAt_gauge (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : ContinuousAt (gauge s) x := by
have ha : Absorbent ℝ s := absorbent_nhds_zero hs₀
refine (nhds_basis_Icc_pos _).tendsto_right_iff.2 fun ε hε₀ ↦ ?_
rw [← map_add_left_nhds_zero, eventually_map]
have : ε • s ∩ -(ε • s) ∈ 𝓝 0 :=
inter_mem ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀)
(neg_mem_nhds_zero _ ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀))
filter_upwards [this] with y hy
constructor
· rw [sub_le_iff_le_add]
calc
gauge s x = gauge s (x + y + (-y)) := by simp
_ ≤ gauge s (x + y) + gauge s (-y) := gauge_add_le hc ha _ _
_ ≤ gauge s (x + y) + ε := add_le_add_left (gauge_le_of_mem hε₀.le (mem_neg.1 hy.2)) _
· calc
gauge s (x + y) ≤ gauge s x + gauge s y := gauge_add_le hc ha _ _
_ ≤ gauge s x + ε := add_le_add_left (gauge_le_of_mem hε₀.le hy.1) _
/-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s`
is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see
`Convex.lipschitz_gauge`. -/
@[continuity]
theorem continuous_gauge (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : Continuous (gauge s) :=
continuous_iff_continuousAt.2 fun _ ↦ continuousAt_gauge hc hs₀
theorem gauge_lt_one_eq_interior (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) :
{ x | gauge s x < 1 } = interior s := by
refine Subset.antisymm (fun x hx ↦ ?_) (interior_subset_gauge_lt_one s)
rcases mem_openSegment_of_gauge_lt_one (absorbent_nhds_zero hs₀) hx with ⟨y, hys, hxy⟩
exact hc.openSegment_interior_self_subset_interior (mem_interior_iff_mem_nhds.2 hs₀) hys hxy
theorem gauge_lt_one_iff_mem_interior (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) :
gauge s x < 1 ↔ x ∈ interior s :=
Set.ext_iff.1 (gauge_lt_one_eq_interior hc hs₀) _
theorem gauge_le_one_iff_mem_closure (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) :
gauge s x ≤ 1 ↔ x ∈ closure s :=
⟨mem_closure_of_gauge_le_one hc (mem_of_mem_nhds hs₀) (absorbent_nhds_zero hs₀), fun h ↦
le_on_closure (fun _ ↦ gauge_le_one_of_mem) (continuous_gauge hc hs₀).continuousOn
continuousOn_const h⟩
theorem gauge_eq_one_iff_mem_frontier (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) :
gauge s x = 1 ↔ x ∈ frontier s := by
rw [eq_iff_le_not_lt, gauge_le_one_iff_mem_closure hc hs₀, gauge_lt_one_iff_mem_interior hc hs₀]
rfl
end TopologicalVectorSpace
section RCLike
variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E]
/-- `gauge s` as a seminorm when `s` is balanced, convex and absorbent. -/
@[simps!]
def gaugeSeminorm (hs₀ : Balanced 𝕜 s) (hs₁ : Convex ℝ s) (hs₂ : Absorbent ℝ s) : Seminorm 𝕜 E :=
Seminorm.of (gauge s) (gauge_add_le hs₁ hs₂) (gauge_smul hs₀)
variable {hs₀ : Balanced 𝕜 s} {hs₁ : Convex ℝ s} {hs₂ : Absorbent ℝ s} [TopologicalSpace E]
[ContinuousSMul ℝ E]
theorem gaugeSeminorm_lt_one_of_isOpen (hs : IsOpen s) {x : E} (hx : x ∈ s) :
gaugeSeminorm hs₀ hs₁ hs₂ x < 1 :=
gauge_lt_one_of_mem_of_isOpen hs hx
theorem gaugeSeminorm_ball_one (hs : IsOpen s) : (gaugeSeminorm hs₀ hs₁ hs₂).ball 0 1 = s := by
rw [Seminorm.ball_zero_eq]
exact gauge_lt_one_eq_self_of_isOpen hs₁ hs₂.zero_mem hs
end RCLike
/-- Any seminorm arises as the gauge of its unit ball. -/
@[simp]
protected theorem Seminorm.gauge_ball (p : Seminorm ℝ E) : gauge (p.ball 0 1) = p := by
ext x
obtain hp | hp := { r : ℝ | 0 < r ∧ x ∈ r • p.ball 0 1 }.eq_empty_or_nonempty
· rw [gauge, hp, Real.sInf_empty]
by_contra h
have hpx : 0 < p x := (apply_nonneg _ _).lt_of_ne h
have hpx₂ : 0 < 2 * p x := mul_pos zero_lt_two hpx
refine hp.subset ⟨hpx₂, (2 * p x)⁻¹ • x, ?_, smul_inv_smul₀ hpx₂.ne' _⟩
rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpx₂),
inv_mul_lt_iff₀ hpx₂, mul_one]
exact lt_mul_of_one_lt_left hpx one_lt_two
refine IsGLB.csInf_eq ⟨fun r => ?_, fun r hr => le_of_forall_pos_le_add fun ε hε => ?_⟩ hp
· rintro ⟨hr, y, hy, rfl⟩
rw [p.mem_ball_zero] at hy
rw [map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos hr]
exact mul_le_of_le_one_right hr.le hy.le
· have hpε : 0 < p x + ε := by positivity
refine hr ⟨hpε, (p x + ε)⁻¹ • x, ?_, smul_inv_smul₀ hpε.ne' _⟩
rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpε),
inv_mul_lt_iff₀ hpε, mul_one]
exact lt_add_of_pos_right _ hε
theorem Seminorm.gaugeSeminorm_ball (p : Seminorm ℝ E) :
gaugeSeminorm (p.balanced_ball_zero 1) (p.convex_ball 0 1) (p.absorbent_ball_zero zero_lt_one) =
p :=
DFunLike.coe_injective p.gauge_ball
end AddCommGroup
section Seminormed
variable [SeminormedAddCommGroup E] [NormedSpace ℝ E] {s : Set E} {r : ℝ} {x : E}
open Metric
theorem gauge_unit_ball (x : E) : gauge (ball (0 : E) 1) x = ‖x‖ := by
rw [← ball_normSeminorm ℝ, Seminorm.gauge_ball, coe_normSeminorm]
theorem gauge_ball (hr : 0 ≤ r) (x : E) : gauge (ball (0 : E) r) x = ‖x‖ / r := by
rcases hr.eq_or_lt with rfl | hr
· simp
· rw [← smul_unitBall_of_pos hr, gauge_smul_left, Pi.smul_apply, gauge_unit_ball, smul_eq_mul,
abs_of_nonneg hr.le, div_eq_inv_mul]
simp_rw [mem_ball_zero_iff, norm_neg]
exact fun _ => id
@[simp]
theorem gauge_closure_zero : gauge (closure (0 : Set E)) = 0 := funext fun x ↦ by
simp only [← singleton_zero, gauge_def', mem_closure_zero_iff_norm, norm_smul, mul_eq_zero,
norm_eq_zero, inv_eq_zero]
rcases (norm_nonneg x).eq_or_gt with hx | hx
· convert csInf_Ioi (a := (0 : ℝ))
exact Set.ext fun r ↦ and_iff_left (.inr hx)
· convert Real.sInf_empty
exact eq_empty_of_forall_not_mem fun r ⟨hr₀, hr⟩ ↦ hx.ne' <| hr.resolve_left hr₀.out.ne'
@[simp]
theorem gauge_closedBall (hr : 0 ≤ r) (x : E) : gauge (closedBall (0 : E) r) x = ‖x‖ / r := by
rcases hr.eq_or_lt with rfl | hr'
· rw [div_zero, closedBall_zero', singleton_zero, gauge_closure_zero]; rfl
· apply le_antisymm
· rw [← gauge_ball hr]
exact gauge_mono (absorbent_ball_zero hr') ball_subset_closedBall x
· suffices ∀ᶠ R in 𝓝[>] r, ‖x‖ / R ≤ gauge (closedBall 0 r) x by
refine le_of_tendsto ?_ this
exact tendsto_const_nhds.div inf_le_left hr'.ne'
filter_upwards [self_mem_nhdsWithin] with R hR
rw [← gauge_ball (hr.trans hR.out.le)]
refine gauge_mono ?_ (closedBall_subset_ball hR) _
exact (absorbent_ball_zero hr').mono ball_subset_closedBall
theorem mul_gauge_le_norm (hs : Metric.ball (0 : E) r ⊆ s) : r * gauge s x ≤ ‖x‖ := by
obtain hr | hr := le_or_lt r 0
· exact (mul_nonpos_of_nonpos_of_nonneg hr <| gauge_nonneg _).trans (norm_nonneg _)
rw [mul_comm, ← le_div_iff₀ hr, ← gauge_ball hr.le]
exact gauge_mono (absorbent_ball_zero hr) hs x
theorem Convex.lipschitzWith_gauge {r : ℝ≥0} (hc : Convex ℝ s) (hr : 0 < r)
(hs : Metric.ball (0 : E) r ⊆ s) : LipschitzWith r⁻¹ (gauge s) :=
have : Absorbent ℝ (Metric.ball (0 : E) r) := absorbent_ball_zero hr
LipschitzWith.of_le_add_mul _ fun x y =>
calc
gauge s x = gauge s (y + (x - y)) := by simp
_ ≤ gauge s y + gauge s (x - y) := gauge_add_le hc (this.mono hs) _ _
_ ≤ gauge s y + ‖x - y‖ / r :=
add_le_add_left ((gauge_mono this hs (x - y)).trans_eq (gauge_ball hr.le _)) _
_ = gauge s y + r⁻¹ * dist x y := by rw [dist_eq_norm, div_eq_inv_mul, NNReal.coe_inv]
theorem Convex.lipschitz_gauge (hc : Convex ℝ s) (h₀ : s ∈ 𝓝 (0 : E)) :
∃ K, LipschitzWith K (gauge s) :=
let ⟨r, hr₀, hr⟩ := Metric.mem_nhds_iff.1 h₀
⟨(⟨r, hr₀.le⟩ : ℝ≥0)⁻¹, hc.lipschitzWith_gauge hr₀ hr⟩
theorem Convex.uniformContinuous_gauge (hc : Convex ℝ s) (h₀ : s ∈ 𝓝 (0 : E)) :
UniformContinuous (gauge s) :=
let ⟨_K, hK⟩ := hc.lipschitz_gauge h₀; hK.uniformContinuous
end Seminormed
section Normed
variable [NormedAddCommGroup E] [NormedSpace ℝ E] {s : Set E} {r : ℝ} {x : E}
open Metric
theorem le_gauge_of_subset_closedBall (hs : Absorbent ℝ s) (hr : 0 ≤ r) (hsr : s ⊆ closedBall 0 r) :
‖x‖ / r ≤ gauge s x := by
rw [← gauge_closedBall hr]
| exact gauge_mono hs hsr _
end Normed
| Mathlib/Analysis/Convex/Gauge.lean | 600 | 612 |
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import Mathlib.Algebra.Polynomial.Identities
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.NumberTheory.Padics.PadicIntegers
import Mathlib.Topology.Algebra.Polynomial
import Mathlib.Topology.MetricSpace.CauSeqFilter
/-!
# Hensel's lemma on ℤ_p
This file proves Hensel's lemma on ℤ_p, roughly following Keith Conrad's writeup:
<http://www.math.uconn.edu/~kconrad/blurbs/gradnumthy/hensel.pdf>
Hensel's lemma gives a simple condition for the existence of a root of a polynomial.
The proof and motivation are described in the paper
[R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019].
## References
* <http://www.math.uconn.edu/~kconrad/blurbs/gradnumthy/hensel.pdf>
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/Hensel%27s_lemma>
## Tags
p-adic, p adic, padic, p-adic integer
-/
noncomputable section
open Topology
-- We begin with some general lemmas that are used below in the computation.
theorem padic_polynomial_dist {p : ℕ} [Fact p.Prime] (F : Polynomial ℤ_[p]) (x y : ℤ_[p]) :
‖F.eval x - F.eval y‖ ≤ ‖x - y‖ :=
let ⟨z, hz⟩ := F.evalSubFactor x y
calc
‖F.eval x - F.eval y‖ = ‖z‖ * ‖x - y‖ := by simp [hz]
_ ≤ 1 * ‖x - y‖ := by gcongr; apply PadicInt.norm_le_one
_ = ‖x - y‖ := by simp
open Filter Metric
private theorem comp_tendsto_lim {p : ℕ} [Fact p.Prime] {F : Polynomial ℤ_[p]}
(ncs : CauSeq ℤ_[p] norm) : Tendsto (fun i => F.eval (ncs i)) atTop (𝓝 (F.eval ncs.lim)) :=
Filter.Tendsto.comp (@Polynomial.continuousAt _ _ _ _ F _) ncs.tendsto_limit
section
variable {p : ℕ} [Fact p.Prime] {ncs : CauSeq ℤ_[p] norm} {F : Polynomial ℤ_[p]}
{a : ℤ_[p]} (ncs_der_val : ∀ n, ‖F.derivative.eval (ncs n)‖ = ‖F.derivative.eval a‖)
private theorem ncs_tendsto_lim :
Tendsto (fun i => ‖F.derivative.eval (ncs i)‖) atTop (𝓝 ‖F.derivative.eval ncs.lim‖) :=
Tendsto.comp (continuous_iff_continuousAt.1 continuous_norm _) (comp_tendsto_lim _)
include ncs_der_val
private theorem ncs_tendsto_const :
Tendsto (fun i => ‖F.derivative.eval (ncs i)‖) atTop (𝓝 ‖F.derivative.eval a‖) := by
convert @tendsto_const_nhds ℝ _ ℕ _ _; rw [ncs_der_val]
private theorem norm_deriv_eq : ‖F.derivative.eval ncs.lim‖ = ‖F.derivative.eval a‖ :=
tendsto_nhds_unique ncs_tendsto_lim (ncs_tendsto_const ncs_der_val)
end
section
variable {p : ℕ} [Fact p.Prime] {ncs : CauSeq ℤ_[p] norm} {F : Polynomial ℤ_[p]}
(hnorm : Tendsto (fun i => ‖F.eval (ncs i)‖) atTop (𝓝 0))
include hnorm
private theorem tendsto_zero_of_norm_tendsto_zero : Tendsto (fun i => F.eval (ncs i)) atTop (𝓝 0) :=
tendsto_iff_norm_sub_tendsto_zero.2 (by simpa using hnorm)
theorem limit_zero_of_norm_tendsto_zero : F.eval ncs.lim = 0 :=
tendsto_nhds_unique (comp_tendsto_lim _) (tendsto_zero_of_norm_tendsto_zero hnorm)
end
section Hensel
open Nat
variable (p : ℕ) [Fact p.Prime] (F : Polynomial ℤ_[p]) (a : ℤ_[p])
/-- `T` is an auxiliary value that is used to control the behavior of the polynomial `F`. -/
private def T_gen : ℝ := ‖F.eval a / ((F.derivative.eval a ^ 2 : ℤ_[p]) : ℚ_[p])‖
local notation "T" => @T_gen p _ F a
variable {p F a}
private theorem T_def : T = ‖F.eval a‖ / ‖F.derivative.eval a‖ ^ 2 := by
simp [T_gen, ← PadicInt.norm_def]
private theorem T_nonneg : 0 ≤ T := norm_nonneg _
private theorem T_pow_nonneg (n : ℕ) : 0 ≤ T ^ n := pow_nonneg T_nonneg _
variable (hnorm : ‖F.eval a‖ < ‖F.derivative.eval a‖ ^ 2)
include hnorm
private theorem deriv_sq_norm_pos : 0 < ‖F.derivative.eval a‖ ^ 2 :=
lt_of_le_of_lt (norm_nonneg _) hnorm
private theorem deriv_sq_norm_ne_zero : ‖F.derivative.eval a‖ ^ 2 ≠ 0 :=
ne_of_gt (deriv_sq_norm_pos hnorm)
private theorem deriv_norm_ne_zero : ‖F.derivative.eval a‖ ≠ 0 := fun h =>
deriv_sq_norm_ne_zero hnorm (by simp [*, sq])
private theorem deriv_norm_pos : 0 < ‖F.derivative.eval a‖ :=
lt_of_le_of_ne (norm_nonneg _) (Ne.symm (deriv_norm_ne_zero hnorm))
private theorem deriv_ne_zero : F.derivative.eval a ≠ 0 :=
mt norm_eq_zero.2 (deriv_norm_ne_zero hnorm)
private theorem T_lt_one : T < 1 := by
have h := (div_lt_one (deriv_sq_norm_pos hnorm)).2 hnorm
rw [T_def]; exact h
private theorem T_pow {n : ℕ} (hn : n ≠ 0) : T ^ n < 1 := pow_lt_one₀ T_nonneg (T_lt_one hnorm) hn
private theorem T_pow' (n : ℕ) : T ^ 2 ^ n < 1 := T_pow hnorm (pow_ne_zero _ two_ne_zero)
/-- We will construct a sequence of elements of ℤ_p satisfying successive values of `ih`. -/
private def ih_gen (n : ℕ) (z : ℤ_[p]) : Prop :=
‖F.derivative.eval z‖ = ‖F.derivative.eval a‖ ∧ ‖F.eval z‖ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n
local notation "ih" => @ih_gen p _ F a
private theorem ih_0 : ih 0 a :=
⟨rfl, by simp [T_def, mul_div_cancel₀ _ (ne_of_gt (deriv_sq_norm_pos hnorm))]⟩
private theorem calc_norm_le_one {n : ℕ} {z : ℤ_[p]} (hz : ih n z) :
‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ ≤ 1 :=
calc
‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ =
‖(↑(F.eval z) : ℚ_[p])‖ / ‖(↑(F.derivative.eval z) : ℚ_[p])‖ :=
norm_div _ _
_ = ‖F.eval z‖ / ‖F.derivative.eval a‖ := by simp [hz.1]
_ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n / ‖F.derivative.eval a‖ := by
gcongr
apply hz.2
_ = ‖F.derivative.eval a‖ * T ^ 2 ^ n := div_sq_cancel _ _
_ ≤ 1 := mul_le_one₀ (PadicInt.norm_le_one _) (T_pow_nonneg _) (le_of_lt (T_pow' hnorm _))
private theorem calc_deriv_dist {z z' z1 : ℤ_[p]} (hz' : z' = z - z1)
(hz1 : ‖z1‖ = ‖F.eval z‖ / ‖F.derivative.eval a‖) {n} (hz : ih n z) :
‖F.derivative.eval z' - F.derivative.eval z‖ < ‖F.derivative.eval a‖ :=
calc
| ‖F.derivative.eval z' - F.derivative.eval z‖ ≤ ‖z' - z‖ := padic_polynomial_dist _ _ _
_ = ‖z1‖ := by simp only [sub_eq_add_neg, add_assoc, hz', add_add_neg_cancel'_right, norm_neg]
_ = ‖F.eval z‖ / ‖F.derivative.eval a‖ := hz1
_ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n / ‖F.derivative.eval a‖ := by
gcongr
apply hz.2
_ = ‖F.derivative.eval a‖ * T ^ 2 ^ n := div_sq_cancel _ _
_ < ‖F.derivative.eval a‖ := (mul_lt_iff_lt_one_right (deriv_norm_pos hnorm)).2
(T_pow' hnorm _)
private def calc_eval_z' {z z' z1 : ℤ_[p]} (hz' : z' = z - z1) {n} (hz : ih n z)
(h1 : ‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ ≤ 1) (hzeq : z1 = ⟨_, h1⟩) :
| Mathlib/NumberTheory/Padics/Hensel.lean | 163 | 175 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Nat.ModEq
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.NumberTheory.Zsqrtd.Basic
/-!
# Pell's equation and Matiyasevic's theorem
This file solves Pell's equation, i.e. integer solutions to `x ^ 2 - d * y ^ 2 = 1`
*in the special case that `d = a ^ 2 - 1`*.
This is then applied to prove Matiyasevic's theorem that the power
function is Diophantine, which is the last key ingredient in the solution to Hilbert's tenth
problem. For the definition of Diophantine function, see `NumberTheory.Dioph`.
For results on Pell's equation for arbitrary (positive, non-square) `d`, see
`NumberTheory.Pell`.
## Main definition
* `pell` is a function assigning to a natural number `n` the `n`-th solution to Pell's equation
constructed recursively from the initial solution `(0, 1)`.
## Main statements
* `eq_pell` shows that every solution to Pell's equation is recursively obtained using `pell`
* `matiyasevic` shows that a certain system of Diophantine equations has a solution if and only if
the first variable is the `x`-component in a solution to Pell's equation - the key step towards
Hilbert's tenth problem in Davis' version of Matiyasevic's theorem.
* `eq_pow_of_pell` shows that the power function is Diophantine.
## Implementation notes
The proof of Matiyasevic's theorem doesn't follow Matiyasevic's original account of using Fibonacci
numbers but instead Davis' variant of using solutions to Pell's equation.
## References
* [M. Carneiro, _A Lean formalization of Matiyasevič's theorem_][carneiro2018matiyasevic]
* [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916]
## Tags
Pell's equation, Matiyasevic's theorem, Hilbert's tenth problem
-/
namespace Pell
open Nat
section
variable {d : ℤ}
/-- The property of being a solution to the Pell equation, expressed
as a property of elements of `ℤ√d`. -/
def IsPell : ℤ√d → Prop
| ⟨x, y⟩ => x * x - d * y * y = 1
theorem isPell_norm : ∀ {b : ℤ√d}, IsPell b ↔ b * star b = 1
| ⟨x, y⟩ => by simp [Zsqrtd.ext_iff, IsPell, mul_comm]; ring_nf
theorem isPell_iff_mem_unitary : ∀ {b : ℤ√d}, IsPell b ↔ b ∈ unitary (ℤ√d)
| ⟨x, y⟩ => by rw [unitary.mem_iff, isPell_norm, mul_comm (star _), and_self_iff]
theorem isPell_mul {b c : ℤ√d} (hb : IsPell b) (hc : IsPell c) : IsPell (b * c) :=
isPell_norm.2 (by simp [mul_comm, mul_left_comm c, mul_assoc,
star_mul, isPell_norm.1 hb, isPell_norm.1 hc])
theorem isPell_star : ∀ {b : ℤ√d}, IsPell b ↔ IsPell (star b)
| ⟨x, y⟩ => by simp [IsPell, Zsqrtd.star_mk]
end
section
variable {a : ℕ} (a1 : 1 < a)
private def d (_a1 : 1 < a) :=
a * a - 1
@[simp]
theorem d_pos : 0 < d a1 :=
tsub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) (by decide) (Nat.zero_le _) : 1 * 1 < a * a)
-- TODO(lint): Fix double namespace issue
/-- The Pell sequences, i.e. the sequence of integer solutions to `x ^ 2 - d * y ^ 2 = 1`, where
`d = a ^ 2 - 1`, defined together in mutual recursion. -/
--@[nolint dup_namespace]
def pell : ℕ → ℕ × ℕ
| 0 => (1, 0)
| n+1 => ((pell n).1 * a + d a1 * (pell n).2, (pell n).1 + (pell n).2 * a)
/-- The Pell `x` sequence. -/
def xn (n : ℕ) : ℕ :=
(pell a1 n).1
/-- The Pell `y` sequence. -/
def yn (n : ℕ) : ℕ :=
(pell a1 n).2
@[simp]
theorem pell_val (n : ℕ) : pell a1 n = (xn a1 n, yn a1 n) :=
show pell a1 n = ((pell a1 n).1, (pell a1 n).2) from
match pell a1 n with
| (_, _) => rfl
@[simp]
theorem xn_zero : xn a1 0 = 1 :=
rfl
@[simp]
theorem yn_zero : yn a1 0 = 0 :=
rfl
@[simp]
theorem xn_succ (n : ℕ) : xn a1 (n + 1) = xn a1 n * a + d a1 * yn a1 n :=
rfl
@[simp]
theorem yn_succ (n : ℕ) : yn a1 (n + 1) = xn a1 n + yn a1 n * a :=
rfl
theorem xn_one : xn a1 1 = a := by simp
theorem yn_one : yn a1 1 = 1 := by simp
/-- The Pell `x` sequence, considered as an integer sequence. -/
def xz (n : ℕ) : ℤ :=
xn a1 n
/-- The Pell `y` sequence, considered as an integer sequence. -/
def yz (n : ℕ) : ℤ :=
yn a1 n
section
/-- The element `a` such that `d = a ^ 2 - 1`, considered as an integer. -/
def az (a : ℕ) : ℤ :=
a
end
include a1 in
theorem asq_pos : 0 < a * a :=
le_trans (le_of_lt a1)
(by have := @Nat.mul_le_mul_left 1 a a (le_of_lt a1); rwa [mul_one] at this)
theorem dz_val : ↑(d a1) = az a * az a - 1 :=
have : 1 ≤ a * a := asq_pos a1
by rw [Pell.d, Int.ofNat_sub this]; rfl
@[simp]
theorem xz_succ (n : ℕ) : (xz a1 (n + 1)) = xz a1 n * az a + d a1 * yz a1 n :=
rfl
@[simp]
theorem yz_succ (n : ℕ) : yz a1 (n + 1) = xz a1 n + yz a1 n * az a :=
rfl
/-- The Pell sequence can also be viewed as an element of `ℤ√d` -/
def pellZd (n : ℕ) : ℤ√(d a1) :=
⟨xn a1 n, yn a1 n⟩
@[simp]
theorem pellZd_re (n : ℕ) : (pellZd a1 n).re = xn a1 n :=
rfl
@[simp]
theorem pellZd_im (n : ℕ) : (pellZd a1 n).im = yn a1 n :=
rfl
theorem isPell_nat {x y : ℕ} : IsPell (⟨x, y⟩ : ℤ√(d a1)) ↔ x * x - d a1 * y * y = 1 :=
⟨fun h =>
(Nat.cast_inj (R := ℤ)).1
(by rw [Int.ofNat_sub (Int.le_of_ofNat_le_ofNat <| Int.le.intro_sub _ h)]; exact h),
fun h =>
show ((x * x : ℕ) - (d a1 * y * y : ℕ) : ℤ) = 1 by
rw [← Int.ofNat_sub <| le_of_lt <| Nat.lt_of_sub_eq_succ h, h]; rfl⟩
@[simp]
theorem pellZd_succ (n : ℕ) : pellZd a1 (n + 1) = pellZd a1 n * ⟨a, 1⟩ := by ext <;> simp
theorem isPell_one : IsPell (⟨a, 1⟩ : ℤ√(d a1)) :=
show az a * az a - d a1 * 1 * 1 = 1 by simp [dz_val]
theorem isPell_pellZd : ∀ n : ℕ, IsPell (pellZd a1 n)
| 0 => rfl
| n + 1 => by
let o := isPell_one a1
simpa using Pell.isPell_mul (isPell_pellZd n) o
@[simp]
theorem pell_eqz (n : ℕ) : xz a1 n * xz a1 n - d a1 * yz a1 n * yz a1 n = 1 :=
isPell_pellZd a1 n
@[simp]
theorem pell_eq (n : ℕ) : xn a1 n * xn a1 n - d a1 * yn a1 n * yn a1 n = 1 :=
let pn := pell_eqz a1 n
have h : (↑(xn a1 n * xn a1 n) : ℤ) - ↑(d a1 * yn a1 n * yn a1 n) = 1 := by
repeat' rw [Int.natCast_mul]; exact pn
have hl : d a1 * yn a1 n * yn a1 n ≤ xn a1 n * xn a1 n :=
Nat.cast_le.1 <| Int.le.intro _ <| add_eq_of_eq_sub' <| Eq.symm h
(Nat.cast_inj (R := ℤ)).1 (by rw [Int.ofNat_sub hl]; exact h)
instance dnsq : Zsqrtd.Nonsquare (d a1) :=
⟨fun n h =>
have : n * n + 1 = a * a := by rw [← h]; exact Nat.succ_pred_eq_of_pos (asq_pos a1)
have na : n < a := Nat.mul_self_lt_mul_self_iff.1 (by rw [← this]; exact Nat.lt_succ_self _)
have : (n + 1) * (n + 1) ≤ n * n + 1 := by rw [this]; exact Nat.mul_self_le_mul_self na
have : n + n ≤ 0 :=
@Nat.le_of_add_le_add_right _ (n * n + 1) _ (by ring_nf at this ⊢; assumption)
Nat.ne_of_gt (d_pos a1) <| by
rwa [Nat.eq_zero_of_le_zero ((Nat.le_add_left _ _).trans this)] at h⟩
theorem xn_ge_a_pow : ∀ n : ℕ, a ^ n ≤ xn a1 n
| 0 => le_refl 1
| n + 1 => by
simp only [_root_.pow_succ, xn_succ]
exact le_trans (Nat.mul_le_mul_right _ (xn_ge_a_pow n)) (Nat.le_add_right _ _)
theorem n_lt_xn (n) : n < xn a1 n :=
lt_of_lt_of_le (Nat.lt_pow_self a1) (xn_ge_a_pow a1 n)
theorem x_pos (n) : 0 < xn a1 n :=
lt_of_le_of_lt (Nat.zero_le n) (n_lt_xn a1 n)
theorem eq_pell_lem : ∀ (n) (b : ℤ√(d a1)), 1 ≤ b → IsPell b →
b ≤ pellZd a1 n → ∃ n, b = pellZd a1 n
| 0, _ => fun h1 _ hl => ⟨0, @Zsqrtd.le_antisymm _ (dnsq a1) _ _ hl h1⟩
| n + 1, b => fun h1 hp h =>
have a1p : (0 : ℤ√(d a1)) ≤ ⟨a, 1⟩ := trivial
have am1p : (0 : ℤ√(d a1)) ≤ ⟨a, -1⟩ := show (_ : Nat) ≤ _ by simp; exact Nat.pred_le _
have a1m : (⟨a, 1⟩ * ⟨a, -1⟩ : ℤ√(d a1)) = 1 := isPell_norm.1 (isPell_one a1)
if ha : (⟨↑a, 1⟩ : ℤ√(d a1)) ≤ b then
let ⟨m, e⟩ :=
eq_pell_lem n (b * ⟨a, -1⟩) (by rw [← a1m]; exact mul_le_mul_of_nonneg_right ha am1p)
(isPell_mul hp (isPell_star.1 (isPell_one a1)))
(by
have t := mul_le_mul_of_nonneg_right h am1p
rwa [pellZd_succ, mul_assoc, a1m, mul_one] at t)
⟨m + 1, by
rw [show b = b * ⟨a, -1⟩ * ⟨a, 1⟩ by rw [mul_assoc, Eq.trans (mul_comm _ _) a1m]; simp,
pellZd_succ, e]⟩
else
suffices ¬1 < b from ⟨0, show b = 1 from (Or.resolve_left (lt_or_eq_of_le h1) this).symm⟩
fun h1l => by
obtain ⟨x, y⟩ := b
exact by
have bm : (_ * ⟨_, _⟩ : ℤ√d a1) = 1 := Pell.isPell_norm.1 hp
have y0l : (0 : ℤ√d a1) < ⟨x - x, y - -y⟩ :=
sub_lt_sub h1l fun hn : (1 : ℤ√d a1) ≤ ⟨x, -y⟩ => by
have t := mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1)
rw [bm, mul_one] at t
exact h1l t
have yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩ :=
show (⟨x, y⟩ - ⟨x, -y⟩ : ℤ√d a1) < ⟨a, 1⟩ - ⟨a, -1⟩ from
sub_lt_sub ha fun hn : (⟨x, -y⟩ : ℤ√d a1) ≤ ⟨a, -1⟩ => by
have t := mul_le_mul_of_nonneg_right
(mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1)) a1p
rw [bm, one_mul, mul_assoc, Eq.trans (mul_comm _ _) a1m, mul_one] at t
exact ha t
simp only [sub_self, sub_neg_eq_add] at y0l; simp only [Zsqrtd.neg_re, add_neg_cancel,
Zsqrtd.neg_im, neg_neg] at yl2
exact
match y, y0l, (yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩) with
| 0, y0l, _ => y0l (le_refl 0)
| (y + 1 : ℕ), _, yl2 =>
yl2
(Zsqrtd.le_of_le_le (by simp [sub_eq_add_neg])
(let t := Int.ofNat_le_ofNat_of_le (Nat.succ_pos y)
add_le_add t t))
| Int.negSucc _, y0l, _ => y0l trivial
theorem eq_pellZd (b : ℤ√(d a1)) (b1 : 1 ≤ b) (hp : IsPell b) : ∃ n, b = pellZd a1 n :=
let ⟨n, h⟩ := @Zsqrtd.le_arch (d a1) b
eq_pell_lem a1 n b b1 hp <|
h.trans <| by
rw [Zsqrtd.natCast_val]
exact
Zsqrtd.le_of_le_le (Int.ofNat_le_ofNat_of_le <| le_of_lt <| n_lt_xn _ _)
(Int.ofNat_zero_le _)
/-- Every solution to **Pell's equation** is recursively obtained from the initial solution
`(1,0)` using the recursion `pell`. -/
theorem eq_pell {x y : ℕ} (hp : x * x - d a1 * y * y = 1) : ∃ n, x = xn a1 n ∧ y = yn a1 n :=
have : (1 : ℤ√(d a1)) ≤ ⟨x, y⟩ :=
match x, hp with
| 0, (hp : 0 - _ = 1) => by rw [zero_tsub] at hp; contradiction
| x + 1, _hp =>
Zsqrtd.le_of_le_le (Int.ofNat_le_ofNat_of_le <| Nat.succ_pos x) (Int.ofNat_zero_le _)
let ⟨m, e⟩ := eq_pellZd a1 ⟨x, y⟩ this ((isPell_nat a1).2 hp)
⟨m,
match x, y, e with
| _, _, rfl => ⟨rfl, rfl⟩⟩
theorem pellZd_add (m) : ∀ n, pellZd a1 (m + n) = pellZd a1 m * pellZd a1 n
| 0 => (mul_one _).symm
| n + 1 => by rw [← add_assoc, pellZd_succ, pellZd_succ, pellZd_add _ n, ← mul_assoc]
theorem xn_add (m n) : xn a1 (m + n) = xn a1 m * xn a1 n + d a1 * yn a1 m * yn a1 n := by
injection pellZd_add a1 m n with h _
zify
rw [h]
simp [pellZd]
theorem yn_add (m n) : yn a1 (m + n) = xn a1 m * yn a1 n + yn a1 m * xn a1 n := by
injection pellZd_add a1 m n with _ h
zify
rw [h]
simp [pellZd]
theorem pellZd_sub {m n} (h : n ≤ m) : pellZd a1 (m - n) = pellZd a1 m * star (pellZd a1 n) := by
let t := pellZd_add a1 n (m - n)
rw [add_tsub_cancel_of_le h] at t
rw [t, mul_comm (pellZd _ n) _, mul_assoc, isPell_norm.1 (isPell_pellZd _ _), mul_one]
theorem xz_sub {m n} (h : n ≤ m) :
xz a1 (m - n) = xz a1 m * xz a1 n - d a1 * yz a1 m * yz a1 n := by
rw [sub_eq_add_neg, ← mul_neg]
exact congr_arg Zsqrtd.re (pellZd_sub a1 h)
theorem yz_sub {m n} (h : n ≤ m) : yz a1 (m - n) = xz a1 n * yz a1 m - xz a1 m * yz a1 n := by
rw [sub_eq_add_neg, ← mul_neg, mul_comm, add_comm]
exact congr_arg Zsqrtd.im (pellZd_sub a1 h)
theorem xy_coprime (n) : (xn a1 n).Coprime (yn a1 n) :=
Nat.coprime_of_dvd' fun k _ kx ky => by
let p := pell_eq a1 n
rw [← p]
exact Nat.dvd_sub (kx.mul_left _) (ky.mul_left _)
theorem strictMono_y : StrictMono (yn a1)
| _, 0, h => absurd h <| Nat.not_lt_zero _
| m, n + 1, h => by
have : yn a1 m ≤ yn a1 n :=
Or.elim (lt_or_eq_of_le <| Nat.le_of_succ_le_succ h) (fun hl => le_of_lt <| strictMono_y hl)
fun e => by rw [e]
simp only [yn_succ, gt_iff_lt]; refine lt_of_le_of_lt ?_ (Nat.lt_add_of_pos_left <| x_pos a1 n)
rw [← mul_one (yn a1 m)]
exact mul_le_mul this (le_of_lt a1) (Nat.zero_le _) (Nat.zero_le _)
theorem strictMono_x : StrictMono (xn a1)
| _, 0, h => absurd h <| Nat.not_lt_zero _
| m, n + 1, h => by
have : xn a1 m ≤ xn a1 n :=
Or.elim (lt_or_eq_of_le <| Nat.le_of_succ_le_succ h) (fun hl => le_of_lt <| strictMono_x hl)
fun e => by rw [e]
simp only [xn_succ, gt_iff_lt]
refine lt_of_lt_of_le (lt_of_le_of_lt this ?_) (Nat.le_add_right _ _)
have t := Nat.mul_lt_mul_of_pos_left a1 (x_pos a1 n)
rwa [mul_one] at t
theorem yn_ge_n : ∀ n, n ≤ yn a1 n
| 0 => Nat.zero_le _
| n + 1 =>
show n < yn a1 (n + 1) from lt_of_le_of_lt (yn_ge_n n) (strictMono_y a1 <| Nat.lt_succ_self n)
theorem y_mul_dvd (n) : ∀ k, yn a1 n ∣ yn a1 (n * k)
| 0 => dvd_zero _
| k + 1 => by
rw [Nat.mul_succ, yn_add]; exact dvd_add (dvd_mul_left _ _) ((y_mul_dvd _ k).mul_right _)
theorem y_dvd_iff (m n) : yn a1 m ∣ yn a1 n ↔ m ∣ n :=
⟨fun h =>
Nat.dvd_of_mod_eq_zero <|
(Nat.eq_zero_or_pos _).resolve_right fun hp => by
have co : Nat.Coprime (yn a1 m) (xn a1 (m * (n / m))) :=
Nat.Coprime.symm <| (xy_coprime a1 _).coprime_dvd_right (y_mul_dvd a1 m (n / m))
have m0 : 0 < m :=
m.eq_zero_or_pos.resolve_left fun e => by
rw [e, Nat.mod_zero] at hp;rw [e] at h
exact _root_.ne_of_lt (strictMono_y a1 hp) (eq_zero_of_zero_dvd h).symm
rw [← Nat.mod_add_div n m, yn_add] at h
exact
not_le_of_gt (strictMono_y _ <| Nat.mod_lt n m0)
(Nat.le_of_dvd (strictMono_y _ hp) <|
co.dvd_of_dvd_mul_right <|
(Nat.dvd_add_iff_right <| (y_mul_dvd _ _ _).mul_left _).2 h),
fun ⟨k, e⟩ => by rw [e]; apply y_mul_dvd⟩
theorem xy_modEq_yn (n) :
∀ k, xn a1 (n * k) ≡ xn a1 n ^ k [MOD yn a1 n ^ 2] ∧ yn a1 (n * k) ≡
k * xn a1 n ^ (k - 1) * yn a1 n [MOD yn a1 n ^ 3]
| 0 => by constructor <;> simpa using Nat.ModEq.refl _
| k + 1 => by
let ⟨hx, hy⟩ := xy_modEq_yn n k
have L : xn a1 (n * k) * xn a1 n + d a1 * yn a1 (n * k) * yn a1 n ≡
xn a1 n ^ k * xn a1 n + 0 [MOD yn a1 n ^ 2] :=
(hx.mul_right _).add <|
modEq_zero_iff_dvd.2 <| by
rw [_root_.pow_succ]
exact
mul_dvd_mul_right
(dvd_mul_of_dvd_right
(modEq_zero_iff_dvd.1 <|
(hy.of_dvd <| by simp [_root_.pow_succ]).trans <|
modEq_zero_iff_dvd.2 <| by simp)
_) _
have R : xn a1 (n * k) * yn a1 n + yn a1 (n * k) * xn a1 n ≡
xn a1 n ^ k * yn a1 n + k * xn a1 n ^ k * yn a1 n [MOD yn a1 n ^ 3] :=
ModEq.add
(by
rw [_root_.pow_succ]
exact hx.mul_right' _) <| by
have : k * xn a1 n ^ (k - 1) * yn a1 n * xn a1 n = k * xn a1 n ^ k * yn a1 n := by
rcases k with - | k <;> simp [_root_.pow_succ]; ring_nf
rw [← this]
exact hy.mul_right _
rw [add_tsub_cancel_right, Nat.mul_succ, xn_add, yn_add, pow_succ (xn _ n), Nat.succ_mul,
add_comm (k * xn _ n ^ k) (xn _ n ^ k), right_distrib]
exact ⟨L, R⟩
theorem ysq_dvd_yy (n) : yn a1 n * yn a1 n ∣ yn a1 (n * yn a1 n) :=
modEq_zero_iff_dvd.1 <|
((xy_modEq_yn a1 n (yn a1 n)).right.of_dvd <| by simp [_root_.pow_succ]).trans
(modEq_zero_iff_dvd.2 <| by simp [mul_dvd_mul_left, mul_assoc])
theorem dvd_of_ysq_dvd {n t} (h : yn a1 n * yn a1 n ∣ yn a1 t) : yn a1 n ∣ t :=
have nt : n ∣ t := (y_dvd_iff a1 n t).1 <| dvd_of_mul_left_dvd h
n.eq_zero_or_pos.elim (fun n0 => by rwa [n0] at nt ⊢) fun n0l : 0 < n => by
let ⟨k, ke⟩ := nt
have : yn a1 n ∣ k * xn a1 n ^ (k - 1) :=
Nat.dvd_of_mul_dvd_mul_right (strictMono_y a1 n0l) <|
modEq_zero_iff_dvd.1 <| by
have xm := (xy_modEq_yn a1 n k).right; rw [← ke] at xm
exact (xm.of_dvd <| by simp [_root_.pow_succ]).symm.trans h.modEq_zero_nat
rw [ke]
exact dvd_mul_of_dvd_right (((xy_coprime _ _).pow_left _).symm.dvd_of_dvd_mul_right this) _
theorem pellZd_succ_succ (n) :
pellZd a1 (n + 2) + pellZd a1 n = (2 * a : ℕ) * pellZd a1 (n + 1) := by
have : (1 : ℤ√(d a1)) + ⟨a, 1⟩ * ⟨a, 1⟩ = ⟨a, 1⟩ * (2 * a) := by
rw [Zsqrtd.natCast_val]
change (⟨_, _⟩ : ℤ√(d a1)) = ⟨_, _⟩
rw [dz_val]
dsimp [az]
ext <;> dsimp <;> ring_nf
simpa [mul_add, mul_comm, mul_left_comm, add_comm] using congr_arg (· * pellZd a1 n) this
theorem xy_succ_succ (n) :
xn a1 (n + 2) + xn a1 n =
2 * a * xn a1 (n + 1) ∧ yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) := by
have := pellZd_succ_succ a1 n; unfold pellZd at this
rw [Zsqrtd.nsmul_val (2 * a : ℕ)] at this
injection this with h₁ h₂
constructor <;> apply Int.ofNat.inj <;> [simpa using h₁; simpa using h₂]
theorem xn_succ_succ (n) : xn a1 (n + 2) + xn a1 n = 2 * a * xn a1 (n + 1) :=
(xy_succ_succ a1 n).1
theorem yn_succ_succ (n) : yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) :=
(xy_succ_succ a1 n).2
theorem xz_succ_succ (n) : xz a1 (n + 2) = (2 * a : ℕ) * xz a1 (n + 1) - xz a1 n :=
eq_sub_of_add_eq <| by delta xz; rw [← Int.natCast_add, ← Int.natCast_mul, xn_succ_succ]
theorem yz_succ_succ (n) : yz a1 (n + 2) = (2 * a : ℕ) * yz a1 (n + 1) - yz a1 n :=
eq_sub_of_add_eq <| by delta yz; rw [← Int.natCast_add, ← Int.natCast_mul, yn_succ_succ]
theorem yn_modEq_a_sub_one : ∀ n, yn a1 n ≡ n [MOD a - 1]
| 0 => by simp [Nat.ModEq.refl]
| 1 => by simp [Nat.ModEq.refl]
| n + 2 =>
(yn_modEq_a_sub_one n).add_right_cancel <| by
rw [yn_succ_succ, (by ring : n + 2 + n = 2 * (n + 1))]
exact ((modEq_sub a1.le).mul_left 2).mul (yn_modEq_a_sub_one (n + 1))
theorem yn_modEq_two : ∀ n, yn a1 n ≡ n [MOD 2]
| 0 => by rfl
| 1 => by simp; rfl
| n + 2 =>
(yn_modEq_two n).add_right_cancel <| by
rw [yn_succ_succ, mul_assoc, (by ring : n + 2 + n = 2 * (n + 1))]
exact (dvd_mul_right 2 _).modEq_zero_nat.trans (dvd_mul_right 2 _).zero_modEq_nat
section
theorem x_sub_y_dvd_pow_lem (y2 y1 y0 yn1 yn0 xn1 xn0 ay a2 : ℤ) :
(a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) =
y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0) := by
ring
end
theorem x_sub_y_dvd_pow (y : ℕ) :
∀ n, (2 * a * y - y * y - 1 : ℤ) ∣ yz a1 n * (a - y) + ↑(y ^ n) - xz a1 n
| 0 => by simp [xz, yz, Int.ofNat_zero, Int.ofNat_one]
| 1 => by simp [xz, yz, Int.ofNat_zero, Int.ofNat_one]
| n + 2 => by
have : (2 * a * y - y * y - 1 : ℤ) ∣ ↑(y ^ (n + 2)) - ↑(2 * a) * ↑(y ^ (n + 1)) + ↑(y ^ n) :=
⟨-↑(y ^ n), by
simp [_root_.pow_succ, mul_add, Int.natCast_mul, show ((2 : ℕ) : ℤ) = 2 from rfl, mul_comm,
mul_left_comm]
ring⟩
rw [xz_succ_succ, yz_succ_succ, x_sub_y_dvd_pow_lem ↑(y ^ (n + 2)) ↑(y ^ (n + 1)) ↑(y ^ n)]
exact _root_.dvd_sub (dvd_add this <| (x_sub_y_dvd_pow _ (n + 1)).mul_left _)
(x_sub_y_dvd_pow _ n)
theorem xn_modEq_x2n_add_lem (n j) : xn a1 n ∣ d a1 * yn a1 n * (yn a1 n * xn a1 j) + xn a1 j := by
have h1 : d a1 * yn a1 n * (yn a1 n * xn a1 j) + xn a1 j =
(d a1 * yn a1 n * yn a1 n + 1) * xn a1 j := by
simp [add_mul, mul_assoc]
have h2 : d a1 * yn a1 n * yn a1 n + 1 = xn a1 n * xn a1 n := by
zify at *
apply add_eq_of_eq_sub' (Eq.symm (pell_eqz a1 n))
rw [h2] at h1; rw [h1, mul_assoc]; exact dvd_mul_right _ _
theorem xn_modEq_x2n_add (n j) : xn a1 (2 * n + j) + xn a1 j ≡ 0 [MOD xn a1 n] := by
rw [two_mul, add_assoc, xn_add, add_assoc, ← zero_add 0]
refine (dvd_mul_right (xn a1 n) (xn a1 (n + j))).modEq_zero_nat.add ?_
rw [yn_add, left_distrib, add_assoc, ← zero_add 0]
exact
((dvd_mul_right _ _).mul_left _).modEq_zero_nat.add (xn_modEq_x2n_add_lem _ _ _).modEq_zero_nat
theorem xn_modEq_x2n_sub_lem {n j} (h : j ≤ n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] := by
have h1 : xz a1 n ∣ d a1 * yz a1 n * yz a1 (n - j) + xz a1 j := by
rw [yz_sub _ h, mul_sub_left_distrib, sub_add_eq_add_sub]
exact
dvd_sub
(by
delta xz; delta yz
rw [mul_comm (xn _ _ : ℤ)]
exact mod_cast (xn_modEq_x2n_add_lem _ n j))
((dvd_mul_right _ _).mul_left _)
rw [two_mul, add_tsub_assoc_of_le h, xn_add, add_assoc, ← zero_add 0]
exact
(dvd_mul_right _ _).modEq_zero_nat.add
(Int.natCast_dvd_natCast.1 <| by simpa [xz, yz] using h1).modEq_zero_nat
theorem xn_modEq_x2n_sub {n j} (h : j ≤ 2 * n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] :=
(le_total j n).elim (xn_modEq_x2n_sub_lem a1) fun jn => by
have : 2 * n - j + j ≤ n + j := by
rw [tsub_add_cancel_of_le h, two_mul]; exact Nat.add_le_add_left jn _
let t := xn_modEq_x2n_sub_lem a1 (Nat.le_of_add_le_add_right this)
rwa [tsub_tsub_cancel_of_le h, add_comm] at t
theorem xn_modEq_x4n_add (n j) : xn a1 (4 * n + j) ≡ xn a1 j [MOD xn a1 n] :=
ModEq.add_right_cancel' (xn a1 (2 * n + j)) <| by
refine @ModEq.trans _ _ 0 _ ?_ (by rw [add_comm]; exact (xn_modEq_x2n_add _ _ _).symm)
rw [show 4 * n = 2 * n + 2 * n from right_distrib 2 2 n, add_assoc]
apply xn_modEq_x2n_add
theorem xn_modEq_x4n_sub {n j} (h : j ≤ 2 * n) : xn a1 (4 * n - j) ≡ xn a1 j [MOD xn a1 n] :=
have h' : j ≤ 2 * n := le_trans h (by rw [Nat.succ_mul])
ModEq.add_right_cancel' (xn a1 (2 * n - j)) <| by
refine @ModEq.trans _ _ 0 _ ?_ (by rw [add_comm]; exact (xn_modEq_x2n_sub _ h).symm)
rw [show 4 * n = 2 * n + 2 * n from right_distrib 2 2 n, add_tsub_assoc_of_le h']
apply xn_modEq_x2n_add
theorem eq_of_xn_modEq_lem1 {i n} : ∀ {j}, i < j → j < n → xn a1 i % xn a1 n < xn a1 j % xn a1 n
| 0, ij, _ => absurd ij (Nat.not_lt_zero _)
| j + 1, ij, jn => by
suffices xn a1 j % xn a1 n < xn a1 (j + 1) % xn a1 n from
(lt_or_eq_of_le (Nat.le_of_succ_le_succ ij)).elim
(fun h => lt_trans (eq_of_xn_modEq_lem1 h (le_of_lt jn)) this) fun h => by
rw [h]; exact this
rw [Nat.mod_eq_of_lt (strictMono_x _ (Nat.lt_of_succ_lt jn)),
Nat.mod_eq_of_lt (strictMono_x _ jn)]
exact strictMono_x _ (Nat.lt_succ_self _)
theorem eq_of_xn_modEq_lem2 {n} (h : 2 * xn a1 n = xn a1 (n + 1)) : a = 2 ∧ n = 0 := by
rw [xn_succ, mul_comm] at h
have : n = 0 :=
n.eq_zero_or_pos.resolve_right fun np =>
_root_.ne_of_lt
(lt_of_le_of_lt (Nat.mul_le_mul_left _ a1)
(Nat.lt_add_of_pos_right <| mul_pos (d_pos a1) (strictMono_y a1 np)))
h
cases this; simp at h; exact ⟨h.symm, rfl⟩
theorem eq_of_xn_modEq_lem3 {i n} (npos : 0 < n) :
∀ {j}, i < j → j ≤ 2 * n → j ≠ n → ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2) →
xn a1 i % xn a1 n < xn a1 j % xn a1 n
| 0, ij, _, _, _ => absurd ij (Nat.not_lt_zero _)
| j + 1, ij, j2n, jnn, ntriv =>
have lem2 : ∀ k > n, k ≤ 2 * n → (↑(xn a1 k % xn a1 n) : ℤ) =
xn a1 n - xn a1 (2 * n - k) := fun k kn k2n => by
let k2nl :=
lt_of_add_lt_add_right <|
show 2 * n - k + k < n + k by
rw [tsub_add_cancel_of_le]
· rw [two_mul]
exact add_lt_add_left kn n
exact k2n
have xle : xn a1 (2 * n - k) ≤ xn a1 n := le_of_lt <| strictMono_x a1 k2nl
suffices xn a1 k % xn a1 n = xn a1 n - xn a1 (2 * n - k) by rw [this, Int.ofNat_sub xle]
rw [← Nat.mod_eq_of_lt (Nat.sub_lt (x_pos a1 n) (x_pos a1 (2 * n - k)))]
apply ModEq.add_right_cancel' (xn a1 (2 * n - k))
rw [tsub_add_cancel_of_le xle]
have t := xn_modEq_x2n_sub_lem a1 k2nl.le
rw [tsub_tsub_cancel_of_le k2n] at t
exact t.trans dvd_rfl.zero_modEq_nat
(lt_trichotomy j n).elim (fun jn : j < n => eq_of_xn_modEq_lem1 _ ij (lt_of_le_of_ne jn jnn))
fun o =>
o.elim
(fun jn : j = n => by
cases jn
apply Int.lt_of_ofNat_lt_ofNat
rw [lem2 (n + 1) (Nat.lt_succ_self _) j2n,
show 2 * n - (n + 1) = n - 1 by
rw [two_mul, tsub_add_eq_tsub_tsub, add_tsub_cancel_right]]
refine lt_sub_left_of_add_lt (Int.ofNat_lt_ofNat_of_lt ?_)
rcases lt_or_eq_of_le <| Nat.le_of_succ_le_succ ij with lin | ein
· rw [Nat.mod_eq_of_lt (strictMono_x _ lin)]
have ll : xn a1 (n - 1) + xn a1 (n - 1) ≤ xn a1 n := by
rw [← two_mul, mul_comm,
show xn a1 n = xn a1 (n - 1 + 1) by rw [tsub_add_cancel_of_le (succ_le_of_lt npos)],
xn_succ]
exact le_trans (Nat.mul_le_mul_left _ a1) (Nat.le_add_right _ _)
have npm : (n - 1).succ = n := Nat.succ_pred_eq_of_pos npos
have il : i ≤ n - 1 := by
apply Nat.le_of_succ_le_succ
rw [npm]
exact lin
rcases lt_or_eq_of_le il with ill | ile
· exact lt_of_lt_of_le (Nat.add_lt_add_left (strictMono_x a1 ill) _) ll
· rw [ile]
apply lt_of_le_of_ne ll
rw [← two_mul]
exact fun e =>
ntriv <| by
let ⟨a2, s1⟩ :=
@eq_of_xn_modEq_lem2 _ a1 (n - 1)
(by rwa [tsub_add_cancel_of_le (succ_le_of_lt npos)])
have n1 : n = 1 := le_antisymm (tsub_eq_zero_iff_le.mp s1) npos
rw [ile, a2, n1]; exact ⟨rfl, rfl, rfl, rfl⟩
· rw [ein, Nat.mod_self, add_zero]
exact strictMono_x _ (Nat.pred_lt npos.ne'))
fun jn : j > n =>
have lem1 : j ≠ n → xn a1 j % xn a1 n < xn a1 (j + 1) % xn a1 n →
xn a1 i % xn a1 n < xn a1 (j + 1) % xn a1 n :=
fun jn s =>
(lt_or_eq_of_le (Nat.le_of_succ_le_succ ij)).elim
(fun h =>
lt_trans
(eq_of_xn_modEq_lem3 npos h (le_of_lt (Nat.lt_of_succ_le j2n)) jn
fun ⟨_, n1, _, j2⟩ => by
rw [n1, j2] at j2n; exact absurd j2n (by decide))
s)
fun h => by rw [h]; exact s
lem1 (_root_.ne_of_gt jn) <|
Int.lt_of_ofNat_lt_ofNat <| by
rw [lem2 j jn (le_of_lt j2n), lem2 (j + 1) (Nat.le_succ_of_le jn) j2n]
refine sub_lt_sub_left (Int.ofNat_lt_ofNat_of_lt <| strictMono_x _ ?_) _
rw [Nat.sub_succ]
exact Nat.pred_lt (_root_.ne_of_gt <| tsub_pos_of_lt j2n)
theorem eq_of_xn_modEq_le {i j n} (ij : i ≤ j) (j2n : j ≤ 2 * n)
(h : xn a1 i ≡ xn a1 j [MOD xn a1 n])
(ntriv : ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2)) : i = j :=
if npos : n = 0 then by simp_all
else
(lt_or_eq_of_le ij).resolve_left fun ij' =>
if jn : j = n then by
refine _root_.ne_of_gt ?_ h
rw [jn, Nat.mod_self]
have x0 : 0 < xn a1 0 % xn a1 n := by
rw [Nat.mod_eq_of_lt (strictMono_x a1 (Nat.pos_of_ne_zero npos))]
exact Nat.succ_pos _
rcases i with - | i
· exact x0
rw [jn] at ij'
exact
x0.trans
(eq_of_xn_modEq_lem3 _ (Nat.pos_of_ne_zero npos) (Nat.succ_pos _) (le_trans ij j2n)
(_root_.ne_of_lt ij') fun ⟨_, n1, _, i2⟩ => by
rw [n1, i2] at ij'; exact absurd ij' (by decide))
else _root_.ne_of_lt (eq_of_xn_modEq_lem3 a1 (Nat.pos_of_ne_zero npos) ij' j2n jn ntriv) h
theorem eq_of_xn_modEq {i j n} (i2n : i ≤ 2 * n) (j2n : j ≤ 2 * n)
(h : xn a1 i ≡ xn a1 j [MOD xn a1 n])
(ntriv : a = 2 → n = 1 → (i = 0 → j ≠ 2) ∧ (i = 2 → j ≠ 0)) : i = j :=
(le_total i j).elim
(fun ij => eq_of_xn_modEq_le a1 ij j2n h fun ⟨a2, n1, i0, j2⟩ => (ntriv a2 n1).left i0 j2)
fun ij =>
(eq_of_xn_modEq_le a1 ij i2n h.symm fun ⟨a2, n1, j0, i2⟩ => (ntriv a2 n1).right i2 j0).symm
theorem eq_of_xn_modEq' {i j n} (ipos : 0 < i) (hin : i ≤ n) (j4n : j ≤ 4 * n)
(h : xn a1 j ≡ xn a1 i [MOD xn a1 n]) : j = i ∨ j + i = 4 * n :=
have i2n : i ≤ 2 * n := by apply le_trans hin; rw [two_mul]; apply Nat.le_add_left
(le_or_gt j (2 * n)).imp
(fun j2n : j ≤ 2 * n =>
eq_of_xn_modEq a1 j2n i2n h fun _ n1 =>
⟨fun _ i2 => by rw [n1, i2] at hin; exact absurd hin (by decide), fun _ i0 =>
_root_.ne_of_gt ipos i0⟩)
fun j2n : 2 * n < j =>
suffices i = 4 * n - j by rw [this, add_tsub_cancel_of_le j4n]
have j42n : 4 * n - j ≤ 2 * n := by omega
eq_of_xn_modEq a1 i2n j42n
(h.symm.trans <| by
let t := xn_modEq_x4n_sub a1 j42n
rwa [tsub_tsub_cancel_of_le j4n] at t)
(by omega)
theorem modEq_of_xn_modEq {i j n} (ipos : 0 < i) (hin : i ≤ n)
(h : xn a1 j ≡ xn a1 i [MOD xn a1 n]) :
j ≡ i [MOD 4 * n] ∨ j + i ≡ 0 [MOD 4 * n] :=
let j' := j % (4 * n)
have n4 : 0 < 4 * n := mul_pos (by decide) (ipos.trans_le hin)
have jl : j' < 4 * n := Nat.mod_lt _ n4
have jj : j ≡ j' [MOD 4 * n] := by delta ModEq; rw [Nat.mod_eq_of_lt jl]
have : ∀ j q, xn a1 (j + 4 * n * q) ≡ xn a1 j [MOD xn a1 n] := by
intro j q; induction q with
| zero => simp [ModEq.refl]
| succ q IH =>
rw [Nat.mul_succ, ← add_assoc, add_comm]
exact (xn_modEq_x4n_add _ _ _).trans IH
Or.imp (fun ji : j' = i => by rwa [← ji])
(fun ji : j' + i = 4 * n =>
(jj.add_right _).trans <| by
rw [ji]
exact dvd_rfl.modEq_zero_nat)
(eq_of_xn_modEq' a1 ipos hin jl.le <|
(h.symm.trans <| by
rw [← Nat.mod_add_div j (4 * n)]
exact this j' _).symm)
end
theorem xy_modEq_of_modEq {a b c} (a1 : 1 < a) (b1 : 1 < b) (h : a ≡ b [MOD c]) :
∀ n, xn a1 n ≡ xn b1 n [MOD c] ∧ yn a1 n ≡ yn b1 n [MOD c]
| 0 => by constructor <;> rfl
| 1 => by simpa using ⟨h, ModEq.refl 1⟩
| n + 2 =>
⟨(xy_modEq_of_modEq a1 b1 h n).left.add_right_cancel <| by
rw [xn_succ_succ a1, xn_succ_succ b1]
exact (h.mul_left _).mul (xy_modEq_of_modEq _ _ h (n + 1)).left,
(xy_modEq_of_modEq a1 b1 h n).right.add_right_cancel <| by
rw [yn_succ_succ a1, yn_succ_succ b1]
exact (h.mul_left _).mul (xy_modEq_of_modEq _ _ h (n + 1)).right⟩
theorem matiyasevic {a k x y} :
(∃ a1 : 1 < a, xn a1 k = x ∧ yn a1 k = y) ↔
1 < a ∧ k ≤ y ∧ (x = 1 ∧ y = 0 ∨
∃ u v s t b : ℕ,
x * x - (a * a - 1) * y * y = 1 ∧ u * u - (a * a - 1) * v * v = 1 ∧
s * s - (b * b - 1) * t * t = 1 ∧ 1 < b ∧ b ≡ 1 [MOD 4 * y] ∧
b ≡ a [MOD u] ∧ 0 < v ∧ y * y ∣ v ∧ s ≡ x [MOD u] ∧ t ≡ k [MOD 4 * y]) :=
⟨fun ⟨a1, hx, hy⟩ => by
rw [← hx, ← hy]
refine ⟨a1,
(Nat.eq_zero_or_pos k).elim (fun k0 => by rw [k0]; exact ⟨le_rfl, Or.inl ⟨rfl, rfl⟩⟩)
fun kpos => ?_⟩
exact
let x := xn a1 k
let y := yn a1 k
let m := 2 * (k * y)
let u := xn a1 m
let v := yn a1 m
have ky : k ≤ y := yn_ge_n a1 k
have yv : y * y ∣ v := (ysq_dvd_yy a1 k).trans <| (y_dvd_iff _ _ _).2 <| dvd_mul_left _ _
have uco : Nat.Coprime u (4 * y) :=
have : 2 ∣ v :=
modEq_zero_iff_dvd.1 <| (yn_modEq_two _ _).trans (dvd_mul_right _ _).modEq_zero_nat
have : Nat.Coprime u 2 := (xy_coprime a1 m).coprime_dvd_right this
(this.mul_right this).mul_right <|
(xy_coprime _ _).coprime_dvd_right (dvd_of_mul_left_dvd yv)
let ⟨b, ba, bm1⟩ := chineseRemainder uco a 1
have m1 : 1 < m :=
have : 0 < k * y := mul_pos kpos (strictMono_y a1 kpos)
Nat.mul_le_mul_left 2 this
have vp : 0 < v := strictMono_y a1 (lt_trans zero_lt_one m1)
have b1 : 1 < b :=
have : xn a1 1 < u := strictMono_x a1 m1
have : a < u := by simpa using this
lt_of_lt_of_le a1 <| by
delta ModEq at ba; rw [Nat.mod_eq_of_lt this] at ba; rw [← ba]
apply Nat.mod_le
let s := xn b1 k
let t := yn b1 k
have sx : s ≡ x [MOD u] := (xy_modEq_of_modEq b1 a1 ba k).left
have tk : t ≡ k [MOD 4 * y] :=
have : 4 * y ∣ b - 1 :=
Int.natCast_dvd_natCast.1 <| by rw [Int.ofNat_sub (le_of_lt b1)]; exact bm1.symm.dvd
(yn_modEq_a_sub_one _ _).of_dvd this
⟨ky,
Or.inr
⟨u, v, s, t, b, pell_eq _ _, pell_eq _ _, pell_eq _ _, b1, bm1, ba, vp, yv, sx, tk⟩⟩,
fun ⟨a1, ky, o⟩ =>
⟨a1,
match o with
| Or.inl ⟨x1, y0⟩ => by
rw [y0] at ky; rw [Nat.eq_zero_of_le_zero ky, x1, y0]; exact ⟨rfl, rfl⟩
| Or.inr ⟨u, v, s, t, b, xy, uv, st, b1, rem⟩ =>
match x, y, eq_pell a1 xy, u, v, eq_pell a1 uv, s, t, eq_pell b1 st, rem, ky with
| _, _, ⟨i, rfl, rfl⟩, _, _, ⟨n, rfl, rfl⟩, _, _, ⟨j, rfl, rfl⟩,
⟨(bm1 : b ≡ 1 [MOD 4 * yn a1 i]), (ba : b ≡ a [MOD xn a1 n]), (vp : 0 < yn a1 n),
(yv : yn a1 i * yn a1 i ∣ yn a1 n), (sx : xn b1 j ≡ xn a1 i [MOD xn a1 n]),
(tk : yn b1 j ≡ k [MOD 4 * yn a1 i])⟩,
(ky : k ≤ yn a1 i) =>
(Nat.eq_zero_or_pos i).elim
(fun i0 => by
simp only [i0, yn_zero, nonpos_iff_eq_zero] at ky; rw [i0, ky]; exact ⟨rfl, rfl⟩)
fun ipos => by
suffices i = k by rw [this]; exact ⟨rfl, rfl⟩
clear o rem xy uv st
have iln : i ≤ n :=
le_of_not_gt fun hin =>
not_lt_of_ge (Nat.le_of_dvd vp (dvd_of_mul_left_dvd yv)) (strictMono_y a1 hin)
have yd : 4 * yn a1 i ∣ 4 * n := mul_dvd_mul_left _ <| dvd_of_ysq_dvd a1 yv
have jk : j ≡ k [MOD 4 * yn a1 i] :=
have : 4 * yn a1 i ∣ b - 1 :=
Int.natCast_dvd_natCast.1 <| by rw [Int.ofNat_sub (le_of_lt b1)]; exact bm1.symm.dvd
((yn_modEq_a_sub_one b1 _).of_dvd this).symm.trans tk
have ki : k + i < 4 * yn a1 i :=
lt_of_le_of_lt (_root_.add_le_add ky (yn_ge_n a1 i)) <| by
rw [← two_mul]
exact Nat.mul_lt_mul_of_pos_right (by decide) (strictMono_y a1 ipos)
have ji : j ≡ i [MOD 4 * n] :=
have : xn a1 j ≡ xn a1 i [MOD xn a1 n] :=
(xy_modEq_of_modEq b1 a1 ba j).left.symm.trans sx
(modEq_of_xn_modEq a1 ipos iln this).resolve_right
fun ji : j + i ≡ 0 [MOD 4 * n] =>
not_le_of_gt ki <|
Nat.le_of_dvd (lt_of_lt_of_le ipos <| Nat.le_add_left _ _) <|
modEq_zero_iff_dvd.1 <| (jk.symm.add_right i).trans <| ji.of_dvd yd
have : i % (4 * yn a1 i) = k % (4 * yn a1 i) := (ji.of_dvd yd).symm.trans jk
rwa [Nat.mod_eq_of_lt (lt_of_le_of_lt (Nat.le_add_left _ _) ki),
Nat.mod_eq_of_lt (lt_of_le_of_lt (Nat.le_add_right _ _) ki)] at this⟩⟩
theorem eq_pow_of_pell_lem {a y k : ℕ} (hy0 : y ≠ 0) (hk0 : k ≠ 0) (hyk : y ^ k < a) :
(↑(y ^ k) : ℤ) < 2 * a * y - y * y - 1 :=
have hya : y < a := (Nat.le_self_pow hk0 _).trans_lt hyk
calc
(↑(y ^ k) : ℤ) < a := Nat.cast_lt.2 hyk
_ ≤ (a : ℤ) ^ 2 - (a - 1 : ℤ) ^ 2 - 1 := by
rw [sub_sq, mul_one, one_pow, sub_add, sub_sub_cancel, two_mul, sub_sub, ← add_sub,
le_add_iff_nonneg_right, sub_nonneg, Int.add_one_le_iff]
norm_cast
exact lt_of_le_of_lt (Nat.succ_le_of_lt (Nat.pos_of_ne_zero hy0)) hya
_ ≤ (a : ℤ) ^ 2 - (a - y : ℤ) ^ 2 - 1 := by
have := hya.le
gcongr <;> norm_cast <;> omega
_ = 2 * a * y - y * y - 1 := by ring
theorem eq_pow_of_pell {m n k} :
n ^ k = m ↔ k = 0 ∧ m = 1 ∨0 < k ∧ (n = 0 ∧ m = 0 ∨
0 < n ∧ ∃ (w a t z : ℕ) (a1 : 1 < a), xn a1 k ≡ yn a1 k * (a - n) + m [MOD t] ∧
2 * a * n = t + (n * n + 1) ∧ m < t ∧
n ≤ w ∧ k ≤ w ∧ a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1) := by
constructor
· rintro rfl
refine k.eq_zero_or_pos.imp (fun k0 : k = 0 => k0.symm ▸ ⟨rfl, rfl⟩) fun hk => ⟨hk, ?_⟩
refine n.eq_zero_or_pos.imp (fun n0 : n = 0 ↦ n0.symm ▸ ⟨rfl, zero_pow hk.ne'⟩)
fun hn ↦ ⟨hn, ?_⟩
set w := max n k
have nw : n ≤ w := le_max_left _ _
have kw : k ≤ w := le_max_right _ _
have wpos : 0 < w := hn.trans_le nw
have w1 : 1 < w + 1 := Nat.succ_lt_succ wpos
set a := xn w1 w
have a1 : 1 < a := strictMono_x w1 wpos
have na : n ≤ a := nw.trans (n_lt_xn w1 w).le
set x := xn a1 k
set y := yn a1 k
obtain ⟨z, ze⟩ : w ∣ yn w1 w :=
modEq_zero_iff_dvd.1 ((yn_modEq_a_sub_one w1 w).trans dvd_rfl.modEq_zero_nat)
have nt : (↑(n ^ k) : ℤ) < 2 * a * n - n * n - 1 := by
refine eq_pow_of_pell_lem hn.ne' hk.ne' ?_
calc
n ^ k ≤ n ^ w := Nat.pow_le_pow_right hn kw
_ < (w + 1) ^ w := Nat.pow_lt_pow_left (Nat.lt_succ_of_le nw) wpos.ne'
_ ≤ a := xn_ge_a_pow w1 w
lift (2 * a * n - n * n - 1 : ℤ) to ℕ using (Nat.cast_nonneg _).trans nt.le with t te
have tm : x ≡ y * (a - n) + n ^ k [MOD t] := by
apply modEq_of_dvd
rw [Int.natCast_add, Int.natCast_mul, Int.ofNat_sub na, te]
exact x_sub_y_dvd_pow a1 n k
have ta : 2 * a * n = t + (n * n + 1) := by
zify
omega
have zp : a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1 := ze ▸ pell_eq w1 w
exact ⟨w, a, t, z, a1, tm, ta, Nat.cast_lt.1 nt, nw, kw, zp⟩
· rintro (⟨rfl, rfl⟩ | ⟨hk0, ⟨rfl, rfl⟩ | ⟨hn0, w, a, t, z, a1, tm, ta, mt, nw, kw, zp⟩⟩)
· exact _root_.pow_zero n
· exact zero_pow hk0.ne'
have hw0 : 0 < w := hn0.trans_le nw
have hw1 : 1 < w + 1 := Nat.succ_lt_succ hw0
rcases eq_pell hw1 zp with ⟨j, rfl, yj⟩
have hj0 : 0 < j := by
apply Nat.pos_of_ne_zero
rintro rfl
exact lt_irrefl 1 a1
have wj : w ≤ j :=
Nat.le_of_dvd hj0
(modEq_zero_iff_dvd.1 <|
(yn_modEq_a_sub_one hw1 j).symm.trans <| modEq_zero_iff_dvd.2 ⟨z, yj.symm⟩)
have hnka : n ^ k < xn hw1 j := calc
n ^ k ≤ n ^ j := Nat.pow_le_pow_right hn0 (le_trans kw wj)
_ < (w + 1) ^ j := Nat.pow_lt_pow_left (Nat.lt_succ_of_le nw) hj0.ne'
_ ≤ xn hw1 j := xn_ge_a_pow hw1 j
have nt : (↑(n ^ k) : ℤ) < 2 * xn hw1 j * n - n * n - 1 :=
eq_pow_of_pell_lem hn0.ne' hk0.ne' hnka
have na : n ≤ xn hw1 j := (Nat.le_self_pow hk0.ne' _).trans hnka.le
have te : (t : ℤ) = 2 * xn hw1 j * n - n * n - 1 := by
rw [sub_sub, eq_sub_iff_add_eq]
exact mod_cast ta.symm
have : xn a1 k ≡ yn a1 k * (xn hw1 j - n) + n ^ k [MOD t] := by
apply modEq_of_dvd
rw [te, Nat.cast_add, Nat.cast_mul, Int.ofNat_sub na]
exact x_sub_y_dvd_pow a1 n k
have : n ^ k % t = m % t := (this.symm.trans tm).add_left_cancel' _
rw [← te] at nt
rwa [Nat.mod_eq_of_lt (Nat.cast_lt.1 nt), Nat.mod_eq_of_lt mt] at this
end Pell
| Mathlib/NumberTheory/PellMatiyasevic.lean | 942 | 1,011 | |
/-
Copyright (c) 2024 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Cardinal.Arithmetic
import Mathlib.SetTheory.Ordinal.Principal
/-!
# Ordinal arithmetic with cardinals
This file collects results about the cardinality of different ordinal operations.
-/
universe u v
open Cardinal Ordinal Set
/-! ### Cardinal operations with ordinal indices -/
namespace Cardinal
/-- Bounds the cardinal of an ordinal-indexed union of sets. -/
lemma mk_iUnion_Ordinal_lift_le_of_le {β : Type v} {o : Ordinal.{u}} {c : Cardinal.{v}}
(ho : lift.{v} o.card ≤ lift.{u} c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β)
(hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by
simp_rw [← mem_Iio, biUnion_eq_iUnion, iUnion, iSup, ← o.enumIsoToType.symm.surjective.range_comp]
rw [← lift_le.{u}]
apply ((mk_iUnion_le_lift _).trans _).trans_eq (mul_eq_self (aleph0_le_lift.2 hc))
rw [mk_toType]
refine mul_le_mul' ho (ciSup_le' ?_)
intro i
simpa using hA _ (o.enumIsoToType.symm i).2
lemma mk_iUnion_Ordinal_le_of_le {β : Type*} {o : Ordinal} {c : Cardinal}
(ho : o.card ≤ c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β)
(hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by
apply mk_iUnion_Ordinal_lift_le_of_le _ hc A hA
rwa [Cardinal.lift_le]
end Cardinal
@[deprecated mk_iUnion_Ordinal_le_of_le (since := "2024-11-02")]
alias Ordinal.Cardinal.mk_iUnion_Ordinal_le_of_le := mk_iUnion_Ordinal_le_of_le
/-! ### Cardinality of ordinals -/
namespace Ordinal
theorem lift_card_iSup_le_sum_card {ι : Type u} [Small.{v} ι] (f : ι → Ordinal.{v}) :
Cardinal.lift.{u} (⨆ i, f i).card ≤ Cardinal.sum fun i ↦ (f i).card := by
simp_rw [← mk_toType]
rw [← mk_sigma, ← Cardinal.lift_id'.{v} #(Σ _, _), ← Cardinal.lift_umax.{v, u}]
apply lift_mk_le_lift_mk_of_surjective (f := enumIsoToType _ ∘ (⟨(enumIsoToType _).symm ·.2,
(mem_Iio.mp ((enumIsoToType _).symm _).2).trans_le (Ordinal.le_iSup _ _)⟩))
rw [EquivLike.comp_surjective]
rintro ⟨x, hx⟩
obtain ⟨i, hi⟩ := Ordinal.lt_iSup_iff.mp hx
exact ⟨⟨i, enumIsoToType _ ⟨x, hi⟩⟩, by simp⟩
theorem card_iSup_le_sum_card {ι : Type u} (f : ι → Ordinal.{max u v}) :
(⨆ i, f i).card ≤ Cardinal.sum (fun i ↦ (f i).card) := by
have := lift_card_iSup_le_sum_card f
rwa [Cardinal.lift_id'] at this
theorem card_iSup_Iio_le_sum_card {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) :
(⨆ a : Iio o, f a).card ≤ Cardinal.sum fun i ↦ (f ((enumIsoToType o).symm i)).card := by
apply le_of_eq_of_le (congr_arg _ _).symm (card_iSup_le_sum_card _)
simpa using (enumIsoToType o).symm.iSup_comp (g := fun x ↦ f x)
theorem card_iSup_Iio_le_card_mul_iSup {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) :
(⨆ a : Iio o, f a).card ≤ Cardinal.lift.{v} o.card * ⨆ a : Iio o, (f a).card := by
apply (card_iSup_Iio_le_sum_card f).trans
convert ← sum_le_iSup_lift _
· exact mk_toType o
· exact (enumIsoToType o).symm.iSup_comp (g := fun x ↦ (f x).card)
theorem card_opow_le_of_omega0_le_left {a : Ordinal} (ha : ω ≤ a) (b : Ordinal) :
(a ^ b).card ≤ max a.card b.card := by
refine limitRecOn b ?_ ?_ ?_
· simpa using one_lt_omega0.le.trans ha
· intro b IH
rw [opow_succ, card_mul, card_succ, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm]
· apply (max_le_max_left _ IH).trans
rw [← max_assoc, max_self]
exact max_le_max_left _ le_self_add
· rw [ne_eq, card_eq_zero, opow_eq_zero]
rintro ⟨rfl, -⟩
cases omega0_pos.not_le ha
· rwa [aleph0_le_card]
· intro b hb IH
rw [(isNormal_opow (one_lt_omega0.trans_le ha)).apply_of_isLimit hb]
apply (card_iSup_Iio_le_card_mul_iSup _).trans
rw [Cardinal.lift_id, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm]
· apply max_le _ (le_max_right _ _)
apply ciSup_le'
intro c
exact (IH c.1 c.2).trans (max_le_max_left _ (card_le_card c.2.le))
· simpa using hb.pos.ne'
· refine le_ciSup_of_le ?_ ⟨1, one_lt_omega0.trans_le <| omega0_le_of_isLimit hb⟩ ?_
· exact Cardinal.bddAbove_of_small _
· simpa
theorem card_opow_le_of_omega0_le_right (a : Ordinal) {b : Ordinal} (hb : ω ≤ b) :
(a ^ b).card ≤ max a.card b.card := by
obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a
· apply (card_le_card <| opow_le_opow_left b (nat_lt_omega0 n).le).trans
apply (card_opow_le_of_omega0_le_left le_rfl _).trans
simp [hb]
· exact card_opow_le_of_omega0_le_left ha b
theorem card_opow_le (a b : Ordinal) : (a ^ b).card ≤ max ℵ₀ (max a.card b.card) := by
obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a
· obtain ⟨m, rfl⟩ | hb := eq_nat_or_omega0_le b
· rw [← natCast_opow, card_nat]
exact le_max_of_le_left (nat_lt_aleph0 _).le
· exact (card_opow_le_of_omega0_le_right _ hb).trans (le_max_right _ _)
· exact (card_opow_le_of_omega0_le_left ha _).trans (le_max_right _ _)
theorem card_opow_eq_of_omega0_le_left {a b : Ordinal} (ha : ω ≤ a) (hb : 0 < b) :
(a ^ b).card = max a.card b.card := by
apply (card_opow_le_of_omega0_le_left ha b).antisymm (max_le _ _) <;> apply card_le_card
· exact left_le_opow a hb
· exact right_le_opow b (one_lt_omega0.trans_le ha)
theorem card_opow_eq_of_omega0_le_right {a b : Ordinal} (ha : 1 < a) (hb : ω ≤ b) :
(a ^ b).card = max a.card b.card := by
apply (card_opow_le_of_omega0_le_right a hb).antisymm (max_le _ _) <;> apply card_le_card
· exact left_le_opow a (omega0_pos.trans_le hb)
· exact right_le_opow b ha
theorem card_omega0_opow {a : Ordinal} (h : a ≠ 0) : card (ω ^ a) = max ℵ₀ a.card := by
rw [card_opow_eq_of_omega0_le_left le_rfl h.bot_lt, card_omega0]
theorem card_opow_omega0 {a : Ordinal} (h : 1 < a) : card (a ^ ω) = max ℵ₀ a.card := by
rw [card_opow_eq_of_omega0_le_right h le_rfl, card_omega0, max_comm]
theorem principal_opow_omega (o : Ordinal) : Principal (· ^ ·) (ω_ o) := by
obtain rfl | ho := Ordinal.eq_zero_or_pos o
· rw [omega_zero]
exact principal_opow_omega0
· intro a b ha hb
rw [lt_omega_iff_card_lt] at ha hb ⊢
apply (card_opow_le a b).trans_lt (max_lt _ (max_lt ha hb))
rwa [← aleph_zero, aleph_lt_aleph]
theorem IsInitial.principal_opow {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) :
Principal (· ^ ·) o := by
obtain ⟨a, rfl⟩ := mem_range_omega_iff.2 ⟨ho, h⟩
exact principal_opow_omega a
theorem principal_opow_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· ^ ·) c.ord := by
apply (isInitial_ord c).principal_opow
rwa [omega0_le_ord]
/-! ### Initial ordinals are principal -/
theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· + ·) c.ord := by
intro a b ha hb
rw [lt_ord, card_add] at *
exact add_lt_of_lt hc ha hb
theorem IsInitial.principal_add {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) :
Principal (· + ·) o := by
rw [← h.ord_card]
apply principal_add_ord
rwa [aleph0_le_card]
theorem principal_add_omega (o : Ordinal) : Principal (· + ·) (ω_ o) :=
(isInitial_omega o).principal_add (omega0_le_omega o)
theorem principal_mul_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· * ·) c.ord := by
intro a b ha hb
rw [lt_ord, card_mul] at *
exact mul_lt_of_lt hc ha hb
theorem IsInitial.principal_mul {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) :
Principal (· * ·) o := by
rw [← h.ord_card]
apply principal_mul_ord
rwa [aleph0_le_card]
theorem principal_mul_omega (o : Ordinal) : Principal (· * ·) (ω_ o) :=
(isInitial_omega o).principal_mul (omega0_le_omega o)
@[deprecated principal_add_omega (since := "2024-11-08")]
theorem _root_.Cardinal.principal_add_aleph (o : Ordinal) : Principal (· + ·) (ℵ_ o).ord :=
principal_add_ord <| aleph0_le_aleph o
end Ordinal
| Mathlib/SetTheory/Cardinal/Ordinal.lean | 216 | 222 | |
/-
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.SpecificLimits.Basic
import Mathlib.Topology.MetricSpace.HausdorffDistance
import Mathlib.Topology.Sets.Compacts
/-!
# Closed subsets
This file defines the metric and emetric space structure on the types of closed subsets and nonempty
compact subsets of a metric or emetric space.
The Hausdorff distance induces an emetric space structure on the type of closed subsets
of an emetric space, called `Closeds`. Its completeness, resp. compactness, resp.
second-countability, follow from the corresponding properties of the original space.
In a metric space, the type of nonempty compact subsets (called `NonemptyCompacts`) also
inherits a metric space structure from the Hausdorff distance, as the Hausdorff edistance is
always finite in this context.
-/
noncomputable section
universe u
open Set Function TopologicalSpace Filter Topology ENNReal
namespace EMetric
section
variable {α : Type u} [EMetricSpace α] {s : Set α}
/-- In emetric spaces, the Hausdorff edistance defines an emetric space structure
on the type of closed subsets -/
instance Closeds.emetricSpace : EMetricSpace (Closeds α) where
edist s t := hausdorffEdist (s : Set α) t
edist_self _ := hausdorffEdist_self
edist_comm _ _ := hausdorffEdist_comm
edist_triangle _ _ _ := hausdorffEdist_triangle
eq_of_edist_eq_zero {s t} h :=
Closeds.ext <| (hausdorffEdist_zero_iff_eq_of_closed s.isClosed t.isClosed).1 h
/-- The edistance to a closed set depends continuously on the point and the set -/
theorem continuous_infEdist_hausdorffEdist :
Continuous fun p : α × Closeds α => infEdist p.1 p.2 := by
refine continuous_of_le_add_edist 2 (by simp) ?_
rintro ⟨x, s⟩ ⟨y, t⟩
calc
infEdist x s ≤ infEdist x t + hausdorffEdist (t : Set α) s :=
infEdist_le_infEdist_add_hausdorffEdist
_ ≤ infEdist y t + edist x y + hausdorffEdist (t : Set α) s :=
(add_le_add_right infEdist_le_infEdist_add_edist _)
_ = infEdist y t + (edist x y + hausdorffEdist (s : Set α) t) := by
rw [add_assoc, hausdorffEdist_comm]
_ ≤ infEdist y t + (edist (x, s) (y, t) + edist (x, s) (y, t)) :=
(add_le_add_left (add_le_add (le_max_left _ _) (le_max_right _ _)) _)
_ = infEdist y t + 2 * edist (x, s) (y, t) := by rw [← mul_two, mul_comm]
/-- Subsets of a given closed subset form a closed set -/
theorem isClosed_subsets_of_isClosed (hs : IsClosed s) :
IsClosed { t : Closeds α | (t : Set α) ⊆ s } := by
refine isClosed_of_closure_subset fun
(t : Closeds α) (ht : t ∈ closure {t : Closeds α | (t : Set α) ⊆ s}) (x : α) (hx : x ∈ t) => ?_
have : x ∈ closure s := by
refine mem_closure_iff.2 fun ε εpos => ?_
obtain ⟨u : Closeds α, hu : u ∈ {t : Closeds α | (t : Set α) ⊆ s}, Dtu : edist t u < ε⟩ :=
mem_closure_iff.1 ht ε εpos
obtain ⟨y : α, hy : y ∈ u, Dxy : edist x y < ε⟩ := exists_edist_lt_of_hausdorffEdist_lt hx Dtu
exact ⟨y, hu hy, Dxy⟩
| rwa [hs.closure_eq] at this
/-- By definition, the edistance on `Closeds α` is given by the Hausdorff edistance -/
theorem Closeds.edist_eq {s t : Closeds α} : edist s t = hausdorffEdist (s : Set α) t :=
rfl
/-- In a complete space, the type of closed subsets is complete for the
Hausdorff edistance. -/
instance Closeds.completeSpace [CompleteSpace α] : CompleteSpace (Closeds α) := by
/- We will show that, if a sequence of sets `s n` satisfies
`edist (s n) (s (n+1)) < 2^{-n}`, then it converges. This is enough to guarantee
| Mathlib/Topology/MetricSpace/Closeds.lean | 74 | 84 |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.NAry
import Mathlib.Data.Finset.Slice
import Mathlib.Data.Set.Sups
/-!
# Set family operations
This file defines a few binary operations on `Finset α` for use in set family combinatorics.
## Main declarations
* `Finset.sups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`.
* `Finset.infs s t`: Finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`.
* `Finset.disjSups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a`
and `b` are disjoint.
* `Finset.diffs`: Finset of elements of the form `a \ b` where `a ∈ s`, `b ∈ t`.
* `Finset.compls`: Finset of elements of the form `aᶜ` where `a ∈ s`.
## Notation
We define the following notation in locale `FinsetFamily`:
* `s ⊻ t` for `Finset.sups`
* `s ⊼ t` for `Finset.infs`
* `s ○ t` for `Finset.disjSups s t`
* `s \\ t` for `Finset.diffs`
* `sᶜˢ` for `Finset.compls`
## References
[B. Bollobás, *Combinatorics*][bollobas1986]
-/
open Function
open SetFamily
variable {F α β : Type*}
namespace Finset
section Sups
variable [DecidableEq α] [DecidableEq β]
variable [SemilatticeSup α] [SemilatticeSup β] [FunLike F α β] [SupHomClass F α β]
variable (s s₁ s₂ t t₁ t₂ u v : Finset α)
/-- `s ⊻ t` is the finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. -/
protected def hasSups : HasSups (Finset α) :=
⟨image₂ (· ⊔ ·)⟩
scoped[FinsetFamily] attribute [instance] Finset.hasSups
open FinsetFamily
variable {s t} {a b c : α}
@[simp]
theorem mem_sups : c ∈ s ⊻ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊔ b = c := by simp [(· ⊻ ·)]
variable (s t)
@[simp, norm_cast]
theorem coe_sups : (↑(s ⊻ t) : Set α) = ↑s ⊻ ↑t :=
coe_image₂ _ _ _
theorem card_sups_le : #(s ⊻ t) ≤ #s * #t := card_image₂_le _ _ _
theorem card_sups_iff : #(s ⊻ t) = #s * #t ↔ (s ×ˢ t : Set (α × α)).InjOn fun x => x.1 ⊔ x.2 :=
card_image₂_iff
variable {s s₁ s₂ t t₁ t₂ u}
theorem sup_mem_sups : a ∈ s → b ∈ t → a ⊔ b ∈ s ⊻ t :=
mem_image₂_of_mem
theorem sups_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊻ t₁ ⊆ s₂ ⊻ t₂ :=
image₂_subset
theorem sups_subset_left : t₁ ⊆ t₂ → s ⊻ t₁ ⊆ s ⊻ t₂ :=
image₂_subset_left
theorem sups_subset_right : s₁ ⊆ s₂ → s₁ ⊻ t ⊆ s₂ ⊻ t :=
image₂_subset_right
lemma image_subset_sups_left : b ∈ t → s.image (· ⊔ b) ⊆ s ⊻ t := image_subset_image₂_left
lemma image_subset_sups_right : a ∈ s → t.image (a ⊔ ·) ⊆ s ⊻ t := image_subset_image₂_right
theorem forall_sups_iff {p : α → Prop} : (∀ c ∈ s ⊻ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊔ b) :=
forall_mem_image₂
@[simp]
theorem sups_subset_iff : s ⊻ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊔ b ∈ u :=
image₂_subset_iff
@[simp]
theorem sups_nonempty : (s ⊻ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image₂_nonempty_iff
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected theorem Nonempty.sups : s.Nonempty → t.Nonempty → (s ⊻ t).Nonempty :=
Nonempty.image₂
theorem Nonempty.of_sups_left : (s ⊻ t).Nonempty → s.Nonempty :=
Nonempty.of_image₂_left
theorem Nonempty.of_sups_right : (s ⊻ t).Nonempty → t.Nonempty :=
Nonempty.of_image₂_right
@[simp]
theorem empty_sups : ∅ ⊻ t = ∅ :=
image₂_empty_left
@[simp]
theorem sups_empty : s ⊻ ∅ = ∅ :=
image₂_empty_right
@[simp]
theorem sups_eq_empty : s ⊻ t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image₂_eq_empty_iff
@[simp] lemma singleton_sups : {a} ⊻ t = t.image (a ⊔ ·) := image₂_singleton_left
@[simp] lemma sups_singleton : s ⊻ {b} = s.image (· ⊔ b) := image₂_singleton_right
theorem singleton_sups_singleton : ({a} ⊻ {b} : Finset α) = {a ⊔ b} :=
image₂_singleton
theorem sups_union_left : (s₁ ∪ s₂) ⊻ t = s₁ ⊻ t ∪ s₂ ⊻ t :=
image₂_union_left
theorem sups_union_right : s ⊻ (t₁ ∪ t₂) = s ⊻ t₁ ∪ s ⊻ t₂ :=
image₂_union_right
theorem sups_inter_subset_left : (s₁ ∩ s₂) ⊻ t ⊆ s₁ ⊻ t ∩ s₂ ⊻ t :=
image₂_inter_subset_left
theorem sups_inter_subset_right : s ⊻ (t₁ ∩ t₂) ⊆ s ⊻ t₁ ∩ s ⊻ t₂ :=
image₂_inter_subset_right
theorem subset_sups {s t : Set α} :
↑u ⊆ s ⊻ t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊻ t' :=
subset_set_image₂
lemma image_sups (f : F) (s t : Finset α) : image f (s ⊻ t) = image f s ⊻ image f t :=
image_image₂_distrib <| map_sup f
lemma map_sups (f : F) (hf) (s t : Finset α) :
map ⟨f, hf⟩ (s ⊻ t) = map ⟨f, hf⟩ s ⊻ map ⟨f, hf⟩ t := by
simpa [map_eq_image] using image_sups f s t
lemma subset_sups_self : s ⊆ s ⊻ s := fun _a ha ↦ mem_sups.2 ⟨_, ha, _, ha, sup_idem _⟩
lemma sups_subset_self : s ⊻ s ⊆ s ↔ SupClosed (s : Set α) := sups_subset_iff
@[simp] lemma sups_eq_self : s ⊻ s = s ↔ SupClosed (s : Set α) := by simp [← coe_inj]
@[simp] lemma univ_sups_univ [Fintype α] : (univ : Finset α) ⊻ univ = univ := by simp
lemma filter_sups_le [DecidableLE α] (s t : Finset α) (a : α) :
{b ∈ s ⊻ t | b ≤ a} = {b ∈ s | b ≤ a} ⊻ {b ∈ t | b ≤ a} := by
simp only [← coe_inj, coe_filter, coe_sups, ← mem_coe, Set.sep_sups_le]
variable (s t u)
lemma biUnion_image_sup_left : s.biUnion (fun a ↦ t.image (a ⊔ ·)) = s ⊻ t := biUnion_image_left
lemma biUnion_image_sup_right : t.biUnion (fun b ↦ s.image (· ⊔ b)) = s ⊻ t := biUnion_image_right
theorem image_sup_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· ⊔ ·)) = s ⊻ t :=
image_uncurry_product _ _ _
theorem sups_assoc : s ⊻ t ⊻ u = s ⊻ (t ⊻ u) := image₂_assoc sup_assoc
theorem sups_comm : s ⊻ t = t ⊻ s := image₂_comm sup_comm
theorem sups_left_comm : s ⊻ (t ⊻ u) = t ⊻ (s ⊻ u) :=
image₂_left_comm sup_left_comm
theorem sups_right_comm : s ⊻ t ⊻ u = s ⊻ u ⊻ t :=
image₂_right_comm sup_right_comm
| theorem sups_sups_sups_comm : s ⊻ t ⊻ (u ⊻ v) = s ⊻ u ⊻ (t ⊻ v) :=
image₂_image₂_image₂_comm sup_sup_sup_comm
| Mathlib/Data/Finset/Sups.lean | 185 | 187 |
/-
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.Algebra.Group.Action.Pi
import Mathlib.Algebra.Order.AbsoluteValue.Basic
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Algebra.Order.Group.MinMax
import Mathlib.Algebra.Ring.Pi
import Mathlib.Data.Setoid.Basic
import Mathlib.GroupTheory.GroupAction.Ring
import Mathlib.Tactic.GCongr
/-!
# Cauchy sequences
A basic theory of Cauchy sequences, used in the construction of the reals and p-adic numbers. Where
applicable, lemmas that will be reused in other contexts have been stated in extra generality.
There are other "versions" of Cauchyness in the library, in particular Cauchy filters in topology.
This is a concrete implementation that is useful for simplicity and computability reasons.
## Important definitions
* `IsCauSeq`: a predicate that says `f : ℕ → β` is Cauchy.
* `CauSeq`: the type of Cauchy sequences valued in type `β` with respect to an absolute value
function `abv`.
## Tags
sequence, cauchy, abs val, absolute value
-/
assert_not_exists Finset Module Submonoid FloorRing Module
variable {α β : Type*}
open IsAbsoluteValue
section
variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] [Ring β]
(abv : β → α) [IsAbsoluteValue abv]
theorem rat_add_continuous_lemma {ε : α} (ε0 : 0 < ε) :
∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ →
abv (a₁ + a₂ - (b₁ + b₂)) < ε :=
⟨ε / 2, half_pos ε0, fun {a₁ a₂ b₁ b₂} h₁ h₂ => by
simpa [add_halves, sub_eq_add_neg, add_comm, add_left_comm, add_assoc] using
lt_of_le_of_lt (abv_add abv _ _) (add_lt_add h₁ h₂)⟩
theorem rat_mul_continuous_lemma {ε K₁ K₂ : α} (ε0 : 0 < ε) :
∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv a₁ < K₁ → abv b₂ < K₂ → abv (a₁ - b₁) < δ →
abv (a₂ - b₂) < δ → abv (a₁ * a₂ - b₁ * b₂) < ε := by
have K0 : (0 : α) < max 1 (max K₁ K₂) := lt_of_lt_of_le zero_lt_one (le_max_left _ _)
have εK := div_pos (half_pos ε0) K0
refine ⟨_, εK, fun {a₁ a₂ b₁ b₂} ha₁ hb₂ h₁ h₂ => ?_⟩
replace ha₁ := lt_of_lt_of_le ha₁ (le_trans (le_max_left _ K₂) (le_max_right 1 _))
replace hb₂ := lt_of_lt_of_le hb₂ (le_trans (le_max_right K₁ _) (le_max_right 1 _))
set M := max 1 (max K₁ K₂)
have : abv (a₁ - b₁) * abv b₂ + abv (a₂ - b₂) * abv a₁ < ε / 2 / M * M + ε / 2 / M * M := by
gcongr
rw [← abv_mul abv, mul_comm, div_mul_cancel₀ _ (ne_of_gt K0), ← abv_mul abv, add_halves] at this
simpa [sub_eq_add_neg, mul_add, add_mul, add_left_comm] using
lt_of_le_of_lt (abv_add abv _ _) this
theorem rat_inv_continuous_lemma {β : Type*} [DivisionRing β] (abv : β → α) [IsAbsoluteValue abv]
{ε K : α} (ε0 : 0 < ε) (K0 : 0 < K) :
∃ δ > 0, ∀ {a b : β}, K ≤ abv a → K ≤ abv b → abv (a - b) < δ → abv (a⁻¹ - b⁻¹) < ε := by
refine ⟨K * ε * K, mul_pos (mul_pos K0 ε0) K0, fun {a b} ha hb h => ?_⟩
have a0 := K0.trans_le ha
have b0 := K0.trans_le hb
rw [inv_sub_inv' ((abv_pos abv).1 a0) ((abv_pos abv).1 b0), abv_mul abv, abv_mul abv, abv_inv abv,
abv_inv abv, abv_sub abv]
refine lt_of_mul_lt_mul_left (lt_of_mul_lt_mul_right ?_ b0.le) a0.le
rw [mul_assoc, inv_mul_cancel_right₀ b0.ne', ← mul_assoc, mul_inv_cancel₀ a0.ne', one_mul]
refine h.trans_le ?_
gcongr
end
/-- A sequence is Cauchy if the distance between its entries tends to zero. -/
@[nolint unusedArguments]
def IsCauSeq {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
{β : Type*} [Ring β] (abv : β → α) (f : ℕ → β) :
Prop :=
∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - f i) < ε
namespace IsCauSeq
variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] [Ring β]
{abv : β → α} [IsAbsoluteValue abv] {f g : ℕ → β}
-- see Note [nolint_ge]
--@[nolint ge_or_gt] -- Porting note: restore attribute
theorem cauchy₂ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε := by
refine (hf _ (half_pos ε0)).imp fun i hi j ij k ik => ?_
rw [← add_halves ε]
refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) ?_)
rw [abv_sub abv]; exact hi _ ik
theorem cauchy₃ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε :=
let ⟨i, H⟩ := hf.cauchy₂ ε0
⟨i, fun _ ij _ jk => H _ (le_trans ij jk) _ ij⟩
lemma bounded (hf : IsCauSeq abv f) : ∃ r, ∀ i, abv (f i) < r := by
obtain ⟨i, h⟩ := hf _ zero_lt_one
set R : ℕ → α := @Nat.rec (fun _ => α) (abv (f 0)) fun i c => max c (abv (f i.succ)) with hR
have : ∀ i, ∀ j ≤ i, abv (f j) ≤ R i := by
refine Nat.rec (by simp [hR]) ?_
rintro i hi j (rfl | hj)
· simp [R]
· exact (hi j hj).trans (le_max_left _ _)
refine ⟨R i + 1, fun j ↦ ?_⟩
obtain hji | hij := le_total j i
· exact (this i _ hji).trans_lt (lt_add_one _)
· simpa using (abv_add abv _ _).trans_lt <| add_lt_add_of_le_of_lt (this i _ le_rfl) (h _ hij)
lemma bounded' (hf : IsCauSeq abv f) (x : α) : ∃ r > x, ∀ i, abv (f i) < r :=
let ⟨r, h⟩ := hf.bounded
⟨max r (x + 1), (lt_add_one x).trans_le (le_max_right _ _),
fun i ↦ (h i).trans_le (le_max_left _ _)⟩
lemma const (x : β) : IsCauSeq abv fun _ ↦ x :=
fun ε ε0 ↦ ⟨0, fun j _ => by simpa [abv_zero] using ε0⟩
theorem add (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f + g) := fun _ ε0 =>
let ⟨_, δ0, Hδ⟩ := rat_add_continuous_lemma abv ε0
let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0)
⟨i, fun _ ij =>
let ⟨H₁, H₂⟩ := H _ le_rfl
Hδ (H₁ _ ij) (H₂ _ ij)⟩
lemma mul (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f * g) := fun _ ε0 =>
let ⟨_, _, hF⟩ := hf.bounded' 0
let ⟨_, _, hG⟩ := hg.bounded' 0
let ⟨_, δ0, Hδ⟩ := rat_mul_continuous_lemma abv ε0
let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0)
⟨i, fun j ij =>
let ⟨H₁, H₂⟩ := H _ le_rfl
Hδ (hF j) (hG i) (H₁ _ ij) (H₂ _ ij)⟩
@[simp] lemma _root_.isCauSeq_neg : IsCauSeq abv (-f) ↔ IsCauSeq abv f := by
simp only [IsCauSeq, Pi.neg_apply, ← neg_sub', abv_neg]
protected alias ⟨of_neg, neg⟩ := isCauSeq_neg
end IsCauSeq
/-- `CauSeq β abv` is the type of `β`-valued Cauchy sequences, with respect to the absolute value
function `abv`. -/
def CauSeq {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
(β : Type*) [Ring β] (abv : β → α) : Type _ :=
{ f : ℕ → β // IsCauSeq abv f }
namespace CauSeq
variable [Field α] [LinearOrder α] [IsStrictOrderedRing α]
section Ring
variable [Ring β] {abv : β → α}
instance : CoeFun (CauSeq β abv) fun _ => ℕ → β :=
⟨Subtype.val⟩
@[ext]
theorem ext {f g : CauSeq β abv} (h : ∀ i, f i = g i) : f = g := Subtype.eq (funext h)
theorem isCauSeq (f : CauSeq β abv) : IsCauSeq abv f :=
f.2
theorem cauchy (f : CauSeq β abv) : ∀ {ε}, 0 < ε → ∃ i, ∀ j ≥ i, abv (f j - f i) < ε := @f.2
/-- Given a Cauchy sequence `f`, create a Cauchy sequence from a sequence `g` with
the same values as `f`. -/
def ofEq (f : CauSeq β abv) (g : ℕ → β) (e : ∀ i, f i = g i) : CauSeq β abv :=
⟨g, fun ε => by rw [show g = f from (funext e).symm]; exact f.cauchy⟩
variable [IsAbsoluteValue abv]
-- see Note [nolint_ge]
-- @[nolint ge_or_gt] -- Porting note: restore attribute
theorem cauchy₂ (f : CauSeq β abv) {ε} :
0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε :=
f.2.cauchy₂
theorem cauchy₃ (f : CauSeq β abv) {ε} : 0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε :=
f.2.cauchy₃
theorem bounded (f : CauSeq β abv) : ∃ r, ∀ i, abv (f i) < r := f.2.bounded
theorem bounded' (f : CauSeq β abv) (x : α) : ∃ r > x, ∀ i, abv (f i) < r := f.2.bounded' x
instance : Add (CauSeq β abv) :=
⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩
@[simp, norm_cast]
theorem coe_add (f g : CauSeq β abv) : ⇑(f + g) = (f : ℕ → β) + g :=
rfl
@[simp, norm_cast]
theorem add_apply (f g : CauSeq β abv) (i : ℕ) : (f + g) i = f i + g i :=
rfl
variable (abv) in
/-- The constant Cauchy sequence. -/
def const (x : β) : CauSeq β abv := ⟨fun _ ↦ x, IsCauSeq.const _⟩
/-- The constant Cauchy sequence -/
local notation "const" => const abv
@[simp, norm_cast]
theorem coe_const (x : β) : (const x : ℕ → β) = Function.const ℕ x :=
rfl
@[simp, norm_cast]
theorem const_apply (x : β) (i : ℕ) : (const x : ℕ → β) i = x :=
rfl
theorem const_inj {x y : β} : (const x : CauSeq β abv) = const y ↔ x = y :=
⟨fun h => congr_arg (fun f : CauSeq β abv => (f : ℕ → β) 0) h, congr_arg _⟩
instance : Zero (CauSeq β abv) :=
⟨const 0⟩
instance : One (CauSeq β abv) :=
⟨const 1⟩
instance : Inhabited (CauSeq β abv) :=
⟨0⟩
@[simp, norm_cast]
theorem coe_zero : ⇑(0 : CauSeq β abv) = 0 :=
rfl
@[simp, norm_cast]
theorem coe_one : ⇑(1 : CauSeq β abv) = 1 :=
rfl
@[simp, norm_cast]
theorem zero_apply (i) : (0 : CauSeq β abv) i = 0 :=
rfl
@[simp, norm_cast]
theorem one_apply (i) : (1 : CauSeq β abv) i = 1 :=
rfl
@[simp]
theorem const_zero : const 0 = 0 :=
rfl
@[simp]
theorem const_one : const 1 = 1 :=
rfl
theorem const_add (x y : β) : const (x + y) = const x + const y :=
rfl
instance : Mul (CauSeq β abv) := ⟨fun f g ↦ ⟨f * g, f.2.mul g.2⟩⟩
@[simp, norm_cast]
theorem coe_mul (f g : CauSeq β abv) : ⇑(f * g) = (f : ℕ → β) * g :=
rfl
@[simp, norm_cast]
theorem mul_apply (f g : CauSeq β abv) (i : ℕ) : (f * g) i = f i * g i :=
rfl
theorem const_mul (x y : β) : const (x * y) = const x * const y :=
rfl
instance : Neg (CauSeq β abv) := ⟨fun f ↦ ⟨-f, f.2.neg⟩⟩
@[simp, norm_cast]
theorem coe_neg (f : CauSeq β abv) : ⇑(-f) = -f :=
rfl
@[simp, norm_cast]
theorem neg_apply (f : CauSeq β abv) (i) : (-f) i = -f i :=
rfl
theorem const_neg (x : β) : const (-x) = -const x :=
rfl
instance : Sub (CauSeq β abv) :=
⟨fun f g => ofEq (f + -g) (fun x => f x - g x) fun i => by simp [sub_eq_add_neg]⟩
@[simp, norm_cast]
theorem coe_sub (f g : CauSeq β abv) : ⇑(f - g) = (f : ℕ → β) - g :=
rfl
@[simp, norm_cast]
theorem sub_apply (f g : CauSeq β abv) (i : ℕ) : (f - g) i = f i - g i :=
rfl
theorem const_sub (x y : β) : const (x - y) = const x - const y :=
rfl
section SMul
variable {G : Type*} [SMul G β] [IsScalarTower G β β]
instance : SMul G (CauSeq β abv) :=
⟨fun a f => (ofEq (const (a • (1 : β)) * f) (a • (f : ℕ → β))) fun _ => smul_one_mul _ _⟩
@[simp, norm_cast]
theorem coe_smul (a : G) (f : CauSeq β abv) : ⇑(a • f) = a • (f : ℕ → β) :=
rfl
@[simp, norm_cast]
theorem smul_apply (a : G) (f : CauSeq β abv) (i : ℕ) : (a • f) i = a • f i :=
rfl
theorem const_smul (a : G) (x : β) : const (a • x) = a • const x :=
rfl
instance : IsScalarTower G (CauSeq β abv) (CauSeq β abv) :=
⟨fun a f g => Subtype.ext <| smul_assoc a (f : ℕ → β) (g : ℕ → β)⟩
end SMul
instance addGroup : AddGroup (CauSeq β abv) :=
Function.Injective.addGroup Subtype.val Subtype.val_injective rfl coe_add coe_neg coe_sub
(fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _
instance instNatCast : NatCast (CauSeq β abv) := ⟨fun n => const n⟩
instance instIntCast : IntCast (CauSeq β abv) := ⟨fun n => const n⟩
instance addGroupWithOne : AddGroupWithOne (CauSeq β abv) :=
Function.Injective.addGroupWithOne Subtype.val Subtype.val_injective rfl rfl
coe_add coe_neg coe_sub
(by intros; rfl)
(by intros; rfl)
(by intros; rfl)
(by intros; rfl)
instance : Pow (CauSeq β abv) ℕ :=
⟨fun f n =>
(ofEq (npowRec n f) fun i => f i ^ n) <| by induction n <;> simp [*, npowRec, pow_succ]⟩
@[simp, norm_cast]
theorem coe_pow (f : CauSeq β abv) (n : ℕ) : ⇑(f ^ n) = (f : ℕ → β) ^ n :=
rfl
@[simp, norm_cast]
theorem pow_apply (f : CauSeq β abv) (n i : ℕ) : (f ^ n) i = f i ^ n :=
rfl
theorem const_pow (x : β) (n : ℕ) : const (x ^ n) = const x ^ n :=
rfl
instance ring : Ring (CauSeq β abv) :=
Function.Injective.ring Subtype.val Subtype.val_injective rfl rfl coe_add coe_mul coe_neg coe_sub
(fun _ _ => coe_smul _ _) (fun _ _ => coe_smul _ _) coe_pow (fun _ => rfl) fun _ => rfl
instance {β : Type*} [CommRing β] {abv : β → α} [IsAbsoluteValue abv] : CommRing (CauSeq β abv) :=
{ CauSeq.ring with
mul_comm := fun a b => ext fun n => by simp [mul_left_comm, mul_comm] }
/-- `LimZero f` holds when `f` approaches 0. -/
def LimZero {abv : β → α} (f : CauSeq β abv) : Prop :=
∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j) < ε
theorem add_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f + g)
| ε, ε0 =>
(exists_forall_ge_and (hf _ <| half_pos ε0) (hg _ <| half_pos ε0)).imp fun _ H j ij => by
let ⟨H₁, H₂⟩ := H _ ij
simpa [add_halves ε] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add H₁ H₂)
theorem mul_limZero_right (f : CauSeq β abv) {g} (hg : LimZero g) : LimZero (f * g)
| ε, ε0 =>
let ⟨F, F0, hF⟩ := f.bounded' 0
(hg _ <| div_pos ε0 F0).imp fun _ H j ij => by
have := mul_lt_mul' (le_of_lt <| hF j) (H _ ij) (abv_nonneg abv _) F0
rwa [mul_comm F, div_mul_cancel₀ _ (ne_of_gt F0), ← abv_mul] at this
theorem mul_limZero_left {f} (g : CauSeq β abv) (hg : LimZero f) : LimZero (f * g)
| ε, ε0 =>
let ⟨G, G0, hG⟩ := g.bounded' 0
(hg _ <| div_pos ε0 G0).imp fun _ H j ij => by
have := mul_lt_mul'' (H _ ij) (hG j) (abv_nonneg abv _) (abv_nonneg abv _)
rwa [div_mul_cancel₀ _ (ne_of_gt G0), ← abv_mul] at this
theorem neg_limZero {f : CauSeq β abv} (hf : LimZero f) : LimZero (-f) := by
rw [← neg_one_mul f]
exact mul_limZero_right _ hf
theorem sub_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f - g) := by
simpa only [sub_eq_add_neg] using add_limZero hf (neg_limZero hg)
theorem limZero_sub_rev {f g : CauSeq β abv} (hfg : LimZero (f - g)) : LimZero (g - f) := by
simpa using neg_limZero hfg
theorem zero_limZero : LimZero (0 : CauSeq β abv)
| ε, ε0 => ⟨0, fun j _ => by simpa [abv_zero abv] using ε0⟩
theorem const_limZero {x : β} : LimZero (const x) ↔ x = 0 :=
⟨fun H =>
(abv_eq_zero abv).1 <|
(eq_of_le_of_forall_lt_imp_le_of_dense (abv_nonneg abv _)) fun _ ε0 =>
let ⟨_, hi⟩ := H _ ε0
le_of_lt <| hi _ le_rfl,
fun e => e.symm ▸ zero_limZero⟩
instance equiv : Setoid (CauSeq β abv) :=
⟨fun f g => LimZero (f - g),
⟨fun f => by simp [zero_limZero],
fun f ε hε => by simpa using neg_limZero f ε hε,
fun fg gh => by simpa using add_limZero fg gh⟩⟩
theorem add_equiv_add {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 + g1 ≈ f2 + g2 := by simpa only [← add_sub_add_comm] using add_limZero hf hg
theorem neg_equiv_neg {f g : CauSeq β abv} (hf : f ≈ g) : -f ≈ -g := by
simpa only [neg_sub'] using neg_limZero hf
theorem sub_equiv_sub {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 - g1 ≈ f2 - g2 := by simpa only [sub_eq_add_neg] using add_equiv_add hf (neg_equiv_neg hg)
theorem equiv_def₃ {f g : CauSeq β abv} (h : f ≈ g) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - g j) < ε :=
(exists_forall_ge_and (h _ <| half_pos ε0) (f.cauchy₃ <| half_pos ε0)).imp fun _ H j ij k jk => by
let ⟨h₁, h₂⟩ := H _ ij
have := lt_of_le_of_lt (abv_add abv (f j - g j) _) (add_lt_add h₁ (h₂ _ jk))
rwa [sub_add_sub_cancel', add_halves] at this
theorem limZero_congr {f g : CauSeq β abv} (h : f ≈ g) : LimZero f ↔ LimZero g :=
⟨fun l => by simpa using add_limZero (Setoid.symm h) l, fun l => by simpa using add_limZero h l⟩
theorem abv_pos_of_not_limZero {f : CauSeq β abv} (hf : ¬LimZero f) :
∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ abv (f j) := by
haveI := Classical.propDecidable
by_contra nk
refine hf fun ε ε0 => ?_
simp? [not_forall] at nk says
simp only [gt_iff_lt, ge_iff_le, not_exists, not_and, not_forall, Classical.not_imp,
not_le] at nk
obtain ⟨i, hi⟩ := f.cauchy₃ (half_pos ε0)
rcases nk _ (half_pos ε0) i with ⟨j, ij, hj⟩
refine ⟨j, fun k jk => ?_⟩
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi j ij k jk) hj)
rwa [sub_add_cancel, add_halves] at this
theorem of_near (f : ℕ → β) (g : CauSeq β abv) (h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - g j) < ε) :
IsCauSeq abv f
| ε, ε0 =>
let ⟨i, hi⟩ := exists_forall_ge_and (h _ (half_pos <| half_pos ε0)) (g.cauchy₃ <| half_pos ε0)
⟨i, fun j ij => by
obtain ⟨h₁, h₂⟩ := hi _ le_rfl; rw [abv_sub abv] at h₁
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi _ ij).1 h₁)
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add this (h₂ _ ij))
rwa [add_halves, add_halves, add_right_comm, sub_add_sub_cancel, sub_add_sub_cancel] at this⟩
theorem not_limZero_of_not_congr_zero {f : CauSeq _ abv} (hf : ¬f ≈ 0) : ¬LimZero f := by
intro h
have : LimZero (f - 0) := by simp [h]
exact hf this
theorem mul_equiv_zero (g : CauSeq _ abv) {f : CauSeq _ abv} (hf : f ≈ 0) : g * f ≈ 0 :=
have : LimZero (f - 0) := hf
have : LimZero (g * f) := mul_limZero_right _ <| by simpa
show LimZero (g * f - 0) by simpa
theorem mul_equiv_zero' (g : CauSeq _ abv) {f : CauSeq _ abv} (hf : f ≈ 0) : f * g ≈ 0 :=
have : LimZero (f - 0) := hf
have : LimZero (f * g) := mul_limZero_left _ <| by simpa
show LimZero (f * g - 0) by simpa
theorem mul_not_equiv_zero {f g : CauSeq _ abv} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) : ¬f * g ≈ 0 :=
fun (this : LimZero (f * g - 0)) => by
have hlz : LimZero (f * g) := by simpa
have hf' : ¬LimZero f := by simpa using show ¬LimZero (f - 0) from hf
have hg' : ¬LimZero g := by simpa using show ¬LimZero (g - 0) from hg
rcases abv_pos_of_not_limZero hf' with ⟨a1, ha1, N1, hN1⟩
rcases abv_pos_of_not_limZero hg' with ⟨a2, ha2, N2, hN2⟩
have : 0 < a1 * a2 := mul_pos ha1 ha2
obtain ⟨N, hN⟩ := hlz _ this
let i := max N (max N1 N2)
have hN' := hN i (le_max_left _ _)
have hN1' := hN1 i (le_trans (le_max_left _ _) (le_max_right _ _))
have hN1' := hN2 i (le_trans (le_max_right _ _) (le_max_right _ _))
apply not_le_of_lt hN'
change _ ≤ abv (_ * _)
rw [abv_mul abv]
gcongr
theorem const_equiv {x y : β} : const x ≈ const y ↔ x = y :=
show LimZero _ ↔ _ by rw [← const_sub, const_limZero, sub_eq_zero]
theorem mul_equiv_mul {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 * g1 ≈ f2 * g2 := by
simpa only [mul_sub, sub_mul, sub_add_sub_cancel]
using add_limZero (mul_limZero_left g1 hf) (mul_limZero_right f2 hg)
theorem smul_equiv_smul {G : Type*} [SMul G β] [IsScalarTower G β β] {f1 f2 : CauSeq β abv} (c : G)
(hf : f1 ≈ f2) : c • f1 ≈ c • f2 := by
simpa [const_smul, smul_one_mul _ _] using
mul_equiv_mul (const_equiv.mpr <| Eq.refl <| c • (1 : β)) hf
theorem pow_equiv_pow {f1 f2 : CauSeq β abv} (hf : f1 ≈ f2) (n : ℕ) : f1 ^ n ≈ f2 ^ n := by
induction n with
| zero => simp only [pow_zero, Setoid.refl]
| succ n ih => simpa only [pow_succ'] using mul_equiv_mul hf ih
end Ring
section IsDomain
variable [Ring β] [IsDomain β] (abv : β → α) [IsAbsoluteValue abv]
theorem one_not_equiv_zero : ¬const abv 1 ≈ const abv 0 := fun h =>
have : ∀ ε > 0, ∃ i, ∀ k, i ≤ k → abv (1 - 0) < ε := h
have h1 : abv 1 ≤ 0 :=
le_of_not_gt fun h2 : 0 < abv 1 =>
(Exists.elim (this _ h2)) fun i hi => lt_irrefl (abv 1) <| by simpa using hi _ le_rfl
have h2 : 0 ≤ abv 1 := abv_nonneg abv _
have : abv 1 = 0 := le_antisymm h1 h2
have : (1 : β) = 0 := (abv_eq_zero abv).mp this
absurd this one_ne_zero
end IsDomain
section DivisionRing
variable [DivisionRing β] {abv : β → α} [IsAbsoluteValue abv]
theorem inv_aux {f : CauSeq β abv} (hf : ¬LimZero f) :
∀ ε > 0, ∃ i, ∀ j ≥ i, abv ((f j)⁻¹ - (f i)⁻¹) < ε
| _, ε0 =>
let ⟨_, K0, HK⟩ := abv_pos_of_not_limZero hf
let ⟨_, δ0, Hδ⟩ := rat_inv_continuous_lemma abv ε0 K0
let ⟨i, H⟩ := exists_forall_ge_and HK (f.cauchy₃ δ0)
⟨i, fun _ ij =>
let ⟨iK, H'⟩ := H _ le_rfl
Hδ (H _ ij).1 iK (H' _ ij)⟩
/-- Given a Cauchy sequence `f` with nonzero limit, create a Cauchy sequence with values equal to
the inverses of the values of `f`. -/
def inv (f : CauSeq β abv) (hf : ¬LimZero f) : CauSeq β abv :=
⟨_, inv_aux hf⟩
@[simp, norm_cast]
theorem coe_inv {f : CauSeq β abv} (hf) : ⇑(inv f hf) = (f : ℕ → β)⁻¹ :=
rfl
@[simp, norm_cast]
theorem inv_apply {f : CauSeq β abv} (hf i) : inv f hf i = (f i)⁻¹ :=
rfl
theorem inv_mul_cancel {f : CauSeq β abv} (hf) : inv f hf * f ≈ 1 := fun ε ε0 =>
let ⟨K, K0, i, H⟩ := abv_pos_of_not_limZero hf
⟨i, fun j ij => by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)), abv_zero abv] using ε0⟩
theorem mul_inv_cancel {f : CauSeq β abv} (hf) : f * inv f hf ≈ 1 := fun ε ε0 =>
let ⟨K, K0, i, H⟩ := abv_pos_of_not_limZero hf
⟨i, fun j ij => by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)), abv_zero abv] using ε0⟩
theorem const_inv {x : β} (hx : x ≠ 0) :
const abv x⁻¹ = inv (const abv x) (by rwa [const_limZero]) :=
rfl
end DivisionRing
section Abs
/-- The constant Cauchy sequence -/
local notation "const" => const abs
/-- The entries of a positive Cauchy sequence eventually have a positive lower bound. -/
def Pos (f : CauSeq α abs) : Prop :=
∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ f j
theorem not_limZero_of_pos {f : CauSeq α abs} : Pos f → ¬LimZero f
| ⟨_, F0, hF⟩, H =>
let ⟨_, h⟩ := exists_forall_ge_and hF (H _ F0)
let ⟨h₁, h₂⟩ := h _ le_rfl
not_lt_of_le h₁ (abs_lt.1 h₂).2
theorem const_pos {x : α} : Pos (const x) ↔ 0 < x :=
⟨fun ⟨_, K0, _, h⟩ => lt_of_lt_of_le K0 (h _ le_rfl), fun h => ⟨x, h, 0, fun _ _ => le_rfl⟩⟩
theorem add_pos {f g : CauSeq α abs} : Pos f → Pos g → Pos (f + g)
| ⟨_, F0, hF⟩, ⟨_, G0, hG⟩ =>
let ⟨i, h⟩ := exists_forall_ge_and hF hG
⟨_, _root_.add_pos F0 G0, i, fun _ ij =>
let ⟨h₁, h₂⟩ := h _ ij
add_le_add h₁ h₂⟩
theorem pos_add_limZero {f g : CauSeq α abs} : Pos f → LimZero g → Pos (f + g)
| ⟨F, F0, hF⟩, H =>
let ⟨i, h⟩ := exists_forall_ge_and hF (H _ (half_pos F0))
⟨_, half_pos F0, i, fun j ij => by
obtain ⟨h₁, h₂⟩ := h j ij
have := add_le_add h₁ (le_of_lt (abs_lt.1 h₂).1)
rwa [← sub_eq_add_neg, sub_self_div_two] at this⟩
protected theorem mul_pos {f g : CauSeq α abs} : Pos f → Pos g → Pos (f * g)
| ⟨_, F0, hF⟩, ⟨_, G0, hG⟩ =>
let ⟨i, h⟩ := exists_forall_ge_and hF hG
⟨_, mul_pos F0 G0, i, fun _ ij =>
let ⟨h₁, h₂⟩ := h _ ij
mul_le_mul h₁ h₂ (le_of_lt G0) (le_trans (le_of_lt F0) h₁)⟩
theorem trichotomy (f : CauSeq α abs) : Pos f ∨ LimZero f ∨ Pos (-f) := by
rcases Classical.em (LimZero f) with h | h <;> simp [*]
rcases abv_pos_of_not_limZero h with ⟨K, K0, hK⟩
rcases exists_forall_ge_and hK (f.cauchy₃ K0) with ⟨i, hi⟩
refine (le_total 0 (f i)).imp ?_ ?_ <;>
refine fun h => ⟨K, K0, i, fun j ij => ?_⟩ <;>
have := (hi _ ij).1 <;>
obtain ⟨h₁, h₂⟩ := hi _ le_rfl
· rwa [abs_of_nonneg] at this
rw [abs_of_nonneg h] at h₁
exact
(le_add_iff_nonneg_right _).1
(le_trans h₁ <| neg_le_sub_iff_le_add'.1 <| le_of_lt (abs_lt.1 <| h₂ _ ij).1)
· rwa [abs_of_nonpos] at this
rw [abs_of_nonpos h] at h₁
rw [← sub_le_sub_iff_right, zero_sub]
exact le_trans (le_of_lt (abs_lt.1 <| h₂ _ ij).2) h₁
instance : LT (CauSeq α abs) :=
⟨fun f g => Pos (g - f)⟩
instance : LE (CauSeq α abs) :=
⟨fun f g => f < g ∨ f ≈ g⟩
theorem lt_of_lt_of_eq {f g h : CauSeq α abs} (fg : f < g) (gh : g ≈ h) : f < h :=
show Pos (h - f) by
convert pos_add_limZero fg (neg_limZero gh) using 1
simp
theorem lt_of_eq_of_lt {f g h : CauSeq α abs} (fg : f ≈ g) (gh : g < h) : f < h := by
have := pos_add_limZero gh (neg_limZero fg)
rwa [← sub_eq_add_neg, sub_sub_sub_cancel_right] at this
theorem lt_trans {f g h : CauSeq α abs} (fg : f < g) (gh : g < h) : f < h :=
show Pos (h - f) by
convert add_pos fg gh using 1
simp
theorem lt_irrefl {f : CauSeq α abs} : ¬f < f
| h => not_limZero_of_pos h (by simp [zero_limZero])
theorem le_of_eq_of_le {f g h : CauSeq α abs} (hfg : f ≈ g) (hgh : g ≤ h) : f ≤ h :=
hgh.elim (Or.inl ∘ CauSeq.lt_of_eq_of_lt hfg) (Or.inr ∘ Setoid.trans hfg)
theorem le_of_le_of_eq {f g h : CauSeq α abs} (hfg : f ≤ g) (hgh : g ≈ h) : f ≤ h :=
hfg.elim (fun h => Or.inl (CauSeq.lt_of_lt_of_eq h hgh)) fun h => Or.inr (Setoid.trans h hgh)
instance : Preorder (CauSeq α abs) where
lt := (· < ·)
le f g := f < g ∨ f ≈ g
le_refl _ := Or.inr (Setoid.refl _)
le_trans _ _ _ fg gh :=
match fg, gh with
| Or.inl fg, Or.inl gh => Or.inl <| lt_trans fg gh
| Or.inl fg, Or.inr gh => Or.inl <| lt_of_lt_of_eq fg gh
| Or.inr fg, Or.inl gh => Or.inl <| lt_of_eq_of_lt fg gh
| Or.inr fg, Or.inr gh => Or.inr <| Setoid.trans fg gh
lt_iff_le_not_le _ _ :=
⟨fun h => ⟨Or.inl h, not_or_intro (mt (lt_trans h) lt_irrefl) (not_limZero_of_pos h)⟩,
fun ⟨h₁, h₂⟩ => h₁.resolve_right (mt (fun h => Or.inr (Setoid.symm h)) h₂)⟩
theorem le_antisymm {f g : CauSeq α abs} (fg : f ≤ g) (gf : g ≤ f) : f ≈ g :=
fg.resolve_left (not_lt_of_le gf)
theorem lt_total (f g : CauSeq α abs) : f < g ∨ f ≈ g ∨ g < f :=
(trichotomy (g - f)).imp_right fun h =>
h.imp (fun h => Setoid.symm h) fun h => by rwa [neg_sub] at h
theorem le_total (f g : CauSeq α abs) : f ≤ g ∨ g ≤ f :=
(or_assoc.2 (lt_total f g)).imp_right Or.inl
theorem const_lt {x y : α} : const x < const y ↔ x < y :=
show Pos _ ↔ _ by rw [← const_sub, const_pos, sub_pos]
theorem const_le {x y : α} : const x ≤ const y ↔ x ≤ y := by
rw [le_iff_lt_or_eq]; exact or_congr const_lt const_equiv
theorem le_of_exists {f g : CauSeq α abs} (h : ∃ i, ∀ j ≥ i, f j ≤ g j) : f ≤ g :=
let ⟨i, hi⟩ := h
(or_assoc.2 (CauSeq.lt_total f g)).elim id fun hgf =>
False.elim
(let ⟨_, hK0, j, hKj⟩ := hgf
not_lt_of_ge (hi (max i j) (le_max_left _ _))
(sub_pos.1 (lt_of_lt_of_le hK0 (hKj _ (le_max_right _ _)))))
theorem exists_gt (f : CauSeq α abs) : ∃ a : α, f < const a :=
let ⟨K, H⟩ := f.bounded
⟨K + 1, 1, zero_lt_one, 0, fun i _ => by
rw [sub_apply, const_apply, le_sub_iff_add_le', add_le_add_iff_right]
exact le_of_lt (abs_lt.1 (H _)).2⟩
theorem exists_lt (f : CauSeq α abs) : ∃ a : α, const a < f :=
let ⟨a, h⟩ := (-f).exists_gt
⟨-a, show Pos _ by rwa [const_neg, sub_neg_eq_add, add_comm, ← sub_neg_eq_add]⟩
-- so named to match `rat_add_continuous_lemma`
theorem rat_sup_continuous_lemma {ε : α} {a₁ a₂ b₁ b₂ : α} :
abs (a₁ - b₁) < ε → abs (a₂ - b₂) < ε → abs (a₁ ⊔ a₂ - b₁ ⊔ b₂) < ε := fun h₁ h₂ =>
(abs_max_sub_max_le_max _ _ _ _).trans_lt (max_lt h₁ h₂)
-- so named to match `rat_add_continuous_lemma`
theorem rat_inf_continuous_lemma {ε : α} {a₁ a₂ b₁ b₂ : α} :
abs (a₁ - b₁) < ε → abs (a₂ - b₂) < ε → abs (a₁ ⊓ a₂ - b₁ ⊓ b₂) < ε := fun h₁ h₂ =>
(abs_min_sub_min_le_max _ _ _ _).trans_lt (max_lt h₁ h₂)
instance : Max (CauSeq α abs) :=
⟨fun f g =>
⟨f ⊔ g, fun _ ε0 =>
(exists_forall_ge_and (f.cauchy₃ ε0) (g.cauchy₃ ε0)).imp fun _ H _ ij =>
let ⟨H₁, H₂⟩ := H _ le_rfl
rat_sup_continuous_lemma (H₁ _ ij) (H₂ _ ij)⟩⟩
instance : Min (CauSeq α abs) :=
⟨fun f g =>
⟨f ⊓ g, fun _ ε0 =>
(exists_forall_ge_and (f.cauchy₃ ε0) (g.cauchy₃ ε0)).imp fun _ H _ ij =>
let ⟨H₁, H₂⟩ := H _ le_rfl
rat_inf_continuous_lemma (H₁ _ ij) (H₂ _ ij)⟩⟩
@[simp, norm_cast]
theorem coe_sup (f g : CauSeq α abs) : ⇑(f ⊔ g) = (f : ℕ → α) ⊔ g :=
rfl
@[simp, norm_cast]
theorem coe_inf (f g : CauSeq α abs) : ⇑(f ⊓ g) = (f : ℕ → α) ⊓ g :=
rfl
theorem sup_limZero {f g : CauSeq α abs} (hf : LimZero f) (hg : LimZero g) : LimZero (f ⊔ g)
| ε, ε0 =>
(exists_forall_ge_and (hf _ ε0) (hg _ ε0)).imp fun _ H j ij => by
let ⟨H₁, H₂⟩ := H _ ij
rw [abs_lt] at H₁ H₂ ⊢
exact ⟨lt_sup_iff.mpr (Or.inl H₁.1), sup_lt_iff.mpr ⟨H₁.2, H₂.2⟩⟩
theorem inf_limZero {f g : CauSeq α abs} (hf : LimZero f) (hg : LimZero g) : LimZero (f ⊓ g)
| ε, ε0 =>
(exists_forall_ge_and (hf _ ε0) (hg _ ε0)).imp fun _ H j ij => by
let ⟨H₁, H₂⟩ := H _ ij
rw [abs_lt] at H₁ H₂ ⊢
exact ⟨lt_inf_iff.mpr ⟨H₁.1, H₂.1⟩, inf_lt_iff.mpr (Or.inl H₁.2)⟩
theorem sup_equiv_sup {a₁ b₁ a₂ b₂ : CauSeq α abs} (ha : a₁ ≈ a₂) (hb : b₁ ≈ b₂) :
a₁ ⊔ b₁ ≈ a₂ ⊔ b₂ := by
intro ε ε0
obtain ⟨ai, hai⟩ := ha ε ε0
obtain ⟨bi, hbi⟩ := hb ε ε0
exact
⟨ai ⊔ bi, fun i hi =>
(abs_max_sub_max_le_max (a₁ i) (b₁ i) (a₂ i) (b₂ i)).trans_lt
(max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))⟩
theorem inf_equiv_inf {a₁ b₁ a₂ b₂ : CauSeq α abs} (ha : a₁ ≈ a₂) (hb : b₁ ≈ b₂) :
a₁ ⊓ b₁ ≈ a₂ ⊓ b₂ := by
intro ε ε0
obtain ⟨ai, hai⟩ := ha ε ε0
obtain ⟨bi, hbi⟩ := hb ε ε0
exact
⟨ai ⊔ bi, fun i hi =>
(abs_min_sub_min_le_max (a₁ i) (b₁ i) (a₂ i) (b₂ i)).trans_lt
(max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))⟩
protected theorem sup_lt {a b c : CauSeq α abs} (ha : a < c) (hb : b < c) : a ⊔ b < c := by
obtain ⟨⟨εa, εa0, ia, ha⟩, ⟨εb, εb0, ib, hb⟩⟩ := ha, hb
refine ⟨εa ⊓ εb, lt_inf_iff.mpr ⟨εa0, εb0⟩, ia ⊔ ib, fun i hi => ?_⟩
have := min_le_min (ha _ (sup_le_iff.mp hi).1) (hb _ (sup_le_iff.mp hi).2)
exact this.trans_eq (min_sub_sub_left _ _ _)
protected theorem lt_inf {a b c : CauSeq α abs} (hb : a < b) (hc : a < c) : a < b ⊓ c := by
obtain ⟨⟨εb, εb0, ib, hb⟩, ⟨εc, εc0, ic, hc⟩⟩ := hb, hc
refine ⟨εb ⊓ εc, lt_inf_iff.mpr ⟨εb0, εc0⟩, ib ⊔ ic, fun i hi => ?_⟩
have := min_le_min (hb _ (sup_le_iff.mp hi).1) (hc _ (sup_le_iff.mp hi).2)
exact this.trans_eq (min_sub_sub_right _ _ _)
@[simp]
protected theorem sup_idem (a : CauSeq α abs) : a ⊔ a = a := Subtype.ext (sup_idem _)
@[simp]
protected theorem inf_idem (a : CauSeq α abs) : a ⊓ a = a := Subtype.ext (inf_idem _)
protected theorem sup_comm (a b : CauSeq α abs) : a ⊔ b = b ⊔ a := Subtype.ext (sup_comm _ _)
protected theorem inf_comm (a b : CauSeq α abs) : a ⊓ b = b ⊓ a := Subtype.ext (inf_comm _ _)
protected theorem sup_eq_right {a b : CauSeq α abs} (h : a ≤ b) : a ⊔ b ≈ b := by
obtain ⟨ε, ε0 : _ < _, i, h⟩ | h := h
· intro _ _
refine ⟨i, fun j hj => ?_⟩
dsimp
rw [← max_sub_sub_right]
rwa [sub_self, max_eq_right, abs_zero]
rw [sub_nonpos, ← sub_nonneg]
exact ε0.le.trans (h _ hj)
· refine Setoid.trans (sup_equiv_sup h (Setoid.refl _)) ?_
rw [CauSeq.sup_idem]
protected theorem inf_eq_right {a b : CauSeq α abs} (h : b ≤ a) : a ⊓ b ≈ b := by
obtain ⟨ε, ε0 : _ < _, i, h⟩ | h := h
· intro _ _
refine ⟨i, fun j hj => ?_⟩
dsimp
rw [← min_sub_sub_right]
rwa [sub_self, min_eq_right, abs_zero]
exact ε0.le.trans (h _ hj)
· refine Setoid.trans (inf_equiv_inf (Setoid.symm h) (Setoid.refl _)) ?_
rw [CauSeq.inf_idem]
protected theorem sup_eq_left {a b : CauSeq α abs} (h : b ≤ a) : a ⊔ b ≈ a := by
simpa only [CauSeq.sup_comm] using CauSeq.sup_eq_right h
protected theorem inf_eq_left {a b : CauSeq α abs} (h : a ≤ b) : a ⊓ b ≈ a := by
simpa only [CauSeq.inf_comm] using CauSeq.inf_eq_right h
protected theorem le_sup_left {a b : CauSeq α abs} : a ≤ a ⊔ b :=
le_of_exists ⟨0, fun _ _ => le_sup_left⟩
protected theorem inf_le_left {a b : CauSeq α abs} : a ⊓ b ≤ a :=
le_of_exists ⟨0, fun _ _ => inf_le_left⟩
protected theorem le_sup_right {a b : CauSeq α abs} : b ≤ a ⊔ b :=
le_of_exists ⟨0, fun _ _ => le_sup_right⟩
protected theorem inf_le_right {a b : CauSeq α abs} : a ⊓ b ≤ b :=
le_of_exists ⟨0, fun _ _ => inf_le_right⟩
protected theorem sup_le {a b c : CauSeq α abs} (ha : a ≤ c) (hb : b ≤ c) : a ⊔ b ≤ c := by
obtain ha | ha := ha
· obtain hb | hb := hb
· exact Or.inl (CauSeq.sup_lt ha hb)
· replace ha := le_of_le_of_eq ha.le (Setoid.symm hb)
refine le_of_le_of_eq (Or.inr ?_) hb
exact CauSeq.sup_eq_right ha
· replace hb := le_of_le_of_eq hb (Setoid.symm ha)
refine le_of_le_of_eq (Or.inr ?_) ha
exact CauSeq.sup_eq_left hb
protected theorem le_inf {a b c : CauSeq α abs} (hb : a ≤ b) (hc : a ≤ c) : a ≤ b ⊓ c := by
obtain hb | hb := hb
· obtain hc | hc := hc
· exact Or.inl (CauSeq.lt_inf hb hc)
· replace hb := le_of_eq_of_le (Setoid.symm hc) hb.le
refine le_of_eq_of_le hc (Or.inr ?_)
exact Setoid.symm (CauSeq.inf_eq_right hb)
· replace hc := le_of_eq_of_le (Setoid.symm hb) hc
refine le_of_eq_of_le hb (Or.inr ?_)
exact Setoid.symm (CauSeq.inf_eq_left hc)
| /-! Note that `DistribLattice (CauSeq α abs)` is not true because there is no `PartialOrder`. -/
protected theorem sup_inf_distrib_left (a b c : CauSeq α abs) : a ⊔ b ⊓ c = (a ⊔ b) ⊓ (a ⊔ c) :=
ext fun _ ↦ max_min_distrib_left _ _ _
| Mathlib/Algebra/Order/CauSeq/Basic.lean | 854 | 859 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Sébastien Gouëzel, Heather Macbeth
-/
import Mathlib.Analysis.Convex.Slope
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Tactic.LinearCombination
/-!
# Collection of convex functions
In this file we prove that the following functions are convex or strictly convex:
* `strictConvexOn_exp` : The exponential function is strictly convex.
* `strictConcaveOn_log_Ioi`, `strictConcaveOn_log_Iio`: `Real.log` is strictly concave on
$(0, +∞)$ and $(-∞, 0)$ respectively.
* `convexOn_rpow`, `strictConvexOn_rpow` : For `p : ℝ`, `fun x ↦ x ^ p` is convex on $[0, +∞)$ when
`1 ≤ p` and strictly convex when `1 < p`.
The proofs in this file are deliberately elementary, *not* by appealing to the sign of the second
derivative. This is in order to keep this file early in the import hierarchy, since it is on the
path to Hölder's and Minkowski's inequalities and after that to Lp spaces and most of measure
theory.
(Strict) concavity of `fun x ↦ x ^ p` for `0 < p < 1` (`0 ≤ p ≤ 1`) can be found in
`Mathlib.Analysis.Convex.SpecificFunctions.Pow`.
## See also
`Mathlib.Analysis.Convex.Mul` for convexity of `x ↦ x ^ n`
-/
open Real Set NNReal
/-- `Real.exp` is strictly convex on the whole real line. -/
theorem strictConvexOn_exp : StrictConvexOn ℝ univ exp := by
apply strictConvexOn_of_slope_strict_mono_adjacent convex_univ
rintro x y z - - hxy hyz
trans exp y
· have h1 : 0 < y - x := by linarith
have h2 : x - y < 0 := by linarith
rw [div_lt_iff₀ h1]
calc
exp y - exp x = exp y - exp y * exp (x - y) := by rw [← exp_add]; ring_nf
_ = exp y * (1 - exp (x - y)) := by ring
_ < exp y * -(x - y) := by gcongr; linarith [add_one_lt_exp h2.ne]
_ = exp y * (y - x) := by ring
· have h1 : 0 < z - y := by linarith
rw [lt_div_iff₀ h1]
calc
exp y * (z - y) < exp y * (exp (z - y) - 1) := by
gcongr _ * ?_
linarith [add_one_lt_exp h1.ne']
_ = exp (z - y) * exp y - exp y := by ring
_ ≤ exp z - exp y := by rw [← exp_add]; ring_nf; rfl
/-- `Real.exp` is convex on the whole real line. -/
theorem convexOn_exp : ConvexOn ℝ univ exp :=
strictConvexOn_exp.convexOn
/-- `Real.log` is strictly concave on `(0, +∞)`. -/
theorem strictConcaveOn_log_Ioi : StrictConcaveOn ℝ (Ioi 0) log := by
apply strictConcaveOn_of_slope_strict_anti_adjacent (convex_Ioi (0 : ℝ))
intro x y z (hx : 0 < x) (hz : 0 < z) hxy hyz
have hy : 0 < y := hx.trans hxy
| trans y⁻¹
· have h : 0 < z - y := by linarith
rw [div_lt_iff₀ h]
have hyz' : 0 < z / y := by positivity
have hyz'' : z / y ≠ 1 := by
contrapose! h
rw [div_eq_one_iff_eq hy.ne'] at h
simp [h]
calc
log z - log y = log (z / y) := by rw [← log_div hz.ne' hy.ne']
_ < z / y - 1 := log_lt_sub_one_of_pos hyz' hyz''
_ = y⁻¹ * (z - y) := by field_simp
· have h : 0 < y - x := by linarith
rw [lt_div_iff₀ h]
have hxy' : 0 < x / y := by positivity
have hxy'' : x / y ≠ 1 := by
contrapose! h
rw [div_eq_one_iff_eq hy.ne'] at h
simp [h]
calc
y⁻¹ * (y - x) = 1 - x / y := by field_simp
_ < -log (x / y) := by linarith [log_lt_sub_one_of_pos hxy' hxy'']
_ = -(log x - log y) := by rw [log_div hx.ne' hy.ne']
_ = log y - log x := by ring
/-- **Bernoulli's inequality** for real exponents, strict version: for `1 < p` and `-1 ≤ s`, with
`s ≠ 0`, we have `1 + p * s < (1 + s) ^ p`. -/
theorem one_add_mul_self_lt_rpow_one_add {s : ℝ} (hs : -1 ≤ s) (hs' : s ≠ 0) {p : ℝ} (hp : 1 < p) :
| Mathlib/Analysis/Convex/SpecificFunctions/Basic.lean | 67 | 94 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Batteries.Tactic.Congr
import Mathlib.Data.Option.Basic
import Mathlib.Data.Prod.Basic
import Mathlib.Data.Set.Subsingleton
import Mathlib.Data.Set.SymmDiff
import Mathlib.Data.Set.Inclusion
/-!
# Images and preimages of sets
## Main definitions
* `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : Set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `Set.preimage f t`
* `f '' s` for `Set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
assert_not_exists WithTop OrderIso
universe u v
open Function Set
namespace Set
variable {α β γ : Type*} {ι : Sort*}
/-! ### Inverse image -/
section Preimage
variable {f : α → β} {g : β → γ}
@[simp]
theorem preimage_empty : f ⁻¹' ∅ = ∅ :=
rfl
theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by
congr with x
simp [h]
@[gcongr]
theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx
@[simp, mfld_simps]
theorem preimage_univ : f ⁻¹' univ = univ :=
rfl
theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ :=
subset_univ _
@[simp, mfld_simps]
theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t :=
rfl
@[simp]
theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t :=
rfl
@[simp]
theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ :=
rfl
@[simp]
theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t :=
rfl
open scoped symmDiff in
@[simp]
lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) :=
rfl
@[simp]
theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) :
f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
@[simp]
theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } :=
rfl
@[simp]
theorem preimage_id_eq : preimage (id : α → α) = id :=
rfl
@[mfld_simps]
theorem preimage_id {s : Set α} : id ⁻¹' s = s :=
rfl
@[simp, mfld_simps]
theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s :=
rfl
@[simp]
theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ :=
eq_univ_of_forall fun _ => h
@[simp]
theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty fun _ hx => h hx
theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] :
(fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by
split_ifs with hb
exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb]
/-- If preimage of each singleton under `f : α → β` is either empty or the whole type,
then `f` is a constant. -/
lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β}
(hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by
rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf'
· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩
· have : ∀ x b, f x ≠ b := fun x b ↦
eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x
exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩
theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) :=
rfl
theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g :=
rfl
theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by
induction n with
| zero => simp
| succ n ih => rw [iterate_succ, iterate_succ', preimage_comp_eq, ih]
theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} :
f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s :=
preimage_comp.symm
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} :
s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t :=
⟨fun s_eq x h => by
rw [s_eq]
simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩
theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) :
s.Nonempty :=
let ⟨x, hx⟩ := hf
⟨f x, hx⟩
@[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp
@[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp
theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by
ext ⟨x, x_in_s⟩
constructor
· intro x_in_u x_in_v
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩
· intro hx
exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx'
lemma preimage_subset {s t} (hs : s ⊆ f '' t) (hf : Set.InjOn f (f ⁻¹' s)) : f ⁻¹' s ⊆ t := by
rintro a ha
obtain ⟨b, hb, hba⟩ := hs ha
rwa [hf ha _ hba.symm]
simpa [hba]
end Preimage
/-! ### Image of a set under a function -/
section Image
variable {f : α → β} {s t : Set α}
theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s :=
rfl
theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩
lemma preimage_subset_of_surjOn {t : Set β} (hf : Injective f) (h : SurjOn f s t) :
f ⁻¹' t ⊆ s := fun _ hx ↦
hf.mem_set_image.1 <| h hx
theorem forall_mem_image {f : α → β} {s : Set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ ∀ ⦃x⦄, x ∈ s → p (f x) := by simp
theorem exists_mem_image {f : α → β} {s : Set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp
@[congr]
theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by
aesop
/-- A common special case of `image_congr` -/
theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s :=
image_congr fun x _ => h x
@[gcongr]
lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by
rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha)
theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) := by aesop
theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp
/-- A variant of `image_comp`, useful for rewriting -/
| theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s :=
(image_comp g f s).symm
| Mathlib/Data/Set/Image.lean | 223 | 224 |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.HomotopyCategory.MappingCone
import Mathlib.Algebra.Homology.HomotopyCategory.HomComplexShift
import Mathlib.CategoryTheory.Triangulated.Functor
/-! The pretriangulated structure on the homotopy category of complexes
In this file, we define the pretriangulated structure on the homotopy
category `HomotopyCategory C (ComplexShape.up ℤ)` of an additive category `C`.
The distinguished triangles are the triangles that are isomorphic to the
image in the homotopy category of the standard triangle
`K ⟶ L ⟶ mappingCone φ ⟶ K⟦(1 : ℤ)⟧` for some morphism of
cochain complexes `φ : K ⟶ L`.
This result first appeared in the Liquid Tensor Experiment. In the LTE, the
formalization followed the Stacks Project: in particular, the distinguished
triangles were defined using degreewise-split short exact sequences of cochain
complexes. Here, we follow the original definitions in [Verdiers's thesis, I.3][verdier1996]
(with the better sign conventions from the introduction of
[Brian Conrad's book *Grothendieck duality and base change*][conrad2000]).
## References
* [Jean-Louis Verdier, *Des catégories dérivées des catégories abéliennes*][verdier1996]
* [Brian Conrad, Grothendieck duality and base change][conrad2000]
* https://stacks.math.columbia.edu/tag/014P
-/
assert_not_exists TwoSidedIdeal
open CategoryTheory Category Limits CochainComplex.HomComplex Pretriangulated
variable {C D : Type*} [Category C] [Category D]
[Preadditive C] [HasBinaryBiproducts C]
[Preadditive D] [HasBinaryBiproducts D]
{K L : CochainComplex C ℤ} (φ : K ⟶ L)
namespace CochainComplex
namespace mappingCone
/-- The standard triangle `K ⟶ L ⟶ mappingCone φ ⟶ K⟦(1 : ℤ)⟧` in `CochainComplex C ℤ`
attached to a morphism `φ : K ⟶ L`. It involves `φ`, `inr φ : L ⟶ mappingCone φ` and
the morphism induced by the `1`-cocycle `-mappingCone.fst φ`. -/
@[simps! obj₁ obj₂ obj₃ mor₁ mor₂]
noncomputable def triangle : Triangle (CochainComplex C ℤ) :=
Triangle.mk φ (inr φ) (Cocycle.homOf ((-fst φ).rightShift 1 0 (zero_add 1)))
@[reassoc (attr := simp)]
lemma inl_v_triangle_mor₃_f (p q : ℤ) (hpq : p + (-1) = q) :
(inl φ).v p q hpq ≫ (triangle φ).mor₃.f q =
-(K.shiftFunctorObjXIso 1 q p (by rw [← hpq, neg_add_cancel_right])).inv := by
dsimp [triangle]
-- the following list of lemmas was obtained by doing
-- simp? [Cochain.rightShift_v _ 1 0 (zero_add 1) q q (add_zero q) p (by omega)]
simp only [Int.reduceNeg, Cochain.rightShift_neg, Cochain.neg_v, shiftFunctor_obj_X',
Cochain.rightShift_v _ 1 0 (zero_add 1) q q (add_zero q) p (by omega), shiftFunctor_obj_X,
shiftFunctorObjXIso, Preadditive.comp_neg, inl_v_fst_v_assoc]
@[reassoc (attr := simp)]
lemma inr_f_triangle_mor₃_f (p : ℤ) : (inr φ).f p ≫ (triangle φ).mor₃.f p = 0 := by
dsimp [triangle]
-- the following list of lemmas was obtained by doing
-- simp? [Cochain.rightShift_v _ 1 0 _ p p (add_zero p) (p+1) rfl]
simp only [Cochain.rightShift_neg, Cochain.neg_v, shiftFunctor_obj_X',
Cochain.rightShift_v _ 1 0 _ p p (add_zero p) (p + 1) rfl, shiftFunctor_obj_X,
shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, comp_id,
Preadditive.comp_neg, inr_f_fst_v, neg_zero]
@[reassoc (attr := simp)]
lemma inr_triangleδ : inr φ ≫ (triangle φ).mor₃ = 0 := by ext; dsimp; simp
/-- The (distinguished) triangle in the homotopy category that is associated to
a morphism `φ : K ⟶ L` in the category `CochainComplex C ℤ`. -/
noncomputable abbrev triangleh : Triangle (HomotopyCategory C (ComplexShape.up ℤ)) :=
(HomotopyCategory.quotient _ _).mapTriangle.obj (triangle φ)
variable (K) in
/-- The mapping cone of the identity is contractible. -/
noncomputable def homotopyToZeroOfId : Homotopy (𝟙 (mappingCone (𝟙 K))) 0 :=
descHomotopy (𝟙 K) _ _ 0 (inl _) (by simp) (by simp)
section mapOfHomotopy
variable {K₁ L₁ K₂ L₂ K₃ L₃ : CochainComplex C ℤ} {φ₁ : K₁ ⟶ L₁} {φ₂ : K₂ ⟶ L₂}
{a : K₁ ⟶ K₂} {b : L₁ ⟶ L₂} (H : Homotopy (φ₁ ≫ b) (a ≫ φ₂))
/-- The morphism `mappingCone φ₁ ⟶ mappingCone φ₂` that is induced by a square that
is commutative up to homotopy. -/
noncomputable def mapOfHomotopy :
mappingCone φ₁ ⟶ mappingCone φ₂ :=
desc φ₁ ((Cochain.ofHom a).comp (inl φ₂) (zero_add _) +
((Cochain.equivHomotopy _ _) H).1.comp (Cochain.ofHom (inr φ₂)) (add_zero _))
(b ≫ inr φ₂) (by simp)
@[reassoc]
lemma triangleMapOfHomotopy_comm₂ :
inr φ₁ ≫ mapOfHomotopy H = b ≫ inr φ₂ := by
simp [mapOfHomotopy]
@[reassoc]
lemma triangleMapOfHomotopy_comm₃ :
mapOfHomotopy H ≫ (triangle φ₂).mor₃ = (triangle φ₁).mor₃ ≫ a⟦1⟧' := by
ext p
dsimp [mapOfHomotopy, triangle]
-- the following list of lemmas as been obtained by doing
-- simp? [ext_from_iff _ _ _ rfl, Cochain.rightShift_v _ 1 0 _ p p _ (p + 1) rfl]
simp only [Int.reduceNeg, Cochain.rightShift_neg, Cochain.neg_v, shiftFunctor_obj_X',
Cochain.rightShift_v _ 1 0 _ p p _ (p + 1) rfl, shiftFunctor_obj_X, shiftFunctorObjXIso,
HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, comp_id, Preadditive.comp_neg,
Preadditive.neg_comp, ext_from_iff _ _ _ rfl, inl_v_desc_f_assoc, Cochain.add_v,
Cochain.zero_cochain_comp_v, Cochain.ofHom_v, Cochain.comp_zero_cochain_v, Preadditive.add_comp,
assoc, inl_v_fst_v, inr_f_fst_v, comp_zero, add_zero, inl_v_fst_v_assoc, inr_f_desc_f_assoc,
HomologicalComplex.comp_f, neg_zero, inr_f_fst_v_assoc, zero_comp, and_self]
/-- The morphism `triangleh φ₁ ⟶ triangleh φ₂` that is induced by a square that
is commutative up to homotopy. -/
@[simps]
noncomputable def trianglehMapOfHomotopy :
triangleh φ₁ ⟶ triangleh φ₂ where
hom₁ := (HomotopyCategory.quotient _ _).map a
hom₂ := (HomotopyCategory.quotient _ _).map b
hom₃ := (HomotopyCategory.quotient _ _).map (mapOfHomotopy H)
comm₁ := by
dsimp
simp only [← Functor.map_comp]
exact HomotopyCategory.eq_of_homotopy _ _ H
comm₂ := by
dsimp
simp only [← Functor.map_comp, triangleMapOfHomotopy_comm₂]
comm₃ := by
dsimp
rw [← Functor.map_comp_assoc, triangleMapOfHomotopy_comm₃, Functor.map_comp, assoc, assoc]
simp
end mapOfHomotopy
section map
variable {K₁ L₁ K₂ L₂ K₃ L₃ : CochainComplex C ℤ} (φ₁ : K₁ ⟶ L₁) (φ₂ : K₂ ⟶ L₂) (φ₃ : K₃ ⟶ L₃)
(a : K₁ ⟶ K₂) (b : L₁ ⟶ L₂)
/-- The morphism `mappingCone φ₁ ⟶ mappingCone φ₂` that is induced by a commutative square. -/
noncomputable def map (comm : φ₁ ≫ b = a ≫ φ₂) : mappingCone φ₁ ⟶ mappingCone φ₂ :=
desc φ₁ ((Cochain.ofHom a).comp (inl φ₂) (zero_add _)) (b ≫ inr φ₂)
(by simp [reassoc_of% comm])
variable (comm : φ₁ ≫ b = a ≫ φ₂)
lemma map_eq_mapOfHomotopy : map φ₁ φ₂ a b comm = mapOfHomotopy (Homotopy.ofEq comm) := by
simp [map, mapOfHomotopy]
lemma map_id : map φ φ (𝟙 _) (𝟙 _) (by rw [id_comp, comp_id]) = 𝟙 _ := by
ext n
simp [ext_from_iff _ (n + 1) n rfl, map]
variable (a' : K₂ ⟶ K₃) (b' : L₂ ⟶ L₃)
@[reassoc]
lemma map_comp (comm' : φ₂ ≫ b' = a' ≫ φ₃) :
map φ₁ φ₃ (a ≫ a') (b ≫ b') (by rw [reassoc_of% comm, comm', assoc]) =
map φ₁ φ₂ a b comm ≫ map φ₂ φ₃ a' b' comm' := by
ext n
simp [ext_from_iff _ (n+1) n rfl, map]
/-- The morphism `triangle φ₁ ⟶ triangle φ₂` that is induced by a commutative square. -/
@[simps]
noncomputable def triangleMap :
triangle φ₁ ⟶ triangle φ₂ where
hom₁ := a
hom₂ := b
hom₃ := map φ₁ φ₂ a b comm
comm₁ := comm
comm₂ := by
dsimp
rw [map_eq_mapOfHomotopy, triangleMapOfHomotopy_comm₂]
comm₃ := by
dsimp
rw [map_eq_mapOfHomotopy, triangleMapOfHomotopy_comm₃]
end map
section Rotate
/-- Given `φ : K ⟶ L`, `K⟦(1 : ℤ)⟧` is homotopy equivalent to
the mapping cone of `inr φ : L ⟶ mappingCone φ`. -/
noncomputable def rotateHomotopyEquiv :
HomotopyEquiv (K⟦(1 : ℤ)⟧) (mappingCone (inr φ)) where
hom := lift (inr φ) (-(Cocycle.ofHom φ).leftShift 1 1 (zero_add 1))
(-(inl φ).leftShift 1 0 (neg_add_cancel 1)) (by
-- the following list of lemmas has been obtained by doing
-- simp? [Cochain.δ_leftShift _ 1 0 1 (neg_add_cancel 1) 0 (zero_add 1)]
simp only [Int.reduceNeg, δ_neg,
Cochain.δ_leftShift _ 1 0 1 (neg_add_cancel 1) 0 (zero_add 1),
Int.negOnePow_one, δ_inl, Cochain.ofHom_comp, Cochain.leftShift_comp_zero_cochain,
Units.neg_smul, one_smul, neg_neg, Cocycle.coe_neg, Cocycle.leftShift_coe,
Cocycle.ofHom_coe, Cochain.neg_comp, add_neg_cancel])
inv := desc (inr φ) 0 (triangle φ).mor₃
(by simp only [δ_zero, inr_triangleδ, Cochain.ofHom_zero])
homotopyHomInvId := Homotopy.ofEq (by
ext n
-- the following list of lemmas has been obtained by doing
-- simp? [lift_desc_f _ _ _ _ _ _ _ _ _ rfl,
-- (inl φ).leftShift_v 1 0 _ _ n _ (n + 1) (by simp only [add_neg_cancel_right])]
simp only [shiftFunctor_obj_X', Int.reduceNeg, HomologicalComplex.comp_f,
lift_desc_f _ _ _ _ _ _ _ _ _ rfl, Cocycle.coe_neg, Cocycle.leftShift_coe,
Cocycle.ofHom_coe, Cochain.neg_v, Cochain.zero_v,
comp_zero, (inl φ).leftShift_v 1 0 _ _ n _ (n + 1) (by simp only [add_neg_cancel_right]),
shiftFunctor_obj_X, mul_zero, sub_self, Int.zero_ediv, add_zero, Int.negOnePow_zero,
shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_hom, id_comp, one_smul,
Preadditive.neg_comp, inl_v_triangle_mor₃_f, Iso.refl_inv, neg_neg, zero_add,
HomologicalComplex.id_f])
homotopyInvHomId := (Cochain.equivHomotopy _ _).symm
⟨-(snd (inr φ)).comp ((snd φ).comp (inl (inr φ)) (zero_add (-1))) (zero_add (-1)), by
ext n
-- the following list of lemmas has been obtained by doing
-- simp? [ext_to_iff _ _ (n + 1) rfl, ext_from_iff _ (n + 1) _ rfl,
-- δ_zero_cochain_comp _ _ _ (neg_add_cancel 1),
-- (inl φ).leftShift_v 1 0 (neg_add_cancel 1) n n (add_zero n) (n + 1) (by omega),
-- (Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) n (n + 1) rfl (n + 1) (by omega),
-- Cochain.comp_v _ _ (add_neg_cancel 1) n (n + 1) n rfl (by omega)]
simp only [Int.reduceNeg, Cochain.ofHom_comp, ofHom_desc, ofHom_lift, Cocycle.coe_neg,
Cocycle.leftShift_coe, Cocycle.ofHom_coe, Cochain.comp_zero_cochain_v,
shiftFunctor_obj_X', δ_neg, δ_zero_cochain_comp _ _ _ (neg_add_cancel 1), δ_inl,
Int.negOnePow_neg, Int.negOnePow_one, δ_snd, Cochain.neg_comp,
Cochain.comp_assoc_of_second_is_zero_cochain, smul_neg, Units.neg_smul, one_smul,
neg_neg, Cochain.comp_add, inr_snd_assoc, neg_add_rev, Cochain.add_v, Cochain.neg_v,
Cochain.comp_v _ _ (add_neg_cancel 1) n (n + 1) n rfl (by omega),
Cochain.zero_cochain_comp_v, Cochain.ofHom_v, HomologicalComplex.id_f,
ext_to_iff _ _ (n + 1) rfl, assoc, liftCochain_v_fst_v,
(Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) n (n + 1) rfl (n + 1) (by omega),
shiftFunctor_obj_X, mul_one, sub_self, mul_zero, Int.zero_ediv, add_zero,
shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_hom, id_comp,
Preadditive.add_comp, Preadditive.neg_comp, inl_v_fst_v, comp_id, inr_f_fst_v, comp_zero,
neg_zero, neg_add_cancel_comm, ext_from_iff _ (n + 1) _ rfl, inl_v_descCochain_v_assoc,
Cochain.zero_v, zero_comp, Preadditive.comp_neg, inl_v_snd_v_assoc,
inr_f_descCochain_v_assoc, inr_f_snd_v_assoc, inl_v_triangle_mor₃_f_assoc, triangle_obj₁,
Iso.refl_inv, inl_v_fst_v_assoc, inr_f_triangle_mor₃_f_assoc, inr_f_fst_v_assoc, and_self,
liftCochain_v_snd_v,
(inl φ).leftShift_v 1 0 (neg_add_cancel 1) n n (add_zero n) (n + 1) (by omega),
Int.negOnePow_zero, inl_v_snd_v, inr_f_snd_v, zero_add, inl_v_descCochain_v,
inr_f_descCochain_v, inl_v_triangle_mor₃_f, inr_f_triangle_mor₃_f, neg_add_cancel]⟩
/-- Auxiliary definition for `rotateTrianglehIso`. -/
noncomputable def rotateHomotopyEquivComm₂Homotopy :
Homotopy ((triangle φ).mor₃ ≫ (rotateHomotopyEquiv φ).hom)
(inr (CochainComplex.mappingCone.inr φ)) := (Cochain.equivHomotopy _ _).symm
⟨-(snd φ).comp (inl (inr φ)) (zero_add (-1)), by
ext p
dsimp [rotateHomotopyEquiv]
-- the following list of lemmas has been obtained by doing
-- simp? [ext_from_iff _ _ _ rfl, ext_to_iff _ _ _ rfl,
-- (inl φ).leftShift_v 1 0 (neg_add_cancel 1) p p (add_zero p) (p + 1) (by omega),
-- δ_zero_cochain_comp _ _ _ (neg_add_cancel 1),
-- Cochain.comp_v _ _ (add_neg_cancel 1) p (p + 1) p rfl (by omega),
-- (Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) p (p + 1) rfl (p + 1) (by omega)]⟩
simp only [Int.reduceNeg, Cochain.ofHom_comp, ofHom_lift, Cocycle.coe_neg,
Cocycle.leftShift_coe, Cocycle.ofHom_coe, Cochain.comp_zero_cochain_v,
shiftFunctor_obj_X', Cochain.ofHom_v, δ_neg, δ_zero_cochain_comp _ _ _ (neg_add_cancel 1),
δ_inl, Int.negOnePow_neg, Int.negOnePow_one, δ_snd, Cochain.neg_comp,
Cochain.comp_assoc_of_second_is_zero_cochain, smul_neg, Units.neg_smul, one_smul, neg_neg,
neg_add_rev, Cochain.add_v, Cochain.neg_v,
Cochain.comp_v _ _ (add_neg_cancel 1) p (p + 1) p rfl (by omega),
Cochain.zero_cochain_comp_v, ext_from_iff _ _ _ rfl, inl_v_triangle_mor₃_f_assoc,
triangle_obj₁, shiftFunctor_obj_X, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl,
Iso.refl_inv, Preadditive.neg_comp, id_comp, Preadditive.comp_add, Preadditive.comp_neg,
inl_v_fst_v_assoc, inl_v_snd_v_assoc, zero_comp, neg_zero, add_zero, ext_to_iff _ _ _ rfl,
liftCochain_v_fst_v,
(Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) p (p + 1) rfl (p + 1) (by omega), mul_one,
sub_self, mul_zero, Int.zero_ediv, Iso.refl_hom, Preadditive.add_comp, assoc, inl_v_fst_v,
comp_id, inr_f_fst_v, comp_zero, liftCochain_v_snd_v,
(inl φ).leftShift_v 1 0 (neg_add_cancel 1) p p (add_zero p) (p + 1) (by omega),
Int.negOnePow_zero, inl_v_snd_v, inr_f_snd_v, zero_add, and_self,
inr_f_triangle_mor₃_f_assoc, inr_f_fst_v_assoc, inr_f_snd_v_assoc, neg_add_cancel]⟩
@[reassoc (attr := simp)]
lemma rotateHomotopyEquiv_comm₂ :
(HomotopyCategory.quotient _ _ ).map (triangle φ).mor₃ ≫
(HomotopyCategory.quotient _ _ ).map (rotateHomotopyEquiv φ).hom =
(HomotopyCategory.quotient _ _ ).map (inr (inr φ)) := by
simpa only [Functor.map_comp]
using HomotopyCategory.eq_of_homotopy _ _ (rotateHomotopyEquivComm₂Homotopy φ)
@[reassoc (attr := simp)]
lemma rotateHomotopyEquiv_comm₃ :
(rotateHomotopyEquiv φ).hom ≫ (triangle (inr φ)).mor₃ = -φ⟦1⟧' := by
ext p
dsimp [rotateHomotopyEquiv]
-- the following list of lemmas has been obtained by doing
-- simp? [lift_f _ _ _ _ _ (p + 1) rfl,
-- (Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) p (p + 1) rfl (p + 1) (by omega)]
simp only [Int.reduceNeg, lift_f _ _ _ _ _ (p + 1) rfl, shiftFunctor_obj_X', Cocycle.coe_neg,
Cocycle.leftShift_coe, Cocycle.ofHom_coe, Cochain.neg_v,
(Cochain.ofHom φ).leftShift_v 1 1 (zero_add 1) p (p + 1) rfl (p + 1) (by omega),
shiftFunctor_obj_X, mul_one, sub_self, mul_zero, Int.zero_ediv, add_zero, Int.negOnePow_one,
shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_hom, Cochain.ofHom_v, id_comp,
Units.neg_smul, one_smul, neg_neg, Preadditive.neg_comp, Preadditive.add_comp, assoc,
inl_v_triangle_mor₃_f, Iso.refl_inv, Preadditive.comp_neg, comp_id, inr_f_triangle_mor₃_f,
comp_zero, neg_zero]
/-- The canonical isomorphism of triangles `(triangleh φ).rotate ≅ (triangleh (inr φ))`. -/
noncomputable def rotateTrianglehIso :
(triangleh φ).rotate ≅ (triangleh (inr φ)) :=
Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _)
(((HomotopyCategory.quotient C (ComplexShape.up ℤ)).commShiftIso (1 : ℤ)).symm.app K ≪≫
HomotopyCategory.isoOfHomotopyEquiv (rotateHomotopyEquiv φ))
(by dsimp; simp) (by dsimp; simp) (by
dsimp
rw [CategoryTheory.Functor.map_id, comp_id, assoc, ← Functor.map_comp_assoc,
rotateHomotopyEquiv_comm₃, Functor.map_neg, Preadditive.neg_comp,
Functor.commShiftIso_hom_naturality, Preadditive.comp_neg,
Iso.inv_hom_id_app_assoc])
end Rotate
section Shift
/-- The canonical isomorphism `(mappingCone φ)⟦n⟧ ≅ mappingCone (φ⟦n⟧')`. -/
noncomputable def shiftIso (n : ℤ) : (mappingCone φ)⟦n⟧ ≅ mappingCone (φ⟦n⟧') where
hom := lift _ (n.negOnePow • (fst φ).shift n) ((snd φ).shift n) (by
ext p q hpq
dsimp
simp only [Cochain.δ_shift, δ_snd, Cochain.shift_neg, smul_neg, Cochain.neg_v,
shiftFunctor_obj_X', Cochain.units_smul_v, Cochain.shift_v', Cochain.comp_zero_cochain_v,
Cochain.ofHom_v, Cochain.units_smul_comp, shiftFunctor_map_f', neg_add_cancel])
inv := desc _ (n.negOnePow • (inl φ).shift n) ((inr φ)⟦n⟧') (by
ext p
dsimp
simp only [Int.reduceNeg, δ_units_smul, Cochain.δ_shift, δ_inl, Cochain.ofHom_comp, smul_smul,
Int.units_mul_self, one_smul, Cochain.shift_v', Cochain.comp_zero_cochain_v,
Cochain.ofHom_v, shiftFunctor_obj_X', shiftFunctor_map_f'])
hom_inv_id := by
ext p
dsimp
simp only [Int.reduceNeg, lift_desc_f _ _ _ _ _ _ _ _ (p + 1) rfl, shiftFunctor_obj_X',
Cocycle.coe_units_smul, Cocycle.shift_coe, Cochain.units_smul_v, Cochain.shift_v',
Linear.comp_units_smul, Linear.units_smul_comp, smul_smul, Int.units_mul_self, one_smul,
shiftFunctor_map_f', id_X]
inv_hom_id := by
ext p
dsimp
simp only [Int.reduceNeg, ext_from_iff _ (p + 1) _ rfl, shiftFunctor_obj_X',
inl_v_desc_f_assoc, Cochain.units_smul_v, Cochain.shift_v', Linear.units_smul_comp, comp_id,
ext_to_iff _ _ (p + 1) rfl, assoc, lift_f_fst_v,
Cocycle.coe_units_smul, Cocycle.shift_coe, Linear.comp_units_smul, inl_v_fst_v, smul_smul,
Int.units_mul_self, one_smul, lift_f_snd_v, inl_v_snd_v, smul_zero, and_self,
inr_f_desc_f_assoc, shiftFunctor_map_f', inr_f_fst_v, inr_f_snd_v]
/-- The canonical isomorphism `(triangle φ)⟦n⟧ ≅ triangle (φ⟦n⟧')`. -/
noncomputable def shiftTriangleIso (n : ℤ) :
(Triangle.shiftFunctor _ n).obj (triangle φ) ≅ triangle (φ⟦n⟧') := by
refine Triangle.isoMk _ _ (Iso.refl _) (n.negOnePow • Iso.refl _) (shiftIso φ n) ?_ ?_ ?_
· dsimp
simp only [Linear.comp_units_smul, comp_id, id_comp, smul_smul,
Int.units_mul_self, one_smul]
· ext p
dsimp
simp only [Units.smul_def, shiftIso, Int.reduceNeg, Linear.smul_comp, id_comp,
ext_to_iff _ _ (p + 1) rfl, shiftFunctor_obj_X', assoc, lift_f_fst_v, Cocycle.coe_smul,
Cocycle.shift_coe, Cochain.smul_v, Cochain.shift_v', Linear.comp_smul, inr_f_fst_v,
smul_zero, lift_f_snd_v, inr_f_snd_v, and_true]
· ext p
dsimp
simp only [triangle, Triangle.mk_mor₃, Cocycle.homOf_f, Cocycle.rightShift_coe,
Cocycle.coe_neg, Cochain.rightShift_neg, Cochain.neg_v, shiftFunctor_obj_X',
(fst φ).1.rightShift_v 1 0 (zero_add 1) (p + n) (p + n) (add_zero (p + n)) (p + 1 + n)
(by omega),
shiftFunctor_obj_X, shiftFunctorObjXIso, shiftFunctorComm_hom_app_f, Preadditive.neg_comp,
assoc, Iso.inv_hom_id, comp_id, smul_neg, Units.smul_def, shiftIso, Int.reduceNeg,
(fst (φ⟦n⟧')).1.rightShift_v 1 0 (zero_add 1) p p (add_zero p) (p + 1) rfl,
HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, Preadditive.comp_neg, lift_f_fst_v,
Cocycle.coe_smul, Cocycle.shift_coe, Cochain.smul_v, Cochain.shift_v']
/-- The canonical isomorphism `(triangleh φ)⟦n⟧ ≅ triangleh (φ⟦n⟧')`. -/
noncomputable def shiftTrianglehIso (n : ℤ) :
(Triangle.shiftFunctor _ n).obj (triangleh φ) ≅ triangleh (φ⟦n⟧') :=
((HomotopyCategory.quotient _ _).mapTriangle.commShiftIso n).symm.app _ ≪≫
(HomotopyCategory.quotient _ _).mapTriangle.mapIso (shiftTriangleIso φ n)
end Shift
section
open Preadditive
variable (G : C ⥤ D) [G.Additive]
lemma map_δ :
(G.mapHomologicalComplex (ComplexShape.up ℤ)).map (triangle φ).mor₃ ≫
NatTrans.app ((Functor.mapHomologicalComplex G (ComplexShape.up ℤ)).commShiftIso 1).hom K =
(mapHomologicalComplexIso φ G).hom ≫
(triangle ((G.mapHomologicalComplex (ComplexShape.up ℤ)).map φ)).mor₃ := by
ext n
dsimp [mapHomologicalComplexIso]
rw [mapHomologicalComplexXIso_eq φ G n (n+1) rfl, mapHomologicalComplexXIso'_hom]
simp only [Functor.mapHomologicalComplex_obj_X, add_comp, assoc, inl_v_triangle_mor₃_f,
shiftFunctor_obj_X, shiftFunctorObjXIso, HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv,
comp_neg, comp_id, inr_f_triangle_mor₃_f, comp_zero, add_zero]
dsimp [triangle]
rw [Cochain.rightShift_v _ 1 0 (by omega) n n (by omega) (n + 1) (by omega)]
simp only [shiftFunctor_obj_X, Cochain.neg_v, shiftFunctorObjXIso,
HomologicalComplex.XIsoOfEq_rfl, Iso.refl_inv, comp_id, Functor.map_neg]
/-- If `φ : K ⟶ L` is a morphism of cochain complexes in `C` and `G : C ⥤ D` is an
additive functor, then the image by `G` of the triangle `triangle φ` identifies to
the triangle associated to the image of `φ` by `G`. -/
noncomputable def mapTriangleIso :
(G.mapHomologicalComplex (ComplexShape.up ℤ)).mapTriangle.obj (triangle φ) ≅
triangle ((G.mapHomologicalComplex (ComplexShape.up ℤ)).map φ) := by
| refine Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (mapHomologicalComplexIso φ G) ?_ ?_ ?_
· dsimp
simp only [comp_id, id_comp]
· dsimp
rw [map_inr, id_comp]
· dsimp
simp only [CategoryTheory.Functor.map_id, comp_id, map_δ]
/-- If `φ : K ⟶ L` is a morphism of cochain complexes in `C` and `G : C ⥤ D` is an
additive functor, then the image by `G` of the triangle `triangleh φ` identifies to
the triangle associated to the image of `φ` by `G`. -/
noncomputable def mapTrianglehIso :
(G.mapHomotopyCategory (ComplexShape.up ℤ)).mapTriangle.obj (triangleh φ) ≅
triangleh ((G.mapHomologicalComplex (ComplexShape.up ℤ)).map φ) :=
(Functor.mapTriangleCompIso _ _).symm.app _ ≪≫
(Functor.mapTriangleIso (G.mapHomotopyCategoryFactors (ComplexShape.up ℤ))).app _ ≪≫
(Functor.mapTriangleCompIso _ _).app _ ≪≫
(HomotopyCategory.quotient D (ComplexShape.up ℤ)).mapTriangle.mapIso
(CochainComplex.mappingCone.mapTriangleIso φ G)
end
end mappingCone
end CochainComplex
| Mathlib/Algebra/Homology/HomotopyCategory/Pretriangulated.lean | 414 | 439 |
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.Algebra.Polynomial.Eval.SMul
import Mathlib.Algebra.Polynomial.HasseDeriv
/-!
# Taylor expansions of polynomials
## Main declarations
* `Polynomial.taylor`: the Taylor expansion of the polynomial `f` at `r`
* `Polynomial.taylor_coeff`: the `k`th coefficient of `taylor r f` is
`(Polynomial.hasseDeriv k f).eval r`
* `Polynomial.eq_zero_of_hasseDeriv_eq_zero`:
the identity principle: a polynomial is 0 iff all its Hasse derivatives are zero
-/
noncomputable section
namespace Polynomial
variable {R : Type*} [Semiring R] (r : R) (f : R[X])
/-- The Taylor expansion of a polynomial `f` at `r`. -/
def taylor (r : R) : R[X] →ₗ[R] R[X] where
toFun f := f.comp (X + C r)
map_add' _ _ := add_comp
map_smul' c f := by simp only [smul_eq_C_mul, C_mul_comp, RingHom.id_apply]
theorem taylor_apply : taylor r f = f.comp (X + C r) :=
rfl
@[simp]
theorem taylor_X : taylor r X = X + C r := by simp only [taylor_apply, X_comp]
@[simp]
theorem taylor_C (x : R) : taylor r (C x) = C x := by simp only [taylor_apply, C_comp]
@[simp]
theorem taylor_zero' : taylor (0 : R) = LinearMap.id := by
ext
simp only [taylor_apply, add_zero, comp_X, map_zero, LinearMap.id_comp,
Function.comp_apply, LinearMap.coe_comp]
theorem taylor_zero (f : R[X]) : taylor 0 f = f := by rw [taylor_zero', LinearMap.id_apply]
@[simp]
theorem taylor_one : taylor r (1 : R[X]) = C 1 := by rw [← C_1, taylor_C]
|
@[simp]
theorem taylor_monomial (i : ℕ) (k : R) : taylor r (monomial i k) = C k * (X + C r) ^ i := by
simp [taylor_apply]
| Mathlib/Algebra/Polynomial/Taylor.lean | 56 | 59 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Data.ENNReal.Operations
/-!
# Results about division in extended non-negative reals
This file establishes basic properties related to the inversion and division operations on `ℝ≥0∞`.
For instance, as a consequence of being a `DivInvOneMonoid`, `ℝ≥0∞` inherits a power operation
with integer exponent.
## Main results
A few order isomorphisms are worthy of mention:
- `OrderIso.invENNReal : ℝ≥0∞ ≃o ℝ≥0∞ᵒᵈ`: The map `x ↦ x⁻¹` as an order isomorphism to the dual.
- `orderIsoIicOneBirational : ℝ≥0∞ ≃o Iic (1 : ℝ≥0∞)`: The birational order isomorphism between
`ℝ≥0∞` and the unit interval `Set.Iic (1 : ℝ≥0∞)` given by `x ↦ (x⁻¹ + 1)⁻¹` with inverse
`x ↦ (x⁻¹ - 1)⁻¹`
- `orderIsoIicCoe (a : ℝ≥0) : Iic (a : ℝ≥0∞) ≃o Iic a`: Order isomorphism between an initial
interval in `ℝ≥0∞` and an initial interval in `ℝ≥0` given by the identity map.
- `orderIsoUnitIntervalBirational : ℝ≥0∞ ≃o Icc (0 : ℝ) 1`: An order isomorphism between
the extended nonnegative real numbers and the unit interval. This is `orderIsoIicOneBirational`
composed with the identity order isomorphism between `Iic (1 : ℝ≥0∞)` and `Icc (0 : ℝ) 1`.
-/
assert_not_exists Finset
open Set NNReal
namespace ENNReal
noncomputable section Inv
variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
protected theorem div_eq_inv_mul : a / b = b⁻¹ * a := by rw [div_eq_mul_inv, mul_comm]
@[simp] theorem inv_zero : (0 : ℝ≥0∞)⁻¹ = ∞ :=
show sInf { b : ℝ≥0∞ | 1 ≤ 0 * b } = ∞ by simp
@[simp] theorem inv_top : ∞⁻¹ = 0 :=
bot_unique <| le_of_forall_gt_imp_ge_of_dense fun a (h : 0 < a) => sInf_le <| by
simp [*, h.ne', top_mul]
theorem coe_inv_le : (↑r⁻¹ : ℝ≥0∞) ≤ (↑r)⁻¹ :=
le_sInf fun b (hb : 1 ≤ ↑r * b) =>
coe_le_iff.2 <| by
rintro b rfl
apply NNReal.inv_le_of_le_mul
rwa [← coe_mul, ← coe_one, coe_le_coe] at hb
@[simp, norm_cast]
theorem coe_inv (hr : r ≠ 0) : (↑r⁻¹ : ℝ≥0∞) = (↑r)⁻¹ :=
coe_inv_le.antisymm <| sInf_le <| mem_setOf.2 <| by rw [← coe_mul, mul_inv_cancel₀ hr, coe_one]
@[norm_cast]
theorem coe_inv_two : ((2⁻¹ : ℝ≥0) : ℝ≥0∞) = 2⁻¹ := by rw [coe_inv _root_.two_ne_zero, coe_two]
@[simp, norm_cast]
theorem coe_div (hr : r ≠ 0) : (↑(p / r) : ℝ≥0∞) = p / r := by
rw [div_eq_mul_inv, div_eq_mul_inv, coe_mul, coe_inv hr]
lemma coe_div_le : ↑(p / r) ≤ (p / r : ℝ≥0∞) := by
simpa only [div_eq_mul_inv, coe_mul] using mul_le_mul_left' coe_inv_le _
theorem div_zero (h : a ≠ 0) : a / 0 = ∞ := by simp [div_eq_mul_inv, h]
instance : DivInvOneMonoid ℝ≥0∞ :=
{ inferInstanceAs (DivInvMonoid ℝ≥0∞) with
inv_one := by simpa only [coe_inv one_ne_zero, coe_one] using coe_inj.2 inv_one }
protected theorem inv_pow : ∀ {a : ℝ≥0∞} {n : ℕ}, (a ^ n)⁻¹ = a⁻¹ ^ n
| _, 0 => by simp only [pow_zero, inv_one]
| ⊤, n + 1 => by simp [top_pow]
| (a : ℝ≥0), n + 1 => by
rcases eq_or_ne a 0 with (rfl | ha)
· simp [top_pow]
· have := pow_ne_zero (n + 1) ha
norm_cast
rw [inv_pow]
protected theorem mul_inv_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a * a⁻¹ = 1 := by
lift a to ℝ≥0 using ht
norm_cast at h0; norm_cast
exact mul_inv_cancel₀ h0
protected theorem inv_mul_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a⁻¹ * a = 1 :=
mul_comm a a⁻¹ ▸ ENNReal.mul_inv_cancel h0 ht
/-- See `ENNReal.inv_mul_cancel_left` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma inv_mul_cancel_left' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) :
a⁻¹ * (a * b) = b := by
obtain rfl | ha₀ := eq_or_ne a 0
· simp_all
obtain rfl | ha := eq_or_ne a ⊤
· simp_all
· simp [← mul_assoc, ENNReal.inv_mul_cancel, *]
/-- See `ENNReal.inv_mul_cancel_left'` for a stronger version. -/
protected lemma inv_mul_cancel_left (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a⁻¹ * (a * b) = b :=
ENNReal.inv_mul_cancel_left' (by simp [ha₀]) (by simp [ha])
/-- See `ENNReal.mul_inv_cancel_left` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma mul_inv_cancel_left' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) :
a * (a⁻¹ * b) = b := by
obtain rfl | ha₀ := eq_or_ne a 0
· simp_all
obtain rfl | ha := eq_or_ne a ⊤
· simp_all
· simp [← mul_assoc, ENNReal.mul_inv_cancel, *]
/-- See `ENNReal.mul_inv_cancel_left'` for a stronger version. -/
protected lemma mul_inv_cancel_left (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a * (a⁻¹ * b) = b :=
ENNReal.mul_inv_cancel_left' (by simp [ha₀]) (by simp [ha])
/-- See `ENNReal.mul_inv_cancel_right` for a simpler version assuming `b ≠ 0`, `b ≠ ∞`. -/
protected lemma mul_inv_cancel_right' (hb₀ : b = 0 → a = 0) (hb : b = ∞ → a = 0) :
a * b * b⁻¹ = a := by
obtain rfl | hb₀ := eq_or_ne b 0
· simp_all
obtain rfl | hb := eq_or_ne b ⊤
· simp_all
· simp [mul_assoc, ENNReal.mul_inv_cancel, *]
/-- See `ENNReal.mul_inv_cancel_right'` for a stronger version. -/
protected lemma mul_inv_cancel_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b * b⁻¹ = a :=
ENNReal.mul_inv_cancel_right' (by simp [hb₀]) (by simp [hb])
/-- See `ENNReal.inv_mul_cancel_right` for a simpler version assuming `b ≠ 0`, `b ≠ ∞`. -/
protected lemma inv_mul_cancel_right' (hb₀ : b = 0 → a = 0) (hb : b = ∞ → a = 0) :
a * b⁻¹ * b = a := by
obtain rfl | hb₀ := eq_or_ne b 0
· simp_all
obtain rfl | hb := eq_or_ne b ⊤
· simp_all
· simp [mul_assoc, ENNReal.inv_mul_cancel, *]
/-- See `ENNReal.inv_mul_cancel_right'` for a stronger version. -/
protected lemma inv_mul_cancel_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b⁻¹ * b = a :=
ENNReal.inv_mul_cancel_right' (by simp [hb₀]) (by simp [hb])
/-- See `ENNReal.mul_div_cancel_right` for a simpler version assuming `b ≠ 0`, `b ≠ ∞`. -/
protected lemma mul_div_cancel_right' (hb₀ : b = 0 → a = 0) (hb : b = ∞ → a = 0) :
a * b / b = a := ENNReal.mul_inv_cancel_right' hb₀ hb
/-- See `ENNReal.mul_div_cancel_right'` for a stronger version. -/
protected lemma mul_div_cancel_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b / b = a :=
ENNReal.mul_div_cancel_right' (by simp [hb₀]) (by simp [hb])
/-- See `ENNReal.div_mul_cancel` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma div_mul_cancel' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) : b / a * a = b :=
ENNReal.inv_mul_cancel_right' ha₀ ha
/-- See `ENNReal.div_mul_cancel'` for a stronger version. -/
protected lemma div_mul_cancel (ha₀ : a ≠ 0) (ha : a ≠ ∞) : b / a * a = b :=
ENNReal.div_mul_cancel' (by simp [ha₀]) (by simp [ha])
/-- See `ENNReal.mul_div_cancel` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma mul_div_cancel' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) : a * (b / a) = b := by
rw [mul_comm, ENNReal.div_mul_cancel' ha₀ ha]
/-- See `ENNReal.mul_div_cancel'` for a stronger version. -/
protected lemma mul_div_cancel (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a * (b / a) = b :=
ENNReal.mul_div_cancel' (by simp [ha₀]) (by simp [ha])
protected theorem mul_comm_div : a / b * c = a * (c / b) := by
simp only [div_eq_mul_inv, mul_left_comm, mul_comm, mul_assoc]
protected theorem mul_div_right_comm : a * b / c = a / c * b := by
simp only [div_eq_mul_inv, mul_right_comm]
instance : InvolutiveInv ℝ≥0∞ where
inv_inv a := by
by_cases a = 0 <;> cases a <;> simp_all [none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm]
@[simp] protected lemma inv_eq_one : a⁻¹ = 1 ↔ a = 1 := by rw [← inv_inj, inv_inv, inv_one]
@[simp] theorem inv_eq_top : a⁻¹ = ∞ ↔ a = 0 := inv_zero ▸ inv_inj
theorem inv_ne_top : a⁻¹ ≠ ∞ ↔ a ≠ 0 := by simp
@[aesop (rule_sets := [finiteness]) safe apply]
protected alias ⟨_, Finiteness.inv_ne_top⟩ := ENNReal.inv_ne_top
@[simp]
theorem inv_lt_top {x : ℝ≥0∞} : x⁻¹ < ∞ ↔ 0 < x := by
simp only [lt_top_iff_ne_top, inv_ne_top, pos_iff_ne_zero]
theorem div_lt_top {x y : ℝ≥0∞} (h1 : x ≠ ∞) (h2 : y ≠ 0) : x / y < ∞ :=
mul_lt_top h1.lt_top (inv_ne_top.mpr h2).lt_top
@[simp]
protected theorem inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ :=
inv_top ▸ inv_inj
protected theorem inv_ne_zero : a⁻¹ ≠ 0 ↔ a ≠ ∞ := by simp
protected theorem div_pos (ha : a ≠ 0) (hb : b ≠ ∞) : 0 < a / b :=
ENNReal.mul_pos ha <| ENNReal.inv_ne_zero.2 hb
protected theorem inv_mul_le_iff {x y z : ℝ≥0∞} (h1 : x ≠ 0) (h2 : x ≠ ∞) :
x⁻¹ * y ≤ z ↔ y ≤ x * z := by
rw [← mul_le_mul_left h1 h2, ← mul_assoc, ENNReal.mul_inv_cancel h1 h2, one_mul]
protected theorem mul_inv_le_iff {x y z : ℝ≥0∞} (h1 : y ≠ 0) (h2 : y ≠ ∞) :
x * y⁻¹ ≤ z ↔ x ≤ z * y := by
rw [mul_comm, ENNReal.inv_mul_le_iff h1 h2, mul_comm]
protected theorem div_le_iff {x y z : ℝ≥0∞} (h1 : y ≠ 0) (h2 : y ≠ ∞) :
x / y ≤ z ↔ x ≤ z * y := by
rw [div_eq_mul_inv, ENNReal.mul_inv_le_iff h1 h2]
protected theorem div_le_iff' {x y z : ℝ≥0∞} (h1 : y ≠ 0) (h2 : y ≠ ∞) :
x / y ≤ z ↔ x ≤ y * z := by
rw [mul_comm, ENNReal.div_le_iff h1 h2]
protected theorem mul_inv {a b : ℝ≥0∞} (ha : a ≠ 0 ∨ b ≠ ∞) (hb : a ≠ ∞ ∨ b ≠ 0) :
(a * b)⁻¹ = a⁻¹ * b⁻¹ := by
induction' b with b
· replace ha : a ≠ 0 := ha.neg_resolve_right rfl
simp [ha]
induction' a with a
· replace hb : b ≠ 0 := coe_ne_zero.1 (hb.neg_resolve_left rfl)
simp [hb]
by_cases h'a : a = 0
· simp only [h'a, top_mul, ENNReal.inv_zero, ENNReal.coe_ne_top, zero_mul, Ne,
not_false_iff, ENNReal.coe_zero, ENNReal.inv_eq_zero]
by_cases h'b : b = 0
· simp only [h'b, ENNReal.inv_zero, ENNReal.coe_ne_top, mul_top, Ne, not_false_iff,
mul_zero, ENNReal.coe_zero, ENNReal.inv_eq_zero]
rw [← ENNReal.coe_mul, ← ENNReal.coe_inv, ← ENNReal.coe_inv h'a, ← ENNReal.coe_inv h'b, ←
ENNReal.coe_mul, mul_inv_rev, mul_comm]
simp [h'a, h'b]
protected theorem inv_div {a b : ℝ≥0∞} (htop : b ≠ ∞ ∨ a ≠ ∞) (hzero : b ≠ 0 ∨ a ≠ 0) :
(a / b)⁻¹ = b / a := by
rw [← ENNReal.inv_ne_zero] at htop
rw [← ENNReal.inv_ne_top] at hzero
rw [ENNReal.div_eq_inv_mul, ENNReal.div_eq_inv_mul, ENNReal.mul_inv htop hzero, mul_comm, inv_inv]
protected theorem mul_div_mul_left (a b : ℝ≥0∞) (hc : c ≠ 0) (hc' : c ≠ ⊤) :
c * a / (c * b) = a / b := by
rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inl hc) (Or.inl hc'), mul_mul_mul_comm,
ENNReal.mul_inv_cancel hc hc', one_mul]
protected theorem mul_div_mul_right (a b : ℝ≥0∞) (hc : c ≠ 0) (hc' : c ≠ ⊤) :
a * c / (b * c) = a / b := by
rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inr hc') (Or.inr hc), mul_mul_mul_comm,
ENNReal.mul_inv_cancel hc hc', mul_one]
protected theorem sub_div (h : 0 < b → b < a → c ≠ 0) : (a - b) / c = a / c - b / c := by
simp_rw [div_eq_mul_inv]
exact ENNReal.sub_mul (by simpa using h)
@[simp]
| protected theorem inv_pos : 0 < a⁻¹ ↔ a ≠ ∞ :=
| Mathlib/Data/ENNReal/Inv.lean | 263 | 263 |
/-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Alexey Soloyev, Junyan Xu, Kamila Szewczyk
-/
import Mathlib.Algebra.EuclideanDomain.Basic
import Mathlib.Algebra.LinearRecurrence
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Nat.Fib.Basic
import Mathlib.Data.Real.Irrational
import Mathlib.Tactic.NormNum.NatFib
import Mathlib.Tactic.NormNum.Prime
/-!
# The golden ratio and its conjugate
This file defines the golden ratio `φ := (1 + √5)/2` and its conjugate
`ψ := (1 - √5)/2`, which are the two real roots of `X² - X - 1`.
Along with various computational facts about them, we prove their
irrationality, and we link them to the Fibonacci sequence by proving
Binet's formula.
-/
noncomputable section
open Polynomial
/-- The golden ratio `φ := (1 + √5)/2`. -/
abbrev goldenRatio : ℝ := (1 + √5) / 2
/-- The conjugate of the golden ratio `ψ := (1 - √5)/2`. -/
abbrev goldenConj : ℝ := (1 - √5) / 2
@[inherit_doc goldenRatio] scoped[goldenRatio] notation "φ" => goldenRatio
@[inherit_doc goldenConj] scoped[goldenRatio] notation "ψ" => goldenConj
open Real goldenRatio
/-- The inverse of the golden ratio is the opposite of its conjugate. -/
theorem inv_gold : φ⁻¹ = -ψ := by
have : 1 + √5 ≠ 0 := ne_of_gt (add_pos (by norm_num) <| Real.sqrt_pos.mpr (by norm_num))
field_simp [sub_mul, mul_add]
norm_num
/-- The opposite of the golden ratio is the inverse of its conjugate. -/
theorem inv_goldConj : ψ⁻¹ = -φ := by
rw [inv_eq_iff_eq_inv, ← neg_inv, ← neg_eq_iff_eq_neg]
exact inv_gold.symm
@[simp]
theorem gold_mul_goldConj : φ * ψ = -1 := by
field_simp
rw [← sq_sub_sq]
norm_num
@[simp]
theorem goldConj_mul_gold : ψ * φ = -1 := by
rw [mul_comm]
exact gold_mul_goldConj
@[simp]
theorem gold_add_goldConj : φ + ψ = 1 := by
rw [goldenRatio, goldenConj]
ring
theorem one_sub_goldConj : 1 - φ = ψ := by
linarith [gold_add_goldConj]
theorem one_sub_gold : 1 - ψ = φ := by
linarith [gold_add_goldConj]
@[simp]
theorem gold_sub_goldConj : φ - ψ = √5 := by ring
theorem gold_pow_sub_gold_pow (n : ℕ) : φ ^ (n + 2) - φ ^ (n + 1) = φ ^ n := by
rw [goldenRatio]; ring_nf; norm_num; ring
@[simp 1200]
theorem gold_sq : φ ^ 2 = φ + 1 := by
rw [goldenRatio, ← sub_eq_zero]
ring_nf
rw [Real.sq_sqrt] <;> norm_num
@[simp 1200]
theorem goldConj_sq : ψ ^ 2 = ψ + 1 := by
rw [goldenConj, ← sub_eq_zero]
ring_nf
rw [Real.sq_sqrt] <;> norm_num
theorem gold_pos : 0 < φ :=
mul_pos (by apply add_pos <;> norm_num) <| inv_pos.2 zero_lt_two
theorem gold_ne_zero : φ ≠ 0 :=
ne_of_gt gold_pos
theorem one_lt_gold : 1 < φ := by
refine lt_of_mul_lt_mul_left ?_ (le_of_lt gold_pos)
simp [← sq, gold_pos, zero_lt_one]
theorem gold_lt_two : φ < 2 := by calc
(1 + sqrt 5) / 2 < (1 + 3) / 2 := by gcongr; rw [sqrt_lt'] <;> norm_num
_ = 2 := by norm_num
theorem goldConj_neg : ψ < 0 := by
linarith [one_sub_goldConj, one_lt_gold]
theorem goldConj_ne_zero : ψ ≠ 0 :=
ne_of_lt goldConj_neg
theorem neg_one_lt_goldConj : -1 < ψ := by
rw [neg_lt, ← inv_gold]
exact inv_lt_one_of_one_lt₀ one_lt_gold
/-!
## Irrationality
-/
/-- The golden ratio is irrational. -/
theorem gold_irrational : Irrational φ := by
have := Nat.Prime.irrational_sqrt (show Nat.Prime 5 by norm_num)
have := this.ratCast_add 1
convert this.ratCast_mul (show (0.5 : ℚ) ≠ 0 by norm_num)
norm_num
field_simp
/-- The conjugate of the golden ratio is irrational. -/
theorem goldConj_irrational : Irrational ψ := by
have := Nat.Prime.irrational_sqrt (show Nat.Prime 5 by norm_num)
have := this.ratCast_sub 1
convert this.ratCast_mul (show (0.5 : ℚ) ≠ 0 by norm_num)
norm_num
field_simp
/-!
## Links with Fibonacci sequence
-/
| section Fibrec
variable {α : Type*} [CommSemiring α]
/-- The recurrence relation satisfied by the Fibonacci sequence. -/
def fibRec : LinearRecurrence α where
order := 2
| Mathlib/Data/Real/GoldenRatio.lean | 140 | 146 |
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Algebra.Polynomial.Module.Basic
import Mathlib.RingTheory.Finiteness.Nakayama
import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic
import Mathlib.RingTheory.ReesAlgebra
/-!
# `I`-filtrations of modules
This file contains the definitions and basic results around (stable) `I`-filtrations of modules.
## Main results
- `Ideal.Filtration`:
An `I`-filtration on the module `M` is a sequence of decreasing submodules `N i` such that
`∀ i, I • (N i) ≤ N (i + 1)`. Note that we do not require the filtration to start from `⊤`.
- `Ideal.Filtration.Stable`: An `I`-filtration is stable if `I • (N i) = N (i + 1)` for large
enough `i`.
- `Ideal.Filtration.submodule`: The associated module `⨁ Nᵢ` of a filtration, implemented as a
submodule of `M[X]`.
- `Ideal.Filtration.submodule_fg_iff_stable`: If `F.N i` are all finitely generated, then
`F.Stable` iff `F.submodule.FG`.
- `Ideal.Filtration.Stable.of_le`: In a finite module over a noetherian ring,
if `F' ≤ F`, then `F.Stable → F'.Stable`.
- `Ideal.exists_pow_inf_eq_pow_smul`: **Artin-Rees lemma**.
given `N ≤ M`, there exists a `k` such that `IⁿM ⊓ N = Iⁿ⁻ᵏ(IᵏM ⊓ N)` for all `n ≥ k`.
- `Ideal.iInf_pow_eq_bot_of_isLocalRing`:
**Krull's intersection theorem** (`⨅ i, I ^ i = ⊥`) for noetherian local rings.
- `Ideal.iInf_pow_eq_bot_of_isDomain`:
**Krull's intersection theorem** (`⨅ i, I ^ i = ⊥`) for noetherian domains.
-/
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (I : Ideal R)
open Polynomial
open scoped Polynomial
/-- An `I`-filtration on the module `M` is a sequence of decreasing submodules `N i` such that
`I • (N i) ≤ N (i + 1)`. Note that we do not require the filtration to start from `⊤`. -/
@[ext]
structure Ideal.Filtration (M : Type*) [AddCommGroup M] [Module R M] where
N : ℕ → Submodule R M
mono : ∀ i, N (i + 1) ≤ N i
smul_le : ∀ i, I • N i ≤ N (i + 1)
variable (F F' : I.Filtration M) {I}
namespace Ideal.Filtration
theorem pow_smul_le (i j : ℕ) : I ^ i • F.N j ≤ F.N (i + j) := by
induction' i with _ ih
· simp
· rw [pow_succ', mul_smul, add_assoc, add_comm 1, ← add_assoc]
exact (smul_mono_right _ ih).trans (F.smul_le _)
theorem pow_smul_le_pow_smul (i j k : ℕ) : I ^ (i + k) • F.N j ≤ I ^ k • F.N (i + j) := by
rw [add_comm, pow_add, mul_smul]
exact smul_mono_right _ (F.pow_smul_le i j)
protected theorem antitone : Antitone F.N :=
antitone_nat_of_succ_le F.mono
/-- The trivial `I`-filtration of `N`. -/
@[simps]
def _root_.Ideal.trivialFiltration (I : Ideal R) (N : Submodule R M) : I.Filtration M where
N _ := N
| mono _ := le_rfl
smul_le _ := Submodule.smul_le_right
| Mathlib/RingTheory/Filtration.lean | 74 | 76 |
/-
Copyright (c) 2020 Paul van Wamelen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul van Wamelen
-/
import Mathlib.Data.Int.NatPrime
import Mathlib.Data.ZMod.Basic
import Mathlib.RingTheory.Int.Basic
import Mathlib.Tactic.FieldSimp
/-!
# Pythagorean Triples
The main result is the classification of Pythagorean triples. The final result is for general
Pythagorean triples. It follows from the more interesting relatively prime case. We use the
"rational parametrization of the circle" method for the proof. The parametrization maps the point
`(x / z, y / z)` to the slope of the line through `(-1 , 0)` and `(x / z, y / z)`. This quickly
shows that `(x / z, y / z) = (2 * m * n / (m ^ 2 + n ^ 2), (m ^ 2 - n ^ 2) / (m ^ 2 + n ^ 2))` where
`m / n` is the slope. In order to identify numerators and denominators we now need results showing
that these are coprime. This is easy except for the prime 2. In order to deal with that we have to
analyze the parity of `x`, `y`, `m` and `n` and eliminate all the impossible cases. This takes up
the bulk of the proof below.
-/
assert_not_exists TwoSidedIdeal
theorem sq_ne_two_fin_zmod_four (z : ZMod 4) : z * z ≠ 2 := by
change Fin 4 at z
fin_cases z <;> decide
theorem Int.sq_ne_two_mod_four (z : ℤ) : z * z % 4 ≠ 2 := by
| suffices ¬z * z % (4 : ℕ) = 2 % (4 : ℕ) by exact this
rw [← ZMod.intCast_eq_intCast_iff']
simpa using sq_ne_two_fin_zmod_four _
| Mathlib/NumberTheory/PythagoreanTriples.lean | 32 | 34 |
/-
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")]
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]
theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by
simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb
@[bound]
theorem le_div_self (ha : 0 ≤ a) (hb₀ : 0 < b) (hb₁ : b ≤ 1) : a ≤ a / b := by
simpa only [div_one] using div_le_div_of_nonneg_left ha hb₀ hb₁
theorem one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by rw [le_div_iff₀ hb, one_mul]
theorem div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b := by rw [div_le_iff₀ hb, one_mul]
theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iff₀ hb, one_mul]
theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iff₀ hb, one_mul]
theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a := by
simpa using inv_le_comm₀ ha hb
theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by
simpa using inv_lt_comm₀ ha hb
theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by
simpa using le_inv_comm₀ ha hb
theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by
simpa using lt_inv_comm₀ ha hb
@[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a → 1 < a / b := (one_lt_div b0).mpr
@[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b → a / b < 1 := (div_lt_one b0).mpr
/-!
### Relating two divisions, involving `1`
-/
theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a := by
simpa using inv_anti₀ ha h
theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by
rwa [lt_div_iff₀' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)]
theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ a :=
le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h
theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a :=
lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h
/-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and
`le_of_one_div_le_one_div` -/
theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ 1 / b ↔ b ≤ a :=
div_le_div_iff_of_pos_left zero_lt_one ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a :=
div_lt_div_iff_of_pos_left zero_lt_one ha hb
theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by
rwa [lt_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one]
theorem one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a := by
rwa [le_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one]
/-!
### Results about halving.
The equalities also hold in semifields of characteristic `0`.
-/
theorem half_pos (h : 0 < a) : 0 < a / 2 :=
div_pos h zero_lt_two
theorem one_half_pos : (0 : α) < 1 / 2 :=
half_pos zero_lt_one
@[simp]
theorem half_le_self_iff : a / 2 ≤ a ↔ 0 ≤ a := by
rw [div_le_iff₀ (zero_lt_two' α), mul_two, le_add_iff_nonneg_left]
@[simp]
theorem half_lt_self_iff : a / 2 < a ↔ 0 < a := by
rw [div_lt_iff₀ (zero_lt_two' α), mul_two, lt_add_iff_pos_left]
alias ⟨_, half_le_self⟩ := half_le_self_iff
alias ⟨_, half_lt_self⟩ := half_lt_self_iff
alias div_two_lt_of_pos := half_lt_self
theorem one_half_lt_one : (1 / 2 : α) < 1 :=
half_lt_self zero_lt_one
theorem two_inv_lt_one : (2⁻¹ : α) < 1 :=
(one_div _).symm.trans_lt one_half_lt_one
theorem left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iff₀, mul_two]
theorem add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iff₀, mul_two]
theorem add_thirds (a : α) : a / 3 + a / 3 + a / 3 = a := by
rw [div_add_div_same, div_add_div_same, ← two_mul, ← add_one_mul 2 a, two_add_one_eq_three,
mul_div_cancel_left₀ a three_ne_zero]
/-!
### Miscellaneous lemmas
-/
@[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b ↔ 0 < b := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos]
@[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b ↔ 0 < a := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)]
theorem mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c := by
rw [← mul_div_assoc] at h
rwa [mul_comm b, ← div_le_iff₀ hc]
theorem div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) :
a / (b * e) ≤ c / (d * e) := by
rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div]
exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he)
theorem exists_pos_mul_lt {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b * c < a := by
have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one))
refine ⟨a / max (b + 1) 1, this, ?_⟩
rw [← lt_div_iff₀ this, div_div_cancel₀ h.ne']
exact lt_max_iff.2 (Or.inl <| lt_add_one _)
theorem exists_pos_lt_mul {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b < c * a :=
let ⟨c, hc₀, hc⟩ := exists_pos_mul_lt h b;
⟨c⁻¹, inv_pos.2 hc₀, by rwa [← div_eq_inv_mul, lt_div_iff₀ hc₀]⟩
lemma monotone_div_right_of_nonneg (ha : 0 ≤ a) : Monotone (· / a) :=
fun _b _c hbc ↦ div_le_div_of_nonneg_right hbc ha
lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (· / a) :=
fun _b _c hbc ↦ div_lt_div_of_pos_right hbc ha
theorem Monotone.div_const {β : Type*} [Preorder β] {f : β → α} (hf : Monotone f) {c : α}
(hc : 0 ≤ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf
theorem StrictMono.div_const {β : Type*} [Preorder β] {f : β → α} (hf : StrictMono f) {c : α}
(hc : 0 < c) : StrictMono fun x => f x / c := by
simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc)
-- see Note [lower instance priority]
instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered α where
dense a₁ a₂ h :=
⟨(a₁ + a₂) / 2,
calc
a₁ = (a₁ + a₁) / 2 := (add_self_div_two a₁).symm
_ < (a₁ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two
,
calc
(a₁ + a₂) / 2 < (a₂ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two
_ = a₂ := add_self_div_two a₂
⟩
theorem min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = min a b / c :=
(monotone_div_right_of_nonneg hc).map_min.symm
theorem max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = max a b / c :=
(monotone_div_right_of_nonneg hc).map_max.symm
theorem one_div_strictAntiOn : StrictAntiOn (fun x : α => 1 / x) (Set.Ioi 0) :=
fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy
theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) :
1 / a ^ n ≤ 1 / a ^ m := by
refine (one_div_le_one_div ?_ ?_).mpr (pow_right_mono₀ a1 mn) <;>
exact pow_pos (zero_lt_one.trans_le a1) _
theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) :
1 / a ^ n < 1 / a ^ m := by
refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_right₀ a1 mn) <;>
exact pow_pos (zero_lt_one.trans a1) _
theorem one_div_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => 1 / a ^ n := fun _ _ =>
one_div_pow_le_one_div_pow_of_le a1
theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => 1 / a ^ n := fun _ _ =>
one_div_pow_lt_one_div_pow_of_lt a1
theorem inv_strictAntiOn : StrictAntiOn (fun x : α => x⁻¹) (Set.Ioi 0) := fun _ hx _ hy xy =>
(inv_lt_inv₀ hy hx).2 xy
theorem inv_pow_le_inv_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : (a ^ n)⁻¹ ≤ (a ^ m)⁻¹ := by
convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp
theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : (a ^ n)⁻¹ < (a ^ m)⁻¹ := by
convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp
theorem inv_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => (a ^ n)⁻¹ := fun _ _ =>
inv_pow_le_inv_pow_of_le a1
theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => (a ^ n)⁻¹ := fun _ _ =>
inv_pow_lt_inv_pow_of_lt a1
theorem le_iff_forall_one_lt_le_mul₀ {α : Type*}
[Semifield α] [LinearOrder α] [IsStrictOrderedRing α]
{a b : α} (hb : 0 ≤ b) : a ≤ b ↔ ∀ ε, 1 < ε → a ≤ b * ε := by
refine ⟨fun h _ hε ↦ h.trans <| le_mul_of_one_le_right hb hε.le, fun h ↦ ?_⟩
obtain rfl|hb := hb.eq_or_lt
· simp_rw [zero_mul] at h
exact h 2 one_lt_two
refine le_of_forall_gt_imp_ge_of_dense fun x hbx => ?_
convert h (x / b) ((one_lt_div hb).mpr hbx)
rw [mul_div_cancel₀ _ hb.ne']
/-! ### Results about `IsGLB` -/
theorem IsGLB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) :
IsGLB ((fun b => a * b) '' s) (a * b) := by
rcases lt_or_eq_of_le ha with (ha | rfl)
· exact (OrderIso.mulLeft₀ _ ha).isGLB_image'.2 hs
· simp_rw [zero_mul]
rw [hs.nonempty.image_const]
exact isGLB_singleton
theorem IsGLB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) :
IsGLB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha
end LinearOrderedSemifield
section
variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] {a b c d : α} {n : ℤ}
/-! ### Lemmas about pos, nonneg, nonpos, neg -/
theorem div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by
simp only [division_def, mul_pos_iff, inv_pos, inv_lt_zero]
theorem div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by
simp [division_def, mul_neg_iff]
theorem div_nonneg_iff : 0 ≤ a / b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := by
simp [division_def, mul_nonneg_iff]
theorem div_nonpos_iff : a / b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b := by
simp [division_def, mul_nonpos_iff]
theorem div_nonneg_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a / b :=
div_nonneg_iff.2 <| Or.inr ⟨ha, hb⟩
theorem div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b :=
div_pos_iff.2 <| Or.inr ⟨ha, hb⟩
theorem div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 :=
div_neg_iff.2 <| Or.inr ⟨ha, hb⟩
theorem div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 :=
div_neg_iff.2 <| Or.inl ⟨ha, hb⟩
/-! ### Relating one division with another term -/
theorem div_le_iff_of_neg (hc : c < 0) : b / c ≤ a ↔ a * c ≤ b :=
⟨fun h => div_mul_cancel₀ b (ne_of_lt hc) ▸ mul_le_mul_of_nonpos_right h hc.le, fun h =>
calc
a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc)
_ ≥ b * (1 / c) := mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le
_ = b / c := (div_eq_mul_one_div b c).symm
⟩
theorem div_le_iff_of_neg' (hc : c < 0) : b / c ≤ a ↔ c * a ≤ b := by
rw [mul_comm, div_le_iff_of_neg hc]
theorem le_div_iff_of_neg (hc : c < 0) : a ≤ b / c ↔ b ≤ a * c := by
rw [← neg_neg c, mul_neg, div_neg, le_neg, div_le_iff₀ (neg_pos.2 hc), neg_mul]
theorem le_div_iff_of_neg' (hc : c < 0) : a ≤ b / c ↔ b ≤ c * a := by
rw [mul_comm, le_div_iff_of_neg hc]
theorem div_lt_iff_of_neg (hc : c < 0) : b / c < a ↔ a * c < b :=
lt_iff_lt_of_le_iff_le <| le_div_iff_of_neg hc
theorem div_lt_iff_of_neg' (hc : c < 0) : b / c < a ↔ c * a < b := by
rw [mul_comm, div_lt_iff_of_neg hc]
theorem lt_div_iff_of_neg (hc : c < 0) : a < b / c ↔ b < a * c :=
lt_iff_lt_of_le_iff_le <| div_le_iff_of_neg hc
theorem lt_div_iff_of_neg' (hc : c < 0) : a < b / c ↔ b < c * a := by
rw [mul_comm, lt_div_iff_of_neg hc]
theorem div_le_one_of_ge (h : b ≤ a) (hb : b ≤ 0) : a / b ≤ 1 := by
simpa only [neg_div_neg_eq] using div_le_one_of_le₀ (neg_le_neg h) (neg_nonneg_of_nonpos hb)
/-! ### Bi-implications of inequalities using inversions -/
theorem inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by
rw [← one_div, div_le_iff_of_neg ha, ← div_eq_inv_mul, div_le_iff_of_neg hb, one_mul]
theorem inv_le_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by
rw [← inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv]
theorem le_inv_of_neg (ha : a < 0) (hb : b < 0) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by
rw [← inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv]
theorem inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b⁻¹ ↔ b < a :=
lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha)
theorem inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b ↔ b⁻¹ < a :=
lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha)
theorem lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b⁻¹ ↔ b < a⁻¹ :=
lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha)
/-!
### Monotonicity results involving inversion
-/
theorem sub_inv_antitoneOn_Ioi :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Ioi c) :=
antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦
inv_le_inv₀ (sub_pos.mpr hb) (sub_pos.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl
theorem sub_inv_antitoneOn_Iio :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Iio c) :=
antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦
inv_le_inv_of_neg (sub_neg.mpr hb) (sub_neg.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl
theorem sub_inv_antitoneOn_Icc_right (ha : c < a) :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by
by_cases hab : a ≤ b
· exact sub_inv_antitoneOn_Ioi.mono <| (Set.Icc_subset_Ioi_iff hab).mpr ha
· simp [hab, Set.Subsingleton.antitoneOn]
theorem sub_inv_antitoneOn_Icc_left (ha : b < c) :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by
by_cases hab : a ≤ b
· exact sub_inv_antitoneOn_Iio.mono <| (Set.Icc_subset_Iio_iff hab).mpr ha
· simp [hab, Set.Subsingleton.antitoneOn]
theorem inv_antitoneOn_Ioi :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Ioi 0) := by
convert sub_inv_antitoneOn_Ioi (α := α)
exact (sub_zero _).symm
theorem inv_antitoneOn_Iio :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Iio 0) := by
convert sub_inv_antitoneOn_Iio (α := α)
exact (sub_zero _).symm
theorem inv_antitoneOn_Icc_right (ha : 0 < a) :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by
convert sub_inv_antitoneOn_Icc_right ha
exact (sub_zero _).symm
theorem inv_antitoneOn_Icc_left (hb : b < 0) :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by
convert sub_inv_antitoneOn_Icc_left hb
exact (sub_zero _).symm
/-! ### Relating two divisions -/
theorem div_le_div_of_nonpos_of_le (hc : c ≤ 0) (h : b ≤ a) : a / c ≤ b / c := by
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c]
exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc)
theorem div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c := by
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c]
exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc)
theorem div_le_div_right_of_neg (hc : c < 0) : a / c ≤ b / c ↔ b ≤ a :=
⟨le_imp_le_of_lt_imp_lt <| div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le <| hc.le⟩
theorem div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c ↔ b < a :=
lt_iff_lt_of_le_iff_le <| div_le_div_right_of_neg hc
/-! ### Relating one division and involving `1` -/
theorem one_le_div_of_neg (hb : b < 0) : 1 ≤ a / b ↔ a ≤ b := by rw [le_div_iff_of_neg hb, one_mul]
theorem div_le_one_of_neg (hb : b < 0) : a / b ≤ 1 ↔ b ≤ a := by rw [div_le_iff_of_neg hb, one_mul]
theorem one_lt_div_of_neg (hb : b < 0) : 1 < a / b ↔ a < b := by rw [lt_div_iff_of_neg hb, one_mul]
theorem div_lt_one_of_neg (hb : b < 0) : a / b < 1 ↔ b < a := by rw [div_lt_iff_of_neg hb, one_mul]
theorem one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ b ↔ 1 / b ≤ a := by
simpa using inv_le_of_neg ha hb
theorem one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b ↔ 1 / b < a := by
simpa using inv_lt_of_neg ha hb
theorem le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a ≤ 1 / b ↔ b ≤ 1 / a := by
simpa using le_inv_of_neg ha hb
theorem lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b ↔ b < 1 / a := by
simpa using lt_inv_of_neg ha hb
theorem one_lt_div_iff : 1 < a / b ↔ 0 < b ∧ b < a ∨ b < 0 ∧ a < b := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
· simp [hb, hb.not_lt, one_lt_div_of_neg]
· simp [lt_irrefl, zero_le_one]
· simp [hb, hb.not_lt, one_lt_div]
theorem one_le_div_iff : 1 ≤ a / b ↔ 0 < b ∧ b ≤ a ∨ b < 0 ∧ a ≤ b := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
· simp [hb, hb.not_lt, one_le_div_of_neg]
· simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one]
· simp [hb, hb.not_lt, one_le_div]
theorem div_lt_one_iff : a / b < 1 ↔ 0 < b ∧ a < b ∨ b = 0 ∨ b < 0 ∧ b < a := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
· simp [hb, hb.not_lt, hb.ne, div_lt_one_of_neg]
· simp [zero_lt_one]
· simp [hb, hb.not_lt, div_lt_one, hb.ne.symm]
theorem div_le_one_iff : a / b ≤ 1 ↔ 0 < b ∧ a ≤ b ∨ b = 0 ∨ b < 0 ∧ b ≤ a := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
· simp [hb, hb.not_lt, hb.ne, div_le_one_of_neg]
· simp [zero_le_one]
· simp [hb, hb.not_lt, div_le_one, hb.ne.symm]
/-! ### Relating two divisions, involving `1` -/
theorem one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a ≤ b) : 1 / b ≤ 1 / a := by
rwa [div_le_iff_of_neg' hb, ← div_eq_mul_one_div, div_le_one_of_neg (h.trans_lt hb)]
theorem one_div_lt_one_div_of_neg_of_lt (hb : b < 0) (h : a < b) : 1 / b < 1 / a := by
rwa [div_lt_iff_of_neg' hb, ← div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)]
theorem le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a ≤ 1 / b) : b ≤ a :=
le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h
theorem lt_of_neg_of_one_div_lt_one_div (hb : b < 0) (h : 1 / a < 1 / b) : b < a :=
lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_le_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ 1 / b ↔ b ≤ a := by
simpa [one_div] using inv_le_inv_of_neg ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b ↔ b < a :=
lt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha)
theorem one_div_lt_neg_one (h1 : a < 0) (h2 : -1 < a) : 1 / a < -1 :=
suffices 1 / a < 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this
one_div_lt_one_div_of_neg_of_lt h1 h2
theorem one_div_le_neg_one (h1 : a < 0) (h2 : -1 ≤ a) : 1 / a ≤ -1 :=
suffices 1 / a ≤ 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this
one_div_le_one_div_of_neg_of_le h1 h2
/-! ### Results about halving -/
theorem sub_self_div_two (a : α) : a - a / 2 = a / 2 := by
suffices a / 2 + a / 2 - a / 2 = a / 2 by rwa [add_halves] at this
rw [add_sub_cancel_right]
theorem div_two_sub_self (a : α) : a / 2 - a = -(a / 2) := by
suffices a / 2 - (a / 2 + a / 2) = -(a / 2) by rwa [add_halves] at this
rw [sub_add_eq_sub_sub, sub_self, zero_sub]
theorem add_sub_div_two_lt (h : a < b) : a + (b - a) / 2 < b := by
rwa [← div_sub_div_same, sub_eq_add_neg, add_comm (b / 2), ← add_assoc, ← sub_eq_add_neg, ←
lt_sub_iff_add_lt, sub_self_div_two, sub_self_div_two,
div_lt_div_iff_of_pos_right (zero_lt_two' α)]
/-- An inequality involving `2`. -/
theorem sub_one_div_inv_le_two (a2 : 2 ≤ a) : (1 - 1 / a)⁻¹ ≤ 2 := by
-- Take inverses on both sides to obtain `2⁻¹ ≤ 1 - 1 / a`
refine (inv_anti₀ (inv_pos.2 <| zero_lt_two' α) ?_).trans_eq (inv_inv (2 : α))
-- move `1 / a` to the left and `2⁻¹` to the right.
rw [le_sub_iff_add_le, add_comm, ← le_sub_iff_add_le]
-- take inverses on both sides and use the assumption `2 ≤ a`.
convert (one_div a).le.trans (inv_anti₀ zero_lt_two a2) using 1
-- show `1 - 1 / 2 = 1 / 2`.
rw [sub_eq_iff_eq_add, ← two_mul, mul_inv_cancel₀ two_ne_zero]
/-! ### Results about `IsLUB` -/
-- TODO: Generalize to `LinearOrderedSemifield`
theorem IsLUB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsLUB s b) :
IsLUB ((fun b => a * b) '' s) (a * b) := by
rcases lt_or_eq_of_le ha with (ha | rfl)
· exact (OrderIso.mulLeft₀ _ ha).isLUB_image'.2 hs
· simp_rw [zero_mul]
rw [hs.nonempty.image_const]
exact isLUB_singleton
-- TODO: Generalize to `LinearOrderedSemifield`
theorem IsLUB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsLUB s b) :
IsLUB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha
/-! ### Miscellaneous lemmas -/
theorem mul_sub_mul_div_mul_neg_iff (hc : c ≠ 0) (hd : d ≠ 0) :
(a * d - b * c) / (c * d) < 0 ↔ a / c < b / d := by
rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_lt_zero]
theorem mul_sub_mul_div_mul_nonpos_iff (hc : c ≠ 0) (hd : d ≠ 0) :
(a * d - b * c) / (c * d) ≤ 0 ↔ a / c ≤ b / d := by
rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_nonpos]
alias ⟨div_lt_div_of_mul_sub_mul_div_neg, mul_sub_mul_div_mul_neg⟩ := mul_sub_mul_div_mul_neg_iff
alias ⟨div_le_div_of_mul_sub_mul_div_nonpos, mul_sub_mul_div_mul_nonpos⟩ :=
mul_sub_mul_div_mul_nonpos_iff
theorem exists_add_lt_and_pos_of_lt (h : b < a) : ∃ c, b + c < a ∧ 0 < c :=
⟨(a - b) / 2, add_sub_div_two_lt h, div_pos (sub_pos_of_lt h) zero_lt_two⟩
theorem le_of_forall_sub_le (h : ∀ ε > 0, b - ε ≤ a) : b ≤ a := by
contrapose! h
simpa only [@and_comm ((0 : α) < _), lt_sub_iff_add_lt, gt_iff_lt] using
exists_add_lt_and_pos_of_lt h
private lemma exists_lt_mul_left_of_nonneg {a b c : α} (ha : 0 ≤ a) (hc : 0 ≤ c) (h : c < a * b) :
∃ a' ∈ Set.Ico 0 a, c < a' * b := by
have hb : 0 < b := pos_of_mul_pos_right (hc.trans_lt h) ha
obtain ⟨a', ha', a_a'⟩ := exists_between ((div_lt_iff₀ hb).2 h)
exact ⟨a', ⟨(div_nonneg hc hb.le).trans ha'.le, a_a'⟩, (div_lt_iff₀ hb).1 ha'⟩
private lemma exists_lt_mul_right_of_nonneg {a b c : α} (ha : 0 ≤ a) (hc : 0 ≤ c) (h : c < a * b) :
∃ b' ∈ Set.Ico 0 b, c < a * b' := by
have hb : 0 < b := pos_of_mul_pos_right (hc.trans_lt h) ha
simp_rw [mul_comm a] at h ⊢
exact exists_lt_mul_left_of_nonneg hb.le hc h
private lemma exists_mul_left_lt₀ {a b c : α} (hc : a * b < c) : ∃ a' > a, a' * b < c := by
rcases le_or_lt b 0 with hb | hb
· obtain ⟨a', ha'⟩ := exists_gt a
exact ⟨a', ha', hc.trans_le' (antitone_mul_right hb ha'.le)⟩
· obtain ⟨a', ha', hc'⟩ := exists_between ((lt_div_iff₀ hb).2 hc)
exact ⟨a', ha', (lt_div_iff₀ hb).1 hc'⟩
private lemma exists_mul_right_lt₀ {a b c : α} (hc : a * b < c) : ∃ b' > b, a * b' < c := by
simp_rw [mul_comm a] at hc ⊢; exact exists_mul_left_lt₀ hc
lemma le_mul_of_forall_lt₀ {a b c : α} (h : ∀ a' > a, ∀ b' > b, c ≤ a' * b') : c ≤ a * b := by
refine le_of_forall_gt_imp_ge_of_dense fun d hd ↦ ?_
obtain ⟨a', ha', hd⟩ := exists_mul_left_lt₀ hd
obtain ⟨b', hb', hd⟩ := exists_mul_right_lt₀ hd
exact (h a' ha' b' hb').trans hd.le
lemma mul_le_of_forall_lt_of_nonneg {a b c : α} (ha : 0 ≤ a) (hc : 0 ≤ c)
(h : ∀ a' ≥ 0, a' < a → ∀ b' ≥ 0, b' < b → a' * b' ≤ c) : a * b ≤ c := by
refine le_of_forall_lt_imp_le_of_dense fun d d_ab ↦ ?_
rcases lt_or_le d 0 with hd | hd
· exact hd.le.trans hc
obtain ⟨a', ha', d_ab⟩ := exists_lt_mul_left_of_nonneg ha hd d_ab
obtain ⟨b', hb', d_ab⟩ := exists_lt_mul_right_of_nonneg ha'.1 hd d_ab
exact d_ab.le.trans (h a' ha'.1 ha'.2 b' hb'.1 hb'.2)
theorem mul_self_inj_of_nonneg (a0 : 0 ≤ a) (b0 : 0 ≤ b) : a * a = b * b ↔ a = b :=
mul_self_eq_mul_self_iff.trans <|
or_iff_left_of_imp fun h => by
subst a
have : b = 0 := le_antisymm (neg_nonneg.1 a0) b0
rw [this, neg_zero]
theorem min_div_div_right_of_nonpos (hc : c ≤ 0) (a b : α) : min (a / c) (b / c) = max a b / c :=
Eq.symm <| Antitone.map_max fun _ _ => div_le_div_of_nonpos_of_le hc
theorem max_div_div_right_of_nonpos (hc : c ≤ 0) (a b : α) : max (a / c) (b / c) = min a b / c :=
Eq.symm <| Antitone.map_min fun _ _ => div_le_div_of_nonpos_of_le hc
theorem abs_inv (a : α) : |a⁻¹| = |a|⁻¹ :=
map_inv₀ (absHom : α →*₀ α) a
theorem abs_div (a b : α) : |a / b| = |a| / |b| :=
map_div₀ (absHom : α →*₀ α) a b
theorem abs_one_div (a : α) : |1 / a| = 1 / |a| := by rw [abs_div, abs_one]
theorem uniform_continuous_npow_on_bounded (B : α) {ε : α} (hε : 0 < ε) (n : ℕ) :
∃ δ > 0, ∀ q r : α, |r| ≤ B → |q - r| ≤ δ → |q ^ n - r ^ n| < ε := by
wlog B_pos : 0 < B generalizing B
· have ⟨δ, δ_pos, cont⟩ := this 1 zero_lt_one
exact ⟨δ, δ_pos, fun q r hr ↦ cont q r (hr.trans ((le_of_not_lt B_pos).trans zero_le_one))⟩
have pos : 0 < 1 + ↑n * (B + 1) ^ (n - 1) := zero_lt_one.trans_le <| le_add_of_nonneg_right <|
mul_nonneg n.cast_nonneg <| (pow_pos (B_pos.trans <| lt_add_of_pos_right _ zero_lt_one) _).le
refine ⟨min 1 (ε / (1 + n * (B + 1) ^ (n - 1))), lt_min zero_lt_one (div_pos hε pos),
fun q r hr hqr ↦ (abs_pow_sub_pow_le ..).trans_lt ?_⟩
rw [le_inf_iff, le_div_iff₀ pos, mul_one_add, ← mul_assoc] at hqr
obtain h | h := (abs_nonneg (q - r)).eq_or_lt
· simpa only [← h, zero_mul] using hε
refine (lt_of_le_of_lt ?_ <| lt_add_of_pos_left _ h).trans_le hqr.2
refine mul_le_mul_of_nonneg_left (pow_le_pow_left₀ ((abs_nonneg _).trans le_sup_left) ?_ _)
(mul_nonneg (abs_nonneg _) n.cast_nonneg)
refine max_le ?_ (hr.trans <| le_add_of_nonneg_right zero_le_one)
exact add_sub_cancel r q ▸ (abs_add_le ..).trans (add_le_add hr hqr.1)
end
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
section LinearOrderedSemifield
variable {α : Type*} [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a b : α}
private lemma div_nonneg_of_pos_of_nonneg (ha : 0 < a) (hb : 0 ≤ b) : 0 ≤ a / b :=
div_nonneg ha.le hb
private lemma div_nonneg_of_nonneg_of_pos (ha : 0 ≤ a) (hb : 0 < b) : 0 ≤ a / b :=
div_nonneg ha hb.le
omit [IsStrictOrderedRing α] in
private lemma div_ne_zero_of_pos_of_ne_zero (ha : 0 < a) (hb : b ≠ 0) : a / b ≠ 0 :=
div_ne_zero ha.ne' hb
omit [IsStrictOrderedRing α] in
private lemma div_ne_zero_of_ne_zero_of_pos (ha : a ≠ 0) (hb : 0 < b) : a / b ≠ 0 :=
div_ne_zero ha hb.ne'
private lemma zpow_zero_pos (a : α) : 0 < a ^ (0 : ℤ) := zero_lt_one.trans_eq (zpow_zero a).symm
end LinearOrderedSemifield
/-- The `positivity` extension which identifies expressions of the form `a / b`,
such that `positivity` successfully recognises both `a` and `b`. -/
@[positivity _ / _] def evalDiv : PositivityExt where eval {u α} zα pα e := do
let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← withReducible (whnf e)
| throwError "not /"
let _e_eq : $e =Q $f $a $b := ⟨⟩
let _a ← synthInstanceQ q(Semifield $α)
let _a ← synthInstanceQ q(LinearOrder $α)
let _a ← synthInstanceQ q(IsStrictOrderedRing $α)
assumeInstancesCommute
let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(HDiv.hDiv)
let ra ← core zα pα a; let rb ← core zα pα b
match ra, rb with
| .positive pa, .positive pb => pure (.positive q(div_pos $pa $pb))
| .positive pa, .nonnegative pb => pure (.nonnegative q(div_nonneg_of_pos_of_nonneg $pa $pb))
| .nonnegative pa, .positive pb => pure (.nonnegative q(div_nonneg_of_nonneg_of_pos $pa $pb))
| .nonnegative pa, .nonnegative pb => pure (.nonnegative q(div_nonneg $pa $pb))
| .positive pa, .nonzero pb => pure (.nonzero q(div_ne_zero_of_pos_of_ne_zero $pa $pb))
| .nonzero pa, .positive pb => pure (.nonzero q(div_ne_zero_of_ne_zero_of_pos $pa $pb))
| .nonzero pa, .nonzero pb => pure (.nonzero q(div_ne_zero $pa $pb))
| _, _ => pure .none
/-- The `positivity` extension which identifies expressions of the form `a⁻¹`,
such that `positivity` successfully recognises `a`. -/
@[positivity _⁻¹]
def evalInv : PositivityExt where eval {u α} zα pα e := do
let .app (f : Q($α → $α)) (a : Q($α)) ← withReducible (whnf e) | throwError "not ⁻¹"
let _e_eq : $e =Q $f $a := ⟨⟩
let _a ← synthInstanceQ q(Semifield $α)
let _a ← synthInstanceQ q(LinearOrder $α)
let _a ← synthInstanceQ q(IsStrictOrderedRing $α)
assumeInstancesCommute
let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(Inv.inv)
let ra ← core zα pα a
match ra with
| .positive pa => pure (.positive q(inv_pos_of_pos $pa))
| .nonnegative pa => pure (.nonnegative q(inv_nonneg_of_nonneg $pa))
| .nonzero pa => pure (.nonzero q(inv_ne_zero $pa))
| .none => pure .none
/-- The `positivity` extension which identifies expressions of the form `a ^ (0:ℤ)`. -/
@[positivity _ ^ (0 : ℤ), Pow.pow _ (0 : ℤ)]
def evalPowZeroInt : PositivityExt where eval {u α} _zα _pα e := do
let .app (.app _ (a : Q($α))) _ ← withReducible (whnf e) | throwError "not ^"
let _a ← synthInstanceQ q(Semifield $α)
let _a ← synthInstanceQ q(LinearOrder $α)
let _a ← synthInstanceQ q(IsStrictOrderedRing $α)
assumeInstancesCommute
let ⟨_a⟩ ← Qq.assertDefEqQ q($e) q($a ^ (0 : ℤ))
pure (.positive q(zpow_zero_pos $a))
end Mathlib.Meta.Positivity
| Mathlib/Algebra/Order/Field/Basic.lean | 803 | 803 | |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Algebra.Operations
import Mathlib.Algebra.Module.BigOperators
import Mathlib.Data.Fintype.Lattice
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Ideal.Basic
import Mathlib.RingTheory.NonUnitalSubsemiring.Basic
/-!
# More operations on modules and ideals
-/
assert_not_exists Basis -- See `RingTheory.Ideal.Basis`
Submodule.hasQuotient -- See `RingTheory.Ideal.Quotient.Operations`
universe u v w x
open Pointwise
namespace Submodule
lemma coe_span_smul {R' M' : Type*} [CommSemiring R'] [AddCommMonoid M'] [Module R' M']
(s : Set R') (N : Submodule R' M') :
(Ideal.span s : Set R') • N = s • N :=
set_smul_eq_of_le _ _ _
(by rintro r n hr hn
induction hr using Submodule.span_induction with
| mem _ h => exact mem_set_smul_of_mem_mem h hn
| zero => rw [zero_smul]; exact Submodule.zero_mem _
| add _ _ _ _ ihr ihs => rw [add_smul]; exact Submodule.add_mem _ ihr ihs
| smul _ _ hr =>
rw [mem_span_set] at hr
obtain ⟨c, hc, rfl⟩ := hr
rw [Finsupp.sum, Finset.smul_sum, Finset.sum_smul]
refine Submodule.sum_mem _ fun i hi => ?_
rw [← mul_smul, smul_eq_mul, mul_comm, mul_smul]
exact mem_set_smul_of_mem_mem (hc hi) <| Submodule.smul_mem _ _ hn) <|
set_smul_mono_left _ Submodule.subset_span
lemma span_singleton_toAddSubgroup_eq_zmultiples (a : ℤ) :
(span ℤ {a}).toAddSubgroup = AddSubgroup.zmultiples a := by
ext i
simp [Ideal.mem_span_singleton', AddSubgroup.mem_zmultiples_iff]
@[simp] lemma _root_.Ideal.span_singleton_toAddSubgroup_eq_zmultiples (a : ℤ) :
(Ideal.span {a}).toAddSubgroup = AddSubgroup.zmultiples a :=
Submodule.span_singleton_toAddSubgroup_eq_zmultiples _
variable {R : Type u} {M : Type v} {M' F G : Type*}
section Semiring
variable [Semiring R] [AddCommMonoid M] [Module R M]
/-- This duplicates the global `smul_eq_mul`, but doesn't have to unfold anywhere near as much to
apply. -/
protected theorem _root_.Ideal.smul_eq_mul (I J : Ideal R) : I • J = I * J :=
rfl
variable {I J : Ideal R} {N : Submodule R M}
theorem smul_le_right : I • N ≤ N :=
smul_le.2 fun r _ _ ↦ N.smul_mem r
theorem map_le_smul_top (I : Ideal R) (f : R →ₗ[R] M) :
Submodule.map f I ≤ I • (⊤ : Submodule R M) := by
rintro _ ⟨y, hy, rfl⟩
rw [← mul_one y, ← smul_eq_mul, f.map_smul]
exact smul_mem_smul hy mem_top
variable (I J N)
@[simp]
theorem top_smul : (⊤ : Ideal R) • N = N :=
le_antisymm smul_le_right fun r hri => one_smul R r ▸ smul_mem_smul mem_top hri
protected theorem mul_smul : (I * J) • N = I • J • N :=
Submodule.smul_assoc _ _ _
theorem mem_of_span_top_of_smul_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M)
(H : ∀ r : s, (r : R) • x ∈ M') : x ∈ M' := by
suffices LinearMap.range (LinearMap.toSpanSingleton R M x) ≤ M' by
rw [← LinearMap.toSpanSingleton_one R M x]
exact this (LinearMap.mem_range_self _ 1)
rw [LinearMap.range_eq_map, ← hs, map_le_iff_le_comap, Ideal.span, span_le]
exact fun r hr ↦ H ⟨r, hr⟩
variable {M' : Type w} [AddCommMonoid M'] [Module R M']
@[simp]
theorem map_smul'' (f : M →ₗ[R] M') : (I • N).map f = I • N.map f :=
le_antisymm
(map_le_iff_le_comap.2 <|
smul_le.2 fun r hr n hn =>
show f (r • n) ∈ I • N.map f from
(f.map_smul r n).symm ▸ smul_mem_smul hr (mem_map_of_mem hn)) <|
smul_le.2 fun r hr _ hn =>
let ⟨p, hp, hfp⟩ := mem_map.1 hn
hfp ▸ f.map_smul r p ▸ mem_map_of_mem (smul_mem_smul hr hp)
theorem mem_smul_top_iff (N : Submodule R M) (x : N) :
x ∈ I • (⊤ : Submodule R N) ↔ (x : M) ∈ I • N := by
have : Submodule.map N.subtype (I • ⊤) = I • N := by
rw [Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype]
simp [← this, -map_smul'']
@[simp]
theorem smul_comap_le_comap_smul (f : M →ₗ[R] M') (S : Submodule R M') (I : Ideal R) :
I • S.comap f ≤ (I • S).comap f := by
refine Submodule.smul_le.mpr fun r hr x hx => ?_
rw [Submodule.mem_comap] at hx ⊢
rw [f.map_smul]
exact Submodule.smul_mem_smul hr hx
end Semiring
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
open Pointwise
theorem mem_smul_span_singleton {I : Ideal R} {m : M} {x : M} :
x ∈ I • span R ({m} : Set M) ↔ ∃ y ∈ I, y • m = x :=
⟨fun hx =>
smul_induction_on hx
(fun r hri _ hnm =>
let ⟨s, hs⟩ := mem_span_singleton.1 hnm
⟨r * s, I.mul_mem_right _ hri, hs ▸ mul_smul r s m⟩)
fun m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩ =>
⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩,
fun ⟨_, hyi, hy⟩ => hy ▸ smul_mem_smul hyi (subset_span <| Set.mem_singleton m)⟩
variable {I J : Ideal R} {N P : Submodule R M}
variable (S : Set R) (T : Set M)
theorem smul_eq_map₂ : I • N = Submodule.map₂ (LinearMap.lsmul R M) I N :=
le_antisymm (smul_le.mpr fun _m hm _n ↦ Submodule.apply_mem_map₂ _ hm)
(map₂_le.mpr fun _m hm _n ↦ smul_mem_smul hm)
theorem span_smul_span : Ideal.span S • span R T = span R (⋃ (s ∈ S) (t ∈ T), {s • t}) := by
rw [smul_eq_map₂]
exact (map₂_span_span _ _ _ _).trans <| congr_arg _ <| Set.image2_eq_iUnion _ _ _
theorem ideal_span_singleton_smul (r : R) (N : Submodule R M) :
(Ideal.span {r} : Ideal R) • N = r • N := by
have : span R (⋃ (t : M) (_ : t ∈ N), {r • t}) = r • N := by
convert span_eq (r • N)
exact (Set.image_eq_iUnion _ (N : Set M)).symm
conv_lhs => rw [← span_eq N, span_smul_span]
simpa
/-- Given `s`, a generating set of `R`, to check that an `x : M` falls in a
submodule `M'` of `x`, we only need to show that `r ^ n • x ∈ M'` for some `n` for each `r : s`. -/
theorem mem_of_span_eq_top_of_smul_pow_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤)
(x : M) (H : ∀ r : s, ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M') : x ∈ M' := by
choose f hf using H
apply M'.mem_of_span_top_of_smul_mem _ (Ideal.span_range_pow_eq_top s hs f)
rintro ⟨_, r, hr, rfl⟩
exact hf r
open Pointwise in
@[simp]
theorem map_pointwise_smul (r : R) (N : Submodule R M) (f : M →ₗ[R] M') :
(r • N).map f = r • N.map f := by
simp_rw [← ideal_span_singleton_smul, map_smul'']
theorem mem_smul_span {s : Set M} {x : M} :
x ∈ I • Submodule.span R s ↔ x ∈ Submodule.span R (⋃ (a ∈ I) (b ∈ s), ({a • b} : Set M)) := by
rw [← I.span_eq, Submodule.span_smul_span, I.span_eq]
simp
variable (I)
/-- If `x` is an `I`-multiple of the submodule spanned by `f '' s`,
then we can write `x` as an `I`-linear combination of the elements of `f '' s`. -/
theorem mem_ideal_smul_span_iff_exists_sum {ι : Type*} (f : ι → M) (x : M) :
x ∈ I • span R (Set.range f) ↔
∃ (a : ι →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by
constructor; swap
· rintro ⟨a, ha, rfl⟩
exact Submodule.sum_mem _ fun c _ => smul_mem_smul (ha c) <| subset_span <| Set.mem_range_self _
refine fun hx => span_induction ?_ ?_ ?_ ?_ (mem_smul_span.mp hx)
· simp only [Set.mem_iUnion, Set.mem_range, Set.mem_singleton_iff]
rintro x ⟨y, hy, x, ⟨i, rfl⟩, rfl⟩
refine ⟨Finsupp.single i y, fun j => ?_, ?_⟩
· letI := Classical.decEq ι
rw [Finsupp.single_apply]
split_ifs
· assumption
· exact I.zero_mem
refine @Finsupp.sum_single_index ι R M _ _ i _ (fun i y => y • f i) ?_
simp
· exact ⟨0, fun _ => I.zero_mem, Finsupp.sum_zero_index⟩
· rintro x y - - ⟨ax, hax, rfl⟩ ⟨ay, hay, rfl⟩
refine ⟨ax + ay, fun i => I.add_mem (hax i) (hay i), Finsupp.sum_add_index' ?_ ?_⟩ <;>
intros <;> simp only [zero_smul, add_smul]
· rintro c x - ⟨a, ha, rfl⟩
refine ⟨c • a, fun i => I.mul_mem_left c (ha i), ?_⟩
rw [Finsupp.sum_smul_index, Finsupp.smul_sum] <;> intros <;> simp only [zero_smul, mul_smul]
theorem mem_ideal_smul_span_iff_exists_sum' {ι : Type*} (s : Set ι) (f : ι → M) (x : M) :
x ∈ I • span R (f '' s) ↔
∃ (a : s →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by
rw [← Submodule.mem_ideal_smul_span_iff_exists_sum, ← Set.image_eq_range]
end CommSemiring
end Submodule
namespace Ideal
section Add
variable {R : Type u} [Semiring R]
@[simp]
theorem add_eq_sup {I J : Ideal R} : I + J = I ⊔ J :=
rfl
@[simp]
theorem zero_eq_bot : (0 : Ideal R) = ⊥ :=
rfl
@[simp]
theorem sum_eq_sup {ι : Type*} (s : Finset ι) (f : ι → Ideal R) : s.sum f = s.sup f :=
rfl
end Add
section Semiring
variable {R : Type u} [Semiring R] {I J K L : Ideal R}
@[simp]
theorem one_eq_top : (1 : Ideal R) = ⊤ := by
rw [Submodule.one_eq_span, ← Ideal.span, Ideal.span_singleton_one]
theorem add_eq_one_iff : I + J = 1 ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by
rw [one_eq_top, eq_top_iff_one, add_eq_sup, Submodule.mem_sup]
theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J :=
Submodule.smul_mem_smul hr hs
theorem pow_mem_pow {x : R} (hx : x ∈ I) (n : ℕ) : x ^ n ∈ I ^ n :=
Submodule.pow_mem_pow _ hx _
theorem mul_le : I * J ≤ K ↔ ∀ r ∈ I, ∀ s ∈ J, r * s ∈ K :=
Submodule.smul_le
theorem mul_le_left : I * J ≤ J :=
mul_le.2 fun _ _ _ => J.mul_mem_left _
@[simp]
theorem sup_mul_left_self : I ⊔ J * I = I :=
sup_eq_left.2 mul_le_left
@[simp]
theorem mul_left_self_sup : J * I ⊔ I = I :=
sup_eq_right.2 mul_le_left
theorem mul_le_right [I.IsTwoSided] : I * J ≤ I :=
mul_le.2 fun _ hr _ _ ↦ I.mul_mem_right _ hr
@[simp]
theorem sup_mul_right_self [I.IsTwoSided] : I ⊔ I * J = I :=
sup_eq_left.2 mul_le_right
@[simp]
theorem mul_right_self_sup [I.IsTwoSided] : I * J ⊔ I = I :=
sup_eq_right.2 mul_le_right
protected theorem mul_assoc : I * J * K = I * (J * K) :=
Submodule.smul_assoc I J K
variable (I)
theorem mul_bot : I * ⊥ = ⊥ := by simp
theorem bot_mul : ⊥ * I = ⊥ := by simp
@[simp]
theorem top_mul : ⊤ * I = I :=
Submodule.top_smul I
variable {I}
theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L :=
Submodule.smul_mono hik hjl
theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K :=
Submodule.smul_mono_left h
theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K :=
smul_mono_right I h
variable (I J K)
theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K :=
Submodule.smul_sup I J K
theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K :=
Submodule.sup_smul I J K
variable {I J K}
theorem pow_le_pow_right {m n : ℕ} (h : m ≤ n) : I ^ n ≤ I ^ m := by
obtain _ | m := m
· rw [Submodule.pow_zero, one_eq_top]; exact le_top
obtain ⟨n, rfl⟩ := Nat.exists_eq_add_of_le h
rw [add_comm, Submodule.pow_add _ m.add_one_ne_zero]
exact mul_le_left
theorem pow_le_self {n : ℕ} (hn : n ≠ 0) : I ^ n ≤ I :=
calc
I ^ n ≤ I ^ 1 := pow_le_pow_right (Nat.pos_of_ne_zero hn)
_ = I := Submodule.pow_one _
theorem pow_right_mono (e : I ≤ J) (n : ℕ) : I ^ n ≤ J ^ n := by
induction' n with _ hn
· rw [Submodule.pow_zero, Submodule.pow_zero]
· rw [Submodule.pow_succ, Submodule.pow_succ]
exact Ideal.mul_mono hn e
namespace IsTwoSided
instance (priority := low) [J.IsTwoSided] : (I * J).IsTwoSided :=
⟨fun b ha ↦ Submodule.mul_induction_on ha
(fun i hi j hj ↦ by rw [mul_assoc]; exact mul_mem_mul hi (mul_mem_right _ _ hj))
fun x y hx hy ↦ by rw [right_distrib]; exact add_mem hx hy⟩
variable [I.IsTwoSided] (m n : ℕ)
instance (priority := low) : (I ^ n).IsTwoSided :=
n.rec
(by rw [Submodule.pow_zero, one_eq_top]; infer_instance)
(fun _ _ ↦ by rw [Submodule.pow_succ]; infer_instance)
protected theorem mul_one : I * 1 = I :=
mul_le_right.antisymm
fun i hi ↦ mul_one i ▸ mul_mem_mul hi (one_eq_top (R := R) ▸ Submodule.mem_top)
protected theorem pow_add : I ^ (m + n) = I ^ m * I ^ n := by
obtain rfl | h := eq_or_ne n 0
· rw [add_zero, Submodule.pow_zero, IsTwoSided.mul_one]
· exact Submodule.pow_add _ h
protected theorem pow_succ : I ^ (n + 1) = I * I ^ n := by
rw [add_comm, IsTwoSided.pow_add, Submodule.pow_one]
end IsTwoSided
@[simp]
theorem mul_eq_bot [NoZeroDivisors R] : I * J = ⊥ ↔ I = ⊥ ∨ J = ⊥ :=
⟨fun hij =>
or_iff_not_imp_left.mpr fun I_ne_bot =>
J.eq_bot_iff.mpr fun j hj =>
let ⟨i, hi, ne0⟩ := I.ne_bot_iff.mp I_ne_bot
Or.resolve_left (mul_eq_zero.mp ((I * J).eq_bot_iff.mp hij _ (mul_mem_mul hi hj))) ne0,
fun h => by obtain rfl | rfl := h; exacts [bot_mul _, mul_bot _]⟩
instance [NoZeroDivisors R] : NoZeroDivisors (Ideal R) where
eq_zero_or_eq_zero_of_mul_eq_zero := mul_eq_bot.1
instance {S A : Type*} [Semiring S] [SMul R S] [AddCommMonoid A] [Module R A] [Module S A]
[IsScalarTower R S A] [NoZeroSMulDivisors R A] {I : Submodule S A} : NoZeroSMulDivisors R I :=
Submodule.noZeroSMulDivisors (Submodule.restrictScalars R I)
theorem pow_eq_zero_of_mem {I : Ideal R} {n m : ℕ} (hnI : I ^ n = 0) (hmn : n ≤ m) {x : R}
(hx : x ∈ I) : x ^ m = 0 := by
simpa [hnI] using pow_le_pow_right hmn <| pow_mem_pow hx m
end Semiring
section MulAndRadical
variable {R : Type u} {ι : Type*} [CommSemiring R]
| variable {I J K L : Ideal R}
theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J :=
mul_comm r s ▸ mul_mem_mul hr hs
theorem prod_mem_prod {ι : Type*} {s : Finset ι} {I : ι → Ideal R} {x : ι → R} :
| Mathlib/RingTheory/Ideal/Operations.lean | 382 | 387 |
/-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sébastien Gouëzel, Yury Kudryashov, Yuyang Zhao
-/
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Comp
import Mathlib.Analysis.Calculus.FDeriv.RestrictScalars
/-!
# One-dimensional derivatives of compositions of functions
In this file we prove the chain rule for the following cases:
* `HasDerivAt.comp` etc: `f : 𝕜' → 𝕜'` composed with `g : 𝕜 → 𝕜'`;
* `HasDerivAt.scomp` etc: `f : 𝕜' → E` composed with `g : 𝕜 → 𝕜'`;
* `HasFDerivAt.comp_hasDerivAt` etc: `f : E → F` composed with `g : 𝕜 → E`;
Here `𝕜` is the base normed field, `E` and `F` are normed spaces over `𝕜` and `𝕜'` is an algebra
over `𝕜` (e.g., `𝕜'=𝕜` or `𝕜=ℝ`, `𝕜'=ℂ`).
We also give versions with the `of_eq` suffix, which require an equality proof instead
of definitional equality of the different points used in the composition. These versions are
often more flexible to use.
For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of
`analysis/calculus/deriv/basic`.
## Keywords
derivative, chain rule
-/
universe u v w
open scoped Topology Filter ENNReal
open Filter Asymptotics Set
open ContinuousLinearMap (smulRight smulRight_one_eq_iff)
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜]
variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {f : 𝕜 → F}
variable {f' : F}
variable {x : 𝕜}
variable {s : Set 𝕜}
variable {L : Filter 𝕜}
section Composition
/-!
### Derivative of the composition of a vector function and a scalar function
We use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp`
in lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also
because the `comp` version with the shorter name will show up much more often in applications).
The formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to
usual multiplication in `comp` lemmas.
-/
/- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to
get confused since there are too many possibilities for composition -/
variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F]
[IsScalarTower 𝕜 𝕜' F] {s' t' : Set 𝕜'} {h : 𝕜 → 𝕜'} {h₂ : 𝕜' → 𝕜'} {h' h₂' : 𝕜'}
{g₁ : 𝕜' → F} {g₁' : F} {L' : Filter 𝕜'} {y : 𝕜'} (x)
theorem HasDerivAtFilter.scomp (hg : HasDerivAtFilter g₁ g₁' (h x) L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') :
HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by
simpa using ((hg.restrictScalars 𝕜).comp x hh hL).hasDerivAtFilter
theorem HasDerivAtFilter.scomp_of_eq (hg : HasDerivAtFilter g₁ g₁' y L')
(hh : HasDerivAtFilter h h' x L) (hy : y = h x) (hL : Tendsto h L L') :
HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by
rw [hy] at hg; exact hg.scomp x hh hL
theorem HasDerivWithinAt.scomp_hasDerivAt (hg : HasDerivWithinAt g₁ g₁' s' (h x))
(hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') : HasDerivAt (g₁ ∘ h) (h' • g₁') x :=
hg.scomp x hh <| tendsto_inf.2 ⟨hh.continuousAt, tendsto_principal.2 <| Eventually.of_forall hs⟩
theorem HasDerivWithinAt.scomp_hasDerivAt_of_eq (hg : HasDerivWithinAt g₁ g₁' s' y)
(hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') (hy : y = h x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp_hasDerivAt x hh hs
nonrec theorem HasDerivWithinAt.scomp (hg : HasDerivWithinAt g₁ g₁' t' (h x))
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x :=
hg.scomp x hh <| hh.continuousWithinAt.tendsto_nhdsWithin hst
theorem HasDerivWithinAt.scomp_of_eq (hg : HasDerivWithinAt g₁ g₁' t' y)
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') (hy : y = h x) :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by
rw [hy] at hg; exact hg.scomp x hh hst
/-- The chain rule. -/
nonrec theorem HasDerivAt.scomp (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivAt h h' x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x :=
hg.scomp x hh hh.continuousAt
/-- The chain rule. -/
theorem HasDerivAt.scomp_of_eq
(hg : HasDerivAt g₁ g₁' y) (hh : HasDerivAt h h' x) (hy : y = h x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp x hh
theorem HasStrictDerivAt.scomp (hg : HasStrictDerivAt g₁ g₁' (h x)) (hh : HasStrictDerivAt h h' x) :
HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by
simpa using ((hg.restrictScalars 𝕜).comp x hh).hasStrictDerivAt
theorem HasStrictDerivAt.scomp_of_eq
(hg : HasStrictDerivAt g₁ g₁' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) :
HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp x hh
theorem HasDerivAt.scomp_hasDerivWithinAt (hg : HasDerivAt g₁ g₁' (h x))
(hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x :=
HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh (mapsTo_univ _ _)
theorem HasDerivAt.scomp_hasDerivWithinAt_of_eq (hg : HasDerivAt g₁ g₁' y)
(hh : HasDerivWithinAt h h' s x) (hy : y = h x) :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by
rw [hy] at hg; exact hg.scomp_hasDerivWithinAt x hh
theorem derivWithin.scomp (hg : DifferentiableWithinAt 𝕜' g₁ t' (h x))
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t') :
derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by
by_cases hsx : UniqueDiffWithinAt 𝕜 s x
· exact (HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh.hasDerivWithinAt hs).derivWithin hsx
· simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx]
theorem derivWithin.scomp_of_eq (hg : DifferentiableWithinAt 𝕜' g₁ t' y)
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t')
(hy : y = h x) :
derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by
rw [hy] at hg; exact derivWithin.scomp x hg hh hs
theorem deriv.scomp (hg : DifferentiableAt 𝕜' g₁ (h x)) (hh : DifferentiableAt 𝕜 h x) :
deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) :=
(HasDerivAt.scomp x hg.hasDerivAt hh.hasDerivAt).deriv
theorem deriv.scomp_of_eq
(hg : DifferentiableAt 𝕜' g₁ y) (hh : DifferentiableAt 𝕜 h x) (hy : y = h x) :
deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) := by
rw [hy] at hg; exact deriv.scomp x hg hh
/-! ### Derivative of the composition of a scalar and vector functions -/
theorem HasDerivAtFilter.comp_hasFDerivAtFilter {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E}
(hh₂ : HasDerivAtFilter h₂ h₂' (f x) L') (hf : HasFDerivAtFilter f f' x L'')
(hL : Tendsto f L'' L') : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by
convert (hh₂.restrictScalars 𝕜).comp x hf hL
ext x
simp [mul_comm]
theorem HasDerivAtFilter.comp_hasFDerivAtFilter_of_eq
{f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E}
(hh₂ : HasDerivAtFilter h₂ h₂' y L') (hf : HasFDerivAtFilter f f' x L'')
(hL : Tendsto f L'' L') (hy : y = f x) : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by
rw [hy] at hh₂; exact hh₂.comp_hasFDerivAtFilter x hf hL
theorem HasStrictDerivAt.comp_hasStrictFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasStrictDerivAt h₂ h₂' (f x)) (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [HasStrictDerivAt] at hh
convert (hh.restrictScalars 𝕜).comp x hf
ext x
simp [mul_comm]
theorem HasStrictDerivAt.comp_hasStrictFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasStrictDerivAt h₂ h₂' y) (hf : HasStrictFDerivAt f f' x) (hy : y = f x) :
HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [hy] at hh; exact hh.comp_hasStrictFDerivAt x hf
theorem HasDerivAt.comp_hasFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivAt f f' x) : HasFDerivAt (h₂ ∘ f) (h₂' • f') x :=
hh.comp_hasFDerivAtFilter x hf hf.continuousAt
theorem HasDerivAt.comp_hasFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivAt f f' x) (hy : y = f x) :
HasFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [hy] at hh; exact hh.comp_hasFDerivAt x hf
theorem HasDerivAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x)
(hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x :=
hh.comp_hasFDerivAtFilter x hf hf.continuousWithinAt
theorem HasDerivAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x)
(hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivWithinAt f f' s x) (hy : y = f x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by
rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf
theorem HasDerivWithinAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x)
(hh : HasDerivWithinAt h₂ h₂' t (f x)) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x :=
hh.comp_hasFDerivAtFilter x hf <| hf.continuousWithinAt.tendsto_nhdsWithin hst
theorem HasDerivWithinAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x)
(hh : HasDerivWithinAt h₂ h₂' t y) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t)
(hy : y = f x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by
rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf hst
/-! ### Derivative of the composition of two scalar functions -/
theorem HasDerivAtFilter.comp (hh₂ : HasDerivAtFilter h₂ h₂' (h x) L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') :
HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by
rw [mul_comm]
exact hh₂.scomp x hh hL
theorem HasDerivAtFilter.comp_of_eq (hh₂ : HasDerivAtFilter h₂ h₂' y L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') (hy : y = h x) :
HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by
rw [hy] at hh₂; exact hh₂.comp x hh hL
theorem HasDerivWithinAt.comp (hh₂ : HasDerivWithinAt h₂ h₂' s' (h x))
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') :
HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by
rw [mul_comm]
exact hh₂.scomp x hh hst
theorem HasDerivWithinAt.comp_of_eq (hh₂ : HasDerivWithinAt h₂ h₂' s' y)
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') (hy : y = h x) :
HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by
rw [hy] at hh₂; exact hh₂.comp x hh hst
/-- The chain rule.
Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule
with `h₂` taking values in a vector space, use `HasDerivAt.scomp`. -/
nonrec theorem HasDerivAt.comp (hh₂ : HasDerivAt h₂ h₂' (h x)) (hh : HasDerivAt h h' x) :
HasDerivAt (h₂ ∘ h) (h₂' * h') x :=
hh₂.comp x hh hh.continuousAt
/-- The chain rule.
Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule
with `h₂` taking values in a vector space, use `HasDerivAt.scomp_of_eq`. -/
theorem HasDerivAt.comp_of_eq
(hh₂ : HasDerivAt h₂ h₂' y) (hh : HasDerivAt h h' x) (hy : y = h x) :
HasDerivAt (h₂ ∘ h) (h₂' * h') x := by
rw [hy] at hh₂; exact hh₂.comp x hh
theorem HasStrictDerivAt.comp (hh₂ : HasStrictDerivAt h₂ h₂' (h x)) (hh : HasStrictDerivAt h h' x) :
HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by
rw [mul_comm]
exact hh₂.scomp x hh
theorem HasStrictDerivAt.comp_of_eq
(hh₂ : HasStrictDerivAt h₂ h₂' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) :
HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by
rw [hy] at hh₂; exact hh₂.comp x hh
theorem HasDerivAt.comp_hasDerivWithinAt (hh₂ : HasDerivAt h₂ h₂' (h x))
(hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x :=
| hh₂.hasDerivWithinAt.comp x hh (mapsTo_univ _ _)
theorem HasDerivAt.comp_hasDerivWithinAt_of_eq (hh₂ : HasDerivAt h₂ h₂' y)
(hh : HasDerivWithinAt h h' s x) (hy : y = h x) :
| Mathlib/Analysis/Calculus/Deriv/Comp.lean | 262 | 265 |
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Abelian.Exact
import Mathlib.CategoryTheory.Comma.Over.Basic
import Mathlib.Algebra.Category.ModuleCat.EpiMono
/-!
# Pseudoelements in abelian categories
A *pseudoelement* of an object `X` in an abelian category `C` is an equivalence class of arrows
ending in `X`, where two arrows are considered equivalent if we can find two epimorphisms with a
common domain making a commutative square with the two arrows. While the construction shows that
pseudoelements are actually subobjects of `X` rather than "elements", it is possible to chase these
pseudoelements through commutative diagrams in an abelian category to prove exactness properties.
This is done using some "diagram-chasing metatheorems" proved in this file. In many cases, a proof
in the category of abelian groups can more or less directly be converted into a proof using
pseudoelements.
A classic application of pseudoelements are diagram lemmas like the four lemma or the snake lemma.
Pseudoelements are in some ways weaker than actual elements in a concrete category. The most
important limitation is that there is no extensionality principle: If `f g : X ⟶ Y`, then
`∀ x ∈ X, f x = g x` does not necessarily imply that `f = g` (however, if `f = 0` or `g = 0`,
it does). A corollary of this is that we can not define arrows in abelian categories by dictating
their action on pseudoelements. Thus, a usual style of proofs in abelian categories is this:
First, we construct some morphism using universal properties, and then we use diagram chasing
of pseudoelements to verify that is has some desirable property such as exactness.
It should be noted that the Freyd-Mitchell embedding theorem
(see `CategoryTheory.Abelian.FreydMitchell`) gives a vastly stronger notion of
pseudoelement (in particular one that gives extensionality) and this file should be updated to
go use that instead!
## Main results
We define the type of pseudoelements of an object and, in particular, the zero pseudoelement.
We prove that every morphism maps the zero pseudoelement to the zero pseudoelement (`apply_zero`)
and that a zero morphism maps every pseudoelement to the zero pseudoelement (`zero_apply`).
Here are the metatheorems we provide:
* A morphism `f` is zero if and only if it is the zero function on pseudoelements.
* A morphism `f` is an epimorphism if and only if it is surjective on pseudoelements.
* A morphism `f` is a monomorphism if and only if it is injective on pseudoelements
if and only if `∀ a, f a = 0 → f = 0`.
* A sequence `f, g` of morphisms is exact if and only if
`∀ a, g (f a) = 0` and `∀ b, g b = 0 → ∃ a, f a = b`.
* If `f` is a morphism and `a, a'` are such that `f a = f a'`, then there is some
pseudoelement `a''` such that `f a'' = 0` and for every `g` we have
`g a' = 0 → g a = g a''`. We can think of `a''` as `a - a'`, but don't get too carried away
by that: pseudoelements of an object do not form an abelian group.
## Notations
We introduce coercions from an object of an abelian category to the set of its pseudoelements
and from a morphism to the function it induces on pseudoelements.
These coercions must be explicitly enabled via local instances:
`attribute [local instance] objectToSort homToFun`
## Implementation notes
It appears that sometimes the coercion from morphisms to functions does not work, i.e.,
writing `g a` raises a "function expected" error. This error can be fixed by writing
`(g : X ⟶ Y) a`.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
open CategoryTheory
open CategoryTheory.Limits
open CategoryTheory.Abelian
open CategoryTheory.Preadditive
universe v u
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C]
attribute [local instance] Over.coeFromHom
/-- This is just composition of morphisms in `C`. Another way to express this would be
`(Over.map f).obj a`, but our definition has nicer definitional properties. -/
def app {P Q : C} (f : P ⟶ Q) (a : Over P) : Over Q :=
a.hom ≫ f
@[simp]
theorem app_hom {P Q : C} (f : P ⟶ Q) (a : Over P) : (app f a).hom = a.hom ≫ f := rfl
/-- Two arrows `f : X ⟶ P` and `g : Y ⟶ P` are called pseudo-equal if there is some object
`R` and epimorphisms `p : R ⟶ X` and `q : R ⟶ Y` such that `p ≫ f = q ≫ g`. -/
def PseudoEqual (P : C) (f g : Over P) : Prop :=
∃ (R : C) (p : R ⟶ f.1) (q : R ⟶ g.1) (_ : Epi p) (_ : Epi q), p ≫ f.hom = q ≫ g.hom
theorem pseudoEqual_refl {P : C} : Reflexive (PseudoEqual P) :=
fun f => ⟨f.1, 𝟙 f.1, 𝟙 f.1, inferInstance, inferInstance, by simp⟩
theorem pseudoEqual_symm {P : C} : Symmetric (PseudoEqual P) :=
fun _ _ ⟨R, p, q, ep, Eq, comm⟩ => ⟨R, q, p, Eq, ep, comm.symm⟩
variable [Abelian.{v} C]
section
/-- Pseudoequality is transitive: Just take the pullback. The pullback morphisms will
be epimorphisms since in an abelian category, pullbacks of epimorphisms are epimorphisms. -/
theorem pseudoEqual_trans {P : C} : Transitive (PseudoEqual P) := by
intro f g h ⟨R, p, q, ep, Eq, comm⟩ ⟨R', p', q', ep', eq', comm'⟩
refine ⟨pullback q p', pullback.fst _ _ ≫ p, pullback.snd _ _ ≫ q',
epi_comp _ _, epi_comp _ _, ?_⟩
rw [Category.assoc, comm, ← Category.assoc, pullback.condition, Category.assoc, comm',
Category.assoc]
end
/-- The arrows with codomain `P` equipped with the equivalence relation of being pseudo-equal. -/
def Pseudoelement.setoid (P : C) : Setoid (Over P) :=
⟨_, ⟨pseudoEqual_refl, @pseudoEqual_symm _ _ _, @pseudoEqual_trans _ _ _ _⟩⟩
attribute [local instance] Pseudoelement.setoid
/-- A `Pseudoelement` of `P` is just an equivalence class of arrows ending in `P` by being
pseudo-equal. -/
def Pseudoelement (P : C) : Type max u v :=
Quotient (Pseudoelement.setoid P)
namespace Pseudoelement
/-- A coercion from an object of an abelian category to its pseudoelements. -/
def objectToSort : CoeSort C (Type max u v) :=
⟨fun P => Pseudoelement P⟩
attribute [local instance] objectToSort
scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.objectToSort
/-- A coercion from an arrow with codomain `P` to its associated pseudoelement. -/
def overToSort {P : C} : Coe (Over P) (Pseudoelement P) :=
⟨Quot.mk (PseudoEqual P)⟩
attribute [local instance] overToSort
theorem over_coe_def {P Q : C} (a : Q ⟶ P) : (a : Pseudoelement P) = ⟦↑a⟧ := rfl
/-- If two elements are pseudo-equal, then their composition with a morphism is, too. -/
theorem pseudoApply_aux {P Q : C} (f : P ⟶ Q) (a b : Over P) : a ≈ b → app f a ≈ app f b :=
fun ⟨R, p, q, ep, Eq, comm⟩ =>
⟨R, p, q, ep, Eq, show p ≫ a.hom ≫ f = q ≫ b.hom ≫ f by rw [reassoc_of% comm]⟩
/-- A morphism `f` induces a function `pseudoApply f` on pseudoelements. -/
def pseudoApply {P Q : C} (f : P ⟶ Q) : P → Q :=
Quotient.map (fun g : Over P => app f g) (pseudoApply_aux f)
/-- A coercion from morphisms to functions on pseudoelements. -/
def homToFun {P Q : C} : CoeFun (P ⟶ Q) fun _ => P → Q :=
⟨pseudoApply⟩
attribute [local instance] homToFun
scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.homToFun
theorem pseudoApply_mk' {P Q : C} (f : P ⟶ Q) (a : Over P) : f ⟦a⟧ = ⟦↑(a.hom ≫ f)⟧ := rfl
/-- Applying a pseudoelement to a composition of morphisms is the same as composing
with each morphism. Sadly, this is not a definitional equality, but at least it is
true. -/
theorem comp_apply {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) (a : P) : (f ≫ g) a = g (f a) :=
Quotient.inductionOn a fun x =>
Quotient.sound <| by
simp only [app]
rw [← Category.assoc, Over.coe_hom]
/-- Composition of functions on pseudoelements is composition of morphisms. -/
theorem comp_comp {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) : g ∘ f = f ≫ g :=
funext fun _ => (comp_apply _ _ _).symm
section Zero
/-!
In this section we prove that for every `P` there is an equivalence class that contains
precisely all the zero morphisms ending in `P` and use this to define *the* zero
pseudoelement.
-/
section
attribute [local instance] HasBinaryBiproducts.of_hasBinaryProducts
/-- The arrows pseudo-equal to a zero morphism are precisely the zero morphisms. -/
theorem pseudoZero_aux {P : C} (Q : C) (f : Over P) : f ≈ (0 : Q ⟶ P) ↔ f.hom = 0 :=
⟨fun ⟨R, p, q, _, _, comm⟩ => zero_of_epi_comp p (by simp [comm]), fun hf =>
⟨biprod f.1 Q, biprod.fst, biprod.snd, inferInstance, inferInstance, by
rw [hf, Over.coe_hom, HasZeroMorphisms.comp_zero, HasZeroMorphisms.comp_zero]⟩⟩
end
theorem zero_eq_zero' {P Q R : C} :
(⟦((0 : Q ⟶ P) : Over P)⟧ : Pseudoelement P) = ⟦((0 : R ⟶ P) : Over P)⟧ :=
Quotient.sound <| (pseudoZero_aux R _).2 rfl
/-- The zero pseudoelement is the class of a zero morphism. -/
def pseudoZero {P : C} : P :=
⟦(0 : P ⟶ P)⟧
-- Porting note: in mathlib3, we couldn't make this an instance
-- as it would have fired on `coe_sort`.
-- However now that coercions are treated differently, this is a structural instance triggered by
-- the appearance of `Pseudoelement`.
instance hasZero {P : C} : Zero P :=
⟨pseudoZero⟩
instance {P : C} : Inhabited P :=
⟨0⟩
theorem pseudoZero_def {P : C} : (0 : Pseudoelement P) = ⟦↑(0 : P ⟶ P)⟧ := rfl
@[simp]
theorem zero_eq_zero {P Q : C} : ⟦((0 : Q ⟶ P) : Over P)⟧ = (0 : Pseudoelement P) :=
zero_eq_zero'
/-- The pseudoelement induced by an arrow is zero precisely when that arrow is zero. -/
theorem pseudoZero_iff {P : C} (a : Over P) : a = (0 : P) ↔ a.hom = 0 := by
rw [← pseudoZero_aux P a]
exact Quotient.eq'
end Zero
open Pseudoelement
/-- Morphisms map the zero pseudoelement to the zero pseudoelement. -/
@[simp]
theorem apply_zero {P Q : C} (f : P ⟶ Q) : f 0 = 0 := by
rw [pseudoZero_def, pseudoApply_mk']
simp
/-- The zero morphism maps every pseudoelement to 0. -/
@[simp]
theorem zero_apply {P : C} (Q : C) (a : P) : (0 : P ⟶ Q) a = 0 :=
Quotient.inductionOn a fun a' => by
rw [pseudoZero_def, pseudoApply_mk']
simp
/-- An extensionality lemma for being the zero arrow. -/
theorem zero_morphism_ext {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0) → f = 0 := fun h => by
rw [← Category.id_comp f]
exact (pseudoZero_iff (𝟙 P ≫ f : Over Q)).1 (h (𝟙 P))
theorem zero_morphism_ext' {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0) → 0 = f :=
Eq.symm ∘ zero_morphism_ext f
theorem eq_zero_iff {P Q : C} (f : P ⟶ Q) : f = 0 ↔ ∀ a, f a = 0 :=
⟨fun h a => by simp [h], zero_morphism_ext _⟩
/-- A monomorphism is injective on pseudoelements. -/
theorem pseudo_injective_of_mono {P Q : C} (f : P ⟶ Q) [Mono f] : Function.Injective f := by
intro abar abar'
refine Quotient.inductionOn₂ abar abar' fun a a' ha => ?_
apply Quotient.sound
have : (⟦(a.hom ≫ f : Over Q)⟧ : Quotient (setoid Q)) = ⟦↑(a'.hom ≫ f)⟧ := by convert ha
have ⟨R, p, q, ep, Eq, comm⟩ := Quotient.exact this
exact ⟨R, p, q, ep, Eq, (cancel_mono f).1 <| by
simp only [Category.assoc]
exact comm⟩
|
/-- A morphism that is injective on pseudoelements only maps the zero element to zero. -/
theorem zero_of_map_zero {P Q : C} (f : P ⟶ Q) : Function.Injective f → ∀ a, f a = 0 → a = 0 :=
fun h a ha => by
| Mathlib/CategoryTheory/Abelian/Pseudoelements.lean | 275 | 278 |
/-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.NoZeroSMulDivisors.Basic
import Mathlib.Algebra.Order.GroupWithZero.Action.Synonym
import Mathlib.Tactic.GCongr
import Mathlib.Tactic.Positivity.Core
/-!
# Monotonicity of scalar multiplication by positive elements
This file defines typeclasses to reason about monotonicity of the operations
* `b ↦ a • b`, "left scalar multiplication"
* `a ↦ a • b`, "right scalar multiplication"
We use eight typeclasses to encode the various properties we care about for those two operations.
These typeclasses are meant to be mostly internal to this file, to set up each lemma in the
appropriate generality.
Less granular typeclasses like `OrderedAddCommMonoid`, `LinearOrderedField`, `OrderedSMul` should be
enough for most purposes, and the system is set up so that they imply the correct granular
typeclasses here. If those are enough for you, you may stop reading here! Else, beware that what
follows is a bit technical.
## Definitions
In all that follows, `α` and `β` are orders which have a `0` and such that `α` acts on `β` by scalar
multiplication. Note however that we do not use lawfulness of this action in most of the file. Hence
`•` should be considered here as a mostly arbitrary function `α → β → β`.
We use the following four typeclasses to reason about left scalar multiplication (`b ↦ a • b`):
* `PosSMulMono`: If `a ≥ 0`, then `b₁ ≤ b₂` implies `a • b₁ ≤ a • b₂`.
* `PosSMulStrictMono`: If `a > 0`, then `b₁ < b₂` implies `a • b₁ < a • b₂`.
* `PosSMulReflectLT`: If `a ≥ 0`, then `a • b₁ < a • b₂` implies `b₁ < b₂`.
* `PosSMulReflectLE`: If `a > 0`, then `a • b₁ ≤ a • b₂` implies `b₁ ≤ b₂`.
We use the following four typeclasses to reason about right scalar multiplication (`a ↦ a • b`):
* `SMulPosMono`: If `b ≥ 0`, then `a₁ ≤ a₂` implies `a₁ • b ≤ a₂ • b`.
* `SMulPosStrictMono`: If `b > 0`, then `a₁ < a₂` implies `a₁ • b < a₂ • b`.
* `SMulPosReflectLT`: If `b ≥ 0`, then `a₁ • b < a₂ • b` implies `a₁ < a₂`.
* `SMulPosReflectLE`: If `b > 0`, then `a₁ • b ≤ a₂ • b` implies `a₁ ≤ a₂`.
## Constructors
The four typeclasses about nonnegativity can usually be checked only on positive inputs due to their
condition becoming trivial when `a = 0` or `b = 0`. We therefore make the following constructors
available: `PosSMulMono.of_pos`, `PosSMulReflectLT.of_pos`, `SMulPosMono.of_pos`,
`SMulPosReflectLT.of_pos`
## Implications
As `α` and `β` get more and more structure, those typeclasses end up being equivalent. The commonly
used implications are:
* When `α`, `β` are partial orders:
* `PosSMulStrictMono → PosSMulMono`
* `SMulPosStrictMono → SMulPosMono`
* `PosSMulReflectLE → PosSMulReflectLT`
* `SMulPosReflectLE → SMulPosReflectLT`
* When `β` is a linear order:
* `PosSMulStrictMono → PosSMulReflectLE`
* `PosSMulReflectLT → PosSMulMono` (not registered as instance)
* `SMulPosReflectLT → SMulPosMono` (not registered as instance)
* `PosSMulReflectLE → PosSMulStrictMono` (not registered as instance)
* `SMulPosReflectLE → SMulPosStrictMono` (not registered as instance)
* When `α` is a linear order:
* `SMulPosStrictMono → SMulPosReflectLE`
* When `α` is an ordered ring, `β` an ordered group and also an `α`-module:
* `PosSMulMono → SMulPosMono`
* `PosSMulStrictMono → SMulPosStrictMono`
* When `α` is an linear ordered semifield, `β` is an `α`-module:
* `PosSMulStrictMono → PosSMulReflectLT`
* `PosSMulMono → PosSMulReflectLE`
* When `α` is a semiring, `β` is an `α`-module with `NoZeroSMulDivisors`:
* `PosSMulMono → PosSMulStrictMono` (not registered as instance)
* When `α` is a ring, `β` is an `α`-module with `NoZeroSMulDivisors`:
* `SMulPosMono → SMulPosStrictMono` (not registered as instance)
Further, the bundled non-granular typeclasses imply the granular ones like so:
* `OrderedSMul → PosSMulStrictMono`
* `OrderedSMul → PosSMulReflectLT`
Unless otherwise stated, all these implications are registered as instances,
which means that in practice you should not worry about these implications.
However, if you encounter a case where you think a statement is true but
not covered by the current implications, please bring it up on Zulip!
## Implementation notes
This file uses custom typeclasses instead of abbreviations of `CovariantClass`/`ContravariantClass`
because:
* They get displayed as classes in the docs. In particular, one can see their list of instances,
instead of their instances being invariably dumped to the `CovariantClass`/`ContravariantClass`
list.
* They don't pollute other typeclass searches. Having many abbreviations of the same typeclass for
different purposes always felt like a performance issue (more instances with the same key, for no
added benefit), and indeed making the classes here abbreviation previous creates timeouts due to
the higher number of `CovariantClass`/`ContravariantClass` instances.
* `SMulPosReflectLT`/`SMulPosReflectLE` do not fit in the framework since they relate `≤` on two
different types. So we would have to generalise `CovariantClass`/`ContravariantClass` to three
types and two relations.
* Very minor, but the constructors let you work with `a : α`, `h : 0 ≤ a` instead of
`a : {a : α // 0 ≤ a}`. This actually makes some instances surprisingly cleaner to prove.
* The `CovariantClass`/`ContravariantClass` framework is only useful to automate very simple logic
anyway. It is easily copied over.
In the future, it would be good to make the corresponding typeclasses in
`Mathlib.Algebra.Order.GroupWithZero.Unbundled` custom typeclasses too.
## TODO
This file acts as a substitute for `Mathlib.Algebra.Order.SMul`. We now need to
* finish the transition by deleting the duplicate lemmas
* rearrange the non-duplicate lemmas into new files
* generalise (most of) the lemmas from `Mathlib.Algebra.Order.Module` to here
* rethink `OrderedSMul`
-/
open OrderDual
variable (α β : Type*)
section Defs
variable [SMul α β] [Preorder α] [Preorder β]
section Left
variable [Zero α]
/-- Typeclass for monotonicity of scalar multiplication by nonnegative elements on the left,
namely `b₁ ≤ b₂ → a • b₁ ≤ a • b₂` if `0 ≤ a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulMono : Prop where
/-- Do not use this. Use `smul_le_smul_of_nonneg_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 ≤ a) ⦃b₁ b₂ : β⦄ (hb : b₁ ≤ b₂) : a • b₁ ≤ a • b₂
/-- Typeclass for strict monotonicity of scalar multiplication by positive elements on the left,
namely `b₁ < b₂ → a • b₁ < a • b₂` if `0 < a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulStrictMono : Prop where
/-- Do not use this. Use `smul_lt_smul_of_pos_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 < a) ⦃b₁ b₂ : β⦄ (hb : b₁ < b₂) : a • b₁ < a • b₂
/-- Typeclass for strict reverse monotonicity of scalar multiplication by nonnegative elements on
the left, namely `a • b₁ < a • b₂ → b₁ < b₂` if `0 ≤ a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulReflectLT : Prop where
/-- Do not use this. Use `lt_of_smul_lt_smul_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 ≤ a) ⦃b₁ b₂ : β⦄ (hb : a • b₁ < a • b₂) : b₁ < b₂
/-- Typeclass for reverse monotonicity of scalar multiplication by positive elements on the left,
namely `a • b₁ ≤ a • b₂ → b₁ ≤ b₂` if `0 < a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulReflectLE : Prop where
/-- Do not use this. Use `le_of_smul_lt_smul_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 < a) ⦃b₁ b₂ : β⦄ (hb : a • b₁ ≤ a • b₂) : b₁ ≤ b₂
end Left
section Right
variable [Zero β]
/-- Typeclass for monotonicity of scalar multiplication by nonnegative elements on the left,
namely `a₁ ≤ a₂ → a₁ • b ≤ a₂ • b` if `0 ≤ b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosMono : Prop where
/-- Do not use this. Use `smul_le_smul_of_nonneg_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 ≤ b) ⦃a₁ a₂ : α⦄ (ha : a₁ ≤ a₂) : a₁ • b ≤ a₂ • b
/-- Typeclass for strict monotonicity of scalar multiplication by positive elements on the left,
namely `a₁ < a₂ → a₁ • b < a₂ • b` if `0 < b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosStrictMono : Prop where
/-- Do not use this. Use `smul_lt_smul_of_pos_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 < b) ⦃a₁ a₂ : α⦄ (ha : a₁ < a₂) : a₁ • b < a₂ • b
/-- Typeclass for strict reverse monotonicity of scalar multiplication by nonnegative elements on
the left, namely `a₁ • b < a₂ • b → a₁ < a₂` if `0 ≤ b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosReflectLT : Prop where
/-- Do not use this. Use `lt_of_smul_lt_smul_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 ≤ b) ⦃a₁ a₂ : α⦄ (hb : a₁ • b < a₂ • b) : a₁ < a₂
/-- Typeclass for reverse monotonicity of scalar multiplication by positive elements on the left,
namely `a₁ • b ≤ a₂ • b → a₁ ≤ a₂` if `0 < b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosReflectLE : Prop where
/-- Do not use this. Use `le_of_smul_lt_smul_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 < b) ⦃a₁ a₂ : α⦄ (hb : a₁ • b ≤ a₂ • b) : a₁ ≤ a₂
end Right
end Defs
variable {α β} {a a₁ a₂ : α} {b b₁ b₂ : β}
section Mul
variable [Zero α] [Mul α] [Preorder α]
-- See note [lower instance priority]
instance (priority := 100) PosMulMono.toPosSMulMono [PosMulMono α] : PosSMulMono α α where
elim _a ha _b₁ _b₂ hb := mul_le_mul_of_nonneg_left hb ha
-- See note [lower instance priority]
instance (priority := 100) PosMulStrictMono.toPosSMulStrictMono [PosMulStrictMono α] :
PosSMulStrictMono α α where
elim _a ha _b₁ _b₂ hb := mul_lt_mul_of_pos_left hb ha
-- See note [lower instance priority]
instance (priority := 100) PosMulReflectLT.toPosSMulReflectLT [PosMulReflectLT α] :
PosSMulReflectLT α α where
elim _a ha _b₁ _b₂ h := lt_of_mul_lt_mul_left h ha
-- See note [lower instance priority]
instance (priority := 100) PosMulReflectLE.toPosSMulReflectLE [PosMulReflectLE α] :
PosSMulReflectLE α α where
elim _a ha _b₁ _b₂ h := le_of_mul_le_mul_left h ha
-- See note [lower instance priority]
instance (priority := 100) MulPosMono.toSMulPosMono [MulPosMono α] : SMulPosMono α α where
elim _b hb _a₁ _a₂ ha := mul_le_mul_of_nonneg_right ha hb
-- See note [lower instance priority]
instance (priority := 100) MulPosStrictMono.toSMulPosStrictMono [MulPosStrictMono α] :
SMulPosStrictMono α α where
elim _b hb _a₁ _a₂ ha := mul_lt_mul_of_pos_right ha hb
-- See note [lower instance priority]
instance (priority := 100) MulPosReflectLT.toSMulPosReflectLT [MulPosReflectLT α] :
SMulPosReflectLT α α where
elim _b hb _a₁ _a₂ h := lt_of_mul_lt_mul_right h hb
-- See note [lower instance priority]
instance (priority := 100) MulPosReflectLE.toSMulPosReflectLE [MulPosReflectLE α] :
SMulPosReflectLE α α where
elim _b hb _a₁ _a₂ h := le_of_mul_le_mul_right h hb
end Mul
section SMul
variable [SMul α β]
section Preorder
variable [Preorder α] [Preorder β]
section Left
variable [Zero α]
lemma monotone_smul_left_of_nonneg [PosSMulMono α β] (ha : 0 ≤ a) : Monotone ((a • ·) : β → β) :=
PosSMulMono.elim ha
lemma strictMono_smul_left_of_pos [PosSMulStrictMono α β] (ha : 0 < a) :
StrictMono ((a • ·) : β → β) := PosSMulStrictMono.elim ha
@[gcongr] lemma smul_le_smul_of_nonneg_left [PosSMulMono α β] (hb : b₁ ≤ b₂) (ha : 0 ≤ a) :
a • b₁ ≤ a • b₂ := monotone_smul_left_of_nonneg ha hb
@[gcongr] lemma smul_lt_smul_of_pos_left [PosSMulStrictMono α β] (hb : b₁ < b₂) (ha : 0 < a) :
a • b₁ < a • b₂ := strictMono_smul_left_of_pos ha hb
lemma lt_of_smul_lt_smul_left [PosSMulReflectLT α β] (h : a • b₁ < a • b₂) (ha : 0 ≤ a) : b₁ < b₂ :=
PosSMulReflectLT.elim ha h
lemma le_of_smul_le_smul_left [PosSMulReflectLE α β] (h : a • b₁ ≤ a • b₂) (ha : 0 < a) : b₁ ≤ b₂ :=
PosSMulReflectLE.elim ha h
alias lt_of_smul_lt_smul_of_nonneg_left := lt_of_smul_lt_smul_left
alias le_of_smul_le_smul_of_pos_left := le_of_smul_le_smul_left
@[simp]
lemma smul_le_smul_iff_of_pos_left [PosSMulMono α β] [PosSMulReflectLE α β] (ha : 0 < a) :
a • b₁ ≤ a • b₂ ↔ b₁ ≤ b₂ :=
⟨fun h ↦ le_of_smul_le_smul_left h ha, fun h ↦ smul_le_smul_of_nonneg_left h ha.le⟩
@[simp]
lemma smul_lt_smul_iff_of_pos_left [PosSMulStrictMono α β] [PosSMulReflectLT α β] (ha : 0 < a) :
a • b₁ < a • b₂ ↔ b₁ < b₂ :=
⟨fun h ↦ lt_of_smul_lt_smul_left h ha.le, fun hb ↦ smul_lt_smul_of_pos_left hb ha⟩
end Left
section Right
variable [Zero β]
lemma monotone_smul_right_of_nonneg [SMulPosMono α β] (hb : 0 ≤ b) : Monotone ((· • b) : α → β) :=
SMulPosMono.elim hb
lemma strictMono_smul_right_of_pos [SMulPosStrictMono α β] (hb : 0 < b) :
StrictMono ((· • b) : α → β) := SMulPosStrictMono.elim hb
@[gcongr] lemma smul_le_smul_of_nonneg_right [SMulPosMono α β] (ha : a₁ ≤ a₂) (hb : 0 ≤ b) :
a₁ • b ≤ a₂ • b := monotone_smul_right_of_nonneg hb ha
@[gcongr] lemma smul_lt_smul_of_pos_right [SMulPosStrictMono α β] (ha : a₁ < a₂) (hb : 0 < b) :
a₁ • b < a₂ • b := strictMono_smul_right_of_pos hb ha
lemma lt_of_smul_lt_smul_right [SMulPosReflectLT α β] (h : a₁ • b < a₂ • b) (hb : 0 ≤ b) :
a₁ < a₂ := SMulPosReflectLT.elim hb h
lemma le_of_smul_le_smul_right [SMulPosReflectLE α β] (h : a₁ • b ≤ a₂ • b) (hb : 0 < b) :
a₁ ≤ a₂ := SMulPosReflectLE.elim hb h
alias lt_of_smul_lt_smul_of_nonneg_right := lt_of_smul_lt_smul_right
alias le_of_smul_le_smul_of_pos_right := le_of_smul_le_smul_right
@[simp]
lemma smul_le_smul_iff_of_pos_right [SMulPosMono α β] [SMulPosReflectLE α β] (hb : 0 < b) :
a₁ • b ≤ a₂ • b ↔ a₁ ≤ a₂ :=
⟨fun h ↦ le_of_smul_le_smul_right h hb, fun ha ↦ smul_le_smul_of_nonneg_right ha hb.le⟩
@[simp]
lemma smul_lt_smul_iff_of_pos_right [SMulPosStrictMono α β] [SMulPosReflectLT α β] (hb : 0 < b) :
a₁ • b < a₂ • b ↔ a₁ < a₂ :=
⟨fun h ↦ lt_of_smul_lt_smul_right h hb.le, fun ha ↦ smul_lt_smul_of_pos_right ha hb⟩
end Right
section LeftRight
variable [Zero α] [Zero β]
lemma smul_lt_smul_of_le_of_lt [PosSMulStrictMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂)
(hb : b₁ < b₂) (h₁ : 0 < a₁) (h₂ : 0 ≤ b₂) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_left hb h₁).trans_le (smul_le_smul_of_nonneg_right ha h₂)
lemma smul_lt_smul_of_le_of_lt' [PosSMulStrictMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂)
(hb : b₁ < b₂) (h₂ : 0 < a₂) (h₁ : 0 ≤ b₁) : a₁ • b₁ < a₂ • b₂ :=
(smul_le_smul_of_nonneg_right ha h₁).trans_lt (smul_lt_smul_of_pos_left hb h₂)
lemma smul_lt_smul_of_lt_of_le [PosSMulMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂)
(hb : b₁ ≤ b₂) (h₁ : 0 ≤ a₁) (h₂ : 0 < b₂) : a₁ • b₁ < a₂ • b₂ :=
(smul_le_smul_of_nonneg_left hb h₁).trans_lt (smul_lt_smul_of_pos_right ha h₂)
lemma smul_lt_smul_of_lt_of_le' [PosSMulMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂)
(hb : b₁ ≤ b₂) (h₂ : 0 ≤ a₂) (h₁ : 0 < b₁) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_right ha h₁).trans_le (smul_le_smul_of_nonneg_left hb h₂)
lemma smul_lt_smul [PosSMulStrictMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂) (hb : b₁ < b₂)
(h₁ : 0 < a₁) (h₂ : 0 < b₂) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_left hb h₁).trans (smul_lt_smul_of_pos_right ha h₂)
lemma smul_lt_smul' [PosSMulStrictMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂) (hb : b₁ < b₂)
(h₂ : 0 < a₂) (h₁ : 0 < b₁) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_right ha h₁).trans (smul_lt_smul_of_pos_left hb h₂)
lemma smul_le_smul [PosSMulMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂)
(h₁ : 0 ≤ a₁) (h₂ : 0 ≤ b₂) : a₁ • b₁ ≤ a₂ • b₂ :=
(smul_le_smul_of_nonneg_left hb h₁).trans (smul_le_smul_of_nonneg_right ha h₂)
lemma smul_le_smul' [PosSMulMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) (h₂ : 0 ≤ a₂)
(h₁ : 0 ≤ b₁) : a₁ • b₁ ≤ a₂ • b₂ :=
(smul_le_smul_of_nonneg_right ha h₁).trans (smul_le_smul_of_nonneg_left hb h₂)
end LeftRight
end Preorder
section LinearOrder
variable [Preorder α] [LinearOrder β]
section Left
variable [Zero α]
-- See note [lower instance priority]
instance (priority := 100) PosSMulStrictMono.toPosSMulReflectLE [PosSMulStrictMono α β] :
PosSMulReflectLE α β where
elim _a ha _b₁ _b₂ := (strictMono_smul_left_of_pos ha).le_iff_le.1
lemma PosSMulReflectLE.toPosSMulStrictMono [PosSMulReflectLE α β] : PosSMulStrictMono α β where
elim _a ha _b₁ _b₂ hb := not_le.1 fun h ↦ hb.not_le <| le_of_smul_le_smul_left h ha
lemma posSMulStrictMono_iff_PosSMulReflectLE : PosSMulStrictMono α β ↔ PosSMulReflectLE α β :=
⟨fun _ ↦ inferInstance, fun _ ↦ PosSMulReflectLE.toPosSMulStrictMono⟩
instance PosSMulMono.toPosSMulReflectLT [PosSMulMono α β] : PosSMulReflectLT α β where
elim _a ha _b₁ _b₂ := (monotone_smul_left_of_nonneg ha).reflect_lt
lemma PosSMulReflectLT.toPosSMulMono [PosSMulReflectLT α β] : PosSMulMono α β where
elim _a ha _b₁ _b₂ hb := not_lt.1 fun h ↦ hb.not_lt <| lt_of_smul_lt_smul_left h ha
lemma posSMulMono_iff_posSMulReflectLT : PosSMulMono α β ↔ PosSMulReflectLT α β :=
⟨fun _ ↦ PosSMulMono.toPosSMulReflectLT, fun _ ↦ PosSMulReflectLT.toPosSMulMono⟩
lemma smul_max_of_nonneg [PosSMulMono α β] (ha : 0 ≤ a) (b₁ b₂ : β) :
a • max b₁ b₂ = max (a • b₁) (a • b₂) := (monotone_smul_left_of_nonneg ha).map_max
lemma smul_min_of_nonneg [PosSMulMono α β] (ha : 0 ≤ a) (b₁ b₂ : β) :
a • min b₁ b₂ = min (a • b₁) (a • b₂) := (monotone_smul_left_of_nonneg ha).map_min
end Left
section Right
variable [Zero β]
lemma SMulPosReflectLE.toSMulPosStrictMono [SMulPosReflectLE α β] : SMulPosStrictMono α β where
elim _b hb _a₁ _a₂ ha := not_le.1 fun h ↦ ha.not_le <| le_of_smul_le_smul_of_pos_right h hb
lemma SMulPosReflectLT.toSMulPosMono [SMulPosReflectLT α β] : SMulPosMono α β where
elim _b hb _a₁ _a₂ ha := not_lt.1 fun h ↦ ha.not_lt <| lt_of_smul_lt_smul_right h hb
end Right
end LinearOrder
section LinearOrder
variable [LinearOrder α] [Preorder β]
section Right
variable [Zero β]
-- See note [lower instance priority]
instance (priority := 100) SMulPosStrictMono.toSMulPosReflectLE [SMulPosStrictMono α β] :
SMulPosReflectLE α β where
elim _b hb _a₁ _a₂ h := not_lt.1 fun ha ↦ h.not_lt <| smul_lt_smul_of_pos_right ha hb
lemma SMulPosMono.toSMulPosReflectLT [SMulPosMono α β] : SMulPosReflectLT α β where
elim _b hb _a₁ _a₂ h := not_le.1 fun ha ↦ h.not_le <| smul_le_smul_of_nonneg_right ha hb
end Right
end LinearOrder
section LinearOrder
variable [LinearOrder α] [LinearOrder β]
section Right
variable [Zero β]
lemma smulPosStrictMono_iff_SMulPosReflectLE : SMulPosStrictMono α β ↔ SMulPosReflectLE α β :=
⟨fun _ ↦ SMulPosStrictMono.toSMulPosReflectLE, fun _ ↦ SMulPosReflectLE.toSMulPosStrictMono⟩
lemma smulPosMono_iff_smulPosReflectLT : SMulPosMono α β ↔ SMulPosReflectLT α β :=
⟨fun _ ↦ SMulPosMono.toSMulPosReflectLT, fun _ ↦ SMulPosReflectLT.toSMulPosMono⟩
end Right
end LinearOrder
end SMul
section SMulZeroClass
variable [Zero α] [Zero β] [SMulZeroClass α β]
section Preorder
variable [Preorder α] [Preorder β]
lemma smul_pos [PosSMulStrictMono α β] (ha : 0 < a) (hb : 0 < b) : 0 < a • b := by
simpa only [smul_zero] using smul_lt_smul_of_pos_left hb ha
lemma smul_neg_of_pos_of_neg [PosSMulStrictMono α β] (ha : 0 < a) (hb : b < 0) : a • b < 0 := by
simpa only [smul_zero] using smul_lt_smul_of_pos_left hb ha
@[simp]
lemma smul_pos_iff_of_pos_left [PosSMulStrictMono α β] [PosSMulReflectLT α β] (ha : 0 < a) :
0 < a • b ↔ 0 < b := by
simpa only [smul_zero] using smul_lt_smul_iff_of_pos_left ha (b₁ := 0) (b₂ := b)
lemma smul_neg_iff_of_pos_left [PosSMulStrictMono α β] [PosSMulReflectLT α β] (ha : 0 < a) :
a • b < 0 ↔ b < 0 := by
simpa only [smul_zero] using smul_lt_smul_iff_of_pos_left ha (b₂ := (0 : β))
lemma smul_nonneg [PosSMulMono α β] (ha : 0 ≤ a) (hb : 0 ≤ b₁) : 0 ≤ a • b₁ := by
simpa only [smul_zero] using smul_le_smul_of_nonneg_left hb ha
lemma smul_nonpos_of_nonneg_of_nonpos [PosSMulMono α β] (ha : 0 ≤ a) (hb : b ≤ 0) : a • b ≤ 0 := by
simpa only [smul_zero] using smul_le_smul_of_nonneg_left hb ha
lemma pos_of_smul_pos_left [PosSMulReflectLT α β] (h : 0 < a • b) (ha : 0 ≤ a) : 0 < b :=
lt_of_smul_lt_smul_left (by rwa [smul_zero]) ha
lemma neg_of_smul_neg_left [PosSMulReflectLT α β] (h : a • b < 0) (ha : 0 ≤ a) : b < 0 :=
lt_of_smul_lt_smul_left (by rwa [smul_zero]) ha
end Preorder
end SMulZeroClass
|
section SMulWithZero
| Mathlib/Algebra/Order/Module/Defs.lean | 485 | 486 |
/-
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.Algebra.CharP.Basic
import Mathlib.Algebra.CharP.Lemmas
import Mathlib.Data.Fintype.Units
import Mathlib.GroupTheory.OrderOfElement
/-!
# Multiplicative characters of finite rings and fields
Let `R` and `R'` be a commutative rings.
A *multiplicative character* of `R` with values in `R'` is a morphism of
monoids from the multiplicative monoid of `R` into that of `R'`
that sends non-units to zero.
We use the namespace `MulChar` for the definitions and results.
## Main results
We show that the multiplicative characters form a group (if `R'` is commutative);
see `MulChar.commGroup`. We also provide an equivalence with the
homomorphisms `Rˣ →* R'ˣ`; see `MulChar.equivToUnitHom`.
We define a multiplicative character to be *quadratic* if its values
are among `0`, `1` and `-1`, and we prove some properties of quadratic characters.
Finally, we show that the sum of all values of a nontrivial multiplicative
character vanishes; see `MulChar.IsNontrivial.sum_eq_zero`.
## Tags
multiplicative character
-/
/-!
### Definitions related to multiplicative characters
Even though the intended use is when domain and target of the characters
are commutative rings, we define them in the more general setting when
the domain is a commutative monoid and the target is a commutative monoid
with zero. (We need a zero in the target, since non-units are supposed
to map to zero.)
In this setting, there is an equivalence between multiplicative characters
`R → R'` and group homomorphisms `Rˣ → R'ˣ`, and the multiplicative characters
have a natural structure as a commutative group.
-/
section Defi
-- The domain of our multiplicative characters
variable (R : Type*) [CommMonoid R]
-- The target
variable (R' : Type*) [CommMonoidWithZero R']
/-- Define a structure for multiplicative characters.
A multiplicative character from a commutative monoid `R` to a commutative monoid with zero `R'`
is a homomorphism of (multiplicative) monoids that sends non-units to zero. -/
structure MulChar extends MonoidHom R R' where
map_nonunit' : ∀ a : R, ¬IsUnit a → toFun a = 0
instance MulChar.instFunLike : FunLike (MulChar R R') R R' :=
⟨fun χ => χ.toFun,
fun χ₀ χ₁ h => by cases χ₀; cases χ₁; congr; apply MonoidHom.ext (fun _ => congr_fun h _)⟩
/-- This is the corresponding extension of `MonoidHomClass`. -/
class MulCharClass (F : Type*) (R R' : outParam Type*) [CommMonoid R]
[CommMonoidWithZero R'] [FunLike F R R'] : Prop extends MonoidHomClass F R R' where
map_nonunit : ∀ (χ : F) {a : R} (_ : ¬IsUnit a), χ a = 0
initialize_simps_projections MulChar (toFun → apply, -toMonoidHom)
end Defi
namespace MulChar
attribute [scoped simp] MulCharClass.map_nonunit
section Group
-- The domain of our multiplicative characters
variable {R : Type*} [CommMonoid R]
-- The target
variable {R' : Type*} [CommMonoidWithZero R']
variable (R R') in
/-- The trivial multiplicative character. It takes the value `0` on non-units and
the value `1` on units. -/
@[simps]
noncomputable def trivial : MulChar R R' where
toFun := by classical exact fun x => if IsUnit x then 1 else 0
map_nonunit' := by
intro a ha
simp only [ha, if_false]
map_one' := by simp only [isUnit_one, if_true]
map_mul' := by
intro x y
classical
simp only [IsUnit.mul_iff, boole_mul]
split_ifs <;> tauto
@[simp]
theorem coe_mk (f : R →* R') (hf) : (MulChar.mk f hf : R → R') = f :=
rfl
/-- Extensionality. See `ext` below for the version that will actually be used. -/
theorem ext' {χ χ' : MulChar R R'} (h : ∀ a, χ a = χ' a) : χ = χ' := by
cases χ
cases χ'
congr
exact MonoidHom.ext h
instance : MulCharClass (MulChar R R') R R' where
map_mul χ := χ.map_mul'
map_one χ := χ.map_one'
map_nonunit χ := χ.map_nonunit' _
theorem map_nonunit (χ : MulChar R R') {a : R} (ha : ¬IsUnit a) : χ a = 0 :=
χ.map_nonunit' a ha
/-- Extensionality. Since `MulChar`s always take the value zero on non-units, it is sufficient
to compare the values on units. -/
@[ext]
theorem ext {χ χ' : MulChar R R'} (h : ∀ a : Rˣ, χ a = χ' a) : χ = χ' := by
apply ext'
intro a
by_cases ha : IsUnit a
· exact h ha.unit
· rw [map_nonunit χ ha, map_nonunit χ' ha]
/-!
### Equivalence of multiplicative characters with homomorphisms on units
We show that restriction / extension by zero gives an equivalence
between `MulChar R R'` and `Rˣ →* R'ˣ`.
-/
/-- Turn a `MulChar` into a homomorphism between the unit groups. -/
def toUnitHom (χ : MulChar R R') : Rˣ →* R'ˣ :=
Units.map χ
theorem coe_toUnitHom (χ : MulChar R R') (a : Rˣ) : ↑(χ.toUnitHom a) = χ a :=
rfl
/-- Turn a homomorphism between unit groups into a `MulChar`. -/
noncomputable def ofUnitHom (f : Rˣ →* R'ˣ) : MulChar R R' where
toFun := by classical exact fun x => if hx : IsUnit x then f hx.unit else 0
map_one' := by
have h1 : (isUnit_one.unit : Rˣ) = 1 := Units.eq_iff.mp rfl
simp only [h1, dif_pos, Units.val_eq_one, map_one, isUnit_one]
map_mul' := by
classical
intro x y
by_cases hx : IsUnit x
· simp only [hx, IsUnit.mul_iff, true_and, dif_pos]
by_cases hy : IsUnit y
· simp only [hy, dif_pos]
have hm : (IsUnit.mul_iff.mpr ⟨hx, hy⟩).unit = hx.unit * hy.unit := Units.eq_iff.mp rfl
rw [hm, map_mul]
norm_cast
· simp only [hy, not_false_iff, dif_neg, mul_zero]
· simp only [hx, IsUnit.mul_iff, false_and, not_false_iff, dif_neg, zero_mul]
map_nonunit' := by
intro a ha
simp only [ha, not_false_iff, dif_neg]
theorem ofUnitHom_coe (f : Rˣ →* R'ˣ) (a : Rˣ) : ofUnitHom f ↑a = f a := by simp [ofUnitHom]
/-- The equivalence between multiplicative characters and homomorphisms of unit groups. -/
noncomputable def equivToUnitHom : MulChar R R' ≃ (Rˣ →* R'ˣ) where
toFun := toUnitHom
invFun := ofUnitHom
left_inv := by
intro χ
ext x
rw [ofUnitHom_coe, coe_toUnitHom]
right_inv := by
intro f
ext x
simp only [coe_toUnitHom, ofUnitHom_coe]
@[simp]
theorem toUnitHom_eq (χ : MulChar R R') : toUnitHom χ = equivToUnitHom χ :=
| rfl
| Mathlib/NumberTheory/MulChar/Basic.lean | 192 | 192 |
/-
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, Sabbir Rahman
-/
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Algebra.Order.Ring.Pow
import Mathlib.Algebra.Ring.CharZero
import Mathlib.Tactic.Positivity.Core
/-!
# Lemmas about powers in ordered fields.
-/
variable {α : Type*}
open Function Int
section LinearOrderedField
variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] {a b : α} {n : ℤ}
protected theorem Even.zpow_nonneg (hn : Even n) (a : α) : 0 ≤ a ^ n := by
obtain ⟨k, rfl⟩ := hn; rw [zpow_add' (by simp [em'])]; exact mul_self_nonneg _
lemma zpow_two_nonneg (a : α) : 0 ≤ a ^ (2 : ℤ) := even_two.zpow_nonneg _
lemma zpow_neg_two_nonneg (a : α) : 0 ≤ a ^ (-2 : ℤ) := even_neg_two.zpow_nonneg _
protected lemma Even.zpow_pos (hn : Even n) (ha : a ≠ 0) : 0 < a ^ n :=
(hn.zpow_nonneg _).lt_of_ne' (zpow_ne_zero _ ha)
lemma zpow_two_pos_of_ne_zero (ha : a ≠ 0) : 0 < a ^ (2 : ℤ) := even_two.zpow_pos ha
theorem Even.zpow_pos_iff (hn : Even n) (h : n ≠ 0) : 0 < a ^ n ↔ a ≠ 0 := by
obtain ⟨k, rfl⟩ := hn
rw [zpow_add' (by simp [em']), mul_self_pos, zpow_ne_zero_iff (by simpa using h)]
theorem Odd.zpow_neg_iff (hn : Odd n) : a ^ n < 0 ↔ a < 0 := by
refine ⟨lt_imp_lt_of_le_imp_le (zpow_nonneg · _), fun ha ↦ ?_⟩
obtain ⟨k, rfl⟩ := hn
rw [zpow_add_one₀ ha.ne]
exact mul_neg_of_pos_of_neg (Even.zpow_pos (even_two_mul _) ha.ne) ha
protected lemma Odd.zpow_nonneg_iff (hn : Odd n) : 0 ≤ a ^ n ↔ 0 ≤ a :=
le_iff_le_iff_lt_iff_lt.2 hn.zpow_neg_iff
|
theorem Odd.zpow_nonpos_iff (hn : Odd n) : a ^ n ≤ 0 ↔ a ≤ 0 := by
rw [le_iff_lt_or_eq, le_iff_lt_or_eq, hn.zpow_neg_iff, zpow_eq_zero_iff]
| Mathlib/Algebra/Order/Field/Power.lean | 48 | 50 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Jeremy Avigad, Simon Hudon
-/
import Batteries.WF
import Mathlib.Data.Part
import Mathlib.Data.Rel
import Mathlib.Tactic.GeneralizeProofs
/-!
# Partial functions
This file defines partial functions. Partial functions are like functions, except they can also be
"undefined" on some inputs. We define them as functions `α → Part β`.
## Definitions
* `PFun α β`: Type of partial functions from `α` to `β`. Defined as `α → Part β` and denoted
`α →. β`.
* `PFun.Dom`: Domain of a partial function. Set of values on which it is defined. Not to be confused
with the domain of a function `α → β`, which is a type (`α` presently).
* `PFun.fn`: Evaluation of a partial function. Takes in an element and a proof it belongs to the
partial function's `Dom`.
* `PFun.asSubtype`: Returns a partial function as a function from its `Dom`.
* `PFun.toSubtype`: Restricts the codomain of a function to a subtype.
* `PFun.evalOpt`: Returns a partial function with a decidable `Dom` as a function `a → Option β`.
* `PFun.lift`: Turns a function into a partial function.
* `PFun.id`: The identity as a partial function.
* `PFun.comp`: Composition of partial functions.
* `PFun.restrict`: Restriction of a partial function to a smaller `Dom`.
* `PFun.res`: Turns a function into a partial function with a prescribed domain.
* `PFun.fix` : First return map of a partial function `f : α →. β ⊕ α`.
* `PFun.fix_induction`: A recursion principle for `PFun.fix`.
### Partial functions as relations
Partial functions can be considered as relations, so we specialize some `Rel` definitions to `PFun`:
* `PFun.image`: Image of a set under a partial function.
* `PFun.ran`: Range of a partial function.
* `PFun.preimage`: Preimage of a set under a partial function.
* `PFun.core`: Core of a set under a partial function.
* `PFun.graph`: Graph of a partial function `a →. β`as a `Set (α × β)`.
* `PFun.graph'`: Graph of a partial function `a →. β`as a `Rel α β`.
### `PFun α` as a monad
Monad operations:
* `PFun.pure`: The monad `pure` function, the constant `x` function.
* `PFun.bind`: The monad `bind` function, pointwise `Part.bind`
* `PFun.map`: The monad `map` function, pointwise `Part.map`.
-/
-- Pending rename in core.
alias WellFounded.fixF_eq := WellFounded.fixFEq
open Function
/-- `PFun α β`, or `α →. β`, is the type of partial functions from
`α` to `β`. It is defined as `α → Part β`. -/
def PFun (α β : Type*) :=
α → Part β
/-- `α →. β` is notation for the type `PFun α β` of partial functions from `α` to `β`. -/
infixr:25 " →. " => PFun
namespace PFun
variable {α β γ δ ε ι : Type*}
instance inhabited : Inhabited (α →. β) :=
⟨fun _ => Part.none⟩
/-- The domain of a partial function -/
def Dom (f : α →. β) : Set α :=
{ a | (f a).Dom }
@[simp]
theorem mem_dom (f : α →. β) (x : α) : x ∈ Dom f ↔ ∃ y, y ∈ f x := by simp [Dom, Part.dom_iff_mem]
@[simp]
theorem dom_mk (p : α → Prop) (f : ∀ a, p a → β) : (PFun.Dom fun x => ⟨p x, f x⟩) = { x | p x } :=
rfl
theorem dom_eq (f : α →. β) : Dom f = { x | ∃ y, y ∈ f x } :=
Set.ext (mem_dom f)
/-- Evaluate a partial function -/
def fn (f : α →. β) (a : α) : Dom f a → β :=
(f a).get
@[simp]
theorem fn_apply (f : α →. β) (a : α) : f.fn a = (f a).get :=
rfl
/-- Evaluate a partial function to return an `Option` -/
def evalOpt (f : α →. β) [D : DecidablePred (· ∈ Dom f)] (x : α) : Option β :=
@Part.toOption _ _ (D x)
/-- Partial function extensionality -/
theorem ext' {f g : α →. β} (H1 : ∀ a, a ∈ Dom f ↔ a ∈ Dom g) (H2 : ∀ a p q, f.fn a p = g.fn a q) :
f = g :=
funext fun a => Part.ext' (H1 a) (H2 a)
@[ext]
theorem ext {f g : α →. β} (H : ∀ a b, b ∈ f a ↔ b ∈ g a) : f = g :=
funext fun a => Part.ext (H a)
/-- Turns a partial function into a function out of its domain. -/
def asSubtype (f : α →. β) (s : f.Dom) : β :=
f.fn s s.2
/-- The type of partial functions `α →. β` is equivalent to
the type of pairs `(p : α → Prop, f : Subtype p → β)`. -/
def equivSubtype : (α →. β) ≃ Σp : α → Prop, Subtype p → β :=
⟨fun f => ⟨fun a => (f a).Dom, asSubtype f⟩, fun f x => ⟨f.1 x, fun h => f.2 ⟨x, h⟩⟩, fun _ =>
funext fun _ => Part.eta _, fun ⟨p, f⟩ => by dsimp; congr⟩
theorem asSubtype_eq_of_mem {f : α →. β} {x : α} {y : β} (fxy : y ∈ f x) (domx : x ∈ f.Dom) :
f.asSubtype ⟨x, domx⟩ = y :=
Part.mem_unique (Part.get_mem _) fxy
/-- Turn a total function into a partial function. -/
@[coe]
protected def lift (f : α → β) : α →. β := fun a => Part.some (f a)
instance coe : Coe (α → β) (α →. β) :=
⟨PFun.lift⟩
@[simp]
theorem coe_val (f : α → β) (a : α) : (f : α →. β) a = Part.some (f a) :=
rfl
@[simp]
theorem dom_coe (f : α → β) : (f : α →. β).Dom = Set.univ :=
rfl
theorem lift_injective : Injective (PFun.lift : (α → β) → α →. β) := fun _ _ h =>
funext fun a => Part.some_injective <| congr_fun h a
/-- Graph of a partial function `f` as the set of pairs `(x, f x)` where `x` is in the domain of
`f`. -/
def graph (f : α →. β) : Set (α × β) :=
{ p | p.2 ∈ f p.1 }
/-- Graph of a partial function as a relation. `x` and `y` are related iff `f x` is defined and
"equals" `y`. -/
def graph' (f : α →. β) : Rel α β := fun x y => y ∈ f x
/-- The range of a partial function is the set of values
`f x` where `x` is in the domain of `f`. -/
def ran (f : α →. β) : Set β :=
{ b | ∃ a, b ∈ f a }
/-- Restrict a partial function to a smaller domain. -/
def restrict (f : α →. β) {p : Set α} (H : p ⊆ f.Dom) : α →. β := fun x =>
(f x).restrict (x ∈ p) (@H x)
@[simp]
theorem mem_restrict {f : α →. β} {s : Set α} (h : s ⊆ f.Dom) (a : α) (b : β) :
b ∈ f.restrict h a ↔ a ∈ s ∧ b ∈ f a := by simp [restrict]
/-- Turns a function into a partial function with a prescribed domain. -/
def res (f : α → β) (s : Set α) : α →. β :=
(PFun.lift f).restrict s.subset_univ
theorem mem_res (f : α → β) (s : Set α) (a : α) (b : β) : b ∈ res f s a ↔ a ∈ s ∧ f a = b := by
simp [res, @eq_comm _ b]
theorem res_univ (f : α → β) : PFun.res f Set.univ = f :=
rfl
theorem dom_iff_graph (f : α →. β) (x : α) : x ∈ f.Dom ↔ ∃ y, (x, y) ∈ f.graph :=
Part.dom_iff_mem
theorem lift_graph {f : α → β} {a b} : (a, b) ∈ (f : α →. β).graph ↔ f a = b :=
show (∃ _ : True, f a = b) ↔ f a = b by simp
/-- The monad `pure` function, the total constant `x` function -/
protected def pure (x : β) : α →. β := fun _ => Part.some x
/-- The monad `bind` function, pointwise `Part.bind` -/
def bind (f : α →. β) (g : β → α →. γ) : α →. γ := fun a => (f a).bind fun b => g b a
@[simp]
theorem bind_apply (f : α →. β) (g : β → α →. γ) (a : α) : f.bind g a = (f a).bind fun b => g b a :=
rfl
/-- The monad `map` function, pointwise `Part.map` -/
def map (f : β → γ) (g : α →. β) : α →. γ := fun a => (g a).map f
instance monad : Monad (PFun α) where
pure := PFun.pure
bind := PFun.bind
map := PFun.map
instance lawfulMonad : LawfulMonad (PFun α) := LawfulMonad.mk'
(bind_pure_comp := fun _ _ => funext fun _ => Part.bind_some_eq_map _ _)
(id_map := fun f => by funext a; dsimp [Functor.map, PFun.map]; cases f a; rfl)
(pure_bind := fun x f => funext fun _ => Part.bind_some _ (f x))
(bind_assoc := fun f g k => funext fun a => (f a).bind_assoc (fun b => g b a) fun b => k b a)
theorem pure_defined (p : Set α) (x : β) : p ⊆ (@PFun.pure α _ x).Dom :=
p.subset_univ
theorem bind_defined {α β γ} (p : Set α) {f : α →. β} {g : β → α →. γ} (H1 : p ⊆ f.Dom)
(H2 : ∀ x, p ⊆ (g x).Dom) : p ⊆ (f >>= g).Dom := fun a ha =>
(⟨H1 ha, H2 _ ha⟩ : (f >>= g).Dom a)
/-- First return map. Transforms a partial function `f : α →. β ⊕ α` into the partial function
`α →. β` which sends `a : α` to the first value in `β` it hits by iterating `f`, if such a value
exists. By abusing notation to illustrate, either `f a` is in the `β` part of `β ⊕ α` (in which
case `f.fix a` returns `f a`), or it is undefined (in which case `f.fix a` is undefined as well), or
it is in the `α` part of `β ⊕ α` (in which case we repeat the procedure, so `f.fix a` will return
`f.fix (f a)`). -/
def fix (f : α →. β ⊕ α) : α →. β := fun a =>
Part.assert (Acc (fun x y => Sum.inr x ∈ f y) a) fun h =>
WellFounded.fixF
(fun a IH =>
Part.assert (f a).Dom fun hf =>
match e : (f a).get hf with
| Sum.inl b => Part.some b
| Sum.inr a' => IH a' ⟨hf, e⟩)
a h
theorem dom_of_mem_fix {f : α →. β ⊕ α} {a : α} {b : β} (h : b ∈ f.fix a) : (f a).Dom := by
let ⟨h₁, h₂⟩ := Part.mem_assert_iff.1 h
rw [WellFounded.fixF_eq] at h₂; exact h₂.fst.fst
theorem mem_fix_iff {f : α →. β ⊕ α} {a : α} {b : β} :
b ∈ f.fix a ↔ Sum.inl b ∈ f a ∨ ∃ a', Sum.inr a' ∈ f a ∧ b ∈ f.fix a' :=
⟨fun h => by
let ⟨h₁, h₂⟩ := Part.mem_assert_iff.1 h
rw [WellFounded.fixF_eq] at h₂
simp only [Part.mem_assert_iff] at h₂
obtain ⟨h₂, h₃⟩ := h₂
split at h₃
next e => simp only [Part.mem_some_iff] at h₃; subst b; exact Or.inl ⟨h₂, e⟩
next e => exact Or.inr ⟨_, ⟨_, e⟩, Part.mem_assert _ h₃⟩,
fun h => by
simp only [fix, Part.mem_assert_iff]
rcases h with (⟨h₁, h₂⟩ | ⟨a', h, h₃⟩)
· refine ⟨⟨_, fun y h' => ?_⟩, ?_⟩
· injection Part.mem_unique ⟨h₁, h₂⟩ h'
· rw [WellFounded.fixF_eq]
-- Porting note: used to be simp [h₁, h₂]
apply Part.mem_assert h₁
split
next e =>
injection h₂.symm.trans e with h; simp [h]
next e =>
injection h₂.symm.trans e
· simp only [fix, Part.mem_assert_iff] at h₃
obtain ⟨h₃, h₄⟩ := h₃
refine ⟨⟨_, fun y h' => ?_⟩, ?_⟩
· injection Part.mem_unique h h' with e
exact e ▸ h₃
· obtain ⟨h₁, h₂⟩ := h
rw [WellFounded.fixF_eq]
-- Porting note: used to be simp [h₁, h₂, h₄]
| apply Part.mem_assert h₁
split
next e =>
| Mathlib/Data/PFun.lean | 261 | 263 |
/-
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, Johan Commelin
-/
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.RingDivision
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.SetTheory.Cardinal.Order
/-!
# Theory of univariate polynomials
We define the multiset of roots of a polynomial, and prove basic results about it.
## Main definitions
* `Polynomial.roots p`: The multiset containing all the roots of `p`, including their
multiplicities.
* `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`.
## Main statements
* `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its
degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a`
ranges through its roots.
-/
assert_not_exists Ideal
open Multiset Finset
noncomputable section
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R] [IsDomain R] {p q : R[X]}
section Roots
/-- `roots p` noncomputably gives a multiset containing all the roots of `p`,
including their multiplicities. -/
noncomputable def roots (p : R[X]) : Multiset R :=
haveI := Classical.decEq R
haveI := Classical.dec (p = 0)
if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h)
theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] :
p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by
rename_i iR ip0
obtain rfl := Subsingleton.elim iR (Classical.decEq R)
obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0))
rfl
@[simp]
theorem roots_zero : (0 : R[X]).roots = 0 :=
dif_pos rfl
theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by
classical
unfold roots
rw [dif_neg hp0]
exact (Classical.choose_spec (exists_multiset_roots hp0)).1
theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by
by_cases hp0 : p = 0
· simp [hp0]
exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0))
theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) :
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p :=
calc
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) :=
card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le
_ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0
theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) :
Multiset.card (p - C a).roots ≤ natDegree p :=
WithBot.coe_le_coe.1
(le_trans (card_roots_sub_C hp0)
(le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl]))
@[simp]
theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by
classical
by_cases hp : p = 0
· simp [hp]
rw [roots_def, dif_neg hp]
exact (Classical.choose_spec (exists_multiset_roots hp)).2 a
@[simp]
theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by
classical
rw [← count_pos, count_roots p, rootMultiplicity_pos']
theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a :=
mem_roots'.trans <| and_iff_right hp
theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 :=
(mem_roots'.1 h).1
theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a :=
(mem_roots'.1 h).2
theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S →+* R}
(hf : Function.Injective f) {x : R} (hp : p ≠ 0) : x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by
rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map]
lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by
rw [aeval_def, ← mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w,
Algebra.id.map_eq_id, map_id]
theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) :
#Z ≤ p.natDegree :=
(Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p)
theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by
classical
simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp]
using p.roots.toFinset.finite_toSet
theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 :=
not_imp_comm.mp finite_setOf_isRoot h
theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x ≤ x₀ :=
Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp
theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x₀ ≤ x :=
Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp
theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) :
p = q := by
rw [← sub_eq_zero]
apply eq_zero_of_infinite_isRoot
simpa only [IsRoot, eval_sub, sub_eq_zero]
theorem roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots := by
classical
exact Multiset.ext.mpr fun r => by
rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq]
theorem roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q := by
rintro ⟨k, rfl⟩
exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩
theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p ≠ C a ∧ p.eval x = a := by
rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C]
theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) :
x ∈ (p - C a).roots ↔ p.eval x = a :=
mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm ▸ degree_C_le
@[simp]
theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by
classical
ext s
rw [count_roots, rootMultiplicity_X_sub_C, count_singleton]
@[simp]
theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r)
@[simp]
theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero]
@[simp]
theorem roots_C (x : R) : (C x).roots = 0 := by
classical exact
if H : x = 0 then by rw [H, C_0, roots_zero]
else
Multiset.ext.mpr fun r => (by
rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)])
@[simp]
theorem roots_one : (1 : R[X]).roots = ∅ :=
roots_C 1
@[simp]
theorem roots_C_mul (p : R[X]) (ha : a ≠ 0) : (C a * p).roots = p.roots := by
by_cases hp : p = 0 <;>
simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C,
zero_add, mul_zero]
@[simp]
theorem roots_smul_nonzero (p : R[X]) (ha : a ≠ 0) : (a • p).roots = p.roots := by
rw [smul_eq_C_mul, roots_C_mul _ ha]
@[simp]
lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by
rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)]
@[simp]
theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X - C b).roots =
{a⁻¹ * b} := by
rw [← roots_C_mul _ (Units.ne_zero a⁻¹), mul_sub, ← mul_assoc, ← C_mul, ← C_mul,
Units.inv_mul, C_1, one_mul]
exact roots_X_sub_C (a⁻¹ * b)
@[simp]
theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X + C b).roots =
{-(a⁻¹ * b)} := by
rw [← sub_neg_eq_add, ← C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg]
theorem roots_list_prod (L : List R[X]) :
(0 : R[X]) ∉ L → L.prod.roots = (L : Multiset R[X]).bind roots :=
List.recOn L (fun _ => roots_one) fun hd tl ih H => by
rw [List.mem_cons, not_or] at H
rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ←
Multiset.cons_coe, Multiset.cons_bind, ih H.2]
theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) ∉ m → m.prod.roots = m.bind roots := by
rcases m with ⟨L⟩
simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L
theorem roots_prod {ι : Type*} (f : ι → R[X]) (s : Finset ι) :
s.prod f ≠ 0 → (s.prod f).roots = s.val.bind fun i => roots (f i) := by
rcases s with ⟨m, hm⟩
simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f)
@[simp]
theorem roots_pow (p : R[X]) (n : ℕ) : (p ^ n).roots = n • p.roots := by
induction n with
| zero => rw [pow_zero, roots_one, zero_smul, empty_eq_zero]
| succ n ihn =>
rcases eq_or_ne p 0 with (rfl | hp)
· rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero]
· rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul]
theorem roots_X_pow (n : ℕ) : (X ^ n : R[X]).roots = n • ({0} : Multiset R) := by
rw [roots_pow, roots_X]
theorem roots_C_mul_X_pow (ha : a ≠ 0) (n : ℕ) :
Polynomial.roots (C a * X ^ n) = n • ({0} : Multiset R) := by
rw [roots_C_mul _ ha, roots_X_pow]
@[simp]
theorem roots_monomial (ha : a ≠ 0) (n : ℕ) : (monomial n a).roots = n • ({0} : Multiset R) := by
rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha]
theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by
apply (roots_prod (fun a => X - C a) s ?_).trans
· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
· refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a)
@[simp]
theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by
rw [roots_multiset_prod, Multiset.bind_map]
· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
· rw [Multiset.mem_map]
rintro ⟨a, -, h⟩
exact X_sub_C_ne_zero a h
theorem card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :
Multiset.card (roots ((X : R[X]) ^ n - C a)) ≤ n :=
WithBot.coe_le_coe.1 <|
calc
(Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot ℕ) ≤ degree ((X : R[X]) ^ n - C a) :=
card_roots (X_pow_sub_C_ne_zero hn a)
_ = n := degree_X_pow_sub_C hn a
section NthRoots
|
/-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`. -/
def nthRoots (n : ℕ) (a : R) : Multiset R :=
roots ((X : R[X]) ^ n - C a)
| Mathlib/Algebra/Polynomial/Roots.lean | 272 | 276 |
/-
Copyright (c) 2022 Dylan MacKenzie. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dylan MacKenzie
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Algebra.Module.Defs
import Mathlib.Tactic.Abel
/-!
# Summation by parts
-/
namespace Finset
variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] (f : ℕ → R) (g : ℕ → M) {m n : ℕ}
-- The partial sum of `g`, starting from zero
local notation "G " n:80 => ∑ i ∈ range n, g i
/-- **Summation by parts**, also known as **Abel's lemma** or an **Abel transformation** -/
| theorem sum_Ico_by_parts (hmn : m < n) :
∑ i ∈ Ico m n, f i • g i =
f (n - 1) • G n - f m • G m - ∑ i ∈ Ico m (n - 1), (f (i + 1) - f i) • G (i + 1) := by
have h₁ : (∑ i ∈ Ico (m + 1) n, f i • G i) = ∑ i ∈ Ico m (n - 1), f (i + 1) • G (i + 1) := by
rw [← Nat.sub_add_cancel (Nat.one_le_of_lt hmn), ← sum_Ico_add']
simp only [tsub_le_iff_right, add_le_iff_nonpos_left, nonpos_iff_eq_zero,
tsub_eq_zero_iff_le, add_tsub_cancel_right]
have h₂ :
(∑ i ∈ Ico (m + 1) n, f i • G (i + 1)) =
(∑ i ∈ Ico m (n - 1), f i • G (i + 1)) + f (n - 1) • G n - f m • G (m + 1) := by
rw [← sum_Ico_sub_bot _ hmn, ← sum_Ico_succ_sub_top _ (Nat.le_sub_one_of_lt hmn),
Nat.sub_add_cancel (pos_of_gt hmn), sub_add_cancel]
rw [sum_eq_sum_Ico_succ_bot hmn]
conv in (occs := 3) (f _ • g _) => rw [← sum_range_succ_sub_sum g]
simp_rw [smul_sub, sum_sub_distrib, h₂, h₁]
conv_lhs => congr; rfl; rw [← add_sub, add_comm, ← add_sub, ← sum_sub_distrib]
have : ∀ i, f i • G (i + 1) - f (i + 1) • G (i + 1) = -((f (i + 1) - f i) • G (i + 1)) := by
intro i
rw [sub_smul]
abel
simp_rw [this, sum_neg_distrib, sum_range_succ, smul_add]
abel
theorem sum_Ioc_by_parts (hmn : m < n) :
∑ i ∈ Ioc m n, f i • g i =
f n • G (n + 1) - f (m + 1) • G (m + 1)
- ∑ i ∈ Ioc m (n - 1), (f (i + 1) - f i) • G (i + 1) := by
simpa only [← Nat.Ico_succ_succ, Nat.succ_eq_add_one, Nat.sub_add_cancel (Nat.one_le_of_lt hmn),
add_tsub_cancel_right] using sum_Ico_by_parts f g (Nat.succ_lt_succ hmn)
variable (n)
/-- **Summation by parts** for ranges -/
theorem sum_range_by_parts :
∑ i ∈ range n, f i • g i =
f (n - 1) • G n - ∑ i ∈ range (n - 1), (f (i + 1) - f i) • G (i + 1) := by
by_cases hn : n = 0
| Mathlib/Algebra/BigOperators/Module.lean | 21 | 57 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Data.ENNReal.Real
/-!
# Properties of addition, multiplication and subtraction on extended non-negative real numbers
In this file we prove elementary properties of algebraic operations on `ℝ≥0∞`, including addition,
multiplication, natural powers and truncated subtraction, as well as how these interact with the
order structure on `ℝ≥0∞`. Notably excluded from this list are inversion and division, the
definitions and properties of which can be found in `Mathlib.Data.ENNReal.Inv`.
Note: the definitions of the operations included in this file can be found in
`Mathlib.Data.ENNReal.Basic`.
-/
assert_not_exists Finset
open Set NNReal ENNReal
namespace ENNReal
variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
section Mul
@[mono, gcongr]
theorem mul_lt_mul (ac : a < c) (bd : b < d) : a * b < c * d := WithTop.mul_lt_mul ac bd
protected lemma pow_right_strictMono {n : ℕ} (hn : n ≠ 0) : StrictMono fun a : ℝ≥0∞ ↦ a ^ n :=
WithTop.pow_right_strictMono hn
@[gcongr] protected lemma pow_lt_pow_left (hab : a < b) {n : ℕ} (hn : n ≠ 0) : a ^ n < b ^ n :=
WithTop.pow_lt_pow_left hab hn
-- TODO: generalize to `WithTop`
theorem mul_left_strictMono (h0 : a ≠ 0) (hinf : a ≠ ∞) : StrictMono (a * ·) := by
lift a to ℝ≥0 using hinf
rw [coe_ne_zero] at h0
intro x y h
contrapose! h
simpa only [← mul_assoc, ← coe_mul, inv_mul_cancel₀ h0, coe_one, one_mul]
using mul_le_mul_left' h (↑a⁻¹)
@[gcongr] protected theorem mul_lt_mul_left' (h0 : a ≠ 0) (hinf : a ≠ ⊤) (bc : b < c) :
a * b < a * c :=
ENNReal.mul_left_strictMono h0 hinf bc
@[gcongr] protected theorem mul_lt_mul_right' (h0 : a ≠ 0) (hinf : a ≠ ⊤) (bc : b < c) :
b * a < c * a :=
mul_comm b a ▸ mul_comm c a ▸ ENNReal.mul_left_strictMono h0 hinf bc
-- TODO: generalize to `WithTop`
protected theorem mul_right_inj (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b = a * c ↔ b = c :=
(mul_left_strictMono h0 hinf).injective.eq_iff
@[deprecated (since := "2025-01-20")]
alias mul_eq_mul_left := ENNReal.mul_right_inj
-- TODO: generalize to `WithTop`
protected theorem mul_left_inj (h0 : c ≠ 0) (hinf : c ≠ ∞) : a * c = b * c ↔ a = b :=
mul_comm c a ▸ mul_comm c b ▸ ENNReal.mul_right_inj h0 hinf
@[deprecated (since := "2025-01-20")]
alias mul_eq_mul_right := ENNReal.mul_left_inj
-- TODO: generalize to `WithTop`
theorem mul_le_mul_left (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b ≤ a * c ↔ b ≤ c :=
(mul_left_strictMono h0 hinf).le_iff_le
-- TODO: generalize to `WithTop`
theorem mul_le_mul_right : c ≠ 0 → c ≠ ∞ → (a * c ≤ b * c ↔ a ≤ b) :=
mul_comm c a ▸ mul_comm c b ▸ mul_le_mul_left
-- TODO: generalize to `WithTop`
theorem mul_lt_mul_left (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b < a * c ↔ b < c :=
(mul_left_strictMono h0 hinf).lt_iff_lt
-- TODO: generalize to `WithTop`
theorem mul_lt_mul_right : c ≠ 0 → c ≠ ∞ → (a * c < b * c ↔ a < b) :=
mul_comm c a ▸ mul_comm c b ▸ mul_lt_mul_left
protected lemma mul_eq_left (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a * b = a ↔ b = 1 := by
simpa using ENNReal.mul_right_inj ha₀ ha (c := 1)
protected lemma mul_eq_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b = b ↔ a = 1 := by
simpa using ENNReal.mul_left_inj hb₀ hb (b := 1)
end Mul
section OperationsAndOrder
protected theorem pow_pos : 0 < a → ∀ n : ℕ, 0 < a ^ n :=
CanonicallyOrderedAdd.pow_pos
protected theorem pow_ne_zero : a ≠ 0 → ∀ n : ℕ, a ^ n ≠ 0 := by
simpa only [pos_iff_ne_zero] using ENNReal.pow_pos
theorem not_lt_zero : ¬a < 0 := by simp
protected theorem le_of_add_le_add_left : a ≠ ∞ → a + b ≤ a + c → b ≤ c :=
WithTop.le_of_add_le_add_left
protected theorem le_of_add_le_add_right : a ≠ ∞ → b + a ≤ c + a → b ≤ c :=
WithTop.le_of_add_le_add_right
@[gcongr] protected theorem add_lt_add_left : a ≠ ∞ → b < c → a + b < a + c :=
WithTop.add_lt_add_left
@[gcongr] protected theorem add_lt_add_right : a ≠ ∞ → b < c → b + a < c + a :=
WithTop.add_lt_add_right
protected theorem add_le_add_iff_left : a ≠ ∞ → (a + b ≤ a + c ↔ b ≤ c) :=
WithTop.add_le_add_iff_left
protected theorem add_le_add_iff_right : a ≠ ∞ → (b + a ≤ c + a ↔ b ≤ c) :=
WithTop.add_le_add_iff_right
protected theorem add_lt_add_iff_left : a ≠ ∞ → (a + b < a + c ↔ b < c) :=
WithTop.add_lt_add_iff_left
protected theorem add_lt_add_iff_right : a ≠ ∞ → (b + a < c + a ↔ b < c) :=
WithTop.add_lt_add_iff_right
protected theorem add_lt_add_of_le_of_lt : a ≠ ∞ → a ≤ b → c < d → a + c < b + d :=
WithTop.add_lt_add_of_le_of_lt
protected theorem add_lt_add_of_lt_of_le : c ≠ ∞ → a < b → c ≤ d → a + c < b + d :=
WithTop.add_lt_add_of_lt_of_le
instance addLeftReflectLT : AddLeftReflectLT ℝ≥0∞ :=
WithTop.addLeftReflectLT
theorem lt_add_right (ha : a ≠ ∞) (hb : b ≠ 0) : a < a + b := by
rwa [← pos_iff_ne_zero, ← ENNReal.add_lt_add_iff_left ha, add_zero] at hb
end OperationsAndOrder
section OperationsAndInfty
variable {α : Type*} {n : ℕ}
@[simp] theorem add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := WithTop.add_eq_top
@[simp] theorem add_lt_top : a + b < ∞ ↔ a < ∞ ∧ b < ∞ := WithTop.add_lt_top
theorem toNNReal_add {r₁ r₂ : ℝ≥0∞} (h₁ : r₁ ≠ ∞) (h₂ : r₂ ≠ ∞) :
(r₁ + r₂).toNNReal = r₁.toNNReal + r₂.toNNReal := by
lift r₁ to ℝ≥0 using h₁
lift r₂ to ℝ≥0 using h₂
rfl
/-- If `a ≤ b + c` and `a = ∞` whenever `b = ∞` or `c = ∞`, then
`ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer
triangle-like inequalities from `ENNReal`s to `Real`s. -/
theorem toReal_le_add' (hle : a ≤ b + c) (hb : b = ∞ → a = ∞) (hc : c = ∞ → a = ∞) :
a.toReal ≤ b.toReal + c.toReal := by
refine le_trans (toReal_mono' hle ?_) toReal_add_le
simpa only [add_eq_top, or_imp] using And.intro hb hc
/-- If `a ≤ b + c`, `b ≠ ∞`, and `c ≠ ∞`, then
`ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer
triangle-like inequalities from `ENNReal`s to `Real`s. -/
theorem toReal_le_add (hle : a ≤ b + c) (hb : b ≠ ∞) (hc : c ≠ ∞) :
a.toReal ≤ b.toReal + c.toReal :=
toReal_le_add' hle (flip absurd hb) (flip absurd hc)
theorem not_lt_top {x : ℝ≥0∞} : ¬x < ∞ ↔ x = ∞ := by rw [lt_top_iff_ne_top, Classical.not_not]
theorem add_ne_top : a + b ≠ ∞ ↔ a ≠ ∞ ∧ b ≠ ∞ := by simpa only [lt_top_iff_ne_top] using add_lt_top
@[aesop (rule_sets := [finiteness]) safe apply]
protected lemma Finiteness.add_ne_top {a b : ℝ≥0∞} (ha : a ≠ ∞) (hb : b ≠ ∞) : a + b ≠ ∞ :=
ENNReal.add_ne_top.2 ⟨ha, hb⟩
theorem mul_top' : a * ∞ = if a = 0 then 0 else ∞ := by convert WithTop.mul_top' a
@[simp] theorem mul_top (h : a ≠ 0) : a * ∞ = ∞ := WithTop.mul_top h
theorem top_mul' : ∞ * a = if a = 0 then 0 else ∞ := by convert WithTop.top_mul' a
@[simp] theorem top_mul (h : a ≠ 0) : ∞ * a = ∞ := WithTop.top_mul h
theorem top_mul_top : ∞ * ∞ = ∞ := WithTop.top_mul_top
theorem mul_eq_top : a * b = ∞ ↔ a ≠ 0 ∧ b = ∞ ∨ a = ∞ ∧ b ≠ 0 :=
WithTop.mul_eq_top_iff
theorem mul_lt_top : a < ∞ → b < ∞ → a * b < ∞ := WithTop.mul_lt_top
-- This is unsafe because we could have `a = ∞` and `b = 0` or vice-versa
@[aesop (rule_sets := [finiteness]) unsafe 75% apply]
theorem mul_ne_top : a ≠ ∞ → b ≠ ∞ → a * b ≠ ∞ := WithTop.mul_ne_top
theorem lt_top_of_mul_ne_top_left (h : a * b ≠ ∞) (hb : b ≠ 0) : a < ∞ :=
lt_top_iff_ne_top.2 fun ha => h <| mul_eq_top.2 (Or.inr ⟨ha, hb⟩)
theorem lt_top_of_mul_ne_top_right (h : a * b ≠ ∞) (ha : a ≠ 0) : b < ∞ :=
lt_top_of_mul_ne_top_left (by rwa [mul_comm]) ha
theorem mul_lt_top_iff {a b : ℝ≥0∞} : a * b < ∞ ↔ a < ∞ ∧ b < ∞ ∨ a = 0 ∨ b = 0 := by
constructor
· intro h
rw [← or_assoc, or_iff_not_imp_right, or_iff_not_imp_right]
intro hb ha
exact ⟨lt_top_of_mul_ne_top_left h.ne hb, lt_top_of_mul_ne_top_right h.ne ha⟩
· rintro (⟨ha, hb⟩ | rfl | rfl) <;> [exact mul_lt_top ha hb; simp; simp]
theorem mul_self_lt_top_iff {a : ℝ≥0∞} : a * a < ⊤ ↔ a < ⊤ := by
rw [ENNReal.mul_lt_top_iff, and_self, or_self, or_iff_left_iff_imp]
rintro rfl
exact zero_lt_top
theorem mul_pos_iff : 0 < a * b ↔ 0 < a ∧ 0 < b :=
CanonicallyOrderedAdd.mul_pos
theorem mul_pos (ha : a ≠ 0) (hb : b ≠ 0) : 0 < a * b :=
mul_pos_iff.2 ⟨pos_iff_ne_zero.2 ha, pos_iff_ne_zero.2 hb⟩
@[simp] lemma top_pow {n : ℕ} (hn : n ≠ 0) : (∞ : ℝ≥0∞) ^ n = ∞ := WithTop.top_pow hn
@[simp] lemma pow_eq_top_iff : a ^ n = ∞ ↔ a = ∞ ∧ n ≠ 0 := WithTop.pow_eq_top_iff
lemma pow_ne_top_iff : a ^ n ≠ ∞ ↔ a ≠ ∞ ∨ n = 0 := WithTop.pow_ne_top_iff
@[simp] lemma pow_lt_top_iff : a ^ n < ∞ ↔ a < ∞ ∨ n = 0 := WithTop.pow_lt_top_iff
lemma eq_top_of_pow (n : ℕ) (ha : a ^ n = ∞) : a = ∞ := WithTop.eq_top_of_pow n ha
@[deprecated (since := "2025-04-24")] alias pow_eq_top := eq_top_of_pow
lemma pow_ne_top (ha : a ≠ ∞) : a ^ n ≠ ∞ := WithTop.pow_ne_top ha
lemma pow_lt_top (ha : a < ∞) : a ^ n < ∞ := WithTop.pow_lt_top ha
end OperationsAndInfty
-- TODO: generalize to `WithTop`
@[gcongr] protected theorem add_lt_add (ac : a < c) (bd : b < d) : a + b < c + d := by
lift a to ℝ≥0 using ac.ne_top
lift b to ℝ≥0 using bd.ne_top
cases c; · simp
cases d; · simp
simp only [← coe_add, some_eq_coe, coe_lt_coe] at *
exact add_lt_add ac bd
section Cancel
-- TODO: generalize to `WithTop`
/-- An element `a` is `AddLECancellable` if `a + b ≤ a + c` implies `b ≤ c` for all `b` and `c`.
This is true in `ℝ≥0∞` for all elements except `∞`. -/
@[simp]
theorem addLECancellable_iff_ne {a : ℝ≥0∞} : AddLECancellable a ↔ a ≠ ∞ := by
constructor
· rintro h rfl
refine zero_lt_one.not_le (h ?_)
simp
· rintro h b c hbc
apply ENNReal.le_of_add_le_add_left h hbc
/-- This lemma has an abbreviated name because it is used frequently. -/
theorem cancel_of_ne {a : ℝ≥0∞} (h : a ≠ ∞) : AddLECancellable a :=
addLECancellable_iff_ne.mpr h
/-- This lemma has an abbreviated name because it is used frequently. -/
theorem cancel_of_lt {a : ℝ≥0∞} (h : a < ∞) : AddLECancellable a :=
cancel_of_ne h.ne
/-- This lemma has an abbreviated name because it is used frequently. -/
theorem cancel_of_lt' {a b : ℝ≥0∞} (h : a < b) : AddLECancellable a :=
cancel_of_ne h.ne_top
/-- This lemma has an abbreviated name because it is used frequently. -/
theorem cancel_coe {a : ℝ≥0} : AddLECancellable (a : ℝ≥0∞) :=
cancel_of_ne coe_ne_top
theorem add_right_inj (h : a ≠ ∞) : a + b = a + c ↔ b = c :=
(cancel_of_ne h).inj
theorem add_left_inj (h : a ≠ ∞) : b + a = c + a ↔ b = c :=
(cancel_of_ne h).inj_left
end Cancel
section Sub
theorem sub_eq_sInf {a b : ℝ≥0∞} : a - b = sInf { d | a ≤ d + b } :=
le_antisymm (le_sInf fun _ h => tsub_le_iff_right.mpr h) <| sInf_le <| mem_setOf.2 le_tsub_add
/-- This is a special case of `WithTop.coe_sub` in the `ENNReal` namespace -/
@[simp, norm_cast] theorem coe_sub : (↑(r - p) : ℝ≥0∞) = ↑r - ↑p := WithTop.coe_sub
/-- This is a special case of `WithTop.top_sub_coe` in the `ENNReal` namespace -/
@[simp] theorem top_sub_coe : ∞ - ↑r = ∞ := WithTop.top_sub_coe
@[simp] lemma top_sub (ha : a ≠ ∞) : ∞ - a = ∞ := by lift a to ℝ≥0 using ha; exact top_sub_coe
/-- This is a special case of `WithTop.sub_top` in the `ENNReal` namespace -/
theorem sub_top : a - ∞ = 0 := WithTop.sub_top
@[simp] theorem sub_eq_top_iff : a - b = ∞ ↔ a = ∞ ∧ b ≠ ∞ := WithTop.sub_eq_top_iff
lemma sub_ne_top_iff : a - b ≠ ∞ ↔ a ≠ ∞ ∨ b = ∞ := WithTop.sub_ne_top_iff
-- This is unsafe because we could have `a = b = ∞`
@[aesop (rule_sets := [finiteness]) unsafe 75% apply]
theorem sub_ne_top (ha : a ≠ ∞) : a - b ≠ ∞ := mt sub_eq_top_iff.mp <| mt And.left ha
@[simp, norm_cast]
theorem natCast_sub (m n : ℕ) : ↑(m - n) = (m - n : ℝ≥0∞) := by
rw [← coe_natCast, Nat.cast_tsub, coe_sub, coe_natCast, coe_natCast]
/-- See `ENNReal.sub_eq_of_eq_add'` for a version assuming that `a = c + b` itself is finite rather
than `b`. -/
protected theorem sub_eq_of_eq_add (hb : b ≠ ∞) : a = c + b → a - b = c :=
(cancel_of_ne hb).tsub_eq_of_eq_add
/-- Weaker version of `ENNReal.sub_eq_of_eq_add` assuming that `a = c + b` itself is finite rather
han `b`. -/
protected lemma sub_eq_of_eq_add' (ha : a ≠ ∞) : a = c + b → a - b = c :=
(cancel_of_ne ha).tsub_eq_of_eq_add'
/-- See `ENNReal.eq_sub_of_add_eq'` for a version assuming that `b = a + c` itself is finite rather
than `c`. -/
protected theorem eq_sub_of_add_eq (hc : c ≠ ∞) : a + c = b → a = b - c :=
(cancel_of_ne hc).eq_tsub_of_add_eq
/-- Weaker version of `ENNReal.eq_sub_of_add_eq` assuming that `b = a + c` itself is finite rather
than `c`. -/
protected lemma eq_sub_of_add_eq' (hb : b ≠ ∞) : a + c = b → a = b - c :=
(cancel_of_ne hb).eq_tsub_of_add_eq'
/-- See `ENNReal.sub_eq_of_eq_add_rev'` for a version assuming that `a = b + c` itself is finite
rather than `b`. -/
protected theorem sub_eq_of_eq_add_rev (hb : b ≠ ∞) : a = b + c → a - b = c :=
(cancel_of_ne hb).tsub_eq_of_eq_add_rev
/-- Weaker version of `ENNReal.sub_eq_of_eq_add_rev` assuming that `a = b + c` itself is finite
rather than `b`. -/
protected lemma sub_eq_of_eq_add_rev' (ha : a ≠ ∞) : a = b + c → a - b = c :=
(cancel_of_ne ha).tsub_eq_of_eq_add_rev'
@[simp]
protected theorem add_sub_cancel_left (ha : a ≠ ∞) : a + b - a = b :=
(cancel_of_ne ha).add_tsub_cancel_left
@[simp]
protected theorem add_sub_cancel_right (hb : b ≠ ∞) : a + b - b = a :=
(cancel_of_ne hb).add_tsub_cancel_right
protected theorem sub_add_eq_add_sub (hab : b ≤ a) (b_ne_top : b ≠ ∞) :
a - b + c = a + c - b := by
by_cases c_top : c = ∞
· simpa [c_top] using ENNReal.eq_sub_of_add_eq b_ne_top rfl
refine ENNReal.eq_sub_of_add_eq b_ne_top ?_
simp only [add_assoc, add_comm c b]
simpa only [← add_assoc] using (add_left_inj c_top).mpr <| tsub_add_cancel_of_le hab
protected theorem lt_add_of_sub_lt_left (h : a ≠ ∞ ∨ b ≠ ∞) : a - b < c → a < b + c := by
obtain rfl | hb := eq_or_ne b ∞
· rw [top_add, lt_top_iff_ne_top]
exact fun _ => h.resolve_right (Classical.not_not.2 rfl)
· exact (cancel_of_ne hb).lt_add_of_tsub_lt_left
protected theorem lt_add_of_sub_lt_right (h : a ≠ ∞ ∨ c ≠ ∞) : a - c < b → a < b + c :=
add_comm c b ▸ ENNReal.lt_add_of_sub_lt_left h
theorem le_sub_of_add_le_left (ha : a ≠ ∞) : a + b ≤ c → b ≤ c - a :=
(cancel_of_ne ha).le_tsub_of_add_le_left
theorem le_sub_of_add_le_right (hb : b ≠ ∞) : a + b ≤ c → a ≤ c - b :=
(cancel_of_ne hb).le_tsub_of_add_le_right
protected theorem sub_lt_of_lt_add (hac : c ≤ a) (h : a < b + c) : a - c < b :=
((cancel_of_lt' <| hac.trans_lt h).tsub_lt_iff_right hac).mpr h
protected theorem sub_lt_iff_lt_right (hb : b ≠ ∞) (hab : b ≤ a) : a - b < c ↔ a < c + b :=
(cancel_of_ne hb).tsub_lt_iff_right hab
protected theorem sub_lt_self (ha : a ≠ ∞) (ha₀ : a ≠ 0) (hb : b ≠ 0) : a - b < a :=
(cancel_of_ne ha).tsub_lt_self (pos_iff_ne_zero.2 ha₀) (pos_iff_ne_zero.2 hb)
protected theorem sub_lt_self_iff (ha : a ≠ ∞) : a - b < a ↔ 0 < a ∧ 0 < b :=
(cancel_of_ne ha).tsub_lt_self_iff
theorem sub_lt_of_sub_lt (h₂ : c ≤ a) (h₃ : a ≠ ∞ ∨ b ≠ ∞) (h₁ : a - b < c) : a - c < b :=
ENNReal.sub_lt_of_lt_add h₂ (add_comm c b ▸ ENNReal.lt_add_of_sub_lt_right h₃ h₁)
theorem sub_sub_cancel (h : a ≠ ∞) (h2 : b ≤ a) : a - (a - b) = b :=
(cancel_of_ne <| sub_ne_top h).tsub_tsub_cancel_of_le h2
theorem sub_right_inj {a b c : ℝ≥0∞} (ha : a ≠ ∞) (hb : b ≤ a) (hc : c ≤ a) :
a - b = a - c ↔ b = c :=
(cancel_of_ne ha).tsub_right_inj (cancel_of_ne <| ne_top_of_le_ne_top ha hb)
(cancel_of_ne <| ne_top_of_le_ne_top ha hc) hb hc
protected theorem sub_mul (h : 0 < b → b < a → c ≠ ∞) : (a - b) * c = a * c - b * c := by
rcases le_or_lt a b with hab | hab; · simp [hab, mul_right_mono hab, tsub_eq_zero_of_le]
rcases eq_or_lt_of_le (zero_le b) with (rfl | hb); · simp
exact (cancel_of_ne <| mul_ne_top hab.ne_top (h hb hab)).tsub_mul
protected theorem mul_sub (h : 0 < c → c < b → a ≠ ∞) : a * (b - c) = a * b - a * c := by
simp only [mul_comm a]
exact ENNReal.sub_mul h
theorem sub_le_sub_iff_left (h : c ≤ a) (h' : a ≠ ∞) :
(a - b ≤ a - c) ↔ c ≤ b :=
(cancel_of_ne h').tsub_le_tsub_iff_left (cancel_of_ne (ne_top_of_le_ne_top h' h)) h
theorem le_toReal_sub {a b : ℝ≥0∞} (hb : b ≠ ∞) : a.toReal - b.toReal ≤ (a - b).toReal := by
lift b to ℝ≥0 using hb
induction a
· simp
· simp only [← coe_sub, NNReal.sub_def, Real.coe_toNNReal', coe_toReal]
exact le_max_left _ _
@[simp]
lemma toNNReal_sub (hb : b ≠ ∞) : (a - b).toNNReal = a.toNNReal - b.toNNReal := by
lift b to ℝ≥0 using hb; induction a <;> simp [← coe_sub]
@[simp]
lemma toReal_sub_of_le (hba : b ≤ a) (ha : a ≠ ∞) : (a - b).toReal = a.toReal - b.toReal := by
simp [ENNReal.toReal, ne_top_of_le_ne_top ha hba, toNNReal_mono ha hba]
theorem ofReal_sub (p : ℝ) {q : ℝ} (hq : 0 ≤ q) :
ENNReal.ofReal (p - q) = ENNReal.ofReal p - ENNReal.ofReal q := by
obtain h | h := le_total p q
· rw [ofReal_of_nonpos (sub_nonpos_of_le h), tsub_eq_zero_of_le (ofReal_le_ofReal h)]
refine ENNReal.eq_sub_of_add_eq ofReal_ne_top ?_
rw [← ofReal_add (sub_nonneg_of_le h) hq, sub_add_cancel]
end Sub
section Interval
variable {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : Set ℝ≥0∞}
protected theorem Ico_eq_Iio : Ico 0 y = Iio y :=
Ico_bot
theorem mem_Iio_self_add : x ≠ ∞ → ε ≠ 0 → x ∈ Iio (x + ε) := fun xt ε0 => lt_add_right xt ε0
theorem mem_Ioo_self_sub_add : x ≠ ∞ → x ≠ 0 → ε₁ ≠ 0 → ε₂ ≠ 0 → x ∈ Ioo (x - ε₁) (x + ε₂) :=
fun xt x0 ε0 ε0' => ⟨ENNReal.sub_lt_self xt x0 ε0, lt_add_right xt ε0'⟩
@[simp]
theorem image_coe_Iic (x : ℝ≥0) : (↑) '' Iic x = Iic (x : ℝ≥0∞) := WithTop.image_coe_Iic
@[simp]
theorem image_coe_Ici (x : ℝ≥0) : (↑) '' Ici x = Ico ↑x ∞ := WithTop.image_coe_Ici
@[simp]
theorem image_coe_Iio (x : ℝ≥0) : (↑) '' Iio x = Iio (x : ℝ≥0∞) := WithTop.image_coe_Iio
@[simp]
theorem image_coe_Ioi (x : ℝ≥0) : (↑) '' Ioi x = Ioo ↑x ∞ := WithTop.image_coe_Ioi
@[simp]
theorem image_coe_Icc (x y : ℝ≥0) : (↑) '' Icc x y = Icc (x : ℝ≥0∞) y := WithTop.image_coe_Icc
@[simp]
theorem image_coe_Ico (x y : ℝ≥0) : (↑) '' Ico x y = Ico (x : ℝ≥0∞) y := WithTop.image_coe_Ico
@[simp]
theorem image_coe_Ioc (x y : ℝ≥0) : (↑) '' Ioc x y = Ioc (x : ℝ≥0∞) y := WithTop.image_coe_Ioc
@[simp]
theorem image_coe_Ioo (x y : ℝ≥0) : (↑) '' Ioo x y = Ioo (x : ℝ≥0∞) y := WithTop.image_coe_Ioo
@[simp]
theorem image_coe_uIcc (x y : ℝ≥0) : (↑) '' uIcc x y = uIcc (x : ℝ≥0∞) y := by simp [uIcc]
@[simp]
theorem image_coe_uIoc (x y : ℝ≥0) : (↑) '' uIoc x y = uIoc (x : ℝ≥0∞) y := by simp [uIoc]
@[simp]
theorem image_coe_uIoo (x y : ℝ≥0) : (↑) '' uIoo x y = uIoo (x : ℝ≥0∞) y := by simp [uIoo]
end Interval
end ENNReal
| Mathlib/Data/ENNReal/Operations.lean | 532 | 538 | |
/-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Simon Hudon
-/
import Mathlib.Data.PFunctor.Multivariate.Basic
/-!
# Multivariate quotients of polynomial functors.
Basic definition of multivariate QPF. QPFs form a compositional framework
for defining inductive and coinductive types, their quotients and nesting.
The idea is based on building ever larger functors. For instance, we can define
a list using a shape functor:
```lean
inductive ListShape (a b : Type)
| nil : ListShape
| cons : a -> b -> ListShape
```
This shape can itself be decomposed as a sum of product which are themselves
QPFs. It follows that the shape is a QPF and we can take its fixed point
and create the list itself:
```lean
def List (a : Type) := fix ListShape a -- not the actual notation
```
We can continue and define the quotient on permutation of lists and create
the multiset type:
```lean
def Multiset (a : Type) := QPF.quot List.perm List a -- not the actual notion
```
And `Multiset` is also a QPF. We can then create a novel data type (for Lean):
```lean
inductive Tree (a : Type)
| node : a -> Multiset Tree -> Tree
```
An unordered tree. This is currently not supported by Lean because it nests
an inductive type inside of a quotient. We can go further and define
unordered, possibly infinite trees:
```lean
coinductive Tree' (a : Type)
| node : a -> Multiset Tree' -> Tree'
```
by using the `cofix` construct. Those options can all be mixed and
matched because they preserve the properties of QPF. The latter example,
`Tree'`, combines fixed point, co-fixed point and quotients.
## Related modules
* constructions
* Fix
* Cofix
* Quot
* Comp
* Sigma / Pi
* Prj
* Const
each proves that some operations on functors preserves the QPF structure
-/
set_option linter.style.longLine false in
/-!
## Reference
[Jeremy Avigad, Mario M. Carneiro and Simon Hudon, *Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019]
-/
universe u
open MvFunctor
/-- Multivariate quotients of polynomial functors.
-/
class MvQPF {n : ℕ} (F : TypeVec.{u} n → Type*) extends MvFunctor F where
P : MvPFunctor.{u} n
abs : ∀ {α}, P α → F α
repr : ∀ {α}, F α → P α
abs_repr : ∀ {α} (x : F α), abs (repr x) = x
abs_map : ∀ {α β} (f : α ⟹ β) (p : P α), abs (f <$$> p) = f <$$> abs p
namespace MvQPF
variable {n : ℕ} {F : TypeVec.{u} n → Type*} [q : MvQPF F]
open MvFunctor (LiftP LiftR)
/-!
### Show that every MvQPF is a lawful MvFunctor.
-/
protected theorem id_map {α : TypeVec n} (x : F α) : TypeVec.id <$$> x = x := by
rw [← abs_repr x, ← abs_map]
rfl
@[simp]
theorem comp_map {α β γ : TypeVec n} (f : α ⟹ β) (g : β ⟹ γ) (x : F α) :
(g ⊚ f) <$$> x = g <$$> f <$$> x := by
rw [← abs_repr x, ← abs_map, ← abs_map, ← abs_map]
rfl
instance (priority := 100) lawfulMvFunctor : LawfulMvFunctor F where
id_map := @MvQPF.id_map n F _
comp_map := @comp_map n F _
-- Lifting predicates and relations
theorem liftP_iff {α : TypeVec n} (p : ∀ ⦃i⦄, α i → Prop) (x : F α) :
LiftP p x ↔ ∃ a f, x = abs ⟨a, f⟩ ∧ ∀ i j, p (f i j) := by
constructor
· rintro ⟨y, hy⟩
rcases h : repr y with ⟨a, f⟩
use a, fun i j => (f i j).val
constructor
· rw [← hy, ← abs_repr y, h, ← abs_map]; rfl
intro i j
apply (f i j).property
rintro ⟨a, f, h₀, h₁⟩
use abs ⟨a, fun i j => ⟨f i j, h₁ i j⟩⟩
rw [← abs_map, h₀]; rfl
theorem liftR_iff {α : TypeVec n} (r : ∀ ⦃i⦄, α i → α i → Prop) (x y : F α) :
LiftR r x y ↔ ∃ a f₀ f₁, x = abs ⟨a, f₀⟩ ∧ y = abs ⟨a, f₁⟩ ∧ ∀ i j, r (f₀ i j) (f₁ i j) := by
constructor
· rintro ⟨u, xeq, yeq⟩
rcases h : repr u with ⟨a, f⟩
use a, fun i j => (f i j).val.fst, fun i j => (f i j).val.snd
constructor
· rw [← xeq, ← abs_repr u, h, ← abs_map]; rfl
constructor
· rw [← yeq, ← abs_repr u, h, ← abs_map]; rfl
intro i j
exact (f i j).property
rintro ⟨a, f₀, f₁, xeq, yeq, h⟩
use abs ⟨a, fun i j => ⟨(f₀ i j, f₁ i j), h i j⟩⟩
dsimp; constructor
· rw [xeq, ← abs_map]; rfl
rw [yeq, ← abs_map]; rfl
open Set
open MvFunctor (LiftP LiftR)
theorem mem_supp {α : TypeVec n} (x : F α) (i) (u : α i) :
u ∈ supp x i ↔ ∀ a f, abs ⟨a, f⟩ = x → u ∈ f i '' univ := by
rw [supp]; dsimp; constructor
· intro h a f haf
have : LiftP (fun i u => u ∈ f i '' univ) x := by
rw [liftP_iff]
refine ⟨a, f, haf.symm, ?_⟩
intro i u
exact mem_image_of_mem _ (mem_univ _)
exact h this
intro h p; rw [liftP_iff]
rintro ⟨a, f, xeq, h'⟩
rcases h a f xeq.symm with ⟨i, _, hi⟩
rw [← hi]; apply h'
theorem supp_eq {α : TypeVec n} {i} (x : F α) :
supp x i = { u | ∀ a f, abs ⟨a, f⟩ = x → u ∈ f i '' univ } := by ext; apply mem_supp
theorem has_good_supp_iff {α : TypeVec n} (x : F α) :
(∀ p, LiftP p x ↔ ∀ (i), ∀ u ∈ supp x i, p i u) ↔
∃ a f, abs ⟨a, f⟩ = x ∧ ∀ i a' f', abs ⟨a', f'⟩ = x → f i '' univ ⊆ f' i '' univ := by
constructor
· intro h
have : LiftP (supp x) x := by rw [h]; introv; exact id
rw [liftP_iff] at this
rcases this with ⟨a, f, xeq, h'⟩
refine ⟨a, f, xeq.symm, ?_⟩
intro a' f' h''
rintro hu u ⟨j, _h₂, hfi⟩
have hh : u ∈ supp x a' := by rw [← hfi]; apply h'
exact (mem_supp x _ u).mp hh _ _ hu
rintro ⟨a, f, xeq, h⟩ p; rw [liftP_iff]; constructor
· rintro ⟨a', f', xeq', h'⟩ i u usuppx
rcases (mem_supp x _ u).mp (@usuppx) a' f' xeq'.symm with ⟨i, _, f'ieq⟩
rw [← f'ieq]
apply h'
intro h'
refine ⟨a, f, xeq.symm, ?_⟩; intro j y
apply h'; rw [mem_supp]
intro a' f' xeq'
apply h _ a' f' xeq'
apply mem_image_of_mem _ (mem_univ _)
/-- A qpf is said to be uniform if every polynomial functor
representing a single value all have the same range. -/
def IsUniform : Prop :=
∀ ⦃α : TypeVec n⦄ (a a' : q.P.A) (f : q.P.B a ⟹ α) (f' : q.P.B a' ⟹ α),
abs ⟨a, f⟩ = abs ⟨a', f'⟩ → ∀ i, f i '' univ = f' i '' univ
/-- does `abs` preserve `liftp`? -/
def LiftPPreservation : Prop :=
∀ ⦃α : TypeVec n⦄ (p : ∀ ⦃i⦄, α i → Prop) (x : q.P α), LiftP p (abs x) ↔ LiftP p x
/-- does `abs` preserve `supp`? -/
def SuppPreservation : Prop :=
∀ ⦃α⦄ (x : q.P α), supp (abs x) = supp x
theorem supp_eq_of_isUniform (h : q.IsUniform) {α : TypeVec n} (a : q.P.A) (f : q.P.B a ⟹ α) :
∀ i, supp (abs ⟨a, f⟩) i = f i '' univ := by
intro; ext u; rw [mem_supp]; constructor
· intro h'
apply h' _ _ rfl
intro h' a' f' e
rw [← h _ _ _ _ e.symm]; apply h'
theorem liftP_iff_of_isUniform (h : q.IsUniform) {α : TypeVec n} (x : F α) (p : ∀ i, α i → Prop) :
LiftP p x ↔ ∀ (i), ∀ u ∈ supp x i, p i u := by
rw [liftP_iff, ← abs_repr x]
obtain ⟨a, f⟩ := repr x; constructor
· rintro ⟨a', f', abseq, hf⟩ u
rw [supp_eq_of_isUniform h, h _ _ _ _ abseq]
rintro b ⟨i, _, hi⟩
rw [← hi]
apply hf
intro h'
refine ⟨a, f, rfl, fun _ i => h' _ _ ?_⟩
rw [supp_eq_of_isUniform h]
exact ⟨i, mem_univ i, rfl⟩
theorem supp_map (h : q.IsUniform) {α β : TypeVec n} (g : α ⟹ β) (x : F α) (i) :
supp (g <$$> x) i = g i '' supp x i := by
rw [← abs_repr x]; obtain ⟨a, f⟩ := repr x; rw [← abs_map, MvPFunctor.map_eq]
rw [supp_eq_of_isUniform h, supp_eq_of_isUniform h, ← image_comp]
rfl
theorem suppPreservation_iff_isUniform : q.SuppPreservation ↔ q.IsUniform := by
constructor
· intro h α a a' f f' h' i
rw [← MvPFunctor.supp_eq, ← MvPFunctor.supp_eq, ← h, h', h]
· rintro h α ⟨a, f⟩
ext
rwa [supp_eq_of_isUniform, MvPFunctor.supp_eq]
theorem suppPreservation_iff_liftpPreservation : q.SuppPreservation ↔ q.LiftPPreservation := by
constructor <;> intro h
· rintro α p ⟨a, f⟩
have h' := h
rw [suppPreservation_iff_isUniform] at h'
dsimp only [SuppPreservation, supp] at h
simp only [liftP_iff_of_isUniform, supp_eq_of_isUniform, MvPFunctor.liftP_iff', h',
image_univ, mem_range, exists_imp]
constructor <;> intros <;> subst_vars <;> solve_by_elim
· rintro α ⟨a, f⟩
simp only [LiftPPreservation] at h
ext
simp only [supp, h, mem_setOf_eq]
theorem liftpPreservation_iff_uniform : q.LiftPPreservation ↔ q.IsUniform := by
| rw [← suppPreservation_iff_liftpPreservation, suppPreservation_iff_isUniform]
/-- Any type function `F` that is (extensionally) equivalent to a QPF, is itself a QPF,
assuming that the functorial map of `F` behaves similar to `MvFunctor.ofEquiv eqv` -/
def ofEquiv {F F' : TypeVec.{u} n → Type*} [q : MvQPF F'] [MvFunctor F]
(eqv : ∀ α, F α ≃ F' α)
(map_eq : ∀ (α β : TypeVec n) (f : α ⟹ β) (a : F α),
f <$$> a = ((eqv _).symm <| f <$$> eqv _ a) := by intros; rfl) :
MvQPF F where
P := q.P
abs α := (eqv _).symm <| q.abs α
repr α := q.repr <| eqv _ α
abs_repr := by simp [q.abs_repr]
| Mathlib/Data/QPF/Multivariate/Basic.lean | 263 | 275 |
/-
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]
theorem gcd_one {n : ℕ+} : gcd n 1 = 1 := by
rw [gcd_comm]
apply one_gcd
@[symm]
theorem Coprime.symm {m n : ℕ+} : m.Coprime n → n.Coprime m := by
unfold Coprime
rw [gcd_comm]
simp
@[simp]
theorem one_coprime {n : ℕ+} : (1 : ℕ+).Coprime n :=
one_gcd
@[simp]
theorem coprime_one {n : ℕ+} : n.Coprime 1 :=
Coprime.symm one_coprime
theorem Coprime.coprime_dvd_left {m k n : ℕ+} : m ∣ k → k.Coprime n → m.Coprime n := by
rw [dvd_iff]
repeat rw [← coprime_coe]
apply Nat.Coprime.coprime_dvd_left
theorem Coprime.factor_eq_gcd_left {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) :
a = (a * b).gcd m := by
rw [← gcd_eq_left_iff_dvd] at am
conv_lhs => rw [← am]
rw [eq_comm]
apply Coprime.gcd_mul_right_cancel a
apply Coprime.coprime_dvd_left bn cop.symm
theorem Coprime.factor_eq_gcd_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) :
a = (b * a).gcd m := by rw [mul_comm]; apply Coprime.factor_eq_gcd_left cop am bn
theorem Coprime.factor_eq_gcd_left_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m)
(bn : b ∣ n) : a = m.gcd (a * b) := by rw [gcd_comm]; apply Coprime.factor_eq_gcd_left cop am bn
theorem Coprime.factor_eq_gcd_right_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m)
(bn : b ∣ n) : a = m.gcd (b * a) := by
rw [gcd_comm]
apply Coprime.factor_eq_gcd_right cop am bn
theorem Coprime.gcd_mul (k : ℕ+) {m n : ℕ+} (h : m.Coprime n) :
k.gcd (m * n) = k.gcd m * k.gcd n := by
rw [← coprime_coe] at h; apply eq
simp only [gcd_coe, mul_coe]; apply Nat.Coprime.gcd_mul k h
| theorem gcd_eq_left {m n : ℕ+} : m ∣ n → m.gcd n = m := by
rw [dvd_iff]
intro h
apply eq
| Mathlib/Data/PNat/Prime.lean | 257 | 260 |
/-
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.Ordmap.Invariants
/-!
# Verification of `Ordnode`
This file uses the invariants defined in `Mathlib.Data.Ordmap.Invariants` to construct `Ordset α`,
a wrapper around `Ordnode α` which includes the correctness invariant of the type. It exposes
parallel operations like `insert` as functions on `Ordset` that do the same thing but bundle the
correctness proofs.
The advantage is that it is possible to, for example, prove that the result of `find` on `insert`
will actually find the element, while `Ordnode` cannot guarantee this if the input tree did not
satisfy the type invariants.
## Main definitions
* `Ordnode.Valid`: The validity predicate for an `Ordnode` subtree.
* `Ordset α`: A well formed set of values of type `α`.
## Implementation notes
Because the `Ordnode` file was ported from Haskell, the correctness invariants of some
of the functions have not been spelled out, and some theorems like
`Ordnode.Valid'.balanceL_aux` show very intricate assumptions on the sizes,
which may need to be revised if it turns out some operations violate these assumptions,
because there is a decent amount of slop in the actual data structure invariants, so the
theorem will go through with multiple choices of assumption.
-/
variable {α : Type*}
namespace Ordnode
section Valid
variable [Preorder α]
/-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are
correct, the tree is balanced, and the elements of the tree are organized according to the
ordering. This version of `Valid` also puts all elements in the tree in the interval `(lo, hi)`. -/
structure Valid' (lo : WithBot α) (t : Ordnode α) (hi : WithTop α) : Prop where
ord : t.Bounded lo hi
sz : t.Sized
bal : t.Balanced
/-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are
correct, the tree is balanced, and the elements of the tree are organized according to the
ordering. -/
def Valid (t : Ordnode α) : Prop :=
Valid' ⊥ t ⊤
theorem Valid'.mono_left {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' y t o) :
Valid' x t o :=
⟨h.1.mono_left xy, h.2, h.3⟩
theorem Valid'.mono_right {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' o t x) :
Valid' o t y :=
⟨h.1.mono_right xy, h.2, h.3⟩
theorem Valid'.trans_left {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (h : Bounded t₁ o₁ x)
(H : Valid' x t₂ o₂) : Valid' o₁ t₂ o₂ :=
⟨h.trans_left H.1, H.2, H.3⟩
theorem Valid'.trans_right {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t₁ x)
(h : Bounded t₂ x o₂) : Valid' o₁ t₁ o₂ :=
⟨H.1.trans_right h, H.2, H.3⟩
theorem Valid'.of_lt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil o₁ x)
(h₂ : All (· < x) t) : Valid' o₁ t x :=
⟨H.1.of_lt h₁ h₂, H.2, H.3⟩
theorem Valid'.of_gt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil x o₂)
(h₂ : All (· > x) t) : Valid' x t o₂ :=
⟨H.1.of_gt h₁ h₂, H.2, H.3⟩
theorem Valid'.valid {t o₁ o₂} (h : @Valid' α _ o₁ t o₂) : Valid t :=
⟨h.1.weak, h.2, h.3⟩
theorem valid'_nil {o₁ o₂} (h : Bounded nil o₁ o₂) : Valid' o₁ (@nil α) o₂ :=
⟨h, ⟨⟩, ⟨⟩⟩
theorem valid_nil : Valid (@nil α) :=
valid'_nil ⟨⟩
theorem Valid'.node {s l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : BalancedSz (size l) (size r)) (hs : s = size l + size r + 1) :
Valid' o₁ (@node α s l x r) o₂ :=
⟨⟨hl.1, hr.1⟩, ⟨hs, hl.2, hr.2⟩, ⟨H, hl.3, hr.3⟩⟩
theorem Valid'.dual : ∀ {t : Ordnode α} {o₁ o₂}, Valid' o₁ t o₂ → @Valid' αᵒᵈ _ o₂ (dual t) o₁
| .nil, _, _, h => valid'_nil h.1.dual
| .node _ l _ r, _, _, ⟨⟨ol, Or⟩, ⟨rfl, sl, sr⟩, ⟨b, bl, br⟩⟩ =>
let ⟨ol', sl', bl'⟩ := Valid'.dual ⟨ol, sl, bl⟩
let ⟨or', sr', br'⟩ := Valid'.dual ⟨Or, sr, br⟩
⟨⟨or', ol'⟩, ⟨by simp [size_dual, add_comm], sr', sl'⟩,
⟨by rw [size_dual, size_dual]; exact b.symm, br', bl'⟩⟩
theorem Valid'.dual_iff {t : Ordnode α} {o₁ o₂} : Valid' o₁ t o₂ ↔ @Valid' αᵒᵈ _ o₂ (.dual t) o₁ :=
⟨Valid'.dual, fun h => by
have := Valid'.dual h; rwa [dual_dual, OrderDual.Preorder.dual_dual] at this⟩
theorem Valid.dual {t : Ordnode α} : Valid t → @Valid αᵒᵈ _ (.dual t) :=
Valid'.dual
theorem Valid.dual_iff {t : Ordnode α} : Valid t ↔ @Valid αᵒᵈ _ (.dual t) :=
Valid'.dual_iff
theorem Valid'.left {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' o₁ l x :=
⟨H.1.1, H.2.2.1, H.3.2.1⟩
theorem Valid'.right {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' x r o₂ :=
⟨H.1.2, H.2.2.2, H.3.2.2⟩
nonrec theorem Valid.left {s l x r} (H : Valid (@node α s l x r)) : Valid l :=
H.left.valid
nonrec theorem Valid.right {s l x r} (H : Valid (@node α s l x r)) : Valid r :=
H.right.valid
theorem Valid.size_eq {s l x r} (H : Valid (@node α s l x r)) :
size (@node α s l x r) = size l + size r + 1 :=
H.2.1
theorem Valid'.node' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : BalancedSz (size l) (size r)) : Valid' o₁ (@node' α l x r) o₂ :=
hl.node hr H rfl
theorem valid'_singleton {x : α} {o₁ o₂} (h₁ : Bounded nil o₁ x) (h₂ : Bounded nil x o₂) :
Valid' o₁ (singleton x : Ordnode α) o₂ :=
(valid'_nil h₁).node (valid'_nil h₂) (Or.inl zero_le_one) rfl
theorem valid_singleton {x : α} : Valid (singleton x : Ordnode α) :=
valid'_singleton ⟨⟩ ⟨⟩
theorem Valid'.node3L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y)
(hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m))
(H2 : BalancedSz (size l + size m + 1) (size r)) : Valid' o₁ (@node3L α l x m y r) o₂ :=
(hl.node' hm H1).node' hr H2
theorem Valid'.node3R {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y)
(hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m + size r + 1))
(H2 : BalancedSz (size m) (size r)) : Valid' o₁ (@node3R α l x m y r) o₂ :=
hl.node' (hm.node' hr H2) H1
theorem Valid'.node4L_lemma₁ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9)
(mr₂ : b + c + 1 ≤ 3 * d) (mm₁ : b ≤ 3 * c) : b < 3 * a + 1 := by omega
theorem Valid'.node4L_lemma₂ {b c d : ℕ} (mr₂ : b + c + 1 ≤ 3 * d) : c ≤ 3 * d := by omega
theorem Valid'.node4L_lemma₃ {b c d : ℕ} (mr₁ : 2 * d ≤ b + c + 1) (mm₁ : b ≤ 3 * c) :
d ≤ 3 * c := by omega
theorem Valid'.node4L_lemma₄ {a b c d : ℕ} (lr₁ : 3 * a ≤ b + c + 1 + d) (mr₂ : b + c + 1 ≤ 3 * d)
(mm₁ : b ≤ 3 * c) : a + b + 1 ≤ 3 * (c + d + 1) := by omega
theorem Valid'.node4L_lemma₅ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9)
(mr₁ : 2 * d ≤ b + c + 1) (mm₂ : c ≤ 3 * b) : c + d + 1 ≤ 3 * (a + b + 1) := by omega
theorem Valid'.node4L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y)
(hr : Valid' (↑y) r o₂) (Hm : 0 < size m)
(H : size l = 0 ∧ size m = 1 ∧ size r ≤ 1 ∨
0 < size l ∧
ratio * size r ≤ size m ∧
delta * size l ≤ size m + size r ∧
3 * (size m + size r) ≤ 16 * size l + 9 ∧ size m ≤ delta * size r) :
Valid' o₁ (@node4L α l x m y r) o₂ := by
obtain - | ⟨s, ml, z, mr⟩ := m; · cases Hm
suffices
BalancedSz (size l) (size ml) ∧
BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1) from
Valid'.node' (hl.node' hm.left this.1) (hm.right.node' hr this.2.1) this.2.2
rcases H with (⟨l0, m1, r0⟩ | ⟨l0, mr₁, lr₁, lr₂, mr₂⟩)
· rw [hm.2.size_eq, Nat.succ_inj, add_eq_zero] at m1
rw [l0, m1.1, m1.2]; revert r0; rcases size r with (_ | _ | _) <;>
[decide; decide; (intro r0; unfold BalancedSz delta; omega)]
· rcases Nat.eq_zero_or_pos (size r) with r0 | r0
· rw [r0] at mr₂; cases not_le_of_lt Hm mr₂
rw [hm.2.size_eq] at lr₁ lr₂ mr₁ mr₂
by_cases mm : size ml + size mr ≤ 1
· have r1 :=
le_antisymm
((mul_le_mul_left (by decide)).1 (le_trans mr₁ (Nat.succ_le_succ mm) : _ ≤ ratio * 1)) r0
rw [r1, add_assoc] at lr₁
have l1 :=
le_antisymm
((mul_le_mul_left (by decide)).1 (le_trans lr₁ (add_le_add_right mm 2) : _ ≤ delta * 1))
l0
rw [l1, r1]
revert mm; cases size ml <;> cases size mr <;> intro mm
· decide
· rw [zero_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩)
decide
· rcases mm with (_ | ⟨⟨⟩⟩); decide
· rw [Nat.succ_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩)
rcases hm.3.1.resolve_left mm with ⟨mm₁, mm₂⟩
rcases Nat.eq_zero_or_pos (size ml) with ml0 | ml0
· rw [ml0, mul_zero, Nat.le_zero] at mm₂
rw [ml0, mm₂] at mm; cases mm (by decide)
have : 2 * size l ≤ size ml + size mr + 1 := by
have := Nat.mul_le_mul_left ratio lr₁
rw [mul_left_comm, mul_add] at this
have := le_trans this (add_le_add_left mr₁ _)
rw [← Nat.succ_mul] at this
exact (mul_le_mul_left (by decide)).1 this
refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩
· refine (mul_le_mul_left (by decide)).1 (le_trans this ?_)
rw [two_mul, Nat.succ_le_iff]
refine add_lt_add_of_lt_of_le ?_ mm₂
simpa using (mul_lt_mul_right ml0).2 (by decide : 1 < 3)
· exact Nat.le_of_lt_succ (Valid'.node4L_lemma₁ lr₂ mr₂ mm₁)
· exact Valid'.node4L_lemma₂ mr₂
· exact Valid'.node4L_lemma₃ mr₁ mm₁
· exact Valid'.node4L_lemma₄ lr₁ mr₂ mm₁
· exact Valid'.node4L_lemma₅ lr₂ mr₁ mm₂
theorem Valid'.rotateL_lemma₁ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (hb₂ : c ≤ 3 * b) : a ≤ 3 * b := by
omega
theorem Valid'.rotateL_lemma₂ {a b c : ℕ} (H3 : 2 * (b + c) ≤ 9 * a + 3) (h : b < 2 * c) :
b < 3 * a + 1 := by omega
theorem Valid'.rotateL_lemma₃ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (h : b < 2 * c) : a + b < 3 * c := by
omega
theorem Valid'.rotateL_lemma₄ {a b : ℕ} (H3 : 2 * b ≤ 9 * a + 3) : 3 * b ≤ 16 * a + 9 := by
omega
theorem Valid'.rotateL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H1 : ¬size l + size r ≤ 1) (H2 : delta * size l < size r)
(H3 : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@rotateL α l x r) o₂ := by
obtain - | ⟨rs, rl, rx, rr⟩ := r; · cases H2
rw [hr.2.size_eq, Nat.lt_succ_iff] at H2
rw [hr.2.size_eq] at H3
replace H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2 :=
H3.imp (@Nat.le_of_add_le_add_right _ 2 _) Nat.le_of_succ_le_succ
have H3_0 : size l = 0 → size rl + size rr ≤ 2 := by
intro l0; rw [l0] at H3
exact
(or_iff_right_of_imp fun h => (mul_le_mul_left (by decide)).1 (le_trans h (by decide))).1 H3
have H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3 := fun l0 : 1 ≤ size l =>
(or_iff_left_of_imp <| by omega).1 H3
have ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1 := by omega
have hlp : size l > 0 → ¬size rl + size rr ≤ 1 := fun l0 hb =>
absurd (le_trans (le_trans (Nat.mul_le_mul_left _ l0) H2) hb) (by decide)
rw [Ordnode.rotateL_node]; split_ifs with h
· have rr0 : size rr > 0 :=
(mul_lt_mul_left (by decide)).1 (lt_of_le_of_lt (Nat.zero_le _) h : ratio * 0 < _)
suffices BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr) by
exact hl.node3L hr.left hr.right this.1 this.2
rcases Nat.eq_zero_or_pos (size l) with l0 | l0
· rw [l0]; replace H3 := H3_0 l0
have := hr.3.1
rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0
· rw [rl0] at this ⊢
rw [le_antisymm (balancedSz_zero.1 this.symm) rr0]
decide
have rr1 : size rr = 1 := le_antisymm (ablem rl0 H3) rr0
rw [add_comm] at H3
rw [rr1, show size rl = 1 from le_antisymm (ablem rr0 H3) rl0]
decide
replace H3 := H3p l0
rcases hr.3.1.resolve_left (hlp l0) with ⟨_, hb₂⟩
refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩
· exact Valid'.rotateL_lemma₁ H2 hb₂
· exact Nat.le_of_lt_succ (Valid'.rotateL_lemma₂ H3 h)
· exact Valid'.rotateL_lemma₃ H2 h
· exact
le_trans hb₂
(Nat.mul_le_mul_left _ <| le_trans (Nat.le_add_left _ _) (Nat.le_add_right _ _))
· rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0
· rw [rl0, not_lt, Nat.le_zero, Nat.mul_eq_zero] at h
replace h := h.resolve_left (by decide)
rw [rl0, h, Nat.le_zero, Nat.mul_eq_zero] at H2
rw [hr.2.size_eq, rl0, h, H2.resolve_left (by decide)] at H1
cases H1 (by decide)
refine hl.node4L hr.left hr.right rl0 ?_
rcases Nat.eq_zero_or_pos (size l) with l0 | l0
· replace H3 := H3_0 l0
rcases Nat.eq_zero_or_pos (size rr) with rr0 | rr0
· have := hr.3.1
rw [rr0] at this
exact Or.inl ⟨l0, le_antisymm (balancedSz_zero.1 this) rl0, rr0.symm ▸ zero_le_one⟩
exact Or.inl ⟨l0, le_antisymm (ablem rr0 <| by rwa [add_comm]) rl0, ablem rl0 H3⟩
exact
Or.inr ⟨l0, not_lt.1 h, H2, Valid'.rotateL_lemma₄ (H3p l0), (hr.3.1.resolve_left (hlp l0)).1⟩
theorem Valid'.rotateR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H1 : ¬size l + size r ≤ 1) (H2 : delta * size r < size l)
(H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@rotateR α l x r) o₂ := by
refine Valid'.dual_iff.2 ?_
rw [dual_rotateR]
refine hr.dual.rotateL hl.dual ?_ ?_ ?_
· rwa [size_dual, size_dual, add_comm]
· rwa [size_dual, size_dual]
· rwa [size_dual, size_dual]
theorem Valid'.balance'_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H₁ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3)
(H₂ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balance' α l x r) o₂ := by
rw [balance']; split_ifs with h h_1 h_2
· exact hl.node' hr (Or.inl h)
· exact hl.rotateL hr h h_1 H₁
· exact hl.rotateR hr h h_2 H₂
· exact hl.node' hr (Or.inr ⟨not_lt.1 h_2, not_lt.1 h_1⟩)
theorem Valid'.balance'_lemma {α l l' r r'} (H1 : BalancedSz l' r')
(H2 : Nat.dist (@size α l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l') :
2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3 := by
suffices @size α r ≤ 3 * (size l + 1) by omega
rcases H2 with (⟨hl, rfl⟩ | ⟨hr, rfl⟩) <;> rcases H1 with (h | ⟨_, h₂⟩)
· exact le_trans (Nat.le_add_left _ _) (le_trans h (Nat.le_add_left _ _))
· exact
le_trans h₂
(Nat.mul_le_mul_left _ <| le_trans (Nat.dist_tri_right _ _) (Nat.add_le_add_left hl _))
· exact
le_trans (Nat.dist_tri_left' _ _)
(le_trans (add_le_add hr (le_trans (Nat.le_add_left _ _) h)) (by omega))
· rw [Nat.mul_succ]
exact le_trans (Nat.dist_tri_right' _ _) (add_le_add h₂ (le_trans hr (by decide)))
theorem Valid'.balance' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : ∃ l' r', BalancedSz l' r' ∧
(Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) :
Valid' o₁ (@balance' α l x r) o₂ :=
let ⟨_, _, H1, H2⟩ := H
Valid'.balance'_aux hl hr (Valid'.balance'_lemma H1 H2) (Valid'.balance'_lemma H1.symm H2.symm)
theorem Valid'.balance {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : ∃ l' r', BalancedSz l' r' ∧
(Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) :
Valid' o₁ (@balance α l x r) o₂ := by
rw [balance_eq_balance' hl.3 hr.3 hl.2 hr.2]; exact hl.balance' hr H
theorem Valid'.balanceL_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H₁ : size l = 0 → size r ≤ 1) (H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l)
(H₃ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balanceL α l x r) o₂ := by
rw [balanceL_eq_balance hl.2 hr.2 H₁ H₂, balance_eq_balance' hl.3 hr.3 hl.2 hr.2]
refine hl.balance'_aux hr (Or.inl ?_) H₃
rcases Nat.eq_zero_or_pos (size r) with r0 | r0
· rw [r0]; exact Nat.zero_le _
rcases Nat.eq_zero_or_pos (size l) with l0 | l0
· rw [l0]; exact le_trans (Nat.mul_le_mul_left _ (H₁ l0)) (by decide)
replace H₂ : _ ≤ 3 * _ := H₂ l0 r0; omega
theorem Valid'.balanceL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨
∃ r', Raised (size r) r' ∧ BalancedSz (size l) r') :
Valid' o₁ (@balanceL α l x r) o₂ := by
rw [balanceL_eq_balance' hl.3 hr.3 hl.2 hr.2 H]
refine hl.balance' hr ?_
rcases H with (⟨l', e, H⟩ | ⟨r', e, H⟩)
· exact ⟨_, _, H, Or.inl ⟨e.dist_le', rfl⟩⟩
· exact ⟨_, _, H, Or.inr ⟨e.dist_le, rfl⟩⟩
theorem Valid'.balanceR_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H₁ : size r = 0 → size l ≤ 1) (H₂ : 1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r)
(H₃ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@balanceR α l x r) o₂ := by
rw [Valid'.dual_iff, dual_balanceR]
have := hr.dual.balanceL_aux hl.dual
rw [size_dual, size_dual] at this
exact this H₁ H₂ H₃
theorem Valid'.balanceR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨
∃ r', Raised r' (size r) ∧ BalancedSz (size l) r') :
Valid' o₁ (@balanceR α l x r) o₂ := by
rw [Valid'.dual_iff, dual_balanceR]; exact hr.dual.balanceL hl.dual (balance_sz_dual H)
theorem Valid'.eraseMax_aux {s l x r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) :
Valid' o₁ (@eraseMax α (.node' l x r)) ↑(findMax' x r) ∧
size (.node' l x r) = size (eraseMax (.node' l x r)) + 1 := by
have := H.2.eq_node'; rw [this] at H; clear this
induction r generalizing l x o₁ with
| nil => exact ⟨H.left, rfl⟩
| node rs rl rx rr _ IHrr =>
have := H.2.2.2.eq_node'; rw [this] at H ⊢
rcases IHrr H.right with ⟨h, e⟩
refine ⟨Valid'.balanceL H.left h (Or.inr ⟨_, Or.inr e, H.3.1⟩), ?_⟩
rw [eraseMax, size_balanceL H.3.2.1 h.3 H.2.2.1 h.2 (Or.inr ⟨_, Or.inr e, H.3.1⟩)]
rw [size_node, e]; rfl
theorem Valid'.eraseMin_aux {s l} {x : α} {r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) :
Valid' ↑(findMin' l x) (@eraseMin α (.node' l x r)) o₂ ∧
size (.node' l x r) = size (eraseMin (.node' l x r)) + 1 := by
have := H.dual.eraseMax_aux
rwa [← dual_node', size_dual, ← dual_eraseMin, size_dual, ← Valid'.dual_iff, findMax'_dual]
at this
theorem eraseMin.valid : ∀ {t}, @Valid α _ t → Valid (eraseMin t)
| nil, _ => valid_nil
| node _ l x r, h => by rw [h.2.eq_node']; exact h.eraseMin_aux.1.valid
theorem eraseMax.valid {t} (h : @Valid α _ t) : Valid (eraseMax t) := by
rw [Valid.dual_iff, dual_eraseMax]; exact eraseMin.valid h.dual
theorem Valid'.glue_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂)
(sep : l.All fun x => r.All fun y => x < y) (bal : BalancedSz (size l) (size r)) :
Valid' o₁ (@glue α l r) o₂ ∧ size (glue l r) = size l + size r := by
obtain - | ⟨ls, ll, lx, lr⟩ := l; · exact ⟨hr, (zero_add _).symm⟩
obtain - | ⟨rs, rl, rx, rr⟩ := r; · exact ⟨hl, rfl⟩
dsimp [glue]; split_ifs
· rw [splitMax_eq]
· obtain ⟨v, e⟩ := Valid'.eraseMax_aux hl
suffices H : _ by
refine ⟨Valid'.balanceR v (hr.of_gt ?_ ?_) H, ?_⟩
· refine findMax'_all (P := fun a : α => Bounded nil (a : WithTop α) o₂)
lx lr hl.1.2.to_nil (sep.2.2.imp ?_)
exact fun x h => hr.1.2.to_nil.mono_left (le_of_lt h.2.1)
· exact @findMax'_all _ (fun a => All (· > a) (.node rs rl rx rr)) lx lr sep.2.1 sep.2.2
· rw [size_balanceR v.3 hr.3 v.2 hr.2 H, add_right_comm, ← e, hl.2.1]; rfl
refine Or.inl ⟨_, Or.inr e, ?_⟩
rwa [hl.2.eq_node'] at bal
· rw [splitMin_eq]
· obtain ⟨v, e⟩ := Valid'.eraseMin_aux hr
suffices H : _ by
refine ⟨Valid'.balanceL (hl.of_lt ?_ ?_) v H, ?_⟩
· refine @findMin'_all (P := fun a : α => Bounded nil o₁ (a : WithBot α))
_ rl rx (sep.2.1.1.imp ?_) hr.1.1.to_nil
exact fun y h => hl.1.1.to_nil.mono_right (le_of_lt h)
· exact
@findMin'_all _ (fun a => All (· < a) (.node ls ll lx lr)) rl rx
(all_iff_forall.2 fun x hx => sep.imp fun y hy => all_iff_forall.1 hy.1 _ hx)
(sep.imp fun y hy => hy.2.1)
· rw [size_balanceL hl.3 v.3 hl.2 v.2 H, add_assoc, ← e, hr.2.1]; rfl
refine Or.inr ⟨_, Or.inr e, ?_⟩
rwa [hr.2.eq_node'] at bal
theorem Valid'.glue {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) :
BalancedSz (size l) (size r) →
Valid' o₁ (@glue α l r) o₂ ∧ size (@glue α l r) = size l + size r :=
Valid'.glue_aux (hl.trans_right hr.1) (hr.trans_left hl.1) (hl.1.to_sep hr.1)
theorem Valid'.merge_lemma {a b c : ℕ} (h₁ : 3 * a < b + c + 1) (h₂ : b ≤ 3 * c) :
2 * (a + b) ≤ 9 * c + 5 := by omega
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
(hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
(h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
rw [hl.2.1] at e
rw [hl.2.1, hr.2.1, delta] at h
rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · omega
suffices H₂ : _ by
suffices H₁ : _ by
refine ⟨Valid'.balanceL_aux v hr.right H₁ H₂ ?_, ?_⟩
· rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
· rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
abel
· rw [e, add_right_comm]; rintro ⟨⟩
intro _ _; rw [e]; unfold delta at hr₂ ⊢; omega
theorem Valid'.merge_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂)
(sep : l.All fun x => r.All fun y => x < y) :
Valid' o₁ (@merge α l r) o₂ ∧ size (merge l r) = size l + size r := by
induction l generalizing o₁ o₂ r with
| nil => exact ⟨hr, (zero_add _).symm⟩
| node ls ll lx lr _ IHlr => ?_
induction r generalizing o₁ o₂ with
| nil => exact ⟨hl, rfl⟩
| node rs rl rx rr IHrl _ => ?_
rw [merge_node]; split_ifs with h h_1
· obtain ⟨v, e⟩ := IHrl (hl.of_lt hr.1.1.to_nil <| sep.imp fun x h => h.2.1) hr.left
(sep.imp fun x h => h.1)
exact Valid'.merge_aux₁ hl hr h v e
· obtain ⟨v, e⟩ := IHlr hl.right (hr.of_gt hl.1.2.to_nil sep.2.1) sep.2.2
have := Valid'.merge_aux₁ hr.dual hl.dual h_1 v.dual
rw [size_dual, add_comm, size_dual, ← dual_balanceR, ← Valid'.dual_iff, size_dual,
add_comm rs] at this
exact this e
· refine Valid'.glue_aux hl hr sep (Or.inr ⟨not_lt.1 h_1, not_lt.1 h⟩)
theorem Valid.merge {l r} (hl : Valid l) (hr : Valid r)
(sep : l.All fun x => r.All fun y => x < y) : Valid (@merge α l r) :=
(Valid'.merge_aux hl hr sep).1
theorem insertWith.valid_aux [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α)
(hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) :
∀ {t o₁ o₂},
Valid' o₁ t o₂ →
Bounded nil o₁ x →
Bounded nil x o₂ →
Valid' o₁ (insertWith f x t) o₂ ∧ Raised (size t) (size (insertWith f x t))
| nil, _, _, _, bl, br => ⟨valid'_singleton bl br, Or.inr rfl⟩
| node sz l y r, o₁, o₂, h, bl, br => by
rw [insertWith, cmpLE]
split_ifs with h_1 h_2 <;> dsimp only
· rcases h with ⟨⟨lx, xr⟩, hs, hb⟩
rcases hf _ ⟨h_1, h_2⟩ with ⟨xf, fx⟩
refine
⟨⟨⟨lx.mono_right (le_trans h_2 xf), xr.mono_left (le_trans fx h_1)⟩, hs, hb⟩, Or.inl rfl⟩
· rcases insertWith.valid_aux f x hf h.left bl (lt_of_le_not_le h_1 h_2) with ⟨vl, e⟩
suffices H : _ by
refine ⟨vl.balanceL h.right H, ?_⟩
rw [size_balanceL vl.3 h.3.2.2 vl.2 h.2.2.2 H, h.2.size_eq]
exact (e.add_right _).add_right _
exact Or.inl ⟨_, e, h.3.1⟩
· have : y < x := lt_of_le_not_le ((total_of (· ≤ ·) _ _).resolve_left h_1) h_1
rcases insertWith.valid_aux f x hf h.right this br with ⟨vr, e⟩
suffices H : _ by
refine ⟨h.left.balanceR vr H, ?_⟩
rw [size_balanceR h.3.2.1 vr.3 h.2.2.1 vr.2 H, h.2.size_eq]
exact (e.add_left _).add_right _
exact Or.inr ⟨_, e, h.3.1⟩
theorem insertWith.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α)
(hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) {t} (h : Valid t) : Valid (insertWith f x t) :=
(insertWith.valid_aux _ _ hf h ⟨⟩ ⟨⟩).1
theorem insert_eq_insertWith [DecidableLE α] (x : α) :
∀ t, Ordnode.insert x t = insertWith (fun _ => x) x t
| nil => rfl
| node _ l y r => by
unfold Ordnode.insert insertWith; cases cmpLE x y <;> simp [insert_eq_insertWith]
theorem insert.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) {t} (h : Valid t) :
Valid (Ordnode.insert x t) := by
rw [insert_eq_insertWith]; exact insertWith.valid _ _ (fun _ _ => ⟨le_rfl, le_rfl⟩) h
theorem insert'_eq_insertWith [DecidableLE α] (x : α) :
∀ t, insert' x t = insertWith id x t
| nil => rfl
| node _ l y r => by
unfold insert' insertWith; cases cmpLE x y <;> simp [insert'_eq_insertWith]
theorem insert'.valid [IsTotal α (· ≤ ·)] [DecidableLE α]
(x : α) {t} (h : Valid t) : Valid (insert' x t) := by
rw [insert'_eq_insertWith]; exact insertWith.valid _ _ (fun _ => id) h
theorem Valid'.map_aux {β} [Preorder β] {f : α → β} (f_strict_mono : StrictMono f) {t a₁ a₂}
(h : Valid' a₁ t a₂) :
Valid' (Option.map f a₁) (map f t) (Option.map f a₂) ∧ (map f t).size = t.size := by
induction t generalizing a₁ a₂ with
| nil =>
simp only [map, size_nil, and_true]; apply valid'_nil
cases a₁; · trivial
cases a₂; · trivial
simp only [Option.map, Bounded]
exact f_strict_mono h.ord
| node _ _ _ _ t_ih_l t_ih_r =>
have t_ih_l' := t_ih_l h.left
have t_ih_r' := t_ih_r h.right
clear t_ih_l t_ih_r
obtain ⟨t_l_valid, t_l_size⟩ := t_ih_l'
obtain ⟨t_r_valid, t_r_size⟩ := t_ih_r'
simp only [map, size_node, and_true]
constructor
· exact And.intro t_l_valid.ord t_r_valid.ord
· constructor
· rw [t_l_size, t_r_size]; exact h.sz.1
· constructor
· exact t_l_valid.sz
· exact t_r_valid.sz
· constructor
· rw [t_l_size, t_r_size]; exact h.bal.1
· constructor
· exact t_l_valid.bal
· exact t_r_valid.bal
theorem map.valid {β} [Preorder β] {f : α → β} (f_strict_mono : StrictMono f) {t} (h : Valid t) :
Valid (map f t) :=
(Valid'.map_aux f_strict_mono h).1
theorem Valid'.erase_aux [DecidableLE α] (x : α) {t a₁ a₂} (h : Valid' a₁ t a₂) :
Valid' a₁ (erase x t) a₂ ∧ Raised (erase x t).size t.size := by
induction t generalizing a₁ a₂ with
| nil =>
simpa [erase, Raised]
| node _ t_l t_x t_r t_ih_l t_ih_r =>
simp only [erase, size_node]
have t_ih_l' := t_ih_l h.left
have t_ih_r' := t_ih_r h.right
clear t_ih_l t_ih_r
obtain ⟨t_l_valid, t_l_size⟩ := t_ih_l'
obtain ⟨t_r_valid, t_r_size⟩ := t_ih_r'
cases cmpLE x t_x <;> rw [h.sz.1]
· suffices h_balanceable : _ by
constructor
· exact Valid'.balanceR t_l_valid h.right h_balanceable
· rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz h_balanceable]
repeat apply Raised.add_right
exact t_l_size
left; exists t_l.size; exact And.intro t_l_size h.bal.1
· have h_glue := Valid'.glue h.left h.right h.bal.1
obtain ⟨h_glue_valid, h_glue_sized⟩ := h_glue
constructor
· exact h_glue_valid
· right; rw [h_glue_sized]
· suffices h_balanceable : _ by
constructor
· exact Valid'.balanceL h.left t_r_valid h_balanceable
· rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz h_balanceable]
apply Raised.add_right
apply Raised.add_left
exact t_r_size
right; exists t_r.size; exact And.intro t_r_size h.bal.1
theorem erase.valid [DecidableLE α] (x : α) {t} (h : Valid t) : Valid (erase x t) :=
(Valid'.erase_aux x h).1
theorem size_erase_of_mem [DecidableLE α] {x : α} {t a₁ a₂} (h : Valid' a₁ t a₂)
(h_mem : x ∈ t) : size (erase x t) = size t - 1 := by
induction t generalizing a₁ a₂ with
| nil =>
contradiction
| node _ t_l t_x t_r t_ih_l t_ih_r =>
have t_ih_l' := t_ih_l h.left
have t_ih_r' := t_ih_r h.right
clear t_ih_l t_ih_r
dsimp only [Membership.mem, mem] at h_mem
unfold erase
revert h_mem; cases cmpLE x t_x <;> intro h_mem <;> dsimp only at h_mem ⊢
· have t_ih_l := t_ih_l' h_mem
clear t_ih_l' t_ih_r'
have t_l_h := Valid'.erase_aux x h.left
obtain ⟨t_l_valid, t_l_size⟩ := t_l_h
rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz
(Or.inl (Exists.intro t_l.size (And.intro t_l_size h.bal.1)))]
rw [t_ih_l, h.sz.1]
have h_pos_t_l_size := pos_size_of_mem h.left.sz h_mem
revert h_pos_t_l_size; rcases t_l.size with - | t_l_size <;> intro h_pos_t_l_size
· cases h_pos_t_l_size
· simp [Nat.add_right_comm]
· rw [(Valid'.glue h.left h.right h.bal.1).2, h.sz.1]; rfl
· have t_ih_r := t_ih_r' h_mem
clear t_ih_l' t_ih_r'
have t_r_h := Valid'.erase_aux x h.right
obtain ⟨t_r_valid, t_r_size⟩ := t_r_h
rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz
(Or.inr (Exists.intro t_r.size (And.intro t_r_size h.bal.1)))]
rw [t_ih_r, h.sz.1]
have h_pos_t_r_size := pos_size_of_mem h.right.sz h_mem
revert h_pos_t_r_size; rcases t_r.size with - | t_r_size <;> intro h_pos_t_r_size
· cases h_pos_t_r_size
· simp [Nat.add_assoc]
end Valid
end Ordnode
/-- An `Ordset α` is a finite set of values, represented as a tree. The operations on this type
maintain that the tree is balanced and correctly stores subtree sizes at each level. The
correctness property of the tree is baked into the type, so all operations on this type are correct
by construction. -/
def Ordset (α : Type*) [Preorder α] :=
{ t : Ordnode α // t.Valid }
namespace Ordset
open Ordnode
variable [Preorder α]
/-- O(1). The empty set. -/
nonrec def nil : Ordset α :=
⟨nil, ⟨⟩, ⟨⟩, ⟨⟩⟩
/-- O(1). Get the size of the set. -/
def size (s : Ordset α) : ℕ :=
s.1.size
/-- O(1). Construct a singleton set containing value `a`. -/
protected def singleton (a : α) : Ordset α :=
⟨singleton a, valid_singleton⟩
instance instEmptyCollection : EmptyCollection (Ordset α) :=
⟨nil⟩
instance instInhabited : Inhabited (Ordset α) :=
⟨nil⟩
instance instSingleton : Singleton α (Ordset α) :=
⟨Ordset.singleton⟩
/-- O(1). Is the set empty? -/
def Empty (s : Ordset α) : Prop :=
s = ∅
theorem empty_iff {s : Ordset α} : s = ∅ ↔ s.1.empty :=
⟨fun h => by cases h; exact rfl,
fun h => by cases s with | mk s_val _ => cases s_val <;> [rfl; cases h]⟩
instance Empty.instDecidablePred : DecidablePred (@Empty α _) :=
fun _ => decidable_of_iff' _ empty_iff
/-- O(log n). Insert an element into the set, preserving balance and the BST property.
If an equivalent element is already in the set, this replaces it. -/
protected def insert [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) (s : Ordset α) :
Ordset α :=
⟨Ordnode.insert x s.1, insert.valid _ s.2⟩
instance instInsert [IsTotal α (· ≤ ·)] [DecidableLE α] : Insert α (Ordset α) :=
⟨Ordset.insert⟩
/-- O(log n). Insert an element into the set, preserving balance and the BST property.
If an equivalent element is already in the set, the set is returned as is. -/
nonrec def insert' [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) (s : Ordset α) :
Ordset α :=
⟨insert' x s.1, insert'.valid _ s.2⟩
section
variable [DecidableLE α]
/-- O(log n). Does the set contain the element `x`? That is,
is there an element that is equivalent to `x` in the order? -/
def mem (x : α) (s : Ordset α) : Bool :=
x ∈ s.val
/-- O(log n). Retrieve an element in the set that is equivalent to `x` in the order,
if it exists. -/
def find (x : α) (s : Ordset α) : Option α :=
Ordnode.find x s.val
instance instMembership : Membership α (Ordset α) :=
⟨fun s x => mem x s⟩
instance mem.decidable (x : α) (s : Ordset α) : Decidable (x ∈ s) :=
instDecidableEqBool _ _
theorem pos_size_of_mem {x : α} {t : Ordset α} (h_mem : x ∈ t) : 0 < size t := by
simp? [Membership.mem, mem] at h_mem says
simp only [Membership.mem, mem, Bool.decide_eq_true] at h_mem
apply Ordnode.pos_size_of_mem t.property.sz h_mem
end
/-- O(log n). Remove an element from the set equivalent to `x`. Does nothing if there
is no such element. -/
def erase [DecidableLE α] (x : α) (s : Ordset α) : Ordset α :=
⟨Ordnode.erase x s.val, Ordnode.erase.valid x s.property⟩
/-- O(n). Map a function across a tree, without changing the structure. -/
def map {β} [Preorder β] (f : α → β) (f_strict_mono : StrictMono f) (s : Ordset α) : Ordset β :=
⟨Ordnode.map f s.val, Ordnode.map.valid f_strict_mono s.property⟩
end Ordset
| Mathlib/Data/Ordmap/Ordset.lean | 1,083 | 1,085 | |
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.EqToHom
/-!
# Functors from the category of the ordered set `ℕ`
In this file, we provide a constructor `Functor.ofSequence`
for functors `ℕ ⥤ C` which takes as an input a sequence
of morphisms `f : X n ⟶ X (n + 1)` for all `n : ℕ`.
We also provide a constructor `NatTrans.ofSequence` for natural
transformations between functors `ℕ ⥤ C` which allows to check
the naturality condition only for morphisms `n ⟶ n + 1`.
The duals of the above for functors `ℕᵒᵖ ⥤ C` are given by `Functor.ofOpSequence` and
`NatTrans.ofOpSequence`.
-/
namespace CategoryTheory
open Category
variable {C : Type*} [Category C]
namespace Functor
variable {X : ℕ → C} (f : ∀ n, X n ⟶ X (n + 1))
namespace OfSequence
lemma congr_f (i j : ℕ) (h : i = j) :
f i = eqToHom (by rw [h]) ≫ f j ≫ eqToHom (by rw [h]) := by
subst h
simp
/-- The morphism `X i ⟶ X j` obtained by composing morphisms of
the form `X n ⟶ X (n + 1)` when `i ≤ j`. -/
def map : ∀ {X : ℕ → C} (_ : ∀ n, X n ⟶ X (n + 1)) (i j : ℕ), i ≤ j → (X i ⟶ X j)
| _, _, 0, 0 => fun _ ↦ 𝟙 _
| _, f, 0, 1 => fun _ ↦ f 0
| _, f, 0, l + 1 => fun _ ↦ f 0 ≫ map (fun n ↦ f (n + 1)) 0 l (by omega)
| _, _, _ + 1, 0 => nofun
| _, f, k + 1, l + 1 => fun _ ↦ map (fun n ↦ f (n + 1)) k l (by omega)
lemma map_id (i : ℕ) : map f i i (by omega) = 𝟙 _ := by
revert X f
induction i with
| zero => intros; rfl
| succ _ hi =>
intro X f
apply hi
lemma map_le_succ (i : ℕ) : map f i (i + 1) (by omega) = f i := by
revert X f
induction i with
| zero => intros; rfl
| succ _ hi =>
intro X f
| apply hi
@[reassoc]
lemma map_comp (i j k : ℕ) (hij : i ≤ j) (hjk : j ≤ k) :
map f i k (hij.trans hjk) = map f i j hij ≫ map f j k hjk := by
revert X f j k
induction i with
| zero =>
intros X f j
revert X f
induction j with
| zero =>
intros X f k hij hjk
rw [map_id, id_comp]
| succ j hj =>
rintro X f (_|_|k) hij hjk
· omega
· obtain rfl : j = 0 := by omega
rw [map_id, comp_id]
· simp only [map, Nat.reduceAdd]
rw [hj (fun n ↦ f (n + 1)) (k + 1) (by omega) (by omega)]
obtain _|j := j
all_goals simp [map]
| succ i hi =>
rintro X f (_|j) (_|k)
· omega
· omega
· omega
| Mathlib/CategoryTheory/Functor/OfSequence.lean | 65 | 92 |
/-
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.CharP.Defs
import Mathlib.Algebra.GeomSum
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.Algebra.MvPolynomial.Equiv
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.RingTheory.Noetherian.Basic
/-!
# Ring-theoretic supplement of Algebra.Polynomial.
## Main results
* `MvPolynomial.isDomain`:
If a ring is an integral domain, then so is its polynomial ring over finitely many variables.
* `Polynomial.isNoetherianRing`:
Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring.
-/
noncomputable section
open Polynomial
open Finset
universe u v w
variable {R : Type u} {S : Type*}
namespace Polynomial
section Semiring
variable [Semiring R]
instance instCharP (p : ℕ) [h : CharP R p] : CharP R[X] p :=
let ⟨h⟩ := h
⟨fun n => by rw [← map_natCast C, ← C_0, C_inj, h]⟩
instance instExpChar (p : ℕ) [h : ExpChar R p] : ExpChar R[X] p := by
cases h; exacts [ExpChar.zero, ExpChar.prime ‹_›]
variable (R)
/-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/
def degreeLE (n : WithBot ℕ) : Submodule R R[X] :=
⨅ k : ℕ, ⨅ _ : ↑k > n, LinearMap.ker (lcoeff R k)
/-- The `R`-submodule of `R[X]` consisting of polynomials of degree < `n`. -/
def degreeLT (n : ℕ) : Submodule R R[X] :=
⨅ k : ℕ, ⨅ (_ : k ≥ n), LinearMap.ker (lcoeff R k)
variable {R}
theorem mem_degreeLE {n : WithBot ℕ} {f : R[X]} : f ∈ degreeLE R n ↔ degree f ≤ n := by
simp only [degreeLE, Submodule.mem_iInf, degree_le_iff_coeff_zero, LinearMap.mem_ker]; rfl
@[mono]
theorem degreeLE_mono {m n : WithBot ℕ} (H : m ≤ n) : degreeLE R m ≤ degreeLE R n := fun _ hf =>
mem_degreeLE.2 (le_trans (mem_degreeLE.1 hf) H)
theorem degreeLE_eq_span_X_pow [DecidableEq R] {n : ℕ} :
degreeLE R n = Submodule.span R ↑((Finset.range (n + 1)).image fun n => (X : R[X]) ^ n) := by
apply le_antisymm
· intro p hp
replace hp := mem_degreeLE.1 hp
rw [← Polynomial.sum_monomial_eq p, Polynomial.sum]
refine Submodule.sum_mem _ fun k hk => ?_
have := WithBot.coe_le_coe.1 (Finset.sup_le_iff.1 hp k hk)
rw [← C_mul_X_pow_eq_monomial, C_mul']
refine
Submodule.smul_mem _ _
(Submodule.subset_span <|
Finset.mem_coe.2 <|
Finset.mem_image.2 ⟨_, Finset.mem_range.2 (Nat.lt_succ_of_le this), rfl⟩)
rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff]
intro k hk
apply mem_degreeLE.2
exact
(degree_X_pow_le _).trans (WithBot.coe_le_coe.2 <| Nat.le_of_lt_succ <| Finset.mem_range.1 hk)
theorem mem_degreeLT {n : ℕ} {f : R[X]} : f ∈ degreeLT R n ↔ degree f < n := by
rw [degreeLT, Submodule.mem_iInf]
conv_lhs => intro i; rw [Submodule.mem_iInf]
rw [degree, Finset.max_eq_sup_coe]
rw [Finset.sup_lt_iff ?_]
rotate_left
· apply WithBot.bot_lt_coe
conv_rhs =>
simp only [mem_support_iff]
intro b
rw [Nat.cast_withBot, WithBot.coe_lt_coe, lt_iff_not_le, Ne, not_imp_not]
rfl
@[mono]
theorem degreeLT_mono {m n : ℕ} (H : m ≤ n) : degreeLT R m ≤ degreeLT R n := fun _ hf =>
mem_degreeLT.2 (lt_of_lt_of_le (mem_degreeLT.1 hf) <| WithBot.coe_le_coe.2 H)
theorem degreeLT_eq_span_X_pow [DecidableEq R] {n : ℕ} :
degreeLT R n = Submodule.span R ↑((Finset.range n).image fun n => X ^ n : Finset R[X]) := by
apply le_antisymm
· intro p hp
replace hp := mem_degreeLT.1 hp
rw [← Polynomial.sum_monomial_eq p, Polynomial.sum]
refine Submodule.sum_mem _ fun k hk => ?_
have := WithBot.coe_lt_coe.1 ((Finset.sup_lt_iff <| WithBot.bot_lt_coe n).1 hp k hk)
rw [← C_mul_X_pow_eq_monomial, C_mul']
refine
Submodule.smul_mem _ _
(Submodule.subset_span <|
Finset.mem_coe.2 <| Finset.mem_image.2 ⟨_, Finset.mem_range.2 this, rfl⟩)
rw [Submodule.span_le, Finset.coe_image, Set.image_subset_iff]
intro k hk
apply mem_degreeLT.2
exact lt_of_le_of_lt (degree_X_pow_le _) (WithBot.coe_lt_coe.2 <| Finset.mem_range.1 hk)
/-- The first `n` coefficients on `degreeLT n` form a linear equivalence with `Fin n → R`. -/
def degreeLTEquiv (R) [Semiring R] (n : ℕ) : degreeLT R n ≃ₗ[R] Fin n → R where
toFun p n := (↑p : R[X]).coeff n
invFun f :=
⟨∑ i : Fin n, monomial i (f i),
(degreeLT R n).sum_mem fun i _ =>
mem_degreeLT.mpr
(lt_of_le_of_lt (degree_monomial_le i (f i)) (WithBot.coe_lt_coe.mpr i.is_lt))⟩
map_add' p q := by
ext
dsimp
rw [coeff_add]
map_smul' x p := by
ext
dsimp
rw [coeff_smul]
rfl
left_inv := by
rintro ⟨p, hp⟩
ext1
simp only [Submodule.coe_mk]
by_cases hp0 : p = 0
· subst hp0
simp only [coeff_zero, LinearMap.map_zero, Finset.sum_const_zero]
rw [mem_degreeLT, degree_eq_natDegree hp0, Nat.cast_lt] at hp
conv_rhs => rw [p.as_sum_range' n hp, ← Fin.sum_univ_eq_sum_range]
right_inv f := by
ext i
simp only [finset_sum_coeff, Submodule.coe_mk]
rw [Finset.sum_eq_single i, coeff_monomial, if_pos rfl]
· rintro j - hji
rw [coeff_monomial, if_neg]
rwa [← Fin.ext_iff]
· intro h
exact (h (Finset.mem_univ _)).elim
theorem degreeLTEquiv_eq_zero_iff_eq_zero {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) :
degreeLTEquiv _ _ ⟨p, hp⟩ = 0 ↔ p = 0 := by simp
theorem eval_eq_sum_degreeLTEquiv {n : ℕ} {p : R[X]} (hp : p ∈ degreeLT R n) (x : R) :
p.eval x = ∑ i, degreeLTEquiv _ _ ⟨p, hp⟩ i * x ^ (i : ℕ) := by
simp_rw [eval_eq_sum]
exact (sum_fin _ (by simp_rw [zero_mul, forall_const]) (mem_degreeLT.mp hp)).symm
theorem degreeLT_succ_eq_degreeLE {n : ℕ} : degreeLT R (n + 1) = degreeLE R n := by
ext x
by_cases x_zero : x = 0
· simp_rw [x_zero, Submodule.zero_mem]
· rw [mem_degreeLT, mem_degreeLE, ← natDegree_lt_iff_degree_lt (by rwa [ne_eq]),
← natDegree_le_iff_degree_le, Nat.lt_succ]
/-- The equivalence between monic polynomials of degree `n` and polynomials of degree less than
`n`, formed by adding a term `X ^ n`. -/
def monicEquivDegreeLT [Nontrivial R] (n : ℕ) :
{ p : R[X] // p.Monic ∧ p.natDegree = n } ≃ degreeLT R n where
toFun p := ⟨p.1.eraseLead, by
rcases p with ⟨p, hp, rfl⟩
simp only [mem_degreeLT]
refine lt_of_lt_of_le ?_ degree_le_natDegree
exact degree_eraseLead_lt (ne_zero_of_ne_zero_of_monic one_ne_zero hp)⟩
invFun := fun p =>
⟨X^n + p.1, monic_X_pow_add (mem_degreeLT.1 p.2), by
rw [natDegree_add_eq_left_of_degree_lt]
· simp
· simp [mem_degreeLT.1 p.2]⟩
left_inv := by
rintro ⟨p, hp, rfl⟩
ext1
simp only
conv_rhs => rw [← eraseLead_add_C_mul_X_pow p]
simp [Monic.def.1 hp, add_comm]
right_inv := by
rintro ⟨p, hp⟩
ext1
simp only
rw [eraseLead_add_of_degree_lt_left]
· simp
· simp [mem_degreeLT.1 hp]
/-- For every polynomial `p` in the span of a set `s : Set R[X]`, there exists a polynomial of
`p' ∈ s` with higher degree. See also `Polynomial.exists_degree_le_of_mem_span_of_finite`. -/
theorem exists_degree_le_of_mem_span {s : Set R[X]} {p : R[X]}
(hs : s.Nonempty) (hp : p ∈ Submodule.span R s) :
∃ p' ∈ s, degree p ≤ degree p' := by
by_contra! h
by_cases hp_zero : p = 0
· rw [hp_zero, degree_zero] at h
rcases hs with ⟨x, hx⟩
exact not_lt_bot (h x hx)
· have : p ∈ degreeLT R (natDegree p) := by
refine (Submodule.span_le.mpr fun p' p'_mem => ?_) hp
rw [SetLike.mem_coe, mem_degreeLT, Nat.cast_withBot]
exact lt_of_lt_of_le (h p' p'_mem) degree_le_natDegree
rwa [mem_degreeLT, Nat.cast_withBot, degree_eq_natDegree hp_zero,
Nat.cast_withBot, lt_self_iff_false] at this
/-- A stronger version of `Polynomial.exists_degree_le_of_mem_span` under the assumption that the
set `s : R[X]` is finite. There exists a polynomial `p' ∈ s` whose degree dominates the degree of
every element of `p ∈ span R s`. -/
theorem exists_degree_le_of_mem_span_of_finite {s : Set R[X]} (s_fin : s.Finite) (hs : s.Nonempty) :
∃ p' ∈ s, ∀ (p : R[X]), p ∈ Submodule.span R s → degree p ≤ degree p' := by
rcases Set.Finite.exists_maximal_wrt degree s s_fin hs with ⟨a, has, hmax⟩
refine ⟨a, has, fun p hp => ?_⟩
rcases exists_degree_le_of_mem_span hs hp with ⟨p', hp'⟩
by_cases h : degree a ≤ degree p'
· rw [← hmax p' hp'.left h] at hp'; exact hp'.right
· exact le_trans hp'.right (not_le.mp h).le
/-- The span of every finite set of polynomials is contained in a `degreeLE n` for some `n`. -/
theorem span_le_degreeLE_of_finite {s : Set R[X]} (s_fin : s.Finite) :
∃ n : ℕ, Submodule.span R s ≤ degreeLE R n := by
by_cases s_emp : s.Nonempty
· rcases exists_degree_le_of_mem_span_of_finite s_fin s_emp with ⟨p', _, hp'max⟩
exact ⟨natDegree p', fun p hp => mem_degreeLE.mpr ((hp'max _ hp).trans degree_le_natDegree)⟩
· rw [Set.not_nonempty_iff_eq_empty] at s_emp
rw [s_emp, Submodule.span_empty]
exact ⟨0, bot_le⟩
/-- The span of every finite set of polynomials is contained in a `degreeLT n` for some `n`. -/
theorem span_of_finite_le_degreeLT {s : Set R[X]} (s_fin : s.Finite) :
∃ n : ℕ, Submodule.span R s ≤ degreeLT R n := by
rcases span_le_degreeLE_of_finite s_fin with ⟨n, _⟩
exact ⟨n + 1, by rwa [degreeLT_succ_eq_degreeLE]⟩
/-- If `R` is a nontrivial ring, the polynomials `R[X]` are not finite as an `R`-module. When `R` is
a field, this is equivalent to `R[X]` being an infinite-dimensional vector space over `R`. -/
theorem not_finite [Nontrivial R] : ¬ Module.Finite R R[X] := by
rw [Module.finite_def, Submodule.fg_def]
push_neg
intro s hs contra
rcases span_le_degreeLE_of_finite hs with ⟨n,hn⟩
have : ((X : R[X]) ^ (n + 1)) ∈ Polynomial.degreeLE R ↑n := by
rw [contra] at hn
exact hn Submodule.mem_top
rw [mem_degreeLE, degree_X_pow, Nat.cast_le, add_le_iff_nonpos_right, nonpos_iff_eq_zero] at this
exact one_ne_zero this
theorem geom_sum_X_comp_X_add_one_eq_sum (n : ℕ) :
(∑ i ∈ range n, (X : R[X]) ^ i).comp (X + 1) =
(Finset.range n).sum fun i : ℕ => (n.choose (i + 1) : R[X]) * X ^ i := by
ext i
trans (n.choose (i + 1) : R); swap
· simp only [finset_sum_coeff, ← C_eq_natCast, coeff_C_mul_X_pow]
rw [Finset.sum_eq_single i, if_pos rfl]
· simp +contextual only [@eq_comm _ i, if_false, eq_self_iff_true,
imp_true_iff]
· simp +contextual only [Nat.lt_add_one_iff, Nat.choose_eq_zero_of_lt,
Nat.cast_zero, Finset.mem_range, not_lt, eq_self_iff_true, if_true, imp_true_iff]
induction' n with n ih generalizing i
· dsimp; simp only [zero_comp, coeff_zero, Nat.cast_zero]
· simp only [geom_sum_succ', ih, add_comp, X_pow_comp, coeff_add, Nat.choose_succ_succ,
Nat.cast_add, coeff_X_add_one_pow]
theorem Monic.geom_sum {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.natDegree) {n : ℕ} (hn : n ≠ 0) :
(∑ i ∈ range n, P ^ i).Monic := by
nontriviality R
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn
rw [geom_sum_succ']
refine (hP.pow _).add_of_left ?_
refine lt_of_le_of_lt (degree_sum_le _ _) ?_
rw [Finset.sup_lt_iff]
· simp only [Finset.mem_range, degree_eq_natDegree (hP.pow _).ne_zero]
simp only [Nat.cast_lt, hP.natDegree_pow]
intro k
exact nsmul_lt_nsmul_left hdeg
· rw [bot_lt_iff_ne_bot, Ne, degree_eq_bot]
exact (hP.pow _).ne_zero
theorem Monic.geom_sum' {P : R[X]} (hP : P.Monic) (hdeg : 0 < P.degree) {n : ℕ} (hn : n ≠ 0) :
(∑ i ∈ range n, P ^ i).Monic :=
hP.geom_sum (natDegree_pos_iff_degree_pos.2 hdeg) hn
theorem monic_geom_sum_X {n : ℕ} (hn : n ≠ 0) : (∑ i ∈ range n, (X : R[X]) ^ i).Monic := by
nontriviality R
apply monic_X.geom_sum _ hn
simp only [natDegree_X, zero_lt_one]
end Semiring
section Ring
variable [Ring R]
/-- Given a polynomial, return the polynomial whose coefficients are in
the ring closure of the original coefficients. -/
def restriction (p : R[X]) : Polynomial (Subring.closure (↑p.coeffs : Set R)) :=
∑ i ∈ p.support,
monomial i
(⟨p.coeff i,
letI := Classical.decEq R
if H : p.coeff i = 0 then H.symm ▸ (Subring.closure _).zero_mem
else Subring.subset_closure (p.coeff_mem_coeffs _ H)⟩ :
Subring.closure (↑p.coeffs : Set R))
@[simp]
theorem coeff_restriction {p : R[X]} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := by
classical
simp only [restriction, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq',
Ne, ite_not]
split_ifs with h
· rw [h]
rfl
· rfl
theorem coeff_restriction' {p : R[X]} {n : ℕ} : (coeff (restriction p) n).1 = coeff p n := by
simp
@[simp]
theorem support_restriction (p : R[X]) : support (restriction p) = support p := by
ext i
simp only [mem_support_iff, not_iff_not, Ne]
conv_rhs => rw [← coeff_restriction]
exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩
@[simp]
theorem map_restriction {R : Type u} [CommRing R] (p : R[X]) :
p.restriction.map (algebraMap _ _) = p :=
ext fun n => by rw [coeff_map, Algebra.algebraMap_ofSubring_apply, coeff_restriction]
@[simp]
theorem degree_restriction {p : R[X]} : (restriction p).degree = p.degree := by simp [degree]
@[simp]
theorem natDegree_restriction {p : R[X]} : (restriction p).natDegree = p.natDegree := by
simp [natDegree]
@[simp]
theorem monic_restriction {p : R[X]} : Monic (restriction p) ↔ Monic p := by
simp only [Monic, leadingCoeff, natDegree_restriction]
rw [← @coeff_restriction _ _ p]
exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩
@[simp]
theorem restriction_zero : restriction (0 : R[X]) = 0 := by
simp only [restriction, Finset.sum_empty, support_zero]
@[simp]
theorem restriction_one : restriction (1 : R[X]) = 1 :=
ext fun i => Subtype.eq <| by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs <;> rfl
variable [Semiring S] {f : R →+* S} {x : S}
theorem eval₂_restriction {p : R[X]} :
eval₂ f x p =
eval₂ (f.comp (Subring.subtype (Subring.closure (p.coeffs : Set R)))) x p.restriction := by
simp only [eval₂_eq_sum, sum, support_restriction, ← @coeff_restriction _ _ p, RingHom.comp_apply,
Subring.coe_subtype]
section ToSubring
variable (p : R[X]) (T : Subring R)
/-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`,
return the corresponding polynomial whose coefficients are in `T`. -/
def toSubring (hp : (↑p.coeffs : Set R) ⊆ T) : T[X] :=
∑ i ∈ p.support,
monomial i
(⟨p.coeff i,
letI := Classical.decEq R
if H : p.coeff i = 0 then H.symm ▸ T.zero_mem else hp (p.coeff_mem_coeffs _ H)⟩ : T)
variable (hp : (↑p.coeffs : Set R) ⊆ T)
@[simp]
theorem coeff_toSubring {n : ℕ} : ↑(coeff (toSubring p T hp) n) = coeff p n := by
classical
simp only [toSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq',
Ne, ite_not]
split_ifs with h
· rw [h]
rfl
· rfl
theorem coeff_toSubring' {n : ℕ} : (coeff (toSubring p T hp) n).1 = coeff p n := by
simp
@[simp]
theorem support_toSubring : support (toSubring p T hp) = support p := by
ext i
simp only [mem_support_iff, not_iff_not, Ne]
conv_rhs => rw [← coeff_toSubring p T hp]
exact ⟨fun H => by rw [H, ZeroMemClass.coe_zero], fun H => Subtype.coe_injective H⟩
@[simp]
theorem degree_toSubring : (toSubring p T hp).degree = p.degree := by simp [degree]
@[simp]
theorem natDegree_toSubring : (toSubring p T hp).natDegree = p.natDegree := by simp [natDegree]
@[simp]
theorem monic_toSubring : Monic (toSubring p T hp) ↔ Monic p := by
simp_rw [Monic, leadingCoeff, natDegree_toSubring, ← coeff_toSubring p T hp]
exact ⟨fun H => by rw [H, OneMemClass.coe_one], fun H => Subtype.coe_injective H⟩
@[simp]
theorem toSubring_zero : toSubring (0 : R[X]) T (by simp [coeffs]) = 0 := by
ext i
simp
@[simp]
theorem toSubring_one :
toSubring (1 : R[X]) T
(Set.Subset.trans coeffs_one <| Finset.singleton_subset_set_iff.2 T.one_mem) =
1 :=
ext fun i => Subtype.eq <| by
rw [coeff_toSubring', coeff_one, coeff_one, apply_ite Subtype.val, ZeroMemClass.coe_zero,
OneMemClass.coe_one]
@[simp]
theorem map_toSubring : (p.toSubring T hp).map (Subring.subtype T) = p := by
ext n
simp [coeff_map]
end ToSubring
variable (T : Subring R)
/-- Given a polynomial whose coefficients are in some subring, return
the corresponding polynomial whose coefficients are in the ambient ring. -/
def ofSubring (p : T[X]) : R[X] :=
∑ i ∈ p.support, monomial i (p.coeff i : R)
theorem coeff_ofSubring (p : T[X]) (n : ℕ) : coeff (ofSubring T p) n = (coeff p n : T) := by
simp only [ofSubring, coeff_monomial, finset_sum_coeff, mem_support_iff, Finset.sum_ite_eq',
ite_eq_right_iff, Ne, ite_not, Classical.not_not, ite_eq_left_iff]
intro h
rw [h, ZeroMemClass.coe_zero]
@[simp]
theorem coeffs_ofSubring {p : T[X]} : (↑(p.ofSubring T).coeffs : Set R) ⊆ T := by
classical
intro i hi
simp only [coeffs, Set.mem_image, mem_support_iff, Ne, Finset.mem_coe,
(Finset.coe_image)] at hi
rcases hi with ⟨n, _, h'n⟩
rw [← h'n, coeff_ofSubring]
exact Subtype.mem (coeff p n : T)
end Ring
end Polynomial
namespace Ideal
open Polynomial
section Semiring
variable [Semiring R]
/-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/
def ofPolynomial (I : Ideal R[X]) : Submodule R R[X] where
carrier := I.carrier
zero_mem' := I.zero_mem
add_mem' := I.add_mem
smul_mem' c x H := by
rw [← C_mul']
exact I.mul_mem_left _ H
variable {I : Ideal R[X]}
theorem mem_ofPolynomial (x) : x ∈ I.ofPolynomial ↔ x ∈ I :=
Iff.rfl
variable (I)
/-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I`
| consisting of polynomials of degree ≤ `n`. -/
def degreeLE (n : WithBot ℕ) : Submodule R R[X] :=
Polynomial.degreeLE R n ⊓ I.ofPolynomial
| Mathlib/RingTheory/Polynomial/Basic.lean | 487 | 489 |
/-
Copyright (c) 2018 Rohan Mitta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Order.Interval.Set.ProjIcc
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Topology.Bornology.Hom
import Mathlib.Topology.EMetricSpace.Lipschitz
import Mathlib.Topology.Maps.Proper.Basic
import Mathlib.Topology.MetricSpace.Basic
import Mathlib.Topology.MetricSpace.Bounded
/-!
# Lipschitz continuous functions
A map `f : α → β` between two (extended) metric spaces is called *Lipschitz continuous*
with constant `K ≥ 0` if for all `x, y` we have `edist (f x) (f y) ≤ K * edist x y`.
For a metric space, the latter inequality is equivalent to `dist (f x) (f y) ≤ K * dist x y`.
There is also a version asserting this inequality only for `x` and `y` in some set `s`.
Finally, `f : α → β` is called *locally Lipschitz continuous* if each `x : α` has a neighbourhood
on which `f` is Lipschitz continuous (with some constant).
In this file we specialize various facts about Lipschitz continuous maps
to the case of (pseudo) metric spaces.
## Implementation notes
The parameter `K` has type `ℝ≥0`. This way we avoid conjunction in the definition and have
coercions both to `ℝ` and `ℝ≥0∞`. Constructors whose names end with `'` take `K : ℝ` as an
argument, and return `LipschitzWith (Real.toNNReal K) f`.
-/
assert_not_exists Basis Ideal
universe u v w x
open Filter Function Set Topology NNReal ENNReal Bornology
variable {α : Type u} {β : Type v} {γ : Type w} {ι : Type x}
theorem lipschitzWith_iff_dist_le_mul [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0}
{f : α → β} : LipschitzWith K f ↔ ∀ x y, dist (f x) (f y) ≤ K * dist x y := by
simp only [LipschitzWith, edist_nndist, dist_nndist]
norm_cast
alias ⟨LipschitzWith.dist_le_mul, LipschitzWith.of_dist_le_mul⟩ := lipschitzWith_iff_dist_le_mul
theorem lipschitzOnWith_iff_dist_le_mul [PseudoMetricSpace α] [PseudoMetricSpace β] {K : ℝ≥0}
{s : Set α} {f : α → β} :
LipschitzOnWith K f s ↔ ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ K * dist x y := by
simp only [LipschitzOnWith, edist_nndist, dist_nndist]
norm_cast
alias ⟨LipschitzOnWith.dist_le_mul, LipschitzOnWith.of_dist_le_mul⟩ :=
lipschitzOnWith_iff_dist_le_mul
namespace LipschitzWith
section Metric
variable [PseudoMetricSpace α] [PseudoMetricSpace β] [PseudoMetricSpace γ] {K : ℝ≥0} {f : α → β}
{x y : α} {r : ℝ}
protected theorem of_dist_le' {K : ℝ} (h : ∀ x y, dist (f x) (f y) ≤ K * dist x y) :
LipschitzWith (Real.toNNReal K) f :=
of_dist_le_mul fun x y =>
le_trans (h x y) <| by gcongr; apply Real.le_coe_toNNReal
protected theorem mk_one (h : ∀ x y, dist (f x) (f y) ≤ dist x y) : LipschitzWith 1 f :=
of_dist_le_mul <| by simpa only [NNReal.coe_one, one_mul] using h
/-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version
doesn't assume `0≤K`. -/
protected theorem of_le_add_mul' {f : α → ℝ} (K : ℝ) (h : ∀ x y, f x ≤ f y + K * dist x y) :
LipschitzWith (Real.toNNReal K) f :=
have I : ∀ x y, f x - f y ≤ K * dist x y := fun x y => sub_le_iff_le_add'.2 (h x y)
LipschitzWith.of_dist_le' fun x y => abs_sub_le_iff.2 ⟨I x y, dist_comm y x ▸ I y x⟩
/-- For functions to `ℝ`, it suffices to prove `f x ≤ f y + K * dist x y`; this version
assumes `0≤K`. -/
protected theorem of_le_add_mul {f : α → ℝ} (K : ℝ≥0) (h : ∀ x y, f x ≤ f y + K * dist x y) :
LipschitzWith K f := by simpa only [Real.toNNReal_coe] using LipschitzWith.of_le_add_mul' K h
protected theorem of_le_add {f : α → ℝ} (h : ∀ x y, f x ≤ f y + dist x y) : LipschitzWith 1 f :=
LipschitzWith.of_le_add_mul 1 <| by simpa only [NNReal.coe_one, one_mul]
protected theorem le_add_mul {f : α → ℝ} {K : ℝ≥0} (h : LipschitzWith K f) (x y) :
f x ≤ f y + K * dist x y :=
sub_le_iff_le_add'.1 <| le_trans (le_abs_self _) <| h.dist_le_mul x y
protected theorem iff_le_add_mul {f : α → ℝ} {K : ℝ≥0} :
LipschitzWith K f ↔ ∀ x y, f x ≤ f y + K * dist x y :=
⟨LipschitzWith.le_add_mul, LipschitzWith.of_le_add_mul K⟩
theorem nndist_le (hf : LipschitzWith K f) (x y : α) : nndist (f x) (f y) ≤ K * nndist x y :=
hf.dist_le_mul x y
theorem dist_le_mul_of_le (hf : LipschitzWith K f) (hr : dist x y ≤ r) : dist (f x) (f y) ≤ K * r :=
(hf.dist_le_mul x y).trans <| by gcongr
theorem mapsTo_closedBall (hf : LipschitzWith K f) (x : α) (r : ℝ) :
MapsTo f (Metric.closedBall x r) (Metric.closedBall (f x) (K * r)) := fun _y hy =>
hf.dist_le_mul_of_le hy
theorem dist_lt_mul_of_lt (hf : LipschitzWith K f) (hK : K ≠ 0) (hr : dist x y < r) :
dist (f x) (f y) < K * r :=
(hf.dist_le_mul x y).trans_lt <| (mul_lt_mul_left <| NNReal.coe_pos.2 hK.bot_lt).2 hr
theorem mapsTo_ball (hf : LipschitzWith K f) (hK : K ≠ 0) (x : α) (r : ℝ) :
MapsTo f (Metric.ball x r) (Metric.ball (f x) (K * r)) := fun _y hy =>
hf.dist_lt_mul_of_lt hK hy
/-- A Lipschitz continuous map is a locally bounded map. -/
def toLocallyBoundedMap (f : α → β) (hf : LipschitzWith K f) : LocallyBoundedMap α β :=
LocallyBoundedMap.ofMapBounded f fun _s hs =>
let ⟨C, hC⟩ := Metric.isBounded_iff.1 hs
Metric.isBounded_iff.2 ⟨K * C, forall_mem_image.2 fun _x hx => forall_mem_image.2 fun _y hy =>
hf.dist_le_mul_of_le (hC hx hy)⟩
@[simp]
theorem coe_toLocallyBoundedMap (hf : LipschitzWith K f) : ⇑(hf.toLocallyBoundedMap f) = f :=
rfl
theorem comap_cobounded_le (hf : LipschitzWith K f) :
comap f (Bornology.cobounded β) ≤ Bornology.cobounded α :=
(hf.toLocallyBoundedMap f).2
/-- The image of a bounded set under a Lipschitz map is bounded. -/
theorem isBounded_image (hf : LipschitzWith K f) {s : Set α} (hs : IsBounded s) :
IsBounded (f '' s) :=
hs.image (toLocallyBoundedMap f hf)
theorem diam_image_le (hf : LipschitzWith K f) (s : Set α) (hs : IsBounded s) :
Metric.diam (f '' s) ≤ K * Metric.diam s :=
Metric.diam_le_of_forall_dist_le (mul_nonneg K.coe_nonneg Metric.diam_nonneg) <|
forall_mem_image.2 fun _x hx =>
forall_mem_image.2 fun _y hy => hf.dist_le_mul_of_le <| Metric.dist_le_diam_of_mem hs hx hy
protected theorem dist_left (y : α) : LipschitzWith 1 (dist · y) :=
LipschitzWith.mk_one fun _ _ => dist_dist_dist_le_left _ _ _
protected theorem dist_right (x : α) : LipschitzWith 1 (dist x) :=
LipschitzWith.of_le_add fun _ _ => dist_triangle_right _ _ _
protected theorem dist : LipschitzWith 2 (Function.uncurry <| @dist α _) := by
rw [← one_add_one_eq_two]
exact LipschitzWith.uncurry LipschitzWith.dist_left LipschitzWith.dist_right
theorem dist_iterate_succ_le_geometric {f : α → α} (hf : LipschitzWith K f) (x n) :
dist (f^[n] x) (f^[n + 1] x) ≤ dist x (f x) * (K : ℝ) ^ n := by
rw [iterate_succ, mul_comm]
simpa only [NNReal.coe_pow] using (hf.iterate n).dist_le_mul x (f x)
theorem _root_.lipschitzWith_max : LipschitzWith 1 fun p : ℝ × ℝ => max p.1 p.2 :=
LipschitzWith.of_le_add fun _ _ => sub_le_iff_le_add'.1 <|
(le_abs_self _).trans (abs_max_sub_max_le_max _ _ _ _)
theorem _root_.lipschitzWith_min : LipschitzWith 1 fun p : ℝ × ℝ => min p.1 p.2 :=
LipschitzWith.of_le_add fun _ _ => sub_le_iff_le_add'.1 <|
(le_abs_self _).trans (abs_min_sub_min_le_max _ _ _ _)
lemma _root_.Real.lipschitzWith_toNNReal : LipschitzWith 1 Real.toNNReal := by
refine lipschitzWith_iff_dist_le_mul.mpr (fun x y ↦ ?_)
simpa only [NNReal.coe_one, dist_prod_same_right, one_mul, Real.dist_eq] using
lipschitzWith_iff_dist_le_mul.mp lipschitzWith_max (x, 0) (y, 0)
lemma cauchySeq_comp (hf : LipschitzWith K f) {u : ℕ → α} (hu : CauchySeq u) :
CauchySeq (f ∘ u) := by
rcases cauchySeq_iff_le_tendsto_0.1 hu with ⟨b, b_nonneg, hb, blim⟩
refine cauchySeq_iff_le_tendsto_0.2 ⟨fun n ↦ K * b n, ?_, ?_, ?_⟩
· exact fun n ↦ mul_nonneg (by positivity) (b_nonneg n)
· exact fun n m N hn hm ↦ hf.dist_le_mul_of_le (hb n m N hn hm)
· rw [← mul_zero (K : ℝ)]
exact blim.const_mul _
end Metric
section EMetric
variable [PseudoEMetricSpace α] {f g : α → ℝ} {Kf Kg : ℝ≥0}
protected theorem max (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) :
LipschitzWith (max Kf Kg) fun x => max (f x) (g x) := by
simpa only [(· ∘ ·), one_mul] using lipschitzWith_max.comp (hf.prodMk hg)
protected theorem min (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) :
LipschitzWith (max Kf Kg) fun x => min (f x) (g x) := by
simpa only [(· ∘ ·), one_mul] using lipschitzWith_min.comp (hf.prodMk hg)
theorem max_const (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => max (f x) a := by
simpa only [max_eq_left (zero_le Kf)] using hf.max (LipschitzWith.const a)
theorem const_max (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => max a (f x) := by
simpa only [max_comm] using hf.max_const a
theorem min_const (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => min (f x) a := by
simpa only [max_eq_left (zero_le Kf)] using hf.min (LipschitzWith.const a)
theorem const_min (hf : LipschitzWith Kf f) (a : ℝ) : LipschitzWith Kf fun x => min a (f x) := by
simpa only [min_comm] using hf.min_const a
end EMetric
protected theorem projIcc {a b : ℝ} (h : a ≤ b) : LipschitzWith 1 (projIcc a b h) :=
((LipschitzWith.id.const_min _).const_max _).subtype_mk _
end LipschitzWith
/-- The preimage of a proper space under a Lipschitz proper map is proper. -/
lemma LipschitzWith.properSpace {X Y : Type*} [PseudoMetricSpace X]
[PseudoMetricSpace Y] [ProperSpace Y] {f : X → Y} (hf : IsProperMap f)
{K : ℝ≥0} (hf' : LipschitzWith K f) : ProperSpace X :=
⟨fun x r ↦ (hf.isCompact_preimage (isCompact_closedBall (f x) (K * r))).of_isClosed_subset
Metric.isClosed_closedBall (hf'.mapsTo_closedBall x r).subset_preimage⟩
namespace Metric
variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s : Set α} {t : Set β}
end Metric
namespace LipschitzOnWith
section Metric
variable [PseudoMetricSpace α] [PseudoMetricSpace β] [PseudoMetricSpace γ]
variable {K : ℝ≥0} {s : Set α} {f : α → β}
|
protected theorem of_dist_le' {K : ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ K * dist x y) :
| Mathlib/Topology/MetricSpace/Lipschitz.lean | 229 | 230 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Patrick Massot, Eric Wieser, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Module.Basic
import Mathlib.LinearAlgebra.Basis.VectorSpace
/-!
# Basic facts about real (semi)normed spaces
In this file we prove some theorems about (semi)normed spaces over real numberes.
## Main results
- `closure_ball`, `frontier_ball`, `interior_closedBall`, `frontier_closedBall`, `interior_sphere`,
`frontier_sphere`: formulas for the closure/interior/frontier
of nontrivial balls and spheres in a real seminormed space;
- `interior_closedBall'`, `frontier_closedBall'`, `interior_sphere'`, `frontier_sphere'`:
similar lemmas assuming that the ambient space is separated and nontrivial instead of `r ≠ 0`.
-/
open Metric Set Function Filter
open scoped NNReal Topology
/-- If `E` is a nontrivial topological module over `ℝ`, then `E` has no isolated points.
This is a particular case of `Module.punctured_nhds_neBot`. -/
instance Real.punctured_nhds_module_neBot {E : Type*} [AddCommGroup E] [TopologicalSpace E]
[ContinuousAdd E] [Nontrivial E] [Module ℝ E] [ContinuousSMul ℝ E] (x : E) : NeBot (𝓝[≠] x) :=
Module.punctured_nhds_neBot ℝ E x
section Seminormed
variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℝ E]
theorem inv_norm_smul_mem_unitClosedBall (x : E) :
‖x‖⁻¹ • x ∈ closedBall (0 : E) 1 := by
simp only [mem_closedBall_zero_iff, norm_smul, norm_inv, norm_norm, ← div_eq_inv_mul,
| div_self_le_one]
@[deprecated (since := "2024-12-01")]
alias inv_norm_smul_mem_closed_unit_ball := inv_norm_smul_mem_unitClosedBall
| Mathlib/Analysis/NormedSpace/Real.lean | 40 | 43 |
/-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.FieldTheory.RatFunc.Defs
import Mathlib.RingTheory.EuclideanDomain
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Polynomial.Content
/-!
# The field structure of rational functions
## Main definitions
Working with rational functions as polynomials:
- `RatFunc.instField` provides a field structure
You can use `IsFractionRing` API to treat `RatFunc` as the field of fractions of polynomials:
* `algebraMap K[X] (RatFunc K)` maps polynomials to rational functions
* `IsFractionRing.algEquiv` maps other fields of fractions of `K[X]` to `RatFunc K`,
in particular:
* `FractionRing.algEquiv K[X] (RatFunc K)` maps the generic field of
fraction construction to `RatFunc K`. Combine this with `AlgEquiv.restrictScalars` to change
the `FractionRing K[X] ≃ₐ[K[X]] RatFunc K` to `FractionRing K[X] ≃ₐ[K] RatFunc K`.
Working with rational functions as fractions:
- `RatFunc.num` and `RatFunc.denom` give the numerator and denominator.
These values are chosen to be coprime and such that `RatFunc.denom` is monic.
Lifting homomorphisms of polynomials to other types, by mapping and dividing, as long
as the homomorphism retains the non-zero-divisor property:
- `RatFunc.liftMonoidWithZeroHom` lifts a `K[X] →*₀ G₀` to
a `RatFunc K →*₀ G₀`, where `[CommRing K] [CommGroupWithZero G₀]`
- `RatFunc.liftRingHom` lifts a `K[X] →+* L` to a `RatFunc K →+* L`,
where `[CommRing K] [Field L]`
- `RatFunc.liftAlgHom` lifts a `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`,
where `[CommRing K] [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]`
This is satisfied by injective homs.
We also have lifting homomorphisms of polynomials to other polynomials,
with the same condition on retaining the non-zero-divisor property across the map:
- `RatFunc.map` lifts `K[X] →* R[X]` when `[CommRing K] [CommRing R]`
- `RatFunc.mapRingHom` lifts `K[X] →+* R[X]` when `[CommRing K] [CommRing R]`
- `RatFunc.mapAlgHom` lifts `K[X] →ₐ[S] R[X]` when
`[CommRing K] [IsDomain K] [CommRing R] [IsDomain R]`
-/
universe u v
noncomputable section
open scoped nonZeroDivisors Polynomial
variable {K : Type u}
namespace RatFunc
section Field
variable [CommRing K]
/-- The zero rational function. -/
protected irreducible_def zero : RatFunc K :=
⟨0⟩
instance : Zero (RatFunc K) :=
⟨RatFunc.zero⟩
theorem ofFractionRing_zero : (ofFractionRing 0 : RatFunc K) = 0 :=
zero_def.symm
/-- Addition of rational functions. -/
protected irreducible_def add : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p + q⟩
instance : Add (RatFunc K) :=
⟨RatFunc.add⟩
theorem ofFractionRing_add (p q : FractionRing K[X]) :
ofFractionRing (p + q) = ofFractionRing p + ofFractionRing q :=
(add_def _ _).symm
/-- Subtraction of rational functions. -/
protected irreducible_def sub : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p - q⟩
instance : Sub (RatFunc K) :=
⟨RatFunc.sub⟩
theorem ofFractionRing_sub (p q : FractionRing K[X]) :
ofFractionRing (p - q) = ofFractionRing p - ofFractionRing q :=
(sub_def _ _).symm
/-- Additive inverse of a rational function. -/
protected irreducible_def neg : RatFunc K → RatFunc K
| ⟨p⟩ => ⟨-p⟩
instance : Neg (RatFunc K) :=
⟨RatFunc.neg⟩
theorem ofFractionRing_neg (p : FractionRing K[X]) :
ofFractionRing (-p) = -ofFractionRing p :=
(neg_def _).symm
/-- The multiplicative unit of rational functions. -/
protected irreducible_def one : RatFunc K :=
⟨1⟩
instance : One (RatFunc K) :=
⟨RatFunc.one⟩
theorem ofFractionRing_one : (ofFractionRing 1 : RatFunc K) = 1 :=
one_def.symm
/-- Multiplication of rational functions. -/
protected irreducible_def mul : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p * q⟩
instance : Mul (RatFunc K) :=
⟨RatFunc.mul⟩
theorem ofFractionRing_mul (p q : FractionRing K[X]) :
ofFractionRing (p * q) = ofFractionRing p * ofFractionRing q :=
(mul_def _ _).symm
section IsDomain
variable [IsDomain K]
/-- Division of rational functions. -/
protected irreducible_def div : RatFunc K → RatFunc K → RatFunc K
| | ⟨p⟩, ⟨q⟩ => ⟨p / q⟩
| Mathlib/FieldTheory/RatFunc/Basic.lean | 131 | 132 |
/-
Copyright (c) 2021 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Order.Lattice
import Mathlib.Data.List.Sort
import Mathlib.Logic.Equiv.Fin.Basic
import Mathlib.Logic.Equiv.Functor
import Mathlib.Data.Fintype.Pigeonhole
import Mathlib.Order.RelSeries
/-!
# Jordan-Hölder Theorem
This file proves the Jordan Hölder theorem for a `JordanHolderLattice`, a class also defined in
this file. Examples of `JordanHolderLattice` include `Subgroup G` if `G` is a group, and
`Submodule R M` if `M` is an `R`-module. Using this approach the theorem need not be proved
separately for both groups and modules, the proof in this file can be applied to both.
## Main definitions
The main definitions in this file are `JordanHolderLattice` and `CompositionSeries`,
and the relation `Equivalent` on `CompositionSeries`
A `JordanHolderLattice` is the class for which the Jordan Hölder theorem is proved. A
Jordan Hölder lattice is a lattice equipped with a notion of maximality, `IsMaximal`, and a notion
of isomorphism of pairs `Iso`. In the example of subgroups of a group, `IsMaximal H K` means that
`H` is a maximal normal subgroup of `K`, and `Iso (H₁, K₁) (H₂, K₂)` means that the quotient
`H₁ / K₁` is isomorphic to the quotient `H₂ / K₂`. `Iso` must be symmetric and transitive and must
satisfy the second isomorphism theorem `Iso (H, H ⊔ K) (H ⊓ K, K)`.
A `CompositionSeries X` is a finite nonempty series of elements of the lattice `X` such that
each element is maximal inside the next. The length of a `CompositionSeries X` is
one less than the number of elements in the series. Note that there is no stipulation
that a series start from the bottom of the lattice and finish at the top.
For a composition series `s`, `s.last` is the largest element of the series,
and `s.head` is the least element.
Two `CompositionSeries X`, `s₁` and `s₂` are equivalent if there is a bijection
`e : Fin s₁.length ≃ Fin s₂.length` such that for any `i`,
`Iso (s₁ i, s₁ i.succ) (s₂ (e i), s₂ (e i.succ))`
## Main theorems
The main theorem is `CompositionSeries.jordan_holder`, which says that if two composition
series have the same least element and the same largest element,
then they are `Equivalent`.
## TODO
Provide instances of `JordanHolderLattice` for subgroups, and potentially for modular lattices.
It is not entirely clear how this should be done. Possibly there should be no global instances
of `JordanHolderLattice`, and the instances should only be defined locally in order to prove
the Jordan-Hölder theorem for modules/groups and the API should be transferred because many of the
theorems in this file will have stronger versions for modules. There will also need to be an API for
mapping composition series across homomorphisms. It is also probably possible to
provide an instance of `JordanHolderLattice` for any `ModularLattice`, and in this case the
Jordan-Hölder theorem will say that there is a well defined notion of length of a modular lattice.
However an instance of `JordanHolderLattice` for a modular lattice will not be able to contain
the correct notion of isomorphism for modules, so a separate instance for modules will still be
required and this will clash with the instance for modular lattices, and so at least one of these
instances should not be a global instance.
> [!NOTE]
> The previous paragraph indicates that the instance of `JordanHolderLattice` for submodules should
> be obtained via `ModularLattice`. This is not the case in `mathlib4`.
> See `JordanHolderModule.instJordanHolderLattice`.
-/
universe u
open Set RelSeries
/-- A `JordanHolderLattice` is the class for which the Jordan Hölder theorem is proved. A
Jordan Hölder lattice is a lattice equipped with a notion of maximality, `IsMaximal`, and a notion
of isomorphism of pairs `Iso`. In the example of subgroups of a group, `IsMaximal H K` means that
`H` is a maximal normal subgroup of `K`, and `Iso (H₁, K₁) (H₂, K₂)` means that the quotient
`H₁ / K₁` is isomorphic to the quotient `H₂ / K₂`. `Iso` must be symmetric and transitive and must
satisfy the second isomorphism theorem `Iso (H, H ⊔ K) (H ⊓ K, K)`.
Examples include `Subgroup G` if `G` is a group, and `Submodule R M` if `M` is an `R`-module.
-/
class JordanHolderLattice (X : Type u) [Lattice X] where
IsMaximal : X → X → Prop
lt_of_isMaximal : ∀ {x y}, IsMaximal x y → x < y
sup_eq_of_isMaximal : ∀ {x y z}, IsMaximal x z → IsMaximal y z → x ≠ y → x ⊔ y = z
isMaximal_inf_left_of_isMaximal_sup :
∀ {x y}, IsMaximal x (x ⊔ y) → IsMaximal y (x ⊔ y) → IsMaximal (x ⊓ y) x
Iso : X × X → X × X → Prop
iso_symm : ∀ {x y}, Iso x y → Iso y x
iso_trans : ∀ {x y z}, Iso x y → Iso y z → Iso x z
second_iso : ∀ {x y}, IsMaximal x (x ⊔ y) → Iso (x, x ⊔ y) (x ⊓ y, y)
namespace JordanHolderLattice
variable {X : Type u} [Lattice X] [JordanHolderLattice X]
theorem isMaximal_inf_right_of_isMaximal_sup {x y : X} (hxz : IsMaximal x (x ⊔ y))
(hyz : IsMaximal y (x ⊔ y)) : IsMaximal (x ⊓ y) y := by
rw [inf_comm]
rw [sup_comm] at hxz hyz
exact isMaximal_inf_left_of_isMaximal_sup hyz hxz
theorem isMaximal_of_eq_inf (x b : X) {a y : X} (ha : x ⊓ y = a) (hxy : x ≠ y) (hxb : IsMaximal x b)
(hyb : IsMaximal y b) : IsMaximal a y := by
have hb : x ⊔ y = b := sup_eq_of_isMaximal hxb hyb hxy
substs a b
exact isMaximal_inf_right_of_isMaximal_sup hxb hyb
theorem second_iso_of_eq {x y a b : X} (hm : IsMaximal x a) (ha : x ⊔ y = a) (hb : x ⊓ y = b) :
Iso (x, a) (b, y) := by substs a b; exact second_iso hm
theorem IsMaximal.iso_refl {x y : X} (h : IsMaximal x y) : Iso (x, y) (x, y) :=
second_iso_of_eq h (sup_eq_right.2 (le_of_lt (lt_of_isMaximal h)))
(inf_eq_left.2 (le_of_lt (lt_of_isMaximal h)))
end JordanHolderLattice
open JordanHolderLattice
attribute [symm] iso_symm
attribute [trans] iso_trans
/-- A `CompositionSeries X` is a finite nonempty series of elements of a
`JordanHolderLattice` such that each element is maximal inside the next. The length of a
`CompositionSeries X` is one less than the number of elements in the series.
Note that there is no stipulation that a series start from the bottom of the lattice and finish at
the top. For a composition series `s`, `s.last` is the largest element of the series,
and `s.head` is the least element.
-/
abbrev CompositionSeries (X : Type u) [Lattice X] [JordanHolderLattice X] : Type u :=
RelSeries (IsMaximal (X := X))
namespace CompositionSeries
variable {X : Type u} [Lattice X] [JordanHolderLattice X]
theorem lt_succ (s : CompositionSeries X) (i : Fin s.length) :
s (Fin.castSucc i) < s (Fin.succ i) :=
lt_of_isMaximal (s.step _)
protected theorem strictMono (s : CompositionSeries X) : StrictMono s :=
Fin.strictMono_iff_lt_succ.2 s.lt_succ
protected theorem injective (s : CompositionSeries X) : Function.Injective s :=
s.strictMono.injective
@[simp]
protected theorem inj (s : CompositionSeries X) {i j : Fin s.length.succ} : s i = s j ↔ i = j :=
s.injective.eq_iff
theorem total {s : CompositionSeries X} {x y : X} (hx : x ∈ s) (hy : y ∈ s) : x ≤ y ∨ y ≤ x := by
rcases Set.mem_range.1 hx with ⟨i, rfl⟩
rcases Set.mem_range.1 hy with ⟨j, rfl⟩
rw [s.strictMono.le_iff_le, s.strictMono.le_iff_le]
exact le_total i j
theorem toList_sorted (s : CompositionSeries X) : s.toList.Sorted (· < ·) :=
List.pairwise_iff_get.2 fun i j h => by
dsimp only [RelSeries.toList]
rw [List.get_ofFn, List.get_ofFn]
exact s.strictMono h
theorem toList_nodup (s : CompositionSeries X) : s.toList.Nodup :=
s.toList_sorted.nodup
/-- Two `CompositionSeries` are equal if they have the same elements. See also `ext_fun`. -/
@[ext]
theorem ext {s₁ s₂ : CompositionSeries X} (h : ∀ x, x ∈ s₁ ↔ x ∈ s₂) : s₁ = s₂ :=
toList_injective <|
List.eq_of_perm_of_sorted
(by
classical
exact List.perm_of_nodup_nodup_toFinset_eq s₁.toList_nodup s₂.toList_nodup
(Finset.ext <| by simpa only [List.mem_toFinset, RelSeries.mem_toList]))
s₁.toList_sorted s₂.toList_sorted
@[simp]
theorem le_last {s : CompositionSeries X} (i : Fin (s.length + 1)) : s i ≤ s.last :=
s.strictMono.monotone (Fin.le_last _)
theorem le_last_of_mem {s : CompositionSeries X} {x : X} (hx : x ∈ s) : x ≤ s.last :=
let ⟨_i, hi⟩ := Set.mem_range.2 hx
hi ▸ le_last _
| @[simp]
theorem head_le {s : CompositionSeries X} (i : Fin (s.length + 1)) : s.head ≤ s i :=
s.strictMono.monotone (Fin.zero_le _)
theorem head_le_of_mem {s : CompositionSeries X} {x : X} (hx : x ∈ s) : s.head ≤ x :=
| Mathlib/Order/JordanHolder.lean | 188 | 192 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Batteries.Data.List.Pairwise
import Mathlib.Logic.Pairwise
import Mathlib.Logic.Relation
/-!
# Pairwise relations on a list
This file provides basic results about `List.Pairwise` and `List.pwFilter` (definitions are in
`Data.List.Defs`).
`Pairwise r [a 0, ..., a (n - 1)]` means `∀ i j, i < j → r (a i) (a j)`. For example,
`Pairwise (≠) l` means that all elements of `l` are distinct, and `Pairwise (<) l` means that `l`
is strictly increasing.
`pwFilter r l` is the list obtained by iteratively adding each element of `l` that doesn't break
the pairwiseness of the list we have so far. It thus yields `l'` a maximal sublist of `l` such that
`Pairwise r l'`.
## Tags
sorted, nodup
-/
open Nat Function
namespace List
variable {α β : Type*} {R : α → α → Prop} {l : List α} {a : α}
mk_iff_of_inductive_prop List.Pairwise List.pairwise_iff
/-! ### Pairwise -/
theorem Pairwise.forall_of_forall (H : Symmetric R) (H₁ : ∀ x ∈ l, R x x) (H₂ : l.Pairwise R) :
∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → R x y :=
H₂.forall_of_forall_of_flip H₁ <| by rwa [H.flip_eq]
theorem Pairwise.forall (hR : Symmetric R) (hl : l.Pairwise R) :
∀ ⦃a⦄, a ∈ l → ∀ ⦃b⦄, b ∈ l → a ≠ b → R a b := by
apply Pairwise.forall_of_forall
· exact fun a b h hne => hR (h hne.symm)
· exact fun _ _ hx => (hx rfl).elim
· exact hl.imp (@fun a b h _ => by exact h)
theorem Pairwise.set_pairwise (hl : Pairwise R l) (hr : Symmetric R) : { x | x ∈ l }.Pairwise R :=
hl.forall hr
theorem pairwise_of_reflexive_of_forall_ne (hr : Reflexive R)
(h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → R a b) : l.Pairwise R := by
rw [pairwise_iff_forall_sublist]
intro a b hab
if heq : a = b then
cases heq; apply hr
else
apply h <;> try (apply hab.subset; simp)
exact heq
theorem Pairwise.rel_head_tail (h₁ : l.Pairwise R) (ha : a ∈ l.tail) :
R (l.head <| ne_nil_of_mem <| mem_of_mem_tail ha) a := by
cases l with
| nil => simp at ha
| cons b l => exact (pairwise_cons.1 h₁).1 a ha
theorem Pairwise.rel_head_of_rel_head_head (h₁ : l.Pairwise R) (ha : a ∈ l)
(hhead : R (l.head <| ne_nil_of_mem ha) (l.head <| ne_nil_of_mem ha)) :
R (l.head <| ne_nil_of_mem ha) a := by
cases l with
| nil => simp at ha
| cons b l => exact (mem_cons.mp ha).elim (· ▸ hhead) ((pairwise_cons.1 h₁).1 _)
theorem Pairwise.rel_head [IsRefl α R] (h₁ : l.Pairwise R) (ha : a ∈ l) :
R (l.head <| ne_nil_of_mem ha) a :=
h₁.rel_head_of_rel_head_head ha (refl_of ..)
theorem Pairwise.rel_dropLast_getLast (h : l.Pairwise R) (ha : a ∈ l.dropLast) :
R a (l.getLast <| ne_nil_of_mem <| dropLast_subset _ ha) := by
| rw [← pairwise_reverse] at h
rw [getLast_eq_head_reverse]
exact h.rel_head_tail (by rwa [tail_reverse, mem_reverse])
theorem Pairwise.rel_getLast_of_rel_getLast_getLast (h₁ : l.Pairwise R) (ha : a ∈ l)
(hlast : R (l.getLast <| ne_nil_of_mem ha) (l.getLast <| ne_nil_of_mem ha)) :
| Mathlib/Data/List/Pairwise.lean | 81 | 86 |
/-
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, Patrick Massot
-/
import Mathlib.Order.Filter.SmallSets
import Mathlib.Topology.UniformSpace.Defs
import Mathlib.Topology.ContinuousOn
/-!
# Basic results on uniform spaces
Uniform spaces are a generalization of metric spaces and topological groups.
## Main definitions
In this file we define a complete lattice structure on the type `UniformSpace X`
of uniform structures on `X`, as well as the pullback (`UniformSpace.comap`) of uniform structures
coming from the pullback of filters.
Like distance functions, uniform structures cannot be pushed forward in general.
## Notations
Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`,
and `○` for composition of relations, seen as terms with type `Set (X × X)`.
## References
The formalization uses the books:
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
But it makes a more systematic use of the filter library.
-/
open Set Filter Topology
universe u v ua ub uc ud
/-!
### Relations, seen as `Set (α × α)`
-/
variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*}
open Uniformity
section UniformSpace
variable [UniformSpace α]
/-- If `s ∈ 𝓤 α`, then for any natural `n`, for a subset `t` of a sufficiently small set in `𝓤 α`,
we have `t ○ t ○ ... ○ t ⊆ s` (`n` compositions). -/
theorem eventually_uniformity_iterate_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) (n : ℕ) :
∀ᶠ t in (𝓤 α).smallSets, (t ○ ·)^[n] t ⊆ s := by
suffices ∀ᶠ t in (𝓤 α).smallSets, t ⊆ s ∧ (t ○ ·)^[n] t ⊆ s from (eventually_and.1 this).2
induction n generalizing s with
| zero => simpa
| succ _ ihn =>
rcases comp_mem_uniformity_sets hs with ⟨t, htU, hts⟩
refine (ihn htU).mono fun U hU => ?_
rw [Function.iterate_succ_apply']
exact
⟨hU.1.trans <| (subset_comp_self <| refl_le_uniformity htU).trans hts,
(compRel_mono hU.1 hU.2).trans hts⟩
/-- If `s ∈ 𝓤 α`, then for a subset `t` of a sufficiently small set in `𝓤 α`,
we have `t ○ t ⊆ s`. -/
theorem eventually_uniformity_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∀ᶠ t in (𝓤 α).smallSets, t ○ t ⊆ s :=
eventually_uniformity_iterate_comp_subset hs 1
/-!
### Balls in uniform spaces
-/
namespace UniformSpace
open UniformSpace (ball)
lemma isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) :=
hV.preimage <| .prodMk_right _
lemma isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) : IsClosed (ball x V) :=
hV.preimage <| .prodMk_right _
/-!
### Neighborhoods in uniform spaces
-/
theorem hasBasis_nhds_prod (x y : α) :
HasBasis (𝓝 (x, y)) (fun s => s ∈ 𝓤 α ∧ IsSymmetricRel s) fun s => ball x s ×ˢ ball y s := by
rw [nhds_prod_eq]
apply (hasBasis_nhds x).prod_same_index (hasBasis_nhds y)
rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩
exact
⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, U_symm.inter V_symm⟩, ball_inter_left x U V,
ball_inter_right y U V⟩
end UniformSpace
open UniformSpace
theorem nhds_eq_uniformity_prod {a b : α} :
𝓝 (a, b) =
(𝓤 α).lift' fun s : Set (α × α) => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ s } := by
rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift']
· exact fun s => monotone_const.set_prod monotone_preimage
· refine fun t => Monotone.set_prod ?_ monotone_const
exact monotone_preimage (f := fun y => (y, a))
theorem nhdset_of_mem_uniformity {d : Set (α × α)} (s : Set (α × α)) (hd : d ∈ 𝓤 α) :
∃ t : Set (α × α), IsOpen t ∧ s ⊆ t ∧
t ⊆ { p | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } := by
let cl_d := { p : α × α | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d }
have : ∀ p ∈ s, ∃ t, t ⊆ cl_d ∧ IsOpen t ∧ p ∈ t := fun ⟨x, y⟩ hp =>
mem_nhds_iff.mp <|
show cl_d ∈ 𝓝 (x, y) by
rw [nhds_eq_uniformity_prod, mem_lift'_sets]
· exact ⟨d, hd, fun ⟨a, b⟩ ⟨ha, hb⟩ => ⟨x, y, ha, hp, hb⟩⟩
· exact fun _ _ h _ h' => ⟨h h'.1, h h'.2⟩
choose t ht using this
exact ⟨(⋃ p : α × α, ⋃ h : p ∈ s, t p h : Set (α × α)),
isOpen_iUnion fun p : α × α => isOpen_iUnion fun hp => (ht p hp).right.left,
fun ⟨a, b⟩ hp => by
simp only [mem_iUnion, Prod.exists]; exact ⟨a, b, hp, (ht (a, b) hp).right.right⟩,
iUnion_subset fun p => iUnion_subset fun hp => (ht p hp).left⟩
/-- Entourages are neighborhoods of the diagonal. -/
theorem nhds_le_uniformity (x : α) : 𝓝 (x, x) ≤ 𝓤 α := by
intro V V_in
rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩
have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x) := by
rw [nhds_prod_eq]
exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in)
apply mem_of_superset this
rintro ⟨u, v⟩ ⟨u_in, v_in⟩
exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in)
/-- Entourages are neighborhoods of the diagonal. -/
theorem iSup_nhds_le_uniformity : ⨆ x : α, 𝓝 (x, x) ≤ 𝓤 α :=
iSup_le nhds_le_uniformity
/-- Entourages are neighborhoods of the diagonal. -/
theorem nhdsSet_diagonal_le_uniformity : 𝓝ˢ (diagonal α) ≤ 𝓤 α :=
(nhdsSet_diagonal α).trans_le iSup_nhds_le_uniformity
section
variable (α)
theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| 𝓤 α] :
∃ V : ℕ → Set (α × α), HasAntitoneBasis (𝓤 α) V ∧ ∀ n, IsSymmetricRel (V n) :=
let ⟨U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis
⟨U, hbasis, fun n => (hsym n).2⟩
end
/-!
### Closure and interior in uniform spaces
-/
theorem closure_eq_uniformity (s : Set <| α × α) :
closure s = ⋂ V ∈ { V | V ∈ 𝓤 α ∧ IsSymmetricRel V }, V ○ s ○ V := by
ext ⟨x, y⟩
simp +contextual only
[mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq,
and_imp, mem_comp_comp, exists_prop, ← mem_inter_iff, inter_comm, Set.Nonempty]
theorem uniformity_hasBasis_closed :
HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsClosed V) id := by
refine Filter.hasBasis_self.2 fun t h => ?_
rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩
refine ⟨closure w, mem_of_superset w_in subset_closure, isClosed_closure, ?_⟩
refine Subset.trans ?_ r
rw [closure_eq_uniformity]
apply iInter_subset_of_subset
apply iInter_subset
exact ⟨w_in, w_symm⟩
theorem uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure :=
Eq.symm <| uniformity_hasBasis_closed.lift'_closure_eq_self fun _ => And.right
theorem Filter.HasBasis.uniformity_closure {p : ι → Prop} {U : ι → Set (α × α)}
(h : (𝓤 α).HasBasis p U) : (𝓤 α).HasBasis p fun i => closure (U i) :=
(@uniformity_eq_uniformity_closure α _).symm ▸ h.lift'_closure
/-- Closed entourages form a basis of the uniformity filter. -/
theorem uniformity_hasBasis_closure : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α) closure :=
(𝓤 α).basis_sets.uniformity_closure
theorem closure_eq_inter_uniformity {t : Set (α × α)} : closure t = ⋂ d ∈ 𝓤 α, d ○ (t ○ d) :=
calc
closure t = ⋂ (V) (_ : V ∈ 𝓤 α ∧ IsSymmetricRel V), V ○ t ○ V := closure_eq_uniformity t
_ = ⋂ V ∈ 𝓤 α, V ○ t ○ V :=
Eq.symm <|
UniformSpace.hasBasis_symmetric.biInter_mem fun _ _ hV =>
compRel_mono (compRel_mono hV Subset.rfl) hV
_ = ⋂ V ∈ 𝓤 α, V ○ (t ○ V) := by simp only [compRel_assoc]
theorem uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior :=
le_antisymm
(le_iInf₂ fun d hd => by
let ⟨s, hs, hs_comp⟩ := comp3_mem_uniformity hd
let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs
have : s ⊆ interior d :=
calc
s ⊆ t := hst
_ ⊆ interior d :=
ht.subset_interior_iff.mpr fun x (hx : x ∈ t) =>
let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp hx
hs_comp ⟨x, h₁, y, h₂, h₃⟩
have : interior d ∈ 𝓤 α := by filter_upwards [hs] using this
simp [this])
fun _ hs => ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset
theorem interior_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : interior s ∈ 𝓤 α := by
rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs
theorem mem_uniformity_isClosed {s : Set (α × α)} (h : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsClosed t ∧ t ⊆ s :=
let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_hasBasis_closed.mem_iff.1 h
⟨t, ht_mem, htc, hts⟩
theorem isOpen_iff_isOpen_ball_subset {s : Set α} :
IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, IsOpen V ∧ ball x V ⊆ s := by
rw [isOpen_iff_ball_subset]
constructor <;> intro h x hx
· obtain ⟨V, hV, hV'⟩ := h x hx
exact
⟨interior V, interior_mem_uniformity hV, isOpen_interior,
(ball_mono interior_subset x).trans hV'⟩
· obtain ⟨V, hV, -, hV'⟩ := h x hx
exact ⟨V, hV, hV'⟩
@[deprecated (since := "2024-11-18")] alias
isOpen_iff_open_ball_subset := isOpen_iff_isOpen_ball_subset
/-- The uniform neighborhoods of all points of a dense set cover the whole space. -/
theorem Dense.biUnion_uniformity_ball {s : Set α} {U : Set (α × α)} (hs : Dense s) (hU : U ∈ 𝓤 α) :
⋃ x ∈ s, ball x U = univ := by
refine iUnion₂_eq_univ_iff.2 fun y => ?_
rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩
exact ⟨x, hxs, hxy⟩
/-- The uniform neighborhoods of all points of a dense indexed collection cover the whole space. -/
lemma DenseRange.iUnion_uniformity_ball {ι : Type*} {xs : ι → α}
(xs_dense : DenseRange xs) {U : Set (α × α)} (hU : U ∈ uniformity α) :
⋃ i, UniformSpace.ball (xs i) U = univ := by
rw [← biUnion_range (f := xs) (g := fun x ↦ UniformSpace.ball x U)]
exact Dense.biUnion_uniformity_ball xs_dense hU
/-!
### Uniformity bases
-/
/-- Open elements of `𝓤 α` form a basis of `𝓤 α`. -/
theorem uniformity_hasBasis_open : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V) id :=
hasBasis_self.2 fun s hs =>
⟨interior s, interior_mem_uniformity hs, isOpen_interior, interior_subset⟩
theorem Filter.HasBasis.mem_uniformity_iff {p : β → Prop} {s : β → Set (α × α)}
(h : (𝓤 α).HasBasis p s) {t : Set (α × α)} :
t ∈ 𝓤 α ↔ ∃ i, p i ∧ ∀ a b, (a, b) ∈ s i → (a, b) ∈ t :=
h.mem_iff.trans <| by simp only [Prod.forall, subset_def]
/-- Open elements `s : Set (α × α)` of `𝓤 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis
of `𝓤 α`. -/
theorem uniformity_hasBasis_open_symmetric :
HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V ∧ IsSymmetricRel V) id := by
simp only [← and_assoc]
refine uniformity_hasBasis_open.restrict fun s hs => ⟨symmetrizeRel s, ?_⟩
exact
⟨⟨symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩,
symmetric_symmetrizeRel s, symmetrizeRel_subset_self s⟩
theorem comp_open_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, IsOpen t ∧ IsSymmetricRel t ∧ t ○ t ⊆ s := by
obtain ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs
obtain ⟨u, ⟨hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_hasBasis_open_symmetric.mem_iff.mp ht₁
exact ⟨u, hu₁, hu₂, hu₃, (compRel_mono hu₄ hu₄).trans ht₂⟩
end UniformSpace
open uniformity
section Constructions
instance : PartialOrder (UniformSpace α) :=
PartialOrder.lift (fun u => 𝓤[u]) fun _ _ => UniformSpace.ext
protected theorem UniformSpace.le_def {u₁ u₂ : UniformSpace α} : u₁ ≤ u₂ ↔ 𝓤[u₁] ≤ 𝓤[u₂] := Iff.rfl
instance : InfSet (UniformSpace α) :=
⟨fun s =>
UniformSpace.ofCore
{ uniformity := ⨅ u ∈ s, 𝓤[u]
refl := le_iInf fun u => le_iInf fun _ => u.toCore.refl
symm := le_iInf₂ fun u hu =>
le_trans (map_mono <| iInf_le_of_le _ <| iInf_le _ hu) u.symm
comp := le_iInf₂ fun u hu =>
le_trans (lift'_mono (iInf_le_of_le _ <| iInf_le _ hu) <| le_rfl) u.comp }⟩
protected theorem UniformSpace.sInf_le {tt : Set (UniformSpace α)} {t : UniformSpace α}
(h : t ∈ tt) : sInf tt ≤ t :=
show ⨅ u ∈ tt, 𝓤[u] ≤ 𝓤[t] from iInf₂_le t h
protected theorem UniformSpace.le_sInf {tt : Set (UniformSpace α)} {t : UniformSpace α}
(h : ∀ t' ∈ tt, t ≤ t') : t ≤ sInf tt :=
show 𝓤[t] ≤ ⨅ u ∈ tt, 𝓤[u] from le_iInf₂ h
instance : Top (UniformSpace α) :=
⟨@UniformSpace.mk α ⊤ ⊤ le_top le_top fun x ↦ by simp only [nhds_top, comap_top]⟩
instance : Bot (UniformSpace α) :=
⟨{ toTopologicalSpace := ⊥
uniformity := 𝓟 idRel
symm := by simp [Tendsto]
comp := lift'_le (mem_principal_self _) <| principal_mono.2 id_compRel.subset
nhds_eq_comap_uniformity := fun s => by
let _ : TopologicalSpace α := ⊥; have := discreteTopology_bot α
simp [idRel] }⟩
instance : Min (UniformSpace α) :=
⟨fun u₁ u₂ =>
{ uniformity := 𝓤[u₁] ⊓ 𝓤[u₂]
symm := u₁.symm.inf u₂.symm
comp := (lift'_inf_le _ _ _).trans <| inf_le_inf u₁.comp u₂.comp
toTopologicalSpace := u₁.toTopologicalSpace ⊓ u₂.toTopologicalSpace
nhds_eq_comap_uniformity := fun _ ↦ by
rw [@nhds_inf _ u₁.toTopologicalSpace _, @nhds_eq_comap_uniformity _ u₁,
@nhds_eq_comap_uniformity _ u₂, comap_inf] }⟩
instance : CompleteLattice (UniformSpace α) :=
{ inferInstanceAs (PartialOrder (UniformSpace α)) with
sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x }
le_sup_left := fun _ _ => UniformSpace.le_sInf fun _ ⟨h, _⟩ => h
le_sup_right := fun _ _ => UniformSpace.le_sInf fun _ ⟨_, h⟩ => h
sup_le := fun _ _ _ h₁ h₂ => UniformSpace.sInf_le ⟨h₁, h₂⟩
inf := (· ⊓ ·)
le_inf := fun a _ _ h₁ h₂ => show a.uniformity ≤ _ from le_inf h₁ h₂
inf_le_left := fun a _ => show _ ≤ a.uniformity from inf_le_left
inf_le_right := fun _ b => show _ ≤ b.uniformity from inf_le_right
top := ⊤
le_top := fun a => show a.uniformity ≤ ⊤ from le_top
bot := ⊥
bot_le := fun u => u.toCore.refl
sSup := fun tt => sInf { t | ∀ t' ∈ tt, t' ≤ t }
le_sSup := fun _ _ h => UniformSpace.le_sInf fun _ h' => h' _ h
sSup_le := fun _ _ h => UniformSpace.sInf_le h
sInf := sInf
le_sInf := fun _ _ hs => UniformSpace.le_sInf hs
sInf_le := fun _ _ ha => UniformSpace.sInf_le ha }
theorem iInf_uniformity {ι : Sort*} {u : ι → UniformSpace α} : 𝓤[iInf u] = ⨅ i, 𝓤[u i] :=
iInf_range
theorem inf_uniformity {u v : UniformSpace α} : 𝓤[u ⊓ v] = 𝓤[u] ⊓ 𝓤[v] := rfl
lemma bot_uniformity : 𝓤[(⊥ : UniformSpace α)] = 𝓟 idRel := rfl
lemma top_uniformity : 𝓤[(⊤ : UniformSpace α)] = ⊤ := rfl
instance inhabitedUniformSpace : Inhabited (UniformSpace α) :=
⟨⊥⟩
instance inhabitedUniformSpaceCore : Inhabited (UniformSpace.Core α) :=
⟨@UniformSpace.toCore _ default⟩
instance [Subsingleton α] : Unique (UniformSpace α) where
uniq u := bot_unique <| le_principal_iff.2 <| by
rw [idRel, ← diagonal, diagonal_eq_univ]; exact univ_mem
/-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f`
is the inverse image in the filter sense of the induced function `α × α → β × β`.
See note [reducible non-instances]. -/
abbrev UniformSpace.comap (f : α → β) (u : UniformSpace β) : UniformSpace α where
uniformity := 𝓤[u].comap fun p : α × α => (f p.1, f p.2)
symm := by
simp only [tendsto_comap_iff, Prod.swap, (· ∘ ·)]
exact tendsto_swap_uniformity.comp tendsto_comap
comp := le_trans
(by
rw [comap_lift'_eq, comap_lift'_eq2]
· exact lift'_mono' fun s _ ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩ => ⟨f x, h₁, h₂⟩
· exact monotone_id.compRel monotone_id)
(comap_mono u.comp)
toTopologicalSpace := u.toTopologicalSpace.induced f
nhds_eq_comap_uniformity x := by
simp only [nhds_induced, nhds_eq_comap_uniformity, comap_comap, Function.comp_def]
theorem uniformity_comap {_ : UniformSpace β} (f : α → β) :
𝓤[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (𝓤 β) :=
rfl
lemma ball_preimage {f : α → β} {U : Set (β × β)} {x : α} :
UniformSpace.ball x (Prod.map f f ⁻¹' U) = f ⁻¹' UniformSpace.ball (f x) U := by
ext : 1
simp only [UniformSpace.ball, mem_preimage, Prod.map_apply]
@[simp]
theorem uniformSpace_comap_id {α : Type*} : UniformSpace.comap (id : α → α) = id := by
ext : 2
rw [uniformity_comap, Prod.map_id, comap_id]
theorem UniformSpace.comap_comap {α β γ} {uγ : UniformSpace γ} {f : α → β} {g : β → γ} :
UniformSpace.comap (g ∘ f) uγ = UniformSpace.comap f (UniformSpace.comap g uγ) := by
ext1
simp only [uniformity_comap, Filter.comap_comap, Prod.map_comp_map]
theorem UniformSpace.comap_inf {α γ} {u₁ u₂ : UniformSpace γ} {f : α → γ} :
(u₁ ⊓ u₂).comap f = u₁.comap f ⊓ u₂.comap f :=
UniformSpace.ext Filter.comap_inf
theorem UniformSpace.comap_iInf {ι α γ} {u : ι → UniformSpace γ} {f : α → γ} :
(⨅ i, u i).comap f = ⨅ i, (u i).comap f := by
ext : 1
simp [uniformity_comap, iInf_uniformity]
theorem UniformSpace.comap_mono {α γ} {f : α → γ} :
Monotone fun u : UniformSpace γ => u.comap f := fun _ _ hu =>
Filter.comap_mono hu
theorem uniformContinuous_iff {α β} {uα : UniformSpace α} {uβ : UniformSpace β} {f : α → β} :
UniformContinuous f ↔ uα ≤ uβ.comap f :=
Filter.map_le_iff_le_comap
theorem le_iff_uniformContinuous_id {u v : UniformSpace α} :
u ≤ v ↔ @UniformContinuous _ _ u v id := by
rw [uniformContinuous_iff, uniformSpace_comap_id, id]
theorem uniformContinuous_comap {f : α → β} [u : UniformSpace β] :
@UniformContinuous α β (UniformSpace.comap f u) u f :=
tendsto_comap
theorem uniformContinuous_comap' {f : γ → β} {g : α → γ} [v : UniformSpace β] [u : UniformSpace α]
(h : UniformContinuous (f ∘ g)) : @UniformContinuous α γ u (UniformSpace.comap f v) g :=
tendsto_comap_iff.2 h
namespace UniformSpace
theorem to_nhds_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) (a : α) :
@nhds _ (@UniformSpace.toTopologicalSpace _ u₁) a ≤
@nhds _ (@UniformSpace.toTopologicalSpace _ u₂) a := by
rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact lift'_mono h le_rfl
theorem toTopologicalSpace_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) :
@UniformSpace.toTopologicalSpace _ u₁ ≤ @UniformSpace.toTopologicalSpace _ u₂ :=
le_of_nhds_le_nhds <| to_nhds_mono h
theorem toTopologicalSpace_comap {f : α → β} {u : UniformSpace β} :
@UniformSpace.toTopologicalSpace _ (UniformSpace.comap f u) =
TopologicalSpace.induced f (@UniformSpace.toTopologicalSpace β u) :=
rfl
lemma uniformSpace_eq_bot {u : UniformSpace α} : u = ⊥ ↔ idRel ∈ 𝓤[u] :=
le_bot_iff.symm.trans le_principal_iff
protected lemma _root_.Filter.HasBasis.uniformSpace_eq_bot {ι p} {s : ι → Set (α × α)}
{u : UniformSpace α} (h : 𝓤[u].HasBasis p s) :
u = ⊥ ↔ ∃ i, p i ∧ Pairwise fun x y : α ↦ (x, y) ∉ s i := by
simp [uniformSpace_eq_bot, h.mem_iff, subset_def, Pairwise, not_imp_not]
theorem toTopologicalSpace_bot : @UniformSpace.toTopologicalSpace α ⊥ = ⊥ := rfl
theorem toTopologicalSpace_top : @UniformSpace.toTopologicalSpace α ⊤ = ⊤ := rfl
theorem toTopologicalSpace_iInf {ι : Sort*} {u : ι → UniformSpace α} :
(iInf u).toTopologicalSpace = ⨅ i, (u i).toTopologicalSpace :=
TopologicalSpace.ext_nhds fun a ↦ by simp only [@nhds_eq_comap_uniformity _ (iInf u), nhds_iInf,
iInf_uniformity, @nhds_eq_comap_uniformity _ (u _), Filter.comap_iInf]
theorem toTopologicalSpace_sInf {s : Set (UniformSpace α)} :
(sInf s).toTopologicalSpace = ⨅ i ∈ s, @UniformSpace.toTopologicalSpace α i := by
rw [sInf_eq_iInf]
simp only [← toTopologicalSpace_iInf]
theorem toTopologicalSpace_inf {u v : UniformSpace α} :
(u ⊓ v).toTopologicalSpace = u.toTopologicalSpace ⊓ v.toTopologicalSpace :=
rfl
end UniformSpace
theorem UniformContinuous.continuous [UniformSpace α] [UniformSpace β] {f : α → β}
(hf : UniformContinuous f) : Continuous f :=
continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <|
uniformContinuous_iff.1 hf
/-- Uniform space structure on `ULift α`. -/
instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) :=
UniformSpace.comap ULift.down ‹_›
/-- Uniform space structure on `αᵒᵈ`. -/
instance OrderDual.instUniformSpace [UniformSpace α] : UniformSpace (αᵒᵈ) :=
‹UniformSpace α›
section UniformContinuousInfi
-- TODO: add an `iff` lemma?
theorem UniformContinuous.inf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ u₃ : UniformSpace β}
(h₁ : UniformContinuous[u₁, u₂] f) (h₂ : UniformContinuous[u₁, u₃] f) :
UniformContinuous[u₁, u₂ ⊓ u₃] f :=
tendsto_inf.mpr ⟨h₁, h₂⟩
theorem UniformContinuous.inf_dom_left {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β}
(hf : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f :=
tendsto_inf_left hf
theorem UniformContinuous.inf_dom_right {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β}
(hf : UniformContinuous[u₂, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f :=
tendsto_inf_right hf
theorem uniformContinuous_sInf_dom {f : α → β} {u₁ : Set (UniformSpace α)} {u₂ : UniformSpace β}
{u : UniformSpace α} (h₁ : u ∈ u₁) (hf : UniformContinuous[u, u₂] f) :
UniformContinuous[sInf u₁, u₂] f := by
delta UniformContinuous
rw [sInf_eq_iInf', iInf_uniformity]
exact tendsto_iInf' ⟨u, h₁⟩ hf
theorem uniformContinuous_sInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : Set (UniformSpace β)} :
UniformContinuous[u₁, sInf u₂] f ↔ ∀ u ∈ u₂, UniformContinuous[u₁, u] f := by
delta UniformContinuous
rw [sInf_eq_iInf', iInf_uniformity, tendsto_iInf, SetCoe.forall]
theorem uniformContinuous_iInf_dom {f : α → β} {u₁ : ι → UniformSpace α} {u₂ : UniformSpace β}
{i : ι} (hf : UniformContinuous[u₁ i, u₂] f) : UniformContinuous[iInf u₁, u₂] f := by
delta UniformContinuous
rw [iInf_uniformity]
exact tendsto_iInf' i hf
theorem uniformContinuous_iInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : ι → UniformSpace β} :
UniformContinuous[u₁, iInf u₂] f ↔ ∀ i, UniformContinuous[u₁, u₂ i] f := by
delta UniformContinuous
rw [iInf_uniformity, tendsto_iInf]
end UniformContinuousInfi
/-- A uniform space with the discrete uniformity has the discrete topology. -/
theorem discreteTopology_of_discrete_uniformity [hα : UniformSpace α] (h : uniformity α = 𝓟 idRel) :
DiscreteTopology α :=
⟨(UniformSpace.ext h.symm : ⊥ = hα) ▸ rfl⟩
instance : UniformSpace Empty := ⊥
instance : UniformSpace PUnit := ⊥
instance : UniformSpace Bool := ⊥
instance : UniformSpace ℕ := ⊥
instance : UniformSpace ℤ := ⊥
section
variable [UniformSpace α]
open Additive Multiplicative
instance : UniformSpace (Additive α) := ‹UniformSpace α›
instance : UniformSpace (Multiplicative α) := ‹UniformSpace α›
theorem uniformContinuous_ofMul : UniformContinuous (ofMul : α → Additive α) :=
uniformContinuous_id
theorem uniformContinuous_toMul : UniformContinuous (toMul : Additive α → α) :=
uniformContinuous_id
theorem uniformContinuous_ofAdd : UniformContinuous (ofAdd : α → Multiplicative α) :=
uniformContinuous_id
theorem uniformContinuous_toAdd : UniformContinuous (toAdd : Multiplicative α → α) :=
uniformContinuous_id
theorem uniformity_additive : 𝓤 (Additive α) = (𝓤 α).map (Prod.map ofMul ofMul) := rfl
theorem uniformity_multiplicative : 𝓤 (Multiplicative α) = (𝓤 α).map (Prod.map ofAdd ofAdd) := rfl
end
instance instUniformSpaceSubtype {p : α → Prop} [t : UniformSpace α] : UniformSpace (Subtype p) :=
UniformSpace.comap Subtype.val t
theorem uniformity_subtype {p : α → Prop} [UniformSpace α] :
𝓤 (Subtype p) = comap (fun q : Subtype p × Subtype p => (q.1.1, q.2.1)) (𝓤 α) :=
rfl
theorem uniformity_setCoe {s : Set α} [UniformSpace α] :
𝓤 s = comap (Prod.map ((↑) : s → α) ((↑) : s → α)) (𝓤 α) :=
rfl
theorem map_uniformity_set_coe {s : Set α} [UniformSpace α] :
map (Prod.map (↑) (↑)) (𝓤 s) = 𝓤 α ⊓ 𝓟 (s ×ˢ s) := by
rw [uniformity_setCoe, map_comap, range_prodMap, Subtype.range_val]
theorem uniformContinuous_subtype_val {p : α → Prop} [UniformSpace α] :
UniformContinuous (Subtype.val : { a : α // p a } → α) :=
uniformContinuous_comap
theorem UniformContinuous.subtype_mk {p : α → Prop} [UniformSpace α] [UniformSpace β] {f : β → α}
(hf : UniformContinuous f) (h : ∀ x, p (f x)) :
UniformContinuous (fun x => ⟨f x, h x⟩ : β → Subtype p) :=
uniformContinuous_comap' hf
theorem uniformContinuousOn_iff_restrict [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} :
UniformContinuousOn f s ↔ UniformContinuous (s.restrict f) := by
delta UniformContinuousOn UniformContinuous
rw [← map_uniformity_set_coe, tendsto_map'_iff]; rfl
theorem tendsto_of_uniformContinuous_subtype [UniformSpace α] [UniformSpace β] {f : α → β}
{s : Set α} {a : α} (hf : UniformContinuous fun x : s => f x.val) (ha : s ∈ 𝓝 a) :
Tendsto f (𝓝 a) (𝓝 (f a)) := by
rw [(@map_nhds_subtype_coe_eq_nhds α _ s a (mem_of_mem_nhds ha) ha).symm]
exact tendsto_map' hf.continuous.continuousAt
theorem UniformContinuousOn.continuousOn [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α}
(h : UniformContinuousOn f s) : ContinuousOn f s := by
rw [uniformContinuousOn_iff_restrict] at h
rw [continuousOn_iff_continuous_restrict]
exact h.continuous
@[to_additive]
instance [UniformSpace α] : UniformSpace αᵐᵒᵖ :=
UniformSpace.comap MulOpposite.unop ‹_›
@[to_additive]
theorem uniformity_mulOpposite [UniformSpace α] :
𝓤 αᵐᵒᵖ = comap (fun q : αᵐᵒᵖ × αᵐᵒᵖ => (q.1.unop, q.2.unop)) (𝓤 α) :=
rfl
@[to_additive (attr := simp)]
theorem comap_uniformity_mulOpposite [UniformSpace α] :
comap (fun p : α × α => (MulOpposite.op p.1, MulOpposite.op p.2)) (𝓤 αᵐᵒᵖ) = 𝓤 α := by
simpa [uniformity_mulOpposite, comap_comap, (· ∘ ·)] using comap_id
namespace MulOpposite
@[to_additive]
theorem uniformContinuous_unop [UniformSpace α] : UniformContinuous (unop : αᵐᵒᵖ → α) :=
uniformContinuous_comap
@[to_additive]
theorem uniformContinuous_op [UniformSpace α] : UniformContinuous (op : α → αᵐᵒᵖ) :=
uniformContinuous_comap' uniformContinuous_id
end MulOpposite
section Prod
open UniformSpace
/- a similar product space is possible on the function space (uniformity of pointwise convergence),
but we want to have the uniformity of uniform convergence on function spaces -/
instance instUniformSpaceProd [u₁ : UniformSpace α] [u₂ : UniformSpace β] : UniformSpace (α × β) :=
u₁.comap Prod.fst ⊓ u₂.comap Prod.snd
-- check the above produces no diamond for `simp` and typeclass search
example [UniformSpace α] [UniformSpace β] :
(instTopologicalSpaceProd : TopologicalSpace (α × β)) = UniformSpace.toTopologicalSpace := by
with_reducible_and_instances rfl
theorem uniformity_prod [UniformSpace α] [UniformSpace β] :
𝓤 (α × β) =
((𝓤 α).comap fun p : (α × β) × α × β => (p.1.1, p.2.1)) ⊓
(𝓤 β).comap fun p : (α × β) × α × β => (p.1.2, p.2.2) :=
rfl
instance [UniformSpace α] [IsCountablyGenerated (𝓤 α)]
[UniformSpace β] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α × β)) := by
rw [uniformity_prod]
infer_instance
theorem uniformity_prod_eq_comap_prod [UniformSpace α] [UniformSpace β] :
𝓤 (α × β) =
comap (fun p : (α × β) × α × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by
simp_rw [uniformity_prod, prod_eq_inf, Filter.comap_inf, Filter.comap_comap, Function.comp_def]
theorem uniformity_prod_eq_prod [UniformSpace α] [UniformSpace β] :
𝓤 (α × β) = map (fun p : (α × α) × β × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by
rw [map_swap4_eq_comap, uniformity_prod_eq_comap_prod]
theorem mem_uniformity_of_uniformContinuous_invariant [UniformSpace α] [UniformSpace β]
{s : Set (β × β)} {f : α → α → β} (hf : UniformContinuous fun p : α × α => f p.1 p.2)
(hs : s ∈ 𝓤 β) : ∃ u ∈ 𝓤 α, ∀ a b c, (a, b) ∈ u → (f a c, f b c) ∈ s := by
rw [UniformContinuous, uniformity_prod_eq_prod, tendsto_map'_iff] at hf
rcases mem_prod_iff.1 (mem_map.1 <| hf hs) with ⟨u, hu, v, hv, huvt⟩
exact ⟨u, hu, fun a b c hab => @huvt ((_, _), (_, _)) ⟨hab, refl_mem_uniformity hv⟩⟩
/-- An entourage of the diagonal in `α` and an entourage in `β` yield an entourage in `α × β`
once we permute coordinates. -/
def entourageProd (u : Set (α × α)) (v : Set (β × β)) : Set ((α × β) × α × β) :=
{((a₁, b₁),(a₂, b₂)) | (a₁, a₂) ∈ u ∧ (b₁, b₂) ∈ v}
theorem mem_entourageProd {u : Set (α × α)} {v : Set (β × β)} {p : (α × β) × α × β} :
p ∈ entourageProd u v ↔ (p.1.1, p.2.1) ∈ u ∧ (p.1.2, p.2.2) ∈ v := Iff.rfl
theorem entourageProd_mem_uniformity [t₁ : UniformSpace α] [t₂ : UniformSpace β] {u : Set (α × α)}
{v : Set (β × β)} (hu : u ∈ 𝓤 α) (hv : v ∈ 𝓤 β) :
entourageProd u v ∈ 𝓤 (α × β) := by
rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap hu) (preimage_mem_comap hv)
theorem ball_entourageProd (u : Set (α × α)) (v : Set (β × β)) (x : α × β) :
ball x (entourageProd u v) = ball x.1 u ×ˢ ball x.2 v := by
ext p; simp only [ball, entourageProd, Set.mem_setOf_eq, Set.mem_prod, Set.mem_preimage]
lemma IsSymmetricRel.entourageProd {u : Set (α × α)} {v : Set (β × β)}
(hu : IsSymmetricRel u) (hv : IsSymmetricRel v) :
IsSymmetricRel (entourageProd u v) :=
Set.ext fun _ ↦ and_congr hu.mk_mem_comm hv.mk_mem_comm
theorem Filter.HasBasis.uniformity_prod {ιa ιb : Type*} [UniformSpace α] [UniformSpace β]
{pa : ιa → Prop} {pb : ιb → Prop} {sa : ιa → Set (α × α)} {sb : ιb → Set (β × β)}
(ha : (𝓤 α).HasBasis pa sa) (hb : (𝓤 β).HasBasis pb sb) :
(𝓤 (α × β)).HasBasis (fun i : ιa × ιb ↦ pa i.1 ∧ pb i.2)
(fun i ↦ entourageProd (sa i.1) (sb i.2)) :=
(ha.comap _).inf (hb.comap _)
theorem entourageProd_subset [UniformSpace α] [UniformSpace β]
{s : Set ((α × β) × α × β)} (h : s ∈ 𝓤 (α × β)) :
∃ u ∈ 𝓤 α, ∃ v ∈ 𝓤 β, entourageProd u v ⊆ s := by
rcases (((𝓤 α).basis_sets.uniformity_prod (𝓤 β).basis_sets).mem_iff' s).1 h with ⟨w, hw⟩
use w.1, hw.1.1, w.2, hw.1.2, hw.2
theorem tendsto_prod_uniformity_fst [UniformSpace α] [UniformSpace β] :
Tendsto (fun p : (α × β) × α × β => (p.1.1, p.2.1)) (𝓤 (α × β)) (𝓤 α) :=
le_trans (map_mono inf_le_left) map_comap_le
theorem tendsto_prod_uniformity_snd [UniformSpace α] [UniformSpace β] :
Tendsto (fun p : (α × β) × α × β => (p.1.2, p.2.2)) (𝓤 (α × β)) (𝓤 β) :=
le_trans (map_mono inf_le_right) map_comap_le
theorem uniformContinuous_fst [UniformSpace α] [UniformSpace β] :
UniformContinuous fun p : α × β => p.1 :=
tendsto_prod_uniformity_fst
theorem uniformContinuous_snd [UniformSpace α] [UniformSpace β] :
UniformContinuous fun p : α × β => p.2 :=
tendsto_prod_uniformity_snd
variable [UniformSpace α] [UniformSpace β] [UniformSpace γ]
theorem UniformContinuous.prodMk {f₁ : α → β} {f₂ : α → γ} (h₁ : UniformContinuous f₁)
(h₂ : UniformContinuous f₂) : UniformContinuous fun a => (f₁ a, f₂ a) := by
rw [UniformContinuous, uniformity_prod]
exact tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩
@[deprecated (since := "2025-03-10")]
alias UniformContinuous.prod_mk := UniformContinuous.prodMk
theorem UniformContinuous.prodMk_left {f : α × β → γ} (h : UniformContinuous f) (b) :
UniformContinuous fun a => f (a, b) :=
h.comp (uniformContinuous_id.prodMk uniformContinuous_const)
@[deprecated (since := "2025-03-10")]
alias UniformContinuous.prod_mk_left := UniformContinuous.prodMk_left
theorem UniformContinuous.prodMk_right {f : α × β → γ} (h : UniformContinuous f) (a) :
UniformContinuous fun b => f (a, b) :=
h.comp (uniformContinuous_const.prodMk uniformContinuous_id)
@[deprecated (since := "2025-03-10")]
alias UniformContinuous.prod_mk_right := UniformContinuous.prodMk_right
theorem UniformContinuous.prodMap [UniformSpace δ] {f : α → γ} {g : β → δ}
(hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous (Prod.map f g) :=
(hf.comp uniformContinuous_fst).prodMk (hg.comp uniformContinuous_snd)
theorem toTopologicalSpace_prod {α} {β} [u : UniformSpace α] [v : UniformSpace β] :
@UniformSpace.toTopologicalSpace (α × β) instUniformSpaceProd =
@instTopologicalSpaceProd α β u.toTopologicalSpace v.toTopologicalSpace :=
rfl
/-- A version of `UniformContinuous.inf_dom_left` for binary functions -/
theorem uniformContinuous_inf_dom_left₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α}
{ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ}
(h : by haveI := ua1; haveI := ub1; exact UniformContinuous fun p : α × β => f p.1 p.2) : by
haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2
exact UniformContinuous fun p : α × β => f p.1 p.2 := by
-- proof essentially copied from `continuous_inf_dom_left₂`
have ha := @UniformContinuous.inf_dom_left _ _ id ua1 ua2 ua1 (@uniformContinuous_id _ (id _))
have hb := @UniformContinuous.inf_dom_left _ _ id ub1 ub2 ub1 (@uniformContinuous_id _ (id _))
have h_unif_cont_id :=
@UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua1 ub1 _ _ ha hb
exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id
/-- A version of `UniformContinuous.inf_dom_right` for binary functions -/
theorem uniformContinuous_inf_dom_right₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α}
{ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ}
(h : by haveI := ua2; haveI := ub2; exact UniformContinuous fun p : α × β => f p.1 p.2) : by
haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2
exact UniformContinuous fun p : α × β => f p.1 p.2 := by
-- proof essentially copied from `continuous_inf_dom_right₂`
have ha := @UniformContinuous.inf_dom_right _ _ id ua1 ua2 ua2 (@uniformContinuous_id _ (id _))
have hb := @UniformContinuous.inf_dom_right _ _ id ub1 ub2 ub2 (@uniformContinuous_id _ (id _))
have h_unif_cont_id :=
@UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua2 ub2 _ _ ha hb
exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id
/-- A version of `uniformContinuous_sInf_dom` for binary functions -/
theorem uniformContinuous_sInf_dom₂ {α β γ} {f : α → β → γ} {uas : Set (UniformSpace α)}
{ubs : Set (UniformSpace β)} {ua : UniformSpace α} {ub : UniformSpace β} {uc : UniformSpace γ}
(ha : ua ∈ uas) (hb : ub ∈ ubs) (hf : UniformContinuous fun p : α × β => f p.1 p.2) : by
haveI := sInf uas; haveI := sInf ubs
exact @UniformContinuous _ _ _ uc fun p : α × β => f p.1 p.2 := by
-- proof essentially copied from `continuous_sInf_dom`
let _ : UniformSpace (α × β) := instUniformSpaceProd
have ha := uniformContinuous_sInf_dom ha uniformContinuous_id
have hb := uniformContinuous_sInf_dom hb uniformContinuous_id
have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (sInf uas) (sInf ubs) ua ub _ _ ha hb
exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ hf h_unif_cont_id
end Prod
section
open UniformSpace Function
variable {δ' : Type*} [UniformSpace α] [UniformSpace β] [UniformSpace γ] [UniformSpace δ]
[UniformSpace δ']
local notation f " ∘₂ " g => Function.bicompr f g
/-- Uniform continuity for functions of two variables. -/
def UniformContinuous₂ (f : α → β → γ) :=
UniformContinuous (uncurry f)
theorem uniformContinuous₂_def (f : α → β → γ) :
UniformContinuous₂ f ↔ UniformContinuous (uncurry f) :=
Iff.rfl
theorem UniformContinuous₂.uniformContinuous {f : α → β → γ} (h : UniformContinuous₂ f) :
UniformContinuous (uncurry f) :=
h
theorem uniformContinuous₂_curry (f : α × β → γ) :
UniformContinuous₂ (Function.curry f) ↔ UniformContinuous f := by
rw [UniformContinuous₂, uncurry_curry]
theorem UniformContinuous₂.comp {f : α → β → γ} {g : γ → δ} (hg : UniformContinuous g)
(hf : UniformContinuous₂ f) : UniformContinuous₂ (g ∘₂ f) :=
hg.comp hf
theorem UniformContinuous₂.bicompl {f : α → β → γ} {ga : δ → α} {gb : δ' → β}
(hf : UniformContinuous₂ f) (hga : UniformContinuous ga) (hgb : UniformContinuous gb) :
UniformContinuous₂ (bicompl f ga gb) :=
hf.uniformContinuous.comp (hga.prodMap hgb)
end
theorem toTopologicalSpace_subtype [u : UniformSpace α] {p : α → Prop} :
@UniformSpace.toTopologicalSpace (Subtype p) instUniformSpaceSubtype =
@instTopologicalSpaceSubtype α p u.toTopologicalSpace :=
rfl
section Sum
variable [UniformSpace α] [UniformSpace β]
open Sum
-- Obsolete auxiliary definitions and lemmas
/-- Uniformity on a disjoint union. Entourages of the diagonal in the union are obtained
by taking independently an entourage of the diagonal in the first part, and an entourage of
the diagonal in the second part. -/
instance Sum.instUniformSpace : UniformSpace (α ⊕ β) where
uniformity := map (fun p : α × α => (inl p.1, inl p.2)) (𝓤 α) ⊔
map (fun p : β × β => (inr p.1, inr p.2)) (𝓤 β)
symm := fun _ hs ↦ ⟨symm_le_uniformity hs.1, symm_le_uniformity hs.2⟩
comp := fun s hs ↦ by
rcases comp_mem_uniformity_sets hs.1 with ⟨tα, htα, Htα⟩
rcases comp_mem_uniformity_sets hs.2 with ⟨tβ, htβ, Htβ⟩
filter_upwards [mem_lift' (union_mem_sup (image_mem_map htα) (image_mem_map htβ))]
rintro ⟨_, _⟩ ⟨z, ⟨⟨a, b⟩, hab, ⟨⟩⟩ | ⟨⟨a, b⟩, hab, ⟨⟩⟩, ⟨⟨_, c⟩, hbc, ⟨⟩⟩ | ⟨⟨_, c⟩, hbc, ⟨⟩⟩⟩
exacts [@Htα (_, _) ⟨b, hab, hbc⟩, @Htβ (_, _) ⟨b, hab, hbc⟩]
nhds_eq_comap_uniformity x := by
ext
cases x <;> simp [mem_comap', -mem_comap, nhds_inl, nhds_inr, nhds_eq_comap_uniformity,
Prod.ext_iff]
/-- The union of an entourage of the diagonal in each set of a disjoint union is again an entourage
of the diagonal. -/
theorem union_mem_uniformity_sum {a : Set (α × α)} (ha : a ∈ 𝓤 α) {b : Set (β × β)} (hb : b ∈ 𝓤 β) :
Prod.map inl inl '' a ∪ Prod.map inr inr '' b ∈ 𝓤 (α ⊕ β) :=
union_mem_sup (image_mem_map ha) (image_mem_map hb)
theorem Sum.uniformity : 𝓤 (α ⊕ β) = map (Prod.map inl inl) (𝓤 α) ⊔ map (Prod.map inr inr) (𝓤 β) :=
rfl
lemma uniformContinuous_inl : UniformContinuous (Sum.inl : α → α ⊕ β) := le_sup_left
lemma uniformContinuous_inr : UniformContinuous (Sum.inr : β → α ⊕ β) := le_sup_right
instance [IsCountablyGenerated (𝓤 α)] [IsCountablyGenerated (𝓤 β)] :
IsCountablyGenerated (𝓤 (α ⊕ β)) := by
rw [Sum.uniformity]
infer_instance
end Sum
end Constructions
/-!
### Expressing continuity properties in uniform spaces
We reformulate the various continuity properties of functions taking values in a uniform space
in terms of the uniformity in the target. Since the same lemmas (essentially with the same names)
also exist for metric spaces and emetric spaces (reformulating things in terms of the distance or
the edistance in the target), we put them in a namespace `Uniform` here.
In the metric and emetric space setting, there are also similar lemmas where one assumes that
both the source and the target are metric spaces, reformulating things in terms of the distance
on both sides. These lemmas are generally written without primes, and the versions where only
the target is a metric space is primed. We follow the same convention here, thus giving lemmas
with primes.
-/
namespace Uniform
variable [UniformSpace α]
theorem tendsto_nhds_right {f : Filter β} {u : β → α} {a : α} :
Tendsto u f (𝓝 a) ↔ Tendsto (fun x => (a, u x)) f (𝓤 α) := by
rw [nhds_eq_comap_uniformity, tendsto_comap_iff]; rfl
theorem tendsto_nhds_left {f : Filter β} {u : β → α} {a : α} :
Tendsto u f (𝓝 a) ↔ Tendsto (fun x => (u x, a)) f (𝓤 α) := by
rw [nhds_eq_comap_uniformity', tendsto_comap_iff]; rfl
theorem continuousAt_iff'_right [TopologicalSpace β] {f : β → α} {b : β} :
ContinuousAt f b ↔ Tendsto (fun x => (f b, f x)) (𝓝 b) (𝓤 α) := by
rw [ContinuousAt, tendsto_nhds_right]
theorem continuousAt_iff'_left [TopologicalSpace β] {f : β → α} {b : β} :
ContinuousAt f b ↔ Tendsto (fun x => (f x, f b)) (𝓝 b) (𝓤 α) := by
rw [ContinuousAt, tendsto_nhds_left]
theorem continuousAt_iff_prod [TopologicalSpace β] {f : β → α} {b : β} :
ContinuousAt f b ↔ Tendsto (fun x : β × β => (f x.1, f x.2)) (𝓝 (b, b)) (𝓤 α) :=
⟨fun H => le_trans (H.prodMap' H) (nhds_le_uniformity _), fun H =>
continuousAt_iff'_left.2 <| H.comp <| tendsto_id.prodMk_nhds tendsto_const_nhds⟩
theorem continuousWithinAt_iff'_right [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} :
ContinuousWithinAt f s b ↔ Tendsto (fun x => (f b, f x)) (𝓝[s] b) (𝓤 α) := by
rw [ContinuousWithinAt, tendsto_nhds_right]
theorem continuousWithinAt_iff'_left [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} :
ContinuousWithinAt f s b ↔ Tendsto (fun x => (f x, f b)) (𝓝[s] b) (𝓤 α) := by
rw [ContinuousWithinAt, tendsto_nhds_left]
theorem continuousOn_iff'_right [TopologicalSpace β] {f : β → α} {s : Set β} :
ContinuousOn f s ↔ ∀ b ∈ s, Tendsto (fun x => (f b, f x)) (𝓝[s] b) (𝓤 α) := by
simp [ContinuousOn, continuousWithinAt_iff'_right]
theorem continuousOn_iff'_left [TopologicalSpace β] {f : β → α} {s : Set β} :
ContinuousOn f s ↔ ∀ b ∈ s, Tendsto (fun x => (f x, f b)) (𝓝[s] b) (𝓤 α) := by
simp [ContinuousOn, continuousWithinAt_iff'_left]
theorem continuous_iff'_right [TopologicalSpace β] {f : β → α} :
Continuous f ↔ ∀ b, Tendsto (fun x => (f b, f x)) (𝓝 b) (𝓤 α) :=
continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_right
theorem continuous_iff'_left [TopologicalSpace β] {f : β → α} :
Continuous f ↔ ∀ b, Tendsto (fun x => (f x, f b)) (𝓝 b) (𝓤 α) :=
continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_left
/-- Consider two functions `f` and `g` which coincide on a set `s` and are continuous there.
Then there is an open neighborhood of `s` on which `f` and `g` are uniformly close. -/
lemma exists_is_open_mem_uniformity_of_forall_mem_eq
[TopologicalSpace β] {r : Set (α × α)} {s : Set β}
{f g : β → α} (hf : ∀ x ∈ s, ContinuousAt f x) (hg : ∀ x ∈ s, ContinuousAt g x)
(hfg : s.EqOn f g) (hr : r ∈ 𝓤 α) :
∃ t, IsOpen t ∧ s ⊆ t ∧ ∀ x ∈ t, (f x, g x) ∈ r := by
have A : ∀ x ∈ s, ∃ t, IsOpen t ∧ x ∈ t ∧ ∀ z ∈ t, (f z, g z) ∈ r := by
intro x hx
obtain ⟨t, ht, htsymm, htr⟩ := comp_symm_mem_uniformity_sets hr
have A : {z | (f x, f z) ∈ t} ∈ 𝓝 x := (hf x hx).preimage_mem_nhds (mem_nhds_left (f x) ht)
have B : {z | (g x, g z) ∈ t} ∈ 𝓝 x := (hg x hx).preimage_mem_nhds (mem_nhds_left (g x) ht)
rcases _root_.mem_nhds_iff.1 (inter_mem A B) with ⟨u, hu, u_open, xu⟩
refine ⟨u, u_open, xu, fun y hy ↦ ?_⟩
have I1 : (f y, f x) ∈ t := (htsymm.mk_mem_comm).2 (hu hy).1
have I2 : (g x, g y) ∈ t := (hu hy).2
rw [hfg hx] at I1
exact htr (prodMk_mem_compRel I1 I2)
choose! t t_open xt ht using A
refine ⟨⋃ x ∈ s, t x, isOpen_biUnion t_open, fun x hx ↦ mem_biUnion hx (xt x hx), ?_⟩
rintro x hx
simp only [mem_iUnion, exists_prop] at hx
rcases hx with ⟨y, ys, hy⟩
exact ht y ys x hy
end Uniform
theorem Filter.Tendsto.congr_uniformity {α β} [UniformSpace β] {f g : α → β} {l : Filter α} {b : β}
(hf : Tendsto f l (𝓝 b)) (hg : Tendsto (fun x => (f x, g x)) l (𝓤 β)) : Tendsto g l (𝓝 b) :=
Uniform.tendsto_nhds_right.2 <| (Uniform.tendsto_nhds_right.1 hf).uniformity_trans hg
theorem Uniform.tendsto_congr {α β} [UniformSpace β] {f g : α → β} {l : Filter α} {b : β}
(hfg : Tendsto (fun x => (f x, g x)) l (𝓤 β)) : Tendsto f l (𝓝 b) ↔ Tendsto g l (𝓝 b) :=
⟨fun h => h.congr_uniformity hfg, fun h => h.congr_uniformity hfg.uniformity_symm⟩
| Mathlib/Topology/UniformSpace/Basic.lean | 1,274 | 1,277 | |
/-
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
| Mathlib/LinearAlgebra/Matrix/SesquilinearForm.lean | 546 | 560 |
/-
Copyright (c) 2021 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots
import Mathlib.Tactic.ByContra
import Mathlib.Topology.Algebra.Polynomial
import Mathlib.NumberTheory.Padics.PadicVal.Basic
import Mathlib.Analysis.Complex.Arg
/-!
# Evaluating cyclotomic polynomials
This file states some results about evaluating cyclotomic polynomials in various different ways.
## Main definitions
* `Polynomial.eval(₂)_one_cyclotomic_prime(_pow)`: `eval 1 (cyclotomic p^k R) = p`.
* `Polynomial.eval_one_cyclotomic_not_prime_pow`: Otherwise, `eval 1 (cyclotomic n R) = 1`.
* `Polynomial.cyclotomic_pos` : `∀ x, 0 < eval x (cyclotomic n R)` if `2 < n`.
-/
namespace Polynomial
open Finset Nat
@[simp]
theorem eval_one_cyclotomic_prime {R : Type*} [CommRing R] {p : ℕ} [hn : Fact p.Prime] :
eval 1 (cyclotomic p R) = p := by
simp only [cyclotomic_prime, eval_X, one_pow, Finset.sum_const, eval_pow, eval_finset_sum,
Finset.card_range, smul_one_eq_cast]
theorem eval₂_one_cyclotomic_prime {R S : Type*} [CommRing R] [Semiring S] (f : R →+* S) {p : ℕ}
[Fact p.Prime] : eval₂ f 1 (cyclotomic p R) = p := by simp
@[simp]
theorem eval_one_cyclotomic_prime_pow {R : Type*} [CommRing R] {p : ℕ} (k : ℕ)
[hn : Fact p.Prime] : eval 1 (cyclotomic (p ^ (k + 1)) R) = p := by
simp only [cyclotomic_prime_pow_eq_geom_sum hn.out, eval_X, one_pow, Finset.sum_const, eval_pow,
eval_finset_sum, Finset.card_range, smul_one_eq_cast]
theorem eval₂_one_cyclotomic_prime_pow {R S : Type*} [CommRing R] [Semiring S] (f : R →+* S)
{p : ℕ} (k : ℕ) [Fact p.Prime] : eval₂ f 1 (cyclotomic (p ^ (k + 1)) R) = p := by simp
private theorem cyclotomic_neg_one_pos {n : ℕ} (hn : 2 < n) {R}
[CommRing R] [PartialOrder R] [IsStrictOrderedRing R] :
0 < eval (-1 : R) (cyclotomic n R) := by
haveI := NeZero.of_gt hn
rw [← map_cyclotomic_int, ← Int.cast_one, ← Int.cast_neg, eval_intCast_map, Int.coe_castRingHom,
Int.cast_pos]
suffices 0 < eval (↑(-1 : ℤ)) (cyclotomic n ℝ) by
rw [← map_cyclotomic_int n ℝ, eval_intCast_map, Int.coe_castRingHom] at this
simpa only [Int.cast_pos] using this
simp only [Int.cast_one, Int.cast_neg]
have h0 := cyclotomic_coeff_zero ℝ hn.le
rw [coeff_zero_eq_eval_zero] at h0
by_contra! hx
have := intermediate_value_univ (-1) 0 (cyclotomic n ℝ).continuous
obtain ⟨y, hy : IsRoot _ y⟩ := this (show (0 : ℝ) ∈ Set.Icc _ _ by simpa [h0] using hx)
rw [@isRoot_cyclotomic_iff] at hy
rw [hy.eq_orderOf] at hn
exact hn.not_le LinearOrderedRing.orderOf_le_two
theorem cyclotomic_pos {n : ℕ} (hn : 2 < n) {R}
[CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (x : R) :
0 < eval x (cyclotomic n R) := by
induction' n using Nat.strong_induction_on with n ih
have hn' : 0 < n := pos_of_gt hn
have hn'' : 1 < n := one_lt_two.trans hn
have := prod_cyclotomic_eq_geom_sum hn' R
apply_fun eval x at this
rw [← cons_self_properDivisors hn'.ne', Finset.erase_cons_of_ne _ hn''.ne', Finset.prod_cons,
eval_mul, eval_geom_sum] at this
rcases lt_trichotomy 0 (∑ i ∈ Finset.range n, x ^ i) with (h | h | h)
· apply pos_of_mul_pos_left
· rwa [this]
rw [eval_prod]
refine Finset.prod_nonneg fun i hi => ?_
simp only [Finset.mem_erase, mem_properDivisors] at hi
rw [geom_sum_pos_iff hn'.ne'] at h
rcases h with hk | hx
· refine (ih _ hi.2.2 (Nat.two_lt_of_ne ?_ hi.1 ?_)).le <;> rintro rfl
· exact hn'.ne' (zero_dvd_iff.mp hi.2.1)
· exact not_odd_iff_even.2 (even_iff_two_dvd.mpr hi.2.1) hk
· rcases eq_or_ne i 2 with (rfl | hk)
· simpa only [eval_X, eval_one, cyclotomic_two, eval_add] using hx.le
refine (ih _ hi.2.2 (Nat.two_lt_of_ne ?_ hi.1 hk)).le
rintro rfl
exact hn'.ne' <| zero_dvd_iff.mp hi.2.1
· rw [eq_comm, geom_sum_eq_zero_iff_neg_one hn'.ne'] at h
exact h.1.symm ▸ cyclotomic_neg_one_pos hn
· apply pos_of_mul_neg_left
· rwa [this]
rw [geom_sum_neg_iff hn'.ne'] at h
have h2 : 2 ∈ n.properDivisors.erase 1 := by
rw [Finset.mem_erase, mem_properDivisors]
exact ⟨by decide, even_iff_two_dvd.mp h.1, hn⟩
rw [eval_prod, ← Finset.prod_erase_mul _ _ h2]
apply mul_nonpos_of_nonneg_of_nonpos
· refine Finset.prod_nonneg fun i hi => le_of_lt ?_
simp only [Finset.mem_erase, mem_properDivisors] at hi
refine ih _ hi.2.2.2 (Nat.two_lt_of_ne ?_ hi.2.1 hi.1)
rintro rfl
rw [zero_dvd_iff] at hi
exact hn'.ne' hi.2.2.1
· simpa only [eval_X, eval_one, cyclotomic_two, eval_add] using h.right.le
theorem cyclotomic_pos_and_nonneg (n : ℕ) {R}
[CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (x : R) :
(1 < x → 0 < eval x (cyclotomic n R)) ∧ (1 ≤ x → 0 ≤ eval x (cyclotomic n R)) := by
rcases n with (_ | _ | _ | n)
· simp only [cyclotomic_zero, eval_one, zero_lt_one, implies_true, zero_le_one, and_self]
· simp only [zero_add, cyclotomic_one, eval_sub, eval_X, eval_one, sub_pos, imp_self, sub_nonneg,
and_self]
· simp only [zero_add, reduceAdd, cyclotomic_two, eval_add, eval_X, eval_one]
constructor <;> intro <;> linarith
· constructor <;> intro <;> [skip; apply le_of_lt] <;> apply cyclotomic_pos (by omega)
/-- Cyclotomic polynomials are always positive on inputs larger than one.
Similar to `cyclotomic_pos` but with the condition on the input rather than index of the
cyclotomic polynomial. -/
theorem cyclotomic_pos' (n : ℕ) {R}
[CommRing R] [LinearOrder R] [IsStrictOrderedRing R] {x : R} (hx : 1 < x) :
0 < eval x (cyclotomic n R) :=
(cyclotomic_pos_and_nonneg n x).1 hx
/-- Cyclotomic polynomials are always nonnegative on inputs one or more. -/
theorem cyclotomic_nonneg (n : ℕ) {R}
[CommRing R] [LinearOrder R] [IsStrictOrderedRing R] {x : R} (hx : 1 ≤ x) :
0 ≤ eval x (cyclotomic n R) :=
(cyclotomic_pos_and_nonneg n x).2 hx
theorem eval_one_cyclotomic_not_prime_pow {R : Type*} [Ring R] {n : ℕ}
(h : ∀ {p : ℕ}, p.Prime → ∀ k : ℕ, p ^ k ≠ n) : eval 1 (cyclotomic n R) = 1 := by
rcases n.eq_zero_or_pos with (rfl | hn')
· simp
have hn : 1 < n := one_lt_iff_ne_zero_and_ne_one.mpr ⟨hn'.ne', (h Nat.prime_two 0).symm⟩
rsuffices h | h : eval 1 (cyclotomic n ℤ) = 1 ∨ eval 1 (cyclotomic n ℤ) = -1
· have := eval_intCast_map (Int.castRingHom R) (cyclotomic n ℤ) 1
simpa only [map_cyclotomic, Int.cast_one, h, eq_intCast] using this
· exfalso
linarith [cyclotomic_nonneg n (le_refl (1 : ℤ))]
rw [← Int.natAbs_eq_natAbs_iff, Int.natAbs_one, Nat.eq_one_iff_not_exists_prime_dvd]
intro p hp hpe
haveI := Fact.mk hp
have := prod_cyclotomic_eq_geom_sum hn' ℤ
apply_fun eval 1 at this
rw [eval_geom_sum, one_geom_sum, eval_prod, eq_comm, ←
Finset.prod_sdiff <| @range_pow_padicValNat_subset_divisors' p _ _, Finset.prod_image] at this
· simp_rw [eval_one_cyclotomic_prime_pow, Finset.prod_const, Finset.card_range, mul_comm] at this
rw [← Finset.prod_sdiff <| show {n} ⊆ _ from _] at this
swap
· simp only [singleton_subset_iff, mem_sdiff, mem_erase, Ne, mem_divisors, dvd_refl,
true_and, mem_image, mem_range, exists_prop, not_exists, not_and]
exact ⟨⟨hn.ne', hn'.ne'⟩, fun t _ => h hp _⟩
rw [← Int.natAbs_natCast p, Int.natAbs_dvd_natAbs] at hpe
obtain ⟨t, ht⟩ := hpe
rw [Finset.prod_singleton, ht, mul_left_comm, mul_comm, ← mul_assoc, mul_assoc] at this
have : (p : ℤ) ^ padicValNat p n * p ∣ n := ⟨_, this⟩
simp only [← _root_.pow_succ, ← Int.natAbs_dvd_natAbs, Int.natAbs_natCast,
Int.natAbs_pow] at this
exact pow_succ_padicValNat_not_dvd hn'.ne' this
· rintro x - y - hxy
apply Nat.succ_injective
exact Nat.pow_right_injective hp.two_le hxy
theorem sub_one_pow_totient_lt_cyclotomic_eval {n : ℕ} {q : ℝ} (hn' : 2 ≤ n) (hq' : 1 < q) :
(q - 1) ^ totient n < (cyclotomic n ℝ).eval q := by
have hn : 0 < n := pos_of_gt hn'
have hq := zero_lt_one.trans hq'
have hfor : ∀ ζ' ∈ primitiveRoots n ℂ, q - 1 ≤ ‖↑q - ζ'‖ := by
intro ζ' hζ'
rw [mem_primitiveRoots hn] at hζ'
convert norm_sub_norm_le (↑q) ζ'
· rw [Complex.norm_real, Real.norm_of_nonneg hq.le]
· rw [hζ'.norm'_eq_one hn.ne']
let ζ := Complex.exp (2 * ↑Real.pi * Complex.I / ↑n)
have hζ : IsPrimitiveRoot ζ n := Complex.isPrimitiveRoot_exp n hn.ne'
have hex : ∃ ζ' ∈ primitiveRoots n ℂ, q - 1 < ‖↑q - ζ'‖ := by
refine ⟨ζ, (mem_primitiveRoots hn).mpr hζ, ?_⟩
suffices ¬SameRay ℝ (q : ℂ) ζ by
convert lt_norm_sub_of_not_sameRay this <;>
simp only [hζ.norm'_eq_one hn.ne', Real.norm_of_nonneg hq.le, Complex.norm_real]
rw [Complex.sameRay_iff]
push_neg
refine ⟨mod_cast hq.ne', hζ.ne_zero hn.ne', ?_⟩
rw [Complex.arg_ofReal_of_nonneg hq.le, Ne, eq_comm, hζ.arg_eq_zero_iff hn.ne']
clear_value ζ
rintro rfl
linarith [hζ.unique IsPrimitiveRoot.one]
have : ¬eval (↑q) (cyclotomic n ℂ) = 0 := by simpa using (cyclotomic_pos' n hq').ne'
suffices Units.mk0 (Real.toNNReal (q - 1)) (by simp [hq']) ^ totient n <
Units.mk0 ‖(cyclotomic n ℂ).eval ↑q‖₊ (by simp_all) by
simp [← Units.val_lt_val, Units.val_pow_eq_pow_val, Units.val_mk0, ← NNReal.coe_lt_coe,
hq'.le, Real.toNNReal_lt_toNNReal_iff_of_nonneg, coe_nnnorm, NNReal.coe_pow,
Real.coe_toNNReal', max_eq_left, sub_nonneg] at this
convert this
rw [eq_comm]
simp [cyclotomic_nonneg n hq'.le]
simp only [cyclotomic_eq_prod_X_sub_primitiveRoots hζ, eval_prod, eval_C, eval_X, eval_sub,
nnnorm_prod, Units.mk0_prod]
convert Finset.prod_lt_prod' (M := NNRealˣ) _ _
swap; · exact fun _ => Units.mk0 (Real.toNNReal (q - 1)) (by simp [hq'])
· simp only [Complex.card_primitiveRoots, prod_const, card_attach]
· simp only [Subtype.coe_mk, Finset.mem_attach, forall_true_left, Subtype.forall, ←
Units.val_le_val, ← NNReal.coe_le_coe, norm_nonneg, hq'.le, Units.val_mk0,
Real.coe_toNNReal', coe_nnnorm, max_le_iff, tsub_le_iff_right]
intro x hx
simpa only [and_true, tsub_le_iff_right] using hfor x hx
· simp only [Subtype.coe_mk, Finset.mem_attach, exists_true_left, Subtype.exists, ←
NNReal.coe_lt_coe, ← Units.val_lt_val, Units.val_mk0 _, coe_nnnorm]
simpa [hq'.le, Real.coe_toNNReal', max_eq_left, sub_nonneg] using hex
theorem sub_one_pow_totient_le_cyclotomic_eval {q : ℝ} (hq' : 1 < q) :
∀ n, (q - 1) ^ totient n ≤ (cyclotomic n ℝ).eval q
| 0 => by simp only [totient_zero, _root_.pow_zero, cyclotomic_zero, eval_one, le_refl]
| 1 => by simp only [totient_one, pow_one, cyclotomic_one, eval_sub, eval_X, eval_one, le_refl]
| _ + 2 => (sub_one_pow_totient_lt_cyclotomic_eval le_add_self hq').le
theorem cyclotomic_eval_lt_add_one_pow_totient {n : ℕ} {q : ℝ} (hn' : 3 ≤ n) (hq' : 1 < q) :
(cyclotomic n ℝ).eval q < (q + 1) ^ totient n := by
have hn : 0 < n := pos_of_gt hn'
have hq := zero_lt_one.trans hq'
| have hfor : ∀ ζ' ∈ primitiveRoots n ℂ, ‖↑q - ζ'‖ ≤ q + 1 := by
intro ζ' hζ'
rw [mem_primitiveRoots hn] at hζ'
convert norm_sub_le (↑q) ζ'
· rw [Complex.norm_real, Real.norm_of_nonneg (zero_le_one.trans_lt hq').le]
| Mathlib/RingTheory/Polynomial/Cyclotomic/Eval.lean | 223 | 227 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro
-/
import Mathlib.Algebra.MonoidAlgebra.Degree
import Mathlib.Algebra.MvPolynomial.Rename
/-!
# Degrees of polynomials
This file establishes many results about the degree of a multivariate polynomial.
The *degree set* of a polynomial $P \in R[X]$ is a `Multiset` containing, for each $x$ in the
variable set, $n$ copies of $x$, where $n$ is the maximum number of copies of $x$ appearing in a
monomial of $P$.
## Main declarations
* `MvPolynomial.degrees p` : the multiset of variables representing the union of the multisets
corresponding to each non-zero monomial in `p`.
For example if `7 ≠ 0` in `R` and `p = x²y+7y³` then `degrees p = {x, x, y, y, y}`
* `MvPolynomial.degreeOf n p : ℕ` : the total degree of `p` with respect to the variable `n`.
For example if `p = x⁴y+yz` then `degreeOf y p = 1`.
* `MvPolynomial.totalDegree p : ℕ` :
the max of the sizes of the multisets `s` whose monomials `X^s` occur in `p`.
For example if `p = x⁴y+yz` then `totalDegree p = 5`.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ τ : Type*` (indexing the variables)
+ `R : Type*` `[CommSemiring R]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s`
+ `r : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
universe u v w
variable {R : Type u} {S : Type v}
namespace MvPolynomial
variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
variable [CommSemiring R] {p q : MvPolynomial σ R}
section Degrees
/-! ### `degrees` -/
/-- The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset.
(For example, `degrees (x^2 * y + y^3)` would be `{x, x, y, y, y}`.)
-/
def degrees (p : MvPolynomial σ R) : Multiset σ :=
letI := Classical.decEq σ
p.support.sup fun s : σ →₀ ℕ => toMultiset s
theorem degrees_def [DecidableEq σ] (p : MvPolynomial σ R) :
p.degrees = p.support.sup fun s : σ →₀ ℕ => Finsupp.toMultiset s := by rw [degrees]; convert rfl
theorem degrees_monomial (s : σ →₀ ℕ) (a : R) : degrees (monomial s a) ≤ toMultiset s := by
classical
refine (supDegree_single s a).trans_le ?_
split_ifs
exacts [bot_le, le_rfl]
theorem degrees_monomial_eq (s : σ →₀ ℕ) (a : R) (ha : a ≠ 0) :
degrees (monomial s a) = toMultiset s := by
classical
exact (supDegree_single s a).trans (if_neg ha)
theorem degrees_C (a : R) : degrees (C a : MvPolynomial σ R) = 0 :=
| Multiset.le_zero.1 <| degrees_monomial _ _
theorem degrees_X' (n : σ) : degrees (X n : MvPolynomial σ R) ≤ {n} :=
le_trans (degrees_monomial _ _) <| le_of_eq <| toMultiset_single _ _
| Mathlib/Algebra/MvPolynomial/Degrees.lean | 95 | 98 |
/-
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.Order.Ring.Defs
import Mathlib.Algebra.Field.Defs
/-!
# Linear ordered (semi)fields
A linear ordered (semi)field is a (semi)field equipped with a linear order such that
* addition respects the order: `a ≤ b → c + a ≤ c + b`;
* multiplication of positives is positive: `0 < a → 0 < b → 0 < a * b`;
* `0 < 1`.
## Main Definitions
* `LinearOrderedSemifield`: Typeclass for linear order semifields.
* `LinearOrderedField`: Typeclass for linear ordered fields.
-/
-- Guard against import creep.
assert_not_exists MonoidHom
set_option linter.deprecated false in
/-- A linear ordered semifield is a field with a linear order respecting the operations. -/
@[deprecated "Use `[Semifield K] [LinearOrder K] [IsStrictOrderedRing K]` instead."
(since := "2025-04-10")]
structure LinearOrderedSemifield (K : Type*) extends LinearOrderedCommSemiring K, Semifield K
set_option linter.deprecated false in
/-- A linear ordered field is a field with a linear order respecting the operations. -/
@[deprecated "Use `[Field K] [LinearOrder K] [IsStrictOrderedRing K]` instead."
(since := "2025-04-10")]
structure LinearOrderedField (K : Type*) extends LinearOrderedCommRing K, Field K
attribute [nolint docBlame] LinearOrderedSemifield.toSemifield LinearOrderedField.toField
| Mathlib/Algebra/Order/Field/Defs.lean | 83 | 84 | |
/-
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.Basic
import Mathlib.Algebra.Order.Group.Multiset
import Mathlib.Data.Multiset.FinsetOps
import Mathlib.Data.Multiset.Fold
/-!
# GCD and LCM operations on multisets
## Main definitions
- `Multiset.gcd` - the greatest common denominator of a `Multiset` of elements of a `GCDMonoid`
- `Multiset.lcm` - the least common multiple of a `Multiset` of elements of a `GCDMonoid`
## Implementation notes
TODO: simplify with a tactic and `Data.Multiset.Lattice`
## Tags
multiset, gcd
-/
namespace Multiset
variable {α : Type*} [CancelCommMonoidWithZero α] [NormalizedGCDMonoid α]
/-! ### LCM -/
section lcm
/-- Least common multiple of a multiset -/
def lcm (s : Multiset α) : α :=
s.fold GCDMonoid.lcm 1
@[simp]
theorem lcm_zero : (0 : Multiset α).lcm = 1 :=
fold_zero _ _
@[simp]
theorem lcm_cons (a : α) (s : Multiset α) : (a ::ₘ s).lcm = GCDMonoid.lcm a s.lcm :=
fold_cons_left _ _ _ _
@[simp]
theorem lcm_singleton {a : α} : ({a} : Multiset α).lcm = normalize a :=
(fold_singleton _ _ _).trans <| lcm_one_right _
@[simp]
theorem lcm_add (s₁ s₂ : Multiset α) : (s₁ + s₂).lcm = GCDMonoid.lcm s₁.lcm s₂.lcm :=
Eq.trans (by simp [lcm]) (fold_add _ _ _ _ _)
theorem lcm_dvd {s : Multiset α} {a : α} : s.lcm ∣ a ↔ ∀ b ∈ s, b ∣ a :=
Multiset.induction_on s (by simp)
(by simp +contextual [or_imp, forall_and, lcm_dvd_iff])
theorem dvd_lcm {s : Multiset α} {a : α} (h : a ∈ s) : a ∣ s.lcm :=
lcm_dvd.1 dvd_rfl _ h
theorem lcm_mono {s₁ s₂ : Multiset α} (h : s₁ ⊆ s₂) : s₁.lcm ∣ s₂.lcm :=
lcm_dvd.2 fun _ hb ↦ dvd_lcm (h hb)
@[simp]
theorem normalize_lcm (s : Multiset α) : normalize s.lcm = s.lcm :=
Multiset.induction_on s (by simp) fun a s _ ↦ by simp
@[simp]
nonrec theorem lcm_eq_zero_iff [Nontrivial α] (s : Multiset α) : s.lcm = 0 ↔ (0 : α) ∈ s := by
induction s using Multiset.induction_on with
| empty => simp only [lcm_zero, one_ne_zero, not_mem_zero]
| cons a s ihs => simp only [mem_cons, lcm_cons, lcm_eq_zero_iff, ihs, @eq_comm _ a]
variable [DecidableEq α]
@[simp]
theorem lcm_dedup (s : Multiset α) : (dedup s).lcm = s.lcm :=
Multiset.induction_on s (by simp) fun a s IH ↦ by
by_cases h : a ∈ s <;> simp [IH, h]
unfold lcm
rw [← cons_erase h, fold_cons_left, ← lcm_assoc, lcm_same]
apply lcm_eq_of_associated_left (associated_normalize _)
@[simp]
theorem lcm_ndunion (s₁ s₂ : Multiset α) : (ndunion s₁ s₂).lcm = GCDMonoid.lcm s₁.lcm s₂.lcm := by
rw [← lcm_dedup, dedup_ext.2, lcm_dedup, lcm_add]
simp
@[simp]
theorem lcm_union (s₁ s₂ : Multiset α) : (s₁ ∪ s₂).lcm = GCDMonoid.lcm s₁.lcm s₂.lcm := by
rw [← lcm_dedup, dedup_ext.2, lcm_dedup, lcm_add]
simp
@[simp]
theorem lcm_ndinsert (a : α) (s : Multiset α) : (ndinsert a s).lcm = GCDMonoid.lcm a s.lcm := by
rw [← lcm_dedup, dedup_ext.2, lcm_dedup, lcm_cons]
simp
end lcm
/-! ### GCD -/
section gcd
/-- Greatest common divisor of a multiset -/
def gcd (s : Multiset α) : α :=
s.fold GCDMonoid.gcd 0
@[simp]
theorem gcd_zero : (0 : Multiset α).gcd = 0 :=
fold_zero _ _
@[simp]
theorem gcd_cons (a : α) (s : Multiset α) : (a ::ₘ s).gcd = GCDMonoid.gcd a s.gcd :=
fold_cons_left _ _ _ _
@[simp]
theorem gcd_singleton {a : α} : ({a} : Multiset α).gcd = normalize a :=
(fold_singleton _ _ _).trans <| gcd_zero_right _
@[simp]
theorem gcd_add (s₁ s₂ : Multiset α) : (s₁ + s₂).gcd = GCDMonoid.gcd s₁.gcd s₂.gcd :=
Eq.trans (by simp [gcd]) (fold_add _ _ _ _ _)
theorem dvd_gcd {s : Multiset α} {a : α} : a ∣ s.gcd ↔ ∀ b ∈ s, a ∣ b :=
Multiset.induction_on s (by simp)
(by simp +contextual [or_imp, forall_and, dvd_gcd_iff])
theorem gcd_dvd {s : Multiset α} {a : α} (h : a ∈ s) : s.gcd ∣ a :=
dvd_gcd.1 dvd_rfl _ h
theorem gcd_mono {s₁ s₂ : Multiset α} (h : s₁ ⊆ s₂) : s₂.gcd ∣ s₁.gcd :=
dvd_gcd.2 fun _ hb ↦ gcd_dvd (h hb)
@[simp]
theorem normalize_gcd (s : Multiset α) : normalize s.gcd = s.gcd :=
Multiset.induction_on s (by simp) fun a s _ ↦ by simp
theorem gcd_eq_zero_iff (s : Multiset α) : s.gcd = 0 ↔ ∀ x : α, x ∈ s → x = 0 := by
constructor
· intro h x hx
apply eq_zero_of_zero_dvd
rw [← h]
apply gcd_dvd hx
| · refine s.induction_on ?_ ?_
· simp
| Mathlib/Algebra/GCDMonoid/Multiset.lean | 149 | 150 |
/-
Copyright (c) 2023 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.Shift.Basic
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
/-! Sequences of functors from a category equipped with a shift
Let `F : C ⥤ A` be a functor from a category `C` that is equipped with a
shift by an additive monoid `M`. In this file, we define a typeclass
`F.ShiftSequence M` which includes the data of a sequence of functors
`F.shift a : C ⥤ A` for all `a : A`. For each `a : A`, we have
an isomorphism `F.isoShift a : shiftFunctor C a ⋙ F ≅ F.shift a` which
satisfies some coherence relations. This allows to state results
(e.g. the long exact sequence of an homology functor (TODO)) using
functors `F.shift a` rather than `shiftFunctor C a ⋙ F`. The reason
for this design is that we can often choose functors `F.shift a` that
have better definitional properties than `shiftFunctor C a ⋙ F`.
For example, if `C` is the derived category (TODO) of an abelian
category `A` and `F` is the homology functor in degree `0`, then
for any `n : ℤ`, we may choose `F.shift n` to be the homology functor
in degree `n`.
-/
open CategoryTheory Category ZeroObject Limits
variable {C A : Type*} [Category C] [Category A] (F : C ⥤ A)
(M : Type*) [AddMonoid M] [HasShift C M]
{G : Type*} [AddGroup G] [HasShift C G]
namespace CategoryTheory
namespace Functor
/-- A shift sequence for a functor `F : C ⥤ A` when `C` is equipped with a shift
by a monoid `M` involves a sequence of functor `sequence n : C ⥤ A` for all `n : M`
which behave like `shiftFunctor C n ⋙ F`. -/
class ShiftSequence where
/-- a sequence of functors -/
sequence : M → C ⥤ A
/-- `sequence 0` identifies to the given functor -/
isoZero : sequence 0 ≅ F
/-- compatibility isomorphism with the shift -/
shiftIso (n a a' : M) (ha' : n + a = a') : shiftFunctor C n ⋙ sequence a ≅ sequence a'
shiftIso_zero (a : M) : shiftIso 0 a a (zero_add a) =
isoWhiskerRight (shiftFunctorZero C M) _ ≪≫ leftUnitor _
shiftIso_add : ∀ (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a''),
shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) =
isoWhiskerRight (shiftFunctorAdd C m n) _ ≪≫ Functor.associator _ _ _ ≪≫
isoWhiskerLeft _ (shiftIso n a a' ha') ≪≫ shiftIso m a' a'' ha''
/-- The tautological shift sequence on a functor. -/
noncomputable def ShiftSequence.tautological : ShiftSequence F M where
sequence n := shiftFunctor C n ⋙ F
isoZero := isoWhiskerRight (shiftFunctorZero C M) F ≪≫ F.rightUnitor
shiftIso n a a' ha' := (Functor.associator _ _ _).symm ≪≫
isoWhiskerRight (shiftFunctorAdd' C n a a' ha').symm _
shiftIso_zero a := by
rw [shiftFunctorAdd'_zero_add]
aesop_cat
shiftIso_add n m a a' a'' ha' ha'' := by
ext X
dsimp
simp only [id_comp, ← Functor.map_comp]
congr
simpa only [← cancel_epi ((shiftFunctor C a).map ((shiftFunctorAdd C m n).hom.app X)),
shiftFunctorAdd'_eq_shiftFunctorAdd, ← Functor.map_comp_assoc, Iso.hom_inv_id_app,
Functor.map_id, id_comp] using shiftFunctorAdd'_assoc_inv_app m n a (m+n) a' a'' rfl ha'
(by rw [← ha'', ← ha', add_assoc]) X
section
variable {M}
variable [F.ShiftSequence M]
/-- The shifted functors given by the shift sequence. -/
def shift (n : M) : C ⥤ A := ShiftSequence.sequence F n
/-- Compatibility isomorphism `shiftFunctor C n ⋙ F.shift a ≅ F.shift a'` when `n + a = a'`. -/
def shiftIso (n a a' : M) (ha' : n + a = a') :
shiftFunctor C n ⋙ F.shift a ≅ F.shift a' :=
ShiftSequence.shiftIso n a a' ha'
@[reassoc (attr := simp)]
lemma shiftIso_hom_naturality {X Y : C} (n a a' : M) (ha' : n + a = a') (f : X ⟶ Y) :
(shift F a).map (f⟦n⟧') ≫ (shiftIso F n a a' ha').hom.app Y =
(shiftIso F n a a' ha').hom.app X ≫ (shift F a').map f :=
(F.shiftIso n a a' ha').hom.naturality f
@[reassoc]
lemma shiftIso_inv_naturality {X Y : C} (n a a' : M) (ha' : n + a = a') (f : X ⟶ Y) :
(shift F a').map f ≫ (shiftIso F n a a' ha').inv.app Y =
(shiftIso F n a a' ha').inv.app X ≫ (shift F a).map (f⟦n⟧') := by
simp
variable (M) in
/-- The canonical isomorphism `F.shift 0 ≅ F`. -/
def isoShiftZero : F.shift (0 : M) ≅ F := ShiftSequence.isoZero
/-- The canonical isomorphism `shiftFunctor C n ⋙ F ≅ F.shift n`. -/
def isoShift (n : M) : shiftFunctor C n ⋙ F ≅ F.shift n :=
isoWhiskerLeft _ (F.isoShiftZero M).symm ≪≫ F.shiftIso _ _ _ (add_zero n)
@[reassoc]
lemma isoShift_hom_naturality (n : M) {X Y : C} (f : X ⟶ Y) :
F.map (f⟦n⟧') ≫ (F.isoShift n).hom.app Y =
(F.isoShift n).hom.app X ≫ (F.shift n).map f :=
(F.isoShift n).hom.naturality f
attribute [simp] isoShift_hom_naturality
@[reassoc]
lemma isoShift_inv_naturality (n : M) {X Y : C} (f : X ⟶ Y) :
(F.shift n).map f ≫ (F.isoShift n).inv.app Y =
(F.isoShift n).inv.app X ≫ F.map (f⟦n⟧') :=
(F.isoShift n).inv.naturality f
lemma shiftIso_zero (a : M) :
F.shiftIso 0 a a (zero_add a) =
isoWhiskerRight (shiftFunctorZero C M) _ ≪≫ leftUnitor _ :=
ShiftSequence.shiftIso_zero a
@[simp]
lemma shiftIso_zero_hom_app (a : M) (X : C) :
(F.shiftIso 0 a a (zero_add a)).hom.app X =
(shift F a).map ((shiftFunctorZero C M).hom.app X) := by
simp [F.shiftIso_zero a]
@[simp]
lemma shiftIso_zero_inv_app (a : M) (X : C) :
(F.shiftIso 0 a a (zero_add a)).inv.app X =
(shift F a).map ((shiftFunctorZero C M).inv.app X) := by
simp [F.shiftIso_zero a]
lemma shiftIso_add (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') :
F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) =
isoWhiskerRight (shiftFunctorAdd C m n) _ ≪≫ Functor.associator _ _ _ ≪≫
isoWhiskerLeft _ (F.shiftIso n a a' ha') ≪≫ F.shiftIso m a' a'' ha'' :=
ShiftSequence.shiftIso_add _ _ _ _ _ _ _
lemma shiftIso_add_hom_app (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
(F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).hom.app X =
(shift F a).map ((shiftFunctorAdd C m n).hom.app X) ≫
(shiftIso F n a a' ha').hom.app ((shiftFunctor C m).obj X) ≫
(shiftIso F m a' a'' ha'').hom.app X := by
simp [F.shiftIso_add n m a a' a'' ha' ha'']
lemma shiftIso_add_inv_app (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
(F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).inv.app X =
(shiftIso F m a' a'' ha'').inv.app X ≫
(shiftIso F n a a' ha').inv.app ((shiftFunctor C m).obj X) ≫
(shift F a).map ((shiftFunctorAdd C m n).inv.app X) := by
simp [F.shiftIso_add n m a a' a'' ha' ha'']
lemma shiftIso_add' (n m mn : M) (hnm : m + n = mn) (a a' a'' : M)
(ha' : n + a = a') (ha'' : m + a' = a'') :
F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc]) =
isoWhiskerRight (shiftFunctorAdd' C m n _ hnm) _ ≪≫ Functor.associator _ _ _ ≪≫
isoWhiskerLeft _ (F.shiftIso n a a' ha') ≪≫ F.shiftIso m a' a'' ha'' := by
subst hnm
rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftIso_add]
lemma shiftIso_add'_hom_app (n m mn : M) (hnm : m + n = mn) (a a' a'' : M)
(ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
(F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).hom.app X =
(shift F a).map ((shiftFunctorAdd' C m n mn hnm).hom.app X) ≫
(shiftIso F n a a' ha').hom.app ((shiftFunctor C m).obj X) ≫
(shiftIso F m a' a'' ha'').hom.app X := by
simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha'']
lemma shiftIso_add'_inv_app (n m mn : M) (hnm : m + n = mn) (a a' a'' : M)
(ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
(F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).inv.app X =
(shiftIso F m a' a'' ha'').inv.app X ≫
(shiftIso F n a a' ha').inv.app ((shiftFunctor C m).obj X) ≫
(shift F a).map ((shiftFunctorAdd' C m n mn hnm).inv.app X) := by
simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha'']
@[reassoc]
lemma shiftIso_hom_app_comp (n m mn : M) (hnm : m + n = mn)
(a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
(shiftIso F n a a' ha').hom.app ((shiftFunctor C m).obj X) ≫
| (shiftIso F m a' a'' ha'').hom.app X =
(shift F a).map ((shiftFunctorAdd' C m n mn hnm).inv.app X) ≫
(F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).hom.app X := by
rw [F.shiftIso_add'_hom_app n m mn hnm a a' a'' ha' ha'', ← Functor.map_comp_assoc,
Iso.inv_hom_id_app, Functor.map_id, id_comp]
/-- The morphism `(F.shift a).obj X ⟶ (F.shift a').obj Y` induced by a morphism
`f : X ⟶ Y⟦n⟧` when `n + a = a'`. -/
def shiftMap {X Y : C} {n : M} (f : X ⟶ Y⟦n⟧) (a a' : M) (ha' : n + a = a') :
| Mathlib/CategoryTheory/Shift/ShiftSequence.lean | 186 | 194 |
/-
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, Yury Kudryashov, David Loeffler
-/
import Mathlib.Analysis.Convex.Slope
import Mathlib.Analysis.Calculus.Deriv.MeanValue
/-!
# Convexity of functions and derivatives
Here we relate convexity of functions `ℝ → ℝ` to properties of their derivatives.
## Main results
* `MonotoneOn.convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function
is increasing or its second derivative is nonnegative, then the original function is convex.
* `ConvexOn.monotoneOn_deriv`: if a function is convex and differentiable, then its derivative is
monotone.
-/
open Metric Set Asymptotics ContinuousLinearMap Filter
open scoped Topology NNReal
/-!
## Monotonicity of `f'` implies convexity of `f`
-/
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn ℝ D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z ⊆ D := hD.ordConnected.out hx hz
have hxyD : Icc x y ⊆ D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y ⊆ interior D :=
subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩
have hyzD : Icc y z ⊆ D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z ⊆ interior D :=
subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzD⟩
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b = (f z - f y) / (z - y) :=
exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [← ha, ← hb]
exact hf'_mono (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (hay.trans hyb).le)
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn ℝ D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [← deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : ∀ w ∈ Ioo x y, deriv f w ≠ 0) :
∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn ℝ f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with ⟨b, ⟨hab, hby⟩⟩
refine ⟨b, ⟨hxa.trans hab, hby⟩, ?_⟩
rw [← ha]
exact hf'_mono ⟨hxa, hay⟩ ⟨hxa.trans hab, hby⟩ hab
theorem StrictMonoOn.exists_slope_lt_deriv {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : ∀ w ∈ Ioo x y, deriv f w ≠ 0
· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
· push_neg at h
rcases h with ⟨w, ⟨hxw, hwy⟩, hw⟩
obtain ⟨a, ⟨hxa, haw⟩, ha⟩ : ∃ a ∈ Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
· intro z hz
rw [← hw]
apply ne_of_lt
exact hf'_mono ⟨hz.1, hz.2.trans hwy⟩ ⟨hxw, hwy⟩ hz.2
obtain ⟨b, ⟨hwb, hby⟩, hb⟩ : ∃ b ∈ Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
· refine hf.mono (Icc_subset_Icc hxw.le le_rfl)
· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
· intro z hz
rw [← hw]
apply ne_of_gt
exact hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hz.1, hz.2⟩ hz.1
refine ⟨b, ⟨hxw.trans hwb, hby⟩, ?_⟩
simp only [div_lt_iff₀, hxy, hxw, hwy, sub_pos] at ha hb ⊢
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
· exact hf'_mono ⟨hxa, haw.trans hwy⟩ ⟨hxw.trans hwb, hby⟩ (haw.trans hwb)
· rw [← hw]
exact (hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hwb, hby⟩ hwb).le
linarith
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : ∀ w ∈ Ioo x y, deriv f w ≠ 0) :
∃ a ∈ Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn ℝ f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with ⟨b, ⟨hxb, hba⟩⟩
refine ⟨b, ⟨hxb, hba.trans hay⟩, ?_⟩
rw [← ha]
exact hf'_mono ⟨hxb, hba.trans hay⟩ ⟨hxa, hay⟩ hba
theorem StrictMonoOn.exists_deriv_lt_slope {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
∃ a ∈ Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : ∀ w ∈ Ioo x y, deriv f w ≠ 0
· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
· push_neg at h
rcases h with ⟨w, ⟨hxw, hwy⟩, hw⟩
obtain ⟨a, ⟨hxa, haw⟩, ha⟩ : ∃ a ∈ Ioo x w, deriv f a < (f w - f x) / (w - x) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _
· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
· intro z hz
rw [← hw]
apply ne_of_lt
exact hf'_mono ⟨hz.1, hz.2.trans hwy⟩ ⟨hxw, hwy⟩ hz.2
obtain ⟨b, ⟨hwb, hby⟩, hb⟩ : ∃ b ∈ Ioo w y, deriv f b < (f y - f w) / (y - w) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hwy _ _
· refine hf.mono (Icc_subset_Icc hxw.le le_rfl)
· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
· intro z hz
rw [← hw]
apply ne_of_gt
exact hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hz.1, hz.2⟩ hz.1
refine ⟨a, ⟨hxa, haw.trans hwy⟩, ?_⟩
simp only [lt_div_iff₀, hxy, hxw, hwy, sub_pos] at ha hb ⊢
have : deriv f a * (y - w) < deriv f b * (y - w) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hwy) _
· exact hf'_mono ⟨hxa, haw.trans hwy⟩ ⟨hxw.trans hwb, hby⟩ (haw.trans hwb)
· rw [← hw]
exact (hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hwb, hby⟩ hwb).le
linarith
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, and `f'` is strictly monotone on the
interior, then `f` is strictly convex on `D`.
Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict monotonicity of `f'`. -/
theorem StrictMonoOn.strictConvexOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf' : StrictMonoOn (deriv f) (interior D)) : StrictConvexOn ℝ D f :=
strictConvexOn_of_slope_strict_mono_adjacent hD fun {x y z} hx hz hxy hyz => by
-- First we prove some trivial inclusions
have hxzD : Icc x z ⊆ D := hD.ordConnected.out hx hz
have hxyD : Icc x y ⊆ D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y ⊆ interior D :=
subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩
have hyzD : Icc y z ⊆ D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z ⊆ interior D :=
subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzD⟩
-- Then we get points `a` and `b` in each interval `[x, y]` and `[y, z]` where the derivatives
-- can be compared to the slopes between `x, y` and `y, z` respectively.
obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a :=
StrictMonoOn.exists_slope_lt_deriv (hf.mono hxyD) hxy (hf'.mono hxyD')
obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b < (f z - f y) / (z - y) :=
StrictMonoOn.exists_deriv_lt_slope (hf.mono hyzD) hyz (hf'.mono hyzD')
apply ha.trans (lt_trans _ hb)
exact hf' (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (hay.trans hyb)
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f'` is strictly antitone on the
interior, then `f` is strictly concave on `D`.
Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict antitonicity of `f'`. -/
theorem StrictAntiOn.strictConcaveOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (h_anti : StrictAntiOn (deriv f) (interior D)) :
StrictConcaveOn ℝ D f :=
have : StrictMonoOn (deriv (-f)) (interior D) := by simpa only [← deriv.neg] using h_anti.neg
neg_neg f ▸ (this.strictConvexOn_of_deriv hD hf.neg).neg
/-- If a function `f` is differentiable and `f'` is monotone on `ℝ` then `f` is convex. -/
theorem Monotone.convexOn_univ_of_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f)
(hf'_mono : Monotone (deriv f)) : ConvexOn ℝ univ f :=
(hf'_mono.monotoneOn _).convexOn_of_deriv convex_univ hf.continuous.continuousOn
hf.differentiableOn
/-- If a function `f` is differentiable and `f'` is antitone on `ℝ` then `f` is concave. -/
theorem Antitone.concaveOn_univ_of_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f)
(hf'_anti : Antitone (deriv f)) : ConcaveOn ℝ univ f :=
(hf'_anti.antitoneOn _).concaveOn_of_deriv convex_univ hf.continuous.continuousOn
hf.differentiableOn
/-- If a function `f` is continuous and `f'` is strictly monotone on `ℝ` then `f` is strictly
convex. Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict monotonicity of `f'`. -/
theorem StrictMono.strictConvexOn_univ_of_deriv {f : ℝ → ℝ} (hf : Continuous f)
(hf'_mono : StrictMono (deriv f)) : StrictConvexOn ℝ univ f :=
(hf'_mono.strictMonoOn _).strictConvexOn_of_deriv convex_univ hf.continuousOn
/-- If a function `f` is continuous and `f'` is strictly antitone on `ℝ` then `f` is strictly
concave. Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict antitonicity of `f'`. -/
theorem StrictAnti.strictConcaveOn_univ_of_deriv {f : ℝ → ℝ} (hf : Continuous f)
(hf'_anti : StrictAnti (deriv f)) : StrictConcaveOn ℝ univ f :=
(hf'_anti.strictAntiOn _).strictConcaveOn_of_deriv convex_univ hf.continuousOn
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its
interior, and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/
theorem convexOn_of_deriv2_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D)
(hf' : DifferentiableOn ℝ f (interior D)) (hf'' : DifferentiableOn ℝ (deriv f) (interior D))
(hf''_nonneg : ∀ x ∈ interior D, 0 ≤ deriv^[2] f x) : ConvexOn ℝ D f :=
(monotoneOn_of_deriv_nonneg hD.interior hf''.continuousOn (by rwa [interior_interior]) <| by
rwa [interior_interior]).convexOn_of_deriv
hD hf hf'
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its
interior, and `f''` is nonpositive on the interior, then `f` is concave on `D`. -/
theorem concaveOn_of_deriv2_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D)
(hf' : DifferentiableOn ℝ f (interior D)) (hf'' : DifferentiableOn ℝ (deriv f) (interior D))
(hf''_nonpos : ∀ x ∈ interior D, deriv^[2] f x ≤ 0) : ConcaveOn ℝ D f :=
(antitoneOn_of_deriv_nonpos hD.interior hf''.continuousOn (by rwa [interior_interior]) <| by
rwa [interior_interior]).concaveOn_of_deriv
hD hf hf'
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its
interior, and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/
lemma convexOn_of_hasDerivWithinAt2_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f f' f'' : ℝ → ℝ}
(hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x)
(hf'' : ∀ x ∈ interior D, HasDerivWithinAt f' (f'' x) (interior D) x)
(hf''₀ : ∀ x ∈ interior D, 0 ≤ f'' x) : ConvexOn ℝ D f := by
have : (interior D).EqOn (deriv f) f' := deriv_eqOn isOpen_interior hf'
refine convexOn_of_deriv2_nonneg hD hf (fun x hx ↦ (hf' _ hx).differentiableWithinAt) ?_ ?_
· rw [differentiableOn_congr this]
exact fun x hx ↦ (hf'' _ hx).differentiableWithinAt
· rintro x hx
convert hf''₀ _ hx using 1
dsimp
rw [deriv_eqOn isOpen_interior (fun y hy ↦ ?_) hx]
exact (hf'' _ hy).congr this <| by rw [this hy]
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its
interior, and `f''` is nonpositive on the interior, then `f` is concave on `D`. -/
lemma concaveOn_of_hasDerivWithinAt2_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f f' f'' : ℝ → ℝ}
(hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x)
(hf'' : ∀ x ∈ interior D, HasDerivWithinAt f' (f'' x) (interior D) x)
(hf''₀ : ∀ x ∈ interior D, f'' x ≤ 0) : ConcaveOn ℝ D f := by
have : (interior D).EqOn (deriv f) f' := deriv_eqOn isOpen_interior hf'
refine concaveOn_of_deriv2_nonpos hD hf (fun x hx ↦ (hf' _ hx).differentiableWithinAt) ?_ ?_
· rw [differentiableOn_congr this]
exact fun x hx ↦ (hf'' _ hx).differentiableWithinAt
· rintro x hx
convert hf''₀ _ hx using 1
dsimp
rw [deriv_eqOn isOpen_interior (fun y hy ↦ ?_) hx]
exact (hf'' _ hy).congr this <| by rw [this hy]
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly positive on the
interior, then `f` is strictly convex on `D`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly positive, except at at most one point. -/
theorem strictConvexOn_of_deriv2_pos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf'' : ∀ x ∈ interior D, 0 < (deriv^[2] f) x) :
StrictConvexOn ℝ D f :=
((strictMonoOn_of_deriv_pos hD.interior fun z hz =>
(differentiableAt_of_deriv_ne_zero
(hf'' z hz).ne').differentiableWithinAt.continuousWithinAt) <|
by rwa [interior_interior]).strictConvexOn_of_deriv
hD hf
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly negative on the
interior, then `f` is strictly concave on `D`.
Note that we don't require twice differentiability explicitly as it already implied by the second
derivative being strictly negative, except at at most one point. -/
theorem strictConcaveOn_of_deriv2_neg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf'' : ∀ x ∈ interior D, deriv^[2] f x < 0) :
StrictConcaveOn ℝ D f :=
((strictAntiOn_of_deriv_neg hD.interior fun z hz =>
(differentiableAt_of_deriv_ne_zero
(hf'' z hz).ne).differentiableWithinAt.continuousWithinAt) <|
by rwa [interior_interior]).strictConcaveOn_of_deriv
hD hf
/-- If a function `f` is twice differentiable on an open convex set `D ⊆ ℝ` and
`f''` is nonnegative on `D`, then `f` is convex on `D`. -/
theorem convexOn_of_deriv2_nonneg' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf' : DifferentiableOn ℝ f D) (hf'' : DifferentiableOn ℝ (deriv f) D)
(hf''_nonneg : ∀ x ∈ D, 0 ≤ (deriv^[2] f) x) : ConvexOn ℝ D f :=
convexOn_of_deriv2_nonneg hD hf'.continuousOn (hf'.mono interior_subset)
(hf''.mono interior_subset) fun x hx => hf''_nonneg x (interior_subset hx)
/-- If a function `f` is twice differentiable on an open convex set `D ⊆ ℝ` and
`f''` is nonpositive on `D`, then `f` is concave on `D`. -/
theorem concaveOn_of_deriv2_nonpos' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf' : DifferentiableOn ℝ f D) (hf'' : DifferentiableOn ℝ (deriv f) D)
(hf''_nonpos : ∀ x ∈ D, deriv^[2] f x ≤ 0) : ConcaveOn ℝ D f :=
concaveOn_of_deriv2_nonpos hD hf'.continuousOn (hf'.mono interior_subset)
(hf''.mono interior_subset) fun x hx => hf''_nonpos x (interior_subset hx)
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly positive on `D`,
then `f` is strictly convex on `D`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly positive, except at at most one point. -/
theorem strictConvexOn_of_deriv2_pos' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf'' : ∀ x ∈ D, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ D f :=
strictConvexOn_of_deriv2_pos hD hf fun x hx => hf'' x (interior_subset hx)
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly negative on `D`,
then `f` is strictly concave on `D`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly negative, except at at most one point. -/
theorem strictConcaveOn_of_deriv2_neg' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf'' : ∀ x ∈ D, deriv^[2] f x < 0) : StrictConcaveOn ℝ D f :=
strictConcaveOn_of_deriv2_neg hD hf fun x hx => hf'' x (interior_subset hx)
/-- If a function `f` is twice differentiable on `ℝ`, and `f''` is nonnegative on `ℝ`,
then `f` is convex on `ℝ`. -/
theorem convexOn_univ_of_deriv2_nonneg {f : ℝ → ℝ} (hf' : Differentiable ℝ f)
(hf'' : Differentiable ℝ (deriv f)) (hf''_nonneg : ∀ x, 0 ≤ (deriv^[2] f) x) :
ConvexOn ℝ univ f :=
convexOn_of_deriv2_nonneg' convex_univ hf'.differentiableOn hf''.differentiableOn fun x _ =>
hf''_nonneg x
/-- If a function `f` is twice differentiable on `ℝ`, and `f''` is nonpositive on `ℝ`,
then `f` is concave on `ℝ`. -/
theorem concaveOn_univ_of_deriv2_nonpos {f : ℝ → ℝ} (hf' : Differentiable ℝ f)
(hf'' : Differentiable ℝ (deriv f)) (hf''_nonpos : ∀ x, deriv^[2] f x ≤ 0) :
ConcaveOn ℝ univ f :=
concaveOn_of_deriv2_nonpos' convex_univ hf'.differentiableOn hf''.differentiableOn fun x _ =>
hf''_nonpos x
/-- If a function `f` is continuous on `ℝ`, and `f''` is strictly positive on `ℝ`,
then `f` is strictly convex on `ℝ`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly positive, except at at most one point. -/
theorem strictConvexOn_univ_of_deriv2_pos {f : ℝ → ℝ} (hf : Continuous f)
(hf'' : ∀ x, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ univ f :=
strictConvexOn_of_deriv2_pos' convex_univ hf.continuousOn fun x _ => hf'' x
/-- If a function `f` is continuous on `ℝ`, and `f''` is strictly negative on `ℝ`,
then `f` is strictly concave on `ℝ`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly negative, except at at most one point. -/
theorem strictConcaveOn_univ_of_deriv2_neg {f : ℝ → ℝ} (hf : Continuous f)
(hf'' : ∀ x, deriv^[2] f x < 0) : StrictConcaveOn ℝ univ f :=
strictConcaveOn_of_deriv2_neg' convex_univ hf.continuousOn fun x _ => hf'' x
/-!
## Convexity of `f` implies monotonicity of `f'`
In this section we prove inequalities relating derivatives of convex functions to slopes of secant
lines, and deduce that if `f` is convex then its derivative is monotone (and similarly for strict
convexity / strict monotonicity).
-/
section slope
variable {𝕜 : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜]
{s : Set 𝕜} {f : 𝕜 → 𝕜} {x : 𝕜}
/-- If `f : 𝕜 → 𝕜` is convex on `s`, then for any point `x ∈ s` the slope of the secant line of `f`
through `x` is monotone on `s \ {x}`. -/
lemma ConvexOn.slope_mono (hfc : ConvexOn 𝕜 s f) (hx : x ∈ s) : MonotoneOn (slope f x) (s \ {x}) :=
(slope_fun_def_field f _).symm ▸ fun _ hy _ hz hz' ↦ hfc.secant_mono hx (mem_of_mem_diff hy)
(mem_of_mem_diff hz) (not_mem_of_mem_diff hy :) (not_mem_of_mem_diff hz :) hz'
lemma ConvexOn.monotoneOn_slope_gt (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ s) :
MonotoneOn (slope f x) {y ∈ s | x < y} :=
(hfc.slope_mono hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne'⟩
lemma ConvexOn.monotoneOn_slope_lt (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ s) :
MonotoneOn (slope f x) {y ∈ s | y < x} :=
(hfc.slope_mono hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne⟩
/-- If `f : 𝕜 → 𝕜` is concave on `s`, then for any point `x ∈ s` the slope of the secant line of `f`
through `x` is antitone on `s \ {x}`. -/
lemma ConcaveOn.slope_anti (hfc : ConcaveOn 𝕜 s f) (hx : x ∈ s) :
AntitoneOn (slope f x) (s \ {x}) := by
rw [← neg_neg f, slope_neg_fun]
exact (ConvexOn.slope_mono hfc.neg hx).neg
lemma ConcaveOn.antitoneOn_slope_gt (hfc : ConcaveOn 𝕜 s f) (hxs : x ∈ s) :
AntitoneOn (slope f x) {y ∈ s | x < y} :=
(hfc.slope_anti hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne'⟩
lemma ConcaveOn.antitoneOn_slope_lt (hfc : ConcaveOn 𝕜 s f) (hxs : x ∈ s) :
AntitoneOn (slope f x) {y ∈ s | y < x} :=
(hfc.slope_anti hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne⟩
variable [TopologicalSpace 𝕜] [OrderTopology 𝕜]
lemma bddBelow_slope_lt_of_mem_interior (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ interior s) :
BddBelow (slope f x '' {y ∈ s | x < y}) := by
obtain ⟨y, hyx, hys⟩ : ∃ y, y < x ∧ y ∈ s :=
Eventually.exists_lt (mem_interior_iff_mem_nhds.mp hxs)
refine bddBelow_iff_subset_Ici.mpr ⟨slope f x y, fun y' ⟨z, hz, hz'⟩ ↦ ?_⟩
simp_rw [mem_Ici, ← hz']
refine hfc.slope_mono (interior_subset hxs) ?_ ?_ (hyx.trans hz.2).le
· simp [hys, hyx.ne]
· simp [hz.2.ne', hz.1]
lemma bddAbove_slope_gt_of_mem_interior (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ interior s) :
BddAbove (slope f x '' {y ∈ s | y < x}) := by
obtain ⟨y, hyx, hys⟩ : ∃ y, x < y ∧ y ∈ s :=
Eventually.exists_gt (mem_interior_iff_mem_nhds.mp hxs)
refine bddAbove_iff_subset_Iic.mpr ⟨slope f x y, fun y' ⟨z, hz, hz'⟩ ↦ ?_⟩
simp_rw [mem_Iic, ← hz']
refine hfc.slope_mono (interior_subset hxs) ?_ ?_ (hz.2.trans hyx).le
· simp [hz.2.ne, hz.1]
· simp [hys, hyx.ne']
end slope
namespace ConvexOn
variable {S : Set ℝ} {f : ℝ → ℝ} {x y f' : ℝ}
section Interior
/-!
### Left and right derivative of a convex function in the interior of the set
-/
lemma hasDerivWithinAt_sInf_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
HasDerivWithinAt f (sInf (slope f x '' {y ∈ S | x < y})) (Ioi x) x := by
have hxs' := hxs
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs'
obtain ⟨a, b, hxab, habs⟩ := hxs'
simp_rw [hasDerivWithinAt_iff_tendsto_slope]
simp only [mem_Ioi, lt_self_iff_false, not_false_eq_true, diff_singleton_eq_self]
have h : Ioo x b ⊆ {y | y ∈ S ∧ x < y} := fun z hz ↦ ⟨habs ⟨hxab.1.trans hz.1, hz.2⟩, hz.1⟩
have h_Ioo : Tendsto (slope f x) (𝓝[>] x) (𝓝 (sInf (slope f x '' Ioo x b))) :=
((monotoneOn_slope_gt hfc (habs hxab)).mono h).tendsto_nhdsWithin_Ioo_right
(by simpa using hxab.2) ((bddBelow_slope_lt_of_mem_interior hfc hxs).mono (image_subset _ h))
suffices sInf (slope f x '' Ioo x b) = sInf (slope f x '' {y ∈ S | x < y}) by rwa [← this]
apply (monotoneOn_slope_gt hfc (habs hxab)).csInf_eq_of_subset_of_forall_exists_le
(bddBelow_slope_lt_of_mem_interior hfc hxs) h ?_
rintro y ⟨hyS, hxy⟩
obtain ⟨z, hxz, hzy⟩ := exists_between (lt_min hxab.2 hxy)
exact ⟨z, ⟨hxz, hzy.trans_le (min_le_left _ _)⟩, hzy.le.trans (min_le_right _ _)⟩
lemma hasDerivWithinAt_sSup_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
HasDerivWithinAt f (sSup (slope f x '' {y ∈ S | y < x})) (Iio x) x := by
have hxs' := hxs
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs'
obtain ⟨a, b, hxab, habs⟩ := hxs'
simp_rw [hasDerivWithinAt_iff_tendsto_slope]
simp only [mem_Iio, lt_self_iff_false, not_false_eq_true, diff_singleton_eq_self]
have h : Ioo a x ⊆ {y | y ∈ S ∧ y < x} := fun z hz ↦ ⟨habs ⟨hz.1, hz.2.trans hxab.2⟩, hz.2⟩
have h_Ioo : Tendsto (slope f x) (𝓝[<] x) (𝓝 (sSup (slope f x '' Ioo a x))) :=
((monotoneOn_slope_lt hfc (habs hxab)).mono h).tendsto_nhdsWithin_Ioo_left
(by simpa using hxab.1) ((bddAbove_slope_gt_of_mem_interior hfc hxs).mono (image_subset _ h))
suffices sSup (slope f x '' Ioo a x) = sSup (slope f x '' {y ∈ S | y < x}) by rwa [← this]
apply (monotoneOn_slope_lt hfc (habs hxab)).csSup_eq_of_subset_of_forall_exists_le
(bddAbove_slope_gt_of_mem_interior hfc hxs) h ?_
rintro y ⟨hyS, hyx⟩
obtain ⟨z, hyz, hzx⟩ := exists_between (max_lt hxab.1 hyx)
exact ⟨z, ⟨(le_max_left _ _).trans_lt hyz, hzx⟩, (le_max_right _ _).trans hyz.le⟩
lemma differentiableWithinAt_Ioi_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
DifferentiableWithinAt ℝ f (Ioi x) x :=
(hfc.hasDerivWithinAt_sInf_slope_of_mem_interior hxs).differentiableWithinAt
lemma differentiableWithinAt_Iio_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
DifferentiableWithinAt ℝ f (Iio x) x :=
(hfc.hasDerivWithinAt_sSup_slope_of_mem_interior hxs).differentiableWithinAt
lemma hasDerivWithinAt_rightDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
HasDerivWithinAt f (derivWithin f (Ioi x) x) (Ioi x) x :=
(hfc.differentiableWithinAt_Ioi_of_mem_interior hxs).hasDerivWithinAt
lemma hasDerivWithinAt_leftDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
HasDerivWithinAt f (derivWithin f (Iio x) x) (Iio x) x :=
(hfc.differentiableWithinAt_Iio_of_mem_interior hxs).hasDerivWithinAt
lemma rightDeriv_eq_sInf_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
derivWithin f (Ioi x) x = sInf (slope f x '' {y | y ∈ S ∧ x < y}) :=
(hfc.hasDerivWithinAt_sInf_slope_of_mem_interior hxs).derivWithin (uniqueDiffWithinAt_Ioi x)
lemma leftDeriv_eq_sSup_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
derivWithin f (Iio x) x = sSup (slope f x '' {y | y ∈ S ∧ y < x}) :=
(hfc.hasDerivWithinAt_sSup_slope_of_mem_interior hxs).derivWithin (uniqueDiffWithinAt_Iio x)
lemma monotoneOn_rightDeriv (hfc : ConvexOn ℝ S f) :
MonotoneOn (fun x ↦ derivWithin f (Ioi x) x) (interior S) := by
intro x hxs y hys hxy
rcases eq_or_lt_of_le hxy with rfl | hxy; · rfl
simp_rw [hfc.rightDeriv_eq_sInf_slope_of_mem_interior hxs,
hfc.rightDeriv_eq_sInf_slope_of_mem_interior hys]
refine csInf_le_of_le (b := slope f x y) (bddBelow_slope_lt_of_mem_interior hfc hxs)
⟨y, by simp only [mem_setOf_eq, hxy, and_true]; exact interior_subset hys⟩
(le_csInf ?_ ?_)
· have hys' := hys
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hys'
obtain ⟨a, b, hxab, habs⟩ := hys'
rw [image_nonempty]
obtain ⟨z, hxz, hzb⟩ := exists_between hxab.2
exact ⟨z, habs ⟨hxab.1.trans hxz, hzb⟩, hxz⟩
· rintro _ ⟨z, ⟨hzs, hyz : y < z⟩, rfl⟩
rw [slope_comm]
exact slope_mono hfc (interior_subset hys) ⟨interior_subset hxs, hxy.ne⟩ ⟨hzs, hyz.ne'⟩
(hxy.trans hyz).le
lemma monotoneOn_leftDeriv (hfc : ConvexOn ℝ S f) :
MonotoneOn (fun x ↦ derivWithin f (Iio x) x) (interior S) := by
intro x hxs y hys hxy
rcases eq_or_lt_of_le hxy with rfl | hxy; · rfl
simp_rw [hfc.leftDeriv_eq_sSup_slope_of_mem_interior hxs,
hfc.leftDeriv_eq_sSup_slope_of_mem_interior hys]
refine le_csSup_of_le (b := slope f x y) (bddAbove_slope_gt_of_mem_interior hfc hys)
⟨x, by simp only [slope_comm, mem_setOf_eq, hxy, and_true]; exact interior_subset hxs⟩
(csSup_le ?_ ?_)
· have hxs' := hxs
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs'
obtain ⟨a, b, hxab, habs⟩ := hxs'
rw [image_nonempty]
obtain ⟨z, hxz, hzb⟩ := exists_between hxab.1
exact ⟨z, habs ⟨hxz, hzb.trans hxab.2⟩, hzb⟩
· rintro _ ⟨z, ⟨hzs, hyz : z < x⟩, rfl⟩
exact slope_mono hfc (interior_subset hxs) ⟨hzs, hyz.ne⟩ ⟨interior_subset hys, hxy.ne'⟩
(hyz.trans hxy).le
lemma leftDeriv_le_rightDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
derivWithin f (Iio x) x ≤ derivWithin f (Ioi x) x := by
have hxs' := hxs
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs'
obtain ⟨a, b, hxab, habs⟩ := hxs'
rw [hfc.rightDeriv_eq_sInf_slope_of_mem_interior hxs,
hfc.leftDeriv_eq_sSup_slope_of_mem_interior hxs]
refine csSup_le ?_ ?_
· rw [image_nonempty]
obtain ⟨z, haz, hzx⟩ := exists_between hxab.1
exact ⟨z, habs ⟨haz, hzx.trans hxab.2⟩, hzx⟩
rintro _ ⟨z, ⟨hzs, hzx⟩, rfl⟩
refine le_csInf ?_ ?_
· rw [image_nonempty]
obtain ⟨z, hxz, hzb⟩ := exists_between hxab.2
exact ⟨z, habs ⟨hxab.1.trans hxz, hzb⟩, hxz⟩
rintro _ ⟨y, ⟨hys, hxy⟩, rfl⟩
exact slope_mono hfc (interior_subset hxs) ⟨hzs, hzx.ne⟩ ⟨hys, hxy.ne'⟩ (hzx.trans hxy).le
end Interior
section left
/-!
### Convex functions, derivative at left endpoint of secant
-/
/-- If `f : ℝ → ℝ` is convex on `S` and right-differentiable at `x ∈ S`, then the slope of any
secant line with left endpoint at `x` is bounded below by the right derivative of `f` at `x`. -/
lemma le_slope_of_hasDerivWithinAt_Ioi (hfc : ConvexOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) :
f' ≤ slope f x y := by
apply le_of_tendsto <| (hasDerivWithinAt_iff_tendsto_slope' not_mem_Ioi_self).mp hf'
simp_rw [eventually_nhdsWithin_iff, slope_def_field]
filter_upwards [eventually_lt_nhds hxy] with t ht (ht' : x < t)
refine hfc.secant_mono hx (?_ : t ∈ S) hy ht'.ne' hxy.ne' ht.le
exact hfc.1.ordConnected.out hx hy ⟨ht'.le, ht.le⟩
/-- Reformulation of `ConvexOn.le_slope_of_hasDerivWithinAt_Ioi` using `derivWithin`. -/
lemma rightDeriv_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f (Ioi x) x) :
derivWithin f (Ioi x) x ≤ slope f x y :=
le_slope_of_hasDerivWithinAt_Ioi hfc hx hy hxy hfd.hasDerivWithinAt
@[deprecated (since := "2025-01-26")]
alias right_deriv_le_slope := rightDeriv_le_slope
lemma rightDeriv_le_slope_of_mem_interior (hfc : ConvexOn ℝ S f)
{y : ℝ} (hxs : x ∈ interior S) (hys : y ∈ S) (hxy : x < y) :
derivWithin f (Ioi x) x ≤ slope f x y :=
rightDeriv_le_slope hfc (interior_subset hxs) hys hxy
(differentiableWithinAt_Ioi_of_mem_interior hfc hxs)
/-- If `f : ℝ → ℝ` is convex on `S` and differentiable within `S` at `x`, then the slope of any
secant line with left endpoint at `x` is bounded below by the derivative of `f` within `S` at `x`.
This is fractionally weaker than `ConvexOn.le_slope_of_hasDerivWithinAt_Ioi` but simpler to apply
under a `DifferentiableOn S` hypothesis. -/
lemma le_slope_of_hasDerivWithinAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hf' : HasDerivWithinAt f f' S x) :
f' ≤ slope f x y :=
hfc.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy <|
hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsGT hx hy hxy
/-- Reformulation of `ConvexOn.le_slope_of_hasDerivWithinAt` using `derivWithin`. -/
lemma derivWithin_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f S x) :
derivWithin f S x ≤ slope f x y :=
le_slope_of_hasDerivWithinAt hfc hx hy hxy hfd.hasDerivWithinAt
/-- If `f : ℝ → ℝ` is convex on `S` and differentiable at `x ∈ S`, then the slope of any secant
line with left endpoint at `x` is bounded below by the derivative of `f` at `x`. -/
lemma le_slope_of_hasDerivAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(ha : HasDerivAt f f' x) :
f' ≤ slope f x y :=
hfc.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy ha.hasDerivWithinAt
/-- Reformulation of `ConvexOn.le_slope_of_hasDerivAt` using `deriv` -/
lemma deriv_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableAt ℝ f x) :
deriv f x ≤ slope f x y :=
le_slope_of_hasDerivAt hfc hx hy hxy hfd.hasDerivAt
end left
section right
/-!
### Convex functions, derivative at right endpoint of secant
-/
/-- If `f : ℝ → ℝ` is convex on `S` and left-differentiable at `y ∈ S`, then the slope of any secant
line with right endpoint at `y` is bounded above by the left derivative of `f` at `y`. -/
lemma slope_le_of_hasDerivWithinAt_Iio (hfc : ConvexOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) :
slope f x y ≤ f' := by
apply ge_of_tendsto <| (hasDerivWithinAt_iff_tendsto_slope' not_mem_Iio_self).mp hf'
simp_rw [eventually_nhdsWithin_iff, slope_comm f x y, slope_def_field]
filter_upwards [eventually_gt_nhds hxy] with t ht (ht' : t < y)
refine hfc.secant_mono hy hx (?_ : t ∈ S) hxy.ne ht'.ne ht.le
exact hfc.1.ordConnected.out hx hy ⟨ht.le, ht'.le⟩
/-- Reformulation of `ConvexOn.slope_le_of_hasDerivWithinAt_Iio` using `derivWithin`. -/
lemma slope_le_leftDeriv (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f (Iio y) y) :
slope f x y ≤ derivWithin f (Iio y) y :=
hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt
@[deprecated (since := "2025-01-26")]
alias slope_le_left_deriv := slope_le_leftDeriv
lemma slope_le_leftDeriv_of_mem_interior (hfc : ConvexOn ℝ S f)
(hys : x ∈ S) (hxs : y ∈ interior S) (hxy : x < y) :
slope f x y ≤ derivWithin f (Iio y) y :=
slope_le_leftDeriv hfc hys (interior_subset hxs) hxy
(differentiableWithinAt_Iio_of_mem_interior hfc hxs)
/-- If `f : ℝ → ℝ` is convex on `S` and differentiable within `S` at `y`, then the slope of any
secant line with right endpoint at `y` is bounded above by the derivative of `f` within `S` at `y`.
This is fractionally weaker than `ConvexOn.slope_le_of_hasDerivWithinAt_Iio` but simpler to apply
under a `DifferentiableOn S` hypothesis. -/
lemma slope_le_of_hasDerivWithinAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hf' : HasDerivWithinAt f f' S y) :
slope f x y ≤ f' :=
hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy <|
hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsLT hx hy hxy
/-- Reformulation of `ConvexOn.slope_le_of_hasDerivWithinAt` using `derivWithin`. -/
lemma slope_le_derivWithin (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f S y) :
slope f x y ≤ derivWithin f S y :=
hfc.slope_le_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt
/-- If `f : ℝ → ℝ` is convex on `S` and differentiable at `y ∈ S`, then the slope of any secant
line with right endpoint at `y` is bounded above by the derivative of `f` at `y`. -/
lemma slope_le_of_hasDerivAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hf' : HasDerivAt f f' y) :
slope f x y ≤ f' :=
hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt
|
/-- Reformulation of `ConvexOn.slope_le_of_hasDerivAt` using `deriv`. -/
lemma slope_le_deriv (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableAt ℝ f y) :
slope f x y ≤ deriv f y :=
hfc.slope_le_of_hasDerivAt hx hy hxy hfd.hasDerivAt
| Mathlib/Analysis/Convex/Deriv.lean | 663 | 668 |
/-
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.Algebra.BigOperators.Fin
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Finset.Sort
/-!
# Compositions
A composition of a natural number `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum
of positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into
non-empty blocks of consecutive integers, where the `iⱼ` are the lengths of the blocks.
This notion is closely related to that of a partition of `n`, but in a composition of `n` the
order of the `iⱼ`s matters.
We implement two different structures covering these two viewpoints on compositions. The first
one, made of a list of positive integers summing to `n`, is the main one and is called
`Composition n`. The second one is useful for combinatorial arguments (for instance to show that
the number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}`
containing `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost
points of each block. The main API is built on `Composition n`, and we provide an equivalence
between the two types.
## Main functions
* `c : Composition n` is a structure, made of a list of integers which are all positive and
add up to `n`.
* `composition_card` states that the cardinality of `Composition n` is exactly
`2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which
is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is
nat subtraction).
Let `c : Composition n` be a composition of `n`. Then
* `c.blocks` is the list of blocks in `c`.
* `c.length` is the number of blocks in the composition.
* `c.blocksFun : Fin c.length → ℕ` is the realization of `c.blocks` as a function on
`Fin c.length`. This is the main object when using compositions to understand the composition of
analytic functions.
* `c.sizeUpTo : ℕ → ℕ` is the sum of the size of the blocks up to `i`.;
* `c.embedding i : Fin (c.blocksFun i) → Fin n` is the increasing embedding of the `i`-th block in
`Fin n`;
* `c.index j`, for `j : Fin n`, is the index of the block containing `j`.
* `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`.
* `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`.
Compositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition
of `n`.
* `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the
blocks of `c`.
* `join_splitWrtComposition` states that splitting a list and then joining it gives back the
original list.
* `splitWrtComposition_join` states that joining a list of lists, and then splitting it back
according to the right composition, gives back the original list of lists.
We turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`.
`c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries`
and proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not
make sense in the edge case `n = 0`, while the previous description works in all cases).
The elements of this set (other than `n`) correspond to leftmost points of blocks.
Thus, there is an equiv between `Composition n` and `CompositionAsSet n`. We
only construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able
to construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv
between `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n`
from a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that
`CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)`
(see `compositionAsSet_card` and `composition_card`).
## Implementation details
The main motivation for this structure and its API is in the construction of the composition of
formal multilinear series, and the proof that the composition of analytic functions is analytic.
The representation of a composition as a list is very handy as lists are very flexible and already
have a well-developed API.
## Tags
Composition, partition
## References
<https://en.wikipedia.org/wiki/Composition_(combinatorics)>
-/
assert_not_exists Field
open List
variable {n : ℕ}
/-- A composition of `n` is a list of positive integers summing to `n`. -/
@[ext]
structure Composition (n : ℕ) where
/-- List of positive integers summing to `n` -/
blocks : List ℕ
/-- Proof of positivity for `blocks` -/
blocks_pos : ∀ {i}, i ∈ blocks → 0 < i
/-- Proof that `blocks` sums to `n` -/
blocks_sum : blocks.sum = n
deriving DecidableEq
attribute [simp] Composition.blocks_sum
/-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of
consecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding
a finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and
get a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure
`CompositionAsSet n`. -/
@[ext]
structure CompositionAsSet (n : ℕ) where
/-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}` -/
boundaries : Finset (Fin n.succ)
/-- Proof that `0` is a member of `boundaries` -/
zero_mem : (0 : Fin n.succ) ∈ boundaries
/-- Last element of the composition -/
getLast_mem : Fin.last n ∈ boundaries
deriving DecidableEq
instance {n : ℕ} : Inhabited (CompositionAsSet n) :=
⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩
attribute [simp] CompositionAsSet.zero_mem CompositionAsSet.getLast_mem
/-!
### Compositions
A composition of an integer `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of
positive integers.
-/
namespace Composition
variable (c : Composition n)
instance (n : ℕ) : ToString (Composition n) :=
⟨fun c => toString c.blocks⟩
/-- The length of a composition, i.e., the number of blocks in the composition. -/
abbrev length : ℕ :=
c.blocks.length
theorem blocks_length : c.blocks.length = c.length :=
rfl
/-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic
functions using compositions, this is the main player. -/
def blocksFun : Fin c.length → ℕ := c.blocks.get
@[simp]
theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks :=
ofFn_get _
@[simp]
theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by
conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn]
@[simp]
theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks :=
get_mem _ _
theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i :=
c.blocks_pos h
theorem blocks_le {i : ℕ} (h : i ∈ c.blocks) : i ≤ n := by
rw [← c.blocks_sum]
exact List.le_sum_of_mem h
@[simp]
theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks[i] :=
c.one_le_blocks (get_mem (blocks c) _)
@[simp]
theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks[i] :=
c.one_le_blocks' h
@[simp]
theorem one_le_blocksFun (i : Fin c.length) : 1 ≤ c.blocksFun i :=
c.one_le_blocks (c.blocksFun_mem_blocks i)
@[simp]
theorem blocksFun_le {n} (c : Composition n) (i : Fin c.length) :
c.blocksFun i ≤ n :=
c.blocks_le <| getElem_mem _
@[simp]
theorem length_le : c.length ≤ n := by
conv_rhs => rw [← c.blocks_sum]
exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi
@[simp]
theorem blocks_eq_nil : c.blocks = [] ↔ n = 0 := by
constructor
· intro h
simpa using congr(List.sum $h)
· rintro rfl
rw [← length_eq_zero_iff, ← nonpos_iff_eq_zero]
exact c.length_le
protected theorem length_eq_zero : c.length = 0 ↔ n = 0 := by
simp
@[simp]
theorem length_pos_iff : 0 < c.length ↔ 0 < n := by
simp [pos_iff_ne_zero]
alias ⟨_, length_pos_of_pos⟩ := length_pos_iff
/-- The sum of the sizes of the blocks in a composition up to `i`. -/
def sizeUpTo (i : ℕ) : ℕ :=
(c.blocks.take i).sum
@[simp]
theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo]
theorem sizeUpTo_ofLength_le (i : ℕ) (h : c.length ≤ i) : c.sizeUpTo i = n := by
dsimp [sizeUpTo]
convert c.blocks_sum
exact take_of_length_le h
@[simp]
theorem sizeUpTo_length : c.sizeUpTo c.length = n :=
c.sizeUpTo_ofLength_le c.length le_rfl
theorem sizeUpTo_le (i : ℕ) : c.sizeUpTo i ≤ n := by
conv_rhs => rw [← c.blocks_sum, ← sum_take_add_sum_drop _ i]
exact Nat.le_add_right _ _
theorem sizeUpTo_succ {i : ℕ} (h : i < c.length) :
c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks[i] := by
simp only [sizeUpTo]
rw [sum_take_succ _ _ h]
theorem sizeUpTo_succ' (i : Fin c.length) :
c.sizeUpTo ((i : ℕ) + 1) = c.sizeUpTo i + c.blocksFun i :=
c.sizeUpTo_succ i.2
theorem sizeUpTo_strict_mono {i : ℕ} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by
rw [c.sizeUpTo_succ h]
simp
theorem monotone_sizeUpTo : Monotone c.sizeUpTo :=
monotone_sum_take _
/-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include
a virtual point at the right of the last block, to make for a nice equiv with
`CompositionAsSet n`. -/
def boundary : Fin (c.length + 1) ↪o Fin (n + 1) :=
(OrderEmbedding.ofStrictMono fun i => ⟨c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)⟩) <|
Fin.strictMono_iff_lt_succ.2 fun ⟨_, hi⟩ => c.sizeUpTo_strict_mono hi
@[simp]
theorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff]
@[simp]
theorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by
simp [boundary, Fin.ext_iff]
/-- The boundaries of a composition, i.e., the leftmost point of all the blocks. We include
a virtual point at the right of the last block, to make for a nice equiv with
`CompositionAsSet n`. -/
def boundaries : Finset (Fin (n + 1)) :=
Finset.univ.map c.boundary.toEmbedding
theorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries]
/-- To `c : Composition n`, one can associate a `CompositionAsSet n` by registering the leftmost
point of each block, and adding a virtual point at the right of the last block. -/
def toCompositionAsSet : CompositionAsSet n where
boundaries := c.boundaries
zero_mem := by
simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]
exact ⟨0, And.intro True.intro rfl⟩
getLast_mem := by
simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]
exact ⟨Fin.last c.length, And.intro True.intro c.boundary_last⟩
/-- The canonical increasing bijection between `Fin (c.length + 1)` and `c.boundaries` is
exactly `c.boundary`. -/
theorem orderEmbOfFin_boundaries :
c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length = c.boundary := by
refine (Finset.orderEmbOfFin_unique' _ ?_).symm
exact fun i => (Finset.mem_map' _).2 (Finset.mem_univ _)
/-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocksFun i)`) into
`Fin n` at the relevant position. -/
def embedding (i : Fin c.length) : Fin (c.blocksFun i) ↪o Fin n :=
(Fin.natAddOrderEmb <| c.sizeUpTo i).trans <| Fin.castLEOrderEmb <|
calc
c.sizeUpTo i + c.blocksFun i = c.sizeUpTo (i + 1) := (c.sizeUpTo_succ i.2).symm
_ ≤ c.sizeUpTo c.length := monotone_sum_take _ i.2
_ = n := c.sizeUpTo_length
@[simp]
theorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.embedding i j : ℕ) = c.sizeUpTo i + j :=
rfl
/-- `index_exists` asserts there is some `i` with `j < c.sizeUpTo (i+1)`.
In the next definition `index` we use `Nat.find` to produce the minimal such index.
-/
theorem index_exists {j : ℕ} (h : j < n) : ∃ i : ℕ, j < c.sizeUpTo (i + 1) ∧ i < c.length := by
have n_pos : 0 < n := lt_of_le_of_lt (zero_le j) h
have : 0 < c.blocks.sum := by rwa [← c.blocks_sum] at n_pos
have length_pos : 0 < c.blocks.length := length_pos_of_sum_pos (blocks c) this
refine ⟨c.length - 1, ?_, Nat.pred_lt (ne_of_gt length_pos)⟩
have : c.length - 1 + 1 = c.length := Nat.succ_pred_eq_of_pos length_pos
simp [this, h]
/-- `c.index j` is the index of the block in the composition `c` containing `j`. -/
def index (j : Fin n) : Fin c.length :=
⟨Nat.find (c.index_exists j.2), (Nat.find_spec (c.index_exists j.2)).2⟩
theorem lt_sizeUpTo_index_succ (j : Fin n) : (j : ℕ) < c.sizeUpTo (c.index j).succ :=
(Nat.find_spec (c.index_exists j.2)).1
theorem sizeUpTo_index_le (j : Fin n) : c.sizeUpTo (c.index j) ≤ j := by
by_contra H
set i := c.index j
push_neg at H
have i_pos : (0 : ℕ) < i := by
by_contra! i_pos
revert H
simp [nonpos_iff_eq_zero.1 i_pos, c.sizeUpTo_zero]
let i₁ := (i : ℕ).pred
have i₁_lt_i : i₁ < i := Nat.pred_lt (ne_of_gt i_pos)
have i₁_succ : i₁ + 1 = i := Nat.succ_pred_eq_of_pos i_pos
have := Nat.find_min (c.index_exists j.2) i₁_lt_i
simp [lt_trans i₁_lt_i (c.index j).2, i₁_succ] at this
exact Nat.lt_le_asymm H this
/-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with
`Fin (c.blocksFun (c.index j))` through the canonical increasing bijection. -/
def invEmbedding (j : Fin n) : Fin (c.blocksFun (c.index j)) :=
⟨j - c.sizeUpTo (c.index j), by
rw [tsub_lt_iff_right, add_comm, ← sizeUpTo_succ']
· exact lt_sizeUpTo_index_succ _ _
· exact sizeUpTo_index_le _ _⟩
@[simp]
theorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : ℕ) = j - c.sizeUpTo (c.index j) :=
rfl
theorem embedding_comp_inv (j : Fin n) : c.embedding (c.index j) (c.invEmbedding j) = j := by
rw [Fin.ext_iff]
apply add_tsub_cancel_of_le (c.sizeUpTo_index_le j)
theorem mem_range_embedding_iff {j : Fin n} {i : Fin c.length} :
j ∈ Set.range (c.embedding i) ↔ c.sizeUpTo i ≤ j ∧ (j : ℕ) < c.sizeUpTo (i : ℕ).succ := by
constructor
· intro h
rcases Set.mem_range.2 h with ⟨k, hk⟩
rw [Fin.ext_iff] at hk
dsimp at hk
rw [← hk]
simp [sizeUpTo_succ', k.is_lt]
· intro h
apply Set.mem_range.2
refine ⟨⟨j - c.sizeUpTo i, ?_⟩, ?_⟩
· rw [tsub_lt_iff_left, ← sizeUpTo_succ']
· exact h.2
· exact h.1
· rw [Fin.ext_iff]
exact add_tsub_cancel_of_le h.1
/-- The embeddings of different blocks of a composition are disjoint. -/
theorem disjoint_range {i₁ i₂ : Fin c.length} (h : i₁ ≠ i₂) :
Disjoint (Set.range (c.embedding i₁)) (Set.range (c.embedding i₂)) := by
classical
wlog h' : i₁ < i₂
· exact (this c h.symm (h.lt_or_lt.resolve_left h')).symm
by_contra d
obtain ⟨x, hx₁, hx₂⟩ :
∃ x : Fin n, x ∈ Set.range (c.embedding i₁) ∧ x ∈ Set.range (c.embedding i₂) :=
Set.not_disjoint_iff.1 d
have A : (i₁ : ℕ).succ ≤ i₂ := Nat.succ_le_of_lt h'
apply lt_irrefl (x : ℕ)
calc
(x : ℕ) < c.sizeUpTo (i₁ : ℕ).succ := (c.mem_range_embedding_iff.1 hx₁).2
_ ≤ c.sizeUpTo (i₂ : ℕ) := monotone_sum_take _ A
_ ≤ x := (c.mem_range_embedding_iff.1 hx₂).1
theorem mem_range_embedding (j : Fin n) : j ∈ Set.range (c.embedding (c.index j)) := by
have : c.embedding (c.index j) (c.invEmbedding j) ∈ Set.range (c.embedding (c.index j)) :=
Set.mem_range_self _
rwa [c.embedding_comp_inv j] at this
theorem mem_range_embedding_iff' {j : Fin n} {i : Fin c.length} :
j ∈ Set.range (c.embedding i) ↔ i = c.index j := by
constructor
· rw [← not_imp_not]
intro h
exact Set.disjoint_right.1 (c.disjoint_range h) (c.mem_range_embedding j)
· intro h
rw [h]
exact c.mem_range_embedding j
theorem index_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
c.index (c.embedding i j) = i := by
symm
rw [← mem_range_embedding_iff']
apply Set.mem_range_self
theorem invEmbedding_comp (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.invEmbedding (c.embedding i j) : ℕ) = j := by
simp_rw [coe_invEmbedding, index_embedding, coe_embedding, add_tsub_cancel_left]
/-- Equivalence between the disjoint union of the blocks (each of them seen as
`Fin (c.blocksFun i)`) with `Fin n`. -/
def blocksFinEquiv : (Σi : Fin c.length, Fin (c.blocksFun i)) ≃ Fin n where
toFun x := c.embedding x.1 x.2
invFun j := ⟨c.index j, c.invEmbedding j⟩
left_inv x := by
rcases x with ⟨i, y⟩
dsimp
congr; · exact c.index_embedding _ _
rw [Fin.heq_ext_iff]
· exact c.invEmbedding_comp _ _
· rw [c.index_embedding]
right_inv j := c.embedding_comp_inv j
theorem blocksFun_congr {n₁ n₂ : ℕ} (c₁ : Composition n₁) (c₂ : Composition n₂) (i₁ : Fin c₁.length)
(i₂ : Fin c₂.length) (hn : n₁ = n₂) (hc : c₁.blocks = c₂.blocks) (hi : (i₁ : ℕ) = i₂) :
c₁.blocksFun i₁ = c₂.blocksFun i₂ := by
cases hn
rw [← Composition.ext_iff] at hc
cases hc
congr
rwa [Fin.ext_iff]
/-- Two compositions (possibly of different integers) coincide if and only if they have the
same sequence of blocks. -/
theorem sigma_eq_iff_blocks_eq {c : Σ n, Composition n} {c' : Σ n, Composition n} :
c = c' ↔ c.2.blocks = c'.2.blocks := by
refine ⟨fun H => by rw [H], fun H => ?_⟩
rcases c with ⟨n, c⟩
rcases c' with ⟨n', c'⟩
have : n = n' := by rw [← c.blocks_sum, ← c'.blocks_sum, H]
induction this
congr
ext1
exact H
/-! ### The composition `Composition.ones` -/
/-- The composition made of blocks all of size `1`. -/
def ones (n : ℕ) : Composition n :=
⟨replicate n (1 : ℕ), fun {i} hi => by simp [List.eq_of_mem_replicate hi], by simp⟩
instance {n : ℕ} : Inhabited (Composition n) :=
⟨Composition.ones n⟩
@[simp]
theorem ones_length (n : ℕ) : (ones n).length = n :=
List.length_replicate
@[simp]
theorem ones_blocks (n : ℕ) : (ones n).blocks = replicate n (1 : ℕ) :=
rfl
@[simp]
theorem ones_blocksFun (n : ℕ) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by
simp only [blocksFun, ones, get_eq_getElem, getElem_replicate]
@[simp]
theorem ones_sizeUpTo (n : ℕ) (i : ℕ) : (ones n).sizeUpTo i = min i n := by
simp [sizeUpTo, ones_blocks, take_replicate]
@[simp]
theorem ones_embedding (i : Fin (ones n).length) (h : 0 < (ones n).blocksFun i) :
(ones n).embedding i ⟨0, h⟩ = ⟨i, lt_of_lt_of_le i.2 (ones n).length_le⟩ := by
ext
simpa using i.2.le
theorem eq_ones_iff {c : Composition n} : c = ones n ↔ ∀ i ∈ c.blocks, i = 1 := by
constructor
· rintro rfl
exact fun i => eq_of_mem_replicate
· intro H
ext1
have A : c.blocks = replicate c.blocks.length 1 := eq_replicate_of_mem H
have : c.blocks.length = n := by
conv_rhs => rw [← c.blocks_sum, A]
simp
rw [A, this, ones_blocks]
theorem ne_ones_iff {c : Composition n} : c ≠ ones n ↔ ∃ i ∈ c.blocks, 1 < i := by
refine (not_congr eq_ones_iff).trans ?_
have : ∀ j ∈ c.blocks, j = 1 ↔ j ≤ 1 := fun j hj => by simp [le_antisymm_iff, c.one_le_blocks hj]
simp +contextual [this]
theorem eq_ones_iff_length {c : Composition n} : c = ones n ↔ c.length = n := by
constructor
· rintro rfl
exact ones_length n
· contrapose
intro H length_n
apply lt_irrefl n
calc
n = ∑ i : Fin c.length, 1 := by simp [length_n]
_ < ∑ i : Fin c.length, c.blocksFun i := by
{
obtain ⟨i, hi, i_blocks⟩ : ∃ i ∈ c.blocks, 1 < i := ne_ones_iff.1 H
rw [← ofFn_blocksFun, mem_ofFn' c.blocksFun, Set.mem_range] at hi
obtain ⟨j : Fin c.length, hj : c.blocksFun j = i⟩ := hi
rw [← hj] at i_blocks
exact Finset.sum_lt_sum (fun i _ => one_le_blocksFun c i) ⟨j, Finset.mem_univ _, i_blocks⟩
}
_ = n := c.sum_blocksFun
theorem eq_ones_iff_le_length {c : Composition n} : c = ones n ↔ n ≤ c.length := by
simp [eq_ones_iff_length, le_antisymm_iff, c.length_le]
/-! ### The composition `Composition.single` -/
/-- The composition made of a single block of size `n`. -/
def single (n : ℕ) (h : 0 < n) : Composition n :=
⟨[n], by simp [h], by simp⟩
@[simp]
theorem single_length {n : ℕ} (h : 0 < n) : (single n h).length = 1 :=
rfl
@[simp]
theorem single_blocks {n : ℕ} (h : 0 < n) : (single n h).blocks = [n] :=
rfl
@[simp]
theorem single_blocksFun {n : ℕ} (h : 0 < n) (i : Fin (single n h).length) :
(single n h).blocksFun i = n := by simp [blocksFun, single, blocks, i.2]
@[simp]
theorem single_embedding {n : ℕ} (h : 0 < n) (i : Fin n) :
((single n h).embedding (0 : Fin 1)) i = i := by
ext
simp
theorem eq_single_iff_length {n : ℕ} (h : 0 < n) {c : Composition n} :
c = single n h ↔ c.length = 1 := by
constructor
· intro H
rw [H]
exact single_length h
· intro H
ext1
have A : c.blocks.length = 1 := H ▸ c.blocks_length
have B : c.blocks.sum = n := c.blocks_sum
rw [eq_cons_of_length_one A] at B ⊢
simpa [single_blocks] using B
theorem ne_single_iff {n : ℕ} (hn : 0 < n) {c : Composition n} :
c ≠ single n hn ↔ ∀ i, c.blocksFun i < n := by
rw [← not_iff_not]
push_neg
constructor
· rintro rfl
exact ⟨⟨0, by simp⟩, by simp⟩
· rintro ⟨i, hi⟩
rw [eq_single_iff_length]
have : ∀ j : Fin c.length, j = i := by
intro j
by_contra ji
apply lt_irrefl (∑ k, c.blocksFun k)
calc
∑ k, c.blocksFun k ≤ c.blocksFun i := by simp only [c.sum_blocksFun, hi]
_ < ∑ k, c.blocksFun k :=
Finset.single_lt_sum ji (Finset.mem_univ _) (Finset.mem_univ _) (c.one_le_blocksFun j)
fun _ _ _ => zero_le _
simpa using Fintype.card_eq_one_of_forall_eq this
variable {m : ℕ}
/-- Change `n` in `(c : Composition n)` to a propositionally equal value. -/
@[simps]
protected def cast (c : Composition m) (hmn : m = n) : Composition n where
__ := c
blocks_sum := c.blocks_sum.trans hmn
@[simp]
theorem cast_rfl (c : Composition n) : c.cast rfl = c := rfl
theorem cast_heq (c : Composition m) (hmn : m = n) : HEq (c.cast hmn) c := by subst m; rfl
theorem cast_eq_cast (c : Composition m) (hmn : m = n) :
c.cast hmn = cast (hmn ▸ rfl) c := by
subst m
rfl
/-- Append two compositions to get a composition of the sum of numbers. -/
@[simps]
def append (c₁ : Composition m) (c₂ : Composition n) : Composition (m + n) where
blocks := c₁.blocks ++ c₂.blocks
blocks_pos := by
intro i hi
rw [mem_append] at hi
exact hi.elim c₁.blocks_pos c₂.blocks_pos
blocks_sum := by simp
/-- Reverse the order of blocks in a composition. -/
@[simps]
def reverse (c : Composition n) : Composition n where
blocks := c.blocks.reverse
blocks_pos hi := c.blocks_pos (mem_reverse.mp hi)
blocks_sum := by simp [List.sum_reverse]
@[simp]
lemma reverse_reverse (c : Composition n) : c.reverse.reverse = c :=
Composition.ext <| List.reverse_reverse _
lemma reverse_involutive : Function.Involutive (@reverse n) := reverse_reverse
lemma reverse_bijective : Function.Bijective (@reverse n) := reverse_involutive.bijective
lemma reverse_injective : Function.Injective (@reverse n) := reverse_involutive.injective
lemma reverse_surjective : Function.Surjective (@reverse n) := reverse_involutive.surjective
@[simp]
lemma reverse_inj {c₁ c₂ : Composition n} : c₁.reverse = c₂.reverse ↔ c₁ = c₂ :=
reverse_injective.eq_iff
@[simp]
lemma reverse_ones : (ones n).reverse = ones n := by ext1; simp
@[simp]
lemma reverse_single (hn : 0 < n) : (single n hn).reverse = single n hn := by ext1; simp
@[simp]
lemma reverse_eq_ones {c : Composition n} : c.reverse = ones n ↔ c = ones n :=
reverse_injective.eq_iff' reverse_ones
@[simp]
lemma reverse_eq_single {hn : 0 < n} {c : Composition n} :
c.reverse = single n hn ↔ c = single n hn :=
reverse_injective.eq_iff' <| reverse_single _
lemma reverse_append (c₁ : Composition m) (c₂ : Composition n) :
reverse (append c₁ c₂) = (append c₂.reverse c₁.reverse).cast (add_comm _ _) :=
Composition.ext <| by simp
/-- Induction (recursion) principle on `c : Composition _`
that corresponds to the usual induction on the list of blocks of `c`. -/
@[elab_as_elim]
def recOnSingleAppend {motive : ∀ n, Composition n → Sort*} {n : ℕ} (c : Composition n)
(zero : motive 0 (ones 0))
(single_append : ∀ k n c, motive n c →
motive (k + 1 + n) (append (single (k + 1) k.succ_pos) c)) :
motive n c :=
match n, c with
| _, ⟨blocks, blocks_pos, rfl⟩ =>
match blocks with
| [] => zero
| 0 :: _ => by simp at blocks_pos
| (k + 1) :: l =>
single_append k l.sum ⟨l, fun hi ↦ blocks_pos <| mem_cons_of_mem _ hi, rfl⟩ <|
recOnSingleAppend _ zero single_append
decreasing_by simp
/-- Induction (recursion) principle on `c : Composition _`
that corresponds to the reverse induction on the list of blocks of `c`. -/
@[elab_as_elim]
def recOnAppendSingle {motive : ∀ n, Composition n → Sort*} {n : ℕ} (c : Composition n)
(zero : motive 0 (ones 0))
(append_single : ∀ k n c, motive n c →
motive (n + (k + 1)) (append c (single (k + 1) k.succ_pos))) :
motive n c :=
reverse_reverse c ▸ c.reverse.recOnSingleAppend zero fun k n c ih ↦ by
convert append_single k n c.reverse ih using 1
· apply add_comm
· rw [reverse_append, reverse_single]
apply cast_heq
end Composition
/-!
### Splitting a list
Given a list of length `n` and a composition `c` of `n`, one can split `l` into `c.length` sublists
of respective lengths `c.blocksFun 0`, ..., `c.blocksFun (c.length-1)`. This is inverse to the
join operation.
-/
namespace List
variable {α : Type*}
/-- Auxiliary for `List.splitWrtComposition`. -/
def splitWrtCompositionAux : List α → List ℕ → List (List α)
| _, [] => []
| l, n::ns =>
let (l₁, l₂) := l.splitAt n
l₁::splitWrtCompositionAux l₂ ns
/-- Given a list of length `n` and a composition `[i₁, ..., iₖ]` of `n`, split `l` into a list of
`k` lists corresponding to the blocks of the composition, of respective lengths `i₁`, ..., `iₖ`.
This makes sense mostly when `n = l.length`, but this is not necessary for the definition. -/
def splitWrtComposition (l : List α) (c : Composition n) : List (List α) :=
splitWrtCompositionAux l c.blocks
@[local simp]
theorem splitWrtCompositionAux_cons (l : List α) (n ns) :
l.splitWrtCompositionAux (n::ns) = take n l::(drop n l).splitWrtCompositionAux ns := by
simp [splitWrtCompositionAux]
theorem length_splitWrtCompositionAux (l : List α) (ns) :
length (l.splitWrtCompositionAux ns) = ns.length := by
induction ns generalizing l
· simp [splitWrtCompositionAux, *]
· simp [*]
/-- When one splits a list along a composition `c`, the number of sublists thus created is
`c.length`. -/
@[simp]
theorem length_splitWrtComposition (l : List α) (c : Composition n) :
length (l.splitWrtComposition c) = c.length :=
length_splitWrtCompositionAux _ _
theorem map_length_splitWrtCompositionAux {ns : List ℕ} :
∀ {l : List α}, ns.sum ≤ l.length → map length (l.splitWrtCompositionAux ns) = ns := by
induction ns with
| nil => simp [splitWrtCompositionAux]
| cons n ns IH =>
intro l h; simp only [sum_cons] at h
have := le_trans (Nat.le_add_right _ _) h
simp only [splitWrtCompositionAux_cons, this]; dsimp
rw [length_take, IH] <;> simp [length_drop]
· assumption
· exact le_tsub_of_add_le_left h
/-- When one splits a list along a composition `c`, the lengths of the sublists thus created are
given by the block sizes in `c`. -/
theorem map_length_splitWrtComposition (l : List α) (c : Composition l.length) :
map length (l.splitWrtComposition c) = c.blocks :=
map_length_splitWrtCompositionAux (le_of_eq c.blocks_sum)
theorem length_pos_of_mem_splitWrtComposition {l l' : List α} {c : Composition l.length}
(h : l' ∈ l.splitWrtComposition c) : 0 < length l' := by
have : l'.length ∈ (l.splitWrtComposition c).map List.length :=
List.mem_map_of_mem h
rw [map_length_splitWrtComposition] at this
exact c.blocks_pos this
theorem sum_take_map_length_splitWrtComposition (l : List α) (c : Composition l.length) (i : ℕ) :
(((l.splitWrtComposition c).map length).take i).sum = c.sizeUpTo i := by
congr
exact map_length_splitWrtComposition l c
theorem getElem_splitWrtCompositionAux (l : List α) (ns : List ℕ) {i : ℕ}
(hi : i < (l.splitWrtCompositionAux ns).length) :
(l.splitWrtCompositionAux ns)[i] =
(l.take (ns.take (i + 1)).sum).drop (ns.take i).sum := by
induction ns generalizing l i with
| nil => cases hi
| cons n ns IH =>
rcases i with - | i
· rw [Nat.add_zero, List.take_zero, sum_nil]
simp
· simp only [splitWrtCompositionAux, getElem_cons_succ, IH, take,
sum_cons, Nat.add_eq, add_zero, splitAt_eq, drop_take, drop_drop]
rw [Nat.add_sub_add_left]
/-- The `i`-th sublist in the splitting of a list `l` along a composition `c`, is the slice of `l`
between the indices `c.sizeUpTo i` and `c.sizeUpTo (i+1)`, i.e., the indices in the `i`-th
block of the composition. -/
theorem getElem_splitWrtComposition' (l : List α) (c : Composition n) {i : ℕ}
(hi : i < (l.splitWrtComposition c).length) :
(l.splitWrtComposition c)[i] = (l.take (c.sizeUpTo (i + 1))).drop (c.sizeUpTo i) :=
getElem_splitWrtCompositionAux _ _ hi
theorem getElem_splitWrtComposition (l : List α) (c : Composition n)
(i : Nat) (h : i < (l.splitWrtComposition c).length) :
(l.splitWrtComposition c)[i] = (l.take (c.sizeUpTo (i + 1))).drop (c.sizeUpTo i) :=
getElem_splitWrtComposition' _ _ h
theorem flatten_splitWrtCompositionAux {ns : List ℕ} :
∀ {l : List α}, ns.sum = l.length → (l.splitWrtCompositionAux ns).flatten = l := by
induction ns with
| nil => exact fun h ↦ (length_eq_zero_iff.1 h.symm).symm
| cons n ns IH =>
intro l h; rw [sum_cons] at h
simp only [splitWrtCompositionAux_cons]; dsimp
rw [IH]
· simp
· rw [length_drop, ← h, add_tsub_cancel_left]
/-- If one splits a list along a composition, and then flattens the sublists, one gets back the
original list. -/
@[simp]
theorem flatten_splitWrtComposition (l : List α) (c : Composition l.length) :
(l.splitWrtComposition c).flatten = l :=
flatten_splitWrtCompositionAux c.blocks_sum
/-- If one joins a list of lists and then splits the flattening along the right composition,
one gets back the original list of lists. -/
@[simp]
theorem splitWrtComposition_flatten (L : List (List α)) (c : Composition L.flatten.length)
(h : map length L = c.blocks) : splitWrtComposition (flatten L) c = L := by
simp only [eq_self_iff_true, and_self_iff, eq_iff_flatten_eq, flatten_splitWrtComposition,
map_length_splitWrtComposition, h]
end List
/-!
### Compositions as sets
Combinatorial viewpoints on compositions, seen as finite subsets of `Fin (n+1)` containing `0` and
`n`, where the points of the set (other than `n`) correspond to the leftmost points of each block.
-/
/-- Bijection between compositions of `n` and subsets of `{0, ..., n-2}`, defined by
considering the restriction of the subset to `{1, ..., n-1}` and shifting to the left by one. -/
def compositionAsSetEquiv (n : ℕ) : CompositionAsSet n ≃ Finset (Fin (n - 1)) where
toFun c :=
{ i : Fin (n - 1) |
(⟨1 + (i : ℕ), by
apply (add_lt_add_left i.is_lt 1).trans_le
rw [Nat.succ_eq_add_one, add_comm]
exact add_le_add (Nat.sub_le n 1) (le_refl 1)⟩ :
Fin n.succ) ∈
c.boundaries }.toFinset
invFun s :=
{ boundaries :=
{ i : Fin n.succ |
i = 0 ∨ i = Fin.last n ∨ ∃ (j : Fin (n - 1)) (_hj : j ∈ s), (i : ℕ) = j + 1 }.toFinset
zero_mem := by simp
getLast_mem := by simp }
left_inv := by
intro c
ext i
simp only [add_comm, Set.toFinset_setOf, Finset.mem_univ,
forall_true_left, Finset.mem_filter, true_and, exists_prop]
constructor
· rintro (rfl | rfl | ⟨j, hj1, hj2⟩)
· exact c.zero_mem
· exact c.getLast_mem
· convert hj1
· simp only [or_iff_not_imp_left, ← ne_eq, ← Fin.exists_succ_eq]
rintro i_mem ⟨j, rfl⟩ i_ne_last
rcases Nat.exists_add_one_eq.mpr j.pos with ⟨n, rfl⟩
obtain ⟨k, rfl⟩ : ∃ k : Fin n, k.castSucc = j := by
simpa [Fin.exists_castSucc_eq] using i_ne_last
use k
simpa using i_mem
right_inv := by
intro s
ext i
have : (i : ℕ) + 1 ≠ n := by
apply ne_of_lt
convert add_lt_add_right i.is_lt 1
apply (Nat.succ_pred_eq_of_pos _).symm
exact Nat.lt_of_lt_pred (Fin.pos i)
simp only [add_comm, Fin.ext_iff, Fin.val_zero, Fin.val_last, exists_prop, Set.toFinset_setOf,
Finset.mem_univ, forall_true_left, Finset.mem_filter, add_eq_zero, and_false,
add_left_inj, false_or, true_and, reduceCtorEq]
simp_rw [this, false_or, ← Fin.ext_iff, exists_eq_right']
instance compositionAsSetFintype (n : ℕ) : Fintype (CompositionAsSet n) :=
Fintype.ofEquiv _ (compositionAsSetEquiv n).symm
theorem compositionAsSet_card (n : ℕ) : Fintype.card (CompositionAsSet n) = 2 ^ (n - 1) := by
| have : Fintype.card (Finset (Fin (n - 1))) = 2 ^ (n - 1) := by simp
rw [← this]
exact Fintype.card_congr (compositionAsSetEquiv n)
| Mathlib/Combinatorics/Enumerative/Composition.lean | 866 | 869 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Group.Unbundled.Int
import Mathlib.Algebra.Ring.Nat
import Mathlib.Data.Int.GCD
/-!
# Congruences modulo a natural number
This file defines the equivalence relation `a ≡ b [MOD n]` on the natural numbers,
and proves basic properties about it such as the Chinese Remainder Theorem
`modEq_and_modEq_iff_modEq_mul`.
## Notations
`a ≡ b [MOD n]` is notation for `nat.ModEq n a b`, which is defined to mean `a % n = b % n`.
## Tags
ModEq, congruence, mod, MOD, modulo
-/
assert_not_exists OrderedAddCommMonoid Function.support
namespace Nat
/-- Modular equality. `n.ModEq a b`, or `a ≡ b [MOD n]`, means that `a - b` is a multiple of `n`. -/
def ModEq (n a b : ℕ) :=
a % n = b % n
@[inherit_doc]
notation:50 a " ≡ " b " [MOD " n "]" => ModEq n a b
variable {m n a b c d : ℕ}
-- Since `ModEq` is semi-reducible, we need to provide the decidable instance manually
instance : Decidable (ModEq n a b) := inferInstanceAs <| Decidable (a % n = b % n)
namespace ModEq
@[refl]
protected theorem refl (a : ℕ) : a ≡ a [MOD n] := rfl
protected theorem rfl : a ≡ a [MOD n] :=
ModEq.refl _
instance : IsRefl _ (ModEq n) :=
⟨ModEq.refl⟩
@[symm]
protected theorem symm : a ≡ b [MOD n] → b ≡ a [MOD n] :=
Eq.symm
@[trans]
protected theorem trans : a ≡ b [MOD n] → b ≡ c [MOD n] → a ≡ c [MOD n] :=
Eq.trans
instance : Trans (ModEq n) (ModEq n) (ModEq n) where
trans := Nat.ModEq.trans
protected theorem comm : a ≡ b [MOD n] ↔ b ≡ a [MOD n] :=
⟨ModEq.symm, ModEq.symm⟩
end ModEq
theorem modEq_zero_iff_dvd : a ≡ 0 [MOD n] ↔ n ∣ a := by rw [ModEq, zero_mod, dvd_iff_mod_eq_zero]
theorem _root_.Dvd.dvd.modEq_zero_nat (h : n ∣ a) : a ≡ 0 [MOD n] :=
modEq_zero_iff_dvd.2 h
theorem _root_.Dvd.dvd.zero_modEq_nat (h : n ∣ a) : 0 ≡ a [MOD n] :=
h.modEq_zero_nat.symm
theorem modEq_iff_dvd : a ≡ b [MOD n] ↔ (n : ℤ) ∣ b - a := by
rw [ModEq, eq_comm, ← Int.natCast_inj, Int.natCast_mod, Int.natCast_mod,
Int.emod_eq_emod_iff_emod_sub_eq_zero, Int.dvd_iff_emod_eq_zero]
alias ⟨ModEq.dvd, modEq_of_dvd⟩ := modEq_iff_dvd
/-- A variant of `modEq_iff_dvd` with `Nat` divisibility -/
theorem modEq_iff_dvd' (h : a ≤ b) : a ≡ b [MOD n] ↔ n ∣ b - a := by
rw [modEq_iff_dvd, ← Int.natCast_dvd_natCast, Int.ofNat_sub h]
theorem mod_modEq (a n) : a % n ≡ a [MOD n] :=
mod_mod _ _
namespace ModEq
lemma of_dvd (d : m ∣ n) (h : a ≡ b [MOD n]) : a ≡ b [MOD m] :=
modEq_of_dvd <| Int.ofNat_dvd.mpr d |>.trans h.dvd
protected theorem mul_left' (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD c * n] := by
unfold ModEq at *; rw [mul_mod_mul_left, mul_mod_mul_left, h]
@[gcongr]
protected theorem mul_left (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD n] :=
(h.mul_left' _).of_dvd (dvd_mul_left _ _)
protected theorem mul_right' (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD n * c] := by
rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left' c
@[gcongr]
protected theorem mul_right (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD n] := by
rw [mul_comm a, mul_comm b]; exact h.mul_left c
@[gcongr]
protected theorem mul (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a * c ≡ b * d [MOD n] :=
(h₂.mul_left _).trans (h₁.mul_right _)
@[gcongr]
protected theorem pow (m : ℕ) (h : a ≡ b [MOD n]) : a ^ m ≡ b ^ m [MOD n] := by
induction m with
| zero => rfl
| succ d hd =>
rw [Nat.pow_succ, Nat.pow_succ]
exact hd.mul h
@[gcongr]
protected theorem add (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a + c ≡ b + d [MOD n] := by
rw [modEq_iff_dvd, Int.natCast_add, Int.natCast_add, add_sub_add_comm]
exact Int.dvd_add h₁.dvd h₂.dvd
@[gcongr]
protected theorem add_left (c : ℕ) (h : a ≡ b [MOD n]) : c + a ≡ c + b [MOD n] :=
ModEq.rfl.add h
@[gcongr]
protected theorem add_right (c : ℕ) (h : a ≡ b [MOD n]) : a + c ≡ b + c [MOD n] :=
h.add ModEq.rfl
protected theorem add_left_cancel (h₁ : a ≡ b [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) :
c ≡ d [MOD n] := by
simp only [modEq_iff_dvd, Int.natCast_add] at *
rw [add_sub_add_comm] at h₂
convert Int.dvd_sub h₂ h₁ using 1
rw [add_sub_cancel_left]
protected theorem add_left_cancel' (c : ℕ) (h : c + a ≡ c + b [MOD n]) : a ≡ b [MOD n] :=
ModEq.rfl.add_left_cancel h
protected theorem add_right_cancel (h₁ : c ≡ d [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) :
a ≡ b [MOD n] := by
rw [add_comm a, add_comm b] at h₂
exact h₁.add_left_cancel h₂
protected theorem add_right_cancel' (c : ℕ) (h : a + c ≡ b + c [MOD n]) : a ≡ b [MOD n] :=
ModEq.rfl.add_right_cancel h
/-- Cancel left multiplication on both sides of the `≡` and in the modulus.
For cancelling left multiplication in the modulus, see `Nat.ModEq.of_mul_left`. -/
protected theorem mul_left_cancel' {a b c m : ℕ} (hc : c ≠ 0) :
c * a ≡ c * b [MOD c * m] → a ≡ b [MOD m] := by
simp only [modEq_iff_dvd, Int.natCast_mul, ← Int.mul_sub]
exact fun h => (Int.dvd_of_mul_dvd_mul_left (Int.ofNat_ne_zero.mpr hc) h)
protected theorem mul_left_cancel_iff' {a b c m : ℕ} (hc : c ≠ 0) :
c * a ≡ c * b [MOD c * m] ↔ a ≡ b [MOD m] :=
⟨ModEq.mul_left_cancel' hc, ModEq.mul_left' _⟩
/-- Cancel right multiplication on both sides of the `≡` and in the modulus.
For cancelling right multiplication in the modulus, see `Nat.ModEq.of_mul_right`. -/
protected theorem mul_right_cancel' {a b c m : ℕ} (hc : c ≠ 0) :
a * c ≡ b * c [MOD m * c] → a ≡ b [MOD m] := by
simp only [modEq_iff_dvd, Int.natCast_mul, ← Int.sub_mul]
exact fun h => (Int.dvd_of_mul_dvd_mul_right (Int.ofNat_ne_zero.mpr hc) h)
protected theorem mul_right_cancel_iff' {a b c m : ℕ} (hc : c ≠ 0) :
a * c ≡ b * c [MOD m * c] ↔ a ≡ b [MOD m] :=
⟨ModEq.mul_right_cancel' hc, ModEq.mul_right' _⟩
/-- Cancel left multiplication in the modulus.
For cancelling left multiplication on both sides of the `≡`, see `nat.modeq.mul_left_cancel'`. -/
lemma of_mul_left (m : ℕ) (h : a ≡ b [MOD m * n]) : a ≡ b [MOD n] := by
rw [modEq_iff_dvd] at *
exact (dvd_mul_left (n : ℤ) (m : ℤ)).trans h
/-- Cancel right multiplication in the modulus.
For cancelling right multiplication on both sides of the `≡`, see `nat.modeq.mul_right_cancel'`. -/
lemma of_mul_right (m : ℕ) : a ≡ b [MOD n * m] → a ≡ b [MOD n] := mul_comm m n ▸ of_mul_left _
theorem of_div (h : a / c ≡ b / c [MOD m / c]) (ha : c ∣ a) (ha : c ∣ b) (ha : c ∣ m) :
a ≡ b [MOD m] := by convert h.mul_left' c <;> rwa [Nat.mul_div_cancel']
end ModEq
lemma modEq_sub (h : b ≤ a) : a ≡ b [MOD a - b] := (modEq_of_dvd <| by rw [Int.ofNat_sub h]).symm
lemma modEq_one : a ≡ b [MOD 1] := modEq_of_dvd <| one_dvd _
@[simp] lemma modEq_zero_iff : a ≡ b [MOD 0] ↔ a = b := by rw [ModEq, mod_zero, mod_zero]
@[simp] lemma add_modEq_left : n + a ≡ a [MOD n] := by rw [ModEq, add_mod_left]
@[simp] lemma add_modEq_right : a + n ≡ a [MOD n] := by rw [ModEq, add_mod_right]
namespace ModEq
theorem le_of_lt_add (h1 : a ≡ b [MOD m]) (h2 : a < b + m) : a ≤ b :=
(le_total a b).elim id fun h3 =>
Nat.le_of_sub_eq_zero
(eq_zero_of_dvd_of_lt ((modEq_iff_dvd' h3).mp h1.symm) (by omega))
theorem add_le_of_lt (h1 : a ≡ b [MOD m]) (h2 : a < b) : a + m ≤ b :=
le_of_lt_add (add_modEq_right.trans h1) (by omega)
theorem dvd_iff (h : a ≡ b [MOD m]) (hdm : d ∣ m) : d ∣ a ↔ d ∣ b := by
simp only [← modEq_zero_iff_dvd]
replace h := h.of_dvd hdm
exact ⟨h.symm.trans, h.trans⟩
theorem gcd_eq (h : a ≡ b [MOD m]) : gcd a m = gcd b m := by
have h1 := gcd_dvd_right a m
have h2 := gcd_dvd_right b m
exact
dvd_antisymm (dvd_gcd ((h.dvd_iff h1).mp (gcd_dvd_left a m)) h1)
(dvd_gcd ((h.dvd_iff h2).mpr (gcd_dvd_left b m)) h2)
lemma eq_of_abs_lt (h : a ≡ b [MOD m]) (h2 : |(b : ℤ) - a| < m) : a = b := by
apply Int.ofNat.inj
rw [eq_comm, ← sub_eq_zero]
exact Int.eq_zero_of_abs_lt_dvd h.dvd h2
lemma eq_of_lt_of_lt (h : a ≡ b [MOD m]) (ha : a < m) (hb : b < m) : a = b :=
h.eq_of_abs_lt <| Int.abs_sub_lt_of_lt_lt ha hb
/-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/
lemma cancel_left_div_gcd (hm : 0 < m) (h : c * a ≡ c * b [MOD m]) : a ≡ b [MOD m / gcd m c] := by
let d := gcd m c
have hmd := gcd_dvd_left m c
have hcd := gcd_dvd_right m c
rw [modEq_iff_dvd]
refine @Int.dvd_of_dvd_mul_right_of_gcd_one (m / d) (c / d) (b - a) ?_ ?_
· show (m / d : ℤ) ∣ c / d * (b - a)
rw [mul_comm, ← Int.mul_ediv_assoc (b - a) (Int.natCast_dvd_natCast.mpr hcd), mul_comm]
apply Int.ediv_dvd_ediv (Int.natCast_dvd_natCast.mpr hmd)
rw [Int.mul_sub]
exact modEq_iff_dvd.mp h
· show Int.gcd (m / d) (c / d) = 1
simp only [d, ← Int.natCast_div, Int.gcd_natCast_natCast (m / d) (c / d),
gcd_div hmd hcd, Nat.div_self (gcd_pos_of_pos_left c hm)]
/-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/
lemma cancel_right_div_gcd (hm : 0 < m) (h : a * c ≡ b * c [MOD m]) : a ≡ b [MOD m / gcd m c] := by
apply cancel_left_div_gcd hm
simpa [mul_comm] using h
lemma cancel_left_div_gcd' (hm : 0 < m) (hcd : c ≡ d [MOD m]) (h : c * a ≡ d * b [MOD m]) :
a ≡ b [MOD m / gcd m c] :=
(h.trans <| hcd.symm.mul_right b).cancel_left_div_gcd hm
lemma cancel_right_div_gcd' (hm : 0 < m) (hcd : c ≡ d [MOD m]) (h : a * c ≡ b * d [MOD m]) :
a ≡ b [MOD m / gcd m c] :=
(h.trans <| hcd.symm.mul_left b).cancel_right_div_gcd hm
/-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/
lemma cancel_left_of_coprime (hmc : gcd m c = 1) (h : c * a ≡ c * b [MOD m]) : a ≡ b [MOD m] := by
rcases m.eq_zero_or_pos with (rfl | hm)
· simp only [gcd_zero_left] at hmc
simp only [gcd_zero_left, hmc, one_mul, modEq_zero_iff] at h
subst h
rfl
simpa [hmc] using h.cancel_left_div_gcd hm
/-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/
lemma cancel_right_of_coprime (hmc : gcd m c = 1) (h : a * c ≡ b * c [MOD m]) : a ≡ b [MOD m] :=
cancel_left_of_coprime hmc <| by simpa [mul_comm] using h
end ModEq
/-- The natural number less than `lcm n m` congruent to `a` mod `n` and `b` mod `m` -/
def chineseRemainder' (h : a ≡ b [MOD gcd n m]) : { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] } :=
if hn : n = 0 then ⟨a, by
rw [hn, gcd_zero_left] at h; constructor
· rfl
· exact h⟩
else
if hm : m = 0 then ⟨b, by
rw [hm, gcd_zero_right] at h; constructor
· exact h.symm
· rfl⟩
else
⟨let (c, d) := xgcd n m; Int.toNat ((n * c * b + m * d * a) / gcd n m % lcm n m), by
rw [xgcd_val]
dsimp
rw [modEq_iff_dvd, modEq_iff_dvd,
Int.toNat_of_nonneg (Int.emod_nonneg _ (Int.natCast_ne_zero.2 (lcm_ne_zero hn hm)))]
have hnonzero : (gcd n m : ℤ) ≠ 0 := by
norm_cast
rw [Nat.gcd_eq_zero_iff, not_and]
exact fun _ => hm
have hcoedvd : ∀ t, (gcd n m : ℤ) ∣ t * (b - a) := fun t => h.dvd.mul_left _
have := gcd_eq_gcd_ab n m
constructor <;> rw [Int.emod_def, ← sub_add] <;>
refine Int.dvd_add ?_ (dvd_mul_of_dvd_left ?_ _) <;>
try norm_cast
· rw [← sub_eq_iff_eq_add'] at this
rw [← this, Int.sub_mul, ← add_sub_assoc, add_comm, add_sub_assoc, ← Int.mul_sub,
Int.add_ediv_of_dvd_left, Int.mul_ediv_cancel_left _ hnonzero,
Int.mul_ediv_assoc _ h.dvd, ← sub_sub, sub_self, zero_sub, Int.dvd_neg, mul_assoc]
· exact dvd_mul_right _ _
norm_cast
exact dvd_mul_right _ _
· exact dvd_lcm_left n m
· rw [← sub_eq_iff_eq_add] at this
rw [← this, Int.sub_mul, sub_add, ← Int.mul_sub, Int.sub_ediv_of_dvd,
Int.mul_ediv_cancel_left _ hnonzero, Int.mul_ediv_assoc _ h.dvd, ← sub_add, sub_self,
zero_add, mul_assoc]
· exact dvd_mul_right _ _
· exact hcoedvd _
· exact dvd_lcm_right n m⟩
/-- The natural number less than `n*m` congruent to `a` mod `n` and `b` mod `m` -/
def chineseRemainder (co : n.Coprime m) (a b : ℕ) : { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] } :=
chineseRemainder' (by convert @modEq_one a b)
theorem chineseRemainder'_lt_lcm (h : a ≡ b [MOD gcd n m]) (hn : n ≠ 0) (hm : m ≠ 0) :
↑(chineseRemainder' h) < lcm n m := by
dsimp only [chineseRemainder']
rw [dif_neg hn, dif_neg hm, Subtype.coe_mk, xgcd_val, ← Int.toNat_natCast (lcm n m)]
have lcm_pos := Int.natCast_pos.mpr (Nat.pos_of_ne_zero (lcm_ne_zero hn hm))
exact (Int.toNat_lt_toNat lcm_pos).mpr (Int.emod_lt_of_pos _ lcm_pos)
theorem chineseRemainder_lt_mul (co : n.Coprime m) (a b : ℕ) (hn : n ≠ 0) (hm : m ≠ 0) :
↑(chineseRemainder co a b) < n * m :=
lt_of_lt_of_le (chineseRemainder'_lt_lcm _ hn hm) (le_of_eq co.lcm_eq_mul)
theorem mod_lcm (hn : a ≡ b [MOD n]) (hm : a ≡ b [MOD m]) : a ≡ b [MOD lcm n m] :=
Nat.modEq_iff_dvd.mpr <| Int.coe_lcm_dvd (Nat.modEq_iff_dvd.mp hn) (Nat.modEq_iff_dvd.mp hm)
theorem chineseRemainder_modEq_unique (co : n.Coprime m) {a b z}
(hzan : z ≡ a [MOD n]) (hzbm : z ≡ b [MOD m]) : z ≡ chineseRemainder co a b [MOD n*m] := by
simpa [Nat.Coprime.lcm_eq_mul co] using
mod_lcm (hzan.trans ((chineseRemainder co a b).prop.1).symm)
(hzbm.trans ((chineseRemainder co a b).prop.2).symm)
theorem modEq_and_modEq_iff_modEq_mul {a b m n : ℕ} (hmn : m.Coprime n) :
a ≡ b [MOD m] ∧ a ≡ b [MOD n] ↔ a ≡ b [MOD m * n] :=
⟨fun h => by
rw [Nat.modEq_iff_dvd, Nat.modEq_iff_dvd, ← Int.dvd_natAbs, Int.natCast_dvd_natCast,
← Int.dvd_natAbs, Int.natCast_dvd_natCast] at h
rw [Nat.modEq_iff_dvd, ← Int.dvd_natAbs, Int.natCast_dvd_natCast]
exact hmn.mul_dvd_of_dvd_of_dvd h.1 h.2,
fun h => ⟨h.of_mul_right _, h.of_mul_left _⟩⟩
theorem coprime_of_mul_modEq_one (b : ℕ) {a n : ℕ} (h : a * b ≡ 1 [MOD n]) : a.Coprime n := by
obtain ⟨g, hh⟩ := Nat.gcd_dvd_right a n
rw [Nat.coprime_iff_gcd_eq_one, ← Nat.dvd_one, ← Nat.modEq_zero_iff_dvd]
calc
1 ≡ a * b [MOD a.gcd n] := (hh ▸ h).symm.of_mul_right g
_ ≡ 0 * b [MOD a.gcd n] := (Nat.modEq_zero_iff_dvd.mpr (Nat.gcd_dvd_left _ _)).mul_right b
_ = 0 := by rw [zero_mul]
theorem add_mod_add_ite (a b c : ℕ) :
((a + b) % c + if c ≤ a % c + b % c then c else 0) = a % c + b % c :=
have : (a + b) % c = (a % c + b % c) % c := ((mod_modEq _ _).add <| mod_modEq _ _).symm
if hc0 : c = 0 then by simp [hc0, Nat.mod_zero]
else by
rw [this]
split_ifs with h
· have h2 : (a % c + b % c) / c < 2 :=
Nat.div_lt_of_lt_mul
(by
rw [mul_two]
exact
add_lt_add (Nat.mod_lt _ (Nat.pos_of_ne_zero hc0))
(Nat.mod_lt _ (Nat.pos_of_ne_zero hc0)))
have h0 : 0 < (a % c + b % c) / c := Nat.div_pos h (Nat.pos_of_ne_zero hc0)
rw [← @add_right_cancel_iff _ _ _ (c * ((a % c + b % c) / c)), add_comm _ c, add_assoc,
mod_add_div, le_antisymm (le_of_lt_succ h2) h0, mul_one, add_comm]
· rw [Nat.mod_eq_of_lt (lt_of_not_ge h), add_zero]
theorem add_mod_of_add_mod_lt {a b c : ℕ} (hc : a % c + b % c < c) :
(a + b) % c = a % c + b % c := by rw [← add_mod_add_ite, if_neg (not_le_of_lt hc), add_zero]
theorem add_mod_add_of_le_add_mod {a b c : ℕ} (hc : c ≤ a % c + b % c) :
(a + b) % c + c = a % c + b % c := by rw [← add_mod_add_ite, if_pos hc]
theorem add_div_eq_of_add_mod_lt {a b c : ℕ} (hc : a % c + b % c < c) :
(a + b) / c = a / c + b / c :=
if hc0 : c = 0 then by simp [hc0]
else by rw [Nat.add_div (Nat.pos_of_ne_zero hc0), if_neg (not_le_of_lt hc), add_zero]
protected theorem add_div_of_dvd_right {a b c : ℕ} (hca : c ∣ a) : (a + b) / c = a / c + b / c :=
if h : c = 0 then by simp [h]
else
add_div_eq_of_add_mod_lt
(by
rw [Nat.mod_eq_zero_of_dvd hca, zero_add]
exact Nat.mod_lt _ (zero_lt_of_ne_zero h))
protected theorem add_div_of_dvd_left {a b c : ℕ} (hca : c ∣ b) : (a + b) / c = a / c + b / c := by
rwa [add_comm, Nat.add_div_of_dvd_right, add_comm]
theorem add_div_eq_of_le_mod_add_mod {a b c : ℕ} (hc : c ≤ a % c + b % c) (hc0 : 0 < c) :
(a + b) / c = a / c + b / c + 1 := by rw [Nat.add_div hc0, if_pos hc]
theorem add_div_le_add_div (a b c : ℕ) : a / c + b / c ≤ (a + b) / c :=
if hc0 : c = 0 then by simp [hc0]
else by rw [Nat.add_div (Nat.pos_of_ne_zero hc0)]; exact Nat.le_add_right _ _
theorem le_mod_add_mod_of_dvd_add_of_not_dvd {a b c : ℕ} (h : c ∣ a + b) (ha : ¬c ∣ a) :
c ≤ a % c + b % c :=
by_contradiction fun hc => by
have : (a + b) % c = a % c + b % c := add_mod_of_add_mod_lt (lt_of_not_ge hc)
simp_all [dvd_iff_mod_eq_zero]
theorem odd_mul_odd {n m : ℕ} : n % 2 = 1 → m % 2 = 1 → n * m % 2 = 1 := by
simpa [Nat.ModEq] using @ModEq.mul 2 n 1 m 1
theorem odd_mul_odd_div_two {m n : ℕ} (hm1 : m % 2 = 1) (hn1 : n % 2 = 1) :
m * n / 2 = m * (n / 2) + m / 2 :=
have hn0 : 0 < n := Nat.pos_of_ne_zero fun h => by simp_all
mul_right_injective₀ two_ne_zero <| by
dsimp
rw [mul_add, two_mul_odd_div_two hm1, mul_left_comm, two_mul_odd_div_two hn1,
two_mul_odd_div_two (Nat.odd_mul_odd hm1 hn1), Nat.mul_sub, mul_one, ←
Nat.add_sub_assoc (by omega), Nat.sub_add_cancel (Nat.le_mul_of_pos_right m hn0)]
theorem odd_of_mod_four_eq_one {n : ℕ} : n % 4 = 1 → n % 2 = 1 := by
simpa [ModEq] using @ModEq.of_mul_left 2 n 1 2
theorem odd_of_mod_four_eq_three {n : ℕ} : n % 4 = 3 → n % 2 = 1 := by
simpa [ModEq] using @ModEq.of_mul_left 2 n 3 2
/-- A natural number is odd iff it has residue `1` or `3` mod `4`. -/
theorem odd_mod_four_iff {n : ℕ} : n % 2 = 1 ↔ n % 4 = 1 ∨ n % 4 = 3 :=
have help : ∀ m : ℕ, m < 4 → m % 2 = 1 → m = 1 ∨ m = 3 := by decide
⟨fun hn =>
help (n % 4) (mod_lt n (by omega)) <| (mod_mod_of_dvd n (by decide : 2 ∣ 4)).trans hn,
fun h => Or.elim h odd_of_mod_four_eq_one odd_of_mod_four_eq_three⟩
lemma mod_eq_of_modEq {a b n} (h : a ≡ b [MOD n]) (hb : b < n) : a % n = b :=
Eq.trans h (mod_eq_of_lt hb)
end Nat
| Mathlib/Data/Nat/ModEq.lean | 505 | 514 | |
/-
Copyright (c) 2023 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis
-/
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal
/-!
# Convexity properties of `rpow`
We prove basic convexity properties of the `rpow` function. The proofs are elementary and do not
require calculus, and as such this file has only moderate dependencies.
## Main declarations
* `NNReal.strictConcaveOn_rpow`, `Real.strictConcaveOn_rpow`: strict concavity of
`fun x ↦ x ^ p` for p ∈ (0,1)
* `NNReal.concaveOn_rpow`, `Real.concaveOn_rpow`: concavity of `fun x ↦ x ^ p` for p ∈ [0,1]
Note that convexity for `p > 1` can be found in `Analysis.Convex.SpecificFunctions.Basic`, which
requires slightly less imports.
## TODO
* Prove convexity for negative powers.
-/
open Set
namespace NNReal
| lemma strictConcaveOn_rpow {p : ℝ} (hp₀ : 0 < p) (hp₁ : p < 1) :
StrictConcaveOn ℝ≥0 univ fun x : ℝ≥0 ↦ x ^ p := by
have hp₀' : 0 < 1 / p := div_pos zero_lt_one hp₀
have hp₁' : 1 < 1 / p := by rw [one_lt_div hp₀]; exact hp₁
let f := NNReal.orderIsoRpow (1 / p) hp₀'
have h₁ : StrictConvexOn ℝ≥0 univ f := by
refine ⟨convex_univ, fun x _ y _ hxy a b ha hb hab => ?_⟩
exact (strictConvexOn_rpow hp₁').2 x.2 y.2 (by simp [hxy]) ha hb (by simp; norm_cast)
have h₂ : ∀ x, f.symm x = x ^ p := by simp [f, NNReal.orderIsoRpow_symm_eq]
refine ⟨convex_univ, fun x mx y my hxy a b ha hb hab => ?_⟩
simp only [← h₂]
exact (f.strictConcaveOn_symm h₁).2 mx my hxy ha hb hab
| Mathlib/Analysis/Convex/SpecificFunctions/Pow.lean | 34 | 45 |
/-
Copyright (c) 2024 Theodore Hwa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kim Morrison, Violeta Hernández Palacios, Junyan Xu, Theodore Hwa
-/
import Mathlib.Logic.Hydra
import Mathlib.SetTheory.Surreal.Basic
/-!
### Surreal multiplication
In this file, we show that multiplication of surreal numbers is well-defined, and thus the
surreal numbers form a linear ordered commutative ring.
An inductive argument proves the following three main theorems:
* P1: being numeric is closed under multiplication,
* P2: multiplying a numeric pregame by equivalent numeric pregames results in equivalent pregames,
* P3: the product of two positive numeric pregames is positive (`mul_pos`).
This is Theorem 8 in [Conway2001], or Theorem 3.8 in [SchleicherStoll]. P1 allows us to define
multiplication as an operation on numeric pregames, P2 says that this is well-defined as an
operation on the quotient by `PGame.Equiv`, namely the surreal numbers, and P3 is an axiom that
needs to be satisfied for the surreals to be a `OrderedRing`.
We follow the proof in [SchleicherStoll], except that we use the well-foundedness of
the hydra relation `CutExpand` on `Multiset PGame` instead of the argument based
on a depth function in the paper.
In the argument, P3 is stated with four variables `x₁`, `x₂`, `y₁`, `y₂` satisfying `x₁ < x₂` and
`y₁ < y₂`, and says that `x₁ * y₂ + x₂ * x₁ < x₁ * y₁ + x₂ * y₂`, which is equivalent to
`0 < x₂ - x₁ → 0 < y₂ - y₁ → 0 < (x₂ - x₁) * (y₂ - y₁)`, i.e.
`@mul_pos PGame _ (x₂ - x₁) (y₂ - y₁)`. It has to be stated in this form and not in terms of
`mul_pos` because we need to show P1, P2 and (a specialized form of) P3 simultaneously, and
for example `P1 x y` will be deduced from P3 with variables taking values simpler than `x` or `y`
(among other induction hypotheses), but if you subtract two pregames simpler than `x` or `y`,
the result may no longer be simpler.
The specialized version of P3 is called P4, which takes only three arguments `x₁`, `x₂`, `y` and
requires that `y₂ = y` or `-y` and that `y₁` is a left option of `y₂`. After P1, P2 and P4 are
shown, a further inductive argument (this time using the `GameAdd` relation) proves P3 in full.
Implementation strategy of the inductive argument: we
* extract specialized versions (`IH1`, `IH2`, `IH3`, `IH4` and `IH24`) of the induction hypothesis
that are easier to apply (taking `IsOption` arguments directly), and
* show they are invariant under certain symmetries (permutation and negation of arguments) and that
the induction hypothesis indeed implies the specialized versions.
* utilize the symmetries to minimize calculation.
The whole proof features a clear separation into lemmas of different roles:
* verification of symmetry properties of P and IH (`P3_comm`, `ih1_neg_left`, etc.),
* calculations that connect P1, P2, P3, and inequalities between the product of
two surreals and its options (`mulOption_lt_iff_P1`, etc.),
* specializations of the induction hypothesis
(`numeric_option_mul`, `ih1`, `ih1_swap`, `ih₁₂`, `ih4`, etc.),
* application of specialized induction hypothesis
(`P1_of_ih`, `mul_right_le_of_equiv`, `P3_of_lt`, etc.).
## References
* [Conway, *On numbers and games*][Conway2001]
* [Schleicher, Stoll, *An introduction to Conway's games and numbers*][SchleicherStoll]
-/
universe u
open SetTheory Game PGame WellFounded
namespace Surreal.Multiplication
/-- The nontrivial part of P1 in [SchleicherStoll] says that the left options of `x * y` are less
than the right options, and this is the general form of these statements. -/
def P1 (x₁ x₂ x₃ y₁ y₂ y₃ : PGame) :=
⟦x₁ * y₁⟧ + ⟦x₂ * y₂⟧ - ⟦x₁ * y₂⟧ < ⟦x₃ * y₁⟧ + ⟦x₂ * y₃⟧ - (⟦x₃ * y₃⟧ : Game)
/-- The proposition P2, without numericity assumptions. -/
def P2 (x₁ x₂ y : PGame) := x₁ ≈ x₂ → ⟦x₁ * y⟧ = (⟦x₂ * y⟧ : Game)
/-- The proposition P3, without the `x₁ < x₂` and `y₁ < y₂` assumptions. -/
def P3 (x₁ x₂ y₁ y₂ : PGame) := ⟦x₁ * y₂⟧ + ⟦x₂ * y₁⟧ < ⟦x₁ * y₁⟧ + (⟦x₂ * y₂⟧ : Game)
/-- The proposition P4, without numericity assumptions. In the references, the second part of the
conjunction is stated as `∀ j, P3 x₁ x₂ y (y.moveRight j)`, which is equivalent to our statement
by `P3_comm` and `P3_neg`. We choose to state everything in terms of left options for uniform
treatment. -/
def P4 (x₁ x₂ y : PGame) :=
x₁ < x₂ → (∀ i, P3 x₁ x₂ (y.moveLeft i) y) ∧ ∀ j, P3 x₁ x₂ ((-y).moveLeft j) (-y)
/-- The conjunction of P2 and P4. -/
def P24 (x₁ x₂ y : PGame) : Prop := P2 x₁ x₂ y ∧ P4 x₁ x₂ y
variable {x x₁ x₂ x₃ x' y y₁ y₂ y₃ y' : PGame.{u}}
/-! #### Symmetry properties of P1, P2, P3, and P4 -/
lemma P3_comm : P3 x₁ x₂ y₁ y₂ ↔ P3 y₁ y₂ x₁ x₂ := by
rw [P3, P3, add_comm]
congr! 2 <;> rw [quot_mul_comm]
lemma P3.trans (h₁ : P3 x₁ x₂ y₁ y₂) (h₂ : P3 x₂ x₃ y₁ y₂) : P3 x₁ x₃ y₁ y₂ := by
rw [P3] at h₁ h₂
rw [P3, ← add_lt_add_iff_left (⟦x₂ * y₁⟧ + ⟦x₂ * y₂⟧)]
convert add_lt_add h₁ h₂ using 1 <;> abel
lemma P3_neg : P3 x₁ x₂ y₁ y₂ ↔ P3 (-x₂) (-x₁) y₁ y₂ := by
simp_rw [P3, quot_neg_mul]
rw [← _root_.neg_lt_neg_iff]
abel_nf
lemma P2_neg_left : P2 x₁ x₂ y ↔ P2 (-x₂) (-x₁) y := by
rw [P2, P2]
constructor
· rw [quot_neg_mul, quot_neg_mul, eq_comm, neg_inj, neg_equiv_neg_iff, PGame.equiv_comm]
exact (· ·)
· rw [PGame.equiv_comm, neg_equiv_neg_iff, quot_neg_mul, quot_neg_mul, neg_inj, eq_comm]
exact (· ·)
lemma P2_neg_right : P2 x₁ x₂ y ↔ P2 x₁ x₂ (-y) := by
rw [P2, P2, quot_mul_neg, quot_mul_neg, neg_inj]
lemma P4_neg_left : P4 x₁ x₂ y ↔ P4 (-x₂) (-x₁) y := by
simp_rw [P4, PGame.neg_lt_neg_iff, moveLeft_neg, ← P3_neg]
lemma P4_neg_right : P4 x₁ x₂ y ↔ P4 x₁ x₂ (-y) := by
rw [P4, P4, neg_neg, and_comm]
lemma P24_neg_left : P24 x₁ x₂ y ↔ P24 (-x₂) (-x₁) y := by rw [P24, P24, P2_neg_left, P4_neg_left]
lemma P24_neg_right : P24 x₁ x₂ y ↔ P24 x₁ x₂ (-y) := by rw [P24, P24, P2_neg_right, P4_neg_right]
/-! #### Explicit calculations necessary for the main proof -/
lemma mulOption_lt_iff_P1 {i j k l} :
(⟦mulOption x y i k⟧ : Game) < -⟦mulOption x (-y) j l⟧ ↔
P1 (x.moveLeft i) x (x.moveLeft j) y (y.moveLeft k) (-(-y).moveLeft l) := by
dsimp only [P1, mulOption, quot_sub, quot_add]
simp_rw [neg_sub', neg_add, quot_mul_neg, neg_neg]
lemma mulOption_lt_mul_iff_P3 {i j} :
⟦mulOption x y i j⟧ < (⟦x * y⟧ : Game) ↔ P3 (x.moveLeft i) x (y.moveLeft j) y := by
dsimp only [mulOption, quot_sub, quot_add]
exact sub_lt_iff_lt_add'
| lemma P1_of_eq (he : x₁ ≈ x₃) (h₁ : P2 x₁ x₃ y₁) (h₃ : P2 x₁ x₃ y₃) (h3 : P3 x₁ x₂ y₂ y₃) :
P1 x₁ x₂ x₃ y₁ y₂ y₃ := by
rw [P1, ← h₁ he, ← h₃ he, sub_lt_sub_iff]
convert add_lt_add_left h3 ⟦x₁ * y₁⟧ using 1 <;> abel
| Mathlib/SetTheory/Surreal/Multiplication.lean | 143 | 146 |
/-
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.Algebra.Field.NegOnePow
import Mathlib.Algebra.Field.Periodic
import Mathlib.Algebra.QuadraticDiscriminant
import Mathlib.Analysis.SpecialFunctions.Exp
/-!
# Trigonometric functions
## Main definitions
This file contains the definition of `π`.
See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and
`Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions.
See also `Analysis.SpecialFunctions.Complex.Arg` and
`Analysis.SpecialFunctions.Complex.Log` for the complex argument function
and the complex logarithm.
## Main statements
Many basic inequalities on the real trigonometric functions are established.
The continuity of the usual trigonometric functions is proved.
Several facts about the real trigonometric functions have the proofs deferred to
`Analysis.SpecialFunctions.Trigonometric.Complex`,
as they are most easily proved by appealing to the corresponding fact for
complex trigonometric functions.
See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas
in terms of Chebyshev polynomials.
## Tags
sin, cos, tan, angle
-/
noncomputable section
open Topology Filter Set
namespace Complex
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin := by
change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2
fun_prop
@[fun_prop]
theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s :=
continuous_sin.continuousOn
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos := by
change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2
fun_prop
@[fun_prop]
theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s :=
continuous_cos.continuousOn
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh := by
change Continuous fun z => (exp z - exp (-z)) / 2
fun_prop
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh := by
change Continuous fun z => (exp z + exp (-z)) / 2
fun_prop
end Complex
namespace Real
variable {x y z : ℝ}
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin :=
Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal)
@[fun_prop]
theorem continuousOn_sin {s} : ContinuousOn sin s :=
continuous_sin.continuousOn
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos :=
Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal)
@[fun_prop]
theorem continuousOn_cos {s} : ContinuousOn cos s :=
continuous_cos.continuousOn
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh :=
Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal)
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh :=
Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal)
end Real
namespace Real
theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuousOn_cos
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`.
Denoted `π`, once the `Real` namespace is opened. -/
protected noncomputable def pi : ℝ :=
2 * Classical.choose exists_cos_eq_zero
@[inherit_doc]
scoped notation "π" => Real.pi
@[simp]
theorem cos_pi_div_two : cos (π / 2) = 0 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).2
theorem one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).1.1
theorem pi_div_two_le_two : π / 2 ≤ 2 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).1.2
theorem two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1
(by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two)
theorem pi_le_four : π ≤ 4 :=
(div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1
(calc
π / 2 ≤ 2 := pi_div_two_le_two
_ = 4 / 2 := by norm_num)
@[bound]
theorem pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
@[bound]
theorem pi_nonneg : 0 ≤ π :=
pi_pos.le
theorem pi_ne_zero : π ≠ 0 :=
pi_pos.ne'
theorem pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos]
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `π` is always positive. -/
@[positivity Real.pi]
def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.pi) =>
assertInstancesCommute
pure (.positive q(Real.pi_pos))
| _, _, _ => throwError "not Real.pi"
end Mathlib.Meta.Positivity
namespace NNReal
open Real
open Real NNReal
/-- `π` considered as a nonnegative real. -/
noncomputable def pi : ℝ≥0 :=
⟨π, Real.pi_pos.le⟩
@[simp]
theorem coe_real_pi : (pi : ℝ) = π :=
rfl
theorem pi_pos : 0 < pi := mod_cast Real.pi_pos
theorem pi_ne_zero : pi ≠ 0 :=
pi_pos.ne'
end NNReal
namespace Real
@[simp]
theorem sin_pi : sin π = 0 := by
rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp
@[simp]
theorem cos_pi : cos π = -1 := by
rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two]
norm_num
@[simp]
theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add]
@[simp]
theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add]
theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add]
theorem sin_periodic : Function.Periodic sin (2 * π) :=
sin_antiperiodic.periodic_two_mul
@[simp]
theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
sin_antiperiodic x
@[simp]
theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
sin_periodic x
@[simp]
theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
@[simp]
theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
@[simp]
theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
@[simp]
theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
@[simp]
theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
@[simp]
theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
@[simp]
theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
@[simp]
theorem sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
@[simp]
theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
@[simp]
theorem sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
@[simp]
theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
@[simp]
theorem sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
theorem sin_add_int_mul_pi (x : ℝ) (n : ℤ) : sin (x + n * π) = (-1) ^ n * sin x :=
n.cast_negOnePow ℝ ▸ sin_antiperiodic.add_int_mul_eq n
theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x :=
sin_antiperiodic.add_nat_mul_eq n
theorem sin_sub_int_mul_pi (x : ℝ) (n : ℤ) : sin (x - n * π) = (-1) ^ n * sin x :=
n.cast_negOnePow ℝ ▸ sin_antiperiodic.sub_int_mul_eq n
theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x :=
sin_antiperiodic.sub_nat_mul_eq n
theorem sin_int_mul_pi_sub (x : ℝ) (n : ℤ) : sin (n * π - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg, Int.cast_negOnePow] using sin_antiperiodic.int_mul_sub_eq n
theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n
theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add]
theorem cos_periodic : Function.Periodic cos (2 * π) :=
cos_antiperiodic.periodic_two_mul
@[simp]
theorem abs_cos_int_mul_pi (k : ℤ) : |cos (k * π)| = 1 := by
simp [abs_cos_eq_sqrt_one_sub_sin_sq]
@[simp]
theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
cos_antiperiodic x
@[simp]
theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
cos_periodic x
@[simp]
theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
@[simp]
theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
@[simp]
theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
@[simp]
theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
@[simp]
theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
@[simp]
theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
@[simp]
theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
@[simp]
theorem cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
@[simp]
theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
@[simp]
theorem cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
@[simp]
theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
@[simp]
theorem cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
theorem cos_add_int_mul_pi (x : ℝ) (n : ℤ) : cos (x + n * π) = (-1) ^ n * cos x :=
n.cast_negOnePow ℝ ▸ cos_antiperiodic.add_int_mul_eq n
theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x :=
cos_antiperiodic.add_nat_mul_eq n
theorem cos_sub_int_mul_pi (x : ℝ) (n : ℤ) : cos (x - n * π) = (-1) ^ n * cos x :=
n.cast_negOnePow ℝ ▸ cos_antiperiodic.sub_int_mul_eq n
theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x :=
cos_antiperiodic.sub_nat_mul_eq n
theorem cos_int_mul_pi_sub (x : ℝ) (n : ℤ) : cos (n * π - x) = (-1) ^ n * cos x :=
n.cast_negOnePow ℝ ▸ cos_neg x ▸ cos_antiperiodic.int_mul_sub_eq n
theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x :=
cos_neg x ▸ cos_antiperiodic.nat_mul_sub_eq n
theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have : (2 : ℝ) + 2 = 4 := by norm_num
have : π - x ≤ 2 :=
sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _))
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x :=
sin_pos_of_pos_of_lt_pi hx.1 hx.2
theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := by
rw [← closure_Ioo pi_ne_zero.symm] at hx
exact
closure_lt_subset_le continuous_const continuous_sin
(closure_mono (fun y => sin_pos_of_mem_Ioo) hx)
theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩
theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 <| sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 <| sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp]
theorem sin_pi_div_two : sin (π / 2) = 1 :=
have : sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by
simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2)
this.resolve_right fun h =>
show ¬(0 : ℝ) < -1 by norm_num <|
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos)
theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add]
theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add]
theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add]
theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add]
theorem cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add]
theorem cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by
rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x :=
sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩
theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x :=
sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩
theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
0 ≤ cos x :=
cos_nonneg_of_mem_Icc ⟨hl, hu⟩
theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) :
cos x < 0 :=
neg_pos.1 <| cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩
theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) :
cos x ≤ 0 :=
neg_nonneg.1 <| cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩
theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) :
sin x = √(1 - cos x ^ 2) := by
rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)]
theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
cos x = √(1 - sin x ^ 2) := by
rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)]
lemma cos_half {x : ℝ} (hl : -π ≤ x) (hr : x ≤ π) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by
have : 0 ≤ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith
rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves]
lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by
rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div]
lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≤ x) (hr : x ≤ 2 * π) :
sin (x / 2) = sqrt ((1 - cos x) / 2) := by
rw [← abs_sin_half, abs_of_nonneg]
apply sin_nonneg_of_nonneg_of_le_pi <;> linarith
lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * π) ≤ x) (hr : x ≤ 0) :
sin (x / 2) = -sqrt ((1 - cos x) / 2) := by
rw [← abs_sin_half, abs_of_nonpos, neg_neg]
apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith
theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 :=
⟨fun h => by
contrapose! h
cases h.lt_or_lt with
| inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne
| inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hx₂).ne',
fun h => by simp [h]⟩
theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x :=
⟨fun h =>
⟨⌊x / π⌋,
le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 <|
le_of_not_gt fun h₃ =>
(sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
fun ⟨_, hn⟩ => hn ▸ sin_int_mul_pi _⟩
theorem sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x := by
rw [← not_exists, not_iff_not, sin_eq_zero_iff]
theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by
rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self]
exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩
theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
⟨fun h =>
let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h))
⟨n / 2,
(Int.emod_two_eq_zero_or_one n).elim
(fun hn0 => by
rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul,
Int.ediv_mul_cancel (Int.dvd_iff_emod_eq_zero.2 hn0)])
fun hn1 => by
rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm,
mul_comm (2 : ℤ), Int.cast_mul, mul_assoc, Int.cast_two] at hn
rw [← hn, cos_int_mul_two_pi_add_pi] at h
exact absurd h (by norm_num)⟩,
fun ⟨_, hn⟩ => hn ▸ cos_int_mul_two_pi _⟩
theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) :
cos x = 1 ↔ x = 0 :=
⟨fun h => by
rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩
rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁
norm_cast at hx₁ hx₂
obtain rfl : n = 0 := le_antisymm (by omega) (by omega)
simp, fun h => by simp [h]⟩
theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) : sin x < sin y := by
rw [← sub_pos, sin_sub_sin]
have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith
have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith
positivity
theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(π / 2)) (π / 2)) := fun _ hx _ hy hxy =>
sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy
theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) :
cos y < cos x := by
rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub]
apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith
theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) : cos y < cos x :=
cos_lt_cos_of_nonneg_of_le_pi hx₁ (hy₂.trans (by linarith)) hxy
theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 π) := fun _ hx _ hy hxy =>
cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy
theorem cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) :
cos y ≤ cos x :=
(strictAntiOn_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy
theorem sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x ≤ y) : sin x ≤ sin y :=
(strictMonoOn_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy
theorem injOn_sin : InjOn sin (Icc (-(π / 2)) (π / 2)) :=
strictMonoOn_sin.injOn
theorem injOn_cos : InjOn cos (Icc 0 π) :=
strictAntiOn_cos.injOn
theorem surjOn_sin : SurjOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := by
simpa only [sin_neg, sin_pi_div_two] using
intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn
theorem surjOn_cos : SurjOn cos (Icc 0 π) (Icc (-1) 1) := by
simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn
theorem sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 :=
⟨neg_one_le_sin x, sin_le_one x⟩
theorem cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 :=
⟨neg_one_le_cos x, cos_le_one x⟩
theorem mapsTo_sin (s : Set ℝ) : MapsTo sin s (Icc (-1 : ℝ) 1) := fun x _ => sin_mem_Icc x
theorem mapsTo_cos (s : Set ℝ) : MapsTo cos s (Icc (-1 : ℝ) 1) := fun x _ => cos_mem_Icc x
theorem bijOn_sin : BijOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
⟨mapsTo_sin _, injOn_sin, surjOn_sin⟩
theorem bijOn_cos : BijOn cos (Icc 0 π) (Icc (-1) 1) :=
⟨mapsTo_cos _, injOn_cos, surjOn_cos⟩
@[simp]
theorem range_cos : range cos = (Icc (-1) 1 : Set ℝ) :=
Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range
@[simp]
theorem range_sin : range sin = (Icc (-1) 1 : Set ℝ) :=
Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range
theorem range_cos_infinite : (range Real.cos).Infinite := by
rw [Real.range_cos]
exact Icc_infinite (by norm_num)
theorem range_sin_infinite : (range Real.sin).Infinite := by
rw [Real.range_sin]
exact Icc_infinite (by norm_num)
section CosDivSq
variable (x : ℝ)
/-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,
starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2`
-/
@[simp]
noncomputable def sqrtTwoAddSeries (x : ℝ) : ℕ → ℝ
| 0 => x
| n + 1 => √(2 + sqrtTwoAddSeries x n)
theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp
theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = √2 := by simp
theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = √(2 + √2) := by simp
theorem sqrtTwoAddSeries_zero_nonneg : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries 0 n
| 0 => le_refl 0
| _ + 1 => sqrt_nonneg _
theorem sqrtTwoAddSeries_nonneg {x : ℝ} (h : 0 ≤ x) : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries x n
| 0 => h
| _ + 1 => sqrt_nonneg _
theorem sqrtTwoAddSeries_lt_two : ∀ n : ℕ, sqrtTwoAddSeries 0 n < 2
| 0 => by norm_num
| n + 1 => by
refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le
rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt']
· refine (sqrtTwoAddSeries_lt_two n).trans_le ?_
norm_num
· exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n)
theorem sqrtTwoAddSeries_succ (x : ℝ) :
∀ n : ℕ, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (√(2 + x)) n
| 0 => rfl
| n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries]
theorem sqrtTwoAddSeries_monotone_left {x y : ℝ} (h : x ≤ y) :
∀ n : ℕ, sqrtTwoAddSeries x n ≤ sqrtTwoAddSeries y n
| 0 => h
| n + 1 => by
rw [sqrtTwoAddSeries, sqrtTwoAddSeries]
exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _)
@[simp]
theorem cos_pi_over_two_pow : ∀ n : ℕ, cos (π / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2
| 0 => by simp
| n + 1 => by
have A : (1 : ℝ) < 2 ^ (n + 1) := one_lt_pow₀ one_lt_two n.succ_ne_zero
have B : π / 2 ^ (n + 1) < π := div_lt_self pi_pos A
have C : 0 < π / 2 ^ (n + 1) := by positivity
rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries,
add_div_eq_mul_add_div, one_mul, ← div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;>
linarith [sqrtTwoAddSeries_nonneg le_rfl n]
theorem sin_sq_pi_over_two_pow (n : ℕ) :
sin (π / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by
rw [sin_sq, cos_pi_over_two_pow]
theorem sin_sq_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by
rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub]
· congr
· norm_num
· norm_num
· exact add_nonneg two_pos.le (sqrtTwoAddSeries_zero_nonneg _)
@[simp]
theorem sin_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n + 2)) = √(2 - sqrtTwoAddSeries 0 n) / 2 := by
rw [eq_div_iff_mul_eq two_ne_zero, eq_comm, sqrt_eq_iff_eq_sq, mul_pow,
sin_sq_pi_over_two_pow_succ, sub_mul]
· congr <;> norm_num
· rw [sub_nonneg]
exact (sqrtTwoAddSeries_lt_two _).le
refine mul_nonneg (sin_nonneg_of_nonneg_of_le_pi ?_ ?_) zero_le_two
· positivity
· exact div_le_self pi_pos.le <| one_le_pow₀ one_le_two
@[simp]
theorem cos_pi_div_four : cos (π / 4) = √2 / 2 := by
trans cos (π / 2 ^ 2)
· congr
norm_num
· simp
@[simp]
theorem sin_pi_div_four : sin (π / 4) = √2 / 2 := by
trans sin (π / 2 ^ 2)
· congr
norm_num
· simp
@[simp]
theorem cos_pi_div_eight : cos (π / 8) = √(2 + √2) / 2 := by
trans cos (π / 2 ^ 3)
· congr
norm_num
· simp
@[simp]
theorem sin_pi_div_eight : sin (π / 8) = √(2 - √2) / 2 := by
trans sin (π / 2 ^ 3)
· congr
norm_num
· simp
@[simp]
theorem cos_pi_div_sixteen : cos (π / 16) = √(2 + √(2 + √2)) / 2 := by
trans cos (π / 2 ^ 4)
· congr
norm_num
· simp
@[simp]
theorem sin_pi_div_sixteen : sin (π / 16) = √(2 - √(2 + √2)) / 2 := by
trans sin (π / 2 ^ 4)
· congr
norm_num
· simp
@[simp]
theorem cos_pi_div_thirty_two : cos (π / 32) = √(2 + √(2 + √(2 + √2))) / 2 := by
trans cos (π / 2 ^ 5)
· congr
norm_num
· simp
@[simp]
theorem sin_pi_div_thirty_two : sin (π / 32) = √(2 - √(2 + √(2 + √2))) / 2 := by
trans sin (π / 2 ^ 5)
· congr
norm_num
· simp
-- This section is also a convenient location for other explicit values of `sin` and `cos`.
/-- The cosine of `π / 3` is `1 / 2`. -/
@[simp]
theorem cos_pi_div_three : cos (π / 3) = 1 / 2 := by
have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 := by
have : cos (3 * (π / 3)) = cos π := by
congr 1
ring
linarith [cos_pi, cos_three_mul (π / 3)]
rcases mul_eq_zero.mp h₁ with h | h
· linarith [pow_eq_zero h]
· have : cos π < cos (π / 3) := by
refine cos_lt_cos_of_nonneg_of_le_pi ?_ le_rfl ?_ <;> linarith [pi_pos]
linarith [cos_pi]
/-- The cosine of `π / 6` is `√3 / 2`. -/
@[simp]
theorem cos_pi_div_six : cos (π / 6) = √3 / 2 := by
| rw [show (6 : ℝ) = 3 * 2 by norm_num, div_mul_eq_div_div, cos_half, cos_pi_div_three, one_add_div,
← div_mul_eq_div_div, two_add_one_eq_three, sqrt_div, sqrt_mul_self] <;> linarith [pi_pos]
/-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean | 765 | 768 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,
Neil Strickland, Aaron Anderson
-/
import Mathlib.Algebra.Group.Basic
import Mathlib.Tactic.Common
/-!
# Divisibility
This file defines the basics of the divisibility relation in the context of `(Comm)` `Monoid`s.
## Main definitions
* `semigroupDvd`
## Implementation notes
The divisibility relation is defined for all monoids, and as such, depends on the order of
multiplication if the monoid is not commutative. There are two possible conventions for
divisibility in the noncommutative context, and this relation follows the convention for ordinals,
so `a | b` is defined as `∃ c, b = a * c`.
## Tags
divisibility, divides
-/
variable {α : Type*}
section Semigroup
variable [Semigroup α] {a b c : α}
/-- There are two possible conventions for divisibility, which coincide in a `CommMonoid`.
This matches the convention for ordinals. -/
instance (priority := 100) semigroupDvd : Dvd α :=
Dvd.mk fun a b => ∃ c, b = a * c
-- TODO: this used to not have `c` explicit, but that seems to be important
-- for use with tactics, similar to `Exists.intro`
theorem Dvd.intro (c : α) (h : a * c = b) : a ∣ b :=
Exists.intro c h.symm
alias dvd_of_mul_right_eq := Dvd.intro
theorem exists_eq_mul_right_of_dvd (h : a ∣ b) : ∃ c, b = a * c :=
h
theorem dvd_def : a ∣ b ↔ ∃ c, b = a * c :=
Iff.rfl
alias dvd_iff_exists_eq_mul_right := dvd_def
theorem Dvd.elim {P : Prop} {a b : α} (H₁ : a ∣ b) (H₂ : ∀ c, b = a * c → P) : P :=
Exists.elim H₁ H₂
attribute [local simp] mul_assoc mul_comm mul_left_comm
@[trans]
theorem dvd_trans : a ∣ b → b ∣ c → a ∣ c
| ⟨d, h₁⟩, ⟨e, h₂⟩ => ⟨d * e, h₁ ▸ h₂.trans <| mul_assoc a d e⟩
alias Dvd.dvd.trans := dvd_trans
/-- Transitivity of `|` for use in `calc` blocks. -/
instance : IsTrans α Dvd.dvd :=
⟨fun _ _ _ => dvd_trans⟩
@[simp]
theorem dvd_mul_right (a b : α) : a ∣ a * b :=
Dvd.intro b rfl
theorem dvd_mul_of_dvd_left (h : a ∣ b) (c : α) : a ∣ b * c :=
h.trans (dvd_mul_right b c)
alias Dvd.dvd.mul_right := dvd_mul_of_dvd_left
theorem dvd_of_mul_right_dvd (h : a * b ∣ c) : a ∣ c :=
(dvd_mul_right a b).trans h
/-- An element `a` in a semigroup is primal if whenever `a` is a divisor of `b * c`, it can be
factored as the product of a divisor of `b` and a divisor of `c`. -/
def IsPrimal (a : α) : Prop := ∀ ⦃b c⦄, a ∣ b * c → ∃ a₁ a₂, a₁ ∣ b ∧ a₂ ∣ c ∧ a = a₁ * a₂
variable (α) in
/-- A monoid is a decomposition monoid if every element is primal. An integral domain whose
multiplicative monoid is a decomposition monoid, is called a pre-Schreier domain; it is a
Schreier domain if it is moreover integrally closed. -/
@[mk_iff] class DecompositionMonoid : Prop where
primal (a : α) : IsPrimal a
theorem exists_dvd_and_dvd_of_dvd_mul [DecompositionMonoid α] {b c a : α} (H : a ∣ b * c) :
∃ a₁ a₂, a₁ ∣ b ∧ a₂ ∣ c ∧ a = a₁ * a₂ := DecompositionMonoid.primal a H
end Semigroup
section Monoid
variable [Monoid α] {a b c : α} {m n : ℕ}
@[refl, simp]
theorem dvd_refl (a : α) : a ∣ a :=
Dvd.intro 1 (mul_one a)
theorem dvd_rfl : ∀ {a : α}, a ∣ a := fun {a} => dvd_refl a
instance : IsRefl α (· ∣ ·) :=
⟨dvd_refl⟩
theorem one_dvd (a : α) : 1 ∣ a :=
Dvd.intro a (one_mul a)
theorem dvd_of_eq (h : a = b) : a ∣ b := by rw [h]
alias Eq.dvd := dvd_of_eq
lemma pow_dvd_pow (a : α) (h : m ≤ n) : a ^ m ∣ a ^ n :=
⟨a ^ (n - m), by rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h]⟩
lemma dvd_pow (hab : a ∣ b) : ∀ {n : ℕ} (_ : n ≠ 0), a ∣ b ^ n
| 0, hn => (hn rfl).elim
| n + 1, _ => by rw [pow_succ']; exact hab.mul_right _
alias Dvd.dvd.pow := dvd_pow
lemma dvd_pow_self (a : α) {n : ℕ} (hn : n ≠ 0) : a ∣ a ^ n := dvd_rfl.pow hn
theorem mul_dvd_mul_left (a : α) (h : b ∣ c) : a * b ∣ a * c := by
obtain ⟨d, rfl⟩ := h
use d
rw [mul_assoc]
end Monoid
section CommSemigroup
variable [CommSemigroup α] {a b c : α}
theorem Dvd.intro_left (c : α) (h : c * a = b) : a ∣ b :=
Dvd.intro c (by rw [mul_comm] at h; apply h)
alias dvd_of_mul_left_eq := Dvd.intro_left
theorem exists_eq_mul_left_of_dvd (h : a ∣ b) : ∃ c, b = c * a :=
Dvd.elim h fun c => fun H1 : b = a * c => Exists.intro c (Eq.trans H1 (mul_comm a c))
theorem dvd_iff_exists_eq_mul_left : a ∣ b ↔ ∃ c, b = c * a :=
⟨exists_eq_mul_left_of_dvd, by
rintro ⟨c, rfl⟩
exact ⟨c, mul_comm _ _⟩⟩
theorem Dvd.elim_left {P : Prop} (h₁ : a ∣ b) (h₂ : ∀ c, b = c * a → P) : P :=
Exists.elim (exists_eq_mul_left_of_dvd h₁) fun c => fun h₃ : b = c * a => h₂ c h₃
@[simp]
theorem dvd_mul_left (a b : α) : a ∣ b * a :=
Dvd.intro b (mul_comm a b)
theorem dvd_mul_of_dvd_right (h : a ∣ b) (c : α) : a ∣ c * b := by
rw [mul_comm]; exact h.mul_right _
alias Dvd.dvd.mul_left := dvd_mul_of_dvd_right
attribute [local simp] mul_assoc mul_comm mul_left_comm
theorem mul_dvd_mul : ∀ {a b c d : α}, a ∣ b → c ∣ d → a * c ∣ b * d
| a, _, c, _, ⟨e, rfl⟩, ⟨f, rfl⟩ => ⟨e * f, by simp⟩
theorem dvd_of_mul_left_dvd (h : a * b ∣ c) : b ∣ c :=
Dvd.elim h fun d ceq => Dvd.intro (a * d) (by simp [ceq])
theorem dvd_mul [DecompositionMonoid α] {k m n : α} :
k ∣ m * n ↔ ∃ d₁ d₂, d₁ ∣ m ∧ d₂ ∣ n ∧ k = d₁ * d₂ := by
refine ⟨exists_dvd_and_dvd_of_dvd_mul, ?_⟩
rintro ⟨d₁, d₂, hy, hz, rfl⟩
exact mul_dvd_mul hy hz
end CommSemigroup
section CommMonoid
variable [CommMonoid α] {a b : α}
theorem mul_dvd_mul_right (h : a ∣ b) (c : α) : a * c ∣ b * c :=
mul_dvd_mul h (dvd_refl c)
theorem pow_dvd_pow_of_dvd (h : a ∣ b) : ∀ n : ℕ, a ^ n ∣ b ^ n
| 0 => by rw [pow_zero, pow_zero]
| n + 1 => by
rw [pow_succ, pow_succ]
exact mul_dvd_mul (pow_dvd_pow_of_dvd h n) h
end CommMonoid
| Mathlib/Algebra/Divisibility/Basic.lean | 209 | 210 | |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro
-/
import Mathlib.Algebra.Notation.Defs
import Mathlib.Data.Int.Notation
import Mathlib.Data.Nat.BinaryRec
import Mathlib.Logic.Function.Defs
import Mathlib.Tactic.Simps.Basic
import Mathlib.Tactic.OfNat
import Batteries.Logic
/-!
# Typeclasses for (semi)groups and monoids
In this file we define typeclasses for algebraic structures with one binary operation.
The classes are named `(Add)?(Comm)?(Semigroup|Monoid|Group)`, where `Add` means that
the class uses additive notation and `Comm` means that the class assumes that the binary
operation is commutative.
The file does not contain any lemmas except for
* axioms of typeclasses restated in the root namespace;
* lemmas required for instances.
For basic lemmas about these classes see `Algebra.Group.Basic`.
We register the following instances:
- `Pow M ℕ`, for monoids `M`, and `Pow G ℤ` for groups `G`;
- `SMul ℕ M` for additive monoids `M`, and `SMul ℤ G` for additive groups `G`.
## Notation
- `+`, `-`, `*`, `/`, `^` : the usual arithmetic operations; the underlying functions are
`Add.add`, `Neg.neg`/`Sub.sub`, `Mul.mul`, `Div.div`, and `HPow.hPow`.
-/
assert_not_exists MonoidWithZero DenselyOrdered Function.const_injective
universe u v w
open Function
variable {G : Type*}
section Mul
variable [Mul G]
/-- `leftMul g` denotes left multiplication by `g` -/
@[to_additive "`leftAdd g` denotes left addition by `g`"]
def leftMul : G → G → G := fun g : G ↦ fun x : G ↦ g * x
/-- `rightMul g` denotes right multiplication by `g` -/
@[to_additive "`rightAdd g` denotes right addition by `g`"]
def rightMul : G → G → G := fun g : G ↦ fun x : G ↦ x * g
attribute [deprecated HMul.hMul "Use (g * ·) instead" (since := "2025-04-08")] leftMul
attribute [deprecated HAdd.hAdd "Use (g + ·) instead" (since := "2025-04-08")] leftAdd
attribute [deprecated HMul.hMul "Use (· * g) instead" (since := "2025-04-08")] rightMul
attribute [deprecated HAdd.hAdd "Use (· + g) instead" (since := "2025-04-08")] rightAdd
/-- A mixin for left cancellative multiplication. -/
class IsLeftCancelMul (G : Type u) [Mul G] : Prop where
/-- Multiplication is left cancellative. -/
protected mul_left_cancel : ∀ a b c : G, a * b = a * c → b = c
/-- A mixin for right cancellative multiplication. -/
class IsRightCancelMul (G : Type u) [Mul G] : Prop where
/-- Multiplication is right cancellative. -/
protected mul_right_cancel : ∀ a b c : G, a * b = c * b → a = c
/-- A mixin for cancellative multiplication. -/
class IsCancelMul (G : Type u) [Mul G] : Prop extends IsLeftCancelMul G, IsRightCancelMul G
/-- A mixin for left cancellative addition. -/
class IsLeftCancelAdd (G : Type u) [Add G] : Prop where
/-- Addition is left cancellative. -/
protected add_left_cancel : ∀ a b c : G, a + b = a + c → b = c
attribute [to_additive IsLeftCancelAdd] IsLeftCancelMul
/-- A mixin for right cancellative addition. -/
class IsRightCancelAdd (G : Type u) [Add G] : Prop where
/-- Addition is right cancellative. -/
protected add_right_cancel : ∀ a b c : G, a + b = c + b → a = c
attribute [to_additive IsRightCancelAdd] IsRightCancelMul
/-- A mixin for cancellative addition. -/
class IsCancelAdd (G : Type u) [Add G] : Prop extends IsLeftCancelAdd G, IsRightCancelAdd G
attribute [to_additive IsCancelAdd] IsCancelMul
section IsLeftCancelMul
variable [IsLeftCancelMul G] {a b c : G}
@[to_additive]
theorem mul_left_cancel : a * b = a * c → b = c :=
IsLeftCancelMul.mul_left_cancel a b c
@[to_additive]
theorem mul_left_cancel_iff : a * b = a * c ↔ b = c :=
⟨mul_left_cancel, congrArg _⟩
@[to_additive]
theorem mul_right_injective (a : G) : Injective (a * ·) := fun _ _ ↦ mul_left_cancel
@[to_additive (attr := simp)]
theorem mul_right_inj (a : G) {b c : G} : a * b = a * c ↔ b = c :=
(mul_right_injective a).eq_iff
@[to_additive]
theorem mul_ne_mul_right (a : G) {b c : G} : a * b ≠ a * c ↔ b ≠ c :=
(mul_right_injective a).ne_iff
end IsLeftCancelMul
section IsRightCancelMul
variable [IsRightCancelMul G] {a b c : G}
@[to_additive]
theorem mul_right_cancel : a * b = c * b → a = c :=
IsRightCancelMul.mul_right_cancel a b c
@[to_additive]
theorem mul_right_cancel_iff : b * a = c * a ↔ b = c :=
⟨mul_right_cancel, congrArg (· * a)⟩
@[to_additive]
theorem mul_left_injective (a : G) : Function.Injective (· * a) := fun _ _ ↦ mul_right_cancel
@[to_additive (attr := simp)]
theorem mul_left_inj (a : G) {b c : G} : b * a = c * a ↔ b = c :=
(mul_left_injective a).eq_iff
@[to_additive]
theorem mul_ne_mul_left (a : G) {b c : G} : b * a ≠ c * a ↔ b ≠ c :=
(mul_left_injective a).ne_iff
end IsRightCancelMul
end Mul
/-- A semigroup is a type with an associative `(*)`. -/
@[ext]
class Semigroup (G : Type u) extends Mul G where
/-- Multiplication is associative -/
protected mul_assoc : ∀ a b c : G, a * b * c = a * (b * c)
/-- An additive semigroup is a type with an associative `(+)`. -/
@[ext]
class AddSemigroup (G : Type u) extends Add G where
/-- Addition is associative -/
protected add_assoc : ∀ a b c : G, a + b + c = a + (b + c)
attribute [to_additive] Semigroup
section Semigroup
variable [Semigroup G]
@[to_additive]
theorem mul_assoc : ∀ a b c : G, a * b * c = a * (b * c) :=
Semigroup.mul_assoc
end Semigroup
/-- A commutative additive magma is a type with an addition which commutes. -/
@[ext]
class AddCommMagma (G : Type u) extends Add G where
/-- Addition is commutative in an commutative additive magma. -/
protected add_comm : ∀ a b : G, a + b = b + a
/-- A commutative multiplicative magma is a type with a multiplication which commutes. -/
@[ext]
class CommMagma (G : Type u) extends Mul G where
/-- Multiplication is commutative in a commutative multiplicative magma. -/
protected mul_comm : ∀ a b : G, a * b = b * a
attribute [to_additive] CommMagma
/-- A commutative semigroup is a type with an associative commutative `(*)`. -/
@[ext]
class CommSemigroup (G : Type u) extends Semigroup G, CommMagma G where
/-- A commutative additive semigroup is a type with an associative commutative `(+)`. -/
@[ext]
class AddCommSemigroup (G : Type u) extends AddSemigroup G, AddCommMagma G where
attribute [to_additive] CommSemigroup
section CommMagma
variable [CommMagma G]
@[to_additive]
theorem mul_comm : ∀ a b : G, a * b = b * a := CommMagma.mul_comm
/-- Any `CommMagma G` that satisfies `IsRightCancelMul G` also satisfies `IsLeftCancelMul G`. -/
@[to_additive AddCommMagma.IsRightCancelAdd.toIsLeftCancelAdd "Any `AddCommMagma G` that satisfies
`IsRightCancelAdd G` also satisfies `IsLeftCancelAdd G`."]
lemma CommMagma.IsRightCancelMul.toIsLeftCancelMul (G : Type u) [CommMagma G] [IsRightCancelMul G] :
IsLeftCancelMul G :=
⟨fun _ _ _ h => mul_right_cancel <| (mul_comm _ _).trans (h.trans (mul_comm _ _))⟩
/-- Any `CommMagma G` that satisfies `IsLeftCancelMul G` also satisfies `IsRightCancelMul G`. -/
@[to_additive AddCommMagma.IsLeftCancelAdd.toIsRightCancelAdd "Any `AddCommMagma G` that satisfies
`IsLeftCancelAdd G` also satisfies `IsRightCancelAdd G`."]
lemma CommMagma.IsLeftCancelMul.toIsRightCancelMul (G : Type u) [CommMagma G] [IsLeftCancelMul G] :
IsRightCancelMul G :=
⟨fun _ _ _ h => mul_left_cancel <| (mul_comm _ _).trans (h.trans (mul_comm _ _))⟩
/-- Any `CommMagma G` that satisfies `IsLeftCancelMul G` also satisfies `IsCancelMul G`. -/
@[to_additive AddCommMagma.IsLeftCancelAdd.toIsCancelAdd "Any `AddCommMagma G` that satisfies
`IsLeftCancelAdd G` also satisfies `IsCancelAdd G`."]
lemma CommMagma.IsLeftCancelMul.toIsCancelMul (G : Type u) [CommMagma G] [IsLeftCancelMul G] :
IsCancelMul G := { CommMagma.IsLeftCancelMul.toIsRightCancelMul G with }
/-- Any `CommMagma G` that satisfies `IsRightCancelMul G` also satisfies `IsCancelMul G`. -/
@[to_additive AddCommMagma.IsRightCancelAdd.toIsCancelAdd "Any `AddCommMagma G` that satisfies
`IsRightCancelAdd G` also satisfies `IsCancelAdd G`."]
lemma CommMagma.IsRightCancelMul.toIsCancelMul (G : Type u) [CommMagma G] [IsRightCancelMul G] :
IsCancelMul G := { CommMagma.IsRightCancelMul.toIsLeftCancelMul G with }
end CommMagma
/-- A `LeftCancelSemigroup` is a semigroup such that `a * b = a * c` implies `b = c`. -/
@[ext]
class LeftCancelSemigroup (G : Type u) extends Semigroup G where
protected mul_left_cancel : ∀ a b c : G, a * b = a * c → b = c
library_note "lower cancel priority" /--
We lower the priority of inheriting from cancellative structures.
This attempts to avoid expensive checks involving bundling and unbundling with the `IsDomain` class.
since `IsDomain` already depends on `Semiring`, we can synthesize that one first.
Zulip discussion: https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Why.20is.20.60simpNF.60.20complaining.20here.3F
-/
attribute [instance 75] LeftCancelSemigroup.toSemigroup -- See note [lower cancel priority]
/-- An `AddLeftCancelSemigroup` is an additive semigroup such that
`a + b = a + c` implies `b = c`. -/
@[ext]
class AddLeftCancelSemigroup (G : Type u) extends AddSemigroup G where
protected add_left_cancel : ∀ a b c : G, a + b = a + c → b = c
attribute [instance 75] AddLeftCancelSemigroup.toAddSemigroup -- See note [lower cancel priority]
attribute [to_additive] LeftCancelSemigroup
/-- Any `LeftCancelSemigroup` satisfies `IsLeftCancelMul`. -/
@[to_additive AddLeftCancelSemigroup.toIsLeftCancelAdd "Any `AddLeftCancelSemigroup` satisfies
`IsLeftCancelAdd`."]
instance (priority := 100) LeftCancelSemigroup.toIsLeftCancelMul (G : Type u)
[LeftCancelSemigroup G] : IsLeftCancelMul G :=
{ mul_left_cancel := LeftCancelSemigroup.mul_left_cancel }
/-- A `RightCancelSemigroup` is a semigroup such that `a * b = c * b` implies `a = c`. -/
@[ext]
class RightCancelSemigroup (G : Type u) extends Semigroup G where
protected mul_right_cancel : ∀ a b c : G, a * b = c * b → a = c
attribute [instance 75] RightCancelSemigroup.toSemigroup -- See note [lower cancel priority]
/-- An `AddRightCancelSemigroup` is an additive semigroup such that
`a + b = c + b` implies `a = c`. -/
@[ext]
class AddRightCancelSemigroup (G : Type u) extends AddSemigroup G where
protected add_right_cancel : ∀ a b c : G, a + b = c + b → a = c
attribute [instance 75] AddRightCancelSemigroup.toAddSemigroup -- See note [lower cancel priority]
attribute [to_additive] RightCancelSemigroup
/-- Any `RightCancelSemigroup` satisfies `IsRightCancelMul`. -/
@[to_additive AddRightCancelSemigroup.toIsRightCancelAdd "Any `AddRightCancelSemigroup` satisfies
`IsRightCancelAdd`."]
instance (priority := 100) RightCancelSemigroup.toIsRightCancelMul (G : Type u)
[RightCancelSemigroup G] : IsRightCancelMul G :=
{ mul_right_cancel := RightCancelSemigroup.mul_right_cancel }
/-- Typeclass for expressing that a type `M` with multiplication and a one satisfies
`1 * a = a` and `a * 1 = a` for all `a : M`. -/
class MulOneClass (M : Type u) extends One M, Mul M where
/-- One is a left neutral element for multiplication -/
protected one_mul : ∀ a : M, 1 * a = a
/-- One is a right neutral element for multiplication -/
protected mul_one : ∀ a : M, a * 1 = a
/-- Typeclass for expressing that a type `M` with addition and a zero satisfies
`0 + a = a` and `a + 0 = a` for all `a : M`. -/
class AddZeroClass (M : Type u) extends Zero M, Add M where
/-- Zero is a left neutral element for addition -/
protected zero_add : ∀ a : M, 0 + a = a
/-- Zero is a right neutral element for addition -/
protected add_zero : ∀ a : M, a + 0 = a
attribute [to_additive] MulOneClass
@[to_additive (attr := ext)]
theorem MulOneClass.ext {M : Type u} : ∀ ⦃m₁ m₂ : MulOneClass M⦄, m₁.mul = m₂.mul → m₁ = m₂ := by
rintro @⟨⟨one₁⟩, ⟨mul₁⟩, one_mul₁, mul_one₁⟩ @⟨⟨one₂⟩, ⟨mul₂⟩, one_mul₂, mul_one₂⟩ ⟨rfl⟩
-- FIXME (See https://github.com/leanprover/lean4/issues/1711)
-- congr
suffices one₁ = one₂ by cases this; rfl
exact (one_mul₂ one₁).symm.trans (mul_one₁ one₂)
section MulOneClass
variable {M : Type u} [MulOneClass M]
@[to_additive (attr := simp)]
theorem one_mul : ∀ a : M, 1 * a = a :=
MulOneClass.one_mul
@[to_additive (attr := simp)]
theorem mul_one : ∀ a : M, a * 1 = a :=
MulOneClass.mul_one
end MulOneClass
section
variable {M : Type u}
/-- The fundamental power operation in a monoid. `npowRec n a = a*a*...*a` n times.
Use instead `a ^ n`, which has better definitional behavior. -/
def npowRec [One M] [Mul M] : ℕ → M → M
| 0, _ => 1
| n + 1, a => npowRec n a * a
/-- The fundamental scalar multiplication in an additive monoid. `nsmulRec n a = a+a+...+a` n
times. Use instead `n • a`, which has better definitional behavior. -/
def nsmulRec [Zero M] [Add M] : ℕ → M → M
| 0, _ => 0
| n + 1, a => nsmulRec n a + a
attribute [to_additive existing] npowRec
variable [One M] [Semigroup M] (m n : ℕ) (hn : n ≠ 0) (a : M) (ha : 1 * a = a)
include hn ha
@[to_additive] theorem npowRec_add : npowRec (m + n) a = npowRec m a * npowRec n a := by
obtain _ | n := n; · exact (hn rfl).elim
induction n with
| zero => simp only [Nat.zero_add, npowRec, ha]
| succ n ih => rw [← Nat.add_assoc, npowRec, ih n.succ_ne_zero]; simp only [npowRec, mul_assoc]
@[to_additive] theorem npowRec_succ : npowRec (n + 1) a = a * npowRec n a := by
rw [Nat.add_comm, npowRec_add 1 n hn a ha, npowRec, npowRec, ha]
end
library_note "forgetful inheritance"/--
Suppose that one can put two mathematical structures on a type, a rich one `R` and a poor one
`P`, and that one can deduce the poor structure from the rich structure through a map `F` (called a
forgetful functor) (think `R = MetricSpace` and `P = TopologicalSpace`). A possible
implementation would be to have a type class `rich` containing a field `R`, a type class `poor`
containing a field `P`, and an instance from `rich` to `poor`. However, this creates diamond
problems, and a better approach is to let `rich` extend `poor` and have a field saying that
`F R = P`.
To illustrate this, consider the pair `MetricSpace` / `TopologicalSpace`. Consider the topology
on a product of two metric spaces. With the first approach, it could be obtained by going first from
each metric space to its topology, and then taking the product topology. But it could also be
obtained by considering the product metric space (with its sup distance) and then the topology
coming from this distance. These would be the same topology, but not definitionally, which means
that from the point of view of Lean's kernel, there would be two different `TopologicalSpace`
instances on the product. This is not compatible with the way instances are designed and used:
there should be at most one instance of a kind on each type. This approach has created an instance
diamond that does not commute definitionally.
The second approach solves this issue. Now, a metric space contains both a distance, a topology, and
a proof that the topology coincides with the one coming from the distance. When one defines the
product of two metric spaces, one uses the sup distance and the product topology, and one has to
give the proof that the sup distance induces the product topology. Following both sides of the
instance diamond then gives rise (definitionally) to the product topology on the product space.
Another approach would be to have the rich type class take the poor type class as an instance
parameter. It would solve the diamond problem, but it would lead to a blow up of the number
of type classes one would need to declare to work with complicated classes, say a real inner
product space, and would create exponential complexity when working with products of
such complicated spaces, that are avoided by bundling things carefully as above.
Note that this description of this specific case of the product of metric spaces is oversimplified
compared to mathlib, as there is an intermediate typeclass between `MetricSpace` and
`TopologicalSpace` called `UniformSpace`. The above scheme is used at both levels, embedding a
topology in the uniform space structure, and a uniform structure in the metric space structure.
Note also that, when `P` is a proposition, there is no such issue as any two proofs of `P` are
definitionally equivalent in Lean.
To avoid boilerplate, there are some designs that can automatically fill the poor fields when
creating a rich structure if one doesn't want to do something special about them. For instance,
in the definition of metric spaces, default tactics fill the uniform space fields if they are
not given explicitly. One can also have a helper function creating the rich structure from a
structure with fewer fields, where the helper function fills the remaining fields. See for instance
`UniformSpace.ofCore` or `RealInnerProduct.ofCore`.
For more details on this question, called the forgetful inheritance pattern, see [Competing
inheritance paths in dependent type theory: a case study in functional
analysis](https://hal.inria.fr/hal-02463336).
-/
/-!
### Design note on `AddMonoid` and `Monoid`
An `AddMonoid` has a natural `ℕ`-action, defined by `n • a = a + ... + a`, that we want to declare
as an instance as it makes it possible to use the language of linear algebra. However, there are
often other natural `ℕ`-actions. For instance, for any semiring `R`, the space of polynomials
`Polynomial R` has a natural `R`-action defined by multiplication on the coefficients. This means
that `Polynomial ℕ` would have two natural `ℕ`-actions, which are equal but not defeq. The same
goes for linear maps, tensor products, and so on (and even for `ℕ` itself).
To solve this issue, we embed an `ℕ`-action in the definition of an `AddMonoid` (which is by
default equal to the naive action `a + ... + a`, but can be adjusted when needed), and declare
a `SMul ℕ α` instance using this action. See Note [forgetful inheritance] for more
explanations on this pattern.
For example, when we define `Polynomial R`, then we declare the `ℕ`-action to be by multiplication
on each coefficient (using the `ℕ`-action on `R` that comes from the fact that `R` is
an `AddMonoid`). In this way, the two natural `SMul ℕ (Polynomial ℕ)` instances are defeq.
The tactic `to_additive` transfers definitions and results from multiplicative monoids to additive
monoids. To work, it has to map fields to fields. This means that we should also add corresponding
fields to the multiplicative structure `Monoid`, which could solve defeq problems for powers if
needed. These problems do not come up in practice, so most of the time we will not need to adjust
the `npow` field when defining multiplicative objects.
-/
/-- Exponentiation by repeated squaring. -/
@[to_additive "Scalar multiplication by repeated self-addition,
the additive version of exponentiation by repeated squaring."]
def npowBinRec {M : Type*} [One M] [Mul M] (k : ℕ) : M → M :=
npowBinRec.go k 1
where
/-- Auxiliary tail-recursive implementation for `npowBinRec`. -/
@[to_additive nsmulBinRec.go "Auxiliary tail-recursive implementation for `nsmulBinRec`."]
go (k : ℕ) : M → M → M :=
k.binaryRec (fun y _ ↦ y) fun bn _n fn y x ↦ fn (cond bn (y * x) y) (x * x)
/--
A variant of `npowRec` which is a semigroup homomorphisms from `ℕ₊` to `M`.
-/
def npowRec' {M : Type*} [One M] [Mul M] : ℕ → M → M
| 0, _ => 1
| 1, m => m
| k + 2, m => npowRec' (k + 1) m * m
/--
A variant of `nsmulRec` which is a semigroup homomorphisms from `ℕ₊` to `M`.
-/
def nsmulRec' {M : Type*} [Zero M] [Add M] : ℕ → M → M
| 0, _ => 0
| 1, m => m
| k + 2, m => nsmulRec' (k + 1) m + m
attribute [to_additive existing] npowRec'
@[to_additive]
theorem npowRec'_succ {M : Type*} [Mul M] [One M] {k : ℕ} (_ : k ≠ 0) (m : M) :
npowRec' (k + 1) m = npowRec' k m * m :=
match k with
| _ + 1 => rfl
@[to_additive]
theorem npowRec'_two_mul {M : Type*} [Semigroup M] [One M] (k : ℕ) (m : M) :
npowRec' (2 * k) m = npowRec' k (m * m) := by
induction k using Nat.strongRecOn with
| ind k' ih =>
match k' with
| 0 => rfl
| 1 => simp [npowRec']
| k + 2 => simp [npowRec', ← mul_assoc, Nat.mul_add, ← ih]
@[to_additive]
theorem npowRec'_mul_comm {M : Type*} [Semigroup M] [One M] {k : ℕ} (k0 : k ≠ 0) (m : M) :
m * npowRec' k m = npowRec' k m * m := by
induction k using Nat.strongRecOn with
| ind k' ih =>
match k' with
| 1 => simp [npowRec', mul_assoc]
| k + 2 => simp [npowRec', ← mul_assoc, ih]
@[to_additive]
theorem npowRec_eq {M : Type*} [Semigroup M] [One M] (k : ℕ) (m : M) :
npowRec (k + 1) m = 1 * npowRec' (k + 1) m := by
induction k using Nat.strongRecOn with
| ind k' ih =>
match k' with
| 0 => rfl
| k + 1 =>
rw [npowRec, npowRec'_succ k.succ_ne_zero, ← mul_assoc]
congr
simp [ih]
@[to_additive]
theorem npowBinRec.go_spec {M : Type*} [Semigroup M] [One M] (k : ℕ) (m n : M) :
npowBinRec.go (k + 1) m n = m * npowRec' (k + 1) n := by
unfold go
generalize hk : k + 1 = k'
replace hk : k' ≠ 0 := by omega
induction k' using Nat.binaryRecFromOne generalizing n m with
| z₀ => simp at hk
| z₁ => simp [npowRec']
| f b k' k'0 ih =>
rw [Nat.binaryRec_eq _ _ (Or.inl rfl), ih _ _ k'0]
cases b <;> simp only [Nat.bit, cond_false, cond_true, ← Nat.two_mul, npowRec'_two_mul]
rw [npowRec'_succ (by omega), npowRec'_two_mul, ← npowRec'_two_mul,
← npowRec'_mul_comm (by omega), mul_assoc]
/--
An abbreviation for `npowRec` with an additional typeclass assumption on associativity
so that we can use `@[csimp]` to replace it with an implementation by repeated squaring
in compiled code.
-/
@[to_additive
"An abbreviation for `nsmulRec` with an additional typeclass assumptions on associativity
so that we can use `@[csimp]` to replace it with an implementation by repeated doubling in compiled
code as an automatic parameter."]
abbrev npowRecAuto {M : Type*} [Semigroup M] [One M] (k : ℕ) (m : M) : M :=
npowRec k m
/--
An abbreviation for `npowBinRec` with an additional typeclass assumption on associativity
so that we can use it in `@[csimp]` for more performant code generation.
-/
@[to_additive
"An abbreviation for `nsmulBinRec` with an additional typeclass assumption on associativity
so that we can use it in `@[csimp]` for more performant code generation
as an automatic parameter."]
abbrev npowBinRecAuto {M : Type*} [Semigroup M] [One M] (k : ℕ) (m : M) : M :=
npowBinRec k m
@[to_additive (attr := csimp)]
theorem npowRec_eq_npowBinRec : @npowRecAuto = @npowBinRecAuto := by
funext M _ _ k m
rw [npowBinRecAuto, npowRecAuto, npowBinRec]
match k with
| 0 => rw [npowRec, npowBinRec.go, Nat.binaryRec_zero]
| k + 1 => rw [npowBinRec.go_spec, npowRec_eq]
/-- An `AddMonoid` is an `AddSemigroup` with an element `0` such that `0 + a = a + 0 = a`. -/
class AddMonoid (M : Type u) extends AddSemigroup M, AddZeroClass M where
/-- Multiplication by a natural number.
Set this to `nsmulRec` unless `Module` diamonds are possible. -/
protected nsmul : ℕ → M → M
/-- Multiplication by `(0 : ℕ)` gives `0`. -/
protected nsmul_zero : ∀ x, nsmul 0 x = 0 := by intros; rfl
/-- Multiplication by `(n + 1 : ℕ)` behaves as expected. -/
protected nsmul_succ : ∀ (n : ℕ) (x), nsmul (n + 1) x = nsmul n x + x := by intros; rfl
attribute [instance 150] AddSemigroup.toAdd
attribute [instance 50] AddZeroClass.toAdd
/-- A `Monoid` is a `Semigroup` with an element `1` such that `1 * a = a * 1 = a`. -/
@[to_additive]
class Monoid (M : Type u) extends Semigroup M, MulOneClass M where
/-- Raising to the power of a natural number. -/
protected npow : ℕ → M → M := npowRecAuto
/-- Raising to the power `(0 : ℕ)` gives `1`. -/
protected npow_zero : ∀ x, npow 0 x = 1 := by intros; rfl
/-- Raising to the power `(n + 1 : ℕ)` behaves as expected. -/
protected npow_succ : ∀ (n : ℕ) (x), npow (n + 1) x = npow n x * x := by intros; rfl
@[default_instance high] instance Monoid.toNatPow {M : Type*} [Monoid M] : Pow M ℕ :=
⟨fun x n ↦ Monoid.npow n x⟩
instance AddMonoid.toNatSMul {M : Type*} [AddMonoid M] : SMul ℕ M :=
⟨AddMonoid.nsmul⟩
attribute [to_additive existing toNatSMul] Monoid.toNatPow
section Monoid
variable {M : Type*} [Monoid M] {a b c : M}
@[to_additive (attr := simp) nsmul_eq_smul]
theorem npow_eq_pow (n : ℕ) (x : M) : Monoid.npow n x = x ^ n :=
rfl
@[to_additive] lemma left_inv_eq_right_inv (hba : b * a = 1) (hac : a * c = 1) : b = c := by
rw [← one_mul c, ← hba, mul_assoc, hac, mul_one b]
-- the attributes are intentionally out of order. `zero_smul` proves `zero_nsmul`.
@[to_additive zero_nsmul, simp]
theorem pow_zero (a : M) : a ^ 0 = 1 :=
Monoid.npow_zero _
@[to_additive succ_nsmul]
theorem pow_succ (a : M) (n : ℕ) : a ^ (n + 1) = a ^ n * a :=
Monoid.npow_succ n a
@[to_additive (attr := simp) one_nsmul]
lemma pow_one (a : M) : a ^ 1 = a := by rw [pow_succ, pow_zero, one_mul]
@[to_additive succ_nsmul'] lemma pow_succ' (a : M) : ∀ n, a ^ (n + 1) = a * a ^ n
| 0 => by simp
| n + 1 => by rw [pow_succ _ n, pow_succ, pow_succ', mul_assoc]
@[to_additive] lemma mul_pow_mul (a b : M) (n : ℕ) :
(a * b) ^ n * a = a * (b * a) ^ n := by
induction n with
| zero => simp
| succ n ih => simp [pow_succ', ← ih, Nat.mul_add, mul_assoc]
@[to_additive]
lemma pow_mul_comm' (a : M) (n : ℕ) : a ^ n * a = a * a ^ n := by rw [← pow_succ, pow_succ']
/-- Note that most of the lemmas about powers of two refer to it as `sq`. -/
@[to_additive two_nsmul] lemma pow_two (a : M) : a ^ 2 = a * a := by rw [pow_succ, pow_one]
-- TODO: Should `alias` automatically transfer `to_additive` statements?
@[to_additive existing two_nsmul] alias sq := pow_two
@[to_additive three'_nsmul]
lemma pow_three' (a : M) : a ^ 3 = a * a * a := by rw [pow_succ, pow_two]
@[to_additive three_nsmul]
lemma pow_three (a : M) : a ^ 3 = a * (a * a) := by rw [pow_succ', pow_two]
-- the attributes are intentionally out of order.
@[to_additive nsmul_zero, simp] lemma one_pow : ∀ n, (1 : M) ^ n = 1
| 0 => pow_zero _
| n + 1 => by rw [pow_succ, one_pow, one_mul]
@[to_additive add_nsmul]
lemma pow_add (a : M) (m : ℕ) : ∀ n, a ^ (m + n) = a ^ m * a ^ n
| 0 => by rw [Nat.add_zero, pow_zero, mul_one]
| n + 1 => by rw [pow_succ, ← mul_assoc, ← pow_add, ← pow_succ, Nat.add_assoc]
@[to_additive] lemma pow_mul_comm (a : M) (m n : ℕ) : a ^ m * a ^ n = a ^ n * a ^ m := by
rw [← pow_add, ← pow_add, Nat.add_comm]
@[to_additive mul_nsmul] lemma pow_mul (a : M) (m : ℕ) : ∀ n, a ^ (m * n) = (a ^ m) ^ n
| 0 => by rw [Nat.mul_zero, pow_zero, pow_zero]
| n + 1 => by rw [Nat.mul_succ, pow_add, pow_succ, pow_mul]
@[to_additive mul_nsmul']
lemma pow_mul' (a : M) (m n : ℕ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Nat.mul_comm, pow_mul]
@[to_additive nsmul_left_comm]
lemma pow_right_comm (a : M) (m n : ℕ) : (a ^ m) ^ n = (a ^ n) ^ m := by
rw [← pow_mul, Nat.mul_comm, pow_mul]
end Monoid
/-- An additive commutative monoid is an additive monoid with commutative `(+)`. -/
class AddCommMonoid (M : Type u) extends AddMonoid M, AddCommSemigroup M
/-- A commutative monoid is a monoid with commutative `(*)`. -/
@[to_additive]
class CommMonoid (M : Type u) extends Monoid M, CommSemigroup M
section LeftCancelMonoid
/-- An additive monoid in which addition is left-cancellative.
Main examples are `ℕ` and groups. This is the right typeclass for many sum lemmas, as having a zero
is useful to define the sum over the empty set, so `AddLeftCancelSemigroup` is not enough. -/
class AddLeftCancelMonoid (M : Type u) extends AddMonoid M, AddLeftCancelSemigroup M
attribute [instance 75] AddLeftCancelMonoid.toAddMonoid -- See note [lower cancel priority]
/-- A monoid in which multiplication is left-cancellative. -/
@[to_additive]
class LeftCancelMonoid (M : Type u) extends Monoid M, LeftCancelSemigroup M
attribute [instance 75] LeftCancelMonoid.toMonoid -- See note [lower cancel priority]
|
end LeftCancelMonoid
| Mathlib/Algebra/Group/Defs.lean | 673 | 674 |
/-
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)⟩
theorem mul_zero (a : R) : a * 0 = 0 := by simp
theorem mul_add {d : R} (_ : (a : R) * b₁ = c₁) (_ : a * b₂ = c₂) (_ : c₁ + 0 + c₂ = d) :
a * (b₁ + b₂) = d := by
subst_vars; simp [_root_.mul_add]
/-- Multiplies a monomial `va` to a polynomial `vb` to get a normalized result polynomial.
* `a * 0 = 0`
* `a * (b₁ + b₂) = (a * b₁) + (a * b₂)`
-/
def evalMul₁ {a b : Q($α)} (va : ExProd sα a) (vb : ExSum sα b) :
Lean.Core.CoreM <| Result (ExSum sα) q($a * $b) := do
match vb with
| .zero => return ⟨_, .zero, q(mul_zero $a)⟩
| .add vb₁ vb₂ =>
let ⟨_, vc₁, pc₁⟩ ← evalMulProd sα va vb₁
let ⟨_, vc₂, pc₂⟩ ← evalMul₁ va vb₂
let ⟨_, vd, pd⟩ ← evalAdd sα vc₁.toSum vc₂
return ⟨_, vd, q(mul_add $pc₁ $pc₂ $pd)⟩
theorem zero_mul (b : R) : 0 * b = 0 := by simp
theorem add_mul {d : R} (_ : (a₁ : R) * b = c₁) (_ : a₂ * b = c₂) (_ : c₁ + c₂ = d) :
(a₁ + a₂) * b = d := by subst_vars; simp [_root_.add_mul]
/-- Multiplies two polynomials `va, vb` together to get a normalized result polynomial.
* `0 * b = 0`
* `(a₁ + a₂) * b = (a₁ * b) + (a₂ * b)`
-/
def evalMul {a b : Q($α)} (va : ExSum sα a) (vb : ExSum sα b) :
Lean.Core.CoreM <| Result (ExSum sα) q($a * $b) := do
match va with
| .zero => return ⟨_, .zero, q(zero_mul $b)⟩
| .add va₁ va₂ =>
let ⟨_, vc₁, pc₁⟩ ← evalMul₁ sα va₁ vb
let ⟨_, vc₂, pc₂⟩ ← evalMul va₂ vb
let ⟨_, vd, pd⟩ ← evalAdd sα vc₁ vc₂
return ⟨_, vd, q(add_mul $pc₁ $pc₂ $pd)⟩
theorem natCast_nat (n) : ((Nat.rawCast n : ℕ) : R) = Nat.rawCast n := by simp
theorem natCast_mul {a₁ a₃ : ℕ} (a₂) (_ : ((a₁ : ℕ) : R) = b₁)
(_ : ((a₃ : ℕ) : R) = b₃) : ((a₁ ^ a₂ * a₃ : ℕ) : R) = b₁ ^ a₂ * b₃ := by
subst_vars; simp
theorem natCast_zero : ((0 : ℕ) : R) = 0 := Nat.cast_zero
theorem natCast_add {a₁ a₂ : ℕ}
(_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) : ((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by
subst_vars; simp
mutual
/-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`.
* An atom `e` causes `↑e` to be allocated as a new atom.
* A sum delegates to `ExSum.evalNatCast`.
-/
partial def ExBase.evalNatCast {a : Q(ℕ)} (va : ExBase sℕ a) : AtomM (Result (ExBase sα) q($a)) :=
match va with
| .atom _ => do
let (i, ⟨b', _⟩) ← addAtomQ q($a)
pure ⟨b', ExBase.atom i, q(Eq.refl $b')⟩
| .sum va => do
let ⟨_, vc, p⟩ ← va.evalNatCast
pure ⟨_, .sum vc, p⟩
/-- Applies `Nat.cast` to a nat monomial to produce a monomial in `α`.
* `↑c = c` if `c` is a numeric literal
* `↑(a ^ n * b) = ↑a ^ n * ↑b`
-/
partial def ExProd.evalNatCast {a : Q(ℕ)} (va : ExProd sℕ a) : AtomM (Result (ExProd sα) q($a)) :=
match va with
| .const c hc =>
have n : Q(ℕ) := a.appArg!
pure ⟨q(Nat.rawCast $n), .const c hc, (q(natCast_nat (R := $α) $n) : Expr)⟩
| .mul (e := a₂) va₁ va₂ va₃ => do
let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast
let ⟨_, vb₃, pb₃⟩ ← va₃.evalNatCast
pure ⟨_, .mul vb₁ va₂ vb₃, q(natCast_mul $a₂ $pb₁ $pb₃)⟩
/-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`.
* `↑0 = 0`
* `↑(a + b) = ↑a + ↑b`
-/
partial def ExSum.evalNatCast {a : Q(ℕ)} (va : ExSum sℕ a) : AtomM (Result (ExSum sα) q($a)) :=
match va with
| .zero => pure ⟨_, .zero, q(natCast_zero (R := $α))⟩
| .add va₁ va₂ => do
let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast
let ⟨_, vb₂, pb₂⟩ ← va₂.evalNatCast
pure ⟨_, .add vb₁ vb₂, q(natCast_add $pb₁ $pb₂)⟩
end
theorem smul_nat {a b c : ℕ} (_ : (a * b : ℕ) = c) : a • b = c := by subst_vars; simp
theorem smul_eq_cast {a : ℕ} (_ : ((a : ℕ) : R) = a') (_ : a' * b = c) : a • b = c := by
subst_vars; simp
/-- Constructs the scalar multiplication `n • a`, where both `n : ℕ` and `a : α` are normalized
polynomial expressions.
* `a • b = a * b` if `α = ℕ`
* `a • b = ↑a * b` otherwise
-/
def evalNSMul {a : Q(ℕ)} {b : Q($α)} (va : ExSum sℕ a) (vb : ExSum sα b) :
AtomM (Result (ExSum sα) q($a • $b)) := do
if ← isDefEq sα sℕ then
let ⟨_, va'⟩ := va.cast
have _b : Q(ℕ) := b
let ⟨(_c : Q(ℕ)), vc, (pc : Q($a * $_b = $_c))⟩ ← evalMul sα va' vb
pure ⟨_, vc, (q(smul_nat $pc) : Expr)⟩
else
let ⟨_, va', pa'⟩ ← va.evalNatCast sα
let ⟨_, vc, pc⟩ ← evalMul sα va' vb
pure ⟨_, vc, (q(smul_eq_cast $pa' $pc) : Expr)⟩
|
theorem neg_one_mul {R} [Ring R] {a b : R} (_ : (Int.negOfNat (nat_lit 1)).rawCast * a = b) :
| Mathlib/Tactic/Ring/Basic.lean | 574 | 575 |
/-
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.Option.NAry
import Mathlib.Data.Seq.Computation
import Mathlib.Tactic.ApplyFun
import Mathlib.Data.List.Basic
/-!
# Possibly infinite lists
This file provides a `Seq α` type representing possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`.
-/
namespace Stream'
universe u v w
/-
coinductive seq (α : Type u) : Type u
| nil : seq α
| cons : α → seq α → seq α
-/
/-- A stream `s : Option α` is a sequence if `s.get n = none` implies `s.get (n + 1) = none`.
-/
def IsSeq {α : Type u} (s : Stream' (Option α)) : Prop :=
∀ {n : ℕ}, s n = none → s (n + 1) = none
/-- `Seq α` is the type of possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`. -/
def Seq (α : Type u) : Type u :=
{ f : Stream' (Option α) // f.IsSeq }
/-- `Seq1 α` is the type of nonempty sequences. -/
def Seq1 (α) :=
α × Seq α
namespace Seq
variable {α : Type u} {β : Type v} {γ : Type w}
/-- The empty sequence -/
def nil : Seq α :=
⟨Stream'.const none, fun {_} _ => rfl⟩
instance : Inhabited (Seq α) :=
⟨nil⟩
/-- Prepend an element to a sequence -/
def cons (a : α) (s : Seq α) : Seq α :=
⟨some a::s.1, by
rintro (n | _) h
· contradiction
· exact s.2 h⟩
@[simp]
theorem val_cons (s : Seq α) (x : α) : (cons x s).val = some x::s.val :=
rfl
/-- Get the nth element of a sequence (if it exists) -/
def get? : Seq α → ℕ → Option α :=
Subtype.val
@[simp]
theorem val_eq_get (s : Seq α) (n : ℕ) : s.val n = s.get? n := by
rfl
@[simp]
theorem get?_mk (f hf) : @get? α ⟨f, hf⟩ = f :=
rfl
@[simp]
theorem get?_nil (n : ℕ) : (@nil α).get? n = none :=
rfl
@[simp]
theorem get?_cons_zero (a : α) (s : Seq α) : (cons a s).get? 0 = some a :=
rfl
@[simp]
theorem get?_cons_succ (a : α) (s : Seq α) (n : ℕ) : (cons a s).get? (n + 1) = s.get? n :=
rfl
@[ext]
protected theorem ext {s t : Seq α} (h : ∀ n : ℕ, s.get? n = t.get? n) : s = t :=
Subtype.eq <| funext h
theorem cons_injective2 : Function.Injective2 (cons : α → Seq α → Seq α) := fun x y s t h =>
⟨by rw [← Option.some_inj, ← get?_cons_zero, h, get?_cons_zero],
Seq.ext fun n => by simp_rw [← get?_cons_succ x s n, h, get?_cons_succ]⟩
theorem cons_left_injective (s : Seq α) : Function.Injective fun x => cons x s :=
cons_injective2.left _
theorem cons_right_injective (x : α) : Function.Injective (cons x) :=
cons_injective2.right _
/-- A sequence has terminated at position `n` if the value at position `n` equals `none`. -/
def TerminatedAt (s : Seq α) (n : ℕ) : Prop :=
s.get? n = none
/-- It is decidable whether a sequence terminates at a given position. -/
instance terminatedAtDecidable (s : Seq α) (n : ℕ) : Decidable (s.TerminatedAt n) :=
decidable_of_iff' (s.get? n).isNone <| by unfold TerminatedAt; cases s.get? n <;> simp
/-- A sequence terminates if there is some position `n` at which it has terminated. -/
def Terminates (s : Seq α) : Prop :=
∃ n : ℕ, s.TerminatedAt n
theorem not_terminates_iff {s : Seq α} : ¬s.Terminates ↔ ∀ n, (s.get? n).isSome := by
simp only [Terminates, TerminatedAt, ← Ne.eq_def, Option.ne_none_iff_isSome, not_exists, iff_self]
/-- Functorial action of the functor `Option (α × _)` -/
@[simp]
def omap (f : β → γ) : Option (α × β) → Option (α × γ)
| none => none
| some (a, b) => some (a, f b)
/-- Get the first element of a sequence -/
def head (s : Seq α) : Option α :=
get? s 0
/-- Get the tail of a sequence (or `nil` if the sequence is `nil`) -/
def tail (s : Seq α) : Seq α :=
⟨s.1.tail, fun n' => by
obtain ⟨f, al⟩ := s
exact al n'⟩
/-- member definition for `Seq` -/
protected def Mem (s : Seq α) (a : α) :=
some a ∈ s.1
instance : Membership α (Seq α) :=
⟨Seq.Mem⟩
theorem le_stable (s : Seq α) {m n} (h : m ≤ n) : s.get? m = none → s.get? n = none := by
obtain ⟨f, al⟩ := s
induction' h with n _ IH
exacts [id, fun h2 => al (IH h2)]
/-- If a sequence terminated at position `n`, it also terminated at `m ≥ n`. -/
theorem terminated_stable : ∀ (s : Seq α) {m n : ℕ}, m ≤ n → s.TerminatedAt m → s.TerminatedAt n :=
le_stable
/-- If `s.get? n = some aₙ` for some value `aₙ`, then there is also some value `aₘ` such
that `s.get? = some aₘ` for `m ≤ n`.
-/
theorem ge_stable (s : Seq α) {aₙ : α} {n m : ℕ} (m_le_n : m ≤ n)
(s_nth_eq_some : s.get? n = some aₙ) : ∃ aₘ : α, s.get? m = some aₘ :=
have : s.get? n ≠ none := by simp [s_nth_eq_some]
have : s.get? m ≠ none := mt (s.le_stable m_le_n) this
Option.ne_none_iff_exists'.mp this
theorem not_mem_nil (a : α) : a ∉ @nil α := fun ⟨_, (h : some a = none)⟩ => by injection h
theorem mem_cons (a : α) : ∀ s : Seq α, a ∈ cons a s
| ⟨_, _⟩ => Stream'.mem_cons (some a) _
theorem mem_cons_of_mem (y : α) {a : α} : ∀ {s : Seq α}, a ∈ s → a ∈ cons y s
| ⟨_, _⟩ => Stream'.mem_cons_of_mem (some y)
theorem eq_or_mem_of_mem_cons {a b : α} : ∀ {s : Seq α}, a ∈ cons b s → a = b ∨ a ∈ s
| ⟨_, _⟩, h => (Stream'.eq_or_mem_of_mem_cons h).imp_left fun h => by injection h
@[simp]
theorem mem_cons_iff {a b : α} {s : Seq α} : a ∈ cons b s ↔ a = b ∨ a ∈ s :=
⟨eq_or_mem_of_mem_cons, by rintro (rfl | m) <;> [apply mem_cons; exact mem_cons_of_mem _ m]⟩
@[simp]
theorem get?_mem {s : Seq α} {n : ℕ} {x : α} (h : s.get? n = .some x) : x ∈ s := ⟨n, h.symm⟩
/-- Destructor for a sequence, resulting in either `none` (for `nil`) or
`some (a, s)` (for `cons a s`). -/
def destruct (s : Seq α) : Option (Seq1 α) :=
(fun a' => (a', s.tail)) <$> get? s 0
theorem destruct_eq_none {s : Seq α} : destruct s = none → s = nil := by
dsimp [destruct]
induction' f0 : get? s 0 <;> intro h
· apply Subtype.eq
funext n
induction' n with n IH
exacts [f0, s.2 IH]
· contradiction
theorem destruct_eq_cons {s : Seq α} {a s'} : destruct s = some (a, s') → s = cons a s' := by
dsimp [destruct]
induction' f0 : get? s 0 with a' <;> intro h
· contradiction
· obtain ⟨f, al⟩ := s
injections _ h1 h2
rw [← h2]
apply Subtype.eq
dsimp [tail, cons]
rw [h1] at f0
rw [← f0]
exact (Stream'.eta f).symm
@[simp]
theorem destruct_nil : destruct (nil : Seq α) = none :=
rfl
@[simp]
theorem destruct_cons (a : α) : ∀ s, destruct (cons a s) = some (a, s)
| ⟨f, al⟩ => by
unfold cons destruct Functor.map
apply congr_arg fun s => some (a, s)
apply Subtype.eq; dsimp [tail]
-- Porting note: needed universe annotation to avoid universe issues
theorem head_eq_destruct (s : Seq α) : head.{u} s = Prod.fst.{u} <$> destruct.{u} s := by
unfold destruct head; cases get? s 0 <;> rfl
@[simp]
theorem head_nil : head (nil : Seq α) = none :=
rfl
@[simp]
theorem head_cons (a : α) (s) : head (cons a s) = some a := by
rw [head_eq_destruct, destruct_cons, Option.map_eq_map, Option.map_some']
@[simp]
theorem tail_nil : tail (nil : Seq α) = nil :=
rfl
@[simp]
theorem tail_cons (a : α) (s) : tail (cons a s) = s := by
obtain ⟨f, al⟩ := s
apply Subtype.eq
dsimp [tail, cons]
@[simp]
theorem get?_tail (s : Seq α) (n) : get? (tail s) n = get? s (n + 1) :=
rfl
/-- Recursion principle for sequences, compare with `List.recOn`. -/
@[cases_eliminator]
def recOn {motive : Seq α → Sort v} (s : Seq α) (nil : motive nil)
(cons : ∀ x s, motive (cons x s)) :
motive s := by
rcases H : destruct s with - | v
· rw [destruct_eq_none H]
apply nil
· obtain ⟨a, s'⟩ := v
rw [destruct_eq_cons H]
apply cons
@[simp]
theorem cons_ne_nil {x : α} {s : Seq α} : (cons x s) ≠ .nil := by
intro h
apply_fun head at h
simp at h
@[simp]
theorem nil_ne_cons {x : α} {s : Seq α} : .nil ≠ (cons x s) := cons_ne_nil.symm
theorem cons_eq_cons {x x' : α} {s s' : Seq α} :
(cons x s = cons x' s') ↔ (x = x' ∧ s = s') := by
constructor
· intro h
constructor
· apply_fun head at h
simpa using h
· apply_fun tail at h
simpa using h
· intro ⟨_, _⟩
congr
theorem head_eq_some {s : Seq α} {x : α} (h : s.head = some x) :
s = cons x s.tail := by
cases s <;> simp at h
simpa [cons_eq_cons]
theorem head_eq_none {s : Seq α} (h : s.head = none) : s = nil := by
cases s
· rfl
· simp at h
@[simp]
theorem head_eq_none_iff {s : Seq α} : s.head = none ↔ s = nil := by
constructor
· apply head_eq_none
· intro h
simp [h]
theorem mem_rec_on {C : Seq α → Prop} {a s} (M : a ∈ s)
(h1 : ∀ b s', a = b ∨ C s' → C (cons b s')) : C s := by
obtain ⟨k, e⟩ := M; unfold Stream'.get at e
induction' k with k IH generalizing s
· have TH : s = cons a (tail s) := by
apply destruct_eq_cons
unfold destruct get? Functor.map
rw [← e]
rfl
rw [TH]
apply h1 _ _ (Or.inl rfl)
cases s with
| nil => injection e
| cons b s' =>
have h_eq : (cons b s').val (Nat.succ k) = s'.val k := by cases s' using Subtype.recOn; rfl
rw [h_eq] at e
apply h1 _ _ (Or.inr (IH e))
/-- Corecursor over pairs of `Option` values -/
def Corec.f (f : β → Option (α × β)) : Option β → Option α × Option β
| none => (none, none)
| some b =>
match f b with
| none => (none, none)
| some (a, b') => (some a, some b')
/-- Corecursor for `Seq α` as a coinductive type. Iterates `f` to produce new elements
of the sequence until `none` is obtained. -/
def corec (f : β → Option (α × β)) (b : β) : Seq α := by
refine ⟨Stream'.corec' (Corec.f f) (some b), fun {n} h => ?_⟩
rw [Stream'.corec'_eq]
change Stream'.corec' (Corec.f f) (Corec.f f (some b)).2 n = none
revert h; generalize some b = o; revert o
induction' n with n IH <;> intro o
· change (Corec.f f o).1 = none → (Corec.f f (Corec.f f o).2).1 = none
rcases o with - | b <;> intro h
· rfl
dsimp [Corec.f] at h
dsimp [Corec.f]
revert h; rcases h₁ : f b with - | s <;> intro h
· rfl
· obtain ⟨a, b'⟩ := s
contradiction
· rw [Stream'.corec'_eq (Corec.f f) (Corec.f f o).2, Stream'.corec'_eq (Corec.f f) o]
exact IH (Corec.f f o).2
@[simp]
theorem corec_eq (f : β → Option (α × β)) (b : β) :
destruct (corec f b) = omap (corec f) (f b) := by
dsimp [corec, destruct, get]
rw [show Stream'.corec' (Corec.f f) (some b) 0 = (Corec.f f (some b)).1 from rfl]
dsimp [Corec.f]
induction' h : f b with s; · rfl
obtain ⟨a, b'⟩ := s; dsimp [Corec.f]
apply congr_arg fun b' => some (a, b')
apply Subtype.eq
dsimp [corec, tail]
rw [Stream'.corec'_eq, Stream'.tail_cons]
dsimp [Corec.f]; rw [h]
theorem corec_nil (f : β → Option (α × β)) (b : β)
(h : f b = .none) : corec f b = nil := by
apply destruct_eq_none
simp [h]
theorem corec_cons {f : β → Option (α × β)} {b : β} {x : α} {s : β}
(h : f b = .some (x, s)) : corec f b = cons x (corec f s) := by
apply destruct_eq_cons
simp [h]
section Bisim
variable (R : Seq α → Seq α → Prop)
local infixl:50 " ~ " => R
/-- Bisimilarity relation over `Option` of `Seq1 α` -/
def BisimO : Option (Seq1 α) → Option (Seq1 α) → Prop
| none, none => True
| some (a, s), some (a', s') => a = a' ∧ R s s'
| _, _ => False
attribute [simp] BisimO
attribute [nolint simpNF] BisimO.eq_3
/-- a relation is bisimilar if it meets the `BisimO` test -/
def IsBisimulation :=
∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → BisimO R (destruct s₁) (destruct s₂)
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ := by
apply Subtype.eq
apply Stream'.eq_of_bisim fun x y => ∃ s s' : Seq α, s.1 = x ∧ s'.1 = y ∧ R s s'
· dsimp [Stream'.IsBisimulation]
intro t₁ t₂ e
exact
match t₁, t₂, e with
| _, _, ⟨s, s', rfl, rfl, r⟩ => by
suffices head s = head s' ∧ R (tail s) (tail s') from
And.imp id (fun r => ⟨tail s, tail s', by cases s using Subtype.recOn; rfl,
by cases s' using Subtype.recOn; rfl, r⟩) this
have := bisim r; revert r this
cases s <;> cases s'
· intro r _
constructor
· rfl
· assumption
· intro _ this
rw [destruct_nil, destruct_cons] at this
exact False.elim this
· intro _ this
rw [destruct_nil, destruct_cons] at this
exact False.elim this
· intro _ this
rw [destruct_cons, destruct_cons] at this
rw [head_cons, head_cons, tail_cons, tail_cons]
obtain ⟨h1, h2⟩ := this
constructor
· rw [h1]
· exact h2
· exact ⟨s₁, s₂, rfl, rfl, r⟩
end Bisim
theorem coinduction :
∀ {s₁ s₂ : Seq α},
head s₁ = head s₂ →
(∀ (β : Type u) (fr : Seq α → β), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂
| _, _, hh, ht =>
Subtype.eq (Stream'.coinduction hh fun β fr => ht β fun s => fr s.1)
theorem coinduction2 (s) (f g : Seq α → Seq β)
(H :
∀ s,
BisimO (fun s1 s2 : Seq β => ∃ s : Seq α, s1 = f s ∧ s2 = g s) (destruct (f s))
(destruct (g s))) :
f s = g s := by
refine eq_of_bisim (fun s1 s2 => ∃ s, s1 = f s ∧ s2 = g s) ?_ ⟨s, rfl, rfl⟩
intro s1 s2 h; rcases h with ⟨s, h1, h2⟩
rw [h1, h2]; apply H
/-- Embed a list as a sequence -/
@[coe]
def ofList (l : List α) : Seq α :=
⟨(l[·]?), fun {n} h => by
rw [List.getElem?_eq_none_iff] at h ⊢
exact h.trans (Nat.le_succ n)⟩
instance coeList : Coe (List α) (Seq α) :=
⟨ofList⟩
@[simp]
theorem ofList_nil : ofList [] = (nil : Seq α) :=
rfl
@[simp]
theorem ofList_get? (l : List α) (n : ℕ) : (ofList l).get? n = l[n]? :=
rfl
@[deprecated (since := "2025-02-21")]
alias ofList_get := ofList_get?
@[simp]
theorem ofList_cons (a : α) (l : List α) : ofList (a::l) = cons a (ofList l) := by
ext1 (_ | n) <;> simp
theorem ofList_injective : Function.Injective (ofList : List α → _) :=
fun _ _ h => List.ext_getElem? fun _ => congr_fun (Subtype.ext_iff.1 h) _
/-- Embed an infinite stream as a sequence -/
@[coe]
def ofStream (s : Stream' α) : Seq α :=
⟨s.map some, fun {n} h => by contradiction⟩
instance coeStream : Coe (Stream' α) (Seq α) :=
⟨ofStream⟩
section MLList
/-- Embed a `MLList α` as a sequence. Note that even though this
is non-meta, it will produce infinite sequences if used with
cyclic `MLList`s created by meta constructions. -/
def ofMLList : MLList Id α → Seq α :=
corec fun l =>
match l.uncons with
| .none => none
| .some (a, l') => some (a, l')
instance coeMLList : Coe (MLList Id α) (Seq α) :=
⟨ofMLList⟩
/-- Translate a sequence into a `MLList`. -/
unsafe def toMLList : Seq α → MLList Id α
| s =>
match destruct s with
| none => .nil
| some (a, s') => .cons a (toMLList s')
end MLList
/-- Translate a sequence to a list. This function will run forever if
run on an infinite sequence. -/
unsafe def forceToList (s : Seq α) : List α :=
(toMLList s).force
/-- The sequence of natural numbers some 0, some 1, ... -/
def nats : Seq ℕ :=
Stream'.nats
@[simp]
theorem nats_get? (n : ℕ) : nats.get? n = some n :=
rfl
/-- Append two sequences. If `s₁` is infinite, then `s₁ ++ s₂ = s₁`,
otherwise it puts `s₂` at the location of the `nil` in `s₁`. -/
def append (s₁ s₂ : Seq α) : Seq α :=
@corec α (Seq α × Seq α)
(fun ⟨s₁, s₂⟩ =>
match destruct s₁ with
| none => omap (fun s₂ => (nil, s₂)) (destruct s₂)
| some (a, s₁') => some (a, s₁', s₂))
(s₁, s₂)
/-- Map a function over a sequence. -/
def map (f : α → β) : Seq α → Seq β
| ⟨s, al⟩ =>
⟨s.map (Option.map f), fun {n} => by
dsimp [Stream'.map, Stream'.get]
induction' e : s n with e <;> intro
· rw [al e]
assumption
· contradiction⟩
/-- Flatten a sequence of sequences. (It is required that the
sequences be nonempty to ensure productivity; in the case
of an infinite sequence of `nil`, the first element is never
generated.) -/
def join : Seq (Seq1 α) → Seq α :=
corec fun S =>
match destruct S with
| none => none
| some ((a, s), S') =>
some
(a,
match destruct s with
| none => S'
| some s' => cons s' S')
/-- Remove the first `n` elements from the sequence. -/
def drop (s : Seq α) : ℕ → Seq α
| 0 => s
| n + 1 => tail (drop s n)
/-- Take the first `n` elements of the sequence (producing a list) -/
def take : ℕ → Seq α → List α
| 0, _ => []
| n + 1, s =>
match destruct s with
| none => []
| some (x, r) => List.cons x (take n r)
/-- Split a sequence at `n`, producing a finite initial segment
and an infinite tail. -/
def splitAt : ℕ → Seq α → List α × Seq α
| 0, s => ([], s)
| n + 1, s =>
match destruct s with
| none => ([], nil)
| some (x, s') =>
let (l, r) := splitAt n s'
(List.cons x l, r)
/-- Folds a sequence using `f`, producing a sequence of intermediate values, i.e.
`[init, f init s.head, f (f init s.head) s.tail.head, ...]`. -/
def fold (s : Seq α) (init : β) (f : β → α → β) : Seq β :=
let f : β × Seq α → Option (β × (β × Seq α)) := fun (acc, x) =>
match destruct x with
| none => .none
| some (x, s) => .some (f acc x, f acc x, s)
cons init <| corec f (init, s)
section ZipWith
/-- Combine two sequences with a function -/
def zipWith (f : α → β → γ) (s₁ : Seq α) (s₂ : Seq β) : Seq γ :=
⟨fun n => Option.map₂ f (s₁.get? n) (s₂.get? n), fun {_} hn =>
Option.map₂_eq_none_iff.2 <| (Option.map₂_eq_none_iff.1 hn).imp s₁.2 s₂.2⟩
@[simp]
theorem get?_zipWith (f : α → β → γ) (s s' n) :
(zipWith f s s').get? n = Option.map₂ f (s.get? n) (s'.get? n) :=
rfl
end ZipWith
/-- Pair two sequences into a sequence of pairs -/
def zip : Seq α → Seq β → Seq (α × β) :=
zipWith Prod.mk
@[simp]
theorem get?_zip (s : Seq α) (t : Seq β) (n : ℕ) :
get? (zip s t) n = Option.map₂ Prod.mk (get? s n) (get? t n) :=
get?_zipWith _ _ _ _
/-- Separate a sequence of pairs into two sequences -/
def unzip (s : Seq (α × β)) : Seq α × Seq β :=
(map Prod.fst s, map Prod.snd s)
/-- Enumerate a sequence by tagging each element with its index. -/
def enum (s : Seq α) : Seq (ℕ × α) :=
Seq.zip nats s
@[simp]
theorem get?_enum (s : Seq α) (n : ℕ) : get? (enum s) n = Option.map (Prod.mk n) (get? s n) :=
get?_zip _ _ _
@[simp]
theorem enum_nil : enum (nil : Seq α) = nil :=
rfl
/-- The length of a terminating sequence. -/
def length (s : Seq α) (h : s.Terminates) : ℕ :=
Nat.find h
/-- Convert a sequence which is known to terminate into a list -/
def toList (s : Seq α) (h : s.Terminates) : List α :=
take (length s h) s
/-- Convert a sequence which is known not to terminate into a stream -/
def toStream (s : Seq α) (h : ¬s.Terminates) : Stream' α := fun n =>
Option.get _ <| not_terminates_iff.1 h n
/-- Convert a sequence into either a list or a stream depending on whether
it is finite or infinite. (Without decidability of the infiniteness predicate,
this is not constructively possible.) -/
def toListOrStream (s : Seq α) [Decidable s.Terminates] : List α ⊕ Stream' α :=
if h : s.Terminates then Sum.inl (toList s h) else Sum.inr (toStream s h)
@[simp]
theorem nil_append (s : Seq α) : append nil s = s := by
apply coinduction2; intro s
dsimp [append]; rw [corec_eq]
dsimp [append]
cases s
· trivial
· rw [destruct_cons]
dsimp
exact ⟨rfl, _, rfl, rfl⟩
@[simp]
theorem take_nil {n : ℕ} : (nil (α := α)).take n = List.nil := by
cases n <;> rfl
@[simp]
theorem take_zero {s : Seq α} : s.take 0 = [] := by
cases s <;> rfl
@[simp]
theorem take_succ_cons {n : ℕ} {x : α} {s : Seq α} :
(cons x s).take (n + 1) = x :: s.take n := by
rfl
@[simp]
theorem getElem?_take : ∀ (n k : ℕ) (s : Seq α),
(s.take k)[n]? = if n < k then s.get? n else none
| n, 0, s => by simp [take]
| n, k+1, s => by
rw [take]
cases h : destruct s with
| none =>
simp [destruct_eq_none h]
| some a =>
match a with
| (x, r) =>
rw [destruct_eq_cons h]
match n with
| 0 => simp
| n+1 =>
simp [List.getElem?_cons_succ, Nat.add_lt_add_iff_right, getElem?_take]
theorem get?_mem_take {s : Seq α} {m n : ℕ} (h_mn : m < n) {x : α}
(h_get : s.get? m = .some x) : x ∈ s.take n := by
induction m generalizing n s with
| zero =>
obtain ⟨l, hl⟩ := Nat.exists_add_one_eq.mpr h_mn
rw [← hl, take, head_eq_some h_get]
simp
| succ k ih =>
obtain ⟨l, hl⟩ := Nat.exists_eq_add_of_lt h_mn
subst hl
have : ∃ y, s.get? 0 = .some y := by
apply ge_stable _ _ h_get
simp
obtain ⟨y, hy⟩ := this
rw [take, head_eq_some hy]
simp
right
apply ih (by omega)
rwa [get?_tail]
theorem terminatedAt_ofList (l : List α) :
(ofList l).TerminatedAt l.length := by
simp [ofList, TerminatedAt]
theorem terminates_ofList (l : List α) : (ofList l).Terminates :=
⟨_, terminatedAt_ofList l⟩
@[simp]
theorem terminatedAt_nil {n : ℕ} : TerminatedAt (nil : Seq α) n := rfl
@[simp]
theorem cons_not_terminatedAt_zero {x : α} {s : Seq α} :
¬(cons x s).TerminatedAt 0 := by
simp [TerminatedAt]
@[simp]
theorem cons_terminatedAt_succ_iff {x : α} {s : Seq α} {n : ℕ} :
(cons x s).TerminatedAt (n + 1) ↔ s.TerminatedAt n := by
simp [TerminatedAt]
@[simp]
theorem terminates_nil : Terminates (nil : Seq α) := ⟨0, rfl⟩
@[simp]
theorem terminates_cons_iff {x : α} {s : Seq α} :
(cons x s).Terminates ↔ s.Terminates := by
constructor <;> intro ⟨n, h⟩
· exact ⟨n, cons_terminatedAt_succ_iff.mp (terminated_stable _ (Nat.le_succ _) h)⟩
· exact ⟨n + 1, cons_terminatedAt_succ_iff.mpr h⟩
@[simp]
theorem length_nil : length (nil : Seq α) terminates_nil = 0 := rfl
@[simp]
theorem get?_zero_eq_none {s : Seq α} : s.get? 0 = none ↔ s = nil := by
refine ⟨fun h => ?_, fun h => h ▸ rfl⟩
ext1 n
exact le_stable s (Nat.zero_le _) h
@[simp] theorem length_eq_zero {s : Seq α} {h : s.Terminates} :
s.length h = 0 ↔ s = nil := by
simp [length, TerminatedAt]
theorem terminatedAt_zero_iff {s : Seq α} : s.TerminatedAt 0 ↔ s = nil := by
refine ⟨?_, ?_⟩
· intro h
ext n
rw [le_stable _ (Nat.zero_le _) h]
simp
· rintro rfl
simp [TerminatedAt]
/-- The statement of `length_le_iff'` does not assume that the sequence terminates. For a
simpler statement of the theorem where the sequence is known to terminate see `length_le_iff` -/
theorem length_le_iff' {s : Seq α} {n : ℕ} :
(∃ h, s.length h ≤ n) ↔ s.TerminatedAt n := by
simp only [length, Nat.find_le_iff, TerminatedAt, Terminates, exists_prop]
refine ⟨?_, ?_⟩
· rintro ⟨_, k, hkn, hk⟩
exact le_stable s hkn hk
· intro hn
exact ⟨⟨n, hn⟩, ⟨n, le_rfl, hn⟩⟩
/-- The statement of `length_le_iff` assumes that the sequence terminates. For a
statement of the where the sequence is not known to terminate see `length_le_iff'` -/
theorem length_le_iff {s : Seq α} {n : ℕ} {h : s.Terminates} :
s.length h ≤ n ↔ s.TerminatedAt n := by
rw [← length_le_iff']; simp [h]
/-- The statement of `lt_length_iff'` does not assume that the sequence terminates. For a
simpler statement of the theorem where the sequence is known to terminate see `lt_length_iff` -/
theorem lt_length_iff' {s : Seq α} {n : ℕ} :
(∀ h : s.Terminates, n < s.length h) ↔ ∃ a, a ∈ s.get? n := by
simp only [Terminates, TerminatedAt, length, Nat.lt_find_iff, forall_exists_index, Option.mem_def,
← Option.ne_none_iff_exists', ne_eq]
refine ⟨?_, ?_⟩
· intro h hn
exact h n hn n le_rfl hn
· intro hn _ _ k hkn hk
exact hn <| le_stable s hkn hk
/-- The statement of `length_le_iff` assumes that the sequence terminates. For a
statement of the where the sequence is not known to terminate see `length_le_iff'` -/
theorem lt_length_iff {s : Seq α} {n : ℕ} {h : s.Terminates} :
n < s.length h ↔ ∃ a, a ∈ s.get? n := by
rw [← lt_length_iff']; simp [h]
theorem length_take_le {s : Seq α} {n : ℕ} : (s.take n).length ≤ n := by
induction n generalizing s with
| zero => simp
| succ m ih =>
rw [take]
cases s.destruct with
| none => simp
| some v =>
obtain ⟨x, r⟩ := v
simpa using ih
theorem length_take_of_le_length {s : Seq α} {n : ℕ}
(hle : ∀ h : s.Terminates, n ≤ s.length h) : (s.take n).length = n := by
induction n generalizing s with
| zero => simp [take]
| succ n ih =>
rw [take, destruct]
let ⟨a, ha⟩ := lt_length_iff'.1 (fun ht => lt_of_lt_of_le (Nat.succ_pos _) (hle ht))
simp [Option.mem_def.1 ha]
rw [ih]
intro h
simp only [length, tail, Nat.le_find_iff, TerminatedAt, get?_mk, Stream'.tail]
intro m hmn hs
have := lt_length_iff'.1 (fun ht => (Nat.lt_of_succ_le (hle ht)))
rw [le_stable s (Nat.succ_le_of_lt hmn) hs] at this
simp at this
@[simp]
| theorem length_toList (s : Seq α) (h : s.Terminates) : (toList s h).length = length s h := by
rw [toList, length_take_of_le_length]
| Mathlib/Data/Seq/Seq.lean | 806 | 807 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky
-/
import Mathlib.Data.Fintype.Card
import Mathlib.Algebra.Group.Commute.Basic
import Mathlib.Algebra.Group.End
import Mathlib.Data.Finset.NoncommProd
/-!
# support of a permutation
## Main definitions
In the following, `f g : Equiv.Perm α`.
* `Equiv.Perm.Disjoint`: two permutations `f` and `g` are `Disjoint` if every element is fixed
either by `f`, or by `g`.
Equivalently, `f` and `g` are `Disjoint` iff their `support` are disjoint.
* `Equiv.Perm.IsSwap`: `f = swap x y` for `x ≠ y`.
* `Equiv.Perm.support`: the elements `x : α` that are not fixed by `f`.
Assume `α` is a Fintype:
* `Equiv.Perm.fixed_point_card_lt_of_ne_one f` says that `f` has
strictly less than `Fintype.card α - 1` fixed points, unless `f = 1`.
(Equivalently, `f.support` has at least 2 elements.)
-/
open Equiv Finset Function
namespace Equiv.Perm
variable {α : Type*}
section Disjoint
/-- Two permutations `f` and `g` are `Disjoint` if their supports are disjoint, i.e.,
every element is fixed either by `f`, or by `g`. -/
def Disjoint (f g : Perm α) :=
∀ x, f x = x ∨ g x = x
variable {f g h : Perm α}
@[symm]
theorem Disjoint.symm : Disjoint f g → Disjoint g f := by simp only [Disjoint, or_comm, imp_self]
theorem Disjoint.symmetric : Symmetric (@Disjoint α) := fun _ _ => Disjoint.symm
instance : IsSymm (Perm α) Disjoint :=
⟨Disjoint.symmetric⟩
theorem disjoint_comm : Disjoint f g ↔ Disjoint g f :=
⟨Disjoint.symm, Disjoint.symm⟩
theorem Disjoint.commute (h : Disjoint f g) : Commute f g :=
Equiv.ext fun x =>
(h x).elim
(fun hf =>
(h (g x)).elim (fun hg => by simp [mul_apply, hf, hg]) fun hg => by
simp [mul_apply, hf, g.injective hg])
fun hg =>
(h (f x)).elim (fun hf => by simp [mul_apply, f.injective hf, hg]) fun hf => by
simp [mul_apply, hf, hg]
@[simp]
theorem disjoint_one_left (f : Perm α) : Disjoint 1 f := fun _ => Or.inl rfl
@[simp]
theorem disjoint_one_right (f : Perm α) : Disjoint f 1 := fun _ => Or.inr rfl
theorem disjoint_iff_eq_or_eq : Disjoint f g ↔ ∀ x : α, f x = x ∨ g x = x :=
Iff.rfl
@[simp]
theorem disjoint_refl_iff : Disjoint f f ↔ f = 1 := by
refine ⟨fun h => ?_, fun h => h.symm ▸ disjoint_one_left 1⟩
ext x
rcases h x with hx | hx <;> simp [hx]
theorem Disjoint.inv_left (h : Disjoint f g) : Disjoint f⁻¹ g := by
intro x
rw [inv_eq_iff_eq, eq_comm]
exact h x
theorem Disjoint.inv_right (h : Disjoint f g) : Disjoint f g⁻¹ :=
h.symm.inv_left.symm
@[simp]
theorem disjoint_inv_left_iff : Disjoint f⁻¹ g ↔ Disjoint f g := by
refine ⟨fun h => ?_, Disjoint.inv_left⟩
convert h.inv_left
@[simp]
theorem disjoint_inv_right_iff : Disjoint f g⁻¹ ↔ Disjoint f g := by
rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm]
theorem Disjoint.mul_left (H1 : Disjoint f h) (H2 : Disjoint g h) : Disjoint (f * g) h := fun x =>
by cases H1 x <;> cases H2 x <;> simp [*]
theorem Disjoint.mul_right (H1 : Disjoint f g) (H2 : Disjoint f h) : Disjoint f (g * h) := by
rw [disjoint_comm]
exact H1.symm.mul_left H2.symm
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it `@[simp]`
theorem disjoint_conj (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) ↔ Disjoint f g :=
(h⁻¹).forall_congr fun {_} ↦ by simp only [mul_apply, eq_inv_iff_eq]
theorem Disjoint.conj (H : Disjoint f g) (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) :=
(disjoint_conj h).2 H
theorem disjoint_prod_right (l : List (Perm α)) (h : ∀ g ∈ l, Disjoint f g) :
Disjoint f l.prod := by
induction' l with g l ih
· exact disjoint_one_right _
· rw [List.prod_cons]
exact (h _ List.mem_cons_self).mul_right (ih fun g hg => h g (List.mem_cons_of_mem _ hg))
theorem disjoint_noncommProd_right {ι : Type*} {k : ι → Perm α} {s : Finset ι}
(hs : Set.Pairwise s fun i j ↦ Commute (k i) (k j))
(hg : ∀ i ∈ s, g.Disjoint (k i)) :
Disjoint g (s.noncommProd k (hs)) :=
noncommProd_induction s k hs g.Disjoint (fun _ _ ↦ Disjoint.mul_right) (disjoint_one_right g) hg
open scoped List in
theorem disjoint_prod_perm {l₁ l₂ : List (Perm α)} (hl : l₁.Pairwise Disjoint) (hp : l₁ ~ l₂) :
l₁.prod = l₂.prod :=
hp.prod_eq' <| hl.imp Disjoint.commute
theorem nodup_of_pairwise_disjoint {l : List (Perm α)} (h1 : (1 : Perm α) ∉ l)
(h2 : l.Pairwise Disjoint) : l.Nodup := by
refine List.Pairwise.imp_of_mem ?_ h2
intro τ σ h_mem _ h_disjoint _
subst τ
suffices (σ : Perm α) = 1 by
rw [this] at h_mem
exact h1 h_mem
exact ext fun a => or_self_iff.mp (h_disjoint a)
theorem pow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℕ, (f ^ n) x = x
| 0 => rfl
| n + 1 => by rw [pow_succ, mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self hfx n]
theorem zpow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℤ, (f ^ n) x = x
| (n : ℕ) => pow_apply_eq_self_of_apply_eq_self hfx n
| Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx]
theorem pow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) :
∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x
| 0 => Or.inl rfl
| n + 1 =>
(pow_apply_eq_of_apply_apply_eq_self hffx n).elim
(fun h => Or.inr (by rw [pow_succ', mul_apply, h]))
fun h => Or.inl (by rw [pow_succ', mul_apply, h, hffx])
theorem zpow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) :
∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x
| | (n : ℕ) => pow_apply_eq_of_apply_apply_eq_self hffx n
| Int.negSucc n => by
rw [zpow_negSucc, inv_eq_iff_eq, ← f.injective.eq_iff, ← mul_apply, ← pow_succ', eq_comm,
| Mathlib/GroupTheory/Perm/Support.lean | 160 | 162 |
/-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
-/
import Mathlib.Control.Basic
import Mathlib.Data.Nat.Basic
import Mathlib.Data.Option.Basic
import Mathlib.Data.List.Defs
import Mathlib.Data.List.Monad
import Mathlib.Logic.OpClass
import Mathlib.Logic.Unique
import Mathlib.Order.Basic
import Mathlib.Tactic.Common
/-!
# Basic properties of lists
-/
assert_not_exists GroupWithZero
assert_not_exists Lattice
assert_not_exists Prod.swap_eq_iff_eq_swap
assert_not_exists Ring
assert_not_exists Set.range
open Function
open Nat hiding one_pos
namespace List
universe u v w
variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α}
/-- There is only one list of an empty type -/
instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) :=
{ instInhabitedList with
uniq := fun l =>
match l with
| [] => rfl
| a :: _ => isEmptyElim a }
instance : Std.LawfulIdentity (α := List α) Append.append [] where
left_id := nil_append
right_id := append_nil
instance : Std.Associative (α := List α) Append.append where
assoc := append_assoc
@[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq
theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1
theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } :=
Set.ext fun _ => mem_cons
/-! ### mem -/
theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α]
{a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by
by_cases hab : a = b
· exact Or.inl hab
· exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩))
lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by
rw [mem_cons, mem_singleton]
-- The simpNF linter says that the LHS can be simplified via `List.mem_map`.
-- However this is a higher priority lemma.
-- It seems the side condition `hf` is not applied by `simpNF`.
-- https://github.com/leanprover/std4/issues/207
@[simp 1100, nolint simpNF]
theorem mem_map_of_injective {f : α → β} (H : Injective f) {a : α} {l : List α} :
f a ∈ map f l ↔ a ∈ l :=
⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem⟩
@[simp]
theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α}
(hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l :=
⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩
theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} :
a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff]
/-! ### length -/
alias ⟨_, length_pos_of_ne_nil⟩ := length_pos_iff
theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] :=
⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩
theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t
| [], H => absurd H.symm <| succ_ne_zero n
| h :: t, _ => ⟨h, t, rfl⟩
@[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by
constructor
· intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl
· intros hα l1 l2 hl
induction l1 generalizing l2 <;> cases l2
· rfl
· cases hl
· cases hl
· next ih _ _ =>
congr
· subsingleton
· apply ih; simpa using hl
@[simp default+1] -- Raise priority above `length_injective_iff`.
lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) :=
length_injective_iff.mpr inferInstance
theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] :=
⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩
theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] :=
⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩
/-! ### set-theoretic notation of lists -/
instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩
instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩
instance [DecidableEq α] : LawfulSingleton α (List α) :=
{ insert_empty_eq := fun x =>
show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg not_mem_nil }
theorem singleton_eq (x : α) : ({x} : List α) = [x] :=
rfl
theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) :
Insert.insert x l = x :: l :=
insert_of_not_mem h
theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l :=
insert_of_mem h
theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by
rw [insert_neg, singleton_eq]
rwa [singleton_eq, mem_singleton]
/-! ### bounded quantifiers over lists -/
theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) :
∀ x ∈ l, p x := (forall_mem_cons.1 h).2
theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x :=
⟨a, mem_cons_self, h⟩
theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) →
∃ x ∈ a :: l, p x :=
fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩
theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) →
p a ∨ ∃ x ∈ l, p x :=
fun ⟨x, xal, px⟩ =>
Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px)
fun h : x ∈ l => Or.inr ⟨x, h, px⟩
theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) :
(∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x :=
Iff.intro or_exists_of_exists_mem_cons fun h =>
Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists
/-! ### list subset -/
theorem cons_subset_of_subset_of_mem {a : α} {l m : List α}
(ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m :=
cons_subset.2 ⟨ainm, lsubm⟩
theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) :
l₁ ++ l₂ ⊆ l :=
fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _)
theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) :
map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by
refine ⟨?_, map_subset f⟩; intro h2 x hx
rcases mem_map.1 (h2 (mem_map_of_mem hx)) with ⟨x', hx', hxx'⟩
cases h hxx'; exact hx'
/-! ### append -/
theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ :=
rfl
theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t :=
fun _ _ ↦ append_cancel_left
theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t :=
fun _ _ ↦ append_cancel_right
/-! ### replicate -/
theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a
| [] => by simp
| (b :: l) => by simp [eq_replicate_length, replicate_succ]
theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by
rw [replicate_append_replicate]
theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h =>
mem_singleton.2 (eq_of_mem_replicate h)
theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by
simp only [eq_replicate_iff, subset_def, mem_singleton, exists_eq_left']
theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) :=
fun _ _ h => (eq_replicate_iff.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩
theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) :
replicate n a = replicate n b ↔ a = b :=
(replicate_right_injective hn).eq_iff
theorem replicate_right_inj' {a b : α} : ∀ {n},
replicate n a = replicate n b ↔ n = 0 ∨ a = b
| 0 => by simp
| n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or]
theorem replicate_left_injective (a : α) : Injective (replicate · a) :=
LeftInverse.injective (length_replicate (n := ·))
theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m :=
(replicate_left_injective a).eq_iff
@[simp]
theorem head?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.head? = l.head? := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
induction l <;> simp [replicate]
@[simp]
theorem getLast?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.getLast? = l.getLast? := by
rw [← List.head?_reverse, ← List.head?_reverse, List.reverse_flatten, List.map_replicate,
List.reverse_replicate, head?_flatten_replicate h]
/-! ### pure -/
theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp
/-! ### bind -/
@[simp]
theorem bind_eq_flatMap {α β} (f : α → List β) (l : List α) : l >>= f = l.flatMap f :=
rfl
/-! ### concat -/
/-! ### reverse -/
theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by
simp only [reverse_cons, concat_eq_append]
theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by
rw [reverse_append]; rfl
@[simp]
theorem reverse_singleton (a : α) : reverse [a] = [a] :=
rfl
@[simp]
theorem reverse_involutive : Involutive (@reverse α) :=
reverse_reverse
@[simp]
theorem reverse_injective : Injective (@reverse α) :=
reverse_involutive.injective
theorem reverse_surjective : Surjective (@reverse α) :=
reverse_involutive.surjective
theorem reverse_bijective : Bijective (@reverse α) :=
reverse_involutive.bijective
theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by
simp only [concat_eq_append, reverse_cons, reverse_reverse]
theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) :
map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by
simp only [reverseAux_eq, map_append, map_reverse]
-- TODO: Rename `List.reverse_perm` to `List.reverse_perm_self`
@[simp] lemma reverse_perm' : l₁.reverse ~ l₂ ↔ l₁ ~ l₂ where
mp := l₁.reverse_perm.symm.trans
mpr := l₁.reverse_perm.trans
@[simp] lemma perm_reverse : l₁ ~ l₂.reverse ↔ l₁ ~ l₂ where
mp hl := hl.trans l₂.reverse_perm
mpr hl := hl.trans l₂.reverse_perm.symm
/-! ### getLast -/
attribute [simp] getLast_cons
theorem getLast_append_singleton {a : α} (l : List α) :
getLast (l ++ [a]) (append_ne_nil_of_right_ne_nil l (cons_ne_nil a _)) = a := by
simp [getLast_append]
theorem getLast_append_of_right_ne_nil (l₁ l₂ : List α) (h : l₂ ≠ []) :
getLast (l₁ ++ l₂) (append_ne_nil_of_right_ne_nil l₁ h) = getLast l₂ h := by
induction l₁ with
| nil => simp
| cons _ _ ih => simp only [cons_append]; rw [List.getLast_cons]; exact ih
@[deprecated (since := "2025-02-06")]
alias getLast_append' := getLast_append_of_right_ne_nil
theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (by simp) = a := by
simp
@[simp]
theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl
@[simp]
theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) :
getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) :=
rfl
theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l
| [], h => absurd rfl h
| [_], _ => rfl
| a :: b :: l, h => by
rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)]
congr
exact dropLast_append_getLast (cons_ne_nil b l)
theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) :
getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl
theorem getLast_replicate_succ (m : ℕ) (a : α) :
(replicate (m + 1) a).getLast (ne_nil_of_length_eq_add_one length_replicate) = a := by
simp only [replicate_succ']
exact getLast_append_singleton _
@[deprecated (since := "2025-02-07")]
alias getLast_filter' := getLast_filter_of_pos
/-! ### getLast? -/
theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h
| [], x, hx => False.elim <| by simp at hx
| [a], x, hx =>
have : a = x := by simpa using hx
this ▸ ⟨cons_ne_nil a [], rfl⟩
| a :: b :: l, x, hx => by
rw [getLast?_cons_cons] at hx
rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩
use cons_ne_nil _ _
assumption
theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h)
| [], h => (h rfl).elim
| [_], _ => rfl
| _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _)
theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast?
| [], _ => by contradiction
| _ :: _, h => h
theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l
| [], a, ha => (Option.not_mem_none a ha).elim
| [a], _, rfl => rfl
| a :: b :: l, c, hc => by
rw [getLast?_cons_cons] at hc
rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc]
theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget
| [] => by simp [getLastI, Inhabited.default]
| [_] => rfl
| [_, _] => rfl
| [_, _, _] => rfl
| _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)]
theorem getLast?_append_cons :
∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂)
| [], _, _ => rfl
| [_], _, _ => rfl
| b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons,
← cons_append, getLast?_append_cons (c :: l₁)]
theorem getLast?_append_of_ne_nil (l₁ : List α) :
∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂
| [], hl₂ => by contradiction
| b :: l₂, _ => getLast?_append_cons l₁ b l₂
theorem mem_getLast?_append_of_mem_getLast? {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) :
x ∈ (l₁ ++ l₂).getLast? := by
cases l₂
· contradiction
· rw [List.getLast?_append_cons]
exact h
/-! ### head(!?) and tail -/
@[simp]
theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl
@[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by
cases x <;> simp at h ⊢
theorem head_eq_getElem_zero {l : List α} (hl : l ≠ []) :
l.head hl = l[0]'(length_pos_iff.2 hl) :=
(getElem_zero _).symm
theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl
theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩
theorem surjective_head? : Surjective (@head? α) :=
Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩
theorem surjective_tail : Surjective (@tail α)
| [] => ⟨[], rfl⟩
| a :: l => ⟨a :: a :: l, rfl⟩
theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l
| [], h => (Option.not_mem_none _ h).elim
| a :: l, h => by
simp only [head?, Option.mem_def, Option.some_inj] at h
exact h ▸ rfl
@[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl
@[simp]
theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) :
head! (s ++ t) = head! s := by
induction s
· contradiction
· rfl
theorem mem_head?_append_of_mem_head? {s t : List α} {x : α} (h : x ∈ s.head?) :
x ∈ (s ++ t).head? := by
cases s
· contradiction
· exact h
theorem head?_append_of_ne_nil :
∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁
| _ :: _, _, _ => rfl
theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) :
tail (l ++ [a]) = tail l ++ [a] := by
induction l
· contradiction
· rw [tail, cons_append, tail]
theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l
| [], a, h => by contradiction
| b :: l, a, h => by
simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h
simp [h]
theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l
| [], h => by contradiction
| _ :: _, _ => rfl
theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l :=
cons_head?_tail (head!_mem_head? h)
theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by
have h' : l.head! ∈ l.head! :: l.tail := mem_cons_self
rwa [cons_head!_tail h] at h'
theorem get_eq_getElem? (l : List α) (i : Fin l.length) :
l.get i = l[i]?.get (by simp [getElem?_eq_getElem]) := by
simp
@[deprecated (since := "2025-02-15")] alias get_eq_get? := get_eq_getElem?
theorem exists_mem_iff_getElem {l : List α} {p : α → Prop} :
(∃ x ∈ l, p x) ↔ ∃ (i : ℕ) (_ : i < l.length), p l[i] := by
simp only [mem_iff_getElem]
exact ⟨fun ⟨_x, ⟨i, hi, hix⟩, hxp⟩ ↦ ⟨i, hi, hix ▸ hxp⟩, fun ⟨i, hi, hp⟩ ↦ ⟨_, ⟨i, hi, rfl⟩, hp⟩⟩
theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} :
(∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by
simp [mem_iff_getElem, @forall_swap α]
theorem get_tail (l : List α) (i) (h : i < l.tail.length)
(h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) :
l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by
cases l <;> [cases h; rfl]
/-! ### sublists -/
attribute [refl] List.Sublist.refl
theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ :=
Sublist.cons₂ _ s
lemma cons_sublist_cons' {a b : α} : a :: l₁ <+ b :: l₂ ↔ a :: l₁ <+ l₂ ∨ a = b ∧ l₁ <+ l₂ := by
constructor
· rintro (_ | _)
· exact Or.inl ‹_›
· exact Or.inr ⟨rfl, ‹_›⟩
· rintro (h | ⟨rfl, h⟩)
· exact h.cons _
· rwa [cons_sublist_cons]
theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _
@[deprecated (since := "2025-02-07")]
alias sublist_nil_iff_eq_nil := sublist_nil
@[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by
constructor <;> rintro (_ | _) <;> aesop
theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ :=
s₁.eq_of_length_le s₂.length_le
/-- If the first element of two lists are different, then a sublist relation can be reduced. -/
theorem Sublist.of_cons_of_ne {a b} (h₁ : a ≠ b) (h₂ : a :: l₁ <+ b :: l₂) : a :: l₁ <+ l₂ :=
match h₁, h₂ with
| _, .cons _ h => h
/-! ### indexOf -/
section IndexOf
variable [DecidableEq α]
theorem idxOf_cons_eq {a b : α} (l : List α) : b = a → idxOf a (b :: l) = 0
| e => by rw [← e]; exact idxOf_cons_self
@[deprecated (since := "2025-01-30")] alias indexOf_cons_eq := idxOf_cons_eq
@[simp]
theorem idxOf_cons_ne {a b : α} (l : List α) : b ≠ a → idxOf a (b :: l) = succ (idxOf a l)
| h => by simp only [idxOf_cons, Bool.cond_eq_ite, beq_iff_eq, if_neg h]
@[deprecated (since := "2025-01-30")] alias indexOf_cons_ne := idxOf_cons_ne
theorem idxOf_eq_length_iff {a : α} {l : List α} : idxOf a l = length l ↔ a ∉ l := by
induction l with
| nil => exact iff_of_true rfl not_mem_nil
| cons b l ih =>
simp only [length, mem_cons, idxOf_cons, eq_comm]
rw [cond_eq_if]
split_ifs with h <;> simp at h
· exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm
· simp only [Ne.symm h, false_or]
rw [← ih]
exact succ_inj
@[simp]
theorem idxOf_of_not_mem {l : List α} {a : α} : a ∉ l → idxOf a l = length l :=
idxOf_eq_length_iff.2
@[deprecated (since := "2025-01-30")] alias indexOf_of_not_mem := idxOf_of_not_mem
theorem idxOf_le_length {a : α} {l : List α} : idxOf a l ≤ length l := by
induction l with | nil => rfl | cons b l ih => ?_
simp only [length, idxOf_cons, cond_eq_if, beq_iff_eq]
by_cases h : b = a
· rw [if_pos h]; exact Nat.zero_le _
· rw [if_neg h]; exact succ_le_succ ih
@[deprecated (since := "2025-01-30")] alias indexOf_le_length := idxOf_le_length
theorem idxOf_lt_length_iff {a} {l : List α} : idxOf a l < length l ↔ a ∈ l :=
⟨fun h => Decidable.byContradiction fun al => Nat.ne_of_lt h <| idxOf_eq_length_iff.2 al,
fun al => (lt_of_le_of_ne idxOf_le_length) fun h => idxOf_eq_length_iff.1 h al⟩
@[deprecated (since := "2025-01-30")] alias indexOf_lt_length_iff := idxOf_lt_length_iff
theorem idxOf_append_of_mem {a : α} (h : a ∈ l₁) : idxOf a (l₁ ++ l₂) = idxOf a l₁ := by
induction l₁ with
| nil =>
exfalso
exact not_mem_nil h
| cons d₁ t₁ ih =>
rw [List.cons_append]
by_cases hh : d₁ = a
· iterate 2 rw [idxOf_cons_eq _ hh]
rw [idxOf_cons_ne _ hh, idxOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_mem := idxOf_append_of_mem
theorem idxOf_append_of_not_mem {a : α} (h : a ∉ l₁) :
idxOf a (l₁ ++ l₂) = l₁.length + idxOf a l₂ := by
induction l₁ with
| nil => rw [List.nil_append, List.length, Nat.zero_add]
| cons d₁ t₁ ih =>
rw [List.cons_append, idxOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length,
ih (not_mem_of_not_mem_cons h), Nat.succ_add]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_not_mem := idxOf_append_of_not_mem
end IndexOf
/-! ### nth element -/
section deprecated
@[simp]
theorem getElem?_length (l : List α) : l[l.length]? = none := getElem?_eq_none le_rfl
/-- A version of `getElem_map` that can be used for rewriting. -/
theorem getElem_map_rev (f : α → β) {l} {n : Nat} {h : n < l.length} :
f l[n] = (map f l)[n]'((l.length_map f).symm ▸ h) := Eq.symm (getElem_map _)
theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) :
l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) :=
(getLast_eq_getElem _).symm
theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) :
(l.drop n).take 1 = [l.get ⟨n, h⟩] := by
rw [drop_eq_getElem_cons h, take, take]
simp
theorem ext_getElem?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) :
l₁ = l₂ := by
apply ext_getElem?
intro n
rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn
· exact h' n hn
· simp_all [Nat.max_le, getElem?_eq_none]
@[deprecated (since := "2025-02-15")] alias ext_get?' := ext_getElem?'
@[deprecated (since := "2025-02-15")] alias ext_get?_iff := List.ext_getElem?_iff
theorem ext_get_iff {l₁ l₂ : List α} :
l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by
constructor
· rintro rfl
exact ⟨rfl, fun _ _ _ ↦ rfl⟩
· intro ⟨h₁, h₂⟩
exact ext_get h₁ h₂
theorem ext_getElem?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔
∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]? :=
⟨by rintro rfl _ _; rfl, ext_getElem?'⟩
@[deprecated (since := "2025-02-15")] alias ext_get?_iff' := ext_getElem?_iff'
/-- If two lists `l₁` and `l₂` are the same length and `l₁[n]! = l₂[n]!` for all `n`,
then the lists are equal. -/
theorem ext_getElem! [Inhabited α] (hl : length l₁ = length l₂) (h : ∀ n : ℕ, l₁[n]! = l₂[n]!) :
l₁ = l₂ :=
ext_getElem hl fun n h₁ h₂ ↦ by simpa only [← getElem!_pos] using h n
@[simp]
theorem getElem_idxOf [DecidableEq α] {a : α} : ∀ {l : List α} (h : idxOf a l < l.length),
l[idxOf a l] = a
| b :: l, h => by
by_cases h' : b = a <;>
simp [h', if_pos, if_false, getElem_idxOf]
@[deprecated (since := "2025-01-30")] alias getElem_indexOf := getElem_idxOf
-- This is incorrectly named and should be `get_idxOf`;
-- this already exists, so will require a deprecation dance.
theorem idxOf_get [DecidableEq α] {a : α} {l : List α} (h) : get l ⟨idxOf a l, h⟩ = a := by
simp
@[deprecated (since := "2025-01-30")] alias indexOf_get := idxOf_get
@[simp]
theorem getElem?_idxOf [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) :
l[idxOf a l]? = some a := by
rw [getElem?_eq_getElem, getElem_idxOf (idxOf_lt_length_iff.2 h)]
@[deprecated (since := "2025-01-30")] alias getElem?_indexOf := getElem?_idxOf
@[deprecated (since := "2025-02-15")] alias idxOf_get? := getElem?_idxOf
@[deprecated (since := "2025-01-30")] alias indexOf_get? := getElem?_idxOf
theorem idxOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) :
idxOf x l = idxOf y l ↔ x = y :=
⟨fun h => by
have x_eq_y :
get l ⟨idxOf x l, idxOf_lt_length_iff.2 hx⟩ =
get l ⟨idxOf y l, idxOf_lt_length_iff.2 hy⟩ := by
simp only [h]
simp only [idxOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩
@[deprecated (since := "2025-01-30")] alias indexOf_inj := idxOf_inj
theorem get_reverse' (l : List α) (n) (hn') :
l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := by
simp
theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.get ⟨0, by omega⟩] := by
refine ext_get (by convert h) fun n h₁ h₂ => ?_
simp
congr
omega
end deprecated
@[simp]
theorem getElem_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α)
(hj : j < (l.set i a).length) :
(l.set i a)[j] = l[j]'(by simpa using hj) := by
rw [← Option.some_inj, ← List.getElem?_eq_getElem, List.getElem?_set_ne h,
List.getElem?_eq_getElem]
/-! ### map -/
-- `List.map_const` (the version with `Function.const` instead of a lambda) is already tagged
-- `simp` in Core
-- TODO: Upstream the tagging to Core?
attribute [simp] map_const'
theorem flatMap_pure_eq_map (f : α → β) (l : List α) : l.flatMap (pure ∘ f) = map f l :=
.symm <| map_eq_flatMap ..
theorem flatMap_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) :
l.flatMap f = l.flatMap g :=
(congr_arg List.flatten <| map_congr_left h :)
theorem infix_flatMap_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) :
f a <:+: as.flatMap f :=
infix_of_mem_flatten (mem_map_of_mem h)
@[simp]
theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l :=
rfl
/-- A single `List.map` of a composition of functions is equal to
composing a `List.map` with another `List.map`, fully applied.
This is the reverse direction of `List.map_map`.
-/
theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) :=
map_map.symm
/-- Composing a `List.map` with another `List.map` is equal to
a single `List.map` of composed functions.
-/
@[simp]
theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by
ext l; rw [comp_map, Function.comp_apply]
section map_bijectivity
theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) :
LeftInverse (map f) (map g)
| [] => by simp_rw [map_nil]
| x :: xs => by simp_rw [map_cons, h x, h.list_map xs]
nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α}
(h : RightInverse f g) : RightInverse (map f) (map g) :=
h.list_map
nonrec theorem _root_.Function.Involutive.list_map {f : α → α}
(h : Involutive f) : Involutive (map f) :=
Function.LeftInverse.list_map h
@[simp]
theorem map_leftInverse_iff {f : α → β} {g : β → α} :
LeftInverse (map f) (map g) ↔ LeftInverse f g :=
⟨fun h x => by injection h [x], (·.list_map)⟩
@[simp]
theorem map_rightInverse_iff {f : α → β} {g : β → α} :
RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff
@[simp]
theorem map_involutive_iff {f : α → α} :
Involutive (map f) ↔ Involutive f := map_leftInverse_iff
theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) :
Injective (map f)
| [], [], _ => rfl
| x :: xs, y :: ys, hxy => by
injection hxy with hxy hxys
rw [h hxy, h.list_map hxys]
@[simp]
theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by
refine ⟨fun h x y hxy => ?_, (·.list_map)⟩
suffices [x] = [y] by simpa using this
apply h
simp [hxy]
theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) :
Surjective (map f) :=
let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective
@[simp]
theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by
refine ⟨fun h x => ?_, (·.list_map)⟩
let ⟨[y], hxy⟩ := h [x]
exact ⟨_, List.singleton_injective hxy⟩
theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) :=
⟨h.1.list_map, h.2.list_map⟩
@[simp]
theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by
simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff]
end map_bijectivity
theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) :
b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h
/-- `eq_nil_or_concat` in simp normal form -/
lemma eq_nil_or_concat' (l : List α) : l = [] ∨ ∃ L b, l = L ++ [b] := by
simpa using l.eq_nil_or_concat
/-! ### foldl, foldr -/
theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) :
foldl f a l = foldl g a l := by
induction l generalizing a with
| nil => rfl
| cons hd tl ih =>
unfold foldl
rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd mem_cons_self]
theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) :
foldr f b l = foldr g b l := by
induction l with | nil => rfl | cons hd tl ih => ?_
simp only [mem_cons, or_imp, forall_and, forall_eq] at H
simp only [foldr, ih H.2, H.1]
theorem foldl_concat
(f : β → α → β) (b : β) (x : α) (xs : List α) :
List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by
simp only [List.foldl_append, List.foldl]
theorem foldr_concat
(f : α → β → β) (b : β) (x : α) (xs : List α) :
List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by
simp only [List.foldr_append, List.foldr]
theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a
| [] => rfl
| b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l]
theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b
| [] => rfl
| a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a]
@[simp]
theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a :=
foldl_fixed' fun _ => rfl
@[simp]
theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b :=
foldr_fixed' fun _ => rfl
@[deprecated foldr_cons_nil (since := "2025-02-10")]
theorem foldr_eta (l : List α) : foldr cons [] l = l := foldr_cons_nil
theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by
simp
theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β)
(op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) :
foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) :=
Eq.symm <| by
revert a b
induction l <;> intros <;> [rfl; simp only [*, foldl]]
theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β)
(op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) :
foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by
revert a
induction l <;> intros <;> [rfl; simp only [*, foldr]]
theorem injective_foldl_comp {l : List (α → α)} {f : α → α}
(hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) :
Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by
induction l generalizing f with
| nil => exact hf
| cons lh lt l_ih =>
apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h)
apply Function.Injective.comp hf
apply hl _ mem_cons_self
/-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them:
`l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`.
Assume the designated element `a₂` is present in neither `x₁` nor `z₁`.
We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal
(`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/
lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α}
(notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) :
x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by
constructor
· simp only [append_eq_append_iff, cons_eq_append_iff, cons_eq_cons]
rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ |
⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all
· rintro ⟨rfl, rfl, rfl⟩
rfl
section FoldlEqFoldr
-- foldl and foldr coincide when f is commutative and associative
variable {f : α → α → α}
theorem foldl1_eq_foldr1 [hassoc : Std.Associative f] :
∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l)
| _, _, nil => rfl
| a, b, c :: l => by
simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l]
rw [hassoc.assoc]
theorem foldl_eq_of_comm_of_assoc [hcomm : Std.Commutative f] [hassoc : Std.Associative f] :
∀ a b l, foldl f a (b :: l) = f b (foldl f a l)
| a, b, nil => hcomm.comm a b
| a, b, c :: l => by
simp only [foldl_cons]
have : RightCommutative f := inferInstance
rw [← foldl_eq_of_comm_of_assoc .., this.right_comm, foldl_cons]
theorem foldl_eq_foldr [Std.Commutative f] [Std.Associative f] :
∀ a l, foldl f a l = foldr f a l
| _, nil => rfl
| a, b :: l => by
simp only [foldr_cons, foldl_eq_of_comm_of_assoc]
rw [foldl_eq_foldr a l]
end FoldlEqFoldr
section FoldlEqFoldlr'
variable {f : α → β → α}
variable (hf : ∀ a b c, f (f a b) c = f (f a c) b)
include hf
theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b
| _, _, [] => rfl
| a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf]
theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l
| _, [] => rfl
| a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl
end FoldlEqFoldlr'
section FoldlEqFoldlr'
variable {f : α → β → β}
theorem foldr_eq_of_comm' (hf : ∀ a b c, f a (f b c) = f b (f a c)) :
∀ a b l, foldr f a (b :: l) = foldr f (f b a) l
| _, _, [] => rfl
| a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' hf ..]; rfl
end FoldlEqFoldlr'
section
variable {op : α → α → α} [ha : Std.Associative op]
/-- Notation for `op a b`. -/
local notation a " ⋆ " b => op a b
/-- Notation for `foldl op a l`. -/
local notation l " <*> " a => foldl op a l
theorem foldl_op_eq_op_foldr_assoc :
∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂
| [], _, _ => rfl
| a :: l, a₁, a₂ => by
simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc]
variable [hc : Std.Commutative op]
theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by
rw [foldl_cons, hc.comm, foldl_assoc]
end
/-! ### foldlM, foldrM, mapM -/
section FoldlMFoldrM
variable {m : Type v → Type w} [Monad m]
variable [LawfulMonad m]
theorem foldrM_eq_foldr (f : α → β → m β) (b l) :
foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*]
theorem foldlM_eq_foldl (f : β → α → m β) (b l) :
List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by
suffices h :
∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l
by simp [← h (pure b)]
induction l with
| nil => intro; simp
| cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm]
end FoldlMFoldrM
/-! ### intersperse -/
@[deprecated (since := "2025-02-07")] alias intersperse_singleton := intersperse_single
@[deprecated (since := "2025-02-07")] alias intersperse_cons_cons := intersperse_cons₂
/-! ### map for partial functions -/
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) :
SizeOf.sizeOf x < SizeOf.sizeOf l := by
induction l with | nil => ?_ | cons h t ih => ?_ <;> cases hx <;> rw [cons.sizeOf_spec]
· omega
· specialize ih ‹_›
omega
/-! ### filter -/
theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) :
l.length = (l.filter f).length + (l.filter (! f ·)).length := by
simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true,
Bool.decide_eq_false]
/-! ### filterMap -/
theorem filterMap_eq_flatMap_toList (f : α → Option β) (l : List α) :
l.filterMap f = l.flatMap fun a ↦ (f a).toList := by
induction l with | nil => ?_ | cons a l ih => ?_ <;> simp [filterMap_cons]
rcases f a <;> simp [ih]
theorem filterMap_congr {f g : α → Option β} {l : List α}
(h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by
induction l <;> simp_all [filterMap_cons]
theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} :
l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where
mp := by
induction l with | nil => simp | cons a l ih => ?_
rcases ha : f a with - | b <;> simp [ha, filterMap_cons]
· intro h
simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff]
using List.length_filterMap_le f l
· rintro rfl h
exact ⟨rfl, ih h⟩
mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun filterMap_eq_map _)
/-! ### filter -/
section Filter
variable {p : α → Bool}
theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] :=
rfl
theorem filter_eq_foldr (p : α → Bool) (l : List α) :
filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by
induction l <;> simp [*, filter]; rfl
#adaptation_note /-- nightly-2024-07-27
This has to be temporarily renamed to avoid an unintentional collision.
The prime should be removed at nightly-2024-07-27. -/
@[simp]
theorem filter_subset' (l : List α) : filter p l ⊆ l :=
filter_sublist.subset
theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2
theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l :=
filter_subset' l h
theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l :=
mem_filter.2 ⟨h₁, h₂⟩
@[deprecated (since := "2025-02-07")] alias monotone_filter_left := filter_subset
variable (p)
theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄
(h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by
induction l with
| nil => rfl
| cons hd tl IH =>
by_cases hp : p hd
· rw [filter_cons_of_pos hp, filter_cons_of_pos (h _ hp)]
exact IH.cons_cons hd
· rw [filter_cons_of_neg hp]
by_cases hq : q hd
· rw [filter_cons_of_pos hq]
exact sublist_cons_of_sublist hd IH
· rw [filter_cons_of_neg hq]
exact IH
lemma map_filter {f : α → β} (hf : Injective f) (l : List α)
[DecidablePred fun b => ∃ a, p a ∧ f a = b] :
(l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by
simp [comp_def, filter_map, hf.eq_iff]
@[deprecated (since := "2025-02-07")] alias map_filter' := map_filter
lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] :
l.attach.filter p =
(l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := by
classical
refine map_injective_iff.2 Subtype.coe_injective ?_
simp [comp_def, map_filter _ Subtype.coe_injective]
lemma filter_attach (l : List α) (p : α → Bool) :
(l.attach.filter fun x => p x : List {x // x ∈ l}) =
(l.filter p).attach.map (Subtype.map id fun _ => mem_of_mem_filter) :=
map_injective_iff.2 Subtype.coe_injective <| by
simp_rw [map_map, comp_def, Subtype.map, id, ← Function.comp_apply (g := Subtype.val),
← filter_map, attach_map_subtype_val]
lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by
simp [Bool.and_comm]
@[simp]
theorem filter_true (l : List α) :
filter (fun _ => true) l = l := by induction l <;> simp [*, filter]
@[simp]
theorem filter_false (l : List α) :
filter (fun _ => false) l = [] := by induction l <;> simp [*, filter]
end Filter
/-! ### eraseP -/
section eraseP
variable {p : α → Bool}
@[simp]
theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) :
(l.eraseP p).length + 1 = l.length := by
let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa
rw [h₂, h₁, length_append, length_append]
rfl
end eraseP
/-! ### erase -/
section Erase
variable [DecidableEq α]
@[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) :
(l.erase a).length + 1 = l.length := by
rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)]
theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) :
map f (l.erase a) = (map f l).erase (f a) := by
have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff]
rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl
theorem map_foldl_erase [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (foldl List.erase l₁ l₂) = foldl (fun l a => l.erase (f a)) (map f l₁) l₂ := by
induction l₂ generalizing l₁ <;> [rfl; simp only [foldl_cons, map_erase finj, *]]
theorem erase_getElem [DecidableEq ι] {l : List ι} {i : ℕ} (hi : i < l.length) :
Perm (l.erase l[i]) (l.eraseIdx i) := by
induction l generalizing i with
| nil => simp
| cons a l IH =>
cases i with
| zero => simp
| succ i =>
have hi' : i < l.length := by simpa using hi
if ha : a = l[i] then
simpa [ha] using .trans (perm_cons_erase (getElem_mem _)) (.cons _ (IH hi'))
else
simpa [ha] using IH hi'
theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) :
(l.eraseIdx i).length + 1 = l.length := by
rw [length_eraseIdx]
split <;> omega
end Erase
/-! ### diff -/
section Diff
variable [DecidableEq α]
@[simp]
theorem map_diff [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by
simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj]
@[deprecated (since := "2025-04-10")]
alias erase_diff_erase_sublist_of_sublist := Sublist.erase_diff_erase_sublist
end Diff
section Choose
variable (p : α → Prop) [DecidablePred p] (l : List α)
theorem choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(chooseX p l hp).property
theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
end Choose
/-! ### Forall -/
section Forall
variable {p q : α → Prop} {l : List α}
@[simp]
theorem forall_cons (p : α → Prop) (x : α) : ∀ l : List α, Forall p (x :: l) ↔ p x ∧ Forall p l
| [] => (and_iff_left_of_imp fun _ ↦ trivial).symm
| _ :: _ => Iff.rfl
@[simp]
theorem forall_append {p : α → Prop} : ∀ {xs ys : List α},
Forall p (xs ++ ys) ↔ Forall p xs ∧ Forall p ys
| [] => by simp
| _ :: _ => by simp [forall_append, and_assoc]
theorem forall_iff_forall_mem : ∀ {l : List α}, Forall p l ↔ ∀ x ∈ l, p x
| [] => (iff_true_intro <| forall_mem_nil _).symm
| x :: l => by rw [forall_mem_cons, forall_cons, forall_iff_forall_mem]
theorem Forall.imp (h : ∀ x, p x → q x) : ∀ {l : List α}, Forall p l → Forall q l
| [] => id
| x :: l => by
simp only [forall_cons, and_imp]
rw [← and_imp]
exact And.imp (h x) (Forall.imp h)
@[simp]
theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by
induction l <;> simp [*]
instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ =>
decidable_of_iff' _ forall_iff_forall_mem
end Forall
/-! ### Miscellaneous lemmas -/
theorem get_attach (l : List α) (i) :
(l.attach.get i).1 = l.get ⟨i, length_attach (l := l) ▸ i.2⟩ := by simp
section Disjoint
/-- The images of disjoint lists under a partially defined map are disjoint -/
theorem disjoint_pmap {p : α → Prop} {f : ∀ a : α, p a → β} {s t : List α}
(hs : ∀ a ∈ s, p a) (ht : ∀ a ∈ t, p a)
(hf : ∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a')
(h : Disjoint s t) :
Disjoint (s.pmap f hs) (t.pmap f ht) := by
simp only [Disjoint, mem_pmap]
rintro b ⟨a, ha, rfl⟩ ⟨a', ha', ha''⟩
apply h ha
rwa [hf a a' (hs a ha) (ht a' ha') ha''.symm]
/-- The images of disjoint lists under an injective map are disjoint -/
theorem disjoint_map {f : α → β} {s t : List α} (hf : Function.Injective f)
(h : Disjoint s t) : Disjoint (s.map f) (t.map f) := by
rw [← pmap_eq_map (fun _ _ ↦ trivial), ← pmap_eq_map (fun _ _ ↦ trivial)]
exact disjoint_pmap _ _ (fun _ _ _ _ h' ↦ hf h') h
alias Disjoint.map := disjoint_map
theorem Disjoint.of_map {f : α → β} {s t : List α} (h : Disjoint (s.map f) (t.map f)) :
Disjoint s t := fun _a has hat ↦
h (mem_map_of_mem has) (mem_map_of_mem hat)
theorem Disjoint.map_iff {f : α → β} {s t : List α} (hf : Function.Injective f) :
Disjoint (s.map f) (t.map f) ↔ Disjoint s t :=
⟨fun h ↦ h.of_map, fun h ↦ h.map hf⟩
theorem Perm.disjoint_left {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l₁ l ↔ Disjoint l₂ l := by
simp_rw [List.disjoint_left, p.mem_iff]
theorem Perm.disjoint_right {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l l₁ ↔ Disjoint l l₂ := by
simp_rw [List.disjoint_right, p.mem_iff]
@[simp]
theorem disjoint_reverse_left {l₁ l₂ : List α} : Disjoint l₁.reverse l₂ ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_left
@[simp]
theorem disjoint_reverse_right {l₁ l₂ : List α} : Disjoint l₁ l₂.reverse ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_right
end Disjoint
section lookup
variable [BEq α] [LawfulBEq α]
lemma lookup_graph (f : α → β) {a : α} {as : List α} (h : a ∈ as) :
lookup a (as.map fun x => (x, f x)) = some (f a) := by
induction as with
| nil => exact (not_mem_nil h).elim
| cons a' as ih =>
by_cases ha : a = a'
· simp [ha, lookup_cons]
· simpa [lookup_cons, beq_false_of_ne ha] using ih (List.mem_of_ne_of_mem ha h)
end lookup
section range'
@[simp]
lemma range'_0 (a b : ℕ) :
range' a b 0 = replicate b a := by
induction b with
| zero => simp
| succ b ih => simp [range'_succ, ih, replicate_succ]
lemma left_le_of_mem_range' {a b s x : ℕ}
(hx : x ∈ List.range' a b s) : a ≤ x := by
obtain ⟨i, _, rfl⟩ := List.mem_range'.mp hx
exact le_add_right a (s * i)
end range'
end List
| Mathlib/Data/List/Basic.lean | 2,147 | 2,149 | |
/-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth, Frédéric Dupuis
-/
import Mathlib.Analysis.InnerProductSpace.Calculus
import Mathlib.Analysis.InnerProductSpace.Dual
import Mathlib.Analysis.InnerProductSpace.Adjoint
import Mathlib.Analysis.Calculus.LagrangeMultipliers
import Mathlib.LinearAlgebra.Eigenspace.Basic
import Mathlib.Algebra.EuclideanDomain.Basic
/-!
# The Rayleigh quotient
The Rayleigh quotient of a self-adjoint operator `T` on an inner product space `E` is the function
`fun x ↦ ⟪T x, x⟫ / ‖x‖ ^ 2`.
The main results of this file are `IsSelfAdjoint.hasEigenvector_of_isMaxOn` and
`IsSelfAdjoint.hasEigenvector_of_isMinOn`, which state that if `E` is complete, and if the
Rayleigh quotient attains its global maximum/minimum over some sphere at the point `x₀`, then `x₀`
is an eigenvector of `T`, and the `iSup`/`iInf` of `fun x ↦ ⟪T x, x⟫ / ‖x‖ ^ 2` is the corresponding
eigenvalue.
The corollaries `LinearMap.IsSymmetric.hasEigenvalue_iSup_of_finiteDimensional` and
`LinearMap.IsSymmetric.hasEigenvalue_iSup_of_finiteDimensional` state that if `E` is
finite-dimensional and nontrivial, then `T` has some (nonzero) eigenvectors with eigenvalue the
`iSup`/`iInf` of `fun x ↦ ⟪T x, x⟫ / ‖x‖ ^ 2`.
## TODO
A slightly more elaborate corollary is that if `E` is complete and `T` is a compact operator, then
`T` has some (nonzero) eigenvector with eigenvalue either `⨆ x, ⟪T x, x⟫ / ‖x‖ ^ 2` or
`⨅ x, ⟪T x, x⟫ / ‖x‖ ^ 2` (not necessarily both).
-/
variable {𝕜 : Type*} [RCLike 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
open scoped NNReal
open Module.End Metric
namespace ContinuousLinearMap
variable (T : E →L[𝕜] E)
/-- The *Rayleigh quotient* of a continuous linear map `T` (over `ℝ` or `ℂ`) at a vector `x` is
the quantity `re ⟪T x, x⟫ / ‖x‖ ^ 2`. -/
noncomputable abbrev rayleighQuotient (x : E) := T.reApplyInnerSelf x / ‖(x : E)‖ ^ 2
theorem rayleigh_smul (x : E) {c : 𝕜} (hc : c ≠ 0) :
rayleighQuotient T (c • x) = rayleighQuotient T x := by
by_cases hx : x = 0
· simp [hx]
field_simp [norm_smul, T.reApplyInnerSelf_smul]
ring
theorem image_rayleigh_eq_image_rayleigh_sphere {r : ℝ} (hr : 0 < r) :
rayleighQuotient T '' {0}ᶜ = rayleighQuotient T '' sphere 0 r := by
ext a
constructor
· rintro ⟨x, hx : x ≠ 0, hxT⟩
have : ‖x‖ ≠ 0 := by simp [hx]
let c : 𝕜 := ↑‖x‖⁻¹ * r
have : c ≠ 0 := by simp [c, hx, hr.ne']
refine ⟨c • x, ?_, ?_⟩
· field_simp [c, norm_smul, abs_of_pos hr]
· rw [T.rayleigh_smul x this]
exact hxT
· rintro ⟨x, hx, hxT⟩
exact ⟨x, ne_zero_of_mem_sphere hr.ne' ⟨x, hx⟩, hxT⟩
theorem iSup_rayleigh_eq_iSup_rayleigh_sphere {r : ℝ} (hr : 0 < r) :
⨆ x : { x : E // x ≠ 0 }, rayleighQuotient T x =
⨆ x : sphere (0 : E) r, rayleighQuotient T x :=
show ⨆ x : ({0}ᶜ : Set E), rayleighQuotient T x = _ by
simp only [← @sSup_image' _ _ _ _ (rayleighQuotient T),
T.image_rayleigh_eq_image_rayleigh_sphere hr]
theorem iInf_rayleigh_eq_iInf_rayleigh_sphere {r : ℝ} (hr : 0 < r) :
⨅ x : { x : E // x ≠ 0 }, rayleighQuotient T x =
⨅ x : sphere (0 : E) r, rayleighQuotient T x :=
show ⨅ x : ({0}ᶜ : Set E), rayleighQuotient T x = _ by
simp only [← @sInf_image' _ _ _ _ (rayleighQuotient T),
T.image_rayleigh_eq_image_rayleigh_sphere hr]
end ContinuousLinearMap
namespace IsSelfAdjoint
section Real
variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
theorem _root_.LinearMap.IsSymmetric.hasStrictFDerivAt_reApplyInnerSelf {T : F →L[ℝ] F}
(hT : (T : F →ₗ[ℝ] F).IsSymmetric) (x₀ : F) :
HasStrictFDerivAt T.reApplyInnerSelf (2 • (innerSL ℝ (T x₀))) x₀ := by
convert T.hasStrictFDerivAt.inner ℝ (hasStrictFDerivAt_id x₀) using 1
ext y
rw [ContinuousLinearMap.smul_apply, ContinuousLinearMap.comp_apply, fderivInnerCLM_apply,
ContinuousLinearMap.prod_apply, innerSL_apply, id, ContinuousLinearMap.id_apply,
hT.apply_clm x₀ y, real_inner_comm _ x₀, two_smul]
variable [CompleteSpace F] {T : F →L[ℝ] F}
theorem linearly_dependent_of_isLocalExtrOn (hT : IsSelfAdjoint T) {x₀ : F}
(hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : F) ‖x₀‖) x₀) :
∃ a b : ℝ, (a, b) ≠ 0 ∧ a • x₀ + b • T x₀ = 0 := by
have H : IsLocalExtrOn T.reApplyInnerSelf {x : F | ‖x‖ ^ 2 = ‖x₀‖ ^ 2} x₀ := by
convert hextr
ext x
simp [dist_eq_norm]
-- find Lagrange multipliers for the function `T.re_apply_inner_self` and the
-- hypersurface-defining function `fun x ↦ ‖x‖ ^ 2`
obtain ⟨a, b, h₁, h₂⟩ :=
IsLocalExtrOn.exists_multipliers_of_hasStrictFDerivAt_1d H (hasStrictFDerivAt_norm_sq x₀)
(hT.isSymmetric.hasStrictFDerivAt_reApplyInnerSelf x₀)
refine ⟨a, b, h₁, ?_⟩
apply (InnerProductSpace.toDualMap ℝ F).injective
simp only [LinearIsometry.map_add, LinearIsometry.map_smul, LinearIsometry.map_zero]
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 changed `map_smulₛₗ` into `map_smulₛₗ _`
simp only [map_smulₛₗ _, RCLike.conj_to_real]
change a • innerSL ℝ x₀ + b • innerSL ℝ (T x₀) = 0
apply smul_right_injective (F →L[ℝ] ℝ) (two_ne_zero : (2 : ℝ) ≠ 0)
simpa only [two_smul, smul_add, add_smul, add_zero] using h₂
open scoped InnerProductSpace in
theorem eq_smul_self_of_isLocalExtrOn_real (hT : IsSelfAdjoint T) {x₀ : F}
(hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : F) ‖x₀‖) x₀) :
T x₀ = T.rayleighQuotient x₀ • x₀ := by
obtain ⟨a, b, h₁, h₂⟩ := hT.linearly_dependent_of_isLocalExtrOn hextr
by_cases hx₀ : x₀ = 0
· simp [hx₀]
by_cases hb : b = 0
· have : a ≠ 0 := by simpa [hb] using h₁
refine absurd ?_ hx₀
apply smul_right_injective F this
simpa [hb] using h₂
let c : ℝ := -b⁻¹ * a
have hc : T x₀ = c • x₀ := by
have : b * (b⁻¹ * a) = a := by field_simp [mul_comm]
apply smul_right_injective F hb
simp [c, eq_neg_of_add_eq_zero_left h₂, ← mul_smul, this]
convert hc
have := congr_arg (fun x => ⟪x, x₀⟫_ℝ) hc
field_simp [inner_smul_left, real_inner_self_eq_norm_mul_norm, sq] at this ⊢
exact this
end Real
section CompleteSpace
variable [CompleteSpace E] {T : E →L[𝕜] E}
theorem eq_smul_self_of_isLocalExtrOn (hT : IsSelfAdjoint T) {x₀ : E}
(hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) :
T x₀ = (↑(T.rayleighQuotient x₀) : 𝕜) • x₀ := by
letI := InnerProductSpace.rclikeToReal 𝕜 E
let hSA := hT.isSymmetric.restrictScalars.toSelfAdjoint.prop
exact hSA.eq_smul_self_of_isLocalExtrOn_real hextr
/-- For a self-adjoint operator `T`, a local extremum of the Rayleigh quotient of `T` on a sphere
centred at the origin is an eigenvector of `T`. -/
theorem hasEigenvector_of_isLocalExtrOn (hT : IsSelfAdjoint T) {x₀ : E} (hx₀ : x₀ ≠ 0)
(hextr : IsLocalExtrOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) :
HasEigenvector (T : E →ₗ[𝕜] E) (↑(T.rayleighQuotient x₀)) x₀ := by
refine ⟨?_, hx₀⟩
rw [Module.End.mem_eigenspace_iff]
exact hT.eq_smul_self_of_isLocalExtrOn hextr
/-- For a self-adjoint operator `T`, a maximum of the Rayleigh quotient of `T` on a sphere centred
at the origin is an eigenvector of `T`, with eigenvalue the global supremum of the Rayleigh
quotient. -/
theorem hasEigenvector_of_isMaxOn (hT : IsSelfAdjoint T) {x₀ : E} (hx₀ : x₀ ≠ 0)
(hextr : IsMaxOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) :
HasEigenvector (T : E →ₗ[𝕜] E) (↑(⨆ x : { x : E // x ≠ 0 }, T.rayleighQuotient x)) x₀ := by
convert hT.hasEigenvector_of_isLocalExtrOn hx₀ (Or.inr hextr.localize)
have hx₀' : 0 < ‖x₀‖ := by simp [hx₀]
have hx₀'' : x₀ ∈ sphere (0 : E) ‖x₀‖ := by simp
rw [T.iSup_rayleigh_eq_iSup_rayleigh_sphere hx₀']
refine IsMaxOn.iSup_eq hx₀'' ?_
intro x hx
dsimp
have : ‖x‖ = ‖x₀‖ := by simpa using hx
simp only [ContinuousLinearMap.rayleighQuotient]
| rw [this]
gcongr
exact hextr hx
/-- For a self-adjoint operator `T`, a minimum of the Rayleigh quotient of `T` on a sphere centred
at the origin is an eigenvector of `T`, with eigenvalue the global infimum of the Rayleigh
quotient. -/
theorem hasEigenvector_of_isMinOn (hT : IsSelfAdjoint T) {x₀ : E} (hx₀ : x₀ ≠ 0)
(hextr : IsMinOn T.reApplyInnerSelf (sphere (0 : E) ‖x₀‖) x₀) :
HasEigenvector (T : E →ₗ[𝕜] E) (↑(⨅ x : { x : E // x ≠ 0 }, T.rayleighQuotient x)) x₀ := by
convert hT.hasEigenvector_of_isLocalExtrOn hx₀ (Or.inl hextr.localize)
have hx₀' : 0 < ‖x₀‖ := by simp [hx₀]
have hx₀'' : x₀ ∈ sphere (0 : E) ‖x₀‖ := by simp
rw [T.iInf_rayleigh_eq_iInf_rayleigh_sphere hx₀']
refine IsMinOn.iInf_eq hx₀'' ?_
| Mathlib/Analysis/InnerProductSpace/Rayleigh.lean | 191 | 205 |
/-
Copyright (c) 2020 Fox Thomson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fox Thomson, Markus Himmel
-/
import Mathlib.SetTheory.Game.Birthday
import Mathlib.SetTheory.Game.Impartial
import Mathlib.SetTheory.Nimber.Basic
/-!
# Nim and the Sprague-Grundy theorem
This file contains the definition for nim for any ordinal `o`. In the game of `nim o₁` both players
may move to `nim o₂` for any `o₂ < o₁`.
We also define a Grundy value for an impartial game `G` and prove the Sprague-Grundy theorem, that
`G` is equivalent to `nim (grundyValue G)`.
Finally, we prove that the grundy value of a sum `G + H` corresponds to the nimber sum of the
individual grundy values.
## Implementation details
The pen-and-paper definition of nim defines the possible moves of `nim o` to be `Set.Iio o`.
However, this definition does not work for us because it would make the type of nim
`Ordinal.{u} → SetTheory.PGame.{u + 1}`, which would make it impossible for us to state the
Sprague-Grundy theorem, since that requires the type of `nim` to be
`Ordinal.{u} → SetTheory.PGame.{u}`. For this reason, we instead use `o.toType` for the possible
moves. We expose `toLeftMovesNim` and `toRightMovesNim` to conveniently convert an ordinal less than
`o` into a left or right move of `nim o`, and vice versa.
-/
noncomputable section
universe u
namespace SetTheory
open scoped PGame
open Ordinal Nimber
namespace PGame
/-- The definition of single-heap nim, which can be viewed as a pile of stones where each player can
take a positive number of stones from it on their turn. -/
noncomputable def nim (o : Ordinal.{u}) : PGame.{u} :=
⟨o.toType, o.toType,
fun x => nim ((enumIsoToType o).symm x).val,
fun x => nim ((enumIsoToType o).symm x).val⟩
termination_by o
decreasing_by all_goals exact ((enumIsoToType o).symm x).prop
@[deprecated "you can use `rw [nim]` directly" (since := "2025-01-23")]
theorem nim_def (o : Ordinal) : nim o =
⟨o.toType, o.toType,
fun x => nim ((enumIsoToType o).symm x).val,
fun x => nim ((enumIsoToType o).symm x).val⟩ := by
rw [nim]
theorem leftMoves_nim (o : Ordinal) : (nim o).LeftMoves = o.toType := by rw [nim]; rfl
theorem rightMoves_nim (o : Ordinal) : (nim o).RightMoves = o.toType := by rw [nim]; rfl
theorem moveLeft_nim_hEq (o : Ordinal) :
HEq (nim o).moveLeft fun i : o.toType => nim ((enumIsoToType o).symm i) := by rw [nim]; rfl
theorem moveRight_nim_hEq (o : Ordinal) :
HEq (nim o).moveRight fun i : o.toType => nim ((enumIsoToType o).symm i) := by rw [nim]; rfl
/-- Turns an ordinal less than `o` into a left move for `nim o` and vice versa. -/
noncomputable def toLeftMovesNim {o : Ordinal} : Set.Iio o ≃ (nim o).LeftMoves :=
(enumIsoToType o).toEquiv.trans (Equiv.cast (leftMoves_nim o).symm)
/-- Turns an ordinal less than `o` into a right move for `nim o` and vice versa. -/
noncomputable def toRightMovesNim {o : Ordinal} : Set.Iio o ≃ (nim o).RightMoves :=
(enumIsoToType o).toEquiv.trans (Equiv.cast (rightMoves_nim o).symm)
@[simp]
theorem toLeftMovesNim_symm_lt {o : Ordinal} (i : (nim o).LeftMoves) :
toLeftMovesNim.symm i < o :=
(toLeftMovesNim.symm i).prop
@[simp]
theorem toRightMovesNim_symm_lt {o : Ordinal} (i : (nim o).RightMoves) :
toRightMovesNim.symm i < o :=
(toRightMovesNim.symm i).prop
@[simp]
theorem moveLeft_nim {o : Ordinal} (i) : (nim o).moveLeft i = nim (toLeftMovesNim.symm i).val :=
(congr_heq (moveLeft_nim_hEq o).symm (cast_heq _ i)).symm
@[deprecated moveLeft_nim (since := "2024-10-30")]
alias moveLeft_nim' := moveLeft_nim
theorem moveLeft_toLeftMovesNim {o : Ordinal} (i) :
(nim o).moveLeft (toLeftMovesNim i) = nim i := by
simp
@[simp]
theorem moveRight_nim {o : Ordinal} (i) : (nim o).moveRight i = nim (toRightMovesNim.symm i).val :=
(congr_heq (moveRight_nim_hEq o).symm (cast_heq _ i)).symm
@[deprecated moveRight_nim (since := "2024-10-30")]
alias moveRight_nim' := moveRight_nim
theorem moveRight_toRightMovesNim {o : Ordinal} (i) :
(nim o).moveRight (toRightMovesNim i) = nim i := by
simp
/-- A recursion principle for left moves of a nim game. -/
@[elab_as_elim]
def leftMovesNimRecOn {o : Ordinal} {P : (nim o).LeftMoves → Sort*} (i : (nim o).LeftMoves)
(H : ∀ a (H : a < o), P <| toLeftMovesNim ⟨a, H⟩) : P i := by
rw [← toLeftMovesNim.apply_symm_apply i]; apply H
/-- A recursion principle for right moves of a nim game. -/
@[elab_as_elim]
def rightMovesNimRecOn {o : Ordinal} {P : (nim o).RightMoves → Sort*} (i : (nim o).RightMoves)
(H : ∀ a (H : a < o), P <| toRightMovesNim ⟨a, H⟩) : P i := by
rw [← toRightMovesNim.apply_symm_apply i]; apply H
instance isEmpty_nim_zero_leftMoves : IsEmpty (nim 0).LeftMoves := by
rw [nim]
exact isEmpty_toType_zero
instance isEmpty_nim_zero_rightMoves : IsEmpty (nim 0).RightMoves := by
rw [nim]
exact isEmpty_toType_zero
/-- `nim 0` has exactly the same moves as `0`. -/
def nimZeroRelabelling : nim 0 ≡r 0 :=
Relabelling.isEmpty _
theorem nim_zero_equiv : nim 0 ≈ 0 :=
Equiv.isEmpty _
noncomputable instance uniqueNimOneLeftMoves : Unique (nim 1).LeftMoves :=
(Equiv.cast <| leftMoves_nim 1).unique
noncomputable instance uniqueNimOneRightMoves : Unique (nim 1).RightMoves :=
(Equiv.cast <| rightMoves_nim 1).unique
@[simp]
theorem default_nim_one_leftMoves_eq :
(default : (nim 1).LeftMoves) = @toLeftMovesNim 1 ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ :=
rfl
@[simp]
theorem default_nim_one_rightMoves_eq :
(default : (nim 1).RightMoves) = @toRightMovesNim 1 ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ :=
rfl
@[simp]
theorem toLeftMovesNim_one_symm (i) :
(@toLeftMovesNim 1).symm i = ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := by
simp [eq_iff_true_of_subsingleton]
@[simp]
theorem toRightMovesNim_one_symm (i) :
(@toRightMovesNim 1).symm i = ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := by
simp [eq_iff_true_of_subsingleton]
theorem nim_one_moveLeft (x) : (nim 1).moveLeft x = nim 0 := by simp
theorem nim_one_moveRight (x) : (nim 1).moveRight x = nim 0 := by simp
/-- `nim 1` has exactly the same moves as `star`. -/
def nimOneRelabelling : nim 1 ≡r star := by
rw [nim]
refine ⟨?_, ?_, fun i => ?_, fun j => ?_⟩
any_goals dsimp; apply Equiv.ofUnique
all_goals simpa [enumIsoToType] using nimZeroRelabelling
theorem nim_one_equiv : nim 1 ≈ star :=
nimOneRelabelling.equiv
@[simp]
theorem nim_birthday (o : Ordinal) : (nim o).birthday = o := by
induction' o using Ordinal.induction with o IH
rw [nim, birthday_def]
dsimp
rw [max_eq_right le_rfl]
convert lsub_typein o with i
exact IH _ (typein_lt_self i)
@[simp]
theorem neg_nim (o : Ordinal) : -nim o = nim o := by
induction' o using Ordinal.induction with o IH
rw [nim]; dsimp; congr <;> funext i <;> exact IH _ (Ordinal.typein_lt_self i)
instance impartial_nim (o : Ordinal) : Impartial (nim o) := by
induction' o using Ordinal.induction with o IH
rw [impartial_def, neg_nim]
refine ⟨equiv_rfl, fun i => ?_, fun i => ?_⟩ <;> simpa using IH _ (typein_lt_self _)
theorem nim_fuzzy_zero_of_ne_zero {o : Ordinal} (ho : o ≠ 0) : nim o ‖ 0 := by
rw [Impartial.fuzzy_zero_iff_lf, lf_zero_le]
use toRightMovesNim ⟨0, Ordinal.pos_iff_ne_zero.2 ho⟩
simp
@[simp]
theorem nim_add_equiv_zero_iff (o₁ o₂ : Ordinal) : (nim o₁ + nim o₂ ≈ 0) ↔ o₁ = o₂ := by
constructor
· refine not_imp_not.1 fun hne : _ ≠ _ => (Impartial.not_equiv_zero_iff (nim o₁ + nim o₂)).2 ?_
wlog h : o₁ < o₂
· exact (fuzzy_congr_left add_comm_equiv).1 (this _ _ hne.symm (hne.lt_or_lt.resolve_left h))
rw [Impartial.fuzzy_zero_iff_gf, zero_lf_le]
use toLeftMovesAdd (Sum.inr <| toLeftMovesNim ⟨_, h⟩)
· simpa using (Impartial.add_self (nim o₁)).2
· rintro rfl
exact Impartial.add_self (nim o₁)
@[simp]
theorem nim_add_fuzzy_zero_iff {o₁ o₂ : Ordinal} : nim o₁ + nim o₂ ‖ 0 ↔ o₁ ≠ o₂ := by
rw [iff_not_comm, Impartial.not_fuzzy_zero_iff, nim_add_equiv_zero_iff]
@[simp]
theorem nim_equiv_iff_eq {o₁ o₂ : Ordinal} : (nim o₁ ≈ nim o₂) ↔ o₁ = o₂ := by
rw [Impartial.equiv_iff_add_equiv_zero, nim_add_equiv_zero_iff]
/-- The Grundy value of an impartial game is recursively defined as the minimum excluded value
(the infimum of the complement) of the Grundy values of either its left or right options.
This is the ordinal which corresponds to the game of nim that the game is equivalent to.
This function takes a value in `Nimber`. This is a type synonym for the ordinals which has the same
ordering, but addition in `Nimber` is such that it corresponds to the grundy value of the addition
of games. See that file for more information on nimbers and their arithmetic. -/
noncomputable def grundyValue (G : PGame.{u}) : Nimber.{u} :=
sInf (Set.range fun i => grundyValue (G.moveLeft i))ᶜ
termination_by G
theorem grundyValue_eq_sInf_moveLeft (G : PGame) :
grundyValue G = sInf (Set.range (grundyValue ∘ G.moveLeft))ᶜ := by
rw [grundyValue]; rfl
theorem grundyValue_ne_moveLeft {G : PGame} (i : G.LeftMoves) :
grundyValue (G.moveLeft i) ≠ grundyValue G := by
conv_rhs => rw [grundyValue_eq_sInf_moveLeft]
have := csInf_mem (nonempty_of_not_bddAbove <|
Nimber.not_bddAbove_compl_of_small (Set.range fun i => grundyValue (G.moveLeft i)))
rw [Set.mem_compl_iff, Set.mem_range, not_exists] at this
exact this _
theorem le_grundyValue_of_Iio_subset_moveLeft {G : PGame} {o : Nimber}
(h : Set.Iio o ⊆ Set.range (grundyValue ∘ G.moveLeft)) : o ≤ grundyValue G := by
by_contra! ho
obtain ⟨i, hi⟩ := h ho
exact grundyValue_ne_moveLeft i hi
theorem exists_grundyValue_moveLeft_of_lt {G : PGame} {o : Nimber} (h : o < grundyValue G) :
∃ i, grundyValue (G.moveLeft i) = o := by
rw [grundyValue_eq_sInf_moveLeft] at h
by_contra ha
exact h.not_le (csInf_le' ha)
theorem grundyValue_le_of_forall_moveLeft {G : PGame} {o : Nimber}
(h : ∀ i, grundyValue (G.moveLeft i) ≠ o) : G.grundyValue ≤ o := by
contrapose! h
exact exists_grundyValue_moveLeft_of_lt h
/-- The **Sprague-Grundy theorem** states that every impartial game is equivalent to a game of nim,
namely the game of nim corresponding to the game's Grundy value. -/
theorem equiv_nim_grundyValue (G : PGame.{u}) [G.Impartial] :
G ≈ nim (toOrdinal (grundyValue G)) := by
rw [Impartial.equiv_iff_add_equiv_zero, ← Impartial.forall_leftMoves_fuzzy_iff_equiv_zero]
intro x
apply leftMoves_add_cases x <;>
intro i
· rw [add_moveLeft_inl,
← fuzzy_congr_left (add_congr_left (Equiv.symm (equiv_nim_grundyValue _))),
nim_add_fuzzy_zero_iff]
exact grundyValue_ne_moveLeft i
· rw [add_moveLeft_inr, ← Impartial.exists_left_move_equiv_iff_fuzzy_zero]
obtain ⟨j, hj⟩ := exists_grundyValue_moveLeft_of_lt <| toLeftMovesNim_symm_lt i
use toLeftMovesAdd (Sum.inl j)
rw [add_moveLeft_inl, moveLeft_nim]
exact Equiv.trans (add_congr_left (equiv_nim_grundyValue _)) (hj ▸ Impartial.add_self _)
termination_by G
theorem grundyValue_eq_iff_equiv_nim {G : PGame} [G.Impartial] {o : Nimber} :
grundyValue G = o ↔ G ≈ nim (toOrdinal o) :=
⟨by rintro rfl; exact equiv_nim_grundyValue G,
by intro h; rw [← nim_equiv_iff_eq]; exact Equiv.trans (Equiv.symm (equiv_nim_grundyValue G)) h⟩
@[simp]
theorem nim_grundyValue (o : Ordinal.{u}) : grundyValue (nim o) = ∗o :=
grundyValue_eq_iff_equiv_nim.2 PGame.equiv_rfl
theorem grundyValue_eq_iff_equiv (G H : PGame) [G.Impartial] [H.Impartial] :
grundyValue G = grundyValue H ↔ (G ≈ H) :=
grundyValue_eq_iff_equiv_nim.trans (equiv_congr_left.1 (equiv_nim_grundyValue H) _).symm
@[simp]
theorem grundyValue_zero : grundyValue 0 = 0 :=
grundyValue_eq_iff_equiv_nim.2 (Equiv.symm nim_zero_equiv)
theorem grundyValue_iff_equiv_zero (G : PGame) [G.Impartial] : grundyValue G = 0 ↔ G ≈ 0 := by
rw [← grundyValue_eq_iff_equiv, grundyValue_zero]
@[simp]
theorem grundyValue_star : grundyValue star = 1 :=
grundyValue_eq_iff_equiv_nim.2 (Equiv.symm nim_one_equiv)
@[simp]
theorem grundyValue_neg (G : PGame) [G.Impartial] : grundyValue (-G) = grundyValue G := by
rw [grundyValue_eq_iff_equiv_nim, neg_equiv_iff, neg_nim, ← grundyValue_eq_iff_equiv_nim]
theorem grundyValue_eq_sInf_moveRight (G : PGame) [G.Impartial] :
grundyValue G = sInf (Set.range (grundyValue ∘ G.moveRight))ᶜ := by
obtain ⟨l, r, L, R⟩ := G
rw [← grundyValue_neg, grundyValue_eq_sInf_moveLeft]
iterate 3 apply congr_arg
ext i
exact @grundyValue_neg _ (@Impartial.moveRight_impartial ⟨l, r, L, R⟩ _ _)
theorem grundyValue_ne_moveRight {G : PGame} [G.Impartial] (i : G.RightMoves) :
grundyValue (G.moveRight i) ≠ grundyValue G := by
convert grundyValue_ne_moveLeft (toLeftMovesNeg i) using 1 <;> simp
theorem le_grundyValue_of_Iio_subset_moveRight {G : PGame} [G.Impartial] {o : Nimber}
(h : Set.Iio o ⊆ Set.range (grundyValue ∘ G.moveRight)) : o ≤ grundyValue G := by
by_contra! ho
obtain ⟨i, hi⟩ := h ho
exact grundyValue_ne_moveRight i hi
theorem exists_grundyValue_moveRight_of_lt {G : PGame} [G.Impartial] {o : Nimber}
(h : o < grundyValue G) : ∃ i, grundyValue (G.moveRight i) = o := by
rw [← grundyValue_neg] at h
obtain ⟨i, hi⟩ := exists_grundyValue_moveLeft_of_lt h
use toLeftMovesNeg.symm i
rwa [← grundyValue_neg, ← moveLeft_neg]
theorem grundyValue_le_of_forall_moveRight {G : PGame} [G.Impartial] {o : Nimber}
(h : ∀ i, grundyValue (G.moveRight i) ≠ o) : G.grundyValue ≤ o := by
contrapose! h
exact exists_grundyValue_moveRight_of_lt h
/-- The Grundy value of the sum of two nim games equals their nimber addition. -/
theorem grundyValue_nim_add_nim (x y : Ordinal) : grundyValue (nim x + nim y) = ∗x + ∗y := by
apply (grundyValue_le_of_forall_moveLeft _).antisymm (le_grundyValue_of_Iio_subset_moveLeft _)
· intro i
apply leftMoves_add_cases i <;> intro j <;> have := (toLeftMovesNim_symm_lt j).ne
· simpa [grundyValue_nim_add_nim (toLeftMovesNim.symm j) y]
· simpa [grundyValue_nim_add_nim x (toLeftMovesNim.symm j)]
· intro k hk
obtain h | h := Nimber.lt_add_cases hk
· let a := toOrdinal (k + ∗y)
use toLeftMovesAdd (Sum.inl (toLeftMovesNim ⟨a, h⟩))
simp [a, grundyValue_nim_add_nim a y]
· let a := toOrdinal (k + ∗x)
use toLeftMovesAdd (Sum.inr (toLeftMovesNim ⟨a, h⟩))
simp [a, grundyValue_nim_add_nim x a, add_comm (∗x)]
termination_by (x, y)
theorem nim_add_nim_equiv (x y : Ordinal) :
nim x + nim y ≈ nim (toOrdinal (∗x + ∗y)) := by
rw [← grundyValue_eq_iff_equiv_nim, grundyValue_nim_add_nim]
@[simp]
theorem grundyValue_add (G H : PGame) [G.Impartial] [H.Impartial] :
grundyValue (G + H) = grundyValue G + grundyValue H := by
rw [← (grundyValue G).toOrdinal_toNimber, ← (grundyValue H).toOrdinal_toNimber,
← grundyValue_nim_add_nim, grundyValue_eq_iff_equiv]
exact add_congr (equiv_nim_grundyValue G) (equiv_nim_grundyValue H)
end PGame
end SetTheory
| Mathlib/SetTheory/Game/Nim.lean | 401 | 402 | |
/-
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.MeasurableSpace.MeasurablyGenerated
import Mathlib.MeasureTheory.Measure.NullMeasurable
import Mathlib.Order.Interval.Set.Monotone
/-!
# Measure spaces
The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with
only a few basic properties. This file provides many more properties of these objects.
This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to
be available in `MeasureSpace` (through `MeasurableSpace`).
Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the
extended nonnegative reals that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint
sets is equal to the measure of the individual sets.
Every measure can be canonically extended to an outer measure, so that it assigns values to
all subsets, not just the measurable subsets. On the other hand, a measure that is countably
additive on measurable sets can be restricted to measurable sets to obtain a measure.
In this file a measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure.
Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`.
Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding
outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the
measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0`
on the null sets.
## Main statements
* `completion` is the completion of a measure to all null measurable sets.
* `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure.
## Implementation notes
Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`.
This conveniently allows us to apply the measure to sets without proving that they are measurable.
We get countable subadditivity for all sets, but only countable additivity for measurable sets.
You often don't want to define a measure via its constructor.
Two ways that are sometimes more convenient:
* `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets
and proving the properties (1) and (2) mentioned above.
* `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that
all measurable sets in the measurable space are Carathéodory measurable.
To prove that two measures are equal, there are multiple options:
* `ext`: two measures are equal if they are equal on all measurable sets.
* `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating
the measurable sets, if the π-system contains a spanning increasing sequence of sets where the
measures take finite value (in particular the measures are σ-finite). This is a special case of
the more general `ext_of_generateFrom_of_cover`
* `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system
generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using
`C ∪ {univ}`, but is easier to work with.
A `MeasureSpace` is a class that is a measurable space with a canonical measure.
The measure is denoted `volume`.
## References
* <https://en.wikipedia.org/wiki/Measure_(mathematics)>
* <https://en.wikipedia.org/wiki/Complete_measure>
* <https://en.wikipedia.org/wiki/Almost_everywhere>
## Tags
measure, almost everywhere, measure space, completion, null set, null measurable set
-/
noncomputable section
open Set
open Filter hiding map
open Function MeasurableSpace Topology Filter ENNReal NNReal Interval MeasureTheory
open scoped symmDiff
variable {α β γ δ ι R R' : Type*}
namespace MeasureTheory
section
variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α}
instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) :=
⟨fun _s hs =>
let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs
⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩
/-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/
theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} :
(∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by
simp only [uIoc_eq_union, mem_union, or_imp, eventually_and]
theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
measure_union₀ h.nullMeasurableSet hd.aedisjoint
theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
measure_union₀' h.nullMeasurableSet hd.aedisjoint
theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s :=
measure_inter_add_diff₀ _ ht.nullMeasurableSet
theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s :=
(add_comm _ _).trans (measure_inter_add_diff s ht)
theorem measure_diff_eq_top (hs : μ s = ∞) (ht : μ t ≠ ∞) : μ (s \ t) = ∞ := by
contrapose! hs
exact ((measure_mono (subset_diff_union s t)).trans_lt
((measure_union_le _ _).trans_lt (ENNReal.add_lt_top.2 ⟨hs.lt_top, ht.lt_top⟩))).ne
theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by
rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ←
measure_inter_add_diff s ht]
ac_rfl
theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by
rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm]
lemma measure_symmDiff_eq (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) :
μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by
simpa only [symmDiff_def, sup_eq_union]
using measure_union₀ (ht.diff hs) disjoint_sdiff_sdiff.aedisjoint
lemma measure_symmDiff_le (s t u : Set α) :
μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) :=
le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u))
theorem measure_symmDiff_eq_top (hs : μ s ≠ ∞) (ht : μ t = ∞) : μ (s ∆ t) = ∞ :=
measure_mono_top subset_union_right (measure_diff_eq_top ht hs)
theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ :=
measure_add_measure_compl₀ h.nullMeasurableSet
theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable)
(hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) :
μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by
haveI := hs.toEncodable
rw [biUnion_eq_iUnion]
exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2
theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f)
(h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) :=
measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet
theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ))
(h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by
rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h]
theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint)
(h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by
rw [sUnion_eq_biUnion, measure_biUnion hs hd h]
theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α}
(hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) :
μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by
rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype]
exact measure_biUnion₀ s.countable_toSet hd hm
theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f)
(hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) :=
measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet
/-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least
the sum of the measures of the sets. -/
theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α)
{As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ)
(As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by
rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff]
intro s
simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i]
gcongr
exact iUnion_subset fun _ ↦ Subset.rfl
/-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of
the measures of the sets. -/
theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α)
{As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i))
(As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) :=
tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet)
(fun _ _ h ↦ Disjoint.aedisjoint (As_disj h))
/-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β}
(hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by
rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf]
lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) :
μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by
rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs]
/-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β}
(hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by
simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf,
Finset.set_biUnion_preimage_singleton]
@[simp] lemma sum_measure_singleton {s : Finset α} [MeasurableSingletonClass α] :
∑ x ∈ s, μ {x} = μ s := by
trans ∑ x ∈ s, μ (id ⁻¹' {x})
· simp
rw [sum_measure_preimage_singleton]
· simp
· simp
theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ :=
measure_congr <| diff_ae_eq_self.2 h
theorem measure_add_diff (hs : NullMeasurableSet s μ) (t : Set α) :
μ s + μ (t \ s) = μ (s ∪ t) := by
rw [← measure_union₀' hs disjoint_sdiff_right.aedisjoint, union_diff_self]
theorem measure_diff' (s : Set α) (hm : NullMeasurableSet t μ) (h_fin : μ t ≠ ∞) :
μ (s \ t) = μ (s ∪ t) - μ t :=
ENNReal.eq_sub_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm]
theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : NullMeasurableSet s₂ μ) (h_fin : μ s₂ ≠ ∞) :
μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h]
theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) :=
tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by
gcongr; apply inter_subset_right
/-- If the measure of the symmetric difference of two sets is finite,
then one has infinite measure if and only if the other one does. -/
theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by
suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞
from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩
intro u v hμuv hμu
by_contra! hμv
apply hμuv
rw [Set.symmDiff_def, eq_top_iff]
calc
∞ = μ u - μ v := by rw [ENNReal.sub_eq_top_iff.2 ⟨hμu, hμv⟩]
_ ≤ μ (u \ v) := le_measure_diff
_ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left
/-- If the measure of the symmetric difference of two sets is finite,
then one has finite measure if and only if the other one does. -/
theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ :=
(measure_eq_top_iff_of_symmDiff hμst).ne
theorem measure_diff_lt_of_lt_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞)
{ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by
rw [measure_diff hst hs hs']; rw [add_comm] at h
exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h
theorem measure_diff_le_iff_le_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞)
{ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by
rw [measure_diff hst hs hs', tsub_le_iff_left]
theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) :
μ s = μ t := measure_congr <|
EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff)
theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃)
(h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by
have le12 : μ s₁ ≤ μ s₂ := measure_mono h12
have le23 : μ s₂ ≤ μ s₃ := measure_mono h23
have key : μ s₃ ≤ μ s₁ :=
calc
μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)]
_ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _
_ = μ s₁ := by simp only [h_nulldiff, zero_add]
exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩
theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂)
(h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ :=
(measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1
theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂)
(h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ :=
(measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2
lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) :
μ sᶜ = μ Set.univ - μ s := by
rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs]
theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s :=
measure_compl₀ h₁.nullMeasurableSet h_fin
lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by
rw [← diff_compl, measure_diff_null']; rwa [← diff_eq]
lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by
rw [← diff_compl, measure_diff_null ht]
@[simp]
theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by
rw [ae_le_set]
refine
⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h =>
eventuallyLE_antisymm_iff.mpr
⟨by rwa [ae_le_set, union_diff_left],
HasSubset.Subset.eventuallyLE subset_union_left⟩⟩
@[simp]
theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by
rw [union_comm, union_ae_eq_left_iff_ae_subset]
theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s)
(hsm : NullMeasurableSet s μ) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by
refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩
replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁)
replace ht : μ s ≠ ∞ := h₂ ▸ ht
rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self]
/-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/
theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : NullMeasurableSet s μ)
(ht : μ t ≠ ∞) : s =ᵐ[μ] t :=
ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht
theorem measure_iUnion_congr_of_subset {ι : Sort*} [Countable ι] {s : ι → Set α} {t : ι → Set α}
(hsub : ∀ i, s i ⊆ t i) (h_le : ∀ i, μ (t i) ≤ μ (s i)) : μ (⋃ i, s i) = μ (⋃ i, t i) := by
refine le_antisymm (by gcongr; apply hsub) ?_
rcases Classical.em (∃ i, μ (t i) = ∞) with (⟨i, hi⟩ | htop)
· calc
μ (⋃ i, t i) ≤ ∞ := le_top
_ ≤ μ (s i) := hi ▸ h_le i
_ ≤ μ (⋃ i, s i) := measure_mono <| subset_iUnion _ _
push_neg at htop
set M := toMeasurable μ
have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by
refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_
· calc
μ (M (t b)) = μ (t b) := measure_toMeasurable _
_ ≤ μ (s b) := h_le b
_ ≤ μ (M (t b) ∩ M (⋃ b, s b)) :=
measure_mono <|
subset_inter ((hsub b).trans <| subset_toMeasurable _ _)
((subset_iUnion _ _).trans <| subset_toMeasurable _ _)
· measurability
· rw [measure_toMeasurable]
exact htop b
calc
μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _)
_ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm
_ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right)
_ = μ (⋃ b, s b) := measure_toMeasurable _
theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁)
(ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by
rw [union_eq_iUnion, union_eq_iUnion]
exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩)
@[simp]
theorem measure_iUnion_toMeasurable {ι : Sort*} [Countable ι] (s : ι → Set α) :
μ (⋃ i, toMeasurable μ (s i)) = μ (⋃ i, s i) :=
Eq.symm <| measure_iUnion_congr_of_subset (fun _i => subset_toMeasurable _ _) fun _i ↦
(measure_toMeasurable _).le
theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) :
μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by
haveI := hc.toEncodable
simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable]
@[simp]
theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) :=
Eq.symm <|
measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl
le_rfl
@[simp]
theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) :=
Eq.symm <|
measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _)
(measure_toMeasurable _).le
theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α}
(h : ∀ i ∈ s, NullMeasurableSet (t i) μ) (H : Set.Pairwise s (AEDisjoint μ on t)) :
(∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by
rw [← measure_biUnion_finset₀ H h]
exact measure_mono (subset_univ _)
theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ)
(H : Pairwise (AEDisjoint μ on s)) : ∑' i, μ (s i) ≤ μ (univ : Set α) := by
rw [ENNReal.tsum_eq_iSup_sum]
exact iSup_le fun s =>
sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij
/-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then
one of the intersections `s i ∩ s j` is not empty. -/
theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α}
(μ : Measure α) {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ)
(H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by
contrapose! H
apply tsum_measure_le_measure_univ hs
intro i j hij
exact (disjoint_iff_inter_eq_empty.mpr (H i j hij)).aedisjoint
/-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and
`∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/
theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α)
{s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, NullMeasurableSet (t i) μ)
(H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) :
∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by
contrapose! H
apply sum_measure_le_measure_univ h
intro i hi j hj hij
exact (disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij)).aedisjoint
/-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`,
then `s` intersects `t`. Version assuming that `t` is measurable. -/
theorem nonempty_inter_of_measure_lt_add {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α}
(ht : MeasurableSet t) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) :
(s ∩ t).Nonempty := by
rw [← Set.not_disjoint_iff_nonempty_inter]
contrapose! h
calc
μ s + μ t = μ (s ∪ t) := (measure_union h ht).symm
_ ≤ μ u := measure_mono (union_subset h's h't)
/-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`,
then `s` intersects `t`. Version assuming that `s` is measurable. -/
theorem nonempty_inter_of_measure_lt_add' {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α}
(hs : MeasurableSet s) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) :
(s ∩ t).Nonempty := by
rw [add_comm] at h
rw [inter_comm]
exact nonempty_inter_of_measure_lt_add μ hs h't h's h
/-- Continuity from below:
the measure of the union of a directed sequence of (not necessarily measurable) sets
is the supremum of the measures. -/
theorem _root_.Directed.measure_iUnion [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) :
μ (⋃ i, s i) = ⨆ i, μ (s i) := by
-- WLOG, `ι = ℕ`
rcases Countable.exists_injective_nat ι with ⟨e, he⟩
generalize ht : Function.extend e s ⊥ = t
replace hd : Directed (· ⊆ ·) t := ht ▸ hd.extend_bot he
suffices μ (⋃ n, t n) = ⨆ n, μ (t n) by
simp only [← ht, Function.apply_extend μ, ← iSup_eq_iUnion, iSup_extend_bot he,
Function.comp_def, Pi.bot_apply, bot_eq_empty, measure_empty] at this
exact this.trans (iSup_extend_bot he _)
clear! ι
-- The `≥` inequality is trivial
refine le_antisymm ?_ (iSup_le fun i ↦ measure_mono <| subset_iUnion _ _)
-- Choose `T n ⊇ t n` of the same measure, put `Td n = disjointed T`
set T : ℕ → Set α := fun n => toMeasurable μ (t n)
set Td : ℕ → Set α := disjointed T
have hm : ∀ n, MeasurableSet (Td n) := .disjointed fun n ↦ measurableSet_toMeasurable _ _
calc
μ (⋃ n, t n) = μ (⋃ n, Td n) := by rw [iUnion_disjointed, measure_iUnion_toMeasurable]
_ ≤ ∑' n, μ (Td n) := measure_iUnion_le _
_ = ⨆ I : Finset ℕ, ∑ n ∈ I, μ (Td n) := ENNReal.tsum_eq_iSup_sum
_ ≤ ⨆ n, μ (t n) := iSup_le fun I => by
rcases hd.finset_le I with ⟨N, hN⟩
calc
(∑ n ∈ I, μ (Td n)) = μ (⋃ n ∈ I, Td n) :=
(measure_biUnion_finset ((disjoint_disjointed T).set_pairwise I) fun n _ => hm n).symm
_ ≤ μ (⋃ n ∈ I, T n) := measure_mono (iUnion₂_mono fun n _hn => disjointed_subset _ _)
_ = μ (⋃ n ∈ I, t n) := measure_biUnion_toMeasurable I.countable_toSet _
_ ≤ μ (t N) := measure_mono (iUnion₂_subset hN)
_ ≤ ⨆ n, μ (t n) := le_iSup (μ ∘ t) N
/-- Continuity from below:
the measure of the union of a monotone family of sets is equal to the supremum of their measures.
The theorem assumes that the `atTop` filter on the index set is countably generated,
so it works for a family indexed by a countable type, as well as `ℝ`. -/
theorem _root_.Monotone.measure_iUnion [Preorder ι] [IsDirected ι (· ≤ ·)]
[(atTop : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Monotone s) :
μ (⋃ i, s i) = ⨆ i, μ (s i) := by
cases isEmpty_or_nonempty ι with
| inl _ => simp
| inr _ =>
rcases exists_seq_monotone_tendsto_atTop_atTop ι with ⟨x, hxm, hx⟩
rw [← hs.iUnion_comp_tendsto_atTop hx, ← Monotone.iSup_comp_tendsto_atTop _ hx]
exacts [(hs.comp hxm).directed_le.measure_iUnion, fun _ _ h ↦ measure_mono (hs h)]
theorem _root_.Antitone.measure_iUnion [Preorder ι] [IsDirected ι (· ≥ ·)]
[(atBot : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Antitone s) :
μ (⋃ i, s i) = ⨆ i, μ (s i) :=
hs.dual_left.measure_iUnion
/-- Continuity from below: the measure of the union of a sequence of
(not necessarily measurable) sets is the supremum of the measures of the partial unions. -/
theorem measure_iUnion_eq_iSup_accumulate [Preorder ι] [IsDirected ι (· ≤ ·)]
[(atTop : Filter ι).IsCountablyGenerated] {f : ι → Set α} :
μ (⋃ i, f i) = ⨆ i, μ (Accumulate f i) := by
rw [← iUnion_accumulate]
exact monotone_accumulate.measure_iUnion
theorem measure_biUnion_eq_iSup {s : ι → Set α} {t : Set ι} (ht : t.Countable)
(hd : DirectedOn ((· ⊆ ·) on s) t) : μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) := by
haveI := ht.to_subtype
rw [biUnion_eq_iUnion, hd.directed_val.measure_iUnion, ← iSup_subtype'']
/-- **Continuity from above**:
the measure of the intersection of a directed downwards countable family of measurable sets
is the infimum of the measures. -/
theorem _root_.Directed.measure_iInter [Countable ι] {s : ι → Set α}
(h : ∀ i, NullMeasurableSet (s i) μ) (hd : Directed (· ⊇ ·) s) (hfin : ∃ i, μ (s i) ≠ ∞) :
μ (⋂ i, s i) = ⨅ i, μ (s i) := by
rcases hfin with ⟨k, hk⟩
have : ∀ t ⊆ s k, μ t ≠ ∞ := fun t ht => ne_top_of_le_ne_top hk (measure_mono ht)
rw [← ENNReal.sub_sub_cancel hk (iInf_le (fun i => μ (s i)) k), ENNReal.sub_iInf, ←
ENNReal.sub_sub_cancel hk (measure_mono (iInter_subset _ k)), ←
measure_diff (iInter_subset _ k) (.iInter h) (this _ (iInter_subset _ k)),
diff_iInter, Directed.measure_iUnion]
· congr 1
refine le_antisymm (iSup_mono' fun i => ?_) (iSup_mono fun i => le_measure_diff)
rcases hd i k with ⟨j, hji, hjk⟩
use j
rw [← measure_diff hjk (h _) (this _ hjk)]
gcongr
· exact hd.mono_comp _ fun _ _ => diff_subset_diff_right
/-- **Continuity from above**:
the measure of the intersection of a monotone family of measurable sets
indexed by a type with countably generated `atBot` filter
is equal to the infimum of the measures. -/
theorem _root_.Monotone.measure_iInter [Preorder ι] [IsDirected ι (· ≥ ·)]
[(atBot : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Monotone s)
(hsm : ∀ i, NullMeasurableSet (s i) μ) (hfin : ∃ i, μ (s i) ≠ ∞) :
μ (⋂ i, s i) = ⨅ i, μ (s i) := by
refine le_antisymm (le_iInf fun i ↦ measure_mono <| iInter_subset _ _) ?_
have := hfin.nonempty
rcases exists_seq_antitone_tendsto_atTop_atBot ι with ⟨x, hxm, hx⟩
calc
⨅ i, μ (s i) ≤ ⨅ n, μ (s (x n)) := le_iInf_comp (μ ∘ s) x
_ = μ (⋂ n, s (x n)) := by
refine .symm <| (hs.comp_antitone hxm).directed_ge.measure_iInter (fun n ↦ hsm _) ?_
rcases hfin with ⟨k, hk⟩
rcases (hx.eventually_le_atBot k).exists with ⟨n, hn⟩
exact ⟨n, ne_top_of_le_ne_top hk <| measure_mono <| hs hn⟩
_ ≤ μ (⋂ i, s i) := by
refine measure_mono <| iInter_mono' fun i ↦ ?_
rcases (hx.eventually_le_atBot i).exists with ⟨n, hn⟩
exact ⟨n, hs hn⟩
/-- **Continuity from above**:
the measure of the intersection of an antitone family of measurable sets
indexed by a type with countably generated `atTop` filter
is equal to the infimum of the measures. -/
theorem _root_.Antitone.measure_iInter [Preorder ι] [IsDirected ι (· ≤ ·)]
[(atTop : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Antitone s)
(hsm : ∀ i, NullMeasurableSet (s i) μ) (hfin : ∃ i, μ (s i) ≠ ∞) :
μ (⋂ i, s i) = ⨅ i, μ (s i) :=
hs.dual_left.measure_iInter hsm hfin
/-- Continuity from above: the measure of the intersection of a sequence of
measurable sets is the infimum of the measures of the partial intersections. -/
theorem measure_iInter_eq_iInf_measure_iInter_le {α ι : Type*} {_ : MeasurableSpace α}
{μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)]
{f : ι → Set α} (h : ∀ i, NullMeasurableSet (f i) μ) (hfin : ∃ i, μ (f i) ≠ ∞) :
μ (⋂ i, f i) = ⨅ i, μ (⋂ j ≤ i, f j) := by
rw [← Antitone.measure_iInter]
· rw [iInter_comm]
exact congrArg μ <| iInter_congr fun i ↦ (biInf_const nonempty_Ici).symm
· exact fun i j h ↦ biInter_mono (Iic_subset_Iic.2 h) fun _ _ ↦ Set.Subset.rfl
· exact fun i ↦ .biInter (to_countable _) fun _ _ ↦ h _
· refine hfin.imp fun k hk ↦ ne_top_of_le_ne_top hk <| measure_mono <| iInter₂_subset k ?_
rfl
/-- Continuity from below: the measure of the union of an increasing sequence of (not necessarily
measurable) sets is the limit of the measures. -/
theorem tendsto_measure_iUnion_atTop [Preorder ι] [IsCountablyGenerated (atTop : Filter ι)]
{s : ι → Set α} (hm : Monotone s) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋃ n, s n))) := by
refine .of_neBot_imp fun h ↦ ?_
have := (atTop_neBot_iff.1 h).2
rw [hm.measure_iUnion]
exact tendsto_atTop_iSup fun n m hnm => measure_mono <| hm hnm
theorem tendsto_measure_iUnion_atBot [Preorder ι] [IsCountablyGenerated (atBot : Filter ι)]
{s : ι → Set α} (hm : Antitone s) : Tendsto (μ ∘ s) atBot (𝓝 (μ (⋃ n, s n))) :=
tendsto_measure_iUnion_atTop (ι := ιᵒᵈ) hm.dual_left
/-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable)
sets is the limit of the measures of the partial unions. -/
theorem tendsto_measure_iUnion_accumulate {α ι : Type*}
[Preorder ι] [IsCountablyGenerated (atTop : Filter ι)]
{_ : MeasurableSpace α} {μ : Measure α} {f : ι → Set α} :
Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by
refine .of_neBot_imp fun h ↦ ?_
have := (atTop_neBot_iff.1 h).2
rw [measure_iUnion_eq_iSup_accumulate]
exact tendsto_atTop_iSup fun i j hij ↦ by gcongr
/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable
sets is the limit of the measures. -/
theorem tendsto_measure_iInter_atTop [Preorder ι]
[IsCountablyGenerated (atTop : Filter ι)] {s : ι → Set α}
(hs : ∀ i, NullMeasurableSet (s i) μ) (hm : Antitone s) (hf : ∃ i, μ (s i) ≠ ∞) :
Tendsto (μ ∘ s) atTop (𝓝 (μ (⋂ n, s n))) := by
refine .of_neBot_imp fun h ↦ ?_
have := (atTop_neBot_iff.1 h).2
rw [hm.measure_iInter hs hf]
exact tendsto_atTop_iInf fun n m hnm => measure_mono <| hm hnm
/-- Continuity from above: the measure of the intersection of an increasing sequence of measurable
sets is the limit of the measures. -/
theorem tendsto_measure_iInter_atBot [Preorder ι] [IsCountablyGenerated (atBot : Filter ι)]
{s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ) (hm : Monotone s)
(hf : ∃ i, μ (s i) ≠ ∞) : Tendsto (μ ∘ s) atBot (𝓝 (μ (⋂ n, s n))) :=
tendsto_measure_iInter_atTop (ι := ιᵒᵈ) hs hm.dual_left hf
/-- Continuity from above: the measure of the intersection of a sequence of measurable
sets such that one has finite measure is the limit of the measures of the partial intersections. -/
theorem tendsto_measure_iInter_le {α ι : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[Countable ι] [Preorder ι] {f : ι → Set α} (hm : ∀ i, NullMeasurableSet (f i) μ)
(hf : ∃ i, μ (f i) ≠ ∞) :
Tendsto (fun i ↦ μ (⋂ j ≤ i, f j)) atTop (𝓝 (μ (⋂ i, f i))) := by
refine .of_neBot_imp fun hne ↦ ?_
cases atTop_neBot_iff.mp hne
rw [measure_iInter_eq_iInf_measure_iInter_le hm hf]
exact tendsto_atTop_iInf
fun i j hij ↦ measure_mono <| biInter_subset_biInter_left fun k hki ↦ le_trans hki hij
/-- Some version of continuity of a measure in the empty set using the intersection along a set of
sets. -/
theorem exists_measure_iInter_lt {α ι : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[SemilatticeSup ι] [Countable ι] {f : ι → Set α}
(hm : ∀ i, NullMeasurableSet (f i) μ) {ε : ℝ≥0∞} (hε : 0 < ε) (hfin : ∃ i, μ (f i) ≠ ∞)
(hfem : ⋂ n, f n = ∅) : ∃ m, μ (⋂ n ≤ m, f n) < ε := by
let F m := μ (⋂ n ≤ m, f n)
have hFAnti : Antitone F :=
fun i j hij => measure_mono (biInter_subset_biInter_left fun k hki => le_trans hki hij)
suffices Filter.Tendsto F Filter.atTop (𝓝 0) by
rw [@ENNReal.tendsto_atTop_zero_iff_lt_of_antitone
_ (nonempty_of_exists hfin) _ _ hFAnti] at this
exact this ε hε
have hzero : μ (⋂ n, f n) = 0 := by
simp only [hfem, measure_empty]
rw [← hzero]
exact tendsto_measure_iInter_le hm hfin
/-- The measure of the intersection of a decreasing sequence of measurable
sets indexed by a linear order with first countable topology is the limit of the measures. -/
theorem tendsto_measure_biInter_gt {ι : Type*} [LinearOrder ι] [TopologicalSpace ι]
[OrderTopology ι] [DenselyOrdered ι] [FirstCountableTopology ι] {s : ι → Set α}
{a : ι} (hs : ∀ r > a, NullMeasurableSet (s r) μ) (hm : ∀ i j, a < i → i ≤ j → s i ⊆ s j)
(hf : ∃ r > a, μ (s r) ≠ ∞) : Tendsto (μ ∘ s) (𝓝[Ioi a] a) (𝓝 (μ (⋂ r > a, s r))) := by
have : (atBot : Filter (Ioi a)).IsCountablyGenerated := by
rw [← comap_coe_Ioi_nhdsGT]
infer_instance
simp_rw [← map_coe_Ioi_atBot, tendsto_map'_iff, ← mem_Ioi, biInter_eq_iInter]
apply tendsto_measure_iInter_atBot
· rwa [Subtype.forall]
· exact fun i j h ↦ hm i j i.2 h
· simpa only [Subtype.exists, exists_prop]
theorem measure_if {x : β} {t : Set β} {s : Set α} [Decidable (x ∈ t)] :
μ (if x ∈ t then s else ∅) = indicator t (fun _ => μ s) x := by split_ifs with h <;> simp [h]
end
section OuterMeasure
variable [ms : MeasurableSpace α] {s t : Set α}
/-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are
Carathéodory measurable. -/
def OuterMeasure.toMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : Measure α :=
Measure.ofMeasurable (fun s _ => m s) m.empty fun _f hf hd =>
m.iUnion_eq_of_caratheodory (fun i => h _ (hf i)) hd
theorem le_toOuterMeasure_caratheodory (μ : Measure α) : ms ≤ μ.toOuterMeasure.caratheodory :=
fun _s hs _t => (measure_inter_add_diff _ hs).symm
@[simp]
theorem toMeasure_toOuterMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) :
(m.toMeasure h).toOuterMeasure = m.trim :=
rfl
@[simp]
theorem toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α}
(hs : MeasurableSet s) : m.toMeasure h s = m s :=
m.trim_eq hs
theorem le_toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) (s : Set α) :
m s ≤ m.toMeasure h s :=
m.le_trim s
theorem toMeasure_apply₀ (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α}
(hs : NullMeasurableSet s (m.toMeasure h)) : m.toMeasure h s = m s := by
refine le_antisymm ?_ (le_toMeasure_apply _ _ _)
rcases hs.exists_measurable_subset_ae_eq with ⟨t, hts, htm, heq⟩
calc
m.toMeasure h s = m.toMeasure h t := measure_congr heq.symm
_ = m t := toMeasure_apply m h htm
_ ≤ m s := m.mono hts
@[simp]
theorem toOuterMeasure_toMeasure {μ : Measure α} :
μ.toOuterMeasure.toMeasure (le_toOuterMeasure_caratheodory _) = μ :=
Measure.ext fun _s => μ.toOuterMeasure.trim_eq
@[simp]
theorem boundedBy_measure (μ : Measure α) : OuterMeasure.boundedBy μ = μ.toOuterMeasure :=
μ.toOuterMeasure.boundedBy_eq_self
end OuterMeasure
section
variable {m0 : MeasurableSpace α} {mβ : MeasurableSpace β} [MeasurableSpace γ]
variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α}
namespace Measure
/-- If `u` is a superset of `t` with the same (finite) measure (both sets possibly non-measurable),
then for any measurable set `s` one also has `μ (t ∩ s) = μ (u ∩ s)`. -/
theorem measure_inter_eq_of_measure_eq {s t u : Set α} (hs : MeasurableSet s) (h : μ t = μ u)
(htu : t ⊆ u) (ht_ne_top : μ t ≠ ∞) : μ (t ∩ s) = μ (u ∩ s) := by
rw [h] at ht_ne_top
refine le_antisymm (by gcongr) ?_
have A : μ (u ∩ s) + μ (u \ s) ≤ μ (t ∩ s) + μ (u \ s) :=
calc
μ (u ∩ s) + μ (u \ s) = μ u := measure_inter_add_diff _ hs
_ = μ t := h.symm
_ = μ (t ∩ s) + μ (t \ s) := (measure_inter_add_diff _ hs).symm
_ ≤ μ (t ∩ s) + μ (u \ s) := by gcongr
have B : μ (u \ s) ≠ ∞ := (lt_of_le_of_lt (measure_mono diff_subset) ht_ne_top.lt_top).ne
exact ENNReal.le_of_add_le_add_right B A
/-- The measurable superset `toMeasurable μ t` of `t` (which has the same measure as `t`)
satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (u ∩ s)`.
Here, we require that the measure of `t` is finite. The conclusion holds without this assumption
when the measure is s-finite (for example when it is σ-finite),
see `measure_toMeasurable_inter_of_sFinite`. -/
theorem measure_toMeasurable_inter {s t : Set α} (hs : MeasurableSet s) (ht : μ t ≠ ∞) :
μ (toMeasurable μ t ∩ s) = μ (t ∩ s) :=
(measure_inter_eq_of_measure_eq hs (measure_toMeasurable t).symm (subset_toMeasurable μ t)
ht).symm
/-! ### The `ℝ≥0∞`-module of measures -/
instance instZero {_ : MeasurableSpace α} : Zero (Measure α) :=
⟨{ toOuterMeasure := 0
m_iUnion := fun _f _hf _hd => tsum_zero.symm
trim_le := OuterMeasure.trim_zero.le }⟩
@[simp]
theorem zero_toOuterMeasure {_m : MeasurableSpace α} : (0 : Measure α).toOuterMeasure = 0 :=
rfl
@[simp, norm_cast]
theorem coe_zero {_m : MeasurableSpace α} : ⇑(0 : Measure α) = 0 :=
rfl
@[simp] lemma _root_.MeasureTheory.OuterMeasure.toMeasure_zero
[ms : MeasurableSpace α] (h : ms ≤ (0 : OuterMeasure α).caratheodory) :
(0 : OuterMeasure α).toMeasure h = 0 := by
ext s hs
simp [hs]
@[simp] lemma _root_.MeasureTheory.OuterMeasure.toMeasure_eq_zero {ms : MeasurableSpace α}
{μ : OuterMeasure α} (h : ms ≤ μ.caratheodory) : μ.toMeasure h = 0 ↔ μ = 0 where
mp hμ := by ext s; exact le_bot_iff.1 <| (le_toMeasure_apply _ _ _).trans_eq congr($hμ s)
mpr := by rintro rfl; simp
@[nontriviality]
lemma apply_eq_zero_of_isEmpty [IsEmpty α] {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) :
μ s = 0 := by
rw [eq_empty_of_isEmpty s, measure_empty]
instance instSubsingleton [IsEmpty α] {m : MeasurableSpace α} : Subsingleton (Measure α) :=
⟨fun μ ν => by ext1 s _; rw [apply_eq_zero_of_isEmpty, apply_eq_zero_of_isEmpty]⟩
theorem eq_zero_of_isEmpty [IsEmpty α] {_m : MeasurableSpace α} (μ : Measure α) : μ = 0 :=
Subsingleton.elim μ 0
instance instInhabited {_ : MeasurableSpace α} : Inhabited (Measure α) :=
⟨0⟩
instance instAdd {_ : MeasurableSpace α} : Add (Measure α) :=
⟨fun μ₁ μ₂ =>
{ toOuterMeasure := μ₁.toOuterMeasure + μ₂.toOuterMeasure
m_iUnion := fun s hs hd =>
show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, (μ₁ (s i) + μ₂ (s i)) by
rw [ENNReal.tsum_add, measure_iUnion hd hs, measure_iUnion hd hs]
trim_le := by rw [OuterMeasure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩
@[simp]
theorem add_toOuterMeasure {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) :
(μ₁ + μ₂).toOuterMeasure = μ₁.toOuterMeasure + μ₂.toOuterMeasure :=
rfl
@[simp, norm_cast]
theorem coe_add {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ :=
rfl
theorem add_apply {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) (s : Set α) :
(μ₁ + μ₂) s = μ₁ s + μ₂ s :=
rfl
section SMul
variable [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
variable [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞]
instance instSMul {_ : MeasurableSpace α} : SMul R (Measure α) :=
⟨fun c μ =>
{ toOuterMeasure := c • μ.toOuterMeasure
m_iUnion := fun s hs hd => by
simp only [OuterMeasure.smul_apply, coe_toOuterMeasure, ENNReal.tsum_const_smul,
measure_iUnion hd hs]
trim_le := by rw [OuterMeasure.trim_smul, μ.trimmed] }⟩
@[simp]
theorem smul_toOuterMeasure {_m : MeasurableSpace α} (c : R) (μ : Measure α) :
(c • μ).toOuterMeasure = c • μ.toOuterMeasure :=
rfl
@[simp, norm_cast]
theorem coe_smul {_m : MeasurableSpace α} (c : R) (μ : Measure α) : ⇑(c • μ) = c • ⇑μ :=
rfl
@[simp]
theorem smul_apply {_m : MeasurableSpace α} (c : R) (μ : Measure α) (s : Set α) :
(c • μ) s = c • μ s :=
rfl
instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] {_ : MeasurableSpace α} :
SMulCommClass R R' (Measure α) :=
⟨fun _ _ _ => ext fun _ _ => smul_comm _ _ _⟩
instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] {_ : MeasurableSpace α} :
IsScalarTower R R' (Measure α) :=
⟨fun _ _ _ => ext fun _ _ => smul_assoc _ _ _⟩
instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] {_ : MeasurableSpace α} :
IsCentralScalar R (Measure α) :=
⟨fun _ _ => ext fun _ _ => op_smul_eq_smul _ _⟩
end SMul
instance instNoZeroSMulDivisors [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
[NoZeroSMulDivisors R ℝ≥0∞] : NoZeroSMulDivisors R (Measure α) where
eq_zero_or_eq_zero_of_smul_eq_zero h := by simpa [Ne, ext_iff', forall_or_left] using h
instance instMulAction [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
{_ : MeasurableSpace α} : MulAction R (Measure α) :=
Injective.mulAction _ toOuterMeasure_injective smul_toOuterMeasure
instance instAddCommMonoid {_ : MeasurableSpace α} : AddCommMonoid (Measure α) :=
toOuterMeasure_injective.addCommMonoid toOuterMeasure zero_toOuterMeasure add_toOuterMeasure
fun _ _ => smul_toOuterMeasure _ _
/-- Coercion to function as an additive monoid homomorphism. -/
def coeAddHom {_ : MeasurableSpace α} : Measure α →+ Set α → ℝ≥0∞ where
toFun := (⇑)
map_zero' := coe_zero
map_add' := coe_add
@[simp]
theorem coeAddHom_apply {_ : MeasurableSpace α} (μ : Measure α) : coeAddHom μ = ⇑μ := rfl
@[simp]
theorem coe_finset_sum {_m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) :
⇑(∑ i ∈ I, μ i) = ∑ i ∈ I, ⇑(μ i) := map_sum coeAddHom μ I
theorem finset_sum_apply {m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) (s : Set α) :
(∑ i ∈ I, μ i) s = ∑ i ∈ I, μ i s := by rw [coe_finset_sum, Finset.sum_apply]
instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
{_ : MeasurableSpace α} : DistribMulAction R (Measure α) :=
Injective.distribMulAction ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩
toOuterMeasure_injective smul_toOuterMeasure
instance instModule [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
{_ : MeasurableSpace α} : Module R (Measure α) :=
Injective.module R ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩
toOuterMeasure_injective smul_toOuterMeasure
@[simp]
theorem coe_nnreal_smul_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) :
(c • μ) s = c * μ s :=
rfl
@[simp]
theorem nnreal_smul_coe_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) :
c • μ s = c * μ s := by
rfl
theorem ae_smul_measure {p : α → Prop} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
(h : ∀ᵐ x ∂μ, p x) (c : R) : ∀ᵐ x ∂c • μ, p x :=
ae_iff.2 <| by rw [smul_apply, ae_iff.1 h, ← smul_one_smul ℝ≥0∞, smul_zero]
theorem ae_smul_measure_le [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) :
ae (c • μ) ≤ ae μ := fun _ h ↦ ae_smul_measure h c
section SMulWithZero
variable {R : Type*} [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
[NoZeroSMulDivisors R ℝ≥0∞] {c : R} {p : α → Prop}
lemma ae_smul_measure_iff (hc : c ≠ 0) {μ : Measure α} : (∀ᵐ x ∂c • μ, p x) ↔ ∀ᵐ x ∂μ, p x := by
simp [ae_iff, hc]
@[simp] lemma ae_smul_measure_eq (hc : c ≠ 0) (μ : Measure α) : ae (c • μ) = ae μ := by
ext; exact ae_smul_measure_iff hc
end SMulWithZero
theorem measure_eq_left_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t)
(h'' : (μ + ν) s = (μ + ν) t) : μ s = μ t := by
refine le_antisymm (measure_mono h') ?_
have : μ t + ν t ≤ μ s + ν t :=
calc
μ t + ν t = μ s + ν s := h''.symm
_ ≤ μ s + ν t := by gcongr
apply ENNReal.le_of_add_le_add_right _ this
exact ne_top_of_le_ne_top h (le_add_left le_rfl)
theorem measure_eq_right_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t)
(h'' : (μ + ν) s = (μ + ν) t) : ν s = ν t := by
rw [add_comm] at h'' h
exact measure_eq_left_of_subset_of_measure_add_eq h h' h''
theorem measure_toMeasurable_add_inter_left {s t : Set α} (hs : MeasurableSet s)
(ht : (μ + ν) t ≠ ∞) : μ (toMeasurable (μ + ν) t ∩ s) = μ (t ∩ s) := by
refine (measure_inter_eq_of_measure_eq hs ?_ (subset_toMeasurable _ _) ?_).symm
· refine
measure_eq_left_of_subset_of_measure_add_eq ?_ (subset_toMeasurable _ _)
(measure_toMeasurable t).symm
rwa [measure_toMeasurable t]
· simp only [not_or, ENNReal.add_eq_top, Pi.add_apply, Ne, coe_add] at ht
exact ht.1
theorem measure_toMeasurable_add_inter_right {s t : Set α} (hs : MeasurableSet s)
(ht : (μ + ν) t ≠ ∞) : ν (toMeasurable (μ + ν) t ∩ s) = ν (t ∩ s) := by
rw [add_comm] at ht ⊢
exact measure_toMeasurable_add_inter_left hs ht
/-! ### The complete lattice of measures -/
/-- Measures are partially ordered. -/
instance instPartialOrder {_ : MeasurableSpace α} : PartialOrder (Measure α) where
le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s
le_refl _ _ := le_rfl
le_trans _ _ _ h₁ h₂ s := le_trans (h₁ s) (h₂ s)
le_antisymm _ _ h₁ h₂ := ext fun s _ => le_antisymm (h₁ s) (h₂ s)
theorem toOuterMeasure_le : μ₁.toOuterMeasure ≤ μ₂.toOuterMeasure ↔ μ₁ ≤ μ₂ := .rfl
theorem le_iff : μ₁ ≤ μ₂ ↔ ∀ s, MeasurableSet s → μ₁ s ≤ μ₂ s := outerMeasure_le_iff
theorem le_intro (h : ∀ s, MeasurableSet s → s.Nonempty → μ₁ s ≤ μ₂ s) : μ₁ ≤ μ₂ :=
le_iff.2 fun s hs ↦ s.eq_empty_or_nonempty.elim (by rintro rfl; simp) (h s hs)
theorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s := .rfl
theorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, MeasurableSet s ∧ μ s < ν s :=
lt_iff_le_not_le.trans <|
and_congr Iff.rfl <| by simp only [le_iff, not_forall, not_le, exists_prop]
theorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s :=
lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff', not_forall, not_le]
instance instAddLeftMono {_ : MeasurableSpace α} : AddLeftMono (Measure α) :=
⟨fun _ν _μ₁ _μ₂ hμ s => add_le_add_left (hμ s) _⟩
protected theorem le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν := fun s => le_add_left (h s)
protected theorem le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' := fun s => le_add_right (h s)
section sInf
variable {m : Set (Measure α)}
theorem sInf_caratheodory (s : Set α) (hs : MeasurableSet s) :
MeasurableSet[(sInf (toOuterMeasure '' m)).caratheodory] s := by
rw [OuterMeasure.sInf_eq_boundedBy_sInfGen]
refine OuterMeasure.boundedBy_caratheodory fun t => ?_
simp only [OuterMeasure.sInfGen, le_iInf_iff, forall_mem_image, measure_eq_iInf t,
coe_toOuterMeasure]
intro μ hμ u htu _hu
have hm : ∀ {s t}, s ⊆ t → OuterMeasure.sInfGen (toOuterMeasure '' m) s ≤ μ t := by
intro s t hst
rw [OuterMeasure.sInfGen_def, iInf_image]
exact iInf₂_le_of_le μ hμ <| measure_mono hst
rw [← measure_inter_add_diff u hs]
exact add_le_add (hm <| inter_subset_inter_left _ htu) (hm <| diff_subset_diff_left htu)
instance {_ : MeasurableSpace α} : InfSet (Measure α) :=
⟨fun m => (sInf (toOuterMeasure '' m)).toMeasure <| sInf_caratheodory⟩
theorem sInf_apply (hs : MeasurableSet s) : sInf m s = sInf (toOuterMeasure '' m) s :=
toMeasure_apply _ _ hs
private theorem measure_sInf_le (h : μ ∈ m) : sInf m ≤ μ :=
have : sInf (toOuterMeasure '' m) ≤ μ.toOuterMeasure := sInf_le (mem_image_of_mem _ h)
le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s
private theorem measure_le_sInf (h : ∀ μ' ∈ m, μ ≤ μ') : μ ≤ sInf m :=
have : μ.toOuterMeasure ≤ sInf (toOuterMeasure '' m) :=
le_sInf <| forall_mem_image.2 fun _ hμ ↦ toOuterMeasure_le.2 <| h _ hμ
le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s
instance instCompleteSemilatticeInf {_ : MeasurableSpace α} : CompleteSemilatticeInf (Measure α) :=
{ (by infer_instance : PartialOrder (Measure α)),
(by infer_instance : InfSet (Measure α)) with
sInf_le := fun _s _a => measure_sInf_le
le_sInf := fun _s _a => measure_le_sInf }
instance instCompleteLattice {_ : MeasurableSpace α} : CompleteLattice (Measure α) :=
{ completeLatticeOfCompleteSemilatticeInf (Measure α) with
top :=
{ toOuterMeasure := ⊤,
m_iUnion := by
intro f _ _
refine (measure_iUnion_le _).antisymm ?_
if hne : (⋃ i, f i).Nonempty then
rw [OuterMeasure.top_apply hne]
exact le_top
else
simp_all [Set.not_nonempty_iff_eq_empty]
trim_le := le_top },
le_top := fun _ => toOuterMeasure_le.mp le_top
bot := 0
bot_le := fun _a _s => bot_le }
end sInf
lemma inf_apply {s : Set α} (hs : MeasurableSet s) :
(μ ⊓ ν) s = sInf {m | ∃ t, m = μ (t ∩ s) + ν (tᶜ ∩ s)} := by
-- `(μ ⊓ ν) s` is defined as `⊓ (t : ℕ → Set α) (ht : s ⊆ ⋃ n, t n), ∑' n, μ (t n) ⊓ ν (t n)`
rw [← sInf_pair, Measure.sInf_apply hs, OuterMeasure.sInf_apply
(image_nonempty.2 <| insert_nonempty μ {ν})]
refine le_antisymm (le_sInf fun m ⟨t, ht₁⟩ ↦ ?_) (le_iInf₂ fun t' ht' ↦ ?_)
· subst ht₁
-- We first show `(μ ⊓ ν) s ≤ μ (t ∩ s) + ν (tᶜ ∩ s)` for any `t : Set α`
-- For this, define the sequence `t' : ℕ → Set α` where `t' 0 = t ∩ s`, `t' 1 = tᶜ ∩ s` and
-- `∅` otherwise. Then, we have by construction
-- `(μ ⊓ ν) s ≤ ∑' n, μ (t' n) ⊓ ν (t' n) ≤ μ (t' 0) + ν (t' 1) = μ (t ∩ s) + ν (tᶜ ∩ s)`.
set t' : ℕ → Set α := fun n ↦ if n = 0 then t ∩ s else if n = 1 then tᶜ ∩ s else ∅ with ht'
refine (iInf₂_le t' fun x hx ↦ ?_).trans ?_
· by_cases hxt : x ∈ t
· refine mem_iUnion.2 ⟨0, ?_⟩
simp [hx, hxt]
· refine mem_iUnion.2 ⟨1, ?_⟩
simp [hx, hxt]
· simp only [iInf_image, coe_toOuterMeasure, iInf_pair]
rw [tsum_eq_add_tsum_ite 0, tsum_eq_add_tsum_ite 1, if_neg zero_ne_one.symm,
ENNReal.summable.tsum_eq_zero_iff.2 _, add_zero]
· exact add_le_add (inf_le_left.trans <| by simp [ht']) (inf_le_right.trans <| by simp [ht'])
· simp only [ite_eq_left_iff]
intro n hn₁ hn₀
simp only [ht', if_neg hn₀, if_neg hn₁, measure_empty, iInf_pair, le_refl, inf_of_le_left]
· simp only [iInf_image, coe_toOuterMeasure, iInf_pair]
-- Conversely, fixing `t' : ℕ → Set α` such that `s ⊆ ⋃ n, t' n`, we construct `t : Set α`
-- for which `μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n, μ (t' n) ⊓ ν (t' n)`.
-- Denoting `I := {n | μ (t' n) ≤ ν (t' n)}`, we set `t = ⋃ n ∈ I, t' n`.
-- Clearly `μ (t ∩ s) ≤ ∑' n ∈ I, μ (t' n)` and `ν (tᶜ ∩ s) ≤ ∑' n ∉ I, ν (t' n)`, so
-- `μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n ∈ I, μ (t' n) + ∑' n ∉ I, ν (t' n)`
-- where the RHS equals `∑' n, μ (t' n) ⊓ ν (t' n)` by the choice of `I`.
set t := ⋃ n ∈ {k : ℕ | μ (t' k) ≤ ν (t' k)}, t' n with ht
suffices hadd : μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n, μ (t' n) ⊓ ν (t' n) by
exact le_trans (sInf_le ⟨t, rfl⟩) hadd
have hle₁ : μ (t ∩ s) ≤ ∑' (n : {k | μ (t' k) ≤ ν (t' k)}), μ (t' n) :=
(measure_mono inter_subset_left).trans <| measure_biUnion_le _ (to_countable _) _
have hcap : tᶜ ∩ s ⊆ ⋃ n ∈ {k | ν (t' k) < μ (t' k)}, t' n := by
simp_rw [ht, compl_iUnion]
refine fun x ⟨hx₁, hx₂⟩ ↦ mem_iUnion₂.2 ?_
obtain ⟨i, hi⟩ := mem_iUnion.1 <| ht' hx₂
refine ⟨i, ?_, hi⟩
by_contra h
simp only [mem_setOf_eq, not_lt] at h
exact mem_iInter₂.1 hx₁ i h hi
have hle₂ : ν (tᶜ ∩ s) ≤ ∑' (n : {k | ν (t' k) < μ (t' k)}), ν (t' n) :=
(measure_mono hcap).trans (measure_biUnion_le ν (to_countable {k | ν (t' k) < μ (t' k)}) _)
refine (add_le_add hle₁ hle₂).trans ?_
have heq : {k | μ (t' k) ≤ ν (t' k)} ∪ {k | ν (t' k) < μ (t' k)} = univ := by
ext k; simp [le_or_lt]
conv in ∑' (n : ℕ), μ (t' n) ⊓ ν (t' n) => rw [← tsum_univ, ← heq]
rw [ENNReal.summable.tsum_union_disjoint (f := fun n ↦ μ (t' n) ⊓ ν (t' n)) ?_ ENNReal.summable]
· refine add_le_add (tsum_congr ?_).le (tsum_congr ?_).le
· rw [Subtype.forall]
intro n hn; simpa
· rw [Subtype.forall]
intro n hn
rw [mem_setOf_eq] at hn
simp [le_of_lt hn]
· rw [Set.disjoint_iff]
rintro k ⟨hk₁, hk₂⟩
rw [mem_setOf_eq] at hk₁ hk₂
exact False.elim <| hk₂.not_le hk₁
@[simp]
theorem _root_.MeasureTheory.OuterMeasure.toMeasure_top :
(⊤ : OuterMeasure α).toMeasure (by rw [OuterMeasure.top_caratheodory]; exact le_top) =
(⊤ : Measure α) :=
toOuterMeasure_toMeasure (μ := ⊤)
@[simp]
theorem toOuterMeasure_top {_ : MeasurableSpace α} :
(⊤ : Measure α).toOuterMeasure = (⊤ : OuterMeasure α) :=
rfl
@[simp]
theorem top_add : ⊤ + μ = ⊤ :=
top_unique <| Measure.le_add_right le_rfl
@[simp]
theorem add_top : μ + ⊤ = ⊤ :=
top_unique <| Measure.le_add_left le_rfl
protected theorem zero_le {_m0 : MeasurableSpace α} (μ : Measure α) : 0 ≤ μ :=
bot_le
theorem nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 :=
μ.zero_le.le_iff_eq
@[simp]
theorem measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 :=
⟨fun h => bot_unique fun s => (h ▸ measure_mono (subset_univ s) : μ s ≤ 0), fun h =>
h.symm ▸ rfl⟩
theorem measure_univ_ne_zero : μ univ ≠ 0 ↔ μ ≠ 0 :=
measure_univ_eq_zero.not
instance [NeZero μ] : NeZero (μ univ) := ⟨measure_univ_ne_zero.2 <| NeZero.ne μ⟩
@[simp]
theorem measure_univ_pos : 0 < μ univ ↔ μ ≠ 0 :=
pos_iff_ne_zero.trans measure_univ_ne_zero
lemma nonempty_of_neZero (μ : Measure α) [NeZero μ] : Nonempty α :=
(isEmpty_or_nonempty α).resolve_left fun h ↦ by
simpa [eq_empty_of_isEmpty] using NeZero.ne (μ univ)
section Sum
variable {f : ι → Measure α}
/-- Sum of an indexed family of measures. -/
noncomputable def sum (f : ι → Measure α) : Measure α :=
(OuterMeasure.sum fun i => (f i).toOuterMeasure).toMeasure <|
le_trans (le_iInf fun _ => le_toOuterMeasure_caratheodory _)
(OuterMeasure.le_sum_caratheodory _)
theorem le_sum_apply (f : ι → Measure α) (s : Set α) : ∑' i, f i s ≤ sum f s :=
le_toMeasure_apply _ _ _
@[simp]
theorem sum_apply (f : ι → Measure α) {s : Set α} (hs : MeasurableSet s) :
sum f s = ∑' i, f i s :=
toMeasure_apply _ _ hs
theorem sum_apply₀ (f : ι → Measure α) {s : Set α} (hs : NullMeasurableSet s (sum f)) :
sum f s = ∑' i, f i s := by
apply le_antisymm ?_ (le_sum_apply _ _)
rcases hs.exists_measurable_subset_ae_eq with ⟨t, ts, t_meas, ht⟩
calc
sum f s = sum f t := measure_congr ht.symm
_ = ∑' i, f i t := sum_apply _ t_meas
_ ≤ ∑' i, f i s := ENNReal.tsum_le_tsum fun i ↦ measure_mono ts
/-! For the next theorem, the countability assumption is necessary. For a counterexample, consider
an uncountable space, with a distinguished point `x₀`, and the sigma-algebra made of countable sets
not containing `x₀`, and their complements. All points but `x₀` are measurable.
Consider the sum of the Dirac masses at points different from `x₀`, and `s = {x₀}`. For any Dirac
mass `δ_x`, we have `δ_x (x₀) = 0`, so `∑' x, δ_x (x₀) = 0`. On the other hand, the measure
`sum δ_x` gives mass one to each point different from `x₀`, so it gives infinite mass to any
measurable set containing `x₀` (as such a set is uncountable), and by outer regularity one gets
`sum δ_x {x₀} = ∞`.
-/
theorem sum_apply_of_countable [Countable ι] (f : ι → Measure α) (s : Set α) :
sum f s = ∑' i, f i s := by
apply le_antisymm ?_ (le_sum_apply _ _)
rcases exists_measurable_superset_forall_eq f s with ⟨t, hst, htm, ht⟩
calc
sum f s ≤ sum f t := measure_mono hst
_ = ∑' i, f i t := sum_apply _ htm
_ = ∑' i, f i s := by simp [ht]
theorem le_sum (μ : ι → Measure α) (i : ι) : μ i ≤ sum μ :=
le_iff.2 fun s hs ↦ by simpa only [sum_apply μ hs] using ENNReal.le_tsum i
@[simp]
theorem sum_apply_eq_zero [Countable ι] {μ : ι → Measure α} {s : Set α} :
sum μ s = 0 ↔ ∀ i, μ i s = 0 := by
simp [sum_apply_of_countable]
theorem sum_apply_eq_zero' {μ : ι → Measure α} {s : Set α} (hs : MeasurableSet s) :
sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [hs]
@[simp] lemma sum_eq_zero : sum f = 0 ↔ ∀ i, f i = 0 := by
simp +contextual [Measure.ext_iff, forall_swap (α := ι)]
@[simp]
lemma sum_zero : Measure.sum (fun (_ : ι) ↦ (0 : Measure α)) = 0 := by
ext s hs
simp [Measure.sum_apply _ hs]
theorem sum_sum {ι' : Type*} (μ : ι → ι' → Measure α) :
(sum fun n => sum (μ n)) = sum (fun (p : ι × ι') ↦ μ p.1 p.2) := by
ext1 s hs
simp [sum_apply _ hs, ENNReal.tsum_prod']
theorem sum_comm {ι' : Type*} (μ : ι → ι' → Measure α) :
(sum fun n => sum (μ n)) = sum fun m => sum fun n => μ n m := by
ext1 s hs
simp_rw [sum_apply _ hs]
rw [ENNReal.tsum_comm]
theorem ae_sum_iff [Countable ι] {μ : ι → Measure α} {p : α → Prop} :
(∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x :=
sum_apply_eq_zero
theorem ae_sum_iff' {μ : ι → Measure α} {p : α → Prop} (h : MeasurableSet { x | p x }) :
(∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x :=
sum_apply_eq_zero' h.compl
@[simp]
theorem sum_fintype [Fintype ι] (μ : ι → Measure α) : sum μ = ∑ i, μ i := by
ext1 s hs
simp only [sum_apply, finset_sum_apply, hs, tsum_fintype]
theorem sum_coe_finset (s : Finset ι) (μ : ι → Measure α) :
(sum fun i : s => μ i) = ∑ i ∈ s, μ i := by rw [sum_fintype, Finset.sum_coe_sort s μ]
@[simp]
theorem ae_sum_eq [Countable ι] (μ : ι → Measure α) : ae (sum μ) = ⨆ i, ae (μ i) :=
Filter.ext fun _ => ae_sum_iff.trans mem_iSup.symm
theorem sum_bool (f : Bool → Measure α) : sum f = f true + f false := by
rw [sum_fintype, Fintype.sum_bool]
theorem sum_cond (μ ν : Measure α) : (sum fun b => cond b μ ν) = μ + ν :=
sum_bool _
@[simp]
theorem sum_of_isEmpty [IsEmpty ι] (μ : ι → Measure α) : sum μ = 0 := by
rw [← measure_univ_eq_zero, sum_apply _ MeasurableSet.univ, tsum_empty]
theorem sum_add_sum_compl (s : Set ι) (μ : ι → Measure α) :
((sum fun i : s => μ i) + sum fun i : ↥sᶜ => μ i) = sum μ := by
ext1 t ht
simp only [add_apply, sum_apply _ ht]
exact ENNReal.summable.tsum_add_tsum_compl (f := fun i => μ i t) ENNReal.summable
theorem sum_congr {μ ν : ℕ → Measure α} (h : ∀ n, μ n = ν n) : sum μ = sum ν :=
congr_arg sum (funext h)
theorem sum_add_sum {ι : Type*} (μ ν : ι → Measure α) : sum μ + sum ν = sum fun n => μ n + ν n := by
ext1 s hs
simp only [add_apply, sum_apply _ hs, Pi.add_apply, coe_add,
ENNReal.summable.tsum_add ENNReal.summable]
@[simp] lemma sum_comp_equiv {ι ι' : Type*} (e : ι' ≃ ι) (m : ι → Measure α) :
sum (m ∘ e) = sum m := by
ext s hs
simpa [hs, sum_apply] using e.tsum_eq (fun n ↦ m n s)
@[simp] lemma sum_extend_zero {ι ι' : Type*} {f : ι → ι'} (hf : Injective f) (m : ι → Measure α) :
sum (Function.extend f m 0) = sum m := by
ext s hs
simp [*, Function.apply_extend (fun μ : Measure α ↦ μ s)]
end Sum
/-! ### The `cofinite` filter -/
/-- The filter of sets `s` such that `sᶜ` has finite measure. -/
def cofinite {m0 : MeasurableSpace α} (μ : Measure α) : Filter α :=
comk (μ · < ∞) (by simp) (fun _ ht _ hs ↦ (measure_mono hs).trans_lt ht) fun s hs t ht ↦
(measure_union_le s t).trans_lt <| ENNReal.add_lt_top.2 ⟨hs, ht⟩
theorem mem_cofinite : s ∈ μ.cofinite ↔ μ sᶜ < ∞ :=
Iff.rfl
theorem compl_mem_cofinite : sᶜ ∈ μ.cofinite ↔ μ s < ∞ := by rw [mem_cofinite, compl_compl]
theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in μ.cofinite, p x) ↔ μ { x | ¬p x } < ∞ :=
Iff.rfl
instance cofinite.instIsMeasurablyGenerated : IsMeasurablyGenerated μ.cofinite where
exists_measurable_subset s hs := by
refine ⟨(toMeasurable μ sᶜ)ᶜ, ?_, (measurableSet_toMeasurable _ _).compl, ?_⟩
· rwa [compl_mem_cofinite, measure_toMeasurable]
· rw [compl_subset_comm]
apply subset_toMeasurable
end Measure
open Measure
open MeasureTheory
protected theorem _root_.AEMeasurable.nullMeasurable {f : α → β} (h : AEMeasurable f μ) :
NullMeasurable f μ :=
let ⟨_g, hgm, hg⟩ := h; hgm.nullMeasurable.congr hg.symm
lemma _root_.AEMeasurable.nullMeasurableSet_preimage {f : α → β} {s : Set β}
(hf : AEMeasurable f μ) (hs : MeasurableSet s) : NullMeasurableSet (f ⁻¹' s) μ :=
hf.nullMeasurable hs
@[simp]
theorem ae_eq_bot : ae μ = ⊥ ↔ μ = 0 := by
rw [← empty_mem_iff_bot, mem_ae_iff, compl_empty, measure_univ_eq_zero]
@[simp]
theorem ae_neBot : (ae μ).NeBot ↔ μ ≠ 0 :=
neBot_iff.trans (not_congr ae_eq_bot)
instance Measure.ae.neBot [NeZero μ] : (ae μ).NeBot := ae_neBot.2 <| NeZero.ne μ
@[simp]
theorem ae_zero {_m0 : MeasurableSpace α} : ae (0 : Measure α) = ⊥ :=
ae_eq_bot.2 rfl
section Intervals
theorem biSup_measure_Iic [Preorder α] {s : Set α} (hsc : s.Countable)
(hst : ∀ x : α, ∃ y ∈ s, x ≤ y) (hdir : DirectedOn (· ≤ ·) s) :
⨆ x ∈ s, μ (Iic x) = μ univ := by
rw [← measure_biUnion_eq_iSup hsc]
· congr
simp only [← bex_def] at hst
exact iUnion₂_eq_univ_iff.2 hst
· exact directedOn_iff_directed.2 (hdir.directed_val.mono_comp _ fun x y => Iic_subset_Iic.2)
theorem tendsto_measure_Ico_atTop [Preorder α] [NoMaxOrder α]
[(atTop : Filter α).IsCountablyGenerated] (μ : Measure α) (a : α) :
Tendsto (fun x => μ (Ico a x)) atTop (𝓝 (μ (Ici a))) := by
rw [← iUnion_Ico_right]
exact tendsto_measure_iUnion_atTop (antitone_const.Ico monotone_id)
theorem tendsto_measure_Ioc_atBot [Preorder α] [NoMinOrder α]
[(atBot : Filter α).IsCountablyGenerated] (μ : Measure α) (a : α) :
Tendsto (fun x => μ (Ioc x a)) atBot (𝓝 (μ (Iic a))) := by
rw [← iUnion_Ioc_left]
exact tendsto_measure_iUnion_atBot (monotone_id.Ioc antitone_const)
theorem tendsto_measure_Iic_atTop [Preorder α] [(atTop : Filter α).IsCountablyGenerated]
(μ : Measure α) : Tendsto (fun x => μ (Iic x)) atTop (𝓝 (μ univ)) := by
rw [← iUnion_Iic]
exact tendsto_measure_iUnion_atTop monotone_Iic
theorem tendsto_measure_Ici_atBot [Preorder α] [(atBot : Filter α).IsCountablyGenerated]
(μ : Measure α) : Tendsto (fun x => μ (Ici x)) atBot (𝓝 (μ univ)) :=
tendsto_measure_Iic_atTop (α := αᵒᵈ) μ
variable [PartialOrder α] {a b : α}
theorem Iio_ae_eq_Iic' (ha : μ {a} = 0) : Iio a =ᵐ[μ] Iic a := by
rw [← Iic_diff_right, diff_ae_eq_self, measure_mono_null Set.inter_subset_right ha]
theorem Ioi_ae_eq_Ici' (ha : μ {a} = 0) : Ioi a =ᵐ[μ] Ici a :=
Iio_ae_eq_Iic' (α := αᵒᵈ) ha
theorem Ioo_ae_eq_Ioc' (hb : μ {b} = 0) : Ioo a b =ᵐ[μ] Ioc a b :=
(ae_eq_refl _).inter (Iio_ae_eq_Iic' hb)
theorem Ioc_ae_eq_Icc' (ha : μ {a} = 0) : Ioc a b =ᵐ[μ] Icc a b :=
(Ioi_ae_eq_Ici' ha).inter (ae_eq_refl _)
theorem Ioo_ae_eq_Ico' (ha : μ {a} = 0) : Ioo a b =ᵐ[μ] Ico a b :=
(Ioi_ae_eq_Ici' ha).inter (ae_eq_refl _)
theorem Ioo_ae_eq_Icc' (ha : μ {a} = 0) (hb : μ {b} = 0) : Ioo a b =ᵐ[μ] Icc a b :=
(Ioi_ae_eq_Ici' ha).inter (Iio_ae_eq_Iic' hb)
theorem Ico_ae_eq_Icc' (hb : μ {b} = 0) : Ico a b =ᵐ[μ] Icc a b :=
(ae_eq_refl _).inter (Iio_ae_eq_Iic' hb)
theorem Ico_ae_eq_Ioc' (ha : μ {a} = 0) (hb : μ {b} = 0) : Ico a b =ᵐ[μ] Ioc a b :=
(Ioo_ae_eq_Ico' ha).symm.trans (Ioo_ae_eq_Ioc' hb)
end Intervals
end
end MeasureTheory
end
| Mathlib/MeasureTheory/Measure/MeasureSpace.lean | 1,844 | 1,857 | |
/-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Algebra.GroupWithZero.Action.Defs
import Mathlib.Algebra.Order.AddGroupWithTop
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Algebra.Ring.Defs
import Mathlib.Order.Hom.Basic
/-!
# Tropical algebraic structures
This file defines algebraic structures of the (min-)tropical numbers, up to the tropical semiring.
Some basic lemmas about conversion from the base type `R` to `Tropical R` are provided, as
well as the expected implementations of tropical addition and tropical multiplication.
## Main declarations
* `Tropical R`: The type synonym of the tropical interpretation of `R`.
If `[LinearOrder R]`, then addition on `R` is via `min`.
* `Semiring (Tropical R)`: A `LinearOrderedAddCommMonoidWithTop R`
induces a `Semiring (Tropical R)`. If one solely has `[LinearOrderedAddCommMonoid R]`,
then the "tropicalization of `R`" would be `Tropical (WithTop R)`.
## Implementation notes
The tropical structure relies on `Top` and `min`. For the max-tropical numbers, use
`OrderDual R`.
Inspiration was drawn from the implementation of `Additive`/`Multiplicative`/`Opposite`,
where a type synonym is created with some barebones API, and quickly made irreducible.
Algebraic structures are provided with as few typeclass assumptions as possible, even though
most references rely on `Semiring (Tropical R)` for building up the whole theory.
## References followed
* https://arxiv.org/pdf/math/0408099.pdf
* https://www.mathenjeans.fr/sites/default/files/sujets/tropical_geometry_-_casagrande.pdf
-/
assert_not_exists Nat.instMulOneClass
universe u v
variable (R : Type u)
/-- The tropicalization of a type `R`. -/
def Tropical : Type u :=
R
variable {R}
namespace Tropical
/-- Reinterpret `x : R` as an element of `Tropical R`.
See `Tropical.tropEquiv` for the equivalence.
-/
def trop : R → Tropical R :=
id
/-- Reinterpret `x : Tropical R` as an element of `R`.
See `Tropical.tropEquiv` for the equivalence. -/
@[pp_nodot]
def untrop : Tropical R → R :=
id
theorem trop_injective : Function.Injective (trop : R → Tropical R) := fun _ _ => id
theorem untrop_injective : Function.Injective (untrop : Tropical R → R) := fun _ _ => id
@[simp]
theorem trop_inj_iff (x y : R) : trop x = trop y ↔ x = y :=
Iff.rfl
@[simp]
theorem untrop_inj_iff (x y : Tropical R) : untrop x = untrop y ↔ x = y :=
Iff.rfl
@[simp]
theorem trop_untrop (x : Tropical R) : trop (untrop x) = x :=
rfl
@[simp]
theorem untrop_trop (x : R) : untrop (trop x) = x :=
rfl
attribute [irreducible] Tropical
theorem leftInverse_trop : Function.LeftInverse (trop : R → Tropical R) untrop :=
trop_untrop
theorem rightInverse_trop : Function.RightInverse (trop : R → Tropical R) untrop :=
untrop_trop
/-- Reinterpret `x : R` as an element of `Tropical R`.
See `Tropical.tropOrderIso` for the order-preserving equivalence. -/
def tropEquiv : R ≃ Tropical R where
toFun := trop
invFun := untrop
left_inv := untrop_trop
right_inv := trop_untrop
@[simp]
theorem tropEquiv_coe_fn : (tropEquiv : R → Tropical R) = trop :=
rfl
@[simp]
theorem tropEquiv_symm_coe_fn : (tropEquiv.symm : Tropical R → R) = untrop :=
rfl
theorem trop_eq_iff_eq_untrop {x : R} {y} : trop x = y ↔ x = untrop y :=
tropEquiv.apply_eq_iff_eq_symm_apply
theorem untrop_eq_iff_eq_trop {x} {y : R} : untrop x = y ↔ x = trop y :=
tropEquiv.symm.apply_eq_iff_eq_symm_apply
theorem injective_trop : Function.Injective (trop : R → Tropical R) :=
tropEquiv.injective
theorem injective_untrop : Function.Injective (untrop : Tropical R → R) :=
tropEquiv.symm.injective
theorem surjective_trop : Function.Surjective (trop : R → Tropical R) :=
tropEquiv.surjective
theorem surjective_untrop : Function.Surjective (untrop : Tropical R → R) :=
tropEquiv.symm.surjective
instance [Inhabited R] : Inhabited (Tropical R) :=
⟨trop default⟩
/-- Recursing on an `x' : Tropical R` is the same as recursing on an `x : R` reinterpreted
as a term of `Tropical R` via `trop x`. -/
@[simp]
def tropRec {F : Tropical R → Sort v} (h : ∀ X, F (trop X)) : ∀ X, F X := fun X => h (untrop X)
instance [DecidableEq R] : DecidableEq (Tropical R) := fun _ _ =>
decidable_of_iff _ injective_untrop.eq_iff
section Order
instance instLETropical [LE R] : LE (Tropical R) where le x y := untrop x ≤ untrop y
@[simp]
theorem untrop_le_iff [LE R] {x y : Tropical R} : untrop x ≤ untrop y ↔ x ≤ y :=
Iff.rfl
instance decidableLE [LE R] [DecidableLE R] : DecidableLE (Tropical R) := fun x y =>
‹DecidableLE R› (untrop x) (untrop y)
instance instLTTropical [LT R] : LT (Tropical R) where lt x y := untrop x < untrop y
@[simp]
theorem untrop_lt_iff [LT R] {x y : Tropical R} : untrop x < untrop y ↔ x < y :=
Iff.rfl
instance decidableLT [LT R] [DecidableLT R] : DecidableLT (Tropical R) := fun x y =>
‹DecidableLT R› (untrop x) (untrop y)
instance instPreorderTropical [Preorder R] : Preorder (Tropical R) :=
{ instLETropical, instLTTropical with
le_refl := fun x => le_refl (untrop x)
le_trans := fun _ _ _ h h' => le_trans (α := R) h h'
lt_iff_le_not_le := fun _ _ => lt_iff_le_not_le (α := R) }
/-- Reinterpret `x : R` as an element of `Tropical R`, preserving the order. -/
def tropOrderIso [Preorder R] : R ≃o Tropical R :=
{ tropEquiv with map_rel_iff' := untrop_le_iff }
@[simp]
theorem tropOrderIso_coe_fn [Preorder R] : (tropOrderIso : R → Tropical R) = trop :=
rfl
@[simp]
theorem tropOrderIso_symm_coe_fn [Preorder R] : (tropOrderIso.symm : Tropical R → R) = untrop :=
rfl
theorem trop_monotone [Preorder R] : Monotone (trop : R → Tropical R) := fun _ _ => id
theorem untrop_monotone [Preorder R] : Monotone (untrop : Tropical R → R) := fun _ _ => id
instance instPartialOrderTropical [PartialOrder R] : PartialOrder (Tropical R) :=
{ instPreorderTropical with le_antisymm := fun _ _ h h' => untrop_injective (le_antisymm h h') }
instance instZeroTropical [Top R] : Zero (Tropical R) :=
⟨trop ⊤⟩
instance instTopTropical [Top R] : Top (Tropical R) :=
⟨0⟩
@[simp]
theorem untrop_zero [Top R] : untrop (0 : Tropical R) = ⊤ :=
rfl
@[simp]
theorem trop_top [Top R] : trop (⊤ : R) = 0 :=
rfl
@[simp]
theorem trop_coe_ne_zero (x : R) : trop (x : WithTop R) ≠ 0 :=
nofun
@[simp]
theorem zero_ne_trop_coe (x : R) : (0 : Tropical (WithTop R)) ≠ trop x :=
nofun
@[simp]
theorem le_zero [LE R] [OrderTop R] (x : Tropical R) : x ≤ 0 :=
le_top (α := R)
instance [LE R] [OrderTop R] : OrderTop (Tropical R) :=
{ instTopTropical with le_top := fun _ => le_top (α := R) }
variable [LinearOrder R]
/-- Tropical addition is the minimum of two underlying elements of `R`. -/
instance : Add (Tropical R) :=
⟨fun x y => trop (min (untrop x) (untrop y))⟩
instance instAddCommSemigroupTropical : AddCommSemigroup (Tropical R) where
add := (· + ·)
add_assoc _ _ _ := untrop_injective (min_assoc _ _ _)
add_comm _ _ := untrop_injective (min_comm _ _)
@[simp]
theorem untrop_add (x y : Tropical R) : untrop (x + y) = min (untrop x) (untrop y) :=
rfl
@[simp]
theorem trop_min (x y : R) : trop (min x y) = trop x + trop y :=
rfl
@[simp]
theorem trop_inf (x y : R) : trop (x ⊓ y) = trop x + trop y :=
rfl
theorem trop_add_def (x y : Tropical R) : x + y = trop (min (untrop x) (untrop y)) :=
rfl
instance instLinearOrderTropical : LinearOrder (Tropical R) :=
{ instPartialOrderTropical with
le_total := fun a b => le_total (untrop a) (untrop b)
toDecidableLE := Tropical.decidableLE
toDecidableEq := Tropical.instDecidableEq
toDecidableLT := Tropical.decidableLT
max := fun a b => trop (max (untrop a) (untrop b))
max_def := fun a b => untrop_injective (by
simp only [max_def, untrop_le_iff, untrop_trop]; split_ifs <;> simp)
min := (· + ·)
min_def := fun a b => untrop_injective (by
simp only [untrop_add, min_def, untrop_le_iff]; split_ifs <;> simp) }
@[simp]
theorem untrop_sup (x y : Tropical R) : untrop (x ⊔ y) = untrop x ⊔ untrop y :=
rfl
@[simp]
theorem untrop_max (x y : Tropical R) : untrop (max x y) = max (untrop x) (untrop y) :=
rfl
@[simp]
theorem min_eq_add : (min : Tropical R → Tropical R → Tropical R) = (· + ·) :=
rfl
@[simp]
theorem inf_eq_add : ((· ⊓ ·) : Tropical R → Tropical R → Tropical R) = (· + ·) :=
rfl
theorem trop_max_def (x y : Tropical R) : max x y = trop (max (untrop x) (untrop y)) :=
rfl
theorem trop_sup_def (x y : Tropical R) : x ⊔ y = trop (untrop x ⊔ untrop y) :=
rfl
@[simp]
theorem add_eq_left ⦃x y : Tropical R⦄ (h : x ≤ y) : x + y = x :=
untrop_injective (by simpa using h)
@[simp]
theorem add_eq_right ⦃x y : Tropical R⦄ (h : y ≤ x) : x + y = y :=
untrop_injective (by simpa using h)
theorem add_eq_left_iff {x y : Tropical R} : x + y = x ↔ x ≤ y := by
rw [trop_add_def, trop_eq_iff_eq_untrop, ← untrop_le_iff, min_eq_left_iff]
theorem add_eq_right_iff {x y : Tropical R} : x + y = y ↔ y ≤ x := by
rw [trop_add_def, trop_eq_iff_eq_untrop, ← untrop_le_iff, min_eq_right_iff]
theorem add_self (x : Tropical R) : x + x = x :=
untrop_injective (min_eq_right le_rfl)
theorem add_eq_iff {x y z : Tropical R} : x + y = z ↔ x = z ∧ x ≤ y ∨ y = z ∧ y ≤ x := by
rw [trop_add_def, trop_eq_iff_eq_untrop]
simp [min_eq_iff]
@[simp]
theorem add_eq_zero_iff {a b : Tropical (WithTop R)} : a + b = 0 ↔ a = 0 ∧ b = 0 := by
rw [add_eq_iff]
constructor
· rintro (⟨rfl, h⟩ | ⟨rfl, h⟩)
· exact ⟨rfl, le_antisymm (le_zero _) h⟩
· exact ⟨le_antisymm (le_zero _) h, rfl⟩
· rintro ⟨rfl, rfl⟩
simp
instance instAddCommMonoidTropical [OrderTop R] : AddCommMonoid (Tropical R) :=
{ instZeroTropical, instAddCommSemigroupTropical with
zero_add := fun _ => untrop_injective (min_top_left _)
add_zero := fun _ => untrop_injective (min_top_right _)
nsmul := nsmulRec }
end Order
section Monoid
/-- Tropical multiplication is the addition in the underlying `R`. -/
instance [Add R] : Mul (Tropical R) :=
⟨fun x y => trop (untrop x + untrop y)⟩
@[simp]
theorem trop_add [Add R] (x y : R) : trop (x + y) = trop x * trop y :=
rfl
@[simp]
theorem untrop_mul [Add R] (x y : Tropical R) : untrop (x * y) = untrop x + untrop y :=
rfl
theorem trop_mul_def [Add R] (x y : Tropical R) : x * y = trop (untrop x + untrop y) :=
rfl
instance instOneTropical [Zero R] : One (Tropical R) :=
⟨trop 0⟩
| @[simp]
theorem trop_zero [Zero R] : trop (0 : R) = 1 :=
| Mathlib/Algebra/Tropical/Basic.lean | 341 | 342 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kevin Kappelmann
-/
import Mathlib.Algebra.Order.Floor.Defs
import Mathlib.Algebra.Order.Floor.Ring
import Mathlib.Algebra.Order.Floor.Semiring
deprecated_module (since := "2025-04-13")
| Mathlib/Algebra/Order/Floor.lean | 1,732 | 1,733 | |
/-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Riccardo Brasca
-/
import Mathlib.Analysis.Normed.Module.Basic
import Mathlib.Analysis.Normed.Group.Hom
import Mathlib.RingTheory.Ideal.Quotient.Operations
import Mathlib.Topology.MetricSpace.HausdorffDistance
/-!
# Quotients of seminormed groups
For any `SeminormedAddCommGroup M` and any `S : AddSubgroup M`, we provide a
`SeminormedAddCommGroup`, the group quotient `M ⧸ S`.
If `S` is closed, we provide `NormedAddCommGroup (M ⧸ S)` (regardless of whether `M` itself is
separated). The two main properties of these structures are the underlying topology is the quotient
topology and the projection is a normed group homomorphism which is norm non-increasing
(better, it has operator norm exactly one unless `S` is dense in `M`). The corresponding
universal property is that every normed group hom defined on `M` which vanishes on `S` descends
to a normed group hom defined on `M ⧸ S`.
This file also introduces a predicate `IsQuotient` characterizing normed group homs that
are isomorphic to the canonical projection onto a normed group quotient.
In addition, this file also provides normed structures for quotients of modules by submodules, and
of (commutative) rings by ideals. The `SeminormedAddCommGroup` and `NormedAddCommGroup`
instances described above are transferred directly, but we also define instances of `NormedSpace`,
`SeminormedCommRing`, `NormedCommRing` and `NormedAlgebra` under appropriate type class
assumptions on the original space. Moreover, while `QuotientAddGroup.completeSpace` works
out-of-the-box for quotients of `NormedAddCommGroup`s by `AddSubgroup`s, we need to transfer
this instance in `Submodule.Quotient.completeSpace` so that it applies to these other quotients.
## Main definitions
We use `M` and `N` to denote seminormed groups and `S : AddSubgroup M`.
All the following definitions are in the `AddSubgroup` namespace. Hence we can access
`AddSubgroup.normedMk S` as `S.normedMk`.
* `seminormedAddCommGroupQuotient` : The seminormed group structure on the quotient by
an additive subgroup. This is an instance so there is no need to explicitly use it.
* `normedAddCommGroupQuotient` : The normed group structure on the quotient by
a closed additive subgroup. This is an instance so there is no need to explicitly use it.
* `normedMk S` : the normed group hom from `M` to `M ⧸ S`.
* `lift S f hf`: implements the universal property of `M ⧸ S`. Here
`(f : NormedAddGroupHom M N)`, `(hf : ∀ s ∈ S, f s = 0)` and
`lift S f hf : NormedAddGroupHom (M ⧸ S) N`.
* `IsQuotient`: given `f : NormedAddGroupHom M N`, `IsQuotient f` means `N` is isomorphic
to a quotient of `M` by a subgroup, with projection `f`. Technically it asserts `f` is
surjective and the norm of `f x` is the infimum of the norms of `x + m` for `m` in `f.ker`.
## Main results
* `norm_normedMk` : the operator norm of the projection is `1` if the subspace is not dense.
* `IsQuotient.norm_lift`: Provided `f : normed_hom M N` satisfies `IsQuotient f`, for every
`n : N` and positive `ε`, there exists `m` such that `f m = n ∧ ‖m‖ < ‖n‖ + ε`.
## Implementation details
For any `SeminormedAddCommGroup M` and any `S : AddSubgroup M` we define a norm on `M ⧸ S` by
`‖x‖ = sInf (norm '' {m | mk' S m = x})`. This formula is really an implementation detail, it
shouldn't be needed outside of this file setting up the theory.
Since `M ⧸ S` is automatically a topological space (as any quotient of a topological space),
one needs to be careful while defining the `SeminormedAddCommGroup` instance to avoid having two
different topologies on this quotient. This is not purely a technological issue.
Mathematically there is something to prove. The main point is proved in the auxiliary lemma
`quotient_nhd_basis` that has no use beyond this verification and states that zero in the quotient
admits as basis of neighborhoods in the quotient topology the sets `{x | ‖x‖ < ε}` for positive `ε`.
Once this mathematical point is settled, we have two topologies that are propositionally equal. This
is not good enough for the type class system. As usual we ensure *definitional* equality
using forgetful inheritance, see Note [forgetful inheritance]. A (semi)-normed group structure
includes a uniform space structure which includes a topological space structure, together
with propositional fields asserting compatibility conditions.
The usual way to define a `SeminormedAddCommGroup` is to let Lean build a uniform space structure
using the provided norm, and then trivially build a proof that the norm and uniform structure are
compatible. Here the uniform structure is provided using `IsTopologicalAddGroup.toUniformSpace`
which uses the topological structure and the group structure to build the uniform structure. This
uniform structure induces the correct topological structure by construction, but the fact that it
is compatible with the norm is not obvious; this is where the mathematical content explained in
the previous paragraph kicks in.
-/
noncomputable section
open Metric Set Topology NNReal
namespace QuotientGroup
variable {M : Type*} [SeminormedCommGroup M] {S : Subgroup M} {x : M ⧸ S} {m : M} {r ε : ℝ}
@[to_additive add_norm_aux]
private lemma norm_aux (x : M ⧸ S) : {m : M | (m : M ⧸ S) = x}.Nonempty := Quot.exists_rep x
/-- The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on
`x * M`. -/
@[to_additive
"The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on
`x + S`."]
noncomputable def groupSeminorm : GroupSeminorm (M ⧸ S) where
toFun x := infDist 1 {m : M | (m : M ⧸ S) = x}
map_one' := infDist_zero_of_mem (by simpa using S.one_mem)
mul_le' x y := by
simp only [infDist_eq_iInf]
have := (norm_aux x).to_subtype
have := (norm_aux y).to_subtype
refine le_ciInf_add_ciInf ?_
rintro ⟨a, rfl⟩ ⟨b, rfl⟩
refine ciInf_le_of_le ⟨0, forall_mem_range.2 fun _ ↦ dist_nonneg⟩ ⟨a * b, rfl⟩ ?_
simpa using norm_mul_le' _ _
inv' x := eq_of_forall_le_iff fun r ↦ by
simp only [le_infDist (norm_aux _)]
exact (Equiv.inv _).forall_congr (by simp [← inv_eq_iff_eq_inv])
/-- The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on
`x * S`. -/
@[to_additive
"The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on
`x + S`."]
noncomputable instance instNorm : Norm (M ⧸ S) where norm := groupSeminorm
@[to_additive]
lemma norm_eq_groupSeminorm (x : M ⧸ S) : ‖x‖ = groupSeminorm x := rfl
@[to_additive]
lemma norm_eq_infDist (x : M ⧸ S) : ‖x‖ = infDist 1 {m : M | (m : M ⧸ S) = x} := rfl
@[to_additive]
lemma le_norm_iff : r ≤ ‖x‖ ↔ ∀ m : M, ↑m = x → r ≤ ‖m‖ := by
simp [norm_eq_infDist, le_infDist (norm_aux _)]
@[to_additive]
lemma norm_lt_iff : ‖x‖ < r ↔ ∃ m : M, ↑m = x ∧ ‖m‖ < r := by
simp [norm_eq_infDist, infDist_lt_iff (norm_aux _)]
@[to_additive]
lemma nhds_one_hasBasis : (𝓝 (1 : M ⧸ S)).HasBasis (fun ε ↦ 0 < ε) fun ε ↦ {x | ‖x‖ < ε} := by
have : ∀ ε : ℝ, mk '' ball (1 : M) ε = {x : M ⧸ S | ‖x‖ < ε} := by
refine fun ε ↦ Set.ext <| forall_mk.2 fun x ↦ ?_
rw [ball_one_eq, mem_setOf_eq, norm_lt_iff, mem_image]
exact exists_congr fun _ ↦ and_comm
rw [← mk_one, nhds_eq, ← funext this]
exact .map _ Metric.nhds_basis_ball
/-- An alternative definition of the norm on the quotient group: the norm of `((x : M) : M ⧸ S)` is
equal to the distance from `x` to `S`. -/
@[to_additive
"An alternative definition of the norm on the quotient group: the norm of `((x : M) : M ⧸ S)` is
equal to the distance from `x` to `S`."]
lemma norm_mk (x : M) : ‖(x : M ⧸ S)‖ = infDist x S := by
rw [norm_eq_infDist, ← infDist_image (IsometryEquiv.divLeft x).isometry,
← IsometryEquiv.preimage_symm]
simp
/-- The norm of the projection is smaller or equal to the norm of the original element. -/
@[to_additive "The norm of the projection is smaller or equal to the norm of the original element."]
lemma norm_mk_le_norm : ‖(m : M ⧸ S)‖ ≤ ‖m‖ :=
(infDist_le_dist_of_mem (by simp)).trans_eq (dist_one_left _)
/-- The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m` belongs
to the closure of `S`. -/
@[to_additive "The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m`
belongs to the closure of `S`."]
lemma norm_mk_eq_zero_iff_mem_closure : ‖(m : M ⧸ S)‖ = 0 ↔ m ∈ closure (S : Set M) := by
rw [norm_mk, ← mem_closure_iff_infDist_zero]
exact ⟨1, S.one_mem⟩
/-- The norm of the image of `m : M` in the quotient by a closed subgroup `S` is zero if and only if
`m ∈ S`. -/
@[to_additive "The norm of the image of `m : M` in the quotient by a closed subgroup `S` is zero if
and only if `m ∈ S`."]
lemma norm_mk_eq_zero [hS : IsClosed (S : Set M)] : ‖(m : M ⧸ S)‖ = 0 ↔ m ∈ S := by
rw [norm_mk_eq_zero_iff_mem_closure, hS.closure_eq, SetLike.mem_coe]
/-- For any `x : M ⧸ S` and any `0 < ε`, there is `m : M` such that `mk' S m = x`
and `‖m‖ < ‖x‖ + ε`. -/
@[to_additive "For any `x : M ⧸ S` and any `0 < ε`, there is `m : M` such that `mk' S m = x`
and `‖m‖ < ‖x‖ + ε`."]
lemma exists_norm_mk_lt (x : M ⧸ S) (hε : 0 < ε) : ∃ m : M, m = x ∧ ‖m‖ < ‖x‖ + ε :=
norm_lt_iff.1 <| lt_add_of_pos_right _ hε
/-- For any `m : M` and any `0 < ε`, there is `s ∈ S` such that `‖m * s‖ < ‖mk' S m‖ + ε`. -/
@[to_additive
"For any `m : M` and any `0 < ε`, there is `s ∈ S` such that `‖m + s‖ < ‖mk' S m‖ + ε`."]
lemma exists_norm_mul_lt (S : Subgroup M) (m : M) {ε : ℝ} (hε : 0 < ε) :
∃ s ∈ S, ‖m * s‖ < ‖mk' S m‖ + ε := by
obtain ⟨n : M, hn, hn'⟩ := exists_norm_mk_lt (QuotientGroup.mk' S m) hε
exact ⟨m⁻¹ * n, by simpa [eq_comm, QuotientGroup.eq] using hn, by simpa⟩
variable (S) in
/-- The seminormed group structure on the quotient by a subgroup. -/
@[to_additive "The seminormed group structure on the quotient by an additive subgroup."]
noncomputable instance instSeminormedCommGroup : SeminormedCommGroup (M ⧸ S) where
toUniformSpace := IsTopologicalGroup.toUniformSpace (M ⧸ S)
__ := groupSeminorm.toSeminormedCommGroup
uniformity_dist := by
rw [uniformity_eq_comap_nhds_one', (nhds_one_hasBasis.comap _).eq_biInf]
simp only [dist, preimage_setOf_eq, norm_eq_groupSeminorm, map_div_rev]
variable (S) in
/-- The quotient in the category of normed groups. -/
@[to_additive "The quotient in the category of normed groups."]
noncomputable instance instNormedCommGroup [hS : IsClosed (S : Set M)] :
NormedCommGroup (M ⧸ S) where
__ := MetricSpace.ofT0PseudoMetricSpace _
-- This is a sanity check left here on purpose to ensure that potential refactors won't destroy
-- this important property.
example :
(instTopologicalSpaceQuotient : TopologicalSpace <| M ⧸ S) =
(instSeminormedCommGroup S).toUniformSpace.toTopologicalSpace := rfl
example [IsClosed (S : Set M)] :
(instSeminormedCommGroup S) = NormedCommGroup.toSeminormedCommGroup := rfl
end QuotientGroup
open QuotientAddGroup Metric Set Topology NNReal
| variable {M N : Type*} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N]
/-- The definition of the norm on the quotient by an additive subgroup. -/
@[deprecated QuotientAddGroup.instNorm (since := "2025-02-02")]
noncomputable def normOnQuotient (S : AddSubgroup M) : Norm (M ⧸ S) := inferInstance
@[deprecated QuotientAddGroup.norm_eq_infDist (since := "2025-02-02")]
theorem AddSubgroup.quotient_norm_eq {S : AddSubgroup M} (x : M ⧸ S) :
| Mathlib/Analysis/Normed/Group/Quotient.lean | 229 | 236 |
/-
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.Data.Int.Range
import Mathlib.Data.ZMod.Basic
import Mathlib.NumberTheory.MulChar.Basic
/-!
# Quadratic characters on ℤ/nℤ
This file defines some quadratic characters on the rings ℤ/4ℤ and ℤ/8ℤ.
We set them up to be of type `MulChar (ZMod n) ℤ`, where `n` is `4` or `8`.
## Tags
quadratic character, zmod
-/
/-!
### Quadratic characters mod 4 and 8
We define the primitive quadratic characters `χ₄`on `ZMod 4`
and `χ₈`, `χ₈'` on `ZMod 8`.
-/
namespace ZMod
section QuadCharModP
/-- Define the nontrivial quadratic character on `ZMod 4`, `χ₄`.
It corresponds to the extension `ℚ(√-1)/ℚ`. -/
@[simps]
def χ₄ : MulChar (ZMod 4) ℤ where
toFun a :=
match a with
| 0 | 2 => 0
| 1 => 1
| 3 => -1
map_one' := rfl
map_mul' := by decide
map_nonunit' := by decide
/-- `χ₄` takes values in `{0, 1, -1}` -/
theorem isQuadratic_χ₄ : χ₄.IsQuadratic := by
unfold MulChar.IsQuadratic
decide
/-- The value of `χ₄ n`, for `n : ℕ`, depends only on `n % 4`. -/
theorem χ₄_nat_mod_four (n : ℕ) : χ₄ n = χ₄ (n % 4 : ℕ) := by
rw [← ZMod.natCast_mod n 4]
/-- The value of `χ₄ n`, for `n : ℤ`, depends only on `n % 4`. -/
theorem χ₄_int_mod_four (n : ℤ) : χ₄ n = χ₄ (n % 4 : ℤ) := by
rw [← ZMod.intCast_mod n 4, Nat.cast_ofNat]
/-- An explicit description of `χ₄` on integers / naturals -/
theorem χ₄_int_eq_if_mod_four (n : ℤ) :
χ₄ n = if n % 2 = 0 then 0 else if n % 4 = 1 then 1 else -1 := by
have help : ∀ m : ℤ, 0 ≤ m → m < 4 → χ₄ m = if m % 2 = 0 then 0 else if m = 1 then 1 else -1 := by
decide
rw [← Int.emod_emod_of_dvd n (by omega : (2 : ℤ) ∣ 4), ← ZMod.intCast_mod n 4]
exact help (n % 4) (Int.emod_nonneg n (by omega)) (Int.emod_lt_abs n (by omega))
theorem χ₄_nat_eq_if_mod_four (n : ℕ) :
χ₄ n = if n % 2 = 0 then 0 else if n % 4 = 1 then 1 else -1 :=
mod_cast χ₄_int_eq_if_mod_four n
/-- Alternative description of `χ₄ n` for odd `n : ℕ` in terms of powers of `-1` -/
theorem χ₄_eq_neg_one_pow {n : ℕ} (hn : n % 2 = 1) : χ₄ n = (-1) ^ (n / 2) := by
rw [χ₄_nat_eq_if_mod_four]
simp only [hn, Nat.one_ne_zero, if_false]
nth_rewrite 3 [← Nat.div_add_mod n 4]
nth_rewrite 3 [show 4 = 2 * 2 by omega]
rw [mul_assoc, add_comm, Nat.add_mul_div_left _ _ zero_lt_two, pow_add, pow_mul,
neg_one_sq, one_pow, mul_one]
have help : ∀ m : ℕ, m < 4 → m % 2 = 1 → ite (m = 1) (1 : ℤ) (-1) = (-1) ^ (m / 2) := by decide
exact help _ (Nat.mod_lt n (by omega)) <| (Nat.mod_mod_of_dvd n (by omega : 2 ∣ 4)).trans hn
/-- If `n % 4 = 1`, then `χ₄ n = 1`. -/
theorem χ₄_nat_one_mod_four {n : ℕ} (hn : n % 4 = 1) : χ₄ n = 1 := by
rw [χ₄_nat_mod_four, hn]
rfl
/-- If `n % 4 = 3`, then `χ₄ n = -1`. -/
theorem χ₄_nat_three_mod_four {n : ℕ} (hn : n % 4 = 3) : χ₄ n = -1 := by
rw [χ₄_nat_mod_four, hn]
rfl
/-- If `n % 4 = 1`, then `χ₄ n = 1`. -/
theorem χ₄_int_one_mod_four {n : ℤ} (hn : n % 4 = 1) : χ₄ n = 1 := by
rw [χ₄_int_mod_four, hn]
rfl
/-- If `n % 4 = 3`, then `χ₄ n = -1`. -/
| theorem χ₄_int_three_mod_four {n : ℤ} (hn : n % 4 = 3) : χ₄ n = -1 := by
rw [χ₄_int_mod_four, hn]
rfl
| Mathlib/NumberTheory/LegendreSymbol/ZModChar.lean | 100 | 102 |
/-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Kim Morrison, Bhavik Mehta, Jakob von Raumer
-/
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Functor.Trifunctor
import Mathlib.CategoryTheory.Products.Basic
/-!
# Monoidal categories
A monoidal category is a category equipped with a tensor product, unitors, and an associator.
In the definition, we provide the tensor product as a pair of functions
* `tensorObj : C → C → C`
* `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))`
and allow use of the overloaded notation `⊗` for both.
The unitors and associator are provided componentwise.
The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`.
The unitors and associator are gathered together as natural
isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`.
Some consequences of the definition are proved in other files after proving the coherence theorem,
e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`.
## Implementation notes
In the definition of monoidal categories, we also provide the whiskering operators:
* `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`,
* `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`.
These are products of an object and a morphism (the terminology "whiskering"
is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined
in terms of the whiskerings. There are two possible such definitions, which are related by
the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def`
and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds
definitionally.
If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it,
you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`.
The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories.
### Simp-normal form for morphisms
Rewriting involving associators and unitors could be very complicated. We try to ease this
complexity by putting carefully chosen simp lemmas that rewrite any morphisms into the simp-normal
form defined below. Rewriting into simp-normal form is especially useful in preprocessing
performed by the `coherence` tactic.
The simp-normal form of morphisms is defined to be an expression that has the minimal number of
parentheses. More precisely,
1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is
either a structural morphisms (morphisms made up only of identities, associators, unitors)
or non-structural morphisms, and
2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`,
where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural
morphisms that is not the identity or a composite.
Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`.
Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`,
respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon.
## References
* Tensor categories, Etingof, Gelaki, Nikshych, Ostrik,
http://www-math.mit.edu/~etingof/egnobookfinal.pdf
* <https://stacks.math.columbia.edu/tag/0FFK>.
-/
universe v u
open CategoryTheory.Category
open CategoryTheory.Iso
namespace CategoryTheory
/-- Auxiliary structure to carry only the data fields of (and provide notation for)
`MonoidalCategory`. -/
class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where
/-- curried tensor product of objects -/
tensorObj : C → C → C
/-- left whiskering for morphisms -/
whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂
/-- right whiskering for morphisms -/
whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y
/-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/
-- By default, it is defined in terms of whiskerings.
tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) :=
whiskerRight f X₂ ≫ whiskerLeft Y₁ g
/-- The tensor unity in the monoidal structure `𝟙_ C` -/
tensorUnit (C) : C
/-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/
associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z)
/-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/
leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X
/-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/
rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X
namespace MonoidalCategory
export MonoidalCategoryStruct
(tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor)
end MonoidalCategory
namespace MonoidalCategory
/-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/
scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj
/-- Notation for the `whiskerLeft` operator of monoidal categories -/
scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft
/-- Notation for the `whiskerRight` operator of monoidal categories -/
scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight
/-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/
scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom
/-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/
scoped notation "𝟙_ " C:arg => MonoidalCategoryStruct.tensorUnit C
/-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/
scoped notation "α_" => MonoidalCategoryStruct.associator
/-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/
scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor
/-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/
scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor
/-- The property that the pentagon relation is satisfied by four objects
in a category equipped with a `MonoidalCategoryStruct`. -/
def Pentagon {C : Type u} [Category.{v} C] [MonoidalCategoryStruct C]
(Y₁ Y₂ Y₃ Y₄ : C) : Prop :=
(α_ Y₁ Y₂ Y₃).hom ▷ Y₄ ≫ (α_ Y₁ (Y₂ ⊗ Y₃) Y₄).hom ≫ Y₁ ◁ (α_ Y₂ Y₃ Y₄).hom =
(α_ (Y₁ ⊗ Y₂) Y₃ Y₄).hom ≫ (α_ Y₁ Y₂ (Y₃ ⊗ Y₄)).hom
end MonoidalCategory
open MonoidalCategory
/--
In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`.
Tensor product does not need to be strictly associative on objects, but there is a
specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`,
with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`.
These associators and unitors satisfy the pentagon and triangle equations. -/
@[stacks 0FFK]
-- Porting note: The Mathport did not translate the temporary notation
class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where
tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) :
f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by
aesop_cat
/-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/
tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat
/--
Tensor product of compositions is composition of tensor products:
`(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂)`
-/
tensor_comp :
∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂),
(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by
aesop_cat
whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by
aesop_cat
id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by
aesop_cat
/-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/
associator_naturality :
∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃),
((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by
aesop_cat
/--
Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y`
-/
leftUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by
aesop_cat
/--
Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y`
-/
rightUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by
aesop_cat
/--
The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W`
-/
pentagon :
∀ W X Y Z : C,
(α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom =
(α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by
aesop_cat
/--
The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y`
-/
triangle :
∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by
aesop_cat
attribute [reassoc] MonoidalCategory.tensorHom_def
attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id
attribute [reassoc, simp] MonoidalCategory.id_whiskerRight
attribute [reassoc] MonoidalCategory.tensor_comp
attribute [simp] MonoidalCategory.tensor_comp
attribute [reassoc] MonoidalCategory.associator_naturality
attribute [reassoc] MonoidalCategory.leftUnitor_naturality
attribute [reassoc] MonoidalCategory.rightUnitor_naturality
attribute [reassoc (attr := simp)] MonoidalCategory.pentagon
attribute [reassoc (attr := simp)] MonoidalCategory.triangle
namespace MonoidalCategory
variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C]
@[simp]
theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) :
𝟙 X ⊗ f = X ◁ f := by
simp [tensorHom_def]
@[simp]
theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) :
| f ⊗ 𝟙 Y = f ▷ Y := by
simp [tensorHom_def]
| Mathlib/CategoryTheory/Monoidal/Category.lean | 225 | 227 |
/-
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.RightAngle
import Mathlib.Geometry.Euclidean.Circumcenter
/-!
# Angles in circles and sphere.
This file proves results about angles in circles and spheres.
-/
noncomputable section
open Module Complex
open scoped EuclideanGeometry Real RealInnerProductSpace ComplexConjugate
namespace Orientation
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V]
variable [Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2))
/-- Angle at center of a circle equals twice angle at circumference, oriented vector angle
form. -/
theorem oangle_eq_two_zsmul_oangle_sub_of_norm_eq {x y z : V} (hxyne : x ≠ y) (hxzne : x ≠ z)
(hxy : ‖x‖ = ‖y‖) (hxz : ‖x‖ = ‖z‖) : o.oangle y z = (2 : ℤ) • o.oangle (y - x) (z - x) := by
have hy : y ≠ 0 := by
rintro rfl
rw [norm_zero, norm_eq_zero] at hxy
exact hxyne hxy
have hx : x ≠ 0 := norm_ne_zero_iff.1 (hxy.symm ▸ norm_ne_zero_iff.2 hy)
have hz : z ≠ 0 := norm_ne_zero_iff.1 (hxz ▸ norm_ne_zero_iff.2 hx)
calc
o.oangle y z = o.oangle x z - o.oangle x y := (o.oangle_sub_left hx hy hz).symm
_ = π - (2 : ℤ) • o.oangle (x - z) x - (π - (2 : ℤ) • o.oangle (x - y) x) := by
rw [o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxzne.symm hxz.symm,
o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxyne.symm hxy.symm]
_ = (2 : ℤ) • (o.oangle (x - y) x - o.oangle (x - z) x) := by abel
_ = (2 : ℤ) • o.oangle (x - y) (x - z) := by
rw [o.oangle_sub_right (sub_ne_zero_of_ne hxyne) (sub_ne_zero_of_ne hxzne) hx]
_ = (2 : ℤ) • o.oangle (y - x) (z - x) := by rw [← oangle_neg_neg, neg_sub, neg_sub]
/-- Angle at center of a circle equals twice angle at circumference, oriented vector angle
form with radius specified. -/
theorem oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real {x y z : V} (hxyne : x ≠ y) (hxzne : x ≠ z)
{r : ℝ} (hx : ‖x‖ = r) (hy : ‖y‖ = r) (hz : ‖z‖ = r) :
o.oangle y z = (2 : ℤ) • o.oangle (y - x) (z - x) :=
o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq hxyne hxzne (hy.symm ▸ hx) (hz.symm ▸ hx)
/-- Oriented vector angle version of "angles in same segment are equal" and "opposite angles of
a cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same
result), represented here as equality of twice the angles. -/
theorem two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq {x₁ x₂ y z : V} (hx₁yne : x₁ ≠ y)
(hx₁zne : x₁ ≠ z) (hx₂yne : x₂ ≠ y) (hx₂zne : x₂ ≠ z) {r : ℝ} (hx₁ : ‖x₁‖ = r) (hx₂ : ‖x₂‖ = r)
(hy : ‖y‖ = r) (hz : ‖z‖ = r) :
(2 : ℤ) • o.oangle (y - x₁) (z - x₁) = (2 : ℤ) • o.oangle (y - x₂) (z - x₂) :=
o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx₁yne hx₁zne hx₁ hy hz ▸
o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx₂yne hx₂zne hx₂ hy hz
end Orientation
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)]
local notation "o" => Module.Oriented.positiveOrientation
namespace Sphere
/-- Angle at center of a circle equals twice angle at circumference, oriented angle version. -/
theorem oangle_center_eq_two_zsmul_oangle {s : Sphere P} {p₁ p₂ p₃ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₃ : p₂ ≠ p₃) :
∡ p₁ s.center p₃ = (2 : ℤ) • ∡ p₁ p₂ p₃ := by
rw [mem_sphere, @dist_eq_norm_vsub V] at hp₁ hp₂ hp₃
rw [oangle, oangle, o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real _ _ hp₂ hp₁ hp₃] <;>
simp [hp₂p₁, hp₂p₃]
/-- Oriented angle version of "angles in same segment are equal" and "opposite angles of a
cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same result),
represented here as equality of twice the angles. -/
theorem two_zsmul_oangle_eq {s : Sphere P} {p₁ p₂ p₃ p₄ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s)
(hp₃ : p₃ ∈ s) (hp₄ : p₄ ∈ s) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₄ : p₂ ≠ p₄) (hp₃p₁ : p₃ ≠ p₁)
(hp₃p₄ : p₃ ≠ p₄) : (2 : ℤ) • ∡ p₁ p₂ p₄ = (2 : ℤ) • ∡ p₁ p₃ p₄ := by
rw [mem_sphere, @dist_eq_norm_vsub V] at hp₁ hp₂ hp₃ hp₄
rw [oangle, oangle, ← vsub_sub_vsub_cancel_right p₁ p₂ s.center, ←
vsub_sub_vsub_cancel_right p₄ p₂ s.center,
o.two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq _ _ _ _ hp₂ hp₃ hp₁ hp₄] <;>
simp [hp₂p₁, hp₂p₄, hp₃p₁, hp₃p₄]
end Sphere
/-- Oriented angle version of "angles in same segment are equal" and "opposite angles of a
cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same result),
represented here as equality of twice the angles. -/
theorem Cospherical.two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ : P}
(h : Cospherical ({p₁, p₂, p₃, p₄} : Set P)) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₄ : p₂ ≠ p₄)
(hp₃p₁ : p₃ ≠ p₁) (hp₃p₄ : p₃ ≠ p₄) : (2 : ℤ) • ∡ p₁ p₂ p₄ = (2 : ℤ) • ∡ p₁ p₃ p₄ := by
obtain ⟨s, hs⟩ := cospherical_iff_exists_sphere.1 h
simp_rw [Set.insert_subset_iff, Set.singleton_subset_iff, Sphere.mem_coe] at hs
exact Sphere.two_zsmul_oangle_eq hs.1 hs.2.1 hs.2.2.1 hs.2.2.2 hp₂p₁ hp₂p₄ hp₃p₁ hp₃p₄
namespace Sphere
/-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented
angle-at-point form where the apex is given as the center of a circle. -/
theorem oangle_eq_pi_sub_two_zsmul_oangle_center_left {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) : ∡ p₁ s.center p₂ = π - (2 : ℤ) • ∡ s.center p₂ p₁ := by
rw [oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq h.symm
(dist_center_eq_dist_center_of_mem_sphere' hp₂ hp₁)]
/-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented
angle-at-point form where the apex is given as the center of a circle. -/
theorem oangle_eq_pi_sub_two_zsmul_oangle_center_right {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) : ∡ p₁ s.center p₂ = π - (2 : ℤ) • ∡ p₂ p₁ s.center := by
rw [oangle_eq_pi_sub_two_zsmul_oangle_center_left hp₁ hp₂ h,
oangle_eq_oangle_of_dist_eq (dist_center_eq_dist_center_of_mem_sphere' hp₂ hp₁)]
/-- Twice a base angle of an isosceles triangle with apex at the center of a circle, plus twice
the angle at the apex of a triangle with the same base but apex on the circle, equals `π`. -/
theorem two_zsmul_oangle_center_add_two_zsmul_oangle_eq_pi {s : Sphere P} {p₁ p₂ p₃ : P}
(hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₃ : p₂ ≠ p₃)
(hp₁p₃ : p₁ ≠ p₃) : (2 : ℤ) • ∡ p₃ p₁ s.center + (2 : ℤ) • ∡ p₁ p₂ p₃ = π := by
rw [← oangle_center_eq_two_zsmul_oangle hp₁ hp₂ hp₃ hp₂p₁ hp₂p₃,
oangle_eq_pi_sub_two_zsmul_oangle_center_right hp₁ hp₃ hp₁p₃, add_sub_cancel]
/-- A base angle of an isosceles triangle with apex at the center of a circle is acute. -/
theorem abs_oangle_center_left_toReal_lt_pi_div_two {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) : |(∡ s.center p₂ p₁).toReal| < π / 2 :=
abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq
(dist_center_eq_dist_center_of_mem_sphere' hp₂ hp₁)
/-- A base angle of an isosceles triangle with apex at the center of a circle is acute. -/
theorem abs_oangle_center_right_toReal_lt_pi_div_two {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) : |(∡ p₂ p₁ s.center).toReal| < π / 2 :=
abs_oangle_left_toReal_lt_pi_div_two_of_dist_eq
(dist_center_eq_dist_center_of_mem_sphere' hp₂ hp₁)
/-- Given two points on a circle, the center of that circle may be expressed explicitly as a
multiple (by half the tangent of the angle between the chord and the radius at one of those
points) of a `π / 2` rotation of the vector between those points, plus the midpoint of those
points. -/
theorem tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center {s : Sphere P} {p₁ p₂ : P}
(hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) :
(Real.Angle.tan (∡ p₂ p₁ s.center) / 2) • o.rotation (π / 2 : ℝ) (p₂ -ᵥ p₁) +ᵥ
midpoint ℝ p₁ p₂ = s.center := by
obtain ⟨r, hr⟩ := (dist_eq_iff_eq_smul_rotation_pi_div_two_vadd_midpoint h).1
(dist_center_eq_dist_center_of_mem_sphere hp₁ hp₂)
rw [← hr, ← oangle_midpoint_rev_left, oangle, vadd_vsub_assoc]
nth_rw 1 [show p₂ -ᵥ p₁ = (2 : ℝ) • (midpoint ℝ p₁ p₂ -ᵥ p₁) by simp]
rw [map_smul, smul_smul, add_comm, o.tan_oangle_add_right_smul_rotation_pi_div_two,
mul_div_cancel_right₀ _ (two_ne_zero' ℝ)]
simpa using h.symm
/-- Given three points on a circle, the center of that circle may be expressed explicitly as a
multiple (by half the inverse of the tangent of the angle at one of those points) of a `π / 2`
rotation of the vector between the other two points, plus the midpoint of those points. -/
theorem inv_tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center {s : Sphere P}
{p₁ p₂ p₃ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₁p₂ : p₁ ≠ p₂) (hp₁p₃ : p₁ ≠ p₃)
(hp₂p₃ : p₂ ≠ p₃) :
((Real.Angle.tan (∡ p₁ p₂ p₃))⁻¹ / 2) • o.rotation (π / 2 : ℝ) (p₃ -ᵥ p₁) +ᵥ midpoint ℝ p₁ p₃ =
s.center := by
convert tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center hp₁ hp₃ hp₁p₃
convert (Real.Angle.tan_eq_inv_of_two_zsmul_add_two_zsmul_eq_pi _).symm
rw [add_comm,
two_zsmul_oangle_center_add_two_zsmul_oangle_eq_pi hp₁ hp₂ hp₃ hp₁p₂.symm hp₂p₃ hp₁p₃]
/-- Given two points on a circle, the radius of that circle may be expressed explicitly as half
the distance between those two points divided by the cosine of the angle between the chord and
the radius at one of those points. -/
theorem dist_div_cos_oangle_center_div_two_eq_radius {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) :
dist p₁ p₂ / Real.Angle.cos (∡ p₂ p₁ s.center) / 2 = s.radius := by
rw [div_right_comm, div_eq_mul_inv _ (2 : ℝ), mul_comm,
show (2 : ℝ)⁻¹ * dist p₁ p₂ = dist p₁ (midpoint ℝ p₁ p₂) by simp, ← mem_sphere.1 hp₁, ←
tan_div_two_smul_rotation_pi_div_two_vadd_midpoint_eq_center hp₁ hp₂ h, ←
oangle_midpoint_rev_left, oangle, vadd_vsub_assoc,
show p₂ -ᵥ p₁ = (2 : ℝ) • (midpoint ℝ p₁ p₂ -ᵥ p₁) by simp, map_smul, smul_smul,
div_mul_cancel₀ _ (two_ne_zero' ℝ), @dist_eq_norm_vsub' V, @dist_eq_norm_vsub' V,
vadd_vsub_assoc, add_comm, o.oangle_add_right_smul_rotation_pi_div_two, Real.Angle.cos_coe,
Real.cos_arctan]
· norm_cast
rw [one_div, div_inv_eq_mul, ←
mul_self_inj (mul_nonneg (norm_nonneg _) (Real.sqrt_nonneg _)) (norm_nonneg _),
norm_add_sq_eq_norm_sq_add_norm_sq_real (o.inner_smul_rotation_pi_div_two_right _ _), ←
| mul_assoc, mul_comm, mul_comm _ (√_), ← mul_assoc, ← mul_assoc,
Real.mul_self_sqrt (add_nonneg zero_le_one (sq_nonneg _)), norm_smul,
LinearIsometryEquiv.norm_map]
conv_rhs =>
rw [← mul_assoc, mul_comm _ ‖Real.Angle.tan _‖, ← mul_assoc, Real.norm_eq_abs,
abs_mul_abs_self]
ring
· simpa using h.symm
/-- Given two points on a circle, twice the radius of that circle may be expressed explicitly as
the distance between those two points divided by the cosine of the angle between the chord and
the radius at one of those points. -/
theorem dist_div_cos_oangle_center_eq_two_mul_radius {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) :
dist p₁ p₂ / Real.Angle.cos (∡ p₂ p₁ s.center) = 2 * s.radius := by
rw [← dist_div_cos_oangle_center_div_two_eq_radius hp₁ hp₂ h, mul_div_cancel₀ _ (two_ne_zero' ℝ)]
/-- Given three points on a circle, the radius of that circle may be expressed explicitly as half
the distance between two of those points divided by the absolute value of the sine of the angle
at the third point (a version of the law of sines or sine rule). -/
theorem dist_div_sin_oangle_div_two_eq_radius {s : Sphere P} {p₁ p₂ p₃ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₁p₂ : p₁ ≠ p₂) (hp₁p₃ : p₁ ≠ p₃) (hp₂p₃ : p₂ ≠ p₃) :
dist p₁ p₃ / |Real.Angle.sin (∡ p₁ p₂ p₃)| / 2 = s.radius := by
| Mathlib/Geometry/Euclidean/Angle/Sphere.lean | 191 | 213 |
/-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Combinatorics.SimpleGraph.Path
import Mathlib.Combinatorics.SimpleGraph.Operations
import Mathlib.Data.Finset.Pairwise
import Mathlib.Data.Fintype.Pigeonhole
import Mathlib.Data.Fintype.Powerset
import Mathlib.Data.Nat.Lattice
import Mathlib.SetTheory.Cardinal.Finite
/-!
# Graph cliques
This file defines cliques in simple graphs.
A clique is a set of vertices that are pairwise adjacent.
## Main declarations
* `SimpleGraph.IsClique`: Predicate for a set of vertices to be a clique.
* `SimpleGraph.IsNClique`: Predicate for a set of vertices to be an `n`-clique.
* `SimpleGraph.cliqueFinset`: Finset of `n`-cliques of a graph.
* `SimpleGraph.CliqueFree`: Predicate for a graph to have no `n`-cliques.
-/
open Finset Fintype Function SimpleGraph.Walk
namespace SimpleGraph
variable {α β : Type*} (G H : SimpleGraph α)
/-! ### Cliques -/
section Clique
variable {s t : Set α}
/-- A clique in a graph is a set of vertices that are pairwise adjacent. -/
abbrev IsClique (s : Set α) : Prop :=
s.Pairwise G.Adj
theorem isClique_iff : G.IsClique s ↔ s.Pairwise G.Adj :=
Iff.rfl
/-- A clique is a set of vertices whose induced graph is complete. -/
theorem isClique_iff_induce_eq : G.IsClique s ↔ G.induce s = ⊤ := by
rw [isClique_iff]
constructor
· intro h
ext ⟨v, hv⟩ ⟨w, hw⟩
simp only [comap_adj, Subtype.coe_mk, top_adj, Ne, Subtype.mk_eq_mk]
exact ⟨Adj.ne, h hv hw⟩
· intro h v hv w hw hne
have h2 : (G.induce s).Adj ⟨v, hv⟩ ⟨w, hw⟩ = _ := rfl
conv_lhs at h2 => rw [h]
simp only [top_adj, ne_eq, Subtype.mk.injEq, eq_iff_iff] at h2
exact h2.1 hne
instance [DecidableEq α] [DecidableRel G.Adj] {s : Finset α} : Decidable (G.IsClique s) :=
decidable_of_iff' _ G.isClique_iff
variable {G H} {a b : α}
lemma isClique_empty : G.IsClique ∅ := by simp
lemma isClique_singleton (a : α) : G.IsClique {a} := by simp
theorem IsClique.of_subsingleton {G : SimpleGraph α} (hs : s.Subsingleton) : G.IsClique s :=
hs.pairwise G.Adj
lemma isClique_pair : G.IsClique {a, b} ↔ a ≠ b → G.Adj a b := Set.pairwise_pair_of_symmetric G.symm
@[simp]
lemma isClique_insert : G.IsClique (insert a s) ↔ G.IsClique s ∧ ∀ b ∈ s, a ≠ b → G.Adj a b :=
Set.pairwise_insert_of_symmetric G.symm
lemma isClique_insert_of_not_mem (ha : a ∉ s) :
G.IsClique (insert a s) ↔ G.IsClique s ∧ ∀ b ∈ s, G.Adj a b :=
Set.pairwise_insert_of_symmetric_of_not_mem G.symm ha
lemma IsClique.insert (hs : G.IsClique s) (h : ∀ b ∈ s, a ≠ b → G.Adj a b) :
G.IsClique (insert a s) := hs.insert_of_symmetric G.symm h
theorem IsClique.mono (h : G ≤ H) : G.IsClique s → H.IsClique s := Set.Pairwise.mono' h
theorem IsClique.subset (h : t ⊆ s) : G.IsClique s → G.IsClique t := Set.Pairwise.mono h
@[simp]
theorem isClique_bot_iff : (⊥ : SimpleGraph α).IsClique s ↔ (s : Set α).Subsingleton :=
Set.pairwise_bot_iff
alias ⟨IsClique.subsingleton, _⟩ := isClique_bot_iff
protected theorem IsClique.map (h : G.IsClique s) {f : α ↪ β} : (G.map f).IsClique (f '' s) := by
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ hab
exact ⟨a, b, h ha hb <| ne_of_apply_ne _ hab, rfl, rfl⟩
theorem isClique_map_iff_of_nontrivial {f : α ↪ β} {t : Set β} (ht : t.Nontrivial) :
(G.map f).IsClique t ↔ ∃ (s : Set α), G.IsClique s ∧ f '' s = t := by
refine ⟨fun h ↦ ⟨f ⁻¹' t, ?_, ?_⟩, by rintro ⟨x, hs, rfl⟩; exact hs.map⟩
· rintro x (hx : f x ∈ t) y (hy : f y ∈ t) hne
obtain ⟨u,v, huv, hux, hvy⟩ := h hx hy (by simpa)
rw [EmbeddingLike.apply_eq_iff_eq] at hux hvy
rwa [← hux, ← hvy]
rw [Set.image_preimage_eq_iff]
intro x hxt
obtain ⟨y,hyt, hyne⟩ := ht.exists_ne x
obtain ⟨u,v, -, rfl, rfl⟩ := h hyt hxt hyne
exact Set.mem_range_self _
theorem isClique_map_iff {f : α ↪ β} {t : Set β} :
(G.map f).IsClique t ↔ t.Subsingleton ∨ ∃ (s : Set α), G.IsClique s ∧ f '' s = t := by
obtain (ht | ht) := t.subsingleton_or_nontrivial
· simp [IsClique.of_subsingleton, ht]
simp [isClique_map_iff_of_nontrivial ht, ht.not_subsingleton]
@[simp] theorem isClique_map_image_iff {f : α ↪ β} :
(G.map f).IsClique (f '' s) ↔ G.IsClique s := by
rw [isClique_map_iff, f.injective.subsingleton_image_iff]
obtain (hs | hs) := s.subsingleton_or_nontrivial
· simp [hs, IsClique.of_subsingleton]
simp [or_iff_right hs.not_subsingleton, Set.image_eq_image f.injective]
variable {f : α ↪ β} {t : Finset β}
theorem isClique_map_finset_iff_of_nontrivial (ht : t.Nontrivial) :
(G.map f).IsClique t ↔ ∃ (s : Finset α), G.IsClique s ∧ s.map f = t := by
constructor
· rw [isClique_map_iff_of_nontrivial (by simpa)]
rintro ⟨s, hs, hst⟩
obtain ⟨s, rfl⟩ := Set.Finite.exists_finset_coe <|
(show s.Finite from Set.Finite.of_finite_image (by simp [hst]) f.injective.injOn)
exact ⟨s,hs, Finset.coe_inj.1 (by simpa)⟩
rintro ⟨s, hs, rfl⟩
simpa using hs.map (f := f)
theorem isClique_map_finset_iff :
(G.map f).IsClique t ↔ #t ≤ 1 ∨ ∃ (s : Finset α), G.IsClique s ∧ s.map f = t := by
obtain (ht | ht) := le_or_lt #t 1
· simp only [ht, true_or, iff_true]
exact IsClique.of_subsingleton <| card_le_one.1 ht
rw [isClique_map_finset_iff_of_nontrivial, ← not_lt]
· simp [ht, Finset.map_eq_image]
exact Finset.one_lt_card_iff_nontrivial.mp ht
protected theorem IsClique.finsetMap {f : α ↪ β} {s : Finset α} (h : G.IsClique s) :
(G.map f).IsClique (s.map f) := by
simpa
/-- If a set of vertices `A` is a clique in subgraph of `G` induced by a superset of `A`,
its embedding is a clique in `G`. -/
theorem IsClique.of_induce {S : Subgraph G} {F : Set α} {A : Set F}
(c : (S.induce F).coe.IsClique A) : G.IsClique (Subtype.val '' A) := by
simp only [Set.Pairwise, Set.mem_image, Subtype.exists, exists_and_right, exists_eq_right]
intro _ ⟨_, ainA⟩ _ ⟨_, binA⟩ anb
exact S.adj_sub (c ainA binA (Subtype.coe_ne_coe.mp anb)).2.2
lemma IsClique.sdiff_of_sup_edge {v w : α} {s : Set α} (hc : (G ⊔ edge v w).IsClique s) :
G.IsClique (s \ {v}) := by
intro _ hx _ hy hxy
have := hc hx.1 hy.1 hxy
simp_all [sup_adj, edge_adj]
lemma isClique_sup_edge_of_ne_sdiff {v w : α} {s : Set α} (h : v ≠ w ) (hv : G.IsClique (s \ {v}))
(hw : G.IsClique (s \ {w})) : (G ⊔ edge v w).IsClique s := by
intro x hx y hy hxy
by_cases h' : x ∈ s \ {v} ∧ y ∈ s \ {v} ∨ x ∈ s \ {w} ∧ y ∈ s \ {w}
· obtain (⟨hx, hy⟩ | ⟨hx, hy⟩) := h'
· exact hv.mono le_sup_left hx hy hxy
· exact hw.mono le_sup_left hx hy hxy
· exact Or.inr ⟨by by_cases x = v <;> aesop, hxy⟩
lemma isClique_sup_edge_of_ne_iff {v w : α} {s : Set α} (h : v ≠ w) :
(G ⊔ edge v w).IsClique s ↔ G.IsClique (s \ {v}) ∧ G.IsClique (s \ {w}) :=
⟨fun h' ↦ ⟨h'.sdiff_of_sup_edge, (edge_comm .. ▸ h').sdiff_of_sup_edge⟩,
fun h' ↦ isClique_sup_edge_of_ne_sdiff h h'.1 h'.2⟩
end Clique
/-! ### `n`-cliques -/
section NClique
variable {n : ℕ} {s : Finset α}
/-- An `n`-clique in a graph is a set of `n` vertices which are pairwise connected. -/
structure IsNClique (n : ℕ) (s : Finset α) : Prop where
isClique : G.IsClique s
card_eq : #s = n
theorem isNClique_iff : G.IsNClique n s ↔ G.IsClique s ∧ #s = n :=
⟨fun h ↦ ⟨h.1, h.2⟩, fun h ↦ ⟨h.1, h.2⟩⟩
instance [DecidableEq α] [DecidableRel G.Adj] {n : ℕ} {s : Finset α} :
Decidable (G.IsNClique n s) :=
decidable_of_iff' _ G.isNClique_iff
variable {G H} {a b c : α}
@[simp] lemma isNClique_empty : G.IsNClique n ∅ ↔ n = 0 := by simp [isNClique_iff, eq_comm]
@[simp]
lemma isNClique_singleton : G.IsNClique n {a} ↔ n = 1 := by simp [isNClique_iff, eq_comm]
theorem IsNClique.mono (h : G ≤ H) : G.IsNClique n s → H.IsNClique n s := by
simp_rw [isNClique_iff]
exact And.imp_left (IsClique.mono h)
protected theorem IsNClique.map (h : G.IsNClique n s) {f : α ↪ β} :
(G.map f).IsNClique n (s.map f) :=
⟨by rw [coe_map]; exact h.1.map, (card_map _).trans h.2⟩
theorem isNClique_map_iff (hn : 1 < n) {t : Finset β} {f : α ↪ β} :
(G.map f).IsNClique n t ↔ ∃ s : Finset α, G.IsNClique n s ∧ s.map f = t := by
rw [isNClique_iff, isClique_map_finset_iff, or_and_right,
or_iff_right (by rintro ⟨h', rfl⟩; exact h'.not_lt hn)]
constructor
· rintro ⟨⟨s, hs, rfl⟩, rfl⟩
simp [isNClique_iff, hs]
rintro ⟨s, hs, rfl⟩
simp [hs.card_eq, hs.isClique]
@[simp]
theorem isNClique_bot_iff : (⊥ : SimpleGraph α).IsNClique n s ↔ n ≤ 1 ∧ #s = n := by
rw [isNClique_iff, isClique_bot_iff]
refine and_congr_left ?_
rintro rfl
exact card_le_one.symm
@[simp]
theorem isNClique_zero : G.IsNClique 0 s ↔ s = ∅ := by
simp only [isNClique_iff, Finset.card_eq_zero, and_iff_right_iff_imp]; rintro rfl; simp
@[simp]
theorem isNClique_one : G.IsNClique 1 s ↔ ∃ a, s = {a} := by
simp only [isNClique_iff, card_eq_one, and_iff_right_iff_imp]; rintro ⟨a, rfl⟩; simp
section DecidableEq
variable [DecidableEq α]
protected theorem IsNClique.insert (hs : G.IsNClique n s) (h : ∀ b ∈ s, G.Adj a b) :
G.IsNClique (n + 1) (insert a s) := by
constructor
· push_cast
exact hs.1.insert fun b hb _ => h _ hb
· rw [card_insert_of_not_mem fun ha => (h _ ha).ne rfl, hs.2]
lemma IsNClique.erase_of_mem (hs : G.IsNClique n s) (ha : a ∈ s) :
G.IsNClique (n - 1) (s.erase a) where
isClique := hs.isClique.subset <| by simp
card_eq := by rw [card_erase_of_mem ha, hs.2]
protected lemma IsNClique.insert_erase
(hs : G.IsNClique n s) (ha : ∀ w ∈ s \ {b}, G.Adj a w) (hb : b ∈ s) :
G.IsNClique n (insert a (erase s b)) := by
cases n with
| zero => exact False.elim <| not_mem_empty _ (isNClique_zero.1 hs ▸ hb)
| succ _ => exact (hs.erase_of_mem hb).insert fun w h ↦ by aesop
theorem is3Clique_triple_iff : G.IsNClique 3 {a, b, c} ↔ G.Adj a b ∧ G.Adj a c ∧ G.Adj b c := by
simp only [isNClique_iff, isClique_iff, Set.pairwise_insert_of_symmetric G.symm, coe_insert]
by_cases hab : a = b <;> by_cases hbc : b = c <;> by_cases hac : a = c <;> subst_vars <;>
simp [G.ne_of_adj, and_rotate, *]
theorem is3Clique_iff :
G.IsNClique 3 s ↔ ∃ a b c, G.Adj a b ∧ G.Adj a c ∧ G.Adj b c ∧ s = {a, b, c} := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain ⟨a, b, c, -, -, -, hs⟩ := card_eq_three.1 h.card_eq
refine ⟨a, b, c, ?_⟩
rwa [hs, eq_self_iff_true, and_true, is3Clique_triple_iff.symm, ← hs]
· rintro ⟨a, b, c, hab, hbc, hca, rfl⟩
exact is3Clique_triple_iff.2 ⟨hab, hbc, hca⟩
end DecidableEq
theorem is3Clique_iff_exists_cycle_length_three :
(∃ s : Finset α, G.IsNClique 3 s) ↔ ∃ (u : α) (w : G.Walk u u), w.IsCycle ∧ w.length = 3 := by
classical
simp_rw [is3Clique_iff, isCycle_def]
exact
⟨(fun ⟨_, a, _, _, hab, hac, hbc, _⟩ => ⟨a, cons hab (cons hbc (cons hac.symm nil)), by aesop⟩),
(fun ⟨_, .cons hab (.cons hbc (.cons hca nil)), _, _⟩ => ⟨_, _, _, _, hab, hca.symm, hbc, rfl⟩)⟩
/-- If a set of vertices `A` is an `n`-clique in subgraph of `G` induced by a superset of `A`,
its embedding is an `n`-clique in `G`. -/
theorem IsNClique.of_induce {S : Subgraph G} {F : Set α} {s : Finset { x // x ∈ F }} {n : ℕ}
(cc : (S.induce F).coe.IsNClique n s) :
G.IsNClique n (Finset.map ⟨Subtype.val, Subtype.val_injective⟩ s) := by
rw [isNClique_iff] at cc ⊢
simp only [Subgraph.induce_verts, coe_map, card_map]
exact ⟨cc.left.of_induce, cc.right⟩
lemma IsNClique.erase_of_sup_edge_of_mem [DecidableEq α] {v w : α} {s : Finset α} {n : ℕ}
(hc : (G ⊔ edge v w).IsNClique n s) (hx : v ∈ s) : G.IsNClique (n - 1) (s.erase v) where
isClique := coe_erase v _ ▸ hc.1.sdiff_of_sup_edge
card_eq := by rw [card_erase_of_mem hx, hc.2]
end NClique
/-! ### Graphs without cliques -/
section CliqueFree
variable {m n : ℕ}
/-- `G.CliqueFree n` means that `G` has no `n`-cliques. -/
def CliqueFree (n : ℕ) : Prop :=
∀ t, ¬G.IsNClique n t
variable {G H} {s : Finset α}
theorem IsNClique.not_cliqueFree (hG : G.IsNClique n s) : ¬G.CliqueFree n :=
fun h ↦ h _ hG
theorem not_cliqueFree_of_top_embedding {n : ℕ} (f : (⊤ : SimpleGraph (Fin n)) ↪g G) :
¬G.CliqueFree n := by
simp only [CliqueFree, isNClique_iff, isClique_iff_induce_eq, not_forall, Classical.not_not]
use Finset.univ.map f.toEmbedding
simp only [card_map, Finset.card_fin, eq_self_iff_true, and_true]
ext ⟨v, hv⟩ ⟨w, hw⟩
simp only [coe_map, Set.mem_image, coe_univ, Set.mem_univ, true_and] at hv hw
obtain ⟨v', rfl⟩ := hv
obtain ⟨w', rfl⟩ := hw
simp_rw [RelEmbedding.coe_toEmbedding, comap_adj, Function.Embedding.coe_subtype, f.map_adj_iff,
top_adj, ne_eq, Subtype.mk.injEq, RelEmbedding.inj]
/-- An embedding of a complete graph that witnesses the fact that the graph is not clique-free. -/
noncomputable def topEmbeddingOfNotCliqueFree {n : ℕ} (h : ¬G.CliqueFree n) :
(⊤ : SimpleGraph (Fin n)) ↪g G := by
simp only [CliqueFree, isNClique_iff, isClique_iff_induce_eq, not_forall, Classical.not_not] at h
obtain ⟨ha, hb⟩ := h.choose_spec
have : (⊤ : SimpleGraph (Fin #h.choose)) ≃g (⊤ : SimpleGraph h.choose) := by
apply Iso.completeGraph
simpa using (Fintype.equivFin h.choose).symm
rw [← ha] at this
convert (Embedding.induce ↑h.choose.toSet).comp this.toEmbedding
exact hb.symm
theorem not_cliqueFree_iff (n : ℕ) : ¬G.CliqueFree n ↔ Nonempty ((⊤ : SimpleGraph (Fin n)) ↪g G) :=
⟨fun h ↦ ⟨topEmbeddingOfNotCliqueFree h⟩, fun ⟨f⟩ ↦ not_cliqueFree_of_top_embedding f⟩
theorem cliqueFree_iff {n : ℕ} : G.CliqueFree n ↔ IsEmpty ((⊤ : SimpleGraph (Fin n)) ↪g G) := by
rw [← not_iff_not, not_cliqueFree_iff, not_isEmpty_iff]
theorem not_cliqueFree_card_of_top_embedding [Fintype α] (f : (⊤ : SimpleGraph α) ↪g G) :
¬G.CliqueFree (card α) := by
rw [not_cliqueFree_iff]
exact ⟨(Iso.completeGraph (Fintype.equivFin α)).symm.toEmbedding.trans f⟩
@[simp] lemma not_cliqueFree_zero : ¬ G.CliqueFree 0 :=
fun h ↦ h ∅ <| isNClique_empty.mpr rfl
@[simp]
theorem cliqueFree_bot (h : 2 ≤ n) : (⊥ : SimpleGraph α).CliqueFree n := by
intro t ht
have := le_trans h (isNClique_bot_iff.1 ht).1
contradiction
theorem CliqueFree.mono (h : m ≤ n) : G.CliqueFree m → G.CliqueFree n := by
intro hG s hs
obtain ⟨t, hts, ht⟩ := exists_subset_card_eq (h.trans hs.card_eq.ge)
exact hG _ ⟨hs.isClique.subset hts, ht⟩
theorem CliqueFree.anti (h : G ≤ H) : H.CliqueFree n → G.CliqueFree n :=
forall_imp fun _ ↦ mt <| IsNClique.mono h
/-- If a graph is cliquefree, any graph that embeds into it is also cliquefree. -/
theorem CliqueFree.comap {H : SimpleGraph β} (f : H ↪g G) : G.CliqueFree n → H.CliqueFree n := by
intro h; contrapose h
exact not_cliqueFree_of_top_embedding <| f.comp (topEmbeddingOfNotCliqueFree h)
@[simp] theorem cliqueFree_map_iff {f : α ↪ β} [Nonempty α] :
(G.map f).CliqueFree n ↔ G.CliqueFree n := by
obtain (hle | hlt) := le_or_lt n 1
· obtain (rfl | rfl) := Nat.le_one_iff_eq_zero_or_eq_one.1 hle
· simp [CliqueFree]
simp [CliqueFree, show ∃ (_ : β), True from ⟨f (Classical.arbitrary _), trivial⟩]
simp [CliqueFree, isNClique_map_iff hlt]
/-- See `SimpleGraph.cliqueFree_of_chromaticNumber_lt` for a tighter bound. -/
theorem cliqueFree_of_card_lt [Fintype α] (hc : card α < n) : G.CliqueFree n := by
by_contra h
refine Nat.lt_le_asymm hc ?_
rw [cliqueFree_iff, not_isEmpty_iff] at h
simpa only [Fintype.card_fin] using Fintype.card_le_of_embedding h.some.toEmbedding
/-- A complete `r`-partite graph has no `n`-cliques for `r < n`. -/
theorem cliqueFree_completeMultipartiteGraph {ι : Type*} [Fintype ι] (V : ι → Type*)
(hc : card ι < n) : (completeMultipartiteGraph V).CliqueFree n := by
rw [cliqueFree_iff, isEmpty_iff]
intro f
obtain ⟨v, w, hn, he⟩ := exists_ne_map_eq_of_card_lt (Sigma.fst ∘ f) (by simp [hc])
rw [← top_adj, ← f.map_adj_iff, comap_adj, top_adj] at hn
exact absurd he hn
namespace completeMultipartiteGraph
variable {ι : Type*} (V : ι → Type*)
/-- Embedding of the complete graph on `ι` into `completeMultipartiteGraph` on `ι` nonempty parts -/
@[simps]
def topEmbedding (f : ∀ (i : ι), V i) :
(⊤ : SimpleGraph ι) ↪g completeMultipartiteGraph V where
toFun := fun i ↦ ⟨i, f i⟩
inj' := fun _ _ h ↦ (Sigma.mk.inj_iff.1 h).1
map_rel_iff' := by simp
theorem not_cliqueFree_of_le_card [Fintype ι] (f : ∀ (i : ι), V i) (hc : n ≤ Fintype.card ι) :
¬ (completeMultipartiteGraph V).CliqueFree n :=
fun hf ↦ (cliqueFree_iff.1 <| hf.mono hc).elim' <|
(topEmbedding V f).comp (Iso.completeGraph (Fintype.equivFin ι).symm).toEmbedding
theorem not_cliqueFree_of_infinite [Infinite ι] (f : ∀ (i : ι), V i) :
¬ (completeMultipartiteGraph V).CliqueFree n :=
fun hf ↦ not_cliqueFree_of_top_embedding (topEmbedding V f |>.comp
<| Embedding.completeGraph <| Fin.valEmbedding.trans <| Infinite.natEmbedding ι) hf
theorem not_cliqueFree_of_le_enatCard (f : ∀ (i : ι), V i) (hc : n ≤ ENat.card ι) :
¬ (completeMultipartiteGraph V).CliqueFree n := by
by_cases h : Infinite ι
· exact not_cliqueFree_of_infinite V f
· have : Fintype ι := fintypeOfNotInfinite h
rw [ENat.card_eq_coe_fintype_card, Nat.cast_le] at hc
exact not_cliqueFree_of_le_card V f hc
end completeMultipartiteGraph
/-- Clique-freeness is preserved by `replaceVertex`. -/
protected theorem CliqueFree.replaceVertex [DecidableEq α] (h : G.CliqueFree n) (s t : α) :
(G.replaceVertex s t).CliqueFree n := by
contrapose h
obtain ⟨φ, hφ⟩ := topEmbeddingOfNotCliqueFree h
rw [not_cliqueFree_iff]
by_cases mt : t ∈ Set.range φ
· obtain ⟨x, hx⟩ := mt
by_cases ms : s ∈ Set.range φ
· obtain ⟨y, hy⟩ := ms
have e := @hφ x y
simp_rw [hx, hy, adj_comm, not_adj_replaceVertex_same, top_adj, false_iff, not_ne_iff] at e
rwa [← hx, e, hy, replaceVertex_self, not_cliqueFree_iff] at h
· unfold replaceVertex at hφ
use φ.setValue x s
intro a b
simp only [Embedding.coeFn_mk, Embedding.setValue, not_exists.mp ms, ite_false]
rw [apply_ite (G.Adj · _), apply_ite (G.Adj _ ·), apply_ite (G.Adj _ ·)]
convert @hφ a b <;> simp only [← φ.apply_eq_iff_eq, SimpleGraph.irrefl, hx]
· use φ
simp_rw [Set.mem_range, not_exists, ← ne_eq] at mt
conv at hφ => enter [a, b]; rw [G.adj_replaceVertex_iff_of_ne _ (mt a) (mt b)]
exact hφ
@[simp]
lemma cliqueFree_one : G.CliqueFree 1 ↔ IsEmpty α := by
simp [CliqueFree, isEmpty_iff]
@[simp]
theorem cliqueFree_two : G.CliqueFree 2 ↔ G = ⊥ := by
classical
constructor
· simp_rw [← edgeSet_eq_empty, Set.eq_empty_iff_forall_not_mem, Sym2.forall, mem_edgeSet]
exact fun h a b hab => h _ ⟨by simpa [hab.ne], card_pair hab.ne⟩
· rintro rfl
exact cliqueFree_bot le_rfl
|
lemma CliqueFree.mem_of_sup_edge_isNClique {x y : α} {t : Finset α} {n : ℕ} (h : G.CliqueFree n)
(hc : (G ⊔ edge x y).IsNClique n t) : x ∈ t := by
by_contra! hf
| Mathlib/Combinatorics/SimpleGraph/Clique.lean | 470 | 473 |
/-
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 _)]
| Mathlib/Data/Set/Card.lean | 290 | 293 |
/-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
import Mathlib.Algebra.Group.Commute.Hom
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Data.Fintype.Basic
/-!
# Products (respectively, sums) over a finset or a multiset.
The regular `Finset.prod` and `Multiset.prod` require `[CommMonoid α]`.
Often, there are collections `s : Finset α` where `[Monoid α]` and we know,
in a dependent fashion, that for all the terms `∀ (x ∈ s) (y ∈ s), Commute x y`.
This allows to still have a well-defined product over `s`.
## Main definitions
- `Finset.noncommProd`, requiring a proof of commutativity of held terms
- `Multiset.noncommProd`, requiring a proof of commutativity of held terms
## Implementation details
While `List.prod` is defined via `List.foldl`, `noncommProd` is defined via
`Multiset.foldr` for neater proofs and definitions. By the commutativity assumption,
the two must be equal.
TODO: Tidy up this file by using the fact that the submonoid generated by commuting
elements is commutative and using the `Finset.prod` versions of lemmas to prove the `noncommProd`
version.
-/
variable {F ι α β γ : Type*} (f : α → β → β) (op : α → α → α)
namespace Multiset
/-- Fold of a `s : Multiset α` with `f : α → β → β`, given a proof that `LeftCommutative f`
on all elements `x ∈ s`. -/
def noncommFoldr (s : Multiset α)
(comm : { x | x ∈ s }.Pairwise fun x y => ∀ b, f x (f y b) = f y (f x b)) (b : β) : β :=
letI : LeftCommutative (α := { x // x ∈ s }) (f ∘ Subtype.val) :=
⟨fun ⟨_, hx⟩ ⟨_, hy⟩ =>
haveI : IsRefl α fun x y => ∀ b, f x (f y b) = f y (f x b) := ⟨fun _ _ => rfl⟩
comm.of_refl hx hy⟩
s.attach.foldr (f ∘ Subtype.val) b
@[simp]
theorem noncommFoldr_coe (l : List α) (comm) (b : β) :
noncommFoldr f (l : Multiset α) comm b = l.foldr f b := by
simp only [noncommFoldr, coe_foldr, coe_attach, List.attach, List.attachWith, Function.comp_def]
rw [← List.foldr_map]
simp [List.map_pmap]
@[simp]
theorem noncommFoldr_empty (h) (b : β) : noncommFoldr f (0 : Multiset α) h b = b :=
rfl
theorem noncommFoldr_cons (s : Multiset α) (a : α) (h h') (b : β) :
noncommFoldr f (a ::ₘ s) h b = f a (noncommFoldr f s h' b) := by
induction s using Quotient.inductionOn
simp
|
theorem noncommFoldr_eq_foldr (s : Multiset α) [h : LeftCommutative f] (b : β) :
noncommFoldr f s (fun x _ y _ _ => h.left_comm x y) b = foldr f b s := by
induction s using Quotient.inductionOn
| Mathlib/Data/Finset/NoncommProd.lean | 64 | 67 |
/-
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yaël Dillies, Patrick Stevens
-/
import Mathlib.Algebra.CharZero.Defs
import Mathlib.Data.Nat.Cast.Basic
import Mathlib.Tactic.Common
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.GroupWithZero.Units.Basic
/-!
# Cast of naturals into fields
This file concerns the canonical homomorphism `ℕ → F`, where `F` is a field.
## Main results
* `Nat.cast_div`: if `n` divides `m`, then `↑(m / n) = ↑m / ↑n`
-/
namespace Nat
variable {K : Type*} [DivisionSemiring K] {d m n : ℕ}
@[simp]
lemma cast_div (hnm : n ∣ m) (hn : (n : K) ≠ 0) : (↑(m / n) : K) = m / n := by
obtain ⟨k, rfl⟩ := hnm
have : n ≠ 0 := by rintro rfl; simp at hn
rw [Nat.mul_div_cancel_left _ <| zero_lt_of_ne_zero this, mul_comm n,
cast_mul, mul_div_cancel_right₀ _ hn]
variable [CharZero K]
@[simp, norm_cast]
lemma cast_div_charZero (hnm : n ∣ m) : (↑(m / n) : K) = m / n := by
obtain rfl | hn := eq_or_ne n 0 <;> simp [*]
lemma cast_div_div_div_cancel_right (hn : d ∣ n) (hm : d ∣ m) :
(↑(m / d) : K) / (↑(n / d) : K) = (m : K) / n := by
rcases eq_or_ne d 0 with (rfl | hd); · simp [Nat.zero_dvd.1 hm]
replace hd : (d : K) ≠ 0 := by norm_cast
rw [cast_div hm, cast_div hn, div_div_div_cancel_right₀ hd] <;> exact hd
end Nat
| Mathlib/Data/Nat/Cast/Field.lean | 70 | 73 | |
/-
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.Order.Antidiag.Finsupp
import Mathlib.Data.Finsupp.Weight
import Mathlib.Tactic.Linarith
import Mathlib.LinearAlgebra.Pi
import Mathlib.Algebra.MvPolynomial.Eval
/-!
# Formal (multivariate) power series
This file defines multivariate 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.
We provide the natural inclusion from multivariate polynomials to multivariate formal power series.
## Main definitions
- `MvPowerSeries.C`: constant power series
- `MvPowerSeries.X`: the indeterminates
- `MvPowerSeries.coeff`, `MvPowerSeries.constantCoeff`:
the coefficients of a `MvPowerSeries`, its constant coefficient
- `MvPowerSeries.monomial`: the monomials
- `MvPowerSeries.coeff_mul`: computes the coefficients of the product of two `MvPowerSeries`
- `MvPowerSeries.coeff_prod` : computes the coefficients of products of `MvPowerSeries`
- `MvPowerSeries.coeff_pow` : computes the coefficients of powers of a `MvPowerSeries`
- `MvPowerSeries.coeff_eq_zero_of_constantCoeff_nilpotent`: if the constant coefficient
of a `MvPowerSeries` is nilpotent, then some coefficients of its powers are automatically zero
- `MvPowerSeries.map`: apply a `RingHom` to the coefficients of a `MvPowerSeries` (as a `RingHom)
- `MvPowerSeries.X_pow_dvd_iff`, `MvPowerSeries.X_dvd_iff`: equivalent
conditions for (a power of) an indeterminate to divide a `MvPowerSeries`
- `MvPolynomial.toMvPowerSeries`: the canonical coercion from `MvPolynomial` to `MvPowerSeries`
## Note
This file sets up the (semi)ring structure on multivariate power series:
additional results are in:
* `Mathlib.RingTheory.MvPowerSeries.Inverse` : invertibility,
formal power series over a local ring form a local ring;
* `Mathlib.RingTheory.MvPowerSeries.Trunc`: truncation of power series.
In `Mathlib.RingTheory.PowerSeries.Basic`, formal power series in one variable
will be obtained as a particular case, defined by
`PowerSeries R := MvPowerSeries Unit R`.
See that file for a specific description.
## Implementation notes
In this file we define multivariate formal power series with
variables indexed by `σ` and coefficients in `R` as
`MvPowerSeries σ R := (σ →₀ ℕ) → R`.
Unfortunately there is not yet enough API to show that they are the completion
of the ring of multivariate polynomials. However, we provide most of the infrastructure
that is needed to do this. Once I-adic completion (topological or algebraic) is available
it should not be hard to fill in the details.
-/
noncomputable section
open Finset (antidiagonal mem_antidiagonal)
/-- Multivariate formal power series, where `σ` is the index set of the variables
and `R` is the coefficient ring. -/
def MvPowerSeries (σ : Type*) (R : Type*) :=
(σ →₀ ℕ) → R
namespace MvPowerSeries
open Finsupp
variable {σ R : Type*}
instance [Inhabited R] : Inhabited (MvPowerSeries σ R) :=
⟨fun _ => default⟩
instance [Zero R] : Zero (MvPowerSeries σ R) :=
Pi.instZero
instance [AddMonoid R] : AddMonoid (MvPowerSeries σ R) :=
Pi.addMonoid
instance [AddGroup R] : AddGroup (MvPowerSeries σ R) :=
Pi.addGroup
instance [AddCommMonoid R] : AddCommMonoid (MvPowerSeries σ R) :=
Pi.addCommMonoid
instance [AddCommGroup R] : AddCommGroup (MvPowerSeries σ R) :=
Pi.addCommGroup
instance [Nontrivial R] : Nontrivial (MvPowerSeries σ R) :=
Function.nontrivial
instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R (MvPowerSeries σ A) :=
Pi.module _ _ _
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 (MvPowerSeries σ A) :=
Pi.isScalarTower
section Semiring
variable (R) [Semiring R]
/-- The `n`th monomial as multivariate formal power series:
it is defined as the `R`-linear map from `R` to the semi-ring
of multivariate formal power series associating to each `a`
the map sending `n : σ →₀ ℕ` to the value `a`
and sending all other `x : σ →₀ ℕ` different from `n` to `0`. -/
def monomial (n : σ →₀ ℕ) : R →ₗ[R] MvPowerSeries σ R :=
letI := Classical.decEq σ
LinearMap.single R (fun _ ↦ R) n
/-- The `n`th coefficient of a multivariate formal power series. -/
def coeff (n : σ →₀ ℕ) : MvPowerSeries σ R →ₗ[R] R :=
LinearMap.proj n
theorem coeff_apply (f : MvPowerSeries σ R) (d : σ →₀ ℕ) : coeff R d f = f d :=
rfl
variable {R}
/-- Two multivariate formal power series are equal if all their coefficients are equal. -/
@[ext]
theorem ext {φ ψ} (h : ∀ n : σ →₀ ℕ, coeff R n φ = coeff R n ψ) : φ = ψ :=
funext h
/-- Two multivariate formal power series are equal
if and only if all their coefficients are equal. -/
add_decl_doc MvPowerSeries.ext_iff
theorem monomial_def [DecidableEq σ] (n : σ →₀ ℕ) :
(monomial R n) = LinearMap.single R (fun _ ↦ R) n := by
rw [monomial]
-- unify the `Decidable` arguments
convert rfl
theorem coeff_monomial [DecidableEq σ] (m n : σ →₀ ℕ) (a : R) :
coeff R m (monomial R n a) = if m = n then a else 0 := by
dsimp only [coeff, MvPowerSeries]
rw [monomial_def, LinearMap.proj_apply (i := m), LinearMap.single_apply, Pi.single_apply]
@[simp]
theorem coeff_monomial_same (n : σ →₀ ℕ) (a : R) : coeff R n (monomial R n a) = a := by
classical
rw [monomial_def]
exact Pi.single_eq_same _ _
theorem coeff_monomial_ne {m n : σ →₀ ℕ} (h : m ≠ n) (a : R) : coeff R m (monomial R n a) = 0 := by
classical
rw [monomial_def]
exact Pi.single_eq_of_ne h _
theorem eq_of_coeff_monomial_ne_zero {m n : σ →₀ ℕ} {a : R} (h : coeff R m (monomial R n a) ≠ 0) :
m = n :=
by_contra fun h' => h <| coeff_monomial_ne h' a
@[simp]
theorem coeff_comp_monomial (n : σ →₀ ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id :=
LinearMap.ext <| coeff_monomial_same n
@[simp]
theorem coeff_zero (n : σ →₀ ℕ) : coeff R n (0 : MvPowerSeries σ R) = 0 :=
rfl
theorem eq_zero_iff_forall_coeff_zero {f : MvPowerSeries σ R} :
f = 0 ↔ (∀ d : σ →₀ ℕ, coeff R d f = 0) :=
MvPowerSeries.ext_iff
theorem ne_zero_iff_exists_coeff_ne_zero (f : MvPowerSeries σ R) :
f ≠ 0 ↔ (∃ d : σ →₀ ℕ, coeff R d f ≠ 0) := by
simp only [MvPowerSeries.ext_iff, ne_eq, coeff_zero, not_forall]
variable (m n : σ →₀ ℕ) (φ ψ : MvPowerSeries σ R)
instance : One (MvPowerSeries σ R) :=
⟨monomial R (0 : σ →₀ ℕ) 1⟩
theorem coeff_one [DecidableEq σ] : coeff R n (1 : MvPowerSeries σ R) = if n = 0 then 1 else 0 :=
coeff_monomial _ _ _
theorem coeff_zero_one : coeff R (0 : σ →₀ ℕ) 1 = 1 :=
coeff_monomial_same 0 1
theorem monomial_zero_one : monomial R (0 : σ →₀ ℕ) 1 = 1 :=
rfl
instance : AddMonoidWithOne (MvPowerSeries σ R) :=
{ show AddMonoid (MvPowerSeries σ R) by infer_instance with
natCast := fun n => monomial R 0 n
natCast_zero := by simp [Nat.cast]
natCast_succ := by simp [Nat.cast, monomial_zero_one]
one := 1 }
instance : Mul (MvPowerSeries σ R) :=
letI := Classical.decEq σ
⟨fun φ ψ n => ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ⟩
theorem coeff_mul [DecidableEq σ] :
coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by
refine Finset.sum_congr ?_ fun _ _ => rfl
rw [Subsingleton.elim (Classical.decEq σ) ‹DecidableEq σ›]
protected theorem zero_mul : (0 : MvPowerSeries σ R) * φ = 0 :=
ext fun n => by classical simp [coeff_mul]
protected theorem mul_zero : φ * 0 = 0 :=
ext fun n => by classical simp [coeff_mul]
theorem coeff_monomial_mul (a : R) :
coeff R m (monomial R n a * φ) = if n ≤ m then a * coeff R (m - n) φ else 0 := by
classical
have :
∀ p ∈ antidiagonal m,
coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 (monomial R n a) * coeff R p.2 φ ≠ 0 → p.1 = n :=
fun p _ hp => eq_of_coeff_monomial_ne_zero (left_ne_zero_of_mul hp)
rw [coeff_mul, ← Finset.sum_filter_of_ne this, Finset.filter_fst_eq_antidiagonal _ n,
Finset.sum_ite_index]
simp only [Finset.sum_singleton, coeff_monomial_same, Finset.sum_empty]
theorem coeff_mul_monomial (a : R) :
coeff R m (φ * monomial R n a) = if n ≤ m then coeff R (m - n) φ * a else 0 := by
classical
have :
∀ p ∈ antidiagonal m,
coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 φ * coeff R p.2 (monomial R n a) ≠ 0 → p.2 = n :=
fun p _ hp => eq_of_coeff_monomial_ne_zero (right_ne_zero_of_mul hp)
rw [coeff_mul, ← Finset.sum_filter_of_ne this, Finset.filter_snd_eq_antidiagonal _ n,
Finset.sum_ite_index]
simp only [Finset.sum_singleton, coeff_monomial_same, Finset.sum_empty]
theorem coeff_add_monomial_mul (a : R) :
coeff R (m + n) (monomial R m a * φ) = a * coeff R n φ := by
rw [coeff_monomial_mul, if_pos, add_tsub_cancel_left]
exact le_add_right le_rfl
theorem coeff_add_mul_monomial (a : R) :
coeff R (m + n) (φ * monomial R n a) = coeff R m φ * a := by
rw [coeff_mul_monomial, if_pos, add_tsub_cancel_right]
exact le_add_left le_rfl
@[simp]
theorem commute_monomial {a : R} {n} :
Commute φ (monomial R n a) ↔ ∀ m, Commute (coeff R m φ) a := by
rw [commute_iff_eq, MvPowerSeries.ext_iff]
refine ⟨fun h m => ?_, fun h m => ?_⟩
· have := h (m + n)
rwa [coeff_add_mul_monomial, add_comm, coeff_add_monomial_mul] at this
· rw [coeff_mul_monomial, coeff_monomial_mul]
split_ifs <;> [apply h; rfl]
protected theorem one_mul : (1 : MvPowerSeries σ R) * φ = φ :=
ext fun n => by simpa using coeff_add_monomial_mul 0 n φ 1
protected theorem mul_one : φ * 1 = φ :=
ext fun n => by simpa using coeff_add_mul_monomial n 0 φ 1
protected theorem mul_add (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : φ₁ * (φ₂ + φ₃) = φ₁ * φ₂ + φ₁ * φ₃ :=
ext fun n => by
classical simp only [coeff_mul, mul_add, Finset.sum_add_distrib, LinearMap.map_add]
protected theorem add_mul (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : (φ₁ + φ₂) * φ₃ = φ₁ * φ₃ + φ₂ * φ₃ :=
ext fun n => by
classical simp only [coeff_mul, add_mul, Finset.sum_add_distrib, LinearMap.map_add]
protected theorem mul_assoc (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : φ₁ * φ₂ * φ₃ = φ₁ * (φ₂ * φ₃) := by
ext1 n
classical
simp only [coeff_mul, Finset.sum_mul, Finset.mul_sum, Finset.sum_sigma']
apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l + j), (l, j)⟩)
(fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i + k, l), (i, k)⟩) <;> aesop (add simp [add_assoc, mul_assoc])
instance : Semiring (MvPowerSeries σ R) :=
{ inferInstanceAs (AddMonoidWithOne (MvPowerSeries σ R)),
inferInstanceAs (Mul (MvPowerSeries σ R)),
inferInstanceAs (AddCommMonoid (MvPowerSeries σ R)) with
mul_one := MvPowerSeries.mul_one
one_mul := MvPowerSeries.one_mul
mul_assoc := MvPowerSeries.mul_assoc
mul_zero := MvPowerSeries.mul_zero
zero_mul := MvPowerSeries.zero_mul
left_distrib := MvPowerSeries.mul_add
right_distrib := MvPowerSeries.add_mul }
end Semiring
instance [CommSemiring R] : CommSemiring (MvPowerSeries σ R) :=
{ show Semiring (MvPowerSeries σ R) by infer_instance with
mul_comm := fun φ ψ =>
ext fun n => by
classical
simpa only [coeff_mul, mul_comm] using
sum_antidiagonal_swap n fun a b => coeff R a φ * coeff R b ψ }
instance [Ring R] : Ring (MvPowerSeries σ R) :=
{ inferInstanceAs (Semiring (MvPowerSeries σ R)),
inferInstanceAs (AddCommGroup (MvPowerSeries σ R)) with }
instance [CommRing R] : CommRing (MvPowerSeries σ R) :=
{ inferInstanceAs (CommSemiring (MvPowerSeries σ R)),
inferInstanceAs (AddCommGroup (MvPowerSeries σ R)) with }
section Semiring
variable [Semiring R]
theorem monomial_mul_monomial (m n : σ →₀ ℕ) (a b : R) :
monomial R m a * monomial R n b = monomial R (m + n) (a * b) := by
classical
ext k
simp only [coeff_mul_monomial, coeff_monomial]
split_ifs with h₁ h₂ h₃ h₃ h₂ <;> try rfl
· rw [← h₂, tsub_add_cancel_of_le h₁] at h₃
exact (h₃ rfl).elim
· rw [h₃, add_tsub_cancel_right] at h₂
exact (h₂ rfl).elim
· exact zero_mul b
· rw [h₂] at h₁
exact (h₁ <| le_add_left le_rfl).elim
variable (σ) (R)
/-- The constant multivariate formal power series. -/
def C : R →+* MvPowerSeries σ R :=
{ monomial R (0 : σ →₀ ℕ) with
map_one' := rfl
map_mul' := fun a b => (monomial_mul_monomial 0 0 a b).symm
map_zero' := (monomial R 0).map_zero }
variable {σ} {R}
@[simp]
theorem monomial_zero_eq_C : ⇑(monomial R (0 : σ →₀ ℕ)) = C σ R :=
rfl
theorem monomial_zero_eq_C_apply (a : R) : monomial R (0 : σ →₀ ℕ) a = C σ R a :=
rfl
theorem coeff_C [DecidableEq σ] (n : σ →₀ ℕ) (a : R) :
coeff R n (C σ R a) = if n = 0 then a else 0 :=
coeff_monomial _ _ _
theorem coeff_zero_C (a : R) : coeff R (0 : σ →₀ ℕ) (C σ R a) = a :=
coeff_monomial_same 0 a
/-- The variables of the multivariate formal power series ring. -/
def X (s : σ) : MvPowerSeries σ R :=
monomial R (single s 1) 1
theorem coeff_X [DecidableEq σ] (n : σ →₀ ℕ) (s : σ) :
coeff R n (X s : MvPowerSeries σ R) = if n = single s 1 then 1 else 0 :=
coeff_monomial _ _ _
theorem coeff_index_single_X [DecidableEq σ] (s t : σ) :
coeff R (single t 1) (X s : MvPowerSeries σ R) = if t = s then 1 else 0 := by
simp only [coeff_X, single_left_inj (one_ne_zero : (1 : ℕ) ≠ 0)]
@[simp]
theorem coeff_index_single_self_X (s : σ) : coeff R (single s 1) (X s : MvPowerSeries σ R) = 1 :=
coeff_monomial_same _ _
theorem coeff_zero_X (s : σ) : coeff R (0 : σ →₀ ℕ) (X s : MvPowerSeries σ R) = 0 := by
classical
rw [coeff_X, if_neg]
intro h
exact one_ne_zero (single_eq_zero.mp h.symm)
theorem commute_X (φ : MvPowerSeries σ R) (s : σ) : Commute φ (X s) :=
φ.commute_monomial.mpr fun _m => Commute.one_right _
theorem X_mul {φ : MvPowerSeries σ R} {s : σ} : X s * φ = φ * X s :=
φ.commute_X s |>.symm.eq
theorem commute_X_pow (φ : MvPowerSeries σ R) (s : σ) (n : ℕ) : Commute φ (X s ^ n) :=
φ.commute_X s |>.pow_right _
theorem X_pow_mul {φ : MvPowerSeries σ R} {s : σ} {n : ℕ} : X s ^ n * φ = φ * X s ^ n :=
φ.commute_X_pow s n |>.symm.eq
theorem X_def (s : σ) : X s = monomial R (single s 1) 1 :=
rfl
theorem X_pow_eq (s : σ) (n : ℕ) : (X s : MvPowerSeries σ R) ^ n = monomial R (single s n) 1 := by
induction n with
| zero => simp
| succ n ih => rw [pow_succ, ih, Finsupp.single_add, X, monomial_mul_monomial, one_mul]
theorem coeff_X_pow [DecidableEq σ] (m : σ →₀ ℕ) (s : σ) (n : ℕ) :
coeff R m ((X s : MvPowerSeries σ R) ^ n) = if m = single s n then 1 else 0 := by
rw [X_pow_eq s n, coeff_monomial]
@[simp]
theorem coeff_mul_C (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (a : R) :
coeff R n (φ * C σ R a) = coeff R n φ * a := by simpa using coeff_add_mul_monomial n 0 φ a
@[simp]
theorem coeff_C_mul (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (a : R) :
coeff R n (C σ R a * φ) = a * coeff R n φ := by simpa using coeff_add_monomial_mul 0 n φ a
theorem coeff_zero_mul_X (φ : MvPowerSeries σ R) (s : σ) : coeff R (0 : σ →₀ ℕ) (φ * X s) = 0 := by
have : ¬single s 1 ≤ 0 := fun h => by simpa using h s
simp only [X, coeff_mul_monomial, if_neg this]
theorem coeff_zero_X_mul (φ : MvPowerSeries σ R) (s : σ) : coeff R (0 : σ →₀ ℕ) (X s * φ) = 0 := by
rw [← (φ.commute_X s).eq, coeff_zero_mul_X]
variable (σ) (R)
/-- The constant coefficient of a formal power series. -/
def constantCoeff : MvPowerSeries σ R →+* R :=
{ coeff R (0 : σ →₀ ℕ) with
| toFun := coeff R (0 : σ →₀ ℕ)
map_one' := coeff_zero_one
| Mathlib/RingTheory/MvPowerSeries/Basic.lean | 431 | 432 |
/-
Copyright (c) 2024 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Kontorovich, David Loeffler, Heather Macbeth, Sébastien Gouëzel
-/
import Mathlib.Analysis.Calculus.ParametricIntegral
import Mathlib.Analysis.Calculus.ContDiff.CPolynomial
import Mathlib.Analysis.Fourier.AddCircle
import Mathlib.Analysis.Fourier.FourierTransform
import Mathlib.Analysis.Calculus.FDeriv.Analytic
import Mathlib.Analysis.Calculus.LineDeriv.IntegrationByParts
import Mathlib.Analysis.Calculus.ContDiff.Bounds
/-!
# Derivatives of the Fourier transform
In this file we compute the Fréchet derivative of the Fourier transform of `f`, where `f` is a
function such that both `f` and `v ↦ ‖v‖ * ‖f v‖` are integrable. Here the Fourier transform is
understood as an operator `(V → E) → (W → E)`, where `V` and `W` are normed `ℝ`-vector spaces
and the Fourier transform is taken with respect to a continuous `ℝ`-bilinear
pairing `L : V × W → ℝ` and a given reference measure `μ`.
We also investigate higher derivatives: Assuming that `‖v‖^n * ‖f v‖` is integrable, we show
that the Fourier transform of `f` is `C^n`.
We also study in a parallel way the Fourier transform of the derivative, which is obtained by
tensoring the Fourier transform of the original function with the bilinear form. We also get
results for iterated derivatives.
A consequence of these results is that, if a function is smooth and all its derivatives are
integrable when multiplied by `‖v‖^k`, then the same goes for its Fourier transform, with
explicit bounds.
We give specialized versions of these results on inner product spaces (where `L` is the scalar
product) and on the real line, where we express the one-dimensional derivative in more concrete
terms, as the Fourier transform of `-2πI x * f x` (or `(-2πI x)^n * f x` for higher derivatives).
## Main definitions and results
We introduce two convenience definitions:
* `VectorFourier.fourierSMulRight L f`: given `f : V → E` and `L` a bilinear pairing
between `V` and `W`, then this is the function `fun v ↦ -(2 * π * I) (L v ⬝) • f v`,
from `V` to `Hom (W, E)`.
This is essentially `ContinuousLinearMap.smulRight`, up to the factor `- 2πI` designed to make
sure that the Fourier integral of `fourierSMulRight L f` is the derivative of the Fourier
integral of `f`.
* `VectorFourier.fourierPowSMulRight` is the higher order analogue for higher derivatives:
`fourierPowSMulRight L f v n` is informally `(-(2 * π * I))^n (L v ⬝)^n • f v`, in
the space of continuous multilinear maps `W [×n]→L[ℝ] E`.
With these definitions, the statements read as follows, first in a general context
(arbitrary `L` and `μ`):
* `VectorFourier.hasFDerivAt_fourierIntegral`: the Fourier integral of `f` is differentiable, with
derivative the Fourier integral of `fourierSMulRight L f`.
* `VectorFourier.differentiable_fourierIntegral`: the Fourier integral of `f` is differentiable.
* `VectorFourier.fderiv_fourierIntegral`: formula for the derivative of the Fourier integral of `f`.
* `VectorFourier.fourierIntegral_fderiv`: formula for the Fourier integral of the derivative of `f`.
* `VectorFourier.hasFTaylorSeriesUpTo_fourierIntegral`: under suitable integrability conditions,
the Fourier integral of `f` has an explicit Taylor series up to order `N`, given by the Fourier
integrals of `fun v ↦ fourierPowSMulRight L f v n`.
* `VectorFourier.contDiff_fourierIntegral`: under suitable integrability conditions,
the Fourier integral of `f` is `C^n`.
* `VectorFourier.iteratedFDeriv_fourierIntegral`: under suitable integrability conditions,
explicit formula for the `n`-th derivative of the Fourier integral of `f`, as the Fourier
integral of `fun v ↦ fourierPowSMulRight L f v n`.
* `VectorFourier.pow_mul_norm_iteratedFDeriv_fourierIntegral_le`: explicit bounds for the `n`-th
derivative of the Fourier integral, multiplied by a power function, in terms of corresponding
integrals for the original function.
These statements are then specialized to the case of the usual Fourier transform on
finite-dimensional inner product spaces with their canonical Lebesgue measure (covering in
particular the case of the real line), replacing the namespace `VectorFourier` by
the namespace `Real` in the above statements.
We also give specialized versions of the one-dimensional real derivative (and iterated derivative)
in `Real.deriv_fourierIntegral` and `Real.iteratedDeriv_fourierIntegral`.
-/
noncomputable section
open Real Complex MeasureTheory Filter TopologicalSpace
open scoped FourierTransform Topology ContDiff
-- without this local instance, Lean tries first the instance
-- `secondCountableTopologyEither_of_right` (whose priority is 100) and takes a very long time to
-- fail. Since we only use the left instance in this file, we make sure it is tried first.
attribute [local instance 101] secondCountableTopologyEither_of_left
namespace Real
lemma hasDerivAt_fourierChar (x : ℝ) : HasDerivAt (𝐞 · : ℝ → ℂ) (2 * π * I * 𝐞 x) x := by
have h1 (y : ℝ) : 𝐞 y = fourier 1 (y : UnitAddCircle) := by
rw [fourierChar_apply, fourier_coe_apply]
push_cast
ring_nf
simpa only [h1, Int.cast_one, ofReal_one, div_one, mul_one] using hasDerivAt_fourier 1 1 x
lemma differentiable_fourierChar : Differentiable ℝ (𝐞 · : ℝ → ℂ) :=
fun x ↦ (Real.hasDerivAt_fourierChar x).differentiableAt
lemma deriv_fourierChar (x : ℝ) : deriv (𝐞 · : ℝ → ℂ) x = 2 * π * I * 𝐞 x :=
(Real.hasDerivAt_fourierChar x).deriv
variable {V W : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V]
[NormedAddCommGroup W] [NormedSpace ℝ W] (L : V →L[ℝ] W →L[ℝ] ℝ)
lemma hasFDerivAt_fourierChar_neg_bilinear_right (v : V) (w : W) :
HasFDerivAt (fun w ↦ (𝐞 (-L v w) : ℂ))
((-2 * π * I * 𝐞 (-L v w)) • (ofRealCLM ∘L (L v))) w := by
have ha : HasFDerivAt (fun w' : W ↦ L v w') (L v) w := ContinuousLinearMap.hasFDerivAt (L v)
convert (hasDerivAt_fourierChar (-L v w)).hasFDerivAt.comp w ha.neg using 1
ext y
simp only [neg_mul, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply,
Function.comp_apply, ofRealCLM_apply, smul_eq_mul, ContinuousLinearMap.comp_neg,
ContinuousLinearMap.neg_apply, ContinuousLinearMap.smulRight_apply,
ContinuousLinearMap.one_apply, real_smul, neg_inj]
ring
lemma fderiv_fourierChar_neg_bilinear_right_apply (v : V) (w y : W) :
fderiv ℝ (fun w ↦ (𝐞 (-L v w) : ℂ)) w y = -2 * π * I * L v y * 𝐞 (-L v w) := by
simp only [(hasFDerivAt_fourierChar_neg_bilinear_right L v w).fderiv, neg_mul,
ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply,
Function.comp_apply, ofRealCLM_apply, smul_eq_mul, neg_inj]
ring
lemma differentiable_fourierChar_neg_bilinear_right (v : V) :
Differentiable ℝ (fun w ↦ (𝐞 (-L v w) : ℂ)) :=
fun w ↦ (hasFDerivAt_fourierChar_neg_bilinear_right L v w).differentiableAt
lemma hasFDerivAt_fourierChar_neg_bilinear_left (v : V) (w : W) :
HasFDerivAt (fun v ↦ (𝐞 (-L v w) : ℂ))
((-2 * π * I * 𝐞 (-L v w)) • (ofRealCLM ∘L (L.flip w))) v :=
hasFDerivAt_fourierChar_neg_bilinear_right L.flip w v
lemma fderiv_fourierChar_neg_bilinear_left_apply (v y : V) (w : W) :
fderiv ℝ (fun v ↦ (𝐞 (-L v w) : ℂ)) v y = -2 * π * I * L y w * 𝐞 (-L v w) := by
simp only [(hasFDerivAt_fourierChar_neg_bilinear_left L v w).fderiv, neg_mul,
ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_comp', Pi.smul_apply,
Function.comp_apply, ContinuousLinearMap.flip_apply, ofRealCLM_apply, smul_eq_mul, neg_inj]
ring
lemma differentiable_fourierChar_neg_bilinear_left (w : W) :
Differentiable ℝ (fun v ↦ (𝐞 (-L v w) : ℂ)) :=
fun v ↦ (hasFDerivAt_fourierChar_neg_bilinear_left L v w).differentiableAt
end Real
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E]
namespace VectorFourier
variable {V W : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V]
[NormedAddCommGroup W] [NormedSpace ℝ W] (L : V →L[ℝ] W →L[ℝ] ℝ) (f : V → E)
/-- Send a function `f : V → E` to the function `f : V → Hom (W, E)` given by
`v ↦ (w ↦ -2 * π * I * L (v, w) • f v)`. This is designed so that the Fourier transform of
`fourierSMulRight L f` is the derivative of the Fourier transform of `f`. -/
def fourierSMulRight (v : V) : (W →L[ℝ] E) := -(2 * π * I) • (L v).smulRight (f v)
@[simp] lemma fourierSMulRight_apply (v : V) (w : W) :
fourierSMulRight L f v w = -(2 * π * I) • L v w • f v := rfl
/-- The `w`-derivative of the Fourier transform integrand. -/
lemma hasFDerivAt_fourierChar_smul (v : V) (w : W) :
HasFDerivAt (fun w' ↦ 𝐞 (-L v w') • f v) (𝐞 (-L v w) • fourierSMulRight L f v) w := by
have ha : HasFDerivAt (fun w' : W ↦ L v w') (L v) w := ContinuousLinearMap.hasFDerivAt (L v)
convert ((hasDerivAt_fourierChar (-L v w)).hasFDerivAt.comp w ha.neg).smul_const (f v)
ext w' : 1
simp_rw [fourierSMulRight, ContinuousLinearMap.smul_apply, ContinuousLinearMap.smulRight_apply]
rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.neg_apply,
ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, ← smul_assoc, smul_comm,
← smul_assoc, real_smul, real_smul, Submonoid.smul_def, smul_eq_mul]
push_cast
ring_nf
lemma norm_fourierSMulRight (L : V →L[ℝ] W →L[ℝ] ℝ) (f : V → E) (v : V) :
‖fourierSMulRight L f v‖ = (2 * π) * ‖L v‖ * ‖f v‖ := by
rw [fourierSMulRight, norm_smul _ (ContinuousLinearMap.smulRight (L v) (f v)),
norm_neg, norm_mul, norm_mul, norm_I, mul_one, Complex.norm_of_nonneg pi_pos.le,
Complex.norm_two, ContinuousLinearMap.norm_smulRight_apply, ← mul_assoc]
lemma norm_fourierSMulRight_le (L : V →L[ℝ] W →L[ℝ] ℝ) (f : V → E) (v : V) :
‖fourierSMulRight L f v‖ ≤ 2 * π * ‖L‖ * ‖v‖ * ‖f v‖ := calc
‖fourierSMulRight L f v‖ = (2 * π) * ‖L v‖ * ‖f v‖ := norm_fourierSMulRight _ _ _
_ ≤ (2 * π) * (‖L‖ * ‖v‖) * ‖f v‖ := by gcongr; exact L.le_opNorm _
_ = 2 * π * ‖L‖ * ‖v‖ * ‖f v‖ := by ring
lemma _root_.MeasureTheory.AEStronglyMeasurable.fourierSMulRight
[SecondCountableTopologyEither V (W →L[ℝ] ℝ)] [MeasurableSpace V] [BorelSpace V]
{L : V →L[ℝ] W →L[ℝ] ℝ} {f : V → E} {μ : Measure V}
(hf : AEStronglyMeasurable f μ) :
AEStronglyMeasurable (fun v ↦ fourierSMulRight L f v) μ := by
apply AEStronglyMeasurable.const_smul'
have aux0 : Continuous fun p : (W →L[ℝ] ℝ) × E ↦ p.1.smulRight p.2 :=
(ContinuousLinearMap.smulRightL ℝ W E).continuous₂
have aux1 : AEStronglyMeasurable (fun v ↦ (L v, f v)) μ :=
L.continuous.aestronglyMeasurable.prodMk hf
-- Elaboration without the expected type is faster here:
exact (aux0.comp_aestronglyMeasurable aux1 :)
variable {f}
/-- Main theorem of this section: if both `f` and `x ↦ ‖x‖ * ‖f x‖` are integrable, then the
Fourier transform of `f` has a Fréchet derivative (everywhere in its domain) and its derivative is
the Fourier transform of `smulRight L f`. -/
theorem hasFDerivAt_fourierIntegral
[MeasurableSpace V] [BorelSpace V] [SecondCountableTopology V] {μ : Measure V}
(hf : Integrable f μ) (hf' : Integrable (fun v : V ↦ ‖v‖ * ‖f v‖) μ) (w : W) :
HasFDerivAt (fourierIntegral 𝐞 μ L.toLinearMap₂ f)
(fourierIntegral 𝐞 μ L.toLinearMap₂ (fourierSMulRight L f) w) w := by
let F : W → V → E := fun w' v ↦ 𝐞 (-L v w') • f v
let F' : W → V → W →L[ℝ] E := fun w' v ↦ 𝐞 (-L v w') • fourierSMulRight L f v
let B : V → ℝ := fun v ↦ 2 * π * ‖L‖ * ‖v‖ * ‖f v‖
have h0 (w' : W) : Integrable (F w') μ :=
(fourierIntegral_convergent_iff continuous_fourierChar
(by apply L.continuous₂ : Continuous (fun p : V × W ↦ L.toLinearMap₂ p.1 p.2)) w').2 hf
have h1 : ∀ᶠ w' in 𝓝 w, AEStronglyMeasurable (F w') μ :=
Eventually.of_forall (fun w' ↦ (h0 w').aestronglyMeasurable)
have h3 : AEStronglyMeasurable (F' w) μ := by
refine .smul ?_ hf.1.fourierSMulRight
refine (continuous_fourierChar.comp ?_).aestronglyMeasurable
fun_prop
have h4 : (∀ᵐ v ∂μ, ∀ (w' : W), w' ∈ Metric.ball w 1 → ‖F' w' v‖ ≤ B v) := by
filter_upwards with v w' _
rw [Circle.norm_smul _ (fourierSMulRight L f v)]
exact norm_fourierSMulRight_le L f v
have h5 : Integrable B μ := by simpa only [← mul_assoc] using hf'.const_mul (2 * π * ‖L‖)
have h6 : ∀ᵐ v ∂μ, ∀ w', w' ∈ Metric.ball w 1 → HasFDerivAt (fun x ↦ F x v) (F' w' v) w' :=
ae_of_all _ (fun v w' _ ↦ hasFDerivAt_fourierChar_smul L f v w')
exact hasFDerivAt_integral_of_dominated_of_fderiv_le one_pos h1 (h0 w) h3 h4 h5 h6
lemma fderiv_fourierIntegral
[MeasurableSpace V] [BorelSpace V] [SecondCountableTopology V] {μ : Measure V}
(hf : Integrable f μ) (hf' : Integrable (fun v : V ↦ ‖v‖ * ‖f v‖) μ) :
fderiv ℝ (fourierIntegral 𝐞 μ L.toLinearMap₂ f) =
fourierIntegral 𝐞 μ L.toLinearMap₂ (fourierSMulRight L f) := by
ext w : 1
exact (hasFDerivAt_fourierIntegral L hf hf' w).fderiv
lemma differentiable_fourierIntegral
[MeasurableSpace V] [BorelSpace V] [SecondCountableTopology V] {μ : Measure V}
(hf : Integrable f μ) (hf' : Integrable (fun v : V ↦ ‖v‖ * ‖f v‖) μ) :
Differentiable ℝ (fourierIntegral 𝐞 μ L.toLinearMap₂ f) :=
fun w ↦ (hasFDerivAt_fourierIntegral L hf hf' w).differentiableAt
/-- The Fourier integral of the derivative of a function is obtained by multiplying the Fourier
integral of the original function by `-L w v`. -/
theorem fourierIntegral_fderiv [MeasurableSpace V] [BorelSpace V] [FiniteDimensional ℝ V]
{μ : Measure V} [Measure.IsAddHaarMeasure μ]
(hf : Integrable f μ) (h'f : Differentiable ℝ f) (hf' : Integrable (fderiv ℝ f) μ) :
fourierIntegral 𝐞 μ L.toLinearMap₂ (fderiv ℝ f)
= fourierSMulRight (-L.flip) (fourierIntegral 𝐞 μ L.toLinearMap₂ f) := by
ext w y
let g (v : V) : ℂ := 𝐞 (-L v w)
/- First rewrite things in a simplified form, without any real change. -/
suffices ∫ x, g x • fderiv ℝ f x y ∂μ = ∫ x, (2 * ↑π * I * L y w * g x) • f x ∂μ by
rw [fourierIntegral_continuousLinearMap_apply' hf']
simpa only [fourierIntegral, ContinuousLinearMap.toLinearMap₂_apply, fourierSMulRight_apply,
ContinuousLinearMap.neg_apply, ContinuousLinearMap.flip_apply, ← integral_smul, neg_smul,
smul_neg, ← smul_smul, coe_smul, neg_neg]
-- Key step: integrate by parts with respect to `y` to switch the derivative from `f` to `g`.
have A x : fderiv ℝ g x y = - 2 * ↑π * I * L y w * g x :=
fderiv_fourierChar_neg_bilinear_left_apply _ _ _ _
rw [integral_smul_fderiv_eq_neg_fderiv_smul_of_integrable, ← integral_neg]
· congr with x
simp only [A, neg_mul, neg_smul, neg_neg]
· have : Integrable (fun x ↦ (-(2 * ↑π * I * ↑((L y) w)) • ((g x : ℂ) • f x))) μ :=
((fourierIntegral_convergent_iff' _ _).2 hf).smul _
convert this using 2 with x
simp only [A, neg_mul, neg_smul, smul_smul]
· exact (fourierIntegral_convergent_iff' _ _).2 (hf'.apply_continuousLinearMap _)
· exact (fourierIntegral_convergent_iff' _ _).2 hf
· exact differentiable_fourierChar_neg_bilinear_left _ _
· exact h'f
/-- The formal multilinear series whose `n`-th term is
`(w₁, ..., wₙ) ↦ (-2πI)^n * L v w₁ * ... * L v wₙ • f v`, as a continuous multilinear map in
the space `W [×n]→L[ℝ] E`.
This is designed so that the Fourier transform of `v ↦ fourierPowSMulRight L f v n` is the
`n`-th derivative of the Fourier transform of `f`.
-/
def fourierPowSMulRight (f : V → E) (v : V) : FormalMultilinearSeries ℝ W E := fun n ↦
(- (2 * π * I))^n • ((ContinuousMultilinearMap.mkPiRing ℝ (Fin n) (f v)).compContinuousLinearMap
(fun _ ↦ L v))
/- Increase the priority to make sure that this lemma is used instead of
`FormalMultilinearSeries.apply_eq_prod_smul_coeff` even in dimension 1. -/
@[simp 1100] lemma fourierPowSMulRight_apply {f : V → E} {v : V} {n : ℕ} {m : Fin n → W} :
fourierPowSMulRight L f v n m = (- (2 * π * I))^n • (∏ i, L v (m i)) • f v := by
simp [fourierPowSMulRight]
open ContinuousMultilinearMap
/-- Decomposing `fourierPowSMulRight L f v n` as a composition of continuous bilinear and
multilinear maps, to deduce easily its continuity and differentiability properties. -/
lemma fourierPowSMulRight_eq_comp {f : V → E} {v : V} {n : ℕ} :
fourierPowSMulRight L f v n = (- (2 * π * I))^n • smulRightL ℝ (fun (_ : Fin n) ↦ W) E
(compContinuousLinearMapLRight
(ContinuousMultilinearMap.mkPiAlgebra ℝ (Fin n) ℝ) (fun _ ↦ L v)) (f v) := rfl
@[continuity, fun_prop]
lemma _root_.Continuous.fourierPowSMulRight {f : V → E} (hf : Continuous f) (n : ℕ) :
Continuous (fun v ↦ fourierPowSMulRight L f v n) := by
simp_rw [fourierPowSMulRight_eq_comp]
apply Continuous.const_smul
apply (smulRightL ℝ (fun (_ : Fin n) ↦ W) E).continuous₂.comp₂ _ hf
exact Continuous.comp (map_continuous _) (continuous_pi (fun _ ↦ L.continuous))
lemma _root_.ContDiff.fourierPowSMulRight
{f : V → E} {k : WithTop ℕ∞} (hf : ContDiff ℝ k f) (n : ℕ) :
ContDiff ℝ k (fun v ↦ fourierPowSMulRight L f v n) := by
simp_rw [fourierPowSMulRight_eq_comp]
apply ContDiff.const_smul
apply (smulRightL ℝ (fun (_ : Fin n) ↦ W) E).isBoundedBilinearMap.contDiff.comp₂ _ hf
apply (ContinuousMultilinearMap.contDiff _).comp
exact contDiff_pi.2 (fun _ ↦ L.contDiff)
lemma norm_fourierPowSMulRight_le (f : V → E) (v : V) (n : ℕ) :
‖fourierPowSMulRight L f v n‖ ≤ (2 * π * ‖L‖) ^ n * ‖v‖ ^ n * ‖f v‖ := by
apply ContinuousMultilinearMap.opNorm_le_bound (by positivity) (fun m ↦ ?_)
calc
‖fourierPowSMulRight L f v n m‖
= (2 * π) ^ n * ((∏ x : Fin n, |(L v) (m x)|) * ‖f v‖) := by
simp [abs_of_nonneg pi_nonneg, norm_smul]
_ ≤ (2 * π) ^ n * ((∏ x : Fin n, ‖L‖ * ‖v‖ * ‖m x‖) * ‖f v‖) := by
gcongr with i _hi
exact L.le_opNorm₂ v (m i)
_ = (2 * π * ‖L‖) ^ n * ‖v‖ ^ n * ‖f v‖ * ∏ i : Fin n, ‖m i‖ := by
simp [Finset.prod_mul_distrib, mul_pow]; ring
/-- The iterated derivative of a function multiplied by `(L v ⬝) ^ n` can be controlled in terms
of the iterated derivatives of the initial function. -/
lemma norm_iteratedFDeriv_fourierPowSMulRight
{f : V → E} {K : WithTop ℕ∞} {C : ℝ} (hf : ContDiff ℝ K f) {n : ℕ} {k : ℕ} (hk : k ≤ K)
{v : V} (hv : ∀ i ≤ k, ∀ j ≤ n, ‖v‖ ^ j * ‖iteratedFDeriv ℝ i f v‖ ≤ C) :
‖iteratedFDeriv ℝ k (fun v ↦ fourierPowSMulRight L f v n) v‖ ≤
(2 * π) ^ n * (2 * n + 2) ^ k * ‖L‖ ^ n * C := by
/- We write `fourierPowSMulRight L f v n` as a composition of bilinear and multilinear maps,
thanks to `fourierPowSMulRight_eq_comp`, and then we control the iterated derivatives of these
thanks to general bounds on derivatives of bilinear and multilinear maps. More precisely,
`fourierPowSMulRight L f v n m = (- (2 * π * I))^n • (∏ i, L v (m i)) • f v`. Here,
`(- (2 * π * I))^n` contributes `(2π)^n` to the bound. The second product is bilinear, so the
iterated derivative is controlled as a weighted sum of those of `v ↦ ∏ i, L v (m i)` and of `f`.
The harder part is to control the iterated derivatives of `v ↦ ∏ i, L v (m i)`. For this, one
argues that this is multilinear in `v`, to apply general bounds for iterated derivatives of
multilinear maps. More precisely, we write it as the composition of a multilinear map `T` (making
the product operation) and the tuple of linear maps `v ↦ (L v ⬝, ..., L v ⬝)` -/
simp_rw [fourierPowSMulRight_eq_comp]
-- first step: controlling the iterated derivatives of `v ↦ ∏ i, L v (m i)`, written below
-- as `v ↦ T (fun _ ↦ L v)`, or `T ∘ (ContinuousLinearMap.pi (fun (_ : Fin n) ↦ L))`.
let T : (W →L[ℝ] ℝ) [×n]→L[ℝ] (W [×n]→L[ℝ] ℝ) :=
compContinuousLinearMapLRight (ContinuousMultilinearMap.mkPiAlgebra ℝ (Fin n) ℝ)
have I₁ m : ‖iteratedFDeriv ℝ m T (fun _ ↦ L v)‖ ≤
n.descFactorial m * 1 * (‖L‖ * ‖v‖) ^ (n - m) := by
have : ‖T‖ ≤ 1 := by
apply (norm_compContinuousLinearMapLRight_le _ _).trans
simp only [norm_mkPiAlgebra, le_refl]
apply (ContinuousMultilinearMap.norm_iteratedFDeriv_le _ _ _).trans
simp only [Fintype.card_fin]
gcongr
refine (pi_norm_le_iff_of_nonneg (by positivity)).mpr (fun _ ↦ ?_)
exact ContinuousLinearMap.le_opNorm _ _
have I₂ m : ‖iteratedFDeriv ℝ m (T ∘ (ContinuousLinearMap.pi (fun (_ : Fin n) ↦ L))) v‖ ≤
(n.descFactorial m * 1 * (‖L‖ * ‖v‖) ^ (n - m)) * ‖L‖ ^ m := by
rw [ContinuousLinearMap.iteratedFDeriv_comp_right _ (ContinuousMultilinearMap.contDiff _)
_ (mod_cast le_top)]
apply (norm_compContinuousLinearMap_le _ _).trans
simp only [Finset.prod_const, Finset.card_fin]
gcongr
· exact I₁ m
· exact ContinuousLinearMap.norm_pi_le_of_le (fun _ ↦ le_rfl) (norm_nonneg _)
have I₃ m : ‖iteratedFDeriv ℝ m (T ∘ (ContinuousLinearMap.pi (fun (_ : Fin n) ↦ L))) v‖ ≤
n.descFactorial m * ‖L‖ ^ n * ‖v‖ ^ (n - m) := by
apply (I₂ m).trans (le_of_eq _)
rcases le_or_lt m n with hm | hm
· rw [show ‖L‖ ^ n = ‖L‖ ^ (m + (n - m)) by rw [Nat.add_sub_cancel' hm], pow_add]
ring
· simp only [Nat.descFactorial_eq_zero_iff_lt.mpr hm, CharP.cast_eq_zero, mul_one, zero_mul]
-- second step: factor out the `(2 * π) ^ n` factor, and cancel it on both sides.
have A : ContDiff ℝ K (fun y ↦ T (fun _ ↦ L y)) :=
(ContinuousMultilinearMap.contDiff _).comp (contDiff_pi.2 fun _ ↦ L.contDiff)
rw [iteratedFDeriv_const_smul_apply' (hf := ((smulRightL ℝ (fun _ ↦ W)
E).isBoundedBilinearMap.contDiff.comp₂ (A.of_le hk) (hf.of_le hk)).contDiffAt),
norm_smul (β := V [×k]→L[ℝ] (W [×n]→L[ℝ] E))]
simp only [mul_assoc, norm_pow, norm_neg, Complex.norm_mul, Complex.norm_ofNat, norm_real,
Real.norm_eq_abs, abs_of_nonneg pi_nonneg, norm_I, mul_one, smulRightL_apply, ge_iff_le]
gcongr
-- third step: argue that the scalar multiplication is bilinear to bound the iterated derivatives
-- of `v ↦ (∏ i, L v (m i)) • f v` in terms of those of `v ↦ (∏ i, L v (m i))` and of `f`.
-- The former are controlled by the first step, the latter by the assumptions.
apply (ContinuousLinearMap.norm_iteratedFDeriv_le_of_bilinear_of_le_one _ A hf _
hk ContinuousMultilinearMap.norm_smulRightL_le).trans
calc
∑ i ∈ Finset.range (k + 1),
k.choose i * ‖iteratedFDeriv ℝ i (fun (y : V) ↦ T (fun _ ↦ L y)) v‖ *
‖iteratedFDeriv ℝ (k - i) f v‖
≤ ∑ i ∈ Finset.range (k + 1),
k.choose i * (n.descFactorial i * ‖L‖ ^ n * ‖v‖ ^ (n - i)) *
‖iteratedFDeriv ℝ (k - i) f v‖ := by
gcongr with i _hi
exact I₃ i
_ = ∑ i ∈ Finset.range (k + 1), (k.choose i * n.descFactorial i * ‖L‖ ^ n) *
(‖v‖ ^ (n - i) * ‖iteratedFDeriv ℝ (k - i) f v‖) := by
congr with i
ring
_ ≤ ∑ i ∈ Finset.range (k + 1), (k.choose i * (n + 1 : ℕ) ^ k * ‖L‖ ^ n) * C := by
gcongr with i hi
· rw [← Nat.cast_pow, Nat.cast_le]
calc n.descFactorial i ≤ n ^ i := Nat.descFactorial_le_pow _ _
_ ≤ (n + 1) ^ i := by gcongr; omega
_ ≤ (n + 1) ^ k := by gcongr; exacts [le_add_self, Finset.mem_range_succ_iff.mp hi]
· exact hv _ (by omega) _ (by omega)
_ = (2 * n + 2) ^ k * (‖L‖^n * C) := by
simp only [← Finset.sum_mul, ← Nat.cast_sum, Nat.sum_range_choose, mul_one, ← mul_assoc,
Nat.cast_pow, Nat.cast_ofNat, Nat.cast_add, Nat.cast_one, ← mul_pow, mul_add]
variable [MeasurableSpace V] [BorelSpace V] {μ : Measure V}
section SecondCountableTopology
variable [SecondCountableTopology V]
lemma _root_.MeasureTheory.AEStronglyMeasurable.fourierPowSMulRight
(hf : AEStronglyMeasurable f μ) (n : ℕ) :
AEStronglyMeasurable (fun v ↦ fourierPowSMulRight L f v n) μ := by
simp_rw [fourierPowSMulRight_eq_comp]
apply AEStronglyMeasurable.const_smul'
apply (smulRightL ℝ (fun (_ : Fin n) ↦ W) E).continuous₂.comp_aestronglyMeasurable₂ _ hf
apply Continuous.aestronglyMeasurable
exact Continuous.comp (map_continuous _) (continuous_pi (fun _ ↦ L.continuous))
lemma integrable_fourierPowSMulRight {n : ℕ} (hf : Integrable (fun v ↦ ‖v‖ ^ n * ‖f v‖) μ)
(h'f : AEStronglyMeasurable f μ) : Integrable (fun v ↦ fourierPowSMulRight L f v n) μ := by
refine (hf.const_mul ((2 * π * ‖L‖) ^ n)).mono' (h'f.fourierPowSMulRight L n) ?_
filter_upwards with v
exact (norm_fourierPowSMulRight_le L f v n).trans (le_of_eq (by ring))
lemma hasFTaylorSeriesUpTo_fourierIntegral {N : WithTop ℕ∞}
(hf : ∀ (n : ℕ), n ≤ N → Integrable (fun v ↦ ‖v‖^n * ‖f v‖) μ)
(h'f : AEStronglyMeasurable f μ) :
HasFTaylorSeriesUpTo N (fourierIntegral 𝐞 μ L.toLinearMap₂ f)
(fun w n ↦ fourierIntegral 𝐞 μ L.toLinearMap₂ (fun v ↦ fourierPowSMulRight L f v n) w) := by
constructor
· intro w
rw [curry0_apply, Matrix.zero_empty, fourierIntegral_continuousMultilinearMap_apply'
(integrable_fourierPowSMulRight L (hf 0 bot_le) h'f)]
simp only [fourierPowSMulRight_apply, pow_zero, Finset.univ_eq_empty, Finset.prod_empty,
one_smul]
· intro n hn w
have I₁ : Integrable (fun v ↦ fourierPowSMulRight L f v n) μ :=
integrable_fourierPowSMulRight L (hf n hn.le) h'f
have I₂ : Integrable (fun v ↦ ‖v‖ * ‖fourierPowSMulRight L f v n‖) μ := by
apply ((hf (n+1) (ENat.add_one_natCast_le_withTop_of_lt hn)).const_mul
((2 * π * ‖L‖) ^ n)).mono'
(continuous_norm.aestronglyMeasurable.mul (h'f.fourierPowSMulRight L n).norm)
filter_upwards with v
simp only [Pi.mul_apply, norm_mul, norm_norm]
calc
‖v‖ * ‖fourierPowSMulRight L f v n‖
≤ ‖v‖ * ((2 * π * ‖L‖) ^ n * ‖v‖ ^ n * ‖f v‖) := by
gcongr; apply norm_fourierPowSMulRight_le
_ = (2 * π * ‖L‖) ^ n * (‖v‖ ^ (n + 1) * ‖f v‖) := by rw [pow_succ]; ring
have I₃ : Integrable (fun v ↦ fourierPowSMulRight L f v (n + 1)) μ :=
integrable_fourierPowSMulRight L (hf (n + 1) (ENat.add_one_natCast_le_withTop_of_lt hn)) h'f
have I₄ : Integrable
(fun v ↦ fourierSMulRight L (fun v ↦ fourierPowSMulRight L f v n) v) μ := by
apply (I₂.const_mul ((2 * π * ‖L‖))).mono' (h'f.fourierPowSMulRight L n).fourierSMulRight
filter_upwards with v
exact (norm_fourierSMulRight_le _ _ _).trans (le_of_eq (by ring))
have E : curryLeft
(fourierIntegral 𝐞 μ L.toLinearMap₂ (fun v ↦ fourierPowSMulRight L f v (n + 1)) w) =
fourierIntegral 𝐞 μ L.toLinearMap₂
(fourierSMulRight L fun v ↦ fourierPowSMulRight L f v n) w := by
ext w' m
rw [curryLeft_apply, fourierIntegral_continuousMultilinearMap_apply' I₃,
fourierIntegral_continuousLinearMap_apply' I₄,
fourierIntegral_continuousMultilinearMap_apply' (I₄.apply_continuousLinearMap _)]
congr with v
simp only [fourierPowSMulRight_apply, mul_comm, pow_succ, neg_mul, Fin.prod_univ_succ,
Fin.cons_zero, Fin.cons_succ, neg_smul, fourierSMulRight_apply, neg_apply, smul_apply,
smul_comm (M := ℝ) (N := ℂ) (α := E), smul_smul]
exact E ▸ hasFDerivAt_fourierIntegral L I₁ I₂ w
· intro n hn
apply fourierIntegral_continuous Real.continuous_fourierChar (by apply L.continuous₂)
exact integrable_fourierPowSMulRight L (hf n hn) h'f
/-- Variant of `hasFTaylorSeriesUpTo_fourierIntegral` in which the smoothness index is restricted
to `ℕ∞` (and so are the inequalities in the assumption `hf`). Avoids normcasting in some
applications. -/
lemma hasFTaylorSeriesUpTo_fourierIntegral' {N : ℕ∞}
(hf : ∀ (n : ℕ), n ≤ N → Integrable (fun v ↦ ‖v‖^n * ‖f v‖) μ)
(h'f : AEStronglyMeasurable f μ) :
HasFTaylorSeriesUpTo N (fourierIntegral 𝐞 μ L.toLinearMap₂ f)
(fun w n ↦ fourierIntegral 𝐞 μ L.toLinearMap₂ (fun v ↦ fourierPowSMulRight L f v n) w) :=
hasFTaylorSeriesUpTo_fourierIntegral _ (fun n hn ↦ hf n (mod_cast hn)) h'f
/-- If `‖v‖^n * ‖f v‖` is integrable for all `n ≤ N`, then the Fourier transform of `f` is `C^N`. -/
theorem contDiff_fourierIntegral {N : ℕ∞}
(hf : ∀ (n : ℕ), n ≤ N → Integrable (fun v ↦ ‖v‖ ^ n * ‖f v‖) μ) :
ContDiff ℝ N (fourierIntegral 𝐞 μ L.toLinearMap₂ f) := by
by_cases h'f : Integrable f μ
· exact (hasFTaylorSeriesUpTo_fourierIntegral' L hf h'f.1).contDiff
· have : fourierIntegral 𝐞 μ L.toLinearMap₂ f = 0 := by
ext w; simp [fourierIntegral, integral, h'f]
simpa [this] using contDiff_const
/-- If `‖v‖^n * ‖f v‖` is integrable for all `n ≤ N`, then the `n`-th derivative of the Fourier
transform of `f` is the Fourier transform of `fourierPowSMulRight L f v n`,
i.e., `(L v ⬝) ^ n • f v`. -/
lemma iteratedFDeriv_fourierIntegral {N : ℕ∞}
(hf : ∀ (n : ℕ), n ≤ N → Integrable (fun v ↦ ‖v‖^n * ‖f v‖) μ)
(h'f : AEStronglyMeasurable f μ) {n : ℕ} (hn : n ≤ N) :
iteratedFDeriv ℝ n (fourierIntegral 𝐞 μ L.toLinearMap₂ f) =
fourierIntegral 𝐞 μ L.toLinearMap₂ (fun v ↦ fourierPowSMulRight L f v n) := by
ext w : 1
exact ((hasFTaylorSeriesUpTo_fourierIntegral' L hf h'f).eq_iteratedFDeriv
(mod_cast hn) w).symm
end SecondCountableTopology
/-- The Fourier integral of the `n`-th derivative of a function is obtained by multiplying the
Fourier integral of the original function by `(2πI L w ⬝ )^n`. -/
theorem fourierIntegral_iteratedFDeriv [FiniteDimensional ℝ V]
{μ : Measure V} [Measure.IsAddHaarMeasure μ] {N : ℕ∞} (hf : ContDiff ℝ N f)
(h'f : ∀ (n : ℕ), n ≤ N → Integrable (iteratedFDeriv ℝ n f) μ) {n : ℕ} (hn : n ≤ N) :
fourierIntegral 𝐞 μ L.toLinearMap₂ (iteratedFDeriv ℝ n f)
= (fun w ↦ fourierPowSMulRight (-L.flip) (fourierIntegral 𝐞 μ L.toLinearMap₂ f) w n) := by
induction n with
| zero =>
ext w m
simp only [iteratedFDeriv_zero_apply, fourierPowSMulRight_apply, pow_zero,
Finset.univ_eq_empty, ContinuousLinearMap.neg_apply, ContinuousLinearMap.flip_apply,
Finset.prod_empty, one_smul, fourierIntegral_continuousMultilinearMap_apply' ((h'f 0 bot_le))]
| succ n ih =>
ext w m
have J : Integrable (fderiv ℝ (iteratedFDeriv ℝ n f)) μ := by
specialize h'f (n + 1) hn
rwa [iteratedFDeriv_succ_eq_comp_left, Function.comp_def,
LinearIsometryEquiv.integrable_comp_iff (𝕜 := ℝ) (φ := fderiv ℝ (iteratedFDeriv ℝ n f))]
at h'f
suffices H : (fourierIntegral 𝐞 μ L.toLinearMap₂ (fderiv ℝ (iteratedFDeriv ℝ n f)) w)
(m 0) (Fin.tail m) =
(-(2 * π * I)) ^ (n + 1) • (∏ x : Fin (n + 1), -L (m x) w) • ∫ v, 𝐞 (-L v w) • f v ∂μ by
rw [fourierIntegral_continuousMultilinearMap_apply' (h'f _ hn)]
simp only [iteratedFDeriv_succ_apply_left, fourierPowSMulRight_apply,
ContinuousLinearMap.neg_apply, ContinuousLinearMap.flip_apply]
rw [← fourierIntegral_continuousMultilinearMap_apply' ((J.apply_continuousLinearMap _)),
← fourierIntegral_continuousLinearMap_apply' J]
exact H
have h'n : n < N := (Nat.cast_lt.mpr n.lt_succ_self).trans_le hn
rw [fourierIntegral_fderiv _ (h'f n h'n.le)
(hf.differentiable_iteratedFDeriv (mod_cast h'n)) J]
simp only [ih h'n.le, fourierSMulRight_apply, ContinuousLinearMap.neg_apply,
ContinuousLinearMap.flip_apply, neg_smul, smul_neg, neg_neg, smul_apply,
fourierPowSMulRight_apply, ← coe_smul (E := E), smul_smul]
congr 1
simp only [ofReal_prod, ofReal_neg, pow_succ, mul_neg, Fin.prod_univ_succ, neg_mul,
ofReal_mul, neg_neg, Fin.tail_def]
ring
/-- The `k`-th derivative of the Fourier integral of `f`, multiplied by `(L v w) ^ n`, is the
Fourier integral of the `n`-th derivative of `(L v w) ^ k * f`. -/
theorem fourierPowSMulRight_iteratedFDeriv_fourierIntegral [FiniteDimensional ℝ V]
{μ : Measure V} [Measure.IsAddHaarMeasure μ] {K N : ℕ∞} (hf : ContDiff ℝ N f)
(h'f : ∀ (k n : ℕ), k ≤ K → n ≤ N → Integrable (fun v ↦ ‖v‖ ^ k * ‖iteratedFDeriv ℝ n f v‖) μ)
{k n : ℕ} (hk : k ≤ K) (hn : n ≤ N) {w : W} :
fourierPowSMulRight (-L.flip)
(iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w n =
fourierIntegral 𝐞 μ L.toLinearMap₂
(iteratedFDeriv ℝ n (fun v ↦ fourierPowSMulRight L f v k)) w := by
rw [fourierIntegral_iteratedFDeriv (N := N) _ (hf.fourierPowSMulRight _ _) _ hn]
· congr
rw [iteratedFDeriv_fourierIntegral (N := K) _ _ hf.continuous.aestronglyMeasurable hk]
intro k hk
simpa only [norm_iteratedFDeriv_zero] using h'f k 0 hk bot_le
· intro m hm
have I : Integrable (fun v ↦ ∑ p ∈ Finset.range (k + 1) ×ˢ Finset.range (m + 1),
‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖) μ := by
apply integrable_finset_sum _ (fun p hp ↦ ?_)
simp only [Finset.mem_product, Finset.mem_range_succ_iff] at hp
exact h'f _ _ ((Nat.cast_le.2 hp.1).trans hk) ((Nat.cast_le.2 hp.2).trans hm)
apply (I.const_mul ((2 * π) ^ k * (2 * k + 2) ^ m * ‖L‖ ^ k)).mono'
((hf.fourierPowSMulRight L k).continuous_iteratedFDeriv (mod_cast hm)).aestronglyMeasurable
filter_upwards with v
refine norm_iteratedFDeriv_fourierPowSMulRight _ hf (mod_cast hm) (fun i hi j hj ↦ ?_)
apply Finset.single_le_sum (f := fun p ↦ ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖) (a := (j, i))
· intro i _hi
positivity
· simpa only [Finset.mem_product, Finset.mem_range_succ_iff] using ⟨hj, hi⟩
/-- One can bound the `k`-th derivative of the Fourier integral of `f`, multiplied by `(L v w) ^ n`,
in terms of integrals of iterated derivatives of `f` (of order up to `n`) multiplied by `‖v‖ ^ i`
(for `i ≤ k`).
Auxiliary version in terms of the operator norm of `fourierPowSMulRight (-L.flip) ⬝`. For a version
in terms of `|L v w| ^ n * ⬝`, see `pow_mul_norm_iteratedFDeriv_fourierIntegral_le`.
-/
theorem norm_fourierPowSMulRight_iteratedFDeriv_fourierIntegral_le [FiniteDimensional ℝ V]
{μ : Measure V} [Measure.IsAddHaarMeasure μ] {K N : ℕ∞} (hf : ContDiff ℝ N f)
(h'f : ∀ (k n : ℕ), k ≤ K → n ≤ N → Integrable (fun v ↦ ‖v‖ ^ k * ‖iteratedFDeriv ℝ n f v‖) μ)
{k n : ℕ} (hk : k ≤ K) (hn : n ≤ N) {w : W} :
‖fourierPowSMulRight (-L.flip)
(iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w n‖ ≤
(2 * π) ^ k * (2 * k + 2) ^ n * ‖L‖ ^ k * ∑ p ∈ Finset.range (k + 1) ×ˢ Finset.range (n + 1),
∫ v, ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖ ∂μ := by
rw [fourierPowSMulRight_iteratedFDeriv_fourierIntegral L hf h'f hk hn]
apply (norm_fourierIntegral_le_integral_norm _ _ _ _ _).trans
have I p (hp : p ∈ Finset.range (k + 1) ×ˢ Finset.range (n + 1)) :
Integrable (fun v ↦ ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖) μ := by
simp only [Finset.mem_product, Finset.mem_range_succ_iff] at hp
exact h'f _ _ (le_trans (by simpa using hp.1) hk) (le_trans (by simpa using hp.2) hn)
rw [← integral_finset_sum _ I, ← integral_const_mul]
apply integral_mono_of_nonneg
· filter_upwards with v using norm_nonneg _
· exact (integrable_finset_sum _ I).const_mul _
· filter_upwards with v
apply norm_iteratedFDeriv_fourierPowSMulRight _ hf (mod_cast hn) _
intro i hi j hj
apply Finset.single_le_sum (f := fun p ↦ ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖) (a := (j, i))
· intro i _hi
positivity
· simp only [Finset.mem_product, Finset.mem_range_succ_iff]
exact ⟨hj, hi⟩
/-- One can bound the `k`-th derivative of the Fourier integral of `f`, multiplied by `(L v w) ^ n`,
in terms of integrals of iterated derivatives of `f` (of order up to `n`) multiplied by `‖v‖ ^ i`
(for `i ≤ k`). -/
lemma pow_mul_norm_iteratedFDeriv_fourierIntegral_le [FiniteDimensional ℝ V]
{μ : Measure V} [Measure.IsAddHaarMeasure μ] {K N : ℕ∞} (hf : ContDiff ℝ N f)
(h'f : ∀ (k n : ℕ), k ≤ K → n ≤ N → Integrable (fun v ↦ ‖v‖^k * ‖iteratedFDeriv ℝ n f v‖) μ)
{k n : ℕ} (hk : k ≤ K) (hn : n ≤ N) (v : V) (w : W) :
|L v w| ^ n * ‖(iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w‖ ≤
‖v‖ ^ n * (2 * π * ‖L‖) ^ k * (2 * k + 2) ^ n *
∑ p ∈ Finset.range (k + 1) ×ˢ Finset.range (n + 1),
∫ v, ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖ ∂μ := calc
|L v w| ^ n * ‖(iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w‖
_ ≤ (2 * π) ^ n
* (|L v w| ^ n * ‖iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f) w‖) := by
apply le_mul_of_one_le_left (by positivity)
apply one_le_pow₀
linarith [one_le_pi_div_two]
_ = ‖fourierPowSMulRight (-L.flip)
(iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w n (fun _ ↦ v)‖ := by
simp [norm_smul, abs_of_nonneg pi_nonneg]
_ ≤ ‖fourierPowSMulRight (-L.flip)
(iteratedFDeriv ℝ k (fourierIntegral 𝐞 μ L.toLinearMap₂ f)) w n‖ * ∏ _ : Fin n, ‖v‖ :=
le_opNorm _ _
_ ≤ ((2 * π) ^ k * (2 * k + 2) ^ n * ‖L‖ ^ k *
∑ p ∈ Finset.range (k + 1) ×ˢ Finset.range (n + 1),
∫ v, ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖ ∂μ) * ‖v‖ ^ n := by
gcongr
· apply norm_fourierPowSMulRight_iteratedFDeriv_fourierIntegral_le _ hf h'f hk hn
· simp
_ = ‖v‖ ^ n * (2 * π * ‖L‖) ^ k * (2 * k + 2) ^ n *
∑ p ∈ Finset.range (k + 1) ×ˢ Finset.range (n + 1),
∫ v, ‖v‖ ^ p.1 * ‖iteratedFDeriv ℝ p.2 f v‖ ∂μ := by
simp [mul_pow]
ring
end VectorFourier
namespace Real
open VectorFourier
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [FiniteDimensional ℝ V]
[MeasurableSpace V] [BorelSpace V] {f : V → E}
/-- The Fréchet derivative of the Fourier transform of `f` is the Fourier transform of
`fun v ↦ -2 * π * I ⟪v, ⬝⟫ f v`. -/
theorem hasFDerivAt_fourierIntegral
(hf_int : Integrable f) (hvf_int : Integrable (fun v ↦ ‖v‖ * ‖f v‖)) (x : V) :
HasFDerivAt (𝓕 f) (𝓕 (fourierSMulRight (innerSL ℝ) f) x) x :=
VectorFourier.hasFDerivAt_fourierIntegral (innerSL ℝ) hf_int hvf_int x
/-- The Fréchet derivative of the Fourier transform of `f` is the Fourier transform of
`fun v ↦ -2 * π * I ⟪v, ⬝⟫ f v`. -/
theorem fderiv_fourierIntegral
(hf_int : Integrable f) (hvf_int : Integrable (fun v ↦ ‖v‖ * ‖f v‖)) :
fderiv ℝ (𝓕 f) = 𝓕 (fourierSMulRight (innerSL ℝ) f) :=
VectorFourier.fderiv_fourierIntegral (innerSL ℝ) hf_int hvf_int
theorem differentiable_fourierIntegral
(hf_int : Integrable f) (hvf_int : Integrable (fun v ↦ ‖v‖ * ‖f v‖)) :
Differentiable ℝ (𝓕 f) :=
VectorFourier.differentiable_fourierIntegral (innerSL ℝ) hf_int hvf_int
/-- The Fourier integral of the Fréchet derivative of a function is obtained by multiplying the
Fourier integral of the original function by `2πI ⟪v, w⟫`. -/
theorem fourierIntegral_fderiv
(hf : Integrable f) (h'f : Differentiable ℝ f) (hf' : Integrable (fderiv ℝ f)) :
𝓕 (fderiv ℝ f) = fourierSMulRight (-innerSL ℝ) (𝓕 f) := by
| rw [← innerSL_real_flip V]
exact VectorFourier.fourierIntegral_fderiv (innerSL ℝ) hf h'f hf'
/-- If `‖v‖^n * ‖f v‖` is integrable, then the Fourier transform of `f` is `C^n`. -/
theorem contDiff_fourierIntegral {N : ℕ∞}
(hf : ∀ (n : ℕ), n ≤ N → Integrable (fun v ↦ ‖v‖ ^ n * ‖f v‖)) :
| Mathlib/Analysis/Fourier/FourierTransformDeriv.lean | 696 | 701 |
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johan Commelin
-/
import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic
/-!
# Minimal polynomials
This file defines the minimal polynomial of an element `x` of an `A`-algebra `B`,
under the assumption that x is integral over `A`, and derives some basic properties
such as irreducibility under the assumption `B` is a domain.
-/
open Polynomial Set Function
variable {A B B' : Type*}
section MinPolyDef
variable (A) [CommRing A] [Ring B] [Algebra A B]
open scoped Classical in
/-- Suppose `x : B`, where `B` is an `A`-algebra.
The minimal polynomial `minpoly A x` of `x`
is a monic polynomial with coefficients in `A` of smallest degree that has `x` as its root,
if such exists (`IsIntegral A x`) or zero otherwise.
For example, if `V` is a `𝕜`-vector space for some field `𝕜` and `f : V →ₗ[𝕜] V` then
the minimal polynomial of `f` is `minpoly 𝕜 f`.
-/
@[stacks 09GM]
noncomputable def minpoly (x : B) : A[X] :=
if hx : IsIntegral A x then degree_lt_wf.min _ hx else 0
end MinPolyDef
namespace minpoly
section Ring
variable [CommRing A] [Ring B] [Ring B'] [Algebra A B] [Algebra A B']
variable {x : B}
/-- A minimal polynomial is monic. -/
theorem monic (hx : IsIntegral A x) : Monic (minpoly A x) := by
delta minpoly
rw [dif_pos hx]
exact (degree_lt_wf.min_mem _ hx).1
/-- A minimal polynomial is nonzero. -/
theorem ne_zero [Nontrivial A] (hx : IsIntegral A x) : minpoly A x ≠ 0 :=
(monic hx).ne_zero
theorem eq_zero (hx : ¬IsIntegral A x) : minpoly A x = 0 :=
dif_neg hx
theorem ne_zero_iff [Nontrivial A] : minpoly A x ≠ 0 ↔ IsIntegral A x :=
⟨fun h => of_not_not <| eq_zero.mt h, ne_zero⟩
theorem algHom_eq (f : B →ₐ[A] B') (hf : Function.Injective f) (x : B) :
minpoly A (f x) = minpoly A x := by
classical
simp_rw [minpoly, isIntegral_algHom_iff _ hf, ← Polynomial.aeval_def, aeval_algHom,
AlgHom.comp_apply, _root_.map_eq_zero_iff f hf]
theorem algebraMap_eq {B} [CommRing B] [Algebra A B] [Algebra B B'] [IsScalarTower A B B']
(h : Function.Injective (algebraMap B B')) (x : B) :
minpoly A (algebraMap B B' x) = minpoly A x :=
algHom_eq (IsScalarTower.toAlgHom A B B') h x
@[simp]
theorem algEquiv_eq (f : B ≃ₐ[A] B') (x : B) : minpoly A (f x) = minpoly A x :=
algHom_eq (f : B →ₐ[A] B') f.injective x
variable (A x)
/-- An element is a root of its minimal polynomial. -/
@[simp]
theorem aeval : aeval x (minpoly A x) = 0 := by
delta minpoly
split_ifs with hx
· exact (degree_lt_wf.min_mem _ hx).2
· exact aeval_zero _
/-- Given any `f : B →ₐ[A] B'` and any `x : L`, the minimal polynomial of `x` vanishes at `f x`. -/
@[simp]
theorem aeval_algHom (f : B →ₐ[A] B') (x : B) : (Polynomial.aeval (f x)) (minpoly A x) = 0 := by
rw [Polynomial.aeval_algHom, AlgHom.coe_comp, comp_apply, aeval, map_zero]
/-- A minimal polynomial is not `1`. -/
theorem ne_one [Nontrivial B] : minpoly A x ≠ 1 := by
intro h
refine (one_ne_zero : (1 : B) ≠ 0) ?_
simpa using congr_arg (Polynomial.aeval x) h
theorem map_ne_one [Nontrivial B] {R : Type*} [Semiring R] [Nontrivial R] (f : A →+* R) :
(minpoly A x).map f ≠ 1 := by
by_cases hx : IsIntegral A x
· exact mt ((monic hx).eq_one_of_map_eq_one f) (ne_one A x)
· rw [eq_zero hx, Polynomial.map_zero]
exact zero_ne_one
/-- A minimal polynomial is not a unit. -/
theorem not_isUnit [Nontrivial B] : ¬IsUnit (minpoly A x) := by
haveI : Nontrivial A := (algebraMap A B).domain_nontrivial
by_cases hx : IsIntegral A x
· exact mt (monic hx).eq_one_of_isUnit (ne_one A x)
· rw [eq_zero hx]
exact not_isUnit_zero
theorem mem_range_of_degree_eq_one (hx : (minpoly A x).degree = 1) :
x ∈ (algebraMap A B).range := by
have h : IsIntegral A x := by
by_contra h
rw [eq_zero h, degree_zero, ← WithBot.coe_one] at hx
exact ne_of_lt (show ⊥ < ↑1 from WithBot.bot_lt_coe 1) hx
have key := minpoly.aeval A x
rw [eq_X_add_C_of_degree_eq_one hx, (minpoly.monic h).leadingCoeff, C_1, one_mul, aeval_add,
aeval_C, aeval_X, ← eq_neg_iff_add_eq_zero, ← RingHom.map_neg] at key
exact ⟨-(minpoly A x).coeff 0, key.symm⟩
/-- The defining property of the minimal polynomial of an element `x`:
it is the monic polynomial with smallest degree that has `x` as its root. -/
theorem min {p : A[X]} (pmonic : p.Monic) (hp : Polynomial.aeval x p = 0) :
degree (minpoly A x) ≤ degree p := by
delta minpoly; split_ifs with hx
· exact le_of_not_lt (degree_lt_wf.not_lt_min _ hx ⟨pmonic, hp⟩)
· simp only [degree_zero, bot_le]
theorem unique' {p : A[X]} (hm : p.Monic) (hp : Polynomial.aeval x p = 0)
(hl : ∀ q : A[X], degree q < degree p → q = 0 ∨ Polynomial.aeval x q ≠ 0) :
p = minpoly A x := by
nontriviality A
have hx : IsIntegral A x := ⟨p, hm, hp⟩
obtain h | h := hl _ ((minpoly A x).degree_modByMonic_lt hm)
swap
· exact (h <| (aeval_modByMonic_eq_self_of_root hm hp).trans <| aeval A x).elim
obtain ⟨r, hr⟩ := (modByMonic_eq_zero_iff_dvd hm).1 h
rw [hr]
have hlead := congr_arg leadingCoeff hr
rw [mul_comm, leadingCoeff_mul_monic hm, (monic hx).leadingCoeff] at hlead
have : natDegree r ≤ 0 := by
have hr0 : r ≠ 0 := by
rintro rfl
exact ne_zero hx (mul_zero p ▸ hr)
apply_fun natDegree at hr
rw [hm.natDegree_mul' hr0] at hr
apply Nat.le_of_add_le_add_left
rw [add_zero]
exact hr.symm.trans_le (natDegree_le_natDegree <| min A x hm hp)
rw [eq_C_of_natDegree_le_zero this, ← Nat.eq_zero_of_le_zero this, ← leadingCoeff, ← hlead, C_1,
mul_one]
@[nontriviality]
theorem subsingleton [Subsingleton B] : minpoly A x = 1 := by
nontriviality A
have := minpoly.min A x monic_one (Subsingleton.elim _ _)
rw [degree_one] at this
rcases le_or_lt (minpoly A x).degree 0 with h | h
· rwa [(monic ⟨1, monic_one, by simp [eq_iff_true_of_subsingleton]⟩ :
(minpoly A x).Monic).degree_le_zero_iff_eq_one] at h
· exact (this.not_lt h).elim
end Ring
section CommRing
variable [CommRing A]
section Ring
variable [Ring B] [Algebra A B]
variable {x : B}
/-- The degree of a minimal polynomial, as a natural number, is positive. -/
theorem natDegree_pos [Nontrivial B] (hx : IsIntegral A x) : 0 < natDegree (minpoly A x) := by
rw [pos_iff_ne_zero]
intro ndeg_eq_zero
have eq_one : minpoly A x = 1 := by
rw [eq_C_of_natDegree_eq_zero ndeg_eq_zero]
convert C_1 (R := A)
simpa only [ndeg_eq_zero.symm] using (monic hx).leadingCoeff
simpa only [eq_one, map_one, one_ne_zero] using aeval A x
/-- The degree of a minimal polynomial is positive. -/
theorem degree_pos [Nontrivial B] (hx : IsIntegral A x) : 0 < degree (minpoly A x) :=
natDegree_pos_iff_degree_pos.mp (natDegree_pos hx)
section
variable [Nontrivial B]
open Polynomial in
theorem degree_eq_one_iff : (minpoly A x).degree = 1 ↔ x ∈ (algebraMap A B).range := by
refine ⟨minpoly.mem_range_of_degree_eq_one _ _, ?_⟩
rintro ⟨x, rfl⟩
haveI := Module.nontrivial A B
exact (degree_X_sub_C x ▸ minpoly.min A (algebraMap A B x) (monic_X_sub_C x) (by simp)).antisymm
(Nat.WithBot.add_one_le_of_lt <| minpoly.degree_pos isIntegral_algebraMap)
theorem natDegree_eq_one_iff :
(minpoly A x).natDegree = 1 ↔ x ∈ (algebraMap A B).range := by
rw [← Polynomial.degree_eq_iff_natDegree_eq_of_pos zero_lt_one]
exact degree_eq_one_iff
theorem two_le_natDegree_iff (int : IsIntegral A x) :
2 ≤ (minpoly A x).natDegree ↔ x ∉ (algebraMap A B).range := by
rw [iff_not_comm, ← natDegree_eq_one_iff, not_le]
exact ⟨fun h ↦ h.trans_lt one_lt_two, fun h ↦ by linarith only [minpoly.natDegree_pos int, h]⟩
theorem two_le_natDegree_subalgebra {B} [CommRing B] [Algebra A B] [Nontrivial B]
{S : Subalgebra A B} {x : B} (int : IsIntegral S x) : 2 ≤ (minpoly S x).natDegree ↔ x ∉ S := by
rw [two_le_natDegree_iff int, Iff.not]
apply Set.ext_iff.mp Subtype.range_val_subtype
end
/-- If `B/A` is an injective ring extension, and `a` is an element of `A`,
then the minimal polynomial of `algebraMap A B a` is `X - C a`. -/
theorem eq_X_sub_C_of_algebraMap_inj (a : A) (hf : Function.Injective (algebraMap A B)) :
minpoly A (algebraMap A B a) = X - C a := by
nontriviality A
refine (unique' A _ (monic_X_sub_C a) ?_ ?_).symm
· rw [map_sub, aeval_C, aeval_X, sub_self]
simp_rw [or_iff_not_imp_left]
intro q hl h0
rw [← natDegree_lt_natDegree_iff h0, natDegree_X_sub_C, Nat.lt_one_iff] at hl
rw [eq_C_of_natDegree_eq_zero hl] at h0 ⊢
rwa [aeval_C, map_ne_zero_iff _ hf, ← C_ne_zero]
end Ring
section IsDomain
variable [Ring B] [Algebra A B]
variable {x : B}
/-- If `a` strictly divides the minimal polynomial of `x`, then `x` cannot be a root for `a`. -/
theorem aeval_ne_zero_of_dvdNotUnit_minpoly {a : A[X]} (hx : IsIntegral A x) (hamonic : a.Monic)
(hdvd : DvdNotUnit a (minpoly A x)) : Polynomial.aeval x a ≠ 0 := by
refine fun ha => (min A x hamonic ha).not_lt (degree_lt_degree ?_)
obtain ⟨_, c, hu, he⟩ := hdvd
have hcm := hamonic.of_mul_monic_left (he.subst <| monic hx)
rw [he, hamonic.natDegree_mul hcm]
-- TODO: port Nat.lt_add_of_zero_lt_left from lean3 core
apply lt_add_of_pos_right
refine (lt_of_not_le fun h => hu ?_)
rw [eq_C_of_natDegree_le_zero h, ← Nat.eq_zero_of_le_zero h, ← leadingCoeff, hcm.leadingCoeff,
C_1]
exact isUnit_one
variable [IsDomain A] [IsDomain B]
/-- A minimal polynomial is irreducible. -/
theorem irreducible (hx : IsIntegral A x) : Irreducible (minpoly A x) := by
refine (irreducible_of_monic (monic hx) <| ne_one A x).2 fun f g hf hg he => ?_
rw [← hf.isUnit_iff, ← hg.isUnit_iff]
by_contra! h
have heval := congr_arg (Polynomial.aeval x) he
rw [aeval A x, aeval_mul, mul_eq_zero] at heval
rcases heval with heval | heval
· exact aeval_ne_zero_of_dvdNotUnit_minpoly hx hf ⟨hf.ne_zero, g, h.2, he.symm⟩ heval
· refine aeval_ne_zero_of_dvdNotUnit_minpoly hx hg ⟨hg.ne_zero, f, h.1, ?_⟩ heval
rw [mul_comm, he]
end IsDomain
end CommRing
end minpoly
| Mathlib/FieldTheory/Minpoly/Basic.lean | 275 | 284 | |
/-
Copyright (c) 2023 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Probability.Kernel.Composition.MeasureComp
import Mathlib.Probability.Kernel.CondDistrib
import Mathlib.Probability.ConditionalProbability
/-!
# Kernel associated with a conditional expectation
We define `condExpKernel μ m`, a kernel from `Ω` to `Ω` such that for all integrable functions `f`,
`μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`.
This kernel is defined if `Ω` is a standard Borel space. In general, `μ⟦s | m⟧` maps a measurable
set `s` to a function `Ω → ℝ≥0∞`, and for all `s` that map is unique up to a `μ`-null set. For all
`a`, the map from sets to `ℝ≥0∞` that we obtain that way verifies some of the properties of a
measure, but the fact that the `μ`-null set depends on `s` can prevent us from finding versions of
the conditional expectation that combine into a true measure. The standard Borel space assumption
on `Ω` allows us to do so.
## Main definitions
* `condExpKernel μ m`: kernel such that `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`.
## Main statements
* `condExp_ae_eq_integral_condExpKernel`: `μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`.
-/
open MeasureTheory Set Filter TopologicalSpace
open scoped ENNReal MeasureTheory ProbabilityTheory
namespace ProbabilityTheory
section AuxLemmas
variable {Ω F : Type*} {m mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f : Ω → F}
theorem _root_.MeasureTheory.AEStronglyMeasurable.comp_snd_map_prod_id [TopologicalSpace F]
(hm : m ≤ mΩ) (hf : AEStronglyMeasurable f μ) :
AEStronglyMeasurable[m.prod mΩ] (fun x : Ω × Ω => f x.2)
(@Measure.map Ω (Ω × Ω) mΩ (m.prod mΩ) (fun ω => (id ω, id ω)) μ) := by
rw [← aestronglyMeasurable_comp_snd_map_prodMk_iff (measurable_id'' hm)] at hf
simp_rw [id] at hf ⊢
exact hf
theorem _root_.MeasureTheory.Integrable.comp_snd_map_prod_id [NormedAddCommGroup F] (hm : m ≤ mΩ)
(hf : Integrable f μ) : Integrable (fun x : Ω × Ω => f x.2)
(@Measure.map Ω (Ω × Ω) mΩ (m.prod mΩ) (fun ω => (id ω, id ω)) μ) := by
rw [← integrable_comp_snd_map_prodMk_iff (measurable_id'' hm)] at hf
simp_rw [id] at hf ⊢
exact hf
end AuxLemmas
variable {Ω F : Type*} {m : MeasurableSpace Ω} [mΩ : MeasurableSpace Ω]
[StandardBorelSpace Ω] {μ : Measure Ω} [IsFiniteMeasure μ]
open Classical in
/-- Kernel associated with the conditional expectation with respect to a σ-algebra. It satisfies
`μ[f | m] =ᵐ[μ] fun ω => ∫ y, f y ∂(condExpKernel μ m ω)`.
It is defined as the conditional distribution of the identity given the identity, where the second
identity is understood as a map from `Ω` with the σ-algebra `mΩ` to `Ω` with σ-algebra `m ⊓ mΩ`.
We use `m ⊓ mΩ` instead of `m` to ensure that it is a sub-σ-algebra of `mΩ`. We then use
`Kernel.comap` to get a kernel from `m` to `mΩ` instead of from `m ⊓ mΩ` to `mΩ`. -/
noncomputable irreducible_def condExpKernel (μ : Measure Ω) [IsFiniteMeasure μ]
(m : MeasurableSpace Ω) : @Kernel Ω Ω m mΩ :=
if _h : Nonempty Ω then
Kernel.comap (@condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _) id
(measurable_id'' (inf_le_left : m ⊓ mΩ ≤ m))
else 0
@[deprecated (since := "2025-01-21")] alias condexpKernel := condExpKernel
lemma condExpKernel_eq (μ : Measure Ω) [IsFiniteMeasure μ] [h : Nonempty Ω]
(m : MeasurableSpace Ω) :
condExpKernel (mΩ := mΩ) μ m = Kernel.comap (@condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _) id
(measurable_id'' (inf_le_left : m ⊓ mΩ ≤ m)) := by
simp [condExpKernel, h]
@[deprecated (since := "2025-01-21")] alias condexpKernel_eq := condExpKernel_eq
lemma condExpKernel_apply_eq_condDistrib [Nonempty Ω] {ω : Ω} :
condExpKernel μ m ω = @condDistrib Ω Ω Ω mΩ _ _ mΩ (m ⊓ mΩ) id id μ _ (id ω) := by
simp [condExpKernel_eq, Kernel.comap_apply]
@[deprecated (since := "2025-01-21")]
alias condexpKernel_apply_eq_condDistrib := condExpKernel_apply_eq_condDistrib
instance : IsMarkovKernel (condExpKernel μ m) := by
rcases isEmpty_or_nonempty Ω with h | h
· exact ⟨fun a ↦ (IsEmpty.false a).elim⟩
· simp [condExpKernel, h]; infer_instance
lemma compProd_trim_condExpKernel (hm : m ≤ mΩ) :
(μ.trim hm) ⊗ₘ condExpKernel μ m
= @Measure.map Ω (Ω × Ω) mΩ (m.prod mΩ) (fun ω ↦ (id ω, id ω)) μ := by
rcases isEmpty_or_nonempty Ω with h | h
· simp [Measure.eq_zero_of_isEmpty μ]
rw [condExpKernel_eq]
have : m ⊓ mΩ = m := inf_of_le_left hm
have h := compProd_map_condDistrib (mβ := m) (μ := μ) (X := id) measurable_id.aemeasurable
rw [← h, trim_eq_map hm]
congr 1
ext a s hs
simp only [Kernel.coe_comap, Function.comp_apply, id_eq]
congr
lemma condExpKernel_comp_trim (hm : m ≤ mΩ) : condExpKernel μ m ∘ₘ μ.trim hm = μ := by
rw [← Measure.snd_compProd, compProd_trim_condExpKernel, @Measure.snd_map_prodMk, Measure.map_id]
exact measurable_id'' hm
section Measurability
variable [NormedAddCommGroup F] {f : Ω → F}
theorem measurable_condExpKernel {s : Set Ω} (hs : MeasurableSet s) :
Measurable[m] fun ω => condExpKernel μ m ω s := by
nontriviality Ω
simp_rw [condExpKernel_apply_eq_condDistrib]
refine Measurable.mono ?_ (inf_le_left : m ⊓ mΩ ≤ m) le_rfl
convert measurable_condDistrib (μ := μ) hs
rw [MeasurableSpace.comap_id]
@[deprecated (since := "2025-01-21")] alias measurable_condexpKernel := measurable_condExpKernel
theorem stronglyMeasurable_condExpKernel {s : Set Ω} (hs : MeasurableSet s) :
StronglyMeasurable[m] fun ω => condExpKernel μ m ω s :=
Measurable.stronglyMeasurable (measurable_condExpKernel hs)
@[deprecated (since := "2025-01-21")]
alias stronglyMeasurable_condexpKernel := stronglyMeasurable_condExpKernel
theorem _root_.MeasureTheory.StronglyMeasurable.integral_condExpKernel' [NormedSpace ℝ F]
(hf : StronglyMeasurable f) :
StronglyMeasurable[m ⊓ mΩ] (fun ω ↦ ∫ y, f y ∂condExpKernel μ m ω) := by
nontriviality Ω
simp_rw [condExpKernel_apply_eq_condDistrib]
exact (hf.comp_measurable measurable_snd).integral_condDistrib
theorem _root_.MeasureTheory.StronglyMeasurable.integral_condExpKernel [NormedSpace ℝ F]
(hf : StronglyMeasurable f) :
StronglyMeasurable[m] (fun ω ↦ ∫ y, f y ∂condExpKernel μ m ω) :=
hf.integral_condExpKernel'.mono inf_le_left
|
theorem _root_.MeasureTheory.AEStronglyMeasurable.integral_condExpKernel [NormedSpace ℝ F]
(hf : AEStronglyMeasurable f μ) :
AEStronglyMeasurable (fun ω => ∫ y, f y ∂condExpKernel μ m ω) μ := by
nontriviality Ω
simp_rw [condExpKernel_apply_eq_condDistrib]
exact AEStronglyMeasurable.integral_condDistrib
| Mathlib/Probability/Kernel/Condexp.lean | 150 | 156 |
/-
Copyright (c) 2021 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Homology.Single
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
/-!
# Homology is an additive functor
When `V` is preadditive, `HomologicalComplex V c` is also preadditive,
and `homologyFunctor` is additive.
-/
universe v u
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits HomologicalComplex
variable {ι : Type*}
variable {V : Type u} [Category.{v} V] [Preadditive V]
variable {W : Type*} [Category W] [Preadditive W]
variable {W₁ W₂ : Type*} [Category W₁] [Category W₂] [HasZeroMorphisms W₁] [HasZeroMorphisms W₂]
variable {c : ComplexShape ι} {C D : HomologicalComplex V c}
variable (f : C ⟶ D) (i : ι)
namespace HomologicalComplex
instance : Zero (C ⟶ D) :=
⟨{ f := fun _ => 0 }⟩
instance : Add (C ⟶ D) :=
⟨fun f g => { f := fun i => f.f i + g.f i }⟩
instance : Neg (C ⟶ D) :=
⟨fun f => { f := fun i => -f.f i }⟩
instance : Sub (C ⟶ D) :=
⟨fun f g => { f := fun i => f.f i - g.f i }⟩
instance hasNatScalar : SMul ℕ (C ⟶ D) :=
⟨fun n f =>
{ f := fun i => n • f.f i
comm' := fun i j _ => by simp [Preadditive.nsmul_comp, Preadditive.comp_nsmul] }⟩
instance hasIntScalar : SMul ℤ (C ⟶ D) :=
⟨fun n f =>
{ f := fun i => n • f.f i
comm' := fun i j _ => by simp [Preadditive.zsmul_comp, Preadditive.comp_zsmul] }⟩
@[simp]
theorem zero_f_apply (i : ι) : (0 : C ⟶ D).f i = 0 :=
rfl
@[simp]
theorem add_f_apply (f g : C ⟶ D) (i : ι) : (f + g).f i = f.f i + g.f i :=
rfl
@[simp]
theorem neg_f_apply (f : C ⟶ D) (i : ι) : (-f).f i = -f.f i :=
rfl
@[simp]
theorem sub_f_apply (f g : C ⟶ D) (i : ι) : (f - g).f i = f.f i - g.f i :=
rfl
@[simp]
theorem nsmul_f_apply (n : ℕ) (f : C ⟶ D) (i : ι) : (n • f).f i = n • f.f i :=
rfl
@[simp]
theorem zsmul_f_apply (n : ℤ) (f : C ⟶ D) (i : ι) : (n • f).f i = n • f.f i :=
rfl
instance : AddCommGroup (C ⟶ D) :=
Function.Injective.addCommGroup Hom.f HomologicalComplex.hom_f_injective
(by aesop_cat) (by aesop_cat) (by aesop_cat) (by aesop_cat) (by aesop_cat) (by aesop_cat)
-- Porting note: proofs had to be provided here, otherwise Lean tries to apply
-- `Preadditive.add_comp/comp_add` to `HomologicalComplex V c`
instance : Preadditive (HomologicalComplex V c) where
add_comp _ _ _ f f' g := by
ext
simp only [comp_f, add_f_apply]
rw [Preadditive.add_comp]
comp_add _ _ _ f g g' := by
ext
simp only [comp_f, add_f_apply]
rw [Preadditive.comp_add]
/-- The `i`-th component of a chain map, as an additive map from chain maps to morphisms. -/
@[simps!]
def Hom.fAddMonoidHom {C₁ C₂ : HomologicalComplex V c} (i : ι) : (C₁ ⟶ C₂) →+ (C₁.X i ⟶ C₂.X i) :=
AddMonoidHom.mk' (fun f => Hom.f f i) fun _ _ => rfl
instance eval_additive (i : ι) : (eval V c i).Additive where
end HomologicalComplex
namespace CategoryTheory
/-- An additive functor induces a functor between homological complexes.
This is sometimes called the "prolongation".
-/
@[simps]
def Functor.mapHomologicalComplex (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] (c : ComplexShape ι) :
HomologicalComplex W₁ c ⥤ HomologicalComplex W₂ c where
obj C :=
{ X := fun i => F.obj (C.X i)
d := fun i j => F.map (C.d i j)
shape := fun i j w => by
rw [C.shape _ _ w, F.map_zero]
d_comp_d' := fun i j k _ _ => by rw [← F.map_comp, C.d_comp_d, F.map_zero] }
map f :=
{ f := fun i => F.map (f.f i)
comm' := fun i j _ => by
dsimp
rw [← F.map_comp, ← F.map_comp, f.comm] }
instance (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] (c : ComplexShape ι) :
(F.mapHomologicalComplex c).PreservesZeroMorphisms where
instance Functor.map_homogical_complex_additive (F : V ⥤ W) [F.Additive] (c : ComplexShape ι) :
(F.mapHomologicalComplex c).Additive where
variable (W₁)
/-- The functor on homological complexes induced by the identity functor is
isomorphic to the identity functor. -/
@[simps!]
def Functor.mapHomologicalComplexIdIso (c : ComplexShape ι) :
(𝟭 W₁).mapHomologicalComplex c ≅ 𝟭 _ :=
NatIso.ofComponents fun K => Hom.isoOfComponents fun _ => Iso.refl _
instance Functor.mapHomologicalComplex_reflects_iso (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms]
[ReflectsIsomorphisms F] (c : ComplexShape ι) :
ReflectsIsomorphisms (F.mapHomologicalComplex c) :=
⟨fun f => by
intro
haveI : ∀ n : ι, IsIso (F.map (f.f n)) := fun n =>
((HomologicalComplex.eval W₂ c n).mapIso
(asIso ((F.mapHomologicalComplex c).map f))).isIso_hom
haveI := fun n => isIso_of_reflects_iso (f.f n) F
exact HomologicalComplex.Hom.isIso_of_components f⟩
variable {W₁}
/-- A natural transformation between functors induces a natural transformation
between those functors applied to homological complexes.
-/
@[simps]
def NatTrans.mapHomologicalComplex {F G : W₁ ⥤ W₂}
[F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] (α : F ⟶ G)
(c : ComplexShape ι) : F.mapHomologicalComplex c ⟶ G.mapHomologicalComplex c where
app C := { f := fun _ => α.app _ }
@[simp]
theorem NatTrans.mapHomologicalComplex_id
(c : ComplexShape ι) (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] :
NatTrans.mapHomologicalComplex (𝟙 F) c = 𝟙 (F.mapHomologicalComplex c) := by aesop_cat
@[simp]
theorem NatTrans.mapHomologicalComplex_comp (c : ComplexShape ι) {F G H : W₁ ⥤ W₂}
[F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] [H.PreservesZeroMorphisms]
(α : F ⟶ G) (β : G ⟶ H) :
NatTrans.mapHomologicalComplex (α ≫ β) c =
NatTrans.mapHomologicalComplex α c ≫ NatTrans.mapHomologicalComplex β c := by
aesop_cat
@[reassoc]
theorem NatTrans.mapHomologicalComplex_naturality {c : ComplexShape ι} {F G : W₁ ⥤ W₂}
[F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms]
(α : F ⟶ G) {C D : HomologicalComplex W₁ c} (f : C ⟶ D) :
(F.mapHomologicalComplex c).map f ≫ (NatTrans.mapHomologicalComplex α c).app D =
(NatTrans.mapHomologicalComplex α c).app C ≫ (G.mapHomologicalComplex c).map f := by
simp
/-- A natural isomorphism between functors induces a natural isomorphism
between those functors applied to homological complexes.
-/
@[simps!]
def NatIso.mapHomologicalComplex {F G : W₁ ⥤ W₂} [F.PreservesZeroMorphisms]
[G.PreservesZeroMorphisms] (α : F ≅ G) (c : ComplexShape ι) :
F.mapHomologicalComplex c ≅ G.mapHomologicalComplex c where
hom := NatTrans.mapHomologicalComplex α.hom c
inv := NatTrans.mapHomologicalComplex α.inv c
hom_inv_id := by simp only [← NatTrans.mapHomologicalComplex_comp, α.hom_inv_id,
NatTrans.mapHomologicalComplex_id]
inv_hom_id := by simp only [← NatTrans.mapHomologicalComplex_comp, α.inv_hom_id,
NatTrans.mapHomologicalComplex_id]
/-- An equivalence of categories induces an equivalences between the respective categories
of homological complex.
-/
@[simps]
def Equivalence.mapHomologicalComplex (e : W₁ ≌ W₂) [e.functor.PreservesZeroMorphisms]
(c : ComplexShape ι) :
HomologicalComplex W₁ c ≌ HomologicalComplex W₂ c where
functor := e.functor.mapHomologicalComplex c
inverse := e.inverse.mapHomologicalComplex c
unitIso :=
(Functor.mapHomologicalComplexIdIso W₁ c).symm ≪≫ NatIso.mapHomologicalComplex e.unitIso c
counitIso := NatIso.mapHomologicalComplex e.counitIso c ≪≫
Functor.mapHomologicalComplexIdIso W₂ c
end CategoryTheory
namespace ChainComplex
variable {α : Type*} [AddRightCancelSemigroup α] [One α] [DecidableEq α]
theorem map_chain_complex_of (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms] (X : α → W₁)
(d : ∀ n, X (n + 1) ⟶ X n) (sq : ∀ n, d (n + 1) ≫ d n = 0) :
(F.mapHomologicalComplex _).obj (ChainComplex.of X d sq) =
ChainComplex.of (fun n => F.obj (X n)) (fun n => F.map (d n)) fun n => by
rw [← F.map_comp, sq n, Functor.map_zero] := by
refine HomologicalComplex.ext rfl ?_
rintro i j (rfl : j + 1 = i)
simp only [CategoryTheory.Functor.mapHomologicalComplex_obj_d, of_d, eqToHom_refl, comp_id,
id_comp]
end ChainComplex
variable [HasZeroObject W₁] [HasZeroObject W₂]
namespace HomologicalComplex
instance (W : Type*) [Category W] [Preadditive W] [HasZeroObject W] [DecidableEq ι] (j : ι) :
(single W c j).Additive where
map_add {_ _ f g} := by ext; simp [single]
variable (F : W₁ ⥤ W₂) [F.PreservesZeroMorphisms]
(c : ComplexShape ι) [DecidableEq ι]
/-- Turning an object into a complex supported at `j` then applying a functor is
the same as applying the functor then forming the complex.
-/
noncomputable def singleMapHomologicalComplex (j : ι) :
single W₁ c j ⋙ F.mapHomologicalComplex _ ≅ F ⋙ single W₂ c j :=
NatIso.ofComponents
(fun X =>
{ hom := { f := fun i => if h : i = j then eqToHom (by simp [h]) else 0 }
inv := { f := fun i => if h : i = j then eqToHom (by simp [h]) else 0 }
hom_inv_id := by
ext i
dsimp
split_ifs with h
· simp [h]
· rw [zero_comp, ← F.map_id,
(isZero_single_obj_X c j X _ h).eq_of_src (𝟙 _) 0, F.map_zero]
inv_hom_id := by
ext i
dsimp
split_ifs with h
· simp [h]
· apply (isZero_single_obj_X c j _ _ h).eq_of_src })
fun f => by
ext i
dsimp
split_ifs with h
· subst h
simp [single_map_f_self, singleObjXSelf, singleObjXIsoOfEq, eqToHom_map]
· apply (isZero_single_obj_X c j _ _ h).eq_of_tgt
@[simp]
theorem singleMapHomologicalComplex_hom_app_self (j : ι) (X : W₁) :
((singleMapHomologicalComplex F c j).hom.app X).f j =
F.map (singleObjXSelf c j X).hom ≫ (singleObjXSelf c j (F.obj X)).inv := by
simp [singleMapHomologicalComplex, singleObjXSelf, singleObjXIsoOfEq, eqToHom_map]
@[simp]
theorem singleMapHomologicalComplex_hom_app_ne {i j : ι} (h : i ≠ j) (X : W₁) :
((singleMapHomologicalComplex F c j).hom.app X).f i = 0 := by
simp [singleMapHomologicalComplex, h]
@[simp]
theorem singleMapHomologicalComplex_inv_app_self (j : ι) (X : W₁) :
((singleMapHomologicalComplex F c j).inv.app X).f j =
(singleObjXSelf c j (F.obj X)).hom ≫ F.map (singleObjXSelf c j X).inv := by
simp [singleMapHomologicalComplex, singleObjXSelf, singleObjXIsoOfEq, eqToHom_map]
@[simp]
theorem singleMapHomologicalComplex_inv_app_ne {i j : ι} (h : i ≠ j) (X : W₁) :
((singleMapHomologicalComplex F c j).inv.app X).f i = 0 := by
simp [singleMapHomologicalComplex, h]
end HomologicalComplex
| Mathlib/Algebra/Homology/Additive.lean | 318 | 321 | |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Sub.Defs
import Mathlib.Util.AssertExists
/-!
# Ordered groups
This file defines bundled ordered groups and develops a few basic results.
## Implementation details
Unfortunately, the number of `'` appended to lemmas in this file
may differ between the multiplicative and the additive version of a lemma.
The reason is that we did not want to change existing names in the library.
-/
/-
`NeZero` theory should not be needed at this point in the ordered algebraic hierarchy.
-/
assert_not_imported Mathlib.Algebra.NeZero
open Function
universe u
variable {α : Type u}
/-- An ordered additive commutative group is an additive commutative group
with a partial order in which addition is strictly monotone. -/
@[deprecated "Use `[AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α]` instead."
(since := "2025-04-10")]
structure OrderedAddCommGroup (α : Type u) extends AddCommGroup α, PartialOrder α where
/-- Addition is monotone in an ordered additive commutative group. -/
protected add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b
set_option linter.existingAttributeWarning false in
/-- An ordered commutative group is a commutative group
with a partial order in which multiplication is strictly monotone. -/
@[to_additive,
deprecated "Use `[CommGroup α] [PartialOrder α] [IsOrderedMonoid α]` instead."
(since := "2025-04-10")]
structure OrderedCommGroup (α : Type u) extends CommGroup α, PartialOrder α where
/-- Multiplication is monotone in an ordered commutative group. -/
protected mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b
alias OrderedCommGroup.mul_lt_mul_left' := mul_lt_mul_left'
attribute [to_additive OrderedAddCommGroup.add_lt_add_left] OrderedCommGroup.mul_lt_mul_left'
alias OrderedCommGroup.le_of_mul_le_mul_left := le_of_mul_le_mul_left'
attribute [to_additive] OrderedCommGroup.le_of_mul_le_mul_left
alias OrderedCommGroup.lt_of_mul_lt_mul_left := lt_of_mul_lt_mul_left'
attribute [to_additive] OrderedCommGroup.lt_of_mul_lt_mul_left
-- See note [lower instance priority]
@[to_additive IsOrderedAddMonoid.toIsOrderedCancelAddMonoid]
instance (priority := 100) IsOrderedMonoid.toIsOrderedCancelMonoid
[CommGroup α] [PartialOrder α] [IsOrderedMonoid α] : IsOrderedCancelMonoid α where
le_of_mul_le_mul_left a b c bc := by simpa using mul_le_mul_left' bc a⁻¹
le_of_mul_le_mul_right a b c bc := by simpa using mul_le_mul_left' bc a⁻¹
/-!
### Linearly ordered commutative groups
-/
set_option linter.deprecated false in
/-- A linearly ordered additive commutative group is an
additive commutative group with a linear order in which
addition is monotone. -/
@[deprecated "Use `[AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α]` instead."
(since := "2025-04-10")]
structure LinearOrderedAddCommGroup (α : Type u) extends OrderedAddCommGroup α, LinearOrder α
set_option linter.existingAttributeWarning false in
set_option linter.deprecated false in
/-- A linearly ordered commutative group is a
commutative group with a linear order in which
multiplication is monotone. -/
@[to_additive,
deprecated "Use `[CommGroup α] [LinearOrder α] [IsOrderedMonoid α]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommGroup (α : Type u) extends OrderedCommGroup α, LinearOrder α
attribute [nolint docBlame]
LinearOrderedCommGroup.toLinearOrder LinearOrderedAddCommGroup.toLinearOrder
section LinearOrderedCommGroup
variable [CommGroup α] [LinearOrder α] [IsOrderedMonoid α] {a : α}
@[to_additive LinearOrderedAddCommGroup.add_lt_add_left]
theorem LinearOrderedCommGroup.mul_lt_mul_left' (a b : α) (h : a < b) (c : α) : c * a < c * b :=
_root_.mul_lt_mul_left' h c
@[to_additive eq_zero_of_neg_eq]
theorem eq_one_of_inv_eq' (h : a⁻¹ = a) : a = 1 :=
match lt_trichotomy a 1 with
| Or.inl h₁ =>
have : 1 < a := h ▸ one_lt_inv_of_inv h₁
absurd h₁ this.asymm
| Or.inr (Or.inl h₁) => h₁
| | Or.inr (Or.inr h₁) =>
have : a < 1 := h ▸ inv_lt_one'.mpr h₁
absurd h₁ this.asymm
| Mathlib/Algebra/Order/Group/Defs.lean | 113 | 115 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro
-/
import Aesop
import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Nat.Init
import Mathlib.Data.Int.Init
import Mathlib.Logic.Function.Iterate
import Mathlib.Tactic.SimpRw
import Mathlib.Tactic.SplitIfs
/-!
# Basic lemmas about semigroups, monoids, and groups
This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are
one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see
`Algebra/Group/Defs.lean`.
-/
assert_not_exists MonoidWithZero DenselyOrdered
open Function
variable {α β G M : Type*}
section ite
variable [Pow α β]
@[to_additive (attr := simp) dite_smul]
lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) :
a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl
@[to_additive (attr := simp) smul_dite]
lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) :
(if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl
@[to_additive (attr := simp) ite_smul]
lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) :
a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _
@[to_additive (attr := simp) smul_ite]
lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) :
(if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _
set_option linter.existingAttributeWarning false in
attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite
end ite
section Semigroup
variable [Semigroup α]
@[to_additive]
instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩
/-- Composing two multiplications on the left by `y` then `x`
is equal to a multiplication on the left by `x * y`.
-/
@[to_additive (attr := simp) "Composing two additions on the left by `y` then `x`
is equal to an addition on the left by `x + y`."]
theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by
ext z
simp [mul_assoc]
/-- Composing two multiplications on the right by `y` and `x`
is equal to a multiplication on the right by `y * x`.
-/
@[to_additive (attr := simp) "Composing two additions on the right by `y` and `x`
is equal to an addition on the right by `y + x`."]
theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by
ext z
simp [mul_assoc]
end Semigroup
@[to_additive]
instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩
section MulOneClass
variable [MulOneClass M]
@[to_additive]
theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} :
ite P (a * b) 1 = ite P a 1 * ite P b 1 := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} :
ite P 1 (a * b) = ite P 1 a * ite P 1 b := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by
constructor <;> (rintro rfl; simpa using h)
@[to_additive]
theorem one_mul_eq_id : ((1 : M) * ·) = id :=
funext one_mul
@[to_additive]
theorem mul_one_eq_id : (· * (1 : M)) = id :=
funext mul_one
end MulOneClass
section CommSemigroup
variable [CommSemigroup G]
@[to_additive]
theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by
rw [← mul_assoc, mul_comm a, mul_assoc]
@[to_additive]
theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by
rw [mul_assoc, mul_comm b, mul_assoc]
@[to_additive]
theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by
simp only [mul_left_comm, mul_assoc]
@[to_additive]
theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by
simp only [mul_left_comm, mul_comm]
@[to_additive]
theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by
simp only [mul_left_comm, mul_comm]
end CommSemigroup
attribute [local simp] mul_assoc sub_eq_add_neg
section Monoid
variable [Monoid M] {a b : M} {m n : ℕ}
@[to_additive boole_nsmul]
lemma pow_boole (P : Prop) [Decidable P] (a : M) :
(a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero]
@[to_additive nsmul_add_sub_nsmul]
lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by
rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h]
@[to_additive sub_nsmul_nsmul_add]
lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by
rw [← pow_add, Nat.sub_add_cancel h]
@[to_additive sub_one_nsmul_add]
lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by
rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
@[to_additive add_sub_one_nsmul]
lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by
rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
/-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/
@[to_additive nsmul_eq_mod_nsmul "If `n • x = 0`, then `m • x` is the same as `(m % n) • x`"]
lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by
calc
a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div]
_ = a ^ (m % n) := by simp [pow_add, pow_mul, ha]
@[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1
| 0, _ => by simp
| n + 1, h =>
calc
a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ']
_ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc]
_ = 1 := by simp [h, pow_mul_pow_eq_one]
@[to_additive (attr := simp)]
lemma mul_left_iterate (a : M) : ∀ n : ℕ, (a * ·)^[n] = (a ^ n * ·)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ, mul_left_iterate]
@[to_additive (attr := simp)]
lemma mul_right_iterate (a : M) : ∀ n : ℕ, (· * a)^[n] = (· * a ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ', mul_right_iterate]
@[to_additive]
lemma mul_left_iterate_apply_one (a : M) : (a * ·)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive]
lemma mul_right_iterate_apply_one (a : M) : (· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive (attr := simp)]
lemma pow_iterate (k : ℕ) : ∀ n : ℕ, (fun x : M ↦ x ^ k)^[n] = (· ^ k ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul]
end Monoid
section CommMonoid
variable [CommMonoid M] {x y z : M}
@[to_additive]
theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z :=
left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz
@[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n
| 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul]
| n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm]
end CommMonoid
section LeftCancelMonoid
variable [Monoid M] [IsLeftCancelMul M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_left : a * b = a ↔ b = 1 := calc
a * b = a ↔ a * b = a * 1 := by rw [mul_one]
_ ↔ b = 1 := mul_left_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left
@[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_eq_self
@[to_additive (attr := simp)]
theorem left_eq_mul : a = a * b ↔ b = 1 :=
eq_comm.trans mul_eq_left
@[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_right
@[to_additive]
theorem mul_ne_left : a * b ≠ a ↔ b ≠ 1 := mul_eq_left.not
@[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left
@[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_ne_self
@[to_additive]
theorem left_ne_mul : a ≠ a * b ↔ b ≠ 1 := left_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_right
end LeftCancelMonoid
section RightCancelMonoid
variable [RightCancelMonoid M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_right : a * b = b ↔ a = 1 := calc
a * b = b ↔ a * b = 1 * b := by rw [one_mul]
_ ↔ a = 1 := mul_right_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right
@[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_eq_self
@[to_additive (attr := simp)]
theorem right_eq_mul : b = a * b ↔ a = 1 :=
eq_comm.trans mul_eq_right
@[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_left
@[to_additive]
theorem mul_ne_right : a * b ≠ b ↔ a ≠ 1 := mul_eq_right.not
@[deprecated (since := "2025-03-05")] alias mul_left_ne_self := mul_ne_right
@[deprecated (since := "2025-03-05")] alias add_left_ne_self := add_ne_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_ne_self
@[to_additive]
theorem right_ne_mul : b ≠ a * b ↔ a ≠ 1 := right_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_left := right_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_left := right_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_left
end RightCancelMonoid
section CancelCommMonoid
variable [CancelCommMonoid α] {a b c d : α}
@[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop
@[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a ≠ c ↔ b ≠ d := by aesop
end CancelCommMonoid
section InvolutiveInv
variable [InvolutiveInv G] {a b : G}
@[to_additive (attr := simp)]
theorem inv_involutive : Function.Involutive (Inv.inv : G → G) :=
inv_inv
@[to_additive (attr := simp)]
theorem inv_surjective : Function.Surjective (Inv.inv : G → G) :=
inv_involutive.surjective
@[to_additive]
theorem inv_injective : Function.Injective (Inv.inv : G → G) :=
inv_involutive.injective
@[to_additive (attr := simp)]
theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b :=
inv_injective.eq_iff
@[to_additive]
theorem inv_eq_iff_eq_inv : a⁻¹ = b ↔ a = b⁻¹ :=
⟨fun h => h ▸ (inv_inv a).symm, fun h => h.symm ▸ inv_inv b⟩
variable (G)
@[to_additive]
theorem inv_comp_inv : Inv.inv ∘ Inv.inv = @id G :=
inv_involutive.comp_self
@[to_additive]
theorem leftInverse_inv : LeftInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ :=
inv_inv
@[to_additive]
theorem rightInverse_inv : RightInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ :=
inv_inv
end InvolutiveInv
section DivInvMonoid
variable [DivInvMonoid G]
@[to_additive]
theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by
rw [div_eq_mul_inv, one_mul, div_eq_mul_inv]
@[to_additive, field_simps] -- The attributes are out of order on purpose
theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c :=
(mul_div_assoc _ _ _).symm
@[to_additive]
theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv]
@[to_additive]
theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div]
end DivInvMonoid
section DivInvOneMonoid
variable [DivInvOneMonoid G]
@[to_additive (attr := simp)]
theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv]
@[to_additive]
theorem one_div_one : (1 : G) / 1 = 1 :=
div_one _
end DivInvOneMonoid
section DivisionMonoid
variable [DivisionMonoid α] {a b c d : α}
attribute [local simp] mul_assoc div_eq_mul_inv
@[to_additive]
theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = a⁻¹ :=
(inv_eq_of_mul_eq_one_right h).symm
@[to_additive]
theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_left h, one_div]
@[to_additive]
theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_right h, one_div]
@[to_additive]
theorem eq_of_div_eq_one (h : a / b = 1) : a = b :=
inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [← div_eq_mul_inv]
@[to_additive]
lemma eq_of_inv_mul_eq_one (h : a⁻¹ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
lemma eq_of_mul_inv_eq_one (h : a * b⁻¹ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
theorem div_ne_one_of_ne : a ≠ b → a / b ≠ 1 :=
mt eq_of_div_eq_one
variable (a b c)
@[to_additive]
theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp
@[to_additive]
theorem inv_div_left : a⁻¹ / b = (b * a)⁻¹ := by simp
@[to_additive (attr := simp)]
theorem inv_div : (a / b)⁻¹ = b / a := by simp
@[to_additive]
theorem one_div_div : 1 / (a / b) = b / a := by simp
@[to_additive]
theorem one_div_one_div : 1 / (1 / a) = a := by simp
@[to_additive]
theorem div_eq_div_iff_comm : a / b = c / d ↔ b / a = d / c :=
inv_inj.symm.trans <| by simp only [inv_div]
@[to_additive]
instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid α :=
{ DivisionMonoid.toDivInvMonoid with
inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : α) 1).symm }
@[to_additive (attr := simp)]
lemma inv_pow (a : α) : ∀ n : ℕ, a⁻¹ ^ n = (a ^ n)⁻¹
| 0 => by rw [pow_zero, pow_zero, inv_one]
| n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev]
-- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`.
@[to_additive zsmul_zero, simp]
lemma one_zpow : ∀ n : ℤ, (1 : α) ^ n = 1
| (n : ℕ) => by rw [zpow_natCast, one_pow]
| .negSucc n => by rw [zpow_negSucc, one_pow, inv_one]
@[to_additive (attr := simp) neg_zsmul]
lemma zpow_neg (a : α) : ∀ n : ℤ, a ^ (-n) = (a ^ n)⁻¹
| (_ + 1 : ℕ) => DivInvMonoid.zpow_neg' _ _
| 0 => by simp
| Int.negSucc n => by
rw [zpow_negSucc, inv_inv, ← zpow_natCast]
rfl
@[to_additive neg_one_zsmul_add]
lemma mul_zpow_neg_one (a b : α) : (a * b) ^ (-1 : ℤ) = b ^ (-1 : ℤ) * a ^ (-1 : ℤ) := by
simp only [zpow_neg, zpow_one, mul_inv_rev]
@[to_additive zsmul_neg]
lemma inv_zpow (a : α) : ∀ n : ℤ, a⁻¹ ^ n = (a ^ n)⁻¹
| (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow]
| .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow]
@[to_additive (attr := simp) zsmul_neg']
lemma inv_zpow' (a : α) (n : ℤ) : a⁻¹ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg]
@[to_additive nsmul_zero_sub]
lemma one_div_pow (a : α) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow]
@[to_additive zsmul_zero_sub]
lemma one_div_zpow (a : α) (n : ℤ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow]
variable {a b c}
@[to_additive (attr := simp)]
theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 :=
inv_injective.eq_iff' inv_one
@[to_additive (attr := simp)]
theorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 :=
eq_comm.trans inv_eq_one
@[to_additive]
theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 :=
inv_eq_one.not
@[to_additive]
theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by
rw [← one_div_one_div a, h, one_div_one_div]
-- Note that `mul_zsmul` and `zpow_mul` have the primes swapped
-- when additivised since their argument order,
-- and therefore the more "natural" choice of lemma, is reversed.
@[to_additive mul_zsmul'] lemma zpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n
| (m : ℕ), (n : ℕ) => by
rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast]
rfl
| (m : ℕ), .negSucc n => by
rw [zpow_natCast, zpow_negSucc, ← pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj,
← zpow_natCast]
| .negSucc m, (n : ℕ) => by
rw [zpow_natCast, zpow_negSucc, ← inv_pow, ← pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow,
inv_inj, ← zpow_natCast]
| .negSucc m, .negSucc n => by
rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, ← pow_mul, ←
zpow_natCast]
rfl
@[to_additive mul_zsmul]
lemma zpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul]
@[to_additive]
theorem zpow_comm (a : α) (m n : ℤ) : (a ^ m) ^ n = (a ^ n) ^ m := by rw [← zpow_mul, zpow_mul']
variable (a b c)
@[to_additive, field_simps] -- The attributes are out of order on purpose
theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp
@[to_additive (attr := simp)]
theorem div_inv_eq_mul : a / b⁻¹ = a * b := by simp
@[to_additive]
theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by
simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv]
end DivisionMonoid
section DivisionCommMonoid
variable [DivisionCommMonoid α] (a b c d : α)
attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv
@[to_additive neg_add]
theorem mul_inv : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by simp
@[to_additive]
theorem inv_div' : (a / b)⁻¹ = a⁻¹ / b⁻¹ := by simp
@[to_additive]
theorem div_eq_inv_mul : a / b = b⁻¹ * a := by simp
@[to_additive]
theorem inv_mul_eq_div : a⁻¹ * b = b / a := by simp
@[to_additive] lemma inv_div_comm (a b : α) : a⁻¹ / b = b⁻¹ / a := by simp
@[to_additive]
theorem inv_mul' : (a * b)⁻¹ = a⁻¹ / b := by simp
@[to_additive]
theorem inv_div_inv : a⁻¹ / b⁻¹ = b / a := by simp
@[to_additive]
theorem inv_inv_div_inv : (a⁻¹ / b⁻¹)⁻¹ = a / b := by simp
@[to_additive]
theorem one_div_mul_one_div : 1 / a * (1 / b) = 1 / (a * b) := by simp
@[to_additive]
theorem div_right_comm : a / b / c = a / c / b := by simp
@[to_additive, field_simps]
theorem div_div : a / b / c = a / (b * c) := by simp
@[to_additive]
theorem div_mul : a / b * c = a / (b / c) := by simp
@[to_additive]
theorem mul_div_left_comm : a * (b / c) = b * (a / c) := by simp
@[to_additive]
theorem mul_div_right_comm : a * b / c = a / c * b := by simp
@[to_additive]
theorem div_mul_eq_div_div : a / (b * c) = a / b / c := by simp
@[to_additive, field_simps]
theorem div_mul_eq_mul_div : a / b * c = a * c / b := by simp
@[to_additive]
theorem one_div_mul_eq_div : 1 / a * b = b / a := by simp
@[to_additive]
theorem mul_comm_div : a / b * c = a * (c / b) := by simp
@[to_additive]
theorem div_mul_comm : a / b * c = c / b * a := by simp
@[to_additive]
theorem div_mul_eq_div_mul_one_div : a / (b * c) = a / b * (1 / c) := by simp
@[to_additive]
theorem div_div_div_eq : a / b / (c / d) = a * d / (b * c) := by simp
@[to_additive]
theorem div_div_div_comm : a / b / (c / d) = a / c / (b / d) := by simp
@[to_additive]
theorem div_mul_div_comm : a / b * (c / d) = a * c / (b * d) := by simp
@[to_additive]
theorem mul_div_mul_comm : a * b / (c * d) = a / c * (b / d) := by simp
@[to_additive zsmul_add] lemma mul_zpow : ∀ n : ℤ, (a * b) ^ n = a ^ n * b ^ n
| (n : ℕ) => by simp_rw [zpow_natCast, mul_pow]
| .negSucc n => by simp_rw [zpow_negSucc, ← inv_pow, mul_inv, mul_pow]
@[to_additive nsmul_sub]
lemma div_pow (a b : α) (n : ℕ) : (a / b) ^ n = a ^ n / b ^ n := by
simp only [div_eq_mul_inv, mul_pow, inv_pow]
@[to_additive zsmul_sub]
lemma div_zpow (a b : α) (n : ℤ) : (a / b) ^ n = a ^ n / b ^ n := by
simp only [div_eq_mul_inv, mul_zpow, inv_zpow]
attribute [field_simps] div_pow div_zpow
end DivisionCommMonoid
section Group
variable [Group G] {a b c d : G} {n : ℤ}
@[to_additive (attr := simp)]
theorem div_eq_inv_self : a / b = b⁻¹ ↔ a = 1 := by rw [div_eq_mul_inv, mul_eq_right]
@[to_additive]
theorem mul_left_surjective (a : G) : Surjective (a * ·) :=
fun x ↦ ⟨a⁻¹ * x, mul_inv_cancel_left a x⟩
@[to_additive]
theorem mul_right_surjective (a : G) : Function.Surjective fun x ↦ x * a := fun x ↦
⟨x * a⁻¹, inv_mul_cancel_right x a⟩
@[to_additive]
theorem eq_mul_inv_of_mul_eq (h : a * c = b) : a = b * c⁻¹ := by simp [h.symm]
@[to_additive]
theorem eq_inv_mul_of_mul_eq (h : b * a = c) : a = b⁻¹ * c := by simp [h.symm]
@[to_additive]
theorem inv_mul_eq_of_eq_mul (h : b = a * c) : a⁻¹ * b = c := by simp [h]
@[to_additive]
theorem mul_inv_eq_of_eq_mul (h : a = c * b) : a * b⁻¹ = c := by simp [h]
@[to_additive]
theorem eq_mul_of_mul_inv_eq (h : a * c⁻¹ = b) : a = b * c := by simp [h.symm]
@[to_additive]
theorem eq_mul_of_inv_mul_eq (h : b⁻¹ * a = c) : a = b * c := by simp [h.symm, mul_inv_cancel_left]
@[to_additive]
theorem mul_eq_of_eq_inv_mul (h : b = a⁻¹ * c) : a * b = c := by rw [h, mul_inv_cancel_left]
@[to_additive]
theorem mul_eq_of_eq_mul_inv (h : a = c * b⁻¹) : a * b = c := by simp [h]
@[to_additive]
theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ :=
⟨eq_inv_of_mul_eq_one_left, fun h ↦ by rw [h, inv_mul_cancel]⟩
@[to_additive]
theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b := by
rw [mul_eq_one_iff_eq_inv, inv_eq_iff_eq_inv]
/-- Variant of `mul_eq_one_iff_eq_inv` with swapped equality. -/
@[to_additive]
theorem mul_eq_one_iff_eq_inv' : a * b = 1 ↔ b = a⁻¹ := by
rw [mul_eq_one_iff_inv_eq, eq_comm]
/-- Variant of `mul_eq_one_iff_inv_eq` with swapped equality. -/
@[to_additive]
theorem mul_eq_one_iff_inv_eq' : a * b = 1 ↔ b⁻¹ = a := by
rw [mul_eq_one_iff_eq_inv, eq_comm]
@[to_additive]
theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 :=
mul_eq_one_iff_eq_inv.symm
@[to_additive]
theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 :=
mul_eq_one_iff_inv_eq.symm
@[to_additive]
theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b :=
⟨fun h ↦ by rw [h, inv_mul_cancel_right], fun h ↦ by rw [← h, mul_inv_cancel_right]⟩
@[to_additive]
theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c :=
⟨fun h ↦ by rw [h, mul_inv_cancel_left], fun h ↦ by rw [← h, inv_mul_cancel_left]⟩
@[to_additive]
theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c :=
⟨fun h ↦ by rw [← h, mul_inv_cancel_left], fun h ↦ by rw [h, inv_mul_cancel_left]⟩
@[to_additive]
theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b :=
⟨fun h ↦ by rw [← h, inv_mul_cancel_right], fun h ↦ by rw [h, mul_inv_cancel_right]⟩
@[to_additive]
theorem mul_inv_eq_one : a * b⁻¹ = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv]
@[to_additive]
theorem inv_mul_eq_one : a⁻¹ * b = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inj]
@[to_additive (attr := simp)]
theorem conj_eq_one_iff : a * b * a⁻¹ = 1 ↔ b = 1 := by
rw [mul_inv_eq_one, mul_eq_left]
@[to_additive]
theorem div_left_injective : Function.Injective fun a ↦ a / b := by
-- FIXME this could be by `simpa`, but it fails. This is probably a bug in `simpa`.
simp only [div_eq_mul_inv]
exact fun a a' h ↦ mul_left_injective b⁻¹ h
@[to_additive]
theorem div_right_injective : Function.Injective fun a ↦ b / a := by
-- FIXME see above
simp only [div_eq_mul_inv]
exact fun a a' h ↦ inv_injective (mul_right_injective b h)
@[to_additive (attr := simp)]
lemma div_mul_cancel_right (a b : G) : a / (b * a) = b⁻¹ := by rw [← inv_div, mul_div_cancel_right]
@[to_additive (attr := simp)]
theorem mul_div_mul_right_eq_div (a b c : G) : a * c / (b * c) = a / b := by
rw [div_mul_eq_div_div_swap]; simp only [mul_left_inj, eq_self_iff_true, mul_div_cancel_right]
@[to_additive eq_sub_of_add_eq]
theorem eq_div_of_mul_eq' (h : a * c = b) : a = b / c := by simp [← h]
@[to_additive sub_eq_of_eq_add]
theorem div_eq_of_eq_mul'' (h : a = c * b) : a / b = c := by simp [h]
@[to_additive]
theorem eq_mul_of_div_eq (h : a / c = b) : a = b * c := by simp [← h]
@[to_additive]
theorem mul_eq_of_eq_div (h : a = c / b) : a * b = c := by simp [h]
@[to_additive (attr := simp)]
theorem div_right_inj : a / b = a / c ↔ b = c :=
div_right_injective.eq_iff
@[to_additive (attr := simp)]
theorem div_left_inj : b / a = c / a ↔ b = c := by
rw [div_eq_mul_inv, div_eq_mul_inv]
exact mul_left_inj _
@[to_additive (attr := simp)]
theorem div_mul_div_cancel (a b c : G) : a / b * (b / c) = a / c := by
rw [← mul_div_assoc, div_mul_cancel]
@[to_additive (attr := simp)]
theorem div_div_div_cancel_right (a b c : G) : a / c / (b / c) = a / b := by
rw [← inv_div c b, div_inv_eq_mul, div_mul_div_cancel]
@[to_additive]
theorem div_eq_one : a / b = 1 ↔ a = b :=
⟨eq_of_div_eq_one, fun h ↦ by rw [h, div_self']⟩
alias ⟨_, div_eq_one_of_eq⟩ := div_eq_one
alias ⟨_, sub_eq_zero_of_eq⟩ := sub_eq_zero
@[to_additive]
theorem div_ne_one : a / b ≠ 1 ↔ a ≠ b :=
not_congr div_eq_one
@[to_additive (attr := simp)]
theorem div_eq_self : a / b = a ↔ b = 1 := by rw [div_eq_mul_inv, mul_eq_left, inv_eq_one]
@[to_additive eq_sub_iff_add_eq]
theorem eq_div_iff_mul_eq' : a = b / c ↔ a * c = b := by rw [div_eq_mul_inv, eq_mul_inv_iff_mul_eq]
@[to_additive]
theorem div_eq_iff_eq_mul : a / b = c ↔ a = c * b := by rw [div_eq_mul_inv, mul_inv_eq_iff_eq_mul]
@[to_additive]
theorem eq_iff_eq_of_div_eq_div (H : a / b = c / d) : a = b ↔ c = d := by
rw [← div_eq_one, H, div_eq_one]
@[to_additive]
theorem leftInverse_div_mul_left (c : G) : Function.LeftInverse (fun x ↦ x / c) fun x ↦ x * c :=
fun x ↦ mul_div_cancel_right x c
@[to_additive]
theorem leftInverse_mul_left_div (c : G) : Function.LeftInverse (fun x ↦ x * c) fun x ↦ x / c :=
fun x ↦ div_mul_cancel x c
@[to_additive]
theorem leftInverse_mul_right_inv_mul (c : G) :
Function.LeftInverse (fun x ↦ c * x) fun x ↦ c⁻¹ * x :=
fun x ↦ mul_inv_cancel_left c x
@[to_additive]
theorem leftInverse_inv_mul_mul_right (c : G) :
Function.LeftInverse (fun x ↦ c⁻¹ * x) fun x ↦ c * x :=
fun x ↦ inv_mul_cancel_left c x
@[to_additive (attr := simp) natAbs_nsmul_eq_zero]
lemma pow_natAbs_eq_one : a ^ n.natAbs = 1 ↔ a ^ n = 1 := by cases n <;> simp
@[to_additive sub_nsmul]
lemma pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ :=
eq_mul_inv_of_mul_eq <| by rw [← pow_add, Nat.sub_add_cancel h]
@[to_additive sub_nsmul_neg]
theorem inv_pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a⁻¹ ^ (m - n) = (a ^ m)⁻¹ * a ^ n := by
rw [pow_sub a⁻¹ h, inv_pow, inv_pow, inv_inv]
@[to_additive add_one_zsmul]
lemma zpow_add_one (a : G) : ∀ n : ℤ, a ^ (n + 1) = a ^ n * a
| (n : ℕ) => by simp only [← Int.natCast_succ, zpow_natCast, pow_succ]
| -1 => by simp [Int.add_left_neg]
| .negSucc (n + 1) => by
rw [zpow_negSucc, pow_succ', mul_inv_rev, inv_mul_cancel_right]
rw [Int.negSucc_eq, Int.neg_add, Int.neg_add_cancel_right]
exact zpow_negSucc _ _
@[to_additive sub_one_zsmul]
lemma zpow_sub_one (a : G) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ :=
calc
a ^ (n - 1) = a ^ (n - 1) * a * a⁻¹ := (mul_inv_cancel_right _ _).symm
_ = a ^ n * a⁻¹ := by rw [← zpow_add_one, Int.sub_add_cancel]
@[to_additive add_zsmul]
lemma zpow_add (a : G) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n := by
induction n with
| hz => simp
| hp n ihn => simp only [← Int.add_assoc, zpow_add_one, ihn, mul_assoc]
| hn n ihn => rw [zpow_sub_one, ← mul_assoc, ← ihn, ← zpow_sub_one, Int.add_sub_assoc]
@[to_additive one_add_zsmul]
lemma zpow_one_add (a : G) (n : ℤ) : a ^ (1 + n) = a * a ^ n := by rw [zpow_add, zpow_one]
@[to_additive add_zsmul_self]
lemma mul_self_zpow (a : G) (n : ℤ) : a * a ^ n = a ^ (n + 1) := by
rw [Int.add_comm, zpow_add, zpow_one]
@[to_additive add_self_zsmul]
lemma mul_zpow_self (a : G) (n : ℤ) : a ^ n * a = a ^ (n + 1) := (zpow_add_one ..).symm
@[to_additive sub_zsmul] lemma zpow_sub (a : G) (m n : ℤ) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by
rw [Int.sub_eq_add_neg, zpow_add, zpow_neg]
@[to_additive natCast_sub_natCast_zsmul]
lemma zpow_natCast_sub_natCast (a : G) (m n : ℕ) : a ^ (m - n : ℤ) = a ^ m / a ^ n := by
simpa [div_eq_mul_inv] using zpow_sub a m n
@[to_additive natCast_sub_one_zsmul]
lemma zpow_natCast_sub_one (a : G) (n : ℕ) : a ^ (n - 1 : ℤ) = a ^ n / a := by
simpa [div_eq_mul_inv] using zpow_sub a n 1
@[to_additive one_sub_natCast_zsmul]
lemma zpow_one_sub_natCast (a : G) (n : ℕ) : a ^ (1 - n : ℤ) = a / a ^ n := by
simpa [div_eq_mul_inv] using zpow_sub a 1 n
@[to_additive] lemma zpow_mul_comm (a : G) (m n : ℤ) : a ^ m * a ^ n = a ^ n * a ^ m := by
rw [← zpow_add, Int.add_comm, zpow_add]
theorem zpow_eq_zpow_emod {x : G} (m : ℤ) {n : ℤ} (h : x ^ n = 1) :
x ^ m = x ^ (m % n) :=
calc
x ^ m = x ^ (m % n + n * (m / n)) := by rw [Int.emod_add_ediv]
_ = x ^ (m % n) := by simp [zpow_add, zpow_mul, h]
theorem zpow_eq_zpow_emod' {x : G} (m : ℤ) {n : ℕ} (h : x ^ n = 1) :
x ^ m = x ^ (m % (n : ℤ)) := zpow_eq_zpow_emod m (by simpa)
@[to_additive (attr := simp)]
lemma zpow_iterate (k : ℤ) : ∀ n : ℕ, (fun x : G ↦ x ^ k)^[n] = (· ^ k ^ n)
| 0 => by ext; simp [Int.pow_zero]
| n + 1 => by ext; simp [zpow_iterate, Int.pow_succ', zpow_mul]
/-- To show a property of all powers of `g` it suffices to show it is closed under multiplication
by `g` and `g⁻¹` on the left. For subgroups generated by more than one element, see
`Subgroup.closure_induction_left`. -/
@[to_additive "To show a property of all multiples of `g` it suffices to show it is closed under
addition by `g` and `-g` on the left. For additive subgroups generated by more than one element, see
`AddSubgroup.closure_induction_left`."]
lemma zpow_induction_left {g : G} {P : G → Prop} (h_one : P (1 : G))
(h_mul : ∀ a, P a → P (g * a)) (h_inv : ∀ a, P a → P (g⁻¹ * a)) (n : ℤ) : P (g ^ n) := by
induction n with
| hz => rwa [zpow_zero]
| hp n ih =>
rw [Int.add_comm, zpow_add, zpow_one]
exact h_mul _ ih
| hn n ih =>
rw [Int.sub_eq_add_neg, Int.add_comm, zpow_add, zpow_neg_one]
exact h_inv _ ih
/-- To show a property of all powers of `g` it suffices to show it is closed under multiplication
by `g` and `g⁻¹` on the right. For subgroups generated by more than one element, see
`Subgroup.closure_induction_right`. -/
@[to_additive "To show a property of all multiples of `g` it suffices to show it is closed under
addition by `g` and `-g` on the right. For additive subgroups generated by more than one element,
see `AddSubgroup.closure_induction_right`."]
lemma zpow_induction_right {g : G} {P : G → Prop} (h_one : P (1 : G))
(h_mul : ∀ a, P a → P (a * g)) (h_inv : ∀ a, P a → P (a * g⁻¹)) (n : ℤ) : P (g ^ n) := by
induction n with
| hz => rwa [zpow_zero]
| hp n ih =>
rw [zpow_add_one]
exact h_mul _ ih
| hn n ih =>
rw [zpow_sub_one]
exact h_inv _ ih
end Group
section CommGroup
variable [CommGroup G] {a b c d : G}
attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv
@[to_additive]
theorem div_eq_of_eq_mul' {a b c : G} (h : a = b * c) : a / b = c := by
rw [h, div_eq_mul_inv, mul_comm, inv_mul_cancel_left]
@[to_additive (attr := simp)]
theorem mul_div_mul_left_eq_div (a b c : G) : c * a / (c * b) = a / b := by
rw [div_eq_mul_inv, mul_inv_rev, mul_comm b⁻¹ c⁻¹, mul_comm c a, mul_assoc, ← mul_assoc c,
mul_inv_cancel, one_mul, div_eq_mul_inv]
@[to_additive eq_sub_of_add_eq']
theorem eq_div_of_mul_eq'' (h : c * a = b) : a = b / c := by simp [h.symm]
@[to_additive]
theorem eq_mul_of_div_eq' (h : a / b = c) : a = b * c := by simp [h.symm]
@[to_additive]
theorem mul_eq_of_eq_div' (h : b = c / a) : a * b = c := by
rw [h, div_eq_mul_inv, mul_comm c, mul_inv_cancel_left]
@[to_additive sub_sub_self]
theorem div_div_self' (a b : G) : a / (a / b) = b := by simp
@[to_additive]
theorem div_eq_div_mul_div (a b c : G) : a / b = c / b * (a / c) := by simp [mul_left_comm c]
@[to_additive (attr := simp)]
theorem div_div_cancel (a b : G) : a / (a / b) = b :=
div_div_self' a b
@[to_additive (attr := simp)]
theorem div_div_cancel_left (a b : G) : a / b / a = b⁻¹ := by simp
@[to_additive eq_sub_iff_add_eq']
theorem eq_div_iff_mul_eq'' : a = b / c ↔ c * a = b := by rw [eq_div_iff_mul_eq', mul_comm]
@[to_additive]
theorem div_eq_iff_eq_mul' : a / b = c ↔ a = b * c := by rw [div_eq_iff_eq_mul, mul_comm]
@[to_additive (attr := simp)]
theorem mul_div_cancel_left (a b : G) : a * b / a = b := by rw [div_eq_inv_mul, inv_mul_cancel_left]
@[to_additive (attr := simp)]
theorem mul_div_cancel (a b : G) : a * (b / a) = b := by
| rw [← mul_div_assoc, mul_div_cancel_left]
| Mathlib/Algebra/Group/Basic.lean | 968 | 968 |
/-
Copyright (c) 2022 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Eric Wieser, Jeremy Avigad, Johan Commelin
-/
import Mathlib.Data.Matrix.Invertible
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.PosDef
/-! # 2×2 block matrices and the Schur complement
This file proves properties of 2×2 block matrices `[A B; C D]` that relate to the Schur complement
`D - C*A⁻¹*B`.
Some of the results here generalize to 2×2 matrices in a category, rather than just a ring. A few
results in this direction can be found in the file `Mathlib.CategoryTheory.Preadditive.Biproducts`,
especially the declarations `CategoryTheory.Biprod.gaussian` and `CategoryTheory.Biprod.isoElim`.
Compare with `Matrix.invertibleOfFromBlocks₁₁Invertible`.
## Main results
* `Matrix.det_fromBlocks₁₁`, `Matrix.det_fromBlocks₂₂`: determinant of a block matrix in terms of
the Schur complement.
* `Matrix.invOf_fromBlocks_zero₂₁_eq`, `Matrix.invOf_fromBlocks_zero₁₂_eq`: the inverse of a
block triangular matrix.
* `Matrix.isUnit_fromBlocks_zero₂₁`, `Matrix.isUnit_fromBlocks_zero₁₂`: invertibility of a
block triangular matrix.
* `Matrix.det_one_add_mul_comm`: the **Weinstein–Aronszajn identity**.
* `Matrix.PosSemidef.fromBlocks₁₁` and `Matrix.PosSemidef.fromBlocks₂₂`: If a matrix `A` is
positive definite, then `[A B; Bᴴ D]` is positive semidefinite if and only if `D - Bᴴ A⁻¹ B` is
positive semidefinite.
-/
variable {l m n α : Type*}
namespace Matrix
open scoped Matrix
section CommRing
variable [Fintype l] [Fintype m] [Fintype n]
variable [DecidableEq l] [DecidableEq m] [DecidableEq n]
variable [CommRing α]
/-- LDU decomposition of a block matrix with an invertible top-left corner, using the
Schur complement. -/
theorem fromBlocks_eq_of_invertible₁₁ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix l m α)
(D : Matrix l n α) [Invertible A] :
fromBlocks A B C D =
fromBlocks 1 0 (C * ⅟ A) 1 * fromBlocks A 0 0 (D - C * ⅟ A * B) *
fromBlocks 1 (⅟ A * B) 0 1 := by
simp only [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, add_zero, zero_add,
Matrix.one_mul, Matrix.mul_one, invOf_mul_self, Matrix.mul_invOf_cancel_left,
Matrix.invOf_mul_cancel_right, Matrix.mul_assoc, add_sub_cancel]
/-- LDU decomposition of a block matrix with an invertible bottom-right corner, using the
Schur complement. -/
theorem fromBlocks_eq_of_invertible₂₂ (A : Matrix l m α) (B : Matrix l n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] :
fromBlocks A B C D =
fromBlocks 1 (B * ⅟ D) 0 1 * fromBlocks (A - B * ⅟ D * C) 0 0 D *
fromBlocks 1 0 (⅟ D * C) 1 :=
(Matrix.reindex (Equiv.sumComm _ _) (Equiv.sumComm _ _)).injective <| by
simpa [reindex_apply, Equiv.sumComm_symm, ← submatrix_mul_equiv _ _ _ (Equiv.sumComm n m), ←
submatrix_mul_equiv _ _ _ (Equiv.sumComm n l), Equiv.sumComm_apply,
fromBlocks_submatrix_sum_swap_sum_swap] using fromBlocks_eq_of_invertible₁₁ D C B A
section Triangular
/-! #### Block triangular matrices -/
/-- An upper-block-triangular matrix is invertible if its diagonal is. -/
def fromBlocksZero₂₁Invertible (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
[Invertible A] [Invertible D] : Invertible (fromBlocks A B 0 D) :=
invertibleOfLeftInverse _ (fromBlocks (⅟ A) (-(⅟ A * B * ⅟ D)) 0 (⅟ D)) <| by
simp_rw [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, zero_add, add_zero,
Matrix.neg_mul, invOf_mul_self, Matrix.invOf_mul_cancel_right, add_neg_cancel,
fromBlocks_one]
/-- A lower-block-triangular matrix is invertible if its diagonal is. -/
def fromBlocksZero₁₂Invertible (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
[Invertible A] [Invertible D] : Invertible (fromBlocks A 0 C D) :=
invertibleOfLeftInverse _
(fromBlocks (⅟ A) 0 (-(⅟ D * C * ⅟ A))
(⅟ D)) <| by -- a symmetry argument is more work than just copying the proof
simp_rw [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, zero_add, add_zero,
Matrix.neg_mul, invOf_mul_self, Matrix.invOf_mul_cancel_right, neg_add_cancel,
fromBlocks_one]
theorem invOf_fromBlocks_zero₂₁_eq (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
[Invertible A] [Invertible D] [Invertible (fromBlocks A B 0 D)] :
⅟ (fromBlocks A B 0 D) = fromBlocks (⅟ A) (-(⅟ A * B * ⅟ D)) 0 (⅟ D) := by
letI := fromBlocksZero₂₁Invertible A B D
convert (rfl : ⅟ (fromBlocks A B 0 D) = _)
theorem invOf_fromBlocks_zero₁₂_eq (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
[Invertible A] [Invertible D] [Invertible (fromBlocks A 0 C D)] :
⅟ (fromBlocks A 0 C D) = fromBlocks (⅟ A) 0 (-(⅟ D * C * ⅟ A)) (⅟ D) := by
letI := fromBlocksZero₁₂Invertible A C D
convert (rfl : ⅟ (fromBlocks A 0 C D) = _)
/-- Both diagonal entries of an invertible upper-block-triangular matrix are invertible (by reading
off the diagonal entries of the inverse). -/
def invertibleOfFromBlocksZero₂₁Invertible (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
[Invertible (fromBlocks A B 0 D)] : Invertible A × Invertible D where
fst :=
invertibleOfLeftInverse _ (⅟ (fromBlocks A B 0 D)).toBlocks₁₁ <| by
have := invOf_mul_self (fromBlocks A B 0 D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A B 0 D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₁₁ this
simpa only [Matrix.toBlocks_fromBlocks₁₁, Matrix.mul_zero, add_zero, ← fromBlocks_one] using
this
snd :=
invertibleOfRightInverse _ (⅟ (fromBlocks A B 0 D)).toBlocks₂₂ <| by
have := mul_invOf_self (fromBlocks A B 0 D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A B 0 D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₂₂ this
simpa only [Matrix.toBlocks_fromBlocks₂₂, Matrix.zero_mul, zero_add, ← fromBlocks_one] using
this
/-- Both diagonal entries of an invertible lower-block-triangular matrix are invertible (by reading
off the diagonal entries of the inverse). -/
def invertibleOfFromBlocksZero₁₂Invertible (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
[Invertible (fromBlocks A 0 C D)] : Invertible A × Invertible D where
fst :=
invertibleOfRightInverse _ (⅟ (fromBlocks A 0 C D)).toBlocks₁₁ <| by
have := mul_invOf_self (fromBlocks A 0 C D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A 0 C D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₁₁ this
simpa only [Matrix.toBlocks_fromBlocks₁₁, Matrix.zero_mul, add_zero, ← fromBlocks_one] using
this
snd :=
invertibleOfLeftInverse _ (⅟ (fromBlocks A 0 C D)).toBlocks₂₂ <| by
have := invOf_mul_self (fromBlocks A 0 C D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A 0 C D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₂₂ this
simpa only [Matrix.toBlocks_fromBlocks₂₂, Matrix.mul_zero, zero_add, ← fromBlocks_one] using
this
/-- `invertibleOfFromBlocksZero₂₁Invertible` and `Matrix.fromBlocksZero₂₁Invertible` form
an equivalence. -/
def fromBlocksZero₂₁InvertibleEquiv (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α) :
Invertible (fromBlocks A B 0 D) ≃ Invertible A × Invertible D where
toFun _ := invertibleOfFromBlocksZero₂₁Invertible A B D
invFun i := by
letI := i.1
letI := i.2
exact fromBlocksZero₂₁Invertible A B D
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- `invertibleOfFromBlocksZero₁₂Invertible` and `Matrix.fromBlocksZero₁₂Invertible` form
an equivalence. -/
def fromBlocksZero₁₂InvertibleEquiv (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α) :
Invertible (fromBlocks A 0 C D) ≃ Invertible A × Invertible D where
toFun _ := invertibleOfFromBlocksZero₁₂Invertible A C D
invFun i := by
letI := i.1
letI := i.2
exact fromBlocksZero₁₂Invertible A C D
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- An upper block-triangular matrix is invertible iff both elements of its diagonal are.
This is a propositional form of `Matrix.fromBlocksZero₂₁InvertibleEquiv`. -/
@[simp]
theorem isUnit_fromBlocks_zero₂₁ {A : Matrix m m α} {B : Matrix m n α} {D : Matrix n n α} :
IsUnit (fromBlocks A B 0 D) ↔ IsUnit A ∧ IsUnit D := by
simp only [← nonempty_invertible_iff_isUnit, ← nonempty_prod,
(fromBlocksZero₂₁InvertibleEquiv _ _ _).nonempty_congr]
/-- A lower block-triangular matrix is invertible iff both elements of its diagonal are.
This is a propositional form of `Matrix.fromBlocksZero₁₂InvertibleEquiv` forms an `iff`. -/
@[simp]
theorem isUnit_fromBlocks_zero₁₂ {A : Matrix m m α} {C : Matrix n m α} {D : Matrix n n α} :
IsUnit (fromBlocks A 0 C D) ↔ IsUnit A ∧ IsUnit D := by
simp only [← nonempty_invertible_iff_isUnit, ← nonempty_prod,
(fromBlocksZero₁₂InvertibleEquiv _ _ _).nonempty_congr]
/-- An expression for the inverse of an upper block-triangular matrix, when either both elements of
diagonal are invertible, or both are not. -/
theorem inv_fromBlocks_zero₂₁_of_isUnit_iff (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
(hAD : IsUnit A ↔ IsUnit D) :
(fromBlocks A B 0 D)⁻¹ = fromBlocks A⁻¹ (-(A⁻¹ * B * D⁻¹)) 0 D⁻¹ := by
by_cases hA : IsUnit A
· have hD := hAD.mp hA
cases hA.nonempty_invertible
cases hD.nonempty_invertible
letI := fromBlocksZero₂₁Invertible A B D
simp_rw [← invOf_eq_nonsing_inv, invOf_fromBlocks_zero₂₁_eq]
· have hD := hAD.not.mp hA
have : ¬IsUnit (fromBlocks A B 0 D) :=
isUnit_fromBlocks_zero₂₁.not.mpr (not_and'.mpr fun _ => hA)
simp_rw [nonsing_inv_eq_ringInverse, Ring.inverse_non_unit _ hA, Ring.inverse_non_unit _ hD,
Ring.inverse_non_unit _ this, Matrix.zero_mul, neg_zero, fromBlocks_zero]
/-- An expression for the inverse of a lower block-triangular matrix, when either both elements of
diagonal are invertible, or both are not. -/
theorem inv_fromBlocks_zero₁₂_of_isUnit_iff (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
(hAD : IsUnit A ↔ IsUnit D) :
(fromBlocks A 0 C D)⁻¹ = fromBlocks A⁻¹ 0 (-(D⁻¹ * C * A⁻¹)) D⁻¹ := by
by_cases hA : IsUnit A
· have hD := hAD.mp hA
cases hA.nonempty_invertible
cases hD.nonempty_invertible
letI := fromBlocksZero₁₂Invertible A C D
simp_rw [← invOf_eq_nonsing_inv, invOf_fromBlocks_zero₁₂_eq]
· have hD := hAD.not.mp hA
have : ¬IsUnit (fromBlocks A 0 C D) :=
isUnit_fromBlocks_zero₁₂.not.mpr (not_and'.mpr fun _ => hA)
simp_rw [nonsing_inv_eq_ringInverse, Ring.inverse_non_unit _ hA, Ring.inverse_non_unit _ hD,
Ring.inverse_non_unit _ this, Matrix.zero_mul, neg_zero, fromBlocks_zero]
end Triangular
/-! ### 2×2 block matrices -/
section Block
/-! #### General 2×2 block matrices -/
/-- A block matrix is invertible if the bottom right corner and the corresponding schur complement
is. -/
def fromBlocks₂₂Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] [Invertible (A - B * ⅟ D * C)] :
Invertible (fromBlocks A B C D) := by
-- factor `fromBlocks` via `fromBlocks_eq_of_invertible₂₂`, and state the inverse we expect
convert Invertible.copy' _ _ (fromBlocks (⅟ (A - B * ⅟ D * C)) (-(⅟ (A - B * ⅟ D * C) * B * ⅟ D))
(-(⅟ D * C * ⅟ (A - B * ⅟ D * C))) (⅟ D + ⅟ D * C * ⅟ (A - B * ⅟ D * C) * B * ⅟ D))
(fromBlocks_eq_of_invertible₂₂ _ _ _ _) _
· -- the product is invertible because all the factors are
letI : Invertible (1 : Matrix n n α) := invertibleOne
letI : Invertible (1 : Matrix m m α) := invertibleOne
refine Invertible.mul ?_ (fromBlocksZero₁₂Invertible _ _ _)
exact
Invertible.mul (fromBlocksZero₂₁Invertible _ _ _)
(fromBlocksZero₂₁Invertible _ _ _)
· -- unfold the `Invertible` instances to get the raw factors
show
_ =
fromBlocks 1 0 (-(1 * (⅟ D * C) * 1)) 1 *
(fromBlocks (⅟ (A - B * ⅟ D * C)) (-(⅟ (A - B * ⅟ D * C) * 0 * ⅟ D)) 0 (⅟ D) *
fromBlocks 1 (-(1 * (B * ⅟ D) * 1)) 0 1)
-- combine into a single block matrix
simp only [fromBlocks_multiply, invOf_one, Matrix.one_mul, Matrix.mul_one, Matrix.zero_mul,
Matrix.mul_zero, add_zero, zero_add, neg_zero, Matrix.mul_neg, Matrix.neg_mul, neg_neg, ←
Matrix.mul_assoc, add_comm (⅟D)]
/-- A block matrix is invertible if the top left corner and the corresponding schur complement
is. -/
def fromBlocks₁₁Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] [Invertible (D - C * ⅟ A * B)] :
Invertible (fromBlocks A B C D) := by
-- we argue by symmetry
letI := fromBlocks₂₂Invertible D C B A
letI iDCBA :=
submatrixEquivInvertible (fromBlocks D C B A) (Equiv.sumComm _ _) (Equiv.sumComm _ _)
exact
iDCBA.copy' _
(fromBlocks (⅟ A + ⅟ A * B * ⅟ (D - C * ⅟ A * B) * C * ⅟ A) (-(⅟ A * B * ⅟ (D - C * ⅟ A * B)))
(-(⅟ (D - C * ⅟ A * B) * C * ⅟ A)) (⅟ (D - C * ⅟ A * B)))
(fromBlocks_submatrix_sum_swap_sum_swap _ _ _ _).symm
(fromBlocks_submatrix_sum_swap_sum_swap _ _ _ _).symm
theorem invOf_fromBlocks₂₂_eq (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] [Invertible (A - B * ⅟ D * C)]
[Invertible (fromBlocks A B C D)] :
⅟ (fromBlocks A B C D) =
fromBlocks (⅟ (A - B * ⅟ D * C)) (-(⅟ (A - B * ⅟ D * C) * B * ⅟ D))
(-(⅟ D * C * ⅟ (A - B * ⅟ D * C))) (⅟ D + ⅟ D * C * ⅟ (A - B * ⅟ D * C) * B * ⅟ D) := by
letI := fromBlocks₂₂Invertible A B C D
convert (rfl : ⅟ (fromBlocks A B C D) = _)
theorem invOf_fromBlocks₁₁_eq (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] [Invertible (D - C * ⅟ A * B)]
[Invertible (fromBlocks A B C D)] :
⅟ (fromBlocks A B C D) =
fromBlocks (⅟ A + ⅟ A * B * ⅟ (D - C * ⅟ A * B) * C * ⅟ A) (-(⅟ A * B * ⅟ (D - C * ⅟ A * B)))
(-(⅟ (D - C * ⅟ A * B) * C * ⅟ A)) (⅟ (D - C * ⅟ A * B)) := by
letI := fromBlocks₁₁Invertible A B C D
convert (rfl : ⅟ (fromBlocks A B C D) = _)
/-- If a block matrix is invertible and so is its bottom left element, then so is the corresponding
Schur complement. -/
def invertibleOfFromBlocks₂₂Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] [Invertible (fromBlocks A B C D)] :
Invertible (A - B * ⅟ D * C) := by
suffices Invertible (fromBlocks (A - B * ⅟ D * C) 0 0 D) by
exact (invertibleOfFromBlocksZero₁₂Invertible (A - B * ⅟ D * C) 0 D).1
letI : Invertible (1 : Matrix n n α) := invertibleOne
letI : Invertible (1 : Matrix m m α) := invertibleOne
letI iDC : Invertible (fromBlocks 1 0 (⅟ D * C) 1 : Matrix (m ⊕ n) (m ⊕ n) α) :=
fromBlocksZero₁₂Invertible _ _ _
letI iBD : Invertible (fromBlocks 1 (B * ⅟ D) 0 1 : Matrix (m ⊕ n) (m ⊕ n) α) :=
fromBlocksZero₂₁Invertible _ _ _
letI iBDC := Invertible.copy ‹_› _ (fromBlocks_eq_of_invertible₂₂ A B C D).symm
refine (iBD.mulLeft _).symm ?_
exact (iDC.mulRight _).symm iBDC
/-- If a block matrix is invertible and so is its bottom left element, then so is the corresponding
Schur complement. -/
def invertibleOfFromBlocks₁₁Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] [Invertible (fromBlocks A B C D)] :
Invertible (D - C * ⅟ A * B) := by
-- another symmetry argument
letI iABCD' :=
submatrixEquivInvertible (fromBlocks A B C D) (Equiv.sumComm _ _) (Equiv.sumComm _ _)
letI iDCBA := iABCD'.copy _ (fromBlocks_submatrix_sum_swap_sum_swap _ _ _ _).symm
exact invertibleOfFromBlocks₂₂Invertible D C B A
/-- `Matrix.invertibleOfFromBlocks₂₂Invertible` and `Matrix.fromBlocks₂₂Invertible` as an
equivalence. -/
def invertibleEquivFromBlocks₂₂Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] :
Invertible (fromBlocks A B C D) ≃ Invertible (A - B * ⅟ D * C) where
toFun _iABCD := invertibleOfFromBlocks₂₂Invertible _ _ _ _
invFun _i_schur := fromBlocks₂₂Invertible _ _ _ _
left_inv _iABCD := Subsingleton.elim _ _
right_inv _i_schur := Subsingleton.elim _ _
/-- `Matrix.invertibleOfFromBlocks₁₁Invertible` and `Matrix.fromBlocks₁₁Invertible` as an
equivalence. -/
def invertibleEquivFromBlocks₁₁Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] :
Invertible (fromBlocks A B C D) ≃ Invertible (D - C * ⅟ A * B) where
toFun _iABCD := invertibleOfFromBlocks₁₁Invertible _ _ _ _
invFun _i_schur := fromBlocks₁₁Invertible _ _ _ _
left_inv _iABCD := Subsingleton.elim _ _
right_inv _i_schur := Subsingleton.elim _ _
/-- If the bottom-left element of a block matrix is invertible, then the whole matrix is invertible
iff the corresponding schur complement is. -/
theorem isUnit_fromBlocks_iff_of_invertible₂₂ {A : Matrix m m α} {B : Matrix m n α}
{C : Matrix n m α} {D : Matrix n n α} [Invertible D] :
IsUnit (fromBlocks A B C D) ↔ IsUnit (A - B * ⅟ D * C) := by
simp only [← nonempty_invertible_iff_isUnit,
(invertibleEquivFromBlocks₂₂Invertible A B C D).nonempty_congr]
/-- If the top-right element of a block matrix is invertible, then the whole matrix is invertible
iff the corresponding schur complement is. -/
theorem isUnit_fromBlocks_iff_of_invertible₁₁ {A : Matrix m m α} {B : Matrix m n α}
{C : Matrix n m α} {D : Matrix n n α} [Invertible A] :
IsUnit (fromBlocks A B C D) ↔ IsUnit (D - C * ⅟ A * B) := by
simp only [← nonempty_invertible_iff_isUnit,
(invertibleEquivFromBlocks₁₁Invertible A B C D).nonempty_congr]
end Block
/-! ### Lemmas about `Matrix.det` -/
section Det
/-- Determinant of a 2×2 block matrix, expanded around an invertible top left element in terms of
the Schur complement. -/
theorem det_fromBlocks₁₁ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] :
(Matrix.fromBlocks A B C D).det = det A * det (D - C * ⅟ A * B) := by
rw [fromBlocks_eq_of_invertible₁₁ (A := A), det_mul, det_mul, det_fromBlocks_zero₂₁,
det_fromBlocks_zero₂₁, det_fromBlocks_zero₁₂, det_one, det_one, one_mul, one_mul, mul_one]
@[simp]
theorem det_fromBlocks_one₁₁ (B : Matrix m n α) (C : Matrix n m α) (D : Matrix n n α) :
(Matrix.fromBlocks 1 B C D).det = det (D - C * B) := by
haveI : Invertible (1 : Matrix m m α) := invertibleOne
rw [det_fromBlocks₁₁, invOf_one, Matrix.mul_one, det_one, one_mul]
/-- Determinant of a 2×2 block matrix, expanded around an invertible bottom right element in terms
of the Schur complement. -/
theorem det_fromBlocks₂₂ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] :
(Matrix.fromBlocks A B C D).det = det D * det (A - B * ⅟ D * C) := by
have : fromBlocks A B C D =
(fromBlocks D C B A).submatrix (Equiv.sumComm _ _) (Equiv.sumComm _ _) := by
ext (i j)
cases i <;> cases j <;> rfl
rw [this, det_submatrix_equiv_self, det_fromBlocks₁₁]
@[simp]
theorem det_fromBlocks_one₂₂ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α) :
(Matrix.fromBlocks A B C 1).det = det (A - B * C) := by
haveI : Invertible (1 : Matrix n n α) := invertibleOne
rw [det_fromBlocks₂₂, invOf_one, Matrix.mul_one, det_one, one_mul]
/-- The **Weinstein–Aronszajn identity**. Note the `1` on the LHS is of shape m×m, while the `1` on
the RHS is of shape n×n. -/
theorem det_one_add_mul_comm (A : Matrix m n α) (B : Matrix n m α) :
det (1 + A * B) = det (1 + B * A) :=
calc
| det (1 + A * B) = det (fromBlocks 1 (-A) B 1) := by
rw [det_fromBlocks_one₂₂, Matrix.neg_mul, sub_neg_eq_add]
_ = det (1 + B * A) := by rw [det_fromBlocks_one₁₁, Matrix.mul_neg, sub_neg_eq_add]
| Mathlib/LinearAlgebra/Matrix/SchurComplement.lean | 398 | 401 |
/-
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, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.Deriv.AffineMap
import Mathlib.Analysis.Calculus.Deriv.Comp
import Mathlib.Analysis.Calculus.Deriv.Mul
import Mathlib.Analysis.Calculus.Deriv.Slope
import Mathlib.Analysis.Normed.Group.AddTorsor
import Mathlib.Analysis.Normed.Module.Convex
import Mathlib.Analysis.RCLike.Basic
import Mathlib.Topology.Instances.RealVectorSpace
import Mathlib.Topology.LocallyConstant.Basic
/-!
# The mean value inequality and equalities
In this file we prove the following facts:
* `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s`
and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with
constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the
derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`,
so they work both for real and complex derivatives.
* `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≤ B x` or
`‖f x‖ ≤ B x` from upper estimates on `f'` or `‖f'‖`, respectively. These lemmas differ by
their assumptions:
* `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`;
* `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative
or its norm is less than `B' x`;
* `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `‖f x‖ = B x`;
* `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`;
* name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]`
and has a right derivative at every point of `[a, b)`, and (2) the lemma has
a counterpart assuming that `B` is differentiable everywhere on `ℝ`
* `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above
by a constant `C`, then `‖f x - f a‖ ≤ C * ‖x - a‖`; several versions deal with
right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`).
* `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`,
then it is a constant on `s`.
* `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is
strictly differentiable. (This is a corollary of the mean value inequality.)
-/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F]
[NormedSpace ℝ F]
open Metric Set Asymptotics ContinuousLinearMap Filter
open scoped Topology NNReal
/-! ### One-dimensional fencing inequalities -/
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by
change Icc a b ⊆ { x | f x ≤ B x }
set s := { x | f x ≤ B x } ∩ Icc a b
have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prodMk hB
have : IsClosed s := by
simp only [s, inter_comm]
exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le'
apply this.Icc_subset_of_forall_exists_gt ha
rintro x ⟨hxB : f x ≤ B x, xab⟩ y hy
rcases hxB.lt_or_eq with hxB | hxB
· -- If `f x < B x`, then all we need is continuity of both sides
refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsGT hy))
have : ∀ᶠ x in 𝓝[Icc a b] x, f x < B x :=
A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB)
have : ∀ᶠ x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsGT_of_mem xab) this
exact this.mono fun y => le_of_lt
· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩
specialize hf' x xab r hfr
have HB : ∀ᶠ z in 𝓝[>] x, r < slope B x z :=
(hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici
(Ioi_mem_nhds hrB)
obtain ⟨z, hfz, hzB, hz⟩ : ∃ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y :=
hf'.and_eventually (HB.and (Ioc_mem_nhdsGT hy)) |>.exists
refine ⟨z, ?_, hz⟩
have := (hfz.trans hzB).le
rwa [slope_def_field, slope_def_field, div_le_div_iff_of_pos_right (sub_pos.2 hz.1), hxB,
sub_le_sub_iff_right] at this
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has derivative `B'` everywhere on `ℝ`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by `B'`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b)) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
-- `bound` actually says `liminf (f z - f x) / (z - x) ≤ B' x`
(bound : ∀ x ∈ Ico a b, ∀ r, B' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) :
∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by
have Hr : ∀ x ∈ Icc a b, ∀ r > 0, f x ≤ B x + r * (x - a) := fun x hx r hr => by
apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound
· rwa [sub_self, mul_zero, add_zero]
· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const))
· intro x hx
exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r)
· intro x _ _
rw [mul_one]
exact (lt_add_iff_pos_right _).2 hr
exact hx
intro x hx
have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 :=
continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const)
convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf
(fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has derivative `B'` everywhere on `ℝ`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has derivative `B'` everywhere on `ℝ`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x ≤ B' x` on `[a, b)`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, f' x ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr =>
(hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr)
/-! ### Vector-valued functions `f : ℝ → E` -/
section
variable {f : ℝ → E} {a b : ℝ}
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `‖f a‖ ≤ B a`;
* `B` has right derivative at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(‖f z‖ - ‖f x‖) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `‖f x‖ = B x`.
Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. -/
theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*}
[NormedAddCommGroup E] {f : ℝ → E} {f' : ℝ → ℝ} (hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (‖f z‖ - ‖f x‖) / (z - x) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope (norm ∘ f) x z < r)
{B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB
hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `‖f a‖ ≤ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`.
Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ → E}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x :=
image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf
(fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `‖f a‖ ≤ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `ℝ`;
* the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`.
Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ → E}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x)
(bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x :=
image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `‖f a‖ ≤ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* we have `‖f' x‖ ≤ B x` everywhere on `[a, b)`.
Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ → E}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB'
fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr)
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `‖f a‖ ≤ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `ℝ`;
* we have `‖f' x‖ ≤ B x` everywhere on `[a, b)`.
Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ → E}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x)
(bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x :=
image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C`
satisfies `‖f x - f a‖ ≤ C * (x - a)`. -/
theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ → E} {C : ℝ}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by
let g x := f x - f a
have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const
have hg' : ∀ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by
intro x hx
simp [g, hf' x hx]
let B x := C * (x - a)
have hB : ∀ x, HasDerivAt B C x := by
intro x
simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a))
convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound
simp only [g, B]; rw [sub_self, norm_zero, sub_self, mul_zero]
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`, `HasDerivWithinAt`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ → E} {C : ℝ}
(hf : ∀ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x)
(bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by
refine
norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt)
(fun x hx => ?_) bound
exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hx)
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`, `derivWithin`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b))
(bound : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≤ C) :
∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by
refine norm_image_sub_le_of_norm_deriv_le_segment' ?_ bound
exact fun x hx => (hf x hx).hasDerivWithinAt
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `‖f 1 - f 0‖ ≤ C`, `HasDerivWithinAt`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ → E} {C : ℝ}
(hf : ∀ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x)
(bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖f' x‖ ≤ C) : ‖f 1 - f 0‖ ≤ C := by
simpa only [sub_zero, mul_one] using
norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one)
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `‖f 1 - f 0‖ ≤ C`, `derivWithin` version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ}
(hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1))
(bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖derivWithin f (Icc (0 : ℝ) 1) x‖ ≤ C) : ‖f 1 - f 0‖ ≤ C := by
simpa only [sub_zero, mul_one] using
norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one)
theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b))
(hderiv : ∀ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : ∀ x ∈ Icc a b, f x = f a := by
have : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ 0 * (x - a) := fun x hx =>
norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx
simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this
theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b))
(hderiv : ∀ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : ∀ x ∈ Icc a b, f x = f a := by
have H : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≤ 0 := by
simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx
simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx =>
norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx
variable {f' g : ℝ → E}
/-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`,
then they are equal everywhere on `[a, b]`. -/
theorem eq_of_has_deriv_right_eq (derivf : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
(derivg : ∀ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b))
(gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : ∀ y ∈ Icc a b, f y = g y := by
simp only [← @sub_eq_zero _ _ (f _)] at hi ⊢
exact hi ▸ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by
simpa only [sub_self] using (derivf y hy).sub (derivg y hy)
/-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere
on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/
theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b))
(gdiff : DifferentiableOn ℝ g (Icc a b))
(hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) :
∀ y ∈ Icc a b, f y = g y := by
have A : ∀ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy =>
(fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin
(Icc_mem_nhdsGE_of_mem hy)
have B : ∀ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy =>
(gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin
(Icc_mem_nhdsGE_of_mem hy)
exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm ▸ B y hy) fdiff.continuousOn
gdiff.continuousOn hi
end
/-!
### Vector-valued functions `f : E → G`
Theorems in this section work both for real and complex differentiable functions. We use assumptions
`[NontriviallyNormedField 𝕜] [IsRCLikeNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 G]` to
achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion
of a `Convex` set. -/
section
namespace Convex
variable {𝕜 G : Type*} [NontriviallyNormedField 𝕜] [IsRCLikeNormedField 𝕜]
[NormedSpace 𝕜 E] [NormedAddCommGroup G] [NormedSpace 𝕜 G]
{f g : E → G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E → E →L[𝕜] G} {φ : E →L[𝕜] G}
instance (priority := 100) : PathConnectedSpace 𝕜 := by
letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜
infer_instance
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then
the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/
theorem norm_image_sub_le_of_norm_hasFDerivWithin_le
(hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖ ≤ C) (hs : Convex ℝ s)
(xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≤ C * ‖y - x‖ := by
letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜
letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ 𝕜 G
/- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined
on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`.
We just have to check the differentiability of the composition and bounds on its derivative,
which is straightforward but tedious for lack of automation. -/
set g := (AffineMap.lineMap x y : ℝ → E)
have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys
have hD : ∀ t ∈ Icc (0 : ℝ) 1,
HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by
simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _
AffineMap.hasDerivWithinAt_lineMap segm
have bound : ∀ t ∈ Ico (0 : ℝ) 1, ‖f' (g t) (y - x)‖ ≤ C * ‖y - x‖ := fun t ht =>
le_of_opNorm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _
simpa [g] using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and
`LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝ≥0}
(hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖₊ ≤ C)
(hs : Convex ℝ s) : LipschitzOnWith C f s := by
rw [lipschitzOnWith_iff_norm_sub_le]
intro x x_in y y_in
exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E → G` be a function
differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is
continuous within `s` at `x`. Then for any number `K : ℝ≥0` larger than `‖f' x‖₊`, `f` is
`K`-Lipschitz on some neighborhood of `x` within `s`. See also
`Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims
existence of `K` instead of an explicit estimate. -/
theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s)
{f : E → G} (hder : ∀ᶠ y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y)
(hcont : ContinuousWithinAt f' s x) (K : ℝ≥0) (hK : ‖f' x‖₊ < K) :
∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by
obtain ⟨ε, ε0, hε⟩ : ∃ ε > 0,
ball x ε ∩ s ⊆ { y | HasFDerivWithinAt f (f' y) s y ∧ ‖f' y‖₊ < K } :=
mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK))
rw [inter_comm] at hε
refine ⟨s ∩ ball x ε, inter_mem_nhdsWithin _ (ball_mem_nhds _ ε0), ?_⟩
exact
(hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le
(fun y hy => (hε hy).1.mono inter_subset_left) fun y hy => (hε hy).2.le
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E → G` be a function
differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is
continuous within `s` at `x`. Then for any number `K : ℝ≥0` larger than `‖f' x‖₊`, `f` is Lipschitz
on some neighborhood of `x` within `s`. See also
`Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version
with an explicit estimate on the Lipschitz constant. -/
theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E → G}
(hder : ∀ᶠ y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) :
∃ K, ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t :=
| (exists_gt _).imp <|
hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont
/-- The mean value theorem on a convex set: if the derivative of a function within this set is
bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/
theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn 𝕜 f s)
| Mathlib/Analysis/Calculus/MeanValue.lean | 477 | 482 |
/-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.Group.Measure
import Mathlib.MeasureTheory.Measure.Prod
/-!
# Measure theory in the product of groups
In this file we show properties about measure theory in products of measurable groups
and properties of iterated integrals in measurable groups.
These lemmas show the uniqueness of left invariant measures on measurable groups, up to
scaling. In this file we follow the proof and refer to the book *Measure Theory* by Paul Halmos.
The idea of the proof is to use the translation invariance of measures to prove `μ(t) = c * μ(s)`
for two sets `s` and `t`, where `c` is a constant that does not depend on `μ`. Let `e` and `f` be
the characteristic functions of `s` and `t`.
Assume that `μ` and `ν` are left-invariant measures. Then the map `(x, y) ↦ (y * x, x⁻¹)`
preserves the measure `μ × ν`, which means that
```
∫ x, ∫ y, h x y ∂ν ∂μ = ∫ x, ∫ y, h (y * x) x⁻¹ ∂ν ∂μ
```
If we apply this to `h x y := e x * f y⁻¹ / ν ((fun h ↦ h * y⁻¹) ⁻¹' s)`, we can rewrite the RHS to
`μ(t)`, and the LHS to `c * μ(s)`, where `c = c(ν)` does not depend on `μ`.
Applying this to `μ` and to `ν` gives `μ (t) / μ (s) = ν (t) / ν (s)`, which is the uniqueness up to
scalar multiplication.
The proof in [Halmos] seems to contain an omission in §60 Th. A, see
`MeasureTheory.measure_lintegral_div_measure`.
Note that this theory only applies in measurable groups, i.e., when multiplication and inversion
are measurable. This is not the case in general in locally compact groups, or even in compact
groups, when the topology is not second-countable. For arguments along the same line, but using
continuous functions instead of measurable sets and working in the general locally compact
setting, see the file `Mathlib/MeasureTheory/Measure/Haar/Unique.lean`.
-/
noncomputable section
open Set hiding prod_eq
open Function MeasureTheory
open Filter hiding map
open scoped ENNReal Pointwise MeasureTheory
variable (G : Type*) [MeasurableSpace G]
variable [Group G] [MeasurableMul₂ G]
variable (μ ν : Measure G) [SFinite ν] [SFinite μ] {s : Set G}
/-- The map `(x, y) ↦ (x, xy)` as a `MeasurableEquiv`. -/
@[to_additive "The map `(x, y) ↦ (x, x + y)` as a `MeasurableEquiv`."]
protected def MeasurableEquiv.shearMulRight [MeasurableInv G] : G × G ≃ᵐ G × G :=
{ Equiv.prodShear (Equiv.refl _) Equiv.mulLeft with
measurable_toFun := measurable_fst.prodMk measurable_mul
measurable_invFun := measurable_fst.prodMk <| measurable_fst.inv.mul measurable_snd }
/-- The map `(x, y) ↦ (x, y / x)` as a `MeasurableEquiv` with as inverse `(x, y) ↦ (x, yx)` -/
@[to_additive
"The map `(x, y) ↦ (x, y - x)` as a `MeasurableEquiv` with as inverse `(x, y) ↦ (x, y + x)`."]
protected def MeasurableEquiv.shearDivRight [MeasurableInv G] : G × G ≃ᵐ G × G :=
{ Equiv.prodShear (Equiv.refl _) Equiv.divRight with
measurable_toFun := measurable_fst.prodMk <| measurable_snd.div measurable_fst
measurable_invFun := measurable_fst.prodMk <| measurable_snd.mul measurable_fst }
variable {G}
namespace MeasureTheory
open Measure
section LeftInvariant
/-- The multiplicative shear mapping `(x, y) ↦ (x, xy)` preserves the measure `μ × ν`.
This condition is part of the definition of a measurable group in [Halmos, §59].
There, the map in this lemma is called `S`. -/
@[to_additive measurePreserving_prod_add
" The shear mapping `(x, y) ↦ (x, x + y)` preserves the measure `μ × ν`. "]
theorem measurePreserving_prod_mul [IsMulLeftInvariant ν] :
MeasurePreserving (fun z : G × G => (z.1, z.1 * z.2)) (μ.prod ν) (μ.prod ν) :=
(MeasurePreserving.id μ).skew_product measurable_mul <|
Filter.Eventually.of_forall <| map_mul_left_eq_self ν
/-- The map `(x, y) ↦ (y, yx)` sends the measure `μ × ν` to `ν × μ`.
This is the map `SR` in [Halmos, §59].
`S` is the map `(x, y) ↦ (x, xy)` and `R` is `Prod.swap`. -/
@[to_additive measurePreserving_prod_add_swap
" The map `(x, y) ↦ (y, y + x)` sends the measure `μ × ν` to `ν × μ`. "]
theorem measurePreserving_prod_mul_swap [IsMulLeftInvariant μ] :
MeasurePreserving (fun z : G × G => (z.2, z.2 * z.1)) (μ.prod ν) (ν.prod μ) :=
(measurePreserving_prod_mul ν μ).comp measurePreserving_swap
@[to_additive]
theorem measurable_measure_mul_right (hs : MeasurableSet s) :
Measurable fun x => μ ((fun y => y * x) ⁻¹' s) := by
suffices
Measurable fun y =>
μ ((fun x => (x, y)) ⁻¹' ((fun z : G × G => ((1 : G), z.1 * z.2)) ⁻¹' univ ×ˢ s))
by convert this using 1; ext1 x; congr 1 with y : 1; simp
apply measurable_measure_prodMk_right
apply measurable_const.prodMk measurable_mul (MeasurableSet.univ.prod hs)
infer_instance
variable [MeasurableInv G]
/-- The map `(x, y) ↦ (x, x⁻¹y)` is measure-preserving.
This is the function `S⁻¹` in [Halmos, §59],
where `S` is the map `(x, y) ↦ (x, xy)`. -/
@[to_additive measurePreserving_prod_neg_add
"The map `(x, y) ↦ (x, - x + y)` is measure-preserving."]
theorem measurePreserving_prod_inv_mul [IsMulLeftInvariant ν] :
MeasurePreserving (fun z : G × G => (z.1, z.1⁻¹ * z.2)) (μ.prod ν) (μ.prod ν) :=
(measurePreserving_prod_mul μ ν).symm <| MeasurableEquiv.shearMulRight G
variable [IsMulLeftInvariant μ]
/-- The map `(x, y) ↦ (y, y⁻¹x)` sends `μ × ν` to `ν × μ`.
This is the function `S⁻¹R` in [Halmos, §59],
where `S` is the map `(x, y) ↦ (x, xy)` and `R` is `Prod.swap`. -/
@[to_additive measurePreserving_prod_neg_add_swap
"The map `(x, y) ↦ (y, - y + x)` sends `μ × ν` to `ν × μ`."]
theorem measurePreserving_prod_inv_mul_swap :
MeasurePreserving (fun z : G × G => (z.2, z.2⁻¹ * z.1)) (μ.prod ν) (ν.prod μ) :=
(measurePreserving_prod_inv_mul ν μ).comp measurePreserving_swap
/-- The map `(x, y) ↦ (yx, x⁻¹)` is measure-preserving.
This is the function `S⁻¹RSR` in [Halmos, §59],
where `S` is the map `(x, y) ↦ (x, xy)` and `R` is `Prod.swap`. -/
@[to_additive measurePreserving_add_prod_neg
"The map `(x, y) ↦ (y + x, - x)` is measure-preserving."]
theorem measurePreserving_mul_prod_inv [IsMulLeftInvariant ν] :
MeasurePreserving (fun z : G × G => (z.2 * z.1, z.1⁻¹)) (μ.prod ν) (μ.prod ν) := by
convert (measurePreserving_prod_inv_mul_swap ν μ).comp (measurePreserving_prod_mul_swap μ ν)
using 1
ext1 ⟨x, y⟩
simp_rw [Function.comp_apply, mul_inv_rev, inv_mul_cancel_right]
@[to_additive]
theorem quasiMeasurePreserving_inv : QuasiMeasurePreserving (Inv.inv : G → G) μ μ := by
refine ⟨measurable_inv, AbsolutelyContinuous.mk fun s hsm hμs => ?_⟩
rw [map_apply measurable_inv hsm, inv_preimage]
have hf : Measurable fun z : G × G => (z.2 * z.1, z.1⁻¹) :=
(measurable_snd.mul measurable_fst).prodMk measurable_fst.inv
suffices map (fun z : G × G => (z.2 * z.1, z.1⁻¹)) (μ.prod μ) (s⁻¹ ×ˢ s⁻¹) = 0 by
simpa only [(measurePreserving_mul_prod_inv μ μ).map_eq, prod_prod, mul_eq_zero (M₀ := ℝ≥0∞),
or_self_iff] using this
have hsm' : MeasurableSet (s⁻¹ ×ˢ s⁻¹) := hsm.inv.prod hsm.inv
simp_rw [map_apply hf hsm', prod_apply_symm (μ := μ) (ν := μ) (hf hsm'), preimage_preimage,
mk_preimage_prod, inv_preimage, inv_inv, measure_mono_null inter_subset_right hμs,
lintegral_zero]
@[to_additive (attr := simp)]
theorem measure_inv_null : μ s⁻¹ = 0 ↔ μ s = 0 := by
refine ⟨fun hs => ?_, (quasiMeasurePreserving_inv μ).preimage_null⟩
rw [← inv_inv s]
exact (quasiMeasurePreserving_inv μ).preimage_null hs
|
@[to_additive (attr := simp)]
theorem inv_ae : (ae μ)⁻¹ = ae μ := by
refine le_antisymm (quasiMeasurePreserving_inv μ).tendsto_ae ?_
nth_rewrite 1 [← inv_inv (ae μ)]
exact Filter.map_mono (quasiMeasurePreserving_inv μ).tendsto_ae
@[to_additive (attr := simp)]
theorem eventuallyConst_inv_set_ae :
EventuallyConst (s⁻¹ : Set G) (ae μ) ↔ EventuallyConst s (ae μ) := by
rw [← inv_preimage, eventuallyConst_preimage, Filter.map_inv, inv_ae]
| Mathlib/MeasureTheory/Group/Prod.lean | 161 | 172 |
/-
Copyright (c) 2020 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.Algebra.Algebra.Spectrum.Basic
import Mathlib.Algebra.Module.LinearMap.Basic
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.RingTheory.Nilpotent.Basic
import Mathlib.RingTheory.Nilpotent.Defs
import Mathlib.RingTheory.Nilpotent.Lemmas
import Mathlib.Tactic.Peel
/-!
# Eigenvectors and eigenvalues
This file defines eigenspaces, eigenvalues, and eigenvalues, as well as their generalized
counterparts. We follow Axler's approach [axler2015] because it allows us to derive many properties
without choosing a basis and without using matrices.
An eigenspace of a linear map `f` for a scalar `μ` is the kernel of the map `(f - μ • id)`. The
nonzero elements of an eigenspace are eigenvectors `x`. They have the property `f x = μ • x`. If
there are eigenvectors for a scalar `μ`, the scalar `μ` is called an eigenvalue.
There is no consensus in the literature whether `0` is an eigenvector. Our definition of
`HasEigenvector` permits only nonzero vectors. For an eigenvector `x` that may also be `0`, we
write `x ∈ f.eigenspace μ`.
A generalized eigenspace of a linear map `f` for a natural number `k` and a scalar `μ` is the kernel
of the map `(f - μ • id) ^ k`. The nonzero elements of a generalized eigenspace are generalized
eigenvectors `x`. If there are generalized eigenvectors for a natural number `k` and a scalar `μ`,
the scalar `μ` is called a generalized eigenvalue.
The fact that the eigenvalues are the roots of the minimal polynomial is proved in
`LinearAlgebra.Eigenspace.Minpoly`.
The existence of eigenvalues over an algebraically closed field
(and the fact that the generalized eigenspaces then span) is deferred to
`LinearAlgebra.Eigenspace.IsAlgClosed`.
## References
* [Sheldon Axler, *Linear Algebra Done Right*][axler2015]
* https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors
## Tags
eigenspace, eigenvector, eigenvalue, eigen
-/
universe u v w
namespace Module
namespace End
open Module Set
variable {K R : Type v} {V M : Type w} [CommRing R] [AddCommGroup M] [Module R M] [Field K]
[AddCommGroup V] [Module K V]
/-- The submodule `genEigenspace f μ k` for a linear map `f`, a scalar `μ`,
and a number `k : ℕ∞` is the kernel of `(f - μ • id) ^ k` if `k` is a natural number
(see Def 8.10 of [axler2015]), or the union of all these kernels if `k = ∞`.
A generalized eigenspace for some exponent `k` is contained in
the generalized eigenspace for exponents larger than `k`. -/
def genEigenspace (f : End R M) (μ : R) : ℕ∞ →o Submodule R M where
toFun k := ⨆ l : ℕ, ⨆ _ : l ≤ k, LinearMap.ker ((f - μ • 1) ^ l)
monotone' _ _ hkl := biSup_mono fun _ hi ↦ hi.trans hkl
lemma mem_genEigenspace {f : End R M} {μ : R} {k : ℕ∞} {x : M} :
x ∈ f.genEigenspace μ k ↔ ∃ l : ℕ, l ≤ k ∧ x ∈ LinearMap.ker ((f - μ • 1) ^ l) := by
have : Nonempty {l : ℕ // l ≤ k} := ⟨⟨0, zero_le _⟩⟩
have : Directed (ι := { i : ℕ // i ≤ k }) (· ≤ ·) fun i ↦ LinearMap.ker ((f - μ • 1) ^ (i : ℕ)) :=
Monotone.directed_le fun m n h ↦ by simpa using (f - μ • 1).iterateKer.monotone h
simp_rw [genEigenspace, OrderHom.coe_mk, LinearMap.mem_ker, iSup_subtype',
Submodule.mem_iSup_of_directed _ this, LinearMap.mem_ker, Subtype.exists, exists_prop]
lemma genEigenspace_directed {f : End R M} {μ : R} {k : ℕ∞} :
Directed (· ≤ ·) (fun l : {l : ℕ // l ≤ k} ↦ f.genEigenspace μ l) := by
have aux : Monotone ((↑) : {l : ℕ // l ≤ k} → ℕ∞) := fun x y h ↦ by simpa using h
exact ((genEigenspace f μ).monotone.comp aux).directed_le
lemma mem_genEigenspace_nat {f : End R M} {μ : R} {k : ℕ} {x : M} :
x ∈ f.genEigenspace μ k ↔ x ∈ LinearMap.ker ((f - μ • 1) ^ k) := by
rw [mem_genEigenspace]
constructor
· rintro ⟨l, hl, hx⟩
simp only [Nat.cast_le] at hl
exact (f - μ • 1).iterateKer.monotone hl hx
· intro hx
exact ⟨k, le_rfl, hx⟩
lemma mem_genEigenspace_top {f : End R M} {μ : R} {x : M} :
x ∈ f.genEigenspace μ ⊤ ↔ ∃ k : ℕ, x ∈ LinearMap.ker ((f - μ • 1) ^ k) := by
simp [mem_genEigenspace]
lemma genEigenspace_nat {f : End R M} {μ : R} {k : ℕ} :
f.genEigenspace μ k = LinearMap.ker ((f - μ • 1) ^ k) := by
ext; simp [mem_genEigenspace_nat]
lemma genEigenspace_eq_iSup_genEigenspace_nat (f : End R M) (μ : R) (k : ℕ∞) :
f.genEigenspace μ k = ⨆ l : {l : ℕ // l ≤ k}, f.genEigenspace μ l := by
simp_rw [genEigenspace_nat, genEigenspace, OrderHom.coe_mk, iSup_subtype]
lemma genEigenspace_top (f : End R M) (μ : R) :
f.genEigenspace μ ⊤ = ⨆ k : ℕ, f.genEigenspace μ k := by
rw [genEigenspace_eq_iSup_genEigenspace_nat, iSup_subtype]
simp only [le_top, iSup_pos, OrderHom.coe_mk]
lemma genEigenspace_one {f : End R M} {μ : R} :
f.genEigenspace μ 1 = LinearMap.ker (f - μ • 1) := by
rw [← Nat.cast_one, genEigenspace_nat, pow_one]
@[simp]
lemma mem_genEigenspace_one {f : End R M} {μ : R} {x : M} :
x ∈ f.genEigenspace μ 1 ↔ f x = μ • x := by
rw [genEigenspace_one, LinearMap.mem_ker, LinearMap.sub_apply,
sub_eq_zero, LinearMap.smul_apply, Module.End.one_apply]
-- `simp` can prove this using `genEigenspace_zero`
lemma mem_genEigenspace_zero {f : End R M} {μ : R} {x : M} :
x ∈ f.genEigenspace μ 0 ↔ x = 0 := by
rw [← Nat.cast_zero, mem_genEigenspace_nat, pow_zero, LinearMap.mem_ker, Module.End.one_apply]
@[simp]
lemma genEigenspace_zero {f : End R M} {μ : R} :
f.genEigenspace μ 0 = ⊥ := by
ext; apply mem_genEigenspace_zero
@[simp]
lemma genEigenspace_zero_nat (f : End R M) (k : ℕ) :
f.genEigenspace 0 k = LinearMap.ker (f ^ k) := by
ext; simp [mem_genEigenspace_nat]
/-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`,
and let `μ : R` and `k : ℕ∞` be given.
Then `x : M` satisfies `HasUnifEigenvector f μ k x` if
`x ∈ f.genEigenspace μ k` and `x ≠ 0`.
For `k = 1`, this means that `x` is an eigenvector of `f` with eigenvalue `μ`. -/
def HasUnifEigenvector (f : End R M) (μ : R) (k : ℕ∞) (x : M) : Prop :=
x ∈ f.genEigenspace μ k ∧ x ≠ 0
/-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`.
Then `μ : R` and `k : ℕ∞` satisfy `HasUnifEigenvalue f μ k` if
`f.genEigenspace μ k ≠ ⊥`.
For `k = 1`, this means that `μ` is an eigenvalue of `f`. -/
def HasUnifEigenvalue (f : End R M) (μ : R) (k : ℕ∞) : Prop :=
f.genEigenspace μ k ≠ ⊥
/-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`.
For `k : ℕ∞`, we define `UnifEigenvalues f k` to be the type of all
`μ : R` that satisfy `f.HasUnifEigenvalue μ k`.
For `k = 1` this is the type of all eigenvalues of `f`. -/
def UnifEigenvalues (f : End R M) (k : ℕ∞) : Type _ :=
{ μ : R // f.HasUnifEigenvalue μ k }
/-- The underlying value of a bundled eigenvalue. -/
@[coe]
def UnifEigenvalues.val (f : Module.End R M) (k : ℕ∞) : UnifEigenvalues f k → R := Subtype.val
instance UnifEigenvalues.instCoeOut {f : Module.End R M} (k : ℕ∞) :
CoeOut (UnifEigenvalues f k) R where
coe := UnifEigenvalues.val f k
instance UnivEigenvalues.instDecidableEq [DecidableEq R] (f : Module.End R M) (k : ℕ∞) :
DecidableEq (UnifEigenvalues f k) :=
inferInstanceAs (DecidableEq (Subtype (fun x : R ↦ f.HasUnifEigenvalue x k)))
lemma HasUnifEigenvector.hasUnifEigenvalue {f : End R M} {μ : R} {k : ℕ∞} {x : M}
(h : f.HasUnifEigenvector μ k x) : f.HasUnifEigenvalue μ k := by
rw [HasUnifEigenvalue, Submodule.ne_bot_iff]
use x; exact h
lemma HasUnifEigenvector.apply_eq_smul {f : End R M} {μ : R} {x : M}
(hx : f.HasUnifEigenvector μ 1 x) : f x = μ • x :=
mem_genEigenspace_one.mp hx.1
lemma HasUnifEigenvector.pow_apply {f : End R M} {μ : R} {v : M} (hv : f.HasUnifEigenvector μ 1 v)
(n : ℕ) : (f ^ n) v = μ ^ n • v := by
induction n <;> simp [*, pow_succ f, hv.apply_eq_smul, smul_smul, pow_succ' μ]
theorem HasUnifEigenvalue.exists_hasUnifEigenvector
{f : End R M} {μ : R} {k : ℕ∞} (hμ : f.HasUnifEigenvalue μ k) :
∃ v, f.HasUnifEigenvector μ k v :=
Submodule.exists_mem_ne_zero_of_ne_bot hμ
lemma HasUnifEigenvalue.pow {f : End R M} {μ : R} (h : f.HasUnifEigenvalue μ 1) (n : ℕ) :
(f ^ n).HasUnifEigenvalue (μ ^ n) 1 := by
rw [HasUnifEigenvalue, Submodule.ne_bot_iff]
obtain ⟨m : M, hm⟩ := h.exists_hasUnifEigenvector
exact ⟨m, by simpa [mem_genEigenspace_one] using hm.pow_apply n, hm.2⟩
/-- A nilpotent endomorphism has nilpotent eigenvalues.
See also `LinearMap.isNilpotent_trace_of_isNilpotent`. -/
lemma HasUnifEigenvalue.isNilpotent_of_isNilpotent [NoZeroSMulDivisors R M] {f : End R M}
(hfn : IsNilpotent f) {μ : R} (hf : f.HasUnifEigenvalue μ 1) :
IsNilpotent μ := by
obtain ⟨m : M, hm⟩ := hf.exists_hasUnifEigenvector
obtain ⟨n : ℕ, hn : f ^ n = 0⟩ := hfn
exact ⟨n, by simpa [hn, hm.2, eq_comm (a := (0 : M))] using hm.pow_apply n⟩
lemma HasUnifEigenvalue.mem_spectrum {f : End R M} {μ : R} (hμ : HasUnifEigenvalue f μ 1) :
μ ∈ spectrum R f := by
refine spectrum.mem_iff.mpr fun h_unit ↦ ?_
set f' := LinearMap.GeneralLinearGroup.toLinearEquiv h_unit.unit
rcases hμ.exists_hasUnifEigenvector with ⟨v, hv⟩
refine hv.2 ((LinearMap.ker_eq_bot'.mp f'.ker) v (?_ : μ • v - f v = 0))
rw [hv.apply_eq_smul, sub_self]
lemma hasUnifEigenvalue_iff_mem_spectrum [FiniteDimensional K V] {f : End K V} {μ : K} :
f.HasUnifEigenvalue μ 1 ↔ μ ∈ spectrum K f := by
rw [spectrum.mem_iff, IsUnit.sub_iff, LinearMap.isUnit_iff_ker_eq_bot,
HasUnifEigenvalue, genEigenspace_one, ne_eq, not_iff_not]
simp [Submodule.ext_iff, LinearMap.mem_ker]
alias ⟨_, HasUnifEigenvalue.of_mem_spectrum⟩ := hasUnifEigenvalue_iff_mem_spectrum
lemma genEigenspace_div (f : End K V) (a b : K) (hb : b ≠ 0) :
genEigenspace f (a / b) 1 = LinearMap.ker (b • f - a • 1) :=
calc
genEigenspace f (a / b) 1 = genEigenspace f (b⁻¹ * a) 1 := by rw [div_eq_mul_inv, mul_comm]
_ = LinearMap.ker (f - (b⁻¹ * a) • 1) := by rw [genEigenspace_one]
_ = LinearMap.ker (f - b⁻¹ • a • 1) := by rw [smul_smul]
_ = LinearMap.ker (b • (f - b⁻¹ • a • 1)) := by rw [LinearMap.ker_smul _ b hb]
_ = LinearMap.ker (b • f - a • 1) := by rw [smul_sub, smul_inv_smul₀ hb]
/-- The generalized eigenrange for a linear map `f`, a scalar `μ`, and an exponent `k ∈ ℕ∞`
is the range of `(f - μ • id) ^ k` if `k` is a natural number,
or the infimum of these ranges if `k = ∞`. -/
def genEigenrange (f : End R M) (μ : R) (k : ℕ∞) : Submodule R M :=
⨅ l : ℕ, ⨅ (_ : l ≤ k), LinearMap.range ((f - μ • 1) ^ l)
lemma genEigenrange_nat {f : End R M} {μ : R} {k : ℕ} :
f.genEigenrange μ k = LinearMap.range ((f - μ • 1) ^ k) := by
ext x
simp only [genEigenrange, Nat.cast_le, Submodule.mem_iInf, LinearMap.mem_range]
constructor
· intro h
exact h _ le_rfl
· rintro ⟨x, rfl⟩ i hi
have : k = i + (k - i) := by omega
rw [this, pow_add]
exact ⟨_, rfl⟩
/-- The exponent of a generalized eigenvalue is never 0. -/
lemma HasUnifEigenvalue.exp_ne_zero {f : End R M} {μ : R} {k : ℕ}
(h : f.HasUnifEigenvalue μ k) : k ≠ 0 := by
rintro rfl
simp [HasUnifEigenvalue, Nat.cast_zero, genEigenspace_zero] at h
/-- If there exists a natural number `k` such that the kernel of `(f - μ • id) ^ k` is the
maximal generalized eigenspace, then this value is the least such `k`. If not, this value is not
meaningful. -/
noncomputable def maxUnifEigenspaceIndex (f : End R M) (μ : R) :=
monotonicSequenceLimitIndex <| (f.genEigenspace μ).comp <| WithTop.coeOrderHom.toOrderHom
/-- For an endomorphism of a Noetherian module, the maximal eigenspace is always of the form kernel
`(f - μ • id) ^ k` for some `k`. -/
lemma genEigenspace_top_eq_maxUnifEigenspaceIndex [IsNoetherian R M] (f : End R M) (μ : R) :
genEigenspace f μ ⊤ = f.genEigenspace μ (maxUnifEigenspaceIndex f μ) := by
have := WellFoundedGT.iSup_eq_monotonicSequenceLimit <|
(f.genEigenspace μ).comp <| WithTop.coeOrderHom.toOrderHom
convert this using 1
simp only [genEigenspace, OrderHom.coe_mk, le_top, iSup_pos, OrderHom.comp_coe,
Function.comp_def]
rw [iSup_prod', iSup_subtype', ← sSup_range, ← sSup_range]
congr
aesop
lemma genEigenspace_le_genEigenspace_maxUnifEigenspaceIndex [IsNoetherian R M] (f : End R M)
(μ : R) (k : ℕ∞) :
f.genEigenspace μ k ≤ f.genEigenspace μ (maxUnifEigenspaceIndex f μ) := by
rw [← genEigenspace_top_eq_maxUnifEigenspaceIndex]
exact (f.genEigenspace μ).monotone le_top
/-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/
theorem genEigenspace_eq_genEigenspace_maxUnifEigenspaceIndex_of_le [IsNoetherian R M]
(f : End R M) (μ : R) {k : ℕ} (hk : maxUnifEigenspaceIndex f μ ≤ k) :
f.genEigenspace μ k = f.genEigenspace μ (maxUnifEigenspaceIndex f μ) :=
le_antisymm
(genEigenspace_le_genEigenspace_maxUnifEigenspaceIndex _ _ _)
((f.genEigenspace μ).monotone <| by simpa using hk)
/-- A generalized eigenvalue for some exponent `k` is also
a generalized eigenvalue for exponents larger than `k`. -/
lemma HasUnifEigenvalue.le {f : End R M} {μ : R} {k m : ℕ∞}
(hm : k ≤ m) (hk : f.HasUnifEigenvalue μ k) :
f.HasUnifEigenvalue μ m := by
unfold HasUnifEigenvalue at *
contrapose! hk
rw [← le_bot_iff, ← hk]
exact (f.genEigenspace _).monotone hm
/-- A generalized eigenvalue for some exponent `k` is also
a generalized eigenvalue for positive exponents. -/
lemma HasUnifEigenvalue.lt {f : End R M} {μ : R} {k m : ℕ∞}
(hm : 0 < m) (hk : f.HasUnifEigenvalue μ k) :
f.HasUnifEigenvalue μ m := by
apply HasUnifEigenvalue.le (k := 1) (Order.one_le_iff_pos.mpr hm)
intro contra; apply hk
rw [genEigenspace_one, LinearMap.ker_eq_bot] at contra
rw [eq_bot_iff]
intro x hx
rw [mem_genEigenspace] at hx
rcases hx with ⟨l, -, hx⟩
rwa [LinearMap.ker_eq_bot.mpr] at hx
rw [Module.End.coe_pow (f - μ • 1) l]
exact Function.Injective.iterate contra l
/-- Generalized eigenvalues are actually just eigenvalues. -/
@[simp]
lemma hasUnifEigenvalue_iff_hasUnifEigenvalue_one {f : End R M} {μ : R} {k : ℕ∞} (hk : 0 < k) :
f.HasUnifEigenvalue μ k ↔ f.HasUnifEigenvalue μ 1 :=
⟨HasUnifEigenvalue.lt zero_lt_one, HasUnifEigenvalue.lt hk⟩
lemma maxUnifEigenspaceIndex_le_finrank [FiniteDimensional K V] (f : End K V) (μ : K) :
maxUnifEigenspaceIndex f μ ≤ finrank K V := by
apply Nat.sInf_le
intro n hn
apply le_antisymm
· exact (f.genEigenspace μ).monotone <| WithTop.coeOrderHom.monotone hn
· show (f.genEigenspace μ) n ≤ (f.genEigenspace μ) (finrank K V)
rw [genEigenspace_nat, genEigenspace_nat]
apply ker_pow_le_ker_pow_finrank
/-- Every generalized eigenvector is a generalized eigenvector for exponent `finrank K V`.
(Lemma 8.11 of [axler2015]) -/
lemma genEigenspace_le_genEigenspace_finrank [FiniteDimensional K V] (f : End K V)
(μ : K) (k : ℕ∞) : f.genEigenspace μ k ≤ f.genEigenspace μ (finrank K V) := by
calc f.genEigenspace μ k
≤ f.genEigenspace μ ⊤ := (f.genEigenspace _).monotone le_top
_ ≤ f.genEigenspace μ (finrank K V) := by
rw [genEigenspace_top_eq_maxUnifEigenspaceIndex]
exact (f.genEigenspace _).monotone <| by simpa using maxUnifEigenspaceIndex_le_finrank f μ
/-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/
theorem genEigenspace_eq_genEigenspace_finrank_of_le [FiniteDimensional K V]
(f : End K V) (μ : K) {k : ℕ} (hk : finrank K V ≤ k) :
f.genEigenspace μ k = f.genEigenspace μ (finrank K V) :=
le_antisymm
(genEigenspace_le_genEigenspace_finrank _ _ _)
((f.genEigenspace μ).monotone <| by simpa using hk)
lemma mapsTo_genEigenspace_of_comm {f g : End R M} (h : Commute f g) (μ : R) (k : ℕ∞) :
MapsTo g (f.genEigenspace μ k) (f.genEigenspace μ k) := by
intro x hx
simp only [SetLike.mem_coe, mem_genEigenspace, LinearMap.mem_ker] at hx ⊢
rcases hx with ⟨l, hl, hx⟩
replace h : Commute ((f - μ • (1 : End R M)) ^ l) g :=
(h.sub_left <| Algebra.commute_algebraMap_left μ g).pow_left l
use l, hl
rw [← LinearMap.comp_apply, ← Module.End.mul_eq_comp, h.eq, Module.End.mul_eq_comp,
LinearMap.comp_apply, hx, map_zero]
/-- The restriction of `f - μ • 1` to the `k`-fold generalized `μ`-eigenspace is nilpotent. -/
lemma isNilpotent_restrict_genEigenspace_nat (f : End R M) (μ : R) (k : ℕ)
(h : MapsTo (f - μ • (1 : End R M))
(f.genEigenspace μ k) (f.genEigenspace μ k) :=
mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ) μ k) :
| IsNilpotent ((f - μ • 1).restrict h) := by
use k
ext ⟨x, hx⟩
rw [mem_genEigenspace_nat] at hx
rw [LinearMap.zero_apply, ZeroMemClass.coe_zero, ZeroMemClass.coe_eq_zero,
Module.End.pow_restrict, LinearMap.restrict_apply]
| Mathlib/LinearAlgebra/Eigenspace/Basic.lean | 367 | 372 |
/-
Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.AlgebraicGeometry.EllipticCurve.Group
import Mathlib.NumberTheory.EllipticDivisibilitySequence
/-!
# Division polynomials of Weierstrass curves
This file defines certain polynomials associated to division polynomials of Weierstrass curves.
These are defined in terms of the auxiliary sequences for normalised elliptic divisibility sequences
(EDS) as defined in `Mathlib.NumberTheory.EllipticDivisibilitySequence`.
## Mathematical background
Let `W` be a Weierstrass curve over a commutative ring `R`. The sequence of `n`-division polynomials
`ψₙ ∈ R[X, Y]` of `W` is the normalised EDS with initial values
* `ψ₀ := 0`,
* `ψ₁ := 1`,
* `ψ₂ := 2Y + a₁X + a₃`,
* `ψ₃ := 3X⁴ + b₂X³ + 3b₄X² + 3b₆X + b₈`, and
* `ψ₄ := ψ₂ ⬝ (2X⁶ + b₂X⁵ + 5b₄X⁴ + 10b₆X³ + 10b₈X² + (b₂b₈ - b₄b₆)X + (b₄b₈ - b₆²))`.
Furthermore, define the associated sequences `φₙ, ωₙ ∈ R[X, Y]` by
* `φₙ := Xψₙ² - ψₙ₊₁ ⬝ ψₙ₋₁`, and
* `ωₙ := (ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)) / 2`.
Note that `ωₙ` is always well-defined as a polynomial in `R[X, Y]`. As a start, it can be shown by
induction that `ψₙ` always divides `ψ₂ₙ` in `R[X, Y]`, so that `ψ₂ₙ / ψₙ` is always well-defined as
a polynomial, while division by `2` is well-defined when `R` has characteristic different from `2`.
In general, it can be shown that `2` always divides the polynomial `ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)`
in the characteristic `0` universal ring `𝓡[X, Y] := ℤ[A₁, A₂, A₃, A₄, A₆][X, Y]` of `W`, where the
`Aᵢ` are indeterminates. Then `ωₙ` can be equivalently defined as the image of this division under
the associated universal morphism `𝓡[X, Y] → R[X, Y]` mapping `Aᵢ` to `aᵢ`.
Now, in the coordinate ring `R[W]`, note that `ψ₂²` is congruent to the polynomial
`Ψ₂Sq := 4X³ + b₂X² + 2b₄X + b₆ ∈ R[X]`. As such, the recurrences of a normalised EDS show that
`ψₙ / ψ₂` are congruent to certain polynomials in `R[W]`. In particular, define `preΨₙ ∈ R[X]` as
the auxiliary sequence for a normalised EDS with extra parameter `Ψ₂Sq²` and initial values
* `preΨ₀ := 0`,
* `preΨ₁ := 1`,
* `preΨ₂ := 1`,
* `preΨ₃ := ψ₃`, and
* `preΨ₄ := ψ₄ / ψ₂`.
The corresponding normalised EDS `Ψₙ ∈ R[X, Y]` is then given by
* `Ψₙ := preΨₙ ⬝ ψ₂` if `n` is even, and
* `Ψₙ := preΨₙ` if `n` is odd.
Furthermore, define the associated sequences `ΨSqₙ, Φₙ ∈ R[X]` by
* `ΨSqₙ := preΨₙ² ⬝ Ψ₂Sq` if `n` is even,
* `ΨSqₙ := preΨₙ²` if `n` is odd,
* `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁` if `n` is even, and
* `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁ ⬝ Ψ₂Sq` if `n` is odd.
With these definitions, `ψₙ ∈ R[X, Y]` and `φₙ ∈ R[X, Y]` are congruent in `R[W]` to `Ψₙ ∈ R[X, Y]`
and `Φₙ ∈ R[X]` respectively, which are defined in terms of `Ψ₂Sq ∈ R[X]` and `preΨₙ ∈ R[X]`.
## Main definitions
* `WeierstrassCurve.preΨ`: the univariate polynomials `preΨₙ`.
* `WeierstrassCurve.ΨSq`: the univariate polynomials `ΨSqₙ`.
* `WeierstrassCurve.Ψ`: the bivariate polynomials `Ψₙ`.
* `WeierstrassCurve.Φ`: the univariate polynomials `Φₙ`.
* `WeierstrassCurve.ψ`: the bivariate `n`-division polynomials `ψₙ`.
* `WeierstrassCurve.φ`: the bivariate polynomials `φₙ`.
* TODO: the bivariate polynomials `ωₙ`.
## Implementation notes
Analogously to `Mathlib.NumberTheory.EllipticDivisibilitySequence`, the bivariate polynomials
`Ψₙ` are defined in terms of the univariate polynomials `preΨₙ`. This is done partially to avoid
ring division, but more crucially to allow the definition of `ΨSqₙ` and `Φₙ` as univariate
polynomials without needing to work under the coordinate ring, and to allow the computation of their
leading terms without ambiguity. Furthermore, evaluating these polynomials at a rational point on
`W` recovers their original definition up to linear combinations of the Weierstrass equation of `W`,
hence also avoiding the need to work in the coordinate ring.
TODO: implementation notes for the definition of `ωₙ`.
## References
[J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009]
## Tags
elliptic curve, division polynomial, torsion point
-/
open Polynomial
open scoped Polynomial.Bivariate
local macro "C_simp" : tactic =>
`(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow])
local macro "map_simp" : tactic =>
`(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow, map_div₀,
Polynomial.map_ofNat, Polynomial.map_one, map_C, map_X, Polynomial.map_neg, Polynomial.map_add,
Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom,
apply_ite <| mapRingHom _, WeierstrassCurve.map])
universe r s u v
namespace WeierstrassCurve
variable {R : Type r} {S : Type s} [CommRing R] [CommRing S] (W : WeierstrassCurve R)
section Ψ₂Sq
/-! ### The univariate polynomial `Ψ₂Sq` -/
/-- The `2`-division polynomial `ψ₂ = Ψ₂`. -/
noncomputable def ψ₂ : R[X][Y] :=
W.toAffine.polynomialY
/-- The univariate polynomial `Ψ₂Sq` congruent to `ψ₂²`. -/
noncomputable def Ψ₂Sq : R[X] :=
C 4 * X ^ 3 + C W.b₂ * X ^ 2 + C (2 * W.b₄) * X + C W.b₆
lemma C_Ψ₂Sq : C W.Ψ₂Sq = W.ψ₂ ^ 2 - 4 * W.toAffine.polynomial := by
rw [Ψ₂Sq, ψ₂, b₂, b₄, b₆, Affine.polynomialY, Affine.polynomial]
C_simp
ring1
lemma ψ₂_sq : W.ψ₂ ^ 2 = C W.Ψ₂Sq + 4 * W.toAffine.polynomial := by
rw [C_Ψ₂Sq, sub_add_cancel]
lemma Affine.CoordinateRing.mk_ψ₂_sq : mk W W.ψ₂ ^ 2 = mk W (C W.Ψ₂Sq) := by
rw [C_Ψ₂Sq, map_sub, map_mul, AdjoinRoot.mk_self, mul_zero, sub_zero, map_pow]
-- TODO: remove `twoTorsionPolynomial` in favour of `Ψ₂Sq`
lemma Ψ₂Sq_eq : W.Ψ₂Sq = W.twoTorsionPolynomial.toPoly :=
rfl
end Ψ₂Sq
section preΨ'
/-! ### The univariate polynomials `preΨₙ` for `n ∈ ℕ` -/
/-- The `3`-division polynomial `ψ₃ = Ψ₃`. -/
noncomputable def Ψ₃ : R[X] :=
3 * X ^ 4 + C W.b₂ * X ^ 3 + 3 * C W.b₄ * X ^ 2 + 3 * C W.b₆ * X + C W.b₈
/-- The univariate polynomial `preΨ₄`, which is auxiliary to the 4-division polynomial
`ψ₄ = Ψ₄ = preΨ₄ψ₂`. -/
noncomputable def preΨ₄ : R[X] :=
2 * X ^ 6 + C W.b₂ * X ^ 5 + 5 * C W.b₄ * X ^ 4 + 10 * C W.b₆ * X ^ 3 + 10 * C W.b₈ * X ^ 2 +
C (W.b₂ * W.b₈ - W.b₄ * W.b₆) * X + C (W.b₄ * W.b₈ - W.b₆ ^ 2)
/-- The univariate polynomials `preΨₙ` for `n ∈ ℕ`, which are auxiliary to the bivariate polynomials
`Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/
noncomputable def preΨ' (n : ℕ) : R[X] :=
preNormEDS' (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n
@[simp]
lemma preΨ'_zero : W.preΨ' 0 = 0 :=
preNormEDS'_zero ..
@[simp]
lemma preΨ'_one : W.preΨ' 1 = 1 :=
preNormEDS'_one ..
@[simp]
lemma preΨ'_two : W.preΨ' 2 = 1 :=
preNormEDS'_two ..
@[simp]
lemma preΨ'_three : W.preΨ' 3 = W.Ψ₃ :=
preNormEDS'_three ..
@[simp]
lemma preΨ'_four : W.preΨ' 4 = W.preΨ₄ :=
preNormEDS'_four ..
lemma preΨ'_even (m : ℕ) : W.preΨ' (2 * (m + 3)) =
W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2 :=
preNormEDS'_even ..
lemma preΨ'_odd (m : ℕ) : W.preΨ' (2 * (m + 2) + 1) =
W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) :=
preNormEDS'_odd ..
end preΨ'
section preΨ
/-! ### The univariate polynomials `preΨₙ` for `n ∈ ℤ` -/
/-- The univariate polynomials `preΨₙ` for `n ∈ ℤ`, which are auxiliary to the bivariate polynomials
`Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/
noncomputable def preΨ (n : ℤ) : R[X] :=
preNormEDS (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n
@[simp]
lemma preΨ_ofNat (n : ℕ) : W.preΨ n = W.preΨ' n :=
preNormEDS_ofNat ..
@[simp]
lemma preΨ_zero : W.preΨ 0 = 0 :=
preNormEDS_zero ..
@[simp]
lemma preΨ_one : W.preΨ 1 = 1 :=
preNormEDS_one ..
@[simp]
lemma preΨ_two : W.preΨ 2 = 1 :=
preNormEDS_two ..
@[simp]
lemma preΨ_three : W.preΨ 3 = W.Ψ₃ :=
preNormEDS_three ..
@[simp]
lemma preΨ_four : W.preΨ 4 = W.preΨ₄ :=
preNormEDS_four ..
lemma preΨ_even_ofNat (m : ℕ) : W.preΨ (2 * (m + 3)) =
W.preΨ (m + 2) ^ 2 * W.preΨ (m + 3) * W.preΨ (m + 5) -
W.preΨ (m + 1) * W.preΨ (m + 3) * W.preΨ (m + 4) ^ 2 :=
preNormEDS_even_ofNat ..
lemma preΨ_odd_ofNat (m : ℕ) : W.preΨ (2 * (m + 2) + 1) =
W.preΨ (m + 4) * W.preΨ (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ (m + 1) * W.preΨ (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) :=
preNormEDS_odd_ofNat ..
@[simp]
lemma preΨ_neg (n : ℤ) : W.preΨ (-n) = -W.preΨ n :=
preNormEDS_neg ..
lemma preΨ_even (m : ℤ) : W.preΨ (2 * m) =
W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) -
W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2 :=
preNormEDS_even ..
lemma preΨ_odd (m : ℤ) : W.preΨ (2 * m + 1) =
W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) :=
preNormEDS_odd ..
end preΨ
section ΨSq
/-! ### The univariate polynomials `ΨSqₙ` -/
/-- The univariate polynomials `ΨSqₙ` congruent to `ψₙ²`. -/
noncomputable def ΨSq (n : ℤ) : R[X] :=
W.preΨ n ^ 2 * if Even n then W.Ψ₂Sq else 1
@[simp]
lemma ΨSq_ofNat (n : ℕ) : W.ΨSq n = W.preΨ' n ^ 2 * if Even n then W.Ψ₂Sq else 1 := by
simp only [ΨSq, preΨ_ofNat, Int.even_coe_nat]
@[simp]
lemma ΨSq_zero : W.ΨSq 0 = 0 := by
rw [← Nat.cast_zero, ΨSq_ofNat, preΨ'_zero, zero_pow two_ne_zero, zero_mul]
@[simp]
lemma ΨSq_one : W.ΨSq 1 = 1 := by
rw [← Nat.cast_one, ΨSq_ofNat, preΨ'_one, one_pow, one_mul, if_neg Nat.not_even_one]
@[simp]
lemma ΨSq_two : W.ΨSq 2 = W.Ψ₂Sq := by
rw [← Nat.cast_two, ΨSq_ofNat, preΨ'_two, one_pow, one_mul, if_pos even_two]
@[simp]
lemma ΨSq_three : W.ΨSq 3 = W.Ψ₃ ^ 2 := by
rw [← Nat.cast_three, ΨSq_ofNat, preΨ'_three, if_neg <| by decide, mul_one]
@[simp]
lemma ΨSq_four : W.ΨSq 4 = W.preΨ₄ ^ 2 * W.Ψ₂Sq := by
rw [← Nat.cast_four, ΨSq_ofNat, preΨ'_four, if_pos <| by decide]
lemma ΨSq_even_ofNat (m : ℕ) : W.ΨSq (2 * (m + 3)) =
(W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2) ^ 2 * W.Ψ₂Sq := by
rw_mod_cast [ΨSq_ofNat, preΨ'_even, if_pos <| even_two_mul _]
lemma ΨSq_odd_ofNat (m : ℕ) : W.ΨSq (2 * (m + 2) + 1) =
(W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by
rw_mod_cast [ΨSq_ofNat, preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, mul_one]
@[simp]
lemma ΨSq_neg (n : ℤ) : W.ΨSq (-n) = W.ΨSq n := by
simp only [ΨSq, preΨ_neg, neg_sq, even_neg]
lemma ΨSq_even (m : ℤ) : W.ΨSq (2 * m) =
(W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) -
W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2) ^ 2 * W.Ψ₂Sq := by
rw [ΨSq, preΨ_even, if_pos <| even_two_mul _]
lemma ΨSq_odd (m : ℤ) : W.ΨSq (2 * m + 1) =
(W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by
rw [ΨSq, preΨ_odd, if_neg m.not_even_two_mul_add_one, mul_one]
end ΨSq
section Ψ
/-! ### The bivariate polynomials `Ψₙ` -/
/-- The bivariate polynomials `Ψₙ` congruent to the `n`-division polynomials `ψₙ`. -/
protected noncomputable def Ψ (n : ℤ) : R[X][Y] :=
C (W.preΨ n) * if Even n then W.ψ₂ else 1
open WeierstrassCurve (Ψ)
@[simp]
lemma Ψ_ofNat (n : ℕ) : W.Ψ n = C (W.preΨ' n) * if Even n then W.ψ₂ else 1 := by
simp only [Ψ, preΨ_ofNat, Int.even_coe_nat]
@[simp]
lemma Ψ_zero : W.Ψ 0 = 0 := by
rw [← Nat.cast_zero, Ψ_ofNat, preΨ'_zero, C_0, zero_mul]
@[simp]
lemma Ψ_one : W.Ψ 1 = 1 := by
rw [← Nat.cast_one, Ψ_ofNat, preΨ'_one, C_1, if_neg Nat.not_even_one, mul_one]
@[simp]
lemma Ψ_two : W.Ψ 2 = W.ψ₂ := by
rw [← Nat.cast_two, Ψ_ofNat, preΨ'_two, C_1, one_mul, if_pos even_two]
@[simp]
lemma Ψ_three : W.Ψ 3 = C W.Ψ₃ := by
rw [← Nat.cast_three, Ψ_ofNat, preΨ'_three, if_neg <| by decide, mul_one]
@[simp]
lemma Ψ_four : W.Ψ 4 = C W.preΨ₄ * W.ψ₂ := by
rw [← Nat.cast_four, Ψ_ofNat, preΨ'_four, if_pos <| by decide]
lemma Ψ_even_ofNat (m : ℕ) : W.Ψ (2 * (m + 3)) * W.ψ₂ =
W.Ψ (m + 2) ^ 2 * W.Ψ (m + 3) * W.Ψ (m + 5) - W.Ψ (m + 1) * W.Ψ (m + 3) * W.Ψ (m + 4) ^ 2 := by
repeat rw_mod_cast [Ψ_ofNat]
simp_rw [preΨ'_even, if_pos <| even_two_mul _, Nat.even_add_one, ite_not]
split_ifs <;> C_simp <;> ring1
lemma Ψ_odd_ofNat (m : ℕ) : W.Ψ (2 * (m + 2) + 1) =
W.Ψ (m + 4) * W.Ψ (m + 2) ^ 3 - W.Ψ (m + 1) * W.Ψ (m + 3) ^ 3 +
W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) *
C (if Even m then W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3
else -W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3) := by
repeat rw_mod_cast [Ψ_ofNat]
simp_rw [preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, Nat.even_add_one, ite_not]
split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1
@[simp]
lemma Ψ_neg (n : ℤ) : W.Ψ (-n) = -W.Ψ n := by
simp only [Ψ, preΨ_neg, C_neg, neg_mul (α := R[X][Y]), even_neg]
lemma Ψ_even (m : ℤ) : W.Ψ (2 * m) * W.ψ₂ =
W.Ψ (m - 1) ^ 2 * W.Ψ m * W.Ψ (m + 2) - W.Ψ (m - 2) * W.Ψ m * W.Ψ (m + 1) ^ 2 := by
repeat rw [Ψ]
simp_rw [preΨ_even, if_pos <| even_two_mul _, Int.even_add_one, show m + 2 = m + 1 + 1 by ring1,
Int.even_add_one, show m - 2 = m - 1 - 1 by ring1, Int.even_sub_one, ite_not]
split_ifs <;> C_simp <;> ring1
lemma Ψ_odd (m : ℤ) : W.Ψ (2 * m + 1) =
W.Ψ (m + 2) * W.Ψ m ^ 3 - W.Ψ (m - 1) * W.Ψ (m + 1) ^ 3 +
W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) *
C (if Even m then W.preΨ (m + 2) * W.preΨ m ^ 3
else -W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3) := by
repeat rw [Ψ]
simp_rw [preΨ_odd, if_neg m.not_even_two_mul_add_one, show m + 2 = m + 1 + 1 by ring1,
Int.even_add_one, Int.even_sub_one, ite_not]
split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1
|
lemma Affine.CoordinateRing.mk_Ψ_sq (n : ℤ) : mk W (W.Ψ n) ^ 2 = mk W (C <| W.ΨSq n) := by
simp only [Ψ, ΨSq, map_one, map_mul, map_pow, one_pow, mul_pow, ite_pow, apply_ite C,
apply_ite <| mk W, mk_ψ₂_sq]
| Mathlib/AlgebraicGeometry/EllipticCurve/DivisionPolynomial/Basic.lean | 376 | 380 |
/-
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.Integrals
import Mathlib.MeasureTheory.Integral.PeakFunction
/-! # Euler's infinite product for the sine function
This file proves the infinite product formula
$$ \sin \pi z = \pi z \prod_{n = 1}^\infty \left(1 - \frac{z ^ 2}{n ^ 2}\right) $$
for any real or complex `z`. Our proof closely follows the article
[Salwinski, *Euler's Sine Product Formula: An Elementary Proof*][salwinski2018]: the basic strategy
is to prove a recurrence relation for the integrals `∫ x in 0..π/2, cos 2 z x * cos x ^ (2 * n)`,
generalising the arguments used to prove Wallis' limit formula for `π`.
-/
open scoped Real Topology
open Real Set Filter intervalIntegral MeasureTheory.MeasureSpace
namespace EulerSine
section IntegralRecursion
/-! ## Recursion formula for the integral of `cos (2 * z * x) * cos x ^ n`
We evaluate the integral of `cos (2 * z * x) * cos x ^ n`, for any complex `z` and even integers
`n`, via repeated integration by parts. -/
variable {z : ℂ} {n : ℕ}
theorem antideriv_cos_comp_const_mul (hz : z ≠ 0) (x : ℝ) :
HasDerivAt (fun y : ℝ => Complex.sin (2 * z * y) / (2 * z)) (Complex.cos (2 * z * x)) x := by
have a : HasDerivAt (fun y : ℂ => y * (2 * z)) _ x := hasDerivAt_mul_const _
have b : HasDerivAt (Complex.sin ∘ fun y : ℂ => (y * (2 * z))) _ x :=
HasDerivAt.comp (x : ℂ) (Complex.hasDerivAt_sin (x * (2 * z))) a
have c := b.comp_ofReal.div_const (2 * z)
field_simp at c; simp only [fun y => mul_comm y (2 * z)] at c
exact c
theorem antideriv_sin_comp_const_mul (hz : z ≠ 0) (x : ℝ) :
HasDerivAt (fun y : ℝ => -Complex.cos (2 * z * y) / (2 * z)) (Complex.sin (2 * z * x)) x := by
have a : HasDerivAt (fun y : ℂ => y * (2 * z)) _ x := hasDerivAt_mul_const _
have b : HasDerivAt (Complex.cos ∘ fun y : ℂ => (y * (2 * z))) _ x :=
HasDerivAt.comp (x : ℂ) (Complex.hasDerivAt_cos (x * (2 * z))) a
have c := (b.comp_ofReal.div_const (2 * z)).neg
field_simp at c; simp only [fun y => mul_comm y (2 * z)] at c
exact c
theorem integral_cos_mul_cos_pow_aux (hn : 2 ≤ n) (hz : z ≠ 0) :
(∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ n) =
n / (2 * z) *
∫ x in (0 : ℝ)..π / 2, Complex.sin (2 * z * x) * sin x * (cos x : ℂ) ^ (n - 1) := by
have der1 :
∀ x : ℝ,
x ∈ uIcc 0 (π / 2) →
HasDerivAt (fun y : ℝ => (cos y : ℂ) ^ n) (-n * sin x * (cos x : ℂ) ^ (n - 1)) x := by
intro x _
have b : HasDerivAt (fun y : ℝ => (cos y : ℂ)) (-sin x) x := by
simpa using (hasDerivAt_cos x).ofReal_comp
convert HasDerivAt.comp x (hasDerivAt_pow _ _) b using 1
ring
convert (config := { sameFun := true })
integral_mul_deriv_eq_deriv_mul der1 (fun x _ => antideriv_cos_comp_const_mul hz x) _ _ using 2
· ext1 x; rw [mul_comm]
· rw [Complex.ofReal_zero, mul_zero, Complex.sin_zero, zero_div, mul_zero, sub_zero,
cos_pi_div_two, Complex.ofReal_zero, zero_pow (by positivity : n ≠ 0), zero_mul, zero_sub,
← integral_neg, ← integral_const_mul]
refine integral_congr fun x _ => ?_
field_simp; ring
· apply Continuous.intervalIntegrable
exact
(continuous_const.mul (Complex.continuous_ofReal.comp continuous_sin)).mul
((Complex.continuous_ofReal.comp continuous_cos).pow (n - 1))
· apply Continuous.intervalIntegrable
exact Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)
theorem integral_sin_mul_sin_mul_cos_pow_eq (hn : 2 ≤ n) (hz : z ≠ 0) :
(∫ x in (0 : ℝ)..π / 2, Complex.sin (2 * z * x) * sin x * (cos x : ℂ) ^ (n - 1)) =
(n / (2 * z) * ∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ n) -
(n - 1) / (2 * z) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (n - 2) := by
| have der1 :
∀ x : ℝ,
x ∈ uIcc 0 (π / 2) →
HasDerivAt (fun y : ℝ => sin y * (cos y : ℂ) ^ (n - 1))
((cos x : ℂ) ^ n - (n - 1) * (sin x : ℂ) ^ 2 * (cos x : ℂ) ^ (n - 2)) x := by
intro x _
have c := HasDerivAt.comp (x : ℂ) (hasDerivAt_pow (n - 1) _) (Complex.hasDerivAt_cos x)
convert ((Complex.hasDerivAt_sin x).mul c).comp_ofReal using 1
· ext1 y; simp only [Complex.ofReal_sin, Complex.ofReal_cos, Function.comp]
· simp only [Complex.ofReal_cos, Complex.ofReal_sin]
rw [mul_neg, mul_neg, ← sub_eq_add_neg, Function.comp_apply]
congr 1
· rw [← pow_succ', Nat.sub_add_cancel (by omega : 1 ≤ n)]
· have : ((n - 1 : ℕ) : ℂ) = (n : ℂ) - 1 := by
rw [Nat.cast_sub (one_le_two.trans hn), Nat.cast_one]
rw [Nat.sub_sub, this]
ring
convert
integral_mul_deriv_eq_deriv_mul der1 (fun x _ => antideriv_sin_comp_const_mul hz x) _ _ using 1
· refine integral_congr fun x _ => ?_
ring_nf
· -- now a tedious rearrangement of terms
-- gather into a single integral, and deal with continuity subgoals:
rw [sin_zero, cos_pi_div_two, Complex.ofReal_zero, zero_pow, zero_mul,
mul_zero, zero_mul, zero_mul, sub_zero, zero_sub, ←
integral_neg, ← integral_const_mul, ← integral_const_mul, ← integral_sub]
rotate_left
· apply Continuous.intervalIntegrable
exact
continuous_const.mul
((Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)).mul
((Complex.continuous_ofReal.comp continuous_cos).pow n))
· apply Continuous.intervalIntegrable
exact
continuous_const.mul
((Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)).mul
((Complex.continuous_ofReal.comp continuous_cos).pow (n - 2)))
· exact Nat.sub_ne_zero_of_lt hn
refine integral_congr fun x _ => ?_
dsimp only
-- get rid of real trig functions and divisions by 2 * z:
rw [Complex.ofReal_cos, Complex.ofReal_sin, Complex.sin_sq, ← mul_div_right_comm, ←
mul_div_right_comm, ← sub_div, mul_div, ← neg_div]
congr 1
have : Complex.cos x ^ n = Complex.cos x ^ (n - 2) * Complex.cos x ^ 2 := by
conv_lhs => rw [← Nat.sub_add_cancel hn, pow_add]
rw [this]
ring
· apply Continuous.intervalIntegrable
exact
((Complex.continuous_ofReal.comp continuous_cos).pow n).sub
((continuous_const.mul ((Complex.continuous_ofReal.comp continuous_sin).pow 2)).mul
((Complex.continuous_ofReal.comp continuous_cos).pow (n - 2)))
· apply Continuous.intervalIntegrable
exact Complex.continuous_sin.comp (continuous_const.mul Complex.continuous_ofReal)
/-- Note this also holds for `z = 0`, but we do not need this case for `sin_pi_mul_eq`. -/
theorem integral_cos_mul_cos_pow (hn : 2 ≤ n) (hz : z ≠ 0) :
(((1 : ℂ) - (4 : ℂ) * z ^ 2 / (n : ℂ) ^ 2) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ n) =
| Mathlib/Analysis/SpecialFunctions/Trigonometric/EulerSineProd.lean | 88 | 147 |
/-
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.AlgebraicTopology.SimplicialObject.Split
import Mathlib.AlgebraicTopology.DoldKan.Degeneracies
import Mathlib.AlgebraicTopology.DoldKan.FunctorN
/-!
# Split simplicial objects in preadditive categories
In this file we define a functor `nondegComplex : SimplicialObject.Split C ⥤ ChainComplex C ℕ`
when `C` is a preadditive category with finite coproducts, and get an isomorphism
`toKaroubiNondegComplexFunctorIsoN₁ : nondegComplex ⋙ toKaroubi _ ≅ forget C ⋙ DoldKan.N₁`.
(See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.)
-/
open CategoryTheory CategoryTheory.Limits CategoryTheory.Category CategoryTheory.Preadditive
CategoryTheory.Idempotents Opposite AlgebraicTopology AlgebraicTopology.DoldKan
Simplicial DoldKan
namespace SimplicialObject
namespace Splitting
variable {C : Type*} [Category C] {X : SimplicialObject C}
(s : Splitting X)
/-- The projection on a summand of the coproduct decomposition given
by a splitting of a simplicial object. -/
noncomputable def πSummand [HasZeroMorphisms C] {Δ : SimplexCategoryᵒᵖ} (A : IndexSet Δ) :
X.obj Δ ⟶ s.N A.1.unop.len :=
s.desc Δ (fun B => by
by_cases h : B = A
· exact eqToHom (by subst h; rfl)
· exact 0)
@[reassoc (attr := simp)]
theorem cofan_inj_πSummand_eq_id [HasZeroMorphisms C] {Δ : SimplexCategoryᵒᵖ} (A : IndexSet Δ) :
(s.cofan Δ).inj A ≫ s.πSummand A = 𝟙 _ := by
simp [πSummand]
@[reassoc (attr := simp)]
theorem cofan_inj_πSummand_eq_zero [HasZeroMorphisms C] {Δ : SimplexCategoryᵒᵖ} (A B : IndexSet Δ)
(h : B ≠ A) : (s.cofan Δ).inj A ≫ s.πSummand B = 0 := by
dsimp [πSummand]
rw [ι_desc, dif_neg h.symm]
variable [Preadditive C]
theorem decomposition_id (Δ : SimplexCategoryᵒᵖ) :
𝟙 (X.obj Δ) = ∑ A : IndexSet Δ, s.πSummand A ≫ (s.cofan Δ).inj A := by
apply s.hom_ext'
intro A
dsimp
erw [comp_id, comp_sum, Finset.sum_eq_single A, cofan_inj_πSummand_eq_id_assoc]
· intro B _ h₂
rw [s.cofan_inj_πSummand_eq_zero_assoc _ _ h₂, zero_comp]
· simp
@[reassoc (attr := simp)]
theorem σ_comp_πSummand_id_eq_zero {n : ℕ} (i : Fin (n + 1)) :
X.σ i ≫ s.πSummand (IndexSet.id (op ⦋n + 1⦌)) = 0 := by
apply s.hom_ext'
intro A
dsimp only [SimplicialObject.σ]
rw [comp_zero, s.cofan_inj_epi_naturality_assoc A (SimplexCategory.σ i).op,
cofan_inj_πSummand_eq_zero]
rw [ne_comm]
change ¬(A.epiComp (SimplexCategory.σ i).op).EqId
rw [IndexSet.eqId_iff_len_eq]
have h := SimplexCategory.len_le_of_epi (inferInstance : Epi A.e)
dsimp at h ⊢
omega
/-- If a simplicial object `X` in an additive category is split,
then `PInfty` vanishes on all the summands of `X _⦋n⦌` which do
not correspond to the identity of `⦋n⦌`. -/
theorem cofan_inj_comp_PInfty_eq_zero {X : SimplicialObject C} (s : SimplicialObject.Splitting X)
{n : ℕ} (A : SimplicialObject.Splitting.IndexSet (op ⦋n⦌)) (hA : ¬A.EqId) :
(s.cofan _).inj A ≫ PInfty.f n = 0 := by
rw [SimplicialObject.Splitting.IndexSet.eqId_iff_mono] at hA
rw [SimplicialObject.Splitting.cofan_inj_eq, assoc, degeneracy_comp_PInfty X n A.e hA, comp_zero]
theorem comp_PInfty_eq_zero_iff {Z : C} {n : ℕ} (f : Z ⟶ X _⦋n⦌) :
| f ≫ PInfty.f n = 0 ↔ f ≫ s.πSummand (IndexSet.id (op ⦋n⦌)) = 0 := by
constructor
· intro h
rcases n with _|n
· dsimp at h
| Mathlib/AlgebraicTopology/DoldKan/SplitSimplicialObject.lean | 91 | 95 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kim Morrison, Ainsley Pahljina
-/
import Mathlib.RingTheory.Fintype
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Zify
/-!
# The Lucas-Lehmer test for Mersenne primes.
We define `lucasLehmerResidue : Π p : ℕ, ZMod (2^p - 1)`, and
prove `lucasLehmerResidue p = 0 → Prime (mersenne p)`.
We construct a `norm_num` extension to calculate this residue to certify primality of Mersenne
primes using `lucas_lehmer_sufficiency`.
## TODO
- Show reverse implication.
- Speed up the calculations using `n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]`.
- Find some bigger primes!
## History
This development began as a student project by Ainsley Pahljina,
and was then cleaned up for mathlib by Kim Morrison.
The tactic for certified computation of Lucas-Lehmer residues was provided by Mario Carneiro.
This tactic was ported by Thomas Murrills to Lean 4, and then it was converted to a `norm_num`
extension and made to use kernel reductions by Kyle Miller.
-/
assert_not_exists TwoSidedIdeal
/-- The Mersenne numbers, 2^p - 1. -/
def mersenne (p : ℕ) : ℕ :=
2 ^ p - 1
theorem strictMono_mersenne : StrictMono mersenne := fun m n h ↦
(Nat.sub_lt_sub_iff_right <| Nat.one_le_pow _ _ two_pos).2 <| by gcongr; norm_num1
@[simp]
theorem mersenne_lt_mersenne {p q : ℕ} : mersenne p < mersenne q ↔ p < q :=
strictMono_mersenne.lt_iff_lt
@[gcongr] protected alias ⟨_, GCongr.mersenne_lt_mersenne⟩ := mersenne_lt_mersenne
@[simp]
theorem mersenne_le_mersenne {p q : ℕ} : mersenne p ≤ mersenne q ↔ p ≤ q :=
strictMono_mersenne.le_iff_le
@[gcongr] protected alias ⟨_, GCongr.mersenne_le_mersenne⟩ := mersenne_le_mersenne
@[simp] theorem mersenne_zero : mersenne 0 = 0 := rfl
@[simp] lemma mersenne_odd : ∀ {p : ℕ}, Odd (mersenne p) ↔ p ≠ 0
| 0 => by simp
| p + 1 => by
simpa using Nat.Even.sub_odd (one_le_pow₀ one_le_two)
(even_two.pow_of_ne_zero p.succ_ne_zero) odd_one
@[simp] theorem mersenne_pos {p : ℕ} : 0 < mersenne p ↔ 0 < p := mersenne_lt_mersenne (p := 0)
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
alias ⟨_, mersenne_pos_of_pos⟩ := mersenne_pos
/-- Extension for the `positivity` tactic: `mersenne`. -/
@[positivity mersenne _]
def evalMersenne : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℕ), ~q(mersenne $a) =>
let ra ← core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa => pure (.positive q(mersenne_pos_of_pos $pa))
| _ => pure (.nonnegative q(Nat.zero_le (mersenne $a)))
| _, _, _ => throwError "not mersenne"
end Mathlib.Meta.Positivity
@[simp]
theorem one_lt_mersenne {p : ℕ} : 1 < mersenne p ↔ 1 < p :=
mersenne_lt_mersenne (p := 1)
@[simp]
theorem succ_mersenne (k : ℕ) : mersenne k + 1 = 2 ^ k := by
rw [mersenne, tsub_add_cancel_of_le]
exact one_le_pow₀ (by norm_num)
namespace LucasLehmer
open Nat
/-!
We now define three(!) different versions of the recurrence
`s (i+1) = (s i)^2 - 2`.
These versions take values either in `ℤ`, in `ZMod (2^p - 1)`, or
in `ℤ` but applying `% (2^p - 1)` at each step.
They are each useful at different points in the proof,
so we take a moment setting up the lemmas relating them.
-/
/-- The recurrence `s (i+1) = (s i)^2 - 2` in `ℤ`. -/
def s : ℕ → ℤ
| 0 => 4
| i + 1 => s i ^ 2 - 2
/-- The recurrence `s (i+1) = (s i)^2 - 2` in `ZMod (2^p - 1)`. -/
def sZMod (p : ℕ) : ℕ → ZMod (2 ^ p - 1)
| 0 => 4
| i + 1 => sZMod p i ^ 2 - 2
/-- The recurrence `s (i+1) = ((s i)^2 - 2) % (2^p - 1)` in `ℤ`. -/
def sMod (p : ℕ) : ℕ → ℤ
| 0 => 4 % (2 ^ p - 1)
| i + 1 => (sMod p i ^ 2 - 2) % (2 ^ p - 1)
theorem mersenne_int_pos {p : ℕ} (hp : p ≠ 0) : (0 : ℤ) < 2 ^ p - 1 :=
sub_pos.2 <| mod_cast Nat.one_lt_two_pow hp
theorem mersenne_int_ne_zero (p : ℕ) (hp : p ≠ 0) : (2 ^ p - 1 : ℤ) ≠ 0 :=
(mersenne_int_pos hp).ne'
theorem sMod_nonneg (p : ℕ) (hp : p ≠ 0) (i : ℕ) : 0 ≤ sMod p i := by
cases i <;> dsimp [sMod]
· exact sup_eq_right.mp rfl
· apply Int.emod_nonneg
exact mersenne_int_ne_zero p hp
theorem sMod_mod (p i : ℕ) : sMod p i % (2 ^ p - 1) = sMod p i := by cases i <;> simp [sMod]
theorem sMod_lt (p : ℕ) (hp : p ≠ 0) (i : ℕ) : sMod p i < 2 ^ p - 1 := by
rw [← sMod_mod]
refine (Int.emod_lt_abs _ (mersenne_int_ne_zero p hp)).trans_eq ?_
exact abs_of_nonneg (mersenne_int_pos hp).le
theorem sZMod_eq_s (p' : ℕ) (i : ℕ) : sZMod (p' + 2) i = (s i : ZMod (2 ^ (p' + 2) - 1)) := by
induction i with
| zero => dsimp [s, sZMod]; norm_num
| succ i ih => push_cast [s, sZMod, ih]; rfl
-- These next two don't make good `norm_cast` lemmas.
theorem Int.natCast_pow_pred (b p : ℕ) (w : 0 < b) : ((b ^ p - 1 : ℕ) : ℤ) = (b : ℤ) ^ p - 1 := by
have : 1 ≤ b ^ p := Nat.one_le_pow p b w
norm_cast
theorem Int.coe_nat_two_pow_pred (p : ℕ) : ((2 ^ p - 1 : ℕ) : ℤ) = (2 ^ p - 1 : ℤ) :=
Int.natCast_pow_pred 2 p (by decide)
theorem sZMod_eq_sMod (p : ℕ) (i : ℕ) : sZMod p i = (sMod p i : ZMod (2 ^ p - 1)) := by
induction i <;> push_cast [← Int.coe_nat_two_pow_pred p, sMod, sZMod, *] <;> rfl
/-- The Lucas-Lehmer residue is `s p (p-2)` in `ZMod (2^p - 1)`. -/
def lucasLehmerResidue (p : ℕ) : ZMod (2 ^ p - 1) :=
sZMod p (p - 2)
theorem residue_eq_zero_iff_sMod_eq_zero (p : ℕ) (w : 1 < p) :
lucasLehmerResidue p = 0 ↔ sMod p (p - 2) = 0 := by
dsimp [lucasLehmerResidue]
rw [sZMod_eq_sMod p]
constructor
· -- We want to use that fact that `0 ≤ s_mod p (p-2) < 2^p - 1`
-- and `lucas_lehmer_residue p = 0 → 2^p - 1 ∣ s_mod p (p-2)`.
intro h
| simp? [ZMod.intCast_zmod_eq_zero_iff_dvd] at h says
simp only [ZMod.intCast_zmod_eq_zero_iff_dvd, ofNat_pos, pow_pos, cast_pred,
| Mathlib/NumberTheory/LucasLehmer.lean | 173 | 174 |
/-
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, Sander Dahmen, Kim Morrison
-/
import Mathlib.Algebra.Algebra.Tower
import Mathlib.LinearAlgebra.LinearIndependent.Basic
import Mathlib.Data.Set.Card
/-!
# Dimension of modules and vector spaces
## Main definitions
* The rank of a module is defined as `Module.rank : Cardinal`.
This is defined as the supremum of the cardinalities of linearly independent subsets.
## Main statements
* `LinearMap.rank_le_of_injective`: the source of an injective linear map has dimension
at most that of the target.
* `LinearMap.rank_le_of_surjective`: the target of a surjective linear map has dimension
at most that of that source.
## Implementation notes
Many theorems in this file are not universe-generic when they relate dimensions
in different universes. They should be as general as they can be without
inserting `lift`s. The types `M`, `M'`, ... all live in different universes,
and `M₁`, `M₂`, ... all live in the same universe.
-/
noncomputable section
universe w w' u u' v v'
variable {R : Type u} {R' : Type u'} {M M₁ : Type v} {M' : Type v'}
open Cardinal Submodule Function Set
section Module
section
variable [Semiring R] [AddCommMonoid M] [Module R M]
variable (R M)
/-- The rank of a module, defined as a term of type `Cardinal`.
We define this as the supremum of the cardinalities of linearly independent subsets.
The supremum may not be attained, see https://mathoverflow.net/a/263053.
For a free module over any ring satisfying the strong rank condition
(e.g. left-noetherian rings, commutative rings, and in particular division rings and fields),
this is the same as the dimension of the space (i.e. the cardinality of any basis).
In particular this agrees with the usual notion of the dimension of a vector space.
See also `Module.finrank` for a `ℕ`-valued function which returns the correct value
for a finite-dimensional vector space (but 0 for an infinite-dimensional vector space).
-/
@[stacks 09G3 "first part"]
protected irreducible_def Module.rank : Cardinal :=
⨆ ι : { s : Set M // LinearIndepOn R id s }, (#ι.1)
theorem rank_le_card : Module.rank R M ≤ #M :=
(Module.rank_def _ _).trans_le (ciSup_le' fun _ ↦ mk_set_le _)
lemma nonempty_linearIndependent_set : Nonempty {s : Set M // LinearIndepOn R id s } :=
⟨⟨∅, linearIndepOn_empty _ _⟩⟩
end
namespace LinearIndependent
variable [Semiring R] [AddCommMonoid M] [Module R M]
variable [Nontrivial R]
theorem cardinal_lift_le_rank {ι : Type w} {v : ι → M}
(hv : LinearIndependent R v) :
Cardinal.lift.{v} #ι ≤ Cardinal.lift.{w} (Module.rank R M) := by
rw [Module.rank]
refine le_trans ?_ (lift_le.mpr <| le_ciSup (bddAbove_range _) ⟨_, hv.linearIndepOn_id⟩)
exact lift_mk_le'.mpr ⟨(Equiv.ofInjective _ hv.injective).toEmbedding⟩
lemma aleph0_le_rank {ι : Type w} [Infinite ι] {v : ι → M}
(hv : LinearIndependent R v) : ℵ₀ ≤ Module.rank R M :=
aleph0_le_lift.mp <| (aleph0_le_lift.mpr <| aleph0_le_mk ι).trans hv.cardinal_lift_le_rank
theorem cardinal_le_rank {ι : Type v} {v : ι → M}
(hv : LinearIndependent R v) : #ι ≤ Module.rank R M := by
simpa using hv.cardinal_lift_le_rank
theorem cardinal_le_rank' {s : Set M}
(hs : LinearIndependent R (fun x => x : s → M)) : #s ≤ Module.rank R M :=
hs.cardinal_le_rank
theorem _root_.LinearIndepOn.encard_le_toENat_rank {ι : Type*} {v : ι → M} {s : Set ι}
(hs : LinearIndepOn R v s) : s.encard ≤ (Module.rank R M).toENat := by
simpa using OrderHom.mono (β := ℕ∞) Cardinal.toENat hs.linearIndependent.cardinal_lift_le_rank
end LinearIndependent
section SurjectiveInjective
section Semiring
variable [Semiring R] [AddCommMonoid M] [Module R M] [Semiring R']
section
variable [AddCommMonoid M'] [Module R' M']
/-- If `M / R` and `M' / R'` are modules, `i : R' → R` is an injective map
non-zero elements, `j : M →+ M'` is an injective monoid homomorphism, such that the scalar
multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to
the rank of `M' / R'`. As a special case, taking `R = R'` it is
`LinearMap.lift_rank_le_of_injective`. -/
theorem lift_rank_le_of_injective_injectiveₛ (i : R' → R) (j : M →+ M')
(hi : Injective i) (hj : Injective j)
(hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) :
lift.{v'} (Module.rank R M) ≤ lift.{v} (Module.rank R' M') := by
simp_rw [Module.rank, lift_iSup (bddAbove_range _)]
exact ciSup_mono' (bddAbove_range _) fun ⟨s, h⟩ ↦ ⟨⟨j '' s,
LinearIndepOn.id_image (h.linearIndependent.map_of_injective_injectiveₛ i j hi hj hc)⟩,
lift_mk_le'.mpr ⟨(Equiv.Set.image j s hj).toEmbedding⟩⟩
/-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a surjective map, and
`j : M →+ M'` is an injective monoid homomorphism, such that the scalar multiplications on `M` and
`M'` are compatible, then the rank of `M / R` is smaller than or equal to the rank of `M' / R'`.
As a special case, taking `R = R'` it is `LinearMap.lift_rank_le_of_injective`. -/
theorem lift_rank_le_of_surjective_injective (i : R → R') (j : M →+ M')
(hi : Surjective i) (hj : Injective j) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) :
lift.{v'} (Module.rank R M) ≤ lift.{v} (Module.rank R' M') := by
obtain ⟨i', hi'⟩ := hi.hasRightInverse
refine lift_rank_le_of_injective_injectiveₛ i' j (fun _ _ h ↦ ?_) hj fun r m ↦ ?_
· apply_fun i at h
rwa [hi', hi'] at h
rw [hc (i' r) m, hi']
/-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a bijective map which maps zero to zero,
`j : M ≃+ M'` is a group isomorphism, such that the scalar multiplications on `M` and `M'` are
compatible, then the rank of `M / R` is equal to the rank of `M' / R'`.
As a special case, taking `R = R'` it is `LinearEquiv.lift_rank_eq`. -/
theorem lift_rank_eq_of_equiv_equiv (i : R → R') (j : M ≃+ M')
(hi : Bijective i) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) :
lift.{v'} (Module.rank R M) = lift.{v} (Module.rank R' M') :=
(lift_rank_le_of_surjective_injective i j hi.2 j.injective hc).antisymm <|
lift_rank_le_of_injective_injectiveₛ i j.symm hi.1
j.symm.injective fun _ _ ↦ j.symm_apply_eq.2 <| by erw [hc, j.apply_symm_apply]
end
section
variable [AddCommMonoid M₁] [Module R' M₁]
/-- The same-universe version of `lift_rank_le_of_injective_injective`. -/
theorem rank_le_of_injective_injectiveₛ (i : R' → R) (j : M →+ M₁)
(hi : Injective i) (hj : Injective j)
(hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) :
Module.rank R M ≤ Module.rank R' M₁ := by
simpa only [lift_id] using lift_rank_le_of_injective_injectiveₛ i j hi hj hc
/-- The same-universe version of `lift_rank_le_of_surjective_injective`. -/
theorem rank_le_of_surjective_injective (i : R → R') (j : M →+ M₁)
(hi : Surjective i) (hj : Injective j)
(hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) :
Module.rank R M ≤ Module.rank R' M₁ := by
simpa only [lift_id] using lift_rank_le_of_surjective_injective i j hi hj hc
/-- The same-universe version of `lift_rank_eq_of_equiv_equiv`. -/
theorem rank_eq_of_equiv_equiv (i : R → R') (j : M ≃+ M₁)
(hi : Bijective i) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) :
Module.rank R M = Module.rank R' M₁ := by
simpa only [lift_id] using lift_rank_eq_of_equiv_equiv i j hi hc
end
end Semiring
section Ring
variable [Ring R] [AddCommGroup M] [Module R M] [Ring R']
/-- If `M / R` and `M' / R'` are modules, `i : R' → R` is a map which sends non-zero elements to
non-zero elements, `j : M →+ M'` is an injective group homomorphism, such that the scalar
multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to
the rank of `M' / R'`. As a special case, taking `R = R'` it is
`LinearMap.lift_rank_le_of_injective`. -/
theorem lift_rank_le_of_injective_injective [AddCommGroup M'] [Module R' M']
(i : R' → R) (j : M →+ M') (hi : ∀ r, i r = 0 → r = 0) (hj : Injective j)
(hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) :
lift.{v'} (Module.rank R M) ≤ lift.{v} (Module.rank R' M') := by
simp_rw [Module.rank, lift_iSup (bddAbove_range _)]
exact ciSup_mono' (bddAbove_range _) fun ⟨s, h⟩ ↦
⟨⟨j '' s, LinearIndepOn.id_image <| h.linearIndependent.map_of_injective_injective i j hi
(fun _ _ ↦ hj <| by rwa [j.map_zero]) hc⟩,
lift_mk_le'.mpr ⟨(Equiv.Set.image j s hj).toEmbedding⟩⟩
/-- The same-universe version of `lift_rank_le_of_injective_injective`. -/
theorem rank_le_of_injective_injective [AddCommGroup M₁] [Module R' M₁]
(i : R' → R) (j : M →+ M₁) (hi : ∀ r, i r = 0 → r = 0) (hj : Injective j)
(hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) :
Module.rank R M ≤ Module.rank R' M₁ := by
simpa only [lift_id] using lift_rank_le_of_injective_injective i j hi hj hc
end Ring
namespace Algebra
variable {R : Type w} {S : Type v} [CommSemiring R] [Semiring S] [Algebra R S]
{R' : Type w'} {S' : Type v'} [CommSemiring R'] [Semiring S'] [Algebra R' S']
/-- If `S / R` and `S' / R'` are algebras, `i : R' →+* R` and `j : S →+* S'` are injective ring
homomorphisms, such that `R' → R → S → S'` and `R' → S'` commute, then the rank of `S / R` is
smaller than or equal to the rank of `S' / R'`. -/
theorem lift_rank_le_of_injective_injective
(i : R' →+* R) (j : S →+* S') (hi : Injective i) (hj : Injective j)
(hc : (j.comp (algebraMap R S)).comp i = algebraMap R' S') :
lift.{v'} (Module.rank R S) ≤ lift.{v} (Module.rank R' S') := by
refine _root_.lift_rank_le_of_injective_injectiveₛ i j hi hj fun r _ ↦ ?_
have := congr($hc r)
simp only [RingHom.coe_comp, comp_apply] at this
simp_rw [smul_def, AddMonoidHom.coe_coe, map_mul, this]
/-- If `S / R` and `S' / R'` are algebras, `i : R →+* R'` is a surjective ring homomorphism,
`j : S →+* S'` is an injective ring homomorphism, such that `R → R' → S'` and `R → S → S'` commute,
then the rank of `S / R` is smaller than or equal to the rank of `S' / R'`. -/
theorem lift_rank_le_of_surjective_injective
(i : R →+* R') (j : S →+* S') (hi : Surjective i) (hj : Injective j)
(hc : (algebraMap R' S').comp i = j.comp (algebraMap R S)) :
lift.{v'} (Module.rank R S) ≤ lift.{v} (Module.rank R' S') := by
refine _root_.lift_rank_le_of_surjective_injective i j hi hj fun r _ ↦ ?_
have := congr($hc r)
simp only [RingHom.coe_comp, comp_apply] at this
simp only [smul_def, AddMonoidHom.coe_coe, map_mul, ZeroHom.coe_coe, this]
/-- If `S / R` and `S' / R'` are algebras, `i : R ≃+* R'` and `j : S ≃+* S'` are
ring isomorphisms, such that `R → R' → S'` and `R → S → S'` commute,
then the rank of `S / R` is equal to the rank of `S' / R'`. -/
theorem lift_rank_eq_of_equiv_equiv (i : R ≃+* R') (j : S ≃+* S')
(hc : (algebraMap R' S').comp i.toRingHom = j.toRingHom.comp (algebraMap R S)) :
lift.{v'} (Module.rank R S) = lift.{v} (Module.rank R' S') := by
refine _root_.lift_rank_eq_of_equiv_equiv i j i.bijective fun r _ ↦ ?_
have := congr($hc r)
simp only [RingEquiv.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe, comp_apply] at this
simp only [smul_def, RingEquiv.coe_toAddEquiv, map_mul, ZeroHom.coe_coe, this]
variable {S' : Type v} [Semiring S'] [Algebra R' S']
/-- The same-universe version of `Algebra.lift_rank_le_of_injective_injective`. -/
theorem rank_le_of_injective_injective
(i : R' →+* R) (j : S →+* S') (hi : Injective i) (hj : Injective j)
(hc : (j.comp (algebraMap R S)).comp i = algebraMap R' S') :
Module.rank R S ≤ Module.rank R' S' := by
simpa only [lift_id] using lift_rank_le_of_injective_injective i j hi hj hc
/-- The same-universe version of `Algebra.lift_rank_le_of_surjective_injective`. -/
theorem rank_le_of_surjective_injective
(i : R →+* R') (j : S →+* S') (hi : Surjective i) (hj : Injective j)
(hc : (algebraMap R' S').comp i = j.comp (algebraMap R S)) :
Module.rank R S ≤ Module.rank R' S' := by
simpa only [lift_id] using lift_rank_le_of_surjective_injective i j hi hj hc
/-- The same-universe version of `Algebra.lift_rank_eq_of_equiv_equiv`. -/
theorem rank_eq_of_equiv_equiv (i : R ≃+* R') (j : S ≃+* S')
(hc : (algebraMap R' S').comp i.toRingHom = j.toRingHom.comp (algebraMap R S)) :
Module.rank R S = Module.rank R' S' := by
simpa only [lift_id] using lift_rank_eq_of_equiv_equiv i j hc
end Algebra
end SurjectiveInjective
variable [Semiring R] [AddCommMonoid M] [Module R M]
[Semiring R'] [AddCommMonoid M'] [AddCommMonoid M₁]
[Module R M'] [Module R M₁] [Module R' M'] [Module R' M₁]
section
theorem LinearMap.lift_rank_le_of_injective (f : M →ₗ[R] M') (i : Injective f) :
Cardinal.lift.{v'} (Module.rank R M) ≤ Cardinal.lift.{v} (Module.rank R M') :=
lift_rank_le_of_injective_injectiveₛ (RingHom.id R) f (fun _ _ h ↦ h) i f.map_smul
theorem LinearMap.rank_le_of_injective (f : M →ₗ[R] M₁) (i : Injective f) :
Module.rank R M ≤ Module.rank R M₁ :=
Cardinal.lift_le.1 (f.lift_rank_le_of_injective i)
/-- The rank of the range of a linear map is at most the rank of the source. -/
-- The proof is: a free submodule of the range lifts to a free submodule of the
-- source, by arbitrarily lifting a basis.
theorem lift_rank_range_le (f : M →ₗ[R] M') : Cardinal.lift.{v}
(Module.rank R (LinearMap.range f)) ≤ Cardinal.lift.{v'} (Module.rank R M) := by
simp only [Module.rank_def]
rw [Cardinal.lift_iSup (Cardinal.bddAbove_range _)]
apply ciSup_le'
rintro ⟨s, li⟩
apply le_trans
swap
· apply Cardinal.lift_le.mpr
refine le_ciSup (Cardinal.bddAbove_range _) ⟨rangeSplitting f '' s, ?_⟩
apply LinearIndependent.of_comp f.rangeRestrict
convert li.comp (Equiv.Set.rangeSplittingImageEquiv f s) (Equiv.injective _) using 1
· exact (Cardinal.lift_mk_eq'.mpr ⟨Equiv.Set.rangeSplittingImageEquiv f s⟩).ge
theorem rank_range_le (f : M →ₗ[R] M₁) : Module.rank R (LinearMap.range f) ≤ Module.rank R M := by
simpa using lift_rank_range_le f
theorem lift_rank_map_le (f : M →ₗ[R] M') (p : Submodule R M) :
Cardinal.lift.{v} (Module.rank R (p.map f)) ≤ Cardinal.lift.{v'} (Module.rank R p) := by
have h := lift_rank_range_le (f.comp (Submodule.subtype p))
rwa [LinearMap.range_comp, range_subtype] at h
theorem rank_map_le (f : M →ₗ[R] M₁) (p : Submodule R M) :
Module.rank R (p.map f) ≤ Module.rank R p := by simpa using lift_rank_map_le f p
lemma Submodule.rank_mono {s t : Submodule R M} (h : s ≤ t) : Module.rank R s ≤ Module.rank R t :=
(Submodule.inclusion h).rank_le_of_injective fun ⟨x, _⟩ ⟨y, _⟩ eq =>
Subtype.eq <| show x = y from Subtype.ext_iff_val.1 eq
/-- Two linearly equivalent vector spaces have the same dimension, a version with different
universes. -/
theorem LinearEquiv.lift_rank_eq (f : M ≃ₗ[R] M') :
Cardinal.lift.{v'} (Module.rank R M) = Cardinal.lift.{v} (Module.rank R M') := by
apply le_antisymm
· exact f.toLinearMap.lift_rank_le_of_injective f.injective
· exact f.symm.toLinearMap.lift_rank_le_of_injective f.symm.injective
/-- Two linearly equivalent vector spaces have the same dimension. -/
theorem LinearEquiv.rank_eq (f : M ≃ₗ[R] M₁) : Module.rank R M = Module.rank R M₁ :=
Cardinal.lift_inj.1 f.lift_rank_eq
theorem lift_rank_range_of_injective (f : M →ₗ[R] M') (h : Injective f) :
lift.{v} (Module.rank R (LinearMap.range f)) = lift.{v'} (Module.rank R M) :=
(LinearEquiv.ofInjective f h).lift_rank_eq.symm
theorem rank_range_of_injective (f : M →ₗ[R] M₁) (h : Injective f) :
Module.rank R (LinearMap.range f) = Module.rank R M :=
(LinearEquiv.ofInjective f h).rank_eq.symm
|
theorem LinearEquiv.lift_rank_map_eq (f : M ≃ₗ[R] M') (p : Submodule R M) :
lift.{v} (Module.rank R (p.map (f : M →ₗ[R] M'))) = lift.{v'} (Module.rank R p) :=
| Mathlib/LinearAlgebra/Dimension/Basic.lean | 336 | 338 |
/-
Copyright (c) 2023 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.FieldTheory.SeparableDegree
import Mathlib.FieldTheory.IsSepClosed
/-!
# Separable closure
This file contains basics about the (relative) separable closure of a field extension.
## Main definitions
- `separableClosure`: the relative separable closure of `F` in `E`, or called maximal separable
subextension of `E / F`, is defined to be the intermediate field of `E / F` consisting of all
separable elements.
- `SeparableClosure`: the absolute separable closure, defined to be the relative separable
closure inside the algebraic closure.
- `Field.sepDegree F E`: the (infinite) separable degree $[E:F]_s$ of an algebraic extension
`E / F` of fields, defined to be the degree of `separableClosure F E / F`. Later we will show
that (`Field.finSepDegree_eq`, not in this file), if `Field.Emb F E` is finite, then this
coincides with `Field.finSepDegree F E`.
- `Field.insepDegree F E`: the (infinite) inseparable degree $[E:F]_i$ of an algebraic extension
`E / F` of fields, defined to be the degree of `E / separableClosure F E`.
- `Field.finInsepDegree F E`: the finite inseparable degree $[E:F]_i$ of an algebraic extension
`E / F` of fields, defined to be the degree of `E / separableClosure F E` as a natural number.
It is zero if such field extension is not finite.
## Main results
- `le_separableClosure_iff`: an intermediate field of `E / F` is contained in the
separable closure of `F` in `E` if and only if it is separable over `F`.
- `separableClosure.normalClosure_eq_self`: the normal closure of the separable
closure of `F` in `E` is equal to itself.
- `separableClosure.isGalois`: the separable closure in a normal extension is Galois
(namely, normal and separable).
- `separableClosure.isSepClosure`: the separable closure in a separably closed extension
is a separable closure of the base field.
- `IntermediateField.isSeparable_adjoin_iff_isSeparable`: `F(S) / F` is a separable extension if and
only if all elements of `S` are separable elements.
- `separableClosure.eq_top_iff`: the separable closure of `F` in `E` is equal to `E`
if and only if `E / F` is separable.
## Tags
separable degree, degree, separable closure
-/
open Module Polynomial IntermediateField Field
noncomputable section
universe u v w
variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E]
variable (K : Type w) [Field K] [Algebra F K]
section separableClosure
/-- The (relative) separable closure of `F` in `E`, or called maximal separable subextension
of `E / F`, is defined to be the intermediate field of `E / F` consisting of all separable
elements. The previous results prove that these elements are closed under field operations. -/
@[stacks 09HC]
def separableClosure : IntermediateField F E where
carrier := {x | IsSeparable F x}
mul_mem' := isSeparable_mul
add_mem' := isSeparable_add
algebraMap_mem' := isSeparable_algebraMap E
inv_mem' _ := isSeparable_inv
variable {F E K}
/-- An element is contained in the separable closure of `F` in `E` if and only if
it is a separable element. -/
theorem mem_separableClosure_iff {x : E} :
x ∈ separableClosure F E ↔ IsSeparable F x := Iff.rfl
/-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then `i x` is contained in
`separableClosure F K` if and only if `x` is contained in `separableClosure F E`. -/
theorem map_mem_separableClosure_iff (i : E →ₐ[F] K) {x : E} :
| i x ∈ separableClosure F K ↔ x ∈ separableClosure F E := by
simp_rw [mem_separableClosure_iff, IsSeparable, minpoly.algHom_eq i i.injective]
| Mathlib/FieldTheory/SeparableClosure.lean | 94 | 96 |
/-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Logic.Function.Basic
import Mathlib.Util.CompileInductive
import Mathlib.Tactic.Simps.NotationClass
/-!
# Typeclass for a type `F` with an injective map to `A → B`
This typeclass is primarily for use by homomorphisms like `MonoidHom` and `LinearMap`.
There is the "D"ependent version `DFunLike` and the non-dependent version `FunLike`.
## Basic usage of `DFunLike` and `FunLike`
A typical type of morphisms should be declared as:
```
structure MyHom (A B : Type*) [MyClass A] [MyClass B] where
(toFun : A → B)
(map_op' : ∀ (x y : A), toFun (MyClass.op x y) = MyClass.op (toFun x) (toFun y))
namespace MyHom
variable (A B : Type*) [MyClass A] [MyClass B]
instance : FunLike (MyHom A B) A B where
coe := MyHom.toFun
coe_injective' := fun f g h => by cases f; cases g; congr
@[ext] theorem ext {f g : MyHom A B} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h
/-- Copy of a `MyHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : MyHom A B) (f' : A → B) (h : f' = ⇑f) : MyHom A B where
toFun := f'
map_op' := h.symm ▸ f.map_op'
end MyHom
```
This file will then provide a `CoeFun` instance and various
extensionality and simp lemmas.
## Morphism classes extending `DFunLike` and `FunLike`
The `FunLike` design provides further benefits if you put in a bit more work.
The first step is to extend `FunLike` to create a class of those types satisfying
the axioms of your new type of morphisms.
Continuing the example above:
```
/-- `MyHomClass F A B` states that `F` is a type of `MyClass.op`-preserving morphisms.
You should extend this class when you extend `MyHom`. -/
class MyHomClass (F : Type*) (A B : outParam Type*) [MyClass A] [MyClass B]
[FunLike F A B] : Prop :=
(map_op : ∀ (f : F) (x y : A), f (MyClass.op x y) = MyClass.op (f x) (f y))
@[simp]
lemma map_op {F A B : Type*} [MyClass A] [MyClass B] [FunLike F A B] [MyHomClass F A B]
(f : F) (x y : A) :
f (MyClass.op x y) = MyClass.op (f x) (f y) :=
MyHomClass.map_op _ _ _
-- You can add the below instance next to `MyHomClass.instFunLike`:
instance : MyHomClass (MyHom A B) A B where
map_op := MyHom.map_op'
-- [Insert `ext` and `copy` here]
```
Note that `A B` are marked as `outParam` even though they are not purely required to be so
due to the `FunLike` parameter already filling them in. This is required to see through
type synonyms, which is important in the category theory library. Also, it appears having them as
`outParam` is slightly faster.
The second step is to add instances of your new `MyHomClass` for all types extending `MyHom`.
Typically, you can just declare a new class analogous to `MyHomClass`:
```
structure CoolerHom (A B : Type*) [CoolClass A] [CoolClass B] extends MyHom A B where
(map_cool' : toFun CoolClass.cool = CoolClass.cool)
class CoolerHomClass (F : Type*) (A B : outParam Type*) [CoolClass A] [CoolClass B]
[FunLike F A B] extends MyHomClass F A B :=
(map_cool : ∀ (f : F), f CoolClass.cool = CoolClass.cool)
@[simp] lemma map_cool {F A B : Type*} [CoolClass A] [CoolClass B] [FunLike F A B]
[CoolerHomClass F A B] (f : F) : f CoolClass.cool = CoolClass.cool :=
CoolerHomClass.map_cool _
variable {A B : Type*} [CoolClass A] [CoolClass B]
instance : FunLike (CoolerHom A B) A B where
coe f := f.toFun
coe_injective' := fun f g h ↦ by cases f; cases g; congr; apply DFunLike.coe_injective; congr
instance : CoolerHomClass (CoolerHom A B) A B where
map_op f := f.map_op'
map_cool f := f.map_cool'
-- [Insert `ext` and `copy` here]
```
Then any declaration taking a specific type of morphisms as parameter can instead take the
class you just defined:
```
-- Compare with: lemma do_something (f : MyHom A B) : sorry := sorry
lemma do_something {F : Type*} [FunLike F A B] [MyHomClass F A B] (f : F) : sorry :=
sorry
```
This means anything set up for `MyHom`s will automatically work for `CoolerHomClass`es,
and defining `CoolerHomClass` only takes a constant amount of effort,
instead of linearly increasing the work per `MyHom`-related declaration.
## Design rationale
The current form of FunLike was set up in pull request https://github.com/leanprover-community/mathlib4/pull/8386:
https://github.com/leanprover-community/mathlib4/pull/8386
We made `FunLike` *unbundled*: child classes don't extend `FunLike`, they take a `[FunLike F A B]`
parameter instead. This suits the instance synthesis algorithm better: it's easy to verify a type
does **not** have a `FunLike` instance by checking the discrimination tree once instead of searching
the entire `extends` hierarchy.
-/
/-- The class `DFunLike F α β` expresses that terms of type `F` have an
injective coercion to (dependent) functions from `α` to `β`.
For non-dependent functions you can also use the abbreviation `FunLike`.
This typeclass is used in the definition of the homomorphism typeclasses,
such as `ZeroHomClass`, `MulHomClass`, `MonoidHomClass`, ....
-/
@[notation_class * toFun Simps.findCoercionArgs]
class DFunLike (F : Sort*) (α : outParam (Sort*)) (β : outParam <| α → Sort*) where
/-- The coercion from `F` to a function. -/
coe : F → ∀ a : α, β a
/-- The coercion to functions must be injective. -/
coe_injective' : Function.Injective coe
-- https://github.com/leanprover/lean4/issues/2096
compile_def% DFunLike.coe
/-- The class `FunLike F α β` (`Fun`ction-`Like`) expresses that terms of type `F`
have an injective coercion to functions from `α` to `β`.
`FunLike` is the non-dependent version of `DFunLike`.
This typeclass is used in the definition of the homomorphism typeclasses,
such as `ZeroHomClass`, `MulHomClass`, `MonoidHomClass`, ....
-/
abbrev FunLike F α β := DFunLike F α fun _ => β
section Dependent
/-! ### `DFunLike F α β` where `β` depends on `a : α` -/
variable (F α : Sort*) (β : α → Sort*)
namespace DFunLike
variable {F α β} [i : DFunLike F α β]
instance (priority := 100) hasCoeToFun : CoeFun F (fun _ ↦ ∀ a : α, β a) where
coe := @DFunLike.coe _ _ β _ -- need to make explicit to beta reduce for non-dependent functions
run_cmd Lean.Elab.Command.liftTermElabM do
Lean.Meta.registerCoercion ``DFunLike.coe
(some { numArgs := 5, coercee := 4, type := .coeFun })
theorem coe_eq_coe_fn : (DFunLike.coe (F := F)) = (fun f => ↑f) := rfl
theorem coe_injective : Function.Injective (fun f : F ↦ (f : ∀ a : α, β a)) :=
DFunLike.coe_injective'
@[simp]
theorem coe_fn_eq {f g : F} : (f : ∀ a : α, β a) = (g : ∀ a : α, β a) ↔ f = g :=
⟨fun h ↦ DFunLike.coe_injective' h, fun h ↦ by cases h; rfl⟩
theorem ext' {f g : F} (h : (f : ∀ a : α, β a) = (g : ∀ a : α, β a)) : f = g :=
DFunLike.coe_injective' h
theorem ext'_iff {f g : F} : f = g ↔ (f : ∀ a : α, β a) = (g : ∀ a : α, β a) :=
coe_fn_eq.symm
theorem ext (f g : F) (h : ∀ x : α, f x = g x) : f = g :=
DFunLike.coe_injective' (funext h)
|
theorem ext_iff {f g : F} : f = g ↔ ∀ x, f x = g x :=
| Mathlib/Data/FunLike/Basic.lean | 189 | 190 |
/-
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, Kexing Ying
-/
import Mathlib.Probability.Notation
import Mathlib.Probability.Integration
import Mathlib.MeasureTheory.Function.L2Space
/-!
# Variance of random variables
We define the variance of a real-valued random variable as `Var[X] = 𝔼[(X - 𝔼[X])^2]` (in the
`ProbabilityTheory` locale).
## Main definitions
* `ProbabilityTheory.evariance`: the variance of a real-valued random variable as an extended
non-negative real.
* `ProbabilityTheory.variance`: the variance of a real-valued random variable as a real number.
## Main results
* `ProbabilityTheory.variance_le_expectation_sq`: the inequality `Var[X] ≤ 𝔼[X^2]`.
* `ProbabilityTheory.meas_ge_le_variance_div_sq`: Chebyshev's inequality, i.e.,
`ℙ {ω | c ≤ |X ω - 𝔼[X]|} ≤ ENNReal.ofReal (Var[X] / c ^ 2)`.
* `ProbabilityTheory.meas_ge_le_evariance_div_sq`: Chebyshev's inequality formulated with
`evariance` without requiring the random variables to be L².
* `ProbabilityTheory.IndepFun.variance_add`: the variance of the sum of two independent
random variables is the sum of the variances.
* `ProbabilityTheory.IndepFun.variance_sum`: the variance of a finite sum of pairwise
independent random variables is the sum of the variances.
* `ProbabilityTheory.variance_le_sub_mul_sub`: the variance of a random variable `X` satisfying
`a ≤ X ≤ b` almost everywhere is at most `(b - 𝔼 X) * (𝔼 X - a)`.
* `ProbabilityTheory.variance_le_sq_of_bounded`: the variance of a random variable `X` satisfying
`a ≤ X ≤ b` almost everywhere is at most`((b - a) / 2) ^ 2`.
-/
open MeasureTheory Filter Finset
noncomputable section
open scoped MeasureTheory ProbabilityTheory ENNReal NNReal
namespace ProbabilityTheory
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {X : Ω → ℝ} {μ : Measure Ω}
variable (X μ) in
-- Porting note: Consider if `evariance` or `eVariance` is better. Also,
-- consider `eVariationOn` in `Mathlib.Analysis.BoundedVariation`.
/-- The `ℝ≥0∞`-valued variance of a real-valued random variable defined as the Lebesgue integral of
`‖X - 𝔼[X]‖^2`. -/
def evariance : ℝ≥0∞ := ∫⁻ ω, ‖X ω - μ[X]‖ₑ ^ 2 ∂μ
variable (X μ) in
/-- The `ℝ`-valued variance of a real-valued random variable defined by applying `ENNReal.toReal`
to `evariance`. -/
def variance : ℝ := (evariance X μ).toReal
/-- The `ℝ≥0∞`-valued variance of the real-valued random variable `X` according to the measure `μ`.
This is defined as the Lebesgue integral of `(X - 𝔼[X])^2`. -/
scoped notation "eVar[" X "; " μ "]" => ProbabilityTheory.evariance X μ
/-- The `ℝ≥0∞`-valued variance of the real-valued random variable `X` according to the volume
measure.
This is defined as the Lebesgue integral of `(X - 𝔼[X])^2`. -/
scoped notation "eVar[" X "]" => eVar[X; MeasureTheory.MeasureSpace.volume]
/-- The `ℝ`-valued variance of the real-valued random variable `X` according to the measure `μ`.
It is set to `0` if `X` has infinite variance. -/
scoped notation "Var[" X "; " μ "]" => ProbabilityTheory.variance X μ
/-- The `ℝ`-valued variance of the real-valued random variable `X` according to the volume measure.
It is set to `0` if `X` has infinite variance. -/
scoped notation "Var[" X "]" => Var[X; MeasureTheory.MeasureSpace.volume]
theorem evariance_lt_top [IsFiniteMeasure μ] (hX : MemLp X 2 μ) : evariance X μ < ∞ := by
have := ENNReal.pow_lt_top (hX.sub <| memLp_const <| μ[X]).2 (n := 2)
rw [eLpNorm_eq_lintegral_rpow_enorm two_ne_zero ENNReal.ofNat_ne_top, ← ENNReal.rpow_two] at this
simp only [ENNReal.toReal_ofNat, Pi.sub_apply, ENNReal.toReal_one, one_div] at this
rw [← ENNReal.rpow_mul, inv_mul_cancel₀ (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_one] at this
simp_rw [ENNReal.rpow_two] at this
exact this
lemma evariance_ne_top [IsFiniteMeasure μ] (hX : MemLp X 2 μ) : evariance X μ ≠ ∞ :=
(evariance_lt_top hX).ne
theorem evariance_eq_top [IsFiniteMeasure μ] (hXm : AEStronglyMeasurable X μ) (hX : ¬MemLp X 2 μ) :
evariance X μ = ∞ := by
by_contra h
rw [← Ne, ← lt_top_iff_ne_top] at h
have : MemLp (fun ω => X ω - μ[X]) 2 μ := by
refine ⟨hXm.sub aestronglyMeasurable_const, ?_⟩
rw [eLpNorm_eq_lintegral_rpow_enorm two_ne_zero ENNReal.ofNat_ne_top]
simp only [ENNReal.toReal_ofNat, ENNReal.toReal_one, ENNReal.rpow_two, Ne]
exact ENNReal.rpow_lt_top_of_nonneg (by linarith) h.ne
refine hX ?_
convert this.add (memLp_const μ[X])
ext ω
rw [Pi.add_apply, sub_add_cancel]
theorem evariance_lt_top_iff_memLp [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ) :
evariance X μ < ∞ ↔ MemLp X 2 μ where
mp := by contrapose!; rw [top_le_iff]; exact evariance_eq_top hX
mpr := evariance_lt_top
@[deprecated (since := "2025-02-21")]
alias evariance_lt_top_iff_memℒp := evariance_lt_top_iff_memLp
lemma evariance_eq_top_iff [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ) :
evariance X μ = ∞ ↔ ¬ MemLp X 2 μ := by simp [← evariance_lt_top_iff_memLp hX]
theorem ofReal_variance [IsFiniteMeasure μ] (hX : MemLp X 2 μ) :
.ofReal (variance X μ) = evariance X μ := by
rw [variance, ENNReal.ofReal_toReal]
exact evariance_ne_top hX
protected alias _root_.MeasureTheory.MemLp.evariance_lt_top := evariance_lt_top
protected alias _root_.MeasureTheory.MemLp.evariance_ne_top := evariance_ne_top
protected alias _root_.MeasureTheory.MemLp.ofReal_variance_eq := ofReal_variance
@[deprecated (since := "2025-02-21")]
protected alias _root_.MeasureTheory.Memℒp.evariance_lt_top := evariance_lt_top
@[deprecated (since := "2025-02-21")]
protected alias _root_.MeasureTheory.Memℒp.evariance_ne_top := evariance_ne_top
@[deprecated (since := "2025-02-21")]
protected alias _root_.MeasureTheory.Memℒp.ofReal_variance_eq := ofReal_variance
variable (X μ) in
theorem evariance_eq_lintegral_ofReal :
evariance X μ = ∫⁻ ω, ENNReal.ofReal ((X ω - μ[X]) ^ 2) ∂μ := by
simp [evariance, ← enorm_pow, Real.enorm_of_nonneg (sq_nonneg _)]
lemma variance_eq_integral (hX : AEMeasurable X μ) : Var[X; μ] = ∫ ω, (X ω - μ[X]) ^ 2 ∂μ := by
simp [variance, evariance, toReal_enorm, ← integral_toReal ((hX.sub_const _).enorm.pow_const _) <|
.of_forall fun _ ↦ ENNReal.pow_lt_top enorm_lt_top]
lemma variance_of_integral_eq_zero (hX : AEMeasurable X μ) (hXint : μ[X] = 0) :
variance X μ = ∫ ω, X ω ^ 2 ∂μ := by
simp [variance_eq_integral hX, hXint]
@[deprecated (since := "2025-01-23")]
alias _root_.MeasureTheory.Memℒp.variance_eq := variance_eq_integral
@[deprecated (since := "2025-01-23")]
alias _root_.MeasureTheory.Memℒp.variance_eq_of_integral_eq_zero := variance_of_integral_eq_zero
@[simp]
theorem evariance_zero : evariance 0 μ = 0 := by simp [evariance]
theorem evariance_eq_zero_iff (hX : AEMeasurable X μ) :
evariance X μ = 0 ↔ X =ᵐ[μ] fun _ => μ[X] := by
simp [evariance, lintegral_eq_zero_iff' ((hX.sub_const _).enorm.pow_const _), EventuallyEq,
sub_eq_zero]
theorem evariance_mul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) :
evariance (fun ω => c * X ω) μ = ENNReal.ofReal (c ^ 2) * evariance X μ := by
rw [evariance, evariance, ← lintegral_const_mul' _ _ ENNReal.ofReal_lt_top.ne]
congr with ω
rw [integral_const_mul, ← mul_sub, enorm_mul, mul_pow, ← enorm_pow,
Real.enorm_of_nonneg (sq_nonneg _)]
@[simp]
theorem variance_zero (μ : Measure Ω) : variance 0 μ = 0 := by
simp only [variance, evariance_zero, ENNReal.toReal_zero]
theorem variance_nonneg (X : Ω → ℝ) (μ : Measure Ω) : 0 ≤ variance X μ :=
ENNReal.toReal_nonneg
theorem variance_mul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) :
variance (fun ω => c * X ω) μ = c ^ 2 * variance X μ := by
rw [variance, evariance_mul, ENNReal.toReal_mul, ENNReal.toReal_ofReal (sq_nonneg _)]
rfl
theorem variance_smul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) :
variance (c • X) μ = c ^ 2 * variance X μ :=
variance_mul c X μ
theorem variance_smul' {A : Type*} [CommSemiring A] [Algebra A ℝ] (c : A) (X : Ω → ℝ)
(μ : Measure Ω) : variance (c • X) μ = c ^ 2 • variance X μ := by
convert variance_smul (algebraMap A ℝ c) X μ using 1
· congr; simp only [algebraMap_smul]
· simp only [Algebra.smul_def, map_pow]
theorem variance_def' [IsProbabilityMeasure μ] {X : Ω → ℝ} (hX : MemLp X 2 μ) :
variance X μ = μ[X ^ 2] - μ[X] ^ 2 := by
simp only [variance_eq_integral hX.aestronglyMeasurable.aemeasurable, sub_sq']
rw [integral_sub, integral_add]; rotate_left
· exact hX.integrable_sq
· apply integrable_const
· apply hX.integrable_sq.add
apply integrable_const
· exact ((hX.integrable one_le_two).const_mul 2).mul_const' _
simp only [integral_const, measureReal_univ_eq_one, smul_eq_mul, one_mul, integral_mul_const,
integral_const_mul, Pi.pow_apply]
ring
theorem variance_le_expectation_sq [IsProbabilityMeasure μ] {X : Ω → ℝ}
(hm : AEStronglyMeasurable X μ) : variance X μ ≤ μ[X ^ 2] := by
by_cases hX : MemLp X 2 μ
· rw [variance_def' hX]
simp only [sq_nonneg, sub_le_self_iff]
rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
· by_cases hint : Integrable X μ; swap
· simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
exact le_rfl
· rw [integral_undef]
· exact integral_nonneg fun a => sq_nonneg _
intro h
have A : MemLp (X - fun ω : Ω => μ[X]) 2 μ :=
(memLp_two_iff_integrable_sq (hint.aestronglyMeasurable.sub aestronglyMeasurable_const)).2 h
have B : MemLp (fun _ : Ω => μ[X]) 2 μ := memLp_const _
apply hX
convert A.add B
simp
· exact Eventually.of_forall fun x => sq_nonneg _
· exact (AEMeasurable.pow_const (hm.aemeasurable.sub_const _) _).aestronglyMeasurable
theorem evariance_def' [IsProbabilityMeasure μ] {X : Ω → ℝ} (hX : AEStronglyMeasurable X μ) :
evariance X μ = (∫⁻ ω, ‖X ω‖ₑ ^ 2 ∂μ) - ENNReal.ofReal (μ[X] ^ 2) := by
by_cases hℒ : MemLp X 2 μ
· rw [← ofReal_variance hℒ, variance_def' hℒ, ENNReal.ofReal_sub _ (sq_nonneg _)]
congr
simp_rw [← enorm_pow, enorm]
rw [lintegral_coe_eq_integral]
· simp
· simpa using hℒ.abs.integrable_sq
· symm
rw [evariance_eq_top hX hℒ, ENNReal.sub_eq_top_iff]
refine ⟨?_, ENNReal.ofReal_ne_top⟩
rw [MemLp, not_and] at hℒ
specialize hℒ hX
simp only [eLpNorm_eq_lintegral_rpow_enorm two_ne_zero ENNReal.ofNat_ne_top, not_lt, top_le_iff,
ENNReal.toReal_ofNat, one_div, ENNReal.rpow_eq_top_iff, inv_lt_zero, inv_pos, and_true,
or_iff_not_imp_left, not_and_or, zero_lt_two] at hℒ
exact mod_cast hℒ fun _ => zero_le_two
/-- **Chebyshev's inequality** for `ℝ≥0∞`-valued variance. -/
theorem meas_ge_le_evariance_div_sq {X : Ω → ℝ} (hX : AEStronglyMeasurable X μ) {c : ℝ≥0}
(hc : c ≠ 0) : μ {ω | ↑c ≤ |X ω - μ[X]|} ≤ evariance X μ / c ^ 2 := by
have A : (c : ℝ≥0∞) ≠ 0 := by rwa [Ne, ENNReal.coe_eq_zero]
have B : AEStronglyMeasurable (fun _ : Ω => μ[X]) μ := aestronglyMeasurable_const
convert meas_ge_le_mul_pow_eLpNorm μ two_ne_zero ENNReal.ofNat_ne_top (hX.sub B) A using 1
· congr
simp only [Pi.sub_apply, ENNReal.coe_le_coe, ← Real.norm_eq_abs, ← coe_nnnorm,
NNReal.coe_le_coe, ENNReal.ofReal_coe_nnreal]
· rw [eLpNorm_eq_lintegral_rpow_enorm two_ne_zero ENNReal.ofNat_ne_top]
simp only [show ENNReal.ofNNReal (c ^ 2) = (ENNReal.ofNNReal c) ^ 2 by norm_cast,
ENNReal.toReal_ofNat, one_div, Pi.sub_apply]
rw [div_eq_mul_inv, ENNReal.inv_pow, mul_comm, ENNReal.rpow_two]
congr
simp_rw [← ENNReal.rpow_mul, inv_mul_cancel₀ (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_two,
ENNReal.rpow_one, evariance]
|
/-- **Chebyshev's inequality**: one can control the deviation probability of a real random variable
from its expectation in terms of the variance. -/
theorem meas_ge_le_variance_div_sq [IsFiniteMeasure μ] {X : Ω → ℝ} (hX : MemLp X 2 μ) {c : ℝ}
(hc : 0 < c) : μ {ω | c ≤ |X ω - μ[X]|} ≤ ENNReal.ofReal (variance X μ / c ^ 2) := by
rw [ENNReal.ofReal_div_of_pos (sq_pos_of_ne_zero hc.ne.symm), hX.ofReal_variance_eq]
convert @meas_ge_le_evariance_div_sq _ _ _ _ hX.1 c.toNNReal (by simp [hc]) using 1
· simp only [Real.coe_toNNReal', max_le_iff, abs_nonneg, and_true]
· rw [ENNReal.ofReal_pow hc.le]
rfl
-- Porting note: supplied `MeasurableSpace Ω` argument of `h` by unification
/-- The variance of the sum of two independent random variables is the sum of the variances. -/
theorem IndepFun.variance_add [IsProbabilityMeasure μ] {X Y : Ω → ℝ} (hX : MemLp X 2 μ)
| Mathlib/Probability/Variance.lean | 258 | 272 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Cardinal.Arithmetic
import Mathlib.SetTheory.Ordinal.FixedPoint
/-!
# Cofinality
This file contains the definition of cofinality of an order and an ordinal number.
## Main Definitions
* `Order.cof r` is the cofinality of a reflexive order. This is the smallest cardinality of a subset
`s` that is *cofinal*, i.e. `∀ x, ∃ y ∈ s, r x y`.
* `Ordinal.cof o` is the cofinality of the ordinal `o` when viewed as a linear order.
## Main Statements
* `Cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for
`c ≥ ℵ₀`.
## Implementation Notes
* The cofinality is defined for ordinals.
If `c` is a cardinal number, its cofinality is `c.ord.cof`.
-/
noncomputable section
open Function Cardinal Set Order
open scoped Ordinal
universe u v w
variable {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop}
/-! ### Cofinality of orders -/
attribute [local instance] IsRefl.swap
namespace Order
/-- Cofinality of a reflexive order `≼`. This is the smallest cardinality
of a subset `S : Set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/
def cof (r : α → α → Prop) : Cardinal :=
sInf { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }
/-- The set in the definition of `Order.cof` is nonempty. -/
private theorem cof_nonempty (r : α → α → Prop) [IsRefl α r] :
{ c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }.Nonempty :=
⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩
theorem cof_le (r : α → α → Prop) {S : Set α} (h : ∀ a, ∃ b ∈ S, r a b) : cof r ≤ #S :=
csInf_le' ⟨S, h, rfl⟩
theorem le_cof [IsRefl α r] (c : Cardinal) :
c ≤ cof r ↔ ∀ {S : Set α}, (∀ a, ∃ b ∈ S, r a b) → c ≤ #S := by
rw [cof, le_csInf_iff'' (cof_nonempty r)]
use fun H S h => H _ ⟨S, h, rfl⟩
rintro H d ⟨S, h, rfl⟩
exact H h
end Order
namespace RelIso
private theorem cof_le_lift [IsRefl β s] (f : r ≃r s) :
Cardinal.lift.{v} (Order.cof r) ≤ Cardinal.lift.{u} (Order.cof s) := by
rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)]
rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩
apply csInf_le'
refine ⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩, lift_mk_eq'.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩
rcases H (f a) with ⟨b, hb, hb'⟩
refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩
rwa [RelIso.apply_symm_apply]
theorem cof_eq_lift [IsRefl β s] (f : r ≃r s) :
Cardinal.lift.{v} (Order.cof r) = Cardinal.lift.{u} (Order.cof s) :=
have := f.toRelEmbedding.isRefl
(f.cof_le_lift).antisymm (f.symm.cof_le_lift)
theorem cof_eq {α β : Type u} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) :
Order.cof r = Order.cof s :=
lift_inj.1 (f.cof_eq_lift)
end RelIso
/-! ### Cofinality of ordinals -/
namespace Ordinal
/-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is
unbounded, in the sense `∀ a, ∃ b ∈ S, a ≤ b`.
In particular, `cof 0 = 0` and `cof (succ o) = 1`. -/
def cof (o : Ordinal.{u}) : Cardinal.{u} :=
o.liftOn (fun a ↦ Order.cof (swap a.rᶜ)) fun _ _ ⟨f⟩ ↦ f.compl.swap.cof_eq
theorem cof_type (r : α → α → Prop) [IsWellOrder α r] : (type r).cof = Order.cof (swap rᶜ) :=
rfl
theorem cof_type_lt [LinearOrder α] [IsWellOrder α (· < ·)] :
(@type α (· < ·) _).cof = @Order.cof α (· ≤ ·) := by
rw [cof_type, compl_lt, swap_ge]
theorem cof_eq_cof_toType (o : Ordinal) : o.cof = @Order.cof o.toType (· ≤ ·) := by
conv_lhs => rw [← type_toType o, cof_type_lt]
theorem le_cof_type [IsWellOrder α r] {c} : c ≤ cof (type r) ↔ ∀ S, Unbounded r S → c ≤ #S :=
(le_csInf_iff'' (Order.cof_nonempty _)).trans
⟨fun H S h => H _ ⟨S, h, rfl⟩, by
rintro H d ⟨S, h, rfl⟩
exact H _ h⟩
theorem cof_type_le [IsWellOrder α r] {S : Set α} (h : Unbounded r S) : cof (type r) ≤ #S :=
le_cof_type.1 le_rfl S h
theorem lt_cof_type [IsWellOrder α r] {S : Set α} : #S < cof (type r) → Bounded r S := by
simpa using not_imp_not.2 cof_type_le
theorem cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ #S = cof (type r) :=
csInf_mem (Order.cof_nonempty (swap rᶜ))
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
∃ S, Unbounded r S ∧ type (Subrel r (· ∈ S)) = (cof (type r)).ord := by
let ⟨S, hS, e⟩ := cof_eq r
let ⟨s, _, e'⟩ := Cardinal.ord_eq S
let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
suffices Unbounded r T by
refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩
rw [← e, e']
refine
(RelEmbedding.ofMonotone
(fun a : T =>
(⟨a,
let ⟨aS, _⟩ := a.2
aS⟩ :
S))
fun a b h => ?_).ordinal_type_le
rcases a with ⟨a, aS, ha⟩
rcases b with ⟨b, bS, hb⟩
change s ⟨a, _⟩ ⟨b, _⟩
refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_
· exact asymm h (ha _ hn)
· intro e
injection e with e
subst b
exact irrefl _ h
intro a
have : { b : S | ¬r b a }.Nonempty :=
let ⟨b, bS, ba⟩ := hS a
⟨⟨b, bS⟩, ba⟩
let b := (IsWellFounded.wf : WellFounded s).min _ this
have ba : ¬r b a := IsWellFounded.wf.min_mem _ this
refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩
rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl]
exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba)
/-! ### Cofinality of suprema and least strict upper bounds -/
private theorem card_mem_cof {o} : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = o.card :=
⟨_, _, lsub_typein o, mk_toType o⟩
/-- The set in the `lsub` characterization of `cof` is nonempty. -/
theorem cof_lsub_def_nonempty (o) :
{ a : Cardinal | ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a }.Nonempty :=
⟨_, card_mem_cof⟩
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_)
· rintro a ⟨ι, f, hf, rfl⟩
rw [← type_toType o]
refine
(cof_type_le fun a => ?_).trans
(@mk_le_of_injective _ _
(fun s : typein ((· < ·) : o.toType → o.toType → Prop) ⁻¹' Set.range f =>
Classical.choose s.prop)
fun s t hst => by
let H := congr_arg f hst
rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
Subtype.coe_inj] at H)
have := typein_lt_self a
simp_rw [← hf, lt_lsub_iff] at this
obtain ⟨i, hi⟩ := this
refine ⟨enum (α := o.toType) (· < ·) ⟨f i, ?_⟩, ?_, ?_⟩
· rw [type_toType, ← hf]
apply lt_lsub
· rw [mem_preimage, typein_enum]
exact mem_range_self i
· rwa [← typein_le_typein, typein_enum]
· rcases cof_eq (α := o.toType) (· < ·) with ⟨S, hS, hS'⟩
let f : S → Ordinal := fun s => typein LT.lt s.val
refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i)
(le_of_forall_lt fun a ha => ?_), by rwa [type_toType o] at hS'⟩
rw [← type_toType o] at ha
rcases hS (enum (· < ·) ⟨a, ha⟩) with ⟨b, hb, hb'⟩
rw [← typein_le_typein, typein_enum] at hb'
exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩)
@[simp]
theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by
refine inductionOn o fun α r _ ↦ ?_
rw [← type_uLift, cof_type, cof_type, ← Cardinal.lift_id'.{v, u} (Order.cof _),
← Cardinal.lift_umax]
apply RelIso.cof_eq_lift ⟨Equiv.ulift.symm, _⟩
simp [swap]
theorem cof_le_card (o) : cof o ≤ card o := by
rw [cof_eq_sInf_lsub]
exact csInf_le' card_mem_cof
theorem cof_ord_le (c : Cardinal) : c.ord.cof ≤ c := by simpa using cof_le_card c.ord
theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord ≤ o :=
(ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o)
theorem exists_lsub_cof (o : Ordinal) :
∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = cof o := by
rw [cof_eq_sInf_lsub]
exact csInf_mem (cof_lsub_def_nonempty o)
theorem cof_lsub_le {ι} (f : ι → Ordinal) : cof (lsub.{u, u} f) ≤ #ι := by
rw [cof_eq_sInf_lsub]
exact csInf_le' ⟨ι, f, rfl, rfl⟩
theorem cof_lsub_le_lift {ι} (f : ι → Ordinal) :
cof (lsub.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by
rw [← mk_uLift.{u, v}]
convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ι => f i.down
exact
lsub_eq_of_range_eq.{u, max u v, max u v}
(Set.ext fun x => ⟨fun ⟨i, hi⟩ => ⟨ULift.up.{v, u} i, hi⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩)
theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} :
a ≤ cof o ↔ ∀ {ι} (f : ι → Ordinal), lsub.{u, u} f = o → a ≤ #ι := by
rw [cof_eq_sInf_lsub]
exact
(le_csInf_iff'' (cof_lsub_def_nonempty o)).trans
⟨fun H ι f hf => H _ ⟨ι, f, hf, rfl⟩, fun H b ⟨ι, f, hf, hb⟩ => by
rw [← hb]
exact H _ hf⟩
theorem lsub_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal}
(hι : Cardinal.lift.{v, u} #ι < c.cof)
(hf : ∀ i, f i < c) : lsub.{u, v} f < c :=
lt_of_le_of_ne (lsub_le hf) fun h => by
subst h
exact (cof_lsub_le_lift.{u, v} f).not_lt hι
theorem lsub_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) :
(∀ i, f i < c) → lsub.{u, u} f < c :=
lsub_lt_ord_lift (by rwa [(#ι).lift_id])
theorem cof_iSup_le_lift {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) :
cof (iSup f) ≤ Cardinal.lift.{v, u} #ι := by
rw [← Ordinal.sup] at *
rw [← sup_eq_lsub_iff_lt_sup.{u, v}] at H
rw [H]
exact cof_lsub_le_lift f
theorem cof_iSup_le {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) :
cof (iSup f) ≤ #ι := by
rw [← (#ι).lift_id]
exact cof_iSup_le_lift H
theorem iSup_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof)
(hf : ∀ i, f i < c) : iSup f < c :=
(sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hι hf)
theorem iSup_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) :
(∀ i, f i < c) → iSup f < c :=
iSup_lt_ord_lift (by rwa [(#ι).lift_id])
theorem iSup_lt_lift {ι} {f : ι → Cardinal} {c : Cardinal}
(hι : Cardinal.lift.{v, u} #ι < c.ord.cof)
(hf : ∀ i, f i < c) : iSup f < c := by
rw [← ord_lt_ord, iSup_ord (Cardinal.bddAbove_range _)]
refine iSup_lt_ord_lift hι fun i => ?_
rw [ord_lt_ord]
apply hf
theorem iSup_lt {ι} {f : ι → Cardinal} {c : Cardinal} (hι : #ι < c.ord.cof) :
(∀ i, f i < c) → iSup f < c :=
iSup_lt_lift (by rwa [(#ι).lift_id])
theorem nfpFamily_lt_ord_lift {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c)
(hc' : Cardinal.lift.{v, u} #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} (ha : a < c) :
nfpFamily f a < c := by
refine iSup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ι)).trans_lt ?_) fun l => ?_
· rw [lift_max]
apply max_lt _ hc'
rwa [Cardinal.lift_aleph0]
· induction' l with i l H
· exact ha
· exact hf _ _ H
theorem nfpFamily_lt_ord {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : #ι < cof c)
(hf : ∀ (i), ∀ b < c, f i b < c) {a} : a < c → nfpFamily.{u, u} f a < c :=
nfpFamily_lt_ord_lift hc (by rwa [(#ι).lift_id]) hf
theorem nfp_lt_ord {f : Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hf : ∀ i < c, f i < c) {a} :
a < c → nfp f a < c :=
nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf
theorem exists_blsub_cof (o : Ordinal) :
∃ f : ∀ a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by
rcases exists_lsub_cof o with ⟨ι, f, hf, hι⟩
rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩
rw [← @blsub_eq_lsub' ι r hr] at hf
rw [← hι, hι']
exact ⟨_, hf⟩
theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} :
a ≤ cof b ↔ ∀ {o} (f : ∀ a < o, Ordinal), blsub.{u, u} o f = b → a ≤ o.card :=
le_cof_iff_lsub.trans
⟨fun H o f hf => by simpa using H _ hf, fun H ι f hf => by
rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩
rw [← @blsub_eq_lsub' ι r hr] at hf
simpa using H _ hf⟩
theorem cof_blsub_le_lift {o} (f : ∀ a < o, Ordinal) :
cof (blsub.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by
rw [← mk_toType o]
exact cof_lsub_le_lift _
theorem cof_blsub_le {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, u} o f) ≤ o.card := by
rw [← o.card.lift_id]
exact cof_blsub_le_lift f
theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : ∀ a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, v} o f < c :=
lt_of_le_of_ne (blsub_le hf) fun h =>
ho.not_le (by simpa [← iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f)
theorem blsub_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof)
(hf : ∀ i hi, f i hi < c) : blsub.{u, u} o f < c :=
blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf
theorem cof_bsup_le_lift {o : Ordinal} {f : ∀ a < o, Ordinal} (H : ∀ i h, f i h < bsup.{u, v} o f) :
cof (bsup.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by
rw [← bsup_eq_blsub_iff_lt_bsup.{u, v}] at H
rw [H]
exact cof_blsub_le_lift.{u, v} f
theorem cof_bsup_le {o : Ordinal} {f : ∀ a < o, Ordinal} :
(∀ i h, f i h < bsup.{u, u} o f) → cof (bsup.{u, u} o f) ≤ o.card := by
rw [← o.card.lift_id]
exact cof_bsup_le_lift
theorem bsup_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : bsup.{u, v} o f < c :=
(bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf)
theorem bsup_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) :
(∀ i hi, f i hi < c) → bsup.{u, u} o f < c :=
bsup_lt_ord_lift (by rwa [o.card.lift_id])
/-! ### Basic results -/
@[simp]
theorem cof_zero : cof 0 = 0 := by
refine LE.le.antisymm ?_ (Cardinal.zero_le _)
rw [← card_zero]
exact cof_le_card 0
@[simp]
theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 :=
⟨inductionOn o fun _ r _ z =>
let ⟨_, hl, e⟩ := cof_eq r
type_eq_zero_iff_isEmpty.2 <|
⟨fun a =>
let ⟨_, h, _⟩ := hl a
(mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩,
fun e => by simp [e]⟩
theorem cof_ne_zero {o} : cof o ≠ 0 ↔ o ≠ 0 :=
cof_eq_zero.not
@[simp]
theorem cof_succ (o) : cof (succ o) = 1 := by
apply le_antisymm
· refine inductionOn o fun α r _ => ?_
change cof (type _) ≤ _
rw [← (_ : #_ = 1)]
· apply cof_type_le
refine fun a => ⟨Sum.inr PUnit.unit, Set.mem_singleton _, ?_⟩
rcases a with (a | ⟨⟨⟨⟩⟩⟩) <;> simp [EmptyRelation]
· rw [Cardinal.mk_fintype, Set.card_singleton]
simp
· rw [← Cardinal.succ_zero, succ_le_iff]
simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h =>
succ_ne_zero o (cof_eq_zero.1 (Eq.symm h))
@[simp]
theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a :=
⟨inductionOn o fun α r _ z => by
rcases cof_eq r with ⟨S, hl, e⟩; rw [z] at e
obtain ⟨a⟩ := mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero)
refine
⟨typein r a,
Eq.symm <|
Quotient.sound
⟨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_⟩⟩
· apply Sum.rec <;> [exact Subtype.val; exact fun _ => a]
· rcases x with (x | ⟨⟨⟨⟩⟩⟩) <;> rcases y with (y | ⟨⟨⟨⟩⟩⟩) <;>
simp [Subrel, Order.Preimage, EmptyRelation]
exact x.2
· suffices r x a ∨ ∃ _ : PUnit.{u}, ↑a = x by
convert this
dsimp [RelEmbedding.ofMonotone]; simp
rcases trichotomous_of r x a with (h | h | h)
· exact Or.inl h
· exact Or.inr ⟨PUnit.unit, h.symm⟩
· rcases hl x with ⟨a', aS, hn⟩
refine absurd h ?_
convert hn
change (a : α) = ↑(⟨a', aS⟩ : S)
have := le_one_iff_subsingleton.1 (le_of_eq e)
congr!,
fun ⟨a, e⟩ => by simp [e]⟩
/-! ### Fundamental sequences -/
-- TODO: move stuff about fundamental sequences to their own file.
/-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at
`a`. We provide `o` explicitly in order to avoid type rewrites. -/
def IsFundamentalSequence (a o : Ordinal.{u}) (f : ∀ b < o, Ordinal.{u}) : Prop :=
o ≤ a.cof.ord ∧ (∀ {i j} (hi hj), i < j → f i hi < f j hj) ∧ blsub.{u, u} o f = a
namespace IsFundamentalSequence
variable {a o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}}
protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o :=
hf.1.antisymm' <| by
rw [← hf.2.2]
exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o)
protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} :
∀ hi hj, i < j → f i hi < f j hj :=
hf.2.1
theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a :=
hf.2.2
theorem ord_cof (hf : IsFundamentalSequence a o f) :
IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by
have H := hf.cof_eq
subst H
exact hf
theorem id_of_le_cof (h : o ≤ o.cof.ord) : IsFundamentalSequence o o fun a _ => a :=
⟨h, @fun _ _ _ _ => id, blsub_id o⟩
protected theorem zero {f : ∀ b < (0 : Ordinal), Ordinal} : IsFundamentalSequence 0 0 f :=
⟨by rw [cof_zero, ord_zero], @fun i _ hi => (Ordinal.not_lt_zero i hi).elim, blsub_zero f⟩
protected theorem succ : IsFundamentalSequence (succ o) 1 fun _ _ => o := by
refine ⟨?_, @fun i j hi hj h => ?_, blsub_const Ordinal.one_ne_zero o⟩
· rw [cof_succ, ord_one]
· rw [lt_one_iff_zero] at hi hj
rw [hi, hj] at h
exact h.false.elim
protected theorem monotone (hf : IsFundamentalSequence a o f) {i j : Ordinal} (hi : i < o)
(hj : j < o) (hij : i ≤ j) : f i hi ≤ f j hj := by
rcases lt_or_eq_of_le hij with (hij | rfl)
· exact (hf.2.1 hi hj hij).le
· rfl
theorem trans {a o o' : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} (hf : IsFundamentalSequence a o f)
{g : ∀ b < o', Ordinal.{u}} (hg : IsFundamentalSequence o o' g) :
IsFundamentalSequence a o' fun i hi =>
f (g i hi) (by rw [← hg.2.2]; apply lt_blsub) := by
refine ⟨?_, @fun i j _ _ h => hf.2.1 _ _ (hg.2.1 _ _ h), ?_⟩
· rw [hf.cof_eq]
exact hg.1.trans (ord_cof_le o)
· rw [@blsub_comp.{u, u, u} o _ f (@IsFundamentalSequence.monotone _ _ f hf)]
· exact hf.2.2
· exact hg.2.2
protected theorem lt {a o : Ordinal} {s : Π p < o, Ordinal}
(h : IsFundamentalSequence a o s) {p : Ordinal} (hp : p < o) : s p hp < a :=
h.blsub_eq ▸ lt_blsub s p hp
end IsFundamentalSequence
/-- Every ordinal has a fundamental sequence. -/
theorem exists_fundamental_sequence (a : Ordinal.{u}) :
∃ f, IsFundamentalSequence a a.cof.ord f := by
suffices h : ∃ o f, IsFundamentalSequence a o f by
rcases h with ⟨o, f, hf⟩
exact ⟨_, hf.ord_cof⟩
rcases exists_lsub_cof a with ⟨ι, f, hf, hι⟩
rcases ord_eq ι with ⟨r, wo, hr⟩
haveI := wo
let r' := Subrel r fun i ↦ ∀ j, r j i → f j < f i
let hrr' : r' ↪r r := Subrel.relEmbedding _ _
haveI := hrr'.isWellOrder
refine
⟨_, _, hrr'.ordinal_type_le.trans ?_, @fun i j _ h _ => (enum r' ⟨j, h⟩).prop _ ?_,
le_antisymm (blsub_le fun i hi => lsub_le_iff.1 hf.le _) ?_⟩
· rw [← hι, hr]
· change r (hrr'.1 _) (hrr'.1 _)
rwa [hrr'.2, @enum_lt_enum _ r']
· rw [← hf, lsub_le_iff]
intro i
suffices h : ∃ i' hi', f i ≤ bfamilyOfFamily' r' (fun i => f i) i' hi' by
rcases h with ⟨i', hi', hfg⟩
exact hfg.trans_lt (lt_blsub _ _ _)
by_cases h : ∀ j, r j i → f j < f i
· refine ⟨typein r' ⟨i, h⟩, typein_lt_type _ _, ?_⟩
rw [bfamilyOfFamily'_typein]
· push_neg at h
obtain ⟨hji, hij⟩ := wo.wf.min_mem _ h
refine ⟨typein r' ⟨_, fun k hkj => lt_of_lt_of_le ?_ hij⟩, typein_lt_type _ _, ?_⟩
· by_contra! H
exact (wo.wf.not_lt_min _ h ⟨IsTrans.trans _ _ _ hkj hji, H⟩) hkj
· rwa [bfamilyOfFamily'_typein]
@[simp]
theorem cof_cof (a : Ordinal.{u}) : cof (cof a).ord = cof a := by
obtain ⟨f, hf⟩ := exists_fundamental_sequence a
obtain ⟨g, hg⟩ := exists_fundamental_sequence a.cof.ord
exact ord_injective (hf.trans hg).cof_eq.symm
protected theorem IsNormal.isFundamentalSequence {f : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f)
{a o} (ha : IsLimit a) {g} (hg : IsFundamentalSequence a o g) :
IsFundamentalSequence (f a) o fun b hb => f (g b hb) := by
refine ⟨?_, @fun i j _ _ h => hf.strictMono (hg.2.1 _ _ h), ?_⟩
· rcases exists_lsub_cof (f a) with ⟨ι, f', hf', hι⟩
rw [← hg.cof_eq, ord_le_ord, ← hι]
suffices (lsub.{u, u} fun i => sInf { b : Ordinal | f' i ≤ f b }) = a by
rw [← this]
apply cof_lsub_le
have H : ∀ i, ∃ b < a, f' i ≤ f b := fun i => by
have := lt_lsub.{u, u} f' i
rw [hf', ← IsNormal.blsub_eq.{u, u} hf ha, lt_blsub_iff] at this
simpa using this
refine (lsub_le fun i => ?_).antisymm (le_of_forall_lt fun b hb => ?_)
· rcases H i with ⟨b, hb, hb'⟩
exact lt_of_le_of_lt (csInf_le' hb') hb
· have := hf.strictMono hb
rw [← hf', lt_lsub_iff] at this
obtain ⟨i, hi⟩ := this
rcases H i with ⟨b, _, hb⟩
exact
((le_csInf_iff'' ⟨b, by exact hb⟩).2 fun c hc =>
hf.strictMono.le_iff_le.1 (hi.trans hc)).trans_lt (lt_lsub _ i)
· rw [@blsub_comp.{u, u, u} a _ (fun b _ => f b) (@fun i j _ _ h => hf.strictMono.monotone h) g
hg.2.2]
exact IsNormal.blsub_eq.{u, u} hf ha
theorem IsNormal.cof_eq {f} (hf : IsNormal f) {a} (ha : IsLimit a) : cof (f a) = cof a :=
let ⟨_, hg⟩ := exists_fundamental_sequence a
ord_injective (hf.isFundamentalSequence ha hg).cof_eq
theorem IsNormal.cof_le {f} (hf : IsNormal f) (a) : cof a ≤ cof (f a) := by
rcases zero_or_succ_or_limit a with (rfl | ⟨b, rfl⟩ | ha)
· rw [cof_zero]
exact zero_le _
· rw [cof_succ, Cardinal.one_le_iff_ne_zero, cof_ne_zero, ← Ordinal.pos_iff_ne_zero]
exact (Ordinal.zero_le (f b)).trans_lt (hf.1 b)
· rw [hf.cof_eq ha]
@[simp]
theorem cof_add (a b : Ordinal) : b ≠ 0 → cof (a + b) = cof b := fun h => by
rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb)
· contradiction
· rw [add_succ, cof_succ, cof_succ]
· exact (isNormal_add_right a).cof_eq hb
theorem aleph0_le_cof {o} : ℵ₀ ≤ cof o ↔ IsLimit o := by
rcases zero_or_succ_or_limit o with (rfl | ⟨o, rfl⟩ | l)
· simp [not_zero_isLimit, Cardinal.aleph0_ne_zero]
· simp [not_succ_isLimit, Cardinal.one_lt_aleph0]
· simp only [l, iff_true]
refine le_of_not_lt fun h => ?_
obtain ⟨n, e⟩ := Cardinal.lt_aleph0.1 h
have := cof_cof o
rw [e, ord_nat] at this
cases n
· simp at e
simp [e, not_zero_isLimit] at l
· rw [natCast_succ, cof_succ] at this
rw [← this, cof_eq_one_iff_is_succ] at e
rcases e with ⟨a, rfl⟩
exact not_succ_isLimit _ l
@[simp]
theorem cof_preOmega {o : Ordinal} (ho : IsSuccPrelimit o) : (preOmega o).cof = o.cof := by
by_cases h : IsMin o
· simp [h.eq_bot]
· exact isNormal_preOmega.cof_eq ⟨h, ho⟩
@[simp]
theorem cof_omega {o : Ordinal} (ho : o.IsLimit) : (ω_ o).cof = o.cof :=
isNormal_omega.cof_eq ho
@[simp]
theorem cof_omega0 : cof ω = ℵ₀ :=
(aleph0_le_cof.2 isLimit_omega0).antisymm' <| by
rw [← card_omega0]
apply cof_le_card
theorem cof_eq' (r : α → α → Prop) [IsWellOrder α r] (h : IsLimit (type r)) :
∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = cof (type r) :=
let ⟨S, H, e⟩ := cof_eq r
⟨S, fun a =>
let a' := enum r ⟨_, h.succ_lt (typein_lt_type r a)⟩
let ⟨b, h, ab⟩ := H a'
⟨b, h,
(IsOrderConnected.conn a b a' <|
(typein_lt_typein r).1
(by
rw [typein_enum]
exact lt_succ (typein _ _))).resolve_right
ab⟩,
e⟩
@[simp]
theorem cof_univ : cof univ.{u, v} = Cardinal.univ.{u, v} :=
le_antisymm (cof_le_card _)
(by
refine le_of_forall_lt fun c h => ?_
rcases lt_univ'.1 h with ⟨c, rfl⟩
rcases @cof_eq Ordinal.{u} (· < ·) _ with ⟨S, H, Se⟩
rw [univ, ← lift_cof, ← Cardinal.lift_lift.{u+1, v, u}, Cardinal.lift_lt, ← Se]
refine lt_of_not_ge fun h => ?_
obtain ⟨a, e⟩ := Cardinal.mem_range_lift_of_le h
refine Quotient.inductionOn a (fun α e => ?_) e
obtain ⟨f⟩ := Quotient.exact e
have f := Equiv.ulift.symm.trans f
let g a := (f a).1
let o := succ (iSup g)
rcases H o with ⟨b, h, l⟩
refine l (lt_succ_iff.2 ?_)
rw [← show g (f.symm ⟨b, h⟩) = b by simp [g]]
apply Ordinal.le_iSup)
end Ordinal
namespace Cardinal
open Ordinal
/-! ### Results on sets -/
theorem mk_bounded_subset {α : Type*} (h : ∀ x < #α, 2 ^ x < #α) {r : α → α → Prop}
[IsWellOrder α r] (hr : (#α).ord = type r) : #{ s : Set α // Bounded r s } = #α := by
rcases eq_or_ne #α 0 with (ha | ha)
· rw [ha]
haveI := mk_eq_zero_iff.1 ha
rw [mk_eq_zero_iff]
constructor
rintro ⟨s, hs⟩
exact (not_unbounded_iff s).2 hs (unbounded_of_isEmpty s)
have h' : IsStrongLimit #α := ⟨ha, @h⟩
have ha := h'.aleph0_le
apply le_antisymm
· have : { s : Set α | Bounded r s } = ⋃ i, 𝒫{ j | r j i } := setOf_exists _
rw [← coe_setOf, this]
refine mk_iUnion_le_sum_mk.trans ((sum_le_iSup (fun i => #(𝒫{ j | r j i }))).trans
((mul_le_max_of_aleph0_le_left ha).trans ?_))
rw [max_eq_left]
apply ciSup_le' _
intro i
rw [mk_powerset]
apply (h'.two_power_lt _).le
rw [coe_setOf, card_typein, ← lt_ord, hr]
apply typein_lt_type
· refine @mk_le_of_injective α _ (fun x => Subtype.mk {x} ?_) ?_
· apply bounded_singleton
rw [← hr]
apply isLimit_ord ha
· intro a b hab
simpa [singleton_eq_singleton_iff] using hab
theorem mk_subset_mk_lt_cof {α : Type*} (h : ∀ x < #α, 2 ^ x < #α) :
#{ s : Set α // #s < cof (#α).ord } = #α := by
rcases eq_or_ne #α 0 with (ha | ha)
· simp [ha]
have h' : IsStrongLimit #α := ⟨ha, @h⟩
rcases ord_eq α with ⟨r, wo, hr⟩
haveI := wo
apply le_antisymm
· conv_rhs => rw [← mk_bounded_subset h hr]
apply mk_le_mk_of_subset
intro s hs
rw [hr] at hs
exact lt_cof_type hs
· refine @mk_le_of_injective α _ (fun x => Subtype.mk {x} ?_) ?_
· rw [mk_singleton]
exact one_lt_aleph0.trans_le (aleph0_le_cof.2 (isLimit_ord h'.aleph0_le))
· intro a b hab
simpa [singleton_eq_singleton_iff] using hab
/-- If the union of s is unbounded and s is smaller than the cofinality,
then s has an unbounded member -/
theorem unbounded_of_unbounded_sUnion (r : α → α → Prop) [wo : IsWellOrder α r] {s : Set (Set α)}
(h₁ : Unbounded r <| ⋃₀ s) (h₂ : #s < Order.cof (swap rᶜ)) : ∃ x ∈ s, Unbounded r x := by
by_contra! h
simp_rw [not_unbounded_iff] at h
let f : s → α := fun x : s => wo.wf.sup x (h x.1 x.2)
refine h₂.not_le (le_trans (csInf_le' ⟨range f, fun x => ?_, rfl⟩) mk_range_le)
rcases h₁ x with ⟨y, ⟨c, hc, hy⟩, hxy⟩
exact ⟨f ⟨c, hc⟩, mem_range_self _, fun hxz => hxy (Trans.trans (wo.wf.lt_sup _ hy) hxz)⟩
/-- If the union of s is unbounded and s is smaller than the cofinality,
then s has an unbounded member -/
theorem unbounded_of_unbounded_iUnion {α β : Type u} (r : α → α → Prop) [wo : IsWellOrder α r]
(s : β → Set α) (h₁ : Unbounded r <| ⋃ x, s x) (h₂ : #β < Order.cof (swap rᶜ)) :
∃ x : β, Unbounded r (s x) := by
rw [← sUnion_range] at h₁
rcases unbounded_of_unbounded_sUnion r h₁ (mk_range_le.trans_lt h₂) with ⟨_, ⟨x, rfl⟩, u⟩
exact ⟨x, u⟩
/-! ### Consequences of König's lemma -/
theorem lt_power_cof {c : Cardinal.{u}} : ℵ₀ ≤ c → c < c ^ c.ord.cof :=
Cardinal.inductionOn c fun α h => by
rcases ord_eq α with ⟨r, wo, re⟩
have := isLimit_ord h
rw [re] at this ⊢
rcases cof_eq' r this with ⟨S, H, Se⟩
have := sum_lt_prod (fun a : S => #{ x // r x a }) (fun _ => #α) fun i => ?_
· simp only [Cardinal.prod_const, Cardinal.lift_id, ← Se, ← mk_sigma, power_def] at this ⊢
refine lt_of_le_of_lt ?_ this
refine ⟨Embedding.ofSurjective ?_ ?_⟩
· exact fun x => x.2.1
· exact fun a =>
let ⟨b, h, ab⟩ := H a
⟨⟨⟨_, h⟩, _, ab⟩, rfl⟩
· have := typein_lt_type r i
rwa [← re, lt_ord] at this
theorem lt_cof_power {a b : Cardinal} (ha : ℵ₀ ≤ a) (b1 : 1 < b) : a < (b ^ a).ord.cof := by
have b0 : b ≠ 0 := (zero_lt_one.trans b1).ne'
apply lt_imp_lt_of_le_imp_le (power_le_power_left <| power_ne_zero a b0)
rw [← power_mul, mul_eq_self ha]
exact lt_power_cof (ha.trans <| (cantor' _ b1).le)
end Cardinal
| Mathlib/SetTheory/Cardinal/Cofinality.lean | 1,057 | 1,059 | |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Multiset.ZeroCons
/-!
# Basic results on multisets
-/
-- No algebra should be required
assert_not_exists Monoid
universe v
open List Subtype Nat Function
variable {α : Type*} {β : Type v} {γ : Type*}
namespace Multiset
/-! ### `Multiset.toList` -/
section ToList
/-- Produces a list of the elements in the multiset using choice. -/
noncomputable def toList (s : Multiset α) :=
s.out
@[simp, norm_cast]
theorem coe_toList (s : Multiset α) : (s.toList : Multiset α) = s :=
s.out_eq'
@[simp]
theorem toList_eq_nil {s : Multiset α} : s.toList = [] ↔ s = 0 := by
rw [← coe_eq_zero, coe_toList]
theorem empty_toList {s : Multiset α} : s.toList.isEmpty ↔ s = 0 := by simp
@[simp]
theorem toList_zero : (Multiset.toList 0 : List α) = [] :=
toList_eq_nil.mpr rfl
@[simp]
theorem mem_toList {a : α} {s : Multiset α} : a ∈ s.toList ↔ a ∈ s := by
rw [← mem_coe, coe_toList]
@[simp]
theorem toList_eq_singleton_iff {a : α} {m : Multiset α} : m.toList = [a] ↔ m = {a} := by
rw [← perm_singleton, ← coe_eq_coe, coe_toList, coe_singleton]
@[simp]
theorem toList_singleton (a : α) : ({a} : Multiset α).toList = [a] :=
Multiset.toList_eq_singleton_iff.2 rfl
@[simp]
theorem length_toList (s : Multiset α) : s.toList.length = card s := by
rw [← coe_card, coe_toList]
end ToList
/-! ### Induction principles -/
/-- The strong induction principle for multisets. -/
@[elab_as_elim]
def strongInductionOn {p : Multiset α → Sort*} (s : Multiset α) (ih : ∀ s, (∀ t < s, p t) → p s) :
p s :=
(ih s) fun t _h =>
strongInductionOn t ih
termination_by card s
decreasing_by exact card_lt_card _h
theorem strongInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) (H) :
@strongInductionOn _ p s H = H s fun t _h => @strongInductionOn _ p t H := by
rw [strongInductionOn]
@[elab_as_elim]
theorem case_strongInductionOn {p : Multiset α → Prop} (s : Multiset α) (h₀ : p 0)
(h₁ : ∀ a s, (∀ t ≤ s, p t) → p (a ::ₘ s)) : p s :=
Multiset.strongInductionOn s fun s =>
Multiset.induction_on s (fun _ => h₀) fun _a _s _ ih =>
(h₁ _ _) fun _t h => ih _ <| lt_of_le_of_lt h <| lt_cons_self _ _
/-- Suppose that, given that `p t` can be defined on all supersets of `s` of cardinality less than
`n`, one knows how to define `p s`. Then one can inductively define `p s` for all multisets `s` of
cardinality less than `n`, starting from multisets of card `n` and iterating. This
can be used either to define data, or to prove properties. -/
def strongDownwardInduction {p : Multiset α → Sort*} {n : ℕ}
(H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁)
(s : Multiset α) :
card s ≤ n → p s :=
H s fun {t} ht _h =>
strongDownwardInduction H t ht
termination_by n - card s
decreasing_by simp_wf; have := (card_lt_card _h); omega
theorem strongDownwardInduction_eq {p : Multiset α → Sort*} {n : ℕ}
(H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁)
(s : Multiset α) :
strongDownwardInduction H s = H s fun ht _hst => strongDownwardInduction H _ ht := by
rw [strongDownwardInduction]
/-- Analogue of `strongDownwardInduction` with order of arguments swapped. -/
@[elab_as_elim]
def strongDownwardInductionOn {p : Multiset α → Sort*} {n : ℕ} :
∀ s : Multiset α,
(∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) →
card s ≤ n → p s :=
fun s H => strongDownwardInduction H s
theorem strongDownwardInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) {n : ℕ}
(H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) :
s.strongDownwardInductionOn H = H s fun {t} ht _h => t.strongDownwardInductionOn H ht := by
dsimp only [strongDownwardInductionOn]
rw [strongDownwardInduction]
section Choose
variable (p : α → Prop) [DecidablePred p] (l : Multiset α)
/-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `chooseX p l hp` returns
that `a` together with proofs of `a ∈ l` and `p a`. -/
def chooseX : ∀ _hp : ∃! a, a ∈ l ∧ p a, { a // a ∈ l ∧ p a } :=
Quotient.recOn l (fun l' ex_unique => List.chooseX p l' (ExistsUnique.exists ex_unique))
(by
intros a b _
funext hp
suffices all_equal : ∀ x y : { t // t ∈ b ∧ p t }, x = y by
apply all_equal
rintro ⟨x, px⟩ ⟨y, py⟩
rcases hp with ⟨z, ⟨_z_mem_l, _pz⟩, z_unique⟩
congr
calc
x = z := z_unique x px
_ = y := (z_unique y py).symm
)
/-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `choose p l hp` returns
that `a`. -/
def choose (hp : ∃! a, a ∈ l ∧ p a) : α :=
chooseX p l hp
theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(chooseX p l hp).property
theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
end Choose
variable (α) in
/-- The equivalence between lists and multisets of a subsingleton type. -/
def subsingletonEquiv [Subsingleton α] : List α ≃ Multiset α where
toFun := ofList
invFun :=
(Quot.lift id) fun (a b : List α) (h : a ~ b) =>
(List.ext_get h.length_eq) fun _ _ _ => Subsingleton.elim _ _
left_inv _ := rfl
right_inv m := Quot.inductionOn m fun _ => rfl
@[simp]
theorem coe_subsingletonEquiv [Subsingleton α] :
(subsingletonEquiv α : List α → Multiset α) = ofList :=
rfl
section SizeOf
set_option linter.deprecated false in
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Multiset α} (hx : x ∈ s) :
SizeOf.sizeOf x < SizeOf.sizeOf s := by
induction s using Quot.inductionOn
exact List.sizeOf_lt_sizeOf_of_mem hx
end SizeOf
end Multiset
| Mathlib/Data/Multiset/Basic.lean | 2,444 | 2,446 | |
/-
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, Sophie Morel, Yury Kudryashov
-/
import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace
import Mathlib.Logic.Embedding.Basic
import Mathlib.Data.Fintype.CardEmbedding
import Mathlib.Topology.Algebra.Module.Multilinear.Topology
/-!
# Operator norm on the space of continuous multilinear maps
When `f` is a continuous multilinear map in finitely many variables, we define its norm `‖f‖` as the
smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`.
We show that it is indeed a norm, and prove its basic properties.
## Main results
Let `f` be a multilinear map in finitely many variables.
* `exists_bound_of_continuous` asserts that, if `f` is continuous, then there exists `C > 0`
with `‖f m‖ ≤ C * ∏ i, ‖m i‖` for all `m`.
* `continuous_of_bound`, conversely, asserts that this bound implies continuity.
* `mkContinuous` constructs the associated continuous multilinear map.
Let `f` be a continuous multilinear map in finitely many variables.
* `‖f‖` is its norm, i.e., the smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for
all `m`.
* `le_opNorm f m` asserts the fundamental inequality `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖`.
* `norm_image_sub_le f m₁ m₂` gives a control of the difference `f m₁ - f m₂` in terms of
`‖f‖` and `‖m₁ - m₂‖`.
## Implementation notes
We mostly follow the API (and the proofs) of `OperatorNorm.lean`, with the additional complexity
that we should deal with multilinear maps in several variables.
From the mathematical point of view, all the results follow from the results on operator norm in
one variable, by applying them to one variable after the other through currying. However, this
is only well defined when there is an order on the variables (for instance on `Fin n`) although
the final result is independent of the order. While everything could be done following this
approach, it turns out that direct proofs are easier and more efficient.
-/
suppress_compilation
noncomputable section
open scoped NNReal Topology Uniformity
open Finset Metric Function Filter
/-!
### Type variables
We use the following type variables in this file:
* `𝕜` : a `NontriviallyNormedField`;
* `ι`, `ι'` : finite index types with decidable equality;
* `E`, `E₁` : families of normed vector spaces over `𝕜` indexed by `i : ι`;
* `E'` : a family of normed vector spaces over `𝕜` indexed by `i' : ι'`;
* `Ei` : a family of normed vector spaces over `𝕜` indexed by `i : Fin (Nat.succ n)`;
* `G`, `G'` : normed vector spaces over `𝕜`.
-/
universe u v v' wE wE₁ wE' wG wG'
section continuous_eval
variable {𝕜 ι : Type*} {E : ι → Type*} {F : Type*}
[NormedField 𝕜] [Finite ι] [∀ i, SeminormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)]
[TopologicalSpace F] [AddCommGroup F] [IsTopologicalAddGroup F] [Module 𝕜 F]
instance ContinuousMultilinearMap.instContinuousEval :
ContinuousEval (ContinuousMultilinearMap 𝕜 E F) (Π i, E i) F where
continuous_eval := by
cases nonempty_fintype ι
let _ := IsTopologicalAddGroup.toUniformSpace F
have := isUniformAddGroup_of_addCommGroup (G := F)
refine (UniformOnFun.continuousOn_eval₂ fun m ↦ ?_).comp_continuous
(isEmbedding_toUniformOnFun.continuous.prodMap continuous_id) fun (f, x) ↦ f.cont.continuousAt
exact ⟨ball m 1, NormedSpace.isVonNBounded_of_isBounded _ isBounded_ball,
ball_mem_nhds _ one_pos⟩
namespace ContinuousLinearMap
variable {G : Type*} [AddCommGroup G] [TopologicalSpace G] [Module 𝕜 G] [ContinuousConstSMul 𝕜 F]
lemma continuous_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) :
Continuous (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) := by
fun_prop
lemma continuousOn_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) {s} :
ContinuousOn (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) s :=
f.continuous_uncurry_of_multilinear.continuousOn
lemma continuousAt_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) {x} :
ContinuousAt (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) x :=
f.continuous_uncurry_of_multilinear.continuousAt
lemma continuousWithinAt_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) {s x} :
ContinuousWithinAt (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) s x :=
f.continuous_uncurry_of_multilinear.continuousWithinAt
end ContinuousLinearMap
end continuous_eval
section Seminorm
variable {𝕜 : Type u} {ι : Type v} {ι' : Type v'} {E : ι → Type wE} {E₁ : ι → Type wE₁}
{E' : ι' → Type wE'} {G : Type wG} {G' : Type wG'}
[Fintype ι'] [NontriviallyNormedField 𝕜] [∀ i, SeminormedAddCommGroup (E i)]
[∀ i, NormedSpace 𝕜 (E i)] [∀ i, SeminormedAddCommGroup (E₁ i)] [∀ i, NormedSpace 𝕜 (E₁ i)]
[SeminormedAddCommGroup G] [NormedSpace 𝕜 G] [SeminormedAddCommGroup G'] [NormedSpace 𝕜 G']
/-!
### Continuity properties of multilinear maps
We relate continuity of multilinear maps to the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, in
both directions. Along the way, we prove useful bounds on the difference `‖f m₁ - f m₂‖`.
-/
namespace MultilinearMap
/-- If `f` is a continuous multilinear map on `E`
and `m` is an element of `∀ i, E i` such that one of the `m i` has norm `0`,
then `f m` has norm `0`.
Note that we cannot drop the continuity assumption because `f (m : Unit → E) = f (m ())`,
where the domain has zero norm and the codomain has a nonzero norm
does not satisfy this condition. -/
lemma norm_map_coord_zero (f : MultilinearMap 𝕜 E G) (hf : Continuous f)
{m : ∀ i, E i} {i : ι} (hi : ‖m i‖ = 0) : ‖f m‖ = 0 := by
classical
rw [← inseparable_zero_iff_norm] at hi ⊢
have : Inseparable (update m i 0) m := inseparable_pi.2 <|
(forall_update_iff m fun i a ↦ Inseparable a (m i)).2 ⟨hi.symm, fun _ _ ↦ rfl⟩
simpa only [map_update_zero] using this.symm.map hf
variable [Fintype ι]
/-- If a multilinear map in finitely many variables on seminormed spaces
sends vectors with a component of norm zero to vectors of norm zero
and satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖` on a shell `ε i / ‖c i‖ < ‖m i‖ < ε i`
for some positive numbers `ε i` and elements `c i : 𝕜`, `1 < ‖c i‖`,
then it satisfies this inequality for all `m`.
The first assumption is automatically satisfied on normed spaces, see `bound_of_shell` below.
For seminormed spaces, it follows from continuity of `f`, see next lemma,
see `bound_of_shell_of_continuous` below. -/
theorem bound_of_shell_of_norm_map_coord_zero (f : MultilinearMap 𝕜 E G)
(hf₀ : ∀ {m i}, ‖m i‖ = 0 → ‖f m‖ = 0)
{ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ‖c i‖)
(hf : ∀ m : ∀ i, E i, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(m : ∀ i, E i) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ := by
rcases em (∃ i, ‖m i‖ = 0) with (⟨i, hi⟩ | hm)
· rw [hf₀ hi, prod_eq_zero (mem_univ i) hi, mul_zero]
push_neg at hm
choose δ hδ0 hδm_lt hle_δm _ using fun i => rescale_to_shell_semi_normed (hc i) (hε i) (hm i)
have hδ0 : 0 < ∏ i, ‖δ i‖ := prod_pos fun i _ => norm_pos_iff.2 (hδ0 i)
simpa [map_smul_univ, norm_smul, prod_mul_distrib, mul_left_comm C, mul_le_mul_left hδ0] using
hf (fun i => δ i • m i) hle_δm hδm_lt
/-- If a continuous multilinear map in finitely many variables on normed spaces satisfies
the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖` on a shell `ε i / ‖c i‖ < ‖m i‖ < ε i` for some positive
numbers `ε i` and elements `c i : 𝕜`, `1 < ‖c i‖`, then it satisfies this inequality for all `m`. -/
theorem bound_of_shell_of_continuous (f : MultilinearMap 𝕜 E G) (hfc : Continuous f)
{ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ‖c i‖)
(hf : ∀ m : ∀ i, E i, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(m : ∀ i, E i) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
bound_of_shell_of_norm_map_coord_zero f (norm_map_coord_zero f hfc) hε hc hf m
/-- If a multilinear map in finitely many variables on normed spaces is continuous, then it
satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, for some `C` which can be chosen to be
positive. -/
theorem exists_bound_of_continuous (f : MultilinearMap 𝕜 E G) (hf : Continuous f) :
∃ C : ℝ, 0 < C ∧ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ := by
cases isEmpty_or_nonempty ι
· refine ⟨‖f 0‖ + 1, add_pos_of_nonneg_of_pos (norm_nonneg _) zero_lt_one, fun m => ?_⟩
obtain rfl : m = 0 := funext (IsEmpty.elim ‹_›)
simp [univ_eq_empty, zero_le_one]
obtain ⟨ε : ℝ, ε0 : 0 < ε, hε : ∀ m : ∀ i, E i, ‖m - 0‖ < ε → ‖f m - f 0‖ < 1⟩ :=
NormedAddCommGroup.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one
simp only [sub_zero, f.map_zero] at hε
rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩
have : 0 < (‖c‖ / ε) ^ Fintype.card ι := pow_pos (div_pos (zero_lt_one.trans hc) ε0) _
refine ⟨_, this, ?_⟩
refine f.bound_of_shell_of_continuous hf (fun _ => ε0) (fun _ => hc) fun m hcm hm => ?_
refine (hε m ((pi_norm_lt_iff ε0).2 hm)).le.trans ?_
rw [← div_le_iff₀' this, one_div, ← inv_pow, inv_div, Fintype.card, ← prod_const]
exact prod_le_prod (fun _ _ => div_nonneg ε0.le (norm_nonneg _)) fun i _ => hcm i
/-- If a multilinear map `f` satisfies a boundedness property around `0`,
one can deduce a bound on `f m₁ - f m₂` using the multilinearity.
Here, we give a precise but hard to use version.
See `norm_image_sub_le_of_bound` for a less precise but more usable version.
The bound reads
`‖f m - f m'‖ ≤
C * ‖m 1 - m' 1‖ * max ‖m 2‖ ‖m' 2‖ * max ‖m 3‖ ‖m' 3‖ * ... * max ‖m n‖ ‖m' n‖ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`. -/
theorem norm_image_sub_le_of_bound' [DecidableEq ι] (f : MultilinearMap 𝕜 E G) {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ C * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
have A :
∀ s : Finset ι,
‖f m₁ - f (s.piecewise m₂ m₁)‖ ≤
C * ∑ i ∈ s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
intro s
induction' s using Finset.induction with i s his Hrec
· simp
have I :
‖f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)‖ ≤
C * ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
have A : (insert i s).piecewise m₂ m₁ = Function.update (s.piecewise m₂ m₁) i (m₂ i) :=
s.piecewise_insert _ _ _
have B : s.piecewise m₂ m₁ = Function.update (s.piecewise m₂ m₁) i (m₁ i) := by
simp [eq_update_iff, his]
rw [B, A, ← f.map_update_sub]
apply le_trans (H _)
gcongr with j
by_cases h : j = i
· rw [h]
simp
· by_cases h' : j ∈ s <;> simp [h', h, le_refl]
calc
‖f m₁ - f ((insert i s).piecewise m₂ m₁)‖ ≤
‖f m₁ - f (s.piecewise m₂ m₁)‖ +
‖f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)‖ := by
rw [← dist_eq_norm, ← dist_eq_norm, ← dist_eq_norm]
exact dist_triangle _ _ _
_ ≤ (C * ∑ i ∈ s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) +
C * ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ :=
(add_le_add Hrec I)
_ = C * ∑ i ∈ insert i s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
simp [his, add_comm, left_distrib]
convert A univ
simp
/-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂`
using the multilinearity. Here, we give a usable but not very precise version. See
`norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is
`‖f m - f m'‖ ≤ C * card ι * ‖m - m'‖ * (max ‖m‖ ‖m'‖) ^ (card ι - 1)`. -/
theorem norm_image_sub_le_of_bound (f : MultilinearMap 𝕜 E G)
{C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ C * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := by
classical
have A :
∀ i : ι,
∏ j, (if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) ≤
‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by
intro i
calc
∏ j, (if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) ≤
∏ j : ι, Function.update (fun _ => max ‖m₁‖ ‖m₂‖) i ‖m₁ - m₂‖ j := by
apply Finset.prod_le_prod
· intro j _
by_cases h : j = i <;> simp [h, norm_nonneg]
· intro j _
by_cases h : j = i
· rw [h]
simp only [ite_true, Function.update_self]
exact norm_le_pi_norm (m₁ - m₂) i
· simp [h, - le_sup_iff, - sup_le_iff, sup_le_sup, norm_le_pi_norm]
_ = ‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by
rw [prod_update_of_mem (Finset.mem_univ _)]
simp [card_univ_diff]
calc
‖f m₁ - f m₂‖ ≤ C * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ :=
f.norm_image_sub_le_of_bound' hC H m₁ m₂
_ ≤ C * ∑ _i, ‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by gcongr; apply A
_ = C * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := by
rw [sum_const, card_univ, nsmul_eq_mul]
ring
/-- If a multilinear map satisfies an inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, then it is
continuous. -/
theorem continuous_of_bound (f : MultilinearMap 𝕜 E G) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) :
Continuous f := by
let D := max C 1
have D_pos : 0 ≤ D := le_trans zero_le_one (le_max_right _ _)
replace H (m) : ‖f m‖ ≤ D * ∏ i, ‖m i‖ :=
(H m).trans (mul_le_mul_of_nonneg_right (le_max_left _ _) <| by positivity)
refine continuous_iff_continuousAt.2 fun m => ?_
refine
continuousAt_of_locally_lipschitz zero_lt_one
(D * Fintype.card ι * (‖m‖ + 1) ^ (Fintype.card ι - 1)) fun m' h' => ?_
rw [dist_eq_norm, dist_eq_norm]
have : max ‖m'‖ ‖m‖ ≤ ‖m‖ + 1 := by
simp [zero_le_one, norm_le_of_mem_closedBall (le_of_lt h')]
calc
‖f m' - f m‖ ≤ D * Fintype.card ι * max ‖m'‖ ‖m‖ ^ (Fintype.card ι - 1) * ‖m' - m‖ :=
f.norm_image_sub_le_of_bound D_pos H m' m
_ ≤ D * Fintype.card ι * (‖m‖ + 1) ^ (Fintype.card ι - 1) * ‖m' - m‖ := by gcongr
/-- Constructing a continuous multilinear map from a multilinear map satisfying a boundedness
condition. -/
def mkContinuous (f : MultilinearMap 𝕜 E G) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) :
ContinuousMultilinearMap 𝕜 E G :=
{ f with cont := f.continuous_of_bound C H }
@[simp]
theorem coe_mkContinuous (f : MultilinearMap 𝕜 E G) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) :
⇑(f.mkContinuous C H) = f :=
rfl
/-- Given a multilinear map in `n` variables, if one restricts it to `k` variables putting `z` on
the other coordinates, then the resulting restricted function satisfies an inequality
`‖f.restr v‖ ≤ C * ‖z‖^(n-k) * Π ‖v i‖` if the original function satisfies `‖f v‖ ≤ C * Π ‖v i‖`. -/
theorem restr_norm_le {k n : ℕ} (f : MultilinearMap 𝕜 (fun _ : Fin n => G) G')
(s : Finset (Fin n)) (hk : #s = k) (z : G) {C : ℝ} (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(v : Fin k → G) : ‖f.restr s hk z v‖ ≤ C * ‖z‖ ^ (n - k) * ∏ i, ‖v i‖ := by
rw [mul_right_comm, mul_assoc]
convert H _ using 2
simp only [apply_dite norm, Fintype.prod_dite, prod_const ‖z‖, Finset.card_univ,
Fintype.card_of_subtype sᶜ fun _ => mem_compl, card_compl, Fintype.card_fin, hk, mk_coe, ←
(s.orderIsoOfFin hk).symm.bijective.prod_comp fun x => ‖v x‖]
convert rfl
end MultilinearMap
/-!
### Continuous multilinear maps
We define the norm `‖f‖` of a continuous multilinear map `f` in finitely many variables as the
smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`. We show that this
defines a normed space structure on `ContinuousMultilinearMap 𝕜 E G`.
-/
namespace ContinuousMultilinearMap
variable [Fintype ι]
theorem bound (f : ContinuousMultilinearMap 𝕜 E G) :
∃ C : ℝ, 0 < C ∧ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
f.toMultilinearMap.exists_bound_of_continuous f.2
open Real
/-- The operator norm of a continuous multilinear map is the inf of all its bounds. -/
def opNorm (f : ContinuousMultilinearMap 𝕜 E G) : ℝ :=
sInf { c | 0 ≤ (c : ℝ) ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ }
instance hasOpNorm : Norm (ContinuousMultilinearMap 𝕜 E G) :=
⟨opNorm⟩
/-- An alias of `ContinuousMultilinearMap.hasOpNorm` with non-dependent types to help typeclass
search. -/
instance hasOpNorm' : Norm (ContinuousMultilinearMap 𝕜 (fun _ : ι => G) G') :=
ContinuousMultilinearMap.hasOpNorm
theorem norm_def (f : ContinuousMultilinearMap 𝕜 E G) :
‖f‖ = sInf { c | 0 ≤ (c : ℝ) ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
rfl
-- So that invocations of `le_csInf` make sense: we show that the set of
-- bounds is nonempty and bounded below.
theorem bounds_nonempty {f : ContinuousMultilinearMap 𝕜 E G} :
∃ c, c ∈ { c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
let ⟨M, hMp, hMb⟩ := f.bound
⟨M, le_of_lt hMp, hMb⟩
theorem bounds_bddBelow {f : ContinuousMultilinearMap 𝕜 E G} :
BddBelow { c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
⟨0, fun _ ⟨hn, _⟩ => hn⟩
theorem isLeast_opNorm (f : ContinuousMultilinearMap 𝕜 E G) :
IsLeast {c : ℝ | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖} ‖f‖ := by
refine IsClosed.isLeast_csInf ?_ bounds_nonempty bounds_bddBelow
simp only [Set.setOf_and, Set.setOf_forall]
exact isClosed_Ici.inter (isClosed_iInter fun m ↦
isClosed_le continuous_const (continuous_id.mul continuous_const))
theorem opNorm_nonneg (f : ContinuousMultilinearMap 𝕜 E G) : 0 ≤ ‖f‖ :=
Real.sInf_nonneg fun _ ⟨hx, _⟩ => hx
/-- The fundamental property of the operator norm of a continuous multilinear map:
`‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`. -/
theorem le_opNorm (f : ContinuousMultilinearMap 𝕜 E G) (m : ∀ i, E i) :
‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖ :=
f.isLeast_opNorm.1.2 m
theorem le_mul_prod_of_opNorm_le_of_le {f : ContinuousMultilinearMap 𝕜 E G}
{m : ∀ i, E i} {C : ℝ} {b : ι → ℝ} (hC : ‖f‖ ≤ C) (hm : ∀ i, ‖m i‖ ≤ b i) :
‖f m‖ ≤ C * ∏ i, b i :=
(f.le_opNorm m).trans <| by gcongr; exacts [f.opNorm_nonneg.trans hC, hm _]
@[deprecated (since := "2024-11-27")]
alias le_mul_prod_of_le_opNorm_of_le := le_mul_prod_of_opNorm_le_of_le
theorem le_opNorm_mul_prod_of_le (f : ContinuousMultilinearMap 𝕜 E G)
{m : ∀ i, E i} {b : ι → ℝ} (hm : ∀ i, ‖m i‖ ≤ b i) : ‖f m‖ ≤ ‖f‖ * ∏ i, b i :=
le_mul_prod_of_opNorm_le_of_le le_rfl hm
theorem le_opNorm_mul_pow_card_of_le (f : ContinuousMultilinearMap 𝕜 E G) {m b} (hm : ‖m‖ ≤ b) :
‖f m‖ ≤ ‖f‖ * b ^ Fintype.card ι := by
simpa only [prod_const] using f.le_opNorm_mul_prod_of_le fun i => (norm_le_pi_norm m i).trans hm
theorem le_opNorm_mul_pow_of_le {n : ℕ} {Ei : Fin n → Type*} [∀ i, SeminormedAddCommGroup (Ei i)]
[∀ i, NormedSpace 𝕜 (Ei i)] (f : ContinuousMultilinearMap 𝕜 Ei G) {m : ∀ i, Ei i} {b : ℝ}
(hm : ‖m‖ ≤ b) : ‖f m‖ ≤ ‖f‖ * b ^ n := by
simpa only [Fintype.card_fin] using f.le_opNorm_mul_pow_card_of_le hm
theorem le_of_opNorm_le {f : ContinuousMultilinearMap 𝕜 E G} {C : ℝ} (h : ‖f‖ ≤ C) (m : ∀ i, E i) :
‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
le_mul_prod_of_opNorm_le_of_le h fun _ ↦ le_rfl
theorem ratio_le_opNorm (f : ContinuousMultilinearMap 𝕜 E G) (m : ∀ i, E i) :
(‖f m‖ / ∏ i, ‖m i‖) ≤ ‖f‖ :=
div_le_of_le_mul₀ (by positivity) (opNorm_nonneg _) (f.le_opNorm m)
/-- The image of the unit ball under a continuous multilinear map is bounded. -/
theorem unit_le_opNorm (f : ContinuousMultilinearMap 𝕜 E G) {m : ∀ i, E i} (h : ‖m‖ ≤ 1) :
‖f m‖ ≤ ‖f‖ :=
(le_opNorm_mul_pow_card_of_le f h).trans <| by simp
/-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/
theorem opNorm_le_bound {f : ContinuousMultilinearMap 𝕜 E G}
{M : ℝ} (hMp : 0 ≤ M) (hM : ∀ m, ‖f m‖ ≤ M * ∏ i, ‖m i‖) : ‖f‖ ≤ M :=
csInf_le bounds_bddBelow ⟨hMp, hM⟩
theorem opNorm_le_iff {f : ContinuousMultilinearMap 𝕜 E G} {C : ℝ} (hC : 0 ≤ C) :
‖f‖ ≤ C ↔ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
⟨fun h _ ↦ le_of_opNorm_le h _, opNorm_le_bound hC⟩
/-- The operator norm satisfies the triangle inequality. -/
theorem opNorm_add_le (f g : ContinuousMultilinearMap 𝕜 E G) : ‖f + g‖ ≤ ‖f‖ + ‖g‖ :=
opNorm_le_bound (add_nonneg (opNorm_nonneg f) (opNorm_nonneg g)) fun x => by
rw [add_mul]
exact norm_add_le_of_le (le_opNorm _ _) (le_opNorm _ _)
theorem opNorm_zero : ‖(0 : ContinuousMultilinearMap 𝕜 E G)‖ = 0 :=
(opNorm_nonneg _).antisymm' <| opNorm_le_bound le_rfl fun m => by simp
section
variable {𝕜' : Type*} [NormedField 𝕜'] [NormedSpace 𝕜' G] [SMulCommClass 𝕜 𝕜' G]
theorem opNorm_smul_le (c : 𝕜') (f : ContinuousMultilinearMap 𝕜 E G) : ‖c • f‖ ≤ ‖c‖ * ‖f‖ :=
(c • f).opNorm_le_bound (mul_nonneg (norm_nonneg _) (opNorm_nonneg _)) fun m ↦ by
rw [smul_apply, norm_smul, mul_assoc]
exact mul_le_mul_of_nonneg_left (le_opNorm _ _) (norm_nonneg _)
variable (𝕜 E G) in
/-- Operator seminorm on the space of continuous multilinear maps, as `Seminorm`.
We use this seminorm
to define a `SeminormedAddCommGroup` structure on `ContinuousMultilinearMap 𝕜 E G`,
but we have to override the projection `UniformSpace`
so that it is definitionally equal to the one coming from the topologies on `E` and `G`. -/
protected def seminorm : Seminorm 𝕜 (ContinuousMultilinearMap 𝕜 E G) :=
.ofSMulLE norm opNorm_zero opNorm_add_le fun c f ↦ f.opNorm_smul_le c
private lemma uniformity_eq_seminorm :
𝓤 (ContinuousMultilinearMap 𝕜 E G) = ⨅ r > 0, 𝓟 {f | ‖f.1 - f.2‖ < r} := by
refine (ContinuousMultilinearMap.seminorm 𝕜 E G).uniformity_eq_of_hasBasis
(ContinuousMultilinearMap.hasBasis_nhds_zero_of_basis Metric.nhds_basis_closedBall)
?_ fun (s, r) ⟨hs, hr⟩ ↦ ?_
· rcases NormedField.exists_lt_norm 𝕜 1 with ⟨c, hc⟩
have hc₀ : 0 < ‖c‖ := one_pos.trans hc
simp only [hasBasis_nhds_zero.mem_iff, Prod.exists]
use 1, closedBall 0 ‖c‖, closedBall 0 1
suffices ∀ f : ContinuousMultilinearMap 𝕜 E G, (∀ x, ‖x‖ ≤ ‖c‖ → ‖f x‖ ≤ 1) → ‖f‖ ≤ 1 by
simpa [NormedSpace.isVonNBounded_closedBall, closedBall_mem_nhds, Set.subset_def, Set.MapsTo]
intro f hf
refine opNorm_le_bound (by positivity) <|
f.1.bound_of_shell_of_continuous f.2 (fun _ ↦ hc₀) (fun _ ↦ hc) fun x hcx hx ↦ ?_
calc
‖f x‖ ≤ 1 := hf _ <| (pi_norm_le_iff_of_nonneg (norm_nonneg c)).2 fun i ↦ (hx i).le
_ = ∏ i : ι, 1 := by simp
_ ≤ ∏ i, ‖x i‖ := Finset.prod_le_prod (fun _ _ ↦ zero_le_one) fun i _ ↦ by
simpa only [div_self hc₀.ne'] using hcx i
_ = 1 * ∏ i, ‖x i‖ := (one_mul _).symm
· rcases (NormedSpace.isVonNBounded_iff' _).1 hs with ⟨ε, hε⟩
rcases exists_pos_mul_lt hr (ε ^ Fintype.card ι) with ⟨δ, hδ₀, hδ⟩
refine ⟨δ, hδ₀, fun f hf x hx ↦ ?_⟩
simp only [Seminorm.mem_ball_zero, mem_closedBall_zero_iff] at hf ⊢
replace hf : ‖f‖ ≤ δ := hf.le
replace hx : ‖x‖ ≤ ε := hε x hx
calc
‖f x‖ ≤ ‖f‖ * ε ^ Fintype.card ι := le_opNorm_mul_pow_card_of_le f hx
_ ≤ δ * ε ^ Fintype.card ι := by have := (norm_nonneg x).trans hx; gcongr
_ ≤ r := (mul_comm _ _).trans_le hδ.le
instance instPseudoMetricSpace : PseudoMetricSpace (ContinuousMultilinearMap 𝕜 E G) :=
.replaceUniformity
(ContinuousMultilinearMap.seminorm 𝕜 E G).toSeminormedAddCommGroup.toPseudoMetricSpace
uniformity_eq_seminorm
/-- Continuous multilinear maps themselves form a seminormed space with respect to
the operator norm. -/
instance seminormedAddCommGroup :
SeminormedAddCommGroup (ContinuousMultilinearMap 𝕜 E G) := ⟨fun _ _ ↦ rfl⟩
/-- An alias of `ContinuousMultilinearMap.seminormedAddCommGroup` with non-dependent types to help
typeclass search. -/
instance seminormedAddCommGroup' :
SeminormedAddCommGroup (ContinuousMultilinearMap 𝕜 (fun _ : ι => G) G') :=
ContinuousMultilinearMap.seminormedAddCommGroup
instance normedSpace : NormedSpace 𝕜' (ContinuousMultilinearMap 𝕜 E G) :=
⟨fun c f => f.opNorm_smul_le c⟩
/-- An alias of `ContinuousMultilinearMap.normedSpace` with non-dependent types to help typeclass
search. -/
instance normedSpace' : NormedSpace 𝕜' (ContinuousMultilinearMap 𝕜 (fun _ : ι => G') G) :=
ContinuousMultilinearMap.normedSpace
@[deprecated norm_neg (since := "2024-11-24")]
theorem opNorm_neg (f : ContinuousMultilinearMap 𝕜 E G) : ‖-f‖ = ‖f‖ := norm_neg f
/-- The fundamental property of the operator norm of a continuous multilinear map:
`‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`, `nnnorm` version. -/
theorem le_opNNNorm (f : ContinuousMultilinearMap 𝕜 E G) (m : ∀ i, E i) :
‖f m‖₊ ≤ ‖f‖₊ * ∏ i, ‖m i‖₊ :=
NNReal.coe_le_coe.1 <| by
push_cast
exact f.le_opNorm m
theorem le_of_opNNNorm_le (f : ContinuousMultilinearMap 𝕜 E G)
{C : ℝ≥0} (h : ‖f‖₊ ≤ C) (m : ∀ i, E i) : ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ :=
(f.le_opNNNorm m).trans <| mul_le_mul' h le_rfl
theorem opNNNorm_le_iff {f : ContinuousMultilinearMap 𝕜 E G} {C : ℝ≥0} :
‖f‖₊ ≤ C ↔ ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ := by
simp only [← NNReal.coe_le_coe]; simp [opNorm_le_iff C.coe_nonneg, NNReal.coe_prod]
theorem isLeast_opNNNorm (f : ContinuousMultilinearMap 𝕜 E G) :
IsLeast {C : ℝ≥0 | ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊} ‖f‖₊ := by
simpa only [← opNNNorm_le_iff] using isLeast_Ici
theorem opNNNorm_prod (f : ContinuousMultilinearMap 𝕜 E G) (g : ContinuousMultilinearMap 𝕜 E G') :
‖f.prod g‖₊ = max ‖f‖₊ ‖g‖₊ :=
eq_of_forall_ge_iff fun _ ↦ by
simp only [opNNNorm_le_iff, prod_apply, Prod.nnnorm_def, max_le_iff, forall_and]
theorem opNorm_prod (f : ContinuousMultilinearMap 𝕜 E G) (g : ContinuousMultilinearMap 𝕜 E G') :
‖f.prod g‖ = max ‖f‖ ‖g‖ :=
congr_arg NNReal.toReal (opNNNorm_prod f g)
theorem opNNNorm_pi
[∀ i', SeminormedAddCommGroup (E' i')] [∀ i', NormedSpace 𝕜 (E' i')]
(f : ∀ i', ContinuousMultilinearMap 𝕜 E (E' i')) : ‖pi f‖₊ = ‖f‖₊ :=
eq_of_forall_ge_iff fun _ ↦ by simpa [opNNNorm_le_iff, pi_nnnorm_le_iff] using forall_swap
theorem opNorm_pi {ι' : Type v'} [Fintype ι'] {E' : ι' → Type wE'}
[∀ i', SeminormedAddCommGroup (E' i')] [∀ i', NormedSpace 𝕜 (E' i')]
(f : ∀ i', ContinuousMultilinearMap 𝕜 E (E' i')) :
‖pi f‖ = ‖f‖ :=
congr_arg NNReal.toReal (opNNNorm_pi f)
section
@[simp]
theorem norm_ofSubsingleton [Subsingleton ι] (i : ι) (f : G →L[𝕜] G') :
‖ofSubsingleton 𝕜 G G' i f‖ = ‖f‖ := by
letI : Unique ι := uniqueOfSubsingleton i
simp [norm_def, ContinuousLinearMap.norm_def, (Equiv.funUnique _ _).symm.surjective.forall]
@[simp]
theorem nnnorm_ofSubsingleton [Subsingleton ι] (i : ι) (f : G →L[𝕜] G') :
‖ofSubsingleton 𝕜 G G' i f‖₊ = ‖f‖₊ :=
NNReal.eq <| norm_ofSubsingleton i f
variable (𝕜 G)
/-- Linear isometry between continuous linear maps from `G` to `G'`
and continuous `1`-multilinear maps from `G` to `G'`. -/
@[simps apply symm_apply]
def ofSubsingletonₗᵢ [Subsingleton ι] (i : ι) :
(G →L[𝕜] G') ≃ₗᵢ[𝕜] ContinuousMultilinearMap 𝕜 (fun _ : ι ↦ G) G' :=
{ ofSubsingleton 𝕜 G G' i with
map_add' := fun _ _ ↦ rfl
map_smul' := fun _ _ ↦ rfl
norm_map' := norm_ofSubsingleton i }
theorem norm_ofSubsingleton_id_le [Subsingleton ι] (i : ι) :
‖ofSubsingleton 𝕜 G G i (.id _ _)‖ ≤ 1 := by
rw [norm_ofSubsingleton]
apply ContinuousLinearMap.norm_id_le
theorem nnnorm_ofSubsingleton_id_le [Subsingleton ι] (i : ι) :
‖ofSubsingleton 𝕜 G G i (.id _ _)‖₊ ≤ 1 :=
norm_ofSubsingleton_id_le _ _ _
variable {G} (E)
@[simp]
theorem norm_constOfIsEmpty [IsEmpty ι] (x : G) : ‖constOfIsEmpty 𝕜 E x‖ = ‖x‖ := by
apply le_antisymm
· refine opNorm_le_bound (norm_nonneg _) fun x => ?_
rw [Fintype.prod_empty, mul_one, constOfIsEmpty_apply]
· simpa using (constOfIsEmpty 𝕜 E x).le_opNorm 0
@[simp]
theorem nnnorm_constOfIsEmpty [IsEmpty ι] (x : G) : ‖constOfIsEmpty 𝕜 E x‖₊ = ‖x‖₊ :=
NNReal.eq <| norm_constOfIsEmpty _ _ _
end
section
variable (𝕜 E E' G G')
/-- `ContinuousMultilinearMap.prod` as a `LinearIsometryEquiv`. -/
@[simps]
def prodL :
ContinuousMultilinearMap 𝕜 E G × ContinuousMultilinearMap 𝕜 E G' ≃ₗᵢ[𝕜]
ContinuousMultilinearMap 𝕜 E (G × G') where
__ := prodEquiv
map_add' _ _ := rfl
map_smul' _ _ := rfl
norm_map' f := opNorm_prod f.1 f.2
/-- `ContinuousMultilinearMap.pi` as a `LinearIsometryEquiv`. -/
@[simps! apply symm_apply]
def piₗᵢ {ι' : Type v'} [Fintype ι'] {E' : ι' → Type wE'} [∀ i', NormedAddCommGroup (E' i')]
[∀ i', NormedSpace 𝕜 (E' i')] :
(Π i', ContinuousMultilinearMap 𝕜 E (E' i'))
≃ₗᵢ[𝕜] (ContinuousMultilinearMap 𝕜 E (Π i, E' i)) where
toLinearEquiv := piLinearEquiv
norm_map' := opNorm_pi
end
end
section RestrictScalars
variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜' 𝕜]
variable [NormedSpace 𝕜' G] [IsScalarTower 𝕜' 𝕜 G]
variable [∀ i, NormedSpace 𝕜' (E i)] [∀ i, IsScalarTower 𝕜' 𝕜 (E i)]
@[simp]
theorem norm_restrictScalars (f : ContinuousMultilinearMap 𝕜 E G) :
‖f.restrictScalars 𝕜'‖ = ‖f‖ :=
rfl
variable (𝕜')
/-- `ContinuousMultilinearMap.restrictScalars` as a `LinearIsometry`. -/
def restrictScalarsₗᵢ : ContinuousMultilinearMap 𝕜 E G →ₗᵢ[𝕜'] ContinuousMultilinearMap 𝕜' E G where
toFun := restrictScalars 𝕜'
map_add' _ _ := rfl
map_smul' _ _ := rfl
norm_map' _ := rfl
end RestrictScalars
/-- The difference `f m₁ - f m₂` is controlled in terms of `‖f‖` and `‖m₁ - m₂‖`, precise version.
For a less precise but more usable version, see `norm_image_sub_le`. The bound reads
`‖f m - f m'‖ ≤
‖f‖ * ‖m 1 - m' 1‖ * max ‖m 2‖ ‖m' 2‖ * max ‖m 3‖ ‖m' 3‖ * ... * max ‖m n‖ ‖m' n‖ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`. -/
theorem norm_image_sub_le' [DecidableEq ι] (f : ContinuousMultilinearMap 𝕜 E G) (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ ‖f‖ * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ :=
f.toMultilinearMap.norm_image_sub_le_of_bound' (norm_nonneg _) f.le_opNorm _ _
/-- The difference `f m₁ - f m₂` is controlled in terms of `‖f‖` and `‖m₁ - m₂‖`, less precise
version. For a more precise but less usable version, see `norm_image_sub_le'`.
The bound is `‖f m - f m'‖ ≤ ‖f‖ * card ι * ‖m - m'‖ * (max ‖m‖ ‖m'‖) ^ (card ι - 1)`. -/
theorem norm_image_sub_le (f : ContinuousMultilinearMap 𝕜 E G) (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ ‖f‖ * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ :=
f.toMultilinearMap.norm_image_sub_le_of_bound (norm_nonneg _) f.le_opNorm _ _
end ContinuousMultilinearMap
variable [Fintype ι]
/-- If a continuous multilinear map is constructed from a multilinear map via the constructor
`mkContinuous`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
theorem MultilinearMap.mkContinuous_norm_le (f : MultilinearMap 𝕜 E G) {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ‖f.mkContinuous C H‖ ≤ C :=
ContinuousMultilinearMap.opNorm_le_bound hC fun m => H m
/-- If a continuous multilinear map is constructed from a multilinear map via the constructor
`mkContinuous`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
theorem MultilinearMap.mkContinuous_norm_le' (f : MultilinearMap 𝕜 E G) {C : ℝ}
(H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ‖f.mkContinuous C H‖ ≤ max C 0 :=
ContinuousMultilinearMap.opNorm_le_bound (le_max_right _ _) fun m ↦ (H m).trans <|
mul_le_mul_of_nonneg_right (le_max_left _ _) <| by positivity
namespace ContinuousMultilinearMap
/-- Given a continuous multilinear map `f` on `n` variables (parameterized by `Fin n`) and a subset
`s` of `k` of these variables, one gets a new continuous multilinear map on `Fin k` by varying
these variables, and fixing the other ones equal to a given value `z`. It is denoted by
`f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit
identification between `Fin k` and `s` that we use is the canonical (increasing) bijection. -/
def restr {k n : ℕ} (f : (G [×n]→L[𝕜] G' :)) (s : Finset (Fin n)) (hk : #s = k) (z : G) :
G [×k]→L[𝕜] G' :=
(f.toMultilinearMap.restr s hk z).mkContinuous (‖f‖ * ‖z‖ ^ (n - k)) fun _ =>
MultilinearMap.restr_norm_le _ _ _ _ f.le_opNorm _
theorem norm_restr {k n : ℕ} (f : G [×n]→L[𝕜] G') (s : Finset (Fin n)) (hk : #s = k) (z : G) :
‖f.restr s hk z‖ ≤ ‖f‖ * ‖z‖ ^ (n - k) := by
apply MultilinearMap.mkContinuous_norm_le
exact mul_nonneg (norm_nonneg _) (pow_nonneg (norm_nonneg _) _)
section
variable {A : Type*} [NormedCommRing A] [NormedAlgebra 𝕜 A]
@[simp]
theorem norm_mkPiAlgebra_le [Nonempty ι] : ‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ ≤ 1 := by
refine opNorm_le_bound zero_le_one fun m => ?_
simp only [ContinuousMultilinearMap.mkPiAlgebra_apply, one_mul]
exact norm_prod_le' _ univ_nonempty _
theorem norm_mkPiAlgebra_of_empty [IsEmpty ι] :
‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ = ‖(1 : A)‖ := by
apply le_antisymm
· apply opNorm_le_bound <;> simp
· convert ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A) fun _ => 1
simp [eq_empty_of_isEmpty univ]
@[simp]
theorem norm_mkPiAlgebra [NormOneClass A] : ‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ = 1 := by
cases isEmpty_or_nonempty ι
· simp [norm_mkPiAlgebra_of_empty]
· refine le_antisymm norm_mkPiAlgebra_le ?_
convert ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A) fun _ => 1
simp
end
section
variable {n : ℕ} {A : Type*} [SeminormedRing A] [NormedAlgebra 𝕜 A]
theorem norm_mkPiAlgebraFin_succ_le : ‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 n.succ A‖ ≤ 1 := by
refine opNorm_le_bound zero_le_one fun m => ?_
simp only [ContinuousMultilinearMap.mkPiAlgebraFin_apply, one_mul, List.ofFn_eq_map,
Fin.prod_univ_def, Multiset.map_coe, Multiset.prod_coe]
refine (List.norm_prod_le' ?_).trans_eq ?_
· rw [Ne, List.map_eq_nil_iff, List.finRange_eq_nil]
exact Nat.succ_ne_zero _
rw [List.map_map, Function.comp_def]
theorem norm_mkPiAlgebraFin_le_of_pos (hn : 0 < n) :
‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 n A‖ ≤ 1 := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'
exact norm_mkPiAlgebraFin_succ_le
theorem norm_mkPiAlgebraFin_zero : ‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 0 A‖ = ‖(1 : A)‖ := by
refine le_antisymm ?_ ?_
· refine opNorm_le_bound (norm_nonneg (1 : A)) ?_
simp
· convert ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 0 A) fun _ => (1 : A)
simp
theorem norm_mkPiAlgebraFin_le :
‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 n A‖ ≤ max 1 ‖(1 : A)‖ := by
cases n
· exact norm_mkPiAlgebraFin_zero.le.trans (le_max_right _ _)
· exact (norm_mkPiAlgebraFin_le_of_pos (Nat.zero_lt_succ _)).trans (le_max_left _ _)
@[simp]
theorem norm_mkPiAlgebraFin [NormOneClass A] :
‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 n A‖ = 1 := by
cases n
· rw [norm_mkPiAlgebraFin_zero]
simp
· refine le_antisymm norm_mkPiAlgebraFin_succ_le ?_
refine le_of_eq_of_le ?_ <|
ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 (Nat.succ _) A) fun _ => 1
simp
end
@[simp]
theorem nnnorm_smulRight (f : ContinuousMultilinearMap 𝕜 E 𝕜) (z : G) :
‖f.smulRight z‖₊ = ‖f‖₊ * ‖z‖₊ := by
refine le_antisymm ?_ ?_
· refine opNNNorm_le_iff.2 fun m => (nnnorm_smul_le _ _).trans ?_
rw [mul_right_comm]
gcongr
exact le_opNNNorm _ _
· obtain hz | hz := eq_zero_or_pos ‖z‖₊
· simp [hz]
rw [← le_div_iff₀ hz, opNNNorm_le_iff]
intro m
rw [div_mul_eq_mul_div, le_div_iff₀ hz]
refine le_trans ?_ ((f.smulRight z).le_opNNNorm m)
rw [smulRight_apply, nnnorm_smul]
@[simp]
theorem norm_smulRight (f : ContinuousMultilinearMap 𝕜 E 𝕜) (z : G) :
‖f.smulRight z‖ = ‖f‖ * ‖z‖ :=
congr_arg NNReal.toReal (nnnorm_smulRight f z)
@[simp]
theorem norm_mkPiRing (z : G) : ‖ContinuousMultilinearMap.mkPiRing 𝕜 ι z‖ = ‖z‖ := by
rw [ContinuousMultilinearMap.mkPiRing, norm_smulRight, norm_mkPiAlgebra, one_mul]
variable (𝕜 E G) in
/-- Continuous bilinear map realizing `(f, z) ↦ f.smulRight z`. -/
def smulRightL : ContinuousMultilinearMap 𝕜 E 𝕜 →L[𝕜] G →L[𝕜] ContinuousMultilinearMap 𝕜 E G :=
LinearMap.mkContinuous₂
{ toFun := fun f ↦
{ toFun := fun z ↦ f.smulRight z
map_add' := fun x y ↦ by ext; simp
map_smul' := fun c x ↦ by ext; simp [smul_smul, mul_comm] }
map_add' := fun f g ↦ by ext; simp [add_smul]
map_smul' := fun c f ↦ by ext; simp [smul_smul] }
1 (fun f z ↦ by simp [norm_smulRight])
@[simp] lemma smulRightL_apply (f : ContinuousMultilinearMap 𝕜 E 𝕜) (z : G) :
smulRightL 𝕜 E G f z = f.smulRight z := rfl
lemma norm_smulRightL_le : ‖smulRightL 𝕜 E G‖ ≤ 1 :=
LinearMap.mkContinuous₂_norm_le _ zero_le_one _
variable (𝕜 ι G)
/-- Continuous multilinear maps on `𝕜^n` with values in `G` are in bijection with `G`, as such a
continuous multilinear map is completely determined by its value on the constant vector made of
ones. We register this bijection as a linear isometry in
`ContinuousMultilinearMap.piFieldEquiv`. -/
protected def piFieldEquiv : G ≃ₗᵢ[𝕜] ContinuousMultilinearMap 𝕜 (fun _ : ι => 𝕜) G where
toFun z := ContinuousMultilinearMap.mkPiRing 𝕜 ι z
invFun f := f fun _ => 1
map_add' z z' := by
ext m
simp [smul_add]
map_smul' c z := by
ext m
simp [smul_smul, mul_comm]
left_inv z := by simp
right_inv f := f.mkPiRing_apply_one_eq_self
norm_map' := norm_mkPiRing
end ContinuousMultilinearMap
namespace ContinuousLinearMap
theorem norm_compContinuousMultilinearMap_le (g : G →L[𝕜] G') (f : ContinuousMultilinearMap 𝕜 E G) :
‖g.compContinuousMultilinearMap f‖ ≤ ‖g‖ * ‖f‖ :=
ContinuousMultilinearMap.opNorm_le_bound (by positivity) fun m ↦
calc
‖g (f m)‖ ≤ ‖g‖ * (‖f‖ * ∏ i, ‖m i‖) := g.le_opNorm_of_le <| f.le_opNorm _
_ = _ := (mul_assoc _ _ _).symm
variable (𝕜 E G G')
/-- `ContinuousLinearMap.compContinuousMultilinearMap` as a bundled continuous bilinear map. -/
def compContinuousMultilinearMapL :
(G →L[𝕜] G') →L[𝕜] ContinuousMultilinearMap 𝕜 E G →L[𝕜] ContinuousMultilinearMap 𝕜 E G' :=
LinearMap.mkContinuous₂
(LinearMap.mk₂ 𝕜 compContinuousMultilinearMap (fun _ _ _ => rfl) (fun _ _ _ => rfl)
(fun f g₁ g₂ => by ext1; apply f.map_add)
(fun c f g => by ext1; simp))
1
fun f g => by rw [one_mul]; exact f.norm_compContinuousMultilinearMap_le g
variable {𝕜 G G'}
/-- `ContinuousLinearMap.compContinuousMultilinearMap` as a bundled
continuous linear equiv. -/
def _root_.ContinuousLinearEquiv.continuousMultilinearMapCongrRight (g : G ≃L[𝕜] G') :
ContinuousMultilinearMap 𝕜 E G ≃L[𝕜] ContinuousMultilinearMap 𝕜 E G' :=
{ compContinuousMultilinearMapL 𝕜 E G G' g.toContinuousLinearMap with
invFun := compContinuousMultilinearMapL 𝕜 E G' G g.symm.toContinuousLinearMap
left_inv := by
intro f
ext1 m
simp [compContinuousMultilinearMapL]
right_inv := by
intro f
ext1 m
simp [compContinuousMultilinearMapL]
continuous_invFun :=
(compContinuousMultilinearMapL 𝕜 E G' G g.symm.toContinuousLinearMap).continuous }
@[deprecated (since := "2025-04-19")]
alias _root_.ContinuousLinearEquiv.compContinuousMultilinearMapL :=
ContinuousLinearEquiv.continuousMultilinearMapCongrRight
@[simp]
theorem _root_.ContinuousLinearEquiv.continuousMultilinearMapCongrRight_symm (g : G ≃L[𝕜] G') :
(g.continuousMultilinearMapCongrRight E).symm = g.symm.continuousMultilinearMapCongrRight E :=
rfl
@[deprecated (since := "2025-04-19")]
alias _root_.ContinuousLinearEquiv.compContinuousMultilinearMapL_symm :=
ContinuousLinearEquiv.continuousMultilinearMapCongrRight_symm
variable {E}
@[simp]
theorem _root_.ContinuousLinearEquiv.continuousMultilinearMapCongrRight_apply (g : G ≃L[𝕜] G')
(f : ContinuousMultilinearMap 𝕜 E G) :
g.continuousMultilinearMapCongrRight E f = (g : G →L[𝕜] G').compContinuousMultilinearMap f :=
rfl
@[deprecated (since := "2025-04-19")]
alias _root_.ContinuousLinearEquiv.compContinuousMultilinearMapL_apply :=
ContinuousLinearEquiv.continuousMultilinearMapCongrRight_apply
/-- Flip arguments in `f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E G'` to get
`ContinuousMultilinearMap 𝕜 E (G →L[𝕜] G')` -/
@[simps! apply_apply]
def flipMultilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E G') :
ContinuousMultilinearMap 𝕜 E (G →L[𝕜] G') :=
MultilinearMap.mkContinuous
{ toFun := fun m =>
LinearMap.mkContinuous
{ toFun := fun x => f x m
map_add' := fun x y => by simp only [map_add, ContinuousMultilinearMap.add_apply]
map_smul' := fun c x => by
simp only [ContinuousMultilinearMap.smul_apply, map_smul, RingHom.id_apply] }
(‖f‖ * ∏ i, ‖m i‖) fun x => by
rw [mul_right_comm]
exact (f x).le_of_opNorm_le (f.le_opNorm x) _
map_update_add' := fun m i x y => by
ext1
simp only [add_apply, ContinuousMultilinearMap.map_update_add, LinearMap.coe_mk,
LinearMap.mkContinuous_apply, AddHom.coe_mk]
map_update_smul' := fun m i c x => by
ext1
simp only [coe_smul', ContinuousMultilinearMap.map_update_smul, LinearMap.coe_mk,
LinearMap.mkContinuous_apply, Pi.smul_apply, AddHom.coe_mk] }
‖f‖ fun m => by
dsimp only [MultilinearMap.coe_mk]
exact LinearMap.mkContinuous_norm_le _ (by positivity) _
end ContinuousLinearMap
theorem LinearIsometry.norm_compContinuousMultilinearMap (g : G →ₗᵢ[𝕜] G')
(f : ContinuousMultilinearMap 𝕜 E G) :
‖g.toContinuousLinearMap.compContinuousMultilinearMap f‖ = ‖f‖ := by
simp only [ContinuousLinearMap.compContinuousMultilinearMap_coe,
LinearIsometry.coe_toContinuousLinearMap, LinearIsometry.norm_map,
ContinuousMultilinearMap.norm_def, Function.comp_apply]
open ContinuousMultilinearMap
namespace MultilinearMap
/-- Given a map `f : G →ₗ[𝕜] MultilinearMap 𝕜 E G'` and an estimate
`H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖`, construct a continuous linear
map from `G` to `ContinuousMultilinearMap 𝕜 E G'`.
In order to lift, e.g., a map `f : (MultilinearMap 𝕜 E G) →ₗ[𝕜] MultilinearMap 𝕜 E' G'`
to a map `(ContinuousMultilinearMap 𝕜 E G) →L[𝕜] ContinuousMultilinearMap 𝕜 E' G'`,
one can apply this construction to `f.comp ContinuousMultilinearMap.toMultilinearMapLinear`
which is a linear map from `ContinuousMultilinearMap 𝕜 E G` to `MultilinearMap 𝕜 E' G'`. -/
def mkContinuousLinear (f : G →ₗ[𝕜] MultilinearMap 𝕜 E G') (C : ℝ)
(H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖) : G →L[𝕜] ContinuousMultilinearMap 𝕜 E G' :=
LinearMap.mkContinuous
{ toFun := fun x => (f x).mkContinuous (C * ‖x‖) <| H x
map_add' := fun x y => by
ext1
simp
map_smul' := fun c x => by
ext1
simp }
(max C 0) fun x => by
simpa using ((f x).mkContinuous_norm_le' _).trans_eq <| by
rw [max_mul_of_nonneg _ _ (norm_nonneg x), zero_mul]
theorem mkContinuousLinear_norm_le' (f : G →ₗ[𝕜] MultilinearMap 𝕜 E G') (C : ℝ)
(H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖) : ‖mkContinuousLinear f C H‖ ≤ max C 0 := by
dsimp only [mkContinuousLinear]
exact LinearMap.mkContinuous_norm_le _ (le_max_right _ _) _
theorem mkContinuousLinear_norm_le (f : G →ₗ[𝕜] MultilinearMap 𝕜 E G') {C : ℝ} (hC : 0 ≤ C)
(H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖) : ‖mkContinuousLinear f C H‖ ≤ C :=
(mkContinuousLinear_norm_le' f C H).trans_eq (max_eq_left hC)
variable [∀ i, SeminormedAddCommGroup (E' i)] [∀ i, NormedSpace 𝕜 (E' i)]
/-- Given a map `f : MultilinearMap 𝕜 E (MultilinearMap 𝕜 E' G)` and an estimate
`H : ∀ m m', ‖f m m'‖ ≤ C * ∏ i, ‖m i‖ * ∏ i, ‖m' i‖`, upgrade all `MultilinearMap`s in the type to
`ContinuousMultilinearMap`s. -/
def mkContinuousMultilinear (f : MultilinearMap 𝕜 E (MultilinearMap 𝕜 E' G)) (C : ℝ)
(H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) :
ContinuousMultilinearMap 𝕜 E (ContinuousMultilinearMap 𝕜 E' G) :=
mkContinuous
{ toFun := fun m => mkContinuous (f m) (C * ∏ i, ‖m i‖) <| H m
map_update_add' := fun m i x y => by
ext1
simp
map_update_smul' := fun m i c x => by
ext1
simp }
(max C 0) fun m => by
simp only [coe_mk]
refine ((f m).mkContinuous_norm_le' _).trans_eq ?_
rw [max_mul_of_nonneg, zero_mul]
positivity
@[simp]
theorem mkContinuousMultilinear_apply (f : MultilinearMap 𝕜 E (MultilinearMap 𝕜 E' G)) {C : ℝ}
(H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) (m : ∀ i, E i) :
⇑(mkContinuousMultilinear f C H m) = f m :=
rfl
theorem mkContinuousMultilinear_norm_le' (f : MultilinearMap 𝕜 E (MultilinearMap 𝕜 E' G)) (C : ℝ)
(H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) :
‖mkContinuousMultilinear f C H‖ ≤ max C 0 := by
dsimp only [mkContinuousMultilinear]
exact mkContinuous_norm_le _ (le_max_right _ _) _
theorem mkContinuousMultilinear_norm_le (f : MultilinearMap 𝕜 E (MultilinearMap 𝕜 E' G)) {C : ℝ}
(hC : 0 ≤ C) (H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) :
‖mkContinuousMultilinear f C H‖ ≤ C :=
(mkContinuousMultilinear_norm_le' f C H).trans_eq (max_eq_left hC)
end MultilinearMap
namespace ContinuousMultilinearMap
theorem norm_compContinuousLinearMap_le (g : ContinuousMultilinearMap 𝕜 E₁ G)
(f : ∀ i, E i →L[𝕜] E₁ i) : ‖g.compContinuousLinearMap f‖ ≤ ‖g‖ * ∏ i, ‖f i‖ :=
opNorm_le_bound (by positivity) fun m =>
calc
‖g fun i => f i (m i)‖ ≤ ‖g‖ * ∏ i, ‖f i (m i)‖ := g.le_opNorm _
_ ≤ ‖g‖ * ∏ i, ‖f i‖ * ‖m i‖ :=
(mul_le_mul_of_nonneg_left
(prod_le_prod (fun _ _ => norm_nonneg _) fun i _ => (f i).le_opNorm (m i))
(norm_nonneg g))
_ = (‖g‖ * ∏ i, ‖f i‖) * ∏ i, ‖m i‖ := by rw [prod_mul_distrib, mul_assoc]
theorem norm_compContinuous_linearIsometry_le (g : ContinuousMultilinearMap 𝕜 E₁ G)
(f : ∀ i, E i →ₗᵢ[𝕜] E₁ i) :
‖g.compContinuousLinearMap fun i => (f i).toContinuousLinearMap‖ ≤ ‖g‖ := by
refine opNorm_le_bound (norm_nonneg _) fun m => ?_
apply (g.le_opNorm _).trans _
simp only [ContinuousLinearMap.coe_coe, LinearIsometry.coe_toContinuousLinearMap,
LinearIsometry.norm_map, le_rfl]
|
theorem norm_compContinuous_linearIsometryEquiv (g : ContinuousMultilinearMap 𝕜 E₁ G)
(f : ∀ i, E i ≃ₗᵢ[𝕜] E₁ i) :
‖g.compContinuousLinearMap fun i => (f i : E i →L[𝕜] E₁ i)‖ = ‖g‖ := by
apply le_antisymm (g.norm_compContinuous_linearIsometry_le fun i => (f i).toLinearIsometry)
have : g = (g.compContinuousLinearMap fun i => (f i : E i →L[𝕜] E₁ i)).compContinuousLinearMap
| Mathlib/Analysis/NormedSpace/Multilinear/Basic.lean | 1,035 | 1,040 |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.MvPolynomial.Expand
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.LinearAlgebra.Dual.Lemmas
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.RingTheory.MvPolynomial.Basic
/-!
## Polynomials over finite fields
-/
namespace MvPolynomial
variable {σ : Type*}
/-- A polynomial over the integers is divisible by `n : ℕ`
if and only if it is zero over `ZMod n`. -/
theorem C_dvd_iff_zmod (n : ℕ) (φ : MvPolynomial σ ℤ) :
C (n : ℤ) ∣ φ ↔ map (Int.castRingHom (ZMod n)) φ = 0 :=
C_dvd_iff_map_hom_eq_zero _ _ (CharP.intCast_eq_zero_iff (ZMod n) n) _
section frobenius
variable {p : ℕ} [Fact p.Prime]
theorem frobenius_zmod (f : MvPolynomial σ (ZMod p)) : frobenius _ p f = expand p f := by
apply induction_on f
· intro a; rw [expand_C, frobenius_def, ← C_pow, ZMod.pow_card]
· simp only [map_add]; intro _ _ hf hg; rw [hf, hg]
· simp only [expand_X, map_mul]
intro _ _ hf; rw [hf, frobenius_def]
theorem expand_zmod (f : MvPolynomial σ (ZMod p)) : expand p f = f ^ p :=
(frobenius_zmod _).symm
end frobenius
end MvPolynomial
namespace MvPolynomial
noncomputable section
open Set LinearMap Submodule
variable {K : Type*} {σ : Type*}
section Indicator
variable [Fintype K] [Fintype σ]
/-- Over a field, this is the indicator function as an `MvPolynomial`. -/
def indicator [CommRing K] (a : σ → K) : MvPolynomial σ K :=
∏ n, (1 - (X n - C (a n)) ^ (Fintype.card K - 1))
section CommRing
variable [CommRing K]
theorem eval_indicator_apply_eq_one (a : σ → K) : eval a (indicator a) = 1 := by
nontriviality
have : 0 < Fintype.card K - 1 := tsub_pos_of_lt Fintype.one_lt_card
simp only [indicator, map_prod, map_sub, map_one, map_pow, eval_X, eval_C, sub_self,
zero_pow this.ne', sub_zero, Finset.prod_const_one]
theorem degrees_indicator (c : σ → K) :
degrees (indicator c) ≤ ∑ s : σ, (Fintype.card K - 1) • {s} := by
rw [indicator]
classical
refine degrees_prod_le.trans <| Finset.sum_le_sum fun s _ ↦ degrees_sub_le.trans ?_
rw [degrees_one, Multiset.zero_union]
refine le_trans degrees_pow_le (nsmul_le_nsmul_right ?_ _)
refine degrees_sub_le.trans ?_
| rw [degrees_C, Multiset.union_zero]
exact degrees_X' _
theorem indicator_mem_restrictDegree (c : σ → K) :
indicator c ∈ restrictDegree σ K (Fintype.card K - 1) := by
classical
rw [mem_restrictDegree_iff_sup, indicator]
intro n
refine le_trans (Multiset.count_le_of_le _ <| degrees_indicator _) (le_of_eq ?_)
simp_rw [← Multiset.coe_countAddMonoidHom, map_sum,
| Mathlib/FieldTheory/Finite/Polynomial.lean | 79 | 88 |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Yaël Dillies, Yuyang Zhao
-/
import Mathlib.Algebra.Order.Ring.Unbundled.Basic
import Mathlib.Algebra.CharZero.Defs
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.NatCast
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Algebra.Ring.Defs
import Mathlib.Tactic.Tauto
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
/-!
# Ordered rings and semirings
This file develops the basics of ordered (semi)rings.
Each typeclass here comprises
* an algebraic class (`Semiring`, `CommSemiring`, `Ring`, `CommRing`)
* an order class (`PartialOrder`, `LinearOrder`)
* assumptions on how both interact ((strict) monotonicity, canonicity)
For short,
* "`+` respects `≤`" means "monotonicity of addition"
* "`+` respects `<`" means "strict monotonicity of addition"
* "`*` respects `≤`" means "monotonicity of multiplication by a nonnegative number".
* "`*` respects `<`" means "strict monotonicity of multiplication by a positive number".
## Typeclasses
* `OrderedSemiring`: Semiring with a partial order such that `+` and `*` respect `≤`.
* `StrictOrderedSemiring`: Nontrivial semiring with a partial order such that `+` and `*` respects
`<`.
* `OrderedCommSemiring`: Commutative semiring with a partial order such that `+` and `*` respect
`≤`.
* `StrictOrderedCommSemiring`: Nontrivial commutative semiring with a partial order such that `+`
and `*` respect `<`.
* `OrderedRing`: Ring with a partial order such that `+` respects `≤` and `*` respects `<`.
* `OrderedCommRing`: Commutative ring with a partial order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedSemiring`: Nontrivial semiring with a linear order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedCommSemiring`: Nontrivial commutative semiring with a linear order such that `+`
respects `≤` and `*` respects `<`.
* `LinearOrderedRing`: Nontrivial ring with a linear order such that `+` respects `≤` and `*`
respects `<`.
* `LinearOrderedCommRing`: Nontrivial commutative ring with a linear order such that `+` respects
`≤` and `*` respects `<`.
## Hierarchy
The hardest part of proving order lemmas might be to figure out the correct generality and its
corresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its
immediate predecessors and what conditions are added to each of them.
* `OrderedSemiring`
- `OrderedAddCommMonoid` & multiplication & `*` respects `≤`
- `Semiring` & partial order structure & `+` respects `≤` & `*` respects `≤`
* `StrictOrderedSemiring`
- `OrderedCancelAddCommMonoid` & multiplication & `*` respects `<` & nontriviality
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommSemiring`
- `OrderedSemiring` & commutativity of multiplication
- `CommSemiring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommSemiring`
- `StrictOrderedSemiring` & commutativity of multiplication
- `OrderedCommSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedRing`
- `OrderedSemiring` & additive inverses
- `OrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedRing`
- `StrictOrderedSemiring` & additive inverses
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommRing`
- `OrderedRing` & commutativity of multiplication
- `OrderedCommSemiring` & additive inverses
- `CommRing` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommRing`
- `StrictOrderedCommSemiring` & additive inverses
- `StrictOrderedRing` & commutativity of multiplication
- `OrderedCommRing` & `+` respects `<` & `*` respects `<` & nontriviality
* `LinearOrderedSemiring`
- `StrictOrderedSemiring` & totality of the order
- `LinearOrderedAddCommMonoid` & multiplication & nontriviality & `*` respects `<`
* `LinearOrderedCommSemiring`
- `StrictOrderedCommSemiring` & totality of the order
- `LinearOrderedSemiring` & commutativity of multiplication
* `LinearOrderedRing`
- `StrictOrderedRing` & totality of the order
- `LinearOrderedSemiring` & additive inverses
- `LinearOrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & `IsDomain` & linear order structure
* `LinearOrderedCommRing`
- `StrictOrderedCommRing` & totality of the order
- `LinearOrderedRing` & commutativity of multiplication
- `LinearOrderedCommSemiring` & additive inverses
- `CommRing` & `IsDomain` & linear order structure
-/
assert_not_exists MonoidHom
open Function
universe u
variable {R : Type u}
-- TODO: assume weaker typeclasses
/-- An ordered semiring is a semiring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
class IsOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends
IsOrderedAddMonoid R, ZeroLEOneClass R where
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left
by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/
protected mul_le_mul_of_nonneg_left : ∀ a b c : R, a ≤ b → 0 ≤ c → c * a ≤ c * b
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right
by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/
protected mul_le_mul_of_nonneg_right : ∀ a b c : R, a ≤ b → 0 ≤ c → a * c ≤ b * c
attribute [instance 100] IsOrderedRing.toZeroLEOneClass
/-- A strict ordered semiring is a nontrivial semiring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
class IsStrictOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends
IsOrderedCancelAddMonoid R, ZeroLEOneClass R, Nontrivial R where
/-- In a strict ordered semiring, we can multiply an inequality `a < b` on the left
by a positive element `0 < c` to obtain `c * a < c * b`. -/
protected mul_lt_mul_of_pos_left : ∀ a b c : R, a < b → 0 < c → c * a < c * b
/-- In a strict ordered semiring, we can multiply an inequality `a < b` on the right
by a positive element `0 < c` to obtain `a * c < b * c`. -/
protected mul_lt_mul_of_pos_right : ∀ a b c : R, a < b → 0 < c → a * c < b * c
attribute [instance 100] IsStrictOrderedRing.toZeroLEOneClass
attribute [instance 100] IsStrictOrderedRing.toNontrivial
lemma IsOrderedRing.of_mul_nonneg [Ring R] [PartialOrder R] [IsOrderedAddMonoid R]
[ZeroLEOneClass R] (mul_nonneg : ∀ a b : R, 0 ≤ a → 0 ≤ b → 0 ≤ a * b) :
IsOrderedRing R where
mul_le_mul_of_nonneg_left a b c ab hc := by
simpa only [mul_sub, sub_nonneg] using mul_nonneg _ _ hc (sub_nonneg.2 ab)
mul_le_mul_of_nonneg_right a b c ab hc := by
simpa only [sub_mul, sub_nonneg] using mul_nonneg _ _ (sub_nonneg.2 ab) hc
lemma IsStrictOrderedRing.of_mul_pos [Ring R] [PartialOrder R] [IsOrderedAddMonoid R]
[ZeroLEOneClass R] [Nontrivial R] (mul_pos : ∀ a b : R, 0 < a → 0 < b → 0 < a * b) :
IsStrictOrderedRing R where
mul_lt_mul_of_pos_left a b c ab hc := by
simpa only [mul_sub, sub_pos] using mul_pos _ _ hc (sub_pos.2 ab)
mul_lt_mul_of_pos_right a b c ab hc := by
simpa only [sub_mul, sub_pos] using mul_pos _ _ (sub_pos.2 ab) hc
section IsOrderedRing
variable [Semiring R] [PartialOrder R] [IsOrderedRing R]
-- see Note [lower instance priority]
instance (priority := 200) IsOrderedRing.toPosMulMono : PosMulMono R where
elim x _ _ h := IsOrderedRing.mul_le_mul_of_nonneg_left _ _ _ h x.2
-- see Note [lower instance priority]
instance (priority := 200) IsOrderedRing.toMulPosMono : MulPosMono R where
elim x _ _ h := IsOrderedRing.mul_le_mul_of_nonneg_right _ _ _ h x.2
end IsOrderedRing
/-- Turn an ordered domain into a strict ordered ring. -/
lemma IsOrderedRing.toIsStrictOrderedRing (R : Type*)
[Ring R] [PartialOrder R] [IsOrderedRing R] [NoZeroDivisors R] [Nontrivial R] :
IsStrictOrderedRing R :=
.of_mul_pos fun _ _ ap bp ↦ (mul_nonneg ap.le bp.le).lt_of_ne' (mul_ne_zero ap.ne' bp.ne')
section IsStrictOrderedRing
variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R]
-- see Note [lower instance priority]
instance (priority := 200) IsStrictOrderedRing.toPosMulStrictMono : PosMulStrictMono R where
elim x _ _ h := IsStrictOrderedRing.mul_lt_mul_of_pos_left _ _ _ h x.prop
-- see Note [lower instance priority]
instance (priority := 200) IsStrictOrderedRing.toMulPosStrictMono : MulPosStrictMono R where
elim x _ _ h := IsStrictOrderedRing.mul_lt_mul_of_pos_right _ _ _ h x.prop
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toIsOrderedRing : IsOrderedRing R where
__ := ‹IsStrictOrderedRing R›
mul_le_mul_of_nonneg_left _ _ _ := mul_le_mul_of_nonneg_left
mul_le_mul_of_nonneg_right _ _ _ := mul_le_mul_of_nonneg_right
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toCharZero :
CharZero R where
cast_injective :=
(strictMono_nat_of_lt_succ fun n ↦ by rw [Nat.cast_succ]; apply lt_add_one).injective
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toNoMaxOrder : NoMaxOrder R :=
⟨fun a => ⟨a + 1, lt_add_of_pos_right _ one_pos⟩⟩
end IsStrictOrderedRing
section LinearOrder
variable [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] [ExistsAddOfLE R]
-- See note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.noZeroDivisors : NoZeroDivisors R where
eq_zero_or_eq_zero_of_mul_eq_zero {a b} hab := by
contrapose! hab
obtain ha | ha := hab.1.lt_or_lt <;> obtain hb | hb := hab.2.lt_or_lt
exacts [(mul_pos_of_neg_of_neg ha hb).ne', (mul_neg_of_neg_of_pos ha hb).ne,
(mul_neg_of_pos_of_neg ha hb).ne, (mul_pos ha hb).ne']
-- Note that we can't use `NoZeroDivisors.to_isDomain` since we are merely in a semiring.
-- See note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.isDomain : IsDomain R where
mul_left_cancel_of_ne_zero {a b c} ha h := by
obtain ha | ha := ha.lt_or_lt
exacts [(strictAnti_mul_left ha).injective h, (strictMono_mul_left_of_pos ha).injective h]
mul_right_cancel_of_ne_zero {b a c} ha h := by
obtain ha | ha := ha.lt_or_lt
exacts [(strictAnti_mul_right ha).injective h, (strictMono_mul_right_of_pos ha).injective h]
end LinearOrder
/-! Note that `OrderDual` does not satisfy any of the ordered ring typeclasses due to the
`zero_le_one` field. -/
set_option linter.deprecated false in
/-- An `OrderedSemiring` is a semiring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[Semiring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedSemiring (R : Type u) extends Semiring R, OrderedAddCommMonoid R where
/-- `0 ≤ 1` in any ordered semiring. -/
protected zero_le_one : (0 : R) ≤ 1
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left
by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/
protected mul_le_mul_of_nonneg_left : ∀ a b c : R, a ≤ b → 0 ≤ c → c * a ≤ c * b
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right
by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/
protected mul_le_mul_of_nonneg_right : ∀ a b c : R, a ≤ b → 0 ≤ c → a * c ≤ b * c
set_option linter.deprecated false in
/-- An `OrderedCommSemiring` is a commutative semiring with a partial order such that addition is
monotone and multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[CommSemiring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedCommSemiring (R : Type u) extends OrderedSemiring R, CommSemiring R where
mul_le_mul_of_nonneg_right a b c ha hc :=
-- parentheses ensure this generates an `optParam` rather than an `autoParam`
(by simpa only [mul_comm] using mul_le_mul_of_nonneg_left a b c ha hc)
set_option linter.deprecated false in
/-- An `OrderedRing` is a ring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[Ring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedRing (R : Type u) extends Ring R, OrderedAddCommGroup R where
/-- `0 ≤ 1` in any ordered ring. -/
protected zero_le_one : 0 ≤ (1 : R)
/-- The product of non-negative elements is non-negative. -/
protected mul_nonneg : ∀ a b : R, 0 ≤ a → 0 ≤ b → 0 ≤ a * b
set_option linter.deprecated false in
/-- An `OrderedCommRing` is a commutative ring with a partial order such that addition is monotone
and multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[CommRing R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedCommRing (R : Type u) extends OrderedRing R, CommRing R
set_option linter.deprecated false in
/-- A `StrictOrderedSemiring` is a nontrivial semiring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Semiring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedSemiring (R : Type u) extends Semiring R, OrderedCancelAddCommMonoid R,
Nontrivial R where
/-- In a strict ordered semiring, `0 ≤ 1`. -/
protected zero_le_one : (0 : R) ≤ 1
/-- Left multiplication by a positive element is strictly monotone. -/
protected mul_lt_mul_of_pos_left : ∀ a b c : R, a < b → 0 < c → c * a < c * b
/-- Right multiplication by a positive element is strictly monotone. -/
protected mul_lt_mul_of_pos_right : ∀ a b c : R, a < b → 0 < c → a * c < b * c
set_option linter.deprecated false in
/-- A `StrictOrderedCommSemiring` is a commutative semiring with a partial order such that
addition is strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedCommSemiring (R : Type u) extends StrictOrderedSemiring R, CommSemiring R
set_option linter.deprecated false in
/-- A `StrictOrderedRing` is a ring with a partial order such that addition is strictly monotone
and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Ring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedRing (R : Type u) extends Ring R, OrderedAddCommGroup R, Nontrivial R where
/-- In a strict ordered ring, `0 ≤ 1`. -/
protected zero_le_one : 0 ≤ (1 : R)
/-- The product of two positive elements is positive. -/
protected mul_pos : ∀ a b : R, 0 < a → 0 < b → 0 < a * b
set_option linter.deprecated false in
/-- A `StrictOrderedCommRing` is a commutative ring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommRing R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedCommRing (R : Type*) extends StrictOrderedRing R, CommRing R
/- It's not entirely clear we should assume `Nontrivial` at this point; it would be reasonable to
explore changing this, but be warned that the instances involving `Domain` may cause typeclass
search loops. -/
set_option linter.deprecated false in
/-- A `LinearOrderedSemiring` is a nontrivial semiring with a linear order such that
addition is monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Semiring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedSemiring (R : Type u) extends StrictOrderedSemiring R,
LinearOrderedAddCommMonoid R
set_option linter.deprecated false in
/-- A `LinearOrderedCommSemiring` is a nontrivial commutative semiring with a linear order such
that addition is monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommSemiring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommSemiring (R : Type*) extends StrictOrderedCommSemiring R,
LinearOrderedSemiring R
set_option linter.deprecated false in
/-- A `LinearOrderedRing` is a ring with a linear order such that addition is monotone and
multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Ring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedRing (R : Type u) extends StrictOrderedRing R, LinearOrder R
set_option linter.deprecated false in
/-- A `LinearOrderedCommRing` is a commutative ring with a linear order such that addition is
monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommRing R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommRing (R : Type u) extends LinearOrderedRing R, CommMonoid R
attribute [nolint docBlame]
StrictOrderedSemiring.toOrderedCancelAddCommMonoid
StrictOrderedCommSemiring.toCommSemiring
LinearOrderedSemiring.toLinearOrderedAddCommMonoid
LinearOrderedRing.toLinearOrder
OrderedSemiring.toOrderedAddCommMonoid
OrderedCommSemiring.toCommSemiring
StrictOrderedCommRing.toCommRing
OrderedRing.toOrderedAddCommGroup
OrderedCommRing.toCommRing
StrictOrderedRing.toOrderedAddCommGroup
LinearOrderedCommSemiring.toLinearOrderedSemiring
LinearOrderedCommRing.toCommMonoid
section OrderedRing
variable [Ring R] [PartialOrder R] [IsOrderedRing R] {a b c : R}
lemma one_add_le_one_sub_mul_one_add (h : a + b + b * c ≤ c) : 1 + a ≤ (1 - b) * (1 + c) := by
rw [one_sub_mul, mul_one_add, le_sub_iff_add_le, add_assoc, ← add_assoc a]
gcongr
lemma one_add_le_one_add_mul_one_sub (h : a + c + b * c ≤ b) : 1 + a ≤ (1 + b) * (1 - c) := by
rw [mul_one_sub, one_add_mul, le_sub_iff_add_le, add_assoc, ← add_assoc a]
gcongr
lemma one_sub_le_one_sub_mul_one_add (h : b + b * c ≤ a + c) : 1 - a ≤ (1 - b) * (1 + c) := by
rw [one_sub_mul, mul_one_add, sub_le_sub_iff, add_assoc, add_comm c]
gcongr
lemma one_sub_le_one_add_mul_one_sub (h : c + b * c ≤ a + b) : 1 - a ≤ (1 + b) * (1 - c) := by
rw [mul_one_sub, one_add_mul, sub_le_sub_iff, add_assoc, add_comm b]
gcongr
end OrderedRing
| Mathlib/Algebra/Order/Ring/Defs.lean | 1,209 | 1,213 | |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yury Kudryashov
-/
import Mathlib.MeasureTheory.OuterMeasure.Basic
/-!
# The “almost everywhere” filter of co-null sets.
If `μ` is an outer measure or a measure on `α`,
then `MeasureTheory.ae μ` is the filter of co-null sets: `s ∈ ae μ ↔ μ sᶜ = 0`.
In this file we define the filter and prove some basic theorems about it.
## Notation
- `∀ᵐ x ∂μ, p x`: the predicate `p` holds for `μ`-a.e. all `x`;
- `∃ᶠ x ∂μ, p x`: the predicate `p` holds on a set of nonzero measure;
- `f =ᵐ[μ] g`: `f x = g x` for `μ`-a.e. all `x`;
- `f ≤ᵐ[μ] g`: `f x ≤ g x` for `μ`-a.e. all `x`.
## Implementation details
All notation introduced in this file
reducibly unfolds to the corresponding definitions about filters,
so generic lemmas about `Filter.Eventually`, `Filter.EventuallyEq` etc apply.
However, we restate some lemmas specifically for `ae`.
## Tags
outer measure, measure, almost everywhere
-/
open Filter Set
open scoped ENNReal
namespace MeasureTheory
variable {α β F : Type*} [FunLike F (Set α) ℝ≥0∞] [OuterMeasureClass F α] {μ : F} {s t : Set α}
/-- The “almost everywhere” filter of co-null sets. -/
def ae (μ : F) : Filter α :=
.ofCountableUnion (μ · = 0) (fun _S hSc ↦ (measure_sUnion_null_iff hSc).2) fun _t ht _s hs ↦
measure_mono_null hs ht
/-- `∀ᵐ a ∂μ, p a` means that `p a` for a.e. `a`, i.e. `p` holds true away from a null set.
This is notation for `Filter.Eventually p (MeasureTheory.ae μ)`. -/
notation3 "∀ᵐ "(...)" ∂"μ", "r:(scoped p => Filter.Eventually p <| MeasureTheory.ae μ) => r
/-- `∃ᵐ a ∂μ, p a` means that `p` holds `∂μ`-frequently,
i.e. `p` holds on a set of positive measure.
This is notation for `Filter.Frequently p (MeasureTheory.ae μ)`. -/
notation3 "∃ᵐ "(...)" ∂"μ", "r:(scoped P => Filter.Frequently P <| MeasureTheory.ae μ) => r
/-- `f =ᵐ[μ] g` means `f` and `g` are eventually equal along the a.e. filter,
i.e. `f=g` away from a null set.
This is notation for `Filter.EventuallyEq (MeasureTheory.ae μ) f g`. -/
notation:50 f " =ᵐ[" μ:50 "] " g:50 => Filter.EventuallyEq (MeasureTheory.ae μ) f g
/-- `f ≤ᵐ[μ] g` means `f` is eventually less than `g` along the a.e. filter,
i.e. `f ≤ g` away from a null set.
This is notation for `Filter.EventuallyLE (MeasureTheory.ae μ) f g`. -/
notation:50 f " ≤ᵐ[" μ:50 "] " g:50 => Filter.EventuallyLE (MeasureTheory.ae μ) f g
theorem mem_ae_iff {s : Set α} : s ∈ ae μ ↔ μ sᶜ = 0 :=
Iff.rfl
theorem ae_iff {p : α → Prop} : (∀ᵐ a ∂μ, p a) ↔ μ { a | ¬p a } = 0 :=
Iff.rfl
theorem compl_mem_ae_iff {s : Set α} : sᶜ ∈ ae μ ↔ μ s = 0 := by simp only [mem_ae_iff, compl_compl]
theorem frequently_ae_iff {p : α → Prop} : (∃ᵐ a ∂μ, p a) ↔ μ { a | p a } ≠ 0 :=
not_congr compl_mem_ae_iff
theorem frequently_ae_mem_iff {s : Set α} : (∃ᵐ a ∂μ, a ∈ s) ↔ μ s ≠ 0 :=
not_congr compl_mem_ae_iff
theorem measure_zero_iff_ae_nmem {s : Set α} : μ s = 0 ↔ ∀ᵐ a ∂μ, a ∉ s :=
compl_mem_ae_iff.symm
theorem ae_of_all {p : α → Prop} (μ : F) : (∀ a, p a) → ∀ᵐ a ∂μ, p a :=
Eventually.of_forall
instance instCountableInterFilter : CountableInterFilter (ae μ) := by
unfold ae; infer_instance
theorem ae_all_iff {ι : Sort*} [Countable ι] {p : α → ι → Prop} :
(∀ᵐ a ∂μ, ∀ i, p a i) ↔ ∀ i, ∀ᵐ a ∂μ, p a i :=
eventually_countable_forall
theorem all_ae_of {ι : Sort*} {p : α → ι → Prop} (hp : ∀ᵐ a ∂μ, ∀ i, p a i) (i : ι) :
∀ᵐ a ∂μ, p a i := by
filter_upwards [hp] with a ha using ha i
lemma ae_iff_of_countable [Countable α] {p : α → Prop} : (∀ᵐ x ∂μ, p x) ↔ ∀ x, μ {x} ≠ 0 → p x := by
rw [ae_iff, measure_null_iff_singleton]
exacts [forall_congr' fun _ ↦ not_imp_comm, Set.to_countable _]
theorem ae_ball_iff {ι : Type*} {S : Set ι} (hS : S.Countable) {p : α → ∀ i ∈ S, Prop} :
(∀ᵐ x ∂μ, ∀ i (hi : i ∈ S), p x i hi) ↔ ∀ i (hi : i ∈ S), ∀ᵐ x ∂μ, p x i hi :=
eventually_countable_ball hS
lemma ae_eq_refl (f : α → β) : f =ᵐ[μ] f := EventuallyEq.rfl
lemma ae_eq_rfl {f : α → β} : f =ᵐ[μ] f := EventuallyEq.rfl
lemma ae_eq_comm {f g : α → β} : f =ᵐ[μ] g ↔ g =ᵐ[μ] f := eventuallyEq_comm
theorem ae_eq_symm {f g : α → β} (h : f =ᵐ[μ] g) : g =ᵐ[μ] f :=
h.symm
theorem ae_eq_trans {f g h : α → β} (h₁ : f =ᵐ[μ] g) (h₂ : g =ᵐ[μ] h) : f =ᵐ[μ] h :=
h₁.trans h₂
@[simp] lemma ae_eq_top : ae μ = ⊤ ↔ ∀ a, μ {a} ≠ 0 := by
simp only [Filter.ext_iff, mem_ae_iff, mem_top, ne_eq]
refine ⟨fun h a ha ↦ by simpa [ha] using (h {a}ᶜ).1, fun h s ↦ ⟨fun hs ↦ ?_, ?_⟩⟩
· rw [← compl_empty_iff, ← not_nonempty_iff_eq_empty]
rintro ⟨a, ha⟩
exact h _ <| measure_mono_null (singleton_subset_iff.2 ha) hs
· rintro rfl
simp
theorem ae_le_of_ae_lt {β : Type*} [Preorder β] {f g : α → β} (h : ∀ᵐ x ∂μ, f x < g x) :
f ≤ᵐ[μ] g :=
h.mono fun _ ↦ le_of_lt
@[simp]
theorem ae_eq_empty : s =ᵐ[μ] (∅ : Set α) ↔ μ s = 0 :=
eventuallyEq_empty.trans <| by simp only [ae_iff, Classical.not_not, setOf_mem_eq]
-- The priority should be higher than `eventuallyEq_univ`.
@[simp high]
theorem ae_eq_univ : s =ᵐ[μ] (univ : Set α) ↔ μ sᶜ = 0 :=
eventuallyEq_univ
theorem ae_le_set : s ≤ᵐ[μ] t ↔ μ (s \ t) = 0 :=
calc
s ≤ᵐ[μ] t ↔ ∀ᵐ x ∂μ, x ∈ s → x ∈ t := Iff.rfl
_ ↔ μ (s \ t) = 0 := by simp [ae_iff]; rfl
theorem ae_le_set_inter {s' t' : Set α} (h : s ≤ᵐ[μ] t) (h' : s' ≤ᵐ[μ] t') :
(s ∩ s' : Set α) ≤ᵐ[μ] (t ∩ t' : Set α) :=
h.inter h'
theorem ae_le_set_union {s' t' : Set α} (h : s ≤ᵐ[μ] t) (h' : s' ≤ᵐ[μ] t') :
(s ∪ s' : Set α) ≤ᵐ[μ] (t ∪ t' : Set α) :=
h.union h'
theorem union_ae_eq_right : (s ∪ t : Set α) =ᵐ[μ] t ↔ μ (s \ t) = 0 := by
simp [eventuallyLE_antisymm_iff, ae_le_set, union_diff_right,
diff_eq_empty.2 Set.subset_union_right]
theorem diff_ae_eq_self : (s \ t : Set α) =ᵐ[μ] s ↔ μ (s ∩ t) = 0 := by
simp [eventuallyLE_antisymm_iff, ae_le_set, diff_diff_right, diff_diff,
diff_eq_empty.2 Set.subset_union_right]
theorem diff_null_ae_eq_self (ht : μ t = 0) : (s \ t : Set α) =ᵐ[μ] s :=
diff_ae_eq_self.mpr (measure_mono_null inter_subset_right ht)
theorem ae_eq_set {s t : Set α} : s =ᵐ[μ] t ↔ μ (s \ t) = 0 ∧ μ (t \ s) = 0 := by
simp [eventuallyLE_antisymm_iff, ae_le_set]
open scoped symmDiff in
@[simp]
theorem measure_symmDiff_eq_zero_iff {s t : Set α} : μ (s ∆ t) = 0 ↔ s =ᵐ[μ] t := by
simp [ae_eq_set, symmDiff_def]
@[simp]
theorem ae_eq_set_compl_compl {s t : Set α} : sᶜ =ᵐ[μ] tᶜ ↔ s =ᵐ[μ] t := by
simp only [← measure_symmDiff_eq_zero_iff, compl_symmDiff_compl]
theorem ae_eq_set_compl {s t : Set α} : sᶜ =ᵐ[μ] t ↔ s =ᵐ[μ] tᶜ := by
rw [← ae_eq_set_compl_compl, compl_compl]
theorem ae_eq_set_inter {s' t' : Set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') :
(s ∩ s' : Set α) =ᵐ[μ] (t ∩ t' : Set α) :=
h.inter h'
theorem ae_eq_set_union {s' t' : Set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') :
(s ∪ s' : Set α) =ᵐ[μ] (t ∪ t' : Set α) :=
h.union h'
theorem ae_eq_set_diff {s' t' : Set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') :
s \ s' =ᵐ[μ] t \ t' :=
h.diff h'
open scoped symmDiff in
theorem ae_eq_set_symmDiff {s' t' : Set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') :
s ∆ s' =ᵐ[μ] t ∆ t' :=
h.symmDiff h'
theorem union_ae_eq_univ_of_ae_eq_univ_left (h : s =ᵐ[μ] univ) : (s ∪ t : Set α) =ᵐ[μ] univ :=
(ae_eq_set_union h (ae_eq_refl t)).trans <| by rw [univ_union]
theorem union_ae_eq_univ_of_ae_eq_univ_right (h : t =ᵐ[μ] univ) : (s ∪ t : Set α) =ᵐ[μ] univ := by
convert ae_eq_set_union (ae_eq_refl s) h
rw [union_univ]
theorem union_ae_eq_right_of_ae_eq_empty (h : s =ᵐ[μ] (∅ : Set α)) : (s ∪ t : Set α) =ᵐ[μ] t := by
convert ae_eq_set_union h (ae_eq_refl t)
rw [empty_union]
theorem union_ae_eq_left_of_ae_eq_empty (h : t =ᵐ[μ] (∅ : Set α)) : (s ∪ t : Set α) =ᵐ[μ] s := by
convert ae_eq_set_union (ae_eq_refl s) h
rw [union_empty]
theorem inter_ae_eq_right_of_ae_eq_univ (h : s =ᵐ[μ] univ) : (s ∩ t : Set α) =ᵐ[μ] t := by
convert ae_eq_set_inter h (ae_eq_refl t)
rw [univ_inter]
theorem inter_ae_eq_left_of_ae_eq_univ (h : t =ᵐ[μ] univ) : (s ∩ t : Set α) =ᵐ[μ] s := by
convert ae_eq_set_inter (ae_eq_refl s) h
rw [inter_univ]
theorem inter_ae_eq_empty_of_ae_eq_empty_left (h : s =ᵐ[μ] (∅ : Set α)) :
(s ∩ t : Set α) =ᵐ[μ] (∅ : Set α) := by
convert ae_eq_set_inter h (ae_eq_refl t)
rw [empty_inter]
theorem inter_ae_eq_empty_of_ae_eq_empty_right (h : t =ᵐ[μ] (∅ : Set α)) :
(s ∩ t : Set α) =ᵐ[μ] (∅ : Set α) := by
convert ae_eq_set_inter (ae_eq_refl s) h
rw [inter_empty]
@[to_additive]
| theorem _root_.Set.mulIndicator_ae_eq_one {M : Type*} [One M] {f : α → M} {s : Set α} :
s.mulIndicator f =ᵐ[μ] 1 ↔ μ (s ∩ f.mulSupport) = 0 := by
simp [EventuallyEq, eventually_iff, ae, compl_setOf]; rfl
| Mathlib/MeasureTheory/OuterMeasure/AE.lean | 231 | 233 |
/-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best, Xavier Roblot
-/
import Mathlib.Algebra.Algebra.Hom.Rat
import Mathlib.Analysis.Complex.Polynomial.Basic
import Mathlib.NumberTheory.NumberField.Norm
import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots
import Mathlib.Topology.Instances.Complex
/-!
# Embeddings of number fields
This file defines the embeddings of a number field into an algebraic closed field.
## Main Definitions and Results
* `NumberField.Embeddings.range_eval_eq_rootSet_minpoly`: let `x ∈ K` with `K` number field and
let `A` be an algebraic closed field of char. 0, then the images of `x` by the embeddings of `K`
in `A` are exactly the roots in `A` of the minimal polynomial of `x` over `ℚ`.
* `NumberField.Embeddings.pow_eq_one_of_norm_eq_one`: an algebraic integer whose conjugates are
all of norm one is a root of unity.
* `NumberField.InfinitePlace`: the type of infinite places of a number field `K`.
* `NumberField.InfinitePlace.mk_eq_iff`: two complex embeddings define the same infinite place iff
they are equal or complex conjugates.
* `NumberField.InfinitePlace.prod_eq_abs_norm`: the infinite part of the product formula, that is
for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where the product is over the infinite place `w` and
`‖·‖_w` is the normalized absolute value for `w`.
## Tags
number field, embeddings, places, infinite places
-/
open scoped Finset
namespace NumberField.Embeddings
section Fintype
open Module
variable (K : Type*) [Field K] [NumberField K]
variable (A : Type*) [Field A] [CharZero A]
/-- There are finitely many embeddings of a number field. -/
noncomputable instance : Fintype (K →+* A) :=
Fintype.ofEquiv (K →ₐ[ℚ] A) RingHom.equivRatAlgHom.symm
variable [IsAlgClosed A]
/-- The number of embeddings of a number field is equal to its finrank. -/
theorem card : Fintype.card (K →+* A) = finrank ℚ K := by
rw [Fintype.ofEquiv_card RingHom.equivRatAlgHom.symm, AlgHom.card]
instance : Nonempty (K →+* A) := by
rw [← Fintype.card_pos_iff, NumberField.Embeddings.card K A]
exact Module.finrank_pos
end Fintype
section Roots
open Set Polynomial
variable (K A : Type*) [Field K] [NumberField K] [Field A] [Algebra ℚ A] [IsAlgClosed A] (x : K)
/-- Let `A` be an algebraically closed field and let `x ∈ K`, with `K` a number field.
The images of `x` by the embeddings of `K` in `A` are exactly the roots in `A` of
the minimal polynomial of `x` over `ℚ`. -/
theorem range_eval_eq_rootSet_minpoly :
(range fun φ : K →+* A => φ x) = (minpoly ℚ x).rootSet A := by
convert (NumberField.isAlgebraic K).range_eval_eq_rootSet_minpoly A x using 1
ext a
exact ⟨fun ⟨φ, hφ⟩ => ⟨φ.toRatAlgHom, hφ⟩, fun ⟨φ, hφ⟩ => ⟨φ.toRingHom, hφ⟩⟩
end Roots
section Bounded
open Module Polynomial Set
variable {K : Type*} [Field K] [NumberField K]
variable {A : Type*} [NormedField A] [IsAlgClosed A] [NormedAlgebra ℚ A]
theorem coeff_bdd_of_norm_le {B : ℝ} {x : K} (h : ∀ φ : K →+* A, ‖φ x‖ ≤ B) (i : ℕ) :
‖(minpoly ℚ x).coeff i‖ ≤ max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2) := by
have hx := Algebra.IsSeparable.isIntegral ℚ x
rw [← norm_algebraMap' A, ← coeff_map (algebraMap ℚ A)]
refine coeff_bdd_of_roots_le _ (minpoly.monic hx)
(IsAlgClosed.splits_codomain _) (minpoly.natDegree_le x) (fun z hz => ?_) i
classical
rw [← Multiset.mem_toFinset] at hz
obtain ⟨φ, rfl⟩ := (range_eval_eq_rootSet_minpoly K A x).symm.subset hz
exact h φ
variable (K A)
/-- Let `B` be a real number. The set of algebraic integers in `K` whose conjugates are all
smaller in norm than `B` is finite. -/
theorem finite_of_norm_le (B : ℝ) : {x : K | IsIntegral ℤ x ∧ ∀ φ : K →+* A, ‖φ x‖ ≤ B}.Finite := by
classical
let C := Nat.ceil (max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2))
have := bUnion_roots_finite (algebraMap ℤ K) (finrank ℚ K) (finite_Icc (-C : ℤ) C)
refine this.subset fun x hx => ?_; simp_rw [mem_iUnion]
have h_map_ℚ_minpoly := minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hx.1
refine ⟨_, ⟨?_, fun i => ?_⟩, mem_rootSet.2 ⟨minpoly.ne_zero hx.1, minpoly.aeval ℤ x⟩⟩
· rw [← (minpoly.monic hx.1).natDegree_map (algebraMap ℤ ℚ), ← h_map_ℚ_minpoly]
exact minpoly.natDegree_le x
rw [mem_Icc, ← abs_le, ← @Int.cast_le ℝ]
refine (Eq.trans_le ?_ <| coeff_bdd_of_norm_le hx.2 i).trans (Nat.le_ceil _)
rw [h_map_ℚ_minpoly, coeff_map, eq_intCast, Int.norm_cast_rat, Int.norm_eq_abs, Int.cast_abs]
/-- An algebraic integer whose conjugates are all of norm one is a root of unity. -/
theorem pow_eq_one_of_norm_eq_one {x : K} (hxi : IsIntegral ℤ x) (hx : ∀ φ : K →+* A, ‖φ x‖ = 1) :
∃ (n : ℕ) (_ : 0 < n), x ^ n = 1 := by
obtain ⟨a, -, b, -, habne, h⟩ :=
@Set.Infinite.exists_ne_map_eq_of_mapsTo _ _ _ _ (x ^ · : ℕ → K) Set.infinite_univ
(by exact fun a _ => ⟨hxi.pow a, fun φ => by simp [hx φ]⟩) (finite_of_norm_le K A (1 : ℝ))
wlog hlt : b < a
· exact this K A hxi hx b a habne.symm h.symm (habne.lt_or_lt.resolve_right hlt)
refine ⟨a - b, tsub_pos_of_lt hlt, ?_⟩
rw [← Nat.sub_add_cancel hlt.le, pow_add, mul_left_eq_self₀] at h
refine h.resolve_right fun hp => ?_
specialize hx (IsAlgClosed.lift (R := ℚ)).toRingHom
rw [pow_eq_zero hp, map_zero, norm_zero] at hx; norm_num at hx
end Bounded
end NumberField.Embeddings
section Place
variable {K : Type*} [Field K] {A : Type*} [NormedDivisionRing A] [Nontrivial A] (φ : K →+* A)
/-- An embedding into a normed division ring defines a place of `K` -/
def NumberField.place : AbsoluteValue K ℝ :=
(IsAbsoluteValue.toAbsoluteValue (norm : A → ℝ)).comp φ.injective
@[simp]
theorem NumberField.place_apply (x : K) : (NumberField.place φ) x = norm (φ x) := rfl
end Place
namespace NumberField.ComplexEmbedding
open Complex NumberField
open scoped ComplexConjugate
variable {K : Type*} [Field K] {k : Type*} [Field k]
variable (K) in
/--
A (random) lift of the complex embedding `φ : k →+* ℂ` to an extension `K` of `k`.
-/
noncomputable def lift [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) : K →+* ℂ := by
letI := φ.toAlgebra
exact (IsAlgClosed.lift (R := k)).toRingHom
@[simp]
theorem lift_comp_algebraMap [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) :
(lift K φ).comp (algebraMap k K) = φ := by
unfold lift
letI := φ.toAlgebra
rw [AlgHom.toRingHom_eq_coe, AlgHom.comp_algebraMap_of_tower, RingHom.algebraMap_toAlgebra']
@[simp]
theorem lift_algebraMap_apply [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) (x : k) :
lift K φ (algebraMap k K x) = φ x :=
RingHom.congr_fun (lift_comp_algebraMap φ) x
/-- The conjugate of a complex embedding as a complex embedding. -/
abbrev conjugate (φ : K →+* ℂ) : K →+* ℂ := star φ
@[simp]
theorem conjugate_coe_eq (φ : K →+* ℂ) (x : K) : (conjugate φ) x = conj (φ x) := rfl
theorem place_conjugate (φ : K →+* ℂ) : place (conjugate φ) = place φ := by
ext; simp only [place_apply, norm_conj, conjugate_coe_eq]
/-- An embedding into `ℂ` is real if it is fixed by complex conjugation. -/
abbrev IsReal (φ : K →+* ℂ) : Prop := IsSelfAdjoint φ
theorem isReal_iff {φ : K →+* ℂ} : IsReal φ ↔ conjugate φ = φ := isSelfAdjoint_iff
theorem isReal_conjugate_iff {φ : K →+* ℂ} : IsReal (conjugate φ) ↔ IsReal φ :=
IsSelfAdjoint.star_iff
/-- A real embedding as a ring homomorphism from `K` to `ℝ` . -/
def IsReal.embedding {φ : K →+* ℂ} (hφ : IsReal φ) : K →+* ℝ where
toFun x := (φ x).re
map_one' := by simp only [map_one, one_re]
map_mul' := by
simp only [Complex.conj_eq_iff_im.mp (RingHom.congr_fun hφ _), map_mul, mul_re,
mul_zero, tsub_zero, eq_self_iff_true, forall_const]
map_zero' := by simp only [map_zero, zero_re]
map_add' := by simp only [map_add, add_re, eq_self_iff_true, forall_const]
@[simp]
theorem IsReal.coe_embedding_apply {φ : K →+* ℂ} (hφ : IsReal φ) (x : K) :
(hφ.embedding x : ℂ) = φ x := by
apply Complex.ext
· rfl
· rw [ofReal_im, eq_comm, ← Complex.conj_eq_iff_im]
exact RingHom.congr_fun hφ x
lemma IsReal.comp (f : k →+* K) {φ : K →+* ℂ} (hφ : IsReal φ) :
IsReal (φ.comp f) := by ext1 x; simpa using RingHom.congr_fun hφ (f x)
lemma isReal_comp_iff {f : k ≃+* K} {φ : K →+* ℂ} :
IsReal (φ.comp (f : k →+* K)) ↔ IsReal φ :=
⟨fun H ↦ by convert H.comp f.symm.toRingHom; ext1; simp, IsReal.comp _⟩
lemma exists_comp_symm_eq_of_comp_eq [Algebra k K] [IsGalois k K] (φ ψ : K →+* ℂ)
(h : φ.comp (algebraMap k K) = ψ.comp (algebraMap k K)) :
∃ σ : K ≃ₐ[k] K, φ.comp σ.symm = ψ := by
letI := (φ.comp (algebraMap k K)).toAlgebra
letI := φ.toAlgebra
have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl
let ψ' : K →ₐ[k] ℂ := { ψ with commutes' := fun r ↦ (RingHom.congr_fun h r).symm }
use (AlgHom.restrictNormal' ψ' K).symm
ext1 x
exact AlgHom.restrictNormal_commutes ψ' K x
variable [Algebra k K] (φ : K →+* ℂ) (σ : K ≃ₐ[k] K)
/--
`IsConj φ σ` states that `σ : K ≃ₐ[k] K` is the conjugation under the embedding `φ : K →+* ℂ`.
-/
def IsConj : Prop := conjugate φ = φ.comp σ
variable {φ σ}
lemma IsConj.eq (h : IsConj φ σ) (x) : φ (σ x) = star (φ x) := RingHom.congr_fun h.symm x
lemma IsConj.ext {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) (h₂ : IsConj φ σ₂) : σ₁ = σ₂ :=
AlgEquiv.ext fun x ↦ φ.injective ((h₁.eq x).trans (h₂.eq x).symm)
lemma IsConj.ext_iff {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) : σ₁ = σ₂ ↔ IsConj φ σ₂ :=
⟨fun e ↦ e ▸ h₁, h₁.ext⟩
lemma IsConj.isReal_comp (h : IsConj φ σ) : IsReal (φ.comp (algebraMap k K)) := by
ext1 x
simp only [conjugate_coe_eq, RingHom.coe_comp, Function.comp_apply, ← h.eq,
starRingEnd_apply, AlgEquiv.commutes]
lemma isConj_one_iff : IsConj φ (1 : K ≃ₐ[k] K) ↔ IsReal φ := Iff.rfl
alias ⟨_, IsReal.isConjGal_one⟩ := ComplexEmbedding.isConj_one_iff
lemma IsConj.symm (hσ : IsConj φ σ) :
IsConj φ σ.symm := RingHom.ext fun x ↦ by simpa using congr_arg star (hσ.eq (σ.symm x))
lemma isConj_symm : IsConj φ σ.symm ↔ IsConj φ σ :=
⟨IsConj.symm, IsConj.symm⟩
end NumberField.ComplexEmbedding
section InfinitePlace
open NumberField
variable {k : Type*} [Field k] (K : Type*) [Field K] {F : Type*} [Field F]
/-- An infinite place of a number field `K` is a place associated to a complex embedding. -/
def NumberField.InfinitePlace := { w : AbsoluteValue K ℝ // ∃ φ : K →+* ℂ, place φ = w }
instance [NumberField K] : Nonempty (NumberField.InfinitePlace K) := Set.instNonemptyRange _
variable {K}
/-- Return the infinite place defined by a complex embedding `φ`. -/
noncomputable def NumberField.InfinitePlace.mk (φ : K →+* ℂ) : NumberField.InfinitePlace K :=
⟨place φ, ⟨φ, rfl⟩⟩
namespace NumberField.InfinitePlace
open NumberField
instance {K : Type*} [Field K] : FunLike (InfinitePlace K) K ℝ where
coe w x := w.1 x
coe_injective' _ _ h := Subtype.eq (AbsoluteValue.ext fun x => congr_fun h x)
lemma coe_apply {K : Type*} [Field K] (v : InfinitePlace K) (x : K) :
v x = v.1 x := rfl
@[ext]
lemma ext {K : Type*} [Field K] (v₁ v₂ : InfinitePlace K) (h : ∀ k, v₁ k = v₂ k) : v₁ = v₂ :=
Subtype.ext <| AbsoluteValue.ext h
instance : MonoidWithZeroHomClass (InfinitePlace K) K ℝ where
map_mul w _ _ := w.1.map_mul _ _
map_one w := w.1.map_one
map_zero w := w.1.map_zero
instance : NonnegHomClass (InfinitePlace K) K ℝ where
apply_nonneg w _ := w.1.nonneg _
@[simp]
theorem apply (φ : K →+* ℂ) (x : K) : (mk φ) x = ‖φ x‖ := rfl
/-- For an infinite place `w`, return an embedding `φ` such that `w = infinite_place φ` . -/
noncomputable def embedding (w : InfinitePlace K) : K →+* ℂ := w.2.choose
@[simp]
theorem mk_embedding (w : InfinitePlace K) : mk (embedding w) = w := Subtype.ext w.2.choose_spec
@[simp]
theorem mk_conjugate_eq (φ : K →+* ℂ) : mk (ComplexEmbedding.conjugate φ) = mk φ := by
refine DFunLike.ext _ _ (fun x => ?_)
rw [apply, apply, ComplexEmbedding.conjugate_coe_eq, Complex.norm_conj]
theorem norm_embedding_eq (w : InfinitePlace K) (x : K) :
‖(embedding w) x‖ = w x := by
nth_rewrite 2 [← mk_embedding w]
rfl
theorem eq_iff_eq (x : K) (r : ℝ) : (∀ w : InfinitePlace K, w x = r) ↔ ∀ φ : K →+* ℂ, ‖φ x‖ = r :=
⟨fun hw φ => hw (mk φ), by rintro hφ ⟨w, ⟨φ, rfl⟩⟩; exact hφ φ⟩
theorem le_iff_le (x : K) (r : ℝ) : (∀ w : InfinitePlace K, w x ≤ r) ↔ ∀ φ : K →+* ℂ, ‖φ x‖ ≤ r :=
⟨fun hw φ => hw (mk φ), by rintro hφ ⟨w, ⟨φ, rfl⟩⟩; exact hφ φ⟩
theorem pos_iff {w : InfinitePlace K} {x : K} : 0 < w x ↔ x ≠ 0 := AbsoluteValue.pos_iff w.1
@[simp]
theorem mk_eq_iff {φ ψ : K →+* ℂ} : mk φ = mk ψ ↔ φ = ψ ∨ ComplexEmbedding.conjugate φ = ψ := by
constructor
· -- We prove that the map ψ ∘ φ⁻¹ between φ(K) and ℂ is uniform continuous, thus it is either the
-- inclusion or the complex conjugation using `Complex.uniformContinuous_ringHom_eq_id_or_conj`
intro h₀
obtain ⟨j, hiφ⟩ := (φ.injective).hasLeftInverse
let ι := RingEquiv.ofLeftInverse hiφ
have hlip : LipschitzWith 1 (RingHom.comp ψ ι.symm.toRingHom) := by
change LipschitzWith 1 (ψ ∘ ι.symm)
apply LipschitzWith.of_dist_le_mul
intro x y
rw [NNReal.coe_one, one_mul, NormedField.dist_eq, Function.comp_apply, Function.comp_apply,
← map_sub, ← map_sub]
apply le_of_eq
suffices ‖φ (ι.symm (x - y))‖ = ‖ψ (ι.symm (x - y))‖ by
rw [← this, ← RingEquiv.ofLeftInverse_apply hiφ _, RingEquiv.apply_symm_apply ι _]
rfl
exact congrFun (congrArg (↑) h₀) _
cases
Complex.uniformContinuous_ringHom_eq_id_or_conj φ.fieldRange hlip.uniformContinuous with
| inl h =>
left; ext1 x
conv_rhs => rw [← hiφ x]
exact (congrFun h (ι x)).symm
| inr h =>
right; ext1 x
conv_rhs => rw [← hiφ x]
exact (congrFun h (ι x)).symm
· rintro (⟨h⟩ | ⟨h⟩)
· exact congr_arg mk h
· rw [← mk_conjugate_eq]
exact congr_arg mk h
/-- An infinite place is real if it is defined by a real embedding. -/
def IsReal (w : InfinitePlace K) : Prop := ∃ φ : K →+* ℂ, ComplexEmbedding.IsReal φ ∧ mk φ = w
/-- An infinite place is complex if it is defined by a complex (ie. not real) embedding. -/
def IsComplex (w : InfinitePlace K) : Prop := ∃ φ : K →+* ℂ, ¬ComplexEmbedding.IsReal φ ∧ mk φ = w
theorem embedding_mk_eq (φ : K →+* ℂ) :
embedding (mk φ) = φ ∨ embedding (mk φ) = ComplexEmbedding.conjugate φ := by
rw [@eq_comm _ _ φ, @eq_comm _ _ (ComplexEmbedding.conjugate φ), ← mk_eq_iff, mk_embedding]
@[simp]
theorem embedding_mk_eq_of_isReal {φ : K →+* ℂ} (h : ComplexEmbedding.IsReal φ) :
embedding (mk φ) = φ := by
have := embedding_mk_eq φ
rwa [ComplexEmbedding.isReal_iff.mp h, or_self] at this
theorem isReal_iff {w : InfinitePlace K} :
IsReal w ↔ ComplexEmbedding.IsReal (embedding w) := by
refine ⟨?_, fun h => ⟨embedding w, h, mk_embedding w⟩⟩
rintro ⟨φ, ⟨hφ, rfl⟩⟩
rwa [embedding_mk_eq_of_isReal hφ]
theorem isComplex_iff {w : InfinitePlace K} :
IsComplex w ↔ ¬ComplexEmbedding.IsReal (embedding w) := by
refine ⟨?_, fun h => ⟨embedding w, h, mk_embedding w⟩⟩
rintro ⟨φ, ⟨hφ, rfl⟩⟩
contrapose! hφ
cases mk_eq_iff.mp (mk_embedding (mk φ)) with
| inl h => rwa [h] at hφ
| inr h => rwa [← ComplexEmbedding.isReal_conjugate_iff, h] at hφ
@[simp]
theorem conjugate_embedding_eq_of_isReal {w : InfinitePlace K} (h : IsReal w) :
ComplexEmbedding.conjugate (embedding w) = embedding w :=
ComplexEmbedding.isReal_iff.mpr (isReal_iff.mp h)
@[simp]
theorem not_isReal_iff_isComplex {w : InfinitePlace K} : ¬IsReal w ↔ IsComplex w := by
rw [isComplex_iff, isReal_iff]
@[simp]
theorem not_isComplex_iff_isReal {w : InfinitePlace K} : ¬IsComplex w ↔ IsReal w := by
rw [isComplex_iff, isReal_iff, not_not]
theorem isReal_or_isComplex (w : InfinitePlace K) : IsReal w ∨ IsComplex w := by
rw [← not_isReal_iff_isComplex]; exact em _
theorem ne_of_isReal_isComplex {w w' : InfinitePlace K} (h : IsReal w) (h' : IsComplex w') :
w ≠ w' := fun h_eq ↦ not_isReal_iff_isComplex.mpr h' (h_eq ▸ h)
variable (K) in
theorem disjoint_isReal_isComplex :
Disjoint {(w : InfinitePlace K) | IsReal w} {(w : InfinitePlace K) | IsComplex w} :=
Set.disjoint_iff.2 <| fun _ hw ↦ not_isReal_iff_isComplex.2 hw.2 hw.1
/-- The real embedding associated to a real infinite place. -/
noncomputable def embedding_of_isReal {w : InfinitePlace K} (hw : IsReal w) : K →+* ℝ :=
ComplexEmbedding.IsReal.embedding (isReal_iff.mp hw)
@[simp]
theorem embedding_of_isReal_apply {w : InfinitePlace K} (hw : IsReal w) (x : K) :
((embedding_of_isReal hw) x : ℂ) = (embedding w) x :=
ComplexEmbedding.IsReal.coe_embedding_apply (isReal_iff.mp hw) x
theorem norm_embedding_of_isReal {w : InfinitePlace K} (hw : IsReal w) (x : K) :
‖embedding_of_isReal hw x‖ = w x := by
rw [← norm_embedding_eq, ← embedding_of_isReal_apply hw, Complex.norm_real]
@[simp]
theorem isReal_of_mk_isReal {φ : K →+* ℂ} (h : IsReal (mk φ)) :
ComplexEmbedding.IsReal φ := by
contrapose! h
rw [not_isReal_iff_isComplex]
exact ⟨φ, h, rfl⟩
lemma isReal_mk_iff {φ : K →+* ℂ} :
IsReal (mk φ) ↔ ComplexEmbedding.IsReal φ :=
⟨isReal_of_mk_isReal, fun H ↦ ⟨_, H, rfl⟩⟩
lemma isComplex_mk_iff {φ : K →+* ℂ} :
IsComplex (mk φ) ↔ ¬ ComplexEmbedding.IsReal φ :=
not_isReal_iff_isComplex.symm.trans isReal_mk_iff.not
@[simp]
theorem not_isReal_of_mk_isComplex {φ : K →+* ℂ} (h : IsComplex (mk φ)) :
¬ ComplexEmbedding.IsReal φ := by rwa [← isComplex_mk_iff]
open scoped Classical in
/-- The multiplicity of an infinite place, that is the number of distinct complex embeddings that
define it, see `card_filter_mk_eq`. -/
noncomputable def mult (w : InfinitePlace K) : ℕ := if (IsReal w) then 1 else 2
@[simp]
theorem mult_isReal (w : {w : InfinitePlace K // IsReal w}) :
mult w.1 = 1 := by
rw [mult, if_pos w.prop]
@[simp]
theorem mult_isComplex (w : {w : InfinitePlace K // IsComplex w}) :
mult w.1 = 2 := by
rw [mult, if_neg (not_isReal_iff_isComplex.mpr w.prop)]
theorem mult_pos {w : InfinitePlace K} : 0 < mult w := by
rw [mult]
split_ifs <;> norm_num
@[simp]
theorem mult_ne_zero {w : InfinitePlace K} : mult w ≠ 0 := ne_of_gt mult_pos
theorem mult_coe_ne_zero {w : InfinitePlace K} : (mult w : ℝ) ≠ 0 :=
Nat.cast_ne_zero.mpr mult_ne_zero
theorem one_le_mult {w : InfinitePlace K} : (1 : ℝ) ≤ mult w := by
rw [← Nat.cast_one, Nat.cast_le]
exact mult_pos
open scoped Classical in
theorem card_filter_mk_eq [NumberField K] (w : InfinitePlace K) : #{φ | mk φ = w} = mult w := by
conv_lhs =>
congr; congr; ext
rw [← mk_embedding w, mk_eq_iff, ComplexEmbedding.conjugate, star_involutive.eq_iff]
simp_rw [Finset.filter_or, Finset.filter_eq' _ (embedding w),
Finset.filter_eq' _ (ComplexEmbedding.conjugate (embedding w)),
Finset.mem_univ, ite_true, mult]
split_ifs with hw
· rw [ComplexEmbedding.isReal_iff.mp (isReal_iff.mp hw), Finset.union_idempotent,
Finset.card_singleton]
· refine Finset.card_pair ?_
rwa [Ne, eq_comm, ← ComplexEmbedding.isReal_iff, ← isReal_iff]
open scoped Classical in
noncomputable instance NumberField.InfinitePlace.fintype [NumberField K] :
Fintype (InfinitePlace K) := Set.fintypeRange _
open scoped Classical in
@[to_additive]
theorem prod_eq_prod_mul_prod {α : Type*} [CommMonoid α] [NumberField K] (f : InfinitePlace K → α) :
∏ w, f w = (∏ w : {w // IsReal w}, f w.1) * (∏ w : {w // IsComplex w}, f w.1) := by
rw [← Equiv.prod_comp (Equiv.subtypeEquivRight (fun _ ↦ not_isReal_iff_isComplex))]
simp [Fintype.prod_subtype_mul_prod_subtype]
theorem sum_mult_eq [NumberField K] :
∑ w : InfinitePlace K, mult w = Module.finrank ℚ K := by
classical
rw [← Embeddings.card K ℂ, Fintype.card, Finset.card_eq_sum_ones, ← Finset.univ.sum_fiberwise
(fun φ => InfinitePlace.mk φ)]
exact Finset.sum_congr rfl
(fun _ _ => by rw [Finset.sum_const, smul_eq_mul, mul_one, card_filter_mk_eq])
/-- The map from real embeddings to real infinite places as an equiv -/
noncomputable def mkReal :
{ φ : K →+* ℂ // ComplexEmbedding.IsReal φ } ≃ { w : InfinitePlace K // IsReal w } := by
refine (Equiv.ofBijective (fun φ => ⟨mk φ, ?_⟩) ⟨fun φ ψ h => ?_, fun w => ?_⟩)
· exact ⟨φ, φ.prop, rfl⟩
· rwa [Subtype.mk.injEq, mk_eq_iff, ComplexEmbedding.isReal_iff.mp φ.prop, or_self,
← Subtype.ext_iff] at h
· exact ⟨⟨embedding w, isReal_iff.mp w.prop⟩, by simp⟩
/-- The map from nonreal embeddings to complex infinite places -/
noncomputable def mkComplex :
{ φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ } → { w : InfinitePlace K // IsComplex w } :=
Subtype.map mk fun φ hφ => ⟨φ, hφ, rfl⟩
@[simp]
theorem mkReal_coe (φ : { φ : K →+* ℂ // ComplexEmbedding.IsReal φ }) :
(mkReal φ : InfinitePlace K) = mk (φ : K →+* ℂ) := rfl
@[simp]
theorem mkComplex_coe (φ : { φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ }) :
(mkComplex φ : InfinitePlace K) = mk (φ : K →+* ℂ) := rfl
section NumberField
variable [NumberField K]
/-- The infinite part of the product formula : for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where
`‖·‖_w` is the normalized absolute value for `w`. -/
theorem prod_eq_abs_norm (x : K) :
∏ w : InfinitePlace K, w x ^ mult w = abs (Algebra.norm ℚ x) := by
| classical
convert (congr_arg (‖·‖) (@Algebra.norm_eq_prod_embeddings ℚ _ _ _ _ ℂ _ _ _ _ _ x)).symm
· rw [norm_prod, ← Fintype.prod_equiv RingHom.equivRatAlgHom (fun f => ‖f x‖)
(fun φ => ‖φ x‖) fun _ => by simp [RingHom.equivRatAlgHom_apply]]
rw [← Finset.prod_fiberwise Finset.univ mk (fun φ => ‖φ x‖)]
have (w : InfinitePlace K) (φ) (hφ : φ ∈ ({φ | mk φ = w} : Finset _)) :
‖φ x‖ = w x := by rw [← (Finset.mem_filter.mp hφ).2, apply]
simp_rw [Finset.prod_congr rfl (this _), Finset.prod_const, card_filter_mk_eq]
· rw [eq_ratCast, Rat.cast_abs, ← Real.norm_eq_abs, ← Complex.norm_real, Complex.ofReal_ratCast]
theorem one_le_of_lt_one {w : InfinitePlace K} {a : (𝓞 K)} (ha : a ≠ 0)
(h : ∀ ⦃z⦄, z ≠ w → z a < 1) : 1 ≤ w a := by
suffices (1 : ℝ) ≤ |Algebra.norm ℚ (a : K)| by
| Mathlib/NumberTheory/NumberField/Embeddings.lean | 538 | 550 |
/-
Copyright (c) 2021 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import Mathlib.Algebra.CharP.Algebra
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Algebra.CharP.Lemmas
import Mathlib.Algebra.EuclideanDomain.Field
import Mathlib.Algebra.Field.ZMod
import Mathlib.Algebra.Polynomial.Roots
import Mathlib.RingTheory.Polynomial.Chebyshev
/-!
# Dickson polynomials
The (generalised) Dickson polynomials are a family of polynomials indexed by `ℕ × ℕ`,
with coefficients in a commutative ring `R` depending on an element `a∈R`. More precisely, the
they satisfy the recursion `dickson k a (n + 2) = X * (dickson k a n + 1) - a * (dickson k a n)`
with starting values `dickson k a 0 = 3 - k` and `dickson k a 1 = X`. In the literature,
`dickson k a n` is called the `n`-th Dickson polynomial of the `k`-th kind associated to the
parameter `a : R`. They are closely related to the Chebyshev polynomials in the case that `a=1`.
When `a=0` they are just the family of monomials `X ^ n`.
## Main definition
* `Polynomial.dickson`: the generalised Dickson polynomials.
## Main statements
* `Polynomial.dickson_one_one_mul`, the `(m * n)`-th Dickson polynomial of the first kind for
parameter `1 : R` is the composition of the `m`-th and `n`-th Dickson polynomials of the first
kind for `1 : R`.
* `Polynomial.dickson_one_one_charP`, for a prime number `p`, the `p`-th Dickson polynomial of the
first kind associated to parameter `1 : R` is congruent to `X ^ p` modulo `p`.
## References
* [R. Lidl, G. L. Mullen and G. Turnwald, _Dickson polynomials_][MR1237403]
## TODO
* Redefine `dickson` in terms of `LinearRecurrence`.
* Show that `dickson 2 1` is equal to the characteristic polynomial of the adjacency matrix of a
type A Dynkin diagram.
* Prove that the adjacency matrices of simply laced Dynkin diagrams are precisely the adjacency
matrices of simple connected graphs which annihilate `dickson 2 1`.
-/
noncomputable section
namespace Polynomial
variable {R S : Type*} [CommRing R] [CommRing S] (k : ℕ) (a : R)
/-- `dickson` is the `n`-th (generalised) Dickson polynomial of the `k`-th kind associated to the
element `a ∈ R`. -/
noncomputable def dickson : ℕ → R[X]
| 0 => 3 - k
| 1 => X
| n + 2 => X * dickson (n + 1) - C a * dickson n
@[simp]
theorem dickson_zero : dickson k a 0 = 3 - k :=
rfl
@[simp]
theorem dickson_one : dickson k a 1 = X :=
rfl
theorem dickson_two : dickson k a 2 = X ^ 2 - C a * (3 - k : R[X]) := by
simp only [dickson, sq]
@[simp]
theorem dickson_add_two (n : ℕ) :
dickson k a (n + 2) = X * dickson k a (n + 1) - C a * dickson k a n := by rw [dickson]
theorem dickson_of_two_le {n : ℕ} (h : 2 ≤ n) :
dickson k a n = X * dickson k a (n - 1) - C a * dickson k a (n - 2) := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_add_of_le h
rw [add_comm]
exact dickson_add_two k a n
variable {k a}
|
theorem map_dickson (f : R →+* S) : ∀ n : ℕ, map f (dickson k a n) = dickson k (f a) n
| 0 => by
simp_rw [dickson_zero, Polynomial.map_sub, Polynomial.map_natCast, Polynomial.map_ofNat]
| 1 => by simp only [dickson_one, map_X]
| Mathlib/RingTheory/Polynomial/Dickson.lean | 86 | 90 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.