Context stringlengths 285 157k | file_name stringlengths 21 79 | start int64 14 3.67k | end int64 18 3.69k | theorem stringlengths 25 2.71k | proof stringlengths 5 10.6k |
|---|---|---|---|---|---|
/-
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, Floris van Doorn
-/
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Finsupp.Defs
import Mathlib.Data.Nat.Cast.Order
import Mathlib.Data.Set.Countable
import Mathlib.Logic.Small.Set
import Mathlib.Order.SuccPred.CompleteLinearOrder
import Mathlib.SetTheory.Cardinal.SchroederBernstein
#align_import set_theory.cardinal.basic from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8"
/-!
# Cardinal Numbers
We define cardinal numbers as a quotient of types under the equivalence relation of equinumerity.
## Main definitions
* `Cardinal` is the type of cardinal numbers (in a given universe).
* `Cardinal.mk α` or `#α` is the cardinality of `α`. The notation `#` lives in the locale
`Cardinal`.
* Addition `c₁ + c₂` is defined by `Cardinal.add_def α β : #α + #β = #(α ⊕ β)`.
* Multiplication `c₁ * c₂` is defined by `Cardinal.mul_def : #α * #β = #(α × β)`.
* The order `c₁ ≤ c₂` is defined by `Cardinal.le_def α β : #α ≤ #β ↔ Nonempty (α ↪ β)`.
* Exponentiation `c₁ ^ c₂` is defined by `Cardinal.power_def α β : #α ^ #β = #(β → α)`.
* `Cardinal.isLimit c` means that `c` is a (weak) limit cardinal: `c ≠ 0 ∧ ∀ x < c, succ x < c`.
* `Cardinal.aleph0` or `ℵ₀` is the cardinality of `ℕ`. This definition is universe polymorphic:
`Cardinal.aleph0.{u} : Cardinal.{u}` (contrast with `ℕ : Type`, which lives in a specific
universe). In some cases the universe level has to be given explicitly.
* `Cardinal.sum` is the sum of an indexed family of cardinals, i.e. the cardinality of the
corresponding sigma type.
* `Cardinal.prod` is the product of an indexed family of cardinals, i.e. the cardinality of the
corresponding pi type.
* `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`.
## Main instances
* Cardinals form a `CanonicallyOrderedCommSemiring` with the aforementioned sum and product.
* Cardinals form a `SuccOrder`. Use `Order.succ c` for the smallest cardinal greater than `c`.
* The less than relation on cardinals forms a well-order.
* Cardinals form a `ConditionallyCompleteLinearOrderBot`. Bounded sets for cardinals in universe
`u` are precisely the sets indexed by some type in universe `u`, see
`Cardinal.bddAbove_iff_small`. One can use `sSup` for the cardinal supremum, and `sInf` for the
minimum of a set of cardinals.
## Main Statements
* Cantor's theorem: `Cardinal.cantor c : c < 2 ^ c`.
* König's theorem: `Cardinal.sum_lt_prod`
## Implementation notes
* There is a type of cardinal numbers in every universe level:
`Cardinal.{u} : Type (u + 1)` is the quotient of types in `Type u`.
The operation `Cardinal.lift` lifts cardinal numbers to a higher level.
* Cardinal arithmetic specifically for infinite cardinals (like `κ * κ = κ`) is in the file
`Mathlib/SetTheory/Cardinal/Ordinal.lean`.
* There is an instance `Pow Cardinal`, but this will only fire if Lean already knows that both
the base and the exponent live in the same universe. As a workaround, you can add
```
local infixr:80 " ^' " => @HPow.hPow Cardinal Cardinal Cardinal _
```
to a file. This notation will work even if Lean doesn't know yet that the base and the exponent
live in the same universe (but no exponents in other types can be used).
(Porting note: This last point might need to be updated.)
## References
* <https://en.wikipedia.org/wiki/Cardinal_number>
## Tags
cardinal number, cardinal arithmetic, cardinal exponentiation, aleph,
Cantor's theorem, König's theorem, Konig's theorem
-/
assert_not_exists Field
assert_not_exists Module
open scoped Classical
open Function Set Order
noncomputable section
universe u v w
variable {α β : Type u}
/-- The equivalence relation on types given by equivalence (bijective correspondence) of types.
Quotienting by this equivalence relation gives the cardinal numbers.
-/
instance Cardinal.isEquivalent : Setoid (Type u) where
r α β := Nonempty (α ≃ β)
iseqv := ⟨
fun α => ⟨Equiv.refl α⟩,
fun ⟨e⟩ => ⟨e.symm⟩,
fun ⟨e₁⟩ ⟨e₂⟩ => ⟨e₁.trans e₂⟩⟩
#align cardinal.is_equivalent Cardinal.isEquivalent
/-- `Cardinal.{u}` is the type of cardinal numbers in `Type u`,
defined as the quotient of `Type u` by existence of an equivalence
(a bijection with explicit inverse). -/
@[pp_with_univ]
def Cardinal : Type (u + 1) :=
Quotient Cardinal.isEquivalent
#align cardinal Cardinal
namespace Cardinal
/-- The cardinal number of a type -/
def mk : Type u → Cardinal :=
Quotient.mk'
#align cardinal.mk Cardinal.mk
@[inherit_doc]
scoped prefix:max "#" => Cardinal.mk
instance canLiftCardinalType : CanLift Cardinal.{u} (Type u) mk fun _ => True :=
⟨fun c _ => Quot.inductionOn c fun α => ⟨α, rfl⟩⟩
#align cardinal.can_lift_cardinal_Type Cardinal.canLiftCardinalType
@[elab_as_elim]
theorem inductionOn {p : Cardinal → Prop} (c : Cardinal) (h : ∀ α, p #α) : p c :=
Quotient.inductionOn c h
#align cardinal.induction_on Cardinal.inductionOn
@[elab_as_elim]
theorem inductionOn₂ {p : Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal)
(h : ∀ α β, p #α #β) : p c₁ c₂ :=
Quotient.inductionOn₂ c₁ c₂ h
#align cardinal.induction_on₂ Cardinal.inductionOn₂
@[elab_as_elim]
theorem inductionOn₃ {p : Cardinal → Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal)
(c₃ : Cardinal) (h : ∀ α β γ, p #α #β #γ) : p c₁ c₂ c₃ :=
Quotient.inductionOn₃ c₁ c₂ c₃ h
#align cardinal.induction_on₃ Cardinal.inductionOn₃
protected theorem eq : #α = #β ↔ Nonempty (α ≃ β) :=
Quotient.eq'
#align cardinal.eq Cardinal.eq
@[simp]
theorem mk'_def (α : Type u) : @Eq Cardinal ⟦α⟧ #α :=
rfl
#align cardinal.mk_def Cardinal.mk'_def
@[simp]
theorem mk_out (c : Cardinal) : #c.out = c :=
Quotient.out_eq _
#align cardinal.mk_out Cardinal.mk_out
/-- The representative of the cardinal of a type is equivalent to the original type. -/
def outMkEquiv {α : Type v} : (#α).out ≃ α :=
Nonempty.some <| Cardinal.eq.mp (by simp)
#align cardinal.out_mk_equiv Cardinal.outMkEquiv
theorem mk_congr (e : α ≃ β) : #α = #β :=
Quot.sound ⟨e⟩
#align cardinal.mk_congr Cardinal.mk_congr
alias _root_.Equiv.cardinal_eq := mk_congr
#align equiv.cardinal_eq Equiv.cardinal_eq
/-- Lift a function between `Type*`s to a function between `Cardinal`s. -/
def map (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) : Cardinal.{u} → Cardinal.{v} :=
Quotient.map f fun α β ⟨e⟩ => ⟨hf α β e⟩
#align cardinal.map Cardinal.map
@[simp]
theorem map_mk (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) (α : Type u) :
map f hf #α = #(f α) :=
rfl
#align cardinal.map_mk Cardinal.map_mk
/-- Lift a binary operation `Type* → Type* → Type*` to a binary operation on `Cardinal`s. -/
def map₂ (f : Type u → Type v → Type w) (hf : ∀ α β γ δ, α ≃ β → γ ≃ δ → f α γ ≃ f β δ) :
Cardinal.{u} → Cardinal.{v} → Cardinal.{w} :=
Quotient.map₂ f fun α β ⟨e₁⟩ γ δ ⟨e₂⟩ => ⟨hf α β γ δ e₁ e₂⟩
#align cardinal.map₂ Cardinal.map₂
/-- The universe lift operation on cardinals. You can specify the universes explicitly with
`lift.{u v} : Cardinal.{v} → Cardinal.{max v u}` -/
@[pp_with_univ]
def lift (c : Cardinal.{v}) : Cardinal.{max v u} :=
map ULift.{u, v} (fun _ _ e => Equiv.ulift.trans <| e.trans Equiv.ulift.symm) c
#align cardinal.lift Cardinal.lift
@[simp]
theorem mk_uLift (α) : #(ULift.{v, u} α) = lift.{v} #α :=
rfl
#align cardinal.mk_ulift Cardinal.mk_uLift
-- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma
-- further down in this file
/-- `lift.{max u v, u}` equals `lift.{v, u}`. -/
@[simp, nolint simpNF]
theorem lift_umax : lift.{max u v, u} = lift.{v, u} :=
funext fun a => inductionOn a fun _ => (Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq
#align cardinal.lift_umax Cardinal.lift_umax
-- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma
-- further down in this file
/-- `lift.{max v u, u}` equals `lift.{v, u}`. -/
@[simp, nolint simpNF]
theorem lift_umax' : lift.{max v u, u} = lift.{v, u} :=
lift_umax
#align cardinal.lift_umax' Cardinal.lift_umax'
-- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma
-- further down in this file
/-- A cardinal lifted to a lower or equal universe equals itself. -/
@[simp, nolint simpNF]
theorem lift_id' (a : Cardinal.{max u v}) : lift.{u} a = a :=
inductionOn a fun _ => mk_congr Equiv.ulift
#align cardinal.lift_id' Cardinal.lift_id'
/-- A cardinal lifted to the same universe equals itself. -/
@[simp]
theorem lift_id (a : Cardinal) : lift.{u, u} a = a :=
lift_id'.{u, u} a
#align cardinal.lift_id Cardinal.lift_id
/-- A cardinal lifted to the zero universe equals itself. -/
-- porting note (#10618): simp can prove this
-- @[simp]
theorem lift_uzero (a : Cardinal.{u}) : lift.{0} a = a :=
lift_id'.{0, u} a
#align cardinal.lift_uzero Cardinal.lift_uzero
@[simp]
theorem lift_lift.{u_1} (a : Cardinal.{u_1}) : lift.{w} (lift.{v} a) = lift.{max v w} a :=
inductionOn a fun _ => (Equiv.ulift.trans <| Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq
#align cardinal.lift_lift Cardinal.lift_lift
/-- We define the order on cardinal numbers by `#α ≤ #β` if and only if
there exists an embedding (injective function) from α to β. -/
instance : LE Cardinal.{u} :=
⟨fun q₁ q₂ =>
Quotient.liftOn₂ q₁ q₂ (fun α β => Nonempty <| α ↪ β) fun _ _ _ _ ⟨e₁⟩ ⟨e₂⟩ =>
propext ⟨fun ⟨e⟩ => ⟨e.congr e₁ e₂⟩, fun ⟨e⟩ => ⟨e.congr e₁.symm e₂.symm⟩⟩⟩
instance partialOrder : PartialOrder Cardinal.{u} where
le := (· ≤ ·)
le_refl := by
rintro ⟨α⟩
exact ⟨Embedding.refl _⟩
le_trans := by
rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨e₁⟩ ⟨e₂⟩
exact ⟨e₁.trans e₂⟩
le_antisymm := by
rintro ⟨α⟩ ⟨β⟩ ⟨e₁⟩ ⟨e₂⟩
exact Quotient.sound (e₁.antisymm e₂)
instance linearOrder : LinearOrder Cardinal.{u} :=
{ Cardinal.partialOrder with
le_total := by
rintro ⟨α⟩ ⟨β⟩
apply Embedding.total
decidableLE := Classical.decRel _ }
theorem le_def (α β : Type u) : #α ≤ #β ↔ Nonempty (α ↪ β) :=
Iff.rfl
#align cardinal.le_def Cardinal.le_def
theorem mk_le_of_injective {α β : Type u} {f : α → β} (hf : Injective f) : #α ≤ #β :=
⟨⟨f, hf⟩⟩
#align cardinal.mk_le_of_injective Cardinal.mk_le_of_injective
theorem _root_.Function.Embedding.cardinal_le {α β : Type u} (f : α ↪ β) : #α ≤ #β :=
⟨f⟩
#align function.embedding.cardinal_le Function.Embedding.cardinal_le
theorem mk_le_of_surjective {α β : Type u} {f : α → β} (hf : Surjective f) : #β ≤ #α :=
⟨Embedding.ofSurjective f hf⟩
#align cardinal.mk_le_of_surjective Cardinal.mk_le_of_surjective
theorem le_mk_iff_exists_set {c : Cardinal} {α : Type u} : c ≤ #α ↔ ∃ p : Set α, #p = c :=
⟨inductionOn c fun _ ⟨⟨f, hf⟩⟩ => ⟨Set.range f, (Equiv.ofInjective f hf).cardinal_eq.symm⟩,
fun ⟨_, e⟩ => e ▸ ⟨⟨Subtype.val, fun _ _ => Subtype.eq⟩⟩⟩
#align cardinal.le_mk_iff_exists_set Cardinal.le_mk_iff_exists_set
theorem mk_subtype_le {α : Type u} (p : α → Prop) : #(Subtype p) ≤ #α :=
⟨Embedding.subtype p⟩
#align cardinal.mk_subtype_le Cardinal.mk_subtype_le
theorem mk_set_le (s : Set α) : #s ≤ #α :=
mk_subtype_le s
#align cardinal.mk_set_le Cardinal.mk_set_le
@[simp]
lemma mk_preimage_down {s : Set α} : #(ULift.down.{v} ⁻¹' s) = lift.{v} (#s) := by
rw [← mk_uLift, Cardinal.eq]
constructor
let f : ULift.down ⁻¹' s → ULift s := fun x ↦ ULift.up (restrictPreimage s ULift.down x)
have : Function.Bijective f :=
ULift.up_bijective.comp (restrictPreimage_bijective _ (ULift.down_bijective))
exact Equiv.ofBijective f this
theorem out_embedding {c c' : Cardinal} : c ≤ c' ↔ Nonempty (c.out ↪ c'.out) := by
trans
· rw [← Quotient.out_eq c, ← Quotient.out_eq c']
· rw [mk'_def, mk'_def, le_def]
#align cardinal.out_embedding Cardinal.out_embedding
theorem lift_mk_le {α : Type v} {β : Type w} :
lift.{max u w} #α ≤ lift.{max u v} #β ↔ Nonempty (α ↪ β) :=
⟨fun ⟨f⟩ => ⟨Embedding.congr Equiv.ulift Equiv.ulift f⟩, fun ⟨f⟩ =>
⟨Embedding.congr Equiv.ulift.symm Equiv.ulift.symm f⟩⟩
#align cardinal.lift_mk_le Cardinal.lift_mk_le
/-- A variant of `Cardinal.lift_mk_le` with specialized universes.
Because Lean often can not realize it should use this specialization itself,
we provide this statement separately so you don't have to solve the specialization problem either.
-/
theorem lift_mk_le' {α : Type u} {β : Type v} : lift.{v} #α ≤ lift.{u} #β ↔ Nonempty (α ↪ β) :=
lift_mk_le.{0}
#align cardinal.lift_mk_le' Cardinal.lift_mk_le'
theorem lift_mk_eq {α : Type u} {β : Type v} :
lift.{max v w} #α = lift.{max u w} #β ↔ Nonempty (α ≃ β) :=
Quotient.eq'.trans
⟨fun ⟨f⟩ => ⟨Equiv.ulift.symm.trans <| f.trans Equiv.ulift⟩, fun ⟨f⟩ =>
⟨Equiv.ulift.trans <| f.trans Equiv.ulift.symm⟩⟩
#align cardinal.lift_mk_eq Cardinal.lift_mk_eq
/-- A variant of `Cardinal.lift_mk_eq` with specialized universes.
Because Lean often can not realize it should use this specialization itself,
we provide this statement separately so you don't have to solve the specialization problem either.
-/
theorem lift_mk_eq' {α : Type u} {β : Type v} : lift.{v} #α = lift.{u} #β ↔ Nonempty (α ≃ β) :=
lift_mk_eq.{u, v, 0}
#align cardinal.lift_mk_eq' Cardinal.lift_mk_eq'
@[simp]
theorem lift_le {a b : Cardinal.{v}} : lift.{u, v} a ≤ lift.{u, v} b ↔ a ≤ b :=
inductionOn₂ a b fun α β => by
rw [← lift_umax]
exact lift_mk_le.{u}
#align cardinal.lift_le Cardinal.lift_le
-- Porting note: changed `simps` to `simps!` because the linter told to do so.
/-- `Cardinal.lift` as an `OrderEmbedding`. -/
@[simps! (config := .asFn)]
def liftOrderEmbedding : Cardinal.{v} ↪o Cardinal.{max v u} :=
OrderEmbedding.ofMapLEIff lift.{u, v} fun _ _ => lift_le
#align cardinal.lift_order_embedding Cardinal.liftOrderEmbedding
theorem lift_injective : Injective lift.{u, v} :=
liftOrderEmbedding.injective
#align cardinal.lift_injective Cardinal.lift_injective
@[simp]
theorem lift_inj {a b : Cardinal.{u}} : lift.{v, u} a = lift.{v, u} b ↔ a = b :=
lift_injective.eq_iff
#align cardinal.lift_inj Cardinal.lift_inj
@[simp]
theorem lift_lt {a b : Cardinal.{u}} : lift.{v, u} a < lift.{v, u} b ↔ a < b :=
liftOrderEmbedding.lt_iff_lt
#align cardinal.lift_lt Cardinal.lift_lt
theorem lift_strictMono : StrictMono lift := fun _ _ => lift_lt.2
#align cardinal.lift_strict_mono Cardinal.lift_strictMono
theorem lift_monotone : Monotone lift :=
lift_strictMono.monotone
#align cardinal.lift_monotone Cardinal.lift_monotone
instance : Zero Cardinal.{u} :=
-- `PEmpty` might be more canonical, but this is convenient for defeq with natCast
⟨lift #(Fin 0)⟩
instance : Inhabited Cardinal.{u} :=
⟨0⟩
@[simp]
theorem mk_eq_zero (α : Type u) [IsEmpty α] : #α = 0 :=
(Equiv.equivOfIsEmpty α (ULift (Fin 0))).cardinal_eq
#align cardinal.mk_eq_zero Cardinal.mk_eq_zero
@[simp]
theorem lift_zero : lift 0 = 0 := mk_eq_zero _
#align cardinal.lift_zero Cardinal.lift_zero
@[simp]
theorem lift_eq_zero {a : Cardinal.{v}} : lift.{u} a = 0 ↔ a = 0 :=
lift_injective.eq_iff' lift_zero
#align cardinal.lift_eq_zero Cardinal.lift_eq_zero
theorem mk_eq_zero_iff {α : Type u} : #α = 0 ↔ IsEmpty α :=
⟨fun e =>
let ⟨h⟩ := Quotient.exact e
h.isEmpty,
@mk_eq_zero α⟩
#align cardinal.mk_eq_zero_iff Cardinal.mk_eq_zero_iff
theorem mk_ne_zero_iff {α : Type u} : #α ≠ 0 ↔ Nonempty α :=
(not_iff_not.2 mk_eq_zero_iff).trans not_isEmpty_iff
#align cardinal.mk_ne_zero_iff Cardinal.mk_ne_zero_iff
@[simp]
theorem mk_ne_zero (α : Type u) [Nonempty α] : #α ≠ 0 :=
mk_ne_zero_iff.2 ‹_›
#align cardinal.mk_ne_zero Cardinal.mk_ne_zero
instance : One Cardinal.{u} :=
-- `PUnit` might be more canonical, but this is convenient for defeq with natCast
⟨lift #(Fin 1)⟩
instance : Nontrivial Cardinal.{u} :=
⟨⟨1, 0, mk_ne_zero _⟩⟩
theorem mk_eq_one (α : Type u) [Unique α] : #α = 1 :=
(Equiv.equivOfUnique α (ULift (Fin 1))).cardinal_eq
#align cardinal.mk_eq_one Cardinal.mk_eq_one
theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ Subsingleton α :=
⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ =>
⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩
#align cardinal.le_one_iff_subsingleton Cardinal.le_one_iff_subsingleton
@[simp]
theorem mk_le_one_iff_set_subsingleton {s : Set α} : #s ≤ 1 ↔ s.Subsingleton :=
le_one_iff_subsingleton.trans s.subsingleton_coe
#align cardinal.mk_le_one_iff_set_subsingleton Cardinal.mk_le_one_iff_set_subsingleton
alias ⟨_, _root_.Set.Subsingleton.cardinal_mk_le_one⟩ := mk_le_one_iff_set_subsingleton
#align set.subsingleton.cardinal_mk_le_one Set.Subsingleton.cardinal_mk_le_one
instance : Add Cardinal.{u} :=
⟨map₂ Sum fun _ _ _ _ => Equiv.sumCongr⟩
theorem add_def (α β : Type u) : #α + #β = #(Sum α β) :=
rfl
#align cardinal.add_def Cardinal.add_def
instance : NatCast Cardinal.{u} :=
⟨fun n => lift #(Fin n)⟩
@[simp]
theorem mk_sum (α : Type u) (β : Type v) : #(α ⊕ β) = lift.{v, u} #α + lift.{u, v} #β :=
mk_congr (Equiv.ulift.symm.sumCongr Equiv.ulift.symm)
#align cardinal.mk_sum Cardinal.mk_sum
@[simp]
theorem mk_option {α : Type u} : #(Option α) = #α + 1 := by
rw [(Equiv.optionEquivSumPUnit.{u, u} α).cardinal_eq, mk_sum, mk_eq_one PUnit, lift_id, lift_id]
#align cardinal.mk_option Cardinal.mk_option
@[simp]
theorem mk_psum (α : Type u) (β : Type v) : #(PSum α β) = lift.{v} #α + lift.{u} #β :=
(mk_congr (Equiv.psumEquivSum α β)).trans (mk_sum α β)
#align cardinal.mk_psum Cardinal.mk_psum
@[simp]
theorem mk_fintype (α : Type u) [h : Fintype α] : #α = Fintype.card α :=
mk_congr (Fintype.equivOfCardEq (by simp))
protected theorem cast_succ (n : ℕ) : ((n + 1 : ℕ) : Cardinal.{u}) = n + 1 := by
change #(ULift.{u} (Fin (n+1))) = # (ULift.{u} (Fin n)) + 1
rw [← mk_option, mk_fintype, mk_fintype]
simp only [Fintype.card_ulift, Fintype.card_fin, Fintype.card_option]
instance : Mul Cardinal.{u} :=
⟨map₂ Prod fun _ _ _ _ => Equiv.prodCongr⟩
theorem mul_def (α β : Type u) : #α * #β = #(α × β) :=
rfl
#align cardinal.mul_def Cardinal.mul_def
@[simp]
theorem mk_prod (α : Type u) (β : Type v) : #(α × β) = lift.{v, u} #α * lift.{u, v} #β :=
mk_congr (Equiv.ulift.symm.prodCongr Equiv.ulift.symm)
#align cardinal.mk_prod Cardinal.mk_prod
private theorem mul_comm' (a b : Cardinal.{u}) : a * b = b * a :=
inductionOn₂ a b fun α β => mk_congr <| Equiv.prodComm α β
/-- The cardinal exponential. `#α ^ #β` is the cardinal of `β → α`. -/
instance instPowCardinal : Pow Cardinal.{u} Cardinal.{u} :=
⟨map₂ (fun α β => β → α) fun _ _ _ _ e₁ e₂ => e₂.arrowCongr e₁⟩
theorem power_def (α β : Type u) : #α ^ #β = #(β → α) :=
rfl
#align cardinal.power_def Cardinal.power_def
theorem mk_arrow (α : Type u) (β : Type v) : #(α → β) = (lift.{u} #β^lift.{v} #α) :=
mk_congr (Equiv.ulift.symm.arrowCongr Equiv.ulift.symm)
#align cardinal.mk_arrow Cardinal.mk_arrow
@[simp]
theorem lift_power (a b : Cardinal.{u}) : lift.{v} (a ^ b) = lift.{v} a ^ lift.{v} b :=
inductionOn₂ a b fun _ _ =>
mk_congr <| Equiv.ulift.trans (Equiv.ulift.arrowCongr Equiv.ulift).symm
#align cardinal.lift_power Cardinal.lift_power
@[simp]
theorem power_zero {a : Cardinal} : a ^ (0 : Cardinal) = 1 :=
inductionOn a fun _ => mk_eq_one _
#align cardinal.power_zero Cardinal.power_zero
@[simp]
theorem power_one {a : Cardinal.{u}} : a ^ (1 : Cardinal) = a :=
inductionOn a fun α => mk_congr (Equiv.funUnique (ULift.{u} (Fin 1)) α)
#align cardinal.power_one Cardinal.power_one
theorem power_add {a b c : Cardinal} : a ^ (b + c) = a ^ b * a ^ c :=
inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumArrowEquivProdArrow β γ α
#align cardinal.power_add Cardinal.power_add
instance commSemiring : CommSemiring Cardinal.{u} where
zero := 0
one := 1
add := (· + ·)
mul := (· * ·)
zero_add a := inductionOn a fun α => mk_congr <| Equiv.emptySum (ULift (Fin 0)) α
add_zero a := inductionOn a fun α => mk_congr <| Equiv.sumEmpty α (ULift (Fin 0))
add_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumAssoc α β γ
add_comm a b := inductionOn₂ a b fun α β => mk_congr <| Equiv.sumComm α β
zero_mul a := inductionOn a fun α => mk_eq_zero _
mul_zero a := inductionOn a fun α => mk_eq_zero _
one_mul a := inductionOn a fun α => mk_congr <| Equiv.uniqueProd α (ULift (Fin 1))
mul_one a := inductionOn a fun α => mk_congr <| Equiv.prodUnique α (ULift (Fin 1))
mul_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodAssoc α β γ
mul_comm := mul_comm'
left_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodSumDistrib α β γ
right_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumProdDistrib α β γ
nsmul := nsmulRec
npow n c := c ^ (n : Cardinal)
npow_zero := @power_zero
npow_succ n c := show c ^ (↑(n + 1) : Cardinal) = c ^ (↑n : Cardinal) * c
by rw [Cardinal.cast_succ, power_add, power_one, mul_comm']
natCast := (fun n => lift.{u} #(Fin n) : ℕ → Cardinal.{u})
natCast_zero := rfl
natCast_succ := Cardinal.cast_succ
/-! Porting note (#11229): Deprecated section. Remove. -/
section deprecated
set_option linter.deprecated false
@[deprecated (since := "2023-02-11")]
theorem power_bit0 (a b : Cardinal) : a ^ bit0 b = a ^ b * a ^ b :=
power_add
#align cardinal.power_bit0 Cardinal.power_bit0
@[deprecated (since := "2023-02-11")]
theorem power_bit1 (a b : Cardinal) : a ^ bit1 b = a ^ b * a ^ b * a := by
rw [bit1, ← power_bit0, power_add, power_one]
#align cardinal.power_bit1 Cardinal.power_bit1
end deprecated
@[simp]
theorem one_power {a : Cardinal} : (1 : Cardinal) ^ a = 1 :=
inductionOn a fun _ => mk_eq_one _
#align cardinal.one_power Cardinal.one_power
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_bool : #Bool = 2 := by simp
#align cardinal.mk_bool Cardinal.mk_bool
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_Prop : #Prop = 2 := by simp
#align cardinal.mk_Prop Cardinal.mk_Prop
@[simp]
theorem zero_power {a : Cardinal} : a ≠ 0 → (0 : Cardinal) ^ a = 0 :=
inductionOn a fun _ heq =>
mk_eq_zero_iff.2 <|
isEmpty_pi.2 <|
let ⟨a⟩ := mk_ne_zero_iff.1 heq
⟨a, inferInstance⟩
#align cardinal.zero_power Cardinal.zero_power
theorem power_ne_zero {a : Cardinal} (b : Cardinal) : a ≠ 0 → a ^ b ≠ 0 :=
inductionOn₂ a b fun _ _ h =>
let ⟨a⟩ := mk_ne_zero_iff.1 h
mk_ne_zero_iff.2 ⟨fun _ => a⟩
#align cardinal.power_ne_zero Cardinal.power_ne_zero
theorem mul_power {a b c : Cardinal} : (a * b) ^ c = a ^ c * b ^ c :=
inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.arrowProdEquivProdArrow α β γ
#align cardinal.mul_power Cardinal.mul_power
theorem power_mul {a b c : Cardinal} : a ^ (b * c) = (a ^ b) ^ c := by
rw [mul_comm b c]
exact inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.curry γ β α
#align cardinal.power_mul Cardinal.power_mul
@[simp]
theorem pow_cast_right (a : Cardinal.{u}) (n : ℕ) : a ^ (↑n : Cardinal.{u}) = a ^ n :=
rfl
#align cardinal.pow_cast_right Cardinal.pow_cast_right
@[simp]
theorem lift_one : lift 1 = 1 := mk_eq_one _
#align cardinal.lift_one Cardinal.lift_one
@[simp]
theorem lift_eq_one {a : Cardinal.{v}} : lift.{u} a = 1 ↔ a = 1 :=
lift_injective.eq_iff' lift_one
@[simp]
theorem lift_add (a b : Cardinal.{u}) : lift.{v} (a + b) = lift.{v} a + lift.{v} b :=
inductionOn₂ a b fun _ _ =>
mk_congr <| Equiv.ulift.trans (Equiv.sumCongr Equiv.ulift Equiv.ulift).symm
#align cardinal.lift_add Cardinal.lift_add
@[simp]
theorem lift_mul (a b : Cardinal.{u}) : lift.{v} (a * b) = lift.{v} a * lift.{v} b :=
inductionOn₂ a b fun _ _ =>
mk_congr <| Equiv.ulift.trans (Equiv.prodCongr Equiv.ulift Equiv.ulift).symm
#align cardinal.lift_mul Cardinal.lift_mul
/-! Porting note (#11229): Deprecated section. Remove. -/
section deprecated
set_option linter.deprecated false
@[simp, deprecated (since := "2023-02-11")]
theorem lift_bit0 (a : Cardinal) : lift.{v} (bit0 a) = bit0 (lift.{v} a) :=
lift_add a a
#align cardinal.lift_bit0 Cardinal.lift_bit0
@[simp, deprecated (since := "2023-02-11")]
theorem lift_bit1 (a : Cardinal) : lift.{v} (bit1 a) = bit1 (lift.{v} a) := by simp [bit1]
#align cardinal.lift_bit1 Cardinal.lift_bit1
end deprecated
-- Porting note: Proof used to be simp, needed to remind simp that 1 + 1 = 2
theorem lift_two : lift.{u, v} 2 = 2 := by simp [← one_add_one_eq_two]
#align cardinal.lift_two Cardinal.lift_two
@[simp]
theorem mk_set {α : Type u} : #(Set α) = 2 ^ #α := by simp [← one_add_one_eq_two, Set, mk_arrow]
#align cardinal.mk_set Cardinal.mk_set
/-- A variant of `Cardinal.mk_set` expressed in terms of a `Set` instead of a `Type`. -/
@[simp]
theorem mk_powerset {α : Type u} (s : Set α) : #(↥(𝒫 s)) = 2 ^ #(↥s) :=
(mk_congr (Equiv.Set.powerset s)).trans mk_set
#align cardinal.mk_powerset Cardinal.mk_powerset
theorem lift_two_power (a : Cardinal) : lift.{v} (2 ^ a) = 2 ^ lift.{v} a := by
simp [← one_add_one_eq_two]
#align cardinal.lift_two_power Cardinal.lift_two_power
section OrderProperties
open Sum
protected theorem zero_le : ∀ a : Cardinal, 0 ≤ a := by
rintro ⟨α⟩
exact ⟨Embedding.ofIsEmpty⟩
#align cardinal.zero_le Cardinal.zero_le
private theorem add_le_add' : ∀ {a b c d : Cardinal}, a ≤ b → c ≤ d → a + c ≤ b + d := by
rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.sumMap e₂⟩
-- #align cardinal.add_le_add' Cardinal.add_le_add'
instance add_covariantClass : CovariantClass Cardinal Cardinal (· + ·) (· ≤ ·) :=
⟨fun _ _ _ => add_le_add' le_rfl⟩
#align cardinal.add_covariant_class Cardinal.add_covariantClass
instance add_swap_covariantClass : CovariantClass Cardinal Cardinal (swap (· + ·)) (· ≤ ·) :=
⟨fun _ _ _ h => add_le_add' h le_rfl⟩
#align cardinal.add_swap_covariant_class Cardinal.add_swap_covariantClass
instance canonicallyOrderedCommSemiring : CanonicallyOrderedCommSemiring Cardinal.{u} :=
{ Cardinal.commSemiring,
Cardinal.partialOrder with
bot := 0
bot_le := Cardinal.zero_le
add_le_add_left := fun a b => add_le_add_left
exists_add_of_le := fun {a b} =>
inductionOn₂ a b fun α β ⟨⟨f, hf⟩⟩ =>
have : Sum α ((range f)ᶜ : Set β) ≃ β :=
(Equiv.sumCongr (Equiv.ofInjective f hf) (Equiv.refl _)).trans <|
Equiv.Set.sumCompl (range f)
⟨#(↥(range f)ᶜ), mk_congr this.symm⟩
le_self_add := fun a b => (add_zero a).ge.trans <| add_le_add_left (Cardinal.zero_le _) _
eq_zero_or_eq_zero_of_mul_eq_zero := fun {a b} =>
inductionOn₂ a b fun α β => by
simpa only [mul_def, mk_eq_zero_iff, isEmpty_prod] using id }
instance : CanonicallyLinearOrderedAddCommMonoid Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring, Cardinal.linearOrder with }
-- Computable instance to prevent a non-computable one being found via the one above
instance : CanonicallyOrderedAddCommMonoid Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring with }
instance : LinearOrderedCommMonoidWithZero Cardinal.{u} :=
{ Cardinal.commSemiring,
Cardinal.linearOrder with
mul_le_mul_left := @mul_le_mul_left' _ _ _ _
zero_le_one := zero_le _ }
-- Computable instance to prevent a non-computable one being found via the one above
instance : CommMonoidWithZero Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring with }
-- Porting note: new
-- Computable instance to prevent a non-computable one being found via the one above
instance : CommMonoid Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring with }
theorem zero_power_le (c : Cardinal.{u}) : (0 : Cardinal.{u}) ^ c ≤ 1 := by
by_cases h : c = 0
· rw [h, power_zero]
· rw [zero_power h]
apply zero_le
#align cardinal.zero_power_le Cardinal.zero_power_le
theorem power_le_power_left : ∀ {a b c : Cardinal}, a ≠ 0 → b ≤ c → a ^ b ≤ a ^ c := by
rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩
let ⟨a⟩ := mk_ne_zero_iff.1 hα
exact ⟨@Function.Embedding.arrowCongrLeft _ _ _ ⟨a⟩ e⟩
#align cardinal.power_le_power_left Cardinal.power_le_power_left
theorem self_le_power (a : Cardinal) {b : Cardinal} (hb : 1 ≤ b) : a ≤ a ^ b := by
rcases eq_or_ne a 0 with (rfl | ha)
· exact zero_le _
· convert power_le_power_left ha hb
exact power_one.symm
#align cardinal.self_le_power Cardinal.self_le_power
/-- **Cantor's theorem** -/
theorem cantor (a : Cardinal.{u}) : a < 2 ^ a := by
induction' a using Cardinal.inductionOn with α
rw [← mk_set]
refine ⟨⟨⟨singleton, fun a b => singleton_eq_singleton_iff.1⟩⟩, ?_⟩
rintro ⟨⟨f, hf⟩⟩
exact cantor_injective f hf
#align cardinal.cantor Cardinal.cantor
instance : NoMaxOrder Cardinal.{u} where exists_gt a := ⟨_, cantor a⟩
-- short-circuit type class inference
instance : DistribLattice Cardinal.{u} := inferInstance
theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by
rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not]
#align cardinal.one_lt_iff_nontrivial Cardinal.one_lt_iff_nontrivial
theorem power_le_max_power_one {a b c : Cardinal} (h : b ≤ c) : a ^ b ≤ max (a ^ c) 1 := by
by_cases ha : a = 0
· simp [ha, zero_power_le]
· exact (power_le_power_left ha h).trans (le_max_left _ _)
#align cardinal.power_le_max_power_one Cardinal.power_le_max_power_one
theorem power_le_power_right {a b c : Cardinal} : a ≤ b → a ^ c ≤ b ^ c :=
inductionOn₃ a b c fun _ _ _ ⟨e⟩ => ⟨Embedding.arrowCongrRight e⟩
#align cardinal.power_le_power_right Cardinal.power_le_power_right
theorem power_pos {a : Cardinal} (b : Cardinal) (ha : 0 < a) : 0 < a ^ b :=
(power_ne_zero _ ha.ne').bot_lt
#align cardinal.power_pos Cardinal.power_pos
end OrderProperties
protected theorem lt_wf : @WellFounded Cardinal.{u} (· < ·) :=
⟨fun a =>
by_contradiction fun h => by
let ι := { c : Cardinal // ¬Acc (· < ·) c }
let f : ι → Cardinal := Subtype.val
haveI hι : Nonempty ι := ⟨⟨_, h⟩⟩
obtain ⟨⟨c : Cardinal, hc : ¬Acc (· < ·) c⟩, ⟨h_1 : ∀ j, (f ⟨c, hc⟩).out ↪ (f j).out⟩⟩ :=
Embedding.min_injective fun i => (f i).out
refine hc (Acc.intro _ fun j h' => by_contradiction fun hj => h'.2 ?_)
have : #_ ≤ #_ := ⟨h_1 ⟨j, hj⟩⟩
simpa only [mk_out] using this⟩
#align cardinal.lt_wf Cardinal.lt_wf
instance : WellFoundedRelation Cardinal.{u} :=
⟨(· < ·), Cardinal.lt_wf⟩
-- Porting note: this no longer is automatically inferred.
instance : WellFoundedLT Cardinal.{u} :=
⟨Cardinal.lt_wf⟩
instance wo : @IsWellOrder Cardinal.{u} (· < ·) where
#align cardinal.wo Cardinal.wo
instance : ConditionallyCompleteLinearOrderBot Cardinal :=
IsWellOrder.conditionallyCompleteLinearOrderBot _
@[simp]
theorem sInf_empty : sInf (∅ : Set Cardinal.{u}) = 0 :=
dif_neg Set.not_nonempty_empty
#align cardinal.Inf_empty Cardinal.sInf_empty
lemma sInf_eq_zero_iff {s : Set Cardinal} : sInf s = 0 ↔ s = ∅ ∨ ∃ a ∈ s, a = 0 := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rcases s.eq_empty_or_nonempty with rfl | hne
· exact Or.inl rfl
· exact Or.inr ⟨sInf s, csInf_mem hne, h⟩
· rcases h with rfl | ⟨a, ha, rfl⟩
· exact Cardinal.sInf_empty
· exact eq_bot_iff.2 (csInf_le' ha)
lemma iInf_eq_zero_iff {ι : Sort*} {f : ι → Cardinal} :
(⨅ i, f i) = 0 ↔ IsEmpty ι ∨ ∃ i, f i = 0 := by
simp [iInf, sInf_eq_zero_iff]
/-- Note that the successor of `c` is not the same as `c + 1` except in the case of finite `c`. -/
instance : SuccOrder Cardinal :=
SuccOrder.ofSuccLeIff (fun c => sInf { c' | c < c' })
-- Porting note: Needed to insert `by apply` in the next line
⟨by apply lt_of_lt_of_le <| csInf_mem <| exists_gt _,
-- Porting note used to be just `csInf_le'`
fun h ↦ csInf_le' h⟩
theorem succ_def (c : Cardinal) : succ c = sInf { c' | c < c' } :=
rfl
#align cardinal.succ_def Cardinal.succ_def
theorem succ_pos : ∀ c : Cardinal, 0 < succ c :=
bot_lt_succ
#align cardinal.succ_pos Cardinal.succ_pos
theorem succ_ne_zero (c : Cardinal) : succ c ≠ 0 :=
(succ_pos _).ne'
#align cardinal.succ_ne_zero Cardinal.succ_ne_zero
theorem add_one_le_succ (c : Cardinal.{u}) : c + 1 ≤ succ c := by
-- Porting note: rewrote the next three lines to avoid defeq abuse.
have : Set.Nonempty { c' | c < c' } := exists_gt c
simp_rw [succ_def, le_csInf_iff'' this, mem_setOf]
intro b hlt
rcases b, c with ⟨⟨β⟩, ⟨γ⟩⟩
cases' le_of_lt hlt with f
have : ¬Surjective f := fun hn => (not_le_of_lt hlt) (mk_le_of_surjective hn)
simp only [Surjective, not_forall] at this
rcases this with ⟨b, hb⟩
calc
#γ + 1 = #(Option γ) := mk_option.symm
_ ≤ #β := (f.optionElim b hb).cardinal_le
#align cardinal.add_one_le_succ Cardinal.add_one_le_succ
/-- A cardinal is a limit if it is not zero or a successor cardinal. Note that `ℵ₀` is a limit
cardinal by this definition, but `0` isn't.
Use `IsSuccLimit` if you want to include the `c = 0` case. -/
def IsLimit (c : Cardinal) : Prop :=
c ≠ 0 ∧ IsSuccLimit c
#align cardinal.is_limit Cardinal.IsLimit
protected theorem IsLimit.ne_zero {c} (h : IsLimit c) : c ≠ 0 :=
h.1
#align cardinal.is_limit.ne_zero Cardinal.IsLimit.ne_zero
protected theorem IsLimit.isSuccLimit {c} (h : IsLimit c) : IsSuccLimit c :=
h.2
#align cardinal.is_limit.is_succ_limit Cardinal.IsLimit.isSuccLimit
theorem IsLimit.succ_lt {x c} (h : IsLimit c) : x < c → succ x < c :=
h.isSuccLimit.succ_lt
#align cardinal.is_limit.succ_lt Cardinal.IsLimit.succ_lt
theorem isSuccLimit_zero : IsSuccLimit (0 : Cardinal) :=
isSuccLimit_bot
#align cardinal.is_succ_limit_zero Cardinal.isSuccLimit_zero
/-- The indexed sum of cardinals is the cardinality of the
indexed disjoint union, i.e. sigma type. -/
def sum {ι} (f : ι → Cardinal) : Cardinal :=
mk (Σi, (f i).out)
#align cardinal.sum Cardinal.sum
theorem le_sum {ι} (f : ι → Cardinal) (i) : f i ≤ sum f := by
rw [← Quotient.out_eq (f i)]
exact ⟨⟨fun a => ⟨i, a⟩, fun a b h => by injection h⟩⟩
#align cardinal.le_sum Cardinal.le_sum
@[simp]
theorem mk_sigma {ι} (f : ι → Type*) : #(Σ i, f i) = sum fun i => #(f i) :=
mk_congr <| Equiv.sigmaCongrRight fun _ => outMkEquiv.symm
#align cardinal.mk_sigma Cardinal.mk_sigma
@[simp]
theorem sum_const (ι : Type u) (a : Cardinal.{v}) :
(sum fun _ : ι => a) = lift.{v} #ι * lift.{u} a :=
inductionOn a fun α =>
mk_congr <|
calc
(Σ _ : ι, Quotient.out #α) ≃ ι × Quotient.out #α := Equiv.sigmaEquivProd _ _
_ ≃ ULift ι × ULift α := Equiv.ulift.symm.prodCongr (outMkEquiv.trans Equiv.ulift.symm)
#align cardinal.sum_const Cardinal.sum_const
theorem sum_const' (ι : Type u) (a : Cardinal.{u}) : (sum fun _ : ι => a) = #ι * a := by simp
#align cardinal.sum_const' Cardinal.sum_const'
@[simp]
theorem sum_add_distrib {ι} (f g : ι → Cardinal) : sum (f + g) = sum f + sum g := by
have := mk_congr (Equiv.sigmaSumDistrib (Quotient.out ∘ f) (Quotient.out ∘ g))
simp only [comp_apply, mk_sigma, mk_sum, mk_out, lift_id] at this
exact this
#align cardinal.sum_add_distrib Cardinal.sum_add_distrib
@[simp]
theorem sum_add_distrib' {ι} (f g : ι → Cardinal) :
(Cardinal.sum fun i => f i + g i) = sum f + sum g :=
sum_add_distrib f g
#align cardinal.sum_add_distrib' Cardinal.sum_add_distrib'
@[simp]
theorem lift_sum {ι : Type u} (f : ι → Cardinal.{v}) :
Cardinal.lift.{w} (Cardinal.sum f) = Cardinal.sum fun i => Cardinal.lift.{w} (f i) :=
Equiv.cardinal_eq <|
Equiv.ulift.trans <|
Equiv.sigmaCongrRight fun a =>
-- Porting note: Inserted universe hint .{_,_,v} below
Nonempty.some <| by rw [← lift_mk_eq.{_,_,v}, mk_out, mk_out, lift_lift]
#align cardinal.lift_sum Cardinal.lift_sum
theorem sum_le_sum {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : sum f ≤ sum g :=
⟨(Embedding.refl _).sigmaMap fun i =>
Classical.choice <| by have := H i; rwa [← Quot.out_eq (f i), ← Quot.out_eq (g i)] at this⟩
#align cardinal.sum_le_sum Cardinal.sum_le_sum
theorem mk_le_mk_mul_of_mk_preimage_le {c : Cardinal} (f : α → β) (hf : ∀ b : β, #(f ⁻¹' {b}) ≤ c) :
#α ≤ #β * c := by
simpa only [← mk_congr (@Equiv.sigmaFiberEquiv α β f), mk_sigma, ← sum_const'] using
sum_le_sum _ _ hf
#align cardinal.mk_le_mk_mul_of_mk_preimage_le Cardinal.mk_le_mk_mul_of_mk_preimage_le
theorem lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le {α : Type u} {β : Type v} {c : Cardinal}
(f : α → β) (hf : ∀ b : β, lift.{v} #(f ⁻¹' {b}) ≤ c) : lift.{v} #α ≤ lift.{u} #β * c :=
(mk_le_mk_mul_of_mk_preimage_le fun x : ULift.{v} α => ULift.up.{u} (f x.1)) <|
ULift.forall.2 fun b =>
(mk_congr <|
(Equiv.ulift.image _).trans
(Equiv.trans
(by
rw [Equiv.image_eq_preimage]
/- Porting note: Need to insert the following `have` b/c bad fun coercion
behaviour for Equivs -/
have : DFunLike.coe (Equiv.symm (Equiv.ulift (α := α))) = ULift.up (α := α) := rfl
rw [this]
simp only [preimage, mem_singleton_iff, ULift.up_inj, mem_setOf_eq, coe_setOf]
exact Equiv.refl _)
Equiv.ulift.symm)).trans_le
(hf b)
#align cardinal.lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le Cardinal.lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le
/-- The range of an indexed cardinal function, whose outputs live in a higher universe than the
inputs, is always bounded above. -/
theorem bddAbove_range {ι : Type u} (f : ι → Cardinal.{max u v}) : BddAbove (Set.range f) :=
⟨_, by
rintro a ⟨i, rfl⟩
-- Porting note: Added universe reference below
exact le_sum.{v,u} f i⟩
#align cardinal.bdd_above_range Cardinal.bddAbove_range
instance (a : Cardinal.{u}) : Small.{u} (Set.Iic a) := by
rw [← mk_out a]
apply @small_of_surjective (Set a.out) (Iic #a.out) _ fun x => ⟨#x, mk_set_le x⟩
rintro ⟨x, hx⟩
simpa using le_mk_iff_exists_set.1 hx
instance (a : Cardinal.{u}) : Small.{u} (Set.Iio a) :=
small_subset Iio_subset_Iic_self
/-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to a usual ZFC set. -/
theorem bddAbove_iff_small {s : Set Cardinal.{u}} : BddAbove s ↔ Small.{u} s :=
⟨fun ⟨a, ha⟩ => @small_subset _ (Iic a) s (fun x h => ha h) _, by
rintro ⟨ι, ⟨e⟩⟩
suffices (range fun x : ι => (e.symm x).1) = s by
rw [← this]
apply bddAbove_range.{u, u}
ext x
refine ⟨?_, fun hx => ⟨e ⟨x, hx⟩, ?_⟩⟩
· rintro ⟨a, rfl⟩
exact (e.symm a).2
· simp_rw [Equiv.symm_apply_apply]⟩
#align cardinal.bdd_above_iff_small Cardinal.bddAbove_iff_small
theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s :=
bddAbove_iff_small.2 h
#align cardinal.bdd_above_of_small Cardinal.bddAbove_of_small
theorem bddAbove_image (f : Cardinal.{u} → Cardinal.{max u v}) {s : Set Cardinal.{u}}
(hs : BddAbove s) : BddAbove (f '' s) := by
rw [bddAbove_iff_small] at hs ⊢
-- Porting note: added universes below
exact small_lift.{_,v,_} _
#align cardinal.bdd_above_image Cardinal.bddAbove_image
theorem bddAbove_range_comp {ι : Type u} {f : ι → Cardinal.{v}} (hf : BddAbove (range f))
(g : Cardinal.{v} → Cardinal.{max v w}) : BddAbove (range (g ∘ f)) := by
rw [range_comp]
exact bddAbove_image.{v,w} g hf
#align cardinal.bdd_above_range_comp Cardinal.bddAbove_range_comp
theorem iSup_le_sum {ι} (f : ι → Cardinal) : iSup f ≤ sum f :=
ciSup_le' <| le_sum.{u_2,u_1} _
#align cardinal.supr_le_sum Cardinal.iSup_le_sum
-- Porting note: Added universe hint .{v,_} below
theorem sum_le_iSup_lift {ι : Type u}
(f : ι → Cardinal.{max u v}) : sum f ≤ Cardinal.lift.{v,_} #ι * iSup f := by
rw [← (iSup f).lift_id, ← lift_umax, lift_umax.{max u v, u}, ← sum_const]
exact sum_le_sum _ _ (le_ciSup <| bddAbove_range.{u, v} f)
#align cardinal.sum_le_supr_lift Cardinal.sum_le_iSup_lift
theorem sum_le_iSup {ι : Type u} (f : ι → Cardinal.{u}) : sum f ≤ #ι * iSup f := by
rw [← lift_id #ι]
exact sum_le_iSup_lift f
#align cardinal.sum_le_supr Cardinal.sum_le_iSup
theorem sum_nat_eq_add_sum_succ (f : ℕ → Cardinal.{u}) :
Cardinal.sum f = f 0 + Cardinal.sum fun i => f (i + 1) := by
refine (Equiv.sigmaNatSucc fun i => Quotient.out (f i)).cardinal_eq.trans ?_
simp only [mk_sum, mk_out, lift_id, mk_sigma]
#align cardinal.sum_nat_eq_add_sum_succ Cardinal.sum_nat_eq_add_sum_succ
-- Porting note: LFS is not in normal form.
-- @[simp]
/-- A variant of `ciSup_of_empty` but with `0` on the RHS for convenience -/
protected theorem iSup_of_empty {ι} (f : ι → Cardinal) [IsEmpty ι] : iSup f = 0 :=
ciSup_of_empty f
#align cardinal.supr_of_empty Cardinal.iSup_of_empty
lemma exists_eq_of_iSup_eq_of_not_isSuccLimit
{ι : Type u} (f : ι → Cardinal.{v}) (ω : Cardinal.{v})
(hω : ¬ Order.IsSuccLimit ω)
(h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by
subst h
refine (isLUB_csSup' ?_).exists_of_not_isSuccLimit hω
contrapose! hω with hf
rw [iSup, csSup_of_not_bddAbove hf, csSup_empty]
exact Order.isSuccLimit_bot
lemma exists_eq_of_iSup_eq_of_not_isLimit
{ι : Type u} [hι : Nonempty ι] (f : ι → Cardinal.{v}) (hf : BddAbove (range f))
(ω : Cardinal.{v}) (hω : ¬ ω.IsLimit)
(h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by
refine (not_and_or.mp hω).elim (fun e ↦ ⟨hι.some, ?_⟩)
(Cardinal.exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f ω · h)
cases not_not.mp e
rw [← le_zero_iff] at h ⊢
exact (le_ciSup hf _).trans h
-- Porting note: simpNF is not happy with universe levels.
@[simp, nolint simpNF]
theorem lift_mk_shrink (α : Type u) [Small.{v} α] :
Cardinal.lift.{max u w} #(Shrink.{v} α) = Cardinal.lift.{max v w} #α :=
-- Porting note: Added .{v,u,w} universe hint below
lift_mk_eq.{v,u,w}.2 ⟨(equivShrink α).symm⟩
#align cardinal.lift_mk_shrink Cardinal.lift_mk_shrink
@[simp]
theorem lift_mk_shrink' (α : Type u) [Small.{v} α] :
Cardinal.lift.{u} #(Shrink.{v} α) = Cardinal.lift.{v} #α :=
lift_mk_shrink.{u, v, 0} α
#align cardinal.lift_mk_shrink' Cardinal.lift_mk_shrink'
@[simp]
theorem lift_mk_shrink'' (α : Type max u v) [Small.{v} α] :
Cardinal.lift.{u} #(Shrink.{v} α) = #α := by
rw [← lift_umax', lift_mk_shrink.{max u v, v, 0} α, ← lift_umax, lift_id]
#align cardinal.lift_mk_shrink'' Cardinal.lift_mk_shrink''
/-- The indexed product of cardinals is the cardinality of the Pi type
(dependent product). -/
def prod {ι : Type u} (f : ι → Cardinal) : Cardinal :=
#(∀ i, (f i).out)
#align cardinal.prod Cardinal.prod
@[simp]
theorem mk_pi {ι : Type u} (α : ι → Type v) : #(∀ i, α i) = prod fun i => #(α i) :=
mk_congr <| Equiv.piCongrRight fun _ => outMkEquiv.symm
#align cardinal.mk_pi Cardinal.mk_pi
@[simp]
theorem prod_const (ι : Type u) (a : Cardinal.{v}) :
(prod fun _ : ι => a) = lift.{u} a ^ lift.{v} #ι :=
inductionOn a fun _ =>
mk_congr <| Equiv.piCongr Equiv.ulift.symm fun _ => outMkEquiv.trans Equiv.ulift.symm
#align cardinal.prod_const Cardinal.prod_const
theorem prod_const' (ι : Type u) (a : Cardinal.{u}) : (prod fun _ : ι => a) = a ^ #ι :=
inductionOn a fun _ => (mk_pi _).symm
#align cardinal.prod_const' Cardinal.prod_const'
theorem prod_le_prod {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : prod f ≤ prod g :=
⟨Embedding.piCongrRight fun i =>
Classical.choice <| by have := H i; rwa [← mk_out (f i), ← mk_out (g i)] at this⟩
#align cardinal.prod_le_prod Cardinal.prod_le_prod
@[simp]
theorem prod_eq_zero {ι} (f : ι → Cardinal.{u}) : prod f = 0 ↔ ∃ i, f i = 0 := by
lift f to ι → Type u using fun _ => trivial
simp only [mk_eq_zero_iff, ← mk_pi, isEmpty_pi]
#align cardinal.prod_eq_zero Cardinal.prod_eq_zero
theorem prod_ne_zero {ι} (f : ι → Cardinal) : prod f ≠ 0 ↔ ∀ i, f i ≠ 0 := by simp [prod_eq_zero]
#align cardinal.prod_ne_zero Cardinal.prod_ne_zero
@[simp]
theorem lift_prod {ι : Type u} (c : ι → Cardinal.{v}) :
lift.{w} (prod c) = prod fun i => lift.{w} (c i) := by
lift c to ι → Type v using fun _ => trivial
simp only [← mk_pi, ← mk_uLift]
exact mk_congr (Equiv.ulift.trans <| Equiv.piCongrRight fun i => Equiv.ulift.symm)
#align cardinal.lift_prod Cardinal.lift_prod
theorem prod_eq_of_fintype {α : Type u} [h : Fintype α] (f : α → Cardinal.{v}) :
prod f = Cardinal.lift.{u} (∏ i, f i) := by
revert f
refine Fintype.induction_empty_option ?_ ?_ ?_ α (h_fintype := h)
· intro α β hβ e h f
letI := Fintype.ofEquiv β e.symm
rw [← e.prod_comp f, ← h]
exact mk_congr (e.piCongrLeft _).symm
· intro f
rw [Fintype.univ_pempty, Finset.prod_empty, lift_one, Cardinal.prod, mk_eq_one]
· intro α hα h f
rw [Cardinal.prod, mk_congr Equiv.piOptionEquivProd, mk_prod, lift_umax'.{v, u}, mk_out, ←
Cardinal.prod, lift_prod, Fintype.prod_option, lift_mul, ← h fun a => f (some a)]
simp only [lift_id]
#align cardinal.prod_eq_of_fintype Cardinal.prod_eq_of_fintype
-- Porting note: Inserted .{u,v} below
@[simp]
theorem lift_sInf (s : Set Cardinal) : lift.{u,v} (sInf s) = sInf (lift.{u,v} '' s) := by
rcases eq_empty_or_nonempty s with (rfl | hs)
· simp
· exact lift_monotone.map_csInf hs
#align cardinal.lift_Inf Cardinal.lift_sInf
-- Porting note: Inserted .{u,v} below
@[simp]
theorem lift_iInf {ι} (f : ι → Cardinal) : lift.{u,v} (iInf f) = ⨅ i, lift.{u,v} (f i) := by
unfold iInf
convert lift_sInf (range f)
simp_rw [← comp_apply (f := lift), range_comp]
#align cardinal.lift_infi Cardinal.lift_iInf
theorem lift_down {a : Cardinal.{u}} {b : Cardinal.{max u v}} :
b ≤ lift.{v,u} a → ∃ a', lift.{v,u} a' = b :=
inductionOn₂ a b fun α β => by
rw [← lift_id #β, ← lift_umax, ← lift_umax.{u, v}, lift_mk_le.{v}]
exact fun ⟨f⟩ =>
⟨#(Set.range f),
Eq.symm <| lift_mk_eq.{_, _, v}.2
⟨Function.Embedding.equivOfSurjective (Embedding.codRestrict _ f Set.mem_range_self)
fun ⟨a, ⟨b, e⟩⟩ => ⟨b, Subtype.eq e⟩⟩⟩
#align cardinal.lift_down Cardinal.lift_down
-- Porting note: Inserted .{u,v} below
theorem le_lift_iff {a : Cardinal.{u}} {b : Cardinal.{max u v}} :
b ≤ lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' ≤ a :=
⟨fun h =>
let ⟨a', e⟩ := lift_down h
⟨a', e, lift_le.1 <| e.symm ▸ h⟩,
fun ⟨_, e, h⟩ => e ▸ lift_le.2 h⟩
#align cardinal.le_lift_iff Cardinal.le_lift_iff
-- Porting note: Inserted .{u,v} below
theorem lt_lift_iff {a : Cardinal.{u}} {b : Cardinal.{max u v}} :
b < lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' < a :=
⟨fun h =>
let ⟨a', e⟩ := lift_down h.le
⟨a', e, lift_lt.1 <| e.symm ▸ h⟩,
fun ⟨_, e, h⟩ => e ▸ lift_lt.2 h⟩
#align cardinal.lt_lift_iff Cardinal.lt_lift_iff
-- Porting note: Inserted .{u,v} below
@[simp]
theorem lift_succ (a) : lift.{v,u} (succ a) = succ (lift.{v,u} a) :=
le_antisymm
(le_of_not_gt fun h => by
rcases lt_lift_iff.1 h with ⟨b, e, h⟩
rw [lt_succ_iff, ← lift_le, e] at h
exact h.not_lt (lt_succ _))
(succ_le_of_lt <| lift_lt.2 <| lt_succ a)
#align cardinal.lift_succ Cardinal.lift_succ
-- Porting note: simpNF is not happy with universe levels.
-- Porting note: Inserted .{u,v} below
@[simp, nolint simpNF]
theorem lift_umax_eq {a : Cardinal.{u}} {b : Cardinal.{v}} :
lift.{max v w} a = lift.{max u w} b ↔ lift.{v} a = lift.{u} b := by
rw [← lift_lift.{v, w, u}, ← lift_lift.{u, w, v}, lift_inj]
#align cardinal.lift_umax_eq Cardinal.lift_umax_eq
-- Porting note: Inserted .{u,v} below
@[simp]
theorem lift_min {a b : Cardinal} : lift.{u,v} (min a b) = min (lift.{u,v} a) (lift.{u,v} b) :=
lift_monotone.map_min
#align cardinal.lift_min Cardinal.lift_min
-- Porting note: Inserted .{u,v} below
@[simp]
theorem lift_max {a b : Cardinal} : lift.{u,v} (max a b) = max (lift.{u,v} a) (lift.{u,v} b) :=
lift_monotone.map_max
#align cardinal.lift_max Cardinal.lift_max
/-- The lift of a supremum is the supremum of the lifts. -/
theorem lift_sSup {s : Set Cardinal} (hs : BddAbove s) :
lift.{u} (sSup s) = sSup (lift.{u} '' s) := by
apply ((le_csSup_iff' (bddAbove_image.{_,u} _ hs)).2 fun c hc => _).antisymm (csSup_le' _)
· intro c hc
by_contra h
obtain ⟨d, rfl⟩ := Cardinal.lift_down (not_le.1 h).le
simp_rw [lift_le] at h hc
rw [csSup_le_iff' hs] at h
exact h fun a ha => lift_le.1 <| hc (mem_image_of_mem _ ha)
· rintro i ⟨j, hj, rfl⟩
exact lift_le.2 (le_csSup hs hj)
#align cardinal.lift_Sup Cardinal.lift_sSup
/-- The lift of a supremum is the supremum of the lifts. -/
theorem lift_iSup {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) :
lift.{u} (iSup f) = ⨆ i, lift.{u} (f i) := by
rw [iSup, iSup, lift_sSup hf, ← range_comp]
simp [Function.comp]
#align cardinal.lift_supr Cardinal.lift_iSup
/-- To prove that the lift of a supremum is bounded by some cardinal `t`,
it suffices to show that the lift of each cardinal is bounded by `t`. -/
theorem lift_iSup_le {ι : Type v} {f : ι → Cardinal.{w}} {t : Cardinal} (hf : BddAbove (range f))
(w : ∀ i, lift.{u} (f i) ≤ t) : lift.{u} (iSup f) ≤ t := by
rw [lift_iSup hf]
exact ciSup_le' w
#align cardinal.lift_supr_le Cardinal.lift_iSup_le
@[simp]
theorem lift_iSup_le_iff {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f))
{t : Cardinal} : lift.{u} (iSup f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t := by
rw [lift_iSup hf]
exact ciSup_le_iff' (bddAbove_range_comp.{_,_,u} hf _)
#align cardinal.lift_supr_le_iff Cardinal.lift_iSup_le_iff
universe v' w'
/-- To prove an inequality between the lifts to a common universe of two different supremums,
it suffices to show that the lift of each cardinal from the smaller supremum
if bounded by the lift of some cardinal from the larger supremum.
-/
theorem lift_iSup_le_lift_iSup {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{w}}
{f' : ι' → Cardinal.{w'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) {g : ι → ι'}
(h : ∀ i, lift.{w'} (f i) ≤ lift.{w} (f' (g i))) : lift.{w'} (iSup f) ≤ lift.{w} (iSup f') := by
rw [lift_iSup hf, lift_iSup hf']
exact ciSup_mono' (bddAbove_range_comp.{_,_,w} hf' _) fun i => ⟨_, h i⟩
#align cardinal.lift_supr_le_lift_supr Cardinal.lift_iSup_le_lift_iSup
/-- A variant of `lift_iSup_le_lift_iSup` with universes specialized via `w = v` and `w' = v'`.
This is sometimes necessary to avoid universe unification issues. -/
theorem lift_iSup_le_lift_iSup' {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{v}}
{f' : ι' → Cardinal.{v'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) (g : ι → ι')
(h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) : lift.{v'} (iSup f) ≤ lift.{v} (iSup f') :=
lift_iSup_le_lift_iSup hf hf' h
#align cardinal.lift_supr_le_lift_supr' Cardinal.lift_iSup_le_lift_iSup'
/-- `ℵ₀` is the smallest infinite cardinal. -/
def aleph0 : Cardinal.{u} :=
lift #ℕ
#align cardinal.aleph_0 Cardinal.aleph0
@[inherit_doc]
scoped notation "ℵ₀" => Cardinal.aleph0
theorem mk_nat : #ℕ = ℵ₀ :=
(lift_id _).symm
#align cardinal.mk_nat Cardinal.mk_nat
theorem aleph0_ne_zero : ℵ₀ ≠ 0 :=
mk_ne_zero _
#align cardinal.aleph_0_ne_zero Cardinal.aleph0_ne_zero
theorem aleph0_pos : 0 < ℵ₀ :=
pos_iff_ne_zero.2 aleph0_ne_zero
#align cardinal.aleph_0_pos Cardinal.aleph0_pos
@[simp]
theorem lift_aleph0 : lift ℵ₀ = ℵ₀ :=
lift_lift _
#align cardinal.lift_aleph_0 Cardinal.lift_aleph0
@[simp]
theorem aleph0_le_lift {c : Cardinal.{u}} : ℵ₀ ≤ lift.{v} c ↔ ℵ₀ ≤ c := by
rw [← lift_aleph0.{u,v}, lift_le]
#align cardinal.aleph_0_le_lift Cardinal.aleph0_le_lift
@[simp]
theorem lift_le_aleph0 {c : Cardinal.{u}} : lift.{v} c ≤ ℵ₀ ↔ c ≤ ℵ₀ := by
rw [← lift_aleph0.{u,v}, lift_le]
#align cardinal.lift_le_aleph_0 Cardinal.lift_le_aleph0
@[simp]
theorem aleph0_lt_lift {c : Cardinal.{u}} : ℵ₀ < lift.{v} c ↔ ℵ₀ < c := by
rw [← lift_aleph0.{u,v}, lift_lt]
#align cardinal.aleph_0_lt_lift Cardinal.aleph0_lt_lift
@[simp]
theorem lift_lt_aleph0 {c : Cardinal.{u}} : lift.{v} c < ℵ₀ ↔ c < ℵ₀ := by
rw [← lift_aleph0.{u,v}, lift_lt]
#align cardinal.lift_lt_aleph_0 Cardinal.lift_lt_aleph0
/-! ### Properties about the cast from `ℕ` -/
section castFromN
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_fin (n : ℕ) : #(Fin n) = n := by simp
#align cardinal.mk_fin Cardinal.mk_fin
@[simp]
theorem lift_natCast (n : ℕ) : lift.{u} (n : Cardinal.{v}) = n := by induction n <;> simp [*]
#align cardinal.lift_nat_cast Cardinal.lift_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] :
lift.{u} (no_index (OfNat.ofNat n : Cardinal.{v})) = OfNat.ofNat n :=
lift_natCast n
@[simp]
theorem lift_eq_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a = n ↔ a = n :=
lift_injective.eq_iff' (lift_natCast n)
#align cardinal.lift_eq_nat_iff Cardinal.lift_eq_nat_iff
@[simp]
theorem lift_eq_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
lift.{v} a = (no_index (OfNat.ofNat n)) ↔ a = OfNat.ofNat n :=
lift_eq_nat_iff
@[simp]
theorem nat_eq_lift_iff {n : ℕ} {a : Cardinal.{u}} :
(n : Cardinal) = lift.{v} a ↔ (n : Cardinal) = a := by
rw [← lift_natCast.{v,u} n, lift_inj]
#align cardinal.nat_eq_lift_iff Cardinal.nat_eq_lift_iff
@[simp]
theorem zero_eq_lift_iff {a : Cardinal.{u}} :
(0 : Cardinal) = lift.{v} a ↔ 0 = a := by
simpa using nat_eq_lift_iff (n := 0)
@[simp]
theorem one_eq_lift_iff {a : Cardinal.{u}} :
(1 : Cardinal) = lift.{v} a ↔ 1 = a := by
simpa using nat_eq_lift_iff (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_eq_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
(no_index (OfNat.ofNat n : Cardinal)) = lift.{v} a ↔ (OfNat.ofNat n : Cardinal) = a :=
nat_eq_lift_iff
@[simp]
theorem lift_le_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a ≤ n ↔ a ≤ n := by
rw [← lift_natCast.{v,u}, lift_le]
#align cardinal.lift_le_nat_iff Cardinal.lift_le_nat_iff
@[simp]
theorem lift_le_one_iff {a : Cardinal.{u}} :
lift.{v} a ≤ 1 ↔ a ≤ 1 := by
simpa using lift_le_nat_iff (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem lift_le_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
lift.{v} a ≤ (no_index (OfNat.ofNat n)) ↔ a ≤ OfNat.ofNat n :=
lift_le_nat_iff
@[simp]
theorem nat_le_lift_iff {n : ℕ} {a : Cardinal.{u}} : n ≤ lift.{v} a ↔ n ≤ a := by
rw [← lift_natCast.{v,u}, lift_le]
#align cardinal.nat_le_lift_iff Cardinal.nat_le_lift_iff
@[simp]
theorem one_le_lift_iff {a : Cardinal.{u}} :
(1 : Cardinal) ≤ lift.{v} a ↔ 1 ≤ a := by
simpa using nat_le_lift_iff (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_le_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
(no_index (OfNat.ofNat n : Cardinal)) ≤ lift.{v} a ↔ (OfNat.ofNat n : Cardinal) ≤ a :=
nat_le_lift_iff
@[simp]
theorem lift_lt_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a < n ↔ a < n := by
rw [← lift_natCast.{v,u}, lift_lt]
#align cardinal.lift_lt_nat_iff Cardinal.lift_lt_nat_iff
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem lift_lt_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
lift.{v} a < (no_index (OfNat.ofNat n)) ↔ a < OfNat.ofNat n :=
lift_lt_nat_iff
@[simp]
theorem nat_lt_lift_iff {n : ℕ} {a : Cardinal.{u}} : n < lift.{v} a ↔ n < a := by
rw [← lift_natCast.{v,u}, lift_lt]
#align cardinal.nat_lt_lift_iff Cardinal.nat_lt_lift_iff
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem zero_lt_lift_iff {a : Cardinal.{u}} :
(0 : Cardinal) < lift.{v} a ↔ 0 < a := by
simpa using nat_lt_lift_iff (n := 0)
@[simp]
theorem one_lt_lift_iff {a : Cardinal.{u}} :
(1 : Cardinal) < lift.{v} a ↔ 1 < a := by
simpa using nat_lt_lift_iff (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_lt_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
(no_index (OfNat.ofNat n : Cardinal)) < lift.{v} a ↔ (OfNat.ofNat n : Cardinal) < a :=
nat_lt_lift_iff
theorem lift_mk_fin (n : ℕ) : lift #(Fin n) = n := rfl
#align cardinal.lift_mk_fin Cardinal.lift_mk_fin
theorem mk_coe_finset {α : Type u} {s : Finset α} : #s = ↑(Finset.card s) := by simp
#align cardinal.mk_coe_finset Cardinal.mk_coe_finset
theorem mk_finset_of_fintype [Fintype α] : #(Finset α) = 2 ^ Fintype.card α := by
simp [Pow.pow]
#align cardinal.mk_finset_of_fintype Cardinal.mk_finset_of_fintype
@[simp]
theorem mk_finsupp_lift_of_fintype (α : Type u) (β : Type v) [Fintype α] [Zero β] :
#(α →₀ β) = lift.{u} #β ^ Fintype.card α := by
simpa using (@Finsupp.equivFunOnFinite α β _ _).cardinal_eq
#align cardinal.mk_finsupp_lift_of_fintype Cardinal.mk_finsupp_lift_of_fintype
theorem mk_finsupp_of_fintype (α β : Type u) [Fintype α] [Zero β] :
#(α →₀ β) = #β ^ Fintype.card α := by simp
#align cardinal.mk_finsupp_of_fintype Cardinal.mk_finsupp_of_fintype
theorem card_le_of_finset {α} (s : Finset α) : (s.card : Cardinal) ≤ #α :=
@mk_coe_finset _ s ▸ mk_set_le _
#align cardinal.card_le_of_finset Cardinal.card_le_of_finset
-- Porting note: was `simp`. LHS is not normal form.
-- @[simp, norm_cast]
@[norm_cast]
theorem natCast_pow {m n : ℕ} : (↑(m ^ n) : Cardinal) = (↑m : Cardinal) ^ (↑n : Cardinal) := by
induction n <;> simp [pow_succ, power_add, *, Pow.pow]
#align cardinal.nat_cast_pow Cardinal.natCast_pow
-- porting note (#10618): simp can prove this
-- @[simp, norm_cast]
@[norm_cast]
theorem natCast_le {m n : ℕ} : (m : Cardinal) ≤ n ↔ m ≤ n := by
rw [← lift_mk_fin, ← lift_mk_fin, lift_le, le_def, Function.Embedding.nonempty_iff_card_le,
Fintype.card_fin, Fintype.card_fin]
#align cardinal.nat_cast_le Cardinal.natCast_le
-- porting note (#10618): simp can prove this
-- @[simp, norm_cast]
@[norm_cast]
theorem natCast_lt {m n : ℕ} : (m : Cardinal) < n ↔ m < n := by
rw [lt_iff_le_not_le, ← not_le]
simp only [natCast_le, not_le, and_iff_right_iff_imp]
exact fun h ↦ le_of_lt h
#align cardinal.nat_cast_lt Cardinal.natCast_lt
instance : CharZero Cardinal :=
⟨StrictMono.injective fun _ _ => natCast_lt.2⟩
theorem natCast_inj {m n : ℕ} : (m : Cardinal) = n ↔ m = n :=
Nat.cast_inj
#align cardinal.nat_cast_inj Cardinal.natCast_inj
theorem natCast_injective : Injective ((↑) : ℕ → Cardinal) :=
Nat.cast_injective
#align cardinal.nat_cast_injective Cardinal.natCast_injective
@[norm_cast]
theorem nat_succ (n : ℕ) : (n.succ : Cardinal) = succ ↑n := by
rw [Nat.cast_succ]
refine (add_one_le_succ _).antisymm (succ_le_of_lt ?_)
rw [← Nat.cast_succ]
exact natCast_lt.2 (Nat.lt_succ_self _)
lemma succ_natCast (n : ℕ) : Order.succ (n : Cardinal) = n + 1 := by
rw [← Cardinal.nat_succ]
norm_cast
lemma natCast_add_one_le_iff {n : ℕ} {c : Cardinal} : n + 1 ≤ c ↔ n < c := by
rw [← Order.succ_le_iff, Cardinal.succ_natCast]
lemma two_le_iff_one_lt {c : Cardinal} : 2 ≤ c ↔ 1 < c := by
convert natCast_add_one_le_iff
norm_cast
@[simp]
theorem succ_zero : succ (0 : Cardinal) = 1 := by norm_cast
#align cardinal.succ_zero Cardinal.succ_zero
theorem exists_finset_le_card (α : Type*) (n : ℕ) (h : n ≤ #α) :
∃ s : Finset α, n ≤ s.card := by
obtain hα|hα := finite_or_infinite α
· let hα := Fintype.ofFinite α
use Finset.univ
simpa only [mk_fintype, Nat.cast_le] using h
· obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq α n
exact ⟨s, hs.ge⟩
theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : Finset α, s.card ≤ n) : #α ≤ n := by
contrapose! H
apply exists_finset_le_card α (n+1)
simpa only [nat_succ, succ_le_iff] using H
#align cardinal.card_le_of Cardinal.card_le_of
theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by
rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb
exact (cantor a).trans_le (power_le_power_right hb)
#align cardinal.cantor' Cardinal.cantor'
theorem one_le_iff_pos {c : Cardinal} : 1 ≤ c ↔ 0 < c := by
rw [← succ_zero, succ_le_iff]
#align cardinal.one_le_iff_pos Cardinal.one_le_iff_pos
theorem one_le_iff_ne_zero {c : Cardinal} : 1 ≤ c ↔ c ≠ 0 := by
rw [one_le_iff_pos, pos_iff_ne_zero]
#align cardinal.one_le_iff_ne_zero Cardinal.one_le_iff_ne_zero
@[simp]
| Mathlib/SetTheory/Cardinal/Basic.lean | 1,535 | 1,536 | theorem lt_one_iff_zero {c : Cardinal} : c < 1 ↔ c = 0 := by |
simpa using lt_succ_bot_iff (a := c)
|
/-
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.Polynomial.Expand
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.LinearAlgebra.Matrix.Charpoly.LinearMap
import Mathlib.RingTheory.Adjoin.FG
import Mathlib.RingTheory.FiniteType
import Mathlib.RingTheory.Polynomial.ScaleRoots
import Mathlib.RingTheory.Polynomial.Tower
import Mathlib.RingTheory.TensorProduct.Basic
#align_import ring_theory.integral_closure from "leanprover-community/mathlib"@"641b6a82006416ec431b2987b354af9311fed4f2"
/-!
# Integral closure of a subring.
If A is an R-algebra then `a : A` is integral over R if it is a root of a monic polynomial
with coefficients in R. Enough theory is developed to prove that integral elements
form a sub-R-algebra of A.
## Main definitions
Let `R` be a `CommRing` and let `A` be an R-algebra.
* `RingHom.IsIntegralElem (f : R →+* A) (x : A)` : `x` is integral with respect to the map `f`,
* `IsIntegral (x : A)` : `x` is integral over `R`, i.e., is a root of a monic polynomial with
coefficients in `R`.
* `integralClosure R A` : the integral closure of `R` in `A`, regarded as a sub-`R`-algebra of `A`.
-/
open scoped Classical
open Polynomial Submodule
section Ring
variable {R S A : Type*}
variable [CommRing R] [Ring A] [Ring S] (f : R →+* S)
/-- An element `x` of `A` is said to be integral over `R` with respect to `f`
if it is a root of a monic polynomial `p : R[X]` evaluated under `f` -/
def RingHom.IsIntegralElem (f : R →+* A) (x : A) :=
∃ p : R[X], Monic p ∧ eval₂ f x p = 0
#align ring_hom.is_integral_elem RingHom.IsIntegralElem
/-- A ring homomorphism `f : R →+* A` is said to be integral
if every element `A` is integral with respect to the map `f` -/
def RingHom.IsIntegral (f : R →+* A) :=
∀ x : A, f.IsIntegralElem x
#align ring_hom.is_integral RingHom.IsIntegral
variable [Algebra R A] (R)
/-- An element `x` of an algebra `A` over a commutative ring `R` is said to be *integral*,
if it is a root of some monic polynomial `p : R[X]`.
Equivalently, the element is integral over `R` with respect to the induced `algebraMap` -/
def IsIntegral (x : A) : Prop :=
(algebraMap R A).IsIntegralElem x
#align is_integral IsIntegral
variable (A)
/-- An algebra is integral if every element of the extension is integral over the base ring -/
protected class Algebra.IsIntegral : Prop :=
isIntegral : ∀ x : A, IsIntegral R x
#align algebra.is_integral Algebra.IsIntegral
variable {R A}
lemma Algebra.isIntegral_def : Algebra.IsIntegral R A ↔ ∀ x : A, IsIntegral R x :=
⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩
theorem RingHom.isIntegralElem_map {x : R} : f.IsIntegralElem (f x) :=
⟨X - C x, monic_X_sub_C _, by simp⟩
#align ring_hom.is_integral_map RingHom.isIntegralElem_map
theorem isIntegral_algebraMap {x : R} : IsIntegral R (algebraMap R A x) :=
(algebraMap R A).isIntegralElem_map
#align is_integral_algebra_map isIntegral_algebraMap
end Ring
section
variable {R A B S : Type*}
variable [CommRing R] [CommRing A] [Ring B] [CommRing S]
variable [Algebra R A] [Algebra R B] (f : R →+* S)
theorem IsIntegral.map {B C F : Type*} [Ring B] [Ring C] [Algebra R B] [Algebra A B] [Algebra R C]
[IsScalarTower R A B] [Algebra A C] [IsScalarTower R A C] {b : B}
[FunLike F B C] [AlgHomClass F A B C] (f : F)
(hb : IsIntegral R b) : IsIntegral R (f b) := by
obtain ⟨P, hP⟩ := hb
refine ⟨P, hP.1, ?_⟩
rw [← aeval_def, ← aeval_map_algebraMap A,
aeval_algHom_apply, aeval_map_algebraMap, aeval_def, hP.2, _root_.map_zero]
#align map_is_integral IsIntegral.map
theorem IsIntegral.map_of_comp_eq {R S T U : Type*} [CommRing R] [Ring S]
[CommRing T] [Ring U] [Algebra R S] [Algebra T U] (φ : R →+* T) (ψ : S →+* U)
(h : (algebraMap T U).comp φ = ψ.comp (algebraMap R S)) {a : S} (ha : IsIntegral R a) :
IsIntegral T (ψ a) :=
let ⟨p, hp⟩ := ha
⟨p.map φ, hp.1.map _, by
rw [← eval_map, map_map, h, ← map_map, eval_map, eval₂_at_apply, eval_map, hp.2, ψ.map_zero]⟩
#align is_integral_map_of_comp_eq_of_is_integral IsIntegral.map_of_comp_eq
section
variable {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B]
variable (f : A →ₐ[R] B) (hf : Function.Injective f)
theorem isIntegral_algHom_iff {x : A} : IsIntegral R (f x) ↔ IsIntegral R x := by
refine ⟨fun ⟨p, hp, hx⟩ ↦ ⟨p, hp, ?_⟩, IsIntegral.map f⟩
rwa [← f.comp_algebraMap, ← AlgHom.coe_toRingHom, ← hom_eval₂, AlgHom.coe_toRingHom,
map_eq_zero_iff f hf] at hx
#align is_integral_alg_hom_iff isIntegral_algHom_iff
theorem Algebra.IsIntegral.of_injective [Algebra.IsIntegral R B] : Algebra.IsIntegral R A :=
⟨fun _ ↦ (isIntegral_algHom_iff f hf).mp (isIntegral _)⟩
end
@[simp]
theorem isIntegral_algEquiv {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B]
(f : A ≃ₐ[R] B) {x : A} : IsIntegral R (f x) ↔ IsIntegral R x :=
⟨fun h ↦ by simpa using h.map f.symm, IsIntegral.map f⟩
#align is_integral_alg_equiv isIntegral_algEquiv
/-- If `R → A → B` is an algebra tower,
then if the entire tower is an integral extension so is `A → B`. -/
theorem IsIntegral.tower_top [Algebra A B] [IsScalarTower R A B] {x : B}
(hx : IsIntegral R x) : IsIntegral A x :=
let ⟨p, hp, hpx⟩ := hx
⟨p.map <| algebraMap R A, hp.map _, by rw [← aeval_def, aeval_map_algebraMap, aeval_def, hpx]⟩
#align is_integral_of_is_scalar_tower IsIntegral.tower_top
#align is_integral_tower_top_of_is_integral IsIntegral.tower_top
theorem map_isIntegral_int {B C F : Type*} [Ring B] [Ring C] {b : B}
[FunLike F B C] [RingHomClass F B C] (f : F)
(hb : IsIntegral ℤ b) : IsIntegral ℤ (f b) :=
hb.map (f : B →+* C).toIntAlgHom
#align map_is_integral_int map_isIntegral_int
theorem IsIntegral.of_subring {x : B} (T : Subring R) (hx : IsIntegral T x) : IsIntegral R x :=
hx.tower_top
#align is_integral_of_subring IsIntegral.of_subring
protected theorem IsIntegral.algebraMap [Algebra A B] [IsScalarTower R A B] {x : A}
(h : IsIntegral R x) : IsIntegral R (algebraMap A B x) := by
rcases h with ⟨f, hf, hx⟩
use f, hf
rw [IsScalarTower.algebraMap_eq R A B, ← hom_eval₂, hx, RingHom.map_zero]
#align is_integral.algebra_map IsIntegral.algebraMap
theorem isIntegral_algebraMap_iff [Algebra A B] [IsScalarTower R A B] {x : A}
(hAB : Function.Injective (algebraMap A B)) :
IsIntegral R (algebraMap A B x) ↔ IsIntegral R x :=
isIntegral_algHom_iff (IsScalarTower.toAlgHom R A B) hAB
#align is_integral_algebra_map_iff isIntegral_algebraMap_iff
theorem isIntegral_iff_isIntegral_closure_finite {r : B} :
IsIntegral R r ↔ ∃ s : Set R, s.Finite ∧ IsIntegral (Subring.closure s) r := by
constructor <;> intro hr
· rcases hr with ⟨p, hmp, hpr⟩
refine ⟨_, Finset.finite_toSet _, p.restriction, monic_restriction.2 hmp, ?_⟩
rw [← aeval_def, ← aeval_map_algebraMap R r p.restriction, map_restriction, aeval_def, hpr]
rcases hr with ⟨s, _, hsr⟩
exact hsr.of_subring _
#align is_integral_iff_is_integral_closure_finite isIntegral_iff_isIntegral_closure_finite
theorem Submodule.span_range_natDegree_eq_adjoin {R A} [CommRing R] [Semiring A] [Algebra R A]
{x : A} {f : R[X]} (hf : f.Monic) (hfx : aeval x f = 0) :
span R (Finset.image (x ^ ·) (Finset.range (natDegree f))) =
Subalgebra.toSubmodule (Algebra.adjoin R {x}) := by
nontriviality A
have hf1 : f ≠ 1 := by rintro rfl; simp [one_ne_zero' A] at hfx
refine (span_le.mpr fun s hs ↦ ?_).antisymm fun r hr ↦ ?_
· rcases Finset.mem_image.1 hs with ⟨k, -, rfl⟩
exact (Algebra.adjoin R {x}).pow_mem (Algebra.subset_adjoin rfl) k
rw [Subalgebra.mem_toSubmodule, Algebra.adjoin_singleton_eq_range_aeval] at hr
rcases (aeval x).mem_range.mp hr with ⟨p, rfl⟩
rw [← modByMonic_add_div p hf, map_add, map_mul, hfx,
zero_mul, add_zero, ← sum_C_mul_X_pow_eq (p %ₘ f), aeval_def, eval₂_sum, sum_def]
refine sum_mem fun k hkq ↦ ?_
rw [C_mul_X_pow_eq_monomial, eval₂_monomial, ← Algebra.smul_def]
exact smul_mem _ _ (subset_span <| Finset.mem_image_of_mem _ <| Finset.mem_range.mpr <|
(le_natDegree_of_mem_supp _ hkq).trans_lt <| natDegree_modByMonic_lt p hf hf1)
theorem IsIntegral.fg_adjoin_singleton {x : B} (hx : IsIntegral R x) :
(Algebra.adjoin R {x}).toSubmodule.FG := by
rcases hx with ⟨f, hfm, hfx⟩
use (Finset.range <| f.natDegree).image (x ^ ·)
exact span_range_natDegree_eq_adjoin hfm (by rwa [aeval_def])
theorem fg_adjoin_of_finite {s : Set A} (hfs : s.Finite) (his : ∀ x ∈ s, IsIntegral R x) :
(Algebra.adjoin R s).toSubmodule.FG :=
Set.Finite.induction_on hfs
(fun _ =>
⟨{1},
Submodule.ext fun x => by
rw [Algebra.adjoin_empty, Finset.coe_singleton, ← one_eq_span, Algebra.toSubmodule_bot]⟩)
(fun {a s} _ _ ih his => by
rw [← Set.union_singleton, Algebra.adjoin_union_coe_submodule]
exact
FG.mul (ih fun i hi => his i <| Set.mem_insert_of_mem a hi)
(his a <| Set.mem_insert a s).fg_adjoin_singleton)
his
#align fg_adjoin_of_finite fg_adjoin_of_finite
theorem isNoetherian_adjoin_finset [IsNoetherianRing R] (s : Finset A)
(hs : ∀ x ∈ s, IsIntegral R x) : IsNoetherian R (Algebra.adjoin R (s : Set A)) :=
isNoetherian_of_fg_of_noetherian _ (fg_adjoin_of_finite s.finite_toSet hs)
#align is_noetherian_adjoin_finset isNoetherian_adjoin_finset
instance Module.End.isIntegral {M : Type*} [AddCommGroup M] [Module R M] [Module.Finite R M] :
Algebra.IsIntegral R (Module.End R M) :=
⟨LinearMap.exists_monic_and_aeval_eq_zero R⟩
#align module.End.is_integral Module.End.isIntegral
variable (R)
theorem IsIntegral.of_finite [Module.Finite R B] (x : B) : IsIntegral R x :=
(isIntegral_algHom_iff (Algebra.lmul R B) Algebra.lmul_injective).mp
(Algebra.IsIntegral.isIntegral _)
variable (B)
instance Algebra.IsIntegral.of_finite [Module.Finite R B] : Algebra.IsIntegral R B :=
⟨.of_finite R⟩
#align algebra.is_integral.of_finite Algebra.IsIntegral.of_finite
variable {R B}
/-- If `S` is a sub-`R`-algebra of `A` and `S` is finitely-generated as an `R`-module,
then all elements of `S` are integral over `R`. -/
theorem IsIntegral.of_mem_of_fg {A} [Ring A] [Algebra R A] (S : Subalgebra R A)
(HS : S.toSubmodule.FG) (x : A) (hx : x ∈ S) : IsIntegral R x :=
have : Module.Finite R S := ⟨(fg_top _).mpr HS⟩
(isIntegral_algHom_iff S.val Subtype.val_injective).mpr (.of_finite R (⟨x, hx⟩ : S))
#align is_integral_of_mem_of_fg IsIntegral.of_mem_of_fg
theorem isIntegral_of_noetherian (_ : IsNoetherian R B) (x : B) : IsIntegral R x :=
.of_finite R x
#align is_integral_of_noetherian isIntegral_of_noetherian
theorem isIntegral_of_submodule_noetherian (S : Subalgebra R B)
(H : IsNoetherian R (Subalgebra.toSubmodule S)) (x : B) (hx : x ∈ S) : IsIntegral R x :=
.of_mem_of_fg _ ((fg_top _).mp <| H.noetherian _) _ hx
#align is_integral_of_submodule_noetherian isIntegral_of_submodule_noetherian
/-- Suppose `A` is an `R`-algebra, `M` is an `A`-module such that `a • m ≠ 0` for all non-zero `a`
and `m`. If `x : A` fixes a nontrivial f.g. `R`-submodule `N` of `M`, then `x` is `R`-integral. -/
theorem isIntegral_of_smul_mem_submodule {M : Type*} [AddCommGroup M] [Module R M] [Module A M]
[IsScalarTower R A M] [NoZeroSMulDivisors A M] (N : Submodule R M) (hN : N ≠ ⊥) (hN' : N.FG)
(x : A) (hx : ∀ n ∈ N, x • n ∈ N) : IsIntegral R x := by
let A' : Subalgebra R A :=
{ carrier := { x | ∀ n ∈ N, x • n ∈ N }
mul_mem' := fun {a b} ha hb n hn => smul_smul a b n ▸ ha _ (hb _ hn)
one_mem' := fun n hn => (one_smul A n).symm ▸ hn
add_mem' := fun {a b} ha hb n hn => (add_smul a b n).symm ▸ N.add_mem (ha _ hn) (hb _ hn)
zero_mem' := fun n _hn => (zero_smul A n).symm ▸ N.zero_mem
algebraMap_mem' := fun r n hn => (algebraMap_smul A r n).symm ▸ N.smul_mem r hn }
let f : A' →ₐ[R] Module.End R N :=
AlgHom.ofLinearMap
{ toFun := fun x => (DistribMulAction.toLinearMap R M x).restrict x.prop
-- Porting note: was
-- `fun x y => LinearMap.ext fun n => Subtype.ext <| add_smul x y n`
map_add' := by intros x y; ext; exact add_smul _ _ _
-- Porting note: was
-- `fun r s => LinearMap.ext fun n => Subtype.ext <| smul_assoc r s n`
map_smul' := by intros r s; ext; apply smul_assoc }
-- Porting note: the next two lines were
--`(LinearMap.ext fun n => Subtype.ext <| one_smul _ _) fun x y =>`
--`LinearMap.ext fun n => Subtype.ext <| mul_smul x y n`
(by ext; apply one_smul)
(by intros x y; ext; apply mul_smul)
obtain ⟨a, ha₁, ha₂⟩ : ∃ a ∈ N, a ≠ (0 : M) := by
by_contra! h'
apply hN
rwa [eq_bot_iff]
have : Function.Injective f := by
show Function.Injective f.toLinearMap
rw [← LinearMap.ker_eq_bot, eq_bot_iff]
intro s hs
have : s.1 • a = 0 := congr_arg Subtype.val (LinearMap.congr_fun hs ⟨a, ha₁⟩)
exact Subtype.ext ((eq_zero_or_eq_zero_of_smul_eq_zero this).resolve_right ha₂)
show IsIntegral R (A'.val ⟨x, hx⟩)
rw [isIntegral_algHom_iff A'.val Subtype.val_injective, ← isIntegral_algHom_iff f this]
haveI : Module.Finite R N := by rwa [Module.finite_def, Submodule.fg_top]
apply Algebra.IsIntegral.isIntegral
#align is_integral_of_smul_mem_submodule isIntegral_of_smul_mem_submodule
variable {f}
theorem RingHom.Finite.to_isIntegral (h : f.Finite) : f.IsIntegral :=
letI := f.toAlgebra
fun _ ↦ IsIntegral.of_mem_of_fg ⊤ h.1 _ trivial
#align ring_hom.finite.to_is_integral RingHom.Finite.to_isIntegral
alias RingHom.IsIntegral.of_finite := RingHom.Finite.to_isIntegral
#align ring_hom.is_integral.of_finite RingHom.IsIntegral.of_finite
/-- The [Kurosh problem](https://en.wikipedia.org/wiki/Kurosh_problem) asks to show that
this is still true when `A` is not necessarily commutative and `R` is a field, but it has
been solved in the negative. See https://arxiv.org/pdf/1706.02383.pdf for criteria for a
finitely generated algebraic (= integral) algebra over a field to be finite dimensional.
This could be an `instance`, but we tend to go from `Module.Finite` to `IsIntegral`/`IsAlgebraic`,
and making it an instance will cause the search to be complicated a lot.
-/
theorem Algebra.IsIntegral.finite [Algebra.IsIntegral R A] [h' : Algebra.FiniteType R A] :
Module.Finite R A :=
have ⟨s, hs⟩ := h'
⟨by apply hs ▸ fg_adjoin_of_finite s.finite_toSet fun x _ ↦ Algebra.IsIntegral.isIntegral x⟩
#align algebra.is_integral.finite Algebra.IsIntegral.finite
/-- finite = integral + finite type -/
theorem Algebra.finite_iff_isIntegral_and_finiteType :
Module.Finite R A ↔ Algebra.IsIntegral R A ∧ Algebra.FiniteType R A :=
⟨fun _ ↦ ⟨⟨.of_finite R⟩, inferInstance⟩, fun ⟨h, _⟩ ↦ h.finite⟩
#align algebra.finite_iff_is_integral_and_finite_type Algebra.finite_iff_isIntegral_and_finiteType
theorem RingHom.IsIntegral.to_finite (h : f.IsIntegral) (h' : f.FiniteType) : f.Finite :=
let _ := f.toAlgebra
let _ : Algebra.IsIntegral R S := ⟨h⟩
Algebra.IsIntegral.finite (h' := h')
#align ring_hom.is_integral.to_finite RingHom.IsIntegral.to_finite
alias RingHom.Finite.of_isIntegral_of_finiteType := RingHom.IsIntegral.to_finite
#align ring_hom.finite.of_is_integral_of_finite_type RingHom.Finite.of_isIntegral_of_finiteType
/-- finite = integral + finite type -/
theorem RingHom.finite_iff_isIntegral_and_finiteType : f.Finite ↔ f.IsIntegral ∧ f.FiniteType :=
⟨fun h ↦ ⟨h.to_isIntegral, h.to_finiteType⟩, fun ⟨h, h'⟩ ↦ h.to_finite h'⟩
#align ring_hom.finite_iff_is_integral_and_finite_type RingHom.finite_iff_isIntegral_and_finiteType
variable (f)
theorem RingHom.IsIntegralElem.of_mem_closure {x y z : S} (hx : f.IsIntegralElem x)
(hy : f.IsIntegralElem y) (hz : z ∈ Subring.closure ({x, y} : Set S)) : f.IsIntegralElem z := by
letI : Algebra R S := f.toAlgebra
have := (IsIntegral.fg_adjoin_singleton hx).mul (IsIntegral.fg_adjoin_singleton hy)
rw [← Algebra.adjoin_union_coe_submodule, Set.singleton_union] at this
exact
IsIntegral.of_mem_of_fg (Algebra.adjoin R {x, y}) this z
(Algebra.mem_adjoin_iff.2 <| Subring.closure_mono Set.subset_union_right hz)
#align ring_hom.is_integral_of_mem_closure RingHom.IsIntegralElem.of_mem_closure
nonrec theorem IsIntegral.of_mem_closure {x y z : A} (hx : IsIntegral R x) (hy : IsIntegral R y)
(hz : z ∈ Subring.closure ({x, y} : Set A)) : IsIntegral R z :=
hx.of_mem_closure (algebraMap R A) hy hz
#align is_integral_of_mem_closure IsIntegral.of_mem_closure
variable (f : R →+* B)
theorem RingHom.isIntegralElem_zero : f.IsIntegralElem 0 :=
f.map_zero ▸ f.isIntegralElem_map
#align ring_hom.is_integral_zero RingHom.isIntegralElem_zero
theorem isIntegral_zero : IsIntegral R (0 : B) :=
(algebraMap R B).isIntegralElem_zero
#align is_integral_zero isIntegral_zero
theorem RingHom.isIntegralElem_one : f.IsIntegralElem 1 :=
f.map_one ▸ f.isIntegralElem_map
#align ring_hom.is_integral_one RingHom.isIntegralElem_one
theorem isIntegral_one : IsIntegral R (1 : B) :=
(algebraMap R B).isIntegralElem_one
#align is_integral_one isIntegral_one
theorem RingHom.IsIntegralElem.add (f : R →+* S) {x y : S}
(hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) :
f.IsIntegralElem (x + y) :=
hx.of_mem_closure f hy <|
Subring.add_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl))
#align ring_hom.is_integral_add RingHom.IsIntegralElem.add
nonrec theorem IsIntegral.add {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) :
IsIntegral R (x + y) :=
hx.add (algebraMap R A) hy
#align is_integral_add IsIntegral.add
variable (f : R →+* S)
-- can be generalized to noncommutative S.
theorem RingHom.IsIntegralElem.neg {x : S} (hx : f.IsIntegralElem x) : f.IsIntegralElem (-x) :=
hx.of_mem_closure f hx (Subring.neg_mem _ (Subring.subset_closure (Or.inl rfl)))
#align ring_hom.is_integral_neg RingHom.IsIntegralElem.neg
theorem IsIntegral.neg {x : B} (hx : IsIntegral R x) : IsIntegral R (-x) :=
.of_mem_of_fg _ hx.fg_adjoin_singleton _ (Subalgebra.neg_mem _ <| Algebra.subset_adjoin rfl)
#align is_integral_neg IsIntegral.neg
theorem RingHom.IsIntegralElem.sub {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) :
f.IsIntegralElem (x - y) := by
simpa only [sub_eq_add_neg] using hx.add f (hy.neg f)
#align ring_hom.is_integral_sub RingHom.IsIntegralElem.sub
nonrec theorem IsIntegral.sub {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) :
IsIntegral R (x - y) :=
hx.sub (algebraMap R A) hy
#align is_integral_sub IsIntegral.sub
theorem RingHom.IsIntegralElem.mul {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) :
f.IsIntegralElem (x * y) :=
hx.of_mem_closure f hy
(Subring.mul_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl)))
#align ring_hom.is_integral_mul RingHom.IsIntegralElem.mul
nonrec theorem IsIntegral.mul {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) :
IsIntegral R (x * y) :=
hx.mul (algebraMap R A) hy
#align is_integral_mul IsIntegral.mul
theorem IsIntegral.smul {R} [CommSemiring R] [CommRing S] [Algebra R B] [Algebra S B] [Algebra R S]
[IsScalarTower R S B] {x : B} (r : R)(hx : IsIntegral S x) : IsIntegral S (r • x) :=
.of_mem_of_fg _ hx.fg_adjoin_singleton _ <| by
rw [← algebraMap_smul S]; apply Subalgebra.smul_mem; exact Algebra.subset_adjoin rfl
#align is_integral_smul IsIntegral.smul
theorem IsIntegral.of_pow {x : B} {n : ℕ} (hn : 0 < n) (hx : IsIntegral R <| x ^ n) :
IsIntegral R x := by
rcases hx with ⟨p, hmonic, heval⟩
exact ⟨expand R n p, hmonic.expand hn, by rwa [← aeval_def, expand_aeval]⟩
#align is_integral_of_pow IsIntegral.of_pow
variable (R A)
/-- The integral closure of R in an R-algebra A. -/
def integralClosure : Subalgebra R A where
carrier := { r | IsIntegral R r }
zero_mem' := isIntegral_zero
one_mem' := isIntegral_one
add_mem' := IsIntegral.add
mul_mem' := IsIntegral.mul
algebraMap_mem' _ := isIntegral_algebraMap
#align integral_closure integralClosure
theorem mem_integralClosure_iff_mem_fg {r : A} :
r ∈ integralClosure R A ↔ ∃ M : Subalgebra R A, M.toSubmodule.FG ∧ r ∈ M :=
⟨fun hr =>
⟨Algebra.adjoin R {r}, hr.fg_adjoin_singleton, Algebra.subset_adjoin rfl⟩,
fun ⟨M, Hf, hrM⟩ => .of_mem_of_fg M Hf _ hrM⟩
#align mem_integral_closure_iff_mem_fg mem_integralClosure_iff_mem_fg
variable {R A}
theorem adjoin_le_integralClosure {x : A} (hx : IsIntegral R x) :
Algebra.adjoin R {x} ≤ integralClosure R A := by
rw [Algebra.adjoin_le_iff]
simp only [SetLike.mem_coe, Set.singleton_subset_iff]
exact hx
#align adjoin_le_integral_closure adjoin_le_integralClosure
theorem le_integralClosure_iff_isIntegral {S : Subalgebra R A} :
S ≤ integralClosure R A ↔ Algebra.IsIntegral R S :=
SetLike.forall.symm.trans <|
(forall_congr' fun x =>
show IsIntegral R (algebraMap S A x) ↔ IsIntegral R x from
isIntegral_algebraMap_iff Subtype.coe_injective).trans
Algebra.isIntegral_def.symm
#align le_integral_closure_iff_is_integral le_integralClosure_iff_isIntegral
theorem Algebra.isIntegral_sup {S T : Subalgebra R A} :
Algebra.IsIntegral R (S ⊔ T : Subalgebra R A) ↔
Algebra.IsIntegral R S ∧ Algebra.IsIntegral R T := by
simp only [← le_integralClosure_iff_isIntegral, sup_le_iff]
#align is_integral_sup Algebra.isIntegral_sup
/-- Mapping an integral closure along an `AlgEquiv` gives the integral closure. -/
theorem integralClosure_map_algEquiv [Algebra R S] (f : A ≃ₐ[R] S) :
(integralClosure R A).map (f : A →ₐ[R] S) = integralClosure R S := by
ext y
rw [Subalgebra.mem_map]
constructor
· rintro ⟨x, hx, rfl⟩
exact hx.map f
· intro hy
use f.symm y, hy.map (f.symm : S →ₐ[R] A)
simp
#align integral_closure_map_alg_equiv integralClosure_map_algEquiv
/-- An `AlgHom` between two rings restrict to an `AlgHom` between the integral closures inside
them. -/
def AlgHom.mapIntegralClosure [Algebra R S] (f : A →ₐ[R] S) :
integralClosure R A →ₐ[R] integralClosure R S :=
(f.restrictDomain (integralClosure R A)).codRestrict (integralClosure R S) (fun ⟨_, h⟩ => h.map f)
@[simp]
theorem AlgHom.coe_mapIntegralClosure [Algebra R S] (f : A →ₐ[R] S)
(x : integralClosure R A) : (f.mapIntegralClosure x : S) = f (x : A) := rfl
/-- An `AlgEquiv` between two rings restrict to an `AlgEquiv` between the integral closures inside
them. -/
def AlgEquiv.mapIntegralClosure [Algebra R S] (f : A ≃ₐ[R] S) :
integralClosure R A ≃ₐ[R] integralClosure R S :=
AlgEquiv.ofAlgHom (f : A →ₐ[R] S).mapIntegralClosure (f.symm : S →ₐ[R] A).mapIntegralClosure
(AlgHom.ext fun _ ↦ Subtype.ext (f.right_inv _))
(AlgHom.ext fun _ ↦ Subtype.ext (f.left_inv _))
@[simp]
theorem AlgEquiv.coe_mapIntegralClosure [Algebra R S] (f : A ≃ₐ[R] S)
(x : integralClosure R A) : (f.mapIntegralClosure x : S) = f (x : A) := rfl
theorem integralClosure.isIntegral (x : integralClosure R A) : IsIntegral R x :=
let ⟨p, hpm, hpx⟩ := x.2
⟨p, hpm,
Subtype.eq <| by
rwa [← aeval_def, ← Subalgebra.val_apply, aeval_algHom_apply] at hpx⟩
#align integral_closure.is_integral integralClosure.isIntegral
instance integralClosure.AlgebraIsIntegral : Algebra.IsIntegral R (integralClosure R A) :=
⟨integralClosure.isIntegral⟩
theorem IsIntegral.of_mul_unit {x y : B} {r : R} (hr : algebraMap R B r * y = 1)
(hx : IsIntegral R (x * y)) : IsIntegral R x := by
obtain ⟨p, p_monic, hp⟩ := hx
refine ⟨scaleRoots p r, (monic_scaleRoots_iff r).2 p_monic, ?_⟩
convert scaleRoots_aeval_eq_zero hp
rw [Algebra.commutes] at hr ⊢
rw [mul_assoc, hr, mul_one]; rfl
#align is_integral_of_is_integral_mul_unit IsIntegral.of_mul_unit
theorem RingHom.IsIntegralElem.of_mul_unit (x y : S) (r : R) (hr : f r * y = 1)
(hx : f.IsIntegralElem (x * y)) : f.IsIntegralElem x :=
letI : Algebra R S := f.toAlgebra
IsIntegral.of_mul_unit hr hx
#align ring_hom.is_integral_of_is_integral_mul_unit RingHom.IsIntegralElem.of_mul_unit
/-- Generalization of `IsIntegral.of_mem_closure` bootstrapped up from that lemma -/
theorem IsIntegral.of_mem_closure' (G : Set A) (hG : ∀ x ∈ G, IsIntegral R x) :
∀ x ∈ Subring.closure G, IsIntegral R x := fun _ hx ↦
Subring.closure_induction hx hG isIntegral_zero isIntegral_one (fun _ _ ↦ IsIntegral.add)
(fun _ ↦ IsIntegral.neg) fun _ _ ↦ IsIntegral.mul
#align is_integral_of_mem_closure' IsIntegral.of_mem_closure'
theorem IsIntegral.of_mem_closure'' {S : Type*} [CommRing S] {f : R →+* S} (G : Set S)
(hG : ∀ x ∈ G, f.IsIntegralElem x) : ∀ x ∈ Subring.closure G, f.IsIntegralElem x := fun x hx =>
@IsIntegral.of_mem_closure' R S _ _ f.toAlgebra G hG x hx
#align is_integral_of_mem_closure'' IsIntegral.of_mem_closure''
theorem IsIntegral.pow {x : B} (h : IsIntegral R x) (n : ℕ) : IsIntegral R (x ^ n) :=
.of_mem_of_fg _ h.fg_adjoin_singleton _ <|
Subalgebra.pow_mem _ (by exact Algebra.subset_adjoin rfl) _
#align is_integral.pow IsIntegral.pow
theorem IsIntegral.nsmul {x : B} (h : IsIntegral R x) (n : ℕ) : IsIntegral R (n • x) :=
h.smul n
#align is_integral.nsmul IsIntegral.nsmul
theorem IsIntegral.zsmul {x : B} (h : IsIntegral R x) (n : ℤ) : IsIntegral R (n • x) :=
h.smul n
#align is_integral.zsmul IsIntegral.zsmul
theorem IsIntegral.multiset_prod {s : Multiset A} (h : ∀ x ∈ s, IsIntegral R x) :
IsIntegral R s.prod :=
(integralClosure R A).multiset_prod_mem h
#align is_integral.multiset_prod IsIntegral.multiset_prod
theorem IsIntegral.multiset_sum {s : Multiset A} (h : ∀ x ∈ s, IsIntegral R x) :
IsIntegral R s.sum :=
(integralClosure R A).multiset_sum_mem h
#align is_integral.multiset_sum IsIntegral.multiset_sum
theorem IsIntegral.prod {α : Type*} {s : Finset α} (f : α → A) (h : ∀ x ∈ s, IsIntegral R (f x)) :
IsIntegral R (∏ x ∈ s, f x) :=
(integralClosure R A).prod_mem h
#align is_integral.prod IsIntegral.prod
theorem IsIntegral.sum {α : Type*} {s : Finset α} (f : α → A) (h : ∀ x ∈ s, IsIntegral R (f x)) :
IsIntegral R (∑ x ∈ s, f x) :=
(integralClosure R A).sum_mem h
#align is_integral.sum IsIntegral.sum
theorem IsIntegral.det {n : Type*} [Fintype n] [DecidableEq n] {M : Matrix n n A}
(h : ∀ i j, IsIntegral R (M i j)) : IsIntegral R M.det := by
rw [Matrix.det_apply]
exact IsIntegral.sum _ fun σ _hσ ↦ (IsIntegral.prod _ fun i _hi => h _ _).zsmul _
#align is_integral.det IsIntegral.det
@[simp]
theorem IsIntegral.pow_iff {x : A} {n : ℕ} (hn : 0 < n) : IsIntegral R (x ^ n) ↔ IsIntegral R x :=
⟨IsIntegral.of_pow hn, fun hx ↦ hx.pow n⟩
#align is_integral.pow_iff IsIntegral.pow_iff
open TensorProduct
theorem IsIntegral.tmul (x : A) {y : B} (h : IsIntegral R y) : IsIntegral A (x ⊗ₜ[R] y) := by
rw [← mul_one x, ← smul_eq_mul, ← smul_tmul']
exact smul _ (h.map_of_comp_eq (algebraMap R A)
(Algebra.TensorProduct.includeRight (R := R) (A := A) (B := B)).toRingHom
Algebra.TensorProduct.includeLeftRingHom_comp_algebraMap)
#align is_integral.tmul IsIntegral.tmul
section
variable (p : R[X]) (x : S)
/-- The monic polynomial whose roots are `p.leadingCoeff * x` for roots `x` of `p`. -/
noncomputable def normalizeScaleRoots (p : R[X]) : R[X] :=
∑ i ∈ p.support,
monomial i (if i = p.natDegree then 1 else p.coeff i * p.leadingCoeff ^ (p.natDegree - 1 - i))
#align normalize_scale_roots normalizeScaleRoots
theorem normalizeScaleRoots_coeff_mul_leadingCoeff_pow (i : ℕ) (hp : 1 ≤ natDegree p) :
(normalizeScaleRoots p).coeff i * p.leadingCoeff ^ i =
p.coeff i * p.leadingCoeff ^ (p.natDegree - 1) := by
simp only [normalizeScaleRoots, finset_sum_coeff, coeff_monomial, Finset.sum_ite_eq', one_mul,
zero_mul, mem_support_iff, ite_mul, Ne, ite_not]
split_ifs with h₁ h₂
· simp [h₁]
· rw [h₂, leadingCoeff, ← pow_succ', tsub_add_cancel_of_le hp]
· rw [mul_assoc, ← pow_add, tsub_add_cancel_of_le]
apply Nat.le_sub_one_of_lt
rw [lt_iff_le_and_ne]
exact ⟨le_natDegree_of_ne_zero h₁, h₂⟩
#align normalize_scale_roots_coeff_mul_leading_coeff_pow normalizeScaleRoots_coeff_mul_leadingCoeff_pow
theorem leadingCoeff_smul_normalizeScaleRoots (p : R[X]) :
p.leadingCoeff • normalizeScaleRoots p = scaleRoots p p.leadingCoeff := by
ext
simp only [coeff_scaleRoots, normalizeScaleRoots, coeff_monomial, coeff_smul, Finset.smul_sum,
Ne, Finset.sum_ite_eq', finset_sum_coeff, smul_ite, smul_zero, mem_support_iff]
-- Porting note: added the following `simp only`
simp only [ge_iff_le, tsub_le_iff_right, smul_eq_mul, mul_ite, mul_one, mul_zero,
Finset.sum_ite_eq', mem_support_iff, ne_eq, ite_not]
split_ifs with h₁ h₂
· simp [*]
· simp [*]
· rw [mul_comm, mul_assoc, ← pow_succ, tsub_right_comm,
tsub_add_cancel_of_le]
rw [Nat.succ_le_iff]
exact tsub_pos_of_lt (lt_of_le_of_ne (le_natDegree_of_ne_zero h₁) h₂)
#align leading_coeff_smul_normalize_scale_roots leadingCoeff_smul_normalizeScaleRoots
theorem normalizeScaleRoots_support : (normalizeScaleRoots p).support ≤ p.support := by
intro x
contrapose
simp only [not_mem_support_iff, normalizeScaleRoots, finset_sum_coeff, coeff_monomial,
Finset.sum_ite_eq', mem_support_iff, Ne, Classical.not_not, ite_eq_right_iff]
intro h₁ h₂
exact (h₂ h₁).elim
#align normalize_scale_roots_support normalizeScaleRoots_support
| Mathlib/RingTheory/IntegralClosure.lean | 649 | 653 | theorem normalizeScaleRoots_degree : (normalizeScaleRoots p).degree = p.degree := by |
apply le_antisymm
· exact Finset.sup_mono (normalizeScaleRoots_support p)
· rw [← degree_scaleRoots, ← leadingCoeff_smul_normalizeScaleRoots]
exact degree_smul_le _ _
|
/-
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
-/
import Mathlib.Algebra.Group.Indicator
import Mathlib.Data.Finset.Piecewise
import Mathlib.Data.Finset.Preimage
#align_import algebra.big_operators.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83"
/-!
# Big operators
In this file we define products and sums indexed by finite sets (specifically, `Finset`).
## Notation
We introduce the following notation.
Let `s` be a `Finset α`, and `f : α → β` a function.
* `∏ x ∈ s, f x` is notation for `Finset.prod s f` (assuming `β` is a `CommMonoid`)
* `∑ x ∈ s, f x` is notation for `Finset.sum s f` (assuming `β` is an `AddCommMonoid`)
* `∏ x, f x` is notation for `Finset.prod Finset.univ f`
(assuming `α` is a `Fintype` and `β` is a `CommMonoid`)
* `∑ x, f x` is notation for `Finset.sum Finset.univ f`
(assuming `α` is a `Fintype` and `β` is an `AddCommMonoid`)
## Implementation Notes
The first arguments in all definitions and lemmas is the codomain of the function of the big
operator. This is necessary for the heuristic in `@[to_additive]`.
See the documentation of `to_additive.attr` for more information.
-/
-- TODO
-- assert_not_exists AddCommMonoidWithOne
assert_not_exists MonoidWithZero
assert_not_exists MulAction
variable {ι κ α β γ : Type*}
open Fin Function
namespace Finset
/-- `∏ x ∈ s, f x` is the product of `f x`
as `x` ranges over the elements of the finite set `s`.
-/
@[to_additive "`∑ x ∈ s, f x` is the sum of `f x` as `x` ranges over the elements
of the finite set `s`."]
protected def prod [CommMonoid β] (s : Finset α) (f : α → β) : β :=
(s.1.map f).prod
#align finset.prod Finset.prod
#align finset.sum Finset.sum
@[to_additive (attr := simp)]
theorem prod_mk [CommMonoid β] (s : Multiset α) (hs : s.Nodup) (f : α → β) :
(⟨s, hs⟩ : Finset α).prod f = (s.map f).prod :=
rfl
#align finset.prod_mk Finset.prod_mk
#align finset.sum_mk Finset.sum_mk
@[to_additive (attr := simp)]
theorem prod_val [CommMonoid α] (s : Finset α) : s.1.prod = s.prod id := by
rw [Finset.prod, Multiset.map_id]
#align finset.prod_val Finset.prod_val
#align finset.sum_val Finset.sum_val
end Finset
library_note "operator precedence of big operators"/--
There is no established mathematical convention
for the operator precedence of big operators like `∏` and `∑`.
We will have to make a choice.
Online discussions, such as https://math.stackexchange.com/q/185538/30839
seem to suggest that `∏` and `∑` should have the same precedence,
and that this should be somewhere between `*` and `+`.
The latter have precedence levels `70` and `65` respectively,
and we therefore choose the level `67`.
In practice, this means that parentheses should be placed as follows:
```lean
∑ k ∈ K, (a k + b k) = ∑ k ∈ K, a k + ∑ k ∈ K, b k →
∏ k ∈ K, a k * b k = (∏ k ∈ K, a k) * (∏ k ∈ K, b k)
```
(Example taken from page 490 of Knuth's *Concrete Mathematics*.)
-/
namespace BigOperators
open Batteries.ExtendedBinder Lean Meta
-- TODO: contribute this modification back to `extBinder`
/-- A `bigOpBinder` is like an `extBinder` and has the form `x`, `x : ty`, or `x pred`
where `pred` is a `binderPred` like `< 2`.
Unlike `extBinder`, `x` is a term. -/
syntax bigOpBinder := term:max ((" : " term) <|> binderPred)?
/-- A BigOperator binder in parentheses -/
syntax bigOpBinderParenthesized := " (" bigOpBinder ")"
/-- A list of parenthesized binders -/
syntax bigOpBinderCollection := bigOpBinderParenthesized+
/-- A single (unparenthesized) binder, or a list of parenthesized binders -/
syntax bigOpBinders := bigOpBinderCollection <|> (ppSpace bigOpBinder)
/-- Collects additional binder/Finset pairs for the given `bigOpBinder`.
Note: this is not extensible at the moment, unlike the usual `bigOpBinder` expansions. -/
def processBigOpBinder (processed : (Array (Term × Term)))
(binder : TSyntax ``bigOpBinder) : MacroM (Array (Term × Term)) :=
set_option hygiene false in
withRef binder do
match binder with
| `(bigOpBinder| $x:term) =>
match x with
| `(($a + $b = $n)) => -- Maybe this is too cute.
return processed |>.push (← `(⟨$a, $b⟩), ← `(Finset.Nat.antidiagonal $n))
| _ => return processed |>.push (x, ← ``(Finset.univ))
| `(bigOpBinder| $x : $t) => return processed |>.push (x, ← ``((Finset.univ : Finset $t)))
| `(bigOpBinder| $x ∈ $s) => return processed |>.push (x, ← `(finset% $s))
| `(bigOpBinder| $x < $n) => return processed |>.push (x, ← `(Finset.Iio $n))
| `(bigOpBinder| $x ≤ $n) => return processed |>.push (x, ← `(Finset.Iic $n))
| `(bigOpBinder| $x > $n) => return processed |>.push (x, ← `(Finset.Ioi $n))
| `(bigOpBinder| $x ≥ $n) => return processed |>.push (x, ← `(Finset.Ici $n))
| _ => Macro.throwUnsupported
/-- Collects the binder/Finset pairs for the given `bigOpBinders`. -/
def processBigOpBinders (binders : TSyntax ``bigOpBinders) :
MacroM (Array (Term × Term)) :=
match binders with
| `(bigOpBinders| $b:bigOpBinder) => processBigOpBinder #[] b
| `(bigOpBinders| $[($bs:bigOpBinder)]*) => bs.foldlM processBigOpBinder #[]
| _ => Macro.throwUnsupported
/-- Collect the binderIdents into a `⟨...⟩` expression. -/
def bigOpBindersPattern (processed : (Array (Term × Term))) :
MacroM Term := do
let ts := processed.map Prod.fst
if ts.size == 1 then
return ts[0]!
else
`(⟨$ts,*⟩)
/-- Collect the terms into a product of sets. -/
def bigOpBindersProd (processed : (Array (Term × Term))) :
MacroM Term := do
if processed.isEmpty then
`((Finset.univ : Finset Unit))
else if processed.size == 1 then
return processed[0]!.2
else
processed.foldrM (fun s p => `(SProd.sprod $(s.2) $p)) processed.back.2
(start := processed.size - 1)
/--
- `∑ x, f x` is notation for `Finset.sum Finset.univ f`. It is the sum of `f x`,
where `x` ranges over the finite domain of `f`.
- `∑ x ∈ s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`,
where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance).
- `∑ x ∈ s with p x, f x` is notation for `Finset.sum (Finset.filter p s) f`.
- `∑ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.sum (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`.
These support destructuring, for example `∑ ⟨x, y⟩ ∈ s ×ˢ t, f x y`.
Notation: `"∑" bigOpBinders* ("with" term)? "," term` -/
syntax (name := bigsum) "∑ " bigOpBinders ("with " term)? ", " term:67 : term
/--
- `∏ x, f x` is notation for `Finset.prod Finset.univ f`. It is the product of `f x`,
where `x` ranges over the finite domain of `f`.
- `∏ x ∈ s, f x` is notation for `Finset.prod s f`. It is the product of `f x`,
where `x` ranges over the finite set `s` (either a `Finset` or a `Set` with a `Fintype` instance).
- `∏ x ∈ s with p x, f x` is notation for `Finset.prod (Finset.filter p s) f`.
- `∏ (x ∈ s) (y ∈ t), f x y` is notation for `Finset.prod (s ×ˢ t) (fun ⟨x, y⟩ ↦ f x y)`.
These support destructuring, for example `∏ ⟨x, y⟩ ∈ s ×ˢ t, f x y`.
Notation: `"∏" bigOpBinders* ("with" term)? "," term` -/
syntax (name := bigprod) "∏ " bigOpBinders ("with " term)? ", " term:67 : term
macro_rules (kind := bigsum)
| `(∑ $bs:bigOpBinders $[with $p?]?, $v) => do
let processed ← processBigOpBinders bs
let x ← bigOpBindersPattern processed
let s ← bigOpBindersProd processed
match p? with
| some p => `(Finset.sum (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v))
| none => `(Finset.sum $s (fun $x ↦ $v))
macro_rules (kind := bigprod)
| `(∏ $bs:bigOpBinders $[with $p?]?, $v) => do
let processed ← processBigOpBinders bs
let x ← bigOpBindersPattern processed
let s ← bigOpBindersProd processed
match p? with
| some p => `(Finset.prod (Finset.filter (fun $x ↦ $p) $s) (fun $x ↦ $v))
| none => `(Finset.prod $s (fun $x ↦ $v))
/-- (Deprecated, use `∑ x ∈ s, f x`)
`∑ x in s, f x` is notation for `Finset.sum s f`. It is the sum of `f x`,
where `x` ranges over the finite set `s`. -/
syntax (name := bigsumin) "∑ " extBinder " in " term ", " term:67 : term
macro_rules (kind := bigsumin)
| `(∑ $x:ident in $s, $r) => `(∑ $x:ident ∈ $s, $r)
| `(∑ $x:ident : $t in $s, $r) => `(∑ $x:ident ∈ ($s : Finset $t), $r)
/-- (Deprecated, use `∏ x ∈ s, f x`)
`∏ x in s, f x` is notation for `Finset.prod s f`. It is the product of `f x`,
where `x` ranges over the finite set `s`. -/
syntax (name := bigprodin) "∏ " extBinder " in " term ", " term:67 : term
macro_rules (kind := bigprodin)
| `(∏ $x:ident in $s, $r) => `(∏ $x:ident ∈ $s, $r)
| `(∏ $x:ident : $t in $s, $r) => `(∏ $x:ident ∈ ($s : Finset $t), $r)
open Lean Meta Parser.Term PrettyPrinter.Delaborator SubExpr
open Batteries.ExtendedBinder
/-- Delaborator for `Finset.prod`. The `pp.piBinderTypes` option controls whether
to show the domain type when the product is over `Finset.univ`. -/
@[delab app.Finset.prod] def delabFinsetProd : Delab :=
whenPPOption getPPNotation <| withOverApp 5 <| do
let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure
guard <| f.isLambda
let ppDomain ← getPPOption getPPPiBinderTypes
let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do
return (i, ← delab)
if s.isAppOfArity ``Finset.univ 2 then
let binder ←
if ppDomain then
let ty ← withNaryArg 0 delab
`(bigOpBinder| $(.mk i):ident : $ty)
else
`(bigOpBinder| $(.mk i):ident)
`(∏ $binder:bigOpBinder, $body)
else
let ss ← withNaryArg 3 <| delab
`(∏ $(.mk i):ident ∈ $ss, $body)
/-- Delaborator for `Finset.sum`. The `pp.piBinderTypes` option controls whether
to show the domain type when the sum is over `Finset.univ`. -/
@[delab app.Finset.sum] def delabFinsetSum : Delab :=
whenPPOption getPPNotation <| withOverApp 5 <| do
let #[_, _, _, s, f] := (← getExpr).getAppArgs | failure
guard <| f.isLambda
let ppDomain ← getPPOption getPPPiBinderTypes
let (i, body) ← withAppArg <| withBindingBodyUnusedName fun i => do
return (i, ← delab)
if s.isAppOfArity ``Finset.univ 2 then
let binder ←
if ppDomain then
let ty ← withNaryArg 0 delab
`(bigOpBinder| $(.mk i):ident : $ty)
else
`(bigOpBinder| $(.mk i):ident)
`(∑ $binder:bigOpBinder, $body)
else
let ss ← withNaryArg 3 <| delab
`(∑ $(.mk i):ident ∈ $ss, $body)
end BigOperators
namespace Finset
variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β}
@[to_additive]
theorem prod_eq_multiset_prod [CommMonoid β] (s : Finset α) (f : α → β) :
∏ x ∈ s, f x = (s.1.map f).prod :=
rfl
#align finset.prod_eq_multiset_prod Finset.prod_eq_multiset_prod
#align finset.sum_eq_multiset_sum Finset.sum_eq_multiset_sum
@[to_additive (attr := simp)]
lemma prod_map_val [CommMonoid β] (s : Finset α) (f : α → β) : (s.1.map f).prod = ∏ a ∈ s, f a :=
rfl
#align finset.prod_map_val Finset.prod_map_val
#align finset.sum_map_val Finset.sum_map_val
@[to_additive]
theorem prod_eq_fold [CommMonoid β] (s : Finset α) (f : α → β) :
∏ x ∈ s, f x = s.fold ((· * ·) : β → β → β) 1 f :=
rfl
#align finset.prod_eq_fold Finset.prod_eq_fold
#align finset.sum_eq_fold Finset.sum_eq_fold
@[simp]
theorem sum_multiset_singleton (s : Finset α) : (s.sum fun x => {x}) = s.val := by
simp only [sum_eq_multiset_sum, Multiset.sum_map_singleton]
#align finset.sum_multiset_singleton Finset.sum_multiset_singleton
end Finset
@[to_additive (attr := simp)]
theorem map_prod [CommMonoid β] [CommMonoid γ] {G : Type*} [FunLike G β γ] [MonoidHomClass G β γ]
(g : G) (f : α → β) (s : Finset α) : g (∏ x ∈ s, f x) = ∏ x ∈ s, g (f x) := by
simp only [Finset.prod_eq_multiset_prod, map_multiset_prod, Multiset.map_map]; rfl
#align map_prod map_prod
#align map_sum map_sum
@[to_additive]
theorem MonoidHom.coe_finset_prod [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α) :
⇑(∏ x ∈ s, f x) = ∏ x ∈ s, ⇑(f x) :=
map_prod (MonoidHom.coeFn β γ) _ _
#align monoid_hom.coe_finset_prod MonoidHom.coe_finset_prod
#align add_monoid_hom.coe_finset_sum AddMonoidHom.coe_finset_sum
/-- See also `Finset.prod_apply`, with the same conclusion but with the weaker hypothesis
`f : α → β → γ` -/
@[to_additive (attr := simp)
"See also `Finset.sum_apply`, with the same conclusion but with the weaker hypothesis
`f : α → β → γ`"]
theorem MonoidHom.finset_prod_apply [MulOneClass β] [CommMonoid γ] (f : α → β →* γ) (s : Finset α)
(b : β) : (∏ x ∈ s, f x) b = ∏ x ∈ s, f x b :=
map_prod (MonoidHom.eval b) _ _
#align monoid_hom.finset_prod_apply MonoidHom.finset_prod_apply
#align add_monoid_hom.finset_sum_apply AddMonoidHom.finset_sum_apply
variable {s s₁ s₂ : Finset α} {a : α} {f g : α → β}
namespace Finset
section CommMonoid
variable [CommMonoid β]
@[to_additive (attr := simp)]
theorem prod_empty : ∏ x ∈ ∅, f x = 1 :=
rfl
#align finset.prod_empty Finset.prod_empty
#align finset.sum_empty Finset.sum_empty
@[to_additive]
theorem prod_of_empty [IsEmpty α] (s : Finset α) : ∏ i ∈ s, f i = 1 := by
rw [eq_empty_of_isEmpty s, prod_empty]
#align finset.prod_of_empty Finset.prod_of_empty
#align finset.sum_of_empty Finset.sum_of_empty
@[to_additive (attr := simp)]
theorem prod_cons (h : a ∉ s) : ∏ x ∈ cons a s h, f x = f a * ∏ x ∈ s, f x :=
fold_cons h
#align finset.prod_cons Finset.prod_cons
#align finset.sum_cons Finset.sum_cons
@[to_additive (attr := simp)]
theorem prod_insert [DecidableEq α] : a ∉ s → ∏ x ∈ insert a s, f x = f a * ∏ x ∈ s, f x :=
fold_insert
#align finset.prod_insert Finset.prod_insert
#align finset.sum_insert Finset.sum_insert
/-- The product of `f` over `insert a s` is the same as
the product over `s`, as long as `a` is in `s` or `f a = 1`. -/
@[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as
the sum over `s`, as long as `a` is in `s` or `f a = 0`."]
theorem prod_insert_of_eq_one_if_not_mem [DecidableEq α] (h : a ∉ s → f a = 1) :
∏ x ∈ insert a s, f x = ∏ x ∈ s, f x := by
by_cases hm : a ∈ s
· simp_rw [insert_eq_of_mem hm]
· rw [prod_insert hm, h hm, one_mul]
#align finset.prod_insert_of_eq_one_if_not_mem Finset.prod_insert_of_eq_one_if_not_mem
#align finset.sum_insert_of_eq_zero_if_not_mem Finset.sum_insert_of_eq_zero_if_not_mem
/-- The product of `f` over `insert a s` is the same as
the product over `s`, as long as `f a = 1`. -/
@[to_additive (attr := simp) "The sum of `f` over `insert a s` is the same as
the sum over `s`, as long as `f a = 0`."]
theorem prod_insert_one [DecidableEq α] (h : f a = 1) : ∏ x ∈ insert a s, f x = ∏ x ∈ s, f x :=
prod_insert_of_eq_one_if_not_mem fun _ => h
#align finset.prod_insert_one Finset.prod_insert_one
#align finset.sum_insert_zero Finset.sum_insert_zero
@[to_additive]
theorem prod_insert_div {M : Type*} [CommGroup M] [DecidableEq α] (ha : a ∉ s) {f : α → M} :
(∏ x ∈ insert a s, f x) / f a = ∏ x ∈ s, f x := by simp [ha]
@[to_additive (attr := simp)]
theorem prod_singleton (f : α → β) (a : α) : ∏ x ∈ singleton a, f x = f a :=
Eq.trans fold_singleton <| mul_one _
#align finset.prod_singleton Finset.prod_singleton
#align finset.sum_singleton Finset.sum_singleton
@[to_additive]
theorem prod_pair [DecidableEq α] {a b : α} (h : a ≠ b) :
(∏ x ∈ ({a, b} : Finset α), f x) = f a * f b := by
rw [prod_insert (not_mem_singleton.2 h), prod_singleton]
#align finset.prod_pair Finset.prod_pair
#align finset.sum_pair Finset.sum_pair
@[to_additive (attr := simp)]
theorem prod_const_one : (∏ _x ∈ s, (1 : β)) = 1 := by
simp only [Finset.prod, Multiset.map_const', Multiset.prod_replicate, one_pow]
#align finset.prod_const_one Finset.prod_const_one
#align finset.sum_const_zero Finset.sum_const_zero
@[to_additive (attr := simp)]
theorem prod_image [DecidableEq α] {s : Finset γ} {g : γ → α} :
(∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) → ∏ x ∈ s.image g, f x = ∏ x ∈ s, f (g x) :=
fold_image
#align finset.prod_image Finset.prod_image
#align finset.sum_image Finset.sum_image
@[to_additive (attr := simp)]
theorem prod_map (s : Finset α) (e : α ↪ γ) (f : γ → β) :
∏ x ∈ s.map e, f x = ∏ x ∈ s, f (e x) := by
rw [Finset.prod, Finset.map_val, Multiset.map_map]; rfl
#align finset.prod_map Finset.prod_map
#align finset.sum_map Finset.sum_map
@[to_additive]
lemma prod_attach (s : Finset α) (f : α → β) : ∏ x ∈ s.attach, f x = ∏ x ∈ s, f x := by
classical rw [← prod_image Subtype.coe_injective.injOn, attach_image_val]
#align finset.prod_attach Finset.prod_attach
#align finset.sum_attach Finset.sum_attach
@[to_additive (attr := congr)]
theorem prod_congr (h : s₁ = s₂) : (∀ x ∈ s₂, f x = g x) → s₁.prod f = s₂.prod g := by
rw [h]; exact fold_congr
#align finset.prod_congr Finset.prod_congr
#align finset.sum_congr Finset.sum_congr
@[to_additive]
theorem prod_eq_one {f : α → β} {s : Finset α} (h : ∀ x ∈ s, f x = 1) : ∏ x ∈ s, f x = 1 :=
calc
∏ x ∈ s, f x = ∏ _x ∈ s, 1 := Finset.prod_congr rfl h
_ = 1 := Finset.prod_const_one
#align finset.prod_eq_one Finset.prod_eq_one
#align finset.sum_eq_zero Finset.sum_eq_zero
@[to_additive]
theorem prod_disjUnion (h) :
∏ x ∈ s₁.disjUnion s₂ h, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by
refine Eq.trans ?_ (fold_disjUnion h)
rw [one_mul]
rfl
#align finset.prod_disj_union Finset.prod_disjUnion
#align finset.sum_disj_union Finset.sum_disjUnion
@[to_additive]
theorem prod_disjiUnion (s : Finset ι) (t : ι → Finset α) (h) :
∏ x ∈ s.disjiUnion t h, f x = ∏ i ∈ s, ∏ x ∈ t i, f x := by
refine Eq.trans ?_ (fold_disjiUnion h)
dsimp [Finset.prod, Multiset.prod, Multiset.fold, Finset.disjUnion, Finset.fold]
congr
exact prod_const_one.symm
#align finset.prod_disj_Union Finset.prod_disjiUnion
#align finset.sum_disj_Union Finset.sum_disjiUnion
@[to_additive]
theorem prod_union_inter [DecidableEq α] :
(∏ x ∈ s₁ ∪ s₂, f x) * ∏ x ∈ s₁ ∩ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x :=
fold_union_inter
#align finset.prod_union_inter Finset.prod_union_inter
#align finset.sum_union_inter Finset.sum_union_inter
@[to_additive]
theorem prod_union [DecidableEq α] (h : Disjoint s₁ s₂) :
∏ x ∈ s₁ ∪ s₂, f x = (∏ x ∈ s₁, f x) * ∏ x ∈ s₂, f x := by
rw [← prod_union_inter, disjoint_iff_inter_eq_empty.mp h]; exact (mul_one _).symm
#align finset.prod_union Finset.prod_union
#align finset.sum_union Finset.sum_union
@[to_additive]
theorem prod_filter_mul_prod_filter_not
(s : Finset α) (p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] (f : α → β) :
(∏ x ∈ s.filter p, f x) * ∏ x ∈ s.filter fun x => ¬p x, f x = ∏ x ∈ s, f x := by
have := Classical.decEq α
rw [← prod_union (disjoint_filter_filter_neg s s p), filter_union_filter_neg_eq]
#align finset.prod_filter_mul_prod_filter_not Finset.prod_filter_mul_prod_filter_not
#align finset.sum_filter_add_sum_filter_not Finset.sum_filter_add_sum_filter_not
section ToList
@[to_additive (attr := simp)]
theorem prod_to_list (s : Finset α) (f : α → β) : (s.toList.map f).prod = s.prod f := by
rw [Finset.prod, ← Multiset.prod_coe, ← Multiset.map_coe, Finset.coe_toList]
#align finset.prod_to_list Finset.prod_to_list
#align finset.sum_to_list Finset.sum_to_list
end ToList
@[to_additive]
theorem _root_.Equiv.Perm.prod_comp (σ : Equiv.Perm α) (s : Finset α) (f : α → β)
(hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x)) = ∏ x ∈ s, f x := by
convert (prod_map s σ.toEmbedding f).symm
exact (map_perm hs).symm
#align equiv.perm.prod_comp Equiv.Perm.prod_comp
#align equiv.perm.sum_comp Equiv.Perm.sum_comp
@[to_additive]
theorem _root_.Equiv.Perm.prod_comp' (σ : Equiv.Perm α) (s : Finset α) (f : α → α → β)
(hs : { a | σ a ≠ a } ⊆ s) : (∏ x ∈ s, f (σ x) x) = ∏ x ∈ s, f x (σ.symm x) := by
convert σ.prod_comp s (fun x => f x (σ.symm x)) hs
rw [Equiv.symm_apply_apply]
#align equiv.perm.prod_comp' Equiv.Perm.prod_comp'
#align equiv.perm.sum_comp' Equiv.Perm.sum_comp'
/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets
of `s`, and over all subsets of `s` to which one adds `x`. -/
@[to_additive "A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets
of `s`, and over all subsets of `s` to which one adds `x`."]
lemma prod_powerset_insert [DecidableEq α] (ha : a ∉ s) (f : Finset α → β) :
∏ t ∈ (insert a s).powerset, f t =
(∏ t ∈ s.powerset, f t) * ∏ t ∈ s.powerset, f (insert a t) := by
rw [powerset_insert, prod_union, prod_image]
· exact insert_erase_invOn.2.injOn.mono fun t ht ↦ not_mem_mono (mem_powerset.1 ht) ha
· aesop (add simp [disjoint_left, insert_subset_iff])
#align finset.prod_powerset_insert Finset.prod_powerset_insert
#align finset.sum_powerset_insert Finset.sum_powerset_insert
/-- A product over all subsets of `s ∪ {x}` is obtained by multiplying the product over all subsets
of `s`, and over all subsets of `s` to which one adds `x`. -/
@[to_additive "A sum over all subsets of `s ∪ {x}` is obtained by summing the sum over all subsets
of `s`, and over all subsets of `s` to which one adds `x`."]
lemma prod_powerset_cons (ha : a ∉ s) (f : Finset α → β) :
∏ t ∈ (s.cons a ha).powerset, f t = (∏ t ∈ s.powerset, f t) *
∏ t ∈ s.powerset.attach, f (cons a t $ not_mem_mono (mem_powerset.1 t.2) ha) := by
classical
simp_rw [cons_eq_insert]
rw [prod_powerset_insert ha, prod_attach _ fun t ↦ f (insert a t)]
/-- A product over `powerset s` is equal to the double product over sets of subsets of `s` with
`card s = k`, for `k = 1, ..., card s`. -/
@[to_additive "A sum over `powerset s` is equal to the double sum over sets of subsets of `s` with
`card s = k`, for `k = 1, ..., card s`"]
lemma prod_powerset (s : Finset α) (f : Finset α → β) :
∏ t ∈ powerset s, f t = ∏ j ∈ range (card s + 1), ∏ t ∈ powersetCard j s, f t := by
rw [powerset_card_disjiUnion, prod_disjiUnion]
#align finset.prod_powerset Finset.prod_powerset
#align finset.sum_powerset Finset.sum_powerset
end CommMonoid
end Finset
section
open Finset
variable [Fintype α] [CommMonoid β]
@[to_additive]
theorem IsCompl.prod_mul_prod {s t : Finset α} (h : IsCompl s t) (f : α → β) :
(∏ i ∈ s, f i) * ∏ i ∈ t, f i = ∏ i, f i :=
(Finset.prod_disjUnion h.disjoint).symm.trans <| by
classical rw [Finset.disjUnion_eq_union, ← Finset.sup_eq_union, h.sup_eq_top]; rfl
#align is_compl.prod_mul_prod IsCompl.prod_mul_prod
#align is_compl.sum_add_sum IsCompl.sum_add_sum
end
namespace Finset
section CommMonoid
variable [CommMonoid β]
/-- Multiplying the products of a function over `s` and over `sᶜ` gives the whole product.
For a version expressed with subtypes, see `Fintype.prod_subtype_mul_prod_subtype`. -/
@[to_additive "Adding the sums of a function over `s` and over `sᶜ` gives the whole sum.
For a version expressed with subtypes, see `Fintype.sum_subtype_add_sum_subtype`. "]
theorem prod_mul_prod_compl [Fintype α] [DecidableEq α] (s : Finset α) (f : α → β) :
(∏ i ∈ s, f i) * ∏ i ∈ sᶜ, f i = ∏ i, f i :=
IsCompl.prod_mul_prod isCompl_compl f
#align finset.prod_mul_prod_compl Finset.prod_mul_prod_compl
#align finset.sum_add_sum_compl Finset.sum_add_sum_compl
@[to_additive]
theorem prod_compl_mul_prod [Fintype α] [DecidableEq α] (s : Finset α) (f : α → β) :
(∏ i ∈ sᶜ, f i) * ∏ i ∈ s, f i = ∏ i, f i :=
(@isCompl_compl _ s _).symm.prod_mul_prod f
#align finset.prod_compl_mul_prod Finset.prod_compl_mul_prod
#align finset.sum_compl_add_sum Finset.sum_compl_add_sum
@[to_additive]
theorem prod_sdiff [DecidableEq α] (h : s₁ ⊆ s₂) :
(∏ x ∈ s₂ \ s₁, f x) * ∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x := by
rw [← prod_union sdiff_disjoint, sdiff_union_of_subset h]
#align finset.prod_sdiff Finset.prod_sdiff
#align finset.sum_sdiff Finset.sum_sdiff
@[to_additive]
theorem prod_subset_one_on_sdiff [DecidableEq α] (h : s₁ ⊆ s₂) (hg : ∀ x ∈ s₂ \ s₁, g x = 1)
(hfg : ∀ x ∈ s₁, f x = g x) : ∏ i ∈ s₁, f i = ∏ i ∈ s₂, g i := by
rw [← prod_sdiff h, prod_eq_one hg, one_mul]
exact prod_congr rfl hfg
#align finset.prod_subset_one_on_sdiff Finset.prod_subset_one_on_sdiff
#align finset.sum_subset_zero_on_sdiff Finset.sum_subset_zero_on_sdiff
@[to_additive]
theorem prod_subset (h : s₁ ⊆ s₂) (hf : ∀ x ∈ s₂, x ∉ s₁ → f x = 1) :
∏ x ∈ s₁, f x = ∏ x ∈ s₂, f x :=
haveI := Classical.decEq α
prod_subset_one_on_sdiff h (by simpa) fun _ _ => rfl
#align finset.prod_subset Finset.prod_subset
#align finset.sum_subset Finset.sum_subset
@[to_additive (attr := simp)]
theorem prod_disj_sum (s : Finset α) (t : Finset γ) (f : Sum α γ → β) :
∏ x ∈ s.disjSum t, f x = (∏ x ∈ s, f (Sum.inl x)) * ∏ x ∈ t, f (Sum.inr x) := by
rw [← map_inl_disjUnion_map_inr, prod_disjUnion, prod_map, prod_map]
rfl
#align finset.prod_disj_sum Finset.prod_disj_sum
#align finset.sum_disj_sum Finset.sum_disj_sum
@[to_additive]
theorem prod_sum_elim (s : Finset α) (t : Finset γ) (f : α → β) (g : γ → β) :
∏ x ∈ s.disjSum t, Sum.elim f g x = (∏ x ∈ s, f x) * ∏ x ∈ t, g x := by simp
#align finset.prod_sum_elim Finset.prod_sum_elim
#align finset.sum_sum_elim Finset.sum_sum_elim
@[to_additive]
theorem prod_biUnion [DecidableEq α] {s : Finset γ} {t : γ → Finset α}
(hs : Set.PairwiseDisjoint (↑s) t) : ∏ x ∈ s.biUnion t, f x = ∏ x ∈ s, ∏ i ∈ t x, f i := by
rw [← disjiUnion_eq_biUnion _ _ hs, prod_disjiUnion]
#align finset.prod_bUnion Finset.prod_biUnion
#align finset.sum_bUnion Finset.sum_biUnion
/-- Product over a sigma type equals the product of fiberwise products. For rewriting
in the reverse direction, use `Finset.prod_sigma'`. -/
@[to_additive "Sum over a sigma type equals the sum of fiberwise sums. For rewriting
in the reverse direction, use `Finset.sum_sigma'`"]
theorem prod_sigma {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : Sigma σ → β) :
∏ x ∈ s.sigma t, f x = ∏ a ∈ s, ∏ s ∈ t a, f ⟨a, s⟩ := by
simp_rw [← disjiUnion_map_sigma_mk, prod_disjiUnion, prod_map, Function.Embedding.sigmaMk_apply]
#align finset.prod_sigma Finset.prod_sigma
#align finset.sum_sigma Finset.sum_sigma
@[to_additive]
theorem prod_sigma' {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) (f : ∀ a, σ a → β) :
(∏ a ∈ s, ∏ s ∈ t a, f a s) = ∏ x ∈ s.sigma t, f x.1 x.2 :=
Eq.symm <| prod_sigma s t fun x => f x.1 x.2
#align finset.prod_sigma' Finset.prod_sigma'
#align finset.sum_sigma' Finset.sum_sigma'
section bij
variable {ι κ α : Type*} [CommMonoid α] {s : Finset ι} {t : Finset κ} {f : ι → α} {g : κ → α}
/-- Reorder a product.
The difference with `Finset.prod_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
The difference with `Finset.prod_nbij` is that the bijection is allowed to use membership of the
domain of the product, rather than being a non-dependent function. -/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
The difference with `Finset.sum_nbij` is that the bijection is allowed to use membership of the
domain of the sum, rather than being a non-dependent function."]
theorem prod_bij (i : ∀ a ∈ s, κ) (hi : ∀ a ha, i a ha ∈ t)
(i_inj : ∀ a₁ ha₁ a₂ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂)
(i_surj : ∀ b ∈ t, ∃ a ha, i a ha = b) (h : ∀ a ha, f a = g (i a ha)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x :=
congr_arg Multiset.prod (Multiset.map_eq_map_of_bij_of_nodup f g s.2 t.2 i hi i_inj i_surj h)
#align finset.prod_bij Finset.prod_bij
#align finset.sum_bij Finset.sum_bij
/-- Reorder a product.
The difference with `Finset.prod_bij` is that the bijection is specified with an inverse, rather
than as a surjective injection.
The difference with `Finset.prod_nbij'` is that the bijection and its inverse are allowed to use
membership of the domains of the products, rather than being non-dependent functions. -/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_bij` is that the bijection is specified with an inverse, rather than
as a surjective injection.
The difference with `Finset.sum_nbij'` is that the bijection and its inverse are allowed to use
membership of the domains of the sums, rather than being non-dependent functions."]
theorem prod_bij' (i : ∀ a ∈ s, κ) (j : ∀ a ∈ t, ι) (hi : ∀ a ha, i a ha ∈ t)
(hj : ∀ a ha, j a ha ∈ s) (left_inv : ∀ a ha, j (i a ha) (hi a ha) = a)
(right_inv : ∀ a ha, i (j a ha) (hj a ha) = a) (h : ∀ a ha, f a = g (i a ha)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x := by
refine prod_bij i hi (fun a1 h1 a2 h2 eq ↦ ?_) (fun b hb ↦ ⟨_, hj b hb, right_inv b hb⟩) h
rw [← left_inv a1 h1, ← left_inv a2 h2]
simp only [eq]
#align finset.prod_bij' Finset.prod_bij'
#align finset.sum_bij' Finset.sum_bij'
/-- Reorder a product.
The difference with `Finset.prod_nbij'` is that the bijection is specified as a surjective
injection, rather than by an inverse function.
The difference with `Finset.prod_bij` is that the bijection is a non-dependent function, rather than
being allowed to use membership of the domain of the product. -/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_nbij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
The difference with `Finset.sum_bij` is that the bijection is a non-dependent function, rather than
being allowed to use membership of the domain of the sum."]
lemma prod_nbij (i : ι → κ) (hi : ∀ a ∈ s, i a ∈ t) (i_inj : (s : Set ι).InjOn i)
(i_surj : (s : Set ι).SurjOn i t) (h : ∀ a ∈ s, f a = g (i a)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x :=
prod_bij (fun a _ ↦ i a) hi i_inj (by simpa using i_surj) h
/-- Reorder a product.
The difference with `Finset.prod_nbij` is that the bijection is specified with an inverse, rather
than as a surjective injection.
The difference with `Finset.prod_bij'` is that the bijection and its inverse are non-dependent
functions, rather than being allowed to use membership of the domains of the products.
The difference with `Finset.prod_equiv` is that bijectivity is only required to hold on the domains
of the products, rather than on the entire types.
-/
@[to_additive "Reorder a sum.
The difference with `Finset.sum_nbij` is that the bijection is specified with an inverse, rather
than as a surjective injection.
The difference with `Finset.sum_bij'` is that the bijection and its inverse are non-dependent
functions, rather than being allowed to use membership of the domains of the sums.
The difference with `Finset.sum_equiv` is that bijectivity is only required to hold on the domains
of the sums, rather than on the entire types."]
lemma prod_nbij' (i : ι → κ) (j : κ → ι) (hi : ∀ a ∈ s, i a ∈ t) (hj : ∀ a ∈ t, j a ∈ s)
(left_inv : ∀ a ∈ s, j (i a) = a) (right_inv : ∀ a ∈ t, i (j a) = a)
(h : ∀ a ∈ s, f a = g (i a)) : ∏ x ∈ s, f x = ∏ x ∈ t, g x :=
prod_bij' (fun a _ ↦ i a) (fun b _ ↦ j b) hi hj left_inv right_inv h
/-- Specialization of `Finset.prod_nbij'` that automatically fills in most arguments.
See `Fintype.prod_equiv` for the version where `s` and `t` are `univ`. -/
@[to_additive "`Specialization of `Finset.sum_nbij'` that automatically fills in most arguments.
See `Fintype.sum_equiv` for the version where `s` and `t` are `univ`."]
lemma prod_equiv (e : ι ≃ κ) (hst : ∀ i, i ∈ s ↔ e i ∈ t) (hfg : ∀ i ∈ s, f i = g (e i)) :
∏ i ∈ s, f i = ∏ i ∈ t, g i := by refine prod_nbij' e e.symm ?_ ?_ ?_ ?_ hfg <;> simp [hst]
#align finset.equiv.prod_comp_finset Finset.prod_equiv
#align finset.equiv.sum_comp_finset Finset.sum_equiv
/-- Specialization of `Finset.prod_bij` that automatically fills in most arguments.
See `Fintype.prod_bijective` for the version where `s` and `t` are `univ`. -/
@[to_additive "`Specialization of `Finset.sum_bij` that automatically fills in most arguments.
See `Fintype.sum_bijective` for the version where `s` and `t` are `univ`."]
lemma prod_bijective (e : ι → κ) (he : e.Bijective) (hst : ∀ i, i ∈ s ↔ e i ∈ t)
(hfg : ∀ i ∈ s, f i = g (e i)) :
∏ i ∈ s, f i = ∏ i ∈ t, g i := prod_equiv (.ofBijective e he) hst hfg
@[to_additive]
lemma prod_of_injOn (e : ι → κ) (he : Set.InjOn e s) (hest : Set.MapsTo e s t)
(h' : ∀ i ∈ t, i ∉ e '' s → g i = 1) (h : ∀ i ∈ s, f i = g (e i)) :
∏ i ∈ s, f i = ∏ j ∈ t, g j := by
classical
exact (prod_nbij e (fun a ↦ mem_image_of_mem e) he (by simp [Set.surjOn_image]) h).trans <|
prod_subset (image_subset_iff.2 hest) <| by simpa using h'
variable [DecidableEq κ]
@[to_additive]
lemma prod_fiberwise_eq_prod_filter (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : ι → α) :
∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s.filter fun i ↦ g i ∈ t, f i := by
rw [← prod_disjiUnion, disjiUnion_filter_eq]
@[to_additive]
lemma prod_fiberwise_eq_prod_filter' (s : Finset ι) (t : Finset κ) (g : ι → κ) (f : κ → α) :
∏ j ∈ t, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s.filter fun i ↦ g i ∈ t, f (g i) := by
calc
_ = ∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f (g i) :=
prod_congr rfl fun j _ ↦ prod_congr rfl fun i hi ↦ by rw [(mem_filter.1 hi).2]
_ = _ := prod_fiberwise_eq_prod_filter _ _ _ _
@[to_additive]
lemma prod_fiberwise_of_maps_to {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : ι → α) :
∏ j ∈ t, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s, f i := by
rw [← prod_disjiUnion, disjiUnion_filter_eq_of_maps_to h]
#align finset.prod_fiberwise_of_maps_to Finset.prod_fiberwise_of_maps_to
#align finset.sum_fiberwise_of_maps_to Finset.sum_fiberwise_of_maps_to
@[to_additive]
lemma prod_fiberwise_of_maps_to' {g : ι → κ} (h : ∀ i ∈ s, g i ∈ t) (f : κ → α) :
∏ j ∈ t, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s, f (g i) := by
calc
_ = ∏ y ∈ t, ∏ x ∈ s.filter fun x ↦ g x = y, f (g x) :=
prod_congr rfl fun y _ ↦ prod_congr rfl fun x hx ↦ by rw [(mem_filter.1 hx).2]
_ = _ := prod_fiberwise_of_maps_to h _
variable [Fintype κ]
@[to_additive]
lemma prod_fiberwise (s : Finset ι) (g : ι → κ) (f : ι → α) :
∏ j, ∏ i ∈ s.filter fun i ↦ g i = j, f i = ∏ i ∈ s, f i :=
prod_fiberwise_of_maps_to (fun _ _ ↦ mem_univ _) _
#align finset.prod_fiberwise Finset.prod_fiberwise
#align finset.sum_fiberwise Finset.sum_fiberwise
@[to_additive]
lemma prod_fiberwise' (s : Finset ι) (g : ι → κ) (f : κ → α) :
∏ j, ∏ _i ∈ s.filter fun i ↦ g i = j, f j = ∏ i ∈ s, f (g i) :=
prod_fiberwise_of_maps_to' (fun _ _ ↦ mem_univ _) _
end bij
/-- Taking a product over `univ.pi t` is the same as taking the product over `Fintype.piFinset t`.
`univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`, but differ
in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and
`Fintype.piFinset t` is a `Finset (Π a, t a)`. -/
@[to_additive "Taking a sum over `univ.pi t` is the same as taking the sum over
`Fintype.piFinset t`. `univ.pi t` and `Fintype.piFinset t` are essentially the same `Finset`,
but differ in the type of their element, `univ.pi t` is a `Finset (Π a ∈ univ, t a)` and
`Fintype.piFinset t` is a `Finset (Π a, t a)`."]
lemma prod_univ_pi [DecidableEq ι] [Fintype ι] {κ : ι → Type*} (t : ∀ i, Finset (κ i))
(f : (∀ i ∈ (univ : Finset ι), κ i) → β) :
∏ x ∈ univ.pi t, f x = ∏ x ∈ Fintype.piFinset t, f fun a _ ↦ x a := by
apply prod_nbij' (fun x i ↦ x i $ mem_univ _) (fun x i _ ↦ x i) <;> simp
#align finset.prod_univ_pi Finset.prod_univ_pi
#align finset.sum_univ_pi Finset.sum_univ_pi
@[to_additive (attr := simp)]
lemma prod_diag [DecidableEq α] (s : Finset α) (f : α × α → β) :
∏ i ∈ s.diag, f i = ∏ i ∈ s, f (i, i) := by
apply prod_nbij' Prod.fst (fun i ↦ (i, i)) <;> simp
@[to_additive]
theorem prod_finset_product (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ × α → β} :
∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (c, a) := by
refine Eq.trans ?_ (prod_sigma s t fun p => f (p.1, p.2))
apply prod_equiv (Equiv.sigmaEquivProd _ _).symm <;> simp [h]
#align finset.prod_finset_product Finset.prod_finset_product
#align finset.sum_finset_product Finset.sum_finset_product
@[to_additive]
theorem prod_finset_product' (r : Finset (γ × α)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ → α → β} :
∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f c a :=
prod_finset_product r s t h
#align finset.prod_finset_product' Finset.prod_finset_product'
#align finset.sum_finset_product' Finset.sum_finset_product'
@[to_additive]
theorem prod_finset_product_right (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α × γ → β} :
∏ p ∈ r, f p = ∏ c ∈ s, ∏ a ∈ t c, f (a, c) := by
refine Eq.trans ?_ (prod_sigma s t fun p => f (p.2, p.1))
apply prod_equiv ((Equiv.prodComm _ _).trans (Equiv.sigmaEquivProd _ _).symm) <;> simp [h]
#align finset.prod_finset_product_right Finset.prod_finset_product_right
#align finset.sum_finset_product_right Finset.sum_finset_product_right
@[to_additive]
theorem prod_finset_product_right' (r : Finset (α × γ)) (s : Finset γ) (t : γ → Finset α)
(h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α → γ → β} :
∏ p ∈ r, f p.1 p.2 = ∏ c ∈ s, ∏ a ∈ t c, f a c :=
prod_finset_product_right r s t h
#align finset.prod_finset_product_right' Finset.prod_finset_product_right'
#align finset.sum_finset_product_right' Finset.sum_finset_product_right'
@[to_additive]
theorem prod_image' [DecidableEq α] {s : Finset γ} {g : γ → α} (h : γ → β)
(eq : ∀ c ∈ s, f (g c) = ∏ x ∈ s.filter fun c' => g c' = g c, h x) :
∏ x ∈ s.image g, f x = ∏ x ∈ s, h x :=
calc
∏ x ∈ s.image g, f x = ∏ x ∈ s.image g, ∏ x ∈ s.filter fun c' => g c' = x, h x :=
(prod_congr rfl) fun _x hx =>
let ⟨c, hcs, hc⟩ := mem_image.1 hx
hc ▸ eq c hcs
_ = ∏ x ∈ s, h x := prod_fiberwise_of_maps_to (fun _x => mem_image_of_mem g) _
#align finset.prod_image' Finset.prod_image'
#align finset.sum_image' Finset.sum_image'
@[to_additive]
theorem prod_mul_distrib : ∏ x ∈ s, f x * g x = (∏ x ∈ s, f x) * ∏ x ∈ s, g x :=
Eq.trans (by rw [one_mul]; rfl) fold_op_distrib
#align finset.prod_mul_distrib Finset.prod_mul_distrib
#align finset.sum_add_distrib Finset.sum_add_distrib
@[to_additive]
lemma prod_mul_prod_comm (f g h i : α → β) :
(∏ a ∈ s, f a * g a) * ∏ a ∈ s, h a * i a = (∏ a ∈ s, f a * h a) * ∏ a ∈ s, g a * i a := by
simp_rw [prod_mul_distrib, mul_mul_mul_comm]
@[to_additive]
theorem prod_product {s : Finset γ} {t : Finset α} {f : γ × α → β} :
∏ x ∈ s ×ˢ t, f x = ∏ x ∈ s, ∏ y ∈ t, f (x, y) :=
prod_finset_product (s ×ˢ t) s (fun _a => t) fun _p => mem_product
#align finset.prod_product Finset.prod_product
#align finset.sum_product Finset.sum_product
/-- An uncurried version of `Finset.prod_product`. -/
@[to_additive "An uncurried version of `Finset.sum_product`"]
theorem prod_product' {s : Finset γ} {t : Finset α} {f : γ → α → β} :
∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ x ∈ s, ∏ y ∈ t, f x y :=
prod_product
#align finset.prod_product' Finset.prod_product'
#align finset.sum_product' Finset.sum_product'
@[to_additive]
theorem prod_product_right {s : Finset γ} {t : Finset α} {f : γ × α → β} :
∏ x ∈ s ×ˢ t, f x = ∏ y ∈ t, ∏ x ∈ s, f (x, y) :=
prod_finset_product_right (s ×ˢ t) t (fun _a => s) fun _p => mem_product.trans and_comm
#align finset.prod_product_right Finset.prod_product_right
#align finset.sum_product_right Finset.sum_product_right
/-- An uncurried version of `Finset.prod_product_right`. -/
@[to_additive "An uncurried version of `Finset.sum_product_right`"]
theorem prod_product_right' {s : Finset γ} {t : Finset α} {f : γ → α → β} :
∏ x ∈ s ×ˢ t, f x.1 x.2 = ∏ y ∈ t, ∏ x ∈ s, f x y :=
prod_product_right
#align finset.prod_product_right' Finset.prod_product_right'
#align finset.sum_product_right' Finset.sum_product_right'
/-- Generalization of `Finset.prod_comm` to the case when the inner `Finset`s depend on the outer
variable. -/
@[to_additive "Generalization of `Finset.sum_comm` to the case when the inner `Finset`s depend on
the outer variable."]
theorem prod_comm' {s : Finset γ} {t : γ → Finset α} {t' : Finset α} {s' : α → Finset γ}
(h : ∀ x y, x ∈ s ∧ y ∈ t x ↔ x ∈ s' y ∧ y ∈ t') {f : γ → α → β} :
(∏ x ∈ s, ∏ y ∈ t x, f x y) = ∏ y ∈ t', ∏ x ∈ s' y, f x y := by
classical
have : ∀ z : γ × α, (z ∈ s.biUnion fun x => (t x).map <| Function.Embedding.sectr x _) ↔
z.1 ∈ s ∧ z.2 ∈ t z.1 := by
rintro ⟨x, y⟩
simp only [mem_biUnion, mem_map, Function.Embedding.sectr_apply, Prod.mk.injEq,
exists_eq_right, ← and_assoc]
exact
(prod_finset_product' _ _ _ this).symm.trans
((prod_finset_product_right' _ _ _) fun ⟨x, y⟩ => (this _).trans ((h x y).trans and_comm))
#align finset.prod_comm' Finset.prod_comm'
#align finset.sum_comm' Finset.sum_comm'
@[to_additive]
theorem prod_comm {s : Finset γ} {t : Finset α} {f : γ → α → β} :
(∏ x ∈ s, ∏ y ∈ t, f x y) = ∏ y ∈ t, ∏ x ∈ s, f x y :=
prod_comm' fun _ _ => Iff.rfl
#align finset.prod_comm Finset.prod_comm
#align finset.sum_comm Finset.sum_comm
@[to_additive]
theorem prod_hom_rel [CommMonoid γ] {r : β → γ → Prop} {f : α → β} {g : α → γ} {s : Finset α}
(h₁ : r 1 1) (h₂ : ∀ a b c, r b c → r (f a * b) (g a * c)) :
r (∏ x ∈ s, f x) (∏ x ∈ s, g x) := by
delta Finset.prod
apply Multiset.prod_hom_rel <;> assumption
#align finset.prod_hom_rel Finset.prod_hom_rel
#align finset.sum_hom_rel Finset.sum_hom_rel
@[to_additive]
theorem prod_filter_of_ne {p : α → Prop} [DecidablePred p] (hp : ∀ x ∈ s, f x ≠ 1 → p x) :
∏ x ∈ s.filter p, f x = ∏ x ∈ s, f x :=
(prod_subset (filter_subset _ _)) fun x => by
classical
rw [not_imp_comm, mem_filter]
exact fun h₁ h₂ => ⟨h₁, by simpa using hp _ h₁ h₂⟩
#align finset.prod_filter_of_ne Finset.prod_filter_of_ne
#align finset.sum_filter_of_ne Finset.sum_filter_of_ne
-- If we use `[DecidableEq β]` here, some rewrites fail because they find a wrong `Decidable`
-- instance first; `{∀ x, Decidable (f x ≠ 1)}` doesn't work with `rw ← prod_filter_ne_one`
@[to_additive]
theorem prod_filter_ne_one (s : Finset α) [∀ x, Decidable (f x ≠ 1)] :
∏ x ∈ s.filter fun x => f x ≠ 1, f x = ∏ x ∈ s, f x :=
prod_filter_of_ne fun _ _ => id
#align finset.prod_filter_ne_one Finset.prod_filter_ne_one
#align finset.sum_filter_ne_zero Finset.sum_filter_ne_zero
@[to_additive]
theorem prod_filter (p : α → Prop) [DecidablePred p] (f : α → β) :
∏ a ∈ s.filter p, f a = ∏ a ∈ s, if p a then f a else 1 :=
calc
∏ a ∈ s.filter p, f a = ∏ a ∈ s.filter p, if p a then f a else 1 :=
prod_congr rfl fun a h => by rw [if_pos]; simpa using (mem_filter.1 h).2
_ = ∏ a ∈ s, if p a then f a else 1 := by
{ refine prod_subset (filter_subset _ s) fun x hs h => ?_
rw [mem_filter, not_and] at h
exact if_neg (by simpa using h hs) }
#align finset.prod_filter Finset.prod_filter
#align finset.sum_filter Finset.sum_filter
@[to_additive]
theorem prod_eq_single_of_mem {s : Finset α} {f : α → β} (a : α) (h : a ∈ s)
(h₀ : ∀ b ∈ s, b ≠ a → f b = 1) : ∏ x ∈ s, f x = f a := by
haveI := Classical.decEq α
calc
∏ x ∈ s, f x = ∏ x ∈ {a}, f x := by
{ refine (prod_subset ?_ ?_).symm
· intro _ H
rwa [mem_singleton.1 H]
· simpa only [mem_singleton] }
_ = f a := prod_singleton _ _
#align finset.prod_eq_single_of_mem Finset.prod_eq_single_of_mem
#align finset.sum_eq_single_of_mem Finset.sum_eq_single_of_mem
@[to_additive]
theorem prod_eq_single {s : Finset α} {f : α → β} (a : α) (h₀ : ∀ b ∈ s, b ≠ a → f b = 1)
(h₁ : a ∉ s → f a = 1) : ∏ x ∈ s, f x = f a :=
haveI := Classical.decEq α
by_cases (prod_eq_single_of_mem a · h₀) fun this =>
(prod_congr rfl fun b hb => h₀ b hb <| by rintro rfl; exact this hb).trans <|
prod_const_one.trans (h₁ this).symm
#align finset.prod_eq_single Finset.prod_eq_single
#align finset.sum_eq_single Finset.sum_eq_single
@[to_additive]
lemma prod_union_eq_left [DecidableEq α] (hs : ∀ a ∈ s₂, a ∉ s₁ → f a = 1) :
∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₁, f a :=
Eq.symm <|
prod_subset subset_union_left fun _a ha ha' ↦ hs _ ((mem_union.1 ha).resolve_left ha') ha'
@[to_additive]
lemma prod_union_eq_right [DecidableEq α] (hs : ∀ a ∈ s₁, a ∉ s₂ → f a = 1) :
∏ a ∈ s₁ ∪ s₂, f a = ∏ a ∈ s₂, f a := by rw [union_comm, prod_union_eq_left hs]
@[to_additive]
theorem prod_eq_mul_of_mem {s : Finset α} {f : α → β} (a b : α) (ha : a ∈ s) (hb : b ∈ s)
(hn : a ≠ b) (h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) : ∏ x ∈ s, f x = f a * f b := by
haveI := Classical.decEq α; let s' := ({a, b} : Finset α)
have hu : s' ⊆ s := by
refine insert_subset_iff.mpr ?_
apply And.intro ha
apply singleton_subset_iff.mpr hb
have hf : ∀ c ∈ s, c ∉ s' → f c = 1 := by
intro c hc hcs
apply h₀ c hc
apply not_or.mp
intro hab
apply hcs
rw [mem_insert, mem_singleton]
exact hab
rw [← prod_subset hu hf]
exact Finset.prod_pair hn
#align finset.prod_eq_mul_of_mem Finset.prod_eq_mul_of_mem
#align finset.sum_eq_add_of_mem Finset.sum_eq_add_of_mem
@[to_additive]
theorem prod_eq_mul {s : Finset α} {f : α → β} (a b : α) (hn : a ≠ b)
(h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) (ha : a ∉ s → f a = 1) (hb : b ∉ s → f b = 1) :
∏ x ∈ s, f x = f a * f b := by
haveI := Classical.decEq α; by_cases h₁ : a ∈ s <;> by_cases h₂ : b ∈ s
· exact prod_eq_mul_of_mem a b h₁ h₂ hn h₀
· rw [hb h₂, mul_one]
apply prod_eq_single_of_mem a h₁
exact fun c hc hca => h₀ c hc ⟨hca, ne_of_mem_of_not_mem hc h₂⟩
· rw [ha h₁, one_mul]
apply prod_eq_single_of_mem b h₂
exact fun c hc hcb => h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, hcb⟩
· rw [ha h₁, hb h₂, mul_one]
exact
_root_.trans
(prod_congr rfl fun c hc =>
h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, ne_of_mem_of_not_mem hc h₂⟩)
prod_const_one
#align finset.prod_eq_mul Finset.prod_eq_mul
#align finset.sum_eq_add Finset.sum_eq_add
-- Porting note: simpNF linter complains that LHS doesn't simplify, but it does
/-- A product over `s.subtype p` equals one over `s.filter p`. -/
@[to_additive (attr := simp, nolint simpNF)
"A sum over `s.subtype p` equals one over `s.filter p`."]
theorem prod_subtype_eq_prod_filter (f : α → β) {p : α → Prop} [DecidablePred p] :
∏ x ∈ s.subtype p, f x = ∏ x ∈ s.filter p, f x := by
conv_lhs => erw [← prod_map (s.subtype p) (Function.Embedding.subtype _) f]
exact prod_congr (subtype_map _) fun x _hx => rfl
#align finset.prod_subtype_eq_prod_filter Finset.prod_subtype_eq_prod_filter
#align finset.sum_subtype_eq_sum_filter Finset.sum_subtype_eq_sum_filter
/-- If all elements of a `Finset` satisfy the predicate `p`, a product
over `s.subtype p` equals that product over `s`. -/
@[to_additive "If all elements of a `Finset` satisfy the predicate `p`, a sum
over `s.subtype p` equals that sum over `s`."]
theorem prod_subtype_of_mem (f : α → β) {p : α → Prop} [DecidablePred p] (h : ∀ x ∈ s, p x) :
∏ x ∈ s.subtype p, f x = ∏ x ∈ s, f x := by
rw [prod_subtype_eq_prod_filter, filter_true_of_mem]
simpa using h
#align finset.prod_subtype_of_mem Finset.prod_subtype_of_mem
#align finset.sum_subtype_of_mem Finset.sum_subtype_of_mem
/-- A product of a function over a `Finset` in a subtype equals a
product in the main type of a function that agrees with the first
function on that `Finset`. -/
@[to_additive "A sum of a function over a `Finset` in a subtype equals a
sum in the main type of a function that agrees with the first
function on that `Finset`."]
theorem prod_subtype_map_embedding {p : α → Prop} {s : Finset { x // p x }} {f : { x // p x } → β}
{g : α → β} (h : ∀ x : { x // p x }, x ∈ s → g x = f x) :
(∏ x ∈ s.map (Function.Embedding.subtype _), g x) = ∏ x ∈ s, f x := by
rw [Finset.prod_map]
exact Finset.prod_congr rfl h
#align finset.prod_subtype_map_embedding Finset.prod_subtype_map_embedding
#align finset.sum_subtype_map_embedding Finset.sum_subtype_map_embedding
variable (f s)
@[to_additive]
theorem prod_coe_sort_eq_attach (f : s → β) : ∏ i : s, f i = ∏ i ∈ s.attach, f i :=
rfl
#align finset.prod_coe_sort_eq_attach Finset.prod_coe_sort_eq_attach
#align finset.sum_coe_sort_eq_attach Finset.sum_coe_sort_eq_attach
@[to_additive]
theorem prod_coe_sort : ∏ i : s, f i = ∏ i ∈ s, f i := prod_attach _ _
#align finset.prod_coe_sort Finset.prod_coe_sort
#align finset.sum_coe_sort Finset.sum_coe_sort
@[to_additive]
theorem prod_finset_coe (f : α → β) (s : Finset α) : (∏ i : (s : Set α), f i) = ∏ i ∈ s, f i :=
prod_coe_sort s f
#align finset.prod_finset_coe Finset.prod_finset_coe
#align finset.sum_finset_coe Finset.sum_finset_coe
variable {f s}
@[to_additive]
theorem prod_subtype {p : α → Prop} {F : Fintype (Subtype p)} (s : Finset α) (h : ∀ x, x ∈ s ↔ p x)
(f : α → β) : ∏ a ∈ s, f a = ∏ a : Subtype p, f a := by
have : (· ∈ s) = p := Set.ext h
subst p
rw [← prod_coe_sort]
congr!
#align finset.prod_subtype Finset.prod_subtype
#align finset.sum_subtype Finset.sum_subtype
@[to_additive]
lemma prod_preimage' (f : ι → κ) [DecidablePred (· ∈ Set.range f)] (s : Finset κ) (hf) (g : κ → β) :
∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s.filter (· ∈ Set.range f), g x := by
classical
calc
∏ x ∈ preimage s f hf, g (f x) = ∏ x ∈ image f (preimage s f hf), g x :=
Eq.symm <| prod_image <| by simpa only [mem_preimage, Set.InjOn] using hf
_ = ∏ x ∈ s.filter fun x => x ∈ Set.range f, g x := by rw [image_preimage]
#align finset.prod_preimage' Finset.prod_preimage'
#align finset.sum_preimage' Finset.sum_preimage'
@[to_additive]
lemma prod_preimage (f : ι → κ) (s : Finset κ) (hf) (g : κ → β)
(hg : ∀ x ∈ s, x ∉ Set.range f → g x = 1) :
∏ x ∈ s.preimage f hf, g (f x) = ∏ x ∈ s, g x := by
classical rw [prod_preimage', prod_filter_of_ne]; exact fun x hx ↦ Not.imp_symm (hg x hx)
#align finset.prod_preimage Finset.prod_preimage
#align finset.sum_preimage Finset.sum_preimage
@[to_additive]
lemma prod_preimage_of_bij (f : ι → κ) (s : Finset κ) (hf : Set.BijOn f (f ⁻¹' ↑s) ↑s) (g : κ → β) :
∏ x ∈ s.preimage f hf.injOn, g (f x) = ∏ x ∈ s, g x :=
prod_preimage _ _ hf.injOn g fun _ hs h_f ↦ (h_f <| hf.subset_range hs).elim
#align finset.prod_preimage_of_bij Finset.prod_preimage_of_bij
#align finset.sum_preimage_of_bij Finset.sum_preimage_of_bij
@[to_additive]
theorem prod_set_coe (s : Set α) [Fintype s] : (∏ i : s, f i) = ∏ i ∈ s.toFinset, f i :=
(Finset.prod_subtype s.toFinset (fun _ ↦ Set.mem_toFinset) f).symm
/-- The product of a function `g` defined only on a set `s` is equal to
the product of a function `f` defined everywhere,
as long as `f` and `g` agree on `s`, and `f = 1` off `s`. -/
@[to_additive "The sum of a function `g` defined only on a set `s` is equal to
the sum of a function `f` defined everywhere,
as long as `f` and `g` agree on `s`, and `f = 0` off `s`."]
theorem prod_congr_set {α : Type*} [CommMonoid α] {β : Type*} [Fintype β] (s : Set β)
[DecidablePred (· ∈ s)] (f : β → α) (g : s → α) (w : ∀ (x : β) (h : x ∈ s), f x = g ⟨x, h⟩)
(w' : ∀ x : β, x ∉ s → f x = 1) : Finset.univ.prod f = Finset.univ.prod g := by
rw [← @Finset.prod_subset _ _ s.toFinset Finset.univ f _ (by simp)]
· rw [Finset.prod_subtype]
· apply Finset.prod_congr rfl
exact fun ⟨x, h⟩ _ => w x h
· simp
· rintro x _ h
exact w' x (by simpa using h)
#align finset.prod_congr_set Finset.prod_congr_set
#align finset.sum_congr_set Finset.sum_congr_set
@[to_additive]
theorem prod_apply_dite {s : Finset α} {p : α → Prop} {hp : DecidablePred p}
[DecidablePred fun x => ¬p x] (f : ∀ x : α, p x → γ) (g : ∀ x : α, ¬p x → γ) (h : γ → β) :
(∏ x ∈ s, h (if hx : p x then f x hx else g x hx)) =
(∏ x ∈ (s.filter p).attach, h (f x.1 <| by simpa using (mem_filter.mp x.2).2)) *
∏ x ∈ (s.filter fun x => ¬p x).attach, h (g x.1 <| by simpa using (mem_filter.mp x.2).2) :=
calc
(∏ x ∈ s, h (if hx : p x then f x hx else g x hx)) =
(∏ x ∈ s.filter p, h (if hx : p x then f x hx else g x hx)) *
∏ x ∈ s.filter (¬p ·), h (if hx : p x then f x hx else g x hx) :=
(prod_filter_mul_prod_filter_not s p _).symm
_ = (∏ x ∈ (s.filter p).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx)) *
∏ x ∈ (s.filter (¬p ·)).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx) :=
congr_arg₂ _ (prod_attach _ _).symm (prod_attach _ _).symm
_ = (∏ x ∈ (s.filter p).attach, h (f x.1 <| by simpa using (mem_filter.mp x.2).2)) *
∏ x ∈ (s.filter (¬p ·)).attach, h (g x.1 <| by simpa using (mem_filter.mp x.2).2) :=
congr_arg₂ _ (prod_congr rfl fun x _hx ↦
congr_arg h (dif_pos <| by simpa using (mem_filter.mp x.2).2))
(prod_congr rfl fun x _hx => congr_arg h (dif_neg <| by simpa using (mem_filter.mp x.2).2))
#align finset.prod_apply_dite Finset.prod_apply_dite
#align finset.sum_apply_dite Finset.sum_apply_dite
@[to_additive]
theorem prod_apply_ite {s : Finset α} {p : α → Prop} {_hp : DecidablePred p} (f g : α → γ)
(h : γ → β) :
(∏ x ∈ s, h (if p x then f x else g x)) =
(∏ x ∈ s.filter p, h (f x)) * ∏ x ∈ s.filter fun x => ¬p x, h (g x) :=
(prod_apply_dite _ _ _).trans <| congr_arg₂ _ (prod_attach _ (h ∘ f)) (prod_attach _ (h ∘ g))
#align finset.prod_apply_ite Finset.prod_apply_ite
#align finset.sum_apply_ite Finset.sum_apply_ite
@[to_additive]
theorem prod_dite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} (f : ∀ x : α, p x → β)
(g : ∀ x : α, ¬p x → β) :
∏ x ∈ s, (if hx : p x then f x hx else g x hx) =
(∏ x ∈ (s.filter p).attach, f x.1 (by simpa using (mem_filter.mp x.2).2)) *
∏ x ∈ (s.filter fun x => ¬p x).attach, g x.1 (by simpa using (mem_filter.mp x.2).2) := by
simp [prod_apply_dite _ _ fun x => x]
#align finset.prod_dite Finset.prod_dite
#align finset.sum_dite Finset.sum_dite
@[to_additive]
theorem prod_ite {s : Finset α} {p : α → Prop} {hp : DecidablePred p} (f g : α → β) :
∏ x ∈ s, (if p x then f x else g x) =
(∏ x ∈ s.filter p, f x) * ∏ x ∈ s.filter fun x => ¬p x, g x := by
simp [prod_apply_ite _ _ fun x => x]
#align finset.prod_ite Finset.prod_ite
#align finset.sum_ite Finset.sum_ite
@[to_additive]
theorem prod_ite_of_false {p : α → Prop} {hp : DecidablePred p} (f g : α → β) (h : ∀ x ∈ s, ¬p x) :
∏ x ∈ s, (if p x then f x else g x) = ∏ x ∈ s, g x := by
rw [prod_ite, filter_false_of_mem, filter_true_of_mem]
· simp only [prod_empty, one_mul]
all_goals intros; apply h; assumption
#align finset.prod_ite_of_false Finset.prod_ite_of_false
#align finset.sum_ite_of_false Finset.sum_ite_of_false
@[to_additive]
theorem prod_ite_of_true {p : α → Prop} {hp : DecidablePred p} (f g : α → β) (h : ∀ x ∈ s, p x) :
∏ x ∈ s, (if p x then f x else g x) = ∏ x ∈ s, f x := by
simp_rw [← ite_not (p _)]
apply prod_ite_of_false
simpa
#align finset.prod_ite_of_true Finset.prod_ite_of_true
#align finset.sum_ite_of_true Finset.sum_ite_of_true
@[to_additive]
theorem prod_apply_ite_of_false {p : α → Prop} {hp : DecidablePred p} (f g : α → γ) (k : γ → β)
(h : ∀ x ∈ s, ¬p x) : (∏ x ∈ s, k (if p x then f x else g x)) = ∏ x ∈ s, k (g x) := by
simp_rw [apply_ite k]
exact prod_ite_of_false _ _ h
#align finset.prod_apply_ite_of_false Finset.prod_apply_ite_of_false
#align finset.sum_apply_ite_of_false Finset.sum_apply_ite_of_false
@[to_additive]
theorem prod_apply_ite_of_true {p : α → Prop} {hp : DecidablePred p} (f g : α → γ) (k : γ → β)
(h : ∀ x ∈ s, p x) : (∏ x ∈ s, k (if p x then f x else g x)) = ∏ x ∈ s, k (f x) := by
simp_rw [apply_ite k]
exact prod_ite_of_true _ _ h
#align finset.prod_apply_ite_of_true Finset.prod_apply_ite_of_true
#align finset.sum_apply_ite_of_true Finset.sum_apply_ite_of_true
@[to_additive]
theorem prod_extend_by_one [DecidableEq α] (s : Finset α) (f : α → β) :
∏ i ∈ s, (if i ∈ s then f i else 1) = ∏ i ∈ s, f i :=
(prod_congr rfl) fun _i hi => if_pos hi
#align finset.prod_extend_by_one Finset.prod_extend_by_one
#align finset.sum_extend_by_zero Finset.sum_extend_by_zero
@[to_additive (attr := simp)]
theorem prod_ite_mem [DecidableEq α] (s t : Finset α) (f : α → β) :
∏ i ∈ s, (if i ∈ t then f i else 1) = ∏ i ∈ s ∩ t, f i := by
rw [← Finset.prod_filter, Finset.filter_mem_eq_inter]
#align finset.prod_ite_mem Finset.prod_ite_mem
#align finset.sum_ite_mem Finset.sum_ite_mem
@[to_additive (attr := simp)]
theorem prod_dite_eq [DecidableEq α] (s : Finset α) (a : α) (b : ∀ x : α, a = x → β) :
∏ x ∈ s, (if h : a = x then b x h else 1) = ite (a ∈ s) (b a rfl) 1 := by
split_ifs with h
· rw [Finset.prod_eq_single a, dif_pos rfl]
· intros _ _ h
rw [dif_neg]
exact h.symm
· simp [h]
· rw [Finset.prod_eq_one]
intros
rw [dif_neg]
rintro rfl
contradiction
#align finset.prod_dite_eq Finset.prod_dite_eq
#align finset.sum_dite_eq Finset.sum_dite_eq
@[to_additive (attr := simp)]
theorem prod_dite_eq' [DecidableEq α] (s : Finset α) (a : α) (b : ∀ x : α, x = a → β) :
∏ x ∈ s, (if h : x = a then b x h else 1) = ite (a ∈ s) (b a rfl) 1 := by
split_ifs with h
· rw [Finset.prod_eq_single a, dif_pos rfl]
· intros _ _ h
rw [dif_neg]
exact h
· simp [h]
· rw [Finset.prod_eq_one]
intros
rw [dif_neg]
rintro rfl
contradiction
#align finset.prod_dite_eq' Finset.prod_dite_eq'
#align finset.sum_dite_eq' Finset.sum_dite_eq'
@[to_additive (attr := simp)]
theorem prod_ite_eq [DecidableEq α] (s : Finset α) (a : α) (b : α → β) :
(∏ x ∈ s, ite (a = x) (b x) 1) = ite (a ∈ s) (b a) 1 :=
prod_dite_eq s a fun x _ => b x
#align finset.prod_ite_eq Finset.prod_ite_eq
#align finset.sum_ite_eq Finset.sum_ite_eq
/-- A product taken over a conditional whose condition is an equality test on the index and whose
alternative is `1` has value either the term at that index or `1`.
The difference with `Finset.prod_ite_eq` is that the arguments to `Eq` are swapped. -/
@[to_additive (attr := simp) "A sum taken over a conditional whose condition is an equality
test on the index and whose alternative is `0` has value either the term at that index or `0`.
The difference with `Finset.sum_ite_eq` is that the arguments to `Eq` are swapped."]
theorem prod_ite_eq' [DecidableEq α] (s : Finset α) (a : α) (b : α → β) :
(∏ x ∈ s, ite (x = a) (b x) 1) = ite (a ∈ s) (b a) 1 :=
prod_dite_eq' s a fun x _ => b x
#align finset.prod_ite_eq' Finset.prod_ite_eq'
#align finset.sum_ite_eq' Finset.sum_ite_eq'
@[to_additive]
theorem prod_ite_index (p : Prop) [Decidable p] (s t : Finset α) (f : α → β) :
∏ x ∈ if p then s else t, f x = if p then ∏ x ∈ s, f x else ∏ x ∈ t, f x :=
apply_ite (fun s => ∏ x ∈ s, f x) _ _ _
#align finset.prod_ite_index Finset.prod_ite_index
#align finset.sum_ite_index Finset.sum_ite_index
@[to_additive (attr := simp)]
theorem prod_ite_irrel (p : Prop) [Decidable p] (s : Finset α) (f g : α → β) :
∏ x ∈ s, (if p then f x else g x) = if p then ∏ x ∈ s, f x else ∏ x ∈ s, g x := by
split_ifs with h <;> rfl
#align finset.prod_ite_irrel Finset.prod_ite_irrel
#align finset.sum_ite_irrel Finset.sum_ite_irrel
@[to_additive (attr := simp)]
theorem prod_dite_irrel (p : Prop) [Decidable p] (s : Finset α) (f : p → α → β) (g : ¬p → α → β) :
∏ x ∈ s, (if h : p then f h x else g h x) =
if h : p then ∏ x ∈ s, f h x else ∏ x ∈ s, g h x := by
split_ifs with h <;> rfl
#align finset.prod_dite_irrel Finset.prod_dite_irrel
#align finset.sum_dite_irrel Finset.sum_dite_irrel
@[to_additive (attr := simp)]
theorem prod_pi_mulSingle' [DecidableEq α] (a : α) (x : β) (s : Finset α) :
∏ a' ∈ s, Pi.mulSingle a x a' = if a ∈ s then x else 1 :=
prod_dite_eq' _ _ _
#align finset.prod_pi_mul_single' Finset.prod_pi_mulSingle'
#align finset.sum_pi_single' Finset.sum_pi_single'
@[to_additive (attr := simp)]
theorem prod_pi_mulSingle {β : α → Type*} [DecidableEq α] [∀ a, CommMonoid (β a)] (a : α)
(f : ∀ a, β a) (s : Finset α) :
(∏ a' ∈ s, Pi.mulSingle a' (f a') a) = if a ∈ s then f a else 1 :=
prod_dite_eq _ _ _
#align finset.prod_pi_mul_single Finset.prod_pi_mulSingle
@[to_additive]
lemma mulSupport_prod (s : Finset ι) (f : ι → α → β) :
mulSupport (fun x ↦ ∏ i ∈ s, f i x) ⊆ ⋃ i ∈ s, mulSupport (f i) := by
simp only [mulSupport_subset_iff', Set.mem_iUnion, not_exists, nmem_mulSupport]
exact fun x ↦ prod_eq_one
#align function.mul_support_prod Finset.mulSupport_prod
#align function.support_sum Finset.support_sum
section indicator
open Set
variable {κ : Type*}
/-- Consider a product of `g i (f i)` over a finset. Suppose `g` is a function such as
`n ↦ (· ^ n)`, which maps a second argument of `1` to `1`. Then if `f` is replaced by the
corresponding multiplicative indicator function, the finset may be replaced by a possibly larger
finset without changing the value of the product. -/
@[to_additive "Consider a sum of `g i (f i)` over a finset. Suppose `g` is a function such as
`n ↦ (n • ·)`, which maps a second argument of `0` to `0` (or a weighted sum of `f i * h i` or
`f i • h i`, where `f` gives the weights that are multiplied by some other function `h`). Then if
`f` is replaced by the corresponding indicator function, the finset may be replaced by a possibly
larger finset without changing the value of the sum."]
lemma prod_mulIndicator_subset_of_eq_one [One α] (f : ι → α) (g : ι → α → β) {s t : Finset ι}
(h : s ⊆ t) (hg : ∀ a, g a 1 = 1) :
∏ i ∈ t, g i (mulIndicator ↑s f i) = ∏ i ∈ s, g i (f i) := by
calc
_ = ∏ i ∈ s, g i (mulIndicator ↑s f i) := by rw [prod_subset h fun i _ hn ↦ by simp [hn, hg]]
-- Porting note: This did not use to need the implicit argument
_ = _ := prod_congr rfl fun i hi ↦ congr_arg _ <| mulIndicator_of_mem (α := ι) hi f
#align set.prod_mul_indicator_subset_of_eq_one Finset.prod_mulIndicator_subset_of_eq_one
#align set.sum_indicator_subset_of_eq_zero Finset.sum_indicator_subset_of_eq_zero
/-- Taking the product of an indicator function over a possibly larger finset is the same as
taking the original function over the original finset. -/
@[to_additive "Summing an indicator function over a possibly larger `Finset` is the same as summing
the original function over the original finset."]
lemma prod_mulIndicator_subset (f : ι → β) {s t : Finset ι} (h : s ⊆ t) :
∏ i ∈ t, mulIndicator (↑s) f i = ∏ i ∈ s, f i :=
prod_mulIndicator_subset_of_eq_one _ (fun _ ↦ id) h fun _ ↦ rfl
#align set.prod_mul_indicator_subset Finset.prod_mulIndicator_subset
#align set.sum_indicator_subset Finset.sum_indicator_subset
@[to_additive]
lemma prod_mulIndicator_eq_prod_filter (s : Finset ι) (f : ι → κ → β) (t : ι → Set κ) (g : ι → κ)
[DecidablePred fun i ↦ g i ∈ t i] :
∏ i ∈ s, mulIndicator (t i) (f i) (g i) = ∏ i ∈ s.filter fun i ↦ g i ∈ t i, f i (g i) := by
refine (prod_filter_mul_prod_filter_not s (fun i ↦ g i ∈ t i) _).symm.trans <|
Eq.trans (congr_arg₂ (· * ·) ?_ ?_) (mul_one _)
· exact prod_congr rfl fun x hx ↦ mulIndicator_of_mem (mem_filter.1 hx).2 _
· exact prod_eq_one fun x hx ↦ mulIndicator_of_not_mem (mem_filter.1 hx).2 _
#align finset.prod_mul_indicator_eq_prod_filter Finset.prod_mulIndicator_eq_prod_filter
#align finset.sum_indicator_eq_sum_filter Finset.sum_indicator_eq_sum_filter
@[to_additive]
lemma prod_mulIndicator_eq_prod_inter [DecidableEq ι] (s t : Finset ι) (f : ι → β) :
∏ i ∈ s, (t : Set ι).mulIndicator f i = ∏ i ∈ s ∩ t, f i := by
rw [← filter_mem_eq_inter, prod_mulIndicator_eq_prod_filter]; rfl
@[to_additive]
lemma mulIndicator_prod (s : Finset ι) (t : Set κ) (f : ι → κ → β) :
mulIndicator t (∏ i ∈ s, f i) = ∏ i ∈ s, mulIndicator t (f i) :=
map_prod (mulIndicatorHom _ _) _ _
#align set.mul_indicator_finset_prod Finset.mulIndicator_prod
#align set.indicator_finset_sum Finset.indicator_sum
variable {κ : Type*}
@[to_additive]
lemma mulIndicator_biUnion (s : Finset ι) (t : ι → Set κ) {f : κ → β} :
((s : Set ι).PairwiseDisjoint t) →
mulIndicator (⋃ i ∈ s, t i) f = fun a ↦ ∏ i ∈ s, mulIndicator (t i) f a := by
classical
refine Finset.induction_on s (by simp) fun i s hi ih hs ↦ funext fun j ↦ ?_
rw [prod_insert hi, set_biUnion_insert, mulIndicator_union_of_not_mem_inter,
ih (hs.subset <| subset_insert _ _)]
simp only [not_exists, exists_prop, mem_iUnion, mem_inter_iff, not_and]
exact fun hji i' hi' hji' ↦ (ne_of_mem_of_not_mem hi' hi).symm <|
hs.elim_set (mem_insert_self _ _) (mem_insert_of_mem hi') _ hji hji'
#align set.mul_indicator_finset_bUnion Finset.mulIndicator_biUnion
#align set.indicator_finset_bUnion Finset.indicator_biUnion
@[to_additive]
lemma mulIndicator_biUnion_apply (s : Finset ι) (t : ι → Set κ) {f : κ → β}
(h : (s : Set ι).PairwiseDisjoint t) (x : κ) :
mulIndicator (⋃ i ∈ s, t i) f x = ∏ i ∈ s, mulIndicator (t i) f x := by
rw [mulIndicator_biUnion s t h]
#align set.mul_indicator_finset_bUnion_apply Finset.mulIndicator_biUnion_apply
#align set.indicator_finset_bUnion_apply Finset.indicator_biUnion_apply
end indicator
@[to_additive]
theorem prod_bij_ne_one {s : Finset α} {t : Finset γ} {f : α → β} {g : γ → β}
(i : ∀ a ∈ s, f a ≠ 1 → γ) (hi : ∀ a h₁ h₂, i a h₁ h₂ ∈ t)
(i_inj : ∀ a₁ h₁₁ h₁₂ a₂ h₂₁ h₂₂, i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂)
(i_surj : ∀ b ∈ t, g b ≠ 1 → ∃ a h₁ h₂, i a h₁ h₂ = b) (h : ∀ a h₁ h₂, f a = g (i a h₁ h₂)) :
∏ x ∈ s, f x = ∏ x ∈ t, g x := by
classical
calc
∏ x ∈ s, f x = ∏ x ∈ s.filter fun x => f x ≠ 1, f x := by rw [prod_filter_ne_one]
_ = ∏ x ∈ t.filter fun x => g x ≠ 1, g x :=
prod_bij (fun a ha => i a (mem_filter.mp ha).1 <| by simpa using (mem_filter.mp ha).2)
?_ ?_ ?_ ?_
_ = ∏ x ∈ t, g x := prod_filter_ne_one _
· intros a ha
refine (mem_filter.mp ha).elim ?_
intros h₁ h₂
refine (mem_filter.mpr ⟨hi a h₁ _, ?_⟩)
specialize h a h₁ fun H ↦ by rw [H] at h₂; simp at h₂
rwa [← h]
· intros a₁ ha₁ a₂ ha₂
refine (mem_filter.mp ha₁).elim fun _ha₁₁ _ha₁₂ ↦ ?_
refine (mem_filter.mp ha₂).elim fun _ha₂₁ _ha₂₂ ↦ ?_
apply i_inj
· intros b hb
refine (mem_filter.mp hb).elim fun h₁ h₂ ↦ ?_
obtain ⟨a, ha₁, ha₂, eq⟩ := i_surj b h₁ fun H ↦ by rw [H] at h₂; simp at h₂
exact ⟨a, mem_filter.mpr ⟨ha₁, ha₂⟩, eq⟩
· refine (fun a ha => (mem_filter.mp ha).elim fun h₁ h₂ ↦ ?_)
exact h a h₁ fun H ↦ by rw [H] at h₂; simp at h₂
#align finset.prod_bij_ne_one Finset.prod_bij_ne_one
#align finset.sum_bij_ne_zero Finset.sum_bij_ne_zero
@[to_additive]
theorem prod_dite_of_false {p : α → Prop} {hp : DecidablePred p} (h : ∀ x ∈ s, ¬p x)
(f : ∀ x : α, p x → β) (g : ∀ x : α, ¬p x → β) :
∏ x ∈ s, (if hx : p x then f x hx else g x hx) = ∏ x : s, g x.val (h x.val x.property) := by
refine prod_bij' (fun x hx => ⟨x, hx⟩) (fun x _ ↦ x) ?_ ?_ ?_ ?_ ?_ <;> aesop
#align finset.prod_dite_of_false Finset.prod_dite_of_false
#align finset.sum_dite_of_false Finset.sum_dite_of_false
@[to_additive]
theorem prod_dite_of_true {p : α → Prop} {hp : DecidablePred p} (h : ∀ x ∈ s, p x)
(f : ∀ x : α, p x → β) (g : ∀ x : α, ¬p x → β) :
∏ x ∈ s, (if hx : p x then f x hx else g x hx) = ∏ x : s, f x.val (h x.val x.property) := by
refine prod_bij' (fun x hx => ⟨x, hx⟩) (fun x _ ↦ x) ?_ ?_ ?_ ?_ ?_ <;> aesop
#align finset.prod_dite_of_true Finset.prod_dite_of_true
#align finset.sum_dite_of_true Finset.sum_dite_of_true
@[to_additive]
theorem nonempty_of_prod_ne_one (h : ∏ x ∈ s, f x ≠ 1) : s.Nonempty :=
s.eq_empty_or_nonempty.elim (fun H => False.elim <| h <| H.symm ▸ prod_empty) id
#align finset.nonempty_of_prod_ne_one Finset.nonempty_of_prod_ne_one
#align finset.nonempty_of_sum_ne_zero Finset.nonempty_of_sum_ne_zero
@[to_additive]
theorem exists_ne_one_of_prod_ne_one (h : ∏ x ∈ s, f x ≠ 1) : ∃ a ∈ s, f a ≠ 1 := by
classical
rw [← prod_filter_ne_one] at h
rcases nonempty_of_prod_ne_one h with ⟨x, hx⟩
exact ⟨x, (mem_filter.1 hx).1, by simpa using (mem_filter.1 hx).2⟩
#align finset.exists_ne_one_of_prod_ne_one Finset.exists_ne_one_of_prod_ne_one
#align finset.exists_ne_zero_of_sum_ne_zero Finset.exists_ne_zero_of_sum_ne_zero
@[to_additive]
theorem prod_range_succ_comm (f : ℕ → β) (n : ℕ) :
(∏ x ∈ range (n + 1), f x) = f n * ∏ x ∈ range n, f x := by
rw [range_succ, prod_insert not_mem_range_self]
#align finset.prod_range_succ_comm Finset.prod_range_succ_comm
#align finset.sum_range_succ_comm Finset.sum_range_succ_comm
@[to_additive]
theorem prod_range_succ (f : ℕ → β) (n : ℕ) :
(∏ x ∈ range (n + 1), f x) = (∏ x ∈ range n, f x) * f n := by
simp only [mul_comm, prod_range_succ_comm]
#align finset.prod_range_succ Finset.prod_range_succ
#align finset.sum_range_succ Finset.sum_range_succ
@[to_additive]
theorem prod_range_succ' (f : ℕ → β) :
∀ n : ℕ, (∏ k ∈ range (n + 1), f k) = (∏ k ∈ range n, f (k + 1)) * f 0
| 0 => prod_range_succ _ _
| n + 1 => by rw [prod_range_succ _ n, mul_right_comm, ← prod_range_succ' _ n, prod_range_succ]
#align finset.prod_range_succ' Finset.prod_range_succ'
#align finset.sum_range_succ' Finset.sum_range_succ'
@[to_additive]
theorem eventually_constant_prod {u : ℕ → β} {N : ℕ} (hu : ∀ n ≥ N, u n = 1) {n : ℕ} (hn : N ≤ n) :
(∏ k ∈ range n, u k) = ∏ k ∈ range N, u k := by
obtain ⟨m, rfl : n = N + m⟩ := Nat.exists_eq_add_of_le hn
clear hn
induction' m with m hm
· simp
· simp [← add_assoc, prod_range_succ, hm, hu]
#align finset.eventually_constant_prod Finset.eventually_constant_prod
#align finset.eventually_constant_sum Finset.eventually_constant_sum
@[to_additive]
theorem prod_range_add (f : ℕ → β) (n m : ℕ) :
(∏ x ∈ range (n + m), f x) = (∏ x ∈ range n, f x) * ∏ x ∈ range m, f (n + x) := by
induction' m with m hm
· simp
· erw [Nat.add_succ, prod_range_succ, prod_range_succ, hm, mul_assoc]
#align finset.prod_range_add Finset.prod_range_add
#align finset.sum_range_add Finset.sum_range_add
@[to_additive]
theorem prod_range_add_div_prod_range {α : Type*} [CommGroup α] (f : ℕ → α) (n m : ℕ) :
(∏ k ∈ range (n + m), f k) / ∏ k ∈ range n, f k = ∏ k ∈ Finset.range m, f (n + k) :=
div_eq_of_eq_mul' (prod_range_add f n m)
#align finset.prod_range_add_div_prod_range Finset.prod_range_add_div_prod_range
#align finset.sum_range_add_sub_sum_range Finset.sum_range_add_sub_sum_range
@[to_additive]
theorem prod_range_zero (f : ℕ → β) : ∏ k ∈ range 0, f k = 1 := by rw [range_zero, prod_empty]
#align finset.prod_range_zero Finset.prod_range_zero
#align finset.sum_range_zero Finset.sum_range_zero
@[to_additive sum_range_one]
theorem prod_range_one (f : ℕ → β) : ∏ k ∈ range 1, f k = f 0 := by
rw [range_one, prod_singleton]
#align finset.prod_range_one Finset.prod_range_one
#align finset.sum_range_one Finset.sum_range_one
open List
@[to_additive]
theorem prod_list_map_count [DecidableEq α] (l : List α) {M : Type*} [CommMonoid M] (f : α → M) :
(l.map f).prod = ∏ m ∈ l.toFinset, f m ^ l.count m := by
induction' l with a s IH; · simp only [map_nil, prod_nil, count_nil, pow_zero, prod_const_one]
simp only [List.map, List.prod_cons, toFinset_cons, IH]
by_cases has : a ∈ s.toFinset
· rw [insert_eq_of_mem has, ← insert_erase has, prod_insert (not_mem_erase _ _),
prod_insert (not_mem_erase _ _), ← mul_assoc, count_cons_self, pow_succ']
congr 1
refine prod_congr rfl fun x hx => ?_
rw [count_cons_of_ne (ne_of_mem_erase hx)]
rw [prod_insert has, count_cons_self, count_eq_zero_of_not_mem (mt mem_toFinset.2 has), pow_one]
congr 1
refine prod_congr rfl fun x hx => ?_
rw [count_cons_of_ne]
rintro rfl
exact has hx
#align finset.prod_list_map_count Finset.prod_list_map_count
#align finset.sum_list_map_count Finset.sum_list_map_count
@[to_additive]
theorem prod_list_count [DecidableEq α] [CommMonoid α] (s : List α) :
s.prod = ∏ m ∈ s.toFinset, m ^ s.count m := by simpa using prod_list_map_count s id
#align finset.prod_list_count Finset.prod_list_count
#align finset.sum_list_count Finset.sum_list_count
@[to_additive]
theorem prod_list_count_of_subset [DecidableEq α] [CommMonoid α] (m : List α) (s : Finset α)
(hs : m.toFinset ⊆ s) : m.prod = ∏ i ∈ s, i ^ m.count i := by
rw [prod_list_count]
refine prod_subset hs fun x _ hx => ?_
rw [mem_toFinset] at hx
rw [count_eq_zero_of_not_mem hx, pow_zero]
#align finset.prod_list_count_of_subset Finset.prod_list_count_of_subset
#align finset.sum_list_count_of_subset Finset.sum_list_count_of_subset
theorem sum_filter_count_eq_countP [DecidableEq α] (p : α → Prop) [DecidablePred p] (l : List α) :
∑ x ∈ l.toFinset.filter p, l.count x = l.countP p := by
simp [Finset.sum, sum_map_count_dedup_filter_eq_countP p l]
#align finset.sum_filter_count_eq_countp Finset.sum_filter_count_eq_countP
open Multiset
@[to_additive]
theorem prod_multiset_map_count [DecidableEq α] (s : Multiset α) {M : Type*} [CommMonoid M]
(f : α → M) : (s.map f).prod = ∏ m ∈ s.toFinset, f m ^ s.count m := by
refine Quot.induction_on s fun l => ?_
simp [prod_list_map_count l f]
#align finset.prod_multiset_map_count Finset.prod_multiset_map_count
#align finset.sum_multiset_map_count Finset.sum_multiset_map_count
@[to_additive]
theorem prod_multiset_count [DecidableEq α] [CommMonoid α] (s : Multiset α) :
s.prod = ∏ m ∈ s.toFinset, m ^ s.count m := by
convert prod_multiset_map_count s id
rw [Multiset.map_id]
#align finset.prod_multiset_count Finset.prod_multiset_count
#align finset.sum_multiset_count Finset.sum_multiset_count
@[to_additive]
theorem prod_multiset_count_of_subset [DecidableEq α] [CommMonoid α] (m : Multiset α) (s : Finset α)
(hs : m.toFinset ⊆ s) : m.prod = ∏ i ∈ s, i ^ m.count i := by
revert hs
refine Quot.induction_on m fun l => ?_
simp only [quot_mk_to_coe'', prod_coe, coe_count]
apply prod_list_count_of_subset l s
#align finset.prod_multiset_count_of_subset Finset.prod_multiset_count_of_subset
#align finset.sum_multiset_count_of_subset Finset.sum_multiset_count_of_subset
@[to_additive]
theorem prod_mem_multiset [DecidableEq α] (m : Multiset α) (f : { x // x ∈ m } → β) (g : α → β)
(hfg : ∀ x, f x = g x) : ∏ x : { x // x ∈ m }, f x = ∏ x ∈ m.toFinset, g x := by
refine prod_bij' (fun x _ ↦ x) (fun x hx ↦ ⟨x, Multiset.mem_toFinset.1 hx⟩) ?_ ?_ ?_ ?_ ?_ <;>
simp [hfg]
#align finset.prod_mem_multiset Finset.prod_mem_multiset
#align finset.sum_mem_multiset Finset.sum_mem_multiset
/-- To prove a property of a product, it suffices to prove that
the property is multiplicative and holds on factors. -/
@[to_additive "To prove a property of a sum, it suffices to prove that
the property is additive and holds on summands."]
theorem prod_induction {M : Type*} [CommMonoid M] (f : α → M) (p : M → Prop)
(hom : ∀ a b, p a → p b → p (a * b)) (unit : p 1) (base : ∀ x ∈ s, p <| f x) :
p <| ∏ x ∈ s, f x :=
Multiset.prod_induction _ _ hom unit (Multiset.forall_mem_map_iff.mpr base)
#align finset.prod_induction Finset.prod_induction
#align finset.sum_induction Finset.sum_induction
/-- To prove a property of a product, it suffices to prove that
the property is multiplicative and holds on factors. -/
@[to_additive "To prove a property of a sum, it suffices to prove that
the property is additive and holds on summands."]
theorem prod_induction_nonempty {M : Type*} [CommMonoid M] (f : α → M) (p : M → Prop)
(hom : ∀ a b, p a → p b → p (a * b)) (nonempty : s.Nonempty) (base : ∀ x ∈ s, p <| f x) :
p <| ∏ x ∈ s, f x :=
Multiset.prod_induction_nonempty p hom (by simp [nonempty_iff_ne_empty.mp nonempty])
(Multiset.forall_mem_map_iff.mpr base)
#align finset.prod_induction_nonempty Finset.prod_induction_nonempty
#align finset.sum_induction_nonempty Finset.sum_induction_nonempty
/-- For any product along `{0, ..., n - 1}` of a commutative-monoid-valued function, we can verify
that it's equal to a different function just by checking ratios of adjacent terms.
This is a multiplicative discrete analogue of the fundamental theorem of calculus. -/
@[to_additive "For any sum along `{0, ..., n - 1}` of a commutative-monoid-valued function, we can
verify that it's equal to a different function just by checking differences of adjacent terms.
This is a discrete analogue of the fundamental theorem of calculus."]
theorem prod_range_induction (f s : ℕ → β) (base : s 0 = 1)
(step : ∀ n, s (n + 1) = s n * f n) (n : ℕ) :
∏ k ∈ Finset.range n, f k = s n := by
induction' n with k hk
· rw [Finset.prod_range_zero, base]
· simp only [hk, Finset.prod_range_succ, step, mul_comm]
#align finset.prod_range_induction Finset.prod_range_induction
#align finset.sum_range_induction Finset.sum_range_induction
/-- A telescoping product along `{0, ..., n - 1}` of a commutative group valued function reduces to
the ratio of the last and first factors. -/
@[to_additive "A telescoping sum along `{0, ..., n - 1}` of an additive commutative group valued
function reduces to the difference of the last and first terms."]
theorem prod_range_div {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
(∏ i ∈ range n, f (i + 1) / f i) = f n / f 0 := by apply prod_range_induction <;> simp
#align finset.prod_range_div Finset.prod_range_div
#align finset.sum_range_sub Finset.sum_range_sub
@[to_additive]
theorem prod_range_div' {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
(∏ i ∈ range n, f i / f (i + 1)) = f 0 / f n := by apply prod_range_induction <;> simp
#align finset.prod_range_div' Finset.prod_range_div'
#align finset.sum_range_sub' Finset.sum_range_sub'
@[to_additive]
theorem eq_prod_range_div {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
f n = f 0 * ∏ i ∈ range n, f (i + 1) / f i := by rw [prod_range_div, mul_div_cancel]
#align finset.eq_prod_range_div Finset.eq_prod_range_div
#align finset.eq_sum_range_sub Finset.eq_sum_range_sub
@[to_additive]
theorem eq_prod_range_div' {M : Type*} [CommGroup M] (f : ℕ → M) (n : ℕ) :
f n = ∏ i ∈ range (n + 1), if i = 0 then f 0 else f i / f (i - 1) := by
conv_lhs => rw [Finset.eq_prod_range_div f]
simp [Finset.prod_range_succ', mul_comm]
#align finset.eq_prod_range_div' Finset.eq_prod_range_div'
#align finset.eq_sum_range_sub' Finset.eq_sum_range_sub'
/-- A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function
reduces to the difference of the last and first terms
when the function we are summing is monotone.
-/
theorem sum_range_tsub [CanonicallyOrderedAddCommMonoid α] [Sub α] [OrderedSub α]
[ContravariantClass α α (· + ·) (· ≤ ·)] {f : ℕ → α} (h : Monotone f) (n : ℕ) :
∑ i ∈ range n, (f (i + 1) - f i) = f n - f 0 := by
apply sum_range_induction
case base => apply tsub_self
case step =>
intro n
have h₁ : f n ≤ f (n + 1) := h (Nat.le_succ _)
have h₂ : f 0 ≤ f n := h (Nat.zero_le _)
rw [tsub_add_eq_add_tsub h₂, add_tsub_cancel_of_le h₁]
#align finset.sum_range_tsub Finset.sum_range_tsub
@[to_additive (attr := simp)]
theorem prod_const (b : β) : ∏ _x ∈ s, b = b ^ s.card :=
(congr_arg _ <| s.val.map_const b).trans <| Multiset.prod_replicate s.card b
#align finset.prod_const Finset.prod_const
#align finset.sum_const Finset.sum_const
@[to_additive sum_eq_card_nsmul]
theorem prod_eq_pow_card {b : β} (hf : ∀ a ∈ s, f a = b) : ∏ a ∈ s, f a = b ^ s.card :=
(prod_congr rfl hf).trans <| prod_const _
#align finset.prod_eq_pow_card Finset.prod_eq_pow_card
#align finset.sum_eq_card_nsmul Finset.sum_eq_card_nsmul
@[to_additive card_nsmul_add_sum]
theorem pow_card_mul_prod {b : β} : b ^ s.card * ∏ a ∈ s, f a = ∏ a ∈ s, b * f a :=
(Finset.prod_const b).symm ▸ prod_mul_distrib.symm
@[to_additive sum_add_card_nsmul]
theorem prod_mul_pow_card {b : β} : (∏ a ∈ s, f a) * b ^ s.card = ∏ a ∈ s, f a * b :=
(Finset.prod_const b).symm ▸ prod_mul_distrib.symm
@[to_additive]
theorem pow_eq_prod_const (b : β) : ∀ n, b ^ n = ∏ _k ∈ range n, b := by simp
#align finset.pow_eq_prod_const Finset.pow_eq_prod_const
#align finset.nsmul_eq_sum_const Finset.nsmul_eq_sum_const
@[to_additive]
theorem prod_pow (s : Finset α) (n : ℕ) (f : α → β) : ∏ x ∈ s, f x ^ n = (∏ x ∈ s, f x) ^ n :=
Multiset.prod_map_pow
#align finset.prod_pow Finset.prod_pow
#align finset.sum_nsmul Finset.sum_nsmul
@[to_additive sum_nsmul_assoc]
lemma prod_pow_eq_pow_sum (s : Finset ι) (f : ι → ℕ) (a : β) :
∏ i ∈ s, a ^ f i = a ^ ∑ i ∈ s, f i :=
cons_induction (by simp) (fun _ _ _ _ ↦ by simp [prod_cons, sum_cons, pow_add, *]) s
#align finset.prod_pow_eq_pow_sum Finset.prod_pow_eq_pow_sum
/-- A product over `Finset.powersetCard` which only depends on the size of the sets is constant. -/
@[to_additive
"A sum over `Finset.powersetCard` which only depends on the size of the sets is constant."]
lemma prod_powersetCard (n : ℕ) (s : Finset α) (f : ℕ → β) :
∏ t ∈ powersetCard n s, f t.card = f n ^ s.card.choose n := by
rw [prod_eq_pow_card, card_powersetCard]; rintro a ha; rw [(mem_powersetCard.1 ha).2]
@[to_additive]
theorem prod_flip {n : ℕ} (f : ℕ → β) :
(∏ r ∈ range (n + 1), f (n - r)) = ∏ k ∈ range (n + 1), f k := by
induction' n with n ih
· rw [prod_range_one, prod_range_one]
· rw [prod_range_succ', prod_range_succ _ (Nat.succ n)]
simp [← ih]
#align finset.prod_flip Finset.prod_flip
#align finset.sum_flip Finset.sum_flip
@[to_additive]
theorem prod_involution {s : Finset α} {f : α → β} :
∀ (g : ∀ a ∈ s, α) (_ : ∀ a ha, f a * f (g a ha) = 1) (_ : ∀ a ha, f a ≠ 1 → g a ha ≠ a)
(g_mem : ∀ a ha, g a ha ∈ s) (_ : ∀ a ha, g (g a ha) (g_mem a ha) = a),
∏ x ∈ s, f x = 1 := by
haveI := Classical.decEq α; haveI := Classical.decEq β
exact
Finset.strongInductionOn s fun s ih g h g_ne g_mem g_inv =>
s.eq_empty_or_nonempty.elim (fun hs => hs.symm ▸ rfl) fun ⟨x, hx⟩ =>
have hmem : ∀ y ∈ (s.erase x).erase (g x hx), y ∈ s := fun y hy =>
mem_of_mem_erase (mem_of_mem_erase hy)
have g_inj : ∀ {x hx y hy}, g x hx = g y hy → x = y := fun {x hx y hy} h => by
rw [← g_inv x hx, ← g_inv y hy]; simp [h]
have ih' : (∏ y ∈ erase (erase s x) (g x hx), f y) = (1 : β) :=
ih ((s.erase x).erase (g x hx))
⟨Subset.trans (erase_subset _ _) (erase_subset _ _), fun h =>
not_mem_erase (g x hx) (s.erase x) (h (g_mem x hx))⟩
(fun y hy => g y (hmem y hy)) (fun y hy => h y (hmem y hy))
(fun y hy => g_ne y (hmem y hy))
(fun y hy =>
mem_erase.2
⟨fun h : g y _ = g x hx => by simp [g_inj h] at hy,
mem_erase.2
⟨fun h : g y _ = x => by
have : y = g x hx := g_inv y (hmem y hy) ▸ by simp [h]
simp [this] at hy, g_mem y (hmem y hy)⟩⟩)
fun y hy => g_inv y (hmem y hy)
if hx1 : f x = 1 then
ih' ▸
Eq.symm
(prod_subset hmem fun y hy hy₁ =>
have : y = x ∨ y = g x hx := by
simpa [hy, -not_and, mem_erase, not_and_or, or_comm] using hy₁
this.elim (fun hy => hy.symm ▸ hx1) fun hy =>
h x hx ▸ hy ▸ hx1.symm ▸ (one_mul _).symm)
else by
rw [← insert_erase hx, prod_insert (not_mem_erase _ _), ←
insert_erase (mem_erase.2 ⟨g_ne x hx hx1, g_mem x hx⟩),
prod_insert (not_mem_erase _ _), ih', mul_one, h x hx]
#align finset.prod_involution Finset.prod_involution
#align finset.sum_involution Finset.sum_involution
/-- The product of the composition of functions `f` and `g`, is the product over `b ∈ s.image g` of
`f b` to the power of the cardinality of the fibre of `b`. See also `Finset.prod_image`. -/
@[to_additive "The sum of the composition of functions `f` and `g`, is the sum over `b ∈ s.image g`
of `f b` times of the cardinality of the fibre of `b`. See also `Finset.sum_image`."]
theorem prod_comp [DecidableEq γ] (f : γ → β) (g : α → γ) :
∏ a ∈ s, f (g a) = ∏ b ∈ s.image g, f b ^ (s.filter fun a => g a = b).card := by
simp_rw [← prod_const, prod_fiberwise_of_maps_to' fun _ ↦ mem_image_of_mem _]
#align finset.prod_comp Finset.prod_comp
#align finset.sum_comp Finset.sum_comp
@[to_additive]
theorem prod_piecewise [DecidableEq α] (s t : Finset α) (f g : α → β) :
(∏ x ∈ s, (t.piecewise f g) x) = (∏ x ∈ s ∩ t, f x) * ∏ x ∈ s \ t, g x := by
erw [prod_ite, filter_mem_eq_inter, ← sdiff_eq_filter]
#align finset.prod_piecewise Finset.prod_piecewise
#align finset.sum_piecewise Finset.sum_piecewise
@[to_additive]
theorem prod_inter_mul_prod_diff [DecidableEq α] (s t : Finset α) (f : α → β) :
(∏ x ∈ s ∩ t, f x) * ∏ x ∈ s \ t, f x = ∏ x ∈ s, f x := by
convert (s.prod_piecewise t f f).symm
simp (config := { unfoldPartialApp := true }) [Finset.piecewise]
#align finset.prod_inter_mul_prod_diff Finset.prod_inter_mul_prod_diff
#align finset.sum_inter_add_sum_diff Finset.sum_inter_add_sum_diff
@[to_additive]
theorem prod_eq_mul_prod_diff_singleton [DecidableEq α] {s : Finset α} {i : α} (h : i ∈ s)
(f : α → β) : ∏ x ∈ s, f x = f i * ∏ x ∈ s \ {i}, f x := by
convert (s.prod_inter_mul_prod_diff {i} f).symm
simp [h]
#align finset.prod_eq_mul_prod_diff_singleton Finset.prod_eq_mul_prod_diff_singleton
#align finset.sum_eq_add_sum_diff_singleton Finset.sum_eq_add_sum_diff_singleton
@[to_additive]
theorem prod_eq_prod_diff_singleton_mul [DecidableEq α] {s : Finset α} {i : α} (h : i ∈ s)
(f : α → β) : ∏ x ∈ s, f x = (∏ x ∈ s \ {i}, f x) * f i := by
rw [prod_eq_mul_prod_diff_singleton h, mul_comm]
#align finset.prod_eq_prod_diff_singleton_mul Finset.prod_eq_prod_diff_singleton_mul
#align finset.sum_eq_sum_diff_singleton_add Finset.sum_eq_sum_diff_singleton_add
@[to_additive]
theorem _root_.Fintype.prod_eq_mul_prod_compl [DecidableEq α] [Fintype α] (a : α) (f : α → β) :
∏ i, f i = f a * ∏ i ∈ {a}ᶜ, f i :=
prod_eq_mul_prod_diff_singleton (mem_univ a) f
#align fintype.prod_eq_mul_prod_compl Fintype.prod_eq_mul_prod_compl
#align fintype.sum_eq_add_sum_compl Fintype.sum_eq_add_sum_compl
@[to_additive]
theorem _root_.Fintype.prod_eq_prod_compl_mul [DecidableEq α] [Fintype α] (a : α) (f : α → β) :
∏ i, f i = (∏ i ∈ {a}ᶜ, f i) * f a :=
prod_eq_prod_diff_singleton_mul (mem_univ a) f
#align fintype.prod_eq_prod_compl_mul Fintype.prod_eq_prod_compl_mul
#align fintype.sum_eq_sum_compl_add Fintype.sum_eq_sum_compl_add
theorem dvd_prod_of_mem (f : α → β) {a : α} {s : Finset α} (ha : a ∈ s) : f a ∣ ∏ i ∈ s, f i := by
classical
rw [Finset.prod_eq_mul_prod_diff_singleton ha]
exact dvd_mul_right _ _
#align finset.dvd_prod_of_mem Finset.dvd_prod_of_mem
/-- A product can be partitioned into a product of products, each equivalent under a setoid. -/
@[to_additive "A sum can be partitioned into a sum of sums, each equivalent under a setoid."]
theorem prod_partition (R : Setoid α) [DecidableRel R.r] :
∏ x ∈ s, f x = ∏ xbar ∈ s.image Quotient.mk'', ∏ y ∈ s.filter (⟦·⟧ = xbar), f y := by
refine (Finset.prod_image' f fun x _hx => ?_).symm
rfl
#align finset.prod_partition Finset.prod_partition
#align finset.sum_partition Finset.sum_partition
/-- If we can partition a product into subsets that cancel out, then the whole product cancels. -/
@[to_additive "If we can partition a sum into subsets that cancel out, then the whole sum cancels."]
theorem prod_cancels_of_partition_cancels (R : Setoid α) [DecidableRel R.r]
(h : ∀ x ∈ s, ∏ a ∈ s.filter fun y => y ≈ x, f a = 1) : ∏ x ∈ s, f x = 1 := by
rw [prod_partition R, ← Finset.prod_eq_one]
intro xbar xbar_in_s
obtain ⟨x, x_in_s, rfl⟩ := mem_image.mp xbar_in_s
simp only [← Quotient.eq] at h
exact h x x_in_s
#align finset.prod_cancels_of_partition_cancels Finset.prod_cancels_of_partition_cancels
#align finset.sum_cancels_of_partition_cancels Finset.sum_cancels_of_partition_cancels
@[to_additive]
theorem prod_update_of_not_mem [DecidableEq α] {s : Finset α} {i : α} (h : i ∉ s) (f : α → β)
(b : β) : ∏ x ∈ s, Function.update f i b x = ∏ x ∈ s, f x := by
apply prod_congr rfl
intros j hj
have : j ≠ i := by
rintro rfl
exact h hj
simp [this]
#align finset.prod_update_of_not_mem Finset.prod_update_of_not_mem
#align finset.sum_update_of_not_mem Finset.sum_update_of_not_mem
@[to_additive]
theorem prod_update_of_mem [DecidableEq α] {s : Finset α} {i : α} (h : i ∈ s) (f : α → β) (b : β) :
∏ x ∈ s, Function.update f i b x = b * ∏ x ∈ s \ singleton i, f x := by
rw [update_eq_piecewise, prod_piecewise]
simp [h]
#align finset.prod_update_of_mem Finset.prod_update_of_mem
#align finset.sum_update_of_mem Finset.sum_update_of_mem
/-- If a product of a `Finset` of size at most 1 has a given value, so
do the terms in that product. -/
@[to_additive eq_of_card_le_one_of_sum_eq "If a sum of a `Finset` of size at most 1 has a given
value, so do the terms in that sum."]
theorem eq_of_card_le_one_of_prod_eq {s : Finset α} (hc : s.card ≤ 1) {f : α → β} {b : β}
(h : ∏ x ∈ s, f x = b) : ∀ x ∈ s, f x = b := by
intro x hx
by_cases hc0 : s.card = 0
· exact False.elim (card_ne_zero_of_mem hx hc0)
· have h1 : s.card = 1 := le_antisymm hc (Nat.one_le_of_lt (Nat.pos_of_ne_zero hc0))
rw [card_eq_one] at h1
cases' h1 with x2 hx2
rw [hx2, mem_singleton] at hx
simp_rw [hx2] at h
rw [hx]
rw [prod_singleton] at h
exact h
#align finset.eq_of_card_le_one_of_prod_eq Finset.eq_of_card_le_one_of_prod_eq
#align finset.eq_of_card_le_one_of_sum_eq Finset.eq_of_card_le_one_of_sum_eq
/-- Taking a product over `s : Finset α` is the same as multiplying the value on a single element
`f a` by the product of `s.erase a`.
See `Multiset.prod_map_erase` for the `Multiset` version. -/
@[to_additive "Taking a sum over `s : Finset α` is the same as adding the value on a single element
`f a` to the sum over `s.erase a`.
See `Multiset.sum_map_erase` for the `Multiset` version."]
theorem mul_prod_erase [DecidableEq α] (s : Finset α) (f : α → β) {a : α} (h : a ∈ s) :
(f a * ∏ x ∈ s.erase a, f x) = ∏ x ∈ s, f x := by
rw [← prod_insert (not_mem_erase a s), insert_erase h]
#align finset.mul_prod_erase Finset.mul_prod_erase
#align finset.add_sum_erase Finset.add_sum_erase
/-- A variant of `Finset.mul_prod_erase` with the multiplication swapped. -/
@[to_additive "A variant of `Finset.add_sum_erase` with the addition swapped."]
theorem prod_erase_mul [DecidableEq α] (s : Finset α) (f : α → β) {a : α} (h : a ∈ s) :
(∏ x ∈ s.erase a, f x) * f a = ∏ x ∈ s, f x := by rw [mul_comm, mul_prod_erase s f h]
#align finset.prod_erase_mul Finset.prod_erase_mul
#align finset.sum_erase_add Finset.sum_erase_add
/-- If a function applied at a point is 1, a product is unchanged by
removing that point, if present, from a `Finset`. -/
@[to_additive "If a function applied at a point is 0, a sum is unchanged by
removing that point, if present, from a `Finset`."]
theorem prod_erase [DecidableEq α] (s : Finset α) {f : α → β} {a : α} (h : f a = 1) :
∏ x ∈ s.erase a, f x = ∏ x ∈ s, f x := by
rw [← sdiff_singleton_eq_erase]
refine prod_subset sdiff_subset fun x hx hnx => ?_
rw [sdiff_singleton_eq_erase] at hnx
rwa [eq_of_mem_of_not_mem_erase hx hnx]
#align finset.prod_erase Finset.prod_erase
#align finset.sum_erase Finset.sum_erase
/-- See also `Finset.prod_boole`. -/
@[to_additive "See also `Finset.sum_boole`."]
theorem prod_ite_one (s : Finset α) (p : α → Prop) [DecidablePred p]
(h : ∀ i ∈ s, ∀ j ∈ s, p i → p j → i = j) (a : β) :
∏ i ∈ s, ite (p i) a 1 = ite (∃ i ∈ s, p i) a 1 := by
split_ifs with h
· obtain ⟨i, hi, hpi⟩ := h
rw [prod_eq_single_of_mem _ hi, if_pos hpi]
exact fun j hj hji ↦ if_neg fun hpj ↦ hji <| h _ hj _ hi hpj hpi
· push_neg at h
rw [prod_eq_one]
exact fun i hi => if_neg (h i hi)
#align finset.prod_ite_one Finset.prod_ite_one
#align finset.sum_ite_zero Finset.sum_ite_zero
@[to_additive]
theorem prod_erase_lt_of_one_lt {γ : Type*} [DecidableEq α] [OrderedCommMonoid γ]
[CovariantClass γ γ (· * ·) (· < ·)] {s : Finset α} {d : α} (hd : d ∈ s) {f : α → γ}
(hdf : 1 < f d) : ∏ m ∈ s.erase d, f m < ∏ m ∈ s, f m := by
conv in ∏ m ∈ s, f m => rw [← Finset.insert_erase hd]
rw [Finset.prod_insert (Finset.not_mem_erase d s)]
exact lt_mul_of_one_lt_left' _ hdf
#align finset.prod_erase_lt_of_one_lt Finset.prod_erase_lt_of_one_lt
#align finset.sum_erase_lt_of_pos Finset.sum_erase_lt_of_pos
/-- If a product is 1 and the function is 1 except possibly at one
point, it is 1 everywhere on the `Finset`. -/
@[to_additive "If a sum is 0 and the function is 0 except possibly at one
point, it is 0 everywhere on the `Finset`."]
theorem eq_one_of_prod_eq_one {s : Finset α} {f : α → β} {a : α} (hp : ∏ x ∈ s, f x = 1)
(h1 : ∀ x ∈ s, x ≠ a → f x = 1) : ∀ x ∈ s, f x = 1 := by
intro x hx
classical
by_cases h : x = a
· rw [h]
rw [h] at hx
rw [← prod_subset (singleton_subset_iff.2 hx) fun t ht ha => h1 t ht (not_mem_singleton.1 ha),
prod_singleton] at hp
exact hp
· exact h1 x hx h
#align finset.eq_one_of_prod_eq_one Finset.eq_one_of_prod_eq_one
#align finset.eq_zero_of_sum_eq_zero Finset.eq_zero_of_sum_eq_zero
@[to_additive sum_boole_nsmul]
theorem prod_pow_boole [DecidableEq α] (s : Finset α) (f : α → β) (a : α) :
(∏ x ∈ s, f x ^ ite (a = x) 1 0) = ite (a ∈ s) (f a) 1 := by simp
#align finset.prod_pow_boole Finset.prod_pow_boole
theorem prod_dvd_prod_of_dvd {S : Finset α} (g1 g2 : α → β) (h : ∀ a ∈ S, g1 a ∣ g2 a) :
S.prod g1 ∣ S.prod g2 := by
classical
induction' S using Finset.induction_on' with a T _haS _hTS haT IH
· simp
· rw [Finset.prod_insert haT, prod_insert haT]
exact mul_dvd_mul (h a <| T.mem_insert_self a) <| IH fun b hb ↦ h b <| mem_insert_of_mem hb
#align finset.prod_dvd_prod_of_dvd Finset.prod_dvd_prod_of_dvd
theorem prod_dvd_prod_of_subset {ι M : Type*} [CommMonoid M] (s t : Finset ι) (f : ι → M)
(h : s ⊆ t) : (∏ i ∈ s, f i) ∣ ∏ i ∈ t, f i :=
Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| by simpa
#align finset.prod_dvd_prod_of_subset Finset.prod_dvd_prod_of_subset
end CommMonoid
section CancelCommMonoid
variable [DecidableEq ι] [CancelCommMonoid α] {s t : Finset ι} {f : ι → α}
@[to_additive]
lemma prod_sdiff_eq_prod_sdiff_iff :
∏ i ∈ s \ t, f i = ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i = ∏ i ∈ t, f i :=
eq_comm.trans $ eq_iff_eq_of_mul_eq_mul $ by
rw [← prod_union disjoint_sdiff_self_left, ← prod_union disjoint_sdiff_self_left,
sdiff_union_self_eq_union, sdiff_union_self_eq_union, union_comm]
@[to_additive]
lemma prod_sdiff_ne_prod_sdiff_iff :
∏ i ∈ s \ t, f i ≠ ∏ i ∈ t \ s, f i ↔ ∏ i ∈ s, f i ≠ ∏ i ∈ t, f i :=
prod_sdiff_eq_prod_sdiff_iff.not
end CancelCommMonoid
theorem card_eq_sum_ones (s : Finset α) : s.card = ∑ x ∈ s, 1 := by simp
#align finset.card_eq_sum_ones Finset.card_eq_sum_ones
theorem sum_const_nat {m : ℕ} {f : α → ℕ} (h₁ : ∀ x ∈ s, f x = m) :
∑ x ∈ s, f x = card s * m := by
rw [← Nat.nsmul_eq_mul, ← sum_const]
apply sum_congr rfl h₁
#align finset.sum_const_nat Finset.sum_const_nat
lemma sum_card_fiberwise_eq_card_filter {κ : Type*} [DecidableEq κ] (s : Finset ι) (t : Finset κ)
(g : ι → κ) : ∑ j ∈ t, (s.filter fun i ↦ g i = j).card = (s.filter fun i ↦ g i ∈ t).card := by
simpa only [card_eq_sum_ones] using sum_fiberwise_eq_sum_filter _ _ _ _
lemma card_filter (p) [DecidablePred p] (s : Finset α) :
(filter p s).card = ∑ a ∈ s, ite (p a) 1 0 := by simp [sum_ite]
#align finset.card_filter Finset.card_filter
section Opposite
open MulOpposite
/-- Moving to the opposite additive commutative monoid commutes with summing. -/
@[simp]
theorem op_sum [AddCommMonoid β] {s : Finset α} (f : α → β) :
op (∑ x ∈ s, f x) = ∑ x ∈ s, op (f x) :=
map_sum (opAddEquiv : β ≃+ βᵐᵒᵖ) _ _
#align finset.op_sum Finset.op_sum
@[simp]
theorem unop_sum [AddCommMonoid β] {s : Finset α} (f : α → βᵐᵒᵖ) :
unop (∑ x ∈ s, f x) = ∑ x ∈ s, unop (f x) :=
map_sum (opAddEquiv : β ≃+ βᵐᵒᵖ).symm _ _
#align finset.unop_sum Finset.unop_sum
end Opposite
section DivisionCommMonoid
variable [DivisionCommMonoid β]
@[to_additive (attr := simp)]
theorem prod_inv_distrib : (∏ x ∈ s, (f x)⁻¹) = (∏ x ∈ s, f x)⁻¹ :=
Multiset.prod_map_inv
#align finset.prod_inv_distrib Finset.prod_inv_distrib
#align finset.sum_neg_distrib Finset.sum_neg_distrib
@[to_additive (attr := simp)]
theorem prod_div_distrib : ∏ x ∈ s, f x / g x = (∏ x ∈ s, f x) / ∏ x ∈ s, g x :=
Multiset.prod_map_div
#align finset.prod_div_distrib Finset.prod_div_distrib
#align finset.sum_sub_distrib Finset.sum_sub_distrib
@[to_additive]
theorem prod_zpow (f : α → β) (s : Finset α) (n : ℤ) : ∏ a ∈ s, f a ^ n = (∏ a ∈ s, f a) ^ n :=
Multiset.prod_map_zpow
#align finset.prod_zpow Finset.prod_zpow
#align finset.sum_zsmul Finset.sum_zsmul
end DivisionCommMonoid
section CommGroup
variable [CommGroup β] [DecidableEq α]
@[to_additive (attr := simp)]
theorem prod_sdiff_eq_div (h : s₁ ⊆ s₂) :
∏ x ∈ s₂ \ s₁, f x = (∏ x ∈ s₂, f x) / ∏ x ∈ s₁, f x := by
rw [eq_div_iff_mul_eq', prod_sdiff h]
#align finset.prod_sdiff_eq_div Finset.prod_sdiff_eq_div
#align finset.sum_sdiff_eq_sub Finset.sum_sdiff_eq_sub
@[to_additive]
theorem prod_sdiff_div_prod_sdiff :
(∏ x ∈ s₂ \ s₁, f x) / ∏ x ∈ s₁ \ s₂, f x = (∏ x ∈ s₂, f x) / ∏ x ∈ s₁, f x := by
simp [← Finset.prod_sdiff (@inf_le_left _ _ s₁ s₂), ← Finset.prod_sdiff (@inf_le_right _ _ s₁ s₂)]
#align finset.prod_sdiff_div_prod_sdiff Finset.prod_sdiff_div_prod_sdiff
#align finset.sum_sdiff_sub_sum_sdiff Finset.sum_sdiff_sub_sum_sdiff
@[to_additive (attr := simp)]
theorem prod_erase_eq_div {a : α} (h : a ∈ s) :
∏ x ∈ s.erase a, f x = (∏ x ∈ s, f x) / f a := by
rw [eq_div_iff_mul_eq', prod_erase_mul _ _ h]
#align finset.prod_erase_eq_div Finset.prod_erase_eq_div
#align finset.sum_erase_eq_sub Finset.sum_erase_eq_sub
end CommGroup
@[simp]
theorem card_sigma {σ : α → Type*} (s : Finset α) (t : ∀ a, Finset (σ a)) :
card (s.sigma t) = ∑ a ∈ s, card (t a) :=
Multiset.card_sigma _ _
#align finset.card_sigma Finset.card_sigma
@[simp]
theorem card_disjiUnion (s : Finset α) (t : α → Finset β) (h) :
(s.disjiUnion t h).card = s.sum fun i => (t i).card :=
Multiset.card_bind _ _
#align finset.card_disj_Union Finset.card_disjiUnion
theorem card_biUnion [DecidableEq β] {s : Finset α} {t : α → Finset β}
(h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → Disjoint (t x) (t y)) :
(s.biUnion t).card = ∑ u ∈ s, card (t u) :=
calc
(s.biUnion t).card = ∑ i ∈ s.biUnion t, 1 := card_eq_sum_ones _
_ = ∑ a ∈ s, ∑ _i ∈ t a, 1 := Finset.sum_biUnion h
_ = ∑ u ∈ s, card (t u) := by simp_rw [card_eq_sum_ones]
#align finset.card_bUnion Finset.card_biUnion
theorem card_biUnion_le [DecidableEq β] {s : Finset α} {t : α → Finset β} :
(s.biUnion t).card ≤ ∑ a ∈ s, (t a).card :=
haveI := Classical.decEq α
Finset.induction_on s (by simp) fun a s has ih =>
calc
((insert a s).biUnion t).card ≤ (t a).card + (s.biUnion t).card := by
{ rw [biUnion_insert]; exact Finset.card_union_le _ _ }
_ ≤ ∑ a ∈ insert a s, card (t a) := by rw [sum_insert has]; exact Nat.add_le_add_left ih _
#align finset.card_bUnion_le Finset.card_biUnion_le
theorem card_eq_sum_card_fiberwise [DecidableEq β] {f : α → β} {s : Finset α} {t : Finset β}
(H : ∀ x ∈ s, f x ∈ t) : s.card = ∑ a ∈ t, (s.filter fun x => f x = a).card := by
simp only [card_eq_sum_ones, sum_fiberwise_of_maps_to H]
#align finset.card_eq_sum_card_fiberwise Finset.card_eq_sum_card_fiberwise
theorem card_eq_sum_card_image [DecidableEq β] (f : α → β) (s : Finset α) :
s.card = ∑ a ∈ s.image f, (s.filter fun x => f x = a).card :=
card_eq_sum_card_fiberwise fun _ => mem_image_of_mem _
#align finset.card_eq_sum_card_image Finset.card_eq_sum_card_image
theorem mem_sum {f : α → Multiset β} (s : Finset α) (b : β) :
(b ∈ ∑ x ∈ s, f x) ↔ ∃ a ∈ s, b ∈ f a := by
classical
refine s.induction_on (by simp) ?_
intro a t hi ih
simp [sum_insert hi, ih, or_and_right, exists_or]
#align finset.mem_sum Finset.mem_sum
@[to_additive]
theorem prod_unique_nonempty {α β : Type*} [CommMonoid β] [Unique α] (s : Finset α) (f : α → β)
(h : s.Nonempty) : ∏ x ∈ s, f x = f default := by
rw [h.eq_singleton_default, Finset.prod_singleton]
#align finset.prod_unique_nonempty Finset.prod_unique_nonempty
#align finset.sum_unique_nonempty Finset.sum_unique_nonempty
theorem sum_nat_mod (s : Finset α) (n : ℕ) (f : α → ℕ) :
(∑ i ∈ s, f i) % n = (∑ i ∈ s, f i % n) % n :=
(Multiset.sum_nat_mod _ _).trans <| by rw [Finset.sum, Multiset.map_map]; rfl
#align finset.sum_nat_mod Finset.sum_nat_mod
theorem prod_nat_mod (s : Finset α) (n : ℕ) (f : α → ℕ) :
(∏ i ∈ s, f i) % n = (∏ i ∈ s, f i % n) % n :=
(Multiset.prod_nat_mod _ _).trans <| by rw [Finset.prod, Multiset.map_map]; rfl
#align finset.prod_nat_mod Finset.prod_nat_mod
theorem sum_int_mod (s : Finset α) (n : ℤ) (f : α → ℤ) :
(∑ i ∈ s, f i) % n = (∑ i ∈ s, f i % n) % n :=
(Multiset.sum_int_mod _ _).trans <| by rw [Finset.sum, Multiset.map_map]; rfl
#align finset.sum_int_mod Finset.sum_int_mod
theorem prod_int_mod (s : Finset α) (n : ℤ) (f : α → ℤ) :
(∏ i ∈ s, f i) % n = (∏ i ∈ s, f i % n) % n :=
(Multiset.prod_int_mod _ _).trans <| by rw [Finset.prod, Multiset.map_map]; rfl
#align finset.prod_int_mod Finset.prod_int_mod
end Finset
namespace Fintype
variable {ι κ α : Type*} [Fintype ι] [Fintype κ]
open Finset
section CommMonoid
variable [CommMonoid α]
/-- `Fintype.prod_bijective` is a variant of `Finset.prod_bij` that accepts `Function.Bijective`.
See `Function.Bijective.prod_comp` for a version without `h`. -/
@[to_additive "`Fintype.sum_bijective` is a variant of `Finset.sum_bij` that accepts
`Function.Bijective`.
See `Function.Bijective.sum_comp` for a version without `h`. "]
lemma prod_bijective (e : ι → κ) (he : e.Bijective) (f : ι → α) (g : κ → α)
(h : ∀ x, f x = g (e x)) : ∏ x, f x = ∏ x, g x :=
prod_equiv (.ofBijective e he) (by simp) (by simp [h])
#align fintype.prod_bijective Fintype.prod_bijective
#align fintype.sum_bijective Fintype.sum_bijective
@[to_additive] alias _root_.Function.Bijective.finset_prod := prod_bijective
/-- `Fintype.prod_equiv` is a specialization of `Finset.prod_bij` that
automatically fills in most arguments.
See `Equiv.prod_comp` for a version without `h`.
-/
@[to_additive "`Fintype.sum_equiv` is a specialization of `Finset.sum_bij` that
automatically fills in most arguments.
See `Equiv.sum_comp` for a version without `h`."]
lemma prod_equiv (e : ι ≃ κ) (f : ι → α) (g : κ → α) (h : ∀ x, f x = g (e x)) :
∏ x, f x = ∏ x, g x := prod_bijective _ e.bijective _ _ h
#align fintype.prod_equiv Fintype.prod_equiv
#align fintype.sum_equiv Fintype.sum_equiv
@[to_additive]
lemma _root_.Function.Bijective.prod_comp {e : ι → κ} (he : e.Bijective) (g : κ → α) :
∏ i, g (e i) = ∏ i, g i := prod_bijective _ he _ _ fun _ ↦ rfl
#align function.bijective.prod_comp Function.Bijective.prod_comp
#align function.bijective.sum_comp Function.Bijective.sum_comp
@[to_additive]
lemma _root_.Equiv.prod_comp (e : ι ≃ κ) (g : κ → α) : ∏ i, g (e i) = ∏ i, g i :=
prod_equiv e _ _ fun _ ↦ rfl
#align equiv.prod_comp Equiv.prod_comp
#align equiv.sum_comp Equiv.sum_comp
@[to_additive]
lemma prod_of_injective (e : ι → κ) (he : Injective e) (f : ι → α) (g : κ → α)
(h' : ∀ i ∉ Set.range e, g i = 1) (h : ∀ i, f i = g (e i)) : ∏ i, f i = ∏ j, g j :=
prod_of_injOn e he.injOn (by simp) (by simpa using h') (fun i _ ↦ h i)
@[to_additive]
lemma prod_fiberwise [DecidableEq κ] (g : ι → κ) (f : ι → α) :
∏ j, ∏ i : {i // g i = j}, f i = ∏ i, f i := by
rw [← Finset.prod_fiberwise _ g f]
congr with j
exact (prod_subtype _ (by simp) _).symm
#align fintype.prod_fiberwise Fintype.prod_fiberwise
#align fintype.sum_fiberwise Fintype.sum_fiberwise
@[to_additive]
lemma prod_fiberwise' [DecidableEq κ] (g : ι → κ) (f : κ → α) :
∏ j, ∏ _i : {i // g i = j}, f j = ∏ i, f (g i) := by
rw [← Finset.prod_fiberwise' _ g f]
congr with j
exact (prod_subtype _ (by simp) fun _ ↦ _).symm
@[to_additive]
theorem prod_unique {α β : Type*} [CommMonoid β] [Unique α] [Fintype α] (f : α → β) :
∏ x : α, f x = f default := by rw [univ_unique, prod_singleton]
#align fintype.prod_unique Fintype.prod_unique
#align fintype.sum_unique Fintype.sum_unique
@[to_additive]
theorem prod_empty {α β : Type*} [CommMonoid β] [IsEmpty α] [Fintype α] (f : α → β) :
∏ x : α, f x = 1 :=
Finset.prod_of_empty _
#align fintype.prod_empty Fintype.prod_empty
#align fintype.sum_empty Fintype.sum_empty
@[to_additive]
theorem prod_subsingleton {α β : Type*} [CommMonoid β] [Subsingleton α] [Fintype α] (f : α → β)
(a : α) : ∏ x : α, f x = f a := by
haveI : Unique α := uniqueOfSubsingleton a
rw [prod_unique f, Subsingleton.elim default a]
#align fintype.prod_subsingleton Fintype.prod_subsingleton
#align fintype.sum_subsingleton Fintype.sum_subsingleton
@[to_additive]
theorem prod_subtype_mul_prod_subtype {α β : Type*} [Fintype α] [CommMonoid β] (p : α → Prop)
(f : α → β) [DecidablePred p] :
(∏ i : { x // p x }, f i) * ∏ i : { x // ¬p x }, f i = ∏ i, f i := by
classical
let s := { x | p x }.toFinset
rw [← Finset.prod_subtype s, ← Finset.prod_subtype sᶜ]
· exact Finset.prod_mul_prod_compl _ _
· simp [s]
· simp [s]
#align fintype.prod_subtype_mul_prod_subtype Fintype.prod_subtype_mul_prod_subtype
#align fintype.sum_subtype_add_sum_subtype Fintype.sum_subtype_add_sum_subtype
@[to_additive] lemma prod_subset {s : Finset ι} {f : ι → α} (h : ∀ i, f i ≠ 1 → i ∈ s) :
∏ i ∈ s, f i = ∏ i, f i :=
Finset.prod_subset s.subset_univ $ by simpa [not_imp_comm (a := _ ∈ s)]
@[to_additive]
lemma prod_ite_eq_ite_exists (p : ι → Prop) [DecidablePred p] (h : ∀ i j, p i → p j → i = j)
(a : α) : ∏ i, ite (p i) a 1 = ite (∃ i, p i) a 1 := by
simp [prod_ite_one univ p (by simpa using h)]
variable [DecidableEq ι]
/-- See also `Finset.prod_dite_eq`. -/
@[to_additive "See also `Finset.sum_dite_eq`."] lemma prod_dite_eq (i : ι) (f : ∀ j, i = j → α) :
∏ j, (if h : i = j then f j h else 1) = f i rfl := by
rw [Finset.prod_dite_eq, if_pos (mem_univ _)]
/-- See also `Finset.prod_dite_eq'`. -/
@[to_additive "See also `Finset.sum_dite_eq'`."] lemma prod_dite_eq' (i : ι) (f : ∀ j, j = i → α) :
∏ j, (if h : j = i then f j h else 1) = f i rfl := by
rw [Finset.prod_dite_eq', if_pos (mem_univ _)]
/-- See also `Finset.prod_ite_eq`. -/
@[to_additive "See also `Finset.sum_ite_eq`."]
lemma prod_ite_eq (i : ι) (f : ι → α) : ∏ j, (if i = j then f j else 1) = f i := by
rw [Finset.prod_ite_eq, if_pos (mem_univ _)]
/-- See also `Finset.prod_ite_eq'`. -/
@[to_additive "See also `Finset.sum_ite_eq'`."]
lemma prod_ite_eq' (i : ι) (f : ι → α) : ∏ j, (if j = i then f j else 1) = f i := by
rw [Finset.prod_ite_eq', if_pos (mem_univ _)]
/-- See also `Finset.prod_pi_mulSingle`. -/
@[to_additive "See also `Finset.sum_pi_single`."]
lemma prod_pi_mulSingle {α : ι → Type*} [∀ i, CommMonoid (α i)] (i : ι) (f : ∀ i, α i) :
∏ j, Pi.mulSingle j (f j) i = f i := prod_dite_eq _ _
/-- See also `Finset.prod_pi_mulSingle'`. -/
@[to_additive "See also `Finset.sum_pi_single'`."]
lemma prod_pi_mulSingle' (i : ι) (a : α) : ∏ j, Pi.mulSingle i a j = a := prod_dite_eq' _ _
end CommMonoid
end Fintype
namespace Finset
variable [CommMonoid α]
@[to_additive (attr := simp)]
lemma prod_attach_univ [Fintype ι] (f : {i // i ∈ @univ ι _} → α) :
∏ i ∈ univ.attach, f i = ∏ i, f ⟨i, mem_univ _⟩ :=
Fintype.prod_equiv (Equiv.subtypeUnivEquiv mem_univ) _ _ $ by simp
#align finset.prod_attach_univ Finset.prod_attach_univ
#align finset.sum_attach_univ Finset.sum_attach_univ
@[to_additive]
theorem prod_erase_attach [DecidableEq ι] {s : Finset ι} (f : ι → α) (i : ↑s) :
∏ j ∈ s.attach.erase i, f ↑j = ∏ j ∈ s.erase ↑i, f j := by
rw [← Function.Embedding.coe_subtype, ← prod_map]
simp [attach_map_val]
end Finset
namespace List
@[to_additive]
theorem prod_toFinset {M : Type*} [DecidableEq α] [CommMonoid M] (f : α → M) :
∀ {l : List α} (_hl : l.Nodup), l.toFinset.prod f = (l.map f).prod
| [], _ => by simp
| a :: l, hl => by
let ⟨not_mem, hl⟩ := List.nodup_cons.mp hl
simp [Finset.prod_insert (mt List.mem_toFinset.mp not_mem), prod_toFinset _ hl]
#align list.prod_to_finset List.prod_toFinset
#align list.sum_to_finset List.sum_toFinset
@[simp]
theorem sum_toFinset_count_eq_length [DecidableEq α] (l : List α) :
∑ a in l.toFinset, l.count a = l.length := by
simpa using (Finset.sum_list_map_count l fun _ => (1 : ℕ)).symm
end List
namespace Multiset
theorem disjoint_list_sum_left {a : Multiset α} {l : List (Multiset α)} :
Multiset.Disjoint l.sum a ↔ ∀ b ∈ l, Multiset.Disjoint b a := by
induction' l with b bs ih
· simp only [zero_disjoint, List.not_mem_nil, IsEmpty.forall_iff, forall_const, List.sum_nil]
· simp_rw [List.sum_cons, disjoint_add_left, List.mem_cons, forall_eq_or_imp]
simp [and_congr_left_iff, iff_self_iff, ih]
#align multiset.disjoint_list_sum_left Multiset.disjoint_list_sum_left
theorem disjoint_list_sum_right {a : Multiset α} {l : List (Multiset α)} :
Multiset.Disjoint a l.sum ↔ ∀ b ∈ l, Multiset.Disjoint a b := by
simpa only [@disjoint_comm _ a] using disjoint_list_sum_left
#align multiset.disjoint_list_sum_right Multiset.disjoint_list_sum_right
theorem disjoint_sum_left {a : Multiset α} {i : Multiset (Multiset α)} :
Multiset.Disjoint i.sum a ↔ ∀ b ∈ i, Multiset.Disjoint b a :=
Quotient.inductionOn i fun l => by
rw [quot_mk_to_coe, Multiset.sum_coe]
exact disjoint_list_sum_left
#align multiset.disjoint_sum_left Multiset.disjoint_sum_left
theorem disjoint_sum_right {a : Multiset α} {i : Multiset (Multiset α)} :
Multiset.Disjoint a i.sum ↔ ∀ b ∈ i, Multiset.Disjoint a b := by
simpa only [@disjoint_comm _ a] using disjoint_sum_left
#align multiset.disjoint_sum_right Multiset.disjoint_sum_right
theorem disjoint_finset_sum_left {β : Type*} {i : Finset β} {f : β → Multiset α} {a : Multiset α} :
Multiset.Disjoint (i.sum f) a ↔ ∀ b ∈ i, Multiset.Disjoint (f b) a := by
convert @disjoint_sum_left _ a (map f i.val)
simp [and_congr_left_iff, iff_self_iff]
#align multiset.disjoint_finset_sum_left Multiset.disjoint_finset_sum_left
theorem disjoint_finset_sum_right {β : Type*} {i : Finset β} {f : β → Multiset α}
{a : Multiset α} : Multiset.Disjoint a (i.sum f) ↔ ∀ b ∈ i, Multiset.Disjoint a (f b) := by
simpa only [disjoint_comm] using disjoint_finset_sum_left
#align multiset.disjoint_finset_sum_right Multiset.disjoint_finset_sum_right
variable [DecidableEq α]
@[simp]
theorem toFinset_sum_count_eq (s : Multiset α) : ∑ a in s.toFinset, s.count a = card s := by
simpa using (Finset.sum_multiset_map_count s (fun _ => (1 : ℕ))).symm
#align multiset.to_finset_sum_count_eq Multiset.toFinset_sum_count_eq
@[simp]
theorem sum_count_eq [Fintype α] (s : Multiset α) : ∑ a, s.count a = Multiset.card s := by
rw [← toFinset_sum_count_eq, ← Finset.sum_filter_ne_zero]
congr
ext
simp
theorem count_sum' {s : Finset β} {a : α} {f : β → Multiset α} :
count a (∑ x ∈ s, f x) = ∑ x ∈ s, count a (f x) := by
dsimp only [Finset.sum]
rw [count_sum]
#align multiset.count_sum' Multiset.count_sum'
@[simp]
theorem toFinset_sum_count_nsmul_eq (s : Multiset α) :
∑ a ∈ s.toFinset, s.count a • {a} = s := by
rw [← Finset.sum_multiset_map_count, Multiset.sum_map_singleton]
#align multiset.to_finset_sum_count_nsmul_eq Multiset.toFinset_sum_count_nsmul_eq
| Mathlib/Algebra/BigOperators/Group/Finset.lean | 2,481 | 2,490 | theorem exists_smul_of_dvd_count (s : Multiset α) {k : ℕ}
(h : ∀ a : α, a ∈ s → k ∣ Multiset.count a s) : ∃ u : Multiset α, s = k • u := by |
use ∑ a ∈ s.toFinset, (s.count a / k) • {a}
have h₂ :
(∑ x ∈ s.toFinset, k • (count x s / k) • ({x} : Multiset α)) =
∑ x ∈ s.toFinset, count x s • {x} := by
apply Finset.sum_congr rfl
intro x hx
rw [← mul_nsmul', Nat.mul_div_cancel' (h x (mem_toFinset.mp hx))]
rw [← Finset.sum_nsmul, h₂, toFinset_sum_count_nsmul_eq]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell
-/
import Mathlib.Data.Nat.Factorial.Basic
import Mathlib.Order.Monotone.Basic
#align_import data.nat.choose.basic from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4"
/-!
# Binomial coefficients
This file defines binomial coefficients and proves simple lemmas (i.e. those not
requiring more imports).
## Main definition and results
* `Nat.choose`: binomial coefficients, defined inductively
* `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)`
* `Nat.choose_symm`: symmetry of binomial coefficients
* `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k`
* `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2`
* `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending
factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements
for the ascending factorial.
* `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations.
The fact that this is indeed the correct counting function for multisets is proved in
`Sym.card_sym_eq_multichoose` in `Data.Sym.Card`.
* `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`.
This is central to the "stars and bars" technique in informal mathematics, where we switch between
counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements
("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail.
## Tags
binomial coefficient, combination, multicombination, stars and bars
-/
open Nat
namespace Nat
/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial
coefficients. -/
def choose : ℕ → ℕ → ℕ
| _, 0 => 1
| 0, _ + 1 => 0
| n + 1, k + 1 => choose n k + choose n (k + 1)
#align nat.choose Nat.choose
@[simp]
theorem choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n <;> rfl
#align nat.choose_zero_right Nat.choose_zero_right
@[simp]
theorem choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 :=
rfl
#align nat.choose_zero_succ Nat.choose_zero_succ
theorem choose_succ_succ (n k : ℕ) : choose (succ n) (succ k) = choose n k + choose n (succ k) :=
rfl
#align nat.choose_succ_succ Nat.choose_succ_succ
theorem choose_succ_succ' (n k : ℕ) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) :=
rfl
theorem choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0
| _, 0, hk => absurd hk (Nat.not_lt_zero _)
| 0, k + 1, _ => choose_zero_succ _
| n + 1, k + 1, hk => by
have hnk : n < k := lt_of_succ_lt_succ hk
have hnk1 : n < k + 1 := lt_of_succ_lt hk
rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1]
#align nat.choose_eq_zero_of_lt Nat.choose_eq_zero_of_lt
@[simp]
theorem choose_self (n : ℕ) : choose n n = 1 := by
induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)]
#align nat.choose_self Nat.choose_self
@[simp]
theorem choose_succ_self (n : ℕ) : choose n (succ n) = 0 :=
choose_eq_zero_of_lt (lt_succ_self _)
#align nat.choose_succ_self Nat.choose_succ_self
@[simp]
lemma choose_one_right (n : ℕ) : choose n 1 = n := by induction n <;> simp [*, choose, Nat.add_comm]
#align nat.choose_one_right Nat.choose_one_right
-- The `n+1`-st triangle number is `n` more than the `n`-th triangle number
theorem triangle_succ (n : ℕ) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by
rw [← add_mul_div_left, Nat.mul_comm 2 n, ← Nat.mul_add, Nat.add_sub_cancel, Nat.mul_comm]
cases n <;> rfl; apply zero_lt_succ
#align nat.triangle_succ Nat.triangle_succ
/-- `choose n 2` is the `n`-th triangle number. -/
theorem choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 := by
induction' n with n ih
· simp
· rw [triangle_succ n, choose, ih]
simp [Nat.add_comm]
#align nat.choose_two_right Nat.choose_two_right
theorem choose_pos : ∀ {n k}, k ≤ n → 0 < choose n k
| 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk]; decide
| n + 1, 0, _ => by simp
| n + 1, k + 1, hk => Nat.add_pos_left (choose_pos (le_of_succ_le_succ hk)) _
#align nat.choose_pos Nat.choose_pos
theorem choose_eq_zero_iff {n k : ℕ} : n.choose k = 0 ↔ n < k :=
⟨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt⟩
#align nat.choose_eq_zero_iff Nat.choose_eq_zero_iff
theorem succ_mul_choose_eq : ∀ n k, succ n * choose n k = choose (succ n) (succ k) * succ k
| 0, 0 => by decide
| 0, k + 1 => by simp [choose]
| n + 1, 0 => by simp [choose, mul_succ, succ_eq_add_one, Nat.add_comm]
| n + 1, k + 1 => by
rw [choose_succ_succ (succ n) (succ k), Nat.add_mul, ← succ_mul_choose_eq n, mul_succ, ←
succ_mul_choose_eq n, Nat.add_right_comm, ← Nat.mul_add, ← choose_succ_succ, ← succ_mul]
#align nat.succ_mul_choose_eq Nat.succ_mul_choose_eq
theorem choose_mul_factorial_mul_factorial : ∀ {n k}, k ≤ n → choose n k * k ! * (n - k)! = n !
| 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk]
| n + 1, 0, _ => by simp
| n + 1, succ k, hk => by
rcases lt_or_eq_of_le hk with hk₁ | hk₁
· have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by
rw [← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have h₁ : (n - k)! = (n - k) * (n - k.succ)! := by
rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ]
have h₂ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by
rw [← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have h₃ : k * n ! ≤ n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk)
rw [choose_succ_succ, Nat.add_mul, Nat.add_mul, succ_sub_succ, h, h₁, h₂, Nat.add_mul,
Nat.mul_sub_right_distrib, factorial_succ, ← Nat.add_sub_assoc h₃, Nat.add_assoc,
← Nat.add_mul, Nat.add_sub_cancel_left, Nat.add_comm]
· rw [hk₁]; simp [hk₁, Nat.mul_comm, choose, Nat.sub_self]
#align nat.choose_mul_factorial_mul_factorial Nat.choose_mul_factorial_mul_factorial
theorem choose_mul {n k s : ℕ} (hkn : k ≤ n) (hsk : s ≤ k) :
n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) :=
have h : 0 < (n - k)! * (k - s)! * s ! := by apply_rules [factorial_pos, Nat.mul_pos]
Nat.mul_right_cancel h <|
calc
n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) =
n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! := by
rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc _ s !, Nat.mul_assoc,
Nat.mul_comm (n - k)!, Nat.mul_comm s !]
_ = n ! := by
rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn]
_ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by
rw [choose_mul_factorial_mul_factorial (Nat.sub_le_sub_right hkn _),
choose_mul_factorial_mul_factorial (hsk.trans hkn)]
_ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by
rw [Nat.sub_sub_sub_cancel_right hsk, Nat.mul_assoc, Nat.mul_left_comm s !, Nat.mul_assoc,
Nat.mul_comm (k - s)!, Nat.mul_comm s !, Nat.mul_right_comm, ← Nat.mul_assoc]
#align nat.choose_mul Nat.choose_mul
theorem choose_eq_factorial_div_factorial {n k : ℕ} (hk : k ≤ n) :
choose n k = n ! / (k ! * (n - k)!) := by
rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]
exact (mul_div_left _ (Nat.mul_pos (factorial_pos _) (factorial_pos _))).symm
#align nat.choose_eq_factorial_div_factorial Nat.choose_eq_factorial_div_factorial
theorem add_choose (i j : ℕ) : (i + j).choose j = (i + j)! / (i ! * j !) := by
rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), Nat.add_sub_cancel_right,
Nat.mul_comm]
#align nat.add_choose Nat.add_choose
theorem add_choose_mul_factorial_mul_factorial (i j : ℕ) :
(i + j).choose j * i ! * j ! = (i + j)! := by
rw [← choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), Nat.add_sub_cancel_right,
Nat.mul_right_comm]
#align nat.add_choose_mul_factorial_mul_factorial Nat.add_choose_mul_factorial_mul_factorial
theorem factorial_mul_factorial_dvd_factorial {n k : ℕ} (hk : k ≤ n) : k ! * (n - k)! ∣ n ! := by
rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]; exact Nat.dvd_mul_left _ _
#align nat.factorial_mul_factorial_dvd_factorial Nat.factorial_mul_factorial_dvd_factorial
theorem factorial_mul_factorial_dvd_factorial_add (i j : ℕ) : i ! * j ! ∣ (i + j)! := by
suffices i ! * (i + j - i) ! ∣ (i + j)! by
rwa [Nat.add_sub_cancel_left i j] at this
exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _)
#align nat.factorial_mul_factorial_dvd_factorial_add Nat.factorial_mul_factorial_dvd_factorial_add
@[simp]
theorem choose_symm {n k : ℕ} (hk : k ≤ n) : choose n (n - k) = choose n k := by
rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _),
Nat.sub_sub_self hk, Nat.mul_comm]
#align nat.choose_symm Nat.choose_symm
theorem choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by
suffices choose n (n - b) = choose n b by
rw [h, Nat.add_sub_cancel_right] at this; rwa [h]
exact choose_symm (h ▸ le_add_left _ _)
#align nat.choose_symm_of_eq_add Nat.choose_symm_of_eq_add
theorem choose_symm_add {a b : ℕ} : choose (a + b) a = choose (a + b) b :=
choose_symm_of_eq_add rfl
#align nat.choose_symm_add Nat.choose_symm_add
theorem choose_symm_half (m : ℕ) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m := by
apply choose_symm_of_eq_add
rw [Nat.add_comm m 1, Nat.add_assoc 1 m m, Nat.add_comm (2 * m) 1, Nat.two_mul m]
#align nat.choose_symm_half Nat.choose_symm_half
theorem choose_succ_right_eq (n k : ℕ) : choose n (k + 1) * (k + 1) = choose n k * (n - k) := by
have e : (n + 1) * choose n k = choose n (k + 1) * (k + 1) + choose n k * (k + 1) := by
rw [← Nat.add_mul, Nat.add_comm (choose _ _), ← choose_succ_succ, succ_mul_choose_eq]
rw [← Nat.sub_eq_of_eq_add e, Nat.mul_comm, ← Nat.mul_sub_left_distrib, Nat.add_sub_add_right]
#align nat.choose_succ_right_eq Nat.choose_succ_right_eq
@[simp]
theorem choose_succ_self_right : ∀ n : ℕ, (n + 1).choose n = n + 1
| 0 => rfl
| n + 1 => by rw [choose_succ_succ, choose_succ_self_right n, choose_self]
#align nat.choose_succ_self_right Nat.choose_succ_self_right
theorem choose_mul_succ_eq (n k : ℕ) : n.choose k * (n + 1) = (n + 1).choose k * (n + 1 - k) := by
cases k with
| zero => simp
| succ k =>
obtain hk | hk := le_or_lt (k + 1) (n + 1)
· rw [choose_succ_succ, Nat.add_mul, succ_sub_succ, ← choose_succ_right_eq, ← succ_sub_succ,
Nat.mul_sub_left_distrib, Nat.add_sub_cancel' (Nat.mul_le_mul_left _ hk)]
· rw [choose_eq_zero_of_lt hk, choose_eq_zero_of_lt (n.lt_succ_self.trans hk), Nat.zero_mul,
Nat.zero_mul]
#align nat.choose_mul_succ_eq Nat.choose_mul_succ_eq
theorem ascFactorial_eq_factorial_mul_choose (n k : ℕ) :
(n + 1).ascFactorial k = k ! * (n + k).choose k := by
rw [Nat.mul_comm]
apply Nat.mul_right_cancel (n + k - k).factorial_pos
rw [choose_mul_factorial_mul_factorial <| Nat.le_add_left k n, Nat.add_sub_cancel_right,
← factorial_mul_ascFactorial, Nat.mul_comm]
#align nat.asc_factorial_eq_factorial_mul_choose Nat.ascFactorial_eq_factorial_mul_choose
theorem ascFactorial_eq_factorial_mul_choose' (n k : ℕ) :
n.ascFactorial k = k ! * (n + k - 1).choose k := by
cases n
· cases k
· rw [ascFactorial_zero, choose_zero_right, factorial_zero, Nat.mul_one]
· simp only [zero_ascFactorial, zero_eq, Nat.zero_add, succ_sub_succ_eq_sub,
Nat.le_zero_eq, Nat.sub_zero, choose_succ_self, Nat.mul_zero]
rw [ascFactorial_eq_factorial_mul_choose]
simp only [succ_add_sub_one]
theorem factorial_dvd_ascFactorial (n k : ℕ) : k ! ∣ n.ascFactorial k :=
⟨(n + k - 1).choose k, ascFactorial_eq_factorial_mul_choose' _ _⟩
#align nat.factorial_dvd_asc_factorial Nat.factorial_dvd_ascFactorial
theorem choose_eq_asc_factorial_div_factorial (n k : ℕ) :
(n + k).choose k = (n + 1).ascFactorial k / k ! := by
apply Nat.mul_left_cancel k.factorial_pos
rw [← ascFactorial_eq_factorial_mul_choose]
exact (Nat.mul_div_cancel' <| factorial_dvd_ascFactorial _ _).symm
#align nat.choose_eq_asc_factorial_div_factorial Nat.choose_eq_asc_factorial_div_factorial
theorem choose_eq_asc_factorial_div_factorial' (n k : ℕ) :
(n + k - 1).choose k = n.ascFactorial k / k ! :=
Nat.eq_div_of_mul_eq_right k.factorial_ne_zero (ascFactorial_eq_factorial_mul_choose' _ _).symm
theorem descFactorial_eq_factorial_mul_choose (n k : ℕ) : n.descFactorial k = k ! * n.choose k := by
obtain h | h := Nat.lt_or_ge n k
· rw [descFactorial_eq_zero_iff_lt.2 h, choose_eq_zero_of_lt h, Nat.mul_zero]
rw [Nat.mul_comm]
apply Nat.mul_right_cancel (n - k).factorial_pos
rw [choose_mul_factorial_mul_factorial h, ← factorial_mul_descFactorial h, Nat.mul_comm]
#align nat.desc_factorial_eq_factorial_mul_choose Nat.descFactorial_eq_factorial_mul_choose
theorem factorial_dvd_descFactorial (n k : ℕ) : k ! ∣ n.descFactorial k :=
⟨n.choose k, descFactorial_eq_factorial_mul_choose _ _⟩
#align nat.factorial_dvd_desc_factorial Nat.factorial_dvd_descFactorial
theorem choose_eq_descFactorial_div_factorial (n k : ℕ) : n.choose k = n.descFactorial k / k ! :=
Nat.eq_div_of_mul_eq_right k.factorial_ne_zero (descFactorial_eq_factorial_mul_choose _ _).symm
#align nat.choose_eq_desc_factorial_div_factorial Nat.choose_eq_descFactorial_div_factorial
/-- A faster implementation of `choose`, to be used during bytecode evaluation
and in compiled code. -/
def fast_choose n k := Nat.descFactorial n k / Nat.factorial k
@[csimp] lemma choose_eq_fast_choose : Nat.choose = fast_choose :=
funext (fun _ => funext (Nat.choose_eq_descFactorial_div_factorial _))
/-! ### Inequalities -/
/-- Show that `Nat.choose` is increasing for small values of the right argument. -/
theorem choose_le_succ_of_lt_half_left {r n : ℕ} (h : r < n / 2) :
choose n r ≤ choose n (r + 1) := by
refine Nat.le_of_mul_le_mul_right ?_ (Nat.sub_pos_of_lt (h.trans_le (n.div_le_self 2)))
rw [← choose_succ_right_eq]
apply Nat.mul_le_mul_left
rw [← Nat.lt_iff_add_one_le, Nat.lt_sub_iff_add_lt, ← Nat.mul_two]
exact lt_of_lt_of_le (Nat.mul_lt_mul_of_pos_right h Nat.zero_lt_two) (n.div_mul_le_self 2)
#align nat.choose_le_succ_of_lt_half_left Nat.choose_le_succ_of_lt_half_left
/-- Show that for small values of the right argument, the middle value is largest. -/
private theorem choose_le_middle_of_le_half_left {n r : ℕ} (hr : r ≤ n / 2) :
choose n r ≤ choose n (n / 2) :=
decreasingInduction
(fun _ k a =>
(eq_or_lt_of_le a).elim (fun t => t.symm ▸ le_rfl) fun h =>
(choose_le_succ_of_lt_half_left h).trans (k h))
hr (fun _ => le_rfl) hr
/-- `choose n r` is maximised when `r` is `n/2`. -/
| Mathlib/Data/Nat/Choose/Basic.lean | 315 | 326 | theorem choose_le_middle (r n : ℕ) : choose n r ≤ choose n (n / 2) := by |
cases' le_or_gt r n with b b
· rcases le_or_lt r (n / 2) with a | h
· apply choose_le_middle_of_le_half_left a
· rw [← choose_symm b]
apply choose_le_middle_of_le_half_left
rw [div_lt_iff_lt_mul' Nat.zero_lt_two] at h
rw [le_div_iff_mul_le' Nat.zero_lt_two, Nat.mul_sub_right_distrib, Nat.sub_le_iff_le_add,
← Nat.sub_le_iff_le_add', Nat.mul_two, Nat.add_sub_cancel]
exact le_of_lt h
· rw [choose_eq_zero_of_lt b]
apply zero_le
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Logic.Relation
import Mathlib.Data.Option.Basic
import Mathlib.Data.Seq.Seq
#align_import data.seq.wseq from "leanprover-community/mathlib"@"a7e36e48519ab281320c4d192da6a7b348ce40ad"
/-!
# Partially defined possibly infinite lists
This file provides a `WSeq α` type representing partially defined possibly infinite lists
(referred here as weak sequences).
-/
namespace Stream'
open Function
universe u v w
/-
coinductive WSeq (α : Type u) : Type u
| nil : WSeq α
| cons : α → WSeq α → WSeq α
| think : WSeq α → WSeq α
-/
/-- Weak sequences.
While the `Seq` structure allows for lists which may not be finite,
a weak sequence also allows the computation of each element to
involve an indeterminate amount of computation, including possibly
an infinite loop. This is represented as a regular `Seq` interspersed
with `none` elements to indicate that computation is ongoing.
This model is appropriate for Haskell style lazy lists, and is closed
under most interesting computation patterns on infinite lists,
but conversely it is difficult to extract elements from it. -/
def WSeq (α) :=
Seq (Option α)
#align stream.wseq Stream'.WSeq
/-
coinductive WSeq (α : Type u) : Type u
| nil : WSeq α
| cons : α → WSeq α → WSeq α
| think : WSeq α → WSeq α
-/
namespace WSeq
variable {α : Type u} {β : Type v} {γ : Type w}
/-- Turn a sequence into a weak sequence -/
@[coe]
def ofSeq : Seq α → WSeq α :=
(· <$> ·) some
#align stream.wseq.of_seq Stream'.WSeq.ofSeq
/-- Turn a list into a weak sequence -/
@[coe]
def ofList (l : List α) : WSeq α :=
ofSeq l
#align stream.wseq.of_list Stream'.WSeq.ofList
/-- Turn a stream into a weak sequence -/
@[coe]
def ofStream (l : Stream' α) : WSeq α :=
ofSeq l
#align stream.wseq.of_stream Stream'.WSeq.ofStream
instance coeSeq : Coe (Seq α) (WSeq α) :=
⟨ofSeq⟩
#align stream.wseq.coe_seq Stream'.WSeq.coeSeq
instance coeList : Coe (List α) (WSeq α) :=
⟨ofList⟩
#align stream.wseq.coe_list Stream'.WSeq.coeList
instance coeStream : Coe (Stream' α) (WSeq α) :=
⟨ofStream⟩
#align stream.wseq.coe_stream Stream'.WSeq.coeStream
/-- The empty weak sequence -/
def nil : WSeq α :=
Seq.nil
#align stream.wseq.nil Stream'.WSeq.nil
instance inhabited : Inhabited (WSeq α) :=
⟨nil⟩
#align stream.wseq.inhabited Stream'.WSeq.inhabited
/-- Prepend an element to a weak sequence -/
def cons (a : α) : WSeq α → WSeq α :=
Seq.cons (some a)
#align stream.wseq.cons Stream'.WSeq.cons
/-- Compute for one tick, without producing any elements -/
def think : WSeq α → WSeq α :=
Seq.cons none
#align stream.wseq.think Stream'.WSeq.think
/-- Destruct a weak sequence, to (eventually possibly) produce either
`none` for `nil` or `some (a, s)` if an element is produced. -/
def destruct : WSeq α → Computation (Option (α × WSeq α)) :=
Computation.corec fun s =>
match Seq.destruct s with
| none => Sum.inl none
| some (none, s') => Sum.inr s'
| some (some a, s') => Sum.inl (some (a, s'))
#align stream.wseq.destruct Stream'.WSeq.destruct
/-- Recursion principle for weak sequences, compare with `List.recOn`. -/
def recOn {C : WSeq α → Sort v} (s : WSeq α) (h1 : C nil) (h2 : ∀ x s, C (cons x s))
(h3 : ∀ s, C (think s)) : C s :=
Seq.recOn s h1 fun o => Option.recOn o h3 h2
#align stream.wseq.rec_on Stream'.WSeq.recOn
/-- membership for weak sequences-/
protected def Mem (a : α) (s : WSeq α) :=
Seq.Mem (some a) s
#align stream.wseq.mem Stream'.WSeq.Mem
instance membership : Membership α (WSeq α) :=
⟨WSeq.Mem⟩
#align stream.wseq.has_mem Stream'.WSeq.membership
theorem not_mem_nil (a : α) : a ∉ @nil α :=
Seq.not_mem_nil (some a)
#align stream.wseq.not_mem_nil Stream'.WSeq.not_mem_nil
/-- Get the head of a weak sequence. This involves a possibly
infinite computation. -/
def head (s : WSeq α) : Computation (Option α) :=
Computation.map (Prod.fst <$> ·) (destruct s)
#align stream.wseq.head Stream'.WSeq.head
/-- Encode a computation yielding a weak sequence into additional
`think` constructors in a weak sequence -/
def flatten : Computation (WSeq α) → WSeq α :=
Seq.corec fun c =>
match Computation.destruct c with
| Sum.inl s => Seq.omap (return ·) (Seq.destruct s)
| Sum.inr c' => some (none, c')
#align stream.wseq.flatten Stream'.WSeq.flatten
/-- Get the tail of a weak sequence. This doesn't need a `Computation`
wrapper, unlike `head`, because `flatten` allows us to hide this
in the construction of the weak sequence itself. -/
def tail (s : WSeq α) : WSeq α :=
flatten <| (fun o => Option.recOn o nil Prod.snd) <$> destruct s
#align stream.wseq.tail Stream'.WSeq.tail
/-- drop the first `n` elements from `s`. -/
def drop (s : WSeq α) : ℕ → WSeq α
| 0 => s
| n + 1 => tail (drop s n)
#align stream.wseq.drop Stream'.WSeq.drop
/-- Get the nth element of `s`. -/
def get? (s : WSeq α) (n : ℕ) : Computation (Option α) :=
head (drop s n)
#align stream.wseq.nth Stream'.WSeq.get?
/-- Convert `s` to a list (if it is finite and completes in finite time). -/
def toList (s : WSeq α) : Computation (List α) :=
@Computation.corec (List α) (List α × WSeq α)
(fun ⟨l, s⟩ =>
match Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a::l, s'))
([], s)
#align stream.wseq.to_list Stream'.WSeq.toList
/-- Get the length of `s` (if it is finite and completes in finite time). -/
def length (s : WSeq α) : Computation ℕ :=
@Computation.corec ℕ (ℕ × WSeq α)
(fun ⟨n, s⟩ =>
match Seq.destruct s with
| none => Sum.inl n
| some (none, s') => Sum.inr (n, s')
| some (some _, s') => Sum.inr (n + 1, s'))
(0, s)
#align stream.wseq.length Stream'.WSeq.length
/-- A weak sequence is finite if `toList s` terminates. Equivalently,
it is a finite number of `think` and `cons` applied to `nil`. -/
class IsFinite (s : WSeq α) : Prop where
out : (toList s).Terminates
#align stream.wseq.is_finite Stream'.WSeq.IsFinite
instance toList_terminates (s : WSeq α) [h : IsFinite s] : (toList s).Terminates :=
h.out
#align stream.wseq.to_list_terminates Stream'.WSeq.toList_terminates
/-- Get the list corresponding to a finite weak sequence. -/
def get (s : WSeq α) [IsFinite s] : List α :=
(toList s).get
#align stream.wseq.get Stream'.WSeq.get
/-- A weak sequence is *productive* if it never stalls forever - there are
always a finite number of `think`s between `cons` constructors.
The sequence itself is allowed to be infinite though. -/
class Productive (s : WSeq α) : Prop where
get?_terminates : ∀ n, (get? s n).Terminates
#align stream.wseq.productive Stream'.WSeq.Productive
#align stream.wseq.productive.nth_terminates Stream'.WSeq.Productive.get?_terminates
theorem productive_iff (s : WSeq α) : Productive s ↔ ∀ n, (get? s n).Terminates :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
#align stream.wseq.productive_iff Stream'.WSeq.productive_iff
instance get?_terminates (s : WSeq α) [h : Productive s] : ∀ n, (get? s n).Terminates :=
h.get?_terminates
#align stream.wseq.nth_terminates Stream'.WSeq.get?_terminates
instance head_terminates (s : WSeq α) [Productive s] : (head s).Terminates :=
s.get?_terminates 0
#align stream.wseq.head_terminates Stream'.WSeq.head_terminates
/-- Replace the `n`th element of `s` with `a`. -/
def updateNth (s : WSeq α) (n : ℕ) (a : α) : WSeq α :=
@Seq.corec (Option α) (ℕ × WSeq α)
(fun ⟨n, s⟩ =>
match Seq.destruct s, n with
| none, _ => none
| some (none, s'), n => some (none, n, s')
| some (some a', s'), 0 => some (some a', 0, s')
| some (some _, s'), 1 => some (some a, 0, s')
| some (some a', s'), n + 2 => some (some a', n + 1, s'))
(n + 1, s)
#align stream.wseq.update_nth Stream'.WSeq.updateNth
/-- Remove the `n`th element of `s`. -/
def removeNth (s : WSeq α) (n : ℕ) : WSeq α :=
@Seq.corec (Option α) (ℕ × WSeq α)
(fun ⟨n, s⟩ =>
match Seq.destruct s, n with
| none, _ => none
| some (none, s'), n => some (none, n, s')
| some (some a', s'), 0 => some (some a', 0, s')
| some (some _, s'), 1 => some (none, 0, s')
| some (some a', s'), n + 2 => some (some a', n + 1, s'))
(n + 1, s)
#align stream.wseq.remove_nth Stream'.WSeq.removeNth
/-- Map the elements of `s` over `f`, removing any values that yield `none`. -/
def filterMap (f : α → Option β) : WSeq α → WSeq β :=
Seq.corec fun s =>
match Seq.destruct s with
| none => none
| some (none, s') => some (none, s')
| some (some a, s') => some (f a, s')
#align stream.wseq.filter_map Stream'.WSeq.filterMap
/-- Select the elements of `s` that satisfy `p`. -/
def filter (p : α → Prop) [DecidablePred p] : WSeq α → WSeq α :=
filterMap fun a => if p a then some a else none
#align stream.wseq.filter Stream'.WSeq.filter
-- example of infinite list manipulations
/-- Get the first element of `s` satisfying `p`. -/
def find (p : α → Prop) [DecidablePred p] (s : WSeq α) : Computation (Option α) :=
head <| filter p s
#align stream.wseq.find Stream'.WSeq.find
/-- Zip a function over two weak sequences -/
def zipWith (f : α → β → γ) (s1 : WSeq α) (s2 : WSeq β) : WSeq γ :=
@Seq.corec (Option γ) (WSeq α × WSeq β)
(fun ⟨s1, s2⟩ =>
match Seq.destruct s1, Seq.destruct s2 with
| some (none, s1'), some (none, s2') => some (none, s1', s2')
| some (some _, _), some (none, s2') => some (none, s1, s2')
| some (none, s1'), some (some _, _) => some (none, s1', s2)
| some (some a1, s1'), some (some a2, s2') => some (some (f a1 a2), s1', s2')
| _, _ => none)
(s1, s2)
#align stream.wseq.zip_with Stream'.WSeq.zipWith
/-- Zip two weak sequences into a single sequence of pairs -/
def zip : WSeq α → WSeq β → WSeq (α × β) :=
zipWith Prod.mk
#align stream.wseq.zip Stream'.WSeq.zip
/-- Get the list of indexes of elements of `s` satisfying `p` -/
def findIndexes (p : α → Prop) [DecidablePred p] (s : WSeq α) : WSeq ℕ :=
(zip s (Stream'.nats : WSeq ℕ)).filterMap fun ⟨a, n⟩ => if p a then some n else none
#align stream.wseq.find_indexes Stream'.WSeq.findIndexes
/-- Get the index of the first element of `s` satisfying `p` -/
def findIndex (p : α → Prop) [DecidablePred p] (s : WSeq α) : Computation ℕ :=
(fun o => Option.getD o 0) <$> head (findIndexes p s)
#align stream.wseq.find_index Stream'.WSeq.findIndex
/-- Get the index of the first occurrence of `a` in `s` -/
def indexOf [DecidableEq α] (a : α) : WSeq α → Computation ℕ :=
findIndex (Eq a)
#align stream.wseq.index_of Stream'.WSeq.indexOf
/-- Get the indexes of occurrences of `a` in `s` -/
def indexesOf [DecidableEq α] (a : α) : WSeq α → WSeq ℕ :=
findIndexes (Eq a)
#align stream.wseq.indexes_of Stream'.WSeq.indexesOf
/-- `union s1 s2` is a weak sequence which interleaves `s1` and `s2` in
some order (nondeterministically). -/
def union (s1 s2 : WSeq α) : WSeq α :=
@Seq.corec (Option α) (WSeq α × WSeq α)
(fun ⟨s1, s2⟩ =>
match Seq.destruct s1, Seq.destruct s2 with
| none, none => none
| some (a1, s1'), none => some (a1, s1', nil)
| none, some (a2, s2') => some (a2, nil, s2')
| some (none, s1'), some (none, s2') => some (none, s1', s2')
| some (some a1, s1'), some (none, s2') => some (some a1, s1', s2')
| some (none, s1'), some (some a2, s2') => some (some a2, s1', s2')
| some (some a1, s1'), some (some a2, s2') => some (some a1, cons a2 s1', s2'))
(s1, s2)
#align stream.wseq.union Stream'.WSeq.union
/-- Returns `true` if `s` is `nil` and `false` if `s` has an element -/
def isEmpty (s : WSeq α) : Computation Bool :=
Computation.map Option.isNone <| head s
#align stream.wseq.is_empty Stream'.WSeq.isEmpty
/-- Calculate one step of computation -/
def compute (s : WSeq α) : WSeq α :=
match Seq.destruct s with
| some (none, s') => s'
| _ => s
#align stream.wseq.compute Stream'.WSeq.compute
/-- Get the first `n` elements of a weak sequence -/
def take (s : WSeq α) (n : ℕ) : WSeq α :=
@Seq.corec (Option α) (ℕ × WSeq α)
(fun ⟨n, s⟩ =>
match n, Seq.destruct s with
| 0, _ => none
| _ + 1, none => none
| m + 1, some (none, s') => some (none, m + 1, s')
| m + 1, some (some a, s') => some (some a, m, s'))
(n, s)
#align stream.wseq.take Stream'.WSeq.take
/-- Split the sequence at position `n` into a finite initial segment
and the weak sequence tail -/
def splitAt (s : WSeq α) (n : ℕ) : Computation (List α × WSeq α) :=
@Computation.corec (List α × WSeq α) (ℕ × List α × WSeq α)
(fun ⟨n, l, s⟩ =>
match n, Seq.destruct s with
| 0, _ => Sum.inl (l.reverse, s)
| _ + 1, none => Sum.inl (l.reverse, s)
| _ + 1, some (none, s') => Sum.inr (n, l, s')
| m + 1, some (some a, s') => Sum.inr (m, a::l, s'))
(n, [], s)
#align stream.wseq.split_at Stream'.WSeq.splitAt
/-- Returns `true` if any element of `s` satisfies `p` -/
def any (s : WSeq α) (p : α → Bool) : Computation Bool :=
Computation.corec
(fun s : WSeq α =>
match Seq.destruct s with
| none => Sum.inl false
| some (none, s') => Sum.inr s'
| some (some a, s') => if p a then Sum.inl true else Sum.inr s')
s
#align stream.wseq.any Stream'.WSeq.any
/-- Returns `true` if every element of `s` satisfies `p` -/
def all (s : WSeq α) (p : α → Bool) : Computation Bool :=
Computation.corec
(fun s : WSeq α =>
match Seq.destruct s with
| none => Sum.inl true
| some (none, s') => Sum.inr s'
| some (some a, s') => if p a then Sum.inr s' else Sum.inl false)
s
#align stream.wseq.all Stream'.WSeq.all
/-- Apply a function to the elements of the sequence to produce a sequence
of partial results. (There is no `scanr` because this would require
working from the end of the sequence, which may not exist.) -/
def scanl (f : α → β → α) (a : α) (s : WSeq β) : WSeq α :=
cons a <|
@Seq.corec (Option α) (α × WSeq β)
(fun ⟨a, s⟩ =>
match Seq.destruct s with
| none => none
| some (none, s') => some (none, a, s')
| some (some b, s') =>
let a' := f a b
some (some a', a', s'))
(a, s)
#align stream.wseq.scanl Stream'.WSeq.scanl
/-- Get the weak sequence of initial segments of the input sequence -/
def inits (s : WSeq α) : WSeq (List α) :=
cons [] <|
@Seq.corec (Option (List α)) (Batteries.DList α × WSeq α)
(fun ⟨l, s⟩ =>
match Seq.destruct s with
| none => none
| some (none, s') => some (none, l, s')
| some (some a, s') =>
let l' := l.push a
some (some l'.toList, l', s'))
(Batteries.DList.empty, s)
#align stream.wseq.inits Stream'.WSeq.inits
/-- Like take, but does not wait for a result. Calculates `n` steps of
computation and returns the sequence computed so far -/
def collect (s : WSeq α) (n : ℕ) : List α :=
(Seq.take n s).filterMap id
#align stream.wseq.collect Stream'.WSeq.collect
/-- Append two weak sequences. As with `Seq.append`, this may not use
the second sequence if the first one takes forever to compute -/
def append : WSeq α → WSeq α → WSeq α :=
Seq.append
#align stream.wseq.append Stream'.WSeq.append
/-- Map a function over a weak sequence -/
def map (f : α → β) : WSeq α → WSeq β :=
Seq.map (Option.map f)
#align stream.wseq.map Stream'.WSeq.map
/-- Flatten a sequence of weak sequences. (Note that this allows
empty sequences, unlike `Seq.join`.) -/
def join (S : WSeq (WSeq α)) : WSeq α :=
Seq.join
((fun o : Option (WSeq α) =>
match o with
| none => Seq1.ret none
| some s => (none, s)) <$>
S)
#align stream.wseq.join Stream'.WSeq.join
/-- Monadic bind operator for weak sequences -/
def bind (s : WSeq α) (f : α → WSeq β) : WSeq β :=
join (map f s)
#align stream.wseq.bind Stream'.WSeq.bind
/-- lift a relation to a relation over weak sequences -/
@[simp]
def LiftRelO (R : α → β → Prop) (C : WSeq α → WSeq β → Prop) :
Option (α × WSeq α) → Option (β × WSeq β) → Prop
| none, none => True
| some (a, s), some (b, t) => R a b ∧ C s t
| _, _ => False
#align stream.wseq.lift_rel_o Stream'.WSeq.LiftRelO
theorem LiftRelO.imp {R S : α → β → Prop} {C D : WSeq α → WSeq β → Prop} (H1 : ∀ a b, R a b → S a b)
(H2 : ∀ s t, C s t → D s t) : ∀ {o p}, LiftRelO R C o p → LiftRelO S D o p
| none, none, _ => trivial
| some (_, _), some (_, _), h => And.imp (H1 _ _) (H2 _ _) h
| none, some _, h => False.elim h
| some (_, _), none, h => False.elim h
#align stream.wseq.lift_rel_o.imp Stream'.WSeq.LiftRelO.imp
theorem LiftRelO.imp_right (R : α → β → Prop) {C D : WSeq α → WSeq β → Prop}
(H : ∀ s t, C s t → D s t) {o p} : LiftRelO R C o p → LiftRelO R D o p :=
LiftRelO.imp (fun _ _ => id) H
#align stream.wseq.lift_rel_o.imp_right Stream'.WSeq.LiftRelO.imp_right
/-- Definition of bisimilarity for weak sequences-/
@[simp]
def BisimO (R : WSeq α → WSeq α → Prop) : Option (α × WSeq α) → Option (α × WSeq α) → Prop :=
LiftRelO (· = ·) R
#align stream.wseq.bisim_o Stream'.WSeq.BisimO
theorem BisimO.imp {R S : WSeq α → WSeq α → Prop} (H : ∀ s t, R s t → S s t) {o p} :
BisimO R o p → BisimO S o p :=
LiftRelO.imp_right _ H
#align stream.wseq.bisim_o.imp Stream'.WSeq.BisimO.imp
/-- Two weak sequences are `LiftRel R` related if they are either both empty,
or they are both nonempty and the heads are `R` related and the tails are
`LiftRel R` related. (This is a coinductive definition.) -/
def LiftRel (R : α → β → Prop) (s : WSeq α) (t : WSeq β) : Prop :=
∃ C : WSeq α → WSeq β → Prop,
C s t ∧ ∀ {s t}, C s t → Computation.LiftRel (LiftRelO R C) (destruct s) (destruct t)
#align stream.wseq.lift_rel Stream'.WSeq.LiftRel
/-- If two sequences are equivalent, then they have the same values and
the same computational behavior (i.e. if one loops forever then so does
the other), although they may differ in the number of `think`s needed to
arrive at the answer. -/
def Equiv : WSeq α → WSeq α → Prop :=
LiftRel (· = ·)
#align stream.wseq.equiv Stream'.WSeq.Equiv
theorem liftRel_destruct {R : α → β → Prop} {s : WSeq α} {t : WSeq β} :
LiftRel R s t → Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t)
| ⟨R, h1, h2⟩ => by
refine Computation.LiftRel.imp ?_ _ _ (h2 h1)
apply LiftRelO.imp_right
exact fun s' t' h' => ⟨R, h', @h2⟩
#align stream.wseq.lift_rel_destruct Stream'.WSeq.liftRel_destruct
theorem liftRel_destruct_iff {R : α → β → Prop} {s : WSeq α} {t : WSeq β} :
LiftRel R s t ↔ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) :=
⟨liftRel_destruct, fun h =>
⟨fun s t =>
LiftRel R s t ∨ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t),
Or.inr h, fun {s t} h => by
have h : Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) := by
cases' h with h h
· exact liftRel_destruct h
· assumption
apply Computation.LiftRel.imp _ _ _ h
intro a b
apply LiftRelO.imp_right
intro s t
apply Or.inl⟩⟩
#align stream.wseq.lift_rel_destruct_iff Stream'.WSeq.liftRel_destruct_iff
-- Porting note: To avoid ambiguous notation, `~` became `~ʷ`.
infixl:50 " ~ʷ " => Equiv
theorem destruct_congr {s t : WSeq α} :
s ~ʷ t → Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) :=
liftRel_destruct
#align stream.wseq.destruct_congr Stream'.WSeq.destruct_congr
theorem destruct_congr_iff {s t : WSeq α} :
s ~ʷ t ↔ Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) :=
liftRel_destruct_iff
#align stream.wseq.destruct_congr_iff Stream'.WSeq.destruct_congr_iff
theorem LiftRel.refl (R : α → α → Prop) (H : Reflexive R) : Reflexive (LiftRel R) := fun s => by
refine ⟨(· = ·), rfl, fun {s t} (h : s = t) => ?_⟩
rw [← h]
apply Computation.LiftRel.refl
intro a
cases' a with a
· simp
· cases a
simp only [LiftRelO, and_true]
apply H
#align stream.wseq.lift_rel.refl Stream'.WSeq.LiftRel.refl
theorem LiftRelO.swap (R : α → β → Prop) (C) :
swap (LiftRelO R C) = LiftRelO (swap R) (swap C) := by
funext x y
rcases x with ⟨⟩ | ⟨hx, jx⟩ <;> rcases y with ⟨⟩ | ⟨hy, jy⟩ <;> rfl
#align stream.wseq.lift_rel_o.swap Stream'.WSeq.LiftRelO.swap
theorem LiftRel.swap_lem {R : α → β → Prop} {s1 s2} (h : LiftRel R s1 s2) :
LiftRel (swap R) s2 s1 := by
refine ⟨swap (LiftRel R), h, fun {s t} (h : LiftRel R t s) => ?_⟩
rw [← LiftRelO.swap, Computation.LiftRel.swap]
apply liftRel_destruct h
#align stream.wseq.lift_rel.swap_lem Stream'.WSeq.LiftRel.swap_lem
theorem LiftRel.swap (R : α → β → Prop) : swap (LiftRel R) = LiftRel (swap R) :=
funext fun _ => funext fun _ => propext ⟨LiftRel.swap_lem, LiftRel.swap_lem⟩
#align stream.wseq.lift_rel.swap Stream'.WSeq.LiftRel.swap
theorem LiftRel.symm (R : α → α → Prop) (H : Symmetric R) : Symmetric (LiftRel R) :=
fun s1 s2 (h : Function.swap (LiftRel R) s2 s1) => by rwa [LiftRel.swap, H.swap_eq] at h
#align stream.wseq.lift_rel.symm Stream'.WSeq.LiftRel.symm
theorem LiftRel.trans (R : α → α → Prop) (H : Transitive R) : Transitive (LiftRel R) :=
fun s t u h1 h2 => by
refine ⟨fun s u => ∃ t, LiftRel R s t ∧ LiftRel R t u, ⟨t, h1, h2⟩, fun {s u} h => ?_⟩
rcases h with ⟨t, h1, h2⟩
have h1 := liftRel_destruct h1
have h2 := liftRel_destruct h2
refine
Computation.liftRel_def.2
⟨(Computation.terminates_of_liftRel h1).trans (Computation.terminates_of_liftRel h2),
fun {a c} ha hc => ?_⟩
rcases h1.left ha with ⟨b, hb, t1⟩
have t2 := Computation.rel_of_liftRel h2 hb hc
cases' a with a <;> cases' c with c
· trivial
· cases b
· cases t2
· cases t1
· cases a
cases' b with b
· cases t1
· cases b
cases t2
· cases' a with a s
cases' b with b
· cases t1
cases' b with b t
cases' c with c u
cases' t1 with ab st
cases' t2 with bc tu
exact ⟨H ab bc, t, st, tu⟩
#align stream.wseq.lift_rel.trans Stream'.WSeq.LiftRel.trans
theorem LiftRel.equiv (R : α → α → Prop) : Equivalence R → Equivalence (LiftRel R)
| ⟨refl, symm, trans⟩ => ⟨LiftRel.refl R refl, @(LiftRel.symm R @symm), @(LiftRel.trans R @trans)⟩
#align stream.wseq.lift_rel.equiv Stream'.WSeq.LiftRel.equiv
@[refl]
theorem Equiv.refl : ∀ s : WSeq α, s ~ʷ s :=
LiftRel.refl (· = ·) Eq.refl
#align stream.wseq.equiv.refl Stream'.WSeq.Equiv.refl
@[symm]
theorem Equiv.symm : ∀ {s t : WSeq α}, s ~ʷ t → t ~ʷ s :=
@(LiftRel.symm (· = ·) (@Eq.symm _))
#align stream.wseq.equiv.symm Stream'.WSeq.Equiv.symm
@[trans]
theorem Equiv.trans : ∀ {s t u : WSeq α}, s ~ʷ t → t ~ʷ u → s ~ʷ u :=
@(LiftRel.trans (· = ·) (@Eq.trans _))
#align stream.wseq.equiv.trans Stream'.WSeq.Equiv.trans
theorem Equiv.equivalence : Equivalence (@Equiv α) :=
⟨@Equiv.refl _, @Equiv.symm _, @Equiv.trans _⟩
#align stream.wseq.equiv.equivalence Stream'.WSeq.Equiv.equivalence
open Computation
@[simp]
theorem destruct_nil : destruct (nil : WSeq α) = Computation.pure none :=
Computation.destruct_eq_pure rfl
#align stream.wseq.destruct_nil Stream'.WSeq.destruct_nil
@[simp]
theorem destruct_cons (a : α) (s) : destruct (cons a s) = Computation.pure (some (a, s)) :=
Computation.destruct_eq_pure <| by simp [destruct, cons, Computation.rmap]
#align stream.wseq.destruct_cons Stream'.WSeq.destruct_cons
@[simp]
theorem destruct_think (s : WSeq α) : destruct (think s) = (destruct s).think :=
Computation.destruct_eq_think <| by simp [destruct, think, Computation.rmap]
#align stream.wseq.destruct_think Stream'.WSeq.destruct_think
@[simp]
theorem seq_destruct_nil : Seq.destruct (nil : WSeq α) = none :=
Seq.destruct_nil
#align stream.wseq.seq_destruct_nil Stream'.WSeq.seq_destruct_nil
@[simp]
theorem seq_destruct_cons (a : α) (s) : Seq.destruct (cons a s) = some (some a, s) :=
Seq.destruct_cons _ _
#align stream.wseq.seq_destruct_cons Stream'.WSeq.seq_destruct_cons
@[simp]
theorem seq_destruct_think (s : WSeq α) : Seq.destruct (think s) = some (none, s) :=
Seq.destruct_cons _ _
#align stream.wseq.seq_destruct_think Stream'.WSeq.seq_destruct_think
@[simp]
theorem head_nil : head (nil : WSeq α) = Computation.pure none := by simp [head]
#align stream.wseq.head_nil Stream'.WSeq.head_nil
@[simp]
theorem head_cons (a : α) (s) : head (cons a s) = Computation.pure (some a) := by simp [head]
#align stream.wseq.head_cons Stream'.WSeq.head_cons
@[simp]
theorem head_think (s : WSeq α) : head (think s) = (head s).think := by simp [head]
#align stream.wseq.head_think Stream'.WSeq.head_think
@[simp]
theorem flatten_pure (s : WSeq α) : flatten (Computation.pure s) = s := by
refine Seq.eq_of_bisim (fun s1 s2 => flatten (Computation.pure s2) = s1) ?_ rfl
intro s' s h
rw [← h]
simp only [Seq.BisimO, flatten, Seq.omap, pure_def, Seq.corec_eq, destruct_pure]
cases Seq.destruct s with
| none => simp
| some val =>
cases' val with o s'
simp
#align stream.wseq.flatten_ret Stream'.WSeq.flatten_pure
@[simp]
theorem flatten_think (c : Computation (WSeq α)) : flatten c.think = think (flatten c) :=
Seq.destruct_eq_cons <| by simp [flatten, think]
#align stream.wseq.flatten_think Stream'.WSeq.flatten_think
@[simp]
theorem destruct_flatten (c : Computation (WSeq α)) : destruct (flatten c) = c >>= destruct := by
refine
Computation.eq_of_bisim
(fun c1 c2 => c1 = c2 ∨ ∃ c, c1 = destruct (flatten c) ∧ c2 = Computation.bind c destruct) ?_
(Or.inr ⟨c, rfl, rfl⟩)
intro c1 c2 h
exact
match c1, c2, h with
| c, _, Or.inl rfl => by cases c.destruct <;> simp
| _, _, Or.inr ⟨c, rfl, rfl⟩ => by
induction' c using Computation.recOn with a c' <;> simp
· cases (destruct a).destruct <;> simp
· exact Or.inr ⟨c', rfl, rfl⟩
#align stream.wseq.destruct_flatten Stream'.WSeq.destruct_flatten
theorem head_terminates_iff (s : WSeq α) : Terminates (head s) ↔ Terminates (destruct s) :=
terminates_map_iff _ (destruct s)
#align stream.wseq.head_terminates_iff Stream'.WSeq.head_terminates_iff
@[simp]
theorem tail_nil : tail (nil : WSeq α) = nil := by simp [tail]
#align stream.wseq.tail_nil Stream'.WSeq.tail_nil
@[simp]
theorem tail_cons (a : α) (s) : tail (cons a s) = s := by simp [tail]
#align stream.wseq.tail_cons Stream'.WSeq.tail_cons
@[simp]
theorem tail_think (s : WSeq α) : tail (think s) = (tail s).think := by simp [tail]
#align stream.wseq.tail_think Stream'.WSeq.tail_think
@[simp]
theorem dropn_nil (n) : drop (nil : WSeq α) n = nil := by induction n <;> simp [*, drop]
#align stream.wseq.dropn_nil Stream'.WSeq.dropn_nil
@[simp]
theorem dropn_cons (a : α) (s) (n) : drop (cons a s) (n + 1) = drop s n := by
induction n with
| zero => simp [drop]
| succ n n_ih =>
-- porting note (#10745): was `simp [*, drop]`.
simp [drop, ← n_ih]
#align stream.wseq.dropn_cons Stream'.WSeq.dropn_cons
@[simp]
theorem dropn_think (s : WSeq α) (n) : drop (think s) n = (drop s n).think := by
induction n <;> simp [*, drop]
#align stream.wseq.dropn_think Stream'.WSeq.dropn_think
theorem dropn_add (s : WSeq α) (m) : ∀ n, drop s (m + n) = drop (drop s m) n
| 0 => rfl
| n + 1 => congr_arg tail (dropn_add s m n)
#align stream.wseq.dropn_add Stream'.WSeq.dropn_add
theorem dropn_tail (s : WSeq α) (n) : drop (tail s) n = drop s (n + 1) := by
rw [Nat.add_comm]
symm
apply dropn_add
#align stream.wseq.dropn_tail Stream'.WSeq.dropn_tail
theorem get?_add (s : WSeq α) (m n) : get? s (m + n) = get? (drop s m) n :=
congr_arg head (dropn_add _ _ _)
#align stream.wseq.nth_add Stream'.WSeq.get?_add
theorem get?_tail (s : WSeq α) (n) : get? (tail s) n = get? s (n + 1) :=
congr_arg head (dropn_tail _ _)
#align stream.wseq.nth_tail Stream'.WSeq.get?_tail
@[simp]
theorem join_nil : join nil = (nil : WSeq α) :=
Seq.join_nil
#align stream.wseq.join_nil Stream'.WSeq.join_nil
@[simp]
theorem join_think (S : WSeq (WSeq α)) : join (think S) = think (join S) := by
simp only [join, think]
dsimp only [(· <$> ·)]
simp [join, Seq1.ret]
#align stream.wseq.join_think Stream'.WSeq.join_think
@[simp]
theorem join_cons (s : WSeq α) (S) : join (cons s S) = think (append s (join S)) := by
simp only [join, think]
dsimp only [(· <$> ·)]
simp [join, cons, append]
#align stream.wseq.join_cons Stream'.WSeq.join_cons
@[simp]
theorem nil_append (s : WSeq α) : append nil s = s :=
Seq.nil_append _
#align stream.wseq.nil_append Stream'.WSeq.nil_append
@[simp]
theorem cons_append (a : α) (s t) : append (cons a s) t = cons a (append s t) :=
Seq.cons_append _ _ _
#align stream.wseq.cons_append Stream'.WSeq.cons_append
@[simp]
theorem think_append (s t : WSeq α) : append (think s) t = think (append s t) :=
Seq.cons_append _ _ _
#align stream.wseq.think_append Stream'.WSeq.think_append
@[simp]
theorem append_nil (s : WSeq α) : append s nil = s :=
Seq.append_nil _
#align stream.wseq.append_nil Stream'.WSeq.append_nil
@[simp]
theorem append_assoc (s t u : WSeq α) : append (append s t) u = append s (append t u) :=
Seq.append_assoc _ _ _
#align stream.wseq.append_assoc Stream'.WSeq.append_assoc
/-- auxiliary definition of tail over weak sequences-/
@[simp]
def tail.aux : Option (α × WSeq α) → Computation (Option (α × WSeq α))
| none => Computation.pure none
| some (_, s) => destruct s
#align stream.wseq.tail.aux Stream'.WSeq.tail.aux
theorem destruct_tail (s : WSeq α) : destruct (tail s) = destruct s >>= tail.aux := by
simp only [tail, destruct_flatten, tail.aux]; rw [← bind_pure_comp, LawfulMonad.bind_assoc]
apply congr_arg; ext1 (_ | ⟨a, s⟩) <;> apply (@pure_bind Computation _ _ _ _ _ _).trans _ <;> simp
#align stream.wseq.destruct_tail Stream'.WSeq.destruct_tail
/-- auxiliary definition of drop over weak sequences-/
@[simp]
def drop.aux : ℕ → Option (α × WSeq α) → Computation (Option (α × WSeq α))
| 0 => Computation.pure
| n + 1 => fun a => tail.aux a >>= drop.aux n
#align stream.wseq.drop.aux Stream'.WSeq.drop.aux
theorem drop.aux_none : ∀ n, @drop.aux α n none = Computation.pure none
| 0 => rfl
| n + 1 =>
show Computation.bind (Computation.pure none) (drop.aux n) = Computation.pure none by
rw [ret_bind, drop.aux_none n]
#align stream.wseq.drop.aux_none Stream'.WSeq.drop.aux_none
theorem destruct_dropn : ∀ (s : WSeq α) (n), destruct (drop s n) = destruct s >>= drop.aux n
| s, 0 => (bind_pure' _).symm
| s, n + 1 => by
rw [← dropn_tail, destruct_dropn _ n, destruct_tail, LawfulMonad.bind_assoc]
rfl
#align stream.wseq.destruct_dropn Stream'.WSeq.destruct_dropn
theorem head_terminates_of_head_tail_terminates (s : WSeq α) [T : Terminates (head (tail s))] :
Terminates (head s) :=
(head_terminates_iff _).2 <| by
rcases (head_terminates_iff _).1 T with ⟨⟨a, h⟩⟩
simp? [tail] at h says simp only [tail, destruct_flatten] at h
rcases exists_of_mem_bind h with ⟨s', h1, _⟩
unfold Functor.map at h1
exact
let ⟨t, h3, _⟩ := Computation.exists_of_mem_map h1
Computation.terminates_of_mem h3
#align stream.wseq.head_terminates_of_head_tail_terminates Stream'.WSeq.head_terminates_of_head_tail_terminates
theorem destruct_some_of_destruct_tail_some {s : WSeq α} {a} (h : some a ∈ destruct (tail s)) :
∃ a', some a' ∈ destruct s := by
unfold tail Functor.map at h; simp only [destruct_flatten] at h
rcases exists_of_mem_bind h with ⟨t, tm, td⟩; clear h
rcases Computation.exists_of_mem_map tm with ⟨t', ht', ht2⟩; clear tm
cases' t' with t' <;> rw [← ht2] at td <;> simp only [destruct_nil] at td
· have := mem_unique td (ret_mem _)
contradiction
· exact ⟨_, ht'⟩
#align stream.wseq.destruct_some_of_destruct_tail_some Stream'.WSeq.destruct_some_of_destruct_tail_some
theorem head_some_of_head_tail_some {s : WSeq α} {a} (h : some a ∈ head (tail s)) :
∃ a', some a' ∈ head s := by
unfold head at h
rcases Computation.exists_of_mem_map h with ⟨o, md, e⟩; clear h
cases' o with o <;> [injection e; injection e with h']; clear h'
cases' destruct_some_of_destruct_tail_some md with a am
exact ⟨_, Computation.mem_map (@Prod.fst α (WSeq α) <$> ·) am⟩
#align stream.wseq.head_some_of_head_tail_some Stream'.WSeq.head_some_of_head_tail_some
theorem head_some_of_get?_some {s : WSeq α} {a n} (h : some a ∈ get? s n) :
∃ a', some a' ∈ head s := by
induction n generalizing a with
| zero => exact ⟨_, h⟩
| succ n IH =>
let ⟨a', h'⟩ := head_some_of_head_tail_some h
exact IH h'
#align stream.wseq.head_some_of_nth_some Stream'.WSeq.head_some_of_get?_some
instance productive_tail (s : WSeq α) [Productive s] : Productive (tail s) :=
⟨fun n => by rw [get?_tail]; infer_instance⟩
#align stream.wseq.productive_tail Stream'.WSeq.productive_tail
instance productive_dropn (s : WSeq α) [Productive s] (n) : Productive (drop s n) :=
⟨fun m => by rw [← get?_add]; infer_instance⟩
#align stream.wseq.productive_dropn Stream'.WSeq.productive_dropn
/-- Given a productive weak sequence, we can collapse all the `think`s to
produce a sequence. -/
def toSeq (s : WSeq α) [Productive s] : Seq α :=
⟨fun n => (get? s n).get,
fun {n} h => by
cases e : Computation.get (get? s (n + 1))
· assumption
have := Computation.mem_of_get_eq _ e
simp? [get?] at this h says simp only [get?] at this h
cases' head_some_of_head_tail_some this with a' h'
have := mem_unique h' (@Computation.mem_of_get_eq _ _ _ _ h)
contradiction⟩
#align stream.wseq.to_seq Stream'.WSeq.toSeq
theorem get?_terminates_le {s : WSeq α} {m n} (h : m ≤ n) :
Terminates (get? s n) → Terminates (get? s m) := by
induction' h with m' _ IH
exacts [id, fun T => IH (@head_terminates_of_head_tail_terminates _ _ T)]
#align stream.wseq.nth_terminates_le Stream'.WSeq.get?_terminates_le
theorem head_terminates_of_get?_terminates {s : WSeq α} {n} :
Terminates (get? s n) → Terminates (head s) :=
get?_terminates_le (Nat.zero_le n)
#align stream.wseq.head_terminates_of_nth_terminates Stream'.WSeq.head_terminates_of_get?_terminates
theorem destruct_terminates_of_get?_terminates {s : WSeq α} {n} (T : Terminates (get? s n)) :
Terminates (destruct s) :=
(head_terminates_iff _).1 <| head_terminates_of_get?_terminates T
#align stream.wseq.destruct_terminates_of_nth_terminates Stream'.WSeq.destruct_terminates_of_get?_terminates
theorem mem_rec_on {C : WSeq α → Prop} {a s} (M : a ∈ s) (h1 : ∀ b s', a = b ∨ C s' → C (cons b s'))
(h2 : ∀ s, C s → C (think s)) : C s := by
apply Seq.mem_rec_on M
intro o s' h; cases' o with b
· apply h2
cases h
· contradiction
· assumption
· apply h1
apply Or.imp_left _ h
intro h
injection h
#align stream.wseq.mem_rec_on Stream'.WSeq.mem_rec_on
@[simp]
theorem mem_think (s : WSeq α) (a) : a ∈ think s ↔ a ∈ s := by
cases' s with f al
change (some (some a) ∈ some none::f) ↔ some (some a) ∈ f
constructor <;> intro h
· apply (Stream'.eq_or_mem_of_mem_cons h).resolve_left
intro
injections
· apply Stream'.mem_cons_of_mem _ h
#align stream.wseq.mem_think Stream'.WSeq.mem_think
theorem eq_or_mem_iff_mem {s : WSeq α} {a a' s'} :
some (a', s') ∈ destruct s → (a ∈ s ↔ a = a' ∨ a ∈ s') := by
generalize e : destruct s = c; intro h
revert s
apply Computation.memRecOn h <;> [skip; intro c IH] <;> intro s <;>
induction' s using WSeq.recOn with x s s <;>
intro m <;>
have := congr_arg Computation.destruct m <;>
simp at this
· cases' this with i1 i2
rw [i1, i2]
cases' s' with f al
dsimp only [cons, (· ∈ ·), WSeq.Mem, Seq.Mem, Seq.cons]
have h_a_eq_a' : a = a' ↔ some (some a) = some (some a') := by simp
rw [h_a_eq_a']
refine ⟨Stream'.eq_or_mem_of_mem_cons, fun o => ?_⟩
· cases' o with e m
· rw [e]
apply Stream'.mem_cons
· exact Stream'.mem_cons_of_mem _ m
· simp [IH this]
#align stream.wseq.eq_or_mem_iff_mem Stream'.WSeq.eq_or_mem_iff_mem
@[simp]
theorem mem_cons_iff (s : WSeq α) (b) {a} : a ∈ cons b s ↔ a = b ∨ a ∈ s :=
eq_or_mem_iff_mem <| by simp [ret_mem]
#align stream.wseq.mem_cons_iff Stream'.WSeq.mem_cons_iff
theorem mem_cons_of_mem {s : WSeq α} (b) {a} (h : a ∈ s) : a ∈ cons b s :=
(mem_cons_iff _ _).2 (Or.inr h)
#align stream.wseq.mem_cons_of_mem Stream'.WSeq.mem_cons_of_mem
theorem mem_cons (s : WSeq α) (a) : a ∈ cons a s :=
(mem_cons_iff _ _).2 (Or.inl rfl)
#align stream.wseq.mem_cons Stream'.WSeq.mem_cons
theorem mem_of_mem_tail {s : WSeq α} {a} : a ∈ tail s → a ∈ s := by
intro h; have := h; cases' h with n e; revert s; simp only [Stream'.get]
induction' n with n IH <;> intro s <;> induction' s using WSeq.recOn with x s s <;>
simp <;> intro m e <;>
injections
· exact Or.inr m
· exact Or.inr m
· apply IH m
rw [e]
cases tail s
rfl
#align stream.wseq.mem_of_mem_tail Stream'.WSeq.mem_of_mem_tail
theorem mem_of_mem_dropn {s : WSeq α} {a} : ∀ {n}, a ∈ drop s n → a ∈ s
| 0, h => h
| n + 1, h => @mem_of_mem_dropn s a n (mem_of_mem_tail h)
#align stream.wseq.mem_of_mem_dropn Stream'.WSeq.mem_of_mem_dropn
theorem get?_mem {s : WSeq α} {a n} : some a ∈ get? s n → a ∈ s := by
revert s; induction' n with n IH <;> intro s h
· -- Porting note: This line is required to infer metavariables in
-- `Computation.exists_of_mem_map`.
dsimp only [get?, head] at h
rcases Computation.exists_of_mem_map h with ⟨o, h1, h2⟩
cases' o with o
· injection h2
injection h2 with h'
cases' o with a' s'
exact (eq_or_mem_iff_mem h1).2 (Or.inl h'.symm)
· have := @IH (tail s)
rw [get?_tail] at this
exact mem_of_mem_tail (this h)
#align stream.wseq.nth_mem Stream'.WSeq.get?_mem
theorem exists_get?_of_mem {s : WSeq α} {a} (h : a ∈ s) : ∃ n, some a ∈ get? s n := by
apply mem_rec_on h
· intro a' s' h
cases' h with h h
· exists 0
simp only [get?, drop, head_cons]
rw [h]
apply ret_mem
· cases' h with n h
exists n + 1
-- porting note (#10745): was `simp [get?]`.
simpa [get?]
· intro s' h
cases' h with n h
exists n
simp only [get?, dropn_think, head_think]
apply think_mem h
#align stream.wseq.exists_nth_of_mem Stream'.WSeq.exists_get?_of_mem
theorem exists_dropn_of_mem {s : WSeq α} {a} (h : a ∈ s) :
∃ n s', some (a, s') ∈ destruct (drop s n) :=
let ⟨n, h⟩ := exists_get?_of_mem h
⟨n, by
rcases (head_terminates_iff _).1 ⟨⟨_, h⟩⟩ with ⟨⟨o, om⟩⟩
have := Computation.mem_unique (Computation.mem_map _ om) h
cases' o with o
· injection this
injection this with i
cases' o with a' s'
dsimp at i
rw [i] at om
exact ⟨_, om⟩⟩
#align stream.wseq.exists_dropn_of_mem Stream'.WSeq.exists_dropn_of_mem
theorem liftRel_dropn_destruct {R : α → β → Prop} {s t} (H : LiftRel R s t) :
∀ n, Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct (drop s n)) (destruct (drop t n))
| 0 => liftRel_destruct H
| n + 1 => by
simp only [LiftRelO, drop, Nat.add_eq, Nat.add_zero, destruct_tail, tail.aux]
apply liftRel_bind
· apply liftRel_dropn_destruct H n
exact fun {a b} o =>
match a, b, o with
| none, none, _ => by
-- Porting note: These 2 theorems should be excluded.
simp [-liftRel_pure_left, -liftRel_pure_right]
| some (a, s), some (b, t), ⟨_, h2⟩ => by simpa [tail.aux] using liftRel_destruct h2
#align stream.wseq.lift_rel_dropn_destruct Stream'.WSeq.liftRel_dropn_destruct
theorem exists_of_liftRel_left {R : α → β → Prop} {s t} (H : LiftRel R s t) {a} (h : a ∈ s) :
∃ b, b ∈ t ∧ R a b := by
let ⟨n, h⟩ := exists_get?_of_mem h
-- Porting note: This line is required to infer metavariables in
-- `Computation.exists_of_mem_map`.
dsimp only [get?, head] at h
let ⟨some (_, s'), sd, rfl⟩ := Computation.exists_of_mem_map h
let ⟨some (b, t'), td, ⟨ab, _⟩⟩ := (liftRel_dropn_destruct H n).left sd
exact ⟨b, get?_mem (Computation.mem_map (Prod.fst.{v, v} <$> ·) td), ab⟩
#align stream.wseq.exists_of_lift_rel_left Stream'.WSeq.exists_of_liftRel_left
theorem exists_of_liftRel_right {R : α → β → Prop} {s t} (H : LiftRel R s t) {b} (h : b ∈ t) :
∃ a, a ∈ s ∧ R a b := by rw [← LiftRel.swap] at H; exact exists_of_liftRel_left H h
#align stream.wseq.exists_of_lift_rel_right Stream'.WSeq.exists_of_liftRel_right
theorem head_terminates_of_mem {s : WSeq α} {a} (h : a ∈ s) : Terminates (head s) :=
let ⟨_, h⟩ := exists_get?_of_mem h
head_terminates_of_get?_terminates ⟨⟨_, h⟩⟩
#align stream.wseq.head_terminates_of_mem Stream'.WSeq.head_terminates_of_mem
theorem of_mem_append {s₁ s₂ : WSeq α} {a : α} : a ∈ append s₁ s₂ → a ∈ s₁ ∨ a ∈ s₂ :=
Seq.of_mem_append
#align stream.wseq.of_mem_append Stream'.WSeq.of_mem_append
theorem mem_append_left {s₁ s₂ : WSeq α} {a : α} : a ∈ s₁ → a ∈ append s₁ s₂ :=
Seq.mem_append_left
#align stream.wseq.mem_append_left Stream'.WSeq.mem_append_left
theorem exists_of_mem_map {f} {b : β} : ∀ {s : WSeq α}, b ∈ map f s → ∃ a, a ∈ s ∧ f a = b
| ⟨g, al⟩, h => by
let ⟨o, om, oe⟩ := Seq.exists_of_mem_map h
cases' o with a
· injection oe
injection oe with h'
exact ⟨a, om, h'⟩
#align stream.wseq.exists_of_mem_map Stream'.WSeq.exists_of_mem_map
@[simp]
theorem liftRel_nil (R : α → β → Prop) : LiftRel R nil nil := by
rw [liftRel_destruct_iff]
-- Porting note: These 2 theorems should be excluded.
simp [-liftRel_pure_left, -liftRel_pure_right]
#align stream.wseq.lift_rel_nil Stream'.WSeq.liftRel_nil
@[simp]
theorem liftRel_cons (R : α → β → Prop) (a b s t) :
LiftRel R (cons a s) (cons b t) ↔ R a b ∧ LiftRel R s t := by
rw [liftRel_destruct_iff]
-- Porting note: These 2 theorems should be excluded.
simp [-liftRel_pure_left, -liftRel_pure_right]
#align stream.wseq.lift_rel_cons Stream'.WSeq.liftRel_cons
@[simp]
theorem liftRel_think_left (R : α → β → Prop) (s t) : LiftRel R (think s) t ↔ LiftRel R s t := by
rw [liftRel_destruct_iff, liftRel_destruct_iff]; simp
#align stream.wseq.lift_rel_think_left Stream'.WSeq.liftRel_think_left
@[simp]
theorem liftRel_think_right (R : α → β → Prop) (s t) : LiftRel R s (think t) ↔ LiftRel R s t := by
rw [liftRel_destruct_iff, liftRel_destruct_iff]; simp
#align stream.wseq.lift_rel_think_right Stream'.WSeq.liftRel_think_right
theorem cons_congr {s t : WSeq α} (a : α) (h : s ~ʷ t) : cons a s ~ʷ cons a t := by
unfold Equiv; simpa using h
#align stream.wseq.cons_congr Stream'.WSeq.cons_congr
theorem think_equiv (s : WSeq α) : think s ~ʷ s := by unfold Equiv; simpa using Equiv.refl _
#align stream.wseq.think_equiv Stream'.WSeq.think_equiv
theorem think_congr {s t : WSeq α} (h : s ~ʷ t) : think s ~ʷ think t := by
unfold Equiv; simpa using h
#align stream.wseq.think_congr Stream'.WSeq.think_congr
theorem head_congr : ∀ {s t : WSeq α}, s ~ʷ t → head s ~ head t := by
suffices ∀ {s t : WSeq α}, s ~ʷ t → ∀ {o}, o ∈ head s → o ∈ head t from fun s t h o =>
⟨this h, this h.symm⟩
intro s t h o ho
rcases @Computation.exists_of_mem_map _ _ _ _ (destruct s) ho with ⟨ds, dsm, dse⟩
rw [← dse]
cases' destruct_congr h with l r
rcases l dsm with ⟨dt, dtm, dst⟩
cases' ds with a <;> cases' dt with b
· apply Computation.mem_map _ dtm
· cases b
cases dst
· cases a
cases dst
· cases' a with a s'
cases' b with b t'
rw [dst.left]
exact @Computation.mem_map _ _ (@Functor.map _ _ (α × WSeq α) _ Prod.fst)
(some (b, t')) (destruct t) dtm
#align stream.wseq.head_congr Stream'.WSeq.head_congr
theorem flatten_equiv {c : Computation (WSeq α)} {s} (h : s ∈ c) : flatten c ~ʷ s := by
apply Computation.memRecOn h
· simp [Equiv.refl]
· intro s'
apply Equiv.trans
simp [think_equiv]
#align stream.wseq.flatten_equiv Stream'.WSeq.flatten_equiv
theorem liftRel_flatten {R : α → β → Prop} {c1 : Computation (WSeq α)} {c2 : Computation (WSeq β)}
(h : c1.LiftRel (LiftRel R) c2) : LiftRel R (flatten c1) (flatten c2) :=
let S s t := ∃ c1 c2, s = flatten c1 ∧ t = flatten c2 ∧ Computation.LiftRel (LiftRel R) c1 c2
⟨S, ⟨c1, c2, rfl, rfl, h⟩, fun {s t} h =>
match s, t, h with
| _, _, ⟨c1, c2, rfl, rfl, h⟩ => by
simp only [destruct_flatten]; apply liftRel_bind _ _ h
intro a b ab; apply Computation.LiftRel.imp _ _ _ (liftRel_destruct ab)
intro a b; apply LiftRelO.imp_right
intro s t h; refine ⟨Computation.pure s, Computation.pure t, ?_, ?_, ?_⟩ <;>
-- Porting note: These 2 theorems should be excluded.
simp [h, -liftRel_pure_left, -liftRel_pure_right]⟩
#align stream.wseq.lift_rel_flatten Stream'.WSeq.liftRel_flatten
theorem flatten_congr {c1 c2 : Computation (WSeq α)} :
Computation.LiftRel Equiv c1 c2 → flatten c1 ~ʷ flatten c2 :=
liftRel_flatten
#align stream.wseq.flatten_congr Stream'.WSeq.flatten_congr
theorem tail_congr {s t : WSeq α} (h : s ~ʷ t) : tail s ~ʷ tail t := by
apply flatten_congr
dsimp only [(· <$> ·)]; rw [← Computation.bind_pure, ← Computation.bind_pure]
apply liftRel_bind _ _ (destruct_congr h)
intro a b h; simp only [comp_apply, liftRel_pure]
cases' a with a <;> cases' b with b
· trivial
· cases h
· cases a
cases h
· cases' a with a s'
cases' b with b t'
exact h.right
#align stream.wseq.tail_congr Stream'.WSeq.tail_congr
theorem dropn_congr {s t : WSeq α} (h : s ~ʷ t) (n) : drop s n ~ʷ drop t n := by
induction n <;> simp [*, tail_congr, drop]
#align stream.wseq.dropn_congr Stream'.WSeq.dropn_congr
theorem get?_congr {s t : WSeq α} (h : s ~ʷ t) (n) : get? s n ~ get? t n :=
head_congr (dropn_congr h _)
#align stream.wseq.nth_congr Stream'.WSeq.get?_congr
theorem mem_congr {s t : WSeq α} (h : s ~ʷ t) (a) : a ∈ s ↔ a ∈ t :=
suffices ∀ {s t : WSeq α}, s ~ʷ t → a ∈ s → a ∈ t from ⟨this h, this h.symm⟩
fun {_ _} h as =>
let ⟨_, hn⟩ := exists_get?_of_mem as
get?_mem ((get?_congr h _ _).1 hn)
#align stream.wseq.mem_congr Stream'.WSeq.mem_congr
theorem productive_congr {s t : WSeq α} (h : s ~ʷ t) : Productive s ↔ Productive t := by
simp only [productive_iff]; exact forall_congr' fun n => terminates_congr <| get?_congr h _
#align stream.wseq.productive_congr Stream'.WSeq.productive_congr
theorem Equiv.ext {s t : WSeq α} (h : ∀ n, get? s n ~ get? t n) : s ~ʷ t :=
⟨fun s t => ∀ n, get? s n ~ get? t n, h, fun {s t} h => by
refine liftRel_def.2 ⟨?_, ?_⟩
· rw [← head_terminates_iff, ← head_terminates_iff]
exact terminates_congr (h 0)
· intro a b ma mb
cases' a with a <;> cases' b with b
· trivial
· injection mem_unique (Computation.mem_map _ ma) ((h 0 _).2 (Computation.mem_map _ mb))
· injection mem_unique (Computation.mem_map _ ma) ((h 0 _).2 (Computation.mem_map _ mb))
· cases' a with a s'
cases' b with b t'
injection mem_unique (Computation.mem_map _ ma) ((h 0 _).2 (Computation.mem_map _ mb)) with
ab
refine ⟨ab, fun n => ?_⟩
refine
(get?_congr (flatten_equiv (Computation.mem_map _ ma)) n).symm.trans
((?_ : get? (tail s) n ~ get? (tail t) n).trans
(get?_congr (flatten_equiv (Computation.mem_map _ mb)) n))
rw [get?_tail, get?_tail]
apply h⟩
#align stream.wseq.equiv.ext Stream'.WSeq.Equiv.ext
theorem length_eq_map (s : WSeq α) : length s = Computation.map List.length (toList s) := by
refine
Computation.eq_of_bisim
(fun c1 c2 =>
∃ (l : List α) (s : WSeq α),
c1 = Computation.corec (fun ⟨n, s⟩ =>
match Seq.destruct s with
| none => Sum.inl n
| some (none, s') => Sum.inr (n, s')
| some (some _, s') => Sum.inr (n + 1, s')) (l.length, s) ∧
c2 = Computation.map List.length (Computation.corec (fun ⟨l, s⟩ =>
match Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a::l, s')) (l, s)))
?_ ⟨[], s, rfl, rfl⟩
intro s1 s2 h; rcases h with ⟨l, s, h⟩; rw [h.left, h.right]
induction' s using WSeq.recOn with a s s <;> simp [toList, nil, cons, think, length]
· refine ⟨a::l, s, ?_, ?_⟩ <;> simp
· refine ⟨l, s, ?_, ?_⟩ <;> simp
#align stream.wseq.length_eq_map Stream'.WSeq.length_eq_map
@[simp]
theorem ofList_nil : ofList [] = (nil : WSeq α) :=
rfl
#align stream.wseq.of_list_nil Stream'.WSeq.ofList_nil
@[simp]
theorem ofList_cons (a : α) (l) : ofList (a::l) = cons a (ofList l) :=
show Seq.map some (Seq.ofList (a::l)) = Seq.cons (some a) (Seq.map some (Seq.ofList l)) by simp
#align stream.wseq.of_list_cons Stream'.WSeq.ofList_cons
@[simp]
theorem toList'_nil (l : List α) :
Computation.corec (fun ⟨l, s⟩ =>
match Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a::l, s')) (l, nil) = Computation.pure l.reverse :=
destruct_eq_pure rfl
#align stream.wseq.to_list'_nil Stream'.WSeq.toList'_nil
@[simp]
theorem toList'_cons (l : List α) (s : WSeq α) (a : α) :
Computation.corec (fun ⟨l, s⟩ =>
match Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a::l, s')) (l, cons a s) =
(Computation.corec (fun ⟨l, s⟩ =>
match Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a::l, s')) (a::l, s)).think :=
destruct_eq_think <| by simp [toList, cons]
#align stream.wseq.to_list'_cons Stream'.WSeq.toList'_cons
@[simp]
theorem toList'_think (l : List α) (s : WSeq α) :
Computation.corec (fun ⟨l, s⟩ =>
match Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a::l, s')) (l, think s) =
(Computation.corec (fun ⟨l, s⟩ =>
match Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a::l, s')) (l, s)).think :=
destruct_eq_think <| by simp [toList, think]
#align stream.wseq.to_list'_think Stream'.WSeq.toList'_think
theorem toList'_map (l : List α) (s : WSeq α) :
Computation.corec (fun ⟨l, s⟩ =>
match Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a :: l, s')) (l, s) = (l.reverse ++ ·) <$> toList s := by
refine
Computation.eq_of_bisim
(fun c1 c2 =>
∃ (l' : List α) (s : WSeq α),
c1 = Computation.corec (fun ⟨l, s⟩ =>
match Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a::l, s')) (l' ++ l, s) ∧
c2 = Computation.map (l.reverse ++ ·) (Computation.corec (fun ⟨l, s⟩ =>
match Seq.destruct s with
| none => Sum.inl l.reverse
| some (none, s') => Sum.inr (l, s')
| some (some a, s') => Sum.inr (a::l, s')) (l', s)))
?_ ⟨[], s, rfl, rfl⟩
intro s1 s2 h; rcases h with ⟨l', s, h⟩; rw [h.left, h.right]
induction' s using WSeq.recOn with a s s <;> simp [toList, nil, cons, think, length]
· refine ⟨a::l', s, ?_, ?_⟩ <;> simp
· refine ⟨l', s, ?_, ?_⟩ <;> simp
#align stream.wseq.to_list'_map Stream'.WSeq.toList'_map
@[simp]
theorem toList_cons (a : α) (s) : toList (cons a s) = (List.cons a <$> toList s).think :=
destruct_eq_think <| by
unfold toList
simp only [toList'_cons, Computation.destruct_think, Sum.inr.injEq]
rw [toList'_map]
simp only [List.reverse_cons, List.reverse_nil, List.nil_append, List.singleton_append]
rfl
#align stream.wseq.to_list_cons Stream'.WSeq.toList_cons
@[simp]
theorem toList_nil : toList (nil : WSeq α) = Computation.pure [] :=
destruct_eq_pure rfl
#align stream.wseq.to_list_nil Stream'.WSeq.toList_nil
theorem toList_ofList (l : List α) : l ∈ toList (ofList l) := by
induction' l with a l IH <;> simp [ret_mem]; exact think_mem (Computation.mem_map _ IH)
#align stream.wseq.to_list_of_list Stream'.WSeq.toList_ofList
@[simp]
theorem destruct_ofSeq (s : Seq α) :
destruct (ofSeq s) = Computation.pure (s.head.map fun a => (a, ofSeq s.tail)) :=
destruct_eq_pure <| by
simp only [destruct, Seq.destruct, Option.map_eq_map, ofSeq, Computation.corec_eq, rmap,
Seq.head]
rw [show Seq.get? (some <$> s) 0 = some <$> Seq.get? s 0 by apply Seq.map_get?]
cases' Seq.get? s 0 with a
· rfl
dsimp only [(· <$> ·)]
simp [destruct]
#align stream.wseq.destruct_of_seq Stream'.WSeq.destruct_ofSeq
@[simp]
theorem head_ofSeq (s : Seq α) : head (ofSeq s) = Computation.pure s.head := by
simp only [head, Option.map_eq_map, destruct_ofSeq, Computation.map_pure, Option.map_map]
cases Seq.head s <;> rfl
#align stream.wseq.head_of_seq Stream'.WSeq.head_ofSeq
@[simp]
theorem tail_ofSeq (s : Seq α) : tail (ofSeq s) = ofSeq s.tail := by
simp only [tail, destruct_ofSeq, map_pure', flatten_pure]
induction' s using Seq.recOn with x s <;> simp only [ofSeq, Seq.tail_nil, Seq.head_nil,
Option.map_none', Seq.tail_cons, Seq.head_cons, Option.map_some']
· rfl
#align stream.wseq.tail_of_seq Stream'.WSeq.tail_ofSeq
@[simp]
theorem dropn_ofSeq (s : Seq α) : ∀ n, drop (ofSeq s) n = ofSeq (s.drop n)
| 0 => rfl
| n + 1 => by
simp only [drop, Nat.add_eq, Nat.add_zero, Seq.drop]
rw [dropn_ofSeq s n, tail_ofSeq]
#align stream.wseq.dropn_of_seq Stream'.WSeq.dropn_ofSeq
theorem get?_ofSeq (s : Seq α) (n) : get? (ofSeq s) n = Computation.pure (Seq.get? s n) := by
dsimp [get?]; rw [dropn_ofSeq, head_ofSeq, Seq.head_dropn]
#align stream.wseq.nth_of_seq Stream'.WSeq.get?_ofSeq
instance productive_ofSeq (s : Seq α) : Productive (ofSeq s) :=
⟨fun n => by rw [get?_ofSeq]; infer_instance⟩
#align stream.wseq.productive_of_seq Stream'.WSeq.productive_ofSeq
| Mathlib/Data/Seq/WSeq.lean | 1,392 | 1,395 | theorem toSeq_ofSeq (s : Seq α) : toSeq (ofSeq s) = s := by |
apply Subtype.eq; funext n
dsimp [toSeq]; apply get_eq_of_mem
rw [get?_ofSeq]; apply ret_mem
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Eric Wieser
-/
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.SesquilinearForm
import Mathlib.LinearAlgebra.Matrix.Symmetric
#align_import linear_algebra.quadratic_form.basic from "leanprover-community/mathlib"@"d11f435d4e34a6cea0a1797d6b625b0c170be845"
/-!
# Quadratic forms
This file defines quadratic forms over a `R`-module `M`.
A quadratic form on a commutative ring `R` is a map `Q : M → R` such that:
* `QuadraticForm.map_smul`: `Q (a • x) = a * a * Q x`
* `QuadraticForm.polar_add_left`, `QuadraticForm.polar_add_right`,
`QuadraticForm.polar_smul_left`, `QuadraticForm.polar_smul_right`:
the map `QuadraticForm.polar Q := fun x y ↦ Q (x + y) - Q x - Q y` is bilinear.
This notion generalizes to commutative semirings using the approach in [izhakian2016][] which
requires that there be a (possibly non-unique) companion bilinear form `B` such that
`∀ x y, Q (x + y) = Q x + Q y + B x y`. Over a ring, this `B` is precisely `QuadraticForm.polar Q`.
To build a `QuadraticForm` from the `polar` axioms, use `QuadraticForm.ofPolar`.
Quadratic forms come with a scalar multiplication, `(a • Q) x = Q (a • x) = a * a * Q x`,
and composition with linear maps `f`, `Q.comp f x = Q (f x)`.
## Main definitions
* `QuadraticForm.ofPolar`: a more familiar constructor that works on rings
* `QuadraticForm.associated`: associated bilinear form
* `QuadraticForm.PosDef`: positive definite quadratic forms
* `QuadraticForm.Anisotropic`: anisotropic quadratic forms
* `QuadraticForm.discr`: discriminant of a quadratic form
* `QuadraticForm.IsOrtho`: orthogonality of vectors with respect to a quadratic form.
## Main statements
* `QuadraticForm.associated_left_inverse`,
* `QuadraticForm.associated_rightInverse`: in a commutative ring where 2 has
an inverse, there is a correspondence between quadratic forms and symmetric
bilinear forms
* `LinearMap.BilinForm.exists_orthogonal_basis`: There exists an orthogonal basis with
respect to any nondegenerate, symmetric bilinear form `B`.
## Notation
In this file, the variable `R` is used when a `CommSemiring` structure is available.
The variable `S` is used when `R` itself has a `•` action.
## Implementation notes
While the definition and many results make sense if we drop commutativity assumptions,
the correct definition of a quadratic form in the noncommutative setting would require
substantial refactors from the current version, such that $Q(rm) = rQ(m)r^*$ for some
suitable conjugation $r^*$.
The [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Quadratic.20Maps/near/395529867)
has some further discusion.
## References
* https://en.wikipedia.org/wiki/Quadratic_form
* https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms
## Tags
quadratic form, homogeneous polynomial, quadratic polynomial
-/
universe u v w
variable {S T : Type*}
variable {R : Type*} {M N : Type*}
open LinearMap (BilinForm)
section Polar
variable [CommRing R] [AddCommGroup M]
namespace QuadraticForm
/-- Up to a factor 2, `Q.polar` is the associated bilinear form for a quadratic form `Q`.
Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization
-/
def polar (f : M → R) (x y : M) :=
f (x + y) - f x - f y
#align quadratic_form.polar QuadraticForm.polar
theorem polar_add (f g : M → R) (x y : M) : polar (f + g) x y = polar f x y + polar g x y := by
simp only [polar, Pi.add_apply]
abel
#align quadratic_form.polar_add QuadraticForm.polar_add
theorem polar_neg (f : M → R) (x y : M) : polar (-f) x y = -polar f x y := by
simp only [polar, Pi.neg_apply, sub_eq_add_neg, neg_add]
#align quadratic_form.polar_neg QuadraticForm.polar_neg
theorem polar_smul [Monoid S] [DistribMulAction S R] (f : M → R) (s : S) (x y : M) :
polar (s • f) x y = s • polar f x y := by simp only [polar, Pi.smul_apply, smul_sub]
#align quadratic_form.polar_smul QuadraticForm.polar_smul
theorem polar_comm (f : M → R) (x y : M) : polar f x y = polar f y x := by
rw [polar, polar, add_comm, sub_sub, sub_sub, add_comm (f x) (f y)]
#align quadratic_form.polar_comm QuadraticForm.polar_comm
/-- Auxiliary lemma to express bilinearity of `QuadraticForm.polar` without subtraction. -/
theorem polar_add_left_iff {f : M → R} {x x' y : M} :
polar f (x + x') y = polar f x y + polar f x' y ↔
f (x + x' + y) + (f x + f x' + f y) = f (x + x') + f (x' + y) + f (y + x) := by
simp only [← add_assoc]
simp only [polar, sub_eq_iff_eq_add, eq_sub_iff_add_eq, sub_add_eq_add_sub, add_sub]
simp only [add_right_comm _ (f y) _, add_right_comm _ (f x') (f x)]
rw [add_comm y x, add_right_comm _ _ (f (x + y)), add_comm _ (f (x + y)),
add_right_comm (f (x + y)), add_left_inj]
#align quadratic_form.polar_add_left_iff QuadraticForm.polar_add_left_iff
theorem polar_comp {F : Type*} [CommRing S] [FunLike F R S] [AddMonoidHomClass F R S]
(f : M → R) (g : F) (x y : M) :
polar (g ∘ f) x y = g (polar f x y) := by
simp only [polar, Pi.smul_apply, Function.comp_apply, map_sub]
#align quadratic_form.polar_comp QuadraticForm.polar_comp
end QuadraticForm
end Polar
/-- A quadratic form over a module.
For a more familiar constructor when `R` is a ring, see `QuadraticForm.ofPolar`. -/
structure QuadraticForm (R : Type u) (M : Type v)
[CommSemiring R] [AddCommMonoid M] [Module R M] where
toFun : M → R
toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = a * a * toFun x
exists_companion' :
∃ B : BilinForm R M, ∀ x y, toFun (x + y) = toFun x + toFun y + B x y
#align quadratic_form QuadraticForm
namespace QuadraticForm
section DFunLike
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
variable {Q Q' : QuadraticForm R M}
instance instFunLike : FunLike (QuadraticForm R M) M R where
coe := toFun
coe_injective' x y h := by cases x; cases y; congr
#align quadratic_form.fun_like QuadraticForm.instFunLike
/-- Helper instance for when there's too many metavariables to apply
`DFunLike.hasCoeToFun` directly. -/
instance : CoeFun (QuadraticForm R M) fun _ => M → R :=
⟨DFunLike.coe⟩
variable (Q)
/-- The `simp` normal form for a quadratic form is `DFunLike.coe`, not `toFun`. -/
@[simp]
theorem toFun_eq_coe : Q.toFun = ⇑Q :=
rfl
#align quadratic_form.to_fun_eq_coe QuadraticForm.toFun_eq_coe
-- this must come after the coe_to_fun definition
initialize_simps_projections QuadraticForm (toFun → apply)
variable {Q}
@[ext]
theorem ext (H : ∀ x : M, Q x = Q' x) : Q = Q' :=
DFunLike.ext _ _ H
#align quadratic_form.ext QuadraticForm.ext
theorem congr_fun (h : Q = Q') (x : M) : Q x = Q' x :=
DFunLike.congr_fun h _
#align quadratic_form.congr_fun QuadraticForm.congr_fun
theorem ext_iff : Q = Q' ↔ ∀ x, Q x = Q' x :=
DFunLike.ext_iff
#align quadratic_form.ext_iff QuadraticForm.ext_iff
/-- Copy of a `QuadraticForm` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (Q : QuadraticForm R M) (Q' : M → R) (h : Q' = ⇑Q) : QuadraticForm R M where
toFun := Q'
toFun_smul := h.symm ▸ Q.toFun_smul
exists_companion' := h.symm ▸ Q.exists_companion'
#align quadratic_form.copy QuadraticForm.copy
@[simp]
theorem coe_copy (Q : QuadraticForm R M) (Q' : M → R) (h : Q' = ⇑Q) : ⇑(Q.copy Q' h) = Q' :=
rfl
#align quadratic_form.coe_copy QuadraticForm.coe_copy
theorem copy_eq (Q : QuadraticForm R M) (Q' : M → R) (h : Q' = ⇑Q) : Q.copy Q' h = Q :=
DFunLike.ext' h
#align quadratic_form.copy_eq QuadraticForm.copy_eq
end DFunLike
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
variable (Q : QuadraticForm R M)
theorem map_smul (a : R) (x : M) : Q (a • x) = a * a * Q x :=
Q.toFun_smul a x
#align quadratic_form.map_smul QuadraticForm.map_smul
theorem exists_companion : ∃ B : BilinForm R M, ∀ x y, Q (x + y) = Q x + Q y + B x y :=
Q.exists_companion'
#align quadratic_form.exists_companion QuadraticForm.exists_companion
theorem map_add_add_add_map (x y z : M) :
Q (x + y + z) + (Q x + Q y + Q z) = Q (x + y) + Q (y + z) + Q (z + x) := by
obtain ⟨B, h⟩ := Q.exists_companion
rw [add_comm z x]
simp only [h, map_add, LinearMap.add_apply]
abel
#align quadratic_form.map_add_add_add_map QuadraticForm.map_add_add_add_map
theorem map_add_self (x : M) : Q (x + x) = 4 * Q x := by
rw [← one_smul R x, ← add_smul, map_smul]
norm_num
#align quadratic_form.map_add_self QuadraticForm.map_add_self
-- Porting note: removed @[simp] because it is superseded by `ZeroHomClass.map_zero`
theorem map_zero : Q 0 = 0 := by
rw [← @zero_smul R _ _ _ _ (0 : M), map_smul, zero_mul, zero_mul]
#align quadratic_form.map_zero QuadraticForm.map_zero
instance zeroHomClass : ZeroHomClass (QuadraticForm R M) M R where
map_zero := map_zero
#align quadratic_form.zero_hom_class QuadraticForm.zeroHomClass
theorem map_smul_of_tower [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] (a : S)
(x : M) : Q (a • x) = (a * a) • Q x := by
rw [← IsScalarTower.algebraMap_smul R a x, map_smul, ← RingHom.map_mul, Algebra.smul_def]
#align quadratic_form.map_smul_of_tower QuadraticForm.map_smul_of_tower
end CommSemiring
section CommRing
variable [CommRing R] [AddCommGroup M]
variable [Module R M] (Q : QuadraticForm R M)
@[simp]
theorem map_neg (x : M) : Q (-x) = Q x := by
rw [← @neg_one_smul R _ _ _ _ x, map_smul, neg_one_mul, neg_neg, one_mul]
#align quadratic_form.map_neg QuadraticForm.map_neg
theorem map_sub (x y : M) : Q (x - y) = Q (y - x) := by rw [← neg_sub, map_neg]
#align quadratic_form.map_sub QuadraticForm.map_sub
@[simp]
theorem polar_zero_left (y : M) : polar Q 0 y = 0 := by
simp only [polar, zero_add, QuadraticForm.map_zero, sub_zero, sub_self]
#align quadratic_form.polar_zero_left QuadraticForm.polar_zero_left
@[simp]
theorem polar_add_left (x x' y : M) : polar Q (x + x') y = polar Q x y + polar Q x' y :=
polar_add_left_iff.mpr <| Q.map_add_add_add_map x x' y
#align quadratic_form.polar_add_left QuadraticForm.polar_add_left
@[simp]
theorem polar_smul_left (a : R) (x y : M) : polar Q (a • x) y = a * polar Q x y := by
obtain ⟨B, h⟩ := Q.exists_companion
simp_rw [polar, h, Q.map_smul, LinearMap.map_smul₂, sub_sub, add_sub_cancel_left, smul_eq_mul]
#align quadratic_form.polar_smul_left QuadraticForm.polar_smul_left
@[simp]
theorem polar_neg_left (x y : M) : polar Q (-x) y = -polar Q x y := by
rw [← neg_one_smul R x, polar_smul_left, neg_one_mul]
#align quadratic_form.polar_neg_left QuadraticForm.polar_neg_left
@[simp]
theorem polar_sub_left (x x' y : M) : polar Q (x - x') y = polar Q x y - polar Q x' y := by
rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_left, polar_neg_left]
#align quadratic_form.polar_sub_left QuadraticForm.polar_sub_left
@[simp]
theorem polar_zero_right (y : M) : polar Q y 0 = 0 := by
simp only [add_zero, polar, QuadraticForm.map_zero, sub_self]
#align quadratic_form.polar_zero_right QuadraticForm.polar_zero_right
@[simp]
theorem polar_add_right (x y y' : M) : polar Q x (y + y') = polar Q x y + polar Q x y' := by
rw [polar_comm Q x, polar_comm Q x, polar_comm Q x, polar_add_left]
#align quadratic_form.polar_add_right QuadraticForm.polar_add_right
@[simp]
theorem polar_smul_right (a : R) (x y : M) : polar Q x (a • y) = a * polar Q x y := by
rw [polar_comm Q x, polar_comm Q x, polar_smul_left]
#align quadratic_form.polar_smul_right QuadraticForm.polar_smul_right
@[simp]
theorem polar_neg_right (x y : M) : polar Q x (-y) = -polar Q x y := by
rw [← neg_one_smul R y, polar_smul_right, neg_one_mul]
#align quadratic_form.polar_neg_right QuadraticForm.polar_neg_right
@[simp]
theorem polar_sub_right (x y y' : M) : polar Q x (y - y') = polar Q x y - polar Q x y' := by
rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_right, polar_neg_right]
#align quadratic_form.polar_sub_right QuadraticForm.polar_sub_right
@[simp]
| Mathlib/LinearAlgebra/QuadraticForm/Basic.lean | 316 | 318 | theorem polar_self (x : M) : polar Q x x = 2 * Q x := by |
rw [polar, map_add_self, sub_sub, sub_eq_iff_eq_add, ← two_mul, ← two_mul, ← mul_assoc]
norm_num
|
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Covering.VitaliFamily
import Mathlib.MeasureTheory.Measure.Regular
import Mathlib.MeasureTheory.Function.AEMeasurableOrder
import Mathlib.MeasureTheory.Integral.Lebesgue
import Mathlib.MeasureTheory.Integral.Average
import Mathlib.MeasureTheory.Decomposition.Lebesgue
#align_import measure_theory.covering.differentiation from "leanprover-community/mathlib"@"57ac39bd365c2f80589a700f9fbb664d3a1a30c2"
/-!
# Differentiation of measures
On a second countable metric space with a measure `μ`, consider a Vitali family (i.e., for each `x`
one has a family of sets shrinking to `x`, with a good behavior with respect to covering theorems).
Consider also another measure `ρ`. Then, for almost every `x`, the ratio `ρ a / μ a` converges when
`a` shrinks to `x` along the Vitali family, towards the Radon-Nikodym derivative of `ρ` with
respect to `μ`. This is the main theorem on differentiation of measures.
This theorem is proved in this file, under the name `VitaliFamily.ae_tendsto_rnDeriv`. Note that,
almost surely, `μ a` is eventually positive and finite (see
`VitaliFamily.ae_eventually_measure_pos` and `VitaliFamily.eventually_measure_lt_top`), so the
ratio really makes sense.
For concrete applications, one needs concrete instances of Vitali families, as provided for instance
by `Besicovitch.vitaliFamily` (for balls) or by `Vitali.vitaliFamily` (for doubling measures).
Specific applications to Lebesgue density points and the Lebesgue differentiation theorem are also
derived:
* `VitaliFamily.ae_tendsto_measure_inter_div` states that, for almost every point `x ∈ s`,
then `μ (s ∩ a) / μ a` tends to `1` as `a` shrinks to `x` along a Vitali family.
* `VitaliFamily.ae_tendsto_average_norm_sub` states that, for almost every point `x`, then the
average of `y ↦ ‖f y - f x‖` on `a` tends to `0` as `a` shrinks to `x` along a Vitali family.
## Sketch of proof
Let `v` be a Vitali family for `μ`. Assume for simplicity that `ρ` is absolutely continuous with
respect to `μ`, as the case of a singular measure is easier.
It is easy to see that a set `s` on which `liminf ρ a / μ a < q` satisfies `ρ s ≤ q * μ s`, by using
a disjoint subcovering provided by the definition of Vitali families. Similarly for the limsup.
It follows that a set on which `ρ a / μ a` oscillates has measure `0`, and therefore that
`ρ a / μ a` converges almost surely (`VitaliFamily.ae_tendsto_div`). Moreover, on a set where the
limit is close to a constant `c`, one gets `ρ s ∼ c μ s`, using again a covering lemma as above.
It follows that `ρ` is equal to `μ.withDensity (v.limRatio ρ x)`, where `v.limRatio ρ x` is the
limit of `ρ a / μ a` at `x` (which is well defined almost everywhere). By uniqueness of the
Radon-Nikodym derivative, one gets `v.limRatio ρ x = ρ.rnDeriv μ x` almost everywhere, completing
the proof.
There is a difficulty in this sketch: this argument works well when `v.limRatio ρ` is measurable,
but there is no guarantee that this is the case, especially if one doesn't make further assumptions
on the Vitali family. We use an indirect argument to show that `v.limRatio ρ` is always
almost everywhere measurable, again based on the disjoint subcovering argument
(see `VitaliFamily.exists_measurable_supersets_limRatio`), and then proceed as sketched above
but replacing `v.limRatio ρ` by a measurable version called `v.limRatioMeas ρ`.
## Counterexample
The standing assumption in this file is that spaces are second countable. Without this assumption,
measures may be zero locally but nonzero globally, which is not compatible with differentiation
theory (which deduces global information from local one). Here is an example displaying this
behavior.
Define a measure `μ` by `μ s = 0` if `s` is covered by countably many balls of radius `1`,
and `μ s = ∞` otherwise. This is indeed a countably additive measure, which is moreover
locally finite and doubling at small scales. It vanishes on every ball of radius `1`, so all the
quantities in differentiation theory (defined as ratios of measures as the radius tends to zero)
make no sense. However, the measure is not globally zero if the space is big enough.
## References
* [Herbert Federer, Geometric Measure Theory, Chapter 2.9][Federer1996]
-/
open MeasureTheory Metric Set Filter TopologicalSpace MeasureTheory.Measure
open scoped Filter ENNReal MeasureTheory NNReal Topology
variable {α : Type*} [MetricSpace α] {m0 : MeasurableSpace α} {μ : Measure α} (v : VitaliFamily μ)
{E : Type*} [NormedAddCommGroup E]
namespace VitaliFamily
/-- The limit along a Vitali family of `ρ a / μ a` where it makes sense, and garbage otherwise.
Do *not* use this definition: it is only a temporary device to show that this ratio tends almost
everywhere to the Radon-Nikodym derivative. -/
noncomputable def limRatio (ρ : Measure α) (x : α) : ℝ≥0∞ :=
limUnder (v.filterAt x) fun a => ρ a / μ a
#align vitali_family.lim_ratio VitaliFamily.limRatio
/-- For almost every point `x`, sufficiently small sets in a Vitali family around `x` have positive
measure. (This is a nontrivial result, following from the covering property of Vitali families). -/
theorem ae_eventually_measure_pos [SecondCountableTopology α] :
∀ᵐ x ∂μ, ∀ᶠ a in v.filterAt x, 0 < μ a := by
set s := {x | ¬∀ᶠ a in v.filterAt x, 0 < μ a} with hs
simp (config := { zeta := false }) only [not_lt, not_eventually, nonpos_iff_eq_zero] at hs
change μ s = 0
let f : α → Set (Set α) := fun _ => {a | μ a = 0}
have h : v.FineSubfamilyOn f s := by
intro x hx ε εpos
rw [hs] at hx
simp only [frequently_filterAt_iff, exists_prop, gt_iff_lt, mem_setOf_eq] at hx
rcases hx ε εpos with ⟨a, a_sets, ax, μa⟩
exact ⟨a, ⟨a_sets, μa⟩, ax⟩
refine le_antisymm ?_ bot_le
calc
μ s ≤ ∑' x : h.index, μ (h.covering x) := h.measure_le_tsum
_ = ∑' x : h.index, 0 := by congr; ext1 x; exact h.covering_mem x.2
_ = 0 := by simp only [tsum_zero, add_zero]
#align vitali_family.ae_eventually_measure_pos VitaliFamily.ae_eventually_measure_pos
/-- For every point `x`, sufficiently small sets in a Vitali family around `x` have finite measure.
(This is a trivial result, following from the fact that the measure is locally finite). -/
theorem eventually_measure_lt_top [IsLocallyFiniteMeasure μ] (x : α) :
∀ᶠ a in v.filterAt x, μ a < ∞ :=
(μ.finiteAt_nhds x).eventually.filter_mono inf_le_left
#align vitali_family.eventually_measure_lt_top VitaliFamily.eventually_measure_lt_top
/-- If two measures `ρ` and `ν` have, at every point of a set `s`, arbitrarily small sets in a
Vitali family satisfying `ρ a ≤ ν a`, then `ρ s ≤ ν s` if `ρ ≪ μ`. -/
theorem measure_le_of_frequently_le [SecondCountableTopology α] [BorelSpace α] {ρ : Measure α}
(ν : Measure α) [IsLocallyFiniteMeasure ν] (hρ : ρ ≪ μ) (s : Set α)
(hs : ∀ x ∈ s, ∃ᶠ a in v.filterAt x, ρ a ≤ ν a) : ρ s ≤ ν s := by
-- this follows from a covering argument using the sets satisfying `ρ a ≤ ν a`.
apply ENNReal.le_of_forall_pos_le_add fun ε εpos _ => ?_
obtain ⟨U, sU, U_open, νU⟩ : ∃ (U : Set α), s ⊆ U ∧ IsOpen U ∧ ν U ≤ ν s + ε :=
exists_isOpen_le_add s ν (ENNReal.coe_pos.2 εpos).ne'
let f : α → Set (Set α) := fun _ => {a | ρ a ≤ ν a ∧ a ⊆ U}
have h : v.FineSubfamilyOn f s := by
apply v.fineSubfamilyOn_of_frequently f s fun x hx => ?_
have :=
(hs x hx).and_eventually
((v.eventually_filterAt_mem_setsAt x).and
(v.eventually_filterAt_subset_of_nhds (U_open.mem_nhds (sU hx))))
apply Frequently.mono this
rintro a ⟨ρa, _, aU⟩
exact ⟨ρa, aU⟩
haveI : Encodable h.index := h.index_countable.toEncodable
calc
ρ s ≤ ∑' x : h.index, ρ (h.covering x) := h.measure_le_tsum_of_absolutelyContinuous hρ
_ ≤ ∑' x : h.index, ν (h.covering x) := ENNReal.tsum_le_tsum fun x => (h.covering_mem x.2).1
_ = ν (⋃ x : h.index, h.covering x) := by
rw [measure_iUnion h.covering_disjoint_subtype fun i => h.measurableSet_u i.2]
_ ≤ ν U := (measure_mono (iUnion_subset fun i => (h.covering_mem i.2).2))
_ ≤ ν s + ε := νU
#align vitali_family.measure_le_of_frequently_le VitaliFamily.measure_le_of_frequently_le
section
variable [SecondCountableTopology α] [BorelSpace α] [IsLocallyFiniteMeasure μ] {ρ : Measure α}
[IsLocallyFiniteMeasure ρ]
/-- If a measure `ρ` is singular with respect to `μ`, then for `μ` almost every `x`, the ratio
`ρ a / μ a` tends to zero when `a` shrinks to `x` along the Vitali family. This makes sense
as `μ a` is eventually positive by `ae_eventually_measure_pos`. -/
theorem ae_eventually_measure_zero_of_singular (hρ : ρ ⟂ₘ μ) :
∀ᵐ x ∂μ, Tendsto (fun a => ρ a / μ a) (v.filterAt x) (𝓝 0) := by
have A : ∀ ε > (0 : ℝ≥0), ∀ᵐ x ∂μ, ∀ᶠ a in v.filterAt x, ρ a < ε * μ a := by
intro ε εpos
set s := {x | ¬∀ᶠ a in v.filterAt x, ρ a < ε * μ a} with hs
change μ s = 0
obtain ⟨o, _, ρo, μo⟩ : ∃ o : Set α, MeasurableSet o ∧ ρ o = 0 ∧ μ oᶜ = 0 := hρ
apply le_antisymm _ bot_le
calc
μ s ≤ μ (s ∩ o ∪ oᶜ) := by
conv_lhs => rw [← inter_union_compl s o]
gcongr
apply inter_subset_right
_ ≤ μ (s ∩ o) + μ oᶜ := measure_union_le _ _
_ = μ (s ∩ o) := by rw [μo, add_zero]
_ = (ε : ℝ≥0∞)⁻¹ * (ε • μ) (s ∩ o) := by
simp only [coe_nnreal_smul_apply, ← mul_assoc, mul_comm _ (ε : ℝ≥0∞)]
rw [ENNReal.mul_inv_cancel (ENNReal.coe_pos.2 εpos).ne' ENNReal.coe_ne_top, one_mul]
_ ≤ (ε : ℝ≥0∞)⁻¹ * ρ (s ∩ o) := by
gcongr
refine v.measure_le_of_frequently_le ρ ((Measure.AbsolutelyContinuous.refl μ).smul ε) _ ?_
intro x hx
rw [hs] at hx
simp only [mem_inter_iff, not_lt, not_eventually, mem_setOf_eq] at hx
exact hx.1
_ ≤ (ε : ℝ≥0∞)⁻¹ * ρ o := by gcongr; apply inter_subset_right
_ = 0 := by rw [ρo, mul_zero]
obtain ⟨u, _, u_pos, u_lim⟩ :
∃ u : ℕ → ℝ≥0, StrictAnti u ∧ (∀ n : ℕ, 0 < u n) ∧ Tendsto u atTop (𝓝 0) :=
exists_seq_strictAnti_tendsto (0 : ℝ≥0)
have B : ∀ᵐ x ∂μ, ∀ n, ∀ᶠ a in v.filterAt x, ρ a < u n * μ a :=
ae_all_iff.2 fun n => A (u n) (u_pos n)
filter_upwards [B, v.ae_eventually_measure_pos]
intro x hx h'x
refine tendsto_order.2 ⟨fun z hz => (ENNReal.not_lt_zero hz).elim, fun z hz => ?_⟩
obtain ⟨w, w_pos, w_lt⟩ : ∃ w : ℝ≥0, (0 : ℝ≥0∞) < w ∧ (w : ℝ≥0∞) < z :=
ENNReal.lt_iff_exists_nnreal_btwn.1 hz
obtain ⟨n, hn⟩ : ∃ n, u n < w := ((tendsto_order.1 u_lim).2 w (ENNReal.coe_pos.1 w_pos)).exists
filter_upwards [hx n, h'x, v.eventually_measure_lt_top x]
intro a ha μa_pos μa_lt_top
rw [ENNReal.div_lt_iff (Or.inl μa_pos.ne') (Or.inl μa_lt_top.ne)]
exact ha.trans_le (mul_le_mul_right' ((ENNReal.coe_le_coe.2 hn.le).trans w_lt.le) _)
#align vitali_family.ae_eventually_measure_zero_of_singular VitaliFamily.ae_eventually_measure_zero_of_singular
section AbsolutelyContinuous
variable (hρ : ρ ≪ μ)
/-- A set of points `s` satisfying both `ρ a ≤ c * μ a` and `ρ a ≥ d * μ a` at arbitrarily small
sets in a Vitali family has measure `0` if `c < d`. Indeed, the first inequality should imply
that `ρ s ≤ c * μ s`, and the second one that `ρ s ≥ d * μ s`, a contradiction if `0 < μ s`. -/
theorem null_of_frequently_le_of_frequently_ge {c d : ℝ≥0} (hcd : c < d) (s : Set α)
(hc : ∀ x ∈ s, ∃ᶠ a in v.filterAt x, ρ a ≤ c * μ a)
(hd : ∀ x ∈ s, ∃ᶠ a in v.filterAt x, (d : ℝ≥0∞) * μ a ≤ ρ a) : μ s = 0 := by
apply measure_null_of_locally_null s fun x _ => ?_
obtain ⟨o, xo, o_open, μo⟩ : ∃ o : Set α, x ∈ o ∧ IsOpen o ∧ μ o < ∞ :=
Measure.exists_isOpen_measure_lt_top μ x
refine ⟨s ∩ o, inter_mem_nhdsWithin _ (o_open.mem_nhds xo), ?_⟩
let s' := s ∩ o
by_contra h
apply lt_irrefl (ρ s')
calc
ρ s' ≤ c * μ s' := v.measure_le_of_frequently_le (c • μ) hρ s' fun x hx => hc x hx.1
_ < d * μ s' := by
apply (ENNReal.mul_lt_mul_right h _).2 (ENNReal.coe_lt_coe.2 hcd)
exact (lt_of_le_of_lt (measure_mono inter_subset_right) μo).ne
_ ≤ ρ s' :=
v.measure_le_of_frequently_le ρ ((Measure.AbsolutelyContinuous.refl μ).smul d) s' fun x hx =>
hd x hx.1
#align vitali_family.null_of_frequently_le_of_frequently_ge VitaliFamily.null_of_frequently_le_of_frequently_ge
/-- If `ρ` is absolutely continuous with respect to `μ`, then for almost every `x`,
the ratio `ρ a / μ a` converges as `a` shrinks to `x` along a Vitali family for `μ`. -/
theorem ae_tendsto_div : ∀ᵐ x ∂μ, ∃ c, Tendsto (fun a => ρ a / μ a) (v.filterAt x) (𝓝 c) := by
obtain ⟨w, w_count, w_dense, _, w_top⟩ :
∃ w : Set ℝ≥0∞, w.Countable ∧ Dense w ∧ 0 ∉ w ∧ ∞ ∉ w :=
ENNReal.exists_countable_dense_no_zero_top
have I : ∀ x ∈ w, x ≠ ∞ := fun x xs hx => w_top (hx ▸ xs)
have A : ∀ c ∈ w, ∀ d ∈ w, c < d → ∀ᵐ x ∂μ,
¬((∃ᶠ a in v.filterAt x, ρ a / μ a < c) ∧ ∃ᶠ a in v.filterAt x, d < ρ a / μ a) := by
intro c hc d hd hcd
lift c to ℝ≥0 using I c hc
lift d to ℝ≥0 using I d hd
apply v.null_of_frequently_le_of_frequently_ge hρ (ENNReal.coe_lt_coe.1 hcd)
· simp only [and_imp, exists_prop, not_frequently, not_and, not_lt, not_le, not_eventually,
mem_setOf_eq, mem_compl_iff, not_forall]
intro x h1x _
apply h1x.mono fun a ha => ?_
refine (ENNReal.div_le_iff_le_mul ?_ (Or.inr (bot_le.trans_lt ha).ne')).1 ha.le
simp only [ENNReal.coe_ne_top, Ne, or_true_iff, not_false_iff]
· simp only [and_imp, exists_prop, not_frequently, not_and, not_lt, not_le, not_eventually,
mem_setOf_eq, mem_compl_iff, not_forall]
intro x _ h2x
apply h2x.mono fun a ha => ?_
exact ENNReal.mul_le_of_le_div ha.le
have B : ∀ᵐ x ∂μ, ∀ c ∈ w, ∀ d ∈ w, c < d →
¬((∃ᶠ a in v.filterAt x, ρ a / μ a < c) ∧ ∃ᶠ a in v.filterAt x, d < ρ a / μ a) := by
#adaptation_note /-- 2024-04-23
The next two lines were previously just `simpa only [ae_ball_iff w_count, ae_all_iff]` -/
rw [ae_ball_iff w_count]; intro x hx; rw [ae_ball_iff w_count]; revert x
simpa only [ae_all_iff]
filter_upwards [B]
intro x hx
exact tendsto_of_no_upcrossings w_dense hx
#align vitali_family.ae_tendsto_div VitaliFamily.ae_tendsto_div
theorem ae_tendsto_limRatio :
∀ᵐ x ∂μ, Tendsto (fun a => ρ a / μ a) (v.filterAt x) (𝓝 (v.limRatio ρ x)) := by
filter_upwards [v.ae_tendsto_div hρ]
intro x hx
exact tendsto_nhds_limUnder hx
#align vitali_family.ae_tendsto_lim_ratio VitaliFamily.ae_tendsto_limRatio
/-- Given two thresholds `p < q`, the sets `{x | v.limRatio ρ x < p}`
and `{x | q < v.limRatio ρ x}` are obviously disjoint. The key to proving that `v.limRatio ρ` is
almost everywhere measurable is to show that these sets have measurable supersets which are also
disjoint, up to zero measure. This is the content of this lemma. -/
theorem exists_measurable_supersets_limRatio {p q : ℝ≥0} (hpq : p < q) :
∃ a b, MeasurableSet a ∧ MeasurableSet b ∧
{x | v.limRatio ρ x < p} ⊆ a ∧ {x | (q : ℝ≥0∞) < v.limRatio ρ x} ⊆ b ∧ μ (a ∩ b) = 0 := by
/- Here is a rough sketch, assuming that the measure is finite and the limit is well defined
everywhere. Let `u := {x | v.limRatio ρ x < p}` and `w := {x | q < v.limRatio ρ x}`. They
have measurable supersets `u'` and `w'` of the same measure. We will show that these satisfy
the conclusion of the theorem, i.e., `μ (u' ∩ w') = 0`. For this, note that
`ρ (u' ∩ w') = ρ (u ∩ w')` (as `w'` is measurable, see `measure_toMeasurable_add_inter_left`).
The latter set is included in the set where the limit of the ratios is `< p`, and therefore
its measure is `≤ p * μ (u ∩ w')`. Using the same trick in the other direction gives that this
is `p * μ (u' ∩ w')`. We have shown that `ρ (u' ∩ w') ≤ p * μ (u' ∩ w')`. Arguing in the same
way but using the `w` part gives `q * μ (u' ∩ w') ≤ ρ (u' ∩ w')`. If `μ (u' ∩ w')` were nonzero,
this would be a contradiction as `p < q`.
For the rigorous proof, we need to work on a part of the space where the measure is finite
(provided by `spanningSets (ρ + μ)`) and to restrict to the set where the limit is well defined
(called `s` below, of full measure). Otherwise, the argument goes through.
-/
let s := {x | ∃ c, Tendsto (fun a => ρ a / μ a) (v.filterAt x) (𝓝 c)}
let o : ℕ → Set α := spanningSets (ρ + μ)
let u n := s ∩ {x | v.limRatio ρ x < p} ∩ o n
let w n := s ∩ {x | (q : ℝ≥0∞) < v.limRatio ρ x} ∩ o n
-- the supersets are obtained by restricting to the set `s` where the limit is well defined, to
-- a finite measure part `o n`, taking a measurable superset here, and then taking the union over
-- `n`.
refine
⟨toMeasurable μ sᶜ ∪ ⋃ n, toMeasurable (ρ + μ) (u n),
toMeasurable μ sᶜ ∪ ⋃ n, toMeasurable (ρ + μ) (w n), ?_, ?_, ?_, ?_, ?_⟩
-- check that these sets are measurable supersets as required
· exact
(measurableSet_toMeasurable _ _).union
(MeasurableSet.iUnion fun n => measurableSet_toMeasurable _ _)
· exact
(measurableSet_toMeasurable _ _).union
(MeasurableSet.iUnion fun n => measurableSet_toMeasurable _ _)
· intro x hx
by_cases h : x ∈ s
· refine Or.inr (mem_iUnion.2 ⟨spanningSetsIndex (ρ + μ) x, ?_⟩)
exact subset_toMeasurable _ _ ⟨⟨h, hx⟩, mem_spanningSetsIndex _ _⟩
· exact Or.inl (subset_toMeasurable μ sᶜ h)
· intro x hx
by_cases h : x ∈ s
· refine Or.inr (mem_iUnion.2 ⟨spanningSetsIndex (ρ + μ) x, ?_⟩)
exact subset_toMeasurable _ _ ⟨⟨h, hx⟩, mem_spanningSetsIndex _ _⟩
· exact Or.inl (subset_toMeasurable μ sᶜ h)
-- it remains to check the nontrivial part that these sets have zero measure intersection.
-- it suffices to do it for fixed `m` and `n`, as one is taking countable unions.
suffices H : ∀ m n : ℕ, μ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) = 0 by
have A :
(toMeasurable μ sᶜ ∪ ⋃ n, toMeasurable (ρ + μ) (u n)) ∩
(toMeasurable μ sᶜ ∪ ⋃ n, toMeasurable (ρ + μ) (w n)) ⊆
toMeasurable μ sᶜ ∪
⋃ (m) (n), toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n) := by
simp only [inter_union_distrib_left, union_inter_distrib_right, true_and_iff,
subset_union_left, union_subset_iff, inter_self]
refine ⟨?_, ?_, ?_⟩
· exact inter_subset_right.trans subset_union_left
· exact inter_subset_left.trans subset_union_left
· simp_rw [iUnion_inter, inter_iUnion]; exact subset_union_right
refine le_antisymm ((measure_mono A).trans ?_) bot_le
calc
μ (toMeasurable μ sᶜ ∪
⋃ (m) (n), toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) ≤
μ (toMeasurable μ sᶜ) +
μ (⋃ (m) (n), toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) :=
measure_union_le _ _
_ = μ (⋃ (m) (n), toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) := by
have : μ sᶜ = 0 := v.ae_tendsto_div hρ; rw [measure_toMeasurable, this, zero_add]
_ ≤ ∑' (m) (n), μ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) :=
((measure_iUnion_le _).trans (ENNReal.tsum_le_tsum fun m => measure_iUnion_le _))
_ = 0 := by simp only [H, tsum_zero]
-- now starts the nontrivial part of the argument. We fix `m` and `n`, and show that the
-- measurable supersets of `u m` and `w n` have zero measure intersection by using the lemmas
-- `measure_toMeasurable_add_inter_left` (to reduce to `u m` or `w n` instead of the measurable
-- superset) and `measure_le_of_frequently_le` to compare their measures for `ρ` and `μ`.
intro m n
have I : (ρ + μ) (u m) ≠ ∞ := by
apply (lt_of_le_of_lt (measure_mono _) (measure_spanningSets_lt_top (ρ + μ) m)).ne
exact inter_subset_right
have J : (ρ + μ) (w n) ≠ ∞ := by
apply (lt_of_le_of_lt (measure_mono _) (measure_spanningSets_lt_top (ρ + μ) n)).ne
exact inter_subset_right
have A :
ρ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) ≤
p * μ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) :=
calc
ρ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) =
ρ (u m ∩ toMeasurable (ρ + μ) (w n)) :=
measure_toMeasurable_add_inter_left (measurableSet_toMeasurable _ _) I
_ ≤ (p • μ) (u m ∩ toMeasurable (ρ + μ) (w n)) := by
refine v.measure_le_of_frequently_le (p • μ) hρ _ fun x hx => ?_
have L : Tendsto (fun a : Set α => ρ a / μ a) (v.filterAt x) (𝓝 (v.limRatio ρ x)) :=
tendsto_nhds_limUnder hx.1.1.1
have I : ∀ᶠ b : Set α in v.filterAt x, ρ b / μ b < p := (tendsto_order.1 L).2 _ hx.1.1.2
apply I.frequently.mono fun a ha => ?_
rw [coe_nnreal_smul_apply]
refine (ENNReal.div_le_iff_le_mul ?_ (Or.inr (bot_le.trans_lt ha).ne')).1 ha.le
simp only [ENNReal.coe_ne_top, Ne, or_true_iff, not_false_iff]
_ = p * μ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) := by
simp only [coe_nnreal_smul_apply,
measure_toMeasurable_add_inter_right (measurableSet_toMeasurable _ _) I]
have B :
(q : ℝ≥0∞) * μ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) ≤
ρ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) :=
calc
(q : ℝ≥0∞) * μ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) =
(q : ℝ≥0∞) * μ (toMeasurable (ρ + μ) (u m) ∩ w n) := by
conv_rhs => rw [inter_comm]
rw [inter_comm, measure_toMeasurable_add_inter_right (measurableSet_toMeasurable _ _) J]
_ ≤ ρ (toMeasurable (ρ + μ) (u m) ∩ w n) := by
rw [← coe_nnreal_smul_apply]
refine v.measure_le_of_frequently_le _ (AbsolutelyContinuous.rfl.smul _) _ ?_
intro x hx
have L : Tendsto (fun a : Set α => ρ a / μ a) (v.filterAt x) (𝓝 (v.limRatio ρ x)) :=
tendsto_nhds_limUnder hx.2.1.1
have I : ∀ᶠ b : Set α in v.filterAt x, (q : ℝ≥0∞) < ρ b / μ b :=
(tendsto_order.1 L).1 _ hx.2.1.2
apply I.frequently.mono fun a ha => ?_
rw [coe_nnreal_smul_apply]
exact ENNReal.mul_le_of_le_div ha.le
_ = ρ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) := by
conv_rhs => rw [inter_comm]
rw [inter_comm]
exact (measure_toMeasurable_add_inter_left (measurableSet_toMeasurable _ _) J).symm
by_contra h
apply lt_irrefl (ρ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)))
calc
ρ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) ≤
p * μ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) :=
A
_ < q * μ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) := by
gcongr
suffices H : (ρ + μ) (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) ≠ ∞ by
simp only [not_or, ENNReal.add_eq_top, Pi.add_apply, Ne, coe_add] at H
exact H.2
apply (lt_of_le_of_lt (measure_mono inter_subset_left) _).ne
rw [measure_toMeasurable]
apply lt_of_le_of_lt (measure_mono _) (measure_spanningSets_lt_top (ρ + μ) m)
exact inter_subset_right
_ ≤ ρ (toMeasurable (ρ + μ) (u m) ∩ toMeasurable (ρ + μ) (w n)) := B
#align vitali_family.exists_measurable_supersets_lim_ratio VitaliFamily.exists_measurable_supersets_limRatio
theorem aemeasurable_limRatio : AEMeasurable (v.limRatio ρ) μ := by
apply ENNReal.aemeasurable_of_exist_almost_disjoint_supersets _ _ fun p q hpq => ?_
exact v.exists_measurable_supersets_limRatio hρ hpq
#align vitali_family.ae_measurable_lim_ratio VitaliFamily.aemeasurable_limRatio
/-- A measurable version of `v.limRatio ρ`. Do *not* use this definition: it is only a temporary
device to show that `v.limRatio` is almost everywhere equal to the Radon-Nikodym derivative. -/
noncomputable def limRatioMeas : α → ℝ≥0∞ :=
(v.aemeasurable_limRatio hρ).mk _
#align vitali_family.lim_ratio_meas VitaliFamily.limRatioMeas
theorem limRatioMeas_measurable : Measurable (v.limRatioMeas hρ) :=
AEMeasurable.measurable_mk _
#align vitali_family.lim_ratio_meas_measurable VitaliFamily.limRatioMeas_measurable
theorem ae_tendsto_limRatioMeas :
∀ᵐ x ∂μ, Tendsto (fun a => ρ a / μ a) (v.filterAt x) (𝓝 (v.limRatioMeas hρ x)) := by
filter_upwards [v.ae_tendsto_limRatio hρ, AEMeasurable.ae_eq_mk (v.aemeasurable_limRatio hρ)]
intro x hx h'x
rwa [h'x] at hx
#align vitali_family.ae_tendsto_lim_ratio_meas VitaliFamily.ae_tendsto_limRatioMeas
/-- If, for all `x` in a set `s`, one has frequently `ρ a / μ a < p`, then `ρ s ≤ p * μ s`, as
proved in `measure_le_of_frequently_le`. Since `ρ a / μ a` tends almost everywhere to
`v.limRatioMeas hρ x`, the same property holds for sets `s` on which `v.limRatioMeas hρ < p`. -/
theorem measure_le_mul_of_subset_limRatioMeas_lt {p : ℝ≥0} {s : Set α}
(h : s ⊆ {x | v.limRatioMeas hρ x < p}) : ρ s ≤ p * μ s := by
let t := {x : α | Tendsto (fun a => ρ a / μ a) (v.filterAt x) (𝓝 (v.limRatioMeas hρ x))}
have A : μ tᶜ = 0 := v.ae_tendsto_limRatioMeas hρ
suffices H : ρ (s ∩ t) ≤ (p • μ) (s ∩ t) by calc
ρ s = ρ (s ∩ t ∪ s ∩ tᶜ) := by rw [inter_union_compl]
_ ≤ ρ (s ∩ t) + ρ (s ∩ tᶜ) := measure_union_le _ _
_ ≤ (p • μ) (s ∩ t) + ρ tᶜ := by gcongr; apply inter_subset_right
_ ≤ p * μ (s ∩ t) := by simp [(hρ A)]
_ ≤ p * μ s := by gcongr; apply inter_subset_left
refine v.measure_le_of_frequently_le (p • μ) hρ _ fun x hx => ?_
have I : ∀ᶠ b : Set α in v.filterAt x, ρ b / μ b < p := (tendsto_order.1 hx.2).2 _ (h hx.1)
apply I.frequently.mono fun a ha => ?_
rw [coe_nnreal_smul_apply]
refine (ENNReal.div_le_iff_le_mul ?_ (Or.inr (bot_le.trans_lt ha).ne')).1 ha.le
simp only [ENNReal.coe_ne_top, Ne, or_true_iff, not_false_iff]
#align vitali_family.measure_le_mul_of_subset_lim_ratio_meas_lt VitaliFamily.measure_le_mul_of_subset_limRatioMeas_lt
/-- If, for all `x` in a set `s`, one has frequently `q < ρ a / μ a`, then `q * μ s ≤ ρ s`, as
proved in `measure_le_of_frequently_le`. Since `ρ a / μ a` tends almost everywhere to
`v.limRatioMeas hρ x`, the same property holds for sets `s` on which `q < v.limRatioMeas hρ`. -/
theorem mul_measure_le_of_subset_lt_limRatioMeas {q : ℝ≥0} {s : Set α}
(h : s ⊆ {x | (q : ℝ≥0∞) < v.limRatioMeas hρ x}) : (q : ℝ≥0∞) * μ s ≤ ρ s := by
let t := {x : α | Tendsto (fun a => ρ a / μ a) (v.filterAt x) (𝓝 (v.limRatioMeas hρ x))}
have A : μ tᶜ = 0 := v.ae_tendsto_limRatioMeas hρ
suffices H : (q • μ) (s ∩ t) ≤ ρ (s ∩ t) by calc
(q • μ) s = (q • μ) (s ∩ t ∪ s ∩ tᶜ) := by rw [inter_union_compl]
_ ≤ (q • μ) (s ∩ t) + (q • μ) (s ∩ tᶜ) := measure_union_le _ _
_ ≤ ρ (s ∩ t) + (q • μ) tᶜ := by gcongr; apply inter_subset_right
_ = ρ (s ∩ t) := by simp [A]
_ ≤ ρ s := by gcongr; apply inter_subset_left
refine v.measure_le_of_frequently_le _ (AbsolutelyContinuous.rfl.smul _) _ ?_
intro x hx
have I : ∀ᶠ a in v.filterAt x, (q : ℝ≥0∞) < ρ a / μ a := (tendsto_order.1 hx.2).1 _ (h hx.1)
apply I.frequently.mono fun a ha => ?_
rw [coe_nnreal_smul_apply]
exact ENNReal.mul_le_of_le_div ha.le
#align vitali_family.mul_measure_le_of_subset_lt_lim_ratio_meas VitaliFamily.mul_measure_le_of_subset_lt_limRatioMeas
/-- The points with `v.limRatioMeas hρ x = ∞` have measure `0` for `μ`. -/
theorem measure_limRatioMeas_top : μ {x | v.limRatioMeas hρ x = ∞} = 0 := by
refine measure_null_of_locally_null _ fun x _ => ?_
obtain ⟨o, xo, o_open, μo⟩ : ∃ o : Set α, x ∈ o ∧ IsOpen o ∧ ρ o < ∞ :=
Measure.exists_isOpen_measure_lt_top ρ x
let s := {x : α | v.limRatioMeas hρ x = ∞} ∩ o
refine ⟨s, inter_mem_nhdsWithin _ (o_open.mem_nhds xo), le_antisymm ?_ bot_le⟩
have ρs : ρ s ≠ ∞ := ((measure_mono inter_subset_right).trans_lt μo).ne
have A : ∀ q : ℝ≥0, 1 ≤ q → μ s ≤ (q : ℝ≥0∞)⁻¹ * ρ s := by
intro q hq
rw [mul_comm, ← div_eq_mul_inv, ENNReal.le_div_iff_mul_le _ (Or.inr ρs), mul_comm]
· apply v.mul_measure_le_of_subset_lt_limRatioMeas hρ
intro y hy
have : v.limRatioMeas hρ y = ∞ := hy.1
simp only [this, ENNReal.coe_lt_top, mem_setOf_eq]
· simp only [(zero_lt_one.trans_le hq).ne', true_or_iff, ENNReal.coe_eq_zero, Ne,
not_false_iff]
have B : Tendsto (fun q : ℝ≥0 => (q : ℝ≥0∞)⁻¹ * ρ s) atTop (𝓝 (∞⁻¹ * ρ s)) := by
apply ENNReal.Tendsto.mul_const _ (Or.inr ρs)
exact ENNReal.tendsto_inv_iff.2 (ENNReal.tendsto_coe_nhds_top.2 tendsto_id)
simp only [zero_mul, ENNReal.inv_top] at B
apply ge_of_tendsto B
exact eventually_atTop.2 ⟨1, A⟩
#align vitali_family.measure_lim_ratio_meas_top VitaliFamily.measure_limRatioMeas_top
/-- The points with `v.limRatioMeas hρ x = 0` have measure `0` for `ρ`. -/
theorem measure_limRatioMeas_zero : ρ {x | v.limRatioMeas hρ x = 0} = 0 := by
refine measure_null_of_locally_null _ fun x _ => ?_
obtain ⟨o, xo, o_open, μo⟩ : ∃ o : Set α, x ∈ o ∧ IsOpen o ∧ μ o < ∞ :=
Measure.exists_isOpen_measure_lt_top μ x
let s := {x : α | v.limRatioMeas hρ x = 0} ∩ o
refine ⟨s, inter_mem_nhdsWithin _ (o_open.mem_nhds xo), le_antisymm ?_ bot_le⟩
have μs : μ s ≠ ∞ := ((measure_mono inter_subset_right).trans_lt μo).ne
have A : ∀ q : ℝ≥0, 0 < q → ρ s ≤ q * μ s := by
intro q hq
apply v.measure_le_mul_of_subset_limRatioMeas_lt hρ
intro y hy
have : v.limRatioMeas hρ y = 0 := hy.1
simp only [this, mem_setOf_eq, hq, ENNReal.coe_pos]
have B : Tendsto (fun q : ℝ≥0 => (q : ℝ≥0∞) * μ s) (𝓝[>] (0 : ℝ≥0)) (𝓝 ((0 : ℝ≥0) * μ s)) := by
apply ENNReal.Tendsto.mul_const _ (Or.inr μs)
rw [ENNReal.tendsto_coe]
exact nhdsWithin_le_nhds
simp only [zero_mul, ENNReal.coe_zero] at B
apply ge_of_tendsto B
filter_upwards [self_mem_nhdsWithin] using A
#align vitali_family.measure_lim_ratio_meas_zero VitaliFamily.measure_limRatioMeas_zero
/-- As an intermediate step to show that `μ.withDensity (v.limRatioMeas hρ) = ρ`, we show here
that `μ.withDensity (v.limRatioMeas hρ) ≤ t^2 ρ` for any `t > 1`. -/
theorem withDensity_le_mul {s : Set α} (hs : MeasurableSet s) {t : ℝ≥0} (ht : 1 < t) :
μ.withDensity (v.limRatioMeas hρ) s ≤ (t : ℝ≥0∞) ^ 2 * ρ s := by
/- We cut `s` into the sets where `v.limRatioMeas hρ = 0`, where `v.limRatioMeas hρ = ∞`, and
where `v.limRatioMeas hρ ∈ [t^n, t^(n+1))` for `n : ℤ`. The first and second have measure `0`.
For the latter, since `v.limRatioMeas hρ` fluctuates by at most `t` on this slice, we can use
`measure_le_mul_of_subset_limRatioMeas_lt` and `mul_measure_le_of_subset_lt_limRatioMeas` to
show that the two measures are comparable up to `t` (in fact `t^2` for technical reasons of
strict inequalities). -/
have t_ne_zero' : t ≠ 0 := (zero_lt_one.trans ht).ne'
have t_ne_zero : (t : ℝ≥0∞) ≠ 0 := by simpa only [ENNReal.coe_eq_zero, Ne] using t_ne_zero'
let ν := μ.withDensity (v.limRatioMeas hρ)
let f := v.limRatioMeas hρ
have f_meas : Measurable f := v.limRatioMeas_measurable hρ
-- Note(kmill): smul elaborator when used for CoeFun fails to get CoeFun instance to trigger
-- unless you use the `(... :)` notation. Another fix is using `(2 : Nat)`, so this appears
-- to be an unpleasant interaction with default instances.
have A : ν (s ∩ f ⁻¹' {0}) ≤ ((t : ℝ≥0∞) ^ 2 • ρ :) (s ∩ f ⁻¹' {0}) := by
apply le_trans _ (zero_le _)
have M : MeasurableSet (s ∩ f ⁻¹' {0}) := hs.inter (f_meas (measurableSet_singleton _))
simp only [ν, nonpos_iff_eq_zero, M, withDensity_apply, lintegral_eq_zero_iff f_meas]
apply (ae_restrict_iff' M).2
exact eventually_of_forall fun x hx => hx.2
have B : ν (s ∩ f ⁻¹' {∞}) ≤ ((t : ℝ≥0∞) ^ 2 • ρ :) (s ∩ f ⁻¹' {∞}) := by
apply le_trans (le_of_eq _) (zero_le _)
apply withDensity_absolutelyContinuous μ _
rw [← nonpos_iff_eq_zero]
exact (measure_mono inter_subset_right).trans (v.measure_limRatioMeas_top hρ).le
have C :
∀ n : ℤ,
ν (s ∩ f ⁻¹' Ico ((t : ℝ≥0∞) ^ n) ((t : ℝ≥0∞) ^ (n + 1))) ≤
((t : ℝ≥0∞) ^ 2 • ρ :) (s ∩ f ⁻¹' Ico ((t : ℝ≥0∞) ^ n) ((t : ℝ≥0∞) ^ (n + 1))) := by
intro n
let I := Ico ((t : ℝ≥0∞) ^ n) ((t : ℝ≥0∞) ^ (n + 1))
have M : MeasurableSet (s ∩ f ⁻¹' I) := hs.inter (f_meas measurableSet_Ico)
simp only [ν, M, withDensity_apply, coe_nnreal_smul_apply]
calc
(∫⁻ x in s ∩ f ⁻¹' I, f x ∂μ) ≤ ∫⁻ _ in s ∩ f ⁻¹' I, (t : ℝ≥0∞) ^ (n + 1) ∂μ :=
lintegral_mono_ae ((ae_restrict_iff' M).2 (eventually_of_forall fun x hx => hx.2.2.le))
_ = (t : ℝ≥0∞) ^ (n + 1) * μ (s ∩ f ⁻¹' I) := by
simp only [lintegral_const, MeasurableSet.univ, Measure.restrict_apply, univ_inter]
_ = (t : ℝ≥0∞) ^ (2 : ℤ) * ((t : ℝ≥0∞) ^ (n - 1) * μ (s ∩ f ⁻¹' I)) := by
rw [← mul_assoc, ← ENNReal.zpow_add t_ne_zero ENNReal.coe_ne_top]
congr 2
abel
_ ≤ (t : ℝ≥0∞) ^ (2 : ℤ) * ρ (s ∩ f ⁻¹' I) := by
gcongr
rw [← ENNReal.coe_zpow (zero_lt_one.trans ht).ne']
apply v.mul_measure_le_of_subset_lt_limRatioMeas hρ
intro x hx
apply lt_of_lt_of_le _ hx.2.1
rw [← ENNReal.coe_zpow (zero_lt_one.trans ht).ne', ENNReal.coe_lt_coe, sub_eq_add_neg,
zpow_add₀ t_ne_zero']
conv_rhs => rw [← mul_one (t ^ n)]
gcongr
rw [zpow_neg_one]
exact inv_lt_one ht
calc
ν s =
ν (s ∩ f ⁻¹' {0}) + ν (s ∩ f ⁻¹' {∞}) +
∑' n : ℤ, ν (s ∩ f ⁻¹' Ico ((t : ℝ≥0∞) ^ n) ((t : ℝ≥0∞) ^ (n + 1))) :=
measure_eq_measure_preimage_add_measure_tsum_Ico_zpow ν f_meas hs ht
_ ≤
((t : ℝ≥0∞) ^ 2 • ρ :) (s ∩ f ⁻¹' {0}) + ((t : ℝ≥0∞) ^ 2 • ρ :) (s ∩ f ⁻¹' {∞}) +
∑' n : ℤ, ((t : ℝ≥0∞) ^ 2 • ρ :) (s ∩ f ⁻¹' Ico (t ^ n) (t ^ (n + 1))) :=
(add_le_add (add_le_add A B) (ENNReal.tsum_le_tsum C))
_ = ((t : ℝ≥0∞) ^ 2 • ρ :) s :=
(measure_eq_measure_preimage_add_measure_tsum_Ico_zpow ((t : ℝ≥0∞) ^ 2 • ρ) f_meas hs ht).symm
#align vitali_family.with_density_le_mul VitaliFamily.withDensity_le_mul
/-- As an intermediate step to show that `μ.withDensity (v.limRatioMeas hρ) = ρ`, we show here
that `ρ ≤ t μ.withDensity (v.limRatioMeas hρ)` for any `t > 1`. -/
theorem le_mul_withDensity {s : Set α} (hs : MeasurableSet s) {t : ℝ≥0} (ht : 1 < t) :
ρ s ≤ t * μ.withDensity (v.limRatioMeas hρ) s := by
/- We cut `s` into the sets where `v.limRatioMeas hρ = 0`, where `v.limRatioMeas hρ = ∞`, and
where `v.limRatioMeas hρ ∈ [t^n, t^(n+1))` for `n : ℤ`. The first and second have measure `0`.
For the latter, since `v.limRatioMeas hρ` fluctuates by at most `t` on this slice, we can use
`measure_le_mul_of_subset_limRatioMeas_lt` and `mul_measure_le_of_subset_lt_limRatioMeas` to
show that the two measures are comparable up to `t`. -/
have t_ne_zero' : t ≠ 0 := (zero_lt_one.trans ht).ne'
have t_ne_zero : (t : ℝ≥0∞) ≠ 0 := by simpa only [ENNReal.coe_eq_zero, Ne] using t_ne_zero'
let ν := μ.withDensity (v.limRatioMeas hρ)
let f := v.limRatioMeas hρ
have f_meas : Measurable f := v.limRatioMeas_measurable hρ
have A : ρ (s ∩ f ⁻¹' {0}) ≤ (t • ν) (s ∩ f ⁻¹' {0}) := by
refine le_trans (measure_mono inter_subset_right) (le_trans (le_of_eq ?_) (zero_le _))
exact v.measure_limRatioMeas_zero hρ
have B : ρ (s ∩ f ⁻¹' {∞}) ≤ (t • ν) (s ∩ f ⁻¹' {∞}) := by
apply le_trans (le_of_eq _) (zero_le _)
apply hρ
rw [← nonpos_iff_eq_zero]
exact (measure_mono inter_subset_right).trans (v.measure_limRatioMeas_top hρ).le
have C :
∀ n : ℤ,
ρ (s ∩ f ⁻¹' Ico ((t : ℝ≥0∞) ^ n) ((t : ℝ≥0∞) ^ (n + 1))) ≤
(t • ν) (s ∩ f ⁻¹' Ico ((t : ℝ≥0∞) ^ n) ((t : ℝ≥0∞) ^ (n + 1))) := by
intro n
let I := Ico ((t : ℝ≥0∞) ^ n) ((t : ℝ≥0∞) ^ (n + 1))
have M : MeasurableSet (s ∩ f ⁻¹' I) := hs.inter (f_meas measurableSet_Ico)
simp only [ν, M, withDensity_apply, coe_nnreal_smul_apply]
calc
ρ (s ∩ f ⁻¹' I) ≤ (t : ℝ≥0∞) ^ (n + 1) * μ (s ∩ f ⁻¹' I) := by
rw [← ENNReal.coe_zpow t_ne_zero']
apply v.measure_le_mul_of_subset_limRatioMeas_lt hρ
intro x hx
apply hx.2.2.trans_le (le_of_eq _)
rw [ENNReal.coe_zpow t_ne_zero']
_ = ∫⁻ _ in s ∩ f ⁻¹' I, (t : ℝ≥0∞) ^ (n + 1) ∂μ := by
simp only [lintegral_const, MeasurableSet.univ, Measure.restrict_apply, univ_inter]
_ ≤ ∫⁻ x in s ∩ f ⁻¹' I, t * f x ∂μ := by
apply lintegral_mono_ae ((ae_restrict_iff' M).2 (eventually_of_forall fun x hx => ?_))
rw [add_comm, ENNReal.zpow_add t_ne_zero ENNReal.coe_ne_top, zpow_one]
exact mul_le_mul_left' hx.2.1 _
_ = t * ∫⁻ x in s ∩ f ⁻¹' I, f x ∂μ := lintegral_const_mul _ f_meas
calc
ρ s =
ρ (s ∩ f ⁻¹' {0}) + ρ (s ∩ f ⁻¹' {∞}) +
∑' n : ℤ, ρ (s ∩ f ⁻¹' Ico ((t : ℝ≥0∞) ^ n) ((t : ℝ≥0∞) ^ (n + 1))) :=
measure_eq_measure_preimage_add_measure_tsum_Ico_zpow ρ f_meas hs ht
_ ≤
(t • ν) (s ∩ f ⁻¹' {0}) + (t • ν) (s ∩ f ⁻¹' {∞}) +
∑' n : ℤ, (t • ν) (s ∩ f ⁻¹' Ico ((t : ℝ≥0∞) ^ n) ((t : ℝ≥0∞) ^ (n + 1))) :=
(add_le_add (add_le_add A B) (ENNReal.tsum_le_tsum C))
_ = (t • ν) s :=
(measure_eq_measure_preimage_add_measure_tsum_Ico_zpow (t • ν) f_meas hs ht).symm
#align vitali_family.le_mul_with_density VitaliFamily.le_mul_withDensity
theorem withDensity_limRatioMeas_eq : μ.withDensity (v.limRatioMeas hρ) = ρ := by
ext1 s hs
refine le_antisymm ?_ ?_
· have : Tendsto (fun t : ℝ≥0 =>
((t : ℝ≥0∞) ^ 2 * ρ s : ℝ≥0∞)) (𝓝[>] 1) (𝓝 ((1 : ℝ≥0∞) ^ 2 * ρ s)) := by
refine ENNReal.Tendsto.mul ?_ ?_ tendsto_const_nhds ?_
· exact ENNReal.Tendsto.pow (ENNReal.tendsto_coe.2 nhdsWithin_le_nhds)
· simp only [one_pow, ENNReal.coe_one, true_or_iff, Ne, not_false_iff, one_ne_zero]
· simp only [one_pow, ENNReal.coe_one, Ne, or_true_iff, ENNReal.one_ne_top, not_false_iff]
simp only [one_pow, one_mul, ENNReal.coe_one] at this
refine ge_of_tendsto this ?_
filter_upwards [self_mem_nhdsWithin] with _ ht
exact v.withDensity_le_mul hρ hs ht
· have :
Tendsto (fun t : ℝ≥0 => (t : ℝ≥0∞) * μ.withDensity (v.limRatioMeas hρ) s) (𝓝[>] 1)
(𝓝 ((1 : ℝ≥0∞) * μ.withDensity (v.limRatioMeas hρ) s)) := by
refine ENNReal.Tendsto.mul_const (ENNReal.tendsto_coe.2 nhdsWithin_le_nhds) ?_
simp only [ENNReal.coe_one, true_or_iff, Ne, not_false_iff, one_ne_zero]
simp only [one_mul, ENNReal.coe_one] at this
refine ge_of_tendsto this ?_
filter_upwards [self_mem_nhdsWithin] with _ ht
exact v.le_mul_withDensity hρ hs ht
#align vitali_family.with_density_lim_ratio_meas_eq VitaliFamily.withDensity_limRatioMeas_eq
/-- Weak version of the main theorem on differentiation of measures: given a Vitali family `v`
for a locally finite measure `μ`, and another locally finite measure `ρ`, then for `μ`-almost
every `x` the ratio `ρ a / μ a` converges, when `a` shrinks to `x` along the Vitali family,
towards the Radon-Nikodym derivative of `ρ` with respect to `μ`.
This version assumes that `ρ` is absolutely continuous with respect to `μ`. The general version
without this superfluous assumption is `VitaliFamily.ae_tendsto_rnDeriv`.
-/
theorem ae_tendsto_rnDeriv_of_absolutelyContinuous :
∀ᵐ x ∂μ, Tendsto (fun a => ρ a / μ a) (v.filterAt x) (𝓝 (ρ.rnDeriv μ x)) := by
have A : (μ.withDensity (v.limRatioMeas hρ)).rnDeriv μ =ᵐ[μ] v.limRatioMeas hρ :=
rnDeriv_withDensity μ (v.limRatioMeas_measurable hρ)
rw [v.withDensity_limRatioMeas_eq hρ] at A
filter_upwards [v.ae_tendsto_limRatioMeas hρ, A] with _ _ h'x
rwa [h'x]
#align vitali_family.ae_tendsto_rn_deriv_of_absolutely_continuous VitaliFamily.ae_tendsto_rnDeriv_of_absolutelyContinuous
end AbsolutelyContinuous
variable (ρ)
/-- Main theorem on differentiation of measures: given a Vitali family `v` for a locally finite
measure `μ`, and another locally finite measure `ρ`, then for `μ`-almost every `x` the
ratio `ρ a / μ a` converges, when `a` shrinks to `x` along the Vitali family, towards the
Radon-Nikodym derivative of `ρ` with respect to `μ`. -/
| Mathlib/MeasureTheory/Covering/Differentiation.lean | 708 | 723 | theorem ae_tendsto_rnDeriv :
∀ᵐ x ∂μ, Tendsto (fun a => ρ a / μ a) (v.filterAt x) (𝓝 (ρ.rnDeriv μ x)) := by |
let t := μ.withDensity (ρ.rnDeriv μ)
have eq_add : ρ = ρ.singularPart μ + t := haveLebesgueDecomposition_add _ _
have A : ∀ᵐ x ∂μ, Tendsto (fun a => ρ.singularPart μ a / μ a) (v.filterAt x) (𝓝 0) :=
v.ae_eventually_measure_zero_of_singular (mutuallySingular_singularPart ρ μ)
have B : ∀ᵐ x ∂μ, t.rnDeriv μ x = ρ.rnDeriv μ x :=
rnDeriv_withDensity μ (measurable_rnDeriv ρ μ)
have C : ∀ᵐ x ∂μ, Tendsto (fun a => t a / μ a) (v.filterAt x) (𝓝 (t.rnDeriv μ x)) :=
v.ae_tendsto_rnDeriv_of_absolutelyContinuous (withDensity_absolutelyContinuous _ _)
filter_upwards [A, B, C] with _ Ax Bx Cx
convert Ax.add Cx using 1
· ext1 a
conv_lhs => rw [eq_add]
simp only [Pi.add_apply, coe_add, ENNReal.add_div]
· simp only [Bx, zero_add]
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Yury Kudryashov
-/
import Mathlib.Analysis.Convex.Between
import Mathlib.Analysis.Convex.Jensen
import Mathlib.Analysis.Convex.Topology
import Mathlib.Analysis.Normed.Group.Pointwise
import Mathlib.Analysis.NormedSpace.AddTorsor
#align_import analysis.convex.normed from "leanprover-community/mathlib"@"a63928c34ec358b5edcda2bf7513c50052a5230f"
/-!
# Topological and metric properties of convex sets in normed spaces
We prove the following facts:
* `convexOn_norm`, `convexOn_dist` : norm and distance to a fixed point is convex on any convex
set;
* `convexOn_univ_norm`, `convexOn_univ_dist` : norm and distance to a fixed point is convex on
the whole space;
* `convexHull_ediam`, `convexHull_diam` : convex hull of a set has the same (e)metric diameter
as the original set;
* `bounded_convexHull` : convex hull of a set is bounded if and only if the original set
is bounded.
-/
variable {ι : Type*} {E P : Type*}
open Metric Set
open scoped Convex
variable [SeminormedAddCommGroup E] [NormedSpace ℝ E] [PseudoMetricSpace P] [NormedAddTorsor E P]
variable {s t : Set E}
/-- The norm on a real normed space is convex on any convex set. See also `Seminorm.convexOn`
and `convexOn_univ_norm`. -/
theorem convexOn_norm (hs : Convex ℝ s) : ConvexOn ℝ s norm :=
⟨hs, fun x _ y _ a b ha hb _ =>
calc
‖a • x + b • y‖ ≤ ‖a • x‖ + ‖b • y‖ := norm_add_le _ _
_ = a * ‖x‖ + b * ‖y‖ := by
rw [norm_smul, norm_smul, Real.norm_of_nonneg ha, Real.norm_of_nonneg hb]⟩
#align convex_on_norm convexOn_norm
/-- The norm on a real normed space is convex on the whole space. See also `Seminorm.convexOn`
and `convexOn_norm`. -/
theorem convexOn_univ_norm : ConvexOn ℝ univ (norm : E → ℝ) :=
convexOn_norm convex_univ
#align convex_on_univ_norm convexOn_univ_norm
theorem convexOn_dist (z : E) (hs : Convex ℝ s) : ConvexOn ℝ s fun z' => dist z' z := by
simpa [dist_eq_norm, preimage_preimage] using
(convexOn_norm (hs.translate (-z))).comp_affineMap (AffineMap.id ℝ E - AffineMap.const ℝ E z)
#align convex_on_dist convexOn_dist
theorem convexOn_univ_dist (z : E) : ConvexOn ℝ univ fun z' => dist z' z :=
convexOn_dist z convex_univ
#align convex_on_univ_dist convexOn_univ_dist
theorem convex_ball (a : E) (r : ℝ) : Convex ℝ (Metric.ball a r) := by
simpa only [Metric.ball, sep_univ] using (convexOn_univ_dist a).convex_lt r
#align convex_ball convex_ball
theorem convex_closedBall (a : E) (r : ℝ) : Convex ℝ (Metric.closedBall a r) := by
simpa only [Metric.closedBall, sep_univ] using (convexOn_univ_dist a).convex_le r
#align convex_closed_ball convex_closedBall
theorem Convex.thickening (hs : Convex ℝ s) (δ : ℝ) : Convex ℝ (thickening δ s) := by
rw [← add_ball_zero]
exact hs.add (convex_ball 0 _)
#align convex.thickening Convex.thickening
theorem Convex.cthickening (hs : Convex ℝ s) (δ : ℝ) : Convex ℝ (cthickening δ s) := by
obtain hδ | hδ := le_total 0 δ
· rw [cthickening_eq_iInter_thickening hδ]
exact convex_iInter₂ fun _ _ => hs.thickening _
· rw [cthickening_of_nonpos hδ]
exact hs.closure
#align convex.cthickening Convex.cthickening
/-- Given a point `x` in the convex hull of `s` and a point `y`, there exists a point
of `s` at distance at least `dist x y` from `y`. -/
theorem convexHull_exists_dist_ge {s : Set E} {x : E} (hx : x ∈ convexHull ℝ s) (y : E) :
∃ x' ∈ s, dist x y ≤ dist x' y :=
(convexOn_dist y (convex_convexHull ℝ _)).exists_ge_of_mem_convexHull hx
#align convex_hull_exists_dist_ge convexHull_exists_dist_ge
/-- Given a point `x` in the convex hull of `s` and a point `y` in the convex hull of `t`,
there exist points `x' ∈ s` and `y' ∈ t` at distance at least `dist x y`. -/
| Mathlib/Analysis/Convex/Normed.lean | 92 | 97 | theorem convexHull_exists_dist_ge2 {s t : Set E} {x y : E} (hx : x ∈ convexHull ℝ s)
(hy : y ∈ convexHull ℝ t) : ∃ x' ∈ s, ∃ y' ∈ t, dist x y ≤ dist x' y' := by |
rcases convexHull_exists_dist_ge hx y with ⟨x', hx', Hx'⟩
rcases convexHull_exists_dist_ge hy x' with ⟨y', hy', Hy'⟩
use x', hx', y', hy'
exact le_trans Hx' (dist_comm y x' ▸ dist_comm y' x' ▸ Hy')
|
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Analytic.Composition
#align_import analysis.analytic.inverse from "leanprover-community/mathlib"@"284fdd2962e67d2932fa3a79ce19fcf92d38e228"
/-!
# Inverse of analytic functions
We construct the left and right inverse of a formal multilinear series with invertible linear term,
we prove that they coincide and study their properties (notably convergence).
## Main statements
* `p.leftInv i`: the formal left inverse of the formal multilinear series `p`,
for `i : E ≃L[𝕜] F` which coincides with `p₁`.
* `p.rightInv i`: the formal right inverse of the formal multilinear series `p`,
for `i : E ≃L[𝕜] F` which coincides with `p₁`.
* `p.leftInv_comp` says that `p.leftInv i` is indeed a left inverse to `p` when `p₁ = i`.
* `p.rightInv_comp` says that `p.rightInv i` is indeed a right inverse to `p` when `p₁ = i`.
* `p.leftInv_eq_rightInv`: the two inverses coincide.
* `p.radius_rightInv_pos_of_radius_pos`: if a power series has a positive radius of convergence,
then so does its inverse.
-/
open scoped Classical Topology
open Finset Filter
namespace FormalMultilinearSeries
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
/-! ### The left inverse of a formal multilinear series -/
/-- The left inverse of a formal multilinear series, where the `n`-th term is defined inductively
in terms of the previous ones to make sure that `(leftInv p i) ∘ p = id`. For this, the linear term
`p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should
coincide with `p₁`, so that one can use its inverse in the construction. The definition does not
use that `i = p₁`, but proofs that the definition is well-behaved do.
The `n`-th term in `q ∘ p` is `∑ qₖ (p_{j₁}, ..., p_{jₖ})` over `j₁ + ... + jₖ = n`. In this
expression, `qₙ` appears only once, in `qₙ (p₁, ..., p₁)`. We adjust the definition so that this
term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`.
These formulas only make sense when the constant term `p₀` vanishes. The definition we give is
general, but it ignores the value of `p₀`.
-/
noncomputable def leftInv (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) :
FormalMultilinearSeries 𝕜 F E
| 0 => 0
| 1 => (continuousMultilinearCurryFin1 𝕜 F E).symm i.symm
| n + 2 =>
-∑ c : { c : Composition (n + 2) // c.length < n + 2 },
(leftInv p i (c : Composition (n + 2)).length).compAlongComposition
(p.compContinuousLinearMap i.symm) c
#align formal_multilinear_series.left_inv FormalMultilinearSeries.leftInv
@[simp]
theorem leftInv_coeff_zero (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) :
p.leftInv i 0 = 0 := by rw [leftInv]
#align formal_multilinear_series.left_inv_coeff_zero FormalMultilinearSeries.leftInv_coeff_zero
@[simp]
theorem leftInv_coeff_one (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) :
p.leftInv i 1 = (continuousMultilinearCurryFin1 𝕜 F E).symm i.symm := by rw [leftInv]
#align formal_multilinear_series.left_inv_coeff_one FormalMultilinearSeries.leftInv_coeff_one
/-- The left inverse does not depend on the zeroth coefficient of a formal multilinear
series. -/
theorem leftInv_removeZero (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) :
p.removeZero.leftInv i = p.leftInv i := by
ext1 n
induction' n using Nat.strongRec' with n IH
match n with
| 0 => simp -- if one replaces `simp` with `refl`, the proof times out in the kernel.
| 1 => simp -- TODO: why?
| n + 2 =>
simp only [leftInv, neg_inj]
refine Finset.sum_congr rfl fun c cuniv => ?_
rcases c with ⟨c, hc⟩
ext v
dsimp
simp [IH _ hc]
#align formal_multilinear_series.left_inv_remove_zero FormalMultilinearSeries.leftInv_removeZero
/-- The left inverse to a formal multilinear series is indeed a left inverse, provided its linear
term is invertible. -/
theorem leftInv_comp (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuousMultilinearCurryFin1 𝕜 E F).symm i) : (leftInv p i).comp p = id 𝕜 E := by
ext (n v)
match n with
| 0 =>
simp only [leftInv_coeff_zero, ContinuousMultilinearMap.zero_apply, id_apply_ne_one, Ne,
not_false_iff, zero_ne_one, comp_coeff_zero']
| 1 =>
simp only [leftInv_coeff_one, comp_coeff_one, h, id_apply_one, ContinuousLinearEquiv.coe_apply,
ContinuousLinearEquiv.symm_apply_apply, continuousMultilinearCurryFin1_symm_apply]
| n + 2 =>
have A :
(Finset.univ : Finset (Composition (n + 2))) =
{c | Composition.length c < n + 2}.toFinset ∪ {Composition.ones (n + 2)} := by
refine Subset.antisymm (fun c _ => ?_) (subset_univ _)
by_cases h : c.length < n + 2
· simp [h, Set.mem_toFinset (s := {c | Composition.length c < n + 2})]
· simp [Composition.eq_ones_iff_le_length.2 (not_lt.1 h)]
have B :
Disjoint ({c | Composition.length c < n + 2} : Set (Composition (n + 2))).toFinset
{Composition.ones (n + 2)} := by
simp [Set.mem_toFinset (s := {c | Composition.length c < n + 2})]
have C :
((p.leftInv i (Composition.ones (n + 2)).length)
fun j : Fin (Composition.ones n.succ.succ).length =>
p 1 fun _ => v ((Fin.castLE (Composition.length_le _)) j)) =
p.leftInv i (n + 2) fun j : Fin (n + 2) => p 1 fun _ => v j := by
apply FormalMultilinearSeries.congr _ (Composition.ones_length _) fun j hj1 hj2 => ?_
exact FormalMultilinearSeries.congr _ rfl fun k _ _ => by congr
have D :
(p.leftInv i (n + 2) fun j : Fin (n + 2) => p 1 fun _ => v j) =
-∑ c ∈ {c : Composition (n + 2) | c.length < n + 2}.toFinset,
(p.leftInv i c.length) (p.applyComposition c v) := by
simp only [leftInv, ContinuousMultilinearMap.neg_apply, neg_inj,
ContinuousMultilinearMap.sum_apply]
convert
(sum_toFinset_eq_subtype
(fun c : Composition (n + 2) => c.length < n + 2)
(fun c : Composition (n + 2) =>
(ContinuousMultilinearMap.compAlongComposition
(p.compContinuousLinearMap (i.symm : F →L[𝕜] E)) c (p.leftInv i c.length))
fun j : Fin (n + 2) => p 1 fun _ : Fin 1 => v j)).symm.trans
_
simp only [compContinuousLinearMap_applyComposition,
ContinuousMultilinearMap.compAlongComposition_apply]
congr
ext c
congr
ext k
simp [h, Function.comp]
simp [FormalMultilinearSeries.comp, show n + 2 ≠ 1 by omega, A, Finset.sum_union B,
applyComposition_ones, C, D, -Set.toFinset_setOf]
#align formal_multilinear_series.left_inv_comp FormalMultilinearSeries.leftInv_comp
/-! ### The right inverse of a formal multilinear series -/
/-- The right inverse of a formal multilinear series, where the `n`-th term is defined inductively
in terms of the previous ones to make sure that `p ∘ (rightInv p i) = id`. For this, the linear
term `p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should
coincide with `p₁`, so that one can use its inverse in the construction. The definition does not
use that `i = p₁`, but proofs that the definition is well-behaved do.
The `n`-th term in `p ∘ q` is `∑ pₖ (q_{j₁}, ..., q_{jₖ})` over `j₁ + ... + jₖ = n`. In this
expression, `qₙ` appears only once, in `p₁ (qₙ)`. We adjust the definition of `qₙ` so that this
term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`.
These formulas only make sense when the constant term `p₀` vanishes. The definition we give is
general, but it ignores the value of `p₀`.
-/
noncomputable def rightInv (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) :
FormalMultilinearSeries 𝕜 F E
| 0 => 0
| 1 => (continuousMultilinearCurryFin1 𝕜 F E).symm i.symm
| n + 2 =>
let q : FormalMultilinearSeries 𝕜 F E := fun k => if k < n + 2 then rightInv p i k else 0;
-(i.symm : F →L[𝕜] E).compContinuousMultilinearMap ((p.comp q) (n + 2))
#align formal_multilinear_series.right_inv FormalMultilinearSeries.rightInv
@[simp]
theorem rightInv_coeff_zero (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) :
p.rightInv i 0 = 0 := by rw [rightInv]
#align formal_multilinear_series.right_inv_coeff_zero FormalMultilinearSeries.rightInv_coeff_zero
@[simp]
theorem rightInv_coeff_one (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) :
p.rightInv i 1 = (continuousMultilinearCurryFin1 𝕜 F E).symm i.symm := by rw [rightInv]
#align formal_multilinear_series.right_inv_coeff_one FormalMultilinearSeries.rightInv_coeff_one
/-- The right inverse does not depend on the zeroth coefficient of a formal multilinear
series. -/
theorem rightInv_removeZero (p : FormalMultilinearSeries 𝕜 E F) (i : E ≃L[𝕜] F) :
p.removeZero.rightInv i = p.rightInv i := by
ext1 n
induction' n using Nat.strongRec' with n IH
match n with
| 0 => simp only [rightInv_coeff_zero]
| 1 => simp only [rightInv_coeff_one]
| n + 2 =>
simp only [rightInv, neg_inj]
rw [removeZero_comp_of_pos _ _ (add_pos_of_nonneg_of_pos n.zero_le zero_lt_two)]
congr (config := { closePost := false }) 2 with k
by_cases hk : k < n + 2 <;> simp [hk, IH]
#align formal_multilinear_series.right_inv_remove_zero FormalMultilinearSeries.rightInv_removeZero
| Mathlib/Analysis/Analytic/Inverse.lean | 202 | 228 | theorem comp_rightInv_aux1 {n : ℕ} (hn : 0 < n) (p : FormalMultilinearSeries 𝕜 E F)
(q : FormalMultilinearSeries 𝕜 F E) (v : Fin n → F) :
p.comp q n v =
∑ c ∈ {c : Composition n | 1 < c.length}.toFinset,
p c.length (q.applyComposition c v) +
p 1 fun _ => q n v := by |
have A :
(Finset.univ : Finset (Composition n)) =
{c | 1 < Composition.length c}.toFinset ∪ {Composition.single n hn} := by
refine Subset.antisymm (fun c _ => ?_) (subset_univ _)
by_cases h : 1 < c.length
· simp [h, Set.mem_toFinset (s := {c | 1 < Composition.length c})]
· have : c.length = 1 := by
refine (eq_iff_le_not_lt.2 ⟨?_, h⟩).symm; exact c.length_pos_of_pos hn
rw [← Composition.eq_single_iff_length hn] at this
simp [this]
have B :
Disjoint ({c | 1 < Composition.length c} : Set (Composition n)).toFinset
{Composition.single n hn} := by
simp [Set.mem_toFinset (s := {c | 1 < Composition.length c})]
have C :
p (Composition.single n hn).length (q.applyComposition (Composition.single n hn) v) =
p 1 fun _ : Fin 1 => q n v := by
apply p.congr (Composition.single_length hn) fun j hj1 _ => ?_
simp [applyComposition_single]
simp [FormalMultilinearSeries.comp, A, Finset.sum_union B, C, -Set.toFinset_setOf,
-add_right_inj, -Composition.single_length]
|
/-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.MeasureTheory.Measure.VectorMeasure
import Mathlib.Order.SymmDiff
#align_import measure_theory.decomposition.signed_hahn from "leanprover-community/mathlib"@"bc7d81beddb3d6c66f71449c5bc76c38cb77cf9e"
/-!
# Hahn decomposition
This file proves the Hahn decomposition theorem (signed version). The Hahn decomposition theorem
states that, given a signed measure `s`, there exist complementary, measurable sets `i` and `j`,
such that `i` is positive and `j` is negative with respect to `s`; that is, `s` restricted on `i`
is non-negative and `s` restricted on `j` is non-positive.
The Hahn decomposition theorem leads to many other results in measure theory, most notably,
the Jordan decomposition theorem, the Lebesgue decomposition theorem and the Radon-Nikodym theorem.
## Main results
* `MeasureTheory.SignedMeasure.exists_isCompl_positive_negative` : the Hahn decomposition
theorem.
* `MeasureTheory.SignedMeasure.exists_subset_restrict_nonpos` : A measurable set of negative
measure contains a negative subset.
## Notation
We use the notations `0 ≤[i] s` and `s ≤[i] 0` to denote the usual definitions of a set `i`
being positive/negative with respect to the signed measure `s`.
## Tags
Hahn decomposition theorem
-/
noncomputable section
open scoped Classical NNReal ENNReal MeasureTheory
variable {α β : Type*} [MeasurableSpace α]
variable {M : Type*} [AddCommMonoid M] [TopologicalSpace M] [OrderedAddCommMonoid M]
namespace MeasureTheory
namespace SignedMeasure
open Filter VectorMeasure
variable {s : SignedMeasure α} {i j : Set α}
section ExistsSubsetRestrictNonpos
/-! ### exists_subset_restrict_nonpos
In this section we will prove that a set `i` whose measure is negative contains a negative subset
`j` with respect to the signed measure `s` (i.e. `s ≤[j] 0`), whose measure is negative. This lemma
is used to prove the Hahn decomposition theorem.
To prove this lemma, we will construct a sequence of measurable sets $(A_n)_{n \in \mathbb{N}}$,
such that, for all $n$, $s(A_{n + 1})$ is close to maximal among subsets of
$i \setminus \bigcup_{k \le n} A_k$.
This sequence of sets does not necessarily exist. However, if this sequence terminates; that is,
there does not exists any sets satisfying the property, the last $A_n$ will be a negative subset
of negative measure, hence proving our claim.
In the case that the sequence does not terminate, it is easy to see that
$i \setminus \bigcup_{k = 0}^\infty A_k$ is the required negative set.
To implement this in Lean, we define several auxiliary definitions.
- given the sets `i` and the natural number `n`, `ExistsOneDivLT s i n` is the property that
there exists a measurable set `k ⊆ i` such that `1 / (n + 1) < s k`.
- given the sets `i` and that `i` is not negative, `findExistsOneDivLT s i` is the
least natural number `n` such that `ExistsOneDivLT s i n`.
- given the sets `i` and that `i` is not negative, `someExistsOneDivLT` chooses the set
`k` from `ExistsOneDivLT s i (findExistsOneDivLT s i)`.
- lastly, given the set `i`, `restrictNonposSeq s i` is the sequence of sets defined inductively
where
`restrictNonposSeq s i 0 = someExistsOneDivLT s (i \ ∅)` and
`restrictNonposSeq s i (n + 1) = someExistsOneDivLT s (i \ ⋃ k ≤ n, restrictNonposSeq k)`.
This definition represents the sequence $(A_n)$ in the proof as described above.
With these definitions, we are able consider the case where the sequence terminates separately,
allowing us to prove `exists_subset_restrict_nonpos`.
-/
/-- Given the set `i` and the natural number `n`, `ExistsOneDivLT s i j` is the property that
there exists a measurable set `k ⊆ i` such that `1 / (n + 1) < s k`. -/
private def ExistsOneDivLT (s : SignedMeasure α) (i : Set α) (n : ℕ) : Prop :=
∃ k : Set α, k ⊆ i ∧ MeasurableSet k ∧ (1 / (n + 1) : ℝ) < s k
private theorem existsNatOneDivLTMeasure_of_not_negative (hi : ¬s ≤[i] 0) :
∃ n : ℕ, ExistsOneDivLT s i n :=
let ⟨k, hj₁, hj₂, hj⟩ := exists_pos_measure_of_not_restrict_le_zero s hi
let ⟨n, hn⟩ := exists_nat_one_div_lt hj
⟨n, k, hj₂, hj₁, hn⟩
/-- Given the set `i`, if `i` is not negative, `findExistsOneDivLT s i` is the
least natural number `n` such that `ExistsOneDivLT s i n`, otherwise, it returns 0. -/
private def findExistsOneDivLT (s : SignedMeasure α) (i : Set α) : ℕ :=
if hi : ¬s ≤[i] 0 then Nat.find (existsNatOneDivLTMeasure_of_not_negative hi) else 0
private theorem findExistsOneDivLT_spec (hi : ¬s ≤[i] 0) :
ExistsOneDivLT s i (findExistsOneDivLT s i) := by
rw [findExistsOneDivLT, dif_pos hi]
convert Nat.find_spec (existsNatOneDivLTMeasure_of_not_negative hi)
private theorem findExistsOneDivLT_min (hi : ¬s ≤[i] 0) {m : ℕ}
(hm : m < findExistsOneDivLT s i) : ¬ExistsOneDivLT s i m := by
rw [findExistsOneDivLT, dif_pos hi] at hm
exact Nat.find_min _ hm
/-- Given the set `i`, if `i` is not negative, `someExistsOneDivLT` chooses the set
`k` from `ExistsOneDivLT s i (findExistsOneDivLT s i)`, otherwise, it returns the
empty set. -/
private def someExistsOneDivLT (s : SignedMeasure α) (i : Set α) : Set α :=
if hi : ¬s ≤[i] 0 then Classical.choose (findExistsOneDivLT_spec hi) else ∅
private theorem someExistsOneDivLT_spec (hi : ¬s ≤[i] 0) :
someExistsOneDivLT s i ⊆ i ∧
MeasurableSet (someExistsOneDivLT s i) ∧
(1 / (findExistsOneDivLT s i + 1) : ℝ) < s (someExistsOneDivLT s i) := by
rw [someExistsOneDivLT, dif_pos hi]
exact Classical.choose_spec (findExistsOneDivLT_spec hi)
private theorem someExistsOneDivLT_subset : someExistsOneDivLT s i ⊆ i := by
by_cases hi : ¬s ≤[i] 0
· exact
let ⟨h, _⟩ := someExistsOneDivLT_spec hi
h
· rw [someExistsOneDivLT, dif_neg hi]
exact Set.empty_subset _
private theorem someExistsOneDivLT_subset' : someExistsOneDivLT s (i \ j) ⊆ i :=
someExistsOneDivLT_subset.trans Set.diff_subset
private theorem someExistsOneDivLT_measurableSet : MeasurableSet (someExistsOneDivLT s i) := by
by_cases hi : ¬s ≤[i] 0
· exact
let ⟨_, h, _⟩ := someExistsOneDivLT_spec hi
h
· rw [someExistsOneDivLT, dif_neg hi]
exact MeasurableSet.empty
private theorem someExistsOneDivLT_lt (hi : ¬s ≤[i] 0) :
(1 / (findExistsOneDivLT s i + 1) : ℝ) < s (someExistsOneDivLT s i) :=
let ⟨_, _, h⟩ := someExistsOneDivLT_spec hi
h
/-- Given the set `i`, `restrictNonposSeq s i` is the sequence of sets defined inductively where
`restrictNonposSeq s i 0 = someExistsOneDivLT s (i \ ∅)` and
`restrictNonposSeq s i (n + 1) = someExistsOneDivLT s (i \ ⋃ k ≤ n, restrictNonposSeq k)`.
For each `n : ℕ`,`s (restrictNonposSeq s i n)` is close to maximal among all subsets of
`i \ ⋃ k ≤ n, restrictNonposSeq s i k`. -/
private def restrictNonposSeq (s : SignedMeasure α) (i : Set α) : ℕ → Set α
| 0 => someExistsOneDivLT s (i \ ∅) -- I used `i \ ∅` instead of `i` to simplify some proofs
| n + 1 =>
someExistsOneDivLT s
(i \
⋃ (k) (H : k ≤ n),
have : k < n + 1 := Nat.lt_succ_iff.mpr H
restrictNonposSeq s i k)
private theorem restrictNonposSeq_succ (n : ℕ) :
restrictNonposSeq s i n.succ = someExistsOneDivLT s (i \ ⋃ k ≤ n, restrictNonposSeq s i k) := by
rw [restrictNonposSeq]
private theorem restrictNonposSeq_subset (n : ℕ) : restrictNonposSeq s i n ⊆ i := by
cases n <;> · rw [restrictNonposSeq]; exact someExistsOneDivLT_subset'
private theorem restrictNonposSeq_lt (n : ℕ) (hn : ¬s ≤[i \ ⋃ k ≤ n, restrictNonposSeq s i k] 0) :
(1 / (findExistsOneDivLT s (i \ ⋃ k ≤ n, restrictNonposSeq s i k) + 1) : ℝ) <
s (restrictNonposSeq s i n.succ) := by
rw [restrictNonposSeq_succ]
apply someExistsOneDivLT_lt hn
private theorem measure_of_restrictNonposSeq (hi₂ : ¬s ≤[i] 0) (n : ℕ)
(hn : ¬s ≤[i \ ⋃ k < n, restrictNonposSeq s i k] 0) : 0 < s (restrictNonposSeq s i n) := by
cases n with
| zero =>
rw [restrictNonposSeq]; rw [← @Set.diff_empty _ i] at hi₂
rcases someExistsOneDivLT_spec hi₂ with ⟨_, _, h⟩
exact lt_trans Nat.one_div_pos_of_nat h
| succ n =>
rw [restrictNonposSeq_succ]
have h₁ : ¬s ≤[i \ ⋃ (k : ℕ) (_ : k ≤ n), restrictNonposSeq s i k] 0 := by
refine mt (restrict_le_zero_subset _ ?_ (by simp [Nat.lt_succ_iff]; rfl)) hn
convert measurable_of_not_restrict_le_zero _ hn using 3
exact funext fun x => by rw [Nat.lt_succ_iff]
rcases someExistsOneDivLT_spec h₁ with ⟨_, _, h⟩
exact lt_trans Nat.one_div_pos_of_nat h
private theorem restrictNonposSeq_measurableSet (n : ℕ) :
MeasurableSet (restrictNonposSeq s i n) := by
cases n <;>
· rw [restrictNonposSeq]
exact someExistsOneDivLT_measurableSet
private theorem restrictNonposSeq_disjoint' {n m : ℕ} (h : n < m) :
restrictNonposSeq s i n ∩ restrictNonposSeq s i m = ∅ := by
rw [Set.eq_empty_iff_forall_not_mem]
rintro x ⟨hx₁, hx₂⟩
cases m; · omega
· rw [restrictNonposSeq] at hx₂
exact
(someExistsOneDivLT_subset hx₂).2
(Set.mem_iUnion.2 ⟨n, Set.mem_iUnion.2 ⟨Nat.lt_succ_iff.mp h, hx₁⟩⟩)
private theorem restrictNonposSeq_disjoint : Pairwise (Disjoint on restrictNonposSeq s i) := by
intro n m h
rw [Function.onFun, Set.disjoint_iff_inter_eq_empty]
rcases lt_or_gt_of_ne h with (h | h)
· rw [restrictNonposSeq_disjoint' h]
· rw [Set.inter_comm, restrictNonposSeq_disjoint' h]
private theorem exists_subset_restrict_nonpos' (hi₁ : MeasurableSet i) (hi₂ : s i < 0)
(hn : ¬∀ n : ℕ, ¬s ≤[i \ ⋃ l < n, restrictNonposSeq s i l] 0) :
∃ j : Set α, MeasurableSet j ∧ j ⊆ i ∧ s ≤[j] 0 ∧ s j < 0 := by
by_cases h : s ≤[i] 0
· exact ⟨i, hi₁, Set.Subset.refl _, h, hi₂⟩
push_neg at hn
set k := Nat.find hn
have hk₂ : s ≤[i \ ⋃ l < k, restrictNonposSeq s i l] 0 := Nat.find_spec hn
have hmeas : MeasurableSet (⋃ (l : ℕ) (_ : l < k), restrictNonposSeq s i l) :=
MeasurableSet.iUnion fun _ => MeasurableSet.iUnion fun _ => restrictNonposSeq_measurableSet _
refine ⟨i \ ⋃ l < k, restrictNonposSeq s i l, hi₁.diff hmeas, Set.diff_subset, hk₂, ?_⟩
rw [of_diff hmeas hi₁, s.of_disjoint_iUnion_nat]
· have h₁ : ∀ l < k, 0 ≤ s (restrictNonposSeq s i l) := by
intro l hl
refine le_of_lt (measure_of_restrictNonposSeq h _ ?_)
refine mt (restrict_le_zero_subset _ (hi₁.diff ?_) (Set.Subset.refl _)) (Nat.find_min hn hl)
exact
MeasurableSet.iUnion fun _ =>
MeasurableSet.iUnion fun _ => restrictNonposSeq_measurableSet _
suffices 0 ≤ ∑' l : ℕ, s (⋃ _ : l < k, restrictNonposSeq s i l) by
rw [sub_neg]
exact lt_of_lt_of_le hi₂ this
refine tsum_nonneg ?_
intro l; by_cases h : l < k
· convert h₁ _ h
ext x
rw [Set.mem_iUnion, exists_prop, and_iff_right_iff_imp]
exact fun _ => h
· convert le_of_eq s.empty.symm
ext; simp only [exists_prop, Set.mem_empty_iff_false, Set.mem_iUnion, not_and, iff_false_iff]
exact fun h' => False.elim (h h')
· intro; exact MeasurableSet.iUnion fun _ => restrictNonposSeq_measurableSet _
· intro a b hab
refine Set.disjoint_iUnion_left.mpr fun _ => ?_
refine Set.disjoint_iUnion_right.mpr fun _ => ?_
exact restrictNonposSeq_disjoint hab
· apply Set.iUnion_subset
intro a x
simp only [and_imp, exists_prop, Set.mem_iUnion]
intro _ hx
exact restrictNonposSeq_subset _ hx
/-- A measurable set of negative measure has a negative subset of negative measure. -/
| Mathlib/MeasureTheory/Decomposition/SignedHahn.lean | 266 | 328 | theorem exists_subset_restrict_nonpos (hi : s i < 0) :
∃ j : Set α, MeasurableSet j ∧ j ⊆ i ∧ s ≤[j] 0 ∧ s j < 0 := by |
have hi₁ : MeasurableSet i := by_contradiction fun h => ne_of_lt hi <| s.not_measurable h
by_cases h : s ≤[i] 0; · exact ⟨i, hi₁, Set.Subset.refl _, h, hi⟩
by_cases hn : ∀ n : ℕ, ¬s ≤[i \ ⋃ l < n, restrictNonposSeq s i l] 0
swap; · exact exists_subset_restrict_nonpos' hi₁ hi hn
set A := i \ ⋃ l, restrictNonposSeq s i l with hA
set bdd : ℕ → ℕ := fun n => findExistsOneDivLT s (i \ ⋃ k ≤ n, restrictNonposSeq s i k)
have hn' : ∀ n : ℕ, ¬s ≤[i \ ⋃ l ≤ n, restrictNonposSeq s i l] 0 := by
intro n
convert hn (n + 1) using 5 <;>
· ext l
simp only [exists_prop, Set.mem_iUnion, and_congr_left_iff]
exact fun _ => Nat.lt_succ_iff.symm
have h₁ : s i = s A + ∑' l, s (restrictNonposSeq s i l) := by
rw [hA, ← s.of_disjoint_iUnion_nat, add_comm, of_add_of_diff]
· exact MeasurableSet.iUnion fun _ => restrictNonposSeq_measurableSet _
exacts [hi₁, Set.iUnion_subset fun _ => restrictNonposSeq_subset _, fun _ =>
restrictNonposSeq_measurableSet _, restrictNonposSeq_disjoint]
have h₂ : s A ≤ s i := by
rw [h₁]
apply le_add_of_nonneg_right
exact tsum_nonneg fun n => le_of_lt (measure_of_restrictNonposSeq h _ (hn n))
have h₃' : Summable fun n => (1 / (bdd n + 1) : ℝ) := by
have : Summable fun l => s (restrictNonposSeq s i l) :=
HasSum.summable
(s.m_iUnion (fun _ => restrictNonposSeq_measurableSet _) restrictNonposSeq_disjoint)
refine .of_nonneg_of_le (fun n => ?_) (fun n => ?_)
(this.comp_injective Nat.succ_injective)
· exact le_of_lt Nat.one_div_pos_of_nat
· exact le_of_lt (restrictNonposSeq_lt n (hn' n))
have h₃ : Tendsto (fun n => (bdd n : ℝ) + 1) atTop atTop := by
simp only [one_div] at h₃'
exact Summable.tendsto_atTop_of_pos h₃' fun n => Nat.cast_add_one_pos (bdd n)
have h₄ : Tendsto (fun n => (bdd n : ℝ)) atTop atTop := by
convert atTop.tendsto_atTop_add_const_right (-1) h₃; simp
have A_meas : MeasurableSet A :=
hi₁.diff (MeasurableSet.iUnion fun _ => restrictNonposSeq_measurableSet _)
refine ⟨A, A_meas, Set.diff_subset, ?_, h₂.trans_lt hi⟩
by_contra hnn
rw [restrict_le_restrict_iff _ _ A_meas] at hnn; push_neg at hnn
obtain ⟨E, hE₁, hE₂, hE₃⟩ := hnn
have : ∃ k, 1 ≤ bdd k ∧ 1 / (bdd k : ℝ) < s E := by
rw [tendsto_atTop_atTop] at h₄
obtain ⟨k, hk⟩ := h₄ (max (1 / s E + 1) 1)
refine ⟨k, ?_, ?_⟩
· have hle := le_of_max_le_right (hk k le_rfl)
norm_cast at hle
· have : 1 / s E < bdd k := by
linarith only [le_of_max_le_left (hk k le_rfl)]
rw [one_div] at this ⊢
rwa [inv_lt (lt_trans (inv_pos.2 hE₃) this) hE₃]
obtain ⟨k, hk₁, hk₂⟩ := this
have hA' : A ⊆ i \ ⋃ l ≤ k, restrictNonposSeq s i l := by
apply Set.diff_subset_diff_right
intro x; simp only [Set.mem_iUnion]
rintro ⟨n, _, hn₂⟩
exact ⟨n, hn₂⟩
refine
findExistsOneDivLT_min (hn' k) (Nat.sub_lt hk₁ Nat.zero_lt_one)
⟨E, Set.Subset.trans hE₂ hA', hE₁, ?_⟩
convert hk₂; norm_cast
exact tsub_add_cancel_of_le hk₁
|
/-
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.Ring.Defs
import Mathlib.Algebra.Group.Int
import Mathlib.Data.Nat.Dist
import Mathlib.Data.Ordmap.Ordnode
import Mathlib.Tactic.Abel
import Mathlib.Tactic.Linarith
#align_import data.ordmap.ordset from "leanprover-community/mathlib"@"47b51515e69f59bca5cf34ef456e6000fe205a69"
/-!
# Verification of the `Ordnode α` datatype
This file proves the correctness of the operations in `Data.Ordmap.Ordnode`.
The public facing version is the type `Ordset α`, which is a wrapper around
`Ordnode α` which includes the correctness invariant of the type, and 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
* `Ordset α`: A well formed set of values of type `α`
## Implementation notes
The majority of this file is actually in the `Ordnode` namespace, because we first
have to prove the correctness of all the operations (and defining what correctness
means here is actually somewhat subtle). So all the actual `Ordset` operations are
at the very end, once we have all the theorems.
An `Ordnode α` is an inductive type which describes a tree which stores the `size` at
internal nodes. The correctness invariant of an `Ordnode α` is:
* `Ordnode.Sized t`: All internal `size` fields must match the actual measured
size of the tree. (This is not hard to satisfy.)
* `Ordnode.Balanced t`: Unless the tree has the form `()` or `((a) b)` or `(a (b))`
(that is, nil or a single singleton subtree), the two subtrees must satisfy
`size l ≤ δ * size r` and `size r ≤ δ * size l`, where `δ := 3` is a global
parameter of the data structure (and this property must hold recursively at subtrees).
This is why we say this is a "size balanced tree" data structure.
* `Ordnode.Bounded lo hi t`: The members of the tree must be in strictly increasing order,
meaning that if `a` is in the left subtree and `b` is the root, then `a ≤ b` and
`¬ (b ≤ a)`. We enforce this using `Ordnode.Bounded` which includes also a global
upper and lower bound.
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.
**Note:** This file is incomplete, in the sense that the intent is to have verified
versions and lemmas about all the definitions in `Ordnode.lean`, but at the moment only
a few operations are verified (the hard part should be out of the way, but still).
Contributors are encouraged to pick this up and finish the job, if it appeals to you.
## Tags
ordered map, ordered set, data structure, verified programming
-/
variable {α : Type*}
namespace Ordnode
/-! ### delta and ratio -/
theorem not_le_delta {s} (H : 1 ≤ s) : ¬s ≤ delta * 0 :=
not_le_of_gt H
#align ordnode.not_le_delta Ordnode.not_le_delta
theorem delta_lt_false {a b : ℕ} (h₁ : delta * a < b) (h₂ : delta * b < a) : False :=
not_le_of_lt (lt_trans ((mul_lt_mul_left (by decide)).2 h₁) h₂) <| by
simpa [mul_assoc] using Nat.mul_le_mul_right a (by decide : 1 ≤ delta * delta)
#align ordnode.delta_lt_false Ordnode.delta_lt_false
/-! ### `singleton` -/
/-! ### `size` and `empty` -/
/-- O(n). Computes the actual number of elements in the set, ignoring the cached `size` field. -/
def realSize : Ordnode α → ℕ
| nil => 0
| node _ l _ r => realSize l + realSize r + 1
#align ordnode.real_size Ordnode.realSize
/-! ### `Sized` -/
/-- The `Sized` property asserts that all the `size` fields in nodes match the actual size of the
respective subtrees. -/
def Sized : Ordnode α → Prop
| nil => True
| node s l _ r => s = size l + size r + 1 ∧ Sized l ∧ Sized r
#align ordnode.sized Ordnode.Sized
theorem Sized.node' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (node' l x r) :=
⟨rfl, hl, hr⟩
#align ordnode.sized.node' Ordnode.Sized.node'
theorem Sized.eq_node' {s l x r} (h : @Sized α (node s l x r)) : node s l x r = .node' l x r := by
rw [h.1]
#align ordnode.sized.eq_node' Ordnode.Sized.eq_node'
theorem Sized.size_eq {s l x r} (H : Sized (@node α s l x r)) :
size (@node α s l x r) = size l + size r + 1 :=
H.1
#align ordnode.sized.size_eq Ordnode.Sized.size_eq
@[elab_as_elim]
theorem Sized.induction {t} (hl : @Sized α t) {C : Ordnode α → Prop} (H0 : C nil)
(H1 : ∀ l x r, C l → C r → C (.node' l x r)) : C t := by
induction t with
| nil => exact H0
| node _ _ _ _ t_ih_l t_ih_r =>
rw [hl.eq_node']
exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2)
#align ordnode.sized.induction Ordnode.Sized.induction
theorem size_eq_realSize : ∀ {t : Ordnode α}, Sized t → size t = realSize t
| nil, _ => rfl
| node s l x r, ⟨h₁, h₂, h₃⟩ => by
rw [size, h₁, size_eq_realSize h₂, size_eq_realSize h₃]; rfl
#align ordnode.size_eq_real_size Ordnode.size_eq_realSize
@[simp]
theorem Sized.size_eq_zero {t : Ordnode α} (ht : Sized t) : size t = 0 ↔ t = nil := by
cases t <;> [simp;simp [ht.1]]
#align ordnode.sized.size_eq_zero Ordnode.Sized.size_eq_zero
theorem Sized.pos {s l x r} (h : Sized (@node α s l x r)) : 0 < s := by
rw [h.1]; apply Nat.le_add_left
#align ordnode.sized.pos Ordnode.Sized.pos
/-! `dual` -/
theorem dual_dual : ∀ t : Ordnode α, dual (dual t) = t
| nil => rfl
| node s l x r => by rw [dual, dual, dual_dual l, dual_dual r]
#align ordnode.dual_dual Ordnode.dual_dual
@[simp]
theorem size_dual (t : Ordnode α) : size (dual t) = size t := by cases t <;> rfl
#align ordnode.size_dual Ordnode.size_dual
/-! `Balanced` -/
/-- The `BalancedSz l r` asserts that a hypothetical tree with children of sizes `l` and `r` is
balanced: either `l ≤ δ * r` and `r ≤ δ * r`, or the tree is trivial with a singleton on one side
and nothing on the other. -/
def BalancedSz (l r : ℕ) : Prop :=
l + r ≤ 1 ∨ l ≤ delta * r ∧ r ≤ delta * l
#align ordnode.balanced_sz Ordnode.BalancedSz
instance BalancedSz.dec : DecidableRel BalancedSz := fun _ _ => Or.decidable
#align ordnode.balanced_sz.dec Ordnode.BalancedSz.dec
/-- The `Balanced t` asserts that the tree `t` satisfies the balance invariants
(at every level). -/
def Balanced : Ordnode α → Prop
| nil => True
| node _ l _ r => BalancedSz (size l) (size r) ∧ Balanced l ∧ Balanced r
#align ordnode.balanced Ordnode.Balanced
instance Balanced.dec : DecidablePred (@Balanced α)
| nil => by
unfold Balanced
infer_instance
| node _ l _ r => by
unfold Balanced
haveI := Balanced.dec l
haveI := Balanced.dec r
infer_instance
#align ordnode.balanced.dec Ordnode.Balanced.dec
@[symm]
theorem BalancedSz.symm {l r : ℕ} : BalancedSz l r → BalancedSz r l :=
Or.imp (by rw [add_comm]; exact id) And.symm
#align ordnode.balanced_sz.symm Ordnode.BalancedSz.symm
theorem balancedSz_zero {l : ℕ} : BalancedSz l 0 ↔ l ≤ 1 := by
simp (config := { contextual := true }) [BalancedSz]
#align ordnode.balanced_sz_zero Ordnode.balancedSz_zero
theorem balancedSz_up {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l)
(H : BalancedSz l r₁) : BalancedSz l r₂ := by
refine or_iff_not_imp_left.2 fun h => ?_
refine ⟨?_, h₂.resolve_left h⟩
cases H with
| inl H =>
cases r₂
· cases h (le_trans (Nat.add_le_add_left (Nat.zero_le _) _) H)
· exact le_trans (le_trans (Nat.le_add_right _ _) H) (Nat.le_add_left 1 _)
| inr H =>
exact le_trans H.1 (Nat.mul_le_mul_left _ h₁)
#align ordnode.balanced_sz_up Ordnode.balancedSz_up
theorem balancedSz_down {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ l ≤ delta * r₁)
(H : BalancedSz l r₂) : BalancedSz l r₁ :=
have : l + r₂ ≤ 1 → BalancedSz l r₁ := fun H => Or.inl (le_trans (Nat.add_le_add_left h₁ _) H)
Or.casesOn H this fun H => Or.casesOn h₂ this fun h₂ => Or.inr ⟨h₂, le_trans h₁ H.2⟩
#align ordnode.balanced_sz_down Ordnode.balancedSz_down
theorem Balanced.dual : ∀ {t : Ordnode α}, Balanced t → Balanced (dual t)
| nil, _ => ⟨⟩
| node _ l _ r, ⟨b, bl, br⟩ => ⟨by rw [size_dual, size_dual]; exact b.symm, br.dual, bl.dual⟩
#align ordnode.balanced.dual Ordnode.Balanced.dual
/-! ### `rotate` and `balance` -/
/-- Build a tree from three nodes, left associated (ignores the invariants). -/
def node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α :=
node' (node' l x m) y r
#align ordnode.node3_l Ordnode.node3L
/-- Build a tree from three nodes, right associated (ignores the invariants). -/
def node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α :=
node' l x (node' m y r)
#align ordnode.node3_r Ordnode.node3R
/-- Build a tree from three nodes, with `a () b -> (a ()) b` and `a (b c) d -> ((a b) (c d))`. -/
def node4L : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α
| l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r)
| l, x, nil, z, r => node3L l x nil z r
#align ordnode.node4_l Ordnode.node4L
-- should not happen
/-- Build a tree from three nodes, with `a () b -> a (() b)` and `a (b c) d -> ((a b) (c d))`. -/
def node4R : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α
| l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r)
| l, x, nil, z, r => node3R l x nil z r
#align ordnode.node4_r Ordnode.node4R
-- should not happen
/-- Concatenate two nodes, performing a left rotation `x (y z) -> ((x y) z)`
if balance is upset. -/
def rotateL : Ordnode α → α → Ordnode α → Ordnode α
| l, x, node _ m y r => if size m < ratio * size r then node3L l x m y r else node4L l x m y r
| l, x, nil => node' l x nil
#align ordnode.rotate_l Ordnode.rotateL
-- Porting note (#11467): during the port we marked these lemmas with `@[eqns]`
-- to emulate the old Lean 3 behaviour.
theorem rotateL_node (l : Ordnode α) (x : α) (sz : ℕ) (m : Ordnode α) (y : α) (r : Ordnode α) :
rotateL l x (node sz m y r) =
if size m < ratio * size r then node3L l x m y r else node4L l x m y r :=
rfl
theorem rotateL_nil (l : Ordnode α) (x : α) : rotateL l x nil = node' l x nil :=
rfl
-- should not happen
/-- Concatenate two nodes, performing a right rotation `(x y) z -> (x (y z))`
if balance is upset. -/
def rotateR : Ordnode α → α → Ordnode α → Ordnode α
| node _ l x m, y, r => if size m < ratio * size l then node3R l x m y r else node4R l x m y r
| nil, y, r => node' nil y r
#align ordnode.rotate_r Ordnode.rotateR
-- Porting note (#11467): during the port we marked these lemmas with `@[eqns]`
-- to emulate the old Lean 3 behaviour.
theorem rotateR_node (sz : ℕ) (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
rotateR (node sz l x m) y r =
if size m < ratio * size l then node3R l x m y r else node4R l x m y r :=
rfl
theorem rotateR_nil (y : α) (r : Ordnode α) : rotateR nil y r = node' nil y r :=
rfl
-- should not happen
/-- A left balance operation. This will rebalance a concatenation, assuming the original nodes are
not too far from balanced. -/
def balanceL' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α :=
if size l + size r ≤ 1 then node' l x r
else if size l > delta * size r then rotateR l x r else node' l x r
#align ordnode.balance_l' Ordnode.balanceL'
/-- A right balance operation. This will rebalance a concatenation, assuming the original nodes are
not too far from balanced. -/
def balanceR' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α :=
if size l + size r ≤ 1 then node' l x r
else if size r > delta * size l then rotateL l x r else node' l x r
#align ordnode.balance_r' Ordnode.balanceR'
/-- The full balance operation. This is the same as `balance`, but with less manual inlining.
It is somewhat easier to work with this version in proofs. -/
def balance' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α :=
if size l + size r ≤ 1 then node' l x r
else
if size r > delta * size l then rotateL l x r
else if size l > delta * size r then rotateR l x r else node' l x r
#align ordnode.balance' Ordnode.balance'
theorem dual_node' (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (node' l x r) = node' (dual r) x (dual l) := by simp [node', add_comm]
#align ordnode.dual_node' Ordnode.dual_node'
theorem dual_node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node3L l x m y r) = node3R (dual r) y (dual m) x (dual l) := by
simp [node3L, node3R, dual_node', add_comm]
#align ordnode.dual_node3_l Ordnode.dual_node3L
theorem dual_node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node3R l x m y r) = node3L (dual r) y (dual m) x (dual l) := by
simp [node3L, node3R, dual_node', add_comm]
#align ordnode.dual_node3_r Ordnode.dual_node3R
theorem dual_node4L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node4L l x m y r) = node4R (dual r) y (dual m) x (dual l) := by
cases m <;> simp [node4L, node4R, node3R, dual_node3L, dual_node', add_comm]
#align ordnode.dual_node4_l Ordnode.dual_node4L
theorem dual_node4R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) :
dual (node4R l x m y r) = node4L (dual r) y (dual m) x (dual l) := by
cases m <;> simp [node4L, node4R, node3L, dual_node3R, dual_node', add_comm]
#align ordnode.dual_node4_r Ordnode.dual_node4R
theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (rotateL l x r) = rotateR (dual r) x (dual l) := by
cases r <;> simp [rotateL, rotateR, dual_node']; split_ifs <;>
simp [dual_node3L, dual_node4L, node3R, add_comm]
#align ordnode.dual_rotate_l Ordnode.dual_rotateL
theorem dual_rotateR (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (rotateR l x r) = rotateL (dual r) x (dual l) := by
rw [← dual_dual (rotateL _ _ _), dual_rotateL, dual_dual, dual_dual]
#align ordnode.dual_rotate_r Ordnode.dual_rotateR
theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (balance' l x r) = balance' (dual r) x (dual l) := by
simp [balance', add_comm]; split_ifs with h h_1 h_2 <;>
simp [dual_node', dual_rotateL, dual_rotateR, add_comm]
cases delta_lt_false h_1 h_2
#align ordnode.dual_balance' Ordnode.dual_balance'
theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (balanceL l x r) = balanceR (dual r) x (dual l) := by
unfold balanceL balanceR
cases' r with rs rl rx rr
· cases' l with ls ll lx lr; · rfl
cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;>
try rfl
split_ifs with h <;> repeat simp [h, add_comm]
· cases' l with ls ll lx lr; · rfl
dsimp only [dual, id]
split_ifs; swap; · simp [add_comm]
cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> try rfl
dsimp only [dual, id]
split_ifs with h <;> simp [h, add_comm]
#align ordnode.dual_balance_l Ordnode.dual_balanceL
theorem dual_balanceR (l : Ordnode α) (x : α) (r : Ordnode α) :
dual (balanceR l x r) = balanceL (dual r) x (dual l) := by
rw [← dual_dual (balanceL _ _ _), dual_balanceL, dual_dual, dual_dual]
#align ordnode.dual_balance_r Ordnode.dual_balanceR
theorem Sized.node3L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) :
Sized (node3L l x m y r) :=
(hl.node' hm).node' hr
#align ordnode.sized.node3_l Ordnode.Sized.node3L
theorem Sized.node3R {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) :
Sized (node3R l x m y r) :=
hl.node' (hm.node' hr)
#align ordnode.sized.node3_r Ordnode.Sized.node3R
theorem Sized.node4L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) :
Sized (node4L l x m y r) := by
cases m <;> [exact (hl.node' hm).node' hr; exact (hl.node' hm.2.1).node' (hm.2.2.node' hr)]
#align ordnode.sized.node4_l Ordnode.Sized.node4L
theorem node3L_size {l x m y r} : size (@node3L α l x m y r) = size l + size m + size r + 2 := by
dsimp [node3L, node', size]; rw [add_right_comm _ 1]
#align ordnode.node3_l_size Ordnode.node3L_size
theorem node3R_size {l x m y r} : size (@node3R α l x m y r) = size l + size m + size r + 2 := by
dsimp [node3R, node', size]; rw [← add_assoc, ← add_assoc]
#align ordnode.node3_r_size Ordnode.node3R_size
theorem node4L_size {l x m y r} (hm : Sized m) :
size (@node4L α l x m y r) = size l + size m + size r + 2 := by
cases m <;> simp [node4L, node3L, node'] <;> [abel; (simp [size, hm.1]; abel)]
#align ordnode.node4_l_size Ordnode.node4L_size
theorem Sized.dual : ∀ {t : Ordnode α}, Sized t → Sized (dual t)
| nil, _ => ⟨⟩
| node _ l _ r, ⟨rfl, sl, sr⟩ => ⟨by simp [size_dual, add_comm], Sized.dual sr, Sized.dual sl⟩
#align ordnode.sized.dual Ordnode.Sized.dual
theorem Sized.dual_iff {t : Ordnode α} : Sized (.dual t) ↔ Sized t :=
⟨fun h => by rw [← dual_dual t]; exact h.dual, Sized.dual⟩
#align ordnode.sized.dual_iff Ordnode.Sized.dual_iff
theorem Sized.rotateL {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateL l x r) := by
cases r; · exact hl.node' hr
rw [Ordnode.rotateL_node]; split_ifs
· exact hl.node3L hr.2.1 hr.2.2
· exact hl.node4L hr.2.1 hr.2.2
#align ordnode.sized.rotate_l Ordnode.Sized.rotateL
theorem Sized.rotateR {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateR l x r) :=
Sized.dual_iff.1 <| by rw [dual_rotateR]; exact hr.dual.rotateL hl.dual
#align ordnode.sized.rotate_r Ordnode.Sized.rotateR
theorem Sized.rotateL_size {l x r} (hm : Sized r) :
size (@Ordnode.rotateL α l x r) = size l + size r + 1 := by
cases r <;> simp [Ordnode.rotateL]
simp only [hm.1]
split_ifs <;> simp [node3L_size, node4L_size hm.2.1] <;> abel
#align ordnode.sized.rotate_l_size Ordnode.Sized.rotateL_size
theorem Sized.rotateR_size {l x r} (hl : Sized l) :
size (@Ordnode.rotateR α l x r) = size l + size r + 1 := by
rw [← size_dual, dual_rotateR, hl.dual.rotateL_size, size_dual, size_dual, add_comm (size l)]
#align ordnode.sized.rotate_r_size Ordnode.Sized.rotateR_size
theorem Sized.balance' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (balance' l x r) := by
unfold balance'; split_ifs
· exact hl.node' hr
· exact hl.rotateL hr
· exact hl.rotateR hr
· exact hl.node' hr
#align ordnode.sized.balance' Ordnode.Sized.balance'
theorem size_balance' {l x r} (hl : @Sized α l) (hr : Sized r) :
size (@balance' α l x r) = size l + size r + 1 := by
unfold balance'; split_ifs
· rfl
· exact hr.rotateL_size
· exact hl.rotateR_size
· rfl
#align ordnode.size_balance' Ordnode.size_balance'
/-! ## `All`, `Any`, `Emem`, `Amem` -/
theorem All.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, All P t → All Q t
| nil, _ => ⟨⟩
| node _ _ _ _, ⟨h₁, h₂, h₃⟩ => ⟨h₁.imp H, H _ h₂, h₃.imp H⟩
#align ordnode.all.imp Ordnode.All.imp
theorem Any.imp {P Q : α → Prop} (H : ∀ a, P a → Q a) : ∀ {t}, Any P t → Any Q t
| nil => id
| node _ _ _ _ => Or.imp (Any.imp H) <| Or.imp (H _) (Any.imp H)
#align ordnode.any.imp Ordnode.Any.imp
theorem all_singleton {P : α → Prop} {x : α} : All P (singleton x) ↔ P x :=
⟨fun h => h.2.1, fun h => ⟨⟨⟩, h, ⟨⟩⟩⟩
#align ordnode.all_singleton Ordnode.all_singleton
theorem any_singleton {P : α → Prop} {x : α} : Any P (singleton x) ↔ P x :=
⟨by rintro (⟨⟨⟩⟩ | h | ⟨⟨⟩⟩); exact h, fun h => Or.inr (Or.inl h)⟩
#align ordnode.any_singleton Ordnode.any_singleton
theorem all_dual {P : α → Prop} : ∀ {t : Ordnode α}, All P (dual t) ↔ All P t
| nil => Iff.rfl
| node _ _l _x _r =>
⟨fun ⟨hr, hx, hl⟩ => ⟨all_dual.1 hl, hx, all_dual.1 hr⟩, fun ⟨hl, hx, hr⟩ =>
⟨all_dual.2 hr, hx, all_dual.2 hl⟩⟩
#align ordnode.all_dual Ordnode.all_dual
theorem all_iff_forall {P : α → Prop} : ∀ {t}, All P t ↔ ∀ x, Emem x t → P x
| nil => (iff_true_intro <| by rintro _ ⟨⟩).symm
| node _ l x r => by simp [All, Emem, all_iff_forall, Any, or_imp, forall_and]
#align ordnode.all_iff_forall Ordnode.all_iff_forall
theorem any_iff_exists {P : α → Prop} : ∀ {t}, Any P t ↔ ∃ x, Emem x t ∧ P x
| nil => ⟨by rintro ⟨⟩, by rintro ⟨_, ⟨⟩, _⟩⟩
| node _ l x r => by simp only [Emem]; simp [Any, any_iff_exists, or_and_right, exists_or]
#align ordnode.any_iff_exists Ordnode.any_iff_exists
theorem emem_iff_all {x : α} {t} : Emem x t ↔ ∀ P, All P t → P x :=
⟨fun h _ al => all_iff_forall.1 al _ h, fun H => H _ <| all_iff_forall.2 fun _ => id⟩
#align ordnode.emem_iff_all Ordnode.emem_iff_all
theorem all_node' {P l x r} : @All α P (node' l x r) ↔ All P l ∧ P x ∧ All P r :=
Iff.rfl
#align ordnode.all_node' Ordnode.all_node'
theorem all_node3L {P l x m y r} :
@All α P (node3L l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by
simp [node3L, all_node', and_assoc]
#align ordnode.all_node3_l Ordnode.all_node3L
theorem all_node3R {P l x m y r} :
@All α P (node3R l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r :=
Iff.rfl
#align ordnode.all_node3_r Ordnode.all_node3R
theorem all_node4L {P l x m y r} :
@All α P (node4L l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by
cases m <;> simp [node4L, all_node', All, all_node3L, and_assoc]
#align ordnode.all_node4_l Ordnode.all_node4L
| Mathlib/Data/Ordmap/Ordset.lean | 513 | 515 | theorem all_node4R {P l x m y r} :
@All α P (node4R l x m y r) ↔ All P l ∧ P x ∧ All P m ∧ P y ∧ All P r := by |
cases m <;> simp [node4R, all_node', All, all_node3R, and_assoc]
|
/-
Copyright (c) 2017 Johannes Hölzl. 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.Ordinal.Basic
import Mathlib.Data.Nat.SuccPred
#align_import set_theory.ordinal.arithmetic from "leanprover-community/mathlib"@"31b269b60935483943542d547a6dd83a66b37dc7"
/-!
# Ordinal arithmetic
Ordinals have an addition (corresponding to disjoint union) that turns them into an additive
monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns
them into a monoid. One can also define correspondingly a subtraction, a division, a successor
function, a power function and a logarithm function.
We also define limit ordinals and prove the basic induction principle on ordinals separating
successor ordinals and limit ordinals, in `limitRecOn`.
## Main definitions and results
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.
* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.
* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the
divisibility predicate, and a modulo operation.
* `Order.succ o = o + 1` is the successor of `o`.
* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.
We discuss the properties of casts of natural numbers of and of `ω` with respect to these
operations.
Some properties of the operations are also used to discuss general tools on ordinals:
* `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.
* `limitRecOn` is the main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals.
* `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing
and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`.
* `enumOrd`: enumerates an unbounded set of ordinals by the ordinals themselves.
* `sup`, `lsub`: the supremum / least strict upper bound of an indexed family of ordinals in
`Type u`, as an ordinal in `Type u`.
* `bsup`, `blsub`: the supremum / least strict upper bound of a set of ordinals indexed by ordinals
less than a given ordinal `o`.
Various other basic arithmetic results are given in `Principal.lean` instead.
-/
assert_not_exists Field
assert_not_exists Module
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Classical
open Cardinal Ordinal
universe u v w
namespace Ordinal
variable {α : Type*} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop}
/-! ### Further properties of addition on ordinals -/
@[simp]
theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩
#align ordinal.lift_add Ordinal.lift_add
@[simp]
theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by
rw [← add_one_eq_succ, lift_add, lift_one]
rfl
#align ordinal.lift_succ Ordinal.lift_succ
instance add_contravariantClass_le : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) :=
⟨fun a b c =>
inductionOn a fun α r hr =>
inductionOn b fun β₁ s₁ hs₁ =>
inductionOn c fun β₂ s₂ hs₂ ⟨f⟩ =>
⟨have fl : ∀ a, f (Sum.inl a) = Sum.inl a := fun a => by
simpa only [InitialSeg.trans_apply, InitialSeg.leAdd_apply] using
@InitialSeg.eq _ _ _ _ _
((InitialSeg.leAdd r s₁).trans f) (InitialSeg.leAdd r s₂) a
have : ∀ b, { b' // f (Sum.inr b) = Sum.inr b' } := by
intro b; cases e : f (Sum.inr b)
· rw [← fl] at e
have := f.inj' e
contradiction
· exact ⟨_, rfl⟩
let g (b) := (this b).1
have fr : ∀ b, f (Sum.inr b) = Sum.inr (g b) := fun b => (this b).2
⟨⟨⟨g, fun x y h => by
injection f.inj' (by rw [fr, fr, h] : f (Sum.inr x) = f (Sum.inr y))⟩,
@fun a b => by
-- Porting note:
-- `relEmbedding.coe_fn_to_embedding` & `initial_seg.coe_fn_to_rel_embedding`
-- → `InitialSeg.coe_coe_fn`
simpa only [Sum.lex_inr_inr, fr, InitialSeg.coe_coe_fn, Embedding.coeFn_mk] using
@RelEmbedding.map_rel_iff _ _ _ _ f.toRelEmbedding (Sum.inr a) (Sum.inr b)⟩,
fun a b H => by
rcases f.init (by rw [fr] <;> exact Sum.lex_inr_inr.2 H) with ⟨a' | a', h⟩
· rw [fl] at h
cases h
· rw [fr] at h
exact ⟨a', Sum.inr.inj h⟩⟩⟩⟩
#align ordinal.add_contravariant_class_le Ordinal.add_contravariantClass_le
theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c := by
simp only [le_antisymm_iff, add_le_add_iff_left]
#align ordinal.add_left_cancel Ordinal.add_left_cancel
private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by
rw [← not_le, ← not_le, add_le_add_iff_left]
instance add_covariantClass_lt : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) :=
⟨fun a _b _c => (add_lt_add_iff_left' a).2⟩
#align ordinal.add_covariant_class_lt Ordinal.add_covariantClass_lt
instance add_contravariantClass_lt : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) :=
⟨fun a _b _c => (add_lt_add_iff_left' a).1⟩
#align ordinal.add_contravariant_class_lt Ordinal.add_contravariantClass_lt
instance add_swap_contravariantClass_lt :
ContravariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· < ·) :=
⟨fun _a _b _c => lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩
#align ordinal.add_swap_contravariant_class_lt Ordinal.add_swap_contravariantClass_lt
theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b
| 0 => by simp
| n + 1 => by
simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right]
#align ordinal.add_le_add_iff_right Ordinal.add_le_add_iff_right
theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by
simp only [le_antisymm_iff, add_le_add_iff_right]
#align ordinal.add_right_cancel Ordinal.add_right_cancel
theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 :=
inductionOn a fun α r _ =>
inductionOn b fun β s _ => by
simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty]
exact isEmpty_sum
#align ordinal.add_eq_zero_iff Ordinal.add_eq_zero_iff
theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 :=
(add_eq_zero_iff.1 h).1
#align ordinal.left_eq_zero_of_add_eq_zero Ordinal.left_eq_zero_of_add_eq_zero
theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 :=
(add_eq_zero_iff.1 h).2
#align ordinal.right_eq_zero_of_add_eq_zero Ordinal.right_eq_zero_of_add_eq_zero
/-! ### The predecessor of an ordinal -/
/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,
and `o` otherwise. -/
def pred (o : Ordinal) : Ordinal :=
if h : ∃ a, o = succ a then Classical.choose h else o
#align ordinal.pred Ordinal.pred
@[simp]
theorem pred_succ (o) : pred (succ o) = o := by
have h : ∃ a, succ o = succ a := ⟨_, rfl⟩;
simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm
#align ordinal.pred_succ Ordinal.pred_succ
theorem pred_le_self (o) : pred o ≤ o :=
if h : ∃ a, o = succ a then by
let ⟨a, e⟩ := h
rw [e, pred_succ]; exact le_succ a
else by rw [pred, dif_neg h]
#align ordinal.pred_le_self Ordinal.pred_le_self
theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a :=
⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩
#align ordinal.pred_eq_iff_not_succ Ordinal.pred_eq_iff_not_succ
theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by
simpa using pred_eq_iff_not_succ
#align ordinal.pred_eq_iff_not_succ' Ordinal.pred_eq_iff_not_succ'
theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a :=
Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and_iff, not_le])
(iff_not_comm.1 pred_eq_iff_not_succ).symm
#align ordinal.pred_lt_iff_is_succ Ordinal.pred_lt_iff_is_succ
@[simp]
theorem pred_zero : pred 0 = 0 :=
pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm
#align ordinal.pred_zero Ordinal.pred_zero
theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a :=
⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩
#align ordinal.succ_pred_iff_is_succ Ordinal.succ_pred_iff_is_succ
theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o :=
⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩
#align ordinal.succ_lt_of_not_succ Ordinal.succ_lt_of_not_succ
theorem lt_pred {a b} : a < pred b ↔ succ a < b :=
if h : ∃ a, b = succ a then by
let ⟨c, e⟩ := h
rw [e, pred_succ, succ_lt_succ_iff]
else by simp only [pred, dif_neg h, succ_lt_of_not_succ h]
#align ordinal.lt_pred Ordinal.lt_pred
theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=
le_iff_le_iff_lt_iff_lt.2 lt_pred
#align ordinal.pred_le Ordinal.pred_le
@[simp]
theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a :=
⟨fun ⟨a, h⟩ =>
let ⟨b, e⟩ := lift_down <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a
⟨b, lift_inj.1 <| by rw [h, ← e, lift_succ]⟩,
fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩
#align ordinal.lift_is_succ Ordinal.lift_is_succ
@[simp]
theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) :=
if h : ∃ a, o = succ a then by cases' h with a e; simp only [e, pred_succ, lift_succ]
else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)]
#align ordinal.lift_pred Ordinal.lift_pred
/-! ### Limit ordinals -/
/-- A limit ordinal is an ordinal which is not zero and not a successor. -/
def IsLimit (o : Ordinal) : Prop :=
o ≠ 0 ∧ ∀ a < o, succ a < o
#align ordinal.is_limit Ordinal.IsLimit
theorem IsLimit.isSuccLimit {o} (h : IsLimit o) : IsSuccLimit o := isSuccLimit_iff_succ_lt.mpr h.2
theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o :=
h.2 a
#align ordinal.is_limit.succ_lt Ordinal.IsLimit.succ_lt
theorem isSuccLimit_zero : IsSuccLimit (0 : Ordinal) := isSuccLimit_bot
theorem not_zero_isLimit : ¬IsLimit 0
| ⟨h, _⟩ => h rfl
#align ordinal.not_zero_is_limit Ordinal.not_zero_isLimit
theorem not_succ_isLimit (o) : ¬IsLimit (succ o)
| ⟨_, h⟩ => lt_irrefl _ (h _ (lt_succ o))
#align ordinal.not_succ_is_limit Ordinal.not_succ_isLimit
theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a
| ⟨a, e⟩ => not_succ_isLimit a (e ▸ h)
#align ordinal.not_succ_of_is_limit Ordinal.not_succ_of_isLimit
theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o :=
⟨(lt_succ a).trans, h.2 _⟩
#align ordinal.succ_lt_of_is_limit Ordinal.succ_lt_of_isLimit
theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a :=
le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h
#align ordinal.le_succ_of_is_limit Ordinal.le_succ_of_isLimit
theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a :=
⟨fun h _x l => l.le.trans h, fun H =>
(le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩
#align ordinal.limit_le Ordinal.limit_le
theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a)
#align ordinal.lt_limit Ordinal.lt_limit
@[simp]
theorem lift_isLimit (o) : IsLimit (lift o) ↔ IsLimit o :=
and_congr (not_congr <| by simpa only [lift_zero] using @lift_inj o 0)
⟨fun H a h => lift_lt.1 <| by simpa only [lift_succ] using H _ (lift_lt.2 h), fun H a h => by
obtain ⟨a', rfl⟩ := lift_down h.le
rw [← lift_succ, lift_lt]
exact H a' (lift_lt.1 h)⟩
#align ordinal.lift_is_limit Ordinal.lift_isLimit
theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o :=
lt_of_le_of_ne (Ordinal.zero_le _) h.1.symm
#align ordinal.is_limit.pos Ordinal.IsLimit.pos
theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by
simpa only [succ_zero] using h.2 _ h.pos
#align ordinal.is_limit.one_lt Ordinal.IsLimit.one_lt
theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o
| 0 => h.pos
| n + 1 => h.2 _ (IsLimit.nat_lt h n)
#align ordinal.is_limit.nat_lt Ordinal.IsLimit.nat_lt
theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o :=
if o0 : o = 0 then Or.inl o0
else
if h : ∃ a, o = succ a then Or.inr (Or.inl h)
else Or.inr <| Or.inr ⟨o0, fun _a => (succ_lt_of_not_succ h).2⟩
#align ordinal.zero_or_succ_or_limit Ordinal.zero_or_succ_or_limit
/-- Main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/
@[elab_as_elim]
def limitRecOn {C : Ordinal → Sort*} (o : Ordinal) (H₁ : C 0) (H₂ : ∀ o, C o → C (succ o))
(H₃ : ∀ o, IsLimit o → (∀ o' < o, C o') → C o) : C o :=
SuccOrder.limitRecOn o (fun o _ ↦ H₂ o) fun o hl ↦
if h : o = 0 then fun _ ↦ h ▸ H₁ else H₃ o ⟨h, fun _ ↦ hl.succ_lt⟩
#align ordinal.limit_rec_on Ordinal.limitRecOn
@[simp]
theorem limitRecOn_zero {C} (H₁ H₂ H₃) : @limitRecOn C 0 H₁ H₂ H₃ = H₁ := by
rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ isSuccLimit_zero, dif_pos rfl]
#align ordinal.limit_rec_on_zero Ordinal.limitRecOn_zero
@[simp]
theorem limitRecOn_succ {C} (o H₁ H₂ H₃) :
@limitRecOn C (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn C o H₁ H₂ H₃) := by
simp_rw [limitRecOn, SuccOrder.limitRecOn_succ _ _ (not_isMax _)]
#align ordinal.limit_rec_on_succ Ordinal.limitRecOn_succ
@[simp]
theorem limitRecOn_limit {C} (o H₁ H₂ H₃ h) :
@limitRecOn C o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn C x H₁ H₂ H₃ := by
simp_rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ h.isSuccLimit, dif_neg h.1]
#align ordinal.limit_rec_on_limit Ordinal.limitRecOn_limit
instance orderTopOutSucc (o : Ordinal) : OrderTop (succ o).out.α :=
@OrderTop.mk _ _ (Top.mk _) le_enum_succ
#align ordinal.order_top_out_succ Ordinal.orderTopOutSucc
theorem enum_succ_eq_top {o : Ordinal} :
enum (· < ·) o
(by
rw [type_lt]
exact lt_succ o) =
(⊤ : (succ o).out.α) :=
rfl
#align ordinal.enum_succ_eq_top Ordinal.enum_succ_eq_top
theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r]
(h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by
use enum r (succ (typein r x)) (h _ (typein_lt_type r x))
convert (enum_lt_enum (typein_lt_type r x)
(h _ (typein_lt_type r x))).mpr (lt_succ _); rw [enum_typein]
#align ordinal.has_succ_of_type_succ_lt Ordinal.has_succ_of_type_succ_lt
theorem out_no_max_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.out.α :=
⟨has_succ_of_type_succ_lt (by rwa [type_lt])⟩
#align ordinal.out_no_max_of_succ_lt Ordinal.out_no_max_of_succ_lt
theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) :
Bounded r {x} := by
refine ⟨enum r (succ (typein r x)) (hr.2 _ (typein_lt_type r x)), ?_⟩
intro b hb
rw [mem_singleton_iff.1 hb]
nth_rw 1 [← enum_typein r x]
rw [@enum_lt_enum _ r]
apply lt_succ
#align ordinal.bounded_singleton Ordinal.bounded_singleton
-- Porting note: `· < ·` requires a type ascription for an `IsWellOrder` instance.
theorem type_subrel_lt (o : Ordinal.{u}) :
type (Subrel ((· < ·) : Ordinal → Ordinal → Prop) { o' : Ordinal | o' < o })
= Ordinal.lift.{u + 1} o := by
refine Quotient.inductionOn o ?_
rintro ⟨α, r, wo⟩; apply Quotient.sound
-- Porting note: `symm; refine' [term]` → `refine' [term].symm`
constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enumIso r).symm).symm
#align ordinal.type_subrel_lt Ordinal.type_subrel_lt
theorem mk_initialSeg (o : Ordinal.{u}) :
#{ o' : Ordinal | o' < o } = Cardinal.lift.{u + 1} o.card := by
rw [lift_card, ← type_subrel_lt, card_type]
#align ordinal.mk_initial_seg Ordinal.mk_initialSeg
/-! ### Normal ordinal functions -/
/-- A normal ordinal function is a strictly increasing function which is
order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`. -/
def IsNormal (f : Ordinal → Ordinal) : Prop :=
(∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a
#align ordinal.is_normal Ordinal.IsNormal
theorem IsNormal.limit_le {f} (H : IsNormal f) :
∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a :=
@H.2
#align ordinal.is_normal.limit_le Ordinal.IsNormal.limit_le
theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} :
a < f o ↔ ∃ b < o, a < f b :=
not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a
#align ordinal.is_normal.limit_lt Ordinal.IsNormal.limit_lt
theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b =>
limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _))
(fun _b IH h =>
(lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _)
fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.2 _ h))
#align ordinal.is_normal.strict_mono Ordinal.IsNormal.strictMono
theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f :=
H.strictMono.monotone
#align ordinal.is_normal.monotone Ordinal.IsNormal.monotone
theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) :
IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a :=
⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ =>
⟨fun a => hs (lt_succ a), fun a ha c =>
⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩
#align ordinal.is_normal_iff_strict_mono_limit Ordinal.isNormal_iff_strictMono_limit
theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b :=
StrictMono.lt_iff_lt <| H.strictMono
#align ordinal.is_normal.lt_iff Ordinal.IsNormal.lt_iff
theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.lt_iff
#align ordinal.is_normal.le_iff Ordinal.IsNormal.le_iff
theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by
simp only [le_antisymm_iff, H.le_iff]
#align ordinal.is_normal.inj Ordinal.IsNormal.inj
theorem IsNormal.self_le {f} (H : IsNormal f) (a) : a ≤ f a :=
lt_wf.self_le_of_strictMono H.strictMono a
#align ordinal.is_normal.self_le Ordinal.IsNormal.self_le
theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o :=
⟨fun h a pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by
-- Porting note: `refine'` didn't work well so `induction` is used
induction b using limitRecOn with
| H₁ =>
cases' p0 with x px
have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px)
rw [this] at px
exact h _ px
| H₂ S _ =>
rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩
exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁)
| H₃ S L _ =>
refine (H.2 _ L _).2 fun a h' => ?_
rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩
exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩
#align ordinal.is_normal.le_set Ordinal.IsNormal.le_set
theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by
simpa [H₂] using H.le_set (g '' p) (p0.image g) b
#align ordinal.is_normal.le_set' Ordinal.IsNormal.le_set'
theorem IsNormal.refl : IsNormal id :=
⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩
#align ordinal.is_normal.refl Ordinal.IsNormal.refl
theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) :=
⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a =>
H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩
#align ordinal.is_normal.trans Ordinal.IsNormal.trans
theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (l : IsLimit o) : IsLimit (f o) :=
⟨ne_of_gt <| (Ordinal.zero_le _).trans_lt <| H.lt_iff.2 l.pos, fun _ h =>
let ⟨_b, h₁, h₂⟩ := (H.limit_lt l).1 h
(succ_le_of_lt h₂).trans_lt (H.lt_iff.2 h₁)⟩
#align ordinal.is_normal.is_limit Ordinal.IsNormal.isLimit
theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a :=
(H.self_le a).le_iff_eq
#align ordinal.is_normal.le_iff_eq Ordinal.IsNormal.le_iff_eq
theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c :=
⟨fun h b' l => (add_le_add_left l.le _).trans h, fun H =>
le_of_not_lt <| by
-- Porting note: `induction` tactics are required because of the parser bug.
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
intro l
suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ _ l) by
-- Porting note: `revert` & `intro` is required because `cases'` doesn't replace
-- `enum _ _ l` in `this`.
revert this; cases' enum _ _ l with x x <;> intro this
· cases this (enum s 0 h.pos)
· exact irrefl _ (this _)
intro x
rw [← typein_lt_typein (Sum.Lex r s), typein_enum]
have := H _ (h.2 _ (typein_lt_type s x))
rw [add_succ, succ_le_iff] at this
refine
(RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨a | b, h⟩
· exact Sum.inl a
· exact Sum.inr ⟨b, by cases h; assumption⟩
· rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;>
rintro ⟨⟩ <;> constructor <;> assumption⟩
#align ordinal.add_le_of_limit Ordinal.add_le_of_limit
theorem add_isNormal (a : Ordinal) : IsNormal (a + ·) :=
⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩
#align ordinal.add_is_normal Ordinal.add_isNormal
theorem add_isLimit (a) {b} : IsLimit b → IsLimit (a + b) :=
(add_isNormal a).isLimit
#align ordinal.add_is_limit Ordinal.add_isLimit
alias IsLimit.add := add_isLimit
#align ordinal.is_limit.add Ordinal.IsLimit.add
/-! ### Subtraction on ordinals-/
/-- The set in the definition of subtraction is nonempty. -/
theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty :=
⟨a, le_add_left _ _⟩
#align ordinal.sub_nonempty Ordinal.sub_nonempty
/-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/
instance sub : Sub Ordinal :=
⟨fun a b => sInf { o | a ≤ b + o }⟩
theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) :=
csInf_mem sub_nonempty
#align ordinal.le_add_sub Ordinal.le_add_sub
theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c :=
⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩
#align ordinal.sub_le Ordinal.sub_le
theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b :=
lt_iff_lt_of_le_iff_le sub_le
#align ordinal.lt_sub Ordinal.lt_sub
theorem add_sub_cancel (a b : Ordinal) : a + b - a = b :=
le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _)
#align ordinal.add_sub_cancel Ordinal.add_sub_cancel
theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b :=
h ▸ add_sub_cancel _ _
#align ordinal.sub_eq_of_add_eq Ordinal.sub_eq_of_add_eq
theorem sub_le_self (a b : Ordinal) : a - b ≤ a :=
sub_le.2 <| le_add_left _ _
#align ordinal.sub_le_self Ordinal.sub_le_self
protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a :=
(le_add_sub a b).antisymm'
(by
rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l)
· simp only [e, add_zero, h]
· rw [e, add_succ, succ_le_iff, ← lt_sub, e]
exact lt_succ c
· exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le)
#align ordinal.add_sub_cancel_of_le Ordinal.add_sub_cancel_of_le
theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by
rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h]
#align ordinal.le_sub_of_le Ordinal.le_sub_of_le
theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c :=
lt_iff_lt_of_le_iff_le (le_sub_of_le h)
#align ordinal.sub_lt_of_le Ordinal.sub_lt_of_le
instance existsAddOfLE : ExistsAddOfLE Ordinal :=
⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩
@[simp]
theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a
#align ordinal.sub_zero Ordinal.sub_zero
@[simp]
theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self
#align ordinal.zero_sub Ordinal.zero_sub
@[simp]
theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0
#align ordinal.sub_self Ordinal.sub_self
protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b :=
⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by
rwa [← Ordinal.le_zero, sub_le, add_zero]⟩
#align ordinal.sub_eq_zero_iff_le Ordinal.sub_eq_zero_iff_le
theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) :=
eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc]
#align ordinal.sub_sub Ordinal.sub_sub
@[simp]
theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by
rw [← sub_sub, add_sub_cancel]
#align ordinal.add_sub_add_cancel Ordinal.add_sub_add_cancel
theorem sub_isLimit {a b} (l : IsLimit a) (h : b < a) : IsLimit (a - b) :=
⟨ne_of_gt <| lt_sub.2 <| by rwa [add_zero], fun c h => by
rw [lt_sub, add_succ]; exact l.2 _ (lt_sub.1 h)⟩
#align ordinal.sub_is_limit Ordinal.sub_isLimit
-- @[simp] -- Porting note (#10618): simp can prove this
theorem one_add_omega : 1 + ω = ω := by
refine le_antisymm ?_ (le_add_left _ _)
rw [omega, ← lift_one.{_, 0}, ← lift_add, lift_le, ← type_unit, ← type_sum_lex]
refine ⟨RelEmbedding.collapse (RelEmbedding.ofMonotone ?_ ?_)⟩
· apply Sum.rec
· exact fun _ => 0
· exact Nat.succ
· intro a b
cases a <;> cases b <;> intro H <;> cases' H with _ _ H _ _ H <;>
[exact H.elim; exact Nat.succ_pos _; exact Nat.succ_lt_succ H]
#align ordinal.one_add_omega Ordinal.one_add_omega
@[simp]
theorem one_add_of_omega_le {o} (h : ω ≤ o) : 1 + o = o := by
rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, one_add_omega]
#align ordinal.one_add_of_omega_le Ordinal.one_add_of_omega_le
/-! ### Multiplication of ordinals-/
/-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on
`o₂ × o₁`. -/
instance monoid : Monoid Ordinal.{u} where
mul a b :=
Quotient.liftOn₂ a b
(fun ⟨α, r, wo⟩ ⟨β, s, wo'⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ :
WellOrder → WellOrder → Ordinal)
fun ⟨α₁, r₁, o₁⟩ ⟨α₂, r₂, o₂⟩ ⟨β₁, s₁, p₁⟩ ⟨β₂, s₂, p₂⟩ ⟨f⟩ ⟨g⟩ =>
Quot.sound ⟨RelIso.prodLexCongr g f⟩
one := 1
mul_assoc a b c :=
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Eq.symm <|
Quotient.sound
⟨⟨prodAssoc _ _ _, @fun a b => by
rcases a with ⟨⟨a₁, a₂⟩, a₃⟩
rcases b with ⟨⟨b₁, b₂⟩, b₃⟩
simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩
mul_one a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨punitProd _, @fun a b => by
rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩
simp only [Prod.lex_def, EmptyRelation, false_or_iff]
simp only [eq_self_iff_true, true_and_iff]
rfl⟩⟩
one_mul a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨prodPUnit _, @fun a b => by
rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩
simp only [Prod.lex_def, EmptyRelation, and_false_iff, or_false_iff]
rfl⟩⟩
@[simp]
theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r]
[IsWellOrder β s] : type (Prod.Lex s r) = type r * type s :=
rfl
#align ordinal.type_prod_lex Ordinal.type_prod_lex
private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
inductionOn a fun α _ _ =>
inductionOn b fun β _ _ => by
simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty]
rw [or_comm]
exact isEmpty_prod
instance monoidWithZero : MonoidWithZero Ordinal :=
{ Ordinal.monoid with
zero := 0
mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl
zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl }
instance noZeroDivisors : NoZeroDivisors Ordinal :=
⟨fun {_ _} => mul_eq_zero'.1⟩
@[simp]
theorem lift_mul (a b : Ordinal.{v}) : lift.{u} (a * b) = lift.{u} a * lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.prodLexCongr (RelIso.preimage Equiv.ulift _)
(RelIso.preimage Equiv.ulift _)).symm⟩
#align ordinal.lift_mul Ordinal.lift_mul
@[simp]
theorem card_mul (a b) : card (a * b) = card a * card b :=
Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α
#align ordinal.card_mul Ordinal.card_mul
instance leftDistribClass : LeftDistribClass Ordinal.{u} :=
⟨fun a b c =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Quotient.sound
⟨⟨sumProdDistrib _ _ _, by
rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;>
simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl,
Sum.lex_inr_inr, sumProdDistrib_apply_left, sumProdDistrib_apply_right] <;>
-- Porting note: `Sum.inr.inj_iff` is required.
simp only [Sum.inl.inj_iff, Sum.inr.inj_iff,
true_or_iff, false_and_iff, false_or_iff]⟩⟩⟩
theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a :=
mul_add_one a b
#align ordinal.mul_succ Ordinal.mul_succ
instance mul_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· * ·) (· ≤ ·) :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le
cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h'
· exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h')
· exact Prod.Lex.right _ h'⟩
#align ordinal.mul_covariant_class_le Ordinal.mul_covariantClass_le
instance mul_swap_covariantClass_le :
CovariantClass Ordinal.{u} Ordinal.{u} (swap (· * ·)) (· ≤ ·) :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le
cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h'
· exact Prod.Lex.left _ _ h'
· exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩
#align ordinal.mul_swap_covariant_class_le Ordinal.mul_swap_covariantClass_le
theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by
convert mul_le_mul_left' (one_le_iff_pos.2 hb) a
rw [mul_one a]
#align ordinal.le_mul_left Ordinal.le_mul_left
theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by
convert mul_le_mul_right' (one_le_iff_pos.2 hb) a
rw [one_mul a]
#align ordinal.le_mul_right Ordinal.le_mul_right
private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c}
(h : IsLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) :
False := by
suffices ∀ a b, Prod.Lex s r (b, a) (enum _ _ l) by
cases' enum _ _ l with b a
exact irrefl _ (this _ _)
intro a b
rw [← typein_lt_typein (Prod.Lex s r), typein_enum]
have := H _ (h.2 _ (typein_lt_type s b))
rw [mul_succ] at this
have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this
refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨⟨b', a'⟩, h⟩
by_cases e : b = b'
· refine Sum.inr ⟨a', ?_⟩
subst e
cases' h with _ _ _ _ h _ _ _ h
· exact (irrefl _ h).elim
· exact h
· refine Sum.inl (⟨b', ?_⟩, a')
cases' h with _ _ _ _ h _ _ _ h
· exact h
· exact (e rfl).elim
· rcases a with ⟨⟨b₁, a₁⟩, h₁⟩
rcases b with ⟨⟨b₂, a₂⟩, h₂⟩
intro h
by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂
· substs b₁ b₂
simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and_iff, false_or_iff,
eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h
· subst b₁
simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, eq_self_iff_true,
or_false_iff, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and_iff] at h ⊢
cases' h₂ with _ _ _ _ h₂_h h₂_h <;> [exact asymm h h₂_h; exact e₂ rfl]
-- Porting note: `cc` hadn't ported yet.
· simp [e₂, dif_neg e₁, show b₂ ≠ b₁ from e₂ ▸ e₁]
· simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk,
Sum.lex_inl_inl] using h
theorem mul_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c :=
⟨fun h b' l => (mul_le_mul_left' l.le _).trans h, fun H =>
-- Porting note: `induction` tactics are required because of the parser bug.
le_of_not_lt <| by
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
exact mul_le_of_limit_aux h H⟩
#align ordinal.mul_le_of_limit Ordinal.mul_le_of_limit
theorem mul_isNormal {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) :=
-- Porting note(#12129): additional beta reduction needed
⟨fun b => by
beta_reduce
rw [mul_succ]
simpa only [add_zero] using (add_lt_add_iff_left (a * b)).2 h,
fun b l c => mul_le_of_limit l⟩
#align ordinal.mul_is_normal Ordinal.mul_isNormal
theorem lt_mul_of_limit {a b c : Ordinal} (h : IsLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@mul_le_of_limit b c a h)
#align ordinal.lt_mul_of_limit Ordinal.lt_mul_of_limit
theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c :=
(mul_isNormal a0).lt_iff
#align ordinal.mul_lt_mul_iff_left Ordinal.mul_lt_mul_iff_left
theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c :=
(mul_isNormal a0).le_iff
#align ordinal.mul_le_mul_iff_left Ordinal.mul_le_mul_iff_left
theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b :=
(mul_lt_mul_iff_left c0).2 h
#align ordinal.mul_lt_mul_of_pos_left Ordinal.mul_lt_mul_of_pos_left
theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by
simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁
#align ordinal.mul_pos Ordinal.mul_pos
theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by
simpa only [Ordinal.pos_iff_ne_zero] using mul_pos
#align ordinal.mul_ne_zero Ordinal.mul_ne_zero
theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b :=
le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h
#align ordinal.le_of_mul_le_mul_left Ordinal.le_of_mul_le_mul_left
theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c :=
(mul_isNormal a0).inj
#align ordinal.mul_right_inj Ordinal.mul_right_inj
theorem mul_isLimit {a b : Ordinal} (a0 : 0 < a) : IsLimit b → IsLimit (a * b) :=
(mul_isNormal a0).isLimit
#align ordinal.mul_is_limit Ordinal.mul_isLimit
theorem mul_isLimit_left {a b : Ordinal} (l : IsLimit a) (b0 : 0 < b) : IsLimit (a * b) := by
rcases zero_or_succ_or_limit b with (rfl | ⟨b, rfl⟩ | lb)
· exact b0.false.elim
· rw [mul_succ]
exact add_isLimit _ l
· exact mul_isLimit l.pos lb
#align ordinal.mul_is_limit_left Ordinal.mul_isLimit_left
theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n
| 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero]
| n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n]
#align ordinal.smul_eq_mul Ordinal.smul_eq_mul
/-! ### Division on ordinals -/
/-- The set in the definition of division is nonempty. -/
theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty :=
⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by
simpa only [succ_zero, one_mul] using
mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩
#align ordinal.div_nonempty Ordinal.div_nonempty
/-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/
instance div : Div Ordinal :=
⟨fun a b => if _h : b = 0 then 0 else sInf { o | a < b * succ o }⟩
@[simp]
theorem div_zero (a : Ordinal) : a / 0 = 0 :=
dif_pos rfl
#align ordinal.div_zero Ordinal.div_zero
theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } :=
dif_neg h
#align ordinal.div_def Ordinal.div_def
theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by
rw [div_def a h]; exact csInf_mem (div_nonempty h)
#align ordinal.lt_mul_succ_div Ordinal.lt_mul_succ_div
theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by
simpa only [mul_succ] using lt_mul_succ_div a h
#align ordinal.lt_mul_div_add Ordinal.lt_mul_div_add
theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c :=
⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by
rw [div_def a b0]; exact csInf_le' h⟩
#align ordinal.div_le Ordinal.div_le
theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by
rw [← not_le, div_le h, not_lt]
#align ordinal.lt_div Ordinal.lt_div
theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h]
#align ordinal.div_pos Ordinal.div_pos
theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by
induction a using limitRecOn with
| H₁ => simp only [mul_zero, Ordinal.zero_le]
| H₂ _ _ => rw [succ_le_iff, lt_div c0]
| H₃ _ h₁ h₂ =>
revert h₁ h₂
simp (config := { contextual := true }) only [mul_le_of_limit, limit_le, iff_self_iff,
forall_true_iff]
#align ordinal.le_div Ordinal.le_div
theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c :=
lt_iff_lt_of_le_iff_le <| le_div b0
#align ordinal.div_lt Ordinal.div_lt
theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c :=
if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le]
else
(div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0)
#align ordinal.div_le_of_le_mul Ordinal.div_le_of_le_mul
theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b :=
lt_imp_lt_of_le_imp_le div_le_of_le_mul
#align ordinal.mul_lt_of_lt_div Ordinal.mul_lt_of_lt_div
@[simp]
theorem zero_div (a : Ordinal) : 0 / a = 0 :=
Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _
#align ordinal.zero_div Ordinal.zero_div
theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a :=
if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl
#align ordinal.mul_div_le Ordinal.mul_div_le
theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by
apply le_antisymm
· apply (div_le b0).2
rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left]
apply lt_mul_div_add _ b0
· rw [le_div b0, mul_add, add_le_add_iff_left]
apply mul_div_le
#align ordinal.mul_add_div Ordinal.mul_add_div
theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by
rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h]
simpa only [succ_zero, mul_one] using h
#align ordinal.div_eq_zero_of_lt Ordinal.div_eq_zero_of_lt
@[simp]
theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by
simpa only [add_zero, zero_div] using mul_add_div a b0 0
#align ordinal.mul_div_cancel Ordinal.mul_div_cancel
@[simp]
theorem div_one (a : Ordinal) : a / 1 = a := by
simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero
#align ordinal.div_one Ordinal.div_one
@[simp]
theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by
simpa only [mul_one] using mul_div_cancel 1 h
#align ordinal.div_self Ordinal.div_self
theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c :=
if a0 : a = 0 then by simp only [a0, zero_mul, sub_self]
else
eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0]
#align ordinal.mul_sub Ordinal.mul_sub
theorem isLimit_add_iff {a b} : IsLimit (a + b) ↔ IsLimit b ∨ b = 0 ∧ IsLimit a := by
constructor <;> intro h
· by_cases h' : b = 0
· rw [h', add_zero] at h
right
exact ⟨h', h⟩
left
rw [← add_sub_cancel a b]
apply sub_isLimit h
suffices a + 0 < a + b by simpa only [add_zero] using this
rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero]
rcases h with (h | ⟨rfl, h⟩)
· exact add_isLimit a h
· simpa only [add_zero]
#align ordinal.is_limit_add_iff Ordinal.isLimit_add_iff
theorem dvd_add_iff : ∀ {a b c : Ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c)
| a, _, c, ⟨b, rfl⟩ =>
⟨fun ⟨d, e⟩ => ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩, fun ⟨d, e⟩ => by
rw [e, ← mul_add]
apply dvd_mul_right⟩
#align ordinal.dvd_add_iff Ordinal.dvd_add_iff
theorem div_mul_cancel : ∀ {a b : Ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b
| a, _, a0, ⟨b, rfl⟩ => by rw [mul_div_cancel _ a0]
#align ordinal.div_mul_cancel Ordinal.div_mul_cancel
theorem le_of_dvd : ∀ {a b : Ordinal}, b ≠ 0 → a ∣ b → a ≤ b
-- Porting note: `⟨b, rfl⟩ => by` → `⟨b, e⟩ => by subst e`
| a, _, b0, ⟨b, e⟩ => by
subst e
-- Porting note: `Ne` is required.
simpa only [mul_one] using
mul_le_mul_left'
(one_le_iff_ne_zero.2 fun h : b = 0 => by
simp only [h, mul_zero, Ne, not_true_eq_false] at b0) a
#align ordinal.le_of_dvd Ordinal.le_of_dvd
theorem dvd_antisymm {a b : Ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b :=
if a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h₁).symm
else
if b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h₂
else (le_of_dvd b0 h₁).antisymm (le_of_dvd a0 h₂)
#align ordinal.dvd_antisymm Ordinal.dvd_antisymm
instance isAntisymm : IsAntisymm Ordinal (· ∣ ·) :=
⟨@dvd_antisymm⟩
/-- `a % b` is the unique ordinal `o'` satisfying
`a = b * o + o'` with `o' < b`. -/
instance mod : Mod Ordinal :=
⟨fun a b => a - b * (a / b)⟩
theorem mod_def (a b : Ordinal) : a % b = a - b * (a / b) :=
rfl
#align ordinal.mod_def Ordinal.mod_def
theorem mod_le (a b : Ordinal) : a % b ≤ a :=
sub_le_self a _
#align ordinal.mod_le Ordinal.mod_le
@[simp]
theorem mod_zero (a : Ordinal) : a % 0 = a := by simp only [mod_def, div_zero, zero_mul, sub_zero]
#align ordinal.mod_zero Ordinal.mod_zero
theorem mod_eq_of_lt {a b : Ordinal} (h : a < b) : a % b = a := by
simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero]
#align ordinal.mod_eq_of_lt Ordinal.mod_eq_of_lt
@[simp]
theorem zero_mod (b : Ordinal) : 0 % b = 0 := by simp only [mod_def, zero_div, mul_zero, sub_self]
#align ordinal.zero_mod Ordinal.zero_mod
theorem div_add_mod (a b : Ordinal) : b * (a / b) + a % b = a :=
Ordinal.add_sub_cancel_of_le <| mul_div_le _ _
#align ordinal.div_add_mod Ordinal.div_add_mod
theorem mod_lt (a) {b : Ordinal} (h : b ≠ 0) : a % b < b :=
(add_lt_add_iff_left (b * (a / b))).1 <| by rw [div_add_mod]; exact lt_mul_div_add a h
#align ordinal.mod_lt Ordinal.mod_lt
@[simp]
theorem mod_self (a : Ordinal) : a % a = 0 :=
if a0 : a = 0 then by simp only [a0, zero_mod]
else by simp only [mod_def, div_self a0, mul_one, sub_self]
#align ordinal.mod_self Ordinal.mod_self
@[simp]
theorem mod_one (a : Ordinal) : a % 1 = 0 := by simp only [mod_def, div_one, one_mul, sub_self]
#align ordinal.mod_one Ordinal.mod_one
theorem dvd_of_mod_eq_zero {a b : Ordinal} (H : a % b = 0) : b ∣ a :=
⟨a / b, by simpa [H] using (div_add_mod a b).symm⟩
#align ordinal.dvd_of_mod_eq_zero Ordinal.dvd_of_mod_eq_zero
theorem mod_eq_zero_of_dvd {a b : Ordinal} (H : b ∣ a) : a % b = 0 := by
rcases H with ⟨c, rfl⟩
rcases eq_or_ne b 0 with (rfl | hb)
· simp
· simp [mod_def, hb]
#align ordinal.mod_eq_zero_of_dvd Ordinal.mod_eq_zero_of_dvd
theorem dvd_iff_mod_eq_zero {a b : Ordinal} : b ∣ a ↔ a % b = 0 :=
⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩
#align ordinal.dvd_iff_mod_eq_zero Ordinal.dvd_iff_mod_eq_zero
@[simp]
theorem mul_add_mod_self (x y z : Ordinal) : (x * y + z) % x = z % x := by
rcases eq_or_ne x 0 with rfl | hx
· simp
· rwa [mod_def, mul_add_div, mul_add, ← sub_sub, add_sub_cancel, mod_def]
#align ordinal.mul_add_mod_self Ordinal.mul_add_mod_self
@[simp]
theorem mul_mod (x y : Ordinal) : x * y % x = 0 := by
simpa using mul_add_mod_self x y 0
#align ordinal.mul_mod Ordinal.mul_mod
theorem mod_mod_of_dvd (a : Ordinal) {b c : Ordinal} (h : c ∣ b) : a % b % c = a % c := by
nth_rw 2 [← div_add_mod a b]
rcases h with ⟨d, rfl⟩
rw [mul_assoc, mul_add_mod_self]
#align ordinal.mod_mod_of_dvd Ordinal.mod_mod_of_dvd
@[simp]
theorem mod_mod (a b : Ordinal) : a % b % b = a % b :=
mod_mod_of_dvd a dvd_rfl
#align ordinal.mod_mod Ordinal.mod_mod
/-! ### Families of ordinals
There are two kinds of indexed families that naturally arise when dealing with ordinals: those
indexed by some type in the appropriate universe, and those indexed by ordinals less than another.
The following API allows one to convert from one kind of family to the other.
In many cases, this makes it easy to prove claims about one kind of family via the corresponding
claim on the other. -/
/-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a specified
well-ordering. -/
def bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) :
∀ a < type r, α := fun a ha => f (enum r a ha)
#align ordinal.bfamily_of_family' Ordinal.bfamilyOfFamily'
/-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a well-ordering
given by the axiom of choice. -/
def bfamilyOfFamily {ι : Type u} : (ι → α) → ∀ a < type (@WellOrderingRel ι), α :=
bfamilyOfFamily' WellOrderingRel
#align ordinal.bfamily_of_family Ordinal.bfamilyOfFamily
/-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a specified
well-ordering. -/
def familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o)
(f : ∀ a < o, α) : ι → α := fun i =>
f (typein r i)
(by
rw [← ho]
exact typein_lt_type r i)
#align ordinal.family_of_bfamily' Ordinal.familyOfBFamily'
/-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a well-ordering
given by the axiom of choice. -/
def familyOfBFamily (o : Ordinal) (f : ∀ a < o, α) : o.out.α → α :=
familyOfBFamily' (· < ·) (type_lt o) f
#align ordinal.family_of_bfamily Ordinal.familyOfBFamily
@[simp]
theorem bfamilyOfFamily'_typein {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) (i) :
bfamilyOfFamily' r f (typein r i) (typein_lt_type r i) = f i := by
simp only [bfamilyOfFamily', enum_typein]
#align ordinal.bfamily_of_family'_typein Ordinal.bfamilyOfFamily'_typein
@[simp]
theorem bfamilyOfFamily_typein {ι} (f : ι → α) (i) :
bfamilyOfFamily f (typein _ i) (typein_lt_type _ i) = f i :=
bfamilyOfFamily'_typein _ f i
#align ordinal.bfamily_of_family_typein Ordinal.bfamilyOfFamily_typein
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem familyOfBFamily'_enum {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) (i hi) :
familyOfBFamily' r ho f (enum r i (by rwa [ho])) = f i hi := by
simp only [familyOfBFamily', typein_enum]
#align ordinal.family_of_bfamily'_enum Ordinal.familyOfBFamily'_enum
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem familyOfBFamily_enum (o : Ordinal) (f : ∀ a < o, α) (i hi) :
familyOfBFamily o f
(enum (· < ·) i
(by
convert hi
exact type_lt _)) =
f i hi :=
familyOfBFamily'_enum _ (type_lt o) f _ _
#align ordinal.family_of_bfamily_enum Ordinal.familyOfBFamily_enum
/-- The range of a family indexed by ordinals. -/
def brange (o : Ordinal) (f : ∀ a < o, α) : Set α :=
{ a | ∃ i hi, f i hi = a }
#align ordinal.brange Ordinal.brange
theorem mem_brange {o : Ordinal} {f : ∀ a < o, α} {a} : a ∈ brange o f ↔ ∃ i hi, f i hi = a :=
Iff.rfl
#align ordinal.mem_brange Ordinal.mem_brange
theorem mem_brange_self {o} (f : ∀ a < o, α) (i hi) : f i hi ∈ brange o f :=
⟨i, hi, rfl⟩
#align ordinal.mem_brange_self Ordinal.mem_brange_self
@[simp]
theorem range_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) : range (familyOfBFamily' r ho f) = brange o f := by
refine Set.ext fun a => ⟨?_, ?_⟩
· rintro ⟨b, rfl⟩
apply mem_brange_self
· rintro ⟨i, hi, rfl⟩
exact ⟨_, familyOfBFamily'_enum _ _ _ _ _⟩
#align ordinal.range_family_of_bfamily' Ordinal.range_familyOfBFamily'
@[simp]
theorem range_familyOfBFamily {o} (f : ∀ a < o, α) : range (familyOfBFamily o f) = brange o f :=
range_familyOfBFamily' _ _ f
#align ordinal.range_family_of_bfamily Ordinal.range_familyOfBFamily
@[simp]
theorem brange_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) :
brange _ (bfamilyOfFamily' r f) = range f := by
refine Set.ext fun a => ⟨?_, ?_⟩
· rintro ⟨i, hi, rfl⟩
apply mem_range_self
· rintro ⟨b, rfl⟩
exact ⟨_, _, bfamilyOfFamily'_typein _ _ _⟩
#align ordinal.brange_bfamily_of_family' Ordinal.brange_bfamilyOfFamily'
@[simp]
theorem brange_bfamilyOfFamily {ι : Type u} (f : ι → α) : brange _ (bfamilyOfFamily f) = range f :=
brange_bfamilyOfFamily' _ _
#align ordinal.brange_bfamily_of_family Ordinal.brange_bfamilyOfFamily
@[simp]
theorem brange_const {o : Ordinal} (ho : o ≠ 0) {c : α} : (brange o fun _ _ => c) = {c} := by
rw [← range_familyOfBFamily]
exact @Set.range_const _ o.out.α (out_nonempty_iff_ne_zero.2 ho) c
#align ordinal.brange_const Ordinal.brange_const
theorem comp_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α)
(g : α → β) : (fun i hi => g (bfamilyOfFamily' r f i hi)) = bfamilyOfFamily' r (g ∘ f) :=
rfl
#align ordinal.comp_bfamily_of_family' Ordinal.comp_bfamilyOfFamily'
theorem comp_bfamilyOfFamily {ι : Type u} (f : ι → α) (g : α → β) :
(fun i hi => g (bfamilyOfFamily f i hi)) = bfamilyOfFamily (g ∘ f) :=
rfl
#align ordinal.comp_bfamily_of_family Ordinal.comp_bfamilyOfFamily
theorem comp_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) (g : α → β) :
g ∘ familyOfBFamily' r ho f = familyOfBFamily' r ho fun i hi => g (f i hi) :=
rfl
#align ordinal.comp_family_of_bfamily' Ordinal.comp_familyOfBFamily'
theorem comp_familyOfBFamily {o} (f : ∀ a < o, α) (g : α → β) :
g ∘ familyOfBFamily o f = familyOfBFamily o fun i hi => g (f i hi) :=
rfl
#align ordinal.comp_family_of_bfamily Ordinal.comp_familyOfBFamily
/-! ### Supremum of a family of ordinals -/
-- Porting note: Universes should be specified in `sup`s.
/-- The supremum of a family of ordinals -/
def sup {ι : Type u} (f : ι → Ordinal.{max u v}) : Ordinal.{max u v} :=
iSup f
#align ordinal.sup Ordinal.sup
@[simp]
theorem sSup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : sSup (Set.range f) = sup.{_, v} f :=
rfl
#align ordinal.Sup_eq_sup Ordinal.sSup_eq_sup
/-- The range of an indexed ordinal function, whose outputs live in a higher universe than the
inputs, is always bounded above. See `Ordinal.lsub` for an explicit bound. -/
theorem bddAbove_range {ι : Type u} (f : ι → Ordinal.{max u v}) : BddAbove (Set.range f) :=
⟨(iSup (succ ∘ card ∘ f)).ord, by
rintro a ⟨i, rfl⟩
exact le_of_lt (Cardinal.lt_ord.2 ((lt_succ _).trans_le
(le_ciSup (Cardinal.bddAbove_range.{_, v} _) _)))⟩
#align ordinal.bdd_above_range Ordinal.bddAbove_range
theorem le_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : ∀ i, f i ≤ sup.{_, v} f := fun i =>
le_csSup (bddAbove_range.{_, v} f) (mem_range_self i)
#align ordinal.le_sup Ordinal.le_sup
theorem sup_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : sup.{_, v} f ≤ a ↔ ∀ i, f i ≤ a :=
(csSup_le_iff' (bddAbove_range.{_, v} f)).trans (by simp)
#align ordinal.sup_le_iff Ordinal.sup_le_iff
theorem sup_le {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : (∀ i, f i ≤ a) → sup.{_, v} f ≤ a :=
sup_le_iff.2
#align ordinal.sup_le Ordinal.sup_le
theorem lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : a < sup.{_, v} f ↔ ∃ i, a < f i := by
simpa only [not_forall, not_le] using not_congr (@sup_le_iff.{_, v} _ f a)
#align ordinal.lt_sup Ordinal.lt_sup
theorem ne_sup_iff_lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} :
(∀ i, f i ≠ sup.{_, v} f) ↔ ∀ i, f i < sup.{_, v} f :=
⟨fun hf _ => lt_of_le_of_ne (le_sup _ _) (hf _), fun hf _ => ne_of_lt (hf _)⟩
#align ordinal.ne_sup_iff_lt_sup Ordinal.ne_sup_iff_lt_sup
theorem sup_not_succ_of_ne_sup {ι : Type u} {f : ι → Ordinal.{max u v}}
(hf : ∀ i, f i ≠ sup.{_, v} f) {a} (hao : a < sup.{_, v} f) : succ a < sup.{_, v} f := by
by_contra! hoa
exact
hao.not_le (sup_le fun i => le_of_lt_succ <| (lt_of_le_of_ne (le_sup _ _) (hf i)).trans_le hoa)
#align ordinal.sup_not_succ_of_ne_sup Ordinal.sup_not_succ_of_ne_sup
@[simp]
theorem sup_eq_zero_iff {ι : Type u} {f : ι → Ordinal.{max u v}} :
sup.{_, v} f = 0 ↔ ∀ i, f i = 0 := by
refine
⟨fun h i => ?_, fun h =>
le_antisymm (sup_le fun i => Ordinal.le_zero.2 (h i)) (Ordinal.zero_le _)⟩
rw [← Ordinal.le_zero, ← h]
exact le_sup f i
#align ordinal.sup_eq_zero_iff Ordinal.sup_eq_zero_iff
theorem IsNormal.sup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f) {ι : Type u}
(g : ι → Ordinal.{max u v}) [Nonempty ι] : f (sup.{_, v} g) = sup.{_, w} (f ∘ g) :=
eq_of_forall_ge_iff fun a => by
rw [sup_le_iff]; simp only [comp]; rw [H.le_set' Set.univ Set.univ_nonempty g] <;>
simp [sup_le_iff]
#align ordinal.is_normal.sup Ordinal.IsNormal.sup
@[simp]
theorem sup_empty {ι} [IsEmpty ι] (f : ι → Ordinal) : sup f = 0 :=
ciSup_of_empty f
#align ordinal.sup_empty Ordinal.sup_empty
@[simp]
theorem sup_const {ι} [_hι : Nonempty ι] (o : Ordinal) : (sup fun _ : ι => o) = o :=
ciSup_const
#align ordinal.sup_const Ordinal.sup_const
@[simp]
theorem sup_unique {ι} [Unique ι] (f : ι → Ordinal) : sup f = f default :=
ciSup_unique
#align ordinal.sup_unique Ordinal.sup_unique
theorem sup_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f ⊆ Set.range g) : sup.{u, max v w} f ≤ sup.{v, max u w} g :=
sup_le fun i =>
match h (mem_range_self i) with
| ⟨_j, hj⟩ => hj ▸ le_sup _ _
#align ordinal.sup_le_of_range_subset Ordinal.sup_le_of_range_subset
theorem sup_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f = Set.range g) : sup.{u, max v w} f = sup.{v, max u w} g :=
(sup_le_of_range_subset.{u, v, w} h.le).antisymm (sup_le_of_range_subset.{v, u, w} h.ge)
#align ordinal.sup_eq_of_range_eq Ordinal.sup_eq_of_range_eq
@[simp]
theorem sup_sum {α : Type u} {β : Type v} (f : Sum α β → Ordinal) :
sup.{max u v, w} f =
max (sup.{u, max v w} fun a => f (Sum.inl a)) (sup.{v, max u w} fun b => f (Sum.inr b)) := by
apply (sup_le_iff.2 _).antisymm (max_le_iff.2 ⟨_, _⟩)
· rintro (i | i)
· exact le_max_of_le_left (le_sup _ i)
· exact le_max_of_le_right (le_sup _ i)
all_goals
apply sup_le_of_range_subset.{_, max u v, w}
rintro i ⟨a, rfl⟩
apply mem_range_self
#align ordinal.sup_sum Ordinal.sup_sum
theorem unbounded_range_of_sup_ge {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β → α)
(h : type r ≤ sup.{u, u} (typein r ∘ f)) : Unbounded r (range f) :=
(not_bounded_iff _).1 fun ⟨x, hx⟩ =>
not_lt_of_le h <|
lt_of_le_of_lt
(sup_le fun y => le_of_lt <| (typein_lt_typein r).2 <| hx _ <| mem_range_self y)
(typein_lt_type r x)
#align ordinal.unbounded_range_of_sup_ge Ordinal.unbounded_range_of_sup_ge
theorem le_sup_shrink_equiv {s : Set Ordinal.{u}} (hs : Small.{u} s) (a) (ha : a ∈ s) :
a ≤ sup.{u, u} fun x => ((@equivShrink s hs).symm x).val := by
convert le_sup.{u, u} (fun x => ((@equivShrink s hs).symm x).val) ((@equivShrink s hs) ⟨a, ha⟩)
rw [symm_apply_apply]
#align ordinal.le_sup_shrink_equiv Ordinal.le_sup_shrink_equiv
instance small_Iio (o : Ordinal.{u}) : Small.{u} (Set.Iio o) :=
let f : o.out.α → Set.Iio o :=
fun x => ⟨typein ((· < ·) : o.out.α → o.out.α → Prop) x, typein_lt_self x⟩
let hf : Surjective f := fun b =>
⟨enum (· < ·) b.val
(by
rw [type_lt]
exact b.prop),
Subtype.ext (typein_enum _ _)⟩
small_of_surjective hf
#align ordinal.small_Iio Ordinal.small_Iio
instance small_Iic (o : Ordinal.{u}) : Small.{u} (Set.Iic o) := by
rw [← Iio_succ]
infer_instance
#align ordinal.small_Iic Ordinal.small_Iic
theorem bddAbove_iff_small {s : Set Ordinal.{u}} : BddAbove s ↔ Small.{u} s :=
⟨fun ⟨a, h⟩ => small_subset <| show s ⊆ Iic a from fun _x hx => h hx, fun h =>
⟨sup.{u, u} fun x => ((@equivShrink s h).symm x).val, le_sup_shrink_equiv h⟩⟩
#align ordinal.bdd_above_iff_small Ordinal.bddAbove_iff_small
theorem bddAbove_of_small (s : Set Ordinal.{u}) [h : Small.{u} s] : BddAbove s :=
bddAbove_iff_small.2 h
#align ordinal.bdd_above_of_small Ordinal.bddAbove_of_small
theorem sup_eq_sSup {s : Set Ordinal.{u}} (hs : Small.{u} s) :
(sup.{u, u} fun x => (@equivShrink s hs).symm x) = sSup s :=
let hs' := bddAbove_iff_small.2 hs
((csSup_le_iff' hs').2 (le_sup_shrink_equiv hs)).antisymm'
(sup_le fun _x => le_csSup hs' (Subtype.mem _))
#align ordinal.sup_eq_Sup Ordinal.sup_eq_sSup
theorem sSup_ord {s : Set Cardinal.{u}} (hs : BddAbove s) : (sSup s).ord = sSup (ord '' s) :=
eq_of_forall_ge_iff fun a => by
rw [csSup_le_iff'
(bddAbove_iff_small.2 (@small_image _ _ _ s (Cardinal.bddAbove_iff_small.1 hs))),
ord_le, csSup_le_iff' hs]
simp [ord_le]
#align ordinal.Sup_ord Ordinal.sSup_ord
theorem iSup_ord {ι} {f : ι → Cardinal} (hf : BddAbove (range f)) :
(iSup f).ord = ⨆ i, (f i).ord := by
unfold iSup
convert sSup_ord hf
-- Porting note: `change` is required.
conv_lhs => change range (ord ∘ f)
rw [range_comp]
#align ordinal.supr_ord Ordinal.iSup_ord
private theorem sup_le_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop)
[IsWellOrder ι r] [IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o)
(f : ∀ a < o, Ordinal.{max u v}) :
sup.{_, v} (familyOfBFamily' r ho f) ≤ sup.{_, v} (familyOfBFamily' r' ho' f) :=
sup_le fun i => by
cases'
typein_surj r'
(by
rw [ho', ← ho]
exact typein_lt_type r i) with
j hj
simp_rw [familyOfBFamily', ← hj]
apply le_sup
theorem sup_eq_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r]
[IsWellOrder ι' r'] {o : Ordinal.{u}} (ho : type r = o) (ho' : type r' = o)
(f : ∀ a < o, Ordinal.{max u v}) :
sup.{_, v} (familyOfBFamily' r ho f) = sup.{_, v} (familyOfBFamily' r' ho' f) :=
sup_eq_of_range_eq.{u, u, v} (by simp)
#align ordinal.sup_eq_sup Ordinal.sup_eq_sup
/-- The supremum of a family of ordinals indexed by the set of ordinals less than some
`o : Ordinal.{u}`. This is a special case of `sup` over the family provided by
`familyOfBFamily`. -/
def bsup (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} :=
sup.{_, v} (familyOfBFamily o f)
#align ordinal.bsup Ordinal.bsup
@[simp]
theorem sup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
sup.{_, v} (familyOfBFamily o f) = bsup.{_, v} o f :=
rfl
#align ordinal.sup_eq_bsup Ordinal.sup_eq_bsup
@[simp]
theorem sup_eq_bsup' {o : Ordinal.{u}} {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (ho : type r = o)
(f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) = bsup.{_, v} o f :=
sup_eq_sup r _ ho _ f
#align ordinal.sup_eq_bsup' Ordinal.sup_eq_bsup'
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem sSup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
sSup (brange o f) = bsup.{_, v} o f := by
congr
rw [range_familyOfBFamily]
#align ordinal.Sup_eq_bsup Ordinal.sSup_eq_bsup
@[simp]
theorem bsup_eq_sup' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → Ordinal.{max u v}) :
bsup.{_, v} _ (bfamilyOfFamily' r f) = sup.{_, v} f := by
simp (config := { unfoldPartialApp := true }) only [← sup_eq_bsup' r, enum_typein,
familyOfBFamily', bfamilyOfFamily']
#align ordinal.bsup_eq_sup' Ordinal.bsup_eq_sup'
theorem bsup_eq_bsup {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r']
(f : ι → Ordinal.{max u v}) :
bsup.{_, v} _ (bfamilyOfFamily' r f) = bsup.{_, v} _ (bfamilyOfFamily' r' f) := by
rw [bsup_eq_sup', bsup_eq_sup']
#align ordinal.bsup_eq_bsup Ordinal.bsup_eq_bsup
@[simp]
theorem bsup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) :
bsup.{_, v} _ (bfamilyOfFamily f) = sup.{_, v} f :=
bsup_eq_sup' _ f
#align ordinal.bsup_eq_sup Ordinal.bsup_eq_sup
@[congr]
theorem bsup_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) :
bsup.{_, v} o₁ f = bsup.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by
subst ho
-- Porting note: `rfl` is required.
rfl
#align ordinal.bsup_congr Ordinal.bsup_congr
theorem bsup_le_iff {o f a} : bsup.{u, v} o f ≤ a ↔ ∀ i h, f i h ≤ a :=
sup_le_iff.trans
⟨fun h i hi => by
rw [← familyOfBFamily_enum o f]
exact h _, fun h i => h _ _⟩
#align ordinal.bsup_le_iff Ordinal.bsup_le_iff
theorem bsup_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} :
(∀ i h, f i h ≤ a) → bsup.{u, v} o f ≤ a :=
bsup_le_iff.2
#align ordinal.bsup_le Ordinal.bsup_le
theorem le_bsup {o} (f : ∀ a < o, Ordinal) (i h) : f i h ≤ bsup o f :=
bsup_le_iff.1 le_rfl _ _
#align ordinal.le_bsup Ordinal.le_bsup
theorem lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) {a} :
a < bsup.{_, v} o f ↔ ∃ i hi, a < f i hi := by
simpa only [not_forall, not_le] using not_congr (@bsup_le_iff.{_, v} _ f a)
#align ordinal.lt_bsup Ordinal.lt_bsup
theorem IsNormal.bsup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f)
{o : Ordinal.{u}} :
∀ (g : ∀ a < o, Ordinal), o ≠ 0 → f (bsup.{_, v} o g) = bsup.{_, w} o fun a h => f (g a h) :=
inductionOn o fun α r _ g h => by
haveI := type_ne_zero_iff_nonempty.1 h
rw [← sup_eq_bsup' r, IsNormal.sup.{_, v, w} H, ← sup_eq_bsup' r] <;> rfl
#align ordinal.is_normal.bsup Ordinal.IsNormal.bsup
theorem lt_bsup_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} :
(∀ i h, f i h ≠ bsup.{_, v} o f) ↔ ∀ i h, f i h < bsup.{_, v} o f :=
⟨fun hf _ _ => lt_of_le_of_ne (le_bsup _ _ _) (hf _ _), fun hf _ _ => ne_of_lt (hf _ _)⟩
#align ordinal.lt_bsup_of_ne_bsup Ordinal.lt_bsup_of_ne_bsup
theorem bsup_not_succ_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}}
(hf : ∀ {i : Ordinal} (h : i < o), f i h ≠ bsup.{_, v} o f) (a) :
a < bsup.{_, v} o f → succ a < bsup.{_, v} o f := by
rw [← sup_eq_bsup] at *
exact sup_not_succ_of_ne_sup fun i => hf _
#align ordinal.bsup_not_succ_of_ne_bsup Ordinal.bsup_not_succ_of_ne_bsup
@[simp]
theorem bsup_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : bsup o f = 0 ↔ ∀ i hi, f i hi = 0 := by
refine
⟨fun h i hi => ?_, fun h =>
le_antisymm (bsup_le fun i hi => Ordinal.le_zero.2 (h i hi)) (Ordinal.zero_le _)⟩
rw [← Ordinal.le_zero, ← h]
exact le_bsup f i hi
#align ordinal.bsup_eq_zero_iff Ordinal.bsup_eq_zero_iff
theorem lt_bsup_of_limit {o : Ordinal} {f : ∀ a < o, Ordinal}
(hf : ∀ {a a'} (ha : a < o) (ha' : a' < o), a < a' → f a ha < f a' ha')
(ho : ∀ a < o, succ a < o) (i h) : f i h < bsup o f :=
(hf _ _ <| lt_succ i).trans_le (le_bsup f (succ i) <| ho _ h)
#align ordinal.lt_bsup_of_limit Ordinal.lt_bsup_of_limit
theorem bsup_succ_of_mono {o : Ordinal} {f : ∀ a < succ o, Ordinal}
(hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : bsup _ f = f o (lt_succ o) :=
le_antisymm (bsup_le fun _i hi => hf _ _ <| le_of_lt_succ hi) (le_bsup _ _ _)
#align ordinal.bsup_succ_of_mono Ordinal.bsup_succ_of_mono
@[simp]
theorem bsup_zero (f : ∀ a < (0 : Ordinal), Ordinal) : bsup 0 f = 0 :=
bsup_eq_zero_iff.2 fun i hi => (Ordinal.not_lt_zero i hi).elim
#align ordinal.bsup_zero Ordinal.bsup_zero
theorem bsup_const {o : Ordinal.{u}} (ho : o ≠ 0) (a : Ordinal.{max u v}) :
(bsup.{_, v} o fun _ _ => a) = a :=
le_antisymm (bsup_le fun _ _ => le_rfl) (le_bsup _ 0 (Ordinal.pos_iff_ne_zero.2 ho))
#align ordinal.bsup_const Ordinal.bsup_const
@[simp]
theorem bsup_one (f : ∀ a < (1 : Ordinal), Ordinal) : bsup 1 f = f 0 zero_lt_one := by
simp_rw [← sup_eq_bsup, sup_unique, familyOfBFamily, familyOfBFamily', typein_one_out]
#align ordinal.bsup_one Ordinal.bsup_one
theorem bsup_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : brange o f ⊆ brange o' g) : bsup.{u, max v w} o f ≤ bsup.{v, max u w} o' g :=
bsup_le fun i hi => by
obtain ⟨j, hj, hj'⟩ := h ⟨i, hi, rfl⟩
rw [← hj']
apply le_bsup
#align ordinal.bsup_le_of_brange_subset Ordinal.bsup_le_of_brange_subset
theorem bsup_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : brange o f = brange o' g) : bsup.{u, max v w} o f = bsup.{v, max u w} o' g :=
(bsup_le_of_brange_subset.{u, v, w} h.le).antisymm (bsup_le_of_brange_subset.{v, u, w} h.ge)
#align ordinal.bsup_eq_of_brange_eq Ordinal.bsup_eq_of_brange_eq
/-- The least strict upper bound of a family of ordinals. -/
def lsub {ι} (f : ι → Ordinal) : Ordinal :=
sup (succ ∘ f)
#align ordinal.lsub Ordinal.lsub
@[simp]
theorem sup_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} (succ ∘ f) = lsub.{_, v} f :=
rfl
#align ordinal.sup_eq_lsub Ordinal.sup_eq_lsub
theorem lsub_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} :
lsub.{_, v} f ≤ a ↔ ∀ i, f i < a := by
convert sup_le_iff.{_, v} (f := succ ∘ f) (a := a) using 2
-- Porting note: `comp_apply` is required.
simp only [comp_apply, succ_le_iff]
#align ordinal.lsub_le_iff Ordinal.lsub_le_iff
theorem lsub_le {ι} {f : ι → Ordinal} {a} : (∀ i, f i < a) → lsub f ≤ a :=
lsub_le_iff.2
#align ordinal.lsub_le Ordinal.lsub_le
theorem lt_lsub {ι} (f : ι → Ordinal) (i) : f i < lsub f :=
succ_le_iff.1 (le_sup _ i)
#align ordinal.lt_lsub Ordinal.lt_lsub
theorem lt_lsub_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} :
a < lsub.{_, v} f ↔ ∃ i, a ≤ f i := by
simpa only [not_forall, not_lt, not_le] using not_congr (@lsub_le_iff.{_, v} _ f a)
#align ordinal.lt_lsub_iff Ordinal.lt_lsub_iff
theorem sup_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f ≤ lsub.{_, v} f :=
sup_le fun i => (lt_lsub f i).le
#align ordinal.sup_le_lsub Ordinal.sup_le_lsub
theorem lsub_le_sup_succ {ι : Type u} (f : ι → Ordinal.{max u v}) :
lsub.{_, v} f ≤ succ (sup.{_, v} f) :=
lsub_le fun i => lt_succ_iff.2 (le_sup f i)
#align ordinal.lsub_le_sup_succ Ordinal.lsub_le_sup_succ
theorem sup_eq_lsub_or_sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} f = lsub.{_, v} f ∨ succ (sup.{_, v} f) = lsub.{_, v} f := by
cases' eq_or_lt_of_le (sup_le_lsub.{_, v} f) with h h
· exact Or.inl h
· exact Or.inr ((succ_le_of_lt h).antisymm (lsub_le_sup_succ f))
#align ordinal.sup_eq_lsub_or_sup_succ_eq_lsub Ordinal.sup_eq_lsub_or_sup_succ_eq_lsub
theorem sup_succ_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
succ (sup.{_, v} f) ≤ lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f := by
refine ⟨fun h => ?_, ?_⟩
· by_contra! hf
exact (succ_le_iff.1 h).ne ((sup_le_lsub f).antisymm (lsub_le (ne_sup_iff_lt_sup.1 hf)))
rintro ⟨_, hf⟩
rw [succ_le_iff, ← hf]
exact lt_lsub _ _
#align ordinal.sup_succ_le_lsub Ordinal.sup_succ_le_lsub
theorem sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
succ (sup.{_, v} f) = lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f :=
(lsub_le_sup_succ f).le_iff_eq.symm.trans (sup_succ_le_lsub f)
#align ordinal.sup_succ_eq_lsub Ordinal.sup_succ_eq_lsub
theorem sup_eq_lsub_iff_succ {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} f = lsub.{_, v} f ↔ ∀ a < lsub.{_, v} f, succ a < lsub.{_, v} f := by
refine ⟨fun h => ?_, fun hf => le_antisymm (sup_le_lsub f) (lsub_le fun i => ?_)⟩
· rw [← h]
exact fun a => sup_not_succ_of_ne_sup fun i => (lsub_le_iff.1 (le_of_eq h.symm) i).ne
by_contra! hle
have heq := (sup_succ_eq_lsub f).2 ⟨i, le_antisymm (le_sup _ _) hle⟩
have :=
hf _
(by
rw [← heq]
exact lt_succ (sup f))
rw [heq] at this
exact this.false
#align ordinal.sup_eq_lsub_iff_succ Ordinal.sup_eq_lsub_iff_succ
theorem sup_eq_lsub_iff_lt_sup {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} f = lsub.{_, v} f ↔ ∀ i, f i < sup.{_, v} f :=
⟨fun h i => by
rw [h]
apply lt_lsub, fun h => le_antisymm (sup_le_lsub f) (lsub_le h)⟩
#align ordinal.sup_eq_lsub_iff_lt_sup Ordinal.sup_eq_lsub_iff_lt_sup
@[simp]
theorem lsub_empty {ι} [h : IsEmpty ι] (f : ι → Ordinal) : lsub f = 0 := by
rw [← Ordinal.le_zero, lsub_le_iff]
exact h.elim
#align ordinal.lsub_empty Ordinal.lsub_empty
theorem lsub_pos {ι : Type u} [h : Nonempty ι] (f : ι → Ordinal.{max u v}) : 0 < lsub.{_, v} f :=
h.elim fun i => (Ordinal.zero_le _).trans_lt (lt_lsub f i)
#align ordinal.lsub_pos Ordinal.lsub_pos
@[simp]
theorem lsub_eq_zero_iff {ι : Type u} (f : ι → Ordinal.{max u v}) :
lsub.{_, v} f = 0 ↔ IsEmpty ι := by
refine ⟨fun h => ⟨fun i => ?_⟩, fun h => @lsub_empty _ h _⟩
have := @lsub_pos.{_, v} _ ⟨i⟩ f
rw [h] at this
exact this.false
#align ordinal.lsub_eq_zero_iff Ordinal.lsub_eq_zero_iff
@[simp]
theorem lsub_const {ι} [Nonempty ι] (o : Ordinal) : (lsub fun _ : ι => o) = succ o :=
sup_const (succ o)
#align ordinal.lsub_const Ordinal.lsub_const
@[simp]
theorem lsub_unique {ι} [Unique ι] (f : ι → Ordinal) : lsub f = succ (f default) :=
sup_unique _
#align ordinal.lsub_unique Ordinal.lsub_unique
theorem lsub_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f ⊆ Set.range g) : lsub.{u, max v w} f ≤ lsub.{v, max u w} g :=
sup_le_of_range_subset.{u, v, w} (by convert Set.image_subset succ h <;> apply Set.range_comp)
#align ordinal.lsub_le_of_range_subset Ordinal.lsub_le_of_range_subset
theorem lsub_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f = Set.range g) : lsub.{u, max v w} f = lsub.{v, max u w} g :=
(lsub_le_of_range_subset.{u, v, w} h.le).antisymm (lsub_le_of_range_subset.{v, u, w} h.ge)
#align ordinal.lsub_eq_of_range_eq Ordinal.lsub_eq_of_range_eq
@[simp]
theorem lsub_sum {α : Type u} {β : Type v} (f : Sum α β → Ordinal) :
lsub.{max u v, w} f =
max (lsub.{u, max v w} fun a => f (Sum.inl a)) (lsub.{v, max u w} fun b => f (Sum.inr b)) :=
sup_sum _
#align ordinal.lsub_sum Ordinal.lsub_sum
theorem lsub_not_mem_range {ι : Type u} (f : ι → Ordinal.{max u v}) :
lsub.{_, v} f ∉ Set.range f := fun ⟨i, h⟩ =>
h.not_lt (lt_lsub f i)
#align ordinal.lsub_not_mem_range Ordinal.lsub_not_mem_range
theorem nonempty_compl_range {ι : Type u} (f : ι → Ordinal.{max u v}) : (Set.range f)ᶜ.Nonempty :=
⟨_, lsub_not_mem_range.{_, v} f⟩
#align ordinal.nonempty_compl_range Ordinal.nonempty_compl_range
@[simp]
theorem lsub_typein (o : Ordinal) : lsub.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o :=
(lsub_le.{u, u} typein_lt_self).antisymm
(by
by_contra! h
-- Porting note: `nth_rw` → `conv_rhs` & `rw`
conv_rhs at h => rw [← type_lt o]
simpa [typein_enum] using lt_lsub.{u, u} (typein (· < ·)) (enum (· < ·) _ h))
#align ordinal.lsub_typein Ordinal.lsub_typein
theorem sup_typein_limit {o : Ordinal} (ho : ∀ a, a < o → succ a < o) :
sup.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o := by
-- Porting note: `rwa` → `rw` & `assumption`
rw [(sup_eq_lsub_iff_succ.{u, u} (typein (· < ·))).2] <;> rw [lsub_typein o]; assumption
#align ordinal.sup_typein_limit Ordinal.sup_typein_limit
@[simp]
theorem sup_typein_succ {o : Ordinal} :
sup.{u, u} (typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) = o := by
cases'
sup_eq_lsub_or_sup_succ_eq_lsub.{u, u}
(typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) with
h h
· rw [sup_eq_lsub_iff_succ] at h
simp only [lsub_typein] at h
exact (h o (lt_succ o)).false.elim
rw [← succ_eq_succ_iff, h]
apply lsub_typein
#align ordinal.sup_typein_succ Ordinal.sup_typein_succ
/-- The least strict upper bound of a family of ordinals indexed by the set of ordinals less than
some `o : Ordinal.{u}`.
This is to `lsub` as `bsup` is to `sup`. -/
def blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} :=
bsup.{_, v} o fun a ha => succ (f a ha)
#align ordinal.blsub Ordinal.blsub
@[simp]
theorem bsup_eq_blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) :
(bsup.{_, v} o fun a ha => succ (f a ha)) = blsub.{_, v} o f :=
rfl
#align ordinal.bsup_eq_blsub Ordinal.bsup_eq_blsub
theorem lsub_eq_blsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o)
(f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily' r ho f) = blsub.{_, v} o f :=
sup_eq_bsup'.{_, v} r ho fun a ha => succ (f a ha)
#align ordinal.lsub_eq_blsub' Ordinal.lsub_eq_blsub'
theorem lsub_eq_lsub {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r]
[IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o)
(f : ∀ a < o, Ordinal.{max u v}) :
lsub.{_, v} (familyOfBFamily' r ho f) = lsub.{_, v} (familyOfBFamily' r' ho' f) := by
rw [lsub_eq_blsub', lsub_eq_blsub']
#align ordinal.lsub_eq_lsub Ordinal.lsub_eq_lsub
@[simp]
theorem lsub_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
lsub.{_, v} (familyOfBFamily o f) = blsub.{_, v} o f :=
lsub_eq_blsub' _ _ _
#align ordinal.lsub_eq_blsub Ordinal.lsub_eq_blsub
@[simp]
theorem blsub_eq_lsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r]
(f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily' r f) = lsub.{_, v} f :=
bsup_eq_sup'.{_, v} r (succ ∘ f)
#align ordinal.blsub_eq_lsub' Ordinal.blsub_eq_lsub'
theorem blsub_eq_blsub {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r']
(f : ι → Ordinal.{max u v}) :
blsub.{_, v} _ (bfamilyOfFamily' r f) = blsub.{_, v} _ (bfamilyOfFamily' r' f) := by
rw [blsub_eq_lsub', blsub_eq_lsub']
#align ordinal.blsub_eq_blsub Ordinal.blsub_eq_blsub
@[simp]
theorem blsub_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
blsub.{_, v} _ (bfamilyOfFamily f) = lsub.{_, v} f :=
blsub_eq_lsub' _ _
#align ordinal.blsub_eq_lsub Ordinal.blsub_eq_lsub
@[congr]
theorem blsub_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) :
blsub.{_, v} o₁ f = blsub.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by
subst ho
-- Porting note: `rfl` is required.
rfl
#align ordinal.blsub_congr Ordinal.blsub_congr
theorem blsub_le_iff {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} {a} :
blsub.{_, v} o f ≤ a ↔ ∀ i h, f i h < a := by
convert bsup_le_iff.{_, v} (f := fun a ha => succ (f a ha)) (a := a) using 2
simp_rw [succ_le_iff]
#align ordinal.blsub_le_iff Ordinal.blsub_le_iff
theorem blsub_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} : (∀ i h, f i h < a) → blsub o f ≤ a :=
blsub_le_iff.2
#align ordinal.blsub_le Ordinal.blsub_le
theorem lt_blsub {o} (f : ∀ a < o, Ordinal) (i h) : f i h < blsub o f :=
blsub_le_iff.1 le_rfl _ _
#align ordinal.lt_blsub Ordinal.lt_blsub
theorem lt_blsub_iff {o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{max u v}} {a} :
a < blsub.{_, v} o f ↔ ∃ i hi, a ≤ f i hi := by
simpa only [not_forall, not_lt, not_le] using not_congr (@blsub_le_iff.{_, v} _ f a)
#align ordinal.lt_blsub_iff Ordinal.lt_blsub_iff
theorem bsup_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f ≤ blsub.{_, v} o f :=
bsup_le fun i h => (lt_blsub f i h).le
#align ordinal.bsup_le_blsub Ordinal.bsup_le_blsub
theorem blsub_le_bsup_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
blsub.{_, v} o f ≤ succ (bsup.{_, v} o f) :=
blsub_le fun i h => lt_succ_iff.2 (le_bsup f i h)
#align ordinal.blsub_le_bsup_succ Ordinal.blsub_le_bsup_succ
theorem bsup_eq_blsub_or_succ_bsup_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f = blsub.{_, v} o f ∨ succ (bsup.{_, v} o f) = blsub.{_, v} o f := by
rw [← sup_eq_bsup, ← lsub_eq_blsub]
exact sup_eq_lsub_or_sup_succ_eq_lsub _
#align ordinal.bsup_eq_blsub_or_succ_bsup_eq_blsub Ordinal.bsup_eq_blsub_or_succ_bsup_eq_blsub
theorem bsup_succ_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
succ (bsup.{_, v} o f) ≤ blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f := by
refine ⟨fun h => ?_, ?_⟩
· by_contra! hf
exact
ne_of_lt (succ_le_iff.1 h)
(le_antisymm (bsup_le_blsub f) (blsub_le (lt_bsup_of_ne_bsup.1 hf)))
rintro ⟨_, _, hf⟩
rw [succ_le_iff, ← hf]
exact lt_blsub _ _ _
#align ordinal.bsup_succ_le_blsub Ordinal.bsup_succ_le_blsub
theorem bsup_succ_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
succ (bsup.{_, v} o f) = blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f :=
(blsub_le_bsup_succ f).le_iff_eq.symm.trans (bsup_succ_le_blsub f)
#align ordinal.bsup_succ_eq_blsub Ordinal.bsup_succ_eq_blsub
theorem bsup_eq_blsub_iff_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ a < blsub.{_, v} o f, succ a < blsub.{_, v} o f := by
rw [← sup_eq_bsup, ← lsub_eq_blsub]
apply sup_eq_lsub_iff_succ
#align ordinal.bsup_eq_blsub_iff_succ Ordinal.bsup_eq_blsub_iff_succ
theorem bsup_eq_blsub_iff_lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ i hi, f i hi < bsup.{_, v} o f :=
⟨fun h i => by
rw [h]
apply lt_blsub, fun h => le_antisymm (bsup_le_blsub f) (blsub_le h)⟩
#align ordinal.bsup_eq_blsub_iff_lt_bsup Ordinal.bsup_eq_blsub_iff_lt_bsup
theorem bsup_eq_blsub_of_lt_succ_limit {o : Ordinal.{u}} (ho : IsLimit o)
{f : ∀ a < o, Ordinal.{max u v}} (hf : ∀ a ha, f a ha < f (succ a) (ho.2 a ha)) :
bsup.{_, v} o f = blsub.{_, v} o f := by
rw [bsup_eq_blsub_iff_lt_bsup]
exact fun i hi => (hf i hi).trans_le (le_bsup f _ _)
#align ordinal.bsup_eq_blsub_of_lt_succ_limit Ordinal.bsup_eq_blsub_of_lt_succ_limit
theorem blsub_succ_of_mono {o : Ordinal.{u}} {f : ∀ a < succ o, Ordinal.{max u v}}
(hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : blsub.{_, v} _ f = succ (f o (lt_succ o)) :=
bsup_succ_of_mono fun {_ _} hi hj h => succ_le_succ (hf hi hj h)
#align ordinal.blsub_succ_of_mono Ordinal.blsub_succ_of_mono
@[simp]
theorem blsub_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : blsub o f = 0 ↔ o = 0 := by
rw [← lsub_eq_blsub, lsub_eq_zero_iff]
exact out_empty_iff_eq_zero
#align ordinal.blsub_eq_zero_iff Ordinal.blsub_eq_zero_iff
-- Porting note: `rwa` → `rw`
@[simp]
theorem blsub_zero (f : ∀ a < (0 : Ordinal), Ordinal) : blsub 0 f = 0 := by rw [blsub_eq_zero_iff]
#align ordinal.blsub_zero Ordinal.blsub_zero
theorem blsub_pos {o : Ordinal} (ho : 0 < o) (f : ∀ a < o, Ordinal) : 0 < blsub o f :=
(Ordinal.zero_le _).trans_lt (lt_blsub f 0 ho)
#align ordinal.blsub_pos Ordinal.blsub_pos
theorem blsub_type {α : Type u} (r : α → α → Prop) [IsWellOrder α r]
(f : ∀ a < type r, Ordinal.{max u v}) :
blsub.{_, v} (type r) f = lsub.{_, v} fun a => f (typein r a) (typein_lt_type _ _) :=
eq_of_forall_ge_iff fun o => by
rw [blsub_le_iff, lsub_le_iff];
exact ⟨fun H b => H _ _, fun H i h => by simpa only [typein_enum] using H (enum r i h)⟩
#align ordinal.blsub_type Ordinal.blsub_type
theorem blsub_const {o : Ordinal} (ho : o ≠ 0) (a : Ordinal) :
(blsub.{u, v} o fun _ _ => a) = succ a :=
bsup_const.{u, v} ho (succ a)
#align ordinal.blsub_const Ordinal.blsub_const
@[simp]
theorem blsub_one (f : ∀ a < (1 : Ordinal), Ordinal) : blsub 1 f = succ (f 0 zero_lt_one) :=
bsup_one _
#align ordinal.blsub_one Ordinal.blsub_one
@[simp]
theorem blsub_id : ∀ o, (blsub.{u, u} o fun x _ => x) = o :=
lsub_typein
#align ordinal.blsub_id Ordinal.blsub_id
theorem bsup_id_limit {o : Ordinal} : (∀ a < o, succ a < o) → (bsup.{u, u} o fun x _ => x) = o :=
sup_typein_limit
#align ordinal.bsup_id_limit Ordinal.bsup_id_limit
@[simp]
theorem bsup_id_succ (o) : (bsup.{u, u} (succ o) fun x _ => x) = o :=
sup_typein_succ
#align ordinal.bsup_id_succ Ordinal.bsup_id_succ
theorem blsub_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : brange o f ⊆ brange o' g) : blsub.{u, max v w} o f ≤ blsub.{v, max u w} o' g :=
bsup_le_of_brange_subset.{u, v, w} fun a ⟨b, hb, hb'⟩ => by
obtain ⟨c, hc, hc'⟩ := h ⟨b, hb, rfl⟩
simp_rw [← hc'] at hb'
exact ⟨c, hc, hb'⟩
#align ordinal.blsub_le_of_brange_subset Ordinal.blsub_le_of_brange_subset
theorem blsub_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : { o | ∃ i hi, f i hi = o } = { o | ∃ i hi, g i hi = o }) :
blsub.{u, max v w} o f = blsub.{v, max u w} o' g :=
(blsub_le_of_brange_subset.{u, v, w} h.le).antisymm (blsub_le_of_brange_subset.{v, u, w} h.ge)
#align ordinal.blsub_eq_of_brange_eq Ordinal.blsub_eq_of_brange_eq
theorem bsup_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}}
(hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}}
(hg : blsub.{_, u} o' g = o) :
(bsup.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = bsup.{_, w} o f := by
apply le_antisymm <;> refine bsup_le fun i hi => ?_
· apply le_bsup
· rw [← hg, lt_blsub_iff] at hi
rcases hi with ⟨j, hj, hj'⟩
exact (hf _ _ hj').trans (le_bsup _ _ _)
#align ordinal.bsup_comp Ordinal.bsup_comp
theorem blsub_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}}
(hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}}
(hg : blsub.{_, u} o' g = o) :
(blsub.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = blsub.{_, w} o f :=
@bsup_comp.{u, v, w} o _ (fun a ha => succ (f a ha))
(fun {_ _} _ _ h => succ_le_succ_iff.2 (hf _ _ h)) g hg
#align ordinal.blsub_comp Ordinal.blsub_comp
theorem IsNormal.bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}}
(h : IsLimit o) : (Ordinal.bsup.{_, v} o fun x _ => f x) = f o := by
rw [← IsNormal.bsup.{u, u, v} H (fun x _ => x) h.1, bsup_id_limit h.2]
#align ordinal.is_normal.bsup_eq Ordinal.IsNormal.bsup_eq
theorem IsNormal.blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}}
(h : IsLimit o) : (blsub.{_, v} o fun x _ => f x) = f o := by
rw [← IsNormal.bsup_eq.{u, v} H h, bsup_eq_blsub_of_lt_succ_limit h]
exact fun a _ => H.1 a
#align ordinal.is_normal.blsub_eq Ordinal.IsNormal.blsub_eq
theorem isNormal_iff_lt_succ_and_bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} :
IsNormal f ↔ (∀ a, f a < f (succ a)) ∧ ∀ o, IsLimit o → (bsup.{_, v} o fun x _ => f x) = f o :=
⟨fun h => ⟨h.1, @IsNormal.bsup_eq f h⟩, fun ⟨h₁, h₂⟩ =>
⟨h₁, fun o ho a => by
rw [← h₂ o ho]
exact bsup_le_iff⟩⟩
#align ordinal.is_normal_iff_lt_succ_and_bsup_eq Ordinal.isNormal_iff_lt_succ_and_bsup_eq
theorem isNormal_iff_lt_succ_and_blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} :
IsNormal f ↔ (∀ a, f a < f (succ a)) ∧
∀ o, IsLimit o → (blsub.{_, v} o fun x _ => f x) = f o := by
rw [isNormal_iff_lt_succ_and_bsup_eq.{u, v}, and_congr_right_iff]
intro h
constructor <;> intro H o ho <;> have := H o ho <;>
rwa [← bsup_eq_blsub_of_lt_succ_limit ho fun a _ => h a] at *
#align ordinal.is_normal_iff_lt_succ_and_blsub_eq Ordinal.isNormal_iff_lt_succ_and_blsub_eq
theorem IsNormal.eq_iff_zero_and_succ {f g : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f)
(hg : IsNormal g) : f = g ↔ f 0 = g 0 ∧ ∀ a, f a = g a → f (succ a) = g (succ a) :=
⟨fun h => by simp [h], fun ⟨h₁, h₂⟩ =>
funext fun a => by
induction' a using limitRecOn with _ _ _ ho H
any_goals solve_by_elim
rw [← IsNormal.bsup_eq.{u, u} hf ho, ← IsNormal.bsup_eq.{u, u} hg ho]
congr
ext b hb
exact H b hb⟩
#align ordinal.is_normal.eq_iff_zero_and_succ Ordinal.IsNormal.eq_iff_zero_and_succ
/-- A two-argument version of `Ordinal.blsub`.
We don't develop a full API for this, since it's only used in a handful of existence results. -/
def blsub₂ (o₁ o₂ : Ordinal) (op : {a : Ordinal} → (a < o₁) → {b : Ordinal} → (b < o₂) → Ordinal) :
Ordinal :=
lsub (fun x : o₁.out.α × o₂.out.α => op (typein_lt_self x.1) (typein_lt_self x.2))
#align ordinal.blsub₂ Ordinal.blsub₂
theorem lt_blsub₂ {o₁ o₂ : Ordinal}
(op : {a : Ordinal} → (a < o₁) → {b : Ordinal} → (b < o₂) → Ordinal) {a b : Ordinal}
(ha : a < o₁) (hb : b < o₂) : op ha hb < blsub₂ o₁ o₂ op := by
convert lt_lsub _ (Prod.mk (enum (· < ·) a (by rwa [type_lt]))
(enum (· < ·) b (by rwa [type_lt])))
simp only [typein_enum]
#align ordinal.lt_blsub₂ Ordinal.lt_blsub₂
/-! ### Minimum excluded ordinals -/
/-- The minimum excluded ordinal in a family of ordinals. -/
def mex {ι : Type u} (f : ι → Ordinal.{max u v}) : Ordinal :=
sInf (Set.range f)ᶜ
#align ordinal.mex Ordinal.mex
theorem mex_not_mem_range {ι : Type u} (f : ι → Ordinal.{max u v}) : mex.{_, v} f ∉ Set.range f :=
csInf_mem (nonempty_compl_range.{_, v} f)
#align ordinal.mex_not_mem_range Ordinal.mex_not_mem_range
theorem le_mex_of_forall {ι : Type u} {f : ι → Ordinal.{max u v}} {a : Ordinal}
(H : ∀ b < a, ∃ i, f i = b) : a ≤ mex.{_, v} f := by
by_contra! h
exact mex_not_mem_range f (H _ h)
#align ordinal.le_mex_of_forall Ordinal.le_mex_of_forall
theorem ne_mex {ι : Type u} (f : ι → Ordinal.{max u v}) : ∀ i, f i ≠ mex.{_, v} f := by
simpa using mex_not_mem_range.{_, v} f
#align ordinal.ne_mex Ordinal.ne_mex
theorem mex_le_of_ne {ι} {f : ι → Ordinal} {a} (ha : ∀ i, f i ≠ a) : mex f ≤ a :=
csInf_le' (by simp [ha])
#align ordinal.mex_le_of_ne Ordinal.mex_le_of_ne
theorem exists_of_lt_mex {ι} {f : ι → Ordinal} {a} (ha : a < mex f) : ∃ i, f i = a := by
by_contra! ha'
exact ha.not_le (mex_le_of_ne ha')
#align ordinal.exists_of_lt_mex Ordinal.exists_of_lt_mex
theorem mex_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : mex.{_, v} f ≤ lsub.{_, v} f :=
csInf_le' (lsub_not_mem_range f)
#align ordinal.mex_le_lsub Ordinal.mex_le_lsub
theorem mex_monotone {α β : Type u} {f : α → Ordinal.{max u v}} {g : β → Ordinal.{max u v}}
(h : Set.range f ⊆ Set.range g) : mex.{_, v} f ≤ mex.{_, v} g := by
refine mex_le_of_ne fun i hi => ?_
cases' h ⟨i, rfl⟩ with j hj
rw [← hj] at hi
exact ne_mex g j hi
#align ordinal.mex_monotone Ordinal.mex_monotone
theorem mex_lt_ord_succ_mk {ι : Type u} (f : ι → Ordinal.{u}) :
mex.{_, u} f < (succ #ι).ord := by
by_contra! h
apply (lt_succ #ι).not_le
have H := fun a => exists_of_lt_mex ((typein_lt_self a).trans_le h)
let g : (succ #ι).ord.out.α → ι := fun a => Classical.choose (H a)
have hg : Injective g := fun a b h' => by
have Hf : ∀ x, f (g x) =
typein ((· < ·) : (succ #ι).ord.out.α → (succ #ι).ord.out.α → Prop) x :=
fun a => Classical.choose_spec (H a)
apply_fun f at h'
rwa [Hf, Hf, typein_inj] at h'
convert Cardinal.mk_le_of_injective hg
rw [Cardinal.mk_ord_out (succ #ι)]
#align ordinal.mex_lt_ord_succ_mk Ordinal.mex_lt_ord_succ_mk
/-- The minimum excluded ordinal of a family of ordinals indexed by the set of ordinals less than
some `o : Ordinal.{u}`. This is a special case of `mex` over the family provided by
`familyOfBFamily`.
This is to `mex` as `bsup` is to `sup`. -/
def bmex (o : Ordinal) (f : ∀ a < o, Ordinal) : Ordinal :=
mex (familyOfBFamily o f)
#align ordinal.bmex Ordinal.bmex
theorem bmex_not_mem_brange {o : Ordinal} (f : ∀ a < o, Ordinal) : bmex o f ∉ brange o f := by
rw [← range_familyOfBFamily]
apply mex_not_mem_range
#align ordinal.bmex_not_mem_brange Ordinal.bmex_not_mem_brange
theorem le_bmex_of_forall {o : Ordinal} (f : ∀ a < o, Ordinal) {a : Ordinal}
(H : ∀ b < a, ∃ i hi, f i hi = b) : a ≤ bmex o f := by
by_contra! h
exact bmex_not_mem_brange f (H _ h)
#align ordinal.le_bmex_of_forall Ordinal.le_bmex_of_forall
theorem ne_bmex {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) {i} (hi) :
f i hi ≠ bmex.{_, v} o f := by
convert (config := {transparency := .default})
ne_mex.{_, v} (familyOfBFamily o f) (enum (· < ·) i (by rwa [type_lt])) using 2
-- Porting note: `familyOfBFamily_enum` → `typein_enum`
rw [typein_enum]
#align ordinal.ne_bmex Ordinal.ne_bmex
theorem bmex_le_of_ne {o : Ordinal} {f : ∀ a < o, Ordinal} {a} (ha : ∀ i hi, f i hi ≠ a) :
bmex o f ≤ a :=
mex_le_of_ne fun _i => ha _ _
#align ordinal.bmex_le_of_ne Ordinal.bmex_le_of_ne
theorem exists_of_lt_bmex {o : Ordinal} {f : ∀ a < o, Ordinal} {a} (ha : a < bmex o f) :
∃ i hi, f i hi = a := by
cases' exists_of_lt_mex ha with i hi
exact ⟨_, typein_lt_self i, hi⟩
#align ordinal.exists_of_lt_bmex Ordinal.exists_of_lt_bmex
theorem bmex_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bmex.{_, v} o f ≤ blsub.{_, v} o f :=
mex_le_lsub _
#align ordinal.bmex_le_blsub Ordinal.bmex_le_blsub
theorem bmex_monotone {o o' : Ordinal.{u}}
{f : ∀ a < o, Ordinal.{max u v}} {g : ∀ a < o', Ordinal.{max u v}}
(h : brange o f ⊆ brange o' g) : bmex.{_, v} o f ≤ bmex.{_, v} o' g :=
mex_monotone (by rwa [range_familyOfBFamily, range_familyOfBFamily])
#align ordinal.bmex_monotone Ordinal.bmex_monotone
theorem bmex_lt_ord_succ_card {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{u}) :
bmex.{_, u} o f < (succ o.card).ord := by
rw [← mk_ordinal_out]
exact mex_lt_ord_succ_mk (familyOfBFamily o f)
#align ordinal.bmex_lt_ord_succ_card Ordinal.bmex_lt_ord_succ_card
end Ordinal
/-! ### Results about injectivity and surjectivity -/
theorem not_surjective_of_ordinal {α : Type u} (f : α → Ordinal.{u}) : ¬Surjective f := fun h =>
Ordinal.lsub_not_mem_range.{u, u} f (h _)
#align not_surjective_of_ordinal not_surjective_of_ordinal
theorem not_injective_of_ordinal {α : Type u} (f : Ordinal.{u} → α) : ¬Injective f := fun h =>
not_surjective_of_ordinal _ (invFun_surjective h)
#align not_injective_of_ordinal not_injective_of_ordinal
theorem not_surjective_of_ordinal_of_small {α : Type v} [Small.{u} α] (f : α → Ordinal.{u}) :
¬Surjective f := fun h => not_surjective_of_ordinal _ (h.comp (equivShrink _).symm.surjective)
#align not_surjective_of_ordinal_of_small not_surjective_of_ordinal_of_small
theorem not_injective_of_ordinal_of_small {α : Type v} [Small.{u} α] (f : Ordinal.{u} → α) :
¬Injective f := fun h => not_injective_of_ordinal _ ((equivShrink _).injective.comp h)
#align not_injective_of_ordinal_of_small not_injective_of_ordinal_of_small
/-- The type of ordinals in universe `u` is not `Small.{u}`. This is the type-theoretic analog of
the Burali-Forti paradox. -/
theorem not_small_ordinal : ¬Small.{u} Ordinal.{max u v} := fun h =>
@not_injective_of_ordinal_of_small _ h _ fun _a _b => Ordinal.lift_inj.{v, u}.1
#align not_small_ordinal not_small_ordinal
/-! ### Enumerating unbounded sets of ordinals with ordinals -/
namespace Ordinal
section
/-- Enumerator function for an unbounded set of ordinals. -/
def enumOrd (S : Set Ordinal.{u}) : Ordinal → Ordinal :=
lt_wf.fix fun o f => sInf (S ∩ Set.Ici (blsub.{u, u} o f))
#align ordinal.enum_ord Ordinal.enumOrd
variable {S : Set Ordinal.{u}}
/-- The equation that characterizes `enumOrd` definitionally. This isn't the nicest expression to
work with, so consider using `enumOrd_def` instead. -/
theorem enumOrd_def' (o) :
enumOrd S o = sInf (S ∩ Set.Ici (blsub.{u, u} o fun a _ => enumOrd S a)) :=
lt_wf.fix_eq _ _
#align ordinal.enum_ord_def' Ordinal.enumOrd_def'
/-- The set in `enumOrd_def'` is nonempty. -/
theorem enumOrd_def'_nonempty (hS : Unbounded (· < ·) S) (a) : (S ∩ Set.Ici a).Nonempty :=
let ⟨b, hb, hb'⟩ := hS a
⟨b, hb, le_of_not_gt hb'⟩
#align ordinal.enum_ord_def'_nonempty Ordinal.enumOrd_def'_nonempty
private theorem enumOrd_mem_aux (hS : Unbounded (· < ·) S) (o) :
enumOrd S o ∈ S ∩ Set.Ici (blsub.{u, u} o fun c _ => enumOrd S c) := by
rw [enumOrd_def']
exact csInf_mem (enumOrd_def'_nonempty hS _)
theorem enumOrd_mem (hS : Unbounded (· < ·) S) (o) : enumOrd S o ∈ S :=
(enumOrd_mem_aux hS o).left
#align ordinal.enum_ord_mem Ordinal.enumOrd_mem
theorem blsub_le_enumOrd (hS : Unbounded (· < ·) S) (o) :
(blsub.{u, u} o fun c _ => enumOrd S c) ≤ enumOrd S o :=
(enumOrd_mem_aux hS o).right
#align ordinal.blsub_le_enum_ord Ordinal.blsub_le_enumOrd
theorem enumOrd_strictMono (hS : Unbounded (· < ·) S) : StrictMono (enumOrd S) := fun _ _ h =>
(lt_blsub.{u, u} _ _ h).trans_le (blsub_le_enumOrd hS _)
#align ordinal.enum_ord_strict_mono Ordinal.enumOrd_strictMono
/-- A more workable definition for `enumOrd`. -/
theorem enumOrd_def (o) : enumOrd S o = sInf (S ∩ { b | ∀ c, c < o → enumOrd S c < b }) := by
rw [enumOrd_def']
congr; ext
exact ⟨fun h a hao => (lt_blsub.{u, u} _ _ hao).trans_le h, blsub_le⟩
#align ordinal.enum_ord_def Ordinal.enumOrd_def
/-- The set in `enumOrd_def` is nonempty. -/
theorem enumOrd_def_nonempty (hS : Unbounded (· < ·) S) {o} :
{ x | x ∈ S ∧ ∀ c, c < o → enumOrd S c < x }.Nonempty :=
⟨_, enumOrd_mem hS o, fun _ b => enumOrd_strictMono hS b⟩
#align ordinal.enum_ord_def_nonempty Ordinal.enumOrd_def_nonempty
@[simp]
theorem enumOrd_range {f : Ordinal → Ordinal} (hf : StrictMono f) : enumOrd (range f) = f :=
funext fun o => by
apply Ordinal.induction o
intro a H
rw [enumOrd_def a]
have Hfa : f a ∈ range f ∩ { b | ∀ c, c < a → enumOrd (range f) c < b } :=
⟨mem_range_self a, fun b hb => by
rw [H b hb]
exact hf hb⟩
refine (csInf_le' Hfa).antisymm ((le_csInf_iff'' ⟨_, Hfa⟩).2 ?_)
rintro _ ⟨⟨c, rfl⟩, hc : ∀ b < a, enumOrd (range f) b < f c⟩
rw [hf.le_iff_le]
contrapose! hc
exact ⟨c, hc, (H c hc).ge⟩
#align ordinal.enum_ord_range Ordinal.enumOrd_range
@[simp]
theorem enumOrd_univ : enumOrd Set.univ = id := by
rw [← range_id]
exact enumOrd_range strictMono_id
#align ordinal.enum_ord_univ Ordinal.enumOrd_univ
@[simp]
theorem enumOrd_zero : enumOrd S 0 = sInf S := by
rw [enumOrd_def]
simp [Ordinal.not_lt_zero]
#align ordinal.enum_ord_zero Ordinal.enumOrd_zero
theorem enumOrd_succ_le {a b} (hS : Unbounded (· < ·) S) (ha : a ∈ S) (hb : enumOrd S b < a) :
enumOrd S (succ b) ≤ a := by
rw [enumOrd_def]
exact
csInf_le' ⟨ha, fun c hc => ((enumOrd_strictMono hS).monotone (le_of_lt_succ hc)).trans_lt hb⟩
#align ordinal.enum_ord_succ_le Ordinal.enumOrd_succ_le
theorem enumOrd_le_of_subset {S T : Set Ordinal} (hS : Unbounded (· < ·) S) (hST : S ⊆ T) (a) :
enumOrd T a ≤ enumOrd S a := by
apply Ordinal.induction a
intro b H
rw [enumOrd_def]
exact csInf_le' ⟨hST (enumOrd_mem hS b), fun c h => (H c h).trans_lt (enumOrd_strictMono hS h)⟩
#align ordinal.enum_ord_le_of_subset Ordinal.enumOrd_le_of_subset
theorem enumOrd_surjective (hS : Unbounded (· < ·) S) : ∀ s ∈ S, ∃ a, enumOrd S a = s := fun s hs =>
⟨sSup { a | enumOrd S a ≤ s }, by
apply le_antisymm
· rw [enumOrd_def]
refine csInf_le' ⟨hs, fun a ha => ?_⟩
have : enumOrd S 0 ≤ s := by
rw [enumOrd_zero]
exact csInf_le' hs
-- Porting note: `flip` is required to infer a metavariable.
rcases flip exists_lt_of_lt_csSup ha ⟨0, this⟩ with ⟨b, hb, hab⟩
exact (enumOrd_strictMono hS hab).trans_le hb
· by_contra! h
exact
(le_csSup ⟨s, fun a => (lt_wf.self_le_of_strictMono (enumOrd_strictMono hS) a).trans⟩
(enumOrd_succ_le hS hs h)).not_lt
(lt_succ _)⟩
#align ordinal.enum_ord_surjective Ordinal.enumOrd_surjective
/-- An order isomorphism between an unbounded set of ordinals and the ordinals. -/
def enumOrdOrderIso (hS : Unbounded (· < ·) S) : Ordinal ≃o S :=
StrictMono.orderIsoOfSurjective (fun o => ⟨_, enumOrd_mem hS o⟩) (enumOrd_strictMono hS) fun s =>
let ⟨a, ha⟩ := enumOrd_surjective hS s s.prop
⟨a, Subtype.eq ha⟩
#align ordinal.enum_ord_order_iso Ordinal.enumOrdOrderIso
theorem range_enumOrd (hS : Unbounded (· < ·) S) : range (enumOrd S) = S := by
rw [range_eq_iff]
exact ⟨enumOrd_mem hS, enumOrd_surjective hS⟩
#align ordinal.range_enum_ord Ordinal.range_enumOrd
/-- A characterization of `enumOrd`: it is the unique strict monotonic function with range `S`. -/
theorem eq_enumOrd (f : Ordinal → Ordinal) (hS : Unbounded (· < ·) S) :
StrictMono f ∧ range f = S ↔ f = enumOrd S := by
constructor
· rintro ⟨h₁, h₂⟩
rwa [← lt_wf.eq_strictMono_iff_eq_range h₁ (enumOrd_strictMono hS), range_enumOrd hS]
· rintro rfl
exact ⟨enumOrd_strictMono hS, range_enumOrd hS⟩
#align ordinal.eq_enum_ord Ordinal.eq_enumOrd
end
/-! ### Casting naturals into ordinals, compatibility with operations -/
@[simp]
theorem one_add_natCast (m : ℕ) : 1 + (m : Ordinal) = succ m := by
rw [← Nat.cast_one, ← Nat.cast_add, add_comm]
rfl
#align ordinal.one_add_nat_cast Ordinal.one_add_natCast
@[deprecated (since := "2024-04-17")]
alias one_add_nat_cast := one_add_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem one_add_ofNat (m : ℕ) [m.AtLeastTwo] :
1 + (no_index (OfNat.ofNat m : Ordinal)) = Order.succ (OfNat.ofNat m : Ordinal) :=
one_add_natCast m
@[simp, norm_cast]
theorem natCast_mul (m : ℕ) : ∀ n : ℕ, ((m * n : ℕ) : Ordinal) = m * n
| 0 => by simp
| n + 1 => by rw [Nat.mul_succ, Nat.cast_add, natCast_mul m n, Nat.cast_succ, mul_add_one]
#align ordinal.nat_cast_mul Ordinal.natCast_mul
@[deprecated (since := "2024-04-17")]
alias nat_cast_mul := natCast_mul
/-- Alias of `Nat.cast_le`, specialized to `Ordinal` --/
theorem natCast_le {m n : ℕ} : (m : Ordinal) ≤ n ↔ m ≤ n := by
rw [← Cardinal.ord_nat, ← Cardinal.ord_nat, Cardinal.ord_le_ord, Cardinal.natCast_le]
#align ordinal.nat_cast_le Ordinal.natCast_le
@[deprecated (since := "2024-04-17")]
alias nat_cast_le := natCast_le
/-- Alias of `Nat.cast_inj`, specialized to `Ordinal` --/
theorem natCast_inj {m n : ℕ} : (m : Ordinal) = n ↔ m = n := by
simp only [le_antisymm_iff, natCast_le]
#align ordinal.nat_cast_inj Ordinal.natCast_inj
@[deprecated (since := "2024-04-17")]
alias nat_cast_inj := natCast_inj
instance charZero : CharZero Ordinal where
cast_injective _ _ := natCast_inj.mp
/-- Alias of `Nat.cast_lt`, specialized to `Ordinal` --/
theorem natCast_lt {m n : ℕ} : (m : Ordinal) < n ↔ m < n := Nat.cast_lt
#align ordinal.nat_cast_lt Ordinal.natCast_lt
@[deprecated (since := "2024-04-17")]
alias nat_cast_lt := natCast_lt
/-- Alias of `Nat.cast_eq_zero`, specialized to `Ordinal` --/
theorem natCast_eq_zero {n : ℕ} : (n : Ordinal) = 0 ↔ n = 0 := Nat.cast_eq_zero
#align ordinal.nat_cast_eq_zero Ordinal.natCast_eq_zero
@[deprecated (since := "2024-04-17")]
alias nat_cast_eq_zero := natCast_eq_zero
/-- Alias of `Nat.cast_eq_zero`, specialized to `Ordinal` --/
theorem natCast_ne_zero {n : ℕ} : (n : Ordinal) ≠ 0 ↔ n ≠ 0 := Nat.cast_ne_zero
#align ordinal.nat_cast_ne_zero Ordinal.natCast_ne_zero
@[deprecated (since := "2024-04-17")]
alias nat_cast_ne_zero := natCast_ne_zero
/-- Alias of `Nat.cast_pos'`, specialized to `Ordinal` --/
theorem natCast_pos {n : ℕ} : (0 : Ordinal) < n ↔ 0 < n := Nat.cast_pos'
#align ordinal.nat_cast_pos Ordinal.natCast_pos
@[deprecated (since := "2024-04-17")]
alias nat_cast_pos := natCast_pos
@[simp, norm_cast]
theorem natCast_sub (m n : ℕ) : ((m - n : ℕ) : Ordinal) = m - n := by
rcases le_total m n with h | h
· rw [tsub_eq_zero_iff_le.2 h, Ordinal.sub_eq_zero_iff_le.2 (natCast_le.2 h)]
rfl
· apply (add_left_cancel n).1
rw [← Nat.cast_add, add_tsub_cancel_of_le h, Ordinal.add_sub_cancel_of_le (natCast_le.2 h)]
#align ordinal.nat_cast_sub Ordinal.natCast_sub
@[deprecated (since := "2024-04-17")]
alias nat_cast_sub := natCast_sub
@[simp, norm_cast]
| Mathlib/SetTheory/Ordinal/Arithmetic.lean | 2,386 | 2,395 | theorem natCast_div (m n : ℕ) : ((m / n : ℕ) : Ordinal) = m / n := by |
rcases eq_or_ne n 0 with (rfl | hn)
· simp
· have hn' := natCast_ne_zero.2 hn
apply le_antisymm
· rw [le_div hn', ← natCast_mul, natCast_le, mul_comm]
apply Nat.div_mul_le_self
· rw [div_le hn', ← add_one_eq_succ, ← Nat.cast_succ, ← natCast_mul, natCast_lt, mul_comm, ←
Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero hn)]
apply Nat.lt_succ_self
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Data.Countable.Basic
import Mathlib.Data.Fin.VecNotation
import Mathlib.Order.Disjointed
import Mathlib.MeasureTheory.OuterMeasure.Defs
#align_import measure_theory.measure.outer_measure from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55"
/-!
# Outer Measures
An outer measure is a function `μ : Set α → ℝ≥0∞`, from the powerset of a type to the extended
nonnegative real numbers that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is monotone;
3. `μ` is countably subadditive. This means that the outer measure of a countable union is at most
the sum of the outer measure on the individual sets.
Note that we do not need `α` to be measurable to define an outer measure.
## References
<https://en.wikipedia.org/wiki/Outer_measure>
## Tags
outer measure
-/
noncomputable section
open Set Function Filter
open scoped Classical NNReal Topology ENNReal
namespace MeasureTheory
section OuterMeasureClass
variable {α ι F : Type*} [FunLike F (Set α) ℝ≥0∞] [OuterMeasureClass F α]
{μ : F} {s t : Set α}
@[simp]
theorem measure_empty : μ ∅ = 0 := OuterMeasureClass.measure_empty μ
#align measure_theory.measure_empty MeasureTheory.measure_empty
@[mono, gcongr]
theorem measure_mono (h : s ⊆ t) : μ s ≤ μ t :=
OuterMeasureClass.measure_mono μ h
#align measure_theory.measure_mono MeasureTheory.measure_mono
theorem measure_mono_null (h : s ⊆ t) (ht : μ t = 0) : μ s = 0 :=
eq_bot_mono (measure_mono h) ht
#align measure_theory.measure_mono_null MeasureTheory.measure_mono_null
theorem measure_pos_of_superset (h : s ⊆ t) (hs : μ s ≠ 0) : 0 < μ t :=
hs.bot_lt.trans_le (measure_mono h)
theorem measure_iUnion_le [Countable ι] (s : ι → Set α) : μ (⋃ i, s i) ≤ ∑' i, μ (s i) := by
refine rel_iSup_tsum μ measure_empty (· ≤ ·) (fun t ↦ ?_) _
calc
μ (⋃ i, t i) = μ (⋃ i, disjointed t i) := by rw [iUnion_disjointed]
_ ≤ ∑' i, μ (disjointed t i) :=
OuterMeasureClass.measure_iUnion_nat_le _ _ (disjoint_disjointed _)
_ ≤ ∑' i, μ (t i) := by gcongr; apply disjointed_subset
#align measure_theory.measure_Union_le MeasureTheory.measure_iUnion_le
theorem measure_biUnion_le {I : Set ι} (μ : F) (hI : I.Countable) (s : ι → Set α) :
μ (⋃ i ∈ I, s i) ≤ ∑' i : I, μ (s i) := by
have := hI.to_subtype
rw [biUnion_eq_iUnion]
apply measure_iUnion_le
#align measure_theory.measure_bUnion_le MeasureTheory.measure_biUnion_le
theorem measure_biUnion_finset_le (I : Finset ι) (s : ι → Set α) :
μ (⋃ i ∈ I, s i) ≤ ∑ i ∈ I, μ (s i) :=
(measure_biUnion_le μ I.countable_toSet s).trans_eq <| I.tsum_subtype (μ <| s ·)
#align measure_theory.measure_bUnion_finset_le MeasureTheory.measure_biUnion_finset_le
theorem measure_iUnion_fintype_le [Fintype ι] (μ : F) (s : ι → Set α) :
μ (⋃ i, s i) ≤ ∑ i, μ (s i) := by
simpa using measure_biUnion_finset_le Finset.univ s
#align measure_theory.measure_Union_fintype_le MeasureTheory.measure_iUnion_fintype_le
theorem measure_union_le (s t : Set α) : μ (s ∪ t) ≤ μ s + μ t := by
simpa [union_eq_iUnion] using measure_iUnion_fintype_le μ (cond · s t)
#align measure_theory.measure_union_le MeasureTheory.measure_union_le
theorem measure_le_inter_add_diff (μ : F) (s t : Set α) : μ s ≤ μ (s ∩ t) + μ (s \ t) := by
simpa using measure_union_le (s ∩ t) (s \ t)
theorem measure_diff_null (ht : μ t = 0) : μ (s \ t) = μ s :=
(measure_mono diff_subset).antisymm <| calc
μ s ≤ μ (s ∩ t) + μ (s \ t) := measure_le_inter_add_diff _ _ _
_ ≤ μ t + μ (s \ t) := by gcongr; apply inter_subset_right
_ = μ (s \ t) := by simp [ht]
#align measure_theory.measure_diff_null MeasureTheory.measure_diff_null
theorem measure_biUnion_null_iff {I : Set ι} (hI : I.Countable) {s : ι → Set α} :
μ (⋃ i ∈ I, s i) = 0 ↔ ∀ i ∈ I, μ (s i) = 0 := by
refine ⟨fun h i hi ↦ measure_mono_null (subset_biUnion_of_mem hi) h, fun h ↦ ?_⟩
have _ := hI.to_subtype
simpa [h] using measure_iUnion_le (μ := μ) fun x : I ↦ s x
#align measure_theory.measure_bUnion_null_iff MeasureTheory.measure_biUnion_null_iff
theorem measure_sUnion_null_iff {S : Set (Set α)} (hS : S.Countable) :
μ (⋃₀ S) = 0 ↔ ∀ s ∈ S, μ s = 0 := by
rw [sUnion_eq_biUnion, measure_biUnion_null_iff hS]
#align measure_theory.measure_sUnion_null_iff MeasureTheory.measure_sUnion_null_iff
@[simp]
theorem measure_iUnion_null_iff {ι : Sort*} [Countable ι] {s : ι → Set α} :
μ (⋃ i, s i) = 0 ↔ ∀ i, μ (s i) = 0 := by
rw [← sUnion_range, measure_sUnion_null_iff (countable_range s), forall_mem_range]
#align measure_theory.measure_Union_null_iff MeasureTheory.measure_iUnion_null_iff
alias ⟨_, measure_iUnion_null⟩ := measure_iUnion_null_iff
#align measure_theory.measure_Union_null MeasureTheory.measure_iUnion_null
@[simp]
theorem measure_union_null_iff : μ (s ∪ t) = 0 ↔ μ s = 0 ∧ μ t = 0 := by
simp [union_eq_iUnion, and_comm]
#align measure_theory.measure_union_null_iff MeasureTheory.measure_union_null_iff
| Mathlib/MeasureTheory/OuterMeasure/Basic.lean | 129 | 129 | theorem measure_union_null (hs : μ s = 0) (ht : μ t = 0) : μ (s ∪ t) = 0 := by | simp [*]
|
/-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
-/
import Mathlib.Algebra.BigOperators.Group.Multiset
import Mathlib.Data.PNat.Prime
import Mathlib.Data.Nat.Factors
import Mathlib.Data.Multiset.Sort
#align_import data.pnat.factors from "leanprover-community/mathlib"@"e3d9ab8faa9dea8f78155c6c27d62a621f4c152d"
/-!
# Prime factors of nonzero naturals
This file defines the factorization of a nonzero natural number `n` as a multiset of primes,
the multiplicity of `p` in this factors multiset being the p-adic valuation of `n`.
## Main declarations
* `PrimeMultiset`: Type of multisets of prime numbers.
* `FactorMultiset n`: Multiset of prime factors of `n`.
-/
-- Porting note: `deriving` contained Inhabited, CanonicallyOrderedAddCommMonoid, DistribLattice,
-- SemilatticeSup, OrderBot, Sub, OrderedSub
/-- The type of multisets of prime numbers. Unique factorization
gives an equivalence between this set and ℕ+, as we will formalize
below. -/
def PrimeMultiset :=
Multiset Nat.Primes deriving Inhabited, CanonicallyOrderedAddCommMonoid, DistribLattice,
SemilatticeSup, Sub
#align prime_multiset PrimeMultiset
instance : OrderBot PrimeMultiset where
bot_le := by simp only [bot_le, forall_const]
instance : OrderedSub PrimeMultiset where
tsub_le_iff_right _ _ _ := Multiset.sub_le_iff_le_add
namespace PrimeMultiset
-- `@[derive]` doesn't work for `meta` instances
unsafe instance : Repr PrimeMultiset := by delta PrimeMultiset; infer_instance
/-- The multiset consisting of a single prime -/
def ofPrime (p : Nat.Primes) : PrimeMultiset :=
({p} : Multiset Nat.Primes)
#align prime_multiset.of_prime PrimeMultiset.ofPrime
theorem card_ofPrime (p : Nat.Primes) : Multiset.card (ofPrime p) = 1 :=
rfl
#align prime_multiset.card_of_prime PrimeMultiset.card_ofPrime
/-- We can forget the primality property and regard a multiset
of primes as just a multiset of positive integers, or a multiset
of natural numbers. In the opposite direction, if we have a
multiset of positive integers or natural numbers, together with
a proof that all the elements are prime, then we can regard it
as a multiset of primes. The next block of results records
obvious properties of these coercions.
-/
def toNatMultiset : PrimeMultiset → Multiset ℕ := fun v => v.map Coe.coe
#align prime_multiset.to_nat_multiset PrimeMultiset.toNatMultiset
instance coeNat : Coe PrimeMultiset (Multiset ℕ) :=
⟨toNatMultiset⟩
#align prime_multiset.coe_nat PrimeMultiset.coeNat
/-- `PrimeMultiset.coe`, the coercion from a multiset of primes to a multiset of
naturals, promoted to an `AddMonoidHom`. -/
def coeNatMonoidHom : PrimeMultiset →+ Multiset ℕ :=
{ Multiset.mapAddMonoidHom Coe.coe with toFun := Coe.coe }
#align prime_multiset.coe_nat_monoid_hom PrimeMultiset.coeNatMonoidHom
@[simp]
theorem coe_coeNatMonoidHom : (coeNatMonoidHom : PrimeMultiset → Multiset ℕ) = Coe.coe :=
rfl
#align prime_multiset.coe_coe_nat_monoid_hom PrimeMultiset.coe_coeNatMonoidHom
theorem coeNat_injective : Function.Injective (Coe.coe : PrimeMultiset → Multiset ℕ) :=
Multiset.map_injective Nat.Primes.coe_nat_injective
#align prime_multiset.coe_nat_injective PrimeMultiset.coeNat_injective
theorem coeNat_ofPrime (p : Nat.Primes) : (ofPrime p : Multiset ℕ) = {(p : ℕ)} :=
rfl
#align prime_multiset.coe_nat_of_prime PrimeMultiset.coeNat_ofPrime
theorem coeNat_prime (v : PrimeMultiset) (p : ℕ) (h : p ∈ (v : Multiset ℕ)) : p.Prime := by
rcases Multiset.mem_map.mp h with ⟨⟨_, hp'⟩, ⟨_, h_eq⟩⟩
exact h_eq ▸ hp'
#align prime_multiset.coe_nat_prime PrimeMultiset.coeNat_prime
/-- Converts a `PrimeMultiset` to a `Multiset ℕ+`. -/
def toPNatMultiset : PrimeMultiset → Multiset ℕ+ := fun v => v.map Coe.coe
#align prime_multiset.to_pnat_multiset PrimeMultiset.toPNatMultiset
instance coePNat : Coe PrimeMultiset (Multiset ℕ+) :=
⟨toPNatMultiset⟩
#align prime_multiset.coe_pnat PrimeMultiset.coePNat
/-- `coePNat`, the coercion from a multiset of primes to a multiset of positive
naturals, regarded as an `AddMonoidHom`. -/
def coePNatMonoidHom : PrimeMultiset →+ Multiset ℕ+ :=
{ Multiset.mapAddMonoidHom Coe.coe with toFun := Coe.coe }
#align prime_multiset.coe_pnat_monoid_hom PrimeMultiset.coePNatMonoidHom
@[simp]
theorem coe_coePNatMonoidHom : (coePNatMonoidHom : PrimeMultiset → Multiset ℕ+) = Coe.coe :=
rfl
#align prime_multiset.coe_coe_pnat_monoid_hom PrimeMultiset.coe_coePNatMonoidHom
theorem coePNat_injective : Function.Injective (Coe.coe : PrimeMultiset → Multiset ℕ+) :=
Multiset.map_injective Nat.Primes.coe_pnat_injective
#align prime_multiset.coe_pnat_injective PrimeMultiset.coePNat_injective
theorem coePNat_ofPrime (p : Nat.Primes) : (ofPrime p : Multiset ℕ+) = {(p : ℕ+)} :=
rfl
#align prime_multiset.coe_pnat_of_prime PrimeMultiset.coePNat_ofPrime
| Mathlib/Data/PNat/Factors.lean | 121 | 123 | theorem coePNat_prime (v : PrimeMultiset) (p : ℕ+) (h : p ∈ (v : Multiset ℕ+)) : p.Prime := by |
rcases Multiset.mem_map.mp h with ⟨⟨_, hp'⟩, ⟨_, h_eq⟩⟩
exact h_eq ▸ hp'
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Data.Complex.Abs
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Nat.Choose.Sum
#align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Exponential, trigonometric and hyperbolic trigonometric functions
This file contains the definitions of the real and complex exponential, sine, cosine, tangent,
hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions.
-/
open CauSeq Finset IsAbsoluteValue
open scoped Classical ComplexConjugate
namespace Complex
theorem isCauSeq_abs_exp (z : ℂ) :
IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) :=
let ⟨n, hn⟩ := exists_nat_gt (abs z)
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn
IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff hn0, one_mul]) fun m hm => by
rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div,
mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
#align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_abs_exp z).of_abv
#align complex.is_cau_exp Complex.isCauSeq_exp
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
-- Porting note (#11180): removed `@[pp_nodot]`
def exp' (z : ℂ) : CauSeq ℂ Complex.abs :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
#align complex.exp' Complex.exp'
/-- The complex exponential function, defined via its Taylor series -/
-- Porting note (#11180): removed `@[pp_nodot]`
-- Porting note: removed `irreducible` attribute, so I can prove things
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
#align complex.exp Complex.exp
/-- The complex sine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def sin (z : ℂ) : ℂ :=
(exp (-z * I) - exp (z * I)) * I / 2
#align complex.sin Complex.sin
/-- The complex cosine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def cos (z : ℂ) : ℂ :=
(exp (z * I) + exp (-z * I)) / 2
#align complex.cos Complex.cos
/-- The complex tangent function, defined as `sin z / cos z` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def tan (z : ℂ) : ℂ :=
sin z / cos z
#align complex.tan Complex.tan
/-- The complex cotangent function, defined as `cos z / sin z` -/
def cot (z : ℂ) : ℂ :=
cos z / sin z
/-- The complex hyperbolic sine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def sinh (z : ℂ) : ℂ :=
(exp z - exp (-z)) / 2
#align complex.sinh Complex.sinh
/-- The complex hyperbolic cosine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def cosh (z : ℂ) : ℂ :=
(exp z + exp (-z)) / 2
#align complex.cosh Complex.cosh
/-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def tanh (z : ℂ) : ℂ :=
sinh z / cosh z
#align complex.tanh Complex.tanh
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
#align real.exp Real.exp
/-- The real sine function, defined as the real part of the complex sine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def sin (x : ℝ) : ℝ :=
(sin x).re
#align real.sin Real.sin
/-- The real cosine function, defined as the real part of the complex cosine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def cos (x : ℝ) : ℝ :=
(cos x).re
#align real.cos Real.cos
/-- The real tangent function, defined as the real part of the complex tangent -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def tan (x : ℝ) : ℝ :=
(tan x).re
#align real.tan Real.tan
/-- The real cotangent function, defined as the real part of the complex cotangent -/
nonrec def cot (x : ℝ) : ℝ :=
(cot x).re
/-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def sinh (x : ℝ) : ℝ :=
(sinh x).re
#align real.sinh Real.sinh
/-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def cosh (x : ℝ) : ℝ :=
(cosh x).re
#align real.cosh Real.cosh
/-- The real hypebolic tangent function, defined as the real part of
the complex hyperbolic tangent -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def tanh (x : ℝ) : ℝ :=
(tanh x).re
#align real.tanh Real.tanh
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- Porting note: ε0 : ε > 0 but goal is _ < ε
cases' j with j j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
#align complex.exp_zero Complex.exp_zero
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y)
#align complex.exp_add Complex.exp_add
-- Porting note (#11445): new definition
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp (Multiplicative.toAdd z),
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
#align complex.exp_list_sum Complex.exp_list_sum
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
#align complex.exp_multiset_sum Complex.exp_multiset_sum
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
#align complex.exp_sum Complex.exp_sum
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
#align complex.exp_nat_mul Complex.exp_nat_mul
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp
#align complex.exp_ne_zero Complex.exp_ne_zero
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)]
#align complex.exp_neg Complex.exp_neg
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
#align complex.exp_sub Complex.exp_sub
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
#align complex.exp_int_mul Complex.exp_int_mul
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
#align complex.exp_conj Complex.exp_conj
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
#align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
#align complex.of_real_exp Complex.ofReal_exp
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
#align complex.exp_of_real_im Complex.exp_ofReal_im
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
#align complex.exp_of_real_re Complex.exp_ofReal_re
theorem two_sinh : 2 * sinh x = exp x - exp (-x) :=
mul_div_cancel₀ _ two_ne_zero
#align complex.two_sinh Complex.two_sinh
theorem two_cosh : 2 * cosh x = exp x + exp (-x) :=
mul_div_cancel₀ _ two_ne_zero
#align complex.two_cosh Complex.two_cosh
@[simp]
theorem sinh_zero : sinh 0 = 0 := by simp [sinh]
#align complex.sinh_zero Complex.sinh_zero
@[simp]
theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul]
#align complex.sinh_neg Complex.sinh_neg
private theorem sinh_add_aux {a b c d : ℂ} :
(a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring
theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ←
mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add,
mul_left_comm, two_cosh, ← mul_assoc, two_cosh]
exact sinh_add_aux
#align complex.sinh_add Complex.sinh_add
@[simp]
theorem cosh_zero : cosh 0 = 1 := by simp [cosh]
#align complex.cosh_zero Complex.cosh_zero
@[simp]
theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg]
#align complex.cosh_neg Complex.cosh_neg
private theorem cosh_add_aux {a b c d : ℂ} :
(a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring
theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ←
mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add,
mul_left_comm, two_cosh, mul_left_comm, two_sinh]
exact cosh_add_aux
#align complex.cosh_add Complex.cosh_add
theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by
simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg]
#align complex.sinh_sub Complex.sinh_sub
theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by
simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg]
#align complex.cosh_sub Complex.cosh_sub
theorem sinh_conj : sinh (conj x) = conj (sinh x) := by
rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀]
-- Porting note: not nice
simp [← one_add_one_eq_two]
#align complex.sinh_conj Complex.sinh_conj
@[simp]
theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x :=
conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal]
#align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re
@[simp, norm_cast]
theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x :=
ofReal_sinh_ofReal_re _
#align complex.of_real_sinh Complex.ofReal_sinh
@[simp]
theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by rw [← ofReal_sinh_ofReal_re, ofReal_im]
#align complex.sinh_of_real_im Complex.sinh_ofReal_im
theorem sinh_ofReal_re (x : ℝ) : (sinh x).re = Real.sinh x :=
rfl
#align complex.sinh_of_real_re Complex.sinh_ofReal_re
theorem cosh_conj : cosh (conj x) = conj (cosh x) := by
rw [cosh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_add, cosh, map_div₀]
-- Porting note: not nice
simp [← one_add_one_eq_two]
#align complex.cosh_conj Complex.cosh_conj
theorem ofReal_cosh_ofReal_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x :=
conj_eq_iff_re.1 <| by rw [← cosh_conj, conj_ofReal]
#align complex.of_real_cosh_of_real_re Complex.ofReal_cosh_ofReal_re
@[simp, norm_cast]
theorem ofReal_cosh (x : ℝ) : (Real.cosh x : ℂ) = cosh x :=
ofReal_cosh_ofReal_re _
#align complex.of_real_cosh Complex.ofReal_cosh
@[simp]
theorem cosh_ofReal_im (x : ℝ) : (cosh x).im = 0 := by rw [← ofReal_cosh_ofReal_re, ofReal_im]
#align complex.cosh_of_real_im Complex.cosh_ofReal_im
@[simp]
theorem cosh_ofReal_re (x : ℝ) : (cosh x).re = Real.cosh x :=
rfl
#align complex.cosh_of_real_re Complex.cosh_ofReal_re
theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x :=
rfl
#align complex.tanh_eq_sinh_div_cosh Complex.tanh_eq_sinh_div_cosh
@[simp]
theorem tanh_zero : tanh 0 = 0 := by simp [tanh]
#align complex.tanh_zero Complex.tanh_zero
@[simp]
theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div]
#align complex.tanh_neg Complex.tanh_neg
theorem tanh_conj : tanh (conj x) = conj (tanh x) := by
rw [tanh, sinh_conj, cosh_conj, ← map_div₀, tanh]
#align complex.tanh_conj Complex.tanh_conj
@[simp]
theorem ofReal_tanh_ofReal_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x :=
conj_eq_iff_re.1 <| by rw [← tanh_conj, conj_ofReal]
#align complex.of_real_tanh_of_real_re Complex.ofReal_tanh_ofReal_re
@[simp, norm_cast]
theorem ofReal_tanh (x : ℝ) : (Real.tanh x : ℂ) = tanh x :=
ofReal_tanh_ofReal_re _
#align complex.of_real_tanh Complex.ofReal_tanh
@[simp]
theorem tanh_ofReal_im (x : ℝ) : (tanh x).im = 0 := by rw [← ofReal_tanh_ofReal_re, ofReal_im]
#align complex.tanh_of_real_im Complex.tanh_ofReal_im
theorem tanh_ofReal_re (x : ℝ) : (tanh x).re = Real.tanh x :=
rfl
#align complex.tanh_of_real_re Complex.tanh_ofReal_re
@[simp]
theorem cosh_add_sinh : cosh x + sinh x = exp x := by
rw [← mul_right_inj' (two_ne_zero' ℂ), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul]
#align complex.cosh_add_sinh Complex.cosh_add_sinh
@[simp]
theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh]
#align complex.sinh_add_cosh Complex.sinh_add_cosh
@[simp]
theorem exp_sub_cosh : exp x - cosh x = sinh x :=
sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm
#align complex.exp_sub_cosh Complex.exp_sub_cosh
@[simp]
theorem exp_sub_sinh : exp x - sinh x = cosh x :=
sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm
#align complex.exp_sub_sinh Complex.exp_sub_sinh
@[simp]
theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by
rw [← mul_right_inj' (two_ne_zero' ℂ), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul]
#align complex.cosh_sub_sinh Complex.cosh_sub_sinh
@[simp]
theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh]
#align complex.sinh_sub_cosh Complex.sinh_sub_cosh
@[simp]
theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by
rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero]
#align complex.cosh_sq_sub_sinh_sq Complex.cosh_sq_sub_sinh_sq
theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by
rw [← cosh_sq_sub_sinh_sq x]
ring
#align complex.cosh_sq Complex.cosh_sq
theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by
rw [← cosh_sq_sub_sinh_sq x]
ring
#align complex.sinh_sq Complex.sinh_sq
theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [two_mul, cosh_add, sq, sq]
#align complex.cosh_two_mul Complex.cosh_two_mul
theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by
rw [two_mul, sinh_add]
ring
#align complex.sinh_two_mul Complex.sinh_two_mul
theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by
have h1 : x + 2 * x = 3 * x := by ring
rw [← h1, cosh_add x (2 * x)]
simp only [cosh_two_mul, sinh_two_mul]
have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2 := by ring
rw [h2, sinh_sq]
ring
#align complex.cosh_three_mul Complex.cosh_three_mul
theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by
have h1 : x + 2 * x = 3 * x := by ring
rw [← h1, sinh_add x (2 * x)]
simp only [cosh_two_mul, sinh_two_mul]
have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2 := by ring
rw [h2, cosh_sq]
ring
#align complex.sinh_three_mul Complex.sinh_three_mul
@[simp]
theorem sin_zero : sin 0 = 0 := by simp [sin]
#align complex.sin_zero Complex.sin_zero
@[simp]
theorem sin_neg : sin (-x) = -sin x := by
simp [sin, sub_eq_add_neg, exp_neg, (neg_div _ _).symm, add_mul]
#align complex.sin_neg Complex.sin_neg
theorem two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I :=
mul_div_cancel₀ _ two_ne_zero
#align complex.two_sin Complex.two_sin
theorem two_cos : 2 * cos x = exp (x * I) + exp (-x * I) :=
mul_div_cancel₀ _ two_ne_zero
#align complex.two_cos Complex.two_cos
theorem sinh_mul_I : sinh (x * I) = sin x * I := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, ← mul_assoc, two_sin, mul_assoc, I_mul_I,
mul_neg_one, neg_sub, neg_mul_eq_neg_mul]
set_option linter.uppercaseLean3 false in
#align complex.sinh_mul_I Complex.sinh_mul_I
theorem cosh_mul_I : cosh (x * I) = cos x := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, two_cos, neg_mul_eq_neg_mul]
set_option linter.uppercaseLean3 false in
#align complex.cosh_mul_I Complex.cosh_mul_I
theorem tanh_mul_I : tanh (x * I) = tan x * I := by
rw [tanh_eq_sinh_div_cosh, cosh_mul_I, sinh_mul_I, mul_div_right_comm, tan]
set_option linter.uppercaseLean3 false in
#align complex.tanh_mul_I Complex.tanh_mul_I
theorem cos_mul_I : cos (x * I) = cosh x := by rw [← cosh_mul_I]; ring_nf; simp
set_option linter.uppercaseLean3 false in
#align complex.cos_mul_I Complex.cos_mul_I
theorem sin_mul_I : sin (x * I) = sinh x * I := by
have h : I * sin (x * I) = -sinh x := by
rw [mul_comm, ← sinh_mul_I]
ring_nf
simp
rw [← neg_neg (sinh x), ← h]
apply Complex.ext <;> simp
set_option linter.uppercaseLean3 false in
#align complex.sin_mul_I Complex.sin_mul_I
theorem tan_mul_I : tan (x * I) = tanh x * I := by
rw [tan, sin_mul_I, cos_mul_I, mul_div_right_comm, tanh_eq_sinh_div_cosh]
set_option linter.uppercaseLean3 false in
#align complex.tan_mul_I Complex.tan_mul_I
theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by
rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, add_mul, add_mul, mul_right_comm, ← sinh_mul_I,
mul_assoc, ← sinh_mul_I, ← cosh_mul_I, ← cosh_mul_I, sinh_add]
#align complex.sin_add Complex.sin_add
@[simp]
theorem cos_zero : cos 0 = 1 := by simp [cos]
#align complex.cos_zero Complex.cos_zero
@[simp]
theorem cos_neg : cos (-x) = cos x := by simp [cos, sub_eq_add_neg, exp_neg, add_comm]
#align complex.cos_neg Complex.cos_neg
private theorem cos_add_aux {a b c d : ℂ} :
(a + b) * (c + d) - (b - a) * (d - c) * -1 = 2 * (a * c + b * d) := by ring
theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by
rw [← cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I,
mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg]
#align complex.cos_add Complex.cos_add
theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by
simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg]
#align complex.sin_sub Complex.sin_sub
theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by
simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg]
#align complex.cos_sub Complex.cos_sub
theorem sin_add_mul_I (x y : ℂ) : sin (x + y * I) = sin x * cosh y + cos x * sinh y * I := by
rw [sin_add, cos_mul_I, sin_mul_I, mul_assoc]
set_option linter.uppercaseLean3 false in
#align complex.sin_add_mul_I Complex.sin_add_mul_I
theorem sin_eq (z : ℂ) : sin z = sin z.re * cosh z.im + cos z.re * sinh z.im * I := by
convert sin_add_mul_I z.re z.im; exact (re_add_im z).symm
#align complex.sin_eq Complex.sin_eq
theorem cos_add_mul_I (x y : ℂ) : cos (x + y * I) = cos x * cosh y - sin x * sinh y * I := by
rw [cos_add, cos_mul_I, sin_mul_I, mul_assoc]
set_option linter.uppercaseLean3 false in
#align complex.cos_add_mul_I Complex.cos_add_mul_I
theorem cos_eq (z : ℂ) : cos z = cos z.re * cosh z.im - sin z.re * sinh z.im * I := by
convert cos_add_mul_I z.re z.im; exact (re_add_im z).symm
#align complex.cos_eq Complex.cos_eq
theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := by
have s1 := sin_add ((x + y) / 2) ((x - y) / 2)
have s2 := sin_sub ((x + y) / 2) ((x - y) / 2)
rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1
rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2
rw [s1, s2]
ring
#align complex.sin_sub_sin Complex.sin_sub_sin
theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := by
have s1 := cos_add ((x + y) / 2) ((x - y) / 2)
have s2 := cos_sub ((x + y) / 2) ((x - y) / 2)
rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1
rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2
rw [s1, s2]
ring
#align complex.cos_sub_cos Complex.cos_sub_cos
theorem sin_add_sin : sin x + sin y = 2 * sin ((x + y) / 2) * cos ((x - y) / 2) := by
simpa using sin_sub_sin x (-y)
theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := by
calc
cos x + cos y = cos ((x + y) / 2 + (x - y) / 2) + cos ((x + y) / 2 - (x - y) / 2) := ?_
_ =
cos ((x + y) / 2) * cos ((x - y) / 2) - sin ((x + y) / 2) * sin ((x - y) / 2) +
(cos ((x + y) / 2) * cos ((x - y) / 2) + sin ((x + y) / 2) * sin ((x - y) / 2)) :=
?_
_ = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ?_
· congr <;> field_simp
· rw [cos_add, cos_sub]
ring
#align complex.cos_add_cos Complex.cos_add_cos
theorem sin_conj : sin (conj x) = conj (sin x) := by
rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← RingHom.map_mul,
sinh_conj, mul_neg, sinh_neg, sinh_mul_I, mul_neg]
#align complex.sin_conj Complex.sin_conj
@[simp]
theorem ofReal_sin_ofReal_re (x : ℝ) : ((sin x).re : ℂ) = sin x :=
conj_eq_iff_re.1 <| by rw [← sin_conj, conj_ofReal]
#align complex.of_real_sin_of_real_re Complex.ofReal_sin_ofReal_re
@[simp, norm_cast]
theorem ofReal_sin (x : ℝ) : (Real.sin x : ℂ) = sin x :=
ofReal_sin_ofReal_re _
#align complex.of_real_sin Complex.ofReal_sin
@[simp]
theorem sin_ofReal_im (x : ℝ) : (sin x).im = 0 := by rw [← ofReal_sin_ofReal_re, ofReal_im]
#align complex.sin_of_real_im Complex.sin_ofReal_im
theorem sin_ofReal_re (x : ℝ) : (sin x).re = Real.sin x :=
rfl
#align complex.sin_of_real_re Complex.sin_ofReal_re
theorem cos_conj : cos (conj x) = conj (cos x) := by
rw [← cosh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← cosh_mul_I, cosh_conj, mul_neg, cosh_neg]
#align complex.cos_conj Complex.cos_conj
@[simp]
theorem ofReal_cos_ofReal_re (x : ℝ) : ((cos x).re : ℂ) = cos x :=
conj_eq_iff_re.1 <| by rw [← cos_conj, conj_ofReal]
#align complex.of_real_cos_of_real_re Complex.ofReal_cos_ofReal_re
@[simp, norm_cast]
theorem ofReal_cos (x : ℝ) : (Real.cos x : ℂ) = cos x :=
ofReal_cos_ofReal_re _
#align complex.of_real_cos Complex.ofReal_cos
@[simp]
theorem cos_ofReal_im (x : ℝ) : (cos x).im = 0 := by rw [← ofReal_cos_ofReal_re, ofReal_im]
#align complex.cos_of_real_im Complex.cos_ofReal_im
theorem cos_ofReal_re (x : ℝ) : (cos x).re = Real.cos x :=
rfl
#align complex.cos_of_real_re Complex.cos_ofReal_re
@[simp]
theorem tan_zero : tan 0 = 0 := by simp [tan]
#align complex.tan_zero Complex.tan_zero
theorem tan_eq_sin_div_cos : tan x = sin x / cos x :=
rfl
#align complex.tan_eq_sin_div_cos Complex.tan_eq_sin_div_cos
theorem tan_mul_cos {x : ℂ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by
rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx]
#align complex.tan_mul_cos Complex.tan_mul_cos
@[simp]
theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div]
#align complex.tan_neg Complex.tan_neg
theorem tan_conj : tan (conj x) = conj (tan x) := by rw [tan, sin_conj, cos_conj, ← map_div₀, tan]
#align complex.tan_conj Complex.tan_conj
@[simp]
theorem ofReal_tan_ofReal_re (x : ℝ) : ((tan x).re : ℂ) = tan x :=
conj_eq_iff_re.1 <| by rw [← tan_conj, conj_ofReal]
#align complex.of_real_tan_of_real_re Complex.ofReal_tan_ofReal_re
@[simp, norm_cast]
theorem ofReal_tan (x : ℝ) : (Real.tan x : ℂ) = tan x :=
ofReal_tan_ofReal_re _
#align complex.of_real_tan Complex.ofReal_tan
@[simp]
theorem tan_ofReal_im (x : ℝ) : (tan x).im = 0 := by rw [← ofReal_tan_ofReal_re, ofReal_im]
#align complex.tan_of_real_im Complex.tan_ofReal_im
theorem tan_ofReal_re (x : ℝ) : (tan x).re = Real.tan x :=
rfl
#align complex.tan_of_real_re Complex.tan_ofReal_re
theorem cos_add_sin_I : cos x + sin x * I = exp (x * I) := by
rw [← cosh_add_sinh, sinh_mul_I, cosh_mul_I]
set_option linter.uppercaseLean3 false in
#align complex.cos_add_sin_I Complex.cos_add_sin_I
theorem cos_sub_sin_I : cos x - sin x * I = exp (-x * I) := by
rw [neg_mul, ← cosh_sub_sinh, sinh_mul_I, cosh_mul_I]
set_option linter.uppercaseLean3 false in
#align complex.cos_sub_sin_I Complex.cos_sub_sin_I
@[simp]
theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 :=
Eq.trans (by rw [cosh_mul_I, sinh_mul_I, mul_pow, I_sq, mul_neg_one, sub_neg_eq_add, add_comm])
(cosh_sq_sub_sinh_sq (x * I))
#align complex.sin_sq_add_cos_sq Complex.sin_sq_add_cos_sq
@[simp]
theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq]
#align complex.cos_sq_add_sin_sq Complex.cos_sq_add_sin_sq
theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := by rw [two_mul, cos_add, ← sq, ← sq]
#align complex.cos_two_mul' Complex.cos_two_mul'
theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by
rw [cos_two_mul', eq_sub_iff_add_eq.2 (sin_sq_add_cos_sq x), ← sub_add, sub_add_eq_add_sub,
two_mul]
#align complex.cos_two_mul Complex.cos_two_mul
theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by
rw [two_mul, sin_add, two_mul, add_mul, mul_comm]
#align complex.sin_two_mul Complex.sin_two_mul
theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := by
simp [cos_two_mul, div_add_div_same, mul_div_cancel_left₀, two_ne_zero, -one_div]
#align complex.cos_sq Complex.cos_sq
theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left]
#align complex.cos_sq' Complex.cos_sq'
theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_right]
#align complex.sin_sq Complex.sin_sq
theorem inv_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := by
rw [tan_eq_sin_div_cos, div_pow]
field_simp
#align complex.inv_one_add_tan_sq Complex.inv_one_add_tan_sq
theorem tan_sq_div_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) :
tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by
simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul]
#align complex.tan_sq_div_one_add_tan_sq Complex.tan_sq_div_one_add_tan_sq
theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by
have h1 : x + 2 * x = 3 * x := by ring
rw [← h1, cos_add x (2 * x)]
simp only [cos_two_mul, sin_two_mul, mul_add, mul_sub, mul_one, sq]
have h2 : 4 * cos x ^ 3 = 2 * cos x * cos x * cos x + 2 * cos x * cos x ^ 2 := by ring
rw [h2, cos_sq']
ring
#align complex.cos_three_mul Complex.cos_three_mul
theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by
have h1 : x + 2 * x = 3 * x := by ring
rw [← h1, sin_add x (2 * x)]
simp only [cos_two_mul, sin_two_mul, cos_sq']
have h2 : cos x * (2 * sin x * cos x) = 2 * sin x * cos x ^ 2 := by ring
rw [h2, cos_sq']
ring
#align complex.sin_three_mul Complex.sin_three_mul
theorem exp_mul_I : exp (x * I) = cos x + sin x * I :=
(cos_add_sin_I _).symm
set_option linter.uppercaseLean3 false in
#align complex.exp_mul_I Complex.exp_mul_I
theorem exp_add_mul_I : exp (x + y * I) = exp x * (cos y + sin y * I) := by rw [exp_add, exp_mul_I]
set_option linter.uppercaseLean3 false in
#align complex.exp_add_mul_I Complex.exp_add_mul_I
theorem exp_eq_exp_re_mul_sin_add_cos : exp x = exp x.re * (cos x.im + sin x.im * I) := by
rw [← exp_add_mul_I, re_add_im]
#align complex.exp_eq_exp_re_mul_sin_add_cos Complex.exp_eq_exp_re_mul_sin_add_cos
theorem exp_re : (exp x).re = Real.exp x.re * Real.cos x.im := by
rw [exp_eq_exp_re_mul_sin_add_cos]
simp [exp_ofReal_re, cos_ofReal_re]
#align complex.exp_re Complex.exp_re
theorem exp_im : (exp x).im = Real.exp x.re * Real.sin x.im := by
rw [exp_eq_exp_re_mul_sin_add_cos]
simp [exp_ofReal_re, sin_ofReal_re]
#align complex.exp_im Complex.exp_im
@[simp]
theorem exp_ofReal_mul_I_re (x : ℝ) : (exp (x * I)).re = Real.cos x := by
simp [exp_mul_I, cos_ofReal_re]
set_option linter.uppercaseLean3 false in
#align complex.exp_of_real_mul_I_re Complex.exp_ofReal_mul_I_re
@[simp]
theorem exp_ofReal_mul_I_im (x : ℝ) : (exp (x * I)).im = Real.sin x := by
simp [exp_mul_I, sin_ofReal_re]
set_option linter.uppercaseLean3 false in
#align complex.exp_of_real_mul_I_im Complex.exp_ofReal_mul_I_im
/-- **De Moivre's formula** -/
theorem cos_add_sin_mul_I_pow (n : ℕ) (z : ℂ) :
(cos z + sin z * I) ^ n = cos (↑n * z) + sin (↑n * z) * I := by
rw [← exp_mul_I, ← exp_mul_I]
induction' n with n ih
· rw [pow_zero, Nat.cast_zero, zero_mul, zero_mul, exp_zero]
· rw [pow_succ, ih, Nat.cast_succ, add_mul, add_mul, one_mul, exp_add]
set_option linter.uppercaseLean3 false in
#align complex.cos_add_sin_mul_I_pow Complex.cos_add_sin_mul_I_pow
end Complex
namespace Real
open Complex
variable (x y : ℝ)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
#align real.exp_zero Real.exp_zero
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
#align real.exp_add Real.exp_add
-- Porting note (#11445): new definition
/-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ :=
{ toFun := fun x => exp (Multiplicative.toAdd x),
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℝ) expMonoidHom l
#align real.exp_list_sum Real.exp_list_sum
theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s
#align real.exp_multiset_sum Real.exp_multiset_sum
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℝ) expMonoidHom f s
#align real.exp_sum Real.exp_sum
lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
#align real.exp_nat_mul Real.exp_nat_mul
nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h =>
exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all
#align real.exp_ne_zero Real.exp_ne_zero
nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ :=
ofReal_injective <| by simp [exp_neg]
#align real.exp_neg Real.exp_neg
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
#align real.exp_sub Real.exp_sub
@[simp]
theorem sin_zero : sin 0 = 0 := by simp [sin]
#align real.sin_zero Real.sin_zero
@[simp]
theorem sin_neg : sin (-x) = -sin x := by simp [sin, exp_neg, (neg_div _ _).symm, add_mul]
#align real.sin_neg Real.sin_neg
nonrec theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y :=
ofReal_injective <| by simp [sin_add]
#align real.sin_add Real.sin_add
@[simp]
theorem cos_zero : cos 0 = 1 := by simp [cos]
#align real.cos_zero Real.cos_zero
@[simp]
theorem cos_neg : cos (-x) = cos x := by simp [cos, exp_neg]
#align real.cos_neg Real.cos_neg
@[simp]
theorem cos_abs : cos |x| = cos x := by
cases le_total x 0 <;> simp only [*, _root_.abs_of_nonneg, abs_of_nonpos, cos_neg]
#align real.cos_abs Real.cos_abs
nonrec theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y :=
ofReal_injective <| by simp [cos_add]
#align real.cos_add Real.cos_add
theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by
simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg]
#align real.sin_sub Real.sin_sub
theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by
simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg]
#align real.cos_sub Real.cos_sub
nonrec theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) :=
ofReal_injective <| by simp [sin_sub_sin]
#align real.sin_sub_sin Real.sin_sub_sin
nonrec theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) :=
ofReal_injective <| by simp [cos_sub_cos]
#align real.cos_sub_cos Real.cos_sub_cos
nonrec theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) :=
ofReal_injective <| by simp [cos_add_cos]
#align real.cos_add_cos Real.cos_add_cos
nonrec theorem tan_eq_sin_div_cos : tan x = sin x / cos x :=
ofReal_injective <| by simp [tan_eq_sin_div_cos]
#align real.tan_eq_sin_div_cos Real.tan_eq_sin_div_cos
theorem tan_mul_cos {x : ℝ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by
rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx]
#align real.tan_mul_cos Real.tan_mul_cos
@[simp]
theorem tan_zero : tan 0 = 0 := by simp [tan]
#align real.tan_zero Real.tan_zero
@[simp]
theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div]
#align real.tan_neg Real.tan_neg
@[simp]
nonrec theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 :=
ofReal_injective (by simp [sin_sq_add_cos_sq])
#align real.sin_sq_add_cos_sq Real.sin_sq_add_cos_sq
@[simp]
theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq]
#align real.cos_sq_add_sin_sq Real.cos_sq_add_sin_sq
theorem sin_sq_le_one : sin x ^ 2 ≤ 1 := by
rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_right (sq_nonneg _)
#align real.sin_sq_le_one Real.sin_sq_le_one
theorem cos_sq_le_one : cos x ^ 2 ≤ 1 := by
rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_left (sq_nonneg _)
#align real.cos_sq_le_one Real.cos_sq_le_one
theorem abs_sin_le_one : |sin x| ≤ 1 :=
abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, sin_sq_le_one]
#align real.abs_sin_le_one Real.abs_sin_le_one
theorem abs_cos_le_one : |cos x| ≤ 1 :=
abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, cos_sq_le_one]
#align real.abs_cos_le_one Real.abs_cos_le_one
theorem sin_le_one : sin x ≤ 1 :=
(abs_le.1 (abs_sin_le_one _)).2
#align real.sin_le_one Real.sin_le_one
theorem cos_le_one : cos x ≤ 1 :=
(abs_le.1 (abs_cos_le_one _)).2
#align real.cos_le_one Real.cos_le_one
theorem neg_one_le_sin : -1 ≤ sin x :=
(abs_le.1 (abs_sin_le_one _)).1
#align real.neg_one_le_sin Real.neg_one_le_sin
theorem neg_one_le_cos : -1 ≤ cos x :=
(abs_le.1 (abs_cos_le_one _)).1
#align real.neg_one_le_cos Real.neg_one_le_cos
nonrec theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 :=
ofReal_injective <| by simp [cos_two_mul]
#align real.cos_two_mul Real.cos_two_mul
nonrec theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 :=
ofReal_injective <| by simp [cos_two_mul']
#align real.cos_two_mul' Real.cos_two_mul'
nonrec theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x :=
ofReal_injective <| by simp [sin_two_mul]
#align real.sin_two_mul Real.sin_two_mul
nonrec theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 :=
ofReal_injective <| by simp [cos_sq]
#align real.cos_sq Real.cos_sq
theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left]
#align real.cos_sq' Real.cos_sq'
theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 :=
eq_sub_iff_add_eq.2 <| sin_sq_add_cos_sq _
#align real.sin_sq Real.sin_sq
lemma sin_sq_eq_half_sub : sin x ^ 2 = 1 / 2 - cos (2 * x) / 2 := by
rw [sin_sq, cos_sq, ← sub_sub, sub_half]
theorem abs_sin_eq_sqrt_one_sub_cos_sq (x : ℝ) : |sin x| = √(1 - cos x ^ 2) := by
rw [← sin_sq, sqrt_sq_eq_abs]
#align real.abs_sin_eq_sqrt_one_sub_cos_sq Real.abs_sin_eq_sqrt_one_sub_cos_sq
theorem abs_cos_eq_sqrt_one_sub_sin_sq (x : ℝ) : |cos x| = √(1 - sin x ^ 2) := by
rw [← cos_sq', sqrt_sq_eq_abs]
#align real.abs_cos_eq_sqrt_one_sub_sin_sq Real.abs_cos_eq_sqrt_one_sub_sin_sq
theorem inv_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 :=
have : Complex.cos x ≠ 0 := mt (congr_arg re) hx
ofReal_inj.1 <| by simpa using Complex.inv_one_add_tan_sq this
#align real.inv_one_add_tan_sq Real.inv_one_add_tan_sq
theorem tan_sq_div_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) :
tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by
simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul]
#align real.tan_sq_div_one_add_tan_sq Real.tan_sq_div_one_add_tan_sq
theorem inv_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) : (√(1 + tan x ^ 2))⁻¹ = cos x := by
rw [← sqrt_sq hx.le, ← sqrt_inv, inv_one_add_tan_sq hx.ne']
#align real.inv_sqrt_one_add_tan_sq Real.inv_sqrt_one_add_tan_sq
theorem tan_div_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) :
tan x / √(1 + tan x ^ 2) = sin x := by
rw [← tan_mul_cos hx.ne', ← inv_sqrt_one_add_tan_sq hx, div_eq_mul_inv]
#align real.tan_div_sqrt_one_add_tan_sq Real.tan_div_sqrt_one_add_tan_sq
nonrec theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by
rw [← ofReal_inj]; simp [cos_three_mul]
#align real.cos_three_mul Real.cos_three_mul
nonrec theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by
rw [← ofReal_inj]; simp [sin_three_mul]
#align real.sin_three_mul Real.sin_three_mul
/-- The definition of `sinh` in terms of `exp`. -/
nonrec theorem sinh_eq (x : ℝ) : sinh x = (exp x - exp (-x)) / 2 :=
ofReal_injective <| by simp [Complex.sinh]
#align real.sinh_eq Real.sinh_eq
@[simp]
theorem sinh_zero : sinh 0 = 0 := by simp [sinh]
#align real.sinh_zero Real.sinh_zero
@[simp]
theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul]
#align real.sinh_neg Real.sinh_neg
nonrec theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by
rw [← ofReal_inj]; simp [sinh_add]
#align real.sinh_add Real.sinh_add
/-- The definition of `cosh` in terms of `exp`. -/
theorem cosh_eq (x : ℝ) : cosh x = (exp x + exp (-x)) / 2 :=
eq_div_of_mul_eq two_ne_zero <| by
rw [cosh, exp, exp, Complex.ofReal_neg, Complex.cosh, mul_two, ← Complex.add_re, ← mul_two,
div_mul_cancel₀ _ (two_ne_zero' ℂ), Complex.add_re]
#align real.cosh_eq Real.cosh_eq
@[simp]
theorem cosh_zero : cosh 0 = 1 := by simp [cosh]
#align real.cosh_zero Real.cosh_zero
@[simp]
theorem cosh_neg : cosh (-x) = cosh x :=
ofReal_inj.1 <| by simp
#align real.cosh_neg Real.cosh_neg
@[simp]
theorem cosh_abs : cosh |x| = cosh x := by
cases le_total x 0 <;> simp [*, _root_.abs_of_nonneg, abs_of_nonpos]
#align real.cosh_abs Real.cosh_abs
nonrec theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by
rw [← ofReal_inj]; simp [cosh_add]
#align real.cosh_add Real.cosh_add
theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by
simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg]
#align real.sinh_sub Real.sinh_sub
theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by
simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg]
#align real.cosh_sub Real.cosh_sub
nonrec theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x :=
ofReal_inj.1 <| by simp [tanh_eq_sinh_div_cosh]
#align real.tanh_eq_sinh_div_cosh Real.tanh_eq_sinh_div_cosh
@[simp]
theorem tanh_zero : tanh 0 = 0 := by simp [tanh]
#align real.tanh_zero Real.tanh_zero
@[simp]
theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div]
#align real.tanh_neg Real.tanh_neg
@[simp]
theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← ofReal_inj]; simp
#align real.cosh_add_sinh Real.cosh_add_sinh
@[simp]
theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh]
#align real.sinh_add_cosh Real.sinh_add_cosh
@[simp]
theorem exp_sub_cosh : exp x - cosh x = sinh x :=
sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm
#align real.exp_sub_cosh Real.exp_sub_cosh
@[simp]
theorem exp_sub_sinh : exp x - sinh x = cosh x :=
sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm
#align real.exp_sub_sinh Real.exp_sub_sinh
@[simp]
theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by
rw [← ofReal_inj]
simp
#align real.cosh_sub_sinh Real.cosh_sub_sinh
@[simp]
theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh]
#align real.sinh_sub_cosh Real.sinh_sub_cosh
@[simp]
theorem cosh_sq_sub_sinh_sq (x : ℝ) : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [← ofReal_inj]; simp
#align real.cosh_sq_sub_sinh_sq Real.cosh_sq_sub_sinh_sq
nonrec theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← ofReal_inj]; simp [cosh_sq]
#align real.cosh_sq Real.cosh_sq
theorem cosh_sq' : cosh x ^ 2 = 1 + sinh x ^ 2 :=
(cosh_sq x).trans (add_comm _ _)
#align real.cosh_sq' Real.cosh_sq'
nonrec theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← ofReal_inj]; simp [sinh_sq]
#align real.sinh_sq Real.sinh_sq
nonrec theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by
rw [← ofReal_inj]; simp [cosh_two_mul]
#align real.cosh_two_mul Real.cosh_two_mul
nonrec theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by
rw [← ofReal_inj]; simp [sinh_two_mul]
#align real.sinh_two_mul Real.sinh_two_mul
nonrec theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by
rw [← ofReal_inj]; simp [cosh_three_mul]
#align real.cosh_three_mul Real.cosh_three_mul
nonrec theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by
rw [← ofReal_inj]; simp [sinh_three_mul]
#align real.sinh_three_mul Real.sinh_three_mul
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x :=
calc
∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by
refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re]
#align real.sum_le_exp_of_nonneg Real.sum_le_exp_of_nonneg
lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x :=
calc
x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n)
_ ≤ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x :=
calc
1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ ≤ exp x := sum_le_exp_of_nonneg hx 3
#align real.quadratic_le_exp_of_nonneg Real.quadratic_le_exp_of_nonneg
private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx]
#align real.one_le_exp Real.one_le_exp
theorem exp_pos (x : ℝ) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by
rw [← neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
#align real.exp_pos Real.exp_pos
lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : ℝ) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
#align real.abs_exp Real.abs_exp
lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, _root_.abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [← sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
#align real.exp_strict_mono Real.exp_strictMono
@[gcongr]
theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
#align real.exp_monotone Real.exp_monotone
@[gcongr]
theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y :=
exp_strictMono.lt_iff_lt
#align real.exp_lt_exp Real.exp_lt_exp
@[simp]
theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y :=
exp_strictMono.le_iff_le
#align real.exp_le_exp Real.exp_le_exp
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
#align real.exp_injective Real.exp_injective
@[simp]
theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y :=
exp_injective.eq_iff
#align real.exp_eq_exp Real.exp_eq_exp
@[simp]
theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 :=
exp_injective.eq_iff' exp_zero
#align real.exp_eq_one_iff Real.exp_eq_one_iff
@[simp]
theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp]
#align real.one_lt_exp_iff Real.one_lt_exp_iff
@[simp]
theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp]
#align real.exp_lt_one_iff Real.exp_lt_one_iff
@[simp]
theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 :=
exp_zero ▸ exp_le_exp
#align real.exp_le_one_iff Real.exp_le_one_iff
@[simp]
theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x :=
exp_zero ▸ exp_le_exp
#align real.one_le_exp_iff Real.one_le_exp_iff
/-- `Real.cosh` is always positive -/
theorem cosh_pos (x : ℝ) : 0 < Real.cosh x :=
(cosh_eq x).symm ▸ half_pos (add_pos (exp_pos x) (exp_pos (-x)))
#align real.cosh_pos Real.cosh_pos
theorem sinh_lt_cosh : sinh x < cosh x :=
lt_of_pow_lt_pow_left 2 (cosh_pos _).le <| (cosh_sq x).symm ▸ lt_add_one _
#align real.sinh_lt_cosh Real.sinh_lt_cosh
end Real
namespace Complex
theorem sum_div_factorial_le {α : Type*} [LinearOrderedField α] (n j : ℕ) (hn : 0 < n) :
(∑ m ∈ filter (fun k => n ≤ k) (range j),
(1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) :=
calc
(∑ m ∈ filter (fun k => n ≤ k) (range j), (1 / m.factorial : α)) =
∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by
refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;>
simp (config := { contextual := true }) [lt_tsub_iff_right, tsub_add_cancel_of_le]
_ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by
simp_rw [one_div]
gcongr
rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm]
exact Nat.factorial_mul_pow_le_factorial
_ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by
simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow]
_ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by
have h₁ : (n.succ : α) ≠ 1 :=
@Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn))
have h₂ : (n.succ : α) ≠ 0 := by positivity
have h₃ : (n.factorial * n : α) ≠ 0 := by positivity
have h₄ : (n.succ - 1 : α) = n := by simp
rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α),
← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α),
mul_comm (n : α) n.factorial, mul_inv_cancel h₃, one_mul, mul_comm]
_ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity
#align complex.sum_div_factorial_le Complex.sum_div_factorial_le
theorem exp_bound {x : ℂ} (hx : abs x ≤ 1) {n : ℕ} (hn : 0 < n) :
abs (exp x - ∑ m ∈ range n, x ^ m / m.factorial) ≤
abs x ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by
rw [← lim_const (abv := Complex.abs) (∑ m ∈ range n, _), exp, sub_eq_add_neg,
← lim_neg, lim_add, ← lim_abs]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show
abs ((∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial) ≤
abs x ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹)
rw [sum_range_sub_sum_range hj]
calc
abs (∑ m ∈ (range j).filter fun k => n ≤ k, (x ^ m / m.factorial : ℂ)) =
abs (∑ m ∈ (range j).filter fun k => n ≤ k,
(x ^ n * (x ^ (m - n) / m.factorial) : ℂ)) := by
refine congr_arg abs (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ filter (fun k => n ≤ k) (range j), abs (x ^ n * (x ^ (m - n) / m.factorial)) :=
(IsAbsoluteValue.abv_sum Complex.abs _ _)
_ ≤ ∑ m ∈ filter (fun k => n ≤ k) (range j), abs x ^ n * (1 / m.factorial) := by
simp_rw [map_mul, map_pow, map_div₀, abs_natCast]
gcongr
rw [abv_pow abs]
exact pow_le_one _ (abs.nonneg _) hx
_ = abs x ^ n * ∑ m ∈ (range j).filter fun k => n ≤ k, (1 / m.factorial : ℝ) := by
simp [abs_mul, abv_pow abs, abs_div, ← mul_sum]
_ ≤ abs x ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by
gcongr
exact sum_div_factorial_le _ _ hn
#align complex.exp_bound Complex.exp_bound
theorem exp_bound' {x : ℂ} {n : ℕ} (hx : abs x / n.succ ≤ 1 / 2) :
abs (exp x - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n / n.factorial * 2 := by
rw [← lim_const (abv := Complex.abs) (∑ m ∈ range n, _),
exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_abs]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show abs ((∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial) ≤
abs x ^ n / n.factorial * 2
let k := j - n
have hj : j = n + k := (add_tsub_cancel_of_le hj).symm
rw [hj, sum_range_add_sub_sum_range]
calc
abs (∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)) ≤
∑ i ∈ range k, abs (x ^ (n + i) / ((n + i).factorial : ℂ)) :=
IsAbsoluteValue.abv_sum _ _ _
_ ≤ ∑ i ∈ range k, abs x ^ (n + i) / (n + i).factorial := by
simp [Complex.abs_natCast, map_div₀, abv_pow abs]
_ ≤ ∑ i ∈ range k, abs x ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_
_ = ∑ i ∈ range k, abs x ^ n / n.factorial * (abs x ^ i / (n.succ : ℝ) ^ i) := ?_
_ ≤ abs x ^ n / ↑n.factorial * 2 := ?_
· gcongr
exact mod_cast Nat.factorial_mul_pow_le_factorial
· refine Finset.sum_congr rfl fun _ _ => ?_
simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc]
· rw [← mul_sum]
gcongr
simp_rw [← div_pow]
rw [geom_sum_eq, div_le_iff_of_neg]
· trans (-1 : ℝ)
· linarith
· simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left]
positivity
· linarith
· linarith
#align complex.exp_bound' Complex.exp_bound'
theorem abs_exp_sub_one_le {x : ℂ} (hx : abs x ≤ 1) : abs (exp x - 1) ≤ 2 * abs x :=
calc
abs (exp x - 1) = abs (exp x - ∑ m ∈ range 1, x ^ m / m.factorial) := by simp [sum_range_succ]
_ ≤ abs x ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ = 2 * abs x := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial]
#align complex.abs_exp_sub_one_le Complex.abs_exp_sub_one_le
theorem abs_exp_sub_one_sub_id_le {x : ℂ} (hx : abs x ≤ 1) : abs (exp x - 1 - x) ≤ abs x ^ 2 :=
calc
abs (exp x - 1 - x) = abs (exp x - ∑ m ∈ range 2, x ^ m / m.factorial) := by
simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial]
_ ≤ abs x ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ ≤ abs x ^ 2 * 1 := by gcongr; norm_num [Nat.factorial]
_ = abs x ^ 2 := by rw [mul_one]
#align complex.abs_exp_sub_one_sub_id_le Complex.abs_exp_sub_one_sub_id_le
end Complex
namespace Real
open Complex Finset
nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) :
|exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by
have hxc : Complex.abs x ≤ 1 := mod_cast hx
convert exp_bound hxc hn using 2 <;>
-- Porting note: was `norm_cast`
simp only [← abs_ofReal, ← ofReal_sub, ← ofReal_exp, ← ofReal_sum, ← ofReal_pow,
← ofReal_div, ← ofReal_natCast]
#align real.exp_bound Real.exp_bound
theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) :
Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) +
x ^ n * (n + 1) / (n.factorial * n) := by
have h3 : |x| = x := by simpa
have h4 : |x| ≤ 1 := by rwa [h3]
have h' := Real.exp_bound h4 hn
rw [h3] at h'
have h'' := (abs_sub_le_iff.1 h').1
have t := sub_le_iff_le_add'.1 h''
simpa [mul_div_assoc] using t
#align real.exp_bound' Real.exp_bound'
theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by
have : |x| ≤ 1 := mod_cast hx
-- Porting note: was
--exact_mod_cast Complex.abs_exp_sub_one_le (x := x) this
have := Complex.abs_exp_sub_one_le (x := x) (by simpa using this)
rw [← ofReal_exp, ← ofReal_one, ← ofReal_sub, abs_ofReal, abs_ofReal] at this
exact this
#align real.abs_exp_sub_one_le Real.abs_exp_sub_one_le
theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by
rw [← _root_.sq_abs]
-- Porting note: was
-- exact_mod_cast Complex.abs_exp_sub_one_sub_id_le this
have : Complex.abs x ≤ 1 := mod_cast hx
have := Complex.abs_exp_sub_one_sub_id_le this
rw [← ofReal_one, ← ofReal_exp, ← ofReal_sub, ← ofReal_sub, abs_ofReal, abs_ofReal] at this
exact this
#align real.abs_exp_sub_one_sub_id_le Real.abs_exp_sub_one_sub_id_le
/-- A finite initial segment of the exponential series, followed by an arbitrary tail.
For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function
of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`,
for any `r`. -/
noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ :=
(∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r
#align real.exp_near Real.expNear
@[simp]
theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear]
#align real.exp_near_zero Real.expNear_zero
@[simp]
theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by
simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv,
mul_inv, Nat.factorial]
ac_rfl
#align real.exp_near_succ Real.expNear_succ
theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ -
expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by
simp [expNear, mul_sub]
#align real.exp_near_sub Real.expNear_sub
theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) :
|exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by
simp only [expNear, mul_zero, add_zero]
convert exp_bound (n := m) h ?_ using 1
· field_simp [mul_comm]
· omega
#align real.exp_approx_end Real.exp_approx_end
theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ)
(e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂)
(h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) :
|exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by
refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_)
subst e₁; rw [expNear_succ, expNear_sub, abs_mul]
convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n))
(le_sub_iff_add_le'.1 e) ?_ using 1
· simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial]
ac_rfl
· simp [div_nonneg, abs_nonneg]
#align real.exp_approx_succ Real.exp_approx_succ
theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm)
(h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) :
|exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by
subst er
exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h)
#align real.exp_approx_end' Real.exp_approx_end'
theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm)
(h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) :
|exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by
subst er
refine exp_approx_succ _ en _ _ ?_ h
field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega]
#align real.exp_1_approx_succ_eq Real.exp_1_approx_succ_eq
theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) :
|exp x - a| ≤ b := by simpa using h
#align real.exp_approx_start Real.exp_approx_start
| Mathlib/Data/Complex/Exponential.lean | 1,508 | 1,537 | theorem cos_bound {x : ℝ} (hx : |x| ≤ 1) : |cos x - (1 - x ^ 2 / 2)| ≤ |x| ^ 4 * (5 / 96) :=
calc
|cos x - (1 - x ^ 2 / 2)| = Complex.abs (Complex.cos x - (1 - (x : ℂ) ^ 2 / 2)) := by |
rw [← abs_ofReal]; simp
_ = Complex.abs ((Complex.exp (x * I) + Complex.exp (-x * I) - (2 - (x : ℂ) ^ 2)) / 2) := by
simp [Complex.cos, sub_div, add_div, neg_div, div_self (two_ne_zero' ℂ)]
_ = abs
(((Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) +
(Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial)) / 2) :=
(congr_arg Complex.abs
(congr_arg (fun x : ℂ => x / 2)
(by
simp only [sum_range_succ, neg_mul, pow_succ, pow_zero, mul_one, range_zero, sum_empty,
Nat.factorial, Nat.cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self,
zero_add, div_one, Nat.mul_one, Nat.cast_succ, Nat.cast_mul, Nat.cast_ofNat, mul_neg,
neg_neg]
apply Complex.ext <;> simp [div_eq_mul_inv, normSq] <;> ring_nf
)))
_ ≤ abs ((Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) / 2) +
abs ((Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) / 2) := by
rw [add_div]; exact Complex.abs.add_le _ _
_ = abs (Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) / 2 +
abs (Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) / 2 := by
simp [map_div₀]
_ ≤ Complex.abs (x * I) ^ 4 * (Nat.succ 4 * ((Nat.factorial 4) * (4 : ℕ) : ℝ)⁻¹) / 2 +
Complex.abs (-x * I) ^ 4 * (Nat.succ 4 * ((Nat.factorial 4) * (4 : ℕ) : ℝ)⁻¹) / 2 := by
gcongr
· exact Complex.exp_bound (by simpa) (by decide)
· exact Complex.exp_bound (by simpa) (by decide)
_ ≤ |x| ^ 4 * (5 / 96) := by norm_num [Nat.factorial]
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.BumpFunction.FiniteDimension
import Mathlib.Geometry.Manifold.ContMDiff.Atlas
import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace
#align_import geometry.manifold.bump_function from "leanprover-community/mathlib"@"b018406ad2f2a73223a3a9e198ccae61e6f05318"
/-!
# Smooth bump functions on a smooth manifold
In this file we define `SmoothBumpFunction I c` to be a bundled smooth "bump" function centered at
`c`. It is a structure that consists of two real numbers `0 < rIn < rOut` with small enough `rOut`.
We define a coercion to function for this type, and for `f : SmoothBumpFunction I c`, the function
`⇑f` written in the extended chart at `c` has the following properties:
* `f x = 1` in the closed ball of radius `f.rIn` centered at `c`;
* `f x = 0` outside of the ball of radius `f.rOut` centered at `c`;
* `0 ≤ f x ≤ 1` for all `x`.
The actual statements involve (pre)images under `extChartAt I f` and are given as lemmas in the
`SmoothBumpFunction` namespace.
## Tags
manifold, smooth bump function
-/
universe uE uF uH uM
variable {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E]
{H : Type uH} [TopologicalSpace H] (I : ModelWithCorners ℝ E H) {M : Type uM} [TopologicalSpace M]
[ChartedSpace H M] [SmoothManifoldWithCorners I M]
open Function Filter FiniteDimensional Set Metric
open scoped Topology Manifold Classical Filter
noncomputable section
/-!
### Smooth bump function
In this section we define a structure for a bundled smooth bump function and prove its properties.
-/
/-- Given a smooth manifold modelled on a finite dimensional space `E`,
`f : SmoothBumpFunction I M` is a smooth function on `M` such that in the extended chart `e` at
`f.c`:
* `f x = 1` in the closed ball of radius `f.rIn` centered at `f.c`;
* `f x = 0` outside of the ball of radius `f.rOut` centered at `f.c`;
* `0 ≤ f x ≤ 1` for all `x`.
The structure contains data required to construct a function with these properties. The function is
available as `⇑f` or `f x`. Formal statements of the properties listed above involve some
(pre)images under `extChartAt I f.c` and are given as lemmas in the `SmoothBumpFunction`
namespace. -/
structure SmoothBumpFunction (c : M) extends ContDiffBump (extChartAt I c c) where
closedBall_subset : closedBall (extChartAt I c c) rOut ∩ range I ⊆ (extChartAt I c).target
#align smooth_bump_function SmoothBumpFunction
namespace SmoothBumpFunction
variable {c : M} (f : SmoothBumpFunction I c) {x : M} {I}
/-- The function defined by `f : SmoothBumpFunction c`. Use automatic coercion to function
instead. -/
@[coe] def toFun : M → ℝ :=
indicator (chartAt H c).source (f.toContDiffBump ∘ extChartAt I c)
#align smooth_bump_function.to_fun SmoothBumpFunction.toFun
instance : CoeFun (SmoothBumpFunction I c) fun _ => M → ℝ :=
⟨toFun⟩
theorem coe_def : ⇑f = indicator (chartAt H c).source (f.toContDiffBump ∘ extChartAt I c) :=
rfl
#align smooth_bump_function.coe_def SmoothBumpFunction.coe_def
theorem rOut_pos : 0 < f.rOut :=
f.toContDiffBump.rOut_pos
set_option linter.uppercaseLean3 false in
#align smooth_bump_function.R_pos SmoothBumpFunction.rOut_pos
theorem ball_subset : ball (extChartAt I c c) f.rOut ∩ range I ⊆ (extChartAt I c).target :=
Subset.trans (inter_subset_inter_left _ ball_subset_closedBall) f.closedBall_subset
#align smooth_bump_function.ball_subset SmoothBumpFunction.ball_subset
theorem ball_inter_range_eq_ball_inter_target :
ball (extChartAt I c c) f.rOut ∩ range I =
ball (extChartAt I c c) f.rOut ∩ (extChartAt I c).target :=
(subset_inter inter_subset_left f.ball_subset).antisymm <| inter_subset_inter_right _ <|
extChartAt_target_subset_range _ _
theorem eqOn_source : EqOn f (f.toContDiffBump ∘ extChartAt I c) (chartAt H c).source :=
eqOn_indicator
#align smooth_bump_function.eq_on_source SmoothBumpFunction.eqOn_source
theorem eventuallyEq_of_mem_source (hx : x ∈ (chartAt H c).source) :
f =ᶠ[𝓝 x] f.toContDiffBump ∘ extChartAt I c :=
f.eqOn_source.eventuallyEq_of_mem <| (chartAt H c).open_source.mem_nhds hx
#align smooth_bump_function.eventually_eq_of_mem_source SmoothBumpFunction.eventuallyEq_of_mem_source
theorem one_of_dist_le (hs : x ∈ (chartAt H c).source)
(hd : dist (extChartAt I c x) (extChartAt I c c) ≤ f.rIn) : f x = 1 := by
simp only [f.eqOn_source hs, (· ∘ ·), f.one_of_mem_closedBall hd]
#align smooth_bump_function.one_of_dist_le SmoothBumpFunction.one_of_dist_le
theorem support_eq_inter_preimage :
support f = (chartAt H c).source ∩ extChartAt I c ⁻¹' ball (extChartAt I c c) f.rOut := by
rw [coe_def, support_indicator, support_comp_eq_preimage, ← extChartAt_source I,
← (extChartAt I c).symm_image_target_inter_eq', ← (extChartAt I c).symm_image_target_inter_eq',
f.support_eq]
#align smooth_bump_function.support_eq_inter_preimage SmoothBumpFunction.support_eq_inter_preimage
theorem isOpen_support : IsOpen (support f) := by
rw [support_eq_inter_preimage]
exact isOpen_extChartAt_preimage I c isOpen_ball
#align smooth_bump_function.is_open_support SmoothBumpFunction.isOpen_support
theorem support_eq_symm_image :
support f = (extChartAt I c).symm '' (ball (extChartAt I c c) f.rOut ∩ range I) := by
rw [f.support_eq_inter_preimage, ← extChartAt_source I,
← (extChartAt I c).symm_image_target_inter_eq', inter_comm,
ball_inter_range_eq_ball_inter_target]
#align smooth_bump_function.support_eq_symm_image SmoothBumpFunction.support_eq_symm_image
theorem support_subset_source : support f ⊆ (chartAt H c).source := by
rw [f.support_eq_inter_preimage, ← extChartAt_source I]; exact inter_subset_left
#align smooth_bump_function.support_subset_source SmoothBumpFunction.support_subset_source
theorem image_eq_inter_preimage_of_subset_support {s : Set M} (hs : s ⊆ support f) :
extChartAt I c '' s =
closedBall (extChartAt I c c) f.rOut ∩ range I ∩ (extChartAt I c).symm ⁻¹' s := by
rw [support_eq_inter_preimage, subset_inter_iff, ← extChartAt_source I, ← image_subset_iff] at hs
cases' hs with hse hsf
apply Subset.antisymm
· refine subset_inter (subset_inter (hsf.trans ball_subset_closedBall) ?_) ?_
· rintro _ ⟨x, -, rfl⟩; exact mem_range_self _
· rw [(extChartAt I c).image_eq_target_inter_inv_preimage hse]
exact inter_subset_right
· refine Subset.trans (inter_subset_inter_left _ f.closedBall_subset) ?_
rw [(extChartAt I c).image_eq_target_inter_inv_preimage hse]
#align smooth_bump_function.image_eq_inter_preimage_of_subset_support SmoothBumpFunction.image_eq_inter_preimage_of_subset_support
theorem mem_Icc : f x ∈ Icc (0 : ℝ) 1 := by
have : f x = 0 ∨ f x = _ := indicator_eq_zero_or_self _ _ _
cases' this with h h <;> rw [h]
exacts [left_mem_Icc.2 zero_le_one, ⟨f.nonneg, f.le_one⟩]
#align smooth_bump_function.mem_Icc SmoothBumpFunction.mem_Icc
theorem nonneg : 0 ≤ f x :=
f.mem_Icc.1
#align smooth_bump_function.nonneg SmoothBumpFunction.nonneg
theorem le_one : f x ≤ 1 :=
f.mem_Icc.2
#align smooth_bump_function.le_one SmoothBumpFunction.le_one
theorem eventuallyEq_one_of_dist_lt (hs : x ∈ (chartAt H c).source)
(hd : dist (extChartAt I c x) (extChartAt I c c) < f.rIn) : f =ᶠ[𝓝 x] 1 := by
filter_upwards [IsOpen.mem_nhds (isOpen_extChartAt_preimage I c isOpen_ball) ⟨hs, hd⟩]
rintro z ⟨hzs, hzd⟩
exact f.one_of_dist_le hzs <| le_of_lt hzd
#align smooth_bump_function.eventually_eq_one_of_dist_lt SmoothBumpFunction.eventuallyEq_one_of_dist_lt
theorem eventuallyEq_one : f =ᶠ[𝓝 c] 1 :=
f.eventuallyEq_one_of_dist_lt (mem_chart_source _ _) <| by rw [dist_self]; exact f.rIn_pos
#align smooth_bump_function.eventually_eq_one SmoothBumpFunction.eventuallyEq_one
@[simp]
theorem eq_one : f c = 1 :=
f.eventuallyEq_one.eq_of_nhds
#align smooth_bump_function.eq_one SmoothBumpFunction.eq_one
theorem support_mem_nhds : support f ∈ 𝓝 c :=
f.eventuallyEq_one.mono fun x hx => by rw [hx]; exact one_ne_zero
#align smooth_bump_function.support_mem_nhds SmoothBumpFunction.support_mem_nhds
theorem tsupport_mem_nhds : tsupport f ∈ 𝓝 c :=
mem_of_superset f.support_mem_nhds subset_closure
#align smooth_bump_function.tsupport_mem_nhds SmoothBumpFunction.tsupport_mem_nhds
theorem c_mem_support : c ∈ support f :=
mem_of_mem_nhds f.support_mem_nhds
#align smooth_bump_function.c_mem_support SmoothBumpFunction.c_mem_support
theorem nonempty_support : (support f).Nonempty :=
⟨c, f.c_mem_support⟩
#align smooth_bump_function.nonempty_support SmoothBumpFunction.nonempty_support
theorem isCompact_symm_image_closedBall :
IsCompact ((extChartAt I c).symm '' (closedBall (extChartAt I c c) f.rOut ∩ range I)) :=
((isCompact_closedBall _ _).inter_right I.isClosed_range).image_of_continuousOn <|
(continuousOn_extChartAt_symm _ _).mono f.closedBall_subset
#align smooth_bump_function.is_compact_symm_image_closed_ball SmoothBumpFunction.isCompact_symm_image_closedBall
/-- Given a smooth bump function `f : SmoothBumpFunction I c`, the closed ball of radius `f.R` is
known to include the support of `f`. These closed balls (in the model normed space `E`) intersected
with `Set.range I` form a basis of `𝓝[range I] (extChartAt I c c)`. -/
theorem nhdsWithin_range_basis :
(𝓝[range I] extChartAt I c c).HasBasis (fun _ : SmoothBumpFunction I c => True) fun f =>
closedBall (extChartAt I c c) f.rOut ∩ range I := by
refine ((nhdsWithin_hasBasis nhds_basis_closedBall _).restrict_subset
(extChartAt_target_mem_nhdsWithin _ _)).to_hasBasis' ?_ ?_
· rintro R ⟨hR0, hsub⟩
exact ⟨⟨⟨R / 2, R, half_pos hR0, half_lt_self hR0⟩, hsub⟩, trivial, Subset.rfl⟩
· exact fun f _ => inter_mem (mem_nhdsWithin_of_mem_nhds <| closedBall_mem_nhds _ f.rOut_pos)
self_mem_nhdsWithin
#align smooth_bump_function.nhds_within_range_basis SmoothBumpFunction.nhdsWithin_range_basis
theorem isClosed_image_of_isClosed {s : Set M} (hsc : IsClosed s) (hs : s ⊆ support f) :
IsClosed (extChartAt I c '' s) := by
rw [f.image_eq_inter_preimage_of_subset_support hs]
refine ContinuousOn.preimage_isClosed_of_isClosed
((continuousOn_extChartAt_symm _ _).mono f.closedBall_subset) ?_ hsc
exact IsClosed.inter isClosed_ball I.isClosed_range
#align smooth_bump_function.is_closed_image_of_is_closed SmoothBumpFunction.isClosed_image_of_isClosed
/-- If `f` is a smooth bump function and `s` closed subset of the support of `f` (i.e., of the open
ball of radius `f.rOut`), then there exists `0 < r < f.rOut` such that `s` is a subset of the open
ball of radius `r`. Formally, `s ⊆ e.source ∩ e ⁻¹' (ball (e c) r)`, where `e = extChartAt I c`. -/
theorem exists_r_pos_lt_subset_ball {s : Set M} (hsc : IsClosed s) (hs : s ⊆ support f) :
∃ r ∈ Ioo 0 f.rOut,
s ⊆ (chartAt H c).source ∩ extChartAt I c ⁻¹' ball (extChartAt I c c) r := by
set e := extChartAt I c
have : IsClosed (e '' s) := f.isClosed_image_of_isClosed hsc hs
rw [support_eq_inter_preimage, subset_inter_iff, ← image_subset_iff] at hs
rcases exists_pos_lt_subset_ball f.rOut_pos this hs.2 with ⟨r, hrR, hr⟩
exact ⟨r, hrR, subset_inter hs.1 (image_subset_iff.1 hr)⟩
#align smooth_bump_function.exists_r_pos_lt_subset_ball SmoothBumpFunction.exists_r_pos_lt_subset_ball
/-- Replace `rIn` with another value in the interval `(0, f.rOut)`. -/
@[simps rOut rIn]
def updateRIn (r : ℝ) (hr : r ∈ Ioo 0 f.rOut) : SmoothBumpFunction I c :=
⟨⟨r, f.rOut, hr.1, hr.2⟩, f.closedBall_subset⟩
#align smooth_bump_function.update_r SmoothBumpFunction.updateRIn
set_option linter.uppercaseLean3 false in
#align smooth_bump_function.update_r_R SmoothBumpFunction.updateRIn_rOut
#align smooth_bump_function.update_r_r SmoothBumpFunction.updateRIn_rIn
@[simp]
| Mathlib/Geometry/Manifold/BumpFunction.lean | 246 | 248 | theorem support_updateRIn {r : ℝ} (hr : r ∈ Ioo 0 f.rOut) :
support (f.updateRIn r hr) = support f := by |
simp only [support_eq_inter_preimage, updateRIn_rOut]
|
/-
Copyright (c) 2022 Antoine Labelle. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Labelle
-/
import Mathlib.RepresentationTheory.FdRep
import Mathlib.LinearAlgebra.Trace
import Mathlib.RepresentationTheory.Invariants
#align_import representation_theory.character from "leanprover-community/mathlib"@"55b3f8206b8596db8bb1804d8a92814a0b6670c9"
/-!
# Characters of representations
This file introduces characters of representation and proves basic lemmas about how characters
behave under various operations on representations.
A key result is the orthogonality of characters for irreducible representations of finite group
over an algebraically closed field whose characteristic doesn't divide the order of the group. It
is the theorem `char_orthonormal`
# Implementation notes
Irreducible representations are implemented categorically, using the `Simple` class defined in
`Mathlib.CategoryTheory.Simple`
# TODO
* Once we have the monoidal closed structure on `FdRep k G` and a better API for the rigid
structure, `char_dual` and `char_linHom` should probably be stated in terms of `Vᘁ` and `ihom V W`.
-/
noncomputable section
universe u
open CategoryTheory LinearMap CategoryTheory.MonoidalCategory Representation FiniteDimensional
variable {k : Type u} [Field k]
namespace FdRep
set_option linter.uppercaseLean3 false -- `FdRep`
section Monoid
variable {G : Type u} [Monoid G]
/-- The character of a representation `V : FdRep k G` is the function associating to `g : G` the
trace of the linear map `V.ρ g`. -/
def character (V : FdRep k G) (g : G) :=
LinearMap.trace k V (V.ρ g)
#align fdRep.character FdRep.character
| Mathlib/RepresentationTheory/Character.lean | 54 | 55 | theorem char_mul_comm (V : FdRep k G) (g : G) (h : G) :
V.character (h * g) = V.character (g * h) := by | simp only [trace_mul_comm, character, map_mul]
|
/-
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.Tactic.Monotonicity
import Mathlib.Topology.Compactness.Compact
import Mathlib.Topology.NhdsSet
import Mathlib.Algebra.Group.Defs
#align_import topology.uniform_space.basic from "leanprover-community/mathlib"@"195fcd60ff2bfe392543bceb0ec2adcdb472db4c"
/-!
# Uniform spaces
Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly
generalize to uniform spaces, e.g.
* uniform continuity (in this file)
* completeness (in `Cauchy.lean`)
* extension of uniform continuous functions to complete spaces (in `UniformEmbedding.lean`)
* totally bounded sets (in `Cauchy.lean`)
* totally bounded complete sets are compact (in `Cauchy.lean`)
A uniform structure on a type `X` is a filter `𝓤 X` on `X × X` satisfying some conditions
which makes it reasonable to say that `∀ᶠ (p : X × X) in 𝓤 X, ...` means
"for all p.1 and p.2 in X close enough, ...". Elements of this filter are called entourages
of `X`. The two main examples are:
* If `X` is a metric space, `V ∈ 𝓤 X ↔ ∃ ε > 0, { p | dist p.1 p.2 < ε } ⊆ V`
* If `G` is an additive topological group, `V ∈ 𝓤 G ↔ ∃ U ∈ 𝓝 (0 : G), {p | p.2 - p.1 ∈ U} ⊆ V`
Those examples are generalizations in two different directions of the elementary example where
`X = ℝ` and `V ∈ 𝓤 ℝ ↔ ∃ ε > 0, { p | |p.2 - p.1| < ε } ⊆ V` which features both the topological
group structure on `ℝ` and its metric space structure.
Each uniform structure on `X` induces a topology on `X` characterized by
> `nhds_eq_comap_uniformity : ∀ {x : X}, 𝓝 x = comap (Prod.mk x) (𝓤 X)`
where `Prod.mk x : X → X × X := (fun y ↦ (x, y))` is the partial evaluation of the product
constructor.
The dictionary with metric spaces includes:
* an upper bound for `dist x y` translates into `(x, y) ∈ V` for some `V ∈ 𝓤 X`
* a ball `ball x r` roughly corresponds to `UniformSpace.ball x V := {y | (x, y) ∈ V}`
for some `V ∈ 𝓤 X`, but the later is more general (it includes in
particular both open and closed balls for suitable `V`).
In particular we have:
`isOpen_iff_ball_subset {s : Set X} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 X, ball x V ⊆ s`
The triangle inequality is abstracted to a statement involving the composition of relations in `X`.
First note that the triangle inequality in a metric space is equivalent to
`∀ (x y z : X) (r r' : ℝ), dist x y ≤ r → dist y z ≤ r' → dist x z ≤ r + r'`.
Then, for any `V` and `W` with type `Set (X × X)`, the composition `V ○ W : Set (X × X)` is
defined as `{ p : X × X | ∃ z, (p.1, z) ∈ V ∧ (z, p.2) ∈ W }`.
In the metric space case, if `V = { p | dist p.1 p.2 ≤ r }` and `W = { p | dist p.1 p.2 ≤ r' }`
then the triangle inequality, as reformulated above, says `V ○ W` is contained in
`{p | dist p.1 p.2 ≤ r + r'}` which is the entourage associated to the radius `r + r'`.
In general we have `mem_ball_comp (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W)`.
Note that this discussion does not depend on any axiom imposed on the uniformity filter,
it is simply captured by the definition of composition.
The uniform space axioms ask the filter `𝓤 X` to satisfy the following:
* every `V ∈ 𝓤 X` contains the diagonal `idRel = { p | p.1 = p.2 }`. This abstracts the fact
that `dist x x ≤ r` for every non-negative radius `r` in the metric space case and also that
`x - x` belongs to every neighborhood of zero in the topological group case.
* `V ∈ 𝓤 X → Prod.swap '' V ∈ 𝓤 X`. This is tightly related the fact that `dist x y = dist y x`
in a metric space, and to continuity of negation in the topological group case.
* `∀ V ∈ 𝓤 X, ∃ W ∈ 𝓤 X, W ○ W ⊆ V`. In the metric space case, it corresponds
to cutting the radius of a ball in half and applying the triangle inequality.
In the topological group case, it comes from continuity of addition at `(0, 0)`.
These three axioms are stated more abstractly in the definition below, in terms of
operations on filters, without directly manipulating entourages.
## Main definitions
* `UniformSpace X` is a uniform space structure on a type `X`
* `UniformContinuous f` is a predicate saying a function `f : α → β` between uniform spaces
is uniformly continuous : `∀ r ∈ 𝓤 β, ∀ᶠ (x : α × α) in 𝓤 α, (f x.1, f x.2) ∈ r`
In this file we also 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)`.
## Implementation notes
There is already a theory of relations in `Data/Rel.lean` where the main definition is
`def Rel (α β : Type*) := α → β → Prop`.
The relations used in the current file involve only one type, but this is not the reason why
we don't reuse `Data/Rel.lean`. We use `Set (α × α)`
instead of `Rel α α` because we really need sets to use the filter library, and elements
of filters on `α × α` have type `Set (α × α)`.
The structure `UniformSpace X` bundles a uniform structure on `X`, a topology on `X` and
an assumption saying those are compatible. This may not seem mathematically reasonable at first,
but is in fact an instance of the forgetful inheritance pattern. See Note [forgetful inheritance]
below.
## 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*}
/-- The identity relation, or the graph of the identity function -/
def idRel {α : Type*} :=
{ p : α × α | p.1 = p.2 }
#align id_rel idRel
@[simp]
theorem mem_idRel {a b : α} : (a, b) ∈ @idRel α ↔ a = b :=
Iff.rfl
#align mem_id_rel mem_idRel
@[simp]
theorem idRel_subset {s : Set (α × α)} : idRel ⊆ s ↔ ∀ a, (a, a) ∈ s := by
simp [subset_def]
#align id_rel_subset idRel_subset
/-- The composition of relations -/
def compRel (r₁ r₂ : Set (α × α)) :=
{ p : α × α | ∃ z : α, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ r₂ }
#align comp_rel compRel
@[inherit_doc]
scoped[Uniformity] infixl:62 " ○ " => compRel
open Uniformity
@[simp]
theorem mem_compRel {α : Type u} {r₁ r₂ : Set (α × α)} {x y : α} :
(x, y) ∈ r₁ ○ r₂ ↔ ∃ z, (x, z) ∈ r₁ ∧ (z, y) ∈ r₂ :=
Iff.rfl
#align mem_comp_rel mem_compRel
@[simp]
theorem swap_idRel : Prod.swap '' idRel = @idRel α :=
Set.ext fun ⟨a, b⟩ => by simpa [image_swap_eq_preimage_swap] using eq_comm
#align swap_id_rel swap_idRel
theorem Monotone.compRel [Preorder β] {f g : β → Set (α × α)} (hf : Monotone f) (hg : Monotone g) :
Monotone fun x => f x ○ g x := fun _ _ h _ ⟨z, h₁, h₂⟩ => ⟨z, hf h h₁, hg h h₂⟩
#align monotone.comp_rel Monotone.compRel
@[mono]
theorem compRel_mono {f g h k : Set (α × α)} (h₁ : f ⊆ h) (h₂ : g ⊆ k) : f ○ g ⊆ h ○ k :=
fun _ ⟨z, h, h'⟩ => ⟨z, h₁ h, h₂ h'⟩
#align comp_rel_mono compRel_mono
theorem prod_mk_mem_compRel {a b c : α} {s t : Set (α × α)} (h₁ : (a, c) ∈ s) (h₂ : (c, b) ∈ t) :
(a, b) ∈ s ○ t :=
⟨c, h₁, h₂⟩
#align prod_mk_mem_comp_rel prod_mk_mem_compRel
@[simp]
theorem id_compRel {r : Set (α × α)} : idRel ○ r = r :=
Set.ext fun ⟨a, b⟩ => by simp
#align id_comp_rel id_compRel
theorem compRel_assoc {r s t : Set (α × α)} : r ○ s ○ t = r ○ (s ○ t) := by
ext ⟨a, b⟩; simp only [mem_compRel]; tauto
#align comp_rel_assoc compRel_assoc
theorem left_subset_compRel {s t : Set (α × α)} (h : idRel ⊆ t) : s ⊆ s ○ t := fun ⟨_x, y⟩ xy_in =>
⟨y, xy_in, h <| rfl⟩
#align left_subset_comp_rel left_subset_compRel
theorem right_subset_compRel {s t : Set (α × α)} (h : idRel ⊆ s) : t ⊆ s ○ t := fun ⟨x, _y⟩ xy_in =>
⟨x, h <| rfl, xy_in⟩
#align right_subset_comp_rel right_subset_compRel
theorem subset_comp_self {s : Set (α × α)} (h : idRel ⊆ s) : s ⊆ s ○ s :=
left_subset_compRel h
#align subset_comp_self subset_comp_self
theorem subset_iterate_compRel {s t : Set (α × α)} (h : idRel ⊆ s) (n : ℕ) :
t ⊆ (s ○ ·)^[n] t := by
induction' n with n ihn generalizing t
exacts [Subset.rfl, (right_subset_compRel h).trans ihn]
#align subset_iterate_comp_rel subset_iterate_compRel
/-- The relation is invariant under swapping factors. -/
def SymmetricRel (V : Set (α × α)) : Prop :=
Prod.swap ⁻¹' V = V
#align symmetric_rel SymmetricRel
/-- The maximal symmetric relation contained in a given relation. -/
def symmetrizeRel (V : Set (α × α)) : Set (α × α) :=
V ∩ Prod.swap ⁻¹' V
#align symmetrize_rel symmetrizeRel
theorem symmetric_symmetrizeRel (V : Set (α × α)) : SymmetricRel (symmetrizeRel V) := by
simp [SymmetricRel, symmetrizeRel, preimage_inter, inter_comm, ← preimage_comp]
#align symmetric_symmetrize_rel symmetric_symmetrizeRel
theorem symmetrizeRel_subset_self (V : Set (α × α)) : symmetrizeRel V ⊆ V :=
sep_subset _ _
#align symmetrize_rel_subset_self symmetrizeRel_subset_self
@[mono]
theorem symmetrize_mono {V W : Set (α × α)} (h : V ⊆ W) : symmetrizeRel V ⊆ symmetrizeRel W :=
inter_subset_inter h <| preimage_mono h
#align symmetrize_mono symmetrize_mono
theorem SymmetricRel.mk_mem_comm {V : Set (α × α)} (hV : SymmetricRel V) {x y : α} :
(x, y) ∈ V ↔ (y, x) ∈ V :=
Set.ext_iff.1 hV (y, x)
#align symmetric_rel.mk_mem_comm SymmetricRel.mk_mem_comm
theorem SymmetricRel.eq {U : Set (α × α)} (hU : SymmetricRel U) : Prod.swap ⁻¹' U = U :=
hU
#align symmetric_rel.eq SymmetricRel.eq
theorem SymmetricRel.inter {U V : Set (α × α)} (hU : SymmetricRel U) (hV : SymmetricRel V) :
SymmetricRel (U ∩ V) := by rw [SymmetricRel, preimage_inter, hU.eq, hV.eq]
#align symmetric_rel.inter SymmetricRel.inter
/-- This core description of a uniform space is outside of the type class hierarchy. It is useful
for constructions of uniform spaces, when the topology is derived from the uniform space. -/
structure UniformSpace.Core (α : Type u) where
/-- The uniformity filter. Once `UniformSpace` is defined, `𝓤 α` (`_root_.uniformity`) becomes the
normal form. -/
uniformity : Filter (α × α)
/-- Every set in the uniformity filter includes the diagonal. -/
refl : 𝓟 idRel ≤ uniformity
/-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/
symm : Tendsto Prod.swap uniformity uniformity
/-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/
comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity
#align uniform_space.core UniformSpace.Core
protected theorem UniformSpace.Core.comp_mem_uniformity_sets {c : Core α} {s : Set (α × α)}
(hs : s ∈ c.uniformity) : ∃ t ∈ c.uniformity, t ○ t ⊆ s :=
(mem_lift'_sets <| monotone_id.compRel monotone_id).mp <| c.comp hs
/-- An alternative constructor for `UniformSpace.Core`. This version unfolds various
`Filter`-related definitions. -/
def UniformSpace.Core.mk' {α : Type u} (U : Filter (α × α)) (refl : ∀ r ∈ U, ∀ (x), (x, x) ∈ r)
(symm : ∀ r ∈ U, Prod.swap ⁻¹' r ∈ U) (comp : ∀ r ∈ U, ∃ t ∈ U, t ○ t ⊆ r) :
UniformSpace.Core α :=
⟨U, fun _r ru => idRel_subset.2 (refl _ ru), symm, fun _r ru =>
let ⟨_s, hs, hsr⟩ := comp _ ru
mem_of_superset (mem_lift' hs) hsr⟩
#align uniform_space.core.mk' UniformSpace.Core.mk'
/-- Defining a `UniformSpace.Core` from a filter basis satisfying some uniformity-like axioms. -/
def UniformSpace.Core.mkOfBasis {α : Type u} (B : FilterBasis (α × α))
(refl : ∀ r ∈ B, ∀ (x), (x, x) ∈ r) (symm : ∀ r ∈ B, ∃ t ∈ B, t ⊆ Prod.swap ⁻¹' r)
(comp : ∀ r ∈ B, ∃ t ∈ B, t ○ t ⊆ r) : UniformSpace.Core α where
uniformity := B.filter
refl := B.hasBasis.ge_iff.mpr fun _r ru => idRel_subset.2 <| refl _ ru
symm := (B.hasBasis.tendsto_iff B.hasBasis).mpr symm
comp := (HasBasis.le_basis_iff (B.hasBasis.lift' (monotone_id.compRel monotone_id))
B.hasBasis).2 comp
#align uniform_space.core.mk_of_basis UniformSpace.Core.mkOfBasis
/-- A uniform space generates a topological space -/
def UniformSpace.Core.toTopologicalSpace {α : Type u} (u : UniformSpace.Core α) :
TopologicalSpace α :=
.mkOfNhds fun x ↦ .comap (Prod.mk x) u.uniformity
#align uniform_space.core.to_topological_space UniformSpace.Core.toTopologicalSpace
theorem UniformSpace.Core.ext :
∀ {u₁ u₂ : UniformSpace.Core α}, u₁.uniformity = u₂.uniformity → u₁ = u₂
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl
#align uniform_space.core_eq UniformSpace.Core.ext
theorem UniformSpace.Core.nhds_toTopologicalSpace {α : Type u} (u : Core α) (x : α) :
@nhds α u.toTopologicalSpace x = comap (Prod.mk x) u.uniformity := by
apply TopologicalSpace.nhds_mkOfNhds_of_hasBasis (fun _ ↦ (basis_sets _).comap _)
· exact fun a U hU ↦ u.refl hU rfl
· intro a U hU
rcases u.comp_mem_uniformity_sets hU with ⟨V, hV, hVU⟩
filter_upwards [preimage_mem_comap hV] with b hb
filter_upwards [preimage_mem_comap hV] with c hc
exact hVU ⟨b, hb, hc⟩
-- the topological structure is embedded in the uniform structure
-- to avoid instance diamond issues. See Note [forgetful inheritance].
/-- A uniform space is a generalization of the "uniform" topological aspects of a
metric space. It consists of a filter on `α × α` called the "uniformity", which
satisfies properties analogous to the reflexivity, symmetry, and triangle properties
of a metric.
A metric space has a natural uniformity, and a uniform space has a natural topology.
A topological group also has a natural uniformity, even when it is not metrizable. -/
class UniformSpace (α : Type u) extends TopologicalSpace α where
/-- The uniformity filter. -/
protected uniformity : Filter (α × α)
/-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/
protected symm : Tendsto Prod.swap uniformity uniformity
/-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/
protected comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity
/-- The uniformity agrees with the topology: the neighborhoods filter of each point `x`
is equal to `Filter.comap (Prod.mk x) (𝓤 α)`. -/
protected nhds_eq_comap_uniformity (x : α) : 𝓝 x = comap (Prod.mk x) uniformity
#align uniform_space UniformSpace
#noalign uniform_space.mk' -- Can't be a `match_pattern`, so not useful anymore
/-- The uniformity is a filter on α × α (inferred from an ambient uniform space
structure on α). -/
def uniformity (α : Type u) [UniformSpace α] : Filter (α × α) :=
@UniformSpace.uniformity α _
#align uniformity uniformity
/-- Notation for the uniformity filter with respect to a non-standard `UniformSpace` instance. -/
scoped[Uniformity] notation "𝓤[" u "]" => @uniformity _ u
@[inherit_doc] -- Porting note (#11215): TODO: should we drop the `uniformity` def?
scoped[Uniformity] notation "𝓤" => uniformity
/-- Construct a `UniformSpace` from a `u : UniformSpace.Core` and a `TopologicalSpace` structure
that is equal to `u.toTopologicalSpace`. -/
abbrev UniformSpace.ofCoreEq {α : Type u} (u : UniformSpace.Core α) (t : TopologicalSpace α)
(h : t = u.toTopologicalSpace) : UniformSpace α where
__ := u
toTopologicalSpace := t
nhds_eq_comap_uniformity x := by rw [h, u.nhds_toTopologicalSpace]
#align uniform_space.of_core_eq UniformSpace.ofCoreEq
/-- Construct a `UniformSpace` from a `UniformSpace.Core`. -/
abbrev UniformSpace.ofCore {α : Type u} (u : UniformSpace.Core α) : UniformSpace α :=
.ofCoreEq u _ rfl
#align uniform_space.of_core UniformSpace.ofCore
/-- Construct a `UniformSpace.Core` from a `UniformSpace`. -/
abbrev UniformSpace.toCore (u : UniformSpace α) : UniformSpace.Core α where
__ := u
refl := by
rintro U hU ⟨x, y⟩ (rfl : x = y)
have : Prod.mk x ⁻¹' U ∈ 𝓝 x := by
rw [UniformSpace.nhds_eq_comap_uniformity]
exact preimage_mem_comap hU
convert mem_of_mem_nhds this
theorem UniformSpace.toCore_toTopologicalSpace (u : UniformSpace α) :
u.toCore.toTopologicalSpace = u.toTopologicalSpace :=
TopologicalSpace.ext_nhds fun a ↦ by
rw [u.nhds_eq_comap_uniformity, u.toCore.nhds_toTopologicalSpace]
#align uniform_space.to_core_to_topological_space UniformSpace.toCore_toTopologicalSpace
/-- Build a `UniformSpace` from a `UniformSpace.Core` and a compatible topology.
Use `UniformSpace.mk` instead to avoid proving
the unnecessary assumption `UniformSpace.Core.refl`.
The main constructor used to use a different compatibility assumption.
This definition was created as a step towards porting to a new definition.
Now the main definition is ported,
so this constructor will be removed in a few months. -/
@[deprecated UniformSpace.mk (since := "2024-03-20")]
def UniformSpace.ofNhdsEqComap (u : UniformSpace.Core α) (_t : TopologicalSpace α)
(h : ∀ x, 𝓝 x = u.uniformity.comap (Prod.mk x)) : UniformSpace α where
__ := u
nhds_eq_comap_uniformity := h
@[ext]
protected theorem UniformSpace.ext {u₁ u₂ : UniformSpace α} (h : 𝓤[u₁] = 𝓤[u₂]) : u₁ = u₂ := by
have : u₁.toTopologicalSpace = u₂.toTopologicalSpace := TopologicalSpace.ext_nhds fun x ↦ by
rw [u₁.nhds_eq_comap_uniformity, u₂.nhds_eq_comap_uniformity]
exact congr_arg (comap _) h
cases u₁; cases u₂; congr
#align uniform_space_eq UniformSpace.ext
protected theorem UniformSpace.ext_iff {u₁ u₂ : UniformSpace α} :
u₁ = u₂ ↔ ∀ s, s ∈ 𝓤[u₁] ↔ s ∈ 𝓤[u₂] :=
⟨fun h _ => h ▸ Iff.rfl, fun h => by ext; exact h _⟩
theorem UniformSpace.ofCoreEq_toCore (u : UniformSpace α) (t : TopologicalSpace α)
(h : t = u.toCore.toTopologicalSpace) : .ofCoreEq u.toCore t h = u :=
UniformSpace.ext rfl
#align uniform_space.of_core_eq_to_core UniformSpace.ofCoreEq_toCore
/-- Replace topology in a `UniformSpace` instance with a propositionally (but possibly not
definitionally) equal one. -/
abbrev UniformSpace.replaceTopology {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α)
(h : i = u.toTopologicalSpace) : UniformSpace α where
__ := u
toTopologicalSpace := i
nhds_eq_comap_uniformity x := by rw [h, u.nhds_eq_comap_uniformity]
#align uniform_space.replace_topology UniformSpace.replaceTopology
theorem UniformSpace.replaceTopology_eq {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α)
(h : i = u.toTopologicalSpace) : u.replaceTopology h = u :=
UniformSpace.ext rfl
#align uniform_space.replace_topology_eq UniformSpace.replaceTopology_eq
-- Porting note: rfc: use `UniformSpace.Core.mkOfBasis`? This will change defeq here and there
/-- Define a `UniformSpace` using a "distance" function. The function can be, e.g., the
distance in a (usual or extended) metric space or an absolute value on a ring. -/
def UniformSpace.ofFun {α : Type u} {β : Type v} [OrderedAddCommMonoid β]
(d : α → α → β) (refl : ∀ x, d x x = 0) (symm : ∀ x y, d x y = d y x)
(triangle : ∀ x y z, d x z ≤ d x y + d y z)
(half : ∀ ε > (0 : β), ∃ δ > (0 : β), ∀ x < δ, ∀ y < δ, x + y < ε) :
UniformSpace α :=
.ofCore
{ uniformity := ⨅ r > 0, 𝓟 { x | d x.1 x.2 < r }
refl := le_iInf₂ fun r hr => principal_mono.2 <| idRel_subset.2 fun x => by simpa [refl]
symm := tendsto_iInf_iInf fun r => tendsto_iInf_iInf fun _ => tendsto_principal_principal.2
fun x hx => by rwa [mem_setOf, symm]
comp := le_iInf₂ fun r hr => let ⟨δ, h0, hδr⟩ := half r hr; le_principal_iff.2 <|
mem_of_superset
(mem_lift' <| mem_iInf_of_mem δ <| mem_iInf_of_mem h0 <| mem_principal_self _)
fun (x, z) ⟨y, h₁, h₂⟩ => (triangle _ _ _).trans_lt (hδr _ h₁ _ h₂) }
#align uniform_space.of_fun UniformSpace.ofFun
theorem UniformSpace.hasBasis_ofFun {α : Type u} {β : Type v} [LinearOrderedAddCommMonoid β]
(h₀ : ∃ x : β, 0 < x) (d : α → α → β) (refl : ∀ x, d x x = 0) (symm : ∀ x y, d x y = d y x)
(triangle : ∀ x y z, d x z ≤ d x y + d y z)
(half : ∀ ε > (0 : β), ∃ δ > (0 : β), ∀ x < δ, ∀ y < δ, x + y < ε) :
𝓤[.ofFun d refl symm triangle half].HasBasis ((0 : β) < ·) (fun ε => { x | d x.1 x.2 < ε }) :=
hasBasis_biInf_principal'
(fun ε₁ h₁ ε₂ h₂ => ⟨min ε₁ ε₂, lt_min h₁ h₂, fun _x hx => lt_of_lt_of_le hx (min_le_left _ _),
fun _x hx => lt_of_lt_of_le hx (min_le_right _ _)⟩) h₀
#align uniform_space.has_basis_of_fun UniformSpace.hasBasis_ofFun
section UniformSpace
variable [UniformSpace α]
theorem nhds_eq_comap_uniformity {x : α} : 𝓝 x = (𝓤 α).comap (Prod.mk x) :=
UniformSpace.nhds_eq_comap_uniformity x
#align nhds_eq_comap_uniformity nhds_eq_comap_uniformity
theorem isOpen_uniformity {s : Set α} :
IsOpen s ↔ ∀ x ∈ s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α := by
simp only [isOpen_iff_mem_nhds, nhds_eq_comap_uniformity, mem_comap_prod_mk]
#align is_open_uniformity isOpen_uniformity
theorem refl_le_uniformity : 𝓟 idRel ≤ 𝓤 α :=
(@UniformSpace.toCore α _).refl
#align refl_le_uniformity refl_le_uniformity
instance uniformity.neBot [Nonempty α] : NeBot (𝓤 α) :=
diagonal_nonempty.principal_neBot.mono refl_le_uniformity
#align uniformity.ne_bot uniformity.neBot
theorem refl_mem_uniformity {x : α} {s : Set (α × α)} (h : s ∈ 𝓤 α) : (x, x) ∈ s :=
refl_le_uniformity h rfl
#align refl_mem_uniformity refl_mem_uniformity
theorem mem_uniformity_of_eq {x y : α} {s : Set (α × α)} (h : s ∈ 𝓤 α) (hx : x = y) : (x, y) ∈ s :=
refl_le_uniformity h hx
#align mem_uniformity_of_eq mem_uniformity_of_eq
theorem symm_le_uniformity : map (@Prod.swap α α) (𝓤 _) ≤ 𝓤 _ :=
UniformSpace.symm
#align symm_le_uniformity symm_le_uniformity
theorem comp_le_uniformity : ((𝓤 α).lift' fun s : Set (α × α) => s ○ s) ≤ 𝓤 α :=
UniformSpace.comp
#align comp_le_uniformity comp_le_uniformity
theorem lift'_comp_uniformity : ((𝓤 α).lift' fun s : Set (α × α) => s ○ s) = 𝓤 α :=
comp_le_uniformity.antisymm <| le_lift'.2 fun _s hs ↦ mem_of_superset hs <|
subset_comp_self <| idRel_subset.2 fun _ ↦ refl_mem_uniformity hs
theorem tendsto_swap_uniformity : Tendsto (@Prod.swap α α) (𝓤 α) (𝓤 α) :=
symm_le_uniformity
#align tendsto_swap_uniformity tendsto_swap_uniformity
theorem comp_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ t ⊆ s :=
(mem_lift'_sets <| monotone_id.compRel monotone_id).mp <| comp_le_uniformity hs
#align comp_mem_uniformity_sets comp_mem_uniformity_sets
/-- 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 with n ihn generalizing s
· simpa
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⟩
#align eventually_uniformity_iterate_comp_subset eventually_uniformity_iterate_comp_subset
/-- 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
#align eventually_uniformity_comp_subset eventually_uniformity_comp_subset
/-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is transitive. -/
theorem Filter.Tendsto.uniformity_trans {l : Filter β} {f₁ f₂ f₃ : β → α}
(h₁₂ : Tendsto (fun x => (f₁ x, f₂ x)) l (𝓤 α))
(h₂₃ : Tendsto (fun x => (f₂ x, f₃ x)) l (𝓤 α)) : Tendsto (fun x => (f₁ x, f₃ x)) l (𝓤 α) := by
refine le_trans (le_lift'.2 fun s hs => mem_map.2 ?_) comp_le_uniformity
filter_upwards [mem_map.1 (h₁₂ hs), mem_map.1 (h₂₃ hs)] with x hx₁₂ hx₂₃ using ⟨_, hx₁₂, hx₂₃⟩
#align filter.tendsto.uniformity_trans Filter.Tendsto.uniformity_trans
/-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is symmetric. -/
theorem Filter.Tendsto.uniformity_symm {l : Filter β} {f : β → α × α} (h : Tendsto f l (𝓤 α)) :
Tendsto (fun x => ((f x).2, (f x).1)) l (𝓤 α) :=
tendsto_swap_uniformity.comp h
#align filter.tendsto.uniformity_symm Filter.Tendsto.uniformity_symm
/-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is reflexive. -/
theorem tendsto_diag_uniformity (f : β → α) (l : Filter β) :
Tendsto (fun x => (f x, f x)) l (𝓤 α) := fun _s hs =>
mem_map.2 <| univ_mem' fun _ => refl_mem_uniformity hs
#align tendsto_diag_uniformity tendsto_diag_uniformity
theorem tendsto_const_uniformity {a : α} {f : Filter β} : Tendsto (fun _ => (a, a)) f (𝓤 α) :=
tendsto_diag_uniformity (fun _ => a) f
#align tendsto_const_uniformity tendsto_const_uniformity
theorem symm_of_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, (∀ a b, (a, b) ∈ t → (b, a) ∈ t) ∧ t ⊆ s :=
have : preimage Prod.swap s ∈ 𝓤 α := symm_le_uniformity hs
⟨s ∩ preimage Prod.swap s, inter_mem hs this, fun _ _ ⟨h₁, h₂⟩ => ⟨h₂, h₁⟩, inter_subset_left⟩
#align symm_of_uniformity symm_of_uniformity
theorem comp_symm_of_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, (∀ {a b}, (a, b) ∈ t → (b, a) ∈ t) ∧ t ○ t ⊆ s :=
let ⟨_t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs
let ⟨t', ht', ht'₁, ht'₂⟩ := symm_of_uniformity ht₁
⟨t', ht', ht'₁ _ _, Subset.trans (monotone_id.compRel monotone_id ht'₂) ht₂⟩
#align comp_symm_of_uniformity comp_symm_of_uniformity
theorem uniformity_le_symm : 𝓤 α ≤ @Prod.swap α α <$> 𝓤 α := by
rw [map_swap_eq_comap_swap]; exact tendsto_swap_uniformity.le_comap
#align uniformity_le_symm uniformity_le_symm
theorem uniformity_eq_symm : 𝓤 α = @Prod.swap α α <$> 𝓤 α :=
le_antisymm uniformity_le_symm symm_le_uniformity
#align uniformity_eq_symm uniformity_eq_symm
@[simp]
theorem comap_swap_uniformity : comap (@Prod.swap α α) (𝓤 α) = 𝓤 α :=
(congr_arg _ uniformity_eq_symm).trans <| comap_map Prod.swap_injective
#align comap_swap_uniformity comap_swap_uniformity
theorem symmetrize_mem_uniformity {V : Set (α × α)} (h : V ∈ 𝓤 α) : symmetrizeRel V ∈ 𝓤 α := by
apply (𝓤 α).inter_sets h
rw [← image_swap_eq_preimage_swap, uniformity_eq_symm]
exact image_mem_map h
#align symmetrize_mem_uniformity symmetrize_mem_uniformity
/-- Symmetric entourages form a basis of `𝓤 α` -/
theorem UniformSpace.hasBasis_symmetric :
(𝓤 α).HasBasis (fun s : Set (α × α) => s ∈ 𝓤 α ∧ SymmetricRel s) id :=
hasBasis_self.2 fun t t_in =>
⟨symmetrizeRel t, symmetrize_mem_uniformity t_in, symmetric_symmetrizeRel t,
symmetrizeRel_subset_self t⟩
#align uniform_space.has_basis_symmetric UniformSpace.hasBasis_symmetric
theorem uniformity_lift_le_swap {g : Set (α × α) → Filter β} {f : Filter β} (hg : Monotone g)
(h : ((𝓤 α).lift fun s => g (preimage Prod.swap s)) ≤ f) : (𝓤 α).lift g ≤ f :=
calc
(𝓤 α).lift g ≤ (Filter.map (@Prod.swap α α) <| 𝓤 α).lift g :=
lift_mono uniformity_le_symm le_rfl
_ ≤ _ := by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h
#align uniformity_lift_le_swap uniformity_lift_le_swap
theorem uniformity_lift_le_comp {f : Set (α × α) → Filter β} (h : Monotone f) :
((𝓤 α).lift fun s => f (s ○ s)) ≤ (𝓤 α).lift f :=
calc
((𝓤 α).lift fun s => f (s ○ s)) = ((𝓤 α).lift' fun s : Set (α × α) => s ○ s).lift f := by
rw [lift_lift'_assoc]
· exact monotone_id.compRel monotone_id
· exact h
_ ≤ (𝓤 α).lift f := lift_mono comp_le_uniformity le_rfl
#align uniformity_lift_le_comp uniformity_lift_le_comp
-- Porting note (#10756): new lemma
theorem comp3_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ (t ○ t) ⊆ s :=
let ⟨_t', ht', ht's⟩ := comp_mem_uniformity_sets hs
let ⟨t, ht, htt'⟩ := comp_mem_uniformity_sets ht'
⟨t, ht, (compRel_mono ((subset_comp_self (refl_le_uniformity ht)).trans htt') htt').trans ht's⟩
/-- See also `comp3_mem_uniformity`. -/
theorem comp_le_uniformity3 : ((𝓤 α).lift' fun s : Set (α × α) => s ○ (s ○ s)) ≤ 𝓤 α := fun _ h =>
let ⟨_t, htU, ht⟩ := comp3_mem_uniformity h
mem_of_superset (mem_lift' htU) ht
#align comp_le_uniformity3 comp_le_uniformity3
/-- See also `comp_open_symm_mem_uniformity_sets`. -/
theorem comp_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, SymmetricRel t ∧ t ○ t ⊆ s := by
obtain ⟨w, w_in, w_sub⟩ : ∃ w ∈ 𝓤 α, w ○ w ⊆ s := comp_mem_uniformity_sets hs
use symmetrizeRel w, symmetrize_mem_uniformity w_in, symmetric_symmetrizeRel w
have : symmetrizeRel w ⊆ w := symmetrizeRel_subset_self w
calc symmetrizeRel w ○ symmetrizeRel w
_ ⊆ w ○ w := by mono
_ ⊆ s := w_sub
#align comp_symm_mem_uniformity_sets comp_symm_mem_uniformity_sets
theorem subset_comp_self_of_mem_uniformity {s : Set (α × α)} (h : s ∈ 𝓤 α) : s ⊆ s ○ s :=
subset_comp_self (refl_le_uniformity h)
#align subset_comp_self_of_mem_uniformity subset_comp_self_of_mem_uniformity
theorem comp_comp_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, SymmetricRel t ∧ t ○ t ○ t ⊆ s := by
rcases comp_symm_mem_uniformity_sets hs with ⟨w, w_in, _, w_sub⟩
rcases comp_symm_mem_uniformity_sets w_in with ⟨t, t_in, t_symm, t_sub⟩
use t, t_in, t_symm
have : t ⊆ t ○ t := subset_comp_self_of_mem_uniformity t_in
-- Porting note: Needed the following `have`s to make `mono` work
have ht := Subset.refl t
have hw := Subset.refl w
calc
t ○ t ○ t ⊆ w ○ t := by mono
_ ⊆ w ○ (t ○ t) := by mono
_ ⊆ w ○ w := by mono
_ ⊆ s := w_sub
#align comp_comp_symm_mem_uniformity_sets comp_comp_symm_mem_uniformity_sets
/-!
### Balls in uniform spaces
-/
/-- The ball around `(x : β)` with respect to `(V : Set (β × β))`. Intended to be
used for `V ∈ 𝓤 β`, but this is not needed for the definition. Recovers the
notions of metric space ball when `V = {p | dist p.1 p.2 < r }`. -/
def UniformSpace.ball (x : β) (V : Set (β × β)) : Set β :=
Prod.mk x ⁻¹' V
#align uniform_space.ball UniformSpace.ball
open UniformSpace (ball)
theorem UniformSpace.mem_ball_self (x : α) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : x ∈ ball x V :=
refl_mem_uniformity hV
#align uniform_space.mem_ball_self UniformSpace.mem_ball_self
/-- The triangle inequality for `UniformSpace.ball` -/
theorem mem_ball_comp {V W : Set (β × β)} {x y z} (h : y ∈ ball x V) (h' : z ∈ ball y W) :
z ∈ ball x (V ○ W) :=
prod_mk_mem_compRel h h'
#align mem_ball_comp mem_ball_comp
theorem ball_subset_of_comp_subset {V W : Set (β × β)} {x y} (h : x ∈ ball y W) (h' : W ○ W ⊆ V) :
ball x W ⊆ ball y V := fun _z z_in => h' (mem_ball_comp h z_in)
#align ball_subset_of_comp_subset ball_subset_of_comp_subset
theorem ball_mono {V W : Set (β × β)} (h : V ⊆ W) (x : β) : ball x V ⊆ ball x W :=
preimage_mono h
#align ball_mono ball_mono
theorem ball_inter (x : β) (V W : Set (β × β)) : ball x (V ∩ W) = ball x V ∩ ball x W :=
preimage_inter
#align ball_inter ball_inter
theorem ball_inter_left (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x V :=
ball_mono inter_subset_left x
#align ball_inter_left ball_inter_left
theorem ball_inter_right (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x W :=
ball_mono inter_subset_right x
#align ball_inter_right ball_inter_right
theorem mem_ball_symmetry {V : Set (β × β)} (hV : SymmetricRel V) {x y} :
x ∈ ball y V ↔ y ∈ ball x V :=
show (x, y) ∈ Prod.swap ⁻¹' V ↔ (x, y) ∈ V by
unfold SymmetricRel at hV
rw [hV]
#align mem_ball_symmetry mem_ball_symmetry
theorem ball_eq_of_symmetry {V : Set (β × β)} (hV : SymmetricRel V) {x} :
ball x V = { y | (y, x) ∈ V } := by
ext y
rw [mem_ball_symmetry hV]
exact Iff.rfl
#align ball_eq_of_symmetry ball_eq_of_symmetry
theorem mem_comp_of_mem_ball {V W : Set (β × β)} {x y z : β} (hV : SymmetricRel V)
(hx : x ∈ ball z V) (hy : y ∈ ball z W) : (x, y) ∈ V ○ W := by
rw [mem_ball_symmetry hV] at hx
exact ⟨z, hx, hy⟩
#align mem_comp_of_mem_ball mem_comp_of_mem_ball
theorem UniformSpace.isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) :=
hV.preimage <| continuous_const.prod_mk continuous_id
#align uniform_space.is_open_ball UniformSpace.isOpen_ball
theorem UniformSpace.isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) :
IsClosed (ball x V) :=
hV.preimage <| continuous_const.prod_mk continuous_id
| Mathlib/Topology/UniformSpace/Basic.lean | 707 | 715 | theorem mem_comp_comp {V W M : Set (β × β)} (hW' : SymmetricRel W) {p : β × β} :
p ∈ V ○ M ○ W ↔ (ball p.1 V ×ˢ ball p.2 W ∩ M).Nonempty := by |
cases' p with x y
constructor
· rintro ⟨z, ⟨w, hpw, hwz⟩, hzy⟩
exact ⟨(w, z), ⟨hpw, by rwa [mem_ball_symmetry hW']⟩, hwz⟩
· rintro ⟨⟨w, z⟩, ⟨w_in, z_in⟩, hwz⟩
rw [mem_ball_symmetry hW'] at z_in
exact ⟨z, ⟨w, w_in, hwz⟩, z_in⟩
|
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Data.Finset.Sort
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Sign
import Mathlib.LinearAlgebra.AffineSpace.Combination
import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv
import Mathlib.LinearAlgebra.Basis.VectorSpace
#align_import linear_algebra.affine_space.independent from "leanprover-community/mathlib"@"2de9c37fa71dde2f1c6feff19876dd6a7b1519f0"
/-!
# Affine independence
This file defines affinely independent families of points.
## Main definitions
* `AffineIndependent` defines affinely independent families of points
as those where no nontrivial weighted subtraction is `0`. This is
proved equivalent to two other formulations: linear independence of
the results of subtracting a base point in the family from the other
points in the family, or any equal affine combinations having the
same weights. A bundled type `Simplex` is provided for finite
affinely independent families of points, with an abbreviation
`Triangle` for the case of three points.
## References
* https://en.wikipedia.org/wiki/Affine_space
-/
noncomputable section
open Finset Function
open scoped Affine
section AffineIndependent
variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V]
variable [AffineSpace V P] {ι : Type*}
/-- An indexed family is said to be affinely independent if no
nontrivial weighted subtractions (where the sum of weights is 0) are
0. -/
def AffineIndependent (p : ι → P) : Prop :=
∀ (s : Finset ι) (w : ι → k),
∑ i ∈ s, w i = 0 → s.weightedVSub p w = (0 : V) → ∀ i ∈ s, w i = 0
#align affine_independent AffineIndependent
/-- The definition of `AffineIndependent`. -/
theorem affineIndependent_def (p : ι → P) :
AffineIndependent k p ↔
∀ (s : Finset ι) (w : ι → k),
∑ i ∈ s, w i = 0 → s.weightedVSub p w = (0 : V) → ∀ i ∈ s, w i = 0 :=
Iff.rfl
#align affine_independent_def affineIndependent_def
/-- A family with at most one point is affinely independent. -/
theorem affineIndependent_of_subsingleton [Subsingleton ι] (p : ι → P) : AffineIndependent k p :=
fun _ _ h _ i hi => Fintype.eq_of_subsingleton_of_sum_eq h i hi
#align affine_independent_of_subsingleton affineIndependent_of_subsingleton
/-- A family indexed by a `Fintype` is affinely independent if and
only if no nontrivial weighted subtractions over `Finset.univ` (where
the sum of the weights is 0) are 0. -/
theorem affineIndependent_iff_of_fintype [Fintype ι] (p : ι → P) :
AffineIndependent k p ↔
∀ w : ι → k, ∑ i, w i = 0 → Finset.univ.weightedVSub p w = (0 : V) → ∀ i, w i = 0 := by
constructor
· exact fun h w hw hs i => h Finset.univ w hw hs i (Finset.mem_univ _)
· intro h s w hw hs i hi
rw [Finset.weightedVSub_indicator_subset _ _ (Finset.subset_univ s)] at hs
rw [← Finset.sum_indicator_subset _ (Finset.subset_univ s)] at hw
replace h := h ((↑s : Set ι).indicator w) hw hs i
simpa [hi] using h
#align affine_independent_iff_of_fintype affineIndependent_iff_of_fintype
/-- A family is affinely independent if and only if the differences
from a base point in that family are linearly independent. -/
theorem affineIndependent_iff_linearIndependent_vsub (p : ι → P) (i1 : ι) :
AffineIndependent k p ↔ LinearIndependent k fun i : { x // x ≠ i1 } => (p i -ᵥ p i1 : V) := by
classical
constructor
· intro h
rw [linearIndependent_iff']
intro s g hg i hi
set f : ι → k := fun x => if hx : x = i1 then -∑ y ∈ s, g y else g ⟨x, hx⟩ with hfdef
let s2 : Finset ι := insert i1 (s.map (Embedding.subtype _))
have hfg : ∀ x : { x // x ≠ i1 }, g x = f x := by
intro x
rw [hfdef]
dsimp only
erw [dif_neg x.property, Subtype.coe_eta]
rw [hfg]
have hf : ∑ ι ∈ s2, f ι = 0 := by
rw [Finset.sum_insert
(Finset.not_mem_map_subtype_of_not_property s (Classical.not_not.2 rfl)),
Finset.sum_subtype_map_embedding fun x _ => (hfg x).symm]
rw [hfdef]
dsimp only
rw [dif_pos rfl]
exact neg_add_self _
have hs2 : s2.weightedVSub p f = (0 : V) := by
set f2 : ι → V := fun x => f x • (p x -ᵥ p i1) with hf2def
set g2 : { x // x ≠ i1 } → V := fun x => g x • (p x -ᵥ p i1)
have hf2g2 : ∀ x : { x // x ≠ i1 }, f2 x = g2 x := by
simp only [g2, hf2def]
refine fun x => ?_
rw [hfg]
rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s2 f p hf (p i1),
Finset.weightedVSubOfPoint_insert, Finset.weightedVSubOfPoint_apply,
Finset.sum_subtype_map_embedding fun x _ => hf2g2 x]
exact hg
exact h s2 f hf hs2 i (Finset.mem_insert_of_mem (Finset.mem_map.2 ⟨i, hi, rfl⟩))
· intro h
rw [linearIndependent_iff'] at h
intro s w hw hs i hi
rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s w p hw (p i1), ←
s.weightedVSubOfPoint_erase w p i1, Finset.weightedVSubOfPoint_apply] at hs
let f : ι → V := fun i => w i • (p i -ᵥ p i1)
have hs2 : (∑ i ∈ (s.erase i1).subtype fun i => i ≠ i1, f i) = 0 := by
rw [← hs]
convert Finset.sum_subtype_of_mem f fun x => Finset.ne_of_mem_erase
have h2 := h ((s.erase i1).subtype fun i => i ≠ i1) (fun x => w x) hs2
simp_rw [Finset.mem_subtype] at h2
have h2b : ∀ i ∈ s, i ≠ i1 → w i = 0 := fun i his hi =>
h2 ⟨i, hi⟩ (Finset.mem_erase_of_ne_of_mem hi his)
exact Finset.eq_zero_of_sum_eq_zero hw h2b i hi
#align affine_independent_iff_linear_independent_vsub affineIndependent_iff_linearIndependent_vsub
/-- A set is affinely independent if and only if the differences from
a base point in that set are linearly independent. -/
theorem affineIndependent_set_iff_linearIndependent_vsub {s : Set P} {p₁ : P} (hp₁ : p₁ ∈ s) :
AffineIndependent k (fun p => p : s → P) ↔
LinearIndependent k (fun v => v : (fun p => (p -ᵥ p₁ : V)) '' (s \ {p₁}) → V) := by
rw [affineIndependent_iff_linearIndependent_vsub k (fun p => p : s → P) ⟨p₁, hp₁⟩]
constructor
· intro h
have hv : ∀ v : (fun p => (p -ᵥ p₁ : V)) '' (s \ {p₁}), (v : V) +ᵥ p₁ ∈ s \ {p₁} := fun v =>
(vsub_left_injective p₁).mem_set_image.1 ((vadd_vsub (v : V) p₁).symm ▸ v.property)
let f : (fun p : P => (p -ᵥ p₁ : V)) '' (s \ {p₁}) → { x : s // x ≠ ⟨p₁, hp₁⟩ } := fun x =>
⟨⟨(x : V) +ᵥ p₁, Set.mem_of_mem_diff (hv x)⟩, fun hx =>
Set.not_mem_of_mem_diff (hv x) (Subtype.ext_iff.1 hx)⟩
convert h.comp f fun x1 x2 hx =>
Subtype.ext (vadd_right_cancel p₁ (Subtype.ext_iff.1 (Subtype.ext_iff.1 hx)))
ext v
exact (vadd_vsub (v : V) p₁).symm
· intro h
let f : { x : s // x ≠ ⟨p₁, hp₁⟩ } → (fun p : P => (p -ᵥ p₁ : V)) '' (s \ {p₁}) := fun x =>
⟨((x : s) : P) -ᵥ p₁, ⟨x, ⟨⟨(x : s).property, fun hx => x.property (Subtype.ext hx)⟩, rfl⟩⟩⟩
convert h.comp f fun x1 x2 hx =>
Subtype.ext (Subtype.ext (vsub_left_cancel (Subtype.ext_iff.1 hx)))
#align affine_independent_set_iff_linear_independent_vsub affineIndependent_set_iff_linearIndependent_vsub
/-- A set of nonzero vectors is linearly independent if and only if,
given a point `p₁`, the vectors added to `p₁` and `p₁` itself are
affinely independent. -/
theorem linearIndependent_set_iff_affineIndependent_vadd_union_singleton {s : Set V}
(hs : ∀ v ∈ s, v ≠ (0 : V)) (p₁ : P) : LinearIndependent k (fun v => v : s → V) ↔
AffineIndependent k (fun p => p : ({p₁} ∪ (fun v => v +ᵥ p₁) '' s : Set P) → P) := by
rw [affineIndependent_set_iff_linearIndependent_vsub k
(Set.mem_union_left _ (Set.mem_singleton p₁))]
have h : (fun p => (p -ᵥ p₁ : V)) '' (({p₁} ∪ (fun v => v +ᵥ p₁) '' s) \ {p₁}) = s := by
simp_rw [Set.union_diff_left, Set.image_diff (vsub_left_injective p₁), Set.image_image,
Set.image_singleton, vsub_self, vadd_vsub, Set.image_id']
exact Set.diff_singleton_eq_self fun h => hs 0 h rfl
rw [h]
#align linear_independent_set_iff_affine_independent_vadd_union_singleton linearIndependent_set_iff_affineIndependent_vadd_union_singleton
/-- A family is affinely independent if and only if any affine
combinations (with sum of weights 1) that evaluate to the same point
have equal `Set.indicator`. -/
theorem affineIndependent_iff_indicator_eq_of_affineCombination_eq (p : ι → P) :
AffineIndependent k p ↔
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i ∈ s1, w1 i = 1 →
∑ i ∈ s2, w2 i = 1 →
s1.affineCombination k p w1 = s2.affineCombination k p w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2 := by
classical
constructor
· intro ha s1 s2 w1 w2 hw1 hw2 heq
ext i
by_cases hi : i ∈ s1 ∪ s2
· rw [← sub_eq_zero]
rw [← Finset.sum_indicator_subset w1 (s1.subset_union_left (s₂:=s2))] at hw1
rw [← Finset.sum_indicator_subset w2 (s1.subset_union_right)] at hw2
have hws : (∑ i ∈ s1 ∪ s2, (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) i) = 0 := by
simp [hw1, hw2]
rw [Finset.affineCombination_indicator_subset w1 p (s1.subset_union_left (s₂:=s2)),
Finset.affineCombination_indicator_subset w2 p s1.subset_union_right,
← @vsub_eq_zero_iff_eq V, Finset.affineCombination_vsub] at heq
exact ha (s1 ∪ s2) (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) hws heq i hi
· rw [← Finset.mem_coe, Finset.coe_union] at hi
have h₁ : Set.indicator (↑s1) w1 i = 0 := by
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
intro h
by_contra
exact (mt (@Set.mem_union_left _ i ↑s1 ↑s2) hi) h
have h₂ : Set.indicator (↑s2) w2 i = 0 := by
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
intro h
by_contra
exact (mt (@Set.mem_union_right _ i ↑s2 ↑s1) hi) h
simp [h₁, h₂]
· intro ha s w hw hs i0 hi0
let w1 : ι → k := Function.update (Function.const ι 0) i0 1
have hw1 : ∑ i ∈ s, w1 i = 1 := by
rw [Finset.sum_update_of_mem hi0]
simp only [Finset.sum_const_zero, add_zero, const_apply]
have hw1s : s.affineCombination k p w1 = p i0 :=
s.affineCombination_of_eq_one_of_eq_zero w1 p hi0 (Function.update_same _ _ _)
fun _ _ hne => Function.update_noteq hne _ _
let w2 := w + w1
have hw2 : ∑ i ∈ s, w2 i = 1 := by
simp_all only [w2, Pi.add_apply, Finset.sum_add_distrib, zero_add]
have hw2s : s.affineCombination k p w2 = p i0 := by
simp_all only [w2, ← Finset.weightedVSub_vadd_affineCombination, zero_vadd]
replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm ▸ hw2s)
have hws : w2 i0 - w1 i0 = 0 := by
rw [← Finset.mem_coe] at hi0
rw [← Set.indicator_of_mem hi0 w2, ← Set.indicator_of_mem hi0 w1, ha, sub_self]
simpa [w2] using hws
#align affine_independent_iff_indicator_eq_of_affine_combination_eq affineIndependent_iff_indicator_eq_of_affineCombination_eq
/-- A finite family is affinely independent if and only if any affine
combinations (with sum of weights 1) that evaluate to the same point are equal. -/
theorem affineIndependent_iff_eq_of_fintype_affineCombination_eq [Fintype ι] (p : ι → P) :
AffineIndependent k p ↔ ∀ w1 w2 : ι → k, ∑ i, w1 i = 1 → ∑ i, w2 i = 1 →
Finset.univ.affineCombination k p w1 = Finset.univ.affineCombination k p w2 → w1 = w2 := by
rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq]
constructor
· intro h w1 w2 hw1 hw2 hweq
simpa only [Set.indicator_univ, Finset.coe_univ] using h _ _ w1 w2 hw1 hw2 hweq
· intro h s1 s2 w1 w2 hw1 hw2 hweq
have hw1' : (∑ i, (s1 : Set ι).indicator w1 i) = 1 := by
rwa [Finset.sum_indicator_subset _ (Finset.subset_univ s1)]
have hw2' : (∑ i, (s2 : Set ι).indicator w2 i) = 1 := by
rwa [Finset.sum_indicator_subset _ (Finset.subset_univ s2)]
rw [Finset.affineCombination_indicator_subset w1 p (Finset.subset_univ s1),
Finset.affineCombination_indicator_subset w2 p (Finset.subset_univ s2)] at hweq
exact h _ _ hw1' hw2' hweq
#align affine_independent_iff_eq_of_fintype_affine_combination_eq affineIndependent_iff_eq_of_fintype_affineCombination_eq
variable {k}
/-- If we single out one member of an affine-independent family of points and affinely transport
all others along the line joining them to this member, the resulting new family of points is affine-
independent.
This is the affine version of `LinearIndependent.units_smul`. -/
theorem AffineIndependent.units_lineMap {p : ι → P} (hp : AffineIndependent k p) (j : ι)
(w : ι → Units k) : AffineIndependent k fun i => AffineMap.lineMap (p j) (p i) (w i : k) := by
rw [affineIndependent_iff_linearIndependent_vsub k _ j] at hp ⊢
simp only [AffineMap.lineMap_vsub_left, AffineMap.coe_const, AffineMap.lineMap_same, const_apply]
exact hp.units_smul fun i => w i
#align affine_independent.units_line_map AffineIndependent.units_lineMap
theorem AffineIndependent.indicator_eq_of_affineCombination_eq {p : ι → P}
(ha : AffineIndependent k p) (s₁ s₂ : Finset ι) (w₁ w₂ : ι → k) (hw₁ : ∑ i ∈ s₁, w₁ i = 1)
(hw₂ : ∑ i ∈ s₂, w₂ i = 1) (h : s₁.affineCombination k p w₁ = s₂.affineCombination k p w₂) :
Set.indicator (↑s₁) w₁ = Set.indicator (↑s₂) w₂ :=
(affineIndependent_iff_indicator_eq_of_affineCombination_eq k p).1 ha s₁ s₂ w₁ w₂ hw₁ hw₂ h
#align affine_independent.indicator_eq_of_affine_combination_eq AffineIndependent.indicator_eq_of_affineCombination_eq
/-- An affinely independent family is injective, if the underlying
ring is nontrivial. -/
protected theorem AffineIndependent.injective [Nontrivial k] {p : ι → P}
(ha : AffineIndependent k p) : Function.Injective p := by
intro i j hij
rw [affineIndependent_iff_linearIndependent_vsub _ _ j] at ha
by_contra hij'
refine ha.ne_zero ⟨i, hij'⟩ (vsub_eq_zero_iff_eq.mpr ?_)
simp_all only [ne_eq]
#align affine_independent.injective AffineIndependent.injective
/-- If a family is affinely independent, so is any subfamily given by
composition of an embedding into index type with the original
family. -/
theorem AffineIndependent.comp_embedding {ι2 : Type*} (f : ι2 ↪ ι) {p : ι → P}
(ha : AffineIndependent k p) : AffineIndependent k (p ∘ f) := by
classical
intro fs w hw hs i0 hi0
let fs' := fs.map f
let w' i := if h : ∃ i2, f i2 = i then w h.choose else 0
have hw' : ∀ i2 : ι2, w' (f i2) = w i2 := by
intro i2
have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩
have hs : h.choose = i2 := f.injective h.choose_spec
simp_rw [w', dif_pos h, hs]
have hw's : ∑ i ∈ fs', w' i = 0 := by
rw [← hw, Finset.sum_map]
simp [hw']
have hs' : fs'.weightedVSub p w' = (0 : V) := by
rw [← hs, Finset.weightedVSub_map]
congr with i
simp_all only [comp_apply, EmbeddingLike.apply_eq_iff_eq, exists_eq, dite_true]
rw [← ha fs' w' hw's hs' (f i0) ((Finset.mem_map' _).2 hi0), hw']
#align affine_independent.comp_embedding AffineIndependent.comp_embedding
/-- If a family is affinely independent, so is any subfamily indexed
by a subtype of the index type. -/
protected theorem AffineIndependent.subtype {p : ι → P} (ha : AffineIndependent k p) (s : Set ι) :
AffineIndependent k fun i : s => p i :=
ha.comp_embedding (Embedding.subtype _)
#align affine_independent.subtype AffineIndependent.subtype
/-- If an indexed family of points is affinely independent, so is the
corresponding set of points. -/
protected theorem AffineIndependent.range {p : ι → P} (ha : AffineIndependent k p) :
AffineIndependent k (fun x => x : Set.range p → P) := by
let f : Set.range p → ι := fun x => x.property.choose
have hf : ∀ x, p (f x) = x := fun x => x.property.choose_spec
let fe : Set.range p ↪ ι := ⟨f, fun x₁ x₂ he => Subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩
convert ha.comp_embedding fe
ext
simp [fe, hf]
#align affine_independent.range AffineIndependent.range
theorem affineIndependent_equiv {ι' : Type*} (e : ι ≃ ι') {p : ι' → P} :
AffineIndependent k (p ∘ e) ↔ AffineIndependent k p := by
refine ⟨?_, AffineIndependent.comp_embedding e.toEmbedding⟩
intro h
have : p = p ∘ e ∘ e.symm.toEmbedding := by
ext
simp
rw [this]
exact h.comp_embedding e.symm.toEmbedding
#align affine_independent_equiv affineIndependent_equiv
/-- If a set of points is affinely independent, so is any subset. -/
protected theorem AffineIndependent.mono {s t : Set P}
(ha : AffineIndependent k (fun x => x : t → P)) (hs : s ⊆ t) :
AffineIndependent k (fun x => x : s → P) :=
ha.comp_embedding (s.embeddingOfSubset t hs)
#align affine_independent.mono AffineIndependent.mono
/-- If the range of an injective indexed family of points is affinely
independent, so is that family. -/
theorem AffineIndependent.of_set_of_injective {p : ι → P}
(ha : AffineIndependent k (fun x => x : Set.range p → P)) (hi : Function.Injective p) :
AffineIndependent k p :=
ha.comp_embedding
(⟨fun i => ⟨p i, Set.mem_range_self _⟩, fun _ _ h => hi (Subtype.mk_eq_mk.1 h)⟩ :
ι ↪ Set.range p)
#align affine_independent.of_set_of_injective AffineIndependent.of_set_of_injective
section Composition
variable {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AffineSpace V₂ P₂]
/-- If the image of a family of points in affine space under an affine transformation is affine-
independent, then the original family of points is also affine-independent. -/
theorem AffineIndependent.of_comp {p : ι → P} (f : P →ᵃ[k] P₂) (hai : AffineIndependent k (f ∘ p)) :
AffineIndependent k p := by
cases' isEmpty_or_nonempty ι with h h;
· haveI := h
apply affineIndependent_of_subsingleton
obtain ⟨i⟩ := h
rw [affineIndependent_iff_linearIndependent_vsub k p i]
simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ←
f.linearMap_vsub] at hai
exact LinearIndependent.of_comp f.linear hai
#align affine_independent.of_comp AffineIndependent.of_comp
/-- The image of a family of points in affine space, under an injective affine transformation, is
affine-independent. -/
| Mathlib/LinearAlgebra/AffineSpace/Independent.lean | 374 | 384 | theorem AffineIndependent.map' {p : ι → P} (hai : AffineIndependent k p) (f : P →ᵃ[k] P₂)
(hf : Function.Injective f) : AffineIndependent k (f ∘ p) := by |
cases' isEmpty_or_nonempty ι with h h
· haveI := h
apply affineIndependent_of_subsingleton
obtain ⟨i⟩ := h
rw [affineIndependent_iff_linearIndependent_vsub k p i] at hai
simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ←
f.linearMap_vsub]
have hf' : LinearMap.ker f.linear = ⊥ := by rwa [LinearMap.ker_eq_bot, f.linear_injective_iff]
exact LinearIndependent.map' hai f.linear hf'
|
/-
Copyright (c) 2019 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo, Yaël Dillies, Moritz Doll
-/
import Mathlib.Data.Real.Pointwise
import Mathlib.Analysis.Convex.Function
import Mathlib.Analysis.LocallyConvex.Basic
import Mathlib.Data.Real.Sqrt
#align_import analysis.seminorm from "leanprover-community/mathlib"@"09079525fd01b3dda35e96adaa08d2f943e1648c"
/-!
# Seminorms
This file defines seminorms.
A seminorm is a function to the reals which is positive-semidefinite, absolutely homogeneous, and
subadditive. They are closely related to convex sets, and a topological vector space is locally
convex if and only if its topology is induced by a family of seminorms.
## Main declarations
For a module over a normed ring:
* `Seminorm`: A function to the reals that is positive-semidefinite, absolutely homogeneous, and
subadditive.
* `normSeminorm 𝕜 E`: The norm on `E` as a seminorm.
## References
* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]
## Tags
seminorm, locally convex, LCTVS
-/
open NormedField Set Filter
open scoped NNReal Pointwise Topology Uniformity
variable {R R' 𝕜 𝕜₂ 𝕜₃ 𝕝 E E₂ E₃ F G ι : Type*}
/-- A seminorm on a module over a normed ring is a function to the reals that is positive
semidefinite, positive homogeneous, and subadditive. -/
structure Seminorm (𝕜 : Type*) (E : Type*) [SeminormedRing 𝕜] [AddGroup E] [SMul 𝕜 E] extends
AddGroupSeminorm E where
/-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar
and the original seminorm. -/
smul' : ∀ (a : 𝕜) (x : E), toFun (a • x) = ‖a‖ * toFun x
#align seminorm Seminorm
attribute [nolint docBlame] Seminorm.toAddGroupSeminorm
/-- `SeminormClass F 𝕜 E` states that `F` is a type of seminorms on the `𝕜`-module `E`.
You should extend this class when you extend `Seminorm`. -/
class SeminormClass (F : Type*) (𝕜 E : outParam Type*) [SeminormedRing 𝕜] [AddGroup E]
[SMul 𝕜 E] [FunLike F E ℝ] extends AddGroupSeminormClass F E ℝ : Prop where
/-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar
and the original seminorm. -/
map_smul_eq_mul (f : F) (a : 𝕜) (x : E) : f (a • x) = ‖a‖ * f x
#align seminorm_class SeminormClass
export SeminormClass (map_smul_eq_mul)
-- Porting note: dangerous instances no longer exist
-- attribute [nolint dangerousInstance] SeminormClass.toAddGroupSeminormClass
section Of
/-- Alternative constructor for a `Seminorm` on an `AddCommGroup E` that is a module over a
`SeminormedRing 𝕜`. -/
def Seminorm.of [SeminormedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ)
(add_le : ∀ x y : E, f (x + y) ≤ f x + f y) (smul : ∀ (a : 𝕜) (x : E), f (a • x) = ‖a‖ * f x) :
Seminorm 𝕜 E where
toFun := f
map_zero' := by rw [← zero_smul 𝕜 (0 : E), smul, norm_zero, zero_mul]
add_le' := add_le
smul' := smul
neg' x := by rw [← neg_one_smul 𝕜, smul, norm_neg, ← smul, one_smul]
#align seminorm.of Seminorm.of
/-- Alternative constructor for a `Seminorm` over a normed field `𝕜` that only assumes `f 0 = 0`
and an inequality for the scalar multiplication. -/
def Seminorm.ofSMulLE [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ) (map_zero : f 0 = 0)
(add_le : ∀ x y, f (x + y) ≤ f x + f y) (smul_le : ∀ (r : 𝕜) (x), f (r • x) ≤ ‖r‖ * f x) :
Seminorm 𝕜 E :=
Seminorm.of f add_le fun r x => by
refine le_antisymm (smul_le r x) ?_
by_cases h : r = 0
· simp [h, map_zero]
rw [← mul_le_mul_left (inv_pos.mpr (norm_pos_iff.mpr h))]
rw [inv_mul_cancel_left₀ (norm_ne_zero_iff.mpr h)]
specialize smul_le r⁻¹ (r • x)
rw [norm_inv] at smul_le
convert smul_le
simp [h]
#align seminorm.of_smul_le Seminorm.ofSMulLE
end Of
namespace Seminorm
section SeminormedRing
variable [SeminormedRing 𝕜]
section AddGroup
variable [AddGroup E]
section SMul
variable [SMul 𝕜 E]
instance instFunLike : FunLike (Seminorm 𝕜 E) E ℝ where
coe f := f.toFun
coe_injective' f g h := by
rcases f with ⟨⟨_⟩⟩
rcases g with ⟨⟨_⟩⟩
congr
instance instSeminormClass : SeminormClass (Seminorm 𝕜 E) 𝕜 E where
map_zero f := f.map_zero'
map_add_le_add f := f.add_le'
map_neg_eq_map f := f.neg'
map_smul_eq_mul f := f.smul'
#align seminorm.seminorm_class Seminorm.instSeminormClass
@[ext]
theorem ext {p q : Seminorm 𝕜 E} (h : ∀ x, (p : E → ℝ) x = q x) : p = q :=
DFunLike.ext p q h
#align seminorm.ext Seminorm.ext
instance instZero : Zero (Seminorm 𝕜 E) :=
⟨{ AddGroupSeminorm.instZeroAddGroupSeminorm.zero with
smul' := fun _ _ => (mul_zero _).symm }⟩
@[simp]
theorem coe_zero : ⇑(0 : Seminorm 𝕜 E) = 0 :=
rfl
#align seminorm.coe_zero Seminorm.coe_zero
@[simp]
theorem zero_apply (x : E) : (0 : Seminorm 𝕜 E) x = 0 :=
rfl
#align seminorm.zero_apply Seminorm.zero_apply
instance : Inhabited (Seminorm 𝕜 E) :=
⟨0⟩
variable (p : Seminorm 𝕜 E) (c : 𝕜) (x y : E) (r : ℝ)
/-- Any action on `ℝ` which factors through `ℝ≥0` applies to a seminorm. -/
instance instSMul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : SMul R (Seminorm 𝕜 E) where
smul r p :=
{ r • p.toAddGroupSeminorm with
toFun := fun x => r • p x
smul' := fun _ _ => by
simp only [← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def, smul_eq_mul]
rw [map_smul_eq_mul, mul_left_comm] }
instance [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] [SMul R' ℝ] [SMul R' ℝ≥0]
[IsScalarTower R' ℝ≥0 ℝ] [SMul R R'] [IsScalarTower R R' ℝ] :
IsScalarTower R R' (Seminorm 𝕜 E) where
smul_assoc r a p := ext fun x => smul_assoc r a (p x)
theorem coe_smul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E) :
⇑(r • p) = r • ⇑p :=
rfl
#align seminorm.coe_smul Seminorm.coe_smul
@[simp]
theorem smul_apply [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E)
(x : E) : (r • p) x = r • p x :=
rfl
#align seminorm.smul_apply Seminorm.smul_apply
instance instAdd : Add (Seminorm 𝕜 E) where
add p q :=
{ p.toAddGroupSeminorm + q.toAddGroupSeminorm with
toFun := fun x => p x + q x
smul' := fun a x => by simp only [map_smul_eq_mul, map_smul_eq_mul, mul_add] }
theorem coe_add (p q : Seminorm 𝕜 E) : ⇑(p + q) = p + q :=
rfl
#align seminorm.coe_add Seminorm.coe_add
@[simp]
theorem add_apply (p q : Seminorm 𝕜 E) (x : E) : (p + q) x = p x + q x :=
rfl
#align seminorm.add_apply Seminorm.add_apply
instance instAddMonoid : AddMonoid (Seminorm 𝕜 E) :=
DFunLike.coe_injective.addMonoid _ rfl coe_add fun _ _ => by rfl
instance instOrderedCancelAddCommMonoid : OrderedCancelAddCommMonoid (Seminorm 𝕜 E) :=
DFunLike.coe_injective.orderedCancelAddCommMonoid _ rfl coe_add fun _ _ => rfl
instance instMulAction [Monoid R] [MulAction R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] :
MulAction R (Seminorm 𝕜 E) :=
DFunLike.coe_injective.mulAction _ (by intros; rfl)
variable (𝕜 E)
/-- `coeFn` as an `AddMonoidHom`. Helper definition for showing that `Seminorm 𝕜 E` is a module. -/
@[simps]
def coeFnAddMonoidHom : AddMonoidHom (Seminorm 𝕜 E) (E → ℝ) where
toFun := (↑)
map_zero' := coe_zero
map_add' := coe_add
#align seminorm.coe_fn_add_monoid_hom Seminorm.coeFnAddMonoidHom
theorem coeFnAddMonoidHom_injective : Function.Injective (coeFnAddMonoidHom 𝕜 E) :=
show @Function.Injective (Seminorm 𝕜 E) (E → ℝ) (↑) from DFunLike.coe_injective
#align seminorm.coe_fn_add_monoid_hom_injective Seminorm.coeFnAddMonoidHom_injective
variable {𝕜 E}
instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ] [SMul R ℝ≥0]
[IsScalarTower R ℝ≥0 ℝ] : DistribMulAction R (Seminorm 𝕜 E) :=
(coeFnAddMonoidHom_injective 𝕜 E).distribMulAction _ (by intros; rfl)
instance instModule [Semiring R] [Module R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] :
Module R (Seminorm 𝕜 E) :=
(coeFnAddMonoidHom_injective 𝕜 E).module R _ (by intros; rfl)
instance instSup : Sup (Seminorm 𝕜 E) where
sup p q :=
{ p.toAddGroupSeminorm ⊔ q.toAddGroupSeminorm with
toFun := p ⊔ q
smul' := fun x v =>
(congr_arg₂ max (map_smul_eq_mul p x v) (map_smul_eq_mul q x v)).trans <|
(mul_max_of_nonneg _ _ <| norm_nonneg x).symm }
@[simp]
theorem coe_sup (p q : Seminorm 𝕜 E) : ⇑(p ⊔ q) = (p : E → ℝ) ⊔ (q : E → ℝ) :=
rfl
#align seminorm.coe_sup Seminorm.coe_sup
theorem sup_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊔ q) x = p x ⊔ q x :=
rfl
#align seminorm.sup_apply Seminorm.sup_apply
theorem smul_sup [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) :
r • (p ⊔ q) = r • p ⊔ r • q :=
have real.smul_max : ∀ x y : ℝ, r • max x y = max (r • x) (r • y) := fun x y => by
simpa only [← smul_eq_mul, ← NNReal.smul_def, smul_one_smul ℝ≥0 r (_ : ℝ)] using
mul_max_of_nonneg x y (r • (1 : ℝ≥0) : ℝ≥0).coe_nonneg
ext fun x => real.smul_max _ _
#align seminorm.smul_sup Seminorm.smul_sup
instance instPartialOrder : PartialOrder (Seminorm 𝕜 E) :=
PartialOrder.lift _ DFunLike.coe_injective
@[simp, norm_cast]
theorem coe_le_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) ≤ q ↔ p ≤ q :=
Iff.rfl
#align seminorm.coe_le_coe Seminorm.coe_le_coe
@[simp, norm_cast]
theorem coe_lt_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) < q ↔ p < q :=
Iff.rfl
#align seminorm.coe_lt_coe Seminorm.coe_lt_coe
theorem le_def {p q : Seminorm 𝕜 E} : p ≤ q ↔ ∀ x, p x ≤ q x :=
Iff.rfl
#align seminorm.le_def Seminorm.le_def
theorem lt_def {p q : Seminorm 𝕜 E} : p < q ↔ p ≤ q ∧ ∃ x, p x < q x :=
@Pi.lt_def _ _ _ p q
#align seminorm.lt_def Seminorm.lt_def
instance instSemilatticeSup : SemilatticeSup (Seminorm 𝕜 E) :=
Function.Injective.semilatticeSup _ DFunLike.coe_injective coe_sup
end SMul
end AddGroup
section Module
variable [SeminormedRing 𝕜₂] [SeminormedRing 𝕜₃]
variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂]
variable {σ₂₃ : 𝕜₂ →+* 𝕜₃} [RingHomIsometric σ₂₃]
variable {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomIsometric σ₁₃]
variable [AddCommGroup E] [AddCommGroup E₂] [AddCommGroup E₃]
variable [AddCommGroup F] [AddCommGroup G]
variable [Module 𝕜 E] [Module 𝕜₂ E₂] [Module 𝕜₃ E₃] [Module 𝕜 F] [Module 𝕜 G]
-- Porting note: even though this instance is found immediately by typeclass search,
-- it seems to be needed below!?
noncomputable instance smul_nnreal_real : SMul ℝ≥0 ℝ := inferInstance
variable [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ]
/-- Composition of a seminorm with a linear map is a seminorm. -/
def comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜 E :=
{ p.toAddGroupSeminorm.comp f.toAddMonoidHom with
toFun := fun x => p (f x)
-- Porting note: the `simp only` below used to be part of the `rw`.
-- I'm not sure why this change was needed, and am worried by it!
-- Note: #8386 had to change `map_smulₛₗ` to `map_smulₛₗ _`
smul' := fun _ _ => by simp only [map_smulₛₗ _]; rw [map_smul_eq_mul, RingHomIsometric.is_iso] }
#align seminorm.comp Seminorm.comp
theorem coe_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : ⇑(p.comp f) = p ∘ f :=
rfl
#align seminorm.coe_comp Seminorm.coe_comp
@[simp]
theorem comp_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) : (p.comp f) x = p (f x) :=
rfl
#align seminorm.comp_apply Seminorm.comp_apply
@[simp]
theorem comp_id (p : Seminorm 𝕜 E) : p.comp LinearMap.id = p :=
ext fun _ => rfl
#align seminorm.comp_id Seminorm.comp_id
@[simp]
theorem comp_zero (p : Seminorm 𝕜₂ E₂) : p.comp (0 : E →ₛₗ[σ₁₂] E₂) = 0 :=
ext fun _ => map_zero p
#align seminorm.comp_zero Seminorm.comp_zero
@[simp]
theorem zero_comp (f : E →ₛₗ[σ₁₂] E₂) : (0 : Seminorm 𝕜₂ E₂).comp f = 0 :=
ext fun _ => rfl
#align seminorm.zero_comp Seminorm.zero_comp
theorem comp_comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] (p : Seminorm 𝕜₃ E₃) (g : E₂ →ₛₗ[σ₂₃] E₃)
(f : E →ₛₗ[σ₁₂] E₂) : p.comp (g.comp f) = (p.comp g).comp f :=
ext fun _ => rfl
#align seminorm.comp_comp Seminorm.comp_comp
theorem add_comp (p q : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) :
(p + q).comp f = p.comp f + q.comp f :=
ext fun _ => rfl
#align seminorm.add_comp Seminorm.add_comp
theorem comp_add_le (p : Seminorm 𝕜₂ E₂) (f g : E →ₛₗ[σ₁₂] E₂) :
p.comp (f + g) ≤ p.comp f + p.comp g := fun _ => map_add_le_add p _ _
#align seminorm.comp_add_le Seminorm.comp_add_le
theorem smul_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : R) :
(c • p).comp f = c • p.comp f :=
ext fun _ => rfl
#align seminorm.smul_comp Seminorm.smul_comp
theorem comp_mono {p q : Seminorm 𝕜₂ E₂} (f : E →ₛₗ[σ₁₂] E₂) (hp : p ≤ q) : p.comp f ≤ q.comp f :=
fun _ => hp _
#align seminorm.comp_mono Seminorm.comp_mono
/-- The composition as an `AddMonoidHom`. -/
@[simps]
def pullback (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜₂ E₂ →+ Seminorm 𝕜 E where
toFun := fun p => p.comp f
map_zero' := zero_comp f
map_add' := fun p q => add_comp p q f
#align seminorm.pullback Seminorm.pullback
instance instOrderBot : OrderBot (Seminorm 𝕜 E) where
bot := 0
bot_le := apply_nonneg
@[simp]
theorem coe_bot : ⇑(⊥ : Seminorm 𝕜 E) = 0 :=
rfl
#align seminorm.coe_bot Seminorm.coe_bot
theorem bot_eq_zero : (⊥ : Seminorm 𝕜 E) = 0 :=
rfl
#align seminorm.bot_eq_zero Seminorm.bot_eq_zero
theorem smul_le_smul {p q : Seminorm 𝕜 E} {a b : ℝ≥0} (hpq : p ≤ q) (hab : a ≤ b) :
a • p ≤ b • q := by
simp_rw [le_def]
intro x
exact mul_le_mul hab (hpq x) (apply_nonneg p x) (NNReal.coe_nonneg b)
#align seminorm.smul_le_smul Seminorm.smul_le_smul
theorem finset_sup_apply (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) :
s.sup p x = ↑(s.sup fun i => ⟨p i x, apply_nonneg (p i) x⟩ : ℝ≥0) := by
induction' s using Finset.cons_induction_on with a s ha ih
· rw [Finset.sup_empty, Finset.sup_empty, coe_bot, _root_.bot_eq_zero, Pi.zero_apply]
norm_cast
· rw [Finset.sup_cons, Finset.sup_cons, coe_sup, sup_eq_max, Pi.sup_apply, sup_eq_max,
NNReal.coe_max, NNReal.coe_mk, ih]
#align seminorm.finset_sup_apply Seminorm.finset_sup_apply
theorem exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) {s : Finset ι} (hs : s.Nonempty) (x : E) :
∃ i ∈ s, s.sup p x = p i x := by
rcases Finset.exists_mem_eq_sup s hs (fun i ↦ (⟨p i x, apply_nonneg _ _⟩ : ℝ≥0)) with ⟨i, hi, hix⟩
rw [finset_sup_apply]
exact ⟨i, hi, congr_arg _ hix⟩
theorem zero_or_exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) :
s.sup p x = 0 ∨ ∃ i ∈ s, s.sup p x = p i x := by
rcases Finset.eq_empty_or_nonempty s with (rfl|hs)
· left; rfl
· right; exact exists_apply_eq_finset_sup p hs x
theorem finset_sup_smul (p : ι → Seminorm 𝕜 E) (s : Finset ι) (C : ℝ≥0) :
s.sup (C • p) = C • s.sup p := by
ext x
rw [smul_apply, finset_sup_apply, finset_sup_apply]
symm
exact congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.mul_finset_sup C s (fun i ↦ ⟨p i x, apply_nonneg _ _⟩))
theorem finset_sup_le_sum (p : ι → Seminorm 𝕜 E) (s : Finset ι) : s.sup p ≤ ∑ i ∈ s, p i := by
classical
refine Finset.sup_le_iff.mpr ?_
intro i hi
rw [Finset.sum_eq_sum_diff_singleton_add hi, le_add_iff_nonneg_left]
exact bot_le
#align seminorm.finset_sup_le_sum Seminorm.finset_sup_le_sum
theorem finset_sup_apply_le {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 ≤ a)
(h : ∀ i, i ∈ s → p i x ≤ a) : s.sup p x ≤ a := by
lift a to ℝ≥0 using ha
rw [finset_sup_apply, NNReal.coe_le_coe]
exact Finset.sup_le h
#align seminorm.finset_sup_apply_le Seminorm.finset_sup_apply_le
theorem le_finset_sup_apply {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {i : ι}
(hi : i ∈ s) : p i x ≤ s.sup p x :=
(Finset.le_sup hi : p i ≤ s.sup p) x
theorem finset_sup_apply_lt {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 < a)
(h : ∀ i, i ∈ s → p i x < a) : s.sup p x < a := by
lift a to ℝ≥0 using ha.le
rw [finset_sup_apply, NNReal.coe_lt_coe, Finset.sup_lt_iff]
· exact h
· exact NNReal.coe_pos.mpr ha
#align seminorm.finset_sup_apply_lt Seminorm.finset_sup_apply_lt
theorem norm_sub_map_le_sub (p : Seminorm 𝕜 E) (x y : E) : ‖p x - p y‖ ≤ p (x - y) :=
abs_sub_map_le_sub p x y
#align seminorm.norm_sub_map_le_sub Seminorm.norm_sub_map_le_sub
end Module
end SeminormedRing
section SeminormedCommRing
variable [SeminormedRing 𝕜] [SeminormedCommRing 𝕜₂]
variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂]
variable [AddCommGroup E] [AddCommGroup E₂] [Module 𝕜 E] [Module 𝕜₂ E₂]
theorem comp_smul (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) :
p.comp (c • f) = ‖c‖₊ • p.comp f :=
ext fun _ => by
rw [comp_apply, smul_apply, LinearMap.smul_apply, map_smul_eq_mul, NNReal.smul_def, coe_nnnorm,
smul_eq_mul, comp_apply]
#align seminorm.comp_smul Seminorm.comp_smul
theorem comp_smul_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) (x : E) :
p.comp (c • f) x = ‖c‖ * p (f x) :=
map_smul_eq_mul p _ _
#align seminorm.comp_smul_apply Seminorm.comp_smul_apply
end SeminormedCommRing
section NormedField
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {p q : Seminorm 𝕜 E} {x : E}
/-- Auxiliary lemma to show that the infimum of seminorms is well-defined. -/
theorem bddBelow_range_add : BddBelow (range fun u => p u + q (x - u)) :=
⟨0, by
rintro _ ⟨x, rfl⟩
dsimp; positivity⟩
#align seminorm.bdd_below_range_add Seminorm.bddBelow_range_add
noncomputable instance instInf : Inf (Seminorm 𝕜 E) where
inf p q :=
{ p.toAddGroupSeminorm ⊓ q.toAddGroupSeminorm with
toFun := fun x => ⨅ u : E, p u + q (x - u)
smul' := by
intro a x
obtain rfl | ha := eq_or_ne a 0
· rw [norm_zero, zero_mul, zero_smul]
refine
ciInf_eq_of_forall_ge_of_forall_gt_exists_lt
-- Porting note: the following was previously `fun i => by positivity`
(fun i => add_nonneg (apply_nonneg _ _) (apply_nonneg _ _))
fun x hx => ⟨0, by rwa [map_zero, sub_zero, map_zero, add_zero]⟩
simp_rw [Real.mul_iInf_of_nonneg (norm_nonneg a), mul_add, ← map_smul_eq_mul p, ←
map_smul_eq_mul q, smul_sub]
refine
Function.Surjective.iInf_congr ((a⁻¹ • ·) : E → E)
(fun u => ⟨a • u, inv_smul_smul₀ ha u⟩) fun u => ?_
rw [smul_inv_smul₀ ha] }
@[simp]
theorem inf_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊓ q) x = ⨅ u : E, p u + q (x - u) :=
rfl
#align seminorm.inf_apply Seminorm.inf_apply
noncomputable instance instLattice : Lattice (Seminorm 𝕜 E) :=
{ Seminorm.instSemilatticeSup with
inf := (· ⊓ ·)
inf_le_left := fun p q x =>
ciInf_le_of_le bddBelow_range_add x <| by
simp only [sub_self, map_zero, add_zero]; rfl
inf_le_right := fun p q x =>
ciInf_le_of_le bddBelow_range_add 0 <| by
simp only [sub_self, map_zero, zero_add, sub_zero]; rfl
le_inf := fun a b c hab hac x =>
le_ciInf fun u => (le_map_add_map_sub a _ _).trans <| add_le_add (hab _) (hac _) }
theorem smul_inf [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) :
r • (p ⊓ q) = r • p ⊓ r • q := by
ext
simp_rw [smul_apply, inf_apply, smul_apply, ← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def,
smul_eq_mul, Real.mul_iInf_of_nonneg (NNReal.coe_nonneg _), mul_add]
#align seminorm.smul_inf Seminorm.smul_inf
section Classical
open scoped Classical
/-- We define the supremum of an arbitrary subset of `Seminorm 𝕜 E` as follows:
* if `s` is `BddAbove` *as a set of functions `E → ℝ`* (that is, if `s` is pointwise bounded
above), we take the pointwise supremum of all elements of `s`, and we prove that it is indeed a
seminorm.
* otherwise, we take the zero seminorm `⊥`.
There are two things worth mentioning here:
* First, it is not trivial at first that `s` being bounded above *by a function* implies
being bounded above *as a seminorm*. We show this in `Seminorm.bddAbove_iff` by using
that the `Sup s` as defined here is then a bounding seminorm for `s`. So it is important to make
the case disjunction on `BddAbove ((↑) '' s : Set (E → ℝ))` and not `BddAbove s`.
* Since the pointwise `Sup` already gives `0` at points where a family of functions is
not bounded above, one could hope that just using the pointwise `Sup` would work here, without the
need for an additional case disjunction. As discussed on Zulip, this doesn't work because this can
give a function which does *not* satisfy the seminorm axioms (typically sub-additivity).
-/
noncomputable instance instSupSet : SupSet (Seminorm 𝕜 E) where
sSup s :=
if h : BddAbove ((↑) '' s : Set (E → ℝ)) then
{ toFun := ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ)
map_zero' := by
rw [iSup_apply, ← @Real.ciSup_const_zero s]
congr!
rename_i _ _ _ i
exact map_zero i.1
add_le' := fun x y => by
rcases h with ⟨q, hq⟩
obtain rfl | h := s.eq_empty_or_nonempty
· simp [Real.iSup_of_isEmpty]
haveI : Nonempty ↑s := h.coe_sort
simp only [iSup_apply]
refine ciSup_le fun i =>
((i : Seminorm 𝕜 E).add_le' x y).trans <| add_le_add
-- Porting note: `f` is provided to force `Subtype.val` to appear.
-- A type ascription on `_` would have also worked, but would have been more verbose.
(le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun x) ⟨q x, ?_⟩ i)
(le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun y) ⟨q y, ?_⟩ i)
<;> rw [mem_upperBounds, forall_mem_range]
<;> exact fun j => hq (mem_image_of_mem _ j.2) _
neg' := fun x => by
simp only [iSup_apply]
congr! 2
rename_i _ _ _ i
exact i.1.neg' _
smul' := fun a x => by
simp only [iSup_apply]
rw [← smul_eq_mul,
Real.smul_iSup_of_nonneg (norm_nonneg a) fun i : s => (i : Seminorm 𝕜 E) x]
congr!
rename_i _ _ _ i
exact i.1.smul' a x }
else ⊥
protected theorem coe_sSup_eq' {s : Set <| Seminorm 𝕜 E}
(hs : BddAbove ((↑) '' s : Set (E → ℝ))) : ↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) :=
congr_arg _ (dif_pos hs)
#align seminorm.coe_Sup_eq' Seminorm.coe_sSup_eq'
protected theorem bddAbove_iff {s : Set <| Seminorm 𝕜 E} :
BddAbove s ↔ BddAbove ((↑) '' s : Set (E → ℝ)) :=
⟨fun ⟨q, hq⟩ => ⟨q, forall_mem_image.2 fun p hp => hq hp⟩, fun H =>
⟨sSup s, fun p hp x => by
dsimp
rw [Seminorm.coe_sSup_eq' H, iSup_apply]
rcases H with ⟨q, hq⟩
exact
le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq (mem_image_of_mem _ i.2) x⟩ ⟨p, hp⟩⟩⟩
#align seminorm.bdd_above_iff Seminorm.bddAbove_iff
protected theorem bddAbove_range_iff {ι : Sort*} {p : ι → Seminorm 𝕜 E} :
BddAbove (range p) ↔ ∀ x, BddAbove (range fun i ↦ p i x) := by
rw [Seminorm.bddAbove_iff, ← range_comp, bddAbove_range_pi]; rfl
protected theorem coe_sSup_eq {s : Set <| Seminorm 𝕜 E} (hs : BddAbove s) :
↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) :=
Seminorm.coe_sSup_eq' (Seminorm.bddAbove_iff.mp hs)
#align seminorm.coe_Sup_eq Seminorm.coe_sSup_eq
protected theorem coe_iSup_eq {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) :
↑(⨆ i, p i) = ⨆ i, ((p i : Seminorm 𝕜 E) : E → ℝ) := by
rw [← sSup_range, Seminorm.coe_sSup_eq hp]
exact iSup_range' (fun p : Seminorm 𝕜 E => (p : E → ℝ)) p
#align seminorm.coe_supr_eq Seminorm.coe_iSup_eq
protected theorem sSup_apply {s : Set (Seminorm 𝕜 E)} (hp : BddAbove s) {x : E} :
(sSup s) x = ⨆ p : s, (p : E → ℝ) x := by
rw [Seminorm.coe_sSup_eq hp, iSup_apply]
protected theorem iSup_apply {ι : Sort*} {p : ι → Seminorm 𝕜 E}
(hp : BddAbove (range p)) {x : E} : (⨆ i, p i) x = ⨆ i, p i x := by
rw [Seminorm.coe_iSup_eq hp, iSup_apply]
protected theorem sSup_empty : sSup (∅ : Set (Seminorm 𝕜 E)) = ⊥ := by
ext
rw [Seminorm.sSup_apply bddAbove_empty, Real.iSup_of_isEmpty]
rfl
private theorem isLUB_sSup (s : Set (Seminorm 𝕜 E)) (hs₁ : BddAbove s) (hs₂ : s.Nonempty) :
IsLUB s (sSup s) := by
refine ⟨fun p hp x => ?_, fun p hp x => ?_⟩ <;> haveI : Nonempty ↑s := hs₂.coe_sort <;>
dsimp <;> rw [Seminorm.coe_sSup_eq hs₁, iSup_apply]
· rcases hs₁ with ⟨q, hq⟩
exact le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq i.2 x⟩ ⟨p, hp⟩
· exact ciSup_le fun q => hp q.2 x
/-- `Seminorm 𝕜 E` is a conditionally complete lattice.
Note that, while `inf`, `sup` and `sSup` have good definitional properties (corresponding to
the instances given here for `Inf`, `Sup` and `SupSet` respectively), `sInf s` is just
defined as the supremum of the lower bounds of `s`, which is not really useful in practice. If you
need to use `sInf` on seminorms, then you should probably provide a more workable definition first,
but this is unlikely to happen so we keep the "bad" definition for now. -/
noncomputable instance instConditionallyCompleteLattice :
ConditionallyCompleteLattice (Seminorm 𝕜 E) :=
conditionallyCompleteLatticeOfLatticeOfsSup (Seminorm 𝕜 E) Seminorm.isLUB_sSup
end Classical
end NormedField
/-! ### Seminorm ball -/
section SeminormedRing
variable [SeminormedRing 𝕜]
section AddCommGroup
variable [AddCommGroup E]
section SMul
variable [SMul 𝕜 E] (p : Seminorm 𝕜 E)
/-- The ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y` with
`p (y - x) < r`. -/
def ball (x : E) (r : ℝ) :=
{ y : E | p (y - x) < r }
#align seminorm.ball Seminorm.ball
/-- The closed ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y`
with `p (y - x) ≤ r`. -/
def closedBall (x : E) (r : ℝ) :=
{ y : E | p (y - x) ≤ r }
#align seminorm.closed_ball Seminorm.closedBall
variable {x y : E} {r : ℝ}
@[simp]
theorem mem_ball : y ∈ ball p x r ↔ p (y - x) < r :=
Iff.rfl
#align seminorm.mem_ball Seminorm.mem_ball
@[simp]
theorem mem_closedBall : y ∈ closedBall p x r ↔ p (y - x) ≤ r :=
Iff.rfl
#align seminorm.mem_closed_ball Seminorm.mem_closedBall
theorem mem_ball_self (hr : 0 < r) : x ∈ ball p x r := by simp [hr]
#align seminorm.mem_ball_self Seminorm.mem_ball_self
theorem mem_closedBall_self (hr : 0 ≤ r) : x ∈ closedBall p x r := by simp [hr]
#align seminorm.mem_closed_ball_self Seminorm.mem_closedBall_self
| Mathlib/Analysis/Seminorm.lean | 690 | 690 | theorem mem_ball_zero : y ∈ ball p 0 r ↔ p y < r := by | rw [mem_ball, sub_zero]
|
/-
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.SplittingField.Construction
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
import Mathlib.FieldTheory.Separable
import Mathlib.FieldTheory.NormalClosure
import Mathlib.RingTheory.Polynomial.SeparableDegree
/-!
# Separable degree
This file contains basics about the separable degree of a field extension.
## Main definitions
- `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`
(the algebraic closure of `F` is usually used in the literature, but our definition has the
advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F`
and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks.
**Remark:** if `E / F` is not algebraic, then this definition makes no mathematical sense,
and if it is infinite, then its cardinality doesn't behave as expected (namely, not equal to the
field extension degree of `separableClosure F E / F`). For example, if $F = \mathbb{Q}$ and
$E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$ is in bijection with
$\operatorname{Gal}(E/F)$, which is isomorphic to
$\mathbb{Z}_p^\times$, which is uncountable, while $[E:F]$ is countable.
**TODO:** prove or disprove that if `E / F` is algebraic and `Emb F E` is infinite, then
`Field.Emb F E` has cardinality `2 ^ Module.rank F (separableClosure F E)`.
- `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an algebraic extension
`E / F` of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic
closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense.
**Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E`
for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is
the (relative) separable closure `separableClosure F E` of `F` in `E`, which is not defined in
this file yet. Later we will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite,
then these two definitions coincide.
- `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
## Main results
- `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`:
a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. In particular, they have the same cardinality (so their
`Field.finSepDegree` are equal).
- `Field.embEquivOfAdjoinSplits`,
`Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F`
and whose minimal polynomial splits in `K`. In particular, they have the same cardinality.
- `Field.embEquivOfIsAlgClosed`,
`Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed.
In particular, they have the same cardinality.
- `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`:
if `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`.
In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$
(see also `FiniteDimensional.finrank_mul_finrank`).
- `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than
its degree.
- `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is
equal to its degree if and only if it is separable.
- `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree
is equal to the number of distinct roots of it over `E`.
- `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to
the number of distinct roots of it over any algebraically closed field.
- `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic
`q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree.
- `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable
contraction, then its separable degree is equal to its separable contraction degree.
- `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible
polynomial divides its degree.
- `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of
`F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`.
- `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then
the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a
separable element.
- `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides
the degree of `E / F`.
- `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller
than the degree of `E / F`.
- `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree
is equal to its degree if and only if it is a separable extension.
- `IntermediateField.isSeparable_adjoin_simple_iff_separable`: `F⟮x⟯ / F` is a separable extension
if and only if `x` is a separable element.
- `IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also separable.
## Tags
separable degree, degree, polynomial
-/
open scoped Classical Polynomial
open FiniteDimensional 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]
namespace Field
/-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure
of `E`. -/
def Emb := E →ₐ[F] AlgebraicClosure E
/-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F`
is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`,
as a natural number. It is defined to be zero if there are infinitely many of them.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/
def finSepDegree : ℕ := Nat.card (Emb F E)
instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩
instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) :=
⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩
/-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. -/
def embEquivOfEquiv (i : E ≃ₐ[F] K) :
Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by
let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra
have : Algebra.IsAlgebraic E K := by
constructor
intro x
have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x)
rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h
simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h
apply AlgEquiv.restrictScalars (R := F) (S := E)
exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)
/-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree`
over `F`. -/
theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) :
finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i)
@[simp]
theorem finSepDegree_self : finSepDegree F F = 1 := by
have : Cardinal.mk (Emb F F) = 1 := le_antisymm
(Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton)
(Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _)
rw [finSepDegree, Nat.card, this, Cardinal.one_toNat]
end Field
namespace IntermediateField
@[simp]
theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by
rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self]
section Tower
variable {F}
variable [Algebra E K] [IsScalarTower F E K]
@[simp]
theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E :=
finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F)
@[simp]
theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K :=
finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F)
end Tower
end IntermediateField
namespace Field
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every
element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`.
Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of
`IntermediateField.nonempty_algHom_of_adjoin_splits`. -/
def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
Emb F E ≃ (E →ₐ[F] K) :=
have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) :=
(hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1)
have halg := (topEquiv (F := F) (E := E)).isAlgebraic
Classical.choice <| Function.Embedding.antisymm
(halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F (S := S) hK (hS ▸ mem_top)) _)
(halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _)
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K`
if `E = F(S)` such that every element
`s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/
theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK)
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic
and `K / F` is algebraically closed. -/
def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
Emb F E ≃ (E →ₐ[F] K) :=
embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦
⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number,
when `E / F` is algebraic and `K / F` is algebraically closed. -/
theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K)
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection
`Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/
def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
Emb F E × Emb E K ≃ Emb F K :=
let e : ∀ f : E →ₐ[F] AlgebraicClosure K,
@AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦
(@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm
(algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans
(Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <|
fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <|
(IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K)
(AlgebraicClosure E)).restrictScalars F).symm
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their
separable degrees satisfy the tower law
$[E:F]_s [K:E]_s = [K:F]_s$. See also `FiniteDimensional.finrank_mul_finrank`. -/
theorem finSepDegree_mul_finSepDegree_of_isAlgebraic
[Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
finSepDegree F E * finSepDegree E K = finSepDegree F K := by
simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K)
end Field
namespace Polynomial
variable {F E}
variable (f : F[X])
/-- The separable degree `Polynomial.natSepDegree` of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
This is similar to `Polynomial.natDegree` but not to `Polynomial.degree`, namely, the separable
degree of `0` is `0`, not negative infinity. -/
def natSepDegree : ℕ := (f.aroots f.SplittingField).toFinset.card
/-- The separable degree of a polynomial is smaller than its degree. -/
theorem natSepDegree_le_natDegree : f.natSepDegree ≤ f.natDegree := by
have := f.map (algebraMap F f.SplittingField) |>.card_roots'
rw [← aroots_def, natDegree_map] at this
exact (f.aroots f.SplittingField).toFinset_card_le.trans this
@[simp]
theorem natSepDegree_X_sub_C (x : F) : (X - C x).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X_sub_C, Multiset.toFinset_singleton, Finset.card_singleton]
@[simp]
theorem natSepDegree_X : (X : F[X]).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X, Multiset.toFinset_singleton, Finset.card_singleton]
/-- A constant polynomial has zero separable degree. -/
theorem natSepDegree_eq_zero (h : f.natDegree = 0) : f.natSepDegree = 0 := by
linarith only [natSepDegree_le_natDegree f, h]
@[simp]
theorem natSepDegree_C (x : F) : (C x).natSepDegree = 0 := natSepDegree_eq_zero _ (natDegree_C _)
@[simp]
theorem natSepDegree_zero : (0 : F[X]).natSepDegree = 0 := by
rw [← C_0, natSepDegree_C]
@[simp]
theorem natSepDegree_one : (1 : F[X]).natSepDegree = 0 := by
rw [← C_1, natSepDegree_C]
/-- A non-constant polynomial has non-zero separable degree. -/
| Mathlib/FieldTheory/SeparableDegree.lean | 299 | 303 | theorem natSepDegree_ne_zero (h : f.natDegree ≠ 0) : f.natSepDegree ≠ 0 := by |
rw [natSepDegree, ne_eq, Finset.card_eq_zero, ← ne_eq, ← Finset.nonempty_iff_ne_empty]
use rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)
rw [Multiset.mem_toFinset, mem_aroots]
exact ⟨ne_of_apply_ne _ h, map_rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)⟩
|
/-
Copyright (c) 2021 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Damiano Testa, Jens Wagemaker
-/
import Mathlib.Algebra.MonoidAlgebra.Division
import Mathlib.Algebra.Polynomial.Degree.Definitions
import Mathlib.Algebra.Polynomial.Induction
import Mathlib.Algebra.Polynomial.EraseLead
import Mathlib.Order.Interval.Finset.Nat
#align_import data.polynomial.inductions from "leanprover-community/mathlib"@"57e09a1296bfb4330ddf6624f1028ba186117d82"
/-!
# Induction on polynomials
This file contains lemmas dealing with different flavours of induction on polynomials.
-/
noncomputable section
open Polynomial
open Finset
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : ℕ}
section Semiring
variable [Semiring R] {p q : R[X]}
/-- `divX p` returns a polynomial `q` such that `q * X + C (p.coeff 0) = p`.
It can be used in a semiring where the usual division algorithm is not possible -/
def divX (p : R[X]) : R[X] :=
⟨AddMonoidAlgebra.divOf p.toFinsupp 1⟩
set_option linter.uppercaseLean3 false in
#align polynomial.div_X Polynomial.divX
@[simp]
theorem coeff_divX : (divX p).coeff n = p.coeff (n + 1) := by
rw [add_comm]; cases p; rfl
set_option linter.uppercaseLean3 false in
#align polynomial.coeff_div_X Polynomial.coeff_divX
theorem divX_mul_X_add (p : R[X]) : divX p * X + C (p.coeff 0) = p :=
ext <| by rintro ⟨_ | _⟩ <;> simp [coeff_C, Nat.succ_ne_zero, coeff_mul_X]
set_option linter.uppercaseLean3 false in
#align polynomial.div_X_mul_X_add Polynomial.divX_mul_X_add
@[simp]
theorem X_mul_divX_add (p : R[X]) : X * divX p + C (p.coeff 0) = p :=
ext <| by rintro ⟨_ | _⟩ <;> simp [coeff_C, Nat.succ_ne_zero, coeff_mul_X]
@[simp]
theorem divX_C (a : R) : divX (C a) = 0 :=
ext fun n => by simp [coeff_divX, coeff_C, Finsupp.single_eq_of_ne _]
set_option linter.uppercaseLean3 false in
#align polynomial.div_X_C Polynomial.divX_C
theorem divX_eq_zero_iff : divX p = 0 ↔ p = C (p.coeff 0) :=
⟨fun h => by simpa [eq_comm, h] using divX_mul_X_add p, fun h => by rw [h, divX_C]⟩
set_option linter.uppercaseLean3 false in
#align polynomial.div_X_eq_zero_iff Polynomial.divX_eq_zero_iff
theorem divX_add : divX (p + q) = divX p + divX q :=
ext <| by simp
set_option linter.uppercaseLean3 false in
#align polynomial.div_X_add Polynomial.divX_add
@[simp]
theorem divX_zero : divX (0 : R[X]) = 0 := leadingCoeff_eq_zero.mp rfl
@[simp]
theorem divX_one : divX (1 : R[X]) = 0 := by
ext
simpa only [coeff_divX, coeff_zero] using coeff_one
@[simp]
theorem divX_C_mul : divX (C a * p) = C a * divX p := by
ext
simp
theorem divX_X_pow : divX (X ^ n : R[X]) = if (n = 0) then 0 else X ^ (n - 1) := by
cases n
· simp
· ext n
simp [coeff_X_pow]
/-- `divX` as an additive homomorphism. -/
noncomputable
def divX_hom : R[X] →+ R[X] :=
{ toFun := divX
map_zero' := divX_zero
map_add' := fun _ _ => divX_add }
@[simp] theorem divX_hom_toFun : divX_hom p = divX p := rfl
theorem natDegree_divX_eq_natDegree_tsub_one : p.divX.natDegree = p.natDegree - 1 := by
apply map_natDegree_eq_sub (φ := divX_hom)
· intro f
simpa [divX_hom, divX_eq_zero_iff] using eq_C_of_natDegree_eq_zero
· intros n c c0
rw [← C_mul_X_pow_eq_monomial, divX_hom_toFun, divX_C_mul, divX_X_pow]
split_ifs with n0
· simp [n0]
· exact natDegree_C_mul_X_pow (n - 1) c c0
theorem natDegree_divX_le : p.divX.natDegree ≤ p.natDegree :=
natDegree_divX_eq_natDegree_tsub_one.trans_le (Nat.pred_le _)
theorem divX_C_mul_X_pow : divX (C a * X ^ n) = if n = 0 then 0 else C a * X ^ (n - 1) := by
simp only [divX_C_mul, divX_X_pow, mul_ite, mul_zero]
theorem degree_divX_lt (hp0 : p ≠ 0) : (divX p).degree < p.degree := by
haveI := Nontrivial.of_polynomial_ne hp0
calc
degree (divX p) < (divX p * X + C (p.coeff 0)).degree :=
if h : degree p ≤ 0 then by
have h' : C (p.coeff 0) ≠ 0 := by rwa [← eq_C_of_degree_le_zero h]
rw [eq_C_of_degree_le_zero h, divX_C, degree_zero, zero_mul, zero_add]
exact lt_of_le_of_ne bot_le (Ne.symm (mt degree_eq_bot.1 <| by simpa using h'))
else by
have hXp0 : divX p ≠ 0 := by
simpa [divX_eq_zero_iff, -not_le, degree_le_zero_iff] using h
have : leadingCoeff (divX p) * leadingCoeff X ≠ 0 := by simpa
have : degree (C (p.coeff 0)) < degree (divX p * X) :=
calc
degree (C (p.coeff 0)) ≤ 0 := degree_C_le
_ < 1 := by decide
_ = degree (X : R[X]) := degree_X.symm
_ ≤ degree (divX p * X) := by
rw [← zero_add (degree X), degree_mul' this]
exact add_le_add
(by rw [zero_le_degree_iff, Ne, divX_eq_zero_iff]
exact fun h0 => h (h0.symm ▸ degree_C_le))
le_rfl
rw [degree_add_eq_left_of_degree_lt this]; exact degree_lt_degree_mul_X hXp0
_ = degree p := congr_arg _ (divX_mul_X_add _)
set_option linter.uppercaseLean3 false in
#align polynomial.degree_div_X_lt Polynomial.degree_divX_lt
/-- An induction principle for polynomials, valued in Sort* instead of Prop. -/
@[elab_as_elim]
noncomputable def recOnHorner {M : R[X] → Sort*} (p : R[X]) (M0 : M 0)
(MC : ∀ p a, coeff p 0 = 0 → a ≠ 0 → M p → M (p + C a))
(MX : ∀ p, p ≠ 0 → M p → M (p * X)) : M p :=
letI := Classical.decEq R
if hp : p = 0 then hp ▸ M0
else by
have wf : degree (divX p) < degree p := degree_divX_lt hp
rw [← divX_mul_X_add p] at *
exact
if hcp0 : coeff p 0 = 0 then by
rw [hcp0, C_0, add_zero]
exact
MX _ (fun h : divX p = 0 => by simp [h, hcp0] at hp) (recOnHorner (divX p) M0 MC MX)
else
MC _ _ (coeff_mul_X_zero _) hcp0
(if hpX0 : divX p = 0 then show M (divX p * X) by rw [hpX0, zero_mul]; exact M0
else MX (divX p) hpX0 (recOnHorner _ M0 MC MX))
termination_by p.degree
#align polynomial.rec_on_horner Polynomial.recOnHorner
/-- A property holds for all polynomials of positive `degree` with coefficients in a semiring `R`
if it holds for
* `a * X`, with `a ∈ R`,
* `p * X`, with `p ∈ R[X]`,
* `p + a`, with `a ∈ R`, `p ∈ R[X]`,
with appropriate restrictions on each term.
See `natDegree_ne_zero_induction_on` for a similar statement involving no explicit multiplication.
-/
@[elab_as_elim]
theorem degree_pos_induction_on {P : R[X] → Prop} (p : R[X]) (h0 : 0 < degree p)
(hC : ∀ {a}, a ≠ 0 → P (C a * X)) (hX : ∀ {p}, 0 < degree p → P p → P (p * X))
(hadd : ∀ {p} {a}, 0 < degree p → P p → P (p + C a)) : P p :=
recOnHorner p (fun h => by rw [degree_zero] at h; exact absurd h (by decide))
(fun p a _ _ ih h0 =>
have : 0 < degree p :=
lt_of_not_ge fun h =>
not_lt_of_ge degree_C_le <| by rwa [eq_C_of_degree_le_zero h, ← C_add] at h0
hadd this (ih this))
(fun p _ ih h0' =>
if h0 : 0 < degree p then hX h0 (ih h0)
else by
rw [eq_C_of_degree_le_zero (le_of_not_gt h0)] at h0' ⊢
exact hC fun h : coeff p 0 = 0 => by simp [h, Nat.not_lt_zero] at h0')
h0
#align polynomial.degree_pos_induction_on Polynomial.degree_pos_induction_on
/-- A property holds for all polynomials of non-zero `natDegree` with coefficients in a
semiring `R` if it holds for
* `p + a`, with `a ∈ R`, `p ∈ R[X]`,
* `p + q`, with `p, q ∈ R[X]`,
* monomials with nonzero coefficient and non-zero exponent,
with appropriate restrictions on each term.
Note that multiplication is "hidden" in the assumption on monomials, so there is no explicit
multiplication in the statement.
See `degree_pos_induction_on` for a similar statement involving more explicit multiplications.
-/
@[elab_as_elim]
| Mathlib/Algebra/Polynomial/Inductions.lean | 207 | 228 | theorem natDegree_ne_zero_induction_on {M : R[X] → Prop} {f : R[X]} (f0 : f.natDegree ≠ 0)
(h_C_add : ∀ {a p}, M p → M (C a + p)) (h_add : ∀ {p q}, M p → M q → M (p + q))
(h_monomial : ∀ {n : ℕ} {a : R}, a ≠ 0 → n ≠ 0 → M (monomial n a)) : M f := by |
suffices f.natDegree = 0 ∨ M f from Or.recOn this (fun h => (f0 h).elim) id
refine Polynomial.induction_on f ?_ ?_ ?_
· exact fun a => Or.inl (natDegree_C _)
· rintro p q (hp | hp) (hq | hq)
· refine Or.inl ?_
rw [eq_C_of_natDegree_eq_zero hp, eq_C_of_natDegree_eq_zero hq, ← C_add, natDegree_C]
· refine Or.inr ?_
rw [eq_C_of_natDegree_eq_zero hp]
exact h_C_add hq
· refine Or.inr ?_
rw [eq_C_of_natDegree_eq_zero hq, add_comm]
exact h_C_add hp
· exact Or.inr (h_add hp hq)
· intro n a _
by_cases a0 : a = 0
· exact Or.inl (by rw [a0, C_0, zero_mul, natDegree_zero])
· refine Or.inr ?_
rw [C_mul_X_pow_eq_monomial]
exact h_monomial a0 n.succ_ne_zero
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Data.Complex.Abs
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Nat.Choose.Sum
#align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb"
/-!
# Exponential, trigonometric and hyperbolic trigonometric functions
This file contains the definitions of the real and complex exponential, sine, cosine, tangent,
hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions.
-/
open CauSeq Finset IsAbsoluteValue
open scoped Classical ComplexConjugate
namespace Complex
theorem isCauSeq_abs_exp (z : ℂ) :
IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) :=
let ⟨n, hn⟩ := exists_nat_gt (abs z)
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn
IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff hn0, one_mul]) fun m hm => by
rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div,
mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
#align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_abs_exp z).of_abv
#align complex.is_cau_exp Complex.isCauSeq_exp
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
-- Porting note (#11180): removed `@[pp_nodot]`
def exp' (z : ℂ) : CauSeq ℂ Complex.abs :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
#align complex.exp' Complex.exp'
/-- The complex exponential function, defined via its Taylor series -/
-- Porting note (#11180): removed `@[pp_nodot]`
-- Porting note: removed `irreducible` attribute, so I can prove things
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
#align complex.exp Complex.exp
/-- The complex sine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def sin (z : ℂ) : ℂ :=
(exp (-z * I) - exp (z * I)) * I / 2
#align complex.sin Complex.sin
/-- The complex cosine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def cos (z : ℂ) : ℂ :=
(exp (z * I) + exp (-z * I)) / 2
#align complex.cos Complex.cos
/-- The complex tangent function, defined as `sin z / cos z` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def tan (z : ℂ) : ℂ :=
sin z / cos z
#align complex.tan Complex.tan
/-- The complex cotangent function, defined as `cos z / sin z` -/
def cot (z : ℂ) : ℂ :=
cos z / sin z
/-- The complex hyperbolic sine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def sinh (z : ℂ) : ℂ :=
(exp z - exp (-z)) / 2
#align complex.sinh Complex.sinh
/-- The complex hyperbolic cosine function, defined via `exp` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def cosh (z : ℂ) : ℂ :=
(exp z + exp (-z)) / 2
#align complex.cosh Complex.cosh
/-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/
-- Porting note (#11180): removed `@[pp_nodot]`
def tanh (z : ℂ) : ℂ :=
sinh z / cosh z
#align complex.tanh Complex.tanh
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
#align real.exp Real.exp
/-- The real sine function, defined as the real part of the complex sine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def sin (x : ℝ) : ℝ :=
(sin x).re
#align real.sin Real.sin
/-- The real cosine function, defined as the real part of the complex cosine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def cos (x : ℝ) : ℝ :=
(cos x).re
#align real.cos Real.cos
/-- The real tangent function, defined as the real part of the complex tangent -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def tan (x : ℝ) : ℝ :=
(tan x).re
#align real.tan Real.tan
/-- The real cotangent function, defined as the real part of the complex cotangent -/
nonrec def cot (x : ℝ) : ℝ :=
(cot x).re
/-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def sinh (x : ℝ) : ℝ :=
(sinh x).re
#align real.sinh Real.sinh
/-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def cosh (x : ℝ) : ℝ :=
(cosh x).re
#align real.cosh Real.cosh
/-- The real hypebolic tangent function, defined as the real part of
the complex hyperbolic tangent -/
-- Porting note (#11180): removed `@[pp_nodot]`
nonrec def tanh (x : ℝ) : ℝ :=
(tanh x).re
#align real.tanh Real.tanh
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- Porting note: ε0 : ε > 0 but goal is _ < ε
cases' j with j j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
#align complex.exp_zero Complex.exp_zero
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y)
#align complex.exp_add Complex.exp_add
-- Porting note (#11445): new definition
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp (Multiplicative.toAdd z),
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
#align complex.exp_list_sum Complex.exp_list_sum
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
#align complex.exp_multiset_sum Complex.exp_multiset_sum
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
#align complex.exp_sum Complex.exp_sum
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
#align complex.exp_nat_mul Complex.exp_nat_mul
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp
#align complex.exp_ne_zero Complex.exp_ne_zero
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)]
#align complex.exp_neg Complex.exp_neg
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
#align complex.exp_sub Complex.exp_sub
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
#align complex.exp_int_mul Complex.exp_int_mul
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
#align complex.exp_conj Complex.exp_conj
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
#align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
#align complex.of_real_exp Complex.ofReal_exp
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
#align complex.exp_of_real_im Complex.exp_ofReal_im
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
#align complex.exp_of_real_re Complex.exp_ofReal_re
theorem two_sinh : 2 * sinh x = exp x - exp (-x) :=
mul_div_cancel₀ _ two_ne_zero
#align complex.two_sinh Complex.two_sinh
theorem two_cosh : 2 * cosh x = exp x + exp (-x) :=
mul_div_cancel₀ _ two_ne_zero
#align complex.two_cosh Complex.two_cosh
@[simp]
theorem sinh_zero : sinh 0 = 0 := by simp [sinh]
#align complex.sinh_zero Complex.sinh_zero
@[simp]
theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul]
#align complex.sinh_neg Complex.sinh_neg
private theorem sinh_add_aux {a b c d : ℂ} :
(a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring
theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ←
mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add,
mul_left_comm, two_cosh, ← mul_assoc, two_cosh]
exact sinh_add_aux
#align complex.sinh_add Complex.sinh_add
@[simp]
theorem cosh_zero : cosh 0 = 1 := by simp [cosh]
#align complex.cosh_zero Complex.cosh_zero
@[simp]
theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg]
#align complex.cosh_neg Complex.cosh_neg
private theorem cosh_add_aux {a b c d : ℂ} :
(a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring
theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ←
mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add,
mul_left_comm, two_cosh, mul_left_comm, two_sinh]
exact cosh_add_aux
#align complex.cosh_add Complex.cosh_add
theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by
simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg]
#align complex.sinh_sub Complex.sinh_sub
theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by
simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg]
#align complex.cosh_sub Complex.cosh_sub
theorem sinh_conj : sinh (conj x) = conj (sinh x) := by
rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀]
-- Porting note: not nice
simp [← one_add_one_eq_two]
#align complex.sinh_conj Complex.sinh_conj
@[simp]
theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x :=
conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal]
#align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re
@[simp, norm_cast]
theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x :=
ofReal_sinh_ofReal_re _
#align complex.of_real_sinh Complex.ofReal_sinh
@[simp]
| Mathlib/Data/Complex/Exponential.lean | 350 | 350 | theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by | rw [← ofReal_sinh_ofReal_re, ofReal_im]
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Topology.Algebra.Polynomial
import Mathlib.Topology.ContinuousFunction.Algebra
import Mathlib.Topology.UnitInterval
import Mathlib.Algebra.Star.Subalgebra
#align_import topology.continuous_function.polynomial from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64"
/-!
# Constructions relating polynomial functions and continuous functions.
## Main definitions
* `Polynomial.toContinuousMapOn p X`: for `X : Set R`, interprets a polynomial `p`
as a bundled continuous function in `C(X, R)`.
* `Polynomial.toContinuousMapOnAlgHom`: the same, as an `R`-algebra homomorphism.
* `polynomialFunctions (X : Set R) : Subalgebra R C(X, R)`: polynomial functions as a subalgebra.
* `polynomialFunctions_separatesPoints (X : Set R) : (polynomialFunctions X).SeparatesPoints`:
the polynomial functions separate points.
-/
variable {R : Type*}
open Polynomial
namespace Polynomial
section
variable [Semiring R] [TopologicalSpace R] [TopologicalSemiring R]
/--
Every polynomial with coefficients in a topological semiring gives a (bundled) continuous function.
-/
@[simps]
def toContinuousMap (p : R[X]) : C(R, R) :=
⟨fun x : R => p.eval x, by fun_prop⟩
#align polynomial.to_continuous_map Polynomial.toContinuousMap
open ContinuousMap in
lemma toContinuousMap_X_eq_id : X.toContinuousMap = .id R := by
ext; simp
/-- A polynomial as a continuous function,
with domain restricted to some subset of the semiring of coefficients.
(This is particularly useful when restricting to compact sets, e.g. `[0,1]`.)
-/
@[simps]
def toContinuousMapOn (p : R[X]) (X : Set R) : C(X, R) :=
-- Porting note: Old proof was `⟨fun x : X => p.toContinuousMap x, by continuity⟩`
⟨fun x : X => p.toContinuousMap x, Continuous.comp (by continuity) (by continuity)⟩
#align polynomial.to_continuous_map_on Polynomial.toContinuousMapOn
open ContinuousMap in
lemma toContinuousMapOn_X_eq_restrict_id (s : Set R) :
X.toContinuousMapOn s = restrict s (.id R) := by
ext; simp
-- TODO some lemmas about when `toContinuousMapOn` is injective?
end
section
variable {α : Type*} [TopologicalSpace α] [CommSemiring R] [TopologicalSpace R]
[TopologicalSemiring R]
@[simp]
theorem aeval_continuousMap_apply (g : R[X]) (f : C(α, R)) (x : α) :
((Polynomial.aeval f) g) x = g.eval (f x) := by
refine Polynomial.induction_on' g ?_ ?_
· intro p q hp hq
simp [hp, hq]
· intro n a
simp [Pi.pow_apply]
#align polynomial.aeval_continuous_map_apply Polynomial.aeval_continuousMap_apply
end
noncomputable section
variable [CommSemiring R] [TopologicalSpace R] [TopologicalSemiring R]
/-- The algebra map from `R[X]` to continuous functions `C(R, R)`.
-/
@[simps]
def toContinuousMapAlgHom : R[X] →ₐ[R] C(R, R) where
toFun p := p.toContinuousMap
map_zero' := by
ext
simp
map_add' _ _ := by
ext
simp
map_one' := by
ext
simp
map_mul' _ _ := by
ext
simp
commutes' _ := by
ext
simp [Algebra.algebraMap_eq_smul_one]
#align polynomial.to_continuous_map_alg_hom Polynomial.toContinuousMapAlgHom
/-- The algebra map from `R[X]` to continuous functions `C(X, R)`, for any subset `X` of `R`.
-/
@[simps]
def toContinuousMapOnAlgHom (X : Set R) : R[X] →ₐ[R] C(X, R) where
toFun p := p.toContinuousMapOn X
map_zero' := by
ext
simp
map_add' _ _ := by
ext
simp
map_one' := by
ext
simp
map_mul' _ _ := by
ext
simp
commutes' _ := by
ext
simp [Algebra.algebraMap_eq_smul_one]
#align polynomial.to_continuous_map_on_alg_hom Polynomial.toContinuousMapOnAlgHom
end
end Polynomial
section
variable [CommSemiring R] [TopologicalSpace R] [TopologicalSemiring R]
/--
The subalgebra of polynomial functions in `C(X, R)`, for `X` a subset of some topological semiring
`R`.
-/
noncomputable -- Porting note: added noncomputable
def polynomialFunctions (X : Set R) : Subalgebra R C(X, R) :=
(⊤ : Subalgebra R R[X]).map (Polynomial.toContinuousMapOnAlgHom X)
#align polynomial_functions polynomialFunctions
@[simp]
theorem polynomialFunctions_coe (X : Set R) :
(polynomialFunctions X : Set C(X, R)) = Set.range (Polynomial.toContinuousMapOnAlgHom X) := by
ext
simp [polynomialFunctions]
#align polynomial_functions_coe polynomialFunctions_coe
-- TODO:
-- if `f : R → R` is an affine equivalence, then pulling back along `f`
-- induces a normed algebra isomorphism between `polynomialFunctions X` and
-- `polynomialFunctions (f ⁻¹' X)`, intertwining the pullback along `f` of `C(R, R)` to itself.
theorem polynomialFunctions_separatesPoints (X : Set R) : (polynomialFunctions X).SeparatesPoints :=
fun x y h => by
-- We use `Polynomial.X`, then clean up.
refine ⟨_, ⟨⟨_, ⟨⟨Polynomial.X, ⟨Algebra.mem_top, rfl⟩⟩, rfl⟩⟩, ?_⟩⟩
dsimp; simp only [Polynomial.eval_X]
exact fun h' => h (Subtype.ext h')
#align polynomial_functions_separates_points polynomialFunctions_separatesPoints
open unitInterval
open ContinuousMap
/-- The preimage of polynomials on `[0,1]` under the pullback map by `x ↦ (b-a) * x + a`
is the polynomials on `[a,b]`. -/
| Mathlib/Topology/ContinuousFunction/Polynomial.lean | 177 | 215 | theorem polynomialFunctions.comap_compRightAlgHom_iccHomeoI (a b : ℝ) (h : a < b) :
(polynomialFunctions I).comap (compRightAlgHom ℝ ℝ (iccHomeoI a b h).symm.toContinuousMap) =
polynomialFunctions (Set.Icc a b) := by |
ext f
fconstructor
· rintro ⟨p, ⟨-, w⟩⟩
rw [DFunLike.ext_iff] at w
dsimp at w
let q := p.comp ((b - a)⁻¹ • Polynomial.X + Polynomial.C (-a * (b - a)⁻¹))
refine ⟨q, ⟨?_, ?_⟩⟩
· simp
· ext x
simp only [q, neg_mul, RingHom.map_neg, RingHom.map_mul, AlgHom.coe_toRingHom,
Polynomial.eval_X, Polynomial.eval_neg, Polynomial.eval_C, Polynomial.eval_smul,
smul_eq_mul, Polynomial.eval_mul, Polynomial.eval_add, Polynomial.coe_aeval_eq_eval,
Polynomial.eval_comp, Polynomial.toContinuousMapOnAlgHom_apply,
Polynomial.toContinuousMapOn_apply, Polynomial.toContinuousMap_apply]
convert w ⟨_, _⟩
· ext
simp only [iccHomeoI_symm_apply_coe, Subtype.coe_mk]
replace h : b - a ≠ 0 := sub_ne_zero_of_ne h.ne.symm
simp only [mul_add]
field_simp
ring
· change _ + _ ∈ I
rw [mul_comm (b - a)⁻¹, ← neg_mul, ← add_mul, ← sub_eq_add_neg]
have w₁ : 0 < (b - a)⁻¹ := inv_pos.mpr (sub_pos.mpr h)
have w₂ : 0 ≤ (x : ℝ) - a := sub_nonneg.mpr x.2.1
have w₃ : (x : ℝ) - a ≤ b - a := sub_le_sub_right x.2.2 a
fconstructor
· exact mul_nonneg w₂ (le_of_lt w₁)
· rw [← div_eq_mul_inv, div_le_one (sub_pos.mpr h)]
exact w₃
· rintro ⟨p, ⟨-, rfl⟩⟩
let q := p.comp ((b - a) • Polynomial.X + Polynomial.C a)
refine ⟨q, ⟨?_, ?_⟩⟩
· simp
· ext x
simp [q, mul_comm]
|
/-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Yury Kudryashov
-/
import Mathlib.Algebra.Star.Order
import Mathlib.Topology.Instances.NNReal
import Mathlib.Topology.Order.MonotoneContinuity
#align_import data.real.sqrt from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004"
/-!
# Square root of a real number
In this file we define
* `NNReal.sqrt` to be the square root of a nonnegative real number.
* `Real.sqrt` to be the square root of a real number, defined to be zero on negative numbers.
Then we prove some basic properties of these functions.
## Implementation notes
We define `NNReal.sqrt` as the noncomputable inverse to the function `x ↦ x * x`. We use general
theory of inverses of strictly monotone functions to prove that `NNReal.sqrt x` exists. As a side
effect, `NNReal.sqrt` is a bundled `OrderIso`, so for `NNReal` numbers we get continuity as well as
theorems like `NNReal.sqrt x ≤ y ↔ x ≤ y * y` for free.
Then we define `Real.sqrt x` to be `NNReal.sqrt (Real.toNNReal x)`.
## Tags
square root
-/
open Set Filter
open scoped Filter NNReal Topology
namespace NNReal
variable {x y : ℝ≥0}
/-- Square root of a nonnegative real number. -/
-- Porting note: was @[pp_nodot]
noncomputable def sqrt : ℝ≥0 ≃o ℝ≥0 :=
OrderIso.symm <| powOrderIso 2 two_ne_zero
#align nnreal.sqrt NNReal.sqrt
@[simp] lemma sq_sqrt (x : ℝ≥0) : sqrt x ^ 2 = x := sqrt.symm_apply_apply _
#align nnreal.sq_sqrt NNReal.sq_sqrt
@[simp] lemma sqrt_sq (x : ℝ≥0) : sqrt (x ^ 2) = x := sqrt.apply_symm_apply _
#align nnreal.sqrt_sq NNReal.sqrt_sq
@[simp] lemma mul_self_sqrt (x : ℝ≥0) : sqrt x * sqrt x = x := by rw [← sq, sq_sqrt]
#align nnreal.mul_self_sqrt NNReal.mul_self_sqrt
@[simp] lemma sqrt_mul_self (x : ℝ≥0) : sqrt (x * x) = x := by rw [← sq, sqrt_sq]
#align nnreal.sqrt_mul_self NNReal.sqrt_mul_self
lemma sqrt_le_sqrt : sqrt x ≤ sqrt y ↔ x ≤ y := sqrt.le_iff_le
#align nnreal.sqrt_le_sqrt_iff NNReal.sqrt_le_sqrt
lemma sqrt_lt_sqrt : sqrt x < sqrt y ↔ x < y := sqrt.lt_iff_lt
#align nnreal.sqrt_lt_sqrt_iff NNReal.sqrt_lt_sqrt
lemma sqrt_eq_iff_eq_sq : sqrt x = y ↔ x = y ^ 2 := sqrt.toEquiv.apply_eq_iff_eq_symm_apply
#align nnreal.sqrt_eq_iff_sq_eq NNReal.sqrt_eq_iff_eq_sq
lemma sqrt_le_iff_le_sq : sqrt x ≤ y ↔ x ≤ y ^ 2 := sqrt.to_galoisConnection _ _
#align nnreal.sqrt_le_iff NNReal.sqrt_le_iff_le_sq
lemma le_sqrt_iff_sq_le : x ≤ sqrt y ↔ x ^ 2 ≤ y := (sqrt.symm.to_galoisConnection _ _).symm
#align nnreal.le_sqrt_iff NNReal.le_sqrt_iff_sq_le
-- 2024-02-14
@[deprecated] alias sqrt_le_sqrt_iff := sqrt_le_sqrt
@[deprecated] alias sqrt_lt_sqrt_iff := sqrt_lt_sqrt
@[deprecated] alias sqrt_le_iff := sqrt_le_iff_le_sq
@[deprecated] alias le_sqrt_iff := le_sqrt_iff_sq_le
@[deprecated] alias sqrt_eq_iff_sq_eq := sqrt_eq_iff_eq_sq
@[simp] lemma sqrt_eq_zero : sqrt x = 0 ↔ x = 0 := by simp [sqrt_eq_iff_eq_sq]
#align nnreal.sqrt_eq_zero NNReal.sqrt_eq_zero
@[simp] lemma sqrt_eq_one : sqrt x = 1 ↔ x = 1 := by simp [sqrt_eq_iff_eq_sq]
@[simp] lemma sqrt_zero : sqrt 0 = 0 := by simp
#align nnreal.sqrt_zero NNReal.sqrt_zero
@[simp] lemma sqrt_one : sqrt 1 = 1 := by simp
#align nnreal.sqrt_one NNReal.sqrt_one
@[simp] lemma sqrt_le_one : sqrt x ≤ 1 ↔ x ≤ 1 := by rw [← sqrt_one, sqrt_le_sqrt, sqrt_one]
@[simp] lemma one_le_sqrt : 1 ≤ sqrt x ↔ 1 ≤ x := by rw [← sqrt_one, sqrt_le_sqrt, sqrt_one]
theorem sqrt_mul (x y : ℝ≥0) : sqrt (x * y) = sqrt x * sqrt y := by
rw [sqrt_eq_iff_eq_sq, mul_pow, sq_sqrt, sq_sqrt]
#align nnreal.sqrt_mul NNReal.sqrt_mul
/-- `NNReal.sqrt` as a `MonoidWithZeroHom`. -/
noncomputable def sqrtHom : ℝ≥0 →*₀ ℝ≥0 :=
⟨⟨sqrt, sqrt_zero⟩, sqrt_one, sqrt_mul⟩
#align nnreal.sqrt_hom NNReal.sqrtHom
theorem sqrt_inv (x : ℝ≥0) : sqrt x⁻¹ = (sqrt x)⁻¹ :=
map_inv₀ sqrtHom x
#align nnreal.sqrt_inv NNReal.sqrt_inv
theorem sqrt_div (x y : ℝ≥0) : sqrt (x / y) = sqrt x / sqrt y :=
map_div₀ sqrtHom x y
#align nnreal.sqrt_div NNReal.sqrt_div
@[continuity, fun_prop]
theorem continuous_sqrt : Continuous sqrt := sqrt.continuous
#align nnreal.continuous_sqrt NNReal.continuous_sqrt
@[simp] theorem sqrt_pos : 0 < sqrt x ↔ 0 < x := by simp [pos_iff_ne_zero]
alias ⟨_, sqrt_pos_of_pos⟩ := sqrt_pos
end NNReal
namespace Real
/-- The square root of a real number. This returns 0 for negative inputs.
This has notation `√x`. Note that `√x⁻¹` is parsed as `√(x⁻¹)`. -/
noncomputable def sqrt (x : ℝ) : ℝ :=
NNReal.sqrt (Real.toNNReal x)
#align real.sqrt Real.sqrt
-- TODO: replace this with a typeclass
@[inherit_doc]
prefix:max "√" => Real.sqrt
/- quotient.lift_on x
(λ f, mk ⟨sqrt_aux f, (sqrt_aux_converges f).fst⟩)
(λ f g e, begin
rcases sqrt_aux_converges f with ⟨hf, x, x0, xf, xs⟩,
rcases sqrt_aux_converges g with ⟨hg, y, y0, yg, ys⟩,
refine xs.trans (eq.trans _ ys.symm),
rw [← @mul_self_inj_of_nonneg ℝ _ x y x0 y0, xf, yg],
congr' 1, exact quotient.sound e
end)-/
variable {x y : ℝ}
@[simp, norm_cast]
theorem coe_sqrt {x : ℝ≥0} : (NNReal.sqrt x : ℝ) = √(x : ℝ) := by
rw [Real.sqrt, Real.toNNReal_coe]
#align real.coe_sqrt Real.coe_sqrt
@[continuity]
theorem continuous_sqrt : Continuous (√· : ℝ → ℝ) :=
NNReal.continuous_coe.comp <| NNReal.continuous_sqrt.comp continuous_real_toNNReal
#align real.continuous_sqrt Real.continuous_sqrt
theorem sqrt_eq_zero_of_nonpos (h : x ≤ 0) : sqrt x = 0 := by simp [sqrt, Real.toNNReal_eq_zero.2 h]
#align real.sqrt_eq_zero_of_nonpos Real.sqrt_eq_zero_of_nonpos
theorem sqrt_nonneg (x : ℝ) : 0 ≤ √x :=
NNReal.coe_nonneg _
#align real.sqrt_nonneg Real.sqrt_nonneg
@[simp]
theorem mul_self_sqrt (h : 0 ≤ x) : √x * √x = x := by
rw [Real.sqrt, ← NNReal.coe_mul, NNReal.mul_self_sqrt, Real.coe_toNNReal _ h]
#align real.mul_self_sqrt Real.mul_self_sqrt
@[simp]
theorem sqrt_mul_self (h : 0 ≤ x) : √(x * x) = x :=
(mul_self_inj_of_nonneg (sqrt_nonneg _) h).1 (mul_self_sqrt (mul_self_nonneg _))
#align real.sqrt_mul_self Real.sqrt_mul_self
theorem sqrt_eq_cases : √x = y ↔ y * y = x ∧ 0 ≤ y ∨ x < 0 ∧ y = 0 := by
constructor
· rintro rfl
rcases le_or_lt 0 x with hle | hlt
· exact Or.inl ⟨mul_self_sqrt hle, sqrt_nonneg x⟩
· exact Or.inr ⟨hlt, sqrt_eq_zero_of_nonpos hlt.le⟩
· rintro (⟨rfl, hy⟩ | ⟨hx, rfl⟩)
exacts [sqrt_mul_self hy, sqrt_eq_zero_of_nonpos hx.le]
#align real.sqrt_eq_cases Real.sqrt_eq_cases
theorem sqrt_eq_iff_mul_self_eq (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = y ↔ y * y = x :=
⟨fun h => by rw [← h, mul_self_sqrt hx], fun h => by rw [← h, sqrt_mul_self hy]⟩
#align real.sqrt_eq_iff_mul_self_eq Real.sqrt_eq_iff_mul_self_eq
theorem sqrt_eq_iff_mul_self_eq_of_pos (h : 0 < y) : √x = y ↔ y * y = x := by
simp [sqrt_eq_cases, h.ne', h.le]
#align real.sqrt_eq_iff_mul_self_eq_of_pos Real.sqrt_eq_iff_mul_self_eq_of_pos
@[simp]
theorem sqrt_eq_one : √x = 1 ↔ x = 1 :=
calc
√x = 1 ↔ 1 * 1 = x := sqrt_eq_iff_mul_self_eq_of_pos zero_lt_one
_ ↔ x = 1 := by rw [eq_comm, mul_one]
#align real.sqrt_eq_one Real.sqrt_eq_one
@[simp]
theorem sq_sqrt (h : 0 ≤ x) : √x ^ 2 = x := by rw [sq, mul_self_sqrt h]
#align real.sq_sqrt Real.sq_sqrt
@[simp]
theorem sqrt_sq (h : 0 ≤ x) : √(x ^ 2) = x := by rw [sq, sqrt_mul_self h]
#align real.sqrt_sq Real.sqrt_sq
theorem sqrt_eq_iff_sq_eq (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = y ↔ y ^ 2 = x := by
rw [sq, sqrt_eq_iff_mul_self_eq hx hy]
#align real.sqrt_eq_iff_sq_eq Real.sqrt_eq_iff_sq_eq
theorem sqrt_mul_self_eq_abs (x : ℝ) : √(x * x) = |x| := by
rw [← abs_mul_abs_self x, sqrt_mul_self (abs_nonneg _)]
#align real.sqrt_mul_self_eq_abs Real.sqrt_mul_self_eq_abs
theorem sqrt_sq_eq_abs (x : ℝ) : √(x ^ 2) = |x| := by rw [sq, sqrt_mul_self_eq_abs]
#align real.sqrt_sq_eq_abs Real.sqrt_sq_eq_abs
@[simp]
theorem sqrt_zero : √0 = 0 := by simp [Real.sqrt]
#align real.sqrt_zero Real.sqrt_zero
@[simp]
theorem sqrt_one : √1 = 1 := by simp [Real.sqrt]
#align real.sqrt_one Real.sqrt_one
@[simp]
theorem sqrt_le_sqrt_iff (hy : 0 ≤ y) : √x ≤ √y ↔ x ≤ y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_le_coe, NNReal.sqrt_le_sqrt, toNNReal_le_toNNReal_iff hy]
#align real.sqrt_le_sqrt_iff Real.sqrt_le_sqrt_iff
@[simp]
theorem sqrt_lt_sqrt_iff (hx : 0 ≤ x) : √x < √y ↔ x < y :=
lt_iff_lt_of_le_iff_le (sqrt_le_sqrt_iff hx)
#align real.sqrt_lt_sqrt_iff Real.sqrt_lt_sqrt_iff
theorem sqrt_lt_sqrt_iff_of_pos (hy : 0 < y) : √x < √y ↔ x < y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_lt_coe, NNReal.sqrt_lt_sqrt, toNNReal_lt_toNNReal_iff hy]
#align real.sqrt_lt_sqrt_iff_of_pos Real.sqrt_lt_sqrt_iff_of_pos
@[gcongr]
theorem sqrt_le_sqrt (h : x ≤ y) : √x ≤ √y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_le_coe, NNReal.sqrt_le_sqrt]
exact toNNReal_le_toNNReal h
#align real.sqrt_le_sqrt Real.sqrt_le_sqrt
@[gcongr]
theorem sqrt_lt_sqrt (hx : 0 ≤ x) (h : x < y) : √x < √y :=
(sqrt_lt_sqrt_iff hx).2 h
#align real.sqrt_lt_sqrt Real.sqrt_lt_sqrt
theorem sqrt_le_left (hy : 0 ≤ y) : √x ≤ y ↔ x ≤ y ^ 2 := by
rw [sqrt, ← Real.le_toNNReal_iff_coe_le hy, NNReal.sqrt_le_iff_le_sq, sq, ← Real.toNNReal_mul hy,
Real.toNNReal_le_toNNReal_iff (mul_self_nonneg y), sq]
#align real.sqrt_le_left Real.sqrt_le_left
theorem sqrt_le_iff : √x ≤ y ↔ 0 ≤ y ∧ x ≤ y ^ 2 := by
rw [← and_iff_right_of_imp fun h => (sqrt_nonneg x).trans h, and_congr_right_iff]
exact sqrt_le_left
#align real.sqrt_le_iff Real.sqrt_le_iff
theorem sqrt_lt (hx : 0 ≤ x) (hy : 0 ≤ y) : √x < y ↔ x < y ^ 2 := by
rw [← sqrt_lt_sqrt_iff hx, sqrt_sq hy]
#align real.sqrt_lt Real.sqrt_lt
theorem sqrt_lt' (hy : 0 < y) : √x < y ↔ x < y ^ 2 := by
rw [← sqrt_lt_sqrt_iff_of_pos (pow_pos hy _), sqrt_sq hy.le]
#align real.sqrt_lt' Real.sqrt_lt'
/-- Note: if you want to conclude `x ≤ √y`, then use `Real.le_sqrt_of_sq_le`.
If you have `x > 0`, consider using `Real.le_sqrt'` -/
theorem le_sqrt (hx : 0 ≤ x) (hy : 0 ≤ y) : x ≤ √y ↔ x ^ 2 ≤ y :=
le_iff_le_iff_lt_iff_lt.2 <| sqrt_lt hy hx
#align real.le_sqrt Real.le_sqrt
theorem le_sqrt' (hx : 0 < x) : x ≤ √y ↔ x ^ 2 ≤ y :=
le_iff_le_iff_lt_iff_lt.2 <| sqrt_lt' hx
#align real.le_sqrt' Real.le_sqrt'
theorem abs_le_sqrt (h : x ^ 2 ≤ y) : |x| ≤ √y := by
rw [← sqrt_sq_eq_abs]; exact sqrt_le_sqrt h
#align real.abs_le_sqrt Real.abs_le_sqrt
theorem sq_le (h : 0 ≤ y) : x ^ 2 ≤ y ↔ -√y ≤ x ∧ x ≤ √y := by
constructor
· simpa only [abs_le] using abs_le_sqrt
· rw [← abs_le, ← sq_abs]
exact (le_sqrt (abs_nonneg x) h).mp
#align real.sq_le Real.sq_le
theorem neg_sqrt_le_of_sq_le (h : x ^ 2 ≤ y) : -√y ≤ x :=
((sq_le ((sq_nonneg x).trans h)).mp h).1
#align real.neg_sqrt_le_of_sq_le Real.neg_sqrt_le_of_sq_le
theorem le_sqrt_of_sq_le (h : x ^ 2 ≤ y) : x ≤ √y :=
((sq_le ((sq_nonneg x).trans h)).mp h).2
#align real.le_sqrt_of_sq_le Real.le_sqrt_of_sq_le
@[simp]
theorem sqrt_inj (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = √y ↔ x = y := by
simp [le_antisymm_iff, hx, hy]
#align real.sqrt_inj Real.sqrt_inj
@[simp]
theorem sqrt_eq_zero (h : 0 ≤ x) : √x = 0 ↔ x = 0 := by simpa using sqrt_inj h le_rfl
#align real.sqrt_eq_zero Real.sqrt_eq_zero
theorem sqrt_eq_zero' : √x = 0 ↔ x ≤ 0 := by
rw [sqrt, NNReal.coe_eq_zero, NNReal.sqrt_eq_zero, Real.toNNReal_eq_zero]
#align real.sqrt_eq_zero' Real.sqrt_eq_zero'
theorem sqrt_ne_zero (h : 0 ≤ x) : √x ≠ 0 ↔ x ≠ 0 := by rw [not_iff_not, sqrt_eq_zero h]
#align real.sqrt_ne_zero Real.sqrt_ne_zero
theorem sqrt_ne_zero' : √x ≠ 0 ↔ 0 < x := by rw [← not_le, not_iff_not, sqrt_eq_zero']
#align real.sqrt_ne_zero' Real.sqrt_ne_zero'
@[simp]
theorem sqrt_pos : 0 < √x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le (Iff.trans (by simp [le_antisymm_iff, sqrt_nonneg]) sqrt_eq_zero')
#align real.sqrt_pos Real.sqrt_pos
alias ⟨_, sqrt_pos_of_pos⟩ := sqrt_pos
#align real.sqrt_pos_of_pos Real.sqrt_pos_of_pos
lemma sqrt_le_sqrt_iff' (hx : 0 < x) : √x ≤ √y ↔ x ≤ y := by
obtain hy | hy := le_total y 0
· exact iff_of_false ((sqrt_eq_zero_of_nonpos hy).trans_lt $ sqrt_pos.2 hx).not_le
(hy.trans_lt hx).not_le
· exact sqrt_le_sqrt_iff hy
@[simp] lemma one_le_sqrt : 1 ≤ √x ↔ 1 ≤ x := by
rw [← sqrt_one, sqrt_le_sqrt_iff' zero_lt_one, sqrt_one]
@[simp] lemma sqrt_le_one : √x ≤ 1 ↔ x ≤ 1 := by
rw [← sqrt_one, sqrt_le_sqrt_iff zero_le_one, sqrt_one]
end Real
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
/-- Extension for the `positivity` tactic: a square root of a strictly positive nonnegative real is
positive. -/
@[positivity NNReal.sqrt _]
def evalNNRealSqrt : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(NNReal), ~q(NNReal.sqrt $a) =>
let ra ← core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa => pure (.positive q(NNReal.sqrt_pos_of_pos $pa))
| _ => failure -- this case is dealt with by generic nonnegativity of nnreals
| _, _, _ => throwError "not NNReal.sqrt"
/-- Extension for the `positivity` tactic: a square root is nonnegative, and is strictly positive if
its input is. -/
@[positivity √ _]
def evalSqrt : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(√$a) =>
let ra ← catchNone <| core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa => pure (.positive q(Real.sqrt_pos_of_pos $pa))
| _ => pure (.nonnegative q(Real.sqrt_nonneg $a))
| _, _, _ => throwError "not Real.sqrt"
end Mathlib.Meta.Positivity
namespace Real
variable {x y : ℝ}
@[simp]
theorem sqrt_mul {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : √(x * y) = √x * √y := by
simp_rw [Real.sqrt, ← NNReal.coe_mul, NNReal.coe_inj, Real.toNNReal_mul hx, NNReal.sqrt_mul]
#align real.sqrt_mul Real.sqrt_mul
@[simp]
| Mathlib/Data/Real/Sqrt.lean | 382 | 383 | theorem sqrt_mul' (x) {y : ℝ} (hy : 0 ≤ y) : √(x * y) = √x * √y := by |
rw [mul_comm, sqrt_mul hy, mul_comm]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell
-/
import Mathlib.Data.Nat.Factorial.Basic
import Mathlib.Order.Monotone.Basic
#align_import data.nat.choose.basic from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4"
/-!
# Binomial coefficients
This file defines binomial coefficients and proves simple lemmas (i.e. those not
requiring more imports).
## Main definition and results
* `Nat.choose`: binomial coefficients, defined inductively
* `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)`
* `Nat.choose_symm`: symmetry of binomial coefficients
* `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k`
* `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2`
* `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending
factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements
for the ascending factorial.
* `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations.
The fact that this is indeed the correct counting function for multisets is proved in
`Sym.card_sym_eq_multichoose` in `Data.Sym.Card`.
* `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`.
This is central to the "stars and bars" technique in informal mathematics, where we switch between
counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements
("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail.
## Tags
binomial coefficient, combination, multicombination, stars and bars
-/
open Nat
namespace Nat
/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial
coefficients. -/
def choose : ℕ → ℕ → ℕ
| _, 0 => 1
| 0, _ + 1 => 0
| n + 1, k + 1 => choose n k + choose n (k + 1)
#align nat.choose Nat.choose
@[simp]
theorem choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n <;> rfl
#align nat.choose_zero_right Nat.choose_zero_right
@[simp]
theorem choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 :=
rfl
#align nat.choose_zero_succ Nat.choose_zero_succ
theorem choose_succ_succ (n k : ℕ) : choose (succ n) (succ k) = choose n k + choose n (succ k) :=
rfl
#align nat.choose_succ_succ Nat.choose_succ_succ
theorem choose_succ_succ' (n k : ℕ) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) :=
rfl
theorem choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0
| _, 0, hk => absurd hk (Nat.not_lt_zero _)
| 0, k + 1, _ => choose_zero_succ _
| n + 1, k + 1, hk => by
have hnk : n < k := lt_of_succ_lt_succ hk
have hnk1 : n < k + 1 := lt_of_succ_lt hk
rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1]
#align nat.choose_eq_zero_of_lt Nat.choose_eq_zero_of_lt
@[simp]
theorem choose_self (n : ℕ) : choose n n = 1 := by
induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)]
#align nat.choose_self Nat.choose_self
@[simp]
theorem choose_succ_self (n : ℕ) : choose n (succ n) = 0 :=
choose_eq_zero_of_lt (lt_succ_self _)
#align nat.choose_succ_self Nat.choose_succ_self
@[simp]
lemma choose_one_right (n : ℕ) : choose n 1 = n := by induction n <;> simp [*, choose, Nat.add_comm]
#align nat.choose_one_right Nat.choose_one_right
-- The `n+1`-st triangle number is `n` more than the `n`-th triangle number
theorem triangle_succ (n : ℕ) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by
rw [← add_mul_div_left, Nat.mul_comm 2 n, ← Nat.mul_add, Nat.add_sub_cancel, Nat.mul_comm]
cases n <;> rfl; apply zero_lt_succ
#align nat.triangle_succ Nat.triangle_succ
/-- `choose n 2` is the `n`-th triangle number. -/
theorem choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 := by
induction' n with n ih
· simp
· rw [triangle_succ n, choose, ih]
simp [Nat.add_comm]
#align nat.choose_two_right Nat.choose_two_right
theorem choose_pos : ∀ {n k}, k ≤ n → 0 < choose n k
| 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk]; decide
| n + 1, 0, _ => by simp
| n + 1, k + 1, hk => Nat.add_pos_left (choose_pos (le_of_succ_le_succ hk)) _
#align nat.choose_pos Nat.choose_pos
theorem choose_eq_zero_iff {n k : ℕ} : n.choose k = 0 ↔ n < k :=
⟨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt⟩
#align nat.choose_eq_zero_iff Nat.choose_eq_zero_iff
theorem succ_mul_choose_eq : ∀ n k, succ n * choose n k = choose (succ n) (succ k) * succ k
| 0, 0 => by decide
| 0, k + 1 => by simp [choose]
| n + 1, 0 => by simp [choose, mul_succ, succ_eq_add_one, Nat.add_comm]
| n + 1, k + 1 => by
rw [choose_succ_succ (succ n) (succ k), Nat.add_mul, ← succ_mul_choose_eq n, mul_succ, ←
succ_mul_choose_eq n, Nat.add_right_comm, ← Nat.mul_add, ← choose_succ_succ, ← succ_mul]
#align nat.succ_mul_choose_eq Nat.succ_mul_choose_eq
theorem choose_mul_factorial_mul_factorial : ∀ {n k}, k ≤ n → choose n k * k ! * (n - k)! = n !
| 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk]
| n + 1, 0, _ => by simp
| n + 1, succ k, hk => by
rcases lt_or_eq_of_le hk with hk₁ | hk₁
· have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by
rw [← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have h₁ : (n - k)! = (n - k) * (n - k.succ)! := by
rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ]
have h₂ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by
rw [← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have h₃ : k * n ! ≤ n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk)
rw [choose_succ_succ, Nat.add_mul, Nat.add_mul, succ_sub_succ, h, h₁, h₂, Nat.add_mul,
Nat.mul_sub_right_distrib, factorial_succ, ← Nat.add_sub_assoc h₃, Nat.add_assoc,
← Nat.add_mul, Nat.add_sub_cancel_left, Nat.add_comm]
· rw [hk₁]; simp [hk₁, Nat.mul_comm, choose, Nat.sub_self]
#align nat.choose_mul_factorial_mul_factorial Nat.choose_mul_factorial_mul_factorial
theorem choose_mul {n k s : ℕ} (hkn : k ≤ n) (hsk : s ≤ k) :
n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) :=
have h : 0 < (n - k)! * (k - s)! * s ! := by apply_rules [factorial_pos, Nat.mul_pos]
Nat.mul_right_cancel h <|
calc
n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) =
n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! := by
rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc _ s !, Nat.mul_assoc,
Nat.mul_comm (n - k)!, Nat.mul_comm s !]
_ = n ! := by
rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn]
_ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by
rw [choose_mul_factorial_mul_factorial (Nat.sub_le_sub_right hkn _),
choose_mul_factorial_mul_factorial (hsk.trans hkn)]
_ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by
rw [Nat.sub_sub_sub_cancel_right hsk, Nat.mul_assoc, Nat.mul_left_comm s !, Nat.mul_assoc,
Nat.mul_comm (k - s)!, Nat.mul_comm s !, Nat.mul_right_comm, ← Nat.mul_assoc]
#align nat.choose_mul Nat.choose_mul
theorem choose_eq_factorial_div_factorial {n k : ℕ} (hk : k ≤ n) :
choose n k = n ! / (k ! * (n - k)!) := by
rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]
exact (mul_div_left _ (Nat.mul_pos (factorial_pos _) (factorial_pos _))).symm
#align nat.choose_eq_factorial_div_factorial Nat.choose_eq_factorial_div_factorial
theorem add_choose (i j : ℕ) : (i + j).choose j = (i + j)! / (i ! * j !) := by
rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), Nat.add_sub_cancel_right,
Nat.mul_comm]
#align nat.add_choose Nat.add_choose
theorem add_choose_mul_factorial_mul_factorial (i j : ℕ) :
(i + j).choose j * i ! * j ! = (i + j)! := by
rw [← choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), Nat.add_sub_cancel_right,
Nat.mul_right_comm]
#align nat.add_choose_mul_factorial_mul_factorial Nat.add_choose_mul_factorial_mul_factorial
theorem factorial_mul_factorial_dvd_factorial {n k : ℕ} (hk : k ≤ n) : k ! * (n - k)! ∣ n ! := by
rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]; exact Nat.dvd_mul_left _ _
#align nat.factorial_mul_factorial_dvd_factorial Nat.factorial_mul_factorial_dvd_factorial
theorem factorial_mul_factorial_dvd_factorial_add (i j : ℕ) : i ! * j ! ∣ (i + j)! := by
suffices i ! * (i + j - i) ! ∣ (i + j)! by
rwa [Nat.add_sub_cancel_left i j] at this
exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _)
#align nat.factorial_mul_factorial_dvd_factorial_add Nat.factorial_mul_factorial_dvd_factorial_add
@[simp]
theorem choose_symm {n k : ℕ} (hk : k ≤ n) : choose n (n - k) = choose n k := by
rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _),
Nat.sub_sub_self hk, Nat.mul_comm]
#align nat.choose_symm Nat.choose_symm
theorem choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by
suffices choose n (n - b) = choose n b by
rw [h, Nat.add_sub_cancel_right] at this; rwa [h]
exact choose_symm (h ▸ le_add_left _ _)
#align nat.choose_symm_of_eq_add Nat.choose_symm_of_eq_add
theorem choose_symm_add {a b : ℕ} : choose (a + b) a = choose (a + b) b :=
choose_symm_of_eq_add rfl
#align nat.choose_symm_add Nat.choose_symm_add
theorem choose_symm_half (m : ℕ) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m := by
apply choose_symm_of_eq_add
rw [Nat.add_comm m 1, Nat.add_assoc 1 m m, Nat.add_comm (2 * m) 1, Nat.two_mul m]
#align nat.choose_symm_half Nat.choose_symm_half
theorem choose_succ_right_eq (n k : ℕ) : choose n (k + 1) * (k + 1) = choose n k * (n - k) := by
have e : (n + 1) * choose n k = choose n (k + 1) * (k + 1) + choose n k * (k + 1) := by
rw [← Nat.add_mul, Nat.add_comm (choose _ _), ← choose_succ_succ, succ_mul_choose_eq]
rw [← Nat.sub_eq_of_eq_add e, Nat.mul_comm, ← Nat.mul_sub_left_distrib, Nat.add_sub_add_right]
#align nat.choose_succ_right_eq Nat.choose_succ_right_eq
@[simp]
theorem choose_succ_self_right : ∀ n : ℕ, (n + 1).choose n = n + 1
| 0 => rfl
| n + 1 => by rw [choose_succ_succ, choose_succ_self_right n, choose_self]
#align nat.choose_succ_self_right Nat.choose_succ_self_right
theorem choose_mul_succ_eq (n k : ℕ) : n.choose k * (n + 1) = (n + 1).choose k * (n + 1 - k) := by
cases k with
| zero => simp
| succ k =>
obtain hk | hk := le_or_lt (k + 1) (n + 1)
· rw [choose_succ_succ, Nat.add_mul, succ_sub_succ, ← choose_succ_right_eq, ← succ_sub_succ,
Nat.mul_sub_left_distrib, Nat.add_sub_cancel' (Nat.mul_le_mul_left _ hk)]
· rw [choose_eq_zero_of_lt hk, choose_eq_zero_of_lt (n.lt_succ_self.trans hk), Nat.zero_mul,
Nat.zero_mul]
#align nat.choose_mul_succ_eq Nat.choose_mul_succ_eq
theorem ascFactorial_eq_factorial_mul_choose (n k : ℕ) :
(n + 1).ascFactorial k = k ! * (n + k).choose k := by
rw [Nat.mul_comm]
apply Nat.mul_right_cancel (n + k - k).factorial_pos
rw [choose_mul_factorial_mul_factorial <| Nat.le_add_left k n, Nat.add_sub_cancel_right,
← factorial_mul_ascFactorial, Nat.mul_comm]
#align nat.asc_factorial_eq_factorial_mul_choose Nat.ascFactorial_eq_factorial_mul_choose
theorem ascFactorial_eq_factorial_mul_choose' (n k : ℕ) :
n.ascFactorial k = k ! * (n + k - 1).choose k := by
cases n
· cases k
· rw [ascFactorial_zero, choose_zero_right, factorial_zero, Nat.mul_one]
· simp only [zero_ascFactorial, zero_eq, Nat.zero_add, succ_sub_succ_eq_sub,
Nat.le_zero_eq, Nat.sub_zero, choose_succ_self, Nat.mul_zero]
rw [ascFactorial_eq_factorial_mul_choose]
simp only [succ_add_sub_one]
theorem factorial_dvd_ascFactorial (n k : ℕ) : k ! ∣ n.ascFactorial k :=
⟨(n + k - 1).choose k, ascFactorial_eq_factorial_mul_choose' _ _⟩
#align nat.factorial_dvd_asc_factorial Nat.factorial_dvd_ascFactorial
theorem choose_eq_asc_factorial_div_factorial (n k : ℕ) :
(n + k).choose k = (n + 1).ascFactorial k / k ! := by
apply Nat.mul_left_cancel k.factorial_pos
rw [← ascFactorial_eq_factorial_mul_choose]
exact (Nat.mul_div_cancel' <| factorial_dvd_ascFactorial _ _).symm
#align nat.choose_eq_asc_factorial_div_factorial Nat.choose_eq_asc_factorial_div_factorial
theorem choose_eq_asc_factorial_div_factorial' (n k : ℕ) :
(n + k - 1).choose k = n.ascFactorial k / k ! :=
Nat.eq_div_of_mul_eq_right k.factorial_ne_zero (ascFactorial_eq_factorial_mul_choose' _ _).symm
theorem descFactorial_eq_factorial_mul_choose (n k : ℕ) : n.descFactorial k = k ! * n.choose k := by
obtain h | h := Nat.lt_or_ge n k
· rw [descFactorial_eq_zero_iff_lt.2 h, choose_eq_zero_of_lt h, Nat.mul_zero]
rw [Nat.mul_comm]
apply Nat.mul_right_cancel (n - k).factorial_pos
rw [choose_mul_factorial_mul_factorial h, ← factorial_mul_descFactorial h, Nat.mul_comm]
#align nat.desc_factorial_eq_factorial_mul_choose Nat.descFactorial_eq_factorial_mul_choose
theorem factorial_dvd_descFactorial (n k : ℕ) : k ! ∣ n.descFactorial k :=
⟨n.choose k, descFactorial_eq_factorial_mul_choose _ _⟩
#align nat.factorial_dvd_desc_factorial Nat.factorial_dvd_descFactorial
theorem choose_eq_descFactorial_div_factorial (n k : ℕ) : n.choose k = n.descFactorial k / k ! :=
Nat.eq_div_of_mul_eq_right k.factorial_ne_zero (descFactorial_eq_factorial_mul_choose _ _).symm
#align nat.choose_eq_desc_factorial_div_factorial Nat.choose_eq_descFactorial_div_factorial
/-- A faster implementation of `choose`, to be used during bytecode evaluation
and in compiled code. -/
def fast_choose n k := Nat.descFactorial n k / Nat.factorial k
@[csimp] lemma choose_eq_fast_choose : Nat.choose = fast_choose :=
funext (fun _ => funext (Nat.choose_eq_descFactorial_div_factorial _))
/-! ### Inequalities -/
/-- Show that `Nat.choose` is increasing for small values of the right argument. -/
theorem choose_le_succ_of_lt_half_left {r n : ℕ} (h : r < n / 2) :
choose n r ≤ choose n (r + 1) := by
refine Nat.le_of_mul_le_mul_right ?_ (Nat.sub_pos_of_lt (h.trans_le (n.div_le_self 2)))
rw [← choose_succ_right_eq]
apply Nat.mul_le_mul_left
rw [← Nat.lt_iff_add_one_le, Nat.lt_sub_iff_add_lt, ← Nat.mul_two]
exact lt_of_lt_of_le (Nat.mul_lt_mul_of_pos_right h Nat.zero_lt_two) (n.div_mul_le_self 2)
#align nat.choose_le_succ_of_lt_half_left Nat.choose_le_succ_of_lt_half_left
/-- Show that for small values of the right argument, the middle value is largest. -/
private theorem choose_le_middle_of_le_half_left {n r : ℕ} (hr : r ≤ n / 2) :
choose n r ≤ choose n (n / 2) :=
decreasingInduction
(fun _ k a =>
(eq_or_lt_of_le a).elim (fun t => t.symm ▸ le_rfl) fun h =>
(choose_le_succ_of_lt_half_left h).trans (k h))
hr (fun _ => le_rfl) hr
/-- `choose n r` is maximised when `r` is `n/2`. -/
theorem choose_le_middle (r n : ℕ) : choose n r ≤ choose n (n / 2) := by
cases' le_or_gt r n with b b
· rcases le_or_lt r (n / 2) with a | h
· apply choose_le_middle_of_le_half_left a
· rw [← choose_symm b]
apply choose_le_middle_of_le_half_left
rw [div_lt_iff_lt_mul' Nat.zero_lt_two] at h
rw [le_div_iff_mul_le' Nat.zero_lt_two, Nat.mul_sub_right_distrib, Nat.sub_le_iff_le_add,
← Nat.sub_le_iff_le_add', Nat.mul_two, Nat.add_sub_cancel]
exact le_of_lt h
· rw [choose_eq_zero_of_lt b]
apply zero_le
#align nat.choose_le_middle Nat.choose_le_middle
/-! #### Inequalities about increasing the first argument -/
theorem choose_le_succ (a c : ℕ) : choose a c ≤ choose a.succ c := by
cases c <;> simp [Nat.choose_succ_succ]
#align nat.choose_le_succ Nat.choose_le_succ
theorem choose_le_add (a b c : ℕ) : choose a c ≤ choose (a + b) c := by
induction' b with b_n b_ih
· simp
exact le_trans b_ih (choose_le_succ (a + b_n) c)
#align nat.choose_le_add Nat.choose_le_add
theorem choose_le_choose {a b : ℕ} (c : ℕ) (h : a ≤ b) : choose a c ≤ choose b c :=
Nat.add_sub_cancel' h ▸ choose_le_add a (b - a) c
#align nat.choose_le_choose Nat.choose_le_choose
theorem choose_mono (b : ℕ) : Monotone fun a => choose a b := fun _ _ => choose_le_choose b
#align nat.choose_mono Nat.choose_mono
/-! #### Multichoose
Whereas `choose n k` is the number of subsets of cardinality `k` from a type of cardinality `n`,
`multichoose n k` is the number of multisets of cardinality `k` from a type of cardinality `n`.
Alternatively, whereas `choose n k` counts the number of combinations,
i.e. ways to select `k` items (up to permutation) from `n` items without replacement,
`multichoose n k` counts the number of multicombinations,
i.e. ways to select `k` items (up to permutation) from `n` items with replacement.
Note that `multichoose` is *not* the multinomial coefficient, although it can be computed
in terms of multinomial coefficients. For details see https://mathworld.wolfram.com/Multichoose.html
TODO: Prove that `choose (-n) k = (-1)^k * multichoose n k`,
where `choose` is the generalized binomial coefficient.
<https://github.com/leanprover-community/mathlib/pull/15072#issuecomment-1171415738>
-/
/--
`multichoose n k` is the number of multisets of cardinality `k` from a type of cardinality `n`. -/
def multichoose : ℕ → ℕ → ℕ
| _, 0 => 1
| 0, _ + 1 => 0
| n + 1, k + 1 =>
multichoose n (k + 1) + multichoose (n + 1) k
#align nat.multichoose Nat.multichoose
@[simp]
| Mathlib/Data/Nat/Choose/Basic.lean | 378 | 378 | theorem multichoose_zero_right (n : ℕ) : multichoose n 0 = 1 := by | cases n <;> simp [multichoose]
|
/-
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.IsometricSMul
#align_import topology.metric_space.hausdorff_distance from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156"
/-!
# Hausdorff distance
The Hausdorff distance on subsets of a metric (or emetric) space.
Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d`
such that any point `s` is within `d` of a point in `t`, and conversely. This quantity
is often infinite (think of `s` bounded and `t` unbounded), and therefore better
expressed in the setting of emetric spaces.
## Main definitions
This files introduces:
* `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space
* `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space
* Versions of these notions on metric spaces, called respectively `Metric.infDist`
and `Metric.hausdorffDist`
## Main results
* `infEdist_closure`: the edistance to a set and its closure coincide
* `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff
`infEdist x s = 0`
* `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y`
which attains this edistance
* `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union
of countably many closed subsets of `U`
* `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance
* `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero
iff their closures coincide
* the Hausdorff edistance is symmetric and satisfies the triangle inequality
* in particular, closed sets in an emetric space are an emetric space
(this is shown in `EMetricSpace.closeds.emetricspace`)
* versions of these notions on metric spaces
* `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space
are nonempty and bounded in a metric space, they are at finite Hausdorff edistance.
## Tags
metric space, Hausdorff distance
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Pointwise Bornology
universe u v w
variable {ι : Sort*} {α : Type u} {β : Type v}
namespace EMetric
section InfEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β}
/-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/
/-- The minimal edistance of a point to a set -/
def infEdist (x : α) (s : Set α) : ℝ≥0∞ :=
⨅ y ∈ s, edist x y
#align emetric.inf_edist EMetric.infEdist
@[simp]
theorem infEdist_empty : infEdist x ∅ = ∞ :=
iInf_emptyset
#align emetric.inf_edist_empty EMetric.infEdist_empty
theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by
simp only [infEdist, le_iInf_iff]
#align emetric.le_inf_edist EMetric.le_infEdist
/-- The edist to a union is the minimum of the edists -/
@[simp]
theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t :=
iInf_union
#align emetric.inf_edist_union EMetric.infEdist_union
@[simp]
theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) :=
iInf_iUnion f _
#align emetric.inf_edist_Union EMetric.infEdist_iUnion
lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) :
infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion]
/-- The edist to a singleton is the edistance to the single point of this singleton -/
@[simp]
theorem infEdist_singleton : infEdist x {y} = edist x y :=
iInf_singleton
#align emetric.inf_edist_singleton EMetric.infEdist_singleton
/-- The edist to a set is bounded above by the edist to any of its points -/
theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y :=
iInf₂_le y h
#align emetric.inf_edist_le_edist_of_mem EMetric.infEdist_le_edist_of_mem
/-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/
theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 :=
nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h
#align emetric.inf_edist_zero_of_mem EMetric.infEdist_zero_of_mem
/-- The edist is antitone with respect to inclusion. -/
theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s :=
iInf_le_iInf_of_subset h
#align emetric.inf_edist_anti EMetric.infEdist_anti
/-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/
theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by
simp_rw [infEdist, iInf_lt_iff, exists_prop]
#align emetric.inf_edist_lt_iff EMetric.infEdist_lt_iff
/-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and
the edist from `x` to `y` -/
theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y :=
calc
⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y :=
iInf₂_mono fun z _ => (edist_triangle _ _ _).trans_eq (add_comm _ _)
_ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add]
#align emetric.inf_edist_le_inf_edist_add_edist EMetric.infEdist_le_infEdist_add_edist
theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by
rw [add_comm]
exact infEdist_le_infEdist_add_edist
#align emetric.inf_edist_le_edist_add_inf_edist EMetric.infEdist_le_edist_add_infEdist
theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by
simp_rw [infEdist, ENNReal.iInf_add]
refine le_iInf₂ fun i hi => ?_
calc
edist x y ≤ edist x i + edist i y := edist_triangle _ _ _
_ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy)
#align emetric.edist_le_inf_edist_add_ediam EMetric.edist_le_infEdist_add_ediam
/-- The edist to a set depends continuously on the point -/
@[continuity]
theorem continuous_infEdist : Continuous fun x => infEdist x s :=
continuous_of_le_add_edist 1 (by simp) <| by
simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff]
#align emetric.continuous_inf_edist EMetric.continuous_infEdist
/-- The edist to a set and to its closure coincide -/
theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by
refine le_antisymm (infEdist_anti subset_closure) ?_
refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_
have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos
have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 :=
ENNReal.lt_add_right h.ne ε0.ne'
obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ :=
infEdist_lt_iff.mp this
obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0
calc
infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs
_ ≤ edist x y + edist y z := edist_triangle _ _ _
_ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz)
_ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves]
#align emetric.inf_edist_closure EMetric.infEdist_closure
/-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/
theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 :=
⟨fun h => by
rw [← infEdist_closure]
exact infEdist_zero_of_mem h,
fun h =>
EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩
#align emetric.mem_closure_iff_inf_edist_zero EMetric.mem_closure_iff_infEdist_zero
/-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/
theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by
rw [← mem_closure_iff_infEdist_zero, h.closure_eq]
#align emetric.mem_iff_inf_edist_zero_of_closed EMetric.mem_iff_infEdist_zero_of_closed
/-- The infimum edistance of a point to a set is positive if and only if the point is not in the
closure of the set. -/
theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x E ↔ x ∉ closure E := by
rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero]
#align emetric.inf_edist_pos_iff_not_mem_closure EMetric.infEdist_pos_iff_not_mem_closure
theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x (closure E) ↔ x ∉ closure E := by
rw [infEdist_closure, infEdist_pos_iff_not_mem_closure]
#align emetric.inf_edist_closure_pos_iff_not_mem_closure EMetric.infEdist_closure_pos_iff_not_mem_closure
theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) :
∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by
rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h
rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩
exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩
#align emetric.exists_real_pos_lt_inf_edist_of_not_mem_closure EMetric.exists_real_pos_lt_infEdist_of_not_mem_closure
theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) :
Disjoint (closedBall x r) s := by
rw [disjoint_left]
intro y hy h'y
apply lt_irrefl (infEdist x s)
calc
infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y
_ ≤ r := by rwa [mem_closedBall, edist_comm] at hy
_ < infEdist x s := h
#align emetric.disjoint_closed_ball_of_lt_inf_edist EMetric.disjoint_closedBall_of_lt_infEdist
/-- The infimum edistance is invariant under isometries -/
theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by
simp only [infEdist, iInf_image, hΦ.edist_eq]
#align emetric.inf_edist_image EMetric.infEdist_image
@[to_additive (attr := simp)]
theorem infEdist_smul {M} [SMul M α] [IsometricSMul M α] (c : M) (x : α) (s : Set α) :
infEdist (c • x) (c • s) = infEdist x s :=
infEdist_image (isometry_smul _ _)
#align emetric.inf_edist_smul EMetric.infEdist_smul
#align emetric.inf_edist_vadd EMetric.infEdist_vadd
| Mathlib/Topology/MetricSpace/HausdorffDistance.lean | 226 | 248 | theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) :
∃ F : ℕ → Set α, (∀ n, IsClosed (F n)) ∧ (∀ n, F n ⊆ U) ∧ ⋃ n, F n = U ∧ Monotone F := by |
obtain ⟨a, a_pos, a_lt_one⟩ : ∃ a : ℝ≥0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one
let F := fun n : ℕ => (fun x => infEdist x Uᶜ) ⁻¹' Ici (a ^ n)
have F_subset : ∀ n, F n ⊆ U := fun n x hx ↦ by
by_contra h
have : infEdist x Uᶜ ≠ 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne'
exact this (infEdist_zero_of_mem h)
refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩
· show ⋃ n, F n = U
refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_
have : ¬x ∈ Uᶜ := by simpa using hx
rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this
have B : 0 < infEdist x Uᶜ := by simpa [pos_iff_ne_zero] using this
have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) :=
ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one
rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩
simp only [mem_iUnion, mem_Ici, mem_preimage]
exact ⟨n, hn.le⟩
show Monotone F
intro m n hmn x hx
simp only [F, mem_Ici, mem_preimage] at hx ⊢
apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Patrick Massot
-/
import Mathlib.MeasureTheory.Integral.IntervalIntegral
import Mathlib.Order.Filter.IndicatorFunction
/-!
# The dominated convergence theorem
This file collects various results related to the Lebesgue dominated convergence theorem
for the Bochner integral.
## Main results
- `MeasureTheory.tendsto_integral_of_dominated_convergence`:
the Lebesgue dominated convergence theorem for the Bochner integral
- `MeasureTheory.hasSum_integral_of_dominated_convergence`:
the Lebesgue dominated convergence theorem for series
- `MeasureTheory.integral_tsum`, `MeasureTheory.integral_tsum_of_summable_integral_norm`:
the integral and `tsum`s commute, if the norms of the functions form a summable series
- `intervalIntegral.hasSum_integral_of_dominated_convergence`: the Lebesgue dominated convergence
theorem for parametric interval integrals
- `intervalIntegral.continuous_of_dominated_interval`: continuity of the interval integral
w.r.t. a parameter
- `intervalIntegral.continuous_primitive` and friends: primitives of interval integrable
measurable functions are continuous
-/
open MeasureTheory
/-!
## The Lebesgue dominated convergence theorem for the Bochner integral
-/
section DominatedConvergenceTheorem
open Set Filter TopologicalSpace ENNReal
open scoped Topology
namespace MeasureTheory
variable {α E G: Type*}
[NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
[NormedAddCommGroup G] [NormedSpace ℝ G]
{f g : α → E} {m : MeasurableSpace α} {μ : Measure α}
/-- **Lebesgue dominated convergence theorem** provides sufficient conditions under which almost
everywhere convergence of a sequence of functions implies the convergence of their integrals.
We could weaken the condition `bound_integrable` to require `HasFiniteIntegral bound μ` instead
(i.e. not requiring that `bound` is measurable), but in all applications proving integrability
is easier. -/
theorem tendsto_integral_of_dominated_convergence {F : ℕ → α → G} {f : α → G} (bound : α → ℝ)
(F_measurable : ∀ n, AEStronglyMeasurable (F n) μ) (bound_integrable : Integrable bound μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) :
Tendsto (fun n => ∫ a, F n a ∂μ) atTop (𝓝 <| ∫ a, f a ∂μ) := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact tendsto_setToFun_of_dominated_convergence (dominatedFinMeasAdditive_weightedSMul μ)
bound F_measurable bound_integrable h_bound h_lim
· simp [integral, hG]
#align measure_theory.tendsto_integral_of_dominated_convergence MeasureTheory.tendsto_integral_of_dominated_convergence
/-- Lebesgue dominated convergence theorem for filters with a countable basis -/
theorem tendsto_integral_filter_of_dominated_convergence {ι} {l : Filter ι} [l.IsCountablyGenerated]
{F : ι → α → G} {f : α → G} (bound : α → ℝ) (hF_meas : ∀ᶠ n in l, AEStronglyMeasurable (F n) μ)
(h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) l (𝓝 (f a))) :
Tendsto (fun n => ∫ a, F n a ∂μ) l (𝓝 <| ∫ a, f a ∂μ) := by
by_cases hG : CompleteSpace G
· simp only [integral, hG, L1.integral]
exact tendsto_setToFun_filter_of_dominated_convergence (dominatedFinMeasAdditive_weightedSMul μ)
bound hF_meas h_bound bound_integrable h_lim
· simp [integral, hG, tendsto_const_nhds]
#align measure_theory.tendsto_integral_filter_of_dominated_convergence MeasureTheory.tendsto_integral_filter_of_dominated_convergence
/-- Lebesgue dominated convergence theorem for series. -/
theorem hasSum_integral_of_dominated_convergence {ι} [Countable ι] {F : ι → α → G} {f : α → G}
(bound : ι → α → ℝ) (hF_meas : ∀ n, AEStronglyMeasurable (F n) μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound n a)
(bound_summable : ∀ᵐ a ∂μ, Summable fun n => bound n a)
(bound_integrable : Integrable (fun a => ∑' n, bound n a) μ)
(h_lim : ∀ᵐ a ∂μ, HasSum (fun n => F n a) (f a)) :
HasSum (fun n => ∫ a, F n a ∂μ) (∫ a, f a ∂μ) := by
have hb_nonneg : ∀ᵐ a ∂μ, ∀ n, 0 ≤ bound n a :=
eventually_countable_forall.2 fun n => (h_bound n).mono fun a => (norm_nonneg _).trans
have hb_le_tsum : ∀ n, bound n ≤ᵐ[μ] fun a => ∑' n, bound n a := by
intro n
filter_upwards [hb_nonneg, bound_summable]
with _ ha0 ha_sum using le_tsum ha_sum _ fun i _ => ha0 i
have hF_integrable : ∀ n, Integrable (F n) μ := by
refine fun n => bound_integrable.mono' (hF_meas n) ?_
exact EventuallyLE.trans (h_bound n) (hb_le_tsum n)
simp only [HasSum, ← integral_finset_sum _ fun n _ => hF_integrable n]
refine tendsto_integral_filter_of_dominated_convergence
(fun a => ∑' n, bound n a) ?_ ?_ bound_integrable h_lim
· exact eventually_of_forall fun s => s.aestronglyMeasurable_sum fun n _ => hF_meas n
· filter_upwards with s
filter_upwards [eventually_countable_forall.2 h_bound, hb_nonneg, bound_summable]
with a hFa ha0 has
calc
‖∑ n ∈ s, F n a‖ ≤ ∑ n ∈ s, bound n a := norm_sum_le_of_le _ fun n _ => hFa n
_ ≤ ∑' n, bound n a := sum_le_tsum _ (fun n _ => ha0 n) has
#align measure_theory.has_sum_integral_of_dominated_convergence MeasureTheory.hasSum_integral_of_dominated_convergence
theorem integral_tsum {ι} [Countable ι] {f : ι → α → G} (hf : ∀ i, AEStronglyMeasurable (f i) μ)
(hf' : ∑' i, ∫⁻ a : α, ‖f i a‖₊ ∂μ ≠ ∞) :
∫ a : α, ∑' i, f i a ∂μ = ∑' i, ∫ a : α, f i a ∂μ := by
by_cases hG : CompleteSpace G; swap
· simp [integral, hG]
have hf'' : ∀ i, AEMeasurable (fun x => (‖f i x‖₊ : ℝ≥0∞)) μ := fun i => (hf i).ennnorm
have hhh : ∀ᵐ a : α ∂μ, Summable fun n => (‖f n a‖₊ : ℝ) := by
rw [← lintegral_tsum hf''] at hf'
refine (ae_lt_top' (AEMeasurable.ennreal_tsum hf'') hf').mono ?_
intro x hx
rw [← ENNReal.tsum_coe_ne_top_iff_summable_coe]
exact hx.ne
convert (MeasureTheory.hasSum_integral_of_dominated_convergence (fun i a => ‖f i a‖₊) hf _ hhh
⟨_, _⟩ _).tsum_eq.symm
· intro n
filter_upwards with x
rfl
· simp_rw [← NNReal.coe_tsum]
rw [aestronglyMeasurable_iff_aemeasurable]
apply AEMeasurable.coe_nnreal_real
apply AEMeasurable.nnreal_tsum
exact fun i => (hf i).nnnorm.aemeasurable
· dsimp [HasFiniteIntegral]
have : ∫⁻ a, ∑' n, ‖f n a‖₊ ∂μ < ⊤ := by rwa [lintegral_tsum hf'', lt_top_iff_ne_top]
convert this using 1
apply lintegral_congr_ae
simp_rw [← coe_nnnorm, ← NNReal.coe_tsum, NNReal.nnnorm_eq]
filter_upwards [hhh] with a ha
exact ENNReal.coe_tsum (NNReal.summable_coe.mp ha)
· filter_upwards [hhh] with x hx
exact hx.of_norm.hasSum
#align measure_theory.integral_tsum MeasureTheory.integral_tsum
lemma hasSum_integral_of_summable_integral_norm {ι} [Countable ι] {F : ι → α → E}
(hF_int : ∀ i : ι, Integrable (F i) μ) (hF_sum : Summable fun i ↦ ∫ a, ‖F i a‖ ∂μ) :
HasSum (∫ a, F · a ∂μ) (∫ a, (∑' i, F i a) ∂μ) := by
rw [integral_tsum (fun i ↦ (hF_int i).1)]
· exact (hF_sum.of_norm_bounded _ fun i ↦ norm_integral_le_integral_norm _).hasSum
have (i : ι) : ∫⁻ (a : α), ‖F i a‖₊ ∂μ = ‖(∫ a : α, ‖F i a‖ ∂μ)‖₊ := by
rw [lintegral_coe_eq_integral _ (hF_int i).norm, coe_nnreal_eq, coe_nnnorm,
Real.norm_of_nonneg (integral_nonneg (fun a ↦ norm_nonneg (F i a)))]
simp only [coe_nnnorm]
rw [funext this, ← ENNReal.coe_tsum]
· apply coe_ne_top
· simp_rw [← NNReal.summable_coe, coe_nnnorm]
exact hF_sum.abs
lemma integral_tsum_of_summable_integral_norm {ι} [Countable ι] {F : ι → α → E}
(hF_int : ∀ i : ι, Integrable (F i) μ) (hF_sum : Summable fun i ↦ ∫ a, ‖F i a‖ ∂μ) :
∑' i, (∫ a, F i a ∂μ) = ∫ a, (∑' i, F i a) ∂μ :=
(hasSum_integral_of_summable_integral_norm hF_int hF_sum).tsum_eq
end MeasureTheory
section TendstoMono
variable {α E : Type*} [MeasurableSpace α]
{μ : Measure α} [NormedAddCommGroup E] [NormedSpace ℝ E] {s : ℕ → Set α}
{f : α → E}
theorem _root_.Antitone.tendsto_setIntegral (hsm : ∀ i, MeasurableSet (s i)) (h_anti : Antitone s)
(hfi : IntegrableOn f (s 0) μ) :
Tendsto (fun i => ∫ a in s i, f a ∂μ) atTop (𝓝 (∫ a in ⋂ n, s n, f a ∂μ)) := by
let bound : α → ℝ := indicator (s 0) fun a => ‖f a‖
have h_int_eq : (fun i => ∫ a in s i, f a ∂μ) = fun i => ∫ a, (s i).indicator f a ∂μ :=
funext fun i => (integral_indicator (hsm i)).symm
rw [h_int_eq]
rw [← integral_indicator (MeasurableSet.iInter hsm)]
refine tendsto_integral_of_dominated_convergence bound ?_ ?_ ?_ ?_
· intro n
rw [aestronglyMeasurable_indicator_iff (hsm n)]
exact (IntegrableOn.mono_set hfi (h_anti (zero_le n))).1
· rw [integrable_indicator_iff (hsm 0)]
exact hfi.norm
· simp_rw [norm_indicator_eq_indicator_norm]
refine fun n => eventually_of_forall fun x => ?_
exact indicator_le_indicator_of_subset (h_anti (zero_le n)) (fun a => norm_nonneg _) _
· filter_upwards [] with a using le_trans (h_anti.tendsto_indicator _ _ _) (pure_le_nhds _)
#align antitone.tendsto_set_integral Antitone.tendsto_setIntegral
@[deprecated (since := "2024-04-17")]
alias _root_.Antitone.tendsto_set_integral := _root_.Antitone.tendsto_setIntegral
end TendstoMono
/-!
## The Lebesgue dominated convergence theorem for interval integrals
As an application, we show continuity of parametric integrals.
-/
namespace intervalIntegral
section DCT
variable {ι 𝕜 E F : Type*} [NormedAddCommGroup E] [CompleteSpace E] [NormedSpace ℝ E]
{a b : ℝ} {f : ℝ → E} {μ : Measure ℝ}
/-- Lebesgue dominated convergence theorem for filters with a countable basis -/
nonrec theorem tendsto_integral_filter_of_dominated_convergence {ι} {l : Filter ι}
[l.IsCountablyGenerated] {F : ι → ℝ → E} (bound : ℝ → ℝ)
(hF_meas : ∀ᶠ n in l, AEStronglyMeasurable (F n) (μ.restrict (Ι a b)))
(h_bound : ∀ᶠ n in l, ∀ᵐ x ∂μ, x ∈ Ι a b → ‖F n x‖ ≤ bound x)
(bound_integrable : IntervalIntegrable bound μ a b)
(h_lim : ∀ᵐ x ∂μ, x ∈ Ι a b → Tendsto (fun n => F n x) l (𝓝 (f x))) :
Tendsto (fun n => ∫ x in a..b, F n x ∂μ) l (𝓝 <| ∫ x in a..b, f x ∂μ) := by
simp only [intervalIntegrable_iff, intervalIntegral_eq_integral_uIoc,
← ae_restrict_iff' (α := ℝ) (μ := μ) measurableSet_uIoc] at *
exact tendsto_const_nhds.smul <|
tendsto_integral_filter_of_dominated_convergence bound hF_meas h_bound bound_integrable h_lim
#align interval_integral.tendsto_integral_filter_of_dominated_convergence intervalIntegral.tendsto_integral_filter_of_dominated_convergence
/-- Lebesgue dominated convergence theorem for parametric interval integrals. -/
nonrec theorem hasSum_integral_of_dominated_convergence {ι} [Countable ι] {F : ι → ℝ → E}
(bound : ι → ℝ → ℝ) (hF_meas : ∀ n, AEStronglyMeasurable (F n) (μ.restrict (Ι a b)))
(h_bound : ∀ n, ∀ᵐ t ∂μ, t ∈ Ι a b → ‖F n t‖ ≤ bound n t)
(bound_summable : ∀ᵐ t ∂μ, t ∈ Ι a b → Summable fun n => bound n t)
(bound_integrable : IntervalIntegrable (fun t => ∑' n, bound n t) μ a b)
(h_lim : ∀ᵐ t ∂μ, t ∈ Ι a b → HasSum (fun n => F n t) (f t)) :
HasSum (fun n => ∫ t in a..b, F n t ∂μ) (∫ t in a..b, f t ∂μ) := by
simp only [intervalIntegrable_iff, intervalIntegral_eq_integral_uIoc, ←
ae_restrict_iff' (α := ℝ) (μ := μ) measurableSet_uIoc] at *
exact
(hasSum_integral_of_dominated_convergence bound hF_meas h_bound bound_summable bound_integrable
h_lim).const_smul
_
#align interval_integral.has_sum_integral_of_dominated_convergence intervalIntegral.hasSum_integral_of_dominated_convergence
/-- Interval integrals commute with countable sums, when the supremum norms are summable (a
special case of the dominated convergence theorem). -/
theorem hasSum_intervalIntegral_of_summable_norm [Countable ι] {f : ι → C(ℝ, E)}
(hf_sum : Summable fun i : ι => ‖(f i).restrict (⟨uIcc a b, isCompact_uIcc⟩ : Compacts ℝ)‖) :
HasSum (fun i : ι => ∫ x in a..b, f i x) (∫ x in a..b, ∑' i : ι, f i x) := by
apply hasSum_integral_of_dominated_convergence
(fun i (x : ℝ) => ‖(f i).restrict ↑(⟨uIcc a b, isCompact_uIcc⟩ : Compacts ℝ)‖)
(fun i => (map_continuous <| f i).aestronglyMeasurable)
· intro i; filter_upwards with x hx
apply ContinuousMap.norm_coe_le_norm ((f i).restrict _) ⟨x, _⟩
exact ⟨hx.1.le, hx.2⟩
· exact ae_of_all _ fun x _ => hf_sum
· exact intervalIntegrable_const
· refine ae_of_all _ fun x hx => Summable.hasSum ?_
let x : (⟨uIcc a b, isCompact_uIcc⟩ : Compacts ℝ) := ⟨x, ?_⟩; swap
· exact ⟨hx.1.le, hx.2⟩
have := hf_sum.of_norm
simpa only [Compacts.coe_mk, ContinuousMap.restrict_apply]
using ContinuousMap.summable_apply this x
#align interval_integral.has_sum_interval_integral_of_summable_norm intervalIntegral.hasSum_intervalIntegral_of_summable_norm
theorem tsum_intervalIntegral_eq_of_summable_norm [Countable ι] {f : ι → C(ℝ, E)}
(hf_sum : Summable fun i : ι => ‖(f i).restrict (⟨uIcc a b, isCompact_uIcc⟩ : Compacts ℝ)‖) :
∑' i : ι, ∫ x in a..b, f i x = ∫ x in a..b, ∑' i : ι, f i x :=
(hasSum_intervalIntegral_of_summable_norm hf_sum).tsum_eq
#align interval_integral.tsum_interval_integral_eq_of_summable_norm intervalIntegral.tsum_intervalIntegral_eq_of_summable_norm
variable {X : Type*} [TopologicalSpace X] [FirstCountableTopology X]
/-- Continuity of interval integral with respect to a parameter, at a point within a set.
Given `F : X → ℝ → E`, assume `F x` is ae-measurable on `[a, b]` for `x` in a
neighborhood of `x₀` within `s` and at `x₀`, and assume it is bounded by a function integrable
on `[a, b]` independent of `x` in a neighborhood of `x₀` within `s`. If `(fun x ↦ F x t)`
is continuous at `x₀` within `s` for almost every `t` in `[a, b]`
then the same holds for `(fun x ↦ ∫ t in a..b, F x t ∂μ) s x₀`. -/
theorem continuousWithinAt_of_dominated_interval {F : X → ℝ → E} {x₀ : X} {bound : ℝ → ℝ} {a b : ℝ}
{s : Set X} (hF_meas : ∀ᶠ x in 𝓝[s] x₀, AEStronglyMeasurable (F x) (μ.restrict <| Ι a b))
(h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ t ∂μ, t ∈ Ι a b → ‖F x t‖ ≤ bound t)
(bound_integrable : IntervalIntegrable bound μ a b)
(h_cont : ∀ᵐ t ∂μ, t ∈ Ι a b → ContinuousWithinAt (fun x => F x t) s x₀) :
ContinuousWithinAt (fun x => ∫ t in a..b, F x t ∂μ) s x₀ :=
tendsto_integral_filter_of_dominated_convergence bound hF_meas h_bound bound_integrable h_cont
#align interval_integral.continuous_within_at_of_dominated_interval intervalIntegral.continuousWithinAt_of_dominated_interval
/-- Continuity of interval integral with respect to a parameter at a point.
Given `F : X → ℝ → E`, assume `F x` is ae-measurable on `[a, b]` for `x` in a
neighborhood of `x₀`, and assume it is bounded by a function integrable on
`[a, b]` independent of `x` in a neighborhood of `x₀`. If `(fun x ↦ F x t)`
is continuous at `x₀` for almost every `t` in `[a, b]`
then the same holds for `(fun x ↦ ∫ t in a..b, F x t ∂μ) s x₀`. -/
theorem continuousAt_of_dominated_interval {F : X → ℝ → E} {x₀ : X} {bound : ℝ → ℝ} {a b : ℝ}
(hF_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (F x) (μ.restrict <| Ι a b))
(h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ t ∂μ, t ∈ Ι a b → ‖F x t‖ ≤ bound t)
(bound_integrable : IntervalIntegrable bound μ a b)
(h_cont : ∀ᵐ t ∂μ, t ∈ Ι a b → ContinuousAt (fun x => F x t) x₀) :
ContinuousAt (fun x => ∫ t in a..b, F x t ∂μ) x₀ :=
tendsto_integral_filter_of_dominated_convergence bound hF_meas h_bound bound_integrable h_cont
#align interval_integral.continuous_at_of_dominated_interval intervalIntegral.continuousAt_of_dominated_interval
/-- Continuity of interval integral with respect to a parameter.
Given `F : X → ℝ → E`, assume each `F x` is ae-measurable on `[a, b]`,
and assume it is bounded by a function integrable on `[a, b]` independent of `x`.
If `(fun x ↦ F x t)` is continuous for almost every `t` in `[a, b]`
then the same holds for `(fun x ↦ ∫ t in a..b, F x t ∂μ) s x₀`. -/
theorem continuous_of_dominated_interval {F : X → ℝ → E} {bound : ℝ → ℝ} {a b : ℝ}
(hF_meas : ∀ x, AEStronglyMeasurable (F x) <| μ.restrict <| Ι a b)
(h_bound : ∀ x, ∀ᵐ t ∂μ, t ∈ Ι a b → ‖F x t‖ ≤ bound t)
(bound_integrable : IntervalIntegrable bound μ a b)
(h_cont : ∀ᵐ t ∂μ, t ∈ Ι a b → Continuous fun x => F x t) :
Continuous fun x => ∫ t in a..b, F x t ∂μ :=
continuous_iff_continuousAt.mpr fun _ =>
continuousAt_of_dominated_interval (eventually_of_forall hF_meas) (eventually_of_forall h_bound)
bound_integrable <|
h_cont.mono fun _ himp hx => (himp hx).continuousAt
#align interval_integral.continuous_of_dominated_interval intervalIntegral.continuous_of_dominated_interval
end DCT
section ContinuousPrimitive
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [CompleteSpace E] [NormedSpace ℝ E]
{a b b₀ b₁ b₂ : ℝ} {μ : Measure ℝ} {f : ℝ → E}
theorem continuousWithinAt_primitive (hb₀ : μ {b₀} = 0)
(h_int : IntervalIntegrable f μ (min a b₁) (max a b₂)) :
ContinuousWithinAt (fun b => ∫ x in a..b, f x ∂μ) (Icc b₁ b₂) b₀ := by
by_cases h₀ : b₀ ∈ Icc b₁ b₂
· have h₁₂ : b₁ ≤ b₂ := h₀.1.trans h₀.2
have min₁₂ : min b₁ b₂ = b₁ := min_eq_left h₁₂
have h_int' : ∀ {x}, x ∈ Icc b₁ b₂ → IntervalIntegrable f μ b₁ x := by
rintro x ⟨h₁, h₂⟩
apply h_int.mono_set
apply uIcc_subset_uIcc
· exact ⟨min_le_of_left_le (min_le_right a b₁),
h₁.trans (h₂.trans <| le_max_of_le_right <| le_max_right _ _)⟩
· exact ⟨min_le_of_left_le <| (min_le_right _ _).trans h₁,
le_max_of_le_right <| h₂.trans <| le_max_right _ _⟩
have : ∀ b ∈ Icc b₁ b₂,
∫ x in a..b, f x ∂μ = (∫ x in a..b₁, f x ∂μ) + ∫ x in b₁..b, f x ∂μ := by
rintro b ⟨h₁, h₂⟩
rw [← integral_add_adjacent_intervals _ (h_int' ⟨h₁, h₂⟩)]
apply h_int.mono_set
apply uIcc_subset_uIcc
· exact ⟨min_le_of_left_le (min_le_left a b₁), le_max_of_le_right (le_max_left _ _)⟩
· exact ⟨min_le_of_left_le (min_le_right _ _),
le_max_of_le_right (h₁.trans <| h₂.trans (le_max_right a b₂))⟩
apply ContinuousWithinAt.congr _ this (this _ h₀); clear this
refine continuousWithinAt_const.add ?_
have :
(fun b => ∫ x in b₁..b, f x ∂μ) =ᶠ[𝓝[Icc b₁ b₂] b₀] fun b =>
∫ x in b₁..b₂, indicator {x | x ≤ b} f x ∂μ := by
apply eventuallyEq_of_mem self_mem_nhdsWithin
exact fun b b_in => (integral_indicator b_in).symm
apply ContinuousWithinAt.congr_of_eventuallyEq _ this (integral_indicator h₀).symm
have : IntervalIntegrable (fun x => ‖f x‖) μ b₁ b₂ :=
IntervalIntegrable.norm (h_int' <| right_mem_Icc.mpr h₁₂)
refine continuousWithinAt_of_dominated_interval ?_ ?_ this ?_ <;> clear this
· filter_upwards [self_mem_nhdsWithin]
intro x hx
erw [aestronglyMeasurable_indicator_iff, Measure.restrict_restrict, Iic_inter_Ioc_of_le]
· rw [min₁₂]
exact (h_int' hx).1.aestronglyMeasurable
· exact le_max_of_le_right hx.2
exacts [measurableSet_Iic, measurableSet_Iic]
· filter_upwards with x; filter_upwards with t
dsimp [indicator]
split_ifs <;> simp
· have : ∀ᵐ t ∂μ, t < b₀ ∨ b₀ < t := by
filter_upwards [compl_mem_ae_iff.mpr hb₀] with x hx using Ne.lt_or_lt hx
apply this.mono
rintro x₀ (hx₀ | hx₀) -
· have : ∀ᶠ x in 𝓝[Icc b₁ b₂] b₀, {t : ℝ | t ≤ x}.indicator f x₀ = f x₀ := by
apply mem_nhdsWithin_of_mem_nhds
apply Eventually.mono (Ioi_mem_nhds hx₀)
intro x hx
simp [hx.le]
apply continuousWithinAt_const.congr_of_eventuallyEq this
simp [hx₀.le]
· have : ∀ᶠ x in 𝓝[Icc b₁ b₂] b₀, {t : ℝ | t ≤ x}.indicator f x₀ = 0 := by
apply mem_nhdsWithin_of_mem_nhds
apply Eventually.mono (Iio_mem_nhds hx₀)
intro x hx
simp [hx]
apply continuousWithinAt_const.congr_of_eventuallyEq this
simp [hx₀]
· apply continuousWithinAt_of_not_mem_closure
rwa [closure_Icc]
#align interval_integral.continuous_within_at_primitive intervalIntegral.continuousWithinAt_primitive
variable {X : Type*} [TopologicalSpace X] [FirstCountableTopology X]
{E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
theorem continuousAt_parametric_primitive_of_dominated {F : X → ℝ → E} (bound : ℝ → ℝ) (a b : ℝ)
{a₀ b₀ : ℝ} {x₀ : X} (hF_meas : ∀ x, AEStronglyMeasurable (F x) (μ.restrict <| Ι a b))
(h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ t ∂μ.restrict <| Ι a b, ‖F x t‖ ≤ bound t)
(bound_integrable : IntervalIntegrable bound μ a b)
(h_cont : ∀ᵐ t ∂μ.restrict <| Ι a b, ContinuousAt (fun x ↦ F x t) x₀) (ha₀ : a₀ ∈ Ioo a b)
(hb₀ : b₀ ∈ Ioo a b) (hμb₀ : μ {b₀} = 0) :
ContinuousAt (fun p : X × ℝ ↦ ∫ t : ℝ in a₀..p.2, F p.1 t ∂μ) (x₀, b₀) := by
have hsub : ∀ {a₀ b₀}, a₀ ∈ Ioo a b → b₀ ∈ Ioo a b → Ι a₀ b₀ ⊆ Ι a b := fun ha₀ hb₀ ↦
(ordConnected_Ioo.uIoc_subset ha₀ hb₀).trans (Ioo_subset_Ioc_self.trans Ioc_subset_uIoc)
have Ioo_nhds : Ioo a b ∈ 𝓝 b₀ := Ioo_mem_nhds hb₀.1 hb₀.2
have Icc_nhds : Icc a b ∈ 𝓝 b₀ := Icc_mem_nhds hb₀.1 hb₀.2
have hx₀ : ∀ᵐ t : ℝ ∂μ.restrict (Ι a b), ‖F x₀ t‖ ≤ bound t := h_bound.self_of_nhds
have : ∀ᶠ p : X × ℝ in 𝓝 (x₀, b₀),
∫ s in a₀..p.2, F p.1 s ∂μ =
∫ s in a₀..b₀, F p.1 s ∂μ + ∫ s in b₀..p.2, F x₀ s ∂μ +
∫ s in b₀..p.2, F p.1 s - F x₀ s ∂μ := by
rw [nhds_prod_eq]
refine (h_bound.prod_mk Ioo_nhds).mono ?_
rintro ⟨x, t⟩ ⟨hx : ∀ᵐ t : ℝ ∂μ.restrict (Ι a b), ‖F x t‖ ≤ bound t, ht : t ∈ Ioo a b⟩
dsimp (config := { eta := false })
have hiF : ∀ {x a₀ b₀},
(∀ᵐ t : ℝ ∂μ.restrict (Ι a b), ‖F x t‖ ≤ bound t) → a₀ ∈ Ioo a b → b₀ ∈ Ioo a b →
IntervalIntegrable (F x) μ a₀ b₀ := fun {x a₀ b₀} hx ha₀ hb₀ ↦
(bound_integrable.mono_set_ae <| eventually_of_forall <| hsub ha₀ hb₀).mono_fun'
((hF_meas x).mono_set <| hsub ha₀ hb₀)
(ae_restrict_of_ae_restrict_of_subset (hsub ha₀ hb₀) hx)
rw [intervalIntegral.integral_sub, add_assoc, add_sub_cancel,
intervalIntegral.integral_add_adjacent_intervals]
· exact hiF hx ha₀ hb₀
· exact hiF hx hb₀ ht
· exact hiF hx hb₀ ht
· exact hiF hx₀ hb₀ ht
rw [continuousAt_congr this]; clear this
refine (ContinuousAt.add ?_ ?_).add ?_
· exact (intervalIntegral.continuousAt_of_dominated_interval
(eventually_of_forall fun x ↦ (hF_meas x).mono_set <| hsub ha₀ hb₀)
(h_bound.mono fun x hx ↦
ae_imp_of_ae_restrict <| ae_restrict_of_ae_restrict_of_subset (hsub ha₀ hb₀) hx)
(bound_integrable.mono_set_ae <| eventually_of_forall <| hsub ha₀ hb₀) <|
ae_imp_of_ae_restrict <| ae_restrict_of_ae_restrict_of_subset (hsub ha₀ hb₀) h_cont).fst'
· refine (?_ : ContinuousAt (fun t ↦ ∫ s in b₀..t, F x₀ s ∂μ) b₀).snd'
apply ContinuousWithinAt.continuousAt _ (Icc_mem_nhds hb₀.1 hb₀.2)
apply intervalIntegral.continuousWithinAt_primitive hμb₀
rw [min_eq_right hb₀.1.le, max_eq_right hb₀.2.le]
exact bound_integrable.mono_fun' (hF_meas x₀) hx₀
· suffices Tendsto (fun x : X × ℝ ↦ ∫ s in b₀..x.2, F x.1 s - F x₀ s ∂μ) (𝓝 (x₀, b₀)) (𝓝 0) by
simpa [ContinuousAt]
have : ∀ᶠ p : X × ℝ in 𝓝 (x₀, b₀),
‖∫ s in b₀..p.2, F p.1 s - F x₀ s ∂μ‖ ≤ |∫ s in b₀..p.2, 2 * bound s ∂μ| := by
rw [nhds_prod_eq]
refine (h_bound.prod_mk Ioo_nhds).mono ?_
rintro ⟨x, t⟩ ⟨hx : ∀ᵐ t ∂μ.restrict (Ι a b), ‖F x t‖ ≤ bound t, ht : t ∈ Ioo a b⟩
have H : ∀ᵐ t : ℝ ∂μ.restrict (Ι b₀ t), ‖F x t - F x₀ t‖ ≤ 2 * bound t := by
apply (ae_restrict_of_ae_restrict_of_subset (hsub hb₀ ht) (hx.and hx₀)).mono
rintro s ⟨hs₁, hs₂⟩
calc
‖F x s - F x₀ s‖ ≤ ‖F x s‖ + ‖F x₀ s‖ := norm_sub_le _ _
_ ≤ 2 * bound s := by linarith only [hs₁, hs₂]
exact intervalIntegral.norm_integral_le_of_norm_le H
((bound_integrable.mono_set' <| hsub hb₀ ht).const_mul 2)
apply squeeze_zero_norm' this
have : Tendsto (fun t ↦ ∫ s in b₀..t, 2 * bound s ∂μ) (𝓝 b₀) (𝓝 0) := by
suffices ContinuousAt (fun t ↦ ∫ s in b₀..t, 2 * bound s ∂μ) b₀ by
simpa [ContinuousAt] using this
apply ContinuousWithinAt.continuousAt _ Icc_nhds
apply intervalIntegral.continuousWithinAt_primitive hμb₀
apply IntervalIntegrable.const_mul
apply bound_integrable.mono_set'
rw [min_eq_right hb₀.1.le, max_eq_right hb₀.2.le]
rw [nhds_prod_eq]
exact (continuous_abs.tendsto' _ _ abs_zero).comp (this.comp tendsto_snd)
variable [NoAtoms μ]
theorem continuousOn_primitive (h_int : IntegrableOn f (Icc a b) μ) :
ContinuousOn (fun x => ∫ t in Ioc a x, f t ∂μ) (Icc a b) := by
by_cases h : a ≤ b
· have : ∀ x ∈ Icc a b, ∫ t in Ioc a x, f t ∂μ = ∫ t in a..x, f t ∂μ := by
intro x x_in
simp_rw [integral_of_le x_in.1]
rw [continuousOn_congr this]
intro x₀ _
refine continuousWithinAt_primitive (measure_singleton x₀) ?_
simp only [intervalIntegrable_iff_integrableOn_Ioc_of_le, min_eq_left, max_eq_right, h,
min_self]
exact h_int.mono Ioc_subset_Icc_self le_rfl
· rw [Icc_eq_empty h]
exact continuousOn_empty _
#align interval_integral.continuous_on_primitive intervalIntegral.continuousOn_primitive
theorem continuousOn_primitive_Icc (h_int : IntegrableOn f (Icc a b) μ) :
ContinuousOn (fun x => ∫ t in Icc a x, f t ∂μ) (Icc a b) := by
have aux : (fun x => ∫ t in Icc a x, f t ∂μ) = fun x => ∫ t in Ioc a x, f t ∂μ := by
ext x
exact integral_Icc_eq_integral_Ioc
rw [aux]
exact continuousOn_primitive h_int
#align interval_integral.continuous_on_primitive_Icc intervalIntegral.continuousOn_primitive_Icc
/-- Note: this assumes that `f` is `IntervalIntegrable`, in contrast to some other lemmas here. -/
theorem continuousOn_primitive_interval' (h_int : IntervalIntegrable f μ b₁ b₂)
(ha : a ∈ [[b₁, b₂]]) : ContinuousOn (fun b => ∫ x in a..b, f x ∂μ) [[b₁, b₂]] := fun _ _ ↦ by
refine continuousWithinAt_primitive (measure_singleton _) ?_
rw [min_eq_right ha.1, max_eq_right ha.2]
simpa [intervalIntegrable_iff, uIoc] using h_int
#align interval_integral.continuous_on_primitive_interval' intervalIntegral.continuousOn_primitive_interval'
theorem continuousOn_primitive_interval (h_int : IntegrableOn f (uIcc a b) μ) :
ContinuousOn (fun x => ∫ t in a..x, f t ∂μ) (uIcc a b) :=
continuousOn_primitive_interval' h_int.intervalIntegrable left_mem_uIcc
#align interval_integral.continuous_on_primitive_interval intervalIntegral.continuousOn_primitive_interval
theorem continuousOn_primitive_interval_left (h_int : IntegrableOn f (uIcc a b) μ) :
ContinuousOn (fun x => ∫ t in x..b, f t ∂μ) (uIcc a b) := by
rw [uIcc_comm a b] at h_int ⊢
simp only [integral_symm b]
exact (continuousOn_primitive_interval h_int).neg
#align interval_integral.continuous_on_primitive_interval_left intervalIntegral.continuousOn_primitive_interval_left
| Mathlib/MeasureTheory/Integral/DominatedConvergence.lean | 506 | 513 | theorem continuous_primitive (h_int : ∀ a b, IntervalIntegrable f μ a b) (a : ℝ) :
Continuous fun b => ∫ x in a..b, f x ∂μ := by |
rw [continuous_iff_continuousAt]
intro b₀
cases' exists_lt b₀ with b₁ hb₁
cases' exists_gt b₀ with b₂ hb₂
apply ContinuousWithinAt.continuousAt _ (Icc_mem_nhds hb₁ hb₂)
exact continuousWithinAt_primitive (measure_singleton b₀) (h_int _ _)
|
/-
Copyright (c) 2023 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.GroupTheory.Subsemigroup.Center
import Mathlib.RingTheory.NonUnitalSubsemiring.Basic
/-!
# `NonUnitalSubring`s
Let `R` be a non-unital ring. This file defines the "bundled" non-unital subring type
`NonUnitalSubring R`, a type whose terms correspond to non-unital subrings of `R`.
This is the preferred way to talk about non-unital subrings in mathlib.
We prove that non-unital subrings are a complete lattice, and that you can `map` (pushforward) and
`comap` (pull back) them along ring homomorphisms.
We define the `closure` construction from `Set R` to `NonUnitalSubring R`, sending a subset of
`R` to the non-unital subring it generates, and prove that it is a Galois insertion.
## Main definitions
Notation used here:
`(R : Type u) [NonUnitalRing R] (S : Type u) [NonUnitalRing S] (f g : R →ₙ+* S)`
`(A : NonUnitalSubring R) (B : NonUnitalSubring S) (s : Set R)`
* `NonUnitalSubring R` : the type of non-unital subrings of a ring `R`.
* `instance : CompleteLattice (NonUnitalSubring R)` : the complete lattice structure on the
non-unital subrings.
* `NonUnitalSubring.center` : the center of a non-unital ring `R`.
* `NonUnitalSubring.closure` : non-unital subring closure of a set, i.e., the smallest
non-unital subring that includes the set.
* `NonUnitalSubring.gi` : `closure : Set M → NonUnitalSubring M` and coercion
`coe : NonUnitalSubring M → Set M`
form a `GaloisInsertion`.
* `comap f B : NonUnitalSubring A` : the preimage of a non-unital subring `B` along the
non-unital ring homomorphism `f`
* `map f A : NonUnitalSubring B` : the image of a non-unital subring `A` along the
non-unital ring homomorphism `f`.
* `Prod A B : NonUnitalSubring (R × S)` : the product of non-unital subrings
* `f.range : NonUnitalSubring B` : the range of the non-unital ring homomorphism `f`.
* `eq_locus f g : NonUnitalSubring R` : given non-unital ring homomorphisms `f g : R →ₙ+* S`,
the non-unital subring of `R` where `f x = g x`
## Implementation notes
A non-unital subring is implemented as a `NonUnitalSubsemiring` which is also an
additive subgroup.
Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although
`∈` is defined as membership of a non-unital subring's underlying set.
## Tags
non-unital subring
-/
universe u v w
section Basic
variable {R : Type u} {S : Type v} {T : Type w} [NonUnitalNonAssocRing R]
section NonUnitalSubringClass
/-- `NonUnitalSubringClass S R` states that `S` is a type of subsets `s ⊆ R` that
are both a multiplicative submonoid and an additive subgroup. -/
class NonUnitalSubringClass (S : Type*) (R : Type u) [NonUnitalNonAssocRing R]
[SetLike S R] extends NonUnitalSubsemiringClass S R, NegMemClass S R : Prop where
-- See note [lower instance priority]
instance (priority := 100) NonUnitalSubringClass.addSubgroupClass (S : Type*) (R : Type u)
[SetLike S R] [NonUnitalNonAssocRing R] [h : NonUnitalSubringClass S R] :
AddSubgroupClass S R :=
{ h with }
variable [SetLike S R] [hSR : NonUnitalSubringClass S R] (s : S)
namespace NonUnitalSubringClass
-- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`.
/-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/
instance (priority := 75) toNonUnitalNonAssocRing : NonUnitalNonAssocRing s :=
Subtype.val_injective.nonUnitalNonAssocRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl
-- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`.
/-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/
instance (priority := 75) toNonUnitalRing {R : Type*} [NonUnitalRing R] [SetLike S R]
[NonUnitalSubringClass S R] (s : S) : NonUnitalRing s :=
Subtype.val_injective.nonUnitalRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl
-- Prefer subclasses of `NonUnitalRing` over subclasses of `NonUnitalSubringClass`.
/-- A non-unital subring of a `NonUnitalCommRing` is a `NonUnitalCommRing`. -/
instance (priority := 75) toNonUnitalCommRing {R} [NonUnitalCommRing R] [SetLike S R]
[NonUnitalSubringClass S R] : NonUnitalCommRing s :=
Subtype.val_injective.nonUnitalCommRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl
/-- The natural non-unital ring hom from a non-unital subring of a non-unital ring `R` to `R`. -/
def subtype (s : S) : s →ₙ+* R :=
{ NonUnitalSubsemiringClass.subtype s,
AddSubgroupClass.subtype s with
toFun := Subtype.val }
@[simp]
theorem coe_subtype : (subtype s : s → R) = Subtype.val :=
rfl
end NonUnitalSubringClass
end NonUnitalSubringClass
variable [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
/-- `NonUnitalSubring R` is the type of non-unital subrings of `R`. A non-unital subring of `R`
is a subset `s` that is a multiplicative subsemigroup and an additive subgroup. Note in particular
that it shares the same 0 as R. -/
structure NonUnitalSubring (R : Type u) [NonUnitalNonAssocRing R] extends
NonUnitalSubsemiring R, AddSubgroup R
/-- Reinterpret a `NonUnitalSubring` as a `NonUnitalSubsemiring`. -/
add_decl_doc NonUnitalSubring.toNonUnitalSubsemiring
/-- Reinterpret a `NonUnitalSubring` as an `AddSubgroup`. -/
add_decl_doc NonUnitalSubring.toAddSubgroup
namespace NonUnitalSubring
/-- The underlying submonoid of a `NonUnitalSubring`. -/
def toSubsemigroup (s : NonUnitalSubring R) : Subsemigroup R :=
{ s.toNonUnitalSubsemiring.toSubsemigroup with carrier := s.carrier }
instance : SetLike (NonUnitalSubring R) R where
coe s := s.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h
instance : NonUnitalSubringClass (NonUnitalSubring R) R where
zero_mem s := s.zero_mem'
add_mem {s} := s.add_mem'
mul_mem {s} := s.mul_mem'
neg_mem {s} := s.neg_mem'
theorem mem_carrier {s : NonUnitalSubring R} {x : R} : x ∈ s.toNonUnitalSubsemiring ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem mem_mk {S : NonUnitalSubsemiring R} {x : R} (h) :
x ∈ (⟨S, h⟩ : NonUnitalSubring R) ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_set_mk (S : NonUnitalSubsemiring R) (h) :
((⟨S, h⟩ : NonUnitalSubring R) : Set R) = S :=
rfl
@[simp]
theorem mk_le_mk {S S' : NonUnitalSubsemiring R} (h h') :
(⟨S, h⟩ : NonUnitalSubring R) ≤ (⟨S', h'⟩ : NonUnitalSubring R) ↔ S ≤ S' :=
Iff.rfl
/-- Two non-unital subrings are equal if they have the same elements. -/
@[ext]
theorem ext {S T : NonUnitalSubring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
/-- Copy of a non-unital subring with a new `carrier` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : NonUnitalSubring R :=
{ S.toNonUnitalSubsemiring.copy s hs with
carrier := s
neg_mem' := hs.symm ▸ S.neg_mem' }
@[simp]
theorem coe_copy (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s :=
rfl
theorem copy_eq (S : NonUnitalSubring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
theorem toNonUnitalSubsemiring_injective :
Function.Injective (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R)
| _r, _s, h => ext (SetLike.ext_iff.mp h : _)
@[mono]
theorem toNonUnitalSubsemiring_strictMono :
StrictMono (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R) := fun _ _ =>
id
@[mono]
theorem toNonUnitalSubsemiring_mono :
Monotone (toNonUnitalSubsemiring : NonUnitalSubring R → NonUnitalSubsemiring R) :=
toNonUnitalSubsemiring_strictMono.monotone
theorem toAddSubgroup_injective :
Function.Injective (toAddSubgroup : NonUnitalSubring R → AddSubgroup R)
| _r, _s, h => ext (SetLike.ext_iff.mp h : _)
@[mono]
theorem toAddSubgroup_strictMono :
StrictMono (toAddSubgroup : NonUnitalSubring R → AddSubgroup R) := fun _ _ => id
@[mono]
theorem toAddSubgroup_mono : Monotone (toAddSubgroup : NonUnitalSubring R → AddSubgroup R) :=
toAddSubgroup_strictMono.monotone
theorem toSubsemigroup_injective :
Function.Injective (toSubsemigroup : NonUnitalSubring R → Subsemigroup R)
| _r, _s, h => ext (SetLike.ext_iff.mp h : _)
@[mono]
theorem toSubsemigroup_strictMono :
StrictMono (toSubsemigroup : NonUnitalSubring R → Subsemigroup R) := fun _ _ => id
@[mono]
theorem toSubsemigroup_mono : Monotone (toSubsemigroup : NonUnitalSubring R → Subsemigroup R) :=
toSubsemigroup_strictMono.monotone
/-- Construct a `NonUnitalSubring R` from a set `s`, a subsemigroup `sm`, and an additive
subgroup `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/
protected def mk' (s : Set R) (sm : Subsemigroup R) (sa : AddSubgroup R) (hm : ↑sm = s)
(ha : ↑sa = s) : NonUnitalSubring R :=
{ sm.copy s hm.symm, sa.copy s ha.symm with }
@[simp]
theorem coe_mk' {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R}
(ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha : Set R) = s :=
rfl
@[simp]
theorem mem_mk' {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s)
{x : R} : x ∈ NonUnitalSubring.mk' s sm sa hm ha ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem mk'_toSubsemigroup {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R}
(ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha).toSubsemigroup = sm :=
SetLike.coe_injective hm.symm
@[simp]
theorem mk'_toAddSubgroup {s : Set R} {sm : Subsemigroup R} (hm : ↑sm = s) {sa : AddSubgroup R}
(ha : ↑sa = s) : (NonUnitalSubring.mk' s sm sa hm ha).toAddSubgroup = sa :=
SetLike.coe_injective ha.symm
end NonUnitalSubring
namespace NonUnitalSubring
variable (s : NonUnitalSubring R)
/-- A non-unital subring contains the ring's 0. -/
protected theorem zero_mem : (0 : R) ∈ s :=
zero_mem _
/-- A non-unital subring is closed under multiplication. -/
protected theorem mul_mem {x y : R} : x ∈ s → y ∈ s → x * y ∈ s :=
mul_mem
/-- A non-unital subring is closed under addition. -/
protected theorem add_mem {x y : R} : x ∈ s → y ∈ s → x + y ∈ s :=
add_mem
/-- A non-unital subring is closed under negation. -/
protected theorem neg_mem {x : R} : x ∈ s → -x ∈ s :=
neg_mem
/-- A non-unital subring is closed under subtraction -/
protected theorem sub_mem {x y : R} (hx : x ∈ s) (hy : y ∈ s) : x - y ∈ s :=
sub_mem hx hy
/-- Sum of a list of elements in a non-unital subring is in the non-unital subring. -/
protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s :=
list_sum_mem
/-- Sum of a multiset of elements in a `NonUnitalSubring` of a `NonUnitalRing` is
in the `NonUnitalSubring`. -/
protected theorem multiset_sum_mem {R} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R)
(m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.sum ∈ s :=
multiset_sum_mem _
/-- Sum of elements in a `NonUnitalSubring` of a `NonUnitalRing` indexed by a `Finset`
is in the `NonUnitalSubring`. -/
protected theorem sum_mem {R : Type*} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R)
{ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∑ i ∈ t, f i) ∈ s :=
sum_mem h
/-- A non-unital subring of a non-unital ring inherits a non-unital ring structure -/
instance toNonUnitalRing {R : Type*} [NonUnitalRing R] (s : NonUnitalSubring R) :
NonUnitalRing s :=
Subtype.coe_injective.nonUnitalRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl
protected theorem zsmul_mem {x : R} (hx : x ∈ s) (n : ℤ) : n • x ∈ s :=
zsmul_mem hx n
@[simp, norm_cast]
theorem val_add (x y : s) : (↑(x + y) : R) = ↑x + ↑y :=
rfl
@[simp, norm_cast]
theorem val_neg (x : s) : (↑(-x) : R) = -↑x :=
rfl
@[simp, norm_cast]
theorem val_mul (x y : s) : (↑(x * y) : R) = ↑x * ↑y :=
rfl
@[simp, norm_cast]
theorem val_zero : ((0 : s) : R) = 0 :=
rfl
theorem coe_eq_zero_iff {x : s} : (x : R) = 0 ↔ x = 0 := by
simp
/-- A non-unital subring of a `NonUnitalCommRing` is a `NonUnitalCommRing`. -/
instance toNonUnitalCommRing {R} [NonUnitalCommRing R] (s : NonUnitalSubring R) :
NonUnitalCommRing s :=
Subtype.coe_injective.nonUnitalCommRing _ rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl
/-! ## Partial order -/
@[simp]
theorem mem_toSubsemigroup {s : NonUnitalSubring R} {x : R} : x ∈ s.toSubsemigroup ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem coe_toSubsemigroup (s : NonUnitalSubring R) : (s.toSubsemigroup : Set R) = s :=
rfl
@[simp]
theorem mem_toAddSubgroup {s : NonUnitalSubring R} {x : R} : x ∈ s.toAddSubgroup ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem coe_toAddSubgroup (s : NonUnitalSubring R) : (s.toAddSubgroup : Set R) = s :=
rfl
@[simp]
theorem mem_toNonUnitalSubsemiring {s : NonUnitalSubring R} {x : R} :
x ∈ s.toNonUnitalSubsemiring ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem coe_toNonUnitalSubsemiring (s : NonUnitalSubring R) :
(s.toNonUnitalSubsemiring : Set R) = s :=
rfl
/-! ## top -/
/-- The non-unital subring `R` of the ring `R`. -/
instance : Top (NonUnitalSubring R) :=
⟨{ (⊤ : Subsemigroup R), (⊤ : AddSubgroup R) with }⟩
@[simp]
theorem mem_top (x : R) : x ∈ (⊤ : NonUnitalSubring R) :=
Set.mem_univ x
@[simp]
theorem coe_top : ((⊤ : NonUnitalSubring R) : Set R) = Set.univ :=
rfl
/-- The ring equiv between the top element of `NonUnitalSubring R` and `R`. -/
@[simps!]
def topEquiv : (⊤ : NonUnitalSubring R) ≃+* R := NonUnitalSubsemiring.topEquiv
end NonUnitalSubring
end Basic
section Hom
namespace NonUnitalSubring
variable {F : Type w} {R : Type u} {S : Type v} {T : Type*} {SR : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
[FunLike F R S] [NonUnitalRingHomClass F R S] (s : NonUnitalSubring R)
/-! ## comap -/
/-- The preimage of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/
def comap {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring S) :
NonUnitalSubring R :=
{ s.toSubsemigroup.comap (f : R →ₙ* S), s.toAddSubgroup.comap (f : R →+ S) with
carrier := f ⁻¹' s.carrier }
@[simp]
theorem coe_comap (s : NonUnitalSubring S) (f : F) : (s.comap f : Set R) = f ⁻¹' s :=
rfl
@[simp]
theorem mem_comap {s : NonUnitalSubring S} {f : F} {x : R} : x ∈ s.comap f ↔ f x ∈ s :=
Iff.rfl
theorem comap_comap (s : NonUnitalSubring T) (g : S →ₙ+* T) (f : R →ₙ+* S) :
(s.comap g).comap f = s.comap (g.comp f) :=
rfl
/-! ## map -/
/-- The image of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/
def map {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring R) :
NonUnitalSubring S :=
{ s.toSubsemigroup.map (f : R →ₙ* S), s.toAddSubgroup.map (f : R →+ S) with
carrier := f '' s.carrier }
@[simp]
theorem coe_map (f : F) (s : NonUnitalSubring R) : (s.map f : Set S) = f '' s :=
rfl
@[simp]
theorem mem_map {f : F} {s : NonUnitalSubring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y :=
Set.mem_image _ _ _
@[simp]
theorem map_id : s.map (NonUnitalRingHom.id R) = s :=
SetLike.coe_injective <| Set.image_id _
theorem map_map (g : S →ₙ+* T) (f : R →ₙ+* S) : (s.map f).map g = s.map (g.comp f) :=
SetLike.coe_injective <| Set.image_image _ _ _
theorem map_le_iff_le_comap {f : F} {s : NonUnitalSubring R} {t : NonUnitalSubring S} :
s.map f ≤ t ↔ s ≤ t.comap f :=
Set.image_subset_iff
theorem gc_map_comap (f : F) :
GaloisConnection (map f : NonUnitalSubring R → NonUnitalSubring S) (comap f) := fun _S _T =>
map_le_iff_le_comap
/-- A `NonUnitalSubring` is isomorphic to its image under an injective function -/
noncomputable def equivMapOfInjective (f : F) (hf : Function.Injective (f : R → S)) :
s ≃+* s.map f :=
{
Equiv.Set.image f s
hf with
map_mul' := fun _ _ => Subtype.ext (map_mul f _ _)
map_add' := fun _ _ => Subtype.ext (map_add f _ _) }
@[simp]
theorem coe_equivMapOfInjective_apply (f : F) (hf : Function.Injective f) (x : s) :
(equivMapOfInjective s f hf x : S) = f x :=
rfl
end NonUnitalSubring
namespace NonUnitalRingHom
variable {R : Type u} {S : Type v} {T : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
(g : S →ₙ+* T) (f : R →ₙ+* S)
/-! ## range -/
/-- The range of a ring homomorphism, as a `NonUnitalSubring` of the target.
See Note [range copy pattern]. -/
def range {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
(f : R →ₙ+* S) : NonUnitalSubring S :=
((⊤ : NonUnitalSubring R).map f).copy (Set.range f) Set.image_univ.symm
@[simp]
theorem coe_range : (f.range : Set S) = Set.range f :=
rfl
@[simp]
theorem mem_range {f : R →ₙ+* S} {y : S} : y ∈ f.range ↔ ∃ x, f x = y :=
Iff.rfl
| Mathlib/RingTheory/NonUnitalSubring/Basic.lean | 486 | 486 | theorem range_eq_map (f : R →ₙ+* S) : f.range = NonUnitalSubring.map f ⊤ := by | ext; simp
|
/-
Copyright (c) 2021 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Algebra.BigOperators.GroupWithZero.Finset
import Mathlib.Data.Finite.Card
import Mathlib.GroupTheory.Finiteness
import Mathlib.GroupTheory.GroupAction.Quotient
#align_import group_theory.index from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988"
/-!
# Index of a Subgroup
In this file we define the index of a subgroup, and prove several divisibility properties.
Several theorems proved in this file are known as Lagrange's theorem.
## Main definitions
- `H.index` : the index of `H : Subgroup G` as a natural number,
and returns 0 if the index is infinite.
- `H.relindex K` : the relative index of `H : Subgroup G` in `K : Subgroup G` as a natural number,
and returns 0 if the relative index is infinite.
# Main results
- `card_mul_index` : `Nat.card H * H.index = Nat.card G`
- `index_mul_card` : `H.index * Fintype.card H = Fintype.card G`
- `index_dvd_card` : `H.index ∣ Fintype.card G`
- `relindex_mul_index` : If `H ≤ K`, then `H.relindex K * K.index = H.index`
- `index_dvd_of_le` : If `H ≤ K`, then `K.index ∣ H.index`
- `relindex_mul_relindex` : `relindex` is multiplicative in towers
-/
namespace Subgroup
open Cardinal
variable {G : Type*} [Group G] (H K L : Subgroup G)
/-- The index of a subgroup as a natural number, and returns 0 if the index is infinite. -/
@[to_additive "The index of a subgroup as a natural number,
and returns 0 if the index is infinite."]
noncomputable def index : ℕ :=
Nat.card (G ⧸ H)
#align subgroup.index Subgroup.index
#align add_subgroup.index AddSubgroup.index
/-- The relative index of a subgroup as a natural number,
and returns 0 if the relative index is infinite. -/
@[to_additive "The relative index of a subgroup as a natural number,
and returns 0 if the relative index is infinite."]
noncomputable def relindex : ℕ :=
(H.subgroupOf K).index
#align subgroup.relindex Subgroup.relindex
#align add_subgroup.relindex AddSubgroup.relindex
@[to_additive]
theorem index_comap_of_surjective {G' : Type*} [Group G'] {f : G' →* G}
(hf : Function.Surjective f) : (H.comap f).index = H.index := by
letI := QuotientGroup.leftRel H
letI := QuotientGroup.leftRel (H.comap f)
have key : ∀ x y : G', Setoid.r x y ↔ Setoid.r (f x) (f y) := by
simp only [QuotientGroup.leftRel_apply]
exact fun x y => iff_of_eq (congr_arg (· ∈ H) (by rw [f.map_mul, f.map_inv]))
refine Cardinal.toNat_congr (Equiv.ofBijective (Quotient.map' f fun x y => (key x y).mp) ⟨?_, ?_⟩)
· simp_rw [← Quotient.eq''] at key
refine Quotient.ind' fun x => ?_
refine Quotient.ind' fun y => ?_
exact (key x y).mpr
· refine Quotient.ind' fun x => ?_
obtain ⟨y, hy⟩ := hf x
exact ⟨y, (Quotient.map'_mk'' f _ y).trans (congr_arg Quotient.mk'' hy)⟩
#align subgroup.index_comap_of_surjective Subgroup.index_comap_of_surjective
#align add_subgroup.index_comap_of_surjective AddSubgroup.index_comap_of_surjective
@[to_additive]
theorem index_comap {G' : Type*} [Group G'] (f : G' →* G) :
(H.comap f).index = H.relindex f.range :=
Eq.trans (congr_arg index (by rfl))
((H.subgroupOf f.range).index_comap_of_surjective f.rangeRestrict_surjective)
#align subgroup.index_comap Subgroup.index_comap
#align add_subgroup.index_comap AddSubgroup.index_comap
@[to_additive]
theorem relindex_comap {G' : Type*} [Group G'] (f : G' →* G) (K : Subgroup G') :
relindex (comap f H) K = relindex H (map f K) := by
rw [relindex, subgroupOf, comap_comap, index_comap, ← f.map_range, K.subtype_range]
#align subgroup.relindex_comap Subgroup.relindex_comap
#align add_subgroup.relindex_comap AddSubgroup.relindex_comap
variable {H K L}
@[to_additive relindex_mul_index]
theorem relindex_mul_index (h : H ≤ K) : H.relindex K * K.index = H.index :=
((mul_comm _ _).trans (Cardinal.toNat_mul _ _).symm).trans
(congr_arg Cardinal.toNat (Equiv.cardinal_eq (quotientEquivProdOfLE h))).symm
#align subgroup.relindex_mul_index Subgroup.relindex_mul_index
#align add_subgroup.relindex_mul_index AddSubgroup.relindex_mul_index
@[to_additive]
theorem index_dvd_of_le (h : H ≤ K) : K.index ∣ H.index :=
dvd_of_mul_left_eq (H.relindex K) (relindex_mul_index h)
#align subgroup.index_dvd_of_le Subgroup.index_dvd_of_le
#align add_subgroup.index_dvd_of_le AddSubgroup.index_dvd_of_le
@[to_additive]
theorem relindex_dvd_index_of_le (h : H ≤ K) : H.relindex K ∣ H.index :=
dvd_of_mul_right_eq K.index (relindex_mul_index h)
#align subgroup.relindex_dvd_index_of_le Subgroup.relindex_dvd_index_of_le
#align add_subgroup.relindex_dvd_index_of_le AddSubgroup.relindex_dvd_index_of_le
@[to_additive]
theorem relindex_subgroupOf (hKL : K ≤ L) :
(H.subgroupOf L).relindex (K.subgroupOf L) = H.relindex K :=
((index_comap (H.subgroupOf L) (inclusion hKL)).trans (congr_arg _ (inclusion_range hKL))).symm
#align subgroup.relindex_subgroup_of Subgroup.relindex_subgroupOf
#align add_subgroup.relindex_add_subgroup_of AddSubgroup.relindex_addSubgroupOf
variable (H K L)
@[to_additive relindex_mul_relindex]
theorem relindex_mul_relindex (hHK : H ≤ K) (hKL : K ≤ L) :
H.relindex K * K.relindex L = H.relindex L := by
rw [← relindex_subgroupOf hKL]
exact relindex_mul_index fun x hx => hHK hx
#align subgroup.relindex_mul_relindex Subgroup.relindex_mul_relindex
#align add_subgroup.relindex_mul_relindex AddSubgroup.relindex_mul_relindex
@[to_additive]
theorem inf_relindex_right : (H ⊓ K).relindex K = H.relindex K := by
rw [relindex, relindex, inf_subgroupOf_right]
#align subgroup.inf_relindex_right Subgroup.inf_relindex_right
#align add_subgroup.inf_relindex_right AddSubgroup.inf_relindex_right
@[to_additive]
theorem inf_relindex_left : (H ⊓ K).relindex H = K.relindex H := by
rw [inf_comm, inf_relindex_right]
#align subgroup.inf_relindex_left Subgroup.inf_relindex_left
#align add_subgroup.inf_relindex_left AddSubgroup.inf_relindex_left
@[to_additive relindex_inf_mul_relindex]
theorem relindex_inf_mul_relindex : H.relindex (K ⊓ L) * K.relindex L = (H ⊓ K).relindex L := by
rw [← inf_relindex_right H (K ⊓ L), ← inf_relindex_right K L, ← inf_relindex_right (H ⊓ K) L,
inf_assoc, relindex_mul_relindex (H ⊓ (K ⊓ L)) (K ⊓ L) L inf_le_right inf_le_right]
#align subgroup.relindex_inf_mul_relindex Subgroup.relindex_inf_mul_relindex
#align add_subgroup.relindex_inf_mul_relindex AddSubgroup.relindex_inf_mul_relindex
@[to_additive (attr := simp)]
theorem relindex_sup_right [K.Normal] : K.relindex (H ⊔ K) = K.relindex H :=
Nat.card_congr (QuotientGroup.quotientInfEquivProdNormalQuotient H K).toEquiv.symm
#align subgroup.relindex_sup_right Subgroup.relindex_sup_right
#align add_subgroup.relindex_sup_right AddSubgroup.relindex_sup_right
@[to_additive (attr := simp)]
theorem relindex_sup_left [K.Normal] : K.relindex (K ⊔ H) = K.relindex H := by
rw [sup_comm, relindex_sup_right]
#align subgroup.relindex_sup_left Subgroup.relindex_sup_left
#align add_subgroup.relindex_sup_left AddSubgroup.relindex_sup_left
@[to_additive]
theorem relindex_dvd_index_of_normal [H.Normal] : H.relindex K ∣ H.index :=
relindex_sup_right K H ▸ relindex_dvd_index_of_le le_sup_right
#align subgroup.relindex_dvd_index_of_normal Subgroup.relindex_dvd_index_of_normal
#align add_subgroup.relindex_dvd_index_of_normal AddSubgroup.relindex_dvd_index_of_normal
variable {H K}
@[to_additive]
theorem relindex_dvd_of_le_left (hHK : H ≤ K) : K.relindex L ∣ H.relindex L :=
inf_of_le_left hHK ▸ dvd_of_mul_left_eq _ (relindex_inf_mul_relindex _ _ _)
#align subgroup.relindex_dvd_of_le_left Subgroup.relindex_dvd_of_le_left
#align add_subgroup.relindex_dvd_of_le_left AddSubgroup.relindex_dvd_of_le_left
/-- A subgroup has index two if and only if there exists `a` such that for all `b`, exactly one
of `b * a` and `b` belong to `H`. -/
@[to_additive "An additive subgroup has index two if and only if there exists `a` such that
for all `b`, exactly one of `b + a` and `b` belong to `H`."]
theorem index_eq_two_iff : H.index = 2 ↔ ∃ a, ∀ b, Xor' (b * a ∈ H) (b ∈ H) := by
simp only [index, Nat.card_eq_two_iff' ((1 : G) : G ⧸ H), ExistsUnique, inv_mem_iff,
QuotientGroup.exists_mk, QuotientGroup.forall_mk, Ne, QuotientGroup.eq, mul_one,
xor_iff_iff_not]
refine exists_congr fun a =>
⟨fun ha b => ⟨fun hba hb => ?_, fun hb => ?_⟩, fun ha => ⟨?_, fun b hb => ?_⟩⟩
· exact ha.1 ((mul_mem_cancel_left hb).1 hba)
· exact inv_inv b ▸ ha.2 _ (mt (inv_mem_iff (x := b)).1 hb)
· rw [← inv_mem_iff (x := a), ← ha, inv_mul_self]
exact one_mem _
· rwa [ha, inv_mem_iff (x := b)]
#align subgroup.index_eq_two_iff Subgroup.index_eq_two_iff
#align add_subgroup.index_eq_two_iff AddSubgroup.index_eq_two_iff
@[to_additive]
theorem mul_mem_iff_of_index_two (h : H.index = 2) {a b : G} : a * b ∈ H ↔ (a ∈ H ↔ b ∈ H) := by
by_cases ha : a ∈ H; · simp only [ha, true_iff_iff, mul_mem_cancel_left ha]
by_cases hb : b ∈ H; · simp only [hb, iff_true_iff, mul_mem_cancel_right hb]
simp only [ha, hb, iff_self_iff, iff_true_iff]
rcases index_eq_two_iff.1 h with ⟨c, hc⟩
refine (hc _).or.resolve_left ?_
rwa [mul_assoc, mul_mem_cancel_right ((hc _).or.resolve_right hb)]
#align subgroup.mul_mem_iff_of_index_two Subgroup.mul_mem_iff_of_index_two
#align add_subgroup.add_mem_iff_of_index_two AddSubgroup.add_mem_iff_of_index_two
@[to_additive]
theorem mul_self_mem_of_index_two (h : H.index = 2) (a : G) : a * a ∈ H := by
rw [mul_mem_iff_of_index_two h]
#align subgroup.mul_self_mem_of_index_two Subgroup.mul_self_mem_of_index_two
#align add_subgroup.add_self_mem_of_index_two AddSubgroup.add_self_mem_of_index_two
@[to_additive two_smul_mem_of_index_two]
theorem sq_mem_of_index_two (h : H.index = 2) (a : G) : a ^ 2 ∈ H :=
(pow_two a).symm ▸ mul_self_mem_of_index_two h a
#align subgroup.sq_mem_of_index_two Subgroup.sq_mem_of_index_two
#align add_subgroup.two_smul_mem_of_index_two AddSubgroup.two_smul_mem_of_index_two
variable (H K)
-- Porting note: had to replace `Cardinal.toNat_eq_one_iff_unique` with `Nat.card_eq_one_iff_unique`
@[to_additive (attr := simp)]
theorem index_top : (⊤ : Subgroup G).index = 1 :=
Nat.card_eq_one_iff_unique.mpr ⟨QuotientGroup.subsingleton_quotient_top, ⟨1⟩⟩
#align subgroup.index_top Subgroup.index_top
#align add_subgroup.index_top AddSubgroup.index_top
@[to_additive (attr := simp)]
theorem index_bot : (⊥ : Subgroup G).index = Nat.card G :=
Cardinal.toNat_congr QuotientGroup.quotientBot.toEquiv
#align subgroup.index_bot Subgroup.index_bot
#align add_subgroup.index_bot AddSubgroup.index_bot
@[to_additive]
theorem index_bot_eq_card [Fintype G] : (⊥ : Subgroup G).index = Fintype.card G :=
index_bot.trans Nat.card_eq_fintype_card
#align subgroup.index_bot_eq_card Subgroup.index_bot_eq_card
#align add_subgroup.index_bot_eq_card AddSubgroup.index_bot_eq_card
@[to_additive (attr := simp)]
theorem relindex_top_left : (⊤ : Subgroup G).relindex H = 1 :=
index_top
#align subgroup.relindex_top_left Subgroup.relindex_top_left
#align add_subgroup.relindex_top_left AddSubgroup.relindex_top_left
@[to_additive (attr := simp)]
theorem relindex_top_right : H.relindex ⊤ = H.index := by
rw [← relindex_mul_index (show H ≤ ⊤ from le_top), index_top, mul_one]
#align subgroup.relindex_top_right Subgroup.relindex_top_right
#align add_subgroup.relindex_top_right AddSubgroup.relindex_top_right
@[to_additive (attr := simp)]
theorem relindex_bot_left : (⊥ : Subgroup G).relindex H = Nat.card H := by
rw [relindex, bot_subgroupOf, index_bot]
#align subgroup.relindex_bot_left Subgroup.relindex_bot_left
#align add_subgroup.relindex_bot_left AddSubgroup.relindex_bot_left
@[to_additive]
theorem relindex_bot_left_eq_card [Fintype H] : (⊥ : Subgroup G).relindex H = Fintype.card H :=
H.relindex_bot_left.trans Nat.card_eq_fintype_card
#align subgroup.relindex_bot_left_eq_card Subgroup.relindex_bot_left_eq_card
#align add_subgroup.relindex_bot_left_eq_card AddSubgroup.relindex_bot_left_eq_card
@[to_additive (attr := simp)]
theorem relindex_bot_right : H.relindex ⊥ = 1 := by rw [relindex, subgroupOf_bot_eq_top, index_top]
#align subgroup.relindex_bot_right Subgroup.relindex_bot_right
#align add_subgroup.relindex_bot_right AddSubgroup.relindex_bot_right
@[to_additive (attr := simp)]
theorem relindex_self : H.relindex H = 1 := by rw [relindex, subgroupOf_self, index_top]
#align subgroup.relindex_self Subgroup.relindex_self
#align add_subgroup.relindex_self AddSubgroup.relindex_self
@[to_additive]
theorem index_ker {H} [Group H] (f : G →* H) : f.ker.index = Nat.card (Set.range f) := by
rw [← MonoidHom.comap_bot, index_comap, relindex_bot_left]
rfl
#align subgroup.index_ker Subgroup.index_ker
#align add_subgroup.index_ker AddSubgroup.index_ker
@[to_additive]
theorem relindex_ker {H} [Group H] (f : G →* H) (K : Subgroup G) :
f.ker.relindex K = Nat.card (f '' K) := by
rw [← MonoidHom.comap_bot, relindex_comap, relindex_bot_left]
rfl
#align subgroup.relindex_ker Subgroup.relindex_ker
#align add_subgroup.relindex_ker AddSubgroup.relindex_ker
@[to_additive (attr := simp) card_mul_index]
theorem card_mul_index : Nat.card H * H.index = Nat.card G := by
rw [← relindex_bot_left, ← index_bot]
exact relindex_mul_index bot_le
#align subgroup.card_mul_index Subgroup.card_mul_index
#align add_subgroup.card_mul_index AddSubgroup.card_mul_index
@[to_additive]
theorem nat_card_dvd_of_injective {G H : Type*} [Group G] [Group H] (f : G →* H)
(hf : Function.Injective f) : Nat.card G ∣ Nat.card H := by
rw [Nat.card_congr (MonoidHom.ofInjective hf).toEquiv]
exact Dvd.intro f.range.index f.range.card_mul_index
#align subgroup.nat_card_dvd_of_injective Subgroup.nat_card_dvd_of_injective
#align add_subgroup.nat_card_dvd_of_injective AddSubgroup.nat_card_dvd_of_injective
@[to_additive]
theorem nat_card_dvd_of_le (hHK : H ≤ K) : Nat.card H ∣ Nat.card K :=
nat_card_dvd_of_injective (inclusion hHK) (inclusion_injective hHK)
#align subgroup.nat_card_dvd_of_le Subgroup.nat_card_dvd_of_le
#align add_subgroup.nat_card_dvd_of_le AddSubgroup.nat_card_dvd_of_le
@[to_additive]
theorem nat_card_dvd_of_surjective {G H : Type*} [Group G] [Group H] (f : G →* H)
(hf : Function.Surjective f) : Nat.card H ∣ Nat.card G := by
rw [← Nat.card_congr (QuotientGroup.quotientKerEquivOfSurjective f hf).toEquiv]
exact Dvd.intro_left (Nat.card f.ker) f.ker.card_mul_index
#align subgroup.nat_card_dvd_of_surjective Subgroup.nat_card_dvd_of_surjective
#align add_subgroup.nat_card_dvd_of_surjective AddSubgroup.nat_card_dvd_of_surjective
@[to_additive]
theorem card_dvd_of_surjective {G H : Type*} [Group G] [Group H] [Fintype G] [Fintype H]
(f : G →* H) (hf : Function.Surjective f) : Fintype.card H ∣ Fintype.card G := by
simp only [← Nat.card_eq_fintype_card, nat_card_dvd_of_surjective f hf]
#align subgroup.card_dvd_of_surjective Subgroup.card_dvd_of_surjective
#align add_subgroup.card_dvd_of_surjective AddSubgroup.card_dvd_of_surjective
@[to_additive]
theorem index_map {G' : Type*} [Group G'] (f : G →* G') :
(H.map f).index = (H ⊔ f.ker).index * f.range.index := by
rw [← comap_map_eq, index_comap, relindex_mul_index (H.map_le_range f)]
#align subgroup.index_map Subgroup.index_map
#align add_subgroup.index_map AddSubgroup.index_map
@[to_additive]
theorem index_map_dvd {G' : Type*} [Group G'] {f : G →* G'} (hf : Function.Surjective f) :
(H.map f).index ∣ H.index := by
rw [index_map, f.range_top_of_surjective hf, index_top, mul_one]
exact index_dvd_of_le le_sup_left
#align subgroup.index_map_dvd Subgroup.index_map_dvd
#align add_subgroup.index_map_dvd AddSubgroup.index_map_dvd
@[to_additive]
theorem dvd_index_map {G' : Type*} [Group G'] {f : G →* G'} (hf : f.ker ≤ H) :
H.index ∣ (H.map f).index := by
rw [index_map, sup_of_le_left hf]
apply dvd_mul_right
#align subgroup.dvd_index_map Subgroup.dvd_index_map
#align add_subgroup.dvd_index_map AddSubgroup.dvd_index_map
@[to_additive]
theorem index_map_eq {G' : Type*} [Group G'] {f : G →* G'} (hf1 : Function.Surjective f)
(hf2 : f.ker ≤ H) : (H.map f).index = H.index :=
Nat.dvd_antisymm (H.index_map_dvd hf1) (H.dvd_index_map hf2)
#align subgroup.index_map_eq Subgroup.index_map_eq
#align add_subgroup.index_map_eq AddSubgroup.index_map_eq
@[to_additive]
theorem index_eq_card [Fintype (G ⧸ H)] : H.index = Fintype.card (G ⧸ H) :=
Nat.card_eq_fintype_card
#align subgroup.index_eq_card Subgroup.index_eq_card
#align add_subgroup.index_eq_card AddSubgroup.index_eq_card
@[to_additive index_mul_card]
theorem index_mul_card [Fintype G] [hH : Fintype H] :
H.index * Fintype.card H = Fintype.card G := by
rw [← relindex_bot_left_eq_card, ← index_bot_eq_card, mul_comm];
exact relindex_mul_index bot_le
#align subgroup.index_mul_card Subgroup.index_mul_card
#align add_subgroup.index_mul_card AddSubgroup.index_mul_card
@[to_additive]
theorem index_dvd_card [Fintype G] : H.index ∣ Fintype.card G := by
classical exact ⟨Fintype.card H, H.index_mul_card.symm⟩
#align subgroup.index_dvd_card Subgroup.index_dvd_card
#align add_subgroup.index_dvd_card AddSubgroup.index_dvd_card
variable {H K L}
@[to_additive]
theorem relindex_eq_zero_of_le_left (hHK : H ≤ K) (hKL : K.relindex L = 0) : H.relindex L = 0 :=
eq_zero_of_zero_dvd (hKL ▸ relindex_dvd_of_le_left L hHK)
#align subgroup.relindex_eq_zero_of_le_left Subgroup.relindex_eq_zero_of_le_left
#align add_subgroup.relindex_eq_zero_of_le_left AddSubgroup.relindex_eq_zero_of_le_left
@[to_additive]
theorem relindex_eq_zero_of_le_right (hKL : K ≤ L) (hHK : H.relindex K = 0) : H.relindex L = 0 :=
Finite.card_eq_zero_of_embedding (quotientSubgroupOfEmbeddingOfLE H hKL) hHK
#align subgroup.relindex_eq_zero_of_le_right Subgroup.relindex_eq_zero_of_le_right
#align add_subgroup.relindex_eq_zero_of_le_right AddSubgroup.relindex_eq_zero_of_le_right
@[to_additive]
theorem index_eq_zero_of_relindex_eq_zero (h : H.relindex K = 0) : H.index = 0 :=
H.relindex_top_right.symm.trans (relindex_eq_zero_of_le_right le_top h)
#align subgroup.index_eq_zero_of_relindex_eq_zero Subgroup.index_eq_zero_of_relindex_eq_zero
#align add_subgroup.index_eq_zero_of_relindex_eq_zero AddSubgroup.index_eq_zero_of_relindex_eq_zero
@[to_additive]
theorem relindex_le_of_le_left (hHK : H ≤ K) (hHL : H.relindex L ≠ 0) :
K.relindex L ≤ H.relindex L :=
Nat.le_of_dvd (Nat.pos_of_ne_zero hHL) (relindex_dvd_of_le_left L hHK)
#align subgroup.relindex_le_of_le_left Subgroup.relindex_le_of_le_left
#align add_subgroup.relindex_le_of_le_left AddSubgroup.relindex_le_of_le_left
@[to_additive]
theorem relindex_le_of_le_right (hKL : K ≤ L) (hHL : H.relindex L ≠ 0) :
H.relindex K ≤ H.relindex L :=
Finite.card_le_of_embedding' (quotientSubgroupOfEmbeddingOfLE H hKL) fun h => (hHL h).elim
#align subgroup.relindex_le_of_le_right Subgroup.relindex_le_of_le_right
#align add_subgroup.relindex_le_of_le_right AddSubgroup.relindex_le_of_le_right
@[to_additive]
theorem relindex_ne_zero_trans (hHK : H.relindex K ≠ 0) (hKL : K.relindex L ≠ 0) :
H.relindex L ≠ 0 := fun h =>
mul_ne_zero (mt (relindex_eq_zero_of_le_right (show K ⊓ L ≤ K from inf_le_left)) hHK) hKL
((relindex_inf_mul_relindex H K L).trans (relindex_eq_zero_of_le_left inf_le_left h))
#align subgroup.relindex_ne_zero_trans Subgroup.relindex_ne_zero_trans
#align add_subgroup.relindex_ne_zero_trans AddSubgroup.relindex_ne_zero_trans
@[to_additive]
theorem relindex_inf_ne_zero (hH : H.relindex L ≠ 0) (hK : K.relindex L ≠ 0) :
(H ⊓ K).relindex L ≠ 0 := by
replace hH : H.relindex (K ⊓ L) ≠ 0 := mt (relindex_eq_zero_of_le_right inf_le_right) hH
rw [← inf_relindex_right] at hH hK ⊢
rw [inf_assoc]
exact relindex_ne_zero_trans hH hK
#align subgroup.relindex_inf_ne_zero Subgroup.relindex_inf_ne_zero
#align add_subgroup.relindex_inf_ne_zero AddSubgroup.relindex_inf_ne_zero
@[to_additive]
theorem index_inf_ne_zero (hH : H.index ≠ 0) (hK : K.index ≠ 0) : (H ⊓ K).index ≠ 0 := by
rw [← relindex_top_right] at hH hK ⊢
exact relindex_inf_ne_zero hH hK
#align subgroup.index_inf_ne_zero Subgroup.index_inf_ne_zero
#align add_subgroup.index_inf_ne_zero AddSubgroup.index_inf_ne_zero
@[to_additive]
theorem relindex_inf_le : (H ⊓ K).relindex L ≤ H.relindex L * K.relindex L := by
by_cases h : H.relindex L = 0
· exact (le_of_eq (relindex_eq_zero_of_le_left inf_le_left h)).trans (zero_le _)
rw [← inf_relindex_right, inf_assoc, ← relindex_mul_relindex _ _ L inf_le_right inf_le_right,
inf_relindex_right, inf_relindex_right]
exact mul_le_mul_right' (relindex_le_of_le_right inf_le_right h) (K.relindex L)
#align subgroup.relindex_inf_le Subgroup.relindex_inf_le
#align add_subgroup.relindex_inf_le AddSubgroup.relindex_inf_le
@[to_additive]
theorem index_inf_le : (H ⊓ K).index ≤ H.index * K.index := by
simp_rw [← relindex_top_right, relindex_inf_le]
#align subgroup.index_inf_le Subgroup.index_inf_le
#align add_subgroup.index_inf_le AddSubgroup.index_inf_le
@[to_additive]
theorem relindex_iInf_ne_zero {ι : Type*} [_hι : Finite ι] {f : ι → Subgroup G}
(hf : ∀ i, (f i).relindex L ≠ 0) : (⨅ i, f i).relindex L ≠ 0 :=
haveI := Fintype.ofFinite ι
(Finset.prod_ne_zero_iff.mpr fun i _hi => hf i) ∘
Nat.card_pi.symm.trans ∘
Finite.card_eq_zero_of_embedding (quotientiInfSubgroupOfEmbedding f L)
#align subgroup.relindex_infi_ne_zero Subgroup.relindex_iInf_ne_zero
#align add_subgroup.relindex_infi_ne_zero AddSubgroup.relindex_iInf_ne_zero
@[to_additive]
theorem relindex_iInf_le {ι : Type*} [Fintype ι] (f : ι → Subgroup G) :
(⨅ i, f i).relindex L ≤ ∏ i, (f i).relindex L :=
le_of_le_of_eq
(Finite.card_le_of_embedding' (quotientiInfSubgroupOfEmbedding f L) fun h =>
let ⟨i, _hi, h⟩ := Finset.prod_eq_zero_iff.mp (Nat.card_pi.symm.trans h)
relindex_eq_zero_of_le_left (iInf_le f i) h)
Nat.card_pi
#align subgroup.relindex_infi_le Subgroup.relindex_iInf_le
#align add_subgroup.relindex_infi_le AddSubgroup.relindex_iInf_le
@[to_additive]
theorem index_iInf_ne_zero {ι : Type*} [Finite ι] {f : ι → Subgroup G}
(hf : ∀ i, (f i).index ≠ 0) : (⨅ i, f i).index ≠ 0 := by
simp_rw [← relindex_top_right] at hf ⊢
exact relindex_iInf_ne_zero hf
#align subgroup.index_infi_ne_zero Subgroup.index_iInf_ne_zero
#align add_subgroup.index_infi_ne_zero AddSubgroup.index_iInf_ne_zero
@[to_additive]
theorem index_iInf_le {ι : Type*} [Fintype ι] (f : ι → Subgroup G) :
(⨅ i, f i).index ≤ ∏ i, (f i).index := by simp_rw [← relindex_top_right, relindex_iInf_le]
#align subgroup.index_infi_le Subgroup.index_iInf_le
#align add_subgroup.index_infi_le AddSubgroup.index_iInf_le
-- Porting note: had to replace `Cardinal.toNat_eq_one_iff_unique` with `Nat.card_eq_one_iff_unique`
@[to_additive (attr := simp) index_eq_one]
theorem index_eq_one : H.index = 1 ↔ H = ⊤ :=
⟨fun h =>
QuotientGroup.subgroup_eq_top_of_subsingleton H (Nat.card_eq_one_iff_unique.mp h).1,
fun h => (congr_arg index h).trans index_top⟩
#align subgroup.index_eq_one Subgroup.index_eq_one
#align add_subgroup.index_eq_one AddSubgroup.index_eq_one
@[to_additive (attr := simp) relindex_eq_one]
theorem relindex_eq_one : H.relindex K = 1 ↔ K ≤ H :=
index_eq_one.trans subgroupOf_eq_top
#align subgroup.relindex_eq_one Subgroup.relindex_eq_one
#align add_subgroup.relindex_eq_one AddSubgroup.relindex_eq_one
@[to_additive (attr := simp) card_eq_one]
theorem card_eq_one : Nat.card H = 1 ↔ H = ⊥ :=
H.relindex_bot_left ▸ relindex_eq_one.trans le_bot_iff
#align subgroup.card_eq_one Subgroup.card_eq_one
#align add_subgroup.card_eq_one AddSubgroup.card_eq_one
@[to_additive]
| Mathlib/GroupTheory/Index.lean | 507 | 510 | theorem index_ne_zero_of_finite [hH : Finite (G ⧸ H)] : H.index ≠ 0 := by |
cases nonempty_fintype (G ⧸ H)
rw [index_eq_card]
exact Fintype.card_ne_zero
|
/-
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.Order.Monoid.Unbundled.Pow
import Mathlib.Data.Finset.Fold
import Mathlib.Data.Finset.Option
import Mathlib.Data.Finset.Pi
import Mathlib.Data.Finset.Prod
import Mathlib.Data.Multiset.Lattice
import Mathlib.Data.Set.Lattice
import Mathlib.Order.Hom.Lattice
import Mathlib.Order.Nat
#align_import data.finset.lattice from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d"
/-!
# Lattice operations on finsets
-/
-- TODO:
-- assert_not_exists OrderedCommMonoid
assert_not_exists MonoidWithZero
open Function Multiset OrderDual
variable {F α β γ ι κ : Type*}
namespace Finset
/-! ### sup -/
section Sup
-- TODO: define with just `[Bot α]` where some lemmas hold without requiring `[OrderBot α]`
variable [SemilatticeSup α] [OrderBot α]
/-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/
def sup (s : Finset β) (f : β → α) : α :=
s.fold (· ⊔ ·) ⊥ f
#align finset.sup Finset.sup
variable {s s₁ s₂ : Finset β} {f g : β → α} {a : α}
theorem sup_def : s.sup f = (s.1.map f).sup :=
rfl
#align finset.sup_def Finset.sup_def
@[simp]
theorem sup_empty : (∅ : Finset β).sup f = ⊥ :=
fold_empty
#align finset.sup_empty Finset.sup_empty
@[simp]
theorem sup_cons {b : β} (h : b ∉ s) : (cons b s h).sup f = f b ⊔ s.sup f :=
fold_cons h
#align finset.sup_cons Finset.sup_cons
@[simp]
theorem sup_insert [DecidableEq β] {b : β} : (insert b s : Finset β).sup f = f b ⊔ s.sup f :=
fold_insert_idem
#align finset.sup_insert Finset.sup_insert
@[simp]
theorem sup_image [DecidableEq β] (s : Finset γ) (f : γ → β) (g : β → α) :
(s.image f).sup g = s.sup (g ∘ f) :=
fold_image_idem
#align finset.sup_image Finset.sup_image
@[simp]
theorem sup_map (s : Finset γ) (f : γ ↪ β) (g : β → α) : (s.map f).sup g = s.sup (g ∘ f) :=
fold_map
#align finset.sup_map Finset.sup_map
@[simp]
theorem sup_singleton {b : β} : ({b} : Finset β).sup f = f b :=
Multiset.sup_singleton
#align finset.sup_singleton Finset.sup_singleton
theorem sup_sup : s.sup (f ⊔ g) = s.sup f ⊔ s.sup g := by
induction s using Finset.cons_induction with
| empty => rw [sup_empty, sup_empty, sup_empty, bot_sup_eq]
| cons _ _ _ ih =>
rw [sup_cons, sup_cons, sup_cons, ih]
exact sup_sup_sup_comm _ _ _ _
#align finset.sup_sup Finset.sup_sup
theorem sup_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) :
s₁.sup f = s₂.sup g := by
subst hs
exact Finset.fold_congr hfg
#align finset.sup_congr Finset.sup_congr
@[simp]
theorem _root_.map_finset_sup [SemilatticeSup β] [OrderBot β]
[FunLike F α β] [SupBotHomClass F α β]
(f : F) (s : Finset ι) (g : ι → α) : f (s.sup g) = s.sup (f ∘ g) :=
Finset.cons_induction_on s (map_bot f) fun i s _ h => by
rw [sup_cons, sup_cons, map_sup, h, Function.comp_apply]
#align map_finset_sup map_finset_sup
@[simp]
protected theorem sup_le_iff {a : α} : s.sup f ≤ a ↔ ∀ b ∈ s, f b ≤ a := by
apply Iff.trans Multiset.sup_le
simp only [Multiset.mem_map, and_imp, exists_imp]
exact ⟨fun k b hb => k _ _ hb rfl, fun k a' b hb h => h ▸ k _ hb⟩
#align finset.sup_le_iff Finset.sup_le_iff
protected alias ⟨_, sup_le⟩ := Finset.sup_le_iff
#align finset.sup_le Finset.sup_le
theorem sup_const_le : (s.sup fun _ => a) ≤ a :=
Finset.sup_le fun _ _ => le_rfl
#align finset.sup_const_le Finset.sup_const_le
theorem le_sup {b : β} (hb : b ∈ s) : f b ≤ s.sup f :=
Finset.sup_le_iff.1 le_rfl _ hb
#align finset.le_sup Finset.le_sup
theorem le_sup_of_le {b : β} (hb : b ∈ s) (h : a ≤ f b) : a ≤ s.sup f := h.trans <| le_sup hb
#align finset.le_sup_of_le Finset.le_sup_of_le
theorem sup_union [DecidableEq β] : (s₁ ∪ s₂).sup f = s₁.sup f ⊔ s₂.sup f :=
eq_of_forall_ge_iff fun c => by simp [or_imp, forall_and]
#align finset.sup_union Finset.sup_union
@[simp]
theorem sup_biUnion [DecidableEq β] (s : Finset γ) (t : γ → Finset β) :
(s.biUnion t).sup f = s.sup fun x => (t x).sup f :=
eq_of_forall_ge_iff fun c => by simp [@forall_swap _ β]
#align finset.sup_bUnion Finset.sup_biUnion
theorem sup_const {s : Finset β} (h : s.Nonempty) (c : α) : (s.sup fun _ => c) = c :=
eq_of_forall_ge_iff (fun _ => Finset.sup_le_iff.trans h.forall_const)
#align finset.sup_const Finset.sup_const
@[simp]
theorem sup_bot (s : Finset β) : (s.sup fun _ => ⊥) = (⊥ : α) := by
obtain rfl | hs := s.eq_empty_or_nonempty
· exact sup_empty
· exact sup_const hs _
#align finset.sup_bot Finset.sup_bot
theorem sup_ite (p : β → Prop) [DecidablePred p] :
(s.sup fun i => ite (p i) (f i) (g i)) = (s.filter p).sup f ⊔ (s.filter fun i => ¬p i).sup g :=
fold_ite _
#align finset.sup_ite Finset.sup_ite
theorem sup_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ≤ g b) : s.sup f ≤ s.sup g :=
Finset.sup_le fun b hb => le_trans (h b hb) (le_sup hb)
#align finset.sup_mono_fun Finset.sup_mono_fun
@[gcongr]
theorem sup_mono (h : s₁ ⊆ s₂) : s₁.sup f ≤ s₂.sup f :=
Finset.sup_le (fun _ hb => le_sup (h hb))
#align finset.sup_mono Finset.sup_mono
protected theorem sup_comm (s : Finset β) (t : Finset γ) (f : β → γ → α) :
(s.sup fun b => t.sup (f b)) = t.sup fun c => s.sup fun b => f b c :=
eq_of_forall_ge_iff fun a => by simpa using forall₂_swap
#align finset.sup_comm Finset.sup_comm
@[simp, nolint simpNF] -- Porting note: linter claims that LHS does not simplify
theorem sup_attach (s : Finset β) (f : β → α) : (s.attach.sup fun x => f x) = s.sup f :=
(s.attach.sup_map (Function.Embedding.subtype _) f).symm.trans <| congr_arg _ attach_map_val
#align finset.sup_attach Finset.sup_attach
/-- See also `Finset.product_biUnion`. -/
theorem sup_product_left (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).sup f = s.sup fun i => t.sup fun i' => f ⟨i, i'⟩ :=
eq_of_forall_ge_iff fun a => by simp [@forall_swap _ γ]
#align finset.sup_product_left Finset.sup_product_left
theorem sup_product_right (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).sup f = t.sup fun i' => s.sup fun i => f ⟨i, i'⟩ := by
rw [sup_product_left, Finset.sup_comm]
#align finset.sup_product_right Finset.sup_product_right
section Prod
variable {ι κ α β : Type*} [SemilatticeSup α] [SemilatticeSup β] [OrderBot α] [OrderBot β]
{s : Finset ι} {t : Finset κ}
@[simp] lemma sup_prodMap (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) :
sup (s ×ˢ t) (Prod.map f g) = (sup s f, sup t g) :=
eq_of_forall_ge_iff fun i ↦ by
obtain ⟨a, ha⟩ := hs
obtain ⟨b, hb⟩ := ht
simp only [Prod.map, Finset.sup_le_iff, mem_product, and_imp, Prod.forall, Prod.le_def]
exact ⟨fun h ↦ ⟨fun i hi ↦ (h _ _ hi hb).1, fun j hj ↦ (h _ _ ha hj).2⟩, by aesop⟩
end Prod
@[simp]
theorem sup_erase_bot [DecidableEq α] (s : Finset α) : (s.erase ⊥).sup id = s.sup id := by
refine (sup_mono (s.erase_subset _)).antisymm (Finset.sup_le_iff.2 fun a ha => ?_)
obtain rfl | ha' := eq_or_ne a ⊥
· exact bot_le
· exact le_sup (mem_erase.2 ⟨ha', ha⟩)
#align finset.sup_erase_bot Finset.sup_erase_bot
theorem sup_sdiff_right {α β : Type*} [GeneralizedBooleanAlgebra α] (s : Finset β) (f : β → α)
(a : α) : (s.sup fun b => f b \ a) = s.sup f \ a := by
induction s using Finset.cons_induction with
| empty => rw [sup_empty, sup_empty, bot_sdiff]
| cons _ _ _ h => rw [sup_cons, sup_cons, h, sup_sdiff]
#align finset.sup_sdiff_right Finset.sup_sdiff_right
theorem comp_sup_eq_sup_comp [SemilatticeSup γ] [OrderBot γ] {s : Finset β} {f : β → α} (g : α → γ)
(g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) :=
Finset.cons_induction_on s bot fun c t hc ih => by
rw [sup_cons, sup_cons, g_sup, ih, Function.comp_apply]
#align finset.comp_sup_eq_sup_comp Finset.comp_sup_eq_sup_comp
/-- Computing `sup` in a subtype (closed under `sup`) is the same as computing it in `α`. -/
theorem sup_coe {P : α → Prop} {Pbot : P ⊥} {Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)} (t : Finset β)
(f : β → { x : α // P x }) :
(@sup { x // P x } _ (Subtype.semilatticeSup Psup) (Subtype.orderBot Pbot) t f : α) =
t.sup fun x => ↑(f x) := by
letI := Subtype.semilatticeSup Psup
letI := Subtype.orderBot Pbot
apply comp_sup_eq_sup_comp Subtype.val <;> intros <;> rfl
#align finset.sup_coe Finset.sup_coe
@[simp]
theorem sup_toFinset {α β} [DecidableEq β] (s : Finset α) (f : α → Multiset β) :
(s.sup f).toFinset = s.sup fun x => (f x).toFinset :=
comp_sup_eq_sup_comp Multiset.toFinset toFinset_union rfl
#align finset.sup_to_finset Finset.sup_toFinset
theorem _root_.List.foldr_sup_eq_sup_toFinset [DecidableEq α] (l : List α) :
l.foldr (· ⊔ ·) ⊥ = l.toFinset.sup id := by
rw [← coe_fold_r, ← Multiset.fold_dedup_idem, sup_def, ← List.toFinset_coe, toFinset_val,
Multiset.map_id]
rfl
#align list.foldr_sup_eq_sup_to_finset List.foldr_sup_eq_sup_toFinset
theorem subset_range_sup_succ (s : Finset ℕ) : s ⊆ range (s.sup id).succ := fun _ hn =>
mem_range.2 <| Nat.lt_succ_of_le <| @le_sup _ _ _ _ _ id _ hn
#align finset.subset_range_sup_succ Finset.subset_range_sup_succ
theorem exists_nat_subset_range (s : Finset ℕ) : ∃ n : ℕ, s ⊆ range n :=
⟨_, s.subset_range_sup_succ⟩
#align finset.exists_nat_subset_range Finset.exists_nat_subset_range
theorem sup_induction {p : α → Prop} (hb : p ⊥) (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊔ a₂))
(hs : ∀ b ∈ s, p (f b)) : p (s.sup f) := by
induction s using Finset.cons_induction with
| empty => exact hb
| cons _ _ _ ih =>
simp only [sup_cons, forall_mem_cons] at hs ⊢
exact hp _ hs.1 _ (ih hs.2)
#align finset.sup_induction Finset.sup_induction
theorem sup_le_of_le_directed {α : Type*} [SemilatticeSup α] [OrderBot α] (s : Set α)
(hs : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s) (t : Finset α) :
(∀ x ∈ t, ∃ y ∈ s, x ≤ y) → ∃ x ∈ s, t.sup id ≤ x := by
classical
induction' t using Finset.induction_on with a r _ ih h
· simpa only [forall_prop_of_true, and_true_iff, forall_prop_of_false, bot_le, not_false_iff,
sup_empty, forall_true_iff, not_mem_empty]
· intro h
have incs : (r : Set α) ⊆ ↑(insert a r) := by
rw [Finset.coe_subset]
apply Finset.subset_insert
-- x ∈ s is above the sup of r
obtain ⟨x, ⟨hxs, hsx_sup⟩⟩ := ih fun x hx => h x <| incs hx
-- y ∈ s is above a
obtain ⟨y, hys, hay⟩ := h a (Finset.mem_insert_self a r)
-- z ∈ s is above x and y
obtain ⟨z, hzs, ⟨hxz, hyz⟩⟩ := hdir x hxs y hys
use z, hzs
rw [sup_insert, id, sup_le_iff]
exact ⟨le_trans hay hyz, le_trans hsx_sup hxz⟩
#align finset.sup_le_of_le_directed Finset.sup_le_of_le_directed
-- If we acquire sublattices
-- the hypotheses should be reformulated as `s : SubsemilatticeSupBot`
theorem sup_mem (s : Set α) (w₁ : ⊥ ∈ s) (w₂ : ∀ᵉ (x ∈ s) (y ∈ s), x ⊔ y ∈ s)
{ι : Type*} (t : Finset ι) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.sup p ∈ s :=
@sup_induction _ _ _ _ _ _ (· ∈ s) w₁ w₂ h
#align finset.sup_mem Finset.sup_mem
@[simp]
protected theorem sup_eq_bot_iff (f : β → α) (S : Finset β) : S.sup f = ⊥ ↔ ∀ s ∈ S, f s = ⊥ := by
classical induction' S using Finset.induction with a S _ hi <;> simp [*]
#align finset.sup_eq_bot_iff Finset.sup_eq_bot_iff
end Sup
theorem sup_eq_iSup [CompleteLattice β] (s : Finset α) (f : α → β) : s.sup f = ⨆ a ∈ s, f a :=
le_antisymm
(Finset.sup_le (fun a ha => le_iSup_of_le a <| le_iSup (fun _ => f a) ha))
(iSup_le fun _ => iSup_le fun ha => le_sup ha)
#align finset.sup_eq_supr Finset.sup_eq_iSup
theorem sup_id_eq_sSup [CompleteLattice α] (s : Finset α) : s.sup id = sSup s := by
simp [sSup_eq_iSup, sup_eq_iSup]
#align finset.sup_id_eq_Sup Finset.sup_id_eq_sSup
theorem sup_id_set_eq_sUnion (s : Finset (Set α)) : s.sup id = ⋃₀ ↑s :=
sup_id_eq_sSup _
#align finset.sup_id_set_eq_sUnion Finset.sup_id_set_eq_sUnion
@[simp]
theorem sup_set_eq_biUnion (s : Finset α) (f : α → Set β) : s.sup f = ⋃ x ∈ s, f x :=
sup_eq_iSup _ _
#align finset.sup_set_eq_bUnion Finset.sup_set_eq_biUnion
theorem sup_eq_sSup_image [CompleteLattice β] (s : Finset α) (f : α → β) :
s.sup f = sSup (f '' s) := by
classical rw [← Finset.coe_image, ← sup_id_eq_sSup, sup_image, Function.id_comp]
#align finset.sup_eq_Sup_image Finset.sup_eq_sSup_image
/-! ### inf -/
section Inf
-- TODO: define with just `[Top α]` where some lemmas hold without requiring `[OrderTop α]`
variable [SemilatticeInf α] [OrderTop α]
/-- Infimum of a finite set: `inf {a, b, c} f = f a ⊓ f b ⊓ f c` -/
def inf (s : Finset β) (f : β → α) : α :=
s.fold (· ⊓ ·) ⊤ f
#align finset.inf Finset.inf
variable {s s₁ s₂ : Finset β} {f g : β → α} {a : α}
theorem inf_def : s.inf f = (s.1.map f).inf :=
rfl
#align finset.inf_def Finset.inf_def
@[simp]
theorem inf_empty : (∅ : Finset β).inf f = ⊤ :=
fold_empty
#align finset.inf_empty Finset.inf_empty
@[simp]
theorem inf_cons {b : β} (h : b ∉ s) : (cons b s h).inf f = f b ⊓ s.inf f :=
@sup_cons αᵒᵈ _ _ _ _ _ _ h
#align finset.inf_cons Finset.inf_cons
@[simp]
theorem inf_insert [DecidableEq β] {b : β} : (insert b s : Finset β).inf f = f b ⊓ s.inf f :=
fold_insert_idem
#align finset.inf_insert Finset.inf_insert
@[simp]
theorem inf_image [DecidableEq β] (s : Finset γ) (f : γ → β) (g : β → α) :
(s.image f).inf g = s.inf (g ∘ f) :=
fold_image_idem
#align finset.inf_image Finset.inf_image
@[simp]
theorem inf_map (s : Finset γ) (f : γ ↪ β) (g : β → α) : (s.map f).inf g = s.inf (g ∘ f) :=
fold_map
#align finset.inf_map Finset.inf_map
@[simp]
theorem inf_singleton {b : β} : ({b} : Finset β).inf f = f b :=
Multiset.inf_singleton
#align finset.inf_singleton Finset.inf_singleton
theorem inf_inf : s.inf (f ⊓ g) = s.inf f ⊓ s.inf g :=
@sup_sup αᵒᵈ _ _ _ _ _ _
#align finset.inf_inf Finset.inf_inf
theorem inf_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) :
s₁.inf f = s₂.inf g := by
subst hs
exact Finset.fold_congr hfg
#align finset.inf_congr Finset.inf_congr
@[simp]
theorem _root_.map_finset_inf [SemilatticeInf β] [OrderTop β]
[FunLike F α β] [InfTopHomClass F α β]
(f : F) (s : Finset ι) (g : ι → α) : f (s.inf g) = s.inf (f ∘ g) :=
Finset.cons_induction_on s (map_top f) fun i s _ h => by
rw [inf_cons, inf_cons, map_inf, h, Function.comp_apply]
#align map_finset_inf map_finset_inf
@[simp] protected theorem le_inf_iff {a : α} : a ≤ s.inf f ↔ ∀ b ∈ s, a ≤ f b :=
@Finset.sup_le_iff αᵒᵈ _ _ _ _ _ _
#align finset.le_inf_iff Finset.le_inf_iff
protected alias ⟨_, le_inf⟩ := Finset.le_inf_iff
#align finset.le_inf Finset.le_inf
theorem le_inf_const_le : a ≤ s.inf fun _ => a :=
Finset.le_inf fun _ _ => le_rfl
#align finset.le_inf_const_le Finset.le_inf_const_le
theorem inf_le {b : β} (hb : b ∈ s) : s.inf f ≤ f b :=
Finset.le_inf_iff.1 le_rfl _ hb
#align finset.inf_le Finset.inf_le
theorem inf_le_of_le {b : β} (hb : b ∈ s) (h : f b ≤ a) : s.inf f ≤ a := (inf_le hb).trans h
#align finset.inf_le_of_le Finset.inf_le_of_le
theorem inf_union [DecidableEq β] : (s₁ ∪ s₂).inf f = s₁.inf f ⊓ s₂.inf f :=
eq_of_forall_le_iff fun c ↦ by simp [or_imp, forall_and]
#align finset.inf_union Finset.inf_union
@[simp] theorem inf_biUnion [DecidableEq β] (s : Finset γ) (t : γ → Finset β) :
(s.biUnion t).inf f = s.inf fun x => (t x).inf f :=
@sup_biUnion αᵒᵈ _ _ _ _ _ _ _ _
#align finset.inf_bUnion Finset.inf_biUnion
theorem inf_const (h : s.Nonempty) (c : α) : (s.inf fun _ => c) = c := @sup_const αᵒᵈ _ _ _ _ h _
#align finset.inf_const Finset.inf_const
@[simp] theorem inf_top (s : Finset β) : (s.inf fun _ => ⊤) = (⊤ : α) := @sup_bot αᵒᵈ _ _ _ _
#align finset.inf_top Finset.inf_top
theorem inf_ite (p : β → Prop) [DecidablePred p] :
(s.inf fun i ↦ ite (p i) (f i) (g i)) = (s.filter p).inf f ⊓ (s.filter fun i ↦ ¬ p i).inf g :=
fold_ite _
theorem inf_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ≤ g b) : s.inf f ≤ s.inf g :=
Finset.le_inf fun b hb => le_trans (inf_le hb) (h b hb)
#align finset.inf_mono_fun Finset.inf_mono_fun
@[gcongr]
theorem inf_mono (h : s₁ ⊆ s₂) : s₂.inf f ≤ s₁.inf f :=
Finset.le_inf (fun _ hb => inf_le (h hb))
#align finset.inf_mono Finset.inf_mono
protected theorem inf_comm (s : Finset β) (t : Finset γ) (f : β → γ → α) :
(s.inf fun b => t.inf (f b)) = t.inf fun c => s.inf fun b => f b c :=
@Finset.sup_comm αᵒᵈ _ _ _ _ _ _ _
#align finset.inf_comm Finset.inf_comm
theorem inf_attach (s : Finset β) (f : β → α) : (s.attach.inf fun x => f x) = s.inf f :=
@sup_attach αᵒᵈ _ _ _ _ _
#align finset.inf_attach Finset.inf_attach
theorem inf_product_left (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).inf f = s.inf fun i => t.inf fun i' => f ⟨i, i'⟩ :=
@sup_product_left αᵒᵈ _ _ _ _ _ _ _
#align finset.inf_product_left Finset.inf_product_left
theorem inf_product_right (s : Finset β) (t : Finset γ) (f : β × γ → α) :
(s ×ˢ t).inf f = t.inf fun i' => s.inf fun i => f ⟨i, i'⟩ :=
@sup_product_right αᵒᵈ _ _ _ _ _ _ _
#align finset.inf_product_right Finset.inf_product_right
section Prod
variable {ι κ α β : Type*} [SemilatticeInf α] [SemilatticeInf β] [OrderTop α] [OrderTop β]
{s : Finset ι} {t : Finset κ}
@[simp] lemma inf_prodMap (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) :
inf (s ×ˢ t) (Prod.map f g) = (inf s f, inf t g) :=
sup_prodMap (α := αᵒᵈ) (β := βᵒᵈ) hs ht _ _
end Prod
@[simp]
theorem inf_erase_top [DecidableEq α] (s : Finset α) : (s.erase ⊤).inf id = s.inf id :=
@sup_erase_bot αᵒᵈ _ _ _ _
#align finset.inf_erase_top Finset.inf_erase_top
theorem comp_inf_eq_inf_comp [SemilatticeInf γ] [OrderTop γ] {s : Finset β} {f : β → α} (g : α → γ)
(g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) :=
@comp_sup_eq_sup_comp αᵒᵈ _ γᵒᵈ _ _ _ _ _ _ _ g_inf top
#align finset.comp_inf_eq_inf_comp Finset.comp_inf_eq_inf_comp
/-- Computing `inf` in a subtype (closed under `inf`) is the same as computing it in `α`. -/
theorem inf_coe {P : α → Prop} {Ptop : P ⊤} {Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)} (t : Finset β)
(f : β → { x : α // P x }) :
(@inf { x // P x } _ (Subtype.semilatticeInf Pinf) (Subtype.orderTop Ptop) t f : α) =
t.inf fun x => ↑(f x) :=
@sup_coe αᵒᵈ _ _ _ _ Ptop Pinf t f
#align finset.inf_coe Finset.inf_coe
theorem _root_.List.foldr_inf_eq_inf_toFinset [DecidableEq α] (l : List α) :
l.foldr (· ⊓ ·) ⊤ = l.toFinset.inf id := by
rw [← coe_fold_r, ← Multiset.fold_dedup_idem, inf_def, ← List.toFinset_coe, toFinset_val,
Multiset.map_id]
rfl
#align list.foldr_inf_eq_inf_to_finset List.foldr_inf_eq_inf_toFinset
theorem inf_induction {p : α → Prop} (ht : p ⊤) (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊓ a₂))
(hs : ∀ b ∈ s, p (f b)) : p (s.inf f) :=
@sup_induction αᵒᵈ _ _ _ _ _ _ ht hp hs
#align finset.inf_induction Finset.inf_induction
theorem inf_mem (s : Set α) (w₁ : ⊤ ∈ s) (w₂ : ∀ᵉ (x ∈ s) (y ∈ s), x ⊓ y ∈ s)
{ι : Type*} (t : Finset ι) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.inf p ∈ s :=
@inf_induction _ _ _ _ _ _ (· ∈ s) w₁ w₂ h
#align finset.inf_mem Finset.inf_mem
@[simp]
protected theorem inf_eq_top_iff (f : β → α) (S : Finset β) : S.inf f = ⊤ ↔ ∀ s ∈ S, f s = ⊤ :=
@Finset.sup_eq_bot_iff αᵒᵈ _ _ _ _ _
#align finset.inf_eq_top_iff Finset.inf_eq_top_iff
end Inf
@[simp]
theorem toDual_sup [SemilatticeSup α] [OrderBot α] (s : Finset β) (f : β → α) :
toDual (s.sup f) = s.inf (toDual ∘ f) :=
rfl
#align finset.to_dual_sup Finset.toDual_sup
@[simp]
theorem toDual_inf [SemilatticeInf α] [OrderTop α] (s : Finset β) (f : β → α) :
toDual (s.inf f) = s.sup (toDual ∘ f) :=
rfl
#align finset.to_dual_inf Finset.toDual_inf
@[simp]
theorem ofDual_sup [SemilatticeInf α] [OrderTop α] (s : Finset β) (f : β → αᵒᵈ) :
ofDual (s.sup f) = s.inf (ofDual ∘ f) :=
rfl
#align finset.of_dual_sup Finset.ofDual_sup
@[simp]
theorem ofDual_inf [SemilatticeSup α] [OrderBot α] (s : Finset β) (f : β → αᵒᵈ) :
ofDual (s.inf f) = s.sup (ofDual ∘ f) :=
rfl
#align finset.of_dual_inf Finset.ofDual_inf
section DistribLattice
variable [DistribLattice α]
section OrderBot
variable [OrderBot α] {s : Finset ι} {t : Finset κ} {f : ι → α} {g : κ → α} {a : α}
theorem sup_inf_distrib_left (s : Finset ι) (f : ι → α) (a : α) :
a ⊓ s.sup f = s.sup fun i => a ⊓ f i := by
induction s using Finset.cons_induction with
| empty => simp_rw [Finset.sup_empty, inf_bot_eq]
| cons _ _ _ h => rw [sup_cons, sup_cons, inf_sup_left, h]
#align finset.sup_inf_distrib_left Finset.sup_inf_distrib_left
theorem sup_inf_distrib_right (s : Finset ι) (f : ι → α) (a : α) :
s.sup f ⊓ a = s.sup fun i => f i ⊓ a := by
rw [_root_.inf_comm, s.sup_inf_distrib_left]
simp_rw [_root_.inf_comm]
#align finset.sup_inf_distrib_right Finset.sup_inf_distrib_right
protected theorem disjoint_sup_right : Disjoint a (s.sup f) ↔ ∀ ⦃i⦄, i ∈ s → Disjoint a (f i) := by
simp only [disjoint_iff, sup_inf_distrib_left, Finset.sup_eq_bot_iff]
#align finset.disjoint_sup_right Finset.disjoint_sup_right
protected theorem disjoint_sup_left : Disjoint (s.sup f) a ↔ ∀ ⦃i⦄, i ∈ s → Disjoint (f i) a := by
simp only [disjoint_iff, sup_inf_distrib_right, Finset.sup_eq_bot_iff]
#align finset.disjoint_sup_left Finset.disjoint_sup_left
theorem sup_inf_sup (s : Finset ι) (t : Finset κ) (f : ι → α) (g : κ → α) :
s.sup f ⊓ t.sup g = (s ×ˢ t).sup fun i => f i.1 ⊓ g i.2 := by
simp_rw [Finset.sup_inf_distrib_right, Finset.sup_inf_distrib_left, sup_product_left]
#align finset.sup_inf_sup Finset.sup_inf_sup
end OrderBot
section OrderTop
variable [OrderTop α] {f : ι → α} {g : κ → α} {s : Finset ι} {t : Finset κ} {a : α}
theorem inf_sup_distrib_left (s : Finset ι) (f : ι → α) (a : α) :
a ⊔ s.inf f = s.inf fun i => a ⊔ f i :=
@sup_inf_distrib_left αᵒᵈ _ _ _ _ _ _
#align finset.inf_sup_distrib_left Finset.inf_sup_distrib_left
theorem inf_sup_distrib_right (s : Finset ι) (f : ι → α) (a : α) :
s.inf f ⊔ a = s.inf fun i => f i ⊔ a :=
@sup_inf_distrib_right αᵒᵈ _ _ _ _ _ _
#align finset.inf_sup_distrib_right Finset.inf_sup_distrib_right
protected theorem codisjoint_inf_right :
Codisjoint a (s.inf f) ↔ ∀ ⦃i⦄, i ∈ s → Codisjoint a (f i) :=
@Finset.disjoint_sup_right αᵒᵈ _ _ _ _ _ _
#align finset.codisjoint_inf_right Finset.codisjoint_inf_right
protected theorem codisjoint_inf_left :
Codisjoint (s.inf f) a ↔ ∀ ⦃i⦄, i ∈ s → Codisjoint (f i) a :=
@Finset.disjoint_sup_left αᵒᵈ _ _ _ _ _ _
#align finset.codisjoint_inf_left Finset.codisjoint_inf_left
theorem inf_sup_inf (s : Finset ι) (t : Finset κ) (f : ι → α) (g : κ → α) :
s.inf f ⊔ t.inf g = (s ×ˢ t).inf fun i => f i.1 ⊔ g i.2 :=
@sup_inf_sup αᵒᵈ _ _ _ _ _ _ _ _
#align finset.inf_sup_inf Finset.inf_sup_inf
end OrderTop
section BoundedOrder
variable [BoundedOrder α] [DecidableEq ι]
--TODO: Extract out the obvious isomorphism `(insert i s).pi t ≃ t i ×ˢ s.pi t` from this proof
theorem inf_sup {κ : ι → Type*} (s : Finset ι) (t : ∀ i, Finset (κ i)) (f : ∀ i, κ i → α) :
(s.inf fun i => (t i).sup (f i)) =
(s.pi t).sup fun g => s.attach.inf fun i => f _ <| g _ i.2 := by
induction' s using Finset.induction with i s hi ih
· simp
rw [inf_insert, ih, attach_insert, sup_inf_sup]
refine eq_of_forall_ge_iff fun c => ?_
simp only [Finset.sup_le_iff, mem_product, mem_pi, and_imp, Prod.forall,
inf_insert, inf_image]
refine
⟨fun h g hg =>
h (g i <| mem_insert_self _ _) (fun j hj => g j <| mem_insert_of_mem hj)
(hg _ <| mem_insert_self _ _) fun j hj => hg _ <| mem_insert_of_mem hj,
fun h a g ha hg => ?_⟩
-- TODO: This `have` must be named to prevent it being shadowed by the internal `this` in `simpa`
have aux : ∀ j : { x // x ∈ s }, ↑j ≠ i := fun j : s => ne_of_mem_of_not_mem j.2 hi
-- Porting note: `simpa` doesn't support placeholders in proof terms
have := h (fun j hj => if hji : j = i then cast (congr_arg κ hji.symm) a
else g _ <| mem_of_mem_insert_of_ne hj hji) (fun j hj => ?_)
· simpa only [cast_eq, dif_pos, Function.comp, Subtype.coe_mk, dif_neg, aux] using this
rw [mem_insert] at hj
obtain (rfl | hj) := hj
· simpa
· simpa [ne_of_mem_of_not_mem hj hi] using hg _ _
#align finset.inf_sup Finset.inf_sup
theorem sup_inf {κ : ι → Type*} (s : Finset ι) (t : ∀ i, Finset (κ i)) (f : ∀ i, κ i → α) :
(s.sup fun i => (t i).inf (f i)) = (s.pi t).inf fun g => s.attach.sup fun i => f _ <| g _ i.2 :=
@inf_sup αᵒᵈ _ _ _ _ _ _ _ _
#align finset.sup_inf Finset.sup_inf
end BoundedOrder
end DistribLattice
section BooleanAlgebra
variable [BooleanAlgebra α] {s : Finset ι}
theorem sup_sdiff_left (s : Finset ι) (f : ι → α) (a : α) :
(s.sup fun b => a \ f b) = a \ s.inf f := by
induction s using Finset.cons_induction with
| empty => rw [sup_empty, inf_empty, sdiff_top]
| cons _ _ _ h => rw [sup_cons, inf_cons, h, sdiff_inf]
#align finset.sup_sdiff_left Finset.sup_sdiff_left
theorem inf_sdiff_left (hs : s.Nonempty) (f : ι → α) (a : α) :
(s.inf fun b => a \ f b) = a \ s.sup f := by
induction hs using Finset.Nonempty.cons_induction with
| singleton => rw [sup_singleton, inf_singleton]
| cons _ _ _ _ ih => rw [sup_cons, inf_cons, ih, sdiff_sup]
#align finset.inf_sdiff_left Finset.inf_sdiff_left
theorem inf_sdiff_right (hs : s.Nonempty) (f : ι → α) (a : α) :
(s.inf fun b => f b \ a) = s.inf f \ a := by
induction hs using Finset.Nonempty.cons_induction with
| singleton => rw [inf_singleton, inf_singleton]
| cons _ _ _ _ ih => rw [inf_cons, inf_cons, ih, inf_sdiff]
#align finset.inf_sdiff_right Finset.inf_sdiff_right
theorem inf_himp_right (s : Finset ι) (f : ι → α) (a : α) :
(s.inf fun b => f b ⇨ a) = s.sup f ⇨ a :=
@sup_sdiff_left αᵒᵈ _ _ _ _ _
#align finset.inf_himp_right Finset.inf_himp_right
theorem sup_himp_right (hs : s.Nonempty) (f : ι → α) (a : α) :
(s.sup fun b => f b ⇨ a) = s.inf f ⇨ a :=
@inf_sdiff_left αᵒᵈ _ _ _ hs _ _
#align finset.sup_himp_right Finset.sup_himp_right
theorem sup_himp_left (hs : s.Nonempty) (f : ι → α) (a : α) :
(s.sup fun b => a ⇨ f b) = a ⇨ s.sup f :=
@inf_sdiff_right αᵒᵈ _ _ _ hs _ _
#align finset.sup_himp_left Finset.sup_himp_left
@[simp]
protected theorem compl_sup (s : Finset ι) (f : ι → α) : (s.sup f)ᶜ = s.inf fun i => (f i)ᶜ :=
map_finset_sup (OrderIso.compl α) _ _
#align finset.compl_sup Finset.compl_sup
@[simp]
protected theorem compl_inf (s : Finset ι) (f : ι → α) : (s.inf f)ᶜ = s.sup fun i => (f i)ᶜ :=
map_finset_inf (OrderIso.compl α) _ _
#align finset.compl_inf Finset.compl_inf
end BooleanAlgebra
section LinearOrder
variable [LinearOrder α]
section OrderBot
variable [OrderBot α] {s : Finset ι} {f : ι → α} {a : α}
theorem comp_sup_eq_sup_comp_of_is_total [SemilatticeSup β] [OrderBot β] (g : α → β)
(mono_g : Monotone g) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) :=
comp_sup_eq_sup_comp g mono_g.map_sup bot
#align finset.comp_sup_eq_sup_comp_of_is_total Finset.comp_sup_eq_sup_comp_of_is_total
@[simp]
protected theorem le_sup_iff (ha : ⊥ < a) : a ≤ s.sup f ↔ ∃ b ∈ s, a ≤ f b := by
apply Iff.intro
· induction s using cons_induction with
| empty => exact (absurd · (not_le_of_lt ha))
| cons c t hc ih =>
rw [sup_cons, le_sup_iff]
exact fun
| Or.inl h => ⟨c, mem_cons.2 (Or.inl rfl), h⟩
| Or.inr h => let ⟨b, hb, hle⟩ := ih h; ⟨b, mem_cons.2 (Or.inr hb), hle⟩
· exact fun ⟨b, hb, hle⟩ => le_trans hle (le_sup hb)
#align finset.le_sup_iff Finset.le_sup_iff
@[simp]
protected theorem lt_sup_iff : a < s.sup f ↔ ∃ b ∈ s, a < f b := by
apply Iff.intro
· induction s using cons_induction with
| empty => exact (absurd · not_lt_bot)
| cons c t hc ih =>
rw [sup_cons, lt_sup_iff]
exact fun
| Or.inl h => ⟨c, mem_cons.2 (Or.inl rfl), h⟩
| Or.inr h => let ⟨b, hb, hlt⟩ := ih h; ⟨b, mem_cons.2 (Or.inr hb), hlt⟩
· exact fun ⟨b, hb, hlt⟩ => lt_of_lt_of_le hlt (le_sup hb)
#align finset.lt_sup_iff Finset.lt_sup_iff
@[simp]
protected theorem sup_lt_iff (ha : ⊥ < a) : s.sup f < a ↔ ∀ b ∈ s, f b < a :=
⟨fun hs b hb => lt_of_le_of_lt (le_sup hb) hs,
Finset.cons_induction_on s (fun _ => ha) fun c t hc => by
simpa only [sup_cons, sup_lt_iff, mem_cons, forall_eq_or_imp] using And.imp_right⟩
#align finset.sup_lt_iff Finset.sup_lt_iff
end OrderBot
section OrderTop
variable [OrderTop α] {s : Finset ι} {f : ι → α} {a : α}
theorem comp_inf_eq_inf_comp_of_is_total [SemilatticeInf β] [OrderTop β] (g : α → β)
(mono_g : Monotone g) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) :=
comp_inf_eq_inf_comp g mono_g.map_inf top
#align finset.comp_inf_eq_inf_comp_of_is_total Finset.comp_inf_eq_inf_comp_of_is_total
@[simp]
protected theorem inf_le_iff (ha : a < ⊤) : s.inf f ≤ a ↔ ∃ b ∈ s, f b ≤ a :=
@Finset.le_sup_iff αᵒᵈ _ _ _ _ _ _ ha
#align finset.inf_le_iff Finset.inf_le_iff
@[simp]
protected theorem inf_lt_iff : s.inf f < a ↔ ∃ b ∈ s, f b < a :=
@Finset.lt_sup_iff αᵒᵈ _ _ _ _ _ _
#align finset.inf_lt_iff Finset.inf_lt_iff
@[simp]
protected theorem lt_inf_iff (ha : a < ⊤) : a < s.inf f ↔ ∀ b ∈ s, a < f b :=
@Finset.sup_lt_iff αᵒᵈ _ _ _ _ _ _ ha
#align finset.lt_inf_iff Finset.lt_inf_iff
end OrderTop
end LinearOrder
theorem inf_eq_iInf [CompleteLattice β] (s : Finset α) (f : α → β) : s.inf f = ⨅ a ∈ s, f a :=
@sup_eq_iSup _ βᵒᵈ _ _ _
#align finset.inf_eq_infi Finset.inf_eq_iInf
theorem inf_id_eq_sInf [CompleteLattice α] (s : Finset α) : s.inf id = sInf s :=
@sup_id_eq_sSup αᵒᵈ _ _
#align finset.inf_id_eq_Inf Finset.inf_id_eq_sInf
theorem inf_id_set_eq_sInter (s : Finset (Set α)) : s.inf id = ⋂₀ ↑s :=
inf_id_eq_sInf _
#align finset.inf_id_set_eq_sInter Finset.inf_id_set_eq_sInter
@[simp]
theorem inf_set_eq_iInter (s : Finset α) (f : α → Set β) : s.inf f = ⋂ x ∈ s, f x :=
inf_eq_iInf _ _
#align finset.inf_set_eq_bInter Finset.inf_set_eq_iInter
theorem inf_eq_sInf_image [CompleteLattice β] (s : Finset α) (f : α → β) :
s.inf f = sInf (f '' s) :=
@sup_eq_sSup_image _ βᵒᵈ _ _ _
#align finset.inf_eq_Inf_image Finset.inf_eq_sInf_image
section Sup'
variable [SemilatticeSup α]
theorem sup_of_mem {s : Finset β} (f : β → α) {b : β} (h : b ∈ s) :
∃ a : α, s.sup ((↑) ∘ f : β → WithBot α) = ↑a :=
Exists.imp (fun _ => And.left) (@le_sup (WithBot α) _ _ _ _ _ _ h (f b) rfl)
#align finset.sup_of_mem Finset.sup_of_mem
/-- Given nonempty finset `s` then `s.sup' H f` is the supremum of its image under `f` in (possibly
unbounded) join-semilattice `α`, where `H` is a proof of nonemptiness. If `α` has a bottom element
you may instead use `Finset.sup` which does not require `s` nonempty. -/
def sup' (s : Finset β) (H : s.Nonempty) (f : β → α) : α :=
WithBot.unbot (s.sup ((↑) ∘ f)) (by simpa using H)
#align finset.sup' Finset.sup'
variable {s : Finset β} (H : s.Nonempty) (f : β → α)
@[simp]
theorem coe_sup' : ((s.sup' H f : α) : WithBot α) = s.sup ((↑) ∘ f) := by
rw [sup', WithBot.coe_unbot]
#align finset.coe_sup' Finset.coe_sup'
@[simp]
theorem sup'_cons {b : β} {hb : b ∉ s} :
(cons b s hb).sup' (nonempty_cons hb) f = f b ⊔ s.sup' H f := by
rw [← WithBot.coe_eq_coe]
simp [WithBot.coe_sup]
#align finset.sup'_cons Finset.sup'_cons
@[simp]
theorem sup'_insert [DecidableEq β] {b : β} :
(insert b s).sup' (insert_nonempty _ _) f = f b ⊔ s.sup' H f := by
rw [← WithBot.coe_eq_coe]
simp [WithBot.coe_sup]
#align finset.sup'_insert Finset.sup'_insert
@[simp]
theorem sup'_singleton {b : β} : ({b} : Finset β).sup' (singleton_nonempty _) f = f b :=
rfl
#align finset.sup'_singleton Finset.sup'_singleton
@[simp]
theorem sup'_le_iff {a : α} : s.sup' H f ≤ a ↔ ∀ b ∈ s, f b ≤ a := by
simp_rw [← @WithBot.coe_le_coe α, coe_sup', Finset.sup_le_iff]; rfl
#align finset.sup'_le_iff Finset.sup'_le_iff
alias ⟨_, sup'_le⟩ := sup'_le_iff
#align finset.sup'_le Finset.sup'_le
theorem le_sup' {b : β} (h : b ∈ s) : f b ≤ s.sup' ⟨b, h⟩ f :=
(sup'_le_iff ⟨b, h⟩ f).1 le_rfl b h
#align finset.le_sup' Finset.le_sup'
theorem le_sup'_of_le {a : α} {b : β} (hb : b ∈ s) (h : a ≤ f b) : a ≤ s.sup' ⟨b, hb⟩ f :=
h.trans <| le_sup' _ hb
#align finset.le_sup'_of_le Finset.le_sup'_of_le
@[simp]
theorem sup'_const (a : α) : s.sup' H (fun _ => a) = a := by
apply le_antisymm
· apply sup'_le
intros
exact le_rfl
· apply le_sup' (fun _ => a) H.choose_spec
#align finset.sup'_const Finset.sup'_const
theorem sup'_union [DecidableEq β] {s₁ s₂ : Finset β} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty)
(f : β → α) :
(s₁ ∪ s₂).sup' (h₁.mono subset_union_left) f = s₁.sup' h₁ f ⊔ s₂.sup' h₂ f :=
eq_of_forall_ge_iff fun a => by simp [or_imp, forall_and]
#align finset.sup'_union Finset.sup'_union
theorem sup'_biUnion [DecidableEq β] {s : Finset γ} (Hs : s.Nonempty) {t : γ → Finset β}
(Ht : ∀ b, (t b).Nonempty) :
(s.biUnion t).sup' (Hs.biUnion fun b _ => Ht b) f = s.sup' Hs (fun b => (t b).sup' (Ht b) f) :=
eq_of_forall_ge_iff fun c => by simp [@forall_swap _ β]
#align finset.sup'_bUnion Finset.sup'_biUnion
protected theorem sup'_comm {t : Finset γ} (hs : s.Nonempty) (ht : t.Nonempty) (f : β → γ → α) :
(s.sup' hs fun b => t.sup' ht (f b)) = t.sup' ht fun c => s.sup' hs fun b => f b c :=
eq_of_forall_ge_iff fun a => by simpa using forall₂_swap
#align finset.sup'_comm Finset.sup'_comm
theorem sup'_product_left {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) :
(s ×ˢ t).sup' h f = s.sup' h.fst fun i => t.sup' h.snd fun i' => f ⟨i, i'⟩ :=
eq_of_forall_ge_iff fun a => by simp [@forall_swap _ γ]
#align finset.sup'_product_left Finset.sup'_product_left
theorem sup'_product_right {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) :
(s ×ˢ t).sup' h f = t.sup' h.snd fun i' => s.sup' h.fst fun i => f ⟨i, i'⟩ := by
rw [sup'_product_left, Finset.sup'_comm]
#align finset.sup'_product_right Finset.sup'_product_right
section Prod
variable {ι κ α β : Type*} [SemilatticeSup α] [SemilatticeSup β] {s : Finset ι} {t : Finset κ}
/-- See also `Finset.sup'_prodMap`. -/
lemma prodMk_sup'_sup' (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) :
(sup' s hs f, sup' t ht g) = sup' (s ×ˢ t) (hs.product ht) (Prod.map f g) :=
eq_of_forall_ge_iff fun i ↦ by
obtain ⟨a, ha⟩ := hs
obtain ⟨b, hb⟩ := ht
simp only [Prod.map, sup'_le_iff, mem_product, and_imp, Prod.forall, Prod.le_def]
exact ⟨by aesop, fun h ↦ ⟨fun i hi ↦ (h _ _ hi hb).1, fun j hj ↦ (h _ _ ha hj).2⟩⟩
/-- See also `Finset.prodMk_sup'_sup'`. -/
-- @[simp] -- TODO: Why does `Prod.map_apply` simplify the LHS?
lemma sup'_prodMap (hst : (s ×ˢ t).Nonempty) (f : ι → α) (g : κ → β) :
sup' (s ×ˢ t) hst (Prod.map f g) = (sup' s hst.fst f, sup' t hst.snd g) :=
(prodMk_sup'_sup' _ _ _ _).symm
end Prod
theorem sup'_induction {p : α → Prop} (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊔ a₂))
(hs : ∀ b ∈ s, p (f b)) : p (s.sup' H f) := by
show @WithBot.recBotCoe α (fun _ => Prop) True p ↑(s.sup' H f)
rw [coe_sup']
refine sup_induction trivial (fun a₁ h₁ a₂ h₂ ↦ ?_) hs
match a₁, a₂ with
| ⊥, _ => rwa [bot_sup_eq]
| (a₁ : α), ⊥ => rwa [sup_bot_eq]
| (a₁ : α), (a₂ : α) => exact hp a₁ h₁ a₂ h₂
#align finset.sup'_induction Finset.sup'_induction
theorem sup'_mem (s : Set α) (w : ∀ᵉ (x ∈ s) (y ∈ s), x ⊔ y ∈ s) {ι : Type*}
(t : Finset ι) (H : t.Nonempty) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.sup' H p ∈ s :=
sup'_induction H p w h
#align finset.sup'_mem Finset.sup'_mem
@[congr]
theorem sup'_congr {t : Finset β} {f g : β → α} (h₁ : s = t) (h₂ : ∀ x ∈ s, f x = g x) :
s.sup' H f = t.sup' (h₁ ▸ H) g := by
subst s
refine eq_of_forall_ge_iff fun c => ?_
simp (config := { contextual := true }) only [sup'_le_iff, h₂]
#align finset.sup'_congr Finset.sup'_congr
theorem comp_sup'_eq_sup'_comp [SemilatticeSup γ] {s : Finset β} (H : s.Nonempty) {f : β → α}
(g : α → γ) (g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) : g (s.sup' H f) = s.sup' H (g ∘ f) := by
refine H.cons_induction ?_ ?_ <;> intros <;> simp [*]
#align finset.comp_sup'_eq_sup'_comp Finset.comp_sup'_eq_sup'_comp
@[simp]
theorem _root_.map_finset_sup' [SemilatticeSup β] [FunLike F α β] [SupHomClass F α β]
(f : F) {s : Finset ι} (hs) (g : ι → α) :
f (s.sup' hs g) = s.sup' hs (f ∘ g) := by
refine hs.cons_induction ?_ ?_ <;> intros <;> simp [*]
#align map_finset_sup' map_finset_sup'
lemma nsmul_sup' [LinearOrderedAddCommMonoid β] {s : Finset α}
(hs : s.Nonempty) (f : α → β) (n : ℕ) :
s.sup' hs (fun a => n • f a) = n • s.sup' hs f :=
let ns : SupHom β β := { toFun := (n • ·), map_sup' := fun _ _ => (nsmul_right_mono n).map_max }
(map_finset_sup' ns hs _).symm
/-- To rewrite from right to left, use `Finset.sup'_comp_eq_image`. -/
@[simp]
theorem sup'_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : (s.image f).Nonempty)
(g : β → α) :
(s.image f).sup' hs g = s.sup' hs.of_image (g ∘ f) := by
rw [← WithBot.coe_eq_coe]; simp only [coe_sup', sup_image, WithBot.coe_sup]; rfl
#align finset.sup'_image Finset.sup'_image
/-- A version of `Finset.sup'_image` with LHS and RHS reversed.
Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/
lemma sup'_comp_eq_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : s.Nonempty) (g : β → α) :
s.sup' hs (g ∘ f) = (s.image f).sup' (hs.image f) g :=
.symm <| sup'_image _ _
/-- To rewrite from right to left, use `Finset.sup'_comp_eq_map`. -/
@[simp]
theorem sup'_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : (s.map f).Nonempty) :
(s.map f).sup' hs g = s.sup' (map_nonempty.1 hs) (g ∘ f) := by
rw [← WithBot.coe_eq_coe, coe_sup', sup_map, coe_sup']
rfl
#align finset.sup'_map Finset.sup'_map
/-- A version of `Finset.sup'_map` with LHS and RHS reversed.
Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/
lemma sup'_comp_eq_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : s.Nonempty) :
s.sup' hs (g ∘ f) = (s.map f).sup' (map_nonempty.2 hs) g :=
.symm <| sup'_map _ _
theorem sup'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) (h₁ : s₁.Nonempty):
s₁.sup' h₁ f ≤ s₂.sup' (h₁.mono h) f :=
Finset.sup'_le h₁ _ (fun _ hb => le_sup' _ (h hb))
/-- A version of `Finset.sup'_mono` acceptable for `@[gcongr]`.
Instead of deducing `s₂.Nonempty` from `s₁.Nonempty` and `s₁ ⊆ s₂`,
this version takes it as an argument. -/
@[gcongr]
lemma _root_.GCongr.finset_sup'_le {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂)
{h₁ : s₁.Nonempty} {h₂ : s₂.Nonempty} : s₁.sup' h₁ f ≤ s₂.sup' h₂ f :=
sup'_mono f h h₁
end Sup'
section Inf'
variable [SemilatticeInf α]
theorem inf_of_mem {s : Finset β} (f : β → α) {b : β} (h : b ∈ s) :
∃ a : α, s.inf ((↑) ∘ f : β → WithTop α) = ↑a :=
@sup_of_mem αᵒᵈ _ _ _ f _ h
#align finset.inf_of_mem Finset.inf_of_mem
/-- Given nonempty finset `s` then `s.inf' H f` is the infimum of its image under `f` in (possibly
unbounded) meet-semilattice `α`, where `H` is a proof of nonemptiness. If `α` has a top element you
may instead use `Finset.inf` which does not require `s` nonempty. -/
def inf' (s : Finset β) (H : s.Nonempty) (f : β → α) : α :=
WithTop.untop (s.inf ((↑) ∘ f)) (by simpa using H)
#align finset.inf' Finset.inf'
variable {s : Finset β} (H : s.Nonempty) (f : β → α)
@[simp]
theorem coe_inf' : ((s.inf' H f : α) : WithTop α) = s.inf ((↑) ∘ f) :=
@coe_sup' αᵒᵈ _ _ _ H f
#align finset.coe_inf' Finset.coe_inf'
@[simp]
theorem inf'_cons {b : β} {hb : b ∉ s} :
(cons b s hb).inf' (nonempty_cons hb) f = f b ⊓ s.inf' H f :=
@sup'_cons αᵒᵈ _ _ _ H f _ _
#align finset.inf'_cons Finset.inf'_cons
@[simp]
theorem inf'_insert [DecidableEq β] {b : β} :
(insert b s).inf' (insert_nonempty _ _) f = f b ⊓ s.inf' H f :=
@sup'_insert αᵒᵈ _ _ _ H f _ _
#align finset.inf'_insert Finset.inf'_insert
@[simp]
theorem inf'_singleton {b : β} : ({b} : Finset β).inf' (singleton_nonempty _) f = f b :=
rfl
#align finset.inf'_singleton Finset.inf'_singleton
@[simp]
theorem le_inf'_iff {a : α} : a ≤ s.inf' H f ↔ ∀ b ∈ s, a ≤ f b :=
sup'_le_iff (α := αᵒᵈ) H f
#align finset.le_inf'_iff Finset.le_inf'_iff
theorem le_inf' {a : α} (hs : ∀ b ∈ s, a ≤ f b) : a ≤ s.inf' H f :=
sup'_le (α := αᵒᵈ) H f hs
#align finset.le_inf' Finset.le_inf'
theorem inf'_le {b : β} (h : b ∈ s) : s.inf' ⟨b, h⟩ f ≤ f b :=
le_sup' (α := αᵒᵈ) f h
#align finset.inf'_le Finset.inf'_le
theorem inf'_le_of_le {a : α} {b : β} (hb : b ∈ s) (h : f b ≤ a) :
s.inf' ⟨b, hb⟩ f ≤ a := (inf'_le _ hb).trans h
#align finset.inf'_le_of_le Finset.inf'_le_of_le
@[simp]
theorem inf'_const (a : α) : (s.inf' H fun _ => a) = a :=
sup'_const (α := αᵒᵈ) H a
#align finset.inf'_const Finset.inf'_const
theorem inf'_union [DecidableEq β] {s₁ s₂ : Finset β} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty)
(f : β → α) :
(s₁ ∪ s₂).inf' (h₁.mono subset_union_left) f = s₁.inf' h₁ f ⊓ s₂.inf' h₂ f :=
@sup'_union αᵒᵈ _ _ _ _ _ h₁ h₂ _
#align finset.inf'_union Finset.inf'_union
theorem inf'_biUnion [DecidableEq β] {s : Finset γ} (Hs : s.Nonempty) {t : γ → Finset β}
(Ht : ∀ b, (t b).Nonempty) :
(s.biUnion t).inf' (Hs.biUnion fun b _ => Ht b) f = s.inf' Hs (fun b => (t b).inf' (Ht b) f) :=
sup'_biUnion (α := αᵒᵈ) _ Hs Ht
#align finset.inf'_bUnion Finset.inf'_biUnion
protected theorem inf'_comm {t : Finset γ} (hs : s.Nonempty) (ht : t.Nonempty) (f : β → γ → α) :
(s.inf' hs fun b => t.inf' ht (f b)) = t.inf' ht fun c => s.inf' hs fun b => f b c :=
@Finset.sup'_comm αᵒᵈ _ _ _ _ _ hs ht _
#align finset.inf'_comm Finset.inf'_comm
theorem inf'_product_left {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) :
(s ×ˢ t).inf' h f = s.inf' h.fst fun i => t.inf' h.snd fun i' => f ⟨i, i'⟩ :=
sup'_product_left (α := αᵒᵈ) h f
#align finset.inf'_product_left Finset.inf'_product_left
theorem inf'_product_right {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) :
(s ×ˢ t).inf' h f = t.inf' h.snd fun i' => s.inf' h.fst fun i => f ⟨i, i'⟩ :=
sup'_product_right (α := αᵒᵈ) h f
#align finset.inf'_product_right Finset.inf'_product_right
section Prod
variable {ι κ α β : Type*} [SemilatticeInf α] [SemilatticeInf β] {s : Finset ι} {t : Finset κ}
/-- See also `Finset.inf'_prodMap`. -/
lemma prodMk_inf'_inf' (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) :
(inf' s hs f, inf' t ht g) = inf' (s ×ˢ t) (hs.product ht) (Prod.map f g) :=
prodMk_sup'_sup' (α := αᵒᵈ) (β := βᵒᵈ) hs ht _ _
/-- See also `Finset.prodMk_inf'_inf'`. -/
-- @[simp] -- TODO: Why does `Prod.map_apply` simplify the LHS?
lemma inf'_prodMap (hst : (s ×ˢ t).Nonempty) (f : ι → α) (g : κ → β) :
inf' (s ×ˢ t) hst (Prod.map f g) = (inf' s hst.fst f, inf' t hst.snd g) :=
(prodMk_inf'_inf' _ _ _ _).symm
end Prod
theorem comp_inf'_eq_inf'_comp [SemilatticeInf γ] {s : Finset β} (H : s.Nonempty) {f : β → α}
(g : α → γ) (g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) : g (s.inf' H f) = s.inf' H (g ∘ f) :=
comp_sup'_eq_sup'_comp (α := αᵒᵈ) (γ := γᵒᵈ) H g g_inf
#align finset.comp_inf'_eq_inf'_comp Finset.comp_inf'_eq_inf'_comp
theorem inf'_induction {p : α → Prop} (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊓ a₂))
(hs : ∀ b ∈ s, p (f b)) : p (s.inf' H f) :=
sup'_induction (α := αᵒᵈ) H f hp hs
#align finset.inf'_induction Finset.inf'_induction
theorem inf'_mem (s : Set α) (w : ∀ᵉ (x ∈ s) (y ∈ s), x ⊓ y ∈ s) {ι : Type*}
(t : Finset ι) (H : t.Nonempty) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.inf' H p ∈ s :=
inf'_induction H p w h
#align finset.inf'_mem Finset.inf'_mem
@[congr]
theorem inf'_congr {t : Finset β} {f g : β → α} (h₁ : s = t) (h₂ : ∀ x ∈ s, f x = g x) :
s.inf' H f = t.inf' (h₁ ▸ H) g :=
sup'_congr (α := αᵒᵈ) H h₁ h₂
#align finset.inf'_congr Finset.inf'_congr
@[simp]
theorem _root_.map_finset_inf' [SemilatticeInf β] [FunLike F α β] [InfHomClass F α β]
(f : F) {s : Finset ι} (hs) (g : ι → α) :
f (s.inf' hs g) = s.inf' hs (f ∘ g) := by
refine hs.cons_induction ?_ ?_ <;> intros <;> simp [*]
#align map_finset_inf' map_finset_inf'
lemma nsmul_inf' [LinearOrderedAddCommMonoid β] {s : Finset α}
(hs : s.Nonempty) (f : α → β) (n : ℕ) :
s.inf' hs (fun a => n • f a) = n • s.inf' hs f :=
let ns : InfHom β β := { toFun := (n • ·), map_inf' := fun _ _ => (nsmul_right_mono n).map_min }
(map_finset_inf' ns hs _).symm
/-- To rewrite from right to left, use `Finset.inf'_comp_eq_image`. -/
@[simp]
theorem inf'_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : (s.image f).Nonempty)
(g : β → α) :
(s.image f).inf' hs g = s.inf' hs.of_image (g ∘ f) :=
@sup'_image αᵒᵈ _ _ _ _ _ _ hs _
#align finset.inf'_image Finset.inf'_image
/-- A version of `Finset.inf'_image` with LHS and RHS reversed.
Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/
lemma inf'_comp_eq_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : s.Nonempty) (g : β → α) :
s.inf' hs (g ∘ f) = (s.image f).inf' (hs.image f) g :=
sup'_comp_eq_image (α := αᵒᵈ) hs g
/-- To rewrite from right to left, use `Finset.inf'_comp_eq_map`. -/
@[simp]
theorem inf'_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : (s.map f).Nonempty) :
(s.map f).inf' hs g = s.inf' (map_nonempty.1 hs) (g ∘ f) :=
sup'_map (α := αᵒᵈ) _ hs
#align finset.inf'_map Finset.inf'_map
/-- A version of `Finset.inf'_map` with LHS and RHS reversed.
Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/
lemma inf'_comp_eq_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : s.Nonempty) :
s.inf' hs (g ∘ f) = (s.map f).inf' (map_nonempty.2 hs) g :=
sup'_comp_eq_map (α := αᵒᵈ) g hs
theorem inf'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) (h₁ : s₁.Nonempty) :
s₂.inf' (h₁.mono h) f ≤ s₁.inf' h₁ f :=
Finset.le_inf' h₁ _ (fun _ hb => inf'_le _ (h hb))
/-- A version of `Finset.inf'_mono` acceptable for `@[gcongr]`.
Instead of deducing `s₂.Nonempty` from `s₁.Nonempty` and `s₁ ⊆ s₂`,
this version takes it as an argument. -/
@[gcongr]
lemma _root_.GCongr.finset_inf'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂)
{h₁ : s₁.Nonempty} {h₂ : s₂.Nonempty} : s₂.inf' h₂ f ≤ s₁.inf' h₁ f :=
inf'_mono f h h₁
end Inf'
section Sup
variable [SemilatticeSup α] [OrderBot α]
theorem sup'_eq_sup {s : Finset β} (H : s.Nonempty) (f : β → α) : s.sup' H f = s.sup f :=
le_antisymm (sup'_le H f fun _ => le_sup) (Finset.sup_le fun _ => le_sup' f)
#align finset.sup'_eq_sup Finset.sup'_eq_sup
theorem coe_sup_of_nonempty {s : Finset β} (h : s.Nonempty) (f : β → α) :
(↑(s.sup f) : WithBot α) = s.sup ((↑) ∘ f) := by simp only [← sup'_eq_sup h, coe_sup' h]
#align finset.coe_sup_of_nonempty Finset.coe_sup_of_nonempty
end Sup
section Inf
variable [SemilatticeInf α] [OrderTop α]
theorem inf'_eq_inf {s : Finset β} (H : s.Nonempty) (f : β → α) : s.inf' H f = s.inf f :=
sup'_eq_sup (α := αᵒᵈ) H f
#align finset.inf'_eq_inf Finset.inf'_eq_inf
theorem coe_inf_of_nonempty {s : Finset β} (h : s.Nonempty) (f : β → α) :
(↑(s.inf f) : WithTop α) = s.inf ((↑) ∘ f) :=
coe_sup_of_nonempty (α := αᵒᵈ) h f
#align finset.coe_inf_of_nonempty Finset.coe_inf_of_nonempty
end Inf
@[simp]
protected theorem sup_apply {C : β → Type*} [∀ b : β, SemilatticeSup (C b)]
[∀ b : β, OrderBot (C b)] (s : Finset α) (f : α → ∀ b : β, C b) (b : β) :
s.sup f b = s.sup fun a => f a b :=
comp_sup_eq_sup_comp (fun x : ∀ b : β, C b => x b) (fun _ _ => rfl) rfl
#align finset.sup_apply Finset.sup_apply
@[simp]
protected theorem inf_apply {C : β → Type*} [∀ b : β, SemilatticeInf (C b)]
[∀ b : β, OrderTop (C b)] (s : Finset α) (f : α → ∀ b : β, C b) (b : β) :
s.inf f b = s.inf fun a => f a b :=
Finset.sup_apply (C := fun b => (C b)ᵒᵈ) s f b
#align finset.inf_apply Finset.inf_apply
@[simp]
protected theorem sup'_apply {C : β → Type*} [∀ b : β, SemilatticeSup (C b)]
{s : Finset α} (H : s.Nonempty) (f : α → ∀ b : β, C b) (b : β) :
s.sup' H f b = s.sup' H fun a => f a b :=
comp_sup'_eq_sup'_comp H (fun x : ∀ b : β, C b => x b) fun _ _ => rfl
#align finset.sup'_apply Finset.sup'_apply
@[simp]
protected theorem inf'_apply {C : β → Type*} [∀ b : β, SemilatticeInf (C b)]
{s : Finset α} (H : s.Nonempty) (f : α → ∀ b : β, C b) (b : β) :
s.inf' H f b = s.inf' H fun a => f a b :=
Finset.sup'_apply (C := fun b => (C b)ᵒᵈ) H f b
#align finset.inf'_apply Finset.inf'_apply
@[simp]
theorem toDual_sup' [SemilatticeSup α] {s : Finset ι} (hs : s.Nonempty) (f : ι → α) :
toDual (s.sup' hs f) = s.inf' hs (toDual ∘ f) :=
rfl
#align finset.to_dual_sup' Finset.toDual_sup'
@[simp]
theorem toDual_inf' [SemilatticeInf α] {s : Finset ι} (hs : s.Nonempty) (f : ι → α) :
toDual (s.inf' hs f) = s.sup' hs (toDual ∘ f) :=
rfl
#align finset.to_dual_inf' Finset.toDual_inf'
@[simp]
theorem ofDual_sup' [SemilatticeInf α] {s : Finset ι} (hs : s.Nonempty) (f : ι → αᵒᵈ) :
ofDual (s.sup' hs f) = s.inf' hs (ofDual ∘ f) :=
rfl
#align finset.of_dual_sup' Finset.ofDual_sup'
@[simp]
theorem ofDual_inf' [SemilatticeSup α] {s : Finset ι} (hs : s.Nonempty) (f : ι → αᵒᵈ) :
ofDual (s.inf' hs f) = s.sup' hs (ofDual ∘ f) :=
rfl
#align finset.of_dual_inf' Finset.ofDual_inf'
section DistribLattice
variable [DistribLattice α] {s : Finset ι} {t : Finset κ} (hs : s.Nonempty) (ht : t.Nonempty)
{f : ι → α} {g : κ → α} {a : α}
theorem sup'_inf_distrib_left (f : ι → α) (a : α) :
a ⊓ s.sup' hs f = s.sup' hs fun i ↦ a ⊓ f i := by
induction hs using Finset.Nonempty.cons_induction with
| singleton => simp
| cons _ _ _ hs ih => simp_rw [sup'_cons hs, inf_sup_left, ih]
#align finset.sup'_inf_distrib_left Finset.sup'_inf_distrib_left
theorem sup'_inf_distrib_right (f : ι → α) (a : α) :
s.sup' hs f ⊓ a = s.sup' hs fun i => f i ⊓ a := by
rw [inf_comm, sup'_inf_distrib_left]; simp_rw [inf_comm]
#align finset.sup'_inf_distrib_right Finset.sup'_inf_distrib_right
theorem sup'_inf_sup' (f : ι → α) (g : κ → α) :
s.sup' hs f ⊓ t.sup' ht g = (s ×ˢ t).sup' (hs.product ht) fun i => f i.1 ⊓ g i.2 := by
simp_rw [Finset.sup'_inf_distrib_right, Finset.sup'_inf_distrib_left, sup'_product_left]
#align finset.sup'_inf_sup' Finset.sup'_inf_sup'
theorem inf'_sup_distrib_left (f : ι → α) (a : α) : a ⊔ s.inf' hs f = s.inf' hs fun i => a ⊔ f i :=
@sup'_inf_distrib_left αᵒᵈ _ _ _ hs _ _
#align finset.inf'_sup_distrib_left Finset.inf'_sup_distrib_left
theorem inf'_sup_distrib_right (f : ι → α) (a : α) : s.inf' hs f ⊔ a = s.inf' hs fun i => f i ⊔ a :=
@sup'_inf_distrib_right αᵒᵈ _ _ _ hs _ _
#align finset.inf'_sup_distrib_right Finset.inf'_sup_distrib_right
theorem inf'_sup_inf' (f : ι → α) (g : κ → α) :
s.inf' hs f ⊔ t.inf' ht g = (s ×ˢ t).inf' (hs.product ht) fun i => f i.1 ⊔ g i.2 :=
@sup'_inf_sup' αᵒᵈ _ _ _ _ _ hs ht _ _
#align finset.inf'_sup_inf' Finset.inf'_sup_inf'
end DistribLattice
section LinearOrder
variable [LinearOrder α] {s : Finset ι} (H : s.Nonempty) {f : ι → α} {a : α}
@[simp]
theorem le_sup'_iff : a ≤ s.sup' H f ↔ ∃ b ∈ s, a ≤ f b := by
rw [← WithBot.coe_le_coe, coe_sup', Finset.le_sup_iff (WithBot.bot_lt_coe a)]
exact exists_congr (fun _ => and_congr_right' WithBot.coe_le_coe)
#align finset.le_sup'_iff Finset.le_sup'_iff
@[simp]
theorem lt_sup'_iff : a < s.sup' H f ↔ ∃ b ∈ s, a < f b := by
rw [← WithBot.coe_lt_coe, coe_sup', Finset.lt_sup_iff]
exact exists_congr (fun _ => and_congr_right' WithBot.coe_lt_coe)
#align finset.lt_sup'_iff Finset.lt_sup'_iff
@[simp]
theorem sup'_lt_iff : s.sup' H f < a ↔ ∀ i ∈ s, f i < a := by
rw [← WithBot.coe_lt_coe, coe_sup', Finset.sup_lt_iff (WithBot.bot_lt_coe a)]
exact forall₂_congr (fun _ _ => WithBot.coe_lt_coe)
#align finset.sup'_lt_iff Finset.sup'_lt_iff
@[simp]
theorem inf'_le_iff : s.inf' H f ≤ a ↔ ∃ i ∈ s, f i ≤ a :=
le_sup'_iff (α := αᵒᵈ) H
#align finset.inf'_le_iff Finset.inf'_le_iff
@[simp]
theorem inf'_lt_iff : s.inf' H f < a ↔ ∃ i ∈ s, f i < a :=
lt_sup'_iff (α := αᵒᵈ) H
#align finset.inf'_lt_iff Finset.inf'_lt_iff
@[simp]
theorem lt_inf'_iff : a < s.inf' H f ↔ ∀ i ∈ s, a < f i :=
sup'_lt_iff (α := αᵒᵈ) H
#align finset.lt_inf'_iff Finset.lt_inf'_iff
theorem exists_mem_eq_sup' (f : ι → α) : ∃ i, i ∈ s ∧ s.sup' H f = f i := by
induction H using Finset.Nonempty.cons_induction with
| singleton c => exact ⟨c, mem_singleton_self c, rfl⟩
| cons c s hcs hs ih =>
rcases ih with ⟨b, hb, h'⟩
rw [sup'_cons hs, h']
cases le_total (f b) (f c) with
| inl h => exact ⟨c, mem_cons.2 (Or.inl rfl), sup_eq_left.2 h⟩
| inr h => exact ⟨b, mem_cons.2 (Or.inr hb), sup_eq_right.2 h⟩
#align finset.exists_mem_eq_sup' Finset.exists_mem_eq_sup'
theorem exists_mem_eq_inf' (f : ι → α) : ∃ i, i ∈ s ∧ s.inf' H f = f i :=
exists_mem_eq_sup' (α := αᵒᵈ) H f
#align finset.exists_mem_eq_inf' Finset.exists_mem_eq_inf'
theorem exists_mem_eq_sup [OrderBot α] (s : Finset ι) (h : s.Nonempty) (f : ι → α) :
∃ i, i ∈ s ∧ s.sup f = f i :=
sup'_eq_sup h f ▸ exists_mem_eq_sup' h f
#align finset.exists_mem_eq_sup Finset.exists_mem_eq_sup
theorem exists_mem_eq_inf [OrderTop α] (s : Finset ι) (h : s.Nonempty) (f : ι → α) :
∃ i, i ∈ s ∧ s.inf f = f i :=
exists_mem_eq_sup (α := αᵒᵈ) s h f
#align finset.exists_mem_eq_inf Finset.exists_mem_eq_inf
end LinearOrder
/-! ### max and min of finite sets -/
section MaxMin
variable [LinearOrder α]
/-- Let `s` be a finset in a linear order. Then `s.max` is the maximum of `s` if `s` is not empty,
and `⊥` otherwise. It belongs to `WithBot α`. If you want to get an element of `α`, see
`s.max'`. -/
protected def max (s : Finset α) : WithBot α :=
sup s (↑)
#align finset.max Finset.max
theorem max_eq_sup_coe {s : Finset α} : s.max = s.sup (↑) :=
rfl
#align finset.max_eq_sup_coe Finset.max_eq_sup_coe
theorem max_eq_sup_withBot (s : Finset α) : s.max = sup s (↑) :=
rfl
#align finset.max_eq_sup_with_bot Finset.max_eq_sup_withBot
@[simp]
theorem max_empty : (∅ : Finset α).max = ⊥ :=
rfl
#align finset.max_empty Finset.max_empty
@[simp]
theorem max_insert {a : α} {s : Finset α} : (insert a s).max = max ↑a s.max :=
fold_insert_idem
#align finset.max_insert Finset.max_insert
@[simp]
theorem max_singleton {a : α} : Finset.max {a} = (a : WithBot α) := by
rw [← insert_emptyc_eq]
exact max_insert
#align finset.max_singleton Finset.max_singleton
theorem max_of_mem {s : Finset α} {a : α} (h : a ∈ s) : ∃ b : α, s.max = b := by
obtain ⟨b, h, _⟩ := le_sup (α := WithBot α) h _ rfl
exact ⟨b, h⟩
#align finset.max_of_mem Finset.max_of_mem
theorem max_of_nonempty {s : Finset α} (h : s.Nonempty) : ∃ a : α, s.max = a :=
let ⟨_, h⟩ := h
max_of_mem h
#align finset.max_of_nonempty Finset.max_of_nonempty
theorem max_eq_bot {s : Finset α} : s.max = ⊥ ↔ s = ∅ :=
⟨fun h ↦ s.eq_empty_or_nonempty.elim id fun H ↦ by
obtain ⟨a, ha⟩ := max_of_nonempty H
rw [h] at ha; cases ha; , -- the `;` is needed since the `cases` syntax allows `cases a, b`
fun h ↦ h.symm ▸ max_empty⟩
#align finset.max_eq_bot Finset.max_eq_bot
| Mathlib/Data/Finset/Lattice.lean | 1,396 | 1,406 | theorem mem_of_max {s : Finset α} : ∀ {a : α}, s.max = a → a ∈ s := by |
induction' s using Finset.induction_on with b s _ ih
· intro _ H; cases H
· intro a h
by_cases p : b = a
· induction p
exact mem_insert_self b s
· cases' max_choice (↑b) s.max with q q <;> rw [max_insert, q] at h
· cases h
cases p rfl
· exact mem_insert_of_mem (ih h)
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Finsupp
import Mathlib.Algebra.Module.Basic
import Mathlib.Algebra.Regular.SMul
import Mathlib.Data.Finset.Preimage
import Mathlib.Data.Rat.BigOperators
import Mathlib.GroupTheory.GroupAction.Hom
import Mathlib.Data.Set.Subsingleton
#align_import data.finsupp.basic from "leanprover-community/mathlib"@"f69db8cecc668e2d5894d7e9bfc491da60db3b9f"
/-!
# Miscellaneous definitions, lemmas, and constructions using finsupp
## Main declarations
* `Finsupp.graph`: the finset of input and output pairs with non-zero outputs.
* `Finsupp.mapRange.equiv`: `Finsupp.mapRange` as an equiv.
* `Finsupp.mapDomain`: maps the domain of a `Finsupp` by a function and by summing.
* `Finsupp.comapDomain`: postcomposition of a `Finsupp` with a function injective on the preimage
of its support.
* `Finsupp.some`: restrict a finitely supported function on `Option α` to a finitely supported
function on `α`.
* `Finsupp.filter`: `filter p f` is the finitely supported function that is `f a` if `p a` is true
and 0 otherwise.
* `Finsupp.frange`: the image of a finitely supported function on its support.
* `Finsupp.subtype_domain`: the restriction of a finitely supported function `f` to a subtype.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## TODO
* This file is currently ~1600 lines long and is quite a miscellany of definitions and lemmas,
so it should be divided into smaller pieces.
* Expand the list of definitions and important lemmas to the module docstring.
-/
noncomputable section
open Finset Function
variable {α β γ ι M M' N P G H R S : Type*}
namespace Finsupp
/-! ### Declarations about `graph` -/
section Graph
variable [Zero M]
/-- The graph of a finitely supported function over its support, i.e. the finset of input and output
pairs with non-zero outputs. -/
def graph (f : α →₀ M) : Finset (α × M) :=
f.support.map ⟨fun a => Prod.mk a (f a), fun _ _ h => (Prod.mk.inj h).1⟩
#align finsupp.graph Finsupp.graph
theorem mk_mem_graph_iff {a : α} {m : M} {f : α →₀ M} : (a, m) ∈ f.graph ↔ f a = m ∧ m ≠ 0 := by
simp_rw [graph, mem_map, mem_support_iff]
constructor
· rintro ⟨b, ha, rfl, -⟩
exact ⟨rfl, ha⟩
· rintro ⟨rfl, ha⟩
exact ⟨a, ha, rfl⟩
#align finsupp.mk_mem_graph_iff Finsupp.mk_mem_graph_iff
@[simp]
| Mathlib/Data/Finsupp/Basic.lean | 78 | 80 | theorem mem_graph_iff {c : α × M} {f : α →₀ M} : c ∈ f.graph ↔ f c.1 = c.2 ∧ c.2 ≠ 0 := by |
cases c
exact mk_mem_graph_iff
|
/-
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.Rename
#align_import data.mv_polynomial.comap from "leanprover-community/mathlib"@"aba31c938d3243cc671be7091b28a1e0814647ee"
/-!
# `comap` operation on `MvPolynomial`
This file defines the `comap` function on `MvPolynomial`.
`MvPolynomial.comap` is a low-tech example of a map of "algebraic varieties," modulo the fact that
`mathlib` does not yet define varieties.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[CommSemiring R]` (the coefficients)
-/
namespace MvPolynomial
variable {σ : Type*} {τ : Type*} {υ : Type*} {R : Type*} [CommSemiring R]
/-- Given an algebra hom `f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R`
and a variable evaluation `v : τ → R`,
`comap f v` produces a variable evaluation `σ → R`.
-/
noncomputable def comap (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) : (τ → R) → σ → R :=
fun x i => aeval x (f (X i))
#align mv_polynomial.comap MvPolynomial.comap
@[simp]
theorem comap_apply (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) (x : τ → R) (i : σ) :
comap f x i = aeval x (f (X i)) :=
rfl
#align mv_polynomial.comap_apply MvPolynomial.comap_apply
@[simp]
theorem comap_id_apply (x : σ → R) : comap (AlgHom.id R (MvPolynomial σ R)) x = x := by
funext i
simp only [comap, AlgHom.id_apply, id, aeval_X]
#align mv_polynomial.comap_id_apply MvPolynomial.comap_id_apply
variable (σ R)
theorem comap_id : comap (AlgHom.id R (MvPolynomial σ R)) = id := by
funext x
exact comap_id_apply x
#align mv_polynomial.comap_id MvPolynomial.comap_id
variable {σ R}
theorem comap_comp_apply (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R)
(g : MvPolynomial τ R →ₐ[R] MvPolynomial υ R) (x : υ → R) :
comap (g.comp f) x = comap f (comap g x) := by
funext i
trans aeval x (aeval (fun i => g (X i)) (f (X i)))
· apply eval₂Hom_congr rfl rfl
rw [AlgHom.comp_apply]
suffices g = aeval fun i => g (X i) by rw [← this]
exact aeval_unique g
· simp only [comap, aeval_eq_eval₂Hom, map_eval₂Hom, AlgHom.comp_apply]
refine eval₂Hom_congr ?_ rfl rfl
ext r
apply aeval_C
#align mv_polynomial.comap_comp_apply MvPolynomial.comap_comp_apply
theorem comap_comp (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R)
(g : MvPolynomial τ R →ₐ[R] MvPolynomial υ R) : comap (g.comp f) = comap f ∘ comap g := by
funext x
exact comap_comp_apply _ _ _
#align mv_polynomial.comap_comp MvPolynomial.comap_comp
| Mathlib/Algebra/MvPolynomial/Comap.lean | 83 | 87 | theorem comap_eq_id_of_eq_id (f : MvPolynomial σ R →ₐ[R] MvPolynomial σ R) (hf : ∀ φ, f φ = φ)
(x : σ → R) : comap f x = x := by |
convert comap_id_apply x
ext1 φ
simp [hf, AlgHom.id_apply]
|
/-
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.MeasureTheory.Covering.DensityTheorem
#align_import measure_theory.covering.liminf_limsup from "leanprover-community/mathlib"@"5f6e827d81dfbeb6151d7016586ceeb0099b9655"
/-!
# Liminf, limsup, and uniformly locally doubling measures.
This file is a place to collect lemmas about liminf and limsup for subsets of a metric space
carrying a uniformly locally doubling measure.
## Main results:
* `blimsup_cthickening_mul_ae_eq`: the limsup of the closed thickening of a sequence of subsets
of a metric space is unchanged almost everywhere for a uniformly locally doubling measure if the
sequence of distances is multiplied by a positive scale factor. This is a generalisation of a
result of Cassels, appearing as Lemma 9 on page 217 of
[J.W.S. Cassels, *Some metrical theorems in Diophantine approximation. I*](cassels1950).
* `blimsup_thickening_mul_ae_eq`: a variant of `blimsup_cthickening_mul_ae_eq` for thickenings
rather than closed thickenings.
-/
open Set Filter Metric MeasureTheory TopologicalSpace
open scoped NNReal ENNReal Topology
variable {α : Type*} [MetricSpace α] [SecondCountableTopology α] [MeasurableSpace α] [BorelSpace α]
variable (μ : Measure α) [IsLocallyFiniteMeasure μ] [IsUnifLocDoublingMeasure μ]
/-- This is really an auxiliary result en route to `blimsup_cthickening_ae_le_of_eventually_mul_le`
(which is itself an auxiliary result en route to `blimsup_cthickening_mul_ae_eq`).
NB: The `: Set α` type ascription is present because of
https://github.com/leanprover-community/mathlib/issues/16932. -/
| Mathlib/MeasureTheory/Covering/LiminfLimsup.lean | 41 | 150 | theorem blimsup_cthickening_ae_le_of_eventually_mul_le_aux (p : ℕ → Prop) {s : ℕ → Set α}
(hs : ∀ i, IsClosed (s i)) {r₁ r₂ : ℕ → ℝ} (hr : Tendsto r₁ atTop (𝓝[>] 0)) (hrp : 0 ≤ r₁)
{M : ℝ} (hM : 0 < M) (hM' : M < 1) (hMr : ∀ᶠ i in atTop, M * r₁ i ≤ r₂ i) :
(blimsup (fun i => cthickening (r₁ i) (s i)) atTop p : Set α) ≤ᵐ[μ]
(blimsup (fun i => cthickening (r₂ i) (s i)) atTop p : Set α) := by |
/- Sketch of proof:
Assume that `p` is identically true for simplicity. Let `Y₁ i = cthickening (r₁ i) (s i)`, define
`Y₂` similarly except using `r₂`, and let `(Z i) = ⋃_{j ≥ i} (Y₂ j)`. Our goal is equivalent to
showing that `μ ((limsup Y₁) \ (Z i)) = 0` for all `i`.
Assume for contradiction that `μ ((limsup Y₁) \ (Z i)) ≠ 0` for some `i` and let
`W = (limsup Y₁) \ (Z i)`. Apply Lebesgue's density theorem to obtain a point `d` in `W` of
density `1`. Since `d ∈ limsup Y₁`, there is a subsequence of `j ↦ Y₁ j`, indexed by
`f 0 < f 1 < ...`, such that `d ∈ Y₁ (f j)` for all `j`. For each `j`, we may thus choose
`w j ∈ s (f j)` such that `d ∈ B j`, where `B j = closedBall (w j) (r₁ (f j))`. Note that
since `d` has density one, `μ (W ∩ (B j)) / μ (B j) → 1`.
We obtain our contradiction by showing that there exists `η < 1` such that
`μ (W ∩ (B j)) / μ (B j) ≤ η` for sufficiently large `j`. In fact we claim that `η = 1 - C⁻¹`
is such a value where `C` is the scaling constant of `M⁻¹` for the uniformly locally doubling
measure `μ`.
To prove the claim, let `b j = closedBall (w j) (M * r₁ (f j))` and for given `j` consider the
sets `b j` and `W ∩ (B j)`. These are both subsets of `B j` and are disjoint for large enough `j`
since `M * r₁ j ≤ r₂ j` and thus `b j ⊆ Z i ⊆ Wᶜ`. We thus have:
`μ (b j) + μ (W ∩ (B j)) ≤ μ (B j)`. Combining this with `μ (B j) ≤ C * μ (b j)` we obtain
the required inequality. -/
set Y₁ : ℕ → Set α := fun i => cthickening (r₁ i) (s i)
set Y₂ : ℕ → Set α := fun i => cthickening (r₂ i) (s i)
let Z : ℕ → Set α := fun i => ⋃ (j) (_ : p j ∧ i ≤ j), Y₂ j
suffices ∀ i, μ (atTop.blimsup Y₁ p \ Z i) = 0 by
rwa [ae_le_set, @blimsup_eq_iInf_biSup_of_nat _ _ _ Y₂, iInf_eq_iInter, diff_iInter,
measure_iUnion_null_iff]
intros i
set W := atTop.blimsup Y₁ p \ Z i
by_contra contra
obtain ⟨d, hd, hd'⟩ : ∃ d, d ∈ W ∧ ∀ {ι : Type _} {l : Filter ι} (w : ι → α) (δ : ι → ℝ),
Tendsto δ l (𝓝[>] 0) → (∀ᶠ j in l, d ∈ closedBall (w j) (2 * δ j)) →
Tendsto (fun j => μ (W ∩ closedBall (w j) (δ j)) / μ (closedBall (w j) (δ j))) l (𝓝 1) :=
Measure.exists_mem_of_measure_ne_zero_of_ae contra
(IsUnifLocDoublingMeasure.ae_tendsto_measure_inter_div μ W 2)
replace hd : d ∈ blimsup Y₁ atTop p := ((mem_diff _).mp hd).1
obtain ⟨f : ℕ → ℕ, hf⟩ := exists_forall_mem_of_hasBasis_mem_blimsup' atTop_basis hd
simp only [forall_and] at hf
obtain ⟨hf₀ : ∀ j, d ∈ cthickening (r₁ (f j)) (s (f j)), hf₁, hf₂ : ∀ j, j ≤ f j⟩ := hf
have hf₃ : Tendsto f atTop atTop :=
tendsto_atTop_atTop.mpr fun j => ⟨f j, fun i hi => (hf₂ j).trans (hi.trans <| hf₂ i)⟩
replace hr : Tendsto (r₁ ∘ f) atTop (𝓝[>] 0) := hr.comp hf₃
replace hMr : ∀ᶠ j in atTop, M * r₁ (f j) ≤ r₂ (f j) := hf₃.eventually hMr
replace hf₀ : ∀ j, ∃ w ∈ s (f j), d ∈ closedBall w (2 * r₁ (f j)) := by
intro j
specialize hrp (f j)
rw [Pi.zero_apply] at hrp
rcases eq_or_lt_of_le hrp with (hr0 | hrp')
· specialize hf₀ j
rw [← hr0, cthickening_zero, (hs (f j)).closure_eq] at hf₀
exact ⟨d, hf₀, by simp [← hr0]⟩
· simpa using mem_iUnion₂.mp (cthickening_subset_iUnion_closedBall_of_lt (s (f j))
(by positivity) (lt_two_mul_self hrp') (hf₀ j))
choose w hw hw' using hf₀
let C := IsUnifLocDoublingMeasure.scalingConstantOf μ M⁻¹
have hC : 0 < C :=
lt_of_lt_of_le zero_lt_one (IsUnifLocDoublingMeasure.one_le_scalingConstantOf μ M⁻¹)
suffices ∃ η < (1 : ℝ≥0),
∀ᶠ j in atTop, μ (W ∩ closedBall (w j) (r₁ (f j))) / μ (closedBall (w j) (r₁ (f j))) ≤ η by
obtain ⟨η, hη, hη'⟩ := this
replace hη' : 1 ≤ η := by
simpa only [ENNReal.one_le_coe_iff] using
le_of_tendsto (hd' w (fun j => r₁ (f j)) hr <| eventually_of_forall hw') hη'
exact (lt_self_iff_false _).mp (lt_of_lt_of_le hη hη')
refine ⟨1 - C⁻¹, tsub_lt_self zero_lt_one (inv_pos.mpr hC), ?_⟩
replace hC : C ≠ 0 := ne_of_gt hC
let b : ℕ → Set α := fun j => closedBall (w j) (M * r₁ (f j))
let B : ℕ → Set α := fun j => closedBall (w j) (r₁ (f j))
have h₁ : ∀ j, b j ⊆ B j := fun j =>
closedBall_subset_closedBall (mul_le_of_le_one_left (hrp (f j)) hM'.le)
have h₂ : ∀ j, W ∩ B j ⊆ B j := fun j => inter_subset_right
have h₃ : ∀ᶠ j in atTop, Disjoint (b j) (W ∩ B j) := by
apply hMr.mp
rw [eventually_atTop]
refine
⟨i, fun j hj hj' => Disjoint.inf_right (B j) <| Disjoint.inf_right' (blimsup Y₁ atTop p) ?_⟩
change Disjoint (b j) (Z i)ᶜ
rw [disjoint_compl_right_iff_subset]
refine (closedBall_subset_cthickening (hw j) (M * r₁ (f j))).trans
((cthickening_mono hj' _).trans fun a ha => ?_)
simp only [Z, mem_iUnion, exists_prop]
exact ⟨f j, ⟨hf₁ j, hj.le.trans (hf₂ j)⟩, ha⟩
have h₄ : ∀ᶠ j in atTop, μ (B j) ≤ C * μ (b j) :=
(hr.eventually (IsUnifLocDoublingMeasure.eventually_measure_le_scaling_constant_mul'
μ M hM)).mono fun j hj => hj (w j)
refine (h₃.and h₄).mono fun j hj₀ => ?_
change μ (W ∩ B j) / μ (B j) ≤ ↑(1 - C⁻¹)
rcases eq_or_ne (μ (B j)) ∞ with (hB | hB); · simp [hB]
apply ENNReal.div_le_of_le_mul
rw [ENNReal.coe_sub, ENNReal.coe_one, ENNReal.sub_mul fun _ _ => hB, one_mul]
replace hB : ↑C⁻¹ * μ (B j) ≠ ∞ := by
refine ENNReal.mul_ne_top ?_ hB
rwa [ENNReal.coe_inv hC, Ne, ENNReal.inv_eq_top, ENNReal.coe_eq_zero]
obtain ⟨hj₁ : Disjoint (b j) (W ∩ B j), hj₂ : μ (B j) ≤ C * μ (b j)⟩ := hj₀
replace hj₂ : ↑C⁻¹ * μ (B j) ≤ μ (b j) := by
rw [ENNReal.coe_inv hC, ← ENNReal.div_eq_inv_mul]
exact ENNReal.div_le_of_le_mul' hj₂
have hj₃ : ↑C⁻¹ * μ (B j) + μ (W ∩ B j) ≤ μ (B j) := by
refine le_trans (add_le_add_right hj₂ _) ?_
rw [← measure_union' hj₁ measurableSet_closedBall]
exact measure_mono (union_subset (h₁ j) (h₂ j))
replace hj₃ := tsub_le_tsub_right hj₃ (↑C⁻¹ * μ (B j))
rwa [ENNReal.add_sub_cancel_left hB] at hj₃
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Scott Morrison, Adam Topaz
-/
import Mathlib.Tactic.Linarith
import Mathlib.CategoryTheory.Skeletal
import Mathlib.Data.Fintype.Sort
import Mathlib.Order.Category.NonemptyFinLinOrd
import Mathlib.CategoryTheory.Functor.ReflectsIso
#align_import algebraic_topology.simplex_category from "leanprover-community/mathlib"@"e8ac6315bcfcbaf2d19a046719c3b553206dac75"
/-! # The simplex category
We construct a skeletal model of the simplex category, with objects `ℕ` and the
morphism `n ⟶ m` being the monotone maps from `Fin (n+1)` to `Fin (m+1)`.
We show that this category is equivalent to `NonemptyFinLinOrd`.
## Remarks
The definitions `SimplexCategory` and `SimplexCategory.Hom` are marked as irreducible.
We provide the following functions to work with these objects:
1. `SimplexCategory.mk` creates an object of `SimplexCategory` out of a natural number.
Use the notation `[n]` in the `Simplicial` locale.
2. `SimplexCategory.len` gives the "length" of an object of `SimplexCategory`, as a natural.
3. `SimplexCategory.Hom.mk` makes a morphism out of a monotone map between `Fin`'s.
4. `SimplexCategory.Hom.toOrderHom` gives the underlying monotone map associated to a
term of `SimplexCategory.Hom`.
-/
universe v
open CategoryTheory CategoryTheory.Limits
/-- The simplex category:
* objects are natural numbers `n : ℕ`
* morphisms from `n` to `m` are monotone functions `Fin (n+1) → Fin (m+1)`
-/
def SimplexCategory :=
ℕ
#align simplex_category SimplexCategory
namespace SimplexCategory
section
-- Porting note: the definition of `SimplexCategory` is made irreducible below
/-- Interpret a natural number as an object of the simplex category. -/
def mk (n : ℕ) : SimplexCategory :=
n
#align simplex_category.mk SimplexCategory.mk
/-- the `n`-dimensional simplex can be denoted `[n]` -/
scoped[Simplicial] notation "[" n "]" => SimplexCategory.mk n
-- TODO: Make `len` irreducible.
/-- The length of an object of `SimplexCategory`. -/
def len (n : SimplexCategory) : ℕ :=
n
#align simplex_category.len SimplexCategory.len
@[ext]
theorem ext (a b : SimplexCategory) : a.len = b.len → a = b :=
id
#align simplex_category.ext SimplexCategory.ext
attribute [irreducible] SimplexCategory
open Simplicial
@[simp]
theorem len_mk (n : ℕ) : [n].len = n :=
rfl
#align simplex_category.len_mk SimplexCategory.len_mk
@[simp]
theorem mk_len (n : SimplexCategory) : ([n.len] : SimplexCategory) = n :=
rfl
#align simplex_category.mk_len SimplexCategory.mk_len
/-- A recursor for `SimplexCategory`. Use it as `induction Δ using SimplexCategory.rec`. -/
protected def rec {F : SimplexCategory → Sort*} (h : ∀ n : ℕ, F [n]) : ∀ X, F X := fun n =>
h n.len
#align simplex_category.rec SimplexCategory.rec
-- porting note (#5171): removed @[nolint has_nonempty_instance]
/-- Morphisms in the `SimplexCategory`. -/
protected def Hom (a b : SimplexCategory) :=
Fin (a.len + 1) →o Fin (b.len + 1)
#align simplex_category.hom SimplexCategory.Hom
namespace Hom
/-- Make a morphism in `SimplexCategory` from a monotone map of `Fin`'s. -/
def mk {a b : SimplexCategory} (f : Fin (a.len + 1) →o Fin (b.len + 1)) : SimplexCategory.Hom a b :=
f
#align simplex_category.hom.mk SimplexCategory.Hom.mk
/-- Recover the monotone map from a morphism in the simplex category. -/
def toOrderHom {a b : SimplexCategory} (f : SimplexCategory.Hom a b) :
Fin (a.len + 1) →o Fin (b.len + 1) :=
f
#align simplex_category.hom.to_order_hom SimplexCategory.Hom.toOrderHom
theorem ext' {a b : SimplexCategory} (f g : SimplexCategory.Hom a b) :
f.toOrderHom = g.toOrderHom → f = g :=
id
#align simplex_category.hom.ext SimplexCategory.Hom.ext'
attribute [irreducible] SimplexCategory.Hom
@[simp]
theorem mk_toOrderHom {a b : SimplexCategory} (f : SimplexCategory.Hom a b) : mk f.toOrderHom = f :=
rfl
#align simplex_category.hom.mk_to_order_hom SimplexCategory.Hom.mk_toOrderHom
@[simp]
theorem toOrderHom_mk {a b : SimplexCategory} (f : Fin (a.len + 1) →o Fin (b.len + 1)) :
(mk f).toOrderHom = f :=
rfl
#align simplex_category.hom.to_order_hom_mk SimplexCategory.Hom.toOrderHom_mk
theorem mk_toOrderHom_apply {a b : SimplexCategory} (f : Fin (a.len + 1) →o Fin (b.len + 1))
(i : Fin (a.len + 1)) : (mk f).toOrderHom i = f i :=
rfl
#align simplex_category.hom.mk_to_order_hom_apply SimplexCategory.Hom.mk_toOrderHom_apply
/-- Identity morphisms of `SimplexCategory`. -/
@[simp]
def id (a : SimplexCategory) : SimplexCategory.Hom a a :=
mk OrderHom.id
#align simplex_category.hom.id SimplexCategory.Hom.id
/-- Composition of morphisms of `SimplexCategory`. -/
@[simp]
def comp {a b c : SimplexCategory} (f : SimplexCategory.Hom b c) (g : SimplexCategory.Hom a b) :
SimplexCategory.Hom a c :=
mk <| f.toOrderHom.comp g.toOrderHom
#align simplex_category.hom.comp SimplexCategory.Hom.comp
end Hom
instance smallCategory : SmallCategory.{0} SimplexCategory where
Hom n m := SimplexCategory.Hom n m
id m := SimplexCategory.Hom.id _
comp f g := SimplexCategory.Hom.comp g f
#align simplex_category.small_category SimplexCategory.smallCategory
@[simp]
lemma id_toOrderHom (a : SimplexCategory) :
Hom.toOrderHom (𝟙 a) = OrderHom.id := rfl
@[simp]
lemma comp_toOrderHom {a b c: SimplexCategory} (f : a ⟶ b) (g : b ⟶ c) :
(f ≫ g).toOrderHom = g.toOrderHom.comp f.toOrderHom := rfl
-- Porting note: added because `Hom.ext'` is not triggered automatically
@[ext]
theorem Hom.ext {a b : SimplexCategory} (f g : a ⟶ b) :
f.toOrderHom = g.toOrderHom → f = g :=
Hom.ext' _ _
/-- The constant morphism from [0]. -/
def const (x y : SimplexCategory) (i : Fin (y.len + 1)) : x ⟶ y :=
Hom.mk <| ⟨fun _ => i, by tauto⟩
#align simplex_category.const SimplexCategory.const
@[simp]
lemma const_eq_id : const [0] [0] 0 = 𝟙 _ := by aesop
@[simp]
lemma const_apply (x y : SimplexCategory) (i : Fin (y.len + 1)) (a : Fin (x.len + 1)) :
(const x y i).toOrderHom a = i := rfl
@[simp]
theorem const_comp (x : SimplexCategory) {y z : SimplexCategory}
(f : y ⟶ z) (i : Fin (y.len + 1)) :
const x y i ≫ f = const x z (f.toOrderHom i) :=
rfl
#align simplex_category.const_comp SimplexCategory.const_comp
/-- Make a morphism `[n] ⟶ [m]` from a monotone map between fin's.
This is useful for constructing morphisms between `[n]` directly
without identifying `n` with `[n].len`.
-/
@[simp]
def mkHom {n m : ℕ} (f : Fin (n + 1) →o Fin (m + 1)) : ([n] : SimplexCategory) ⟶ [m] :=
SimplexCategory.Hom.mk f
#align simplex_category.mk_hom SimplexCategory.mkHom
theorem hom_zero_zero (f : ([0] : SimplexCategory) ⟶ [0]) : f = 𝟙 _ := by
ext : 3
apply @Subsingleton.elim (Fin 1)
#align simplex_category.hom_zero_zero SimplexCategory.hom_zero_zero
end
open Simplicial
section Generators
/-!
## Generating maps for the simplex category
TODO: prove that the simplex category is equivalent to
one given by the following generators and relations.
-/
/-- The `i`-th face map from `[n]` to `[n+1]` -/
def δ {n} (i : Fin (n + 2)) : ([n] : SimplexCategory) ⟶ [n + 1] :=
mkHom (Fin.succAboveOrderEmb i).toOrderHom
#align simplex_category.δ SimplexCategory.δ
/-- The `i`-th degeneracy map from `[n+1]` to `[n]` -/
def σ {n} (i : Fin (n + 1)) : ([n + 1] : SimplexCategory) ⟶ [n] :=
mkHom
{ toFun := Fin.predAbove i
monotone' := Fin.predAbove_right_monotone i }
#align simplex_category.σ SimplexCategory.σ
/-- The generic case of the first simplicial identity -/
theorem δ_comp_δ {n} {i j : Fin (n + 2)} (H : i ≤ j) :
δ i ≫ δ j.succ = δ j ≫ δ (Fin.castSucc i) := by
ext k
dsimp [δ, Fin.succAbove]
rcases i with ⟨i, _⟩
rcases j with ⟨j, _⟩
rcases k with ⟨k, _⟩
split_ifs <;> · simp at * <;> omega
#align simplex_category.δ_comp_δ SimplexCategory.δ_comp_δ
theorem δ_comp_δ' {n} {i : Fin (n + 2)} {j : Fin (n + 3)} (H : Fin.castSucc i < j) :
δ i ≫ δ j =
δ (j.pred fun (hj : j = 0) => by simp [hj, Fin.not_lt_zero] at H) ≫
δ (Fin.castSucc i) := by
rw [← δ_comp_δ]
· rw [Fin.succ_pred]
· simpa only [Fin.le_iff_val_le_val, ← Nat.lt_succ_iff, Nat.succ_eq_add_one, ← Fin.val_succ,
j.succ_pred, Fin.lt_iff_val_lt_val] using H
#align simplex_category.δ_comp_δ' SimplexCategory.δ_comp_δ'
theorem δ_comp_δ'' {n} {i : Fin (n + 3)} {j : Fin (n + 2)} (H : i ≤ Fin.castSucc j) :
δ (i.castLT (Nat.lt_of_le_of_lt (Fin.le_iff_val_le_val.mp H) j.is_lt)) ≫ δ j.succ =
δ j ≫ δ i := by
rw [δ_comp_δ]
· rfl
· exact H
#align simplex_category.δ_comp_δ'' SimplexCategory.δ_comp_δ''
/-- The special case of the first simplicial identity -/
@[reassoc]
theorem δ_comp_δ_self {n} {i : Fin (n + 2)} : δ i ≫ δ (Fin.castSucc i) = δ i ≫ δ i.succ :=
(δ_comp_δ (le_refl i)).symm
#align simplex_category.δ_comp_δ_self SimplexCategory.δ_comp_δ_self
@[reassoc]
theorem δ_comp_δ_self' {n} {i : Fin (n + 2)} {j : Fin (n + 3)} (H : j = Fin.castSucc i) :
δ i ≫ δ j = δ i ≫ δ i.succ := by
subst H
rw [δ_comp_δ_self]
#align simplex_category.δ_comp_δ_self' SimplexCategory.δ_comp_δ_self'
/-- The second simplicial identity -/
@[reassoc]
theorem δ_comp_σ_of_le {n} {i : Fin (n + 2)} {j : Fin (n + 1)} (H : i ≤ Fin.castSucc j) :
δ (Fin.castSucc i) ≫ σ j.succ = σ j ≫ δ i := by
ext k : 3
dsimp [σ, δ]
rcases le_or_lt i k with (hik | hik)
· rw [Fin.succAbove_of_le_castSucc _ _ (Fin.castSucc_le_castSucc_iff.mpr hik),
Fin.succ_predAbove_succ, Fin.succAbove_of_le_castSucc]
rcases le_or_lt k (j.castSucc) with (hjk | hjk)
· rwa [Fin.predAbove_of_le_castSucc _ _ hjk, Fin.castSucc_castPred]
· rw [Fin.le_castSucc_iff, Fin.predAbove_of_castSucc_lt _ _ hjk, Fin.succ_pred]
exact H.trans_lt hjk
· rw [Fin.succAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_castSucc_iff.mpr hik)]
have hjk := H.trans_lt' hik
rw [Fin.predAbove_of_le_castSucc _ _ (Fin.castSucc_le_castSucc_iff.mpr
(hjk.trans (Fin.castSucc_lt_succ _)).le),
Fin.predAbove_of_le_castSucc _ _ hjk.le, Fin.castPred_castSucc, Fin.succAbove_of_castSucc_lt,
Fin.castSucc_castPred]
rwa [Fin.castSucc_castPred]
#align simplex_category.δ_comp_σ_of_le SimplexCategory.δ_comp_σ_of_le
/-- The first part of the third simplicial identity -/
@[reassoc]
theorem δ_comp_σ_self {n} {i : Fin (n + 1)} :
δ (Fin.castSucc i) ≫ σ i = 𝟙 ([n] : SimplexCategory) := by
rcases i with ⟨i, hi⟩
ext ⟨j, hj⟩
simp? at hj says simp only [len_mk] at hj
dsimp [σ, δ, Fin.predAbove, Fin.succAbove]
simp only [Fin.lt_iff_val_lt_val, Fin.dite_val, Fin.ite_val, Fin.coe_pred, ge_iff_le,
Fin.coe_castLT, dite_eq_ite]
split_ifs
any_goals simp
all_goals omega
#align simplex_category.δ_comp_σ_self SimplexCategory.δ_comp_σ_self
@[reassoc]
theorem δ_comp_σ_self' {n} {j : Fin (n + 2)} {i : Fin (n + 1)} (H : j = Fin.castSucc i) :
δ j ≫ σ i = 𝟙 ([n] : SimplexCategory) := by
subst H
rw [δ_comp_σ_self]
#align simplex_category.δ_comp_σ_self' SimplexCategory.δ_comp_σ_self'
/-- The second part of the third simplicial identity -/
@[reassoc]
theorem δ_comp_σ_succ {n} {i : Fin (n + 1)} : δ i.succ ≫ σ i = 𝟙 ([n] : SimplexCategory) := by
ext j
rcases i with ⟨i, _⟩
rcases j with ⟨j, _⟩
dsimp [δ, σ, Fin.succAbove, Fin.predAbove]
split_ifs <;> simp <;> simp at * <;> omega
#align simplex_category.δ_comp_σ_succ SimplexCategory.δ_comp_σ_succ
@[reassoc]
theorem δ_comp_σ_succ' {n} (j : Fin (n + 2)) (i : Fin (n + 1)) (H : j = i.succ) :
δ j ≫ σ i = 𝟙 ([n] : SimplexCategory) := by
subst H
rw [δ_comp_σ_succ]
#align simplex_category.δ_comp_σ_succ' SimplexCategory.δ_comp_σ_succ'
/-- The fourth simplicial identity -/
@[reassoc]
theorem δ_comp_σ_of_gt {n} {i : Fin (n + 2)} {j : Fin (n + 1)} (H : Fin.castSucc j < i) :
δ i.succ ≫ σ (Fin.castSucc j) = σ j ≫ δ i := by
ext k : 3
dsimp [δ, σ]
rcases le_or_lt k i with (hik | hik)
· rw [Fin.succAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_succ_iff.mpr hik)]
rcases le_or_lt k (j.castSucc) with (hjk | hjk)
· rw [Fin.predAbove_of_le_castSucc _ _
(Fin.castSucc_le_castSucc_iff.mpr hjk), Fin.castPred_castSucc,
Fin.predAbove_of_le_castSucc _ _ hjk, Fin.succAbove_of_castSucc_lt, Fin.castSucc_castPred]
rw [Fin.castSucc_castPred]
exact hjk.trans_lt H
· rw [Fin.predAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_castSucc_iff.mpr hjk),
Fin.predAbove_of_castSucc_lt _ _ hjk, Fin.succAbove_of_castSucc_lt,
Fin.castSucc_pred_eq_pred_castSucc]
rwa [Fin.castSucc_lt_iff_succ_le, Fin.succ_pred]
· rw [Fin.succAbove_of_le_castSucc _ _ (Fin.succ_le_castSucc_iff.mpr hik)]
have hjk := H.trans hik
rw [Fin.predAbove_of_castSucc_lt _ _ hjk, Fin.predAbove_of_castSucc_lt _ _
(Fin.castSucc_lt_succ_iff.mpr hjk.le),
Fin.pred_succ, Fin.succAbove_of_le_castSucc, Fin.succ_pred]
rwa [Fin.le_castSucc_pred_iff]
#align simplex_category.δ_comp_σ_of_gt SimplexCategory.δ_comp_σ_of_gt
@[reassoc]
theorem δ_comp_σ_of_gt' {n} {i : Fin (n + 3)} {j : Fin (n + 2)} (H : j.succ < i) :
δ i ≫ σ j = σ (j.castLT ((add_lt_add_iff_right 1).mp (lt_of_lt_of_le H i.is_le))) ≫
δ (i.pred fun (hi : i = 0) => by simp only [Fin.not_lt_zero, hi] at H) := by
rw [← δ_comp_σ_of_gt]
· simp
· rw [Fin.castSucc_castLT, ← Fin.succ_lt_succ_iff, Fin.succ_pred]
exact H
#align simplex_category.δ_comp_σ_of_gt' SimplexCategory.δ_comp_σ_of_gt'
/-- The fifth simplicial identity -/
@[reassoc]
theorem σ_comp_σ {n} {i j : Fin (n + 1)} (H : i ≤ j) :
σ (Fin.castSucc i) ≫ σ j = σ j.succ ≫ σ i := by
ext k : 3
dsimp [σ]
cases' k using Fin.lastCases with k
· simp only [len_mk, Fin.predAbove_right_last]
· cases' k using Fin.cases with k
· rw [Fin.castSucc_zero, Fin.predAbove_of_le_castSucc _ 0 (Fin.zero_le _),
Fin.predAbove_of_le_castSucc _ _ (Fin.zero_le _), Fin.castPred_zero,
Fin.predAbove_of_le_castSucc _ 0 (Fin.zero_le _),
Fin.predAbove_of_le_castSucc _ _ (Fin.zero_le _)]
· rcases le_or_lt i k with (h | h)
· simp_rw [Fin.predAbove_of_castSucc_lt i.castSucc _ (Fin.castSucc_lt_castSucc_iff.mpr
(Fin.castSucc_lt_succ_iff.mpr h)), ← Fin.succ_castSucc, Fin.pred_succ,
Fin.succ_predAbove_succ]
rw [Fin.predAbove_of_castSucc_lt i _ (Fin.castSucc_lt_succ_iff.mpr _), Fin.pred_succ]
rcases le_or_lt k j with (hkj | hkj)
· rwa [Fin.predAbove_of_le_castSucc _ _ (Fin.castSucc_le_castSucc_iff.mpr hkj),
Fin.castPred_castSucc]
· rw [Fin.predAbove_of_castSucc_lt _ _ (Fin.castSucc_lt_castSucc_iff.mpr hkj),
Fin.le_pred_iff,
Fin.succ_le_castSucc_iff]
exact H.trans_lt hkj
· simp_rw [Fin.predAbove_of_le_castSucc i.castSucc _ (Fin.castSucc_le_castSucc_iff.mpr
(Fin.succ_le_castSucc_iff.mpr h)), Fin.castPred_castSucc, ← Fin.succ_castSucc,
Fin.succ_predAbove_succ]
rw [Fin.predAbove_of_le_castSucc _ k.castSucc
(Fin.castSucc_le_castSucc_iff.mpr (h.le.trans H)),
Fin.castPred_castSucc, Fin.predAbove_of_le_castSucc _ k.succ
(Fin.succ_le_castSucc_iff.mpr (H.trans_lt' h)), Fin.predAbove_of_le_castSucc _ k.succ
(Fin.succ_le_castSucc_iff.mpr h)]
#align simplex_category.σ_comp_σ SimplexCategory.σ_comp_σ
/--
If `f : [m] ⟶ [n+1]` is a morphism and `j` is not in the range of `f`,
then `factor_δ f j` is a morphism `[m] ⟶ [n]` such that
`factor_δ f j ≫ δ j = f` (as witnessed by `factor_δ_spec`).
-/
def factor_δ {m n : ℕ} (f : ([m] : SimplexCategory) ⟶ [n+1]) (j : Fin (n+2)) :
([m] : SimplexCategory) ⟶ [n] :=
f ≫ σ (Fin.predAbove 0 j)
open Fin in
lemma factor_δ_spec {m n : ℕ} (f : ([m] : SimplexCategory) ⟶ [n+1]) (j : Fin (n+2))
(hj : ∀ (k : Fin (m+1)), f.toOrderHom k ≠ j) :
factor_δ f j ≫ δ j = f := by
ext k : 3
specialize hj k
dsimp [factor_δ, δ, σ]
cases' j using cases with j
· rw [predAbove_of_le_castSucc _ _ (zero_le _), castPred_zero, predAbove_of_castSucc_lt 0 _
(castSucc_zero ▸ pos_of_ne_zero hj),
zero_succAbove, succ_pred]
· rw [predAbove_of_castSucc_lt 0 _ (castSucc_zero ▸ succ_pos _), pred_succ]
rcases hj.lt_or_lt with (hj | hj)
· rw [predAbove_of_le_castSucc j _]
swap
· exact (le_castSucc_iff.mpr hj)
· rw [succAbove_of_castSucc_lt]
swap
· rwa [castSucc_lt_succ_iff, castPred_le_iff, le_castSucc_iff]
rw [castSucc_castPred]
· rw [predAbove_of_castSucc_lt]
swap
· exact (castSucc_lt_succ _).trans hj
rw [succAbove_of_le_castSucc]
swap
· rwa [succ_le_castSucc_iff, lt_pred_iff]
rw [succ_pred]
end Generators
section Skeleton
/-- The functor that exhibits `SimplexCategory` as skeleton
of `NonemptyFinLinOrd` -/
@[simps obj map]
def skeletalFunctor : SimplexCategory ⥤ NonemptyFinLinOrd where
obj a := NonemptyFinLinOrd.of (Fin (a.len + 1))
map f := f.toOrderHom
#align simplex_category.skeletal_functor SimplexCategory.skeletalFunctor
theorem skeletalFunctor.coe_map {Δ₁ Δ₂ : SimplexCategory} (f : Δ₁ ⟶ Δ₂) :
↑(skeletalFunctor.map f) = f.toOrderHom :=
rfl
#align simplex_category.skeletal_functor.coe_map SimplexCategory.skeletalFunctor.coe_map
theorem skeletal : Skeletal SimplexCategory := fun X Y ⟨I⟩ => by
suffices Fintype.card (Fin (X.len + 1)) = Fintype.card (Fin (Y.len + 1)) by
ext
simpa
apply Fintype.card_congr
exact ((skeletalFunctor ⋙ forget NonemptyFinLinOrd).mapIso I).toEquiv
#align simplex_category.skeletal SimplexCategory.skeletal
namespace SkeletalFunctor
instance : skeletalFunctor.Full where
map_surjective f := ⟨SimplexCategory.Hom.mk f, rfl⟩
instance : skeletalFunctor.Faithful where
map_injective {_ _ f g} h := by
ext1
exact h
instance : skeletalFunctor.EssSurj where
mem_essImage X :=
⟨mk (Fintype.card X - 1 : ℕ),
⟨by
have aux : Fintype.card X = Fintype.card X - 1 + 1 :=
(Nat.succ_pred_eq_of_pos <| Fintype.card_pos_iff.mpr ⟨⊥⟩).symm
let f := monoEquivOfFin X aux
have hf := (Finset.univ.orderEmbOfFin aux).strictMono
refine
{ hom := ⟨f, hf.monotone⟩
inv := ⟨f.symm, ?_⟩
hom_inv_id := by ext1; apply f.symm_apply_apply
inv_hom_id := by ext1; apply f.apply_symm_apply }
intro i j h
show f.symm i ≤ f.symm j
rw [← hf.le_iff_le]
show f (f.symm i) ≤ f (f.symm j)
simpa only [OrderIso.apply_symm_apply]⟩⟩
noncomputable instance isEquivalence : skeletalFunctor.IsEquivalence where
#align simplex_category.skeletal_functor.is_equivalence SimplexCategory.SkeletalFunctor.isEquivalence
end SkeletalFunctor
/-- The equivalence that exhibits `SimplexCategory` as skeleton
of `NonemptyFinLinOrd` -/
noncomputable def skeletalEquivalence : SimplexCategory ≌ NonemptyFinLinOrd :=
Functor.asEquivalence skeletalFunctor
#align simplex_category.skeletal_equivalence SimplexCategory.skeletalEquivalence
end Skeleton
/-- `SimplexCategory` is a skeleton of `NonemptyFinLinOrd`.
-/
lemma isSkeletonOf :
IsSkeletonOf NonemptyFinLinOrd SimplexCategory skeletalFunctor where
skel := skeletal
eqv := SkeletalFunctor.isEquivalence
#align simplex_category.is_skeleton_of SimplexCategory.isSkeletonOf
/-- The truncated simplex category. -/
def Truncated (n : ℕ) :=
FullSubcategory fun a : SimplexCategory => a.len ≤ n
#align simplex_category.truncated SimplexCategory.Truncated
instance (n : ℕ) : SmallCategory.{0} (Truncated n) :=
FullSubcategory.category _
namespace Truncated
instance {n} : Inhabited (Truncated n) :=
⟨⟨[0], by simp⟩⟩
/-- The fully faithful inclusion of the truncated simplex category into the usual
simplex category.
-/
def inclusion {n : ℕ} : SimplexCategory.Truncated n ⥤ SimplexCategory :=
fullSubcategoryInclusion _
#align simplex_category.truncated.inclusion SimplexCategory.Truncated.inclusion
instance (n : ℕ) : (inclusion : Truncated n ⥤ _).Full := FullSubcategory.full _
instance (n : ℕ) : (inclusion : Truncated n ⥤ _).Faithful := FullSubcategory.faithful _
end Truncated
section Concrete
instance : ConcreteCategory.{0} SimplexCategory where
forget :=
{ obj := fun i => Fin (i.len + 1)
map := fun f => f.toOrderHom }
forget_faithful := ⟨fun h => by ext : 2; exact h⟩
end Concrete
section EpiMono
/-- A morphism in `SimplexCategory` is a monomorphism precisely when it is an injective function
-/
theorem mono_iff_injective {n m : SimplexCategory} {f : n ⟶ m} :
Mono f ↔ Function.Injective f.toOrderHom := by
rw [← Functor.mono_map_iff_mono skeletalEquivalence.functor]
dsimp only [skeletalEquivalence, Functor.asEquivalence_functor]
simp only [skeletalFunctor_obj, skeletalFunctor_map,
NonemptyFinLinOrd.mono_iff_injective, NonemptyFinLinOrd.coe_of]
#align simplex_category.mono_iff_injective SimplexCategory.mono_iff_injective
/-- A morphism in `SimplexCategory` is an epimorphism if and only if it is a surjective function
-/
theorem epi_iff_surjective {n m : SimplexCategory} {f : n ⟶ m} :
Epi f ↔ Function.Surjective f.toOrderHom := by
rw [← Functor.epi_map_iff_epi skeletalEquivalence.functor]
dsimp only [skeletalEquivalence, Functor.asEquivalence_functor]
simp only [skeletalFunctor_obj, skeletalFunctor_map,
NonemptyFinLinOrd.epi_iff_surjective, NonemptyFinLinOrd.coe_of]
#align simplex_category.epi_iff_surjective SimplexCategory.epi_iff_surjective
/-- A monomorphism in `SimplexCategory` must increase lengths-/
theorem len_le_of_mono {x y : SimplexCategory} {f : x ⟶ y} : Mono f → x.len ≤ y.len := by
intro hyp_f_mono
have f_inj : Function.Injective f.toOrderHom.toFun := mono_iff_injective.1 hyp_f_mono
simpa using Fintype.card_le_of_injective f.toOrderHom.toFun f_inj
#align simplex_category.len_le_of_mono SimplexCategory.len_le_of_mono
theorem le_of_mono {n m : ℕ} {f : ([n] : SimplexCategory) ⟶ [m]} : CategoryTheory.Mono f → n ≤ m :=
len_le_of_mono
#align simplex_category.le_of_mono SimplexCategory.le_of_mono
/-- An epimorphism in `SimplexCategory` must decrease lengths-/
| Mathlib/AlgebraicTopology/SimplexCategory.lean | 583 | 586 | theorem len_le_of_epi {x y : SimplexCategory} {f : x ⟶ y} : Epi f → y.len ≤ x.len := by |
intro hyp_f_epi
have f_surj : Function.Surjective f.toOrderHom.toFun := epi_iff_surjective.1 hyp_f_epi
simpa using Fintype.card_le_of_surjective f.toOrderHom.toFun f_surj
|
/-
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, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import Mathlib.Algebra.Module.Submodule.Ker
#align_import linear_algebra.basic from "leanprover-community/mathlib"@"9d684a893c52e1d6692a504a118bfccbae04feeb"
/-!
# Range of linear maps
The range `LinearMap.range` of a (semi)linear map `f : M → M₂` is a submodule of `M₂`.
More specifically, `LinearMap.range` applies to any `SemilinearMapClass` over a `RingHomSurjective`
ring homomorphism.
Note that this also means that dot notation (i.e. `f.range` for a linear map `f`) does not work.
## Notations
* We continue to use the notations `M →ₛₗ[σ] M₂` and `M →ₗ[R] M₂` for the type of semilinear
(resp. linear) maps from `M` to `M₂` over the ring homomorphism `σ` (resp. over the ring `R`).
## Tags
linear algebra, vector space, module, range
-/
open Function
variable {R : Type*} {R₂ : Type*} {R₃ : Type*}
variable {K : Type*} {K₂ : Type*}
variable {M : Type*} {M₂ : Type*} {M₃ : Type*}
variable {V : Type*} {V₂ : Type*}
namespace LinearMap
section AddCommMonoid
variable [Semiring R] [Semiring R₂] [Semiring R₃]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃}
variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃]
variable [Module R M] [Module R₂ M₂] [Module R₃ M₃]
open Submodule
variable {σ₂₁ : R₂ →+* R} {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃]
section
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂]
/-- The range of a linear map `f : M → M₂` is a submodule of `M₂`.
See Note [range copy pattern]. -/
def range [RingHomSurjective τ₁₂] (f : F) : Submodule R₂ M₂ :=
(map f ⊤).copy (Set.range f) Set.image_univ.symm
#align linear_map.range LinearMap.range
theorem range_coe [RingHomSurjective τ₁₂] (f : F) : (range f : Set M₂) = Set.range f :=
rfl
#align linear_map.range_coe LinearMap.range_coe
theorem range_toAddSubmonoid [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
f.range.toAddSubmonoid = AddMonoidHom.mrange f :=
rfl
#align linear_map.range_to_add_submonoid LinearMap.range_toAddSubmonoid
@[simp]
theorem mem_range [RingHomSurjective τ₁₂] {f : F} {x} : x ∈ range f ↔ ∃ y, f y = x :=
Iff.rfl
#align linear_map.mem_range LinearMap.mem_range
theorem range_eq_map [RingHomSurjective τ₁₂] (f : F) : range f = map f ⊤ := by
ext
simp
#align linear_map.range_eq_map LinearMap.range_eq_map
theorem mem_range_self [RingHomSurjective τ₁₂] (f : F) (x : M) : f x ∈ range f :=
⟨x, rfl⟩
#align linear_map.mem_range_self LinearMap.mem_range_self
@[simp]
theorem range_id : range (LinearMap.id : M →ₗ[R] M) = ⊤ :=
SetLike.coe_injective Set.range_id
#align linear_map.range_id LinearMap.range_id
theorem range_comp [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃]
(f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) = map g (range f) :=
SetLike.coe_injective (Set.range_comp g f)
#align linear_map.range_comp LinearMap.range_comp
theorem range_comp_le_range [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂)
(g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) ≤ range g :=
SetLike.coe_mono (Set.range_comp_subset_range f g)
#align linear_map.range_comp_le_range LinearMap.range_comp_le_range
theorem range_eq_top [RingHomSurjective τ₁₂] {f : F} : range f = ⊤ ↔ Surjective f := by
rw [SetLike.ext'_iff, range_coe, top_coe, Set.range_iff_surjective]
#align linear_map.range_eq_top LinearMap.range_eq_top
theorem range_le_iff_comap [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} :
range f ≤ p ↔ comap f p = ⊤ := by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff]
#align linear_map.range_le_iff_comap LinearMap.range_le_iff_comap
theorem map_le_range [RingHomSurjective τ₁₂] {f : F} {p : Submodule R M} : map f p ≤ range f :=
SetLike.coe_mono (Set.image_subset_range f p)
#align linear_map.map_le_range LinearMap.map_le_range
@[simp]
theorem range_neg {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*} [Semiring R] [Ring R₂]
[AddCommMonoid M] [AddCommGroup M₂] [Module R M] [Module R₂ M₂] {τ₁₂ : R →+* R₂}
[RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : LinearMap.range (-f) = LinearMap.range f := by
change range ((-LinearMap.id : M₂ →ₗ[R₂] M₂).comp f) = _
rw [range_comp, Submodule.map_neg, Submodule.map_id]
#align linear_map.range_neg LinearMap.range_neg
lemma range_domRestrict_le_range [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) (S : Submodule R M) :
LinearMap.range (f.domRestrict S) ≤ LinearMap.range f := by
rintro x ⟨⟨y, hy⟩, rfl⟩
exact LinearMap.mem_range_self f y
@[simp]
theorem _root_.AddMonoidHom.coe_toIntLinearMap_range {M M₂ : Type*} [AddCommGroup M]
[AddCommGroup M₂] (f : M →+ M₂) :
LinearMap.range f.toIntLinearMap = AddSubgroup.toIntSubmodule f.range := rfl
lemma _root_.Submodule.map_comap_eq_of_le [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂}
(h : p ≤ LinearMap.range f) : (p.comap f).map f = p :=
SetLike.coe_injective <| Set.image_preimage_eq_of_subset h
end
/-- The decreasing sequence of submodules consisting of the ranges of the iterates of a linear map.
-/
@[simps]
def iterateRange (f : M →ₗ[R] M) : ℕ →o (Submodule R M)ᵒᵈ where
toFun n := LinearMap.range (f ^ n)
monotone' n m w x h := by
obtain ⟨c, rfl⟩ := le_iff_exists_add.mp w
rw [LinearMap.mem_range] at h
obtain ⟨m, rfl⟩ := h
rw [LinearMap.mem_range]
use (f ^ c) m
rw [pow_add, LinearMap.mul_apply]
#align linear_map.iterate_range LinearMap.iterateRange
/-- Restrict the codomain of a linear map `f` to `f.range`.
This is the bundled version of `Set.rangeFactorization`. -/
abbrev rangeRestrict [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : M →ₛₗ[τ₁₂] LinearMap.range f :=
f.codRestrict (LinearMap.range f) (LinearMap.mem_range_self f)
#align linear_map.range_restrict LinearMap.rangeRestrict
/-- The range of a linear map is finite if the domain is finite.
Note: this instance can form a diamond with `Subtype.fintype` in the
presence of `Fintype M₂`. -/
instance fintypeRange [Fintype M] [DecidableEq M₂] [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
Fintype (range f) :=
Set.fintypeRange f
#align linear_map.fintype_range LinearMap.fintypeRange
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂]
theorem range_codRestrict {τ₂₁ : R₂ →+* R} [RingHomSurjective τ₂₁] (p : Submodule R M)
(f : M₂ →ₛₗ[τ₂₁] M) (hf) :
range (codRestrict p f hf) = comap p.subtype (LinearMap.range f) := by
simpa only [range_eq_map] using map_codRestrict _ _ _ _
#align linear_map.range_cod_restrict LinearMap.range_codRestrict
theorem _root_.Submodule.map_comap_eq [RingHomSurjective τ₁₂] (f : F) (q : Submodule R₂ M₂) :
map f (comap f q) = range f ⊓ q :=
le_antisymm (le_inf map_le_range (map_comap_le _ _)) <| by
rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩
#align submodule.map_comap_eq Submodule.map_comap_eq
theorem _root_.Submodule.map_comap_eq_self [RingHomSurjective τ₁₂] {f : F} {q : Submodule R₂ M₂}
(h : q ≤ range f) : map f (comap f q) = q := by rwa [Submodule.map_comap_eq, inf_eq_right]
#align submodule.map_comap_eq_self Submodule.map_comap_eq_self
@[simp]
theorem range_zero [RingHomSurjective τ₁₂] : range (0 : M →ₛₗ[τ₁₂] M₂) = ⊥ := by
simpa only [range_eq_map] using Submodule.map_zero _
#align linear_map.range_zero LinearMap.range_zero
section
variable [RingHomSurjective τ₁₂]
theorem range_le_bot_iff (f : M →ₛₗ[τ₁₂] M₂) : range f ≤ ⊥ ↔ f = 0 := by
rw [range_le_iff_comap]; exact ker_eq_top
#align linear_map.range_le_bot_iff LinearMap.range_le_bot_iff
theorem range_eq_bot {f : M →ₛₗ[τ₁₂] M₂} : range f = ⊥ ↔ f = 0 := by
rw [← range_le_bot_iff, le_bot_iff]
#align linear_map.range_eq_bot LinearMap.range_eq_bot
theorem range_le_ker_iff {f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₃] M₃} :
range f ≤ ker g ↔ (g.comp f : M →ₛₗ[τ₁₃] M₃) = 0 :=
⟨fun h => ker_eq_top.1 <| eq_top_iff'.2 fun x => h <| ⟨_, rfl⟩, fun h x hx =>
mem_ker.2 <| Exists.elim hx fun y hy => by rw [← hy, ← comp_apply, h, zero_apply]⟩
#align linear_map.range_le_ker_iff LinearMap.range_le_ker_iff
theorem comap_le_comap_iff {f : F} (hf : range f = ⊤) {p p'} : comap f p ≤ comap f p' ↔ p ≤ p' :=
⟨fun H x hx => by rcases range_eq_top.1 hf x with ⟨y, hy, rfl⟩; exact H hx, comap_mono⟩
#align linear_map.comap_le_comap_iff LinearMap.comap_le_comap_iff
theorem comap_injective {f : F} (hf : range f = ⊤) : Injective (comap f) := fun _ _ h =>
le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h)) ((comap_le_comap_iff hf).1 (ge_of_eq h))
#align linear_map.comap_injective LinearMap.comap_injective
end
end AddCommMonoid
section Ring
variable [Ring R] [Ring R₂] [Ring R₃]
variable [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃]
variable [Module R M] [Module R₂ M₂] [Module R₃ M₃]
variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃]
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂]
variable {f : F}
open Submodule
theorem range_toAddSubgroup [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
(range f).toAddSubgroup = f.toAddMonoidHom.range :=
rfl
#align linear_map.range_to_add_subgroup LinearMap.range_toAddSubgroup
theorem ker_le_iff [RingHomSurjective τ₁₂] {p : Submodule R M} :
ker f ≤ p ↔ ∃ y ∈ range f, f ⁻¹' {y} ⊆ p := by
constructor
· intro h
use 0
rw [← SetLike.mem_coe, range_coe]
exact ⟨⟨0, map_zero f⟩, h⟩
· rintro ⟨y, h₁, h₂⟩
rw [SetLike.le_def]
intro z hz
simp only [mem_ker, SetLike.mem_coe] at hz
rw [← SetLike.mem_coe, range_coe, Set.mem_range] at h₁
obtain ⟨x, hx⟩ := h₁
have hx' : x ∈ p := h₂ hx
have hxz : z + x ∈ p := by
apply h₂
simp [hx, hz]
suffices z + x - x ∈ p by simpa only [this, add_sub_cancel_right]
exact p.sub_mem hxz hx'
#align linear_map.ker_le_iff LinearMap.ker_le_iff
end Ring
section Semifield
variable [Semifield K] [Semifield K₂]
variable [AddCommMonoid V] [Module K V]
variable [AddCommMonoid V₂] [Module K V₂]
| Mathlib/Algebra/Module/Submodule/Range.lean | 264 | 265 | theorem range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f := by |
simpa only [range_eq_map] using Submodule.map_smul f _ a h
|
/-
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.Convolution
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
import Mathlib.Analysis.Analytic.IsolatedZeros
import Mathlib.Analysis.Complex.CauchyIntegral
#align_import analysis.special_functions.gamma.beta from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-!
# The Beta function, and further properties of the Gamma function
In this file we define the Beta integral, relate Beta and Gamma functions, and prove some
refined properties of the Gamma function using these relations.
## Results on the Beta function
* `Complex.betaIntegral`: the Beta function `Β(u, v)`, where `u`, `v` are complex with positive
real part.
* `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula
`Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`.
## Results on the Gamma function
* `Complex.Gamma_ne_zero`: for all `s : ℂ` with `s ∉ {-n : n ∈ ℕ}` we have `Γ s ≠ 0`.
* `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n → ∞` of the sequence
`n ↦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Γ(s)`.
* `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula
`Gamma s * Gamma (1 - s) = π / sin π s`.
* `Complex.differentiable_one_div_Gamma`: the function `1 / Γ(s)` is differentiable everywhere.
* `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula
`Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * √π`.
* `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`,
`Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above.
-/
noncomputable section
set_option linter.uppercaseLean3 false
open Filter intervalIntegral Set Real MeasureTheory
open scoped Nat Topology Real
section BetaIntegral
/-! ## The Beta function -/
namespace Complex
/-- The Beta function `Β (u, v)`, defined as `∫ x:ℝ in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/
noncomputable def betaIntegral (u v : ℂ) : ℂ :=
∫ x : ℝ in (0)..1, (x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1)
#align complex.beta_integral Complex.betaIntegral
/-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/
theorem betaIntegral_convergent_left {u : ℂ} (hu : 0 < re u) (v : ℂ) :
IntervalIntegrable (fun x =>
(x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1) : ℝ → ℂ) volume 0 (1 / 2) := by
apply IntervalIntegrable.mul_continuousOn
· refine intervalIntegral.intervalIntegrable_cpow' ?_
rwa [sub_re, one_re, ← zero_sub, sub_lt_sub_iff_right]
· apply ContinuousAt.continuousOn
intro x hx
rw [uIcc_of_le (by positivity : (0 : ℝ) ≤ 1 / 2)] at hx
apply ContinuousAt.cpow
· exact (continuous_const.sub continuous_ofReal).continuousAt
· exact continuousAt_const
· norm_cast
exact ofReal_mem_slitPlane.2 <| by linarith only [hx.2]
#align complex.beta_integral_convergent_left Complex.betaIntegral_convergent_left
/-- The Beta integral is convergent for all `u, v` of positive real part. -/
theorem betaIntegral_convergent {u v : ℂ} (hu : 0 < re u) (hv : 0 < re v) :
IntervalIntegrable (fun x =>
(x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1) : ℝ → ℂ) volume 0 1 := by
refine (betaIntegral_convergent_left hu v).trans ?_
rw [IntervalIntegrable.iff_comp_neg]
convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1
· ext1 x
conv_lhs => rw [mul_comm]
congr 2 <;> · push_cast; ring
· norm_num
· norm_num
#align complex.beta_integral_convergent Complex.betaIntegral_convergent
theorem betaIntegral_symm (u v : ℂ) : betaIntegral v u = betaIntegral u v := by
rw [betaIntegral, betaIntegral]
have := intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1)
(fun x : ℝ => (x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ (v - 1)) neg_one_lt_zero.ne 1
rw [inv_neg, inv_one, neg_one_smul, ← intervalIntegral.integral_symm] at this
simp? at this says
simp only [neg_mul, one_mul, ofReal_add, ofReal_neg, ofReal_one, sub_add_cancel_right, neg_neg,
mul_one, add_left_neg, mul_zero, zero_add] at this
conv_lhs at this => arg 1; intro x; rw [add_comm, ← sub_eq_add_neg, mul_comm]
exact this
#align complex.beta_integral_symm Complex.betaIntegral_symm
theorem betaIntegral_eval_one_right {u : ℂ} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by
simp_rw [betaIntegral, sub_self, cpow_zero, mul_one]
rw [integral_cpow (Or.inl _)]
· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel]
rw [sub_add_cancel]
contrapose! hu; rw [hu, zero_re]
· rwa [sub_re, one_re, ← sub_pos, sub_neg_eq_add, sub_add_cancel]
#align complex.beta_integral_eval_one_right Complex.betaIntegral_eval_one_right
theorem betaIntegral_scaled (s t : ℂ) {a : ℝ} (ha : 0 < a) :
∫ x in (0)..a, (x : ℂ) ^ (s - 1) * ((a : ℂ) - x) ^ (t - 1) =
(a : ℂ) ^ (s + t - 1) * betaIntegral s t := by
have ha' : (a : ℂ) ≠ 0 := ofReal_ne_zero.mpr ha.ne'
rw [betaIntegral]
have A : (a : ℂ) ^ (s + t - 1) = a * ((a : ℂ) ^ (s - 1) * (a : ℂ) ^ (t - 1)) := by
rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one,
mul_assoc]
rw [A, mul_assoc, ← intervalIntegral.integral_const_mul, ← real_smul, ← zero_div a, ←
div_self ha.ne', ← intervalIntegral.integral_comp_div _ ha.ne', zero_div]
simp_rw [intervalIntegral.integral_of_le ha.le]
refine setIntegral_congr measurableSet_Ioc fun x hx => ?_
rw [mul_mul_mul_comm]
congr 1
· rw [← mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancel₀ _ ha']
· rw [(by norm_cast : (1 : ℂ) - ↑(x / a) = ↑(1 - x / a)), ←
mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)]
push_cast
rw [mul_sub, mul_one, mul_div_cancel₀ _ ha']
#align complex.beta_integral_scaled Complex.betaIntegral_scaled
/-- Relation between Beta integral and Gamma function. -/
theorem Gamma_mul_Gamma_eq_betaIntegral {s t : ℂ} (hs : 0 < re s) (ht : 0 < re t) :
Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by
-- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate
-- this as a formula for the Beta function.
have conv_int := integral_posConvolution
(GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul ℝ ℂ)
simp_rw [ContinuousLinearMap.mul_apply'] at conv_int
have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral,
GammaIntegral, GammaIntegral, ← conv_int, ← integral_mul_right (betaIntegral _ _)]
refine setIntegral_congr measurableSet_Ioi fun x hx => ?_
rw [mul_assoc, ← betaIntegral_scaled s t hx, ← intervalIntegral.integral_const_mul]
congr 1 with y : 1
push_cast
suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring
rw [← Complex.exp_add]; congr 1; abel
#align complex.Gamma_mul_Gamma_eq_beta_integral Complex.Gamma_mul_Gamma_eq_betaIntegral
/-- Recurrence formula for the Beta function. -/
theorem betaIntegral_recurrence {u v : ℂ} (hu : 0 < re u) (hv : 0 < re v) :
u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by
-- NB: If we knew `Gamma (u + v + 1) ≠ 0` this would be an easy consequence of
-- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but
-- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument.
let F : ℝ → ℂ := fun x => (x : ℂ) ^ u * (1 - (x : ℂ)) ^ v
have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity
have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity
have hc : ContinuousOn F (Icc 0 1) := by
refine (ContinuousAt.continuousOn fun x hx => ?_).mul (ContinuousAt.continuousOn fun x hx => ?_)
· refine (continuousAt_cpow_const_of_re_pos (Or.inl ?_) hu).comp continuous_ofReal.continuousAt
rw [ofReal_re]; exact hx.1
· refine (continuousAt_cpow_const_of_re_pos (Or.inl ?_) hv).comp
(continuous_const.sub continuous_ofReal).continuousAt
rw [sub_re, one_re, ofReal_re, sub_nonneg]
exact hx.2
have hder : ∀ x : ℝ, x ∈ Ioo (0 : ℝ) 1 →
HasDerivAt F (u * ((x : ℂ) ^ (u - 1) * (1 - (x : ℂ)) ^ v) -
v * ((x : ℂ) ^ u * (1 - (x : ℂ)) ^ (v - 1))) x := by
intro x hx
have U : HasDerivAt (fun y : ℂ => y ^ u) (u * (x : ℂ) ^ (u - 1)) ↑x := by
have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : ℂ)) (Or.inl ?_)
· simp only [id_eq, mul_one] at this
exact this
· rw [id_eq, ofReal_re]; exact hx.1
have V : HasDerivAt (fun y : ℂ => (1 - y) ^ v) (-v * (1 - (x : ℂ)) ^ (v - 1)) ↑x := by
have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : ℂ))) (Or.inl ?_)
swap; · rw [id, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2
simp_rw [id] at A
have B : HasDerivAt (fun y : ℂ => 1 - y) (-1) ↑x := by
apply HasDerivAt.const_sub; apply hasDerivAt_id
convert HasDerivAt.comp (↑x) A B using 1
ring
convert (U.mul V).comp_ofReal using 1
ring
have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub
((betaIntegral_convergent hu' hv).const_mul v)
rw [add_sub_cancel_right, add_sub_cancel_right] at h_int
have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int
have hF0 : F 0 = 0 := by
simp only [F, mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, eq_self_iff_true, Ne,
true_and_iff, sub_zero, one_cpow, one_ne_zero, or_false_iff]
contrapose! hu; rw [hu, zero_re]
have hF1 : F 1 = 0 := by
simp only [F, mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff,
eq_self_iff_true, Ne, true_and_iff, false_or_iff]
contrapose! hv; rw [hv, zero_re]
rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul,
intervalIntegral.integral_const_mul] at int_ev
· rw [betaIntegral, betaIntegral, ← sub_eq_zero]
convert int_ev <;> ring
· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu hv'; ring
· apply IntervalIntegrable.const_mul
convert betaIntegral_convergent hu' hv; ring
#align complex.beta_integral_recurrence Complex.betaIntegral_recurrence
/-- Explicit formula for the Beta function when second argument is a positive integer. -/
theorem betaIntegral_eval_nat_add_one_right {u : ℂ} (hu : 0 < re u) (n : ℕ) :
betaIntegral u (n + 1) = n ! / ∏ j ∈ Finset.range (n + 1), (u + j) := by
induction' n with n IH generalizing u
· rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one]
simp
· have := betaIntegral_recurrence hu (?_ : 0 < re n.succ)
swap; · rw [← ofReal_natCast, ofReal_re]; positivity
rw [mul_comm u _, ← eq_div_iff] at this
swap; · contrapose! hu; rw [hu, zero_re]
rw [this, Finset.prod_range_succ', Nat.cast_succ, IH]
swap; · rw [add_re, one_re]; positivity
rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, ←
mul_div_assoc, ← div_div]
congr 3 with j : 1
push_cast; abel
#align complex.beta_integral_eval_nat_add_one_right Complex.betaIntegral_eval_nat_add_one_right
end Complex
end BetaIntegral
section LimitFormula
/-! ## The Euler limit formula -/
namespace Complex
/-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`.
We will show that this tends to `Γ(s)` as `n → ∞`. -/
noncomputable def GammaSeq (s : ℂ) (n : ℕ) :=
(n : ℂ) ^ s * n ! / ∏ j ∈ Finset.range (n + 1), (s + j)
#align complex.Gamma_seq Complex.GammaSeq
theorem GammaSeq_eq_betaIntegral_of_re_pos {s : ℂ} (hs : 0 < re s) (n : ℕ) :
GammaSeq s n = (n : ℂ) ^ s * betaIntegral s (n + 1) := by
rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, ← mul_div_assoc]
#align complex.Gamma_seq_eq_beta_integral_of_re_pos Complex.GammaSeq_eq_betaIntegral_of_re_pos
theorem GammaSeq_add_one_left (s : ℂ) {n : ℕ} (hn : n ≠ 0) :
GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by
conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div]
conv_rhs =>
rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, ← mul_assoc,
← mul_assoc, mul_comm _ (Finset.prod _ _)]
congr 3
· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm]
· refine Finset.prod_congr (by rfl) fun x _ => ?_
push_cast; ring
· abel
#align complex.Gamma_seq_add_one_left Complex.GammaSeq_add_one_left
theorem GammaSeq_eq_approx_Gamma_integral {s : ℂ} (hs : 0 < re s) {n : ℕ} (hn : n ≠ 0) :
GammaSeq s n = ∫ x : ℝ in (0)..n, ↑((1 - x / n) ^ n) * (x : ℂ) ^ (s - 1) := by
have : ∀ x : ℝ, x = x / n * n := by intro x; rw [div_mul_cancel₀]; exact Nat.cast_ne_zero.mpr hn
conv_rhs => enter [1, x, 2, 1]; rw [this x]
rw [GammaSeq_eq_betaIntegral_of_re_pos hs]
have := intervalIntegral.integral_comp_div (a := 0) (b := n)
(fun x => ↑((1 - x) ^ n) * ↑(x * ↑n) ^ (s - 1) : ℝ → ℂ) (Nat.cast_ne_zero.mpr hn)
dsimp only at this
rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel_right,
← intervalIntegral.integral_const_mul, ← intervalIntegral.integral_const_mul]
swap; · exact Nat.cast_ne_zero.mpr hn
simp_rw [intervalIntegral.integral_of_le zero_le_one]
refine setIntegral_congr measurableSet_Ioc fun x hx => ?_
push_cast
have hn' : (n : ℂ) ≠ 0 := Nat.cast_ne_zero.mpr hn
have A : (n : ℂ) ^ s = (n : ℂ) ^ (s - 1) * n := by
conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn']
simp
have B : ((x : ℂ) * ↑n) ^ (s - 1) = (x : ℂ) ^ (s - 1) * (n : ℂ) ^ (s - 1) := by
rw [← ofReal_natCast,
mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le]
rw [A, B, cpow_natCast]; ring
#align complex.Gamma_seq_eq_approx_Gamma_integral Complex.GammaSeq_eq_approx_Gamma_integral
/-- The main techical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the
Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/
theorem approx_Gamma_integral_tendsto_Gamma_integral {s : ℂ} (hs : 0 < re s) :
Tendsto (fun n : ℕ => ∫ x : ℝ in (0)..n, ((1 - x / n) ^ n : ℝ) * (x : ℂ) ^ (s - 1)) atTop
(𝓝 <| Gamma s) := by
rw [Gamma_eq_integral hs]
-- We apply dominated convergence to the following function, which we will show is uniformly
-- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`.
let f : ℕ → ℝ → ℂ := fun n =>
indicator (Ioc 0 (n : ℝ)) fun x : ℝ => ((1 - x / n) ^ n : ℝ) * (x : ℂ) ^ (s - 1)
-- integrability of f
have f_ible : ∀ n : ℕ, Integrable (f n) (volume.restrict (Ioi 0)) := by
intro n
rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : ℝ) _)), IntegrableOn,
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, ← IntegrableOn, ←
intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : ℝ) ≤ n)]
apply IntervalIntegrable.continuousOn_mul
· refine intervalIntegral.intervalIntegrable_cpow' ?_
rwa [sub_re, one_re, ← zero_sub, sub_lt_sub_iff_right]
· apply Continuous.continuousOn
exact RCLike.continuous_ofReal.comp -- Porting note: was `continuity`
((continuous_const.sub (continuous_id'.div_const ↑n)).pow n)
-- pointwise limit of f
have f_tends : ∀ x : ℝ, x ∈ Ioi (0 : ℝ) →
Tendsto (fun n : ℕ => f n x) atTop (𝓝 <| ↑(Real.exp (-x)) * (x : ℂ) ^ (s - 1)) := by
intro x hx
apply Tendsto.congr'
· show ∀ᶠ n : ℕ in atTop, ↑((1 - x / n) ^ n) * (x : ℂ) ^ (s - 1) = f n x
filter_upwards [eventually_ge_atTop ⌈x⌉₊] with n hn
rw [Nat.ceil_le] at hn
dsimp only [f]
rw [indicator_of_mem]
exact ⟨hx, hn⟩
· simp_rw [mul_comm]
refine (Tendsto.comp (continuous_ofReal.tendsto _) ?_).const_mul _
convert tendsto_one_plus_div_pow_exp (-x) using 1
ext1 n
rw [neg_div, ← sub_eq_add_neg]
-- let `convert` identify the remaining goals
convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1)
(Real.GammaIntegral_convergent hs) _
((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1
-- limit of f is the integrand we want
· ext1 n
rw [integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : ℝ) _)),
intervalIntegral.integral_of_le (by positivity : 0 ≤ (n : ℝ)),
Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self]
-- f is uniformly bounded by the Gamma integrand
· intro n
rw [ae_restrict_iff' measurableSet_Ioi]
filter_upwards with x hx
dsimp only [f]
rcases lt_or_le (n : ℝ) x with (hxn | hxn)
· rw [indicator_of_not_mem (not_mem_Ioc_of_gt hxn), norm_zero,
mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)]
exact rpow_nonneg (le_of_lt hx) _
· rw [indicator_of_mem (mem_Ioc.mpr ⟨mem_Ioi.mp hx, hxn⟩), norm_mul, Complex.norm_eq_abs,
Complex.abs_of_nonneg
(pow_nonneg (sub_nonneg.mpr <| div_le_one_of_le hxn <| by positivity) _),
Complex.norm_eq_abs, abs_cpow_eq_rpow_re_of_pos hx, sub_re, one_re,
mul_le_mul_right (rpow_pos_of_pos hx _)]
exact one_sub_div_pow_le_exp_neg hxn
#align complex.approx_Gamma_integral_tendsto_Gamma_integral Complex.approx_Gamma_integral_tendsto_Gamma_integral
/-- Euler's limit formula for the complex Gamma function. -/
| Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean | 354 | 383 | theorem GammaSeq_tendsto_Gamma (s : ℂ) : Tendsto (GammaSeq s) atTop (𝓝 <| Gamma s) := by |
suffices ∀ m : ℕ, -↑m < re s → Tendsto (GammaSeq s) atTop (𝓝 <| GammaAux m s) by
rw [Gamma]
apply this
rw [neg_lt]
rcases lt_or_le 0 (re s) with (hs | hs)
· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _)
· refine (Nat.lt_floor_add_one _).trans_le ?_
rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one]
intro m
induction' m with m IH generalizing s
· -- Base case: `0 < re s`, so Gamma is given by the integral formula
intro hs
rw [Nat.cast_zero, neg_zero] at hs
rw [← Gamma_eq_GammaAux]
· refine Tendsto.congr' ?_ (approx_Gamma_integral_tendsto_Gamma_integral hs)
refine (eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)
exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm
· rwa [Nat.cast_zero, neg_lt_zero]
· -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq
intro hs
rw [Nat.cast_succ, neg_add, ← sub_eq_add_neg, sub_lt_iff_lt_add, ← one_re, ← add_re] at hs
rw [GammaAux]
have := @Tendsto.congr' _ _ _ ?_ _ _
((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn => ?_)) ((IH _ hs).div_const s)
pick_goal 3; · exact GammaSeq_add_one_left s hn -- doesn't work if inlined?
conv at this => arg 1; intro n; rw [mul_comm]
rwa [← mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' ℂ)] at this
simp_rw [add_assoc]
exact tendsto_natCast_div_add_atTop (1 + s)
|
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Kevin Buzzard, Jujian Zhang
-/
import Mathlib.Algebra.Algebra.Operations
import Mathlib.Algebra.Algebra.Subalgebra.Basic
import Mathlib.Algebra.DirectSum.Algebra
#align_import algebra.direct_sum.internal from "leanprover-community/mathlib"@"9936c3dfc04e5876f4368aeb2e60f8d8358d095a"
/-!
# Internally graded rings and algebras
This module provides `DirectSum.GSemiring` and `DirectSum.GCommSemiring` instances for a collection
of subobjects `A` when a `SetLike.GradedMonoid` instance is available:
* `SetLike.gnonUnitalNonAssocSemiring`
* `SetLike.gsemiring`
* `SetLike.gcommSemiring`
With these instances in place, it provides the bundled canonical maps out of a direct sum of
subobjects into their carrier type:
* `DirectSum.coeRingHom` (a `RingHom` version of `DirectSum.coeAddMonoidHom`)
* `DirectSum.coeAlgHom` (an `AlgHom` version of `DirectSum.coeLinearMap`)
Strictly the definitions in this file are not sufficient to fully define an "internal" direct sum;
to represent this case, `(h : DirectSum.IsInternal A) [SetLike.GradedMonoid A]` is
needed. In the future there will likely be a data-carrying, constructive, typeclass version of
`DirectSum.IsInternal` for providing an explicit decomposition function.
When `CompleteLattice.Independent (Set.range A)` (a weaker condition than
`DirectSum.IsInternal A`), these provide a grading of `⨆ i, A i`, and the
mapping `⨁ i, A i →+ ⨆ i, A i` can be obtained as
`DirectSum.toAddMonoid (fun i ↦ AddSubmonoid.inclusion <| le_iSup A i)`.
## Tags
internally graded ring
-/
open DirectSum
variable {ι : Type*} {σ S R : Type*}
instance AddCommMonoid.ofSubmonoidOnSemiring [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R]
(A : ι → σ) : ∀ i, AddCommMonoid (A i) := fun i => by infer_instance
#align add_comm_monoid.of_submonoid_on_semiring AddCommMonoid.ofSubmonoidOnSemiring
instance AddCommGroup.ofSubgroupOnRing [Ring R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ) :
∀ i, AddCommGroup (A i) := fun i => by infer_instance
#align add_comm_group.of_subgroup_on_ring AddCommGroup.ofSubgroupOnRing
theorem SetLike.algebraMap_mem_graded [Zero ι] [CommSemiring S] [Semiring R] [Algebra S R]
(A : ι → Submodule S R) [SetLike.GradedOne A] (s : S) : algebraMap S R s ∈ A 0 := by
rw [Algebra.algebraMap_eq_smul_one]
exact (A 0).smul_mem s <| SetLike.one_mem_graded _
#align set_like.algebra_map_mem_graded SetLike.algebraMap_mem_graded
theorem SetLike.natCast_mem_graded [Zero ι] [AddMonoidWithOne R] [SetLike σ R]
[AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedOne A] (n : ℕ) : (n : R) ∈ A 0 := by
induction' n with _ n_ih
· rw [Nat.cast_zero]
exact zero_mem (A 0)
· rw [Nat.cast_succ]
exact add_mem n_ih (SetLike.one_mem_graded _)
#align set_like.nat_cast_mem_graded SetLike.natCast_mem_graded
@[deprecated (since := "2024-04-17")]
alias SetLike.nat_cast_mem_graded := SetLike.natCast_mem_graded
theorem SetLike.intCast_mem_graded [Zero ι] [AddGroupWithOne R] [SetLike σ R]
[AddSubgroupClass σ R] (A : ι → σ) [SetLike.GradedOne A] (z : ℤ) : (z : R) ∈ A 0 := by
induction z
· rw [Int.ofNat_eq_coe, Int.cast_natCast]
exact SetLike.natCast_mem_graded _ _
· rw [Int.cast_negSucc]
exact neg_mem (SetLike.natCast_mem_graded _ _)
#align set_like.int_cast_mem_graded SetLike.intCast_mem_graded
@[deprecated (since := "2024-04-17")]
alias SetLike.int_cast_mem_graded := SetLike.intCast_mem_graded
section DirectSum
variable [DecidableEq ι]
/-! #### From `AddSubmonoid`s and `AddSubgroup`s -/
namespace SetLike
/-- Build a `DirectSum.GNonUnitalNonAssocSemiring` instance for a collection of additive
submonoids. -/
instance gnonUnitalNonAssocSemiring [Add ι] [NonUnitalNonAssocSemiring R] [SetLike σ R]
[AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedMul A] :
DirectSum.GNonUnitalNonAssocSemiring fun i => A i :=
{ SetLike.gMul A with
mul_zero := fun _ => Subtype.ext (mul_zero _)
zero_mul := fun _ => Subtype.ext (zero_mul _)
mul_add := fun _ _ _ => Subtype.ext (mul_add _ _ _)
add_mul := fun _ _ _ => Subtype.ext (add_mul _ _ _) }
#align set_like.gnon_unital_non_assoc_semiring SetLike.gnonUnitalNonAssocSemiring
/-- Build a `DirectSum.GSemiring` instance for a collection of additive submonoids. -/
instance gsemiring [AddMonoid ι] [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ)
[SetLike.GradedMonoid A] : DirectSum.GSemiring fun i => A i :=
{ SetLike.gMonoid A with
mul_zero := fun _ => Subtype.ext (mul_zero _)
zero_mul := fun _ => Subtype.ext (zero_mul _)
mul_add := fun _ _ _ => Subtype.ext (mul_add _ _ _)
add_mul := fun _ _ _ => Subtype.ext (add_mul _ _ _)
natCast := fun n => ⟨n, SetLike.natCast_mem_graded _ _⟩
natCast_zero := Subtype.ext Nat.cast_zero
natCast_succ := fun n => Subtype.ext (Nat.cast_succ n) }
#align set_like.gsemiring SetLike.gsemiring
/-- Build a `DirectSum.GCommSemiring` instance for a collection of additive submonoids. -/
instance gcommSemiring [AddCommMonoid ι] [CommSemiring R] [SetLike σ R] [AddSubmonoidClass σ R]
(A : ι → σ) [SetLike.GradedMonoid A] : DirectSum.GCommSemiring fun i => A i :=
{ SetLike.gCommMonoid A, SetLike.gsemiring A with }
#align set_like.gcomm_semiring SetLike.gcommSemiring
/-- Build a `DirectSum.GRing` instance for a collection of additive subgroups. -/
instance gring [AddMonoid ι] [Ring R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ)
[SetLike.GradedMonoid A] : DirectSum.GRing fun i => A i :=
{ SetLike.gsemiring A with
intCast := fun z => ⟨z, SetLike.intCast_mem_graded _ _⟩
intCast_ofNat := fun _n => Subtype.ext <| Int.cast_natCast _
intCast_negSucc_ofNat := fun n => Subtype.ext <| Int.cast_negSucc n }
#align set_like.gring SetLike.gring
/-- Build a `DirectSum.GCommRing` instance for a collection of additive submonoids. -/
instance gcommRing [AddCommMonoid ι] [CommRing R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ)
[SetLike.GradedMonoid A] : DirectSum.GCommRing fun i => A i :=
{ SetLike.gCommMonoid A, SetLike.gring A with }
#align set_like.gcomm_ring SetLike.gcommRing
end SetLike
namespace DirectSum
section coe
variable [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ)
/-- The canonical ring isomorphism between `⨁ i, A i` and `R`-/
def coeRingHom [AddMonoid ι] [SetLike.GradedMonoid A] : (⨁ i, A i) →+* R :=
DirectSum.toSemiring (fun i => AddSubmonoidClass.subtype (A i)) rfl fun _ _ => rfl
#align direct_sum.coe_ring_hom DirectSum.coeRingHom
/-- The canonical ring isomorphism between `⨁ i, A i` and `R`-/
@[simp]
theorem coeRingHom_of [AddMonoid ι] [SetLike.GradedMonoid A] (i : ι) (x : A i) :
(coeRingHom A : _ →+* R) (of (fun i => A i) i x) = x :=
DirectSum.toSemiring_of _ _ _ _ _
#align direct_sum.coe_ring_hom_of DirectSum.coeRingHom_of
theorem coe_mul_apply [AddMonoid ι] [SetLike.GradedMonoid A]
[∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (r r' : ⨁ i, A i) (n : ι) :
((r * r') n : R) =
∑ ij ∈ (r.support ×ˢ r'.support).filter (fun ij : ι × ι => ij.1 + ij.2 = n),
(r ij.1 * r' ij.2 : R) := by
rw [mul_eq_sum_support_ghas_mul, DFinsupp.finset_sum_apply, AddSubmonoidClass.coe_finset_sum]
simp_rw [coe_of_apply, apply_ite, ZeroMemClass.coe_zero, ← Finset.sum_filter, SetLike.coe_gMul]
#align direct_sum.coe_mul_apply DirectSum.coe_mul_apply
theorem coe_mul_apply_eq_dfinsupp_sum [AddMonoid ι] [SetLike.GradedMonoid A]
[∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (r r' : ⨁ i, A i) (n : ι) :
((r * r') n : R) = r.sum fun i ri => r'.sum fun j rj => if i + j = n then (ri * rj : R)
else 0 := by
rw [mul_eq_dfinsupp_sum]
iterate 2 rw [DFinsupp.sum_apply, DFinsupp.sum, AddSubmonoidClass.coe_finset_sum]; congr; ext
dsimp only
split_ifs with h
· subst h
rw [of_eq_same]
rfl
· rw [of_eq_of_ne _ _ _ _ h]
rfl
#align direct_sum.coe_mul_apply_eq_dfinsupp_sum DirectSum.coe_mul_apply_eq_dfinsupp_sum
theorem coe_of_mul_apply_aux [AddMonoid ι] [SetLike.GradedMonoid A] {i : ι} (r : A i)
(r' : ⨁ i, A i) {j n : ι} (H : ∀ x : ι, i + x = n ↔ x = j) :
((of (fun i => A i) i r * r') n : R) = r * r' j := by
classical
rw [coe_mul_apply_eq_dfinsupp_sum]
apply (DFinsupp.sum_single_index _).trans
swap
· simp_rw [ZeroMemClass.coe_zero, zero_mul, ite_self]
exact DFinsupp.sum_zero
simp_rw [DFinsupp.sum, H, Finset.sum_ite_eq']
split_ifs with h
· rfl
rw [DFinsupp.not_mem_support_iff.mp h, ZeroMemClass.coe_zero, mul_zero]
#align direct_sum.coe_of_mul_apply_aux DirectSum.coe_of_mul_apply_aux
theorem coe_mul_of_apply_aux [AddMonoid ι] [SetLike.GradedMonoid A] (r : ⨁ i, A i) {i : ι}
(r' : A i) {j n : ι} (H : ∀ x : ι, x + i = n ↔ x = j) :
((r * of (fun i => A i) i r') n : R) = r j * r' := by
classical
rw [coe_mul_apply_eq_dfinsupp_sum, DFinsupp.sum_comm]
apply (DFinsupp.sum_single_index _).trans
swap
· simp_rw [ZeroMemClass.coe_zero, mul_zero, ite_self]
exact DFinsupp.sum_zero
simp_rw [DFinsupp.sum, H, Finset.sum_ite_eq']
split_ifs with h
· rfl
rw [DFinsupp.not_mem_support_iff.mp h, ZeroMemClass.coe_zero, zero_mul]
#align direct_sum.coe_mul_of_apply_aux DirectSum.coe_mul_of_apply_aux
theorem coe_of_mul_apply_add [AddLeftCancelMonoid ι] [SetLike.GradedMonoid A] {i : ι} (r : A i)
(r' : ⨁ i, A i) (j : ι) : ((of (fun i => A i) i r * r') (i + j) : R) = r * r' j :=
coe_of_mul_apply_aux _ _ _ fun _x => ⟨fun h => add_left_cancel h, fun h => h ▸ rfl⟩
#align direct_sum.coe_of_mul_apply_add DirectSum.coe_of_mul_apply_add
theorem coe_mul_of_apply_add [AddRightCancelMonoid ι] [SetLike.GradedMonoid A] (r : ⨁ i, A i)
{i : ι} (r' : A i) (j : ι) : ((r * of (fun i => A i) i r') (j + i) : R) = r j * r' :=
coe_mul_of_apply_aux _ _ _ fun _x => ⟨fun h => add_right_cancel h, fun h => h ▸ rfl⟩
#align direct_sum.coe_mul_of_apply_add DirectSum.coe_mul_of_apply_add
end coe
section CanonicallyOrderedAddCommMonoid
variable [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ)
variable [CanonicallyOrderedAddCommMonoid ι] [SetLike.GradedMonoid A]
| Mathlib/Algebra/DirectSum/Internal.lean | 232 | 241 | theorem coe_of_mul_apply_of_not_le {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι) (h : ¬i ≤ n) :
((of (fun i => A i) i r * r') n : R) = 0 := by |
classical
rw [coe_mul_apply_eq_dfinsupp_sum]
apply (DFinsupp.sum_single_index _).trans
swap
· simp_rw [ZeroMemClass.coe_zero, zero_mul, ite_self]
exact DFinsupp.sum_zero
· rw [DFinsupp.sum, Finset.sum_ite_of_false _ _ fun x _ H => _, Finset.sum_const_zero]
exact fun x _ H => h ((self_le_add_right i x).trans_eq H)
|
/-
Copyright (c) 2017 Johannes Hölzl. 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.Ordinal.Basic
import Mathlib.Data.Nat.SuccPred
#align_import set_theory.ordinal.arithmetic from "leanprover-community/mathlib"@"31b269b60935483943542d547a6dd83a66b37dc7"
/-!
# Ordinal arithmetic
Ordinals have an addition (corresponding to disjoint union) that turns them into an additive
monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns
them into a monoid. One can also define correspondingly a subtraction, a division, a successor
function, a power function and a logarithm function.
We also define limit ordinals and prove the basic induction principle on ordinals separating
successor ordinals and limit ordinals, in `limitRecOn`.
## Main definitions and results
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.
* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.
* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the
divisibility predicate, and a modulo operation.
* `Order.succ o = o + 1` is the successor of `o`.
* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.
We discuss the properties of casts of natural numbers of and of `ω` with respect to these
operations.
Some properties of the operations are also used to discuss general tools on ordinals:
* `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.
* `limitRecOn` is the main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals.
* `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing
and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`.
* `enumOrd`: enumerates an unbounded set of ordinals by the ordinals themselves.
* `sup`, `lsub`: the supremum / least strict upper bound of an indexed family of ordinals in
`Type u`, as an ordinal in `Type u`.
* `bsup`, `blsub`: the supremum / least strict upper bound of a set of ordinals indexed by ordinals
less than a given ordinal `o`.
Various other basic arithmetic results are given in `Principal.lean` instead.
-/
assert_not_exists Field
assert_not_exists Module
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Classical
open Cardinal Ordinal
universe u v w
namespace Ordinal
variable {α : Type*} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop}
/-! ### Further properties of addition on ordinals -/
@[simp]
theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩
#align ordinal.lift_add Ordinal.lift_add
@[simp]
theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by
rw [← add_one_eq_succ, lift_add, lift_one]
rfl
#align ordinal.lift_succ Ordinal.lift_succ
instance add_contravariantClass_le : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) :=
⟨fun a b c =>
inductionOn a fun α r hr =>
inductionOn b fun β₁ s₁ hs₁ =>
inductionOn c fun β₂ s₂ hs₂ ⟨f⟩ =>
⟨have fl : ∀ a, f (Sum.inl a) = Sum.inl a := fun a => by
simpa only [InitialSeg.trans_apply, InitialSeg.leAdd_apply] using
@InitialSeg.eq _ _ _ _ _
((InitialSeg.leAdd r s₁).trans f) (InitialSeg.leAdd r s₂) a
have : ∀ b, { b' // f (Sum.inr b) = Sum.inr b' } := by
intro b; cases e : f (Sum.inr b)
· rw [← fl] at e
have := f.inj' e
contradiction
· exact ⟨_, rfl⟩
let g (b) := (this b).1
have fr : ∀ b, f (Sum.inr b) = Sum.inr (g b) := fun b => (this b).2
⟨⟨⟨g, fun x y h => by
injection f.inj' (by rw [fr, fr, h] : f (Sum.inr x) = f (Sum.inr y))⟩,
@fun a b => by
-- Porting note:
-- `relEmbedding.coe_fn_to_embedding` & `initial_seg.coe_fn_to_rel_embedding`
-- → `InitialSeg.coe_coe_fn`
simpa only [Sum.lex_inr_inr, fr, InitialSeg.coe_coe_fn, Embedding.coeFn_mk] using
@RelEmbedding.map_rel_iff _ _ _ _ f.toRelEmbedding (Sum.inr a) (Sum.inr b)⟩,
fun a b H => by
rcases f.init (by rw [fr] <;> exact Sum.lex_inr_inr.2 H) with ⟨a' | a', h⟩
· rw [fl] at h
cases h
· rw [fr] at h
exact ⟨a', Sum.inr.inj h⟩⟩⟩⟩
#align ordinal.add_contravariant_class_le Ordinal.add_contravariantClass_le
theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c := by
simp only [le_antisymm_iff, add_le_add_iff_left]
#align ordinal.add_left_cancel Ordinal.add_left_cancel
private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by
rw [← not_le, ← not_le, add_le_add_iff_left]
instance add_covariantClass_lt : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) :=
⟨fun a _b _c => (add_lt_add_iff_left' a).2⟩
#align ordinal.add_covariant_class_lt Ordinal.add_covariantClass_lt
instance add_contravariantClass_lt : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) :=
⟨fun a _b _c => (add_lt_add_iff_left' a).1⟩
#align ordinal.add_contravariant_class_lt Ordinal.add_contravariantClass_lt
instance add_swap_contravariantClass_lt :
ContravariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· < ·) :=
⟨fun _a _b _c => lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩
#align ordinal.add_swap_contravariant_class_lt Ordinal.add_swap_contravariantClass_lt
theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b
| 0 => by simp
| n + 1 => by
simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right]
#align ordinal.add_le_add_iff_right Ordinal.add_le_add_iff_right
theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by
simp only [le_antisymm_iff, add_le_add_iff_right]
#align ordinal.add_right_cancel Ordinal.add_right_cancel
theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 :=
inductionOn a fun α r _ =>
inductionOn b fun β s _ => by
simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty]
exact isEmpty_sum
#align ordinal.add_eq_zero_iff Ordinal.add_eq_zero_iff
theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 :=
(add_eq_zero_iff.1 h).1
#align ordinal.left_eq_zero_of_add_eq_zero Ordinal.left_eq_zero_of_add_eq_zero
theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 :=
(add_eq_zero_iff.1 h).2
#align ordinal.right_eq_zero_of_add_eq_zero Ordinal.right_eq_zero_of_add_eq_zero
/-! ### The predecessor of an ordinal -/
/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,
and `o` otherwise. -/
def pred (o : Ordinal) : Ordinal :=
if h : ∃ a, o = succ a then Classical.choose h else o
#align ordinal.pred Ordinal.pred
@[simp]
theorem pred_succ (o) : pred (succ o) = o := by
have h : ∃ a, succ o = succ a := ⟨_, rfl⟩;
simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm
#align ordinal.pred_succ Ordinal.pred_succ
theorem pred_le_self (o) : pred o ≤ o :=
if h : ∃ a, o = succ a then by
let ⟨a, e⟩ := h
rw [e, pred_succ]; exact le_succ a
else by rw [pred, dif_neg h]
#align ordinal.pred_le_self Ordinal.pred_le_self
theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a :=
⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩
#align ordinal.pred_eq_iff_not_succ Ordinal.pred_eq_iff_not_succ
theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by
simpa using pred_eq_iff_not_succ
#align ordinal.pred_eq_iff_not_succ' Ordinal.pred_eq_iff_not_succ'
theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a :=
Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and_iff, not_le])
(iff_not_comm.1 pred_eq_iff_not_succ).symm
#align ordinal.pred_lt_iff_is_succ Ordinal.pred_lt_iff_is_succ
@[simp]
theorem pred_zero : pred 0 = 0 :=
pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm
#align ordinal.pred_zero Ordinal.pred_zero
theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a :=
⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩
#align ordinal.succ_pred_iff_is_succ Ordinal.succ_pred_iff_is_succ
theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o :=
⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩
#align ordinal.succ_lt_of_not_succ Ordinal.succ_lt_of_not_succ
theorem lt_pred {a b} : a < pred b ↔ succ a < b :=
if h : ∃ a, b = succ a then by
let ⟨c, e⟩ := h
rw [e, pred_succ, succ_lt_succ_iff]
else by simp only [pred, dif_neg h, succ_lt_of_not_succ h]
#align ordinal.lt_pred Ordinal.lt_pred
theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=
le_iff_le_iff_lt_iff_lt.2 lt_pred
#align ordinal.pred_le Ordinal.pred_le
@[simp]
theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a :=
⟨fun ⟨a, h⟩ =>
let ⟨b, e⟩ := lift_down <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a
⟨b, lift_inj.1 <| by rw [h, ← e, lift_succ]⟩,
fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩
#align ordinal.lift_is_succ Ordinal.lift_is_succ
@[simp]
theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) :=
if h : ∃ a, o = succ a then by cases' h with a e; simp only [e, pred_succ, lift_succ]
else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)]
#align ordinal.lift_pred Ordinal.lift_pred
/-! ### Limit ordinals -/
/-- A limit ordinal is an ordinal which is not zero and not a successor. -/
def IsLimit (o : Ordinal) : Prop :=
o ≠ 0 ∧ ∀ a < o, succ a < o
#align ordinal.is_limit Ordinal.IsLimit
theorem IsLimit.isSuccLimit {o} (h : IsLimit o) : IsSuccLimit o := isSuccLimit_iff_succ_lt.mpr h.2
theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o :=
h.2 a
#align ordinal.is_limit.succ_lt Ordinal.IsLimit.succ_lt
theorem isSuccLimit_zero : IsSuccLimit (0 : Ordinal) := isSuccLimit_bot
theorem not_zero_isLimit : ¬IsLimit 0
| ⟨h, _⟩ => h rfl
#align ordinal.not_zero_is_limit Ordinal.not_zero_isLimit
theorem not_succ_isLimit (o) : ¬IsLimit (succ o)
| ⟨_, h⟩ => lt_irrefl _ (h _ (lt_succ o))
#align ordinal.not_succ_is_limit Ordinal.not_succ_isLimit
theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a
| ⟨a, e⟩ => not_succ_isLimit a (e ▸ h)
#align ordinal.not_succ_of_is_limit Ordinal.not_succ_of_isLimit
theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o :=
⟨(lt_succ a).trans, h.2 _⟩
#align ordinal.succ_lt_of_is_limit Ordinal.succ_lt_of_isLimit
theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a :=
le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h
#align ordinal.le_succ_of_is_limit Ordinal.le_succ_of_isLimit
theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a :=
⟨fun h _x l => l.le.trans h, fun H =>
(le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩
#align ordinal.limit_le Ordinal.limit_le
theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a)
#align ordinal.lt_limit Ordinal.lt_limit
@[simp]
theorem lift_isLimit (o) : IsLimit (lift o) ↔ IsLimit o :=
and_congr (not_congr <| by simpa only [lift_zero] using @lift_inj o 0)
⟨fun H a h => lift_lt.1 <| by simpa only [lift_succ] using H _ (lift_lt.2 h), fun H a h => by
obtain ⟨a', rfl⟩ := lift_down h.le
rw [← lift_succ, lift_lt]
exact H a' (lift_lt.1 h)⟩
#align ordinal.lift_is_limit Ordinal.lift_isLimit
theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o :=
lt_of_le_of_ne (Ordinal.zero_le _) h.1.symm
#align ordinal.is_limit.pos Ordinal.IsLimit.pos
theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by
simpa only [succ_zero] using h.2 _ h.pos
#align ordinal.is_limit.one_lt Ordinal.IsLimit.one_lt
theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o
| 0 => h.pos
| n + 1 => h.2 _ (IsLimit.nat_lt h n)
#align ordinal.is_limit.nat_lt Ordinal.IsLimit.nat_lt
theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o :=
if o0 : o = 0 then Or.inl o0
else
if h : ∃ a, o = succ a then Or.inr (Or.inl h)
else Or.inr <| Or.inr ⟨o0, fun _a => (succ_lt_of_not_succ h).2⟩
#align ordinal.zero_or_succ_or_limit Ordinal.zero_or_succ_or_limit
/-- Main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/
@[elab_as_elim]
def limitRecOn {C : Ordinal → Sort*} (o : Ordinal) (H₁ : C 0) (H₂ : ∀ o, C o → C (succ o))
(H₃ : ∀ o, IsLimit o → (∀ o' < o, C o') → C o) : C o :=
SuccOrder.limitRecOn o (fun o _ ↦ H₂ o) fun o hl ↦
if h : o = 0 then fun _ ↦ h ▸ H₁ else H₃ o ⟨h, fun _ ↦ hl.succ_lt⟩
#align ordinal.limit_rec_on Ordinal.limitRecOn
@[simp]
theorem limitRecOn_zero {C} (H₁ H₂ H₃) : @limitRecOn C 0 H₁ H₂ H₃ = H₁ := by
rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ isSuccLimit_zero, dif_pos rfl]
#align ordinal.limit_rec_on_zero Ordinal.limitRecOn_zero
@[simp]
theorem limitRecOn_succ {C} (o H₁ H₂ H₃) :
@limitRecOn C (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn C o H₁ H₂ H₃) := by
simp_rw [limitRecOn, SuccOrder.limitRecOn_succ _ _ (not_isMax _)]
#align ordinal.limit_rec_on_succ Ordinal.limitRecOn_succ
@[simp]
theorem limitRecOn_limit {C} (o H₁ H₂ H₃ h) :
@limitRecOn C o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn C x H₁ H₂ H₃ := by
simp_rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ h.isSuccLimit, dif_neg h.1]
#align ordinal.limit_rec_on_limit Ordinal.limitRecOn_limit
instance orderTopOutSucc (o : Ordinal) : OrderTop (succ o).out.α :=
@OrderTop.mk _ _ (Top.mk _) le_enum_succ
#align ordinal.order_top_out_succ Ordinal.orderTopOutSucc
theorem enum_succ_eq_top {o : Ordinal} :
enum (· < ·) o
(by
rw [type_lt]
exact lt_succ o) =
(⊤ : (succ o).out.α) :=
rfl
#align ordinal.enum_succ_eq_top Ordinal.enum_succ_eq_top
theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r]
(h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by
use enum r (succ (typein r x)) (h _ (typein_lt_type r x))
convert (enum_lt_enum (typein_lt_type r x)
(h _ (typein_lt_type r x))).mpr (lt_succ _); rw [enum_typein]
#align ordinal.has_succ_of_type_succ_lt Ordinal.has_succ_of_type_succ_lt
theorem out_no_max_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.out.α :=
⟨has_succ_of_type_succ_lt (by rwa [type_lt])⟩
#align ordinal.out_no_max_of_succ_lt Ordinal.out_no_max_of_succ_lt
theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) :
Bounded r {x} := by
refine ⟨enum r (succ (typein r x)) (hr.2 _ (typein_lt_type r x)), ?_⟩
intro b hb
rw [mem_singleton_iff.1 hb]
nth_rw 1 [← enum_typein r x]
rw [@enum_lt_enum _ r]
apply lt_succ
#align ordinal.bounded_singleton Ordinal.bounded_singleton
-- Porting note: `· < ·` requires a type ascription for an `IsWellOrder` instance.
theorem type_subrel_lt (o : Ordinal.{u}) :
type (Subrel ((· < ·) : Ordinal → Ordinal → Prop) { o' : Ordinal | o' < o })
= Ordinal.lift.{u + 1} o := by
refine Quotient.inductionOn o ?_
rintro ⟨α, r, wo⟩; apply Quotient.sound
-- Porting note: `symm; refine' [term]` → `refine' [term].symm`
constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enumIso r).symm).symm
#align ordinal.type_subrel_lt Ordinal.type_subrel_lt
theorem mk_initialSeg (o : Ordinal.{u}) :
#{ o' : Ordinal | o' < o } = Cardinal.lift.{u + 1} o.card := by
rw [lift_card, ← type_subrel_lt, card_type]
#align ordinal.mk_initial_seg Ordinal.mk_initialSeg
/-! ### Normal ordinal functions -/
/-- A normal ordinal function is a strictly increasing function which is
order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`. -/
def IsNormal (f : Ordinal → Ordinal) : Prop :=
(∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a
#align ordinal.is_normal Ordinal.IsNormal
theorem IsNormal.limit_le {f} (H : IsNormal f) :
∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a :=
@H.2
#align ordinal.is_normal.limit_le Ordinal.IsNormal.limit_le
theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} :
a < f o ↔ ∃ b < o, a < f b :=
not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a
#align ordinal.is_normal.limit_lt Ordinal.IsNormal.limit_lt
theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b =>
limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _))
(fun _b IH h =>
(lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _)
fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.2 _ h))
#align ordinal.is_normal.strict_mono Ordinal.IsNormal.strictMono
theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f :=
H.strictMono.monotone
#align ordinal.is_normal.monotone Ordinal.IsNormal.monotone
theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) :
IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a :=
⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ =>
⟨fun a => hs (lt_succ a), fun a ha c =>
⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩
#align ordinal.is_normal_iff_strict_mono_limit Ordinal.isNormal_iff_strictMono_limit
theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b :=
StrictMono.lt_iff_lt <| H.strictMono
#align ordinal.is_normal.lt_iff Ordinal.IsNormal.lt_iff
theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.lt_iff
#align ordinal.is_normal.le_iff Ordinal.IsNormal.le_iff
theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by
simp only [le_antisymm_iff, H.le_iff]
#align ordinal.is_normal.inj Ordinal.IsNormal.inj
theorem IsNormal.self_le {f} (H : IsNormal f) (a) : a ≤ f a :=
lt_wf.self_le_of_strictMono H.strictMono a
#align ordinal.is_normal.self_le Ordinal.IsNormal.self_le
theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o :=
⟨fun h a pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by
-- Porting note: `refine'` didn't work well so `induction` is used
induction b using limitRecOn with
| H₁ =>
cases' p0 with x px
have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px)
rw [this] at px
exact h _ px
| H₂ S _ =>
rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩
exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁)
| H₃ S L _ =>
refine (H.2 _ L _).2 fun a h' => ?_
rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩
exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩
#align ordinal.is_normal.le_set Ordinal.IsNormal.le_set
theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by
simpa [H₂] using H.le_set (g '' p) (p0.image g) b
#align ordinal.is_normal.le_set' Ordinal.IsNormal.le_set'
theorem IsNormal.refl : IsNormal id :=
⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩
#align ordinal.is_normal.refl Ordinal.IsNormal.refl
theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) :=
⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a =>
H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩
#align ordinal.is_normal.trans Ordinal.IsNormal.trans
theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (l : IsLimit o) : IsLimit (f o) :=
⟨ne_of_gt <| (Ordinal.zero_le _).trans_lt <| H.lt_iff.2 l.pos, fun _ h =>
let ⟨_b, h₁, h₂⟩ := (H.limit_lt l).1 h
(succ_le_of_lt h₂).trans_lt (H.lt_iff.2 h₁)⟩
#align ordinal.is_normal.is_limit Ordinal.IsNormal.isLimit
theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a :=
(H.self_le a).le_iff_eq
#align ordinal.is_normal.le_iff_eq Ordinal.IsNormal.le_iff_eq
theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c :=
⟨fun h b' l => (add_le_add_left l.le _).trans h, fun H =>
le_of_not_lt <| by
-- Porting note: `induction` tactics are required because of the parser bug.
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
intro l
suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ _ l) by
-- Porting note: `revert` & `intro` is required because `cases'` doesn't replace
-- `enum _ _ l` in `this`.
revert this; cases' enum _ _ l with x x <;> intro this
· cases this (enum s 0 h.pos)
· exact irrefl _ (this _)
intro x
rw [← typein_lt_typein (Sum.Lex r s), typein_enum]
have := H _ (h.2 _ (typein_lt_type s x))
rw [add_succ, succ_le_iff] at this
refine
(RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨a | b, h⟩
· exact Sum.inl a
· exact Sum.inr ⟨b, by cases h; assumption⟩
· rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;>
rintro ⟨⟩ <;> constructor <;> assumption⟩
#align ordinal.add_le_of_limit Ordinal.add_le_of_limit
theorem add_isNormal (a : Ordinal) : IsNormal (a + ·) :=
⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩
#align ordinal.add_is_normal Ordinal.add_isNormal
theorem add_isLimit (a) {b} : IsLimit b → IsLimit (a + b) :=
(add_isNormal a).isLimit
#align ordinal.add_is_limit Ordinal.add_isLimit
alias IsLimit.add := add_isLimit
#align ordinal.is_limit.add Ordinal.IsLimit.add
/-! ### Subtraction on ordinals-/
/-- The set in the definition of subtraction is nonempty. -/
theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty :=
⟨a, le_add_left _ _⟩
#align ordinal.sub_nonempty Ordinal.sub_nonempty
/-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/
instance sub : Sub Ordinal :=
⟨fun a b => sInf { o | a ≤ b + o }⟩
theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) :=
csInf_mem sub_nonempty
#align ordinal.le_add_sub Ordinal.le_add_sub
theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c :=
⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩
#align ordinal.sub_le Ordinal.sub_le
theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b :=
lt_iff_lt_of_le_iff_le sub_le
#align ordinal.lt_sub Ordinal.lt_sub
theorem add_sub_cancel (a b : Ordinal) : a + b - a = b :=
le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _)
#align ordinal.add_sub_cancel Ordinal.add_sub_cancel
theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b :=
h ▸ add_sub_cancel _ _
#align ordinal.sub_eq_of_add_eq Ordinal.sub_eq_of_add_eq
theorem sub_le_self (a b : Ordinal) : a - b ≤ a :=
sub_le.2 <| le_add_left _ _
#align ordinal.sub_le_self Ordinal.sub_le_self
protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a :=
(le_add_sub a b).antisymm'
(by
rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l)
· simp only [e, add_zero, h]
· rw [e, add_succ, succ_le_iff, ← lt_sub, e]
exact lt_succ c
· exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le)
#align ordinal.add_sub_cancel_of_le Ordinal.add_sub_cancel_of_le
theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by
rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h]
#align ordinal.le_sub_of_le Ordinal.le_sub_of_le
theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c :=
lt_iff_lt_of_le_iff_le (le_sub_of_le h)
#align ordinal.sub_lt_of_le Ordinal.sub_lt_of_le
instance existsAddOfLE : ExistsAddOfLE Ordinal :=
⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩
@[simp]
theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a
#align ordinal.sub_zero Ordinal.sub_zero
@[simp]
theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self
#align ordinal.zero_sub Ordinal.zero_sub
@[simp]
theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0
#align ordinal.sub_self Ordinal.sub_self
protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b :=
⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by
rwa [← Ordinal.le_zero, sub_le, add_zero]⟩
#align ordinal.sub_eq_zero_iff_le Ordinal.sub_eq_zero_iff_le
theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) :=
eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc]
#align ordinal.sub_sub Ordinal.sub_sub
@[simp]
theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by
rw [← sub_sub, add_sub_cancel]
#align ordinal.add_sub_add_cancel Ordinal.add_sub_add_cancel
theorem sub_isLimit {a b} (l : IsLimit a) (h : b < a) : IsLimit (a - b) :=
⟨ne_of_gt <| lt_sub.2 <| by rwa [add_zero], fun c h => by
rw [lt_sub, add_succ]; exact l.2 _ (lt_sub.1 h)⟩
#align ordinal.sub_is_limit Ordinal.sub_isLimit
-- @[simp] -- Porting note (#10618): simp can prove this
theorem one_add_omega : 1 + ω = ω := by
refine le_antisymm ?_ (le_add_left _ _)
rw [omega, ← lift_one.{_, 0}, ← lift_add, lift_le, ← type_unit, ← type_sum_lex]
refine ⟨RelEmbedding.collapse (RelEmbedding.ofMonotone ?_ ?_)⟩
· apply Sum.rec
· exact fun _ => 0
· exact Nat.succ
· intro a b
cases a <;> cases b <;> intro H <;> cases' H with _ _ H _ _ H <;>
[exact H.elim; exact Nat.succ_pos _; exact Nat.succ_lt_succ H]
#align ordinal.one_add_omega Ordinal.one_add_omega
@[simp]
theorem one_add_of_omega_le {o} (h : ω ≤ o) : 1 + o = o := by
rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, one_add_omega]
#align ordinal.one_add_of_omega_le Ordinal.one_add_of_omega_le
/-! ### Multiplication of ordinals-/
/-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on
`o₂ × o₁`. -/
instance monoid : Monoid Ordinal.{u} where
mul a b :=
Quotient.liftOn₂ a b
(fun ⟨α, r, wo⟩ ⟨β, s, wo'⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ :
WellOrder → WellOrder → Ordinal)
fun ⟨α₁, r₁, o₁⟩ ⟨α₂, r₂, o₂⟩ ⟨β₁, s₁, p₁⟩ ⟨β₂, s₂, p₂⟩ ⟨f⟩ ⟨g⟩ =>
Quot.sound ⟨RelIso.prodLexCongr g f⟩
one := 1
mul_assoc a b c :=
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Eq.symm <|
Quotient.sound
⟨⟨prodAssoc _ _ _, @fun a b => by
rcases a with ⟨⟨a₁, a₂⟩, a₃⟩
rcases b with ⟨⟨b₁, b₂⟩, b₃⟩
simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩
mul_one a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨punitProd _, @fun a b => by
rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩
simp only [Prod.lex_def, EmptyRelation, false_or_iff]
simp only [eq_self_iff_true, true_and_iff]
rfl⟩⟩
one_mul a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨prodPUnit _, @fun a b => by
rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩
simp only [Prod.lex_def, EmptyRelation, and_false_iff, or_false_iff]
rfl⟩⟩
@[simp]
theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r]
[IsWellOrder β s] : type (Prod.Lex s r) = type r * type s :=
rfl
#align ordinal.type_prod_lex Ordinal.type_prod_lex
private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
inductionOn a fun α _ _ =>
inductionOn b fun β _ _ => by
simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty]
rw [or_comm]
exact isEmpty_prod
instance monoidWithZero : MonoidWithZero Ordinal :=
{ Ordinal.monoid with
zero := 0
mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl
zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl }
instance noZeroDivisors : NoZeroDivisors Ordinal :=
⟨fun {_ _} => mul_eq_zero'.1⟩
@[simp]
theorem lift_mul (a b : Ordinal.{v}) : lift.{u} (a * b) = lift.{u} a * lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.prodLexCongr (RelIso.preimage Equiv.ulift _)
(RelIso.preimage Equiv.ulift _)).symm⟩
#align ordinal.lift_mul Ordinal.lift_mul
@[simp]
theorem card_mul (a b) : card (a * b) = card a * card b :=
Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α
#align ordinal.card_mul Ordinal.card_mul
instance leftDistribClass : LeftDistribClass Ordinal.{u} :=
⟨fun a b c =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Quotient.sound
⟨⟨sumProdDistrib _ _ _, by
rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;>
simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl,
Sum.lex_inr_inr, sumProdDistrib_apply_left, sumProdDistrib_apply_right] <;>
-- Porting note: `Sum.inr.inj_iff` is required.
simp only [Sum.inl.inj_iff, Sum.inr.inj_iff,
true_or_iff, false_and_iff, false_or_iff]⟩⟩⟩
theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a :=
mul_add_one a b
#align ordinal.mul_succ Ordinal.mul_succ
instance mul_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· * ·) (· ≤ ·) :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le
cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h'
· exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h')
· exact Prod.Lex.right _ h'⟩
#align ordinal.mul_covariant_class_le Ordinal.mul_covariantClass_le
instance mul_swap_covariantClass_le :
CovariantClass Ordinal.{u} Ordinal.{u} (swap (· * ·)) (· ≤ ·) :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le
cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h'
· exact Prod.Lex.left _ _ h'
· exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩
#align ordinal.mul_swap_covariant_class_le Ordinal.mul_swap_covariantClass_le
theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by
convert mul_le_mul_left' (one_le_iff_pos.2 hb) a
rw [mul_one a]
#align ordinal.le_mul_left Ordinal.le_mul_left
theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by
convert mul_le_mul_right' (one_le_iff_pos.2 hb) a
rw [one_mul a]
#align ordinal.le_mul_right Ordinal.le_mul_right
private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c}
(h : IsLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) :
False := by
suffices ∀ a b, Prod.Lex s r (b, a) (enum _ _ l) by
cases' enum _ _ l with b a
exact irrefl _ (this _ _)
intro a b
rw [← typein_lt_typein (Prod.Lex s r), typein_enum]
have := H _ (h.2 _ (typein_lt_type s b))
rw [mul_succ] at this
have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this
refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨⟨b', a'⟩, h⟩
by_cases e : b = b'
· refine Sum.inr ⟨a', ?_⟩
subst e
cases' h with _ _ _ _ h _ _ _ h
· exact (irrefl _ h).elim
· exact h
· refine Sum.inl (⟨b', ?_⟩, a')
cases' h with _ _ _ _ h _ _ _ h
· exact h
· exact (e rfl).elim
· rcases a with ⟨⟨b₁, a₁⟩, h₁⟩
rcases b with ⟨⟨b₂, a₂⟩, h₂⟩
intro h
by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂
· substs b₁ b₂
simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and_iff, false_or_iff,
eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h
· subst b₁
simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, eq_self_iff_true,
or_false_iff, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and_iff] at h ⊢
cases' h₂ with _ _ _ _ h₂_h h₂_h <;> [exact asymm h h₂_h; exact e₂ rfl]
-- Porting note: `cc` hadn't ported yet.
· simp [e₂, dif_neg e₁, show b₂ ≠ b₁ from e₂ ▸ e₁]
· simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk,
Sum.lex_inl_inl] using h
theorem mul_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c :=
⟨fun h b' l => (mul_le_mul_left' l.le _).trans h, fun H =>
-- Porting note: `induction` tactics are required because of the parser bug.
le_of_not_lt <| by
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
exact mul_le_of_limit_aux h H⟩
#align ordinal.mul_le_of_limit Ordinal.mul_le_of_limit
theorem mul_isNormal {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) :=
-- Porting note(#12129): additional beta reduction needed
⟨fun b => by
beta_reduce
rw [mul_succ]
simpa only [add_zero] using (add_lt_add_iff_left (a * b)).2 h,
fun b l c => mul_le_of_limit l⟩
#align ordinal.mul_is_normal Ordinal.mul_isNormal
theorem lt_mul_of_limit {a b c : Ordinal} (h : IsLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@mul_le_of_limit b c a h)
#align ordinal.lt_mul_of_limit Ordinal.lt_mul_of_limit
theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c :=
(mul_isNormal a0).lt_iff
#align ordinal.mul_lt_mul_iff_left Ordinal.mul_lt_mul_iff_left
theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c :=
(mul_isNormal a0).le_iff
#align ordinal.mul_le_mul_iff_left Ordinal.mul_le_mul_iff_left
theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b :=
(mul_lt_mul_iff_left c0).2 h
#align ordinal.mul_lt_mul_of_pos_left Ordinal.mul_lt_mul_of_pos_left
theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by
simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁
#align ordinal.mul_pos Ordinal.mul_pos
theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by
simpa only [Ordinal.pos_iff_ne_zero] using mul_pos
#align ordinal.mul_ne_zero Ordinal.mul_ne_zero
theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b :=
le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h
#align ordinal.le_of_mul_le_mul_left Ordinal.le_of_mul_le_mul_left
theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c :=
(mul_isNormal a0).inj
#align ordinal.mul_right_inj Ordinal.mul_right_inj
theorem mul_isLimit {a b : Ordinal} (a0 : 0 < a) : IsLimit b → IsLimit (a * b) :=
(mul_isNormal a0).isLimit
#align ordinal.mul_is_limit Ordinal.mul_isLimit
theorem mul_isLimit_left {a b : Ordinal} (l : IsLimit a) (b0 : 0 < b) : IsLimit (a * b) := by
rcases zero_or_succ_or_limit b with (rfl | ⟨b, rfl⟩ | lb)
· exact b0.false.elim
· rw [mul_succ]
exact add_isLimit _ l
· exact mul_isLimit l.pos lb
#align ordinal.mul_is_limit_left Ordinal.mul_isLimit_left
theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n
| 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero]
| n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n]
#align ordinal.smul_eq_mul Ordinal.smul_eq_mul
/-! ### Division on ordinals -/
/-- The set in the definition of division is nonempty. -/
theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty :=
⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by
simpa only [succ_zero, one_mul] using
mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩
#align ordinal.div_nonempty Ordinal.div_nonempty
/-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/
instance div : Div Ordinal :=
⟨fun a b => if _h : b = 0 then 0 else sInf { o | a < b * succ o }⟩
@[simp]
theorem div_zero (a : Ordinal) : a / 0 = 0 :=
dif_pos rfl
#align ordinal.div_zero Ordinal.div_zero
theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } :=
dif_neg h
#align ordinal.div_def Ordinal.div_def
theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by
rw [div_def a h]; exact csInf_mem (div_nonempty h)
#align ordinal.lt_mul_succ_div Ordinal.lt_mul_succ_div
theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by
simpa only [mul_succ] using lt_mul_succ_div a h
#align ordinal.lt_mul_div_add Ordinal.lt_mul_div_add
theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c :=
⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by
rw [div_def a b0]; exact csInf_le' h⟩
#align ordinal.div_le Ordinal.div_le
theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by
rw [← not_le, div_le h, not_lt]
#align ordinal.lt_div Ordinal.lt_div
theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h]
#align ordinal.div_pos Ordinal.div_pos
theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by
induction a using limitRecOn with
| H₁ => simp only [mul_zero, Ordinal.zero_le]
| H₂ _ _ => rw [succ_le_iff, lt_div c0]
| H₃ _ h₁ h₂ =>
revert h₁ h₂
simp (config := { contextual := true }) only [mul_le_of_limit, limit_le, iff_self_iff,
forall_true_iff]
#align ordinal.le_div Ordinal.le_div
theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c :=
lt_iff_lt_of_le_iff_le <| le_div b0
#align ordinal.div_lt Ordinal.div_lt
theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c :=
if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le]
else
(div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0)
#align ordinal.div_le_of_le_mul Ordinal.div_le_of_le_mul
theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b :=
lt_imp_lt_of_le_imp_le div_le_of_le_mul
#align ordinal.mul_lt_of_lt_div Ordinal.mul_lt_of_lt_div
@[simp]
theorem zero_div (a : Ordinal) : 0 / a = 0 :=
Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _
#align ordinal.zero_div Ordinal.zero_div
theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a :=
if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl
#align ordinal.mul_div_le Ordinal.mul_div_le
theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by
apply le_antisymm
· apply (div_le b0).2
rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left]
apply lt_mul_div_add _ b0
· rw [le_div b0, mul_add, add_le_add_iff_left]
apply mul_div_le
#align ordinal.mul_add_div Ordinal.mul_add_div
theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by
rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h]
simpa only [succ_zero, mul_one] using h
#align ordinal.div_eq_zero_of_lt Ordinal.div_eq_zero_of_lt
@[simp]
theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by
simpa only [add_zero, zero_div] using mul_add_div a b0 0
#align ordinal.mul_div_cancel Ordinal.mul_div_cancel
@[simp]
theorem div_one (a : Ordinal) : a / 1 = a := by
simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero
#align ordinal.div_one Ordinal.div_one
@[simp]
theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by
simpa only [mul_one] using mul_div_cancel 1 h
#align ordinal.div_self Ordinal.div_self
theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c :=
if a0 : a = 0 then by simp only [a0, zero_mul, sub_self]
else
eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0]
#align ordinal.mul_sub Ordinal.mul_sub
theorem isLimit_add_iff {a b} : IsLimit (a + b) ↔ IsLimit b ∨ b = 0 ∧ IsLimit a := by
constructor <;> intro h
· by_cases h' : b = 0
· rw [h', add_zero] at h
right
exact ⟨h', h⟩
left
rw [← add_sub_cancel a b]
apply sub_isLimit h
suffices a + 0 < a + b by simpa only [add_zero] using this
rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero]
rcases h with (h | ⟨rfl, h⟩)
· exact add_isLimit a h
· simpa only [add_zero]
#align ordinal.is_limit_add_iff Ordinal.isLimit_add_iff
theorem dvd_add_iff : ∀ {a b c : Ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c)
| a, _, c, ⟨b, rfl⟩ =>
⟨fun ⟨d, e⟩ => ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩, fun ⟨d, e⟩ => by
rw [e, ← mul_add]
apply dvd_mul_right⟩
#align ordinal.dvd_add_iff Ordinal.dvd_add_iff
theorem div_mul_cancel : ∀ {a b : Ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b
| a, _, a0, ⟨b, rfl⟩ => by rw [mul_div_cancel _ a0]
#align ordinal.div_mul_cancel Ordinal.div_mul_cancel
theorem le_of_dvd : ∀ {a b : Ordinal}, b ≠ 0 → a ∣ b → a ≤ b
-- Porting note: `⟨b, rfl⟩ => by` → `⟨b, e⟩ => by subst e`
| a, _, b0, ⟨b, e⟩ => by
subst e
-- Porting note: `Ne` is required.
simpa only [mul_one] using
mul_le_mul_left'
(one_le_iff_ne_zero.2 fun h : b = 0 => by
simp only [h, mul_zero, Ne, not_true_eq_false] at b0) a
#align ordinal.le_of_dvd Ordinal.le_of_dvd
theorem dvd_antisymm {a b : Ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b :=
if a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h₁).symm
else
if b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h₂
else (le_of_dvd b0 h₁).antisymm (le_of_dvd a0 h₂)
#align ordinal.dvd_antisymm Ordinal.dvd_antisymm
instance isAntisymm : IsAntisymm Ordinal (· ∣ ·) :=
⟨@dvd_antisymm⟩
/-- `a % b` is the unique ordinal `o'` satisfying
`a = b * o + o'` with `o' < b`. -/
instance mod : Mod Ordinal :=
⟨fun a b => a - b * (a / b)⟩
theorem mod_def (a b : Ordinal) : a % b = a - b * (a / b) :=
rfl
#align ordinal.mod_def Ordinal.mod_def
theorem mod_le (a b : Ordinal) : a % b ≤ a :=
sub_le_self a _
#align ordinal.mod_le Ordinal.mod_le
@[simp]
theorem mod_zero (a : Ordinal) : a % 0 = a := by simp only [mod_def, div_zero, zero_mul, sub_zero]
#align ordinal.mod_zero Ordinal.mod_zero
theorem mod_eq_of_lt {a b : Ordinal} (h : a < b) : a % b = a := by
simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero]
#align ordinal.mod_eq_of_lt Ordinal.mod_eq_of_lt
@[simp]
theorem zero_mod (b : Ordinal) : 0 % b = 0 := by simp only [mod_def, zero_div, mul_zero, sub_self]
#align ordinal.zero_mod Ordinal.zero_mod
theorem div_add_mod (a b : Ordinal) : b * (a / b) + a % b = a :=
Ordinal.add_sub_cancel_of_le <| mul_div_le _ _
#align ordinal.div_add_mod Ordinal.div_add_mod
theorem mod_lt (a) {b : Ordinal} (h : b ≠ 0) : a % b < b :=
(add_lt_add_iff_left (b * (a / b))).1 <| by rw [div_add_mod]; exact lt_mul_div_add a h
#align ordinal.mod_lt Ordinal.mod_lt
@[simp]
theorem mod_self (a : Ordinal) : a % a = 0 :=
if a0 : a = 0 then by simp only [a0, zero_mod]
else by simp only [mod_def, div_self a0, mul_one, sub_self]
#align ordinal.mod_self Ordinal.mod_self
@[simp]
theorem mod_one (a : Ordinal) : a % 1 = 0 := by simp only [mod_def, div_one, one_mul, sub_self]
#align ordinal.mod_one Ordinal.mod_one
theorem dvd_of_mod_eq_zero {a b : Ordinal} (H : a % b = 0) : b ∣ a :=
⟨a / b, by simpa [H] using (div_add_mod a b).symm⟩
#align ordinal.dvd_of_mod_eq_zero Ordinal.dvd_of_mod_eq_zero
theorem mod_eq_zero_of_dvd {a b : Ordinal} (H : b ∣ a) : a % b = 0 := by
rcases H with ⟨c, rfl⟩
rcases eq_or_ne b 0 with (rfl | hb)
· simp
· simp [mod_def, hb]
#align ordinal.mod_eq_zero_of_dvd Ordinal.mod_eq_zero_of_dvd
theorem dvd_iff_mod_eq_zero {a b : Ordinal} : b ∣ a ↔ a % b = 0 :=
⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩
#align ordinal.dvd_iff_mod_eq_zero Ordinal.dvd_iff_mod_eq_zero
@[simp]
theorem mul_add_mod_self (x y z : Ordinal) : (x * y + z) % x = z % x := by
rcases eq_or_ne x 0 with rfl | hx
· simp
· rwa [mod_def, mul_add_div, mul_add, ← sub_sub, add_sub_cancel, mod_def]
#align ordinal.mul_add_mod_self Ordinal.mul_add_mod_self
@[simp]
theorem mul_mod (x y : Ordinal) : x * y % x = 0 := by
simpa using mul_add_mod_self x y 0
#align ordinal.mul_mod Ordinal.mul_mod
theorem mod_mod_of_dvd (a : Ordinal) {b c : Ordinal} (h : c ∣ b) : a % b % c = a % c := by
nth_rw 2 [← div_add_mod a b]
rcases h with ⟨d, rfl⟩
rw [mul_assoc, mul_add_mod_self]
#align ordinal.mod_mod_of_dvd Ordinal.mod_mod_of_dvd
@[simp]
theorem mod_mod (a b : Ordinal) : a % b % b = a % b :=
mod_mod_of_dvd a dvd_rfl
#align ordinal.mod_mod Ordinal.mod_mod
/-! ### Families of ordinals
There are two kinds of indexed families that naturally arise when dealing with ordinals: those
indexed by some type in the appropriate universe, and those indexed by ordinals less than another.
The following API allows one to convert from one kind of family to the other.
In many cases, this makes it easy to prove claims about one kind of family via the corresponding
claim on the other. -/
/-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a specified
well-ordering. -/
def bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) :
∀ a < type r, α := fun a ha => f (enum r a ha)
#align ordinal.bfamily_of_family' Ordinal.bfamilyOfFamily'
/-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a well-ordering
given by the axiom of choice. -/
def bfamilyOfFamily {ι : Type u} : (ι → α) → ∀ a < type (@WellOrderingRel ι), α :=
bfamilyOfFamily' WellOrderingRel
#align ordinal.bfamily_of_family Ordinal.bfamilyOfFamily
/-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a specified
well-ordering. -/
def familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o)
(f : ∀ a < o, α) : ι → α := fun i =>
f (typein r i)
(by
rw [← ho]
exact typein_lt_type r i)
#align ordinal.family_of_bfamily' Ordinal.familyOfBFamily'
/-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a well-ordering
given by the axiom of choice. -/
def familyOfBFamily (o : Ordinal) (f : ∀ a < o, α) : o.out.α → α :=
familyOfBFamily' (· < ·) (type_lt o) f
#align ordinal.family_of_bfamily Ordinal.familyOfBFamily
@[simp]
theorem bfamilyOfFamily'_typein {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) (i) :
bfamilyOfFamily' r f (typein r i) (typein_lt_type r i) = f i := by
simp only [bfamilyOfFamily', enum_typein]
#align ordinal.bfamily_of_family'_typein Ordinal.bfamilyOfFamily'_typein
@[simp]
theorem bfamilyOfFamily_typein {ι} (f : ι → α) (i) :
bfamilyOfFamily f (typein _ i) (typein_lt_type _ i) = f i :=
bfamilyOfFamily'_typein _ f i
#align ordinal.bfamily_of_family_typein Ordinal.bfamilyOfFamily_typein
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem familyOfBFamily'_enum {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) (i hi) :
familyOfBFamily' r ho f (enum r i (by rwa [ho])) = f i hi := by
simp only [familyOfBFamily', typein_enum]
#align ordinal.family_of_bfamily'_enum Ordinal.familyOfBFamily'_enum
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem familyOfBFamily_enum (o : Ordinal) (f : ∀ a < o, α) (i hi) :
familyOfBFamily o f
(enum (· < ·) i
(by
convert hi
exact type_lt _)) =
f i hi :=
familyOfBFamily'_enum _ (type_lt o) f _ _
#align ordinal.family_of_bfamily_enum Ordinal.familyOfBFamily_enum
/-- The range of a family indexed by ordinals. -/
def brange (o : Ordinal) (f : ∀ a < o, α) : Set α :=
{ a | ∃ i hi, f i hi = a }
#align ordinal.brange Ordinal.brange
theorem mem_brange {o : Ordinal} {f : ∀ a < o, α} {a} : a ∈ brange o f ↔ ∃ i hi, f i hi = a :=
Iff.rfl
#align ordinal.mem_brange Ordinal.mem_brange
theorem mem_brange_self {o} (f : ∀ a < o, α) (i hi) : f i hi ∈ brange o f :=
⟨i, hi, rfl⟩
#align ordinal.mem_brange_self Ordinal.mem_brange_self
@[simp]
theorem range_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) : range (familyOfBFamily' r ho f) = brange o f := by
refine Set.ext fun a => ⟨?_, ?_⟩
· rintro ⟨b, rfl⟩
apply mem_brange_self
· rintro ⟨i, hi, rfl⟩
exact ⟨_, familyOfBFamily'_enum _ _ _ _ _⟩
#align ordinal.range_family_of_bfamily' Ordinal.range_familyOfBFamily'
@[simp]
theorem range_familyOfBFamily {o} (f : ∀ a < o, α) : range (familyOfBFamily o f) = brange o f :=
range_familyOfBFamily' _ _ f
#align ordinal.range_family_of_bfamily Ordinal.range_familyOfBFamily
@[simp]
theorem brange_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) :
brange _ (bfamilyOfFamily' r f) = range f := by
refine Set.ext fun a => ⟨?_, ?_⟩
· rintro ⟨i, hi, rfl⟩
apply mem_range_self
· rintro ⟨b, rfl⟩
exact ⟨_, _, bfamilyOfFamily'_typein _ _ _⟩
#align ordinal.brange_bfamily_of_family' Ordinal.brange_bfamilyOfFamily'
@[simp]
theorem brange_bfamilyOfFamily {ι : Type u} (f : ι → α) : brange _ (bfamilyOfFamily f) = range f :=
brange_bfamilyOfFamily' _ _
#align ordinal.brange_bfamily_of_family Ordinal.brange_bfamilyOfFamily
@[simp]
theorem brange_const {o : Ordinal} (ho : o ≠ 0) {c : α} : (brange o fun _ _ => c) = {c} := by
rw [← range_familyOfBFamily]
exact @Set.range_const _ o.out.α (out_nonempty_iff_ne_zero.2 ho) c
#align ordinal.brange_const Ordinal.brange_const
theorem comp_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α)
(g : α → β) : (fun i hi => g (bfamilyOfFamily' r f i hi)) = bfamilyOfFamily' r (g ∘ f) :=
rfl
#align ordinal.comp_bfamily_of_family' Ordinal.comp_bfamilyOfFamily'
theorem comp_bfamilyOfFamily {ι : Type u} (f : ι → α) (g : α → β) :
(fun i hi => g (bfamilyOfFamily f i hi)) = bfamilyOfFamily (g ∘ f) :=
rfl
#align ordinal.comp_bfamily_of_family Ordinal.comp_bfamilyOfFamily
theorem comp_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) (g : α → β) :
g ∘ familyOfBFamily' r ho f = familyOfBFamily' r ho fun i hi => g (f i hi) :=
rfl
#align ordinal.comp_family_of_bfamily' Ordinal.comp_familyOfBFamily'
theorem comp_familyOfBFamily {o} (f : ∀ a < o, α) (g : α → β) :
g ∘ familyOfBFamily o f = familyOfBFamily o fun i hi => g (f i hi) :=
rfl
#align ordinal.comp_family_of_bfamily Ordinal.comp_familyOfBFamily
/-! ### Supremum of a family of ordinals -/
-- Porting note: Universes should be specified in `sup`s.
/-- The supremum of a family of ordinals -/
def sup {ι : Type u} (f : ι → Ordinal.{max u v}) : Ordinal.{max u v} :=
iSup f
#align ordinal.sup Ordinal.sup
@[simp]
theorem sSup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : sSup (Set.range f) = sup.{_, v} f :=
rfl
#align ordinal.Sup_eq_sup Ordinal.sSup_eq_sup
/-- The range of an indexed ordinal function, whose outputs live in a higher universe than the
inputs, is always bounded above. See `Ordinal.lsub` for an explicit bound. -/
theorem bddAbove_range {ι : Type u} (f : ι → Ordinal.{max u v}) : BddAbove (Set.range f) :=
⟨(iSup (succ ∘ card ∘ f)).ord, by
rintro a ⟨i, rfl⟩
exact le_of_lt (Cardinal.lt_ord.2 ((lt_succ _).trans_le
(le_ciSup (Cardinal.bddAbove_range.{_, v} _) _)))⟩
#align ordinal.bdd_above_range Ordinal.bddAbove_range
theorem le_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : ∀ i, f i ≤ sup.{_, v} f := fun i =>
le_csSup (bddAbove_range.{_, v} f) (mem_range_self i)
#align ordinal.le_sup Ordinal.le_sup
theorem sup_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : sup.{_, v} f ≤ a ↔ ∀ i, f i ≤ a :=
(csSup_le_iff' (bddAbove_range.{_, v} f)).trans (by simp)
#align ordinal.sup_le_iff Ordinal.sup_le_iff
theorem sup_le {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : (∀ i, f i ≤ a) → sup.{_, v} f ≤ a :=
sup_le_iff.2
#align ordinal.sup_le Ordinal.sup_le
theorem lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : a < sup.{_, v} f ↔ ∃ i, a < f i := by
simpa only [not_forall, not_le] using not_congr (@sup_le_iff.{_, v} _ f a)
#align ordinal.lt_sup Ordinal.lt_sup
theorem ne_sup_iff_lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} :
(∀ i, f i ≠ sup.{_, v} f) ↔ ∀ i, f i < sup.{_, v} f :=
⟨fun hf _ => lt_of_le_of_ne (le_sup _ _) (hf _), fun hf _ => ne_of_lt (hf _)⟩
#align ordinal.ne_sup_iff_lt_sup Ordinal.ne_sup_iff_lt_sup
theorem sup_not_succ_of_ne_sup {ι : Type u} {f : ι → Ordinal.{max u v}}
(hf : ∀ i, f i ≠ sup.{_, v} f) {a} (hao : a < sup.{_, v} f) : succ a < sup.{_, v} f := by
by_contra! hoa
exact
hao.not_le (sup_le fun i => le_of_lt_succ <| (lt_of_le_of_ne (le_sup _ _) (hf i)).trans_le hoa)
#align ordinal.sup_not_succ_of_ne_sup Ordinal.sup_not_succ_of_ne_sup
@[simp]
theorem sup_eq_zero_iff {ι : Type u} {f : ι → Ordinal.{max u v}} :
sup.{_, v} f = 0 ↔ ∀ i, f i = 0 := by
refine
⟨fun h i => ?_, fun h =>
le_antisymm (sup_le fun i => Ordinal.le_zero.2 (h i)) (Ordinal.zero_le _)⟩
rw [← Ordinal.le_zero, ← h]
exact le_sup f i
#align ordinal.sup_eq_zero_iff Ordinal.sup_eq_zero_iff
theorem IsNormal.sup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f) {ι : Type u}
(g : ι → Ordinal.{max u v}) [Nonempty ι] : f (sup.{_, v} g) = sup.{_, w} (f ∘ g) :=
eq_of_forall_ge_iff fun a => by
rw [sup_le_iff]; simp only [comp]; rw [H.le_set' Set.univ Set.univ_nonempty g] <;>
simp [sup_le_iff]
#align ordinal.is_normal.sup Ordinal.IsNormal.sup
@[simp]
theorem sup_empty {ι} [IsEmpty ι] (f : ι → Ordinal) : sup f = 0 :=
ciSup_of_empty f
#align ordinal.sup_empty Ordinal.sup_empty
@[simp]
theorem sup_const {ι} [_hι : Nonempty ι] (o : Ordinal) : (sup fun _ : ι => o) = o :=
ciSup_const
#align ordinal.sup_const Ordinal.sup_const
@[simp]
theorem sup_unique {ι} [Unique ι] (f : ι → Ordinal) : sup f = f default :=
ciSup_unique
#align ordinal.sup_unique Ordinal.sup_unique
theorem sup_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f ⊆ Set.range g) : sup.{u, max v w} f ≤ sup.{v, max u w} g :=
sup_le fun i =>
match h (mem_range_self i) with
| ⟨_j, hj⟩ => hj ▸ le_sup _ _
#align ordinal.sup_le_of_range_subset Ordinal.sup_le_of_range_subset
theorem sup_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f = Set.range g) : sup.{u, max v w} f = sup.{v, max u w} g :=
(sup_le_of_range_subset.{u, v, w} h.le).antisymm (sup_le_of_range_subset.{v, u, w} h.ge)
#align ordinal.sup_eq_of_range_eq Ordinal.sup_eq_of_range_eq
@[simp]
theorem sup_sum {α : Type u} {β : Type v} (f : Sum α β → Ordinal) :
sup.{max u v, w} f =
max (sup.{u, max v w} fun a => f (Sum.inl a)) (sup.{v, max u w} fun b => f (Sum.inr b)) := by
apply (sup_le_iff.2 _).antisymm (max_le_iff.2 ⟨_, _⟩)
· rintro (i | i)
· exact le_max_of_le_left (le_sup _ i)
· exact le_max_of_le_right (le_sup _ i)
all_goals
apply sup_le_of_range_subset.{_, max u v, w}
rintro i ⟨a, rfl⟩
apply mem_range_self
#align ordinal.sup_sum Ordinal.sup_sum
theorem unbounded_range_of_sup_ge {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β → α)
(h : type r ≤ sup.{u, u} (typein r ∘ f)) : Unbounded r (range f) :=
(not_bounded_iff _).1 fun ⟨x, hx⟩ =>
not_lt_of_le h <|
lt_of_le_of_lt
(sup_le fun y => le_of_lt <| (typein_lt_typein r).2 <| hx _ <| mem_range_self y)
(typein_lt_type r x)
#align ordinal.unbounded_range_of_sup_ge Ordinal.unbounded_range_of_sup_ge
theorem le_sup_shrink_equiv {s : Set Ordinal.{u}} (hs : Small.{u} s) (a) (ha : a ∈ s) :
a ≤ sup.{u, u} fun x => ((@equivShrink s hs).symm x).val := by
convert le_sup.{u, u} (fun x => ((@equivShrink s hs).symm x).val) ((@equivShrink s hs) ⟨a, ha⟩)
rw [symm_apply_apply]
#align ordinal.le_sup_shrink_equiv Ordinal.le_sup_shrink_equiv
instance small_Iio (o : Ordinal.{u}) : Small.{u} (Set.Iio o) :=
let f : o.out.α → Set.Iio o :=
fun x => ⟨typein ((· < ·) : o.out.α → o.out.α → Prop) x, typein_lt_self x⟩
let hf : Surjective f := fun b =>
⟨enum (· < ·) b.val
(by
rw [type_lt]
exact b.prop),
Subtype.ext (typein_enum _ _)⟩
small_of_surjective hf
#align ordinal.small_Iio Ordinal.small_Iio
instance small_Iic (o : Ordinal.{u}) : Small.{u} (Set.Iic o) := by
rw [← Iio_succ]
infer_instance
#align ordinal.small_Iic Ordinal.small_Iic
theorem bddAbove_iff_small {s : Set Ordinal.{u}} : BddAbove s ↔ Small.{u} s :=
⟨fun ⟨a, h⟩ => small_subset <| show s ⊆ Iic a from fun _x hx => h hx, fun h =>
⟨sup.{u, u} fun x => ((@equivShrink s h).symm x).val, le_sup_shrink_equiv h⟩⟩
#align ordinal.bdd_above_iff_small Ordinal.bddAbove_iff_small
theorem bddAbove_of_small (s : Set Ordinal.{u}) [h : Small.{u} s] : BddAbove s :=
bddAbove_iff_small.2 h
#align ordinal.bdd_above_of_small Ordinal.bddAbove_of_small
theorem sup_eq_sSup {s : Set Ordinal.{u}} (hs : Small.{u} s) :
(sup.{u, u} fun x => (@equivShrink s hs).symm x) = sSup s :=
let hs' := bddAbove_iff_small.2 hs
((csSup_le_iff' hs').2 (le_sup_shrink_equiv hs)).antisymm'
(sup_le fun _x => le_csSup hs' (Subtype.mem _))
#align ordinal.sup_eq_Sup Ordinal.sup_eq_sSup
theorem sSup_ord {s : Set Cardinal.{u}} (hs : BddAbove s) : (sSup s).ord = sSup (ord '' s) :=
eq_of_forall_ge_iff fun a => by
rw [csSup_le_iff'
(bddAbove_iff_small.2 (@small_image _ _ _ s (Cardinal.bddAbove_iff_small.1 hs))),
ord_le, csSup_le_iff' hs]
simp [ord_le]
#align ordinal.Sup_ord Ordinal.sSup_ord
theorem iSup_ord {ι} {f : ι → Cardinal} (hf : BddAbove (range f)) :
(iSup f).ord = ⨆ i, (f i).ord := by
unfold iSup
convert sSup_ord hf
-- Porting note: `change` is required.
conv_lhs => change range (ord ∘ f)
rw [range_comp]
#align ordinal.supr_ord Ordinal.iSup_ord
private theorem sup_le_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop)
[IsWellOrder ι r] [IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o)
(f : ∀ a < o, Ordinal.{max u v}) :
sup.{_, v} (familyOfBFamily' r ho f) ≤ sup.{_, v} (familyOfBFamily' r' ho' f) :=
sup_le fun i => by
cases'
typein_surj r'
(by
rw [ho', ← ho]
exact typein_lt_type r i) with
j hj
simp_rw [familyOfBFamily', ← hj]
apply le_sup
theorem sup_eq_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r]
[IsWellOrder ι' r'] {o : Ordinal.{u}} (ho : type r = o) (ho' : type r' = o)
(f : ∀ a < o, Ordinal.{max u v}) :
sup.{_, v} (familyOfBFamily' r ho f) = sup.{_, v} (familyOfBFamily' r' ho' f) :=
sup_eq_of_range_eq.{u, u, v} (by simp)
#align ordinal.sup_eq_sup Ordinal.sup_eq_sup
/-- The supremum of a family of ordinals indexed by the set of ordinals less than some
`o : Ordinal.{u}`. This is a special case of `sup` over the family provided by
`familyOfBFamily`. -/
def bsup (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} :=
sup.{_, v} (familyOfBFamily o f)
#align ordinal.bsup Ordinal.bsup
@[simp]
theorem sup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
sup.{_, v} (familyOfBFamily o f) = bsup.{_, v} o f :=
rfl
#align ordinal.sup_eq_bsup Ordinal.sup_eq_bsup
@[simp]
theorem sup_eq_bsup' {o : Ordinal.{u}} {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (ho : type r = o)
(f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) = bsup.{_, v} o f :=
sup_eq_sup r _ ho _ f
#align ordinal.sup_eq_bsup' Ordinal.sup_eq_bsup'
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem sSup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
sSup (brange o f) = bsup.{_, v} o f := by
congr
rw [range_familyOfBFamily]
#align ordinal.Sup_eq_bsup Ordinal.sSup_eq_bsup
@[simp]
theorem bsup_eq_sup' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → Ordinal.{max u v}) :
bsup.{_, v} _ (bfamilyOfFamily' r f) = sup.{_, v} f := by
simp (config := { unfoldPartialApp := true }) only [← sup_eq_bsup' r, enum_typein,
familyOfBFamily', bfamilyOfFamily']
#align ordinal.bsup_eq_sup' Ordinal.bsup_eq_sup'
theorem bsup_eq_bsup {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r']
(f : ι → Ordinal.{max u v}) :
bsup.{_, v} _ (bfamilyOfFamily' r f) = bsup.{_, v} _ (bfamilyOfFamily' r' f) := by
rw [bsup_eq_sup', bsup_eq_sup']
#align ordinal.bsup_eq_bsup Ordinal.bsup_eq_bsup
@[simp]
theorem bsup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) :
bsup.{_, v} _ (bfamilyOfFamily f) = sup.{_, v} f :=
bsup_eq_sup' _ f
#align ordinal.bsup_eq_sup Ordinal.bsup_eq_sup
@[congr]
theorem bsup_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) :
bsup.{_, v} o₁ f = bsup.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by
subst ho
-- Porting note: `rfl` is required.
rfl
#align ordinal.bsup_congr Ordinal.bsup_congr
theorem bsup_le_iff {o f a} : bsup.{u, v} o f ≤ a ↔ ∀ i h, f i h ≤ a :=
sup_le_iff.trans
⟨fun h i hi => by
rw [← familyOfBFamily_enum o f]
exact h _, fun h i => h _ _⟩
#align ordinal.bsup_le_iff Ordinal.bsup_le_iff
theorem bsup_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} :
(∀ i h, f i h ≤ a) → bsup.{u, v} o f ≤ a :=
bsup_le_iff.2
#align ordinal.bsup_le Ordinal.bsup_le
theorem le_bsup {o} (f : ∀ a < o, Ordinal) (i h) : f i h ≤ bsup o f :=
bsup_le_iff.1 le_rfl _ _
#align ordinal.le_bsup Ordinal.le_bsup
theorem lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) {a} :
a < bsup.{_, v} o f ↔ ∃ i hi, a < f i hi := by
simpa only [not_forall, not_le] using not_congr (@bsup_le_iff.{_, v} _ f a)
#align ordinal.lt_bsup Ordinal.lt_bsup
theorem IsNormal.bsup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f)
{o : Ordinal.{u}} :
∀ (g : ∀ a < o, Ordinal), o ≠ 0 → f (bsup.{_, v} o g) = bsup.{_, w} o fun a h => f (g a h) :=
inductionOn o fun α r _ g h => by
haveI := type_ne_zero_iff_nonempty.1 h
rw [← sup_eq_bsup' r, IsNormal.sup.{_, v, w} H, ← sup_eq_bsup' r] <;> rfl
#align ordinal.is_normal.bsup Ordinal.IsNormal.bsup
theorem lt_bsup_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} :
(∀ i h, f i h ≠ bsup.{_, v} o f) ↔ ∀ i h, f i h < bsup.{_, v} o f :=
⟨fun hf _ _ => lt_of_le_of_ne (le_bsup _ _ _) (hf _ _), fun hf _ _ => ne_of_lt (hf _ _)⟩
#align ordinal.lt_bsup_of_ne_bsup Ordinal.lt_bsup_of_ne_bsup
theorem bsup_not_succ_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}}
(hf : ∀ {i : Ordinal} (h : i < o), f i h ≠ bsup.{_, v} o f) (a) :
a < bsup.{_, v} o f → succ a < bsup.{_, v} o f := by
rw [← sup_eq_bsup] at *
exact sup_not_succ_of_ne_sup fun i => hf _
#align ordinal.bsup_not_succ_of_ne_bsup Ordinal.bsup_not_succ_of_ne_bsup
@[simp]
theorem bsup_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : bsup o f = 0 ↔ ∀ i hi, f i hi = 0 := by
refine
⟨fun h i hi => ?_, fun h =>
le_antisymm (bsup_le fun i hi => Ordinal.le_zero.2 (h i hi)) (Ordinal.zero_le _)⟩
rw [← Ordinal.le_zero, ← h]
exact le_bsup f i hi
#align ordinal.bsup_eq_zero_iff Ordinal.bsup_eq_zero_iff
theorem lt_bsup_of_limit {o : Ordinal} {f : ∀ a < o, Ordinal}
(hf : ∀ {a a'} (ha : a < o) (ha' : a' < o), a < a' → f a ha < f a' ha')
(ho : ∀ a < o, succ a < o) (i h) : f i h < bsup o f :=
(hf _ _ <| lt_succ i).trans_le (le_bsup f (succ i) <| ho _ h)
#align ordinal.lt_bsup_of_limit Ordinal.lt_bsup_of_limit
theorem bsup_succ_of_mono {o : Ordinal} {f : ∀ a < succ o, Ordinal}
(hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : bsup _ f = f o (lt_succ o) :=
le_antisymm (bsup_le fun _i hi => hf _ _ <| le_of_lt_succ hi) (le_bsup _ _ _)
#align ordinal.bsup_succ_of_mono Ordinal.bsup_succ_of_mono
@[simp]
theorem bsup_zero (f : ∀ a < (0 : Ordinal), Ordinal) : bsup 0 f = 0 :=
bsup_eq_zero_iff.2 fun i hi => (Ordinal.not_lt_zero i hi).elim
#align ordinal.bsup_zero Ordinal.bsup_zero
theorem bsup_const {o : Ordinal.{u}} (ho : o ≠ 0) (a : Ordinal.{max u v}) :
(bsup.{_, v} o fun _ _ => a) = a :=
le_antisymm (bsup_le fun _ _ => le_rfl) (le_bsup _ 0 (Ordinal.pos_iff_ne_zero.2 ho))
#align ordinal.bsup_const Ordinal.bsup_const
@[simp]
theorem bsup_one (f : ∀ a < (1 : Ordinal), Ordinal) : bsup 1 f = f 0 zero_lt_one := by
simp_rw [← sup_eq_bsup, sup_unique, familyOfBFamily, familyOfBFamily', typein_one_out]
#align ordinal.bsup_one Ordinal.bsup_one
theorem bsup_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : brange o f ⊆ brange o' g) : bsup.{u, max v w} o f ≤ bsup.{v, max u w} o' g :=
bsup_le fun i hi => by
obtain ⟨j, hj, hj'⟩ := h ⟨i, hi, rfl⟩
rw [← hj']
apply le_bsup
#align ordinal.bsup_le_of_brange_subset Ordinal.bsup_le_of_brange_subset
theorem bsup_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : brange o f = brange o' g) : bsup.{u, max v w} o f = bsup.{v, max u w} o' g :=
(bsup_le_of_brange_subset.{u, v, w} h.le).antisymm (bsup_le_of_brange_subset.{v, u, w} h.ge)
#align ordinal.bsup_eq_of_brange_eq Ordinal.bsup_eq_of_brange_eq
/-- The least strict upper bound of a family of ordinals. -/
def lsub {ι} (f : ι → Ordinal) : Ordinal :=
sup (succ ∘ f)
#align ordinal.lsub Ordinal.lsub
@[simp]
theorem sup_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} (succ ∘ f) = lsub.{_, v} f :=
rfl
#align ordinal.sup_eq_lsub Ordinal.sup_eq_lsub
theorem lsub_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} :
lsub.{_, v} f ≤ a ↔ ∀ i, f i < a := by
convert sup_le_iff.{_, v} (f := succ ∘ f) (a := a) using 2
-- Porting note: `comp_apply` is required.
simp only [comp_apply, succ_le_iff]
#align ordinal.lsub_le_iff Ordinal.lsub_le_iff
theorem lsub_le {ι} {f : ι → Ordinal} {a} : (∀ i, f i < a) → lsub f ≤ a :=
lsub_le_iff.2
#align ordinal.lsub_le Ordinal.lsub_le
theorem lt_lsub {ι} (f : ι → Ordinal) (i) : f i < lsub f :=
succ_le_iff.1 (le_sup _ i)
#align ordinal.lt_lsub Ordinal.lt_lsub
theorem lt_lsub_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} :
a < lsub.{_, v} f ↔ ∃ i, a ≤ f i := by
simpa only [not_forall, not_lt, not_le] using not_congr (@lsub_le_iff.{_, v} _ f a)
#align ordinal.lt_lsub_iff Ordinal.lt_lsub_iff
theorem sup_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f ≤ lsub.{_, v} f :=
sup_le fun i => (lt_lsub f i).le
#align ordinal.sup_le_lsub Ordinal.sup_le_lsub
theorem lsub_le_sup_succ {ι : Type u} (f : ι → Ordinal.{max u v}) :
lsub.{_, v} f ≤ succ (sup.{_, v} f) :=
lsub_le fun i => lt_succ_iff.2 (le_sup f i)
#align ordinal.lsub_le_sup_succ Ordinal.lsub_le_sup_succ
theorem sup_eq_lsub_or_sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} f = lsub.{_, v} f ∨ succ (sup.{_, v} f) = lsub.{_, v} f := by
cases' eq_or_lt_of_le (sup_le_lsub.{_, v} f) with h h
· exact Or.inl h
· exact Or.inr ((succ_le_of_lt h).antisymm (lsub_le_sup_succ f))
#align ordinal.sup_eq_lsub_or_sup_succ_eq_lsub Ordinal.sup_eq_lsub_or_sup_succ_eq_lsub
theorem sup_succ_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
succ (sup.{_, v} f) ≤ lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f := by
refine ⟨fun h => ?_, ?_⟩
· by_contra! hf
exact (succ_le_iff.1 h).ne ((sup_le_lsub f).antisymm (lsub_le (ne_sup_iff_lt_sup.1 hf)))
rintro ⟨_, hf⟩
rw [succ_le_iff, ← hf]
exact lt_lsub _ _
#align ordinal.sup_succ_le_lsub Ordinal.sup_succ_le_lsub
theorem sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
succ (sup.{_, v} f) = lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f :=
(lsub_le_sup_succ f).le_iff_eq.symm.trans (sup_succ_le_lsub f)
#align ordinal.sup_succ_eq_lsub Ordinal.sup_succ_eq_lsub
theorem sup_eq_lsub_iff_succ {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} f = lsub.{_, v} f ↔ ∀ a < lsub.{_, v} f, succ a < lsub.{_, v} f := by
refine ⟨fun h => ?_, fun hf => le_antisymm (sup_le_lsub f) (lsub_le fun i => ?_)⟩
· rw [← h]
exact fun a => sup_not_succ_of_ne_sup fun i => (lsub_le_iff.1 (le_of_eq h.symm) i).ne
by_contra! hle
have heq := (sup_succ_eq_lsub f).2 ⟨i, le_antisymm (le_sup _ _) hle⟩
have :=
hf _
(by
rw [← heq]
exact lt_succ (sup f))
rw [heq] at this
exact this.false
#align ordinal.sup_eq_lsub_iff_succ Ordinal.sup_eq_lsub_iff_succ
theorem sup_eq_lsub_iff_lt_sup {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} f = lsub.{_, v} f ↔ ∀ i, f i < sup.{_, v} f :=
⟨fun h i => by
rw [h]
apply lt_lsub, fun h => le_antisymm (sup_le_lsub f) (lsub_le h)⟩
#align ordinal.sup_eq_lsub_iff_lt_sup Ordinal.sup_eq_lsub_iff_lt_sup
@[simp]
theorem lsub_empty {ι} [h : IsEmpty ι] (f : ι → Ordinal) : lsub f = 0 := by
rw [← Ordinal.le_zero, lsub_le_iff]
exact h.elim
#align ordinal.lsub_empty Ordinal.lsub_empty
theorem lsub_pos {ι : Type u} [h : Nonempty ι] (f : ι → Ordinal.{max u v}) : 0 < lsub.{_, v} f :=
h.elim fun i => (Ordinal.zero_le _).trans_lt (lt_lsub f i)
#align ordinal.lsub_pos Ordinal.lsub_pos
@[simp]
theorem lsub_eq_zero_iff {ι : Type u} (f : ι → Ordinal.{max u v}) :
lsub.{_, v} f = 0 ↔ IsEmpty ι := by
refine ⟨fun h => ⟨fun i => ?_⟩, fun h => @lsub_empty _ h _⟩
have := @lsub_pos.{_, v} _ ⟨i⟩ f
rw [h] at this
exact this.false
#align ordinal.lsub_eq_zero_iff Ordinal.lsub_eq_zero_iff
@[simp]
theorem lsub_const {ι} [Nonempty ι] (o : Ordinal) : (lsub fun _ : ι => o) = succ o :=
sup_const (succ o)
#align ordinal.lsub_const Ordinal.lsub_const
@[simp]
theorem lsub_unique {ι} [Unique ι] (f : ι → Ordinal) : lsub f = succ (f default) :=
sup_unique _
#align ordinal.lsub_unique Ordinal.lsub_unique
theorem lsub_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f ⊆ Set.range g) : lsub.{u, max v w} f ≤ lsub.{v, max u w} g :=
sup_le_of_range_subset.{u, v, w} (by convert Set.image_subset succ h <;> apply Set.range_comp)
#align ordinal.lsub_le_of_range_subset Ordinal.lsub_le_of_range_subset
theorem lsub_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f = Set.range g) : lsub.{u, max v w} f = lsub.{v, max u w} g :=
(lsub_le_of_range_subset.{u, v, w} h.le).antisymm (lsub_le_of_range_subset.{v, u, w} h.ge)
#align ordinal.lsub_eq_of_range_eq Ordinal.lsub_eq_of_range_eq
@[simp]
theorem lsub_sum {α : Type u} {β : Type v} (f : Sum α β → Ordinal) :
lsub.{max u v, w} f =
max (lsub.{u, max v w} fun a => f (Sum.inl a)) (lsub.{v, max u w} fun b => f (Sum.inr b)) :=
sup_sum _
#align ordinal.lsub_sum Ordinal.lsub_sum
theorem lsub_not_mem_range {ι : Type u} (f : ι → Ordinal.{max u v}) :
lsub.{_, v} f ∉ Set.range f := fun ⟨i, h⟩ =>
h.not_lt (lt_lsub f i)
#align ordinal.lsub_not_mem_range Ordinal.lsub_not_mem_range
theorem nonempty_compl_range {ι : Type u} (f : ι → Ordinal.{max u v}) : (Set.range f)ᶜ.Nonempty :=
⟨_, lsub_not_mem_range.{_, v} f⟩
#align ordinal.nonempty_compl_range Ordinal.nonempty_compl_range
@[simp]
theorem lsub_typein (o : Ordinal) : lsub.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o :=
(lsub_le.{u, u} typein_lt_self).antisymm
(by
by_contra! h
-- Porting note: `nth_rw` → `conv_rhs` & `rw`
conv_rhs at h => rw [← type_lt o]
simpa [typein_enum] using lt_lsub.{u, u} (typein (· < ·)) (enum (· < ·) _ h))
#align ordinal.lsub_typein Ordinal.lsub_typein
theorem sup_typein_limit {o : Ordinal} (ho : ∀ a, a < o → succ a < o) :
sup.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o := by
-- Porting note: `rwa` → `rw` & `assumption`
rw [(sup_eq_lsub_iff_succ.{u, u} (typein (· < ·))).2] <;> rw [lsub_typein o]; assumption
#align ordinal.sup_typein_limit Ordinal.sup_typein_limit
@[simp]
theorem sup_typein_succ {o : Ordinal} :
sup.{u, u} (typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) = o := by
cases'
sup_eq_lsub_or_sup_succ_eq_lsub.{u, u}
(typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) with
h h
· rw [sup_eq_lsub_iff_succ] at h
simp only [lsub_typein] at h
exact (h o (lt_succ o)).false.elim
rw [← succ_eq_succ_iff, h]
apply lsub_typein
#align ordinal.sup_typein_succ Ordinal.sup_typein_succ
/-- The least strict upper bound of a family of ordinals indexed by the set of ordinals less than
some `o : Ordinal.{u}`.
This is to `lsub` as `bsup` is to `sup`. -/
def blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} :=
bsup.{_, v} o fun a ha => succ (f a ha)
#align ordinal.blsub Ordinal.blsub
@[simp]
theorem bsup_eq_blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) :
(bsup.{_, v} o fun a ha => succ (f a ha)) = blsub.{_, v} o f :=
rfl
#align ordinal.bsup_eq_blsub Ordinal.bsup_eq_blsub
theorem lsub_eq_blsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o)
(f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily' r ho f) = blsub.{_, v} o f :=
sup_eq_bsup'.{_, v} r ho fun a ha => succ (f a ha)
#align ordinal.lsub_eq_blsub' Ordinal.lsub_eq_blsub'
theorem lsub_eq_lsub {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r]
[IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o)
(f : ∀ a < o, Ordinal.{max u v}) :
lsub.{_, v} (familyOfBFamily' r ho f) = lsub.{_, v} (familyOfBFamily' r' ho' f) := by
rw [lsub_eq_blsub', lsub_eq_blsub']
#align ordinal.lsub_eq_lsub Ordinal.lsub_eq_lsub
@[simp]
theorem lsub_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
lsub.{_, v} (familyOfBFamily o f) = blsub.{_, v} o f :=
lsub_eq_blsub' _ _ _
#align ordinal.lsub_eq_blsub Ordinal.lsub_eq_blsub
@[simp]
theorem blsub_eq_lsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r]
(f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily' r f) = lsub.{_, v} f :=
bsup_eq_sup'.{_, v} r (succ ∘ f)
#align ordinal.blsub_eq_lsub' Ordinal.blsub_eq_lsub'
theorem blsub_eq_blsub {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r']
(f : ι → Ordinal.{max u v}) :
blsub.{_, v} _ (bfamilyOfFamily' r f) = blsub.{_, v} _ (bfamilyOfFamily' r' f) := by
rw [blsub_eq_lsub', blsub_eq_lsub']
#align ordinal.blsub_eq_blsub Ordinal.blsub_eq_blsub
@[simp]
theorem blsub_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
blsub.{_, v} _ (bfamilyOfFamily f) = lsub.{_, v} f :=
blsub_eq_lsub' _ _
#align ordinal.blsub_eq_lsub Ordinal.blsub_eq_lsub
@[congr]
theorem blsub_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) :
blsub.{_, v} o₁ f = blsub.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by
subst ho
-- Porting note: `rfl` is required.
rfl
#align ordinal.blsub_congr Ordinal.blsub_congr
theorem blsub_le_iff {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} {a} :
blsub.{_, v} o f ≤ a ↔ ∀ i h, f i h < a := by
convert bsup_le_iff.{_, v} (f := fun a ha => succ (f a ha)) (a := a) using 2
simp_rw [succ_le_iff]
#align ordinal.blsub_le_iff Ordinal.blsub_le_iff
theorem blsub_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} : (∀ i h, f i h < a) → blsub o f ≤ a :=
blsub_le_iff.2
#align ordinal.blsub_le Ordinal.blsub_le
theorem lt_blsub {o} (f : ∀ a < o, Ordinal) (i h) : f i h < blsub o f :=
blsub_le_iff.1 le_rfl _ _
#align ordinal.lt_blsub Ordinal.lt_blsub
theorem lt_blsub_iff {o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{max u v}} {a} :
a < blsub.{_, v} o f ↔ ∃ i hi, a ≤ f i hi := by
simpa only [not_forall, not_lt, not_le] using not_congr (@blsub_le_iff.{_, v} _ f a)
#align ordinal.lt_blsub_iff Ordinal.lt_blsub_iff
theorem bsup_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f ≤ blsub.{_, v} o f :=
bsup_le fun i h => (lt_blsub f i h).le
#align ordinal.bsup_le_blsub Ordinal.bsup_le_blsub
theorem blsub_le_bsup_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
blsub.{_, v} o f ≤ succ (bsup.{_, v} o f) :=
blsub_le fun i h => lt_succ_iff.2 (le_bsup f i h)
#align ordinal.blsub_le_bsup_succ Ordinal.blsub_le_bsup_succ
theorem bsup_eq_blsub_or_succ_bsup_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f = blsub.{_, v} o f ∨ succ (bsup.{_, v} o f) = blsub.{_, v} o f := by
rw [← sup_eq_bsup, ← lsub_eq_blsub]
exact sup_eq_lsub_or_sup_succ_eq_lsub _
#align ordinal.bsup_eq_blsub_or_succ_bsup_eq_blsub Ordinal.bsup_eq_blsub_or_succ_bsup_eq_blsub
theorem bsup_succ_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
succ (bsup.{_, v} o f) ≤ blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f := by
refine ⟨fun h => ?_, ?_⟩
· by_contra! hf
exact
ne_of_lt (succ_le_iff.1 h)
(le_antisymm (bsup_le_blsub f) (blsub_le (lt_bsup_of_ne_bsup.1 hf)))
rintro ⟨_, _, hf⟩
rw [succ_le_iff, ← hf]
exact lt_blsub _ _ _
#align ordinal.bsup_succ_le_blsub Ordinal.bsup_succ_le_blsub
theorem bsup_succ_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
succ (bsup.{_, v} o f) = blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f :=
(blsub_le_bsup_succ f).le_iff_eq.symm.trans (bsup_succ_le_blsub f)
#align ordinal.bsup_succ_eq_blsub Ordinal.bsup_succ_eq_blsub
theorem bsup_eq_blsub_iff_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ a < blsub.{_, v} o f, succ a < blsub.{_, v} o f := by
rw [← sup_eq_bsup, ← lsub_eq_blsub]
apply sup_eq_lsub_iff_succ
#align ordinal.bsup_eq_blsub_iff_succ Ordinal.bsup_eq_blsub_iff_succ
theorem bsup_eq_blsub_iff_lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ i hi, f i hi < bsup.{_, v} o f :=
⟨fun h i => by
rw [h]
apply lt_blsub, fun h => le_antisymm (bsup_le_blsub f) (blsub_le h)⟩
#align ordinal.bsup_eq_blsub_iff_lt_bsup Ordinal.bsup_eq_blsub_iff_lt_bsup
theorem bsup_eq_blsub_of_lt_succ_limit {o : Ordinal.{u}} (ho : IsLimit o)
{f : ∀ a < o, Ordinal.{max u v}} (hf : ∀ a ha, f a ha < f (succ a) (ho.2 a ha)) :
bsup.{_, v} o f = blsub.{_, v} o f := by
rw [bsup_eq_blsub_iff_lt_bsup]
exact fun i hi => (hf i hi).trans_le (le_bsup f _ _)
#align ordinal.bsup_eq_blsub_of_lt_succ_limit Ordinal.bsup_eq_blsub_of_lt_succ_limit
theorem blsub_succ_of_mono {o : Ordinal.{u}} {f : ∀ a < succ o, Ordinal.{max u v}}
(hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : blsub.{_, v} _ f = succ (f o (lt_succ o)) :=
bsup_succ_of_mono fun {_ _} hi hj h => succ_le_succ (hf hi hj h)
#align ordinal.blsub_succ_of_mono Ordinal.blsub_succ_of_mono
@[simp]
theorem blsub_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : blsub o f = 0 ↔ o = 0 := by
rw [← lsub_eq_blsub, lsub_eq_zero_iff]
exact out_empty_iff_eq_zero
#align ordinal.blsub_eq_zero_iff Ordinal.blsub_eq_zero_iff
-- Porting note: `rwa` → `rw`
@[simp]
theorem blsub_zero (f : ∀ a < (0 : Ordinal), Ordinal) : blsub 0 f = 0 := by rw [blsub_eq_zero_iff]
#align ordinal.blsub_zero Ordinal.blsub_zero
theorem blsub_pos {o : Ordinal} (ho : 0 < o) (f : ∀ a < o, Ordinal) : 0 < blsub o f :=
(Ordinal.zero_le _).trans_lt (lt_blsub f 0 ho)
#align ordinal.blsub_pos Ordinal.blsub_pos
theorem blsub_type {α : Type u} (r : α → α → Prop) [IsWellOrder α r]
(f : ∀ a < type r, Ordinal.{max u v}) :
blsub.{_, v} (type r) f = lsub.{_, v} fun a => f (typein r a) (typein_lt_type _ _) :=
eq_of_forall_ge_iff fun o => by
rw [blsub_le_iff, lsub_le_iff];
exact ⟨fun H b => H _ _, fun H i h => by simpa only [typein_enum] using H (enum r i h)⟩
#align ordinal.blsub_type Ordinal.blsub_type
theorem blsub_const {o : Ordinal} (ho : o ≠ 0) (a : Ordinal) :
(blsub.{u, v} o fun _ _ => a) = succ a :=
bsup_const.{u, v} ho (succ a)
#align ordinal.blsub_const Ordinal.blsub_const
@[simp]
theorem blsub_one (f : ∀ a < (1 : Ordinal), Ordinal) : blsub 1 f = succ (f 0 zero_lt_one) :=
bsup_one _
#align ordinal.blsub_one Ordinal.blsub_one
@[simp]
theorem blsub_id : ∀ o, (blsub.{u, u} o fun x _ => x) = o :=
lsub_typein
#align ordinal.blsub_id Ordinal.blsub_id
theorem bsup_id_limit {o : Ordinal} : (∀ a < o, succ a < o) → (bsup.{u, u} o fun x _ => x) = o :=
sup_typein_limit
#align ordinal.bsup_id_limit Ordinal.bsup_id_limit
@[simp]
theorem bsup_id_succ (o) : (bsup.{u, u} (succ o) fun x _ => x) = o :=
sup_typein_succ
#align ordinal.bsup_id_succ Ordinal.bsup_id_succ
theorem blsub_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : brange o f ⊆ brange o' g) : blsub.{u, max v w} o f ≤ blsub.{v, max u w} o' g :=
bsup_le_of_brange_subset.{u, v, w} fun a ⟨b, hb, hb'⟩ => by
obtain ⟨c, hc, hc'⟩ := h ⟨b, hb, rfl⟩
simp_rw [← hc'] at hb'
exact ⟨c, hc, hb'⟩
#align ordinal.blsub_le_of_brange_subset Ordinal.blsub_le_of_brange_subset
theorem blsub_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : { o | ∃ i hi, f i hi = o } = { o | ∃ i hi, g i hi = o }) :
blsub.{u, max v w} o f = blsub.{v, max u w} o' g :=
(blsub_le_of_brange_subset.{u, v, w} h.le).antisymm (blsub_le_of_brange_subset.{v, u, w} h.ge)
#align ordinal.blsub_eq_of_brange_eq Ordinal.blsub_eq_of_brange_eq
theorem bsup_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}}
(hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}}
(hg : blsub.{_, u} o' g = o) :
(bsup.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = bsup.{_, w} o f := by
apply le_antisymm <;> refine bsup_le fun i hi => ?_
· apply le_bsup
· rw [← hg, lt_blsub_iff] at hi
rcases hi with ⟨j, hj, hj'⟩
exact (hf _ _ hj').trans (le_bsup _ _ _)
#align ordinal.bsup_comp Ordinal.bsup_comp
theorem blsub_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}}
(hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}}
(hg : blsub.{_, u} o' g = o) :
(blsub.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = blsub.{_, w} o f :=
@bsup_comp.{u, v, w} o _ (fun a ha => succ (f a ha))
(fun {_ _} _ _ h => succ_le_succ_iff.2 (hf _ _ h)) g hg
#align ordinal.blsub_comp Ordinal.blsub_comp
theorem IsNormal.bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}}
(h : IsLimit o) : (Ordinal.bsup.{_, v} o fun x _ => f x) = f o := by
rw [← IsNormal.bsup.{u, u, v} H (fun x _ => x) h.1, bsup_id_limit h.2]
#align ordinal.is_normal.bsup_eq Ordinal.IsNormal.bsup_eq
theorem IsNormal.blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}}
(h : IsLimit o) : (blsub.{_, v} o fun x _ => f x) = f o := by
rw [← IsNormal.bsup_eq.{u, v} H h, bsup_eq_blsub_of_lt_succ_limit h]
exact fun a _ => H.1 a
#align ordinal.is_normal.blsub_eq Ordinal.IsNormal.blsub_eq
theorem isNormal_iff_lt_succ_and_bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} :
IsNormal f ↔ (∀ a, f a < f (succ a)) ∧ ∀ o, IsLimit o → (bsup.{_, v} o fun x _ => f x) = f o :=
⟨fun h => ⟨h.1, @IsNormal.bsup_eq f h⟩, fun ⟨h₁, h₂⟩ =>
⟨h₁, fun o ho a => by
rw [← h₂ o ho]
exact bsup_le_iff⟩⟩
#align ordinal.is_normal_iff_lt_succ_and_bsup_eq Ordinal.isNormal_iff_lt_succ_and_bsup_eq
| Mathlib/SetTheory/Ordinal/Arithmetic.lean | 1,977 | 1,983 | theorem isNormal_iff_lt_succ_and_blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} :
IsNormal f ↔ (∀ a, f a < f (succ a)) ∧
∀ o, IsLimit o → (blsub.{_, v} o fun x _ => f x) = f o := by |
rw [isNormal_iff_lt_succ_and_bsup_eq.{u, v}, and_congr_right_iff]
intro h
constructor <;> intro H o ho <;> have := H o ho <;>
rwa [← bsup_eq_blsub_of_lt_succ_limit ho fun a _ => h a] at *
|
/-
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
import Mathlib.Data.Set.Subsingleton
#align_import combinatorics.composition from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7"
/-!
# 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.blocks_fun : 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.blocks_fun 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.
* `joinSplitWrtComposition_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)>
-/
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
#align composition Composition
/-- 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
#align composition_as_set CompositionAsSet
instance {n : ℕ} : Inhabited (CompositionAsSet n) :=
⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩
/-!
### 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
#align composition.length Composition.length
theorem blocks_length : c.blocks.length = c.length :=
rfl
#align composition.blocks_length Composition.blocks_length
/-- 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
#align composition.blocks_fun Composition.blocksFun
theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks :=
ofFn_get _
#align composition.of_fn_blocks_fun Composition.ofFn_blocksFun
theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by
conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn]
#align composition.sum_blocks_fun Composition.sum_blocksFun
theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks :=
get_mem _ _ _
#align composition.blocks_fun_mem_blocks Composition.blocksFun_mem_blocks
@[simp]
theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i :=
c.blocks_pos h
#align composition.one_le_blocks Composition.one_le_blocks
@[simp]
theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks.get ⟨i, h⟩ :=
c.one_le_blocks (get_mem (blocks c) i h)
#align composition.one_le_blocks' Composition.one_le_blocks'
@[simp]
theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks.get ⟨i, h⟩ :=
c.one_le_blocks' h
#align composition.blocks_pos' Composition.blocks_pos'
theorem one_le_blocksFun (i : Fin c.length) : 1 ≤ c.blocksFun i :=
c.one_le_blocks (c.blocksFun_mem_blocks i)
#align composition.one_le_blocks_fun Composition.one_le_blocksFun
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
#align composition.length_le Composition.length_le
theorem length_pos_of_pos (h : 0 < n) : 0 < c.length := by
apply length_pos_of_sum_pos
convert h
exact c.blocks_sum
#align composition.length_pos_of_pos Composition.length_pos_of_pos
/-- The sum of the sizes of the blocks in a composition up to `i`. -/
def sizeUpTo (i : ℕ) : ℕ :=
(c.blocks.take i).sum
#align composition.size_up_to Composition.sizeUpTo
@[simp]
theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo]
#align composition.size_up_to_zero Composition.sizeUpTo_zero
theorem sizeUpTo_ofLength_le (i : ℕ) (h : c.length ≤ i) : c.sizeUpTo i = n := by
dsimp [sizeUpTo]
convert c.blocks_sum
exact take_all_of_le h
#align composition.size_up_to_of_length_le Composition.sizeUpTo_ofLength_le
@[simp]
theorem sizeUpTo_length : c.sizeUpTo c.length = n :=
c.sizeUpTo_ofLength_le c.length le_rfl
#align composition.size_up_to_length Composition.sizeUpTo_length
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 _ _
#align composition.size_up_to_le Composition.sizeUpTo_le
theorem sizeUpTo_succ {i : ℕ} (h : i < c.length) :
c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks.get ⟨i, h⟩ := by
simp only [sizeUpTo]
rw [sum_take_succ _ _ h]
#align composition.size_up_to_succ Composition.sizeUpTo_succ
theorem sizeUpTo_succ' (i : Fin c.length) :
c.sizeUpTo ((i : ℕ) + 1) = c.sizeUpTo i + c.blocksFun i :=
c.sizeUpTo_succ i.2
#align composition.size_up_to_succ' Composition.sizeUpTo_succ'
theorem sizeUpTo_strict_mono {i : ℕ} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by
rw [c.sizeUpTo_succ h]
simp
#align composition.size_up_to_strict_mono Composition.sizeUpTo_strict_mono
theorem monotone_sizeUpTo : Monotone c.sizeUpTo :=
monotone_sum_take _
#align composition.monotone_size_up_to Composition.monotone_sizeUpTo
/-- 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
#align composition.boundary Composition.boundary
@[simp]
theorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff]
#align composition.boundary_zero Composition.boundary_zero
@[simp]
theorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by
simp [boundary, Fin.ext_iff]
#align composition.boundary_last Composition.boundary_last
/-- 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
#align composition.boundaries Composition.boundaries
theorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries]
#align composition.card_boundaries_eq_succ_length Composition.card_boundaries_eq_succ_length
/-- 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⟩
#align composition.to_composition_as_set Composition.toCompositionAsSet
/-- 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 _)
#align composition.order_emb_of_fin_boundaries Composition.orderEmbOfFin_boundaries
/-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocks_fun 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 _).symm
_ ≤ c.sizeUpTo c.length := monotone_sum_take _ i.2
_ = n := c.sizeUpTo_length
#align composition.embedding Composition.embedding
@[simp]
theorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.embedding i j : ℕ) = c.sizeUpTo i + j :=
rfl
#align composition.coe_embedding Composition.coe_embedding
/-- `index_exists` asserts there is some `i` with `j < c.size_up_to (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]
#align composition.index_exists Composition.index_exists
/-- `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⟩
#align composition.index Composition.index
theorem lt_sizeUpTo_index_succ (j : Fin n) : (j : ℕ) < c.sizeUpTo (c.index j).succ :=
(Nat.find_spec (c.index_exists j.2)).1
#align composition.lt_size_up_to_index_succ Composition.lt_sizeUpTo_index_succ
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
#align composition.size_up_to_index_le Composition.sizeUpTo_index_le
/-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with
`Fin (c.blocks_fun (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 _ _⟩
#align composition.inv_embedding Composition.invEmbedding
@[simp]
theorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : ℕ) = j - c.sizeUpTo (c.index j) :=
rfl
#align composition.coe_inv_embedding Composition.coe_invEmbedding
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)
#align composition.embedding_comp_inv Composition.embedding_comp_inv
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
#align composition.mem_range_embedding_iff Composition.mem_range_embedding_iff
/-- 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
#align composition.disjoint_range Composition.disjoint_range
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
#align composition.mem_range_embedding Composition.mem_range_embedding
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
#align composition.mem_range_embedding_iff' Composition.mem_range_embedding_iff'
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
#align composition.index_embedding Composition.index_embedding
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]
#align composition.inv_embedding_comp Composition.invEmbedding_comp
/-- Equivalence between the disjoint union of the blocks (each of them seen as
`Fin (c.blocks_fun 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
#align composition.blocks_fin_equiv Composition.blocksFinEquiv
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]
#align composition.blocks_fun_congr Composition.blocksFun_congr
/-- 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
#align composition.sigma_eq_iff_blocks_eq Composition.sigma_eq_iff_blocks_eq
/-! ### 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⟩
#align composition.ones Composition.ones
instance {n : ℕ} : Inhabited (Composition n) :=
⟨Composition.ones n⟩
@[simp]
theorem ones_length (n : ℕ) : (ones n).length = n :=
List.length_replicate n 1
#align composition.ones_length Composition.ones_length
@[simp]
theorem ones_blocks (n : ℕ) : (ones n).blocks = replicate n (1 : ℕ) :=
rfl
#align composition.ones_blocks Composition.ones_blocks
@[simp]
theorem ones_blocksFun (n : ℕ) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by
simp only [blocksFun, ones, blocks, i.2, List.get_replicate]
#align composition.ones_blocks_fun Composition.ones_blocksFun
@[simp]
theorem ones_sizeUpTo (n : ℕ) (i : ℕ) : (ones n).sizeUpTo i = min i n := by
simp [sizeUpTo, ones_blocks, take_replicate]
#align composition.ones_size_up_to Composition.ones_sizeUpTo
@[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
#align composition.ones_embedding Composition.ones_embedding
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]
#align composition.eq_ones_iff Composition.eq_ones_iff
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 (config := { contextual := true }) [this]
#align composition.ne_ones_iff Composition.ne_ones_iff
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
#align composition.eq_ones_iff_length Composition.eq_ones_iff_length
| Mathlib/Combinatorics/Enumerative/Composition.lean | 544 | 545 | 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]
|
/-
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.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.RingTheory.MvPowerSeries.Basic
#align_import ring_theory.power_series.basic from "leanprover-community/mathlib"@"2d5739b61641ee4e7e53eca5688a08f66f2e6a60"
/-!
# Formal power series (in one variable)
This file defines (univariate) formal power series
and develops the basic properties of these objects.
A formal power series is to a polynomial like an infinite sum is to a finite sum.
Formal power series in one variable are defined from multivariate
power series as `PowerSeries R := MvPowerSeries Unit R`.
The file sets up the (semi)ring structure on univariate power series.
We provide the natural inclusion from polynomials to formal power series.
Additional results can be found in:
* `Mathlib.RingTheory.PowerSeries.Trunc`, truncation of power series;
* `Mathlib.RingTheory.PowerSeries.Inverse`, about inverses of power series,
and the fact that power series over a local ring form a local ring;
* `Mathlib.RingTheory.PowerSeries.Order`, the order of a power series at 0,
and application to the fact that power series over an integral domain
form an integral domain.
## Implementation notes
Because of its definition,
`PowerSeries R := MvPowerSeries Unit R`.
a lot of proofs and properties from the multivariate case
can be ported to the single variable case.
However, it means that formal power series are indexed by `Unit →₀ ℕ`,
which is of course canonically isomorphic to `ℕ`.
We then build some glue to treat formal power series as if they were indexed by `ℕ`.
Occasionally this leads to proofs that are uglier than expected.
-/
noncomputable section
open Finset (antidiagonal mem_antidiagonal)
/-- Formal power series over a coefficient type `R` -/
def PowerSeries (R : Type*) :=
MvPowerSeries Unit R
#align power_series PowerSeries
namespace PowerSeries
open Finsupp (single)
variable {R : Type*}
section
-- Porting note: not available in Lean 4
-- local reducible PowerSeries
/--
`R⟦X⟧` is notation for `PowerSeries R`,
the semiring of formal power series in one variable over a semiring `R`.
-/
scoped notation:9000 R "⟦X⟧" => PowerSeries R
instance [Inhabited R] : Inhabited R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Zero R] : Zero R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddMonoid R] : AddMonoid R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddGroup R] : AddGroup R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddCommMonoid R] : AddCommMonoid R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddCommGroup R] : AddCommGroup R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Semiring R] : Semiring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [CommSemiring R] : CommSemiring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Ring R] : Ring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [CommRing R] : CommRing R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Nontrivial R] : Nontrivial R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R A⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S]
[IsScalarTower R S A] : IsScalarTower R S A⟦X⟧ :=
Pi.isScalarTower
instance {A} [Semiring A] [CommSemiring R] [Algebra R A] : Algebra R A⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
end
section Semiring
variable (R) [Semiring R]
/-- The `n`th coefficient of a formal power series. -/
def coeff (n : ℕ) : R⟦X⟧ →ₗ[R] R :=
MvPowerSeries.coeff R (single () n)
#align power_series.coeff PowerSeries.coeff
/-- The `n`th monomial with coefficient `a` as formal power series. -/
def monomial (n : ℕ) : R →ₗ[R] R⟦X⟧ :=
MvPowerSeries.monomial R (single () n)
#align power_series.monomial PowerSeries.monomial
variable {R}
theorem coeff_def {s : Unit →₀ ℕ} {n : ℕ} (h : s () = n) : coeff R n = MvPowerSeries.coeff R s := by
erw [coeff, ← h, ← Finsupp.unique_single s]
#align power_series.coeff_def PowerSeries.coeff_def
/-- Two formal power series are equal if all their coefficients are equal. -/
@[ext]
theorem ext {φ ψ : R⟦X⟧} (h : ∀ n, coeff R n φ = coeff R n ψ) : φ = ψ :=
MvPowerSeries.ext fun n => by
rw [← coeff_def]
· apply h
rfl
#align power_series.ext PowerSeries.ext
/-- Two formal power series are equal if all their coefficients are equal. -/
theorem ext_iff {φ ψ : R⟦X⟧} : φ = ψ ↔ ∀ n, coeff R n φ = coeff R n ψ :=
⟨fun h n => congr_arg (coeff R n) h, ext⟩
#align power_series.ext_iff PowerSeries.ext_iff
instance [Subsingleton R] : Subsingleton R⟦X⟧ := by
simp only [subsingleton_iff, ext_iff]
exact fun _ _ _ ↦ (subsingleton_iff).mp (by infer_instance) _ _
/-- Constructor for formal power series. -/
def mk {R} (f : ℕ → R) : R⟦X⟧ := fun s => f (s ())
#align power_series.mk PowerSeries.mk
@[simp]
theorem coeff_mk (n : ℕ) (f : ℕ → R) : coeff R n (mk f) = f n :=
congr_arg f Finsupp.single_eq_same
#align power_series.coeff_mk PowerSeries.coeff_mk
theorem coeff_monomial (m n : ℕ) (a : R) : coeff R m (monomial R n a) = if m = n then a else 0 :=
calc
coeff R m (monomial R n a) = _ := MvPowerSeries.coeff_monomial _ _ _
_ = if m = n then a else 0 := by simp only [Finsupp.unique_single_eq_iff]
#align power_series.coeff_monomial PowerSeries.coeff_monomial
theorem monomial_eq_mk (n : ℕ) (a : R) : monomial R n a = mk fun m => if m = n then a else 0 :=
ext fun m => by rw [coeff_monomial, coeff_mk]
#align power_series.monomial_eq_mk PowerSeries.monomial_eq_mk
@[simp]
theorem coeff_monomial_same (n : ℕ) (a : R) : coeff R n (monomial R n a) = a :=
MvPowerSeries.coeff_monomial_same _ _
#align power_series.coeff_monomial_same PowerSeries.coeff_monomial_same
@[simp]
theorem coeff_comp_monomial (n : ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id :=
LinearMap.ext <| coeff_monomial_same n
#align power_series.coeff_comp_monomial PowerSeries.coeff_comp_monomial
variable (R)
/-- The constant coefficient of a formal power series. -/
def constantCoeff : R⟦X⟧ →+* R :=
MvPowerSeries.constantCoeff Unit R
#align power_series.constant_coeff PowerSeries.constantCoeff
/-- The constant formal power series. -/
def C : R →+* R⟦X⟧ :=
MvPowerSeries.C Unit R
set_option linter.uppercaseLean3 false in
#align power_series.C PowerSeries.C
variable {R}
/-- The variable of the formal power series ring. -/
def X : R⟦X⟧ :=
MvPowerSeries.X ()
set_option linter.uppercaseLean3 false in
#align power_series.X PowerSeries.X
theorem commute_X (φ : R⟦X⟧) : Commute φ X :=
MvPowerSeries.commute_X _ _
set_option linter.uppercaseLean3 false in
#align power_series.commute_X PowerSeries.commute_X
@[simp]
theorem coeff_zero_eq_constantCoeff : ⇑(coeff R 0) = constantCoeff R := by
rw [coeff, Finsupp.single_zero]
rfl
#align power_series.coeff_zero_eq_constant_coeff PowerSeries.coeff_zero_eq_constantCoeff
theorem coeff_zero_eq_constantCoeff_apply (φ : R⟦X⟧) : coeff R 0 φ = constantCoeff R φ := by
rw [coeff_zero_eq_constantCoeff]
#align power_series.coeff_zero_eq_constant_coeff_apply PowerSeries.coeff_zero_eq_constantCoeff_apply
@[simp]
theorem monomial_zero_eq_C : ⇑(monomial R 0) = C R := by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [monomial, Finsupp.single_zero, MvPowerSeries.monomial_zero_eq_C]
set_option linter.uppercaseLean3 false in
#align power_series.monomial_zero_eq_C PowerSeries.monomial_zero_eq_C
theorem monomial_zero_eq_C_apply (a : R) : monomial R 0 a = C R a := by simp
set_option linter.uppercaseLean3 false in
#align power_series.monomial_zero_eq_C_apply PowerSeries.monomial_zero_eq_C_apply
theorem coeff_C (n : ℕ) (a : R) : coeff R n (C R a : R⟦X⟧) = if n = 0 then a else 0 := by
rw [← monomial_zero_eq_C_apply, coeff_monomial]
set_option linter.uppercaseLean3 false in
#align power_series.coeff_C PowerSeries.coeff_C
@[simp]
theorem coeff_zero_C (a : R) : coeff R 0 (C R a) = a := by
rw [coeff_C, if_pos rfl]
set_option linter.uppercaseLean3 false in
#align power_series.coeff_zero_C PowerSeries.coeff_zero_C
theorem coeff_ne_zero_C {a : R} {n : ℕ} (h : n ≠ 0) : coeff R n (C R a) = 0 := by
rw [coeff_C, if_neg h]
@[simp]
theorem coeff_succ_C {a : R} {n : ℕ} : coeff R (n + 1) (C R a) = 0 :=
coeff_ne_zero_C n.succ_ne_zero
theorem C_injective : Function.Injective (C R) := by
intro a b H
have := (ext_iff (φ := C R a) (ψ := C R b)).mp H 0
rwa [coeff_zero_C, coeff_zero_C] at this
protected theorem subsingleton_iff : Subsingleton R⟦X⟧ ↔ Subsingleton R := by
refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩
rw [subsingleton_iff] at h ⊢
exact fun a b ↦ C_injective (h (C R a) (C R b))
theorem X_eq : (X : R⟦X⟧) = monomial R 1 1 :=
rfl
set_option linter.uppercaseLean3 false in
#align power_series.X_eq PowerSeries.X_eq
theorem coeff_X (n : ℕ) : coeff R n (X : R⟦X⟧) = if n = 1 then 1 else 0 := by
rw [X_eq, coeff_monomial]
set_option linter.uppercaseLean3 false in
#align power_series.coeff_X PowerSeries.coeff_X
@[simp]
theorem coeff_zero_X : coeff R 0 (X : R⟦X⟧) = 0 := by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [coeff, Finsupp.single_zero, X, MvPowerSeries.coeff_zero_X]
set_option linter.uppercaseLean3 false in
#align power_series.coeff_zero_X PowerSeries.coeff_zero_X
@[simp]
theorem coeff_one_X : coeff R 1 (X : R⟦X⟧) = 1 := by rw [coeff_X, if_pos rfl]
set_option linter.uppercaseLean3 false in
#align power_series.coeff_one_X PowerSeries.coeff_one_X
@[simp]
theorem X_ne_zero [Nontrivial R] : (X : R⟦X⟧) ≠ 0 := fun H => by
simpa only [coeff_one_X, one_ne_zero, map_zero] using congr_arg (coeff R 1) H
set_option linter.uppercaseLean3 false in
#align power_series.X_ne_zero PowerSeries.X_ne_zero
theorem X_pow_eq (n : ℕ) : (X : R⟦X⟧) ^ n = monomial R n 1 :=
MvPowerSeries.X_pow_eq _ n
set_option linter.uppercaseLean3 false in
#align power_series.X_pow_eq PowerSeries.X_pow_eq
theorem coeff_X_pow (m n : ℕ) : coeff R m ((X : R⟦X⟧) ^ n) = if m = n then 1 else 0 := by
rw [X_pow_eq, coeff_monomial]
set_option linter.uppercaseLean3 false in
#align power_series.coeff_X_pow PowerSeries.coeff_X_pow
@[simp]
theorem coeff_X_pow_self (n : ℕ) : coeff R n ((X : R⟦X⟧) ^ n) = 1 := by
rw [coeff_X_pow, if_pos rfl]
set_option linter.uppercaseLean3 false in
#align power_series.coeff_X_pow_self PowerSeries.coeff_X_pow_self
@[simp]
theorem coeff_one (n : ℕ) : coeff R n (1 : R⟦X⟧) = if n = 0 then 1 else 0 :=
coeff_C n 1
#align power_series.coeff_one PowerSeries.coeff_one
theorem coeff_zero_one : coeff R 0 (1 : R⟦X⟧) = 1 :=
coeff_zero_C 1
#align power_series.coeff_zero_one PowerSeries.coeff_zero_one
theorem coeff_mul (n : ℕ) (φ ψ : R⟦X⟧) :
coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by
-- `rw` can't see that `PowerSeries = MvPowerSeries Unit`, so use `.trans`
refine (MvPowerSeries.coeff_mul _ φ ψ).trans ?_
rw [Finsupp.antidiagonal_single, Finset.sum_map]
rfl
#align power_series.coeff_mul PowerSeries.coeff_mul
@[simp]
theorem coeff_mul_C (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (φ * C R a) = coeff R n φ * a :=
MvPowerSeries.coeff_mul_C _ φ a
set_option linter.uppercaseLean3 false in
#align power_series.coeff_mul_C PowerSeries.coeff_mul_C
@[simp]
theorem coeff_C_mul (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (C R a * φ) = a * coeff R n φ :=
MvPowerSeries.coeff_C_mul _ φ a
set_option linter.uppercaseLean3 false in
#align power_series.coeff_C_mul PowerSeries.coeff_C_mul
@[simp]
theorem coeff_smul {S : Type*} [Semiring S] [Module R S] (n : ℕ) (φ : PowerSeries S) (a : R) :
coeff S n (a • φ) = a • coeff S n φ :=
rfl
#align power_series.coeff_smul PowerSeries.coeff_smul
@[simp]
theorem constantCoeff_smul {S : Type*} [Semiring S] [Module R S] (φ : PowerSeries S) (a : R) :
constantCoeff S (a • φ) = a • constantCoeff S φ :=
rfl
theorem smul_eq_C_mul (f : R⟦X⟧) (a : R) : a • f = C R a * f := by
ext
simp
set_option linter.uppercaseLean3 false in
#align power_series.smul_eq_C_mul PowerSeries.smul_eq_C_mul
@[simp]
theorem coeff_succ_mul_X (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (φ * X) = coeff R n φ := by
simp only [coeff, Finsupp.single_add]
convert φ.coeff_add_mul_monomial (single () n) (single () 1) _
rw [mul_one]; rfl
set_option linter.uppercaseLean3 false in
#align power_series.coeff_succ_mul_X PowerSeries.coeff_succ_mul_X
@[simp]
| Mathlib/RingTheory/PowerSeries/Basic.lean | 376 | 379 | theorem coeff_succ_X_mul (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (X * φ) = coeff R n φ := by |
simp only [coeff, Finsupp.single_add, add_comm n 1]
convert φ.coeff_add_monomial_mul (single () 1) (single () n) _
rw [one_mul]; rfl
|
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.Measure.MeasureSpace
import Mathlib.MeasureTheory.Measure.Regular
import Mathlib.Topology.Sets.Compacts
#align_import measure_theory.measure.content from "leanprover-community/mathlib"@"d39590fc8728fbf6743249802486f8c91ffe07bc"
/-!
# Contents
In this file we work with *contents*. A content `λ` is a function from a certain class of subsets
(such as the compact subsets) to `ℝ≥0` that is
* additive: If `K₁` and `K₂` are disjoint sets in the domain of `λ`,
then `λ(K₁ ∪ K₂) = λ(K₁) + λ(K₂)`;
* subadditive: If `K₁` and `K₂` are in the domain of `λ`, then `λ(K₁ ∪ K₂) ≤ λ(K₁) + λ(K₂)`;
* monotone: If `K₁ ⊆ K₂` are in the domain of `λ`, then `λ(K₁) ≤ λ(K₂)`.
We show that:
* Given a content `λ` on compact sets, let us define a function `λ*` on open sets, by letting
`λ* U` be the supremum of `λ K` for `K` included in `U`. This is a countably subadditive map that
vanishes at `∅`. In Halmos (1950) this is called the *inner content* `λ*` of `λ`, and formalized
as `innerContent`.
* Given an inner content, we define an outer measure `μ*`, by letting `μ* E` be the infimum of
`λ* U` over the open sets `U` containing `E`. This is indeed an outer measure. It is formalized
as `outerMeasure`.
* Restricting this outer measure to Borel sets gives a regular measure `μ`.
We define bundled contents as `Content`.
In this file we only work on contents on compact sets, and inner contents on open sets, and both
contents and inner contents map into the extended nonnegative reals. However, in other applications
other choices can be made, and it is not a priori clear what the best interface should be.
## Main definitions
For `μ : Content G`, we define
* `μ.innerContent` : the inner content associated to `μ`.
* `μ.outerMeasure` : the outer measure associated to `μ`.
* `μ.measure` : the Borel measure associated to `μ`.
These definitions are given for spaces which are R₁.
The resulting measure `μ.measure` is always outer regular by design.
When the space is locally compact, `μ.measure` is also regular.
## References
* Paul Halmos (1950), Measure Theory, §53
* <https://en.wikipedia.org/wiki/Content_(measure_theory)>
-/
universe u v w
noncomputable section
open Set TopologicalSpace
open NNReal ENNReal MeasureTheory
namespace MeasureTheory
variable {G : Type w} [TopologicalSpace G]
/-- A content is an additive function on compact sets taking values in `ℝ≥0`. It is a device
from which one can define a measure. -/
structure Content (G : Type w) [TopologicalSpace G] where
toFun : Compacts G → ℝ≥0
mono' : ∀ K₁ K₂ : Compacts G, (K₁ : Set G) ⊆ K₂ → toFun K₁ ≤ toFun K₂
sup_disjoint' :
∀ K₁ K₂ : Compacts G, Disjoint (K₁ : Set G) K₂ → IsClosed (K₁ : Set G) → IsClosed (K₂ : Set G)
→ toFun (K₁ ⊔ K₂) = toFun K₁ + toFun K₂
sup_le' : ∀ K₁ K₂ : Compacts G, toFun (K₁ ⊔ K₂) ≤ toFun K₁ + toFun K₂
#align measure_theory.content MeasureTheory.Content
instance : Inhabited (Content G) :=
⟨{ toFun := fun _ => 0
mono' := by simp
sup_disjoint' := by simp
sup_le' := by simp }⟩
/-- Although the `toFun` field of a content takes values in `ℝ≥0`, we register a coercion to
functions taking values in `ℝ≥0∞` as most constructions below rely on taking iSups and iInfs, which
is more convenient in a complete lattice, and aim at constructing a measure. -/
instance : CoeFun (Content G) fun _ => Compacts G → ℝ≥0∞ :=
⟨fun μ s => μ.toFun s⟩
namespace Content
variable (μ : Content G)
theorem apply_eq_coe_toFun (K : Compacts G) : μ K = μ.toFun K :=
rfl
#align measure_theory.content.apply_eq_coe_to_fun MeasureTheory.Content.apply_eq_coe_toFun
theorem mono (K₁ K₂ : Compacts G) (h : (K₁ : Set G) ⊆ K₂) : μ K₁ ≤ μ K₂ := by
simp [apply_eq_coe_toFun, μ.mono' _ _ h]
#align measure_theory.content.mono MeasureTheory.Content.mono
theorem sup_disjoint (K₁ K₂ : Compacts G) (h : Disjoint (K₁ : Set G) K₂)
(h₁ : IsClosed (K₁ : Set G)) (h₂ : IsClosed (K₂ : Set G)) :
μ (K₁ ⊔ K₂) = μ K₁ + μ K₂ := by
simp [apply_eq_coe_toFun, μ.sup_disjoint' _ _ h]
#align measure_theory.content.sup_disjoint MeasureTheory.Content.sup_disjoint
theorem sup_le (K₁ K₂ : Compacts G) : μ (K₁ ⊔ K₂) ≤ μ K₁ + μ K₂ := by
simp only [apply_eq_coe_toFun]
norm_cast
exact μ.sup_le' _ _
#align measure_theory.content.sup_le MeasureTheory.Content.sup_le
theorem lt_top (K : Compacts G) : μ K < ∞ :=
ENNReal.coe_lt_top
#align measure_theory.content.lt_top MeasureTheory.Content.lt_top
theorem empty : μ ⊥ = 0 := by
have := μ.sup_disjoint' ⊥ ⊥
simpa [apply_eq_coe_toFun] using this
#align measure_theory.content.empty MeasureTheory.Content.empty
/-- Constructing the inner content of a content. From a content defined on the compact sets, we
obtain a function defined on all open sets, by taking the supremum of the content of all compact
subsets. -/
def innerContent (U : Opens G) : ℝ≥0∞ :=
⨆ (K : Compacts G) (_ : (K : Set G) ⊆ U), μ K
#align measure_theory.content.inner_content MeasureTheory.Content.innerContent
theorem le_innerContent (K : Compacts G) (U : Opens G) (h2 : (K : Set G) ⊆ U) :
μ K ≤ μ.innerContent U :=
le_iSup_of_le K <| le_iSup (fun _ ↦ (μ.toFun K : ℝ≥0∞)) h2
#align measure_theory.content.le_inner_content MeasureTheory.Content.le_innerContent
theorem innerContent_le (U : Opens G) (K : Compacts G) (h2 : (U : Set G) ⊆ K) :
μ.innerContent U ≤ μ K :=
iSup₂_le fun _ hK' => μ.mono _ _ (Subset.trans hK' h2)
#align measure_theory.content.inner_content_le MeasureTheory.Content.innerContent_le
theorem innerContent_of_isCompact {K : Set G} (h1K : IsCompact K) (h2K : IsOpen K) :
μ.innerContent ⟨K, h2K⟩ = μ ⟨K, h1K⟩ :=
le_antisymm (iSup₂_le fun _ hK' => μ.mono _ ⟨K, h1K⟩ hK') (μ.le_innerContent _ _ Subset.rfl)
#align measure_theory.content.inner_content_of_is_compact MeasureTheory.Content.innerContent_of_isCompact
theorem innerContent_bot : μ.innerContent ⊥ = 0 := by
refine le_antisymm ?_ (zero_le _)
rw [← μ.empty]
refine iSup₂_le fun K hK => ?_
have : K = ⊥ := by
ext1
rw [subset_empty_iff.mp hK, Compacts.coe_bot]
rw [this]
#align measure_theory.content.inner_content_bot MeasureTheory.Content.innerContent_bot
/-- This is "unbundled", because that is required for the API of `inducedOuterMeasure`. -/
theorem innerContent_mono ⦃U V : Set G⦄ (hU : IsOpen U) (hV : IsOpen V) (h2 : U ⊆ V) :
μ.innerContent ⟨U, hU⟩ ≤ μ.innerContent ⟨V, hV⟩ :=
biSup_mono fun _ hK => hK.trans h2
#align measure_theory.content.inner_content_mono MeasureTheory.Content.innerContent_mono
theorem innerContent_exists_compact {U : Opens G} (hU : μ.innerContent U ≠ ∞) {ε : ℝ≥0}
(hε : ε ≠ 0) : ∃ K : Compacts G, (K : Set G) ⊆ U ∧ μ.innerContent U ≤ μ K + ε := by
have h'ε := ENNReal.coe_ne_zero.2 hε
rcases le_or_lt (μ.innerContent U) ε with h | h
· exact ⟨⊥, empty_subset _, le_add_left h⟩
have h₂ := ENNReal.sub_lt_self hU h.ne_bot h'ε
conv at h₂ => rhs; rw [innerContent]
simp only [lt_iSup_iff] at h₂
rcases h₂ with ⟨U, h1U, h2U⟩; refine ⟨U, h1U, ?_⟩
rw [← tsub_le_iff_right]; exact le_of_lt h2U
#align measure_theory.content.inner_content_exists_compact MeasureTheory.Content.innerContent_exists_compact
/-- The inner content of a supremum of opens is at most the sum of the individual inner contents. -/
theorem innerContent_iSup_nat [R1Space G] (U : ℕ → Opens G) :
μ.innerContent (⨆ i : ℕ, U i) ≤ ∑' i : ℕ, μ.innerContent (U i) := by
have h3 : ∀ (t : Finset ℕ) (K : ℕ → Compacts G), μ (t.sup K) ≤ t.sum fun i => μ (K i) := by
intro t K
refine Finset.induction_on t ?_ ?_
· simp only [μ.empty, nonpos_iff_eq_zero, Finset.sum_empty, Finset.sup_empty]
· intro n s hn ih
rw [Finset.sup_insert, Finset.sum_insert hn]
exact le_trans (μ.sup_le _ _) (add_le_add_left ih _)
refine iSup₂_le fun K hK => ?_
obtain ⟨t, ht⟩ :=
K.isCompact.elim_finite_subcover _ (fun i => (U i).isOpen) (by rwa [← Opens.coe_iSup])
rcases K.isCompact.finite_compact_cover t (SetLike.coe ∘ U) (fun i _ => (U i).isOpen) ht with
⟨K', h1K', h2K', h3K'⟩
let L : ℕ → Compacts G := fun n => ⟨K' n, h1K' n⟩
convert le_trans (h3 t L) _
· ext1
rw [Compacts.coe_finset_sup, Finset.sup_eq_iSup]
exact h3K'
refine le_trans (Finset.sum_le_sum ?_) (ENNReal.sum_le_tsum t)
intro i _
refine le_trans ?_ (le_iSup _ (L i))
refine le_trans ?_ (le_iSup _ (h2K' i))
rfl
#align measure_theory.content.inner_content_Sup_nat MeasureTheory.Content.innerContent_iSup_nat
/-- The inner content of a union of sets is at most the sum of the individual inner contents.
This is the "unbundled" version of `innerContent_iSup_nat`.
It is required for the API of `inducedOuterMeasure`. -/
theorem innerContent_iUnion_nat [R1Space G] ⦃U : ℕ → Set G⦄
(hU : ∀ i : ℕ, IsOpen (U i)) :
μ.innerContent ⟨⋃ i : ℕ, U i, isOpen_iUnion hU⟩ ≤ ∑' i : ℕ, μ.innerContent ⟨U i, hU i⟩ := by
have := μ.innerContent_iSup_nat fun i => ⟨U i, hU i⟩
rwa [Opens.iSup_def] at this
#align measure_theory.content.inner_content_Union_nat MeasureTheory.Content.innerContent_iUnion_nat
theorem innerContent_comap (f : G ≃ₜ G) (h : ∀ ⦃K : Compacts G⦄, μ (K.map f f.continuous) = μ K)
(U : Opens G) : μ.innerContent (Opens.comap f.toContinuousMap U) = μ.innerContent U := by
refine (Compacts.equiv f).surjective.iSup_congr _ fun K => iSup_congr_Prop image_subset_iff ?_
intro hK
simp only [Equiv.coe_fn_mk, Subtype.mk_eq_mk, Compacts.equiv]
apply h
#align measure_theory.content.inner_content_comap MeasureTheory.Content.innerContent_comap
@[to_additive]
| Mathlib/MeasureTheory/Measure/Content.lean | 219 | 223 | theorem is_mul_left_invariant_innerContent [Group G] [TopologicalGroup G]
(h : ∀ (g : G) {K : Compacts G}, μ (K.map _ <| continuous_mul_left g) = μ K) (g : G)
(U : Opens G) :
μ.innerContent (Opens.comap (Homeomorph.mulLeft g).toContinuousMap U) = μ.innerContent U := by |
convert μ.innerContent_comap (Homeomorph.mulLeft g) (fun K => h g) U
|
/-
Copyright (c) 2018 Violeta Hernández Palacios, Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios, Mario Carneiro
-/
import Mathlib.SetTheory.Ordinal.Arithmetic
import Mathlib.SetTheory.Ordinal.Exponential
#align_import set_theory.ordinal.fixed_point from "leanprover-community/mathlib"@"0dd4319a17376eda5763cd0a7e0d35bbaaa50e83"
/-!
# Fixed points of normal functions
We prove various statements about the fixed points of normal ordinal functions. We state them in
three forms: as statements about type-indexed families of normal functions, as statements about
ordinal-indexed families of normal functions, and as statements about a single normal function. For
the most part, the first case encompasses the others.
Moreover, we prove some lemmas about the fixed points of specific normal functions.
## Main definitions and results
* `nfpFamily`, `nfpBFamily`, `nfp`: the next fixed point of a (family of) normal function(s).
* `fp_family_unbounded`, `fp_bfamily_unbounded`, `fp_unbounded`: the (common) fixed points of a
(family of) normal function(s) are unbounded in the ordinals.
* `deriv_add_eq_mul_omega_add`: a characterization of the derivative of addition.
* `deriv_mul_eq_opow_omega_mul`: a characterization of the derivative of multiplication.
-/
noncomputable section
universe u v
open Function Order
namespace Ordinal
/-! ### Fixed points of type-indexed families of ordinals -/
section
variable {ι : Type u} {f : ι → Ordinal.{max u v} → Ordinal.{max u v}}
/-- The next common fixed point, at least `a`, for a family of normal functions.
This is defined for any family of functions, as the supremum of all values reachable by applying
finitely many functions in the family to `a`.
`Ordinal.nfpFamily_fp` shows this is a fixed point, `Ordinal.le_nfpFamily` shows it's at
least `a`, and `Ordinal.nfpFamily_le_fp` shows this is the least ordinal with these properties. -/
def nfpFamily (f : ι → Ordinal → Ordinal) (a : Ordinal) : Ordinal :=
sup (List.foldr f a)
#align ordinal.nfp_family Ordinal.nfpFamily
theorem nfpFamily_eq_sup (f : ι → Ordinal.{max u v} → Ordinal.{max u v}) (a : Ordinal.{max u v}) :
nfpFamily.{u, v} f a = sup.{u, v} (List.foldr f a) :=
rfl
#align ordinal.nfp_family_eq_sup Ordinal.nfpFamily_eq_sup
theorem foldr_le_nfpFamily (f : ι → Ordinal → Ordinal)
(a l) : List.foldr f a l ≤ nfpFamily.{u, v} f a :=
le_sup.{u, v} _ _
#align ordinal.foldr_le_nfp_family Ordinal.foldr_le_nfpFamily
theorem le_nfpFamily (f : ι → Ordinal → Ordinal) (a) : a ≤ nfpFamily f a :=
le_sup _ []
#align ordinal.le_nfp_family Ordinal.le_nfpFamily
theorem lt_nfpFamily {a b} : a < nfpFamily.{u, v} f b ↔ ∃ l, a < List.foldr f b l :=
lt_sup.{u, v}
#align ordinal.lt_nfp_family Ordinal.lt_nfpFamily
theorem nfpFamily_le_iff {a b} : nfpFamily.{u, v} f a ≤ b ↔ ∀ l, List.foldr f a l ≤ b :=
sup_le_iff
#align ordinal.nfp_family_le_iff Ordinal.nfpFamily_le_iff
theorem nfpFamily_le {a b} : (∀ l, List.foldr f a l ≤ b) → nfpFamily.{u, v} f a ≤ b :=
sup_le.{u, v}
#align ordinal.nfp_family_le Ordinal.nfpFamily_le
theorem nfpFamily_monotone (hf : ∀ i, Monotone (f i)) : Monotone (nfpFamily.{u, v} f) :=
fun _ _ h => sup_le.{u, v} fun l => (List.foldr_monotone hf l h).trans (le_sup.{u, v} _ l)
#align ordinal.nfp_family_monotone Ordinal.nfpFamily_monotone
theorem apply_lt_nfpFamily (H : ∀ i, IsNormal (f i)) {a b} (hb : b < nfpFamily.{u, v} f a) (i) :
f i b < nfpFamily.{u, v} f a :=
let ⟨l, hl⟩ := lt_nfpFamily.1 hb
lt_sup.2 ⟨i::l, (H i).strictMono hl⟩
#align ordinal.apply_lt_nfp_family Ordinal.apply_lt_nfpFamily
theorem apply_lt_nfpFamily_iff [Nonempty ι] (H : ∀ i, IsNormal (f i)) {a b} :
(∀ i, f i b < nfpFamily.{u, v} f a) ↔ b < nfpFamily.{u, v} f a :=
⟨fun h =>
lt_nfpFamily.2 <|
let ⟨l, hl⟩ := lt_sup.1 <| h <| Classical.arbitrary ι
⟨l, ((H _).self_le b).trans_lt hl⟩,
apply_lt_nfpFamily H⟩
#align ordinal.apply_lt_nfp_family_iff Ordinal.apply_lt_nfpFamily_iff
theorem nfpFamily_le_apply [Nonempty ι] (H : ∀ i, IsNormal (f i)) {a b} :
(∃ i, nfpFamily.{u, v} f a ≤ f i b) ↔ nfpFamily.{u, v} f a ≤ b := by
rw [← not_iff_not]
push_neg
exact apply_lt_nfpFamily_iff H
#align ordinal.nfp_family_le_apply Ordinal.nfpFamily_le_apply
theorem nfpFamily_le_fp (H : ∀ i, Monotone (f i)) {a b} (ab : a ≤ b) (h : ∀ i, f i b ≤ b) :
nfpFamily.{u, v} f a ≤ b :=
sup_le fun l => by
by_cases hι : IsEmpty ι
· rwa [Unique.eq_default l]
· induction' l with i l IH generalizing a
· exact ab
exact (H i (IH ab)).trans (h i)
#align ordinal.nfp_family_le_fp Ordinal.nfpFamily_le_fp
theorem nfpFamily_fp {i} (H : IsNormal (f i)) (a) :
f i (nfpFamily.{u, v} f a) = nfpFamily.{u, v} f a := by
unfold nfpFamily
rw [@IsNormal.sup.{u, v, v} _ H _ _ ⟨[]⟩]
apply le_antisymm <;> refine Ordinal.sup_le fun l => ?_
· exact le_sup _ (i::l)
· exact (H.self_le _).trans (le_sup _ _)
#align ordinal.nfp_family_fp Ordinal.nfpFamily_fp
theorem apply_le_nfpFamily [hι : Nonempty ι] {f : ι → Ordinal → Ordinal} (H : ∀ i, IsNormal (f i))
{a b} : (∀ i, f i b ≤ nfpFamily.{u, v} f a) ↔ b ≤ nfpFamily.{u, v} f a := by
refine ⟨fun h => ?_, fun h i => ?_⟩
· cases' hι with i
exact ((H i).self_le b).trans (h i)
rw [← nfpFamily_fp (H i)]
exact (H i).monotone h
#align ordinal.apply_le_nfp_family Ordinal.apply_le_nfpFamily
theorem nfpFamily_eq_self {f : ι → Ordinal → Ordinal} {a} (h : ∀ i, f i a = a) :
nfpFamily f a = a :=
le_antisymm (sup_le fun l => by rw [List.foldr_fixed' h l]) <| le_nfpFamily f a
#align ordinal.nfp_family_eq_self Ordinal.nfpFamily_eq_self
-- Todo: This is actually a special case of the fact the intersection of club sets is a club set.
/-- A generalization of the fixed point lemma for normal functions: any family of normal functions
has an unbounded set of common fixed points. -/
theorem fp_family_unbounded (H : ∀ i, IsNormal (f i)) :
(⋂ i, Function.fixedPoints (f i)).Unbounded (· < ·) := fun a =>
⟨nfpFamily.{u, v} f a, fun s ⟨i, hi⟩ => by
rw [← hi, mem_fixedPoints_iff]
exact nfpFamily_fp.{u, v} (H i) a, (le_nfpFamily f a).not_lt⟩
#align ordinal.fp_family_unbounded Ordinal.fp_family_unbounded
/-- The derivative of a family of normal functions is the sequence of their common fixed points.
This is defined for all functions such that `Ordinal.derivFamily_zero`,
`Ordinal.derivFamily_succ`, and `Ordinal.derivFamily_limit` are satisfied. -/
def derivFamily (f : ι → Ordinal → Ordinal) (o : Ordinal) : Ordinal :=
limitRecOn o (nfpFamily.{u, v} f 0) (fun _ IH => nfpFamily.{u, v} f (succ IH))
fun a _ => bsup.{max u v, u} a
#align ordinal.deriv_family Ordinal.derivFamily
@[simp]
theorem derivFamily_zero (f : ι → Ordinal → Ordinal) :
derivFamily.{u, v} f 0 = nfpFamily.{u, v} f 0 :=
limitRecOn_zero _ _ _
#align ordinal.deriv_family_zero Ordinal.derivFamily_zero
@[simp]
theorem derivFamily_succ (f : ι → Ordinal → Ordinal) (o) :
derivFamily.{u, v} f (succ o) = nfpFamily.{u, v} f (succ (derivFamily.{u, v} f o)) :=
limitRecOn_succ _ _ _ _
#align ordinal.deriv_family_succ Ordinal.derivFamily_succ
theorem derivFamily_limit (f : ι → Ordinal → Ordinal) {o} :
IsLimit o → derivFamily.{u, v} f o = bsup.{max u v, u} o fun a _ => derivFamily.{u, v} f a :=
limitRecOn_limit _ _ _ _
#align ordinal.deriv_family_limit Ordinal.derivFamily_limit
theorem derivFamily_isNormal (f : ι → Ordinal → Ordinal) : IsNormal (derivFamily f) :=
⟨fun o => by rw [derivFamily_succ, ← succ_le_iff]; apply le_nfpFamily, fun o l a => by
rw [derivFamily_limit _ l, bsup_le_iff]⟩
#align ordinal.deriv_family_is_normal Ordinal.derivFamily_isNormal
theorem derivFamily_fp {i} (H : IsNormal (f i)) (o : Ordinal.{max u v}) :
f i (derivFamily.{u, v} f o) = derivFamily.{u, v} f o := by
induction' o using limitRecOn with o _ o l IH
· rw [derivFamily_zero]
exact nfpFamily_fp H 0
· rw [derivFamily_succ]
exact nfpFamily_fp H _
· rw [derivFamily_limit _ l,
IsNormal.bsup.{max u v, u, max u v} H (fun a _ => derivFamily f a) l.1]
refine eq_of_forall_ge_iff fun c => ?_
simp (config := { contextual := true }) only [bsup_le_iff, IH]
#align ordinal.deriv_family_fp Ordinal.derivFamily_fp
theorem le_iff_derivFamily (H : ∀ i, IsNormal (f i)) {a} :
(∀ i, f i a ≤ a) ↔ ∃ o, derivFamily.{u, v} f o = a :=
⟨fun ha => by
suffices ∀ (o) (_ : a ≤ derivFamily.{u, v} f o), ∃ o, derivFamily.{u, v} f o = a from
this a ((derivFamily_isNormal _).self_le _)
intro o
induction' o using limitRecOn with o IH o l IH
· intro h₁
refine ⟨0, le_antisymm ?_ h₁⟩
rw [derivFamily_zero]
exact nfpFamily_le_fp (fun i => (H i).monotone) (Ordinal.zero_le _) ha
· intro h₁
rcases le_or_lt a (derivFamily.{u, v} f o) with h | h
· exact IH h
refine ⟨succ o, le_antisymm ?_ h₁⟩
rw [derivFamily_succ]
exact nfpFamily_le_fp (fun i => (H i).monotone) (succ_le_of_lt h) ha
· intro h₁
cases' eq_or_lt_of_le h₁ with h h
· exact ⟨_, h.symm⟩
rw [derivFamily_limit _ l, ← not_le, bsup_le_iff, not_forall₂] at h
exact
let ⟨o', h, hl⟩ := h
IH o' h (le_of_not_le hl),
fun ⟨o, e⟩ i => e ▸ (derivFamily_fp (H i) _).le⟩
#align ordinal.le_iff_deriv_family Ordinal.le_iff_derivFamily
theorem fp_iff_derivFamily (H : ∀ i, IsNormal (f i)) {a} :
(∀ i, f i a = a) ↔ ∃ o, derivFamily.{u, v} f o = a :=
Iff.trans ⟨fun h i => le_of_eq (h i), fun h i => (H i).le_iff_eq.1 (h i)⟩ (le_iff_derivFamily H)
#align ordinal.fp_iff_deriv_family Ordinal.fp_iff_derivFamily
/-- For a family of normal functions, `Ordinal.derivFamily` enumerates the common fixed points. -/
theorem derivFamily_eq_enumOrd (H : ∀ i, IsNormal (f i)) :
derivFamily.{u, v} f = enumOrd (⋂ i, Function.fixedPoints (f i)) := by
rw [← eq_enumOrd _ (fp_family_unbounded.{u, v} H)]
use (derivFamily_isNormal f).strictMono
rw [Set.range_eq_iff]
refine ⟨?_, fun a ha => ?_⟩
· rintro a S ⟨i, hi⟩
rw [← hi]
exact derivFamily_fp (H i) a
rw [Set.mem_iInter] at ha
rwa [← fp_iff_derivFamily H]
#align ordinal.deriv_family_eq_enum_ord Ordinal.derivFamily_eq_enumOrd
end
/-! ### Fixed points of ordinal-indexed families of ordinals -/
section
variable {o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{max u v} → Ordinal.{max u v}}
/-- The next common fixed point, at least `a`, for a family of normal functions indexed by ordinals.
This is defined as `Ordinal.nfpFamily` of the type-indexed family associated to `f`. -/
def nfpBFamily (o : Ordinal) (f : ∀ b < o, Ordinal → Ordinal) : Ordinal → Ordinal :=
nfpFamily (familyOfBFamily o f)
#align ordinal.nfp_bfamily Ordinal.nfpBFamily
theorem nfpBFamily_eq_nfpFamily {o : Ordinal} (f : ∀ b < o, Ordinal → Ordinal) :
nfpBFamily.{u, v} o f = nfpFamily.{u, v} (familyOfBFamily o f) :=
rfl
#align ordinal.nfp_bfamily_eq_nfp_family Ordinal.nfpBFamily_eq_nfpFamily
theorem foldr_le_nfpBFamily {o : Ordinal}
(f : ∀ b < o, Ordinal → Ordinal) (a l) :
List.foldr (familyOfBFamily o f) a l ≤ nfpBFamily.{u, v} o f a :=
le_sup.{u, v} _ _
#align ordinal.foldr_le_nfp_bfamily Ordinal.foldr_le_nfpBFamily
theorem le_nfpBFamily {o : Ordinal} (f : ∀ b < o, Ordinal → Ordinal) (a) :
a ≤ nfpBFamily.{u, v} o f a :=
le_sup.{u, v} _ []
#align ordinal.le_nfp_bfamily Ordinal.le_nfpBFamily
theorem lt_nfpBFamily {a b} :
a < nfpBFamily.{u, v} o f b ↔ ∃ l, a < List.foldr (familyOfBFamily o f) b l :=
lt_sup.{u, v}
#align ordinal.lt_nfp_bfamily Ordinal.lt_nfpBFamily
theorem nfpBFamily_le_iff {o : Ordinal} {f : ∀ b < o, Ordinal → Ordinal} {a b} :
nfpBFamily.{u, v} o f a ≤ b ↔ ∀ l, List.foldr (familyOfBFamily o f) a l ≤ b :=
sup_le_iff.{u, v}
#align ordinal.nfp_bfamily_le_iff Ordinal.nfpBFamily_le_iff
theorem nfpBFamily_le {o : Ordinal} {f : ∀ b < o, Ordinal → Ordinal} {a b} :
(∀ l, List.foldr (familyOfBFamily o f) a l ≤ b) → nfpBFamily.{u, v} o f a ≤ b :=
sup_le.{u, v}
#align ordinal.nfp_bfamily_le Ordinal.nfpBFamily_le
theorem nfpBFamily_monotone (hf : ∀ i hi, Monotone (f i hi)) : Monotone (nfpBFamily.{u, v} o f) :=
nfpFamily_monotone fun _ => hf _ _
#align ordinal.nfp_bfamily_monotone Ordinal.nfpBFamily_monotone
theorem apply_lt_nfpBFamily (H : ∀ i hi, IsNormal (f i hi)) {a b} (hb : b < nfpBFamily.{u, v} o f a)
(i hi) : f i hi b < nfpBFamily.{u, v} o f a := by
rw [← familyOfBFamily_enum o f]
apply apply_lt_nfpFamily (fun _ => H _ _) hb
#align ordinal.apply_lt_nfp_bfamily Ordinal.apply_lt_nfpBFamily
theorem apply_lt_nfpBFamily_iff (ho : o ≠ 0) (H : ∀ i hi, IsNormal (f i hi)) {a b} :
(∀ i hi, f i hi b < nfpBFamily.{u, v} o f a) ↔ b < nfpBFamily.{u, v} o f a :=
⟨fun h => by
haveI := out_nonempty_iff_ne_zero.2 ho
refine (apply_lt_nfpFamily_iff.{u, v} ?_).1 fun _ => h _ _
exact fun _ => H _ _, apply_lt_nfpBFamily H⟩
#align ordinal.apply_lt_nfp_bfamily_iff Ordinal.apply_lt_nfpBFamily_iff
theorem nfpBFamily_le_apply (ho : o ≠ 0) (H : ∀ i hi, IsNormal (f i hi)) {a b} :
(∃ i hi, nfpBFamily.{u, v} o f a ≤ f i hi b) ↔ nfpBFamily.{u, v} o f a ≤ b := by
rw [← not_iff_not]
push_neg
exact apply_lt_nfpBFamily_iff.{u, v} ho H
#align ordinal.nfp_bfamily_le_apply Ordinal.nfpBFamily_le_apply
theorem nfpBFamily_le_fp (H : ∀ i hi, Monotone (f i hi)) {a b} (ab : a ≤ b)
(h : ∀ i hi, f i hi b ≤ b) : nfpBFamily.{u, v} o f a ≤ b :=
nfpFamily_le_fp (fun _ => H _ _) ab fun _ => h _ _
#align ordinal.nfp_bfamily_le_fp Ordinal.nfpBFamily_le_fp
theorem nfpBFamily_fp {i hi} (H : IsNormal (f i hi)) (a) :
f i hi (nfpBFamily.{u, v} o f a) = nfpBFamily.{u, v} o f a := by
rw [← familyOfBFamily_enum o f]
apply nfpFamily_fp
rw [familyOfBFamily_enum]
exact H
#align ordinal.nfp_bfamily_fp Ordinal.nfpBFamily_fp
theorem apply_le_nfpBFamily (ho : o ≠ 0) (H : ∀ i hi, IsNormal (f i hi)) {a b} :
(∀ i hi, f i hi b ≤ nfpBFamily.{u, v} o f a) ↔ b ≤ nfpBFamily.{u, v} o f a := by
refine ⟨fun h => ?_, fun h i hi => ?_⟩
· have ho' : 0 < o := Ordinal.pos_iff_ne_zero.2 ho
exact ((H 0 ho').self_le b).trans (h 0 ho')
· rw [← nfpBFamily_fp (H i hi)]
exact (H i hi).monotone h
#align ordinal.apply_le_nfp_bfamily Ordinal.apply_le_nfpBFamily
theorem nfpBFamily_eq_self {a} (h : ∀ i hi, f i hi a = a) : nfpBFamily.{u, v} o f a = a :=
nfpFamily_eq_self fun _ => h _ _
#align ordinal.nfp_bfamily_eq_self Ordinal.nfpBFamily_eq_self
/-- A generalization of the fixed point lemma for normal functions: any family of normal functions
has an unbounded set of common fixed points. -/
theorem fp_bfamily_unbounded (H : ∀ i hi, IsNormal (f i hi)) :
(⋂ (i) (hi), Function.fixedPoints (f i hi)).Unbounded (· < ·) := fun a =>
⟨nfpBFamily.{u, v} _ f a, by
rw [Set.mem_iInter₂]
exact fun i hi => nfpBFamily_fp (H i hi) _, (le_nfpBFamily f a).not_lt⟩
#align ordinal.fp_bfamily_unbounded Ordinal.fp_bfamily_unbounded
/-- The derivative of a family of normal functions is the sequence of their common fixed points.
This is defined as `Ordinal.derivFamily` of the type-indexed family associated to `f`. -/
def derivBFamily (o : Ordinal) (f : ∀ b < o, Ordinal → Ordinal) : Ordinal → Ordinal :=
derivFamily (familyOfBFamily o f)
#align ordinal.deriv_bfamily Ordinal.derivBFamily
theorem derivBFamily_eq_derivFamily {o : Ordinal} (f : ∀ b < o, Ordinal → Ordinal) :
derivBFamily.{u, v} o f = derivFamily.{u, v} (familyOfBFamily o f) :=
rfl
#align ordinal.deriv_bfamily_eq_deriv_family Ordinal.derivBFamily_eq_derivFamily
theorem derivBFamily_isNormal {o : Ordinal} (f : ∀ b < o, Ordinal → Ordinal) :
IsNormal (derivBFamily o f) :=
derivFamily_isNormal _
#align ordinal.deriv_bfamily_is_normal Ordinal.derivBFamily_isNormal
theorem derivBFamily_fp {i hi} (H : IsNormal (f i hi)) (a : Ordinal) :
f i hi (derivBFamily.{u, v} o f a) = derivBFamily.{u, v} o f a := by
rw [← familyOfBFamily_enum o f]
apply derivFamily_fp
rw [familyOfBFamily_enum]
exact H
#align ordinal.deriv_bfamily_fp Ordinal.derivBFamily_fp
theorem le_iff_derivBFamily (H : ∀ i hi, IsNormal (f i hi)) {a} :
(∀ i hi, f i hi a ≤ a) ↔ ∃ b, derivBFamily.{u, v} o f b = a := by
unfold derivBFamily
rw [← le_iff_derivFamily]
· refine ⟨fun h i => h _ _, fun h i hi => ?_⟩
rw [← familyOfBFamily_enum o f]
apply h
· exact fun _ => H _ _
#align ordinal.le_iff_deriv_bfamily Ordinal.le_iff_derivBFamily
theorem fp_iff_derivBFamily (H : ∀ i hi, IsNormal (f i hi)) {a} :
(∀ i hi, f i hi a = a) ↔ ∃ b, derivBFamily.{u, v} o f b = a := by
rw [← le_iff_derivBFamily H]
refine ⟨fun h i hi => le_of_eq (h i hi), fun h i hi => ?_⟩
rw [← (H i hi).le_iff_eq]
exact h i hi
#align ordinal.fp_iff_deriv_bfamily Ordinal.fp_iff_derivBFamily
/-- For a family of normal functions, `Ordinal.derivBFamily` enumerates the common fixed points. -/
theorem derivBFamily_eq_enumOrd (H : ∀ i hi, IsNormal (f i hi)) :
derivBFamily.{u, v} o f = enumOrd (⋂ (i) (hi), Function.fixedPoints (f i hi)) := by
rw [← eq_enumOrd _ (fp_bfamily_unbounded.{u, v} H)]
use (derivBFamily_isNormal f).strictMono
rw [Set.range_eq_iff]
refine ⟨fun a => Set.mem_iInter₂.2 fun i hi => derivBFamily_fp (H i hi) a, fun a ha => ?_⟩
rw [Set.mem_iInter₂] at ha
rwa [← fp_iff_derivBFamily H]
#align ordinal.deriv_bfamily_eq_enum_ord Ordinal.derivBFamily_eq_enumOrd
end
/-! ### Fixed points of a single function -/
section
variable {f : Ordinal.{u} → Ordinal.{u}}
/-- The next fixed point function, the least fixed point of the normal function `f`, at least `a`.
This is defined as `ordinal.nfpFamily` applied to a family consisting only of `f`. -/
def nfp (f : Ordinal → Ordinal) : Ordinal → Ordinal :=
nfpFamily fun _ : Unit => f
#align ordinal.nfp Ordinal.nfp
theorem nfp_eq_nfpFamily (f : Ordinal → Ordinal) : nfp f = nfpFamily fun _ : Unit => f :=
rfl
#align ordinal.nfp_eq_nfp_family Ordinal.nfp_eq_nfpFamily
@[simp]
theorem sup_iterate_eq_nfp (f : Ordinal.{u} → Ordinal.{u}) :
(fun a => sup fun n : ℕ => f^[n] a) = nfp f := by
refine funext fun a => le_antisymm ?_ (sup_le fun l => ?_)
· rw [sup_le_iff]
intro n
rw [← List.length_replicate n Unit.unit, ← List.foldr_const f a]
apply le_sup
· rw [List.foldr_const f a l]
exact le_sup _ _
#align ordinal.sup_iterate_eq_nfp Ordinal.sup_iterate_eq_nfp
| Mathlib/SetTheory/Ordinal/FixedPoint.lean | 435 | 437 | theorem iterate_le_nfp (f a n) : f^[n] a ≤ nfp f a := by |
rw [← sup_iterate_eq_nfp]
exact le_sup _ n
|
/-
Copyright (c) 2018 Ellen Arlt. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang
-/
import Mathlib.Algebra.Algebra.Opposite
import Mathlib.Algebra.Algebra.Pi
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Algebra.BigOperators.RingEquiv
import Mathlib.Algebra.Module.LinearMap.Basic
import Mathlib.Algebra.Module.Pi
import Mathlib.Algebra.Star.BigOperators
import Mathlib.Algebra.Star.Module
import Mathlib.Algebra.Star.Pi
import Mathlib.Data.Fintype.BigOperators
import Mathlib.GroupTheory.GroupAction.BigOperators
#align_import data.matrix.basic from "leanprover-community/mathlib"@"eba5bb3155cab51d80af00e8d7d69fa271b1302b"
/-!
# Matrices
This file defines basic properties of matrices.
Matrices with rows indexed by `m`, columns indexed by `n`, and entries of type `α` are represented
with `Matrix m n α`. For the typical approach of counting rows and columns,
`Matrix (Fin m) (Fin n) α` can be used.
## Notation
The locale `Matrix` gives the following notation:
* `⬝ᵥ` for `Matrix.dotProduct`
* `*ᵥ` for `Matrix.mulVec`
* `ᵥ*` for `Matrix.vecMul`
* `ᵀ` for `Matrix.transpose`
* `ᴴ` for `Matrix.conjTranspose`
## Implementation notes
For convenience, `Matrix m n α` is defined as `m → n → α`, as this allows elements of the matrix
to be accessed with `A i j`. However, it is not advisable to _construct_ matrices using terms of the
form `fun i j ↦ _` or even `(fun i j ↦ _ : Matrix m n α)`, as these are not recognized by Lean
as having the right type. Instead, `Matrix.of` should be used.
## TODO
Under various conditions, multiplication of infinite matrices makes sense.
These have not yet been implemented.
-/
universe u u' v w
/-- `Matrix m n R` is the type of matrices with entries in `R`, whose rows are indexed by `m`
and whose columns are indexed by `n`. -/
def Matrix (m : Type u) (n : Type u') (α : Type v) : Type max u u' v :=
m → n → α
#align matrix Matrix
variable {l m n o : Type*} {m' : o → Type*} {n' : o → Type*}
variable {R : Type*} {S : Type*} {α : Type v} {β : Type w} {γ : Type*}
namespace Matrix
section Ext
variable {M N : Matrix m n α}
theorem ext_iff : (∀ i j, M i j = N i j) ↔ M = N :=
⟨fun h => funext fun i => funext <| h i, fun h => by simp [h]⟩
#align matrix.ext_iff Matrix.ext_iff
@[ext]
theorem ext : (∀ i j, M i j = N i j) → M = N :=
ext_iff.mp
#align matrix.ext Matrix.ext
end Ext
/-- Cast a function into a matrix.
The two sides of the equivalence are definitionally equal types. We want to use an explicit cast
to distinguish the types because `Matrix` has different instances to pi types (such as `Pi.mul`,
which performs elementwise multiplication, vs `Matrix.mul`).
If you are defining a matrix, in terms of its entries, use `of (fun i j ↦ _)`. The
purpose of this approach is to ensure that terms of the form `(fun i j ↦ _) * (fun i j ↦ _)` do not
appear, as the type of `*` can be misleading.
Porting note: In Lean 3, it is also safe to use pattern matching in a definition as `| i j := _`,
which can only be unfolded when fully-applied. leanprover/lean4#2042 means this does not
(currently) work in Lean 4.
-/
def of : (m → n → α) ≃ Matrix m n α :=
Equiv.refl _
#align matrix.of Matrix.of
@[simp]
theorem of_apply (f : m → n → α) (i j) : of f i j = f i j :=
rfl
#align matrix.of_apply Matrix.of_apply
@[simp]
theorem of_symm_apply (f : Matrix m n α) (i j) : of.symm f i j = f i j :=
rfl
#align matrix.of_symm_apply Matrix.of_symm_apply
/-- `M.map f` is the matrix obtained by applying `f` to each entry of the matrix `M`.
This is available in bundled forms as:
* `AddMonoidHom.mapMatrix`
* `LinearMap.mapMatrix`
* `RingHom.mapMatrix`
* `AlgHom.mapMatrix`
* `Equiv.mapMatrix`
* `AddEquiv.mapMatrix`
* `LinearEquiv.mapMatrix`
* `RingEquiv.mapMatrix`
* `AlgEquiv.mapMatrix`
-/
def map (M : Matrix m n α) (f : α → β) : Matrix m n β :=
of fun i j => f (M i j)
#align matrix.map Matrix.map
@[simp]
theorem map_apply {M : Matrix m n α} {f : α → β} {i : m} {j : n} : M.map f i j = f (M i j) :=
rfl
#align matrix.map_apply Matrix.map_apply
@[simp]
theorem map_id (M : Matrix m n α) : M.map id = M := by
ext
rfl
#align matrix.map_id Matrix.map_id
@[simp]
theorem map_id' (M : Matrix m n α) : M.map (·) = M := map_id M
@[simp]
theorem map_map {M : Matrix m n α} {β γ : Type*} {f : α → β} {g : β → γ} :
(M.map f).map g = M.map (g ∘ f) := by
ext
rfl
#align matrix.map_map Matrix.map_map
theorem map_injective {f : α → β} (hf : Function.Injective f) :
Function.Injective fun M : Matrix m n α => M.map f := fun _ _ h =>
ext fun i j => hf <| ext_iff.mpr h i j
#align matrix.map_injective Matrix.map_injective
/-- The transpose of a matrix. -/
def transpose (M : Matrix m n α) : Matrix n m α :=
of fun x y => M y x
#align matrix.transpose Matrix.transpose
-- TODO: set as an equation lemma for `transpose`, see mathlib4#3024
@[simp]
theorem transpose_apply (M : Matrix m n α) (i j) : transpose M i j = M j i :=
rfl
#align matrix.transpose_apply Matrix.transpose_apply
@[inherit_doc]
scoped postfix:1024 "ᵀ" => Matrix.transpose
/-- The conjugate transpose of a matrix defined in term of `star`. -/
def conjTranspose [Star α] (M : Matrix m n α) : Matrix n m α :=
M.transpose.map star
#align matrix.conj_transpose Matrix.conjTranspose
@[inherit_doc]
scoped postfix:1024 "ᴴ" => Matrix.conjTranspose
instance inhabited [Inhabited α] : Inhabited (Matrix m n α) :=
inferInstanceAs <| Inhabited <| m → n → α
-- Porting note: new, Lean3 found this automatically
instance decidableEq [DecidableEq α] [Fintype m] [Fintype n] : DecidableEq (Matrix m n α) :=
Fintype.decidablePiFintype
instance {n m} [Fintype m] [DecidableEq m] [Fintype n] [DecidableEq n] (α) [Fintype α] :
Fintype (Matrix m n α) := inferInstanceAs (Fintype (m → n → α))
instance {n m} [Finite m] [Finite n] (α) [Finite α] :
Finite (Matrix m n α) := inferInstanceAs (Finite (m → n → α))
instance add [Add α] : Add (Matrix m n α) :=
Pi.instAdd
instance addSemigroup [AddSemigroup α] : AddSemigroup (Matrix m n α) :=
Pi.addSemigroup
instance addCommSemigroup [AddCommSemigroup α] : AddCommSemigroup (Matrix m n α) :=
Pi.addCommSemigroup
instance zero [Zero α] : Zero (Matrix m n α) :=
Pi.instZero
instance addZeroClass [AddZeroClass α] : AddZeroClass (Matrix m n α) :=
Pi.addZeroClass
instance addMonoid [AddMonoid α] : AddMonoid (Matrix m n α) :=
Pi.addMonoid
instance addCommMonoid [AddCommMonoid α] : AddCommMonoid (Matrix m n α) :=
Pi.addCommMonoid
instance neg [Neg α] : Neg (Matrix m n α) :=
Pi.instNeg
instance sub [Sub α] : Sub (Matrix m n α) :=
Pi.instSub
instance addGroup [AddGroup α] : AddGroup (Matrix m n α) :=
Pi.addGroup
instance addCommGroup [AddCommGroup α] : AddCommGroup (Matrix m n α) :=
Pi.addCommGroup
instance unique [Unique α] : Unique (Matrix m n α) :=
Pi.unique
instance subsingleton [Subsingleton α] : Subsingleton (Matrix m n α) :=
inferInstanceAs <| Subsingleton <| m → n → α
instance nonempty [Nonempty m] [Nonempty n] [Nontrivial α] : Nontrivial (Matrix m n α) :=
Function.nontrivial
instance smul [SMul R α] : SMul R (Matrix m n α) :=
Pi.instSMul
instance smulCommClass [SMul R α] [SMul S α] [SMulCommClass R S α] :
SMulCommClass R S (Matrix m n α) :=
Pi.smulCommClass
instance isScalarTower [SMul R S] [SMul R α] [SMul S α] [IsScalarTower R S α] :
IsScalarTower R S (Matrix m n α) :=
Pi.isScalarTower
instance isCentralScalar [SMul R α] [SMul Rᵐᵒᵖ α] [IsCentralScalar R α] :
IsCentralScalar R (Matrix m n α) :=
Pi.isCentralScalar
instance mulAction [Monoid R] [MulAction R α] : MulAction R (Matrix m n α) :=
Pi.mulAction _
instance distribMulAction [Monoid R] [AddMonoid α] [DistribMulAction R α] :
DistribMulAction R (Matrix m n α) :=
Pi.distribMulAction _
instance module [Semiring R] [AddCommMonoid α] [Module R α] : Module R (Matrix m n α) :=
Pi.module _ _ _
-- Porting note (#10756): added the following section with simp lemmas because `simp` fails
-- to apply the corresponding lemmas in the namespace `Pi`.
-- (e.g. `Pi.zero_apply` used on `OfNat.ofNat 0 i j`)
section
@[simp]
theorem zero_apply [Zero α] (i : m) (j : n) : (0 : Matrix m n α) i j = 0 := rfl
@[simp]
theorem add_apply [Add α] (A B : Matrix m n α) (i : m) (j : n) :
(A + B) i j = (A i j) + (B i j) := rfl
@[simp]
theorem smul_apply [SMul β α] (r : β) (A : Matrix m n α) (i : m) (j : n) :
(r • A) i j = r • (A i j) := rfl
@[simp]
theorem sub_apply [Sub α] (A B : Matrix m n α) (i : m) (j : n) :
(A - B) i j = (A i j) - (B i j) := rfl
@[simp]
theorem neg_apply [Neg α] (A : Matrix m n α) (i : m) (j : n) :
(-A) i j = -(A i j) := rfl
end
/-! simp-normal form pulls `of` to the outside. -/
@[simp]
theorem of_zero [Zero α] : of (0 : m → n → α) = 0 :=
rfl
#align matrix.of_zero Matrix.of_zero
@[simp]
theorem of_add_of [Add α] (f g : m → n → α) : of f + of g = of (f + g) :=
rfl
#align matrix.of_add_of Matrix.of_add_of
@[simp]
theorem of_sub_of [Sub α] (f g : m → n → α) : of f - of g = of (f - g) :=
rfl
#align matrix.of_sub_of Matrix.of_sub_of
@[simp]
theorem neg_of [Neg α] (f : m → n → α) : -of f = of (-f) :=
rfl
#align matrix.neg_of Matrix.neg_of
@[simp]
theorem smul_of [SMul R α] (r : R) (f : m → n → α) : r • of f = of (r • f) :=
rfl
#align matrix.smul_of Matrix.smul_of
@[simp]
protected theorem map_zero [Zero α] [Zero β] (f : α → β) (h : f 0 = 0) :
(0 : Matrix m n α).map f = 0 := by
ext
simp [h]
#align matrix.map_zero Matrix.map_zero
protected theorem map_add [Add α] [Add β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ + a₂) = f a₁ + f a₂)
(M N : Matrix m n α) : (M + N).map f = M.map f + N.map f :=
ext fun _ _ => hf _ _
#align matrix.map_add Matrix.map_add
protected theorem map_sub [Sub α] [Sub β] (f : α → β) (hf : ∀ a₁ a₂, f (a₁ - a₂) = f a₁ - f a₂)
(M N : Matrix m n α) : (M - N).map f = M.map f - N.map f :=
ext fun _ _ => hf _ _
#align matrix.map_sub Matrix.map_sub
theorem map_smul [SMul R α] [SMul R β] (f : α → β) (r : R) (hf : ∀ a, f (r • a) = r • f a)
(M : Matrix m n α) : (r • M).map f = r • M.map f :=
ext fun _ _ => hf _
#align matrix.map_smul Matrix.map_smul
/-- The scalar action via `Mul.toSMul` is transformed by the same map as the elements
of the matrix, when `f` preserves multiplication. -/
theorem map_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α)
(hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) : (r • A).map f = f r • A.map f :=
ext fun _ _ => hf _ _
#align matrix.map_smul' Matrix.map_smul'
/-- The scalar action via `mul.toOppositeSMul` is transformed by the same map as the
elements of the matrix, when `f` preserves multiplication. -/
theorem map_op_smul' [Mul α] [Mul β] (f : α → β) (r : α) (A : Matrix n n α)
(hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂) :
(MulOpposite.op r • A).map f = MulOpposite.op (f r) • A.map f :=
ext fun _ _ => hf _ _
#align matrix.map_op_smul' Matrix.map_op_smul'
theorem _root_.IsSMulRegular.matrix [SMul R S] {k : R} (hk : IsSMulRegular S k) :
IsSMulRegular (Matrix m n S) k :=
IsSMulRegular.pi fun _ => IsSMulRegular.pi fun _ => hk
#align is_smul_regular.matrix IsSMulRegular.matrix
theorem _root_.IsLeftRegular.matrix [Mul α] {k : α} (hk : IsLeftRegular k) :
IsSMulRegular (Matrix m n α) k :=
hk.isSMulRegular.matrix
#align is_left_regular.matrix IsLeftRegular.matrix
instance subsingleton_of_empty_left [IsEmpty m] : Subsingleton (Matrix m n α) :=
⟨fun M N => by
ext i
exact isEmptyElim i⟩
#align matrix.subsingleton_of_empty_left Matrix.subsingleton_of_empty_left
instance subsingleton_of_empty_right [IsEmpty n] : Subsingleton (Matrix m n α) :=
⟨fun M N => by
ext i j
exact isEmptyElim j⟩
#align matrix.subsingleton_of_empty_right Matrix.subsingleton_of_empty_right
end Matrix
open Matrix
namespace Matrix
section Diagonal
variable [DecidableEq n]
/-- `diagonal d` is the square matrix such that `(diagonal d) i i = d i` and `(diagonal d) i j = 0`
if `i ≠ j`.
Note that bundled versions exist as:
* `Matrix.diagonalAddMonoidHom`
* `Matrix.diagonalLinearMap`
* `Matrix.diagonalRingHom`
* `Matrix.diagonalAlgHom`
-/
def diagonal [Zero α] (d : n → α) : Matrix n n α :=
of fun i j => if i = j then d i else 0
#align matrix.diagonal Matrix.diagonal
-- TODO: set as an equation lemma for `diagonal`, see mathlib4#3024
theorem diagonal_apply [Zero α] (d : n → α) (i j) : diagonal d i j = if i = j then d i else 0 :=
rfl
#align matrix.diagonal_apply Matrix.diagonal_apply
@[simp]
theorem diagonal_apply_eq [Zero α] (d : n → α) (i : n) : (diagonal d) i i = d i := by
simp [diagonal]
#align matrix.diagonal_apply_eq Matrix.diagonal_apply_eq
@[simp]
theorem diagonal_apply_ne [Zero α] (d : n → α) {i j : n} (h : i ≠ j) : (diagonal d) i j = 0 := by
simp [diagonal, h]
#align matrix.diagonal_apply_ne Matrix.diagonal_apply_ne
theorem diagonal_apply_ne' [Zero α] (d : n → α) {i j : n} (h : j ≠ i) : (diagonal d) i j = 0 :=
diagonal_apply_ne d h.symm
#align matrix.diagonal_apply_ne' Matrix.diagonal_apply_ne'
@[simp]
theorem diagonal_eq_diagonal_iff [Zero α] {d₁ d₂ : n → α} :
diagonal d₁ = diagonal d₂ ↔ ∀ i, d₁ i = d₂ i :=
⟨fun h i => by simpa using congr_arg (fun m : Matrix n n α => m i i) h, fun h => by
rw [show d₁ = d₂ from funext h]⟩
#align matrix.diagonal_eq_diagonal_iff Matrix.diagonal_eq_diagonal_iff
theorem diagonal_injective [Zero α] : Function.Injective (diagonal : (n → α) → Matrix n n α) :=
fun d₁ d₂ h => funext fun i => by simpa using Matrix.ext_iff.mpr h i i
#align matrix.diagonal_injective Matrix.diagonal_injective
@[simp]
theorem diagonal_zero [Zero α] : (diagonal fun _ => 0 : Matrix n n α) = 0 := by
ext
simp [diagonal]
#align matrix.diagonal_zero Matrix.diagonal_zero
@[simp]
theorem diagonal_transpose [Zero α] (v : n → α) : (diagonal v)ᵀ = diagonal v := by
ext i j
by_cases h : i = j
· simp [h, transpose]
· simp [h, transpose, diagonal_apply_ne' _ h]
#align matrix.diagonal_transpose Matrix.diagonal_transpose
@[simp]
theorem diagonal_add [AddZeroClass α] (d₁ d₂ : n → α) :
diagonal d₁ + diagonal d₂ = diagonal fun i => d₁ i + d₂ i := by
ext i j
by_cases h : i = j <;>
simp [h]
#align matrix.diagonal_add Matrix.diagonal_add
@[simp]
theorem diagonal_smul [Zero α] [SMulZeroClass R α] (r : R) (d : n → α) :
diagonal (r • d) = r • diagonal d := by
ext i j
by_cases h : i = j <;> simp [h]
#align matrix.diagonal_smul Matrix.diagonal_smul
@[simp]
theorem diagonal_neg [NegZeroClass α] (d : n → α) :
-diagonal d = diagonal fun i => -d i := by
ext i j
by_cases h : i = j <;>
simp [h]
#align matrix.diagonal_neg Matrix.diagonal_neg
@[simp]
theorem diagonal_sub [SubNegZeroMonoid α] (d₁ d₂ : n → α) :
diagonal d₁ - diagonal d₂ = diagonal fun i => d₁ i - d₂ i := by
ext i j
by_cases h : i = j <;>
simp [h]
instance [Zero α] [NatCast α] : NatCast (Matrix n n α) where
natCast m := diagonal fun _ => m
@[norm_cast]
theorem diagonal_natCast [Zero α] [NatCast α] (m : ℕ) : diagonal (fun _ : n => (m : α)) = m := rfl
@[norm_cast]
theorem diagonal_natCast' [Zero α] [NatCast α] (m : ℕ) : diagonal ((m : n → α)) = m := rfl
-- See note [no_index around OfNat.ofNat]
theorem diagonal_ofNat [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] :
diagonal (fun _ : n => no_index (OfNat.ofNat m : α)) = OfNat.ofNat m := rfl
-- See note [no_index around OfNat.ofNat]
theorem diagonal_ofNat' [Zero α] [NatCast α] (m : ℕ) [m.AtLeastTwo] :
diagonal (no_index (OfNat.ofNat m : n → α)) = OfNat.ofNat m := rfl
instance [Zero α] [IntCast α] : IntCast (Matrix n n α) where
intCast m := diagonal fun _ => m
@[norm_cast]
theorem diagonal_intCast [Zero α] [IntCast α] (m : ℤ) : diagonal (fun _ : n => (m : α)) = m := rfl
@[norm_cast]
theorem diagonal_intCast' [Zero α] [IntCast α] (m : ℤ) : diagonal ((m : n → α)) = m := rfl
variable (n α)
/-- `Matrix.diagonal` as an `AddMonoidHom`. -/
@[simps]
def diagonalAddMonoidHom [AddZeroClass α] : (n → α) →+ Matrix n n α where
toFun := diagonal
map_zero' := diagonal_zero
map_add' x y := (diagonal_add x y).symm
#align matrix.diagonal_add_monoid_hom Matrix.diagonalAddMonoidHom
variable (R)
/-- `Matrix.diagonal` as a `LinearMap`. -/
@[simps]
def diagonalLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : (n → α) →ₗ[R] Matrix n n α :=
{ diagonalAddMonoidHom n α with map_smul' := diagonal_smul }
#align matrix.diagonal_linear_map Matrix.diagonalLinearMap
variable {n α R}
@[simp]
theorem diagonal_map [Zero α] [Zero β] {f : α → β} (h : f 0 = 0) {d : n → α} :
(diagonal d).map f = diagonal fun m => f (d m) := by
ext
simp only [diagonal_apply, map_apply]
split_ifs <;> simp [h]
#align matrix.diagonal_map Matrix.diagonal_map
@[simp]
theorem diagonal_conjTranspose [AddMonoid α] [StarAddMonoid α] (v : n → α) :
(diagonal v)ᴴ = diagonal (star v) := by
rw [conjTranspose, diagonal_transpose, diagonal_map (star_zero _)]
rfl
#align matrix.diagonal_conj_transpose Matrix.diagonal_conjTranspose
section One
variable [Zero α] [One α]
instance one : One (Matrix n n α) :=
⟨diagonal fun _ => 1⟩
@[simp]
theorem diagonal_one : (diagonal fun _ => 1 : Matrix n n α) = 1 :=
rfl
#align matrix.diagonal_one Matrix.diagonal_one
theorem one_apply {i j} : (1 : Matrix n n α) i j = if i = j then 1 else 0 :=
rfl
#align matrix.one_apply Matrix.one_apply
@[simp]
theorem one_apply_eq (i) : (1 : Matrix n n α) i i = 1 :=
diagonal_apply_eq _ i
#align matrix.one_apply_eq Matrix.one_apply_eq
@[simp]
theorem one_apply_ne {i j} : i ≠ j → (1 : Matrix n n α) i j = 0 :=
diagonal_apply_ne _
#align matrix.one_apply_ne Matrix.one_apply_ne
theorem one_apply_ne' {i j} : j ≠ i → (1 : Matrix n n α) i j = 0 :=
diagonal_apply_ne' _
#align matrix.one_apply_ne' Matrix.one_apply_ne'
@[simp]
theorem map_one [Zero β] [One β] (f : α → β) (h₀ : f 0 = 0) (h₁ : f 1 = 1) :
(1 : Matrix n n α).map f = (1 : Matrix n n β) := by
ext
simp only [one_apply, map_apply]
split_ifs <;> simp [h₀, h₁]
#align matrix.map_one Matrix.map_one
-- Porting note: added implicit argument `(f := fun_ => α)`, why is that needed?
theorem one_eq_pi_single {i j} : (1 : Matrix n n α) i j = Pi.single (f := fun _ => α) i 1 j := by
simp only [one_apply, Pi.single_apply, eq_comm]
#align matrix.one_eq_pi_single Matrix.one_eq_pi_single
lemma zero_le_one_elem [Preorder α] [ZeroLEOneClass α] (i j : n) :
0 ≤ (1 : Matrix n n α) i j := by
by_cases hi : i = j <;> simp [hi]
lemma zero_le_one_row [Preorder α] [ZeroLEOneClass α] (i : n) :
0 ≤ (1 : Matrix n n α) i :=
zero_le_one_elem i
end One
instance instAddMonoidWithOne [AddMonoidWithOne α] : AddMonoidWithOne (Matrix n n α) where
natCast_zero := show diagonal _ = _ by
rw [Nat.cast_zero, diagonal_zero]
natCast_succ n := show diagonal _ = diagonal _ + _ by
rw [Nat.cast_succ, ← diagonal_add, diagonal_one]
instance instAddGroupWithOne [AddGroupWithOne α] : AddGroupWithOne (Matrix n n α) where
intCast_ofNat n := show diagonal _ = diagonal _ by
rw [Int.cast_natCast]
intCast_negSucc n := show diagonal _ = -(diagonal _) by
rw [Int.cast_negSucc, diagonal_neg]
__ := addGroup
__ := instAddMonoidWithOne
instance instAddCommMonoidWithOne [AddCommMonoidWithOne α] :
AddCommMonoidWithOne (Matrix n n α) where
__ := addCommMonoid
__ := instAddMonoidWithOne
instance instAddCommGroupWithOne [AddCommGroupWithOne α] :
AddCommGroupWithOne (Matrix n n α) where
__ := addCommGroup
__ := instAddGroupWithOne
section Numeral
set_option linter.deprecated false
@[deprecated, simp]
theorem bit0_apply [Add α] (M : Matrix m m α) (i : m) (j : m) : (bit0 M) i j = bit0 (M i j) :=
rfl
#align matrix.bit0_apply Matrix.bit0_apply
variable [AddZeroClass α] [One α]
@[deprecated]
theorem bit1_apply (M : Matrix n n α) (i : n) (j : n) :
(bit1 M) i j = if i = j then bit1 (M i j) else bit0 (M i j) := by
dsimp [bit1]
by_cases h : i = j <;>
simp [h]
#align matrix.bit1_apply Matrix.bit1_apply
@[deprecated, simp]
theorem bit1_apply_eq (M : Matrix n n α) (i : n) : (bit1 M) i i = bit1 (M i i) := by
simp [bit1_apply]
#align matrix.bit1_apply_eq Matrix.bit1_apply_eq
@[deprecated, simp]
theorem bit1_apply_ne (M : Matrix n n α) {i j : n} (h : i ≠ j) : (bit1 M) i j = bit0 (M i j) := by
simp [bit1_apply, h]
#align matrix.bit1_apply_ne Matrix.bit1_apply_ne
end Numeral
end Diagonal
section Diag
/-- The diagonal of a square matrix. -/
-- @[simp] -- Porting note: simpNF does not like this.
def diag (A : Matrix n n α) (i : n) : α :=
A i i
#align matrix.diag Matrix.diag
-- Porting note: new, because of removed `simp` above.
-- TODO: set as an equation lemma for `diag`, see mathlib4#3024
@[simp]
theorem diag_apply (A : Matrix n n α) (i) : diag A i = A i i :=
rfl
@[simp]
theorem diag_diagonal [DecidableEq n] [Zero α] (a : n → α) : diag (diagonal a) = a :=
funext <| @diagonal_apply_eq _ _ _ _ a
#align matrix.diag_diagonal Matrix.diag_diagonal
@[simp]
theorem diag_transpose (A : Matrix n n α) : diag Aᵀ = diag A :=
rfl
#align matrix.diag_transpose Matrix.diag_transpose
@[simp]
theorem diag_zero [Zero α] : diag (0 : Matrix n n α) = 0 :=
rfl
#align matrix.diag_zero Matrix.diag_zero
@[simp]
theorem diag_add [Add α] (A B : Matrix n n α) : diag (A + B) = diag A + diag B :=
rfl
#align matrix.diag_add Matrix.diag_add
@[simp]
theorem diag_sub [Sub α] (A B : Matrix n n α) : diag (A - B) = diag A - diag B :=
rfl
#align matrix.diag_sub Matrix.diag_sub
@[simp]
theorem diag_neg [Neg α] (A : Matrix n n α) : diag (-A) = -diag A :=
rfl
#align matrix.diag_neg Matrix.diag_neg
@[simp]
theorem diag_smul [SMul R α] (r : R) (A : Matrix n n α) : diag (r • A) = r • diag A :=
rfl
#align matrix.diag_smul Matrix.diag_smul
@[simp]
theorem diag_one [DecidableEq n] [Zero α] [One α] : diag (1 : Matrix n n α) = 1 :=
diag_diagonal _
#align matrix.diag_one Matrix.diag_one
variable (n α)
/-- `Matrix.diag` as an `AddMonoidHom`. -/
@[simps]
def diagAddMonoidHom [AddZeroClass α] : Matrix n n α →+ n → α where
toFun := diag
map_zero' := diag_zero
map_add' := diag_add
#align matrix.diag_add_monoid_hom Matrix.diagAddMonoidHom
variable (R)
/-- `Matrix.diag` as a `LinearMap`. -/
@[simps]
def diagLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : Matrix n n α →ₗ[R] n → α :=
{ diagAddMonoidHom n α with map_smul' := diag_smul }
#align matrix.diag_linear_map Matrix.diagLinearMap
variable {n α R}
theorem diag_map {f : α → β} {A : Matrix n n α} : diag (A.map f) = f ∘ diag A :=
rfl
#align matrix.diag_map Matrix.diag_map
@[simp]
theorem diag_conjTranspose [AddMonoid α] [StarAddMonoid α] (A : Matrix n n α) :
diag Aᴴ = star (diag A) :=
rfl
#align matrix.diag_conj_transpose Matrix.diag_conjTranspose
@[simp]
theorem diag_list_sum [AddMonoid α] (l : List (Matrix n n α)) : diag l.sum = (l.map diag).sum :=
map_list_sum (diagAddMonoidHom n α) l
#align matrix.diag_list_sum Matrix.diag_list_sum
@[simp]
theorem diag_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix n n α)) :
diag s.sum = (s.map diag).sum :=
map_multiset_sum (diagAddMonoidHom n α) s
#align matrix.diag_multiset_sum Matrix.diag_multiset_sum
@[simp]
theorem diag_sum {ι} [AddCommMonoid α] (s : Finset ι) (f : ι → Matrix n n α) :
diag (∑ i ∈ s, f i) = ∑ i ∈ s, diag (f i) :=
map_sum (diagAddMonoidHom n α) f s
#align matrix.diag_sum Matrix.diag_sum
end Diag
section DotProduct
variable [Fintype m] [Fintype n]
/-- `dotProduct v w` is the sum of the entrywise products `v i * w i` -/
def dotProduct [Mul α] [AddCommMonoid α] (v w : m → α) : α :=
∑ i, v i * w i
#align matrix.dot_product Matrix.dotProduct
/- The precedence of 72 comes immediately after ` • ` for `SMul.smul`,
so that `r₁ • a ⬝ᵥ r₂ • b` is parsed as `(r₁ • a) ⬝ᵥ (r₂ • b)` here. -/
@[inherit_doc]
scoped infixl:72 " ⬝ᵥ " => Matrix.dotProduct
theorem dotProduct_assoc [NonUnitalSemiring α] (u : m → α) (w : n → α) (v : Matrix m n α) :
(fun j => u ⬝ᵥ fun i => v i j) ⬝ᵥ w = u ⬝ᵥ fun i => v i ⬝ᵥ w := by
simpa [dotProduct, Finset.mul_sum, Finset.sum_mul, mul_assoc] using Finset.sum_comm
#align matrix.dot_product_assoc Matrix.dotProduct_assoc
theorem dotProduct_comm [AddCommMonoid α] [CommSemigroup α] (v w : m → α) : v ⬝ᵥ w = w ⬝ᵥ v := by
simp_rw [dotProduct, mul_comm]
#align matrix.dot_product_comm Matrix.dotProduct_comm
@[simp]
theorem dotProduct_pUnit [AddCommMonoid α] [Mul α] (v w : PUnit → α) : v ⬝ᵥ w = v ⟨⟩ * w ⟨⟩ := by
simp [dotProduct]
#align matrix.dot_product_punit Matrix.dotProduct_pUnit
section MulOneClass
variable [MulOneClass α] [AddCommMonoid α]
theorem dotProduct_one (v : n → α) : v ⬝ᵥ 1 = ∑ i, v i := by simp [(· ⬝ᵥ ·)]
#align matrix.dot_product_one Matrix.dotProduct_one
theorem one_dotProduct (v : n → α) : 1 ⬝ᵥ v = ∑ i, v i := by simp [(· ⬝ᵥ ·)]
#align matrix.one_dot_product Matrix.one_dotProduct
end MulOneClass
section NonUnitalNonAssocSemiring
variable [NonUnitalNonAssocSemiring α] (u v w : m → α) (x y : n → α)
@[simp]
theorem dotProduct_zero : v ⬝ᵥ 0 = 0 := by simp [dotProduct]
#align matrix.dot_product_zero Matrix.dotProduct_zero
@[simp]
theorem dotProduct_zero' : (v ⬝ᵥ fun _ => 0) = 0 :=
dotProduct_zero v
#align matrix.dot_product_zero' Matrix.dotProduct_zero'
@[simp]
theorem zero_dotProduct : 0 ⬝ᵥ v = 0 := by simp [dotProduct]
#align matrix.zero_dot_product Matrix.zero_dotProduct
@[simp]
theorem zero_dotProduct' : (fun _ => (0 : α)) ⬝ᵥ v = 0 :=
zero_dotProduct v
#align matrix.zero_dot_product' Matrix.zero_dotProduct'
@[simp]
theorem add_dotProduct : (u + v) ⬝ᵥ w = u ⬝ᵥ w + v ⬝ᵥ w := by
simp [dotProduct, add_mul, Finset.sum_add_distrib]
#align matrix.add_dot_product Matrix.add_dotProduct
@[simp]
theorem dotProduct_add : u ⬝ᵥ (v + w) = u ⬝ᵥ v + u ⬝ᵥ w := by
simp [dotProduct, mul_add, Finset.sum_add_distrib]
#align matrix.dot_product_add Matrix.dotProduct_add
@[simp]
| Mathlib/Data/Matrix/Basic.lean | 811 | 812 | theorem sum_elim_dotProduct_sum_elim : Sum.elim u x ⬝ᵥ Sum.elim v y = u ⬝ᵥ v + x ⬝ᵥ y := by |
simp [dotProduct]
|
/-
Copyright (c) 2020 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri, Sebastien Gouezel, Heather Macbeth, Patrick Massot, Floris van Doorn
-/
import Mathlib.Analysis.NormedSpace.BoundedLinearMaps
import Mathlib.Topology.FiberBundle.Basic
#align_import topology.vector_bundle.basic from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833"
/-!
# Vector bundles
In this file we define (topological) vector bundles.
Let `B` be the base space, let `F` be a normed space over a normed field `R`, and let
`E : B → Type*` be a `FiberBundle` with fiber `F`, in which, for each `x`, the fiber `E x` is a
topological vector space over `R`.
To have a vector bundle structure on `Bundle.TotalSpace F E`, one should additionally have the
following properties:
* The bundle trivializations in the trivialization atlas should be continuous linear equivs in the
fibers;
* For any two trivializations `e`, `e'` in the atlas the transition function considered as a map
from `B` into `F →L[R] F` is continuous on `e.baseSet ∩ e'.baseSet` with respect to the operator
norm topology on `F →L[R] F`.
If these conditions are satisfied, we register the typeclass `VectorBundle R F E`.
We define constructions on vector bundles like pullbacks and direct sums in other files.
## Main Definitions
* `Trivialization.IsLinear`: a class stating that a trivialization is fiberwise linear on its base
set.
* `Trivialization.linearEquivAt` and `Trivialization.continuousLinearMapAt` are the
(continuous) linear fiberwise equivalences a trivialization induces.
* They have forward maps `Trivialization.linearMapAt` / `Trivialization.continuousLinearMapAt`
and inverses `Trivialization.symmₗ` / `Trivialization.symmL`. Note that these are all defined
everywhere, since they are extended using the zero function.
* `Trivialization.coordChangeL` is the coordinate change induced by two trivializations. It only
makes sense on the intersection of their base sets, but is extended outside it using the identity.
* Given a continuous (semi)linear map between `E x` and `E' y` where `E` and `E'` are bundles over
possibly different base sets, `ContinuousLinearMap.inCoordinates` turns this into a continuous
(semi)linear map between the chosen fibers of those bundles.
## Implementation notes
The implementation choices in the vector bundle definition are discussed in the "Implementation
notes" section of `Mathlib.Topology.FiberBundle.Basic`.
## Tags
Vector bundle
-/
noncomputable section
open scoped Classical
open Bundle Set
open scoped Topology
variable (R : Type*) {B : Type*} (F : Type*) (E : B → Type*)
section TopologicalVectorSpace
variable {F E}
variable [Semiring R] [TopologicalSpace F] [TopologicalSpace B]
/-- A mixin class for `Pretrivialization`, stating that a pretrivialization is fiberwise linear with
respect to given module structures on its fibers and the model fiber. -/
protected class Pretrivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] (e : Pretrivialization F (π F E)) : Prop where
linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2
#align pretrivialization.is_linear Pretrivialization.IsLinear
namespace Pretrivialization
variable (e : Pretrivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b}
theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
[e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) :
IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 :=
Pretrivialization.IsLinear.linear b hb
#align pretrivialization.linear Pretrivialization.linear
variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
/-- A fiberwise linear inverse to `e`. -/
@[simps!]
protected def symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := by
refine IsLinearMap.mk' (e.symm b) ?_
by_cases hb : b ∈ e.baseSet
· exact (((e.linear R hb).mk' _).inverse (e.symm b) (e.symm_apply_apply_mk hb) fun v ↦
congr_arg Prod.snd <| e.apply_mk_symm hb v).isLinear
· rw [e.coe_symm_of_not_mem hb]
exact (0 : F →ₗ[R] E b).isLinear
#align pretrivialization.symmₗ Pretrivialization.symmₗ
/-- A pretrivialization for a vector bundle defines linear equivalences between the
fibers and the model space. -/
@[simps (config := .asFn)]
def linearEquivAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) :
E b ≃ₗ[R] F where
toFun y := (e ⟨b, y⟩).2
invFun := e.symm b
left_inv := e.symm_apply_apply_mk hb
right_inv v := by simp_rw [e.apply_mk_symm hb v]
map_add' v w := (e.linear R hb).map_add v w
map_smul' c v := (e.linear R hb).map_smul c v
#align pretrivialization.linear_equiv_at Pretrivialization.linearEquivAt
/-- A fiberwise linear map equal to `e` on `e.baseSet`. -/
protected def linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F :=
if hb : b ∈ e.baseSet then e.linearEquivAt R b hb else 0
#align pretrivialization.linear_map_at Pretrivialization.linearMapAt
variable {R}
theorem coe_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [Pretrivialization.linearMapAt]
split_ifs <;> rfl
#align pretrivialization.coe_linear_map_at Pretrivialization.coe_linearMapAt
theorem coe_linearMapAt_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by
simp_rw [coe_linearMapAt, if_pos hb]
#align pretrivialization.coe_linear_map_at_of_mem Pretrivialization.coe_linearMapAt_of_mem
theorem linearMapAt_apply (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) :
e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [coe_linearMapAt]
#align pretrivialization.linear_map_at_apply Pretrivialization.linearMapAt_apply
theorem linearMapAt_def_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb :=
dif_pos hb
#align pretrivialization.linear_map_at_def_of_mem Pretrivialization.linearMapAt_def_of_mem
theorem linearMapAt_def_of_not_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
#align pretrivialization.linear_map_at_def_of_not_mem Pretrivialization.linearMapAt_def_of_not_mem
theorem linearMapAt_eq_zero (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
#align pretrivialization.linear_map_at_eq_zero Pretrivialization.linearMapAt_eq_zero
theorem symmₗ_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y := by
rw [e.linearMapAt_def_of_mem hb]
exact (e.linearEquivAt R b hb).left_inv y
#align pretrivialization.symmₗ_linear_map_at Pretrivialization.symmₗ_linearMapAt
theorem linearMapAt_symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : F) : e.linearMapAt R b (e.symmₗ R b y) = y := by
rw [e.linearMapAt_def_of_mem hb]
exact (e.linearEquivAt R b hb).right_inv y
#align pretrivialization.linear_map_at_symmₗ Pretrivialization.linearMapAt_symmₗ
end Pretrivialization
variable [TopologicalSpace (TotalSpace F E)]
/-- A mixin class for `Trivialization`, stating that a trivialization is fiberwise linear with
respect to given module structures on its fibers and the model fiber. -/
protected class Trivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] (e : Trivialization F (π F E)) : Prop where
linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2
#align trivialization.is_linear Trivialization.IsLinear
namespace Trivialization
variable (e : Trivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b}
protected theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) :
IsLinearMap R fun y : E b => (e ⟨b, y⟩).2 :=
Trivialization.IsLinear.linear b hb
#align trivialization.linear Trivialization.linear
instance toPretrivialization.isLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] [e.IsLinear R] : e.toPretrivialization.IsLinear R :=
{ (‹_› : e.IsLinear R) with }
#align trivialization.to_pretrivialization.is_linear Trivialization.toPretrivialization.isLinear
variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
/-- A trivialization for a vector bundle defines linear equivalences between the
fibers and the model space. -/
def linearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) :
E b ≃ₗ[R] F :=
e.toPretrivialization.linearEquivAt R b hb
#align trivialization.linear_equiv_at Trivialization.linearEquivAt
variable {R}
@[simp]
theorem linearEquivAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) (v : E b) : e.linearEquivAt R b hb v = (e ⟨b, v⟩).2 :=
rfl
#align trivialization.linear_equiv_at_apply Trivialization.linearEquivAt_apply
@[simp]
theorem linearEquivAt_symm_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) (v : F) : (e.linearEquivAt R b hb).symm v = e.symm b v :=
rfl
#align trivialization.linear_equiv_at_symm_apply Trivialization.linearEquivAt_symm_apply
variable (R)
/-- A fiberwise linear inverse to `e`. -/
protected def symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b :=
e.toPretrivialization.symmₗ R b
#align trivialization.symmₗ Trivialization.symmₗ
variable {R}
theorem coe_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.symmₗ R b) = e.symm b :=
rfl
#align trivialization.coe_symmₗ Trivialization.coe_symmₗ
variable (R)
/-- A fiberwise linear map equal to `e` on `e.baseSet`. -/
protected def linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F :=
e.toPretrivialization.linearMapAt R b
#align trivialization.linear_map_at Trivialization.linearMapAt
variable {R}
theorem coe_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 :=
e.toPretrivialization.coe_linearMapAt b
#align trivialization.coe_linear_map_at Trivialization.coe_linearMapAt
theorem coe_linearMapAt_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by
simp_rw [coe_linearMapAt, if_pos hb]
#align trivialization.coe_linear_map_at_of_mem Trivialization.coe_linearMapAt_of_mem
theorem linearMapAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) :
e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [coe_linearMapAt]
#align trivialization.linear_map_at_apply Trivialization.linearMapAt_apply
theorem linearMapAt_def_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb :=
dif_pos hb
#align trivialization.linear_map_at_def_of_mem Trivialization.linearMapAt_def_of_mem
theorem linearMapAt_def_of_not_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
#align trivialization.linear_map_at_def_of_not_mem Trivialization.linearMapAt_def_of_not_mem
theorem symmₗ_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet)
(y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y :=
e.toPretrivialization.symmₗ_linearMapAt hb y
#align trivialization.symmₗ_linear_map_at Trivialization.symmₗ_linearMapAt
theorem linearMapAt_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet)
(y : F) : e.linearMapAt R b (e.symmₗ R b y) = y :=
e.toPretrivialization.linearMapAt_symmₗ hb y
#align trivialization.linear_map_at_symmₗ Trivialization.linearMapAt_symmₗ
variable (R)
/-- A coordinate change function between two trivializations, as a continuous linear equivalence.
Defined to be the identity when `b` does not lie in the base set of both trivializations. -/
def coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] (b : B) :
F ≃L[R] F :=
{ toLinearEquiv := if hb : b ∈ e.baseSet ∩ e'.baseSet
then (e.linearEquivAt R b (hb.1 : _)).symm.trans (e'.linearEquivAt R b hb.2)
else LinearEquiv.refl R F
continuous_toFun := by
by_cases hb : b ∈ e.baseSet ∩ e'.baseSet
· rw [dif_pos hb]
refine (e'.continuousOn.comp_continuous ?_ ?_).snd
· exact e.continuousOn_symm.comp_continuous (Continuous.Prod.mk b) fun y =>
mk_mem_prod hb.1 (mem_univ y)
· exact fun y => e'.mem_source.mpr hb.2
· rw [dif_neg hb]
exact continuous_id
continuous_invFun := by
by_cases hb : b ∈ e.baseSet ∩ e'.baseSet
· rw [dif_pos hb]
refine (e.continuousOn.comp_continuous ?_ ?_).snd
· exact e'.continuousOn_symm.comp_continuous (Continuous.Prod.mk b) fun y =>
mk_mem_prod hb.2 (mem_univ y)
exact fun y => e.mem_source.mpr hb.1
· rw [dif_neg hb]
exact continuous_id }
set_option linter.uppercaseLean3 false in
#align trivialization.coord_changeL Trivialization.coordChangeL
variable {R}
theorem coe_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) :
⇑(coordChangeL R e e' b) = (e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) :=
congr_arg (fun f : F ≃ₗ[R] F ↦ ⇑f) (dif_pos hb)
set_option linter.uppercaseLean3 false in
#align trivialization.coe_coord_changeL Trivialization.coe_coordChangeL
theorem coe_coordChangeL' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) :
(coordChangeL R e e' b).toLinearEquiv =
(e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) :=
LinearEquiv.coe_injective (coe_coordChangeL _ _ hb)
set_option linter.uppercaseLean3 false in
#align trivialization.coe_coord_changeL' Trivialization.coe_coordChangeL'
theorem symm_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e'.baseSet ∩ e.baseSet) : (e.coordChangeL R e' b).symm = e'.coordChangeL R e b := by
apply ContinuousLinearEquiv.toLinearEquiv_injective
rw [coe_coordChangeL' e' e hb, (coordChangeL R e e' b).symm_toLinearEquiv,
coe_coordChangeL' e e' hb.symm, LinearEquiv.trans_symm, LinearEquiv.symm_symm]
set_option linter.uppercaseLean3 false in
#align trivialization.symm_coord_changeL Trivialization.symm_coordChangeL
theorem coordChangeL_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) :
coordChangeL R e e' b y = (e' ⟨b, e.symm b y⟩).2 :=
congr_fun (coe_coordChangeL e e' hb) y
set_option linter.uppercaseLean3 false in
#align trivialization.coord_changeL_apply Trivialization.coordChangeL_apply
theorem mk_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) :
(b, coordChangeL R e e' b y) = e' ⟨b, e.symm b y⟩ := by
ext
· rw [e.mk_symm hb.1 y, e'.coe_fst', e.proj_symm_apply' hb.1]
rw [e.proj_symm_apply' hb.1]
exact hb.2
· exact e.coordChangeL_apply e' hb y
set_option linter.uppercaseLean3 false in
#align trivialization.mk_coord_changeL Trivialization.mk_coordChangeL
theorem apply_symm_apply_eq_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R]
[e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) :
e' (e.toPartialHomeomorph.symm (b, v)) = (b, e.coordChangeL R e' b v) := by
rw [e.mk_coordChangeL e' hb, e.mk_symm hb.1]
set_option linter.uppercaseLean3 false in
#align trivialization.apply_symm_apply_eq_coord_changeL Trivialization.apply_symm_apply_eq_coordChangeL
/-- A version of `Trivialization.coordChangeL_apply` that fully unfolds `coordChange`. The
right-hand side is ugly, but has good definitional properties for specifically defined
trivializations. -/
theorem coordChangeL_apply' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) :
coordChangeL R e e' b y = (e' (e.toPartialHomeomorph.symm (b, y))).2 := by
rw [e.coordChangeL_apply e' hb, e.mk_symm hb.1]
set_option linter.uppercaseLean3 false in
#align trivialization.coord_changeL_apply' Trivialization.coordChangeL_apply'
theorem coordChangeL_symm_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R]
{b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) :
⇑(coordChangeL R e e' b).symm =
(e'.linearEquivAt R b hb.2).symm.trans (e.linearEquivAt R b hb.1) :=
congr_arg LinearEquiv.invFun (dif_pos hb)
set_option linter.uppercaseLean3 false in
#align trivialization.coord_changeL_symm_apply Trivialization.coordChangeL_symm_apply
end Trivialization
end TopologicalVectorSpace
section
namespace Bundle
/-- The zero section of a vector bundle -/
def zeroSection [∀ x, Zero (E x)] : B → TotalSpace F E := (⟨·, 0⟩)
#align bundle.zero_section Bundle.zeroSection
@[simp, mfld_simps]
theorem zeroSection_proj [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).proj = x :=
rfl
#align bundle.zero_section_proj Bundle.zeroSection_proj
@[simp, mfld_simps]
theorem zeroSection_snd [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).2 = 0 :=
rfl
#align bundle.zero_section_snd Bundle.zeroSection_snd
end Bundle
open Bundle
variable [NontriviallyNormedField R] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
[NormedAddCommGroup F] [NormedSpace R F] [TopologicalSpace B] [TopologicalSpace (TotalSpace F E)]
[∀ x, TopologicalSpace (E x)] [FiberBundle F E]
/-- The space `Bundle.TotalSpace F E` (for `E : B → Type*` such that each `E x` is a topological
vector space) has a topological vector space structure with fiber `F` (denoted with
`VectorBundle R F E`) if around every point there is a fiber bundle trivialization which is linear
in the fibers. -/
class VectorBundle : Prop where
trivialization_linear' : ∀ (e : Trivialization F (π F E)) [MemTrivializationAtlas e], e.IsLinear R
continuousOn_coordChange' :
∀ (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'],
ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F)
(e.baseSet ∩ e'.baseSet)
#align vector_bundle VectorBundle
variable {F E}
instance (priority := 100) trivialization_linear [VectorBundle R F E] (e : Trivialization F (π F E))
[MemTrivializationAtlas e] : e.IsLinear R :=
VectorBundle.trivialization_linear' e
#align trivialization_linear trivialization_linear
theorem continuousOn_coordChange [VectorBundle R F E] (e e' : Trivialization F (π F E))
[MemTrivializationAtlas e] [MemTrivializationAtlas e'] :
ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F)
(e.baseSet ∩ e'.baseSet) :=
VectorBundle.continuousOn_coordChange' e e'
#align continuous_on_coord_change continuousOn_coordChange
namespace Trivialization
/-- Forward map of `Trivialization.continuousLinearEquivAt` (only propositionally equal),
defined everywhere (`0` outside domain). -/
@[simps (config := .asFn) apply]
def continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →L[R] F :=
{ e.linearMapAt R b with
toFun := e.linearMapAt R b -- given explicitly to help `simps`
cont := by
dsimp
rw [e.coe_linearMapAt b]
refine continuous_if_const _ (fun hb => ?_) fun _ => continuous_zero
exact (e.continuousOn.comp_continuous (FiberBundle.totalSpaceMk_inducing F E b).continuous
fun x => e.mem_source.mpr hb).snd }
#align trivialization.continuous_linear_map_at Trivialization.continuousLinearMapAt
/-- Backwards map of `Trivialization.continuousLinearEquivAt`, defined everywhere. -/
@[simps (config := .asFn) apply]
def symmL (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →L[R] E b :=
{ e.symmₗ R b with
toFun := e.symm b -- given explicitly to help `simps`
cont := by
by_cases hb : b ∈ e.baseSet
· rw [(FiberBundle.totalSpaceMk_inducing F E b).continuous_iff]
exact e.continuousOn_symm.comp_continuous (continuous_const.prod_mk continuous_id) fun x ↦
mk_mem_prod hb (mem_univ x)
· refine continuous_zero.congr fun x => (e.symm_apply_of_not_mem hb x).symm }
set_option linter.uppercaseLean3 false in
#align trivialization.symmL Trivialization.symmL
variable {R}
theorem symmL_continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : E b) : e.symmL R b (e.continuousLinearMapAt R b y) = y :=
e.symmₗ_linearMapAt hb y
set_option linter.uppercaseLean3 false in
#align trivialization.symmL_continuous_linear_map_at Trivialization.symmL_continuousLinearMapAt
theorem continuousLinearMapAt_symmL (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : F) : e.continuousLinearMapAt R b (e.symmL R b y) = y :=
e.linearMapAt_symmₗ hb y
set_option linter.uppercaseLean3 false in
#align trivialization.continuous_linear_map_at_symmL Trivialization.continuousLinearMapAt_symmL
variable (R)
/-- In a vector bundle, a trivialization in the fiber (which is a priori only linear)
is in fact a continuous linear equiv between the fibers and the model fiber. -/
@[simps (config := .asFn) apply symm_apply]
def continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) : E b ≃L[R] F :=
{ e.toPretrivialization.linearEquivAt R b hb with
toFun := fun y => (e ⟨b, y⟩).2 -- given explicitly to help `simps`
invFun := e.symm b -- given explicitly to help `simps`
continuous_toFun := (e.continuousOn.comp_continuous
(FiberBundle.totalSpaceMk_inducing F E b).continuous fun _ => e.mem_source.mpr hb).snd
continuous_invFun := (e.symmL R b).continuous }
#align trivialization.continuous_linear_equiv_at Trivialization.continuousLinearEquivAt
variable {R}
theorem coe_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) :
(e.continuousLinearEquivAt R b hb : E b → F) = e.continuousLinearMapAt R b :=
(e.coe_linearMapAt_of_mem hb).symm
#align trivialization.coe_continuous_linear_equiv_at_eq Trivialization.coe_continuousLinearEquivAt_eq
theorem symm_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : ((e.continuousLinearEquivAt R b hb).symm : F → E b) = e.symmL R b :=
rfl
#align trivialization.symm_continuous_linear_equiv_at_eq Trivialization.symm_continuousLinearEquivAt_eq
@[simp, nolint simpNF] -- `simp` can prove it but `dsimp` can't; todo: prove `Sigma.eta` with `rfl`
theorem continuousLinearEquivAt_apply' (e : Trivialization F (π F E)) [e.IsLinear R]
(x : TotalSpace F E) (hx : x ∈ e.source) :
e.continuousLinearEquivAt R x.proj (e.mem_source.1 hx) x.2 = (e x).2 := rfl
#align trivialization.continuous_linear_equiv_at_apply' Trivialization.continuousLinearEquivAt_apply'
variable (R)
theorem apply_eq_prod_continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) (z : E b) : e ⟨b, z⟩ = (b, e.continuousLinearEquivAt R b hb z) := by
ext
· refine e.coe_fst ?_
rw [e.source_eq]
exact hb
· simp only [coe_coe, continuousLinearEquivAt_apply]
#align trivialization.apply_eq_prod_continuous_linear_equiv_at Trivialization.apply_eq_prod_continuousLinearEquivAt
protected theorem zeroSection (e : Trivialization F (π F E)) [e.IsLinear R] {x : B}
(hx : x ∈ e.baseSet) : e (zeroSection F E x) = (x, 0) := by
simp_rw [zeroSection, e.apply_eq_prod_continuousLinearEquivAt R x hx 0, map_zero]
#align trivialization.zero_section Trivialization.zeroSection
variable {R}
theorem symm_apply_eq_mk_continuousLinearEquivAt_symm (e : Trivialization F (π F E)) [e.IsLinear R]
(b : B) (hb : b ∈ e.baseSet) (z : F) :
e.toPartialHomeomorph.symm ⟨b, z⟩ = ⟨b, (e.continuousLinearEquivAt R b hb).symm z⟩ := by
have h : (b, z) ∈ e.target := by
rw [e.target_eq]
exact ⟨hb, mem_univ _⟩
apply e.injOn (e.map_target h)
· simpa only [e.source_eq, mem_preimage]
· simp_rw [e.right_inv h, coe_coe, e.apply_eq_prod_continuousLinearEquivAt R b hb,
ContinuousLinearEquiv.apply_symm_apply]
#align trivialization.symm_apply_eq_mk_continuous_linear_equiv_at_symm Trivialization.symm_apply_eq_mk_continuousLinearEquivAt_symm
theorem comp_continuousLinearEquivAt_eq_coord_change (e e' : Trivialization F (π F E))
[e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) :
(e.continuousLinearEquivAt R b hb.1).symm.trans (e'.continuousLinearEquivAt R b hb.2) =
coordChangeL R e e' b := by
ext v
rw [coordChangeL_apply e e' hb]
rfl
#align trivialization.comp_continuous_linear_equiv_at_eq_coord_change Trivialization.comp_continuousLinearEquivAt_eq_coord_change
end Trivialization
/-! ### Constructing vector bundles -/
variable (B F)
/-- Analogous construction of `FiberBundleCore` for vector bundles. This
construction gives a way to construct vector bundles from a structure registering how
trivialization changes act on fibers. -/
structure VectorBundleCore (ι : Type*) where
baseSet : ι → Set B
isOpen_baseSet : ∀ i, IsOpen (baseSet i)
indexAt : B → ι
mem_baseSet_at : ∀ x, x ∈ baseSet (indexAt x)
coordChange : ι → ι → B → F →L[R] F
coordChange_self : ∀ i, ∀ x ∈ baseSet i, ∀ v, coordChange i i x v = v
continuousOn_coordChange : ∀ i j, ContinuousOn (coordChange i j) (baseSet i ∩ baseSet j)
coordChange_comp : ∀ i j k, ∀ x ∈ baseSet i ∩ baseSet j ∩ baseSet k, ∀ v,
(coordChange j k x) (coordChange i j x v) = coordChange i k x v
#align vector_bundle_core VectorBundleCore
/-- The trivial vector bundle core, in which all the changes of coordinates are the
identity. -/
def trivialVectorBundleCore (ι : Type*) [Inhabited ι] : VectorBundleCore R B F ι where
baseSet _ := univ
isOpen_baseSet _ := isOpen_univ
indexAt := default
mem_baseSet_at x := mem_univ x
coordChange _ _ _ := ContinuousLinearMap.id R F
coordChange_self _ _ _ _ := rfl
coordChange_comp _ _ _ _ _ _ := rfl
continuousOn_coordChange _ _ := continuousOn_const
#align trivial_vector_bundle_core trivialVectorBundleCore
instance (ι : Type*) [Inhabited ι] : Inhabited (VectorBundleCore R B F ι) :=
⟨trivialVectorBundleCore R B F ι⟩
namespace VectorBundleCore
variable {R B F} {ι : Type*}
variable (Z : VectorBundleCore R B F ι)
/-- Natural identification to a `FiberBundleCore`. -/
@[simps (config := mfld_cfg)]
def toFiberBundleCore : FiberBundleCore ι B F :=
{ Z with
coordChange := fun i j b => Z.coordChange i j b
continuousOn_coordChange := fun i j =>
isBoundedBilinearMap_apply.continuous.comp_continuousOn
((Z.continuousOn_coordChange i j).prod_map continuousOn_id) }
#align vector_bundle_core.to_fiber_bundle_core VectorBundleCore.toFiberBundleCore
-- Porting note (#11215): TODO: restore coercion
-- instance toFiberBundleCoreCoe : Coe (VectorBundleCore R B F ι) (FiberBundleCore ι B F) :=
-- ⟨toFiberBundleCore⟩
-- #align vector_bundle_core.to_fiber_bundle_core_coe VectorBundleCore.toFiberBundleCoreCoe
theorem coordChange_linear_comp (i j k : ι) :
∀ x ∈ Z.baseSet i ∩ Z.baseSet j ∩ Z.baseSet k,
(Z.coordChange j k x).comp (Z.coordChange i j x) = Z.coordChange i k x :=
fun x hx => by
ext v
exact Z.coordChange_comp i j k x hx v
#align vector_bundle_core.coord_change_linear_comp VectorBundleCore.coordChange_linear_comp
/-- The index set of a vector bundle core, as a convenience function for dot notation -/
@[nolint unusedArguments] -- Porting note(#5171): was `nolint has_nonempty_instance`
def Index := ι
#align vector_bundle_core.index VectorBundleCore.Index
/-- The base space of a vector bundle core, as a convenience function for dot notation-/
@[nolint unusedArguments, reducible]
def Base := B
#align vector_bundle_core.base VectorBundleCore.Base
/-- The fiber of a vector bundle core, as a convenience function for dot notation and
typeclass inference -/
@[nolint unusedArguments] -- Porting note(#5171): was `nolint has_nonempty_instance`
def Fiber : B → Type _ :=
Z.toFiberBundleCore.Fiber
#align vector_bundle_core.fiber VectorBundleCore.Fiber
instance topologicalSpaceFiber (x : B) : TopologicalSpace (Z.Fiber x) :=
Z.toFiberBundleCore.topologicalSpaceFiber x
#align vector_bundle_core.topological_space_fiber VectorBundleCore.topologicalSpaceFiber
-- Porting note: fixed: used to assume both `[NormedAddCommGroup F]` and `[AddCommGroupCat F]`
instance addCommGroupFiber (x : B) : AddCommGroup (Z.Fiber x) :=
inferInstanceAs (AddCommGroup F)
#align vector_bundle_core.add_comm_group_fiber VectorBundleCore.addCommGroupFiber
instance moduleFiber (x : B) : Module R (Z.Fiber x) :=
inferInstanceAs (Module R F)
#align vector_bundle_core.module_fiber VectorBundleCore.moduleFiber
/-- The projection from the total space of a fiber bundle core, on its base. -/
@[reducible, simp, mfld_simps]
protected def proj : TotalSpace F Z.Fiber → B :=
TotalSpace.proj
#align vector_bundle_core.proj VectorBundleCore.proj
/-- The total space of the vector bundle, as a convenience function for dot notation.
It is by definition equal to `Bundle.TotalSpace F Z.Fiber`. -/
@[nolint unusedArguments, reducible]
protected def TotalSpace :=
Bundle.TotalSpace F Z.Fiber
#align vector_bundle_core.total_space VectorBundleCore.TotalSpace
/-- Local homeomorphism version of the trivialization change. -/
def trivChange (i j : ι) : PartialHomeomorph (B × F) (B × F) :=
Z.toFiberBundleCore.trivChange i j
#align vector_bundle_core.triv_change VectorBundleCore.trivChange
@[simp, mfld_simps]
theorem mem_trivChange_source (i j : ι) (p : B × F) :
p ∈ (Z.trivChange i j).source ↔ p.1 ∈ Z.baseSet i ∩ Z.baseSet j :=
Z.toFiberBundleCore.mem_trivChange_source i j p
#align vector_bundle_core.mem_triv_change_source VectorBundleCore.mem_trivChange_source
/-- Topological structure on the total space of a vector bundle created from core, designed so
that all the local trivialization are continuous. -/
instance toTopologicalSpace : TopologicalSpace Z.TotalSpace :=
Z.toFiberBundleCore.toTopologicalSpace
#align vector_bundle_core.to_topological_space VectorBundleCore.toTopologicalSpace
variable (b : B) (a : F)
@[simp, mfld_simps]
theorem coe_coordChange (i j : ι) : Z.toFiberBundleCore.coordChange i j b = Z.coordChange i j b :=
rfl
#align vector_bundle_core.coe_coord_change VectorBundleCore.coe_coordChange
/-- One of the standard local trivializations of a vector bundle constructed from core, taken by
considering this in particular as a fiber bundle constructed from core. -/
def localTriv (i : ι) : Trivialization F (π F Z.Fiber) :=
Z.toFiberBundleCore.localTriv i
#align vector_bundle_core.local_triv VectorBundleCore.localTriv
-- Porting note: moved from below to fix the next instance
@[simp, mfld_simps]
theorem localTriv_apply {i : ι} (p : Z.TotalSpace) :
(Z.localTriv i) p = ⟨p.1, Z.coordChange (Z.indexAt p.1) i p.1 p.2⟩ :=
rfl
#align vector_bundle_core.local_triv_apply VectorBundleCore.localTriv_apply
/-- The standard local trivializations of a vector bundle constructed from core are linear. -/
instance localTriv.isLinear (i : ι) : (Z.localTriv i).IsLinear R where
linear x _ :=
{ map_add := fun _ _ => by simp only [map_add, localTriv_apply, mfld_simps]
map_smul := fun _ _ => by simp only [map_smul, localTriv_apply, mfld_simps] }
#align vector_bundle_core.local_triv.is_linear VectorBundleCore.localTriv.isLinear
variable (i j : ι)
@[simp, mfld_simps]
theorem mem_localTriv_source (p : Z.TotalSpace) : p ∈ (Z.localTriv i).source ↔ p.1 ∈ Z.baseSet i :=
Iff.rfl
#align vector_bundle_core.mem_local_triv_source VectorBundleCore.mem_localTriv_source
@[simp, mfld_simps]
theorem baseSet_at : Z.baseSet i = (Z.localTriv i).baseSet :=
rfl
#align vector_bundle_core.base_set_at VectorBundleCore.baseSet_at
@[simp, mfld_simps]
theorem mem_localTriv_target (p : B × F) :
p ∈ (Z.localTriv i).target ↔ p.1 ∈ (Z.localTriv i).baseSet :=
Z.toFiberBundleCore.mem_localTriv_target i p
#align vector_bundle_core.mem_local_triv_target VectorBundleCore.mem_localTriv_target
@[simp, mfld_simps]
theorem localTriv_symm_fst (p : B × F) :
(Z.localTriv i).toPartialHomeomorph.symm p = ⟨p.1, Z.coordChange i (Z.indexAt p.1) p.1 p.2⟩ :=
rfl
#align vector_bundle_core.local_triv_symm_fst VectorBundleCore.localTriv_symm_fst
@[simp, mfld_simps]
| Mathlib/Topology/VectorBundle/Basic.lean | 719 | 721 | theorem localTriv_symm_apply {b : B} (hb : b ∈ Z.baseSet i) (v : F) :
(Z.localTriv i).symm b v = Z.coordChange i (Z.indexAt b) b v := by |
apply (Z.localTriv i).symm_apply hb v
|
/-
Copyright (c) 2022 Antoine Labelle, Rémi Bottinelli. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Labelle, Rémi Bottinelli
-/
import Mathlib.Combinatorics.Quiver.Cast
import Mathlib.Combinatorics.Quiver.Symmetric
import Mathlib.Data.Sigma.Basic
import Mathlib.Logic.Equiv.Basic
import Mathlib.Tactic.Common
#align_import combinatorics.quiver.covering from "leanprover-community/mathlib"@"188a411e916e1119e502dbe35b8b475716362401"
/-!
# Covering
This file defines coverings of quivers as prefunctors that are bijective on the
so-called stars and costars at each vertex of the domain.
## Main definitions
* `Quiver.Star u` is the type of all arrows with source `u`;
* `Quiver.Costar u` is the type of all arrows with target `u`;
* `Prefunctor.star φ u` is the obvious function `star u → star (φ.obj u)`;
* `Prefunctor.costar φ u` is the obvious function `costar u → costar (φ.obj u)`;
* `Prefunctor.IsCovering φ` means that `φ.star u` and `φ.costar u` are bijections for all `u`;
* `Quiver.PathStar u` is the type of all paths with source `u`;
* `Prefunctor.pathStar u` is the obvious function `PathStar u → PathStar (φ.obj u)`.
## Main statements
* `Prefunctor.IsCovering.pathStar_bijective` states that if `φ` is a covering,
then `φ.pathStar u` is a bijection for all `u`.
In other words, every path in the codomain of `φ` lifts uniquely to its domain.
## TODO
Clean up the namespaces by renaming `Prefunctor` to `Quiver.Prefunctor`.
## Tags
Cover, covering, quiver, path, lift
-/
open Function Quiver
universe u v w
variable {U : Type _} [Quiver.{u + 1} U] {V : Type _} [Quiver.{v + 1} V] (φ : U ⥤q V) {W : Type _}
[Quiver.{w + 1} W] (ψ : V ⥤q W)
/-- The `Quiver.Star` at a vertex is the collection of arrows whose source is the vertex.
The type `Quiver.Star u` is defined to be `Σ (v : U), (u ⟶ v)`. -/
abbrev Quiver.Star (u : U) :=
Σ v : U, u ⟶ v
#align quiver.star Quiver.Star
/-- Constructor for `Quiver.Star`. Defined to be `Sigma.mk`. -/
protected abbrev Quiver.Star.mk {u v : U} (f : u ⟶ v) : Quiver.Star u :=
⟨_, f⟩
#align quiver.star.mk Quiver.Star.mk
/-- The `Quiver.Costar` at a vertex is the collection of arrows whose target is the vertex.
The type `Quiver.Costar v` is defined to be `Σ (u : U), (u ⟶ v)`. -/
abbrev Quiver.Costar (v : U) :=
Σ u : U, u ⟶ v
#align quiver.costar Quiver.Costar
/-- Constructor for `Quiver.Costar`. Defined to be `Sigma.mk`. -/
protected abbrev Quiver.Costar.mk {u v : U} (f : u ⟶ v) : Quiver.Costar v :=
⟨_, f⟩
#align quiver.costar.mk Quiver.Costar.mk
/-- A prefunctor induces a map of `Quiver.Star` at every vertex. -/
@[simps]
def Prefunctor.star (u : U) : Quiver.Star u → Quiver.Star (φ.obj u) := fun F =>
Quiver.Star.mk (φ.map F.2)
#align prefunctor.star Prefunctor.star
/-- A prefunctor induces a map of `Quiver.Costar` at every vertex. -/
@[simps]
def Prefunctor.costar (u : U) : Quiver.Costar u → Quiver.Costar (φ.obj u) := fun F =>
Quiver.Costar.mk (φ.map F.2)
#align prefunctor.costar Prefunctor.costar
@[simp]
theorem Prefunctor.star_apply {u v : U} (e : u ⟶ v) :
φ.star u (Quiver.Star.mk e) = Quiver.Star.mk (φ.map e) :=
rfl
#align prefunctor.star_apply Prefunctor.star_apply
@[simp]
theorem Prefunctor.costar_apply {u v : U} (e : u ⟶ v) :
φ.costar v (Quiver.Costar.mk e) = Quiver.Costar.mk (φ.map e) :=
rfl
#align prefunctor.costar_apply Prefunctor.costar_apply
theorem Prefunctor.star_comp (u : U) : (φ ⋙q ψ).star u = ψ.star (φ.obj u) ∘ φ.star u :=
rfl
#align prefunctor.star_comp Prefunctor.star_comp
theorem Prefunctor.costar_comp (u : U) : (φ ⋙q ψ).costar u = ψ.costar (φ.obj u) ∘ φ.costar u :=
rfl
#align prefunctor.costar_comp Prefunctor.costar_comp
/-- A prefunctor is a covering of quivers if it defines bijections on all stars and costars. -/
protected structure Prefunctor.IsCovering : Prop where
star_bijective : ∀ u, Bijective (φ.star u)
costar_bijective : ∀ u, Bijective (φ.costar u)
#align prefunctor.is_covering Prefunctor.IsCovering
@[simp]
theorem Prefunctor.IsCovering.map_injective (hφ : φ.IsCovering) {u v : U} :
Injective fun f : u ⟶ v => φ.map f := by
rintro f g he
have : φ.star u (Quiver.Star.mk f) = φ.star u (Quiver.Star.mk g) := by simpa using he
simpa using (hφ.star_bijective u).left this
#align prefunctor.is_covering.map_injective Prefunctor.IsCovering.map_injective
theorem Prefunctor.IsCovering.comp (hφ : φ.IsCovering) (hψ : ψ.IsCovering) : (φ ⋙q ψ).IsCovering :=
⟨fun _ => (hψ.star_bijective _).comp (hφ.star_bijective _),
fun _ => (hψ.costar_bijective _).comp (hφ.costar_bijective _)⟩
#align prefunctor.is_covering.comp Prefunctor.IsCovering.comp
theorem Prefunctor.IsCovering.of_comp_right (hψ : ψ.IsCovering) (hφψ : (φ ⋙q ψ).IsCovering) :
φ.IsCovering :=
⟨fun _ => (Bijective.of_comp_iff' (hψ.star_bijective _) _).mp (hφψ.star_bijective _),
fun _ => (Bijective.of_comp_iff' (hψ.costar_bijective _) _).mp (hφψ.costar_bijective _)⟩
#align prefunctor.is_covering.of_comp_right Prefunctor.IsCovering.of_comp_right
theorem Prefunctor.IsCovering.of_comp_left (hφ : φ.IsCovering) (hφψ : (φ ⋙q ψ).IsCovering)
(φsur : Surjective φ.obj) : ψ.IsCovering := by
refine ⟨fun v => ?_, fun v => ?_⟩ <;> obtain ⟨u, rfl⟩ := φsur v
exacts [(Bijective.of_comp_iff _ (hφ.star_bijective u)).mp (hφψ.star_bijective u),
(Bijective.of_comp_iff _ (hφ.costar_bijective u)).mp (hφψ.costar_bijective u)]
#align prefunctor.is_covering.of_comp_left Prefunctor.IsCovering.of_comp_left
/-- The star of the symmetrification of a quiver at a vertex `u` is equivalent to the sum of the
star and the costar at `u` in the original quiver. -/
def Quiver.symmetrifyStar (u : U) :
Quiver.Star (Symmetrify.of.obj u) ≃ Sum (Quiver.Star u) (Quiver.Costar u) :=
Equiv.sigmaSumDistrib _ _
#align quiver.symmetrify_star Quiver.symmetrifyStar
/-- The costar of the symmetrification of a quiver at a vertex `u` is equivalent to the sum of the
costar and the star at `u` in the original quiver. -/
def Quiver.symmetrifyCostar (u : U) :
Quiver.Costar (Symmetrify.of.obj u) ≃ Sum (Quiver.Costar u) (Quiver.Star u) :=
Equiv.sigmaSumDistrib _ _
#align quiver.symmetrify_costar Quiver.symmetrifyCostar
theorem Prefunctor.symmetrifyStar (u : U) :
φ.symmetrify.star u =
(Quiver.symmetrifyStar _).symm ∘ Sum.map (φ.star u) (φ.costar u) ∘
Quiver.symmetrifyStar u := by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [Equiv.eq_symm_comp]
ext ⟨v, f | g⟩ <;>
-- porting note (#10745): was `simp [Quiver.symmetrifyStar]`
simp only [Quiver.symmetrifyStar, Function.comp_apply] <;>
erw [Equiv.sigmaSumDistrib_apply, Equiv.sigmaSumDistrib_apply] <;>
simp
#align prefunctor.symmetrify_star Prefunctor.symmetrifyStar
protected theorem Prefunctor.symmetrifyCostar (u : U) :
φ.symmetrify.costar u =
(Quiver.symmetrifyCostar _).symm ∘
Sum.map (φ.costar u) (φ.star u) ∘ Quiver.symmetrifyCostar u := by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [Equiv.eq_symm_comp]
ext ⟨v, f | g⟩ <;>
-- porting note (#10745): was `simp [Quiver.symmetrifyCostar]`
simp only [Quiver.symmetrifyCostar, Function.comp_apply] <;>
erw [Equiv.sigmaSumDistrib_apply, Equiv.sigmaSumDistrib_apply] <;>
simp
#align prefunctor.symmetrify_costar Prefunctor.symmetrifyCostar
protected theorem Prefunctor.IsCovering.symmetrify (hφ : φ.IsCovering) :
φ.symmetrify.IsCovering := by
refine ⟨fun u => ?_, fun u => ?_⟩ <;>
-- Porting note: was
-- simp [φ.symmetrifyStar, φ.symmetrifyCostar, hφ.star_bijective u, hφ.costar_bijective u]
simp only [φ.symmetrifyStar, φ.symmetrifyCostar] <;>
erw [EquivLike.comp_bijective, EquivLike.bijective_comp] <;>
simp [hφ.star_bijective u, hφ.costar_bijective u]
#align prefunctor.is_covering.symmetrify Prefunctor.IsCovering.symmetrify
/-- The path star at a vertex `u` is the type of all paths starting at `u`.
The type `Quiver.PathStar u` is defined to be `Σ v : U, Path u v`. -/
abbrev Quiver.PathStar (u : U) :=
Σ v : U, Path u v
#align quiver.path_star Quiver.PathStar
/-- Constructor for `Quiver.PathStar`. Defined to be `Sigma.mk`. -/
protected abbrev Quiver.PathStar.mk {u v : U} (p : Path u v) : Quiver.PathStar u :=
⟨_, p⟩
#align quiver.path_star.mk Quiver.PathStar.mk
/-- A prefunctor induces a map of path stars. -/
def Prefunctor.pathStar (u : U) : Quiver.PathStar u → Quiver.PathStar (φ.obj u) := fun p =>
Quiver.PathStar.mk (φ.mapPath p.2)
#align prefunctor.path_star Prefunctor.pathStar
@[simp]
theorem Prefunctor.pathStar_apply {u v : U} (p : Path u v) :
φ.pathStar u (Quiver.PathStar.mk p) = Quiver.PathStar.mk (φ.mapPath p) :=
rfl
#align prefunctor.path_star_apply Prefunctor.pathStar_apply
theorem Prefunctor.pathStar_injective (hφ : ∀ u, Injective (φ.star u)) (u : U) :
Injective (φ.pathStar u) := by
dsimp (config := { unfoldPartialApp := true }) [Prefunctor.pathStar, Quiver.PathStar.mk]
rintro ⟨v₁, p₁⟩
induction' p₁ with x₁ y₁ p₁ e₁ ih <;>
rintro ⟨y₂, p₂⟩ <;>
cases' p₂ with x₂ _ p₂ e₂ <;>
intro h <;>
-- Porting note: added `Sigma.mk.inj_iff`
simp only [Prefunctor.pathStar_apply, Prefunctor.mapPath_nil, Prefunctor.mapPath_cons,
Sigma.mk.inj_iff] at h
· -- Porting note: goal not present in lean3.
rfl
· exfalso
cases' h with h h'
rw [← Path.eq_cast_iff_heq rfl h.symm, Path.cast_cons] at h'
exact (Path.nil_ne_cons _ _) h'
· exfalso
cases' h with h h'
rw [← Path.cast_eq_iff_heq rfl h, Path.cast_cons] at h'
exact (Path.cons_ne_nil _ _) h'
· cases' h with hφy h'
rw [← Path.cast_eq_iff_heq rfl hφy, Path.cast_cons, Path.cast_rfl_rfl] at h'
have hφx := Path.obj_eq_of_cons_eq_cons h'
have hφp := Path.heq_of_cons_eq_cons h'
have hφe := HEq.trans (Hom.cast_heq rfl hφy _).symm (Path.hom_heq_of_cons_eq_cons h')
have h_path_star : φ.pathStar u ⟨x₁, p₁⟩ = φ.pathStar u ⟨x₂, p₂⟩ := by
simp only [Prefunctor.pathStar_apply, Sigma.mk.inj_iff]; exact ⟨hφx, hφp⟩
cases ih h_path_star
have h_star : φ.star x₁ ⟨y₁, e₁⟩ = φ.star x₁ ⟨y₂, e₂⟩ := by
simp only [Prefunctor.star_apply, Sigma.mk.inj_iff]; exact ⟨hφy, hφe⟩
cases hφ x₁ h_star
rfl
#align prefunctor.path_star_injective Prefunctor.pathStar_injective
theorem Prefunctor.pathStar_surjective (hφ : ∀ u, Surjective (φ.star u)) (u : U) :
Surjective (φ.pathStar u) := by
dsimp (config := { unfoldPartialApp := true }) [Prefunctor.pathStar, Quiver.PathStar.mk]
rintro ⟨v, p⟩
induction' p with v' v'' p' ev ih
· use ⟨u, Path.nil⟩
simp only [Prefunctor.mapPath_nil, eq_self_iff_true, heq_iff_eq, and_self_iff]
· obtain ⟨⟨u', q'⟩, h⟩ := ih
simp only at h
obtain ⟨rfl, rfl⟩ := h
obtain ⟨⟨u'', eu⟩, k⟩ := hφ u' ⟨_, ev⟩
simp only [star_apply, Sigma.mk.inj_iff] at k
-- Porting note: was `obtain ⟨rfl, rfl⟩ := k`
obtain ⟨rfl, k⟩ := k
simp only [heq_eq_eq] at k
subst k
use ⟨_, q'.cons eu⟩
simp only [Prefunctor.mapPath_cons, eq_self_iff_true, heq_iff_eq, and_self_iff]
#align prefunctor.path_star_surjective Prefunctor.pathStar_surjective
theorem Prefunctor.pathStar_bijective (hφ : ∀ u, Bijective (φ.star u)) (u : U) :
Bijective (φ.pathStar u) :=
⟨φ.pathStar_injective (fun u => (hφ u).1) _, φ.pathStar_surjective (fun u => (hφ u).2) _⟩
#align prefunctor.path_star_bijective Prefunctor.pathStar_bijective
namespace Prefunctor.IsCovering
variable {φ}
protected theorem pathStar_bijective (hφ : φ.IsCovering) (u : U) : Bijective (φ.pathStar u) :=
φ.pathStar_bijective hφ.1 u
#align prefunctor.is_covering.path_star_bijective Prefunctor.IsCovering.pathStar_bijective
end Prefunctor.IsCovering
section HasInvolutiveReverse
variable [HasInvolutiveReverse U] [HasInvolutiveReverse V] [Prefunctor.MapReverse φ]
/-- In a quiver with involutive inverses, the star and costar at every vertex are equivalent.
This map is induced by `Quiver.reverse`. -/
@[simps]
def Quiver.starEquivCostar (u : U) : Quiver.Star u ≃ Quiver.Costar u where
toFun e := ⟨e.1, reverse e.2⟩
invFun e := ⟨e.1, reverse e.2⟩
left_inv e := by simp [Sigma.ext_iff]
right_inv e := by simp [Sigma.ext_iff]
#align quiver.star_equiv_costar Quiver.starEquivCostar
@[simp]
theorem Quiver.starEquivCostar_apply {u v : U} (e : u ⟶ v) :
Quiver.starEquivCostar u (Quiver.Star.mk e) = Quiver.Costar.mk (reverse e) :=
rfl
#align quiver.star_equiv_costar_apply Quiver.starEquivCostar_apply
@[simp]
theorem Quiver.starEquivCostar_symm_apply {u v : U} (e : u ⟶ v) :
(Quiver.starEquivCostar v).symm (Quiver.Costar.mk e) = Quiver.Star.mk (reverse e) :=
rfl
#align quiver.star_equiv_costar_symm_apply Quiver.starEquivCostar_symm_apply
| Mathlib/Combinatorics/Quiver/Covering.lean | 307 | 309 | theorem Prefunctor.costar_conj_star (u : U) :
φ.costar u = Quiver.starEquivCostar (φ.obj u) ∘ φ.star u ∘ (Quiver.starEquivCostar u).symm := by |
ext ⟨v, f⟩ <;> simp
|
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Antichain
import Mathlib.Order.UpperLower.Basic
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Order.RelIso.Set
#align_import order.minimal from "leanprover-community/mathlib"@"59694bd07f0a39c5beccba34bd9f413a160782bf"
/-!
# Minimal/maximal elements of a set
This file defines minimal and maximal of a set with respect to an arbitrary relation.
## Main declarations
* `maximals r s`: Maximal elements of `s` with respect to `r`.
* `minimals r s`: Minimal elements of `s` with respect to `r`.
## TODO
Do we need a `Finset` version?
-/
open Function Set
variable {α : Type*} (r r₁ r₂ : α → α → Prop) (s t : Set α) (a b : α)
/-- Turns a set into an antichain by keeping only the "maximal" elements. -/
def maximals : Set α :=
{ a ∈ s | ∀ ⦃b⦄, b ∈ s → r a b → r b a }
#align maximals maximals
/-- Turns a set into an antichain by keeping only the "minimal" elements. -/
def minimals : Set α :=
{ a ∈ s | ∀ ⦃b⦄, b ∈ s → r b a → r a b }
#align minimals minimals
theorem maximals_subset : maximals r s ⊆ s :=
sep_subset _ _
#align maximals_subset maximals_subset
theorem minimals_subset : minimals r s ⊆ s :=
sep_subset _ _
#align minimals_subset minimals_subset
@[simp]
theorem maximals_empty : maximals r ∅ = ∅ :=
sep_empty _
#align maximals_empty maximals_empty
@[simp]
theorem minimals_empty : minimals r ∅ = ∅ :=
sep_empty _
#align minimals_empty minimals_empty
@[simp]
theorem maximals_singleton : maximals r {a} = {a} :=
(maximals_subset _ _).antisymm <|
singleton_subset_iff.2 <|
⟨rfl, by
rintro b (rfl : b = a)
exact id⟩
#align maximals_singleton maximals_singleton
@[simp]
theorem minimals_singleton : minimals r {a} = {a} :=
maximals_singleton _ _
#align minimals_singleton minimals_singleton
theorem maximals_swap : maximals (swap r) s = minimals r s :=
rfl
#align maximals_swap maximals_swap
theorem minimals_swap : minimals (swap r) s = maximals r s :=
rfl
#align minimals_swap minimals_swap
section IsAntisymm
variable {r s t a b} [IsAntisymm α r]
theorem eq_of_mem_maximals (ha : a ∈ maximals r s) (hb : b ∈ s) (h : r a b) : a = b :=
antisymm h <| ha.2 hb h
#align eq_of_mem_maximals eq_of_mem_maximals
theorem eq_of_mem_minimals (ha : a ∈ minimals r s) (hb : b ∈ s) (h : r b a) : a = b :=
antisymm (ha.2 hb h) h
#align eq_of_mem_minimals eq_of_mem_minimals
set_option autoImplicit true
theorem mem_maximals_iff : x ∈ maximals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → r x y → x = y := by
simp only [maximals, Set.mem_sep_iff, and_congr_right_iff]
refine fun _ ↦ ⟨fun h y hys hxy ↦ antisymm hxy (h hys hxy), fun h y hys hxy ↦ ?_⟩
convert hxy <;> rw [h hys hxy]
theorem mem_maximals_setOf_iff : x ∈ maximals r (setOf P) ↔ P x ∧ ∀ ⦃y⦄, P y → r x y → x = y :=
mem_maximals_iff
theorem mem_minimals_iff : x ∈ minimals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, y ∈ s → r y x → x = y :=
@mem_maximals_iff _ _ _ (IsAntisymm.swap r) _
theorem mem_minimals_setOf_iff : x ∈ minimals r (setOf P) ↔ P x ∧ ∀ ⦃y⦄, P y → r y x → x = y :=
mem_minimals_iff
/-- This theorem can't be used to rewrite without specifying `rlt`, since `rlt` would have to be
guessed. See `mem_minimals_iff_forall_ssubset_not_mem` and `mem_minimals_iff_forall_lt_not_mem`
for `⊆` and `≤` versions. -/
| Mathlib/Order/Minimal.lean | 113 | 115 | theorem mem_minimals_iff_forall_lt_not_mem' (rlt : α → α → Prop) [IsNonstrictStrictOrder α r rlt] :
x ∈ minimals r s ↔ x ∈ s ∧ ∀ ⦃y⦄, rlt y x → y ∉ s := by |
simp [minimals, right_iff_left_not_left_of r rlt, not_imp_not, imp.swap (a := _ ∈ _)]
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Group.Submonoid.Membership
import Mathlib.Data.Finsupp.Fin
import Mathlib.Data.Finsupp.Indicator
#align_import algebra.big_operators.finsupp from "leanprover-community/mathlib"@"842328d9df7e96fd90fc424e115679c15fb23a71"
/-!
# Big operators for finsupps
This file contains theorems relevant to big operators in finitely supported functions.
-/
noncomputable section
open Finset Function
variable {α ι γ A B C : Type*} [AddCommMonoid A] [AddCommMonoid B] [AddCommMonoid C]
variable {t : ι → A → C} (h0 : ∀ i, t i 0 = 0) (h1 : ∀ i x y, t i (x + y) = t i x + t i y)
variable {s : Finset α} {f : α → ι →₀ A} (i : ι)
variable (g : ι →₀ A) (k : ι → A → γ → B) (x : γ)
variable {β M M' N P G H R S : Type*}
namespace Finsupp
/-!
### Declarations about `Finsupp.sum` and `Finsupp.prod`
In most of this section, the domain `β` is assumed to be an `AddMonoid`.
-/
section SumProd
/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/
@[to_additive "`sum f g` is the sum of `g a (f a)` over the support of `f`. "]
def prod [Zero M] [CommMonoid N] (f : α →₀ M) (g : α → M → N) : N :=
∏ a ∈ f.support, g a (f a)
#align finsupp.prod Finsupp.prod
#align finsupp.sum Finsupp.sum
variable [Zero M] [Zero M'] [CommMonoid N]
@[to_additive]
theorem prod_of_support_subset (f : α →₀ M) {s : Finset α} (hs : f.support ⊆ s) (g : α → M → N)
(h : ∀ i ∈ s, g i 0 = 1) : f.prod g = ∏ x ∈ s, g x (f x) := by
refine Finset.prod_subset hs fun x hxs hx => h x hxs ▸ (congr_arg (g x) ?_)
exact not_mem_support_iff.1 hx
#align finsupp.prod_of_support_subset Finsupp.prod_of_support_subset
#align finsupp.sum_of_support_subset Finsupp.sum_of_support_subset
@[to_additive]
theorem prod_fintype [Fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :
f.prod g = ∏ i, g i (f i) :=
f.prod_of_support_subset (subset_univ _) g fun x _ => h x
#align finsupp.prod_fintype Finsupp.prod_fintype
#align finsupp.sum_fintype Finsupp.sum_fintype
@[to_additive (attr := simp)]
theorem prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :
(single a b).prod h = h a b :=
calc
(single a b).prod h = ∏ x ∈ {a}, h x (single a b x) :=
prod_of_support_subset _ support_single_subset h fun x hx =>
(mem_singleton.1 hx).symm ▸ h_zero
_ = h a b := by simp
#align finsupp.prod_single_index Finsupp.prod_single_index
#align finsupp.sum_single_index Finsupp.sum_single_index
@[to_additive]
theorem prod_mapRange_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}
(h0 : ∀ a, h a 0 = 1) : (mapRange f hf g).prod h = g.prod fun a b => h a (f b) :=
Finset.prod_subset support_mapRange fun _ _ H => by rw [not_mem_support_iff.1 H, h0]
#align finsupp.prod_map_range_index Finsupp.prod_mapRange_index
#align finsupp.sum_map_range_index Finsupp.sum_mapRange_index
@[to_additive (attr := simp)]
theorem prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 :=
rfl
#align finsupp.prod_zero_index Finsupp.prod_zero_index
#align finsupp.sum_zero_index Finsupp.sum_zero_index
@[to_additive]
theorem prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :
(f.prod fun x v => g.prod fun x' v' => h x v x' v') =
g.prod fun x' v' => f.prod fun x v => h x v x' v' :=
Finset.prod_comm
#align finsupp.prod_comm Finsupp.prod_comm
#align finsupp.sum_comm Finsupp.sum_comm
@[to_additive (attr := simp)]
theorem prod_ite_eq [DecidableEq α] (f : α →₀ M) (a : α) (b : α → M → N) :
(f.prod fun x v => ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 := by
dsimp [Finsupp.prod]
rw [f.support.prod_ite_eq]
#align finsupp.prod_ite_eq Finsupp.prod_ite_eq
#align finsupp.sum_ite_eq Finsupp.sum_ite_eq
/- Porting note: simpnf linter, added aux lemma below
Left-hand side simplifies from
Finsupp.sum f fun x v => if a = x then v else 0
to
if ↑f a = 0 then 0 else ↑f a
-/
-- @[simp]
theorem sum_ite_self_eq [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :
(f.sum fun x v => ite (a = x) v 0) = f a := by
classical
convert f.sum_ite_eq a fun _ => id
simp [ite_eq_right_iff.2 Eq.symm]
#align finsupp.sum_ite_self_eq Finsupp.sum_ite_self_eq
-- Porting note: Added this thm to replace the simp in the previous one. Need to add [DecidableEq N]
@[simp]
| Mathlib/Algebra/BigOperators/Finsupp.lean | 124 | 127 | theorem sum_ite_self_eq_aux [DecidableEq α] {N : Type*} [AddCommMonoid N] (f : α →₀ N) (a : α) :
(if a ∈ f.support then f a else 0) = f a := by |
simp only [mem_support_iff, ne_eq, ite_eq_left_iff, not_not]
exact fun h ↦ h.symm
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel,
Rémy Degenne, David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Complex
import Qq
#align_import analysis.special_functions.pow.real from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8"
/-! # Power function on `ℝ`
We construct the power functions `x ^ y`, where `x` and `y` are real numbers.
-/
noncomputable section
open scoped Classical
open Real ComplexConjugate
open Finset Set
/-
## Definitions
-/
namespace Real
variable {x y z : ℝ}
/-- The real power function `x ^ y`, defined as the real part of the complex power function.
For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for
`y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex
determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/
noncomputable def rpow (x y : ℝ) :=
((x : ℂ) ^ (y : ℂ)).re
#align real.rpow Real.rpow
noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl
#align real.rpow_eq_pow Real.rpow_eq_pow
theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl
#align real.rpow_def Real.rpow_def
theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) :
x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by
simp only [rpow_def, Complex.cpow_def]; split_ifs <;>
simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, -RCLike.ofReal_mul,
(Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero]
#align real.rpow_def_of_nonneg Real.rpow_def_of_nonneg
theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by
rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)]
#align real.rpow_def_of_pos Real.rpow_def_of_pos
theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp]
#align real.exp_mul Real.exp_mul
@[simp, norm_cast]
theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast,
Complex.ofReal_re]
#align real.rpow_int_cast Real.rpow_intCast
@[deprecated (since := "2024-04-17")]
alias rpow_int_cast := rpow_intCast
@[simp, norm_cast]
theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n
#align real.rpow_nat_cast Real.rpow_natCast
@[deprecated (since := "2024-04-17")]
alias rpow_nat_cast := rpow_natCast
@[simp]
theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul]
#align real.exp_one_rpow Real.exp_one_rpow
@[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow]
theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by
simp only [rpow_def_of_nonneg hx]
split_ifs <;> simp [*, exp_ne_zero]
#align real.rpow_eq_zero_iff_of_nonneg Real.rpow_eq_zero_iff_of_nonneg
@[simp]
lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by
simp [rpow_eq_zero_iff_of_nonneg, *]
@[simp]
lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 :=
Real.rpow_eq_zero hx hy |>.not
open Real
theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by
rw [rpow_def, Complex.cpow_def, if_neg]
· have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by
simp only [Complex.log, abs_of_neg hx, Complex.arg_ofReal_of_neg hx, Complex.abs_ofReal,
Complex.ofReal_mul]
ring
rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ←
Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul,
Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im,
Real.log_neg_eq_log]
ring
· rw [Complex.ofReal_eq_zero]
exact ne_of_lt hx
#align real.rpow_def_of_neg Real.rpow_def_of_neg
theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) :
x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by
split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _
#align real.rpow_def_of_nonpos Real.rpow_def_of_nonpos
theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by
rw [rpow_def_of_pos hx]; apply exp_pos
#align real.rpow_pos_of_pos Real.rpow_pos_of_pos
@[simp]
theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def]
#align real.rpow_zero Real.rpow_zero
theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp
@[simp]
theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *]
#align real.zero_rpow Real.zero_rpow
theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by
constructor
· intro hyp
simp only [rpow_def, Complex.ofReal_zero] at hyp
by_cases h : x = 0
· subst h
simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp
exact Or.inr ⟨rfl, hyp.symm⟩
· rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp
exact Or.inl ⟨h, hyp.symm⟩
· rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩)
· exact zero_rpow h
· exact rpow_zero _
#align real.zero_rpow_eq_iff Real.zero_rpow_eq_iff
theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by
rw [← zero_rpow_eq_iff, eq_comm]
#align real.eq_zero_rpow_iff Real.eq_zero_rpow_iff
@[simp]
theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def]
#align real.rpow_one Real.rpow_one
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def]
#align real.one_rpow Real.one_rpow
theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by
by_cases h : x = 0 <;> simp [h, zero_le_one]
#align real.zero_rpow_le_one Real.zero_rpow_le_one
theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by
by_cases h : x = 0 <;> simp [h, zero_le_one]
#align real.zero_rpow_nonneg Real.zero_rpow_nonneg
theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by
rw [rpow_def_of_nonneg hx]; split_ifs <;>
simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)]
#align real.rpow_nonneg_of_nonneg Real.rpow_nonneg
theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by
have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _
rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg]
#align real.abs_rpow_of_nonneg Real.abs_rpow_of_nonneg
theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≤ |x| ^ y := by
rcases le_or_lt 0 x with hx | hx
· rw [abs_rpow_of_nonneg hx]
· rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul,
abs_of_pos (exp_pos _)]
exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _)
#align real.abs_rpow_le_abs_rpow Real.abs_rpow_le_abs_rpow
theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≤ exp (log x * y) := by
refine (abs_rpow_le_abs_rpow x y).trans ?_
by_cases hx : x = 0
· by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one]
· rw [rpow_def_of_pos (abs_pos.2 hx), log_abs]
#align real.abs_rpow_le_exp_log_mul Real.abs_rpow_le_exp_log_mul
theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : ‖x ^ y‖ = ‖x‖ ^ y := by
simp_rw [Real.norm_eq_abs]
exact abs_rpow_of_nonneg hx_nonneg
#align real.norm_rpow_of_nonneg Real.norm_rpow_of_nonneg
variable {w x y z : ℝ}
theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by
simp only [rpow_def_of_pos hx, mul_add, exp_add]
#align real.rpow_add Real.rpow_add
theorem rpow_add' (hx : 0 ≤ x) (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by
rcases hx.eq_or_lt with (rfl | pos)
· rw [zero_rpow h, zero_eq_mul]
have : y ≠ 0 ∨ z ≠ 0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm ▸ hz.symm ▸ zero_add 0
exact this.imp zero_rpow zero_rpow
· exact rpow_add pos _ _
#align real.rpow_add' Real.rpow_add'
/-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/
lemma rpow_of_add_eq (hx : 0 ≤ x) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by
rw [← h, rpow_add' hx]; rwa [h]
theorem rpow_add_of_nonneg (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 ≤ z) :
x ^ (y + z) = x ^ y * x ^ z := by
rcases hy.eq_or_lt with (rfl | hy)
· rw [zero_add, rpow_zero, one_mul]
exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz)
#align real.rpow_add_of_nonneg Real.rpow_add_of_nonneg
/-- For `0 ≤ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for
`x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish.
The inequality is always true, though, and given in this lemma. -/
theorem le_rpow_add {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ y * x ^ z ≤ x ^ (y + z) := by
rcases le_iff_eq_or_lt.1 hx with (H | pos)
· by_cases h : y + z = 0
· simp only [H.symm, h, rpow_zero]
calc
(0 : ℝ) ^ y * 0 ^ z ≤ 1 * 1 :=
mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one
_ = 1 := by simp
· simp [rpow_add', ← H, h]
· simp [rpow_add pos]
#align real.le_rpow_add Real.le_rpow_add
theorem rpow_sum_of_pos {ι : Type*} {a : ℝ} (ha : 0 < a) (f : ι → ℝ) (s : Finset ι) :
(a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x :=
map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ →+ (Additive ℝ)) f s
#align real.rpow_sum_of_pos Real.rpow_sum_of_pos
theorem rpow_sum_of_nonneg {ι : Type*} {a : ℝ} (ha : 0 ≤ a) {s : Finset ι} {f : ι → ℝ}
(h : ∀ x ∈ s, 0 ≤ f x) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by
induction' s using Finset.cons_induction with i s hi ihs
· rw [sum_empty, Finset.prod_empty, rpow_zero]
· rw [forall_mem_cons] at h
rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)]
#align real.rpow_sum_of_nonneg Real.rpow_sum_of_nonneg
theorem rpow_neg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by
simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg]
#align real.rpow_neg Real.rpow_neg
theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by
simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv]
#align real.rpow_sub Real.rpow_sub
theorem rpow_sub' {x : ℝ} (hx : 0 ≤ x) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := by
simp only [sub_eq_add_neg] at h ⊢
simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv]
#align real.rpow_sub' Real.rpow_sub'
end Real
/-!
## Comparing real and complex powers
-/
namespace Complex
theorem ofReal_cpow {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : ((x ^ y : ℝ) : ℂ) = (x : ℂ) ^ (y : ℂ) := by
simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;>
simp [Complex.ofReal_log hx]
#align complex.of_real_cpow Complex.ofReal_cpow
theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℂ) :
(x : ℂ) ^ y = (-x : ℂ) ^ y * exp (π * I * y) := by
rcases hx.eq_or_lt with (rfl | hlt)
· rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*]
have hne : (x : ℂ) ≠ 0 := ofReal_ne_zero.mpr hlt.ne
rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log,
log, abs.map_neg, arg_ofReal_of_neg hlt, ← ofReal_neg,
arg_ofReal_of_nonneg (neg_nonneg.2 hx), ofReal_zero, zero_mul, add_zero]
#align complex.of_real_cpow_of_nonpos Complex.ofReal_cpow_of_nonpos
lemma cpow_ofReal (x : ℂ) (y : ℝ) :
x ^ (y : ℂ) = ↑(abs x ^ y) * (Real.cos (arg x * y) + Real.sin (arg x * y) * I) := by
rcases eq_or_ne x 0 with rfl | hx
· simp [ofReal_cpow le_rfl]
· rw [cpow_def_of_ne_zero hx, exp_eq_exp_re_mul_sin_add_cos, mul_comm (log x)]
norm_cast
rw [re_ofReal_mul, im_ofReal_mul, log_re, log_im, mul_comm y, mul_comm y, Real.exp_mul,
Real.exp_log]
rwa [abs.pos_iff]
lemma cpow_ofReal_re (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).re = (abs x) ^ y * Real.cos (arg x * y) := by
rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.cos]
lemma cpow_ofReal_im (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).im = (abs x) ^ y * Real.sin (arg x * y) := by
rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin]
theorem abs_cpow_of_ne_zero {z : ℂ} (hz : z ≠ 0) (w : ℂ) :
abs (z ^ w) = abs z ^ w.re / Real.exp (arg z * im w) := by
rw [cpow_def_of_ne_zero hz, abs_exp, mul_re, log_re, log_im, Real.exp_sub,
Real.rpow_def_of_pos (abs.pos hz)]
#align complex.abs_cpow_of_ne_zero Complex.abs_cpow_of_ne_zero
theorem abs_cpow_of_imp {z w : ℂ} (h : z = 0 → w.re = 0 → w = 0) :
abs (z ^ w) = abs z ^ w.re / Real.exp (arg z * im w) := by
rcases ne_or_eq z 0 with (hz | rfl) <;> [exact abs_cpow_of_ne_zero hz w; rw [map_zero]]
rcases eq_or_ne w.re 0 with hw | hw
· simp [hw, h rfl hw]
· rw [Real.zero_rpow hw, zero_div, zero_cpow, map_zero]
exact ne_of_apply_ne re hw
#align complex.abs_cpow_of_imp Complex.abs_cpow_of_imp
theorem abs_cpow_le (z w : ℂ) : abs (z ^ w) ≤ abs z ^ w.re / Real.exp (arg z * im w) := by
by_cases h : z = 0 → w.re = 0 → w = 0
· exact (abs_cpow_of_imp h).le
· push_neg at h
simp [h]
#align complex.abs_cpow_le Complex.abs_cpow_le
@[simp]
theorem abs_cpow_real (x : ℂ) (y : ℝ) : abs (x ^ (y : ℂ)) = Complex.abs x ^ y := by
rw [abs_cpow_of_imp] <;> simp
#align complex.abs_cpow_real Complex.abs_cpow_real
@[simp]
theorem abs_cpow_inv_nat (x : ℂ) (n : ℕ) : abs (x ^ (n⁻¹ : ℂ)) = Complex.abs x ^ (n⁻¹ : ℝ) := by
rw [← abs_cpow_real]; simp [-abs_cpow_real]
#align complex.abs_cpow_inv_nat Complex.abs_cpow_inv_nat
theorem abs_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : ℂ) : abs (x ^ y) = x ^ y.re := by
rw [abs_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le,
zero_mul, Real.exp_zero, div_one, abs_of_nonneg hx.le]
#align complex.abs_cpow_eq_rpow_re_of_pos Complex.abs_cpow_eq_rpow_re_of_pos
theorem abs_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≤ x) {y : ℂ} (hy : re y ≠ 0) :
abs (x ^ y) = x ^ re y := by
rw [abs_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, _root_.abs_of_nonneg]
#align complex.abs_cpow_eq_rpow_re_of_nonneg Complex.abs_cpow_eq_rpow_re_of_nonneg
lemma norm_natCast_cpow_of_re_ne_zero (n : ℕ) {s : ℂ} (hs : s.re ≠ 0) :
‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by
rw [norm_eq_abs, ← ofReal_natCast, abs_cpow_eq_rpow_re_of_nonneg n.cast_nonneg hs]
lemma norm_natCast_cpow_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) :
‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by
rw [norm_eq_abs, ← ofReal_natCast, abs_cpow_eq_rpow_re_of_pos (Nat.cast_pos.mpr hn) _]
lemma norm_natCast_cpow_pos_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : 0 < ‖(n : ℂ) ^ s‖ :=
(norm_natCast_cpow_of_pos hn _).symm ▸ Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _
theorem cpow_mul_ofReal_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (z : ℂ) :
(x : ℂ) ^ (↑y * z) = (↑(x ^ y) : ℂ) ^ z := by
rw [cpow_mul, ofReal_cpow hx]
· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im, neg_lt_zero]; exact Real.pi_pos
· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im]; exact Real.pi_pos.le
#align complex.cpow_mul_of_real_nonneg Complex.cpow_mul_ofReal_nonneg
end Complex
/-! ### Positivity extension -/
namespace Mathlib.Meta.Positivity
open Lean Meta Qq
/-- Extension for the `positivity` tactic: exponentiation by a real number is positive (namely 1)
when the exponent is zero. The other cases are done in `evalRpow`. -/
@[positivity (_ : ℝ) ^ (0 : ℝ)]
def evalRpowZero : PositivityExt where eval {u α} _ _ e := do
match u, α, e with
| 0, ~q(ℝ), ~q($a ^ (0 : ℝ)) =>
assertInstancesCommute
pure (.positive q(Real.rpow_zero_pos $a))
| _, _, _ => throwError "not Real.rpow"
/-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when
the base is nonnegative and positive when the base is positive. -/
@[positivity (_ : ℝ) ^ (_ : ℝ)]
def evalRpow : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q($a ^ ($b : ℝ)) =>
let ra ← core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa =>
pure (.positive q(Real.rpow_pos_of_pos $pa $b))
| .nonnegative pa =>
pure (.nonnegative q(Real.rpow_nonneg $pa $b))
| _ => pure .none
| _, _, _ => throwError "not Real.rpow"
end Mathlib.Meta.Positivity
/-!
## Further algebraic properties of `rpow`
-/
namespace Real
variable {x y z : ℝ} {n : ℕ}
theorem rpow_mul {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by
rw [← Complex.ofReal_inj, Complex.ofReal_cpow (rpow_nonneg hx _),
Complex.ofReal_cpow hx, Complex.ofReal_mul, Complex.cpow_mul, Complex.ofReal_cpow hx] <;>
simp only [(Complex.ofReal_mul _ _).symm, (Complex.ofReal_log hx).symm, Complex.ofReal_im,
neg_lt_zero, pi_pos, le_of_lt pi_pos]
#align real.rpow_mul Real.rpow_mul
theorem rpow_add_int {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by
rw [rpow_def, rpow_def, Complex.ofReal_add,
Complex.cpow_add _ _ (Complex.ofReal_ne_zero.mpr hx), Complex.ofReal_intCast,
Complex.cpow_intCast, ← Complex.ofReal_zpow, mul_comm, Complex.re_ofReal_mul, mul_comm]
#align real.rpow_add_int Real.rpow_add_int
theorem rpow_add_nat {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by
simpa using rpow_add_int hx y n
#align real.rpow_add_nat Real.rpow_add_nat
theorem rpow_sub_int {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
simpa using rpow_add_int hx y (-n)
#align real.rpow_sub_int Real.rpow_sub_int
theorem rpow_sub_nat {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
simpa using rpow_sub_int hx y n
#align real.rpow_sub_nat Real.rpow_sub_nat
lemma rpow_add_int' (hx : 0 ≤ x) {n : ℤ} (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by
rw [rpow_add' hx h, rpow_intCast]
lemma rpow_add_nat' (hx : 0 ≤ x) (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by
rw [rpow_add' hx h, rpow_natCast]
lemma rpow_sub_int' (hx : 0 ≤ x) {n : ℤ} (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by
rw [rpow_sub' hx h, rpow_intCast]
lemma rpow_sub_nat' (hx : 0 ≤ x) (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by
rw [rpow_sub' hx h, rpow_natCast]
theorem rpow_add_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by
simpa using rpow_add_nat hx y 1
#align real.rpow_add_one Real.rpow_add_one
theorem rpow_sub_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by
simpa using rpow_sub_nat hx y 1
#align real.rpow_sub_one Real.rpow_sub_one
lemma rpow_add_one' (hx : 0 ≤ x) (h : y + 1 ≠ 0) : x ^ (y + 1) = x ^ y * x := by
rw [rpow_add' hx h, rpow_one]
lemma rpow_one_add' (hx : 0 ≤ x) (h : 1 + y ≠ 0) : x ^ (1 + y) = x * x ^ y := by
rw [rpow_add' hx h, rpow_one]
lemma rpow_sub_one' (hx : 0 ≤ x) (h : y - 1 ≠ 0) : x ^ (y - 1) = x ^ y / x := by
rw [rpow_sub' hx h, rpow_one]
lemma rpow_one_sub' (hx : 0 ≤ x) (h : 1 - y ≠ 0) : x ^ (1 - y) = x / x ^ y := by
rw [rpow_sub' hx h, rpow_one]
@[simp]
theorem rpow_two (x : ℝ) : x ^ (2 : ℝ) = x ^ 2 := by
rw [← rpow_natCast]
simp only [Nat.cast_ofNat]
#align real.rpow_two Real.rpow_two
theorem rpow_neg_one (x : ℝ) : x ^ (-1 : ℝ) = x⁻¹ := by
suffices H : x ^ ((-1 : ℤ) : ℝ) = x⁻¹ by rwa [Int.cast_neg, Int.cast_one] at H
simp only [rpow_intCast, zpow_one, zpow_neg]
#align real.rpow_neg_one Real.rpow_neg_one
theorem mul_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) : (x * y) ^ z = x ^ z * y ^ z := by
iterate 2 rw [Real.rpow_def_of_nonneg]; split_ifs with h_ifs <;> simp_all
· rw [log_mul ‹_› ‹_›, add_mul, exp_add, rpow_def_of_pos (hy.lt_of_ne' ‹_›)]
all_goals positivity
#align real.mul_rpow Real.mul_rpow
theorem inv_rpow (hx : 0 ≤ x) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by
simp only [← rpow_neg_one, ← rpow_mul hx, mul_comm]
#align real.inv_rpow Real.inv_rpow
theorem div_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := by
simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy]
#align real.div_rpow Real.div_rpow
theorem log_rpow {x : ℝ} (hx : 0 < x) (y : ℝ) : log (x ^ y) = y * log x := by
apply exp_injective
rw [exp_log (rpow_pos_of_pos hx y), ← exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y]
#align real.log_rpow Real.log_rpow
theorem mul_log_eq_log_iff {x y z : ℝ} (hx : 0 < x) (hz : 0 < z) :
y * log x = log z ↔ x ^ y = z :=
⟨fun h ↦ log_injOn_pos (rpow_pos_of_pos hx _) hz <| log_rpow hx _ |>.trans h,
by rintro rfl; rw [log_rpow hx]⟩
@[simp] lemma rpow_rpow_inv (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y) ^ y⁻¹ = x := by
rw [← rpow_mul hx, mul_inv_cancel hy, rpow_one]
@[simp] lemma rpow_inv_rpow (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y⁻¹) ^ y = x := by
rw [← rpow_mul hx, inv_mul_cancel hy, rpow_one]
theorem pow_rpow_inv_natCast (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by
have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn
rw [← rpow_natCast, ← rpow_mul hx, mul_inv_cancel hn0, rpow_one]
#align real.pow_nat_rpow_nat_inv Real.pow_rpow_inv_natCast
theorem rpow_inv_natCast_pow (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by
have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn
rw [← rpow_natCast, ← rpow_mul hx, inv_mul_cancel hn0, rpow_one]
#align real.rpow_nat_inv_pow_nat Real.rpow_inv_natCast_pow
lemma rpow_natCast_mul (hx : 0 ≤ x) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul hx, rpow_natCast]
lemma rpow_mul_natCast (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul hx, rpow_natCast]
lemma rpow_intCast_mul (hx : 0 ≤ x) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul hx, rpow_intCast]
lemma rpow_mul_intCast (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul hx, rpow_intCast]
/-! Note: lemmas about `(∏ i ∈ s, f i ^ r)` such as `Real.finset_prod_rpow` are proved
in `Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean` instead. -/
/-!
## Order and monotonicity
-/
@[gcongr]
theorem rpow_lt_rpow (hx : 0 ≤ x) (hxy : x < y) (hz : 0 < z) : x ^ z < y ^ z := by
rw [le_iff_eq_or_lt] at hx; cases' hx with hx hx
· rw [← hx, zero_rpow (ne_of_gt hz)]
exact rpow_pos_of_pos (by rwa [← hx] at hxy) _
· rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp]
exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz
#align real.rpow_lt_rpow Real.rpow_lt_rpow
theorem strictMonoOn_rpow_Ici_of_exponent_pos {r : ℝ} (hr : 0 < r) :
StrictMonoOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) :=
fun _ ha _ _ hab => rpow_lt_rpow ha hab hr
@[gcongr]
| Mathlib/Analysis/SpecialFunctions/Pow/Real.lean | 552 | 555 | theorem rpow_le_rpow {x y z : ℝ} (h : 0 ≤ x) (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := by |
rcases eq_or_lt_of_le h₁ with (rfl | h₁'); · rfl
rcases eq_or_lt_of_le h₂ with (rfl | h₂'); · simp
exact le_of_lt (rpow_lt_rpow h h₁' h₂')
|
/-
Copyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Kontorovich, Heather Macbeth, Marc Masdeu
-/
import Mathlib.Analysis.Complex.UpperHalfPlane.Basic
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup
import Mathlib.Topology.Instances.Matrix
import Mathlib.Topology.Algebra.Module.FiniteDimension
#align_import number_theory.modular from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2"
/-!
# The action of the modular group SL(2, ℤ) on the upper half-plane
We define the action of `SL(2,ℤ)` on `ℍ` (via restriction of the `SL(2,ℝ)` action in
`Analysis.Complex.UpperHalfPlane`). We then define the standard fundamental domain
(`ModularGroup.fd`, `𝒟`) for this action and show
(`ModularGroup.exists_smul_mem_fd`) that any point in `ℍ` can be
moved inside `𝒟`.
## Main definitions
The standard (closed) fundamental domain of the action of `SL(2,ℤ)` on `ℍ`, denoted `𝒟`:
`fd := {z | 1 ≤ (z : ℂ).normSq ∧ |z.re| ≤ (1 : ℝ) / 2}`
The standard open fundamental domain of the action of `SL(2,ℤ)` on `ℍ`, denoted `𝒟ᵒ`:
`fdo := {z | 1 < (z : ℂ).normSq ∧ |z.re| < (1 : ℝ) / 2}`
These notations are localized in the `Modular` locale and can be enabled via `open scoped Modular`.
## Main results
Any `z : ℍ` can be moved to `𝒟` by an element of `SL(2,ℤ)`:
`exists_smul_mem_fd (z : ℍ) : ∃ g : SL(2,ℤ), g • z ∈ 𝒟`
If both `z` and `γ • z` are in the open domain `𝒟ᵒ` then `z = γ • z`:
`eq_smul_self_of_mem_fdo_mem_fdo {z : ℍ} {g : SL(2,ℤ)} (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : z = g • z`
# Discussion
Standard proofs make use of the identity
`g • z = a / c - 1 / (c (cz + d))`
for `g = [[a, b], [c, d]]` in `SL(2)`, but this requires separate handling of whether `c = 0`.
Instead, our proof makes use of the following perhaps novel identity (see
`ModularGroup.smul_eq_lcRow0_add`):
`g • z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))`
where there is no issue of division by zero.
Another feature is that we delay until the very end the consideration of special matrices
`T=[[1,1],[0,1]]` (see `ModularGroup.T`) and `S=[[0,-1],[1,0]]` (see `ModularGroup.S`), by
instead using abstract theory on the properness of certain maps (phrased in terms of the filters
`Filter.cocompact`, `Filter.cofinite`, etc) to deduce existence theorems, first to prove the
existence of `g` maximizing `(g•z).im` (see `ModularGroup.exists_max_im`), and then among
those, to minimize `|(g•z).re|` (see `ModularGroup.exists_row_one_eq_and_min_re`).
-/
open Complex hiding abs_two
open Matrix hiding mul_smul
open Matrix.SpecialLinearGroup UpperHalfPlane ModularGroup
noncomputable section
local notation "SL(" n ", " R ")" => SpecialLinearGroup (Fin n) R
local macro "↑ₘ" t:term:80 : term => `(term| ($t : Matrix (Fin 2) (Fin 2) ℤ))
open scoped UpperHalfPlane ComplexConjugate
namespace ModularGroup
variable {g : SL(2, ℤ)} (z : ℍ)
section BottomRow
/-- The two numbers `c`, `d` in the "bottom_row" of `g=[[*,*],[c,d]]` in `SL(2, ℤ)` are coprime. -/
| Mathlib/NumberTheory/Modular.lean | 85 | 89 | theorem bottom_row_coprime {R : Type*} [CommRing R] (g : SL(2, R)) :
IsCoprime ((↑g : Matrix (Fin 2) (Fin 2) R) 1 0) ((↑g : Matrix (Fin 2) (Fin 2) R) 1 1) := by |
use -(↑g : Matrix (Fin 2) (Fin 2) R) 0 1, (↑g : Matrix (Fin 2) (Fin 2) R) 0 0
rw [add_comm, neg_mul, ← sub_eq_add_neg, ← det_fin_two]
exact g.det_coe
|
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Init.Core
import Mathlib.LinearAlgebra.AffineSpace.Basis
import Mathlib.LinearAlgebra.FiniteDimensional
#align_import linear_algebra.affine_space.finite_dimensional from "leanprover-community/mathlib"@"67e606eaea14c7854bdc556bd53d98aefdf76ec0"
/-!
# Finite-dimensional subspaces of affine spaces.
This file provides a few results relating to finite-dimensional
subspaces of affine spaces.
## Main definitions
* `Collinear` defines collinear sets of points as those that span a
subspace of dimension at most 1.
-/
noncomputable section
open Affine
section AffineSpace'
variable (k : Type*) {V : Type*} {P : Type*}
variable {ι : Type*}
open AffineSubspace FiniteDimensional Module
variable [DivisionRing k] [AddCommGroup V] [Module k V] [AffineSpace V P]
/-- The `vectorSpan` of a finite set is finite-dimensional. -/
theorem finiteDimensional_vectorSpan_of_finite {s : Set P} (h : Set.Finite s) :
FiniteDimensional k (vectorSpan k s) :=
span_of_finite k <| h.vsub h
#align finite_dimensional_vector_span_of_finite finiteDimensional_vectorSpan_of_finite
/-- The `vectorSpan` of a family indexed by a `Fintype` is
finite-dimensional. -/
instance finiteDimensional_vectorSpan_range [Finite ι] (p : ι → P) :
FiniteDimensional k (vectorSpan k (Set.range p)) :=
finiteDimensional_vectorSpan_of_finite k (Set.finite_range _)
#align finite_dimensional_vector_span_range finiteDimensional_vectorSpan_range
/-- The `vectorSpan` of a subset of a family indexed by a `Fintype`
is finite-dimensional. -/
instance finiteDimensional_vectorSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) :
FiniteDimensional k (vectorSpan k (p '' s)) :=
finiteDimensional_vectorSpan_of_finite k (Set.toFinite _)
#align finite_dimensional_vector_span_image_of_finite finiteDimensional_vectorSpan_image_of_finite
/-- The direction of the affine span of a finite set is
finite-dimensional. -/
theorem finiteDimensional_direction_affineSpan_of_finite {s : Set P} (h : Set.Finite s) :
FiniteDimensional k (affineSpan k s).direction :=
(direction_affineSpan k s).symm ▸ finiteDimensional_vectorSpan_of_finite k h
#align finite_dimensional_direction_affine_span_of_finite finiteDimensional_direction_affineSpan_of_finite
/-- The direction of the affine span of a family indexed by a
`Fintype` is finite-dimensional. -/
instance finiteDimensional_direction_affineSpan_range [Finite ι] (p : ι → P) :
FiniteDimensional k (affineSpan k (Set.range p)).direction :=
finiteDimensional_direction_affineSpan_of_finite k (Set.finite_range _)
#align finite_dimensional_direction_affine_span_range finiteDimensional_direction_affineSpan_range
/-- The direction of the affine span of a subset of a family indexed
by a `Fintype` is finite-dimensional. -/
instance finiteDimensional_direction_affineSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) :
FiniteDimensional k (affineSpan k (p '' s)).direction :=
finiteDimensional_direction_affineSpan_of_finite k (Set.toFinite _)
#align finite_dimensional_direction_affine_span_image_of_finite finiteDimensional_direction_affineSpan_image_of_finite
/-- An affine-independent family of points in a finite-dimensional affine space is finite. -/
theorem finite_of_fin_dim_affineIndependent [FiniteDimensional k V] {p : ι → P}
(hi : AffineIndependent k p) : Finite ι := by
nontriviality ι; inhabit ι
rw [affineIndependent_iff_linearIndependent_vsub k p default] at hi
letI : IsNoetherian k V := IsNoetherian.iff_fg.2 inferInstance
exact
(Set.finite_singleton default).finite_of_compl (Set.finite_coe_iff.1 hi.finite_of_isNoetherian)
#align finite_of_fin_dim_affine_independent finite_of_fin_dim_affineIndependent
/-- An affine-independent subset of a finite-dimensional affine space is finite. -/
theorem finite_set_of_fin_dim_affineIndependent [FiniteDimensional k V] {s : Set ι} {f : s → P}
(hi : AffineIndependent k f) : s.Finite :=
@Set.toFinite _ s (finite_of_fin_dim_affineIndependent k hi)
#align finite_set_of_fin_dim_affine_independent finite_set_of_fin_dim_affineIndependent
variable {k}
/-- The `vectorSpan` of a finite subset of an affinely independent
family has dimension one less than its cardinality. -/
theorem AffineIndependent.finrank_vectorSpan_image_finset [DecidableEq P]
{p : ι → P} (hi : AffineIndependent k p) {s : Finset ι} {n : ℕ} (hc : Finset.card s = n + 1) :
finrank k (vectorSpan k (s.image p : Set P)) = n := by
classical
have hi' := hi.range.mono (Set.image_subset_range p ↑s)
have hc' : (s.image p).card = n + 1 := by rwa [s.card_image_of_injective hi.injective]
have hn : (s.image p).Nonempty := by simp [hc', ← Finset.card_pos]
rcases hn with ⟨p₁, hp₁⟩
have hp₁' : p₁ ∈ p '' s := by simpa using hp₁
rw [affineIndependent_set_iff_linearIndependent_vsub k hp₁', ← Finset.coe_singleton,
← Finset.coe_image, ← Finset.coe_sdiff, Finset.sdiff_singleton_eq_erase, ← Finset.coe_image]
at hi'
have hc : (Finset.image (fun p : P => p -ᵥ p₁) ((Finset.image p s).erase p₁)).card = n := by
rw [Finset.card_image_of_injective _ (vsub_left_injective _), Finset.card_erase_of_mem hp₁]
exact Nat.pred_eq_of_eq_succ hc'
rwa [vectorSpan_eq_span_vsub_finset_right_ne k hp₁, finrank_span_finset_eq_card, hc]
#align affine_independent.finrank_vector_span_image_finset AffineIndependent.finrank_vectorSpan_image_finset
/-- The `vectorSpan` of a finite affinely independent family has
dimension one less than its cardinality. -/
theorem AffineIndependent.finrank_vectorSpan [Fintype ι] {p : ι → P} (hi : AffineIndependent k p)
{n : ℕ} (hc : Fintype.card ι = n + 1) : finrank k (vectorSpan k (Set.range p)) = n := by
classical
rw [← Finset.card_univ] at hc
rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image]
exact hi.finrank_vectorSpan_image_finset hc
#align affine_independent.finrank_vector_span AffineIndependent.finrank_vectorSpan
/-- The `vectorSpan` of a finite affinely independent family has dimension one less than its
cardinality. -/
lemma AffineIndependent.finrank_vectorSpan_add_one [Fintype ι] [Nonempty ι] {p : ι → P}
(hi : AffineIndependent k p) : finrank k (vectorSpan k (Set.range p)) + 1 = Fintype.card ι := by
rw [hi.finrank_vectorSpan (tsub_add_cancel_of_le _).symm, tsub_add_cancel_of_le] <;>
exact Fintype.card_pos
/-- The `vectorSpan` of a finite affinely independent family whose
cardinality is one more than that of the finite-dimensional space is
`⊤`. -/
theorem AffineIndependent.vectorSpan_eq_top_of_card_eq_finrank_add_one [FiniteDimensional k V]
[Fintype ι] {p : ι → P} (hi : AffineIndependent k p) (hc : Fintype.card ι = finrank k V + 1) :
vectorSpan k (Set.range p) = ⊤ :=
Submodule.eq_top_of_finrank_eq <| hi.finrank_vectorSpan hc
#align affine_independent.vector_span_eq_top_of_card_eq_finrank_add_one AffineIndependent.vectorSpan_eq_top_of_card_eq_finrank_add_one
variable (k)
/-- The `vectorSpan` of `n + 1` points in an indexed family has
dimension at most `n`. -/
theorem finrank_vectorSpan_image_finset_le [DecidableEq P] (p : ι → P) (s : Finset ι) {n : ℕ}
(hc : Finset.card s = n + 1) : finrank k (vectorSpan k (s.image p : Set P)) ≤ n := by
classical
have hn : (s.image p).Nonempty := by
rw [Finset.image_nonempty, ← Finset.card_pos, hc]
apply Nat.succ_pos
rcases hn with ⟨p₁, hp₁⟩
rw [vectorSpan_eq_span_vsub_finset_right_ne k hp₁]
refine le_trans (finrank_span_finset_le_card (((s.image p).erase p₁).image fun p => p -ᵥ p₁)) ?_
rw [Finset.card_image_of_injective _ (vsub_left_injective p₁), Finset.card_erase_of_mem hp₁,
tsub_le_iff_right, ← hc]
apply Finset.card_image_le
#align finrank_vector_span_image_finset_le finrank_vectorSpan_image_finset_le
/-- The `vectorSpan` of an indexed family of `n + 1` points has
dimension at most `n`. -/
theorem finrank_vectorSpan_range_le [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 1) :
finrank k (vectorSpan k (Set.range p)) ≤ n := by
classical
rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image]
rw [← Finset.card_univ] at hc
exact finrank_vectorSpan_image_finset_le _ _ _ hc
#align finrank_vector_span_range_le finrank_vectorSpan_range_le
/-- The `vectorSpan` of an indexed family of `n + 1` points has dimension at most `n`. -/
lemma finrank_vectorSpan_range_add_one_le [Fintype ι] [Nonempty ι] (p : ι → P) :
finrank k (vectorSpan k (Set.range p)) + 1 ≤ Fintype.card ι :=
(le_tsub_iff_right $ Nat.succ_le_iff.2 Fintype.card_pos).1 $ finrank_vectorSpan_range_le _ _
(tsub_add_cancel_of_le $ Nat.succ_le_iff.2 Fintype.card_pos).symm
/-- `n + 1` points are affinely independent if and only if their
`vectorSpan` has dimension `n`. -/
theorem affineIndependent_iff_finrank_vectorSpan_eq [Fintype ι] (p : ι → P) {n : ℕ}
(hc : Fintype.card ι = n + 1) :
AffineIndependent k p ↔ finrank k (vectorSpan k (Set.range p)) = n := by
classical
have hn : Nonempty ι := by simp [← Fintype.card_pos_iff, hc]
cases' hn with i₁
rw [affineIndependent_iff_linearIndependent_vsub _ _ i₁,
linearIndependent_iff_card_eq_finrank_span, eq_comm,
vectorSpan_range_eq_span_range_vsub_right_ne k p i₁, Set.finrank]
rw [← Finset.card_univ] at hc
rw [Fintype.subtype_card]
simp [Finset.filter_ne', Finset.card_erase_of_mem, hc]
#align affine_independent_iff_finrank_vector_span_eq affineIndependent_iff_finrank_vectorSpan_eq
/-- `n + 1` points are affinely independent if and only if their
`vectorSpan` has dimension at least `n`. -/
theorem affineIndependent_iff_le_finrank_vectorSpan [Fintype ι] (p : ι → P) {n : ℕ}
(hc : Fintype.card ι = n + 1) :
AffineIndependent k p ↔ n ≤ finrank k (vectorSpan k (Set.range p)) := by
rw [affineIndependent_iff_finrank_vectorSpan_eq k p hc]
constructor
· rintro rfl
rfl
· exact fun hle => le_antisymm (finrank_vectorSpan_range_le k p hc) hle
#align affine_independent_iff_le_finrank_vector_span affineIndependent_iff_le_finrank_vectorSpan
/-- `n + 2` points are affinely independent if and only if their
`vectorSpan` does not have dimension at most `n`. -/
theorem affineIndependent_iff_not_finrank_vectorSpan_le [Fintype ι] (p : ι → P) {n : ℕ}
(hc : Fintype.card ι = n + 2) :
AffineIndependent k p ↔ ¬finrank k (vectorSpan k (Set.range p)) ≤ n := by
rw [affineIndependent_iff_le_finrank_vectorSpan k p hc, ← Nat.lt_iff_add_one_le, lt_iff_not_ge]
#align affine_independent_iff_not_finrank_vector_span_le affineIndependent_iff_not_finrank_vectorSpan_le
/-- `n + 2` points have a `vectorSpan` with dimension at most `n` if
and only if they are not affinely independent. -/
theorem finrank_vectorSpan_le_iff_not_affineIndependent [Fintype ι] (p : ι → P) {n : ℕ}
(hc : Fintype.card ι = n + 2) :
finrank k (vectorSpan k (Set.range p)) ≤ n ↔ ¬AffineIndependent k p :=
(not_iff_comm.1 (affineIndependent_iff_not_finrank_vectorSpan_le k p hc).symm).symm
#align finrank_vector_span_le_iff_not_affine_independent finrank_vectorSpan_le_iff_not_affineIndependent
variable {k}
lemma AffineIndependent.card_le_finrank_succ [Fintype ι] {p : ι → P} (hp : AffineIndependent k p) :
Fintype.card ι ≤ FiniteDimensional.finrank k (vectorSpan k (Set.range p)) + 1 := by
cases isEmpty_or_nonempty ι
· simp [Fintype.card_eq_zero]
rw [← tsub_le_iff_right]
exact (affineIndependent_iff_le_finrank_vectorSpan _ _
(tsub_add_cancel_of_le <| Nat.one_le_iff_ne_zero.2 Fintype.card_ne_zero).symm).1 hp
open Finset in
/-- If an affine independent finset is contained in the affine span of another finset, then its
cardinality is at most the cardinality of that finset. -/
lemma AffineIndependent.card_le_card_of_subset_affineSpan {s t : Finset V}
(hs : AffineIndependent k ((↑) : s → V)) (hst : (s : Set V) ⊆ affineSpan k (t : Set V)) :
s.card ≤ t.card := by
obtain rfl | hs' := s.eq_empty_or_nonempty
· simp
obtain rfl | ht' := t.eq_empty_or_nonempty
· simpa [Set.subset_empty_iff] using hst
have := hs'.to_subtype
have := ht'.to_set.to_subtype
have direction_le := AffineSubspace.direction_le (affineSpan_mono k hst)
rw [AffineSubspace.affineSpan_coe, direction_affineSpan, direction_affineSpan,
← @Subtype.range_coe _ (s : Set V), ← @Subtype.range_coe _ (t : Set V)] at direction_le
have finrank_le := add_le_add_right (Submodule.finrank_le_finrank_of_le direction_le) 1
-- We use `erw` to elide the difference between `↥s` and `↥(s : Set V)}`
erw [hs.finrank_vectorSpan_add_one] at finrank_le
simpa using finrank_le.trans <| finrank_vectorSpan_range_add_one_le _ _
open Finset in
/-- If the affine span of an affine independent finset is strictly contained in the affine span of
another finset, then its cardinality is strictly less than the cardinality of that finset. -/
lemma AffineIndependent.card_lt_card_of_affineSpan_lt_affineSpan {s t : Finset V}
(hs : AffineIndependent k ((↑) : s → V))
(hst : affineSpan k (s : Set V) < affineSpan k (t : Set V)) : s.card < t.card := by
obtain rfl | hs' := s.eq_empty_or_nonempty
· simpa [card_pos] using hst
obtain rfl | ht' := t.eq_empty_or_nonempty
· simp [Set.subset_empty_iff] at hst
have := hs'.to_subtype
have := ht'.to_set.to_subtype
have dir_lt := AffineSubspace.direction_lt_of_nonempty (k := k) hst $ hs'.to_set.affineSpan k
rw [direction_affineSpan, direction_affineSpan,
← @Subtype.range_coe _ (s : Set V), ← @Subtype.range_coe _ (t : Set V)] at dir_lt
have finrank_lt := add_lt_add_right (Submodule.finrank_lt_finrank_of_lt dir_lt) 1
-- We use `erw` to elide the difference between `↥s` and `↥(s : Set V)}`
erw [hs.finrank_vectorSpan_add_one] at finrank_lt
simpa using finrank_lt.trans_le <| finrank_vectorSpan_range_add_one_le _ _
/-- If the `vectorSpan` of a finite subset of an affinely independent
family lies in a submodule with dimension one less than its
cardinality, it equals that submodule. -/
theorem AffineIndependent.vectorSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one
[DecidableEq P] {p : ι → P}
(hi : AffineIndependent k p) {s : Finset ι} {sm : Submodule k V} [FiniteDimensional k sm]
(hle : vectorSpan k (s.image p : Set P) ≤ sm) (hc : Finset.card s = finrank k sm + 1) :
vectorSpan k (s.image p : Set P) = sm :=
eq_of_le_of_finrank_eq hle <| hi.finrank_vectorSpan_image_finset hc
#align affine_independent.vector_span_image_finset_eq_of_le_of_card_eq_finrank_add_one AffineIndependent.vectorSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one
/-- If the `vectorSpan` of a finite affinely independent
family lies in a submodule with dimension one less than its
cardinality, it equals that submodule. -/
theorem AffineIndependent.vectorSpan_eq_of_le_of_card_eq_finrank_add_one [Fintype ι] {p : ι → P}
(hi : AffineIndependent k p) {sm : Submodule k V} [FiniteDimensional k sm]
(hle : vectorSpan k (Set.range p) ≤ sm) (hc : Fintype.card ι = finrank k sm + 1) :
vectorSpan k (Set.range p) = sm :=
eq_of_le_of_finrank_eq hle <| hi.finrank_vectorSpan hc
#align affine_independent.vector_span_eq_of_le_of_card_eq_finrank_add_one AffineIndependent.vectorSpan_eq_of_le_of_card_eq_finrank_add_one
/-- If the `affineSpan` of a finite subset of an affinely independent
family lies in an affine subspace whose direction has dimension one
less than its cardinality, it equals that subspace. -/
theorem AffineIndependent.affineSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one
[DecidableEq P] {p : ι → P}
(hi : AffineIndependent k p) {s : Finset ι} {sp : AffineSubspace k P}
[FiniteDimensional k sp.direction] (hle : affineSpan k (s.image p : Set P) ≤ sp)
(hc : Finset.card s = finrank k sp.direction + 1) : affineSpan k (s.image p : Set P) = sp := by
have hn : s.Nonempty := by
rw [← Finset.card_pos, hc]
apply Nat.succ_pos
refine eq_of_direction_eq_of_nonempty_of_le ?_ ((hn.image p).to_set.affineSpan k) hle
have hd := direction_le hle
rw [direction_affineSpan] at hd ⊢
exact hi.vectorSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one hd hc
#align affine_independent.affine_span_image_finset_eq_of_le_of_card_eq_finrank_add_one AffineIndependent.affineSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one
/-- If the `affineSpan` of a finite affinely independent family lies
in an affine subspace whose direction has dimension one less than its
cardinality, it equals that subspace. -/
theorem AffineIndependent.affineSpan_eq_of_le_of_card_eq_finrank_add_one [Fintype ι] {p : ι → P}
(hi : AffineIndependent k p) {sp : AffineSubspace k P} [FiniteDimensional k sp.direction]
(hle : affineSpan k (Set.range p) ≤ sp) (hc : Fintype.card ι = finrank k sp.direction + 1) :
affineSpan k (Set.range p) = sp := by
classical
rw [← Finset.card_univ] at hc
rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image] at hle ⊢
exact hi.affineSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one hle hc
#align affine_independent.affine_span_eq_of_le_of_card_eq_finrank_add_one AffineIndependent.affineSpan_eq_of_le_of_card_eq_finrank_add_one
/-- The `affineSpan` of a finite affinely independent family is `⊤` iff the
family's cardinality is one more than that of the finite-dimensional space. -/
theorem AffineIndependent.affineSpan_eq_top_iff_card_eq_finrank_add_one [FiniteDimensional k V]
[Fintype ι] {p : ι → P} (hi : AffineIndependent k p) :
affineSpan k (Set.range p) = ⊤ ↔ Fintype.card ι = finrank k V + 1 := by
constructor
· intro h_tot
let n := Fintype.card ι - 1
have hn : Fintype.card ι = n + 1 :=
(Nat.succ_pred_eq_of_pos (card_pos_of_affineSpan_eq_top k V P h_tot)).symm
rw [hn, ← finrank_top, ← (vectorSpan_eq_top_of_affineSpan_eq_top k V P) h_tot,
← hi.finrank_vectorSpan hn]
· intro hc
rw [← finrank_top, ← direction_top k V P] at hc
exact hi.affineSpan_eq_of_le_of_card_eq_finrank_add_one le_top hc
#align affine_independent.affine_span_eq_top_iff_card_eq_finrank_add_one AffineIndependent.affineSpan_eq_top_iff_card_eq_finrank_add_one
theorem Affine.Simplex.span_eq_top [FiniteDimensional k V] {n : ℕ} (T : Affine.Simplex k V n)
(hrank : finrank k V = n) : affineSpan k (Set.range T.points) = ⊤ := by
rw [AffineIndependent.affineSpan_eq_top_iff_card_eq_finrank_add_one T.independent,
Fintype.card_fin, hrank]
#align affine.simplex.span_eq_top Affine.Simplex.span_eq_top
/-- The `vectorSpan` of adding a point to a finite-dimensional subspace is finite-dimensional. -/
instance finiteDimensional_vectorSpan_insert (s : AffineSubspace k P)
[FiniteDimensional k s.direction] (p : P) :
FiniteDimensional k (vectorSpan k (insert p (s : Set P))) := by
rw [← direction_affineSpan, ← affineSpan_insert_affineSpan]
rcases (s : Set P).eq_empty_or_nonempty with (hs | ⟨p₀, hp₀⟩)
· rw [coe_eq_bot_iff] at hs
rw [hs, bot_coe, span_empty, bot_coe, direction_affineSpan]
convert finiteDimensional_bot k V <;> simp
· rw [affineSpan_coe, direction_affineSpan_insert hp₀]
infer_instance
#align finite_dimensional_vector_span_insert finiteDimensional_vectorSpan_insert
/-- The direction of the affine span of adding a point to a finite-dimensional subspace is
finite-dimensional. -/
instance finiteDimensional_direction_affineSpan_insert (s : AffineSubspace k P)
[FiniteDimensional k s.direction] (p : P) :
FiniteDimensional k (affineSpan k (insert p (s : Set P))).direction :=
(direction_affineSpan k (insert p (s : Set P))).symm ▸ finiteDimensional_vectorSpan_insert s p
#align finite_dimensional_direction_affine_span_insert finiteDimensional_direction_affineSpan_insert
variable (k)
/-- The `vectorSpan` of adding a point to a set with a finite-dimensional `vectorSpan` is
finite-dimensional. -/
instance finiteDimensional_vectorSpan_insert_set (s : Set P) [FiniteDimensional k (vectorSpan k s)]
(p : P) : FiniteDimensional k (vectorSpan k (insert p s)) := by
haveI : FiniteDimensional k (affineSpan k s).direction :=
(direction_affineSpan k s).symm ▸ inferInstance
rw [← direction_affineSpan, ← affineSpan_insert_affineSpan, direction_affineSpan]
exact finiteDimensional_vectorSpan_insert (affineSpan k s) p
#align finite_dimensional_vector_span_insert_set finiteDimensional_vectorSpan_insert_set
/-- A set of points is collinear if their `vectorSpan` has dimension
at most `1`. -/
def Collinear (s : Set P) : Prop :=
Module.rank k (vectorSpan k s) ≤ 1
#align collinear Collinear
/-- The definition of `Collinear`. -/
theorem collinear_iff_rank_le_one (s : Set P) :
Collinear k s ↔ Module.rank k (vectorSpan k s) ≤ 1 := Iff.rfl
#align collinear_iff_rank_le_one collinear_iff_rank_le_one
variable {k}
/-- A set of points, whose `vectorSpan` is finite-dimensional, is
collinear if and only if their `vectorSpan` has dimension at most
`1`. -/
theorem collinear_iff_finrank_le_one {s : Set P} [FiniteDimensional k (vectorSpan k s)] :
Collinear k s ↔ finrank k (vectorSpan k s) ≤ 1 := by
have h := collinear_iff_rank_le_one k s
rw [← finrank_eq_rank] at h
exact mod_cast h
#align collinear_iff_finrank_le_one collinear_iff_finrank_le_one
alias ⟨Collinear.finrank_le_one, _⟩ := collinear_iff_finrank_le_one
#align collinear.finrank_le_one Collinear.finrank_le_one
/-- A subset of a collinear set is collinear. -/
theorem Collinear.subset {s₁ s₂ : Set P} (hs : s₁ ⊆ s₂) (h : Collinear k s₂) : Collinear k s₁ :=
(rank_le_of_submodule (vectorSpan k s₁) (vectorSpan k s₂) (vectorSpan_mono k hs)).trans h
#align collinear.subset Collinear.subset
/-- The `vectorSpan` of collinear points is finite-dimensional. -/
theorem Collinear.finiteDimensional_vectorSpan {s : Set P} (h : Collinear k s) :
FiniteDimensional k (vectorSpan k s) :=
IsNoetherian.iff_fg.1
(IsNoetherian.iff_rank_lt_aleph0.2 (lt_of_le_of_lt h Cardinal.one_lt_aleph0))
#align collinear.finite_dimensional_vector_span Collinear.finiteDimensional_vectorSpan
/-- The direction of the affine span of collinear points is finite-dimensional. -/
theorem Collinear.finiteDimensional_direction_affineSpan {s : Set P} (h : Collinear k s) :
FiniteDimensional k (affineSpan k s).direction :=
(direction_affineSpan k s).symm ▸ h.finiteDimensional_vectorSpan
#align collinear.finite_dimensional_direction_affine_span Collinear.finiteDimensional_direction_affineSpan
variable (k P)
/-- The empty set is collinear. -/
theorem collinear_empty : Collinear k (∅ : Set P) := by
rw [collinear_iff_rank_le_one, vectorSpan_empty]
simp
#align collinear_empty collinear_empty
variable {P}
/-- A single point is collinear. -/
theorem collinear_singleton (p : P) : Collinear k ({p} : Set P) := by
rw [collinear_iff_rank_le_one, vectorSpan_singleton]
simp
#align collinear_singleton collinear_singleton
variable {k}
/-- Given a point `p₀` in a set of points, that set is collinear if and
only if the points can all be expressed as multiples of the same
vector, added to `p₀`. -/
theorem collinear_iff_of_mem {s : Set P} {p₀ : P} (h : p₀ ∈ s) :
Collinear k s ↔ ∃ v : V, ∀ p ∈ s, ∃ r : k, p = r • v +ᵥ p₀ := by
simp_rw [collinear_iff_rank_le_one, rank_submodule_le_one_iff', Submodule.le_span_singleton_iff]
constructor
· rintro ⟨v₀, hv⟩
use v₀
intro p hp
obtain ⟨r, hr⟩ := hv (p -ᵥ p₀) (vsub_mem_vectorSpan k hp h)
use r
rw [eq_vadd_iff_vsub_eq]
exact hr.symm
· rintro ⟨v, hp₀v⟩
use v
intro w hw
have hs : vectorSpan k s ≤ k ∙ v := by
rw [vectorSpan_eq_span_vsub_set_right k h, Submodule.span_le, Set.subset_def]
intro x hx
rw [SetLike.mem_coe, Submodule.mem_span_singleton]
rw [Set.mem_image] at hx
rcases hx with ⟨p, hp, rfl⟩
rcases hp₀v p hp with ⟨r, rfl⟩
use r
simp
have hw' := SetLike.le_def.1 hs hw
rwa [Submodule.mem_span_singleton] at hw'
#align collinear_iff_of_mem collinear_iff_of_mem
/-- A set of points is collinear if and only if they can all be
expressed as multiples of the same vector, added to the same base
point. -/
theorem collinear_iff_exists_forall_eq_smul_vadd (s : Set P) :
Collinear k s ↔ ∃ (p₀ : P) (v : V), ∀ p ∈ s, ∃ r : k, p = r • v +ᵥ p₀ := by
rcases Set.eq_empty_or_nonempty s with (rfl | ⟨⟨p₁, hp₁⟩⟩)
· simp [collinear_empty]
· rw [collinear_iff_of_mem hp₁]
constructor
· exact fun h => ⟨p₁, h⟩
· rintro ⟨p, v, hv⟩
use v
intro p₂ hp₂
rcases hv p₂ hp₂ with ⟨r, rfl⟩
rcases hv p₁ hp₁ with ⟨r₁, rfl⟩
use r - r₁
simp [vadd_vadd, ← add_smul]
#align collinear_iff_exists_forall_eq_smul_vadd collinear_iff_exists_forall_eq_smul_vadd
variable (k)
/-- Two points are collinear. -/
theorem collinear_pair (p₁ p₂ : P) : Collinear k ({p₁, p₂} : Set P) := by
rw [collinear_iff_exists_forall_eq_smul_vadd]
use p₁, p₂ -ᵥ p₁
intro p hp
rw [Set.mem_insert_iff, Set.mem_singleton_iff] at hp
cases' hp with hp hp
· use 0
simp [hp]
· use 1
simp [hp]
#align collinear_pair collinear_pair
variable {k}
/-- Three points are affinely independent if and only if they are not
collinear. -/
theorem affineIndependent_iff_not_collinear {p : Fin 3 → P} :
AffineIndependent k p ↔ ¬Collinear k (Set.range p) := by
rw [collinear_iff_finrank_le_one,
affineIndependent_iff_not_finrank_vectorSpan_le k p (Fintype.card_fin 3)]
#align affine_independent_iff_not_collinear affineIndependent_iff_not_collinear
/-- Three points are collinear if and only if they are not affinely
independent. -/
theorem collinear_iff_not_affineIndependent {p : Fin 3 → P} :
Collinear k (Set.range p) ↔ ¬AffineIndependent k p := by
rw [collinear_iff_finrank_le_one,
finrank_vectorSpan_le_iff_not_affineIndependent k p (Fintype.card_fin 3)]
#align collinear_iff_not_affine_independent collinear_iff_not_affineIndependent
/-- Three points are affinely independent if and only if they are not collinear. -/
theorem affineIndependent_iff_not_collinear_set {p₁ p₂ p₃ : P} :
AffineIndependent k ![p₁, p₂, p₃] ↔ ¬Collinear k ({p₁, p₂, p₃} : Set P) := by
rw [affineIndependent_iff_not_collinear]
simp_rw [Matrix.range_cons, Matrix.range_empty, Set.singleton_union, insert_emptyc_eq]
#align affine_independent_iff_not_collinear_set affineIndependent_iff_not_collinear_set
/-- Three points are collinear if and only if they are not affinely independent. -/
theorem collinear_iff_not_affineIndependent_set {p₁ p₂ p₃ : P} :
Collinear k ({p₁, p₂, p₃} : Set P) ↔ ¬AffineIndependent k ![p₁, p₂, p₃] :=
affineIndependent_iff_not_collinear_set.not_left.symm
#align collinear_iff_not_affine_independent_set collinear_iff_not_affineIndependent_set
/-- Three points are affinely independent if and only if they are not collinear. -/
theorem affineIndependent_iff_not_collinear_of_ne {p : Fin 3 → P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂)
(h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) :
AffineIndependent k p ↔ ¬Collinear k ({p i₁, p i₂, p i₃} : Set P) := by
have hu : (Finset.univ : Finset (Fin 3)) = {i₁, i₂, i₃} := by
-- Porting note: Originally `by decide!`
fin_cases i₁ <;> fin_cases i₂ <;> fin_cases i₃
<;> simp (config := {decide := true}) only at h₁₂ h₁₃ h₂₃ ⊢
rw [affineIndependent_iff_not_collinear, ← Set.image_univ, ← Finset.coe_univ, hu,
Finset.coe_insert, Finset.coe_insert, Finset.coe_singleton, Set.image_insert_eq, Set.image_pair]
#align affine_independent_iff_not_collinear_of_ne affineIndependent_iff_not_collinear_of_ne
/-- Three points are collinear if and only if they are not affinely independent. -/
theorem collinear_iff_not_affineIndependent_of_ne {p : Fin 3 → P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂)
(h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) :
Collinear k ({p i₁, p i₂, p i₃} : Set P) ↔ ¬AffineIndependent k p :=
(affineIndependent_iff_not_collinear_of_ne h₁₂ h₁₃ h₂₃).not_left.symm
#align collinear_iff_not_affine_independent_of_ne collinear_iff_not_affineIndependent_of_ne
/-- If three points are not collinear, the first and second are different. -/
theorem ne₁₂_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear k ({p₁, p₂, p₃} : Set P)) :
p₁ ≠ p₂ := by
rintro rfl
simp [collinear_pair] at h
#align ne₁₂_of_not_collinear ne₁₂_of_not_collinear
/-- If three points are not collinear, the first and third are different. -/
theorem ne₁₃_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear k ({p₁, p₂, p₃} : Set P)) :
p₁ ≠ p₃ := by
rintro rfl
simp [collinear_pair] at h
#align ne₁₃_of_not_collinear ne₁₃_of_not_collinear
/-- If three points are not collinear, the second and third are different. -/
theorem ne₂₃_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear k ({p₁, p₂, p₃} : Set P)) :
p₂ ≠ p₃ := by
rintro rfl
simp [collinear_pair] at h
#align ne₂₃_of_not_collinear ne₂₃_of_not_collinear
/-- A point in a collinear set of points lies in the affine span of any two distinct points of
that set. -/
theorem Collinear.mem_affineSpan_of_mem_of_ne {s : Set P} (h : Collinear k s) {p₁ p₂ p₃ : P}
(hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₁p₂ : p₁ ≠ p₂) : p₃ ∈ line[k, p₁, p₂] := by
rw [collinear_iff_of_mem hp₁] at h
rcases h with ⟨v, h⟩
rcases h p₂ hp₂ with ⟨r₂, rfl⟩
rcases h p₃ hp₃ with ⟨r₃, rfl⟩
rw [vadd_left_mem_affineSpan_pair]
refine ⟨r₃ / r₂, ?_⟩
have h₂ : r₂ ≠ 0 := by
rintro rfl
simp at hp₁p₂
simp [smul_smul, h₂]
#align collinear.mem_affine_span_of_mem_of_ne Collinear.mem_affineSpan_of_mem_of_ne
/-- The affine span of any two distinct points of a collinear set of points equals the affine
span of the whole set. -/
theorem Collinear.affineSpan_eq_of_ne {s : Set P} (h : Collinear k s) {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) (hp₁p₂ : p₁ ≠ p₂) : line[k, p₁, p₂] = affineSpan k s :=
le_antisymm (affineSpan_mono _ (Set.insert_subset_iff.2 ⟨hp₁, Set.singleton_subset_iff.2 hp₂⟩))
(affineSpan_le.2 fun _ hp => h.mem_affineSpan_of_mem_of_ne hp₁ hp₂ hp hp₁p₂)
#align collinear.affine_span_eq_of_ne Collinear.affineSpan_eq_of_ne
/-- Given a collinear set of points, and two distinct points `p₂` and `p₃` in it, a point `p₁` is
collinear with the set if and only if it is collinear with `p₂` and `p₃`. -/
theorem Collinear.collinear_insert_iff_of_ne {s : Set P} (h : Collinear k s) {p₁ p₂ p₃ : P}
(hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₂p₃ : p₂ ≠ p₃) :
Collinear k (insert p₁ s) ↔ Collinear k ({p₁, p₂, p₃} : Set P) := by
have hv : vectorSpan k (insert p₁ s) = vectorSpan k ({p₁, p₂, p₃} : Set P) := by
-- Porting note: Original proof used `conv_lhs` and `conv_rhs`, but these tactics timed out.
rw [← direction_affineSpan, ← affineSpan_insert_affineSpan]
symm
rw [← direction_affineSpan, ← affineSpan_insert_affineSpan, h.affineSpan_eq_of_ne hp₂ hp₃ hp₂p₃]
rw [Collinear, Collinear, hv]
#align collinear.collinear_insert_iff_of_ne Collinear.collinear_insert_iff_of_ne
/-- Adding a point in the affine span of a set does not change whether that set is collinear. -/
theorem collinear_insert_iff_of_mem_affineSpan {s : Set P} {p : P} (h : p ∈ affineSpan k s) :
Collinear k (insert p s) ↔ Collinear k s := by
rw [Collinear, Collinear, vectorSpan_insert_eq_vectorSpan h]
#align collinear_insert_iff_of_mem_affine_span collinear_insert_iff_of_mem_affineSpan
/-- If a point lies in the affine span of two points, those three points are collinear. -/
theorem collinear_insert_of_mem_affineSpan_pair {p₁ p₂ p₃ : P} (h : p₁ ∈ line[k, p₂, p₃]) :
Collinear k ({p₁, p₂, p₃} : Set P) := by
rw [collinear_insert_iff_of_mem_affineSpan h]
exact collinear_pair _ _ _
#align collinear_insert_of_mem_affine_span_pair collinear_insert_of_mem_affineSpan_pair
/-- If two points lie in the affine span of two points, those four points are collinear. -/
theorem collinear_insert_insert_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ : P} (h₁ : p₁ ∈ line[k, p₃, p₄])
(h₂ : p₂ ∈ line[k, p₃, p₄]) : Collinear k ({p₁, p₂, p₃, p₄} : Set P) := by
rw [collinear_insert_iff_of_mem_affineSpan
((AffineSubspace.le_def' _ _).1 (affineSpan_mono k (Set.subset_insert _ _)) _ h₁),
collinear_insert_iff_of_mem_affineSpan h₂]
exact collinear_pair _ _ _
#align collinear_insert_insert_of_mem_affine_span_pair collinear_insert_insert_of_mem_affineSpan_pair
/-- If three points lie in the affine span of two points, those five points are collinear. -/
theorem collinear_insert_insert_insert_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ p₅ : P}
(h₁ : p₁ ∈ line[k, p₄, p₅]) (h₂ : p₂ ∈ line[k, p₄, p₅]) (h₃ : p₃ ∈ line[k, p₄, p₅]) :
Collinear k ({p₁, p₂, p₃, p₄, p₅} : Set P) := by
rw [collinear_insert_iff_of_mem_affineSpan
((AffineSubspace.le_def' _ _).1
(affineSpan_mono k ((Set.subset_insert _ _).trans (Set.subset_insert _ _))) _ h₁),
collinear_insert_iff_of_mem_affineSpan
((AffineSubspace.le_def' _ _).1 (affineSpan_mono k (Set.subset_insert _ _)) _ h₂),
collinear_insert_iff_of_mem_affineSpan h₃]
exact collinear_pair _ _ _
#align collinear_insert_insert_insert_of_mem_affine_span_pair collinear_insert_insert_insert_of_mem_affineSpan_pair
/-- If three points lie in the affine span of two points, the first four points are collinear. -/
theorem collinear_insert_insert_insert_left_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ p₅ : P}
(h₁ : p₁ ∈ line[k, p₄, p₅]) (h₂ : p₂ ∈ line[k, p₄, p₅]) (h₃ : p₃ ∈ line[k, p₄, p₅]) :
Collinear k ({p₁, p₂, p₃, p₄} : Set P) := by
refine (collinear_insert_insert_insert_of_mem_affineSpan_pair h₁ h₂ h₃).subset ?_
repeat apply Set.insert_subset_insert
simp
#align collinear_insert_insert_insert_left_of_mem_affine_span_pair collinear_insert_insert_insert_left_of_mem_affineSpan_pair
/-- If three points lie in the affine span of two points, the first three points are collinear. -/
theorem collinear_triple_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ p₅ : P} (h₁ : p₁ ∈ line[k, p₄, p₅])
(h₂ : p₂ ∈ line[k, p₄, p₅]) (h₃ : p₃ ∈ line[k, p₄, p₅]) :
Collinear k ({p₁, p₂, p₃} : Set P) := by
refine (collinear_insert_insert_insert_left_of_mem_affineSpan_pair h₁ h₂ h₃).subset ?_
simp [Set.insert_subset_insert]
#align collinear_triple_of_mem_affine_span_pair collinear_triple_of_mem_affineSpan_pair
variable (k)
/-- A set of points is coplanar if their `vectorSpan` has dimension at most `2`. -/
def Coplanar (s : Set P) : Prop :=
Module.rank k (vectorSpan k s) ≤ 2
#align coplanar Coplanar
variable {k}
/-- The `vectorSpan` of coplanar points is finite-dimensional. -/
| Mathlib/LinearAlgebra/AffineSpace/FiniteDimensional.lean | 675 | 678 | theorem Coplanar.finiteDimensional_vectorSpan {s : Set P} (h : Coplanar k s) :
FiniteDimensional k (vectorSpan k s) := by |
refine IsNoetherian.iff_fg.1 (IsNoetherian.iff_rank_lt_aleph0.2 (lt_of_le_of_lt h ?_))
exact Cardinal.lt_aleph0.2 ⟨2, rfl⟩
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Logic.Equiv.PartialEquiv
import Mathlib.Topology.Sets.Opens
#align_import topology.local_homeomorph from "leanprover-community/mathlib"@"431589bce478b2229eba14b14a283250428217db"
/-!
# Partial homeomorphisms
This file defines homeomorphisms between open subsets of topological spaces. An element `e` of
`PartialHomeomorph X Y` is an extension of `PartialEquiv X Y`, i.e., it is a pair of functions
`e.toFun` and `e.invFun`, inverse of each other on the sets `e.source` and `e.target`.
Additionally, we require that these sets are open, and that the functions are continuous on them.
Equivalently, they are homeomorphisms there.
As in equivs, we register a coercion to functions, and we use `e x` and `e.symm x` throughout
instead of `e.toFun x` and `e.invFun x`.
## Main definitions
* `Homeomorph.toPartialHomeomorph`: associating a partial homeomorphism to a homeomorphism, with
`source = target = Set.univ`;
* `PartialHomeomorph.symm`: the inverse of a partial homeomorphism
* `PartialHomeomorph.trans`: the composition of two partial homeomorphisms
* `PartialHomeomorph.refl`: the identity partial homeomorphism
* `PartialHomeomorph.ofSet`: the identity on a set `s`
* `PartialHomeomorph.EqOnSource`: equivalence relation describing the "right" notion of equality
for partial homeomorphisms
## Implementation notes
Most statements are copied from their `PartialEquiv` versions, although some care is required
especially when restricting to subsets, as these should be open subsets.
For design notes, see `PartialEquiv.lean`.
### Local coding conventions
If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`,
then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`.
-/
open Function Set Filter Topology
variable {X X' : Type*} {Y Y' : Type*} {Z Z' : Type*}
[TopologicalSpace X] [TopologicalSpace X'] [TopologicalSpace Y] [TopologicalSpace Y']
[TopologicalSpace Z] [TopologicalSpace Z']
/-- Partial homeomorphisms, defined on open subsets of the space -/
-- Porting note(#5171): this linter isn't ported yet. @[nolint has_nonempty_instance]
structure PartialHomeomorph (X : Type*) (Y : Type*) [TopologicalSpace X]
[TopologicalSpace Y] extends PartialEquiv X Y where
open_source : IsOpen source
open_target : IsOpen target
continuousOn_toFun : ContinuousOn toFun source
continuousOn_invFun : ContinuousOn invFun target
#align local_homeomorph PartialHomeomorph
namespace PartialHomeomorph
variable (e : PartialHomeomorph X Y)
/-! Basic properties; inverse (symm instance) -/
section Basic
/-- Coercion of a partial homeomorphisms to a function. We don't use `e.toFun` because it is
actually `e.toPartialEquiv.toFun`, so `simp` will apply lemmas about `toPartialEquiv`.
While we may want to switch to this behavior later, doing it mid-port will break a lot of proofs. -/
@[coe] def toFun' : X → Y := e.toFun
/-- Coercion of a `PartialHomeomorph` to function.
Note that a `PartialHomeomorph` is not `DFunLike`. -/
instance : CoeFun (PartialHomeomorph X Y) fun _ => X → Y :=
⟨fun e => e.toFun'⟩
/-- The inverse of a partial homeomorphism -/
@[symm]
protected def symm : PartialHomeomorph Y X where
toPartialEquiv := e.toPartialEquiv.symm
open_source := e.open_target
open_target := e.open_source
continuousOn_toFun := e.continuousOn_invFun
continuousOn_invFun := e.continuousOn_toFun
#align local_homeomorph.symm PartialHomeomorph.symm
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def Simps.apply (e : PartialHomeomorph X Y) : X → Y := e
#align local_homeomorph.simps.apply PartialHomeomorph.Simps.apply
/-- See Note [custom simps projection] -/
def Simps.symm_apply (e : PartialHomeomorph X Y) : Y → X := e.symm
#align local_homeomorph.simps.symm_apply PartialHomeomorph.Simps.symm_apply
initialize_simps_projections PartialHomeomorph (toFun → apply, invFun → symm_apply)
protected theorem continuousOn : ContinuousOn e e.source :=
e.continuousOn_toFun
#align local_homeomorph.continuous_on PartialHomeomorph.continuousOn
theorem continuousOn_symm : ContinuousOn e.symm e.target :=
e.continuousOn_invFun
#align local_homeomorph.continuous_on_symm PartialHomeomorph.continuousOn_symm
@[simp, mfld_simps]
theorem mk_coe (e : PartialEquiv X Y) (a b c d) : (PartialHomeomorph.mk e a b c d : X → Y) = e :=
rfl
#align local_homeomorph.mk_coe PartialHomeomorph.mk_coe
@[simp, mfld_simps]
theorem mk_coe_symm (e : PartialEquiv X Y) (a b c d) :
((PartialHomeomorph.mk e a b c d).symm : Y → X) = e.symm :=
rfl
#align local_homeomorph.mk_coe_symm PartialHomeomorph.mk_coe_symm
theorem toPartialEquiv_injective :
Injective (toPartialEquiv : PartialHomeomorph X Y → PartialEquiv X Y)
| ⟨_, _, _, _, _⟩, ⟨_, _, _, _, _⟩, rfl => rfl
#align local_homeomorph.to_local_equiv_injective PartialHomeomorph.toPartialEquiv_injective
/- Register a few simp lemmas to make sure that `simp` puts the application of a local
homeomorphism in its normal form, i.e., in terms of its coercion to a function. -/
@[simp, mfld_simps]
theorem toFun_eq_coe (e : PartialHomeomorph X Y) : e.toFun = e :=
rfl
#align local_homeomorph.to_fun_eq_coe PartialHomeomorph.toFun_eq_coe
@[simp, mfld_simps]
theorem invFun_eq_coe (e : PartialHomeomorph X Y) : e.invFun = e.symm :=
rfl
#align local_homeomorph.inv_fun_eq_coe PartialHomeomorph.invFun_eq_coe
@[simp, mfld_simps]
theorem coe_coe : (e.toPartialEquiv : X → Y) = e :=
rfl
#align local_homeomorph.coe_coe PartialHomeomorph.coe_coe
@[simp, mfld_simps]
theorem coe_coe_symm : (e.toPartialEquiv.symm : Y → X) = e.symm :=
rfl
#align local_homeomorph.coe_coe_symm PartialHomeomorph.coe_coe_symm
@[simp, mfld_simps]
theorem map_source {x : X} (h : x ∈ e.source) : e x ∈ e.target :=
e.map_source' h
#align local_homeomorph.map_source PartialHomeomorph.map_source
/-- Variant of `map_source`, stated for images of subsets of `source`. -/
lemma map_source'' : e '' e.source ⊆ e.target :=
fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx)
@[simp, mfld_simps]
theorem map_target {x : Y} (h : x ∈ e.target) : e.symm x ∈ e.source :=
e.map_target' h
#align local_homeomorph.map_target PartialHomeomorph.map_target
@[simp, mfld_simps]
theorem left_inv {x : X} (h : x ∈ e.source) : e.symm (e x) = x :=
e.left_inv' h
#align local_homeomorph.left_inv PartialHomeomorph.left_inv
@[simp, mfld_simps]
theorem right_inv {x : Y} (h : x ∈ e.target) : e (e.symm x) = x :=
e.right_inv' h
#align local_homeomorph.right_inv PartialHomeomorph.right_inv
theorem eq_symm_apply {x : X} {y : Y} (hx : x ∈ e.source) (hy : y ∈ e.target) :
x = e.symm y ↔ e x = y :=
e.toPartialEquiv.eq_symm_apply hx hy
#align local_homeomorph.eq_symm_apply PartialHomeomorph.eq_symm_apply
protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source
#align local_homeomorph.maps_to PartialHomeomorph.mapsTo
protected theorem symm_mapsTo : MapsTo e.symm e.target e.source :=
e.symm.mapsTo
#align local_homeomorph.symm_maps_to PartialHomeomorph.symm_mapsTo
protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv
#align local_homeomorph.left_inv_on PartialHomeomorph.leftInvOn
protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv
#align local_homeomorph.right_inv_on PartialHomeomorph.rightInvOn
protected theorem invOn : InvOn e.symm e e.source e.target :=
⟨e.leftInvOn, e.rightInvOn⟩
#align local_homeomorph.inv_on PartialHomeomorph.invOn
protected theorem injOn : InjOn e e.source :=
e.leftInvOn.injOn
#align local_homeomorph.inj_on PartialHomeomorph.injOn
protected theorem bijOn : BijOn e e.source e.target :=
e.invOn.bijOn e.mapsTo e.symm_mapsTo
#align local_homeomorph.bij_on PartialHomeomorph.bijOn
protected theorem surjOn : SurjOn e e.source e.target :=
e.bijOn.surjOn
#align local_homeomorph.surj_on PartialHomeomorph.surjOn
end Basic
/-- Interpret a `Homeomorph` as a `PartialHomeomorph` by restricting it
to an open set `s` in the domain and to `t` in the codomain. -/
@[simps! (config := .asFn) apply symm_apply toPartialEquiv,
simps! (config := .lemmasOnly) source target]
def _root_.Homeomorph.toPartialHomeomorphOfImageEq (e : X ≃ₜ Y) (s : Set X) (hs : IsOpen s)
(t : Set Y) (h : e '' s = t) : PartialHomeomorph X Y where
toPartialEquiv := e.toPartialEquivOfImageEq s t h
open_source := hs
open_target := by simpa [← h]
continuousOn_toFun := e.continuous.continuousOn
continuousOn_invFun := e.symm.continuous.continuousOn
/-- A homeomorphism induces a partial homeomorphism on the whole space -/
@[simps! (config := mfld_cfg)]
def _root_.Homeomorph.toPartialHomeomorph (e : X ≃ₜ Y) : PartialHomeomorph X Y :=
e.toPartialHomeomorphOfImageEq univ isOpen_univ univ <| by rw [image_univ, e.surjective.range_eq]
#align homeomorph.to_local_homeomorph Homeomorph.toPartialHomeomorph
/-- Replace `toPartialEquiv` field to provide better definitional equalities. -/
def replaceEquiv (e : PartialHomeomorph X Y) (e' : PartialEquiv X Y) (h : e.toPartialEquiv = e') :
PartialHomeomorph X Y where
toPartialEquiv := e'
open_source := h ▸ e.open_source
open_target := h ▸ e.open_target
continuousOn_toFun := h ▸ e.continuousOn_toFun
continuousOn_invFun := h ▸ e.continuousOn_invFun
#align local_homeomorph.replace_equiv PartialHomeomorph.replaceEquiv
theorem replaceEquiv_eq_self (e' : PartialEquiv X Y)
(h : e.toPartialEquiv = e') : e.replaceEquiv e' h = e := by
cases e
subst e'
rfl
#align local_homeomorph.replace_equiv_eq_self PartialHomeomorph.replaceEquiv_eq_self
theorem source_preimage_target : e.source ⊆ e ⁻¹' e.target :=
e.mapsTo
#align local_homeomorph.source_preimage_target PartialHomeomorph.source_preimage_target
@[deprecated toPartialEquiv_injective (since := "2023-02-18")]
theorem eq_of_partialEquiv_eq {e e' : PartialHomeomorph X Y}
(h : e.toPartialEquiv = e'.toPartialEquiv) : e = e' :=
toPartialEquiv_injective h
#align local_homeomorph.eq_of_local_equiv_eq PartialHomeomorph.eq_of_partialEquiv_eq
theorem eventually_left_inverse {x} (hx : x ∈ e.source) :
∀ᶠ y in 𝓝 x, e.symm (e y) = y :=
(e.open_source.eventually_mem hx).mono e.left_inv'
#align local_homeomorph.eventually_left_inverse PartialHomeomorph.eventually_left_inverse
theorem eventually_left_inverse' {x} (hx : x ∈ e.target) :
∀ᶠ y in 𝓝 (e.symm x), e.symm (e y) = y :=
e.eventually_left_inverse (e.map_target hx)
#align local_homeomorph.eventually_left_inverse' PartialHomeomorph.eventually_left_inverse'
theorem eventually_right_inverse {x} (hx : x ∈ e.target) :
∀ᶠ y in 𝓝 x, e (e.symm y) = y :=
(e.open_target.eventually_mem hx).mono e.right_inv'
#align local_homeomorph.eventually_right_inverse PartialHomeomorph.eventually_right_inverse
theorem eventually_right_inverse' {x} (hx : x ∈ e.source) :
∀ᶠ y in 𝓝 (e x), e (e.symm y) = y :=
e.eventually_right_inverse (e.map_source hx)
#align local_homeomorph.eventually_right_inverse' PartialHomeomorph.eventually_right_inverse'
theorem eventually_ne_nhdsWithin {x} (hx : x ∈ e.source) :
∀ᶠ x' in 𝓝[≠] x, e x' ≠ e x :=
eventually_nhdsWithin_iff.2 <|
(e.eventually_left_inverse hx).mono fun x' hx' =>
mt fun h => by rw [mem_singleton_iff, ← e.left_inv hx, ← h, hx']
#align local_homeomorph.eventually_ne_nhds_within PartialHomeomorph.eventually_ne_nhdsWithin
theorem nhdsWithin_source_inter {x} (hx : x ∈ e.source) (s : Set X) : 𝓝[e.source ∩ s] x = 𝓝[s] x :=
nhdsWithin_inter_of_mem (mem_nhdsWithin_of_mem_nhds <| IsOpen.mem_nhds e.open_source hx)
#align local_homeomorph.nhds_within_source_inter PartialHomeomorph.nhdsWithin_source_inter
theorem nhdsWithin_target_inter {x} (hx : x ∈ e.target) (s : Set Y) : 𝓝[e.target ∩ s] x = 𝓝[s] x :=
e.symm.nhdsWithin_source_inter hx s
#align local_homeomorph.nhds_within_target_inter PartialHomeomorph.nhdsWithin_target_inter
theorem image_eq_target_inter_inv_preimage {s : Set X} (h : s ⊆ e.source) :
e '' s = e.target ∩ e.symm ⁻¹' s :=
e.toPartialEquiv.image_eq_target_inter_inv_preimage h
#align local_homeomorph.image_eq_target_inter_inv_preimage PartialHomeomorph.image_eq_target_inter_inv_preimage
theorem image_source_inter_eq' (s : Set X) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s :=
e.toPartialEquiv.image_source_inter_eq' s
#align local_homeomorph.image_source_inter_eq' PartialHomeomorph.image_source_inter_eq'
theorem image_source_inter_eq (s : Set X) :
e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) :=
e.toPartialEquiv.image_source_inter_eq s
#align local_homeomorph.image_source_inter_eq PartialHomeomorph.image_source_inter_eq
theorem symm_image_eq_source_inter_preimage {s : Set Y} (h : s ⊆ e.target) :
e.symm '' s = e.source ∩ e ⁻¹' s :=
e.symm.image_eq_target_inter_inv_preimage h
#align local_homeomorph.symm_image_eq_source_inter_preimage PartialHomeomorph.symm_image_eq_source_inter_preimage
theorem symm_image_target_inter_eq (s : Set Y) :
e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) :=
e.symm.image_source_inter_eq _
#align local_homeomorph.symm_image_target_inter_eq PartialHomeomorph.symm_image_target_inter_eq
theorem source_inter_preimage_inv_preimage (s : Set X) :
e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s :=
e.toPartialEquiv.source_inter_preimage_inv_preimage s
#align local_homeomorph.source_inter_preimage_inv_preimage PartialHomeomorph.source_inter_preimage_inv_preimage
theorem target_inter_inv_preimage_preimage (s : Set Y) :
e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s :=
e.symm.source_inter_preimage_inv_preimage _
#align local_homeomorph.target_inter_inv_preimage_preimage PartialHomeomorph.target_inter_inv_preimage_preimage
theorem source_inter_preimage_target_inter (s : Set Y) :
e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s :=
e.toPartialEquiv.source_inter_preimage_target_inter s
#align local_homeomorph.source_inter_preimage_target_inter PartialHomeomorph.source_inter_preimage_target_inter
theorem image_source_eq_target : e '' e.source = e.target :=
e.toPartialEquiv.image_source_eq_target
#align local_homeomorph.image_source_eq_target PartialHomeomorph.image_source_eq_target
theorem symm_image_target_eq_source : e.symm '' e.target = e.source :=
e.symm.image_source_eq_target
#align local_homeomorph.symm_image_target_eq_source PartialHomeomorph.symm_image_target_eq_source
/-- Two partial homeomorphisms are equal when they have equal `toFun`, `invFun` and `source`.
It is not sufficient to have equal `toFun` and `source`, as this only determines `invFun` on
the target. This would only be true for a weaker notion of equality, arguably the right one,
called `EqOnSource`. -/
@[ext]
protected theorem ext (e' : PartialHomeomorph X Y) (h : ∀ x, e x = e' x)
(hinv : ∀ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' :=
toPartialEquiv_injective (PartialEquiv.ext h hinv hs)
#align local_homeomorph.ext PartialHomeomorph.ext
protected theorem ext_iff {e e' : PartialHomeomorph X Y} :
e = e' ↔ (∀ x, e x = e' x) ∧ (∀ x, e.symm x = e'.symm x) ∧ e.source = e'.source :=
⟨by
rintro rfl
exact ⟨fun x => rfl, fun x => rfl, rfl⟩, fun h => e.ext e' h.1 h.2.1 h.2.2⟩
#align local_homeomorph.ext_iff PartialHomeomorph.ext_iff
@[simp, mfld_simps]
theorem symm_toPartialEquiv : e.symm.toPartialEquiv = e.toPartialEquiv.symm :=
rfl
#align local_homeomorph.symm_to_local_equiv PartialHomeomorph.symm_toPartialEquiv
-- The following lemmas are already simp via `PartialEquiv`
theorem symm_source : e.symm.source = e.target :=
rfl
#align local_homeomorph.symm_source PartialHomeomorph.symm_source
theorem symm_target : e.symm.target = e.source :=
rfl
#align local_homeomorph.symm_target PartialHomeomorph.symm_target
@[simp, mfld_simps] theorem symm_symm : e.symm.symm = e := rfl
#align local_homeomorph.symm_symm PartialHomeomorph.symm_symm
theorem symm_bijective : Function.Bijective
(PartialHomeomorph.symm : PartialHomeomorph X Y → PartialHomeomorph Y X) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
/-- A partial homeomorphism is continuous at any point of its source -/
protected theorem continuousAt {x : X} (h : x ∈ e.source) : ContinuousAt e x :=
(e.continuousOn x h).continuousAt (e.open_source.mem_nhds h)
#align local_homeomorph.continuous_at PartialHomeomorph.continuousAt
/-- A partial homeomorphism inverse is continuous at any point of its target -/
theorem continuousAt_symm {x : Y} (h : x ∈ e.target) : ContinuousAt e.symm x :=
e.symm.continuousAt h
#align local_homeomorph.continuous_at_symm PartialHomeomorph.continuousAt_symm
theorem tendsto_symm {x} (hx : x ∈ e.source) : Tendsto e.symm (𝓝 (e x)) (𝓝 x) := by
simpa only [ContinuousAt, e.left_inv hx] using e.continuousAt_symm (e.map_source hx)
#align local_homeomorph.tendsto_symm PartialHomeomorph.tendsto_symm
theorem map_nhds_eq {x} (hx : x ∈ e.source) : map e (𝓝 x) = 𝓝 (e x) :=
le_antisymm (e.continuousAt hx) <|
le_map_of_right_inverse (e.eventually_right_inverse' hx) (e.tendsto_symm hx)
#align local_homeomorph.map_nhds_eq PartialHomeomorph.map_nhds_eq
theorem symm_map_nhds_eq {x} (hx : x ∈ e.source) : map e.symm (𝓝 (e x)) = 𝓝 x :=
(e.symm.map_nhds_eq <| e.map_source hx).trans <| by rw [e.left_inv hx]
#align local_homeomorph.symm_map_nhds_eq PartialHomeomorph.symm_map_nhds_eq
theorem image_mem_nhds {x} (hx : x ∈ e.source) {s : Set X} (hs : s ∈ 𝓝 x) : e '' s ∈ 𝓝 (e x) :=
e.map_nhds_eq hx ▸ Filter.image_mem_map hs
#align local_homeomorph.image_mem_nhds PartialHomeomorph.image_mem_nhds
theorem map_nhdsWithin_eq {x} (hx : x ∈ e.source) (s : Set X) :
map e (𝓝[s] x) = 𝓝[e '' (e.source ∩ s)] e x :=
calc
map e (𝓝[s] x) = map e (𝓝[e.source ∩ s] x) :=
congr_arg (map e) (e.nhdsWithin_source_inter hx _).symm
_ = 𝓝[e '' (e.source ∩ s)] e x :=
(e.leftInvOn.mono inter_subset_left).map_nhdsWithin_eq (e.left_inv hx)
(e.continuousAt_symm (e.map_source hx)).continuousWithinAt
(e.continuousAt hx).continuousWithinAt
#align local_homeomorph.map_nhds_within_eq PartialHomeomorph.map_nhdsWithin_eq
theorem map_nhdsWithin_preimage_eq {x} (hx : x ∈ e.source) (s : Set Y) :
map e (𝓝[e ⁻¹' s] x) = 𝓝[s] e x := by
rw [e.map_nhdsWithin_eq hx, e.image_source_inter_eq', e.target_inter_inv_preimage_preimage,
e.nhdsWithin_target_inter (e.map_source hx)]
#align local_homeomorph.map_nhds_within_preimage_eq PartialHomeomorph.map_nhdsWithin_preimage_eq
theorem eventually_nhds {x : X} (p : Y → Prop) (hx : x ∈ e.source) :
(∀ᶠ y in 𝓝 (e x), p y) ↔ ∀ᶠ x in 𝓝 x, p (e x) :=
Iff.trans (by rw [e.map_nhds_eq hx]) eventually_map
#align local_homeomorph.eventually_nhds PartialHomeomorph.eventually_nhds
theorem eventually_nhds' {x : X} (p : X → Prop) (hx : x ∈ e.source) :
(∀ᶠ y in 𝓝 (e x), p (e.symm y)) ↔ ∀ᶠ x in 𝓝 x, p x := by
rw [e.eventually_nhds _ hx]
refine eventually_congr ((e.eventually_left_inverse hx).mono fun y hy => ?_)
rw [hy]
#align local_homeomorph.eventually_nhds' PartialHomeomorph.eventually_nhds'
theorem eventually_nhdsWithin {x : X} (p : Y → Prop) {s : Set X}
(hx : x ∈ e.source) : (∀ᶠ y in 𝓝[e.symm ⁻¹' s] e x, p y) ↔ ∀ᶠ x in 𝓝[s] x, p (e x) := by
refine Iff.trans ?_ eventually_map
rw [e.map_nhdsWithin_eq hx, e.image_source_inter_eq', e.nhdsWithin_target_inter (e.mapsTo hx)]
#align local_homeomorph.eventually_nhds_within PartialHomeomorph.eventually_nhdsWithin
theorem eventually_nhdsWithin' {x : X} (p : X → Prop) {s : Set X}
(hx : x ∈ e.source) : (∀ᶠ y in 𝓝[e.symm ⁻¹' s] e x, p (e.symm y)) ↔ ∀ᶠ x in 𝓝[s] x, p x := by
rw [e.eventually_nhdsWithin _ hx]
refine eventually_congr <|
(eventually_nhdsWithin_of_eventually_nhds <| e.eventually_left_inverse hx).mono fun y hy => ?_
rw [hy]
#align local_homeomorph.eventually_nhds_within' PartialHomeomorph.eventually_nhdsWithin'
/-- This lemma is useful in the manifold library in the case that `e` is a chart. It states that
locally around `e x` the set `e.symm ⁻¹' s` is the same as the set intersected with the target
of `e` and some other neighborhood of `f x` (which will be the source of a chart on `Z`). -/
theorem preimage_eventuallyEq_target_inter_preimage_inter {e : PartialHomeomorph X Y} {s : Set X}
{t : Set Z} {x : X} {f : X → Z} (hf : ContinuousWithinAt f s x) (hxe : x ∈ e.source)
(ht : t ∈ 𝓝 (f x)) :
e.symm ⁻¹' s =ᶠ[𝓝 (e x)] (e.target ∩ e.symm ⁻¹' (s ∩ f ⁻¹' t) : Set Y) := by
rw [eventuallyEq_set, e.eventually_nhds _ hxe]
filter_upwards [e.open_source.mem_nhds hxe,
mem_nhdsWithin_iff_eventually.mp (hf.preimage_mem_nhdsWithin ht)]
intro y hy hyu
simp_rw [mem_inter_iff, mem_preimage, mem_inter_iff, e.mapsTo hy, true_and_iff, iff_self_and,
e.left_inv hy, iff_true_intro hyu]
#align local_homeomorph.preimage_eventually_eq_target_inter_preimage_inter PartialHomeomorph.preimage_eventuallyEq_target_inter_preimage_inter
theorem isOpen_inter_preimage {s : Set Y} (hs : IsOpen s) : IsOpen (e.source ∩ e ⁻¹' s) :=
e.continuousOn.isOpen_inter_preimage e.open_source hs
#align local_homeomorph.preimage_open_of_open PartialHomeomorph.isOpen_inter_preimage
theorem isOpen_inter_preimage_symm {s : Set X} (hs : IsOpen s) : IsOpen (e.target ∩ e.symm ⁻¹' s) :=
e.symm.continuousOn.isOpen_inter_preimage e.open_target hs
#align local_homeomorph.preimage_open_of_open_symm PartialHomeomorph.isOpen_inter_preimage_symm
/-- A partial homeomorphism is an open map on its source:
the image of an open subset of the source is open. -/
lemma isOpen_image_of_subset_source {s : Set X} (hs : IsOpen s) (hse : s ⊆ e.source) :
IsOpen (e '' s) := by
rw [(image_eq_target_inter_inv_preimage (e := e) hse)]
exact e.continuousOn_invFun.isOpen_inter_preimage e.open_target hs
#align local_homeomorph.image_open_of_open PartialHomeomorph.isOpen_image_of_subset_source
/-- The image of the restriction of an open set to the source is open. -/
theorem isOpen_image_source_inter {s : Set X} (hs : IsOpen s) :
IsOpen (e '' (e.source ∩ s)) :=
e.isOpen_image_of_subset_source (e.open_source.inter hs) inter_subset_left
#align local_homeomorph.image_open_of_open' PartialHomeomorph.isOpen_image_source_inter
/-- The inverse of a partial homeomorphism `e` is an open map on `e.target`. -/
lemma isOpen_image_symm_of_subset_target {t : Set Y} (ht : IsOpen t) (hte : t ⊆ e.target) :
IsOpen (e.symm '' t) :=
isOpen_image_of_subset_source e.symm ht (e.symm_source ▸ hte)
lemma isOpen_symm_image_iff_of_subset_target {t : Set Y} (hs : t ⊆ e.target) :
IsOpen (e.symm '' t) ↔ IsOpen t := by
refine ⟨fun h ↦ ?_, fun h ↦ e.symm.isOpen_image_of_subset_source h hs⟩
have hs' : e.symm '' t ⊆ e.source := by
rw [e.symm_image_eq_source_inter_preimage hs]
apply Set.inter_subset_left
rw [← e.image_symm_image_of_subset_target hs]
exact e.isOpen_image_of_subset_source h hs'
theorem isOpen_image_iff_of_subset_source {s : Set X} (hs : s ⊆ e.source) :
IsOpen (e '' s) ↔ IsOpen s := by
rw [← e.symm.isOpen_symm_image_iff_of_subset_target hs, e.symm_symm]
section IsImage
/-!
### `PartialHomeomorph.IsImage` relation
We say that `t : Set Y` is an image of `s : Set X` under a partial homeomorphism `e` if any of the
following equivalent conditions hold:
* `e '' (e.source ∩ s) = e.target ∩ t`;
* `e.source ∩ e ⁻¹ t = e.source ∩ s`;
* `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition).
This definition is a restatement of `PartialEquiv.IsImage` for partial homeomorphisms.
In this section we transfer API about `PartialEquiv.IsImage` to partial homeomorphisms and
add a few `PartialHomeomorph`-specific lemmas like `PartialHomeomorph.IsImage.closure`.
-/
/-- We say that `t : Set Y` is an image of `s : Set X` under a partial homeomorphism `e`
if any of the following equivalent conditions hold:
* `e '' (e.source ∩ s) = e.target ∩ t`;
* `e.source ∩ e ⁻¹ t = e.source ∩ s`;
* `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition).
-/
def IsImage (s : Set X) (t : Set Y) : Prop :=
∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s)
#align local_homeomorph.is_image PartialHomeomorph.IsImage
namespace IsImage
variable {e} {s : Set X} {t : Set Y} {x : X} {y : Y}
theorem toPartialEquiv (h : e.IsImage s t) : e.toPartialEquiv.IsImage s t :=
h
#align local_homeomorph.is_image.to_local_equiv PartialHomeomorph.IsImage.toPartialEquiv
theorem apply_mem_iff (h : e.IsImage s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s :=
h hx
#align local_homeomorph.is_image.apply_mem_iff PartialHomeomorph.IsImage.apply_mem_iff
protected theorem symm (h : e.IsImage s t) : e.symm.IsImage t s :=
h.toPartialEquiv.symm
#align local_homeomorph.is_image.symm PartialHomeomorph.IsImage.symm
theorem symm_apply_mem_iff (h : e.IsImage s t) (hy : y ∈ e.target) : e.symm y ∈ s ↔ y ∈ t :=
h.symm hy
#align local_homeomorph.is_image.symm_apply_mem_iff PartialHomeomorph.IsImage.symm_apply_mem_iff
@[simp]
theorem symm_iff : e.symm.IsImage t s ↔ e.IsImage s t :=
⟨fun h => h.symm, fun h => h.symm⟩
#align local_homeomorph.is_image.symm_iff PartialHomeomorph.IsImage.symm_iff
protected theorem mapsTo (h : e.IsImage s t) : MapsTo e (e.source ∩ s) (e.target ∩ t) :=
h.toPartialEquiv.mapsTo
#align local_homeomorph.is_image.maps_to PartialHomeomorph.IsImage.mapsTo
theorem symm_mapsTo (h : e.IsImage s t) : MapsTo e.symm (e.target ∩ t) (e.source ∩ s) :=
h.symm.mapsTo
#align local_homeomorph.is_image.symm_maps_to PartialHomeomorph.IsImage.symm_mapsTo
theorem image_eq (h : e.IsImage s t) : e '' (e.source ∩ s) = e.target ∩ t :=
h.toPartialEquiv.image_eq
#align local_homeomorph.is_image.image_eq PartialHomeomorph.IsImage.image_eq
theorem symm_image_eq (h : e.IsImage s t) : e.symm '' (e.target ∩ t) = e.source ∩ s :=
h.symm.image_eq
#align local_homeomorph.is_image.symm_image_eq PartialHomeomorph.IsImage.symm_image_eq
theorem iff_preimage_eq : e.IsImage s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s :=
PartialEquiv.IsImage.iff_preimage_eq
#align local_homeomorph.is_image.iff_preimage_eq PartialHomeomorph.IsImage.iff_preimage_eq
alias ⟨preimage_eq, of_preimage_eq⟩ := iff_preimage_eq
#align local_homeomorph.is_image.preimage_eq PartialHomeomorph.IsImage.preimage_eq
#align local_homeomorph.is_image.of_preimage_eq PartialHomeomorph.IsImage.of_preimage_eq
theorem iff_symm_preimage_eq : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t :=
symm_iff.symm.trans iff_preimage_eq
#align local_homeomorph.is_image.iff_symm_preimage_eq PartialHomeomorph.IsImage.iff_symm_preimage_eq
alias ⟨symm_preimage_eq, of_symm_preimage_eq⟩ := iff_symm_preimage_eq
#align local_homeomorph.is_image.symm_preimage_eq PartialHomeomorph.IsImage.symm_preimage_eq
#align local_homeomorph.is_image.of_symm_preimage_eq PartialHomeomorph.IsImage.of_symm_preimage_eq
theorem iff_symm_preimage_eq' :
e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' (e.source ∩ s) = e.target ∩ t := by
rw [iff_symm_preimage_eq, ← image_source_inter_eq, ← image_source_inter_eq']
#align local_homeomorph.is_image.iff_symm_preimage_eq' PartialHomeomorph.IsImage.iff_symm_preimage_eq'
alias ⟨symm_preimage_eq', of_symm_preimage_eq'⟩ := iff_symm_preimage_eq'
#align local_homeomorph.is_image.symm_preimage_eq' PartialHomeomorph.IsImage.symm_preimage_eq'
#align local_homeomorph.is_image.of_symm_preimage_eq' PartialHomeomorph.IsImage.of_symm_preimage_eq'
theorem iff_preimage_eq' : e.IsImage s t ↔ e.source ∩ e ⁻¹' (e.target ∩ t) = e.source ∩ s :=
symm_iff.symm.trans iff_symm_preimage_eq'
#align local_homeomorph.is_image.iff_preimage_eq' PartialHomeomorph.IsImage.iff_preimage_eq'
alias ⟨preimage_eq', of_preimage_eq'⟩ := iff_preimage_eq'
#align local_homeomorph.is_image.preimage_eq' PartialHomeomorph.IsImage.preimage_eq'
#align local_homeomorph.is_image.of_preimage_eq' PartialHomeomorph.IsImage.of_preimage_eq'
theorem of_image_eq (h : e '' (e.source ∩ s) = e.target ∩ t) : e.IsImage s t :=
PartialEquiv.IsImage.of_image_eq h
#align local_homeomorph.is_image.of_image_eq PartialHomeomorph.IsImage.of_image_eq
theorem of_symm_image_eq (h : e.symm '' (e.target ∩ t) = e.source ∩ s) : e.IsImage s t :=
PartialEquiv.IsImage.of_symm_image_eq h
#align local_homeomorph.is_image.of_symm_image_eq PartialHomeomorph.IsImage.of_symm_image_eq
protected theorem compl (h : e.IsImage s t) : e.IsImage sᶜ tᶜ := fun _ hx => (h hx).not
#align local_homeomorph.is_image.compl PartialHomeomorph.IsImage.compl
protected theorem inter {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s ∩ s') (t ∩ t') := fun _ hx => (h hx).and (h' hx)
#align local_homeomorph.is_image.inter PartialHomeomorph.IsImage.inter
protected theorem union {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s ∪ s') (t ∪ t') := fun _ hx => (h hx).or (h' hx)
#align local_homeomorph.is_image.union PartialHomeomorph.IsImage.union
protected theorem diff {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s \ s') (t \ t') :=
h.inter h'.compl
#align local_homeomorph.is_image.diff PartialHomeomorph.IsImage.diff
theorem leftInvOn_piecewise {e' : PartialHomeomorph X Y} [∀ i, Decidable (i ∈ s)]
[∀ i, Decidable (i ∈ t)] (h : e.IsImage s t) (h' : e'.IsImage s t) :
LeftInvOn (t.piecewise e.symm e'.symm) (s.piecewise e e') (s.ite e.source e'.source) :=
h.toPartialEquiv.leftInvOn_piecewise h'
#align local_homeomorph.is_image.left_inv_on_piecewise PartialHomeomorph.IsImage.leftInvOn_piecewise
theorem inter_eq_of_inter_eq_of_eqOn {e' : PartialHomeomorph X Y} (h : e.IsImage s t)
(h' : e'.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (Heq : EqOn e e' (e.source ∩ s)) :
e.target ∩ t = e'.target ∩ t :=
h.toPartialEquiv.inter_eq_of_inter_eq_of_eqOn h' hs Heq
#align local_homeomorph.is_image.inter_eq_of_inter_eq_of_eq_on PartialHomeomorph.IsImage.inter_eq_of_inter_eq_of_eqOn
theorem symm_eqOn_of_inter_eq_of_eqOn {e' : PartialHomeomorph X Y} (h : e.IsImage s t)
(hs : e.source ∩ s = e'.source ∩ s) (Heq : EqOn e e' (e.source ∩ s)) :
EqOn e.symm e'.symm (e.target ∩ t) :=
h.toPartialEquiv.symm_eq_on_of_inter_eq_of_eqOn hs Heq
#align local_homeomorph.is_image.symm_eq_on_of_inter_eq_of_eq_on PartialHomeomorph.IsImage.symm_eqOn_of_inter_eq_of_eqOn
theorem map_nhdsWithin_eq (h : e.IsImage s t) (hx : x ∈ e.source) : map e (𝓝[s] x) = 𝓝[t] e x := by
rw [e.map_nhdsWithin_eq hx, h.image_eq, e.nhdsWithin_target_inter (e.map_source hx)]
#align local_homeomorph.is_image.map_nhds_within_eq PartialHomeomorph.IsImage.map_nhdsWithin_eq
protected theorem closure (h : e.IsImage s t) : e.IsImage (closure s) (closure t) := fun x hx => by
simp only [mem_closure_iff_nhdsWithin_neBot, ← h.map_nhdsWithin_eq hx, map_neBot_iff]
#align local_homeomorph.is_image.closure PartialHomeomorph.IsImage.closure
protected theorem interior (h : e.IsImage s t) : e.IsImage (interior s) (interior t) := by
simpa only [closure_compl, compl_compl] using h.compl.closure.compl
#align local_homeomorph.is_image.interior PartialHomeomorph.IsImage.interior
protected theorem frontier (h : e.IsImage s t) : e.IsImage (frontier s) (frontier t) :=
h.closure.diff h.interior
#align local_homeomorph.is_image.frontier PartialHomeomorph.IsImage.frontier
theorem isOpen_iff (h : e.IsImage s t) : IsOpen (e.source ∩ s) ↔ IsOpen (e.target ∩ t) :=
⟨fun hs => h.symm_preimage_eq' ▸ e.symm.isOpen_inter_preimage hs, fun hs =>
h.preimage_eq' ▸ e.isOpen_inter_preimage hs⟩
#align local_homeomorph.is_image.is_open_iff PartialHomeomorph.IsImage.isOpen_iff
/-- Restrict a `PartialHomeomorph` to a pair of corresponding open sets. -/
@[simps toPartialEquiv]
def restr (h : e.IsImage s t) (hs : IsOpen (e.source ∩ s)) : PartialHomeomorph X Y where
toPartialEquiv := h.toPartialEquiv.restr
open_source := hs
open_target := h.isOpen_iff.1 hs
continuousOn_toFun := e.continuousOn.mono inter_subset_left
continuousOn_invFun := e.symm.continuousOn.mono inter_subset_left
#align local_homeomorph.is_image.restr PartialHomeomorph.IsImage.restr
end IsImage
theorem isImage_source_target : e.IsImage e.source e.target :=
e.toPartialEquiv.isImage_source_target
#align local_homeomorph.is_image_source_target PartialHomeomorph.isImage_source_target
theorem isImage_source_target_of_disjoint (e' : PartialHomeomorph X Y)
(hs : Disjoint e.source e'.source) (ht : Disjoint e.target e'.target) :
e.IsImage e'.source e'.target :=
e.toPartialEquiv.isImage_source_target_of_disjoint e'.toPartialEquiv hs ht
#align local_homeomorph.is_image_source_target_of_disjoint PartialHomeomorph.isImage_source_target_of_disjoint
/-- Preimage of interior or interior of preimage coincide for partial homeomorphisms,
when restricted to the source. -/
theorem preimage_interior (s : Set Y) :
e.source ∩ e ⁻¹' interior s = e.source ∩ interior (e ⁻¹' s) :=
(IsImage.of_preimage_eq rfl).interior.preimage_eq
#align local_homeomorph.preimage_interior PartialHomeomorph.preimage_interior
theorem preimage_closure (s : Set Y) : e.source ∩ e ⁻¹' closure s = e.source ∩ closure (e ⁻¹' s) :=
(IsImage.of_preimage_eq rfl).closure.preimage_eq
#align local_homeomorph.preimage_closure PartialHomeomorph.preimage_closure
theorem preimage_frontier (s : Set Y) :
e.source ∩ e ⁻¹' frontier s = e.source ∩ frontier (e ⁻¹' s) :=
(IsImage.of_preimage_eq rfl).frontier.preimage_eq
#align local_homeomorph.preimage_frontier PartialHomeomorph.preimage_frontier
end IsImage
/-- A `PartialEquiv` with continuous open forward map and open source is a `PartialHomeomorph`. -/
def ofContinuousOpenRestrict (e : PartialEquiv X Y) (hc : ContinuousOn e e.source)
(ho : IsOpenMap (e.source.restrict e)) (hs : IsOpen e.source) : PartialHomeomorph X Y where
toPartialEquiv := e
open_source := hs
open_target := by simpa only [range_restrict, e.image_source_eq_target] using ho.isOpen_range
continuousOn_toFun := hc
continuousOn_invFun := e.image_source_eq_target ▸ ho.continuousOn_image_of_leftInvOn e.leftInvOn
#align local_homeomorph.of_continuous_open_restrict PartialHomeomorph.ofContinuousOpenRestrict
/-- A `PartialEquiv` with continuous open forward map and open source is a `PartialHomeomorph`. -/
def ofContinuousOpen (e : PartialEquiv X Y) (hc : ContinuousOn e e.source) (ho : IsOpenMap e)
(hs : IsOpen e.source) : PartialHomeomorph X Y :=
ofContinuousOpenRestrict e hc (ho.restrict hs) hs
#align local_homeomorph.of_continuous_open PartialHomeomorph.ofContinuousOpen
/-- Restricting a partial homeomorphism `e` to `e.source ∩ s` when `s` is open.
This is sometimes hard to use because of the openness assumption, but it has the advantage that
when it can be used then its `PartialEquiv` is defeq to `PartialEquiv.restr`. -/
protected def restrOpen (s : Set X) (hs : IsOpen s) : PartialHomeomorph X Y :=
(@IsImage.of_symm_preimage_eq X Y _ _ e s (e.symm ⁻¹' s) rfl).restr
(IsOpen.inter e.open_source hs)
#align local_homeomorph.restr_open PartialHomeomorph.restrOpen
@[simp, mfld_simps]
theorem restrOpen_toPartialEquiv (s : Set X) (hs : IsOpen s) :
(e.restrOpen s hs).toPartialEquiv = e.toPartialEquiv.restr s :=
rfl
#align local_homeomorph.restr_open_to_local_equiv PartialHomeomorph.restrOpen_toPartialEquiv
-- Already simp via `PartialEquiv`
theorem restrOpen_source (s : Set X) (hs : IsOpen s) : (e.restrOpen s hs).source = e.source ∩ s :=
rfl
#align local_homeomorph.restr_open_source PartialHomeomorph.restrOpen_source
/-- Restricting a partial homeomorphism `e` to `e.source ∩ interior s`. We use the interior to make
sure that the restriction is well defined whatever the set s, since partial homeomorphisms are by
definition defined on open sets. In applications where `s` is open, this coincides with the
restriction of partial equivalences -/
@[simps! (config := mfld_cfg) apply symm_apply, simps! (config := .lemmasOnly) source target]
protected def restr (s : Set X) : PartialHomeomorph X Y :=
e.restrOpen (interior s) isOpen_interior
#align local_homeomorph.restr PartialHomeomorph.restr
@[simp, mfld_simps]
theorem restr_toPartialEquiv (s : Set X) :
(e.restr s).toPartialEquiv = e.toPartialEquiv.restr (interior s) :=
rfl
#align local_homeomorph.restr_to_local_equiv PartialHomeomorph.restr_toPartialEquiv
theorem restr_source' (s : Set X) (hs : IsOpen s) : (e.restr s).source = e.source ∩ s := by
rw [e.restr_source, hs.interior_eq]
#align local_homeomorph.restr_source' PartialHomeomorph.restr_source'
theorem restr_toPartialEquiv' (s : Set X) (hs : IsOpen s) :
(e.restr s).toPartialEquiv = e.toPartialEquiv.restr s := by
rw [e.restr_toPartialEquiv, hs.interior_eq]
#align local_homeomorph.restr_to_local_equiv' PartialHomeomorph.restr_toPartialEquiv'
theorem restr_eq_of_source_subset {e : PartialHomeomorph X Y} {s : Set X} (h : e.source ⊆ s) :
e.restr s = e :=
toPartialEquiv_injective <| PartialEquiv.restr_eq_of_source_subset <|
interior_maximal h e.open_source
#align local_homeomorph.restr_eq_of_source_subset PartialHomeomorph.restr_eq_of_source_subset
@[simp, mfld_simps]
theorem restr_univ {e : PartialHomeomorph X Y} : e.restr univ = e :=
restr_eq_of_source_subset (subset_univ _)
#align local_homeomorph.restr_univ PartialHomeomorph.restr_univ
theorem restr_source_inter (s : Set X) : e.restr (e.source ∩ s) = e.restr s := by
refine PartialHomeomorph.ext _ _ (fun x => rfl) (fun x => rfl) ?_
simp [e.open_source.interior_eq, ← inter_assoc]
#align local_homeomorph.restr_source_inter PartialHomeomorph.restr_source_inter
/-- The identity on the whole space as a partial homeomorphism. -/
@[simps! (config := mfld_cfg) apply, simps! (config := .lemmasOnly) source target]
protected def refl (X : Type*) [TopologicalSpace X] : PartialHomeomorph X X :=
(Homeomorph.refl X).toPartialHomeomorph
#align local_homeomorph.refl PartialHomeomorph.refl
@[simp, mfld_simps]
theorem refl_partialEquiv : (PartialHomeomorph.refl X).toPartialEquiv = PartialEquiv.refl X :=
rfl
#align local_homeomorph.refl_local_equiv PartialHomeomorph.refl_partialEquiv
@[simp, mfld_simps]
theorem refl_symm : (PartialHomeomorph.refl X).symm = PartialHomeomorph.refl X :=
rfl
#align local_homeomorph.refl_symm PartialHomeomorph.refl_symm
/-! ofSet: the identity on a set `s` -/
section ofSet
variable {s : Set X} (hs : IsOpen s)
/-- The identity partial equivalence on a set `s` -/
@[simps! (config := mfld_cfg) apply, simps! (config := .lemmasOnly) source target]
def ofSet (s : Set X) (hs : IsOpen s) : PartialHomeomorph X X where
toPartialEquiv := PartialEquiv.ofSet s
open_source := hs
open_target := hs
continuousOn_toFun := continuous_id.continuousOn
continuousOn_invFun := continuous_id.continuousOn
#align local_homeomorph.of_set PartialHomeomorph.ofSet
@[simp, mfld_simps]
theorem ofSet_toPartialEquiv : (ofSet s hs).toPartialEquiv = PartialEquiv.ofSet s :=
rfl
#align local_homeomorph.of_set_to_local_equiv PartialHomeomorph.ofSet_toPartialEquiv
@[simp, mfld_simps]
theorem ofSet_symm : (ofSet s hs).symm = ofSet s hs :=
rfl
#align local_homeomorph.of_set_symm PartialHomeomorph.ofSet_symm
@[simp, mfld_simps]
theorem ofSet_univ_eq_refl : ofSet univ isOpen_univ = PartialHomeomorph.refl X := by ext <;> simp
#align local_homeomorph.of_set_univ_eq_refl PartialHomeomorph.ofSet_univ_eq_refl
end ofSet
/-! `trans`: composition of two partial homeomorphisms -/
section trans
variable (e' : PartialHomeomorph Y Z)
/-- Composition of two partial homeomorphisms when the target of the first and the source of
the second coincide. -/
@[simps! apply symm_apply toPartialEquiv, simps! (config := .lemmasOnly) source target]
protected def trans' (h : e.target = e'.source) : PartialHomeomorph X Z where
toPartialEquiv := PartialEquiv.trans' e.toPartialEquiv e'.toPartialEquiv h
open_source := e.open_source
open_target := e'.open_target
continuousOn_toFun := e'.continuousOn.comp e.continuousOn <| h ▸ e.mapsTo
continuousOn_invFun := e.continuousOn_symm.comp e'.continuousOn_symm <| h.symm ▸ e'.symm_mapsTo
#align local_homeomorph.trans' PartialHomeomorph.trans'
/-- Composing two partial homeomorphisms, by restricting to the maximal domain where their
composition is well defined. -/
@[trans]
protected def trans : PartialHomeomorph X Z :=
PartialHomeomorph.trans' (e.symm.restrOpen e'.source e'.open_source).symm
(e'.restrOpen e.target e.open_target) (by simp [inter_comm])
#align local_homeomorph.trans PartialHomeomorph.trans
@[simp, mfld_simps]
theorem trans_toPartialEquiv :
(e.trans e').toPartialEquiv = e.toPartialEquiv.trans e'.toPartialEquiv :=
rfl
#align local_homeomorph.trans_to_local_equiv PartialHomeomorph.trans_toPartialEquiv
@[simp, mfld_simps]
theorem coe_trans : (e.trans e' : X → Z) = e' ∘ e :=
rfl
#align local_homeomorph.coe_trans PartialHomeomorph.coe_trans
@[simp, mfld_simps]
theorem coe_trans_symm : ((e.trans e').symm : Z → X) = e.symm ∘ e'.symm :=
rfl
#align local_homeomorph.coe_trans_symm PartialHomeomorph.coe_trans_symm
theorem trans_apply {x : X} : (e.trans e') x = e' (e x) :=
rfl
#align local_homeomorph.trans_apply PartialHomeomorph.trans_apply
theorem trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm := rfl
#align local_homeomorph.trans_symm_eq_symm_trans_symm PartialHomeomorph.trans_symm_eq_symm_trans_symm
/- This could be considered as a simp lemma, but there are many situations where it makes something
simple into something more complicated. -/
theorem trans_source : (e.trans e').source = e.source ∩ e ⁻¹' e'.source :=
PartialEquiv.trans_source e.toPartialEquiv e'.toPartialEquiv
#align local_homeomorph.trans_source PartialHomeomorph.trans_source
theorem trans_source' : (e.trans e').source = e.source ∩ e ⁻¹' (e.target ∩ e'.source) :=
PartialEquiv.trans_source' e.toPartialEquiv e'.toPartialEquiv
#align local_homeomorph.trans_source' PartialHomeomorph.trans_source'
theorem trans_source'' : (e.trans e').source = e.symm '' (e.target ∩ e'.source) :=
PartialEquiv.trans_source'' e.toPartialEquiv e'.toPartialEquiv
#align local_homeomorph.trans_source'' PartialHomeomorph.trans_source''
theorem image_trans_source : e '' (e.trans e').source = e.target ∩ e'.source :=
PartialEquiv.image_trans_source e.toPartialEquiv e'.toPartialEquiv
#align local_homeomorph.image_trans_source PartialHomeomorph.image_trans_source
theorem trans_target : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' e.target :=
rfl
#align local_homeomorph.trans_target PartialHomeomorph.trans_target
theorem trans_target' : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' (e'.source ∩ e.target) :=
trans_source' e'.symm e.symm
#align local_homeomorph.trans_target' PartialHomeomorph.trans_target'
theorem trans_target'' : (e.trans e').target = e' '' (e'.source ∩ e.target) :=
trans_source'' e'.symm e.symm
#align local_homeomorph.trans_target'' PartialHomeomorph.trans_target''
theorem inv_image_trans_target : e'.symm '' (e.trans e').target = e'.source ∩ e.target :=
image_trans_source e'.symm e.symm
#align local_homeomorph.inv_image_trans_target PartialHomeomorph.inv_image_trans_target
theorem trans_assoc (e'' : PartialHomeomorph Z Z') :
(e.trans e').trans e'' = e.trans (e'.trans e'') :=
toPartialEquiv_injective <| e.1.trans_assoc _ _
#align local_homeomorph.trans_assoc PartialHomeomorph.trans_assoc
@[simp, mfld_simps]
theorem trans_refl : e.trans (PartialHomeomorph.refl Y) = e :=
toPartialEquiv_injective e.1.trans_refl
#align local_homeomorph.trans_refl PartialHomeomorph.trans_refl
@[simp, mfld_simps]
theorem refl_trans : (PartialHomeomorph.refl X).trans e = e :=
toPartialEquiv_injective e.1.refl_trans
#align local_homeomorph.refl_trans PartialHomeomorph.refl_trans
theorem trans_ofSet {s : Set Y} (hs : IsOpen s) : e.trans (ofSet s hs) = e.restr (e ⁻¹' s) :=
PartialHomeomorph.ext _ _ (fun _ => rfl) (fun _ => rfl) <| by
rw [trans_source, restr_source, ofSet_source, ← preimage_interior, hs.interior_eq]
#align local_homeomorph.trans_of_set PartialHomeomorph.trans_ofSet
theorem trans_of_set' {s : Set Y} (hs : IsOpen s) :
e.trans (ofSet s hs) = e.restr (e.source ∩ e ⁻¹' s) := by rw [trans_ofSet, restr_source_inter]
#align local_homeomorph.trans_of_set' PartialHomeomorph.trans_of_set'
theorem ofSet_trans {s : Set X} (hs : IsOpen s) : (ofSet s hs).trans e = e.restr s :=
PartialHomeomorph.ext _ _ (fun x => rfl) (fun x => rfl) <| by simp [hs.interior_eq, inter_comm]
#align local_homeomorph.of_set_trans PartialHomeomorph.ofSet_trans
theorem ofSet_trans' {s : Set X} (hs : IsOpen s) :
(ofSet s hs).trans e = e.restr (e.source ∩ s) := by
rw [ofSet_trans, restr_source_inter]
#align local_homeomorph.of_set_trans' PartialHomeomorph.ofSet_trans'
@[simp, mfld_simps]
| Mathlib/Topology/PartialHomeomorph.lean | 938 | 941 | theorem ofSet_trans_ofSet {s : Set X} (hs : IsOpen s) {s' : Set X} (hs' : IsOpen s') :
(ofSet s hs).trans (ofSet s' hs') = ofSet (s ∩ s') (IsOpen.inter hs hs') := by |
rw [(ofSet s hs).trans_ofSet hs']
ext <;> simp [hs'.interior_eq]
|
/-
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.NormedSpace.Basic
import Mathlib.Analysis.Normed.Group.Hom
import Mathlib.Data.Real.Sqrt
import Mathlib.RingTheory.Ideal.QuotientOperations
import Mathlib.Topology.MetricSpace.HausdorffDistance
#align_import analysis.normed.group.quotient from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2"
/-!
# 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 `TopologicalAddGroup.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 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. -/
noncomputable instance normOnQuotient (S : AddSubgroup M) : Norm (M ⧸ S) where
norm x := sInf (norm '' { m | mk' S m = x })
#align norm_on_quotient normOnQuotient
theorem AddSubgroup.quotient_norm_eq {S : AddSubgroup M} (x : M ⧸ S) :
‖x‖ = sInf (norm '' { m : M | (m : M ⧸ S) = x }) :=
rfl
#align add_subgroup.quotient_norm_eq AddSubgroup.quotient_norm_eq
theorem QuotientAddGroup.norm_eq_infDist {S : AddSubgroup M} (x : M ⧸ S) :
‖x‖ = infDist 0 { m : M | (m : M ⧸ S) = x } := by
simp only [AddSubgroup.quotient_norm_eq, infDist_eq_iInf, sInf_image', dist_zero_left]
/-- 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`. -/
theorem QuotientAddGroup.norm_mk {S : AddSubgroup M} (x : M) :
‖(x : M ⧸ S)‖ = infDist x S := by
rw [norm_eq_infDist, ← infDist_image (IsometryEquiv.subLeft x).isometry,
IsometryEquiv.subLeft_apply, sub_zero, ← IsometryEquiv.preimage_symm]
congr 1 with y
simp only [mem_preimage, IsometryEquiv.subLeft_symm_apply, mem_setOf_eq, QuotientAddGroup.eq,
neg_add, neg_neg, neg_add_cancel_right, SetLike.mem_coe]
theorem image_norm_nonempty {S : AddSubgroup M} (x : M ⧸ S) :
(norm '' { m | mk' S m = x }).Nonempty :=
.image _ <| Quot.exists_rep x
#align image_norm_nonempty image_norm_nonempty
theorem bddBelow_image_norm (s : Set M) : BddBelow (norm '' s) :=
⟨0, forall_mem_image.2 fun _ _ ↦ norm_nonneg _⟩
#align bdd_below_image_norm bddBelow_image_norm
theorem isGLB_quotient_norm {S : AddSubgroup M} (x : M ⧸ S) :
IsGLB (norm '' { m | mk' S m = x }) (‖x‖) :=
isGLB_csInf (image_norm_nonempty x) (bddBelow_image_norm _)
/-- The norm on the quotient satisfies `‖-x‖ = ‖x‖`. -/
theorem quotient_norm_neg {S : AddSubgroup M} (x : M ⧸ S) : ‖-x‖ = ‖x‖ := by
simp only [AddSubgroup.quotient_norm_eq]
congr 1 with r
constructor <;> { rintro ⟨m, hm, rfl⟩; use -m; simpa [neg_eq_iff_eq_neg] using hm }
#align quotient_norm_neg quotient_norm_neg
| Mathlib/Analysis/Normed/Group/Quotient.lean | 147 | 148 | theorem quotient_norm_sub_rev {S : AddSubgroup M} (x y : M ⧸ S) : ‖x - y‖ = ‖y - x‖ := by |
rw [← neg_sub, quotient_norm_neg]
|
/-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import Mathlib.Algebra.Group.Submonoid.Membership
import Mathlib.Algebra.Group.Units
import Mathlib.Algebra.Regular.Basic
import Mathlib.GroupTheory.Congruence.Basic
import Mathlib.Init.Data.Prod
import Mathlib.RingTheory.OreLocalization.Basic
#align_import group_theory.monoid_localization from "leanprover-community/mathlib"@"10ee941346c27bdb5e87bb3535100c0b1f08ac41"
/-!
# Localizations of commutative monoids
Localizing a commutative ring at one of its submonoids does not rely on the ring's addition, so
we can generalize localizations to commutative monoids.
We characterize the localization of a commutative monoid `M` at a submonoid `S` up to
isomorphism; that is, a commutative monoid `N` is the localization of `M` at `S` iff we can find a
monoid homomorphism `f : M →* N` satisfying 3 properties:
1. For all `y ∈ S`, `f y` is a unit;
2. For all `z : N`, there exists `(x, y) : M × S` such that `z * f y = f x`;
3. For all `x, y : M` such that `f x = f y`, there exists `c ∈ S` such that `x * c = y * c`.
(The converse is a consequence of 1.)
Given such a localization map `f : M →* N`, we can define the surjection
`Submonoid.LocalizationMap.mk'` sending `(x, y) : M × S` to `f x * (f y)⁻¹`, and
`Submonoid.LocalizationMap.lift`, the homomorphism from `N` induced by a homomorphism from `M` which
maps elements of `S` to invertible elements of the codomain. Similarly, given commutative monoids
`P, Q`, a submonoid `T` of `P` and a localization map for `T` from `P` to `Q`, then a homomorphism
`g : M →* P` such that `g(S) ⊆ T` induces a homomorphism of localizations, `LocalizationMap.map`,
from `N` to `Q`. We treat the special case of localizing away from an element in the sections
`AwayMap` and `Away`.
We also define the quotient of `M × S` by the unique congruence relation (equivalence relation
preserving a binary operation) `r` such that for any other congruence relation `s` on `M × S`
satisfying '`∀ y ∈ S`, `(1, 1) ∼ (y, y)` under `s`', we have that `(x₁, y₁) ∼ (x₂, y₂)` by `s`
whenever `(x₁, y₁) ∼ (x₂, y₂)` by `r`. We show this relation is equivalent to the standard
localization relation.
This defines the localization as a quotient type, `Localization`, but the majority of
subsequent lemmas in the file are given in terms of localizations up to isomorphism, using maps
which satisfy the characteristic predicate.
The Grothendieck group construction corresponds to localizing at the top submonoid, namely making
every element invertible.
## Implementation notes
In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one
structure with an isomorphic one; one way around this is to isolate a predicate characterizing
a structure up to isomorphism, and reason about things that satisfy the predicate.
The infimum form of the localization congruence relation is chosen as 'canonical' here, since it
shortens some proofs.
To apply a localization map `f` as a function, we use `f.toMap`, as coercions don't work well for
this structure.
To reason about the localization as a quotient type, use `mk_eq_monoidOf_mk'` and associated
lemmas. These show the quotient map `mk : M → S → Localization S` equals the
surjection `LocalizationMap.mk'` induced by the map
`Localization.monoidOf : Submonoid.LocalizationMap S (Localization S)` (where `of` establishes the
localization as a quotient type satisfies the characteristic predicate). The lemma
`mk_eq_monoidOf_mk'` hence gives you access to the results in the rest of the file, which are about
the `LocalizationMap.mk'` induced by any localization map.
## TODO
* Show that the localization at the top monoid is a group.
* Generalise to (nonempty) subsemigroups.
* If we acquire more bundlings, we can make `Localization.mkOrderEmbedding` be an ordered monoid
embedding.
## Tags
localization, monoid localization, quotient monoid, congruence relation, characteristic predicate,
commutative monoid, grothendieck group
-/
open Function
namespace AddSubmonoid
variable {M : Type*} [AddCommMonoid M] (S : AddSubmonoid M) (N : Type*) [AddCommMonoid N]
/-- The type of AddMonoid homomorphisms satisfying the characteristic predicate: if `f : M →+ N`
satisfies this predicate, then `N` is isomorphic to the localization of `M` at `S`. -/
-- Porting note(#5171): this linter isn't ported yet.
-- @[nolint has_nonempty_instance]
structure LocalizationMap extends AddMonoidHom M N where
map_add_units' : ∀ y : S, IsAddUnit (toFun y)
surj' : ∀ z : N, ∃ x : M × S, z + toFun x.2 = toFun x.1
exists_of_eq : ∀ x y, toFun x = toFun y → ∃ c : S, ↑c + x = ↑c + y
#align add_submonoid.localization_map AddSubmonoid.LocalizationMap
-- Porting note: no docstrings for AddSubmonoid.LocalizationMap
attribute [nolint docBlame] AddSubmonoid.LocalizationMap.map_add_units'
AddSubmonoid.LocalizationMap.surj' AddSubmonoid.LocalizationMap.exists_of_eq
/-- The AddMonoidHom underlying a `LocalizationMap` of `AddCommMonoid`s. -/
add_decl_doc LocalizationMap.toAddMonoidHom
end AddSubmonoid
section CommMonoid
variable {M : Type*} [CommMonoid M] (S : Submonoid M) (N : Type*) [CommMonoid N] {P : Type*}
[CommMonoid P]
namespace Submonoid
/-- The type of monoid homomorphisms satisfying the characteristic predicate: if `f : M →* N`
satisfies this predicate, then `N` is isomorphic to the localization of `M` at `S`. -/
-- Porting note(#5171): this linter isn't ported yet.
-- @[nolint has_nonempty_instance]
structure LocalizationMap extends MonoidHom M N where
map_units' : ∀ y : S, IsUnit (toFun y)
surj' : ∀ z : N, ∃ x : M × S, z * toFun x.2 = toFun x.1
exists_of_eq : ∀ x y, toFun x = toFun y → ∃ c : S, ↑c * x = c * y
#align submonoid.localization_map Submonoid.LocalizationMap
-- Porting note: no docstrings for Submonoid.LocalizationMap
attribute [nolint docBlame] Submonoid.LocalizationMap.map_units' Submonoid.LocalizationMap.surj'
Submonoid.LocalizationMap.exists_of_eq
attribute [to_additive] Submonoid.LocalizationMap
-- Porting note: this translation already exists
-- attribute [to_additive] Submonoid.LocalizationMap.toMonoidHom
/-- The monoid hom underlying a `LocalizationMap`. -/
add_decl_doc LocalizationMap.toMonoidHom
end Submonoid
namespace Localization
-- Porting note: this does not work so it is done explicitly instead
-- run_cmd to_additive.map_namespace `Localization `AddLocalization
-- run_cmd Elab.Command.liftCoreM <| ToAdditive.insertTranslation `Localization `AddLocalization
/-- The congruence relation on `M × S`, `M` a `CommMonoid` and `S` a submonoid of `M`, whose
quotient is the localization of `M` at `S`, defined as the unique congruence relation on
`M × S` such that for any other congruence relation `s` on `M × S` where for all `y ∈ S`,
`(1, 1) ∼ (y, y)` under `s`, we have that `(x₁, y₁) ∼ (x₂, y₂)` by `r` implies
`(x₁, y₁) ∼ (x₂, y₂)` by `s`. -/
@[to_additive AddLocalization.r
"The congruence relation on `M × S`, `M` an `AddCommMonoid` and `S` an `AddSubmonoid` of `M`,
whose quotient is the localization of `M` at `S`, defined as the unique congruence relation on
`M × S` such that for any other congruence relation `s` on `M × S` where for all `y ∈ S`,
`(0, 0) ∼ (y, y)` under `s`, we have that `(x₁, y₁) ∼ (x₂, y₂)` by `r` implies
`(x₁, y₁) ∼ (x₂, y₂)` by `s`."]
def r (S : Submonoid M) : Con (M × S) :=
sInf { c | ∀ y : S, c 1 (y, y) }
#align localization.r Localization.r
#align add_localization.r AddLocalization.r
/-- An alternate form of the congruence relation on `M × S`, `M` a `CommMonoid` and `S` a
submonoid of `M`, whose quotient is the localization of `M` at `S`. -/
@[to_additive AddLocalization.r'
"An alternate form of the congruence relation on `M × S`, `M` a `CommMonoid` and `S` a
submonoid of `M`, whose quotient is the localization of `M` at `S`."]
def r' : Con (M × S) := by
-- note we multiply by `c` on the left so that we can later generalize to `•`
refine
{ r := fun a b : M × S ↦ ∃ c : S, ↑c * (↑b.2 * a.1) = c * (a.2 * b.1)
iseqv := ⟨fun a ↦ ⟨1, rfl⟩, fun ⟨c, hc⟩ ↦ ⟨c, hc.symm⟩, ?_⟩
mul' := ?_ }
· rintro a b c ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩
use t₂ * t₁ * b.2
simp only [Submonoid.coe_mul]
calc
(t₂ * t₁ * b.2 : M) * (c.2 * a.1) = t₂ * c.2 * (t₁ * (b.2 * a.1)) := by ac_rfl
_ = t₁ * a.2 * (t₂ * (c.2 * b.1)) := by rw [ht₁]; ac_rfl
_ = t₂ * t₁ * b.2 * (a.2 * c.1) := by rw [ht₂]; ac_rfl
· rintro a b c d ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩
use t₂ * t₁
calc
(t₂ * t₁ : M) * (b.2 * d.2 * (a.1 * c.1)) = t₂ * (d.2 * c.1) * (t₁ * (b.2 * a.1)) := by ac_rfl
_ = (t₂ * t₁ : M) * (a.2 * c.2 * (b.1 * d.1)) := by rw [ht₁, ht₂]; ac_rfl
#align localization.r' Localization.r'
#align add_localization.r' AddLocalization.r'
/-- The congruence relation used to localize a `CommMonoid` at a submonoid can be expressed
equivalently as an infimum (see `Localization.r`) or explicitly
(see `Localization.r'`). -/
@[to_additive AddLocalization.r_eq_r'
"The additive congruence relation used to localize an `AddCommMonoid` at a submonoid can be
expressed equivalently as an infimum (see `AddLocalization.r`) or explicitly
(see `AddLocalization.r'`)."]
theorem r_eq_r' : r S = r' S :=
le_antisymm (sInf_le fun _ ↦ ⟨1, by simp⟩) <|
le_sInf fun b H ⟨p, q⟩ ⟨x, y⟩ ⟨t, ht⟩ ↦ by
rw [← one_mul (p, q), ← one_mul (x, y)]
refine b.trans (b.mul (H (t * y)) (b.refl _)) ?_
convert b.symm (b.mul (H (t * q)) (b.refl (x, y))) using 1
dsimp only [Prod.mk_mul_mk, Submonoid.coe_mul] at ht ⊢
simp_rw [mul_assoc, ht, mul_comm y q]
#align localization.r_eq_r' Localization.r_eq_r'
#align add_localization.r_eq_r' AddLocalization.r_eq_r'
variable {S}
@[to_additive AddLocalization.r_iff_exists]
theorem r_iff_exists {x y : M × S} : r S x y ↔ ∃ c : S, ↑c * (↑y.2 * x.1) = c * (x.2 * y.1) := by
rw [r_eq_r' S]; rfl
#align localization.r_iff_exists Localization.r_iff_exists
#align add_localization.r_iff_exists AddLocalization.r_iff_exists
end Localization
/-- The localization of a `CommMonoid` at one of its submonoids (as a quotient type). -/
@[to_additive AddLocalization
"The localization of an `AddCommMonoid` at one of its submonoids (as a quotient type)."]
def Localization := (Localization.r S).Quotient
#align localization Localization
#align add_localization AddLocalization
namespace Localization
@[to_additive]
instance inhabited : Inhabited (Localization S) := Con.Quotient.inhabited
#align localization.inhabited Localization.inhabited
#align add_localization.inhabited AddLocalization.inhabited
/-- Multiplication in a `Localization` is defined as `⟨a, b⟩ * ⟨c, d⟩ = ⟨a * c, b * d⟩`. -/
@[to_additive "Addition in an `AddLocalization` is defined as `⟨a, b⟩ + ⟨c, d⟩ = ⟨a + c, b + d⟩`.
Should not be confused with the ring localization counterpart `Localization.add`, which maps
`⟨a, b⟩ + ⟨c, d⟩` to `⟨d * a + b * c, b * d⟩`."]
protected irreducible_def mul : Localization S → Localization S → Localization S :=
(r S).commMonoid.mul
#align localization.mul Localization.mul
#align add_localization.add AddLocalization.add
@[to_additive]
instance : Mul (Localization S) := ⟨Localization.mul S⟩
/-- The identity element of a `Localization` is defined as `⟨1, 1⟩`. -/
@[to_additive "The identity element of an `AddLocalization` is defined as `⟨0, 0⟩`.
Should not be confused with the ring localization counterpart `Localization.zero`,
which is defined as `⟨0, 1⟩`."]
protected irreducible_def one : Localization S := (r S).commMonoid.one
#align localization.one Localization.one
#align add_localization.zero AddLocalization.zero
@[to_additive]
instance : One (Localization S) := ⟨Localization.one S⟩
/-- Exponentiation in a `Localization` is defined as `⟨a, b⟩ ^ n = ⟨a ^ n, b ^ n⟩`.
This is a separate `irreducible` def to ensure the elaborator doesn't waste its time
trying to unify some huge recursive definition with itself, but unfolded one step less.
-/
@[to_additive "Multiplication with a natural in an `AddLocalization` is defined as
`n • ⟨a, b⟩ = ⟨n • a, n • b⟩`.
This is a separate `irreducible` def to ensure the elaborator doesn't waste its time
trying to unify some huge recursive definition with itself, but unfolded one step less."]
protected irreducible_def npow : ℕ → Localization S → Localization S := (r S).commMonoid.npow
#align localization.npow Localization.npow
#align add_localization.nsmul AddLocalization.nsmul
@[to_additive]
instance commMonoid : CommMonoid (Localization S) where
mul := (· * ·)
one := 1
mul_assoc x y z := show (x.mul S y).mul S z = x.mul S (y.mul S z) by
rw [Localization.mul]; apply (r S).commMonoid.mul_assoc
mul_comm x y := show x.mul S y = y.mul S x by
rw [Localization.mul]; apply (r S).commMonoid.mul_comm
mul_one x := show x.mul S (.one S) = x by
rw [Localization.mul, Localization.one]; apply (r S).commMonoid.mul_one
one_mul x := show (Localization.one S).mul S x = x by
rw [Localization.mul, Localization.one]; apply (r S).commMonoid.one_mul
npow := Localization.npow S
npow_zero x := show Localization.npow S 0 x = .one S by
rw [Localization.npow, Localization.one]; apply (r S).commMonoid.npow_zero
npow_succ n x := show Localization.npow S n.succ x = (Localization.npow S n x).mul S x by
rw [Localization.npow, Localization.mul]; apply (r S).commMonoid.npow_succ
variable {S}
/-- Given a `CommMonoid` `M` and submonoid `S`, `mk` sends `x : M`, `y ∈ S` to the equivalence
class of `(x, y)` in the localization of `M` at `S`. -/
@[to_additive
"Given an `AddCommMonoid` `M` and submonoid `S`, `mk` sends `x : M`, `y ∈ S` to
the equivalence class of `(x, y)` in the localization of `M` at `S`."]
def mk (x : M) (y : S) : Localization S := (r S).mk' (x, y)
#align localization.mk Localization.mk
#align add_localization.mk AddLocalization.mk
@[to_additive]
theorem mk_eq_mk_iff {a c : M} {b d : S} : mk a b = mk c d ↔ r S ⟨a, b⟩ ⟨c, d⟩ := (r S).eq
#align localization.mk_eq_mk_iff Localization.mk_eq_mk_iff
#align add_localization.mk_eq_mk_iff AddLocalization.mk_eq_mk_iff
universe u
/-- Dependent recursion principle for `Localizations`: given elements `f a b : p (mk a b)`
for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d` (with the correct coercions),
then `f` is defined on the whole `Localization S`. -/
@[to_additive (attr := elab_as_elim)
"Dependent recursion principle for `AddLocalizations`: given elements `f a b : p (mk a b)`
for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d` (with the correct coercions),
then `f` is defined on the whole `AddLocalization S`."]
def rec {p : Localization S → Sort u} (f : ∀ (a : M) (b : S), p (mk a b))
(H : ∀ {a c : M} {b d : S} (h : r S (a, b) (c, d)),
(Eq.ndrec (f a b) (mk_eq_mk_iff.mpr h) : p (mk c d)) = f c d) (x) : p x :=
Quot.rec (fun y ↦ Eq.ndrec (f y.1 y.2) (by rfl)) (fun y z h ↦ by cases y; cases z; exact H h) x
#align localization.rec Localization.rec
#align add_localization.rec AddLocalization.rec
/-- Copy of `Quotient.recOnSubsingleton₂` for `Localization` -/
@[to_additive (attr := elab_as_elim) "Copy of `Quotient.recOnSubsingleton₂` for `AddLocalization`"]
def recOnSubsingleton₂ {r : Localization S → Localization S → Sort u}
[h : ∀ (a c : M) (b d : S), Subsingleton (r (mk a b) (mk c d))] (x y : Localization S)
(f : ∀ (a c : M) (b d : S), r (mk a b) (mk c d)) : r x y :=
@Quotient.recOnSubsingleton₂' _ _ _ _ r (Prod.rec fun _ _ => Prod.rec fun _ _ => h _ _ _ _) x y
(Prod.rec fun _ _ => Prod.rec fun _ _ => f _ _ _ _)
#align localization.rec_on_subsingleton₂ Localization.recOnSubsingleton₂
#align add_localization.rec_on_subsingleton₂ AddLocalization.recOnSubsingleton₂
@[to_additive]
theorem mk_mul (a c : M) (b d : S) : mk a b * mk c d = mk (a * c) (b * d) :=
show Localization.mul S _ _ = _ by rw [Localization.mul]; rfl
#align localization.mk_mul Localization.mk_mul
#align add_localization.mk_add AddLocalization.mk_add
@[to_additive]
theorem mk_one : mk 1 (1 : S) = 1 :=
show mk _ _ = .one S by rw [Localization.one]; rfl
#align localization.mk_one Localization.mk_one
#align add_localization.mk_zero AddLocalization.mk_zero
@[to_additive]
theorem mk_pow (n : ℕ) (a : M) (b : S) : mk a b ^ n = mk (a ^ n) (b ^ n) :=
show Localization.npow S _ _ = _ by rw [Localization.npow]; rfl
#align localization.mk_pow Localization.mk_pow
#align add_localization.mk_nsmul AddLocalization.mk_nsmul
-- Porting note: mathport translated `rec` to `ndrec` in the name of this lemma
@[to_additive (attr := simp)]
theorem ndrec_mk {p : Localization S → Sort u} (f : ∀ (a : M) (b : S), p (mk a b)) (H) (a : M)
(b : S) : (rec f H (mk a b) : p (mk a b)) = f a b := rfl
#align localization.rec_mk Localization.ndrec_mk
#align add_localization.rec_mk AddLocalization.ndrec_mk
/-- Non-dependent recursion principle for localizations: given elements `f a b : p`
for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d`,
then `f` is defined on the whole `Localization S`. -/
-- Porting note: the attribute `elab_as_elim` fails with `unexpected eliminator resulting type p`
-- @[to_additive (attr := elab_as_elim)
@[to_additive
"Non-dependent recursion principle for `AddLocalization`s: given elements `f a b : p`
for all `a b`, such that `r S (a, b) (c, d)` implies `f a b = f c d`,
then `f` is defined on the whole `Localization S`."]
def liftOn {p : Sort u} (x : Localization S) (f : M → S → p)
(H : ∀ {a c : M} {b d : S}, r S (a, b) (c, d) → f a b = f c d) : p :=
rec f (fun h ↦ (by simpa only [eq_rec_constant] using H h)) x
#align localization.lift_on Localization.liftOn
#align add_localization.lift_on AddLocalization.liftOn
@[to_additive]
theorem liftOn_mk {p : Sort u} (f : M → S → p) (H) (a : M) (b : S) :
liftOn (mk a b) f H = f a b := rfl
#align localization.lift_on_mk Localization.liftOn_mk
#align add_localization.lift_on_mk AddLocalization.liftOn_mk
@[to_additive (attr := elab_as_elim)]
theorem ind {p : Localization S → Prop} (H : ∀ y : M × S, p (mk y.1 y.2)) (x) : p x :=
rec (fun a b ↦ H (a, b)) (fun _ ↦ rfl) x
#align localization.ind Localization.ind
#align add_localization.ind AddLocalization.ind
@[to_additive (attr := elab_as_elim)]
theorem induction_on {p : Localization S → Prop} (x) (H : ∀ y : M × S, p (mk y.1 y.2)) : p x :=
ind H x
#align localization.induction_on Localization.induction_on
#align add_localization.induction_on AddLocalization.induction_on
/-- Non-dependent recursion principle for localizations: given elements `f x y : p`
for all `x` and `y`, such that `r S x x'` and `r S y y'` implies `f x y = f x' y'`,
then `f` is defined on the whole `Localization S`. -/
-- Porting note: the attribute `elab_as_elim` fails with `unexpected eliminator resulting type p`
-- @[to_additive (attr := elab_as_elim)
@[to_additive
"Non-dependent recursion principle for localizations: given elements `f x y : p`
for all `x` and `y`, such that `r S x x'` and `r S y y'` implies `f x y = f x' y'`,
then `f` is defined on the whole `Localization S`."]
def liftOn₂ {p : Sort u} (x y : Localization S) (f : M → S → M → S → p)
(H : ∀ {a a' b b' c c' d d'}, r S (a, b) (a', b') → r S (c, d) (c', d') →
f a b c d = f a' b' c' d') : p :=
liftOn x (fun a b ↦ liftOn y (f a b) fun hy ↦ H ((r S).refl _) hy) fun hx ↦
induction_on y fun ⟨_, _⟩ ↦ H hx ((r S).refl _)
#align localization.lift_on₂ Localization.liftOn₂
#align add_localization.lift_on₂ AddLocalization.liftOn₂
@[to_additive]
theorem liftOn₂_mk {p : Sort*} (f : M → S → M → S → p) (H) (a c : M) (b d : S) :
liftOn₂ (mk a b) (mk c d) f H = f a b c d := rfl
#align localization.lift_on₂_mk Localization.liftOn₂_mk
#align add_localization.lift_on₂_mk AddLocalization.liftOn₂_mk
@[to_additive (attr := elab_as_elim)]
theorem induction_on₂ {p : Localization S → Localization S → Prop} (x y)
(H : ∀ x y : M × S, p (mk x.1 x.2) (mk y.1 y.2)) : p x y :=
induction_on x fun x ↦ induction_on y <| H x
#align localization.induction_on₂ Localization.induction_on₂
#align add_localization.induction_on₂ AddLocalization.induction_on₂
@[to_additive (attr := elab_as_elim)]
theorem induction_on₃ {p : Localization S → Localization S → Localization S → Prop} (x y z)
(H : ∀ x y z : M × S, p (mk x.1 x.2) (mk y.1 y.2) (mk z.1 z.2)) : p x y z :=
induction_on₂ x y fun x y ↦ induction_on z <| H x y
#align localization.induction_on₃ Localization.induction_on₃
#align add_localization.induction_on₃ AddLocalization.induction_on₃
@[to_additive]
theorem one_rel (y : S) : r S 1 (y, y) := fun _ hb ↦ hb y
#align localization.one_rel Localization.one_rel
#align add_localization.zero_rel AddLocalization.zero_rel
@[to_additive]
theorem r_of_eq {x y : M × S} (h : ↑y.2 * x.1 = ↑x.2 * y.1) : r S x y :=
r_iff_exists.2 ⟨1, by rw [h]⟩
#align localization.r_of_eq Localization.r_of_eq
#align add_localization.r_of_eq AddLocalization.r_of_eq
@[to_additive]
theorem mk_self (a : S) : mk (a : M) a = 1 := by
symm
rw [← mk_one, mk_eq_mk_iff]
exact one_rel a
#align localization.mk_self Localization.mk_self
#align add_localization.mk_self AddLocalization.mk_self
section Scalar
variable {R R₁ R₂ : Type*}
/-- Scalar multiplication in a monoid localization is defined as `c • ⟨a, b⟩ = ⟨c • a, b⟩`. -/
protected irreducible_def smul [SMul R M] [IsScalarTower R M M] (c : R) (z : Localization S) :
Localization S :=
Localization.liftOn z (fun a b ↦ mk (c • a) b)
(fun {a a' b b'} h ↦ mk_eq_mk_iff.2 (by
let ⟨b, hb⟩ := b
let ⟨b', hb'⟩ := b'
rw [r_eq_r'] at h ⊢
let ⟨t, ht⟩ := h
use t
dsimp only [Subtype.coe_mk] at ht ⊢
-- TODO: this definition should take `SMulCommClass R M M` instead of `IsScalarTower R M M` if
-- we ever want to generalize to the non-commutative case.
haveI : SMulCommClass R M M :=
⟨fun r m₁ m₂ ↦ by simp_rw [smul_eq_mul, mul_comm m₁, smul_mul_assoc]⟩
simp only [mul_smul_comm, ht]))
#align localization.smul Localization.smul
instance instSMulLocalization [SMul R M] [IsScalarTower R M M] : SMul R (Localization S) where
smul := Localization.smul
theorem smul_mk [SMul R M] [IsScalarTower R M M] (c : R) (a b) :
c • (mk a b : Localization S) = mk (c • a) b := by
simp only [HSMul.hSMul, instHSMul, SMul.smul, instSMulLocalization, Localization.smul]
show liftOn (mk a b) (fun a b => mk (c • a) b) _ = _
exact liftOn_mk (fun a b => mk (c • a) b) _ a b
#align localization.smul_mk Localization.smul_mk
instance [SMul R₁ M] [SMul R₂ M] [IsScalarTower R₁ M M] [IsScalarTower R₂ M M]
[SMulCommClass R₁ R₂ M] : SMulCommClass R₁ R₂ (Localization S) where
smul_comm s t := Localization.ind <| Prod.rec fun r x ↦ by simp only [smul_mk, smul_comm s t r]
instance [SMul R₁ M] [SMul R₂ M] [IsScalarTower R₁ M M] [IsScalarTower R₂ M M] [SMul R₁ R₂]
[IsScalarTower R₁ R₂ M] : IsScalarTower R₁ R₂ (Localization S) where
smul_assoc s t := Localization.ind <| Prod.rec fun r x ↦ by simp only [smul_mk, smul_assoc s t r]
instance smulCommClass_right {R : Type*} [SMul R M] [IsScalarTower R M M] :
SMulCommClass R (Localization S) (Localization S) where
smul_comm s :=
Localization.ind <|
Prod.rec fun r₁ x₁ ↦
Localization.ind <|
Prod.rec fun r₂ x₂ ↦ by
simp only [smul_mk, smul_eq_mul, mk_mul, mul_comm r₁, smul_mul_assoc]
#align localization.smul_comm_class_right Localization.smulCommClass_right
instance isScalarTower_right {R : Type*} [SMul R M] [IsScalarTower R M M] :
IsScalarTower R (Localization S) (Localization S) where
smul_assoc s :=
Localization.ind <|
Prod.rec fun r₁ x₁ ↦
Localization.ind <|
Prod.rec fun r₂ x₂ ↦ by simp only [smul_mk, smul_eq_mul, mk_mul, smul_mul_assoc]
#align localization.is_scalar_tower_right Localization.isScalarTower_right
instance [SMul R M] [SMul Rᵐᵒᵖ M] [IsScalarTower R M M] [IsScalarTower Rᵐᵒᵖ M M]
[IsCentralScalar R M] : IsCentralScalar R (Localization S) where
op_smul_eq_smul s :=
Localization.ind <| Prod.rec fun r x ↦ by simp only [smul_mk, op_smul_eq_smul]
instance [Monoid R] [MulAction R M] [IsScalarTower R M M] : MulAction R (Localization S) where
one_smul :=
Localization.ind <|
Prod.rec <| by
intros
simp only [Localization.smul_mk, one_smul]
mul_smul s₁ s₂ :=
Localization.ind <|
Prod.rec <| by
intros
simp only [Localization.smul_mk, mul_smul]
instance [Monoid R] [MulDistribMulAction R M] [IsScalarTower R M M] :
MulDistribMulAction R (Localization S) where
smul_one s := by simp only [← Localization.mk_one, Localization.smul_mk, smul_one]
smul_mul s x y :=
Localization.induction_on₂ x y <|
Prod.rec fun r₁ x₁ ↦
Prod.rec fun r₂ x₂ ↦ by simp only [Localization.smul_mk, Localization.mk_mul, smul_mul']
end Scalar
end Localization
variable {S N}
namespace MonoidHom
/-- Makes a localization map from a `CommMonoid` hom satisfying the characteristic predicate. -/
@[to_additive
"Makes a localization map from an `AddCommMonoid` hom satisfying the characteristic predicate."]
def toLocalizationMap (f : M →* N) (H1 : ∀ y : S, IsUnit (f y))
(H2 : ∀ z, ∃ x : M × S, z * f x.2 = f x.1) (H3 : ∀ x y, f x = f y → ∃ c : S, ↑c * x = ↑c * y) :
Submonoid.LocalizationMap S N :=
{ f with
map_units' := H1
surj' := H2
exists_of_eq := H3 }
#align monoid_hom.to_localization_map MonoidHom.toLocalizationMap
#align add_monoid_hom.to_localization_map AddMonoidHom.toLocalizationMap
end MonoidHom
namespace Submonoid
namespace LocalizationMap
/-- Short for `toMonoidHom`; used to apply a localization map as a function. -/
@[to_additive "Short for `toAddMonoidHom`; used to apply a localization map as a function."]
abbrev toMap (f : LocalizationMap S N) := f.toMonoidHom
#align submonoid.localization_map.to_map Submonoid.LocalizationMap.toMap
#align add_submonoid.localization_map.to_map AddSubmonoid.LocalizationMap.toMap
@[to_additive (attr := ext)]
theorem ext {f g : LocalizationMap S N} (h : ∀ x, f.toMap x = g.toMap x) : f = g := by
rcases f with ⟨⟨⟩⟩
rcases g with ⟨⟨⟩⟩
simp only [mk.injEq, MonoidHom.mk.injEq]
exact OneHom.ext h
#align submonoid.localization_map.ext Submonoid.LocalizationMap.ext
#align add_submonoid.localization_map.ext AddSubmonoid.LocalizationMap.ext
@[to_additive]
theorem ext_iff {f g : LocalizationMap S N} : f = g ↔ ∀ x, f.toMap x = g.toMap x :=
⟨fun h _ ↦ h ▸ rfl, ext⟩
#align submonoid.localization_map.ext_iff Submonoid.LocalizationMap.ext_iff
#align add_submonoid.localization_map.ext_iff AddSubmonoid.LocalizationMap.ext_iff
@[to_additive]
theorem toMap_injective : Function.Injective (@LocalizationMap.toMap _ _ S N _) :=
fun _ _ h ↦ ext <| DFunLike.ext_iff.1 h
#align submonoid.localization_map.to_map_injective Submonoid.LocalizationMap.toMap_injective
#align add_submonoid.localization_map.to_map_injective AddSubmonoid.LocalizationMap.toMap_injective
@[to_additive]
theorem map_units (f : LocalizationMap S N) (y : S) : IsUnit (f.toMap y) :=
f.2 y
#align submonoid.localization_map.map_units Submonoid.LocalizationMap.map_units
#align add_submonoid.localization_map.map_add_units AddSubmonoid.LocalizationMap.map_addUnits
@[to_additive]
theorem surj (f : LocalizationMap S N) (z : N) : ∃ x : M × S, z * f.toMap x.2 = f.toMap x.1 :=
f.3 z
#align submonoid.localization_map.surj Submonoid.LocalizationMap.surj
#align add_submonoid.localization_map.surj AddSubmonoid.LocalizationMap.surj
/-- Given a localization map `f : M →* N`, and `z w : N`, there exist `z' w' : M` and `d : S`
such that `f z' / f d = z` and `f w' / f d = w`. -/
@[to_additive
"Given a localization map `f : M →+ N`, and `z w : N`, there exist `z' w' : M` and `d : S`
such that `f z' - f d = z` and `f w' - f d = w`."]
theorem surj₂ (f : LocalizationMap S N) (z w : N) : ∃ z' w' : M, ∃ d : S,
(z * f.toMap d = f.toMap z') ∧ (w * f.toMap d = f.toMap w') := by
let ⟨a, ha⟩ := surj f z
let ⟨b, hb⟩ := surj f w
refine ⟨a.1 * b.2, a.2 * b.1, a.2 * b.2, ?_, ?_⟩
· simp_rw [mul_def, map_mul, ← ha]
exact (mul_assoc z _ _).symm
· simp_rw [mul_def, map_mul, ← hb]
exact mul_left_comm w _ _
@[to_additive]
theorem eq_iff_exists (f : LocalizationMap S N) {x y} :
f.toMap x = f.toMap y ↔ ∃ c : S, ↑c * x = c * y := Iff.intro (f.4 x y)
fun ⟨c, h⟩ ↦ by
replace h := congr_arg f.toMap h
rw [map_mul, map_mul] at h
exact (f.map_units c).mul_right_inj.mp h
#align submonoid.localization_map.eq_iff_exists Submonoid.LocalizationMap.eq_iff_exists
#align add_submonoid.localization_map.eq_iff_exists AddSubmonoid.LocalizationMap.eq_iff_exists
/-- Given a localization map `f : M →* N`, a section function sending `z : N` to some
`(x, y) : M × S` such that `f x * (f y)⁻¹ = z`. -/
@[to_additive
"Given a localization map `f : M →+ N`, a section function sending `z : N`
to some `(x, y) : M × S` such that `f x - f y = z`."]
noncomputable def sec (f : LocalizationMap S N) (z : N) : M × S := Classical.choose <| f.surj z
#align submonoid.localization_map.sec Submonoid.LocalizationMap.sec
#align add_submonoid.localization_map.sec AddSubmonoid.LocalizationMap.sec
@[to_additive]
theorem sec_spec {f : LocalizationMap S N} (z : N) :
z * f.toMap (f.sec z).2 = f.toMap (f.sec z).1 := Classical.choose_spec <| f.surj z
#align submonoid.localization_map.sec_spec Submonoid.LocalizationMap.sec_spec
#align add_submonoid.localization_map.sec_spec AddSubmonoid.LocalizationMap.sec_spec
@[to_additive]
theorem sec_spec' {f : LocalizationMap S N} (z : N) :
f.toMap (f.sec z).1 = f.toMap (f.sec z).2 * z := by rw [mul_comm, sec_spec]
#align submonoid.localization_map.sec_spec' Submonoid.LocalizationMap.sec_spec'
#align add_submonoid.localization_map.sec_spec' AddSubmonoid.LocalizationMap.sec_spec'
/-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all
`w, z : N` and `y ∈ S`, we have `w * (f y)⁻¹ = z ↔ w = f y * z`. -/
@[to_additive
"Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that
`f(S) ⊆ AddUnits N`, for all `w, z : N` and `y ∈ S`, we have `w - f y = z ↔ w = f y + z`."]
theorem mul_inv_left {f : M →* N} (h : ∀ y : S, IsUnit (f y)) (y : S) (w z : N) :
w * (IsUnit.liftRight (f.restrict S) h y)⁻¹ = z ↔ w = f y * z := by
rw [mul_comm]
exact Units.inv_mul_eq_iff_eq_mul (IsUnit.liftRight (f.restrict S) h y)
#align submonoid.localization_map.mul_inv_left Submonoid.LocalizationMap.mul_inv_left
#align add_submonoid.localization_map.add_neg_left AddSubmonoid.LocalizationMap.add_neg_left
/-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all
`w, z : N` and `y ∈ S`, we have `z = w * (f y)⁻¹ ↔ z * f y = w`. -/
@[to_additive
"Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that
`f(S) ⊆ AddUnits N`, for all `w, z : N` and `y ∈ S`, we have `z = w - f y ↔ z + f y = w`."]
theorem mul_inv_right {f : M →* N} (h : ∀ y : S, IsUnit (f y)) (y : S) (w z : N) :
z = w * (IsUnit.liftRight (f.restrict S) h y)⁻¹ ↔ z * f y = w := by
rw [eq_comm, mul_inv_left h, mul_comm, eq_comm]
#align submonoid.localization_map.mul_inv_right Submonoid.LocalizationMap.mul_inv_right
#align add_submonoid.localization_map.add_neg_right AddSubmonoid.LocalizationMap.add_neg_right
/-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that
`f(S) ⊆ Nˣ`, for all `x₁ x₂ : M` and `y₁, y₂ ∈ S`, we have
`f x₁ * (f y₁)⁻¹ = f x₂ * (f y₂)⁻¹ ↔ f (x₁ * y₂) = f (x₂ * y₁)`. -/
@[to_additive (attr := simp)
"Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that
`f(S) ⊆ AddUnits N`, for all `x₁ x₂ : M` and `y₁, y₂ ∈ S`, we have
`f x₁ - f y₁ = f x₂ - f y₂ ↔ f (x₁ + y₂) = f (x₂ + y₁)`."]
theorem mul_inv {f : M →* N} (h : ∀ y : S, IsUnit (f y)) {x₁ x₂} {y₁ y₂ : S} :
f x₁ * (IsUnit.liftRight (f.restrict S) h y₁)⁻¹ =
f x₂ * (IsUnit.liftRight (f.restrict S) h y₂)⁻¹ ↔
f (x₁ * y₂) = f (x₂ * y₁) := by
rw [mul_inv_right h, mul_assoc, mul_comm _ (f y₂), ← mul_assoc, mul_inv_left h, mul_comm x₂,
f.map_mul, f.map_mul]
#align submonoid.localization_map.mul_inv Submonoid.LocalizationMap.mul_inv
#align add_submonoid.localization_map.add_neg AddSubmonoid.LocalizationMap.add_neg
/-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all
`y, z ∈ S`, we have `(f y)⁻¹ = (f z)⁻¹ → f y = f z`. -/
@[to_additive
"Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that
`f(S) ⊆ AddUnits N`, for all `y, z ∈ S`, we have `- (f y) = - (f z) → f y = f z`."]
theorem inv_inj {f : M →* N} (hf : ∀ y : S, IsUnit (f y)) {y z : S}
(h : (IsUnit.liftRight (f.restrict S) hf y)⁻¹ = (IsUnit.liftRight (f.restrict S) hf z)⁻¹) :
f y = f z := by
rw [← mul_one (f y), eq_comm, ← mul_inv_left hf y (f z) 1, h]
exact Units.inv_mul (IsUnit.liftRight (f.restrict S) hf z)⁻¹
#align submonoid.localization_map.inv_inj Submonoid.LocalizationMap.inv_inj
#align add_submonoid.localization_map.neg_inj AddSubmonoid.LocalizationMap.neg_inj
/-- Given a MonoidHom `f : M →* N` and Submonoid `S ⊆ M` such that `f(S) ⊆ Nˣ`, for all
`y ∈ S`, `(f y)⁻¹` is unique. -/
@[to_additive
"Given an AddMonoidHom `f : M →+ N` and Submonoid `S ⊆ M` such that
`f(S) ⊆ AddUnits N`, for all `y ∈ S`, `- (f y)` is unique."]
theorem inv_unique {f : M →* N} (h : ∀ y : S, IsUnit (f y)) {y : S} {z : N} (H : f y * z = 1) :
(IsUnit.liftRight (f.restrict S) h y)⁻¹ = z := by
rw [← one_mul _⁻¹, Units.val_mul, mul_inv_left]
exact H.symm
#align submonoid.localization_map.inv_unique Submonoid.LocalizationMap.inv_unique
#align add_submonoid.localization_map.neg_unique AddSubmonoid.LocalizationMap.neg_unique
variable (f : LocalizationMap S N)
@[to_additive]
theorem map_right_cancel {x y} {c : S} (h : f.toMap (c * x) = f.toMap (c * y)) :
f.toMap x = f.toMap y := by
rw [f.toMap.map_mul, f.toMap.map_mul] at h
let ⟨u, hu⟩ := f.map_units c
rw [← hu] at h
exact (Units.mul_right_inj u).1 h
#align submonoid.localization_map.map_right_cancel Submonoid.LocalizationMap.map_right_cancel
#align add_submonoid.localization_map.map_right_cancel AddSubmonoid.LocalizationMap.map_right_cancel
@[to_additive]
theorem map_left_cancel {x y} {c : S} (h : f.toMap (x * c) = f.toMap (y * c)) :
f.toMap x = f.toMap y :=
f.map_right_cancel <| by rw [mul_comm _ x, mul_comm _ y, h]
#align submonoid.localization_map.map_left_cancel Submonoid.LocalizationMap.map_left_cancel
#align add_submonoid.localization_map.map_left_cancel AddSubmonoid.LocalizationMap.map_left_cancel
/-- Given a localization map `f : M →* N`, the surjection sending `(x, y) : M × S` to
`f x * (f y)⁻¹`. -/
@[to_additive
"Given a localization map `f : M →+ N`, the surjection sending `(x, y) : M × S`
to `f x - f y`."]
noncomputable def mk' (f : LocalizationMap S N) (x : M) (y : S) : N :=
f.toMap x * ↑(IsUnit.liftRight (f.toMap.restrict S) f.map_units y)⁻¹
#align submonoid.localization_map.mk' Submonoid.LocalizationMap.mk'
#align add_submonoid.localization_map.mk' AddSubmonoid.LocalizationMap.mk'
@[to_additive]
theorem mk'_mul (x₁ x₂ : M) (y₁ y₂ : S) : f.mk' (x₁ * x₂) (y₁ * y₂) = f.mk' x₁ y₁ * f.mk' x₂ y₂ :=
(mul_inv_left f.map_units _ _ _).2 <|
show _ = _ * (_ * _ * (_ * _)) by
rw [← mul_assoc, ← mul_assoc, mul_inv_right f.map_units, mul_assoc, mul_assoc,
mul_comm _ (f.toMap x₂), ← mul_assoc, ← mul_assoc, mul_inv_right f.map_units,
Submonoid.coe_mul, f.toMap.map_mul, f.toMap.map_mul]
ac_rfl
#align submonoid.localization_map.mk'_mul Submonoid.LocalizationMap.mk'_mul
#align add_submonoid.localization_map.mk'_add AddSubmonoid.LocalizationMap.mk'_add
@[to_additive]
theorem mk'_one (x) : f.mk' x (1 : S) = f.toMap x := by
rw [mk', MonoidHom.map_one]
exact mul_one _
#align submonoid.localization_map.mk'_one Submonoid.LocalizationMap.mk'_one
#align add_submonoid.localization_map.mk'_zero AddSubmonoid.LocalizationMap.mk'_zero
/-- Given a localization map `f : M →* N` for a submonoid `S ⊆ M`, for all `z : N` we have that if
`x : M, y ∈ S` are such that `z * f y = f x`, then `f x * (f y)⁻¹ = z`. -/
@[to_additive (attr := simp)
"Given a localization map `f : M →+ N` for a Submonoid `S ⊆ M`, for all `z : N`
we have that if `x : M, y ∈ S` are such that `z + f y = f x`, then `f x - f y = z`."]
theorem mk'_sec (z : N) : f.mk' (f.sec z).1 (f.sec z).2 = z :=
show _ * _ = _ by rw [← sec_spec, mul_inv_left, mul_comm]
#align submonoid.localization_map.mk'_sec Submonoid.LocalizationMap.mk'_sec
#align add_submonoid.localization_map.mk'_sec AddSubmonoid.LocalizationMap.mk'_sec
@[to_additive]
theorem mk'_surjective (z : N) : ∃ (x : _) (y : S), f.mk' x y = z :=
⟨(f.sec z).1, (f.sec z).2, f.mk'_sec z⟩
#align submonoid.localization_map.mk'_surjective Submonoid.LocalizationMap.mk'_surjective
#align add_submonoid.localization_map.mk'_surjective AddSubmonoid.LocalizationMap.mk'_surjective
@[to_additive]
theorem mk'_spec (x) (y : S) : f.mk' x y * f.toMap y = f.toMap x :=
show _ * _ * _ = _ by rw [mul_assoc, mul_comm _ (f.toMap y), ← mul_assoc, mul_inv_left, mul_comm]
#align submonoid.localization_map.mk'_spec Submonoid.LocalizationMap.mk'_spec
#align add_submonoid.localization_map.mk'_spec AddSubmonoid.LocalizationMap.mk'_spec
@[to_additive]
theorem mk'_spec' (x) (y : S) : f.toMap y * f.mk' x y = f.toMap x := by rw [mul_comm, mk'_spec]
#align submonoid.localization_map.mk'_spec' Submonoid.LocalizationMap.mk'_spec'
#align add_submonoid.localization_map.mk'_spec' AddSubmonoid.LocalizationMap.mk'_spec'
@[to_additive]
theorem eq_mk'_iff_mul_eq {x} {y : S} {z} : z = f.mk' x y ↔ z * f.toMap y = f.toMap x :=
⟨fun H ↦ by rw [H, mk'_spec], fun H ↦ by erw [mul_inv_right, H]⟩
#align submonoid.localization_map.eq_mk'_iff_mul_eq Submonoid.LocalizationMap.eq_mk'_iff_mul_eq
#align add_submonoid.localization_map.eq_mk'_iff_add_eq AddSubmonoid.LocalizationMap.eq_mk'_iff_add_eq
@[to_additive]
theorem mk'_eq_iff_eq_mul {x} {y : S} {z} : f.mk' x y = z ↔ f.toMap x = z * f.toMap y := by
rw [eq_comm, eq_mk'_iff_mul_eq, eq_comm]
#align submonoid.localization_map.mk'_eq_iff_eq_mul Submonoid.LocalizationMap.mk'_eq_iff_eq_mul
#align add_submonoid.localization_map.mk'_eq_iff_eq_add AddSubmonoid.LocalizationMap.mk'_eq_iff_eq_add
@[to_additive]
theorem mk'_eq_iff_eq {x₁ x₂} {y₁ y₂ : S} :
f.mk' x₁ y₁ = f.mk' x₂ y₂ ↔ f.toMap (y₂ * x₁) = f.toMap (y₁ * x₂) :=
⟨fun H ↦ by
rw [f.toMap.map_mul, f.toMap.map_mul, f.mk'_eq_iff_eq_mul.1 H,← mul_assoc, mk'_spec',
mul_comm ((toMap f) x₂) _],
fun H ↦ by
rw [mk'_eq_iff_eq_mul, mk', mul_assoc, mul_comm _ (f.toMap y₁), ← mul_assoc, ←
f.toMap.map_mul, mul_comm x₂, ← H, ← mul_comm x₁, f.toMap.map_mul,
mul_inv_right f.map_units]⟩
#align submonoid.localization_map.mk'_eq_iff_eq Submonoid.LocalizationMap.mk'_eq_iff_eq
#align add_submonoid.localization_map.mk'_eq_iff_eq AddSubmonoid.LocalizationMap.mk'_eq_iff_eq
@[to_additive]
theorem mk'_eq_iff_eq' {x₁ x₂} {y₁ y₂ : S} :
f.mk' x₁ y₁ = f.mk' x₂ y₂ ↔ f.toMap (x₁ * y₂) = f.toMap (x₂ * y₁) := by
simp only [f.mk'_eq_iff_eq, mul_comm]
#align submonoid.localization_map.mk'_eq_iff_eq' Submonoid.LocalizationMap.mk'_eq_iff_eq'
#align add_submonoid.localization_map.mk'_eq_iff_eq' AddSubmonoid.LocalizationMap.mk'_eq_iff_eq'
@[to_additive]
protected theorem eq {a₁ b₁} {a₂ b₂ : S} :
f.mk' a₁ a₂ = f.mk' b₁ b₂ ↔ ∃ c : S, ↑c * (↑b₂ * a₁) = c * (a₂ * b₁) :=
f.mk'_eq_iff_eq.trans <| f.eq_iff_exists
#align submonoid.localization_map.eq Submonoid.LocalizationMap.eq
#align add_submonoid.localization_map.eq AddSubmonoid.LocalizationMap.eq
@[to_additive]
protected theorem eq' {a₁ b₁} {a₂ b₂ : S} :
f.mk' a₁ a₂ = f.mk' b₁ b₂ ↔ Localization.r S (a₁, a₂) (b₁, b₂) := by
rw [f.eq, Localization.r_iff_exists]
#align submonoid.localization_map.eq' Submonoid.LocalizationMap.eq'
#align add_submonoid.localization_map.eq' AddSubmonoid.LocalizationMap.eq'
@[to_additive]
theorem eq_iff_eq (g : LocalizationMap S P) {x y} : f.toMap x = f.toMap y ↔ g.toMap x = g.toMap y :=
f.eq_iff_exists.trans g.eq_iff_exists.symm
#align submonoid.localization_map.eq_iff_eq Submonoid.LocalizationMap.eq_iff_eq
#align add_submonoid.localization_map.eq_iff_eq AddSubmonoid.LocalizationMap.eq_iff_eq
@[to_additive]
theorem mk'_eq_iff_mk'_eq (g : LocalizationMap S P) {x₁ x₂} {y₁ y₂ : S} :
f.mk' x₁ y₁ = f.mk' x₂ y₂ ↔ g.mk' x₁ y₁ = g.mk' x₂ y₂ :=
f.eq'.trans g.eq'.symm
#align submonoid.localization_map.mk'_eq_iff_mk'_eq Submonoid.LocalizationMap.mk'_eq_iff_mk'_eq
#align add_submonoid.localization_map.mk'_eq_iff_mk'_eq AddSubmonoid.LocalizationMap.mk'_eq_iff_mk'_eq
/-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, for all `x₁ : M` and `y₁ ∈ S`,
if `x₂ : M, y₂ ∈ S` are such that `f x₁ * (f y₁)⁻¹ * f y₂ = f x₂`, then there exists `c ∈ S`
such that `x₁ * y₂ * c = x₂ * y₁ * c`. -/
@[to_additive
"Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, for all `x₁ : M`
and `y₁ ∈ S`, if `x₂ : M, y₂ ∈ S` are such that `(f x₁ - f y₁) + f y₂ = f x₂`, then there exists
`c ∈ S` such that `x₁ + y₂ + c = x₂ + y₁ + c`."]
theorem exists_of_sec_mk' (x) (y : S) :
∃ c : S, ↑c * (↑(f.sec <| f.mk' x y).2 * x) = c * (y * (f.sec <| f.mk' x y).1) :=
f.eq_iff_exists.1 <| f.mk'_eq_iff_eq.1 <| (mk'_sec _ _).symm
#align submonoid.localization_map.exists_of_sec_mk' Submonoid.LocalizationMap.exists_of_sec_mk'
#align add_submonoid.localization_map.exists_of_sec_mk' AddSubmonoid.LocalizationMap.exists_of_sec_mk'
@[to_additive]
theorem mk'_eq_of_eq {a₁ b₁ : M} {a₂ b₂ : S} (H : ↑a₂ * b₁ = ↑b₂ * a₁) :
f.mk' a₁ a₂ = f.mk' b₁ b₂ :=
f.mk'_eq_iff_eq.2 <| H ▸ rfl
#align submonoid.localization_map.mk'_eq_of_eq Submonoid.LocalizationMap.mk'_eq_of_eq
#align add_submonoid.localization_map.mk'_eq_of_eq AddSubmonoid.LocalizationMap.mk'_eq_of_eq
@[to_additive]
theorem mk'_eq_of_eq' {a₁ b₁ : M} {a₂ b₂ : S} (H : b₁ * ↑a₂ = a₁ * ↑b₂) :
f.mk' a₁ a₂ = f.mk' b₁ b₂ :=
f.mk'_eq_of_eq <| by simpa only [mul_comm] using H
#align submonoid.localization_map.mk'_eq_of_eq' Submonoid.LocalizationMap.mk'_eq_of_eq'
#align add_submonoid.localization_map.mk'_eq_of_eq' AddSubmonoid.LocalizationMap.mk'_eq_of_eq'
@[to_additive]
theorem mk'_cancel (a : M) (b c : S) :
f.mk' (a * c) (b * c) = f.mk' a b :=
mk'_eq_of_eq' f (by rw [Submonoid.coe_mul, mul_comm (b:M), mul_assoc])
@[to_additive]
theorem mk'_eq_of_same {a b} {d : S} :
f.mk' a d = f.mk' b d ↔ ∃ c : S, c * a = c * b := by
rw [mk'_eq_iff_eq', map_mul, map_mul, ← eq_iff_exists f]
exact (map_units f d).mul_left_inj
@[to_additive (attr := simp)]
theorem mk'_self' (y : S) : f.mk' (y : M) y = 1 :=
show _ * _ = _ by rw [mul_inv_left, mul_one]
#align submonoid.localization_map.mk'_self' Submonoid.LocalizationMap.mk'_self'
#align add_submonoid.localization_map.mk'_self' AddSubmonoid.LocalizationMap.mk'_self'
@[to_additive (attr := simp)]
theorem mk'_self (x) (H : x ∈ S) : f.mk' x ⟨x, H⟩ = 1 := mk'_self' f ⟨x, H⟩
#align submonoid.localization_map.mk'_self Submonoid.LocalizationMap.mk'_self
#align add_submonoid.localization_map.mk'_self AddSubmonoid.LocalizationMap.mk'_self
@[to_additive]
theorem mul_mk'_eq_mk'_of_mul (x₁ x₂) (y : S) : f.toMap x₁ * f.mk' x₂ y = f.mk' (x₁ * x₂) y := by
rw [← mk'_one, ← mk'_mul, one_mul]
#align submonoid.localization_map.mul_mk'_eq_mk'_of_mul Submonoid.LocalizationMap.mul_mk'_eq_mk'_of_mul
#align add_submonoid.localization_map.add_mk'_eq_mk'_of_add AddSubmonoid.LocalizationMap.add_mk'_eq_mk'_of_add
@[to_additive]
theorem mk'_mul_eq_mk'_of_mul (x₁ x₂) (y : S) : f.mk' x₂ y * f.toMap x₁ = f.mk' (x₁ * x₂) y := by
rw [mul_comm, mul_mk'_eq_mk'_of_mul]
#align submonoid.localization_map.mk'_mul_eq_mk'_of_mul Submonoid.LocalizationMap.mk'_mul_eq_mk'_of_mul
#align add_submonoid.localization_map.mk'_add_eq_mk'_of_add AddSubmonoid.LocalizationMap.mk'_add_eq_mk'_of_add
@[to_additive]
theorem mul_mk'_one_eq_mk' (x) (y : S) : f.toMap x * f.mk' 1 y = f.mk' x y := by
rw [mul_mk'_eq_mk'_of_mul, mul_one]
#align submonoid.localization_map.mul_mk'_one_eq_mk' Submonoid.LocalizationMap.mul_mk'_one_eq_mk'
#align add_submonoid.localization_map.add_mk'_zero_eq_mk' AddSubmonoid.LocalizationMap.add_mk'_zero_eq_mk'
@[to_additive (attr := simp)]
theorem mk'_mul_cancel_right (x : M) (y : S) : f.mk' (x * y) y = f.toMap x := by
rw [← mul_mk'_one_eq_mk', f.toMap.map_mul, mul_assoc, mul_mk'_one_eq_mk', mk'_self', mul_one]
#align submonoid.localization_map.mk'_mul_cancel_right Submonoid.LocalizationMap.mk'_mul_cancel_right
#align add_submonoid.localization_map.mk'_add_cancel_right AddSubmonoid.LocalizationMap.mk'_add_cancel_right
@[to_additive]
theorem mk'_mul_cancel_left (x) (y : S) : f.mk' ((y : M) * x) y = f.toMap x := by
rw [mul_comm, mk'_mul_cancel_right]
#align submonoid.localization_map.mk'_mul_cancel_left Submonoid.LocalizationMap.mk'_mul_cancel_left
#align add_submonoid.localization_map.mk'_add_cancel_left AddSubmonoid.LocalizationMap.mk'_add_cancel_left
@[to_additive]
theorem isUnit_comp (j : N →* P) (y : S) : IsUnit (j.comp f.toMap y) :=
⟨Units.map j <| IsUnit.liftRight (f.toMap.restrict S) f.map_units y,
show j _ = j _ from congr_arg j <| IsUnit.coe_liftRight (f.toMap.restrict S) f.map_units _⟩
#align submonoid.localization_map.is_unit_comp Submonoid.LocalizationMap.isUnit_comp
#align add_submonoid.localization_map.is_add_unit_comp AddSubmonoid.LocalizationMap.isAddUnit_comp
variable {g : M →* P}
/-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M` and a map of `CommMonoid`s
`g : M →* P` such that `g(S) ⊆ Units P`, `f x = f y → g x = g y` for all `x y : M`. -/
@[to_additive
"Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M` and a map of
`AddCommMonoid`s `g : M →+ P` such that `g(S) ⊆ AddUnits P`, `f x = f y → g x = g y`
for all `x y : M`."]
theorem eq_of_eq (hg : ∀ y : S, IsUnit (g y)) {x y} (h : f.toMap x = f.toMap y) : g x = g y := by
obtain ⟨c, hc⟩ := f.eq_iff_exists.1 h
rw [← one_mul (g x), ← IsUnit.liftRight_inv_mul (g.restrict S) hg c]
show _ * g c * _ = _
rw [mul_assoc, ← g.map_mul, hc, mul_comm, mul_inv_left hg, g.map_mul]
#align submonoid.localization_map.eq_of_eq Submonoid.LocalizationMap.eq_of_eq
#align add_submonoid.localization_map.eq_of_eq AddSubmonoid.LocalizationMap.eq_of_eq
/-- Given `CommMonoid`s `M, P`, Localization maps `f : M →* N, k : P →* Q` for Submonoids
`S, T` respectively, and `g : M →* P` such that `g(S) ⊆ T`, `f x = f y` implies
`k (g x) = k (g y)`. -/
@[to_additive
"Given `AddCommMonoid`s `M, P`, Localization maps `f : M →+ N, k : P →+ Q` for Submonoids
`S, T` respectively, and `g : M →+ P` such that `g(S) ⊆ T`, `f x = f y`
implies `k (g x) = k (g y)`."]
theorem comp_eq_of_eq {T : Submonoid P} {Q : Type*} [CommMonoid Q] (hg : ∀ y : S, g y ∈ T)
(k : LocalizationMap T Q) {x y} (h : f.toMap x = f.toMap y) : k.toMap (g x) = k.toMap (g y) :=
f.eq_of_eq (fun y : S ↦ show IsUnit (k.toMap.comp g y) from k.map_units ⟨g y, hg y⟩) h
#align submonoid.localization_map.comp_eq_of_eq Submonoid.LocalizationMap.comp_eq_of_eq
#align add_submonoid.localization_map.comp_eq_of_eq AddSubmonoid.LocalizationMap.comp_eq_of_eq
variable (hg : ∀ y : S, IsUnit (g y))
/-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M` and a map of `CommMonoid`s
`g : M →* P` such that `g y` is invertible for all `y : S`, the homomorphism induced from
`N` to `P` sending `z : N` to `g x * (g y)⁻¹`, where `(x, y) : M × S` are such that
`z = f x * (f y)⁻¹`. -/
@[to_additive
"Given a localization map `f : M →+ N` for a submonoid `S ⊆ M` and a map of
`AddCommMonoid`s `g : M →+ P` such that `g y` is invertible for all `y : S`, the homomorphism
induced from `N` to `P` sending `z : N` to `g x - g y`, where `(x, y) : M × S` are such that
`z = f x - f y`."]
noncomputable def lift : N →* P where
toFun z := g (f.sec z).1 * (IsUnit.liftRight (g.restrict S) hg (f.sec z).2)⁻¹
map_one' := by rw [mul_inv_left, mul_one]; exact f.eq_of_eq hg (by rw [← sec_spec, one_mul])
map_mul' x y := by
dsimp only
rw [mul_inv_left hg, ← mul_assoc, ← mul_assoc, mul_inv_right hg, mul_comm _ (g (f.sec y).1), ←
mul_assoc, ← mul_assoc, mul_inv_right hg]
repeat rw [← g.map_mul]
exact f.eq_of_eq hg (by simp_rw [f.toMap.map_mul, sec_spec']; ac_rfl)
#align submonoid.localization_map.lift Submonoid.LocalizationMap.lift
#align add_submonoid.localization_map.lift AddSubmonoid.LocalizationMap.lift
/-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M` and a map of `CommMonoid`s
`g : M →* P` such that `g y` is invertible for all `y : S`, the homomorphism induced from
`N` to `P` maps `f x * (f y)⁻¹` to `g x * (g y)⁻¹` for all `x : M, y ∈ S`. -/
@[to_additive
"Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M` and a map of
`AddCommMonoid`s `g : M →+ P` such that `g y` is invertible for all `y : S`, the homomorphism
induced from `N` to `P` maps `f x - f y` to `g x - g y` for all `x : M, y ∈ S`."]
theorem lift_mk' (x y) : f.lift hg (f.mk' x y) = g x * (IsUnit.liftRight (g.restrict S) hg y)⁻¹ :=
(mul_inv hg).2 <|
f.eq_of_eq hg <| by
simp_rw [f.toMap.map_mul, sec_spec', mul_assoc, f.mk'_spec, mul_comm]
#align submonoid.localization_map.lift_mk' Submonoid.LocalizationMap.lift_mk'
#align add_submonoid.localization_map.lift_mk' AddSubmonoid.LocalizationMap.lift_mk'
/-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, if a `CommMonoid` map
`g : M →* P` induces a map `f.lift hg : N →* P` then for all `z : N, v : P`, we have
`f.lift hg z = v ↔ g x = g y * v`, where `x : M, y ∈ S` are such that `z * f y = f x`. -/
@[to_additive
"Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, if an
`AddCommMonoid` map `g : M →+ P` induces a map `f.lift hg : N →+ P` then for all
`z : N, v : P`, we have `f.lift hg z = v ↔ g x = g y + v`, where `x : M, y ∈ S` are such that
`z + f y = f x`."]
theorem lift_spec (z v) : f.lift hg z = v ↔ g (f.sec z).1 = g (f.sec z).2 * v :=
mul_inv_left hg _ _ v
#align submonoid.localization_map.lift_spec Submonoid.LocalizationMap.lift_spec
#align add_submonoid.localization_map.lift_spec AddSubmonoid.LocalizationMap.lift_spec
/-- Given a Localization map `f : M →* N` for a Submonoid `S ⊆ M`, if a `CommMonoid` map
`g : M →* P` induces a map `f.lift hg : N →* P` then for all `z : N, v w : P`, we have
`f.lift hg z * w = v ↔ g x * w = g y * v`, where `x : M, y ∈ S` are such that
`z * f y = f x`. -/
@[to_additive
"Given a Localization map `f : M →+ N` for a Submonoid `S ⊆ M`, if an `AddCommMonoid` map
`g : M →+ P` induces a map `f.lift hg : N →+ P` then for all
`z : N, v w : P`, we have `f.lift hg z + w = v ↔ g x + w = g y + v`, where `x : M, y ∈ S` are such
that `z + f y = f x`."]
| Mathlib/GroupTheory/MonoidLocalization.lean | 1,006 | 1,007 | theorem lift_spec_mul (z w v) : f.lift hg z * w = v ↔ g (f.sec z).1 * w = g (f.sec z).2 * v := by |
erw [mul_comm, ← mul_assoc, mul_inv_left hg, mul_comm]
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Int.Defs
import Mathlib.Data.Rat.Init
import Mathlib.Order.Basic
import Mathlib.Tactic.Common
#align_import data.rat.defs from "leanprover-community/mathlib"@"18a5306c091183ac90884daa9373fa3b178e8607"
/-!
# Basics for the Rational Numbers
## Summary
We define the integral domain structure on `ℚ` and prove basic lemmas about it.
The definition of the field structure on `ℚ` will be done in `Mathlib.Data.Rat.Basic` once the
`Field` class has been defined.
## Main Definitions
- `Rat.divInt n d` constructs a rational number `q = n / d` from `n d : ℤ`.
## Notations
- `/.` is infix notation for `Rat.divInt`.
-/
-- TODO: If `Inv` was defined earlier than `Algebra.Group.Defs`, we could have
-- assert_not_exists Monoid
assert_not_exists MonoidWithZero
assert_not_exists Lattice
assert_not_exists PNat
assert_not_exists Nat.dvd_mul
open Function
namespace Rat
variable {q : ℚ}
-- Porting note: the definition of `ℚ` has changed; in mathlib3 this was a field.
theorem pos (a : ℚ) : 0 < a.den := Nat.pos_of_ne_zero a.den_nz
#align rat.pos Rat.pos
#align rat.of_int Rat.ofInt
lemma mk'_num_den (q : ℚ) : mk' q.num q.den q.den_nz q.reduced = q := rfl
@[simp]
theorem ofInt_eq_cast (n : ℤ) : ofInt n = Int.cast n :=
rfl
#align rat.of_int_eq_cast Rat.ofInt_eq_cast
-- TODO: Replace `Rat.ofNat_num`/`Rat.ofNat_den` in Batteries
-- See note [no_index around OfNat.ofNat]
@[simp] lemma num_ofNat (n : ℕ) : num (no_index (OfNat.ofNat n)) = OfNat.ofNat n := rfl
@[simp] lemma den_ofNat (n : ℕ) : den (no_index (OfNat.ofNat n)) = 1 := rfl
@[simp, norm_cast] lemma num_natCast (n : ℕ) : num n = n := rfl
#align rat.coe_nat_num Rat.num_natCast
@[simp, norm_cast] lemma den_natCast (n : ℕ) : den n = 1 := rfl
#align rat.coe_nat_denom Rat.den_natCast
-- TODO: Replace `intCast_num`/`intCast_den` the names in Batteries
@[simp, norm_cast] lemma num_intCast (n : ℤ) : (n : ℚ).num = n := rfl
#align rat.coe_int_num Rat.num_intCast
@[simp, norm_cast] lemma den_intCast (n : ℤ) : (n : ℚ).den = 1 := rfl
#align rat.coe_int_denom Rat.den_intCast
@[deprecated (since := "2024-04-29")] alias coe_int_num := num_intCast
@[deprecated (since := "2024-04-29")] alias coe_int_den := den_intCast
lemma intCast_injective : Injective (Int.cast : ℤ → ℚ) := fun _ _ ↦ congr_arg num
lemma natCast_injective : Injective (Nat.cast : ℕ → ℚ) :=
intCast_injective.comp fun _ _ ↦ Int.natCast_inj.1
-- We want to use these lemmas earlier than the lemmas simp can prove them with
@[simp, nolint simpNF, norm_cast] lemma natCast_inj {m n : ℕ} : (m : ℚ) = n ↔ m = n :=
natCast_injective.eq_iff
@[simp, nolint simpNF, norm_cast] lemma intCast_eq_zero {n : ℤ} : (n : ℚ) = 0 ↔ n = 0 := intCast_inj
@[simp, nolint simpNF, norm_cast] lemma natCast_eq_zero {n : ℕ} : (n : ℚ) = 0 ↔ n = 0 := natCast_inj
@[simp, nolint simpNF, norm_cast] lemma intCast_eq_one {n : ℤ} : (n : ℚ) = 1 ↔ n = 1 := intCast_inj
@[simp, nolint simpNF, norm_cast] lemma natCast_eq_one {n : ℕ} : (n : ℚ) = 1 ↔ n = 1 := natCast_inj
#noalign rat.mk_pnat
#noalign rat.mk_pnat_eq
#noalign rat.zero_mk_pnat
-- Porting note (#11215): TODO Should this be namespaced?
#align rat.mk_nat mkRat
lemma mkRat_eq_divInt (n d) : mkRat n d = n /. d := rfl
#align rat.mk_nat_eq Rat.mkRat_eq_divInt
#align rat.mk_zero Rat.divInt_zero
#align rat.zero_mk_nat Rat.zero_mkRat
#align rat.zero_mk Rat.zero_divInt
@[simp] lemma mk'_zero (d) (h : d ≠ 0) (w) : mk' 0 d h w = 0 := by congr; simp_all
@[simp]
lemma num_eq_zero {q : ℚ} : q.num = 0 ↔ q = 0 := by
induction q
constructor
· rintro rfl
exact mk'_zero _ _ _
· exact congr_arg num
lemma num_ne_zero {q : ℚ} : q.num ≠ 0 ↔ q ≠ 0 := num_eq_zero.not
#align rat.num_ne_zero_of_ne_zero Rat.num_ne_zero
@[simp] lemma den_ne_zero (q : ℚ) : q.den ≠ 0 := q.den_pos.ne'
#noalign rat.nonneg
@[simp] lemma num_nonneg : 0 ≤ q.num ↔ 0 ≤ q := by
simp [Int.le_iff_lt_or_eq, instLE, Rat.blt, Int.not_lt]; tauto
#align rat.num_nonneg_iff_zero_le Rat.num_nonneg
@[simp]
theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 := by
rw [← zero_divInt b, divInt_eq_iff b0 b0, Int.zero_mul, Int.mul_eq_zero, or_iff_left b0]
#align rat.mk_eq_zero Rat.divInt_eq_zero
theorem divInt_ne_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b ≠ 0 ↔ a ≠ 0 :=
(divInt_eq_zero b0).not
#align rat.mk_ne_zero Rat.divInt_ne_zero
#align rat.mk_eq Rat.divInt_eq_iff
#align rat.div_mk_div_cancel_left Rat.divInt_mul_right
-- Porting note: this can move to Batteries
theorem normalize_eq_mk' (n : Int) (d : Nat) (h : d ≠ 0) (c : Nat.gcd (Int.natAbs n) d = 1) :
normalize n d h = mk' n d h c := (mk_eq_normalize ..).symm
-- TODO: Rename `mkRat_num_den` in Batteries
@[simp] alias mkRat_num_den' := mkRat_self
-- TODO: Rename `Rat.divInt_self` to `Rat.num_divInt_den` in Batteries
lemma num_divInt_den (q : ℚ) : q.num /. q.den = q := divInt_self _
#align rat.num_denom Rat.num_divInt_den
lemma mk'_eq_divInt {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d := (num_divInt_den _).symm
#align rat.num_denom' Rat.mk'_eq_divInt
theorem intCast_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 := mk'_eq_divInt
#align rat.coe_int_eq_mk Rat.intCast_eq_divInt
-- TODO: Rename `divInt_self` in Batteries to `num_divInt_den`
@[simp] lemma divInt_self' {n : ℤ} (hn : n ≠ 0) : n /. n = 1 := by
simpa using divInt_mul_right (n := 1) (d := 1) hn
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@[elab_as_elim]
def numDenCasesOn.{u} {C : ℚ → Sort u} :
∀ (a : ℚ) (_ : ∀ n d, 0 < d → (Int.natAbs n).Coprime d → C (n /. d)), C a
| ⟨n, d, h, c⟩, H => by rw [mk'_eq_divInt]; exact H n d (Nat.pos_of_ne_zero h) c
#align rat.num_denom_cases_on Rat.numDenCasesOn
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `d ≠ 0`. -/
@[elab_as_elim]
def numDenCasesOn'.{u} {C : ℚ → Sort u} (a : ℚ) (H : ∀ (n : ℤ) (d : ℕ), d ≠ 0 → C (n /. d)) :
C a :=
numDenCasesOn a fun n d h _ => H n d h.ne'
#align rat.num_denom_cases_on' Rat.numDenCasesOn'
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `mk' n d` with `d ≠ 0`. -/
@[elab_as_elim]
def numDenCasesOn''.{u} {C : ℚ → Sort u} (a : ℚ)
(H : ∀ (n : ℤ) (d : ℕ) (nz red), C (mk' n d nz red)) : C a :=
numDenCasesOn a fun n d h h' ↦ by rw [← mk_eq_divInt _ _ h.ne' h']; exact H n d h.ne' _
#align rat.add Rat.add
-- Porting note: there's already an instance for `Add ℚ` is in Batteries.
theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ → ℤ → ℤ) (f₂ : ℤ → ℤ → ℤ → ℤ → ℤ)
(fv :
∀ {n₁ d₁ h₁ c₁ n₂ d₂ h₂ c₂},
f ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ = f₁ n₁ d₁ n₂ d₂ /. f₂ n₁ d₁ n₂ d₂)
(f0 : ∀ {n₁ d₁ n₂ d₂}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0) (a b c d : ℤ)
(b0 : b ≠ 0) (d0 : d ≠ 0)
(H :
∀ {n₁ d₁ n₂ d₂}, a * d₁ = n₁ * b → c * d₂ = n₂ * d →
f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂) :
f (a /. b) (c /. d) = f₁ a b c d /. f₂ a b c d := by
generalize ha : a /. b = x; cases' x with n₁ d₁ h₁ c₁; rw [mk'_eq_divInt] at ha
generalize hc : c /. d = x; cases' x with n₂ d₂ h₂ c₂; rw [mk'_eq_divInt] at hc
rw [fv]
have d₁0 := Int.ofNat_ne_zero.2 h₁
have d₂0 := Int.ofNat_ne_zero.2 h₂
exact (divInt_eq_iff (f0 d₁0 d₂0) (f0 b0 d0)).2
(H ((divInt_eq_iff b0 d₁0).1 ha) ((divInt_eq_iff d0 d₂0).1 hc))
#align rat.lift_binop_eq Rat.lift_binop_eq
attribute [simp] divInt_add_divInt
@[deprecated divInt_add_divInt (since := "2024-03-18")]
theorem add_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b + c /. d = (a * d + c * b) /. (b * d) := divInt_add_divInt _ _ b0 d0
#align rat.add_def Rat.add_def''
#align rat.neg Rat.neg
attribute [simp] neg_divInt
#align rat.neg_def Rat.neg_divInt
lemma neg_def (q : ℚ) : -q = -q.num /. q.den := by rw [← neg_divInt, num_divInt_den]
@[simp] lemma divInt_neg (n d : ℤ) : n /. -d = -n /. d := divInt_neg' ..
#align rat.mk_neg_denom Rat.divInt_neg
@[deprecated (since := "2024-03-18")] alias divInt_neg_den := divInt_neg
attribute [simp] divInt_sub_divInt
@[deprecated divInt_sub_divInt (since := "2024-03-18")]
lemma sub_def'' {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b - c /. d = (a * d - c * b) /. (b * d) := divInt_sub_divInt _ _ b0 d0
#align rat.sub_def Rat.sub_def''
#align rat.mul Rat.mul
@[simp]
lemma divInt_mul_divInt' (n₁ d₁ n₂ d₂ : ℤ) : (n₁ /. d₁) * (n₂ /. d₂) = (n₁ * n₂) /. (d₁ * d₂) := by
obtain rfl | h₁ := eq_or_ne d₁ 0
· simp
obtain rfl | h₂ := eq_or_ne d₂ 0
· simp
exact divInt_mul_divInt _ _ h₁ h₂
#align rat.mul_def Rat.divInt_mul_divInt'
attribute [simp] mkRat_mul_mkRat
lemma mk'_mul_mk' (n₁ n₂ : ℤ) (d₁ d₂ : ℕ) (hd₁ hd₂ hnd₁ hnd₂) (h₁₂ : n₁.natAbs.Coprime d₂)
(h₂₁ : n₂.natAbs.Coprime d₁) :
mk' n₁ d₁ hd₁ hnd₁ * mk' n₂ d₂ hd₂ hnd₂ = mk' (n₁ * n₂) (d₁ * d₂) (Nat.mul_ne_zero hd₁ hd₂) (by
rw [Int.natAbs_mul]; exact (hnd₁.mul h₂₁).mul_right (h₁₂.mul hnd₂)) := by
rw [mul_def]; dsimp; simp [mk_eq_normalize]
lemma mul_eq_mkRat (q r : ℚ) : q * r = mkRat (q.num * r.num) (q.den * r.den) := by
rw [mul_def, normalize_eq_mkRat]
-- TODO: Rename `divInt_eq_iff` in Batteries to `divInt_eq_divInt`
alias divInt_eq_divInt := divInt_eq_iff
@[deprecated] alias mul_num_den := mul_eq_mkRat
#align rat.mul_num_denom Rat.mul_eq_mkRat
instance instPowNat : Pow ℚ ℕ where
pow q n := ⟨q.num ^ n, q.den ^ n, by simp [Nat.pow_eq_zero], by
rw [Int.natAbs_pow]; exact q.reduced.pow _ _⟩
lemma pow_def (q : ℚ) (n : ℕ) :
q ^ n = ⟨q.num ^ n, q.den ^ n,
by simp [Nat.pow_eq_zero],
by rw [Int.natAbs_pow]; exact q.reduced.pow _ _⟩ := rfl
lemma pow_eq_mkRat (q : ℚ) (n : ℕ) : q ^ n = mkRat (q.num ^ n) (q.den ^ n) := by
rw [pow_def, mk_eq_mkRat]
lemma pow_eq_divInt (q : ℚ) (n : ℕ) : q ^ n = q.num ^ n /. q.den ^ n := by
rw [pow_def, mk_eq_divInt, Int.natCast_pow]
@[simp] lemma num_pow (q : ℚ) (n : ℕ) : (q ^ n).num = q.num ^ n := rfl
@[simp] lemma den_pow (q : ℚ) (n : ℕ) : (q ^ n).den = q.den ^ n := rfl
@[simp] lemma mk'_pow (num : ℤ) (den : ℕ) (hd hdn) (n : ℕ) :
mk' num den hd hdn ^ n = mk' (num ^ n) (den ^ n)
(by simp [Nat.pow_eq_zero, hd]) (by rw [Int.natAbs_pow]; exact hdn.pow _ _) := rfl
#align rat.inv Rat.inv
instance : Inv ℚ :=
⟨Rat.inv⟩
@[simp] lemma inv_divInt' (a b : ℤ) : (a /. b)⁻¹ = b /. a := inv_divInt ..
#align rat.inv_def Rat.inv_divInt
@[simp] lemma inv_mkRat (a : ℤ) (b : ℕ) : (mkRat a b)⁻¹ = b /. a := by
rw [mkRat_eq_divInt, inv_divInt']
lemma inv_def' (q : ℚ) : q⁻¹ = q.den /. q.num := by rw [← inv_divInt', num_divInt_den]
#align rat.inv_def' Rat.inv_def'
@[simp] lemma divInt_div_divInt (n₁ d₁ n₂ d₂) :
(n₁ /. d₁) / (n₂ /. d₂) = (n₁ * d₂) /. (d₁ * n₂) := by
rw [div_def, inv_divInt, divInt_mul_divInt']
lemma div_def' (q r : ℚ) : q / r = (q.num * r.den) /. (q.den * r.num) := by
rw [← divInt_div_divInt, num_divInt_den, num_divInt_den]
@[deprecated (since := "2024-04-15")] alias div_num_den := div_def'
#align rat.div_num_denom Rat.div_def'
variable (a b c : ℚ)
protected lemma add_zero : a + 0 = a := by simp [add_def, normalize_eq_mkRat]
#align rat.add_zero Rat.add_zero
protected lemma zero_add : 0 + a = a := by simp [add_def, normalize_eq_mkRat]
#align rat.zero_add Rat.zero_add
protected lemma add_comm : a + b = b + a := by
simp [add_def, Int.add_comm, Int.mul_comm, Nat.mul_comm]
#align rat.add_comm Rat.add_comm
protected theorem add_assoc : a + b + c = a + (b + c) :=
numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ numDenCasesOn' c fun n₃ d₃ h₃ ↦ by
simp only [ne_eq, Int.natCast_eq_zero, h₁, not_false_eq_true, h₂, divInt_add_divInt,
Int.mul_eq_zero, or_self, h₃]
rw [Int.mul_assoc, Int.add_mul, Int.add_mul, Int.mul_assoc, Int.add_assoc]
congr 2
ac_rfl
#align rat.add_assoc Rat.add_assoc
protected lemma add_left_neg : -a + a = 0 := by
simp [add_def, normalize_eq_mkRat, Int.neg_mul, Int.add_comm, ← Int.sub_eq_add_neg]
#align rat.add_left_neg Rat.add_left_neg
@[deprecated zero_divInt (since := "2024-03-18")]
lemma divInt_zero_one : 0 /. 1 = 0 := zero_divInt _
#align rat.mk_zero_one Rat.zero_divInt
@[simp] lemma divInt_one (n : ℤ) : n /. 1 = n := by simp [divInt, mkRat, normalize]
@[simp] lemma mkRat_one (n : ℤ) : mkRat n 1 = n := by simp [mkRat_eq_divInt]
lemma divInt_one_one : 1 /. 1 = 1 := by rw [divInt_one]; rfl
#align rat.mk_one_one Rat.divInt_one_one
@[deprecated divInt_one (since := "2024-03-18")]
lemma divInt_neg_one_one : -1 /. 1 = -1 := by rw [divInt_one]; rfl
#align rat.mk_neg_one_one Rat.divInt_neg_one_one
#align rat.mul_one Rat.mul_one
#align rat.one_mul Rat.one_mul
#align rat.mul_comm Rat.mul_comm
protected theorem mul_assoc : a * b * c = a * (b * c) :=
numDenCasesOn' a fun n₁ d₁ h₁ =>
numDenCasesOn' b fun n₂ d₂ h₂ =>
numDenCasesOn' c fun n₃ d₃ h₃ => by
simp [h₁, h₂, h₃, Int.mul_comm, Nat.mul_assoc, Int.mul_left_comm]
#align rat.mul_assoc Rat.mul_assoc
protected theorem add_mul : (a + b) * c = a * c + b * c :=
numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ numDenCasesOn' c fun n₃ d₃ h₃ ↦ by
simp only [ne_eq, Int.natCast_eq_zero, h₁, not_false_eq_true, h₂, divInt_add_divInt,
Int.mul_eq_zero, or_self, h₃, divInt_mul_divInt]
rw [← divInt_mul_right (Int.natCast_ne_zero.2 h₃), Int.add_mul, Int.add_mul]
ac_rfl
#align rat.add_mul Rat.add_mul
protected theorem mul_add : a * (b + c) = a * b + a * c := by
rw [Rat.mul_comm, Rat.add_mul, Rat.mul_comm, Rat.mul_comm c a]
#align rat.mul_add Rat.mul_add
protected theorem zero_ne_one : 0 ≠ (1 : ℚ) := by
rw [ne_comm, ← divInt_one_one, divInt_ne_zero] <;> omega
#align rat.zero_ne_one Rat.zero_ne_one
attribute [simp] mkRat_eq_zero
protected theorem mul_inv_cancel : a ≠ 0 → a * a⁻¹ = 1 :=
numDenCasesOn' a fun n d hd hn ↦ by
simp [hd] at hn;
simp [-divInt_ofNat, mkRat_eq_divInt, Int.mul_comm, Int.mul_ne_zero hn (Int.ofNat_ne_zero.2 hd)]
#align rat.mul_inv_cancel Rat.mul_inv_cancel
protected theorem inv_mul_cancel (h : a ≠ 0) : a⁻¹ * a = 1 :=
Eq.trans (Rat.mul_comm _ _) (Rat.mul_inv_cancel _ h)
#align rat.inv_mul_cancel Rat.inv_mul_cancel
-- Porting note: we already have a `DecidableEq ℚ`.
-- Extra instances to short-circuit type class resolution
-- TODO(Mario): this instance slows down Mathlib.Data.Real.Basic
instance nontrivial : Nontrivial ℚ where exists_pair_ne := ⟨1, 0, by decide⟩
/-! ### The rational numbers are a group -/
instance addCommGroup : AddCommGroup ℚ where
zero := 0
add := (· + ·)
neg := Neg.neg
zero_add := Rat.zero_add
add_zero := Rat.add_zero
add_comm := Rat.add_comm
add_assoc := Rat.add_assoc
add_left_neg := Rat.add_left_neg
sub_eq_add_neg := Rat.sub_eq_add_neg
nsmul := nsmulRec
zsmul := zsmulRec
instance addGroup : AddGroup ℚ := by infer_instance
instance addCommMonoid : AddCommMonoid ℚ := by infer_instance
instance addMonoid : AddMonoid ℚ := by infer_instance
instance addLeftCancelSemigroup : AddLeftCancelSemigroup ℚ := by infer_instance
instance addRightCancelSemigroup : AddRightCancelSemigroup ℚ := by infer_instance
instance addCommSemigroup : AddCommSemigroup ℚ := by infer_instance
instance addSemigroup : AddSemigroup ℚ := by infer_instance
instance commMonoid : CommMonoid ℚ where
one := 1
mul := (· * ·)
mul_one := Rat.mul_one
one_mul := Rat.one_mul
mul_comm := Rat.mul_comm
mul_assoc := Rat.mul_assoc
npow n q := q ^ n
npow_zero := by intros; apply Rat.ext <;> simp [Int.pow_zero]
npow_succ n q := by
dsimp
rw [← q.mk'_num_den, mk'_pow, mk'_mul_mk']
· congr
· rw [mk'_pow, Int.natAbs_pow]
exact q.reduced.pow_left _
· rw [mk'_pow]
exact q.reduced.pow_right _
instance monoid : Monoid ℚ := by infer_instance
instance commSemigroup : CommSemigroup ℚ := by infer_instance
instance semigroup : Semigroup ℚ := by infer_instance
#align rat.denom_ne_zero Rat.den_nz
theorem eq_iff_mul_eq_mul {p q : ℚ} : p = q ↔ p.num * q.den = q.num * p.den := by
conv =>
lhs
rw [← num_divInt_den p, ← num_divInt_den q]
apply Rat.divInt_eq_iff <;>
· rw [← Int.natCast_zero, Ne, Int.ofNat_inj]
apply den_nz
#align rat.eq_iff_mul_eq_mul Rat.eq_iff_mul_eq_mul
@[simp]
theorem den_neg_eq_den (q : ℚ) : (-q).den = q.den :=
rfl
#align rat.denom_neg_eq_denom Rat.den_neg_eq_den
@[simp]
theorem num_neg_eq_neg_num (q : ℚ) : (-q).num = -q.num :=
rfl
#align rat.num_neg_eq_neg_num Rat.num_neg_eq_neg_num
@[simp]
theorem num_zero : Rat.num 0 = 0 :=
rfl
#align rat.num_zero Rat.num_zero
@[simp]
theorem den_zero : Rat.den 0 = 1 :=
rfl
#align rat.denom_zero Rat.den_zero
lemma zero_of_num_zero {q : ℚ} (hq : q.num = 0) : q = 0 := by simpa [hq] using q.num_divInt_den.symm
#align rat.zero_of_num_zero Rat.zero_of_num_zero
theorem zero_iff_num_zero {q : ℚ} : q = 0 ↔ q.num = 0 :=
⟨fun _ => by simp [*], zero_of_num_zero⟩
#align rat.zero_iff_num_zero Rat.zero_iff_num_zero
@[simp]
theorem num_one : (1 : ℚ).num = 1 :=
rfl
#align rat.num_one Rat.num_one
@[simp]
theorem den_one : (1 : ℚ).den = 1 :=
rfl
#align rat.denom_one Rat.den_one
theorem mk_num_ne_zero_of_ne_zero {q : ℚ} {n d : ℤ} (hq : q ≠ 0) (hqnd : q = n /. d) : n ≠ 0 :=
fun this => hq <| by simpa [this] using hqnd
#align rat.mk_num_ne_zero_of_ne_zero Rat.mk_num_ne_zero_of_ne_zero
theorem mk_denom_ne_zero_of_ne_zero {q : ℚ} {n d : ℤ} (hq : q ≠ 0) (hqnd : q = n /. d) : d ≠ 0 :=
fun this => hq <| by simpa [this] using hqnd
#align rat.mk_denom_ne_zero_of_ne_zero Rat.mk_denom_ne_zero_of_ne_zero
theorem divInt_ne_zero_of_ne_zero {n d : ℤ} (h : n ≠ 0) (hd : d ≠ 0) : n /. d ≠ 0 :=
(divInt_ne_zero hd).mpr h
#align rat.mk_ne_zero_of_ne_zero Rat.divInt_ne_zero_of_ne_zero
protected lemma nonneg_antisymm : 0 ≤ q → 0 ≤ -q → q = 0 := by
simp_rw [← num_eq_zero, Int.le_antisymm_iff, ← num_nonneg, num_neg_eq_neg_num, Int.neg_nonneg]
tauto
#align rat.nonneg_antisymm Rat.nonneg_antisymm
protected lemma nonneg_total (a : ℚ) : 0 ≤ a ∨ 0 ≤ -a := by
simp_rw [← num_nonneg, num_neg_eq_neg_num, Int.neg_nonneg]; exact Int.le_total _ _
#align rat.nonneg_total Rat.nonneg_total
#align rat.decidable_nonneg Rat.instDecidableLe
section Casts
protected theorem add_divInt (a b c : ℤ) : (a + b) /. c = a /. c + b /. c :=
if h : c = 0 then by simp [h]
else by
rw [divInt_add_divInt _ _ h h, divInt_eq_iff h (Int.mul_ne_zero h h)]
simp [Int.add_mul, Int.mul_assoc]
#align rat.add_mk Rat.add_divInt
theorem divInt_eq_div (n d : ℤ) : n /. d = (n : ℚ) / d := by simp [div_def']
#align rat.mk_eq_div Rat.divInt_eq_div
lemma intCast_div_eq_divInt (n d : ℤ) : (n : ℚ) / (d) = n /. d := by rw [divInt_eq_div]
#align rat.coe_int_div_eq_mk Rat.intCast_div_eq_divInt
theorem natCast_div_eq_divInt (n d : ℕ) : (n : ℚ) / d = n /. d := Rat.intCast_div_eq_divInt n d
theorem divInt_mul_divInt_cancel {x : ℤ} (hx : x ≠ 0) (n d : ℤ) : n /. x * (x /. d) = n /. d := by
by_cases hd : d = 0
· rw [hd]
simp
rw [divInt_mul_divInt _ _ hx hd, x.mul_comm, divInt_mul_right hx]
#align rat.mk_mul_mk_cancel Rat.divInt_mul_divInt_cancel
| Mathlib/Data/Rat/Defs.lean | 537 | 540 | theorem coe_int_num_of_den_eq_one {q : ℚ} (hq : q.den = 1) : (q.num : ℚ) = q := by |
conv_rhs => rw [← num_divInt_den q, hq]
rw [intCast_eq_divInt]
rfl
|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.RingTheory.Multiplicity
import Mathlib.RingTheory.PowerSeries.Basic
#align_import ring_theory.power_series.basic from "leanprover-community/mathlib"@"2d5739b61641ee4e7e53eca5688a08f66f2e6a60"
/-! # Formal power series (in one variable) - Order
The `PowerSeries.order` of a formal power series `φ` is the multiplicity of the variable `X` in `φ`.
If the coefficients form an integral domain, then `PowerSeries.order` is an
additive valuation (`PowerSeries.order_mul`, `PowerSeries.le_order_add`).
We prove that if the commutative ring `R` of coefficients is an integral domain,
then the ring `R⟦X⟧` of formal power series in one variable over `R`
is an integral domain.
Given a non-zero power series `f`, `divided_by_X_pow_order f` is the power series obtained by
dividing out the largest power of X that divides `f`, that is its order. This is useful when
proving that `R⟦X⟧` is a normalization monoid, which is done in `PowerSeries.Inverse`.
-/
noncomputable section
open Polynomial
open Finset (antidiagonal mem_antidiagonal)
namespace PowerSeries
open Finsupp (single)
variable {R : Type*}
section OrderBasic
open multiplicity
variable [Semiring R] {φ : R⟦X⟧}
theorem exists_coeff_ne_zero_iff_ne_zero : (∃ n : ℕ, coeff R n φ ≠ 0) ↔ φ ≠ 0 := by
refine not_iff_not.mp ?_
push_neg
-- FIXME: the `FunLike.coe` doesn't seem to be picked up in the expression after #8386?
simp [PowerSeries.ext_iff, (coeff R _).map_zero]
#align power_series.exists_coeff_ne_zero_iff_ne_zero PowerSeries.exists_coeff_ne_zero_iff_ne_zero
/-- The order of a formal power series `φ` is the greatest `n : PartENat`
such that `X^n` divides `φ`. The order is `⊤` if and only if `φ = 0`. -/
def order (φ : R⟦X⟧) : PartENat :=
letI := Classical.decEq R
letI := Classical.decEq R⟦X⟧
if h : φ = 0 then ⊤ else Nat.find (exists_coeff_ne_zero_iff_ne_zero.mpr h)
#align power_series.order PowerSeries.order
/-- The order of the `0` power series is infinite. -/
@[simp]
theorem order_zero : order (0 : R⟦X⟧) = ⊤ :=
dif_pos rfl
#align power_series.order_zero PowerSeries.order_zero
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
simp only [order]
constructor
· split_ifs with h <;> intro H
· simp only [PartENat.top_eq_none, Part.not_none_dom] at H
· exact h
· intro h
simp [h]
#align power_series.order_finite_iff_ne_zero PowerSeries.order_finite_iff_ne_zero
/-- If the order of a formal power series is finite,
then the coefficient indexed by the order is nonzero. -/
theorem coeff_order (h : (order φ).Dom) : coeff R (φ.order.get h) φ ≠ 0 := by
classical
simp only [order, order_finite_iff_ne_zero.mp h, not_false_iff, dif_neg, PartENat.get_natCast']
generalize_proofs h
exact Nat.find_spec h
#align power_series.coeff_order PowerSeries.coeff_order
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`. -/
theorem order_le (n : ℕ) (h : coeff R n φ ≠ 0) : order φ ≤ n := by
classical
rw [order, dif_neg]
· simp only [PartENat.coe_le_coe]
exact Nat.find_le h
· exact exists_coeff_ne_zero_iff_ne_zero.mp ⟨n, h⟩
#align power_series.order_le PowerSeries.order_le
/-- The `n`th coefficient of a formal power series is `0` if `n` is strictly
smaller than the order of the power series. -/
| Mathlib/RingTheory/PowerSeries/Order.lean | 99 | 101 | theorem coeff_of_lt_order (n : ℕ) (h : ↑n < order φ) : coeff R n φ = 0 := by |
contrapose! h
exact order_le _ h
|
/-
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.Constructions.Prod.Basic
import Mathlib.MeasureTheory.Group.Measure
#align_import measure_theory.group.prod from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844"
/-!
# 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 `MeasureTheory.Measure.Haar.Unique.lean`.
-/
noncomputable section
open Set hiding prod_eq
open Function MeasureTheory
open Filter hiding map
open scoped Classical ENNReal Pointwise MeasureTheory
variable (G : Type*) [MeasurableSpace G]
variable [Group G] [MeasurableMul₂ G]
variable (μ ν : Measure G) [SigmaFinite ν] [SigmaFinite μ] {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.prod_mk measurable_mul
measurable_invFun := measurable_fst.prod_mk <| measurable_fst.inv.mul measurable_snd }
#align measurable_equiv.shear_mul_right MeasurableEquiv.shearMulRight
#align measurable_equiv.shear_add_right MeasurableEquiv.shearAddRight
/-- 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.prod_mk <| measurable_snd.div measurable_fst
measurable_invFun := measurable_fst.prod_mk <| measurable_snd.mul measurable_fst }
#align measurable_equiv.shear_div_right MeasurableEquiv.shearDivRight
#align measurable_equiv.shear_sub_right MeasurableEquiv.shearSubRight
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 ν
#align measure_theory.measure_preserving_prod_mul MeasureTheory.measurePreserving_prod_mul
#align measure_theory.measure_preserving_prod_add MeasureTheory.measurePreserving_prod_add
/-- 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
#align measure_theory.measure_preserving_prod_mul_swap MeasureTheory.measurePreserving_prod_mul_swap
#align measure_theory.measure_preserving_prod_add_swap MeasureTheory.measurePreserving_prod_add_swap
@[to_additive]
| Mathlib/MeasureTheory/Group/Prod.lean | 108 | 116 | 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_prod_mk_right
apply measurable_const.prod_mk measurable_mul (MeasurableSet.univ.prod hs)
infer_instance
|
/-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhangir Azerbayev, Adam Topaz, Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Basic
import Mathlib.LinearAlgebra.Alternating.Basic
#align_import linear_algebra.exterior_algebra.basic from "leanprover-community/mathlib"@"b8d2eaa69d69ce8f03179a5cda774fc0cde984e4"
/-!
# Exterior Algebras
We construct the exterior algebra of a module `M` over a commutative semiring `R`.
## Notation
The exterior algebra of the `R`-module `M` is denoted as `ExteriorAlgebra R M`.
It is endowed with the structure of an `R`-algebra.
The `n`th exterior power of the `R`-module `M` is denoted by `exteriorPower R n M`;
it is of type `Submodule R (ExteriorAlgebra R M)` and defined as
`LinearMap.range (ExteriorAlgebra.ι R : M →ₗ[R] ExteriorAlgebra R M) ^ n`.
We also introduce the notation `⋀[R]^n M` for `exteriorPower R n M`.
Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that
`cond : ∀ m : M, f m * f m = 0`, there is a (unique) lift of `f` to an `R`-algebra morphism,
which is denoted `ExteriorAlgebra.lift R f cond`.
The canonical linear map `M → ExteriorAlgebra R M` is denoted `ExteriorAlgebra.ι R`.
## Theorems
The main theorems proved ensure that `ExteriorAlgebra R M` satisfies the universal property
of the exterior algebra.
1. `ι_comp_lift` is the fact that the composition of `ι R` with `lift R f cond` agrees with `f`.
2. `lift_unique` ensures the uniqueness of `lift R f cond` with respect to 1.
## Definitions
* `ιMulti` is the `AlternatingMap` corresponding to the wedge product of `ι R m` terms.
## Implementation details
The exterior algebra of `M` is constructed as simply `CliffordAlgebra (0 : QuadraticForm R M)`,
as this avoids us having to duplicate API.
-/
universe u1 u2 u3 u4 u5
variable (R : Type u1) [CommRing R]
variable (M : Type u2) [AddCommGroup M] [Module R M]
/-- The exterior algebra of an `R`-module `M`.
-/
abbrev ExteriorAlgebra :=
CliffordAlgebra (0 : QuadraticForm R M)
#align exterior_algebra ExteriorAlgebra
namespace ExteriorAlgebra
variable {M}
/-- The canonical linear map `M →ₗ[R] ExteriorAlgebra R M`.
-/
abbrev ι : M →ₗ[R] ExteriorAlgebra R M :=
CliffordAlgebra.ι _
#align exterior_algebra.ι ExteriorAlgebra.ι
section exteriorPower
-- New variables `n` and `M`, to get the correct order of variables in the notation.
variable (n : ℕ) (M : Type u2) [AddCommGroup M] [Module R M]
/-- Definition of the `n`th exterior power of a `R`-module `N`. We introduce the notation
`⋀[R]^n M` for `exteriorPower R n M`. -/
abbrev exteriorPower : Submodule R (ExteriorAlgebra R M) :=
LinearMap.range (ι R : M →ₗ[R] ExteriorAlgebra R M) ^ n
@[inherit_doc exteriorPower]
notation:max "⋀[" R "]^" n:arg => exteriorPower R n
end exteriorPower
variable {R}
/-- As well as being linear, `ι m` squares to zero. -/
-- @[simp] -- Porting note (#10618): simp can prove this
theorem ι_sq_zero (m : M) : ι R m * ι R m = 0 :=
(CliffordAlgebra.ι_sq_scalar _ m).trans <| map_zero _
#align exterior_algebra.ι_sq_zero ExteriorAlgebra.ι_sq_zero
variable {A : Type*} [Semiring A] [Algebra R A]
-- @[simp] -- Porting note (#10618): simp can prove this
theorem comp_ι_sq_zero (g : ExteriorAlgebra R M →ₐ[R] A) (m : M) : g (ι R m) * g (ι R m) = 0 := by
rw [← AlgHom.map_mul, ι_sq_zero, AlgHom.map_zero]
#align exterior_algebra.comp_ι_sq_zero ExteriorAlgebra.comp_ι_sq_zero
variable (R)
/-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition:
`cond : ∀ m : M, f m * f m = 0`, this is the canonical lift of `f` to a morphism of `R`-algebras
from `ExteriorAlgebra R M` to `A`.
-/
@[simps! symm_apply]
def lift : { f : M →ₗ[R] A // ∀ m, f m * f m = 0 } ≃ (ExteriorAlgebra R M →ₐ[R] A) :=
Equiv.trans (Equiv.subtypeEquiv (Equiv.refl _) <| by simp) <| CliffordAlgebra.lift _
#align exterior_algebra.lift ExteriorAlgebra.lift
@[simp]
theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) :
(lift R ⟨f, cond⟩).toLinearMap.comp (ι R) = f :=
CliffordAlgebra.ι_comp_lift f _
#align exterior_algebra.ι_comp_lift ExteriorAlgebra.ι_comp_lift
@[simp]
theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (x) :
lift R ⟨f, cond⟩ (ι R x) = f x :=
CliffordAlgebra.lift_ι_apply f _ x
#align exterior_algebra.lift_ι_apply ExteriorAlgebra.lift_ι_apply
@[simp]
theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (g : ExteriorAlgebra R M →ₐ[R] A) :
g.toLinearMap.comp (ι R) = f ↔ g = lift R ⟨f, cond⟩ :=
CliffordAlgebra.lift_unique f _ _
#align exterior_algebra.lift_unique ExteriorAlgebra.lift_unique
variable {R}
@[simp]
theorem lift_comp_ι (g : ExteriorAlgebra R M →ₐ[R] A) :
lift R ⟨g.toLinearMap.comp (ι R), comp_ι_sq_zero _⟩ = g :=
CliffordAlgebra.lift_comp_ι g
#align exterior_algebra.lift_comp_ι ExteriorAlgebra.lift_comp_ι
/-- See note [partially-applied ext lemmas]. -/
@[ext]
theorem hom_ext {f g : ExteriorAlgebra R M →ₐ[R] A}
(h : f.toLinearMap.comp (ι R) = g.toLinearMap.comp (ι R)) : f = g :=
CliffordAlgebra.hom_ext h
#align exterior_algebra.hom_ext ExteriorAlgebra.hom_ext
/-- If `C` holds for the `algebraMap` of `r : R` into `ExteriorAlgebra R M`, the `ι` of `x : M`,
and is preserved under addition and muliplication, then it holds for all of `ExteriorAlgebra R M`.
-/
@[elab_as_elim]
theorem induction {C : ExteriorAlgebra R M → Prop}
(algebraMap : ∀ r, C (algebraMap R (ExteriorAlgebra R M) r)) (ι : ∀ x, C (ι R x))
(mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b))
(a : ExteriorAlgebra R M) : C a :=
CliffordAlgebra.induction algebraMap ι mul add a
#align exterior_algebra.induction ExteriorAlgebra.induction
/-- The left-inverse of `algebraMap`. -/
def algebraMapInv : ExteriorAlgebra R M →ₐ[R] R :=
ExteriorAlgebra.lift R ⟨(0 : M →ₗ[R] R), fun _ => by simp⟩
#align exterior_algebra.algebra_map_inv ExteriorAlgebra.algebraMapInv
variable (M)
theorem algebraMap_leftInverse :
Function.LeftInverse algebraMapInv (algebraMap R <| ExteriorAlgebra R M) := fun x => by
simp [algebraMapInv]
#align exterior_algebra.algebra_map_left_inverse ExteriorAlgebra.algebraMap_leftInverse
@[simp]
theorem algebraMap_inj (x y : R) :
algebraMap R (ExteriorAlgebra R M) x = algebraMap R (ExteriorAlgebra R M) y ↔ x = y :=
(algebraMap_leftInverse M).injective.eq_iff
#align exterior_algebra.algebra_map_inj ExteriorAlgebra.algebraMap_inj
@[simp]
theorem algebraMap_eq_zero_iff (x : R) : algebraMap R (ExteriorAlgebra R M) x = 0 ↔ x = 0 :=
map_eq_zero_iff (algebraMap _ _) (algebraMap_leftInverse _).injective
#align exterior_algebra.algebra_map_eq_zero_iff ExteriorAlgebra.algebraMap_eq_zero_iff
@[simp]
theorem algebraMap_eq_one_iff (x : R) : algebraMap R (ExteriorAlgebra R M) x = 1 ↔ x = 1 :=
map_eq_one_iff (algebraMap _ _) (algebraMap_leftInverse _).injective
#align exterior_algebra.algebra_map_eq_one_iff ExteriorAlgebra.algebraMap_eq_one_iff
theorem isUnit_algebraMap (r : R) : IsUnit (algebraMap R (ExteriorAlgebra R M) r) ↔ IsUnit r :=
isUnit_map_of_leftInverse _ (algebraMap_leftInverse M)
#align exterior_algebra.is_unit_algebra_map ExteriorAlgebra.isUnit_algebraMap
/-- Invertibility in the exterior algebra is the same as invertibility of the base ring. -/
@[simps!]
def invertibleAlgebraMapEquiv (r : R) :
Invertible (algebraMap R (ExteriorAlgebra R M) r) ≃ Invertible r :=
invertibleEquivOfLeftInverse _ _ _ (algebraMap_leftInverse M)
#align exterior_algebra.invertible_algebra_map_equiv ExteriorAlgebra.invertibleAlgebraMapEquiv
variable {M}
/-- The canonical map from `ExteriorAlgebra R M` into `TrivSqZeroExt R M` that sends
`ExteriorAlgebra.ι` to `TrivSqZeroExt.inr`. -/
def toTrivSqZeroExt [Module Rᵐᵒᵖ M] [IsCentralScalar R M] :
ExteriorAlgebra R M →ₐ[R] TrivSqZeroExt R M :=
lift R ⟨TrivSqZeroExt.inrHom R M, fun m => TrivSqZeroExt.inr_mul_inr R m m⟩
#align exterior_algebra.to_triv_sq_zero_ext ExteriorAlgebra.toTrivSqZeroExt
@[simp]
theorem toTrivSqZeroExt_ι [Module Rᵐᵒᵖ M] [IsCentralScalar R M] (x : M) :
toTrivSqZeroExt (ι R x) = TrivSqZeroExt.inr x :=
lift_ι_apply _ _ _ _
#align exterior_algebra.to_triv_sq_zero_ext_ι ExteriorAlgebra.toTrivSqZeroExt_ι
/-- The left-inverse of `ι`.
As an implementation detail, we implement this using `TrivSqZeroExt` which has a suitable
algebra structure. -/
def ιInv : ExteriorAlgebra R M →ₗ[R] M := by
letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩
exact (TrivSqZeroExt.sndHom R M).comp toTrivSqZeroExt.toLinearMap
#align exterior_algebra.ι_inv ExteriorAlgebra.ιInv
theorem ι_leftInverse : Function.LeftInverse ιInv (ι R : M → ExteriorAlgebra R M) := fun x => by
-- Porting note: Original proof didn't have `letI` and `haveI`
letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩
simp [ιInv]
#align exterior_algebra.ι_left_inverse ExteriorAlgebra.ι_leftInverse
variable (R)
@[simp]
theorem ι_inj (x y : M) : ι R x = ι R y ↔ x = y :=
ι_leftInverse.injective.eq_iff
#align exterior_algebra.ι_inj ExteriorAlgebra.ι_inj
variable {R}
@[simp]
theorem ι_eq_zero_iff (x : M) : ι R x = 0 ↔ x = 0 := by rw [← ι_inj R x 0, LinearMap.map_zero]
#align exterior_algebra.ι_eq_zero_iff ExteriorAlgebra.ι_eq_zero_iff
@[simp]
theorem ι_eq_algebraMap_iff (x : M) (r : R) : ι R x = algebraMap R _ r ↔ x = 0 ∧ r = 0 := by
refine ⟨fun h => ?_, ?_⟩
· letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩
have hf0 : toTrivSqZeroExt (ι R x) = (0, x) := toTrivSqZeroExt_ι _
rw [h, AlgHom.commutes] at hf0
have : r = 0 ∧ 0 = x := Prod.ext_iff.1 hf0
exact this.symm.imp_left Eq.symm
· rintro ⟨rfl, rfl⟩
rw [LinearMap.map_zero, RingHom.map_zero]
#align exterior_algebra.ι_eq_algebra_map_iff ExteriorAlgebra.ι_eq_algebraMap_iff
@[simp]
theorem ι_ne_one [Nontrivial R] (x : M) : ι R x ≠ 1 := by
rw [← (algebraMap R (ExteriorAlgebra R M)).map_one, Ne, ι_eq_algebraMap_iff]
exact one_ne_zero ∘ And.right
#align exterior_algebra.ι_ne_one ExteriorAlgebra.ι_ne_one
/-- The generators of the exterior algebra are disjoint from its scalars. -/
theorem ι_range_disjoint_one :
Disjoint (LinearMap.range (ι R : M →ₗ[R] ExteriorAlgebra R M))
(1 : Submodule R (ExteriorAlgebra R M)) := by
rw [Submodule.disjoint_def]
rintro _ ⟨x, hx⟩ ⟨r, rfl : algebraMap R (ExteriorAlgebra R M) r = _⟩
rw [ι_eq_algebraMap_iff x] at hx
rw [hx.2, RingHom.map_zero]
#align exterior_algebra.ι_range_disjoint_one ExteriorAlgebra.ι_range_disjoint_one
@[simp]
theorem ι_add_mul_swap (x y : M) : ι R x * ι R y + ι R y * ι R x = 0 :=
CliffordAlgebra.ι_mul_ι_add_swap_of_isOrtho <| .all _ _
#align exterior_algebra.ι_add_mul_swap ExteriorAlgebra.ι_add_mul_swap
| Mathlib/LinearAlgebra/ExteriorAlgebra/Basic.lean | 274 | 286 | theorem ι_mul_prod_list {n : ℕ} (f : Fin n → M) (i : Fin n) :
(ι R <| f i) * (List.ofFn fun i => ι R <| f i).prod = 0 := by |
induction' n with n hn
· exact i.elim0
· rw [List.ofFn_succ, List.prod_cons, ← mul_assoc]
by_cases h : i = 0
· rw [h, ι_sq_zero, zero_mul]
· replace hn :=
congr_arg (ι R (f 0) * ·) <| hn (fun i => f <| Fin.succ i) (i.pred h)
simp only at hn
rw [Fin.succ_pred, ← mul_assoc, mul_zero] at hn
refine (eq_zero_iff_eq_zero_of_add_eq_zero ?_).mp hn
rw [← add_mul, ι_add_mul_swap, zero_mul]
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau
-/
import Mathlib.Data.Finsupp.ToDFinsupp
import Mathlib.LinearAlgebra.Finsupp
import Mathlib.LinearAlgebra.LinearIndependent
#align_import linear_algebra.dfinsupp from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64"
/-!
# Properties of the module `Π₀ i, M i`
Given an indexed collection of `R`-modules `M i`, the `R`-module structure on `Π₀ i, M i`
is defined in `Data.DFinsupp`.
In this file we define `LinearMap` versions of various maps:
* `DFinsupp.lsingle a : M →ₗ[R] Π₀ i, M i`: `DFinsupp.single a` as a linear map;
* `DFinsupp.lmk s : (Π i : (↑s : Set ι), M i) →ₗ[R] Π₀ i, M i`: `DFinsupp.single a` as a linear map;
* `DFinsupp.lapply i : (Π₀ i, M i) →ₗ[R] M`: the map `fun f ↦ f i` as a linear map;
* `DFinsupp.lsum`: `DFinsupp.sum` or `DFinsupp.liftAddHom` as a `LinearMap`;
## Implementation notes
This file should try to mirror `LinearAlgebra.Finsupp` where possible. The API of `Finsupp` is
much more developed, but many lemmas in that file should be eligible to copy over.
## Tags
function with finite support, module, linear algebra
-/
variable {ι : Type*} {R : Type*} {S : Type*} {M : ι → Type*} {N : Type*}
namespace DFinsupp
variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
variable [AddCommMonoid N] [Module R N]
section DecidableEq
variable [DecidableEq ι]
/-- `DFinsupp.mk` as a `LinearMap`. -/
def lmk (s : Finset ι) : (∀ i : (↑s : Set ι), M i) →ₗ[R] Π₀ i, M i where
toFun := mk s
map_add' _ _ := mk_add
map_smul' c x := mk_smul c x
#align dfinsupp.lmk DFinsupp.lmk
/-- `DFinsupp.single` as a `LinearMap` -/
def lsingle (i) : M i →ₗ[R] Π₀ i, M i :=
{ DFinsupp.singleAddHom _ _ with
toFun := single i
map_smul' := single_smul }
#align dfinsupp.lsingle DFinsupp.lsingle
/-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere. -/
theorem lhom_ext ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄ (h : ∀ i x, φ (single i x) = ψ (single i x)) : φ = ψ :=
LinearMap.toAddMonoidHom_injective <| addHom_ext h
#align dfinsupp.lhom_ext DFinsupp.lhom_ext
/-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere.
See note [partially-applied ext lemmas].
After apply this lemma, if `M = R` then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/
@[ext 1100]
theorem lhom_ext' ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄ (h : ∀ i, φ.comp (lsingle i) = ψ.comp (lsingle i)) :
φ = ψ :=
lhom_ext fun i => LinearMap.congr_fun (h i)
#align dfinsupp.lhom_ext' DFinsupp.lhom_ext'
/-- Interpret `fun (f : Π₀ i, M i) ↦ f i` as a linear map. -/
def lapply (i : ι) : (Π₀ i, M i) →ₗ[R] M i where
toFun f := f i
map_add' f g := add_apply f g i
map_smul' c f := smul_apply c f i
#align dfinsupp.lapply DFinsupp.lapply
-- This lemma has always been bad, but the linter only noticed after lean4#2644.
@[simp, nolint simpNF]
theorem lmk_apply (s : Finset ι) (x) : (lmk s : _ →ₗ[R] Π₀ i, M i) x = mk s x :=
rfl
#align dfinsupp.lmk_apply DFinsupp.lmk_apply
@[simp]
theorem lsingle_apply (i : ι) (x : M i) : (lsingle i : (M i) →ₗ[R] _) x = single i x :=
rfl
#align dfinsupp.lsingle_apply DFinsupp.lsingle_apply
@[simp]
theorem lapply_apply (i : ι) (f : Π₀ i, M i) : (lapply i : (Π₀ i, M i) →ₗ[R] _) f = f i :=
rfl
#align dfinsupp.lapply_apply DFinsupp.lapply_apply
section Lsum
-- Porting note: Unclear how true these docstrings are in lean 4
/-- Typeclass inference can't find `DFinsupp.addCommMonoid` without help for this case.
This instance allows it to be found where it is needed on the LHS of the colon in
`DFinsupp.moduleOfLinearMap`. -/
instance addCommMonoidOfLinearMap : AddCommMonoid (Π₀ i : ι, M i →ₗ[R] N) :=
inferInstance
#align dfinsupp.add_comm_monoid_of_linear_map DFinsupp.addCommMonoidOfLinearMap
/-- Typeclass inference can't find `DFinsupp.module` without help for this case.
This is needed to define `DFinsupp.lsum` below.
The cause seems to be an inability to unify the `∀ i, AddCommMonoid (M i →ₗ[R] N)` instance that
we have with the `∀ i, Zero (M i →ₗ[R] N)` instance which appears as a parameter to the
`DFinsupp` type. -/
instance moduleOfLinearMap [Semiring S] [Module S N] [SMulCommClass R S N] :
Module S (Π₀ i : ι, M i →ₗ[R] N) :=
DFinsupp.module
#align dfinsupp.module_of_linear_map DFinsupp.moduleOfLinearMap
variable (S)
instance {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S)
{σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) (M₂ : Type*)
[AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] :
EquivLike (LinearEquiv σ M M₂) M M₂ :=
inferInstance
/- Porting note: In every application of lsum that follows, the argument M needs to be explicitly
supplied, lean does not manage to gather that information itself -/
/-- The `DFinsupp` version of `Finsupp.lsum`.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
@[simps]
def lsum [Semiring S] [Module S N] [SMulCommClass R S N] :
(∀ i, M i →ₗ[R] N) ≃ₗ[S] (Π₀ i, M i) →ₗ[R] N where
toFun F :=
{ toFun := sumAddHom fun i => (F i).toAddMonoidHom
map_add' := (DFinsupp.liftAddHom fun (i : ι) => (F i).toAddMonoidHom).map_add
map_smul' := fun c f => by
dsimp
apply DFinsupp.induction f
· rw [smul_zero, AddMonoidHom.map_zero, smul_zero]
· intro a b f _ _ hf
rw [smul_add, AddMonoidHom.map_add, AddMonoidHom.map_add, smul_add, hf, ← single_smul,
sumAddHom_single, sumAddHom_single, LinearMap.toAddMonoidHom_coe,
LinearMap.map_smul] }
invFun F i := F.comp (lsingle i)
left_inv F := by
ext
simp
right_inv F := by
refine DFinsupp.lhom_ext' (fun i ↦ ?_)
ext
simp
map_add' F G := by
refine DFinsupp.lhom_ext' (fun i ↦ ?_)
ext
simp
map_smul' c F := by
refine DFinsupp.lhom_ext' (fun i ↦ ?_)
ext
simp
#align dfinsupp.lsum DFinsupp.lsum
/-- While `simp` can prove this, it is often convenient to avoid unfolding `lsum` into `sumAddHom`
with `DFinsupp.lsum_apply_apply`. -/
theorem lsum_single [Semiring S] [Module S N] [SMulCommClass R S N] (F : ∀ i, M i →ₗ[R] N) (i)
(x : M i) : lsum S (M := M) F (single i x) = F i x := by
simp
#align dfinsupp.lsum_single DFinsupp.lsum_single
end Lsum
end DecidableEq
/-! ### Bundled versions of `DFinsupp.mapRange`
The names should match the equivalent bundled `Finsupp.mapRange` definitions.
-/
section mapRange
variable {β β₁ β₂ : ι → Type*}
variable [∀ i, AddCommMonoid (β i)] [∀ i, AddCommMonoid (β₁ i)] [∀ i, AddCommMonoid (β₂ i)]
variable [∀ i, Module R (β i)] [∀ i, Module R (β₁ i)] [∀ i, Module R (β₂ i)]
theorem mapRange_smul (f : ∀ i, β₁ i → β₂ i) (hf : ∀ i, f i 0 = 0) (r : R)
(hf' : ∀ i x, f i (r • x) = r • f i x) (g : Π₀ i, β₁ i) :
mapRange f hf (r • g) = r • mapRange f hf g := by
ext
simp only [mapRange_apply f, coe_smul, Pi.smul_apply, hf']
#align dfinsupp.map_range_smul DFinsupp.mapRange_smul
/-- `DFinsupp.mapRange` as a `LinearMap`. -/
@[simps! apply]
def mapRange.linearMap (f : ∀ i, β₁ i →ₗ[R] β₂ i) : (Π₀ i, β₁ i) →ₗ[R] Π₀ i, β₂ i :=
{ mapRange.addMonoidHom fun i => (f i).toAddMonoidHom with
toFun := mapRange (fun i x => f i x) fun i => (f i).map_zero
map_smul' := fun r => mapRange_smul _ (fun i => (f i).map_zero) _ fun i => (f i).map_smul r }
#align dfinsupp.map_range.linear_map DFinsupp.mapRange.linearMap
@[simp]
| Mathlib/LinearAlgebra/DFinsupp.lean | 206 | 209 | theorem mapRange.linearMap_id :
(mapRange.linearMap fun i => (LinearMap.id : β₂ i →ₗ[R] _)) = LinearMap.id := by |
ext
simp [linearMap]
|
/-
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.Topology.Sets.Closeds
#align_import topology.noetherian_space from "leanprover-community/mathlib"@"dc6c365e751e34d100e80fe6e314c3c3e0fd2988"
/-!
# Noetherian space
A Noetherian space is a topological space that satisfies any of the following equivalent conditions:
- `WellFounded ((· > ·) : TopologicalSpace.Opens α → TopologicalSpace.Opens α → Prop)`
- `WellFounded ((· < ·) : TopologicalSpace.Closeds α → TopologicalSpace.Closeds α → Prop)`
- `∀ s : Set α, IsCompact s`
- `∀ s : TopologicalSpace.Opens α, IsCompact s`
The first is chosen as the definition, and the equivalence is shown in
`TopologicalSpace.noetherianSpace_TFAE`.
Many examples of noetherian spaces come from algebraic topology. For example, the underlying space
of a noetherian scheme (e.g., the spectrum of a noetherian ring) is noetherian.
## Main Results
- `TopologicalSpace.NoetherianSpace.set`: Every subspace of a noetherian space is noetherian.
- `TopologicalSpace.NoetherianSpace.isCompact`: Every set in a noetherian space is a compact set.
- `TopologicalSpace.noetherianSpace_TFAE`: Describes the equivalent definitions of noetherian
spaces.
- `TopologicalSpace.NoetherianSpace.range`: The image of a noetherian space under a continuous map
is noetherian.
- `TopologicalSpace.NoetherianSpace.iUnion`: The finite union of noetherian spaces is noetherian.
- `TopologicalSpace.NoetherianSpace.discrete`: A noetherian and Hausdorff space is discrete.
- `TopologicalSpace.NoetherianSpace.exists_finset_irreducible`: Every closed subset of a noetherian
space is a finite union of irreducible closed subsets.
- `TopologicalSpace.NoetherianSpace.finite_irreducibleComponents`: The number of irreducible
components of a noetherian space is finite.
-/
variable (α β : Type*) [TopologicalSpace α] [TopologicalSpace β]
namespace TopologicalSpace
/-- Type class for noetherian spaces. It is defined to be spaces whose open sets satisfies ACC. -/
@[mk_iff]
class NoetherianSpace : Prop where
wellFounded_opens : WellFounded ((· > ·) : Opens α → Opens α → Prop)
#align topological_space.noetherian_space TopologicalSpace.NoetherianSpace
| Mathlib/Topology/NoetherianSpace.lean | 53 | 56 | theorem noetherianSpace_iff_opens : NoetherianSpace α ↔ ∀ s : Opens α, IsCompact (s : Set α) := by |
rw [noetherianSpace_iff, CompleteLattice.wellFounded_iff_isSupFiniteCompact,
CompleteLattice.isSupFiniteCompact_iff_all_elements_compact]
exact forall_congr' Opens.isCompactElement_iff
|
/-
Copyright (c) 2021 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Ines Wright, Joachim Breitner
-/
import Mathlib.GroupTheory.QuotientGroup
import Mathlib.GroupTheory.Solvable
import Mathlib.GroupTheory.PGroup
import Mathlib.GroupTheory.Sylow
import Mathlib.Data.Nat.Factorization.Basic
import Mathlib.Tactic.TFAE
#align_import group_theory.nilpotent from "leanprover-community/mathlib"@"2bbc7e3884ba234309d2a43b19144105a753292e"
/-!
# Nilpotent groups
An API for nilpotent groups, that is, groups for which the upper central series
reaches `⊤`.
## Main definitions
Recall that if `H K : Subgroup G` then `⁅H, K⁆ : Subgroup G` is the subgroup of `G` generated
by the commutators `hkh⁻¹k⁻¹`. Recall also Lean's conventions that `⊤` denotes the
subgroup `G` of `G`, and `⊥` denotes the trivial subgroup `{1}`.
* `upperCentralSeries G : ℕ → Subgroup G` : the upper central series of a group `G`.
This is an increasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊥` and
`H (n + 1) / H n` is the centre of `G / H n`.
* `lowerCentralSeries G : ℕ → Subgroup G` : the lower central series of a group `G`.
This is a decreasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊤` and
`H (n + 1) = ⁅H n, G⁆`.
* `IsNilpotent` : A group G is nilpotent if its upper central series reaches `⊤`, or
equivalently if its lower central series reaches `⊥`.
* `nilpotency_class` : the length of the upper central series of a nilpotent group.
* `IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop` and
* `IsDescendingCentralSeries (H : ℕ → Subgroup G) : Prop` : Note that in the literature
a "central series" for a group is usually defined to be a *finite* sequence of normal subgroups
`H 0`, `H 1`, ..., starting at `⊤`, finishing at `⊥`, and with each `H n / H (n + 1)`
central in `G / H (n + 1)`. In this formalisation it is convenient to have two weaker predicates
on an infinite sequence of subgroups `H n` of `G`: we say a sequence is a *descending central
series* if it starts at `G` and `⁅H n, ⊤⁆ ⊆ H (n + 1)` for all `n`. Note that this series
may not terminate at `⊥`, and the `H i` need not be normal. Similarly a sequence is an
*ascending central series* if `H 0 = ⊥` and `⁅H (n + 1), ⊤⁆ ⊆ H n` for all `n`, again with no
requirement that the series reaches `⊤` or that the `H i` are normal.
## Main theorems
`G` is *defined* to be nilpotent if the upper central series reaches `⊤`.
* `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central
series reaches `⊤`.
* `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central
series reaches `⊥`.
* `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `⊥`.
* The `nilpotency_class` can likewise be obtained from these equivalent
definitions, see `least_ascending_central_series_length_eq_nilpotencyClass`,
`least_descending_central_series_length_eq_nilpotencyClass` and
`lowerCentralSeries_length_eq_nilpotencyClass`.
* If `G` is nilpotent, then so are its subgroups, images, quotients and preimages.
Binary and finite products of nilpotent groups are nilpotent.
Infinite products are nilpotent if their nilpotent class is bounded.
Corresponding lemmas about the `nilpotency_class` are provided.
* The `nilpotency_class` of `G ⧸ center G` is given explicitly, and an induction principle
is derived from that.
* `IsNilpotent.to_isSolvable`: If `G` is nilpotent, it is solvable.
## Warning
A "central series" is usually defined to be a finite sequence of normal subgroups going
from `⊥` to `⊤` with the property that each subquotient is contained within the centre of
the associated quotient of `G`. This means that if `G` is not nilpotent, then
none of what we have called `upperCentralSeries G`, `lowerCentralSeries G` or
the sequences satisfying `IsAscendingCentralSeries` or `IsDescendingCentralSeries`
are actually central series. Note that the fact that the upper and lower central series
are not central series if `G` is not nilpotent is a standard abuse of notation.
-/
open Subgroup
section WithGroup
variable {G : Type*} [Group G] (H : Subgroup G) [Normal H]
/-- If `H` is a normal subgroup of `G`, then the set `{x : G | ∀ y : G, x*y*x⁻¹*y⁻¹ ∈ H}`
is a subgroup of `G` (because it is the preimage in `G` of the centre of the
quotient group `G/H`.)
-/
def upperCentralSeriesStep : Subgroup G where
carrier := { x : G | ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ H }
one_mem' y := by simp [Subgroup.one_mem]
mul_mem' {a b ha hb y} := by
convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1
group
inv_mem' {x hx y} := by
specialize hx y⁻¹
rw [mul_assoc, inv_inv] at hx ⊢
exact Subgroup.Normal.mem_comm inferInstance hx
#align upper_central_series_step upperCentralSeriesStep
theorem mem_upperCentralSeriesStep (x : G) :
x ∈ upperCentralSeriesStep H ↔ ∀ y, x * y * x⁻¹ * y⁻¹ ∈ H := Iff.rfl
#align mem_upper_central_series_step mem_upperCentralSeriesStep
open QuotientGroup
/-- The proof that `upperCentralSeriesStep H` is the preimage of the centre of `G/H` under
the canonical surjection. -/
theorem upperCentralSeriesStep_eq_comap_center :
upperCentralSeriesStep H = Subgroup.comap (mk' H) (center (G ⧸ H)) := by
ext
rw [mem_comap, mem_center_iff, forall_mk]
apply forall_congr'
intro y
rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem,
div_eq_mul_inv, mul_inv_rev, mul_assoc]
#align upper_central_series_step_eq_comap_center upperCentralSeriesStep_eq_comap_center
instance : Normal (upperCentralSeriesStep H) := by
rw [upperCentralSeriesStep_eq_comap_center]
infer_instance
variable (G)
/-- An auxiliary type-theoretic definition defining both the upper central series of
a group, and a proof that it is normal, all in one go. -/
def upperCentralSeriesAux : ℕ → Σ'H : Subgroup G, Normal H
| 0 => ⟨⊥, inferInstance⟩
| n + 1 =>
let un := upperCentralSeriesAux n
let _un_normal := un.2
⟨upperCentralSeriesStep un.1, inferInstance⟩
#align upper_central_series_aux upperCentralSeriesAux
/-- `upperCentralSeries G n` is the `n`th term in the upper central series of `G`. -/
def upperCentralSeries (n : ℕ) : Subgroup G :=
(upperCentralSeriesAux G n).1
#align upper_central_series upperCentralSeries
instance upperCentralSeries_normal (n : ℕ) : Normal (upperCentralSeries G n) :=
(upperCentralSeriesAux G n).2
@[simp]
theorem upperCentralSeries_zero : upperCentralSeries G 0 = ⊥ := rfl
#align upper_central_series_zero upperCentralSeries_zero
@[simp]
theorem upperCentralSeries_one : upperCentralSeries G 1 = center G := by
ext
simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep,
Subgroup.mem_center_iff, mem_mk, mem_bot, Set.mem_setOf_eq]
exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm]
#align upper_central_series_one upperCentralSeries_one
/-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such
that `⁅x,G⁆ ⊆ H n`-/
theorem mem_upperCentralSeries_succ_iff (n : ℕ) (x : G) :
x ∈ upperCentralSeries G (n + 1) ↔ ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n :=
Iff.rfl
#align mem_upper_central_series_succ_iff mem_upperCentralSeries_succ_iff
-- is_nilpotent is already defined in the root namespace (for elements of rings).
/-- A group `G` is nilpotent if its upper central series is eventually `G`. -/
class Group.IsNilpotent (G : Type*) [Group G] : Prop where
nilpotent' : ∃ n : ℕ, upperCentralSeries G n = ⊤
#align group.is_nilpotent Group.IsNilpotent
-- Porting note: add lemma since infer kinds are unsupported in the definition of `IsNilpotent`
lemma Group.IsNilpotent.nilpotent (G : Type*) [Group G] [IsNilpotent G] :
∃ n : ℕ, upperCentralSeries G n = ⊤ := Group.IsNilpotent.nilpotent'
open Group
variable {G}
/-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and
`⁅H (n + 1), G⁆ ⊆ H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/
def IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop :=
H 0 = ⊥ ∧ ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H n
#align is_ascending_central_series IsAscendingCentralSeries
/-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and
`⁅H n, G⁆ ⊆ H (n + 1)` for all `n`. Note that we do not require that `H n = {1}` for some `n`. -/
def IsDescendingCentralSeries (H : ℕ → Subgroup G) :=
H 0 = ⊤ ∧ ∀ (x : G) (n : ℕ), x ∈ H n → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H (n + 1)
#align is_descending_central_series IsDescendingCentralSeries
/-- Any ascending central series for a group is bounded above by the upper central series. -/
theorem ascending_central_series_le_upper (H : ℕ → Subgroup G) (hH : IsAscendingCentralSeries H) :
∀ n : ℕ, H n ≤ upperCentralSeries G n
| 0 => hH.1.symm ▸ le_refl ⊥
| n + 1 => by
intro x hx
rw [mem_upperCentralSeries_succ_iff]
exact fun y => ascending_central_series_le_upper H hH n (hH.2 x n hx y)
#align ascending_central_series_le_upper ascending_central_series_le_upper
variable (G)
/-- The upper central series of a group is an ascending central series. -/
theorem upperCentralSeries_isAscendingCentralSeries :
IsAscendingCentralSeries (upperCentralSeries G) :=
⟨rfl, fun _x _n h => h⟩
#align upper_central_series_is_ascending_central_series upperCentralSeries_isAscendingCentralSeries
theorem upperCentralSeries_mono : Monotone (upperCentralSeries G) := by
refine monotone_nat_of_le_succ ?_
intro n x hx y
rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹]
exact mul_mem hx (Normal.conj_mem (upperCentralSeries_normal G n) x⁻¹ (inv_mem hx) y)
#align upper_central_series_mono upperCentralSeries_mono
/-- A group `G` is nilpotent iff there exists an ascending central series which reaches `G` in
finitely many steps. -/
theorem nilpotent_iff_finite_ascending_central_series :
IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsAscendingCentralSeries H ∧ H n = ⊤ := by
constructor
· rintro ⟨n, nH⟩
exact ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩
· rintro ⟨n, H, hH, hn⟩
use n
rw [eq_top_iff, ← hn]
exact ascending_central_series_le_upper H hH n
#align nilpotent_iff_finite_ascending_central_series nilpotent_iff_finite_ascending_central_series
theorem is_decending_rev_series_of_is_ascending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊤)
(hasc : IsAscendingCentralSeries H) : IsDescendingCentralSeries fun m : ℕ => H (n - m) := by
cases' hasc with h0 hH
refine ⟨hn, fun x m hx g => ?_⟩
dsimp at hx
by_cases hm : n ≤ m
· rw [tsub_eq_zero_of_le hm, h0, Subgroup.mem_bot] at hx
subst hx
rw [show (1 : G) * g * (1⁻¹ : G) * g⁻¹ = 1 by group]
exact Subgroup.one_mem _
· push_neg at hm
apply hH
convert hx using 1
rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right]
#align is_decending_rev_series_of_is_ascending is_decending_rev_series_of_is_ascending
theorem is_ascending_rev_series_of_is_descending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊥)
(hdesc : IsDescendingCentralSeries H) : IsAscendingCentralSeries fun m : ℕ => H (n - m) := by
cases' hdesc with h0 hH
refine ⟨hn, fun x m hx g => ?_⟩
dsimp only at hx ⊢
by_cases hm : n ≤ m
· have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm
rw [hnm, h0]
exact mem_top _
· push_neg at hm
convert hH x _ hx g using 1
rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right]
#align is_ascending_rev_series_of_is_descending is_ascending_rev_series_of_is_descending
/-- A group `G` is nilpotent iff there exists a descending central series which reaches the
trivial group in a finite time. -/
theorem nilpotent_iff_finite_descending_central_series :
IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsDescendingCentralSeries H ∧ H n = ⊥ := by
rw [nilpotent_iff_finite_ascending_central_series]
constructor
· rintro ⟨n, H, hH, hn⟩
refine ⟨n, fun m => H (n - m), is_decending_rev_series_of_is_ascending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
· rintro ⟨n, H, hH, hn⟩
refine ⟨n, fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
#align nilpotent_iff_finite_descending_central_series nilpotent_iff_finite_descending_central_series
/-- The lower central series of a group `G` is a sequence `H n` of subgroups of `G`, defined
by `H 0` is all of `G` and for `n≥1`, `H (n + 1) = ⁅H n, G⁆` -/
def lowerCentralSeries (G : Type*) [Group G] : ℕ → Subgroup G
| 0 => ⊤
| n + 1 => ⁅lowerCentralSeries G n, ⊤⁆
#align lower_central_series lowerCentralSeries
variable {G}
@[simp]
theorem lowerCentralSeries_zero : lowerCentralSeries G 0 = ⊤ := rfl
#align lower_central_series_zero lowerCentralSeries_zero
@[simp]
theorem lowerCentralSeries_one : lowerCentralSeries G 1 = commutator G := rfl
#align lower_central_series_one lowerCentralSeries_one
theorem mem_lowerCentralSeries_succ_iff (n : ℕ) (q : G) :
q ∈ lowerCentralSeries G (n + 1) ↔
q ∈ closure { x | ∃ p ∈ lowerCentralSeries G n,
∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := Iff.rfl
#align mem_lower_central_series_succ_iff mem_lowerCentralSeries_succ_iff
theorem lowerCentralSeries_succ (n : ℕ) :
lowerCentralSeries G (n + 1) =
closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } :=
rfl
#align lower_central_series_succ lowerCentralSeries_succ
instance lowerCentralSeries_normal (n : ℕ) : Normal (lowerCentralSeries G n) := by
induction' n with d hd
· exact (⊤ : Subgroup G).normal_of_characteristic
· exact @Subgroup.commutator_normal _ _ (lowerCentralSeries G d) ⊤ hd _
theorem lowerCentralSeries_antitone : Antitone (lowerCentralSeries G) := by
refine antitone_nat_of_succ_le fun n x hx => ?_
simp only [mem_lowerCentralSeries_succ_iff, exists_prop, mem_top, exists_true_left,
true_and_iff] at hx
refine
closure_induction hx ?_ (Subgroup.one_mem _) (@Subgroup.mul_mem _ _ _) (@Subgroup.inv_mem _ _ _)
rintro y ⟨z, hz, a, ha⟩
rw [← ha, mul_assoc, mul_assoc, ← mul_assoc a z⁻¹ a⁻¹]
exact mul_mem hz (Normal.conj_mem (lowerCentralSeries_normal n) z⁻¹ (inv_mem hz) a)
#align lower_central_series_antitone lowerCentralSeries_antitone
/-- The lower central series of a group is a descending central series. -/
theorem lowerCentralSeries_isDescendingCentralSeries :
IsDescendingCentralSeries (lowerCentralSeries G) := by
constructor
· rfl
intro x n hxn g
exact commutator_mem_commutator hxn (mem_top g)
#align lower_central_series_is_descending_central_series lowerCentralSeries_isDescendingCentralSeries
/-- Any descending central series for a group is bounded below by the lower central series. -/
theorem descending_central_series_ge_lower (H : ℕ → Subgroup G) (hH : IsDescendingCentralSeries H) :
∀ n : ℕ, lowerCentralSeries G n ≤ H n
| 0 => hH.1.symm ▸ le_refl ⊤
| n + 1 => commutator_le.mpr fun x hx q _ =>
hH.2 x n (descending_central_series_ge_lower H hH n hx) q
#align descending_central_series_ge_lower descending_central_series_ge_lower
/-- A group is nilpotent if and only if its lower central series eventually reaches
the trivial subgroup. -/
theorem nilpotent_iff_lowerCentralSeries : IsNilpotent G ↔ ∃ n, lowerCentralSeries G n = ⊥ := by
rw [nilpotent_iff_finite_descending_central_series]
constructor
· rintro ⟨n, H, ⟨h0, hs⟩, hn⟩
use n
rw [eq_bot_iff, ← hn]
exact descending_central_series_ge_lower H ⟨h0, hs⟩ n
· rintro ⟨n, hn⟩
exact ⟨n, lowerCentralSeries G, lowerCentralSeries_isDescendingCentralSeries, hn⟩
#align nilpotent_iff_lower_central_series nilpotent_iff_lowerCentralSeries
section Classical
open scoped Classical
variable [hG : IsNilpotent G]
variable (G)
/-- The nilpotency class of a nilpotent group is the smallest natural `n` such that
the `n`'th term of the upper central series is `G`. -/
noncomputable def Group.nilpotencyClass : ℕ := Nat.find (IsNilpotent.nilpotent G)
#align group.nilpotency_class Group.nilpotencyClass
variable {G}
@[simp]
theorem upperCentralSeries_nilpotencyClass : upperCentralSeries G (Group.nilpotencyClass G) = ⊤ :=
Nat.find_spec (IsNilpotent.nilpotent G)
#align upper_central_series_nilpotency_class upperCentralSeries_nilpotencyClass
theorem upperCentralSeries_eq_top_iff_nilpotencyClass_le {n : ℕ} :
upperCentralSeries G n = ⊤ ↔ Group.nilpotencyClass G ≤ n := by
constructor
· intro h
exact Nat.find_le h
· intro h
rw [eq_top_iff, ← upperCentralSeries_nilpotencyClass]
exact upperCentralSeries_mono _ h
#align upper_central_series_eq_top_iff_nilpotency_class_le upperCentralSeries_eq_top_iff_nilpotencyClass_le
/-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which an ascending
central series reaches `G` in its `n`'th term. -/
| Mathlib/GroupTheory/Nilpotent.lean | 384 | 392 | theorem least_ascending_central_series_length_eq_nilpotencyClass :
Nat.find ((nilpotent_iff_finite_ascending_central_series G).mp hG) =
Group.nilpotencyClass G := by |
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· intro n hn
exact ⟨upperCentralSeries G, upperCentralSeries_isAscendingCentralSeries G, hn⟩
· rintro n ⟨H, ⟨hH, hn⟩⟩
rw [← top_le_iff, ← hn]
exact ascending_central_series_le_upper H hH n
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Scott Morrison
-/
import Mathlib.CategoryTheory.Subobject.Lattice
#align_import category_theory.subobject.limits from "leanprover-community/mathlib"@"956af7c76589f444f2e1313911bad16366ea476d"
/-!
# Specific subobjects
We define `equalizerSubobject`, `kernelSubobject` and `imageSubobject`, which are the subobjects
represented by the equalizer, kernel and image of (a pair of) morphism(s) and provide conditions
for `P.factors f`, where `P` is one of these special subobjects.
TODO: Add conditions for when `P` is a pullback subobject.
TODO: an iff characterisation of `(imageSubobject f).Factors h`
-/
universe v u
noncomputable section
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Subobject Opposite
variable {C : Type u} [Category.{v} C] {X Y Z : C}
namespace CategoryTheory
namespace Limits
section Equalizer
variable (f g : X ⟶ Y) [HasEqualizer f g]
/-- The equalizer of morphisms `f g : X ⟶ Y` as a `Subobject X`. -/
abbrev equalizerSubobject : Subobject X :=
Subobject.mk (equalizer.ι f g)
#align category_theory.limits.equalizer_subobject CategoryTheory.Limits.equalizerSubobject
/-- The underlying object of `equalizerSubobject f g` is (up to isomorphism!)
the same as the chosen object `equalizer f g`. -/
def equalizerSubobjectIso : (equalizerSubobject f g : C) ≅ equalizer f g :=
Subobject.underlyingIso (equalizer.ι f g)
#align category_theory.limits.equalizer_subobject_iso CategoryTheory.Limits.equalizerSubobjectIso
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow :
(equalizerSubobjectIso f g).hom ≫ equalizer.ι f g = (equalizerSubobject f g).arrow := by
simp [equalizerSubobjectIso]
#align category_theory.limits.equalizer_subobject_arrow CategoryTheory.Limits.equalizerSubobject_arrow
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow' :
(equalizerSubobjectIso f g).inv ≫ (equalizerSubobject f g).arrow = equalizer.ι f g := by
simp [equalizerSubobjectIso]
#align category_theory.limits.equalizer_subobject_arrow' CategoryTheory.Limits.equalizerSubobject_arrow'
@[reassoc]
theorem equalizerSubobject_arrow_comp :
(equalizerSubobject f g).arrow ≫ f = (equalizerSubobject f g).arrow ≫ g := by
rw [← equalizerSubobject_arrow, Category.assoc, Category.assoc, equalizer.condition]
#align category_theory.limits.equalizer_subobject_arrow_comp CategoryTheory.Limits.equalizerSubobject_arrow_comp
theorem equalizerSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = h ≫ g) :
(equalizerSubobject f g).Factors h :=
⟨equalizer.lift h w, by simp⟩
#align category_theory.limits.equalizer_subobject_factors CategoryTheory.Limits.equalizerSubobject_factors
theorem equalizerSubobject_factors_iff {W : C} (h : W ⟶ X) :
(equalizerSubobject f g).Factors h ↔ h ≫ f = h ≫ g :=
⟨fun w => by
rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, equalizerSubobject_arrow_comp,
Category.assoc],
equalizerSubobject_factors f g h⟩
#align category_theory.limits.equalizer_subobject_factors_iff CategoryTheory.Limits.equalizerSubobject_factors_iff
end Equalizer
section Kernel
variable [HasZeroMorphisms C] (f : X ⟶ Y) [HasKernel f]
/-- The kernel of a morphism `f : X ⟶ Y` as a `Subobject X`. -/
abbrev kernelSubobject : Subobject X :=
Subobject.mk (kernel.ι f)
#align category_theory.limits.kernel_subobject CategoryTheory.Limits.kernelSubobject
/-- The underlying object of `kernelSubobject f` is (up to isomorphism!)
the same as the chosen object `kernel f`. -/
def kernelSubobjectIso : (kernelSubobject f : C) ≅ kernel f :=
Subobject.underlyingIso (kernel.ι f)
#align category_theory.limits.kernel_subobject_iso CategoryTheory.Limits.kernelSubobjectIso
@[reassoc (attr := simp), elementwise (attr := simp)]
| Mathlib/CategoryTheory/Subobject/Limits.lean | 98 | 100 | theorem kernelSubobject_arrow :
(kernelSubobjectIso f).hom ≫ kernel.ι f = (kernelSubobject f).arrow := by |
simp [kernelSubobjectIso]
|
/-
Copyright (c) 2022 Moritz Firsching. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Firsching, Fabian Kruse, Nikolas Kuhn
-/
import Mathlib.Analysis.PSeries
import Mathlib.Data.Real.Pi.Wallis
import Mathlib.Tactic.AdaptationNote
#align_import analysis.special_functions.stirling from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1"
/-!
# Stirling's formula
This file proves Stirling's formula for the factorial.
It states that $n!$ grows asymptotically like $\sqrt{2\pi n}(\frac{n}{e})^n$.
## Proof outline
The proof follows: <https://proofwiki.org/wiki/Stirling%27s_Formula>.
We proceed in two parts.
**Part 1**: We consider the sequence $a_n$ of fractions $\frac{n!}{\sqrt{2n}(\frac{n}{e})^n}$
and prove that this sequence converges to a real, positive number $a$. For this the two main
ingredients are
- taking the logarithm of the sequence and
- using the series expansion of $\log(1 + x)$.
**Part 2**: We use the fact that the series defined in part 1 converges against a real number $a$
and prove that $a = \sqrt{\pi}$. Here the main ingredient is the convergence of Wallis' product
formula for `π`.
-/
open scoped Topology Real Nat Asymptotics
open Finset Filter Nat Real
namespace Stirling
/-!
### Part 1
https://proofwiki.org/wiki/Stirling%27s_Formula#Part_1
-/
/-- Define `stirlingSeq n` as $\frac{n!}{\sqrt{2n}(\frac{n}{e})^n}$.
Stirling's formula states that this sequence has limit $\sqrt(π)$.
-/
noncomputable def stirlingSeq (n : ℕ) : ℝ :=
n ! / (√(2 * n : ℝ) * (n / exp 1) ^ n)
#align stirling.stirling_seq Stirling.stirlingSeq
@[simp]
theorem stirlingSeq_zero : stirlingSeq 0 = 0 := by
rw [stirlingSeq, cast_zero, mul_zero, Real.sqrt_zero, zero_mul, div_zero]
#align stirling.stirling_seq_zero Stirling.stirlingSeq_zero
@[simp]
theorem stirlingSeq_one : stirlingSeq 1 = exp 1 / √2 := by
rw [stirlingSeq, pow_one, factorial_one, cast_one, mul_one, mul_one_div, one_div_div]
#align stirling.stirling_seq_one Stirling.stirlingSeq_one
theorem log_stirlingSeq_formula (n : ℕ) :
log (stirlingSeq n) = Real.log n ! - 1 / 2 * Real.log (2 * n) - n * log (n / exp 1) := by
cases n
· simp
· rw [stirlingSeq, log_div, log_mul, sqrt_eq_rpow, log_rpow, Real.log_pow, tsub_tsub]
<;> positivity
-- Porting note: generalized from `n.succ` to `n`
#align stirling.log_stirling_seq_formula Stirling.log_stirlingSeq_formulaₓ
/-- The sequence `log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))` has the series expansion
`∑ 1 / (2 * (k + 1) + 1) * (1 / 2 * (m + 1) + 1)^(2 * (k + 1))`
-/
theorem log_stirlingSeq_diff_hasSum (m : ℕ) :
HasSum (fun k : ℕ => (1 : ℝ) / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ ↑(k + 1))
(log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))) := by
let f (k : ℕ) := (1 : ℝ) / (2 * k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
change HasSum (fun k => f (k + 1)) _
rw [hasSum_nat_add_iff]
convert (hasSum_log_one_add_inv m.cast_add_one_pos).mul_left ((↑(m + 1) : ℝ) + 1 / 2) using 1
· ext k
dsimp only [f]
rw [← pow_mul, pow_add]
push_cast
field_simp
ring
· have h : ∀ x ≠ (0 : ℝ), 1 + x⁻¹ = (x + 1) / x := fun x hx ↦ by field_simp [hx]
simp (disch := positivity) only [log_stirlingSeq_formula, log_div, log_mul, log_exp,
factorial_succ, cast_mul, cast_succ, cast_zero, range_one, sum_singleton, h]
ring
#align stirling.log_stirling_seq_diff_has_sum Stirling.log_stirlingSeq_diff_hasSum
/-- The sequence `log ∘ stirlingSeq ∘ succ` is monotone decreasing -/
theorem log_stirlingSeq'_antitone : Antitone (Real.log ∘ stirlingSeq ∘ succ) :=
antitone_nat_of_succ_le fun n =>
sub_nonneg.mp <| (log_stirlingSeq_diff_hasSum n).nonneg fun m => by positivity
#align stirling.log_stirling_seq'_antitone Stirling.log_stirlingSeq'_antitone
/-- We have a bound for successive elements in the sequence `log (stirlingSeq k)`.
-/
theorem log_stirlingSeq_diff_le_geo_sum (n : ℕ) :
log (stirlingSeq (n + 1)) - log (stirlingSeq (n + 2)) ≤
((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 / (1 - ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) := by
have h_nonneg : (0 : ℝ) ≤ ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 := sq_nonneg _
have g : HasSum (fun k : ℕ => (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1))
(((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 / (1 - ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2)) := by
have := (hasSum_geometric_of_lt_one h_nonneg ?_).mul_left (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2)
· simp_rw [← _root_.pow_succ'] at this
exact this
rw [one_div, inv_pow]
exact inv_lt_one (one_lt_pow ((lt_add_iff_pos_left 1).mpr <| by positivity) two_ne_zero)
have hab (k : ℕ) : (1 : ℝ) / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1) ≤
(((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1) := by
refine mul_le_of_le_one_left (pow_nonneg h_nonneg ↑(k + 1)) ?_
rw [one_div]
exact inv_le_one (le_add_of_nonneg_left <| by positivity)
exact hasSum_le hab (log_stirlingSeq_diff_hasSum n) g
#align stirling.log_stirling_seq_diff_le_geo_sum Stirling.log_stirlingSeq_diff_le_geo_sum
#adaptation_note /-- after v4.7.0-rc1, there is a performance problem in `field_simp`.
(Part of the code was ignoring the `maxDischargeDepth` setting:
now that we have to increase it, other paths become slow.) -/
set_option maxHeartbeats 400000 in
/-- We have the bound `log (stirlingSeq n) - log (stirlingSeq (n+1))` ≤ 1/(4 n^2)
-/
theorem log_stirlingSeq_sub_log_stirlingSeq_succ (n : ℕ) :
log (stirlingSeq (n + 1)) - log (stirlingSeq (n + 2)) ≤ 1 / (4 * (↑(n + 1):ℝ) ^ 2) := by
have h₁ : (0 : ℝ) < 4 * ((n : ℝ) + 1) ^ 2 := by positivity
have h₃ : (0 : ℝ) < (2 * ((n : ℝ) + 1) + 1) ^ 2 := by positivity
have h₂ : (0 : ℝ) < 1 - (1 / (2 * ((n : ℝ) + 1) + 1)) ^ 2 := by
rw [← mul_lt_mul_right h₃]
have H : 0 < (2 * ((n : ℝ) + 1) + 1) ^ 2 - 1 := by nlinarith [@cast_nonneg ℝ _ n]
convert H using 1 <;> field_simp [h₃.ne']
refine (log_stirlingSeq_diff_le_geo_sum n).trans ?_
push_cast
rw [div_le_div_iff h₂ h₁]
field_simp [h₃.ne']
rw [div_le_div_right h₃]
ring_nf
norm_cast
omega
#align stirling.log_stirling_seq_sub_log_stirling_seq_succ Stirling.log_stirlingSeq_sub_log_stirlingSeq_succ
/-- For any `n`, we have `log_stirlingSeq 1 - log_stirlingSeq n ≤ 1/4 * ∑' 1/k^2` -/
theorem log_stirlingSeq_bounded_aux :
∃ c : ℝ, ∀ n : ℕ, log (stirlingSeq 1) - log (stirlingSeq (n + 1)) ≤ c := by
let d : ℝ := ∑' k : ℕ, (1 : ℝ) / (↑(k + 1) : ℝ) ^ 2
use 1 / 4 * d
let log_stirlingSeq' : ℕ → ℝ := fun k => log (stirlingSeq (k + 1))
intro n
have h₁ k : log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≤ 1 / 4 * (1 / (↑(k + 1) : ℝ) ^ 2) := by
convert log_stirlingSeq_sub_log_stirlingSeq_succ k using 1; field_simp
have h₂ : (∑ k ∈ range n, 1 / (↑(k + 1) : ℝ) ^ 2) ≤ d := by
have := (summable_nat_add_iff 1).mpr <| Real.summable_one_div_nat_pow.mpr one_lt_two
exact sum_le_tsum (range n) (fun k _ => by positivity) this
calc
log (stirlingSeq 1) - log (stirlingSeq (n + 1)) = log_stirlingSeq' 0 - log_stirlingSeq' n :=
rfl
_ = ∑ k ∈ range n, (log_stirlingSeq' k - log_stirlingSeq' (k + 1)) := by
rw [← sum_range_sub' log_stirlingSeq' n]
_ ≤ ∑ k ∈ range n, 1 / 4 * (1 / ↑((k + 1)) ^ 2) := sum_le_sum fun k _ => h₁ k
_ = 1 / 4 * ∑ k ∈ range n, 1 / ↑((k + 1)) ^ 2 := by rw [mul_sum]
_ ≤ 1 / 4 * d := by gcongr
#align stirling.log_stirling_seq_bounded_aux Stirling.log_stirlingSeq_bounded_aux
/-- The sequence `log_stirlingSeq` is bounded below for `n ≥ 1`. -/
theorem log_stirlingSeq_bounded_by_constant : ∃ c, ∀ n : ℕ, c ≤ log (stirlingSeq (n + 1)) := by
obtain ⟨d, h⟩ := log_stirlingSeq_bounded_aux
exact ⟨log (stirlingSeq 1) - d, fun n => sub_le_comm.mp (h n)⟩
#align stirling.log_stirling_seq_bounded_by_constant Stirling.log_stirlingSeq_bounded_by_constant
/-- The sequence `stirlingSeq` is positive for `n > 0` -/
theorem stirlingSeq'_pos (n : ℕ) : 0 < stirlingSeq (n + 1) := by unfold stirlingSeq; positivity
#align stirling.stirling_seq'_pos Stirling.stirlingSeq'_pos
/-- The sequence `stirlingSeq` has a positive lower bound.
-/
theorem stirlingSeq'_bounded_by_pos_constant : ∃ a, 0 < a ∧ ∀ n : ℕ, a ≤ stirlingSeq (n + 1) := by
cases' log_stirlingSeq_bounded_by_constant with c h
refine ⟨exp c, exp_pos _, fun n => ?_⟩
rw [← le_log_iff_exp_le (stirlingSeq'_pos n)]
exact h n
#align stirling.stirling_seq'_bounded_by_pos_constant Stirling.stirlingSeq'_bounded_by_pos_constant
/-- The sequence `stirlingSeq ∘ succ` is monotone decreasing -/
theorem stirlingSeq'_antitone : Antitone (stirlingSeq ∘ succ) := fun n m h =>
(log_le_log_iff (stirlingSeq'_pos m) (stirlingSeq'_pos n)).mp (log_stirlingSeq'_antitone h)
#align stirling.stirling_seq'_antitone Stirling.stirlingSeq'_antitone
/-- The limit `a` of the sequence `stirlingSeq` satisfies `0 < a` -/
theorem stirlingSeq_has_pos_limit_a : ∃ a : ℝ, 0 < a ∧ Tendsto stirlingSeq atTop (𝓝 a) := by
obtain ⟨x, x_pos, hx⟩ := stirlingSeq'_bounded_by_pos_constant
have hx' : x ∈ lowerBounds (Set.range (stirlingSeq ∘ succ)) := by simpa [lowerBounds] using hx
refine ⟨_, lt_of_lt_of_le x_pos (le_csInf (Set.range_nonempty _) hx'), ?_⟩
rw [← Filter.tendsto_add_atTop_iff_nat 1]
exact tendsto_atTop_ciInf stirlingSeq'_antitone ⟨x, hx'⟩
#align stirling.stirling_seq_has_pos_limit_a Stirling.stirlingSeq_has_pos_limit_a
/-!
### Part 2
https://proofwiki.org/wiki/Stirling%27s_Formula#Part_2
-/
/-- The sequence `n / (2 * n + 1)` tends to `1/2` -/
theorem tendsto_self_div_two_mul_self_add_one :
Tendsto (fun n : ℕ => (n : ℝ) / (2 * n + 1)) atTop (𝓝 (1 / 2)) := by
conv =>
congr
· skip
· skip
rw [one_div, ← add_zero (2 : ℝ)]
refine (((tendsto_const_div_atTop_nhds_zero_nat 1).const_add (2 : ℝ)).inv₀
((add_zero (2 : ℝ)).symm ▸ two_ne_zero)).congr' (eventually_atTop.mpr ⟨1, fun n hn => ?_⟩)
rw [add_div' (1 : ℝ) 2 n (cast_ne_zero.mpr (one_le_iff_ne_zero.mp hn)), inv_div]
#align stirling.tendsto_self_div_two_mul_self_add_one Stirling.tendsto_self_div_two_mul_self_add_one
/-- For any `n ≠ 0`, we have the identity
`(stirlingSeq n)^4 / (stirlingSeq (2*n))^2 * (n / (2 * n + 1)) = W n`, where `W n` is the
`n`-th partial product of Wallis' formula for `π / 2`. -/
theorem stirlingSeq_pow_four_div_stirlingSeq_pow_two_eq (n : ℕ) (hn : n ≠ 0) :
stirlingSeq n ^ 4 / stirlingSeq (2 * n) ^ 2 * (n / (2 * n + 1)) = Wallis.W n := by
have : 4 = 2 * 2 := by rfl
rw [stirlingSeq, this, pow_mul, stirlingSeq, Wallis.W_eq_factorial_ratio]
simp_rw [div_pow, mul_pow]
rw [sq_sqrt, sq_sqrt]
any_goals positivity
field_simp [← exp_nsmul]
ring_nf
#align stirling.stirling_seq_pow_four_div_stirling_seq_pow_two_eq Stirling.stirlingSeq_pow_four_div_stirlingSeq_pow_two_eq
/-- Suppose the sequence `stirlingSeq` (defined above) has the limit `a ≠ 0`.
Then the Wallis sequence `W n` has limit `a^2 / 2`.
-/
theorem second_wallis_limit (a : ℝ) (hane : a ≠ 0) (ha : Tendsto stirlingSeq atTop (𝓝 a)) :
Tendsto Wallis.W atTop (𝓝 (a ^ 2 / 2)) := by
refine Tendsto.congr' (eventually_atTop.mpr ⟨1, fun n hn =>
stirlingSeq_pow_four_div_stirlingSeq_pow_two_eq n (one_le_iff_ne_zero.mp hn)⟩) ?_
have h : a ^ 2 / 2 = a ^ 4 / a ^ 2 * (1 / 2) := by
rw [mul_one_div, ← mul_one_div (a ^ 4) (a ^ 2), one_div, ← pow_sub_of_lt a]
norm_num
rw [h]
exact ((ha.pow 4).div ((ha.comp (tendsto_id.const_mul_atTop' two_pos)).pow 2)
(pow_ne_zero 2 hane)).mul tendsto_self_div_two_mul_self_add_one
#align stirling.second_wallis_limit Stirling.second_wallis_limit
/-- **Stirling's Formula** -/
| Mathlib/Analysis/SpecialFunctions/Stirling.lean | 251 | 255 | theorem tendsto_stirlingSeq_sqrt_pi : Tendsto stirlingSeq atTop (𝓝 (√π)) := by |
obtain ⟨a, hapos, halimit⟩ := stirlingSeq_has_pos_limit_a
have hπ : π / 2 = a ^ 2 / 2 :=
tendsto_nhds_unique Wallis.tendsto_W_nhds_pi_div_two (second_wallis_limit a hapos.ne' halimit)
rwa [(div_left_inj' (two_ne_zero' ℝ)).mp hπ, sqrt_sq hapos.le]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Angle
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse
#align_import analysis.special_functions.complex.arg from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1"
/-!
# The argument of a complex number.
We define `arg : ℂ → ℝ`, returning a real number in the range (-π, π],
such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
while `arg 0` defaults to `0`
-/
open Filter Metric Set
open scoped ComplexConjugate Real Topology
namespace Complex
variable {a x z : ℂ}
/-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`,
`sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
`arg 0` defaults to `0` -/
noncomputable def arg (x : ℂ) : ℝ :=
if 0 ≤ x.re then Real.arcsin (x.im / abs x)
else if 0 ≤ x.im then Real.arcsin ((-x).im / abs x) + π else Real.arcsin ((-x).im / abs x) - π
#align complex.arg Complex.arg
theorem sin_arg (x : ℂ) : Real.sin (arg x) = x.im / abs x := by
unfold arg; split_ifs <;>
simp [sub_eq_add_neg, arg,
Real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1 (abs_le.1 (abs_im_div_abs_le_one x)).2,
Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg]
#align complex.sin_arg Complex.sin_arg
theorem cos_arg {x : ℂ} (hx : x ≠ 0) : Real.cos (arg x) = x.re / abs x := by
rw [arg]
split_ifs with h₁ h₂
· rw [Real.cos_arcsin]
field_simp [Real.sqrt_sq, (abs.pos hx).le, *]
· rw [Real.cos_add_pi, Real.cos_arcsin]
field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 h₁), *]
· rw [Real.cos_sub_pi, Real.cos_arcsin]
field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 h₁), *]
#align complex.cos_arg Complex.cos_arg
@[simp]
theorem abs_mul_exp_arg_mul_I (x : ℂ) : ↑(abs x) * exp (arg x * I) = x := by
rcases eq_or_ne x 0 with (rfl | hx)
· simp
· have : abs x ≠ 0 := abs.ne_zero hx
apply Complex.ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm (abs x)]
set_option linter.uppercaseLean3 false in
#align complex.abs_mul_exp_arg_mul_I Complex.abs_mul_exp_arg_mul_I
@[simp]
theorem abs_mul_cos_add_sin_mul_I (x : ℂ) : (abs x * (cos (arg x) + sin (arg x) * I) : ℂ) = x := by
rw [← exp_mul_I, abs_mul_exp_arg_mul_I]
set_option linter.uppercaseLean3 false in
#align complex.abs_mul_cos_add_sin_mul_I Complex.abs_mul_cos_add_sin_mul_I
@[simp]
lemma abs_mul_cos_arg (x : ℂ) : abs x * Real.cos (arg x) = x.re := by
simpa [-abs_mul_cos_add_sin_mul_I] using congr_arg re (abs_mul_cos_add_sin_mul_I x)
@[simp]
lemma abs_mul_sin_arg (x : ℂ) : abs x * Real.sin (arg x) = x.im := by
simpa [-abs_mul_cos_add_sin_mul_I] using congr_arg im (abs_mul_cos_add_sin_mul_I x)
theorem abs_eq_one_iff (z : ℂ) : abs z = 1 ↔ ∃ θ : ℝ, exp (θ * I) = z := by
refine ⟨fun hz => ⟨arg z, ?_⟩, ?_⟩
· calc
exp (arg z * I) = abs z * exp (arg z * I) := by rw [hz, ofReal_one, one_mul]
_ = z := abs_mul_exp_arg_mul_I z
· rintro ⟨θ, rfl⟩
exact Complex.abs_exp_ofReal_mul_I θ
#align complex.abs_eq_one_iff Complex.abs_eq_one_iff
@[simp]
theorem range_exp_mul_I : (Set.range fun x : ℝ => exp (x * I)) = Metric.sphere 0 1 := by
ext x
simp only [mem_sphere_zero_iff_norm, norm_eq_abs, abs_eq_one_iff, Set.mem_range]
set_option linter.uppercaseLean3 false in
#align complex.range_exp_mul_I Complex.range_exp_mul_I
theorem arg_mul_cos_add_sin_mul_I {r : ℝ} (hr : 0 < r) {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) :
arg (r * (cos θ + sin θ * I)) = θ := by
simp only [arg, map_mul, abs_cos_add_sin_mul_I, abs_of_nonneg hr.le, mul_one]
simp only [re_ofReal_mul, im_ofReal_mul, neg_im, ← ofReal_cos, ← ofReal_sin, ←
mk_eq_add_mul_I, neg_div, mul_div_cancel_left₀ _ hr.ne', mul_nonneg_iff_right_nonneg_of_pos hr]
by_cases h₁ : θ ∈ Set.Icc (-(π / 2)) (π / 2)
· rw [if_pos]
exacts [Real.arcsin_sin' h₁, Real.cos_nonneg_of_mem_Icc h₁]
· rw [Set.mem_Icc, not_and_or, not_le, not_le] at h₁
cases' h₁ with h₁ h₁
· replace hθ := hθ.1
have hcos : Real.cos θ < 0 := by
rw [← neg_pos, ← Real.cos_add_pi]
refine Real.cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith
have hsin : Real.sin θ < 0 := Real.sin_neg_of_neg_of_neg_pi_lt (by linarith) hθ
rw [if_neg, if_neg, ← Real.sin_add_pi, Real.arcsin_sin, add_sub_cancel_right] <;> [linarith;
linarith; exact hsin.not_le; exact hcos.not_le]
· replace hθ := hθ.2
have hcos : Real.cos θ < 0 := Real.cos_neg_of_pi_div_two_lt_of_lt h₁ (by linarith)
have hsin : 0 ≤ Real.sin θ := Real.sin_nonneg_of_mem_Icc ⟨by linarith, hθ⟩
rw [if_neg, if_pos, ← Real.sin_sub_pi, Real.arcsin_sin, sub_add_cancel] <;> [linarith;
linarith; exact hsin; exact hcos.not_le]
set_option linter.uppercaseLean3 false in
#align complex.arg_mul_cos_add_sin_mul_I Complex.arg_mul_cos_add_sin_mul_I
theorem arg_cos_add_sin_mul_I {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) : arg (cos θ + sin θ * I) = θ := by
rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I zero_lt_one hθ]
set_option linter.uppercaseLean3 false in
#align complex.arg_cos_add_sin_mul_I Complex.arg_cos_add_sin_mul_I
lemma arg_exp_mul_I (θ : ℝ) :
arg (exp (θ * I)) = toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ := by
convert arg_cos_add_sin_mul_I (θ := toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ) _ using 2
· rw [← exp_mul_I, eq_sub_of_add_eq $ toIocMod_add_toIocDiv_zsmul _ _ θ, ofReal_sub,
ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq]
· convert toIocMod_mem_Ioc _ _ _
ring
@[simp]
theorem arg_zero : arg 0 = 0 := by simp [arg, le_refl]
#align complex.arg_zero Complex.arg_zero
theorem ext_abs_arg {x y : ℂ} (h₁ : abs x = abs y) (h₂ : x.arg = y.arg) : x = y := by
rw [← abs_mul_exp_arg_mul_I x, ← abs_mul_exp_arg_mul_I y, h₁, h₂]
#align complex.ext_abs_arg Complex.ext_abs_arg
theorem ext_abs_arg_iff {x y : ℂ} : x = y ↔ abs x = abs y ∧ arg x = arg y :=
⟨fun h => h ▸ ⟨rfl, rfl⟩, and_imp.2 ext_abs_arg⟩
#align complex.ext_abs_arg_iff Complex.ext_abs_arg_iff
theorem arg_mem_Ioc (z : ℂ) : arg z ∈ Set.Ioc (-π) π := by
have hπ : 0 < π := Real.pi_pos
rcases eq_or_ne z 0 with (rfl | hz)
· simp [hπ, hπ.le]
rcases existsUnique_add_zsmul_mem_Ioc Real.two_pi_pos (arg z) (-π) with ⟨N, hN, -⟩
rw [two_mul, neg_add_cancel_left, ← two_mul, zsmul_eq_mul] at hN
rw [← abs_mul_cos_add_sin_mul_I z, ← cos_add_int_mul_two_pi _ N, ← sin_add_int_mul_two_pi _ N]
have := arg_mul_cos_add_sin_mul_I (abs.pos hz) hN
push_cast at this
rwa [this]
#align complex.arg_mem_Ioc Complex.arg_mem_Ioc
@[simp]
theorem range_arg : Set.range arg = Set.Ioc (-π) π :=
(Set.range_subset_iff.2 arg_mem_Ioc).antisymm fun _ hx => ⟨_, arg_cos_add_sin_mul_I hx⟩
#align complex.range_arg Complex.range_arg
theorem arg_le_pi (x : ℂ) : arg x ≤ π :=
(arg_mem_Ioc x).2
#align complex.arg_le_pi Complex.arg_le_pi
theorem neg_pi_lt_arg (x : ℂ) : -π < arg x :=
(arg_mem_Ioc x).1
#align complex.neg_pi_lt_arg Complex.neg_pi_lt_arg
theorem abs_arg_le_pi (z : ℂ) : |arg z| ≤ π :=
abs_le.2 ⟨(neg_pi_lt_arg z).le, arg_le_pi z⟩
#align complex.abs_arg_le_pi Complex.abs_arg_le_pi
@[simp]
theorem arg_nonneg_iff {z : ℂ} : 0 ≤ arg z ↔ 0 ≤ z.im := by
rcases eq_or_ne z 0 with (rfl | h₀); · simp
calc
0 ≤ arg z ↔ 0 ≤ Real.sin (arg z) :=
⟨fun h => Real.sin_nonneg_of_mem_Icc ⟨h, arg_le_pi z⟩, by
contrapose!
intro h
exact Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_arg _)⟩
_ ↔ _ := by rw [sin_arg, le_div_iff (abs.pos h₀), zero_mul]
#align complex.arg_nonneg_iff Complex.arg_nonneg_iff
@[simp]
theorem arg_neg_iff {z : ℂ} : arg z < 0 ↔ z.im < 0 :=
lt_iff_lt_of_le_iff_le arg_nonneg_iff
#align complex.arg_neg_iff Complex.arg_neg_iff
theorem arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := by
rcases eq_or_ne x 0 with (rfl | hx); · rw [mul_zero]
conv_lhs =>
rw [← abs_mul_cos_add_sin_mul_I x, ← mul_assoc, ← ofReal_mul,
arg_mul_cos_add_sin_mul_I (mul_pos hr (abs.pos hx)) x.arg_mem_Ioc]
#align complex.arg_real_mul Complex.arg_real_mul
theorem arg_mul_real {r : ℝ} (hr : 0 < r) (x : ℂ) : arg (x * r) = arg x :=
mul_comm x r ▸ arg_real_mul x hr
theorem arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) :
arg x = arg y ↔ (abs y / abs x : ℂ) * x = y := by
simp only [ext_abs_arg_iff, map_mul, map_div₀, abs_ofReal, abs_abs,
div_mul_cancel₀ _ (abs.ne_zero hx), eq_self_iff_true, true_and_iff]
rw [← ofReal_div, arg_real_mul]
exact div_pos (abs.pos hy) (abs.pos hx)
#align complex.arg_eq_arg_iff Complex.arg_eq_arg_iff
@[simp]
theorem arg_one : arg 1 = 0 := by simp [arg, zero_le_one]
#align complex.arg_one Complex.arg_one
@[simp]
theorem arg_neg_one : arg (-1) = π := by simp [arg, le_refl, not_le.2 (zero_lt_one' ℝ)]
#align complex.arg_neg_one Complex.arg_neg_one
@[simp]
theorem arg_I : arg I = π / 2 := by simp [arg, le_refl]
set_option linter.uppercaseLean3 false in
#align complex.arg_I Complex.arg_I
@[simp]
theorem arg_neg_I : arg (-I) = -(π / 2) := by simp [arg, le_refl]
set_option linter.uppercaseLean3 false in
#align complex.arg_neg_I Complex.arg_neg_I
@[simp]
theorem tan_arg (x : ℂ) : Real.tan (arg x) = x.im / x.re := by
by_cases h : x = 0
· simp only [h, zero_div, Complex.zero_im, Complex.arg_zero, Real.tan_zero, Complex.zero_re]
rw [Real.tan_eq_sin_div_cos, sin_arg, cos_arg h, div_div_div_cancel_right _ (abs.ne_zero h)]
#align complex.tan_arg Complex.tan_arg
theorem arg_ofReal_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 := by simp [arg, hx]
#align complex.arg_of_real_of_nonneg Complex.arg_ofReal_of_nonneg
@[simp, norm_cast]
lemma natCast_arg {n : ℕ} : arg n = 0 :=
ofReal_natCast n ▸ arg_ofReal_of_nonneg n.cast_nonneg
@[simp]
lemma ofNat_arg {n : ℕ} [n.AtLeastTwo] : arg (no_index (OfNat.ofNat n)) = 0 :=
natCast_arg
theorem arg_eq_zero_iff {z : ℂ} : arg z = 0 ↔ 0 ≤ z.re ∧ z.im = 0 := by
refine ⟨fun h => ?_, ?_⟩
· rw [← abs_mul_cos_add_sin_mul_I z, h]
simp [abs.nonneg]
· cases' z with x y
rintro ⟨h, rfl : y = 0⟩
exact arg_ofReal_of_nonneg h
#align complex.arg_eq_zero_iff Complex.arg_eq_zero_iff
open ComplexOrder in
lemma arg_eq_zero_iff_zero_le {z : ℂ} : arg z = 0 ↔ 0 ≤ z := by
rw [arg_eq_zero_iff, eq_comm, nonneg_iff]
theorem arg_eq_pi_iff {z : ℂ} : arg z = π ↔ z.re < 0 ∧ z.im = 0 := by
by_cases h₀ : z = 0
· simp [h₀, lt_irrefl, Real.pi_ne_zero.symm]
constructor
· intro h
rw [← abs_mul_cos_add_sin_mul_I z, h]
simp [h₀]
· cases' z with x y
rintro ⟨h : x < 0, rfl : y = 0⟩
rw [← arg_neg_one, ← arg_real_mul (-1) (neg_pos.2 h)]
simp [← ofReal_def]
#align complex.arg_eq_pi_iff Complex.arg_eq_pi_iff
open ComplexOrder in
lemma arg_eq_pi_iff_lt_zero {z : ℂ} : arg z = π ↔ z < 0 := arg_eq_pi_iff
theorem arg_lt_pi_iff {z : ℂ} : arg z < π ↔ 0 ≤ z.re ∨ z.im ≠ 0 := by
rw [(arg_le_pi z).lt_iff_ne, not_iff_comm, not_or, not_le, Classical.not_not, arg_eq_pi_iff]
#align complex.arg_lt_pi_iff Complex.arg_lt_pi_iff
theorem arg_ofReal_of_neg {x : ℝ} (hx : x < 0) : arg x = π :=
arg_eq_pi_iff.2 ⟨hx, rfl⟩
#align complex.arg_of_real_of_neg Complex.arg_ofReal_of_neg
theorem arg_eq_pi_div_two_iff {z : ℂ} : arg z = π / 2 ↔ z.re = 0 ∧ 0 < z.im := by
by_cases h₀ : z = 0; · simp [h₀, lt_irrefl, Real.pi_div_two_pos.ne]
constructor
· intro h
rw [← abs_mul_cos_add_sin_mul_I z, h]
simp [h₀]
· cases' z with x y
rintro ⟨rfl : x = 0, hy : 0 < y⟩
rw [← arg_I, ← arg_real_mul I hy, ofReal_mul', I_re, I_im, mul_zero, mul_one]
#align complex.arg_eq_pi_div_two_iff Complex.arg_eq_pi_div_two_iff
theorem arg_eq_neg_pi_div_two_iff {z : ℂ} : arg z = -(π / 2) ↔ z.re = 0 ∧ z.im < 0 := by
by_cases h₀ : z = 0; · simp [h₀, lt_irrefl, Real.pi_ne_zero]
constructor
· intro h
rw [← abs_mul_cos_add_sin_mul_I z, h]
simp [h₀]
· cases' z with x y
rintro ⟨rfl : x = 0, hy : y < 0⟩
rw [← arg_neg_I, ← arg_real_mul (-I) (neg_pos.2 hy), mk_eq_add_mul_I]
simp
#align complex.arg_eq_neg_pi_div_two_iff Complex.arg_eq_neg_pi_div_two_iff
theorem arg_of_re_nonneg {x : ℂ} (hx : 0 ≤ x.re) : arg x = Real.arcsin (x.im / abs x) :=
if_pos hx
#align complex.arg_of_re_nonneg Complex.arg_of_re_nonneg
theorem arg_of_re_neg_of_im_nonneg {x : ℂ} (hx_re : x.re < 0) (hx_im : 0 ≤ x.im) :
arg x = Real.arcsin ((-x).im / abs x) + π := by
simp only [arg, hx_re.not_le, hx_im, if_true, if_false]
#align complex.arg_of_re_neg_of_im_nonneg Complex.arg_of_re_neg_of_im_nonneg
theorem arg_of_re_neg_of_im_neg {x : ℂ} (hx_re : x.re < 0) (hx_im : x.im < 0) :
arg x = Real.arcsin ((-x).im / abs x) - π := by
simp only [arg, hx_re.not_le, hx_im.not_le, if_false]
#align complex.arg_of_re_neg_of_im_neg Complex.arg_of_re_neg_of_im_neg
theorem arg_of_im_nonneg_of_ne_zero {z : ℂ} (h₁ : 0 ≤ z.im) (h₂ : z ≠ 0) :
arg z = Real.arccos (z.re / abs z) := by
rw [← cos_arg h₂, Real.arccos_cos (arg_nonneg_iff.2 h₁) (arg_le_pi _)]
#align complex.arg_of_im_nonneg_of_ne_zero Complex.arg_of_im_nonneg_of_ne_zero
theorem arg_of_im_pos {z : ℂ} (hz : 0 < z.im) : arg z = Real.arccos (z.re / abs z) :=
arg_of_im_nonneg_of_ne_zero hz.le fun h => hz.ne' <| h.symm ▸ rfl
#align complex.arg_of_im_pos Complex.arg_of_im_pos
theorem arg_of_im_neg {z : ℂ} (hz : z.im < 0) : arg z = -Real.arccos (z.re / abs z) := by
have h₀ : z ≠ 0 := mt (congr_arg im) hz.ne
rw [← cos_arg h₀, ← Real.cos_neg, Real.arccos_cos, neg_neg]
exacts [neg_nonneg.2 (arg_neg_iff.2 hz).le, neg_le.2 (neg_pi_lt_arg z).le]
#align complex.arg_of_im_neg Complex.arg_of_im_neg
theorem arg_conj (x : ℂ) : arg (conj x) = if arg x = π then π else -arg x := by
simp_rw [arg_eq_pi_iff, arg, neg_im, conj_im, conj_re, abs_conj, neg_div, neg_neg,
Real.arcsin_neg]
rcases lt_trichotomy x.re 0 with (hr | hr | hr) <;>
rcases lt_trichotomy x.im 0 with (hi | hi | hi)
· simp [hr, hr.not_le, hi.le, hi.ne, not_le.2 hi, add_comm]
· simp [hr, hr.not_le, hi]
· simp [hr, hr.not_le, hi.ne.symm, hi.le, not_le.2 hi, sub_eq_neg_add]
· simp [hr]
· simp [hr]
· simp [hr]
· simp [hr, hr.le, hi.ne]
· simp [hr, hr.le, hr.le.not_lt]
· simp [hr, hr.le, hr.le.not_lt]
#align complex.arg_conj Complex.arg_conj
theorem arg_inv (x : ℂ) : arg x⁻¹ = if arg x = π then π else -arg x := by
rw [← arg_conj, inv_def, mul_comm]
by_cases hx : x = 0
· simp [hx]
· exact arg_real_mul (conj x) (by simp [hx])
#align complex.arg_inv Complex.arg_inv
@[simp] lemma abs_arg_inv (x : ℂ) : |x⁻¹.arg| = |x.arg| := by rw [arg_inv]; split_ifs <;> simp [*]
-- TODO: Replace the next two lemmas by general facts about periodic functions
lemma abs_eq_one_iff' : abs x = 1 ↔ ∃ θ ∈ Set.Ioc (-π) π, exp (θ * I) = x := by
rw [abs_eq_one_iff]
constructor
· rintro ⟨θ, rfl⟩
refine ⟨toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ, ?_, ?_⟩
· convert toIocMod_mem_Ioc _ _ _
ring
· rw [eq_sub_of_add_eq $ toIocMod_add_toIocDiv_zsmul _ _ θ, ofReal_sub,
ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq]
· rintro ⟨θ, _, rfl⟩
exact ⟨θ, rfl⟩
lemma image_exp_Ioc_eq_sphere : (fun θ : ℝ ↦ exp (θ * I)) '' Set.Ioc (-π) π = sphere 0 1 := by
ext; simpa using abs_eq_one_iff'.symm
theorem arg_le_pi_div_two_iff {z : ℂ} : arg z ≤ π / 2 ↔ 0 ≤ re z ∨ im z < 0 := by
rcases le_or_lt 0 (re z) with hre | hre
· simp only [hre, arg_of_re_nonneg hre, Real.arcsin_le_pi_div_two, true_or_iff]
simp only [hre.not_le, false_or_iff]
rcases le_or_lt 0 (im z) with him | him
· simp only [him.not_lt]
rw [iff_false_iff, not_le, arg_of_re_neg_of_im_nonneg hre him, ← sub_lt_iff_lt_add, half_sub,
Real.neg_pi_div_two_lt_arcsin, neg_im, neg_div, neg_lt_neg_iff, div_lt_one, ←
_root_.abs_of_nonneg him, abs_im_lt_abs]
exacts [hre.ne, abs.pos <| ne_of_apply_ne re hre.ne]
· simp only [him]
rw [iff_true_iff, arg_of_re_neg_of_im_neg hre him]
exact (sub_le_self _ Real.pi_pos.le).trans (Real.arcsin_le_pi_div_two _)
#align complex.arg_le_pi_div_two_iff Complex.arg_le_pi_div_two_iff
theorem neg_pi_div_two_le_arg_iff {z : ℂ} : -(π / 2) ≤ arg z ↔ 0 ≤ re z ∨ 0 ≤ im z := by
rcases le_or_lt 0 (re z) with hre | hre
· simp only [hre, arg_of_re_nonneg hre, Real.neg_pi_div_two_le_arcsin, true_or_iff]
simp only [hre.not_le, false_or_iff]
rcases le_or_lt 0 (im z) with him | him
· simp only [him]
rw [iff_true_iff, arg_of_re_neg_of_im_nonneg hre him]
exact (Real.neg_pi_div_two_le_arcsin _).trans (le_add_of_nonneg_right Real.pi_pos.le)
· simp only [him.not_le]
rw [iff_false_iff, not_le, arg_of_re_neg_of_im_neg hre him, sub_lt_iff_lt_add', ←
sub_eq_add_neg, sub_half, Real.arcsin_lt_pi_div_two, div_lt_one, neg_im, ← abs_of_neg him,
abs_im_lt_abs]
exacts [hre.ne, abs.pos <| ne_of_apply_ne re hre.ne]
#align complex.neg_pi_div_two_le_arg_iff Complex.neg_pi_div_two_le_arg_iff
lemma neg_pi_div_two_lt_arg_iff {z : ℂ} : -(π / 2) < arg z ↔ 0 < re z ∨ 0 ≤ im z := by
rw [lt_iff_le_and_ne, neg_pi_div_two_le_arg_iff, ne_comm, Ne, arg_eq_neg_pi_div_two_iff]
rcases lt_trichotomy z.re 0 with hre | hre | hre
· simp [hre.ne, hre.not_le, hre.not_lt]
· simp [hre]
· simp [hre, hre.le, hre.ne']
lemma arg_lt_pi_div_two_iff {z : ℂ} : arg z < π / 2 ↔ 0 < re z ∨ im z < 0 ∨ z = 0 := by
rw [lt_iff_le_and_ne, arg_le_pi_div_two_iff, Ne, arg_eq_pi_div_two_iff]
rcases lt_trichotomy z.re 0 with hre | hre | hre
· have : z ≠ 0 := by simp [ext_iff, hre.ne]
simp [hre.ne, hre.not_le, hre.not_lt, this]
· have : z = 0 ↔ z.im = 0 := by simp [ext_iff, hre]
simp [hre, this, or_comm, le_iff_eq_or_lt]
· simp [hre, hre.le, hre.ne']
@[simp]
theorem abs_arg_le_pi_div_two_iff {z : ℂ} : |arg z| ≤ π / 2 ↔ 0 ≤ re z := by
rw [abs_le, arg_le_pi_div_two_iff, neg_pi_div_two_le_arg_iff, ← or_and_left, ← not_le,
and_not_self_iff, or_false_iff]
#align complex.abs_arg_le_pi_div_two_iff Complex.abs_arg_le_pi_div_two_iff
@[simp]
theorem abs_arg_lt_pi_div_two_iff {z : ℂ} : |arg z| < π / 2 ↔ 0 < re z ∨ z = 0 := by
rw [abs_lt, arg_lt_pi_div_two_iff, neg_pi_div_two_lt_arg_iff, ← or_and_left]
rcases eq_or_ne z 0 with hz | hz
· simp [hz]
· simp_rw [hz, or_false, ← not_lt, not_and_self_iff, or_false]
@[simp]
theorem arg_conj_coe_angle (x : ℂ) : (arg (conj x) : Real.Angle) = -arg x := by
by_cases h : arg x = π <;> simp [arg_conj, h]
#align complex.arg_conj_coe_angle Complex.arg_conj_coe_angle
@[simp]
| Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean | 439 | 440 | theorem arg_inv_coe_angle (x : ℂ) : (arg x⁻¹ : Real.Angle) = -arg x := by |
by_cases h : arg x = π <;> simp [arg_inv, h]
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Set.Pairwise.Basic
import Mathlib.Data.Set.Lattice
import Mathlib.Data.SetLike.Basic
#align_import order.chain from "leanprover-community/mathlib"@"c227d107bbada5d0d9d20287e3282c0a7f1651a0"
/-!
# Chains and flags
This file defines chains for an arbitrary relation and flags for an order and proves Hausdorff's
Maximality Principle.
## Main declarations
* `IsChain s`: A chain `s` is a set of comparable elements.
* `maxChain_spec`: Hausdorff's Maximality Principle.
* `Flag`: The type of flags, aka maximal chains, of an order.
## Notes
Originally ported from Isabelle/HOL. The
[original file](https://isabelle.in.tum.de/dist/library/HOL/HOL/Zorn.html) was written by Jacques D.
Fleuriot, Tobias Nipkow, Christian Sternagel.
-/
open scoped Classical
open Set
variable {α β : Type*}
/-! ### Chains -/
section Chain
variable (r : α → α → Prop)
/-- In this file, we use `≺` as a local notation for any relation `r`. -/
local infixl:50 " ≺ " => r
/-- A chain is a set `s` satisfying `x ≺ y ∨ x = y ∨ y ≺ x` for all `x y ∈ s`. -/
def IsChain (s : Set α) : Prop :=
s.Pairwise fun x y => x ≺ y ∨ y ≺ x
#align is_chain IsChain
/-- `SuperChain s t` means that `t` is a chain that strictly includes `s`. -/
def SuperChain (s t : Set α) : Prop :=
IsChain r t ∧ s ⊂ t
#align super_chain SuperChain
/-- A chain `s` is a maximal chain if there does not exists a chain strictly including `s`. -/
def IsMaxChain (s : Set α) : Prop :=
IsChain r s ∧ ∀ ⦃t⦄, IsChain r t → s ⊆ t → s = t
#align is_max_chain IsMaxChain
variable {r} {c c₁ c₂ c₃ s t : Set α} {a b x y : α}
theorem isChain_empty : IsChain r ∅ :=
Set.pairwise_empty _
#align is_chain_empty isChain_empty
theorem Set.Subsingleton.isChain (hs : s.Subsingleton) : IsChain r s :=
hs.pairwise _
#align set.subsingleton.is_chain Set.Subsingleton.isChain
theorem IsChain.mono : s ⊆ t → IsChain r t → IsChain r s :=
Set.Pairwise.mono
#align is_chain.mono IsChain.mono
theorem IsChain.mono_rel {r' : α → α → Prop} (h : IsChain r s) (h_imp : ∀ x y, r x y → r' x y) :
IsChain r' s :=
h.mono' fun x y => Or.imp (h_imp x y) (h_imp y x)
#align is_chain.mono_rel IsChain.mono_rel
/-- This can be used to turn `IsChain (≥)` into `IsChain (≤)` and vice-versa. -/
theorem IsChain.symm (h : IsChain r s) : IsChain (flip r) s :=
h.mono' fun _ _ => Or.symm
#align is_chain.symm IsChain.symm
theorem isChain_of_trichotomous [IsTrichotomous α r] (s : Set α) : IsChain r s :=
fun a _ b _ hab => (trichotomous_of r a b).imp_right fun h => h.resolve_left hab
#align is_chain_of_trichotomous isChain_of_trichotomous
protected theorem IsChain.insert (hs : IsChain r s) (ha : ∀ b ∈ s, a ≠ b → a ≺ b ∨ b ≺ a) :
IsChain r (insert a s) :=
hs.insert_of_symmetric (fun _ _ => Or.symm) ha
#align is_chain.insert IsChain.insert
theorem isChain_univ_iff : IsChain r (univ : Set α) ↔ IsTrichotomous α r := by
refine ⟨fun h => ⟨fun a b => ?_⟩, fun h => @isChain_of_trichotomous _ _ h univ⟩
rw [or_left_comm, or_iff_not_imp_left]
exact h trivial trivial
#align is_chain_univ_iff isChain_univ_iff
theorem IsChain.image (r : α → α → Prop) (s : β → β → Prop) (f : α → β)
(h : ∀ x y, r x y → s (f x) (f y)) {c : Set α} (hrc : IsChain r c) : IsChain s (f '' c) :=
fun _ ⟨_, ha₁, ha₂⟩ _ ⟨_, hb₁, hb₂⟩ =>
ha₂ ▸ hb₂ ▸ fun hxy => (hrc ha₁ hb₁ <| ne_of_apply_ne f hxy).imp (h _ _) (h _ _)
#align is_chain.image IsChain.image
| Mathlib/Order/Chain.lean | 107 | 110 | theorem Monotone.isChain_range [LinearOrder α] [Preorder β] {f : α → β} (hf : Monotone f) :
IsChain (· ≤ ·) (range f) := by |
rw [← image_univ]
exact (isChain_of_trichotomous _).image (· ≤ ·) _ _ hf
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen, Antoine Labelle
-/
import Mathlib.LinearAlgebra.Contraction
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
#align_import linear_algebra.trace from "leanprover-community/mathlib"@"4cf7ca0e69e048b006674cf4499e5c7d296a89e0"
/-!
# Trace of a linear map
This file defines the trace of a linear map.
See also `LinearAlgebra/Matrix/Trace.lean` for the trace of a matrix.
## Tags
linear_map, trace, diagonal
-/
noncomputable section
universe u v w
namespace LinearMap
open Matrix
open FiniteDimensional
open TensorProduct
section
variable (R : Type u) [CommSemiring R] {M : Type v} [AddCommMonoid M] [Module R M]
variable {ι : Type w} [DecidableEq ι] [Fintype ι]
variable {κ : Type*} [DecidableEq κ] [Fintype κ]
variable (b : Basis ι R M) (c : Basis κ R M)
/-- The trace of an endomorphism given a basis. -/
def traceAux : (M →ₗ[R] M) →ₗ[R] R :=
Matrix.traceLinearMap ι R R ∘ₗ ↑(LinearMap.toMatrix b b)
#align linear_map.trace_aux LinearMap.traceAux
-- Can't be `simp` because it would cause a loop.
theorem traceAux_def (b : Basis ι R M) (f : M →ₗ[R] M) :
traceAux R b f = Matrix.trace (LinearMap.toMatrix b b f) :=
rfl
#align linear_map.trace_aux_def LinearMap.traceAux_def
theorem traceAux_eq : traceAux R b = traceAux R c :=
LinearMap.ext fun f =>
calc
Matrix.trace (LinearMap.toMatrix b b f) =
Matrix.trace (LinearMap.toMatrix b b ((LinearMap.id.comp f).comp LinearMap.id)) := by
rw [LinearMap.id_comp, LinearMap.comp_id]
_ = Matrix.trace (LinearMap.toMatrix c b LinearMap.id * LinearMap.toMatrix c c f *
LinearMap.toMatrix b c LinearMap.id) := by
rw [LinearMap.toMatrix_comp _ c, LinearMap.toMatrix_comp _ c]
_ = Matrix.trace (LinearMap.toMatrix c c f * LinearMap.toMatrix b c LinearMap.id *
LinearMap.toMatrix c b LinearMap.id) := by
rw [Matrix.mul_assoc, Matrix.trace_mul_comm]
_ = Matrix.trace (LinearMap.toMatrix c c ((f.comp LinearMap.id).comp LinearMap.id)) := by
rw [LinearMap.toMatrix_comp _ b, LinearMap.toMatrix_comp _ c]
_ = Matrix.trace (LinearMap.toMatrix c c f) := by rw [LinearMap.comp_id, LinearMap.comp_id]
#align linear_map.trace_aux_eq LinearMap.traceAux_eq
open scoped Classical
variable (M)
/-- Trace of an endomorphism independent of basis. -/
def trace : (M →ₗ[R] M) →ₗ[R] R :=
if H : ∃ s : Finset M, Nonempty (Basis s R M) then traceAux R H.choose_spec.some else 0
#align linear_map.trace LinearMap.trace
variable {M}
/-- Auxiliary lemma for `trace_eq_matrix_trace`. -/
theorem trace_eq_matrix_trace_of_finset {s : Finset M} (b : Basis s R M) (f : M →ₗ[R] M) :
trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by
have : ∃ s : Finset M, Nonempty (Basis s R M) := ⟨s, ⟨b⟩⟩
rw [trace, dif_pos this, ← traceAux_def]
congr 1
apply traceAux_eq
#align linear_map.trace_eq_matrix_trace_of_finset LinearMap.trace_eq_matrix_trace_of_finset
theorem trace_eq_matrix_trace (f : M →ₗ[R] M) :
trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by
rw [trace_eq_matrix_trace_of_finset R b.reindexFinsetRange, ← traceAux_def, ← traceAux_def,
traceAux_eq R b b.reindexFinsetRange]
#align linear_map.trace_eq_matrix_trace LinearMap.trace_eq_matrix_trace
theorem trace_mul_comm (f g : M →ₗ[R] M) : trace R M (f * g) = trace R M (g * f) :=
if H : ∃ s : Finset M, Nonempty (Basis s R M) then by
let ⟨s, ⟨b⟩⟩ := H
simp_rw [trace_eq_matrix_trace R b, LinearMap.toMatrix_mul]
apply Matrix.trace_mul_comm
else by rw [trace, dif_neg H, LinearMap.zero_apply, LinearMap.zero_apply]
#align linear_map.trace_mul_comm LinearMap.trace_mul_comm
lemma trace_mul_cycle (f g h : M →ₗ[R] M) :
trace R M (f * g * h) = trace R M (h * f * g) := by
rw [LinearMap.trace_mul_comm, ← mul_assoc]
lemma trace_mul_cycle' (f g h : M →ₗ[R] M) :
trace R M (f * (g * h)) = trace R M (h * (f * g)) := by
rw [← mul_assoc, LinearMap.trace_mul_comm]
/-- The trace of an endomorphism is invariant under conjugation -/
@[simp]
theorem trace_conj (g : M →ₗ[R] M) (f : (M →ₗ[R] M)ˣ) :
trace R M (↑f * g * ↑f⁻¹) = trace R M g := by
rw [trace_mul_comm]
simp
#align linear_map.trace_conj LinearMap.trace_conj
@[simp]
lemma trace_lie {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (f g : Module.End R M) :
trace R M ⁅f, g⁆ = 0 := by
rw [Ring.lie_def, map_sub, trace_mul_comm]
exact sub_self _
end
section
variable {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M]
variable (N P : Type*) [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P]
variable {ι : Type*}
/-- The trace of a linear map correspond to the contraction pairing under the isomorphism
`End(M) ≃ M* ⊗ M`-/
theorem trace_eq_contract_of_basis [Finite ι] (b : Basis ι R M) :
LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M := by
classical
cases nonempty_fintype ι
apply Basis.ext (Basis.tensorProduct (Basis.dualBasis b) b)
rintro ⟨i, j⟩
simp only [Function.comp_apply, Basis.tensorProduct_apply, Basis.coe_dualBasis, coe_comp]
rw [trace_eq_matrix_trace R b, toMatrix_dualTensorHom]
by_cases hij : i = j
· rw [hij]
simp
rw [Matrix.StdBasisMatrix.trace_zero j i (1 : R) hij]
simp [Finsupp.single_eq_pi_single, hij]
#align linear_map.trace_eq_contract_of_basis LinearMap.trace_eq_contract_of_basis
/-- The trace of a linear map correspond to the contraction pairing under the isomorphism
`End(M) ≃ M* ⊗ M`-/
theorem trace_eq_contract_of_basis' [Fintype ι] [DecidableEq ι] (b : Basis ι R M) :
LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquivOfBasis b).symm.toLinearMap := by
simp [LinearEquiv.eq_comp_toLinearMap_symm, trace_eq_contract_of_basis b]
#align linear_map.trace_eq_contract_of_basis' LinearMap.trace_eq_contract_of_basis'
variable (R M)
variable [Module.Free R M] [Module.Finite R M] [Module.Free R N] [Module.Finite R N]
[Module.Free R P] [Module.Finite R P]
/-- When `M` is finite free, the trace of a linear map correspond to the contraction pairing under
the isomorphism `End(M) ≃ M* ⊗ M`-/
@[simp]
theorem trace_eq_contract : LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M :=
trace_eq_contract_of_basis (Module.Free.chooseBasis R M)
#align linear_map.trace_eq_contract LinearMap.trace_eq_contract
@[simp]
theorem trace_eq_contract_apply (x : Module.Dual R M ⊗[R] M) :
(LinearMap.trace R M) ((dualTensorHom R M M) x) = contractLeft R M x := by
rw [← comp_apply, trace_eq_contract]
#align linear_map.trace_eq_contract_apply LinearMap.trace_eq_contract_apply
/-- When `M` is finite free, the trace of a linear map correspond to the contraction pairing under
the isomorphism `End(M) ≃ M* ⊗ M`-/
theorem trace_eq_contract' :
LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquiv R M M).symm.toLinearMap :=
trace_eq_contract_of_basis' (Module.Free.chooseBasis R M)
#align linear_map.trace_eq_contract' LinearMap.trace_eq_contract'
/-- The trace of the identity endomorphism is the dimension of the free module -/
@[simp]
| Mathlib/LinearAlgebra/Trace.lean | 186 | 191 | theorem trace_one : trace R M 1 = (finrank R M : R) := by |
cases subsingleton_or_nontrivial R
· simp [eq_iff_true_of_subsingleton]
have b := Module.Free.chooseBasis R M
rw [trace_eq_matrix_trace R b, toMatrix_one, finrank_eq_card_chooseBasisIndex]
simp
|
/-
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, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.Deriv.Inv
#align_import analysis.calculus.deriv.zpow from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe"
/-!
# Derivatives of `x ^ m`, `m : ℤ`
In this file we prove theorems about (iterated) derivatives of `x ^ m`, `m : ℤ`.
For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of
`analysis/calculus/deriv/basic`.
## Keywords
derivative, power
-/
universe u v w
open scoped Classical
open Topology Filter
open Filter Asymptotics Set
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜]
variable {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {x : 𝕜}
variable {s : Set 𝕜}
variable {m : ℤ}
/-! ### Derivative of `x ↦ x^m` for `m : ℤ` -/
theorem hasStrictDerivAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
HasStrictDerivAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) x := by
have : ∀ m : ℤ, 0 < m → HasStrictDerivAt (· ^ m) ((m : 𝕜) * x ^ (m - 1)) x := fun m hm ↦ by
lift m to ℕ using hm.le
simp only [zpow_natCast, Int.cast_natCast]
convert hasStrictDerivAt_pow m x using 2
rw [← Int.ofNat_one, ← Int.ofNat_sub, zpow_natCast]
norm_cast at hm
rcases lt_trichotomy m 0 with (hm | hm | hm)
· have hx : x ≠ 0 := h.resolve_right hm.not_le
have := (hasStrictDerivAt_inv ?_).scomp _ (this (-m) (neg_pos.2 hm)) <;>
[skip; exact zpow_ne_zero _ hx]
simp only [(· ∘ ·), zpow_neg, one_div, inv_inv, smul_eq_mul] at this
convert this using 1
rw [sq, mul_inv, inv_inv, Int.cast_neg, neg_mul, neg_mul_neg, ← zpow_add₀ hx, mul_assoc, ←
zpow_add₀ hx]
congr
abel
· simp only [hm, zpow_zero, Int.cast_zero, zero_mul, hasStrictDerivAt_const]
· exact this m hm
#align has_strict_deriv_at_zpow hasStrictDerivAt_zpow
theorem hasDerivAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
HasDerivAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) x :=
(hasStrictDerivAt_zpow m x h).hasDerivAt
#align has_deriv_at_zpow hasDerivAt_zpow
theorem hasDerivWithinAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) (s : Set 𝕜) :
HasDerivWithinAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) s x :=
(hasDerivAt_zpow m x h).hasDerivWithinAt
#align has_deriv_within_at_zpow hasDerivWithinAt_zpow
theorem differentiableAt_zpow : DifferentiableAt 𝕜 (fun x => x ^ m) x ↔ x ≠ 0 ∨ 0 ≤ m :=
⟨fun H => NormedField.continuousAt_zpow.1 H.continuousAt, fun H =>
(hasDerivAt_zpow m x H).differentiableAt⟩
#align differentiable_at_zpow differentiableAt_zpow
theorem differentiableWithinAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
DifferentiableWithinAt 𝕜 (fun x => x ^ m) s x :=
(differentiableAt_zpow.mpr h).differentiableWithinAt
#align differentiable_within_at_zpow differentiableWithinAt_zpow
theorem differentiableOn_zpow (m : ℤ) (s : Set 𝕜) (h : (0 : 𝕜) ∉ s ∨ 0 ≤ m) :
DifferentiableOn 𝕜 (fun x => x ^ m) s := fun x hxs =>
differentiableWithinAt_zpow m x <| h.imp_left <| ne_of_mem_of_not_mem hxs
#align differentiable_on_zpow differentiableOn_zpow
theorem deriv_zpow (m : ℤ) (x : 𝕜) : deriv (fun x => x ^ m) x = m * x ^ (m - 1) := by
by_cases H : x ≠ 0 ∨ 0 ≤ m
· exact (hasDerivAt_zpow m x H).deriv
· rw [deriv_zero_of_not_differentiableAt (mt differentiableAt_zpow.1 H)]
push_neg at H
rcases H with ⟨rfl, hm⟩
rw [zero_zpow _ ((sub_one_lt _).trans hm).ne, mul_zero]
#align deriv_zpow deriv_zpow
@[simp]
theorem deriv_zpow' (m : ℤ) : (deriv fun x : 𝕜 => x ^ m) = fun x => (m : 𝕜) * x ^ (m - 1) :=
funext <| deriv_zpow m
#align deriv_zpow' deriv_zpow'
theorem derivWithin_zpow (hxs : UniqueDiffWithinAt 𝕜 s x) (h : x ≠ 0 ∨ 0 ≤ m) :
derivWithin (fun x => x ^ m) s x = (m : 𝕜) * x ^ (m - 1) :=
(hasDerivWithinAt_zpow m x h s).derivWithin hxs
#align deriv_within_zpow derivWithin_zpow
@[simp]
theorem iter_deriv_zpow' (m : ℤ) (k : ℕ) :
(deriv^[k] fun x : 𝕜 => x ^ m) =
fun x => (∏ i ∈ Finset.range k, ((m : 𝕜) - i)) * x ^ (m - k) := by
induction' k with k ihk
· simp only [Nat.zero_eq, one_mul, Int.ofNat_zero, id, sub_zero, Finset.prod_range_zero,
Function.iterate_zero]
· simp only [Function.iterate_succ_apply', ihk, deriv_const_mul_field', deriv_zpow',
Finset.prod_range_succ, Int.ofNat_succ, ← sub_sub, Int.cast_sub, Int.cast_natCast, mul_assoc]
#align iter_deriv_zpow' iter_deriv_zpow'
theorem iter_deriv_zpow (m : ℤ) (x : 𝕜) (k : ℕ) :
deriv^[k] (fun y => y ^ m) x = (∏ i ∈ Finset.range k, ((m : 𝕜) - i)) * x ^ (m - k) :=
congr_fun (iter_deriv_zpow' m k) x
#align iter_deriv_zpow iter_deriv_zpow
theorem iter_deriv_pow (n : ℕ) (x : 𝕜) (k : ℕ) :
deriv^[k] (fun x : 𝕜 => x ^ n) x = (∏ i ∈ Finset.range k, ((n : 𝕜) - i)) * x ^ (n - k) := by
simp only [← zpow_natCast, iter_deriv_zpow, Int.cast_natCast]
rcases le_or_lt k n with hkn | hnk
· rw [Int.ofNat_sub hkn]
· have : (∏ i ∈ Finset.range k, (n - i : 𝕜)) = 0 :=
Finset.prod_eq_zero (Finset.mem_range.2 hnk) (sub_self _)
simp only [this, zero_mul]
#align iter_deriv_pow iter_deriv_pow
@[simp]
theorem iter_deriv_pow' (n k : ℕ) :
(deriv^[k] fun x : 𝕜 => x ^ n) =
fun x => (∏ i ∈ Finset.range k, ((n : 𝕜) - i)) * x ^ (n - k) :=
funext fun x => iter_deriv_pow n x k
#align iter_deriv_pow' iter_deriv_pow'
| Mathlib/Analysis/Calculus/Deriv/ZPow.lean | 138 | 140 | theorem iter_deriv_inv (k : ℕ) (x : 𝕜) :
deriv^[k] Inv.inv x = (∏ i ∈ Finset.range k, (-1 - i : 𝕜)) * x ^ (-1 - k : ℤ) := by |
simpa only [zpow_neg_one, Int.cast_neg, Int.cast_one] using iter_deriv_zpow (-1) x k
|
/-
Copyright (c) 2022 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Order.Filter.Cofinite
#align_import topology.bornology.basic from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1"
/-!
# Basic theory of bornology
We develop the basic theory of bornologies. Instead of axiomatizing bounded sets and defining
bornologies in terms of those, we recognize that the cobounded sets form a filter and define a
bornology as a filter of cobounded sets which contains the cofinite filter. This allows us to make
use of the extensive library for filters, but we also provide the relevant connecting results for
bounded sets.
The specification of a bornology in terms of the cobounded filter is equivalent to the standard
one (e.g., see [Bourbaki, *Topological Vector Spaces*][bourbaki1987], **covering bornology**, now
often called simply **bornology**) in terms of bounded sets (see `Bornology.ofBounded`,
`IsBounded.union`, `IsBounded.subset`), except that we do not allow the empty bornology (that is,
we require that *some* set must be bounded; equivalently, `∅` is bounded). In the literature the
cobounded filter is generally referred to as the *filter at infinity*.
## Main definitions
- `Bornology α`: a class consisting of `cobounded : Filter α` and a proof that this filter
contains the `cofinite` filter.
- `Bornology.IsCobounded`: the predicate that a set is a member of the `cobounded α` filter. For
`s : Set α`, one should prefer `Bornology.IsCobounded s` over `s ∈ cobounded α`.
- `bornology.IsBounded`: the predicate that states a set is bounded (i.e., the complement of a
cobounded set). One should prefer `Bornology.IsBounded s` over `sᶜ ∈ cobounded α`.
- `BoundedSpace α`: a class extending `Bornology α` with the condition
`Bornology.IsBounded (Set.univ : Set α)`
Although use of `cobounded α` is discouraged for indicating the (co)boundedness of individual sets,
it is intended for regular use as a filter on `α`.
-/
open Set Filter
variable {ι α β : Type*}
/-- A **bornology** on a type `α` is a filter of cobounded sets which contains the cofinite filter.
Such spaces are equivalently specified by their bounded sets, see `Bornology.ofBounded`
and `Bornology.ext_iff_isBounded`-/
class Bornology (α : Type*) where
/-- The filter of cobounded sets in a bornology. This is a field of the structure, but one
should always prefer `Bornology.cobounded` because it makes the `α` argument explicit. -/
cobounded' : Filter α
/-- The cobounded filter in a bornology is smaller than the cofinite filter. This is a field of
the structure, but one should always prefer `Bornology.le_cofinite` because it makes the `α`
argument explicit. -/
le_cofinite' : cobounded' ≤ cofinite
#align bornology Bornology
/- porting note: Because Lean 4 doesn't accept the `[]` syntax to make arguments of structure
fields explicit, we have to define these separately, prove the `ext` lemmas manually, and
initialize new `simps` projections. -/
/-- The filter of cobounded sets in a bornology. -/
def Bornology.cobounded (α : Type*) [Bornology α] : Filter α := Bornology.cobounded'
#align bornology.cobounded Bornology.cobounded
alias Bornology.Simps.cobounded := Bornology.cobounded
lemma Bornology.le_cofinite (α : Type*) [Bornology α] : cobounded α ≤ cofinite :=
Bornology.le_cofinite'
#align bornology.le_cofinite Bornology.le_cofinite
initialize_simps_projections Bornology (cobounded' → cobounded)
@[ext]
lemma Bornology.ext (t t' : Bornology α)
(h_cobounded : @Bornology.cobounded α t = @Bornology.cobounded α t') :
t = t' := by
cases t
cases t'
congr
#align bornology.ext Bornology.ext
lemma Bornology.ext_iff (t t' : Bornology α) :
t = t' ↔ @Bornology.cobounded α t = @Bornology.cobounded α t' :=
⟨congrArg _, Bornology.ext _ _⟩
#align bornology.ext_iff Bornology.ext_iff
/-- A constructor for bornologies by specifying the bounded sets,
and showing that they satisfy the appropriate conditions. -/
@[simps]
def Bornology.ofBounded {α : Type*} (B : Set (Set α))
(empty_mem : ∅ ∈ B)
(subset_mem : ∀ s₁ ∈ B, ∀ s₂ ⊆ s₁, s₂ ∈ B)
(union_mem : ∀ s₁ ∈ B, ∀ s₂ ∈ B, s₁ ∪ s₂ ∈ B)
(singleton_mem : ∀ x, {x} ∈ B) : Bornology α where
cobounded' := comk (· ∈ B) empty_mem subset_mem union_mem
le_cofinite' := by simpa [le_cofinite_iff_compl_singleton_mem]
#align bornology.of_bounded Bornology.ofBounded
#align bornology.of_bounded_cobounded_sets Bornology.ofBounded_cobounded
/-- A constructor for bornologies by specifying the bounded sets,
and showing that they satisfy the appropriate conditions. -/
@[simps! cobounded]
def Bornology.ofBounded' {α : Type*} (B : Set (Set α))
(empty_mem : ∅ ∈ B)
(subset_mem : ∀ s₁ ∈ B, ∀ s₂ ⊆ s₁, s₂ ∈ B)
(union_mem : ∀ s₁ ∈ B, ∀ s₂ ∈ B, s₁ ∪ s₂ ∈ B)
(sUnion_univ : ⋃₀ B = univ) :
Bornology α :=
Bornology.ofBounded B empty_mem subset_mem union_mem fun x => by
rw [sUnion_eq_univ_iff] at sUnion_univ
rcases sUnion_univ x with ⟨s, hs, hxs⟩
exact subset_mem s hs {x} (singleton_subset_iff.mpr hxs)
#align bornology.of_bounded' Bornology.ofBounded'
#align bornology.of_bounded'_cobounded_sets Bornology.ofBounded'_cobounded
namespace Bornology
section
/-- `IsCobounded` is the predicate that `s` is in the filter of cobounded sets in the ambient
bornology on `α` -/
def IsCobounded [Bornology α] (s : Set α) : Prop :=
s ∈ cobounded α
#align bornology.is_cobounded Bornology.IsCobounded
/-- `IsBounded` is the predicate that `s` is bounded relative to the ambient bornology on `α`. -/
def IsBounded [Bornology α] (s : Set α) : Prop :=
IsCobounded sᶜ
#align bornology.is_bounded Bornology.IsBounded
variable {_ : Bornology α} {s t : Set α} {x : α}
theorem isCobounded_def {s : Set α} : IsCobounded s ↔ s ∈ cobounded α :=
Iff.rfl
#align bornology.is_cobounded_def Bornology.isCobounded_def
theorem isBounded_def {s : Set α} : IsBounded s ↔ sᶜ ∈ cobounded α :=
Iff.rfl
#align bornology.is_bounded_def Bornology.isBounded_def
@[simp]
theorem isBounded_compl_iff : IsBounded sᶜ ↔ IsCobounded s := by
rw [isBounded_def, isCobounded_def, compl_compl]
#align bornology.is_bounded_compl_iff Bornology.isBounded_compl_iff
@[simp]
theorem isCobounded_compl_iff : IsCobounded sᶜ ↔ IsBounded s :=
Iff.rfl
#align bornology.is_cobounded_compl_iff Bornology.isCobounded_compl_iff
alias ⟨IsBounded.of_compl, IsCobounded.compl⟩ := isBounded_compl_iff
#align bornology.is_bounded.of_compl Bornology.IsBounded.of_compl
#align bornology.is_cobounded.compl Bornology.IsCobounded.compl
alias ⟨IsCobounded.of_compl, IsBounded.compl⟩ := isCobounded_compl_iff
#align bornology.is_cobounded.of_compl Bornology.IsCobounded.of_compl
#align bornology.is_bounded.compl Bornology.IsBounded.compl
@[simp]
theorem isBounded_empty : IsBounded (∅ : Set α) := by
rw [isBounded_def, compl_empty]
exact univ_mem
#align bornology.is_bounded_empty Bornology.isBounded_empty
theorem nonempty_of_not_isBounded (h : ¬IsBounded s) : s.Nonempty := by
rw [nonempty_iff_ne_empty]
rintro rfl
exact h isBounded_empty
#align metric.nonempty_of_unbounded Bornology.nonempty_of_not_isBounded
@[simp]
theorem isBounded_singleton : IsBounded ({x} : Set α) := by
rw [isBounded_def]
exact le_cofinite _ (finite_singleton x).compl_mem_cofinite
#align bornology.is_bounded_singleton Bornology.isBounded_singleton
theorem isBounded_iff_forall_mem : IsBounded s ↔ ∀ x ∈ s, IsBounded s :=
⟨fun h _ _ ↦ h, fun h ↦ by
rcases s.eq_empty_or_nonempty with rfl | ⟨x, hx⟩
exacts [isBounded_empty, h x hx]⟩
@[simp]
theorem isCobounded_univ : IsCobounded (univ : Set α) :=
univ_mem
#align bornology.is_cobounded_univ Bornology.isCobounded_univ
@[simp]
theorem isCobounded_inter : IsCobounded (s ∩ t) ↔ IsCobounded s ∧ IsCobounded t :=
inter_mem_iff
#align bornology.is_cobounded_inter Bornology.isCobounded_inter
theorem IsCobounded.inter (hs : IsCobounded s) (ht : IsCobounded t) : IsCobounded (s ∩ t) :=
isCobounded_inter.2 ⟨hs, ht⟩
#align bornology.is_cobounded.inter Bornology.IsCobounded.inter
@[simp]
theorem isBounded_union : IsBounded (s ∪ t) ↔ IsBounded s ∧ IsBounded t := by
simp only [← isCobounded_compl_iff, compl_union, isCobounded_inter]
#align bornology.is_bounded_union Bornology.isBounded_union
theorem IsBounded.union (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s ∪ t) :=
isBounded_union.2 ⟨hs, ht⟩
#align bornology.is_bounded.union Bornology.IsBounded.union
theorem IsCobounded.superset (hs : IsCobounded s) (ht : s ⊆ t) : IsCobounded t :=
mem_of_superset hs ht
#align bornology.is_cobounded.superset Bornology.IsCobounded.superset
theorem IsBounded.subset (ht : IsBounded t) (hs : s ⊆ t) : IsBounded s :=
ht.superset (compl_subset_compl.mpr hs)
#align bornology.is_bounded.subset Bornology.IsBounded.subset
@[simp]
theorem sUnion_bounded_univ : ⋃₀ { s : Set α | IsBounded s } = univ :=
sUnion_eq_univ_iff.2 fun a => ⟨{a}, isBounded_singleton, mem_singleton a⟩
#align bornology.sUnion_bounded_univ Bornology.sUnion_bounded_univ
theorem IsBounded.insert (h : IsBounded s) (x : α) : IsBounded (insert x s) :=
isBounded_singleton.union h
@[simp]
theorem isBounded_insert : IsBounded (insert x s) ↔ IsBounded s :=
⟨fun h ↦ h.subset (subset_insert _ _), (.insert · x)⟩
theorem comap_cobounded_le_iff [Bornology β] {f : α → β} :
(cobounded β).comap f ≤ cobounded α ↔ ∀ ⦃s⦄, IsBounded s → IsBounded (f '' s) := by
refine
⟨fun h s hs => ?_, fun h t ht =>
⟨(f '' tᶜ)ᶜ, h <| IsCobounded.compl ht, compl_subset_comm.1 <| subset_preimage_image _ _⟩⟩
obtain ⟨t, ht, hts⟩ := h hs.compl
rw [subset_compl_comm, ← preimage_compl] at hts
exact (IsCobounded.compl ht).subset ((image_subset f hts).trans <| image_preimage_subset _ _)
#align bornology.comap_cobounded_le_iff Bornology.comap_cobounded_le_iff
end
theorem ext_iff' {t t' : Bornology α} :
t = t' ↔ ∀ s, s ∈ @cobounded α t ↔ s ∈ @cobounded α t' :=
(Bornology.ext_iff _ _).trans Filter.ext_iff
#align bornology.ext_iff' Bornology.ext_iff'
theorem ext_iff_isBounded {t t' : Bornology α} :
t = t' ↔ ∀ s, @IsBounded α t s ↔ @IsBounded α t' s :=
ext_iff'.trans compl_surjective.forall
#align bornology.ext_iff_is_bounded Bornology.ext_iff_isBounded
variable {s : Set α}
theorem isCobounded_ofBounded_iff (B : Set (Set α)) {empty_mem subset_mem union_mem sUnion_univ} :
@IsCobounded _ (ofBounded B empty_mem subset_mem union_mem sUnion_univ) s ↔ sᶜ ∈ B :=
Iff.rfl
#align bornology.is_cobounded_of_bounded_iff Bornology.isCobounded_ofBounded_iff
theorem isBounded_ofBounded_iff (B : Set (Set α)) {empty_mem subset_mem union_mem sUnion_univ} :
@IsBounded _ (ofBounded B empty_mem subset_mem union_mem sUnion_univ) s ↔ s ∈ B := by
rw [isBounded_def, ofBounded_cobounded, compl_mem_comk]
#align bornology.is_bounded_of_bounded_iff Bornology.isBounded_ofBounded_iff
variable [Bornology α]
theorem isCobounded_biInter {s : Set ι} {f : ι → Set α} (hs : s.Finite) :
IsCobounded (⋂ i ∈ s, f i) ↔ ∀ i ∈ s, IsCobounded (f i) :=
biInter_mem hs
#align bornology.is_cobounded_bInter Bornology.isCobounded_biInter
@[simp]
theorem isCobounded_biInter_finset (s : Finset ι) {f : ι → Set α} :
IsCobounded (⋂ i ∈ s, f i) ↔ ∀ i ∈ s, IsCobounded (f i) :=
biInter_finset_mem s
#align bornology.is_cobounded_bInter_finset Bornology.isCobounded_biInter_finset
@[simp]
theorem isCobounded_iInter [Finite ι] {f : ι → Set α} :
IsCobounded (⋂ i, f i) ↔ ∀ i, IsCobounded (f i) :=
iInter_mem
#align bornology.is_cobounded_Inter Bornology.isCobounded_iInter
theorem isCobounded_sInter {S : Set (Set α)} (hs : S.Finite) :
IsCobounded (⋂₀ S) ↔ ∀ s ∈ S, IsCobounded s :=
sInter_mem hs
#align bornology.is_cobounded_sInter Bornology.isCobounded_sInter
theorem isBounded_biUnion {s : Set ι} {f : ι → Set α} (hs : s.Finite) :
IsBounded (⋃ i ∈ s, f i) ↔ ∀ i ∈ s, IsBounded (f i) := by
simp only [← isCobounded_compl_iff, compl_iUnion, isCobounded_biInter hs]
#align bornology.is_bounded_bUnion Bornology.isBounded_biUnion
theorem isBounded_biUnion_finset (s : Finset ι) {f : ι → Set α} :
IsBounded (⋃ i ∈ s, f i) ↔ ∀ i ∈ s, IsBounded (f i) :=
isBounded_biUnion s.finite_toSet
#align bornology.is_bounded_bUnion_finset Bornology.isBounded_biUnion_finset
| Mathlib/Topology/Bornology/Basic.lean | 294 | 295 | theorem isBounded_sUnion {S : Set (Set α)} (hs : S.Finite) :
IsBounded (⋃₀ S) ↔ ∀ s ∈ S, IsBounded s := by | rw [sUnion_eq_biUnion, isBounded_biUnion hs]
|
/-
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.DoldKan.Normalized
#align_import algebraic_topology.dold_kan.homotopy_equivalence from "leanprover-community/mathlib"@"f951e201d416fb50cc7826171d80aa510ec20747"
/-!
# The normalized Moore complex and the alternating face map complex are homotopy equivalent
In this file, when the category `A` is abelian, we obtain the homotopy equivalence
`homotopyEquivNormalizedMooreComplexAlternatingFaceMapComplex` between the
normalized Moore complex and the alternating face map complex of a simplicial object in `A`.
-/
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits
CategoryTheory.Preadditive Simplicial DoldKan
noncomputable section
namespace AlgebraicTopology
namespace DoldKan
variable {C : Type*} [Category C] [Preadditive C] (X : SimplicialObject C)
/-- Inductive construction of homotopies from `P q` to `𝟙 _` -/
noncomputable def homotopyPToId : ∀ q : ℕ, Homotopy (P q : K[X] ⟶ _) (𝟙 _)
| 0 => Homotopy.refl _
| q + 1 => by
refine
Homotopy.trans (Homotopy.ofEq ?_)
(Homotopy.trans
(Homotopy.add (homotopyPToId q) (Homotopy.compLeft (homotopyHσToZero q) (P q)))
(Homotopy.ofEq ?_))
· simp only [P_succ, comp_add, comp_id]
· simp only [add_zero, comp_zero]
set_option linter.uppercaseLean3 false in
#align algebraic_topology.dold_kan.homotopy_P_to_id AlgebraicTopology.DoldKan.homotopyPToId
/-- The complement projection `Q q` to `P q` is homotopic to zero. -/
def homotopyQToZero (q : ℕ) : Homotopy (Q q : K[X] ⟶ _) 0 :=
Homotopy.equivSubZero.toFun (homotopyPToId X q).symm
set_option linter.uppercaseLean3 false in
#align algebraic_topology.dold_kan.homotopy_Q_to_zero AlgebraicTopology.DoldKan.homotopyQToZero
| Mathlib/AlgebraicTopology/DoldKan/HomotopyEquivalence.lean | 52 | 58 | theorem homotopyPToId_eventually_constant {q n : ℕ} (hqn : n < q) :
((homotopyPToId X (q + 1)).hom n (n + 1) : X _[n] ⟶ X _[n + 1]) =
(homotopyPToId X q).hom n (n + 1) := by |
simp only [homotopyHσToZero, AlternatingFaceMapComplex.obj_X, Nat.add_eq, Homotopy.trans_hom,
Homotopy.ofEq_hom, Pi.zero_apply, Homotopy.add_hom, Homotopy.compLeft_hom, add_zero,
Homotopy.nullHomotopy'_hom, ComplexShape.down_Rel, hσ'_eq_zero hqn (c_mk (n + 1) n rfl),
dite_eq_ite, ite_self, comp_zero, zero_add, homotopyPToId]
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Algebra.Equiv
import Mathlib.LinearAlgebra.Dimension.StrongRankCondition
import Mathlib.LinearAlgebra.FreeModule.Basic
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.SetTheory.Cardinal.Ordinal
#align_import algebra.quaternion from "leanprover-community/mathlib"@"cf7a7252c1989efe5800e0b3cdfeb4228ac6b40e"
/-!
# Quaternions
In this file we define quaternions `ℍ[R]` over a commutative ring `R`, and define some
algebraic structures on `ℍ[R]`.
## Main definitions
* `QuaternionAlgebra R a b`, `ℍ[R, a, b]` :
[quaternion algebra](https://en.wikipedia.org/wiki/Quaternion_algebra) with coefficients `a`, `b`
* `Quaternion R`, `ℍ[R]` : the space of quaternions, a.k.a. `QuaternionAlgebra R (-1) (-1)`;
* `Quaternion.normSq` : square of the norm of a quaternion;
We also define the following algebraic structures on `ℍ[R]`:
* `Ring ℍ[R, a, b]`, `StarRing ℍ[R, a, b]`, and `Algebra R ℍ[R, a, b]` : for any commutative ring
`R`;
* `Ring ℍ[R]`, `StarRing ℍ[R]`, and `Algebra R ℍ[R]` : for any commutative ring `R`;
* `IsDomain ℍ[R]` : for a linear ordered commutative ring `R`;
* `DivisionRing ℍ[R]` : for a linear ordered field `R`.
## Notation
The following notation is available with `open Quaternion` or `open scoped Quaternion`.
* `ℍ[R, c₁, c₂]` : `QuaternionAlgebra R c₁ c₂`
* `ℍ[R]` : quaternions over `R`.
## Implementation notes
We define quaternions over any ring `R`, not just `ℝ` to be able to deal with, e.g., integer
or rational quaternions without using real numbers. In particular, all definitions in this file
are computable.
## Tags
quaternion
-/
/-- Quaternion algebra over a type with fixed coefficients $a=i^2$ and $b=j^2$.
Implemented as a structure with four fields: `re`, `imI`, `imJ`, and `imK`. -/
@[ext]
structure QuaternionAlgebra (R : Type*) (a b : R) where
/-- Real part of a quaternion. -/
re : R
imI : R
imJ : R
imK : R
#align quaternion_algebra QuaternionAlgebra
#align quaternion_algebra.re QuaternionAlgebra.re
#align quaternion_algebra.im_i QuaternionAlgebra.imI
#align quaternion_algebra.im_j QuaternionAlgebra.imJ
#align quaternion_algebra.im_k QuaternionAlgebra.imK
@[inherit_doc]
scoped[Quaternion] notation "ℍ[" R "," a "," b "]" => QuaternionAlgebra R a b
open Quaternion
namespace QuaternionAlgebra
/-- The equivalence between a quaternion algebra over `R` and `R × R × R × R`. -/
@[simps]
def equivProd {R : Type*} (c₁ c₂ : R) : ℍ[R,c₁,c₂] ≃ R × R × R × R where
toFun a := ⟨a.1, a.2, a.3, a.4⟩
invFun a := ⟨a.1, a.2.1, a.2.2.1, a.2.2.2⟩
left_inv _ := rfl
right_inv _ := rfl
#align quaternion_algebra.equiv_prod QuaternionAlgebra.equivProd
/-- The equivalence between a quaternion algebra over `R` and `Fin 4 → R`. -/
@[simps symm_apply]
def equivTuple {R : Type*} (c₁ c₂ : R) : ℍ[R,c₁,c₂] ≃ (Fin 4 → R) where
toFun a := ![a.1, a.2, a.3, a.4]
invFun a := ⟨a 0, a 1, a 2, a 3⟩
left_inv _ := rfl
right_inv f := by ext ⟨_, _ | _ | _ | _ | _ | ⟨⟩⟩ <;> rfl
#align quaternion_algebra.equiv_tuple QuaternionAlgebra.equivTuple
@[simp]
theorem equivTuple_apply {R : Type*} (c₁ c₂ : R) (x : ℍ[R,c₁,c₂]) :
equivTuple c₁ c₂ x = ![x.re, x.imI, x.imJ, x.imK] :=
rfl
#align quaternion_algebra.equiv_tuple_apply QuaternionAlgebra.equivTuple_apply
@[simp]
theorem mk.eta {R : Type*} {c₁ c₂} (a : ℍ[R,c₁,c₂]) : mk a.1 a.2 a.3 a.4 = a := rfl
#align quaternion_algebra.mk.eta QuaternionAlgebra.mk.eta
variable {S T R : Type*} [CommRing R] {c₁ c₂ : R} (r x y z : R) (a b c : ℍ[R,c₁,c₂])
instance [Subsingleton R] : Subsingleton ℍ[R, c₁, c₂] := (equivTuple c₁ c₂).subsingleton
instance [Nontrivial R] : Nontrivial ℍ[R, c₁, c₂] := (equivTuple c₁ c₂).surjective.nontrivial
/-- The imaginary part of a quaternion. -/
def im (x : ℍ[R,c₁,c₂]) : ℍ[R,c₁,c₂] :=
⟨0, x.imI, x.imJ, x.imK⟩
#align quaternion_algebra.im QuaternionAlgebra.im
@[simp]
theorem im_re : a.im.re = 0 :=
rfl
#align quaternion_algebra.im_re QuaternionAlgebra.im_re
@[simp]
theorem im_imI : a.im.imI = a.imI :=
rfl
#align quaternion_algebra.im_im_i QuaternionAlgebra.im_imI
@[simp]
theorem im_imJ : a.im.imJ = a.imJ :=
rfl
#align quaternion_algebra.im_im_j QuaternionAlgebra.im_imJ
@[simp]
theorem im_imK : a.im.imK = a.imK :=
rfl
#align quaternion_algebra.im_im_k QuaternionAlgebra.im_imK
@[simp]
theorem im_idem : a.im.im = a.im :=
rfl
#align quaternion_algebra.im_idem QuaternionAlgebra.im_idem
/-- Coercion `R → ℍ[R,c₁,c₂]`. -/
@[coe] def coe (x : R) : ℍ[R,c₁,c₂] := ⟨x, 0, 0, 0⟩
instance : CoeTC R ℍ[R,c₁,c₂] := ⟨coe⟩
@[simp, norm_cast]
theorem coe_re : (x : ℍ[R,c₁,c₂]).re = x := rfl
#align quaternion_algebra.coe_re QuaternionAlgebra.coe_re
@[simp, norm_cast]
theorem coe_imI : (x : ℍ[R,c₁,c₂]).imI = 0 := rfl
#align quaternion_algebra.coe_im_i QuaternionAlgebra.coe_imI
@[simp, norm_cast]
theorem coe_imJ : (x : ℍ[R,c₁,c₂]).imJ = 0 := rfl
#align quaternion_algebra.coe_im_j QuaternionAlgebra.coe_imJ
@[simp, norm_cast]
theorem coe_imK : (x : ℍ[R,c₁,c₂]).imK = 0 := rfl
#align quaternion_algebra.coe_im_k QuaternionAlgebra.coe_imK
theorem coe_injective : Function.Injective (coe : R → ℍ[R,c₁,c₂]) := fun _ _ h => congr_arg re h
#align quaternion_algebra.coe_injective QuaternionAlgebra.coe_injective
@[simp]
theorem coe_inj {x y : R} : (x : ℍ[R,c₁,c₂]) = y ↔ x = y :=
coe_injective.eq_iff
#align quaternion_algebra.coe_inj QuaternionAlgebra.coe_inj
-- Porting note: removed `simps`, added simp lemmas manually
instance : Zero ℍ[R,c₁,c₂] := ⟨⟨0, 0, 0, 0⟩⟩
@[simp] theorem zero_re : (0 : ℍ[R,c₁,c₂]).re = 0 := rfl
#align quaternion_algebra.has_zero_zero_re QuaternionAlgebra.zero_re
@[simp] theorem zero_imI : (0 : ℍ[R,c₁,c₂]).imI = 0 := rfl
#align quaternion_algebra.has_zero_zero_im_i QuaternionAlgebra.zero_imI
@[simp] theorem zero_imJ : (0 : ℍ[R,c₁,c₂]).imJ = 0 := rfl
#align quaternion_algebra.zero_zero_im_j QuaternionAlgebra.zero_imJ
@[simp] theorem zero_imK : (0 : ℍ[R,c₁,c₂]).imK = 0 := rfl
#align quaternion_algebra.zero_zero_im_k QuaternionAlgebra.zero_imK
@[simp] theorem zero_im : (0 : ℍ[R,c₁,c₂]).im = 0 := rfl
@[simp, norm_cast]
theorem coe_zero : ((0 : R) : ℍ[R,c₁,c₂]) = 0 := rfl
#align quaternion_algebra.coe_zero QuaternionAlgebra.coe_zero
instance : Inhabited ℍ[R,c₁,c₂] := ⟨0⟩
-- Porting note: removed `simps`, added simp lemmas manually
instance : One ℍ[R,c₁,c₂] := ⟨⟨1, 0, 0, 0⟩⟩
@[simp] theorem one_re : (1 : ℍ[R,c₁,c₂]).re = 1 := rfl
#align quaternion_algebra.has_one_one_re QuaternionAlgebra.one_re
@[simp] theorem one_imI : (1 : ℍ[R,c₁,c₂]).imI = 0 := rfl
#align quaternion_algebra.has_one_one_im_i QuaternionAlgebra.one_imI
@[simp] theorem one_imJ : (1 : ℍ[R,c₁,c₂]).imJ = 0 := rfl
#align quaternion_algebra.one_one_im_j QuaternionAlgebra.one_imJ
@[simp] theorem one_imK : (1 : ℍ[R,c₁,c₂]).imK = 0 := rfl
#align quaternion_algebra.one_one_im_k QuaternionAlgebra.one_imK
@[simp] theorem one_im : (1 : ℍ[R,c₁,c₂]).im = 0 := rfl
@[simp, norm_cast]
theorem coe_one : ((1 : R) : ℍ[R,c₁,c₂]) = 1 := rfl
#align quaternion_algebra.coe_one QuaternionAlgebra.coe_one
-- Porting note: removed `simps`, added simp lemmas manually
instance : Add ℍ[R,c₁,c₂] :=
⟨fun a b => ⟨a.1 + b.1, a.2 + b.2, a.3 + b.3, a.4 + b.4⟩⟩
@[simp] theorem add_re : (a + b).re = a.re + b.re := rfl
#align quaternion_algebra.has_add_add_re QuaternionAlgebra.add_re
@[simp] theorem add_imI : (a + b).imI = a.imI + b.imI := rfl
#align quaternion_algebra.has_add_add_im_i QuaternionAlgebra.add_imI
@[simp] theorem add_imJ : (a + b).imJ = a.imJ + b.imJ := rfl
#align quaternion_algebra.has_add_add_im_j QuaternionAlgebra.add_imJ
@[simp] theorem add_imK : (a + b).imK = a.imK + b.imK := rfl
#align quaternion_algebra.has_add_add_im_k QuaternionAlgebra.add_imK
@[simp] theorem add_im : (a + b).im = a.im + b.im :=
QuaternionAlgebra.ext _ _ (zero_add _).symm rfl rfl rfl
@[simp]
theorem mk_add_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) :
(mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂]) + mk b₁ b₂ b₃ b₄ = mk (a₁ + b₁) (a₂ + b₂) (a₃ + b₃) (a₄ + b₄) :=
rfl
#align quaternion_algebra.mk_add_mk QuaternionAlgebra.mk_add_mk
@[simp, norm_cast]
theorem coe_add : ((x + y : R) : ℍ[R,c₁,c₂]) = x + y := by ext <;> simp
#align quaternion_algebra.coe_add QuaternionAlgebra.coe_add
-- Porting note: removed `simps`, added simp lemmas manually
instance : Neg ℍ[R,c₁,c₂] := ⟨fun a => ⟨-a.1, -a.2, -a.3, -a.4⟩⟩
@[simp] theorem neg_re : (-a).re = -a.re := rfl
#align quaternion_algebra.has_neg_neg_re QuaternionAlgebra.neg_re
@[simp] theorem neg_imI : (-a).imI = -a.imI := rfl
#align quaternion_algebra.has_neg_neg_im_i QuaternionAlgebra.neg_imI
@[simp] theorem neg_imJ : (-a).imJ = -a.imJ := rfl
#align quaternion_algebra.has_neg_neg_im_j QuaternionAlgebra.neg_imJ
@[simp] theorem neg_imK : (-a).imK = -a.imK := rfl
#align quaternion_algebra.has_neg_neg_im_k QuaternionAlgebra.neg_imK
@[simp] theorem neg_im : (-a).im = -a.im :=
QuaternionAlgebra.ext _ _ neg_zero.symm rfl rfl rfl
@[simp]
theorem neg_mk (a₁ a₂ a₃ a₄ : R) : -(mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂]) = ⟨-a₁, -a₂, -a₃, -a₄⟩ :=
rfl
#align quaternion_algebra.neg_mk QuaternionAlgebra.neg_mk
@[simp, norm_cast]
theorem coe_neg : ((-x : R) : ℍ[R,c₁,c₂]) = -x := by ext <;> simp
#align quaternion_algebra.coe_neg QuaternionAlgebra.coe_neg
instance : Sub ℍ[R,c₁,c₂] :=
⟨fun a b => ⟨a.1 - b.1, a.2 - b.2, a.3 - b.3, a.4 - b.4⟩⟩
@[simp] theorem sub_re : (a - b).re = a.re - b.re := rfl
#align quaternion_algebra.has_sub_sub_re QuaternionAlgebra.sub_re
@[simp] theorem sub_imI : (a - b).imI = a.imI - b.imI := rfl
#align quaternion_algebra.has_sub_sub_im_i QuaternionAlgebra.sub_imI
@[simp] theorem sub_imJ : (a - b).imJ = a.imJ - b.imJ := rfl
#align quaternion_algebra.has_sub_sub_im_j QuaternionAlgebra.sub_imJ
@[simp] theorem sub_imK : (a - b).imK = a.imK - b.imK := rfl
#align quaternion_algebra.has_sub_sub_im_k QuaternionAlgebra.sub_imK
@[simp] theorem sub_im : (a - b).im = a.im - b.im :=
QuaternionAlgebra.ext _ _ (sub_zero _).symm rfl rfl rfl
@[simp]
theorem mk_sub_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) :
(mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂]) - mk b₁ b₂ b₃ b₄ = mk (a₁ - b₁) (a₂ - b₂) (a₃ - b₃) (a₄ - b₄) :=
rfl
#align quaternion_algebra.mk_sub_mk QuaternionAlgebra.mk_sub_mk
@[simp, norm_cast]
theorem coe_im : (x : ℍ[R,c₁,c₂]).im = 0 :=
rfl
#align quaternion_algebra.coe_im QuaternionAlgebra.coe_im
@[simp]
theorem re_add_im : ↑a.re + a.im = a :=
QuaternionAlgebra.ext _ _ (add_zero _) (zero_add _) (zero_add _) (zero_add _)
#align quaternion_algebra.re_add_im QuaternionAlgebra.re_add_im
@[simp]
theorem sub_self_im : a - a.im = a.re :=
QuaternionAlgebra.ext _ _ (sub_zero _) (sub_self _) (sub_self _) (sub_self _)
#align quaternion_algebra.sub_self_im QuaternionAlgebra.sub_self_im
@[simp]
theorem sub_self_re : a - a.re = a.im :=
QuaternionAlgebra.ext _ _ (sub_self _) (sub_zero _) (sub_zero _) (sub_zero _)
#align quaternion_algebra.sub_self_re QuaternionAlgebra.sub_self_re
/-- Multiplication is given by
* `1 * x = x * 1 = x`;
* `i * i = c₁`;
* `j * j = c₂`;
* `i * j = k`, `j * i = -k`;
* `k * k = -c₁ * c₂`;
* `i * k = c₁ * j`, `k * i = -c₁ * j`;
* `j * k = -c₂ * i`, `k * j = c₂ * i`. -/
instance : Mul ℍ[R,c₁,c₂] :=
⟨fun a b =>
⟨a.1 * b.1 + c₁ * a.2 * b.2 + c₂ * a.3 * b.3 - c₁ * c₂ * a.4 * b.4,
a.1 * b.2 + a.2 * b.1 - c₂ * a.3 * b.4 + c₂ * a.4 * b.3,
a.1 * b.3 + c₁ * a.2 * b.4 + a.3 * b.1 - c₁ * a.4 * b.2,
a.1 * b.4 + a.2 * b.3 - a.3 * b.2 + a.4 * b.1⟩⟩
@[simp]
theorem mul_re : (a * b).re = a.1 * b.1 + c₁ * a.2 * b.2 + c₂ * a.3 * b.3 - c₁ * c₂ * a.4 * b.4 :=
rfl
#align quaternion_algebra.has_mul_mul_re QuaternionAlgebra.mul_re
@[simp]
theorem mul_imI : (a * b).imI = a.1 * b.2 + a.2 * b.1 - c₂ * a.3 * b.4 + c₂ * a.4 * b.3 := rfl
#align quaternion_algebra.has_mul_mul_im_i QuaternionAlgebra.mul_imI
@[simp]
theorem mul_imJ : (a * b).imJ = a.1 * b.3 + c₁ * a.2 * b.4 + a.3 * b.1 - c₁ * a.4 * b.2 := rfl
#align quaternion_algebra.has_mul_mul_im_j QuaternionAlgebra.mul_imJ
@[simp] theorem mul_imK : (a * b).imK = a.1 * b.4 + a.2 * b.3 - a.3 * b.2 + a.4 * b.1 := rfl
#align quaternion_algebra.has_mul_mul_im_k QuaternionAlgebra.mul_imK
@[simp]
theorem mk_mul_mk (a₁ a₂ a₃ a₄ b₁ b₂ b₃ b₄ : R) :
(mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂]) * mk b₁ b₂ b₃ b₄ =
⟨a₁ * b₁ + c₁ * a₂ * b₂ + c₂ * a₃ * b₃ - c₁ * c₂ * a₄ * b₄,
a₁ * b₂ + a₂ * b₁ - c₂ * a₃ * b₄ + c₂ * a₄ * b₃,
a₁ * b₃ + c₁ * a₂ * b₄ + a₃ * b₁ - c₁ * a₄ * b₂, a₁ * b₄ + a₂ * b₃ - a₃ * b₂ + a₄ * b₁⟩ :=
rfl
#align quaternion_algebra.mk_mul_mk QuaternionAlgebra.mk_mul_mk
section
variable [SMul S R] [SMul T R] (s : S)
-- Porting note: Lean 4 auto drops the unused `[Ring R]` argument
instance : SMul S ℍ[R,c₁,c₂] where smul s a := ⟨s • a.1, s • a.2, s • a.3, s • a.4⟩
instance [SMul S T] [IsScalarTower S T R] : IsScalarTower S T ℍ[R,c₁,c₂] where
smul_assoc s t x := by ext <;> exact smul_assoc _ _ _
instance [SMulCommClass S T R] : SMulCommClass S T ℍ[R,c₁,c₂] where
smul_comm s t x := by ext <;> exact smul_comm _ _ _
@[simp] theorem smul_re : (s • a).re = s • a.re := rfl
#align quaternion_algebra.smul_re QuaternionAlgebra.smul_re
@[simp] theorem smul_imI : (s • a).imI = s • a.imI := rfl
#align quaternion_algebra.smul_im_i QuaternionAlgebra.smul_imI
@[simp] theorem smul_imJ : (s • a).imJ = s • a.imJ := rfl
#align quaternion_algebra.smul_im_j QuaternionAlgebra.smul_imJ
@[simp] theorem smul_imK : (s • a).imK = s • a.imK := rfl
#align quaternion_algebra.smul_im_k QuaternionAlgebra.smul_imK
@[simp] theorem smul_im {S} [SMulZeroClass S R] (s : S) : (s • a).im = s • a.im :=
QuaternionAlgebra.ext _ _ (smul_zero s).symm rfl rfl rfl
@[simp]
theorem smul_mk (re im_i im_j im_k : R) :
s • (⟨re, im_i, im_j, im_k⟩ : ℍ[R,c₁,c₂]) = ⟨s • re, s • im_i, s • im_j, s • im_k⟩ :=
rfl
#align quaternion_algebra.smul_mk QuaternionAlgebra.smul_mk
end
@[simp, norm_cast]
theorem coe_smul [SMulZeroClass S R] (s : S) (r : R) :
(↑(s • r) : ℍ[R,c₁,c₂]) = s • (r : ℍ[R,c₁,c₂]) :=
QuaternionAlgebra.ext _ _ rfl (smul_zero s).symm (smul_zero s).symm (smul_zero s).symm
#align quaternion_algebra.coe_smul QuaternionAlgebra.coe_smul
instance : AddCommGroup ℍ[R,c₁,c₂] :=
(equivProd c₁ c₂).injective.addCommGroup _ rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl)
(fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
instance : AddCommGroupWithOne ℍ[R,c₁,c₂] where
natCast n := ((n : R) : ℍ[R,c₁,c₂])
natCast_zero := by simp
natCast_succ := by simp
intCast n := ((n : R) : ℍ[R,c₁,c₂])
intCast_ofNat _ := congr_arg coe (Int.cast_natCast _)
intCast_negSucc n := by
change coe _ = -coe _
rw [Int.cast_negSucc, coe_neg]
@[simp, norm_cast]
theorem natCast_re (n : ℕ) : (n : ℍ[R,c₁,c₂]).re = n :=
rfl
#align quaternion_algebra.nat_cast_re QuaternionAlgebra.natCast_re
@[deprecated (since := "2024-04-17")]
alias nat_cast_re := natCast_re
@[simp, norm_cast]
theorem natCast_imI (n : ℕ) : (n : ℍ[R,c₁,c₂]).imI = 0 :=
rfl
#align quaternion_algebra.nat_cast_im_i QuaternionAlgebra.natCast_imI
@[deprecated (since := "2024-04-17")]
alias nat_cast_imI := natCast_imI
@[simp, norm_cast]
theorem natCast_imJ (n : ℕ) : (n : ℍ[R,c₁,c₂]).imJ = 0 :=
rfl
#align quaternion_algebra.nat_cast_im_j QuaternionAlgebra.natCast_imJ
@[deprecated (since := "2024-04-17")]
alias nat_cast_imJ := natCast_imJ
@[simp, norm_cast]
theorem natCast_imK (n : ℕ) : (n : ℍ[R,c₁,c₂]).imK = 0 :=
rfl
#align quaternion_algebra.nat_cast_im_k QuaternionAlgebra.natCast_imK
@[deprecated (since := "2024-04-17")]
alias nat_cast_imK := natCast_imK
@[simp, norm_cast]
theorem natCast_im (n : ℕ) : (n : ℍ[R,c₁,c₂]).im = 0 :=
rfl
#align quaternion_algebra.nat_cast_im QuaternionAlgebra.natCast_im
@[deprecated (since := "2024-04-17")]
alias nat_cast_im := natCast_im
@[norm_cast]
theorem coe_natCast (n : ℕ) : ↑(n : R) = (n : ℍ[R,c₁,c₂]) :=
rfl
#align quaternion_algebra.coe_nat_cast QuaternionAlgebra.coe_natCast
@[deprecated (since := "2024-04-17")]
alias coe_nat_cast := coe_natCast
@[simp, norm_cast]
theorem intCast_re (z : ℤ) : (z : ℍ[R,c₁,c₂]).re = z :=
rfl
#align quaternion_algebra.int_cast_re QuaternionAlgebra.intCast_re
@[deprecated (since := "2024-04-17")]
alias int_cast_re := intCast_re
@[simp, norm_cast]
theorem intCast_imI (z : ℤ) : (z : ℍ[R,c₁,c₂]).imI = 0 :=
rfl
#align quaternion_algebra.int_cast_im_i QuaternionAlgebra.intCast_imI
@[deprecated (since := "2024-04-17")]
alias int_cast_imI := intCast_imI
@[simp, norm_cast]
theorem intCast_imJ (z : ℤ) : (z : ℍ[R,c₁,c₂]).imJ = 0 :=
rfl
#align quaternion_algebra.int_cast_im_j QuaternionAlgebra.intCast_imJ
@[deprecated (since := "2024-04-17")]
alias int_cast_imJ := intCast_imJ
@[simp, norm_cast]
theorem intCast_imK (z : ℤ) : (z : ℍ[R,c₁,c₂]).imK = 0 :=
rfl
#align quaternion_algebra.int_cast_im_k QuaternionAlgebra.intCast_imK
@[deprecated (since := "2024-04-17")]
alias int_cast_imK := intCast_imK
@[simp, norm_cast]
theorem intCast_im (z : ℤ) : (z : ℍ[R,c₁,c₂]).im = 0 :=
rfl
#align quaternion_algebra.int_cast_im QuaternionAlgebra.intCast_im
@[deprecated (since := "2024-04-17")]
alias int_cast_im := intCast_im
@[norm_cast]
theorem coe_intCast (z : ℤ) : ↑(z : R) = (z : ℍ[R,c₁,c₂]) :=
rfl
#align quaternion_algebra.coe_int_cast QuaternionAlgebra.coe_intCast
@[deprecated (since := "2024-04-17")]
alias coe_int_cast := coe_intCast
instance instRing : Ring ℍ[R,c₁,c₂] where
__ := inferInstanceAs (AddCommGroupWithOne ℍ[R,c₁,c₂])
left_distrib _ _ _ := by ext <;> simp <;> ring
right_distrib _ _ _ := by ext <;> simp <;> ring
zero_mul _ := by ext <;> simp
mul_zero _ := by ext <;> simp
mul_assoc _ _ _ := by ext <;> simp <;> ring
one_mul _ := by ext <;> simp
mul_one _ := by ext <;> simp
@[norm_cast, simp]
theorem coe_mul : ((x * y : R) : ℍ[R,c₁,c₂]) = x * y := by ext <;> simp
#align quaternion_algebra.coe_mul QuaternionAlgebra.coe_mul
-- TODO: add weaker `MulAction`, `DistribMulAction`, and `Module` instances (and repeat them
-- for `ℍ[R]`)
instance [CommSemiring S] [Algebra S R] : Algebra S ℍ[R,c₁,c₂] where
smul := (· • ·)
toFun s := coe (algebraMap S R s)
map_one' := by simp only [map_one, coe_one]
map_zero' := by simp only [map_zero, coe_zero]
map_mul' x y := by simp only [map_mul, coe_mul]
map_add' x y := by simp only [map_add, coe_add]
smul_def' s x := by ext <;> simp [Algebra.smul_def]
commutes' s x := by ext <;> simp [Algebra.commutes]
theorem algebraMap_eq (r : R) : algebraMap R ℍ[R,c₁,c₂] r = ⟨r, 0, 0, 0⟩ :=
rfl
#align quaternion_algebra.algebra_map_eq QuaternionAlgebra.algebraMap_eq
theorem algebraMap_injective : (algebraMap R ℍ[R,c₁,c₂] : _ → _).Injective :=
fun _ _ ↦ by simp [algebraMap_eq]
instance [NoZeroDivisors R] : NoZeroSMulDivisors R ℍ[R,c₁,c₂] := ⟨by
rintro t ⟨a, b, c, d⟩ h
rw [or_iff_not_imp_left]
intro ht
simpa [QuaternionAlgebra.ext_iff, ht] using h⟩
section
variable (c₁ c₂)
/-- `QuaternionAlgebra.re` as a `LinearMap`-/
@[simps]
def reₗ : ℍ[R,c₁,c₂] →ₗ[R] R where
toFun := re
map_add' _ _ := rfl
map_smul' _ _ := rfl
#align quaternion_algebra.re_lm QuaternionAlgebra.reₗ
/-- `QuaternionAlgebra.imI` as a `LinearMap`-/
@[simps]
def imIₗ : ℍ[R,c₁,c₂] →ₗ[R] R where
toFun := imI
map_add' _ _ := rfl
map_smul' _ _ := rfl
#align quaternion_algebra.im_i_lm QuaternionAlgebra.imIₗ
/-- `QuaternionAlgebra.imJ` as a `LinearMap`-/
@[simps]
def imJₗ : ℍ[R,c₁,c₂] →ₗ[R] R where
toFun := imJ
map_add' _ _ := rfl
map_smul' _ _ := rfl
#align quaternion_algebra.im_j_lm QuaternionAlgebra.imJₗ
/-- `QuaternionAlgebra.imK` as a `LinearMap`-/
@[simps]
def imKₗ : ℍ[R,c₁,c₂] →ₗ[R] R where
toFun := imK
map_add' _ _ := rfl
map_smul' _ _ := rfl
#align quaternion_algebra.im_k_lm QuaternionAlgebra.imKₗ
/-- `QuaternionAlgebra.equivTuple` as a linear equivalence. -/
def linearEquivTuple : ℍ[R,c₁,c₂] ≃ₗ[R] Fin 4 → R :=
LinearEquiv.symm -- proofs are not `rfl` in the forward direction
{ (equivTuple c₁ c₂).symm with
toFun := (equivTuple c₁ c₂).symm
invFun := equivTuple c₁ c₂
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
#align quaternion_algebra.linear_equiv_tuple QuaternionAlgebra.linearEquivTuple
@[simp]
theorem coe_linearEquivTuple : ⇑(linearEquivTuple c₁ c₂) = equivTuple c₁ c₂ :=
rfl
#align quaternion_algebra.coe_linear_equiv_tuple QuaternionAlgebra.coe_linearEquivTuple
@[simp]
theorem coe_linearEquivTuple_symm : ⇑(linearEquivTuple c₁ c₂).symm = (equivTuple c₁ c₂).symm :=
rfl
#align quaternion_algebra.coe_linear_equiv_tuple_symm QuaternionAlgebra.coe_linearEquivTuple_symm
/-- `ℍ[R, c₁, c₂]` has a basis over `R` given by `1`, `i`, `j`, and `k`. -/
noncomputable def basisOneIJK : Basis (Fin 4) R ℍ[R,c₁,c₂] :=
.ofEquivFun <| linearEquivTuple c₁ c₂
#align quaternion_algebra.basis_one_i_j_k QuaternionAlgebra.basisOneIJK
@[simp]
theorem coe_basisOneIJK_repr (q : ℍ[R,c₁,c₂]) :
⇑((basisOneIJK c₁ c₂).repr q) = ![q.re, q.imI, q.imJ, q.imK] :=
rfl
#align quaternion_algebra.coe_basis_one_i_j_k_repr QuaternionAlgebra.coe_basisOneIJK_repr
instance : Module.Finite R ℍ[R,c₁,c₂] := .of_basis (basisOneIJK c₁ c₂)
instance : Module.Free R ℍ[R,c₁,c₂] := .of_basis (basisOneIJK c₁ c₂)
theorem rank_eq_four [StrongRankCondition R] : Module.rank R ℍ[R,c₁,c₂] = 4 := by
rw [rank_eq_card_basis (basisOneIJK c₁ c₂), Fintype.card_fin]
norm_num
#align quaternion_algebra.rank_eq_four QuaternionAlgebra.rank_eq_four
theorem finrank_eq_four [StrongRankCondition R] : FiniteDimensional.finrank R ℍ[R,c₁,c₂] = 4 := by
rw [FiniteDimensional.finrank, rank_eq_four, Cardinal.toNat_ofNat]
#align quaternion_algebra.finrank_eq_four QuaternionAlgebra.finrank_eq_four
/-- There is a natural equivalence when swapping the coefficients of a quaternion algebra. -/
@[simps]
def swapEquiv : ℍ[R,c₁,c₂] ≃ₐ[R] ℍ[R, c₂, c₁] where
toFun t := ⟨t.1, t.3, t.2, -t.4⟩
invFun t := ⟨t.1, t.3, t.2, -t.4⟩
left_inv _ := by simp
right_inv _ := by simp
map_mul' _ _ := by
ext
<;> simp only [mul_re, mul_imJ, mul_imI, add_left_inj, mul_imK, neg_mul, neg_add_rev,
neg_sub, mk_mul_mk, mul_neg, neg_neg, sub_neg_eq_add]
<;> ring
map_add' _ _ := by ext <;> simp [add_comm]
commutes' _ := by simp [algebraMap_eq]
end
@[norm_cast, simp]
theorem coe_sub : ((x - y : R) : ℍ[R,c₁,c₂]) = x - y :=
(algebraMap R ℍ[R,c₁,c₂]).map_sub x y
#align quaternion_algebra.coe_sub QuaternionAlgebra.coe_sub
@[norm_cast, simp]
theorem coe_pow (n : ℕ) : (↑(x ^ n) : ℍ[R,c₁,c₂]) = (x : ℍ[R,c₁,c₂]) ^ n :=
(algebraMap R ℍ[R,c₁,c₂]).map_pow x n
#align quaternion_algebra.coe_pow QuaternionAlgebra.coe_pow
theorem coe_commutes : ↑r * a = a * r :=
Algebra.commutes r a
#align quaternion_algebra.coe_commutes QuaternionAlgebra.coe_commutes
theorem coe_commute : Commute (↑r) a :=
coe_commutes r a
#align quaternion_algebra.coe_commute QuaternionAlgebra.coe_commute
theorem coe_mul_eq_smul : ↑r * a = r • a :=
(Algebra.smul_def r a).symm
#align quaternion_algebra.coe_mul_eq_smul QuaternionAlgebra.coe_mul_eq_smul
theorem mul_coe_eq_smul : a * r = r • a := by rw [← coe_commutes, coe_mul_eq_smul]
#align quaternion_algebra.mul_coe_eq_smul QuaternionAlgebra.mul_coe_eq_smul
@[norm_cast, simp]
theorem coe_algebraMap : ⇑(algebraMap R ℍ[R,c₁,c₂]) = coe :=
rfl
#align quaternion_algebra.coe_algebra_map QuaternionAlgebra.coe_algebraMap
theorem smul_coe : x • (y : ℍ[R,c₁,c₂]) = ↑(x * y) := by rw [coe_mul, coe_mul_eq_smul]
#align quaternion_algebra.smul_coe QuaternionAlgebra.smul_coe
/-- Quaternion conjugate. -/
instance instStarQuaternionAlgebra : Star ℍ[R,c₁,c₂] where star a := ⟨a.1, -a.2, -a.3, -a.4⟩
@[simp] theorem re_star : (star a).re = a.re := rfl
#align quaternion_algebra.re_star QuaternionAlgebra.re_star
@[simp]
theorem imI_star : (star a).imI = -a.imI :=
rfl
#align quaternion_algebra.im_i_star QuaternionAlgebra.imI_star
@[simp]
theorem imJ_star : (star a).imJ = -a.imJ :=
rfl
#align quaternion_algebra.im_j_star QuaternionAlgebra.imJ_star
@[simp]
theorem imK_star : (star a).imK = -a.imK :=
rfl
#align quaternion_algebra.im_k_star QuaternionAlgebra.imK_star
@[simp]
theorem im_star : (star a).im = -a.im :=
QuaternionAlgebra.ext _ _ neg_zero.symm rfl rfl rfl
#align quaternion_algebra.im_star QuaternionAlgebra.im_star
@[simp]
theorem star_mk (a₁ a₂ a₃ a₄ : R) : star (mk a₁ a₂ a₃ a₄ : ℍ[R,c₁,c₂]) = ⟨a₁, -a₂, -a₃, -a₄⟩ :=
rfl
#align quaternion_algebra.star_mk QuaternionAlgebra.star_mk
instance instStarRing : StarRing ℍ[R,c₁,c₂] where
star_involutive x := by simp [Star.star]
star_add a b := by ext <;> simp [add_comm]
star_mul a b := by ext <;> simp <;> ring
theorem self_add_star' : a + star a = ↑(2 * a.re) := by ext <;> simp [two_mul]
#align quaternion_algebra.self_add_star' QuaternionAlgebra.self_add_star'
theorem self_add_star : a + star a = 2 * a.re := by simp only [self_add_star', two_mul, coe_add]
#align quaternion_algebra.self_add_star QuaternionAlgebra.self_add_star
theorem star_add_self' : star a + a = ↑(2 * a.re) := by rw [add_comm, self_add_star']
#align quaternion_algebra.star_add_self' QuaternionAlgebra.star_add_self'
theorem star_add_self : star a + a = 2 * a.re := by rw [add_comm, self_add_star]
#align quaternion_algebra.star_add_self QuaternionAlgebra.star_add_self
theorem star_eq_two_re_sub : star a = ↑(2 * a.re) - a :=
eq_sub_iff_add_eq.2 a.star_add_self'
#align quaternion_algebra.star_eq_two_re_sub QuaternionAlgebra.star_eq_two_re_sub
instance : IsStarNormal a :=
⟨by
rw [a.star_eq_two_re_sub]
exact (coe_commute (2 * a.re) a).sub_left (Commute.refl a)⟩
@[simp, norm_cast]
theorem star_coe : star (x : ℍ[R,c₁,c₂]) = x := by ext <;> simp
#align quaternion_algebra.star_coe QuaternionAlgebra.star_coe
@[simp] theorem star_im : star a.im = -a.im := im_star _
#align quaternion_algebra.star_im QuaternionAlgebra.star_im
@[simp]
theorem star_smul [Monoid S] [DistribMulAction S R] (s : S) (a : ℍ[R,c₁,c₂]) :
star (s • a) = s • star a :=
QuaternionAlgebra.ext _ _ rfl (smul_neg _ _).symm (smul_neg _ _).symm (smul_neg _ _).symm
#align quaternion_algebra.star_smul QuaternionAlgebra.star_smul
theorem eq_re_of_eq_coe {a : ℍ[R,c₁,c₂]} {x : R} (h : a = x) : a = a.re := by rw [h, coe_re]
#align quaternion_algebra.eq_re_of_eq_coe QuaternionAlgebra.eq_re_of_eq_coe
theorem eq_re_iff_mem_range_coe {a : ℍ[R,c₁,c₂]} :
a = a.re ↔ a ∈ Set.range (coe : R → ℍ[R,c₁,c₂]) :=
⟨fun h => ⟨a.re, h.symm⟩, fun ⟨_, h⟩ => eq_re_of_eq_coe h.symm⟩
#align quaternion_algebra.eq_re_iff_mem_range_coe QuaternionAlgebra.eq_re_iff_mem_range_coe
section CharZero
variable [NoZeroDivisors R] [CharZero R]
@[simp]
theorem star_eq_self {c₁ c₂ : R} {a : ℍ[R,c₁,c₂]} : star a = a ↔ a = a.re := by
simp [QuaternionAlgebra.ext_iff, neg_eq_iff_add_eq_zero, add_self_eq_zero]
#align quaternion_algebra.star_eq_self QuaternionAlgebra.star_eq_self
theorem star_eq_neg {c₁ c₂ : R} {a : ℍ[R,c₁,c₂]} : star a = -a ↔ a.re = 0 := by
simp [QuaternionAlgebra.ext_iff, eq_neg_iff_add_eq_zero]
#align quaternion_algebra.star_eq_neg QuaternionAlgebra.star_eq_neg
end CharZero
-- Can't use `rw ← star_eq_self` in the proof without additional assumptions
theorem star_mul_eq_coe : star a * a = (star a * a).re := by ext <;> simp <;> ring
#align quaternion_algebra.star_mul_eq_coe QuaternionAlgebra.star_mul_eq_coe
theorem mul_star_eq_coe : a * star a = (a * star a).re := by
rw [← star_comm_self']
exact a.star_mul_eq_coe
#align quaternion_algebra.mul_star_eq_coe QuaternionAlgebra.mul_star_eq_coe
open MulOpposite
/-- Quaternion conjugate as an `AlgEquiv` to the opposite ring. -/
def starAe : ℍ[R,c₁,c₂] ≃ₐ[R] ℍ[R,c₁,c₂]ᵐᵒᵖ :=
{ starAddEquiv.trans opAddEquiv with
toFun := op ∘ star
invFun := star ∘ unop
map_mul' := fun x y => by simp
commutes' := fun r => by simp }
#align quaternion_algebra.star_ae QuaternionAlgebra.starAe
@[simp]
theorem coe_starAe : ⇑(starAe : ℍ[R,c₁,c₂] ≃ₐ[R] _) = op ∘ star :=
rfl
#align quaternion_algebra.coe_star_ae QuaternionAlgebra.coe_starAe
end QuaternionAlgebra
/-- Space of quaternions over a type. Implemented as a structure with four fields:
`re`, `im_i`, `im_j`, and `im_k`. -/
def Quaternion (R : Type*) [One R] [Neg R] :=
QuaternionAlgebra R (-1) (-1)
#align quaternion Quaternion
scoped[Quaternion] notation "ℍ[" R "]" => Quaternion R
/-- The equivalence between the quaternions over `R` and `R × R × R × R`. -/
@[simps!]
def Quaternion.equivProd (R : Type*) [One R] [Neg R] : ℍ[R] ≃ R × R × R × R :=
QuaternionAlgebra.equivProd _ _
#align quaternion.equiv_prod Quaternion.equivProd
/-- The equivalence between the quaternions over `R` and `Fin 4 → R`. -/
@[simps! symm_apply]
def Quaternion.equivTuple (R : Type*) [One R] [Neg R] : ℍ[R] ≃ (Fin 4 → R) :=
QuaternionAlgebra.equivTuple _ _
#align quaternion.equiv_tuple Quaternion.equivTuple
@[simp]
theorem Quaternion.equivTuple_apply (R : Type*) [One R] [Neg R] (x : ℍ[R]) :
Quaternion.equivTuple R x = ![x.re, x.imI, x.imJ, x.imK] :=
rfl
#align quaternion.equiv_tuple_apply Quaternion.equivTuple_apply
instance {R : Type*} [One R] [Neg R] [Subsingleton R] : Subsingleton ℍ[R] :=
inferInstanceAs (Subsingleton <| ℍ[R, -1, -1])
instance {R : Type*} [One R] [Neg R] [Nontrivial R] : Nontrivial ℍ[R] :=
inferInstanceAs (Nontrivial <| ℍ[R, -1, -1])
namespace Quaternion
variable {S T R : Type*} [CommRing R] (r x y z : R) (a b c : ℍ[R])
export QuaternionAlgebra (re imI imJ imK)
/-- Coercion `R → ℍ[R]`. -/
@[coe] def coe : R → ℍ[R] := QuaternionAlgebra.coe
instance : CoeTC R ℍ[R] := ⟨coe⟩
instance instRing : Ring ℍ[R] := QuaternionAlgebra.instRing
instance : Inhabited ℍ[R] := inferInstanceAs <| Inhabited ℍ[R,-1,-1]
instance [SMul S R] : SMul S ℍ[R] := inferInstanceAs <| SMul S ℍ[R,-1,-1]
instance [SMul S T] [SMul S R] [SMul T R] [IsScalarTower S T R] : IsScalarTower S T ℍ[R] :=
inferInstanceAs <| IsScalarTower S T ℍ[R,-1,-1]
instance [SMul S R] [SMul T R] [SMulCommClass S T R] : SMulCommClass S T ℍ[R] :=
inferInstanceAs <| SMulCommClass S T ℍ[R,-1,-1]
protected instance algebra [CommSemiring S] [Algebra S R] : Algebra S ℍ[R] :=
inferInstanceAs <| Algebra S ℍ[R,-1,-1]
-- Porting note: added shortcut
instance : Star ℍ[R] := QuaternionAlgebra.instStarQuaternionAlgebra
instance : StarRing ℍ[R] := QuaternionAlgebra.instStarRing
instance : IsStarNormal a := inferInstanceAs <| IsStarNormal (R := ℍ[R,-1,-1]) a
@[ext]
theorem ext : a.re = b.re → a.imI = b.imI → a.imJ = b.imJ → a.imK = b.imK → a = b :=
QuaternionAlgebra.ext a b
#align quaternion.ext Quaternion.ext
theorem ext_iff {a b : ℍ[R]} :
a = b ↔ a.re = b.re ∧ a.imI = b.imI ∧ a.imJ = b.imJ ∧ a.imK = b.imK :=
QuaternionAlgebra.ext_iff a b
#align quaternion.ext_iff Quaternion.ext_iff
/-- The imaginary part of a quaternion. -/
nonrec def im (x : ℍ[R]) : ℍ[R] := x.im
#align quaternion.im Quaternion.im
@[simp] theorem im_re : a.im.re = 0 := rfl
#align quaternion.im_re Quaternion.im_re
@[simp] theorem im_imI : a.im.imI = a.imI := rfl
#align quaternion.im_im_i Quaternion.im_imI
@[simp] theorem im_imJ : a.im.imJ = a.imJ := rfl
#align quaternion.im_im_j Quaternion.im_imJ
@[simp] theorem im_imK : a.im.imK = a.imK := rfl
#align quaternion.im_im_k Quaternion.im_imK
@[simp] theorem im_idem : a.im.im = a.im := rfl
#align quaternion.im_idem Quaternion.im_idem
@[simp] nonrec theorem re_add_im : ↑a.re + a.im = a := a.re_add_im
#align quaternion.re_add_im Quaternion.re_add_im
@[simp] nonrec theorem sub_self_im : a - a.im = a.re := a.sub_self_im
#align quaternion.sub_self_im Quaternion.sub_self_im
@[simp] nonrec theorem sub_self_re : a - ↑a.re = a.im := a.sub_self_re
#align quaternion.sub_self_re Quaternion.sub_self_re
@[simp, norm_cast]
theorem coe_re : (x : ℍ[R]).re = x := rfl
#align quaternion.coe_re Quaternion.coe_re
@[simp, norm_cast]
theorem coe_imI : (x : ℍ[R]).imI = 0 := rfl
#align quaternion.coe_im_i Quaternion.coe_imI
@[simp, norm_cast]
theorem coe_imJ : (x : ℍ[R]).imJ = 0 := rfl
#align quaternion.coe_im_j Quaternion.coe_imJ
@[simp, norm_cast]
theorem coe_imK : (x : ℍ[R]).imK = 0 := rfl
#align quaternion.coe_im_k Quaternion.coe_imK
@[simp, norm_cast]
theorem coe_im : (x : ℍ[R]).im = 0 := rfl
#align quaternion.coe_im Quaternion.coe_im
@[simp] theorem zero_re : (0 : ℍ[R]).re = 0 := rfl
#align quaternion.zero_re Quaternion.zero_re
@[simp] theorem zero_imI : (0 : ℍ[R]).imI = 0 := rfl
#align quaternion.zero_im_i Quaternion.zero_imI
@[simp] theorem zero_imJ : (0 : ℍ[R]).imJ = 0 := rfl
#align quaternion.zero_im_j Quaternion.zero_imJ
@[simp] theorem zero_imK : (0 : ℍ[R]).imK = 0 := rfl
#align quaternion.zero_im_k Quaternion.zero_imK
@[simp] theorem zero_im : (0 : ℍ[R]).im = 0 := rfl
#align quaternion.zero_im Quaternion.zero_im
@[simp, norm_cast]
theorem coe_zero : ((0 : R) : ℍ[R]) = 0 := rfl
#align quaternion.coe_zero Quaternion.coe_zero
@[simp] theorem one_re : (1 : ℍ[R]).re = 1 := rfl
#align quaternion.one_re Quaternion.one_re
@[simp] theorem one_imI : (1 : ℍ[R]).imI = 0 := rfl
#align quaternion.one_im_i Quaternion.one_imI
@[simp] theorem one_imJ : (1 : ℍ[R]).imJ = 0 := rfl
#align quaternion.one_im_j Quaternion.one_imJ
@[simp] theorem one_imK : (1 : ℍ[R]).imK = 0 := rfl
#align quaternion.one_im_k Quaternion.one_imK
@[simp] theorem one_im : (1 : ℍ[R]).im = 0 := rfl
#align quaternion.one_im Quaternion.one_im
@[simp, norm_cast]
theorem coe_one : ((1 : R) : ℍ[R]) = 1 := rfl
#align quaternion.coe_one Quaternion.coe_one
@[simp] theorem add_re : (a + b).re = a.re + b.re := rfl
#align quaternion.add_re Quaternion.add_re
@[simp] theorem add_imI : (a + b).imI = a.imI + b.imI := rfl
#align quaternion.add_im_i Quaternion.add_imI
@[simp] theorem add_imJ : (a + b).imJ = a.imJ + b.imJ := rfl
#align quaternion.add_im_j Quaternion.add_imJ
@[simp] theorem add_imK : (a + b).imK = a.imK + b.imK := rfl
#align quaternion.add_im_k Quaternion.add_imK
@[simp] nonrec theorem add_im : (a + b).im = a.im + b.im := a.add_im b
#align quaternion.add_im Quaternion.add_im
@[simp, norm_cast]
theorem coe_add : ((x + y : R) : ℍ[R]) = x + y :=
QuaternionAlgebra.coe_add x y
#align quaternion.coe_add Quaternion.coe_add
@[simp] theorem neg_re : (-a).re = -a.re := rfl
#align quaternion.neg_re Quaternion.neg_re
@[simp] theorem neg_imI : (-a).imI = -a.imI := rfl
#align quaternion.neg_im_i Quaternion.neg_imI
@[simp] theorem neg_imJ : (-a).imJ = -a.imJ := rfl
#align quaternion.neg_im_j Quaternion.neg_imJ
@[simp] theorem neg_imK : (-a).imK = -a.imK := rfl
#align quaternion.neg_im_k Quaternion.neg_imK
@[simp] nonrec theorem neg_im : (-a).im = -a.im := a.neg_im
#align quaternion.neg_im Quaternion.neg_im
@[simp, norm_cast]
theorem coe_neg : ((-x : R) : ℍ[R]) = -x :=
QuaternionAlgebra.coe_neg x
#align quaternion.coe_neg Quaternion.coe_neg
@[simp] theorem sub_re : (a - b).re = a.re - b.re := rfl
#align quaternion.sub_re Quaternion.sub_re
@[simp] theorem sub_imI : (a - b).imI = a.imI - b.imI := rfl
#align quaternion.sub_im_i Quaternion.sub_imI
@[simp] theorem sub_imJ : (a - b).imJ = a.imJ - b.imJ := rfl
#align quaternion.sub_im_j Quaternion.sub_imJ
@[simp] theorem sub_imK : (a - b).imK = a.imK - b.imK := rfl
#align quaternion.sub_im_k Quaternion.sub_imK
@[simp] nonrec theorem sub_im : (a - b).im = a.im - b.im := a.sub_im b
#align quaternion.sub_im Quaternion.sub_im
@[simp, norm_cast]
theorem coe_sub : ((x - y : R) : ℍ[R]) = x - y :=
QuaternionAlgebra.coe_sub x y
#align quaternion.coe_sub Quaternion.coe_sub
@[simp]
theorem mul_re : (a * b).re = a.re * b.re - a.imI * b.imI - a.imJ * b.imJ - a.imK * b.imK :=
(QuaternionAlgebra.mul_re a b).trans <| by simp only [one_mul, neg_mul, sub_eq_add_neg, neg_neg]
#align quaternion.mul_re Quaternion.mul_re
@[simp]
theorem mul_imI : (a * b).imI = a.re * b.imI + a.imI * b.re + a.imJ * b.imK - a.imK * b.imJ :=
(QuaternionAlgebra.mul_imI a b).trans <| by simp only [one_mul, neg_mul, sub_eq_add_neg, neg_neg]
#align quaternion.mul_im_i Quaternion.mul_imI
@[simp]
theorem mul_imJ : (a * b).imJ = a.re * b.imJ - a.imI * b.imK + a.imJ * b.re + a.imK * b.imI :=
(QuaternionAlgebra.mul_imJ a b).trans <| by simp only [one_mul, neg_mul, sub_eq_add_neg, neg_neg]
#align quaternion.mul_im_j Quaternion.mul_imJ
@[simp]
theorem mul_imK : (a * b).imK = a.re * b.imK + a.imI * b.imJ - a.imJ * b.imI + a.imK * b.re :=
(QuaternionAlgebra.mul_imK a b).trans <| by simp only [one_mul, neg_mul, sub_eq_add_neg, neg_neg]
#align quaternion.mul_im_k Quaternion.mul_imK
@[simp, norm_cast]
theorem coe_mul : ((x * y : R) : ℍ[R]) = x * y := QuaternionAlgebra.coe_mul x y
#align quaternion.coe_mul Quaternion.coe_mul
@[norm_cast, simp]
theorem coe_pow (n : ℕ) : (↑(x ^ n) : ℍ[R]) = (x : ℍ[R]) ^ n :=
QuaternionAlgebra.coe_pow x n
#align quaternion.coe_pow Quaternion.coe_pow
@[simp, norm_cast]
theorem natCast_re (n : ℕ) : (n : ℍ[R]).re = n := rfl
#align quaternion.nat_cast_re Quaternion.natCast_re
@[deprecated (since := "2024-04-17")]
alias nat_cast_re := natCast_re
@[simp, norm_cast]
theorem natCast_imI (n : ℕ) : (n : ℍ[R]).imI = 0 := rfl
#align quaternion.nat_cast_im_i Quaternion.natCast_imI
@[deprecated (since := "2024-04-17")]
alias nat_cast_imI := natCast_imI
@[simp, norm_cast]
theorem natCast_imJ (n : ℕ) : (n : ℍ[R]).imJ = 0 := rfl
#align quaternion.nat_cast_im_j Quaternion.natCast_imJ
@[deprecated (since := "2024-04-17")]
alias nat_cast_imJ := natCast_imJ
@[simp, norm_cast]
theorem natCast_imK (n : ℕ) : (n : ℍ[R]).imK = 0 := rfl
#align quaternion.nat_cast_im_k Quaternion.natCast_imK
@[deprecated (since := "2024-04-17")]
alias nat_cast_imK := natCast_imK
@[simp, norm_cast]
theorem natCast_im (n : ℕ) : (n : ℍ[R]).im = 0 := rfl
#align quaternion.nat_cast_im Quaternion.natCast_im
@[deprecated (since := "2024-04-17")]
alias nat_cast_im := natCast_im
@[norm_cast]
theorem coe_natCast (n : ℕ) : ↑(n : R) = (n : ℍ[R]) := rfl
#align quaternion.coe_nat_cast Quaternion.coe_natCast
@[deprecated (since := "2024-04-17")]
alias coe_nat_cast := coe_natCast
@[simp, norm_cast]
theorem intCast_re (z : ℤ) : (z : ℍ[R]).re = z := rfl
#align quaternion.int_cast_re Quaternion.intCast_re
@[deprecated (since := "2024-04-17")]
alias int_cast_re := intCast_re
@[simp, norm_cast]
theorem intCast_imI (z : ℤ) : (z : ℍ[R]).imI = 0 := rfl
#align quaternion.int_cast_im_i Quaternion.intCast_imI
@[deprecated (since := "2024-04-17")]
alias int_cast_imI := intCast_imI
@[simp, norm_cast]
theorem intCast_imJ (z : ℤ) : (z : ℍ[R]).imJ = 0 := rfl
#align quaternion.int_cast_im_j Quaternion.intCast_imJ
@[deprecated (since := "2024-04-17")]
alias int_cast_imJ := intCast_imJ
@[simp, norm_cast]
theorem intCast_imK (z : ℤ) : (z : ℍ[R]).imK = 0 := rfl
#align quaternion.int_cast_im_k Quaternion.intCast_imK
@[deprecated (since := "2024-04-17")]
alias int_cast_imK := intCast_imK
@[simp, norm_cast]
theorem intCast_im (z : ℤ) : (z : ℍ[R]).im = 0 := rfl
#align quaternion.int_cast_im Quaternion.intCast_im
@[deprecated (since := "2024-04-17")]
alias int_cast_im := intCast_im
@[norm_cast]
theorem coe_intCast (z : ℤ) : ↑(z : R) = (z : ℍ[R]) := rfl
#align quaternion.coe_int_cast Quaternion.coe_intCast
@[deprecated (since := "2024-04-17")]
alias coe_int_cast := coe_intCast
theorem coe_injective : Function.Injective (coe : R → ℍ[R]) :=
QuaternionAlgebra.coe_injective
#align quaternion.coe_injective Quaternion.coe_injective
@[simp]
theorem coe_inj {x y : R} : (x : ℍ[R]) = y ↔ x = y :=
coe_injective.eq_iff
#align quaternion.coe_inj Quaternion.coe_inj
@[simp]
theorem smul_re [SMul S R] (s : S) : (s • a).re = s • a.re :=
rfl
#align quaternion.smul_re Quaternion.smul_re
@[simp] theorem smul_imI [SMul S R] (s : S) : (s • a).imI = s • a.imI := rfl
#align quaternion.smul_im_i Quaternion.smul_imI
@[simp] theorem smul_imJ [SMul S R] (s : S) : (s • a).imJ = s • a.imJ := rfl
#align quaternion.smul_im_j Quaternion.smul_imJ
@[simp] theorem smul_imK [SMul S R] (s : S) : (s • a).imK = s • a.imK := rfl
#align quaternion.smul_im_k Quaternion.smul_imK
@[simp]
nonrec theorem smul_im [SMulZeroClass S R] (s : S) : (s • a).im = s • a.im :=
a.smul_im s
#align quaternion.smul_im Quaternion.smul_im
@[simp, norm_cast]
theorem coe_smul [SMulZeroClass S R] (s : S) (r : R) : (↑(s • r) : ℍ[R]) = s • (r : ℍ[R]) :=
QuaternionAlgebra.coe_smul _ _
#align quaternion.coe_smul Quaternion.coe_smul
theorem coe_commutes : ↑r * a = a * r :=
QuaternionAlgebra.coe_commutes r a
#align quaternion.coe_commutes Quaternion.coe_commutes
theorem coe_commute : Commute (↑r) a :=
QuaternionAlgebra.coe_commute r a
#align quaternion.coe_commute Quaternion.coe_commute
theorem coe_mul_eq_smul : ↑r * a = r • a :=
QuaternionAlgebra.coe_mul_eq_smul r a
#align quaternion.coe_mul_eq_smul Quaternion.coe_mul_eq_smul
theorem mul_coe_eq_smul : a * r = r • a :=
QuaternionAlgebra.mul_coe_eq_smul r a
#align quaternion.mul_coe_eq_smul Quaternion.mul_coe_eq_smul
@[simp]
theorem algebraMap_def : ⇑(algebraMap R ℍ[R]) = coe :=
rfl
#align quaternion.algebra_map_def Quaternion.algebraMap_def
theorem algebraMap_injective : (algebraMap R ℍ[R] : _ → _).Injective :=
QuaternionAlgebra.algebraMap_injective
theorem smul_coe : x • (y : ℍ[R]) = ↑(x * y) :=
QuaternionAlgebra.smul_coe x y
#align quaternion.smul_coe Quaternion.smul_coe
instance : Module.Finite R ℍ[R] := inferInstanceAs <| Module.Finite R ℍ[R,-1,-1]
instance : Module.Free R ℍ[R] := inferInstanceAs <| Module.Free R ℍ[R,-1,-1]
theorem rank_eq_four [StrongRankCondition R] : Module.rank R ℍ[R] = 4 :=
QuaternionAlgebra.rank_eq_four _ _
#align quaternion.rank_eq_four Quaternion.rank_eq_four
theorem finrank_eq_four [StrongRankCondition R] : FiniteDimensional.finrank R ℍ[R] = 4 :=
QuaternionAlgebra.finrank_eq_four _ _
#align quaternion.finrank_eq_four Quaternion.finrank_eq_four
@[simp] theorem star_re : (star a).re = a.re := rfl
#align quaternion.star_re Quaternion.star_re
@[simp] theorem star_imI : (star a).imI = -a.imI := rfl
#align quaternion.star_im_i Quaternion.star_imI
@[simp] theorem star_imJ : (star a).imJ = -a.imJ := rfl
#align quaternion.star_im_j Quaternion.star_imJ
@[simp] theorem star_imK : (star a).imK = -a.imK := rfl
#align quaternion.star_im_k Quaternion.star_imK
@[simp] theorem star_im : (star a).im = -a.im := a.im_star
#align quaternion.star_im Quaternion.star_im
nonrec theorem self_add_star' : a + star a = ↑(2 * a.re) :=
a.self_add_star'
#align quaternion.self_add_star' Quaternion.self_add_star'
nonrec theorem self_add_star : a + star a = 2 * a.re :=
a.self_add_star
#align quaternion.self_add_star Quaternion.self_add_star
nonrec theorem star_add_self' : star a + a = ↑(2 * a.re) :=
a.star_add_self'
#align quaternion.star_add_self' Quaternion.star_add_self'
nonrec theorem star_add_self : star a + a = 2 * a.re :=
a.star_add_self
#align quaternion.star_add_self Quaternion.star_add_self
nonrec theorem star_eq_two_re_sub : star a = ↑(2 * a.re) - a :=
a.star_eq_two_re_sub
#align quaternion.star_eq_two_re_sub Quaternion.star_eq_two_re_sub
@[simp, norm_cast]
theorem star_coe : star (x : ℍ[R]) = x :=
QuaternionAlgebra.star_coe x
#align quaternion.star_coe Quaternion.star_coe
@[simp]
theorem im_star : star a.im = -a.im :=
QuaternionAlgebra.im_star _
#align quaternion.im_star Quaternion.im_star
@[simp]
theorem star_smul [Monoid S] [DistribMulAction S R] (s : S) (a : ℍ[R]) :
star (s • a) = s • star a :=
QuaternionAlgebra.star_smul _ _
#align quaternion.star_smul Quaternion.star_smul
theorem eq_re_of_eq_coe {a : ℍ[R]} {x : R} (h : a = x) : a = a.re :=
QuaternionAlgebra.eq_re_of_eq_coe h
#align quaternion.eq_re_of_eq_coe Quaternion.eq_re_of_eq_coe
theorem eq_re_iff_mem_range_coe {a : ℍ[R]} : a = a.re ↔ a ∈ Set.range (coe : R → ℍ[R]) :=
QuaternionAlgebra.eq_re_iff_mem_range_coe
#align quaternion.eq_re_iff_mem_range_coe Quaternion.eq_re_iff_mem_range_coe
section CharZero
variable [NoZeroDivisors R] [CharZero R]
@[simp]
theorem star_eq_self {a : ℍ[R]} : star a = a ↔ a = a.re :=
QuaternionAlgebra.star_eq_self
#align quaternion.star_eq_self Quaternion.star_eq_self
@[simp]
theorem star_eq_neg {a : ℍ[R]} : star a = -a ↔ a.re = 0 :=
QuaternionAlgebra.star_eq_neg
#align quaternion.star_eq_neg Quaternion.star_eq_neg
end CharZero
nonrec theorem star_mul_eq_coe : star a * a = (star a * a).re :=
a.star_mul_eq_coe
#align quaternion.star_mul_eq_coe Quaternion.star_mul_eq_coe
nonrec theorem mul_star_eq_coe : a * star a = (a * star a).re :=
a.mul_star_eq_coe
#align quaternion.mul_star_eq_coe Quaternion.mul_star_eq_coe
open MulOpposite
/-- Quaternion conjugate as an `AlgEquiv` to the opposite ring. -/
def starAe : ℍ[R] ≃ₐ[R] ℍ[R]ᵐᵒᵖ :=
QuaternionAlgebra.starAe
#align quaternion.star_ae Quaternion.starAe
@[simp]
theorem coe_starAe : ⇑(starAe : ℍ[R] ≃ₐ[R] ℍ[R]ᵐᵒᵖ) = op ∘ star :=
rfl
#align quaternion.coe_star_ae Quaternion.coe_starAe
/-- Square of the norm. -/
def normSq : ℍ[R] →*₀ R where
toFun a := (a * star a).re
map_zero' := by simp only [star_zero, zero_mul, zero_re]
map_one' := by simp only [star_one, one_mul, one_re]
map_mul' x y := coe_injective <| by
conv_lhs => rw [← mul_star_eq_coe, star_mul, mul_assoc, ← mul_assoc y, y.mul_star_eq_coe,
coe_commutes, ← mul_assoc, x.mul_star_eq_coe, ← coe_mul]
#align quaternion.norm_sq Quaternion.normSq
theorem normSq_def : normSq a = (a * star a).re := rfl
#align quaternion.norm_sq_def Quaternion.normSq_def
theorem normSq_def' : normSq a = a.1 ^ 2 + a.2 ^ 2 + a.3 ^ 2 + a.4 ^ 2 := by
simp only [normSq_def, sq, mul_neg, sub_neg_eq_add, mul_re, star_re, star_imI, star_imJ,
star_imK]
#align quaternion.norm_sq_def' Quaternion.normSq_def'
theorem normSq_coe : normSq (x : ℍ[R]) = x ^ 2 := by
rw [normSq_def, star_coe, ← coe_mul, coe_re, sq]
#align quaternion.norm_sq_coe Quaternion.normSq_coe
@[simp]
theorem normSq_star : normSq (star a) = normSq a := by simp [normSq_def']
#align quaternion.norm_sq_star Quaternion.normSq_star
@[norm_cast]
theorem normSq_natCast (n : ℕ) : normSq (n : ℍ[R]) = (n : R) ^ 2 := by
rw [← coe_natCast, normSq_coe]
#align quaternion.norm_sq_nat_cast Quaternion.normSq_natCast
@[deprecated (since := "2024-04-17")]
alias normSq_nat_cast := normSq_natCast
@[norm_cast]
theorem normSq_intCast (z : ℤ) : normSq (z : ℍ[R]) = (z : R) ^ 2 := by
rw [← coe_intCast, normSq_coe]
#align quaternion.norm_sq_int_cast Quaternion.normSq_intCast
@[deprecated (since := "2024-04-17")]
alias normSq_int_cast := normSq_intCast
@[simp]
theorem normSq_neg : normSq (-a) = normSq a := by simp only [normSq_def, star_neg, neg_mul_neg]
#align quaternion.norm_sq_neg Quaternion.normSq_neg
theorem self_mul_star : a * star a = normSq a := by rw [mul_star_eq_coe, normSq_def]
#align quaternion.self_mul_star Quaternion.self_mul_star
theorem star_mul_self : star a * a = normSq a := by rw [star_comm_self, self_mul_star]
#align quaternion.star_mul_self Quaternion.star_mul_self
theorem im_sq : a.im ^ 2 = -normSq a.im := by
simp_rw [sq, ← star_mul_self, im_star, neg_mul, neg_neg]
#align quaternion.im_sq Quaternion.im_sq
theorem coe_normSq_add : normSq (a + b) = normSq a + a * star b + b * star a + normSq b := by
simp only [star_add, ← self_mul_star, mul_add, add_mul, add_assoc, add_left_comm]
#align quaternion.coe_norm_sq_add Quaternion.coe_normSq_add
theorem normSq_smul (r : R) (q : ℍ[R]) : normSq (r • q) = r ^ 2 * normSq q := by
simp only [normSq_def', smul_re, smul_imI, smul_imJ, smul_imK, mul_pow, mul_add, smul_eq_mul]
#align quaternion.norm_sq_smul Quaternion.normSq_smul
theorem normSq_add (a b : ℍ[R]) : normSq (a + b) = normSq a + normSq b + 2 * (a * star b).re :=
calc
normSq (a + b) = normSq a + (a * star b).re + ((b * star a).re + normSq b) := by
simp_rw [normSq_def, star_add, add_mul, mul_add, add_re]
_ = normSq a + normSq b + ((a * star b).re + (b * star a).re) := by abel
_ = normSq a + normSq b + 2 * (a * star b).re := by
rw [← add_re, ← star_mul_star a b, self_add_star', coe_re]
#align quaternion.norm_sq_add Quaternion.normSq_add
end Quaternion
namespace Quaternion
variable {R : Type*}
section LinearOrderedCommRing
variable [LinearOrderedCommRing R] {a : ℍ[R]}
@[simp]
theorem normSq_eq_zero : normSq a = 0 ↔ a = 0 := by
refine ⟨fun h => ?_, fun h => h.symm ▸ normSq.map_zero⟩
rw [normSq_def', add_eq_zero_iff', add_eq_zero_iff', add_eq_zero_iff'] at h
· exact ext a 0 (pow_eq_zero h.1.1.1) (pow_eq_zero h.1.1.2) (pow_eq_zero h.1.2) (pow_eq_zero h.2)
all_goals apply_rules [sq_nonneg, add_nonneg]
#align quaternion.norm_sq_eq_zero Quaternion.normSq_eq_zero
theorem normSq_ne_zero : normSq a ≠ 0 ↔ a ≠ 0 := normSq_eq_zero.not
#align quaternion.norm_sq_ne_zero Quaternion.normSq_ne_zero
@[simp]
theorem normSq_nonneg : 0 ≤ normSq a := by
rw [normSq_def']
apply_rules [sq_nonneg, add_nonneg]
#align quaternion.norm_sq_nonneg Quaternion.normSq_nonneg
@[simp]
theorem normSq_le_zero : normSq a ≤ 0 ↔ a = 0 :=
normSq_nonneg.le_iff_eq.trans normSq_eq_zero
#align quaternion.norm_sq_le_zero Quaternion.normSq_le_zero
instance instNontrivial : Nontrivial ℍ[R] where
exists_pair_ne := ⟨0, 1, mt (congr_arg re) zero_ne_one⟩
instance : NoZeroDivisors ℍ[R] where
eq_zero_or_eq_zero_of_mul_eq_zero {a b} hab :=
have : normSq a * normSq b = 0 := by rwa [← map_mul, normSq_eq_zero]
(eq_zero_or_eq_zero_of_mul_eq_zero this).imp normSq_eq_zero.1 normSq_eq_zero.1
instance : IsDomain ℍ[R] := NoZeroDivisors.to_isDomain _
theorem sq_eq_normSq : a ^ 2 = normSq a ↔ a = a.re := by
rw [← star_eq_self, ← star_mul_self, sq, mul_eq_mul_right_iff, eq_comm]
exact or_iff_left_of_imp fun ha ↦ ha.symm ▸ star_zero _
#align quaternion.sq_eq_norm_sq Quaternion.sq_eq_normSq
theorem sq_eq_neg_normSq : a ^ 2 = -normSq a ↔ a.re = 0 := by
simp_rw [← star_eq_neg]
obtain rfl | hq0 := eq_or_ne a 0
· simp
· rw [← star_mul_self, ← mul_neg, ← neg_sq, sq, mul_left_inj' (neg_ne_zero.mpr hq0), eq_comm]
#align quaternion.sq_eq_neg_norm_sq Quaternion.sq_eq_neg_normSq
end LinearOrderedCommRing
section Field
variable [LinearOrderedField R] (a b : ℍ[R])
@[simps (config := .lemmasOnly)]
instance instInv : Inv ℍ[R] :=
⟨fun a => (normSq a)⁻¹ • star a⟩
instance instGroupWithZero : GroupWithZero ℍ[R] :=
{ Quaternion.instNontrivial,
(by infer_instance : MonoidWithZero ℍ[R]) with
inv := Inv.inv
inv_zero := by rw [instInv_inv, star_zero, smul_zero]
mul_inv_cancel := fun a ha => by
-- Porting note: the aliased definition confuse TC search
letI : Semiring ℍ[R] := inferInstanceAs (Semiring ℍ[R,-1,-1])
rw [instInv_inv, Algebra.mul_smul_comm (normSq a)⁻¹ a (star a), self_mul_star, smul_coe,
inv_mul_cancel (normSq_ne_zero.2 ha), coe_one] }
@[norm_cast, simp]
theorem coe_inv (x : R) : ((x⁻¹ : R) : ℍ[R]) = (↑x)⁻¹ :=
map_inv₀ (algebraMap R ℍ[R]) _
#align quaternion.coe_inv Quaternion.coe_inv
@[norm_cast, simp]
theorem coe_div (x y : R) : ((x / y : R) : ℍ[R]) = x / y :=
map_div₀ (algebraMap R ℍ[R]) x y
#align quaternion.coe_div Quaternion.coe_div
@[norm_cast, simp]
theorem coe_zpow (x : R) (z : ℤ) : ((x ^ z : R) : ℍ[R]) = (x : ℍ[R]) ^ z :=
map_zpow₀ (algebraMap R ℍ[R]) x z
#align quaternion.coe_zpow Quaternion.coe_zpow
instance instNNRatCast : NNRatCast ℍ[R] where nnratCast q := (q : R)
instance instRatCast : RatCast ℍ[R] where ratCast q := (q : R)
@[simp, norm_cast] lemma re_nnratCast (q : ℚ≥0) : (q : ℍ[R]).re = q := rfl
@[simp, norm_cast] lemma im_nnratCast (q : ℚ≥0) : (q : ℍ[R]).im = 0 := rfl
@[simp, norm_cast] lemma imI_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imI = 0 := rfl
@[simp, norm_cast] lemma imJ_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imJ = 0 := rfl
@[simp, norm_cast] lemma imK_nnratCast (q : ℚ≥0) : (q : ℍ[R]).imK = 0 := rfl
@[simp, norm_cast] lemma ratCast_re (q : ℚ) : (q : ℍ[R]).re = q := rfl
@[simp, norm_cast] lemma ratCast_im (q : ℚ) : (q : ℍ[R]).im = 0 := rfl
@[simp, norm_cast] lemma ratCast_imI (q : ℚ) : (q : ℍ[R]).imI = 0 := rfl
@[simp, norm_cast] lemma ratCast_imJ (q : ℚ) : (q : ℍ[R]).imJ = 0 := rfl
@[simp, norm_cast] lemma ratCast_imK (q : ℚ) : (q : ℍ[R]).imK = 0 := rfl
#align quaternion.rat_cast_re Quaternion.ratCast_re
#align quaternion.rat_cast_im Quaternion.ratCast_im
#align quaternion.rat_cast_im_i Quaternion.ratCast_imI
#align quaternion.rat_cast_im_j Quaternion.ratCast_imJ
#align quaternion.rat_cast_im_k Quaternion.ratCast_imK
@[deprecated (since := "2024-04-17")]
alias rat_cast_imI := ratCast_imI
@[deprecated (since := "2024-04-17")]
alias rat_cast_imJ := ratCast_imJ
@[deprecated (since := "2024-04-17")]
alias rat_cast_imK := ratCast_imK
@[norm_cast] lemma coe_nnratCast (q : ℚ≥0) : ↑(q : R) = (q : ℍ[R]) := rfl
@[norm_cast] lemma coe_ratCast (q : ℚ) : ↑(q : R) = (q : ℍ[R]) := rfl
#align quaternion.coe_rat_cast Quaternion.coe_ratCast
@[deprecated (since := "2024-04-17")]
alias coe_rat_cast := coe_ratCast
instance instDivisionRing : DivisionRing ℍ[R] where
__ := Quaternion.instGroupWithZero
__ := Quaternion.instRing
nnqsmul := (· • ·)
qsmul := (· • ·)
nnratCast_def q := by rw [← coe_nnratCast, NNRat.cast_def, coe_div, coe_natCast, coe_natCast]
ratCast_def q := by rw [← coe_ratCast, Rat.cast_def, coe_div, coe_intCast, coe_natCast]
nnqsmul_def q x := by rw [← coe_nnratCast, coe_mul_eq_smul]; ext <;> exact NNRat.smul_def _ _
qsmul_def q x := by rw [← coe_ratCast, coe_mul_eq_smul]; ext <;> exact Rat.smul_def _ _
--@[simp] Porting note (#10618): `simp` can prove it
theorem normSq_inv : normSq a⁻¹ = (normSq a)⁻¹ :=
map_inv₀ normSq _
#align quaternion.norm_sq_inv Quaternion.normSq_inv
--@[simp] Porting note (#10618): `simp` can prove it
theorem normSq_div : normSq (a / b) = normSq a / normSq b :=
map_div₀ normSq a b
#align quaternion.norm_sq_div Quaternion.normSq_div
--@[simp] Porting note (#10618): `simp` can prove it
theorem normSq_zpow (z : ℤ) : normSq (a ^ z) = normSq a ^ z :=
map_zpow₀ normSq a z
#align quaternion.norm_sq_zpow Quaternion.normSq_zpow
@[norm_cast]
theorem normSq_ratCast (q : ℚ) : normSq (q : ℍ[R]) = (q : ℍ[R]) ^ 2 := by
rw [← coe_ratCast, normSq_coe, coe_pow]
#align quaternion.norm_sq_rat_cast Quaternion.normSq_ratCast
@[deprecated (since := "2024-04-17")]
alias normSq_rat_cast := normSq_ratCast
end Field
end Quaternion
namespace Cardinal
open Quaternion
section QuaternionAlgebra
variable {R : Type*} (c₁ c₂ : R)
private theorem pow_four [Infinite R] : #R ^ 4 = #R :=
power_nat_eq (aleph0_le_mk R) <| by decide
/-- The cardinality of a quaternion algebra, as a type. -/
theorem mk_quaternionAlgebra : #(ℍ[R,c₁,c₂]) = #R ^ 4 := by
rw [mk_congr (QuaternionAlgebra.equivProd c₁ c₂)]
simp only [mk_prod, lift_id]
ring
#align cardinal.mk_quaternion_algebra Cardinal.mk_quaternionAlgebra
@[simp]
| Mathlib/Algebra/Quaternion.lean | 1,546 | 1,547 | theorem mk_quaternionAlgebra_of_infinite [Infinite R] : #(ℍ[R,c₁,c₂]) = #R := by |
rw [mk_quaternionAlgebra, pow_four]
|
/-
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, Scott Morrison
-/
import Mathlib.Algebra.BigOperators.Finsupp
import Mathlib.Algebra.Module.Basic
import Mathlib.Algebra.Regular.SMul
import Mathlib.Data.Finset.Preimage
import Mathlib.Data.Rat.BigOperators
import Mathlib.GroupTheory.GroupAction.Hom
import Mathlib.Data.Set.Subsingleton
#align_import data.finsupp.basic from "leanprover-community/mathlib"@"f69db8cecc668e2d5894d7e9bfc491da60db3b9f"
/-!
# Miscellaneous definitions, lemmas, and constructions using finsupp
## Main declarations
* `Finsupp.graph`: the finset of input and output pairs with non-zero outputs.
* `Finsupp.mapRange.equiv`: `Finsupp.mapRange` as an equiv.
* `Finsupp.mapDomain`: maps the domain of a `Finsupp` by a function and by summing.
* `Finsupp.comapDomain`: postcomposition of a `Finsupp` with a function injective on the preimage
of its support.
* `Finsupp.some`: restrict a finitely supported function on `Option α` to a finitely supported
function on `α`.
* `Finsupp.filter`: `filter p f` is the finitely supported function that is `f a` if `p a` is true
and 0 otherwise.
* `Finsupp.frange`: the image of a finitely supported function on its support.
* `Finsupp.subtype_domain`: the restriction of a finitely supported function `f` to a subtype.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## TODO
* This file is currently ~1600 lines long and is quite a miscellany of definitions and lemmas,
so it should be divided into smaller pieces.
* Expand the list of definitions and important lemmas to the module docstring.
-/
noncomputable section
open Finset Function
variable {α β γ ι M M' N P G H R S : Type*}
namespace Finsupp
/-! ### Declarations about `graph` -/
section Graph
variable [Zero M]
/-- The graph of a finitely supported function over its support, i.e. the finset of input and output
pairs with non-zero outputs. -/
def graph (f : α →₀ M) : Finset (α × M) :=
f.support.map ⟨fun a => Prod.mk a (f a), fun _ _ h => (Prod.mk.inj h).1⟩
#align finsupp.graph Finsupp.graph
theorem mk_mem_graph_iff {a : α} {m : M} {f : α →₀ M} : (a, m) ∈ f.graph ↔ f a = m ∧ m ≠ 0 := by
simp_rw [graph, mem_map, mem_support_iff]
constructor
· rintro ⟨b, ha, rfl, -⟩
exact ⟨rfl, ha⟩
· rintro ⟨rfl, ha⟩
exact ⟨a, ha, rfl⟩
#align finsupp.mk_mem_graph_iff Finsupp.mk_mem_graph_iff
@[simp]
theorem mem_graph_iff {c : α × M} {f : α →₀ M} : c ∈ f.graph ↔ f c.1 = c.2 ∧ c.2 ≠ 0 := by
cases c
exact mk_mem_graph_iff
#align finsupp.mem_graph_iff Finsupp.mem_graph_iff
theorem mk_mem_graph (f : α →₀ M) {a : α} (ha : a ∈ f.support) : (a, f a) ∈ f.graph :=
mk_mem_graph_iff.2 ⟨rfl, mem_support_iff.1 ha⟩
#align finsupp.mk_mem_graph Finsupp.mk_mem_graph
theorem apply_eq_of_mem_graph {a : α} {m : M} {f : α →₀ M} (h : (a, m) ∈ f.graph) : f a = m :=
(mem_graph_iff.1 h).1
#align finsupp.apply_eq_of_mem_graph Finsupp.apply_eq_of_mem_graph
@[simp 1100] -- Porting note: change priority to appease `simpNF`
theorem not_mem_graph_snd_zero (a : α) (f : α →₀ M) : (a, (0 : M)) ∉ f.graph := fun h =>
(mem_graph_iff.1 h).2.irrefl
#align finsupp.not_mem_graph_snd_zero Finsupp.not_mem_graph_snd_zero
@[simp]
theorem image_fst_graph [DecidableEq α] (f : α →₀ M) : f.graph.image Prod.fst = f.support := by
classical simp only [graph, map_eq_image, image_image, Embedding.coeFn_mk, (· ∘ ·), image_id']
#align finsupp.image_fst_graph Finsupp.image_fst_graph
theorem graph_injective (α M) [Zero M] : Injective (@graph α M _) := by
intro f g h
classical
have hsup : f.support = g.support := by rw [← image_fst_graph, h, image_fst_graph]
refine ext_iff'.2 ⟨hsup, fun x hx => apply_eq_of_mem_graph <| h.symm ▸ ?_⟩
exact mk_mem_graph _ (hsup ▸ hx)
#align finsupp.graph_injective Finsupp.graph_injective
@[simp]
theorem graph_inj {f g : α →₀ M} : f.graph = g.graph ↔ f = g :=
(graph_injective α M).eq_iff
#align finsupp.graph_inj Finsupp.graph_inj
@[simp]
theorem graph_zero : graph (0 : α →₀ M) = ∅ := by simp [graph]
#align finsupp.graph_zero Finsupp.graph_zero
@[simp]
theorem graph_eq_empty {f : α →₀ M} : f.graph = ∅ ↔ f = 0 :=
(graph_injective α M).eq_iff' graph_zero
#align finsupp.graph_eq_empty Finsupp.graph_eq_empty
end Graph
end Finsupp
/-! ### Declarations about `mapRange` -/
section MapRange
namespace Finsupp
section Equiv
variable [Zero M] [Zero N] [Zero P]
/-- `Finsupp.mapRange` as an equiv. -/
@[simps apply]
def mapRange.equiv (f : M ≃ N) (hf : f 0 = 0) (hf' : f.symm 0 = 0) : (α →₀ M) ≃ (α →₀ N) where
toFun := (mapRange f hf : (α →₀ M) → α →₀ N)
invFun := (mapRange f.symm hf' : (α →₀ N) → α →₀ M)
left_inv x := by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.symm_comp_self]
· exact mapRange_id _
· rfl
right_inv x := by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.self_comp_symm]
· exact mapRange_id _
· rfl
#align finsupp.map_range.equiv Finsupp.mapRange.equiv
@[simp]
theorem mapRange.equiv_refl : mapRange.equiv (Equiv.refl M) rfl rfl = Equiv.refl (α →₀ M) :=
Equiv.ext mapRange_id
#align finsupp.map_range.equiv_refl Finsupp.mapRange.equiv_refl
theorem mapRange.equiv_trans (f : M ≃ N) (hf : f 0 = 0) (hf') (f₂ : N ≃ P) (hf₂ : f₂ 0 = 0) (hf₂') :
(mapRange.equiv (f.trans f₂) (by rw [Equiv.trans_apply, hf, hf₂])
(by rw [Equiv.symm_trans_apply, hf₂', hf']) :
(α →₀ _) ≃ _) =
(mapRange.equiv f hf hf').trans (mapRange.equiv f₂ hf₂ hf₂') :=
Equiv.ext <| mapRange_comp f₂ hf₂ f hf ((congrArg f₂ hf).trans hf₂)
#align finsupp.map_range.equiv_trans Finsupp.mapRange.equiv_trans
@[simp]
theorem mapRange.equiv_symm (f : M ≃ N) (hf hf') :
((mapRange.equiv f hf hf').symm : (α →₀ _) ≃ _) = mapRange.equiv f.symm hf' hf :=
Equiv.ext fun _ => rfl
#align finsupp.map_range.equiv_symm Finsupp.mapRange.equiv_symm
end Equiv
section ZeroHom
variable [Zero M] [Zero N] [Zero P]
/-- Composition with a fixed zero-preserving homomorphism is itself a zero-preserving homomorphism
on functions. -/
@[simps]
def mapRange.zeroHom (f : ZeroHom M N) : ZeroHom (α →₀ M) (α →₀ N) where
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
map_zero' := mapRange_zero
#align finsupp.map_range.zero_hom Finsupp.mapRange.zeroHom
@[simp]
theorem mapRange.zeroHom_id : mapRange.zeroHom (ZeroHom.id M) = ZeroHom.id (α →₀ M) :=
ZeroHom.ext mapRange_id
#align finsupp.map_range.zero_hom_id Finsupp.mapRange.zeroHom_id
theorem mapRange.zeroHom_comp (f : ZeroHom N P) (f₂ : ZeroHom M N) :
(mapRange.zeroHom (f.comp f₂) : ZeroHom (α →₀ _) _) =
(mapRange.zeroHom f).comp (mapRange.zeroHom f₂) :=
ZeroHom.ext <| mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero])
#align finsupp.map_range.zero_hom_comp Finsupp.mapRange.zeroHom_comp
end ZeroHom
section AddMonoidHom
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable {F : Type*} [FunLike F M N] [AddMonoidHomClass F M N]
/-- Composition with a fixed additive homomorphism is itself an additive homomorphism on functions.
-/
@[simps]
def mapRange.addMonoidHom (f : M →+ N) : (α →₀ M) →+ α →₀ N where
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
map_zero' := mapRange_zero
map_add' a b := by dsimp only; exact mapRange_add f.map_add _ _; -- Porting note: `dsimp` needed
#align finsupp.map_range.add_monoid_hom Finsupp.mapRange.addMonoidHom
@[simp]
theorem mapRange.addMonoidHom_id :
mapRange.addMonoidHom (AddMonoidHom.id M) = AddMonoidHom.id (α →₀ M) :=
AddMonoidHom.ext mapRange_id
#align finsupp.map_range.add_monoid_hom_id Finsupp.mapRange.addMonoidHom_id
theorem mapRange.addMonoidHom_comp (f : N →+ P) (f₂ : M →+ N) :
(mapRange.addMonoidHom (f.comp f₂) : (α →₀ _) →+ _) =
(mapRange.addMonoidHom f).comp (mapRange.addMonoidHom f₂) :=
AddMonoidHom.ext <|
mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero])
#align finsupp.map_range.add_monoid_hom_comp Finsupp.mapRange.addMonoidHom_comp
@[simp]
theorem mapRange.addMonoidHom_toZeroHom (f : M →+ N) :
(mapRange.addMonoidHom f).toZeroHom = (mapRange.zeroHom f.toZeroHom : ZeroHom (α →₀ _) _) :=
ZeroHom.ext fun _ => rfl
#align finsupp.map_range.add_monoid_hom_to_zero_hom Finsupp.mapRange.addMonoidHom_toZeroHom
theorem mapRange_multiset_sum (f : F) (m : Multiset (α →₀ M)) :
mapRange f (map_zero f) m.sum = (m.map fun x => mapRange f (map_zero f) x).sum :=
(mapRange.addMonoidHom (f : M →+ N) : (α →₀ _) →+ _).map_multiset_sum _
#align finsupp.map_range_multiset_sum Finsupp.mapRange_multiset_sum
theorem mapRange_finset_sum (f : F) (s : Finset ι) (g : ι → α →₀ M) :
mapRange f (map_zero f) (∑ x ∈ s, g x) = ∑ x ∈ s, mapRange f (map_zero f) (g x) :=
map_sum (mapRange.addMonoidHom (f : M →+ N)) _ _
#align finsupp.map_range_finset_sum Finsupp.mapRange_finset_sum
/-- `Finsupp.mapRange.AddMonoidHom` as an equiv. -/
@[simps apply]
def mapRange.addEquiv (f : M ≃+ N) : (α →₀ M) ≃+ (α →₀ N) :=
{ mapRange.addMonoidHom f.toAddMonoidHom with
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
invFun := (mapRange f.symm f.symm.map_zero : (α →₀ N) → α →₀ M)
left_inv := fun x => by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.symm_comp_self]
· exact mapRange_id _
· rfl
right_inv := fun x => by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.self_comp_symm]
· exact mapRange_id _
· rfl }
#align finsupp.map_range.add_equiv Finsupp.mapRange.addEquiv
@[simp]
theorem mapRange.addEquiv_refl : mapRange.addEquiv (AddEquiv.refl M) = AddEquiv.refl (α →₀ M) :=
AddEquiv.ext mapRange_id
#align finsupp.map_range.add_equiv_refl Finsupp.mapRange.addEquiv_refl
theorem mapRange.addEquiv_trans (f : M ≃+ N) (f₂ : N ≃+ P) :
(mapRange.addEquiv (f.trans f₂) : (α →₀ M) ≃+ (α →₀ P)) =
(mapRange.addEquiv f).trans (mapRange.addEquiv f₂) :=
AddEquiv.ext (mapRange_comp _ f₂.map_zero _ f.map_zero (by simp))
#align finsupp.map_range.add_equiv_trans Finsupp.mapRange.addEquiv_trans
@[simp]
theorem mapRange.addEquiv_symm (f : M ≃+ N) :
((mapRange.addEquiv f).symm : (α →₀ _) ≃+ _) = mapRange.addEquiv f.symm :=
AddEquiv.ext fun _ => rfl
#align finsupp.map_range.add_equiv_symm Finsupp.mapRange.addEquiv_symm
@[simp]
theorem mapRange.addEquiv_toAddMonoidHom (f : M ≃+ N) :
((mapRange.addEquiv f : (α →₀ _) ≃+ _) : _ →+ _) =
(mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ _) →+ _) :=
AddMonoidHom.ext fun _ => rfl
#align finsupp.map_range.add_equiv_to_add_monoid_hom Finsupp.mapRange.addEquiv_toAddMonoidHom
@[simp]
theorem mapRange.addEquiv_toEquiv (f : M ≃+ N) :
↑(mapRange.addEquiv f : (α →₀ _) ≃+ _) =
(mapRange.equiv (f : M ≃ N) f.map_zero f.symm.map_zero : (α →₀ _) ≃ _) :=
Equiv.ext fun _ => rfl
#align finsupp.map_range.add_equiv_to_equiv Finsupp.mapRange.addEquiv_toEquiv
end AddMonoidHom
end Finsupp
end MapRange
/-! ### Declarations about `equivCongrLeft` -/
section EquivCongrLeft
variable [Zero M]
namespace Finsupp
/-- Given `f : α ≃ β`, we can map `l : α →₀ M` to `equivMapDomain f l : β →₀ M` (computably)
by mapping the support forwards and the function backwards. -/
def equivMapDomain (f : α ≃ β) (l : α →₀ M) : β →₀ M where
support := l.support.map f.toEmbedding
toFun a := l (f.symm a)
mem_support_toFun a := by simp only [Finset.mem_map_equiv, mem_support_toFun]; rfl
#align finsupp.equiv_map_domain Finsupp.equivMapDomain
@[simp]
theorem equivMapDomain_apply (f : α ≃ β) (l : α →₀ M) (b : β) :
equivMapDomain f l b = l (f.symm b) :=
rfl
#align finsupp.equiv_map_domain_apply Finsupp.equivMapDomain_apply
theorem equivMapDomain_symm_apply (f : α ≃ β) (l : β →₀ M) (a : α) :
equivMapDomain f.symm l a = l (f a) :=
rfl
#align finsupp.equiv_map_domain_symm_apply Finsupp.equivMapDomain_symm_apply
@[simp]
theorem equivMapDomain_refl (l : α →₀ M) : equivMapDomain (Equiv.refl _) l = l := by ext x; rfl
#align finsupp.equiv_map_domain_refl Finsupp.equivMapDomain_refl
theorem equivMapDomain_refl' : equivMapDomain (Equiv.refl _) = @id (α →₀ M) := by ext x; rfl
#align finsupp.equiv_map_domain_refl' Finsupp.equivMapDomain_refl'
theorem equivMapDomain_trans (f : α ≃ β) (g : β ≃ γ) (l : α →₀ M) :
equivMapDomain (f.trans g) l = equivMapDomain g (equivMapDomain f l) := by ext x; rfl
#align finsupp.equiv_map_domain_trans Finsupp.equivMapDomain_trans
theorem equivMapDomain_trans' (f : α ≃ β) (g : β ≃ γ) :
@equivMapDomain _ _ M _ (f.trans g) = equivMapDomain g ∘ equivMapDomain f := by ext x; rfl
#align finsupp.equiv_map_domain_trans' Finsupp.equivMapDomain_trans'
@[simp]
theorem equivMapDomain_single (f : α ≃ β) (a : α) (b : M) :
equivMapDomain f (single a b) = single (f a) b := by
classical
ext x
simp only [single_apply, Equiv.apply_eq_iff_eq_symm_apply, equivMapDomain_apply]
#align finsupp.equiv_map_domain_single Finsupp.equivMapDomain_single
@[simp]
theorem equivMapDomain_zero {f : α ≃ β} : equivMapDomain f (0 : α →₀ M) = (0 : β →₀ M) := by
ext; simp only [equivMapDomain_apply, coe_zero, Pi.zero_apply]
#align finsupp.equiv_map_domain_zero Finsupp.equivMapDomain_zero
@[to_additive (attr := simp)]
theorem prod_equivMapDomain [CommMonoid N] (f : α ≃ β) (l : α →₀ M) (g : β → M → N):
prod (equivMapDomain f l) g = prod l (fun a m => g (f a) m) := by
simp [prod, equivMapDomain]
/-- Given `f : α ≃ β`, the finitely supported function spaces are also in bijection:
`(α →₀ M) ≃ (β →₀ M)`.
This is the finitely-supported version of `Equiv.piCongrLeft`. -/
def equivCongrLeft (f : α ≃ β) : (α →₀ M) ≃ (β →₀ M) := by
refine ⟨equivMapDomain f, equivMapDomain f.symm, fun f => ?_, fun f => ?_⟩ <;> ext x <;>
simp only [equivMapDomain_apply, Equiv.symm_symm, Equiv.symm_apply_apply,
Equiv.apply_symm_apply]
#align finsupp.equiv_congr_left Finsupp.equivCongrLeft
@[simp]
theorem equivCongrLeft_apply (f : α ≃ β) (l : α →₀ M) : equivCongrLeft f l = equivMapDomain f l :=
rfl
#align finsupp.equiv_congr_left_apply Finsupp.equivCongrLeft_apply
@[simp]
theorem equivCongrLeft_symm (f : α ≃ β) :
(@equivCongrLeft _ _ M _ f).symm = equivCongrLeft f.symm :=
rfl
#align finsupp.equiv_congr_left_symm Finsupp.equivCongrLeft_symm
end Finsupp
end EquivCongrLeft
section CastFinsupp
variable [Zero M] (f : α →₀ M)
namespace Nat
@[simp, norm_cast]
theorem cast_finsupp_prod [CommSemiring R] (g : α → M → ℕ) :
(↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
Nat.cast_prod _ _
#align nat.cast_finsupp_prod Nat.cast_finsupp_prod
@[simp, norm_cast]
theorem cast_finsupp_sum [CommSemiring R] (g : α → M → ℕ) :
(↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
Nat.cast_sum _ _
#align nat.cast_finsupp_sum Nat.cast_finsupp_sum
end Nat
namespace Int
@[simp, norm_cast]
theorem cast_finsupp_prod [CommRing R] (g : α → M → ℤ) :
(↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
Int.cast_prod _ _
#align int.cast_finsupp_prod Int.cast_finsupp_prod
@[simp, norm_cast]
theorem cast_finsupp_sum [CommRing R] (g : α → M → ℤ) :
(↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
Int.cast_sum _ _
#align int.cast_finsupp_sum Int.cast_finsupp_sum
end Int
namespace Rat
@[simp, norm_cast]
theorem cast_finsupp_sum [DivisionRing R] [CharZero R] (g : α → M → ℚ) :
(↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
cast_sum _ _
#align rat.cast_finsupp_sum Rat.cast_finsupp_sum
@[simp, norm_cast]
theorem cast_finsupp_prod [Field R] [CharZero R] (g : α → M → ℚ) :
(↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
cast_prod _ _
#align rat.cast_finsupp_prod Rat.cast_finsupp_prod
end Rat
end CastFinsupp
/-! ### Declarations about `mapDomain` -/
namespace Finsupp
section MapDomain
variable [AddCommMonoid M] {v v₁ v₂ : α →₀ M}
/-- Given `f : α → β` and `v : α →₀ M`, `mapDomain f v : β →₀ M`
is the finitely supported function whose value at `a : β` is the sum
of `v x` over all `x` such that `f x = a`. -/
def mapDomain (f : α → β) (v : α →₀ M) : β →₀ M :=
v.sum fun a => single (f a)
#align finsupp.map_domain Finsupp.mapDomain
theorem mapDomain_apply {f : α → β} (hf : Function.Injective f) (x : α →₀ M) (a : α) :
mapDomain f x (f a) = x a := by
rw [mapDomain, sum_apply, sum_eq_single a, single_eq_same]
· intro b _ hba
exact single_eq_of_ne (hf.ne hba)
· intro _
rw [single_zero, coe_zero, Pi.zero_apply]
#align finsupp.map_domain_apply Finsupp.mapDomain_apply
theorem mapDomain_notin_range {f : α → β} (x : α →₀ M) (a : β) (h : a ∉ Set.range f) :
mapDomain f x a = 0 := by
rw [mapDomain, sum_apply, sum]
exact Finset.sum_eq_zero fun a' _ => single_eq_of_ne fun eq => h <| eq ▸ Set.mem_range_self _
#align finsupp.map_domain_notin_range Finsupp.mapDomain_notin_range
@[simp]
theorem mapDomain_id : mapDomain id v = v :=
sum_single _
#align finsupp.map_domain_id Finsupp.mapDomain_id
theorem mapDomain_comp {f : α → β} {g : β → γ} :
mapDomain (g ∘ f) v = mapDomain g (mapDomain f v) := by
refine ((sum_sum_index ?_ ?_).trans ?_).symm
· intro
exact single_zero _
· intro
exact single_add _
refine sum_congr fun _ _ => sum_single_index ?_
exact single_zero _
#align finsupp.map_domain_comp Finsupp.mapDomain_comp
@[simp]
theorem mapDomain_single {f : α → β} {a : α} {b : M} : mapDomain f (single a b) = single (f a) b :=
sum_single_index <| single_zero _
#align finsupp.map_domain_single Finsupp.mapDomain_single
@[simp]
theorem mapDomain_zero {f : α → β} : mapDomain f (0 : α →₀ M) = (0 : β →₀ M) :=
sum_zero_index
#align finsupp.map_domain_zero Finsupp.mapDomain_zero
theorem mapDomain_congr {f g : α → β} (h : ∀ x ∈ v.support, f x = g x) :
v.mapDomain f = v.mapDomain g :=
Finset.sum_congr rfl fun _ H => by simp only [h _ H]
#align finsupp.map_domain_congr Finsupp.mapDomain_congr
theorem mapDomain_add {f : α → β} : mapDomain f (v₁ + v₂) = mapDomain f v₁ + mapDomain f v₂ :=
sum_add_index' (fun _ => single_zero _) fun _ => single_add _
#align finsupp.map_domain_add Finsupp.mapDomain_add
@[simp]
theorem mapDomain_equiv_apply {f : α ≃ β} (x : α →₀ M) (a : β) :
mapDomain f x a = x (f.symm a) := by
conv_lhs => rw [← f.apply_symm_apply a]
exact mapDomain_apply f.injective _ _
#align finsupp.map_domain_equiv_apply Finsupp.mapDomain_equiv_apply
/-- `Finsupp.mapDomain` is an `AddMonoidHom`. -/
@[simps]
def mapDomain.addMonoidHom (f : α → β) : (α →₀ M) →+ β →₀ M where
toFun := mapDomain f
map_zero' := mapDomain_zero
map_add' _ _ := mapDomain_add
#align finsupp.map_domain.add_monoid_hom Finsupp.mapDomain.addMonoidHom
@[simp]
theorem mapDomain.addMonoidHom_id : mapDomain.addMonoidHom id = AddMonoidHom.id (α →₀ M) :=
AddMonoidHom.ext fun _ => mapDomain_id
#align finsupp.map_domain.add_monoid_hom_id Finsupp.mapDomain.addMonoidHom_id
theorem mapDomain.addMonoidHom_comp (f : β → γ) (g : α → β) :
(mapDomain.addMonoidHom (f ∘ g) : (α →₀ M) →+ γ →₀ M) =
(mapDomain.addMonoidHom f).comp (mapDomain.addMonoidHom g) :=
AddMonoidHom.ext fun _ => mapDomain_comp
#align finsupp.map_domain.add_monoid_hom_comp Finsupp.mapDomain.addMonoidHom_comp
theorem mapDomain_finset_sum {f : α → β} {s : Finset ι} {v : ι → α →₀ M} :
mapDomain f (∑ i ∈ s, v i) = ∑ i ∈ s, mapDomain f (v i) :=
map_sum (mapDomain.addMonoidHom f) _ _
#align finsupp.map_domain_finset_sum Finsupp.mapDomain_finset_sum
theorem mapDomain_sum [Zero N] {f : α → β} {s : α →₀ N} {v : α → N → α →₀ M} :
mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b) :=
map_finsupp_sum (mapDomain.addMonoidHom f : (α →₀ M) →+ β →₀ M) _ _
#align finsupp.map_domain_sum Finsupp.mapDomain_sum
theorem mapDomain_support [DecidableEq β] {f : α → β} {s : α →₀ M} :
(s.mapDomain f).support ⊆ s.support.image f :=
Finset.Subset.trans support_sum <|
Finset.Subset.trans (Finset.biUnion_mono fun a _ => support_single_subset) <| by
rw [Finset.biUnion_singleton]
#align finsupp.map_domain_support Finsupp.mapDomain_support
theorem mapDomain_apply' (S : Set α) {f : α → β} (x : α →₀ M) (hS : (x.support : Set α) ⊆ S)
(hf : Set.InjOn f S) {a : α} (ha : a ∈ S) : mapDomain f x (f a) = x a := by
classical
rw [mapDomain, sum_apply, sum]
simp_rw [single_apply]
by_cases hax : a ∈ x.support
· rw [← Finset.add_sum_erase _ _ hax, if_pos rfl]
convert add_zero (x a)
refine Finset.sum_eq_zero fun i hi => if_neg ?_
exact (hf.mono hS).ne (Finset.mem_of_mem_erase hi) hax (Finset.ne_of_mem_erase hi)
· rw [not_mem_support_iff.1 hax]
refine Finset.sum_eq_zero fun i hi => if_neg ?_
exact hf.ne (hS hi) ha (ne_of_mem_of_not_mem hi hax)
#align finsupp.map_domain_apply' Finsupp.mapDomain_apply'
theorem mapDomain_support_of_injOn [DecidableEq β] {f : α → β} (s : α →₀ M)
(hf : Set.InjOn f s.support) : (mapDomain f s).support = Finset.image f s.support :=
Finset.Subset.antisymm mapDomain_support <| by
intro x hx
simp only [mem_image, exists_prop, mem_support_iff, Ne] at hx
rcases hx with ⟨hx_w, hx_h_left, rfl⟩
simp only [mem_support_iff, Ne]
rw [mapDomain_apply' (↑s.support : Set _) _ _ hf]
· exact hx_h_left
· simp only [mem_coe, mem_support_iff, Ne]
exact hx_h_left
· exact Subset.refl _
#align finsupp.map_domain_support_of_inj_on Finsupp.mapDomain_support_of_injOn
theorem mapDomain_support_of_injective [DecidableEq β] {f : α → β} (hf : Function.Injective f)
(s : α →₀ M) : (mapDomain f s).support = Finset.image f s.support :=
mapDomain_support_of_injOn s hf.injOn
#align finsupp.map_domain_support_of_injective Finsupp.mapDomain_support_of_injective
@[to_additive]
theorem prod_mapDomain_index [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N}
(h_zero : ∀ b, h b 0 = 1) (h_add : ∀ b m₁ m₂, h b (m₁ + m₂) = h b m₁ * h b m₂) :
(mapDomain f s).prod h = s.prod fun a m => h (f a) m :=
(prod_sum_index h_zero h_add).trans <| prod_congr fun _ _ => prod_single_index (h_zero _)
#align finsupp.prod_map_domain_index Finsupp.prod_mapDomain_index
#align finsupp.sum_map_domain_index Finsupp.sum_mapDomain_index
-- Note that in `prod_mapDomain_index`, `M` is still an additive monoid,
-- so there is no analogous version in terms of `MonoidHom`.
/-- A version of `sum_mapDomain_index` that takes a bundled `AddMonoidHom`,
rather than separate linearity hypotheses.
-/
@[simp]
theorem sum_mapDomain_index_addMonoidHom [AddCommMonoid N] {f : α → β} {s : α →₀ M}
(h : β → M →+ N) : ((mapDomain f s).sum fun b m => h b m) = s.sum fun a m => h (f a) m :=
sum_mapDomain_index (fun b => (h b).map_zero) (fun b _ _ => (h b).map_add _ _)
#align finsupp.sum_map_domain_index_add_monoid_hom Finsupp.sum_mapDomain_index_addMonoidHom
theorem embDomain_eq_mapDomain (f : α ↪ β) (v : α →₀ M) : embDomain f v = mapDomain f v := by
ext a
by_cases h : a ∈ Set.range f
· rcases h with ⟨a, rfl⟩
rw [mapDomain_apply f.injective, embDomain_apply]
· rw [mapDomain_notin_range, embDomain_notin_range] <;> assumption
#align finsupp.emb_domain_eq_map_domain Finsupp.embDomain_eq_mapDomain
@[to_additive]
theorem prod_mapDomain_index_inj [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N}
(hf : Function.Injective f) : (s.mapDomain f).prod h = s.prod fun a b => h (f a) b := by
rw [← Function.Embedding.coeFn_mk f hf, ← embDomain_eq_mapDomain, prod_embDomain]
#align finsupp.prod_map_domain_index_inj Finsupp.prod_mapDomain_index_inj
#align finsupp.sum_map_domain_index_inj Finsupp.sum_mapDomain_index_inj
theorem mapDomain_injective {f : α → β} (hf : Function.Injective f) :
Function.Injective (mapDomain f : (α →₀ M) → β →₀ M) := by
intro v₁ v₂ eq
ext a
have : mapDomain f v₁ (f a) = mapDomain f v₂ (f a) := by rw [eq]
rwa [mapDomain_apply hf, mapDomain_apply hf] at this
#align finsupp.map_domain_injective Finsupp.mapDomain_injective
/-- When `f` is an embedding we have an embedding `(α →₀ ℕ) ↪ (β →₀ ℕ)` given by `mapDomain`. -/
@[simps]
def mapDomainEmbedding {α β : Type*} (f : α ↪ β) : (α →₀ ℕ) ↪ β →₀ ℕ :=
⟨Finsupp.mapDomain f, Finsupp.mapDomain_injective f.injective⟩
#align finsupp.map_domain_embedding Finsupp.mapDomainEmbedding
theorem mapDomain.addMonoidHom_comp_mapRange [AddCommMonoid N] (f : α → β) (g : M →+ N) :
(mapDomain.addMonoidHom f).comp (mapRange.addMonoidHom g) =
(mapRange.addMonoidHom g).comp (mapDomain.addMonoidHom f) := by
ext
simp only [AddMonoidHom.coe_comp, Finsupp.mapRange_single, Finsupp.mapDomain.addMonoidHom_apply,
Finsupp.singleAddHom_apply, eq_self_iff_true, Function.comp_apply, Finsupp.mapDomain_single,
Finsupp.mapRange.addMonoidHom_apply]
#align finsupp.map_domain.add_monoid_hom_comp_map_range Finsupp.mapDomain.addMonoidHom_comp_mapRange
/-- When `g` preserves addition, `mapRange` and `mapDomain` commute. -/
theorem mapDomain_mapRange [AddCommMonoid N] (f : α → β) (v : α →₀ M) (g : M → N) (h0 : g 0 = 0)
(hadd : ∀ x y, g (x + y) = g x + g y) :
mapDomain f (mapRange g h0 v) = mapRange g h0 (mapDomain f v) :=
let g' : M →+ N :=
{ toFun := g
map_zero' := h0
map_add' := hadd }
DFunLike.congr_fun (mapDomain.addMonoidHom_comp_mapRange f g') v
#align finsupp.map_domain_map_range Finsupp.mapDomain_mapRange
theorem sum_update_add [AddCommMonoid α] [AddCommMonoid β] (f : ι →₀ α) (i : ι) (a : α)
(g : ι → α → β) (hg : ∀ i, g i 0 = 0)
(hgg : ∀ (j : ι) (a₁ a₂ : α), g j (a₁ + a₂) = g j a₁ + g j a₂) :
(f.update i a).sum g + g i (f i) = f.sum g + g i a := by
rw [update_eq_erase_add_single, sum_add_index' hg hgg]
conv_rhs => rw [← Finsupp.update_self f i]
rw [update_eq_erase_add_single, sum_add_index' hg hgg, add_assoc, add_assoc]
congr 1
rw [add_comm, sum_single_index (hg _), sum_single_index (hg _)]
#align finsupp.sum_update_add Finsupp.sum_update_add
theorem mapDomain_injOn (S : Set α) {f : α → β} (hf : Set.InjOn f S) :
Set.InjOn (mapDomain f : (α →₀ M) → β →₀ M) { w | (w.support : Set α) ⊆ S } := by
intro v₁ hv₁ v₂ hv₂ eq
ext a
classical
by_cases h : a ∈ v₁.support ∪ v₂.support
· rw [← mapDomain_apply' S _ hv₁ hf _, ← mapDomain_apply' S _ hv₂ hf _, eq] <;>
· apply Set.union_subset hv₁ hv₂
exact mod_cast h
· simp only [not_or, mem_union, not_not, mem_support_iff] at h
simp [h]
#align finsupp.map_domain_inj_on Finsupp.mapDomain_injOn
theorem equivMapDomain_eq_mapDomain {M} [AddCommMonoid M] (f : α ≃ β) (l : α →₀ M) :
equivMapDomain f l = mapDomain f l := by ext x; simp [mapDomain_equiv_apply]
#align finsupp.equiv_map_domain_eq_map_domain Finsupp.equivMapDomain_eq_mapDomain
end MapDomain
/-! ### Declarations about `comapDomain` -/
section ComapDomain
/-- Given `f : α → β`, `l : β →₀ M` and a proof `hf` that `f` is injective on
the preimage of `l.support`, `comapDomain f l hf` is the finitely supported function
from `α` to `M` given by composing `l` with `f`. -/
@[simps support]
def comapDomain [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) :
α →₀ M where
support := l.support.preimage f hf
toFun a := l (f a)
mem_support_toFun := by
intro a
simp only [Finset.mem_def.symm, Finset.mem_preimage]
exact l.mem_support_toFun (f a)
#align finsupp.comap_domain Finsupp.comapDomain
@[simp]
theorem comapDomain_apply [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support))
(a : α) : comapDomain f l hf a = l (f a) :=
rfl
#align finsupp.comap_domain_apply Finsupp.comapDomain_apply
theorem sum_comapDomain [Zero M] [AddCommMonoid N] (f : α → β) (l : β →₀ M) (g : β → M → N)
(hf : Set.BijOn f (f ⁻¹' ↑l.support) ↑l.support) :
(comapDomain f l hf.injOn).sum (g ∘ f) = l.sum g := by
simp only [sum, comapDomain_apply, (· ∘ ·), comapDomain]
exact Finset.sum_preimage_of_bij f _ hf fun x => g x (l x)
#align finsupp.sum_comap_domain Finsupp.sum_comapDomain
theorem eq_zero_of_comapDomain_eq_zero [AddCommMonoid M] (f : α → β) (l : β →₀ M)
(hf : Set.BijOn f (f ⁻¹' ↑l.support) ↑l.support) : comapDomain f l hf.injOn = 0 → l = 0 := by
rw [← support_eq_empty, ← support_eq_empty, comapDomain]
simp only [Finset.ext_iff, Finset.not_mem_empty, iff_false_iff, mem_preimage]
intro h a ha
cases' hf.2.2 ha with b hb
exact h b (hb.2.symm ▸ ha)
#align finsupp.eq_zero_of_comap_domain_eq_zero Finsupp.eq_zero_of_comapDomain_eq_zero
section FInjective
section Zero
variable [Zero M]
lemma embDomain_comapDomain {f : α ↪ β} {g : β →₀ M} (hg : ↑g.support ⊆ Set.range f) :
embDomain f (comapDomain f g f.injective.injOn) = g := by
ext b
by_cases hb : b ∈ Set.range f
· obtain ⟨a, rfl⟩ := hb
rw [embDomain_apply, comapDomain_apply]
· replace hg : g b = 0 := not_mem_support_iff.mp <| mt (hg ·) hb
rw [embDomain_notin_range _ _ _ hb, hg]
/-- Note the `hif` argument is needed for this to work in `rw`. -/
@[simp]
theorem comapDomain_zero (f : α → β)
(hif : Set.InjOn f (f ⁻¹' ↑(0 : β →₀ M).support) := Finset.coe_empty ▸ (Set.injOn_empty f)) :
comapDomain f (0 : β →₀ M) hif = (0 : α →₀ M) := by
ext
rfl
#align finsupp.comap_domain_zero Finsupp.comapDomain_zero
@[simp]
| Mathlib/Data/Finsupp/Basic.lean | 742 | 750 | theorem comapDomain_single (f : α → β) (a : α) (m : M)
(hif : Set.InjOn f (f ⁻¹' (single (f a) m).support)) :
comapDomain f (Finsupp.single (f a) m) hif = Finsupp.single a m := by |
rcases eq_or_ne m 0 with (rfl | hm)
· simp only [single_zero, comapDomain_zero]
· rw [eq_single_iff, comapDomain_apply, comapDomain_support, ← Finset.coe_subset, coe_preimage,
support_single_ne_zero _ hm, coe_singleton, coe_singleton, single_eq_same]
rw [support_single_ne_zero _ hm, coe_singleton] at hif
exact ⟨fun x hx => hif hx rfl hx, rfl⟩
|
/-
Copyright (c) 2022 Stuart Presnell. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stuart Presnell, Eric Wieser, Yaël Dillies, Patrick Massot, Scott Morrison
-/
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.Algebra.Ring.Regular
import Mathlib.Order.Interval.Set.Basic
#align_import data.set.intervals.instances from "leanprover-community/mathlib"@"d012cd09a9b256d870751284dd6a29882b0be105"
/-!
# Algebraic instances for unit intervals
For suitably structured underlying type `α`, we exhibit the structure of
the unit intervals (`Set.Icc`, `Set.Ioc`, `Set.Ioc`, and `Set.Ioo`) from `0` to `1`.
Note: Instances for the interval `Ici 0` are dealt with in `Algebra/Order/Nonneg.lean`.
## Main definitions
The strongest typeclass provided on each interval is:
* `Set.Icc.cancelCommMonoidWithZero`
* `Set.Ico.commSemigroup`
* `Set.Ioc.commMonoid`
* `Set.Ioo.commSemigroup`
## TODO
* algebraic instances for intervals -1 to 1
* algebraic instances for `Ici 1`
* algebraic instances for `(Ioo (-1) 1)ᶜ`
* provide `distribNeg` instances where applicable
* prove versions of `mul_le_{left,right}` for other intervals
* prove versions of the lemmas in `Topology/UnitInterval` with `ℝ` generalized to
some arbitrary ordered semiring
-/
open Set
variable {α : Type*}
section OrderedSemiring
variable [OrderedSemiring α]
/-! ### Instances for `↥(Set.Icc 0 1)` -/
namespace Set.Icc
instance zero : Zero (Icc (0 : α) 1) where zero := ⟨0, left_mem_Icc.2 zero_le_one⟩
#align set.Icc.has_zero Set.Icc.zero
instance one : One (Icc (0 : α) 1) where one := ⟨1, right_mem_Icc.2 zero_le_one⟩
#align set.Icc.has_one Set.Icc.one
@[simp, norm_cast]
theorem coe_zero : ↑(0 : Icc (0 : α) 1) = (0 : α) :=
rfl
#align set.Icc.coe_zero Set.Icc.coe_zero
@[simp, norm_cast]
theorem coe_one : ↑(1 : Icc (0 : α) 1) = (1 : α) :=
rfl
#align set.Icc.coe_one Set.Icc.coe_one
@[simp]
theorem mk_zero (h : (0 : α) ∈ Icc (0 : α) 1) : (⟨0, h⟩ : Icc (0 : α) 1) = 0 :=
rfl
#align set.Icc.mk_zero Set.Icc.mk_zero
@[simp]
theorem mk_one (h : (1 : α) ∈ Icc (0 : α) 1) : (⟨1, h⟩ : Icc (0 : α) 1) = 1 :=
rfl
#align set.Icc.mk_one Set.Icc.mk_one
@[simp, norm_cast]
theorem coe_eq_zero {x : Icc (0 : α) 1} : (x : α) = 0 ↔ x = 0 := by
symm
exact Subtype.ext_iff
#align set.Icc.coe_eq_zero Set.Icc.coe_eq_zero
theorem coe_ne_zero {x : Icc (0 : α) 1} : (x : α) ≠ 0 ↔ x ≠ 0 :=
not_iff_not.mpr coe_eq_zero
#align set.Icc.coe_ne_zero Set.Icc.coe_ne_zero
@[simp, norm_cast]
theorem coe_eq_one {x : Icc (0 : α) 1} : (x : α) = 1 ↔ x = 1 := by
symm
exact Subtype.ext_iff
#align set.Icc.coe_eq_one Set.Icc.coe_eq_one
theorem coe_ne_one {x : Icc (0 : α) 1} : (x : α) ≠ 1 ↔ x ≠ 1 :=
not_iff_not.mpr coe_eq_one
#align set.Icc.coe_ne_one Set.Icc.coe_ne_one
theorem coe_nonneg (x : Icc (0 : α) 1) : 0 ≤ (x : α) :=
x.2.1
#align set.Icc.coe_nonneg Set.Icc.coe_nonneg
theorem coe_le_one (x : Icc (0 : α) 1) : (x : α) ≤ 1 :=
x.2.2
#align set.Icc.coe_le_one Set.Icc.coe_le_one
/-- like `coe_nonneg`, but with the inequality in `Icc (0:α) 1`. -/
theorem nonneg {t : Icc (0 : α) 1} : 0 ≤ t :=
t.2.1
#align set.Icc.nonneg Set.Icc.nonneg
/-- like `coe_le_one`, but with the inequality in `Icc (0:α) 1`. -/
theorem le_one {t : Icc (0 : α) 1} : t ≤ 1 :=
t.2.2
#align set.Icc.le_one Set.Icc.le_one
instance mul : Mul (Icc (0 : α) 1) where
mul p q := ⟨p * q, ⟨mul_nonneg p.2.1 q.2.1, mul_le_one p.2.2 q.2.1 q.2.2⟩⟩
#align set.Icc.has_mul Set.Icc.mul
instance pow : Pow (Icc (0 : α) 1) ℕ where
pow p n := ⟨p.1 ^ n, ⟨pow_nonneg p.2.1 n, pow_le_one n p.2.1 p.2.2⟩⟩
#align set.Icc.has_pow Set.Icc.pow
@[simp, norm_cast]
theorem coe_mul (x y : Icc (0 : α) 1) : ↑(x * y) = (x * y : α) :=
rfl
#align set.Icc.coe_mul Set.Icc.coe_mul
@[simp, norm_cast]
theorem coe_pow (x : Icc (0 : α) 1) (n : ℕ) : ↑(x ^ n) = ((x : α) ^ n) :=
rfl
#align set.Icc.coe_pow Set.Icc.coe_pow
theorem mul_le_left {x y : Icc (0 : α) 1} : x * y ≤ x :=
(mul_le_mul_of_nonneg_left y.2.2 x.2.1).trans_eq (mul_one _)
#align set.Icc.mul_le_left Set.Icc.mul_le_left
theorem mul_le_right {x y : Icc (0 : α) 1} : x * y ≤ y :=
(mul_le_mul_of_nonneg_right x.2.2 y.2.1).trans_eq (one_mul _)
#align set.Icc.mul_le_right Set.Icc.mul_le_right
instance monoidWithZero : MonoidWithZero (Icc (0 : α) 1) :=
Subtype.coe_injective.monoidWithZero _ coe_zero coe_one coe_mul coe_pow
#align set.Icc.monoid_with_zero Set.Icc.monoidWithZero
instance commMonoidWithZero {α : Type*} [OrderedCommSemiring α] :
CommMonoidWithZero (Icc (0 : α) 1) :=
Subtype.coe_injective.commMonoidWithZero _ coe_zero coe_one coe_mul coe_pow
#align set.Icc.comm_monoid_with_zero Set.Icc.commMonoidWithZero
instance cancelMonoidWithZero {α : Type*} [OrderedRing α] [NoZeroDivisors α] :
CancelMonoidWithZero (Icc (0 : α) 1) :=
@Function.Injective.cancelMonoidWithZero α _ NoZeroDivisors.toCancelMonoidWithZero _ _ _ _
(fun v => v.val) Subtype.coe_injective coe_zero coe_one coe_mul coe_pow
#align set.Icc.cancel_monoid_with_zero Set.Icc.cancelMonoidWithZero
instance cancelCommMonoidWithZero {α : Type*} [OrderedCommRing α] [NoZeroDivisors α] :
CancelCommMonoidWithZero (Icc (0 : α) 1) :=
@Function.Injective.cancelCommMonoidWithZero α _ NoZeroDivisors.toCancelCommMonoidWithZero _ _ _ _
(fun v => v.val) Subtype.coe_injective coe_zero coe_one coe_mul coe_pow
#align set.Icc.cancel_comm_monoid_with_zero Set.Icc.cancelCommMonoidWithZero
variable {β : Type*} [OrderedRing β]
theorem one_sub_mem {t : β} (ht : t ∈ Icc (0 : β) 1) : 1 - t ∈ Icc (0 : β) 1 := by
rw [mem_Icc] at *
exact ⟨sub_nonneg.2 ht.2, (sub_le_self_iff _).2 ht.1⟩
#align set.Icc.one_sub_mem Set.Icc.one_sub_mem
theorem mem_iff_one_sub_mem {t : β} : t ∈ Icc (0 : β) 1 ↔ 1 - t ∈ Icc (0 : β) 1 :=
⟨one_sub_mem, fun h => sub_sub_cancel 1 t ▸ one_sub_mem h⟩
#align set.Icc.mem_iff_one_sub_mem Set.Icc.mem_iff_one_sub_mem
theorem one_sub_nonneg (x : Icc (0 : β) 1) : 0 ≤ 1 - (x : β) := by simpa using x.2.2
#align set.Icc.one_sub_nonneg Set.Icc.one_sub_nonneg
theorem one_sub_le_one (x : Icc (0 : β) 1) : 1 - (x : β) ≤ 1 := by simpa using x.2.1
#align set.Icc.one_sub_le_one Set.Icc.one_sub_le_one
end Set.Icc
/-! ### Instances for `↥(Set.Ico 0 1)` -/
namespace Set.Ico
instance zero [Nontrivial α] : Zero (Ico (0 : α) 1) where zero := ⟨0, left_mem_Ico.2 zero_lt_one⟩
#align set.Ico.has_zero Set.Ico.zero
@[simp, norm_cast]
theorem coe_zero [Nontrivial α] : ↑(0 : Ico (0 : α) 1) = (0 : α) :=
rfl
#align set.Ico.coe_zero Set.Ico.coe_zero
@[simp]
theorem mk_zero [Nontrivial α] (h : (0 : α) ∈ Ico (0 : α) 1) : (⟨0, h⟩ : Ico (0 : α) 1) = 0 :=
rfl
#align set.Ico.mk_zero Set.Ico.mk_zero
@[simp, norm_cast]
theorem coe_eq_zero [Nontrivial α] {x : Ico (0 : α) 1} : (x : α) = 0 ↔ x = 0 := by
symm
exact Subtype.ext_iff
#align set.Ico.coe_eq_zero Set.Ico.coe_eq_zero
theorem coe_ne_zero [Nontrivial α] {x : Ico (0 : α) 1} : (x : α) ≠ 0 ↔ x ≠ 0 :=
not_iff_not.mpr coe_eq_zero
#align set.Ico.coe_ne_zero Set.Ico.coe_ne_zero
theorem coe_nonneg (x : Ico (0 : α) 1) : 0 ≤ (x : α) :=
x.2.1
#align set.Ico.coe_nonneg Set.Ico.coe_nonneg
theorem coe_lt_one (x : Ico (0 : α) 1) : (x : α) < 1 :=
x.2.2
#align set.Ico.coe_lt_one Set.Ico.coe_lt_one
/-- like `coe_nonneg`, but with the inequality in `Ico (0:α) 1`. -/
theorem nonneg [Nontrivial α] {t : Ico (0 : α) 1} : 0 ≤ t :=
t.2.1
#align set.Ico.nonneg Set.Ico.nonneg
instance mul : Mul (Ico (0 : α) 1) where
mul p q :=
⟨p * q, ⟨mul_nonneg p.2.1 q.2.1, mul_lt_one_of_nonneg_of_lt_one_right p.2.2.le q.2.1 q.2.2⟩⟩
#align set.Ico.has_mul Set.Ico.mul
@[simp, norm_cast]
theorem coe_mul (x y : Ico (0 : α) 1) : ↑(x * y) = (x * y : α) :=
rfl
#align set.Ico.coe_mul Set.Ico.coe_mul
instance semigroup : Semigroup (Ico (0 : α) 1) :=
Subtype.coe_injective.semigroup _ coe_mul
#align set.Ico.semigroup Set.Ico.semigroup
instance commSemigroup {α : Type*} [OrderedCommSemiring α] : CommSemigroup (Ico (0 : α) 1) :=
Subtype.coe_injective.commSemigroup _ coe_mul
#align set.Ico.comm_semigroup Set.Ico.commSemigroup
end Set.Ico
end OrderedSemiring
variable [StrictOrderedSemiring α]
/-! ### Instances for `↥(Set.Ioc 0 1)` -/
namespace Set.Ioc
instance one [Nontrivial α] : One (Ioc (0 : α) 1) where one := ⟨1, ⟨zero_lt_one, le_refl 1⟩⟩
#align set.Ioc.has_one Set.Ioc.one
@[simp, norm_cast]
theorem coe_one [Nontrivial α] : ↑(1 : Ioc (0 : α) 1) = (1 : α) :=
rfl
#align set.Ioc.coe_one Set.Ioc.coe_one
@[simp]
theorem mk_one [Nontrivial α] (h : (1 : α) ∈ Ioc (0 : α) 1) : (⟨1, h⟩ : Ioc (0 : α) 1) = 1 :=
rfl
#align set.Ioc.mk_one Set.Ioc.mk_one
@[simp, norm_cast]
theorem coe_eq_one [Nontrivial α] {x : Ioc (0 : α) 1} : (x : α) = 1 ↔ x = 1 := by
symm
exact Subtype.ext_iff
#align set.Ioc.coe_eq_one Set.Ioc.coe_eq_one
theorem coe_ne_one [Nontrivial α] {x : Ioc (0 : α) 1} : (x : α) ≠ 1 ↔ x ≠ 1 :=
not_iff_not.mpr coe_eq_one
#align set.Ioc.coe_ne_one Set.Ioc.coe_ne_one
theorem coe_pos (x : Ioc (0 : α) 1) : 0 < (x : α) :=
x.2.1
#align set.Ioc.coe_pos Set.Ioc.coe_pos
theorem coe_le_one (x : Ioc (0 : α) 1) : (x : α) ≤ 1 :=
x.2.2
#align set.Ioc.coe_le_one Set.Ioc.coe_le_one
/-- like `coe_le_one`, but with the inequality in `Ioc (0:α) 1`. -/
theorem le_one [Nontrivial α] {t : Ioc (0 : α) 1} : t ≤ 1 :=
t.2.2
#align set.Ioc.le_one Set.Ioc.le_one
instance mul : Mul (Ioc (0 : α) 1) where
mul p q := ⟨p.1 * q.1, ⟨mul_pos p.2.1 q.2.1, mul_le_one p.2.2 (le_of_lt q.2.1) q.2.2⟩⟩
#align set.Ioc.has_mul Set.Ioc.mul
instance pow : Pow (Ioc (0 : α) 1) ℕ where
pow p n := ⟨p.1 ^ n, ⟨pow_pos p.2.1 n, pow_le_one n (le_of_lt p.2.1) p.2.2⟩⟩
#align set.Ioc.has_pow Set.Ioc.pow
@[simp, norm_cast]
theorem coe_mul (x y : Ioc (0 : α) 1) : ↑(x * y) = (x * y : α) :=
rfl
#align set.Ioc.coe_mul Set.Ioc.coe_mul
@[simp, norm_cast]
theorem coe_pow (x : Ioc (0 : α) 1) (n : ℕ) : ↑(x ^ n) = ((x : α) ^ n) :=
rfl
#align set.Ioc.coe_pow Set.Ioc.coe_pow
instance semigroup : Semigroup (Ioc (0 : α) 1) :=
Subtype.coe_injective.semigroup _ coe_mul
#align set.Ioc.semigroup Set.Ioc.semigroup
instance monoid [Nontrivial α] : Monoid (Ioc (0 : α) 1) :=
Subtype.coe_injective.monoid _ coe_one coe_mul coe_pow
#align set.Ioc.monoid Set.Ioc.monoid
instance commSemigroup {α : Type*} [StrictOrderedCommSemiring α] : CommSemigroup (Ioc (0 : α) 1) :=
Subtype.coe_injective.commSemigroup _ coe_mul
#align set.Ioc.comm_semigroup Set.Ioc.commSemigroup
instance commMonoid {α : Type*} [StrictOrderedCommSemiring α] [Nontrivial α] :
CommMonoid (Ioc (0 : α) 1) :=
Subtype.coe_injective.commMonoid _ coe_one coe_mul coe_pow
#align set.Ioc.comm_monoid Set.Ioc.commMonoid
instance cancelMonoid {α : Type*} [StrictOrderedRing α] [IsDomain α] :
CancelMonoid (Ioc (0 : α) 1) :=
{ Set.Ioc.monoid with
mul_left_cancel := fun a _ _ h =>
Subtype.ext <| mul_left_cancel₀ a.prop.1.ne' <| (congr_arg Subtype.val h : _)
mul_right_cancel := fun _ b _ h =>
Subtype.ext <| mul_right_cancel₀ b.prop.1.ne' <| (congr_arg Subtype.val h : _) }
#align set.Ioc.cancel_monoid Set.Ioc.cancelMonoid
instance cancelCommMonoid {α : Type*} [StrictOrderedCommRing α] [IsDomain α] :
CancelCommMonoid (Ioc (0 : α) 1) :=
{ Set.Ioc.cancelMonoid, Set.Ioc.commMonoid with }
#align set.Ioc.cancel_comm_monoid Set.Ioc.cancelCommMonoid
end Set.Ioc
/-! ### Instances for `↥(Set.Ioo 0 1)` -/
namespace Set.Ioo
theorem pos (x : Ioo (0 : α) 1) : 0 < (x : α) :=
x.2.1
#align set.Ioo.pos Set.Ioo.pos
theorem lt_one (x : Ioo (0 : α) 1) : (x : α) < 1 :=
x.2.2
#align set.Ioo.lt_one Set.Ioo.lt_one
instance mul : Mul (Ioo (0 : α) 1) where
mul p q :=
⟨p.1 * q.1, ⟨mul_pos p.2.1 q.2.1, mul_lt_one_of_nonneg_of_lt_one_right p.2.2.le q.2.1.le q.2.2⟩⟩
#align set.Ioo.has_mul Set.Ioo.mul
@[simp, norm_cast]
theorem coe_mul (x y : Ioo (0 : α) 1) : ↑(x * y) = (x * y : α) :=
rfl
#align set.Ioo.coe_mul Set.Ioo.coe_mul
instance semigroup : Semigroup (Ioo (0 : α) 1) :=
Subtype.coe_injective.semigroup _ coe_mul
#align set.Ioo.semigroup Set.Ioo.semigroup
instance commSemigroup {α : Type*} [StrictOrderedCommSemiring α] : CommSemigroup (Ioo (0 : α) 1) :=
Subtype.coe_injective.commSemigroup _ coe_mul
#align set.Ioo.comm_semigroup Set.Ioo.commSemigroup
variable {β : Type*} [OrderedRing β]
theorem one_sub_mem {t : β} (ht : t ∈ Ioo (0 : β) 1) : 1 - t ∈ Ioo (0 : β) 1 := by
rw [mem_Ioo] at *
refine ⟨sub_pos.2 ht.2, ?_⟩
exact lt_of_le_of_ne ((sub_le_self_iff 1).2 ht.1.le) (mt sub_eq_self.mp ht.1.ne')
#align set.Ioo.one_sub_mem Set.Ioo.one_sub_mem
theorem mem_iff_one_sub_mem {t : β} : t ∈ Ioo (0 : β) 1 ↔ 1 - t ∈ Ioo (0 : β) 1 :=
⟨one_sub_mem, fun h => sub_sub_cancel 1 t ▸ one_sub_mem h⟩
#align set.Ioo.mem_iff_one_sub_mem Set.Ioo.mem_iff_one_sub_mem
| Mathlib/Algebra/Order/Interval/Set/Instances.lean | 382 | 382 | theorem one_minus_pos (x : Ioo (0 : β) 1) : 0 < 1 - (x : β) := by | simpa using x.2.2
|
/-
Copyright (c) 2022 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Analysis.NormedSpace.Star.Spectrum
import Mathlib.Analysis.Normed.Group.Quotient
import Mathlib.Analysis.NormedSpace.Algebra
import Mathlib.Topology.ContinuousFunction.Units
import Mathlib.Topology.ContinuousFunction.Compact
import Mathlib.Topology.Algebra.Algebra
import Mathlib.Topology.ContinuousFunction.Ideals
import Mathlib.Topology.ContinuousFunction.StoneWeierstrass
#align_import analysis.normed_space.star.gelfand_duality from "leanprover-community/mathlib"@"e65771194f9e923a70dfb49b6ca7be6e400d8b6f"
/-!
# Gelfand Duality
The `gelfandTransform` is an algebra homomorphism from a topological `𝕜`-algebra `A` to
`C(characterSpace 𝕜 A, 𝕜)`. In the case where `A` is a commutative complex Banach algebra, then
the Gelfand transform is actually spectrum-preserving (`spectrum.gelfandTransform_eq`). Moreover,
when `A` is a commutative C⋆-algebra over `ℂ`, then the Gelfand transform is a surjective isometry,
and even an equivalence between C⋆-algebras.
Consider the contravariant functors between compact Hausdorff spaces and commutative unital
C⋆algebras `F : Cpct → CommCStarAlg := X ↦ C(X, ℂ)` and
`G : CommCStarAlg → Cpct := A → characterSpace ℂ A` whose actions on morphisms are given by
`WeakDual.CharacterSpace.compContinuousMap` and `ContinuousMap.compStarAlgHom'`, respectively.
Then `η₁ : id → F ∘ G := gelfandStarTransform` and
`η₂ : id → G ∘ F := WeakDual.CharacterSpace.homeoEval` are the natural isomorphisms implementing
**Gelfand Duality**, i.e., the (contravariant) equivalence of these categories.
## Main definitions
* `Ideal.toCharacterSpace` : constructs an element of the character space from a maximal ideal in
a commutative complex Banach algebra
* `WeakDual.CharacterSpace.compContinuousMap`: The functorial map taking `ψ : A →⋆ₐ[𝕜] B` to a
continuous function `characterSpace 𝕜 B → characterSpace 𝕜 A` given by pre-composition with `ψ`.
## Main statements
* `spectrum.gelfandTransform_eq` : the Gelfand transform is spectrum-preserving when the algebra is
a commutative complex Banach algebra.
* `gelfandTransform_isometry` : the Gelfand transform is an isometry when the algebra is a
commutative (unital) C⋆-algebra over `ℂ`.
* `gelfandTransform_bijective` : the Gelfand transform is bijective when the algebra is a
commutative (unital) C⋆-algebra over `ℂ`.
* `gelfandStarTransform_naturality`: The `gelfandStarTransform` is a natural isomorphism
* `WeakDual.CharacterSpace.homeoEval_naturality`: This map implements a natural isomorphism
## TODO
* After defining the category of commutative unital C⋆-algebras, bundle the existing unbundled
**Gelfand duality** into an actual equivalence (duality) of categories associated to the
functors `C(·, ℂ)` and `characterSpace ℂ ·` and the natural isomorphisms `gelfandStarTransform`
and `WeakDual.CharacterSpace.homeoEval`.
## Tags
Gelfand transform, character space, C⋆-algebra
-/
open WeakDual
open scoped NNReal
section ComplexBanachAlgebra
open Ideal
variable {A : Type*} [NormedCommRing A] [NormedAlgebra ℂ A] [CompleteSpace A] (I : Ideal A)
[Ideal.IsMaximal I]
/-- Every maximal ideal in a commutative complex Banach algebra gives rise to a character on that
algebra. In particular, the character, which may be identified as an algebra homomorphism due to
`WeakDual.CharacterSpace.equivAlgHom`, is given by the composition of the quotient map and
the Gelfand-Mazur isomorphism `NormedRing.algEquivComplexOfComplete`. -/
noncomputable def Ideal.toCharacterSpace : characterSpace ℂ A :=
CharacterSpace.equivAlgHom.symm <|
((NormedRing.algEquivComplexOfComplete
(letI := Quotient.field I; isUnit_iff_ne_zero (G₀ := A ⧸ I))).symm : A ⧸ I →ₐ[ℂ] ℂ).comp <|
Quotient.mkₐ ℂ I
#align ideal.to_character_space Ideal.toCharacterSpace
theorem Ideal.toCharacterSpace_apply_eq_zero_of_mem {a : A} (ha : a ∈ I) :
I.toCharacterSpace a = 0 := by
unfold Ideal.toCharacterSpace
simp only [CharacterSpace.equivAlgHom_symm_coe, AlgHom.coe_comp, AlgHom.coe_coe,
Quotient.mkₐ_eq_mk, Function.comp_apply, NormedRing.algEquivComplexOfComplete_symm_apply]
simp_rw [Quotient.eq_zero_iff_mem.mpr ha, spectrum.zero_eq]
exact Set.eq_of_mem_singleton (Set.singleton_nonempty (0 : ℂ)).some_mem
#align ideal.to_character_space_apply_eq_zero_of_mem Ideal.toCharacterSpace_apply_eq_zero_of_mem
/-- If `a : A` is not a unit, then some character takes the value zero at `a`. This is equivalent
to `gelfandTransform ℂ A a` takes the value zero at some character. -/
theorem WeakDual.CharacterSpace.exists_apply_eq_zero {a : A} (ha : ¬IsUnit a) :
∃ f : characterSpace ℂ A, f a = 0 := by
obtain ⟨M, hM, haM⟩ := (span {a}).exists_le_maximal (span_singleton_ne_top ha)
exact
⟨M.toCharacterSpace,
M.toCharacterSpace_apply_eq_zero_of_mem
(haM (mem_span_singleton.mpr ⟨1, (mul_one a).symm⟩))⟩
#align weak_dual.character_space.exists_apply_eq_zero WeakDual.CharacterSpace.exists_apply_eq_zero
theorem WeakDual.CharacterSpace.mem_spectrum_iff_exists {a : A} {z : ℂ} :
z ∈ spectrum ℂ a ↔ ∃ f : characterSpace ℂ A, f a = z := by
refine ⟨fun hz => ?_, ?_⟩
· obtain ⟨f, hf⟩ := WeakDual.CharacterSpace.exists_apply_eq_zero hz
simp only [map_sub, sub_eq_zero, AlgHomClass.commutes] at hf
exact ⟨_, hf.symm⟩
· rintro ⟨f, rfl⟩
exact AlgHom.apply_mem_spectrum f a
#align weak_dual.character_space.mem_spectrum_iff_exists WeakDual.CharacterSpace.mem_spectrum_iff_exists
/-- The Gelfand transform is spectrum-preserving. -/
theorem spectrum.gelfandTransform_eq (a : A) :
spectrum ℂ (gelfandTransform ℂ A a) = spectrum ℂ a := by
ext z
rw [ContinuousMap.spectrum_eq_range, WeakDual.CharacterSpace.mem_spectrum_iff_exists]
exact Iff.rfl
#align spectrum.gelfand_transform_eq spectrum.gelfandTransform_eq
instance [Nontrivial A] : Nonempty (characterSpace ℂ A) :=
⟨Classical.choose <|
WeakDual.CharacterSpace.exists_apply_eq_zero <| zero_mem_nonunits.2 zero_ne_one⟩
end ComplexBanachAlgebra
section ComplexCstarAlgebra
variable {A : Type*} [NormedCommRing A] [NormedAlgebra ℂ A] [CompleteSpace A]
variable [StarRing A] [CstarRing A] [StarModule ℂ A]
theorem gelfandTransform_map_star (a : A) :
gelfandTransform ℂ A (star a) = star (gelfandTransform ℂ A a) :=
ContinuousMap.ext fun φ => map_star φ a
#align gelfand_transform_map_star gelfandTransform_map_star
variable (A)
/-- The Gelfand transform is an isometry when the algebra is a C⋆-algebra over `ℂ`. -/
| Mathlib/Analysis/NormedSpace/Star/GelfandDuality.lean | 145 | 158 | theorem gelfandTransform_isometry : Isometry (gelfandTransform ℂ A) := by |
nontriviality A
refine AddMonoidHomClass.isometry_of_norm (gelfandTransform ℂ A) fun a => ?_
/- By `spectrum.gelfandTransform_eq`, the spectra of `star a * a` and its
`gelfandTransform` coincide. Therefore, so do their spectral radii, and since they are
self-adjoint, so also do their norms. Applying the C⋆-property of the norm and taking square
roots shows that the norm is preserved. -/
have : spectralRadius ℂ (gelfandTransform ℂ A (star a * a)) = spectralRadius ℂ (star a * a) := by
unfold spectralRadius; rw [spectrum.gelfandTransform_eq]
rw [map_mul, (IsSelfAdjoint.star_mul_self a).spectralRadius_eq_nnnorm, gelfandTransform_map_star,
(IsSelfAdjoint.star_mul_self (gelfandTransform ℂ A a)).spectralRadius_eq_nnnorm] at this
simp only [ENNReal.coe_inj, CstarRing.nnnorm_star_mul_self, ← sq] at this
simpa only [Function.comp_apply, NNReal.sqrt_sq] using
congr_arg (((↑) : ℝ≥0 → ℝ) ∘ ⇑NNReal.sqrt) this
|
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Complex.AbsMax
import Mathlib.Analysis.Asymptotics.SuperpolynomialDecay
#align_import analysis.complex.phragmen_lindelof from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982"
/-!
# Phragmen-Lindelöf principle
In this file we prove several versions of the Phragmen-Lindelöf principle, a version of the maximum
modulus principle for an unbounded domain.
## Main statements
* `PhragmenLindelof.horizontal_strip`: the Phragmen-Lindelöf principle in a horizontal strip
`{z : ℂ | a < complex.im z < b}`;
* `PhragmenLindelof.eq_zero_on_horizontal_strip`, `PhragmenLindelof.eqOn_horizontal_strip`:
extensionality lemmas based on the Phragmen-Lindelöf principle in a horizontal strip;
* `PhragmenLindelof.vertical_strip`: the Phragmen-Lindelöf principle in a vertical strip
`{z : ℂ | a < complex.re z < b}`;
* `PhragmenLindelof.eq_zero_on_vertical_strip`, `PhragmenLindelof.eqOn_vertical_strip`:
extensionality lemmas based on the Phragmen-Lindelöf principle in a vertical strip;
* `PhragmenLindelof.quadrant_I`, `PhragmenLindelof.quadrant_II`, `PhragmenLindelof.quadrant_III`,
`PhragmenLindelof.quadrant_IV`: the Phragmen-Lindelöf principle in the coordinate quadrants;
* `PhragmenLindelof.right_half_plane_of_tendsto_zero_on_real`,
`PhragmenLindelof.right_half_plane_of_bounded_on_real`: two versions of the Phragmen-Lindelöf
principle in the right half-plane;
* `PhragmenLindelof.eq_zero_on_right_half_plane_of_superexponential_decay`,
`PhragmenLindelof.eqOn_right_half_plane_of_superexponential_decay`: extensionality lemmas based
on the Phragmen-Lindelöf principle in the right half-plane.
In the case of the right half-plane, we prove a version of the Phragmen-Lindelöf principle that is
useful for Ilyashenko's proof of the individual finiteness theorem (a polynomial vector field on the
real plane has only finitely many limit cycles).
-/
open Set Function Filter Asymptotics Metric Complex Bornology
open scoped Topology Filter Real
local notation "expR" => Real.exp
namespace PhragmenLindelof
/-!
### Auxiliary lemmas
-/
variable {E : Type*} [NormedAddCommGroup E]
/-- An auxiliary lemma that combines two double exponential estimates into a similar estimate
on the difference of the functions. -/
theorem isBigO_sub_exp_exp {a : ℝ} {f g : ℂ → E} {l : Filter ℂ} {u : ℂ → ℝ}
(hBf : ∃ c < a, ∃ B, f =O[l] fun z => expR (B * expR (c * |u z|)))
(hBg : ∃ c < a, ∃ B, g =O[l] fun z => expR (B * expR (c * |u z|))) :
∃ c < a, ∃ B, (f - g) =O[l] fun z => expR (B * expR (c * |u z|)) := by
have : ∀ {c₁ c₂ B₁ B₂}, c₁ ≤ c₂ → 0 ≤ B₂ → B₁ ≤ B₂ → ∀ z,
‖expR (B₁ * expR (c₁ * |u z|))‖ ≤ ‖expR (B₂ * expR (c₂ * |u z|))‖ := fun hc hB₀ hB z ↦ by
simp only [Real.norm_eq_abs, Real.abs_exp]; gcongr
rcases hBf with ⟨cf, hcf, Bf, hOf⟩; rcases hBg with ⟨cg, hcg, Bg, hOg⟩
refine ⟨max cf cg, max_lt hcf hcg, max 0 (max Bf Bg), ?_⟩
refine (hOf.trans_le <| this ?_ ?_ ?_).sub (hOg.trans_le <| this ?_ ?_ ?_)
exacts [le_max_left _ _, le_max_left _ _, (le_max_left _ _).trans (le_max_right _ _),
le_max_right _ _, le_max_left _ _, (le_max_right _ _).trans (le_max_right _ _)]
set_option linter.uppercaseLean3 false in
#align phragmen_lindelof.is_O_sub_exp_exp PhragmenLindelof.isBigO_sub_exp_exp
/-- An auxiliary lemma that combines two “exponential of a power” estimates into a similar estimate
on the difference of the functions. -/
theorem isBigO_sub_exp_rpow {a : ℝ} {f g : ℂ → E} {l : Filter ℂ}
(hBf : ∃ c < a, ∃ B, f =O[cobounded ℂ ⊓ l] fun z => expR (B * abs z ^ c))
(hBg : ∃ c < a, ∃ B, g =O[cobounded ℂ ⊓ l] fun z => expR (B * abs z ^ c)) :
∃ c < a, ∃ B, (f - g) =O[cobounded ℂ ⊓ l] fun z => expR (B * abs z ^ c) := by
have : ∀ {c₁ c₂ B₁ B₂ : ℝ}, c₁ ≤ c₂ → 0 ≤ B₂ → B₁ ≤ B₂ →
(fun z : ℂ => expR (B₁ * abs z ^ c₁)) =O[cobounded ℂ ⊓ l]
fun z => expR (B₂ * abs z ^ c₂) := fun hc hB₀ hB ↦ .of_bound 1 <| by
filter_upwards [(eventually_cobounded_le_norm 1).filter_mono inf_le_left] with z hz
simp only [one_mul, Real.norm_eq_abs, Real.abs_exp]
gcongr; assumption
rcases hBf with ⟨cf, hcf, Bf, hOf⟩; rcases hBg with ⟨cg, hcg, Bg, hOg⟩
refine ⟨max cf cg, max_lt hcf hcg, max 0 (max Bf Bg), ?_⟩
refine (hOf.trans <| this ?_ ?_ ?_).sub (hOg.trans <| this ?_ ?_ ?_)
exacts [le_max_left _ _, le_max_left _ _, (le_max_left _ _).trans (le_max_right _ _),
le_max_right _ _, le_max_left _ _, (le_max_right _ _).trans (le_max_right _ _)]
set_option linter.uppercaseLean3 false in
#align phragmen_lindelof.is_O_sub_exp_rpow PhragmenLindelof.isBigO_sub_exp_rpow
variable [NormedSpace ℂ E] {a b C : ℝ} {f g : ℂ → E} {z : ℂ}
/-!
### Phragmen-Lindelöf principle in a horizontal strip
-/
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < im z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some `c < π / (b - a)`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of `U`.
Then `‖f z‖` is bounded by the same constant on the closed strip
`{z : ℂ | a ≤ im z ≤ b}`. Moreover, it suffices to verify the second assumption
only for sufficiently large values of `|re z|`.
-/
theorem horizontal_strip (hfd : DiffContOnCl ℂ f (im ⁻¹' Ioo a b))
(hB : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ re) atTop ⊓ 𝓟 (im ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.re|)))
(hle_a : ∀ z : ℂ, im z = a → ‖f z‖ ≤ C) (hle_b : ∀ z, im z = b → ‖f z‖ ≤ C) (hza : a ≤ im z)
(hzb : im z ≤ b) : ‖f z‖ ≤ C := by
-- If `im z = a` or `im z = b`, then we apply `hle_a` or `hle_b`, otherwise `im z ∈ Ioo a b`.
rw [le_iff_eq_or_lt] at hza hzb
cases' hza with hza hza; · exact hle_a _ hza.symm
cases' hzb with hzb hzb; · exact hle_b _ hzb
wlog hC₀ : 0 < C generalizing C
· refine le_of_forall_le_of_dense fun C' hC' => this (fun w hw => ?_) (fun w hw => ?_) ?_
· exact (hle_a _ hw).trans hC'.le
· exact (hle_b _ hw).trans hC'.le
· refine ((norm_nonneg (f (a * I))).trans (hle_a _ ?_)).trans_lt hC'
rw [mul_I_im, ofReal_re]
-- After a change of variables, we deal with the strip `a - b < im z < a + b` instead
-- of `a < im z < b`
obtain ⟨a, b, rfl, rfl⟩ : ∃ a' b', a = a' - b' ∧ b = a' + b' :=
⟨(a + b) / 2, (b - a) / 2, by ring, by ring⟩
have hab : a - b < a + b := hza.trans hzb
have hb : 0 < b := by simpa only [sub_eq_add_neg, add_lt_add_iff_left, neg_lt_self_iff] using hab
rw [add_sub_sub_cancel, ← two_mul, div_mul_eq_div_div] at hB
have hπb : 0 < π / 2 / b := div_pos Real.pi_div_two_pos hb
-- Choose some `c B : ℝ` satisfying `hB`, then choose `max c 0 < d < π / 2 / b`.
rcases hB with ⟨c, hc, B, hO⟩
obtain ⟨d, ⟨hcd, hd₀⟩, hd⟩ : ∃ d, (c < d ∧ 0 < d) ∧ d < π / 2 / b := by
simpa only [max_lt_iff] using exists_between (max_lt hc hπb)
have hb' : d * b < π / 2 := (lt_div_iff hb).1 hd
set aff := (fun w => d * (w - a * I) : ℂ → ℂ)
set g := fun (ε : ℝ) (w : ℂ) => exp (ε * (exp (aff w) + exp (-aff w)))
/- Since `g ε z → 1` as `ε → 0⁻`, it suffices to prove that `‖g ε z • f z‖ ≤ C`
for all negative `ε`. -/
suffices ∀ᶠ ε : ℝ in 𝓝[<] (0 : ℝ), ‖g ε z • f z‖ ≤ C by
refine le_of_tendsto (Tendsto.mono_left ?_ nhdsWithin_le_nhds) this
apply ((continuous_ofReal.mul continuous_const).cexp.smul continuous_const).norm.tendsto'
simp
filter_upwards [self_mem_nhdsWithin] with ε ε₀; change ε < 0 at ε₀
-- An upper estimate on `‖g ε w‖` that will be used in two branches of the proof.
obtain ⟨δ, δ₀, hδ⟩ :
∃ δ : ℝ,
δ < 0 ∧ ∀ ⦃w⦄, im w ∈ Icc (a - b) (a + b) → abs (g ε w) ≤ expR (δ * expR (d * |re w|)) := by
refine
⟨ε * Real.cos (d * b),
mul_neg_of_neg_of_pos ε₀
(Real.cos_pos_of_mem_Ioo <| abs_lt.1 <| (abs_of_pos (mul_pos hd₀ hb)).symm ▸ hb'),
fun w hw => ?_⟩
replace hw : |im (aff w)| ≤ d * b := by
rw [← Real.closedBall_eq_Icc] at hw
rwa [im_ofReal_mul, sub_im, mul_I_im, ofReal_re, _root_.abs_mul, abs_of_pos hd₀,
mul_le_mul_left hd₀]
simpa only [aff, re_ofReal_mul, _root_.abs_mul, abs_of_pos hd₀, sub_re, mul_I_re, ofReal_im,
zero_mul, neg_zero, sub_zero] using
abs_exp_mul_exp_add_exp_neg_le_of_abs_im_le ε₀.le hw hb'.le
-- `abs (g ε w) ≤ 1` on the lines `w.im = a ± b` (actually, it holds everywhere in the strip)
have hg₁ : ∀ w, im w = a - b ∨ im w = a + b → abs (g ε w) ≤ 1 := by
refine fun w hw => (hδ <| hw.by_cases ?_ ?_).trans (Real.exp_le_one_iff.2 ?_)
exacts [fun h => h.symm ▸ left_mem_Icc.2 hab.le, fun h => h.symm ▸ right_mem_Icc.2 hab.le,
mul_nonpos_of_nonpos_of_nonneg δ₀.le (Real.exp_pos _).le]
/- Our apriori estimate on `f` implies that `g ε w • f w → 0` as `|w.re| → ∞` along the strip. In
particular, its norm is less than or equal to `C` for sufficiently large `|w.re|`. -/
obtain ⟨R, hzR, hR⟩ :
∃ R : ℝ, |z.re| < R ∧ ∀ w, |re w| = R → im w ∈ Ioo (a - b) (a + b) → ‖g ε w • f w‖ ≤ C := by
refine ((eventually_gt_atTop _).and ?_).exists
rcases hO.exists_pos with ⟨A, hA₀, hA⟩
simp only [isBigOWith_iff, eventually_inf_principal, eventually_comap, mem_Ioo, ← abs_lt,
mem_preimage, (· ∘ ·), Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] at hA
suffices
Tendsto (fun R => expR (δ * expR (d * R) + B * expR (c * R) + Real.log A)) atTop (𝓝 0) by
filter_upwards [this.eventually (ge_mem_nhds hC₀), hA] with R hR Hle w hre him
calc
‖g ε w • f w‖ ≤ expR (δ * expR (d * R) + B * expR (c * R) + Real.log A) := ?_
_ ≤ C := hR
rw [norm_smul, Real.exp_add, ← hre, Real.exp_add, Real.exp_log hA₀, mul_assoc, mul_comm _ A]
gcongr
exacts [hδ <| Ioo_subset_Icc_self him, Hle _ hre him]
refine Real.tendsto_exp_atBot.comp ?_
suffices H : Tendsto (fun R => δ + B * (expR ((d - c) * R))⁻¹) atTop (𝓝 (δ + B * 0)) by
rw [mul_zero, add_zero] at H
refine Tendsto.atBot_add ?_ tendsto_const_nhds
simpa only [id, (· ∘ ·), add_mul, mul_assoc, ← div_eq_inv_mul, ← Real.exp_sub, ← sub_mul,
sub_sub_cancel]
using H.neg_mul_atTop δ₀ <| Real.tendsto_exp_atTop.comp <|
tendsto_const_nhds.mul_atTop hd₀ tendsto_id
refine tendsto_const_nhds.add (tendsto_const_nhds.mul ?_)
exact tendsto_inv_atTop_zero.comp <| Real.tendsto_exp_atTop.comp <|
tendsto_const_nhds.mul_atTop (sub_pos.2 hcd) tendsto_id
have hR₀ : 0 < R := (_root_.abs_nonneg _).trans_lt hzR
/- Finally, we apply the bounded version of the maximum modulus principle to the rectangle
`(-R, R) × (a - b, a + b)`. The function is bounded by `C` on the horizontal sides by assumption
(and because `‖g ε w‖ ≤ 1`) and on the vertical sides by the choice of `R`. -/
have hgd : Differentiable ℂ (g ε) :=
((((differentiable_id.sub_const _).const_mul _).cexp.add
((differentiable_id.sub_const _).const_mul _).neg.cexp).const_mul _).cexp
replace hd : DiffContOnCl ℂ (fun w => g ε w • f w) (Ioo (-R) R ×ℂ Ioo (a - b) (a + b)) :=
(hgd.diffContOnCl.smul hfd).mono inter_subset_right
convert norm_le_of_forall_mem_frontier_norm_le ((isBounded_Ioo _ _).reProdIm (isBounded_Ioo _ _))
hd (fun w hw => _) _
· rw [frontier_reProdIm, closure_Ioo (neg_lt_self hR₀).ne, frontier_Ioo hab, closure_Ioo hab.ne,
frontier_Ioo (neg_lt_self hR₀)] at hw
by_cases him : w.im = a - b ∨ w.im = a + b
· rw [norm_smul, ← one_mul C]
exact mul_le_mul (hg₁ _ him) (him.by_cases (hle_a _) (hle_b _)) (norm_nonneg _) zero_le_one
· replace hw : w ∈ {-R, R} ×ℂ Icc (a - b) (a + b) := hw.resolve_left fun h ↦ him h.2
have hw' := eq_endpoints_or_mem_Ioo_of_mem_Icc hw.2; rw [← or_assoc] at hw'
exact hR _ ((abs_eq hR₀.le).2 hw.1.symm) (hw'.resolve_left him)
· rw [closure_reProdIm, closure_Ioo hab.ne, closure_Ioo (neg_lt_self hR₀).ne]
exact ⟨abs_le.1 hzR.le, ⟨hza.le, hzb.le⟩⟩
#align phragmen_lindelof.horizontal_strip PhragmenLindelof.horizontal_strip
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < im z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some `c < π / (b - a)`;
* `f z = 0` on the boundary of `U`.
Then `f` is equal to zero on the closed strip `{z : ℂ | a ≤ im z ≤ b}`.
-/
theorem eq_zero_on_horizontal_strip (hd : DiffContOnCl ℂ f (im ⁻¹' Ioo a b))
(hB : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ re) atTop ⊓ 𝓟 (im ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.re|)))
(ha : ∀ z : ℂ, z.im = a → f z = 0) (hb : ∀ z : ℂ, z.im = b → f z = 0) :
EqOn f 0 (im ⁻¹' Icc a b) := fun _z hz =>
norm_le_zero_iff.1 <| horizontal_strip hd hB (fun z hz => (ha z hz).symm ▸ norm_zero.le)
(fun z hz => (hb z hz).symm ▸ norm_zero.le) hz.1 hz.2
#align phragmen_lindelof.eq_zero_on_horizontal_strip PhragmenLindelof.eq_zero_on_horizontal_strip
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < im z < b}`.
Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable on `U` and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some
`c < π / (b - a)`;
* `f z = g z` on the boundary of `U`.
Then `f` is equal to `g` on the closed strip `{z : ℂ | a ≤ im z ≤ b}`.
-/
theorem eqOn_horizontal_strip {g : ℂ → E} (hdf : DiffContOnCl ℂ f (im ⁻¹' Ioo a b))
(hBf : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ re) atTop ⊓ 𝓟 (im ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.re|)))
(hdg : DiffContOnCl ℂ g (im ⁻¹' Ioo a b))
(hBg : ∃ c < π / (b - a), ∃ B, g =O[comap (_root_.abs ∘ re) atTop ⊓ 𝓟 (im ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.re|)))
(ha : ∀ z : ℂ, z.im = a → f z = g z) (hb : ∀ z : ℂ, z.im = b → f z = g z) :
EqOn f g (im ⁻¹' Icc a b) := fun _z hz =>
sub_eq_zero.1 (eq_zero_on_horizontal_strip (hdf.sub hdg) (isBigO_sub_exp_exp hBf hBg)
(fun w hw => sub_eq_zero.2 (ha w hw)) (fun w hw => sub_eq_zero.2 (hb w hw)) hz)
#align phragmen_lindelof.eq_on_horizontal_strip PhragmenLindelof.eqOn_horizontal_strip
/-!
### Phragmen-Lindelöf principle in a vertical strip
-/
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < re z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some `c < π / (b - a)`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of `U`.
Then `‖f z‖` is bounded by the same constant on the closed strip
`{z : ℂ | a ≤ re z ≤ b}`. Moreover, it suffices to verify the second assumption
only for sufficiently large values of `|im z|`.
-/
theorem vertical_strip (hfd : DiffContOnCl ℂ f (re ⁻¹' Ioo a b))
(hB : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ im) atTop ⊓ 𝓟 (re ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.im|)))
(hle_a : ∀ z : ℂ, re z = a → ‖f z‖ ≤ C) (hle_b : ∀ z, re z = b → ‖f z‖ ≤ C) (hza : a ≤ re z)
(hzb : re z ≤ b) : ‖f z‖ ≤ C := by
suffices ‖f (z * I * -I)‖ ≤ C by simpa [mul_assoc] using this
have H : MapsTo (· * -I) (im ⁻¹' Ioo a b) (re ⁻¹' Ioo a b) := fun z hz ↦ by simpa using hz
refine horizontal_strip (f := fun z ↦ f (z * -I))
(hfd.comp (differentiable_id.mul_const _).diffContOnCl H) ?_ (fun z hz => hle_a _ ?_)
(fun z hz => hle_b _ ?_) ?_ ?_
· rcases hB with ⟨c, hc, B, hO⟩
refine ⟨c, hc, B, ?_⟩
have : Tendsto (· * -I) (comap (|re ·|) atTop ⊓ 𝓟 (im ⁻¹' Ioo a b))
(comap (|im ·|) atTop ⊓ 𝓟 (re ⁻¹' Ioo a b)) := by
refine (tendsto_comap_iff.2 ?_).inf H.tendsto
simpa [(· ∘ ·)] using tendsto_comap
simpa [(· ∘ ·)] using hO.comp_tendsto this
all_goals simpa
#align phragmen_lindelof.vertical_strip PhragmenLindelof.vertical_strip
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < re z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some `c < π / (b - a)`;
* `f z = 0` on the boundary of `U`.
Then `f` is equal to zero on the closed strip `{z : ℂ | a ≤ re z ≤ b}`.
-/
theorem eq_zero_on_vertical_strip (hd : DiffContOnCl ℂ f (re ⁻¹' Ioo a b))
(hB : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ im) atTop ⊓ 𝓟 (re ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.im|)))
(ha : ∀ z : ℂ, re z = a → f z = 0) (hb : ∀ z : ℂ, re z = b → f z = 0) :
EqOn f 0 (re ⁻¹' Icc a b) := fun _z hz =>
norm_le_zero_iff.1 <| vertical_strip hd hB (fun z hz => (ha z hz).symm ▸ norm_zero.le)
(fun z hz => (hb z hz).symm ▸ norm_zero.le) hz.1 hz.2
#align phragmen_lindelof.eq_zero_on_vertical_strip PhragmenLindelof.eq_zero_on_vertical_strip
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < re z < b}`.
Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable on `U` and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some
`c < π / (b - a)`;
* `f z = g z` on the boundary of `U`.
Then `f` is equal to `g` on the closed strip `{z : ℂ | a ≤ re z ≤ b}`.
-/
theorem eqOn_vertical_strip {g : ℂ → E} (hdf : DiffContOnCl ℂ f (re ⁻¹' Ioo a b))
(hBf : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ im) atTop ⊓ 𝓟 (re ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.im|)))
(hdg : DiffContOnCl ℂ g (re ⁻¹' Ioo a b))
(hBg : ∃ c < π / (b - a), ∃ B, g =O[comap (_root_.abs ∘ im) atTop ⊓ 𝓟 (re ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.im|)))
(ha : ∀ z : ℂ, re z = a → f z = g z) (hb : ∀ z : ℂ, re z = b → f z = g z) :
EqOn f g (re ⁻¹' Icc a b) := fun _z hz =>
sub_eq_zero.1 (eq_zero_on_vertical_strip (hdf.sub hdg) (isBigO_sub_exp_exp hBf hBg)
(fun w hw => sub_eq_zero.2 (ha w hw)) (fun w hw => sub_eq_zero.2 (hb w hw)) hz)
#align phragmen_lindelof.eq_on_vertical_strip PhragmenLindelof.eqOn_vertical_strip
/-!
### Phragmen-Lindelöf principle in coordinate quadrants
-/
/-- **Phragmen-Lindelöf principle** in the first quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open first quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open first quadrant
for some `c < 2`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of the first quadrant.
Then `‖f z‖` is bounded from above by the same constant on the closed first quadrant. -/
nonrec theorem quadrant_I (hd : DiffContOnCl ℂ f (Ioi 0 ×ℂ Ioi 0))
(hB : ∃ c < (2 : ℝ), ∃ B,
f =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c))
(hre : ∀ x : ℝ, 0 ≤ x → ‖f x‖ ≤ C) (him : ∀ x : ℝ, 0 ≤ x → ‖f (x * I)‖ ≤ C) (hz_re : 0 ≤ z.re)
(hz_im : 0 ≤ z.im) : ‖f z‖ ≤ C := by
-- The case `z = 0` is trivial.
rcases eq_or_ne z 0 with (rfl | hzne);
· exact hre 0 le_rfl
-- Otherwise, `z = e ^ ζ` for some `ζ : ℂ`, `0 < Im ζ < π / 2`.
obtain ⟨ζ, hζ, rfl⟩ : ∃ ζ : ℂ, ζ.im ∈ Icc 0 (π / 2) ∧ exp ζ = z := by
refine ⟨log z, ?_, exp_log hzne⟩
rw [log_im]
exact ⟨arg_nonneg_iff.2 hz_im, arg_le_pi_div_two_iff.2 (Or.inl hz_re)⟩
-- Porting note: failed to clear `clear hz_re hz_im hzne`
-- We are going to apply `PhragmenLindelof.horizontal_strip` to `f ∘ Complex.exp` and `ζ`.
change ‖(f ∘ exp) ζ‖ ≤ C
have H : MapsTo exp (im ⁻¹' Ioo 0 (π / 2)) (Ioi 0 ×ℂ Ioi 0) := fun z hz ↦ by
rw [mem_reProdIm, exp_re, exp_im, mem_Ioi, mem_Ioi]
have : 0 < Real.cos z.im := Real.cos_pos_of_mem_Ioo ⟨by linarith [hz.1, hz.2], hz.2⟩
have : 0 < Real.sin z.im :=
Real.sin_pos_of_mem_Ioo ⟨hz.1, hz.2.trans (half_lt_self Real.pi_pos)⟩
constructor <;> positivity
refine horizontal_strip (hd.comp differentiable_exp.diffContOnCl H) ?_ ?_ ?_ hζ.1 hζ.2
-- Porting note: failed to clear hζ ζ
· -- The estimate `hB` on `f` implies the required estimate on
-- `f ∘ exp` with the same `c` and `B' = max B 0`.
rw [sub_zero, div_div_cancel' Real.pi_pos.ne']
rcases hB with ⟨c, hc, B, hO⟩
refine ⟨c, hc, max B 0, ?_⟩
rw [← comap_comap, comap_abs_atTop, comap_sup, inf_sup_right]
-- We prove separately the estimates as `ζ.re → ∞` and as `ζ.re → -∞`
refine IsBigO.sup ?_
((hO.comp_tendsto <| tendsto_exp_comap_re_atTop.inf H.tendsto).trans <| .of_bound 1 ?_)
· -- For the estimate as `ζ.re → -∞`, note that `f` is continuous within the first quadrant at
-- zero, hence `f (exp ζ)` has a limit as `ζ.re → -∞`, `0 < ζ.im < π / 2`.
have hc : ContinuousWithinAt f (Ioi 0 ×ℂ Ioi 0) 0 := by
refine (hd.continuousOn _ ?_).mono subset_closure
simp [closure_reProdIm, mem_reProdIm]
refine ((hc.tendsto.comp <| tendsto_exp_comap_re_atBot.inf H.tendsto).isBigO_one ℝ).trans
(isBigO_of_le _ fun w => ?_)
rw [norm_one, Real.norm_of_nonneg (Real.exp_pos _).le, Real.one_le_exp_iff]
positivity
· -- For the estimate as `ζ.re → ∞`, we reuse the upper estimate on `f`
simp only [eventually_inf_principal, eventually_comap, comp_apply, one_mul,
Real.norm_of_nonneg (Real.exp_pos _).le, abs_exp, ← Real.exp_mul, Real.exp_le_exp]
refine (eventually_ge_atTop 0).mono fun x hx z hz _ => ?_
rw [hz, _root_.abs_of_nonneg hx, mul_comm _ c]
gcongr; apply le_max_left
· -- If `ζ.im = 0`, then `Complex.exp ζ` is a positive real number
intro ζ hζ; lift ζ to ℝ using hζ
rw [comp_apply, ← ofReal_exp]
exact hre _ (Real.exp_pos _).le
· -- If `ζ.im = π / 2`, then `Complex.exp ζ` is a purely imaginary number with positive `im`
intro ζ hζ
rw [← re_add_im ζ, hζ, comp_apply, exp_add_mul_I, ← ofReal_cos, ← ofReal_sin,
Real.cos_pi_div_two, Real.sin_pi_div_two, ofReal_zero, ofReal_one, one_mul, zero_add, ←
ofReal_exp]
exact him _ (Real.exp_pos _).le
set_option linter.uppercaseLean3 false in
#align phragmen_lindelof.quadrant_I PhragmenLindelof.quadrant_I
/-- **Phragmen-Lindelöf principle** in the first quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open first quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open first quadrant
for some `A`, `B`, and `c < 2`;
* `f` is equal to zero on the boundary of the first quadrant.
Then `f` is equal to zero on the closed first quadrant. -/
theorem eq_zero_on_quadrant_I (hd : DiffContOnCl ℂ f (Ioi 0 ×ℂ Ioi 0))
(hB : ∃ c < (2 : ℝ), ∃ B,
f =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c))
(hre : ∀ x : ℝ, 0 ≤ x → f x = 0) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = 0) :
EqOn f 0 {z | 0 ≤ z.re ∧ 0 ≤ z.im} := fun _z hz =>
norm_le_zero_iff.1 <|
quadrant_I hd hB (fun x hx => norm_le_zero_iff.2 <| hre x hx)
(fun x hx => norm_le_zero_iff.2 <| him x hx) hz.1 hz.2
set_option linter.uppercaseLean3 false in
#align phragmen_lindelof.eq_zero_on_quadrant_I PhragmenLindelof.eq_zero_on_quadrant_I
/-- **Phragmen-Lindelöf principle** in the first quadrant. Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable in the open first quadrant and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open first
quadrant for some `A`, `B`, and `c < 2`;
* `f` is equal to `g` on the boundary of the first quadrant.
Then `f` is equal to `g` on the closed first quadrant. -/
theorem eqOn_quadrant_I (hdf : DiffContOnCl ℂ f (Ioi 0 ×ℂ Ioi 0))
(hBf : ∃ c < (2 : ℝ), ∃ B,
f =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c))
(hdg : DiffContOnCl ℂ g (Ioi 0 ×ℂ Ioi 0))
(hBg : ∃ c < (2 : ℝ), ∃ B,
g =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c))
(hre : ∀ x : ℝ, 0 ≤ x → f x = g x) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = g (x * I)) :
EqOn f g {z | 0 ≤ z.re ∧ 0 ≤ z.im} := fun _z hz =>
sub_eq_zero.1 <|
eq_zero_on_quadrant_I (hdf.sub hdg) (isBigO_sub_exp_rpow hBf hBg)
(fun x hx => sub_eq_zero.2 <| hre x hx) (fun x hx => sub_eq_zero.2 <| him x hx) hz
set_option linter.uppercaseLean3 false in
#align phragmen_lindelof.eq_on_quadrant_I PhragmenLindelof.eqOn_quadrant_I
/-- **Phragmen-Lindelöf principle** in the second quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open second quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open second quadrant
for some `c < 2`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of the second quadrant.
Then `‖f z‖` is bounded from above by the same constant on the closed second quadrant. -/
theorem quadrant_II (hd : DiffContOnCl ℂ f (Iio 0 ×ℂ Ioi 0))
(hB : ∃ c < (2 : ℝ), ∃ B,
f =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c))
(hre : ∀ x : ℝ, x ≤ 0 → ‖f x‖ ≤ C) (him : ∀ x : ℝ, 0 ≤ x → ‖f (x * I)‖ ≤ C) (hz_re : z.re ≤ 0)
(hz_im : 0 ≤ z.im) : ‖f z‖ ≤ C := by
obtain ⟨z, rfl⟩ : ∃ z', z' * I = z := ⟨z / I, div_mul_cancel₀ _ I_ne_zero⟩
simp only [mul_I_re, mul_I_im, neg_nonpos] at hz_re hz_im
change ‖(f ∘ (· * I)) z‖ ≤ C
have H : MapsTo (· * I) (Ioi 0 ×ℂ Ioi 0) (Iio 0 ×ℂ Ioi 0) := fun w hw ↦ by
simpa only [mem_reProdIm, mul_I_re, mul_I_im, neg_lt_zero, mem_Iio] using hw.symm
rcases hB with ⟨c, hc, B, hO⟩
refine quadrant_I (hd.comp (differentiable_id.mul_const _).diffContOnCl H) ⟨c, hc, B, ?_⟩ him
(fun x hx => ?_) hz_im hz_re
· simpa only [(· ∘ ·), map_mul, abs_I, mul_one]
using hO.comp_tendsto ((tendsto_mul_right_cobounded I_ne_zero).inf H.tendsto)
· rw [comp_apply, mul_assoc, I_mul_I, mul_neg_one, ← ofReal_neg]
exact hre _ (neg_nonpos.2 hx)
set_option linter.uppercaseLean3 false in
#align phragmen_lindelof.quadrant_II PhragmenLindelof.quadrant_II
/-- **Phragmen-Lindelöf principle** in the second quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open second quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open second quadrant
for some `A`, `B`, and `c < 2`;
* `f` is equal to zero on the boundary of the second quadrant.
Then `f` is equal to zero on the closed second quadrant. -/
theorem eq_zero_on_quadrant_II (hd : DiffContOnCl ℂ f (Iio 0 ×ℂ Ioi 0))
(hB : ∃ c < (2 : ℝ), ∃ B,
f =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c))
(hre : ∀ x : ℝ, x ≤ 0 → f x = 0) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = 0) :
EqOn f 0 {z | z.re ≤ 0 ∧ 0 ≤ z.im} := fun _z hz =>
norm_le_zero_iff.1 <|
quadrant_II hd hB (fun x hx => norm_le_zero_iff.2 <| hre x hx)
(fun x hx => norm_le_zero_iff.2 <| him x hx) hz.1 hz.2
set_option linter.uppercaseLean3 false in
#align phragmen_lindelof.eq_zero_on_quadrant_II PhragmenLindelof.eq_zero_on_quadrant_II
/-- **Phragmen-Lindelöf principle** in the second quadrant. Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable in the open second quadrant and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open second
quadrant for some `A`, `B`, and `c < 2`;
* `f` is equal to `g` on the boundary of the second quadrant.
Then `f` is equal to `g` on the closed second quadrant. -/
theorem eqOn_quadrant_II (hdf : DiffContOnCl ℂ f (Iio 0 ×ℂ Ioi 0))
(hBf : ∃ c < (2 : ℝ), ∃ B,
f =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c))
(hdg : DiffContOnCl ℂ g (Iio 0 ×ℂ Ioi 0))
(hBg : ∃ c < (2 : ℝ), ∃ B,
g =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c))
(hre : ∀ x : ℝ, x ≤ 0 → f x = g x) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = g (x * I)) :
EqOn f g {z | z.re ≤ 0 ∧ 0 ≤ z.im} := fun _z hz =>
sub_eq_zero.1 <| eq_zero_on_quadrant_II (hdf.sub hdg) (isBigO_sub_exp_rpow hBf hBg)
(fun x hx => sub_eq_zero.2 <| hre x hx) (fun x hx => sub_eq_zero.2 <| him x hx) hz
set_option linter.uppercaseLean3 false in
#align phragmen_lindelof.eq_on_quadrant_II PhragmenLindelof.eqOn_quadrant_II
/-- **Phragmen-Lindelöf principle** in the third quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open third quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp (B * (abs z) ^ c)` on the open third quadrant
for some `c < 2`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of the third quadrant.
Then `‖f z‖` is bounded from above by the same constant on the closed third quadrant. -/
| Mathlib/Analysis/Complex/PhragmenLindelof.lean | 529 | 550 | theorem quadrant_III (hd : DiffContOnCl ℂ f (Iio 0 ×ℂ Iio 0))
(hB : ∃ c < (2 : ℝ), ∃ B,
f =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Iio 0)] fun z => expR (B * abs z ^ c))
(hre : ∀ x : ℝ, x ≤ 0 → ‖f x‖ ≤ C) (him : ∀ x : ℝ, x ≤ 0 → ‖f (x * I)‖ ≤ C) (hz_re : z.re ≤ 0)
(hz_im : z.im ≤ 0) : ‖f z‖ ≤ C := by |
obtain ⟨z, rfl⟩ : ∃ z', -z' = z := ⟨-z, neg_neg z⟩
simp only [neg_re, neg_im, neg_nonpos] at hz_re hz_im
change ‖(f ∘ Neg.neg) z‖ ≤ C
have H : MapsTo Neg.neg (Ioi 0 ×ℂ Ioi 0) (Iio 0 ×ℂ Iio 0) := by
intro w hw
simpa only [mem_reProdIm, neg_re, neg_im, neg_lt_zero, mem_Iio] using hw
refine
quadrant_I (hd.comp differentiable_neg.diffContOnCl H) ?_ (fun x hx => ?_) (fun x hx => ?_)
hz_re hz_im
· rcases hB with ⟨c, hc, B, hO⟩
refine ⟨c, hc, B, ?_⟩
simpa only [(· ∘ ·), Complex.abs.map_neg]
using hO.comp_tendsto (tendsto_neg_cobounded.inf H.tendsto)
· rw [comp_apply, ← ofReal_neg]
exact hre (-x) (neg_nonpos.2 hx)
· rw [comp_apply, ← neg_mul, ← ofReal_neg]
exact him (-x) (neg_nonpos.2 hx)
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau, Yury Kudryashov
-/
import Mathlib.Logic.Relation
import Mathlib.Data.List.Forall2
import Mathlib.Data.List.Lex
import Mathlib.Data.List.Infix
#align_import data.list.chain from "leanprover-community/mathlib"@"dd71334db81d0bd444af1ee339a29298bef40734"
/-!
# Relation chain
This file provides basic results about `List.Chain` (definition in `Data.List.Defs`).
A list `[a₂, ..., aₙ]` is a `Chain` starting at `a₁` with respect to the relation `r` if `r a₁ a₂`
and `r a₂ a₃` and ... and `r aₙ₋₁ aₙ`. We write it `Chain r a₁ [a₂, ..., aₙ]`.
A graph-specialized version is in development and will hopefully be added under `combinatorics.`
sometime soon.
-/
-- Make sure we haven't imported `Data.Nat.Order.Basic`
assert_not_exists OrderedSub
universe u v
open Nat
namespace List
variable {α : Type u} {β : Type v} {R r : α → α → Prop} {l l₁ l₂ : List α} {a b : α}
mk_iff_of_inductive_prop List.Chain List.chain_iff
#align list.chain_iff List.chain_iff
#align list.chain.nil List.Chain.nil
#align list.chain.cons List.Chain.cons
#align list.rel_of_chain_cons List.rel_of_chain_cons
#align list.chain_of_chain_cons List.chain_of_chain_cons
#align list.chain.imp' List.Chain.imp'
#align list.chain.imp List.Chain.imp
theorem Chain.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {a : α} {l : List α} :
Chain R a l ↔ Chain S a l :=
⟨Chain.imp fun a b => (H a b).1, Chain.imp fun a b => (H a b).2⟩
#align list.chain.iff List.Chain.iff
theorem Chain.iff_mem {a : α} {l : List α} :
Chain R a l ↔ Chain (fun x y => x ∈ a :: l ∧ y ∈ l ∧ R x y) a l :=
⟨fun p => by
induction' p with _ a b l r _ IH <;> constructor <;>
[exact ⟨mem_cons_self _ _, mem_cons_self _ _, r⟩;
exact IH.imp fun a b ⟨am, bm, h⟩ => ⟨mem_cons_of_mem _ am, mem_cons_of_mem _ bm, h⟩],
Chain.imp fun a b h => h.2.2⟩
#align list.chain.iff_mem List.Chain.iff_mem
theorem chain_singleton {a b : α} : Chain R a [b] ↔ R a b := by
simp only [chain_cons, Chain.nil, and_true_iff]
#align list.chain_singleton List.chain_singleton
theorem chain_split {a b : α} {l₁ l₂ : List α} :
Chain R a (l₁ ++ b :: l₂) ↔ Chain R a (l₁ ++ [b]) ∧ Chain R b l₂ := by
induction' l₁ with x l₁ IH generalizing a <;>
simp only [*, nil_append, cons_append, Chain.nil, chain_cons, and_true_iff, and_assoc]
#align list.chain_split List.chain_split
@[simp]
theorem chain_append_cons_cons {a b c : α} {l₁ l₂ : List α} :
Chain R a (l₁ ++ b :: c :: l₂) ↔ Chain R a (l₁ ++ [b]) ∧ R b c ∧ Chain R c l₂ := by
rw [chain_split, chain_cons]
#align list.chain_append_cons_cons List.chain_append_cons_cons
theorem chain_iff_forall₂ :
∀ {a : α} {l : List α}, Chain R a l ↔ l = [] ∨ Forall₂ R (a :: dropLast l) l
| a, [] => by simp
| a, b :: l => by
by_cases h : l = [] <;>
simp [@chain_iff_forall₂ b l, dropLast, *]
#align list.chain_iff_forall₂ List.chain_iff_forall₂
theorem chain_append_singleton_iff_forall₂ :
Chain R a (l ++ [b]) ↔ Forall₂ R (a :: l) (l ++ [b]) := by simp [chain_iff_forall₂]
#align list.chain_append_singleton_iff_forall₂ List.chain_append_singleton_iff_forall₂
theorem chain_map (f : β → α) {b : β} {l : List β} :
Chain R (f b) (map f l) ↔ Chain (fun a b : β => R (f a) (f b)) b l := by
induction l generalizing b <;> simp only [map, Chain.nil, chain_cons, *]
#align list.chain_map List.chain_map
theorem chain_of_chain_map {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, S (f a) (f b) → R a b)
{a : α} {l : List α} (p : Chain S (f a) (map f l)) : Chain R a l :=
((chain_map f).1 p).imp H
#align list.chain_of_chain_map List.chain_of_chain_map
theorem chain_map_of_chain {S : β → β → Prop} (f : α → β) (H : ∀ a b : α, R a b → S (f a) (f b))
{a : α} {l : List α} (p : Chain R a l) : Chain S (f a) (map f l) :=
(chain_map f).2 <| p.imp H
#align list.chain_map_of_chain List.chain_map_of_chain
theorem chain_pmap_of_chain {S : β → β → Prop} {p : α → Prop} {f : ∀ a, p a → β}
(H : ∀ a b ha hb, R a b → S (f a ha) (f b hb)) {a : α} {l : List α} (hl₁ : Chain R a l)
(ha : p a) (hl₂ : ∀ a ∈ l, p a) : Chain S (f a ha) (List.pmap f l hl₂) := by
induction' l with lh lt l_ih generalizing a
· simp
· simp [H _ _ _ _ (rel_of_chain_cons hl₁), l_ih (chain_of_chain_cons hl₁)]
#align list.chain_pmap_of_chain List.chain_pmap_of_chain
theorem chain_of_chain_pmap {S : β → β → Prop} {p : α → Prop} (f : ∀ a, p a → β) {l : List α}
(hl₁ : ∀ a ∈ l, p a) {a : α} (ha : p a) (hl₂ : Chain S (f a ha) (List.pmap f l hl₁))
(H : ∀ a b ha hb, S (f a ha) (f b hb) → R a b) : Chain R a l := by
induction' l with lh lt l_ih generalizing a
· simp
· simp [H _ _ _ _ (rel_of_chain_cons hl₂), l_ih _ _ (chain_of_chain_cons hl₂)]
#align list.chain_of_chain_pmap List.chain_of_chain_pmap
#align list.pairwise.chain List.Pairwise.chain
protected theorem Chain.pairwise [IsTrans α R] :
∀ {a : α} {l : List α}, Chain R a l → Pairwise R (a :: l)
| a, [], Chain.nil => pairwise_singleton _ _
| a, _, @Chain.cons _ _ _ b l h hb =>
hb.pairwise.cons
(by
simp only [mem_cons, forall_eq_or_imp, h, true_and_iff]
exact fun c hc => _root_.trans h (rel_of_pairwise_cons hb.pairwise hc))
#align list.chain.pairwise List.Chain.pairwise
theorem chain_iff_pairwise [IsTrans α R] {a : α} {l : List α} : Chain R a l ↔ Pairwise R (a :: l) :=
⟨Chain.pairwise, Pairwise.chain⟩
#align list.chain_iff_pairwise List.chain_iff_pairwise
protected theorem Chain.sublist [IsTrans α R] (hl : l₂.Chain R a) (h : l₁ <+ l₂) :
l₁.Chain R a := by
rw [chain_iff_pairwise] at hl ⊢
exact hl.sublist (h.cons_cons a)
#align list.chain.sublist List.Chain.sublist
protected theorem Chain.rel [IsTrans α R] (hl : l.Chain R a) (hb : b ∈ l) : R a b := by
rw [chain_iff_pairwise] at hl
exact rel_of_pairwise_cons hl hb
#align list.chain.rel List.Chain.rel
theorem chain_iff_get {R} : ∀ {a : α} {l : List α}, Chain R a l ↔
(∀ h : 0 < length l, R a (get l ⟨0, h⟩)) ∧
∀ (i : ℕ) (h : i < l.length - 1),
R (get l ⟨i, by omega⟩) (get l ⟨i+1, by omega⟩)
| a, [] => iff_of_true (by simp) ⟨fun h => by simp at h, fun _ h => by simp at h⟩
| a, b :: t => by
rw [chain_cons, @chain_iff_get _ _ t]
constructor
· rintro ⟨R, ⟨h0, h⟩⟩
constructor
· intro _
exact R
intro i w
cases' i with i
· apply h0
· exact h i (by simp only [length_cons] at w; omega)
rintro ⟨h0, h⟩; constructor
· apply h0
simp
constructor
· apply h 0
intro i w
exact h (i+1) (by simp only [length_cons]; omega)
set_option linter.deprecated false in
@[deprecated chain_iff_get (since := "2023-01-10")]
theorem chain_iff_nthLe {R} {a : α} {l : List α} : Chain R a l ↔
(∀ h : 0 < length l, R a (nthLe l 0 h)) ∧
∀ (i) (h : i < length l - 1),
R (nthLe l i (by omega)) (nthLe l (i + 1) (by omega)) := by
rw [chain_iff_get]; simp [nthLe]
#align list.chain_iff_nth_le List.chain_iff_nthLe
theorem Chain'.imp {S : α → α → Prop} (H : ∀ a b, R a b → S a b) {l : List α} (p : Chain' R l) :
Chain' S l := by cases l <;> [trivial; exact Chain.imp H p]
#align list.chain'.imp List.Chain'.imp
theorem Chain'.iff {S : α → α → Prop} (H : ∀ a b, R a b ↔ S a b) {l : List α} :
Chain' R l ↔ Chain' S l :=
⟨Chain'.imp fun a b => (H a b).1, Chain'.imp fun a b => (H a b).2⟩
#align list.chain'.iff List.Chain'.iff
theorem Chain'.iff_mem : ∀ {l : List α}, Chain' R l ↔ Chain' (fun x y => x ∈ l ∧ y ∈ l ∧ R x y) l
| [] => Iff.rfl
| _ :: _ =>
⟨fun h => (Chain.iff_mem.1 h).imp fun _ _ ⟨h₁, h₂, h₃⟩ => ⟨h₁, mem_cons.2 (Or.inr h₂), h₃⟩,
Chain'.imp fun _ _ h => h.2.2⟩
#align list.chain'.iff_mem List.Chain'.iff_mem
@[simp]
theorem chain'_nil : Chain' R [] :=
trivial
#align list.chain'_nil List.chain'_nil
@[simp]
theorem chain'_singleton (a : α) : Chain' R [a] :=
Chain.nil
#align list.chain'_singleton List.chain'_singleton
@[simp]
theorem chain'_cons {x y l} : Chain' R (x :: y :: l) ↔ R x y ∧ Chain' R (y :: l) :=
chain_cons
#align list.chain'_cons List.chain'_cons
theorem chain'_isInfix : ∀ l : List α, Chain' (fun x y => [x, y] <:+: l) l
| [] => chain'_nil
| [a] => chain'_singleton _
| a :: b :: l =>
chain'_cons.2
⟨⟨[], l, by simp⟩, (chain'_isInfix (b :: l)).imp fun x y h => h.trans ⟨[a], [], by simp⟩⟩
#align list.chain'_is_infix List.chain'_isInfix
theorem chain'_split {a : α} :
∀ {l₁ l₂ : List α}, Chain' R (l₁ ++ a :: l₂) ↔ Chain' R (l₁ ++ [a]) ∧ Chain' R (a :: l₂)
| [], _ => (and_iff_right (chain'_singleton a)).symm
| _ :: _, _ => chain_split
#align list.chain'_split List.chain'_split
@[simp]
| Mathlib/Data/List/Chain.lean | 223 | 225 | theorem chain'_append_cons_cons {b c : α} {l₁ l₂ : List α} :
Chain' R (l₁ ++ b :: c :: l₂) ↔ Chain' R (l₁ ++ [b]) ∧ R b c ∧ Chain' R (c :: l₂) := by |
rw [chain'_split, chain'_cons]
|
/-
Copyright (c) 2019 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov
-/
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Analysis.Convex.Hull
import Mathlib.LinearAlgebra.AffineSpace.Basis
#align_import analysis.convex.combination from "leanprover-community/mathlib"@"92bd7b1ffeb306a89f450bee126ddd8a284c259d"
/-!
# Convex combinations
This file defines convex combinations of points in a vector space.
## Main declarations
* `Finset.centerMass`: Center of mass of a finite family of points.
## Implementation notes
We divide by the sum of the weights in the definition of `Finset.centerMass` because of the way
mathematical arguments go: one doesn't change weights, but merely adds some. This also makes a few
lemmas unconditional on the sum of the weights being `1`.
-/
open Set Function
open scoped Classical
open Pointwise
universe u u'
variable {R R' E F ι ι' α : Type*} [LinearOrderedField R] [LinearOrderedField R'] [AddCommGroup E]
[AddCommGroup F] [LinearOrderedAddCommGroup α] [Module R E] [Module R F] [Module R α]
[OrderedSMul R α] {s : Set E}
/-- Center of mass of a finite collection of points with prescribed weights.
Note that we require neither `0 ≤ w i` nor `∑ w = 1`. -/
def Finset.centerMass (t : Finset ι) (w : ι → R) (z : ι → E) : E :=
(∑ i ∈ t, w i)⁻¹ • ∑ i ∈ t, w i • z i
#align finset.center_mass Finset.centerMass
variable (i j : ι) (c : R) (t : Finset ι) (w : ι → R) (z : ι → E)
open Finset
theorem Finset.centerMass_empty : (∅ : Finset ι).centerMass w z = 0 := by
simp only [centerMass, sum_empty, smul_zero]
#align finset.center_mass_empty Finset.centerMass_empty
theorem Finset.centerMass_pair (hne : i ≠ j) :
({i, j} : Finset ι).centerMass w z = (w i / (w i + w j)) • z i + (w j / (w i + w j)) • z j := by
simp only [centerMass, sum_pair hne, smul_add, (mul_smul _ _ _).symm, div_eq_inv_mul]
#align finset.center_mass_pair Finset.centerMass_pair
variable {w}
theorem Finset.centerMass_insert (ha : i ∉ t) (hw : ∑ j ∈ t, w j ≠ 0) :
(insert i t).centerMass w z =
(w i / (w i + ∑ j ∈ t, w j)) • z i +
((∑ j ∈ t, w j) / (w i + ∑ j ∈ t, w j)) • t.centerMass w z := by
simp only [centerMass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, ← div_eq_inv_mul]
congr 2
rw [div_mul_eq_mul_div, mul_inv_cancel hw, one_div]
#align finset.center_mass_insert Finset.centerMass_insert
theorem Finset.centerMass_singleton (hw : w i ≠ 0) : ({i} : Finset ι).centerMass w z = z i := by
rw [centerMass, sum_singleton, sum_singleton, ← mul_smul, inv_mul_cancel hw, one_smul]
#align finset.center_mass_singleton Finset.centerMass_singleton
@[simp] lemma Finset.centerMass_neg_left : t.centerMass (-w) z = t.centerMass w z := by
simp [centerMass, inv_neg]
lemma Finset.centerMass_smul_left {c : R'} [Module R' R] [Module R' E] [SMulCommClass R' R R]
[IsScalarTower R' R R] [SMulCommClass R R' E] [IsScalarTower R' R E] (hc : c ≠ 0) :
t.centerMass (c • w) z = t.centerMass w z := by
simp [centerMass, -smul_assoc, smul_assoc c, ← smul_sum, smul_inv₀, smul_smul_smul_comm, hc]
theorem Finset.centerMass_eq_of_sum_1 (hw : ∑ i ∈ t, w i = 1) :
t.centerMass w z = ∑ i ∈ t, w i • z i := by
simp only [Finset.centerMass, hw, inv_one, one_smul]
#align finset.center_mass_eq_of_sum_1 Finset.centerMass_eq_of_sum_1
theorem Finset.centerMass_smul : (t.centerMass w fun i => c • z i) = c • t.centerMass w z := by
simp only [Finset.centerMass, Finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc]
#align finset.center_mass_smul Finset.centerMass_smul
/-- A convex combination of two centers of mass is a center of mass as well. This version
deals with two different index types. -/
theorem Finset.centerMass_segment' (s : Finset ι) (t : Finset ι') (ws : ι → R) (zs : ι → E)
(wt : ι' → R) (zt : ι' → E) (hws : ∑ i ∈ s, ws i = 1) (hwt : ∑ i ∈ t, wt i = 1) (a b : R)
(hab : a + b = 1) : a • s.centerMass ws zs + b • t.centerMass wt zt = (s.disjSum t).centerMass
(Sum.elim (fun i => a * ws i) fun j => b * wt j) (Sum.elim zs zt) := by
rw [s.centerMass_eq_of_sum_1 _ hws, t.centerMass_eq_of_sum_1 _ hwt, smul_sum, smul_sum, ←
Finset.sum_sum_elim, Finset.centerMass_eq_of_sum_1]
· congr with ⟨⟩ <;> simp only [Sum.elim_inl, Sum.elim_inr, mul_smul]
· rw [sum_sum_elim, ← mul_sum, ← mul_sum, hws, hwt, mul_one, mul_one, hab]
#align finset.center_mass_segment' Finset.centerMass_segment'
/-- A convex combination of two centers of mass is a center of mass as well. This version
works if two centers of mass share the set of original points. -/
theorem Finset.centerMass_segment (s : Finset ι) (w₁ w₂ : ι → R) (z : ι → E)
(hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) (a b : R) (hab : a + b = 1) :
a • s.centerMass w₁ z + b • s.centerMass w₂ z =
s.centerMass (fun i => a * w₁ i + b * w₂ i) z := by
have hw : (∑ i ∈ s, (a * w₁ i + b * w₂ i)) = 1 := by
simp only [← mul_sum, sum_add_distrib, mul_one, *]
simp only [Finset.centerMass_eq_of_sum_1, Finset.centerMass_eq_of_sum_1 _ _ hw,
smul_sum, sum_add_distrib, add_smul, mul_smul, *]
#align finset.center_mass_segment Finset.centerMass_segment
theorem Finset.centerMass_ite_eq (hi : i ∈ t) :
t.centerMass (fun j => if i = j then (1 : R) else 0) z = z i := by
rw [Finset.centerMass_eq_of_sum_1]
· trans ∑ j ∈ t, if i = j then z i else 0
· congr with i
split_ifs with h
exacts [h ▸ one_smul _ _, zero_smul _ _]
· rw [sum_ite_eq, if_pos hi]
· rw [sum_ite_eq, if_pos hi]
#align finset.center_mass_ite_eq Finset.centerMass_ite_eq
variable {t}
theorem Finset.centerMass_subset {t' : Finset ι} (ht : t ⊆ t') (h : ∀ i ∈ t', i ∉ t → w i = 0) :
t.centerMass w z = t'.centerMass w z := by
rw [centerMass, sum_subset ht h, smul_sum, centerMass, smul_sum]
apply sum_subset ht
intro i hit' hit
rw [h i hit' hit, zero_smul, smul_zero]
#align finset.center_mass_subset Finset.centerMass_subset
theorem Finset.centerMass_filter_ne_zero :
(t.filter fun i => w i ≠ 0).centerMass w z = t.centerMass w z :=
Finset.centerMass_subset z (filter_subset _ _) fun i hit hit' => by
simpa only [hit, mem_filter, true_and_iff, Ne, Classical.not_not] using hit'
#align finset.center_mass_filter_ne_zero Finset.centerMass_filter_ne_zero
namespace Finset
theorem centerMass_le_sup {s : Finset ι} {f : ι → α} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i)
(hw₁ : 0 < ∑ i ∈ s, w i) :
s.centerMass w f ≤ s.sup' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f := by
rw [centerMass, inv_smul_le_iff_of_pos hw₁, sum_smul]
exact sum_le_sum fun i hi => smul_le_smul_of_nonneg_left (le_sup' _ hi) <| hw₀ i hi
#align finset.center_mass_le_sup Finset.centerMass_le_sup
theorem inf_le_centerMass {s : Finset ι} {f : ι → α} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i)
(hw₁ : 0 < ∑ i ∈ s, w i) :
s.inf' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f ≤ s.centerMass w f :=
@centerMass_le_sup R _ αᵒᵈ _ _ _ _ _ _ _ hw₀ hw₁
#align finset.inf_le_center_mass Finset.inf_le_centerMass
end Finset
variable {z}
lemma Finset.centerMass_of_sum_add_sum_eq_zero {s t : Finset ι}
(hw : ∑ i ∈ s, w i + ∑ i ∈ t, w i = 0) (hz : ∑ i ∈ s, w i • z i + ∑ i ∈ t, w i • z i = 0) :
s.centerMass w z = t.centerMass w z := by
simp [centerMass, eq_neg_of_add_eq_zero_right hw, eq_neg_of_add_eq_zero_left hz, ← neg_inv]
/-- The center of mass of a finite subset of a convex set belongs to the set
provided that all weights are non-negative, and the total weight is positive. -/
theorem Convex.centerMass_mem (hs : Convex R s) :
(∀ i ∈ t, 0 ≤ w i) → (0 < ∑ i ∈ t, w i) → (∀ i ∈ t, z i ∈ s) → t.centerMass w z ∈ s := by
induction' t using Finset.induction with i t hi ht
· simp [lt_irrefl]
intro h₀ hpos hmem
have zi : z i ∈ s := hmem _ (mem_insert_self _ _)
have hs₀ : ∀ j ∈ t, 0 ≤ w j := fun j hj => h₀ j <| mem_insert_of_mem hj
rw [sum_insert hi] at hpos
by_cases hsum_t : ∑ j ∈ t, w j = 0
· have ws : ∀ j ∈ t, w j = 0 := (sum_eq_zero_iff_of_nonneg hs₀).1 hsum_t
have wz : ∑ j ∈ t, w j • z j = 0 := sum_eq_zero fun i hi => by simp [ws i hi]
simp only [centerMass, sum_insert hi, wz, hsum_t, add_zero]
simp only [hsum_t, add_zero] at hpos
rw [← mul_smul, inv_mul_cancel (ne_of_gt hpos), one_smul]
exact zi
· rw [Finset.centerMass_insert _ _ _ hi hsum_t]
refine convex_iff_div.1 hs zi (ht hs₀ ?_ ?_) ?_ (sum_nonneg hs₀) hpos
· exact lt_of_le_of_ne (sum_nonneg hs₀) (Ne.symm hsum_t)
· intro j hj
exact hmem j (mem_insert_of_mem hj)
· exact h₀ _ (mem_insert_self _ _)
#align convex.center_mass_mem Convex.centerMass_mem
| Mathlib/Analysis/Convex/Combination.lean | 191 | 194 | theorem Convex.sum_mem (hs : Convex R s) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1)
(hz : ∀ i ∈ t, z i ∈ s) : (∑ i ∈ t, w i • z i) ∈ s := by |
simpa only [h₁, centerMass, inv_one, one_smul] using
hs.centerMass_mem h₀ (h₁.symm ▸ zero_lt_one) hz
|
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Jujian Zhang
-/
import Mathlib.Algebra.DirectSum.Module
import Mathlib.Algebra.Module.Submodule.Basic
#align_import algebra.direct_sum.decomposition from "leanprover-community/mathlib"@"4e861f25ba5ceef42ba0712d8ffeb32f38ad6441"
/-!
# Decompositions of additive monoids, groups, and modules into direct sums
## Main definitions
* `DirectSum.Decomposition ℳ`: A typeclass to provide a constructive decomposition from
an additive monoid `M` into a family of additive submonoids `ℳ`
* `DirectSum.decompose ℳ`: The canonical equivalence provided by the above typeclass
## Main statements
* `DirectSum.Decomposition.isInternal`: The link to `DirectSum.IsInternal`.
## Implementation details
As we want to talk about different types of decomposition (additive monoids, modules, rings, ...),
we choose to avoid heavily bundling `DirectSum.decompose`, instead making copies for the
`AddEquiv`, `LinearEquiv`, etc. This means we have to repeat statements that follow from these
bundled homs, but means we don't have to repeat statements for different types of decomposition.
-/
variable {ι R M σ : Type*}
open DirectSum
namespace DirectSum
section AddCommMonoid
variable [DecidableEq ι] [AddCommMonoid M]
variable [SetLike σ M] [AddSubmonoidClass σ M] (ℳ : ι → σ)
/-- A decomposition is an equivalence between an additive monoid `M` and a direct sum of additive
submonoids `ℳ i` of that `M`, such that the "recomposition" is canonical. This definition also
works for additive groups and modules.
This is a version of `DirectSum.IsInternal` which comes with a constructive inverse to the
canonical "recomposition" rather than just a proof that the "recomposition" is bijective.
Often it is easier to construct a term of this type via `Decomposition.ofAddHom` or
`Decomposition.ofLinearMap`. -/
class Decomposition where
decompose' : M → ⨁ i, ℳ i
left_inv : Function.LeftInverse (DirectSum.coeAddMonoidHom ℳ) decompose'
right_inv : Function.RightInverse (DirectSum.coeAddMonoidHom ℳ) decompose'
#align direct_sum.decomposition DirectSum.Decomposition
/-- `DirectSum.Decomposition` instances, while carrying data, are always equal. -/
instance : Subsingleton (Decomposition ℳ) :=
⟨fun x y ↦ by
cases' x with x xl xr
cases' y with y yl yr
congr
exact Function.LeftInverse.eq_rightInverse xr yl⟩
/-- A convenience method to construct a decomposition from an `AddMonoidHom`, such that the proofs
of left and right inverse can be constructed via `ext`. -/
abbrev Decomposition.ofAddHom (decompose : M →+ ⨁ i, ℳ i)
(h_left_inv : (DirectSum.coeAddMonoidHom ℳ).comp decompose = .id _)
(h_right_inv : decompose.comp (DirectSum.coeAddMonoidHom ℳ) = .id _) : Decomposition ℳ where
decompose' := decompose
left_inv := DFunLike.congr_fun h_left_inv
right_inv := DFunLike.congr_fun h_right_inv
/-- Noncomputably conjure a decomposition instance from a `DirectSum.IsInternal` proof. -/
noncomputable def IsInternal.chooseDecomposition (h : IsInternal ℳ) :
DirectSum.Decomposition ℳ where
decompose' := (Equiv.ofBijective _ h).symm
left_inv := (Equiv.ofBijective _ h).right_inv
right_inv := (Equiv.ofBijective _ h).left_inv
variable [Decomposition ℳ]
protected theorem Decomposition.isInternal : DirectSum.IsInternal ℳ :=
⟨Decomposition.right_inv.injective, Decomposition.left_inv.surjective⟩
#align direct_sum.decomposition.is_internal DirectSum.Decomposition.isInternal
/-- If `M` is graded by `ι` with degree `i` component `ℳ i`, then it is isomorphic as
to a direct sum of components. This is the canonical spelling of the `decompose'` field. -/
def decompose : M ≃ ⨁ i, ℳ i where
toFun := Decomposition.decompose'
invFun := DirectSum.coeAddMonoidHom ℳ
left_inv := Decomposition.left_inv
right_inv := Decomposition.right_inv
#align direct_sum.decompose DirectSum.decompose
protected theorem Decomposition.inductionOn {p : M → Prop} (h_zero : p 0)
(h_homogeneous : ∀ {i} (m : ℳ i), p (m : M)) (h_add : ∀ m m' : M, p m → p m' → p (m + m')) :
∀ m, p m := by
let ℳ' : ι → AddSubmonoid M := fun i ↦
(⟨⟨ℳ i, fun x y ↦ AddMemClass.add_mem x y⟩, (ZeroMemClass.zero_mem _)⟩ : AddSubmonoid M)
haveI t : DirectSum.Decomposition ℳ' :=
{ decompose' := DirectSum.decompose ℳ
left_inv := fun _ ↦ (decompose ℳ).left_inv _
right_inv := fun _ ↦ (decompose ℳ).right_inv _ }
have mem : ∀ m, m ∈ iSup ℳ' := fun _m ↦
(DirectSum.IsInternal.addSubmonoid_iSup_eq_top ℳ' (Decomposition.isInternal ℳ')).symm ▸ trivial
-- Porting note: needs to use @ even though no implicit argument is provided
exact fun m ↦ @AddSubmonoid.iSup_induction _ _ _ ℳ' _ _ (mem m)
(fun i m h ↦ h_homogeneous ⟨m, h⟩) h_zero h_add
-- exact fun m ↦
-- AddSubmonoid.iSup_induction ℳ' (mem m) (fun i m h ↦ h_homogeneous ⟨m, h⟩) h_zero h_add
#align direct_sum.decomposition.induction_on DirectSum.Decomposition.inductionOn
@[simp]
theorem Decomposition.decompose'_eq : Decomposition.decompose' = decompose ℳ := rfl
#align direct_sum.decomposition.decompose'_eq DirectSum.Decomposition.decompose'_eq
@[simp]
theorem decompose_symm_of {i : ι} (x : ℳ i) : (decompose ℳ).symm (DirectSum.of _ i x) = x :=
DirectSum.coeAddMonoidHom_of ℳ _ _
#align direct_sum.decompose_symm_of DirectSum.decompose_symm_of
@[simp]
theorem decompose_coe {i : ι} (x : ℳ i) : decompose ℳ (x : M) = DirectSum.of _ i x := by
rw [← decompose_symm_of _, Equiv.apply_symm_apply]
#align direct_sum.decompose_coe DirectSum.decompose_coe
theorem decompose_of_mem {x : M} {i : ι} (hx : x ∈ ℳ i) :
decompose ℳ x = DirectSum.of (fun i ↦ ℳ i) i ⟨x, hx⟩ :=
decompose_coe _ ⟨x, hx⟩
#align direct_sum.decompose_of_mem DirectSum.decompose_of_mem
theorem decompose_of_mem_same {x : M} {i : ι} (hx : x ∈ ℳ i) : (decompose ℳ x i : M) = x := by
rw [decompose_of_mem _ hx, DirectSum.of_eq_same, Subtype.coe_mk]
#align direct_sum.decompose_of_mem_same DirectSum.decompose_of_mem_same
theorem decompose_of_mem_ne {x : M} {i j : ι} (hx : x ∈ ℳ i) (hij : i ≠ j) :
(decompose ℳ x j : M) = 0 := by
rw [decompose_of_mem _ hx, DirectSum.of_eq_of_ne _ _ _ _ hij, ZeroMemClass.coe_zero]
#align direct_sum.decompose_of_mem_ne DirectSum.decompose_of_mem_ne
| Mathlib/Algebra/DirectSum/Decomposition.lean | 145 | 147 | theorem degree_eq_of_mem_mem {x : M} {i j : ι} (hxi : x ∈ ℳ i) (hxj : x ∈ ℳ j) (hx : x ≠ 0) :
i = j := by |
contrapose! hx; rw [← decompose_of_mem_same ℳ hxj, decompose_of_mem_ne ℳ hxi hx]
|
/-
Copyright (c) 2023 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Algebra.Unitization
import Mathlib.Algebra.Star.NonUnitalSubalgebra
import Mathlib.Algebra.Star.Subalgebra
import Mathlib.GroupTheory.GroupAction.Ring
/-!
# Relating unital and non-unital substructures
This file relates various algebraic structures and provides maps (generally algebra homomorphisms),
from the unitization of a non-unital subobject into the full structure. The range of this map is
the unital closure of the non-unital subobject (e.g., `Algebra.adjoin`, `Subring.closure`,
`Subsemiring.closure` or `StarAlgebra.adjoin`). When the underlying scalar ring is a field, for
this map to be injective it suffices that the range omits `1`. In this setting we provide suitable
`AlgEquiv` (or `StarAlgEquiv`) onto the range.
## Main declarations
* `NonUnitalSubalgebra.unitization s : Unitization R s →ₐ[R] A`:
where `s` is a non-unital subalgebra of a unital `R`-algebra `A`, this is the natural algebra
homomorphism sending `(r, a)` to `r • 1 + a`. The range of this map is
`Algebra.adjoin R (s : Set A)`.
* `NonUnitalSubalgebra.unitizationAlgEquiv s : Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A)`
when `R` is a field and `1 ∉ s`. This is `NonUnitalSubalgebra.unitization` upgraded to an
`AlgEquiv` onto its range.
* `NonUnitalSubsemiring.unitization : Unitization ℕ s →ₐ[ℕ] R`: the natural `ℕ`-algebra homomorphism
from the unitization of a non-unital subsemiring `s` into the ring containing it. The range of
this map is `subalgebraOfSubsemiring (Subsemiring.closure s)`.
This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because
there is an instance Lean can't find on its own due to `outParam`.
* `NonUnitalSubring.unitization : Unitization ℤ s →ₐ[ℤ] R`:
the natural `ℤ`-algebra homomorphism from the unitization of a non-unital subring `s` into the
ring containing it. The range of this map is `subalgebraOfSubring (Subring.closure s)`.
This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because
there is an instance Lean can't find on its own due to `outParam`.
* `NonUnitalStarSubalgebra s : Unitization R s →⋆ₐ[R] A`: a version of
`NonUnitalSubalgebra.unitization` for star algebras.
* `NonUnitalStarSubalgebra.unitizationStarAlgEquiv s :`
`Unitization R s ≃⋆ₐ[R] StarAlgebra.adjoin R (s : Set A)`:
a version of `NonUnitalSubalgebra.unitizationAlgEquiv` for star algebras.
-/
/-! ## Subalgebras -/
section Subalgebra
variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]
/-- Turn a `Subalgebra` into a `NonUnitalSubalgebra` by forgetting that it contains `1`. -/
def Subalgebra.toNonUnitalSubalgebra (S : Subalgebra R A) : NonUnitalSubalgebra R A :=
{ S with
smul_mem' := fun r _x hx => S.smul_mem hx r }
theorem Subalgebra.one_mem_toNonUnitalSubalgebra (S : Subalgebra R A) :
(1 : A) ∈ S.toNonUnitalSubalgebra :=
S.one_mem
/-- Turn a non-unital subalgebra containing `1` into a subalgebra. -/
def NonUnitalSubalgebra.toSubalgebra (S : NonUnitalSubalgebra R A) (h1 : (1 : A) ∈ S) :
Subalgebra R A :=
{ S with
one_mem' := h1
algebraMap_mem' := fun r =>
(Algebra.algebraMap_eq_smul_one (R := R) (A := A) r).symm ▸ SMulMemClass.smul_mem r h1 }
theorem Subalgebra.toNonUnitalSubalgebra_toSubalgebra (S : Subalgebra R A) :
S.toNonUnitalSubalgebra.toSubalgebra S.one_mem = S := by cases S; rfl
theorem NonUnitalSubalgebra.toSubalgebra_toNonUnitalSubalgebra (S : NonUnitalSubalgebra R A)
(h1 : (1 : A) ∈ S) : (NonUnitalSubalgebra.toSubalgebra S h1).toNonUnitalSubalgebra = S := by
cases S; rfl
open Submodule in
lemma Algebra.adjoin_nonUnitalSubalgebra_eq_span (s : NonUnitalSubalgebra R A) :
Subalgebra.toSubmodule (adjoin R (s : Set A)) = span R {1} ⊔ s.toSubmodule := by
rw [adjoin_eq_span, Submonoid.closure_eq_one_union, span_union, ← NonUnitalAlgebra.adjoin_eq_span,
NonUnitalAlgebra.adjoin_eq]
variable (R)
lemma NonUnitalAlgebra.adjoin_le_algebra_adjoin (s : Set A) :
adjoin R s ≤ (Algebra.adjoin R s).toNonUnitalSubalgebra :=
adjoin_le Algebra.subset_adjoin
lemma Algebra.adjoin_nonUnitalSubalgebra (s : Set A) :
adjoin R (NonUnitalAlgebra.adjoin R s : Set A) = adjoin R s :=
le_antisymm
(adjoin_le <| NonUnitalAlgebra.adjoin_le_algebra_adjoin R s)
(adjoin_le <| (NonUnitalAlgebra.subset_adjoin R).trans subset_adjoin)
end Subalgebra
namespace Unitization
variable {R A C : Type*} [CommSemiring R] [NonUnitalSemiring A]
variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [Semiring C] [Algebra R C]
theorem lift_range_le {f : A →ₙₐ[R] C} {S : Subalgebra R C} :
(lift f).range ≤ S ↔ NonUnitalAlgHom.range f ≤ S.toNonUnitalSubalgebra := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rintro - ⟨x, rfl⟩
exact @h (f x) ⟨x, by simp⟩
· rintro - ⟨x, rfl⟩
induction x with
| _ r a => simpa using add_mem (algebraMap_mem S r) (h ⟨a, rfl⟩)
theorem lift_range (f : A →ₙₐ[R] C) :
(lift f).range = Algebra.adjoin R (NonUnitalAlgHom.range f : Set C) :=
eq_of_forall_ge_iff fun c ↦ by rw [lift_range_le, Algebra.adjoin_le_iff]; rfl
end Unitization
namespace NonUnitalSubalgebra
section Semiring
variable {R S A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [SetLike S A]
[hSA : NonUnitalSubsemiringClass S A] [hSRA : SMulMemClass S R A] (s : S)
/-- The natural `R`-algebra homomorphism from the unitization of a non-unital subalgebra into
the algebra containing it. -/
def unitization : Unitization R s →ₐ[R] A :=
Unitization.lift (NonUnitalSubalgebraClass.subtype s)
@[simp]
theorem unitization_apply (x : Unitization R s) :
unitization s x = algebraMap R A x.fst + x.snd :=
rfl
theorem unitization_range : (unitization s).range = Algebra.adjoin R (s : Set A) := by
rw [unitization, Unitization.lift_range]
simp only [NonUnitalAlgHom.coe_range, NonUnitalSubalgebraClass.coeSubtype,
Subtype.range_coe_subtype, SetLike.mem_coe]
rfl
end Semiring
/-- A sufficient condition for injectivity of `NonUnitalSubalgebra.unitization` when the scalars
are a commutative ring. When the scalars are a field, one should use the more natural
`NonUnitalStarSubalgebra.unitization_injective` whose hypothesis is easier to verify. -/
theorem _root_.AlgHomClass.unitization_injective' {F R S A : Type*} [CommRing R] [Ring A]
[Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A]
(s : S) (h : ∀ r, r ≠ 0 → algebraMap R A r ∉ s)
[FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A]
(f : F) (hf : ∀ x : s, f x = x) : Function.Injective f := by
refine (injective_iff_map_eq_zero f).mpr fun x hx => ?_
induction' x with r a
simp_rw [map_add, hf, ← Unitization.algebraMap_eq_inl, AlgHomClass.commutes] at hx
rw [add_eq_zero_iff_eq_neg] at hx ⊢
by_cases hr : r = 0
· ext <;> simp [hr] at hx ⊢
exact hx
· exact (h r hr <| hx ▸ (neg_mem a.property)).elim
/-- This is a generic version which allows us to prove both
`NonUnitalSubalgebra.unitization_injective` and `NonUnitalStarSubalgebra.unitization_injective`. -/
theorem _root_.AlgHomClass.unitization_injective {F R S A : Type*} [Field R] [Ring A]
[Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A]
(s : S) (h1 : 1 ∉ s) [FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A]
(f : F) (hf : ∀ x : s, f x = x) : Function.Injective f := by
refine AlgHomClass.unitization_injective' s (fun r hr hr' ↦ ?_) f hf
rw [Algebra.algebraMap_eq_smul_one] at hr'
exact h1 <| inv_smul_smul₀ hr (1 : A) ▸ SMulMemClass.smul_mem r⁻¹ hr'
section Field
variable {R S A : Type*} [Field R] [Ring A] [Algebra R A]
[SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S)
theorem unitization_injective (h1 : (1 : A) ∉ s) : Function.Injective (unitization s) :=
AlgHomClass.unitization_injective s h1 (unitization s) fun _ ↦ by simp
/-- If a `NonUnitalSubalgebra` over a field does not contain `1`, then its unitization is
isomorphic to its `Algebra.adjoin`. -/
@[simps! apply_coe]
noncomputable def unitizationAlgEquiv (h1 : (1 : A) ∉ s) :
Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A) :=
let algHom : Unitization R s →ₐ[R] Algebra.adjoin R (s : Set A) :=
((unitization s).codRestrict _
fun x ↦ (unitization_range s).le <| AlgHom.mem_range_self _ x)
AlgEquiv.ofBijective algHom <| by
refine ⟨?_, fun x ↦ ?_⟩
· have := AlgHomClass.unitization_injective s h1
((Subalgebra.val _).comp algHom) fun _ ↦ by simp [algHom]
rw [AlgHom.coe_comp] at this
exact this.of_comp
· obtain (⟨a, ha⟩ : (x : A) ∈ (unitization s).range) :=
(unitization_range s).ge x.property
exact ⟨a, Subtype.ext ha⟩
end Field
end NonUnitalSubalgebra
/-! ## Subsemirings -/
section Subsemiring
variable {R : Type*} [NonAssocSemiring R]
/-- Turn a `Subsemiring` into a `NonUnitalSubsemiring` by forgetting that it contains `1`. -/
def Subsemiring.toNonUnitalSubsemiring (S : Subsemiring R) : NonUnitalSubsemiring R :=
{ S with }
theorem Subsemiring.one_mem_toNonUnitalSubsemiring (S : Subsemiring R) :
(1 : R) ∈ S.toNonUnitalSubsemiring :=
S.one_mem
/-- Turn a non-unital subsemiring containing `1` into a subsemiring. -/
def NonUnitalSubsemiring.toSubsemiring (S : NonUnitalSubsemiring R) (h1 : (1 : R) ∈ S) :
Subsemiring R :=
{ S with
one_mem' := h1 }
theorem Subsemiring.toNonUnitalSubsemiring_toSubsemiring (S : Subsemiring R) :
S.toNonUnitalSubsemiring.toSubsemiring S.one_mem = S := by cases S; rfl
theorem NonUnitalSubsemiring.toSubsemiring_toNonUnitalSubsemiring (S : NonUnitalSubsemiring R)
(h1 : (1 : R) ∈ S) : (NonUnitalSubsemiring.toSubsemiring S h1).toNonUnitalSubsemiring = S := by
cases S; rfl
end Subsemiring
namespace NonUnitalSubsemiring
variable {R S : Type*} [Semiring R] [SetLike S R] [hSR : NonUnitalSubsemiringClass S R] (s : S)
/-- The natural `ℕ`-algebra homomorphism from the unitization of a non-unital subsemiring to
its `Subsemiring.closure`. -/
def unitization : Unitization ℕ s →ₐ[ℕ] R :=
NonUnitalSubalgebra.unitization (hSRA := AddSubmonoidClass.nsmulMemClass) s
@[simp]
theorem unitization_apply (x : Unitization ℕ s) : unitization s x = x.fst + x.snd :=
rfl
theorem unitization_range :
(unitization s).range = subalgebraOfSubsemiring (Subsemiring.closure s) := by
have := AddSubmonoidClass.nsmulMemClass (S := S)
rw [unitization, NonUnitalSubalgebra.unitization_range (hSRA := this), Algebra.adjoin_nat]
end NonUnitalSubsemiring
/-! ## Subrings -/
section Subring
-- TODO: Maybe we could use `NonAssocRing` here but right now `Subring` takes a `Ring` argument.
variable {R : Type*} [Ring R]
/-- Turn a `Subring` into a `NonUnitalSubring` by forgetting that it contains `1`. -/
def Subring.toNonUnitalSubring (S : Subring R) : NonUnitalSubring R :=
{ S with }
theorem Subring.one_mem_toNonUnitalSubring (S : Subring R) : (1 : R) ∈ S.toNonUnitalSubring :=
S.one_mem
/-- Turn a non-unital subring containing `1` into a subring. -/
def NonUnitalSubring.toSubring (S : NonUnitalSubring R) (h1 : (1 : R) ∈ S) : Subring R :=
{ S with
one_mem' := h1 }
theorem Subring.toNonUnitalSubring_toSubring (S : Subring R) :
S.toNonUnitalSubring.toSubring S.one_mem = S := by cases S; rfl
theorem NonUnitalSubring.toSubring_toNonUnitalSubring (S : NonUnitalSubring R) (h1 : (1 : R) ∈ S) :
(NonUnitalSubring.toSubring S h1).toNonUnitalSubring = S := by cases S; rfl
end Subring
namespace NonUnitalSubring
variable {R S : Type*} [Ring R] [SetLike S R] [hSR : NonUnitalSubringClass S R] (s : S)
/-- The natural `ℤ`-algebra homomorphism from the unitization of a non-unital subring to
its `Subring.closure`. -/
def unitization : Unitization ℤ s →ₐ[ℤ] R :=
NonUnitalSubalgebra.unitization (hSRA := AddSubgroupClass.zsmulMemClass) s
@[simp]
theorem unitization_apply (x : Unitization ℤ s) : unitization s x = x.fst + x.snd :=
rfl
theorem unitization_range :
(unitization s).range = subalgebraOfSubring (Subring.closure s) := by
have := AddSubgroupClass.zsmulMemClass (S := S)
rw [unitization, NonUnitalSubalgebra.unitization_range (hSRA := this), Algebra.adjoin_int]
end NonUnitalSubring
/-! ## Star subalgebras -/
section StarSubalgebra
variable {R A : Type*} [CommSemiring R] [StarRing R] [Semiring A] [StarRing A]
variable [Algebra R A] [StarModule R A]
/-- Turn a `StarSubalgebra` into a `NonUnitalStarSubalgebra` by forgetting that it contains `1`. -/
def StarSubalgebra.toNonUnitalStarSubalgebra (S : StarSubalgebra R A) :
NonUnitalStarSubalgebra R A :=
{ S with
carrier := S.carrier
smul_mem' := fun r _x hx => S.smul_mem hx r }
theorem StarSubalgebra.one_mem_toNonUnitalStarSubalgebra (S : StarSubalgebra R A) :
(1 : A) ∈ S.toNonUnitalStarSubalgebra :=
S.one_mem'
/-- Turn a non-unital star subalgebra containing `1` into a `StarSubalgebra`. -/
def NonUnitalStarSubalgebra.toStarSubalgebra (S : NonUnitalStarSubalgebra R A) (h1 : (1 : A) ∈ S) :
StarSubalgebra R A :=
{ S with
carrier := S.carrier
one_mem' := h1
algebraMap_mem' := fun r =>
(Algebra.algebraMap_eq_smul_one (R := R) (A := A) r).symm ▸ SMulMemClass.smul_mem r h1 }
theorem StarSubalgebra.toNonUnitalStarSubalgebra_toStarSubalgebra (S : StarSubalgebra R A) :
S.toNonUnitalStarSubalgebra.toStarSubalgebra S.one_mem' = S := by cases S; rfl
| Mathlib/Algebra/Algebra/Subalgebra/Unitization.lean | 325 | 328 | theorem NonUnitalStarSubalgebra.toStarSubalgebra_toNonUnitalStarSubalgebra
(S : NonUnitalStarSubalgebra R A) (h1 : (1 : A) ∈ S) :
(S.toStarSubalgebra h1).toNonUnitalStarSubalgebra = S := by |
cases S; rfl
|
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.Analysis.Convex.Jensen
import Mathlib.Analysis.Convex.Mul
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal
#align_import analysis.mean_inequalities_pow from "leanprover-community/mathlib"@"ccdbfb6e5614667af5aa3ab2d50885e0ef44a46f"
/-!
# Mean value inequalities
In this file we prove several mean inequalities for finite sums. Versions for integrals of some of
these inequalities are available in `MeasureTheory.MeanInequalities`.
## Main theorems: generalized mean inequality
The inequality says that for two non-negative vectors $w$ and $z$ with $\sum_{i\in s} w_i=1$
and $p ≤ q$ we have
$$
\sqrt[p]{\sum_{i\in s} w_i z_i^p} ≤ \sqrt[q]{\sum_{i\in s} w_i z_i^q}.
$$
Currently we only prove this inequality for $p=1$. As in the rest of `Mathlib`, we provide
different theorems for natural exponents (`pow_arith_mean_le_arith_mean_pow`), integer exponents
(`zpow_arith_mean_le_arith_mean_zpow`), and real exponents (`rpow_arith_mean_le_arith_mean_rpow` and
`arith_mean_le_rpow_mean`). In the first two cases we prove
$$
\left(\sum_{i\in s} w_i z_i\right)^n ≤ \sum_{i\in s} w_i z_i^n
$$
in order to avoid using real exponents. For real exponents we prove both this and standard versions.
## TODO
- each inequality `A ≤ B` should come with a theorem `A = B ↔ _`; one of the ways to prove them
is to define `StrictConvexOn` functions.
- generalized mean inequality with any `p ≤ q`, including negative numbers;
- prove that the power mean tends to the geometric mean as the exponent tends to zero.
-/
universe u v
open Finset
open scoped Classical
open NNReal ENNReal
noncomputable section
variable {ι : Type u} (s : Finset ι)
namespace Real
theorem pow_arith_mean_le_arith_mean_pow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (n : ℕ) :
(∑ i ∈ s, w i * z i) ^ n ≤ ∑ i ∈ s, w i * z i ^ n :=
(convexOn_pow n).map_sum_le hw hw' hz
#align real.pow_arith_mean_le_arith_mean_pow Real.pow_arith_mean_le_arith_mean_pow
theorem pow_arith_mean_le_arith_mean_pow_of_even (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) {n : ℕ} (hn : Even n) :
(∑ i ∈ s, w i * z i) ^ n ≤ ∑ i ∈ s, w i * z i ^ n :=
hn.convexOn_pow.map_sum_le hw hw' fun _ _ => Set.mem_univ _
#align real.pow_arith_mean_le_arith_mean_pow_of_even Real.pow_arith_mean_le_arith_mean_pow_of_even
/-- Specific case of Jensen's inequality for sums of powers -/
theorem pow_sum_div_card_le_sum_pow {f : ι → ℝ} (n : ℕ) (hf : ∀ a ∈ s, 0 ≤ f a) :
(∑ x ∈ s, f x) ^ (n + 1) / (s.card : ℝ) ^ n ≤ ∑ x ∈ s, f x ^ (n + 1) := by
rcases s.eq_empty_or_nonempty with (rfl | hs)
· simp_rw [Finset.sum_empty, zero_pow n.succ_ne_zero, zero_div]; rfl
· have hs0 : 0 < (s.card : ℝ) := Nat.cast_pos.2 hs.card_pos
suffices (∑ x ∈ s, f x / s.card) ^ (n + 1) ≤ ∑ x ∈ s, f x ^ (n + 1) / s.card by
rwa [← Finset.sum_div, ← Finset.sum_div, div_pow, pow_succ (s.card : ℝ), ← div_div,
div_le_iff hs0, div_mul, div_self hs0.ne', div_one] at this
have :=
@ConvexOn.map_sum_le ℝ ℝ ℝ ι _ _ _ _ _ _ (Set.Ici 0) (fun x => x ^ (n + 1)) s
(fun _ => 1 / s.card) ((↑) ∘ f) (convexOn_pow (n + 1)) ?_ ?_ fun i hi =>
Set.mem_Ici.2 (hf i hi)
· simpa only [inv_mul_eq_div, one_div, Algebra.id.smul_eq_mul] using this
· simp only [one_div, inv_nonneg, Nat.cast_nonneg, imp_true_iff]
· simpa only [one_div, Finset.sum_const, nsmul_eq_mul] using mul_inv_cancel hs0.ne'
#align real.pow_sum_div_card_le_sum_pow Real.pow_sum_div_card_le_sum_pow
theorem zpow_arith_mean_le_arith_mean_zpow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 < z i) (m : ℤ) :
(∑ i ∈ s, w i * z i) ^ m ≤ ∑ i ∈ s, w i * z i ^ m :=
(convexOn_zpow m).map_sum_le hw hw' hz
#align real.zpow_arith_mean_le_arith_mean_zpow Real.zpow_arith_mean_le_arith_mean_zpow
theorem rpow_arith_mean_le_arith_mean_rpow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) {p : ℝ} (hp : 1 ≤ p) :
(∑ i ∈ s, w i * z i) ^ p ≤ ∑ i ∈ s, w i * z i ^ p :=
(convexOn_rpow hp).map_sum_le hw hw' hz
#align real.rpow_arith_mean_le_arith_mean_rpow Real.rpow_arith_mean_le_arith_mean_rpow
theorem arith_mean_le_rpow_mean (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i ∈ s, w i = 1)
(hz : ∀ i ∈ s, 0 ≤ z i) {p : ℝ} (hp : 1 ≤ p) :
∑ i ∈ s, w i * z i ≤ (∑ i ∈ s, w i * z i ^ p) ^ (1 / p) := by
have : 0 < p := by positivity
rw [← rpow_le_rpow_iff _ _ this, ← rpow_mul, one_div_mul_cancel (ne_of_gt this), rpow_one]
· exact rpow_arith_mean_le_arith_mean_rpow s w z hw hw' hz hp
all_goals
apply_rules [sum_nonneg, rpow_nonneg]
intro i hi
apply_rules [mul_nonneg, rpow_nonneg, hw i hi, hz i hi]
#align real.arith_mean_le_rpow_mean Real.arith_mean_le_rpow_mean
end Real
namespace NNReal
/-- Weighted generalized mean inequality, version sums over finite sets, with `ℝ≥0`-valued
functions and natural exponent. -/
theorem pow_arith_mean_le_arith_mean_pow (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) (n : ℕ) :
(∑ i ∈ s, w i * z i) ^ n ≤ ∑ i ∈ s, w i * z i ^ n :=
mod_cast
Real.pow_arith_mean_le_arith_mean_pow s _ _ (fun i _ => (w i).coe_nonneg)
(mod_cast hw') (fun i _ => (z i).coe_nonneg) n
#align nnreal.pow_arith_mean_le_arith_mean_pow NNReal.pow_arith_mean_le_arith_mean_pow
theorem pow_sum_div_card_le_sum_pow (f : ι → ℝ≥0) (n : ℕ) :
(∑ x ∈ s, f x) ^ (n + 1) / (s.card : ℝ) ^ n ≤ ∑ x ∈ s, f x ^ (n + 1) := by
simpa only [← NNReal.coe_le_coe, NNReal.coe_sum, Nonneg.coe_div, NNReal.coe_pow] using
@Real.pow_sum_div_card_le_sum_pow ι s (((↑) : ℝ≥0 → ℝ) ∘ f) n fun _ _ => NNReal.coe_nonneg _
#align nnreal.pow_sum_div_card_le_sum_pow NNReal.pow_sum_div_card_le_sum_pow
/-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝ≥0`-valued
functions and real exponents. -/
theorem rpow_arith_mean_le_arith_mean_rpow (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) {p : ℝ}
(hp : 1 ≤ p) : (∑ i ∈ s, w i * z i) ^ p ≤ ∑ i ∈ s, w i * z i ^ p :=
mod_cast
Real.rpow_arith_mean_le_arith_mean_rpow s _ _ (fun i _ => (w i).coe_nonneg)
(mod_cast hw') (fun i _ => (z i).coe_nonneg) hp
#align nnreal.rpow_arith_mean_le_arith_mean_rpow NNReal.rpow_arith_mean_le_arith_mean_rpow
/-- Weighted generalized mean inequality, version for two elements of `ℝ≥0` and real exponents. -/
theorem rpow_arith_mean_le_arith_mean2_rpow (w₁ w₂ z₁ z₂ : ℝ≥0) (hw' : w₁ + w₂ = 1) {p : ℝ}
(hp : 1 ≤ p) : (w₁ * z₁ + w₂ * z₂) ^ p ≤ w₁ * z₁ ^ p + w₂ * z₂ ^ p := by
have h := rpow_arith_mean_le_arith_mean_rpow univ ![w₁, w₂] ![z₁, z₂] ?_ hp
· simpa [Fin.sum_univ_succ] using h
· simp [hw', Fin.sum_univ_succ]
#align nnreal.rpow_arith_mean_le_arith_mean2_rpow NNReal.rpow_arith_mean_le_arith_mean2_rpow
/-- Unweighted mean inequality, version for two elements of `ℝ≥0` and real exponents. -/
theorem rpow_add_le_mul_rpow_add_rpow (z₁ z₂ : ℝ≥0) {p : ℝ} (hp : 1 ≤ p) :
(z₁ + z₂) ^ p ≤ (2 : ℝ≥0) ^ (p - 1) * (z₁ ^ p + z₂ ^ p) := by
rcases eq_or_lt_of_le hp with (rfl | h'p)
· simp only [rpow_one, sub_self, rpow_zero, one_mul]; rfl
convert rpow_arith_mean_le_arith_mean2_rpow (1 / 2) (1 / 2) (2 * z₁) (2 * z₂) (add_halves 1) hp
using 1
· simp only [one_div, inv_mul_cancel_left₀, Ne, mul_eq_zero, two_ne_zero, one_ne_zero,
not_false_iff]
· have A : p - 1 ≠ 0 := ne_of_gt (sub_pos.2 h'p)
simp only [mul_rpow, rpow_sub' _ A, div_eq_inv_mul, rpow_one, mul_one]
ring
#align nnreal.rpow_add_le_mul_rpow_add_rpow NNReal.rpow_add_le_mul_rpow_add_rpow
/-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝ≥0`-valued
functions and real exponents. -/
theorem arith_mean_le_rpow_mean (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) {p : ℝ} (hp : 1 ≤ p) :
∑ i ∈ s, w i * z i ≤ (∑ i ∈ s, w i * z i ^ p) ^ (1 / p) :=
mod_cast
Real.arith_mean_le_rpow_mean s _ _ (fun i _ => (w i).coe_nonneg) (mod_cast hw')
(fun i _ => (z i).coe_nonneg) hp
#align nnreal.arith_mean_le_rpow_mean NNReal.arith_mean_le_rpow_mean
private theorem add_rpow_le_one_of_add_le_one {p : ℝ} (a b : ℝ≥0) (hab : a + b ≤ 1) (hp1 : 1 ≤ p) :
a ^ p + b ^ p ≤ 1 := by
have h_le_one : ∀ x : ℝ≥0, x ≤ 1 → x ^ p ≤ x := fun x hx => rpow_le_self_of_le_one hx hp1
have ha : a ≤ 1 := (self_le_add_right a b).trans hab
have hb : b ≤ 1 := (self_le_add_left b a).trans hab
exact (add_le_add (h_le_one a ha) (h_le_one b hb)).trans hab
theorem add_rpow_le_rpow_add {p : ℝ} (a b : ℝ≥0) (hp1 : 1 ≤ p) : a ^ p + b ^ p ≤ (a + b) ^ p := by
have hp_pos : 0 < p := by positivity
by_cases h_zero : a + b = 0
· simp [add_eq_zero_iff.mp h_zero, hp_pos.ne']
have h_nonzero : ¬(a = 0 ∧ b = 0) := by rwa [add_eq_zero_iff] at h_zero
have h_add : a / (a + b) + b / (a + b) = 1 := by rw [div_add_div_same, div_self h_zero]
have h := add_rpow_le_one_of_add_le_one (a / (a + b)) (b / (a + b)) h_add.le hp1
rw [div_rpow a (a + b), div_rpow b (a + b)] at h
have hab_0 : (a + b) ^ p ≠ 0 := by simp [hp_pos, h_nonzero]
have hab_0' : 0 < (a + b) ^ p := zero_lt_iff.mpr hab_0
have h_mul : (a + b) ^ p * (a ^ p / (a + b) ^ p + b ^ p / (a + b) ^ p) ≤ (a + b) ^ p := by
nth_rw 4 [← mul_one ((a + b) ^ p)]
exact (mul_le_mul_left hab_0').mpr h
rwa [div_eq_mul_inv, div_eq_mul_inv, mul_add, mul_comm (a ^ p), mul_comm (b ^ p), ← mul_assoc, ←
mul_assoc, mul_inv_cancel hab_0, one_mul, one_mul] at h_mul
#align nnreal.add_rpow_le_rpow_add NNReal.add_rpow_le_rpow_add
theorem rpow_add_rpow_le_add {p : ℝ} (a b : ℝ≥0) (hp1 : 1 ≤ p) :
(a ^ p + b ^ p) ^ (1 / p) ≤ a + b := by
rw [← @NNReal.le_rpow_one_div_iff _ _ (1 / p) (by simp [lt_of_lt_of_le zero_lt_one hp1])]
rw [one_div_one_div]
exact add_rpow_le_rpow_add _ _ hp1
#align nnreal.rpow_add_rpow_le_add NNReal.rpow_add_rpow_le_add
theorem rpow_add_rpow_le {p q : ℝ} (a b : ℝ≥0) (hp_pos : 0 < p) (hpq : p ≤ q) :
(a ^ q + b ^ q) ^ (1 / q) ≤ (a ^ p + b ^ p) ^ (1 / p) := by
have h_rpow : ∀ a : ℝ≥0, a ^ q = (a ^ p) ^ (q / p) := fun a => by
rw [← NNReal.rpow_mul, div_eq_inv_mul, ← mul_assoc, _root_.mul_inv_cancel hp_pos.ne.symm,
one_mul]
have h_rpow_add_rpow_le_add :
((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (1 / (q / p)) ≤ a ^ p + b ^ p := by
refine rpow_add_rpow_le_add (a ^ p) (b ^ p) ?_
rwa [one_le_div hp_pos]
rw [h_rpow a, h_rpow b, NNReal.le_rpow_one_div_iff hp_pos, ← NNReal.rpow_mul, mul_comm,
mul_one_div]
rwa [one_div_div] at h_rpow_add_rpow_le_add
#align nnreal.rpow_add_rpow_le NNReal.rpow_add_rpow_le
theorem rpow_add_le_add_rpow {p : ℝ} (a b : ℝ≥0) (hp : 0 ≤ p) (hp1 : p ≤ 1) :
(a + b) ^ p ≤ a ^ p + b ^ p := by
rcases hp.eq_or_lt with (rfl | hp_pos)
· simp
have h := rpow_add_rpow_le a b hp_pos hp1
rw [one_div_one] at h
repeat' rw [NNReal.rpow_one] at h
exact (NNReal.le_rpow_one_div_iff hp_pos).mp h
#align nnreal.rpow_add_le_add_rpow NNReal.rpow_add_le_add_rpow
end NNReal
namespace ENNReal
/-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝ≥0∞`-valued
functions and real exponents. -/
theorem rpow_arith_mean_le_arith_mean_rpow (w z : ι → ℝ≥0∞) (hw' : ∑ i ∈ s, w i = 1) {p : ℝ}
(hp : 1 ≤ p) : (∑ i ∈ s, w i * z i) ^ p ≤ ∑ i ∈ s, w i * z i ^ p := by
have hp_pos : 0 < p := by positivity
have hp_nonneg : 0 ≤ p := by positivity
have hp_not_neg : ¬p < 0 := by simp [hp_nonneg]
have h_top_iff_rpow_top : ∀ (i : ι), i ∈ s → (w i * z i = ⊤ ↔ w i * z i ^ p = ⊤) := by
simp [ENNReal.mul_eq_top, hp_pos, hp_nonneg, hp_not_neg]
refine le_of_top_imp_top_of_toNNReal_le ?_ ?_
· -- first, prove `(∑ i ∈ s, w i * z i) ^ p = ⊤ → ∑ i ∈ s, (w i * z i ^ p) = ⊤`
rw [rpow_eq_top_iff, sum_eq_top_iff, sum_eq_top_iff]
intro h
simp only [and_false_iff, hp_not_neg, false_or_iff] at h
rcases h.left with ⟨a, H, ha⟩
use a, H
rwa [← h_top_iff_rpow_top a H]
· -- second, suppose both `(∑ i ∈ s, w i * z i) ^ p ≠ ⊤` and `∑ i ∈ s, (w i * z i ^ p) ≠ ⊤`,
-- and prove `((∑ i ∈ s, w i * z i) ^ p).toNNReal ≤ (∑ i ∈ s, (w i * z i ^ p)).toNNReal`,
-- by using `NNReal.rpow_arith_mean_le_arith_mean_rpow`.
intro h_top_rpow_sum _
-- show hypotheses needed to put the `.toNNReal` inside the sums.
have h_top : ∀ a : ι, a ∈ s → w a * z a ≠ ⊤ :=
haveI h_top_sum : ∑ i ∈ s, w i * z i ≠ ⊤ := by
intro h
rw [h, top_rpow_of_pos hp_pos] at h_top_rpow_sum
exact h_top_rpow_sum rfl
fun a ha => (lt_top_of_sum_ne_top h_top_sum ha).ne
have h_top_rpow : ∀ a : ι, a ∈ s → w a * z a ^ p ≠ ⊤ := by
intro i hi
specialize h_top i hi
rwa [Ne, ← h_top_iff_rpow_top i hi]
-- put the `.toNNReal` inside the sums.
simp_rw [toNNReal_sum h_top_rpow, ← toNNReal_rpow, toNNReal_sum h_top, toNNReal_mul, ←
toNNReal_rpow]
-- use corresponding nnreal result
refine
NNReal.rpow_arith_mean_le_arith_mean_rpow s (fun i => (w i).toNNReal)
(fun i => (z i).toNNReal) ?_ hp
-- verify the hypothesis `∑ i ∈ s, (w i).toNNReal = 1`, using `∑ i ∈ s, w i = 1` .
have h_sum_nnreal : ∑ i ∈ s, w i = ↑(∑ i ∈ s, (w i).toNNReal) := by
rw [coe_finset_sum]
refine sum_congr rfl fun i hi => (coe_toNNReal ?_).symm
refine (lt_top_of_sum_ne_top ?_ hi).ne
exact hw'.symm ▸ ENNReal.one_ne_top
rwa [← coe_inj, ← h_sum_nnreal]
#align ennreal.rpow_arith_mean_le_arith_mean_rpow ENNReal.rpow_arith_mean_le_arith_mean_rpow
/-- Weighted generalized mean inequality, version for two elements of `ℝ≥0∞` and real
exponents. -/
theorem rpow_arith_mean_le_arith_mean2_rpow (w₁ w₂ z₁ z₂ : ℝ≥0∞) (hw' : w₁ + w₂ = 1) {p : ℝ}
(hp : 1 ≤ p) : (w₁ * z₁ + w₂ * z₂) ^ p ≤ w₁ * z₁ ^ p + w₂ * z₂ ^ p := by
have h := rpow_arith_mean_le_arith_mean_rpow univ ![w₁, w₂] ![z₁, z₂] ?_ hp
· simpa [Fin.sum_univ_succ] using h
· simp [hw', Fin.sum_univ_succ]
#align ennreal.rpow_arith_mean_le_arith_mean2_rpow ENNReal.rpow_arith_mean_le_arith_mean2_rpow
/-- Unweighted mean inequality, version for two elements of `ℝ≥0∞` and real exponents. -/
theorem rpow_add_le_mul_rpow_add_rpow (z₁ z₂ : ℝ≥0∞) {p : ℝ} (hp : 1 ≤ p) :
(z₁ + z₂) ^ p ≤ (2 : ℝ≥0∞) ^ (p - 1) * (z₁ ^ p + z₂ ^ p) := by
convert rpow_arith_mean_le_arith_mean2_rpow (1 / 2) (1 / 2) (2 * z₁) (2 * z₂)
(ENNReal.add_halves 1) hp using 1
· simp [← mul_assoc, ENNReal.inv_mul_cancel two_ne_zero two_ne_top]
· simp only [mul_rpow_of_nonneg _ _ (zero_le_one.trans hp), rpow_sub _ _ two_ne_zero two_ne_top,
ENNReal.div_eq_inv_mul, rpow_one, mul_one]
ring
#align ennreal.rpow_add_le_mul_rpow_add_rpow ENNReal.rpow_add_le_mul_rpow_add_rpow
theorem add_rpow_le_rpow_add {p : ℝ} (a b : ℝ≥0∞) (hp1 : 1 ≤ p) : a ^ p + b ^ p ≤ (a + b) ^ p := by
have hp_pos : 0 < p := by positivity
by_cases h_top : a + b = ⊤
· rw [← @ENNReal.rpow_eq_top_iff_of_pos (a + b) p hp_pos] at h_top
rw [h_top]
exact le_top
obtain ⟨ha_top, hb_top⟩ := add_ne_top.mp h_top
lift a to ℝ≥0 using ha_top
lift b to ℝ≥0 using hb_top
simpa [← ENNReal.coe_rpow_of_nonneg _ hp_pos.le] using
ENNReal.coe_le_coe.2 (NNReal.add_rpow_le_rpow_add a b hp1)
#align ennreal.add_rpow_le_rpow_add ENNReal.add_rpow_le_rpow_add
theorem rpow_add_rpow_le_add {p : ℝ} (a b : ℝ≥0∞) (hp1 : 1 ≤ p) :
(a ^ p + b ^ p) ^ (1 / p) ≤ a + b := by
rw [← @ENNReal.le_rpow_one_div_iff _ _ (1 / p) (by simp [lt_of_lt_of_le zero_lt_one hp1])]
rw [one_div_one_div]
exact add_rpow_le_rpow_add _ _ hp1
#align ennreal.rpow_add_rpow_le_add ENNReal.rpow_add_rpow_le_add
theorem rpow_add_rpow_le {p q : ℝ} (a b : ℝ≥0∞) (hp_pos : 0 < p) (hpq : p ≤ q) :
(a ^ q + b ^ q) ^ (1 / q) ≤ (a ^ p + b ^ p) ^ (1 / p) := by
have h_rpow : ∀ a : ℝ≥0∞, a ^ q = (a ^ p) ^ (q / p) := fun a => by
rw [← ENNReal.rpow_mul, mul_div_cancel₀ _ hp_pos.ne']
have h_rpow_add_rpow_le_add :
((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (1 / (q / p)) ≤ a ^ p + b ^ p := by
refine rpow_add_rpow_le_add (a ^ p) (b ^ p) ?_
rwa [one_le_div hp_pos]
rw [h_rpow a, h_rpow b, ENNReal.le_rpow_one_div_iff hp_pos, ← ENNReal.rpow_mul, mul_comm,
mul_one_div]
rwa [one_div_div] at h_rpow_add_rpow_le_add
#align ennreal.rpow_add_rpow_le ENNReal.rpow_add_rpow_le
| Mathlib/Analysis/MeanInequalitiesPow.lean | 332 | 339 | theorem rpow_add_le_add_rpow {p : ℝ} (a b : ℝ≥0∞) (hp : 0 ≤ p) (hp1 : p ≤ 1) :
(a + b) ^ p ≤ a ^ p + b ^ p := by |
rcases hp.eq_or_lt with (rfl | hp_pos)
· simp
have h := rpow_add_rpow_le a b hp_pos hp1
rw [one_div_one] at h
repeat' rw [ENNReal.rpow_one] at h
exact (ENNReal.le_rpow_one_div_iff hp_pos).mp h
|
/-
Copyright (c) 2022 Yaël Dillies, Sara Rousta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Sara Rousta
-/
import Mathlib.Data.SetLike.Basic
import Mathlib.Order.Interval.Set.OrdConnected
import Mathlib.Order.Interval.Set.OrderIso
import Mathlib.Data.Set.Lattice
#align_import order.upper_lower.basic from "leanprover-community/mathlib"@"c0c52abb75074ed8b73a948341f50521fbf43b4c"
/-!
# Up-sets and down-sets
This file defines upper and lower sets in an order.
## Main declarations
* `IsUpperSet`: Predicate for a set to be an upper set. This means every element greater than a
member of the set is in the set itself.
* `IsLowerSet`: Predicate for a set to be a lower set. This means every element less than a member
of the set is in the set itself.
* `UpperSet`: The type of upper sets.
* `LowerSet`: The type of lower sets.
* `upperClosure`: The greatest upper set containing a set.
* `lowerClosure`: The least lower set containing a set.
* `UpperSet.Ici`: Principal upper set. `Set.Ici` as an upper set.
* `UpperSet.Ioi`: Strict principal upper set. `Set.Ioi` as an upper set.
* `LowerSet.Iic`: Principal lower set. `Set.Iic` as a lower set.
* `LowerSet.Iio`: Strict principal lower set. `Set.Iio` as a lower set.
## Notation
* `×ˢ` is notation for `UpperSet.prod` / `LowerSet.prod`.
## Notes
Upper sets are ordered by **reverse** inclusion. This convention is motivated by the fact that this
makes them order-isomorphic to lower sets and antichains, and matches the convention on `Filter`.
## TODO
Lattice structure on antichains. Order equivalence between upper/lower sets and antichains.
-/
open Function OrderDual Set
variable {α β γ : Type*} {ι : Sort*} {κ : ι → Sort*}
/-! ### Unbundled upper/lower sets -/
section LE
variable [LE α] [LE β] {s t : Set α} {a : α}
/-- An upper set in an order `α` is a set such that any element greater than one of its members is
also a member. Also called up-set, upward-closed set. -/
@[aesop norm unfold]
def IsUpperSet (s : Set α) : Prop :=
∀ ⦃a b : α⦄, a ≤ b → a ∈ s → b ∈ s
#align is_upper_set IsUpperSet
/-- A lower set in an order `α` is a set such that any element less than one of its members is also
a member. Also called down-set, downward-closed set. -/
@[aesop norm unfold]
def IsLowerSet (s : Set α) : Prop :=
∀ ⦃a b : α⦄, b ≤ a → a ∈ s → b ∈ s
#align is_lower_set IsLowerSet
theorem isUpperSet_empty : IsUpperSet (∅ : Set α) := fun _ _ _ => id
#align is_upper_set_empty isUpperSet_empty
theorem isLowerSet_empty : IsLowerSet (∅ : Set α) := fun _ _ _ => id
#align is_lower_set_empty isLowerSet_empty
theorem isUpperSet_univ : IsUpperSet (univ : Set α) := fun _ _ _ => id
#align is_upper_set_univ isUpperSet_univ
theorem isLowerSet_univ : IsLowerSet (univ : Set α) := fun _ _ _ => id
#align is_lower_set_univ isLowerSet_univ
theorem IsUpperSet.compl (hs : IsUpperSet s) : IsLowerSet sᶜ := fun _a _b h hb ha => hb <| hs h ha
#align is_upper_set.compl IsUpperSet.compl
theorem IsLowerSet.compl (hs : IsLowerSet s) : IsUpperSet sᶜ := fun _a _b h hb ha => hb <| hs h ha
#align is_lower_set.compl IsLowerSet.compl
@[simp]
theorem isUpperSet_compl : IsUpperSet sᶜ ↔ IsLowerSet s :=
⟨fun h => by
convert h.compl
rw [compl_compl], IsLowerSet.compl⟩
#align is_upper_set_compl isUpperSet_compl
@[simp]
theorem isLowerSet_compl : IsLowerSet sᶜ ↔ IsUpperSet s :=
⟨fun h => by
convert h.compl
rw [compl_compl], IsUpperSet.compl⟩
#align is_lower_set_compl isLowerSet_compl
theorem IsUpperSet.union (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∪ t) :=
fun _ _ h => Or.imp (hs h) (ht h)
#align is_upper_set.union IsUpperSet.union
theorem IsLowerSet.union (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∪ t) :=
fun _ _ h => Or.imp (hs h) (ht h)
#align is_lower_set.union IsLowerSet.union
theorem IsUpperSet.inter (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∩ t) :=
fun _ _ h => And.imp (hs h) (ht h)
#align is_upper_set.inter IsUpperSet.inter
theorem IsLowerSet.inter (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∩ t) :=
fun _ _ h => And.imp (hs h) (ht h)
#align is_lower_set.inter IsLowerSet.inter
theorem isUpperSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋃₀ S) :=
fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩
#align is_upper_set_sUnion isUpperSet_sUnion
theorem isLowerSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋃₀ S) :=
fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩
#align is_lower_set_sUnion isLowerSet_sUnion
theorem isUpperSet_iUnion {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋃ i, f i) :=
isUpperSet_sUnion <| forall_mem_range.2 hf
#align is_upper_set_Union isUpperSet_iUnion
theorem isLowerSet_iUnion {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋃ i, f i) :=
isLowerSet_sUnion <| forall_mem_range.2 hf
#align is_lower_set_Union isLowerSet_iUnion
theorem isUpperSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) :
IsUpperSet (⋃ (i) (j), f i j) :=
isUpperSet_iUnion fun i => isUpperSet_iUnion <| hf i
#align is_upper_set_Union₂ isUpperSet_iUnion₂
theorem isLowerSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) :
IsLowerSet (⋃ (i) (j), f i j) :=
isLowerSet_iUnion fun i => isLowerSet_iUnion <| hf i
#align is_lower_set_Union₂ isLowerSet_iUnion₂
theorem isUpperSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋂₀ S) :=
fun _ _ h => forall₂_imp fun s hs => hf s hs h
#align is_upper_set_sInter isUpperSet_sInter
theorem isLowerSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋂₀ S) :=
fun _ _ h => forall₂_imp fun s hs => hf s hs h
#align is_lower_set_sInter isLowerSet_sInter
theorem isUpperSet_iInter {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋂ i, f i) :=
isUpperSet_sInter <| forall_mem_range.2 hf
#align is_upper_set_Inter isUpperSet_iInter
theorem isLowerSet_iInter {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋂ i, f i) :=
isLowerSet_sInter <| forall_mem_range.2 hf
#align is_lower_set_Inter isLowerSet_iInter
theorem isUpperSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) :
IsUpperSet (⋂ (i) (j), f i j) :=
isUpperSet_iInter fun i => isUpperSet_iInter <| hf i
#align is_upper_set_Inter₂ isUpperSet_iInter₂
theorem isLowerSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) :
IsLowerSet (⋂ (i) (j), f i j) :=
isLowerSet_iInter fun i => isLowerSet_iInter <| hf i
#align is_lower_set_Inter₂ isLowerSet_iInter₂
@[simp]
theorem isLowerSet_preimage_ofDual_iff : IsLowerSet (ofDual ⁻¹' s) ↔ IsUpperSet s :=
Iff.rfl
#align is_lower_set_preimage_of_dual_iff isLowerSet_preimage_ofDual_iff
@[simp]
theorem isUpperSet_preimage_ofDual_iff : IsUpperSet (ofDual ⁻¹' s) ↔ IsLowerSet s :=
Iff.rfl
#align is_upper_set_preimage_of_dual_iff isUpperSet_preimage_ofDual_iff
@[simp]
theorem isLowerSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsLowerSet (toDual ⁻¹' s) ↔ IsUpperSet s :=
Iff.rfl
#align is_lower_set_preimage_to_dual_iff isLowerSet_preimage_toDual_iff
@[simp]
theorem isUpperSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsUpperSet (toDual ⁻¹' s) ↔ IsLowerSet s :=
Iff.rfl
#align is_upper_set_preimage_to_dual_iff isUpperSet_preimage_toDual_iff
alias ⟨_, IsUpperSet.toDual⟩ := isLowerSet_preimage_ofDual_iff
#align is_upper_set.to_dual IsUpperSet.toDual
alias ⟨_, IsLowerSet.toDual⟩ := isUpperSet_preimage_ofDual_iff
#align is_lower_set.to_dual IsLowerSet.toDual
alias ⟨_, IsUpperSet.ofDual⟩ := isLowerSet_preimage_toDual_iff
#align is_upper_set.of_dual IsUpperSet.ofDual
alias ⟨_, IsLowerSet.ofDual⟩ := isUpperSet_preimage_toDual_iff
#align is_lower_set.of_dual IsLowerSet.ofDual
lemma IsUpperSet.isLowerSet_preimage_coe (hs : IsUpperSet s) :
IsLowerSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t := by aesop
lemma IsLowerSet.isUpperSet_preimage_coe (hs : IsLowerSet s) :
IsUpperSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t := by aesop
lemma IsUpperSet.sdiff (hs : IsUpperSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t) :
IsUpperSet (s \ t) :=
fun _b _c hbc hb ↦ ⟨hs hbc hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hbc⟩
lemma IsLowerSet.sdiff (hs : IsLowerSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t) :
IsLowerSet (s \ t) :=
fun _b _c hcb hb ↦ ⟨hs hcb hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hcb⟩
lemma IsUpperSet.sdiff_of_isLowerSet (hs : IsUpperSet s) (ht : IsLowerSet t) : IsUpperSet (s \ t) :=
hs.sdiff <| by aesop
lemma IsLowerSet.sdiff_of_isUpperSet (hs : IsLowerSet s) (ht : IsUpperSet t) : IsLowerSet (s \ t) :=
hs.sdiff <| by aesop
lemma IsUpperSet.erase (hs : IsUpperSet s) (has : ∀ b ∈ s, b ≤ a → b = a) : IsUpperSet (s \ {a}) :=
hs.sdiff <| by simpa using has
lemma IsLowerSet.erase (hs : IsLowerSet s) (has : ∀ b ∈ s, a ≤ b → b = a) : IsLowerSet (s \ {a}) :=
hs.sdiff <| by simpa using has
end LE
section Preorder
variable [Preorder α] [Preorder β] {s : Set α} {p : α → Prop} (a : α)
theorem isUpperSet_Ici : IsUpperSet (Ici a) := fun _ _ => ge_trans
#align is_upper_set_Ici isUpperSet_Ici
theorem isLowerSet_Iic : IsLowerSet (Iic a) := fun _ _ => le_trans
#align is_lower_set_Iic isLowerSet_Iic
theorem isUpperSet_Ioi : IsUpperSet (Ioi a) := fun _ _ => flip lt_of_lt_of_le
#align is_upper_set_Ioi isUpperSet_Ioi
theorem isLowerSet_Iio : IsLowerSet (Iio a) := fun _ _ => lt_of_le_of_lt
#align is_lower_set_Iio isLowerSet_Iio
theorem isUpperSet_iff_Ici_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ici a ⊆ s := by
simp [IsUpperSet, subset_def, @forall_swap (_ ∈ s)]
#align is_upper_set_iff_Ici_subset isUpperSet_iff_Ici_subset
theorem isLowerSet_iff_Iic_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iic a ⊆ s := by
simp [IsLowerSet, subset_def, @forall_swap (_ ∈ s)]
#align is_lower_set_iff_Iic_subset isLowerSet_iff_Iic_subset
alias ⟨IsUpperSet.Ici_subset, _⟩ := isUpperSet_iff_Ici_subset
#align is_upper_set.Ici_subset IsUpperSet.Ici_subset
alias ⟨IsLowerSet.Iic_subset, _⟩ := isLowerSet_iff_Iic_subset
#align is_lower_set.Iic_subset IsLowerSet.Iic_subset
theorem IsUpperSet.Ioi_subset (h : IsUpperSet s) ⦃a⦄ (ha : a ∈ s) : Ioi a ⊆ s :=
Ioi_subset_Ici_self.trans <| h.Ici_subset ha
#align is_upper_set.Ioi_subset IsUpperSet.Ioi_subset
theorem IsLowerSet.Iio_subset (h : IsLowerSet s) ⦃a⦄ (ha : a ∈ s) : Iio a ⊆ s :=
h.toDual.Ioi_subset ha
#align is_lower_set.Iio_subset IsLowerSet.Iio_subset
theorem IsUpperSet.ordConnected (h : IsUpperSet s) : s.OrdConnected :=
⟨fun _ ha _ _ => Icc_subset_Ici_self.trans <| h.Ici_subset ha⟩
#align is_upper_set.ord_connected IsUpperSet.ordConnected
theorem IsLowerSet.ordConnected (h : IsLowerSet s) : s.OrdConnected :=
⟨fun _ _ _ hb => Icc_subset_Iic_self.trans <| h.Iic_subset hb⟩
#align is_lower_set.ord_connected IsLowerSet.ordConnected
theorem IsUpperSet.preimage (hs : IsUpperSet s) {f : β → α} (hf : Monotone f) :
IsUpperSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h
#align is_upper_set.preimage IsUpperSet.preimage
theorem IsLowerSet.preimage (hs : IsLowerSet s) {f : β → α} (hf : Monotone f) :
IsLowerSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h
#align is_lower_set.preimage IsLowerSet.preimage
theorem IsUpperSet.image (hs : IsUpperSet s) (f : α ≃o β) : IsUpperSet (f '' s : Set β) := by
change IsUpperSet ((f : α ≃ β) '' s)
rw [Set.image_equiv_eq_preimage_symm]
exact hs.preimage f.symm.monotone
#align is_upper_set.image IsUpperSet.image
theorem IsLowerSet.image (hs : IsLowerSet s) (f : α ≃o β) : IsLowerSet (f '' s : Set β) := by
change IsLowerSet ((f : α ≃ β) '' s)
rw [Set.image_equiv_eq_preimage_symm]
exact hs.preimage f.symm.monotone
#align is_lower_set.image IsLowerSet.image
theorem OrderEmbedding.image_Ici (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) :
e '' Ici a = Ici (e a) := by
rw [← e.preimage_Ici, image_preimage_eq_inter_range,
inter_eq_left.2 <| he.Ici_subset (mem_range_self _)]
theorem OrderEmbedding.image_Iic (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) :
e '' Iic a = Iic (e a) :=
e.dual.image_Ici he a
theorem OrderEmbedding.image_Ioi (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) :
e '' Ioi a = Ioi (e a) := by
rw [← e.preimage_Ioi, image_preimage_eq_inter_range,
inter_eq_left.2 <| he.Ioi_subset (mem_range_self _)]
theorem OrderEmbedding.image_Iio (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) :
e '' Iio a = Iio (e a) :=
e.dual.image_Ioi he a
@[simp]
theorem Set.monotone_mem : Monotone (· ∈ s) ↔ IsUpperSet s :=
Iff.rfl
#align set.monotone_mem Set.monotone_mem
@[simp]
theorem Set.antitone_mem : Antitone (· ∈ s) ↔ IsLowerSet s :=
forall_swap
#align set.antitone_mem Set.antitone_mem
@[simp]
theorem isUpperSet_setOf : IsUpperSet { a | p a } ↔ Monotone p :=
Iff.rfl
#align is_upper_set_set_of isUpperSet_setOf
@[simp]
theorem isLowerSet_setOf : IsLowerSet { a | p a } ↔ Antitone p :=
forall_swap
#align is_lower_set_set_of isLowerSet_setOf
lemma IsUpperSet.upperBounds_subset (hs : IsUpperSet s) : s.Nonempty → upperBounds s ⊆ s :=
fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha
lemma IsLowerSet.lowerBounds_subset (hs : IsLowerSet s) : s.Nonempty → lowerBounds s ⊆ s :=
fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha
section OrderTop
variable [OrderTop α]
theorem IsLowerSet.top_mem (hs : IsLowerSet s) : ⊤ ∈ s ↔ s = univ :=
⟨fun h => eq_univ_of_forall fun _ => hs le_top h, fun h => h.symm ▸ mem_univ _⟩
#align is_lower_set.top_mem IsLowerSet.top_mem
theorem IsUpperSet.top_mem (hs : IsUpperSet s) : ⊤ ∈ s ↔ s.Nonempty :=
⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs le_top ha⟩
#align is_upper_set.top_mem IsUpperSet.top_mem
theorem IsUpperSet.not_top_mem (hs : IsUpperSet s) : ⊤ ∉ s ↔ s = ∅ :=
hs.top_mem.not.trans not_nonempty_iff_eq_empty
#align is_upper_set.not_top_mem IsUpperSet.not_top_mem
end OrderTop
section OrderBot
variable [OrderBot α]
theorem IsUpperSet.bot_mem (hs : IsUpperSet s) : ⊥ ∈ s ↔ s = univ :=
⟨fun h => eq_univ_of_forall fun _ => hs bot_le h, fun h => h.symm ▸ mem_univ _⟩
#align is_upper_set.bot_mem IsUpperSet.bot_mem
theorem IsLowerSet.bot_mem (hs : IsLowerSet s) : ⊥ ∈ s ↔ s.Nonempty :=
⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs bot_le ha⟩
#align is_lower_set.bot_mem IsLowerSet.bot_mem
theorem IsLowerSet.not_bot_mem (hs : IsLowerSet s) : ⊥ ∉ s ↔ s = ∅ :=
hs.bot_mem.not.trans not_nonempty_iff_eq_empty
#align is_lower_set.not_bot_mem IsLowerSet.not_bot_mem
end OrderBot
section NoMaxOrder
variable [NoMaxOrder α]
theorem IsUpperSet.not_bddAbove (hs : IsUpperSet s) : s.Nonempty → ¬BddAbove s := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
obtain ⟨c, hc⟩ := exists_gt b
exact hc.not_le (hb <| hs ((hb ha).trans hc.le) ha)
#align is_upper_set.not_bdd_above IsUpperSet.not_bddAbove
theorem not_bddAbove_Ici : ¬BddAbove (Ici a) :=
(isUpperSet_Ici _).not_bddAbove nonempty_Ici
#align not_bdd_above_Ici not_bddAbove_Ici
theorem not_bddAbove_Ioi : ¬BddAbove (Ioi a) :=
(isUpperSet_Ioi _).not_bddAbove nonempty_Ioi
#align not_bdd_above_Ioi not_bddAbove_Ioi
end NoMaxOrder
section NoMinOrder
variable [NoMinOrder α]
theorem IsLowerSet.not_bddBelow (hs : IsLowerSet s) : s.Nonempty → ¬BddBelow s := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
obtain ⟨c, hc⟩ := exists_lt b
exact hc.not_le (hb <| hs (hc.le.trans <| hb ha) ha)
#align is_lower_set.not_bdd_below IsLowerSet.not_bddBelow
theorem not_bddBelow_Iic : ¬BddBelow (Iic a) :=
(isLowerSet_Iic _).not_bddBelow nonempty_Iic
#align not_bdd_below_Iic not_bddBelow_Iic
theorem not_bddBelow_Iio : ¬BddBelow (Iio a) :=
(isLowerSet_Iio _).not_bddBelow nonempty_Iio
#align not_bdd_below_Iio not_bddBelow_Iio
end NoMinOrder
end Preorder
section PartialOrder
variable [PartialOrder α] {s : Set α}
theorem isUpperSet_iff_forall_lt : IsUpperSet s ↔ ∀ ⦃a b : α⦄, a < b → a ∈ s → b ∈ s :=
forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and]
#align is_upper_set_iff_forall_lt isUpperSet_iff_forall_lt
theorem isLowerSet_iff_forall_lt : IsLowerSet s ↔ ∀ ⦃a b : α⦄, b < a → a ∈ s → b ∈ s :=
forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and]
#align is_lower_set_iff_forall_lt isLowerSet_iff_forall_lt
theorem isUpperSet_iff_Ioi_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ioi a ⊆ s := by
simp [isUpperSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)]
#align is_upper_set_iff_Ioi_subset isUpperSet_iff_Ioi_subset
theorem isLowerSet_iff_Iio_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iio a ⊆ s := by
simp [isLowerSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)]
#align is_lower_set_iff_Iio_subset isLowerSet_iff_Iio_subset
end PartialOrder
section LinearOrder
variable [LinearOrder α] {s t : Set α}
theorem IsUpperSet.total (hs : IsUpperSet s) (ht : IsUpperSet t) : s ⊆ t ∨ t ⊆ s := by
by_contra! h
simp_rw [Set.not_subset] at h
obtain ⟨⟨a, has, hat⟩, b, hbt, hbs⟩ := h
obtain hab | hba := le_total a b
· exact hbs (hs hab has)
· exact hat (ht hba hbt)
#align is_upper_set.total IsUpperSet.total
theorem IsLowerSet.total (hs : IsLowerSet s) (ht : IsLowerSet t) : s ⊆ t ∨ t ⊆ s :=
hs.toDual.total ht.toDual
#align is_lower_set.total IsLowerSet.total
end LinearOrder
/-! ### Bundled upper/lower sets -/
section LE
variable [LE α]
/-- The type of upper sets of an order. -/
structure UpperSet (α : Type*) [LE α] where
/-- The carrier of an `UpperSet`. -/
carrier : Set α
/-- The carrier of an `UpperSet` is an upper set. -/
upper' : IsUpperSet carrier
#align upper_set UpperSet
/-- The type of lower sets of an order. -/
structure LowerSet (α : Type*) [LE α] where
/-- The carrier of a `LowerSet`. -/
carrier : Set α
/-- The carrier of a `LowerSet` is a lower set. -/
lower' : IsLowerSet carrier
#align lower_set LowerSet
namespace UpperSet
instance : SetLike (UpperSet α) α where
coe := UpperSet.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : UpperSet α) : Set α := s
initialize_simps_projections UpperSet (carrier → coe)
@[ext]
theorem ext {s t : UpperSet α} : (s : Set α) = t → s = t :=
SetLike.ext'
#align upper_set.ext UpperSet.ext
@[simp]
theorem carrier_eq_coe (s : UpperSet α) : s.carrier = s :=
rfl
#align upper_set.carrier_eq_coe UpperSet.carrier_eq_coe
@[simp] protected lemma upper (s : UpperSet α) : IsUpperSet (s : Set α) := s.upper'
#align upper_set.upper UpperSet.upper
@[simp, norm_cast] lemma coe_mk (s : Set α) (hs) : mk s hs = s := rfl
@[simp] lemma mem_mk {s : Set α} (hs) {a : α} : a ∈ mk s hs ↔ a ∈ s := Iff.rfl
#align upper_set.mem_mk UpperSet.mem_mk
end UpperSet
namespace LowerSet
instance : SetLike (LowerSet α) α where
coe := LowerSet.carrier
coe_injective' s t h := by cases s; cases t; congr
/-- See Note [custom simps projection]. -/
def Simps.coe (s : LowerSet α) : Set α := s
initialize_simps_projections LowerSet (carrier → coe)
@[ext]
theorem ext {s t : LowerSet α} : (s : Set α) = t → s = t :=
SetLike.ext'
#align lower_set.ext LowerSet.ext
@[simp]
theorem carrier_eq_coe (s : LowerSet α) : s.carrier = s :=
rfl
#align lower_set.carrier_eq_coe LowerSet.carrier_eq_coe
@[simp] protected lemma lower (s : LowerSet α) : IsLowerSet (s : Set α) := s.lower'
#align lower_set.lower LowerSet.lower
@[simp, norm_cast] lemma coe_mk (s : Set α) (hs) : mk s hs = s := rfl
@[simp] lemma mem_mk {s : Set α} (hs) {a : α} : a ∈ mk s hs ↔ a ∈ s := Iff.rfl
#align lower_set.mem_mk LowerSet.mem_mk
end LowerSet
/-! #### Order -/
namespace UpperSet
variable {S : Set (UpperSet α)} {s t : UpperSet α} {a : α}
instance : Sup (UpperSet α) :=
⟨fun s t => ⟨s ∩ t, s.upper.inter t.upper⟩⟩
instance : Inf (UpperSet α) :=
⟨fun s t => ⟨s ∪ t, s.upper.union t.upper⟩⟩
instance : Top (UpperSet α) :=
⟨⟨∅, isUpperSet_empty⟩⟩
instance : Bot (UpperSet α) :=
⟨⟨univ, isUpperSet_univ⟩⟩
instance : SupSet (UpperSet α) :=
⟨fun S => ⟨⋂ s ∈ S, ↑s, isUpperSet_iInter₂ fun s _ => s.upper⟩⟩
instance : InfSet (UpperSet α) :=
⟨fun S => ⟨⋃ s ∈ S, ↑s, isUpperSet_iUnion₂ fun s _ => s.upper⟩⟩
instance completelyDistribLattice : CompletelyDistribLattice (UpperSet α) :=
(toDual.injective.comp SetLike.coe_injective).completelyDistribLattice _ (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl
instance : Inhabited (UpperSet α) :=
⟨⊥⟩
@[simp 1100, norm_cast]
theorem coe_subset_coe : (s : Set α) ⊆ t ↔ t ≤ s :=
Iff.rfl
#align upper_set.coe_subset_coe UpperSet.coe_subset_coe
@[simp 1100, norm_cast] lemma coe_ssubset_coe : (s : Set α) ⊂ t ↔ t < s := Iff.rfl
@[simp, norm_cast]
theorem coe_top : ((⊤ : UpperSet α) : Set α) = ∅ :=
rfl
#align upper_set.coe_top UpperSet.coe_top
@[simp, norm_cast]
theorem coe_bot : ((⊥ : UpperSet α) : Set α) = univ :=
rfl
#align upper_set.coe_bot UpperSet.coe_bot
@[simp, norm_cast]
theorem coe_eq_univ : (s : Set α) = univ ↔ s = ⊥ := by simp [SetLike.ext'_iff]
#align upper_set.coe_eq_univ UpperSet.coe_eq_univ
@[simp, norm_cast]
theorem coe_eq_empty : (s : Set α) = ∅ ↔ s = ⊤ := by simp [SetLike.ext'_iff]
#align upper_set.coe_eq_empty UpperSet.coe_eq_empty
@[simp, norm_cast] lemma coe_nonempty : (s : Set α).Nonempty ↔ s ≠ ⊤ :=
nonempty_iff_ne_empty.trans coe_eq_empty.not
@[simp, norm_cast]
theorem coe_sup (s t : UpperSet α) : (↑(s ⊔ t) : Set α) = (s : Set α) ∩ t :=
rfl
#align upper_set.coe_sup UpperSet.coe_sup
@[simp, norm_cast]
theorem coe_inf (s t : UpperSet α) : (↑(s ⊓ t) : Set α) = (s : Set α) ∪ t :=
rfl
#align upper_set.coe_inf UpperSet.coe_inf
@[simp, norm_cast]
theorem coe_sSup (S : Set (UpperSet α)) : (↑(sSup S) : Set α) = ⋂ s ∈ S, ↑s :=
rfl
#align upper_set.coe_Sup UpperSet.coe_sSup
@[simp, norm_cast]
theorem coe_sInf (S : Set (UpperSet α)) : (↑(sInf S) : Set α) = ⋃ s ∈ S, ↑s :=
rfl
#align upper_set.coe_Inf UpperSet.coe_sInf
@[simp, norm_cast]
theorem coe_iSup (f : ι → UpperSet α) : (↑(⨆ i, f i) : Set α) = ⋂ i, f i := by simp [iSup]
#align upper_set.coe_supr UpperSet.coe_iSup
@[simp, norm_cast]
theorem coe_iInf (f : ι → UpperSet α) : (↑(⨅ i, f i) : Set α) = ⋃ i, f i := by simp [iInf]
#align upper_set.coe_infi UpperSet.coe_iInf
@[norm_cast] -- Porting note: no longer a `simp`
theorem coe_iSup₂ (f : ∀ i, κ i → UpperSet α) :
(↑(⨆ (i) (j), f i j) : Set α) = ⋂ (i) (j), f i j := by simp_rw [coe_iSup]
#align upper_set.coe_supr₂ UpperSet.coe_iSup₂
@[norm_cast] -- Porting note: no longer a `simp`
theorem coe_iInf₂ (f : ∀ i, κ i → UpperSet α) :
(↑(⨅ (i) (j), f i j) : Set α) = ⋃ (i) (j), f i j := by simp_rw [coe_iInf]
#align upper_set.coe_infi₂ UpperSet.coe_iInf₂
@[simp]
theorem not_mem_top : a ∉ (⊤ : UpperSet α) :=
id
#align upper_set.not_mem_top UpperSet.not_mem_top
@[simp]
theorem mem_bot : a ∈ (⊥ : UpperSet α) :=
trivial
#align upper_set.mem_bot UpperSet.mem_bot
@[simp]
theorem mem_sup_iff : a ∈ s ⊔ t ↔ a ∈ s ∧ a ∈ t :=
Iff.rfl
#align upper_set.mem_sup_iff UpperSet.mem_sup_iff
@[simp]
theorem mem_inf_iff : a ∈ s ⊓ t ↔ a ∈ s ∨ a ∈ t :=
Iff.rfl
#align upper_set.mem_inf_iff UpperSet.mem_inf_iff
@[simp]
theorem mem_sSup_iff : a ∈ sSup S ↔ ∀ s ∈ S, a ∈ s :=
mem_iInter₂
#align upper_set.mem_Sup_iff UpperSet.mem_sSup_iff
@[simp]
theorem mem_sInf_iff : a ∈ sInf S ↔ ∃ s ∈ S, a ∈ s :=
mem_iUnion₂.trans <| by simp only [exists_prop, SetLike.mem_coe]
#align upper_set.mem_Inf_iff UpperSet.mem_sInf_iff
@[simp]
theorem mem_iSup_iff {f : ι → UpperSet α} : (a ∈ ⨆ i, f i) ↔ ∀ i, a ∈ f i := by
rw [← SetLike.mem_coe, coe_iSup]
exact mem_iInter
#align upper_set.mem_supr_iff UpperSet.mem_iSup_iff
@[simp]
theorem mem_iInf_iff {f : ι → UpperSet α} : (a ∈ ⨅ i, f i) ↔ ∃ i, a ∈ f i := by
rw [← SetLike.mem_coe, coe_iInf]
exact mem_iUnion
#align upper_set.mem_infi_iff UpperSet.mem_iInf_iff
-- Porting note: no longer a @[simp]
theorem mem_iSup₂_iff {f : ∀ i, κ i → UpperSet α} : (a ∈ ⨆ (i) (j), f i j) ↔ ∀ i j, a ∈ f i j := by
simp_rw [mem_iSup_iff]
#align upper_set.mem_supr₂_iff UpperSet.mem_iSup₂_iff
-- Porting note: no longer a @[simp]
theorem mem_iInf₂_iff {f : ∀ i, κ i → UpperSet α} : (a ∈ ⨅ (i) (j), f i j) ↔ ∃ i j, a ∈ f i j := by
simp_rw [mem_iInf_iff]
#align upper_set.mem_infi₂_iff UpperSet.mem_iInf₂_iff
@[simp, norm_cast]
theorem codisjoint_coe : Codisjoint (s : Set α) t ↔ Disjoint s t := by
simp [disjoint_iff, codisjoint_iff, SetLike.ext'_iff]
#align upper_set.codisjoint_coe UpperSet.codisjoint_coe
end UpperSet
namespace LowerSet
variable {S : Set (LowerSet α)} {s t : LowerSet α} {a : α}
instance : Sup (LowerSet α) :=
⟨fun s t => ⟨s ∪ t, fun _ _ h => Or.imp (s.lower h) (t.lower h)⟩⟩
instance : Inf (LowerSet α) :=
⟨fun s t => ⟨s ∩ t, fun _ _ h => And.imp (s.lower h) (t.lower h)⟩⟩
instance : Top (LowerSet α) :=
⟨⟨univ, fun _ _ _ => id⟩⟩
instance : Bot (LowerSet α) :=
⟨⟨∅, fun _ _ _ => id⟩⟩
instance : SupSet (LowerSet α) :=
⟨fun S => ⟨⋃ s ∈ S, ↑s, isLowerSet_iUnion₂ fun s _ => s.lower⟩⟩
instance : InfSet (LowerSet α) :=
⟨fun S => ⟨⋂ s ∈ S, ↑s, isLowerSet_iInter₂ fun s _ => s.lower⟩⟩
instance completelyDistribLattice : CompletelyDistribLattice (LowerSet α) :=
SetLike.coe_injective.completelyDistribLattice _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ => rfl) rfl rfl
instance : Inhabited (LowerSet α) :=
⟨⊥⟩
@[norm_cast] lemma coe_subset_coe : (s : Set α) ⊆ t ↔ s ≤ t := Iff.rfl
#align lower_set.coe_subset_coe LowerSet.coe_subset_coe
@[norm_cast] lemma coe_ssubset_coe : (s : Set α) ⊂ t ↔ s < t := Iff.rfl
@[simp, norm_cast]
theorem coe_top : ((⊤ : LowerSet α) : Set α) = univ :=
rfl
#align lower_set.coe_top LowerSet.coe_top
@[simp, norm_cast]
theorem coe_bot : ((⊥ : LowerSet α) : Set α) = ∅ :=
rfl
#align lower_set.coe_bot LowerSet.coe_bot
@[simp, norm_cast]
theorem coe_eq_univ : (s : Set α) = univ ↔ s = ⊤ := by simp [SetLike.ext'_iff]
#align lower_set.coe_eq_univ LowerSet.coe_eq_univ
@[simp, norm_cast]
theorem coe_eq_empty : (s : Set α) = ∅ ↔ s = ⊥ := by simp [SetLike.ext'_iff]
#align lower_set.coe_eq_empty LowerSet.coe_eq_empty
@[simp, norm_cast] lemma coe_nonempty : (s : Set α).Nonempty ↔ s ≠ ⊥ :=
nonempty_iff_ne_empty.trans coe_eq_empty.not
@[simp, norm_cast]
theorem coe_sup (s t : LowerSet α) : (↑(s ⊔ t) : Set α) = (s : Set α) ∪ t :=
rfl
#align lower_set.coe_sup LowerSet.coe_sup
@[simp, norm_cast]
theorem coe_inf (s t : LowerSet α) : (↑(s ⊓ t) : Set α) = (s : Set α) ∩ t :=
rfl
#align lower_set.coe_inf LowerSet.coe_inf
@[simp, norm_cast]
theorem coe_sSup (S : Set (LowerSet α)) : (↑(sSup S) : Set α) = ⋃ s ∈ S, ↑s :=
rfl
#align lower_set.coe_Sup LowerSet.coe_sSup
@[simp, norm_cast]
theorem coe_sInf (S : Set (LowerSet α)) : (↑(sInf S) : Set α) = ⋂ s ∈ S, ↑s :=
rfl
#align lower_set.coe_Inf LowerSet.coe_sInf
@[simp, norm_cast]
theorem coe_iSup (f : ι → LowerSet α) : (↑(⨆ i, f i) : Set α) = ⋃ i, f i := by
simp_rw [iSup, coe_sSup, mem_range, iUnion_exists, iUnion_iUnion_eq']
#align lower_set.coe_supr LowerSet.coe_iSup
@[simp, norm_cast]
theorem coe_iInf (f : ι → LowerSet α) : (↑(⨅ i, f i) : Set α) = ⋂ i, f i := by
simp_rw [iInf, coe_sInf, mem_range, iInter_exists, iInter_iInter_eq']
#align lower_set.coe_infi LowerSet.coe_iInf
@[norm_cast] -- Porting note: no longer a `simp`
theorem coe_iSup₂ (f : ∀ i, κ i → LowerSet α) :
(↑(⨆ (i) (j), f i j) : Set α) = ⋃ (i) (j), f i j := by simp_rw [coe_iSup]
#align lower_set.coe_supr₂ LowerSet.coe_iSup₂
@[norm_cast] -- Porting note: no longer a `simp`
theorem coe_iInf₂ (f : ∀ i, κ i → LowerSet α) :
(↑(⨅ (i) (j), f i j) : Set α) = ⋂ (i) (j), f i j := by simp_rw [coe_iInf]
#align lower_set.coe_infi₂ LowerSet.coe_iInf₂
@[simp]
theorem mem_top : a ∈ (⊤ : LowerSet α) :=
trivial
#align lower_set.mem_top LowerSet.mem_top
@[simp]
theorem not_mem_bot : a ∉ (⊥ : LowerSet α) :=
id
#align lower_set.not_mem_bot LowerSet.not_mem_bot
@[simp]
theorem mem_sup_iff : a ∈ s ⊔ t ↔ a ∈ s ∨ a ∈ t :=
Iff.rfl
#align lower_set.mem_sup_iff LowerSet.mem_sup_iff
@[simp]
theorem mem_inf_iff : a ∈ s ⊓ t ↔ a ∈ s ∧ a ∈ t :=
Iff.rfl
#align lower_set.mem_inf_iff LowerSet.mem_inf_iff
@[simp]
theorem mem_sSup_iff : a ∈ sSup S ↔ ∃ s ∈ S, a ∈ s :=
mem_iUnion₂.trans <| by simp only [exists_prop, SetLike.mem_coe]
#align lower_set.mem_Sup_iff LowerSet.mem_sSup_iff
@[simp]
theorem mem_sInf_iff : a ∈ sInf S ↔ ∀ s ∈ S, a ∈ s :=
mem_iInter₂
#align lower_set.mem_Inf_iff LowerSet.mem_sInf_iff
@[simp]
theorem mem_iSup_iff {f : ι → LowerSet α} : (a ∈ ⨆ i, f i) ↔ ∃ i, a ∈ f i := by
rw [← SetLike.mem_coe, coe_iSup]
exact mem_iUnion
#align lower_set.mem_supr_iff LowerSet.mem_iSup_iff
@[simp]
theorem mem_iInf_iff {f : ι → LowerSet α} : (a ∈ ⨅ i, f i) ↔ ∀ i, a ∈ f i := by
rw [← SetLike.mem_coe, coe_iInf]
exact mem_iInter
#align lower_set.mem_infi_iff LowerSet.mem_iInf_iff
-- Porting note: no longer a @[simp]
| Mathlib/Order/UpperLower/Basic.lean | 837 | 838 | theorem mem_iSup₂_iff {f : ∀ i, κ i → LowerSet α} : (a ∈ ⨆ (i) (j), f i j) ↔ ∃ i j, a ∈ f i j := by |
simp_rw [mem_iSup_iff]
|
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Junyan Xu
-/
import Mathlib.Topology.Sheaves.PUnit
import Mathlib.Topology.Sheaves.Stalks
import Mathlib.Topology.Sheaves.Functors
#align_import topology.sheaves.skyscraper from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a"
/-!
# Skyscraper (pre)sheaves
A skyscraper (pre)sheaf `𝓕 : (Pre)Sheaf C X` is the (pre)sheaf with value `A` at point `p₀` that is
supported only at open sets contain `p₀`, i.e. `𝓕(U) = A` if `p₀ ∈ U` and `𝓕(U) = *` if `p₀ ∉ U`
where `*` is a terminal object of `C`. In terms of stalks, `𝓕` is supported at all specializations
of `p₀`, i.e. if `p₀ ⤳ x` then `𝓕ₓ ≅ A` and if `¬ p₀ ⤳ x` then `𝓕ₓ ≅ *`.
## Main definitions
* `skyscraperPresheaf`: `skyscraperPresheaf p₀ A` is the skyscraper presheaf at point `p₀` with
value `A`.
* `skyscraperSheaf`: the skyscraper presheaf satisfies the sheaf condition.
## Main statements
* `skyscraperPresheafStalkOfSpecializes`: if `y ∈ closure {p₀}` then the stalk of
`skyscraperPresheaf p₀ A` at `y` is `A`.
* `skyscraperPresheafStalkOfNotSpecializes`: if `y ∉ closure {p₀}` then the stalk of
`skyscraperPresheaf p₀ A` at `y` is `*` the terminal object.
TODO: generalize universe level when calculating stalks, after generalizing universe level of stalk.
-/
noncomputable section
open TopologicalSpace TopCat CategoryTheory CategoryTheory.Limits Opposite
universe u v w
variable {X : TopCat.{u}} (p₀ : X) [∀ U : Opens X, Decidable (p₀ ∈ U)]
section
variable {C : Type v} [Category.{w} C] [HasTerminal C] (A : C)
/-- A skyscraper presheaf is a presheaf supported at a single point: if `p₀ ∈ X` is a specified
point, then the skyscraper presheaf `𝓕` with value `A` is defined by `U ↦ A` if `p₀ ∈ U` and
`U ↦ *` if `p₀ ∉ A` where `*` is some terminal object.
-/
@[simps]
def skyscraperPresheaf : Presheaf C X where
obj U := if p₀ ∈ unop U then A else terminal C
map {U V} i :=
if h : p₀ ∈ unop V then eqToHom <| by dsimp; erw [if_pos h, if_pos (leOfHom i.unop h)]
else ((if_neg h).symm.ndrec terminalIsTerminal).from _
map_id U :=
(em (p₀ ∈ U.unop)).elim (fun h => dif_pos h) fun h =>
((if_neg h).symm.ndrec terminalIsTerminal).hom_ext _ _
map_comp {U V W} iVU iWV := by
by_cases hW : p₀ ∈ unop W
· have hV : p₀ ∈ unop V := leOfHom iWV.unop hW
simp only [dif_pos hW, dif_pos hV, eqToHom_trans]
· dsimp; rw [dif_neg hW]; apply ((if_neg hW).symm.ndrec terminalIsTerminal).hom_ext
#align skyscraper_presheaf skyscraperPresheaf
| Mathlib/Topology/Sheaves/Skyscraper.lean | 68 | 74 | theorem skyscraperPresheaf_eq_pushforward
[hd : ∀ U : Opens (TopCat.of PUnit.{u + 1}), Decidable (PUnit.unit ∈ U)] :
skyscraperPresheaf p₀ A =
ContinuousMap.const (TopCat.of PUnit) p₀ _*
skyscraperPresheaf (X := TopCat.of PUnit) PUnit.unit A := by |
convert_to @skyscraperPresheaf X p₀ (fun U => hd <| (Opens.map <| ContinuousMap.const _ p₀).obj U)
C _ _ A = _ <;> congr
|
/-
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, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.FormalMultilinearSeries
import Mathlib.Analysis.SpecificLimits.Normed
import Mathlib.Logic.Equiv.Fin
import Mathlib.Topology.Algebra.InfiniteSum.Module
#align_import analysis.analytic.basic from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514"
/-!
# Analytic functions
A function is analytic in one dimension around `0` if it can be written as a converging power series
`Σ pₙ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by
requiring that `pₙ` is a continuous `n`-multilinear map. In general, `pₙ` is not unique (in two
dimensions, taking `p₂ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a
vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pₙ`, but this is not
always possible in nonzero characteristic (in characteristic 2, the previous example has no
symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition,
and we only require the existence of a converging series.
The general framework is important to say that the exponential map on bounded operators on a Banach
space is analytic, as well as the inverse on invertible operators.
## Main definitions
Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n`
for `n : ℕ`.
* `p.radius`: the largest `r : ℝ≥0∞` such that `‖p n‖ * r^n` grows subexponentially.
* `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_isBigO`: if `‖p n‖ * r ^ n`
is bounded above, then `r ≤ p.radius`;
* `p.isLittleO_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`,
`p.isLittleO_one_of_lt_radius`,
`p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then
`‖p n‖ * r ^ n` tends to zero exponentially;
* `p.lt_radius_of_isBigO`: if `r ≠ 0` and `‖p n‖ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then
`r < p.radius`;
* `p.partialSum n x`: the sum `∑_{i = 0}^{n-1} pᵢ xⁱ`.
* `p.sum x`: the sum `∑'_{i = 0}^{∞} pᵢ xⁱ`.
Additionally, let `f` be a function from `E` to `F`.
* `HasFPowerSeriesOnBall f p x r`: on the ball of center `x` with radius `r`,
`f (x + y) = ∑'_n pₙ yⁿ`.
* `HasFPowerSeriesAt f p x`: on some ball of center `x` with positive radius, holds
`HasFPowerSeriesOnBall f p x r`.
* `AnalyticAt 𝕜 f x`: there exists a power series `p` such that holds `HasFPowerSeriesAt f p x`.
* `AnalyticOn 𝕜 f s`: the function `f` is analytic at every point of `s`.
We develop the basic properties of these notions, notably:
* If a function admits a power series, it is continuous (see
`HasFPowerSeriesOnBall.continuousOn` and `HasFPowerSeriesAt.continuousAt` and
`AnalyticAt.continuousAt`).
* In a complete space, the sum of a formal power series with positive radius is well defined on the
disk of convergence, see `FormalMultilinearSeries.hasFPowerSeriesOnBall`.
* If a function admits a power series in a ball, then it is analytic at any point `y` of this ball,
and the power series there can be expressed in terms of the initial power series `p` as
`p.changeOrigin y`. See `HasFPowerSeriesOnBall.changeOrigin`. It follows in particular that
the set of points at which a given function is analytic is open, see `isOpen_analyticAt`.
## Implementation details
We only introduce the radius of convergence of a power series, as `p.radius`.
For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent)
notion, describing the polydisk of convergence. This notion is more specific, and not necessary to
build the general theory. We do not define it here.
-/
noncomputable section
variable {𝕜 E F G : Type*}
open scoped Classical
open Topology NNReal Filter ENNReal
open Set Filter Asymptotics
namespace FormalMultilinearSeries
variable [Ring 𝕜] [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F]
variable [TopologicalSpace E] [TopologicalSpace F]
variable [TopologicalAddGroup E] [TopologicalAddGroup F]
variable [ContinuousConstSMul 𝕜 E] [ContinuousConstSMul 𝕜 F]
/-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Σ pₙ xⁿ`. A
priori, it only behaves well when `‖x‖ < p.radius`. -/
protected def sum (p : FormalMultilinearSeries 𝕜 E F) (x : E) : F :=
∑' n : ℕ, p n fun _ => x
#align formal_multilinear_series.sum FormalMultilinearSeries.sum
/-- Given a formal multilinear series `p` and a vector `x`, then `p.partialSum n x` is the sum
`Σ pₖ xᵏ` for `k ∈ {0,..., n-1}`. -/
def partialSum (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) (x : E) : F :=
∑ k ∈ Finset.range n, p k fun _ : Fin k => x
#align formal_multilinear_series.partial_sum FormalMultilinearSeries.partialSum
/-- The partial sums of a formal multilinear series are continuous. -/
theorem partialSum_continuous (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) :
Continuous (p.partialSum n) := by
unfold partialSum -- Porting note: added
continuity
#align formal_multilinear_series.partial_sum_continuous FormalMultilinearSeries.partialSum_continuous
end FormalMultilinearSeries
/-! ### The radius of a formal multilinear series -/
variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F]
[NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G]
namespace FormalMultilinearSeries
variable (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
/-- The radius of a formal multilinear series is the largest `r` such that the sum `Σ ‖pₙ‖ ‖y‖ⁿ`
converges for all `‖y‖ < r`. This implies that `Σ pₙ yⁿ` converges for all `‖y‖ < r`, but these
definitions are *not* equivalent in general. -/
def radius (p : FormalMultilinearSeries 𝕜 E F) : ℝ≥0∞ :=
⨆ (r : ℝ≥0) (C : ℝ) (_ : ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C), (r : ℝ≥0∞)
#align formal_multilinear_series.radius FormalMultilinearSeries.radius
/-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_bound (C : ℝ) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖ * (r : ℝ) ^ n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
le_iSup_of_le r <| le_iSup_of_le C <| le_iSup (fun _ => (r : ℝ≥0∞)) h
#align formal_multilinear_series.le_radius_of_bound FormalMultilinearSeries.le_radius_of_bound
/-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_bound_nnreal (C : ℝ≥0) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖₊ * r ^ n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
p.le_radius_of_bound C fun n => mod_cast h n
#align formal_multilinear_series.le_radius_of_bound_nnreal FormalMultilinearSeries.le_radius_of_bound_nnreal
/-- If `‖pₙ‖ rⁿ = O(1)`, as `n → ∞`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_isBigO (h : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) :
↑r ≤ p.radius :=
Exists.elim (isBigO_one_nat_atTop_iff.1 h) fun C hC =>
p.le_radius_of_bound C fun n => (le_abs_self _).trans (hC n)
set_option linter.uppercaseLean3 false in
#align formal_multilinear_series.le_radius_of_is_O FormalMultilinearSeries.le_radius_of_isBigO
theorem le_radius_of_eventually_le (C) (h : ∀ᶠ n in atTop, ‖p n‖ * (r : ℝ) ^ n ≤ C) :
↑r ≤ p.radius :=
p.le_radius_of_isBigO <| IsBigO.of_bound C <| h.mono fun n hn => by simpa
#align formal_multilinear_series.le_radius_of_eventually_le FormalMultilinearSeries.le_radius_of_eventually_le
theorem le_radius_of_summable_nnnorm (h : Summable fun n => ‖p n‖₊ * r ^ n) : ↑r ≤ p.radius :=
p.le_radius_of_bound_nnreal (∑' n, ‖p n‖₊ * r ^ n) fun _ => le_tsum' h _
#align formal_multilinear_series.le_radius_of_summable_nnnorm FormalMultilinearSeries.le_radius_of_summable_nnnorm
theorem le_radius_of_summable (h : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius :=
p.le_radius_of_summable_nnnorm <| by
simp only [← coe_nnnorm] at h
exact mod_cast h
#align formal_multilinear_series.le_radius_of_summable FormalMultilinearSeries.le_radius_of_summable
theorem radius_eq_top_of_forall_nnreal_isBigO
(h : ∀ r : ℝ≥0, (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) : p.radius = ∞ :=
ENNReal.eq_top_of_forall_nnreal_le fun r => p.le_radius_of_isBigO (h r)
set_option linter.uppercaseLean3 false in
#align formal_multilinear_series.radius_eq_top_of_forall_nnreal_is_O FormalMultilinearSeries.radius_eq_top_of_forall_nnreal_isBigO
theorem radius_eq_top_of_eventually_eq_zero (h : ∀ᶠ n in atTop, p n = 0) : p.radius = ∞ :=
p.radius_eq_top_of_forall_nnreal_isBigO fun r =>
(isBigO_zero _ _).congr' (h.mono fun n hn => by simp [hn]) EventuallyEq.rfl
#align formal_multilinear_series.radius_eq_top_of_eventually_eq_zero FormalMultilinearSeries.radius_eq_top_of_eventually_eq_zero
theorem radius_eq_top_of_forall_image_add_eq_zero (n : ℕ) (hn : ∀ m, p (m + n) = 0) :
p.radius = ∞ :=
p.radius_eq_top_of_eventually_eq_zero <|
mem_atTop_sets.2 ⟨n, fun _ hk => tsub_add_cancel_of_le hk ▸ hn _⟩
#align formal_multilinear_series.radius_eq_top_of_forall_image_add_eq_zero FormalMultilinearSeries.radius_eq_top_of_forall_image_add_eq_zero
@[simp]
theorem constFormalMultilinearSeries_radius {v : F} :
(constFormalMultilinearSeries 𝕜 E v).radius = ⊤ :=
(constFormalMultilinearSeries 𝕜 E v).radius_eq_top_of_forall_image_add_eq_zero 1
(by simp [constFormalMultilinearSeries])
#align formal_multilinear_series.const_formal_multilinear_series_radius FormalMultilinearSeries.constFormalMultilinearSeries_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially:
for some `0 < a < 1`, `‖p n‖ rⁿ = o(aⁿ)`. -/
theorem isLittleO_of_lt_radius (h : ↑r < p.radius) :
∃ a ∈ Ioo (0 : ℝ) 1, (fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (a ^ ·) := by
have := (TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4
rw [this]
-- Porting note: was
-- rw [(TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4]
simp only [radius, lt_iSup_iff] at h
rcases h with ⟨t, C, hC, rt⟩
rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at rt
have : 0 < (t : ℝ) := r.coe_nonneg.trans_lt rt
rw [← div_lt_one this] at rt
refine ⟨_, rt, C, Or.inr zero_lt_one, fun n => ?_⟩
calc
|‖p n‖ * (r : ℝ) ^ n| = ‖p n‖ * (t : ℝ) ^ n * (r / t : ℝ) ^ n := by
field_simp [mul_right_comm, abs_mul]
_ ≤ C * (r / t : ℝ) ^ n := by gcongr; apply hC
#align formal_multilinear_series.is_o_of_lt_radius FormalMultilinearSeries.isLittleO_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ = o(1)`. -/
theorem isLittleO_one_of_lt_radius (h : ↑r < p.radius) :
(fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (fun _ => 1 : ℕ → ℝ) :=
let ⟨_, ha, hp⟩ := p.isLittleO_of_lt_radius h
hp.trans <| (isLittleO_pow_pow_of_lt_left ha.1.le ha.2).congr (fun _ => rfl) one_pow
#align formal_multilinear_series.is_o_one_of_lt_radius FormalMultilinearSeries.isLittleO_one_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially:
for some `0 < a < 1` and `C > 0`, `‖p n‖ * r ^ n ≤ C * a ^ n`. -/
theorem norm_mul_pow_le_mul_pow_of_lt_radius (h : ↑r < p.radius) :
∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C * a ^ n := by
-- Porting note: moved out of `rcases`
have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 5).mp
(p.isLittleO_of_lt_radius h)
rcases this with ⟨a, ha, C, hC, H⟩
exact ⟨a, ha, C, hC, fun n => (le_abs_self _).trans (H n)⟩
#align formal_multilinear_series.norm_mul_pow_le_mul_pow_of_lt_radius FormalMultilinearSeries.norm_mul_pow_le_mul_pow_of_lt_radius
/-- If `r ≠ 0` and `‖pₙ‖ rⁿ = O(aⁿ)` for some `-1 < a < 1`, then `r < p.radius`. -/
theorem lt_radius_of_isBigO (h₀ : r ≠ 0) {a : ℝ} (ha : a ∈ Ioo (-1 : ℝ) 1)
(hp : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] (a ^ ·)) : ↑r < p.radius := by
-- Porting note: moved out of `rcases`
have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 2 5)
rcases this.mp ⟨a, ha, hp⟩ with ⟨a, ha, C, hC, hp⟩
rw [← pos_iff_ne_zero, ← NNReal.coe_pos] at h₀
lift a to ℝ≥0 using ha.1.le
have : (r : ℝ) < r / a := by
simpa only [div_one] using (div_lt_div_left h₀ zero_lt_one ha.1).2 ha.2
norm_cast at this
rw [← ENNReal.coe_lt_coe] at this
refine this.trans_le (p.le_radius_of_bound C fun n => ?_)
rw [NNReal.coe_div, div_pow, ← mul_div_assoc, div_le_iff (pow_pos ha.1 n)]
exact (le_abs_self _).trans (hp n)
set_option linter.uppercaseLean3 false in
#align formal_multilinear_series.lt_radius_of_is_O FormalMultilinearSeries.lt_radius_of_isBigO
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
theorem norm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C :=
let ⟨_, ha, C, hC, h⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h
⟨C, hC, fun n => (h n).trans <| mul_le_of_le_one_right hC.lt.le (pow_le_one _ ha.1.le ha.2.le)⟩
#align formal_multilinear_series.norm_mul_pow_le_of_lt_radius FormalMultilinearSeries.norm_mul_pow_le_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
theorem norm_le_div_pow_of_pos_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
(h0 : 0 < r) (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ ≤ C / (r : ℝ) ^ n :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h
⟨C, hC, fun n => Iff.mpr (le_div_iff (pow_pos h0 _)) (hp n)⟩
#align formal_multilinear_series.norm_le_div_pow_of_pos_of_lt_radius FormalMultilinearSeries.norm_le_div_pow_of_pos_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
theorem nnnorm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖₊ * r ^ n ≤ C :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h
⟨⟨C, hC.lt.le⟩, hC, mod_cast hp⟩
#align formal_multilinear_series.nnnorm_mul_pow_le_of_lt_radius FormalMultilinearSeries.nnnorm_mul_pow_le_of_lt_radius
theorem le_radius_of_tendsto (p : FormalMultilinearSeries 𝕜 E F) {l : ℝ}
(h : Tendsto (fun n => ‖p n‖ * (r : ℝ) ^ n) atTop (𝓝 l)) : ↑r ≤ p.radius :=
p.le_radius_of_isBigO (h.isBigO_one _)
#align formal_multilinear_series.le_radius_of_tendsto FormalMultilinearSeries.le_radius_of_tendsto
theorem le_radius_of_summable_norm (p : FormalMultilinearSeries 𝕜 E F)
(hs : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius :=
p.le_radius_of_tendsto hs.tendsto_atTop_zero
#align formal_multilinear_series.le_radius_of_summable_norm FormalMultilinearSeries.le_radius_of_summable_norm
theorem not_summable_norm_of_radius_lt_nnnorm (p : FormalMultilinearSeries 𝕜 E F) {x : E}
(h : p.radius < ‖x‖₊) : ¬Summable fun n => ‖p n‖ * ‖x‖ ^ n :=
fun hs => not_le_of_lt h (p.le_radius_of_summable_norm hs)
#align formal_multilinear_series.not_summable_norm_of_radius_lt_nnnorm FormalMultilinearSeries.not_summable_norm_of_radius_lt_nnnorm
theorem summable_norm_mul_pow (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) :
Summable fun n : ℕ => ‖p n‖ * (r : ℝ) ^ n := by
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, - : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h
exact .of_nonneg_of_le (fun n => mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg _))
hp ((summable_geometric_of_lt_one ha.1.le ha.2).mul_left _)
#align formal_multilinear_series.summable_norm_mul_pow FormalMultilinearSeries.summable_norm_mul_pow
| Mathlib/Analysis/Analytic/Basic.lean | 284 | 289 | theorem summable_norm_apply (p : FormalMultilinearSeries 𝕜 E F) {x : E}
(hx : x ∈ EMetric.ball (0 : E) p.radius) : Summable fun n : ℕ => ‖p n fun _ => x‖ := by |
rw [mem_emetric_ball_zero_iff] at hx
refine .of_nonneg_of_le
(fun _ ↦ norm_nonneg _) (fun n ↦ ((p n).le_opNorm _).trans_eq ?_) (p.summable_norm_mul_pow hx)
simp
|
/-
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.Order.Field.Power
import Mathlib.NumberTheory.Padics.PadicVal
#align_import number_theory.padics.padic_norm from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7"
/-!
# p-adic norm
This file defines the `p`-adic norm on `ℚ`.
The `p`-adic valuation on `ℚ` is the difference of the multiplicities of `p` in the numerator and
denominator of `q`. This function obeys the standard properties of a valuation, with the appropriate
assumptions on `p`.
The valuation induces a norm on `ℚ`. This norm is a nonarchimedean absolute value.
It takes values in {0} ∪ {1/p^k | k ∈ ℤ}.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking `[Fact p.Prime]` as a type class argument.
## References
* [F. Q. Gouvêa, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, norm, valuation
-/
/-- If `q ≠ 0`, the `p`-adic norm of a rational `q` is `p ^ (-padicValRat p q)`.
If `q = 0`, the `p`-adic norm of `q` is `0`. -/
def padicNorm (p : ℕ) (q : ℚ) : ℚ :=
if q = 0 then 0 else (p : ℚ) ^ (-padicValRat p q)
#align padic_norm padicNorm
namespace padicNorm
open padicValRat
variable {p : ℕ}
/-- Unfolds the definition of the `p`-adic norm of `q` when `q ≠ 0`. -/
@[simp]
protected theorem eq_zpow_of_nonzero {q : ℚ} (hq : q ≠ 0) :
padicNorm p q = (p : ℚ) ^ (-padicValRat p q) := by simp [hq, padicNorm]
#align padic_norm.eq_zpow_of_nonzero padicNorm.eq_zpow_of_nonzero
/-- The `p`-adic norm is nonnegative. -/
protected theorem nonneg (q : ℚ) : 0 ≤ padicNorm p q :=
if hq : q = 0 then by simp [hq, padicNorm]
else by
unfold padicNorm
split_ifs
apply zpow_nonneg
exact mod_cast Nat.zero_le _
#align padic_norm.nonneg padicNorm.nonneg
/-- The `p`-adic norm of `0` is `0`. -/
@[simp]
protected theorem zero : padicNorm p 0 = 0 := by simp [padicNorm]
#align padic_norm.zero padicNorm.zero
/-- The `p`-adic norm of `1` is `1`. -/
-- @[simp] -- Porting note (#10618): simp can prove this
protected theorem one : padicNorm p 1 = 1 := by simp [padicNorm]
#align padic_norm.one padicNorm.one
/-- The `p`-adic norm of `p` is `p⁻¹` if `p > 1`.
See also `padicNorm.padicNorm_p_of_prime` for a version assuming `p` is prime. -/
theorem padicNorm_p (hp : 1 < p) : padicNorm p p = (p : ℚ)⁻¹ := by
simp [padicNorm, (pos_of_gt hp).ne', padicValNat.self hp]
#align padic_norm.padic_norm_p padicNorm.padicNorm_p
/-- The `p`-adic norm of `p` is `p⁻¹` if `p` is prime.
See also `padicNorm.padicNorm_p` for a version assuming `1 < p`. -/
@[simp]
theorem padicNorm_p_of_prime [Fact p.Prime] : padicNorm p p = (p : ℚ)⁻¹ :=
padicNorm_p <| Nat.Prime.one_lt Fact.out
#align padic_norm.padic_norm_p_of_prime padicNorm.padicNorm_p_of_prime
/-- The `p`-adic norm of `q` is `1` if `q` is prime and not equal to `p`. -/
theorem padicNorm_of_prime_of_ne {q : ℕ} [p_prime : Fact p.Prime] [q_prime : Fact q.Prime]
(neq : p ≠ q) : padicNorm p q = 1 := by
have p : padicValRat p q = 0 := mod_cast padicValNat_primes neq
rw [padicNorm, p]
simp [q_prime.1.ne_zero]
#align padic_norm.padic_norm_of_prime_of_ne padicNorm.padicNorm_of_prime_of_ne
/-- The `p`-adic norm of `p` is less than `1` if `1 < p`.
See also `padicNorm.padicNorm_p_lt_one_of_prime` for a version assuming `p` is prime. -/
theorem padicNorm_p_lt_one (hp : 1 < p) : padicNorm p p < 1 := by
rw [padicNorm_p hp, inv_lt_one_iff]
exact mod_cast Or.inr hp
#align padic_norm.padic_norm_p_lt_one padicNorm.padicNorm_p_lt_one
/-- The `p`-adic norm of `p` is less than `1` if `p` is prime.
See also `padicNorm.padicNorm_p_lt_one` for a version assuming `1 < p`. -/
theorem padicNorm_p_lt_one_of_prime [Fact p.Prime] : padicNorm p p < 1 :=
padicNorm_p_lt_one <| Nat.Prime.one_lt Fact.out
#align padic_norm.padic_norm_p_lt_one_of_prime padicNorm.padicNorm_p_lt_one_of_prime
/-- `padicNorm p q` takes discrete values `p ^ -z` for `z : ℤ`. -/
protected theorem values_discrete {q : ℚ} (hq : q ≠ 0) : ∃ z : ℤ, padicNorm p q = (p : ℚ) ^ (-z) :=
⟨padicValRat p q, by simp [padicNorm, hq]⟩
#align padic_norm.values_discrete padicNorm.values_discrete
/-- `padicNorm p` is symmetric. -/
@[simp]
protected theorem neg (q : ℚ) : padicNorm p (-q) = padicNorm p q :=
if hq : q = 0 then by simp [hq] else by simp [padicNorm, hq]
#align padic_norm.neg padicNorm.neg
variable [hp : Fact p.Prime]
/-- If `q ≠ 0`, then `padicNorm p q ≠ 0`. -/
protected theorem nonzero {q : ℚ} (hq : q ≠ 0) : padicNorm p q ≠ 0 := by
rw [padicNorm.eq_zpow_of_nonzero hq]
apply zpow_ne_zero
exact mod_cast ne_of_gt hp.1.pos
#align padic_norm.nonzero padicNorm.nonzero
/-- If the `p`-adic norm of `q` is 0, then `q` is `0`. -/
theorem zero_of_padicNorm_eq_zero {q : ℚ} (h : padicNorm p q = 0) : q = 0 := by
apply by_contradiction; intro hq
unfold padicNorm at h; rw [if_neg hq] at h
apply absurd h
apply zpow_ne_zero
exact mod_cast hp.1.ne_zero
#align padic_norm.zero_of_padic_norm_eq_zero padicNorm.zero_of_padicNorm_eq_zero
/-- The `p`-adic norm is multiplicative. -/
@[simp]
protected theorem mul (q r : ℚ) : padicNorm p (q * r) = padicNorm p q * padicNorm p r :=
if hq : q = 0 then by simp [hq]
else
if hr : r = 0 then by simp [hr]
else by
have : (p : ℚ) ≠ 0 := by simp [hp.1.ne_zero]
simp [padicNorm, *, padicValRat.mul, zpow_add₀ this, mul_comm]
#align padic_norm.mul padicNorm.mul
/-- The `p`-adic norm respects division. -/
@[simp]
protected theorem div (q r : ℚ) : padicNorm p (q / r) = padicNorm p q / padicNorm p r :=
if hr : r = 0 then by simp [hr]
else eq_div_of_mul_eq (padicNorm.nonzero hr) (by rw [← padicNorm.mul, div_mul_cancel₀ _ hr])
#align padic_norm.div padicNorm.div
/-- The `p`-adic norm of an integer is at most `1`. -/
protected theorem of_int (z : ℤ) : padicNorm p z ≤ 1 :=
if hz : z = 0 then by simp [hz, zero_le_one]
else by
unfold padicNorm
rw [if_neg _]
· refine zpow_le_one_of_nonpos ?_ ?_
· exact mod_cast le_of_lt hp.1.one_lt
· rw [padicValRat.of_int, neg_nonpos]
norm_cast
simp
exact mod_cast hz
#align padic_norm.of_int padicNorm.of_int
private theorem nonarchimedean_aux {q r : ℚ} (h : padicValRat p q ≤ padicValRat p r) :
padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) :=
have hnqp : padicNorm p q ≥ 0 := padicNorm.nonneg _
have hnrp : padicNorm p r ≥ 0 := padicNorm.nonneg _
if hq : q = 0 then by simp [hq, max_eq_right hnrp, le_max_right]
else
if hr : r = 0 then by simp [hr, max_eq_left hnqp, le_max_left]
else
if hqr : q + r = 0 then le_trans (by simpa [hqr] using hnqp) (le_max_left _ _)
else by
unfold padicNorm; split_ifs
apply le_max_iff.2
left
apply zpow_le_of_le
· exact mod_cast le_of_lt hp.1.one_lt
· apply neg_le_neg
have : padicValRat p q = min (padicValRat p q) (padicValRat p r) := (min_eq_left h).symm
rw [this]
exact min_le_padicValRat_add hqr
/-- The `p`-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p`
and the norm of `q`. -/
protected theorem nonarchimedean {q r : ℚ} :
padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) := by
wlog hle : padicValRat p q ≤ padicValRat p r generalizing q r
· rw [add_comm, max_comm]
exact this (le_of_not_le hle)
exact nonarchimedean_aux hle
#align padic_norm.nonarchimedean padicNorm.nonarchimedean
/-- The `p`-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of
`p` plus the norm of `q`. -/
theorem triangle_ineq (q r : ℚ) : padicNorm p (q + r) ≤ padicNorm p q + padicNorm p r :=
calc
padicNorm p (q + r) ≤ max (padicNorm p q) (padicNorm p r) := padicNorm.nonarchimedean
_ ≤ padicNorm p q + padicNorm p r :=
max_le_add_of_nonneg (padicNorm.nonneg _) (padicNorm.nonneg _)
#align padic_norm.triangle_ineq padicNorm.triangle_ineq
/-- The `p`-adic norm of a difference is at most the max of each component. Restates the archimedean
property of the `p`-adic norm. -/
protected theorem sub {q r : ℚ} : padicNorm p (q - r) ≤ max (padicNorm p q) (padicNorm p r) := by
rw [sub_eq_add_neg, ← padicNorm.neg r]
exact padicNorm.nonarchimedean
#align padic_norm.sub padicNorm.sub
/-- If the `p`-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max
of the norms of `q` and `r`. -/
theorem add_eq_max_of_ne {q r : ℚ} (hne : padicNorm p q ≠ padicNorm p r) :
padicNorm p (q + r) = max (padicNorm p q) (padicNorm p r) := by
wlog hlt : padicNorm p r < padicNorm p q
· rw [add_comm, max_comm]
exact this hne.symm (hne.lt_or_lt.resolve_right hlt)
have : padicNorm p q ≤ max (padicNorm p (q + r)) (padicNorm p r) :=
calc
padicNorm p q = padicNorm p (q + r + (-r)) := by ring_nf
_ ≤ max (padicNorm p (q + r)) (padicNorm p (-r)) := padicNorm.nonarchimedean
_ = max (padicNorm p (q + r)) (padicNorm p r) := by simp
have hnge : padicNorm p r ≤ padicNorm p (q + r) := by
apply le_of_not_gt
intro hgt
rw [max_eq_right_of_lt hgt] at this
exact not_lt_of_ge this hlt
have : padicNorm p q ≤ padicNorm p (q + r) := by rwa [max_eq_left hnge] at this
apply _root_.le_antisymm
· apply padicNorm.nonarchimedean
· rwa [max_eq_left_of_lt hlt]
#align padic_norm.add_eq_max_of_ne padicNorm.add_eq_max_of_ne
/-- The `p`-adic norm is an absolute value: positive-definite and multiplicative, satisfying the
triangle inequality. -/
instance : IsAbsoluteValue (padicNorm p) where
abv_nonneg' := padicNorm.nonneg
abv_eq_zero' := ⟨zero_of_padicNorm_eq_zero, fun hx ↦ by simp [hx]⟩
abv_add' := padicNorm.triangle_ineq
abv_mul' := padicNorm.mul
theorem dvd_iff_norm_le {n : ℕ} {z : ℤ} : ↑(p ^ n) ∣ z ↔ padicNorm p z ≤ (p : ℚ) ^ (-n : ℤ) := by
unfold padicNorm; split_ifs with hz
· norm_cast at hz
simp [hz]
· rw [zpow_le_iff_le, neg_le_neg_iff, padicValRat.of_int,
padicValInt.of_ne_one_ne_zero hp.1.ne_one _]
· norm_cast
rw [← PartENat.coe_le_coe, PartENat.natCast_get, ← multiplicity.pow_dvd_iff_le_multiplicity,
Nat.cast_pow]
exact mod_cast hz
· exact mod_cast hp.1.one_lt
#align padic_norm.dvd_iff_norm_le padicNorm.dvd_iff_norm_le
/-- The `p`-adic norm of an integer `m` is one iff `p` doesn't divide `m`. -/
theorem int_eq_one_iff (m : ℤ) : padicNorm p m = 1 ↔ ¬(p : ℤ) ∣ m := by
nth_rw 2 [← pow_one p]
simp only [dvd_iff_norm_le, Int.cast_natCast, Nat.cast_one, zpow_neg, zpow_one, not_le]
constructor
· intro h
rw [h, inv_lt_one_iff_of_pos] <;> norm_cast
· exact Nat.Prime.one_lt Fact.out
· exact Nat.Prime.pos Fact.out
· simp only [padicNorm]
split_ifs
· rw [inv_lt_zero, ← Nat.cast_zero, Nat.cast_lt]
intro h
exact (Nat.not_lt_zero p h).elim
· have : 1 < (p : ℚ) := by norm_cast; exact Nat.Prime.one_lt (Fact.out : Nat.Prime p)
rw [← zpow_neg_one, zpow_lt_iff_lt this]
have : 0 ≤ padicValRat p m := by simp only [of_int, Nat.cast_nonneg]
intro h
rw [← zpow_zero (p : ℚ), zpow_inj] <;> linarith
#align padic_norm.int_eq_one_iff padicNorm.int_eq_one_iff
theorem int_lt_one_iff (m : ℤ) : padicNorm p m < 1 ↔ (p : ℤ) ∣ m := by
rw [← not_iff_not, ← int_eq_one_iff, eq_iff_le_not_lt]
simp only [padicNorm.of_int, true_and_iff]
#align padic_norm.int_lt_one_iff padicNorm.int_lt_one_iff
theorem of_nat (m : ℕ) : padicNorm p m ≤ 1 :=
padicNorm.of_int (m : ℤ)
#align padic_norm.of_nat padicNorm.of_nat
/-- The `p`-adic norm of a natural `m` is one iff `p` doesn't divide `m`. -/
theorem nat_eq_one_iff (m : ℕ) : padicNorm p m = 1 ↔ ¬p ∣ m := by
rw [← Int.natCast_dvd_natCast, ← int_eq_one_iff, Int.cast_natCast]
#align padic_norm.nat_eq_one_iff padicNorm.nat_eq_one_iff
theorem nat_lt_one_iff (m : ℕ) : padicNorm p m < 1 ↔ p ∣ m := by
rw [← Int.natCast_dvd_natCast, ← int_lt_one_iff, Int.cast_natCast]
#align padic_norm.nat_lt_one_iff padicNorm.nat_lt_one_iff
/-- If a rational is not a p-adic integer, it is not an integer. -/
theorem not_int_of_not_padic_int (p : ℕ) {a : ℚ} [hp : Fact (Nat.Prime p)]
(H : 1 < padicNorm p a) : ¬ a.isInt := by
contrapose! H
rw [Rat.eq_num_of_isInt H]
apply padicNorm.of_int
theorem sum_lt {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α} :
s.Nonempty → (∀ i ∈ s, padicNorm p (F i) < t) → padicNorm p (∑ i ∈ s, F i) < t := by
classical
refine s.induction_on (by rintro ⟨-, ⟨⟩⟩) ?_
rintro a S haS IH - ht
by_cases hs : S.Nonempty
· rw [Finset.sum_insert haS]
exact
lt_of_le_of_lt padicNorm.nonarchimedean
(max_lt (ht a (Finset.mem_insert_self a S))
(IH hs fun b hb ↦ ht b (Finset.mem_insert_of_mem hb)))
· simp_all
#align padic_norm.sum_lt padicNorm.sum_lt
theorem sum_le {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α} :
s.Nonempty → (∀ i ∈ s, padicNorm p (F i) ≤ t) → padicNorm p (∑ i ∈ s, F i) ≤ t := by
classical
refine s.induction_on (by rintro ⟨-, ⟨⟩⟩) ?_
rintro a S haS IH - ht
by_cases hs : S.Nonempty
· rw [Finset.sum_insert haS]
exact
padicNorm.nonarchimedean.trans
(max_le (ht a (Finset.mem_insert_self a S))
(IH hs fun b hb ↦ ht b (Finset.mem_insert_of_mem hb)))
· simp_all
#align padic_norm.sum_le padicNorm.sum_le
theorem sum_lt' {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α}
(hF : ∀ i ∈ s, padicNorm p (F i) < t) (ht : 0 < t) : padicNorm p (∑ i ∈ s, F i) < t := by
obtain rfl | hs := Finset.eq_empty_or_nonempty s
· simp [ht]
· exact sum_lt hs hF
#align padic_norm.sum_lt' padicNorm.sum_lt'
| Mathlib/NumberTheory/Padics/PadicNorm.lean | 348 | 352 | theorem sum_le' {α : Type*} {F : α → ℚ} {t : ℚ} {s : Finset α}
(hF : ∀ i ∈ s, padicNorm p (F i) ≤ t) (ht : 0 ≤ t) : padicNorm p (∑ i ∈ s, F i) ≤ t := by |
obtain rfl | hs := Finset.eq_empty_or_nonempty s
· simp [ht]
· exact sum_le hs hF
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Algebra.Hom
import Mathlib.RingTheory.Ideal.Quotient
#align_import algebra.ring_quot from "leanprover-community/mathlib"@"e5820f6c8fcf1b75bcd7738ae4da1c5896191f72"
/-!
# Quotients of non-commutative rings
Unfortunately, ideals have only been developed in the commutative case as `Ideal`,
and it's not immediately clear how one should formalise ideals in the non-commutative case.
In this file, we directly define the quotient of a semiring by any relation,
by building a bigger relation that represents the ideal generated by that relation.
We prove the universal properties of the quotient, and recommend avoiding relying on the actual
definition, which is made irreducible for this purpose.
Since everything runs in parallel for quotients of `R`-algebras, we do that case at the same time.
-/
universe uR uS uT uA u₄
variable {R : Type uR} [Semiring R]
variable {S : Type uS} [CommSemiring S]
variable {T : Type uT}
variable {A : Type uA} [Semiring A] [Algebra S A]
namespace RingCon
instance (c : RingCon A) : Algebra S c.Quotient where
smul := (· • ·)
toRingHom := c.mk'.comp (algebraMap S A)
commutes' _ := Quotient.ind' fun _ ↦ congr_arg Quotient.mk'' <| Algebra.commutes _ _
smul_def' _ := Quotient.ind' fun _ ↦ congr_arg Quotient.mk'' <| Algebra.smul_def _ _
@[simp, norm_cast]
theorem coe_algebraMap (c : RingCon A) (s : S) :
(algebraMap S A s : c.Quotient) = algebraMap S _ s :=
rfl
#align ring_con.coe_algebra_map RingCon.coe_algebraMap
end RingCon
namespace RingQuot
/-- Given an arbitrary relation `r` on a ring, we strengthen it to a relation `Rel r`,
such that the equivalence relation generated by `Rel r` has `x ~ y` if and only if
`x - y` is in the ideal generated by elements `a - b` such that `r a b`.
-/
inductive Rel (r : R → R → Prop) : R → R → Prop
| of ⦃x y : R⦄ (h : r x y) : Rel r x y
| add_left ⦃a b c⦄ : Rel r a b → Rel r (a + c) (b + c)
| mul_left ⦃a b c⦄ : Rel r a b → Rel r (a * c) (b * c)
| mul_right ⦃a b c⦄ : Rel r b c → Rel r (a * b) (a * c)
#align ring_quot.rel RingQuot.Rel
theorem Rel.add_right {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r b c) : Rel r (a + b) (a + c) := by
rw [add_comm a b, add_comm a c]
exact Rel.add_left h
#align ring_quot.rel.add_right RingQuot.Rel.add_right
theorem Rel.neg {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b : R⦄ (h : Rel r a b) :
Rel r (-a) (-b) := by simp only [neg_eq_neg_one_mul a, neg_eq_neg_one_mul b, Rel.mul_right h]
#align ring_quot.rel.neg RingQuot.Rel.neg
theorem Rel.sub_left {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r a b) :
Rel r (a - c) (b - c) := by simp only [sub_eq_add_neg, h.add_left]
#align ring_quot.rel.sub_left RingQuot.Rel.sub_left
theorem Rel.sub_right {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r b c) :
Rel r (a - b) (a - c) := by simp only [sub_eq_add_neg, h.neg.add_right]
#align ring_quot.rel.sub_right RingQuot.Rel.sub_right
theorem Rel.smul {r : A → A → Prop} (k : S) ⦃a b : A⦄ (h : Rel r a b) : Rel r (k • a) (k • b) := by
simp only [Algebra.smul_def, Rel.mul_right h]
#align ring_quot.rel.smul RingQuot.Rel.smul
/-- `EqvGen (RingQuot.Rel r)` is a ring congruence. -/
def ringCon (r : R → R → Prop) : RingCon R where
r := EqvGen (Rel r)
iseqv := EqvGen.is_equivalence _
add' {a b c d} hab hcd := by
induction hab generalizing c d with
| rel _ _ hab =>
refine (EqvGen.rel _ _ hab.add_left).trans _ _ _ ?_
induction hcd with
| rel _ _ hcd => exact EqvGen.rel _ _ hcd.add_right
| refl => exact EqvGen.refl _
| symm _ _ _ h => exact h.symm _ _
| trans _ _ _ _ _ h h' => exact h.trans _ _ _ h'
| refl => induction hcd with
| rel _ _ hcd => exact EqvGen.rel _ _ hcd.add_right
| refl => exact EqvGen.refl _
| symm _ _ _ h => exact h.symm _ _
| trans _ _ _ _ _ h h' => exact h.trans _ _ _ h'
| symm x y _ hxy => exact (hxy hcd.symm).symm
| trans x y z _ _ h h' => exact (h hcd).trans _ _ _ (h' <| EqvGen.refl _)
mul' {a b c d} hab hcd := by
induction hab generalizing c d with
| rel _ _ hab =>
refine (EqvGen.rel _ _ hab.mul_left).trans _ _ _ ?_
induction hcd with
| rel _ _ hcd => exact EqvGen.rel _ _ hcd.mul_right
| refl => exact EqvGen.refl _
| symm _ _ _ h => exact h.symm _ _
| trans _ _ _ _ _ h h' => exact h.trans _ _ _ h'
| refl => induction hcd with
| rel _ _ hcd => exact EqvGen.rel _ _ hcd.mul_right
| refl => exact EqvGen.refl _
| symm _ _ _ h => exact h.symm _ _
| trans _ _ _ _ _ h h' => exact h.trans _ _ _ h'
| symm x y _ hxy => exact (hxy hcd.symm).symm
| trans x y z _ _ h h' => exact (h hcd).trans _ _ _ (h' <| EqvGen.refl _)
#align ring_quot.ring_con RingQuot.ringCon
theorem eqvGen_rel_eq (r : R → R → Prop) : EqvGen (Rel r) = RingConGen.Rel r := by
ext x₁ x₂
constructor
· intro h
induction h with
| rel _ _ h => induction h with
| of => exact RingConGen.Rel.of _ _ ‹_›
| add_left _ h => exact h.add (RingConGen.Rel.refl _)
| mul_left _ h => exact h.mul (RingConGen.Rel.refl _)
| mul_right _ h => exact (RingConGen.Rel.refl _).mul h
| refl => exact RingConGen.Rel.refl _
| symm => exact RingConGen.Rel.symm ‹_›
| trans => exact RingConGen.Rel.trans ‹_› ‹_›
· intro h
induction h with
| of => exact EqvGen.rel _ _ (Rel.of ‹_›)
| refl => exact (RingQuot.ringCon r).refl _
| symm => exact (RingQuot.ringCon r).symm ‹_›
| trans => exact (RingQuot.ringCon r).trans ‹_› ‹_›
| add => exact (RingQuot.ringCon r).add ‹_› ‹_›
| mul => exact (RingQuot.ringCon r).mul ‹_› ‹_›
#align ring_quot.eqv_gen_rel_eq RingQuot.eqvGen_rel_eq
end RingQuot
/-- The quotient of a ring by an arbitrary relation. -/
structure RingQuot (r : R → R → Prop) where
toQuot : Quot (RingQuot.Rel r)
#align ring_quot RingQuot
namespace RingQuot
variable (r : R → R → Prop)
-- can't be irreducible, causes diamonds in ℕ-algebras
private def natCast (n : ℕ) : RingQuot r :=
⟨Quot.mk _ n⟩
private irreducible_def zero : RingQuot r :=
⟨Quot.mk _ 0⟩
private irreducible_def one : RingQuot r :=
⟨Quot.mk _ 1⟩
private irreducible_def add : RingQuot r → RingQuot r → RingQuot r
| ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ (· + ·) Rel.add_right Rel.add_left a b⟩
private irreducible_def mul : RingQuot r → RingQuot r → RingQuot r
| ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ (· * ·) Rel.mul_right Rel.mul_left a b⟩
private irreducible_def neg {R : Type uR} [Ring R] (r : R → R → Prop) : RingQuot r → RingQuot r
| ⟨a⟩ => ⟨Quot.map (fun a ↦ -a) Rel.neg a⟩
private irreducible_def sub {R : Type uR} [Ring R] (r : R → R → Prop) :
RingQuot r → RingQuot r → RingQuot r
| ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ Sub.sub Rel.sub_right Rel.sub_left a b⟩
private irreducible_def npow (n : ℕ) : RingQuot r → RingQuot r
| ⟨a⟩ =>
⟨Quot.lift (fun a ↦ Quot.mk (RingQuot.Rel r) (a ^ n))
(fun a b (h : Rel r a b) ↦ by
-- note we can't define a `Rel.pow` as `Rel` isn't reflexive so `Rel r 1 1` isn't true
dsimp only
induction n with
| zero => rw [pow_zero, pow_zero]
| succ n ih =>
rw [pow_succ, pow_succ]
-- Porting note:
-- `simpa [mul_def] using congr_arg₂ (fun x y ↦ mul r ⟨x⟩ ⟨y⟩) (Quot.sound h) ih`
-- mysteriously doesn't work
have := congr_arg₂ (fun x y ↦ mul r ⟨x⟩ ⟨y⟩) ih (Quot.sound h)
dsimp only at this
simp? [mul_def] at this says simp only [mul_def, Quot.map₂_mk, mk.injEq] at this
exact this)
a⟩
-- note: this cannot be irreducible, as otherwise diamonds don't commute.
private def smul [Algebra S R] (n : S) : RingQuot r → RingQuot r
| ⟨a⟩ => ⟨Quot.map (fun a ↦ n • a) (Rel.smul n) a⟩
instance : NatCast (RingQuot r) :=
⟨natCast r⟩
instance : Zero (RingQuot r) :=
⟨zero r⟩
instance : One (RingQuot r) :=
⟨one r⟩
instance : Add (RingQuot r) :=
⟨add r⟩
instance : Mul (RingQuot r) :=
⟨mul r⟩
instance : NatPow (RingQuot r) :=
⟨fun x n ↦ npow r n x⟩
instance {R : Type uR} [Ring R] (r : R → R → Prop) : Neg (RingQuot r) :=
⟨neg r⟩
instance {R : Type uR} [Ring R] (r : R → R → Prop) : Sub (RingQuot r) :=
⟨sub r⟩
instance [Algebra S R] : SMul S (RingQuot r) :=
⟨smul r⟩
theorem zero_quot : (⟨Quot.mk _ 0⟩ : RingQuot r) = 0 :=
show _ = zero r by rw [zero_def]
#align ring_quot.zero_quot RingQuot.zero_quot
theorem one_quot : (⟨Quot.mk _ 1⟩ : RingQuot r) = 1 :=
show _ = one r by rw [one_def]
#align ring_quot.one_quot RingQuot.one_quot
theorem add_quot {a b} : (⟨Quot.mk _ a⟩ + ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a + b)⟩ := by
show add r _ _ = _
rw [add_def]
rfl
#align ring_quot.add_quot RingQuot.add_quot
theorem mul_quot {a b} : (⟨Quot.mk _ a⟩ * ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a * b)⟩ := by
show mul r _ _ = _
rw [mul_def]
rfl
#align ring_quot.mul_quot RingQuot.mul_quot
theorem pow_quot {a} {n : ℕ} : (⟨Quot.mk _ a⟩ ^ n : RingQuot r) = ⟨Quot.mk _ (a ^ n)⟩ := by
show npow r _ _ = _
rw [npow_def]
#align ring_quot.pow_quot RingQuot.pow_quot
theorem neg_quot {R : Type uR} [Ring R] (r : R → R → Prop) {a} :
(-⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (-a)⟩ := by
show neg r _ = _
rw [neg_def]
rfl
#align ring_quot.neg_quot RingQuot.neg_quot
theorem sub_quot {R : Type uR} [Ring R] (r : R → R → Prop) {a b} :
(⟨Quot.mk _ a⟩ - ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a - b)⟩ := by
show sub r _ _ = _
rw [sub_def]
rfl
#align ring_quot.sub_quot RingQuot.sub_quot
theorem smul_quot [Algebra S R] {n : S} {a : R} :
(n • ⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (n • a)⟩ := by
show smul r _ _ = _
rw [smul]
rfl
#align ring_quot.smul_quot RingQuot.smul_quot
instance instIsScalarTower [CommSemiring T] [SMul S T] [Algebra S R] [Algebra T R]
[IsScalarTower S T R] : IsScalarTower S T (RingQuot r) :=
⟨fun s t ⟨a⟩ => Quot.inductionOn a fun a' => by simp only [RingQuot.smul_quot, smul_assoc]⟩
instance instSMulCommClass [CommSemiring T] [Algebra S R] [Algebra T R] [SMulCommClass S T R] :
SMulCommClass S T (RingQuot r) :=
⟨fun s t ⟨a⟩ => Quot.inductionOn a fun a' => by simp only [RingQuot.smul_quot, smul_comm]⟩
instance instAddCommMonoid (r : R → R → Prop) : AddCommMonoid (RingQuot r) where
add := (· + ·)
zero := 0
add_assoc := by
rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩
simp only [add_quot, add_assoc]
zero_add := by
rintro ⟨⟨⟩⟩
simp [add_quot, ← zero_quot, zero_add]
add_zero := by
rintro ⟨⟨⟩⟩
simp only [add_quot, ← zero_quot, add_zero]
add_comm := by
rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩
simp only [add_quot, add_comm]
nsmul := (· • ·)
nsmul_zero := by
rintro ⟨⟨⟩⟩
simp only [smul_quot, zero_smul, zero_quot]
nsmul_succ := by
rintro n ⟨⟨⟩⟩
simp only [smul_quot, nsmul_eq_mul, Nat.cast_add, Nat.cast_one, add_mul, one_mul,
add_comm, add_quot]
instance instMonoidWithZero (r : R → R → Prop) : MonoidWithZero (RingQuot r) where
mul_assoc := by
rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩
simp only [mul_quot, mul_assoc]
one_mul := by
rintro ⟨⟨⟩⟩
simp only [mul_quot, ← one_quot, one_mul]
mul_one := by
rintro ⟨⟨⟩⟩
simp only [mul_quot, ← one_quot, mul_one]
zero_mul := by
rintro ⟨⟨⟩⟩
simp only [mul_quot, ← zero_quot, zero_mul]
mul_zero := by
rintro ⟨⟨⟩⟩
simp only [mul_quot, ← zero_quot, mul_zero]
npow n x := x ^ n
npow_zero := by
rintro ⟨⟨⟩⟩
simp only [pow_quot, ← one_quot, pow_zero]
npow_succ := by
rintro n ⟨⟨⟩⟩
simp only [pow_quot, mul_quot, pow_succ]
instance instSemiring (r : R → R → Prop) : Semiring (RingQuot r) where
natCast := natCast r
natCast_zero := by simp [Nat.cast, natCast, ← zero_quot]
natCast_succ := by simp [Nat.cast, natCast, ← one_quot, add_quot]
left_distrib := by
rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩
simp only [mul_quot, add_quot, left_distrib]
right_distrib := by
rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨⟨⟩⟩
simp only [mul_quot, add_quot, right_distrib]
nsmul := (· • ·)
nsmul_zero := by
rintro ⟨⟨⟩⟩
simp only [smul_quot, zero_smul, zero_quot]
nsmul_succ := by
rintro n ⟨⟨⟩⟩
simp only [smul_quot, nsmul_eq_mul, Nat.cast_add, Nat.cast_one, add_mul, one_mul,
add_comm, add_quot]
__ := instAddCommMonoid r
__ := instMonoidWithZero r
-- can't be irreducible, causes diamonds in ℤ-algebras
private def intCast {R : Type uR} [Ring R] (r : R → R → Prop) (z : ℤ) : RingQuot r :=
⟨Quot.mk _ z⟩
instance instRing {R : Type uR} [Ring R] (r : R → R → Prop) : Ring (RingQuot r) :=
{ RingQuot.instSemiring r with
neg := Neg.neg
add_left_neg := by
rintro ⟨⟨⟩⟩
simp [neg_quot, add_quot, ← zero_quot]
sub := Sub.sub
sub_eq_add_neg := by
rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩
simp [neg_quot, sub_quot, add_quot, sub_eq_add_neg]
zsmul := (· • ·)
zsmul_zero' := by
rintro ⟨⟨⟩⟩
simp [smul_quot, ← zero_quot]
zsmul_succ' := by
rintro n ⟨⟨⟩⟩
simp [smul_quot, add_quot, add_mul, add_comm]
zsmul_neg' := by
rintro n ⟨⟨⟩⟩
simp [smul_quot, neg_quot, add_mul]
intCast := intCast r
intCast_ofNat := fun n => congrArg RingQuot.mk <| by
exact congrArg (Quot.mk _) (Int.cast_natCast _)
intCast_negSucc := fun n => congrArg RingQuot.mk <| by
simp_rw [neg_def]
exact congrArg (Quot.mk _) (Int.cast_negSucc n) }
instance instCommSemiring {R : Type uR} [CommSemiring R] (r : R → R → Prop) :
CommSemiring (RingQuot r) :=
{ RingQuot.instSemiring r with
mul_comm := by
rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩
simp [mul_quot, mul_comm] }
instance {R : Type uR} [CommRing R] (r : R → R → Prop) : CommRing (RingQuot r) :=
{ RingQuot.instCommSemiring r, RingQuot.instRing r with }
instance instInhabited (r : R → R → Prop) : Inhabited (RingQuot r) :=
⟨0⟩
instance instAlgebra [Algebra S R] (r : R → R → Prop) : Algebra S (RingQuot r) where
smul := (· • ·)
toFun r := ⟨Quot.mk _ (algebraMap S R r)⟩
map_one' := by simp [← one_quot]
map_mul' := by simp [mul_quot]
map_zero' := by simp [← zero_quot]
map_add' := by simp [add_quot]
commutes' r := by
rintro ⟨⟨a⟩⟩
simp [Algebra.commutes, mul_quot]
smul_def' r := by
rintro ⟨⟨a⟩⟩
simp [smul_quot, Algebra.smul_def, mul_quot]
/-- The quotient map from a ring to its quotient, as a homomorphism of rings.
-/
irreducible_def mkRingHom (r : R → R → Prop) : R →+* RingQuot r :=
{ toFun := fun x ↦ ⟨Quot.mk _ x⟩
map_one' := by simp [← one_quot]
map_mul' := by simp [mul_quot]
map_zero' := by simp [← zero_quot]
map_add' := by simp [add_quot] }
#align ring_quot.mk_ring_hom RingQuot.mkRingHom
theorem mkRingHom_rel {r : R → R → Prop} {x y : R} (w : r x y) : mkRingHom r x = mkRingHom r y := by
simp [mkRingHom_def, Quot.sound (Rel.of w)]
#align ring_quot.mk_ring_hom_rel RingQuot.mkRingHom_rel
theorem mkRingHom_surjective (r : R → R → Prop) : Function.Surjective (mkRingHom r) := by
simp only [mkRingHom_def, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk]
rintro ⟨⟨⟩⟩
simp
#align ring_quot.mk_ring_hom_surjective RingQuot.mkRingHom_surjective
@[ext 1100]
theorem ringQuot_ext [Semiring T] {r : R → R → Prop} (f g : RingQuot r →+* T)
(w : f.comp (mkRingHom r) = g.comp (mkRingHom r)) : f = g := by
ext x
rcases mkRingHom_surjective r x with ⟨x, rfl⟩
exact (RingHom.congr_fun w x : _)
#align ring_quot.ring_quot_ext RingQuot.ringQuot_ext
variable [Semiring T]
irreducible_def preLift {r : R → R → Prop} { f : R →+* T } (h : ∀ ⦃x y⦄, r x y → f x = f y) :
RingQuot r →+* T :=
{ toFun := fun x ↦ Quot.lift f
(by
rintro _ _ r
induction r with
| of r => exact h r
| add_left _ r' => rw [map_add, map_add, r']
| mul_left _ r' => rw [map_mul, map_mul, r']
| mul_right _ r' => rw [map_mul, map_mul, r'])
x.toQuot
map_zero' := by simp only [← zero_quot, f.map_zero]
map_add' := by
rintro ⟨⟨x⟩⟩ ⟨⟨y⟩⟩
simp only [add_quot, f.map_add x y]
map_one' := by simp only [← one_quot, f.map_one]
map_mul' := by
rintro ⟨⟨x⟩⟩ ⟨⟨y⟩⟩
simp only [mul_quot, f.map_mul x y] }
/-- Any ring homomorphism `f : R →+* T` which respects a relation `r : R → R → Prop`
factors uniquely through a morphism `RingQuot r →+* T`.
-/
irreducible_def lift {r : R → R → Prop} :
{ f : R →+* T // ∀ ⦃x y⦄, r x y → f x = f y } ≃ (RingQuot r →+* T) :=
{ toFun := fun f ↦ preLift f.prop
invFun := fun F ↦ ⟨F.comp (mkRingHom r), fun x y h ↦ congr_arg F (mkRingHom_rel h)⟩
left_inv := fun f ↦ by
ext
simp only [preLift_def, mkRingHom_def, RingHom.coe_comp, RingHom.coe_mk, MonoidHom.coe_mk,
OneHom.coe_mk, Function.comp_apply]
right_inv := fun F ↦ by
simp only [preLift_def]
ext
simp only [mkRingHom_def, RingHom.coe_comp, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk,
Function.comp_apply, forall_const] }
#align ring_quot.lift RingQuot.lift
@[simp]
theorem lift_mkRingHom_apply (f : R →+* T) {r : R → R → Prop} (w : ∀ ⦃x y⦄, r x y → f x = f y) (x) :
lift ⟨f, w⟩ (mkRingHom r x) = f x := by
simp_rw [lift_def, preLift_def, mkRingHom_def]
rfl
#align ring_quot.lift_mk_ring_hom_apply RingQuot.lift_mkRingHom_apply
-- note this is essentially `lift.symm_apply_eq.mp h`
theorem lift_unique (f : R →+* T) {r : R → R → Prop} (w : ∀ ⦃x y⦄, r x y → f x = f y)
(g : RingQuot r →+* T) (h : g.comp (mkRingHom r) = f) : g = lift ⟨f, w⟩ := by
ext
simp [h]
#align ring_quot.lift_unique RingQuot.lift_unique
theorem eq_lift_comp_mkRingHom {r : R → R → Prop} (f : RingQuot r →+* T) :
f = lift ⟨f.comp (mkRingHom r), fun x y h ↦ congr_arg f (mkRingHom_rel h)⟩ := by
conv_lhs => rw [← lift.apply_symm_apply f]
rw [lift_def]
rfl
#align ring_quot.eq_lift_comp_mk_ring_hom RingQuot.eq_lift_comp_mkRingHom
section CommRing
/-!
We now verify that in the case of a commutative ring, the `RingQuot` construction
agrees with the quotient by the appropriate ideal.
-/
variable {B : Type uR} [CommRing B]
/-- The universal ring homomorphism from `RingQuot r` to `B ⧸ Ideal.ofRel r`. -/
def ringQuotToIdealQuotient (r : B → B → Prop) : RingQuot r →+* B ⧸ Ideal.ofRel r :=
lift ⟨Ideal.Quotient.mk (Ideal.ofRel r),
fun x y h ↦ Ideal.Quotient.eq.2 <| Submodule.mem_sInf.mpr
fun _ w ↦ w ⟨x, y, h, sub_add_cancel x y⟩⟩
#align ring_quot.ring_quot_to_ideal_quotient RingQuot.ringQuotToIdealQuotient
@[simp]
theorem ringQuotToIdealQuotient_apply (r : B → B → Prop) (x : B) :
ringQuotToIdealQuotient r (mkRingHom r x) = Ideal.Quotient.mk (Ideal.ofRel r) x := by
simp_rw [ringQuotToIdealQuotient, lift_def, preLift_def, mkRingHom_def]
rfl
#align ring_quot.ring_quot_to_ideal_quotient_apply RingQuot.ringQuotToIdealQuotient_apply
/-- The universal ring homomorphism from `B ⧸ Ideal.ofRel r` to `RingQuot r`. -/
def idealQuotientToRingQuot (r : B → B → Prop) : B ⧸ Ideal.ofRel r →+* RingQuot r :=
Ideal.Quotient.lift (Ideal.ofRel r) (mkRingHom r)
(by
refine fun x h ↦ Submodule.span_induction h ?_ ?_ ?_ ?_
· rintro y ⟨a, b, h, su⟩
symm at su
rw [← sub_eq_iff_eq_add] at su
rw [← su, RingHom.map_sub, mkRingHom_rel h, sub_self]
· simp
· intro a b ha hb
simp [ha, hb]
· intro a x hx
simp [hx])
#align ring_quot.ideal_quotient_to_ring_quot RingQuot.idealQuotientToRingQuot
@[simp]
theorem idealQuotientToRingQuot_apply (r : B → B → Prop) (x : B) :
idealQuotientToRingQuot r (Ideal.Quotient.mk _ x) = mkRingHom r x :=
rfl
#align ring_quot.ideal_quotient_to_ring_quot_apply RingQuot.idealQuotientToRingQuot_apply
/-- The ring equivalence between `RingQuot r` and `(Ideal.ofRel r).quotient`
-/
def ringQuotEquivIdealQuotient (r : B → B → Prop) : RingQuot r ≃+* B ⧸ Ideal.ofRel r :=
RingEquiv.ofHomInv (ringQuotToIdealQuotient r) (idealQuotientToRingQuot r)
(by
ext x
simp_rw [ringQuotToIdealQuotient, lift_def, preLift_def, mkRingHom_def]
change mkRingHom r x = _
rw [mkRingHom_def]
rfl)
(by
ext x
simp_rw [ringQuotToIdealQuotient, lift_def, preLift_def, mkRingHom_def]
change Quot.lift _ _ ((mkRingHom r) x).toQuot = _
rw [mkRingHom_def]
rfl)
#align ring_quot.ring_quot_equiv_ideal_quotient RingQuot.ringQuotEquivIdealQuotient
end CommRing
section StarRing
variable [StarRing R] (hr : ∀ a b, r a b → r (star a) (star b))
theorem Rel.star ⦃a b : R⦄ (h : Rel r a b) : Rel r (star a) (star b) := by
induction h with
| of h => exact Rel.of (hr _ _ h)
| add_left _ h => rw [star_add, star_add]
exact Rel.add_left h
| mul_left _ h => rw [star_mul, star_mul]
exact Rel.mul_right h
| mul_right _ h => rw [star_mul, star_mul]
exact Rel.mul_left h
#align ring_quot.rel.star RingQuot.Rel.star
private irreducible_def star' : RingQuot r → RingQuot r
| ⟨a⟩ => ⟨Quot.map (star : R → R) (Rel.star r hr) a⟩
theorem star'_quot (hr : ∀ a b, r a b → r (star a) (star b)) {a} :
(star' r hr ⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (star a)⟩ := star'_def _ _ _
#align ring_quot.star'_quot RingQuot.star'_quot
/-- Transfer a star_ring instance through a quotient, if the quotient is invariant to `star` -/
def starRing {R : Type uR} [Semiring R] [StarRing R] (r : R → R → Prop)
(hr : ∀ a b, r a b → r (star a) (star b)) : StarRing (RingQuot r) where
star := star' r hr
star_involutive := by
rintro ⟨⟨⟩⟩
simp [star'_quot]
star_mul := by
rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩
simp [star'_quot, mul_quot, star_mul]
star_add := by
rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩
simp [star'_quot, add_quot, star_add]
#align ring_quot.star_ring RingQuot.starRing
end StarRing
section Algebra
variable (S)
/-- The quotient map from an `S`-algebra to its quotient, as a homomorphism of `S`-algebras.
-/
irreducible_def mkAlgHom (s : A → A → Prop) : A →ₐ[S] RingQuot s :=
{ mkRingHom s with
commutes' := fun _ ↦ by simp [mkRingHom_def]; rfl }
#align ring_quot.mk_alg_hom RingQuot.mkAlgHom
@[simp]
| Mathlib/Algebra/RingQuot.lean | 616 | 618 | theorem mkAlgHom_coe (s : A → A → Prop) : (mkAlgHom S s : A →+* RingQuot s) = mkRingHom s := by |
simp_rw [mkAlgHom_def, mkRingHom_def]
rfl
|
/-
Copyright (c) 2022 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.Group.Measure
/-!
# Lebesgue Integration on Groups
We develop properties of integrals with a group as domain.
This file contains properties about Lebesgue integration.
-/
assert_not_exists NormedSpace
namespace MeasureTheory
open Measure TopologicalSpace
open scoped ENNReal
variable {G : Type*} [MeasurableSpace G] {μ : Measure G} {g : G}
section MeasurableMul
variable [Group G] [MeasurableMul G]
/-- Translating a function by left-multiplication does not change its Lebesgue integral
with respect to a left-invariant measure. -/
@[to_additive
"Translating a function by left-addition does not change its Lebesgue integral with
respect to a left-invariant measure."]
theorem lintegral_mul_left_eq_self [IsMulLeftInvariant μ] (f : G → ℝ≥0∞) (g : G) :
(∫⁻ x, f (g * x) ∂μ) = ∫⁻ x, f x ∂μ := by
convert (lintegral_map_equiv f <| MeasurableEquiv.mulLeft g).symm
simp [map_mul_left_eq_self μ g]
#align measure_theory.lintegral_mul_left_eq_self MeasureTheory.lintegral_mul_left_eq_self
#align measure_theory.lintegral_add_left_eq_self MeasureTheory.lintegral_add_left_eq_self
/-- Translating a function by right-multiplication does not change its Lebesgue integral
with respect to a right-invariant measure. -/
@[to_additive
"Translating a function by right-addition does not change its Lebesgue integral with
respect to a right-invariant measure."]
| Mathlib/MeasureTheory/Group/LIntegral.lean | 46 | 49 | theorem lintegral_mul_right_eq_self [IsMulRightInvariant μ] (f : G → ℝ≥0∞) (g : G) :
(∫⁻ x, f (x * g) ∂μ) = ∫⁻ x, f x ∂μ := by |
convert (lintegral_map_equiv f <| MeasurableEquiv.mulRight g).symm using 1
simp [map_mul_right_eq_self μ g]
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Devon Tuma
-/
import Mathlib.Topology.Instances.ENNReal
import Mathlib.MeasureTheory.Measure.Dirac
#align_import probability.probability_mass_function.basic from "leanprover-community/mathlib"@"4ac69b290818724c159de091daa3acd31da0ee6d"
/-!
# Probability mass functions
This file is about probability mass functions or discrete probability measures:
a function `α → ℝ≥0∞` such that the values have (infinite) sum `1`.
Construction of monadic `pure` and `bind` is found in `ProbabilityMassFunction/Monad.lean`,
other constructions of `PMF`s are found in `ProbabilityMassFunction/Constructions.lean`.
Given `p : PMF α`, `PMF.toOuterMeasure` constructs an `OuterMeasure` on `α`,
by assigning each set the sum of the probabilities of each of its elements.
Under this outer measure, every set is Carathéodory-measurable,
so we can further extend this to a `Measure` on `α`, see `PMF.toMeasure`.
`PMF.toMeasure.isProbabilityMeasure` shows this associated measure is a probability measure.
Conversely, given a probability measure `μ` on a measurable space `α` with all singleton sets
measurable, `μ.toPMF` constructs a `PMF` on `α`, setting the probability mass of a point `x`
to be the measure of the singleton set `{x}`.
## Tags
probability mass function, discrete probability measure
-/
noncomputable section
variable {α β γ : Type*}
open scoped Classical
open NNReal ENNReal MeasureTheory
/-- A probability mass function, or discrete probability measures is a function `α → ℝ≥0∞` such
that the values have (infinite) sum `1`. -/
def PMF.{u} (α : Type u) : Type u :=
{ f : α → ℝ≥0∞ // HasSum f 1 }
#align pmf PMF
namespace PMF
instance instFunLike : FunLike (PMF α) α ℝ≥0∞ where
coe p a := p.1 a
coe_injective' _ _ h := Subtype.eq h
#align pmf.fun_like PMF.instFunLike
@[ext]
protected theorem ext {p q : PMF α} (h : ∀ x, p x = q x) : p = q :=
DFunLike.ext p q h
#align pmf.ext PMF.ext
theorem ext_iff {p q : PMF α} : p = q ↔ ∀ x, p x = q x :=
DFunLike.ext_iff
#align pmf.ext_iff PMF.ext_iff
theorem hasSum_coe_one (p : PMF α) : HasSum p 1 :=
p.2
#align pmf.has_sum_coe_one PMF.hasSum_coe_one
@[simp]
theorem tsum_coe (p : PMF α) : ∑' a, p a = 1 :=
p.hasSum_coe_one.tsum_eq
#align pmf.tsum_coe PMF.tsum_coe
theorem tsum_coe_ne_top (p : PMF α) : ∑' a, p a ≠ ∞ :=
p.tsum_coe.symm ▸ ENNReal.one_ne_top
#align pmf.tsum_coe_ne_top PMF.tsum_coe_ne_top
theorem tsum_coe_indicator_ne_top (p : PMF α) (s : Set α) : ∑' a, s.indicator p a ≠ ∞ :=
ne_of_lt (lt_of_le_of_lt
(tsum_le_tsum (fun _ => Set.indicator_apply_le fun _ => le_rfl) ENNReal.summable
ENNReal.summable)
(lt_of_le_of_ne le_top p.tsum_coe_ne_top))
#align pmf.tsum_coe_indicator_ne_top PMF.tsum_coe_indicator_ne_top
@[simp]
theorem coe_ne_zero (p : PMF α) : ⇑p ≠ 0 := fun hp =>
zero_ne_one ((tsum_zero.symm.trans (tsum_congr fun x => symm (congr_fun hp x))).trans p.tsum_coe)
#align pmf.coe_ne_zero PMF.coe_ne_zero
/-- The support of a `PMF` is the set where it is nonzero. -/
def support (p : PMF α) : Set α :=
Function.support p
#align pmf.support PMF.support
@[simp]
theorem mem_support_iff (p : PMF α) (a : α) : a ∈ p.support ↔ p a ≠ 0 := Iff.rfl
#align pmf.mem_support_iff PMF.mem_support_iff
@[simp]
theorem support_nonempty (p : PMF α) : p.support.Nonempty :=
Function.support_nonempty_iff.2 p.coe_ne_zero
#align pmf.support_nonempty PMF.support_nonempty
@[simp]
theorem support_countable (p : PMF α) : p.support.Countable :=
Summable.countable_support_ennreal (tsum_coe_ne_top p)
theorem apply_eq_zero_iff (p : PMF α) (a : α) : p a = 0 ↔ a ∉ p.support := by
rw [mem_support_iff, Classical.not_not]
#align pmf.apply_eq_zero_iff PMF.apply_eq_zero_iff
theorem apply_pos_iff (p : PMF α) (a : α) : 0 < p a ↔ a ∈ p.support :=
pos_iff_ne_zero.trans (p.mem_support_iff a).symm
#align pmf.apply_pos_iff PMF.apply_pos_iff
theorem apply_eq_one_iff (p : PMF α) (a : α) : p a = 1 ↔ p.support = {a} := by
refine ⟨fun h => Set.Subset.antisymm (fun a' ha' => by_contra fun ha => ?_)
fun a' ha' => ha'.symm ▸ (p.mem_support_iff a).2 fun ha => zero_ne_one <| ha.symm.trans h,
fun h => _root_.trans (symm <| tsum_eq_single a
fun a' ha' => (p.apply_eq_zero_iff a').2 (h.symm ▸ ha')) p.tsum_coe⟩
suffices 1 < ∑' a, p a from ne_of_lt this p.tsum_coe.symm
have : 0 < ∑' b, ite (b = a) 0 (p b) := lt_of_le_of_ne' zero_le'
((tsum_ne_zero_iff ENNReal.summable).2
⟨a', ite_ne_left_iff.2 ⟨ha, Ne.symm <| (p.mem_support_iff a').2 ha'⟩⟩)
calc
1 = 1 + 0 := (add_zero 1).symm
_ < p a + ∑' b, ite (b = a) 0 (p b) :=
(ENNReal.add_lt_add_of_le_of_lt ENNReal.one_ne_top (le_of_eq h.symm) this)
_ = ite (a = a) (p a) 0 + ∑' b, ite (b = a) 0 (p b) := by rw [eq_self_iff_true, if_true]
_ = (∑' b, ite (b = a) (p b) 0) + ∑' b, ite (b = a) 0 (p b) := by
congr
exact symm (tsum_eq_single a fun b hb => if_neg hb)
_ = ∑' b, (ite (b = a) (p b) 0 + ite (b = a) 0 (p b)) := ENNReal.tsum_add.symm
_ = ∑' b, p b := tsum_congr fun b => by split_ifs <;> simp only [zero_add, add_zero, le_rfl]
#align pmf.apply_eq_one_iff PMF.apply_eq_one_iff
| Mathlib/Probability/ProbabilityMassFunction/Basic.lean | 136 | 138 | theorem coe_le_one (p : PMF α) (a : α) : p a ≤ 1 := by |
refine hasSum_le (fun b => ?_) (hasSum_ite_eq a (p a)) (hasSum_coe_one p)
split_ifs with h <;> simp only [h, zero_le', le_rfl]
|
/-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky, Chris Hughes
-/
import Mathlib.Data.List.Nodup
#align_import data.list.duplicate from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e"
/-!
# List duplicates
## Main definitions
* `List.Duplicate x l : Prop` is an inductive property that holds when `x` is a duplicate in `l`
## Implementation details
In this file, `x ∈+ l` notation is shorthand for `List.Duplicate x l`.
-/
variable {α : Type*}
namespace List
/-- Property that an element `x : α` of `l : List α` can be found in the list more than once. -/
inductive Duplicate (x : α) : List α → Prop
| cons_mem {l : List α} : x ∈ l → Duplicate x (x :: l)
| cons_duplicate {y : α} {l : List α} : Duplicate x l → Duplicate x (y :: l)
#align list.duplicate List.Duplicate
local infixl:50 " ∈+ " => List.Duplicate
variable {l : List α} {x : α}
theorem Mem.duplicate_cons_self (h : x ∈ l) : x ∈+ x :: l :=
Duplicate.cons_mem h
#align list.mem.duplicate_cons_self List.Mem.duplicate_cons_self
theorem Duplicate.duplicate_cons (h : x ∈+ l) (y : α) : x ∈+ y :: l :=
Duplicate.cons_duplicate h
#align list.duplicate.duplicate_cons List.Duplicate.duplicate_cons
theorem Duplicate.mem (h : x ∈+ l) : x ∈ l := by
induction' h with l' _ y l' _ hm
· exact mem_cons_self _ _
· exact mem_cons_of_mem _ hm
#align list.duplicate.mem List.Duplicate.mem
theorem Duplicate.mem_cons_self (h : x ∈+ x :: l) : x ∈ l := by
cases' h with _ h _ _ h
· exact h
· exact h.mem
#align list.duplicate.mem_cons_self List.Duplicate.mem_cons_self
@[simp]
theorem duplicate_cons_self_iff : x ∈+ x :: l ↔ x ∈ l :=
⟨Duplicate.mem_cons_self, Mem.duplicate_cons_self⟩
#align list.duplicate_cons_self_iff List.duplicate_cons_self_iff
theorem Duplicate.ne_nil (h : x ∈+ l) : l ≠ [] := fun H => (mem_nil_iff x).mp (H ▸ h.mem)
#align list.duplicate.ne_nil List.Duplicate.ne_nil
@[simp]
theorem not_duplicate_nil (x : α) : ¬x ∈+ [] := fun H => H.ne_nil rfl
#align list.not_duplicate_nil List.not_duplicate_nil
theorem Duplicate.ne_singleton (h : x ∈+ l) (y : α) : l ≠ [y] := by
induction' h with l' h z l' h _
· simp [ne_nil_of_mem h]
· simp [ne_nil_of_mem h.mem]
#align list.duplicate.ne_singleton List.Duplicate.ne_singleton
@[simp]
theorem not_duplicate_singleton (x y : α) : ¬x ∈+ [y] := fun H => H.ne_singleton _ rfl
#align list.not_duplicate_singleton List.not_duplicate_singleton
theorem Duplicate.elim_nil (h : x ∈+ []) : False :=
not_duplicate_nil x h
#align list.duplicate.elim_nil List.Duplicate.elim_nil
theorem Duplicate.elim_singleton {y : α} (h : x ∈+ [y]) : False :=
not_duplicate_singleton x y h
#align list.duplicate.elim_singleton List.Duplicate.elim_singleton
theorem duplicate_cons_iff {y : α} : x ∈+ y :: l ↔ y = x ∧ x ∈ l ∨ x ∈+ l := by
refine ⟨fun h => ?_, fun h => ?_⟩
· cases' h with _ hm _ _ hm
· exact Or.inl ⟨rfl, hm⟩
· exact Or.inr hm
· rcases h with (⟨rfl | h⟩ | h)
· simpa
· exact h.cons_duplicate
#align list.duplicate_cons_iff List.duplicate_cons_iff
| Mathlib/Data/List/Duplicate.lean | 98 | 99 | theorem Duplicate.of_duplicate_cons {y : α} (h : x ∈+ y :: l) (hx : x ≠ y) : x ∈+ l := by |
simpa [duplicate_cons_iff, hx.symm] using h
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Algebra.BigOperators.GroupWithZero.Finset
import Mathlib.Algebra.BigOperators.Ring.Multiset
import Mathlib.Algebra.Field.Defs
import Mathlib.Data.Fintype.Powerset
import Mathlib.Data.Int.Cast.Lemmas
#align_import algebra.big_operators.ring from "leanprover-community/mathlib"@"b2c89893177f66a48daf993b7ba5ef7cddeff8c9"
/-!
# Results about big operators with values in a (semi)ring
We prove results about big operators that involve some interaction between
multiplicative and additive structures on the values being combined.
-/
open Fintype
variable {ι α β γ : Type*} {κ : ι → Type*} {s s₁ s₂ : Finset ι} {i : ι} {a : α} {f g : ι → α}
#align monoid_hom.map_prod map_prod
#align add_monoid_hom.map_sum map_sum
#align mul_equiv.map_prod map_prod
#align add_equiv.map_sum map_sum
#align ring_hom.map_list_prod map_list_prod
#align ring_hom.map_list_sum map_list_sum
#align ring_hom.unop_map_list_prod unop_map_list_prod
#align ring_hom.map_multiset_prod map_multiset_prod
#align ring_hom.map_multiset_sum map_multiset_sum
#align ring_hom.map_prod map_prod
#align ring_hom.map_sum map_sum
namespace Finset
section AddCommMonoidWithOne
variable [AddCommMonoidWithOne α]
lemma natCast_card_filter (p) [DecidablePred p] (s : Finset ι) :
((filter p s).card : α) = ∑ a ∈ s, if p a then (1 : α) else 0 := by
rw [sum_ite, sum_const_zero, add_zero, sum_const, nsmul_one]
#align finset.nat_cast_card_filter Finset.natCast_card_filter
@[simp] lemma sum_boole (p) [DecidablePred p] (s : Finset ι) :
(∑ x ∈ s, if p x then 1 else 0 : α) = (s.filter p).card :=
(natCast_card_filter _ _).symm
#align finset.sum_boole Finset.sum_boole
end AddCommMonoidWithOne
section NonUnitalNonAssocSemiring
variable [NonUnitalNonAssocSemiring α]
lemma sum_mul (s : Finset ι) (f : ι → α) (a : α) :
(∑ i ∈ s, f i) * a = ∑ i ∈ s, f i * a := map_sum (AddMonoidHom.mulRight a) _ s
#align finset.sum_mul Finset.sum_mul
lemma mul_sum (s : Finset ι) (f : ι → α) (a : α) :
a * ∑ i ∈ s, f i = ∑ i ∈ s, a * f i := map_sum (AddMonoidHom.mulLeft a) _ s
#align finset.mul_sum Finset.mul_sum
lemma sum_mul_sum {κ : Type*} (s : Finset ι) (t : Finset κ) (f : ι → α) (g : κ → α) :
(∑ i ∈ s, f i) * ∑ j ∈ t, g j = ∑ i ∈ s, ∑ j ∈ t, f i * g j := by
simp_rw [sum_mul, ← mul_sum]
#align finset.sum_mul_sum Finset.sum_mul_sum
lemma _root_.Commute.sum_right [NonUnitalNonAssocSemiring α] (s : Finset ι) (f : ι → α) (b : α)
(h : ∀ i ∈ s, Commute b (f i)) : Commute b (∑ i ∈ s, f i) :=
(Commute.multiset_sum_right _ _) fun b hb => by
obtain ⟨i, hi, rfl⟩ := Multiset.mem_map.mp hb
exact h _ hi
#align commute.sum_right Commute.sum_right
lemma _root_.Commute.sum_left [NonUnitalNonAssocSemiring α] (s : Finset ι) (f : ι → α) (b : α)
(h : ∀ i ∈ s, Commute (f i) b) : Commute (∑ i ∈ s, f i) b :=
((Commute.sum_right _ _ _) fun _i hi => (h _ hi).symm).symm
#align commute.sum_left Commute.sum_left
lemma sum_range_succ_mul_sum_range_succ (m n : ℕ) (f g : ℕ → α) :
(∑ i ∈ range (m + 1), f i) * ∑ i ∈ range (n + 1), g i =
(∑ i ∈ range m, f i) * ∑ i ∈ range n, g i +
f m * ∑ i ∈ range n, g i + (∑ i ∈ range m, f i) * g n + f m * g n := by
simp only [add_mul, mul_add, add_assoc, sum_range_succ]
#align finset.sum_range_succ_mul_sum_range_succ Finset.sum_range_succ_mul_sum_range_succ
end NonUnitalNonAssocSemiring
section NonUnitalSemiring
variable [NonUnitalSemiring α]
lemma dvd_sum (h : ∀ i ∈ s, a ∣ f i) : a ∣ ∑ i ∈ s, f i :=
Multiset.dvd_sum fun y hy => by rcases Multiset.mem_map.1 hy with ⟨x, hx, rfl⟩; exact h x hx
#align finset.dvd_sum Finset.dvd_sum
end NonUnitalSemiring
section NonAssocSemiring
variable [NonAssocSemiring α] [DecidableEq ι]
lemma sum_mul_boole (s : Finset ι) (f : ι → α) (i : ι) :
∑ j ∈ s, f j * ite (i = j) 1 0 = ite (i ∈ s) (f i) 0 := by simp
#align finset.sum_mul_boole Finset.sum_mul_boole
lemma sum_boole_mul (s : Finset ι) (f : ι → α) (i : ι) :
∑ j ∈ s, ite (i = j) 1 0 * f i = ite (i ∈ s) (f i) 0 := by simp
#align finset.sum_boole_mul Finset.sum_boole_mul
end NonAssocSemiring
section CommSemiring
variable [CommSemiring α]
/-- If `f = g = h` everywhere but at `i`, where `f i = g i + h i`, then the product of `f` over `s`
is the sum of the products of `g` and `h`. -/
theorem prod_add_prod_eq {s : Finset ι} {i : ι} {f g h : ι → α} (hi : i ∈ s)
(h1 : g i + h i = f i) (h2 : ∀ j ∈ s, j ≠ i → g j = f j) (h3 : ∀ j ∈ s, j ≠ i → h j = f j) :
(∏ i ∈ s, g i) + ∏ i ∈ s, h i = ∏ i ∈ s, f i := by
classical
simp_rw [prod_eq_mul_prod_diff_singleton hi, ← h1, right_distrib]
congr 2 <;> apply prod_congr rfl <;> simpa
#align finset.prod_add_prod_eq Finset.prod_add_prod_eq
section DecidableEq
variable [DecidableEq ι]
/-- The product over a sum can be written as a sum over the product of sets, `Finset.Pi`.
`Finset.prod_univ_sum` is an alternative statement when the product is over `univ`. -/
lemma prod_sum (s : Finset ι) (t : ∀ i, Finset (κ i)) (f : ∀ i, κ i → α) :
∏ a ∈ s, ∑ b ∈ t a, f a b = ∑ p ∈ s.pi t, ∏ x ∈ s.attach, f x.1 (p x.1 x.2) := by
classical
induction' s using Finset.induction with a s ha ih
· rw [pi_empty, sum_singleton]
rfl
· have h₁ : ∀ x ∈ t a, ∀ y ∈ t a, x ≠ y →
Disjoint (image (Pi.cons s a x) (pi s t)) (image (Pi.cons s a y) (pi s t)) := by
intro x _ y _ h
simp only [disjoint_iff_ne, mem_image]
rintro _ ⟨p₂, _, eq₂⟩ _ ⟨p₃, _, eq₃⟩ eq
have : Pi.cons s a x p₂ a (mem_insert_self _ _)
= Pi.cons s a y p₃ a (mem_insert_self _ _) := by rw [eq₂, eq₃, eq]
rw [Pi.cons_same, Pi.cons_same] at this
exact h this
rw [prod_insert ha, pi_insert ha, ih, sum_mul, sum_biUnion h₁]
refine sum_congr rfl fun b _ => ?_
have h₂ : ∀ p₁ ∈ pi s t, ∀ p₂ ∈ pi s t, Pi.cons s a b p₁ = Pi.cons s a b p₂ → p₁ = p₂ :=
fun p₁ _ p₂ _ eq => Pi.cons_injective ha eq
rw [sum_image h₂, mul_sum]
refine sum_congr rfl fun g _ => ?_
rw [attach_insert, prod_insert, prod_image]
· simp only [Pi.cons_same]
congr with ⟨v, hv⟩
congr
exact (Pi.cons_ne (by rintro rfl; exact ha hv)).symm
· exact fun _ _ _ _ => Subtype.eq ∘ Subtype.mk.inj
· simpa only [mem_image, mem_attach, Subtype.mk.injEq, true_and,
Subtype.exists, exists_prop, exists_eq_right] using ha
#align finset.prod_sum Finset.prod_sum
/-- The product over `univ` of a sum can be written as a sum over the product of sets,
`Fintype.piFinset`. `Finset.prod_sum` is an alternative statement when the product is not
over `univ`. -/
lemma prod_univ_sum [Fintype ι] (t : ∀ i, Finset (κ i)) (f : ∀ i, κ i → α) :
∏ i, ∑ j ∈ t i, f i j = ∑ x ∈ piFinset t, ∏ i, f i (x i) := by
simp only [prod_attach_univ, prod_sum, Finset.sum_univ_pi]
#align finset.prod_univ_sum Finset.prod_univ_sum
lemma sum_prod_piFinset {κ : Type*} [Fintype ι] (s : Finset κ) (g : ι → κ → α) :
∑ f ∈ piFinset fun _ : ι ↦ s, ∏ i, g i (f i) = ∏ i, ∑ j ∈ s, g i j := by
rw [← prod_univ_sum]
lemma sum_pow' (s : Finset ι) (f : ι → α) (n : ℕ) :
(∑ a ∈ s, f a) ^ n = ∑ p ∈ piFinset fun _i : Fin n ↦ s, ∏ i, f (p i) := by
convert @prod_univ_sum (Fin n) _ _ _ _ _ (fun _i ↦ s) fun _i d ↦ f d; simp
/-- The product of `f a + g a` over all of `s` is the sum over the powerset of `s` of the product of
`f` over a subset `t` times the product of `g` over the complement of `t` -/
theorem prod_add (f g : ι → α) (s : Finset ι) :
∏ i ∈ s, (f i + g i) = ∑ t ∈ s.powerset, (∏ i ∈ t, f i) * ∏ i ∈ s \ t, g i := by
classical
calc
∏ i ∈ s, (f i + g i) =
∏ i ∈ s, ∑ p ∈ ({True, False} : Finset Prop), if p then f i else g i := by simp
_ = ∑ p ∈ (s.pi fun _ => {True, False} : Finset (∀ a ∈ s, Prop)),
∏ a ∈ s.attach, if p a.1 a.2 then f a.1 else g a.1 := prod_sum _ _ _
_ = ∑ t ∈ s.powerset, (∏ a ∈ t, f a) * ∏ a ∈ s \ t, g a :=
sum_bij'
(fun f _ ↦ s.filter fun a ↦ ∃ h : a ∈ s, f a h)
(fun t _ a _ => a ∈ t)
(by simp)
(by simp [Classical.em])
(by simp_rw [mem_filter, Function.funext_iff, eq_iff_iff, mem_pi, mem_insert]; tauto)
(by simp_rw [ext_iff, @mem_filter _ _ (id _), mem_powerset]; tauto)
(fun a _ ↦ by
simp only [prod_ite, filter_attach', prod_map, Function.Embedding.coeFn_mk,
Subtype.map_coe, id_eq, prod_attach, filter_congr_decidable]
congr 2 with x
simp only [mem_filter, mem_sdiff, not_and, not_exists, and_congr_right_iff]
tauto)
#align finset.prod_add Finset.prod_add
end DecidableEq
/-- `∏ i, (f i + g i) = (∏ i, f i) + ∑ i, g i * (∏ j < i, f j + g j) * (∏ j > i, f j)`. -/
theorem prod_add_ordered [LinearOrder ι] [CommSemiring α] (s : Finset ι) (f g : ι → α) :
∏ i ∈ s, (f i + g i) =
(∏ i ∈ s, f i) +
∑ i ∈ s,
g i * (∏ j ∈ s.filter (· < i), (f j + g j)) * ∏ j ∈ s.filter fun j => i < j, f j := by
refine Finset.induction_on_max s (by simp) ?_
clear s
intro a s ha ihs
have ha' : a ∉ s := fun ha' => lt_irrefl a (ha a ha')
rw [prod_insert ha', prod_insert ha', sum_insert ha', filter_insert, if_neg (lt_irrefl a),
filter_true_of_mem ha, ihs, add_mul, mul_add, mul_add, add_assoc]
congr 1
rw [add_comm]
congr 1
· rw [filter_false_of_mem, prod_empty, mul_one]
exact (forall_mem_insert _ _ _).2 ⟨lt_irrefl a, fun i hi => (ha i hi).not_lt⟩
· rw [mul_sum]
refine sum_congr rfl fun i hi => ?_
rw [filter_insert, if_neg (ha i hi).not_lt, filter_insert, if_pos (ha i hi), prod_insert,
mul_left_comm]
exact mt (fun ha => (mem_filter.1 ha).1) ha'
#align finset.prod_add_ordered Finset.prod_add_ordered
/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a `Finset`
gives `(a + b)^s.card`. -/
| Mathlib/Algebra/BigOperators/Ring.lean | 232 | 237 | theorem sum_pow_mul_eq_add_pow (a b : α) (s : Finset ι) :
(∑ t ∈ s.powerset, a ^ t.card * b ^ (s.card - t.card)) = (a + b) ^ s.card := by |
classical
rw [← prod_const, prod_add]
refine Finset.sum_congr rfl fun t ht => ?_
rw [prod_const, prod_const, ← card_sdiff (mem_powerset.1 ht)]
|
/-
Copyright (c) 2021 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.Algebra.Group.Subgroup.Pointwise
import Mathlib.Data.Set.Basic
import Mathlib.Data.Setoid.Basic
import Mathlib.GroupTheory.Coset
#align_import group_theory.double_coset from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514"
/-!
# Double cosets
This file defines double cosets for two subgroups `H K` of a group `G` and the quotient of `G` by
the double coset relation, i.e. `H \ G / K`. We also prove that `G` can be written as a disjoint
union of the double cosets and that if one of `H` or `K` is the trivial group (i.e. `⊥` ) then
this is the usual left or right quotient of a group by a subgroup.
## Main definitions
* `rel`: The double coset relation defined by two subgroups `H K` of `G`.
* `Doset.quotient`: The quotient of `G` by the double coset relation, i.e, `H \ G / K`.
-/
-- Porting note: removed import
-- import Mathlib.Tactic.Group
variable {G : Type*} [Group G] {α : Type*} [Mul α] (J : Subgroup G) (g : G)
open MulOpposite
open scoped Pointwise
namespace Doset
/-- The double coset as an element of `Set α` corresponding to `s a t` -/
def doset (a : α) (s t : Set α) : Set α :=
s * {a} * t
#align doset Doset.doset
lemma doset_eq_image2 (a : α) (s t : Set α) : doset a s t = Set.image2 (· * a * ·) s t := by
simp_rw [doset, Set.mul_singleton, ← Set.image2_mul, Set.image2_image_left]
theorem mem_doset {s t : Set α} {a b : α} : b ∈ doset a s t ↔ ∃ x ∈ s, ∃ y ∈ t, b = x * a * y := by
simp only [doset_eq_image2, Set.mem_image2, eq_comm]
#align doset.mem_doset Doset.mem_doset
theorem mem_doset_self (H K : Subgroup G) (a : G) : a ∈ doset a H K :=
mem_doset.mpr ⟨1, H.one_mem, 1, K.one_mem, (one_mul a).symm.trans (mul_one (1 * a)).symm⟩
#align doset.mem_doset_self Doset.mem_doset_self
theorem doset_eq_of_mem {H K : Subgroup G} {a b : G} (hb : b ∈ doset a H K) :
doset b H K = doset a H K := by
obtain ⟨h, hh, k, hk, rfl⟩ := mem_doset.1 hb
rw [doset, doset, ← Set.singleton_mul_singleton, ← Set.singleton_mul_singleton, mul_assoc,
mul_assoc, Subgroup.singleton_mul_subgroup hk, ← mul_assoc, ← mul_assoc,
Subgroup.subgroup_mul_singleton hh]
#align doset.doset_eq_of_mem Doset.doset_eq_of_mem
theorem mem_doset_of_not_disjoint {H K : Subgroup G} {a b : G}
(h : ¬Disjoint (doset a H K) (doset b H K)) : b ∈ doset a H K := by
rw [Set.not_disjoint_iff] at h
simp only [mem_doset] at *
obtain ⟨x, ⟨l, hl, r, hr, hrx⟩, y, hy, ⟨r', hr', rfl⟩⟩ := h
refine ⟨y⁻¹ * l, H.mul_mem (H.inv_mem hy) hl, r * r'⁻¹, K.mul_mem hr (K.inv_mem hr'), ?_⟩
rwa [mul_assoc, mul_assoc, eq_inv_mul_iff_mul_eq, ← mul_assoc, ← mul_assoc, eq_mul_inv_iff_mul_eq]
#align doset.mem_doset_of_not_disjoint Doset.mem_doset_of_not_disjoint
theorem eq_of_not_disjoint {H K : Subgroup G} {a b : G}
(h : ¬Disjoint (doset a H K) (doset b H K)) : doset a H K = doset b H K := by
rw [disjoint_comm] at h
have ha : a ∈ doset b H K := mem_doset_of_not_disjoint h
apply doset_eq_of_mem ha
#align doset.eq_of_not_disjoint Doset.eq_of_not_disjoint
/-- The setoid defined by the double_coset relation -/
def setoid (H K : Set G) : Setoid G :=
Setoid.ker fun x => doset x H K
#align doset.setoid Doset.setoid
/-- Quotient of `G` by the double coset relation, i.e. `H \ G / K` -/
def Quotient (H K : Set G) : Type _ :=
_root_.Quotient (setoid H K)
#align doset.quotient Doset.Quotient
theorem rel_iff {H K : Subgroup G} {x y : G} :
(setoid ↑H ↑K).Rel x y ↔ ∃ a ∈ H, ∃ b ∈ K, y = a * x * b :=
Iff.trans
⟨fun hxy => (congr_arg _ hxy).mpr (mem_doset_self H K y), fun hxy => (doset_eq_of_mem hxy).symm⟩
mem_doset
#align doset.rel_iff Doset.rel_iff
theorem bot_rel_eq_leftRel (H : Subgroup G) :
(setoid ↑(⊥ : Subgroup G) ↑H).Rel = (QuotientGroup.leftRel H).Rel := by
ext a b
rw [rel_iff, Setoid.Rel, QuotientGroup.leftRel_apply]
constructor
· rintro ⟨a, rfl : a = 1, b, hb, rfl⟩
change a⁻¹ * (1 * a * b) ∈ H
rwa [one_mul, inv_mul_cancel_left]
· rintro (h : a⁻¹ * b ∈ H)
exact ⟨1, rfl, a⁻¹ * b, h, by rw [one_mul, mul_inv_cancel_left]⟩
#align doset.bot_rel_eq_left_rel Doset.bot_rel_eq_leftRel
theorem rel_bot_eq_right_group_rel (H : Subgroup G) :
(setoid ↑H ↑(⊥ : Subgroup G)).Rel = (QuotientGroup.rightRel H).Rel := by
ext a b
rw [rel_iff, Setoid.Rel, QuotientGroup.rightRel_apply]
constructor
· rintro ⟨b, hb, a, rfl : a = 1, rfl⟩
change b * a * 1 * a⁻¹ ∈ H
rwa [mul_one, mul_inv_cancel_right]
· rintro (h : b * a⁻¹ ∈ H)
exact ⟨b * a⁻¹, h, 1, rfl, by rw [mul_one, inv_mul_cancel_right]⟩
#align doset.rel_bot_eq_right_group_rel Doset.rel_bot_eq_right_group_rel
/-- Create a doset out of an element of `H \ G / K`-/
def quotToDoset (H K : Subgroup G) (q : Quotient (H : Set G) K) : Set G :=
doset q.out' H K
#align doset.quot_to_doset Doset.quotToDoset
/-- Map from `G` to `H \ G / K`-/
abbrev mk (H K : Subgroup G) (a : G) : Quotient (H : Set G) K :=
Quotient.mk'' a
#align doset.mk Doset.mk
instance (H K : Subgroup G) : Inhabited (Quotient (H : Set G) K) :=
⟨mk H K (1 : G)⟩
theorem eq (H K : Subgroup G) (a b : G) :
mk H K a = mk H K b ↔ ∃ h ∈ H, ∃ k ∈ K, b = h * a * k := by
rw [Quotient.eq'']
apply rel_iff
#align doset.eq Doset.eq
theorem out_eq' (H K : Subgroup G) (q : Quotient ↑H ↑K) : mk H K q.out' = q :=
Quotient.out_eq' q
#align doset.out_eq' Doset.out_eq'
theorem mk_out'_eq_mul (H K : Subgroup G) (g : G) :
∃ h k : G, h ∈ H ∧ k ∈ K ∧ (mk H K g : Quotient ↑H ↑K).out' = h * g * k := by
have := eq H K (mk H K g : Quotient ↑H ↑K).out' g
rw [out_eq'] at this
obtain ⟨h, h_h, k, hk, T⟩ := this.1 rfl
refine ⟨h⁻¹, k⁻¹, H.inv_mem h_h, K.inv_mem hk, eq_mul_inv_of_mul_eq (eq_inv_mul_of_mul_eq ?_)⟩
rw [← mul_assoc, ← T]
#align doset.mk_out'_eq_mul Doset.mk_out'_eq_mul
theorem mk_eq_of_doset_eq {H K : Subgroup G} {a b : G} (h : doset a H K = doset b H K) :
mk H K a = mk H K b := by
rw [eq]
exact mem_doset.mp (h.symm ▸ mem_doset_self H K b)
#align doset.mk_eq_of_doset_eq Doset.mk_eq_of_doset_eq
theorem disjoint_out' {H K : Subgroup G} {a b : Quotient H.1 K} :
a ≠ b → Disjoint (doset a.out' H K) (doset b.out' (H : Set G) K) := by
contrapose!
intro h
simpa [out_eq'] using mk_eq_of_doset_eq (eq_of_not_disjoint h)
#align doset.disjoint_out' Doset.disjoint_out'
theorem union_quotToDoset (H K : Subgroup G) : ⋃ q, quotToDoset H K q = Set.univ := by
ext x
simp only [Set.mem_iUnion, quotToDoset, mem_doset, SetLike.mem_coe, exists_prop, Set.mem_univ,
iff_true_iff]
use mk H K x
obtain ⟨h, k, h3, h4, h5⟩ := mk_out'_eq_mul H K x
refine ⟨h⁻¹, H.inv_mem h3, k⁻¹, K.inv_mem h4, ?_⟩
simp only [h5, Subgroup.coe_mk, ← mul_assoc, one_mul, mul_left_inv, mul_inv_cancel_right]
#align doset.union_quot_to_doset Doset.union_quotToDoset
theorem doset_union_rightCoset (H K : Subgroup G) (a : G) :
⋃ k : K, op (a * k) • ↑H = doset a H K := by
ext x
simp only [mem_rightCoset_iff, exists_prop, mul_inv_rev, Set.mem_iUnion, mem_doset,
Subgroup.mem_carrier, SetLike.mem_coe]
constructor
· rintro ⟨y, h_h⟩
refine ⟨x * (y⁻¹ * a⁻¹), h_h, y, y.2, ?_⟩
simp only [← mul_assoc, Subgroup.coe_mk, inv_mul_cancel_right, InvMemClass.coe_inv]
· rintro ⟨x, hx, y, hy, hxy⟩
refine ⟨⟨y, hy⟩, ?_⟩
simp only [hxy, ← mul_assoc, hx, mul_inv_cancel_right, Subgroup.coe_mk]
#align doset.doset_union_right_coset Doset.doset_union_rightCoset
theorem doset_union_leftCoset (H K : Subgroup G) (a : G) :
⋃ h : H, (h * a : G) • ↑K = doset a H K := by
ext x
simp only [mem_leftCoset_iff, mul_inv_rev, Set.mem_iUnion, mem_doset]
constructor
· rintro ⟨y, h_h⟩
refine ⟨y, y.2, a⁻¹ * y⁻¹ * x, h_h, ?_⟩
simp only [← mul_assoc, one_mul, mul_right_inv, mul_inv_cancel_right, InvMemClass.coe_inv]
· rintro ⟨x, hx, y, hy, hxy⟩
refine ⟨⟨x, hx⟩, ?_⟩
simp only [hxy, ← mul_assoc, hy, one_mul, mul_left_inv, Subgroup.coe_mk, inv_mul_cancel_right]
#align doset.doset_union_left_coset Doset.doset_union_leftCoset
| Mathlib/GroupTheory/DoubleCoset.lean | 199 | 205 | theorem left_bot_eq_left_quot (H : Subgroup G) :
Quotient (⊥ : Subgroup G).1 (H : Set G) = (G ⧸ H) := by |
unfold Quotient
congr
ext
simp_rw [← bot_rel_eq_leftRel H]
rfl
|
/-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Markus Himmel, Bhavik Mehta, Andrew Yang, Emily Riehl
-/
import Mathlib.CategoryTheory.Limits.Shapes.WidePullbacks
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts
#align_import category_theory.limits.shapes.pullbacks from "leanprover-community/mathlib"@"7316286ff2942aa14e540add9058c6b0aa1c8070"
/-!
# Pullbacks
We define a category `WalkingCospan` (resp. `WalkingSpan`), which is the index category
for the given data for a pullback (resp. pushout) diagram. Convenience methods `cospan f g`
and `span f g` construct functors from the walking (co)span, hitting the given morphisms.
We define `pullback f g` and `pushout f g` as limits and colimits of such functors.
## References
* [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U)
* [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025)
-/
noncomputable section
open CategoryTheory
universe w v₁ v₂ v u u₂
namespace CategoryTheory.Limits
-- attribute [local tidy] tactic.case_bash Porting note: no tidy, no local
/-- The type of objects for the diagram indexing a pullback, defined as a special case of
`WidePullbackShape`. -/
abbrev WalkingCospan : Type :=
WidePullbackShape WalkingPair
#align category_theory.limits.walking_cospan CategoryTheory.Limits.WalkingCospan
/-- The left point of the walking cospan. -/
@[match_pattern]
abbrev WalkingCospan.left : WalkingCospan :=
some WalkingPair.left
#align category_theory.limits.walking_cospan.left CategoryTheory.Limits.WalkingCospan.left
/-- The right point of the walking cospan. -/
@[match_pattern]
abbrev WalkingCospan.right : WalkingCospan :=
some WalkingPair.right
#align category_theory.limits.walking_cospan.right CategoryTheory.Limits.WalkingCospan.right
/-- The central point of the walking cospan. -/
@[match_pattern]
abbrev WalkingCospan.one : WalkingCospan :=
none
#align category_theory.limits.walking_cospan.one CategoryTheory.Limits.WalkingCospan.one
/-- The type of objects for the diagram indexing a pushout, defined as a special case of
`WidePushoutShape`.
-/
abbrev WalkingSpan : Type :=
WidePushoutShape WalkingPair
#align category_theory.limits.walking_span CategoryTheory.Limits.WalkingSpan
/-- The left point of the walking span. -/
@[match_pattern]
abbrev WalkingSpan.left : WalkingSpan :=
some WalkingPair.left
#align category_theory.limits.walking_span.left CategoryTheory.Limits.WalkingSpan.left
/-- The right point of the walking span. -/
@[match_pattern]
abbrev WalkingSpan.right : WalkingSpan :=
some WalkingPair.right
#align category_theory.limits.walking_span.right CategoryTheory.Limits.WalkingSpan.right
/-- The central point of the walking span. -/
@[match_pattern]
abbrev WalkingSpan.zero : WalkingSpan :=
none
#align category_theory.limits.walking_span.zero CategoryTheory.Limits.WalkingSpan.zero
namespace WalkingCospan
/-- The type of arrows for the diagram indexing a pullback. -/
abbrev Hom : WalkingCospan → WalkingCospan → Type :=
WidePullbackShape.Hom
#align category_theory.limits.walking_cospan.hom CategoryTheory.Limits.WalkingCospan.Hom
/-- The left arrow of the walking cospan. -/
@[match_pattern]
abbrev Hom.inl : left ⟶ one :=
WidePullbackShape.Hom.term _
#align category_theory.limits.walking_cospan.hom.inl CategoryTheory.Limits.WalkingCospan.Hom.inl
/-- The right arrow of the walking cospan. -/
@[match_pattern]
abbrev Hom.inr : right ⟶ one :=
WidePullbackShape.Hom.term _
#align category_theory.limits.walking_cospan.hom.inr CategoryTheory.Limits.WalkingCospan.Hom.inr
/-- The identity arrows of the walking cospan. -/
@[match_pattern]
abbrev Hom.id (X : WalkingCospan) : X ⟶ X :=
WidePullbackShape.Hom.id X
#align category_theory.limits.walking_cospan.hom.id CategoryTheory.Limits.WalkingCospan.Hom.id
instance (X Y : WalkingCospan) : Subsingleton (X ⟶ Y) := by
constructor; intros; simp [eq_iff_true_of_subsingleton]
end WalkingCospan
namespace WalkingSpan
/-- The type of arrows for the diagram indexing a pushout. -/
abbrev Hom : WalkingSpan → WalkingSpan → Type :=
WidePushoutShape.Hom
#align category_theory.limits.walking_span.hom CategoryTheory.Limits.WalkingSpan.Hom
/-- The left arrow of the walking span. -/
@[match_pattern]
abbrev Hom.fst : zero ⟶ left :=
WidePushoutShape.Hom.init _
#align category_theory.limits.walking_span.hom.fst CategoryTheory.Limits.WalkingSpan.Hom.fst
/-- The right arrow of the walking span. -/
@[match_pattern]
abbrev Hom.snd : zero ⟶ right :=
WidePushoutShape.Hom.init _
#align category_theory.limits.walking_span.hom.snd CategoryTheory.Limits.WalkingSpan.Hom.snd
/-- The identity arrows of the walking span. -/
@[match_pattern]
abbrev Hom.id (X : WalkingSpan) : X ⟶ X :=
WidePushoutShape.Hom.id X
#align category_theory.limits.walking_span.hom.id CategoryTheory.Limits.WalkingSpan.Hom.id
instance (X Y : WalkingSpan) : Subsingleton (X ⟶ Y) := by
constructor; intros a b; simp [eq_iff_true_of_subsingleton]
end WalkingSpan
open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom
variable {C : Type u} [Category.{v} C]
/-- To construct an isomorphism of cones over the walking cospan,
it suffices to construct an isomorphism
of the cone points and check it commutes with the legs to `left` and `right`. -/
def WalkingCospan.ext {F : WalkingCospan ⥤ C} {s t : Cone F} (i : s.pt ≅ t.pt)
(w₁ : s.π.app WalkingCospan.left = i.hom ≫ t.π.app WalkingCospan.left)
(w₂ : s.π.app WalkingCospan.right = i.hom ≫ t.π.app WalkingCospan.right) : s ≅ t := by
apply Cones.ext i _
rintro (⟨⟩ | ⟨⟨⟩⟩)
· have h₁ := s.π.naturality WalkingCospan.Hom.inl
dsimp at h₁
simp only [Category.id_comp] at h₁
have h₂ := t.π.naturality WalkingCospan.Hom.inl
dsimp at h₂
simp only [Category.id_comp] at h₂
simp_rw [h₂, ← Category.assoc, ← w₁, ← h₁]
· exact w₁
· exact w₂
#align category_theory.limits.walking_cospan.ext CategoryTheory.Limits.WalkingCospan.ext
/-- To construct an isomorphism of cocones over the walking span,
it suffices to construct an isomorphism
of the cocone points and check it commutes with the legs from `left` and `right`. -/
def WalkingSpan.ext {F : WalkingSpan ⥤ C} {s t : Cocone F} (i : s.pt ≅ t.pt)
(w₁ : s.ι.app WalkingCospan.left ≫ i.hom = t.ι.app WalkingCospan.left)
(w₂ : s.ι.app WalkingCospan.right ≫ i.hom = t.ι.app WalkingCospan.right) : s ≅ t := by
apply Cocones.ext i _
rintro (⟨⟩ | ⟨⟨⟩⟩)
· have h₁ := s.ι.naturality WalkingSpan.Hom.fst
dsimp at h₁
simp only [Category.comp_id] at h₁
have h₂ := t.ι.naturality WalkingSpan.Hom.fst
dsimp at h₂
simp only [Category.comp_id] at h₂
simp_rw [← h₁, Category.assoc, w₁, h₂]
· exact w₁
· exact w₂
#align category_theory.limits.walking_span.ext CategoryTheory.Limits.WalkingSpan.ext
/-- `cospan f g` is the functor from the walking cospan hitting `f` and `g`. -/
def cospan {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : WalkingCospan ⥤ C :=
WidePullbackShape.wideCospan Z (fun j => WalkingPair.casesOn j X Y) fun j =>
WalkingPair.casesOn j f g
#align category_theory.limits.cospan CategoryTheory.Limits.cospan
/-- `span f g` is the functor from the walking span hitting `f` and `g`. -/
def span {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : WalkingSpan ⥤ C :=
WidePushoutShape.wideSpan X (fun j => WalkingPair.casesOn j Y Z) fun j =>
WalkingPair.casesOn j f g
#align category_theory.limits.span CategoryTheory.Limits.span
@[simp]
theorem cospan_left {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.left = X :=
rfl
#align category_theory.limits.cospan_left CategoryTheory.Limits.cospan_left
@[simp]
theorem span_left {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.left = Y :=
rfl
#align category_theory.limits.span_left CategoryTheory.Limits.span_left
@[simp]
theorem cospan_right {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).obj WalkingCospan.right = Y := rfl
#align category_theory.limits.cospan_right CategoryTheory.Limits.cospan_right
@[simp]
theorem span_right {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.right = Z :=
rfl
#align category_theory.limits.span_right CategoryTheory.Limits.span_right
@[simp]
theorem cospan_one {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).obj WalkingCospan.one = Z :=
rfl
#align category_theory.limits.cospan_one CategoryTheory.Limits.cospan_one
@[simp]
theorem span_zero {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).obj WalkingSpan.zero = X :=
rfl
#align category_theory.limits.span_zero CategoryTheory.Limits.span_zero
@[simp]
theorem cospan_map_inl {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).map WalkingCospan.Hom.inl = f := rfl
#align category_theory.limits.cospan_map_inl CategoryTheory.Limits.cospan_map_inl
@[simp]
theorem span_map_fst {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.fst = f :=
rfl
#align category_theory.limits.span_map_fst CategoryTheory.Limits.span_map_fst
@[simp]
theorem cospan_map_inr {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).map WalkingCospan.Hom.inr = g := rfl
#align category_theory.limits.cospan_map_inr CategoryTheory.Limits.cospan_map_inr
@[simp]
theorem span_map_snd {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).map WalkingSpan.Hom.snd = g :=
rfl
#align category_theory.limits.span_map_snd CategoryTheory.Limits.span_map_snd
theorem cospan_map_id {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (w : WalkingCospan) :
(cospan f g).map (WalkingCospan.Hom.id w) = 𝟙 _ := rfl
#align category_theory.limits.cospan_map_id CategoryTheory.Limits.cospan_map_id
theorem span_map_id {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (w : WalkingSpan) :
(span f g).map (WalkingSpan.Hom.id w) = 𝟙 _ := rfl
#align category_theory.limits.span_map_id CategoryTheory.Limits.span_map_id
/-- Every diagram indexing a pullback is naturally isomorphic (actually, equal) to a `cospan` -/
-- @[simps (config := { rhsMd := semireducible })] Porting note: no semireducible
@[simps!]
def diagramIsoCospan (F : WalkingCospan ⥤ C) : F ≅ cospan (F.map inl) (F.map inr) :=
NatIso.ofComponents
(fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl))
(by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp)
#align category_theory.limits.diagram_iso_cospan CategoryTheory.Limits.diagramIsoCospan
/-- Every diagram indexing a pushout is naturally isomorphic (actually, equal) to a `span` -/
-- @[simps (config := { rhsMd := semireducible })] Porting note: no semireducible
@[simps!]
def diagramIsoSpan (F : WalkingSpan ⥤ C) : F ≅ span (F.map fst) (F.map snd) :=
NatIso.ofComponents
(fun j => eqToIso (by rcases j with (⟨⟩ | ⟨⟨⟩⟩) <;> rfl))
(by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp)
#align category_theory.limits.diagram_iso_span CategoryTheory.Limits.diagramIsoSpan
variable {D : Type u₂} [Category.{v₂} D]
/-- A functor applied to a cospan is a cospan. -/
def cospanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
cospan f g ⋙ F ≅ cospan (F.map f) (F.map g) :=
NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _)
(by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp)
#align category_theory.limits.cospan_comp_iso CategoryTheory.Limits.cospanCompIso
section
variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z)
@[simp]
theorem cospanCompIso_app_left : (cospanCompIso F f g).app WalkingCospan.left = Iso.refl _ := rfl
#align category_theory.limits.cospan_comp_iso_app_left CategoryTheory.Limits.cospanCompIso_app_left
@[simp]
theorem cospanCompIso_app_right : (cospanCompIso F f g).app WalkingCospan.right = Iso.refl _ :=
rfl
#align category_theory.limits.cospan_comp_iso_app_right CategoryTheory.Limits.cospanCompIso_app_right
@[simp]
theorem cospanCompIso_app_one : (cospanCompIso F f g).app WalkingCospan.one = Iso.refl _ := rfl
#align category_theory.limits.cospan_comp_iso_app_one CategoryTheory.Limits.cospanCompIso_app_one
@[simp]
theorem cospanCompIso_hom_app_left : (cospanCompIso F f g).hom.app WalkingCospan.left = 𝟙 _ :=
rfl
#align category_theory.limits.cospan_comp_iso_hom_app_left CategoryTheory.Limits.cospanCompIso_hom_app_left
@[simp]
theorem cospanCompIso_hom_app_right : (cospanCompIso F f g).hom.app WalkingCospan.right = 𝟙 _ :=
rfl
#align category_theory.limits.cospan_comp_iso_hom_app_right CategoryTheory.Limits.cospanCompIso_hom_app_right
@[simp]
theorem cospanCompIso_hom_app_one : (cospanCompIso F f g).hom.app WalkingCospan.one = 𝟙 _ := rfl
#align category_theory.limits.cospan_comp_iso_hom_app_one CategoryTheory.Limits.cospanCompIso_hom_app_one
@[simp]
theorem cospanCompIso_inv_app_left : (cospanCompIso F f g).inv.app WalkingCospan.left = 𝟙 _ :=
rfl
#align category_theory.limits.cospan_comp_iso_inv_app_left CategoryTheory.Limits.cospanCompIso_inv_app_left
@[simp]
theorem cospanCompIso_inv_app_right : (cospanCompIso F f g).inv.app WalkingCospan.right = 𝟙 _ :=
rfl
#align category_theory.limits.cospan_comp_iso_inv_app_right CategoryTheory.Limits.cospanCompIso_inv_app_right
@[simp]
theorem cospanCompIso_inv_app_one : (cospanCompIso F f g).inv.app WalkingCospan.one = 𝟙 _ := rfl
#align category_theory.limits.cospan_comp_iso_inv_app_one CategoryTheory.Limits.cospanCompIso_inv_app_one
end
/-- A functor applied to a span is a span. -/
def spanCompIso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
span f g ⋙ F ≅ span (F.map f) (F.map g) :=
NatIso.ofComponents (by rintro (⟨⟩ | ⟨⟨⟩⟩) <;> exact Iso.refl _)
(by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp)
#align category_theory.limits.span_comp_iso CategoryTheory.Limits.spanCompIso
section
variable (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z)
@[simp]
theorem spanCompIso_app_left : (spanCompIso F f g).app WalkingSpan.left = Iso.refl _ := rfl
#align category_theory.limits.span_comp_iso_app_left CategoryTheory.Limits.spanCompIso_app_left
@[simp]
theorem spanCompIso_app_right : (spanCompIso F f g).app WalkingSpan.right = Iso.refl _ := rfl
#align category_theory.limits.span_comp_iso_app_right CategoryTheory.Limits.spanCompIso_app_right
@[simp]
theorem spanCompIso_app_zero : (spanCompIso F f g).app WalkingSpan.zero = Iso.refl _ := rfl
#align category_theory.limits.span_comp_iso_app_zero CategoryTheory.Limits.spanCompIso_app_zero
@[simp]
theorem spanCompIso_hom_app_left : (spanCompIso F f g).hom.app WalkingSpan.left = 𝟙 _ := rfl
#align category_theory.limits.span_comp_iso_hom_app_left CategoryTheory.Limits.spanCompIso_hom_app_left
@[simp]
theorem spanCompIso_hom_app_right : (spanCompIso F f g).hom.app WalkingSpan.right = 𝟙 _ := rfl
#align category_theory.limits.span_comp_iso_hom_app_right CategoryTheory.Limits.spanCompIso_hom_app_right
@[simp]
theorem spanCompIso_hom_app_zero : (spanCompIso F f g).hom.app WalkingSpan.zero = 𝟙 _ := rfl
#align category_theory.limits.span_comp_iso_hom_app_zero CategoryTheory.Limits.spanCompIso_hom_app_zero
@[simp]
theorem spanCompIso_inv_app_left : (spanCompIso F f g).inv.app WalkingSpan.left = 𝟙 _ := rfl
#align category_theory.limits.span_comp_iso_inv_app_left CategoryTheory.Limits.spanCompIso_inv_app_left
@[simp]
theorem spanCompIso_inv_app_right : (spanCompIso F f g).inv.app WalkingSpan.right = 𝟙 _ := rfl
#align category_theory.limits.span_comp_iso_inv_app_right CategoryTheory.Limits.spanCompIso_inv_app_right
@[simp]
theorem spanCompIso_inv_app_zero : (spanCompIso F f g).inv.app WalkingSpan.zero = 𝟙 _ := rfl
#align category_theory.limits.span_comp_iso_inv_app_zero CategoryTheory.Limits.spanCompIso_inv_app_zero
end
section
variable {X Y Z X' Y' Z' : C} (iX : X ≅ X') (iY : Y ≅ Y') (iZ : Z ≅ Z')
section
variable {f : X ⟶ Z} {g : Y ⟶ Z} {f' : X' ⟶ Z'} {g' : Y' ⟶ Z'}
/-- Construct an isomorphism of cospans from components. -/
def cospanExt (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) :
cospan f g ≅ cospan f' g' :=
NatIso.ofComponents
(by rintro (⟨⟩ | ⟨⟨⟩⟩); exacts [iZ, iX, iY])
(by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) f <;> cases f <;> dsimp <;> simp [wf, wg])
#align category_theory.limits.cospan_ext CategoryTheory.Limits.cospanExt
variable (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom)
@[simp]
theorem cospanExt_app_left : (cospanExt iX iY iZ wf wg).app WalkingCospan.left = iX := by
dsimp [cospanExt]
#align category_theory.limits.cospan_ext_app_left CategoryTheory.Limits.cospanExt_app_left
@[simp]
theorem cospanExt_app_right : (cospanExt iX iY iZ wf wg).app WalkingCospan.right = iY := by
dsimp [cospanExt]
#align category_theory.limits.cospan_ext_app_right CategoryTheory.Limits.cospanExt_app_right
@[simp]
theorem cospanExt_app_one : (cospanExt iX iY iZ wf wg).app WalkingCospan.one = iZ := by
dsimp [cospanExt]
#align category_theory.limits.cospan_ext_app_one CategoryTheory.Limits.cospanExt_app_one
@[simp]
| Mathlib/CategoryTheory/Limits/Shapes/Pullbacks.lean | 414 | 415 | theorem cospanExt_hom_app_left :
(cospanExt iX iY iZ wf wg).hom.app WalkingCospan.left = iX.hom := by | dsimp [cospanExt]
|
/-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Data.PFunctor.Univariate.M
#align_import data.qpf.univariate.basic from "leanprover-community/mathlib"@"14b69e9f3c16630440a2cbd46f1ddad0d561dee7"
/-!
# Quotients of Polynomial Functors
We assume the following:
* `P`: a polynomial functor
* `W`: its W-type
* `M`: its M-type
* `F`: a functor
We define:
* `q`: `QPF` data, representing `F` as a quotient of `P`
The main goal is to construct:
* `Fix`: the initial algebra with structure map `F Fix → Fix`.
* `Cofix`: the final coalgebra with structure map `Cofix → F Cofix`
We also show that the composition of qpfs is a qpf, and that the quotient of a qpf
is a qpf.
The present theory focuses on the univariate case for qpfs
## References
* [Jeremy Avigad, Mario M. Carneiro and Simon Hudon, *Data Types as Quotients of Polynomial
Functors*][avigad-carneiro-hudon2019]
-/
universe u
/-- Quotients of polynomial functors.
Roughly speaking, saying that `F` is a quotient of a polynomial functor means that for each `α`,
elements of `F α` are represented by pairs `⟨a, f⟩`, where `a` is the shape of the object and
`f` indexes the relevant elements of `α`, in a suitably natural manner.
-/
class QPF (F : Type u → Type u) [Functor F] where
P : PFunctor.{u}
abs : ∀ {α}, P α → F α
repr : ∀ {α}, F α → P α
abs_repr : ∀ {α} (x : F α), abs (repr x) = x
abs_map : ∀ {α β} (f : α → β) (p : P α), abs (P.map f p) = f <$> abs p
#align qpf QPF
namespace QPF
variable {F : Type u → Type u} [Functor F] [q : QPF F]
open Functor (Liftp Liftr)
/-
Show that every qpf is a lawful functor.
Note: every functor has a field, `map_const`, and `lawfulFunctor` has the defining
characterization. We can only propagate the assumption.
-/
theorem id_map {α : Type _} (x : F α) : id <$> x = x := by
rw [← abs_repr x]
cases' repr x with a f
rw [← abs_map]
rfl
#align qpf.id_map QPF.id_map
theorem comp_map {α β γ : Type _} (f : α → β) (g : β → γ) (x : F α) :
(g ∘ f) <$> x = g <$> f <$> x := by
rw [← abs_repr x]
cases' repr x with a f
rw [← abs_map, ← abs_map, ← abs_map]
rfl
#align qpf.comp_map QPF.comp_map
theorem lawfulFunctor
(h : ∀ α β : Type u, @Functor.mapConst F _ α _ = Functor.map ∘ Function.const β) :
LawfulFunctor F :=
{ map_const := @h
id_map := @id_map F _ _
comp_map := @comp_map F _ _ }
#align qpf.is_lawful_functor QPF.lawfulFunctor
/-
Lifting predicates and relations
-/
section
open Functor
theorem liftp_iff {α : Type u} (p : α → Prop) (x : F α) :
Liftp p x ↔ ∃ a f, x = abs ⟨a, f⟩ ∧ ∀ i, p (f i) := by
constructor
· rintro ⟨y, hy⟩
cases' h : repr y with a f
use a, fun i => (f i).val
constructor
· rw [← hy, ← abs_repr y, h, ← abs_map]
rfl
intro i
apply (f i).property
rintro ⟨a, f, h₀, h₁⟩
use abs ⟨a, fun i => ⟨f i, h₁ i⟩⟩
rw [← abs_map, h₀]; rfl
#align qpf.liftp_iff QPF.liftp_iff
theorem liftp_iff' {α : Type u} (p : α → Prop) (x : F α) :
Liftp p x ↔ ∃ u : q.P α, abs u = x ∧ ∀ i, p (u.snd i) := by
constructor
· rintro ⟨y, hy⟩
cases' h : repr y with a f
use ⟨a, fun i => (f i).val⟩
dsimp
constructor
· rw [← hy, ← abs_repr y, h, ← abs_map]
rfl
intro i
apply (f i).property
rintro ⟨⟨a, f⟩, h₀, h₁⟩; dsimp at *
use abs ⟨a, fun i => ⟨f i, h₁ i⟩⟩
rw [← abs_map, ← h₀]; rfl
#align qpf.liftp_iff' QPF.liftp_iff'
theorem liftr_iff {α : Type u} (r : α → α → Prop) (x y : F α) :
Liftr r x y ↔ ∃ a f₀ f₁, x = abs ⟨a, f₀⟩ ∧ y = abs ⟨a, f₁⟩ ∧ ∀ i, r (f₀ i) (f₁ i) := by
constructor
· rintro ⟨u, xeq, yeq⟩
cases' h : repr u with a f
use a, fun i => (f i).val.fst, fun i => (f i).val.snd
constructor
· rw [← xeq, ← abs_repr u, h, ← abs_map]
rfl
constructor
· rw [← yeq, ← abs_repr u, h, ← abs_map]
rfl
intro i
exact (f i).property
rintro ⟨a, f₀, f₁, xeq, yeq, h⟩
use abs ⟨a, fun i => ⟨(f₀ i, f₁ i), h i⟩⟩
constructor
· rw [xeq, ← abs_map]
rfl
rw [yeq, ← abs_map]; rfl
#align qpf.liftr_iff QPF.liftr_iff
end
/-
Think of trees in the `W` type corresponding to `P` as representatives of elements of the
least fixed point of `F`, and assign a canonical representative to each equivalence class
of trees.
-/
/-- does recursion on `q.P.W` using `g : F α → α` rather than `g : P α → α` -/
def recF {α : Type _} (g : F α → α) : q.P.W → α
| ⟨a, f⟩ => g (abs ⟨a, fun x => recF g (f x)⟩)
set_option linter.uppercaseLean3 false in
#align qpf.recF QPF.recF
theorem recF_eq {α : Type _} (g : F α → α) (x : q.P.W) :
recF g x = g (abs (q.P.map (recF g) x.dest)) := by
cases x
rfl
set_option linter.uppercaseLean3 false in
#align qpf.recF_eq QPF.recF_eq
theorem recF_eq' {α : Type _} (g : F α → α) (a : q.P.A) (f : q.P.B a → q.P.W) :
recF g ⟨a, f⟩ = g (abs (q.P.map (recF g) ⟨a, f⟩)) :=
rfl
set_option linter.uppercaseLean3 false in
#align qpf.recF_eq' QPF.recF_eq'
/-- two trees are equivalent if their F-abstractions are -/
inductive Wequiv : q.P.W → q.P.W → Prop
| ind (a : q.P.A) (f f' : q.P.B a → q.P.W) : (∀ x, Wequiv (f x) (f' x)) → Wequiv ⟨a, f⟩ ⟨a, f'⟩
| abs (a : q.P.A) (f : q.P.B a → q.P.W) (a' : q.P.A) (f' : q.P.B a' → q.P.W) :
abs ⟨a, f⟩ = abs ⟨a', f'⟩ → Wequiv ⟨a, f⟩ ⟨a', f'⟩
| trans (u v w : q.P.W) : Wequiv u v → Wequiv v w → Wequiv u w
set_option linter.uppercaseLean3 false in
#align qpf.Wequiv QPF.Wequiv
/-- `recF` is insensitive to the representation -/
theorem recF_eq_of_Wequiv {α : Type u} (u : F α → α) (x y : q.P.W) :
Wequiv x y → recF u x = recF u y := by
intro h
induction h with
| ind a f f' _ ih => simp only [recF_eq', PFunctor.map_eq, Function.comp, ih]
| abs a f a' f' h => simp only [recF_eq', abs_map, h]
| trans x y z _ _ ih₁ ih₂ => exact Eq.trans ih₁ ih₂
set_option linter.uppercaseLean3 false in
#align qpf.recF_eq_of_Wequiv QPF.recF_eq_of_Wequiv
theorem Wequiv.abs' (x y : q.P.W) (h : QPF.abs x.dest = QPF.abs y.dest) : Wequiv x y := by
cases x
cases y
apply Wequiv.abs
apply h
set_option linter.uppercaseLean3 false in
#align qpf.Wequiv.abs' QPF.Wequiv.abs'
theorem Wequiv.refl (x : q.P.W) : Wequiv x x := by
cases' x with a f
exact Wequiv.abs a f a f rfl
set_option linter.uppercaseLean3 false in
#align qpf.Wequiv.refl QPF.Wequiv.refl
theorem Wequiv.symm (x y : q.P.W) : Wequiv x y → Wequiv y x := by
intro h
induction h with
| ind a f f' _ ih => exact Wequiv.ind _ _ _ ih
| abs a f a' f' h => exact Wequiv.abs _ _ _ _ h.symm
| trans x y z _ _ ih₁ ih₂ => exact QPF.Wequiv.trans _ _ _ ih₂ ih₁
set_option linter.uppercaseLean3 false in
#align qpf.Wequiv.symm QPF.Wequiv.symm
/-- maps every element of the W type to a canonical representative -/
def Wrepr : q.P.W → q.P.W :=
recF (PFunctor.W.mk ∘ repr)
set_option linter.uppercaseLean3 false in
#align qpf.Wrepr QPF.Wrepr
theorem Wrepr_equiv (x : q.P.W) : Wequiv (Wrepr x) x := by
induction' x with a f ih
apply Wequiv.trans
· change Wequiv (Wrepr ⟨a, f⟩) (PFunctor.W.mk (q.P.map Wrepr ⟨a, f⟩))
apply Wequiv.abs'
have : Wrepr ⟨a, f⟩ = PFunctor.W.mk (repr (abs (q.P.map Wrepr ⟨a, f⟩))) := rfl
rw [this, PFunctor.W.dest_mk, abs_repr]
rfl
apply Wequiv.ind; exact ih
set_option linter.uppercaseLean3 false in
#align qpf.Wrepr_equiv QPF.Wrepr_equiv
/-- Define the fixed point as the quotient of trees under the equivalence relation `Wequiv`. -/
def Wsetoid : Setoid q.P.W :=
⟨Wequiv, @Wequiv.refl _ _ _, @Wequiv.symm _ _ _, @Wequiv.trans _ _ _⟩
set_option linter.uppercaseLean3 false in
#align qpf.W_setoid QPF.Wsetoid
attribute [local instance] Wsetoid
/-- inductive type defined as initial algebra of a Quotient of Polynomial Functor -/
-- Porting note(#5171): this linter isn't ported yet.
-- @[nolint has_nonempty_instance]
def Fix (F : Type u → Type u) [Functor F] [q : QPF F] :=
Quotient (Wsetoid : Setoid q.P.W)
#align qpf.fix QPF.Fix
/-- recursor of a type defined by a qpf -/
def Fix.rec {α : Type _} (g : F α → α) : Fix F → α :=
Quot.lift (recF g) (recF_eq_of_Wequiv g)
#align qpf.fix.rec QPF.Fix.rec
/-- access the underlying W-type of a fixpoint data type -/
def fixToW : Fix F → q.P.W :=
Quotient.lift Wrepr (recF_eq_of_Wequiv fun x => @PFunctor.W.mk q.P (repr x))
set_option linter.uppercaseLean3 false in
#align qpf.fix_to_W QPF.fixToW
/-- constructor of a type defined by a qpf -/
def Fix.mk (x : F (Fix F)) : Fix F :=
Quot.mk _ (PFunctor.W.mk (q.P.map fixToW (repr x)))
#align qpf.fix.mk QPF.Fix.mk
/-- destructor of a type defined by a qpf -/
def Fix.dest : Fix F → F (Fix F) :=
Fix.rec (Functor.map Fix.mk)
#align qpf.fix.dest QPF.Fix.dest
theorem Fix.rec_eq {α : Type _} (g : F α → α) (x : F (Fix F)) :
Fix.rec g (Fix.mk x) = g (Fix.rec g <$> x) := by
have : recF g ∘ fixToW = Fix.rec g := by
apply funext
apply Quotient.ind
intro x
apply recF_eq_of_Wequiv
rw [fixToW]
apply Wrepr_equiv
conv =>
lhs
rw [Fix.rec, Fix.mk]
dsimp
cases' h : repr x with a f
rw [PFunctor.map_eq, recF_eq, ← PFunctor.map_eq, PFunctor.W.dest_mk, PFunctor.map_map, abs_map,
← h, abs_repr, this]
#align qpf.fix.rec_eq QPF.Fix.rec_eq
theorem Fix.ind_aux (a : q.P.A) (f : q.P.B a → q.P.W) :
Fix.mk (abs ⟨a, fun x => ⟦f x⟧⟩) = ⟦⟨a, f⟩⟧ := by
have : Fix.mk (abs ⟨a, fun x => ⟦f x⟧⟩) = ⟦Wrepr ⟨a, f⟩⟧ := by
apply Quot.sound; apply Wequiv.abs'
rw [PFunctor.W.dest_mk, abs_map, abs_repr, ← abs_map, PFunctor.map_eq]
simp only [Wrepr, recF_eq, PFunctor.W.dest_mk, abs_repr, Function.comp]
rfl
rw [this]
apply Quot.sound
apply Wrepr_equiv
#align qpf.fix.ind_aux QPF.Fix.ind_aux
theorem Fix.ind_rec {α : Type u} (g₁ g₂ : Fix F → α)
(h : ∀ x : F (Fix F), g₁ <$> x = g₂ <$> x → g₁ (Fix.mk x) = g₂ (Fix.mk x)) :
∀ x, g₁ x = g₂ x := by
apply Quot.ind
intro x
induction' x with a f ih
change g₁ ⟦⟨a, f⟩⟧ = g₂ ⟦⟨a, f⟩⟧
rw [← Fix.ind_aux a f]; apply h
rw [← abs_map, ← abs_map, PFunctor.map_eq, PFunctor.map_eq]
congr with x
apply ih
#align qpf.fix.ind_rec QPF.Fix.ind_rec
theorem Fix.rec_unique {α : Type u} (g : F α → α) (h : Fix F → α)
(hyp : ∀ x, h (Fix.mk x) = g (h <$> x)) : Fix.rec g = h := by
ext x
apply Fix.ind_rec
intro x hyp'
rw [hyp, ← hyp', Fix.rec_eq]
#align qpf.fix.rec_unique QPF.Fix.rec_unique
theorem Fix.mk_dest (x : Fix F) : Fix.mk (Fix.dest x) = x := by
change (Fix.mk ∘ Fix.dest) x = id x
apply Fix.ind_rec (mk ∘ dest) id
intro x
rw [Function.comp_apply, id_eq, Fix.dest, Fix.rec_eq, id_map, comp_map]
intro h
rw [h]
#align qpf.fix.mk_dest QPF.Fix.mk_dest
theorem Fix.dest_mk (x : F (Fix F)) : Fix.dest (Fix.mk x) = x := by
unfold Fix.dest; rw [Fix.rec_eq, ← Fix.dest, ← comp_map]
conv =>
rhs
rw [← id_map x]
congr with x
apply Fix.mk_dest
#align qpf.fix.dest_mk QPF.Fix.dest_mk
theorem Fix.ind (p : Fix F → Prop) (h : ∀ x : F (Fix F), Liftp p x → p (Fix.mk x)) : ∀ x, p x := by
apply Quot.ind
intro x
induction' x with a f ih
change p ⟦⟨a, f⟩⟧
rw [← Fix.ind_aux a f]
apply h
rw [liftp_iff]
refine ⟨_, _, rfl, ?_⟩
convert ih
#align qpf.fix.ind QPF.Fix.ind
end QPF
/-
Construct the final coalgebra to a qpf.
-/
namespace QPF
variable {F : Type u → Type u} [Functor F] [q : QPF F]
open Functor (Liftp Liftr)
/-- does recursion on `q.P.M` using `g : α → F α` rather than `g : α → P α` -/
def corecF {α : Type _} (g : α → F α) : α → q.P.M :=
PFunctor.M.corec fun x => repr (g x)
set_option linter.uppercaseLean3 false in
#align qpf.corecF QPF.corecF
theorem corecF_eq {α : Type _} (g : α → F α) (x : α) :
PFunctor.M.dest (corecF g x) = q.P.map (corecF g) (repr (g x)) := by
rw [corecF, PFunctor.M.dest_corec]
set_option linter.uppercaseLean3 false in
#align qpf.corecF_eq QPF.corecF_eq
-- Equivalence
/-- A pre-congruence on `q.P.M` *viewed as an F-coalgebra*. Not necessarily symmetric. -/
def IsPrecongr (r : q.P.M → q.P.M → Prop) : Prop :=
∀ ⦃x y⦄, r x y →
abs (q.P.map (Quot.mk r) (PFunctor.M.dest x)) = abs (q.P.map (Quot.mk r) (PFunctor.M.dest y))
#align qpf.is_precongr QPF.IsPrecongr
/-- The maximal congruence on `q.P.M`. -/
def Mcongr : q.P.M → q.P.M → Prop := fun x y => ∃ r, IsPrecongr r ∧ r x y
set_option linter.uppercaseLean3 false in
#align qpf.Mcongr QPF.Mcongr
/-- coinductive type defined as the final coalgebra of a qpf -/
def Cofix (F : Type u → Type u) [Functor F] [q : QPF F] :=
Quot (@Mcongr F _ q)
#align qpf.cofix QPF.Cofix
instance [Inhabited q.P.A] : Inhabited (Cofix F) :=
⟨Quot.mk _ default⟩
/-- corecursor for type defined by `Cofix` -/
def Cofix.corec {α : Type _} (g : α → F α) (x : α) : Cofix F :=
Quot.mk _ (corecF g x)
#align qpf.cofix.corec QPF.Cofix.corec
/-- destructor for type defined by `Cofix` -/
def Cofix.dest : Cofix F → F (Cofix F) :=
Quot.lift (fun x => Quot.mk Mcongr <$> abs (PFunctor.M.dest x))
(by
rintro x y ⟨r, pr, rxy⟩
dsimp
have : ∀ x y, r x y → Mcongr x y := by
intro x y h
exact ⟨r, pr, h⟩
rw [← Quot.factor_mk_eq _ _ this]
conv =>
lhs
rw [comp_map, ← abs_map, pr rxy, abs_map, ← comp_map])
#align qpf.cofix.dest QPF.Cofix.dest
| Mathlib/Data/QPF/Univariate/Basic.lean | 423 | 429 | theorem Cofix.dest_corec {α : Type u} (g : α → F α) (x : α) :
Cofix.dest (Cofix.corec g x) = Cofix.corec g <$> g x := by |
conv =>
lhs
rw [Cofix.dest, Cofix.corec];
dsimp
rw [corecF_eq, abs_map, abs_repr, ← comp_map]; rfl
|
/-
Copyright (c) 2023 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Algebra.NonUnitalSubalgebra
import Mathlib.Algebra.Star.StarAlgHom
import Mathlib.Algebra.Star.Center
/-!
# Non-unital Star Subalgebras
In this file we define `NonUnitalStarSubalgebra`s and the usual operations on them
(`map`, `comap`).
## TODO
* once we have scalar actions by semigroups (as opposed to monoids), implement the action of a
non-unital subalgebra on the larger algebra.
-/
namespace StarMemClass
/-- If a type carries an involutive star, then any star-closed subset does too. -/
instance instInvolutiveStar {S R : Type*} [InvolutiveStar R] [SetLike S R] [StarMemClass S R]
(s : S) : InvolutiveStar s where
star_involutive r := Subtype.ext <| star_star (r : R)
/-- In a star magma (i.e., a multiplication with an antimultiplicative involutive star
operation), any star-closed subset which is also closed under multiplication is itself a star
magma. -/
instance instStarMul {S R : Type*} [Mul R] [StarMul R] [SetLike S R]
[MulMemClass S R] [StarMemClass S R] (s : S) : StarMul s where
star_mul _ _ := Subtype.ext <| star_mul _ _
/-- In a `StarAddMonoid` (i.e., an additive monoid with an additive involutive star operation), any
star-closed subset which is also closed under addition and contains zero is itself a
`StarAddMonoid`. -/
instance instStarAddMonoid {S R : Type*} [AddMonoid R] [StarAddMonoid R] [SetLike S R]
[AddSubmonoidClass S R] [StarMemClass S R] (s : S) : StarAddMonoid s where
star_add _ _ := Subtype.ext <| star_add _ _
/-- In a star ring (i.e., a non-unital, non-associative, semiring with an additive,
antimultiplicative, involutive star operation), a star-closed non-unital subsemiring is itself a
star ring. -/
instance instStarRing {S R : Type*} [NonUnitalNonAssocSemiring R] [StarRing R] [SetLike S R]
[NonUnitalSubsemiringClass S R] [StarMemClass S R] (s : S) : StarRing s :=
{ StarMemClass.instStarMul s, StarMemClass.instStarAddMonoid s with }
/-- In a star `R`-module (i.e., `star (r • m) = (star r) • m`) any star-closed subset which is also
closed under the scalar action by `R` is itself a star `R`-module. -/
instance instStarModule {S : Type*} (R : Type*) {M : Type*} [Star R] [Star M] [SMul R M]
[StarModule R M] [SetLike S M] [SMulMemClass S R M] [StarMemClass S M] (s : S) :
StarModule R s where
star_smul _ _ := Subtype.ext <| star_smul _ _
end StarMemClass
universe u u' v v' w w' w''
variable {F : Type v'} {R' : Type u'} {R : Type u}
variable {A : Type v} {B : Type w} {C : Type w'}
namespace NonUnitalStarSubalgebraClass
variable [CommSemiring R] [NonUnitalNonAssocSemiring A]
variable [Star A] [Module R A]
variable {S : Type w''} [SetLike S A] [NonUnitalSubsemiringClass S A]
variable [hSR : SMulMemClass S R A] [StarMemClass S A] (s : S)
/-- Embedding of a non-unital star subalgebra into the non-unital star algebra. -/
def subtype (s : S) : s →⋆ₙₐ[R] A :=
{ NonUnitalSubalgebraClass.subtype s with
toFun := Subtype.val
map_star' := fun _ => rfl }
@[simp]
theorem coeSubtype : (subtype s : s → A) = Subtype.val :=
rfl
end NonUnitalStarSubalgebraClass
/-- A non-unital star subalgebra is a non-unital subalgebra which is closed under the `star`
operation. -/
structure NonUnitalStarSubalgebra (R : Type u) (A : Type v) [CommSemiring R]
[NonUnitalNonAssocSemiring A] [Module R A] [Star A]
extends NonUnitalSubalgebra R A : Type v where
/-- The `carrier` of a `NonUnitalStarSubalgebra` is closed under the `star` operation. -/
star_mem' : ∀ {a : A} (_ha : a ∈ carrier), star a ∈ carrier
/-- Reinterpret a `NonUnitalStarSubalgebra` as a `NonUnitalSubalgebra`. -/
add_decl_doc NonUnitalStarSubalgebra.toNonUnitalSubalgebra
namespace NonUnitalStarSubalgebra
variable [CommSemiring R]
variable [NonUnitalNonAssocSemiring A] [Module R A] [Star A]
variable [NonUnitalNonAssocSemiring B] [Module R B] [Star B]
variable [NonUnitalNonAssocSemiring C] [Module R C] [Star C]
variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [NonUnitalStarAlgHomClass F R A B]
instance instSetLike : SetLike (NonUnitalStarSubalgebra R A) A where
coe {s} := s.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h
instance instNonUnitalSubsemiringClass :
NonUnitalSubsemiringClass (NonUnitalStarSubalgebra R A) A where
add_mem {s} := s.add_mem'
mul_mem {s} := s.mul_mem'
zero_mem {s} := s.zero_mem'
instance instSMulMemClass : SMulMemClass (NonUnitalStarSubalgebra R A) R A where
smul_mem {s} := s.smul_mem'
instance instStarMemClass : StarMemClass (NonUnitalStarSubalgebra R A) A where
star_mem {s} := s.star_mem'
instance instNonUnitalSubringClass {R : Type u} {A : Type v} [CommRing R] [NonUnitalNonAssocRing A]
[Module R A] [Star A] : NonUnitalSubringClass (NonUnitalStarSubalgebra R A) A :=
{ NonUnitalStarSubalgebra.instNonUnitalSubsemiringClass with
neg_mem := fun _S {x} hx => neg_one_smul R x ▸ SMulMemClass.smul_mem _ hx }
theorem mem_carrier {s : NonUnitalStarSubalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=
Iff.rfl
@[ext]
theorem ext {S T : NonUnitalStarSubalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
@[simp]
theorem mem_toNonUnitalSubalgebra {S : NonUnitalStarSubalgebra R A} {x} :
x ∈ S.toNonUnitalSubalgebra ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_toNonUnitalSubalgebra (S : NonUnitalStarSubalgebra R A) :
(↑S.toNonUnitalSubalgebra : Set A) = S :=
rfl
theorem toNonUnitalSubalgebra_injective :
Function.Injective
(toNonUnitalSubalgebra : NonUnitalStarSubalgebra R A → NonUnitalSubalgebra R A) :=
fun S T h =>
ext fun x => by rw [← mem_toNonUnitalSubalgebra, ← mem_toNonUnitalSubalgebra, h]
theorem toNonUnitalSubalgebra_inj {S U : NonUnitalStarSubalgebra R A} :
S.toNonUnitalSubalgebra = U.toNonUnitalSubalgebra ↔ S = U :=
toNonUnitalSubalgebra_injective.eq_iff
theorem toNonUnitalSubalgebra_le_iff {S₁ S₂ : NonUnitalStarSubalgebra R A} :
S₁.toNonUnitalSubalgebra ≤ S₂.toNonUnitalSubalgebra ↔ S₁ ≤ S₂ :=
Iff.rfl
/-- Copy of a non-unital star subalgebra with a new `carrier` equal to the old one.
Useful to fix definitional equalities. -/
protected def copy (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) :
NonUnitalStarSubalgebra R A :=
{ S.toNonUnitalSubalgebra.copy s hs with
star_mem' := @fun x (hx : x ∈ s) => by
show star x ∈ s
rw [hs] at hx ⊢
exact S.star_mem' hx }
@[simp]
theorem coe_copy (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) :
(S.copy s hs : Set A) = s :=
rfl
theorem copy_eq (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
variable (S : NonUnitalStarSubalgebra R A)
/-- A non-unital star subalgebra over a ring is also a `Subring`. -/
def toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A]
[Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalSubring A where
toNonUnitalSubsemiring := S.toNonUnitalSubsemiring
neg_mem' := neg_mem (s := S)
@[simp]
theorem mem_toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A]
[Star A] {S : NonUnitalStarSubalgebra R A} {x} : x ∈ S.toNonUnitalSubring ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A]
[Star A] (S : NonUnitalStarSubalgebra R A) : (↑S.toNonUnitalSubring : Set A) = S :=
rfl
theorem toNonUnitalSubring_injective {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A]
[Module R A] [Star A] :
Function.Injective (toNonUnitalSubring : NonUnitalStarSubalgebra R A → NonUnitalSubring A) :=
fun S T h => ext fun x => by rw [← mem_toNonUnitalSubring, ← mem_toNonUnitalSubring, h]
theorem toNonUnitalSubring_inj {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A]
[Star A] {S U : NonUnitalStarSubalgebra R A} :
S.toNonUnitalSubring = U.toNonUnitalSubring ↔ S = U :=
toNonUnitalSubring_injective.eq_iff
instance instInhabited : Inhabited S :=
⟨(0 : S.toNonUnitalSubalgebra)⟩
section
/-! `NonUnitalStarSubalgebra`s inherit structure from their `NonUnitalSubsemiringClass` and
`NonUnitalSubringClass` instances. -/
instance toNonUnitalSemiring {R A} [CommSemiring R] [NonUnitalSemiring A] [Module R A] [Star A]
(S : NonUnitalStarSubalgebra R A) : NonUnitalSemiring S :=
inferInstance
instance toNonUnitalCommSemiring {R A} [CommSemiring R] [NonUnitalCommSemiring A] [Module R A]
[Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalCommSemiring S :=
inferInstance
instance toNonUnitalRing {R A} [CommRing R] [NonUnitalRing A] [Module R A] [Star A]
(S : NonUnitalStarSubalgebra R A) : NonUnitalRing S :=
inferInstance
instance toNonUnitalCommRing {R A} [CommRing R] [NonUnitalCommRing A] [Module R A] [Star A]
(S : NonUnitalStarSubalgebra R A) : NonUnitalCommRing S :=
inferInstance
end
/-- The forgetful map from `NonUnitalStarSubalgebra` to `NonUnitalSubalgebra` as an
`OrderEmbedding` -/
def toNonUnitalSubalgebra' : NonUnitalStarSubalgebra R A ↪o NonUnitalSubalgebra R A where
toEmbedding :=
{ toFun := fun S => S.toNonUnitalSubalgebra
inj' := fun S T h => ext <| by apply SetLike.ext_iff.1 h }
map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe
section
/-! `NonUnitalStarSubalgebra`s inherit structure from their `Submodule` coercions. -/
instance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=
SMulMemClass.toModule' _ R' R A S
instance instModule : Module R S :=
S.module'
instance instIsScalarTower' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] :
IsScalarTower R' R S :=
S.toNonUnitalSubalgebra.instIsScalarTower'
instance instIsScalarTower [IsScalarTower R A A] : IsScalarTower R S S where
smul_assoc r x y := Subtype.ext <| smul_assoc r (x : A) (y : A)
instance instSMulCommClass' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A]
[SMulCommClass R' R A] : SMulCommClass R' R S where
smul_comm r' r s := Subtype.ext <| smul_comm r' r (s : A)
instance instSMulCommClass [SMulCommClass R A A] : SMulCommClass R S S where
smul_comm r x y := Subtype.ext <| smul_comm r (x : A) (y : A)
end
instance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=
⟨fun {c x} h =>
have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg ((↑) : S → A) h)
this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩
protected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y :=
rfl
protected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y :=
rfl
protected theorem coe_zero : ((0 : S) : A) = 0 :=
rfl
protected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A]
[Star A] {S : NonUnitalStarSubalgebra R A} (x : S) : (↑(-x) : A) = -↑x :=
rfl
protected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A]
[Star A] {S : NonUnitalStarSubalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y :=
rfl
@[simp, norm_cast]
theorem coe_smul [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] (r : R') (x : S) :
↑(r • x) = r • (x : A) :=
rfl
protected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=
ZeroMemClass.coe_eq_zero
@[simp]
theorem toNonUnitalSubalgebra_subtype :
NonUnitalSubalgebraClass.subtype S = NonUnitalStarSubalgebraClass.subtype S :=
rfl
@[simp]
theorem toSubring_subtype {R A : Type*} [CommRing R] [NonUnitalRing A] [Module R A] [Star A]
(S : NonUnitalStarSubalgebra R A) :
NonUnitalSubringClass.subtype S = NonUnitalStarSubalgebraClass.subtype S :=
rfl
/-- Transport a non-unital star subalgebra via a non-unital star algebra homomorphism. -/
def map (f : F) (S : NonUnitalStarSubalgebra R A) : NonUnitalStarSubalgebra R B where
toNonUnitalSubalgebra := S.toNonUnitalSubalgebra.map (f : A →ₙₐ[R] B)
star_mem' := by rintro _ ⟨a, ha, rfl⟩; exact ⟨star a, star_mem (s := S) ha, map_star f a⟩
theorem map_mono {S₁ S₂ : NonUnitalStarSubalgebra R A} {f : F} :
S₁ ≤ S₂ → (map f S₁ : NonUnitalStarSubalgebra R B) ≤ map f S₂ :=
Set.image_subset f
theorem map_injective {f : F} (hf : Function.Injective f) :
Function.Injective (map f : NonUnitalStarSubalgebra R A → NonUnitalStarSubalgebra R B) :=
fun _S₁ _S₂ ih =>
ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih
@[simp]
theorem map_id (S : NonUnitalStarSubalgebra R A) : map (NonUnitalStarAlgHom.id R A) S = S :=
SetLike.coe_injective <| Set.image_id _
theorem map_map (S : NonUnitalStarSubalgebra R A) (g : B →⋆ₙₐ[R] C) (f : A →⋆ₙₐ[R] B) :
(S.map f).map g = S.map (g.comp f) :=
SetLike.coe_injective <| Set.image_image _ _ _
@[simp]
theorem mem_map {S : NonUnitalStarSubalgebra R A} {f : F} {y : B} :
y ∈ map f S ↔ ∃ x ∈ S, f x = y :=
NonUnitalSubalgebra.mem_map
theorem map_toNonUnitalSubalgebra {S : NonUnitalStarSubalgebra R A} {f : F} :
(map f S : NonUnitalStarSubalgebra R B).toNonUnitalSubalgebra =
NonUnitalSubalgebra.map f S.toNonUnitalSubalgebra :=
SetLike.coe_injective rfl
@[simp]
theorem coe_map (S : NonUnitalStarSubalgebra R A) (f : F) : map f S = f '' S :=
rfl
/-- Preimage of a non-unital star subalgebra under a non-unital star algebra homomorphism. -/
def comap (f : F) (S : NonUnitalStarSubalgebra R B) : NonUnitalStarSubalgebra R A where
toNonUnitalSubalgebra := S.toNonUnitalSubalgebra.comap f
star_mem' := @fun a (ha : f a ∈ S) =>
show f (star a) ∈ S from (map_star f a).symm ▸ star_mem (s := S) ha
theorem map_le {S : NonUnitalStarSubalgebra R A} {f : F} {U : NonUnitalStarSubalgebra R B} :
map f S ≤ U ↔ S ≤ comap f U :=
Set.image_subset_iff
theorem gc_map_comap (f : F) : GaloisConnection (map f) (comap f) :=
fun _S _U => map_le
@[simp]
theorem mem_comap (S : NonUnitalStarSubalgebra R B) (f : F) (x : A) : x ∈ comap f S ↔ f x ∈ S :=
Iff.rfl
@[simp, norm_cast]
theorem coe_comap (S : NonUnitalStarSubalgebra R B) (f : F) : comap f S = f ⁻¹' (S : Set B) :=
rfl
instance instNoZeroDivisors {R A : Type*} [CommSemiring R] [NonUnitalSemiring A] [NoZeroDivisors A]
[Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NoZeroDivisors S :=
NonUnitalSubsemiringClass.noZeroDivisors S
end NonUnitalStarSubalgebra
namespace NonUnitalSubalgebra
variable [CommSemiring R] [NonUnitalSemiring A] [Module R A] [Star A]
variable (s : NonUnitalSubalgebra R A)
/-- A non-unital subalgebra closed under `star` is a non-unital star subalgebra. -/
def toNonUnitalStarSubalgebra (h_star : ∀ x, x ∈ s → star x ∈ s) : NonUnitalStarSubalgebra R A :=
{ s with
star_mem' := @h_star }
@[simp]
theorem mem_toNonUnitalStarSubalgebra {s : NonUnitalSubalgebra R A} {h_star} {x} :
x ∈ s.toNonUnitalStarSubalgebra h_star ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem coe_toNonUnitalStarSubalgebra (s : NonUnitalSubalgebra R A) (h_star) :
(s.toNonUnitalStarSubalgebra h_star : Set A) = s :=
rfl
@[simp]
theorem toNonUnitalStarSubalgebra_toNonUnitalSubalgebra (s : NonUnitalSubalgebra R A) (h_star) :
(s.toNonUnitalStarSubalgebra h_star).toNonUnitalSubalgebra = s :=
SetLike.coe_injective rfl
@[simp]
theorem _root_.NonUnitalStarSubalgebra.toNonUnitalSubalgebra_toNonUnitalStarSubalgebra
(S : NonUnitalStarSubalgebra R A) :
(S.toNonUnitalSubalgebra.toNonUnitalStarSubalgebra fun _ => star_mem (s := S)) = S :=
SetLike.coe_injective rfl
end NonUnitalSubalgebra
namespace NonUnitalStarAlgHom
variable [CommSemiring R]
variable [NonUnitalNonAssocSemiring A] [Module R A] [Star A]
variable [NonUnitalNonAssocSemiring B] [Module R B] [Star B]
variable [NonUnitalNonAssocSemiring C] [Module R C] [Star C]
variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [NonUnitalStarAlgHomClass F R A B]
/-- Range of an `NonUnitalAlgHom` as a `NonUnitalStarSubalgebra`. -/
protected def range (φ : F) : NonUnitalStarSubalgebra R B where
toNonUnitalSubalgebra := NonUnitalAlgHom.range (φ : A →ₙₐ[R] B)
star_mem' := by rintro _ ⟨a, rfl⟩; exact ⟨star a, map_star φ a⟩
@[simp]
theorem mem_range (φ : F) {y : B} :
y ∈ (NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) ↔ ∃ x : A, φ x = y :=
NonUnitalRingHom.mem_srange
theorem mem_range_self (φ : F) (x : A) :
φ x ∈ (NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) :=
(NonUnitalAlgHom.mem_range φ).2 ⟨x, rfl⟩
@[simp]
theorem coe_range (φ : F) :
((NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) : Set B) = Set.range (φ : A → B) :=
by ext; rw [SetLike.mem_coe, mem_range]; rfl
theorem range_comp (f : A →⋆ₙₐ[R] B) (g : B →⋆ₙₐ[R] C) :
NonUnitalStarAlgHom.range (g.comp f) = (NonUnitalStarAlgHom.range f).map g :=
SetLike.coe_injective (Set.range_comp g f)
theorem range_comp_le_range (f : A →⋆ₙₐ[R] B) (g : B →⋆ₙₐ[R] C) :
NonUnitalStarAlgHom.range (g.comp f) ≤ NonUnitalStarAlgHom.range g :=
SetLike.coe_mono (Set.range_comp_subset_range f g)
/-- Restrict the codomain of a non-unital star algebra homomorphism. -/
def codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x, f x ∈ S) : A →⋆ₙₐ[R] S where
toNonUnitalAlgHom := NonUnitalAlgHom.codRestrict f S.toNonUnitalSubalgebra hf
map_star' := fun a => Subtype.ext <| map_star f a
@[simp]
theorem subtype_comp_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) :
(NonUnitalStarSubalgebraClass.subtype S).comp (NonUnitalStarAlgHom.codRestrict f S hf) = f :=
NonUnitalStarAlgHom.ext fun _ => rfl
@[simp]
theorem coe_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :
↑(NonUnitalStarAlgHom.codRestrict f S hf x) = f x :=
rfl
theorem injective_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) :
Function.Injective (NonUnitalStarAlgHom.codRestrict f S hf) ↔ Function.Injective f :=
⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy : _)⟩
/-- Restrict the codomain of a non-unital star algebra homomorphism `f` to `f.range`.
This is the bundled version of `Set.rangeFactorization`. -/
abbrev rangeRestrict (f : F) :
A →⋆ₙₐ[R] (NonUnitalStarAlgHom.range f : NonUnitalStarSubalgebra R B) :=
NonUnitalStarAlgHom.codRestrict f (NonUnitalStarAlgHom.range f)
(NonUnitalStarAlgHom.mem_range_self f)
/-- The equalizer of two non-unital star `R`-algebra homomorphisms -/
def equalizer (ϕ ψ : F) : NonUnitalStarSubalgebra R A where
toNonUnitalSubalgebra := NonUnitalAlgHom.equalizer ϕ ψ
star_mem' := @fun x (hx : ϕ x = ψ x) => by simp [map_star, hx]
@[simp]
theorem mem_equalizer (φ ψ : F) (x : A) :
x ∈ NonUnitalStarAlgHom.equalizer φ ψ ↔ φ x = ψ x :=
Iff.rfl
end NonUnitalStarAlgHom
namespace StarAlgEquiv
variable [CommSemiring R]
variable [NonUnitalSemiring A] [Module R A] [Star A]
variable [NonUnitalSemiring B] [Module R B] [Star B]
variable [NonUnitalSemiring C] [Module R C] [Star C]
variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [NonUnitalStarAlgHomClass F R A B]
/-- Restrict a non-unital star algebra homomorphism with a left inverse to an algebra isomorphism
to its range.
This is a computable alternative to `StarAlgEquiv.ofInjective`. -/
def ofLeftInverse' {g : B → A} {f : F} (h : Function.LeftInverse g f) :
A ≃⋆ₐ[R] NonUnitalStarAlgHom.range f :=
{ NonUnitalStarAlgHom.rangeRestrict f with
toFun := NonUnitalStarAlgHom.rangeRestrict f
invFun := g ∘ (NonUnitalStarSubalgebraClass.subtype <| NonUnitalStarAlgHom.range f)
left_inv := h
right_inv := fun x =>
Subtype.ext <|
let ⟨x', hx'⟩ := (NonUnitalStarAlgHom.mem_range f).mp x.prop
show f (g x) = x by rw [← hx', h x'] }
@[simp]
theorem ofLeftInverse'_apply {g : B → A} {f : F} (h : Function.LeftInverse g f) (x : A) :
ofLeftInverse' h x = f x :=
rfl
@[simp]
theorem ofLeftInverse'_symm_apply {g : B → A} {f : F} (h : Function.LeftInverse g f)
(x : NonUnitalStarAlgHom.range f) : (ofLeftInverse' h).symm x = g x :=
rfl
/-- Restrict an injective non-unital star algebra homomorphism to a star algebra isomorphism -/
noncomputable def ofInjective' (f : F) (hf : Function.Injective f) :
A ≃⋆ₐ[R] NonUnitalStarAlgHom.range f :=
ofLeftInverse' (Classical.choose_spec hf.hasLeftInverse)
@[simp]
theorem ofInjective'_apply (f : F) (hf : Function.Injective f) (x : A) :
ofInjective' f hf x = f x :=
rfl
end StarAlgEquiv
/-! ### The star closure of a subalgebra -/
namespace NonUnitalSubalgebra
open scoped Pointwise
variable [CommSemiring R] [StarRing R]
variable [NonUnitalSemiring A] [StarRing A] [Module R A]
variable [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A]
variable [NonUnitalSemiring B] [StarRing B] [Module R B]
variable [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B]
/-- The pointwise `star` of a non-unital subalgebra is a non-unital subalgebra. -/
instance instInvolutiveStar : InvolutiveStar (NonUnitalSubalgebra R A) where
star S :=
{ carrier := star S.carrier
mul_mem' := @fun x y hx hy => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier]
using (star_mul x y).symm ▸ mul_mem hy hx
add_mem' := @fun x y hx hy => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier]
using (star_add x y).symm ▸ add_mem hx hy
zero_mem' := Set.mem_star.mp ((star_zero A).symm ▸ zero_mem S : star (0 : A) ∈ S)
smul_mem' := fun r x hx => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier]
using (star_smul r x).symm ▸ SMulMemClass.smul_mem (star r) hx }
star_involutive S := NonUnitalSubalgebra.ext fun x =>
⟨fun hx => star_star x ▸ hx, fun hx => ((star_star x).symm ▸ hx : star (star x) ∈ S)⟩
@[simp]
theorem mem_star_iff (S : NonUnitalSubalgebra R A) (x : A) : x ∈ star S ↔ star x ∈ S :=
Iff.rfl
theorem star_mem_star_iff (S : NonUnitalSubalgebra R A) (x : A) : star x ∈ star S ↔ x ∈ S := by
simp
@[simp]
theorem coe_star (S : NonUnitalSubalgebra R A) : star S = star (S : Set A) :=
rfl
theorem star_mono : Monotone (star : NonUnitalSubalgebra R A → NonUnitalSubalgebra R A) :=
fun _ _ h _ hx => h hx
variable (R)
/-- The star operation on `NonUnitalSubalgebra` commutes with `NonUnitalAlgebra.adjoin`. -/
theorem star_adjoin_comm (s : Set A) :
star (NonUnitalAlgebra.adjoin R s) = NonUnitalAlgebra.adjoin R (star s) :=
have this :
∀ t : Set A, NonUnitalAlgebra.adjoin R (star t) ≤ star (NonUnitalAlgebra.adjoin R t) := fun t =>
NonUnitalAlgebra.adjoin_le fun x hx => NonUnitalAlgebra.subset_adjoin R hx
le_antisymm (by simpa only [star_star] using NonUnitalSubalgebra.star_mono (this (star s)))
(this s)
variable {R}
/-- The `NonUnitalStarSubalgebra` obtained from `S : NonUnitalSubalgebra R A` by taking the
smallest non-unital subalgebra containing both `S` and `star S`. -/
@[simps!]
def starClosure (S : NonUnitalSubalgebra R A) : NonUnitalStarSubalgebra R A where
toNonUnitalSubalgebra := S ⊔ star S
star_mem' := @fun a (ha : a ∈ S ⊔ star S) => show star a ∈ S ⊔ star S by
simp only [← mem_star_iff _ a, ← (@NonUnitalAlgebra.gi R A _ _ _ _ _).l_sup_u _ _] at *
convert ha using 2
simp only [Set.sup_eq_union, star_adjoin_comm, Set.union_star, coe_star, star_star,
Set.union_comm]
theorem starClosure_le {S₁ : NonUnitalSubalgebra R A} {S₂ : NonUnitalStarSubalgebra R A}
(h : S₁ ≤ S₂.toNonUnitalSubalgebra) : S₁.starClosure ≤ S₂ :=
NonUnitalStarSubalgebra.toNonUnitalSubalgebra_le_iff.1 <|
sup_le h fun x hx =>
(star_star x ▸ star_mem (show star x ∈ S₂ from h <| (S₁.mem_star_iff _).1 hx) : x ∈ S₂)
theorem starClosure_le_iff {S₁ : NonUnitalSubalgebra R A} {S₂ : NonUnitalStarSubalgebra R A} :
S₁.starClosure ≤ S₂ ↔ S₁ ≤ S₂.toNonUnitalSubalgebra :=
⟨fun h => le_sup_left.trans h, starClosure_le⟩
@[simp]
theorem starClosure_toNonunitalSubalgebra {S : NonUnitalSubalgebra R A} :
S.starClosure.toNonUnitalSubalgebra = S ⊔ star S :=
rfl
@[mono]
theorem starClosure_mono : Monotone (starClosure (R := R) (A := A)) :=
fun _ _ h => starClosure_le <| h.trans le_sup_left
end NonUnitalSubalgebra
namespace NonUnitalStarAlgebra
variable [CommSemiring R] [StarRing R]
variable [NonUnitalSemiring A] [StarRing A]
variable [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A]
variable [NonUnitalSemiring B] [StarRing B]
variable [Module R B] [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B]
variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [NonUnitalStarAlgHomClass F R A B]
open scoped Pointwise
open NonUnitalStarSubalgebra
variable (R)
/-- The minimal non-unital subalgebra that includes `s`. -/
def adjoin (s : Set A) : NonUnitalStarSubalgebra R A where
toNonUnitalSubalgebra := NonUnitalAlgebra.adjoin R (s ∪ star s)
star_mem' _ := by
rwa [NonUnitalSubalgebra.mem_carrier, ← NonUnitalSubalgebra.mem_star_iff,
NonUnitalSubalgebra.star_adjoin_comm, Set.union_star, star_star, Set.union_comm]
theorem adjoin_eq_starClosure_adjoin (s : Set A) :
adjoin R s = (NonUnitalAlgebra.adjoin R s).starClosure :=
toNonUnitalSubalgebra_injective <| show
NonUnitalAlgebra.adjoin R (s ∪ star s) =
NonUnitalAlgebra.adjoin R s ⊔ star (NonUnitalAlgebra.adjoin R s)
from
(NonUnitalSubalgebra.star_adjoin_comm R s).symm ▸ NonUnitalAlgebra.adjoin_union s (star s)
theorem adjoin_toNonUnitalSubalgebra (s : Set A) :
(adjoin R s).toNonUnitalSubalgebra = NonUnitalAlgebra.adjoin R (s ∪ star s) :=
rfl
@[aesop safe 20 apply (rule_sets := [SetLike])]
theorem subset_adjoin (s : Set A) : s ⊆ adjoin R s :=
Set.subset_union_left.trans <| NonUnitalAlgebra.subset_adjoin R
theorem star_subset_adjoin (s : Set A) : star s ⊆ adjoin R s :=
Set.subset_union_right.trans <| NonUnitalAlgebra.subset_adjoin R
theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) :=
NonUnitalAlgebra.subset_adjoin R <| Set.mem_union_left _ (Set.mem_singleton x)
theorem star_self_mem_adjoin_singleton (x : A) : star x ∈ adjoin R ({x} : Set A) :=
star_mem <| self_mem_adjoin_singleton R x
@[elab_as_elim]
lemma adjoin_induction' {s : Set A} {p : ∀ x, x ∈ adjoin R s → Prop} {a : A}
(ha : a ∈ adjoin R s) (mem : ∀ (x : A) (hx : x ∈ s), p x (subset_adjoin R s hx))
(add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (add_mem hx hy))
(zero : p 0 (zero_mem _)) (mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy))
(smul : ∀ (r : R) x hx, p x hx → p (r • x) (SMulMemClass.smul_mem r hx))
(star : ∀ x hx, p x hx → p (star x) (star_mem hx)) : p a ha := by
refine NonUnitalAlgebra.adjoin_induction' (fun x hx ↦ ?_) add zero mul smul ha
simp only [Set.mem_union, Set.mem_star] at hx
obtain (hx | hx) := hx
· exact mem x hx
· simpa using star _ (NonUnitalAlgebra.subset_adjoin R (by simpa using Or.inl hx)) (mem _ hx)
variable {R}
protected theorem gc : GaloisConnection (adjoin R : Set A → NonUnitalStarSubalgebra R A) (↑) := by
intro s S
rw [← toNonUnitalSubalgebra_le_iff, adjoin_toNonUnitalSubalgebra,
NonUnitalAlgebra.adjoin_le_iff, coe_toNonUnitalSubalgebra]
exact ⟨fun h => Set.subset_union_left.trans h,
fun h => Set.union_subset h fun x hx => star_star x ▸ star_mem (show star x ∈ S from h hx)⟩
/-- Galois insertion between `adjoin` and `Subtype.val`. -/
protected def gi : GaloisInsertion (adjoin R : Set A → NonUnitalStarSubalgebra R A) (↑) where
choice s hs := (adjoin R s).copy s <| le_antisymm (NonUnitalStarAlgebra.gc.le_u_l s) hs
gc := NonUnitalStarAlgebra.gc
le_l_u S := (NonUnitalStarAlgebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl
choice_eq _ _ := NonUnitalStarSubalgebra.copy_eq _ _ _
theorem adjoin_le {S : NonUnitalStarSubalgebra R A} {s : Set A} (hs : s ⊆ S) : adjoin R s ≤ S :=
NonUnitalStarAlgebra.gc.l_le hs
theorem adjoin_le_iff {S : NonUnitalStarSubalgebra R A} {s : Set A} : adjoin R s ≤ S ↔ s ⊆ S :=
NonUnitalStarAlgebra.gc _ _
lemma adjoin_eq (s : NonUnitalStarSubalgebra R A) : adjoin R (s : Set A) = s :=
le_antisymm (adjoin_le le_rfl) (subset_adjoin R (s : Set A))
lemma adjoin_eq_span (s : Set A) :
(adjoin R s).toSubmodule = Submodule.span R (Subsemigroup.closure (s ∪ star s)) := by
rw [adjoin_toNonUnitalSubalgebra, NonUnitalAlgebra.adjoin_eq_span]
@[simp]
lemma span_eq_toSubmodule (s : NonUnitalStarSubalgebra R A) :
Submodule.span R (s : Set A) = s.toSubmodule := by
simp [SetLike.ext'_iff, Submodule.coe_span_eq_self]
theorem _root_.NonUnitalSubalgebra.starClosure_eq_adjoin (S : NonUnitalSubalgebra R A) :
S.starClosure = adjoin R (S : Set A) :=
le_antisymm (NonUnitalSubalgebra.starClosure_le_iff.2 <| subset_adjoin R (S : Set A))
(adjoin_le (le_sup_left : S ≤ S ⊔ star S))
instance : CompleteLattice (NonUnitalStarSubalgebra R A) :=
GaloisInsertion.liftCompleteLattice NonUnitalStarAlgebra.gi
@[simp]
theorem coe_top : ((⊤ : NonUnitalStarSubalgebra R A) : Set A) = Set.univ :=
rfl
@[simp]
theorem mem_top {x : A} : x ∈ (⊤ : NonUnitalStarSubalgebra R A) :=
Set.mem_univ x
@[simp]
theorem top_toNonUnitalSubalgebra :
(⊤ : NonUnitalStarSubalgebra R A).toNonUnitalSubalgebra = ⊤ := by ext; simp
@[simp]
theorem toNonUnitalSubalgebra_eq_top {S : NonUnitalStarSubalgebra R A} :
S.toNonUnitalSubalgebra = ⊤ ↔ S = ⊤ :=
NonUnitalStarSubalgebra.toNonUnitalSubalgebra_injective.eq_iff' top_toNonUnitalSubalgebra
theorem mem_sup_left {S T : NonUnitalStarSubalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T := by
rw [← SetLike.le_def]
exact le_sup_left
theorem mem_sup_right {S T : NonUnitalStarSubalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T := by
rw [← SetLike.le_def]
exact le_sup_right
theorem mul_mem_sup {S T : NonUnitalStarSubalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) :
x * y ∈ S ⊔ T :=
mul_mem (mem_sup_left hx) (mem_sup_right hy)
theorem map_sup (f : F) (S T : NonUnitalStarSubalgebra R A) :
((S ⊔ T).map f : NonUnitalStarSubalgebra R B) = S.map f ⊔ T.map f :=
(NonUnitalStarSubalgebra.gc_map_comap f).l_sup
@[simp, norm_cast]
theorem coe_inf (S T : NonUnitalStarSubalgebra R A) : (↑(S ⊓ T) : Set A) = (S : Set A) ∩ T :=
rfl
@[simp]
theorem mem_inf {S T : NonUnitalStarSubalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T :=
Iff.rfl
@[simp]
theorem inf_toNonUnitalSubalgebra (S T : NonUnitalStarSubalgebra R A) :
(S ⊓ T).toNonUnitalSubalgebra = S.toNonUnitalSubalgebra ⊓ T.toNonUnitalSubalgebra :=
SetLike.coe_injective <| coe_inf _ _
-- it's a bit surprising `rfl` fails here.
@[simp, norm_cast]
theorem coe_sInf (S : Set (NonUnitalStarSubalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=
sInf_image
theorem mem_sInf {S : Set (NonUnitalStarSubalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by
simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]
@[simp]
theorem sInf_toNonUnitalSubalgebra (S : Set (NonUnitalStarSubalgebra R A)) :
(sInf S).toNonUnitalSubalgebra = sInf (NonUnitalStarSubalgebra.toNonUnitalSubalgebra '' S) :=
SetLike.coe_injective <| by simp
@[simp, norm_cast]
| Mathlib/Algebra/Star/NonUnitalSubalgebra.lean | 761 | 762 | theorem coe_iInf {ι : Sort*} {S : ι → NonUnitalStarSubalgebra R A} :
(↑(⨅ i, S i) : Set A) = ⋂ i, S i := by | simp [iInf]
|
/-
Copyright (c) 2022 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Integral.Bochner
import Mathlib.MeasureTheory.Measure.GiryMonad
#align_import probability.kernel.basic from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844"
/-!
# Markov Kernels
A kernel from a measurable space `α` to another measurable space `β` is a measurable map
`α → MeasureTheory.Measure β`, where the measurable space instance on `measure β` is the one defined
in `MeasureTheory.Measure.instMeasurableSpace`. That is, a kernel `κ` verifies that for all
measurable sets `s` of `β`, `a ↦ κ a s` is measurable.
## Main definitions
Classes of kernels:
* `ProbabilityTheory.kernel α β`: kernels from `α` to `β`, defined as the `AddSubmonoid` of the
measurable functions in `α → Measure β`.
* `ProbabilityTheory.IsMarkovKernel κ`: a kernel from `α` to `β` is said to be a Markov kernel
if for all `a : α`, `k a` is a probability measure.
* `ProbabilityTheory.IsFiniteKernel κ`: a kernel from `α` to `β` is said to be finite if there
exists `C : ℝ≥0∞` such that `C < ∞` and for all `a : α`, `κ a univ ≤ C`. This implies in
particular that all measures in the image of `κ` are finite, but is stronger since it requires a
uniform bound. This stronger condition is necessary to ensure that the composition of two finite
kernels is finite.
* `ProbabilityTheory.IsSFiniteKernel κ`: a kernel is called s-finite if it is a countable
sum of finite kernels.
Particular kernels:
* `ProbabilityTheory.kernel.deterministic (f : α → β) (hf : Measurable f)`:
kernel `a ↦ Measure.dirac (f a)`.
* `ProbabilityTheory.kernel.const α (μβ : measure β)`: constant kernel `a ↦ μβ`.
* `ProbabilityTheory.kernel.restrict κ (hs : MeasurableSet s)`: kernel for which the image of
`a : α` is `(κ a).restrict s`.
Integral: `∫⁻ b, f b ∂(kernel.restrict κ hs a) = ∫⁻ b in s, f b ∂(κ a)`
## Main statements
* `ProbabilityTheory.kernel.ext_fun`: if `∫⁻ b, f b ∂(κ a) = ∫⁻ b, f b ∂(η a)` for all measurable
functions `f` and all `a`, then the two kernels `κ` and `η` are equal.
-/
open MeasureTheory
open scoped MeasureTheory ENNReal NNReal
namespace ProbabilityTheory
/-- A kernel from a measurable space `α` to another measurable space `β` is a measurable function
`κ : α → Measure β`. The measurable space structure on `MeasureTheory.Measure β` is given by
`MeasureTheory.Measure.instMeasurableSpace`. A map `κ : α → MeasureTheory.Measure β` is measurable
iff `∀ s : Set β, MeasurableSet s → Measurable (fun a ↦ κ a s)`. -/
noncomputable def kernel (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] :
AddSubmonoid (α → Measure β) where
carrier := Measurable
zero_mem' := measurable_zero
add_mem' hf hg := Measurable.add hf hg
#align probability_theory.kernel ProbabilityTheory.kernel
-- Porting note: using `FunLike` instead of `CoeFun` to use `DFunLike.coe`
instance {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] :
FunLike (kernel α β) α (Measure β) where
coe := Subtype.val
coe_injective' := Subtype.val_injective
instance kernel.instCovariantAddLE {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] :
CovariantClass (kernel α β) (kernel α β) (· + ·) (· ≤ ·) :=
⟨fun _ _ _ hμ a ↦ add_le_add_left (hμ a) _⟩
noncomputable
instance kernel.instOrderBot {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] :
OrderBot (kernel α β) where
bot := 0
bot_le κ a := by simp only [ZeroMemClass.coe_zero, Pi.zero_apply, Measure.zero_le]
variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
namespace kernel
@[simp]
theorem coeFn_zero : ⇑(0 : kernel α β) = 0 :=
rfl
#align probability_theory.kernel.coe_fn_zero ProbabilityTheory.kernel.coeFn_zero
@[simp]
theorem coeFn_add (κ η : kernel α β) : ⇑(κ + η) = κ + η :=
rfl
#align probability_theory.kernel.coe_fn_add ProbabilityTheory.kernel.coeFn_add
/-- Coercion to a function as an additive monoid homomorphism. -/
def coeAddHom (α β : Type*) [MeasurableSpace α] [MeasurableSpace β] :
kernel α β →+ α → Measure β :=
AddSubmonoid.subtype _
#align probability_theory.kernel.coe_add_hom ProbabilityTheory.kernel.coeAddHom
@[simp]
theorem zero_apply (a : α) : (0 : kernel α β) a = 0 :=
rfl
#align probability_theory.kernel.zero_apply ProbabilityTheory.kernel.zero_apply
@[simp]
theorem coe_finset_sum (I : Finset ι) (κ : ι → kernel α β) : ⇑(∑ i ∈ I, κ i) = ∑ i ∈ I, ⇑(κ i) :=
map_sum (coeAddHom α β) _ _
#align probability_theory.kernel.coe_finset_sum ProbabilityTheory.kernel.coe_finset_sum
theorem finset_sum_apply (I : Finset ι) (κ : ι → kernel α β) (a : α) :
(∑ i ∈ I, κ i) a = ∑ i ∈ I, κ i a := by rw [coe_finset_sum, Finset.sum_apply]
#align probability_theory.kernel.finset_sum_apply ProbabilityTheory.kernel.finset_sum_apply
theorem finset_sum_apply' (I : Finset ι) (κ : ι → kernel α β) (a : α) (s : Set β) :
(∑ i ∈ I, κ i) a s = ∑ i ∈ I, κ i a s := by rw [finset_sum_apply, Measure.finset_sum_apply]
#align probability_theory.kernel.finset_sum_apply' ProbabilityTheory.kernel.finset_sum_apply'
end kernel
/-- A kernel is a Markov kernel if every measure in its image is a probability measure. -/
class IsMarkovKernel (κ : kernel α β) : Prop where
isProbabilityMeasure : ∀ a, IsProbabilityMeasure (κ a)
#align probability_theory.is_markov_kernel ProbabilityTheory.IsMarkovKernel
/-- A kernel is finite if every measure in its image is finite, with a uniform bound. -/
class IsFiniteKernel (κ : kernel α β) : Prop where
exists_univ_le : ∃ C : ℝ≥0∞, C < ∞ ∧ ∀ a, κ a Set.univ ≤ C
#align probability_theory.is_finite_kernel ProbabilityTheory.IsFiniteKernel
/-- A constant `C : ℝ≥0∞` such that `C < ∞` (`ProbabilityTheory.IsFiniteKernel.bound_lt_top κ`) and
for all `a : α` and `s : Set β`, `κ a s ≤ C` (`ProbabilityTheory.kernel.measure_le_bound κ a s`).
Porting note (#11215): TODO: does it make sense to
-- make `ProbabilityTheory.IsFiniteKernel.bound` the least possible bound?
-- Should it be an `NNReal` number? -/
noncomputable def IsFiniteKernel.bound (κ : kernel α β) [h : IsFiniteKernel κ] : ℝ≥0∞ :=
h.exists_univ_le.choose
#align probability_theory.is_finite_kernel.bound ProbabilityTheory.IsFiniteKernel.bound
theorem IsFiniteKernel.bound_lt_top (κ : kernel α β) [h : IsFiniteKernel κ] :
IsFiniteKernel.bound κ < ∞ :=
h.exists_univ_le.choose_spec.1
#align probability_theory.is_finite_kernel.bound_lt_top ProbabilityTheory.IsFiniteKernel.bound_lt_top
theorem IsFiniteKernel.bound_ne_top (κ : kernel α β) [IsFiniteKernel κ] :
IsFiniteKernel.bound κ ≠ ∞ :=
(IsFiniteKernel.bound_lt_top κ).ne
#align probability_theory.is_finite_kernel.bound_ne_top ProbabilityTheory.IsFiniteKernel.bound_ne_top
theorem kernel.measure_le_bound (κ : kernel α β) [h : IsFiniteKernel κ] (a : α) (s : Set β) :
κ a s ≤ IsFiniteKernel.bound κ :=
(measure_mono (Set.subset_univ s)).trans (h.exists_univ_le.choose_spec.2 a)
#align probability_theory.kernel.measure_le_bound ProbabilityTheory.kernel.measure_le_bound
instance isFiniteKernel_zero (α β : Type*) {mα : MeasurableSpace α} {mβ : MeasurableSpace β} :
IsFiniteKernel (0 : kernel α β) :=
⟨⟨0, ENNReal.coe_lt_top, fun _ => by
simp only [kernel.zero_apply, Measure.coe_zero, Pi.zero_apply, le_zero_iff]⟩⟩
#align probability_theory.is_finite_kernel_zero ProbabilityTheory.isFiniteKernel_zero
instance IsFiniteKernel.add (κ η : kernel α β) [IsFiniteKernel κ] [IsFiniteKernel η] :
IsFiniteKernel (κ + η) := by
refine ⟨⟨IsFiniteKernel.bound κ + IsFiniteKernel.bound η,
ENNReal.add_lt_top.mpr ⟨IsFiniteKernel.bound_lt_top κ, IsFiniteKernel.bound_lt_top η⟩,
fun a => ?_⟩⟩
exact add_le_add (kernel.measure_le_bound _ _ _) (kernel.measure_le_bound _ _ _)
#align probability_theory.is_finite_kernel.add ProbabilityTheory.IsFiniteKernel.add
lemma isFiniteKernel_of_le {κ ν : kernel α β} [hν : IsFiniteKernel ν] (hκν : κ ≤ ν) :
IsFiniteKernel κ := by
refine ⟨hν.bound, hν.bound_lt_top, fun a ↦ (hκν _ _).trans (kernel.measure_le_bound ν a Set.univ)⟩
variable {κ : kernel α β}
instance IsMarkovKernel.is_probability_measure' [IsMarkovKernel κ] (a : α) :
IsProbabilityMeasure (κ a) :=
IsMarkovKernel.isProbabilityMeasure a
#align probability_theory.is_markov_kernel.is_probability_measure' ProbabilityTheory.IsMarkovKernel.is_probability_measure'
instance IsFiniteKernel.isFiniteMeasure [IsFiniteKernel κ] (a : α) : IsFiniteMeasure (κ a) :=
⟨(kernel.measure_le_bound κ a Set.univ).trans_lt (IsFiniteKernel.bound_lt_top κ)⟩
#align probability_theory.is_finite_kernel.is_finite_measure ProbabilityTheory.IsFiniteKernel.isFiniteMeasure
instance (priority := 100) IsMarkovKernel.isFiniteKernel [IsMarkovKernel κ] :
IsFiniteKernel κ :=
⟨⟨1, ENNReal.one_lt_top, fun _ => prob_le_one⟩⟩
#align probability_theory.is_markov_kernel.is_finite_kernel ProbabilityTheory.IsMarkovKernel.isFiniteKernel
namespace kernel
@[ext]
theorem ext {η : kernel α β} (h : ∀ a, κ a = η a) : κ = η := DFunLike.ext _ _ h
#align probability_theory.kernel.ext ProbabilityTheory.kernel.ext
theorem ext_iff {η : kernel α β} : κ = η ↔ ∀ a, κ a = η a := DFunLike.ext_iff
#align probability_theory.kernel.ext_iff ProbabilityTheory.kernel.ext_iff
theorem ext_iff' {η : kernel α β} :
κ = η ↔ ∀ a s, MeasurableSet s → κ a s = η a s := by
simp_rw [ext_iff, Measure.ext_iff]
#align probability_theory.kernel.ext_iff' ProbabilityTheory.kernel.ext_iff'
theorem ext_fun {η : kernel α β} (h : ∀ a f, Measurable f → ∫⁻ b, f b ∂κ a = ∫⁻ b, f b ∂η a) :
κ = η := by
ext a s hs
specialize h a (s.indicator fun _ => 1) (Measurable.indicator measurable_const hs)
simp_rw [lintegral_indicator_const hs, one_mul] at h
rw [h]
#align probability_theory.kernel.ext_fun ProbabilityTheory.kernel.ext_fun
theorem ext_fun_iff {η : kernel α β} :
κ = η ↔ ∀ a f, Measurable f → ∫⁻ b, f b ∂κ a = ∫⁻ b, f b ∂η a :=
⟨fun h a f _ => by rw [h], ext_fun⟩
#align probability_theory.kernel.ext_fun_iff ProbabilityTheory.kernel.ext_fun_iff
protected theorem measurable (κ : kernel α β) : Measurable κ :=
κ.prop
#align probability_theory.kernel.measurable ProbabilityTheory.kernel.measurable
protected theorem measurable_coe (κ : kernel α β) {s : Set β} (hs : MeasurableSet s) :
Measurable fun a => κ a s :=
(Measure.measurable_coe hs).comp (kernel.measurable κ)
#align probability_theory.kernel.measurable_coe ProbabilityTheory.kernel.measurable_coe
lemma IsFiniteKernel.integrable (μ : Measure α) [IsFiniteMeasure μ]
(κ : kernel α β) [IsFiniteKernel κ] {s : Set β} (hs : MeasurableSet s) :
Integrable (fun x => (κ x s).toReal) μ := by
refine Integrable.mono' (integrable_const (IsFiniteKernel.bound κ).toReal)
((kernel.measurable_coe κ hs).ennreal_toReal.aestronglyMeasurable)
(ae_of_all μ fun x => ?_)
rw [Real.norm_eq_abs, abs_of_nonneg ENNReal.toReal_nonneg,
ENNReal.toReal_le_toReal (measure_ne_top _ _) (IsFiniteKernel.bound_ne_top _)]
exact kernel.measure_le_bound _ _ _
lemma IsMarkovKernel.integrable (μ : Measure α) [IsFiniteMeasure μ]
(κ : kernel α β) [IsMarkovKernel κ] {s : Set β} (hs : MeasurableSet s) :
Integrable (fun x => (κ x s).toReal) μ :=
IsFiniteKernel.integrable μ κ hs
section Sum
/-- Sum of an indexed family of kernels. -/
protected noncomputable def sum [Countable ι] (κ : ι → kernel α β) : kernel α β where
val a := Measure.sum fun n => κ n a
property := by
refine Measure.measurable_of_measurable_coe _ fun s hs => ?_
simp_rw [Measure.sum_apply _ hs]
exact Measurable.ennreal_tsum fun n => kernel.measurable_coe (κ n) hs
#align probability_theory.kernel.sum ProbabilityTheory.kernel.sum
theorem sum_apply [Countable ι] (κ : ι → kernel α β) (a : α) :
kernel.sum κ a = Measure.sum fun n => κ n a :=
rfl
#align probability_theory.kernel.sum_apply ProbabilityTheory.kernel.sum_apply
theorem sum_apply' [Countable ι] (κ : ι → kernel α β) (a : α) {s : Set β} (hs : MeasurableSet s) :
kernel.sum κ a s = ∑' n, κ n a s := by rw [sum_apply κ a, Measure.sum_apply _ hs]
#align probability_theory.kernel.sum_apply' ProbabilityTheory.kernel.sum_apply'
@[simp]
theorem sum_zero [Countable ι] : (kernel.sum fun _ : ι => (0 : kernel α β)) = 0 := by
ext a s hs
rw [sum_apply' _ a hs]
simp only [zero_apply, Measure.coe_zero, Pi.zero_apply, tsum_zero]
#align probability_theory.kernel.sum_zero ProbabilityTheory.kernel.sum_zero
theorem sum_comm [Countable ι] (κ : ι → ι → kernel α β) :
(kernel.sum fun n => kernel.sum (κ n)) = kernel.sum fun m => kernel.sum fun n => κ n m := by
ext a s; simp_rw [sum_apply]; rw [Measure.sum_comm]
#align probability_theory.kernel.sum_comm ProbabilityTheory.kernel.sum_comm
@[simp]
theorem sum_fintype [Fintype ι] (κ : ι → kernel α β) : kernel.sum κ = ∑ i, κ i := by
ext a s hs
simp only [sum_apply' κ a hs, finset_sum_apply' _ κ a s, tsum_fintype]
#align probability_theory.kernel.sum_fintype ProbabilityTheory.kernel.sum_fintype
theorem sum_add [Countable ι] (κ η : ι → kernel α β) :
(kernel.sum fun n => κ n + η n) = kernel.sum κ + kernel.sum η := by
ext a s hs
simp only [coeFn_add, Pi.add_apply, sum_apply, Measure.sum_apply _ hs, Pi.add_apply,
Measure.coe_add, tsum_add ENNReal.summable ENNReal.summable]
#align probability_theory.kernel.sum_add ProbabilityTheory.kernel.sum_add
end Sum
section SFinite
/-- A kernel is s-finite if it can be written as the sum of countably many finite kernels. -/
class _root_.ProbabilityTheory.IsSFiniteKernel (κ : kernel α β) : Prop where
tsum_finite : ∃ κs : ℕ → kernel α β, (∀ n, IsFiniteKernel (κs n)) ∧ κ = kernel.sum κs
#align probability_theory.is_s_finite_kernel ProbabilityTheory.IsSFiniteKernel
instance (priority := 100) IsFiniteKernel.isSFiniteKernel [h : IsFiniteKernel κ] :
IsSFiniteKernel κ :=
⟨⟨fun n => if n = 0 then κ else 0, fun n => by
simp only; split_ifs
· exact h
· infer_instance, by
ext a s hs
rw [kernel.sum_apply' _ _ hs]
have : (fun i => ((ite (i = 0) κ 0) a) s) = fun i => ite (i = 0) (κ a s) 0 := by
ext1 i; split_ifs <;> rfl
rw [this, tsum_ite_eq]⟩⟩
#align probability_theory.kernel.is_finite_kernel.is_s_finite_kernel ProbabilityTheory.kernel.IsFiniteKernel.isSFiniteKernel
/-- A sequence of finite kernels such that `κ = ProbabilityTheory.kernel.sum (seq κ)`. See
`ProbabilityTheory.kernel.isFiniteKernel_seq` and `ProbabilityTheory.kernel.kernel_sum_seq`. -/
noncomputable def seq (κ : kernel α β) [h : IsSFiniteKernel κ] : ℕ → kernel α β :=
h.tsum_finite.choose
#align probability_theory.kernel.seq ProbabilityTheory.kernel.seq
theorem kernel_sum_seq (κ : kernel α β) [h : IsSFiniteKernel κ] : kernel.sum (seq κ) = κ :=
h.tsum_finite.choose_spec.2.symm
#align probability_theory.kernel.kernel_sum_seq ProbabilityTheory.kernel.kernel_sum_seq
theorem measure_sum_seq (κ : kernel α β) [h : IsSFiniteKernel κ] (a : α) :
(Measure.sum fun n => seq κ n a) = κ a := by rw [← kernel.sum_apply, kernel_sum_seq κ]
#align probability_theory.kernel.measure_sum_seq ProbabilityTheory.kernel.measure_sum_seq
instance isFiniteKernel_seq (κ : kernel α β) [h : IsSFiniteKernel κ] (n : ℕ) :
IsFiniteKernel (kernel.seq κ n) :=
h.tsum_finite.choose_spec.1 n
#align probability_theory.kernel.is_finite_kernel_seq ProbabilityTheory.kernel.isFiniteKernel_seq
instance IsSFiniteKernel.sFinite [IsSFiniteKernel κ] (a : α) : SFinite (κ a) :=
⟨⟨fun n ↦ seq κ n a, inferInstance, (measure_sum_seq κ a).symm⟩⟩
instance IsSFiniteKernel.add (κ η : kernel α β) [IsSFiniteKernel κ] [IsSFiniteKernel η] :
IsSFiniteKernel (κ + η) := by
refine ⟨⟨fun n => seq κ n + seq η n, fun n => inferInstance, ?_⟩⟩
rw [sum_add, kernel_sum_seq κ, kernel_sum_seq η]
#align probability_theory.kernel.is_s_finite_kernel.add ProbabilityTheory.kernel.IsSFiniteKernel.add
theorem IsSFiniteKernel.finset_sum {κs : ι → kernel α β} (I : Finset ι)
(h : ∀ i ∈ I, IsSFiniteKernel (κs i)) : IsSFiniteKernel (∑ i ∈ I, κs i) := by
classical
induction' I using Finset.induction with i I hi_nmem_I h_ind h
· rw [Finset.sum_empty]; infer_instance
· rw [Finset.sum_insert hi_nmem_I]
haveI : IsSFiniteKernel (κs i) := h i (Finset.mem_insert_self _ _)
have : IsSFiniteKernel (∑ x ∈ I, κs x) :=
h_ind fun i hiI => h i (Finset.mem_insert_of_mem hiI)
exact IsSFiniteKernel.add _ _
#align probability_theory.kernel.is_s_finite_kernel.finset_sum ProbabilityTheory.kernel.IsSFiniteKernel.finset_sum
theorem isSFiniteKernel_sum_of_denumerable [Denumerable ι] {κs : ι → kernel α β}
(hκs : ∀ n, IsSFiniteKernel (κs n)) : IsSFiniteKernel (kernel.sum κs) := by
let e : ℕ ≃ ι × ℕ := (Denumerable.eqv (ι × ℕ)).symm
refine ⟨⟨fun n => seq (κs (e n).1) (e n).2, inferInstance, ?_⟩⟩
have hκ_eq : kernel.sum κs = kernel.sum fun n => kernel.sum (seq (κs n)) := by
simp_rw [kernel_sum_seq]
ext a s hs
rw [hκ_eq]
simp_rw [kernel.sum_apply' _ _ hs]
change (∑' i, ∑' m, seq (κs i) m a s) = ∑' n, (fun im : ι × ℕ => seq (κs im.fst) im.snd a s) (e n)
rw [e.tsum_eq (fun im : ι × ℕ => seq (κs im.fst) im.snd a s),
tsum_prod' ENNReal.summable fun _ => ENNReal.summable]
#align probability_theory.kernel.is_s_finite_kernel_sum_of_denumerable ProbabilityTheory.kernel.isSFiniteKernel_sum_of_denumerable
theorem isSFiniteKernel_sum [Countable ι] {κs : ι → kernel α β}
(hκs : ∀ n, IsSFiniteKernel (κs n)) : IsSFiniteKernel (kernel.sum κs) := by
cases fintypeOrInfinite ι
· rw [sum_fintype]
exact IsSFiniteKernel.finset_sum Finset.univ fun i _ => hκs i
cases nonempty_denumerable ι
exact isSFiniteKernel_sum_of_denumerable hκs
#align probability_theory.kernel.is_s_finite_kernel_sum ProbabilityTheory.kernel.isSFiniteKernel_sum
end SFinite
section Deterministic
/-- Kernel which to `a` associates the dirac measure at `f a`. This is a Markov kernel. -/
noncomputable def deterministic (f : α → β) (hf : Measurable f) : kernel α β where
val a := Measure.dirac (f a)
property := by
refine Measure.measurable_of_measurable_coe _ fun s hs => ?_
simp_rw [Measure.dirac_apply' _ hs]
exact measurable_one.indicator (hf hs)
#align probability_theory.kernel.deterministic ProbabilityTheory.kernel.deterministic
theorem deterministic_apply {f : α → β} (hf : Measurable f) (a : α) :
deterministic f hf a = Measure.dirac (f a) :=
rfl
#align probability_theory.kernel.deterministic_apply ProbabilityTheory.kernel.deterministic_apply
theorem deterministic_apply' {f : α → β} (hf : Measurable f) (a : α) {s : Set β}
(hs : MeasurableSet s) : deterministic f hf a s = s.indicator (fun _ => 1) (f a) := by
rw [deterministic]
change Measure.dirac (f a) s = s.indicator 1 (f a)
simp_rw [Measure.dirac_apply' _ hs]
#align probability_theory.kernel.deterministic_apply' ProbabilityTheory.kernel.deterministic_apply'
instance isMarkovKernel_deterministic {f : α → β} (hf : Measurable f) :
IsMarkovKernel (deterministic f hf) :=
⟨fun a => by rw [deterministic_apply hf]; infer_instance⟩
#align probability_theory.kernel.is_markov_kernel_deterministic ProbabilityTheory.kernel.isMarkovKernel_deterministic
theorem lintegral_deterministic' {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g)
(hf : Measurable f) : ∫⁻ x, f x ∂kernel.deterministic g hg a = f (g a) := by
rw [kernel.deterministic_apply, lintegral_dirac' _ hf]
#align probability_theory.kernel.lintegral_deterministic' ProbabilityTheory.kernel.lintegral_deterministic'
@[simp]
theorem lintegral_deterministic {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g)
[MeasurableSingletonClass β] : ∫⁻ x, f x ∂kernel.deterministic g hg a = f (g a) := by
rw [kernel.deterministic_apply, lintegral_dirac (g a) f]
#align probability_theory.kernel.lintegral_deterministic ProbabilityTheory.kernel.lintegral_deterministic
theorem set_lintegral_deterministic' {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g)
(hf : Measurable f) {s : Set β} (hs : MeasurableSet s) [Decidable (g a ∈ s)] :
∫⁻ x in s, f x ∂kernel.deterministic g hg a = if g a ∈ s then f (g a) else 0 := by
rw [kernel.deterministic_apply, set_lintegral_dirac' hf hs]
#align probability_theory.kernel.set_lintegral_deterministic' ProbabilityTheory.kernel.set_lintegral_deterministic'
@[simp]
theorem set_lintegral_deterministic {f : β → ℝ≥0∞} {g : α → β} {a : α} (hg : Measurable g)
[MeasurableSingletonClass β] (s : Set β) [Decidable (g a ∈ s)] :
∫⁻ x in s, f x ∂kernel.deterministic g hg a = if g a ∈ s then f (g a) else 0 := by
rw [kernel.deterministic_apply, set_lintegral_dirac f s]
#align probability_theory.kernel.set_lintegral_deterministic ProbabilityTheory.kernel.set_lintegral_deterministic
theorem integral_deterministic' {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[CompleteSpace E] {f : β → E} {g : α → β} {a : α} (hg : Measurable g)
(hf : StronglyMeasurable f) : ∫ x, f x ∂kernel.deterministic g hg a = f (g a) := by
rw [kernel.deterministic_apply, integral_dirac' _ _ hf]
#align probability_theory.kernel.integral_deterministic' ProbabilityTheory.kernel.integral_deterministic'
@[simp]
theorem integral_deterministic {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[CompleteSpace E] {f : β → E} {g : α → β} {a : α} (hg : Measurable g)
[MeasurableSingletonClass β] : ∫ x, f x ∂kernel.deterministic g hg a = f (g a) := by
rw [kernel.deterministic_apply, integral_dirac _ (g a)]
#align probability_theory.kernel.integral_deterministic ProbabilityTheory.kernel.integral_deterministic
theorem setIntegral_deterministic' {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[CompleteSpace E] {f : β → E} {g : α → β} {a : α} (hg : Measurable g)
(hf : StronglyMeasurable f) {s : Set β} (hs : MeasurableSet s) [Decidable (g a ∈ s)] :
∫ x in s, f x ∂kernel.deterministic g hg a = if g a ∈ s then f (g a) else 0 := by
rw [kernel.deterministic_apply, setIntegral_dirac' hf _ hs]
#align probability_theory.kernel.set_integral_deterministic' ProbabilityTheory.kernel.setIntegral_deterministic'
@[deprecated (since := "2024-04-17")]
alias set_integral_deterministic' := setIntegral_deterministic'
@[simp]
| Mathlib/Probability/Kernel/Basic.lean | 451 | 455 | theorem setIntegral_deterministic {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[CompleteSpace E] {f : β → E} {g : α → β} {a : α} (hg : Measurable g)
[MeasurableSingletonClass β] (s : Set β) [Decidable (g a ∈ s)] :
∫ x in s, f x ∂kernel.deterministic g hg a = if g a ∈ s then f (g a) else 0 := by |
rw [kernel.deterministic_apply, setIntegral_dirac f _ s]
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Yury Kudryashov
-/
import Mathlib.Analysis.Convex.Combination
import Mathlib.Analysis.Convex.Strict
import Mathlib.Topology.Connected.PathConnected
import Mathlib.Topology.Algebra.Affine
import Mathlib.Topology.Algebra.Module.Basic
#align_import analysis.convex.topology from "leanprover-community/mathlib"@"0e3aacdc98d25e0afe035c452d876d28cbffaa7e"
/-!
# Topological properties of convex sets
We prove the following facts:
* `Convex.interior` : interior of a convex set is convex;
* `Convex.closure` : closure of a convex set is convex;
* `Set.Finite.isCompact_convexHull` : convex hull of a finite set is compact;
* `Set.Finite.isClosed_convexHull` : convex hull of a finite set is closed.
-/
assert_not_exists Norm
open Metric Bornology Set Pointwise Convex
variable {ι 𝕜 E : Type*}
theorem Real.convex_iff_isPreconnected {s : Set ℝ} : Convex ℝ s ↔ IsPreconnected s :=
convex_iff_ordConnected.trans isPreconnected_iff_ordConnected.symm
#align real.convex_iff_is_preconnected Real.convex_iff_isPreconnected
alias ⟨_, IsPreconnected.convex⟩ := Real.convex_iff_isPreconnected
#align is_preconnected.convex IsPreconnected.convex
/-! ### Standard simplex -/
section stdSimplex
variable [Fintype ι]
/-- Every vector in `stdSimplex 𝕜 ι` has `max`-norm at most `1`. -/
theorem stdSimplex_subset_closedBall : stdSimplex ℝ ι ⊆ Metric.closedBall 0 1 := fun f hf ↦ by
rw [Metric.mem_closedBall, dist_pi_le_iff zero_le_one]
intro x
rw [Pi.zero_apply, Real.dist_0_eq_abs, abs_of_nonneg <| hf.1 x]
exact (mem_Icc_of_mem_stdSimplex hf x).2
#align std_simplex_subset_closed_ball stdSimplex_subset_closedBall
variable (ι)
/-- `stdSimplex ℝ ι` is bounded. -/
theorem bounded_stdSimplex : IsBounded (stdSimplex ℝ ι) :=
(Metric.isBounded_iff_subset_closedBall 0).2 ⟨1, stdSimplex_subset_closedBall⟩
#align bounded_std_simplex bounded_stdSimplex
/-- `stdSimplex ℝ ι` is closed. -/
theorem isClosed_stdSimplex : IsClosed (stdSimplex ℝ ι) :=
(stdSimplex_eq_inter ℝ ι).symm ▸
IsClosed.inter (isClosed_iInter fun i => isClosed_le continuous_const (continuous_apply i))
(isClosed_eq (continuous_finset_sum _ fun x _ => continuous_apply x) continuous_const)
#align is_closed_std_simplex isClosed_stdSimplex
/-- `stdSimplex ℝ ι` is compact. -/
theorem isCompact_stdSimplex : IsCompact (stdSimplex ℝ ι) :=
Metric.isCompact_iff_isClosed_bounded.2 ⟨isClosed_stdSimplex ι, bounded_stdSimplex ι⟩
#align is_compact_std_simplex isCompact_stdSimplex
instance stdSimplex.instCompactSpace_coe : CompactSpace ↥(stdSimplex ℝ ι) :=
isCompact_iff_compactSpace.mp <| isCompact_stdSimplex _
/-- The standard one-dimensional simplex in `ℝ² = Fin 2 → ℝ`
is homeomorphic to the unit interval. -/
@[simps! (config := .asFn)]
def stdSimplexHomeomorphUnitInterval : stdSimplex ℝ (Fin 2) ≃ₜ unitInterval where
toEquiv := stdSimplexEquivIcc ℝ
continuous_toFun := .subtype_mk ((continuous_apply 0).comp continuous_subtype_val) _
continuous_invFun := by
apply Continuous.subtype_mk
exact (continuous_pi <| Fin.forall_fin_two.2
⟨continuous_subtype_val, continuous_const.sub continuous_subtype_val⟩)
end stdSimplex
/-! ### Topological vector spaces -/
section TopologicalSpace
variable [LinearOrderedRing 𝕜] [DenselyOrdered 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜]
[AddCommGroup E] [TopologicalSpace E] [ContinuousAdd E] [Module 𝕜 E] [ContinuousSMul 𝕜 E]
{x y : E}
theorem segment_subset_closure_openSegment : [x -[𝕜] y] ⊆ closure (openSegment 𝕜 x y) := by
rw [segment_eq_image, openSegment_eq_image, ← closure_Ioo (zero_ne_one' 𝕜)]
exact image_closure_subset_closure_image (by continuity)
#align segment_subset_closure_open_segment segment_subset_closure_openSegment
end TopologicalSpace
section PseudoMetricSpace
variable [LinearOrderedRing 𝕜] [DenselyOrdered 𝕜] [PseudoMetricSpace 𝕜] [OrderTopology 𝕜]
[ProperSpace 𝕜] [CompactIccSpace 𝕜] [AddCommGroup E] [TopologicalSpace E] [T2Space E]
[ContinuousAdd E] [Module 𝕜 E] [ContinuousSMul 𝕜 E]
@[simp]
theorem closure_openSegment (x y : E) : closure (openSegment 𝕜 x y) = [x -[𝕜] y] := by
rw [segment_eq_image, openSegment_eq_image, ← closure_Ioo (zero_ne_one' 𝕜)]
exact (image_closure_of_isCompact (isBounded_Ioo _ _).isCompact_closure <|
Continuous.continuousOn <| by continuity).symm
#align closure_open_segment closure_openSegment
end PseudoMetricSpace
section ContinuousConstSMul
variable [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E]
[TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E]
/-- If `s` is a convex set, then `a • interior s + b • closure s ⊆ interior s` for all `0 < a`,
`0 ≤ b`, `a + b = 1`. See also `Convex.combo_interior_self_subset_interior` for a weaker version. -/
theorem Convex.combo_interior_closure_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜}
(ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • interior s + b • closure s ⊆ interior s :=
interior_smul₀ ha.ne' s ▸
calc
interior (a • s) + b • closure s ⊆ interior (a • s) + closure (b • s) :=
add_subset_add Subset.rfl (smul_closure_subset b s)
_ = interior (a • s) + b • s := by rw [isOpen_interior.add_closure (b • s)]
_ ⊆ interior (a • s + b • s) := subset_interior_add_left
_ ⊆ interior s := interior_mono <| hs.set_combo_subset ha.le hb hab
#align convex.combo_interior_closure_subset_interior Convex.combo_interior_closure_subset_interior
/-- If `s` is a convex set, then `a • interior s + b • s ⊆ interior s` for all `0 < a`, `0 ≤ b`,
`a + b = 1`. See also `Convex.combo_interior_closure_subset_interior` for a stronger version. -/
theorem Convex.combo_interior_self_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜}
(ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • interior s + b • s ⊆ interior s :=
calc
a • interior s + b • s ⊆ a • interior s + b • closure s :=
add_subset_add Subset.rfl <| image_subset _ subset_closure
_ ⊆ interior s := hs.combo_interior_closure_subset_interior ha hb hab
#align convex.combo_interior_self_subset_interior Convex.combo_interior_self_subset_interior
/-- If `s` is a convex set, then `a • closure s + b • interior s ⊆ interior s` for all `0 ≤ a`,
`0 < b`, `a + b = 1`. See also `Convex.combo_self_interior_subset_interior` for a weaker version. -/
theorem Convex.combo_closure_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜}
(ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • closure s + b • interior s ⊆ interior s := by
rw [add_comm]
exact hs.combo_interior_closure_subset_interior hb ha (add_comm a b ▸ hab)
#align convex.combo_closure_interior_subset_interior Convex.combo_closure_interior_subset_interior
/-- If `s` is a convex set, then `a • s + b • interior s ⊆ interior s` for all `0 ≤ a`, `0 < b`,
`a + b = 1`. See also `Convex.combo_closure_interior_subset_interior` for a stronger version. -/
theorem Convex.combo_self_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜}
(ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • s + b • interior s ⊆ interior s := by
rw [add_comm]
exact hs.combo_interior_self_subset_interior hb ha (add_comm a b ▸ hab)
#align convex.combo_self_interior_subset_interior Convex.combo_self_interior_subset_interior
theorem Convex.combo_interior_closure_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E}
(hx : x ∈ interior s) (hy : y ∈ closure s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b)
(hab : a + b = 1) : a • x + b • y ∈ interior s :=
hs.combo_interior_closure_subset_interior ha hb hab <|
add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy)
#align convex.combo_interior_closure_mem_interior Convex.combo_interior_closure_mem_interior
theorem Convex.combo_interior_self_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E}
(hx : x ∈ interior s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) :
a • x + b • y ∈ interior s :=
hs.combo_interior_closure_mem_interior hx (subset_closure hy) ha hb hab
#align convex.combo_interior_self_mem_interior Convex.combo_interior_self_mem_interior
theorem Convex.combo_closure_interior_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E}
(hx : x ∈ closure s) (hy : y ∈ interior s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b)
(hab : a + b = 1) : a • x + b • y ∈ interior s :=
hs.combo_closure_interior_subset_interior ha hb hab <|
add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy)
#align convex.combo_closure_interior_mem_interior Convex.combo_closure_interior_mem_interior
theorem Convex.combo_self_interior_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s)
(hy : y ∈ interior s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) :
a • x + b • y ∈ interior s :=
hs.combo_closure_interior_mem_interior (subset_closure hx) hy ha hb hab
#align convex.combo_self_interior_mem_interior Convex.combo_self_interior_mem_interior
theorem Convex.openSegment_interior_closure_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E}
(hx : x ∈ interior s) (hy : y ∈ closure s) : openSegment 𝕜 x y ⊆ interior s := by
rintro _ ⟨a, b, ha, hb, hab, rfl⟩
exact hs.combo_interior_closure_mem_interior hx hy ha hb.le hab
#align convex.open_segment_interior_closure_subset_interior Convex.openSegment_interior_closure_subset_interior
theorem Convex.openSegment_interior_self_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E}
(hx : x ∈ interior s) (hy : y ∈ s) : openSegment 𝕜 x y ⊆ interior s :=
hs.openSegment_interior_closure_subset_interior hx (subset_closure hy)
#align convex.open_segment_interior_self_subset_interior Convex.openSegment_interior_self_subset_interior
theorem Convex.openSegment_closure_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E}
(hx : x ∈ closure s) (hy : y ∈ interior s) : openSegment 𝕜 x y ⊆ interior s := by
rintro _ ⟨a, b, ha, hb, hab, rfl⟩
exact hs.combo_closure_interior_mem_interior hx hy ha.le hb hab
#align convex.open_segment_closure_interior_subset_interior Convex.openSegment_closure_interior_subset_interior
theorem Convex.openSegment_self_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E}
(hx : x ∈ s) (hy : y ∈ interior s) : openSegment 𝕜 x y ⊆ interior s :=
hs.openSegment_closure_interior_subset_interior (subset_closure hx) hy
#align convex.open_segment_self_interior_subset_interior Convex.openSegment_self_interior_subset_interior
/-- If `x ∈ closure s` and `y ∈ interior s`, then the segment `(x, y]` is included in `interior s`.
-/
theorem Convex.add_smul_sub_mem_interior' {s : Set E} (hs : Convex 𝕜 s) {x y : E}
(hx : x ∈ closure s) (hy : y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) :
x + t • (y - x) ∈ interior s := by
simpa only [sub_smul, smul_sub, one_smul, add_sub, add_comm] using
hs.combo_interior_closure_mem_interior hy hx ht.1 (sub_nonneg.mpr ht.2)
(add_sub_cancel _ _)
#align convex.add_smul_sub_mem_interior' Convex.add_smul_sub_mem_interior'
/-- If `x ∈ s` and `y ∈ interior s`, then the segment `(x, y]` is included in `interior s`. -/
theorem Convex.add_smul_sub_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s)
(hy : y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • (y - x) ∈ interior s :=
hs.add_smul_sub_mem_interior' (subset_closure hx) hy ht
#align convex.add_smul_sub_mem_interior Convex.add_smul_sub_mem_interior
/-- If `x ∈ closure s` and `x + y ∈ interior s`, then `x + t y ∈ interior s` for `t ∈ (0, 1]`. -/
| Mathlib/Analysis/Convex/Topology.lean | 228 | 230 | theorem Convex.add_smul_mem_interior' {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s)
(hy : x + y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • y ∈ interior s := by |
simpa only [add_sub_cancel_left] using hs.add_smul_sub_mem_interior' hx hy ht
|
/-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Algebra.Bilinear
import Mathlib.Algebra.Algebra.Equiv
import Mathlib.Algebra.Algebra.Opposite
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.Algebra.Module.Opposites
import Mathlib.Algebra.Module.Submodule.Bilinear
import Mathlib.Algebra.Module.Submodule.Pointwise
import Mathlib.Algebra.Order.Kleene
import Mathlib.Data.Finset.Pointwise
import Mathlib.Data.Set.Pointwise.BigOperators
import Mathlib.Data.Set.Semiring
import Mathlib.GroupTheory.GroupAction.SubMulAction.Pointwise
import Mathlib.LinearAlgebra.Basic
#align_import algebra.algebra.operations from "leanprover-community/mathlib"@"27b54c47c3137250a521aa64e9f1db90be5f6a26"
/-!
# Multiplication and division of submodules of an algebra.
An interface for multiplication and division of sub-R-modules of an R-algebra A is developed.
## Main definitions
Let `R` be a commutative ring (or semiring) and let `A` be an `R`-algebra.
* `1 : Submodule R A` : the R-submodule R of the R-algebra A
* `Mul (Submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be
the smallest submodule containing all the products `m * n`.
* `Div (Submodule R A)` : `I / J` is defined to be the submodule consisting of all `a : A` such
that `a • J ⊆ I`
It is proved that `Submodule R A` is a semiring, and also an algebra over `Set A`.
Additionally, in the `Pointwise` locale we promote `Submodule.pointwiseDistribMulAction` to a
`MulSemiringAction` as `Submodule.pointwiseMulSemiringAction`.
## Tags
multiplication of submodules, division of submodules, submodule semiring
-/
universe uι u v
open Algebra Set MulOpposite
open Pointwise
namespace SubMulAction
variable {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]
theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : SubMulAction R A) :=
⟨r, (algebraMap_eq_smul_one r).symm⟩
#align sub_mul_action.algebra_map_mem SubMulAction.algebraMap_mem
theorem mem_one' {x : A} : x ∈ (1 : SubMulAction R A) ↔ ∃ y, algebraMap R A y = x :=
exists_congr fun r => by rw [algebraMap_eq_smul_one]
#align sub_mul_action.mem_one' SubMulAction.mem_one'
end SubMulAction
namespace Submodule
variable {ι : Sort uι}
variable {R : Type u} [CommSemiring R]
section Ring
variable {A : Type v} [Semiring A] [Algebra R A]
variable (S T : Set A) {M N P Q : Submodule R A} {m n : A}
/-- `1 : Submodule R A` is the submodule R of A. -/
instance one : One (Submodule R A) :=
-- Porting note: `f.range` notation doesn't work
⟨LinearMap.range (Algebra.linearMap R A)⟩
#align submodule.has_one Submodule.one
theorem one_eq_range : (1 : Submodule R A) = LinearMap.range (Algebra.linearMap R A) :=
rfl
#align submodule.one_eq_range Submodule.one_eq_range
theorem le_one_toAddSubmonoid : 1 ≤ (1 : Submodule R A).toAddSubmonoid := by
rintro x ⟨n, rfl⟩
exact ⟨n, map_natCast (algebraMap R A) n⟩
#align submodule.le_one_to_add_submonoid Submodule.le_one_toAddSubmonoid
theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : Submodule R A) :=
LinearMap.mem_range_self (Algebra.linearMap R A) _
#align submodule.algebra_map_mem Submodule.algebraMap_mem
@[simp]
theorem mem_one {x : A} : x ∈ (1 : Submodule R A) ↔ ∃ y, algebraMap R A y = x :=
Iff.rfl
#align submodule.mem_one Submodule.mem_one
@[simp]
theorem toSubMulAction_one : (1 : Submodule R A).toSubMulAction = 1 :=
SetLike.ext fun _ => mem_one.trans SubMulAction.mem_one'.symm
#align submodule.to_sub_mul_action_one Submodule.toSubMulAction_one
theorem one_eq_span : (1 : Submodule R A) = R ∙ 1 := by
apply Submodule.ext
intro a
simp only [mem_one, mem_span_singleton, Algebra.smul_def, mul_one]
#align submodule.one_eq_span Submodule.one_eq_span
theorem one_eq_span_one_set : (1 : Submodule R A) = span R 1 :=
one_eq_span
#align submodule.one_eq_span_one_set Submodule.one_eq_span_one_set
theorem one_le : (1 : Submodule R A) ≤ P ↔ (1 : A) ∈ P := by
-- Porting note: simpa no longer closes refl goals, so added `SetLike.mem_coe`
simp only [one_eq_span, span_le, Set.singleton_subset_iff, SetLike.mem_coe]
#align submodule.one_le Submodule.one_le
protected theorem map_one {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') :
map f.toLinearMap (1 : Submodule R A) = 1 := by
ext
simp
#align submodule.map_one Submodule.map_one
@[simp]
theorem map_op_one :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R A) = 1 := by
ext x
induction x using MulOpposite.rec'
simp
#align submodule.map_op_one Submodule.map_op_one
@[simp]
theorem comap_op_one :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (1 : Submodule R Aᵐᵒᵖ) = 1 := by
ext
simp
#align submodule.comap_op_one Submodule.comap_op_one
@[simp]
theorem map_unop_one :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R Aᵐᵒᵖ) = 1 := by
rw [← comap_equiv_eq_map_symm, comap_op_one]
#align submodule.map_unop_one Submodule.map_unop_one
@[simp]
theorem comap_unop_one :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (1 : Submodule R A) = 1 := by
rw [← map_equiv_eq_comap_symm, map_op_one]
#align submodule.comap_unop_one Submodule.comap_unop_one
/-- Multiplication of sub-R-modules of an R-algebra A. The submodule `M * N` is the
smallest R-submodule of `A` containing the elements `m * n` for `m ∈ M` and `n ∈ N`. -/
instance mul : Mul (Submodule R A) :=
⟨Submodule.map₂ <| LinearMap.mul R A⟩
#align submodule.has_mul Submodule.mul
theorem mul_mem_mul (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N :=
apply_mem_map₂ _ hm hn
#align submodule.mul_mem_mul Submodule.mul_mem_mul
theorem mul_le : M * N ≤ P ↔ ∀ m ∈ M, ∀ n ∈ N, m * n ∈ P :=
map₂_le
#align submodule.mul_le Submodule.mul_le
theorem mul_toAddSubmonoid (M N : Submodule R A) :
(M * N).toAddSubmonoid = M.toAddSubmonoid * N.toAddSubmonoid := by
dsimp [HMul.hMul, Mul.mul] -- Porting note: added `hMul`
rw [map₂, iSup_toAddSubmonoid]
rfl
#align submodule.mul_to_add_submonoid Submodule.mul_toAddSubmonoid
@[elab_as_elim]
protected theorem mul_induction_on {C : A → Prop} {r : A} (hr : r ∈ M * N)
(hm : ∀ m ∈ M, ∀ n ∈ N, C (m * n)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := by
rw [← mem_toAddSubmonoid, mul_toAddSubmonoid] at hr
exact AddSubmonoid.mul_induction_on hr hm ha
#align submodule.mul_induction_on Submodule.mul_induction_on
/-- A dependent version of `mul_induction_on`. -/
@[elab_as_elim]
protected theorem mul_induction_on' {C : ∀ r, r ∈ M * N → Prop}
(mem_mul_mem : ∀ m (hm : m ∈ M) n (hn : n ∈ N), C (m * n) (mul_mem_mul hm hn))
(add : ∀ x hx y hy, C x hx → C y hy → C (x + y) (add_mem hx hy)) {r : A} (hr : r ∈ M * N) :
C r hr := by
refine Exists.elim ?_ fun (hr : r ∈ M * N) (hc : C r hr) => hc
exact
Submodule.mul_induction_on hr
(fun x hx y hy => ⟨_, mem_mul_mem _ hx _ hy⟩)
fun x y ⟨_, hx⟩ ⟨_, hy⟩ => ⟨_, add _ _ _ _ hx hy⟩
#align submodule.mul_induction_on' Submodule.mul_induction_on'
variable (R)
theorem span_mul_span : span R S * span R T = span R (S * T) :=
map₂_span_span _ _ _ _
#align submodule.span_mul_span Submodule.span_mul_span
variable {R}
variable (M N P Q)
@[simp]
theorem mul_bot : M * ⊥ = ⊥ :=
map₂_bot_right _ _
#align submodule.mul_bot Submodule.mul_bot
@[simp]
theorem bot_mul : ⊥ * M = ⊥ :=
map₂_bot_left _ _
#align submodule.bot_mul Submodule.bot_mul
-- @[simp] -- Porting note (#10618): simp can prove this once we have a monoid structure
protected theorem one_mul : (1 : Submodule R A) * M = M := by
conv_lhs => rw [one_eq_span, ← span_eq M]
erw [span_mul_span, one_mul, span_eq]
#align submodule.one_mul Submodule.one_mul
-- @[simp] -- Porting note (#10618): simp can prove this once we have a monoid structure
protected theorem mul_one : M * 1 = M := by
conv_lhs => rw [one_eq_span, ← span_eq M]
erw [span_mul_span, mul_one, span_eq]
#align submodule.mul_one Submodule.mul_one
variable {M N P Q}
@[mono]
theorem mul_le_mul (hmp : M ≤ P) (hnq : N ≤ Q) : M * N ≤ P * Q :=
map₂_le_map₂ hmp hnq
#align submodule.mul_le_mul Submodule.mul_le_mul
theorem mul_le_mul_left (h : M ≤ N) : M * P ≤ N * P :=
map₂_le_map₂_left h
#align submodule.mul_le_mul_left Submodule.mul_le_mul_left
theorem mul_le_mul_right (h : N ≤ P) : M * N ≤ M * P :=
map₂_le_map₂_right h
#align submodule.mul_le_mul_right Submodule.mul_le_mul_right
variable (M N P)
theorem mul_sup : M * (N ⊔ P) = M * N ⊔ M * P :=
map₂_sup_right _ _ _ _
#align submodule.mul_sup Submodule.mul_sup
theorem sup_mul : (M ⊔ N) * P = M * P ⊔ N * P :=
map₂_sup_left _ _ _ _
#align submodule.sup_mul Submodule.sup_mul
theorem mul_subset_mul : (↑M : Set A) * (↑N : Set A) ⊆ (↑(M * N) : Set A) :=
image2_subset_map₂ (Algebra.lmul R A).toLinearMap M N
#align submodule.mul_subset_mul Submodule.mul_subset_mul
protected theorem map_mul {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') :
map f.toLinearMap (M * N) = map f.toLinearMap M * map f.toLinearMap N :=
calc
map f.toLinearMap (M * N) = ⨆ i : M, (N.map (LinearMap.mul R A i)).map f.toLinearMap :=
map_iSup _ _
_ = map f.toLinearMap M * map f.toLinearMap N := by
apply congr_arg sSup
ext S
constructor <;> rintro ⟨y, hy⟩
· use ⟨f y, mem_map.mpr ⟨y.1, y.2, rfl⟩⟩ -- Porting note: added `⟨⟩`
refine Eq.trans ?_ hy
ext
simp
· obtain ⟨y', hy', fy_eq⟩ := mem_map.mp y.2
use ⟨y', hy'⟩ -- Porting note: added `⟨⟩`
refine Eq.trans ?_ hy
rw [f.toLinearMap_apply] at fy_eq
ext
simp [fy_eq]
#align submodule.map_mul Submodule.map_mul
theorem map_op_mul :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) =
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N *
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by
apply le_antisymm
· simp_rw [map_le_iff_le_comap]
refine mul_le.2 fun m hm n hn => ?_
rw [mem_comap, map_equiv_eq_comap_symm, map_equiv_eq_comap_symm]
show op n * op m ∈ _
exact mul_mem_mul hn hm
· refine mul_le.2 (MulOpposite.rec' fun m hm => MulOpposite.rec' fun n hn => ?_)
rw [Submodule.mem_map_equiv] at hm hn ⊢
exact mul_mem_mul hn hm
#align submodule.map_op_mul Submodule.map_op_mul
theorem comap_unop_mul :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) =
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N *
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M := by
simp_rw [← map_equiv_eq_comap_symm, map_op_mul]
#align submodule.comap_unop_mul Submodule.comap_unop_mul
theorem map_unop_mul (M N : Submodule R Aᵐᵒᵖ) :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M * N) =
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) N *
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M :=
have : Function.Injective (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) :=
LinearEquiv.injective _
map_injective_of_injective this <| by
rw [← map_comp, map_op_mul, ← map_comp, ← map_comp, LinearEquiv.comp_coe,
LinearEquiv.symm_trans_self, LinearEquiv.refl_toLinearMap, map_id, map_id, map_id]
#align submodule.map_unop_mul Submodule.map_unop_mul
theorem comap_op_mul (M N : Submodule R Aᵐᵒᵖ) :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M * N) =
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) N *
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M := by
simp_rw [comap_equiv_eq_map_symm, map_unop_mul]
#align submodule.comap_op_mul Submodule.comap_op_mul
lemma restrictScalars_mul {A B C} [CommSemiring A] [CommSemiring B] [Semiring C]
[Algebra A B] [Algebra A C] [Algebra B C] [IsScalarTower A B C] {I J : Submodule B C} :
(I * J).restrictScalars A = I.restrictScalars A * J.restrictScalars A := by
apply le_antisymm
· intro x (hx : x ∈ I * J)
refine Submodule.mul_induction_on hx ?_ ?_
· exact fun m hm n hn ↦ mul_mem_mul hm hn
· exact fun _ _ ↦ add_mem
· exact mul_le.mpr (fun _ hm _ hn ↦ mul_mem_mul hm hn)
section
open Pointwise
/-- `Submodule.pointwiseNeg` distributes over multiplication.
This is available as an instance in the `Pointwise` locale. -/
protected def hasDistribPointwiseNeg {A} [Ring A] [Algebra R A] : HasDistribNeg (Submodule R A) :=
toAddSubmonoid_injective.hasDistribNeg _ neg_toAddSubmonoid mul_toAddSubmonoid
#align submodule.has_distrib_pointwise_neg Submodule.hasDistribPointwiseNeg
scoped[Pointwise] attribute [instance] Submodule.hasDistribPointwiseNeg
end
section DecidableEq
open scoped Classical
theorem mem_span_mul_finite_of_mem_span_mul {R A} [Semiring R] [AddCommMonoid A] [Mul A]
[Module R A] {S : Set A} {S' : Set A} {x : A} (hx : x ∈ span R (S * S')) :
∃ T T' : Finset A, ↑T ⊆ S ∧ ↑T' ⊆ S' ∧ x ∈ span R (T * T' : Set A) := by
obtain ⟨U, h, hU⟩ := mem_span_finite_of_mem_span hx
obtain ⟨T, T', hS, hS', h⟩ := Finset.subset_mul h
use T, T', hS, hS'
have h' : (U : Set A) ⊆ T * T' := by assumption_mod_cast
have h'' := span_mono h' hU
assumption
#align submodule.mem_span_mul_finite_of_mem_span_mul Submodule.mem_span_mul_finite_of_mem_span_mul
end DecidableEq
theorem mul_eq_span_mul_set (s t : Submodule R A) : s * t = span R ((s : Set A) * (t : Set A)) :=
map₂_eq_span_image2 _ s t
#align submodule.mul_eq_span_mul_set Submodule.mul_eq_span_mul_set
theorem iSup_mul (s : ι → Submodule R A) (t : Submodule R A) : (⨆ i, s i) * t = ⨆ i, s i * t :=
map₂_iSup_left _ s t
#align submodule.supr_mul Submodule.iSup_mul
theorem mul_iSup (t : Submodule R A) (s : ι → Submodule R A) : (t * ⨆ i, s i) = ⨆ i, t * s i :=
map₂_iSup_right _ t s
#align submodule.mul_supr Submodule.mul_iSup
theorem mem_span_mul_finite_of_mem_mul {P Q : Submodule R A} {x : A} (hx : x ∈ P * Q) :
∃ T T' : Finset A, (T : Set A) ⊆ P ∧ (T' : Set A) ⊆ Q ∧ x ∈ span R (T * T' : Set A) :=
Submodule.mem_span_mul_finite_of_mem_span_mul
(by rwa [← Submodule.span_eq P, ← Submodule.span_eq Q, Submodule.span_mul_span] at hx)
#align submodule.mem_span_mul_finite_of_mem_mul Submodule.mem_span_mul_finite_of_mem_mul
variable {M N P}
theorem mem_span_singleton_mul {x y : A} : x ∈ span R {y} * P ↔ ∃ z ∈ P, y * z = x := by
-- Porting note: need both `*` and `Mul.mul`
simp_rw [(· * ·), Mul.mul, map₂_span_singleton_eq_map]
rfl
#align submodule.mem_span_singleton_mul Submodule.mem_span_singleton_mul
theorem mem_mul_span_singleton {x y : A} : x ∈ P * span R {y} ↔ ∃ z ∈ P, z * y = x := by
-- Porting note: need both `*` and `Mul.mul`
simp_rw [(· * ·), Mul.mul, map₂_span_singleton_eq_map_flip]
rfl
#align submodule.mem_mul_span_singleton Submodule.mem_mul_span_singleton
lemma span_singleton_mul {x : A} {p : Submodule R A} :
Submodule.span R {x} * p = x • p := ext fun _ ↦ mem_span_singleton_mul
lemma mem_smul_iff_inv_mul_mem {S} [Field S] [Algebra R S] {x : S} {p : Submodule R S} {y : S}
(hx : x ≠ 0) : y ∈ x • p ↔ x⁻¹ * y ∈ p := by
constructor
· rintro ⟨a, ha : a ∈ p, rfl⟩; simpa [inv_mul_cancel_left₀ hx]
· exact fun h ↦ ⟨_, h, by simp [mul_inv_cancel_left₀ hx]⟩
lemma mul_mem_smul_iff {S} [CommRing S] [Algebra R S] {x : S} {p : Submodule R S} {y : S}
(hx : x ∈ nonZeroDivisors S) :
x * y ∈ x • p ↔ y ∈ p :=
show Exists _ ↔ _ by simp [mul_cancel_left_mem_nonZeroDivisors hx]
variable (M N) in
theorem mul_smul_mul_eq_smul_mul_smul (x y : R) : (x * y) • (M * N) = (x • M) * (y • N) := by
ext
refine ⟨?_, fun hx ↦ Submodule.mul_induction_on hx ?_ fun _ _ hx hy ↦ Submodule.add_mem _ hx hy⟩
· rintro ⟨_, hx, rfl⟩
rw [DistribMulAction.toLinearMap_apply]
refine Submodule.mul_induction_on hx (fun m hm n hn ↦ ?_) (fun _ _ hn hm ↦ ?_)
· rw [← smul_mul_smul x y m n]
exact mul_mem_mul (smul_mem_pointwise_smul m x M hm) (smul_mem_pointwise_smul n y N hn)
· rw [smul_add]
exact Submodule.add_mem _ hn hm
· rintro _ ⟨m, hm, rfl⟩ _ ⟨n, hn, rfl⟩
erw [smul_mul_smul x y m n]
exact smul_mem_pointwise_smul _ _ _ (mul_mem_mul hm hn)
/-- Sub-R-modules of an R-algebra form an idempotent semiring. -/
instance idemSemiring : IdemSemiring (Submodule R A) :=
{ toAddSubmonoid_injective.semigroup _ fun m n : Submodule R A => mul_toAddSubmonoid m n,
AddMonoidWithOne.unary, Submodule.pointwiseAddCommMonoid,
(by infer_instance :
Lattice (Submodule R A)) with
one_mul := Submodule.one_mul
mul_one := Submodule.mul_one
zero_mul := bot_mul
mul_zero := mul_bot
left_distrib := mul_sup
right_distrib := sup_mul,
-- Porting note: removed `(by infer_instance : OrderBot (Submodule R A))`
bot_le := fun _ => bot_le }
variable (M)
theorem span_pow (s : Set A) : ∀ n : ℕ, span R s ^ n = span R (s ^ n)
| 0 => by rw [pow_zero, pow_zero, one_eq_span_one_set]
| n + 1 => by rw [pow_succ, pow_succ, span_pow s n, span_mul_span]
#align submodule.span_pow Submodule.span_pow
theorem pow_eq_span_pow_set (n : ℕ) : M ^ n = span R ((M : Set A) ^ n) := by
rw [← span_pow, span_eq]
#align submodule.pow_eq_span_pow_set Submodule.pow_eq_span_pow_set
theorem pow_subset_pow {n : ℕ} : (↑M : Set A) ^ n ⊆ ↑(M ^ n : Submodule R A) :=
(pow_eq_span_pow_set M n).symm ▸ subset_span
#align submodule.pow_subset_pow Submodule.pow_subset_pow
theorem pow_mem_pow {x : A} (hx : x ∈ M) (n : ℕ) : x ^ n ∈ M ^ n :=
pow_subset_pow _ <| Set.pow_mem_pow hx _
#align submodule.pow_mem_pow Submodule.pow_mem_pow
theorem pow_toAddSubmonoid {n : ℕ} (h : n ≠ 0) : (M ^ n).toAddSubmonoid = M.toAddSubmonoid ^ n := by
induction' n with n ih
· exact (h rfl).elim
· rw [pow_succ, pow_succ, mul_toAddSubmonoid]
cases n with
| zero => rw [pow_zero, pow_zero, one_mul, ← mul_toAddSubmonoid, one_mul]
| succ n => rw [ih n.succ_ne_zero]
#align submodule.pow_to_add_submonoid Submodule.pow_toAddSubmonoid
theorem le_pow_toAddSubmonoid {n : ℕ} : M.toAddSubmonoid ^ n ≤ (M ^ n).toAddSubmonoid := by
obtain rfl | hn := Decidable.eq_or_ne n 0
· rw [pow_zero, pow_zero]
exact le_one_toAddSubmonoid
· exact (pow_toAddSubmonoid M hn).ge
#align submodule.le_pow_to_add_submonoid Submodule.le_pow_toAddSubmonoid
/-- Dependent version of `Submodule.pow_induction_on_left`. -/
@[elab_as_elim]
protected theorem pow_induction_on_left' {C : ∀ (n : ℕ) (x), x ∈ M ^ n → Prop}
(algebraMap : ∀ r : R, C 0 (algebraMap _ _ r) (algebraMap_mem r))
(add : ∀ x y i hx hy, C i x hx → C i y hy → C i (x + y) (add_mem ‹_› ‹_›))
(mem_mul : ∀ m (hm : m ∈ M), ∀ (i x hx), C i x hx → C i.succ (m * x)
((pow_succ' M i).symm ▸ (mul_mem_mul hm hx)))
-- Porting note: swapped argument order to match order of `C`
{n : ℕ} {x : A}
(hx : x ∈ M ^ n) : C n x hx := by
induction' n with n n_ih generalizing x
· rw [pow_zero] at hx
obtain ⟨r, rfl⟩ := hx
exact algebraMap r
revert hx
simp_rw [pow_succ']
intro hx
exact
Submodule.mul_induction_on' (fun m hm x ih => mem_mul _ hm _ _ _ (n_ih ih))
(fun x hx y hy Cx Cy => add _ _ _ _ _ Cx Cy) hx
#align submodule.pow_induction_on_left' Submodule.pow_induction_on_left'
/-- Dependent version of `Submodule.pow_induction_on_right`. -/
@[elab_as_elim]
protected theorem pow_induction_on_right' {C : ∀ (n : ℕ) (x), x ∈ M ^ n → Prop}
(algebraMap : ∀ r : R, C 0 (algebraMap _ _ r) (algebraMap_mem r))
(add : ∀ x y i hx hy, C i x hx → C i y hy → C i (x + y) (add_mem ‹_› ‹_›))
(mul_mem :
∀ i x hx, C i x hx →
∀ m (hm : m ∈ M), C i.succ (x * m) (mul_mem_mul hx hm))
-- Porting note: swapped argument order to match order of `C`
{n : ℕ} {x : A} (hx : x ∈ M ^ n) : C n x hx := by
induction' n with n n_ih generalizing x
· rw [pow_zero] at hx
obtain ⟨r, rfl⟩ := hx
exact algebraMap r
revert hx
simp_rw [pow_succ]
intro hx
exact
Submodule.mul_induction_on' (fun m hm x ih => mul_mem _ _ hm (n_ih _) _ ih)
(fun x hx y hy Cx Cy => add _ _ _ _ _ Cx Cy) hx
#align submodule.pow_induction_on_right' Submodule.pow_induction_on_right'
/-- To show a property on elements of `M ^ n` holds, it suffices to show that it holds for scalars,
is closed under addition, and holds for `m * x` where `m ∈ M` and it holds for `x` -/
@[elab_as_elim]
protected theorem pow_induction_on_left {C : A → Prop} (hr : ∀ r : R, C (algebraMap _ _ r))
(hadd : ∀ x y, C x → C y → C (x + y)) (hmul : ∀ m ∈ M, ∀ (x), C x → C (m * x)) {x : A} {n : ℕ}
(hx : x ∈ M ^ n) : C x :=
-- Porting note: `M` is explicit yet can't be passed positionally!
Submodule.pow_induction_on_left' (M := M) (C := fun _ a _ => C a) hr
(fun x y _i _hx _hy => hadd x y)
(fun _m hm _i _x _hx => hmul _ hm _) hx
#align submodule.pow_induction_on_left Submodule.pow_induction_on_left
/-- To show a property on elements of `M ^ n` holds, it suffices to show that it holds for scalars,
is closed under addition, and holds for `x * m` where `m ∈ M` and it holds for `x` -/
@[elab_as_elim]
protected theorem pow_induction_on_right {C : A → Prop} (hr : ∀ r : R, C (algebraMap _ _ r))
(hadd : ∀ x y, C x → C y → C (x + y)) (hmul : ∀ x, C x → ∀ m ∈ M, C (x * m)) {x : A} {n : ℕ}
(hx : x ∈ M ^ n) : C x :=
Submodule.pow_induction_on_right' (M := M) (C := fun _ a _ => C a) hr
(fun x y _i _hx _hy => hadd x y)
(fun _i _x _hx => hmul _) hx
#align submodule.pow_induction_on_right Submodule.pow_induction_on_right
/-- `Submonoid.map` as a `MonoidWithZeroHom`, when applied to `AlgHom`s. -/
@[simps]
def mapHom {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') :
Submodule R A →*₀ Submodule R A' where
toFun := map f.toLinearMap
map_zero' := Submodule.map_bot _
map_one' := Submodule.map_one _
map_mul' _ _ := Submodule.map_mul _ _ _
#align submodule.map_hom Submodule.mapHom
/-- The ring of submodules of the opposite algebra is isomorphic to the opposite ring of
submodules. -/
@[simps apply symm_apply]
def equivOpposite : Submodule R Aᵐᵒᵖ ≃+* (Submodule R A)ᵐᵒᵖ where
toFun p := op <| p.comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ)
invFun p := p.unop.comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A)
left_inv p := SetLike.coe_injective <| rfl
right_inv p := unop_injective <| SetLike.coe_injective rfl
map_add' p q := by simp [comap_equiv_eq_map_symm, ← op_add]
map_mul' p q := congr_arg op <| comap_op_mul _ _
#align submodule.equiv_opposite Submodule.equivOpposite
protected theorem map_pow {A'} [Semiring A'] [Algebra R A'] (f : A →ₐ[R] A') (n : ℕ) :
map f.toLinearMap (M ^ n) = map f.toLinearMap M ^ n :=
map_pow (mapHom f) M n
#align submodule.map_pow Submodule.map_pow
theorem comap_unop_pow (n : ℕ) :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M ^ n) =
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M ^ n :=
(equivOpposite : Submodule R Aᵐᵒᵖ ≃+* _).symm.map_pow (op M) n
#align submodule.comap_unop_pow Submodule.comap_unop_pow
theorem comap_op_pow (n : ℕ) (M : Submodule R Aᵐᵒᵖ) :
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M ^ n) =
comap (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M ^ n :=
op_injective <| (equivOpposite : Submodule R Aᵐᵒᵖ ≃+* _).map_pow M n
#align submodule.comap_op_pow Submodule.comap_op_pow
theorem map_op_pow (n : ℕ) :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) (M ^ n) =
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ) : A →ₗ[R] Aᵐᵒᵖ) M ^ n := by
rw [map_equiv_eq_comap_symm, map_equiv_eq_comap_symm, comap_unop_pow]
#align submodule.map_op_pow Submodule.map_op_pow
theorem map_unop_pow (n : ℕ) (M : Submodule R Aᵐᵒᵖ) :
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) (M ^ n) =
map (↑(opLinearEquiv R : A ≃ₗ[R] Aᵐᵒᵖ).symm : Aᵐᵒᵖ →ₗ[R] A) M ^ n := by
rw [← comap_equiv_eq_map_symm, ← comap_equiv_eq_map_symm, comap_op_pow]
#align submodule.map_unop_pow Submodule.map_unop_pow
/-- `span` is a semiring homomorphism (recall multiplication is pointwise multiplication of subsets
on either side). -/
@[simps]
def span.ringHom : SetSemiring A →+* Submodule R A where
-- Note: the hint `(α := A)` is new in #8386
toFun s := Submodule.span R (SetSemiring.down (α := A) s)
map_zero' := span_empty
map_one' := one_eq_span.symm
map_add' := span_union
map_mul' s t := by
dsimp only -- Porting note: new, needed due to new-style structures
rw [SetSemiring.down_mul, span_mul_span]
#align submodule.span.ring_hom Submodule.span.ringHom
section
variable {α : Type*} [Monoid α] [MulSemiringAction α A] [SMulCommClass α R A]
/-- The action on a submodule corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale.
This is a stronger version of `Submodule.pointwiseDistribMulAction`. -/
protected def pointwiseMulSemiringAction : MulSemiringAction α (Submodule R A) :=
{
Submodule.pointwiseDistribMulAction with
smul_mul := fun r x y => Submodule.map_mul x y <| MulSemiringAction.toAlgHom R A r
smul_one := fun r => Submodule.map_one <| MulSemiringAction.toAlgHom R A r }
#align submodule.pointwise_mul_semiring_action Submodule.pointwiseMulSemiringAction
scoped[Pointwise] attribute [instance] Submodule.pointwiseMulSemiringAction
end
end Ring
section CommRing
variable {A : Type v} [CommSemiring A] [Algebra R A]
variable {M N : Submodule R A} {m n : A}
theorem mul_mem_mul_rev (hm : m ∈ M) (hn : n ∈ N) : n * m ∈ M * N :=
mul_comm m n ▸ mul_mem_mul hm hn
#align submodule.mul_mem_mul_rev Submodule.mul_mem_mul_rev
variable (M N)
protected theorem mul_comm : M * N = N * M :=
le_antisymm (mul_le.2 fun _r hrm _s hsn => mul_mem_mul_rev hsn hrm)
(mul_le.2 fun _r hrn _s hsm => mul_mem_mul_rev hsm hrn)
#align submodule.mul_comm Submodule.mul_comm
/-- Sub-R-modules of an R-algebra A form a semiring. -/
instance : IdemCommSemiring (Submodule R A) :=
{ Submodule.idemSemiring with mul_comm := Submodule.mul_comm }
theorem prod_span {ι : Type*} (s : Finset ι) (M : ι → Set A) :
(∏ i ∈ s, Submodule.span R (M i)) = Submodule.span R (∏ i ∈ s, M i) := by
letI := Classical.decEq ι
refine Finset.induction_on s ?_ ?_
· simp [one_eq_span, Set.singleton_one]
· intro _ _ H ih
rw [Finset.prod_insert H, Finset.prod_insert H, ih, span_mul_span]
#align submodule.prod_span Submodule.prod_span
| Mathlib/Algebra/Algebra/Operations.lean | 653 | 655 | theorem prod_span_singleton {ι : Type*} (s : Finset ι) (x : ι → A) :
(∏ i ∈ s, span R ({x i} : Set A)) = span R {∏ i ∈ s, x i} := by |
rw [prod_span, Set.finset_prod_singleton]
|
/-
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.Data.List.Cycle
import Mathlib.GroupTheory.Perm.Cycle.Type
import Mathlib.GroupTheory.Perm.List
#align_import group_theory.perm.cycle.concrete from "leanprover-community/mathlib"@"00638177efd1b2534fc5269363ebf42a7871df9a"
/-!
# Properties of cyclic permutations constructed from lists/cycles
In the following, `{α : Type*} [Fintype α] [DecidableEq α]`.
## Main definitions
* `Cycle.formPerm`: the cyclic permutation created by looping over a `Cycle α`
* `Equiv.Perm.toList`: the list formed by iterating application of a permutation
* `Equiv.Perm.toCycle`: the cycle formed by iterating application of a permutation
* `Equiv.Perm.isoCycle`: the equivalence between cyclic permutations `f : Perm α`
and the terms of `Cycle α` that correspond to them
* `Equiv.Perm.isoCycle'`: the same equivalence as `Equiv.Perm.isoCycle`
but with evaluation via choosing over fintypes
* The notation `c[1, 2, 3]` to emulate notation of cyclic permutations `(1 2 3)`
* A `Repr` instance for any `Perm α`, by representing the `Finset` of
`Cycle α` that correspond to the cycle factors.
## Main results
* `List.isCycle_formPerm`: a nontrivial list without duplicates, when interpreted as
a permutation, is cyclic
* `Equiv.Perm.IsCycle.existsUnique_cycle`: there is only one nontrivial `Cycle α`
corresponding to each cyclic `f : Perm α`
## Implementation details
The forward direction of `Equiv.Perm.isoCycle'` uses `Fintype.choose` of the uniqueness
result, relying on the `Fintype` instance of a `Cycle.nodup` subtype.
It is unclear if this works faster than the `Equiv.Perm.toCycle`, which relies
on recursion over `Finset.univ`.
Running `#eval` on even a simple noncyclic permutation `c[(1 : Fin 7), 2, 3] * c[0, 5]`
to show it takes a long time. TODO: is this because computing the cycle factors is slow?
-/
open Equiv Equiv.Perm List
variable {α : Type*}
namespace List
variable [DecidableEq α] {l l' : List α}
theorem formPerm_disjoint_iff (hl : Nodup l) (hl' : Nodup l') (hn : 2 ≤ l.length)
(hn' : 2 ≤ l'.length) : Perm.Disjoint (formPerm l) (formPerm l') ↔ l.Disjoint l' := by
rw [disjoint_iff_eq_or_eq, List.Disjoint]
constructor
· rintro h x hx hx'
specialize h x
rw [formPerm_apply_mem_eq_self_iff _ hl _ hx, formPerm_apply_mem_eq_self_iff _ hl' _ hx'] at h
omega
· intro h x
by_cases hx : x ∈ l
on_goal 1 => by_cases hx' : x ∈ l'
· exact (h hx hx').elim
all_goals have := formPerm_eq_self_of_not_mem _ _ ‹_›; tauto
#align list.form_perm_disjoint_iff List.formPerm_disjoint_iff
theorem isCycle_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) : IsCycle (formPerm l) := by
cases' l with x l
· set_option tactic.skipAssignedInstances false in norm_num at hn
induction' l with y l generalizing x
· set_option tactic.skipAssignedInstances false in norm_num at hn
· use x
constructor
· rwa [formPerm_apply_mem_ne_self_iff _ hl _ (mem_cons_self _ _)]
· intro w hw
have : w ∈ x::y::l := mem_of_formPerm_ne_self _ _ hw
obtain ⟨k, hk⟩ := get_of_mem this
use k
rw [← hk]
simp only [zpow_natCast, formPerm_pow_apply_head _ _ hl k, Nat.mod_eq_of_lt k.isLt]
#align list.is_cycle_form_perm List.isCycle_formPerm
theorem pairwise_sameCycle_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) :
Pairwise l.formPerm.SameCycle l :=
Pairwise.imp_mem.mpr
(pairwise_of_forall fun _ _ hx hy =>
(isCycle_formPerm hl hn).sameCycle ((formPerm_apply_mem_ne_self_iff _ hl _ hx).mpr hn)
((formPerm_apply_mem_ne_self_iff _ hl _ hy).mpr hn))
#align list.pairwise_same_cycle_form_perm List.pairwise_sameCycle_formPerm
theorem cycleOf_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) (x) :
cycleOf l.attach.formPerm x = l.attach.formPerm :=
have hn : 2 ≤ l.attach.length := by rwa [← length_attach] at hn
have hl : l.attach.Nodup := by rwa [← nodup_attach] at hl
(isCycle_formPerm hl hn).cycleOf_eq
((formPerm_apply_mem_ne_self_iff _ hl _ (mem_attach _ _)).mpr hn)
#align list.cycle_of_form_perm List.cycleOf_formPerm
theorem cycleType_formPerm (hl : Nodup l) (hn : 2 ≤ l.length) :
cycleType l.attach.formPerm = {l.length} := by
rw [← length_attach] at hn
rw [← nodup_attach] at hl
rw [cycleType_eq [l.attach.formPerm]]
· simp only [map, Function.comp_apply]
rw [support_formPerm_of_nodup _ hl, card_toFinset, dedup_eq_self.mpr hl]
· simp
· intro x h
simp [h, Nat.succ_le_succ_iff] at hn
· simp
· simpa using isCycle_formPerm hl hn
· simp
#align list.cycle_type_form_perm List.cycleType_formPerm
theorem formPerm_apply_mem_eq_next (hl : Nodup l) (x : α) (hx : x ∈ l) :
formPerm l x = next l x hx := by
obtain ⟨k, rfl⟩ := get_of_mem hx
rw [next_get _ hl, formPerm_apply_get _ hl]
#align list.form_perm_apply_mem_eq_next List.formPerm_apply_mem_eq_next
end List
namespace Cycle
variable [DecidableEq α] (s s' : Cycle α)
/-- A cycle `s : Cycle α`, given `Nodup s` can be interpreted as an `Equiv.Perm α`
where each element in the list is permuted to the next one, defined as `formPerm`.
-/
def formPerm : ∀ s : Cycle α, Nodup s → Equiv.Perm α :=
fun s => Quotient.hrecOn s (fun l _ => List.formPerm l) fun l₁ l₂ (h : l₁ ~r l₂) => by
apply Function.hfunext
· ext
exact h.nodup_iff
· intro h₁ h₂ _
exact heq_of_eq (formPerm_eq_of_isRotated h₁ h)
#align cycle.form_perm Cycle.formPerm
@[simp]
theorem formPerm_coe (l : List α) (hl : l.Nodup) : formPerm (l : Cycle α) hl = l.formPerm :=
rfl
#align cycle.form_perm_coe Cycle.formPerm_coe
theorem formPerm_subsingleton (s : Cycle α) (h : Subsingleton s) : formPerm s h.nodup = 1 := by
induction' s using Quot.inductionOn with s
simp only [formPerm_coe, mk_eq_coe]
simp only [length_subsingleton_iff, length_coe, mk_eq_coe] at h
cases' s with hd tl
· simp
· simp only [length_eq_zero, add_le_iff_nonpos_left, List.length, nonpos_iff_eq_zero] at h
simp [h]
#align cycle.form_perm_subsingleton Cycle.formPerm_subsingleton
theorem isCycle_formPerm (s : Cycle α) (h : Nodup s) (hn : Nontrivial s) :
IsCycle (formPerm s h) := by
induction s using Quot.inductionOn
exact List.isCycle_formPerm h (length_nontrivial hn)
#align cycle.is_cycle_form_perm Cycle.isCycle_formPerm
theorem support_formPerm [Fintype α] (s : Cycle α) (h : Nodup s) (hn : Nontrivial s) :
support (formPerm s h) = s.toFinset := by
induction' s using Quot.inductionOn with s
refine support_formPerm_of_nodup s h ?_
rintro _ rfl
simpa [Nat.succ_le_succ_iff] using length_nontrivial hn
#align cycle.support_form_perm Cycle.support_formPerm
| Mathlib/GroupTheory/Perm/Cycle/Concrete.lean | 173 | 176 | theorem formPerm_eq_self_of_not_mem (s : Cycle α) (h : Nodup s) (x : α) (hx : x ∉ s) :
formPerm s h x = x := by |
induction s using Quot.inductionOn
simpa using List.formPerm_eq_self_of_not_mem _ _ hx
|
/-
Copyright (c) 2022 Benjamin Davidson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Benjamin Davidson, Devon Tuma, Eric Rodriguez, Oliver Nash
-/
import Mathlib.Data.Set.Pointwise.Interval
import Mathlib.Topology.Algebra.Field
import Mathlib.Topology.Algebra.Order.Group
#align_import topology.algebra.order.field from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd"
/-!
# Topologies on linear ordered fields
In this file we prove that a linear ordered field with order topology has continuous multiplication
and division (apart from zero in the denominator). We also prove theorems like
`Filter.Tendsto.mul_atTop`: if `f` tends to a positive number and `g` tends to positive infinity,
then `f * g` tends to positive infinity.
-/
open Set Filter TopologicalSpace Function
open scoped Pointwise Topology
open OrderDual (toDual ofDual)
/-- If a (possibly non-unital and/or non-associative) ring `R` admits a submultiplicative
nonnegative norm `norm : R → 𝕜`, where `𝕜` is a linear ordered field, and the open balls
`{ x | norm x < ε }`, `ε > 0`, form a basis of neighborhoods of zero, then `R` is a topological
ring. -/
theorem TopologicalRing.of_norm {R 𝕜 : Type*} [NonUnitalNonAssocRing R] [LinearOrderedField 𝕜]
[TopologicalSpace R] [TopologicalAddGroup R] (norm : R → 𝕜)
(norm_nonneg : ∀ x, 0 ≤ norm x) (norm_mul_le : ∀ x y, norm (x * y) ≤ norm x * norm y)
(nhds_basis : (𝓝 (0 : R)).HasBasis ((0 : 𝕜) < ·) (fun ε ↦ { x | norm x < ε })) :
TopologicalRing R := by
have h0 : ∀ f : R → R, ∀ c ≥ (0 : 𝕜), (∀ x, norm (f x) ≤ c * norm x) →
Tendsto f (𝓝 0) (𝓝 0) := by
refine fun f c c0 hf ↦ (nhds_basis.tendsto_iff nhds_basis).2 fun ε ε0 ↦ ?_
rcases exists_pos_mul_lt ε0 c with ⟨δ, δ0, hδ⟩
refine ⟨δ, δ0, fun x hx ↦ (hf _).trans_lt ?_⟩
exact (mul_le_mul_of_nonneg_left (le_of_lt hx) c0).trans_lt hδ
apply TopologicalRing.of_addGroup_of_nhds_zero
case hmul =>
refine ((nhds_basis.prod nhds_basis).tendsto_iff nhds_basis).2 fun ε ε0 ↦ ?_
refine ⟨(1, ε), ⟨one_pos, ε0⟩, fun (x, y) ⟨hx, hy⟩ => ?_⟩
simp only [sub_zero] at *
calc norm (x * y) ≤ norm x * norm y := norm_mul_le _ _
_ < ε := mul_lt_of_le_one_of_lt_of_nonneg hx.le hy (norm_nonneg _)
case hmul_left => exact fun x => h0 _ (norm x) (norm_nonneg _) (norm_mul_le x)
case hmul_right =>
exact fun y => h0 (· * y) (norm y) (norm_nonneg y) fun x =>
(norm_mul_le x y).trans_eq (mul_comm _ _)
variable {𝕜 α : Type*} [LinearOrderedField 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜]
{l : Filter α} {f g : α → 𝕜}
-- see Note [lower instance priority]
instance (priority := 100) LinearOrderedField.topologicalRing : TopologicalRing 𝕜 :=
.of_norm abs abs_nonneg (fun _ _ ↦ (abs_mul _ _).le) <| by
simpa using nhds_basis_abs_sub_lt (0 : 𝕜)
/-- In a linearly ordered field with the order topology, if `f` tends to `Filter.atTop` and `g`
tends to a positive constant `C` then `f * g` tends to `Filter.atTop`. -/
theorem Filter.Tendsto.atTop_mul {C : 𝕜} (hC : 0 < C) (hf : Tendsto f l atTop)
(hg : Tendsto g l (𝓝 C)) : Tendsto (fun x => f x * g x) l atTop := by
refine tendsto_atTop_mono' _ ?_ (hf.atTop_mul_const (half_pos hC))
filter_upwards [hg.eventually (lt_mem_nhds (half_lt_self hC)), hf.eventually_ge_atTop 0]
with x hg hf using mul_le_mul_of_nonneg_left hg.le hf
#align filter.tendsto.at_top_mul Filter.Tendsto.atTop_mul
/-- In a linearly ordered field with the order topology, if `f` tends to a positive constant `C` and
`g` tends to `Filter.atTop` then `f * g` tends to `Filter.atTop`. -/
theorem Filter.Tendsto.mul_atTop {C : 𝕜} (hC : 0 < C) (hf : Tendsto f l (𝓝 C))
(hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atTop := by
simpa only [mul_comm] using hg.atTop_mul hC hf
#align filter.tendsto.mul_at_top Filter.Tendsto.mul_atTop
/-- In a linearly ordered field with the order topology, if `f` tends to `Filter.atTop` and `g`
tends to a negative constant `C` then `f * g` tends to `Filter.atBot`. -/
theorem Filter.Tendsto.atTop_mul_neg {C : 𝕜} (hC : C < 0) (hf : Tendsto f l atTop)
(hg : Tendsto g l (𝓝 C)) : Tendsto (fun x => f x * g x) l atBot := by
have := hf.atTop_mul (neg_pos.2 hC) hg.neg
simpa only [(· ∘ ·), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_atTop_atBot.comp this
#align filter.tendsto.at_top_mul_neg Filter.Tendsto.atTop_mul_neg
/-- In a linearly ordered field with the order topology, if `f` tends to a negative constant `C` and
`g` tends to `Filter.atTop` then `f * g` tends to `Filter.atBot`. -/
theorem Filter.Tendsto.neg_mul_atTop {C : 𝕜} (hC : C < 0) (hf : Tendsto f l (𝓝 C))
(hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atBot := by
simpa only [mul_comm] using hg.atTop_mul_neg hC hf
#align filter.tendsto.neg_mul_at_top Filter.Tendsto.neg_mul_atTop
/-- In a linearly ordered field with the order topology, if `f` tends to `Filter.atBot` and `g`
tends to a positive constant `C` then `f * g` tends to `Filter.atBot`. -/
| Mathlib/Topology/Algebra/Order/Field.lean | 94 | 97 | theorem Filter.Tendsto.atBot_mul {C : 𝕜} (hC : 0 < C) (hf : Tendsto f l atBot)
(hg : Tendsto g l (𝓝 C)) : Tendsto (fun x => f x * g x) l atBot := by |
have := (tendsto_neg_atBot_atTop.comp hf).atTop_mul hC hg
simpa [(· ∘ ·)] using tendsto_neg_atTop_atBot.comp this
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell
-/
import Mathlib.Data.Nat.Factorial.Basic
import Mathlib.Order.Monotone.Basic
#align_import data.nat.choose.basic from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4"
/-!
# Binomial coefficients
This file defines binomial coefficients and proves simple lemmas (i.e. those not
requiring more imports).
## Main definition and results
* `Nat.choose`: binomial coefficients, defined inductively
* `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)`
* `Nat.choose_symm`: symmetry of binomial coefficients
* `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k`
* `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2`
* `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending
factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements
for the ascending factorial.
* `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations.
The fact that this is indeed the correct counting function for multisets is proved in
`Sym.card_sym_eq_multichoose` in `Data.Sym.Card`.
* `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`.
This is central to the "stars and bars" technique in informal mathematics, where we switch between
counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements
("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail.
## Tags
binomial coefficient, combination, multicombination, stars and bars
-/
open Nat
namespace Nat
/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial
coefficients. -/
def choose : ℕ → ℕ → ℕ
| _, 0 => 1
| 0, _ + 1 => 0
| n + 1, k + 1 => choose n k + choose n (k + 1)
#align nat.choose Nat.choose
@[simp]
theorem choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n <;> rfl
#align nat.choose_zero_right Nat.choose_zero_right
@[simp]
theorem choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 :=
rfl
#align nat.choose_zero_succ Nat.choose_zero_succ
theorem choose_succ_succ (n k : ℕ) : choose (succ n) (succ k) = choose n k + choose n (succ k) :=
rfl
#align nat.choose_succ_succ Nat.choose_succ_succ
theorem choose_succ_succ' (n k : ℕ) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) :=
rfl
theorem choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0
| _, 0, hk => absurd hk (Nat.not_lt_zero _)
| 0, k + 1, _ => choose_zero_succ _
| n + 1, k + 1, hk => by
have hnk : n < k := lt_of_succ_lt_succ hk
have hnk1 : n < k + 1 := lt_of_succ_lt hk
rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1]
#align nat.choose_eq_zero_of_lt Nat.choose_eq_zero_of_lt
@[simp]
theorem choose_self (n : ℕ) : choose n n = 1 := by
induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)]
#align nat.choose_self Nat.choose_self
@[simp]
theorem choose_succ_self (n : ℕ) : choose n (succ n) = 0 :=
choose_eq_zero_of_lt (lt_succ_self _)
#align nat.choose_succ_self Nat.choose_succ_self
@[simp]
lemma choose_one_right (n : ℕ) : choose n 1 = n := by induction n <;> simp [*, choose, Nat.add_comm]
#align nat.choose_one_right Nat.choose_one_right
-- The `n+1`-st triangle number is `n` more than the `n`-th triangle number
theorem triangle_succ (n : ℕ) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by
rw [← add_mul_div_left, Nat.mul_comm 2 n, ← Nat.mul_add, Nat.add_sub_cancel, Nat.mul_comm]
cases n <;> rfl; apply zero_lt_succ
#align nat.triangle_succ Nat.triangle_succ
/-- `choose n 2` is the `n`-th triangle number. -/
theorem choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 := by
induction' n with n ih
· simp
· rw [triangle_succ n, choose, ih]
simp [Nat.add_comm]
#align nat.choose_two_right Nat.choose_two_right
theorem choose_pos : ∀ {n k}, k ≤ n → 0 < choose n k
| 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk]; decide
| n + 1, 0, _ => by simp
| n + 1, k + 1, hk => Nat.add_pos_left (choose_pos (le_of_succ_le_succ hk)) _
#align nat.choose_pos Nat.choose_pos
theorem choose_eq_zero_iff {n k : ℕ} : n.choose k = 0 ↔ n < k :=
⟨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt⟩
#align nat.choose_eq_zero_iff Nat.choose_eq_zero_iff
theorem succ_mul_choose_eq : ∀ n k, succ n * choose n k = choose (succ n) (succ k) * succ k
| 0, 0 => by decide
| 0, k + 1 => by simp [choose]
| n + 1, 0 => by simp [choose, mul_succ, succ_eq_add_one, Nat.add_comm]
| n + 1, k + 1 => by
rw [choose_succ_succ (succ n) (succ k), Nat.add_mul, ← succ_mul_choose_eq n, mul_succ, ←
succ_mul_choose_eq n, Nat.add_right_comm, ← Nat.mul_add, ← choose_succ_succ, ← succ_mul]
#align nat.succ_mul_choose_eq Nat.succ_mul_choose_eq
theorem choose_mul_factorial_mul_factorial : ∀ {n k}, k ≤ n → choose n k * k ! * (n - k)! = n !
| 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk]
| n + 1, 0, _ => by simp
| n + 1, succ k, hk => by
rcases lt_or_eq_of_le hk with hk₁ | hk₁
· have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by
rw [← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have h₁ : (n - k)! = (n - k) * (n - k.succ)! := by
rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ]
have h₂ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by
rw [← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁)]
simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc]
have h₃ : k * n ! ≤ n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk)
rw [choose_succ_succ, Nat.add_mul, Nat.add_mul, succ_sub_succ, h, h₁, h₂, Nat.add_mul,
Nat.mul_sub_right_distrib, factorial_succ, ← Nat.add_sub_assoc h₃, Nat.add_assoc,
← Nat.add_mul, Nat.add_sub_cancel_left, Nat.add_comm]
· rw [hk₁]; simp [hk₁, Nat.mul_comm, choose, Nat.sub_self]
#align nat.choose_mul_factorial_mul_factorial Nat.choose_mul_factorial_mul_factorial
theorem choose_mul {n k s : ℕ} (hkn : k ≤ n) (hsk : s ≤ k) :
n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) :=
have h : 0 < (n - k)! * (k - s)! * s ! := by apply_rules [factorial_pos, Nat.mul_pos]
Nat.mul_right_cancel h <|
calc
n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) =
n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! := by
rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc _ s !, Nat.mul_assoc,
Nat.mul_comm (n - k)!, Nat.mul_comm s !]
_ = n ! := by
rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn]
_ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by
rw [choose_mul_factorial_mul_factorial (Nat.sub_le_sub_right hkn _),
choose_mul_factorial_mul_factorial (hsk.trans hkn)]
_ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by
rw [Nat.sub_sub_sub_cancel_right hsk, Nat.mul_assoc, Nat.mul_left_comm s !, Nat.mul_assoc,
Nat.mul_comm (k - s)!, Nat.mul_comm s !, Nat.mul_right_comm, ← Nat.mul_assoc]
#align nat.choose_mul Nat.choose_mul
theorem choose_eq_factorial_div_factorial {n k : ℕ} (hk : k ≤ n) :
choose n k = n ! / (k ! * (n - k)!) := by
rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]
exact (mul_div_left _ (Nat.mul_pos (factorial_pos _) (factorial_pos _))).symm
#align nat.choose_eq_factorial_div_factorial Nat.choose_eq_factorial_div_factorial
theorem add_choose (i j : ℕ) : (i + j).choose j = (i + j)! / (i ! * j !) := by
rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), Nat.add_sub_cancel_right,
Nat.mul_comm]
#align nat.add_choose Nat.add_choose
theorem add_choose_mul_factorial_mul_factorial (i j : ℕ) :
(i + j).choose j * i ! * j ! = (i + j)! := by
rw [← choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), Nat.add_sub_cancel_right,
Nat.mul_right_comm]
#align nat.add_choose_mul_factorial_mul_factorial Nat.add_choose_mul_factorial_mul_factorial
theorem factorial_mul_factorial_dvd_factorial {n k : ℕ} (hk : k ≤ n) : k ! * (n - k)! ∣ n ! := by
rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]; exact Nat.dvd_mul_left _ _
#align nat.factorial_mul_factorial_dvd_factorial Nat.factorial_mul_factorial_dvd_factorial
theorem factorial_mul_factorial_dvd_factorial_add (i j : ℕ) : i ! * j ! ∣ (i + j)! := by
suffices i ! * (i + j - i) ! ∣ (i + j)! by
rwa [Nat.add_sub_cancel_left i j] at this
exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _)
#align nat.factorial_mul_factorial_dvd_factorial_add Nat.factorial_mul_factorial_dvd_factorial_add
@[simp]
theorem choose_symm {n k : ℕ} (hk : k ≤ n) : choose n (n - k) = choose n k := by
rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _),
Nat.sub_sub_self hk, Nat.mul_comm]
#align nat.choose_symm Nat.choose_symm
theorem choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by
suffices choose n (n - b) = choose n b by
rw [h, Nat.add_sub_cancel_right] at this; rwa [h]
exact choose_symm (h ▸ le_add_left _ _)
#align nat.choose_symm_of_eq_add Nat.choose_symm_of_eq_add
theorem choose_symm_add {a b : ℕ} : choose (a + b) a = choose (a + b) b :=
choose_symm_of_eq_add rfl
#align nat.choose_symm_add Nat.choose_symm_add
theorem choose_symm_half (m : ℕ) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m := by
apply choose_symm_of_eq_add
rw [Nat.add_comm m 1, Nat.add_assoc 1 m m, Nat.add_comm (2 * m) 1, Nat.two_mul m]
#align nat.choose_symm_half Nat.choose_symm_half
theorem choose_succ_right_eq (n k : ℕ) : choose n (k + 1) * (k + 1) = choose n k * (n - k) := by
have e : (n + 1) * choose n k = choose n (k + 1) * (k + 1) + choose n k * (k + 1) := by
rw [← Nat.add_mul, Nat.add_comm (choose _ _), ← choose_succ_succ, succ_mul_choose_eq]
rw [← Nat.sub_eq_of_eq_add e, Nat.mul_comm, ← Nat.mul_sub_left_distrib, Nat.add_sub_add_right]
#align nat.choose_succ_right_eq Nat.choose_succ_right_eq
@[simp]
theorem choose_succ_self_right : ∀ n : ℕ, (n + 1).choose n = n + 1
| 0 => rfl
| n + 1 => by rw [choose_succ_succ, choose_succ_self_right n, choose_self]
#align nat.choose_succ_self_right Nat.choose_succ_self_right
theorem choose_mul_succ_eq (n k : ℕ) : n.choose k * (n + 1) = (n + 1).choose k * (n + 1 - k) := by
cases k with
| zero => simp
| succ k =>
obtain hk | hk := le_or_lt (k + 1) (n + 1)
· rw [choose_succ_succ, Nat.add_mul, succ_sub_succ, ← choose_succ_right_eq, ← succ_sub_succ,
Nat.mul_sub_left_distrib, Nat.add_sub_cancel' (Nat.mul_le_mul_left _ hk)]
· rw [choose_eq_zero_of_lt hk, choose_eq_zero_of_lt (n.lt_succ_self.trans hk), Nat.zero_mul,
Nat.zero_mul]
#align nat.choose_mul_succ_eq Nat.choose_mul_succ_eq
theorem ascFactorial_eq_factorial_mul_choose (n k : ℕ) :
(n + 1).ascFactorial k = k ! * (n + k).choose k := by
rw [Nat.mul_comm]
apply Nat.mul_right_cancel (n + k - k).factorial_pos
rw [choose_mul_factorial_mul_factorial <| Nat.le_add_left k n, Nat.add_sub_cancel_right,
← factorial_mul_ascFactorial, Nat.mul_comm]
#align nat.asc_factorial_eq_factorial_mul_choose Nat.ascFactorial_eq_factorial_mul_choose
theorem ascFactorial_eq_factorial_mul_choose' (n k : ℕ) :
n.ascFactorial k = k ! * (n + k - 1).choose k := by
cases n
· cases k
· rw [ascFactorial_zero, choose_zero_right, factorial_zero, Nat.mul_one]
· simp only [zero_ascFactorial, zero_eq, Nat.zero_add, succ_sub_succ_eq_sub,
Nat.le_zero_eq, Nat.sub_zero, choose_succ_self, Nat.mul_zero]
rw [ascFactorial_eq_factorial_mul_choose]
simp only [succ_add_sub_one]
theorem factorial_dvd_ascFactorial (n k : ℕ) : k ! ∣ n.ascFactorial k :=
⟨(n + k - 1).choose k, ascFactorial_eq_factorial_mul_choose' _ _⟩
#align nat.factorial_dvd_asc_factorial Nat.factorial_dvd_ascFactorial
| Mathlib/Data/Nat/Choose/Basic.lean | 257 | 261 | theorem choose_eq_asc_factorial_div_factorial (n k : ℕ) :
(n + k).choose k = (n + 1).ascFactorial k / k ! := by |
apply Nat.mul_left_cancel k.factorial_pos
rw [← ascFactorial_eq_factorial_mul_choose]
exact (Nat.mul_div_cancel' <| factorial_dvd_ascFactorial _ _).symm
|
/-
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, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.Deriv.Slope
import Mathlib.Analysis.NormedSpace.FiniteDimension
import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap
import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic
#align_import analysis.calculus.fderiv_measurable from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe"
/-!
# Derivative is measurable
In this file we prove that the derivative of any function with complete codomain is a measurable
function. Namely, we prove:
* `measurableSet_of_differentiableAt`: the set `{x | DifferentiableAt 𝕜 f x}` is measurable;
* `measurable_fderiv`: the function `fderiv 𝕜 f` is measurable;
* `measurable_fderiv_apply_const`: for a fixed vector `y`, the function `fun x ↦ fderiv 𝕜 f x y`
is measurable;
* `measurable_deriv`: the function `deriv f` is measurable (for `f : 𝕜 → F`).
We also show the same results for the right derivative on the real line
(see `measurable_derivWithin_Ici` and `measurable_derivWithin_Ioi`), following the same
proof strategy.
We also prove measurability statements for functions depending on a parameter: for `f : α → E → F`,
we show the measurability of `(p : α × E) ↦ fderiv 𝕜 (f p.1) p.2`. This requires additional
assumptions. We give versions of the above statements (appending `with_param` to their names) when
`f` is continuous and `E` is locally compact.
## Implementation
We give a proof that avoids second-countability issues, by expressing the differentiability set
as a function of open sets in the following way. Define `A (L, r, ε)` to be the set of points
where, on a ball of radius roughly `r` around `x`, the function is uniformly approximated by the
linear map `L`, up to `ε r`. It is an open set.
Let also `B (L, r, s, ε) = A (L, r, ε) ∩ A (L, s, ε)`: we require that at two possibly different
scales `r` and `s`, the function is well approximated by the linear map `L`. It is also open.
We claim that the differentiability set of `f` is exactly
`D = ⋂ ε > 0, ⋃ δ > 0, ⋂ r, s < δ, ⋃ L, B (L, r, s, ε)`.
In other words, for any `ε > 0`, we require that there is a size `δ` such that, for any two scales
below this size, the function is well approximated by a linear map, common to the two scales.
The set `⋃ L, B (L, r, s, ε)` is open, as a union of open sets. Converting the intersections and
unions to countable ones (using real numbers of the form `2 ^ (-n)`), it follows that the
differentiability set is measurable.
To prove the claim, there are two inclusions. One is trivial: if the function is differentiable
at `x`, then `x` belongs to `D` (just take `L` to be the derivative, and use that the
differentiability exactly says that the map is well approximated by `L`). This is proved in
`mem_A_of_differentiable` and `differentiable_set_subset_D`.
For the other direction, the difficulty is that `L` in the union may depend on `ε, r, s`. The key
point is that, in fact, it doesn't depend too much on them. First, if `x` belongs both to
`A (L, r, ε)` and `A (L', r, ε)`, then `L` and `L'` have to be close on a shell, and thus
`‖L - L'‖` is bounded by `ε` (see `norm_sub_le_of_mem_A`). Assume now `x ∈ D`. If one has two maps
`L` and `L'` such that `x` belongs to `A (L, r, ε)` and to `A (L', r', ε')`, one deduces that `L` is
close to `L'` by arguing as follows. Consider another scale `s` smaller than `r` and `r'`. Take a
linear map `L₁` that approximates `f` around `x` both at scales `r` and `s` w.r.t. `ε` (it exists as
`x` belongs to `D`). Take also `L₂` that approximates `f` around `x` both at scales `r'` and `s`
w.r.t. `ε'`. Then `L₁` is close to `L` (as they are close on a shell of radius `r`), and `L₂` is
close to `L₁` (as they are close on a shell of radius `s`), and `L'` is close to `L₂` (as they are
close on a shell of radius `r'`). It follows that `L` is close to `L'`, as we claimed.
It follows that the different approximating linear maps that show up form a Cauchy sequence when
`ε` tends to `0`. When the target space is complete, this sequence converges, to a limit `f'`.
With the same kind of arguments, one checks that `f` is differentiable with derivative `f'`.
To show that the derivative itself is measurable, add in the definition of `B` and `D` a set
`K` of continuous linear maps to which `L` should belong. Then, when `K` is complete, the set `D K`
is exactly the set of points where `f` is differentiable with a derivative in `K`.
## Tags
derivative, measurable function, Borel σ-algebra
-/
set_option linter.uppercaseLean3 false -- A B D
noncomputable section
open Set Metric Asymptotics Filter ContinuousLinearMap MeasureTheory TopologicalSpace
open scoped Topology
namespace ContinuousLinearMap
variable {𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E]
[NormedAddCommGroup F] [NormedSpace 𝕜 F]
theorem measurable_apply₂ [MeasurableSpace E] [OpensMeasurableSpace E]
[SecondCountableTopologyEither (E →L[𝕜] F) E]
[MeasurableSpace F] [BorelSpace F] : Measurable fun p : (E →L[𝕜] F) × E => p.1 p.2 :=
isBoundedBilinearMap_apply.continuous.measurable
#align continuous_linear_map.measurable_apply₂ ContinuousLinearMap.measurable_apply₂
end ContinuousLinearMap
section fderiv
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {f : E → F} (K : Set (E →L[𝕜] F))
namespace FDerivMeasurableAux
/-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated
at scale `r` by the linear map `L`, up to an error `ε`. We tweak the definition to make sure that
this is an open set. -/
def A (f : E → F) (L : E →L[𝕜] F) (r ε : ℝ) : Set E :=
{ x | ∃ r' ∈ Ioc (r / 2) r, ∀ y ∈ ball x r', ∀ z ∈ ball x r', ‖f z - f y - L (z - y)‖ < ε * r }
#align fderiv_measurable_aux.A FDerivMeasurableAux.A
/-- The set `B f K r s ε` is the set of points `x` around which there exists a continuous linear map
`L` belonging to `K` (a given set of continuous linear maps) that approximates well the
function `f` (up to an error `ε`), simultaneously at scales `r` and `s`. -/
def B (f : E → F) (K : Set (E →L[𝕜] F)) (r s ε : ℝ) : Set E :=
⋃ L ∈ K, A f L r ε ∩ A f L s ε
#align fderiv_measurable_aux.B FDerivMeasurableAux.B
/-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its
main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable,
with a derivative in `K`. -/
def D (f : E → F) (K : Set (E →L[𝕜] F)) : Set E :=
⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e)
#align fderiv_measurable_aux.D FDerivMeasurableAux.D
theorem isOpen_A (L : E →L[𝕜] F) (r ε : ℝ) : IsOpen (A f L r ε) := by
rw [Metric.isOpen_iff]
rintro x ⟨r', r'_mem, hr'⟩
obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between r'_mem.1
have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le r'_mem.2)⟩
refine ⟨r' - s, by linarith, fun x' hx' => ⟨s, this, ?_⟩⟩
have B : ball x' s ⊆ ball x r' := ball_subset (le_of_lt hx')
intro y hy z hz
exact hr' y (B hy) z (B hz)
#align fderiv_measurable_aux.is_open_A FDerivMeasurableAux.isOpen_A
theorem isOpen_B {K : Set (E →L[𝕜] F)} {r s ε : ℝ} : IsOpen (B f K r s ε) := by
simp [B, isOpen_biUnion, IsOpen.inter, isOpen_A]
#align fderiv_measurable_aux.is_open_B FDerivMeasurableAux.isOpen_B
theorem A_mono (L : E →L[𝕜] F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : A f L r ε ⊆ A f L r δ := by
rintro x ⟨r', r'r, hr'⟩
refine ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans_le (mul_le_mul_of_nonneg_right h ?_)⟩
linarith [mem_ball.1 hy, r'r.2, @dist_nonneg _ _ y x]
#align fderiv_measurable_aux.A_mono FDerivMeasurableAux.A_mono
theorem le_of_mem_A {r ε : ℝ} {L : E →L[𝕜] F} {x : E} (hx : x ∈ A f L r ε) {y z : E}
(hy : y ∈ closedBall x (r / 2)) (hz : z ∈ closedBall x (r / 2)) :
‖f z - f y - L (z - y)‖ ≤ ε * r := by
rcases hx with ⟨r', r'mem, hr'⟩
apply le_of_lt
exact hr' _ ((mem_closedBall.1 hy).trans_lt r'mem.1) _ ((mem_closedBall.1 hz).trans_lt r'mem.1)
#align fderiv_measurable_aux.le_of_mem_A FDerivMeasurableAux.le_of_mem_A
theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : E} (hx : DifferentiableAt 𝕜 f x) :
∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (fderiv 𝕜 f x) r ε := by
let δ := (ε / 2) / 2
obtain ⟨R, R_pos, hR⟩ :
∃ R > 0, ∀ y ∈ ball x R, ‖f y - f x - fderiv 𝕜 f x (y - x)‖ ≤ δ * ‖y - x‖ :=
eventually_nhds_iff_ball.1 <| hx.hasFDerivAt.isLittleO.bound <| by positivity
refine ⟨R, R_pos, fun r hr => ?_⟩
have : r ∈ Ioc (r / 2) r := right_mem_Ioc.2 <| half_lt_self hr.1
refine ⟨r, this, fun y hy z hz => ?_⟩
calc
‖f z - f y - (fderiv 𝕜 f x) (z - y)‖ =
‖f z - f x - (fderiv 𝕜 f x) (z - x) - (f y - f x - (fderiv 𝕜 f x) (y - x))‖ := by
simp only [map_sub]; abel_nf
_ ≤ ‖f z - f x - (fderiv 𝕜 f x) (z - x)‖ + ‖f y - f x - (fderiv 𝕜 f x) (y - x)‖ :=
norm_sub_le _ _
_ ≤ δ * ‖z - x‖ + δ * ‖y - x‖ :=
add_le_add (hR _ (ball_subset_ball hr.2.le hz)) (hR _ (ball_subset_ball hr.2.le hy))
_ ≤ δ * r + δ * r := by rw [mem_ball_iff_norm] at hz hy; gcongr
_ = (ε / 2) * r := by ring
_ < ε * r := by gcongr; exacts [hr.1, half_lt_self hε]
#align fderiv_measurable_aux.mem_A_of_differentiable FDerivMeasurableAux.mem_A_of_differentiable
theorem norm_sub_le_of_mem_A {c : 𝕜} (hc : 1 < ‖c‖) {r ε : ℝ} (hε : 0 < ε) (hr : 0 < r) {x : E}
{L₁ L₂ : E →L[𝕜] F} (h₁ : x ∈ A f L₁ r ε) (h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ‖c‖ * ε := by
refine opNorm_le_of_shell (half_pos hr) (by positivity) hc ?_
intro y ley ylt
rw [div_div, div_le_iff' (mul_pos (by norm_num : (0 : ℝ) < 2) (zero_lt_one.trans hc))] at ley
calc
‖(L₁ - L₂) y‖ = ‖f (x + y) - f x - L₂ (x + y - x) - (f (x + y) - f x - L₁ (x + y - x))‖ := by
simp
_ ≤ ‖f (x + y) - f x - L₂ (x + y - x)‖ + ‖f (x + y) - f x - L₁ (x + y - x)‖ := norm_sub_le _ _
_ ≤ ε * r + ε * r := by
apply add_le_add
· apply le_of_mem_A h₂
· simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self]
· simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le]
· apply le_of_mem_A h₁
· simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self]
· simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le]
_ = 2 * ε * r := by ring
_ ≤ 2 * ε * (2 * ‖c‖ * ‖y‖) := by gcongr
_ = 4 * ‖c‖ * ε * ‖y‖ := by ring
#align fderiv_measurable_aux.norm_sub_le_of_mem_A FDerivMeasurableAux.norm_sub_le_of_mem_A
/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/
theorem differentiable_set_subset_D :
{ x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } ⊆ D f K := by
intro x hx
rw [D, mem_iInter]
intro e
have : (0 : ℝ) < (1 / 2) ^ e := by positivity
rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩
obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R :=
exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1)
simp only [mem_iUnion, mem_iInter, B, mem_inter_iff]
refine ⟨n, fun p hp q hq => ⟨fderiv 𝕜 f x, hx.2, ⟨?_, ?_⟩⟩⟩ <;>
· refine hR _ ⟨pow_pos (by norm_num) _, lt_of_le_of_lt ?_ hn⟩
exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption)
#align fderiv_measurable_aux.differentiable_set_subset_D FDerivMeasurableAux.differentiable_set_subset_D
/-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/
theorem D_subset_differentiable_set {K : Set (E →L[𝕜] F)} (hK : IsComplete K) :
D f K ⊆ { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by
have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := fun {n} => pow_pos (by norm_num) n
rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩
intro x hx
have :
∀ e : ℕ, ∃ n : ℕ, ∀ p q, n ≤ p → n ≤ q →
∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) := by
intro e
have := mem_iInter.1 hx e
rcases mem_iUnion.1 this with ⟨n, hn⟩
refine ⟨n, fun p q hp hq => ?_⟩
simp only [mem_iInter, ge_iff_le] at hn
rcases mem_iUnion.1 (hn p hp q hq) with ⟨L, hL⟩
exact ⟨L, exists_prop.mp <| mem_iUnion.1 hL⟩
/- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K`
such that, for `p, q ≥ n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and
`2 ^ (-q)`, with an error `2 ^ (-e)`. -/
choose! n L hn using this
/- All the operators `L e p q` that show up are close to each other. To prove this, we argue
that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at
scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale
`2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale
`2 ^ (- p')`. -/
have M :
∀ e p q e' p' q',
n e ≤ p →
n e ≤ q →
n e' ≤ p' → n e' ≤ q' → e ≤ e' → ‖L e p q - L e' p' q'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := by
intro e p q e' p' q' hp hq hp' hq' he'
let r := max (n e) (n e')
have I : ((1 : ℝ) / 2) ^ e' ≤ (1 / 2) ^ e :=
pow_le_pow_of_le_one (by norm_num) (by norm_num) he'
have J1 : ‖L e p q - L e p r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1
have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1
exact norm_sub_le_of_mem_A hc P P I1 I2
have J2 : ‖L e p r - L e' p' r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2
have I2 : x ∈ A f (L e' p' r) ((1 / 2) ^ r) ((1 / 2) ^ e') :=
(hn e' p' r hp' (le_max_right _ _)).2.2
exact norm_sub_le_of_mem_A hc P P I1 (A_mono _ _ I I2)
have J3 : ‖L e' p' r - L e' p' q'‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e' p' r) ((1 / 2) ^ p') ((1 / 2) ^ e') :=
(hn e' p' r hp' (le_max_right _ _)).2.1
have I2 : x ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' q' hp' hq').2.1
exact norm_sub_le_of_mem_A hc P P (A_mono _ _ I I1) (A_mono _ _ I I2)
calc
‖L e p q - L e' p' q'‖ =
‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ := by
congr 1; abel
_ ≤ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ :=
norm_add₃_le _ _ _
_ ≤ 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e := by gcongr
_ = 12 * ‖c‖ * (1 / 2) ^ e := by ring
/- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this
is a Cauchy sequence. -/
let L0 : ℕ → E →L[𝕜] F := fun e => L e (n e) (n e)
have : CauchySeq L0 := by
rw [Metric.cauchySeq_iff']
intro ε εpos
obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (12 * ‖c‖) :=
exists_pow_lt_of_lt_one (by positivity) (by norm_num)
refine ⟨e, fun e' he' => ?_⟩
rw [dist_comm, dist_eq_norm]
calc
‖L0 e - L0 e'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he'
_ < 12 * ‖c‖ * (ε / (12 * ‖c‖)) := by gcongr
_ = ε := by field_simp
-- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`.
obtain ⟨f', f'K, hf'⟩ : ∃ f' ∈ K, Tendsto L0 atTop (𝓝 f') :=
cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this
have Lf' : ∀ e p, n e ≤ p → ‖L e (n e) p - f'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := by
intro e p hp
apply le_of_tendsto (tendsto_const_nhds.sub hf').norm
rw [eventually_atTop]
exact ⟨e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩
-- Let us show that `f` has derivative `f'` at `x`.
have : HasFDerivAt f f' x := by
simp only [hasFDerivAt_iff_isLittleO_nhds_zero, isLittleO_iff]
/- to get an approximation with a precision `ε`, we will replace `f` with `L e (n e) m` for
some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`,
this makes it possible to cover all scales, and thus to obtain a good linear approximation in
the whole ball of radius `(1/2)^(n e)`. -/
intro ε εpos
have pos : 0 < 4 + 12 * ‖c‖ := by positivity
obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (4 + 12 * ‖c‖) :=
exists_pow_lt_of_lt_one (div_pos εpos pos) (by norm_num)
rw [eventually_nhds_iff_ball]
refine ⟨(1 / 2) ^ (n e + 1), P, fun y hy => ?_⟩
-- We need to show that `f (x + y) - f x - f' y` is small. For this, we will work at scale
-- `k` where `k` is chosen with `‖y‖ ∼ 2 ^ (-k)`.
by_cases y_pos : y = 0;
· simp [y_pos]
have yzero : 0 < ‖y‖ := norm_pos_iff.mpr y_pos
have y_lt : ‖y‖ < (1 / 2) ^ (n e + 1) := by simpa using mem_ball_iff_norm.1 hy
have yone : ‖y‖ ≤ 1 := le_trans y_lt.le (pow_le_one _ (by norm_num) (by norm_num))
-- define the scale `k`.
obtain ⟨k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < ‖y‖ ∧ ‖y‖ ≤ (1 / 2) ^ k :=
exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2)
(by norm_num : (1 : ℝ) / 2 < 1)
-- the scale is large enough (as `y` is small enough)
have k_gt : n e < k := by
have : ((1 : ℝ) / 2) ^ (k + 1) < (1 / 2) ^ (n e + 1) := lt_trans hk y_lt
rw [pow_lt_pow_iff_right_of_lt_one (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num)] at this
omega
set m := k - 1
have m_ge : n e ≤ m := Nat.le_sub_one_of_lt k_gt
have km : k = m + 1 := (Nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm
rw [km] at hk h'k
-- `f` is well approximated by `L e (n e) k` at the relevant scale
-- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`).
have J1 : ‖f (x + y) - f x - L e (n e) m (x + y - x)‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by
apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2
· simp only [mem_closedBall, dist_self]
positivity
· simpa only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, pow_succ, mul_one_div] using
h'k
have J2 : ‖f (x + y) - f x - L e (n e) m y‖ ≤ 4 * (1 / 2) ^ e * ‖y‖ :=
calc
‖f (x + y) - f x - L e (n e) m y‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by
simpa only [add_sub_cancel_left] using J1
_ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) := by field_simp; ring
_ ≤ 4 * (1 / 2) ^ e * ‖y‖ := by gcongr
-- use the previous estimates to see that `f (x + y) - f x - f' y` is small.
calc
‖f (x + y) - f x - f' y‖ = ‖f (x + y) - f x - L e (n e) m y + (L e (n e) m - f') y‖ :=
congr_arg _ (by simp)
_ ≤ 4 * (1 / 2) ^ e * ‖y‖ + 12 * ‖c‖ * (1 / 2) ^ e * ‖y‖ :=
norm_add_le_of_le J2 <| (le_opNorm _ _).trans <| by gcongr; exact Lf' _ _ m_ge
_ = (4 + 12 * ‖c‖) * ‖y‖ * (1 / 2) ^ e := by ring
_ ≤ (4 + 12 * ‖c‖) * ‖y‖ * (ε / (4 + 12 * ‖c‖)) := by gcongr
_ = ε * ‖y‖ := by field_simp [ne_of_gt pos]; ring
rw [← this.fderiv] at f'K
exact ⟨this.differentiableAt, f'K⟩
#align fderiv_measurable_aux.D_subset_differentiable_set FDerivMeasurableAux.D_subset_differentiable_set
theorem differentiable_set_eq_D (hK : IsComplete K) :
{ x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } = D f K :=
Subset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK)
#align fderiv_measurable_aux.differentiable_set_eq_D FDerivMeasurableAux.differentiable_set_eq_D
end FDerivMeasurableAux
open FDerivMeasurableAux
variable [MeasurableSpace E] [OpensMeasurableSpace E]
variable (𝕜 f)
/-- The set of differentiability points of a function, with derivative in a given complete set,
is Borel-measurable. -/
theorem measurableSet_of_differentiableAt_of_isComplete {K : Set (E →L[𝕜] F)} (hK : IsComplete K) :
MeasurableSet { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by
-- Porting note: was
-- simp [differentiable_set_eq_D K hK, D, isOpen_B.measurableSet, MeasurableSet.iInter,
-- MeasurableSet.iUnion]
simp only [D, differentiable_set_eq_D K hK]
repeat apply_rules [MeasurableSet.iUnion, MeasurableSet.iInter] <;> intro
exact isOpen_B.measurableSet
#align measurable_set_of_differentiable_at_of_is_complete measurableSet_of_differentiableAt_of_isComplete
variable [CompleteSpace F]
/-- The set of differentiability points of a function taking values in a complete space is
Borel-measurable. -/
theorem measurableSet_of_differentiableAt : MeasurableSet { x | DifferentiableAt 𝕜 f x } := by
have : IsComplete (univ : Set (E →L[𝕜] F)) := complete_univ
convert measurableSet_of_differentiableAt_of_isComplete 𝕜 f this
simp
#align measurable_set_of_differentiable_at measurableSet_of_differentiableAt
@[measurability]
theorem measurable_fderiv : Measurable (fderiv 𝕜 f) := by
refine measurable_of_isClosed fun s hs => ?_
have :
fderiv 𝕜 f ⁻¹' s =
{ x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ s } ∪
{ x | ¬DifferentiableAt 𝕜 f x } ∩ { _x | (0 : E →L[𝕜] F) ∈ s } :=
Set.ext fun x => mem_preimage.trans fderiv_mem_iff
rw [this]
exact
(measurableSet_of_differentiableAt_of_isComplete _ _ hs.isComplete).union
((measurableSet_of_differentiableAt _ _).compl.inter (MeasurableSet.const _))
#align measurable_fderiv measurable_fderiv
@[measurability]
theorem measurable_fderiv_apply_const [MeasurableSpace F] [BorelSpace F] (y : E) :
Measurable fun x => fderiv 𝕜 f x y :=
(ContinuousLinearMap.measurable_apply y).comp (measurable_fderiv 𝕜 f)
#align measurable_fderiv_apply_const measurable_fderiv_apply_const
variable {𝕜}
@[measurability]
theorem measurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F]
[BorelSpace F] (f : 𝕜 → F) : Measurable (deriv f) := by
simpa only [fderiv_deriv] using measurable_fderiv_apply_const 𝕜 f 1
#align measurable_deriv measurable_deriv
theorem stronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜]
[h : SecondCountableTopologyEither 𝕜 F] (f : 𝕜 → F) : StronglyMeasurable (deriv f) := by
borelize F
rcases h.out with h𝕜|hF
· exact stronglyMeasurable_iff_measurable_separable.2
⟨measurable_deriv f, isSeparable_range_deriv _⟩
· exact (measurable_deriv f).stronglyMeasurable
#align strongly_measurable_deriv stronglyMeasurable_deriv
theorem aemeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F]
[BorelSpace F] (f : 𝕜 → F) (μ : Measure 𝕜) : AEMeasurable (deriv f) μ :=
(measurable_deriv f).aemeasurable
#align ae_measurable_deriv aemeasurable_deriv
theorem aestronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜]
[SecondCountableTopologyEither 𝕜 F] (f : 𝕜 → F) (μ : Measure 𝕜) :
AEStronglyMeasurable (deriv f) μ :=
(stronglyMeasurable_deriv f).aestronglyMeasurable
#align ae_strongly_measurable_deriv aestronglyMeasurable_deriv
end fderiv
section RightDeriv
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]
variable {f : ℝ → F} (K : Set F)
namespace RightDerivMeasurableAux
/-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated
at scale `r` by the linear map `h ↦ h • L`, up to an error `ε`. We tweak the definition to
make sure that this is open on the right. -/
def A (f : ℝ → F) (L : F) (r ε : ℝ) : Set ℝ :=
{ x | ∃ r' ∈ Ioc (r / 2) r, ∀ᵉ (y ∈ Icc x (x + r')) (z ∈ Icc x (x + r')),
‖f z - f y - (z - y) • L‖ ≤ ε * r }
#align right_deriv_measurable_aux.A RightDerivMeasurableAux.A
/-- The set `B f K r s ε` is the set of points `x` around which there exists a vector
`L` belonging to `K` (a given set of vectors) such that `h • L` approximates well `f (x + h)`
(up to an error `ε`), simultaneously at scales `r` and `s`. -/
def B (f : ℝ → F) (K : Set F) (r s ε : ℝ) : Set ℝ :=
⋃ L ∈ K, A f L r ε ∩ A f L s ε
#align right_deriv_measurable_aux.B RightDerivMeasurableAux.B
/-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its
main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable,
with a derivative in `K`. -/
def D (f : ℝ → F) (K : Set F) : Set ℝ :=
⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e)
#align right_deriv_measurable_aux.D RightDerivMeasurableAux.D
theorem A_mem_nhdsWithin_Ioi {L : F} {r ε x : ℝ} (hx : x ∈ A f L r ε) : A f L r ε ∈ 𝓝[>] x := by
rcases hx with ⟨r', rr', hr'⟩
rw [mem_nhdsWithin_Ioi_iff_exists_Ioo_subset]
obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between rr'.1
have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le rr'.2)⟩
refine ⟨x + r' - s, by simp only [mem_Ioi]; linarith, fun x' hx' => ⟨s, this, ?_⟩⟩
have A : Icc x' (x' + s) ⊆ Icc x (x + r') := by
apply Icc_subset_Icc hx'.1.le
linarith [hx'.2]
intro y hy z hz
exact hr' y (A hy) z (A hz)
#align right_deriv_measurable_aux.A_mem_nhds_within_Ioi RightDerivMeasurableAux.A_mem_nhdsWithin_Ioi
theorem B_mem_nhdsWithin_Ioi {K : Set F} {r s ε x : ℝ} (hx : x ∈ B f K r s ε) :
B f K r s ε ∈ 𝓝[>] x := by
obtain ⟨L, LK, hL₁, hL₂⟩ : ∃ L : F, L ∈ K ∧ x ∈ A f L r ε ∧ x ∈ A f L s ε := by
simpa only [B, mem_iUnion, mem_inter_iff, exists_prop] using hx
filter_upwards [A_mem_nhdsWithin_Ioi hL₁, A_mem_nhdsWithin_Ioi hL₂] with y hy₁ hy₂
simp only [B, mem_iUnion, mem_inter_iff, exists_prop]
exact ⟨L, LK, hy₁, hy₂⟩
#align right_deriv_measurable_aux.B_mem_nhds_within_Ioi RightDerivMeasurableAux.B_mem_nhdsWithin_Ioi
theorem measurableSet_B {K : Set F} {r s ε : ℝ} : MeasurableSet (B f K r s ε) :=
measurableSet_of_mem_nhdsWithin_Ioi fun _ hx => B_mem_nhdsWithin_Ioi hx
#align right_deriv_measurable_aux.measurable_set_B RightDerivMeasurableAux.measurableSet_B
theorem A_mono (L : F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : A f L r ε ⊆ A f L r δ := by
rintro x ⟨r', r'r, hr'⟩
refine ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h ?_)⟩
linarith [hy.1, hy.2, r'r.2]
#align right_deriv_measurable_aux.A_mono RightDerivMeasurableAux.A_mono
theorem le_of_mem_A {r ε : ℝ} {L : F} {x : ℝ} (hx : x ∈ A f L r ε) {y z : ℝ}
(hy : y ∈ Icc x (x + r / 2)) (hz : z ∈ Icc x (x + r / 2)) :
‖f z - f y - (z - y) • L‖ ≤ ε * r := by
rcases hx with ⟨r', r'mem, hr'⟩
have A : x + r / 2 ≤ x + r' := by linarith [r'mem.1]
exact hr' _ ((Icc_subset_Icc le_rfl A) hy) _ ((Icc_subset_Icc le_rfl A) hz)
#align right_deriv_measurable_aux.le_of_mem_A RightDerivMeasurableAux.le_of_mem_A
theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : ℝ}
(hx : DifferentiableWithinAt ℝ f (Ici x) x) :
∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (derivWithin f (Ici x) x) r ε := by
have := hx.hasDerivWithinAt
simp_rw [hasDerivWithinAt_iff_isLittleO, isLittleO_iff] at this
rcases mem_nhdsWithin_Ici_iff_exists_Ico_subset.1 (this (half_pos hε)) with ⟨m, xm, hm⟩
refine ⟨m - x, by linarith [show x < m from xm], fun r hr => ?_⟩
have : r ∈ Ioc (r / 2) r := ⟨half_lt_self hr.1, le_rfl⟩
refine ⟨r, this, fun y hy z hz => ?_⟩
calc
‖f z - f y - (z - y) • derivWithin f (Ici x) x‖ =
‖f z - f x - (z - x) • derivWithin f (Ici x) x -
(f y - f x - (y - x) • derivWithin f (Ici x) x)‖ := by
congr 1; simp only [sub_smul]; abel
_ ≤
‖f z - f x - (z - x) • derivWithin f (Ici x) x‖ +
‖f y - f x - (y - x) • derivWithin f (Ici x) x‖ :=
(norm_sub_le _ _)
_ ≤ ε / 2 * ‖z - x‖ + ε / 2 * ‖y - x‖ :=
(add_le_add (hm ⟨hz.1, hz.2.trans_lt (by linarith [hr.2])⟩)
(hm ⟨hy.1, hy.2.trans_lt (by linarith [hr.2])⟩))
_ ≤ ε / 2 * r + ε / 2 * r := by
gcongr
· rw [Real.norm_of_nonneg] <;> linarith [hz.1, hz.2]
· rw [Real.norm_of_nonneg] <;> linarith [hy.1, hy.2]
_ = ε * r := by ring
#align right_deriv_measurable_aux.mem_A_of_differentiable RightDerivMeasurableAux.mem_A_of_differentiable
theorem norm_sub_le_of_mem_A {r x : ℝ} (hr : 0 < r) (ε : ℝ) {L₁ L₂ : F} (h₁ : x ∈ A f L₁ r ε)
(h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ε := by
suffices H : ‖(r / 2) • (L₁ - L₂)‖ ≤ r / 2 * (4 * ε) by
rwa [norm_smul, Real.norm_of_nonneg (half_pos hr).le, mul_le_mul_left (half_pos hr)] at H
calc
‖(r / 2) • (L₁ - L₂)‖ =
‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂ -
(f (x + r / 2) - f x - (x + r / 2 - x) • L₁)‖ := by
simp [smul_sub]
_ ≤ ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂‖ +
‖f (x + r / 2) - f x - (x + r / 2 - x) • L₁‖ :=
norm_sub_le _ _
_ ≤ ε * r + ε * r := by
apply add_le_add
· apply le_of_mem_A h₂ <;> simp [(half_pos hr).le]
· apply le_of_mem_A h₁ <;> simp [(half_pos hr).le]
_ = r / 2 * (4 * ε) := by ring
#align right_deriv_measurable_aux.norm_sub_le_of_mem_A RightDerivMeasurableAux.norm_sub_le_of_mem_A
/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/
theorem differentiable_set_subset_D :
{ x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } ⊆ D f K := by
intro x hx
rw [D, mem_iInter]
intro e
have : (0 : ℝ) < (1 / 2) ^ e := pow_pos (by norm_num) _
rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩
obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R :=
exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1)
simp only [mem_iUnion, mem_iInter, B, mem_inter_iff]
refine ⟨n, fun p hp q hq => ⟨derivWithin f (Ici x) x, hx.2, ⟨?_, ?_⟩⟩⟩ <;>
· refine hR _ ⟨pow_pos (by norm_num) _, lt_of_le_of_lt ?_ hn⟩
exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption)
#align right_deriv_measurable_aux.differentiable_set_subset_D RightDerivMeasurableAux.differentiable_set_subset_D
/-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/
theorem D_subset_differentiable_set {K : Set F} (hK : IsComplete K) :
D f K ⊆ { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } := by
have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := fun {n} => pow_pos (by norm_num) n
intro x hx
have :
∀ e : ℕ, ∃ n : ℕ, ∀ p q, n ≤ p → n ≤ q →
∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) := by
intro e
have := mem_iInter.1 hx e
rcases mem_iUnion.1 this with ⟨n, hn⟩
refine ⟨n, fun p q hp hq => ?_⟩
simp only [mem_iInter, ge_iff_le] at hn
rcases mem_iUnion.1 (hn p hp q hq) with ⟨L, hL⟩
exact ⟨L, exists_prop.mp <| mem_iUnion.1 hL⟩
/- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K`
such that, for `p, q ≥ n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and
`2 ^ (-q)`, with an error `2 ^ (-e)`. -/
choose! n L hn using this
/- All the operators `L e p q` that show up are close to each other. To prove this, we argue
that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at
scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale
`2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale
`2 ^ (- p')`. -/
have M :
∀ e p q e' p' q',
n e ≤ p →
n e ≤ q → n e' ≤ p' → n e' ≤ q' → e ≤ e' → ‖L e p q - L e' p' q'‖ ≤ 12 * (1 / 2) ^ e := by
intro e p q e' p' q' hp hq hp' hq' he'
let r := max (n e) (n e')
have I : ((1 : ℝ) / 2) ^ e' ≤ (1 / 2) ^ e :=
pow_le_pow_of_le_one (by norm_num) (by norm_num) he'
have J1 : ‖L e p q - L e p r‖ ≤ 4 * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1
have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1
exact norm_sub_le_of_mem_A P _ I1 I2
have J2 : ‖L e p r - L e' p' r‖ ≤ 4 * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2
have I2 : x ∈ A f (L e' p' r) ((1 / 2) ^ r) ((1 / 2) ^ e') :=
(hn e' p' r hp' (le_max_right _ _)).2.2
exact norm_sub_le_of_mem_A P _ I1 (A_mono _ _ I I2)
have J3 : ‖L e' p' r - L e' p' q'‖ ≤ 4 * (1 / 2) ^ e := by
have I1 : x ∈ A f (L e' p' r) ((1 / 2) ^ p') ((1 / 2) ^ e') :=
(hn e' p' r hp' (le_max_right _ _)).2.1
have I2 : x ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' q' hp' hq').2.1
exact norm_sub_le_of_mem_A P _ (A_mono _ _ I I1) (A_mono _ _ I I2)
calc
‖L e p q - L e' p' q'‖ =
‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ := by
congr 1; abel
_ ≤ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ :=
(le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _))
_ ≤ 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e := by gcongr
-- Porting note: proof was `by apply_rules [add_le_add]`
_ = 12 * (1 / 2) ^ e := by ring
/- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this
is a Cauchy sequence. -/
let L0 : ℕ → F := fun e => L e (n e) (n e)
have : CauchySeq L0 := by
rw [Metric.cauchySeq_iff']
intro ε εpos
obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 12 :=
exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num)
refine ⟨e, fun e' he' => ?_⟩
rw [dist_comm, dist_eq_norm]
calc
‖L0 e - L0 e'‖ ≤ 12 * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he'
_ < 12 * (ε / 12) := mul_lt_mul' le_rfl he (le_of_lt P) (by norm_num)
_ = ε := by field_simp [(by norm_num : (12 : ℝ) ≠ 0)]
-- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`.
obtain ⟨f', f'K, hf'⟩ : ∃ f' ∈ K, Tendsto L0 atTop (𝓝 f') :=
cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this
have Lf' : ∀ e p, n e ≤ p → ‖L e (n e) p - f'‖ ≤ 12 * (1 / 2) ^ e := by
intro e p hp
apply le_of_tendsto (tendsto_const_nhds.sub hf').norm
rw [eventually_atTop]
exact ⟨e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩
-- Let us show that `f` has right derivative `f'` at `x`.
have : HasDerivWithinAt f f' (Ici x) x := by
simp only [hasDerivWithinAt_iff_isLittleO, isLittleO_iff]
/- to get an approximation with a precision `ε`, we will replace `f` with `L e (n e) m` for
some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`,
this makes it possible to cover all scales, and thus to obtain a good linear approximation in
the whole interval of length `(1/2)^(n e)`. -/
intro ε εpos
obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 16 :=
exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num)
have xmem : x ∈ Ico x (x + (1 / 2) ^ (n e + 1)) := by
simp only [one_div, left_mem_Ico, lt_add_iff_pos_right, inv_pos, pow_pos, zero_lt_two,
zero_lt_one]
filter_upwards [Icc_mem_nhdsWithin_Ici xmem] with y hy
-- We need to show that `f y - f x - f' (y - x)` is small. For this, we will work at scale
-- `k` where `k` is chosen with `‖y - x‖ ∼ 2 ^ (-k)`.
rcases eq_or_lt_of_le hy.1 with (rfl | xy)
· simp only [sub_self, zero_smul, norm_zero, mul_zero, le_rfl]
have yzero : 0 < y - x := sub_pos.2 xy
have y_le : y - x ≤ (1 / 2) ^ (n e + 1) := by linarith [hy.2]
have yone : y - x ≤ 1 := le_trans y_le (pow_le_one _ (by norm_num) (by norm_num))
-- define the scale `k`.
obtain ⟨k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < y - x ∧ y - x ≤ (1 / 2) ^ k :=
exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2)
(by norm_num : (1 : ℝ) / 2 < 1)
-- the scale is large enough (as `y - x` is small enough)
have k_gt : n e < k := by
have : ((1 : ℝ) / 2) ^ (k + 1) < (1 / 2) ^ (n e + 1) := lt_of_lt_of_le hk y_le
rw [pow_lt_pow_iff_right_of_lt_one (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num)] at this
omega
set m := k - 1
have m_ge : n e ≤ m := Nat.le_sub_one_of_lt k_gt
have km : k = m + 1 := (Nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm
rw [km] at hk h'k
-- `f` is well approximated by `L e (n e) k` at the relevant scale
-- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`).
have J : ‖f y - f x - (y - x) • L e (n e) m‖ ≤ 4 * (1 / 2) ^ e * ‖y - x‖ :=
calc
‖f y - f x - (y - x) • L e (n e) m‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by
apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2
· simp only [one_div, inv_pow, left_mem_Icc, le_add_iff_nonneg_right]
positivity
· simp only [pow_add, tsub_le_iff_left] at h'k
simpa only [hy.1, mem_Icc, true_and_iff, one_div, pow_one] using h'k
_ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) := by field_simp; ring
_ ≤ 4 * (1 / 2) ^ e * (y - x) := by gcongr
_ = 4 * (1 / 2) ^ e * ‖y - x‖ := by rw [Real.norm_of_nonneg yzero.le]
calc
‖f y - f x - (y - x) • f'‖ =
‖f y - f x - (y - x) • L e (n e) m + (y - x) • (L e (n e) m - f')‖ := by
simp only [smul_sub, sub_add_sub_cancel]
_ ≤ 4 * (1 / 2) ^ e * ‖y - x‖ + ‖y - x‖ * (12 * (1 / 2) ^ e) :=
norm_add_le_of_le J <| by rw [norm_smul]; gcongr; exact Lf' _ _ m_ge
_ = 16 * ‖y - x‖ * (1 / 2) ^ e := by ring
_ ≤ 16 * ‖y - x‖ * (ε / 16) := by gcongr
_ = ε * ‖y - x‖ := by ring
rw [← this.derivWithin (uniqueDiffOn_Ici x x Set.left_mem_Ici)] at f'K
exact ⟨this.differentiableWithinAt, f'K⟩
#align right_deriv_measurable_aux.D_subset_differentiable_set RightDerivMeasurableAux.D_subset_differentiable_set
theorem differentiable_set_eq_D (hK : IsComplete K) :
{ x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } = D f K :=
Subset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK)
#align right_deriv_measurable_aux.differentiable_set_eq_D RightDerivMeasurableAux.differentiable_set_eq_D
end RightDerivMeasurableAux
open RightDerivMeasurableAux
variable (f)
/-- The set of right differentiability points of a function, with derivative in a given complete
set, is Borel-measurable. -/
theorem measurableSet_of_differentiableWithinAt_Ici_of_isComplete {K : Set F} (hK : IsComplete K) :
MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } := by
-- simp [differentiable_set_eq_d K hK, D, measurableSet_b, MeasurableSet.iInter,
-- MeasurableSet.iUnion]
simp only [differentiable_set_eq_D K hK, D]
repeat apply_rules [MeasurableSet.iUnion, MeasurableSet.iInter] <;> intro
exact measurableSet_B
#align measurable_set_of_differentiable_within_at_Ici_of_is_complete measurableSet_of_differentiableWithinAt_Ici_of_isComplete
variable [CompleteSpace F]
/-- The set of right differentiability points of a function taking values in a complete space is
Borel-measurable. -/
theorem measurableSet_of_differentiableWithinAt_Ici :
MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x } := by
have : IsComplete (univ : Set F) := complete_univ
convert measurableSet_of_differentiableWithinAt_Ici_of_isComplete f this
simp
#align measurable_set_of_differentiable_within_at_Ici measurableSet_of_differentiableWithinAt_Ici
@[measurability]
theorem measurable_derivWithin_Ici [MeasurableSpace F] [BorelSpace F] :
Measurable fun x => derivWithin f (Ici x) x := by
refine measurable_of_isClosed fun s hs => ?_
have :
(fun x => derivWithin f (Ici x) x) ⁻¹' s =
{ x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ s } ∪
{ x | ¬DifferentiableWithinAt ℝ f (Ici x) x } ∩ { _x | (0 : F) ∈ s } :=
Set.ext fun x => mem_preimage.trans derivWithin_mem_iff
rw [this]
exact
(measurableSet_of_differentiableWithinAt_Ici_of_isComplete _ hs.isComplete).union
((measurableSet_of_differentiableWithinAt_Ici _).compl.inter (MeasurableSet.const _))
#align measurable_deriv_within_Ici measurable_derivWithin_Ici
theorem stronglyMeasurable_derivWithin_Ici :
StronglyMeasurable (fun x ↦ derivWithin f (Ici x) x) := by
borelize F
apply stronglyMeasurable_iff_measurable_separable.2 ⟨measurable_derivWithin_Ici f, ?_⟩
obtain ⟨t, t_count, ht⟩ : ∃ t : Set ℝ, t.Countable ∧ Dense t := exists_countable_dense ℝ
suffices H : range (fun x ↦ derivWithin f (Ici x) x) ⊆ closure (Submodule.span ℝ (f '' t)) from
IsSeparable.mono (t_count.image f).isSeparable.span.closure H
rintro - ⟨x, rfl⟩
suffices H' : range (fun y ↦ derivWithin f (Ici x) y) ⊆ closure (Submodule.span ℝ (f '' t)) from
H' (mem_range_self _)
apply range_derivWithin_subset_closure_span_image
calc Ici x
= closure (Ioi x ∩ closure t) := by simp [dense_iff_closure_eq.1 ht]
_ ⊆ closure (closure (Ioi x ∩ t)) := by
apply closure_mono
simpa [inter_comm] using (isOpen_Ioi (a := x)).closure_inter (s := t)
_ ⊆ closure (Ici x ∩ t) := by
rw [closure_closure]
exact closure_mono (inter_subset_inter_left _ Ioi_subset_Ici_self)
#align strongly_measurable_deriv_within_Ici stronglyMeasurable_derivWithin_Ici
theorem aemeasurable_derivWithin_Ici [MeasurableSpace F] [BorelSpace F] (μ : Measure ℝ) :
AEMeasurable (fun x => derivWithin f (Ici x) x) μ :=
(measurable_derivWithin_Ici f).aemeasurable
#align ae_measurable_deriv_within_Ici aemeasurable_derivWithin_Ici
theorem aestronglyMeasurable_derivWithin_Ici (μ : Measure ℝ) :
AEStronglyMeasurable (fun x => derivWithin f (Ici x) x) μ :=
(stronglyMeasurable_derivWithin_Ici f).aestronglyMeasurable
#align ae_strongly_measurable_deriv_within_Ici aestronglyMeasurable_derivWithin_Ici
/-- The set of right differentiability points of a function taking values in a complete space is
Borel-measurable. -/
theorem measurableSet_of_differentiableWithinAt_Ioi :
MeasurableSet { x | DifferentiableWithinAt ℝ f (Ioi x) x } := by
simpa [differentiableWithinAt_Ioi_iff_Ici] using measurableSet_of_differentiableWithinAt_Ici f
#align measurable_set_of_differentiable_within_at_Ioi measurableSet_of_differentiableWithinAt_Ioi
@[measurability]
theorem measurable_derivWithin_Ioi [MeasurableSpace F] [BorelSpace F] :
Measurable fun x => derivWithin f (Ioi x) x := by
simpa [derivWithin_Ioi_eq_Ici] using measurable_derivWithin_Ici f
#align measurable_deriv_within_Ioi measurable_derivWithin_Ioi
theorem stronglyMeasurable_derivWithin_Ioi :
StronglyMeasurable (fun x ↦ derivWithin f (Ioi x) x) := by
simpa [derivWithin_Ioi_eq_Ici] using stronglyMeasurable_derivWithin_Ici f
#align strongly_measurable_deriv_within_Ioi stronglyMeasurable_derivWithin_Ioi
theorem aemeasurable_derivWithin_Ioi [MeasurableSpace F] [BorelSpace F] (μ : Measure ℝ) :
AEMeasurable (fun x => derivWithin f (Ioi x) x) μ :=
(measurable_derivWithin_Ioi f).aemeasurable
#align ae_measurable_deriv_within_Ioi aemeasurable_derivWithin_Ioi
theorem aestronglyMeasurable_derivWithin_Ioi (μ : Measure ℝ) :
AEStronglyMeasurable (fun x => derivWithin f (Ioi x) x) μ :=
(stronglyMeasurable_derivWithin_Ioi f).aestronglyMeasurable
#align ae_strongly_measurable_deriv_within_Ioi aestronglyMeasurable_derivWithin_Ioi
end RightDeriv
section WithParam
/- In this section, we prove the measurability of the derivative in a context with parameters:
given `f : α → E → F`, we want to show that `p ↦ fderiv 𝕜 (f p.1) p.2` is measurable. Contrary
to the previous sections, some assumptions are needed for this: if `f p.1` depends arbitrarily on
`p.1`, this is obviously false. We require that `f` is continuous and `E` is locally compact --
then the proofs in the previous sections adapt readily, as the set `A` defined above is open, so
that the differentiability set `D` is measurable. -/
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [LocallyCompactSpace E]
{F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
{α : Type*} [TopologicalSpace α] [MeasurableSpace α] [MeasurableSpace E]
[OpensMeasurableSpace α] [OpensMeasurableSpace E]
{f : α → E → F} (K : Set (E →L[𝕜] F))
namespace FDerivMeasurableAux
open Uniformity
lemma isOpen_A_with_param {r s : ℝ} (hf : Continuous f.uncurry) (L : E →L[𝕜] F) :
IsOpen {p : α × E | p.2 ∈ A (f p.1) L r s} := by
have : ProperSpace E := .of_locallyCompactSpace 𝕜
simp only [A, half_lt_self_iff, not_lt, mem_Ioc, mem_ball, map_sub, mem_setOf_eq]
apply isOpen_iff_mem_nhds.2
rintro ⟨a, x⟩ ⟨r', ⟨Irr', Ir'r⟩, hr⟩
have ha : Continuous (f a) := hf.uncurry_left a
rcases exists_between Irr' with ⟨t, hrt, htr'⟩
rcases exists_between hrt with ⟨t', hrt', ht't⟩
obtain ⟨b, b_lt, hb⟩ : ∃ b, b < s * r ∧ ∀ y ∈ closedBall x t, ∀ z ∈ closedBall x t,
‖f a z - f a y - (L z - L y)‖ ≤ b := by
have B : Continuous (fun (p : E × E) ↦ ‖f a p.2 - f a p.1 - (L p.2 - L p.1)‖) := by
-- `continuity` took several seconds to solve this.
refine continuous_norm.comp' <| Continuous.sub ?_ ?_
· exact ha.comp' continuous_snd |>.sub <| ha.comp' continuous_fst
· exact L.continuous.comp' continuous_snd |>.sub <| L.continuous.comp' continuous_fst
have C : (closedBall x t ×ˢ closedBall x t).Nonempty := by simp; linarith
rcases ((isCompact_closedBall x t).prod (isCompact_closedBall x t)).exists_isMaxOn
C B.continuousOn with ⟨p, pt, hp⟩
simp only [mem_prod, mem_closedBall] at pt
refine ⟨‖f a p.2 - f a p.1 - (L p.2 - L p.1)‖,
hr p.1 (pt.1.trans_lt htr') p.2 (pt.2.trans_lt htr'), fun y hy z hz ↦ ?_⟩
have D : (y, z) ∈ closedBall x t ×ˢ closedBall x t := mem_prod.2 ⟨hy, hz⟩
exact hp D
obtain ⟨ε, εpos, hε⟩ : ∃ ε, 0 < ε ∧ b + 2 * ε < s * r :=
⟨(s * r - b) / 3, by linarith, by linarith⟩
obtain ⟨u, u_open, au, hu⟩ : ∃ u, IsOpen u ∧ a ∈ u ∧ ∀ (p : α × E),
p.1 ∈ u → p.2 ∈ closedBall x t → dist (f.uncurry p) (f.uncurry (a, p.2)) < ε := by
have C : Continuous (fun (p : α × E) ↦ f a p.2) :=
-- `continuity` took several seconds to solve this.
ha.comp' continuous_snd
have D : ({a} ×ˢ closedBall x t).EqOn f.uncurry (fun p ↦ f a p.2) := by
rintro ⟨b, y⟩ ⟨hb, -⟩
simp only [mem_singleton_iff] at hb
simp [hb]
obtain ⟨v, v_open, sub_v, hv⟩ : ∃ v, IsOpen v ∧ {a} ×ˢ closedBall x t ⊆ v ∧
∀ p ∈ v, dist (Function.uncurry f p) (f a p.2) < ε :=
Uniform.exists_is_open_mem_uniformity_of_forall_mem_eq (s := {a} ×ˢ closedBall x t)
(fun p _ ↦ hf.continuousAt) (fun p _ ↦ C.continuousAt) D (dist_mem_uniformity εpos)
obtain ⟨w, w', w_open, -, sub_w, sub_w', hww'⟩ : ∃ (w : Set α) (w' : Set E),
IsOpen w ∧ IsOpen w' ∧ {a} ⊆ w ∧ closedBall x t ⊆ w' ∧ w ×ˢ w' ⊆ v :=
generalized_tube_lemma isCompact_singleton (isCompact_closedBall x t) v_open sub_v
refine ⟨w, w_open, sub_w rfl, ?_⟩
rintro ⟨b, y⟩ h hby
exact hv _ (hww' ⟨h, sub_w' hby⟩)
have : u ×ˢ ball x (t - t') ∈ 𝓝 (a, x) :=
prod_mem_nhds (u_open.mem_nhds au) (ball_mem_nhds _ (sub_pos.2 ht't))
filter_upwards [this]
rintro ⟨a', x'⟩ ha'x'
simp only [mem_prod, mem_ball] at ha'x'
refine ⟨t', ⟨hrt', ht't.le.trans (htr'.le.trans Ir'r)⟩, fun y hy z hz ↦ ?_⟩
have dyx : dist y x ≤ t := by linarith [dist_triangle y x' x]
have dzx : dist z x ≤ t := by linarith [dist_triangle z x' x]
calc
‖f a' z - f a' y - (L z - L y)‖ =
‖(f a' z - f a z) + (f a y - f a' y) + (f a z - f a y - (L z - L y))‖ := by congr; abel
_ ≤ ‖f a' z - f a z‖ + ‖f a y - f a' y‖ + ‖f a z - f a y - (L z - L y)‖ := norm_add₃_le _ _ _
_ ≤ ε + ε + b := by
gcongr
· rw [← dist_eq_norm]
change dist (f.uncurry (a', z)) (f.uncurry (a, z)) ≤ ε
apply (hu _ _ _).le
· exact ha'x'.1
· simp [dzx]
· rw [← dist_eq_norm']
change dist (f.uncurry (a', y)) (f.uncurry (a, y)) ≤ ε
apply (hu _ _ _).le
· exact ha'x'.1
· simp [dyx]
· simp [hb, dyx, dzx]
_ < s * r := by linarith
lemma isOpen_B_with_param {r s t : ℝ} (hf : Continuous f.uncurry) (K : Set (E →L[𝕜] F)) :
IsOpen {p : α × E | p.2 ∈ B (f p.1) K r s t} := by
suffices H : IsOpen (⋃ L ∈ K,
{p : α × E | p.2 ∈ A (f p.1) L r t ∧ p.2 ∈ A (f p.1) L s t}) by
convert H; ext p; simp [B]
refine isOpen_biUnion (fun L _ ↦ ?_)
exact (isOpen_A_with_param hf L).inter (isOpen_A_with_param hf L)
end FDerivMeasurableAux
open FDerivMeasurableAux
theorem measurableSet_of_differentiableAt_of_isComplete_with_param
(hf : Continuous f.uncurry) {K : Set (E →L[𝕜] F)} (hK : IsComplete K) :
MeasurableSet {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ K} := by
have : {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ K}
= {p : α × E | p.2 ∈ D (f p.1) K} := by simp [← differentiable_set_eq_D K hK]
rw [this]
simp only [D, mem_iInter, mem_iUnion]
simp only [setOf_forall, setOf_exists]
refine MeasurableSet.iInter (fun _ ↦ ?_)
refine MeasurableSet.iUnion (fun _ ↦ ?_)
refine MeasurableSet.iInter (fun _ ↦ ?_)
refine MeasurableSet.iInter (fun _ ↦ ?_)
refine MeasurableSet.iInter (fun _ ↦ ?_)
refine MeasurableSet.iInter (fun _ ↦ ?_)
have : ProperSpace E := .of_locallyCompactSpace 𝕜
exact (isOpen_B_with_param hf K).measurableSet
variable (𝕜)
variable [CompleteSpace F]
/-- The set of differentiability points of a continuous function depending on a parameter taking
values in a complete space is Borel-measurable. -/
theorem measurableSet_of_differentiableAt_with_param (hf : Continuous f.uncurry) :
MeasurableSet {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2} := by
have : IsComplete (univ : Set (E →L[𝕜] F)) := complete_univ
convert measurableSet_of_differentiableAt_of_isComplete_with_param hf this
simp
| Mathlib/Analysis/Calculus/FDeriv/Measurable.lean | 957 | 968 | theorem measurable_fderiv_with_param (hf : Continuous f.uncurry) :
Measurable (fun (p : α × E) ↦ fderiv 𝕜 (f p.1) p.2) := by |
refine measurable_of_isClosed (fun s hs ↦ ?_)
have :
(fun (p : α × E) ↦ fderiv 𝕜 (f p.1) p.2) ⁻¹' s =
{p | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ s } ∪
{ p | ¬DifferentiableAt 𝕜 (f p.1) p.2} ∩ { _p | (0 : E →L[𝕜] F) ∈ s} :=
Set.ext (fun x ↦ mem_preimage.trans fderiv_mem_iff)
rw [this]
exact
(measurableSet_of_differentiableAt_of_isComplete_with_param hf hs.isComplete).union
((measurableSet_of_differentiableAt_with_param _ hf).compl.inter (MeasurableSet.const _))
|
/-
Copyright (c) 2020 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa, Alex Meiburg
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Polynomial.Degree.Lemmas
#align_import data.polynomial.erase_lead from "leanprover-community/mathlib"@"fa256f00ce018e7b40e1dc756e403c86680bf448"
/-!
# Erase the leading term of a univariate polynomial
## Definition
* `eraseLead f`: the polynomial `f - leading term of f`
`eraseLead` serves as reduction step in an induction, shaving off one monomial from a polynomial.
The definition is set up so that it does not mention subtraction in the definition,
and thus works for polynomials over semirings as well as rings.
-/
noncomputable section
open Polynomial
open Polynomial Finset
namespace Polynomial
variable {R : Type*} [Semiring R] {f : R[X]}
/-- `eraseLead f` for a polynomial `f` is the polynomial obtained by
subtracting from `f` the leading term of `f`. -/
def eraseLead (f : R[X]) : R[X] :=
Polynomial.erase f.natDegree f
#align polynomial.erase_lead Polynomial.eraseLead
section EraseLead
theorem eraseLead_support (f : R[X]) : f.eraseLead.support = f.support.erase f.natDegree := by
simp only [eraseLead, support_erase]
#align polynomial.erase_lead_support Polynomial.eraseLead_support
theorem eraseLead_coeff (i : ℕ) :
f.eraseLead.coeff i = if i = f.natDegree then 0 else f.coeff i := by
simp only [eraseLead, coeff_erase]
#align polynomial.erase_lead_coeff Polynomial.eraseLead_coeff
@[simp]
theorem eraseLead_coeff_natDegree : f.eraseLead.coeff f.natDegree = 0 := by simp [eraseLead_coeff]
#align polynomial.erase_lead_coeff_nat_degree Polynomial.eraseLead_coeff_natDegree
theorem eraseLead_coeff_of_ne (i : ℕ) (hi : i ≠ f.natDegree) : f.eraseLead.coeff i = f.coeff i := by
simp [eraseLead_coeff, hi]
#align polynomial.erase_lead_coeff_of_ne Polynomial.eraseLead_coeff_of_ne
@[simp]
theorem eraseLead_zero : eraseLead (0 : R[X]) = 0 := by simp only [eraseLead, erase_zero]
#align polynomial.erase_lead_zero Polynomial.eraseLead_zero
@[simp]
theorem eraseLead_add_monomial_natDegree_leadingCoeff (f : R[X]) :
f.eraseLead + monomial f.natDegree f.leadingCoeff = f :=
(add_comm _ _).trans (f.monomial_add_erase _)
#align polynomial.erase_lead_add_monomial_nat_degree_leading_coeff Polynomial.eraseLead_add_monomial_natDegree_leadingCoeff
@[simp]
theorem eraseLead_add_C_mul_X_pow (f : R[X]) :
f.eraseLead + C f.leadingCoeff * X ^ f.natDegree = f := by
rw [C_mul_X_pow_eq_monomial, eraseLead_add_monomial_natDegree_leadingCoeff]
set_option linter.uppercaseLean3 false in
#align polynomial.erase_lead_add_C_mul_X_pow Polynomial.eraseLead_add_C_mul_X_pow
@[simp]
theorem self_sub_monomial_natDegree_leadingCoeff {R : Type*} [Ring R] (f : R[X]) :
f - monomial f.natDegree f.leadingCoeff = f.eraseLead :=
(eq_sub_iff_add_eq.mpr (eraseLead_add_monomial_natDegree_leadingCoeff f)).symm
#align polynomial.self_sub_monomial_nat_degree_leading_coeff Polynomial.self_sub_monomial_natDegree_leadingCoeff
@[simp]
theorem self_sub_C_mul_X_pow {R : Type*} [Ring R] (f : R[X]) :
f - C f.leadingCoeff * X ^ f.natDegree = f.eraseLead := by
rw [C_mul_X_pow_eq_monomial, self_sub_monomial_natDegree_leadingCoeff]
set_option linter.uppercaseLean3 false in
#align polynomial.self_sub_C_mul_X_pow Polynomial.self_sub_C_mul_X_pow
theorem eraseLead_ne_zero (f0 : 2 ≤ f.support.card) : eraseLead f ≠ 0 := by
rw [Ne, ← card_support_eq_zero, eraseLead_support]
exact
(zero_lt_one.trans_le <| (tsub_le_tsub_right f0 1).trans Finset.pred_card_le_card_erase).ne.symm
#align polynomial.erase_lead_ne_zero Polynomial.eraseLead_ne_zero
theorem lt_natDegree_of_mem_eraseLead_support {a : ℕ} (h : a ∈ (eraseLead f).support) :
a < f.natDegree := by
rw [eraseLead_support, mem_erase] at h
exact (le_natDegree_of_mem_supp a h.2).lt_of_ne h.1
#align polynomial.lt_nat_degree_of_mem_erase_lead_support Polynomial.lt_natDegree_of_mem_eraseLead_support
theorem ne_natDegree_of_mem_eraseLead_support {a : ℕ} (h : a ∈ (eraseLead f).support) :
a ≠ f.natDegree :=
(lt_natDegree_of_mem_eraseLead_support h).ne
#align polynomial.ne_nat_degree_of_mem_erase_lead_support Polynomial.ne_natDegree_of_mem_eraseLead_support
theorem natDegree_not_mem_eraseLead_support : f.natDegree ∉ (eraseLead f).support := fun h =>
ne_natDegree_of_mem_eraseLead_support h rfl
#align polynomial.nat_degree_not_mem_erase_lead_support Polynomial.natDegree_not_mem_eraseLead_support
theorem eraseLead_support_card_lt (h : f ≠ 0) : (eraseLead f).support.card < f.support.card := by
rw [eraseLead_support]
exact card_lt_card (erase_ssubset <| natDegree_mem_support_of_nonzero h)
#align polynomial.erase_lead_support_card_lt Polynomial.eraseLead_support_card_lt
theorem card_support_eraseLead_add_one (h : f ≠ 0) :
f.eraseLead.support.card + 1 = f.support.card := by
set c := f.support.card with hc
cases h₁ : c
case zero =>
by_contra
exact h (card_support_eq_zero.mp h₁)
case succ =>
rw [eraseLead_support, card_erase_of_mem (natDegree_mem_support_of_nonzero h), ← hc, h₁]
rfl
@[simp]
theorem card_support_eraseLead : f.eraseLead.support.card = f.support.card - 1 := by
by_cases hf : f = 0
· rw [hf, eraseLead_zero, support_zero, card_empty]
· rw [← card_support_eraseLead_add_one hf, add_tsub_cancel_right]
theorem card_support_eraseLead' {c : ℕ} (fc : f.support.card = c + 1) :
f.eraseLead.support.card = c := by
rw [card_support_eraseLead, fc, add_tsub_cancel_right]
#align polynomial.erase_lead_card_support' Polynomial.card_support_eraseLead'
theorem card_support_eq_one_of_eraseLead_eq_zero (h₀ : f ≠ 0) (h₁ : f.eraseLead = 0) :
f.support.card = 1 :=
(card_support_eq_zero.mpr h₁ ▸ card_support_eraseLead_add_one h₀).symm
theorem card_support_le_one_of_eraseLead_eq_zero (h : f.eraseLead = 0) : f.support.card ≤ 1 := by
by_cases hpz : f = 0
case pos => simp [hpz]
case neg => exact le_of_eq (card_support_eq_one_of_eraseLead_eq_zero hpz h)
@[simp]
theorem eraseLead_monomial (i : ℕ) (r : R) : eraseLead (monomial i r) = 0 := by
classical
by_cases hr : r = 0
· subst r
simp only [monomial_zero_right, eraseLead_zero]
· rw [eraseLead, natDegree_monomial, if_neg hr, erase_monomial]
#align polynomial.erase_lead_monomial Polynomial.eraseLead_monomial
@[simp]
theorem eraseLead_C (r : R) : eraseLead (C r) = 0 :=
eraseLead_monomial _ _
set_option linter.uppercaseLean3 false in
#align polynomial.erase_lead_C Polynomial.eraseLead_C
@[simp]
theorem eraseLead_X : eraseLead (X : R[X]) = 0 :=
eraseLead_monomial _ _
set_option linter.uppercaseLean3 false in
#align polynomial.erase_lead_X Polynomial.eraseLead_X
@[simp]
theorem eraseLead_X_pow (n : ℕ) : eraseLead (X ^ n : R[X]) = 0 := by
rw [X_pow_eq_monomial, eraseLead_monomial]
set_option linter.uppercaseLean3 false in
#align polynomial.erase_lead_X_pow Polynomial.eraseLead_X_pow
@[simp]
theorem eraseLead_C_mul_X_pow (r : R) (n : ℕ) : eraseLead (C r * X ^ n) = 0 := by
rw [C_mul_X_pow_eq_monomial, eraseLead_monomial]
set_option linter.uppercaseLean3 false in
#align polynomial.erase_lead_C_mul_X_pow Polynomial.eraseLead_C_mul_X_pow
@[simp] lemma eraseLead_C_mul_X (r : R) : eraseLead (C r * X) = 0 := by
simpa using eraseLead_C_mul_X_pow _ 1
theorem eraseLead_add_of_natDegree_lt_left {p q : R[X]} (pq : q.natDegree < p.natDegree) :
(p + q).eraseLead = p.eraseLead + q := by
ext n
by_cases nd : n = p.natDegree
· rw [nd, eraseLead_coeff, if_pos (natDegree_add_eq_left_of_natDegree_lt pq).symm]
simpa using (coeff_eq_zero_of_natDegree_lt pq).symm
· rw [eraseLead_coeff, coeff_add, coeff_add, eraseLead_coeff, if_neg, if_neg nd]
rintro rfl
exact nd (natDegree_add_eq_left_of_natDegree_lt pq)
#align polynomial.erase_lead_add_of_nat_degree_lt_left Polynomial.eraseLead_add_of_natDegree_lt_left
theorem eraseLead_add_of_natDegree_lt_right {p q : R[X]} (pq : p.natDegree < q.natDegree) :
(p + q).eraseLead = p + q.eraseLead := by
ext n
by_cases nd : n = q.natDegree
· rw [nd, eraseLead_coeff, if_pos (natDegree_add_eq_right_of_natDegree_lt pq).symm]
simpa using (coeff_eq_zero_of_natDegree_lt pq).symm
· rw [eraseLead_coeff, coeff_add, coeff_add, eraseLead_coeff, if_neg, if_neg nd]
rintro rfl
exact nd (natDegree_add_eq_right_of_natDegree_lt pq)
#align polynomial.erase_lead_add_of_nat_degree_lt_right Polynomial.eraseLead_add_of_natDegree_lt_right
theorem eraseLead_degree_le : (eraseLead f).degree ≤ f.degree :=
f.degree_erase_le _
#align polynomial.erase_lead_degree_le Polynomial.eraseLead_degree_le
theorem eraseLead_natDegree_le_aux : (eraseLead f).natDegree ≤ f.natDegree :=
natDegree_le_natDegree eraseLead_degree_le
#align polynomial.erase_lead_nat_degree_le_aux Polynomial.eraseLead_natDegree_le_aux
theorem eraseLead_natDegree_lt (f0 : 2 ≤ f.support.card) : (eraseLead f).natDegree < f.natDegree :=
lt_of_le_of_ne eraseLead_natDegree_le_aux <|
ne_natDegree_of_mem_eraseLead_support <|
natDegree_mem_support_of_nonzero <| eraseLead_ne_zero f0
#align polynomial.erase_lead_nat_degree_lt Polynomial.eraseLead_natDegree_lt
theorem natDegree_pos_of_eraseLead_ne_zero (h : f.eraseLead ≠ 0) : 0 < f.natDegree := by
by_contra h₂
rw [eq_C_of_natDegree_eq_zero (Nat.eq_zero_of_not_pos h₂)] at h
simp at h
theorem eraseLead_natDegree_lt_or_eraseLead_eq_zero (f : R[X]) :
(eraseLead f).natDegree < f.natDegree ∨ f.eraseLead = 0 := by
by_cases h : f.support.card ≤ 1
· right
rw [← C_mul_X_pow_eq_self h]
simp
· left
apply eraseLead_natDegree_lt (lt_of_not_ge h)
#align polynomial.erase_lead_nat_degree_lt_or_erase_lead_eq_zero Polynomial.eraseLead_natDegree_lt_or_eraseLead_eq_zero
theorem eraseLead_natDegree_le (f : R[X]) : (eraseLead f).natDegree ≤ f.natDegree - 1 := by
rcases f.eraseLead_natDegree_lt_or_eraseLead_eq_zero with (h | h)
· exact Nat.le_sub_one_of_lt h
· simp only [h, natDegree_zero, zero_le]
#align polynomial.erase_lead_nat_degree_le Polynomial.eraseLead_natDegree_le
lemma natDegree_eraseLead (h : f.nextCoeff ≠ 0) : f.eraseLead.natDegree = f.natDegree - 1 := by
have := natDegree_pos_of_nextCoeff_ne_zero h
refine f.eraseLead_natDegree_le.antisymm $ le_natDegree_of_ne_zero ?_
rwa [eraseLead_coeff_of_ne _ (tsub_lt_self _ _).ne, ← nextCoeff_of_natDegree_pos]
all_goals positivity
lemma natDegree_eraseLead_add_one (h : f.nextCoeff ≠ 0) :
f.eraseLead.natDegree + 1 = f.natDegree := by
rw [natDegree_eraseLead h, tsub_add_cancel_of_le]
exact natDegree_pos_of_nextCoeff_ne_zero h
theorem natDegree_eraseLead_le_of_nextCoeff_eq_zero (h : f.nextCoeff = 0) :
f.eraseLead.natDegree ≤ f.natDegree - 2 := by
refine natDegree_le_pred (n := f.natDegree - 1) (eraseLead_natDegree_le f) ?_
rw [nextCoeff_eq_zero, natDegree_eq_zero] at h
obtain ⟨a, rfl⟩ | ⟨hf, h⟩ := h
· simp
rw [eraseLead_coeff_of_ne _ (tsub_lt_self hf zero_lt_one).ne, ← nextCoeff_of_natDegree_pos hf]
simp [nextCoeff_eq_zero, h, eq_zero_or_pos]
lemma two_le_natDegree_of_nextCoeff_eraseLead (hlead : f.eraseLead ≠ 0) (hnext : f.nextCoeff = 0) :
2 ≤ f.natDegree := by
contrapose! hlead
rw [Nat.lt_succ_iff, Nat.le_one_iff_eq_zero_or_eq_one, natDegree_eq_zero, natDegree_eq_one]
at hlead
obtain ⟨a, rfl⟩ | ⟨a, ha, b, rfl⟩ := hlead
· simp
· rw [nextCoeff_C_mul_X_add_C ha] at hnext
subst b
simp
theorem leadingCoeff_eraseLead_eq_nextCoeff (h : f.nextCoeff ≠ 0) :
f.eraseLead.leadingCoeff = f.nextCoeff := by
have := natDegree_pos_of_nextCoeff_ne_zero h
rw [leadingCoeff, nextCoeff, natDegree_eraseLead h, if_neg,
eraseLead_coeff_of_ne _ (tsub_lt_self _ _).ne]
all_goals positivity
theorem nextCoeff_eq_zero_of_eraseLead_eq_zero (h : f.eraseLead = 0) : f.nextCoeff = 0 := by
by_contra h₂
exact leadingCoeff_ne_zero.mp (leadingCoeff_eraseLead_eq_nextCoeff h₂ ▸ h₂) h
end EraseLead
/-- An induction lemma for polynomials. It takes a natural number `N` as a parameter, that is
required to be at least as big as the `nat_degree` of the polynomial. This is useful to prove
results where you want to change each term in a polynomial to something else depending on the
`nat_degree` of the polynomial itself and not on the specific `nat_degree` of each term. -/
theorem induction_with_natDegree_le (P : R[X] → Prop) (N : ℕ) (P_0 : P 0)
(P_C_mul_pow : ∀ n : ℕ, ∀ r : R, r ≠ 0 → n ≤ N → P (C r * X ^ n))
(P_C_add : ∀ f g : R[X], f.natDegree < g.natDegree → g.natDegree ≤ N → P f → P g → P (f + g)) :
∀ f : R[X], f.natDegree ≤ N → P f := by
intro f df
generalize hd : card f.support = c
revert f
induction' c with c hc
· intro f _ f0
convert P_0
simpa [support_eq_empty, card_eq_zero] using f0
· intro f df f0
rw [← eraseLead_add_C_mul_X_pow f]
cases c
· convert P_C_mul_pow f.natDegree f.leadingCoeff ?_ df using 1
· convert zero_add (C (leadingCoeff f) * X ^ f.natDegree)
rw [← card_support_eq_zero, card_support_eraseLead' f0]
· rw [leadingCoeff_ne_zero, Ne, ← card_support_eq_zero, f0]
exact zero_ne_one.symm
refine P_C_add f.eraseLead _ ?_ ?_ ?_ ?_
· refine (eraseLead_natDegree_lt ?_).trans_le (le_of_eq ?_)
· exact (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le _))).trans f0.ge
· rw [natDegree_C_mul_X_pow _ _ (leadingCoeff_ne_zero.mpr _)]
rintro rfl
simp at f0
· exact (natDegree_C_mul_X_pow_le f.leadingCoeff f.natDegree).trans df
· exact hc _ (eraseLead_natDegree_le_aux.trans df) (card_support_eraseLead' f0)
· refine P_C_mul_pow _ _ ?_ df
rw [Ne, leadingCoeff_eq_zero, ← card_support_eq_zero, f0]
exact Nat.succ_ne_zero _
#align polynomial.induction_with_nat_degree_le Polynomial.induction_with_natDegree_le
/-- Let `φ : R[x] → S[x]` be an additive map, `k : ℕ` a bound, and `fu : ℕ → ℕ` a
"sufficiently monotone" map. Assume also that
* `φ` maps to `0` all monomials of degree less than `k`,
* `φ` maps each monomial `m` in `R[x]` to a polynomial `φ m` of degree `fu (deg m)`.
Then, `φ` maps each polynomial `p` in `R[x]` to a polynomial of degree `fu (deg p)`. -/
theorem mono_map_natDegree_eq {S F : Type*} [Semiring S]
[FunLike F R[X] S[X]] [AddMonoidHomClass F R[X] S[X]] {φ : F}
{p : R[X]} (k : ℕ) (fu : ℕ → ℕ) (fu0 : ∀ {n}, n ≤ k → fu n = 0)
(fc : ∀ {n m}, k ≤ n → n < m → fu n < fu m) (φ_k : ∀ {f : R[X]}, f.natDegree < k → φ f = 0)
(φ_mon_nat : ∀ n c, c ≠ 0 → (φ (monomial n c)).natDegree = fu n) :
(φ p).natDegree = fu p.natDegree := by
refine induction_with_natDegree_le (fun p => (φ p).natDegree = fu p.natDegree)
p.natDegree (by simp [fu0]) ?_ ?_ _ rfl.le
· intro n r r0 _
rw [natDegree_C_mul_X_pow _ _ r0, C_mul_X_pow_eq_monomial, φ_mon_nat _ _ r0]
· intro f g fg _ fk gk
rw [natDegree_add_eq_right_of_natDegree_lt fg, _root_.map_add]
by_cases FG : k ≤ f.natDegree
· rw [natDegree_add_eq_right_of_natDegree_lt, gk]
rw [fk, gk]
exact fc FG fg
· cases k
· exact (FG (Nat.zero_le _)).elim
· rwa [φ_k (not_le.mp FG), zero_add]
#align polynomial.mono_map_nat_degree_eq Polynomial.mono_map_natDegree_eq
theorem map_natDegree_eq_sub {S F : Type*} [Semiring S]
[FunLike F R[X] S[X]] [AddMonoidHomClass F R[X] S[X]] {φ : F}
{p : R[X]} {k : ℕ} (φ_k : ∀ f : R[X], f.natDegree < k → φ f = 0)
(φ_mon : ∀ n c, c ≠ 0 → (φ (monomial n c)).natDegree = n - k) :
(φ p).natDegree = p.natDegree - k :=
mono_map_natDegree_eq k (fun j => j - k) (by simp_all)
(@fun m n h => (tsub_lt_tsub_iff_right h).mpr)
(φ_k _) φ_mon
#align polynomial.map_nat_degree_eq_sub Polynomial.map_natDegree_eq_sub
theorem map_natDegree_eq_natDegree {S F : Type*} [Semiring S]
[FunLike F R[X] S[X]] [AddMonoidHomClass F R[X] S[X]]
{φ : F} (p) (φ_mon_nat : ∀ n c, c ≠ 0 → (φ (monomial n c)).natDegree = n) :
(φ p).natDegree = p.natDegree :=
(map_natDegree_eq_sub (fun f h => (Nat.not_lt_zero _ h).elim) (by simpa)).trans
p.natDegree.sub_zero
#align polynomial.map_nat_degree_eq_nat_degree Polynomial.map_natDegree_eq_natDegree
theorem card_support_eq' {n : ℕ} (k : Fin n → ℕ) (x : Fin n → R) (hk : Function.Injective k)
(hx : ∀ i, x i ≠ 0) : (∑ i, C (x i) * X ^ k i).support.card = n := by
suffices (∑ i, C (x i) * X ^ k i).support = image k univ by
rw [this, univ.card_image_of_injective hk, card_fin]
simp_rw [Finset.ext_iff, mem_support_iff, finset_sum_coeff, coeff_C_mul_X_pow, mem_image,
mem_univ, true_and]
refine fun i => ⟨fun h => ?_, ?_⟩
· obtain ⟨j, _, h⟩ := exists_ne_zero_of_sum_ne_zero h
exact ⟨j, (ite_ne_right_iff.mp h).1.symm⟩
· rintro ⟨j, _, rfl⟩
rw [sum_eq_single_of_mem j (mem_univ j), if_pos rfl]
· exact hx j
· exact fun m _ hmj => if_neg fun h => hmj.symm (hk h)
#align polynomial.card_support_eq' Polynomial.card_support_eq'
theorem card_support_eq {n : ℕ} :
f.support.card = n ↔
∃ (k : Fin n → ℕ) (x : Fin n → R) (hk : StrictMono k) (hx : ∀ i, x i ≠ 0),
f = ∑ i, C (x i) * X ^ k i := by
refine ⟨?_, fun ⟨k, x, hk, hx, hf⟩ => hf.symm ▸ card_support_eq' k x hk.injective hx⟩
induction' n with n hn generalizing f
· exact fun hf => ⟨0, 0, fun x => x.elim0, fun x => x.elim0, card_support_eq_zero.mp hf⟩
· intro h
obtain ⟨k, x, hk, hx, hf⟩ := hn (card_support_eraseLead' h)
have H : ¬∃ k : Fin n, Fin.castSucc k = Fin.last n := by
rintro ⟨i, hi⟩
exact i.castSucc_lt_last.ne hi
refine
⟨Function.extend Fin.castSucc k fun _ => f.natDegree,
Function.extend Fin.castSucc x fun _ => f.leadingCoeff, ?_, ?_, ?_⟩
· intro i j hij
have hi : i ∈ Set.range (Fin.castSucc : Fin n → Fin (n + 1)) := by
rw [Fin.range_castSucc, Set.mem_def]
exact lt_of_lt_of_le hij (Nat.lt_succ_iff.mp j.2)
obtain ⟨i, rfl⟩ := hi
rw [Fin.strictMono_castSucc.injective.extend_apply]
by_cases hj : ∃ j₀, Fin.castSucc j₀ = j
· obtain ⟨j, rfl⟩ := hj
rwa [Fin.strictMono_castSucc.injective.extend_apply, hk.lt_iff_lt,
← Fin.castSucc_lt_castSucc_iff]
· rw [Function.extend_apply' _ _ _ hj]
apply lt_natDegree_of_mem_eraseLead_support
rw [mem_support_iff, hf, finset_sum_coeff]
rw [sum_eq_single, coeff_C_mul, coeff_X_pow_self, mul_one]
· exact hx i
· intro j _ hji
rw [coeff_C_mul, coeff_X_pow, if_neg (hk.injective.ne hji.symm), mul_zero]
· exact fun hi => (hi (mem_univ i)).elim
· intro i
by_cases hi : ∃ i₀, Fin.castSucc i₀ = i
· obtain ⟨i, rfl⟩ := hi
rw [Fin.strictMono_castSucc.injective.extend_apply]
exact hx i
· rw [Function.extend_apply' _ _ _ hi, Ne, leadingCoeff_eq_zero, ← card_support_eq_zero, h]
exact n.succ_ne_zero
· rw [Fin.sum_univ_castSucc]
simp only [Fin.strictMono_castSucc.injective.extend_apply]
rw [← hf, Function.extend_apply', Function.extend_apply', eraseLead_add_C_mul_X_pow]
all_goals exact H
#align polynomial.card_support_eq Polynomial.card_support_eq
theorem card_support_eq_one : f.support.card = 1 ↔
∃ (k : ℕ) (x : R) (hx : x ≠ 0), f = C x * X ^ k := by
refine ⟨fun h => ?_, ?_⟩
· obtain ⟨k, x, _, hx, rfl⟩ := card_support_eq.mp h
exact ⟨k 0, x 0, hx 0, Fin.sum_univ_one _⟩
· rintro ⟨k, x, hx, rfl⟩
rw [support_C_mul_X_pow k hx, card_singleton]
#align polynomial.card_support_eq_one Polynomial.card_support_eq_one
theorem card_support_eq_two :
f.support.card = 2 ↔
∃ (k m : ℕ) (hkm : k < m) (x y : R) (hx : x ≠ 0) (hy : y ≠ 0),
f = C x * X ^ k + C y * X ^ m := by
refine ⟨fun h => ?_, ?_⟩
· obtain ⟨k, x, hk, hx, rfl⟩ := card_support_eq.mp h
refine ⟨k 0, k 1, hk Nat.zero_lt_one, x 0, x 1, hx 0, hx 1, ?_⟩
rw [Fin.sum_univ_castSucc, Fin.sum_univ_one]
rfl
· rintro ⟨k, m, hkm, x, y, hx, hy, rfl⟩
exact card_support_binomial hkm.ne hx hy
#align polynomial.card_support_eq_two Polynomial.card_support_eq_two
| Mathlib/Algebra/Polynomial/EraseLead.lean | 446 | 458 | theorem card_support_eq_three :
f.support.card = 3 ↔
∃ (k m n : ℕ) (hkm : k < m) (hmn : m < n) (x y z : R) (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0),
f = C x * X ^ k + C y * X ^ m + C z * X ^ n := by |
refine ⟨fun h => ?_, ?_⟩
· obtain ⟨k, x, hk, hx, rfl⟩ := card_support_eq.mp h
refine
⟨k 0, k 1, k 2, hk Nat.zero_lt_one, hk (Nat.lt_succ_self 1), x 0, x 1, x 2, hx 0, hx 1, hx 2,
?_⟩
rw [Fin.sum_univ_castSucc, Fin.sum_univ_castSucc, Fin.sum_univ_one]
rfl
· rintro ⟨k, m, n, hkm, hmn, x, y, z, hx, hy, hz, rfl⟩
exact card_support_trinomial hkm hmn hx hy hz
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.